@zapier/policy-schema 0.15.0 → 0.17.0

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/index.cjs CHANGED
@@ -4,9 +4,14 @@ var zod = require('zod');
4
4
 
5
5
  // src/schema.ts
6
6
  var RUBBERDUCK_POLICY_VERSION = "rc-rubberduck";
7
- var VALID_VERSIONS = [1, 2, RUBBERDUCK_POLICY_VERSION];
7
+ var VALID_VERSIONS = [1, 2, 3, RUBBERDUCK_POLICY_VERSION];
8
+ var ID_BASED_VERSIONS = /* @__PURE__ */ new Set([
9
+ 3,
10
+ RUBBERDUCK_POLICY_VERSION
11
+ ]);
8
12
  var VALID_EFFECTS = ["allow", "ask", "deny"];
9
13
  var VALID_OPERATOR_LIST = [
14
+ "all",
10
15
  "equals",
11
16
  "exists",
12
17
  "in",
@@ -15,12 +20,15 @@ var VALID_OPERATOR_LIST = [
15
20
  "matches_host",
16
21
  "matches_path",
17
22
  "matches_url",
23
+ "none",
18
24
  "range",
19
25
  "size",
26
+ "some",
20
27
  "values_in"
21
28
  ];
22
29
  var ScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
23
30
  var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).min(1);
31
+ var RelativePathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()]));
24
32
  var ConditionValueSchema = zod.z.json();
25
33
  var EqualsConditionSchema = zod.z.object({
26
34
  path: PathSchema,
@@ -86,6 +94,24 @@ var SizeConditionSchema = zod.z.object({
86
94
  operator: zod.z.literal("size"),
87
95
  value: SizeValueSchema
88
96
  }).strict();
97
+ var RelativeConditionSchema = zod.z.union([
98
+ EqualsConditionSchema.extend({ path: RelativePathSchema }),
99
+ InConditionSchema.extend({ path: RelativePathSchema }),
100
+ MatchesConditionSchema.extend({ path: RelativePathSchema }),
101
+ MatchesHostConditionSchema.extend({ path: RelativePathSchema }),
102
+ MatchesPathConditionSchema.extend({ path: RelativePathSchema }),
103
+ RangeConditionSchema.extend({ path: RelativePathSchema }),
104
+ MatchesUrlConditionSchema.extend({ path: RelativePathSchema }),
105
+ ValuesInConditionSchema.extend({ path: RelativePathSchema }),
106
+ ExistsConditionSchema.extend({ path: RelativePathSchema }),
107
+ KeysInConditionSchema.extend({ path: RelativePathSchema }),
108
+ SizeConditionSchema.extend({ path: RelativePathSchema })
109
+ ]);
110
+ var QuantifierConditionSchema = zod.z.object({
111
+ path: PathSchema,
112
+ operator: zod.z.enum(["some", "all", "none"]),
113
+ where: zod.z.array(RelativeConditionSchema).min(1)
114
+ }).strict();
89
115
  var ConditionSchema = zod.z.union([
90
116
  // Scalar operators
91
117
  EqualsConditionSchema,
@@ -101,7 +127,8 @@ var ConditionSchema = zod.z.union([
101
127
  // Other operators
102
128
  ExistsConditionSchema,
103
129
  KeysInConditionSchema,
104
- SizeConditionSchema
130
+ SizeConditionSchema,
131
+ QuantifierConditionSchema
105
132
  ]);
106
133
  var ScalarOperatorSchema = zod.z.enum([
107
134
  "equals",
@@ -111,7 +138,7 @@ var ScalarOperatorSchema = zod.z.enum([
111
138
  "matches_path",
112
139
  "range"
113
140
  ]);
114
- var ArrayOperatorSchema = zod.z.enum(["values_in"]);
141
+ var ArrayOperatorSchema = zod.z.enum(["values_in", "some", "all", "none"]);
115
142
  var UrlOperatorSchema = zod.z.enum(["matches_url"]);
116
143
  var OtherOperatorSchema = zod.z.enum(["exists", "keys_in", "size"]);
117
144
  var OperatorSchema = zod.z.enum([
@@ -126,6 +153,9 @@ var OperatorSchema = zod.z.enum([
126
153
  "matches_url",
127
154
  // Array
128
155
  "values_in",
156
+ "some",
157
+ "all",
158
+ "none",
129
159
  // Other
130
160
  "exists",
131
161
  "keys_in",
@@ -170,9 +200,24 @@ var RcRubberduckPolicySchema = zod.z.object({
170
200
  defaultEffect: DefaultEffectSchema,
171
201
  statements: zod.z.array(RcRubberduckStatementSchema)
172
202
  }).strict();
203
+ var V3_MAX_TIERS = 3;
204
+ var V3StatementSchema = zod.z.object({
205
+ id: StatementIdSchema,
206
+ effect: zod.z.enum(["allow", "ask", "deny"]),
207
+ permissions: zod.z.array(zod.z.string()).min(1),
208
+ resources: zod.z.array(zod.z.string()).min(1),
209
+ conditions: zod.z.array(ConditionSchema).optional()
210
+ }).strict();
211
+ var V3PolicySchema = zod.z.object({
212
+ version: zod.z.literal(3),
213
+ // Ordered tiers, in priority order. 1..V3_MAX_TIERS tiers; a tier may be
214
+ // empty (e.g. `[[]]` denies everything).
215
+ statements: zod.z.array(zod.z.array(V3StatementSchema)).min(1).max(V3_MAX_TIERS)
216
+ }).strict();
173
217
  var PolicySchema = zod.z.union([
174
218
  V1PolicySchema,
175
219
  V2PolicySchema,
220
+ V3PolicySchema,
176
221
  RcRubberduckPolicySchema
177
222
  ]);
178
223
  var CanonicalHashSchema = zod.z.custom(
@@ -237,73 +282,76 @@ var OverrideSchema = zod.z.union([
237
282
  }).strict()
238
283
  ]);
239
284
  function getOpenApiSchema() {
240
- return {
285
+ const statementItems = {
241
286
  type: "object",
242
- required: ["version", "statements"],
287
+ required: ["effect", "permissions", "resources"],
243
288
  properties: {
244
- version: {
245
- anyOf: [
246
- { type: "integer", enum: [1, 2] },
247
- { type: "string", enum: [RUBBERDUCK_POLICY_VERSION] }
248
- ],
249
- description: "Policy schema version. Stable versions are 1 and 2; supported release candidates are rc-rubberduck."
250
- },
251
289
  id: {
252
290
  type: "string",
253
- description: "Policy id (required for rc-rubberduck policies). Must use the p_ prefix and contain no whitespace."
291
+ description: "Statement identifier. Required for v3 and rc-rubberduck policies; must use the s_ prefix with no whitespace. Optional on v1/v2 for debugging and provenance."
254
292
  },
255
- defaultEffect: {
293
+ effect: {
256
294
  type: "string",
257
- enum: [...DefaultEffectSchema.options],
258
- description: "Effect applied when no statement matches. Required on rc-rubberduck policies; deny equals implicit deny."
295
+ enum: [...VALID_EFFECTS].sort(),
296
+ description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is valid in version 2, version 3, and rc-rubberduck policies."
259
297
  },
260
- statements: {
298
+ permissions: {
299
+ type: "array",
300
+ minItems: 1,
301
+ items: { type: "string" },
302
+ description: "List of permission identifiers."
303
+ },
304
+ resources: {
261
305
  type: "array",
262
- description: "List of policy statements defining permissions.",
306
+ minItems: 1,
307
+ items: { type: "string" },
308
+ description: "List of resource identifiers the statement applies to."
309
+ },
310
+ conditions: {
311
+ type: "array",
312
+ description: "Optional conditions that must be met for the statement to apply.",
263
313
  items: {
264
314
  type: "object",
265
- required: ["effect", "permissions", "resources"],
315
+ required: ["path", "operator"],
266
316
  properties: {
267
- id: {
268
- type: "string",
269
- description: "Statement identifier. Required for rc-rubberduck policies; must use the s_ prefix with no whitespace. Optional on v1/v2 for debugging and provenance."
317
+ path: {
318
+ type: "array",
319
+ minItems: 1,
320
+ description: "Path to the value to evaluate in the request context.",
321
+ items: {
322
+ anyOf: [{ type: "string" }, { type: "integer" }]
323
+ }
270
324
  },
271
- effect: {
325
+ operator: {
272
326
  type: "string",
273
- enum: [...VALID_EFFECTS].sort(),
274
- description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is valid in version 2 and rc-rubberduck policies."
327
+ enum: [...VALID_OPERATOR_LIST],
328
+ description: "Comparison operator used to evaluate the condition."
275
329
  },
276
- permissions: {
277
- type: "array",
278
- minItems: 1,
279
- items: { type: "string" },
280
- description: "List of permission identifiers."
330
+ value: {
331
+ description: "Value to compare against using the operator."
281
332
  },
282
- resources: {
333
+ where: {
283
334
  type: "array",
284
335
  minItems: 1,
285
- items: { type: "string" },
286
- description: "List of resource identifiers the statement applies to."
287
- },
288
- conditions: {
289
- type: "array",
290
- description: "Optional conditions that must be met for the statement to apply.",
336
+ description: "Conditions evaluated relative to each collection element for some, all, and none.",
291
337
  items: {
292
338
  type: "object",
293
339
  required: ["path", "operator"],
294
340
  properties: {
295
341
  path: {
296
342
  type: "array",
297
- minItems: 1,
298
- description: "Path to the value to evaluate in the request context.",
343
+ minItems: 0,
344
+ description: "Path relative to the collection element; an empty path selects the element itself.",
299
345
  items: {
300
346
  anyOf: [{ type: "string" }, { type: "integer" }]
301
347
  }
302
348
  },
303
349
  operator: {
304
350
  type: "string",
305
- enum: [...VALID_OPERATOR_LIST],
306
- description: "Comparison operator used to evaluate the condition."
351
+ enum: [...VALID_OPERATOR_LIST].filter(
352
+ (operator) => operator !== "some" && operator !== "all" && operator !== "none"
353
+ ),
354
+ description: "Non-quantifier operator evaluated against the collection element."
307
355
  },
308
356
  value: {
309
357
  description: "Value to compare against using the operator."
@@ -316,6 +364,42 @@ function getOpenApiSchema() {
316
364
  }
317
365
  }
318
366
  };
367
+ return {
368
+ type: "object",
369
+ required: ["version", "statements"],
370
+ properties: {
371
+ version: {
372
+ anyOf: [
373
+ { type: "integer", enum: [1, 2, 3] },
374
+ { type: "string", enum: [RUBBERDUCK_POLICY_VERSION] }
375
+ ],
376
+ description: "Policy schema version. Stable versions are 1, 2, and 3; supported release candidates are rc-rubberduck."
377
+ },
378
+ id: {
379
+ type: "string",
380
+ description: "Policy id (required for rc-rubberduck policies; not permitted on any other version). Must use the p_ prefix and contain no whitespace."
381
+ },
382
+ defaultEffect: {
383
+ type: "string",
384
+ enum: [...DefaultEffectSchema.options],
385
+ description: "Effect applied when no statement matches. Required on rc-rubberduck policies (deny equals implicit deny); not permitted on any other version."
386
+ },
387
+ statements: {
388
+ type: "array",
389
+ description: "Policy statements. For v1/v2/rc-rubberduck each entry is a statement. For v3 each entry is a tier (a list of statements); tiers are in priority order and evaluated first-to-last (the first tier with a match decides), so `statements` is a list of lists.",
390
+ items: {
391
+ anyOf: [
392
+ statementItems,
393
+ {
394
+ type: "array",
395
+ description: "A v3 tier: statements evaluated together with deny > ask > allow precedence.",
396
+ items: statementItems
397
+ }
398
+ ]
399
+ }
400
+ }
401
+ }
402
+ };
319
403
  }
320
404
 
321
405
  exports.ArrayOperatorSchema = ArrayOperatorSchema;
@@ -323,6 +407,7 @@ exports.CanonicalHashSchema = CanonicalHashSchema;
323
407
  exports.ConditionSchema = ConditionSchema;
324
408
  exports.ConditionValueSchema = ConditionValueSchema;
325
409
  exports.DefaultEffectSchema = DefaultEffectSchema;
410
+ exports.ID_BASED_VERSIONS = ID_BASED_VERSIONS;
326
411
  exports.OperatorSchema = OperatorSchema;
327
412
  exports.OtherOperatorSchema = OtherOperatorSchema;
328
413
  exports.OverrideSchema = OverrideSchema;
@@ -335,6 +420,7 @@ exports.SizeValueSchema = SizeValueSchema;
335
420
  exports.StatementIdSchema = StatementIdSchema;
336
421
  exports.StatementSchema = StatementSchema;
337
422
  exports.UrlOperatorSchema = UrlOperatorSchema;
423
+ exports.V3_MAX_TIERS = V3_MAX_TIERS;
338
424
  exports.VALID_EFFECTS = VALID_EFFECTS;
339
425
  exports.VALID_OPERATOR_LIST = VALID_OPERATOR_LIST;
340
426
  exports.VALID_VERSIONS = VALID_VERSIONS;