@cedar-policy/cedar-wasm 4.3.0 → 4.4.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.
@@ -10,6 +10,26 @@ export function getValidRequestEnvsTemplate(t: Template, s: Schema): GetValidReq
10
10
  export function getValidRequestEnvsPolicy(t: Policy, s: Schema): GetValidRequestEnvsResult;
11
11
  export function getCedarVersion(): string;
12
12
  export function getCedarSDKVersion(): string;
13
+ /**
14
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
15
+ */
16
+ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
17
+ /**
18
+ * Check whether a policy set successfully parses.
19
+ */
20
+ export function checkParsePolicySet(policies: PolicySet): CheckParseAnswer;
21
+ /**
22
+ * Check whether a schema successfully parses.
23
+ */
24
+ export function checkParseSchema(schema: Schema): CheckParseAnswer;
25
+ /**
26
+ * Check whether a set of entities successfully parses.
27
+ */
28
+ export function checkParseEntities(call: EntitiesParsingCall): CheckParseAnswer;
29
+ /**
30
+ * Check whether a context successfully parses.
31
+ */
32
+ export function checkParseContext(call: ContextParsingCall): CheckParseAnswer;
13
33
  /**
14
34
  * Parse a policy set and optionally validate it against a provided schema
15
35
  *
@@ -18,9 +38,9 @@ export function getCedarSDKVersion(): string;
18
38
  */
19
39
  export function validate(call: ValidationCall): ValidationAnswer;
20
40
  /**
21
- * Get language version of Cedar
41
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
22
42
  */
23
- export function getCedarLangVersion(): string;
43
+ export function formatPolicies(call: FormattingCall): FormattingAnswer;
24
44
  /**
25
45
  * Return the Cedar (textual) representation of a policy.
26
46
  */
@@ -46,73 +66,11 @@ export function schemaToText(schema: Schema): SchemaToTextAnswer;
46
66
  */
47
67
  export function schemaToJson(schema: Schema): SchemaToJsonAnswer;
48
68
  /**
49
- * Check whether a policy set successfully parses.
50
- */
51
- export function checkParsePolicySet(policies: PolicySet): CheckParseAnswer;
52
- /**
53
- * Check whether a schema successfully parses.
54
- */
55
- export function checkParseSchema(schema: Schema): CheckParseAnswer;
56
- /**
57
- * Check whether a set of entities successfully parses.
58
- */
59
- export function checkParseEntities(call: EntitiesParsingCall): CheckParseAnswer;
60
- /**
61
- * Check whether a context successfully parses.
62
- */
63
- export function checkParseContext(call: ContextParsingCall): CheckParseAnswer;
64
- /**
65
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
66
- */
67
- export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
68
- /**
69
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
69
+ * Get language version of Cedar
70
70
  */
71
- export function formatPolicies(call: FormattingCall): FormattingAnswer;
71
+ export function getCedarLangVersion(): string;
72
72
  export type GetValidRequestEnvsResult = { type: "success"; principals: string[]; actions: string[]; resources: string[] } | { type: "failure"; error: string };
73
73
 
74
- export interface ValidationCall {
75
- validationSettings?: ValidationSettings;
76
- schema: Schema;
77
- policies: PolicySet;
78
- }
79
-
80
- export interface ValidationSettings {
81
- mode: ValidationMode;
82
- }
83
-
84
- export interface ValidationError {
85
- policyId: string;
86
- error: DetailedError;
87
- }
88
-
89
- export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
90
-
91
- export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
92
-
93
- export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
94
-
95
- export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
96
-
97
- export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
98
-
99
- export type SlotId = string;
100
-
101
- export type PolicyId = string;
102
-
103
- export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
104
-
105
- export interface EntitiesParsingCall {
106
- entities: Entities;
107
- schema?: Schema | null;
108
- }
109
-
110
- export interface ContextParsingCall {
111
- context: Context;
112
- schema?: Schema | null;
113
- action?: EntityUid | null;
114
- }
115
-
116
74
  export interface Response {
117
75
  decision: Decision;
118
76
  diagnostics: Diagnostics;
@@ -141,13 +99,22 @@ export interface AuthorizationCall {
141
99
  entities: Entities;
142
100
  }
143
101
 
144
- export interface FormattingCall {
145
- policyText: string;
146
- lineWidth?: number;
147
- indentWidth?: number;
102
+ export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
103
+
104
+ export interface EntitiesParsingCall {
105
+ entities: Entities;
106
+ schema?: Schema | null;
148
107
  }
149
108
 
150
- export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
109
+ export interface ContextParsingCall {
110
+ context: Context;
111
+ schema?: Schema | null;
112
+ action?: EntityUid | null;
113
+ }
114
+
115
+ export type SlotId = string;
116
+
117
+ export type PolicyId = string;
151
118
 
152
119
  export type Schema = string | SchemaJson<string>;
153
120
 
@@ -196,6 +163,39 @@ export interface DetailedError {
196
163
  related?: DetailedError[];
197
164
  }
198
165
 
166
+ export interface ValidationCall {
167
+ validationSettings?: ValidationSettings;
168
+ schema: Schema;
169
+ policies: PolicySet;
170
+ }
171
+
172
+ export interface ValidationSettings {
173
+ mode: ValidationMode;
174
+ }
175
+
176
+ export interface ValidationError {
177
+ policyId: string;
178
+ error: DetailedError;
179
+ }
180
+
181
+ export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
182
+
183
+ export interface FormattingCall {
184
+ policyText: string;
185
+ lineWidth?: number;
186
+ indentWidth?: number;
187
+ }
188
+
189
+ export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
190
+
191
+ export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
192
+
193
+ export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
194
+
195
+ export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
196
+
197
+ export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
198
+
199
199
  export type ValidationMode = "strict";
200
200
 
201
201
  export type TypeVariant<N> = { type: "String" } | { type: "Long" } | { type: "Boolean" } | { type: "Set"; element: Type<N> } | ({ type: "Record" } & RecordType<N>) | { type: "Entity"; name: N } | { type: "EntityOrCommon"; name: N } | { type: "Extension"; name: UnreservedId };
@@ -227,13 +227,14 @@ export interface ActionType<N> {
227
227
 
228
228
  export type AttributesOrContext<N> = Type<N>;
229
229
 
230
- export interface EntityType<N> {
230
+ export interface StandardEntityType<N> {
231
231
  memberOfTypes?: N[];
232
232
  shape?: AttributesOrContext<N>;
233
233
  tags?: Type<N>;
234
- annotations?: Annotations;
235
234
  }
236
235
 
236
+ export type EntityTypeKind<N> = StandardEntityType<N> | { enum: NonEmpty<SmolStr> };
237
+
237
238
  export interface NamespaceDefinition<N> {
238
239
  commonTypes?: Record<CommonTypeId, CommonType<N>>;
239
240
  entityTypes: Record<UnreservedId, EntityType<N>>;
@@ -245,41 +246,8 @@ export type CommonTypeId = string;
245
246
 
246
247
  export type SchemaJson<N> = Record<string, NamespaceDefinition<N>>;
247
248
 
248
- export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
249
-
250
- export interface PrincipalOrResourceIsConstraint {
251
- entity_type: string;
252
- in?: PrincipalOrResourceInConstraint;
253
- }
254
-
255
- export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
256
-
257
- export type EqConstraint = { entity: EntityUidJson } | { slot: string };
258
-
259
- export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
260
-
261
- export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
262
-
263
- export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
264
-
265
249
  export type Var = "principal" | "action" | "resource" | "context";
266
250
 
267
- export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
268
-
269
- export interface FnAndArg {
270
- fn: string;
271
- arg: CedarValueJson;
272
- }
273
-
274
- export interface TypeAndId {
275
- type: string;
276
- id: string;
277
- }
278
-
279
- export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
280
-
281
- export type Annotations = Record<string, Annotation>;
282
-
283
251
  export interface EntityJson {
284
252
  uid: EntityUidJson;
285
253
  attrs: Record<string, CedarValueJson>;
@@ -289,8 +257,6 @@ export interface EntityJson {
289
257
 
290
258
  export type Decision = "allow" | "deny";
291
259
 
292
- export type Annotation = SmolStr;
293
-
294
260
  export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
295
261
 
296
262
  export interface PolicyJson {
@@ -314,36 +280,73 @@ export type AnyId = SmolStr;
314
280
 
315
281
  export type UnreservedId = string;
316
282
 
283
+ export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
284
+
285
+ export interface FnAndArg {
286
+ fn: string;
287
+ arg: CedarValueJson;
288
+ }
289
+
290
+ export interface TypeAndId {
291
+ type: string;
292
+ id: string;
293
+ }
294
+
295
+ export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
296
+
297
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
298
+
299
+ export interface PrincipalOrResourceIsConstraint {
300
+ entity_type: string;
301
+ in?: PrincipalOrResourceInConstraint;
302
+ }
303
+
304
+ export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
305
+
306
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
307
+
308
+ export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
309
+
310
+ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
311
+
312
+ export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
313
+
317
314
  export type Effect = "permit" | "forbid";
318
315
 
316
+ export type Annotations = Record<string, Annotation>;
317
+
318
+ export type Annotation = SmolStr;
319
+
319
320
 
320
321
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
321
322
 
322
323
  export interface InitOutput {
323
324
  readonly memory: WebAssembly.Memory;
324
- readonly getValidRequestEnvsTemplate: (a: number, b: number) => number;
325
- readonly getValidRequestEnvsPolicy: (a: number, b: number) => number;
326
- readonly getCedarSDKVersion: (a: number) => void;
327
- readonly getCedarVersion: (a: number) => void;
328
- readonly validate: (a: number) => number;
329
- readonly getCedarLangVersion: (a: number) => void;
330
- readonly policyToText: (a: number) => number;
331
- readonly templateToText: (a: number) => number;
332
- readonly policyToJson: (a: number) => number;
333
- readonly templateToJson: (a: number) => number;
334
- readonly schemaToText: (a: number) => number;
335
- readonly schemaToJson: (a: number) => number;
336
- readonly checkParsePolicySet: (a: number) => number;
337
- readonly checkParseSchema: (a: number) => number;
338
- readonly checkParseEntities: (a: number) => number;
339
- readonly checkParseContext: (a: number) => number;
340
- readonly isAuthorized: (a: number) => number;
341
- readonly formatPolicies: (a: number) => number;
325
+ readonly getValidRequestEnvsTemplate: (a: any, b: any) => any;
326
+ readonly getValidRequestEnvsPolicy: (a: any, b: any) => any;
327
+ readonly getCedarSDKVersion: () => [number, number];
328
+ readonly getCedarVersion: () => [number, number];
329
+ readonly isAuthorized: (a: any) => any;
330
+ readonly checkParsePolicySet: (a: any) => any;
331
+ readonly checkParseSchema: (a: any) => any;
332
+ readonly checkParseEntities: (a: any) => any;
333
+ readonly checkParseContext: (a: any) => any;
334
+ readonly validate: (a: any) => any;
335
+ readonly formatPolicies: (a: any) => any;
336
+ readonly policyToText: (a: any) => any;
337
+ readonly templateToText: (a: any) => any;
338
+ readonly policyToJson: (a: any) => any;
339
+ readonly templateToJson: (a: any) => any;
340
+ readonly schemaToText: (a: any) => any;
341
+ readonly schemaToJson: (a: any) => any;
342
+ readonly getCedarLangVersion: () => [number, number];
342
343
  readonly __wbindgen_exn_store: (a: number) => void;
344
+ readonly __externref_table_alloc: () => number;
345
+ readonly __wbindgen_export_2: WebAssembly.Table;
343
346
  readonly __wbindgen_malloc: (a: number, b: number) => number;
344
347
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
345
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
346
348
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
349
+ readonly __wbindgen_start: () => void;
347
350
  }
348
351
 
349
352
  export type SyncInitInput = BufferSource | WebAssembly.Module;
@@ -369,3 +372,5 @@ export default function __wbg_init (module_or_path?: { module_or_path: InitInput
369
372
  type SmolStr = string;
370
373
  export type TypeOfAttribute<N> = Type<N> & { required?: boolean };
371
374
  export type CommonType<N> = Type<N> & { annotations?: Annotations };
375
+ export type EntityType<N> = EntityTypeKind<N> & { annotations?: Annotations; };
376
+ export type NonEmpty<Type> = Array<Type>;