edge-functions 2.9.1 → 2.9.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### [2.9.2](https://github.com/aziontech/vulcan/compare/v2.9.1...v2.9.2) (2024-06-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * simplify rewrite rule ([#346](https://github.com/aziontech/vulcan/issues/346)) ([4e5756b](https://github.com/aziontech/vulcan/commit/4e5756bd633c9191363c561c5e47e6f2c346ba90))
7
+
8
+ ### [2.9.2-stage.1](https://github.com/aziontech/vulcan/compare/v2.9.1...v2.9.2-stage.1) (2024-06-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * simplify rewrite rule ([#346](https://github.com/aziontech/vulcan/issues/346)) ([4e5756b](https://github.com/aziontech/vulcan/commit/4e5756bd633c9191363c561c5e47e6f2c346ba90))
14
+
1
15
  ### [2.9.1](https://github.com/aziontech/vulcan/compare/v2.9.0...v2.9.1) (2024-06-21)
2
16
 
3
17
 
package/README.md CHANGED
@@ -19,10 +19,10 @@ Table:
19
19
  | Next 13 5 6 Middleware | ✅ |
20
20
  | Next 12 3 4 Middleware | ✅ |
21
21
  | Next Node Pages 12 3 1 | ✅ |
22
- | Next 13 5 6 Config | ⚠️ |
22
+ | Next 13 5 6 Config | |
23
23
  | Next 12 3 4 Config | ✅ |
24
24
  | Next Static | ✅ |
25
- | Gatsby Static | |
25
+ | Gatsby Static | ⚠️ |
26
26
  | Next Node Pages 12 3 1 Fs | ✅ |
27
27
  | Vue Vite Static | ✅ |
28
28
  | Next 12 Static | ✅ |
@@ -41,7 +41,7 @@ Table:
41
41
  | Simple Js Esm | ✅ |
42
42
  | Simple Ts Esm | ✅ |
43
43
 
44
- Last test run date: 06/21/24 03:23:09 AM
44
+ Last test run date: 06/24/24 03:23:39 AM
45
45
  ## Quick Installation
46
46
 
47
47
  For those who just want to use Vulcan in their project without contributing to the development, you can install it directly from npm.
@@ -35,9 +35,7 @@ const AzionConfig = {
35
35
  name: 'Redirect to index.html',
36
36
  match: '^\\/',
37
37
  behavior: {
38
- rewrite: {
39
- set: () => `/index.html`,
40
- },
38
+ rewrite: `/index.html`,
41
39
  },
42
40
  },
43
41
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -33,18 +33,14 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ rewrite: '${uri}index.html',
39
37
  },
40
38
  },
41
39
  {
42
40
  name: 'Redirect to index.html for Subpaths',
43
41
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
42
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
43
+ rewrite: '${uri}/index.html',
48
44
  },
49
45
  },
50
46
  ],
@@ -35,9 +35,7 @@ const AzionConfig = {
35
35
  name: 'Redirect to index.html',
36
36
  match: '^\\/',
37
37
  behavior: {
38
- rewrite: {
39
- set: () => `/index.html`,
40
- },
38
+ rewrite: `/index.html`,
41
39
  },
42
40
  },
43
41
  ],
@@ -33,18 +33,16 @@ const AzionConfig = {
33
33
  name: 'Redirect to index.html',
34
34
  match: '.*/$',
35
35
  behavior: {
36
- rewrite: {
37
- set: (uri) => `${uri}index.html`,
38
- },
36
+ // eslint-disable-next-line no-template-curly-in-string
37
+ rewrite: '${uri}index.html',
39
38
  },
40
39
  },
41
40
  {
42
41
  name: 'Redirect to index.html for Subpaths',
43
42
  match: '^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*',
44
43
  behavior: {
45
- rewrite: {
46
- set: (uri) => `${uri}/index.html`,
47
- },
44
+ // eslint-disable-next-line no-template-curly-in-string
45
+ rewrite: '${uri}/index.html',
48
46
  },
49
47
  },
50
48
  ],
@@ -34,9 +34,7 @@ const AzionConfig = {
34
34
  name: 'Redirect to index.html',
35
35
  match: '^\\/',
36
36
  behavior: {
37
- rewrite: {
38
- set: () => `/index.html`,
39
- },
37
+ rewrite: `/index.html`,
40
38
  },
41
39
  },
42
40
  ],
@@ -86,17 +86,18 @@ function jsToJson(inputConfig) {
86
86
  // Convert cache settings
87
87
  if (config && config.cache && config.cache.length > 0) {
88
88
  config.cache.forEach((cache) => {
89
- const maxAgeSecondsBrowser = evaluateMathExpression(
90
- cache?.browser?.maxAgeSeconds,
91
- );
92
- const maxAgeSecondsEdge = evaluateMathExpression(
93
- cache?.edge?.maxAgeSeconds,
94
- );
89
+ const maxAgeSecondsBrowser = cache?.browser
90
+ ? evaluateMathExpression(cache.browser.maxAgeSeconds)
91
+ : 0;
92
+ const maxAgeSecondsEdge = cache?.edge
93
+ ? evaluateMathExpression(cache.edge.maxAgeSeconds)
94
+ : 60;
95
95
 
96
96
  const cacheSetting = {
97
97
  name: cache.name,
98
- browser_cache_settings: 'override',
98
+ browser_cache_settings: cache?.browser ? 'override' : 'honor',
99
99
  browser_cache_settings_maximum_ttl: maxAgeSecondsBrowser,
100
+ cdn_cache_settings: cache?.edge ? 'override' : 'honor',
100
101
  cdn_cache_settings_maximum_ttl: maxAgeSecondsEdge,
101
102
  enable_caching_for_post: cache?.methods?.post || false,
102
103
  enable_caching_for_options: cache?.methods?.options || false,
@@ -50,50 +50,6 @@ describe('Utils - generateManifest', () => {
50
50
  );
51
51
  });
52
52
 
53
- it('should handle rewrites with dynamic parameter names correctly', () => {
54
- const azionConfig = {
55
- rules: {
56
- request: [
57
- {
58
- name: 'rewriteRule',
59
- match: '/path',
60
- behavior: {
61
- capture: {
62
- match: '^(./)([^/])$',
63
- captured: 'other',
64
- subject: 'uri',
65
- },
66
- rewrite: {
67
- match: '^(./)([^/])$',
68
- set: (other) => `/${other[0]}/${other[1]}`,
69
- },
70
- },
71
- },
72
- ],
73
- },
74
- };
75
-
76
- const result = jsToJson(azionConfig);
77
- expect(result.rules[0].behaviors).toEqual(
78
- expect.arrayContaining([
79
- expect.objectContaining({
80
- name: 'capture_match_groups',
81
- target: expect.objectContaining({
82
- regex: '^(./)([^/])$',
83
- captured_array: 'other',
84
- // eslint-disable-next-line no-template-curly-in-string
85
- subject: '${uri}',
86
- }),
87
- }),
88
- expect.objectContaining({
89
- name: 'rewrite_request',
90
- // eslint-disable-next-line no-template-curly-in-string
91
- target: '/${other[0]}/${other[1]}',
92
- }),
93
- ]),
94
- );
95
- });
96
-
97
53
  it('should handle rewrites directly as a string', () => {
98
54
  const azionConfig = {
99
55
  rules: {
@@ -34,11 +34,7 @@ export default {
34
34
  match: '^/rewrite$',
35
35
  behavior: {
36
36
  setCache: 'mycache1',
37
- rewrite: {
38
- match: '^(./)([^/])$',
39
- subject: 'uri',
40
- set: (captured) => `/new/${captured[1]}`, // Rewrites /original/image.jpg to /new/image.jpg
41
- },
37
+ rewrite: `/new/%{captured[1]}`, // Rewrites /original/image.jpg to /new/image.jpg
42
38
  setCookie: 'user=12345; Path=/; Secure',
43
39
  setHeaders: 'Cache-Control: no-cache',
44
40
  forwardCookies: true,
@@ -24,42 +24,10 @@ export const requestBehaviors = {
24
24
  rewrite: {
25
25
  transform: (value) => {
26
26
  const behaviors = [];
27
-
28
- if (typeof value === 'string') {
29
- behaviors.push({
30
- name: 'rewrite_request',
31
- target: value,
32
- });
33
- return behaviors;
34
- }
35
-
36
- const functionString = value.set.toString();
37
- const paramNameMatch = functionString.match(/\(([^)]+)\)/);
38
- let paramName = paramNameMatch ? paramNameMatch[1] : null;
39
- if (paramName) {
40
- [paramName] = paramName.trim().split(/\s*,\s*/);
41
- }
42
-
43
- if (value.match) {
44
- behaviors.push({
45
- name: 'capture_match_groups',
46
- target: {
47
- captured_array: paramName || 'captured',
48
- subject: `\${${value.subject ?? 'uri'}}`,
49
- regex: value.match,
50
- },
51
- });
52
- }
53
-
54
- const pathTransformation = functionString
55
- .replace(/.*=>\s*`/, '')
56
- .replace(/`\s*;?\s*}?\s*$/, '');
57
-
58
27
  behaviors.push({
59
28
  name: 'rewrite_request',
60
- target: pathTransformation,
29
+ target: value,
61
30
  });
62
-
63
31
  return behaviors;
64
32
  },
65
33
  },
@@ -205,40 +205,8 @@ const azionConfigSchema = {
205
205
  },
206
206
  },
207
207
  rewrite: {
208
- oneOf: [
209
- {
210
- type: 'object',
211
- properties: {
212
- match: {
213
- type: ['string', 'null'],
214
- errorMessage:
215
- "The 'match' field must be a string or null.",
216
- },
217
- subject: {
218
- type: ['string', 'null'],
219
- errorMessage:
220
- "The 'subject' field must be a string or null.",
221
- },
222
- set: {
223
- instanceof: 'Function',
224
- errorMessage: "The 'set' field must be a function.",
225
- },
226
- },
227
- required: ['set'],
228
- additionalProperties: false,
229
- errorMessage: {
230
- additionalProperties:
231
- "No additional properties are allowed in the 'rewrite' object.",
232
- required:
233
- "The 'set' field is required in the 'rewrite' object.",
234
- },
235
- },
236
- {
237
- type: 'string',
238
- errorMessage:
239
- "The 'rewrite' field can be a direct string.",
240
- },
241
- ],
208
+ type: 'string',
209
+ errorMessage: "The 'rewrite' field must be a string.",
242
210
  },
243
211
  setHeaders: {
244
212
  type: 'array',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "edge-functions",
3
3
  "type": "module",
4
- "version": "2.9.1",
4
+ "version": "2.9.2",
5
5
  "description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.",
6
6
  "main": "lib/main.js",
7
7
  "bin": {