@exdst-sitecore-content-sdk/astro 0.0.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 +202 -0
- package/README.md +3 -0
- package/package.json +101 -0
- package/src/client/index.ts +12 -0
- package/src/client/sitecore-astro-client.test.ts +271 -0
- package/src/client/sitecore-astro-client.ts +137 -0
- package/src/components/AstroImage.astro +114 -0
- package/src/components/Date.astro +76 -0
- package/src/components/DefaultEmptyFieldEditingComponentImage.astro +24 -0
- package/src/components/DefaultEmptyFieldEditingComponentText.astro +12 -0
- package/src/components/EditingScripts.astro +49 -0
- package/src/components/EmptyRendering.astro +3 -0
- package/src/components/ErrorBoundary.astro +77 -0
- package/src/components/FieldMetadata.astro +30 -0
- package/src/components/File.astro +46 -0
- package/src/components/HiddenRendering.astro +22 -0
- package/src/components/Image.astro +155 -0
- package/src/components/Link.astro +105 -0
- package/src/components/MissingComponent.astro +39 -0
- package/src/components/Placeholder/EmptyPlaceholder.astro +9 -0
- package/src/components/Placeholder/Placeholder.astro +100 -0
- package/src/components/Placeholder/PlaceholderMetadata.astro +102 -0
- package/src/components/Placeholder/PlaceholderUtils.astro +153 -0
- package/src/components/Placeholder/index.ts +5 -0
- package/src/components/Placeholder/models.ts +82 -0
- package/src/components/Placeholder/placeholder-utils.test.ts +162 -0
- package/src/components/Placeholder/placeholder-utils.ts +80 -0
- package/src/components/RenderWrapper.astro +31 -0
- package/src/components/RichText.astro +59 -0
- package/src/components/Text.astro +97 -0
- package/src/components/sharedTypes/index.ts +1 -0
- package/src/components/sharedTypes/props.ts +17 -0
- package/src/config/define-config.test.ts +526 -0
- package/src/config/define-config.ts +99 -0
- package/src/config/index.ts +1 -0
- package/src/config-cli/define-cli-config.test.ts +95 -0
- package/src/config-cli/define-cli-config.ts +50 -0
- package/src/config-cli/index.ts +1 -0
- package/src/context.ts +68 -0
- package/src/editing/constants.ts +8 -0
- package/src/editing/editing-config-middleware.test.ts +166 -0
- package/src/editing/editing-config-middleware.ts +111 -0
- package/src/editing/editing-render-middleware.test.ts +801 -0
- package/src/editing/editing-render-middleware.ts +288 -0
- package/src/editing/index.ts +16 -0
- package/src/editing/render-middleware.test.ts +57 -0
- package/src/editing/render-middleware.ts +51 -0
- package/src/editing/utils.test.ts +852 -0
- package/src/editing/utils.ts +308 -0
- package/src/enhancers/WithEmptyFieldEditingComponent.astro +56 -0
- package/src/enhancers/WithFieldMetadata.astro +31 -0
- package/src/env.d.ts +12 -0
- package/src/index.ts +16 -0
- package/src/middleware/index.ts +24 -0
- package/src/middleware/middleware.test.ts +507 -0
- package/src/middleware/middleware.ts +167 -0
- package/src/middleware/multisite-middleware.test.ts +672 -0
- package/src/middleware/multisite-middleware.ts +147 -0
- package/src/middleware/robots-middleware.test.ts +113 -0
- package/src/middleware/robots-middleware.ts +47 -0
- package/src/middleware/sitemap-middleware.test.ts +152 -0
- package/src/middleware/sitemap-middleware.ts +65 -0
- package/src/services/component-props-service.ts +182 -0
- package/src/sharedTypes/component-props.ts +17 -0
- package/src/site/index.ts +1 -0
- package/src/test-data/components/Bar.astro +0 -0
- package/src/test-data/components/Baz.astro +0 -0
- package/src/test-data/components/Foo.astro +0 -0
- package/src/test-data/components/Hero.variant.astro +0 -0
- package/src/test-data/components/NotComponent.bsx +0 -0
- package/src/test-data/components/Qux.astro +0 -0
- package/src/test-data/components/folded/Folded.astro +0 -0
- package/src/test-data/components/folded/random-file-2.docx +0 -0
- package/src/test-data/components/random-file.txt +0 -0
- package/src/test-data/helpers.ts +46 -0
- package/src/test-data/personalizeData.ts +63 -0
- package/src/tools/generate-map.ts +83 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/templating/components.test.ts +305 -0
- package/src/tools/templating/components.ts +49 -0
- package/src/tools/templating/constants.ts +4 -0
- package/src/tools/templating/default-component.test.ts +31 -0
- package/src/tools/templating/default-component.ts +63 -0
- package/src/tools/templating/index.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.test.ts +48 -0
- package/src/utils/utils.ts +52 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import proxyquire from 'proxyquire';
|
|
5
|
+
|
|
6
|
+
describe('defineConfig', () => {
|
|
7
|
+
let defineConfigCoreStub: sinon.SinonStub;
|
|
8
|
+
let defineConfigModule: any;
|
|
9
|
+
const sandbox = sinon.createSandbox();
|
|
10
|
+
const defaultConfig = () => ({
|
|
11
|
+
api: {
|
|
12
|
+
edge: { contextId: 'contextId' },
|
|
13
|
+
},
|
|
14
|
+
defaultLanguage: 'en',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
defineConfigCoreStub = sandbox.stub();
|
|
19
|
+
defineConfigModule = proxyquire('./define-config', {
|
|
20
|
+
'@sitecore-content-sdk/core/config': {
|
|
21
|
+
defineConfig: defineConfigCoreStub,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
sandbox.restore();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('config.api.edge.contextid', () => {
|
|
31
|
+
describe('environment variable is not set', () => {
|
|
32
|
+
it('should default to empty string', () => {
|
|
33
|
+
defineConfigModule.defineConfig({
|
|
34
|
+
api: {
|
|
35
|
+
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
36
|
+
},
|
|
37
|
+
defaultLanguage: 'en',
|
|
38
|
+
});
|
|
39
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
40
|
+
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should use the value from the config', () => {
|
|
44
|
+
defineConfigModule.defineConfig({
|
|
45
|
+
api: {
|
|
46
|
+
edge: { contextId: 'custom-context-id' },
|
|
47
|
+
},
|
|
48
|
+
defaultLanguage: 'en',
|
|
49
|
+
});
|
|
50
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
51
|
+
expect(resultConfig.api?.edge?.contextId).to.equal('custom-context-id');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('environment variable is set', () => {
|
|
56
|
+
before(() => {
|
|
57
|
+
process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID = 'next-public-sitecore-edge-context-id';
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
after(() => {
|
|
61
|
+
delete process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should use the value from the config if present', () => {
|
|
65
|
+
defineConfigModule.defineConfig({
|
|
66
|
+
api: {
|
|
67
|
+
edge: { contextId: 'custom-context-id' },
|
|
68
|
+
},
|
|
69
|
+
defaultLanguage: 'en',
|
|
70
|
+
});
|
|
71
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
72
|
+
expect(resultConfig.api?.edge?.contextId).to.equal('custom-context-id');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should NOT use the env var for server-side contextId', () => {
|
|
76
|
+
defineConfigModule.defineConfig({
|
|
77
|
+
api: {
|
|
78
|
+
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
79
|
+
},
|
|
80
|
+
defaultLanguage: 'en',
|
|
81
|
+
});
|
|
82
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
83
|
+
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('config.api.edge.clientContextId', () => {
|
|
89
|
+
describe('environment variable is not set', () => {
|
|
90
|
+
it('should default to undefined', () => {
|
|
91
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
92
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
93
|
+
expect(resultConfig.api?.edge?.clientContextId).to.be.undefined;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should use the value from the config', () => {
|
|
97
|
+
defineConfigModule.defineConfig({
|
|
98
|
+
...defaultConfig(),
|
|
99
|
+
api: {
|
|
100
|
+
edge: {
|
|
101
|
+
contextId: 'context-id',
|
|
102
|
+
clientContextId: 'clien-context-id',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
107
|
+
expect(resultConfig.api?.edge?.clientContextId).to.equal('clien-context-id');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('environment variable is set', () => {
|
|
111
|
+
before(() => {
|
|
112
|
+
process.env.PUBLIC_SITECORE_EDGE_CONTEXT_ID = 'next-public-sitecore-edge-context-id';
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
after(() => {
|
|
116
|
+
delete process.env.PUBLIC_SITECORE_EDGE_CONTEXT_ID;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should use the value from the config if present', () => {
|
|
120
|
+
defineConfigModule.defineConfig({
|
|
121
|
+
api: {
|
|
122
|
+
edge: {
|
|
123
|
+
contextId: 'custom-context-id',
|
|
124
|
+
clientContextId: 'custom-client-context-id',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
defaultLanguage: 'en',
|
|
128
|
+
});
|
|
129
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
130
|
+
expect(resultConfig.api?.edge?.clientContextId).to.equal('custom-client-context-id');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should use the env var for client-side contextId only', () => {
|
|
134
|
+
defineConfigModule.defineConfig({
|
|
135
|
+
api: {
|
|
136
|
+
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
137
|
+
},
|
|
138
|
+
defaultLanguage: 'en',
|
|
139
|
+
});
|
|
140
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
141
|
+
// Server-side contextId should be empty
|
|
142
|
+
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
143
|
+
// Client-side contextId should use env var
|
|
144
|
+
expect(resultConfig.api?.edge?.clientContextId).to.equal(
|
|
145
|
+
'next-public-sitecore-edge-context-id'
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('config.api.edge.edgeUrl', () => {
|
|
152
|
+
describe('environment variable is not set', () => {
|
|
153
|
+
it('should default to undefined', () => {
|
|
154
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
155
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
156
|
+
expect(resultConfig.api?.edge?.edgeUrl).to.be.undefined;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should use the value from the config', () => {
|
|
160
|
+
defineConfigModule.defineConfig({
|
|
161
|
+
...defaultConfig(),
|
|
162
|
+
api: { edge: { contextId: 'context-id', edgeUrl: 'edgeUrl' } },
|
|
163
|
+
});
|
|
164
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
165
|
+
expect(resultConfig.api?.edge?.edgeUrl).to.equal('edgeUrl');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('environment variable is set', () => {
|
|
169
|
+
before(() => {
|
|
170
|
+
process.env.PUBLIC_SITECORE_EDGE_URL = 'next-public-sitecore-edgeUrl';
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
after(() => {
|
|
174
|
+
delete process.env.PUBLIC_SITECORE_EDGE_URL;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should use the value from the config if present', () => {
|
|
178
|
+
defineConfigModule.defineConfig({
|
|
179
|
+
api: {
|
|
180
|
+
edge: { contextId: 'custom-context-id', edgeUrl: 'custom-edgeUrl' },
|
|
181
|
+
},
|
|
182
|
+
defaultLanguage: 'en',
|
|
183
|
+
});
|
|
184
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
185
|
+
expect(resultConfig.api?.edge?.edgeUrl).to.equal('custom-edgeUrl');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should use the env var if present', () => {
|
|
189
|
+
defineConfigModule.defineConfig({
|
|
190
|
+
api: {
|
|
191
|
+
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
192
|
+
},
|
|
193
|
+
defaultLanguage: 'en',
|
|
194
|
+
});
|
|
195
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
196
|
+
expect(resultConfig.api?.edge?.edgeUrl).to.equal('next-public-sitecore-edgeUrl');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('config.api.local', () => {
|
|
202
|
+
describe('environment variables are not set', () => {
|
|
203
|
+
it('should default to empty string', () => {
|
|
204
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
205
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
206
|
+
expect(resultConfig.api?.local?.apiKey).to.be.equal('');
|
|
207
|
+
expect(resultConfig.api?.local?.apiHost).to.be.equal('');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should use the value from the config', () => {
|
|
211
|
+
defineConfigModule.defineConfig({
|
|
212
|
+
...defaultConfig(),
|
|
213
|
+
api: { local: { apiKey: 'apiKey', apiHost: 'apiHost' } },
|
|
214
|
+
});
|
|
215
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
216
|
+
expect(resultConfig.api?.local?.apiKey).to.equal('apiKey');
|
|
217
|
+
expect(resultConfig.api?.local?.apiHost).to.equal('apiHost');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe('environment variables are set', () => {
|
|
222
|
+
before(() => {
|
|
223
|
+
process.env.PUBLIC_SITECORE_API_KEY = 'next-public-sitecore-api-key';
|
|
224
|
+
process.env.PUBLIC_SITECORE_API_HOST = 'next-public-sitecore-api-host';
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
after(() => {
|
|
228
|
+
delete process.env.PUBLIC_SITECORE_API_KEY;
|
|
229
|
+
delete process.env.PUBLIC_SITECORE_API_HOST;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should use the values from the config if present', () => {
|
|
233
|
+
defineConfigModule.defineConfig({
|
|
234
|
+
...defaultConfig(),
|
|
235
|
+
api: { local: { apiKey: 'apiKey', apiHost: 'apiHost' } },
|
|
236
|
+
});
|
|
237
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
238
|
+
expect(resultConfig.api?.local?.apiKey).to.equal('apiKey');
|
|
239
|
+
expect(resultConfig.api?.local?.apiHost).to.equal('apiHost');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('should use the env vars if present', () => {
|
|
243
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
244
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
245
|
+
expect(resultConfig.api?.local?.apiKey).to.equal('next-public-sitecore-api-key');
|
|
246
|
+
expect(resultConfig.api?.local?.apiHost).to.equal('next-public-sitecore-api-host');
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe('config.defaultSite', () => {
|
|
252
|
+
describe('environment variable is not set', () => {
|
|
253
|
+
it('should default to undefined', () => {
|
|
254
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
255
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
256
|
+
expect(resultConfig.defaultSite).to.equal('');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should use the value from the config', () => {
|
|
260
|
+
defineConfigModule.defineConfig({
|
|
261
|
+
...defaultConfig(),
|
|
262
|
+
defaultSite: 'skate-park',
|
|
263
|
+
});
|
|
264
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
265
|
+
expect(resultConfig.defaultSite).to.equal('skate-park');
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('environment variable is set', () => {
|
|
270
|
+
before(() => {
|
|
271
|
+
process.env.PUBLIC_DEFAULT_SITE_NAME = 'next-public-sitecore-site-name';
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
after(() => {
|
|
275
|
+
delete process.env.PUBLIC_DEFAULT_SITE_NAME;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should use the value from the config if present', () => {
|
|
279
|
+
defineConfigModule.defineConfig({
|
|
280
|
+
...defaultConfig(),
|
|
281
|
+
defaultSite: 'skate-park',
|
|
282
|
+
});
|
|
283
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
284
|
+
expect(resultConfig.defaultSite).to.equal('skate-park');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('should use the env var if config value not present', () => {
|
|
288
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
289
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
290
|
+
expect(resultConfig.defaultSite).to.equal('next-public-sitecore-site-name');
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe('config.defaultLanguage', () => {
|
|
296
|
+
describe('environment variable is not set', () => {
|
|
297
|
+
it('should default to undefined', () => {
|
|
298
|
+
defineConfigModule.defineConfig({
|
|
299
|
+
api: {
|
|
300
|
+
edge: { contextId: 'contextId' },
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
304
|
+
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should use the value from the config', () => {
|
|
308
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
309
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
310
|
+
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('environment variable is set', () => {
|
|
315
|
+
before(() => {
|
|
316
|
+
process.env.PUBLIC_DEFAULT_LANGUAGE = 'de';
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
after(() => {
|
|
320
|
+
delete process.env.PUBLIC_DEFAULT_LANGUAGE;
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('should use the value from the config if present', () => {
|
|
324
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
325
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
326
|
+
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('should use the env var if config value not present', () => {
|
|
330
|
+
defineConfigModule.defineConfig({
|
|
331
|
+
api: {
|
|
332
|
+
edge: { contextId: 'contextId' },
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
336
|
+
expect(resultConfig.defaultLanguage).to.equal('de');
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe('config.multisite', () => {
|
|
342
|
+
describe('enabled', () => {
|
|
343
|
+
it('should default to undefined', () => {
|
|
344
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
345
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
346
|
+
expect(resultConfig.multisite?.enabled).to.be.undefined;
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('should be able to override default value of enabled', () => {
|
|
350
|
+
defineConfigModule.defineConfig({
|
|
351
|
+
...defaultConfig(),
|
|
352
|
+
multisite: { enabled: false },
|
|
353
|
+
});
|
|
354
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
355
|
+
expect(resultConfig.multisite?.enabled).to.be.false;
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('useCookieResolution', () => {
|
|
360
|
+
it('cookie resolution should return default function', () => {
|
|
361
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
362
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
363
|
+
expect(resultConfig.multisite?.useCookieResolution).to.be.a('function');
|
|
364
|
+
|
|
365
|
+
if (resultConfig.multisite?.useCookieResolution) {
|
|
366
|
+
process.env.VERCEL_ENV = 'preview';
|
|
367
|
+
expect(resultConfig.multisite.useCookieResolution()).to.be.true;
|
|
368
|
+
delete process.env.VERCEL_ENV;
|
|
369
|
+
expect(resultConfig.multisite.useCookieResolution()).to.be.false;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('it should be able to override cookie resolution function', () => {
|
|
374
|
+
defineConfigModule.defineConfig({
|
|
375
|
+
...defaultConfig(),
|
|
376
|
+
multisite: { useCookieResolution: () => true },
|
|
377
|
+
});
|
|
378
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
379
|
+
expect(resultConfig.multisite?.useCookieResolution).to.be.a('function');
|
|
380
|
+
if (resultConfig.multisite?.useCookieResolution) {
|
|
381
|
+
expect(resultConfig.multisite.useCookieResolution()).to.be.true;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('config.personalize', () => {
|
|
388
|
+
describe('scope', () => {
|
|
389
|
+
describe('environment variable is not set', () => {
|
|
390
|
+
it('should default to undefined', () => {
|
|
391
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
392
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
393
|
+
expect(resultConfig.personalize?.scope).to.be.undefined;
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('should use the value from the config', () => {
|
|
397
|
+
defineConfigModule.defineConfig({
|
|
398
|
+
...defaultConfig(),
|
|
399
|
+
personalize: { scope: 'custom-scope' },
|
|
400
|
+
});
|
|
401
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
402
|
+
expect(resultConfig.personalize?.scope).to.equal('custom-scope');
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe('environment variable is set', () => {
|
|
407
|
+
before(() => {
|
|
408
|
+
process.env.PUBLIC_PERSONALIZE_SCOPE = 'custom-env-scope';
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
after(() => {
|
|
412
|
+
delete process.env.PUBLIC_PERSONALIZE_SCOPE;
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('should use the value from the config if present', () => {
|
|
416
|
+
defineConfigModule.defineConfig({
|
|
417
|
+
...defaultConfig(),
|
|
418
|
+
personalize: { scope: 'custom-scope' },
|
|
419
|
+
});
|
|
420
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
421
|
+
expect(resultConfig.personalize?.scope).to.equal('custom-scope');
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it('should use the env var if config value not present', () => {
|
|
425
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
426
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
427
|
+
expect(resultConfig.personalize?.scope).to.equal('custom-env-scope');
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
describe('config.generateStaticPaths', () => {
|
|
434
|
+
describe('environment variable is not set', () => {
|
|
435
|
+
it('should default to true', () => {
|
|
436
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
437
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
438
|
+
expect(resultConfig.generateStaticPaths).to.equal(true);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('should use the value from the config', () => {
|
|
442
|
+
defineConfigModule.defineConfig({
|
|
443
|
+
generateStaticPaths: false,
|
|
444
|
+
...defaultConfig(),
|
|
445
|
+
});
|
|
446
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
447
|
+
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe('environment variable is set', () => {
|
|
452
|
+
afterEach(() => {
|
|
453
|
+
delete process.env.GENERATE_STATIC_PATHS;
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('should return false when GENERATE_STATIC_PATHS is set to false', () => {
|
|
457
|
+
process.env.GENERATE_STATIC_PATHS = 'false';
|
|
458
|
+
|
|
459
|
+
defineConfigModule.defineConfig({
|
|
460
|
+
generateStaticPaths: true,
|
|
461
|
+
...defaultConfig(),
|
|
462
|
+
});
|
|
463
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
464
|
+
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('should return true when GENERATE_STATIC_PATHS is set to true', () => {
|
|
468
|
+
process.env.GENERATE_STATIC_PATHS = 'true';
|
|
469
|
+
|
|
470
|
+
defineConfigModule.defineConfig({
|
|
471
|
+
generateStaticPaths: false,
|
|
472
|
+
...defaultConfig(),
|
|
473
|
+
});
|
|
474
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
475
|
+
expect(resultConfig.generateStaticPaths).to.equal(true);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('should return false when GENERATE_STATIC_PATHS is set to any other value', () => {
|
|
479
|
+
process.env.GENERATE_STATIC_PATHS = 'some-other-value';
|
|
480
|
+
|
|
481
|
+
defineConfigModule.defineConfig({
|
|
482
|
+
generateStaticPaths: true,
|
|
483
|
+
...defaultConfig(),
|
|
484
|
+
});
|
|
485
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
486
|
+
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
describe('sitecoreInternalEditingHostUrl', () => {
|
|
491
|
+
describe('environment variable is not set', () => {
|
|
492
|
+
it('should default to undefined', () => {
|
|
493
|
+
defineConfigModule.defineConfig(defaultConfig());
|
|
494
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
495
|
+
expect(resultConfig.sitecoreInternalEditingHostUrl).to.be.undefined;
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('should use the value from the config', () => {
|
|
499
|
+
defineConfigModule.defineConfig({
|
|
500
|
+
sitecoreInternalEditingHostUrl: 'http://localhost:3000',
|
|
501
|
+
...defaultConfig(),
|
|
502
|
+
});
|
|
503
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
504
|
+
expect(resultConfig.sitecoreInternalEditingHostUrl).to.equal('http://localhost:3000');
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
describe('environment variable is set', () => {
|
|
509
|
+
afterEach(() => {
|
|
510
|
+
delete process.env.SITECORE_INTERNAL_EDITING_HOST_URL;
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('should return set value', () => {
|
|
514
|
+
process.env.SITECORE_INTERNAL_EDITING_HOST_URL = 'http://localhost:3000';
|
|
515
|
+
|
|
516
|
+
defineConfigModule.defineConfig({
|
|
517
|
+
generateStaticPaths: true,
|
|
518
|
+
...defaultConfig(),
|
|
519
|
+
});
|
|
520
|
+
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
521
|
+
expect(resultConfig.sitecoreInternalEditingHostUrl).to.equal('http://localhost:3000');
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import {
|
|
3
|
+
DeepRequired,
|
|
4
|
+
defineConfig as defineConfigCore,
|
|
5
|
+
SitecoreConfigInput as SitecoreConfigInputCore,
|
|
6
|
+
} from '@sitecore-content-sdk/core/config';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provides default Astro initial values from env variables for SitecoreConfig
|
|
10
|
+
* @param {SitecoreConfigInput} config optional override values to be written over default config settings
|
|
11
|
+
* @returns default Astro input config
|
|
12
|
+
*/
|
|
13
|
+
export const getAstroFallbackConfig = (
|
|
14
|
+
config?: SitecoreConfigInput
|
|
15
|
+
): SitecoreConfigInput => {
|
|
16
|
+
return {
|
|
17
|
+
...config,
|
|
18
|
+
api: {
|
|
19
|
+
...config?.api,
|
|
20
|
+
edge: {
|
|
21
|
+
...config?.api?.edge,
|
|
22
|
+
contextId: config?.api?.edge?.contextId || '',
|
|
23
|
+
clientContextId:
|
|
24
|
+
config?.api?.edge?.clientContextId ||
|
|
25
|
+
process.env.PUBLIC_SITECORE_EDGE_CONTEXT_ID,
|
|
26
|
+
edgeUrl:
|
|
27
|
+
config?.api?.edge?.edgeUrl || process.env.PUBLIC_SITECORE_EDGE_URL,
|
|
28
|
+
},
|
|
29
|
+
local: {
|
|
30
|
+
...config?.api?.local,
|
|
31
|
+
apiKey:
|
|
32
|
+
config?.api?.local?.apiKey ||
|
|
33
|
+
process.env.PUBLIC_SITECORE_API_KEY ||
|
|
34
|
+
'',
|
|
35
|
+
apiHost:
|
|
36
|
+
config?.api?.local?.apiHost ||
|
|
37
|
+
process.env.PUBLIC_SITECORE_API_HOST ||
|
|
38
|
+
'',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultSite:
|
|
42
|
+
config?.defaultSite || process.env.PUBLIC_DEFAULT_SITE_NAME || '',
|
|
43
|
+
defaultLanguage:
|
|
44
|
+
config?.defaultLanguage || process.env.PUBLIC_DEFAULT_LANGUAGE || 'en',
|
|
45
|
+
multisite: {
|
|
46
|
+
...config?.multisite,
|
|
47
|
+
useCookieResolution:
|
|
48
|
+
config?.multisite?.useCookieResolution ??
|
|
49
|
+
(() => process.env.VERCEL_ENV === 'preview'),
|
|
50
|
+
},
|
|
51
|
+
personalize: {
|
|
52
|
+
...config?.personalize,
|
|
53
|
+
scope: config?.personalize?.scope || process.env.PUBLIC_PERSONALIZE_SCOPE,
|
|
54
|
+
},
|
|
55
|
+
generateStaticPaths:
|
|
56
|
+
process.env.GENERATE_STATIC_PATHS !== undefined
|
|
57
|
+
? process.env.GENERATE_STATIC_PATHS.toLowerCase() === 'true'
|
|
58
|
+
: config?.generateStaticPaths ?? true,
|
|
59
|
+
sitecoreInternalEditingHostUrl:
|
|
60
|
+
config?.sitecoreInternalEditingHostUrl || process.env.SITECORE_INTERNAL_EDITING_HOST_URL,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Type to be used as config input in sitecore.config
|
|
66
|
+
*/
|
|
67
|
+
export type SitecoreConfigInput = SitecoreConfigInputCore & {
|
|
68
|
+
/**
|
|
69
|
+
* Indicates whether SSG `getStaticPaths` pre-render any pages.
|
|
70
|
+
*
|
|
71
|
+
* Set the environment variable `GENERATE_STATIC_PATHS=true`
|
|
72
|
+
* to enable static paths generation.
|
|
73
|
+
*
|
|
74
|
+
* By default, this is set to `true`.
|
|
75
|
+
*
|
|
76
|
+
* This is set to `false` when the application is deployed and used as editing host in Sitecore.
|
|
77
|
+
*/
|
|
78
|
+
generateStaticPaths?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The internal host URL for the Astro application, used for server-side requests for page rendering during editing.
|
|
82
|
+
* This should be the base URL where the Astro app is accessible from the server side (e.g., "http://localhost:3000").
|
|
83
|
+
*/
|
|
84
|
+
sitecoreInternalEditingHostUrl?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Final sitecore config type used at runtime Every property should be populated, either from sitecore.config or built-in fallback values
|
|
89
|
+
*/
|
|
90
|
+
export type SitecoreConfig = DeepRequired<SitecoreConfigInput>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
94
|
+
* @param {SitecoreConfigInput} config override values to be written over default config settings
|
|
95
|
+
* @returns {SitecoreConfig} full sitecore configuration to use in application
|
|
96
|
+
*/
|
|
97
|
+
export const defineConfig = (config?: SitecoreConfigInput): SitecoreConfig => {
|
|
98
|
+
return defineConfigCore(getAstroFallbackConfig(config)) as SitecoreConfig;
|
|
99
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SitecoreConfig, SitecoreConfigInput, defineConfig } from './define-config';
|