@exdst-sitecore-content-sdk/astro 0.0.16 → 0.0.19
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/README.md +3 -3
- package/package.json +41 -42
- package/src/client/index.ts +1 -1
- package/src/client/sitecore-astro-client.test.ts +41 -20
- package/src/client/sitecore-astro-client.ts +74 -57
- package/src/components/AstroImage.astro +2 -2
- package/src/components/AstroImage.astro.test.ts +542 -0
- package/src/components/Date.astro +5 -1
- package/src/components/Date.astro.test.ts +197 -0
- package/src/components/DefaultEmptyFieldEditingComponentImage.astro +4 -0
- package/src/components/DefaultEmptyFieldEditingComponentText.astro +4 -0
- package/src/components/EditingScripts.astro +2 -2
- package/src/components/EditingScripts.astro.test.ts +267 -0
- package/src/components/ErrorBoundary.astro +8 -9
- package/src/components/ErrorBoundary.astro.test.ts +252 -0
- package/src/components/ErrorComponent.astro +16 -0
- package/src/components/ErrorComponent.astro.test.ts +31 -0
- package/src/components/FieldMetadata.astro +1 -1
- package/src/components/FieldMetadata.astro.test.ts +40 -0
- package/src/components/File.astro +5 -1
- package/src/components/File.astro.test.ts +68 -0
- package/src/components/HiddenRendering.astro.test.ts +36 -0
- package/src/components/Image.astro +18 -4
- package/src/components/Image.astro.test.ts +438 -0
- package/src/components/Link.astro +13 -1
- package/src/components/Link.astro.test.ts +261 -0
- package/src/components/MissingComponent.astro.test.ts +21 -0
- package/src/components/Placeholder/Placeholder.astro +18 -23
- package/src/components/Placeholder/Placeholder.astro.test.ts +1088 -0
- package/src/components/Placeholder/PlaceholderMetadata.astro +24 -18
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +228 -0
- package/src/components/Placeholder/PlaceholderUtils.astro +21 -40
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +149 -0
- package/src/components/Placeholder/models.ts +26 -17
- package/src/components/Placeholder/placeholder-utils.test.ts +153 -6
- package/src/components/Placeholder/placeholder-utils.ts +33 -11
- package/src/components/RichText.astro +9 -1
- package/src/components/RichText.astro.test.ts +205 -0
- package/src/components/Text.astro +15 -3
- package/src/components/Text.astro.test.ts +273 -0
- package/src/config/define-config.test.ts +5 -5
- package/src/config/define-config.ts +22 -42
- package/src/config-cli/define-cli-config.test.ts +5 -12
- package/src/config-cli/define-cli-config.ts +4 -8
- package/src/context.ts +42 -11
- package/src/debug.ts +13 -0
- package/src/editing/editing-config-middleware.test.ts +5 -7
- package/src/editing/editing-config-middleware.ts +11 -7
- package/src/editing/editing-render-middleware.test.ts +366 -24
- package/src/editing/editing-render-middleware.ts +34 -12
- package/src/editing/index.ts +2 -0
- package/src/editing/render-middleware.test.ts +1 -1
- package/src/editing/render-middleware.ts +1 -1
- package/src/editing/types.ts +39 -0
- package/src/editing/utils.test.ts +364 -4
- package/src/editing/utils.ts +82 -24
- package/src/enhancers/WithEmptyFieldEditingComponent.astro +1 -1
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +380 -0
- package/src/enhancers/WithFieldMetadata.astro.test.ts +113 -0
- package/src/index.ts +10 -7
- package/src/middleware/index.ts +4 -12
- package/src/middleware/middleware.test.ts +13 -0
- package/src/middleware/middleware.ts +12 -3
- package/src/middleware/multisite-middleware.test.ts +45 -50
- package/src/middleware/multisite-middleware.ts +33 -6
- package/src/middleware/robots-middleware.test.ts +20 -4
- package/src/middleware/robots-middleware.ts +10 -3
- package/src/middleware/sitemap-middleware.test.ts +35 -3
- package/src/middleware/sitemap-middleware.ts +7 -6
- package/src/services/component-props-service.ts +7 -6
- package/src/sharedTypes/component-props.ts +15 -4
- package/src/site/index.ts +1 -1
- package/src/tests/astro-helpers.ts +61 -0
- package/src/tests/test-components/CustomErrorComponent.astro +3 -0
- package/src/tests/test-components/CustomHiddenRendering.astro +10 -0
- package/src/tests/test-components/CustomMissingComponent.astro +9 -0
- package/src/tests/test-components/DownloadCallout.astro +12 -0
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +5 -0
- package/src/tests/test-components/ErrorBoundaryWithError.astro +10 -0
- package/src/tests/test-components/Home.astro +12 -0
- package/src/tests/test-components/SxaRichText.astro +23 -0
- package/src/tests/test-components/SxaRichTextDefault.astro +7 -0
- package/src/tests/test-components/SxaRichTextWithTitle.astro +8 -0
- package/src/tests/test-components/TestComponent.astro +9 -0
- package/src/tests/test-components/TestComponentWithError.astro +4 -0
- package/src/tests/test-components/TestComponentWithField.astro +17 -0
- package/src/tests/test-components/TestHeader.astro +8 -0
- package/src/tests/test-components/TestLogo.astro +5 -0
- package/src/tests/test-components/TestParentWrapperComponent.astro +5 -0
- package/src/tests/test-components/TestWrapperComponent.astro +5 -0
- package/src/tests/test-data/metadata-data.ts +86 -0
- package/src/tests/test-data/normal-mode-data.ts +466 -0
- package/src/tests/vitest.setup.ts +4 -0
- package/src/tools/generate-map.ts +4 -3
- package/src/tools/index.ts +2 -4
- package/src/tools/templating/components.test.ts +100 -87
- package/src/tools/templating/components.ts +2 -1
- package/src/tools/templating/default-component.ts +3 -8
- package/src/utils/utils.ts +20 -2
- /package/src/{test-data → tests}/helpers.ts +0 -0
- /package/src/{test-data → tests}/personalizeData.ts +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Bar.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Baz.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Foo.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Hero.variant.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/NotComponent.bsx +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Qux.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/folded/Folded.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/folded/random-file-2.docx +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/random-file.txt +0 -0
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Sitecore Content SDK for Astro
|
|
2
|
-
|
|
3
|
-
This module contains Astro components and integration for Sitecore Content SDK.
|
|
1
|
+
# Sitecore Content SDK for Astro
|
|
2
|
+
|
|
3
|
+
This module contains Astro components and integration for Sitecore Content SDK.
|
package/package.json
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exdst-sitecore-content-sdk/astro",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": "./src/index.ts",
|
|
7
|
-
"./*": "./src/*",
|
|
8
|
-
"./context": "./src/context.ts",
|
|
9
|
-
"./editing": "./src/editing/index.ts",
|
|
10
|
-
"./utils": "./src/utils/index.ts",
|
|
11
|
-
"./client": "./src/client/index.ts",
|
|
12
|
-
"./config": "./src/config/index.ts",
|
|
13
|
-
"./components/Placeholder": "./src/components/Placeholder/index.ts"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"src",
|
|
19
|
-
"index.ts",
|
|
20
|
-
"readme.md"
|
|
21
|
-
],
|
|
22
5
|
"sideEffects": false,
|
|
23
6
|
"publishConfig": {
|
|
24
7
|
"access": "public",
|
|
@@ -26,14 +9,17 @@
|
|
|
26
9
|
},
|
|
27
10
|
"scripts": {
|
|
28
11
|
"typecheck": "tsc -p tsconfig.json",
|
|
29
|
-
"copy:astro": "ts-node ./src/scripts/copy-astro-components.ts",
|
|
30
12
|
"lint": "eslint \"./src/**/*.ts\"",
|
|
31
|
-
"test": "
|
|
13
|
+
"test": "npm run test:unit & npm run test:components",
|
|
14
|
+
"test:unit": "mocha \"./src/**/*.test.ts\" --ignore \"src/**/*.astro.test.ts\"",
|
|
15
|
+
"test:components": "vitest run --config ./vitest.config.ts",
|
|
32
16
|
"coverage": "nyc npm test",
|
|
33
|
-
"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"
|
|
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
|
+
"api-extractor": "npm run build && api-extractor run --local --verbose",
|
|
19
|
+
"api-extractor:verify": "api-extractor run"
|
|
34
20
|
},
|
|
35
21
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
22
|
+
"node": ">=24"
|
|
37
23
|
},
|
|
38
24
|
"author": {
|
|
39
25
|
"name": "EXDST",
|
|
@@ -48,23 +34,22 @@
|
|
|
48
34
|
"url": "https://github.com/exdst/jss-astro-public/issues"
|
|
49
35
|
},
|
|
50
36
|
"devDependencies": {
|
|
51
|
-
"@
|
|
37
|
+
"@happy-dom/global-registrator": "^20.8.7",
|
|
38
|
+
"@sitecore-content-sdk/events": "^2.0.1",
|
|
52
39
|
"@stylistic/eslint-plugin": "^5.2.2",
|
|
40
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
53
41
|
"@types/chai": "^5.2.2",
|
|
54
42
|
"@types/chai-spies": "^1.0.6",
|
|
55
43
|
"@types/chai-string": "^1.4.5",
|
|
56
44
|
"@types/debug": "^4.1.12",
|
|
57
|
-
"@types/jsdom": "^21.1.7",
|
|
58
|
-
"@types/memory-cache": "^0.2.6",
|
|
59
45
|
"@types/mocha": "^10.0.10",
|
|
60
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^24.10.4",
|
|
61
47
|
"@types/proxyquire": "^1.3.31",
|
|
62
48
|
"@types/sinon": "^17.0.4",
|
|
63
49
|
"@types/sinon-chai": "^4.0.0",
|
|
64
|
-
"@types/url-parse": "1.4.11",
|
|
65
50
|
"@typescript-eslint/eslint-plugin": "8.39.0",
|
|
66
51
|
"@typescript-eslint/parser": "8.39.0",
|
|
67
|
-
"astro": "^5.
|
|
52
|
+
"astro": "^5.18.1",
|
|
68
53
|
"chai": "^4.4.1",
|
|
69
54
|
"chai-spies": "^1.1.0",
|
|
70
55
|
"chai-string": "^1.6.0",
|
|
@@ -73,35 +58,49 @@
|
|
|
73
58
|
"eslint-plugin-import": "2.32.0",
|
|
74
59
|
"eslint-plugin-jsdoc": "52.0.3",
|
|
75
60
|
"eslint-plugin-prettier": "^4.0.0",
|
|
76
|
-
"eslint-plugin-react": "7.37.5",
|
|
77
|
-
"eslint-plugin-react-hooks": "5.2.0",
|
|
78
61
|
"glob": "^11.0.2",
|
|
79
|
-
"
|
|
62
|
+
"happy-dom": "^16.7.3",
|
|
80
63
|
"mocha": "^11.2.2",
|
|
81
|
-
"nock": "14.0.0-beta.7",
|
|
82
64
|
"nyc": "^17.1.0",
|
|
83
65
|
"prettier": "^2.8.0",
|
|
84
66
|
"proxyquire": "^2.1.3",
|
|
85
67
|
"sinon": "^20.0.0",
|
|
86
68
|
"sinon-chai": "3.7.0",
|
|
87
|
-
"tslib": "^2.8.1",
|
|
88
69
|
"tsx": "^4.19.4",
|
|
89
|
-
"typescript": "~5.8.3"
|
|
70
|
+
"typescript": "~5.8.3",
|
|
71
|
+
"vitest": "^3.0.4"
|
|
90
72
|
},
|
|
91
73
|
"peerDependencies": {
|
|
92
|
-
"@sitecore-
|
|
74
|
+
"@sitecore-content-sdk/analytics-core": "^2.0.1",
|
|
75
|
+
"@sitecore-content-sdk/events": "^2.0.1"
|
|
93
76
|
},
|
|
94
77
|
"dependencies": {
|
|
95
|
-
"@sitecore-content-sdk/
|
|
78
|
+
"@sitecore-content-sdk/content": "^2.0.1",
|
|
79
|
+
"@sitecore-content-sdk/core": "^2.0.1",
|
|
96
80
|
"chalk": "^4.1.2",
|
|
97
81
|
"cookie": "^1.0.2",
|
|
98
82
|
"debug": "^4.4.0",
|
|
99
83
|
"glob": "^11.0.2",
|
|
100
|
-
"
|
|
101
|
-
"graphql-request": "^6.1.0",
|
|
102
|
-
"memory-cache": "^0.2.0",
|
|
103
|
-
"nanostores": "^0.10.3",
|
|
104
|
-
"url-parse": "^1.5.10"
|
|
84
|
+
"nanostores": "^0.10.3"
|
|
105
85
|
},
|
|
106
|
-
"
|
|
86
|
+
"exports": {
|
|
87
|
+
".": "./src/index.ts",
|
|
88
|
+
"./*": "./src/*",
|
|
89
|
+
"./client": "./src/client/index.ts",
|
|
90
|
+
"./config": "./src/config/index.ts",
|
|
91
|
+
"./config-cli": "./src/config-cli/index.ts",
|
|
92
|
+
"./context": "./src/context.ts",
|
|
93
|
+
"./editing": "./src/editing/index.ts",
|
|
94
|
+
"./middleware": "./src/middleware/index.ts",
|
|
95
|
+
"./site": "./src/site/index.ts",
|
|
96
|
+
"./tools": "./src/tools/index.ts",
|
|
97
|
+
"./utils": "./src/utils/index.ts",
|
|
98
|
+
"./components/Placeholder": "./src/components/Placeholder/index.ts"
|
|
99
|
+
},
|
|
100
|
+
"description": "",
|
|
101
|
+
"files": [
|
|
102
|
+
"src",
|
|
103
|
+
"index.ts",
|
|
104
|
+
"readme.md"
|
|
105
|
+
]
|
|
107
106
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -6,12 +6,9 @@ import sinon from 'sinon';
|
|
|
6
6
|
import sinonChai from 'sinon-chai';
|
|
7
7
|
import { SitecoreAstroClient } from './sitecore-astro-client';
|
|
8
8
|
import { DefaultRetryStrategy } from '@sitecore-content-sdk/core';
|
|
9
|
-
import { SITE_PREFIX } from '@sitecore-content-sdk/
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
componentsWithExperiencesArray,
|
|
13
|
-
} from '../test-data/personalizeData';
|
|
14
|
-
import { VARIANT_PREFIX } from '@sitecore-content-sdk/core/personalize';
|
|
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';
|
|
15
12
|
|
|
16
13
|
chai.use(sinonChai);
|
|
17
14
|
|
|
@@ -60,6 +57,9 @@ describe('SitecoreClient', () => {
|
|
|
60
57
|
let restComponentServiceStub = {
|
|
61
58
|
fetchComponentData: sandbox.stub(),
|
|
62
59
|
};
|
|
60
|
+
let sitePathServiceStub = {
|
|
61
|
+
fetchSiteRoutes: sandbox.stub(),
|
|
62
|
+
};
|
|
63
63
|
|
|
64
64
|
beforeEach(() => {
|
|
65
65
|
layoutServiceStub = {
|
|
@@ -78,6 +78,9 @@ describe('SitecoreClient', () => {
|
|
|
78
78
|
restComponentServiceStub = {
|
|
79
79
|
fetchComponentData: sandbox.stub(),
|
|
80
80
|
};
|
|
81
|
+
sitePathServiceStub = {
|
|
82
|
+
fetchSiteRoutes: sandbox.stub(),
|
|
83
|
+
};
|
|
81
84
|
|
|
82
85
|
sitecoreClient = new SitecoreAstroClient(defaultInitOptions);
|
|
83
86
|
|
|
@@ -86,6 +89,7 @@ describe('SitecoreClient', () => {
|
|
|
86
89
|
(sitecoreClient as any).errorPagesService = errorPagesServiceStub;
|
|
87
90
|
(sitecoreClient as any).editingService = editingServiceStub;
|
|
88
91
|
(sitecoreClient as any).componentService = restComponentServiceStub;
|
|
92
|
+
(sitecoreClient as any).sitePathService = sitePathServiceStub;
|
|
89
93
|
});
|
|
90
94
|
|
|
91
95
|
describe('getPage', () => {
|
|
@@ -147,13 +151,10 @@ describe('SitecoreClient', () => {
|
|
|
147
151
|
locale,
|
|
148
152
|
});
|
|
149
153
|
|
|
150
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
site: 'mysite',
|
|
155
|
-
}
|
|
156
|
-
);
|
|
154
|
+
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
155
|
+
locale,
|
|
156
|
+
site: 'mysite',
|
|
157
|
+
});
|
|
157
158
|
});
|
|
158
159
|
|
|
159
160
|
it('should use site passed in page options over site parsed from path', async () => {
|
|
@@ -170,13 +171,10 @@ describe('SitecoreClient', () => {
|
|
|
170
171
|
site: 'other-site',
|
|
171
172
|
});
|
|
172
173
|
|
|
173
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
site: 'other-site',
|
|
178
|
-
}
|
|
179
|
-
);
|
|
174
|
+
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
175
|
+
locale,
|
|
176
|
+
site: 'other-site',
|
|
177
|
+
});
|
|
180
178
|
});
|
|
181
179
|
});
|
|
182
180
|
|
|
@@ -227,6 +225,29 @@ describe('SitecoreClient', () => {
|
|
|
227
225
|
expect(result).to.equal(expectedPath);
|
|
228
226
|
});
|
|
229
227
|
});
|
|
228
|
+
|
|
229
|
+
describe('getPagePaths', () => {
|
|
230
|
+
it('should return static paths without site prefixes', async () => {
|
|
231
|
+
const paths = [
|
|
232
|
+
{ params: { path: ['_site_site-one', 'home'] }, locale: 'en' },
|
|
233
|
+
{ params: { path: ['_site_site-one', 'about'] }, locale: 'en' },
|
|
234
|
+
{ params: { path: ['_site_site-two', 'home'] }, locale: 'de-DE' },
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const expectedPaths = [
|
|
238
|
+
{ params: { path: ['home'] }, locale: 'en' },
|
|
239
|
+
{ params: { path: ['about'] }, locale: 'en' },
|
|
240
|
+
{ params: { path: ['home'] }, locale: 'de-DE' },
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
sitePathServiceStub.fetchSiteRoutes.resolves(structuredClone(paths));
|
|
244
|
+
|
|
245
|
+
const result = await sitecoreClient.getPagePaths(['site-one'], ['en'], undefined);
|
|
246
|
+
|
|
247
|
+
expect(result).to.deep.equal(expectedPaths);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
230
251
|
/*
|
|
231
252
|
describe('getComponentData', () => {
|
|
232
253
|
it('should return componentData when component has getComponentsProps method', async () => {
|
|
@@ -1,32 +1,34 @@
|
|
|
1
|
+
import { StaticPath } from '@sitecore-content-sdk/content';
|
|
1
2
|
import {
|
|
2
3
|
FetchOptions,
|
|
3
4
|
Page,
|
|
4
5
|
PageOptions,
|
|
5
6
|
SitecoreClient,
|
|
6
7
|
SitecoreClientInit,
|
|
7
|
-
} from '@sitecore-content-sdk/
|
|
8
|
-
import {
|
|
9
|
-
AstroContentSdkComponent,
|
|
10
|
-
ComponentMap,
|
|
11
|
-
ComponentPropsCollection,
|
|
12
|
-
ComponentPropsError,
|
|
13
|
-
PreviewData,
|
|
14
|
-
} from '../sharedTypes/component-props';
|
|
15
|
-
import { LayoutServiceData } from '@sitecore-content-sdk/core/layout';
|
|
8
|
+
} from '@sitecore-content-sdk/content/client';
|
|
9
|
+
import { PreviewData } from '../sharedTypes/component-props';
|
|
16
10
|
import { ComponentPropsService } from '../services/component-props-service';
|
|
17
|
-
import { EditingPreviewData } from '@sitecore-content-sdk/
|
|
18
|
-
import {
|
|
19
|
-
getSiteRewriteData,
|
|
20
|
-
normalizeSiteRewrite,
|
|
21
|
-
} from '@sitecore-content-sdk/core/site';
|
|
11
|
+
import { EditingPreviewData } from '@sitecore-content-sdk/content/editing';
|
|
12
|
+
import { getSiteRewriteData, normalizeSiteRewrite } from '@sitecore-content-sdk/content/site';
|
|
22
13
|
import {
|
|
23
14
|
getPersonalizedRewriteData,
|
|
24
15
|
normalizePersonalizedRewrite,
|
|
25
|
-
} from '@sitecore-content-sdk/
|
|
16
|
+
} from '@sitecore-content-sdk/content/personalize';
|
|
17
|
+
import { SitecoreConfig } from '../config';
|
|
26
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Init options for Sitecore Client that allows you to override services too
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export type SitecoreAstroClientInit = SitecoreClientInit & Pick<SitecoreConfig, 'multisite'>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The SitecoreAstroClient class extends the SitecoreClient class to provide additional functionality for Astro.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
27
29
|
export class SitecoreAstroClient extends SitecoreClient {
|
|
28
30
|
protected componentPropsService: ComponentPropsService;
|
|
29
|
-
constructor(protected initOptions:
|
|
31
|
+
constructor(protected initOptions: SitecoreAstroClientInit) {
|
|
30
32
|
super(initOptions);
|
|
31
33
|
this.componentPropsService = this.getComponentPropsService();
|
|
32
34
|
}
|
|
@@ -38,11 +40,8 @@ export class SitecoreAstroClient extends SitecoreClient {
|
|
|
38
40
|
*/
|
|
39
41
|
getSiteNameFromPath(path: string | string[]) {
|
|
40
42
|
const resolvedPath = super.parsePath(path);
|
|
41
|
-
// Get site name (from path rewritten in
|
|
42
|
-
const siteData = getSiteRewriteData(
|
|
43
|
-
resolvedPath,
|
|
44
|
-
this.initOptions.defaultSite
|
|
45
|
-
);
|
|
43
|
+
// Get site name (from path rewritten in proxy)
|
|
44
|
+
const siteData = getSiteRewriteData(resolvedPath, this.initOptions.defaultSite);
|
|
46
45
|
|
|
47
46
|
return siteData.siteName;
|
|
48
47
|
}
|
|
@@ -65,8 +64,7 @@ export class SitecoreAstroClient extends SitecoreClient {
|
|
|
65
64
|
const resolvedPath = this.parsePath(path);
|
|
66
65
|
// Get variant(s) for personalization (from path), must ensure path is of type string
|
|
67
66
|
const personalizeData =
|
|
68
|
-
pageOptions.personalize ||
|
|
69
|
-
getPersonalizedRewriteData(super.parsePath(path));
|
|
67
|
+
pageOptions.personalize || getPersonalizedRewriteData(super.parsePath(path));
|
|
70
68
|
const site = pageOptions.site || this.getSiteNameFromPath(path);
|
|
71
69
|
const page = await super.getPage(
|
|
72
70
|
resolvedPath,
|
|
@@ -86,50 +84,69 @@ export class SitecoreAstroClient extends SitecoreClient {
|
|
|
86
84
|
* @param {PreviewData} previewData - The editing preview data for metadata mode.
|
|
87
85
|
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
|
|
88
86
|
*/
|
|
89
|
-
async getPreview(
|
|
90
|
-
previewData: PreviewData,
|
|
91
|
-
fetchOptions?: FetchOptions
|
|
92
|
-
): Promise<Page | null> {
|
|
87
|
+
async getPreview(previewData: PreviewData, fetchOptions?: FetchOptions): Promise<Page | null> {
|
|
93
88
|
return super.getPreview(previewData as EditingPreviewData, fetchOptions);
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {
|
|
101
|
-
* @returns {
|
|
92
|
+
* Retrieves the static paths for pages based on the given languages.
|
|
93
|
+
* @param {string[]} sites - An array of site names to fetch routes for.
|
|
94
|
+
* @param {string[]} [languages] - An optional array of language codes to generate paths for.
|
|
95
|
+
* @param {FetchOptions} [fetchOptions] - Additional fetch options.
|
|
96
|
+
* @returns {Promise<StaticPath[]>} A promise that resolves to an array of static paths.
|
|
102
97
|
*/
|
|
103
|
-
async
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
): Promise<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// context,
|
|
114
|
-
components,
|
|
98
|
+
async getPagePaths(
|
|
99
|
+
sites: string[],
|
|
100
|
+
languages?: string[],
|
|
101
|
+
fetchOptions?: FetchOptions
|
|
102
|
+
): Promise<StaticPath[]> {
|
|
103
|
+
const staticPaths = await super.getPagePaths(sites, languages, fetchOptions);
|
|
104
|
+
|
|
105
|
+
// remove _site_ segments (Astro doesn't support multisite in SSG yet)
|
|
106
|
+
staticPaths.map((path) => {
|
|
107
|
+
path.params.path = normalizeSiteRewrite(path.params.path.join('/')).split('/');
|
|
115
108
|
});
|
|
116
109
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
return staticPaths;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// /**
|
|
114
|
+
// * Parses components from component map and layoutData, executes getServerProps/getStaticProps methods
|
|
115
|
+
// * and returns resulting props from components
|
|
116
|
+
// * @param {LayoutServiceData} layoutData layout data to parse compnents from
|
|
117
|
+
// * @param {ComponentMap<AstroContentSdkComponent>} components component map to get props for
|
|
118
|
+
// * @returns {ComponentPropsCollection} component props
|
|
119
|
+
// */
|
|
120
|
+
// async getComponentData(
|
|
121
|
+
// layoutData: LayoutServiceData,
|
|
122
|
+
// // context: GetServerSidePropsContext | GetStaticPropsContext,
|
|
123
|
+
// components: ComponentMap<AstroContentSdkComponent>
|
|
124
|
+
// ): Promise<ComponentPropsCollection> {
|
|
125
|
+
// let componentProps: ComponentPropsCollection = {};
|
|
126
|
+
// if (!layoutData.sitecore.route) return componentProps;
|
|
127
|
+
// // Retrieve component props using side-effects defined on components level
|
|
128
|
+
// componentProps = await this.componentPropsService.fetchComponentProps({
|
|
129
|
+
// layoutData: layoutData,
|
|
130
|
+
// // context,
|
|
131
|
+
// components,
|
|
132
|
+
// });
|
|
120
133
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
.join('');
|
|
134
|
+
// const errors = Object.keys(componentProps)
|
|
135
|
+
// .map((id) => {
|
|
136
|
+
// const component = componentProps[id] as ComponentPropsError;
|
|
126
137
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
// return component.error
|
|
139
|
+
// ? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
|
|
140
|
+
// : '';
|
|
141
|
+
// })
|
|
142
|
+
// .join('');
|
|
130
143
|
|
|
131
|
-
|
|
132
|
-
|
|
144
|
+
// if (errors.length) {
|
|
145
|
+
// throw new Error(errors);
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
// return componentProps;
|
|
149
|
+
// }
|
|
133
150
|
|
|
134
151
|
protected getComponentPropsService(): ComponentPropsService {
|
|
135
152
|
return new ComponentPropsService();
|
|
@@ -8,9 +8,9 @@ import type {
|
|
|
8
8
|
} from './Image.astro';
|
|
9
9
|
import Image from './Image.astro';
|
|
10
10
|
import { EditableFieldProps } from './sharedTypes';
|
|
11
|
-
import { isFieldValueEmpty } from '@sitecore-content-sdk/
|
|
11
|
+
import { isFieldValueEmpty } from '@sitecore-content-sdk/content/layout';
|
|
12
12
|
import { addClassName } from '../utils';
|
|
13
|
-
import { mediaApi } from '@sitecore-content-sdk/
|
|
13
|
+
import { mediaApi } from '@sitecore-content-sdk/content/media';
|
|
14
14
|
|
|
15
15
|
const { page } = useSitecore();
|
|
16
16
|
let fallback = false,
|