@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,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Run from SFDX project root: install dependencies, build, and launch the dev server
|
|
4
|
+
* for the UI bundle in force-app/main/default/uiBundles/.
|
|
5
|
+
*
|
|
6
|
+
* Usage: npm run sf-project-setup
|
|
7
|
+
* (from the directory that contains force-app/ and sfdx-project.json)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { resolve, dirname } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { readdirSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
|
|
15
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const ROOT = resolve(__dirname, '..');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* npm strips .gitignore from published packages — generate them on first run.
|
|
20
|
+
* Templates are stored in scripts/gitignore-templates.json (generated at build
|
|
21
|
+
* time from the actual .gitignore files). The JSON may not exist in git-cloned
|
|
22
|
+
* distributions where .gitignore is already present, so loading is best-effort.
|
|
23
|
+
*/
|
|
24
|
+
function loadGitignoreTemplates() {
|
|
25
|
+
const templatesPath = resolve(__dirname, 'gitignore-templates.json');
|
|
26
|
+
if (!existsSync(templatesPath)) return null;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(readFileSync(templatesPath, 'utf8'));
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ensureGitignore(dir, content) {
|
|
35
|
+
if (!content) return;
|
|
36
|
+
const gitignorePath = resolve(dir, '.gitignore');
|
|
37
|
+
if (!existsSync(gitignorePath)) {
|
|
38
|
+
writeFileSync(gitignorePath, content, 'utf8');
|
|
39
|
+
console.log(`Created .gitignore in ${dir}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function resolveUIBundlesDir() {
|
|
44
|
+
const sfdxPath = resolve(ROOT, 'sfdx-project.json');
|
|
45
|
+
if (!existsSync(sfdxPath)) {
|
|
46
|
+
console.error('Error: sfdx-project.json not found at project root.');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
const sfdxProject = JSON.parse(readFileSync(sfdxPath, 'utf8'));
|
|
50
|
+
const pkgDir = sfdxProject?.packageDirectories?.[0]?.path;
|
|
51
|
+
if (!pkgDir) {
|
|
52
|
+
console.error('Error: No packageDirectories[].path found in sfdx-project.json.');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
return resolve(ROOT, pkgDir, 'main', 'default', 'uiBundles');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function discoverUIBundleDir() {
|
|
59
|
+
const uiBundlesDir = resolveUIBundlesDir();
|
|
60
|
+
if (!existsSync(uiBundlesDir)) {
|
|
61
|
+
console.error(`Error: uiBundles directory not found: ${uiBundlesDir}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const entries = readdirSync(uiBundlesDir, { withFileTypes: true });
|
|
65
|
+
const dirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith('.'));
|
|
66
|
+
if (dirs.length === 0) {
|
|
67
|
+
console.error(`Error: No UI bundle folder found under ${uiBundlesDir}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
if (dirs.length > 1) {
|
|
71
|
+
console.log(`Multiple UI bundles found; using first: ${dirs[0].name}`);
|
|
72
|
+
}
|
|
73
|
+
return resolve(uiBundlesDir, dirs[0].name);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function run(label, cmd, args, opts) {
|
|
77
|
+
console.log(`\n--- ${label} ---\n`);
|
|
78
|
+
const result = spawnSync(cmd, args, { stdio: 'inherit', ...opts });
|
|
79
|
+
if (result.status !== 0) {
|
|
80
|
+
process.exit(result.status ?? 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Ensure .gitignore files exist (npm strips them from published packages).
|
|
85
|
+
const gitignoreTemplates = loadGitignoreTemplates();
|
|
86
|
+
if (gitignoreTemplates) {
|
|
87
|
+
ensureGitignore(ROOT, gitignoreTemplates.sfdx);
|
|
88
|
+
const bundlesDir = resolveUIBundlesDir();
|
|
89
|
+
if (existsSync(bundlesDir)) {
|
|
90
|
+
for (const entry of readdirSync(bundlesDir, { withFileTypes: true })) {
|
|
91
|
+
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
92
|
+
ensureGitignore(resolve(bundlesDir, entry.name), gitignoreTemplates.webapp);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const uiBundleDir = discoverUIBundleDir();
|
|
99
|
+
console.log('SFDX project root:', ROOT);
|
|
100
|
+
console.log('UI bundle directory:', uiBundleDir);
|
|
101
|
+
|
|
102
|
+
run('npm install', 'npm', ['install', '--registry', 'https://registry.npmjs.org/'], { cwd: uiBundleDir });
|
|
103
|
+
run('npm run build', 'npm', ['run', 'build'], { cwd: uiBundleDir });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build / CI gate: validate this package's org-setup.config.json against the
|
|
3
|
+
* shared schema (W-23043729, spec §5.2).
|
|
4
|
+
*
|
|
5
|
+
* Ships inside the SFDX project template, so a generated app can self-check its
|
|
6
|
+
* org-setup.config.json in its own CI:
|
|
7
|
+
* npm run validate:org-setup-config
|
|
8
|
+
*
|
|
9
|
+
* Uses the SAME validateConfig + schema as org-setup.mjs runtime, so build-time
|
|
10
|
+
* and runtime checks can never drift. A missing config file is OK (not every
|
|
11
|
+
* project ships one); a present-but-invalid config fails the gate.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { resolve, dirname } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
import { validateConfig } from './org-setup-config-schema.mjs';
|
|
19
|
+
|
|
20
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const configPath = resolve(__dirname, 'org-setup.config.json');
|
|
22
|
+
|
|
23
|
+
if (!existsSync(configPath)) {
|
|
24
|
+
console.log('✓ org-setup.config.json: not present (nothing to validate)');
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result = validateConfig(readFileSync(configPath, 'utf8'), configPath);
|
|
29
|
+
if (result.ok) {
|
|
30
|
+
console.log('✓ org-setup.config.json');
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.error('❌ org-setup.config.json is invalid:');
|
|
35
|
+
for (const err of result.errors) {
|
|
36
|
+
console.error(` - ${err}`);
|
|
37
|
+
}
|
|
38
|
+
process.exit(1);
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/ui-bundle-template-feature-cms-toolkit",
|
|
3
|
+
"version": "11.59.1",
|
|
4
|
+
"description": "CMS toolkit — framework-agnostic APIs for reading Salesforce CMS delivery content (by public URL or contentKey, single or bulk) and decoding RichText and other utility functions",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts",
|
|
9
|
+
"types": "src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts",
|
|
13
|
+
"import": "./src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts",
|
|
14
|
+
"default": "./src/force-app/main/default/uiBundles/feature-cms-toolkit/src/index.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@salesforce/platform-sdk": "^11.59.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@salesforce/ui-bundle": "^11.59.1",
|
|
32
|
+
"vite": "^7.3.5"
|
|
33
|
+
},
|
|
34
|
+
"nx": {
|
|
35
|
+
"targets": {
|
|
36
|
+
"build": {
|
|
37
|
+
"executor": "@salesforce/ui-bundle-template-cli:apply-patches"
|
|
38
|
+
},
|
|
39
|
+
"watch": {
|
|
40
|
+
"executor": "@salesforce/ui-bundle-template-cli:watch-patches"
|
|
41
|
+
},
|
|
42
|
+
"build:dist-app": {
|
|
43
|
+
"executor": "@salesforce/ui-bundle-template-cli:build-dist-app"
|
|
44
|
+
},
|
|
45
|
+
"dev": {
|
|
46
|
+
"executor": "@salesforce/ui-bundle-template-cli:dev-server"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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
|
+
}
|