@cedar-policy/cedar-wasm 3.4.1 → 4.1.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.
@@ -1,150 +1,205 @@
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
+ * Check whether a policy set successfully parses.
38
+ * @param {PolicySet} policies
39
+ * @returns {CheckParseAnswer}
33
40
  */
34
- export function checkParseSchema(input_schema: string): CheckParseResult;
41
+ export function checkParsePolicySet(policies: PolicySet): CheckParseAnswer;
35
42
  /**
36
- * @param {string} entities_str
37
- * @param {string} schema_str
38
- * @returns {CheckParseResult}
43
+ * Check whether a schema successfully parses.
44
+ * @param {Schema} schema
45
+ * @returns {CheckParseAnswer}
39
46
  */
40
- export function checkParseEntities(entities_str: string, schema_str: string): CheckParseResult;
47
+ export function checkParseSchema(schema: Schema): CheckParseAnswer;
41
48
  /**
42
- * @param {string} context_str
43
- * @param {string} action_str
44
- * @param {string} schema_str
45
- * @returns {CheckParseResult}
49
+ * Check whether a set of entities successfully parses.
50
+ * @param {EntitiesParsingCall} call
51
+ * @returns {CheckParseAnswer}
46
52
  */
47
- export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
53
+ export function checkParseEntities(call: EntitiesParsingCall): CheckParseAnswer;
48
54
  /**
49
- * @param {AuthorizationCall} call
50
- * @returns {AuthorizationAnswer}
55
+ * Check whether a context successfully parses.
56
+ * @param {ContextParsingCall} call
57
+ * @returns {CheckParseAnswer}
51
58
  */
52
- export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
59
+ export function checkParseContext(call: ContextParsingCall): CheckParseAnswer;
53
60
  /**
54
- * @param {ValidationCall} call
55
- * @returns {ValidationAnswer}
61
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
62
+ * @param {FormattingCall} call
63
+ * @returns {FormattingAnswer}
56
64
  */
57
- export function validate(call: ValidationCall): ValidationAnswer;
65
+ export function formatPolicies(call: FormattingCall): FormattingAnswer;
58
66
  /**
59
- * @returns {string}
67
+ * Return the Cedar (textual) representation of a policy.
68
+ * @param {Policy} policy
69
+ * @returns {PolicyToTextAnswer}
60
70
  */
61
- export function getCedarVersion(): string;
62
- export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
63
-
64
- export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
71
+ export function policyToText(policy: Policy): PolicyToTextAnswer;
72
+ /**
73
+ * Return the Cedar (textual) representation of a template.
74
+ * @param {Template} template
75
+ * @returns {PolicyToTextAnswer}
76
+ */
77
+ export function templateToText(template: Template): PolicyToTextAnswer;
78
+ /**
79
+ * Return the JSON representation of a policy.
80
+ * @param {Policy} policy
81
+ * @returns {PolicyToJsonAnswer}
82
+ */
83
+ export function policyToJson(policy: Policy): PolicyToJsonAnswer;
84
+ /**
85
+ * Return the JSON representation of a template.
86
+ * @param {Template} template
87
+ * @returns {PolicyToJsonAnswer}
88
+ */
89
+ export function templateToJson(template: Template): PolicyToJsonAnswer;
90
+ /**
91
+ * Return the Cedar (textual) representation of a schema.
92
+ * @param {Schema} schema
93
+ * @returns {SchemaToTextAnswer}
94
+ */
95
+ export function schemaToText(schema: Schema): SchemaToTextAnswer;
96
+ /**
97
+ * Return the JSON representation of a schema.
98
+ * @param {Schema} schema
99
+ * @returns {SchemaToJsonAnswer}
100
+ */
101
+ export function schemaToJson(schema: Schema): SchemaToJsonAnswer;
102
+ export type GetValidRequestEnvsResult = { type: "success"; principals: string[]; actions: string[]; resources: string[] } | { type: "failure"; error: string };
65
103
 
66
- export type CheckParsePolicySetResult = { type: "success"; policies: number; templates: number } | { type: "error"; errors: string[] };
104
+ export interface Response {
105
+ decision: Decision;
106
+ diagnostics: Diagnostics;
107
+ }
67
108
 
68
- export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
109
+ export interface Diagnostics {
110
+ reason: PolicyId[];
111
+ errors: AuthorizationError[];
112
+ }
69
113
 
70
- export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
114
+ export interface AuthorizationError {
115
+ policyId: string;
116
+ error: DetailedError;
117
+ }
71
118
 
72
- export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
119
+ export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
73
120
 
74
- export interface RecvdSlice {
121
+ export interface AuthorizationCall {
122
+ principal: EntityUid;
123
+ action: EntityUid;
124
+ resource: EntityUid;
125
+ context: Context;
126
+ schema?: Schema;
127
+ validateRequest?: boolean;
75
128
  policies: PolicySet;
76
- entities: Array<EntityJson>;
77
- templates?: Record<string, string> | null;
78
- templateInstantiations: TemplateLink[] | null;
129
+ entities: Entities;
79
130
  }
80
131
 
81
- export type Links = Link[];
82
-
83
- export interface TemplateLink {
84
- templateId: string;
85
- resultPolicyId: string;
86
- instantiations: Links;
132
+ export interface ValidationCall {
133
+ validationSettings?: ValidationSettings;
134
+ schema: Schema;
135
+ policies: PolicySet;
87
136
  }
88
137
 
89
- export interface Link {
90
- slot: string;
91
- value: EntityUIDStrings;
138
+ export interface ValidationSettings {
139
+ mode: ValidationMode;
92
140
  }
93
141
 
94
- export interface EntityUIDStrings {
95
- ty: string;
96
- eid: string;
142
+ export interface ValidationError {
143
+ policyId: string;
144
+ error: DetailedError;
97
145
  }
98
146
 
99
- export interface AuthorizationCall {
100
- principal: {type: string, id: string};
101
- action: {type: string, id: string};
102
- resource: {type: string, id: string};
103
- context: Record<string, CedarValueJson>;
104
- schema?: Schema;
105
- enableRequestValidation?: boolean;
106
- slice: RecvdSlice;
107
- }
147
+ export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
108
148
 
109
- export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
149
+ export type CheckParseAnswer = { type: "success" } | { type: "failure"; errors: DetailedError[] };
110
150
 
111
- export interface AuthorizationError {
112
- policyId: SmolStr;
113
- error: DetailedError;
151
+ export interface EntitiesParsingCall {
152
+ entities: Entities;
153
+ schema?: Schema | null;
114
154
  }
115
155
 
116
- export interface Diagnostics {
117
- reason: Set<String>;
118
- errors: AuthorizationError[];
156
+ export interface ContextParsingCall {
157
+ context: Context;
158
+ schema?: Schema | null;
159
+ action?: EntityUid | null;
119
160
  }
120
161
 
121
- export interface Response {
122
- decision: Decision;
123
- diagnostics: Diagnostics;
162
+ export interface FormattingCall {
163
+ policyText: string;
164
+ lineWidth?: number;
165
+ indentWidth?: number;
124
166
  }
125
167
 
126
- export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
168
+ export type FormattingAnswer = { type: "failure"; errors: DetailedError[] } | { type: "success"; formatted_policy: string };
127
169
 
128
- export interface ValidationError {
129
- policyId: SmolStr;
130
- error: DetailedError;
131
- }
170
+ export type PolicyToTextAnswer = { type: "success"; text: string } | { type: "failure"; errors: DetailedError[] };
132
171
 
133
- export type ValidationEnabled = "on" | "off";
172
+ export type PolicyToJsonAnswer = { type: "success"; json: PolicyJson } | { type: "failure"; errors: DetailedError[] };
134
173
 
135
- export interface ValidationSettings {
136
- enabled: ValidationEnabled;
174
+ export type SchemaToTextAnswer = { type: "success"; text: string; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
175
+
176
+ export type SchemaToJsonAnswer = { type: "success"; json: SchemaJson<string>; warnings: DetailedError[] } | { type: "failure"; errors: DetailedError[] };
177
+
178
+ export type Schema = string | SchemaJson<string>;
179
+
180
+ export interface PolicySet {
181
+ staticPolicies?: StaticPolicySet;
182
+ templates?: Record<PolicyId, Template>;
183
+ templateLinks?: TemplateLink[];
137
184
  }
138
185
 
139
- export interface ValidationCall {
140
- validationSettings?: ValidationSettings;
141
- schema: Schema;
142
- policySet: PolicySet;
186
+ export interface TemplateLink {
187
+ templateId: PolicyId;
188
+ newId: PolicyId;
189
+ values: Record<SlotId, EntityUid>;
143
190
  }
144
191
 
145
- export type Schema = { human: string } | { json: SchemaJson };
192
+ export type StaticPolicySet = string | Policy[] | Record<PolicyId, Policy>;
193
+
194
+ export type Template = string | PolicyJson;
195
+
196
+ export type Policy = string | PolicyJson;
197
+
198
+ export type Entities = Array<EntityJson>;
146
199
 
147
- export type PolicySet = string | Record<string, string>;
200
+ export type Context = Record<string, CedarValueJson>;
201
+
202
+ export type EntityUid = EntityUidJson;
148
203
 
149
204
  export interface SourceLocation {
150
205
  start: number;
@@ -167,41 +222,77 @@ export interface DetailedError {
167
222
  related?: DetailedError[];
168
223
  }
169
224
 
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 };
225
+ export type ValidationMode = "strict";
226
+
227
+ export type SlotId = string;
228
+
229
+ export type PolicyId = string;
171
230
 
172
- export type SchemaType = SchemaTypeVariant | { type: Name };
231
+ 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 };
173
232
 
174
- export interface ActionEntityUID {
233
+ export interface RecordType<N> {
234
+ attributes: Record<SmolStr, TypeOfAttribute<N>>;
235
+ additionalAttributes?: boolean;
236
+ }
237
+
238
+ export type Type<N> = TypeVariant<N> | { type: N };
239
+
240
+ export interface ActionEntityUID<N> {
175
241
  id: SmolStr;
176
- type?: Name;
242
+ type?: N;
177
243
  }
178
244
 
179
- export interface ApplySpec {
180
- resourceTypes?: Name[];
181
- principalTypes?: Name[];
182
- context?: AttributesOrContext;
245
+ export interface ApplySpec<N> {
246
+ resourceTypes: N[];
247
+ principalTypes: N[];
248
+ context?: AttributesOrContext<N>;
183
249
  }
184
250
 
185
- export interface ActionType {
251
+ export interface ActionType<N> {
186
252
  attributes?: Record<SmolStr, CedarValueJson>;
187
- appliesTo?: ApplySpec;
188
- memberOf?: ActionEntityUID[];
253
+ appliesTo?: ApplySpec<N>;
254
+ memberOf?: ActionEntityUID<N>[];
189
255
  }
190
256
 
191
- export type AttributesOrContext = SchemaType;
257
+ export type AttributesOrContext<N> = Type<N>;
192
258
 
193
- export interface EntityType {
194
- memberOfTypes?: Name[];
195
- shape?: AttributesOrContext;
259
+ export interface EntityType<N> {
260
+ memberOfTypes?: N[];
261
+ shape?: AttributesOrContext<N>;
262
+ tags?: Type<N>;
196
263
  }
197
264
 
198
- export interface NamespaceDefinition {
199
- commonTypes?: Record<Id, SchemaType>;
200
- entityTypes: Record<Id, EntityType>;
201
- actions: Record<SmolStr, ActionType>;
265
+ export interface NamespaceDefinition<N> {
266
+ commonTypes?: Record<CommonTypeId, Type<N>>;
267
+ entityTypes: Record<UnreservedId, EntityType<N>>;
268
+ actions: Record<SmolStr, ActionType<N>>;
202
269
  }
203
270
 
204
- export type SchemaJson = Record<string, NamespaceDefinition>;
271
+ export type CommonTypeId = string;
272
+
273
+ export type SchemaJson<N> = Record<string, NamespaceDefinition<N>>;
274
+
275
+ export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
276
+
277
+ export interface PolicyJson {
278
+ effect: Effect;
279
+ principal: PrincipalConstraint;
280
+ action: ActionConstraint;
281
+ resource: ResourceConstraint;
282
+ conditions: Clause[];
283
+ annotations?: Record<string, string>;
284
+ }
285
+
286
+ export interface EntityJson {
287
+ uid: EntityUidJson;
288
+ attrs: Record<string, CedarValueJson>;
289
+ parents: EntityUidJson[];
290
+ tags?: Record<string, CedarValueJson>;
291
+ }
292
+
293
+ export type UnreservedId = string;
294
+
295
+ export type Var = "principal" | "action" | "resource" | "context";
205
296
 
206
297
  export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
298
 
@@ -220,7 +311,9 @@ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | (
220
311
 
221
312
  export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
222
313
 
223
- export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
314
+ export type Decision = "allow" | "deny";
315
+
316
+ export type EntityUidJson = { __entity: TypeAndId } | TypeAndId;
224
317
 
225
318
  export interface FnAndArg {
226
319
  fn: string;
@@ -232,39 +325,17 @@ export interface TypeAndId {
232
325
  id: string;
233
326
  }
234
327
 
235
- export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
236
-
237
- export type Effect = "permit" | "forbid";
238
-
239
- export type Var = "principal" | "action" | "resource" | "context";
240
-
241
- export interface EntityJson {
242
- uid: EntityUidJson;
243
- attrs: Record<string, CedarValueJson>;
244
- parents: EntityUidJson[];
245
- }
246
-
247
- export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
248
-
249
- export interface Policy {
250
- effect: Effect;
251
- principal: PrincipalConstraint;
252
- action: ActionConstraint;
253
- resource: ResourceConstraint;
254
- conditions: Clause[];
255
- annotations?: Record<string, string>;
256
- }
328
+ export type CedarValueJson = { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
257
329
 
258
330
  export type ExtFuncCall = {} & Record<string, Array<Expr>>;
259
331
 
260
- 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> };
332
+ 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 } } | { 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> };
333
+
334
+ export type PatternElem = "Wildcard" | { Literal: SmolStr };
261
335
 
262
336
  export type Expr = ExprNoExt | ExtFuncCall;
263
337
 
264
- export type Decision = "Allow" | "Deny";
338
+ export type Effect = "permit" | "forbid";
265
339
 
266
340
  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>;
341
+ export type TypeOfAttribute<N> = Type<N> & { required?: boolean };