@cedar-policy/cedar-wasm 3.3.0 → 4.0.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,79 +1,180 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * @param {string} json_str
5
- * @returns {JsonToPolicyResult}
4
+ * Get valid request environment
5
+ * @param {Template} t
6
+ * @param {Schema} s
7
+ * @returns {GetValidRequestEnvsResult}
6
8
  */
7
- export function policyTextFromJson(json_str: string): JsonToPolicyResult;
9
+ export function getValidRequestEnvsTemplate(t: Template, s: Schema): GetValidRequestEnvsResult;
8
10
  /**
9
- * @param {string} cedar_str
10
- * @returns {PolicyToJsonResult}
11
+ * Get valid request environment
12
+ * @param {Policy} t
13
+ * @param {Schema} s
14
+ * @returns {GetValidRequestEnvsResult}
11
15
  */
12
- export function policyTextToJson(cedar_str: string): PolicyToJsonResult;
16
+ export function getValidRequestEnvsPolicy(t: Policy, s: Schema): GetValidRequestEnvsResult;
13
17
  /**
14
- * @param {string} input_policies_str
15
- * @returns {CheckParsePolicySetResult}
18
+ * @returns {string}
16
19
  */
17
- export function checkParsePolicySet(input_policies_str: string): CheckParsePolicySetResult;
20
+ export function getCedarVersion(): string;
18
21
  /**
19
- * @param {string} template_str
20
- * @returns {CheckParseTemplateResult}
22
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
23
+ * @param {AuthorizationCall} call
24
+ * @returns {AuthorizationAnswer}
21
25
  */
22
- export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
26
+ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
23
27
  /**
24
- * @param {string} policies_str
25
- * @param {number} line_width
26
- * @param {number} indent_width
27
- * @returns {FormattingResult}
28
+ * Parse a policy set and optionally validate it against a provided schema
29
+ *
30
+ * This is the basic validator interface, using [`ValidationCall`] and
31
+ * [`ValidationAnswer`] types
32
+ * @param {ValidationCall} call
33
+ * @returns {ValidationAnswer}
28
34
  */
29
- export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
35
+ export function validate(call: ValidationCall): ValidationAnswer;
30
36
  /**
31
- * @param {string} input_schema
32
- * @returns {CheckParseResult}
37
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
38
+ * @param {FormattingCall} call
39
+ * @returns {FormattingAnswer}
33
40
  */
34
- export function checkParseSchema(input_schema: string): CheckParseResult;
41
+ export function formatPolicies(call: FormattingCall): FormattingAnswer;
35
42
  /**
36
- * @param {string} entities_str
37
- * @param {string} schema_str
38
- * @returns {CheckParseResult}
43
+ * Return the Cedar (textual) representation of a policy.
44
+ * @param {Policy} policy
45
+ * @returns {PolicyToTextAnswer}
39
46
  */
40
- export function checkParseEntities(entities_str: string, schema_str: string): CheckParseResult;
47
+ export function policyToText(policy: Policy): PolicyToTextAnswer;
41
48
  /**
42
- * @param {string} context_str
43
- * @param {string} action_str
44
- * @param {string} schema_str
45
- * @returns {CheckParseResult}
49
+ * Return the Cedar (textual) representation of a template.
50
+ * @param {Template} template
51
+ * @returns {PolicyToTextAnswer}
46
52
  */
47
- export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
53
+ export function templateToText(template: Template): PolicyToTextAnswer;
48
54
  /**
49
- * @returns {string}
55
+ * Return the JSON representation of a policy.
56
+ * @param {Policy} policy
57
+ * @returns {PolicyToJsonAnswer}
50
58
  */
51
- export function getCedarVersion(): string;
59
+ export function policyToJson(policy: Policy): PolicyToJsonAnswer;
52
60
  /**
53
- * @param {AuthorizationCall} call
54
- * @returns {AuthorizationAnswer}
61
+ * Return the JSON representation of a template.
62
+ * @param {Template} template
63
+ * @returns {PolicyToJsonAnswer}
55
64
  */
56
- export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
65
+ export function templateToJson(template: Template): PolicyToJsonAnswer;
57
66
  /**
58
- * @param {ValidationCall} call
59
- * @returns {ValidationAnswer}
67
+ * Return the Cedar (textual) representation of a schema.
68
+ * @param {Schema} schema
69
+ * @returns {SchemaToTextAnswer}
60
70
  */
61
- export function validate(call: ValidationCall): ValidationAnswer;
62
- export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
71
+ export function schemaToText(schema: Schema): SchemaToTextAnswer;
72
+ /**
73
+ * Return the JSON representation of a schema.
74
+ * @param {Schema} schema
75
+ * @returns {SchemaToJsonAnswer}
76
+ */
77
+ export function schemaToJson(schema: Schema): SchemaToJsonAnswer;
78
+ /**
79
+ * Check whether a policy set successfully parses.
80
+ * @param {PolicySet} policies
81
+ * @returns {CheckParseAnswer}
82
+ */
83
+ export function checkParsePolicySet(policies: PolicySet): CheckParseAnswer;
84
+ /**
85
+ * Check whether a schema successfully parses.
86
+ * @param {Schema} schema
87
+ * @returns {CheckParseAnswer}
88
+ */
89
+ export function checkParseSchema(schema: Schema): CheckParseAnswer;
90
+ /**
91
+ * Check whether a set of entities successfully parses.
92
+ * @param {EntitiesParsingCall} call
93
+ * @returns {CheckParseAnswer}
94
+ */
95
+ export function checkParseEntities(call: EntitiesParsingCall): CheckParseAnswer;
96
+ /**
97
+ * Check whether a context successfully parses.
98
+ * @param {ContextParsingCall} call
99
+ * @returns {CheckParseAnswer}
100
+ */
101
+ export function checkParseContext(call: ContextParsingCall): CheckParseAnswer;
102
+ export type GetValidRequestEnvsResult = { type: "success"; principals: string[]; actions: string[]; resources: string[] } | { type: "failure"; error: string };
103
+
104
+ export type SlotId = string;
105
+
106
+ export type PolicyId = string;
107
+
108
+ export interface Response {
109
+ decision: Decision;
110
+ diagnostics: Diagnostics;
111
+ }
112
+
113
+ export interface Diagnostics {
114
+ reason: PolicyId[];
115
+ errors: AuthorizationError[];
116
+ }
63
117
 
64
- export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
118
+ export interface AuthorizationError {
119
+ policyId: string;
120
+ error: DetailedError;
121
+ }
65
122
 
66
- export type CheckParsePolicySetResult = { type: "success"; policies: number; templates: number } | { type: "error"; errors: string[] };
123
+ export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
67
124
 
68
- export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
125
+ export interface AuthorizationCall {
126
+ principal: EntityUid;
127
+ action: EntityUid;
128
+ resource: EntityUid;
129
+ context: Context;
130
+ schema?: Schema;
131
+ validateRequest?: boolean;
132
+ policies: PolicySet;
133
+ entities: Entities;
134
+ }
69
135
 
70
- export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
136
+ export interface ValidationCall {
137
+ validationSettings?: ValidationSettings;
138
+ schema: Schema;
139
+ policies: PolicySet;
140
+ }
71
141
 
72
- export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
142
+ export interface ValidationSettings {
143
+ mode: ValidationMode;
144
+ }
73
145
 
74
- export type Schema = { human: string } | { json: SchemaJson };
146
+ export interface ValidationError {
147
+ policyId: string;
148
+ error: DetailedError;
149
+ }
150
+
151
+ export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
152
+
153
+ export type Schema = string | SchemaJson<string>;
75
154
 
76
- export type PolicySet = string | Record<string, string>;
155
+ export interface PolicySet {
156
+ staticPolicies?: StaticPolicySet;
157
+ templates?: Record<PolicyId, Template>;
158
+ templateLinks?: TemplateLink[];
159
+ }
160
+
161
+ export interface TemplateLink {
162
+ templateId: PolicyId;
163
+ newId: PolicyId;
164
+ values: Record<SlotId, EntityUid>;
165
+ }
166
+
167
+ export type StaticPolicySet = string | Policy[] | Record<PolicyId, Policy>;
168
+
169
+ export type Template = string | PolicyJson;
170
+
171
+ export type Policy = string | PolicyJson;
172
+
173
+ export type Entities = Array<EntityJson>;
174
+
175
+ export type Context = Record<string, CedarValueJson>;
176
+
177
+ export type EntityUid = EntityUidJson;
77
178
 
78
179
  export interface SourceLocation {
79
180
  start: number;
@@ -96,112 +197,114 @@ export interface DetailedError {
96
197
  related?: DetailedError[];
97
198
  }
98
199
 
99
- export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
200
+ export type ValidationMode = "strict";
100
201
 
101
- export interface ValidationError {
102
- policyId: SmolStr;
103
- error: DetailedError;
202
+ export interface FormattingCall {
203
+ policyText: string;
204
+ lineWidth?: number;
205
+ indentWidth?: number;
104
206
  }
105
207
 
106
- export type ValidationEnabled = "on" | "off";
208
+ export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
107
209
 
108
- export interface ValidationSettings {
109
- enabled: ValidationEnabled;
110
- }
210
+ export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
111
211
 
112
- export interface ValidationCall {
113
- validationSettings?: ValidationSettings;
114
- schema: Schema;
115
- policySet: PolicySet;
116
- }
212
+ export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
117
213
 
118
- export interface RecvdSlice {
119
- policies: PolicySet;
120
- entities: Array<EntityJson>;
121
- templates?: Record<string, string> | null;
122
- templateInstantiations: TemplateLink[] | null;
123
- }
214
+ export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
124
215
 
125
- export type Links = Link[];
216
+ export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
126
217
 
127
- export interface TemplateLink {
128
- templateId: string;
129
- resultPolicyId: string;
130
- instantiations: Links;
131
- }
218
+ export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
132
219
 
133
- export interface Link {
134
- slot: string;
135
- value: EntityUIDStrings;
220
+ export interface EntitiesParsingCall {
221
+ entities: Entities;
222
+ schema?: Schema | null;
136
223
  }
137
224
 
138
- export interface EntityUIDStrings {
139
- ty: string;
140
- eid: string;
225
+ export interface ContextParsingCall {
226
+ context: Context;
227
+ schema?: Schema | null;
228
+ action?: EntityUid | null;
141
229
  }
142
230
 
143
- export interface AuthorizationCall {
144
- principal: {type: string, id: string};
145
- action: {type: string, id: string};
146
- resource: {type: string, id: string};
147
- context: Record<string, CedarValueJson>;
148
- schema?: Schema;
149
- enableRequestValidation?: boolean;
150
- slice: RecvdSlice;
231
+ export type RecordAttributeType<N> = { required?: boolean } & Type<N>;
232
+
233
+ export type EntityAttributeType<N> = { required?: boolean } & EntityAttributeTypeInternal<N>;
234
+
235
+ export type EntityAttributeTypeInternal<N> = { Type: Type<N> } | { EAMap: { value_type: Type<N> } };
236
+
237
+ export type TypeVariant<N> = { type: "String" } | { type: "Long" } | { type: "Boolean" } | { type: "Set"; element: Type<N> } | ({ type: "Record" } & RecordType<RecordAttributeType<N>>) | { type: "Entity"; name: N } | { type: "EntityOrCommon"; name: N } | { type: "Extension"; name: UnreservedId };
238
+
239
+ export interface RecordType<V> {
240
+ attributes: Record<SmolStr, V>;
241
+ additionalAttributes?: boolean;
151
242
  }
152
243
 
153
- export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
244
+ export type Type<N> = TypeVariant<N> | { type: N };
154
245
 
155
- export interface AuthorizationError {
156
- policyId: SmolStr;
157
- error: DetailedError;
246
+ export interface ActionEntityUID<N> {
247
+ id: SmolStr;
248
+ type?: N;
158
249
  }
159
250
 
160
- export interface Diagnostics {
161
- reason: Set<String>;
162
- errors: AuthorizationError[];
251
+ export interface ApplySpec<N> {
252
+ resourceTypes: N[];
253
+ principalTypes: N[];
254
+ context?: RecordOrContextAttributes<N>;
163
255
  }
164
256
 
165
- export interface Response {
166
- decision: Decision;
167
- diagnostics: Diagnostics;
257
+ export interface ActionType<N> {
258
+ attributes?: Record<SmolStr, CedarValueJson>;
259
+ appliesTo?: ApplySpec<N>;
260
+ memberOf?: ActionEntityUID<N>[];
168
261
  }
169
262
 
170
- export type SchemaTypeVariant = { type: "String" } | { type: "Long" } | { type: "Boolean" } | { type: "Set"; element: SchemaType } | { type: "Record"; attributes: Record<SmolStr, TypeOfAttribute>; additionalAttributes: boolean } | { type: "Entity"; name: Name } | { type: "Extension"; name: Id };
263
+ export interface EntityAttributesInternal<N> extends RecordType<EntityAttributeType<N>> {
264
+ type: "Record";
265
+ }
171
266
 
172
- export type SchemaType = SchemaTypeVariant | { type: Name };
267
+ export type EntityAttributes<N> = RecordOrContextAttributes<N> | EntityAttributesInternal<N>;
173
268
 
174
- export interface ActionEntityUID {
175
- id: SmolStr;
176
- type?: Name;
177
- }
269
+ export type RecordOrContextAttributes<N> = Type<N>;
178
270
 
179
- export interface ApplySpec {
180
- resourceTypes?: Name[];
181
- principalTypes?: Name[];
182
- context?: AttributesOrContext;
271
+ export interface EntityType<N> {
272
+ memberOfTypes?: N[];
273
+ shape?: EntityAttributes<N>;
183
274
  }
184
275
 
185
- export interface ActionType {
186
- attributes?: Record<SmolStr, CedarValueJson>;
187
- appliesTo?: ApplySpec;
188
- memberOf?: ActionEntityUID[];
276
+ export interface NamespaceDefinition<N> {
277
+ commonTypes?: Record<CommonTypeId, Type<N>>;
278
+ entityTypes: Record<UnreservedId, EntityType<N>>;
279
+ actions: Record<SmolStr, ActionType<N>>;
189
280
  }
190
281
 
191
- export type AttributesOrContext = SchemaType;
282
+ export type CommonTypeId = string;
283
+
284
+ export type SchemaJson<N> = Record<string, NamespaceDefinition<N>>;
285
+
286
+ export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
192
287
 
193
- export interface EntityType {
194
- memberOfTypes?: Name[];
195
- shape?: AttributesOrContext;
288
+ export interface PolicyJson {
289
+ effect: Effect;
290
+ principal: PrincipalConstraint;
291
+ action: ActionConstraint;
292
+ resource: ResourceConstraint;
293
+ conditions: Clause[];
294
+ annotations?: Record<string, string>;
196
295
  }
197
296
 
198
- export interface NamespaceDefinition {
199
- commonTypes?: Record<Id, SchemaType>;
200
- entityTypes: Record<Id, EntityType>;
201
- actions: Record<SmolStr, ActionType>;
297
+ export type Decision = "allow" | "deny";
298
+
299
+ export interface EntityJson {
300
+ uid: EntityUidJson;
301
+ attrs: Record<string, CedarValueJson>;
302
+ parents: EntityUidJson[];
202
303
  }
203
304
 
204
- export type SchemaJson = Record<string, NamespaceDefinition>;
305
+ export type UnreservedId = string;
306
+
307
+ export type Var = "principal" | "action" | "resource" | "context";
205
308
 
206
309
  export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
310
 
@@ -220,7 +323,7 @@ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | (
220
323
 
221
324
  export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
222
325
 
223
- export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
326
+ export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
224
327
 
225
328
  export interface FnAndArg {
226
329
  fn: string;
@@ -232,39 +335,16 @@ export interface TypeAndId {
232
335
  id: string;
233
336
  }
234
337
 
235
- export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
338
+ export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
236
339
 
237
340
  export type ExtFuncCall = {} & Record<string, Array<Expr>>;
238
341
 
239
- export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: 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 } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
342
+ 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 } } | { ".": { 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> };
240
343
 
241
- export type Expr = ExprNoExt | ExtFuncCall;
344
+ export type PatternElem = "Wildcard" | { Literal: SmolStr };
242
345
 
243
- export type Decision = "Allow" | "Deny";
346
+ export type Expr = ExprNoExt | ExtFuncCall;
244
347
 
245
348
  export type Effect = "permit" | "forbid";
246
349
 
247
- export interface EntityJson {
248
- uid: EntityUidJson;
249
- attrs: Record<string, CedarValueJson>;
250
- parents: EntityUidJson[];
251
- }
252
-
253
- export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
254
-
255
- export interface Policy {
256
- effect: Effect;
257
- principal: PrincipalConstraint;
258
- action: ActionConstraint;
259
- resource: ResourceConstraint;
260
- conditions: Clause[];
261
- annotations?: Record<string, string>;
262
- }
263
-
264
- export type Var = "principal" | "action" | "resource" | "context";
265
-
266
350
  type SmolStr = string;
267
- type Name = string;
268
- type Id = string;
269
- export type TypeOfAttribute = SchemaType & { required?: boolean };
270
- export type Context = Record<string, CedarValueJson>;