@zapier/policy-schema 0.11.1 → 0.13.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 +24 -13
- package/dist/index.d.cts +184 -128
- package/dist/index.d.ts +184 -128
- package/dist/index.mjs +23 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,20 +20,10 @@ var VALID_OPERATOR_LIST = [
|
|
|
20
20
|
];
|
|
21
21
|
var ScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
|
|
22
22
|
var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).min(1);
|
|
23
|
-
var JsonValueSchema = zod.z.lazy(
|
|
24
|
-
() => zod.z.union([
|
|
25
|
-
zod.z.string(),
|
|
26
|
-
zod.z.number(),
|
|
27
|
-
zod.z.boolean(),
|
|
28
|
-
zod.z.null(),
|
|
29
|
-
zod.z.array(JsonValueSchema),
|
|
30
|
-
zod.z.record(zod.z.string(), JsonValueSchema)
|
|
31
|
-
])
|
|
32
|
-
);
|
|
33
23
|
var EqualsConditionSchema = zod.z.object({
|
|
34
24
|
path: PathSchema,
|
|
35
25
|
operator: zod.z.literal("equals"),
|
|
36
|
-
value:
|
|
26
|
+
value: zod.z.json()
|
|
37
27
|
}).strict();
|
|
38
28
|
var InConditionSchema = zod.z.object({
|
|
39
29
|
path: PathSchema,
|
|
@@ -139,7 +129,7 @@ var OperatorSchema = zod.z.enum([
|
|
|
139
129
|
"keys_in",
|
|
140
130
|
"size"
|
|
141
131
|
]);
|
|
142
|
-
var ConditionValueSchema =
|
|
132
|
+
var ConditionValueSchema = zod.z.json();
|
|
143
133
|
var V1StatementSchema = zod.z.object({
|
|
144
134
|
id: zod.z.string().optional(),
|
|
145
135
|
effect: zod.z.enum(["allow", "deny"]),
|
|
@@ -164,6 +154,26 @@ var V2PolicySchema = zod.z.object({
|
|
|
164
154
|
statements: zod.z.array(V2StatementSchema)
|
|
165
155
|
}).strict();
|
|
166
156
|
var PolicySchema = zod.z.union([V1PolicySchema, V2PolicySchema]);
|
|
157
|
+
var CanonicalHashSchema = zod.z.custom(
|
|
158
|
+
(value) => typeof value === "string" && /^[0-9a-f]{64}$/.test(value),
|
|
159
|
+
{ error: "Expected a 64-character lowercase hex SHA-256 digest" }
|
|
160
|
+
);
|
|
161
|
+
var OverrideBaseShape = {
|
|
162
|
+
id: zod.z.string().optional(),
|
|
163
|
+
statementHash: CanonicalHashSchema,
|
|
164
|
+
effect: zod.z.literal("allow")
|
|
165
|
+
};
|
|
166
|
+
var OverrideSchema = zod.z.union([
|
|
167
|
+
zod.z.object({ ...OverrideBaseShape, match: zod.z.literal("any") }).strict(),
|
|
168
|
+
zod.z.object({ ...OverrideBaseShape, contextHash: CanonicalHashSchema }).strict(),
|
|
169
|
+
// Empty conditionals is intentional (the "blank check"): the override
|
|
170
|
+
// applies whenever the targeted ask statement fires, with no extra
|
|
171
|
+
// conditions. Do not add .min(1) here.
|
|
172
|
+
zod.z.object({
|
|
173
|
+
...OverrideBaseShape,
|
|
174
|
+
conditionals: zod.z.array(ConditionSchema)
|
|
175
|
+
}).strict()
|
|
176
|
+
]);
|
|
167
177
|
function getOpenApiSchema() {
|
|
168
178
|
return {
|
|
169
179
|
type: "object",
|
|
@@ -236,11 +246,12 @@ function getOpenApiSchema() {
|
|
|
236
246
|
}
|
|
237
247
|
|
|
238
248
|
exports.ArrayOperatorSchema = ArrayOperatorSchema;
|
|
249
|
+
exports.CanonicalHashSchema = CanonicalHashSchema;
|
|
239
250
|
exports.ConditionSchema = ConditionSchema;
|
|
240
251
|
exports.ConditionValueSchema = ConditionValueSchema;
|
|
241
|
-
exports.JsonValueSchema = JsonValueSchema;
|
|
242
252
|
exports.OperatorSchema = OperatorSchema;
|
|
243
253
|
exports.OtherOperatorSchema = OtherOperatorSchema;
|
|
254
|
+
exports.OverrideSchema = OverrideSchema;
|
|
244
255
|
exports.PolicySchema = PolicySchema;
|
|
245
256
|
exports.RangeValueSchema = RangeValueSchema;
|
|
246
257
|
exports.ScalarOperatorSchema = ScalarOperatorSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,142 +1,29 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
|
|
4
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
5
|
-
[key: string]: JsonValue;
|
|
6
|
-
};
|
|
7
|
-
type ArrayOperator = "values_in";
|
|
8
|
-
type UrlOperator = "matches_url";
|
|
9
|
-
type OtherOperator = "exists" | "keys_in" | "size";
|
|
10
|
-
type Operator = ScalarOperator | ArrayOperator | UrlOperator | OtherOperator;
|
|
11
|
-
type RangeValue = {
|
|
12
|
-
min?: number;
|
|
13
|
-
max?: number;
|
|
14
|
-
};
|
|
15
|
-
type SizeValue = number | RangeValue;
|
|
16
|
-
type ConditionValue = JsonValue | RangeValue | SizeValue;
|
|
17
|
-
interface Condition {
|
|
18
|
-
path: (string | number)[];
|
|
19
|
-
operator: Operator;
|
|
20
|
-
value?: ConditionValue;
|
|
21
|
-
}
|
|
22
|
-
type Effect = "allow" | "ask" | "deny";
|
|
23
|
-
interface Statement {
|
|
24
|
-
id?: string;
|
|
25
|
-
effect: Effect;
|
|
26
|
-
permissions: string[];
|
|
27
|
-
resources: string[];
|
|
28
|
-
conditions?: Condition[];
|
|
29
|
-
}
|
|
30
|
-
interface Policy {
|
|
31
|
-
version: 1 | 2;
|
|
32
|
-
statements: Statement[];
|
|
33
|
-
}
|
|
34
|
-
interface PolicyRequest {
|
|
35
|
-
permission: string;
|
|
36
|
-
resource: string;
|
|
37
|
-
context?: Record<string, unknown>;
|
|
38
|
-
}
|
|
39
|
-
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
40
|
-
type CanonicalHash = string & {
|
|
41
|
-
readonly __brand: "CanonicalHash";
|
|
42
|
-
};
|
|
43
|
-
interface OverrideBase {
|
|
44
|
-
id?: string;
|
|
45
|
-
statementHash: CanonicalHash;
|
|
46
|
-
effect: "allow";
|
|
47
|
-
}
|
|
48
|
-
type Override = (OverrideBase & {
|
|
49
|
-
match: "any";
|
|
50
|
-
}) | (OverrideBase & {
|
|
51
|
-
contextHash: CanonicalHash;
|
|
52
|
-
}) | (OverrideBase & {
|
|
53
|
-
conditionals: Condition[];
|
|
54
|
-
});
|
|
55
|
-
interface ConditionTrace {
|
|
56
|
-
condition: Condition;
|
|
57
|
-
resolved: unknown;
|
|
58
|
-
passed: boolean;
|
|
59
|
-
}
|
|
60
|
-
interface OverrideTrace {
|
|
61
|
-
override: Override;
|
|
62
|
-
matched: boolean;
|
|
63
|
-
conditionResults?: ConditionTrace[];
|
|
64
|
-
}
|
|
65
|
-
interface StatementTrace {
|
|
66
|
-
statement: Statement;
|
|
67
|
-
permissionMatched: boolean;
|
|
68
|
-
resourceMatched: boolean;
|
|
69
|
-
conditionResults?: ConditionTrace[];
|
|
70
|
-
passed: boolean;
|
|
71
|
-
overrides?: OverrideTrace[];
|
|
72
|
-
}
|
|
73
|
-
interface EvaluatePolicyOptions {
|
|
74
|
-
policy: Policy;
|
|
75
|
-
request: PolicyRequest;
|
|
76
|
-
overrides?: Override[];
|
|
77
|
-
trace?: boolean;
|
|
78
|
-
}
|
|
79
|
-
type PolicyReason = "matched" | "unmatched" | "hpp" | "overridden";
|
|
80
|
-
interface PolicyResult {
|
|
81
|
-
effect: Effect;
|
|
82
|
-
explicit: boolean;
|
|
83
|
-
reason: PolicyReason;
|
|
84
|
-
statements: StatementTrace[];
|
|
85
|
-
}
|
|
86
|
-
interface ParsedUrl {
|
|
87
|
-
scheme: string;
|
|
88
|
-
host: string;
|
|
89
|
-
port: number;
|
|
90
|
-
path: string;
|
|
91
|
-
query: Record<string, string[]>;
|
|
92
|
-
}
|
|
93
|
-
interface PolicyHttpRequest {
|
|
94
|
-
method: string;
|
|
95
|
-
url: ParsedUrl;
|
|
96
|
-
headers: Record<string, string | string[]>;
|
|
97
|
-
body: string | null;
|
|
98
|
-
body_json: unknown;
|
|
99
|
-
connection_id?: string;
|
|
100
|
-
}
|
|
101
|
-
interface PolicyActionRequest {
|
|
102
|
-
connection_id?: string;
|
|
103
|
-
selected_api?: string;
|
|
104
|
-
action_type?: string;
|
|
105
|
-
action_key?: string;
|
|
106
|
-
inputs?: Record<string, unknown>;
|
|
107
|
-
}
|
|
108
|
-
/** Simplified OpenAPI-compatible JSON Schema type for getOpenApiSchema(). */
|
|
109
|
-
interface OpenApiSchema {
|
|
110
|
-
type?: string;
|
|
111
|
-
required?: string[];
|
|
112
|
-
properties?: Record<string, OpenApiSchema>;
|
|
113
|
-
items?: OpenApiSchema;
|
|
114
|
-
enum?: (string | number)[];
|
|
115
|
-
description?: string;
|
|
116
|
-
minItems?: number;
|
|
117
|
-
oneOf?: OpenApiSchema[];
|
|
118
|
-
anyOf?: OpenApiSchema[];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
3
|
/** Current policy document version. */
|
|
122
4
|
declare const VALID_VERSIONS: readonly [1, 2];
|
|
123
5
|
/** Valid policy effects. */
|
|
124
6
|
declare const VALID_EFFECTS: readonly ["allow", "ask", "deny"];
|
|
7
|
+
/** Derived from VALID_EFFECTS — the constant is the single source of truth. */
|
|
8
|
+
type Effect = (typeof VALID_EFFECTS)[number];
|
|
125
9
|
/** Valid condition operators. */
|
|
126
10
|
declare const VALID_OPERATOR_LIST: readonly ["equals", "exists", "in", "keys_in", "matches", "matches_host", "matches_path", "matches_url", "range", "size", "values_in"];
|
|
127
|
-
declare const JsonValueSchema: z.ZodType<JsonValue>;
|
|
128
11
|
declare const RangeValueSchema: z.ZodObject<{
|
|
129
12
|
min: z.ZodOptional<z.ZodNumber>;
|
|
130
13
|
max: z.ZodOptional<z.ZodNumber>;
|
|
131
14
|
}, z.core.$strict>;
|
|
15
|
+
/** Derived from RangeValueSchema — the schema is the single source of truth. */
|
|
16
|
+
type RangeValue = z.infer<typeof RangeValueSchema>;
|
|
132
17
|
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
133
18
|
min: z.ZodOptional<z.ZodNumber>;
|
|
134
19
|
max: z.ZodOptional<z.ZodNumber>;
|
|
135
20
|
}, z.core.$strict>]>;
|
|
21
|
+
/** Derived from SizeValueSchema — the schema is the single source of truth. */
|
|
22
|
+
type SizeValue = z.infer<typeof SizeValueSchema>;
|
|
136
23
|
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
137
24
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
138
25
|
operator: z.ZodLiteral<"equals">;
|
|
139
|
-
value: z.
|
|
26
|
+
value: z.ZodJSONSchema;
|
|
140
27
|
}, z.core.$strict>, z.ZodObject<{
|
|
141
28
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
142
29
|
operator: z.ZodLiteral<"in">;
|
|
@@ -183,6 +70,8 @@ declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
183
70
|
max: z.ZodOptional<z.ZodNumber>;
|
|
184
71
|
}, z.core.$strict>]>;
|
|
185
72
|
}, z.core.$strict>]>;
|
|
73
|
+
/** Derived from ConditionSchema — the schema is the single source of truth. */
|
|
74
|
+
type Condition = z.infer<typeof ConditionSchema>;
|
|
186
75
|
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
187
76
|
equals: "equals";
|
|
188
77
|
in: "in";
|
|
@@ -191,31 +80,41 @@ declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
|
191
80
|
matches_path: "matches_path";
|
|
192
81
|
range: "range";
|
|
193
82
|
}>;
|
|
83
|
+
/** Derived from ScalarOperatorSchema — the schema is the single source of truth. */
|
|
84
|
+
type ScalarOperator = z.infer<typeof ScalarOperatorSchema>;
|
|
194
85
|
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
195
86
|
values_in: "values_in";
|
|
196
87
|
}>;
|
|
88
|
+
/** Derived from ArrayOperatorSchema — the schema is the single source of truth. */
|
|
89
|
+
type ArrayOperator = z.infer<typeof ArrayOperatorSchema>;
|
|
197
90
|
declare const UrlOperatorSchema: z.ZodEnum<{
|
|
198
91
|
matches_url: "matches_url";
|
|
199
92
|
}>;
|
|
93
|
+
/** Derived from UrlOperatorSchema — the schema is the single source of truth. */
|
|
94
|
+
type UrlOperator = z.infer<typeof UrlOperatorSchema>;
|
|
200
95
|
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
201
96
|
exists: "exists";
|
|
202
97
|
keys_in: "keys_in";
|
|
203
98
|
size: "size";
|
|
204
99
|
}>;
|
|
100
|
+
/** Derived from OtherOperatorSchema — the schema is the single source of truth. */
|
|
101
|
+
type OtherOperator = z.infer<typeof OtherOperatorSchema>;
|
|
205
102
|
declare const OperatorSchema: z.ZodEnum<{
|
|
206
103
|
equals: "equals";
|
|
104
|
+
exists: "exists";
|
|
207
105
|
in: "in";
|
|
106
|
+
keys_in: "keys_in";
|
|
208
107
|
matches: "matches";
|
|
209
108
|
matches_host: "matches_host";
|
|
210
109
|
matches_path: "matches_path";
|
|
110
|
+
matches_url: "matches_url";
|
|
211
111
|
range: "range";
|
|
212
|
-
exists: "exists";
|
|
213
|
-
keys_in: "keys_in";
|
|
214
112
|
size: "size";
|
|
215
113
|
values_in: "values_in";
|
|
216
|
-
matches_url: "matches_url";
|
|
217
114
|
}>;
|
|
218
|
-
|
|
115
|
+
/** Derived from OperatorSchema — the schema is the single source of truth. */
|
|
116
|
+
type Operator = z.infer<typeof OperatorSchema>;
|
|
117
|
+
declare const ConditionValueSchema: z.ZodJSONSchema;
|
|
219
118
|
/** Statement schema accepting the union of all effects (use PolicySchema for version-aware validation). */
|
|
220
119
|
declare const StatementSchema: z.ZodObject<{
|
|
221
120
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -229,7 +128,7 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
229
128
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
230
129
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
231
130
|
operator: z.ZodLiteral<"equals">;
|
|
232
|
-
value: z.
|
|
131
|
+
value: z.ZodJSONSchema;
|
|
233
132
|
}, z.core.$strict>, z.ZodObject<{
|
|
234
133
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
235
134
|
operator: z.ZodLiteral<"in">;
|
|
@@ -277,6 +176,8 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
277
176
|
}, z.core.$strict>]>;
|
|
278
177
|
}, z.core.$strict>]>>>;
|
|
279
178
|
}, z.core.$strict>;
|
|
179
|
+
/** Derived from StatementSchema — the schema is the single source of truth. */
|
|
180
|
+
type Statement = z.infer<typeof StatementSchema>;
|
|
280
181
|
declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
281
182
|
version: z.ZodLiteral<1>;
|
|
282
183
|
statements: z.ZodArray<z.ZodObject<{
|
|
@@ -290,7 +191,7 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
290
191
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
291
192
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
292
193
|
operator: z.ZodLiteral<"equals">;
|
|
293
|
-
value: z.
|
|
194
|
+
value: z.ZodJSONSchema;
|
|
294
195
|
}, z.core.$strict>, z.ZodObject<{
|
|
295
196
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
296
197
|
operator: z.ZodLiteral<"in">;
|
|
@@ -352,7 +253,7 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
352
253
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
353
254
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
354
255
|
operator: z.ZodLiteral<"equals">;
|
|
355
|
-
value: z.
|
|
256
|
+
value: z.ZodJSONSchema;
|
|
356
257
|
}, z.core.$strict>, z.ZodObject<{
|
|
357
258
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
358
259
|
operator: z.ZodLiteral<"in">;
|
|
@@ -401,6 +302,82 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
401
302
|
}, z.core.$strict>]>>>;
|
|
402
303
|
}, z.core.$strict>>;
|
|
403
304
|
}, z.core.$strict>]>;
|
|
305
|
+
/** Derived from PolicySchema — the schema is the single source of truth. */
|
|
306
|
+
type Policy = z.infer<typeof PolicySchema>;
|
|
307
|
+
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
308
|
+
declare const CanonicalHashSchema: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
309
|
+
/**
|
|
310
|
+
* Runtime schema for the Override type. `.strict()` keeps the variants
|
|
311
|
+
* mutually exclusive (an object carrying two variant fields fails all
|
|
312
|
+
* branches).
|
|
313
|
+
*/
|
|
314
|
+
declare const OverrideSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
315
|
+
match: z.ZodLiteral<"any">;
|
|
316
|
+
id: z.ZodOptional<z.ZodString>;
|
|
317
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
318
|
+
effect: z.ZodLiteral<"allow">;
|
|
319
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
320
|
+
contextHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
321
|
+
id: z.ZodOptional<z.ZodString>;
|
|
322
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
323
|
+
effect: z.ZodLiteral<"allow">;
|
|
324
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
325
|
+
conditionals: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
326
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
327
|
+
operator: z.ZodLiteral<"equals">;
|
|
328
|
+
value: z.ZodJSONSchema;
|
|
329
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
330
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
331
|
+
operator: z.ZodLiteral<"in">;
|
|
332
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
333
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
334
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
335
|
+
operator: z.ZodLiteral<"matches">;
|
|
336
|
+
value: z.ZodString;
|
|
337
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
338
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
339
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
340
|
+
value: z.ZodString;
|
|
341
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
342
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
343
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
344
|
+
value: z.ZodString;
|
|
345
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
346
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
347
|
+
operator: z.ZodLiteral<"range">;
|
|
348
|
+
value: z.ZodObject<{
|
|
349
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
350
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
351
|
+
}, z.core.$strict>;
|
|
352
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
353
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
354
|
+
operator: z.ZodLiteral<"matches_url">;
|
|
355
|
+
value: z.ZodString;
|
|
356
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
357
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
358
|
+
operator: z.ZodLiteral<"values_in">;
|
|
359
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
360
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
361
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
362
|
+
operator: z.ZodLiteral<"exists">;
|
|
363
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
364
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
365
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
366
|
+
value: z.ZodArray<z.ZodString>;
|
|
367
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
368
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
369
|
+
operator: z.ZodLiteral<"size">;
|
|
370
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
371
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
372
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
373
|
+
}, z.core.$strict>]>;
|
|
374
|
+
}, z.core.$strict>]>>;
|
|
375
|
+
id: z.ZodOptional<z.ZodString>;
|
|
376
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
377
|
+
effect: z.ZodLiteral<"allow">;
|
|
378
|
+
}, z.core.$strict>]>;
|
|
379
|
+
/** Derived from OverrideSchema — the schema is the single source of truth. */
|
|
380
|
+
type Override = z.infer<typeof OverrideSchema>;
|
|
404
381
|
/**
|
|
405
382
|
* Returns an OpenAPI-compatible JSON Schema object for a policy document.
|
|
406
383
|
*
|
|
@@ -409,4 +386,83 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
409
386
|
*/
|
|
410
387
|
declare function getOpenApiSchema(): OpenApiSchema;
|
|
411
388
|
|
|
412
|
-
|
|
389
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
390
|
+
[key: string]: JsonValue;
|
|
391
|
+
};
|
|
392
|
+
type ConditionValue = JsonValue | RangeValue | SizeValue;
|
|
393
|
+
interface PolicyRequest {
|
|
394
|
+
permission: string;
|
|
395
|
+
resource: string;
|
|
396
|
+
context?: Record<string, unknown>;
|
|
397
|
+
}
|
|
398
|
+
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
399
|
+
type CanonicalHash = string & {
|
|
400
|
+
readonly __brand: "CanonicalHash";
|
|
401
|
+
};
|
|
402
|
+
interface ConditionTrace {
|
|
403
|
+
condition: Condition;
|
|
404
|
+
resolved: unknown;
|
|
405
|
+
passed: boolean;
|
|
406
|
+
}
|
|
407
|
+
interface OverrideTrace {
|
|
408
|
+
override: Override;
|
|
409
|
+
matched: boolean;
|
|
410
|
+
conditionResults?: ConditionTrace[];
|
|
411
|
+
}
|
|
412
|
+
interface StatementTrace {
|
|
413
|
+
statement: Statement;
|
|
414
|
+
permissionMatched: boolean;
|
|
415
|
+
resourceMatched: boolean;
|
|
416
|
+
conditionResults?: ConditionTrace[];
|
|
417
|
+
passed: boolean;
|
|
418
|
+
overrides?: OverrideTrace[];
|
|
419
|
+
}
|
|
420
|
+
interface EvaluatePolicyOptions {
|
|
421
|
+
policy: Policy;
|
|
422
|
+
request: PolicyRequest;
|
|
423
|
+
overrides?: Override[];
|
|
424
|
+
trace?: boolean;
|
|
425
|
+
}
|
|
426
|
+
type PolicyReason = "matched" | "unmatched" | "hpp" | "overridden";
|
|
427
|
+
interface PolicyResult {
|
|
428
|
+
effect: Effect;
|
|
429
|
+
explicit: boolean;
|
|
430
|
+
reason: PolicyReason;
|
|
431
|
+
statements: StatementTrace[];
|
|
432
|
+
}
|
|
433
|
+
interface ParsedUrl {
|
|
434
|
+
scheme: string;
|
|
435
|
+
host: string;
|
|
436
|
+
port: number;
|
|
437
|
+
path: string;
|
|
438
|
+
query: Record<string, string[]>;
|
|
439
|
+
}
|
|
440
|
+
interface PolicyHttpRequest {
|
|
441
|
+
method: string;
|
|
442
|
+
url: ParsedUrl;
|
|
443
|
+
headers: Record<string, string | string[]>;
|
|
444
|
+
body: string | null;
|
|
445
|
+
body_json: unknown;
|
|
446
|
+
connection_id?: string;
|
|
447
|
+
}
|
|
448
|
+
interface PolicyActionRequest {
|
|
449
|
+
connection_id?: string;
|
|
450
|
+
selected_api?: string;
|
|
451
|
+
action_type?: string;
|
|
452
|
+
action_key?: string;
|
|
453
|
+
inputs?: Record<string, unknown>;
|
|
454
|
+
}
|
|
455
|
+
/** Simplified OpenAPI-compatible JSON Schema type for getOpenApiSchema(). */
|
|
456
|
+
interface OpenApiSchema {
|
|
457
|
+
type?: string;
|
|
458
|
+
required?: string[];
|
|
459
|
+
properties?: Record<string, OpenApiSchema>;
|
|
460
|
+
items?: OpenApiSchema;
|
|
461
|
+
enum?: (string | number)[];
|
|
462
|
+
description?: string;
|
|
463
|
+
minItems?: number;
|
|
464
|
+
oneOf?: OpenApiSchema[];
|
|
465
|
+
anyOf?: OpenApiSchema[];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export { type ArrayOperator, ArrayOperatorSchema, type CanonicalHash, CanonicalHashSchema, type Condition, ConditionSchema, type ConditionTrace, type ConditionValue, ConditionValueSchema, type Effect, type EvaluatePolicyOptions, type JsonValue, type OpenApiSchema, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type Override, OverrideSchema, type OverrideTrace, type ParsedUrl, type Policy, type PolicyActionRequest, type PolicyHttpRequest, type PolicyReason, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type StatementTrace, type UrlOperator, UrlOperatorSchema, VALID_EFFECTS, VALID_OPERATOR_LIST, VALID_VERSIONS, getOpenApiSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,142 +1,29 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
type ScalarOperator = "equals" | "in" | "matches" | "matches_host" | "matches_path" | "range";
|
|
4
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
5
|
-
[key: string]: JsonValue;
|
|
6
|
-
};
|
|
7
|
-
type ArrayOperator = "values_in";
|
|
8
|
-
type UrlOperator = "matches_url";
|
|
9
|
-
type OtherOperator = "exists" | "keys_in" | "size";
|
|
10
|
-
type Operator = ScalarOperator | ArrayOperator | UrlOperator | OtherOperator;
|
|
11
|
-
type RangeValue = {
|
|
12
|
-
min?: number;
|
|
13
|
-
max?: number;
|
|
14
|
-
};
|
|
15
|
-
type SizeValue = number | RangeValue;
|
|
16
|
-
type ConditionValue = JsonValue | RangeValue | SizeValue;
|
|
17
|
-
interface Condition {
|
|
18
|
-
path: (string | number)[];
|
|
19
|
-
operator: Operator;
|
|
20
|
-
value?: ConditionValue;
|
|
21
|
-
}
|
|
22
|
-
type Effect = "allow" | "ask" | "deny";
|
|
23
|
-
interface Statement {
|
|
24
|
-
id?: string;
|
|
25
|
-
effect: Effect;
|
|
26
|
-
permissions: string[];
|
|
27
|
-
resources: string[];
|
|
28
|
-
conditions?: Condition[];
|
|
29
|
-
}
|
|
30
|
-
interface Policy {
|
|
31
|
-
version: 1 | 2;
|
|
32
|
-
statements: Statement[];
|
|
33
|
-
}
|
|
34
|
-
interface PolicyRequest {
|
|
35
|
-
permission: string;
|
|
36
|
-
resource: string;
|
|
37
|
-
context?: Record<string, unknown>;
|
|
38
|
-
}
|
|
39
|
-
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
40
|
-
type CanonicalHash = string & {
|
|
41
|
-
readonly __brand: "CanonicalHash";
|
|
42
|
-
};
|
|
43
|
-
interface OverrideBase {
|
|
44
|
-
id?: string;
|
|
45
|
-
statementHash: CanonicalHash;
|
|
46
|
-
effect: "allow";
|
|
47
|
-
}
|
|
48
|
-
type Override = (OverrideBase & {
|
|
49
|
-
match: "any";
|
|
50
|
-
}) | (OverrideBase & {
|
|
51
|
-
contextHash: CanonicalHash;
|
|
52
|
-
}) | (OverrideBase & {
|
|
53
|
-
conditionals: Condition[];
|
|
54
|
-
});
|
|
55
|
-
interface ConditionTrace {
|
|
56
|
-
condition: Condition;
|
|
57
|
-
resolved: unknown;
|
|
58
|
-
passed: boolean;
|
|
59
|
-
}
|
|
60
|
-
interface OverrideTrace {
|
|
61
|
-
override: Override;
|
|
62
|
-
matched: boolean;
|
|
63
|
-
conditionResults?: ConditionTrace[];
|
|
64
|
-
}
|
|
65
|
-
interface StatementTrace {
|
|
66
|
-
statement: Statement;
|
|
67
|
-
permissionMatched: boolean;
|
|
68
|
-
resourceMatched: boolean;
|
|
69
|
-
conditionResults?: ConditionTrace[];
|
|
70
|
-
passed: boolean;
|
|
71
|
-
overrides?: OverrideTrace[];
|
|
72
|
-
}
|
|
73
|
-
interface EvaluatePolicyOptions {
|
|
74
|
-
policy: Policy;
|
|
75
|
-
request: PolicyRequest;
|
|
76
|
-
overrides?: Override[];
|
|
77
|
-
trace?: boolean;
|
|
78
|
-
}
|
|
79
|
-
type PolicyReason = "matched" | "unmatched" | "hpp" | "overridden";
|
|
80
|
-
interface PolicyResult {
|
|
81
|
-
effect: Effect;
|
|
82
|
-
explicit: boolean;
|
|
83
|
-
reason: PolicyReason;
|
|
84
|
-
statements: StatementTrace[];
|
|
85
|
-
}
|
|
86
|
-
interface ParsedUrl {
|
|
87
|
-
scheme: string;
|
|
88
|
-
host: string;
|
|
89
|
-
port: number;
|
|
90
|
-
path: string;
|
|
91
|
-
query: Record<string, string[]>;
|
|
92
|
-
}
|
|
93
|
-
interface PolicyHttpRequest {
|
|
94
|
-
method: string;
|
|
95
|
-
url: ParsedUrl;
|
|
96
|
-
headers: Record<string, string | string[]>;
|
|
97
|
-
body: string | null;
|
|
98
|
-
body_json: unknown;
|
|
99
|
-
connection_id?: string;
|
|
100
|
-
}
|
|
101
|
-
interface PolicyActionRequest {
|
|
102
|
-
connection_id?: string;
|
|
103
|
-
selected_api?: string;
|
|
104
|
-
action_type?: string;
|
|
105
|
-
action_key?: string;
|
|
106
|
-
inputs?: Record<string, unknown>;
|
|
107
|
-
}
|
|
108
|
-
/** Simplified OpenAPI-compatible JSON Schema type for getOpenApiSchema(). */
|
|
109
|
-
interface OpenApiSchema {
|
|
110
|
-
type?: string;
|
|
111
|
-
required?: string[];
|
|
112
|
-
properties?: Record<string, OpenApiSchema>;
|
|
113
|
-
items?: OpenApiSchema;
|
|
114
|
-
enum?: (string | number)[];
|
|
115
|
-
description?: string;
|
|
116
|
-
minItems?: number;
|
|
117
|
-
oneOf?: OpenApiSchema[];
|
|
118
|
-
anyOf?: OpenApiSchema[];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
3
|
/** Current policy document version. */
|
|
122
4
|
declare const VALID_VERSIONS: readonly [1, 2];
|
|
123
5
|
/** Valid policy effects. */
|
|
124
6
|
declare const VALID_EFFECTS: readonly ["allow", "ask", "deny"];
|
|
7
|
+
/** Derived from VALID_EFFECTS — the constant is the single source of truth. */
|
|
8
|
+
type Effect = (typeof VALID_EFFECTS)[number];
|
|
125
9
|
/** Valid condition operators. */
|
|
126
10
|
declare const VALID_OPERATOR_LIST: readonly ["equals", "exists", "in", "keys_in", "matches", "matches_host", "matches_path", "matches_url", "range", "size", "values_in"];
|
|
127
|
-
declare const JsonValueSchema: z.ZodType<JsonValue>;
|
|
128
11
|
declare const RangeValueSchema: z.ZodObject<{
|
|
129
12
|
min: z.ZodOptional<z.ZodNumber>;
|
|
130
13
|
max: z.ZodOptional<z.ZodNumber>;
|
|
131
14
|
}, z.core.$strict>;
|
|
15
|
+
/** Derived from RangeValueSchema — the schema is the single source of truth. */
|
|
16
|
+
type RangeValue = z.infer<typeof RangeValueSchema>;
|
|
132
17
|
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
133
18
|
min: z.ZodOptional<z.ZodNumber>;
|
|
134
19
|
max: z.ZodOptional<z.ZodNumber>;
|
|
135
20
|
}, z.core.$strict>]>;
|
|
21
|
+
/** Derived from SizeValueSchema — the schema is the single source of truth. */
|
|
22
|
+
type SizeValue = z.infer<typeof SizeValueSchema>;
|
|
136
23
|
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
137
24
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
138
25
|
operator: z.ZodLiteral<"equals">;
|
|
139
|
-
value: z.
|
|
26
|
+
value: z.ZodJSONSchema;
|
|
140
27
|
}, z.core.$strict>, z.ZodObject<{
|
|
141
28
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
142
29
|
operator: z.ZodLiteral<"in">;
|
|
@@ -183,6 +70,8 @@ declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
183
70
|
max: z.ZodOptional<z.ZodNumber>;
|
|
184
71
|
}, z.core.$strict>]>;
|
|
185
72
|
}, z.core.$strict>]>;
|
|
73
|
+
/** Derived from ConditionSchema — the schema is the single source of truth. */
|
|
74
|
+
type Condition = z.infer<typeof ConditionSchema>;
|
|
186
75
|
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
187
76
|
equals: "equals";
|
|
188
77
|
in: "in";
|
|
@@ -191,31 +80,41 @@ declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
|
191
80
|
matches_path: "matches_path";
|
|
192
81
|
range: "range";
|
|
193
82
|
}>;
|
|
83
|
+
/** Derived from ScalarOperatorSchema — the schema is the single source of truth. */
|
|
84
|
+
type ScalarOperator = z.infer<typeof ScalarOperatorSchema>;
|
|
194
85
|
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
195
86
|
values_in: "values_in";
|
|
196
87
|
}>;
|
|
88
|
+
/** Derived from ArrayOperatorSchema — the schema is the single source of truth. */
|
|
89
|
+
type ArrayOperator = z.infer<typeof ArrayOperatorSchema>;
|
|
197
90
|
declare const UrlOperatorSchema: z.ZodEnum<{
|
|
198
91
|
matches_url: "matches_url";
|
|
199
92
|
}>;
|
|
93
|
+
/** Derived from UrlOperatorSchema — the schema is the single source of truth. */
|
|
94
|
+
type UrlOperator = z.infer<typeof UrlOperatorSchema>;
|
|
200
95
|
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
201
96
|
exists: "exists";
|
|
202
97
|
keys_in: "keys_in";
|
|
203
98
|
size: "size";
|
|
204
99
|
}>;
|
|
100
|
+
/** Derived from OtherOperatorSchema — the schema is the single source of truth. */
|
|
101
|
+
type OtherOperator = z.infer<typeof OtherOperatorSchema>;
|
|
205
102
|
declare const OperatorSchema: z.ZodEnum<{
|
|
206
103
|
equals: "equals";
|
|
104
|
+
exists: "exists";
|
|
207
105
|
in: "in";
|
|
106
|
+
keys_in: "keys_in";
|
|
208
107
|
matches: "matches";
|
|
209
108
|
matches_host: "matches_host";
|
|
210
109
|
matches_path: "matches_path";
|
|
110
|
+
matches_url: "matches_url";
|
|
211
111
|
range: "range";
|
|
212
|
-
exists: "exists";
|
|
213
|
-
keys_in: "keys_in";
|
|
214
112
|
size: "size";
|
|
215
113
|
values_in: "values_in";
|
|
216
|
-
matches_url: "matches_url";
|
|
217
114
|
}>;
|
|
218
|
-
|
|
115
|
+
/** Derived from OperatorSchema — the schema is the single source of truth. */
|
|
116
|
+
type Operator = z.infer<typeof OperatorSchema>;
|
|
117
|
+
declare const ConditionValueSchema: z.ZodJSONSchema;
|
|
219
118
|
/** Statement schema accepting the union of all effects (use PolicySchema for version-aware validation). */
|
|
220
119
|
declare const StatementSchema: z.ZodObject<{
|
|
221
120
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -229,7 +128,7 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
229
128
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
230
129
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
231
130
|
operator: z.ZodLiteral<"equals">;
|
|
232
|
-
value: z.
|
|
131
|
+
value: z.ZodJSONSchema;
|
|
233
132
|
}, z.core.$strict>, z.ZodObject<{
|
|
234
133
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
235
134
|
operator: z.ZodLiteral<"in">;
|
|
@@ -277,6 +176,8 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
277
176
|
}, z.core.$strict>]>;
|
|
278
177
|
}, z.core.$strict>]>>>;
|
|
279
178
|
}, z.core.$strict>;
|
|
179
|
+
/** Derived from StatementSchema — the schema is the single source of truth. */
|
|
180
|
+
type Statement = z.infer<typeof StatementSchema>;
|
|
280
181
|
declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
281
182
|
version: z.ZodLiteral<1>;
|
|
282
183
|
statements: z.ZodArray<z.ZodObject<{
|
|
@@ -290,7 +191,7 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
290
191
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
291
192
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
292
193
|
operator: z.ZodLiteral<"equals">;
|
|
293
|
-
value: z.
|
|
194
|
+
value: z.ZodJSONSchema;
|
|
294
195
|
}, z.core.$strict>, z.ZodObject<{
|
|
295
196
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
296
197
|
operator: z.ZodLiteral<"in">;
|
|
@@ -352,7 +253,7 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
352
253
|
conditions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
353
254
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
354
255
|
operator: z.ZodLiteral<"equals">;
|
|
355
|
-
value: z.
|
|
256
|
+
value: z.ZodJSONSchema;
|
|
356
257
|
}, z.core.$strict>, z.ZodObject<{
|
|
357
258
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
358
259
|
operator: z.ZodLiteral<"in">;
|
|
@@ -401,6 +302,82 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
401
302
|
}, z.core.$strict>]>>>;
|
|
402
303
|
}, z.core.$strict>>;
|
|
403
304
|
}, z.core.$strict>]>;
|
|
305
|
+
/** Derived from PolicySchema — the schema is the single source of truth. */
|
|
306
|
+
type Policy = z.infer<typeof PolicySchema>;
|
|
307
|
+
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
308
|
+
declare const CanonicalHashSchema: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
309
|
+
/**
|
|
310
|
+
* Runtime schema for the Override type. `.strict()` keeps the variants
|
|
311
|
+
* mutually exclusive (an object carrying two variant fields fails all
|
|
312
|
+
* branches).
|
|
313
|
+
*/
|
|
314
|
+
declare const OverrideSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
315
|
+
match: z.ZodLiteral<"any">;
|
|
316
|
+
id: z.ZodOptional<z.ZodString>;
|
|
317
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
318
|
+
effect: z.ZodLiteral<"allow">;
|
|
319
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
320
|
+
contextHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
321
|
+
id: z.ZodOptional<z.ZodString>;
|
|
322
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
323
|
+
effect: z.ZodLiteral<"allow">;
|
|
324
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
325
|
+
conditionals: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
326
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
327
|
+
operator: z.ZodLiteral<"equals">;
|
|
328
|
+
value: z.ZodJSONSchema;
|
|
329
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
330
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
331
|
+
operator: z.ZodLiteral<"in">;
|
|
332
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
333
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
334
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
335
|
+
operator: z.ZodLiteral<"matches">;
|
|
336
|
+
value: z.ZodString;
|
|
337
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
338
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
339
|
+
operator: z.ZodLiteral<"matches_host">;
|
|
340
|
+
value: z.ZodString;
|
|
341
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
342
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
343
|
+
operator: z.ZodLiteral<"matches_path">;
|
|
344
|
+
value: z.ZodString;
|
|
345
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
346
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
347
|
+
operator: z.ZodLiteral<"range">;
|
|
348
|
+
value: z.ZodObject<{
|
|
349
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
350
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
351
|
+
}, z.core.$strict>;
|
|
352
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
353
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
354
|
+
operator: z.ZodLiteral<"matches_url">;
|
|
355
|
+
value: z.ZodString;
|
|
356
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
357
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
358
|
+
operator: z.ZodLiteral<"values_in">;
|
|
359
|
+
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
360
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
361
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
362
|
+
operator: z.ZodLiteral<"exists">;
|
|
363
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
364
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
365
|
+
operator: z.ZodLiteral<"keys_in">;
|
|
366
|
+
value: z.ZodArray<z.ZodString>;
|
|
367
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
368
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
369
|
+
operator: z.ZodLiteral<"size">;
|
|
370
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
371
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
372
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
373
|
+
}, z.core.$strict>]>;
|
|
374
|
+
}, z.core.$strict>]>>;
|
|
375
|
+
id: z.ZodOptional<z.ZodString>;
|
|
376
|
+
statementHash: z.ZodCustom<CanonicalHash, CanonicalHash>;
|
|
377
|
+
effect: z.ZodLiteral<"allow">;
|
|
378
|
+
}, z.core.$strict>]>;
|
|
379
|
+
/** Derived from OverrideSchema — the schema is the single source of truth. */
|
|
380
|
+
type Override = z.infer<typeof OverrideSchema>;
|
|
404
381
|
/**
|
|
405
382
|
* Returns an OpenAPI-compatible JSON Schema object for a policy document.
|
|
406
383
|
*
|
|
@@ -409,4 +386,83 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
409
386
|
*/
|
|
410
387
|
declare function getOpenApiSchema(): OpenApiSchema;
|
|
411
388
|
|
|
412
|
-
|
|
389
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
390
|
+
[key: string]: JsonValue;
|
|
391
|
+
};
|
|
392
|
+
type ConditionValue = JsonValue | RangeValue | SizeValue;
|
|
393
|
+
interface PolicyRequest {
|
|
394
|
+
permission: string;
|
|
395
|
+
resource: string;
|
|
396
|
+
context?: Record<string, unknown>;
|
|
397
|
+
}
|
|
398
|
+
/** SHA-256 hex digest of an RFC 8785 (JCS) canonicalized JSON value. */
|
|
399
|
+
type CanonicalHash = string & {
|
|
400
|
+
readonly __brand: "CanonicalHash";
|
|
401
|
+
};
|
|
402
|
+
interface ConditionTrace {
|
|
403
|
+
condition: Condition;
|
|
404
|
+
resolved: unknown;
|
|
405
|
+
passed: boolean;
|
|
406
|
+
}
|
|
407
|
+
interface OverrideTrace {
|
|
408
|
+
override: Override;
|
|
409
|
+
matched: boolean;
|
|
410
|
+
conditionResults?: ConditionTrace[];
|
|
411
|
+
}
|
|
412
|
+
interface StatementTrace {
|
|
413
|
+
statement: Statement;
|
|
414
|
+
permissionMatched: boolean;
|
|
415
|
+
resourceMatched: boolean;
|
|
416
|
+
conditionResults?: ConditionTrace[];
|
|
417
|
+
passed: boolean;
|
|
418
|
+
overrides?: OverrideTrace[];
|
|
419
|
+
}
|
|
420
|
+
interface EvaluatePolicyOptions {
|
|
421
|
+
policy: Policy;
|
|
422
|
+
request: PolicyRequest;
|
|
423
|
+
overrides?: Override[];
|
|
424
|
+
trace?: boolean;
|
|
425
|
+
}
|
|
426
|
+
type PolicyReason = "matched" | "unmatched" | "hpp" | "overridden";
|
|
427
|
+
interface PolicyResult {
|
|
428
|
+
effect: Effect;
|
|
429
|
+
explicit: boolean;
|
|
430
|
+
reason: PolicyReason;
|
|
431
|
+
statements: StatementTrace[];
|
|
432
|
+
}
|
|
433
|
+
interface ParsedUrl {
|
|
434
|
+
scheme: string;
|
|
435
|
+
host: string;
|
|
436
|
+
port: number;
|
|
437
|
+
path: string;
|
|
438
|
+
query: Record<string, string[]>;
|
|
439
|
+
}
|
|
440
|
+
interface PolicyHttpRequest {
|
|
441
|
+
method: string;
|
|
442
|
+
url: ParsedUrl;
|
|
443
|
+
headers: Record<string, string | string[]>;
|
|
444
|
+
body: string | null;
|
|
445
|
+
body_json: unknown;
|
|
446
|
+
connection_id?: string;
|
|
447
|
+
}
|
|
448
|
+
interface PolicyActionRequest {
|
|
449
|
+
connection_id?: string;
|
|
450
|
+
selected_api?: string;
|
|
451
|
+
action_type?: string;
|
|
452
|
+
action_key?: string;
|
|
453
|
+
inputs?: Record<string, unknown>;
|
|
454
|
+
}
|
|
455
|
+
/** Simplified OpenAPI-compatible JSON Schema type for getOpenApiSchema(). */
|
|
456
|
+
interface OpenApiSchema {
|
|
457
|
+
type?: string;
|
|
458
|
+
required?: string[];
|
|
459
|
+
properties?: Record<string, OpenApiSchema>;
|
|
460
|
+
items?: OpenApiSchema;
|
|
461
|
+
enum?: (string | number)[];
|
|
462
|
+
description?: string;
|
|
463
|
+
minItems?: number;
|
|
464
|
+
oneOf?: OpenApiSchema[];
|
|
465
|
+
anyOf?: OpenApiSchema[];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export { type ArrayOperator, ArrayOperatorSchema, type CanonicalHash, CanonicalHashSchema, type Condition, ConditionSchema, type ConditionTrace, type ConditionValue, ConditionValueSchema, type Effect, type EvaluatePolicyOptions, type JsonValue, type OpenApiSchema, type Operator, OperatorSchema, type OtherOperator, OtherOperatorSchema, type Override, OverrideSchema, type OverrideTrace, type ParsedUrl, type Policy, type PolicyActionRequest, type PolicyHttpRequest, type PolicyReason, type PolicyRequest, type PolicyResult, PolicySchema, type RangeValue, RangeValueSchema, type ScalarOperator, ScalarOperatorSchema, type SizeValue, SizeValueSchema, type Statement, StatementSchema, type StatementTrace, type UrlOperator, UrlOperatorSchema, VALID_EFFECTS, VALID_OPERATOR_LIST, VALID_VERSIONS, getOpenApiSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -18,20 +18,10 @@ var VALID_OPERATOR_LIST = [
|
|
|
18
18
|
];
|
|
19
19
|
var ScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
20
20
|
var PathSchema = z.array(z.union([z.string(), z.number()])).min(1);
|
|
21
|
-
var JsonValueSchema = z.lazy(
|
|
22
|
-
() => z.union([
|
|
23
|
-
z.string(),
|
|
24
|
-
z.number(),
|
|
25
|
-
z.boolean(),
|
|
26
|
-
z.null(),
|
|
27
|
-
z.array(JsonValueSchema),
|
|
28
|
-
z.record(z.string(), JsonValueSchema)
|
|
29
|
-
])
|
|
30
|
-
);
|
|
31
21
|
var EqualsConditionSchema = z.object({
|
|
32
22
|
path: PathSchema,
|
|
33
23
|
operator: z.literal("equals"),
|
|
34
|
-
value:
|
|
24
|
+
value: z.json()
|
|
35
25
|
}).strict();
|
|
36
26
|
var InConditionSchema = z.object({
|
|
37
27
|
path: PathSchema,
|
|
@@ -137,7 +127,7 @@ var OperatorSchema = z.enum([
|
|
|
137
127
|
"keys_in",
|
|
138
128
|
"size"
|
|
139
129
|
]);
|
|
140
|
-
var ConditionValueSchema =
|
|
130
|
+
var ConditionValueSchema = z.json();
|
|
141
131
|
var V1StatementSchema = z.object({
|
|
142
132
|
id: z.string().optional(),
|
|
143
133
|
effect: z.enum(["allow", "deny"]),
|
|
@@ -162,6 +152,26 @@ var V2PolicySchema = z.object({
|
|
|
162
152
|
statements: z.array(V2StatementSchema)
|
|
163
153
|
}).strict();
|
|
164
154
|
var PolicySchema = z.union([V1PolicySchema, V2PolicySchema]);
|
|
155
|
+
var CanonicalHashSchema = z.custom(
|
|
156
|
+
(value) => typeof value === "string" && /^[0-9a-f]{64}$/.test(value),
|
|
157
|
+
{ error: "Expected a 64-character lowercase hex SHA-256 digest" }
|
|
158
|
+
);
|
|
159
|
+
var OverrideBaseShape = {
|
|
160
|
+
id: z.string().optional(),
|
|
161
|
+
statementHash: CanonicalHashSchema,
|
|
162
|
+
effect: z.literal("allow")
|
|
163
|
+
};
|
|
164
|
+
var OverrideSchema = z.union([
|
|
165
|
+
z.object({ ...OverrideBaseShape, match: z.literal("any") }).strict(),
|
|
166
|
+
z.object({ ...OverrideBaseShape, contextHash: CanonicalHashSchema }).strict(),
|
|
167
|
+
// Empty conditionals is intentional (the "blank check"): the override
|
|
168
|
+
// applies whenever the targeted ask statement fires, with no extra
|
|
169
|
+
// conditions. Do not add .min(1) here.
|
|
170
|
+
z.object({
|
|
171
|
+
...OverrideBaseShape,
|
|
172
|
+
conditionals: z.array(ConditionSchema)
|
|
173
|
+
}).strict()
|
|
174
|
+
]);
|
|
165
175
|
function getOpenApiSchema() {
|
|
166
176
|
return {
|
|
167
177
|
type: "object",
|
|
@@ -233,4 +243,4 @@ function getOpenApiSchema() {
|
|
|
233
243
|
};
|
|
234
244
|
}
|
|
235
245
|
|
|
236
|
-
export { ArrayOperatorSchema, ConditionSchema, ConditionValueSchema,
|
|
246
|
+
export { ArrayOperatorSchema, CanonicalHashSchema, ConditionSchema, ConditionValueSchema, OperatorSchema, OtherOperatorSchema, OverrideSchema, PolicySchema, RangeValueSchema, ScalarOperatorSchema, SizeValueSchema, StatementSchema, UrlOperatorSchema, VALID_EFFECTS, VALID_OPERATOR_LIST, VALID_VERSIONS, getOpenApiSchema };
|