@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,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/src/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";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS toolkit shared types (framework-agnostic).
|
|
3
|
+
*
|
|
4
|
+
* The public contract is tiny and grows ADDITIVELY only:
|
|
5
|
+
* - CmsReadOptions — the single options object every read method accepts. New
|
|
6
|
+
* parameters (locale, fields, apiVersion…) arrive as NEW OPTIONAL fields here,
|
|
7
|
+
* so no existing call site ever breaks.
|
|
8
|
+
* - CmsBulkResult — one per-key result for the array overload of getCmsContentByKey.
|
|
9
|
+
* - CmsContentBody — default body type; callers refine with their own TBody.
|
|
10
|
+
* - CmsContentCatalog — shape of the runtime public/content-metadata.json.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Default content body: an open bag of per-type fields. Callers refine via TBody. */
|
|
15
|
+
export type CmsContentBody = Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Structured image field as Delivery returns it — the one field that is an object, not
|
|
19
|
+
* a primitive. Two variants (`resolveCmsImageUrl` handles both):
|
|
20
|
+
* - CMS image (`source.type === 'imageReference'`): a root-relative top-level `url`
|
|
21
|
+
* plus `source.ref = { contentKey }`.
|
|
22
|
+
* - Foreign image (`source.type === 'url'`): no top-level `url`; the absolute url is
|
|
23
|
+
* the string in `source.ref`.
|
|
24
|
+
*/
|
|
25
|
+
export interface CmsImageField {
|
|
26
|
+
/** Resolved media path — ROOT-RELATIVE for a CMS imageReference; absent for a foreign url image. */
|
|
27
|
+
url?: string;
|
|
28
|
+
altText?: string;
|
|
29
|
+
overrideAltText?: boolean;
|
|
30
|
+
source?: {
|
|
31
|
+
type?: "url" | "imageReference" | string;
|
|
32
|
+
/** Legacy/alternate slot for a `type: 'url'` absolute url. */
|
|
33
|
+
url?: string;
|
|
34
|
+
mimeType?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
/**
|
|
37
|
+
* For `type: 'url'`, the absolute image URL STRING (the payload puts it HERE,
|
|
38
|
+
* not in `source.url`). For `type: 'imageReference'`, a `{ contentKey }` identity
|
|
39
|
+
* for a CMS media item, resolved via the optional `resolveRef` callback.
|
|
40
|
+
*/
|
|
41
|
+
ref?: string | { contentKey?: string };
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Options common to every read method. A required positional subject (url / key /
|
|
47
|
+
* keys) plus this ONE optional object. Every future parameter is a new optional
|
|
48
|
+
* field here — additive, never breaking.
|
|
49
|
+
*/
|
|
50
|
+
export interface CmsReadOptions {
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
channelId?: string;
|
|
53
|
+
// ← future options (locale, apiVersion, fields…) are ADDED here. Additive only.
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Bulk-read result for one requested contentKey. Best-effort: a key that is
|
|
58
|
+
* unpublished / wrong-channel / absent from the response comes back with `error`
|
|
59
|
+
* set instead of failing the whole batch. Matched BY contentKey, never positionally.
|
|
60
|
+
*/
|
|
61
|
+
export interface CmsBulkResult<TBody = CmsContentBody> {
|
|
62
|
+
/** The requested contentKey — echoed back so callers can match results. */
|
|
63
|
+
contentKey: string;
|
|
64
|
+
/** The unwrapped content body (with title lifted), when the key resolved. */
|
|
65
|
+
body?: TBody;
|
|
66
|
+
/** Populated when this key failed to resolve (e.g. CmsNotFoundError). */
|
|
67
|
+
error?: Error;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Shape of the runtime public/content-metadata.json. Grows additively.
|
|
72
|
+
* Loaded once and memoized; fail-open (missing/malformed → `{}`). See api/catalog.ts.
|
|
73
|
+
*/
|
|
74
|
+
export interface CmsContentCatalog {
|
|
75
|
+
channelId?: string;
|
|
76
|
+
contentKeyMap?: ReadonlyMap<string, string>;
|
|
77
|
+
// ← future: defaults, … (additive only)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Delivery envelope. BOTH transports (public CDN + authenticated Connect) return
|
|
82
|
+
* this same shape: the managed content item DIRECTLY.
|
|
83
|
+
* `contentBody` holds the per-type renderable fields.
|
|
84
|
+
*/
|
|
85
|
+
export interface CmsDeliveryEnvelope<TBody = CmsContentBody> {
|
|
86
|
+
/** Per-type renderable fields — its keys vary by content type. */
|
|
87
|
+
contentBody: TBody;
|
|
88
|
+
/** Envelope-level display title; merged into the body by unwrapContent. */
|
|
89
|
+
title?: string;
|
|
90
|
+
contentKey?: string;
|
|
91
|
+
publishedDate?: string;
|
|
92
|
+
urlName?: string;
|
|
93
|
+
language?: string;
|
|
94
|
+
unauthenticatedUrl?: string;
|
|
95
|
+
contentType?: { fullyQualifiedName?: string };
|
|
96
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode entity-encoded RichText (Delivery returns `"<div>…"`) to its literal
|
|
3
|
+
* characters before you sanitize + inject it. Sanitizing is the consumer's concern —
|
|
4
|
+
* add DOMPurify at your injection site.
|
|
5
|
+
*
|
|
6
|
+
* Pure JS, no DOM — works in browser, Node, and SSR. Decodes in a SINGLE pass, so a
|
|
7
|
+
* double-encoded payload (`&lt;`) decodes one level only (→ `<`). Never also
|
|
8
|
+
* HTML-escape the same string — the round-trip cancels out.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Named entities RichText delivery emits; everything else arrives as a numeric ref.
|
|
12
|
+
* Keys are without the leading `&`/trailing `;`. */
|
|
13
|
+
const NAMED_ENTITIES: Record<string, string> = {
|
|
14
|
+
amp: "&",
|
|
15
|
+
lt: "<",
|
|
16
|
+
gt: ">",
|
|
17
|
+
quot: '"',
|
|
18
|
+
apos: "'",
|
|
19
|
+
nbsp: " ",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// One reference per match: `&name;`, `{`, or `«` (hex case-insensitive).
|
|
23
|
+
const ENTITY_RE = /&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]*);/gi;
|
|
24
|
+
|
|
25
|
+
/** Resolve a numeric character reference (`#123` decimal or `#x7b` hex); returns the
|
|
26
|
+
* original text unchanged for invalid or out-of-range code points. */
|
|
27
|
+
function decodeNumericEntity(entityBody: string, fullMatch: string): string {
|
|
28
|
+
const codePoint =
|
|
29
|
+
entityBody[1] === "x" || entityBody[1] === "X"
|
|
30
|
+
? Number.parseInt(entityBody.slice(2), 16)
|
|
31
|
+
: Number.parseInt(entityBody.slice(1), 10);
|
|
32
|
+
|
|
33
|
+
// Reject NaN, surrogates, and anything past the Unicode max — fromCodePoint throws on these.
|
|
34
|
+
if (!Number.isFinite(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
|
|
35
|
+
return fullMatch;
|
|
36
|
+
}
|
|
37
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
|
|
38
|
+
return fullMatch;
|
|
39
|
+
}
|
|
40
|
+
return String.fromCodePoint(codePoint);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Decode entity-encoded RichText to its literal characters. Handles named entities
|
|
45
|
+
* (`<`), decimal (`<`), and hex (`<`) references in one pass; unknown
|
|
46
|
+
* names and invalid numeric references are left verbatim.
|
|
47
|
+
*/
|
|
48
|
+
export function decodeRichHtmlEntities(encoded: string): string {
|
|
49
|
+
if (!encoded || encoded.indexOf("&") === -1) return encoded;
|
|
50
|
+
|
|
51
|
+
return encoded.replace(ENTITY_RE, (fullMatch, entityBody: string) => {
|
|
52
|
+
if (entityBody[0] === "#") {
|
|
53
|
+
return decodeNumericEntity(entityBody, fullMatch);
|
|
54
|
+
}
|
|
55
|
+
const named = NAMED_ENTITIES[entityBody.toLowerCase()];
|
|
56
|
+
return named !== undefined ? named : fullMatch;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS image URL resolution. A Delivery image field (`CmsImageField`) does not hand you
|
|
3
|
+
* a ready `src`; this turns it into a loadable URL, covering both variants:
|
|
4
|
+
* - Foreign image (`source.type === 'url'`) → an absolute CDN url, returned as-is.
|
|
5
|
+
* - CMS image (`source.type === 'imageReference'`) → a root-relative `url`, prefixed
|
|
6
|
+
* with `options.instanceOrigin` when supplied (else returned unchanged).
|
|
7
|
+
*/
|
|
8
|
+
import type { CmsImageField } from "../types/cms";
|
|
9
|
+
|
|
10
|
+
/** Options for {@link resolveCmsImageUrl}. */
|
|
11
|
+
export interface CmsImageOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Instance origin (e.g. `https://my-org.my.salesforce.com`) used to prefix a
|
|
14
|
+
* root-relative media path. Absolute/protocol-relative URLs ignore it; omit it and
|
|
15
|
+
* a root-relative path is returned unchanged.
|
|
16
|
+
*/
|
|
17
|
+
instanceOrigin?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a nested `imageReference` contentKey to its media item — for the rare
|
|
20
|
+
* "references bag" payload with no top-level `url`. Returns the media field (with
|
|
21
|
+
* its own `url`), or undefined if unknown.
|
|
22
|
+
*/
|
|
23
|
+
resolveRef?: (contentKey: string) => CmsImageField | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Prefix a root-relative url with `origin`; leave absolute and protocol-relative urls untouched. */
|
|
27
|
+
function prefixOrigin(rawUrl: string, origin?: string): string {
|
|
28
|
+
if (/^https?:\/\//i.test(rawUrl) || rawUrl.startsWith("//")) return rawUrl;
|
|
29
|
+
if (rawUrl.startsWith("/") && origin) {
|
|
30
|
+
return `${origin.endsWith("/") ? origin.slice(0, -1) : origin}${rawUrl}`;
|
|
31
|
+
}
|
|
32
|
+
return rawUrl;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Extract the delivered (un-prefixed) image url from a `CmsImageField`, or undefined. */
|
|
36
|
+
function extractRawUrl(
|
|
37
|
+
field: CmsImageField,
|
|
38
|
+
resolveRef?: CmsImageOptions["resolveRef"],
|
|
39
|
+
): string | undefined {
|
|
40
|
+
// A top-level `url` is the resolved media path for a CMS imageReference image
|
|
41
|
+
// (root-relative) — it must win over the `source` branches below.
|
|
42
|
+
if (field.url) return field.url;
|
|
43
|
+
|
|
44
|
+
const source = field.source;
|
|
45
|
+
if (!source) return undefined;
|
|
46
|
+
|
|
47
|
+
// Foreign image: the absolute url lives in `source.ref` (a plain string) in the
|
|
48
|
+
// current payload; older shapes put it in `source.url`.
|
|
49
|
+
if (source.type === "url") {
|
|
50
|
+
if (typeof source.ref === "string") return source.ref;
|
|
51
|
+
if (source.url) return source.url;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// imageReference WITHOUT a top-level url (references-bag shape): resolve the CMS
|
|
56
|
+
// media item via the caller's callback. `ref` may be a bare contentKey string or
|
|
57
|
+
// a `{ contentKey }` object.
|
|
58
|
+
if (source.type === "imageReference" && resolveRef) {
|
|
59
|
+
const contentKey = typeof source.ref === "string" ? source.ref : source.ref?.contentKey;
|
|
60
|
+
if (!contentKey) return undefined;
|
|
61
|
+
return resolveRef(contentKey)?.url;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve a `CmsImageField` to a loadable image URL — external (absolute CDN) or CMS
|
|
69
|
+
* imageReference (root-relative, prefixed with `options.instanceOrigin`). Returns
|
|
70
|
+
* undefined when the field has no resolvable url.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // Foreign/CDN image — absolute url, origin not needed:
|
|
75
|
+
* resolveCmsImageUrl(body.bannerImage);
|
|
76
|
+
* // CMS image — root-relative, prefixed to load:
|
|
77
|
+
* resolveCmsImageUrl(body.bannerImage, { instanceOrigin });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function resolveCmsImageUrl(
|
|
81
|
+
field: CmsImageField | undefined,
|
|
82
|
+
options?: CmsImageOptions,
|
|
83
|
+
): string | undefined {
|
|
84
|
+
if (!field || typeof field !== "object") return undefined;
|
|
85
|
+
const rawUrl = extractRawUrl(field, options?.resolveRef);
|
|
86
|
+
if (!rawUrl) return undefined;
|
|
87
|
+
return prefixOrigin(rawUrl, options?.instanceOrigin);
|
|
88
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feature-cms-toolkit — framework-agnostic CMS delivery APIs.
|
|
3
|
+
*
|
|
4
|
+
* Package entry point. The public surface is defined in features/cmsToolkit/index.ts;
|
|
5
|
+
* this re-exports it so the toolkit can be consumed as a package or a local feature dir.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from "./features/cmsToolkit";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import salesforce from "@salesforce/vite-plugin-ui-bundle";
|
|
5
|
+
|
|
6
|
+
export default defineConfig(() => {
|
|
7
|
+
return {
|
|
8
|
+
plugins: [salesforce({ debug: true })] as import("vite").PluginOption[],
|
|
9
|
+
|
|
10
|
+
build: {
|
|
11
|
+
outDir: resolve(__dirname, "dist"),
|
|
12
|
+
assetsDir: "assets",
|
|
13
|
+
sourcemap: false,
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
resolve: {
|
|
17
|
+
alias: {
|
|
18
|
+
"@": path.resolve(__dirname, "./src"),
|
|
19
|
+
"@api": path.resolve(__dirname, "./src/features/cmsToolkit/api"),
|
|
20
|
+
"@config": path.resolve(__dirname, "./src/features/cmsToolkit/config"),
|
|
21
|
+
"@types": path.resolve(__dirname, "./src/features/cmsToolkit/types"),
|
|
22
|
+
"@utils": path.resolve(__dirname, "./src/features/cmsToolkit/utils"),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
});
|