@vercel/routing-utils 5.0.4 → 5.0.6

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/dist/schemas.js CHANGED
@@ -27,6 +27,101 @@ __export(schemas_exports, {
27
27
  trailingSlashSchema: () => trailingSlashSchema
28
28
  });
29
29
  module.exports = __toCommonJS(schemas_exports);
30
+ const mitigateSchema = {
31
+ description: "Mitigation action to take on a route",
32
+ type: "object",
33
+ additionalProperties: false,
34
+ required: ["action"],
35
+ properties: {
36
+ action: {
37
+ description: "The mitigation action to take",
38
+ type: "string",
39
+ enum: ["challenge", "deny"]
40
+ }
41
+ }
42
+ };
43
+ const matchableValueSchema = {
44
+ description: "A value to match against. Can be a string (regex) or a condition operation object",
45
+ anyOf: [
46
+ {
47
+ description: "A regular expression used to match thev value. Named groups can be used in the destination.",
48
+ type: "string",
49
+ maxLength: 4096
50
+ },
51
+ {
52
+ description: "A condition operation object",
53
+ type: "object",
54
+ additionalProperties: false,
55
+ minProperties: 1,
56
+ properties: {
57
+ eq: {
58
+ description: "Equal to",
59
+ anyOf: [
60
+ {
61
+ type: "string",
62
+ maxLength: 4096
63
+ },
64
+ {
65
+ type: "number"
66
+ }
67
+ ]
68
+ },
69
+ neq: {
70
+ description: "Not equal",
71
+ type: "string",
72
+ maxLength: 4096
73
+ },
74
+ inc: {
75
+ description: "In array",
76
+ type: "array",
77
+ items: {
78
+ type: "string",
79
+ maxLength: 4096
80
+ }
81
+ },
82
+ ninc: {
83
+ description: "Not in array",
84
+ type: "array",
85
+ items: {
86
+ type: "string",
87
+ maxLength: 4096
88
+ }
89
+ },
90
+ pre: {
91
+ description: "Starts with",
92
+ type: "string",
93
+ maxLength: 4096
94
+ },
95
+ suf: {
96
+ description: "Ends with",
97
+ type: "string",
98
+ maxLength: 4096
99
+ },
100
+ re: {
101
+ description: "Regex",
102
+ type: "string",
103
+ maxLength: 4096
104
+ },
105
+ gt: {
106
+ description: "Greater than",
107
+ type: "number"
108
+ },
109
+ gte: {
110
+ description: "Greater than or equal to",
111
+ type: "number"
112
+ },
113
+ lt: {
114
+ description: "Less than",
115
+ type: "number"
116
+ },
117
+ lte: {
118
+ description: "Less than or equal to",
119
+ type: "number"
120
+ }
121
+ }
122
+ }
123
+ ]
124
+ };
30
125
  const hasSchema = {
31
126
  description: "An array of requirements that are needed to match",
32
127
  type: "array",
@@ -43,11 +138,7 @@ const hasSchema = {
43
138
  type: "string",
44
139
  enum: ["host"]
45
140
  },
46
- value: {
47
- description: "A regular expression used to match the value. Named groups can be used in the destination",
48
- type: "string",
49
- maxLength: 4096
50
- }
141
+ value: matchableValueSchema
51
142
  }
52
143
  },
53
144
  {
@@ -65,11 +156,7 @@ const hasSchema = {
65
156
  type: "string",
66
157
  maxLength: 4096
67
158
  },
68
- value: {
69
- description: "A regular expression used to match the value. Named groups can be used in the destination",
70
- type: "string",
71
- maxLength: 4096
72
- }
159
+ value: matchableValueSchema
73
160
  }
74
161
  }
75
162
  ]
@@ -186,7 +273,8 @@ const routesSchema = {
186
273
  }
187
274
  },
188
275
  has: hasSchema,
189
- missing: hasSchema
276
+ missing: hasSchema,
277
+ mitigate: mitigateSchema
190
278
  }
191
279
  },
192
280
  {
@@ -254,14 +254,26 @@ const normalizeHasKeys = (hasItems = []) => {
254
254
  }
255
255
  return hasItems;
256
256
  };
257
+ function getStringValueForRegex(value) {
258
+ if (typeof value === "string") {
259
+ return value;
260
+ }
261
+ if (value && typeof value === "object" && value !== null) {
262
+ if ("re" in value && typeof value.re === "string") {
263
+ return value.re;
264
+ }
265
+ }
266
+ return null;
267
+ }
257
268
  function collectHasSegments(has) {
258
269
  const hasSegments = /* @__PURE__ */ new Set();
259
270
  for (const hasItem of has || []) {
260
271
  if (!hasItem.value && "key" in hasItem) {
261
272
  hasSegments.add(hasItem.key);
262
273
  }
263
- if (hasItem.value) {
264
- for (const match of hasItem.value.matchAll(namedGroupsRegex)) {
274
+ const stringValue = getStringValueForRegex(hasItem.value);
275
+ if (stringValue) {
276
+ for (const match of stringValue.matchAll(namedGroupsRegex)) {
265
277
  if (match[1]) {
266
278
  hasSegments.add(match[1]);
267
279
  }
package/dist/types.d.ts CHANGED
@@ -7,13 +7,27 @@ export type RouteApiError = {
7
7
  action?: string;
8
8
  errors?: string[];
9
9
  };
10
+ type MatchableValue = string | {
11
+ eq?: string | number;
12
+ neq?: string;
13
+ inc?: string[];
14
+ ninc?: string[];
15
+ pre?: string;
16
+ suf?: string;
17
+ re?: string;
18
+ gt?: number;
19
+ gte?: number;
20
+ lt?: number;
21
+ lte?: number;
22
+ };
23
+ type MitigateAction = 'challenge' | 'deny';
10
24
  export type HasField = Array<{
11
25
  type: 'host';
12
- value: string;
26
+ value: MatchableValue;
13
27
  } | {
14
28
  type: 'header' | 'cookie' | 'query';
15
29
  key: string;
16
- value?: string;
30
+ value?: MatchableValue;
17
31
  }>;
18
32
  export type RouteWithSrc = {
19
33
  src: string;
@@ -30,6 +44,9 @@ export type RouteWithSrc = {
30
44
  status?: number;
31
45
  has?: HasField;
32
46
  missing?: HasField;
47
+ mitigate?: {
48
+ action: MitigateAction;
49
+ };
33
50
  locale?: {
34
51
  redirect?: Record<string, string>;
35
52
  cookie?: string;
@@ -116,3 +133,4 @@ export interface AppendRoutesToPhaseProps {
116
133
  */
117
134
  phase: HandleValue | null;
118
135
  }
136
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/routing-utils",
3
- "version": "5.0.4",
3
+ "version": "5.0.6",
4
4
  "description": "Vercel routing utilities",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",