@adobe/helix-shared-config 1.7.23 → 2.0.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/package.json +10 -7
  3. package/src/config-wrapper.js +0 -6
  4. package/src/index.js +0 -12
  5. package/src/Condition.js +0 -573
  6. package/src/ConfigValidator.js +0 -95
  7. package/src/DataEmbedValidator.js +0 -51
  8. package/src/DynamicRedirect.js +0 -125
  9. package/src/HelixConfig.js +0 -133
  10. package/src/MarkupConfig.js +0 -35
  11. package/src/Origin.js +0 -159
  12. package/src/Performance.js +0 -80
  13. package/src/Redirect.js +0 -64
  14. package/src/RedirectConfig.js +0 -64
  15. package/src/RedirectRuleHandler.js +0 -46
  16. package/src/Static.js +0 -119
  17. package/src/Strain.js +0 -332
  18. package/src/Strains.js +0 -68
  19. package/src/schemas/conditions.schema.json +0 -140
  20. package/src/schemas/config.description.md +0 -7
  21. package/src/schemas/config.example.1.json +0 -26
  22. package/src/schemas/config.schema.json +0 -44
  23. package/src/schemas/data-embed-response.schema.json +0 -40
  24. package/src/schemas/giturl.schema.json +0 -62
  25. package/src/schemas/markup.schema.json +0 -22
  26. package/src/schemas/markupconfig.schema.json +0 -38
  27. package/src/schemas/markupmapping.description.md +0 -242
  28. package/src/schemas/markupmapping.schema.json +0 -122
  29. package/src/schemas/origin.description.md +0 -5
  30. package/src/schemas/origin.schema.json +0 -86
  31. package/src/schemas/performance.schema.json +0 -210
  32. package/src/schemas/proxystrain.description.md +0 -20
  33. package/src/schemas/proxystrain.schema.json +0 -87
  34. package/src/schemas/redirect.schema.json +0 -34
  35. package/src/schemas/redirectrule.schema.json +0 -46
  36. package/src/schemas/redirects.description.md +0 -1
  37. package/src/schemas/redirects.schema.json +0 -41
  38. package/src/schemas/row.schema.json +0 -23
  39. package/src/schemas/runtimestrain.schema.json +0 -144
  40. package/src/schemas/sheet.schema.json +0 -57
  41. package/src/schemas/staticgiturl.schema.json +0 -80
  42. package/src/schemas/strains.schema.json +0 -39
  43. package/src/schemas/vanity.schema.json +0 -38
  44. package/src/schemas/version-lock.description.md +0 -3
  45. package/src/schemas/version-lock.schema.json +0 -35
  46. package/src/schemas/workbook.schema.json +0 -49
package/src/Redirect.js DELETED
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright 2019 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- const DEFAULT_TYPE = 'permanent';
14
-
15
- /**
16
- * Defines a redirect rule
17
- */
18
- class Redirect {
19
- constructor(cfg) {
20
- this._from = new RegExp(cfg.from);
21
- this._to = cfg.to;
22
- this._type = cfg.type;
23
- }
24
-
25
- match(path) {
26
- if (this._from.test(path)) {
27
- return {
28
- url: path.replace(this._from, this._to),
29
- type: this.type,
30
- };
31
- }
32
- return null;
33
- }
34
-
35
- get from() {
36
- return this._from.source;
37
- }
38
-
39
- get to() {
40
- return this._to;
41
- }
42
-
43
- get type() {
44
- return this._type || DEFAULT_TYPE;
45
- }
46
-
47
- toJSON() {
48
- const retval = {
49
- from: this.from,
50
- to: this.to,
51
- };
52
-
53
- return this._type ? {
54
- ...retval,
55
- type: this.type,
56
- } : retval;
57
- }
58
-
59
- all() {
60
- return [this];
61
- }
62
- }
63
-
64
- module.exports = Redirect;
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
- const SchemaDerivedConfig = require('./SchemaDerivedConfig.js');
13
- const { NamedMapHandler } = require('./NamedMapHandler');
14
- const { RedirectRuleHandler } = require('./RedirectRuleHandler');
15
-
16
- const redirectsConfigSchema = require('./schemas/redirects.schema.json');
17
- const redirectSchema = require('./schemas/redirect.schema.json');
18
- const redirectRuleSchema = require('./schemas/redirectrule.schema.json');
19
- const vanitySchema = require('./schemas/vanity.schema.json');
20
-
21
- class RedirectConfig extends SchemaDerivedConfig {
22
- constructor() {
23
- const rrhandler = RedirectRuleHandler();
24
-
25
- super({
26
- filename: 'helix-redirects.yaml',
27
- schemas: {
28
- '^/$': redirectsConfigSchema,
29
- '^/redirects/.*$': redirectSchema,
30
- '^/redirects/.*/$': redirectRuleSchema,
31
- '^/vanity/.*$': vanitySchema,
32
- },
33
- handlers: {
34
- '^/vanity$': NamedMapHandler(),
35
- '^/redirects$': rrhandler,
36
- },
37
- });
38
-
39
- rrhandler.withLogger(this._logger);
40
- this.rrhandler = rrhandler;
41
- }
42
-
43
- withTransactionID(id) {
44
- this.rrhandler.withTransactionID(id);
45
- return this;
46
- }
47
-
48
- withGithubToken(token) {
49
- this.rrhandler.withGithubToken(token);
50
- return this;
51
- }
52
-
53
- async match(path) {
54
- const resolved = await Promise.all(this.redirects.map((redirect) => redirect.match(path)));
55
- return resolved.find((o) => o);
56
- }
57
-
58
- async all() {
59
- const resolved = await Promise.all(this.redirects.map((redirect) => redirect.all()));
60
- return resolved.flat();
61
- }
62
- }
63
-
64
- module.exports = RedirectConfig;
@@ -1,46 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
- const Redirect = require('./Redirect');
13
- const DynamicRedirect = require('./DynamicRedirect');
14
-
15
- const RedirectRuleHandler = () => ({
16
- withLogger(logger) {
17
- this.logger = logger;
18
- return this;
19
- },
20
-
21
- withTransactionID(id) {
22
- this._transactionID = id;
23
- return this;
24
- },
25
-
26
- withGithubToken(token) {
27
- this._token = token;
28
- return this;
29
- },
30
-
31
- get(target, prop) {
32
- const index = Number.parseInt(prop, 10);
33
- if (!Number.isNaN(index) && index >= 0) {
34
- const item = target[prop];
35
-
36
- if (item.from && item.to) {
37
- return new Redirect(item);
38
- }
39
- return new DynamicRedirect(item, this.logger)
40
- .withGithubToken(this._token)
41
- .withTransactionID(this._transactionID);
42
- }
43
- return target[prop];
44
- },
45
- });
46
- exports.RedirectRuleHandler = RedirectRuleHandler;
package/src/Static.js DELETED
@@ -1,119 +0,0 @@
1
- /*
2
- * Copyright 2021 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- const { Pair } = require('yaml/types');
14
-
15
- const EventEmitter = require('events');
16
- const { GitUrl } = require('@adobe/helix-shared-git');
17
- const pruneEmptyValues = require('@adobe/helix-shared-prune');
18
-
19
- /**
20
- * Static content handling
21
- */
22
- class Static extends EventEmitter {
23
- constructor(cfg) {
24
- super();
25
- this.url = cfg;
26
- this._magic = cfg.magic || false;
27
- this._allow = cfg.allow || [];
28
- this._deny = cfg.deny || [];
29
- }
30
-
31
- get url() {
32
- return this._url;
33
- }
34
-
35
- set url(value) {
36
- if (value.toJSON) {
37
- this._url = new GitUrl(value.toJSON({ minimal: true, keepFormat: true }), { ref: 'master', path: '/htdocs' });
38
- } else {
39
- this._url = new GitUrl(value, { ref: 'master', path: '/htdocs' });
40
- }
41
- this.emit('url-change', value);
42
- }
43
-
44
- get magic() {
45
- return this._magic;
46
- }
47
-
48
- get allow() {
49
- return this._allow;
50
- }
51
-
52
- get deny() {
53
- return this._deny;
54
- }
55
-
56
- get path() {
57
- return this._url.path;
58
- }
59
-
60
- get owner() {
61
- return this._url.owner;
62
- }
63
-
64
- get repo() {
65
- return this._url.repo;
66
- }
67
-
68
- get ref() {
69
- return this._url.ref;
70
- }
71
-
72
- /**
73
- * JSON Serialization of Static
74
- * @typedef Static~JSON
75
- * @augments GitUrl~JSON
76
- * @property {boolean} magic
77
- * @property {String[]} allow
78
- * @property {String[]} deny
79
- */
80
-
81
- /**
82
- * Returns a json representation
83
- * @returns {Static~JSON}
84
- */
85
- toJSON(opts) {
86
- let json = {
87
- magic: this.magic,
88
- allow: this.allow,
89
- deny: this.deny,
90
- };
91
- if (opts && (opts.minimal || opts.keepFormat)) {
92
- json = pruneEmptyValues(json);
93
- }
94
- if (!json) {
95
- return this.url.toJSON(opts);
96
- }
97
- const myOpts = { ...opts };
98
- delete myOpts.keepFormat;
99
- return Object.assign(json, this.url.toJSON(myOpts));
100
- }
101
-
102
- toYAMLNode() {
103
- const props = pruneEmptyValues({
104
- magic: this.magic,
105
- allow: this.allow,
106
- deny: this.deny,
107
- });
108
- if (!props) {
109
- return this.url.toYAMLNode();
110
- }
111
- const node = this.url.toYAMLNode(true);
112
- Object.keys(props).forEach((key) => {
113
- node.items.push(new Pair(key, props[key]));
114
- });
115
- return node;
116
- }
117
- }
118
-
119
- module.exports = Static;
package/src/Strain.js DELETED
@@ -1,332 +0,0 @@
1
- /*
2
- * Copyright 2021 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- const URI = require('uri-js');
14
- const YAML = require('yaml');
15
- const { YAMLMap, Pair } = require('yaml/types');
16
- const { GitUrl } = require('@adobe/helix-shared-git');
17
- const pruneEmptyValues = require('@adobe/helix-shared-prune');
18
- const Origin = require('./Origin.js');
19
- const Static = require('./Static.js');
20
- const Performance = require('./Performance.js');
21
- const Redirect = require('./Redirect.js');
22
- const Condition = require('./Condition.js');
23
-
24
- /**
25
- * Strain
26
- */
27
- class Strain {
28
- constructor(cfg) {
29
- this._name = cfg.name;
30
- if (cfg.origin) {
31
- // proxy
32
- this._origin = new Origin(cfg.origin);
33
- } else {
34
- this._origin = null;
35
- this._content = new GitUrl(cfg.content, { ref: 'master' });
36
- this._code = new GitUrl(cfg.code, { ref: 'master' });
37
- // todo: 1. do we still need whilelists?
38
- this._static = new Static(cfg.static);
39
- // detect changes in static URL
40
- this._static.on('url-change', () => {
41
- this._modified('static', this._static);
42
- });
43
- this._directoryIndex = cfg.directoryIndex;
44
- this._package = cfg.package || '';
45
- }
46
-
47
- // todo: schema for perf
48
- this._perf = new Performance(cfg.perf);
49
- this._condition = cfg.condition ? new Condition(cfg.condition) : null;
50
-
51
- if (cfg.url) {
52
- throw new Error('url property is no longer supported.');
53
- }
54
-
55
- this._sticky = cfg.sticky;
56
-
57
- this._redirects = (Array.isArray(cfg.redirects) ? cfg.redirects : [])
58
- .map((r) => new Redirect(r));
59
-
60
- this._urls = new Set(Array.isArray(cfg.urls) ? cfg.urls.map(URI.normalize) : []);
61
- this._params = Array.isArray(cfg.params) ? cfg.params : [];
62
- this._versionLock = cfg['version-lock'];
63
- this._yamlNode = null;
64
- // define them initially, and clear for alias node
65
- // todo: improve
66
- this._ownProperties = new Set([
67
- 'name',
68
- 'origin',
69
- 'code',
70
- 'content',
71
- 'static',
72
- 'package',
73
- 'perf',
74
- 'condition',
75
- 'sticky',
76
- 'urls',
77
- 'params',
78
- 'redirects',
79
- 'version-lock',
80
- ]);
81
- }
82
-
83
- clone() {
84
- const strain = new Strain(this.toJSON({ keepFormat: true }));
85
- if (this._directoryIndex) {
86
- // this is a bit a hack...consider a better binding
87
- // eslint-disable-next-line no-underscore-dangle
88
- strain._ownProperties.add('directoryIndex');
89
- }
90
- // another neccessary hack
91
- // eslint-disable-next-line no-underscore-dangle
92
- strain._sticky = this._sticky;
93
- return strain;
94
- }
95
-
96
- get urls() {
97
- return Array.from(this._urls);
98
- }
99
-
100
- set urls(value) {
101
- if (Array.isArray(value)) {
102
- this._urls = new Set(value.map(URI.normalize));
103
- } else {
104
- this._urls = new Set([value].map(URI.normalize));
105
- }
106
- }
107
-
108
- get sticky() {
109
- // when `sticky` is not set
110
- // assume the strain to be sticky when the condition is
111
- return this._sticky === undefined && this._condition !== null
112
- ? this._condition.sticky()
113
- : !!this._sticky;
114
- }
115
-
116
- /**
117
- * Name of this strain.
118
- * @returns {String}
119
- */
120
- get name() {
121
- return this._name;
122
- }
123
-
124
- set name(value) {
125
- this._name = value;
126
- }
127
-
128
- /**
129
- * GitUrl of the content repository
130
- * @returns {GitUrl}
131
- */
132
- get content() {
133
- return this._content;
134
- }
135
-
136
- set content(url) {
137
- this._content = url;
138
- this._modified('content', url);
139
- }
140
-
141
- /**
142
- * GitUrl of the code repository
143
- * @returns {GitUrl}
144
- */
145
- get code() {
146
- return this._code;
147
- }
148
-
149
- set code(code) {
150
- this._code = code;
151
- this._modified('code', code);
152
- }
153
-
154
- /**
155
- * Static information of this strain
156
- * @returns {Static}
157
- */
158
- get static() {
159
- return this._static;
160
- }
161
-
162
- get package() {
163
- return this._package;
164
- }
165
-
166
- set package(value) {
167
- this._package = value;
168
- this._modified('package', value);
169
- }
170
-
171
- get params() {
172
- return this._params;
173
- }
174
-
175
- get condition() {
176
- return this._condition;
177
- }
178
-
179
- set condition(value) {
180
- this._condition = value;
181
- }
182
-
183
- get directoryIndex() {
184
- return this._directoryIndex || 'index.html';
185
- }
186
-
187
- set directoryIndex(value) {
188
- this._directoryIndex = value;
189
- this._modified('directoryIndex', value);
190
- }
191
-
192
- get perf() {
193
- return this._perf;
194
- }
195
-
196
- get origin() {
197
- return this._origin;
198
- }
199
-
200
- isProxy() {
201
- return this._origin !== null;
202
- }
203
-
204
- get redirects() {
205
- return this._redirects;
206
- }
207
-
208
- get versionLock() {
209
- return this._versionLock;
210
- }
211
-
212
- /**
213
- * JSON Serialization of a Strain
214
- * @typedef Strain~JSON
215
- * @property {String} name
216
- * @property {String} code
217
- * @property {GitUrl~JSON} content
218
- * @property {Static~JSON} static
219
- * @property {String} condition
220
- * @property {String} directoryIndex
221
- * @property {Performance~JSON} perf
222
- * @property {Origin~JSON} origin
223
- */
224
-
225
- /**
226
- * Returns a json representation
227
- * @returns {Strain~JSON}
228
- */
229
- toJSON(opts) {
230
- const json = {
231
- name: this.name,
232
- sticky: this.sticky,
233
- condition: this.condition ? this.condition.toJSON(opts) : '',
234
- perf: this.perf.toJSON(opts),
235
- urls: this.urls,
236
- };
237
- if (this.params.length > 0) {
238
- json.params = this.params;
239
- }
240
- if (this.redirects.length > 0) {
241
- json.redirects = this.redirects.map((r) => r.toJSON());
242
- }
243
- if (this.isProxy()) {
244
- return { origin: this.origin.toJSON(opts), ...json };
245
- }
246
- if (this.versionLock) {
247
- json['version-lock'] = this.versionLock;
248
- }
249
- const ret = {
250
- code: this.code.toJSON(opts),
251
- content: this.content.toJSON(opts),
252
- static: this.static.toJSON(opts),
253
- directoryIndex: this.directoryIndex,
254
- package: this.package,
255
- ...json,
256
- };
257
- if (opts && opts.minimal) {
258
- return pruneEmptyValues(ret);
259
- }
260
- return ret;
261
- }
262
-
263
- _modified(propertyName, propertyValue) {
264
- if (propertyName && propertyValue) {
265
- this._ownProperties.add(propertyName);
266
- }
267
-
268
- if (this._yamlNode) {
269
- const node = this._yamlNode;
270
- this._ownProperties.forEach((key) => {
271
- const idx = node.items.findIndex((i) => i.key === key
272
- || (i.key.value && i.key.value === key));
273
- let value = key === 'version-lock' ? this.versionLock : this[key];
274
- value = key === 'sticky' ? this._sticky : value;
275
- if (value && value.toYAMLNode) {
276
- value = value.toYAMLNode();
277
- }
278
- if (Array.isArray(value) && value.length === 0) {
279
- value = null;
280
- }
281
- if (value || (value === false && key === 'sticky')) {
282
- if (idx >= 0) {
283
- const item = node.items[idx];
284
- const oldValue = item.value.type === 'ALIAS' ? item.value.source : item.value;
285
- if (oldValue.toString() !== value.toString()) {
286
- item.value = value;
287
- }
288
- } else {
289
- node.items.push(new Pair(key, value));
290
- }
291
- } else if (idx >= 0) {
292
- node.items.splice(idx, 1);
293
- }
294
- });
295
- }
296
-
297
- if (propertyName && !propertyValue) {
298
- this._ownProperties.clear(propertyName);
299
- }
300
- }
301
-
302
- toYAML() {
303
- return YAML.stringify(this.toYAMLNode());
304
- }
305
-
306
- static fromYAMLNode(node) {
307
- /* eslint-disable no-underscore-dangle */
308
- const json = node.toJSON();
309
- const strain = new Strain(json);
310
- strain._yamlNode = node;
311
- strain._ownProperties.clear();
312
- if (node.type === 'MAP') {
313
- // remember our 'own' properties
314
- node.items.forEach((pair) => {
315
- strain._ownProperties.add(pair.key.value);
316
- });
317
- strain._ownProperties.delete('<<');
318
- }
319
- /* eslint-enable no-underscore-dangle */
320
- return strain;
321
- }
322
-
323
- toYAMLNode() {
324
- if (!this._yamlNode) {
325
- this._yamlNode = new YAMLMap();
326
- this._modified();
327
- }
328
- return this._yamlNode;
329
- }
330
- }
331
-
332
- module.exports = Strain;
package/src/Strains.js DELETED
@@ -1,68 +0,0 @@
1
- /*
2
- * Copyright 2018 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
- const Strain = require('./Strain.js');
13
-
14
- /**
15
- * Strains
16
- */
17
- class Strains extends Map {
18
- add(strain) {
19
- this.set(strain.name, strain);
20
- if (this._yamlNode) {
21
- const node = strain.toYAMLNode();
22
- node.spaceBefore = true;
23
- this._yamlNode.items.push(node);
24
- }
25
- }
26
-
27
- /**
28
- * Returns a json representation
29
- * @returns {Strains~JSON}
30
- */
31
- toJSON() {
32
- const strains = [];
33
- this.forEach((strain) => {
34
- strains.push(strain.toJSON());
35
- });
36
- return strains;
37
- }
38
-
39
- filterByCode(code) {
40
- return this.getByFilter((strain) => code.equalsIgnoreTransport(strain.code));
41
- }
42
-
43
- getByFilter(filterfn) {
44
- return [...this.values()].filter(filterfn);
45
- }
46
-
47
- getRuntimeStrains() {
48
- return this.getByFilter((strain) => !strain.isProxy());
49
- }
50
-
51
- getProxyStrains() {
52
- return this.getByFilter((strain) => strain.isProxy());
53
- }
54
-
55
- /**
56
- * Creates the strains from a yaml node
57
- * @param {YAMLSeq} node
58
- */
59
- fromYAML(node) {
60
- this._yamlNode = node;
61
- node.items.forEach((value) => {
62
- const strain = Strain.fromYAMLNode(value);
63
- this.set(strain.name, strain);
64
- });
65
- }
66
- }
67
-
68
- module.exports = Strains;