@cedar-policy/cedar-wasm 4.8.2 → 4.9.1

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.
@@ -1,16 +1,22 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export type GetValidRequestEnvsResult = { type: "success"; principals: string[]; actions: string[]; resources: string[] } | { type: "failure"; error: string };
4
-
5
- export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
3
+ export interface ActionEntityUID<N> {
4
+ id: SmolStr;
5
+ type?: N;
6
+ }
6
7
 
7
- export interface FormattingCall {
8
- policyText: string;
9
- lineWidth?: number;
10
- indentWidth?: number;
8
+ export interface ActionType<N> {
9
+ attributes?: Record<SmolStr, CedarValueJson>;
10
+ appliesTo?: ApplySpec<N>;
11
+ memberOf?: ActionEntityUID<N>[];
12
+ annotations?: Annotations;
11
13
  }
12
14
 
13
- export type ValidationMode = "strict";
15
+ export interface ApplySpec<N> {
16
+ resourceTypes: N[];
17
+ principalTypes: N[];
18
+ context?: AttributesOrContext<N>;
19
+ }
14
20
 
15
21
  export interface AuthorizationCall {
16
22
  principal: EntityUid;
@@ -23,32 +29,15 @@ export interface AuthorizationCall {
23
29
  entities: Entities;
24
30
  }
25
31
 
26
- export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
27
-
28
32
  export interface AuthorizationError {
29
33
  policyId: string;
30
34
  error: DetailedError;
31
35
  }
32
36
 
33
- export interface StatefulAuthorizationCall {
34
- principal: EntityUid;
35
- action: EntityUid;
36
- resource: EntityUid;
37
+ export interface ContextParsingCall {
37
38
  context: Context;
38
- preparsedSchemaName?: string;
39
- validateRequest?: boolean;
40
- preparsedPolicySetId: string;
41
- entities: Entities;
42
- }
43
-
44
- export interface Diagnostics {
45
- reason: PolicyId[];
46
- errors: AuthorizationError[];
47
- }
48
-
49
- export interface Response {
50
- decision: Decision;
51
- diagnostics: Diagnostics;
39
+ schema?: Schema | null;
40
+ action?: EntityUid | null;
52
41
  }
53
42
 
54
43
  export interface DetailedError {
@@ -61,9 +50,55 @@ export interface DetailedError {
61
50
  related?: DetailedError[];
62
51
  }
63
52
 
64
- export type StaticPolicySet = string | Policy[] | Record<PolicyId, Policy>;
53
+ export interface Diagnostics {
54
+ reason: PolicyId[];
55
+ errors: AuthorizationError[];
56
+ }
65
57
 
66
- export type Entities = Array<EntityJson>;
58
+ export interface EntitiesParsingCall {
59
+ entities: Entities;
60
+ schema?: Schema | null;
61
+ }
62
+
63
+ export interface EntityJson {
64
+ uid: EntityUidJson;
65
+ attrs: Record<string, CedarValueJson>;
66
+ parents: EntityUidJson[];
67
+ tags?: Record<string, CedarValueJson>;
68
+ }
69
+
70
+ export interface FormattingCall {
71
+ policyText: string;
72
+ lineWidth?: number;
73
+ indentWidth?: number;
74
+ }
75
+
76
+ export interface NamespaceDefinition<N> {
77
+ commonTypes?: Record<CommonTypeId, CommonType<N>>;
78
+ entityTypes: Record<UnreservedId, EntityType<N>>;
79
+ actions: Record<SmolStr, ActionType<N>>;
80
+ annotations?: Annotations;
81
+ }
82
+
83
+ export interface PartialAuthorizationCall {
84
+ principal: EntityUid | null;
85
+ action: EntityUid | null;
86
+ resource: EntityUid | null;
87
+ context: Context;
88
+ schema?: Schema;
89
+ validateRequest?: boolean;
90
+ policies: PolicySet;
91
+ entities: Entities;
92
+ }
93
+
94
+ export interface PolicyJson {
95
+ effect: Effect;
96
+ principal: PrincipalConstraint;
97
+ action: ActionConstraint;
98
+ resource: ResourceConstraint;
99
+ conditions: Clause[];
100
+ annotations?: Annotations;
101
+ }
67
102
 
68
103
  export interface PolicySet {
69
104
  staticPolicies?: StaticPolicySet;
@@ -71,42 +106,66 @@ export interface PolicySet {
71
106
  templateLinks?: TemplateLink[];
72
107
  }
73
108
 
74
- export interface SourceLocation {
75
- start: number;
76
- end: number;
109
+ export interface PrincipalOrResourceIsConstraint {
110
+ entity_type: string;
111
+ in?: PrincipalOrResourceInConstraint;
77
112
  }
78
113
 
79
- export interface TemplateLink {
80
- templateId: PolicyId;
81
- newId: PolicyId;
82
- values: Record<SlotId, EntityUid>;
114
+ export interface RecordType<N> {
115
+ attributes: Record<SmolStr, TypeOfAttribute<N>>;
116
+ additionalAttributes?: boolean;
83
117
  }
84
118
 
85
- export type Severity = "advice" | "warning" | "error";
86
-
87
- export type Schema = string | SchemaJson<string>;
88
-
89
- export type Context = Record<string, CedarValueJson>;
119
+ export interface ResidualResponse {
120
+ decision: Decision | null;
121
+ satisfied: PolicyId[];
122
+ errored: PolicyId[];
123
+ mayBeDetermining: PolicyId[];
124
+ mustBeDetermining: PolicyId[];
125
+ residuals: Record<string, PolicyJson>;
126
+ nontrivialResiduals: PolicyId[];
127
+ }
90
128
 
91
- export type Policy = string | PolicyJson;
129
+ export interface Response {
130
+ decision: Decision;
131
+ diagnostics: Diagnostics;
132
+ }
92
133
 
93
134
  export interface SourceLabel extends SourceLocation {
94
135
  label: string | null;
95
136
  }
96
137
 
97
- export type EntityUid = EntityUidJson;
138
+ export interface SourceLocation {
139
+ start: number;
140
+ end: number;
141
+ }
98
142
 
99
- export type Template = string | PolicyJson;
143
+ export interface StandardEntityType<N> {
144
+ memberOfTypes?: N[];
145
+ shape?: AttributesOrContext<N>;
146
+ tags?: Type<N>;
147
+ }
100
148
 
101
- export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
149
+ export interface StatefulAuthorizationCall {
150
+ principal: EntityUid;
151
+ action: EntityUid;
152
+ resource: EntityUid;
153
+ context: Context;
154
+ preparsedSchemaName?: string;
155
+ validateRequest?: boolean;
156
+ preparsedPolicySetId: string;
157
+ entities: Entities;
158
+ }
102
159
 
103
- export interface ValidationError {
104
- policyId: string;
105
- error: DetailedError;
160
+ export interface TemplateLink {
161
+ templateId: PolicyId;
162
+ newId: PolicyId;
163
+ values: Record<SlotId, EntityUid>;
106
164
  }
107
165
 
108
- export interface ValidationSettings {
109
- mode: ValidationMode;
166
+ export interface TypeAndId {
167
+ type: string;
168
+ id: string;
110
169
  }
111
170
 
112
171
  export interface ValidationCall {
@@ -115,148 +174,114 @@ export interface ValidationCall {
115
174
  policies: PolicySet;
116
175
  }
117
176
 
118
- export interface ContextParsingCall {
119
- context: Context;
120
- schema?: Schema | null;
121
- action?: EntityUid | null;
177
+ export interface ValidationError {
178
+ policyId: string;
179
+ error: DetailedError;
122
180
  }
123
181
 
124
- export interface EntitiesParsingCall {
125
- entities: Entities;
126
- schema?: Schema | null;
182
+ export interface ValidationSettings {
183
+ mode: ValidationMode;
127
184
  }
128
185
 
129
- export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
186
+ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
130
187
 
131
- export type PolicyId = string;
188
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
132
189
 
133
- export type SlotId = string;
190
+ export type Annotation = SmolStr;
134
191
 
135
- export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
192
+ export type Annotations = Record<string, Annotation>;
136
193
 
137
- export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
194
+ export type AnyId = SmolStr;
138
195
 
139
- export type PolicySetTextToPartsAnswer = { type: "success"; policies: string[]; policy_templates: string[] } | { type: "failure"; errors: DetailedError[] };
196
+ export type AttributesOrContext<N> = Type<N>;
140
197
 
141
- export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
198
+ export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
142
199
 
143
- export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
200
+ export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArgs } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
144
201
 
145
- export type Annotation = SmolStr;
202
+ export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
146
203
 
147
- export type Annotations = Record<string, Annotation>;
204
+ export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
148
205
 
149
- export interface EntityJson {
150
- uid: EntityUidJson;
151
- attrs: Record<string, CedarValueJson>;
152
- parents: EntityUidJson[];
153
- tags?: Record<string, CedarValueJson>;
154
- }
206
+ export type CommonTypeId = string;
155
207
 
156
- export type Var = "principal" | "action" | "resource" | "context";
208
+ export type Context = Record<string, CedarValueJson>;
157
209
 
158
210
  export type Decision = "allow" | "deny";
159
211
 
160
- export type AnyId = SmolStr;
212
+ export type Effect = "permit" | "forbid";
161
213
 
162
- export type UnreservedId = string;
214
+ export type Entities = Array<EntityJson>;
163
215
 
164
- 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 };
216
+ export type EntityTypeKind<N> = StandardEntityType<N> | { enum: NonEmpty<SmolStr> };
165
217
 
166
- export type Type<N> = ({} & TypeVariant<N>) | { type: N };
218
+ export type EntityUid = EntityUidJson;
167
219
 
168
- export interface RecordType<N> {
169
- attributes: Record<SmolStr, TypeOfAttribute<N>>;
170
- additionalAttributes?: boolean;
171
- }
220
+ export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
172
221
 
173
- export type CommonTypeId = string;
222
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
174
223
 
175
- export type AttributesOrContext<N> = Type<N>;
224
+ export type Expr = ExprNoExt | ExtFuncCall;
176
225
 
177
- export interface ActionEntityUID<N> {
178
- id: SmolStr;
179
- type?: N;
180
- }
226
+ export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { isEmpty: { arg: Expr } } | { getTag: { left: Expr; right: Expr } } | { hasTag: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: PatternElem[] } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
181
227
 
182
- export interface ActionType<N> {
183
- attributes?: Record<SmolStr, CedarValueJson>;
184
- appliesTo?: ApplySpec<N>;
185
- memberOf?: ActionEntityUID<N>[];
186
- annotations?: Annotations;
187
- }
228
+ export type ExtFuncCall = {} & Record<string, Array<Expr>>;
188
229
 
189
- export type SchemaJson<N> = Record<string, NamespaceDefinition<N>>;
230
+ export type FnAndArgs = { fn: string; arg: CedarValueJson } | { fn: string; args: CedarValueJson[] };
190
231
 
191
- export type EntityTypeKind<N> = StandardEntityType<N> | { enum: NonEmpty<SmolStr> };
232
+ export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
192
233
 
193
- export interface NamespaceDefinition<N> {
194
- commonTypes?: Record<CommonTypeId, CommonType<N>>;
195
- entityTypes: Record<UnreservedId, EntityType<N>>;
196
- actions: Record<SmolStr, ActionType<N>>;
197
- annotations?: Annotations;
198
- }
234
+ export type GetValidRequestEnvsResult = { type: "success"; principals: string[]; actions: string[]; resources: string[] } | { type: "failure"; error: string };
199
235
 
200
- export interface StandardEntityType<N> {
201
- memberOfTypes?: N[];
202
- shape?: AttributesOrContext<N>;
203
- tags?: Type<N>;
204
- }
236
+ export type PartialAuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "residuals"; response: ResidualResponse; warnings: DetailedError[] };
205
237
 
206
- export interface ApplySpec<N> {
207
- resourceTypes: N[];
208
- principalTypes: N[];
209
- context?: AttributesOrContext<N>;
210
- }
238
+ export type PatternElem = "Wildcard" | { Literal: SmolStr };
211
239
 
212
- export type Effect = "permit" | "forbid";
240
+ export type Policy = string | PolicyJson;
213
241
 
214
- export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
242
+ export type PolicyId = string;
215
243
 
216
- export interface PrincipalOrResourceIsConstraint {
217
- entity_type: string;
218
- in?: PrincipalOrResourceInConstraint;
219
- }
244
+ export type PolicySetTextToPartsAnswer = { type: "success"; policies: string[]; policy_templates: string[] } | { type: "failure"; errors: DetailedError[] };
220
245
 
221
- export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
246
+ export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
222
247
 
223
- export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
248
+ export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
249
+
250
+ export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
224
251
 
225
252
  export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
226
253
 
227
254
  export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
228
255
 
229
- export type EqConstraint = { entity: EntityUidJson } | { slot: string };
256
+ export type Schema = string | SchemaJson<string>;
230
257
 
231
- export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
258
+ export type SchemaJson<N> = Record<string, NamespaceDefinition<N>>;
232
259
 
233
- export interface PolicyJson {
234
- effect: Effect;
235
- principal: PrincipalConstraint;
236
- action: ActionConstraint;
237
- resource: ResourceConstraint;
238
- conditions: Clause[];
239
- annotations?: Annotations;
240
- }
260
+ export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
241
261
 
242
- export type ExtFuncCall = {} & Record<string, Array<Expr>>;
262
+ export type SchemaToJsonWithResolvedTypesAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
243
263
 
244
- export type Expr = ExprNoExt | ExtFuncCall;
264
+ export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
245
265
 
246
- export type PatternElem = "Wildcard" | { Literal: SmolStr };
266
+ export type Severity = "advice" | "warning" | "error";
247
267
 
248
- export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { isEmpty: { arg: Expr } } | { getTag: { left: Expr; right: Expr } } | { hasTag: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: PatternElem[] } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
268
+ export type SlotId = string;
249
269
 
250
- export interface TypeAndId {
251
- type: string;
252
- id: string;
253
- }
270
+ export type StaticPolicySet = string | Policy[] | Record<PolicyId, Policy>;
254
271
 
255
- export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArgs } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
272
+ export type Template = string | PolicyJson;
256
273
 
257
- export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
274
+ export type Type<N> = ({} & TypeVariant<N>) | { type: N };
258
275
 
259
- export type FnAndArgs = { fn: string; arg: CedarValueJson } | { fn: string; args: CedarValueJson[] };
276
+ 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 };
277
+
278
+ export type UnreservedId = string;
279
+
280
+ export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
281
+
282
+ export type ValidationMode = "strict";
283
+
284
+ export type Var = "principal" | "action" | "resource" | "context";
260
285
 
261
286
 
262
287
  /**
@@ -308,6 +333,12 @@ export function getValidRequestEnvsTemplate(t: Template, s: Schema): GetValidReq
308
333
  */
309
334
  export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
310
335
 
336
+ /**
337
+ * Basic interface for partial evaluation, using [`AuthorizationCall`] and
338
+ * [`PartialAuthorizationAnswer`] types
339
+ */
340
+ export function isAuthorizedPartial(call: PartialAuthorizationCall): PartialAuthorizationAnswer;
341
+
311
342
  /**
312
343
  * Takes a `PolicySet` represented as string and return the policies
313
344
  * and templates split into vecs and sorted by id.
@@ -347,6 +378,16 @@ export function preparseSchema(schema_name: string, schema: Schema): CheckParseA
347
378
  */
348
379
  export function schemaToJson(schema: Schema): SchemaToJsonAnswer;
349
380
 
381
+ /**
382
+ * Convert a Cedar schema string to JSON format with resolved types.
383
+ *
384
+ * This function resolves ambiguous "`EntityOrCommon`" types to their specific
385
+ * Entity or `CommonType` classifications using the schema's type definitions.
386
+ * This is primarily meant to be used when working with schemas programmatically,
387
+ * for example when creating a schema building UI.
388
+ */
389
+ export function schemaToJsonWithResolvedTypes(schema_str: string): SchemaToJsonWithResolvedTypesAnswer;
390
+
350
391
  /**
351
392
  * Return the Cedar (textual) representation of a schema.
352
393
  */
package/esm/cedar_wasm.js CHANGED
@@ -1,5 +1,9 @@
1
+ /* @ts-self-types="./cedar_wasm.d.ts" */
2
+
1
3
  import * as wasm from "./cedar_wasm_bg.wasm";
2
- export * from "./cedar_wasm_bg.js";
3
4
  import { __wbg_set_wasm } from "./cedar_wasm_bg.js";
4
5
  __wbg_set_wasm(wasm);
5
6
  wasm.__wbindgen_start();
7
+ export {
8
+ checkParseContext, checkParseEntities, checkParsePolicySet, checkParseSchema, formatPolicies, getCedarLangVersion, getCedarSDKVersion, getCedarVersion, getValidRequestEnvsPolicy, getValidRequestEnvsTemplate, isAuthorized, isAuthorizedPartial, policySetTextToParts, policyToJson, policyToText, preparsePolicySet, preparseSchema, schemaToJson, schemaToJsonWithResolvedTypes, schemaToText, statefulIsAuthorized, templateToJson, templateToText, validate
9
+ } from "./cedar_wasm_bg.js";