@zapier/policy-schema 0.12.0 → 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 +22 -0
- package/dist/index.d.cts +179 -122
- package/dist/index.d.ts +179 -122
- package/dist/index.mjs +21 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -154,6 +154,26 @@ var V2PolicySchema = zod.z.object({
|
|
|
154
154
|
statements: zod.z.array(V2StatementSchema)
|
|
155
155
|
}).strict();
|
|
156
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
|
+
]);
|
|
157
177
|
function getOpenApiSchema() {
|
|
158
178
|
return {
|
|
159
179
|
type: "object",
|
|
@@ -226,10 +246,12 @@ function getOpenApiSchema() {
|
|
|
226
246
|
}
|
|
227
247
|
|
|
228
248
|
exports.ArrayOperatorSchema = ArrayOperatorSchema;
|
|
249
|
+
exports.CanonicalHashSchema = CanonicalHashSchema;
|
|
229
250
|
exports.ConditionSchema = ConditionSchema;
|
|
230
251
|
exports.ConditionValueSchema = ConditionValueSchema;
|
|
231
252
|
exports.OperatorSchema = OperatorSchema;
|
|
232
253
|
exports.OtherOperatorSchema = OtherOperatorSchema;
|
|
254
|
+
exports.OverrideSchema = OverrideSchema;
|
|
233
255
|
exports.PolicySchema = PolicySchema;
|
|
234
256
|
exports.RangeValueSchema = RangeValueSchema;
|
|
235
257
|
exports.ScalarOperatorSchema = ScalarOperatorSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,137 +1,25 @@
|
|
|
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
11
|
declare const RangeValueSchema: z.ZodObject<{
|
|
128
12
|
min: z.ZodOptional<z.ZodNumber>;
|
|
129
13
|
max: z.ZodOptional<z.ZodNumber>;
|
|
130
14
|
}, z.core.$strict>;
|
|
15
|
+
/** Derived from RangeValueSchema — the schema is the single source of truth. */
|
|
16
|
+
type RangeValue = z.infer<typeof RangeValueSchema>;
|
|
131
17
|
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
132
18
|
min: z.ZodOptional<z.ZodNumber>;
|
|
133
19
|
max: z.ZodOptional<z.ZodNumber>;
|
|
134
20
|
}, z.core.$strict>]>;
|
|
21
|
+
/** Derived from SizeValueSchema — the schema is the single source of truth. */
|
|
22
|
+
type SizeValue = z.infer<typeof SizeValueSchema>;
|
|
135
23
|
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
136
24
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
137
25
|
operator: z.ZodLiteral<"equals">;
|
|
@@ -182,6 +70,8 @@ declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
182
70
|
max: z.ZodOptional<z.ZodNumber>;
|
|
183
71
|
}, z.core.$strict>]>;
|
|
184
72
|
}, z.core.$strict>]>;
|
|
73
|
+
/** Derived from ConditionSchema — the schema is the single source of truth. */
|
|
74
|
+
type Condition = z.infer<typeof ConditionSchema>;
|
|
185
75
|
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
186
76
|
equals: "equals";
|
|
187
77
|
in: "in";
|
|
@@ -190,30 +80,40 @@ declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
|
190
80
|
matches_path: "matches_path";
|
|
191
81
|
range: "range";
|
|
192
82
|
}>;
|
|
83
|
+
/** Derived from ScalarOperatorSchema — the schema is the single source of truth. */
|
|
84
|
+
type ScalarOperator = z.infer<typeof ScalarOperatorSchema>;
|
|
193
85
|
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
194
86
|
values_in: "values_in";
|
|
195
87
|
}>;
|
|
88
|
+
/** Derived from ArrayOperatorSchema — the schema is the single source of truth. */
|
|
89
|
+
type ArrayOperator = z.infer<typeof ArrayOperatorSchema>;
|
|
196
90
|
declare const UrlOperatorSchema: z.ZodEnum<{
|
|
197
91
|
matches_url: "matches_url";
|
|
198
92
|
}>;
|
|
93
|
+
/** Derived from UrlOperatorSchema — the schema is the single source of truth. */
|
|
94
|
+
type UrlOperator = z.infer<typeof UrlOperatorSchema>;
|
|
199
95
|
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
200
96
|
exists: "exists";
|
|
201
97
|
keys_in: "keys_in";
|
|
202
98
|
size: "size";
|
|
203
99
|
}>;
|
|
100
|
+
/** Derived from OtherOperatorSchema — the schema is the single source of truth. */
|
|
101
|
+
type OtherOperator = z.infer<typeof OtherOperatorSchema>;
|
|
204
102
|
declare const OperatorSchema: z.ZodEnum<{
|
|
205
103
|
equals: "equals";
|
|
104
|
+
exists: "exists";
|
|
206
105
|
in: "in";
|
|
106
|
+
keys_in: "keys_in";
|
|
207
107
|
matches: "matches";
|
|
208
108
|
matches_host: "matches_host";
|
|
209
109
|
matches_path: "matches_path";
|
|
110
|
+
matches_url: "matches_url";
|
|
210
111
|
range: "range";
|
|
211
|
-
exists: "exists";
|
|
212
|
-
keys_in: "keys_in";
|
|
213
112
|
size: "size";
|
|
214
113
|
values_in: "values_in";
|
|
215
|
-
matches_url: "matches_url";
|
|
216
114
|
}>;
|
|
115
|
+
/** Derived from OperatorSchema — the schema is the single source of truth. */
|
|
116
|
+
type Operator = z.infer<typeof OperatorSchema>;
|
|
217
117
|
declare const ConditionValueSchema: z.ZodJSONSchema;
|
|
218
118
|
/** Statement schema accepting the union of all effects (use PolicySchema for version-aware validation). */
|
|
219
119
|
declare const StatementSchema: z.ZodObject<{
|
|
@@ -276,6 +176,8 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
276
176
|
}, z.core.$strict>]>;
|
|
277
177
|
}, z.core.$strict>]>>>;
|
|
278
178
|
}, z.core.$strict>;
|
|
179
|
+
/** Derived from StatementSchema — the schema is the single source of truth. */
|
|
180
|
+
type Statement = z.infer<typeof StatementSchema>;
|
|
279
181
|
declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
280
182
|
version: z.ZodLiteral<1>;
|
|
281
183
|
statements: z.ZodArray<z.ZodObject<{
|
|
@@ -400,6 +302,82 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
400
302
|
}, z.core.$strict>]>>>;
|
|
401
303
|
}, z.core.$strict>>;
|
|
402
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>;
|
|
403
381
|
/**
|
|
404
382
|
* Returns an OpenAPI-compatible JSON Schema object for a policy document.
|
|
405
383
|
*
|
|
@@ -408,4 +386,83 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
408
386
|
*/
|
|
409
387
|
declare function getOpenApiSchema(): OpenApiSchema;
|
|
410
388
|
|
|
411
|
-
|
|
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,137 +1,25 @@
|
|
|
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
11
|
declare const RangeValueSchema: z.ZodObject<{
|
|
128
12
|
min: z.ZodOptional<z.ZodNumber>;
|
|
129
13
|
max: z.ZodOptional<z.ZodNumber>;
|
|
130
14
|
}, z.core.$strict>;
|
|
15
|
+
/** Derived from RangeValueSchema — the schema is the single source of truth. */
|
|
16
|
+
type RangeValue = z.infer<typeof RangeValueSchema>;
|
|
131
17
|
declare const SizeValueSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
132
18
|
min: z.ZodOptional<z.ZodNumber>;
|
|
133
19
|
max: z.ZodOptional<z.ZodNumber>;
|
|
134
20
|
}, z.core.$strict>]>;
|
|
21
|
+
/** Derived from SizeValueSchema — the schema is the single source of truth. */
|
|
22
|
+
type SizeValue = z.infer<typeof SizeValueSchema>;
|
|
135
23
|
declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
136
24
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
137
25
|
operator: z.ZodLiteral<"equals">;
|
|
@@ -182,6 +70,8 @@ declare const ConditionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
182
70
|
max: z.ZodOptional<z.ZodNumber>;
|
|
183
71
|
}, z.core.$strict>]>;
|
|
184
72
|
}, z.core.$strict>]>;
|
|
73
|
+
/** Derived from ConditionSchema — the schema is the single source of truth. */
|
|
74
|
+
type Condition = z.infer<typeof ConditionSchema>;
|
|
185
75
|
declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
186
76
|
equals: "equals";
|
|
187
77
|
in: "in";
|
|
@@ -190,30 +80,40 @@ declare const ScalarOperatorSchema: z.ZodEnum<{
|
|
|
190
80
|
matches_path: "matches_path";
|
|
191
81
|
range: "range";
|
|
192
82
|
}>;
|
|
83
|
+
/** Derived from ScalarOperatorSchema — the schema is the single source of truth. */
|
|
84
|
+
type ScalarOperator = z.infer<typeof ScalarOperatorSchema>;
|
|
193
85
|
declare const ArrayOperatorSchema: z.ZodEnum<{
|
|
194
86
|
values_in: "values_in";
|
|
195
87
|
}>;
|
|
88
|
+
/** Derived from ArrayOperatorSchema — the schema is the single source of truth. */
|
|
89
|
+
type ArrayOperator = z.infer<typeof ArrayOperatorSchema>;
|
|
196
90
|
declare const UrlOperatorSchema: z.ZodEnum<{
|
|
197
91
|
matches_url: "matches_url";
|
|
198
92
|
}>;
|
|
93
|
+
/** Derived from UrlOperatorSchema — the schema is the single source of truth. */
|
|
94
|
+
type UrlOperator = z.infer<typeof UrlOperatorSchema>;
|
|
199
95
|
declare const OtherOperatorSchema: z.ZodEnum<{
|
|
200
96
|
exists: "exists";
|
|
201
97
|
keys_in: "keys_in";
|
|
202
98
|
size: "size";
|
|
203
99
|
}>;
|
|
100
|
+
/** Derived from OtherOperatorSchema — the schema is the single source of truth. */
|
|
101
|
+
type OtherOperator = z.infer<typeof OtherOperatorSchema>;
|
|
204
102
|
declare const OperatorSchema: z.ZodEnum<{
|
|
205
103
|
equals: "equals";
|
|
104
|
+
exists: "exists";
|
|
206
105
|
in: "in";
|
|
106
|
+
keys_in: "keys_in";
|
|
207
107
|
matches: "matches";
|
|
208
108
|
matches_host: "matches_host";
|
|
209
109
|
matches_path: "matches_path";
|
|
110
|
+
matches_url: "matches_url";
|
|
210
111
|
range: "range";
|
|
211
|
-
exists: "exists";
|
|
212
|
-
keys_in: "keys_in";
|
|
213
112
|
size: "size";
|
|
214
113
|
values_in: "values_in";
|
|
215
|
-
matches_url: "matches_url";
|
|
216
114
|
}>;
|
|
115
|
+
/** Derived from OperatorSchema — the schema is the single source of truth. */
|
|
116
|
+
type Operator = z.infer<typeof OperatorSchema>;
|
|
217
117
|
declare const ConditionValueSchema: z.ZodJSONSchema;
|
|
218
118
|
/** Statement schema accepting the union of all effects (use PolicySchema for version-aware validation). */
|
|
219
119
|
declare const StatementSchema: z.ZodObject<{
|
|
@@ -276,6 +176,8 @@ declare const StatementSchema: z.ZodObject<{
|
|
|
276
176
|
}, z.core.$strict>]>;
|
|
277
177
|
}, z.core.$strict>]>>>;
|
|
278
178
|
}, z.core.$strict>;
|
|
179
|
+
/** Derived from StatementSchema — the schema is the single source of truth. */
|
|
180
|
+
type Statement = z.infer<typeof StatementSchema>;
|
|
279
181
|
declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
280
182
|
version: z.ZodLiteral<1>;
|
|
281
183
|
statements: z.ZodArray<z.ZodObject<{
|
|
@@ -400,6 +302,82 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
400
302
|
}, z.core.$strict>]>>>;
|
|
401
303
|
}, z.core.$strict>>;
|
|
402
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>;
|
|
403
381
|
/**
|
|
404
382
|
* Returns an OpenAPI-compatible JSON Schema object for a policy document.
|
|
405
383
|
*
|
|
@@ -408,4 +386,83 @@ declare const PolicySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
408
386
|
*/
|
|
409
387
|
declare function getOpenApiSchema(): OpenApiSchema;
|
|
410
388
|
|
|
411
|
-
|
|
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
|
@@ -152,6 +152,26 @@ var V2PolicySchema = z.object({
|
|
|
152
152
|
statements: z.array(V2StatementSchema)
|
|
153
153
|
}).strict();
|
|
154
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
|
+
]);
|
|
155
175
|
function getOpenApiSchema() {
|
|
156
176
|
return {
|
|
157
177
|
type: "object",
|
|
@@ -223,4 +243,4 @@ function getOpenApiSchema() {
|
|
|
223
243
|
};
|
|
224
244
|
}
|
|
225
245
|
|
|
226
|
-
export { ArrayOperatorSchema, ConditionSchema, ConditionValueSchema, OperatorSchema, OtherOperatorSchema, PolicySchema, RangeValueSchema, ScalarOperatorSchema, SizeValueSchema, StatementSchema, UrlOperatorSchema, VALID_EFFECTS, VALID_OPERATOR_LIST, VALID_VERSIONS, getOpenApiSchema };
|
|
246
|
+
export { ArrayOperatorSchema, CanonicalHashSchema, ConditionSchema, ConditionValueSchema, OperatorSchema, OtherOperatorSchema, OverrideSchema, PolicySchema, RangeValueSchema, ScalarOperatorSchema, SizeValueSchema, StatementSchema, UrlOperatorSchema, VALID_EFFECTS, VALID_OPERATOR_LIST, VALID_VERSIONS, getOpenApiSchema };
|