@cedar-policy/cedar-wasm 3.2.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/README.md +135 -0
- package/cedar_wasm.d.ts +270 -0
- package/cedar_wasm.js +4 -0
- package/cedar_wasm_bg.js +307 -0
- package/cedar_wasm_bg.wasm +0 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# cedar-wasm
|
|
2
|
+
|
|
3
|
+
An implementation of various cedar functions to enable developers to write typescript and javascript applications using Cedar and wasm.
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
|
|
7
|
+
Installing is simple, just run `npm i @cedar-policy/cedar-wasm` or install with whatever your favorite package manager is.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Loading in webpack 5:
|
|
11
|
+
|
|
12
|
+
Minimal package.json for webpack including dev server:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
{
|
|
16
|
+
"name": "webpack-ts-tester",
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
"description": "",
|
|
19
|
+
"private": true,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "webpack",
|
|
23
|
+
"dev": "webpack serve"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@cedar-policy/cedar-wasm": "3.2.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"ts-loader": "^9.5.1",
|
|
33
|
+
"typescript": "^5.4.5",
|
|
34
|
+
"webpack": "^5.91.0",
|
|
35
|
+
"webpack-cli": "^5.1.4",
|
|
36
|
+
"webpack-dev-server": "^5.0.4"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Minimal tsconfig:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
{
|
|
45
|
+
"compilerOptions": {
|
|
46
|
+
"outDir": "./dist/",
|
|
47
|
+
"noImplicitAny": true,
|
|
48
|
+
"module": "es2020",
|
|
49
|
+
"target": "es5",
|
|
50
|
+
"jsx": "react",
|
|
51
|
+
"allowJs": true,
|
|
52
|
+
"moduleResolution": "node"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Configure webpack.config.js:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
const path = require('path');
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
mode: 'development', // change this to suit you
|
|
64
|
+
entry: './src/index.ts',
|
|
65
|
+
module: {
|
|
66
|
+
rules: [
|
|
67
|
+
{
|
|
68
|
+
test: /\.tsx?$/,
|
|
69
|
+
use: 'ts-loader',
|
|
70
|
+
exclude: /node_modules/,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
resolve: {
|
|
75
|
+
extensions: ['.tsx', '.ts', '.js'],
|
|
76
|
+
},
|
|
77
|
+
output: {
|
|
78
|
+
filename: 'bundle.js',
|
|
79
|
+
path: path.resolve(__dirname, 'dist'),
|
|
80
|
+
},
|
|
81
|
+
experiments: {
|
|
82
|
+
asyncWebAssembly: true, // enables wasm support in webpack
|
|
83
|
+
},
|
|
84
|
+
devServer: {
|
|
85
|
+
static: {
|
|
86
|
+
directory: path.join(__dirname, 'dist'),
|
|
87
|
+
},
|
|
88
|
+
compress: true,
|
|
89
|
+
port: 8000,
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Finally, load the code from your `index.ts` file. We recommend dynamic imports:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
import('@cedar-policy/cedar-wasm').then(mod => {
|
|
98
|
+
// cache it globally here or invoke functions like mod.getCedarVersion();
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Loading in vite 5:
|
|
105
|
+
|
|
106
|
+
Starting from the vite typescript template, install these two dependencies to enable wasm:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
npm i --save-dev vite-plugin-top-level-await vite-plugin-wasm
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Then add those two plugins to your vite config in `vite.config.js`:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
import wasm from 'vite-plugin-wasm';
|
|
116
|
+
import topLevelAwait from 'vite-plugin-top-level-await';
|
|
117
|
+
import { defineConfig } from 'vite';
|
|
118
|
+
|
|
119
|
+
export default defineConfig({
|
|
120
|
+
plugins: [
|
|
121
|
+
wasm(),
|
|
122
|
+
topLevelAwait()
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Finally, load the code. We recommend dynamic imports:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
import('@cedar-policy/cedar-wasm').then(mod => {
|
|
132
|
+
// cache it globally here or invoke functions like mod.getCedarVersion();
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
package/cedar_wasm.d.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} json_str
|
|
5
|
+
* @returns {JsonToPolicyResult}
|
|
6
|
+
*/
|
|
7
|
+
export function policyTextFromJson(json_str: string): JsonToPolicyResult;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} cedar_str
|
|
10
|
+
* @returns {PolicyToJsonResult}
|
|
11
|
+
*/
|
|
12
|
+
export function policyTextToJson(cedar_str: string): PolicyToJsonResult;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} input_policies_str
|
|
15
|
+
* @returns {CheckParsePolicySetResult}
|
|
16
|
+
*/
|
|
17
|
+
export function checkParsePolicySet(input_policies_str: string): CheckParsePolicySetResult;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} template_str
|
|
20
|
+
* @returns {CheckParseTemplateResult}
|
|
21
|
+
*/
|
|
22
|
+
export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} input_schema
|
|
25
|
+
* @returns {CheckParseResult}
|
|
26
|
+
*/
|
|
27
|
+
export function checkParseSchema(input_schema: string): CheckParseResult;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} entities_str
|
|
30
|
+
* @param {string} schema_str
|
|
31
|
+
* @returns {CheckParseResult}
|
|
32
|
+
*/
|
|
33
|
+
export function checkParseEntities(entities_str: string, schema_str: string): CheckParseResult;
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} context_str
|
|
36
|
+
* @param {string} action_str
|
|
37
|
+
* @param {string} schema_str
|
|
38
|
+
* @returns {CheckParseResult}
|
|
39
|
+
*/
|
|
40
|
+
export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} policies_str
|
|
43
|
+
* @param {number} line_width
|
|
44
|
+
* @param {number} indent_width
|
|
45
|
+
* @returns {FormattingResult}
|
|
46
|
+
*/
|
|
47
|
+
export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
|
|
48
|
+
/**
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
export function getCedarVersion(): string;
|
|
52
|
+
/**
|
|
53
|
+
* @param {AuthorizationCall} call
|
|
54
|
+
* @returns {AuthorizationAnswer}
|
|
55
|
+
*/
|
|
56
|
+
export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
|
|
57
|
+
/**
|
|
58
|
+
* @param {ValidationCall} call
|
|
59
|
+
* @returns {ValidationAnswer}
|
|
60
|
+
*/
|
|
61
|
+
export function validate(call: ValidationCall): ValidationAnswer;
|
|
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[] };
|
|
65
|
+
|
|
66
|
+
export type CheckParsePolicySetResult = { type: "success"; policies: number; templates: number } | { type: "error"; errors: string[] };
|
|
67
|
+
|
|
68
|
+
export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
|
|
69
|
+
|
|
70
|
+
export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
|
|
71
|
+
|
|
72
|
+
export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
|
|
73
|
+
|
|
74
|
+
export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
|
|
75
|
+
|
|
76
|
+
export interface ValidationError {
|
|
77
|
+
policyId: SmolStr;
|
|
78
|
+
error: DetailedError;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ValidationEnabled = "on" | "off";
|
|
82
|
+
|
|
83
|
+
export interface ValidationSettings {
|
|
84
|
+
enabled: ValidationEnabled;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ValidationCall {
|
|
88
|
+
validationSettings?: ValidationSettings;
|
|
89
|
+
schema: Schema;
|
|
90
|
+
policySet: PolicySet;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface RecvdSlice {
|
|
94
|
+
policies: PolicySet;
|
|
95
|
+
entities: Array<EntityJson>;
|
|
96
|
+
templates?: Record<string, string> | null;
|
|
97
|
+
templateInstantiations: TemplateLink[] | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type Links = Link[];
|
|
101
|
+
|
|
102
|
+
export interface TemplateLink {
|
|
103
|
+
templateId: string;
|
|
104
|
+
resultPolicyId: string;
|
|
105
|
+
instantiations: Links;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface Link {
|
|
109
|
+
slot: string;
|
|
110
|
+
value: EntityUIDStrings;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface EntityUIDStrings {
|
|
114
|
+
ty: string;
|
|
115
|
+
eid: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface AuthorizationCall {
|
|
119
|
+
principal: string|{type: string, id: string};
|
|
120
|
+
action: string|{type: string, id: string};
|
|
121
|
+
resource: string|{type: string, id: string};
|
|
122
|
+
context: Record<string, CedarValueJson>;
|
|
123
|
+
schema?: Schema;
|
|
124
|
+
enableRequestValidation?: boolean;
|
|
125
|
+
slice: RecvdSlice;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
|
|
129
|
+
|
|
130
|
+
export interface AuthorizationError {
|
|
131
|
+
policyId: SmolStr;
|
|
132
|
+
error: DetailedError;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface Diagnostics {
|
|
136
|
+
reason: Set<String>;
|
|
137
|
+
errors: AuthorizationError[];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface Response {
|
|
141
|
+
decision: Decision;
|
|
142
|
+
diagnostics: Diagnostics;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type Schema = { human: string } | { json: JsonValueWithNoDuplicateKeys };
|
|
146
|
+
|
|
147
|
+
export type PolicySet = string | Record<string, string>;
|
|
148
|
+
|
|
149
|
+
export interface SourceLocation {
|
|
150
|
+
start: number;
|
|
151
|
+
end: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface SourceLabel extends SourceLocation {
|
|
155
|
+
label: string | null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type Severity = "advice" | "warning" | "error";
|
|
159
|
+
|
|
160
|
+
export interface DetailedError {
|
|
161
|
+
message: string;
|
|
162
|
+
help: string | null;
|
|
163
|
+
code: string | null;
|
|
164
|
+
url: string | null;
|
|
165
|
+
severity: Severity | null;
|
|
166
|
+
sourceLocations?: SourceLabel[];
|
|
167
|
+
related?: DetailedError[];
|
|
168
|
+
}
|
|
169
|
+
|
|
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 };
|
|
171
|
+
|
|
172
|
+
export type SchemaType = SchemaTypeVariant | { type: Name };
|
|
173
|
+
|
|
174
|
+
export interface ActionEntityUID {
|
|
175
|
+
id: SmolStr;
|
|
176
|
+
type?: Name;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface ApplySpec {
|
|
180
|
+
resourceTypes?: Name[];
|
|
181
|
+
principalTypes?: Name[];
|
|
182
|
+
context?: AttributesOrContext;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface ActionType {
|
|
186
|
+
attributes?: Record<SmolStr, CedarValueJson>;
|
|
187
|
+
appliesTo?: ApplySpec;
|
|
188
|
+
memberOf?: ActionEntityUID[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type AttributesOrContext = SchemaType;
|
|
192
|
+
|
|
193
|
+
export interface EntityType {
|
|
194
|
+
memberOfTypes?: Name[];
|
|
195
|
+
shape?: AttributesOrContext;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface NamespaceDefinition {
|
|
199
|
+
commonTypes?: Record<Id, SchemaType>;
|
|
200
|
+
entityTypes: Record<Id, EntityType>;
|
|
201
|
+
actions: Record<SmolStr, ActionType>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export type Schema = Record<string, NamespaceDefinition>;
|
|
205
|
+
|
|
206
|
+
export type Decision = "Allow" | "Deny";
|
|
207
|
+
|
|
208
|
+
export interface EntityJson {
|
|
209
|
+
uid: EntityUidJson;
|
|
210
|
+
attrs: Record<string, CedarValueJson>;
|
|
211
|
+
parents: EntityUidJson[];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
|
|
215
|
+
|
|
216
|
+
export interface FnAndArg {
|
|
217
|
+
fn: string;
|
|
218
|
+
arg: CedarValueJson;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface TypeAndId {
|
|
222
|
+
type: string;
|
|
223
|
+
id: string;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
|
|
227
|
+
|
|
228
|
+
export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
|
|
229
|
+
|
|
230
|
+
export interface PrincipalOrResourceIsConstraint {
|
|
231
|
+
entity_type: string;
|
|
232
|
+
in?: PrincipalOrResourceInConstraint;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
|
|
236
|
+
|
|
237
|
+
export type EqConstraint = { entity: EntityUidJson } | { slot: string };
|
|
238
|
+
|
|
239
|
+
export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
|
|
240
|
+
|
|
241
|
+
export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
|
|
242
|
+
|
|
243
|
+
export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
|
|
244
|
+
|
|
245
|
+
export type ExtFuncCall = {} & Record<string, Array<Expr>>;
|
|
246
|
+
|
|
247
|
+
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> };
|
|
248
|
+
|
|
249
|
+
export type Expr = ExprNoExt | ExtFuncCall;
|
|
250
|
+
|
|
251
|
+
export type Var = "principal" | "action" | "resource" | "context";
|
|
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 Effect = "permit" | "forbid";
|
|
265
|
+
|
|
266
|
+
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>;
|
package/cedar_wasm.js
ADDED
package/cedar_wasm_bg.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
export function __wbg_set_wasm(val) {
|
|
3
|
+
wasm = val;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const heap = new Array(128).fill(undefined);
|
|
8
|
+
|
|
9
|
+
heap.push(undefined, null, true, false);
|
|
10
|
+
|
|
11
|
+
function getObject(idx) { return heap[idx]; }
|
|
12
|
+
|
|
13
|
+
let heap_next = heap.length;
|
|
14
|
+
|
|
15
|
+
function addHeapObject(obj) {
|
|
16
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
17
|
+
const idx = heap_next;
|
|
18
|
+
heap_next = heap[idx];
|
|
19
|
+
|
|
20
|
+
heap[idx] = obj;
|
|
21
|
+
return idx;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function dropObject(idx) {
|
|
25
|
+
if (idx < 132) return;
|
|
26
|
+
heap[idx] = heap_next;
|
|
27
|
+
heap_next = idx;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function takeObject(idx) {
|
|
31
|
+
const ret = getObject(idx);
|
|
32
|
+
dropObject(idx);
|
|
33
|
+
return ret;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let WASM_VECTOR_LEN = 0;
|
|
37
|
+
|
|
38
|
+
let cachedUint8Memory0 = null;
|
|
39
|
+
|
|
40
|
+
function getUint8Memory0() {
|
|
41
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
42
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
43
|
+
}
|
|
44
|
+
return cachedUint8Memory0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
|
48
|
+
|
|
49
|
+
let cachedTextEncoder = new lTextEncoder('utf-8');
|
|
50
|
+
|
|
51
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
52
|
+
? function (arg, view) {
|
|
53
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
54
|
+
}
|
|
55
|
+
: function (arg, view) {
|
|
56
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
57
|
+
view.set(buf);
|
|
58
|
+
return {
|
|
59
|
+
read: arg.length,
|
|
60
|
+
written: buf.length
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
65
|
+
|
|
66
|
+
if (realloc === undefined) {
|
|
67
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
68
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
69
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
70
|
+
WASM_VECTOR_LEN = buf.length;
|
|
71
|
+
return ptr;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let len = arg.length;
|
|
75
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
76
|
+
|
|
77
|
+
const mem = getUint8Memory0();
|
|
78
|
+
|
|
79
|
+
let offset = 0;
|
|
80
|
+
|
|
81
|
+
for (; offset < len; offset++) {
|
|
82
|
+
const code = arg.charCodeAt(offset);
|
|
83
|
+
if (code > 0x7F) break;
|
|
84
|
+
mem[ptr + offset] = code;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (offset !== len) {
|
|
88
|
+
if (offset !== 0) {
|
|
89
|
+
arg = arg.slice(offset);
|
|
90
|
+
}
|
|
91
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
92
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
93
|
+
const ret = encodeString(arg, view);
|
|
94
|
+
|
|
95
|
+
offset += ret.written;
|
|
96
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
WASM_VECTOR_LEN = offset;
|
|
100
|
+
return ptr;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isLikeNone(x) {
|
|
104
|
+
return x === undefined || x === null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let cachedInt32Memory0 = null;
|
|
108
|
+
|
|
109
|
+
function getInt32Memory0() {
|
|
110
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
|
111
|
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
112
|
+
}
|
|
113
|
+
return cachedInt32Memory0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
117
|
+
|
|
118
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
119
|
+
|
|
120
|
+
cachedTextDecoder.decode();
|
|
121
|
+
|
|
122
|
+
function getStringFromWasm0(ptr, len) {
|
|
123
|
+
ptr = ptr >>> 0;
|
|
124
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @param {string} json_str
|
|
128
|
+
* @returns {JsonToPolicyResult}
|
|
129
|
+
*/
|
|
130
|
+
export function policyTextFromJson(json_str) {
|
|
131
|
+
const ptr0 = passStringToWasm0(json_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
132
|
+
const len0 = WASM_VECTOR_LEN;
|
|
133
|
+
const ret = wasm.policyTextFromJson(ptr0, len0);
|
|
134
|
+
return takeObject(ret);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} cedar_str
|
|
139
|
+
* @returns {PolicyToJsonResult}
|
|
140
|
+
*/
|
|
141
|
+
export function policyTextToJson(cedar_str) {
|
|
142
|
+
const ptr0 = passStringToWasm0(cedar_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
143
|
+
const len0 = WASM_VECTOR_LEN;
|
|
144
|
+
const ret = wasm.policyTextToJson(ptr0, len0);
|
|
145
|
+
return takeObject(ret);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {string} input_policies_str
|
|
150
|
+
* @returns {CheckParsePolicySetResult}
|
|
151
|
+
*/
|
|
152
|
+
export function checkParsePolicySet(input_policies_str) {
|
|
153
|
+
const ptr0 = passStringToWasm0(input_policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
154
|
+
const len0 = WASM_VECTOR_LEN;
|
|
155
|
+
const ret = wasm.checkParsePolicySet(ptr0, len0);
|
|
156
|
+
return takeObject(ret);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param {string} template_str
|
|
161
|
+
* @returns {CheckParseTemplateResult}
|
|
162
|
+
*/
|
|
163
|
+
export function checkParseTemplate(template_str) {
|
|
164
|
+
const ptr0 = passStringToWasm0(template_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
165
|
+
const len0 = WASM_VECTOR_LEN;
|
|
166
|
+
const ret = wasm.checkParseTemplate(ptr0, len0);
|
|
167
|
+
return takeObject(ret);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {string} input_schema
|
|
172
|
+
* @returns {CheckParseResult}
|
|
173
|
+
*/
|
|
174
|
+
export function checkParseSchema(input_schema) {
|
|
175
|
+
const ptr0 = passStringToWasm0(input_schema, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
176
|
+
const len0 = WASM_VECTOR_LEN;
|
|
177
|
+
const ret = wasm.checkParseSchema(ptr0, len0);
|
|
178
|
+
return takeObject(ret);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {string} entities_str
|
|
183
|
+
* @param {string} schema_str
|
|
184
|
+
* @returns {CheckParseResult}
|
|
185
|
+
*/
|
|
186
|
+
export function checkParseEntities(entities_str, schema_str) {
|
|
187
|
+
const ptr0 = passStringToWasm0(entities_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
188
|
+
const len0 = WASM_VECTOR_LEN;
|
|
189
|
+
const ptr1 = passStringToWasm0(schema_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
190
|
+
const len1 = WASM_VECTOR_LEN;
|
|
191
|
+
const ret = wasm.checkParseEntities(ptr0, len0, ptr1, len1);
|
|
192
|
+
return takeObject(ret);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @param {string} context_str
|
|
197
|
+
* @param {string} action_str
|
|
198
|
+
* @param {string} schema_str
|
|
199
|
+
* @returns {CheckParseResult}
|
|
200
|
+
*/
|
|
201
|
+
export function checkParseContext(context_str, action_str, schema_str) {
|
|
202
|
+
const ptr0 = passStringToWasm0(context_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
203
|
+
const len0 = WASM_VECTOR_LEN;
|
|
204
|
+
const ptr1 = passStringToWasm0(action_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
205
|
+
const len1 = WASM_VECTOR_LEN;
|
|
206
|
+
const ptr2 = passStringToWasm0(schema_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
207
|
+
const len2 = WASM_VECTOR_LEN;
|
|
208
|
+
const ret = wasm.checkParseContext(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
209
|
+
return takeObject(ret);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {string} policies_str
|
|
214
|
+
* @param {number} line_width
|
|
215
|
+
* @param {number} indent_width
|
|
216
|
+
* @returns {FormattingResult}
|
|
217
|
+
*/
|
|
218
|
+
export function formatPolicies(policies_str, line_width, indent_width) {
|
|
219
|
+
const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
220
|
+
const len0 = WASM_VECTOR_LEN;
|
|
221
|
+
const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
|
|
222
|
+
return takeObject(ret);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @returns {string}
|
|
227
|
+
*/
|
|
228
|
+
export function getCedarVersion() {
|
|
229
|
+
let deferred1_0;
|
|
230
|
+
let deferred1_1;
|
|
231
|
+
try {
|
|
232
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
233
|
+
wasm.getCedarVersion(retptr);
|
|
234
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
235
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
236
|
+
deferred1_0 = r0;
|
|
237
|
+
deferred1_1 = r1;
|
|
238
|
+
return getStringFromWasm0(r0, r1);
|
|
239
|
+
} finally {
|
|
240
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
241
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @param {AuthorizationCall} call
|
|
247
|
+
* @returns {AuthorizationAnswer}
|
|
248
|
+
*/
|
|
249
|
+
export function isAuthorized(call) {
|
|
250
|
+
const ret = wasm.isAuthorized(addHeapObject(call));
|
|
251
|
+
return takeObject(ret);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {ValidationCall} call
|
|
256
|
+
* @returns {ValidationAnswer}
|
|
257
|
+
*/
|
|
258
|
+
export function validate(call) {
|
|
259
|
+
const ret = wasm.validate(addHeapObject(call));
|
|
260
|
+
return takeObject(ret);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function handleError(f, args) {
|
|
264
|
+
try {
|
|
265
|
+
return f.apply(this, args);
|
|
266
|
+
} catch (e) {
|
|
267
|
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function __wbindgen_is_undefined(arg0) {
|
|
272
|
+
const ret = getObject(arg0) === undefined;
|
|
273
|
+
return ret;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export function __wbindgen_object_clone_ref(arg0) {
|
|
277
|
+
const ret = getObject(arg0);
|
|
278
|
+
return addHeapObject(ret);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export function __wbindgen_object_drop_ref(arg0) {
|
|
282
|
+
takeObject(arg0);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export function __wbindgen_string_get(arg0, arg1) {
|
|
286
|
+
const obj = getObject(arg1);
|
|
287
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
288
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
289
|
+
var len1 = WASM_VECTOR_LEN;
|
|
290
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
291
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export function __wbg_parse_66d1801634e099ac() { return handleError(function (arg0, arg1) {
|
|
295
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
296
|
+
return addHeapObject(ret);
|
|
297
|
+
}, arguments) };
|
|
298
|
+
|
|
299
|
+
export function __wbg_stringify_8887fe74e1c50d81() { return handleError(function (arg0) {
|
|
300
|
+
const ret = JSON.stringify(getObject(arg0));
|
|
301
|
+
return addHeapObject(ret);
|
|
302
|
+
}, arguments) };
|
|
303
|
+
|
|
304
|
+
export function __wbindgen_throw(arg0, arg1) {
|
|
305
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
306
|
+
};
|
|
307
|
+
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cedar-policy/cedar-wasm",
|
|
3
|
+
"description": "WASM bindings and typescript types for Cedar lib",
|
|
4
|
+
"version": "3.2.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"cedar_wasm_bg.wasm",
|
|
8
|
+
"cedar_wasm.js",
|
|
9
|
+
"cedar_wasm_bg.js",
|
|
10
|
+
"cedar_wasm.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"module": "cedar_wasm.js",
|
|
13
|
+
"types": "cedar_wasm.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./cedar_wasm.js",
|
|
16
|
+
"./snippets/*"
|
|
17
|
+
]
|
|
18
|
+
}
|