@zapier/policy-schema 0.4.0 → 0.7.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
@@ -5,10 +5,20 @@ var zod = require('zod');
5
5
  // src/schema.ts
6
6
  var ScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
7
7
  var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).min(1);
8
+ var JsonValueSchema = zod.z.lazy(
9
+ () => zod.z.union([
10
+ zod.z.string(),
11
+ zod.z.number(),
12
+ zod.z.boolean(),
13
+ zod.z.null(),
14
+ zod.z.array(JsonValueSchema),
15
+ zod.z.record(zod.z.string(), JsonValueSchema)
16
+ ])
17
+ );
8
18
  var EqualsConditionSchema = zod.z.object({
9
19
  path: PathSchema,
10
20
  operator: zod.z.literal("equals"),
11
- value: ScalarSchema
21
+ value: JsonValueSchema
12
22
  }).strict();
13
23
  var InConditionSchema = zod.z.object({
14
24
  path: PathSchema,
@@ -114,21 +124,15 @@ var OperatorSchema = zod.z.enum([
114
124
  "keys_in",
115
125
  "size"
116
126
  ]);
117
- var ConditionValueSchema = zod.z.union([
118
- ScalarSchema,
119
- zod.z.array(ScalarSchema),
120
- RangeValueSchema,
121
- SizeValueSchema,
122
- zod.z.array(zod.z.string())
123
- ]);
127
+ var ConditionValueSchema = JsonValueSchema;
124
128
  var StatementSchema = zod.z.object({
125
- effect: zod.z.enum(["allow", "deny"]),
129
+ effect: zod.z.enum(["allow", "ask", "deny"]),
126
130
  permissions: zod.z.array(zod.z.string()).min(1),
127
131
  resources: zod.z.array(zod.z.string()).min(1),
128
132
  conditions: zod.z.array(ConditionSchema).optional()
129
133
  }).strict();
130
134
  var PolicySchema = zod.z.object({
131
- version: zod.z.literal(1),
135
+ version: zod.z.literal(2),
132
136
  statements: zod.z.array(StatementSchema)
133
137
  }).strict();
134
138
 
package/dist/index.d.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
4
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
5
+ [key: string]: JsonValue;
6
+ };
4
7
  type ArrayOperator = "values_in";
5
8
  type UrlOperator = "matches_url";
6
9
  type OtherOperator = "exists" | "keys_in" | "size";
@@ -10,13 +13,13 @@ type RangeValue = {
10
13
  max?: number;
11
14
  };
12
15
  type SizeValue = number | RangeValue;
13
- type ConditionValue = string | number | boolean | (string | number | boolean)[] | RangeValue | SizeValue;
16
+ type ConditionValue = JsonValue | RangeValue | SizeValue;
14
17
  interface Condition {
15
18
  path: (string | number)[];
16
19
  operator: Operator;
17
20
  value?: ConditionValue;
18
21
  }
19
- type Effect = "allow" | "deny";
22
+ type Effect = "allow" | "ask" | "deny";
20
23
  interface Statement {
21
24
  effect: Effect;
22
25
  permissions: string[];
@@ -24,7 +27,7 @@ interface Statement {
24
27
  conditions?: Condition[];
25
28
  }
26
29
  interface Policy {
27
- version: 1;
30
+ version: 2;
28
31
  statements: Statement[];
29
32
  }
30
33
  interface PolicyRequest {
@@ -33,7 +36,7 @@ interface PolicyRequest {
33
36
  context?: Record<string, unknown>;
34
37
  }
35
38
  interface PolicyResult {
36
- allowed: boolean;
39
+ effect: Effect;
37
40
  matchedStatement?: Statement;
38
41
  }
39
42
  interface ParsedUrl {
@@ -62,7 +65,7 @@ declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
62
65
  declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
63
66
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
64
67
  operator: z.ZodLiteral<"equals">;
65
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
68
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
66
69
  }, z.core.$strict>, z.ZodObject<{
67
70
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
68
71
  operator: z.ZodLiteral<"in">;
@@ -141,16 +144,11 @@ declare const OperatorSchema: z.ZodEnum<{
141
144
  values_in: "values_in";
142
145
  matches_url: "matches_url";
143
146
  }>;
144
- declare const ConditionValueSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>, z.ZodObject<{
145
- min: z.ZodOptional<z.ZodNumber>;
146
- max: z.ZodOptional<z.ZodNumber>;
147
- }, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
148
- min: z.ZodOptional<z.ZodNumber>;
149
- max: z.ZodOptional<z.ZodNumber>;
150
- }, z.core.$strict>]>, z.ZodArray<z.ZodString>]>;
147
+ declare const ConditionValueSchema: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
151
148
  declare const StatementSchema: z.ZodObject<{
152
149
  effect: z.ZodEnum<{
153
150
  allow: "allow";
151
+ ask: "ask";
154
152
  deny: "deny";
155
153
  }>;
156
154
  permissions: z.ZodArray<z.ZodString>;
@@ -158,7 +156,7 @@ declare const StatementSchema: z.ZodObject<{
158
156
  conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
159
157
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
160
158
  operator: z.ZodLiteral<"equals">;
161
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
159
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
162
160
  }, z.core.$strict>, z.ZodObject<{
163
161
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
164
162
  operator: z.ZodLiteral<"in">;
@@ -207,10 +205,11 @@ declare const StatementSchema: z.ZodObject<{
207
205
  }, z.core.$strict>]>>>;
208
206
  }, z.core.$strict>;
209
207
  declare const PolicySchema: z.ZodObject<{
210
- version: z.ZodLiteral<1>;
208
+ version: z.ZodLiteral<2>;
211
209
  statements: z.ZodArray<z.ZodObject<{
212
210
  effect: z.ZodEnum<{
213
211
  allow: "allow";
212
+ ask: "ask";
214
213
  deny: "deny";
215
214
  }>;
216
215
  permissions: z.ZodArray<z.ZodString>;
@@ -218,7 +217,7 @@ declare const PolicySchema: z.ZodObject<{
218
217
  conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
219
218
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
220
219
  operator: z.ZodLiteral<"equals">;
221
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
220
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
222
221
  }, z.core.$strict>, z.ZodObject<{
223
222
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
224
223
  operator: z.ZodLiteral<"in">;
@@ -268,4 +267,4 @@ declare const PolicySchema: z.ZodObject<{
268
267
  }, z.core.$strict>>;
269
268
  }, z.core.$strict>;
270
269
 
271
- export { type ArrayOperator, ArrayOperatorSchema, type Condition, ConditionSchema, type ConditionValue, ConditionValueSchema, type Effect, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type ParsedUrl, type Policy, type PolicyHttpRequest, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type UrlOperator, UrlOperatorSchema };
270
+ export { type ArrayOperator, ArrayOperatorSchema, type Condition, ConditionSchema, type ConditionValue, ConditionValueSchema, type Effect, type JsonValue, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type ParsedUrl, type Policy, type PolicyHttpRequest, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type UrlOperator, UrlOperatorSchema };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
4
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
5
+ [key: string]: JsonValue;
6
+ };
4
7
  type ArrayOperator = "values_in";
5
8
  type UrlOperator = "matches_url";
6
9
  type OtherOperator = "exists" | "keys_in" | "size";
@@ -10,13 +13,13 @@ type RangeValue = {
10
13
  max?: number;
11
14
  };
12
15
  type SizeValue = number | RangeValue;
13
- type ConditionValue = string | number | boolean | (string | number | boolean)[] | RangeValue | SizeValue;
16
+ type ConditionValue = JsonValue | RangeValue | SizeValue;
14
17
  interface Condition {
15
18
  path: (string | number)[];
16
19
  operator: Operator;
17
20
  value?: ConditionValue;
18
21
  }
19
- type Effect = "allow" | "deny";
22
+ type Effect = "allow" | "ask" | "deny";
20
23
  interface Statement {
21
24
  effect: Effect;
22
25
  permissions: string[];
@@ -24,7 +27,7 @@ interface Statement {
24
27
  conditions?: Condition[];
25
28
  }
26
29
  interface Policy {
27
- version: 1;
30
+ version: 2;
28
31
  statements: Statement[];
29
32
  }
30
33
  interface PolicyRequest {
@@ -33,7 +36,7 @@ interface PolicyRequest {
33
36
  context?: Record<string, unknown>;
34
37
  }
35
38
  interface PolicyResult {
36
- allowed: boolean;
39
+ effect: Effect;
37
40
  matchedStatement?: Statement;
38
41
  }
39
42
  interface ParsedUrl {
@@ -62,7 +65,7 @@ declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
62
65
  declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
63
66
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
64
67
  operator: z.ZodLiteral<"equals">;
65
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
68
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
66
69
  }, z.core.$strict>, z.ZodObject<{
67
70
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
68
71
  operator: z.ZodLiteral<"in">;
@@ -141,16 +144,11 @@ declare const OperatorSchema: z.ZodEnum<{
141
144
  values_in: "values_in";
142
145
  matches_url: "matches_url";
143
146
  }>;
144
- declare const ConditionValueSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>, z.ZodObject<{
145
- min: z.ZodOptional<z.ZodNumber>;
146
- max: z.ZodOptional<z.ZodNumber>;
147
- }, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
148
- min: z.ZodOptional<z.ZodNumber>;
149
- max: z.ZodOptional<z.ZodNumber>;
150
- }, z.core.$strict>]>, z.ZodArray<z.ZodString>]>;
147
+ declare const ConditionValueSchema: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
151
148
  declare const StatementSchema: z.ZodObject<{
152
149
  effect: z.ZodEnum<{
153
150
  allow: "allow";
151
+ ask: "ask";
154
152
  deny: "deny";
155
153
  }>;
156
154
  permissions: z.ZodArray<z.ZodString>;
@@ -158,7 +156,7 @@ declare const StatementSchema: z.ZodObject<{
158
156
  conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
159
157
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
160
158
  operator: z.ZodLiteral<"equals">;
161
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
159
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
162
160
  }, z.core.$strict>, z.ZodObject<{
163
161
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
164
162
  operator: z.ZodLiteral<"in">;
@@ -207,10 +205,11 @@ declare const StatementSchema: z.ZodObject<{
207
205
  }, z.core.$strict>]>>>;
208
206
  }, z.core.$strict>;
209
207
  declare const PolicySchema: z.ZodObject<{
210
- version: z.ZodLiteral<1>;
208
+ version: z.ZodLiteral<2>;
211
209
  statements: z.ZodArray<z.ZodObject<{
212
210
  effect: z.ZodEnum<{
213
211
  allow: "allow";
212
+ ask: "ask";
214
213
  deny: "deny";
215
214
  }>;
216
215
  permissions: z.ZodArray<z.ZodString>;
@@ -218,7 +217,7 @@ declare const PolicySchema: z.ZodObject<{
218
217
  conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
219
218
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
220
219
  operator: z.ZodLiteral<"equals">;
221
- value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
220
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
222
221
  }, z.core.$strict>, z.ZodObject<{
223
222
  path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
224
223
  operator: z.ZodLiteral<"in">;
@@ -268,4 +267,4 @@ declare const PolicySchema: z.ZodObject<{
268
267
  }, z.core.$strict>>;
269
268
  }, z.core.$strict>;
270
269
 
271
- export { type ArrayOperator, ArrayOperatorSchema, type Condition, ConditionSchema, type ConditionValue, ConditionValueSchema, type Effect, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type ParsedUrl, type Policy, type PolicyHttpRequest, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type UrlOperator, UrlOperatorSchema };
270
+ export { type ArrayOperator, ArrayOperatorSchema, type Condition, ConditionSchema, type ConditionValue, ConditionValueSchema, type Effect, type JsonValue, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type ParsedUrl, type Policy, type PolicyHttpRequest, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type UrlOperator, UrlOperatorSchema };
package/dist/index.mjs CHANGED
@@ -3,10 +3,20 @@ import { z } from 'zod';
3
3
  // src/schema.ts
4
4
  var ScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
5
5
  var PathSchema = z.array(z.union([z.string(), z.number()])).min(1);
6
+ var JsonValueSchema = z.lazy(
7
+ () => z.union([
8
+ z.string(),
9
+ z.number(),
10
+ z.boolean(),
11
+ z.null(),
12
+ z.array(JsonValueSchema),
13
+ z.record(z.string(), JsonValueSchema)
14
+ ])
15
+ );
6
16
  var EqualsConditionSchema = z.object({
7
17
  path: PathSchema,
8
18
  operator: z.literal("equals"),
9
- value: ScalarSchema
19
+ value: JsonValueSchema
10
20
  }).strict();
11
21
  var InConditionSchema = z.object({
12
22
  path: PathSchema,
@@ -112,21 +122,15 @@ var OperatorSchema = z.enum([
112
122
  "keys_in",
113
123
  "size"
114
124
  ]);
115
- var ConditionValueSchema = z.union([
116
- ScalarSchema,
117
- z.array(ScalarSchema),
118
- RangeValueSchema,
119
- SizeValueSchema,
120
- z.array(z.string())
121
- ]);
125
+ var ConditionValueSchema = JsonValueSchema;
122
126
  var StatementSchema = z.object({
123
- effect: z.enum(["allow", "deny"]),
127
+ effect: z.enum(["allow", "ask", "deny"]),
124
128
  permissions: z.array(z.string()).min(1),
125
129
  resources: z.array(z.string()).min(1),
126
130
  conditions: z.array(ConditionSchema).optional()
127
131
  }).strict();
128
132
  var PolicySchema = z.object({
129
- version: z.literal(1),
133
+ version: z.literal(2),
130
134
  statements: z.array(StatementSchema)
131
135
  }).strict();
132
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/policy-schema",
3
- "version": "0.4.0",
3
+ "version": "0.7.0",
4
4
  "description": "Zod schemas and TypeScript types for the Zapier policy engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -22,6 +22,11 @@
22
22
  "dist",
23
23
  "README.md"
24
24
  ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://gitlab.com/zapier/team-identity-platform/policy.git",
28
+ "directory": "typescript/schema"
29
+ },
25
30
  "publishConfig": {
26
31
  "access": "public"
27
32
  },