@salesforce/ui-bundle-template-feature-cms-toolkit 11.59.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +82 -0
- package/README.md +88 -0
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/CHANGELOG.md +4705 -0
- package/dist/README.md +77 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/eslint.config.js +7 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.forceignore +15 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.graphqlrc.yml +2 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.prettierignore +9 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/.prettierrc +11 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/CHANGELOG.md +10 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/README.md +75 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/codegen.yml +95 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/components.json +18 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/e2e/app.spec.ts +17 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/eslint.config.js +169 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/feature-cms-toolkit.uibundle-meta.xml +7 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/index.html +12 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/package.json +76 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/playwright.config.ts +24 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/scripts/get-graphql-schema.mjs +71 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/scripts/rewrite-e2e-assets.mjs +23 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/api/graphqlClient.ts +44 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/app.tsx +17 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/appLayout.tsx +83 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/alerts/status-alert.tsx +52 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/layouts/card-layout.tsx +29 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/alert.tsx +76 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/avatar.tsx +109 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/badge.tsx +48 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/breadcrumb.tsx +109 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/button.tsx +67 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/calendar.tsx +232 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/card.tsx +103 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/checkbox.tsx +32 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/collapsible.tsx +33 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/datePicker.tsx +127 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/dialog.tsx +162 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/dropdown-menu.tsx +257 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/field.tsx +237 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/index.ts +109 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/label.tsx +22 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/pagination.tsx +132 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/popover.tsx +89 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/select.tsx +193 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/separator.tsx +26 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/skeleton.tsx +14 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/sonner.tsx +20 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/spinner.tsx +16 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/table.tsx +121 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/components/ui/tabs.tsx +88 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/catalog.ts +140 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsContent.ts +127 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsPaths.ts +37 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/envelope.ts +30 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/errors.ts +54 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/httpClient.ts +102 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/config/env.ts +46 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/index.ts +46 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/types/cms.ts +96 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/htmlEntities.ts +58 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/imageUrl.ts +88 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/hooks/useAsyncData.ts +67 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts +10 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/navigationMenu.tsx +80 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/pages/Home.tsx +12 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/router-utils.tsx +35 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/routes.tsx +22 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/styles/global.css +135 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.json +45 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/tsconfig.tsbuildinfo +1 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/ui-bundle.json +7 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vite-env.d.ts +4 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vite.config.ts +26 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest.config.ts +11 -0
- package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/vitest.setup.ts +1 -0
- package/dist/jest.config.js +6 -0
- package/dist/package-lock.json +10066 -0
- package/dist/package.json +46 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/gitignore-templates.json +4 -0
- package/dist/scripts/graphql-search.sh +191 -0
- package/dist/scripts/org-setup-config-schema.mjs +120 -0
- package/dist/scripts/org-setup-dev.mjs +87 -0
- package/dist/scripts/org-setup-utils.mjs +569 -0
- package/dist/scripts/org-setup-xml.mjs +182 -0
- package/dist/scripts/org-setup.config.json +5 -0
- package/dist/scripts/org-setup.mjs +2345 -0
- package/dist/scripts/sf-project-setup.mjs +103 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/scripts/validate-org-setup-config.mjs +38 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +50 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/catalog.ts +140 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsContent.ts +127 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/cmsPaths.ts +37 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/envelope.ts +30 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/errors.ts +54 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/api/httpClient.ts +102 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/config/env.ts +46 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/index.ts +46 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/types/cms.ts +96 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/htmlEntities.ts +58 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/utils/imageUrl.ts +88 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts +10 -0
- package/src/force-app/main/default/uiBundles/feature-cms-toolkit/vite.config.ts +26 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { Tabs as TabsPrimitive } from 'radix-ui';
|
|
4
|
+
|
|
5
|
+
import { cn } from '../../lib/utils';
|
|
6
|
+
|
|
7
|
+
function Tabs({
|
|
8
|
+
className,
|
|
9
|
+
orientation = 'horizontal',
|
|
10
|
+
...props
|
|
11
|
+
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
|
12
|
+
return (
|
|
13
|
+
<TabsPrimitive.Root
|
|
14
|
+
data-slot="tabs"
|
|
15
|
+
data-orientation={orientation}
|
|
16
|
+
className={cn(
|
|
17
|
+
'gap-2 group/tabs flex data-horizontal:flex-col',
|
|
18
|
+
className
|
|
19
|
+
)}
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const tabsListVariants = cva(
|
|
26
|
+
'rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col',
|
|
27
|
+
{
|
|
28
|
+
variants: {
|
|
29
|
+
variant: {
|
|
30
|
+
default: 'bg-muted',
|
|
31
|
+
line: 'gap-1 bg-transparent',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: 'default',
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
function TabsList({
|
|
41
|
+
className,
|
|
42
|
+
variant = 'default',
|
|
43
|
+
...props
|
|
44
|
+
}: React.ComponentProps<typeof TabsPrimitive.List> &
|
|
45
|
+
VariantProps<typeof tabsListVariants>) {
|
|
46
|
+
return (
|
|
47
|
+
<TabsPrimitive.List
|
|
48
|
+
data-slot="tabs-list"
|
|
49
|
+
data-variant={variant}
|
|
50
|
+
className={cn(tabsListVariants({ variant }), className)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function TabsTrigger({
|
|
57
|
+
className,
|
|
58
|
+
...props
|
|
59
|
+
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
|
60
|
+
return (
|
|
61
|
+
<TabsPrimitive.Trigger
|
|
62
|
+
data-slot="tabs-trigger"
|
|
63
|
+
className={cn(
|
|
64
|
+
"gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*='size-'])]:size-4 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
65
|
+
'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent',
|
|
66
|
+
'data-active:bg-background dark:data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 data-active:text-foreground',
|
|
67
|
+
'after:bg-foreground after:absolute after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100',
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
{...props}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function TabsContent({
|
|
76
|
+
className,
|
|
77
|
+
...props
|
|
78
|
+
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
|
79
|
+
return (
|
|
80
|
+
<TabsPrimitive.Content
|
|
81
|
+
data-slot="tabs-content"
|
|
82
|
+
className={cn('text-sm flex-1 outline-none', className)}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* content-metadata.json loader + resolvers for the authenticated (byKey) read path.
|
|
3
|
+
*
|
|
4
|
+
* The catalog is a deploy-specific public JSON asset at `CONTENT_CATALOG_URL`
|
|
5
|
+
* (`{ channelId, contents }`), fetched once and memoized. Fail-open: a missing /
|
|
6
|
+
* unreachable / malformed catalog resolves to `{}` and never throws.
|
|
7
|
+
*/
|
|
8
|
+
import { CONTENT_CATALOG_URL } from "../config/env";
|
|
9
|
+
import type { CmsContentCatalog } from "../types/cms";
|
|
10
|
+
|
|
11
|
+
// Module-scoped: each catalog URL is fetched at most once per session. The Map
|
|
12
|
+
// is keyed by URL and is BOTH the inflight guard and the cache — so a custom URL
|
|
13
|
+
// never collides with the default one.
|
|
14
|
+
const catalogPromises = new Map<string, Promise<CmsContentCatalog>>();
|
|
15
|
+
// Guards the single fail-open warning so a missing catalog doesn't spam the console.
|
|
16
|
+
let warned = false;
|
|
17
|
+
|
|
18
|
+
/** Parse the raw `contents` array into a source→target contentKey Map, skipping any
|
|
19
|
+
* entry missing either string key. Returns undefined when nothing usable is present. */
|
|
20
|
+
function parseContentKeyMap(rawContents: unknown): ReadonlyMap<string, string> | undefined {
|
|
21
|
+
if (!Array.isArray(rawContents)) return undefined;
|
|
22
|
+
const contentKeyMap = new Map<string, string>();
|
|
23
|
+
for (const entry of rawContents) {
|
|
24
|
+
if (!entry || typeof entry !== "object") continue;
|
|
25
|
+
const { sourceContentKey, targetContentKey } = entry as {
|
|
26
|
+
sourceContentKey?: unknown;
|
|
27
|
+
targetContentKey?: unknown;
|
|
28
|
+
};
|
|
29
|
+
if (typeof sourceContentKey === "string" && typeof targetContentKey === "string") {
|
|
30
|
+
contentKeyMap.set(sourceContentKey, targetContentKey);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return contentKeyMap.size > 0 ? contentKeyMap : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Parse a raw catalog payload into a CmsContentCatalog. Tolerates any shape. */
|
|
37
|
+
function parseCatalog(payload: unknown): CmsContentCatalog {
|
|
38
|
+
if (!payload || typeof payload !== "object") return {};
|
|
39
|
+
const { channelId, contents } = payload as { channelId?: unknown; contents?: unknown };
|
|
40
|
+
const catalog: CmsContentCatalog = {};
|
|
41
|
+
if (typeof channelId === "string") catalog.channelId = channelId;
|
|
42
|
+
const contentKeyMap = parseContentKeyMap(contents);
|
|
43
|
+
if (contentKeyMap) catalog.contentKeyMap = contentKeyMap;
|
|
44
|
+
return catalog;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Emit the single fail-open warning, once. Never rethrows. */
|
|
48
|
+
function warnOnce(catalogUrl: string, detail: unknown): void {
|
|
49
|
+
if (warned) return;
|
|
50
|
+
warned = true;
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.warn(
|
|
53
|
+
`[cms] content-metadata.json unavailable at ${catalogUrl} — ` +
|
|
54
|
+
"no channelId from the catalog. Pass options.channelId explicitly. " +
|
|
55
|
+
"This is expected in local dev.",
|
|
56
|
+
detail,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Load and memoize the catalog. Fail-open: any error resolves to `{}` — never rejects.
|
|
62
|
+
*
|
|
63
|
+
* @param catalogUrl - Where to fetch the catalog from. Defaults to `CONTENT_CATALOG_URL`.
|
|
64
|
+
* Each distinct URL is fetched and cached independently, so passing a custom URL
|
|
65
|
+
* never collides with the default one.
|
|
66
|
+
*/
|
|
67
|
+
export function loadCatalog(catalogUrl: string = CONTENT_CATALOG_URL): Promise<CmsContentCatalog> {
|
|
68
|
+
const cached = catalogPromises.get(catalogUrl);
|
|
69
|
+
if (cached) return cached;
|
|
70
|
+
|
|
71
|
+
const promise = (async (): Promise<CmsContentCatalog> => {
|
|
72
|
+
try {
|
|
73
|
+
// Plain same-origin fetch of a static public asset — no SDK, no auth.
|
|
74
|
+
const response = await fetch(catalogUrl);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
warnOnce(catalogUrl, `HTTP ${response.status}`);
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
return parseCatalog(await response.json());
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// Network error or invalid JSON — a missing catalog is a normal dev state.
|
|
82
|
+
warnOnce(catalogUrl, error);
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
|
|
87
|
+
// Self-cleaning: if the promise ever rejects (it shouldn't), drop it so the next
|
|
88
|
+
// caller retries instead of reusing a poisoned entry.
|
|
89
|
+
promise.catch(() => {
|
|
90
|
+
if (catalogPromises.get(catalogUrl) === promise) catalogPromises.delete(catalogUrl);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
catalogPromises.set(catalogUrl, promise);
|
|
94
|
+
return promise;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the CMS channel for an authenticated (byKey) read:
|
|
99
|
+
* `channelId` arg ?? catalog `channelId` ?? throw. Throws when neither yields one.
|
|
100
|
+
*
|
|
101
|
+
* @param channelId - Explicit channel id; short-circuits the catalog lookup when set.
|
|
102
|
+
* @param catalogUrl - Optional catalog URL override. Defaults to `CONTENT_CATALOG_URL`.
|
|
103
|
+
* Pass this to stay usable if the metadata file's path or name changes in future.
|
|
104
|
+
*/
|
|
105
|
+
export async function resolveChannelId(channelId?: string, catalogUrl?: string): Promise<string> {
|
|
106
|
+
if (channelId) return channelId;
|
|
107
|
+
const catalog = await loadCatalog(catalogUrl);
|
|
108
|
+
if (catalog.channelId) return catalog.channelId;
|
|
109
|
+
throw new Error(
|
|
110
|
+
"No CMS channel id — pass `channelId` in options or set it in " + "content-metadata.json.",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Read the catalog's default `channelId`, or `undefined` when the catalog is
|
|
116
|
+
* missing/malformed or has no channelId. Fail-open — never throws.
|
|
117
|
+
*
|
|
118
|
+
* @param catalogUrl - Optional catalog URL override. Defaults to `CONTENT_CATALOG_URL`.
|
|
119
|
+
* Pass this to stay usable if the metadata file's path or name changes in future.
|
|
120
|
+
*/
|
|
121
|
+
export async function getCmsDefaultChannelId(catalogUrl?: string): Promise<string | undefined> {
|
|
122
|
+
const catalog = await loadCatalog(catalogUrl);
|
|
123
|
+
return catalog.channelId;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Remap a baked-in `sourceContentKey` to the deployed org's `targetContentKey`.
|
|
128
|
+
* Fail-open: returns the input key unchanged when the catalog has no matching entry.
|
|
129
|
+
*
|
|
130
|
+
* @param contentKey - The baked-in source contentKey to remap.
|
|
131
|
+
* @param catalogUrl - Optional catalog URL override. Defaults to `CONTENT_CATALOG_URL`.
|
|
132
|
+
* Pass this to stay usable if the metadata file's path or name changes in future.
|
|
133
|
+
*/
|
|
134
|
+
export async function resolveEffectiveContentKey(
|
|
135
|
+
contentKey: string,
|
|
136
|
+
catalogUrl?: string,
|
|
137
|
+
): Promise<string> {
|
|
138
|
+
const catalog = await loadCatalog(catalogUrl);
|
|
139
|
+
return catalog.contentKeyMap?.get(contentKey) ?? contentKey;
|
|
140
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS content read API. Three methods over the two delivery transports:
|
|
3
|
+
* - getCmsContentByUrl → public CDN URL (unauthenticated)
|
|
4
|
+
* - getCmsContentByKey → single item by contentKey (authenticated; throws)
|
|
5
|
+
* - getCmsContentByKeys → many by contentKey (authenticated; best-effort)
|
|
6
|
+
*
|
|
7
|
+
* Each takes a required subject + one optional `CmsReadOptions`, and returns the
|
|
8
|
+
* unwrapped `contentBody` typed by the caller's `TBody` (envelope title lifted in).
|
|
9
|
+
*/
|
|
10
|
+
import { cmsDeliveryGet, connectGet } from "./httpClient";
|
|
11
|
+
import { buildBulkPath, buildDetailPath } from "./cmsPaths";
|
|
12
|
+
import { resolveChannelId, resolveEffectiveContentKey } from "./catalog";
|
|
13
|
+
import { unwrapContent } from "./envelope";
|
|
14
|
+
import { CmsNotFoundError } from "./errors";
|
|
15
|
+
import type {
|
|
16
|
+
CmsBulkResult,
|
|
17
|
+
CmsContentBody,
|
|
18
|
+
CmsDeliveryEnvelope,
|
|
19
|
+
CmsReadOptions,
|
|
20
|
+
} from "../types/cms";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fetch a single CMS item from a public delivery URL (a pasted CDN link or
|
|
24
|
+
* `unauthenticatedUrl`). Unauthenticated. Throws on failure.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const article = await getCmsContentByUrl<NewsBody>(url, { signal });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function getCmsContentByUrl<TBody = CmsContentBody>(
|
|
32
|
+
url: string,
|
|
33
|
+
options?: CmsReadOptions,
|
|
34
|
+
): Promise<TBody> {
|
|
35
|
+
const envelope = await cmsDeliveryGet<CmsDeliveryEnvelope<TBody>>(url, options?.signal);
|
|
36
|
+
return unwrapContent<TBody>(envelope);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetch a single CMS item by `contentKey` (authenticated Connect delivery). The key is
|
|
41
|
+
* remapped via the catalog (source→target; fail-open to the given key).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const news = await getCmsContentByKey<NewsBody>("M3ASD4KHASDB73");
|
|
46
|
+
* const scoped = await getCmsContentByKey<NewsBody>(key, { channelId, signal });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function getCmsContentByKey<TBody = CmsContentBody>(
|
|
50
|
+
contentKey: string,
|
|
51
|
+
options?: CmsReadOptions,
|
|
52
|
+
): Promise<TBody> {
|
|
53
|
+
const [channel, effectiveKey] = await Promise.all([
|
|
54
|
+
resolveChannelId(options?.channelId),
|
|
55
|
+
resolveEffectiveContentKey(contentKey),
|
|
56
|
+
]);
|
|
57
|
+
const envelope = await connectGet<CmsDeliveryEnvelope<TBody>>(
|
|
58
|
+
buildDetailPath(channel, effectiveKey),
|
|
59
|
+
options?.signal,
|
|
60
|
+
);
|
|
61
|
+
return unwrapContent<TBody>(envelope);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Bulk-read many items by `contentKey` in ONE authenticated Connect call. Best-effort:
|
|
66
|
+
* each requested key comes back as a `CmsBulkResult` with either `body` or `error` set,
|
|
67
|
+
* echoing the requested key. Keys are catalog-remapped (fail-open); a key missing from
|
|
68
|
+
* the response gets a `CmsNotFoundError`. Never throws except on cancellation (AbortError).
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const results = await getCmsContentByKeys<NewsBody>(["k1", "k2"]);
|
|
73
|
+
* for (const r of results) {
|
|
74
|
+
* if (r.error) console.warn(r.contentKey, r.error.message);
|
|
75
|
+
* else render(r.body);
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export async function getCmsContentByKeys<TBody = CmsContentBody>(
|
|
80
|
+
contentKeys: string[],
|
|
81
|
+
options?: CmsReadOptions,
|
|
82
|
+
): Promise<CmsBulkResult<TBody>[]> {
|
|
83
|
+
if (contentKeys.length === 0) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
// Resolve channel + keys INSIDE the try: `resolveChannelId` throws when the
|
|
89
|
+
// catalog is absent and no `channelId` was passed (the normal local-dev state)
|
|
90
|
+
const [channel, effectiveKeys] = await Promise.all([
|
|
91
|
+
resolveChannelId(options?.channelId),
|
|
92
|
+
Promise.all(contentKeys.map((key) => resolveEffectiveContentKey(key))),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const response = await connectGet<{ contents?: CmsDeliveryEnvelope<TBody>[] }>(
|
|
96
|
+
buildBulkPath(channel, effectiveKeys),
|
|
97
|
+
options?.signal,
|
|
98
|
+
);
|
|
99
|
+
const contents = Array.isArray(response.contents) ? response.contents : [];
|
|
100
|
+
|
|
101
|
+
const byKey = new Map<string, CmsDeliveryEnvelope<TBody>>();
|
|
102
|
+
for (const envelope of contents) {
|
|
103
|
+
if (envelope?.contentKey) {
|
|
104
|
+
byKey.set(envelope.contentKey, envelope);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return contentKeys.map((contentKey, i) => {
|
|
109
|
+
const envelope = byKey.get(effectiveKeys[i]);
|
|
110
|
+
if (!envelope) {
|
|
111
|
+
return { contentKey, error: new CmsNotFoundError() };
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return { contentKey, body: unwrapContent<TBody>(envelope) };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return {
|
|
117
|
+
contentKey,
|
|
118
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error instanceof DOMException && error.name === "AbortError") throw error;
|
|
124
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
125
|
+
return contentKeys.map((contentKey) => ({ contentKey, error: err }));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authenticated Connect delivery path builders.
|
|
3
|
+
*
|
|
4
|
+
* Both build the full `/services/data/<ver>/connect/cms/delivery/...` path fed to
|
|
5
|
+
* `connectGet`. Public delivery URLs never come through here — they are complete
|
|
6
|
+
* URLs fetched as-is via `cmsDeliveryGet`.
|
|
7
|
+
*/
|
|
8
|
+
import { API_VERSION } from "../config/env";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Build the authenticated Connect delivery path for a single uiBundle-space item.
|
|
12
|
+
* API_VERSION is the bare number (e.g. '64.0', no leading 'v').
|
|
13
|
+
*
|
|
14
|
+
* `channelId` and `contentKey` are `encodeURIComponent`-wrapped so a value containing
|
|
15
|
+
* `?`/`#`/`/` can't corrupt the path. An empty `contentKey` fast-fails, since it would
|
|
16
|
+
* otherwise collapse to the collection form (`.../contents/`) and silently mis-read.
|
|
17
|
+
*/
|
|
18
|
+
export function buildDetailPath(channelId: string, contentKey: string): string {
|
|
19
|
+
if (!contentKey) {
|
|
20
|
+
throw new Error("buildDetailPath: contentKey must be a non-empty string.");
|
|
21
|
+
}
|
|
22
|
+
return `/services/data/v${API_VERSION}/connect/cms/delivery/channels/${encodeURIComponent(channelId)}/contents/${encodeURIComponent(contentKey)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Bulk delivery path — the trailing-slash + query form that reads MANY contentKeys in one call.
|
|
27
|
+
* `includeContentBody=true` is REQUIRED or every envelope comes back without
|
|
28
|
+
* `contentBody`.
|
|
29
|
+
*
|
|
30
|
+
* Each key is `encodeURIComponent`-wrapped BEFORE the `,` join, so a key containing
|
|
31
|
+
* `&`/`=`/`,` can't inject query params (e.g. flip off the required `includeContentBody`)
|
|
32
|
+
* or split into extra server-side lookups. `channelId` is encoded for the same reason.
|
|
33
|
+
*/
|
|
34
|
+
export function buildBulkPath(channelId: string, contentKeys: string[]): string {
|
|
35
|
+
const joinedKeys = contentKeys.map((key) => encodeURIComponent(key)).join(",");
|
|
36
|
+
return `/services/data/v${API_VERSION}/connect/cms/delivery/channels/${encodeURIComponent(channelId)}/contents/?includeContentBody=true&contentKeys=${joinedKeys}`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delivery-envelope unwrapping (framework-agnostic).
|
|
3
|
+
*
|
|
4
|
+
* BOTH transports (public CDN + authenticated Connect) return the same envelope: the
|
|
5
|
+
* managed content item DIRECTLY, with per-type fields under `contentBody` and the
|
|
6
|
+
* display `title` at the ENVELOPE root (NOT inside contentBody). Two rules fall out:
|
|
7
|
+
* 1. `contentBody` IS the per-type body — its keys vary by content type.
|
|
8
|
+
* 2. `title` is envelope-level; lift it into the returned body (only when the body
|
|
9
|
+
* lacks one) so callers reading `body.title` still see it.
|
|
10
|
+
*/
|
|
11
|
+
import { CmsNotFoundError } from "./errors";
|
|
12
|
+
import type { CmsContentBody, CmsDeliveryEnvelope } from "../types/cms";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Guards a missing `contentBody` (unpublished / wrong channel) → CmsNotFoundError.
|
|
16
|
+
* Applies to BOTH transports — never return `data.items[0]` or `data` itself.
|
|
17
|
+
*/
|
|
18
|
+
export function unwrapContent<TBody = CmsContentBody>(
|
|
19
|
+
data: CmsDeliveryEnvelope<TBody> | undefined,
|
|
20
|
+
): TBody {
|
|
21
|
+
if (!data?.contentBody) {
|
|
22
|
+
throw new CmsNotFoundError();
|
|
23
|
+
}
|
|
24
|
+
const body = data.contentBody;
|
|
25
|
+
|
|
26
|
+
if (data.title !== undefined && body && typeof body === "object" && !("title" in body)) {
|
|
27
|
+
return { ...(body as Record<string, unknown>), title: data.title } as TBody;
|
|
28
|
+
}
|
|
29
|
+
return body;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS error hierarchy (single source of truth for both transports).
|
|
3
|
+
*
|
|
4
|
+
* ConnectApiError — authenticated Connect delivery failures
|
|
5
|
+
* └─ CmsNotFoundError — 404 / unpublished / wrong-channel (authenticated)
|
|
6
|
+
* CmsDeliveryError — unauthenticated public CDN failures
|
|
7
|
+
* └─ CmsDeliveryNotFoundError — 404 (unauthenticated)
|
|
8
|
+
*
|
|
9
|
+
* These classes are the STABLE contract for `instanceof` checks. New error types
|
|
10
|
+
* must EXTEND one of these — never rename or re-parent an existing class. Fields are
|
|
11
|
+
* declared explicitly (no TS parameter properties — `erasableSyntaxOnly`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Authenticated Connect delivery error. */
|
|
15
|
+
export class ConnectApiError extends Error {
|
|
16
|
+
status?: number;
|
|
17
|
+
originalError?: unknown;
|
|
18
|
+
|
|
19
|
+
constructor(message: string, status?: number, originalError?: unknown) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "ConnectApiError";
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.originalError = originalError;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Authenticated 404 — content unpublished or wrong channel. */
|
|
28
|
+
export class CmsNotFoundError extends ConnectApiError {
|
|
29
|
+
constructor(message = "Content not found") {
|
|
30
|
+
super(message, 404);
|
|
31
|
+
this.name = "CmsNotFoundError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Unauthenticated public CDN delivery error. */
|
|
36
|
+
export class CmsDeliveryError extends Error {
|
|
37
|
+
status?: number;
|
|
38
|
+
originalError?: unknown;
|
|
39
|
+
|
|
40
|
+
constructor(message: string, status?: number, originalError?: unknown) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = "CmsDeliveryError";
|
|
43
|
+
this.status = status;
|
|
44
|
+
this.originalError = originalError;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Unauthenticated 404 — public content not found. */
|
|
49
|
+
export class CmsDeliveryNotFoundError extends CmsDeliveryError {
|
|
50
|
+
constructor(message = "Content not found") {
|
|
51
|
+
super(message, 404);
|
|
52
|
+
this.name = "CmsDeliveryNotFoundError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS HTTP clients — the two delivery transports in one place.
|
|
3
|
+
*
|
|
4
|
+
* cmsDeliveryGet — UNAUTHENTICATED public CDN reads (a public delivery URL).
|
|
5
|
+
* connectGet — AUTHENTICATED Connect REST reads (`/services/data/vXX/...`).
|
|
6
|
+
*
|
|
7
|
+
* These are two DISTINCT transports that must never be crossed:
|
|
8
|
+
* - A public delivery URL is fetched AS-IS with `credentials: 'omit'`.
|
|
9
|
+
* - An authenticated Connect path needs the SF base URL + CSRF/session, added by `createDataSDK().fetch`. `sdk.fetch(path)`
|
|
10
|
+
*/
|
|
11
|
+
import { createDataSDK } from "@salesforce/platform-sdk";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
CmsDeliveryError,
|
|
15
|
+
CmsDeliveryNotFoundError,
|
|
16
|
+
CmsNotFoundError,
|
|
17
|
+
ConnectApiError,
|
|
18
|
+
} from "./errors";
|
|
19
|
+
|
|
20
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
21
|
+
// Unauthenticated public CDN transport
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
// Dev CORS: the browser can't reach the CDN cross-origin from localhost, and
|
|
25
|
+
// createDataSDK().fetch doesn't proxy absolute URLs. So in dev fetch the
|
|
26
|
+
// same-origin relative path (Vite `server.proxy['/cms']` forwards it); in prod
|
|
27
|
+
// fetch the absolute URL.
|
|
28
|
+
function resolveFetchUrl(deliveryUrl: string): string {
|
|
29
|
+
if (import.meta.env.DEV) {
|
|
30
|
+
const parsedUrl = new URL(deliveryUrl);
|
|
31
|
+
return parsedUrl.pathname + parsedUrl.search;
|
|
32
|
+
}
|
|
33
|
+
return deliveryUrl;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fetch a public CMS delivery URL directly (unauthenticated). `signal` is only for a
|
|
38
|
+
* genuinely per-consumer request.
|
|
39
|
+
*/
|
|
40
|
+
export async function cmsDeliveryGet<T>(url: string, signal?: AbortSignal): Promise<T> {
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(resolveFetchUrl(url), {
|
|
43
|
+
// Public CDN endpoint — carries no session;
|
|
44
|
+
credentials: "omit",
|
|
45
|
+
signal,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (response.status === 404) {
|
|
49
|
+
throw new CmsDeliveryNotFoundError();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
throw new CmsDeliveryError(
|
|
54
|
+
`CMS delivery error: ${response.status} ${response.statusText}`,
|
|
55
|
+
response.status,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (await response.json()) as T;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof CmsDeliveryError) throw error;
|
|
62
|
+
// Preserve AbortError so callers can distinguish cancellation from failure.
|
|
63
|
+
if (error instanceof DOMException && error.name === "AbortError") throw error;
|
|
64
|
+
throw new CmsDeliveryError("CMS delivery request failed", undefined, error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
69
|
+
// Authenticated Connect transport
|
|
70
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Fetch an authenticated Connect REST path via `createDataSDK().fetch`.
|
|
74
|
+
*/
|
|
75
|
+
export async function connectGet<T>(pathOrUrl: string, signal?: AbortSignal): Promise<T> {
|
|
76
|
+
try {
|
|
77
|
+
const sdk = await createDataSDK();
|
|
78
|
+
const response = await sdk.fetch?.(pathOrUrl, { signal });
|
|
79
|
+
|
|
80
|
+
if (!response) {
|
|
81
|
+
throw new ConnectApiError("Connect API response is undefined");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (response.status === 404) {
|
|
85
|
+
throw new CmsNotFoundError();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new ConnectApiError(
|
|
90
|
+
`Connect API error: ${response.status} ${response.statusText}`,
|
|
91
|
+
response.status,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (await response.json()) as T;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof ConnectApiError) throw error;
|
|
98
|
+
// Preserve AbortError so callers can distinguish cancellation from failure.
|
|
99
|
+
if (error instanceof DOMException && error.name === "AbortError") throw error;
|
|
100
|
+
throw new ConnectApiError("Connect API request failed", undefined, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment values for the CMS toolkit runtime:
|
|
3
|
+
* - API_VERSION — Salesforce Connect REST API version (Vite define).
|
|
4
|
+
* - CONTENT_CATALOG_URL — where to fetch content-metadata.json.
|
|
5
|
+
* - getCmsInstanceOrigin() — Salesforce instance origin for prefixing media URLs.
|
|
6
|
+
*
|
|
7
|
+
* The CMS `channelId` is not here — it ships in the catalog (see api/catalog.ts).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Salesforce Connect REST API version, injected by @salesforce/vite-plugin-ui-bundle. */
|
|
11
|
+
declare const __SF_API_VERSION__: string;
|
|
12
|
+
export const API_VERSION: string =
|
|
13
|
+
typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "64.0";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* URL of the public content-metadata.json, served from the uiBundle base.
|
|
17
|
+
* Override with `VITE_CONTENT_CATALOG_URL`. See api/catalog.ts.
|
|
18
|
+
*/
|
|
19
|
+
export const CONTENT_CATALOG_URL: string =
|
|
20
|
+
(import.meta.env.VITE_CONTENT_CATALOG_URL as string | undefined) ??
|
|
21
|
+
`${import.meta.env.BASE_URL}content-metadata.json`;
|
|
22
|
+
|
|
23
|
+
/** Minimal shape of the parts of `globalThis.SFDC_ENV` we read — declared locally so
|
|
24
|
+
* the toolkit needs no ambient platform typings in a consumer's tsconfig. */
|
|
25
|
+
interface SfdcEnvLike {
|
|
26
|
+
/** Salesforce org force.com URL, e.g. `https://myorg.lightning.force.com`. */
|
|
27
|
+
orgUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the Salesforce instance origin (from `globalThis.SFDC_ENV.orgUrl`) for
|
|
32
|
+
* prefixing root-relative CMS media URLs. Fail-open: returns `undefined` when the
|
|
33
|
+
* global is absent — pass it straight to `resolveCmsImageUrl`, which then leaves a
|
|
34
|
+
* root-relative path unchanged rather than throwing.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const src = resolveCmsImageUrl(body.bannerImage, {
|
|
39
|
+
* instanceOrigin: getCmsInstanceOrigin(),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function getCmsInstanceOrigin(): string | undefined {
|
|
44
|
+
const env = (globalThis as { SFDC_ENV?: SfdcEnvLike }).SFDC_ENV;
|
|
45
|
+
return env?.orgUrl;
|
|
46
|
+
}
|
package/dist/force-app/main/default/uiBundles/feature-cms-toolkit/src/features/cmsToolkit/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feature-cms-toolkit — framework-agnostic CMS delivery APIs.
|
|
3
|
+
*
|
|
4
|
+
* A small, stable, additive-only surface for reading Salesforce CMS delivery
|
|
5
|
+
* content. Pure JS/TS — NO React/Vue/Angular imports.
|
|
6
|
+
*
|
|
7
|
+
* - getCmsContentByUrl(url, options?) — public URL (unauthenticated CDN)
|
|
8
|
+
* - getCmsContentByKey(key, options?) — one item by contentKey (throws)
|
|
9
|
+
* - getCmsContentByKeys(keys, options?) — many by contentKey (best-effort)
|
|
10
|
+
* - resolveCmsImageUrl(field, options?) — image field → loadable URL
|
|
11
|
+
* - getCmsInstanceOrigin() — instance origin for media prefixing
|
|
12
|
+
* - resolveEffectiveContentKey(key, catalogUrl?) — catalog source→target key remap
|
|
13
|
+
* - getCmsDefaultChannelId(catalogUrl?) — catalog default channelId (fail-open)
|
|
14
|
+
* - decodeRichHtmlEntities(encoded) — decode RichText before injection
|
|
15
|
+
*
|
|
16
|
+
* This is the public entry point. When the feature is copied into a consuming app,
|
|
17
|
+
* `src/features/cmsToolkit/index.ts` is the single import target — consumers import
|
|
18
|
+
* from `.../features/cmsToolkit`.
|
|
19
|
+
* New capability is added ADDITIVELY (new optional option, new named export, new
|
|
20
|
+
* error subclass) — never by changing an existing signature.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// ── reads + utility ─────────────────────────────────────────────────────────
|
|
24
|
+
export { getCmsContentByUrl, getCmsContentByKey, getCmsContentByKeys } from "./api/cmsContent";
|
|
25
|
+
export { decodeRichHtmlEntities } from "./utils/htmlEntities";
|
|
26
|
+
export { resolveCmsImageUrl } from "./utils/imageUrl";
|
|
27
|
+
export { getCmsInstanceOrigin } from "./config/env";
|
|
28
|
+
export { resolveEffectiveContentKey, getCmsDefaultChannelId } from "./api/catalog";
|
|
29
|
+
|
|
30
|
+
// ── errors (stable for instanceof) ──────────────────────────────────────────
|
|
31
|
+
export {
|
|
32
|
+
CmsDeliveryError,
|
|
33
|
+
CmsDeliveryNotFoundError,
|
|
34
|
+
ConnectApiError,
|
|
35
|
+
CmsNotFoundError,
|
|
36
|
+
} from "./api/errors";
|
|
37
|
+
|
|
38
|
+
// ── shared types ────────────────────────────────────────────────────────────
|
|
39
|
+
export type {
|
|
40
|
+
CmsContentBody,
|
|
41
|
+
CmsReadOptions,
|
|
42
|
+
CmsBulkResult,
|
|
43
|
+
CmsContentCatalog,
|
|
44
|
+
CmsImageField,
|
|
45
|
+
} from "./types/cms";
|
|
46
|
+
export type { CmsImageOptions } from "./utils/imageUrl";
|