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