@zapier/policy-schema 0.3.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 +134 -0
- package/dist/index.d.cts +254 -0
- package/dist/index.d.ts +254 -0
- package/dist/index.mjs +123 -0
- package/package.json +49 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/schema.ts
|
|
6
|
+
var ScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
|
|
7
|
+
var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).min(1);
|
|
8
|
+
var EqualsConditionSchema = zod.z.object({
|
|
9
|
+
path: PathSchema,
|
|
10
|
+
operator: zod.z.literal("equals"),
|
|
11
|
+
value: ScalarSchema
|
|
12
|
+
}).strict();
|
|
13
|
+
var InConditionSchema = zod.z.object({
|
|
14
|
+
path: PathSchema,
|
|
15
|
+
operator: zod.z.literal("in"),
|
|
16
|
+
value: zod.z.array(ScalarSchema).min(1)
|
|
17
|
+
}).strict();
|
|
18
|
+
var MatchesConditionSchema = zod.z.object({
|
|
19
|
+
path: PathSchema,
|
|
20
|
+
operator: zod.z.literal("matches"),
|
|
21
|
+
value: zod.z.string()
|
|
22
|
+
}).strict();
|
|
23
|
+
var MatchesHostConditionSchema = zod.z.object({
|
|
24
|
+
path: PathSchema,
|
|
25
|
+
operator: zod.z.literal("matches_host"),
|
|
26
|
+
value: zod.z.string()
|
|
27
|
+
}).strict();
|
|
28
|
+
var MatchesPathConditionSchema = zod.z.object({
|
|
29
|
+
path: PathSchema,
|
|
30
|
+
operator: zod.z.literal("matches_path"),
|
|
31
|
+
value: zod.z.string()
|
|
32
|
+
}).strict();
|
|
33
|
+
var RangeValueSchema = zod.z.object({
|
|
34
|
+
min: zod.z.number().finite().optional(),
|
|
35
|
+
max: zod.z.number().finite().optional()
|
|
36
|
+
}).strict().refine((v) => v.min !== void 0 || v.max !== void 0, {
|
|
37
|
+
message: "Range must have at least min or max"
|
|
38
|
+
});
|
|
39
|
+
var RangeConditionSchema = zod.z.object({
|
|
40
|
+
path: PathSchema,
|
|
41
|
+
operator: zod.z.literal("range"),
|
|
42
|
+
value: RangeValueSchema
|
|
43
|
+
}).strict();
|
|
44
|
+
var ValuesInConditionSchema = zod.z.object({
|
|
45
|
+
path: PathSchema,
|
|
46
|
+
operator: zod.z.literal("values_in"),
|
|
47
|
+
value: zod.z.array(ScalarSchema).min(1)
|
|
48
|
+
}).strict();
|
|
49
|
+
var ExistsConditionSchema = zod.z.object({
|
|
50
|
+
path: PathSchema,
|
|
51
|
+
operator: zod.z.literal("exists")
|
|
52
|
+
}).strict();
|
|
53
|
+
var KeysInConditionSchema = zod.z.object({
|
|
54
|
+
path: PathSchema,
|
|
55
|
+
operator: zod.z.literal("keys_in"),
|
|
56
|
+
value: zod.z.array(zod.z.string())
|
|
57
|
+
}).strict();
|
|
58
|
+
var SizeValueSchema = zod.z.union([
|
|
59
|
+
zod.z.number().int().nonnegative(),
|
|
60
|
+
RangeValueSchema
|
|
61
|
+
]);
|
|
62
|
+
var SizeConditionSchema = zod.z.object({
|
|
63
|
+
path: PathSchema,
|
|
64
|
+
operator: zod.z.literal("size"),
|
|
65
|
+
value: SizeValueSchema
|
|
66
|
+
}).strict();
|
|
67
|
+
var ConditionSchema = zod.z.union([
|
|
68
|
+
// Scalar operators
|
|
69
|
+
EqualsConditionSchema,
|
|
70
|
+
InConditionSchema,
|
|
71
|
+
MatchesConditionSchema,
|
|
72
|
+
MatchesHostConditionSchema,
|
|
73
|
+
MatchesPathConditionSchema,
|
|
74
|
+
RangeConditionSchema,
|
|
75
|
+
// Array operators
|
|
76
|
+
ValuesInConditionSchema,
|
|
77
|
+
// Other operators
|
|
78
|
+
ExistsConditionSchema,
|
|
79
|
+
KeysInConditionSchema,
|
|
80
|
+
SizeConditionSchema
|
|
81
|
+
]);
|
|
82
|
+
var ScalarOperatorSchema = zod.z.enum([
|
|
83
|
+
"equals",
|
|
84
|
+
"in",
|
|
85
|
+
"matches",
|
|
86
|
+
"matches_host",
|
|
87
|
+
"matches_path",
|
|
88
|
+
"range"
|
|
89
|
+
]);
|
|
90
|
+
var ArrayOperatorSchema = zod.z.enum(["values_in"]);
|
|
91
|
+
var OtherOperatorSchema = zod.z.enum(["exists", "keys_in", "size"]);
|
|
92
|
+
var OperatorSchema = zod.z.enum([
|
|
93
|
+
// Scalar
|
|
94
|
+
"equals",
|
|
95
|
+
"in",
|
|
96
|
+
"matches",
|
|
97
|
+
"matches_host",
|
|
98
|
+
"matches_path",
|
|
99
|
+
"range",
|
|
100
|
+
// Array
|
|
101
|
+
"values_in",
|
|
102
|
+
// Other
|
|
103
|
+
"exists",
|
|
104
|
+
"keys_in",
|
|
105
|
+
"size"
|
|
106
|
+
]);
|
|
107
|
+
var ConditionValueSchema = zod.z.union([
|
|
108
|
+
ScalarSchema,
|
|
109
|
+
zod.z.array(ScalarSchema),
|
|
110
|
+
RangeValueSchema,
|
|
111
|
+
SizeValueSchema,
|
|
112
|
+
zod.z.array(zod.z.string())
|
|
113
|
+
]);
|
|
114
|
+
var StatementSchema = zod.z.object({
|
|
115
|
+
effect: zod.z.enum(["allow", "deny"]),
|
|
116
|
+
permissions: zod.z.array(zod.z.string()).min(1),
|
|
117
|
+
resources: zod.z.array(zod.z.string()).min(1),
|
|
118
|
+
conditions: zod.z.array(ConditionSchema).optional()
|
|
119
|
+
}).strict();
|
|
120
|
+
var PolicySchema = zod.z.object({
|
|
121
|
+
version: zod.z.literal(1),
|
|
122
|
+
statements: zod.z.array(StatementSchema)
|
|
123
|
+
}).strict();
|
|
124
|
+
|
|
125
|
+
exports.ArrayOperatorSchema = ArrayOperatorSchema;
|
|
126
|
+
exports.ConditionSchema = ConditionSchema;
|
|
127
|
+
exports.ConditionValueSchema = ConditionValueSchema;
|
|
128
|
+
exports.OperatorSchema = OperatorSchema;
|
|
129
|
+
exports.OtherOperatorSchema = OtherOperatorSchema;
|
|
130
|
+
exports.PolicySchema = PolicySchema;
|
|
131
|
+
exports.RangeValueSchema = RangeValueSchema;
|
|
132
|
+
exports.ScalarOperatorSchema = ScalarOperatorSchema;
|
|
133
|
+
exports.SizeValueSchema = SizeValueSchema;
|
|
134
|
+
exports.StatementSchema = StatementSchema;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
|
|
4
|
+
type ArrayOperator = "values_in";
|
|
5
|
+
type OtherOperator = "exists" | "keys_in" | "size";
|
|
6
|
+
type Operator = ScalarOperator | ArrayOperator | OtherOperator;
|
|
7
|
+
type RangeValue = {
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
type SizeValue = number | RangeValue;
|
|
12
|
+
type ConditionValue = string | number | boolean | (string | number | boolean)[] | RangeValue | SizeValue;
|
|
13
|
+
interface Condition {
|
|
14
|
+
path: (string | number)[];
|
|
15
|
+
operator: Operator;
|
|
16
|
+
value?: ConditionValue;
|
|
17
|
+
}
|
|
18
|
+
type Effect = "allow" | "deny";
|
|
19
|
+
interface Statement {
|
|
20
|
+
effect: Effect;
|
|
21
|
+
permissions: string[];
|
|
22
|
+
resources: string[];
|
|
23
|
+
conditions?: Condition[];
|
|
24
|
+
}
|
|
25
|
+
interface Policy {
|
|
26
|
+
version: 1;
|
|
27
|
+
statements: Statement[];
|
|
28
|
+
}
|
|
29
|
+
interface PolicyRequest {
|
|
30
|
+
permission: string;
|
|
31
|
+
resource: string;
|
|
32
|
+
context?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface PolicyResult {
|
|
35
|
+
allowed: boolean;
|
|
36
|
+
matchedStatement?: Statement;
|
|
37
|
+
}
|
|
38
|
+
interface ParsedUrl {
|
|
39
|
+
scheme: string;
|
|
40
|
+
host: string;
|
|
41
|
+
port: number;
|
|
42
|
+
path: string;
|
|
43
|
+
query: Record<string, string[]>;
|
|
44
|
+
}
|
|
45
|
+
interface PolicyHttpRequest {
|
|
46
|
+
method: string;
|
|
47
|
+
url: ParsedUrl;
|
|
48
|
+
headers: Record<string, string | string[]>;
|
|
49
|
+
body: string | null;
|
|
50
|
+
body_json: unknown;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const RangeValueSchema: z.ZodObject<{
|
|
54
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
58
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
}, z.core.$strict>]>;
|
|
61
|
+
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
62
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
63
|
+
operator: z.ZodLiteral<"equals">;
|
|
64
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
65
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
66
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
67
|
+
operator: z.ZodLiteral<"in">;
|
|
68
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
71
|
+
operator: z.ZodLiteral<"matches">;
|
|
72
|
+
value: z.ZodString;
|
|
73
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
74
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
75
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
76
|
+
value: z.ZodString;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
79
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
80
|
+
value: z.ZodString;
|
|
81
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
82
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
83
|
+
operator: z.ZodLiteral<"range">;
|
|
84
|
+
value: z.ZodObject<{
|
|
85
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
89
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
90
|
+
operator: z.ZodLiteral<"values_in">;
|
|
91
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
92
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
93
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
94
|
+
operator: z.ZodLiteral<"exists">;
|
|
95
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
96
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
97
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
98
|
+
value: z.ZodArray<z.ZodString>;
|
|
99
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
100
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
101
|
+
operator: z.ZodLiteral<"size">;
|
|
102
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
103
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
104
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
}, z.core.$strict>]>;
|
|
106
|
+
}, z.core.$strict>]>;
|
|
107
|
+
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
108
|
+
equals: "equals";
|
|
109
|
+
in: "in";
|
|
110
|
+
matches: "matches";
|
|
111
|
+
matches_host: "matches_host";
|
|
112
|
+
matches_path: "matches_path";
|
|
113
|
+
range: "range";
|
|
114
|
+
}>;
|
|
115
|
+
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
116
|
+
values_in: "values_in";
|
|
117
|
+
}>;
|
|
118
|
+
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
119
|
+
exists: "exists";
|
|
120
|
+
keys_in: "keys_in";
|
|
121
|
+
size: "size";
|
|
122
|
+
}>;
|
|
123
|
+
declare const OperatorSchema: z.ZodEnum<{
|
|
124
|
+
equals: "equals";
|
|
125
|
+
in: "in";
|
|
126
|
+
matches: "matches";
|
|
127
|
+
matches_host: "matches_host";
|
|
128
|
+
matches_path: "matches_path";
|
|
129
|
+
range: "range";
|
|
130
|
+
exists: "exists";
|
|
131
|
+
keys_in: "keys_in";
|
|
132
|
+
size: "size";
|
|
133
|
+
values_in: "values_in";
|
|
134
|
+
}>;
|
|
135
|
+
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<{
|
|
136
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
139
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
141
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodString>]>;
|
|
142
|
+
declare const StatementSchema: z.ZodObject<{
|
|
143
|
+
effect: z.ZodEnum<{
|
|
144
|
+
allow: "allow";
|
|
145
|
+
deny: "deny";
|
|
146
|
+
}>;
|
|
147
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
148
|
+
resources: z.ZodArray<z.ZodString>;
|
|
149
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
150
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
151
|
+
operator: z.ZodLiteral<"equals">;
|
|
152
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
155
|
+
operator: z.ZodLiteral<"in">;
|
|
156
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
157
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
158
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
159
|
+
operator: z.ZodLiteral<"matches">;
|
|
160
|
+
value: z.ZodString;
|
|
161
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
162
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
163
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
164
|
+
value: z.ZodString;
|
|
165
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
166
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
167
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
168
|
+
value: z.ZodString;
|
|
169
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
170
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
171
|
+
operator: z.ZodLiteral<"range">;
|
|
172
|
+
value: z.ZodObject<{
|
|
173
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
174
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
175
|
+
}, z.core.$strict>;
|
|
176
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
177
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
178
|
+
operator: z.ZodLiteral<"values_in">;
|
|
179
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
180
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
181
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
182
|
+
operator: z.ZodLiteral<"exists">;
|
|
183
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
184
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
185
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
186
|
+
value: z.ZodArray<z.ZodString>;
|
|
187
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
188
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
189
|
+
operator: z.ZodLiteral<"size">;
|
|
190
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
191
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
192
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
193
|
+
}, z.core.$strict>]>;
|
|
194
|
+
}, z.core.$strict>]>>>;
|
|
195
|
+
}, z.core.$strict>;
|
|
196
|
+
declare const PolicySchema: z.ZodObject<{
|
|
197
|
+
version: z.ZodLiteral<1>;
|
|
198
|
+
statements: z.ZodArray<z.ZodObject<{
|
|
199
|
+
effect: z.ZodEnum<{
|
|
200
|
+
allow: "allow";
|
|
201
|
+
deny: "deny";
|
|
202
|
+
}>;
|
|
203
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
204
|
+
resources: z.ZodArray<z.ZodString>;
|
|
205
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
206
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
207
|
+
operator: z.ZodLiteral<"equals">;
|
|
208
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
209
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
210
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
211
|
+
operator: z.ZodLiteral<"in">;
|
|
212
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
213
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
214
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
215
|
+
operator: z.ZodLiteral<"matches">;
|
|
216
|
+
value: z.ZodString;
|
|
217
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
218
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
219
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
220
|
+
value: z.ZodString;
|
|
221
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
222
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
223
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
224
|
+
value: z.ZodString;
|
|
225
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
226
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
227
|
+
operator: z.ZodLiteral<"range">;
|
|
228
|
+
value: z.ZodObject<{
|
|
229
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
230
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
}, z.core.$strict>;
|
|
232
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
233
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
234
|
+
operator: z.ZodLiteral<"values_in">;
|
|
235
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
236
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
237
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
238
|
+
operator: z.ZodLiteral<"exists">;
|
|
239
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
240
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
241
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
242
|
+
value: z.ZodArray<z.ZodString>;
|
|
243
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
244
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
245
|
+
operator: z.ZodLiteral<"size">;
|
|
246
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
247
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
248
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
249
|
+
}, z.core.$strict>]>;
|
|
250
|
+
}, z.core.$strict>]>>>;
|
|
251
|
+
}, z.core.$strict>>;
|
|
252
|
+
}, z.core.$strict>;
|
|
253
|
+
|
|
254
|
+
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
|
|
4
|
+
type ArrayOperator = "values_in";
|
|
5
|
+
type OtherOperator = "exists" | "keys_in" | "size";
|
|
6
|
+
type Operator = ScalarOperator | ArrayOperator | OtherOperator;
|
|
7
|
+
type RangeValue = {
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
type SizeValue = number | RangeValue;
|
|
12
|
+
type ConditionValue = string | number | boolean | (string | number | boolean)[] | RangeValue | SizeValue;
|
|
13
|
+
interface Condition {
|
|
14
|
+
path: (string | number)[];
|
|
15
|
+
operator: Operator;
|
|
16
|
+
value?: ConditionValue;
|
|
17
|
+
}
|
|
18
|
+
type Effect = "allow" | "deny";
|
|
19
|
+
interface Statement {
|
|
20
|
+
effect: Effect;
|
|
21
|
+
permissions: string[];
|
|
22
|
+
resources: string[];
|
|
23
|
+
conditions?: Condition[];
|
|
24
|
+
}
|
|
25
|
+
interface Policy {
|
|
26
|
+
version: 1;
|
|
27
|
+
statements: Statement[];
|
|
28
|
+
}
|
|
29
|
+
interface PolicyRequest {
|
|
30
|
+
permission: string;
|
|
31
|
+
resource: string;
|
|
32
|
+
context?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface PolicyResult {
|
|
35
|
+
allowed: boolean;
|
|
36
|
+
matchedStatement?: Statement;
|
|
37
|
+
}
|
|
38
|
+
interface ParsedUrl {
|
|
39
|
+
scheme: string;
|
|
40
|
+
host: string;
|
|
41
|
+
port: number;
|
|
42
|
+
path: string;
|
|
43
|
+
query: Record<string, string[]>;
|
|
44
|
+
}
|
|
45
|
+
interface PolicyHttpRequest {
|
|
46
|
+
method: string;
|
|
47
|
+
url: ParsedUrl;
|
|
48
|
+
headers: Record<string, string | string[]>;
|
|
49
|
+
body: string | null;
|
|
50
|
+
body_json: unknown;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const RangeValueSchema: z.ZodObject<{
|
|
54
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
58
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
}, z.core.$strict>]>;
|
|
61
|
+
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
62
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
63
|
+
operator: z.ZodLiteral<"equals">;
|
|
64
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
65
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
66
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
67
|
+
operator: z.ZodLiteral<"in">;
|
|
68
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
71
|
+
operator: z.ZodLiteral<"matches">;
|
|
72
|
+
value: z.ZodString;
|
|
73
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
74
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
75
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
76
|
+
value: z.ZodString;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
79
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
80
|
+
value: z.ZodString;
|
|
81
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
82
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
83
|
+
operator: z.ZodLiteral<"range">;
|
|
84
|
+
value: z.ZodObject<{
|
|
85
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
89
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
90
|
+
operator: z.ZodLiteral<"values_in">;
|
|
91
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
92
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
93
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
94
|
+
operator: z.ZodLiteral<"exists">;
|
|
95
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
96
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
97
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
98
|
+
value: z.ZodArray<z.ZodString>;
|
|
99
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
100
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
101
|
+
operator: z.ZodLiteral<"size">;
|
|
102
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
103
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
104
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
}, z.core.$strict>]>;
|
|
106
|
+
}, z.core.$strict>]>;
|
|
107
|
+
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
108
|
+
equals: "equals";
|
|
109
|
+
in: "in";
|
|
110
|
+
matches: "matches";
|
|
111
|
+
matches_host: "matches_host";
|
|
112
|
+
matches_path: "matches_path";
|
|
113
|
+
range: "range";
|
|
114
|
+
}>;
|
|
115
|
+
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
116
|
+
values_in: "values_in";
|
|
117
|
+
}>;
|
|
118
|
+
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
119
|
+
exists: "exists";
|
|
120
|
+
keys_in: "keys_in";
|
|
121
|
+
size: "size";
|
|
122
|
+
}>;
|
|
123
|
+
declare const OperatorSchema: z.ZodEnum<{
|
|
124
|
+
equals: "equals";
|
|
125
|
+
in: "in";
|
|
126
|
+
matches: "matches";
|
|
127
|
+
matches_host: "matches_host";
|
|
128
|
+
matches_path: "matches_path";
|
|
129
|
+
range: "range";
|
|
130
|
+
exists: "exists";
|
|
131
|
+
keys_in: "keys_in";
|
|
132
|
+
size: "size";
|
|
133
|
+
values_in: "values_in";
|
|
134
|
+
}>;
|
|
135
|
+
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<{
|
|
136
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
139
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
141
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodString>]>;
|
|
142
|
+
declare const StatementSchema: z.ZodObject<{
|
|
143
|
+
effect: z.ZodEnum<{
|
|
144
|
+
allow: "allow";
|
|
145
|
+
deny: "deny";
|
|
146
|
+
}>;
|
|
147
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
148
|
+
resources: z.ZodArray<z.ZodString>;
|
|
149
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
150
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
151
|
+
operator: z.ZodLiteral<"equals">;
|
|
152
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
155
|
+
operator: z.ZodLiteral<"in">;
|
|
156
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
157
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
158
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
159
|
+
operator: z.ZodLiteral<"matches">;
|
|
160
|
+
value: z.ZodString;
|
|
161
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
162
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
163
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
164
|
+
value: z.ZodString;
|
|
165
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
166
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
167
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
168
|
+
value: z.ZodString;
|
|
169
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
170
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
171
|
+
operator: z.ZodLiteral<"range">;
|
|
172
|
+
value: z.ZodObject<{
|
|
173
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
174
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
175
|
+
}, z.core.$strict>;
|
|
176
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
177
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
178
|
+
operator: z.ZodLiteral<"values_in">;
|
|
179
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
180
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
181
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
182
|
+
operator: z.ZodLiteral<"exists">;
|
|
183
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
184
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
185
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
186
|
+
value: z.ZodArray<z.ZodString>;
|
|
187
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
188
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
189
|
+
operator: z.ZodLiteral<"size">;
|
|
190
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
191
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
192
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
193
|
+
}, z.core.$strict>]>;
|
|
194
|
+
}, z.core.$strict>]>>>;
|
|
195
|
+
}, z.core.$strict>;
|
|
196
|
+
declare const PolicySchema: z.ZodObject<{
|
|
197
|
+
version: z.ZodLiteral<1>;
|
|
198
|
+
statements: z.ZodArray<z.ZodObject<{
|
|
199
|
+
effect: z.ZodEnum<{
|
|
200
|
+
allow: "allow";
|
|
201
|
+
deny: "deny";
|
|
202
|
+
}>;
|
|
203
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
204
|
+
resources: z.ZodArray<z.ZodString>;
|
|
205
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
206
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
207
|
+
operator: z.ZodLiteral<"equals">;
|
|
208
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
209
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
210
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
211
|
+
operator: z.ZodLiteral<"in">;
|
|
212
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
213
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
214
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
215
|
+
operator: z.ZodLiteral<"matches">;
|
|
216
|
+
value: z.ZodString;
|
|
217
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
218
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
219
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
220
|
+
value: z.ZodString;
|
|
221
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
222
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
223
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
224
|
+
value: z.ZodString;
|
|
225
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
226
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
227
|
+
operator: z.ZodLiteral<"range">;
|
|
228
|
+
value: z.ZodObject<{
|
|
229
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
230
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
}, z.core.$strict>;
|
|
232
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
233
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
234
|
+
operator: z.ZodLiteral<"values_in">;
|
|
235
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
236
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
237
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
238
|
+
operator: z.ZodLiteral<"exists">;
|
|
239
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
240
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
241
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
242
|
+
value: z.ZodArray<z.ZodString>;
|
|
243
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
244
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
245
|
+
operator: z.ZodLiteral<"size">;
|
|
246
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
247
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
248
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
249
|
+
}, z.core.$strict>]>;
|
|
250
|
+
}, z.core.$strict>]>>>;
|
|
251
|
+
}, z.core.$strict>>;
|
|
252
|
+
}, z.core.$strict>;
|
|
253
|
+
|
|
254
|
+
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 };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/schema.ts
|
|
4
|
+
var ScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
5
|
+
var PathSchema = z.array(z.union([z.string(), z.number()])).min(1);
|
|
6
|
+
var EqualsConditionSchema = z.object({
|
|
7
|
+
path: PathSchema,
|
|
8
|
+
operator: z.literal("equals"),
|
|
9
|
+
value: ScalarSchema
|
|
10
|
+
}).strict();
|
|
11
|
+
var InConditionSchema = z.object({
|
|
12
|
+
path: PathSchema,
|
|
13
|
+
operator: z.literal("in"),
|
|
14
|
+
value: z.array(ScalarSchema).min(1)
|
|
15
|
+
}).strict();
|
|
16
|
+
var MatchesConditionSchema = z.object({
|
|
17
|
+
path: PathSchema,
|
|
18
|
+
operator: z.literal("matches"),
|
|
19
|
+
value: z.string()
|
|
20
|
+
}).strict();
|
|
21
|
+
var MatchesHostConditionSchema = z.object({
|
|
22
|
+
path: PathSchema,
|
|
23
|
+
operator: z.literal("matches_host"),
|
|
24
|
+
value: z.string()
|
|
25
|
+
}).strict();
|
|
26
|
+
var MatchesPathConditionSchema = z.object({
|
|
27
|
+
path: PathSchema,
|
|
28
|
+
operator: z.literal("matches_path"),
|
|
29
|
+
value: z.string()
|
|
30
|
+
}).strict();
|
|
31
|
+
var RangeValueSchema = z.object({
|
|
32
|
+
min: z.number().finite().optional(),
|
|
33
|
+
max: z.number().finite().optional()
|
|
34
|
+
}).strict().refine((v) => v.min !== void 0 || v.max !== void 0, {
|
|
35
|
+
message: "Range must have at least min or max"
|
|
36
|
+
});
|
|
37
|
+
var RangeConditionSchema = z.object({
|
|
38
|
+
path: PathSchema,
|
|
39
|
+
operator: z.literal("range"),
|
|
40
|
+
value: RangeValueSchema
|
|
41
|
+
}).strict();
|
|
42
|
+
var ValuesInConditionSchema = z.object({
|
|
43
|
+
path: PathSchema,
|
|
44
|
+
operator: z.literal("values_in"),
|
|
45
|
+
value: z.array(ScalarSchema).min(1)
|
|
46
|
+
}).strict();
|
|
47
|
+
var ExistsConditionSchema = z.object({
|
|
48
|
+
path: PathSchema,
|
|
49
|
+
operator: z.literal("exists")
|
|
50
|
+
}).strict();
|
|
51
|
+
var KeysInConditionSchema = z.object({
|
|
52
|
+
path: PathSchema,
|
|
53
|
+
operator: z.literal("keys_in"),
|
|
54
|
+
value: z.array(z.string())
|
|
55
|
+
}).strict();
|
|
56
|
+
var SizeValueSchema = z.union([
|
|
57
|
+
z.number().int().nonnegative(),
|
|
58
|
+
RangeValueSchema
|
|
59
|
+
]);
|
|
60
|
+
var SizeConditionSchema = z.object({
|
|
61
|
+
path: PathSchema,
|
|
62
|
+
operator: z.literal("size"),
|
|
63
|
+
value: SizeValueSchema
|
|
64
|
+
}).strict();
|
|
65
|
+
var ConditionSchema = z.union([
|
|
66
|
+
// Scalar operators
|
|
67
|
+
EqualsConditionSchema,
|
|
68
|
+
InConditionSchema,
|
|
69
|
+
MatchesConditionSchema,
|
|
70
|
+
MatchesHostConditionSchema,
|
|
71
|
+
MatchesPathConditionSchema,
|
|
72
|
+
RangeConditionSchema,
|
|
73
|
+
// Array operators
|
|
74
|
+
ValuesInConditionSchema,
|
|
75
|
+
// Other operators
|
|
76
|
+
ExistsConditionSchema,
|
|
77
|
+
KeysInConditionSchema,
|
|
78
|
+
SizeConditionSchema
|
|
79
|
+
]);
|
|
80
|
+
var ScalarOperatorSchema = z.enum([
|
|
81
|
+
"equals",
|
|
82
|
+
"in",
|
|
83
|
+
"matches",
|
|
84
|
+
"matches_host",
|
|
85
|
+
"matches_path",
|
|
86
|
+
"range"
|
|
87
|
+
]);
|
|
88
|
+
var ArrayOperatorSchema = z.enum(["values_in"]);
|
|
89
|
+
var OtherOperatorSchema = z.enum(["exists", "keys_in", "size"]);
|
|
90
|
+
var OperatorSchema = z.enum([
|
|
91
|
+
// Scalar
|
|
92
|
+
"equals",
|
|
93
|
+
"in",
|
|
94
|
+
"matches",
|
|
95
|
+
"matches_host",
|
|
96
|
+
"matches_path",
|
|
97
|
+
"range",
|
|
98
|
+
// Array
|
|
99
|
+
"values_in",
|
|
100
|
+
// Other
|
|
101
|
+
"exists",
|
|
102
|
+
"keys_in",
|
|
103
|
+
"size"
|
|
104
|
+
]);
|
|
105
|
+
var ConditionValueSchema = z.union([
|
|
106
|
+
ScalarSchema,
|
|
107
|
+
z.array(ScalarSchema),
|
|
108
|
+
RangeValueSchema,
|
|
109
|
+
SizeValueSchema,
|
|
110
|
+
z.array(z.string())
|
|
111
|
+
]);
|
|
112
|
+
var StatementSchema = z.object({
|
|
113
|
+
effect: z.enum(["allow", "deny"]),
|
|
114
|
+
permissions: z.array(z.string()).min(1),
|
|
115
|
+
resources: z.array(z.string()).min(1),
|
|
116
|
+
conditions: z.array(ConditionSchema).optional()
|
|
117
|
+
}).strict();
|
|
118
|
+
var PolicySchema = z.object({
|
|
119
|
+
version: z.literal(1),
|
|
120
|
+
statements: z.array(StatementSchema)
|
|
121
|
+
}).strict();
|
|
122
|
+
|
|
123
|
+
export { ArrayOperatorSchema, ConditionSchema, ConditionValueSchema, OperatorSchema, OtherOperatorSchema, PolicySchema, RangeValueSchema, ScalarOperatorSchema, SizeValueSchema, StatementSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zapier/policy-schema",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Zod schemas and TypeScript types for the Zapier policy engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"zod": "4.3.6"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^22.0.0",
|
|
33
|
+
"prettier": "^3.5.0",
|
|
34
|
+
"tsx": "^4.0.0",
|
|
35
|
+
"tsup": "^8.0.0",
|
|
36
|
+
"typescript": "^5.7.0",
|
|
37
|
+
"vitest": "^3.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest watch --clearScreen=false",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"lint": "prettier --check .",
|
|
45
|
+
"fmt": "prettier --write .",
|
|
46
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test",
|
|
47
|
+
"dump-schema": "tsx scripts/dump-schema.ts"
|
|
48
|
+
}
|
|
49
|
+
}
|