forked from oomol-lab/open-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog-assets.ts
More file actions
26 lines (21 loc) · 1.02 KB
/
Copy pathcatalog-assets.ts
File metadata and controls
26 lines (21 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { CatalogStore, LoadCatalogOptions } from "../../catalog-store.ts";
import type { ProviderDefinition } from "../../core/types.ts";
import type { AssetsBinding } from "./cloudflare-bindings.ts";
import { createCatalogStore, resolveExecutableActionIds } from "../../catalog-store.ts";
const catalogAssetPath = "/catalog/apps.json";
export async function loadCatalogFromAssets(
assets: AssetsBinding,
options: LoadCatalogOptions = {},
): Promise<CatalogStore> {
const providers = (await readJsonAsset(assets, catalogAssetPath)) as ProviderDefinition[];
return createCatalogStore(providers, {
executableActionIds: resolveExecutableActionIds(providers, options),
});
}
async function readJsonAsset(assets: AssetsBinding, path: string): Promise<unknown> {
const response = await assets.fetch(new Request(new URL(path, "https://assets.local")));
if (!response.ok) {
throw new Error(`Cloudflare asset catalog request failed: ${path} returned ${response.status}`);
}
return response.json() as Promise<unknown>;
}