Template catalog retrieval
Template catalog retrieval turns a remote templates.json catalog into the template choices used by the application. It selects the catalog source, checks its shape, applies the menu policy, creates a flat template view, and resolves a requested template as a catalog entry, a local path, or an external repository.
The broader selection flow is described in Template catalog and selection. Menu behavior and prompt use are covered in Template menu and prompts, while the data contract is covered in Template schema and option flags.
Catalog source
The catalog source is a URL that points to the remote template list. home/…/get-templates-url.ts uses TEMPLATES_URL when set. Otherwise, it uses the main Solana Foundation template catalog. The command can also supply a URL directly through its templates URL option.
This boundary lets local development and controlled environments use another catalog without changing the selection flow. The rest of the system receives a URL and does not need to know how that URL was chosen.
References: src/…/get-templates-url.ts• L1-6 src/…/get-args.ts• L41-42
Remote catalog fetch
Remote fetching converts the URL response into trusted catalog groups. fetchTemplatesJsonUrl requires a successful response, reads its text, parses JSON, and validates the full result against the template catalog schema. A network failure or an invalid catalog stops retrieval with an error that identifies the URL or the catalog format problem.
The fetch stage therefore protects later selection stages from two different bad inputs: a source that cannot be reached and a source that does not describe the expected catalog. It returns groups rather than a flat list so the menu policy can still use group boundaries.
References: src/…/fetch-templates.ts• L1-18 src/…/template-schema.ts• L16-25
Catalog normalization
Normalization reshapes the remote groups into the views needed by the command. fetchTemplateData first retrieves groups, maps them into configured menu items, and then flattens the templates in those items into one list. It returns both views because prompts need menu items while direct listing and template lookup need the flat template list.
The menu configuration controls which groups and keywords contribute to each menu item. A configured item can include every template in its selected groups or only templates whose keyword set contains one of its configured keywords. This filtering is the catalog’s product-facing selection boundary; it does not alter the remote source.
The retrieval path is shown below.
flowchart LR
A[Catalog URL] --> B[Remote templates.json]
B --> C[Validated template groups]
C --> D[Configured menu items]
D --> E[Flat template list]
E --> F[Listing or catalog lookup]
D --> G[Interactive template choice]
References: src/…/fetch-template-data.ts• L6-26 src/…/get-template-groups-from-url.ts• L5-15 src/…/get-menu-items-from-template-groups.ts• L6-21 src/…/menu-utils.ts• L3-27 src/…/get-templates-from-items.ts• L5-19
Template identity lookup
Template lookup resolves the value supplied to the template option into a template descriptor. A catalog name is matched against the normalized list by its name; a name that contains / is treated as an external repository identity; and a value that begins with an absolute or relative path is treated as a local template identity.
These identity forms support different sources without mixing their trust and resolution rules. Catalog entries come from the validated remote data. External identities are passed through as repository references, with a gh: prefix added when no source prefix exists. Local identities must point to an existing path and are marked with a local: ID for downstream use.
The command performs this lookup after catalog retrieval. The same retrieved list also supports human-readable template output and a JSON list of catalog IDs.
| Input form | Meaning | Lookup result |
|---|---|---|
template-name | Entry in the configured catalog | Matching catalog template or a not-found error |
org/repository | External repository identity | External template descriptor |
./path, ../path, or /path | Local template identity | Local template descriptor or a missing-path error |
References: src/…/find-template.ts• L7-64 src/…/get-args.ts• L64-83 src/…/get-args.ts• L110-122 src/…/template.ts• L1-6
Catalog observability
Verbose output exposes the retrieval stages without changing their results. It reports the source URL, the number and identity of fetched groups, the number and identity of menu items, and the final template set. This gives an engineer a way to see whether a missing template came from the source, menu filtering, or name lookup.
The listing actions use the final normalized list. Human-readable listing shows each template’s name, description, and ID. ID listing emits only the IDs as a JSON array, which supports callers that need a machine-readable catalog view.
References: src/…/get-template-groups-from-url.ts• L5-15 src/…/get-menu-items-from-template-groups.ts• L6-21 src/…/get-templates-from-items.ts• L5-19 src/…/list-templates.ts• L4-8 src/…/list-template-ids.ts• L3-5
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the remote catalog shape must stay aligned with validation and with every consumer of group, template, and menu-item data.
- Changes to group paths or template keywords must be checked against menu configuration because they can silently remove choices without changing the fetch result.
- Changes to template names or identity prefixes must stay aligned with downstream template cloning and with the command’s list and lookup actions.
- Changes to the catalog URL source must preserve the direct command option and the environment override as equivalent ways to select a catalog.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The catalog URL returns a non-success response | Retrieval stops before menu creation | Check the response status and report the URL with the status details |
| The response is not valid JSON or does not match the catalog schema | No templates are available for selection | Parse and validate the complete response before normalization |
| Menu configuration names a group path or keyword that the catalog does not provide | A menu item can contain no templates | Keep group paths and keyword values coordinated across the catalog and menu policy |
| A catalog template name does not match the requested name | Direct template selection fails | Use an exact catalog name or provide a supported external or local identity |
| A local template path does not exist | Local template selection fails before use | Check the resolved path before returning the local descriptor |
Key files
| File | Why to read it |
|---|---|
| src/…/fetch-template-data.ts | Shows the complete retrieval and normalization boundary |
| src/…/get-templates-url.ts | Defines the default catalog source and override point |
| src/…/fetch-templates.ts | Defines remote fetch and catalog validation behavior |
| src/…/template-schema.ts | Defines the group, template, and menu data contract |
| src/…/menu-utils.ts | Shows how catalog groups become configured menu items |
| src/…/find-template.ts | Defines catalog, external, and local identity resolution |
| src/…/get-args.ts | Shows when retrieval, listing, and lookup enter the command flow |