@zapier/policy-schema 0.12.0 → 0.15.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
@@ -3,7 +3,8 @@
3
3
  var zod = require('zod');
4
4
 
5
5
  // src/schema.ts
6
- var VALID_VERSIONS = [1, 2];
6
+ var RUBBERDUCK_POLICY_VERSION = "rc-rubberduck";
7
+ var VALID_VERSIONS = [1, 2, RUBBERDUCK_POLICY_VERSION];
7
8
  var VALID_EFFECTS = ["allow", "ask", "deny"];
8
9
  var VALID_OPERATOR_LIST = [
9
10
  "equals",
@@ -20,10 +21,11 @@ var VALID_OPERATOR_LIST = [
20
21
  ];
21
22
  var ScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
22
23
  var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).min(1);
24
+ var ConditionValueSchema = zod.z.json();
23
25
  var EqualsConditionSchema = zod.z.object({
24
26
  path: PathSchema,
25
27
  operator: zod.z.literal("equals"),
26
- value: zod.z.json()
28
+ value: ConditionValueSchema
27
29
  }).strict();
28
30
  var InConditionSchema = zod.z.object({
29
31
  path: PathSchema,
@@ -129,7 +131,6 @@ var OperatorSchema = zod.z.enum([
129
131
  "keys_in",
130
132
  "size"
131
133
  ]);
132
- var ConditionValueSchema = zod.z.json();
133
134
  var V1StatementSchema = zod.z.object({
134
135
  id: zod.z.string().optional(),
135
136
  effect: zod.z.enum(["allow", "deny"]),
@@ -145,24 +146,116 @@ var V2StatementSchema = zod.z.object({
145
146
  conditions: zod.z.array(ConditionSchema).optional()
146
147
  }).strict();
147
148
  var StatementSchema = V2StatementSchema;
149
+ var StatementIdSchema = zod.z.string().regex(/^s_\S+$/, { error: "Statement id must match ^s_\\S+$" }).max(512);
150
+ var PolicyIdSchema = zod.z.string().regex(/^p_\S+$/, { error: "Policy id must match ^p_\\S+$" }).max(512);
148
151
  var V1PolicySchema = zod.z.object({
149
152
  version: zod.z.literal(1),
150
153
  statements: zod.z.array(V1StatementSchema)
151
154
  }).strict();
155
+ var DefaultEffectSchema = zod.z.enum(["deny", "ask"]);
152
156
  var V2PolicySchema = zod.z.object({
153
157
  version: zod.z.literal(2),
154
158
  statements: zod.z.array(V2StatementSchema)
155
159
  }).strict();
156
- var PolicySchema = zod.z.union([V1PolicySchema, V2PolicySchema]);
160
+ var RcRubberduckStatementSchema = zod.z.object({
161
+ id: StatementIdSchema,
162
+ effect: zod.z.enum(["allow", "ask", "deny"]),
163
+ permissions: zod.z.array(zod.z.string()).min(1),
164
+ resources: zod.z.array(zod.z.string()).min(1),
165
+ conditions: zod.z.array(ConditionSchema).optional()
166
+ }).strict();
167
+ var RcRubberduckPolicySchema = zod.z.object({
168
+ version: zod.z.literal(RUBBERDUCK_POLICY_VERSION),
169
+ id: PolicyIdSchema,
170
+ defaultEffect: DefaultEffectSchema,
171
+ statements: zod.z.array(RcRubberduckStatementSchema)
172
+ }).strict();
173
+ var PolicySchema = zod.z.union([
174
+ V1PolicySchema,
175
+ V2PolicySchema,
176
+ RcRubberduckPolicySchema
177
+ ]);
178
+ var CanonicalHashSchema = zod.z.custom(
179
+ (value) => typeof value === "string" && /^[0-9a-f]{64}$/.test(value),
180
+ { error: "Expected a 64-character lowercase hex SHA-256 digest" }
181
+ );
182
+ var OverrideHashBaseShape = {
183
+ id: zod.z.string().optional(),
184
+ /**
185
+ * The canonical hash of the targeted statement.
186
+ * Used for v1/v2 policies. Must be a valid SHA-256 hex digest (non-null).
187
+ */
188
+ statementHash: CanonicalHashSchema,
189
+ effect: zod.z.literal("allow")
190
+ };
191
+ var OverrideIdBaseShape = {
192
+ id: zod.z.string().optional(),
193
+ /**
194
+ * The statement id of the targeted statement. Used for rc-rubberduck policies.
195
+ * Must be a valid statement id (non-null). To target the policy's default
196
+ * effect, use policyId instead.
197
+ */
198
+ statementId: StatementIdSchema,
199
+ effect: zod.z.literal("allow")
200
+ };
201
+ var OverridePolicyIdBaseShape = {
202
+ id: zod.z.string().optional(),
203
+ /**
204
+ * Targets the policy's default effect. Only applies when this policyId
205
+ * matches the evaluated policy's id. Used for rc-rubberduck policies.
206
+ */
207
+ policyId: PolicyIdSchema,
208
+ effect: zod.z.literal("allow")
209
+ };
210
+ var OverrideSchema = zod.z.union([
211
+ // statementHash × match
212
+ zod.z.object({ ...OverrideHashBaseShape, match: zod.z.literal("any") }).strict(),
213
+ // statementHash × contextHash
214
+ zod.z.object({ ...OverrideHashBaseShape, contextHash: CanonicalHashSchema }).strict(),
215
+ // statementHash × conditionals
216
+ zod.z.object({
217
+ ...OverrideHashBaseShape,
218
+ conditionals: zod.z.array(ConditionSchema)
219
+ }).strict(),
220
+ // statementId × match
221
+ zod.z.object({ ...OverrideIdBaseShape, match: zod.z.literal("any") }).strict(),
222
+ // statementId × contextHash
223
+ zod.z.object({ ...OverrideIdBaseShape, contextHash: CanonicalHashSchema }).strict(),
224
+ // statementId × conditionals
225
+ zod.z.object({
226
+ ...OverrideIdBaseShape,
227
+ conditionals: zod.z.array(ConditionSchema)
228
+ }).strict(),
229
+ // policyId × match
230
+ zod.z.object({ ...OverridePolicyIdBaseShape, match: zod.z.literal("any") }).strict(),
231
+ // policyId × contextHash
232
+ zod.z.object({ ...OverridePolicyIdBaseShape, contextHash: CanonicalHashSchema }).strict(),
233
+ // policyId × conditionals
234
+ zod.z.object({
235
+ ...OverridePolicyIdBaseShape,
236
+ conditionals: zod.z.array(ConditionSchema)
237
+ }).strict()
238
+ ]);
157
239
  function getOpenApiSchema() {
158
240
  return {
159
241
  type: "object",
160
242
  required: ["version", "statements"],
161
243
  properties: {
162
244
  version: {
163
- type: "integer",
164
- enum: [...VALID_VERSIONS],
165
- description: `Policy schema version. Must be one of ${JSON.stringify([...VALID_VERSIONS])}.`
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
+ id: {
252
+ type: "string",
253
+ description: "Policy id (required for rc-rubberduck policies). Must use the p_ prefix and contain no whitespace."
254
+ },
255
+ defaultEffect: {
256
+ type: "string",
257
+ enum: [...DefaultEffectSchema.options],
258
+ description: "Effect applied when no statement matches. Required on rc-rubberduck policies; deny equals implicit deny."
166
259
  },
167
260
  statements: {
168
261
  type: "array",
@@ -173,12 +266,12 @@ function getOpenApiSchema() {
173
266
  properties: {
174
267
  id: {
175
268
  type: "string",
176
- description: "Optional identifier for debugging and provenance. Included in canonical hash."
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."
177
270
  },
178
271
  effect: {
179
272
  type: "string",
180
273
  enum: [...VALID_EFFECTS].sort(),
181
- description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is only valid in version 2 policies."
274
+ description: "Whether to allow, ask, or deny the specified permissions. The 'ask' effect is valid in version 2 and rc-rubberduck policies."
182
275
  },
183
276
  permissions: {
184
277
  type: "array",
@@ -226,14 +319,20 @@ function getOpenApiSchema() {
226
319
  }
227
320
 
228
321
  exports.ArrayOperatorSchema = ArrayOperatorSchema;
322
+ exports.CanonicalHashSchema = CanonicalHashSchema;
229
323
  exports.ConditionSchema = ConditionSchema;
230
324
  exports.ConditionValueSchema = ConditionValueSchema;
325
+ exports.DefaultEffectSchema = DefaultEffectSchema;
231
326
  exports.OperatorSchema = OperatorSchema;
232
327
  exports.OtherOperatorSchema = OtherOperatorSchema;
328
+ exports.OverrideSchema = OverrideSchema;
329
+ exports.PolicyIdSchema = PolicyIdSchema;
233
330
  exports.PolicySchema = PolicySchema;
331
+ exports.RUBBERDUCK_POLICY_VERSION = RUBBERDUCK_POLICY_VERSION;
234
332
  exports.RangeValueSchema = RangeValueSchema;
235
333
  exports.ScalarOperatorSchema = ScalarOperatorSchema;
236
334
  exports.SizeValueSchema = SizeValueSchema;
335
+ exports.StatementIdSchema = StatementIdSchema;
237
336
  exports.StatementSchema = StatementSchema;
238
337
  exports.UrlOperatorSchema = UrlOperatorSchema;
239
338
  exports.VALID_EFFECTS = VALID_EFFECTS;