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