@exdst-sitecore-content-sdk/astro 0.0.24 → 0.0.25
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/package.json +7 -12
- package/src/context.ts +1 -1
- package/src/client/sitecore-astro-client.test.ts +0 -267
- package/src/components/AstroImage.astro.test.ts +0 -541
- package/src/components/Date.astro.test.ts +0 -197
- package/src/components/EditingScripts.astro.test.ts +0 -267
- package/src/components/ErrorBoundary.astro.test.ts +0 -252
- package/src/components/ErrorComponent.astro.test.ts +0 -31
- package/src/components/FieldMetadata.astro.test.ts +0 -40
- package/src/components/File.astro.test.ts +0 -68
- package/src/components/HiddenRendering.astro.test.ts +0 -36
- package/src/components/Image.astro.test.ts +0 -438
- package/src/components/Link.astro.test.ts +0 -261
- package/src/components/MissingComponent.astro.test.ts +0 -21
- package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
- package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
- package/src/components/RichText.astro.test.ts +0 -205
- package/src/components/Text.astro.test.ts +0 -273
- package/src/config/define-config.test.ts +0 -526
- package/src/config-cli/define-cli-config.test.ts +0 -67
- package/src/editing/editing-config-middleware.test.ts +0 -164
- package/src/editing/editing-render-middleware.test.ts +0 -1143
- package/src/editing/render-middleware.test.ts +0 -57
- package/src/editing/utils.test.ts +0 -1212
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
- package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
- package/src/middleware/middleware.test.ts +0 -520
- package/src/middleware/multisite-middleware.test.ts +0 -736
- package/src/middleware/robots-middleware.test.ts +0 -129
- package/src/middleware/sitemap-middleware.test.ts +0 -184
- package/src/tests/astro-helpers.ts +0 -61
- package/src/tests/helpers.ts +0 -46
- package/src/tests/personalizeData.ts +0 -63
- package/src/tests/test-components/CustomErrorComponent.astro +0 -3
- package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
- package/src/tests/test-components/CustomMissingComponent.astro +0 -9
- package/src/tests/test-components/DownloadCallout.astro +0 -12
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
- package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
- package/src/tests/test-components/Home.astro +0 -12
- package/src/tests/test-components/SxaRichText.astro +0 -23
- package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
- package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
- package/src/tests/test-components/TestComponent.astro +0 -9
- package/src/tests/test-components/TestComponentWithError.astro +0 -4
- package/src/tests/test-components/TestComponentWithField.astro +0 -17
- package/src/tests/test-components/TestHeader.astro +0 -8
- package/src/tests/test-components/TestLogo.astro +0 -5
- package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
- package/src/tests/test-components/TestWrapperComponent.astro +0 -5
- package/src/tests/test-components/generate-map/Button.astro +0 -4
- package/src/tests/test-components/generate-map/Link.astro +0 -4
- package/src/tests/test-components/map-components/Bar.astro +0 -0
- package/src/tests/test-components/map-components/Baz.astro +0 -0
- package/src/tests/test-components/map-components/Foo.astro +0 -0
- package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
- package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
- package/src/tests/test-components/map-components/Qux.astro +0 -0
- package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
- package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
- package/src/tests/test-components/map-components/random-file.txt +0 -0
- package/src/tests/test-data/metadata-data.ts +0 -86
- package/src/tests/test-data/normal-mode-data.ts +0 -466
- package/src/tests/vitest.setup.ts +0 -4
- package/src/tools/generate-map.test.ts +0 -201
- package/src/tools/templating/components.test.ts +0 -318
- package/src/tools/templating/default-component.test.ts +0 -31
- package/src/utils/utils.test.ts +0 -111
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exdst-sitecore-content-sdk/astro",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
|
+
"description": "Astro Content SDK for Sitecore AI (XM Cloud)",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"publishConfig": {
|
|
@@ -9,12 +10,12 @@
|
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"typecheck": "tsc -p tsconfig.json",
|
|
13
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
12
14
|
"lint": "eslint \"./src/**/*.ts\"",
|
|
13
|
-
"test": "npm run test:unit
|
|
15
|
+
"test": "npm run test:unit && npm run test:components",
|
|
14
16
|
"test:unit": "mocha \"./src/**/*.test.ts\" --ignore \"src/**/*.astro.test.ts\"",
|
|
15
17
|
"test:components": "vitest run --config ./vitest.config.ts",
|
|
16
18
|
"coverage": "nyc npm test",
|
|
17
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/client/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false",
|
|
18
19
|
"api-extractor": "api-extractor run --local --verbose",
|
|
19
20
|
"api-extractor:verify": "api-extractor run"
|
|
20
21
|
},
|
|
@@ -58,7 +59,6 @@
|
|
|
58
59
|
"eslint-plugin-import": "2.32.0",
|
|
59
60
|
"eslint-plugin-jsdoc": "52.0.3",
|
|
60
61
|
"eslint-plugin-prettier": "^4.0.0",
|
|
61
|
-
"glob": "^11.0.2",
|
|
62
62
|
"happy-dom": "^16.7.3",
|
|
63
63
|
"mocha": "^11.2.2",
|
|
64
64
|
"nyc": "^17.1.0",
|
|
@@ -72,7 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@sitecore-content-sdk/analytics-core": "^2.0.1",
|
|
75
|
-
"@sitecore-content-sdk/events": "^2.0.1"
|
|
75
|
+
"@sitecore-content-sdk/events": "^2.0.1",
|
|
76
|
+
"astro": "^6.0.0"
|
|
76
77
|
},
|
|
77
78
|
"dependencies": {
|
|
78
79
|
"@sitecore-content-sdk/content": "^2.0.1",
|
|
@@ -96,11 +97,5 @@
|
|
|
96
97
|
"./tools": "./src/tools/index.ts",
|
|
97
98
|
"./utils": "./src/utils/index.ts",
|
|
98
99
|
"./components/Placeholder": "./src/components/Placeholder/index.ts"
|
|
99
|
-
}
|
|
100
|
-
"description": "",
|
|
101
|
-
"files": [
|
|
102
|
-
"src",
|
|
103
|
-
"index.ts",
|
|
104
|
-
"readme.md"
|
|
105
|
-
]
|
|
100
|
+
}
|
|
106
101
|
}
|
package/src/context.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { map } from 'nanostores';
|
|
|
2
2
|
import { ComponentMap } from './sharedTypes/component-props';
|
|
3
3
|
import { Page } from '@sitecore-content-sdk/content/client';
|
|
4
4
|
import { SitecoreConfig } from '@sitecore-content-sdk/content/config';
|
|
5
|
-
import { DictionaryPhrases } from '@sitecore-content-sdk/content/
|
|
5
|
+
import { DictionaryPhrases } from '@sitecore-content-sdk/content/i18n';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Nanostore map holding Sitecore page, API config, component map, and dictionary for the current request or app scope.
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import * as chai from 'chai';
|
|
5
|
-
import sinon from 'sinon';
|
|
6
|
-
import sinonChai from 'sinon-chai';
|
|
7
|
-
import { SitecoreAstroClient } from './sitecore-astro-client';
|
|
8
|
-
import { DefaultRetryStrategy } from '@sitecore-content-sdk/core';
|
|
9
|
-
import { SITE_PREFIX } from '@sitecore-content-sdk/content/site';
|
|
10
|
-
import { layoutData, componentsWithExperiencesArray } from '../tests/personalizeData';
|
|
11
|
-
import { VARIANT_PREFIX } from '@sitecore-content-sdk/content/personalize';
|
|
12
|
-
|
|
13
|
-
chai.use(sinonChai);
|
|
14
|
-
|
|
15
|
-
describe('SitecoreClient', () => {
|
|
16
|
-
const sandbox = sinon.createSandbox();
|
|
17
|
-
const defaultInitOptions = {
|
|
18
|
-
api: {
|
|
19
|
-
edge: {
|
|
20
|
-
contextId: 'test-context-id',
|
|
21
|
-
clientContextId: 'client-context-id',
|
|
22
|
-
edgeUrl: 'https://edge.example.com',
|
|
23
|
-
},
|
|
24
|
-
local: {
|
|
25
|
-
apiHost: 'http://local.example.com',
|
|
26
|
-
apiKey: 'test-api-key',
|
|
27
|
-
path: '/api/graph/test',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
editingSecret: '********-****',
|
|
31
|
-
retries: {
|
|
32
|
-
count: 3,
|
|
33
|
-
retryStrategy: sinon.createStubInstance(DefaultRetryStrategy),
|
|
34
|
-
},
|
|
35
|
-
defaultSite: 'default-site',
|
|
36
|
-
defaultLanguage: 'en',
|
|
37
|
-
multisite: {
|
|
38
|
-
enabled: true,
|
|
39
|
-
useCookieResolution: () => true,
|
|
40
|
-
},
|
|
41
|
-
layout: { formatLayoutQuery: sandbox.stub() },
|
|
42
|
-
dictionary: { caching: { enabled: true, timeout: 60000 } },
|
|
43
|
-
disableCodeGeneration: false,
|
|
44
|
-
rewriteMediaUrls: false,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
let sitecoreClient = new SitecoreAstroClient(defaultInitOptions);
|
|
48
|
-
|
|
49
|
-
let layoutServiceStub = {
|
|
50
|
-
fetchLayoutData: sandbox.stub(),
|
|
51
|
-
};
|
|
52
|
-
let dictionaryServiceStub = {
|
|
53
|
-
fetchDictionaryData: sandbox.stub(),
|
|
54
|
-
};
|
|
55
|
-
let errorPagesServiceStub = {
|
|
56
|
-
fetchErrorPages: sandbox.stub(),
|
|
57
|
-
};
|
|
58
|
-
let editingServiceStub = {
|
|
59
|
-
fetchEditingData: sandbox.stub(),
|
|
60
|
-
fetchDictionaryData: sandbox.stub(),
|
|
61
|
-
};
|
|
62
|
-
let restComponentServiceStub = {
|
|
63
|
-
fetchComponentData: sandbox.stub(),
|
|
64
|
-
};
|
|
65
|
-
let sitePathServiceStub = {
|
|
66
|
-
fetchSiteRoutes: sandbox.stub(),
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
layoutServiceStub = {
|
|
71
|
-
fetchLayoutData: sandbox.stub(),
|
|
72
|
-
};
|
|
73
|
-
dictionaryServiceStub = {
|
|
74
|
-
fetchDictionaryData: sandbox.stub(),
|
|
75
|
-
};
|
|
76
|
-
errorPagesServiceStub = {
|
|
77
|
-
fetchErrorPages: sandbox.stub(),
|
|
78
|
-
};
|
|
79
|
-
editingServiceStub = {
|
|
80
|
-
fetchEditingData: sandbox.stub(),
|
|
81
|
-
fetchDictionaryData: sandbox.stub(),
|
|
82
|
-
};
|
|
83
|
-
restComponentServiceStub = {
|
|
84
|
-
fetchComponentData: sandbox.stub(),
|
|
85
|
-
};
|
|
86
|
-
sitePathServiceStub = {
|
|
87
|
-
fetchSiteRoutes: sandbox.stub(),
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
sitecoreClient = new SitecoreAstroClient(defaultInitOptions);
|
|
91
|
-
|
|
92
|
-
(sitecoreClient as any).layoutService = layoutServiceStub;
|
|
93
|
-
(sitecoreClient as any).dictionaryService = dictionaryServiceStub;
|
|
94
|
-
(sitecoreClient as any).errorPagesService = errorPagesServiceStub;
|
|
95
|
-
(sitecoreClient as any).editingService = editingServiceStub;
|
|
96
|
-
(sitecoreClient as any).componentService = restComponentServiceStub;
|
|
97
|
-
(sitecoreClient as any).sitePathService = sitePathServiceStub;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('getPage', () => {
|
|
101
|
-
it('should personalize page layout when variants present in path', async () => {
|
|
102
|
-
const path = `${VARIANT_PREFIX}variant1/${VARIANT_PREFIX}mountain_bike_audience/test/path`;
|
|
103
|
-
const locale = 'en-US';
|
|
104
|
-
const testLayoutData = structuredClone(layoutData);
|
|
105
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
106
|
-
sandbox.stub(sitecoreClient, 'getHeadLinks').returns([]);
|
|
107
|
-
|
|
108
|
-
const result = await sitecoreClient.getPage(path, { locale });
|
|
109
|
-
|
|
110
|
-
expect(result?.layout.sitecore.route?.placeholders).to.deep.equal({
|
|
111
|
-
'content-sdk-main': [...componentsWithExperiencesArray],
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should use personalize details passed in page options over variants present in path', async () => {
|
|
116
|
-
const path = `${VARIANT_PREFIX}variant1/${VARIANT_PREFIX}sand_bike_audience/test/path`;
|
|
117
|
-
const locale = 'en-US';
|
|
118
|
-
const testLayoutData = structuredClone(layoutData);
|
|
119
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
120
|
-
sandbox.stub(sitecoreClient, 'getHeadLinks').returns([]);
|
|
121
|
-
|
|
122
|
-
const result = await sitecoreClient.getPage(path, {
|
|
123
|
-
locale,
|
|
124
|
-
personalize: {
|
|
125
|
-
variantId: 'variant2',
|
|
126
|
-
componentVariantIds: ['mountain_bike_audience'],
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(result?.layout.sitecore.route?.placeholders).to.deep.equal({
|
|
131
|
-
'content-sdk-main': [...componentsWithExperiencesArray],
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should pass site from path to base getPage method', async () => {
|
|
136
|
-
const path = `${SITE_PREFIX}mysite/test/path`;
|
|
137
|
-
const locale = 'en-US';
|
|
138
|
-
const testLayoutData = structuredClone(layoutData);
|
|
139
|
-
|
|
140
|
-
sandbox.stub(sitecoreClient, 'parsePath').returns('/test/path');
|
|
141
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
142
|
-
|
|
143
|
-
await sitecoreClient.getPage(path, {
|
|
144
|
-
locale,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
148
|
-
locale,
|
|
149
|
-
site: 'mysite',
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should use site passed in page options over site parsed from path', async () => {
|
|
154
|
-
const path = `${SITE_PREFIX}mysite/test/path`;
|
|
155
|
-
const locale = 'en-US';
|
|
156
|
-
const testLayoutData = structuredClone(layoutData);
|
|
157
|
-
|
|
158
|
-
sandbox.stub(sitecoreClient, 'parsePath').returns('/test/path');
|
|
159
|
-
|
|
160
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
161
|
-
|
|
162
|
-
await sitecoreClient.getPage(path, {
|
|
163
|
-
locale,
|
|
164
|
-
site: 'other-site',
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
168
|
-
locale,
|
|
169
|
-
site: 'other-site',
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('getSiteNameFromPath', () => {
|
|
175
|
-
it('should get site name correctly with string path', () => {
|
|
176
|
-
const path = '/some/path';
|
|
177
|
-
const siteInfo = { name: 'default-site', hostName: '*', language: 'en' };
|
|
178
|
-
|
|
179
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
180
|
-
|
|
181
|
-
expect(result).to.equal(siteInfo.name);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should get site name correctly with array path', () => {
|
|
185
|
-
const path = [`${SITE_PREFIX}other-site`, '/some', 'path'];
|
|
186
|
-
const siteInfo = { name: 'other-site', hostName: '*', language: 'en' };
|
|
187
|
-
|
|
188
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
189
|
-
|
|
190
|
-
expect(result).to.equal(siteInfo.name);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should get default site name when site not found', () => {
|
|
194
|
-
const path = ['wrong-path-yet-anoother-site', '/some', 'path'];
|
|
195
|
-
|
|
196
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
197
|
-
|
|
198
|
-
expect(result).to.equal('default-site');
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('parsePath', () => {
|
|
203
|
-
it('should return string path when accepting string[] path', () => {
|
|
204
|
-
const path = ['/some', 'path'];
|
|
205
|
-
const expectedPath = '/some/path';
|
|
206
|
-
|
|
207
|
-
const result = sitecoreClient.parsePath(path);
|
|
208
|
-
|
|
209
|
-
expect(result).to.equal(expectedPath);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('should strip site and variant prefixes from path', () => {
|
|
213
|
-
const path = `/${SITE_PREFIX}site1/${VARIANT_PREFIX}variant1/some/path`;
|
|
214
|
-
const expectedPath = '/some/path';
|
|
215
|
-
|
|
216
|
-
const result = sitecoreClient.parsePath(path);
|
|
217
|
-
|
|
218
|
-
expect(result).to.equal(expectedPath);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe('getPagePaths', () => {
|
|
223
|
-
it('should return static paths without site prefixes', async () => {
|
|
224
|
-
const paths = [
|
|
225
|
-
{ params: { path: ['_site_site-one', 'home'] }, locale: 'en' },
|
|
226
|
-
{ params: { path: ['_site_site-one', 'about'] }, locale: 'en' },
|
|
227
|
-
{ params: { path: ['_site_site-two', 'home'] }, locale: 'de-DE' },
|
|
228
|
-
];
|
|
229
|
-
|
|
230
|
-
const expectedPaths = [
|
|
231
|
-
{ params: { path: ['home'] }, locale: 'en' },
|
|
232
|
-
{ params: { path: ['about'] }, locale: 'en' },
|
|
233
|
-
{ params: { path: ['home'] }, locale: 'de-DE' },
|
|
234
|
-
];
|
|
235
|
-
|
|
236
|
-
sitePathServiceStub.fetchSiteRoutes.resolves(structuredClone(paths));
|
|
237
|
-
|
|
238
|
-
const result = await sitecoreClient.getPagePaths(['site-one'], ['en'], undefined);
|
|
239
|
-
|
|
240
|
-
expect(result).to.deep.equal(expectedPaths);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe('getPreview', () => {
|
|
245
|
-
it('should call base getPreview with preview data and fetch options', async () => {
|
|
246
|
-
const previewData = {
|
|
247
|
-
variantId: 'variant-a',
|
|
248
|
-
route: '/test/path',
|
|
249
|
-
language: 'en',
|
|
250
|
-
} as any;
|
|
251
|
-
const fetchOptions = {
|
|
252
|
-
retries: 2,
|
|
253
|
-
} as any;
|
|
254
|
-
|
|
255
|
-
const basePrototype = Object.getPrototypeOf(SitecoreAstroClient.prototype);
|
|
256
|
-
const superGetPreviewStub = sandbox.stub(basePrototype, 'getPreview').resolves(null);
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
await sitecoreClient.getPreview(previewData, fetchOptions);
|
|
260
|
-
|
|
261
|
-
expect(superGetPreviewStub).to.have.been.calledOnceWithExactly(previewData, fetchOptions);
|
|
262
|
-
} finally {
|
|
263
|
-
superGetPreviewStub.restore();
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|