toride 0.2.0 → 0.3.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/dist/{chunk-24PMDTLE.js → chunk-2AWXNP37.js} +13 -3
- package/dist/{chunk-475CNU63.js → chunk-S6DKDABO.js} +2 -1
- package/dist/cli.js +1 -1
- package/dist/{client-RqwW0K_-.d.ts → client-aExMng5T.d.ts} +12 -7
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +32 -19
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -2001,16 +2001,17 @@ async function permittedFields(engine, actor, operation, resource, fieldAccess,
|
|
|
2001
2001
|
for (const fieldName of fieldNames) {
|
|
2002
2002
|
const fieldDef = fieldAccess[fieldName];
|
|
2003
2003
|
const allowedRoles = fieldDef?.[operation];
|
|
2004
|
+
const typedFieldName = fieldName;
|
|
2004
2005
|
if (allowedRoles) {
|
|
2005
2006
|
if (actorRoles.some((role) => allowedRoles.includes(role))) {
|
|
2006
|
-
permitted.push(
|
|
2007
|
+
permitted.push(typedFieldName);
|
|
2007
2008
|
}
|
|
2008
2009
|
} else {
|
|
2009
2010
|
if (hasResourcePermission === void 0) {
|
|
2010
2011
|
hasResourcePermission = await engine.can(actor, operation, resource, options);
|
|
2011
2012
|
}
|
|
2012
2013
|
if (hasResourcePermission) {
|
|
2013
|
-
permitted.push(
|
|
2014
|
+
permitted.push(typedFieldName);
|
|
2014
2015
|
}
|
|
2015
2016
|
}
|
|
2016
2017
|
}
|
|
@@ -2209,9 +2210,18 @@ var Toride = class {
|
|
|
2209
2210
|
/**
|
|
2210
2211
|
* T064: Translate constraint AST using an adapter.
|
|
2211
2212
|
* Dispatches each constraint node to the adapter's methods.
|
|
2213
|
+
*
|
|
2214
|
+
* Accepts ConstraintResult<R> from buildConstraints() and returns
|
|
2215
|
+
* TQueryMap[R] — the adapter's mapped output type for resource R.
|
|
2216
|
+
* The resource type R is inferred from the ConstraintResult phantom type.
|
|
2212
2217
|
*/
|
|
2213
2218
|
translateConstraints(constraints, adapter) {
|
|
2214
|
-
|
|
2219
|
+
if ("unrestricted" in constraints || "forbidden" in constraints) {
|
|
2220
|
+
throw new Error(
|
|
2221
|
+
"Cannot translate unrestricted or forbidden ConstraintResult. Check for 'constraints' property before calling translateConstraints()."
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
return translateConstraints(constraints.constraints, adapter);
|
|
2215
2225
|
}
|
|
2216
2226
|
/**
|
|
2217
2227
|
* T072: Fire onDecision audit callback via microtask (non-blocking).
|
|
@@ -4,7 +4,8 @@ var TorideClient = class {
|
|
|
4
4
|
permissions;
|
|
5
5
|
constructor(snapshot) {
|
|
6
6
|
this.permissions = /* @__PURE__ */ new Map();
|
|
7
|
-
|
|
7
|
+
const entries = snapshot;
|
|
8
|
+
for (const [key, actions] of Object.entries(entries)) {
|
|
8
9
|
this.permissions.set(key, new Set(actions));
|
|
9
10
|
}
|
|
10
11
|
}
|
package/dist/cli.js
CHANGED
|
@@ -329,14 +329,19 @@ declare class DepthLimitError extends Error {
|
|
|
329
329
|
* A serializable map of permissions keyed by "Type:id".
|
|
330
330
|
* Values are arrays of permitted action strings.
|
|
331
331
|
* Suitable for JSON transport to client-side TorideClient.
|
|
332
|
+
*
|
|
333
|
+
* Generic over TorideSchema so that the type parameter flows through
|
|
334
|
+
* to TorideClient<S> on deserialization. The runtime structure is unchanged.
|
|
332
335
|
*/
|
|
333
|
-
type PermissionSnapshot = Record<string, string[]
|
|
336
|
+
type PermissionSnapshot<S extends TorideSchema = DefaultSchema> = Record<string, string[]> & {
|
|
337
|
+
readonly __schema?: S | undefined;
|
|
338
|
+
};
|
|
334
339
|
|
|
335
340
|
declare const CLIENT_VERSION = "0.0.1";
|
|
336
341
|
|
|
337
|
-
/** Minimal resource reference for client-side lookups. Generic over S for type narrowing. */
|
|
338
|
-
interface ClientResourceRef<S extends TorideSchema = DefaultSchema> {
|
|
339
|
-
readonly type:
|
|
342
|
+
/** Minimal resource reference for client-side lookups. Generic over S and R for type narrowing. */
|
|
343
|
+
interface ClientResourceRef<S extends TorideSchema = DefaultSchema, R extends S["resources"] = S["resources"]> {
|
|
344
|
+
readonly type: R;
|
|
340
345
|
readonly id: string;
|
|
341
346
|
}
|
|
342
347
|
/**
|
|
@@ -351,18 +356,18 @@ interface ClientResourceRef<S extends TorideSchema = DefaultSchema> {
|
|
|
351
356
|
*/
|
|
352
357
|
declare class TorideClient<S extends TorideSchema = DefaultSchema> {
|
|
353
358
|
private readonly permissions;
|
|
354
|
-
constructor(snapshot: PermissionSnapshot);
|
|
359
|
+
constructor(snapshot: PermissionSnapshot<S>);
|
|
355
360
|
/**
|
|
356
361
|
* Synchronous permission check.
|
|
357
362
|
* Returns true if the action is permitted for the resource, false otherwise.
|
|
358
363
|
* Unknown resources return false (default-deny).
|
|
359
364
|
*/
|
|
360
|
-
can(action: S["
|
|
365
|
+
can<R extends S["resources"]>(action: S["permissionMap"][R], resource: ClientResourceRef<S, R>): boolean;
|
|
361
366
|
/**
|
|
362
367
|
* Return the list of permitted actions for a resource.
|
|
363
368
|
* Returns empty array for unknown resources.
|
|
364
369
|
*/
|
|
365
|
-
permittedActions(resource: ClientResourceRef<S>): S["
|
|
370
|
+
permittedActions<R extends S["resources"]>(resource: ClientResourceRef<S, R>): S["permissionMap"][R][];
|
|
366
371
|
}
|
|
367
372
|
|
|
368
373
|
export { type ActorRef as A, type BatchCheckItem as B, type CheckOptions as C, type DefaultSchema as D, type ExplainResult as E, type FieldAccessDef as F, type GlobalRole as G, type MatchedRule as M, type Policy as P, type QueryEvent as Q, type ResourceRef as R, type SimpleConditions as S, type TorideSchema as T, ValidationError as V, type TorideOptions as a, type PermissionSnapshot as b, type TestCase as c, type Resolvers as d, type ActorDeclaration as e, type AttributeType as f, type ClientResourceRef as g, type ConditionExpression as h, type ConditionOperator as i, type ConditionValue as j, CycleError as k, type DecisionEvent as l, DepthLimitError as m, type DerivedRoleEntry as n, type DerivedRoleTrace as o, type EvaluatorFn as p, type ResolvedRolesDetail as q, type ResourceBlock as r, type ResourceResolver as s, type Rule as t, TorideClient as u, CLIENT_VERSION as v };
|
package/dist/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { v as CLIENT_VERSION, g as ClientResourceRef, b as PermissionSnapshot, u as TorideClient } from './client-
|
|
1
|
+
export { v as CLIENT_VERSION, g as ClientResourceRef, b as PermissionSnapshot, u as TorideClient } from './client-aExMng5T.js';
|
package/dist/client.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Policy, T as TorideSchema, D as DefaultSchema, a as TorideOptions, A as ActorRef, R as ResourceRef, C as CheckOptions, E as ExplainResult, b as PermissionSnapshot, B as BatchCheckItem, c as TestCase, d as Resolvers } from './client-
|
|
2
|
-
export { e as ActorDeclaration, f as AttributeType, g as ClientResourceRef, h as ConditionExpression, i as ConditionOperator, j as ConditionValue, k as CycleError, l as DecisionEvent, m as DepthLimitError, n as DerivedRoleEntry, o as DerivedRoleTrace, p as EvaluatorFn, F as FieldAccessDef, G as GlobalRole, M as MatchedRule, Q as QueryEvent, q as ResolvedRolesDetail, r as ResourceBlock, s as ResourceResolver, t as Rule, S as SimpleConditions, u as TorideClient, V as ValidationError } from './client-
|
|
1
|
+
import { P as Policy, T as TorideSchema, D as DefaultSchema, a as TorideOptions, A as ActorRef, R as ResourceRef, C as CheckOptions, E as ExplainResult, b as PermissionSnapshot, B as BatchCheckItem, c as TestCase, d as Resolvers } from './client-aExMng5T.js';
|
|
2
|
+
export { e as ActorDeclaration, f as AttributeType, g as ClientResourceRef, h as ConditionExpression, i as ConditionOperator, j as ConditionValue, k as CycleError, l as DecisionEvent, m as DepthLimitError, n as DerivedRoleEntry, o as DerivedRoleTrace, p as EvaluatorFn, F as FieldAccessDef, G as GlobalRole, M as MatchedRule, Q as QueryEvent, q as ResolvedRolesDetail, r as ResourceBlock, s as ResourceResolver, t as Rule, S as SimpleConditions, u as TorideClient, V as ValidationError } from './client-aExMng5T.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Parse and validate a YAML string into a typed Policy object.
|
|
@@ -149,23 +149,32 @@ interface NeverConstraint {
|
|
|
149
149
|
type Constraint = FieldEqConstraint | FieldNeqConstraint | FieldGtConstraint | FieldGteConstraint | FieldLtConstraint | FieldLteConstraint | FieldInConstraint | FieldNinConstraint | FieldExistsConstraint | FieldIncludesConstraint | FieldContainsConstraint | RelationConstraint | HasRoleConstraint | UnknownConstraint | AndConstraint | OrConstraint | NotConstraint | AlwaysConstraint | NeverConstraint;
|
|
150
150
|
/** Leaf constraint subset for ConstraintAdapter.translate(). */
|
|
151
151
|
type LeafConstraint = FieldEqConstraint | FieldNeqConstraint | FieldGtConstraint | FieldGteConstraint | FieldLtConstraint | FieldLteConstraint | FieldInConstraint | FieldNinConstraint | FieldExistsConstraint | FieldIncludesConstraint | FieldContainsConstraint;
|
|
152
|
-
/** Result of partial evaluation. */
|
|
153
|
-
type ConstraintResult = {
|
|
152
|
+
/** Result of partial evaluation, tagged with resource type R (phantom). */
|
|
153
|
+
type ConstraintResult<R extends string = string> = {
|
|
154
154
|
readonly unrestricted: true;
|
|
155
|
+
readonly __resource?: R;
|
|
155
156
|
} | {
|
|
156
157
|
readonly forbidden: true;
|
|
158
|
+
readonly __resource?: R;
|
|
157
159
|
} | {
|
|
158
160
|
readonly constraints: Constraint;
|
|
161
|
+
readonly __resource?: R;
|
|
159
162
|
};
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
/**
|
|
164
|
+
* User-provided adapter for translating constraint ASTs to queries.
|
|
165
|
+
* TQueryMap maps resource type names to their query output types.
|
|
166
|
+
*
|
|
167
|
+
* BREAKING CHANGE: Previously ConstraintAdapter<TQuery> with a single query type.
|
|
168
|
+
* Now uses a resource-to-query-type map for per-resource output typing.
|
|
169
|
+
*/
|
|
170
|
+
interface ConstraintAdapter<TQueryMap extends Record<string, unknown> = Record<string, unknown>> {
|
|
171
|
+
translate(constraint: LeafConstraint): TQueryMap[string];
|
|
172
|
+
relation(field: string, resourceType: string, childQuery: TQueryMap[string]): TQueryMap[string];
|
|
173
|
+
hasRole(actorId: string, actorType: string, role: string): TQueryMap[string];
|
|
174
|
+
unknown(name: string): TQueryMap[string];
|
|
175
|
+
and(queries: TQueryMap[string][]): TQueryMap[string];
|
|
176
|
+
or(queries: TQueryMap[string][]): TQueryMap[string];
|
|
177
|
+
not(query: TQueryMap[string]): TQueryMap[string];
|
|
169
178
|
}
|
|
170
179
|
|
|
171
180
|
/**
|
|
@@ -205,22 +214,22 @@ declare class Toride<S extends TorideSchema = DefaultSchema> {
|
|
|
205
214
|
* keyed by "Type:id" with arrays of permitted action strings.
|
|
206
215
|
* Suitable for serializing to the client via TorideClient.
|
|
207
216
|
*/
|
|
208
|
-
snapshot(actor: ActorRef<S>, resources: ResourceRef<S>[], options?: CheckOptions): Promise<PermissionSnapshot
|
|
217
|
+
snapshot(actor: ActorRef<S>, resources: ResourceRef<S>[], options?: CheckOptions): Promise<PermissionSnapshot<S>>;
|
|
209
218
|
/**
|
|
210
219
|
* T095: Check if an actor can perform a field-level operation on a specific field.
|
|
211
220
|
* Restricted fields require the actor to have a role listed in field_access.
|
|
212
221
|
* Unlisted fields are unrestricted: any actor with the resource-level permission can access them.
|
|
213
222
|
*/
|
|
214
|
-
canField<R extends S["resources"]>(actor: ActorRef<S>, operation: "read" | "update", resource: ResourceRef<S, R>, field: string, options?: CheckOptions): Promise<boolean>;
|
|
223
|
+
canField<R extends S["resources"]>(actor: ActorRef<S>, operation: "read" | "update", resource: ResourceRef<S, R>, field: keyof S["resourceAttributeMap"][R] & string, options?: CheckOptions): Promise<boolean>;
|
|
215
224
|
/**
|
|
216
225
|
* T095: Return the list of declared field_access field names the actor can access
|
|
217
226
|
* for the given operation. Only returns explicitly declared fields.
|
|
218
227
|
*/
|
|
219
|
-
permittedFields<R extends S["resources"]>(actor: ActorRef<S>, operation: "read" | "update", resource: ResourceRef<S, R>, options?: CheckOptions): Promise<string[]>;
|
|
228
|
+
permittedFields<R extends S["resources"]>(actor: ActorRef<S>, operation: "read" | "update", resource: ResourceRef<S, R>, options?: CheckOptions): Promise<(keyof S["resourceAttributeMap"][R] & string)[]>;
|
|
220
229
|
/**
|
|
221
230
|
* T070: Return flat deduplicated list of all resolved roles (direct + derived).
|
|
222
231
|
*/
|
|
223
|
-
resolvedRoles<R extends S["resources"]>(actor: ActorRef<S>, resource: ResourceRef<S, R>, options?: CheckOptions): Promise<
|
|
232
|
+
resolvedRoles<R extends S["resources"]>(actor: ActorRef<S>, resource: ResourceRef<S, R>, options?: CheckOptions): Promise<S["roleMap"][R][]>;
|
|
224
233
|
/**
|
|
225
234
|
* T071: Evaluate multiple checks for the same actor with a shared resolver cache.
|
|
226
235
|
* Returns boolean[] in the same order as the input checks.
|
|
@@ -230,12 +239,16 @@ declare class Toride<S extends TorideSchema = DefaultSchema> {
|
|
|
230
239
|
* T064: Build constraint AST for partial evaluation / data filtering.
|
|
231
240
|
* Returns ConstraintResult with unrestricted/forbidden sentinels or constraint AST.
|
|
232
241
|
*/
|
|
233
|
-
buildConstraints<R extends S["resources"]>(actor: ActorRef<S>, action: S["permissionMap"][R], resourceType: R, options?: CheckOptions): Promise<ConstraintResult
|
|
242
|
+
buildConstraints<R extends S["resources"]>(actor: ActorRef<S>, action: S["permissionMap"][R], resourceType: R, options?: CheckOptions): Promise<ConstraintResult<R>>;
|
|
234
243
|
/**
|
|
235
244
|
* T064: Translate constraint AST using an adapter.
|
|
236
245
|
* Dispatches each constraint node to the adapter's methods.
|
|
246
|
+
*
|
|
247
|
+
* Accepts ConstraintResult<R> from buildConstraints() and returns
|
|
248
|
+
* TQueryMap[R] — the adapter's mapped output type for resource R.
|
|
249
|
+
* The resource type R is inferred from the ConstraintResult phantom type.
|
|
237
250
|
*/
|
|
238
|
-
translateConstraints<
|
|
251
|
+
translateConstraints<R extends string, TQueryMap extends Record<string, unknown>>(constraints: ConstraintResult<R>, adapter: ConstraintAdapter<TQueryMap>): TQueryMap[R];
|
|
239
252
|
/**
|
|
240
253
|
* T072: Fire onDecision audit callback via microtask (non-blocking).
|
|
241
254
|
* Errors are silently swallowed to prevent audit failures from affecting authorization.
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
validatePolicy,
|
|
13
13
|
validatePolicyResult,
|
|
14
14
|
validatePolicyStrict
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-2AWXNP37.js";
|
|
16
16
|
import {
|
|
17
17
|
TorideClient
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-S6DKDABO.js";
|
|
19
19
|
|
|
20
20
|
// src/policy/parser.ts
|
|
21
21
|
import * as YAML from "yaml";
|