@zapier/policy-schema 0.18.0 → 1.0.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,10 @@ 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, 3, RUBBERDUCK_POLICY_VERSION];
7
+ var VALID_VERSIONS = [1, 2, 3, 4, RUBBERDUCK_POLICY_VERSION];
8
8
  var ID_BASED_VERSIONS = /* @__PURE__ */ new Set([
9
9
  3,
10
+ 4,
10
11
  RUBBERDUCK_POLICY_VERSION
11
12
  ]);
12
13
  var VALID_EFFECTS = ["allow", "ask", "deny"];
@@ -191,6 +192,7 @@ var V2StatementSchema = zod.z.object({
191
192
  var StatementSchema = V2StatementSchema;
192
193
  var StatementIdSchema = zod.z.string().regex(/^s_\S+$/, { error: "Statement id must match ^s_\\S+$" }).max(512);
193
194
  var PolicyIdSchema = zod.z.string().regex(/^p_\S+$/, { error: "Policy id must match ^p_\\S+$" }).max(512);
195
+ var RuleIdSchema = zod.z.string().regex(/^r_\S+$/, { error: "Rule id must match ^r_\\S+$" }).max(512);
194
196
  var V1PolicySchema = zod.z.object({
195
197
  version: zod.z.literal(1),
196
198
  statements: zod.z.array(V1StatementSchema)
@@ -227,10 +229,25 @@ var V3PolicySchema = zod.z.object({
227
229
  // empty (e.g. `[[]]` denies everything).
228
230
  statements: zod.z.array(zod.z.array(V3StatementSchema)).min(1).max(V3_MAX_TIERS)
229
231
  }).strict();
232
+ var V4_MAX_TIERS = 3;
233
+ var V4RuleSchema = zod.z.object({
234
+ id: RuleIdSchema,
235
+ effect: zod.z.enum(["allow", "ask", "deny"]),
236
+ permissions: zod.z.array(zod.z.string()).min(1),
237
+ resources: zod.z.array(zod.z.string()).min(1),
238
+ conditions: zod.z.array(ConditionSchema).optional()
239
+ }).strict();
240
+ var V4PolicySchema = zod.z.object({
241
+ version: zod.z.literal(4),
242
+ // Ordered tiers, in priority order. 1..V4_MAX_TIERS tiers; a tier may be
243
+ // empty (e.g. `[[]]` denies everything). Renamed from v3's `statements`.
244
+ rules: zod.z.array(zod.z.array(V4RuleSchema)).min(1).max(V4_MAX_TIERS)
245
+ }).strict();
230
246
  var PolicySchema = zod.z.union([
231
247
  V1PolicySchema,
232
248
  V2PolicySchema,
233
249
  V3PolicySchema,
250
+ V4PolicySchema,
234
251
  RcRubberduckPolicySchema
235
252
  ]);
236
253
  var CanonicalHashSchema = zod.z.custom(
@@ -265,6 +282,12 @@ var OverridePolicyIdBaseShape = {
265
282
  policyId: PolicyIdSchema,
266
283
  effect: zod.z.literal("allow")
267
284
  };
285
+ var OverrideRuleIdBaseShape = {
286
+ id: zod.z.string().optional(),
287
+ /** Targets a v4 rule by id (r_ prefix, non-null). */
288
+ ruleId: RuleIdSchema,
289
+ effect: zod.z.literal("allow")
290
+ };
268
291
  var OverrideSchema = zod.z.union([
269
292
  // statementHash × match
270
293
  zod.z.object({ ...OverrideHashBaseShape, match: zod.z.literal("any") }).strict(),
@@ -292,6 +315,15 @@ var OverrideSchema = zod.z.union([
292
315
  zod.z.object({
293
316
  ...OverridePolicyIdBaseShape,
294
317
  conditionals: zod.z.array(ConditionSchema)
318
+ }).strict(),
319
+ // ruleId × match
320
+ zod.z.object({ ...OverrideRuleIdBaseShape, match: zod.z.literal("any") }).strict(),
321
+ // ruleId × contextHash
322
+ zod.z.object({ ...OverrideRuleIdBaseShape, contextHash: CanonicalHashSchema }).strict(),
323
+ // ruleId × conditionals
324
+ zod.z.object({
325
+ ...OverrideRuleIdBaseShape,
326
+ conditionals: zod.z.array(ConditionSchema)
295
327
  }).strict()
296
328
  ]);
297
329
  function getOpenApiSchema() {
@@ -306,7 +338,7 @@ function getOpenApiSchema() {
306
338
  effect: {
307
339
  type: "string",
308
340
  enum: [...VALID_EFFECTS].sort(),
309
- description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is valid in version 2, version 3, and rc-rubberduck policies."
341
+ description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is valid in version 2, version 3, version 4, and rc-rubberduck policies."
310
342
  },
311
343
  permissions: {
312
344
  type: "array",
@@ -385,42 +417,123 @@ function getOpenApiSchema() {
385
417
  }
386
418
  }
387
419
  };
388
- return {
389
- type: "object",
390
- required: ["version", "statements"],
420
+ const ruleItems = {
421
+ ...statementItems,
391
422
  properties: {
392
- version: {
393
- anyOf: [
394
- { type: "integer", enum: [1, 2, 3] },
395
- { type: "string", enum: [RUBBERDUCK_POLICY_VERSION] }
396
- ],
397
- description: "Policy schema version. Stable versions are 1, 2, and 3; supported release candidates are rc-rubberduck."
398
- },
423
+ ...statementItems.properties,
399
424
  id: {
400
425
  type: "string",
401
- description: "Policy id (required for rc-rubberduck policies; not permitted on any other version). Must use the p_ prefix and contain no whitespace."
426
+ description: "Rule identifier. Required for v4 policies; must use the r_ prefix with no whitespace."
402
427
  },
403
- defaultEffect: {
404
- type: "string",
405
- enum: [...DefaultEffectSchema.options],
406
- description: "Effect applied when no statement matches. Required on rc-rubberduck policies (deny equals implicit deny); not permitted on any other version."
428
+ resources: {
429
+ ...statementItems.properties.resources,
430
+ description: "List of resource identifiers the rule applies to."
407
431
  },
408
- statements: {
409
- type: "array",
410
- 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.",
411
- items: {
412
- anyOf: [
413
- statementItems,
414
- {
415
- type: "array",
416
- description: "A v3 tier: statements evaluated together with deny > ask > allow precedence.",
417
- items: statementItems
418
- }
419
- ]
420
- }
432
+ conditions: {
433
+ ...statementItems.properties.conditions,
434
+ description: "Optional conditions that must be met for the rule to apply."
421
435
  }
422
436
  }
423
437
  };
438
+ const versionDescription = "Policy schema version. Stable versions are 1, 2, 3, and 4; supported release candidates are rc-rubberduck.";
439
+ const flatStatements = {
440
+ type: "array",
441
+ description: "Policy statements; each entry is a statement.",
442
+ items: statementItems
443
+ };
444
+ const statementTiers = {
445
+ type: "array",
446
+ description: "v3 tiers in priority order; each entry is a tier (a list of statements) evaluated first-to-last (the first tier with a match decides), so `statements` is a list of lists.",
447
+ items: {
448
+ type: "array",
449
+ description: "A v3 tier: statements evaluated together with deny > ask > allow precedence.",
450
+ items: statementItems
451
+ }
452
+ };
453
+ const ruleTiers = {
454
+ type: "array",
455
+ description: "v4 rules in priority order; each entry is a tier (a list of rules) evaluated first-to-last (the first tier with a match decides), so `rules` is a list of lists.",
456
+ items: {
457
+ type: "array",
458
+ description: "A v4 tier: rules evaluated together with deny > ask > allow precedence.",
459
+ items: ruleItems
460
+ }
461
+ };
462
+ const idProperty = {
463
+ type: "string",
464
+ description: "Policy id (rc-rubberduck only). Must use the p_ prefix and contain no whitespace."
465
+ };
466
+ const defaultEffectProperty = {
467
+ type: "string",
468
+ enum: [...DefaultEffectSchema.options],
469
+ description: "Effect applied when no statement matches (rc-rubberduck only; deny equals implicit deny)."
470
+ };
471
+ return {
472
+ oneOf: [
473
+ {
474
+ type: "object",
475
+ required: ["version", "statements"],
476
+ properties: {
477
+ version: {
478
+ type: "integer",
479
+ const: 1,
480
+ description: versionDescription
481
+ },
482
+ statements: flatStatements
483
+ }
484
+ },
485
+ {
486
+ type: "object",
487
+ required: ["version", "statements"],
488
+ properties: {
489
+ version: {
490
+ type: "integer",
491
+ const: 2,
492
+ description: versionDescription
493
+ },
494
+ statements: flatStatements
495
+ }
496
+ },
497
+ {
498
+ type: "object",
499
+ required: ["version", "statements"],
500
+ properties: {
501
+ version: {
502
+ type: "integer",
503
+ const: 3,
504
+ description: versionDescription
505
+ },
506
+ statements: statementTiers
507
+ }
508
+ },
509
+ {
510
+ type: "object",
511
+ required: ["version", "rules"],
512
+ properties: {
513
+ version: {
514
+ type: "integer",
515
+ const: 4,
516
+ description: versionDescription
517
+ },
518
+ rules: ruleTiers
519
+ }
520
+ },
521
+ {
522
+ type: "object",
523
+ required: ["version", "id", "defaultEffect", "statements"],
524
+ properties: {
525
+ version: {
526
+ type: "string",
527
+ const: RUBBERDUCK_POLICY_VERSION,
528
+ description: versionDescription
529
+ },
530
+ id: idProperty,
531
+ defaultEffect: defaultEffectProperty,
532
+ statements: flatStatements
533
+ }
534
+ }
535
+ ]
536
+ };
424
537
  }
425
538
 
426
539
  exports.ArrayOperatorSchema = ArrayOperatorSchema;
@@ -436,12 +549,14 @@ exports.PolicyIdSchema = PolicyIdSchema;
436
549
  exports.PolicySchema = PolicySchema;
437
550
  exports.RUBBERDUCK_POLICY_VERSION = RUBBERDUCK_POLICY_VERSION;
438
551
  exports.RangeValueSchema = RangeValueSchema;
552
+ exports.RuleIdSchema = RuleIdSchema;
439
553
  exports.ScalarOperatorSchema = ScalarOperatorSchema;
440
554
  exports.SizeValueSchema = SizeValueSchema;
441
555
  exports.StatementIdSchema = StatementIdSchema;
442
556
  exports.StatementSchema = StatementSchema;
443
557
  exports.UrlOperatorSchema = UrlOperatorSchema;
444
558
  exports.V3_MAX_TIERS = V3_MAX_TIERS;
559
+ exports.V4_MAX_TIERS = V4_MAX_TIERS;
445
560
  exports.VALID_EFFECTS = VALID_EFFECTS;
446
561
  exports.VALID_OPERATOR_LIST = VALID_OPERATOR_LIST;
447
562
  exports.VALID_VERSIONS = VALID_VERSIONS;