@lunora/server 1.0.0-alpha.29 → 1.0.0-alpha.290
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/LICENSE.md +414 -104
- package/README.md +21 -15
- package/dist/data-model.d.mts +328 -78
- package/dist/data-model.d.ts +328 -78
- package/dist/data-model.mjs +0 -1
- package/dist/drizzle.mjs +1 -1
- package/dist/in-process.d.mts +115 -0
- package/dist/in-process.d.ts +115 -0
- package/dist/in-process.mjs +1 -0
- package/dist/index.d.mts +3615 -1125
- package/dist/index.d.ts +3615 -1125
- package/dist/index.mjs +1 -29
- package/dist/otel.d.mts +649 -0
- package/dist/otel.d.ts +649 -0
- package/dist/otel.mjs +1 -0
- package/dist/packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-Dv4DKrj0.mjs +1 -0
- package/dist/packem_shared/DEFAULT_LIMIT-z7HB19s7.mjs +1 -0
- package/dist/packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BCa6sLSJ.mjs +1 -0
- package/dist/packem_shared/LunoraEnvError-06_Zc4yc.mjs +3 -0
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-aj9Ec70J.mjs +1 -0
- package/dist/packem_shared/PROCEDURE_META-DVzrXpfa.mjs +1 -0
- package/dist/packem_shared/allowAll-DkRAgItV.mjs +1 -0
- package/dist/packem_shared/apply-output-C5wZ5EAL.mjs +1 -0
- package/dist/packem_shared/asBucketStorage-DoGYOjq3.mjs +1 -0
- package/dist/packem_shared/assertShapesDeclareReadPolicies-B9Kat3xb.mjs +1 -0
- package/dist/packem_shared/authorize-CVLZJxf_.mjs +1 -0
- package/dist/packem_shared/beginDeferredDeletes-DhwFBbvs.mjs +1 -0
- package/dist/packem_shared/beginDeferredSchedules-BOsY07vZ.mjs +1 -0
- package/dist/packem_shared/bindOrm-DjpQXKLX.mjs +1 -0
- package/dist/packem_shared/buildMaskRegistry-DpWMtalG.mjs +1 -0
- package/dist/packem_shared/compose-middleware-BK9FlblN.mjs +1 -0
- package/dist/packem_shared/composePluginMiddleware-3e7F9JIa.mjs +1 -0
- package/dist/packem_shared/context-identity-B2XYGA0B.mjs +1 -0
- package/dist/packem_shared/createPolicyDsl-BZa6SqLJ.mjs +1 -0
- package/dist/packem_shared/createSecrets-D6rLB42U.mjs +1 -0
- package/dist/packem_shared/createServices-IJvoqi0e.mjs +1 -0
- package/dist/packem_shared/defineAggregateIndex-C3xWV-Dr.mjs +1 -0
- package/dist/packem_shared/defineIdentity-DwkNKwYa.mjs +1 -0
- package/dist/packem_shared/defineIdentityGuard-Bt8N65Zs.mjs +1 -0
- package/dist/packem_shared/defineLiveStream-D3xRvNDy.mjs +1 -0
- package/dist/packem_shared/defineMigration-CXOS0Bvq.mjs +1 -0
- package/dist/packem_shared/defineModule-OecXWM3U.mjs +1 -0
- package/dist/packem_shared/defineMutator-DlLFSWbO.mjs +1 -0
- package/dist/packem_shared/defineRoom-CoGi-xwm.mjs +1 -0
- package/dist/packem_shared/defineShape-BE1Drcby.mjs +1 -0
- package/dist/packem_shared/defineStorageRule-Dv4nJE0H.mjs +1 -0
- package/dist/packem_shared/defineWebSocket-BHoy6_ox.mjs +1 -0
- package/dist/packem_shared/fnv1a-D3ueNTWB.mjs +1 -0
- package/dist/packem_shared/functions-QFoBUe9t.mjs +1 -0
- package/dist/packem_shared/httpAction-DD8h1jcf.mjs +1 -0
- package/dist/packem_shared/initLunora-DcvCGLL_.mjs +1 -0
- package/dist/packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs +1 -0
- package/dist/packem_shared/isSafeHeaderValue-DswDADFy.mjs +6 -0
- package/dist/packem_shared/mask-BdHDaOeI.mjs +1 -0
- package/dist/packem_shared/middleware-6q14NoEG.mjs +1 -0
- package/dist/packem_shared/onConnect-BLRoOpv2.mjs +1 -0
- package/dist/packem_shared/onQueryChange-iuLzmyPs.mjs +1 -0
- package/dist/packem_shared/onWhisper-CfDbFLQh.mjs +1 -0
- package/dist/packem_shared/platformAdmin-kczXQme8.mjs +1 -0
- package/dist/packem_shared/plugin-CyLqvCB9.mjs +1 -0
- package/dist/packem_shared/policy-tag-V0lqFzgS.mjs +1 -0
- package/dist/packem_shared/protectPublic-Bi5_95aP.mjs +1 -0
- package/dist/packem_shared/redact-secrets-BpatNz48.mjs +2 -0
- package/dist/packem_shared/redactSecrets-Dmh9pHZu.mjs +1 -0
- package/dist/packem_shared/rls-QoHmZEia.mjs +1 -0
- package/dist/packem_shared/run-middleware-BefYq7Xd.mjs +1 -0
- package/dist/packem_shared/serveStorageObject-CLz3qhNI.mjs +1 -0
- package/dist/packem_shared/storageRules-gnLtvRbZ.mjs +1 -0
- package/dist/packem_shared/types.d--zaGh3rX.d.mts +3025 -0
- package/dist/packem_shared/types.d--zaGh3rX.d.ts +3025 -0
- package/dist/packem_shared/{types.d-C4CMJK8x.d.mts → types.d-B7FLdYUD.d.mts} +15 -8
- package/dist/packem_shared/{types.d-DdYF8E18.d.ts → types.d-BCtjbIzl.d.ts} +15 -8
- package/dist/rls/testing.d.mts +13 -5
- package/dist/rls/testing.d.ts +13 -5
- package/dist/rls/testing.mjs +1 -49
- package/dist/types.d.mts +2 -1468
- package/dist/types.d.ts +2 -1468
- package/dist/types.mjs +0 -31
- package/package.json +28 -8
- package/dist/packem_shared/LunoraEnvError-BGmd1Qs0.mjs +0 -187
- package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +0 -9
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-Cv1UPaJj.mjs +0 -114
- package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
- package/dist/packem_shared/bindOrm-Bfgl7f-Q.mjs +0 -146
- package/dist/packem_shared/buildRlsReadRegistry-D54vUQe4.mjs +0 -107
- package/dist/packem_shared/composePluginMiddleware-z62dttBo.mjs +0 -103
- package/dist/packem_shared/createPolicyDsl-By3QB4he.mjs +0 -32
- package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +0 -58
- package/dist/packem_shared/defineAggregateIndex-DTULzh09.mjs +0 -333
- package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +0 -35
- package/dist/packem_shared/defineMigration-Hx01yIht.mjs +0 -10
- package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
- package/dist/packem_shared/defineShape-C5scNOrf.mjs +0 -18
- package/dist/packem_shared/defineStorageRule-B5nL4Z1P.mjs +0 -23
- package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
- package/dist/packem_shared/httpAction-DCXoYPIk.mjs +0 -355
- package/dist/packem_shared/initLunora-CmMVk4i7.mjs +0 -107
- package/dist/packem_shared/mask-CZuu9WAF.mjs +0 -331
- package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
- package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
- package/dist/packem_shared/protectPublic-BlcGpiRc.mjs +0 -15
- package/dist/packem_shared/rls-B_ZWgslr.mjs +0 -595
- package/dist/packem_shared/run-middleware-I6EiQfxL.mjs +0 -20
- package/dist/packem_shared/storageRules-6QxzDOcx.mjs +0 -88
|
@@ -32,7 +32,7 @@ type PolicyDecision = WhereInput | boolean | undefined;
|
|
|
32
32
|
* generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
|
|
33
33
|
* read policy may now return a Prisma-style relation predicate (the
|
|
34
34
|
* `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
|
|
35
|
-
* authoring surface accepts `WhereOf
|
|
35
|
+
* authoring surface accepts `WhereOf<DM, REL, T>` — column predicates **and**
|
|
36
36
|
* `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
|
|
37
37
|
* addition to the `boolean`/`undefined` decisions. Used by the project-bound
|
|
38
38
|
* `definePolicy` from `createPolicyDsl`.
|
|
@@ -51,8 +51,12 @@ interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T ext
|
|
|
51
51
|
when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Context handed to a policy. `auth.roles` is the per-request role list,
|
|
55
|
-
*
|
|
54
|
+
* Context handed to a policy. `auth.roles` is the per-request role list, read
|
|
55
|
+
* from the `roles` CLAIM on the resolved identity — a `string[]` or a
|
|
56
|
+
* comma-separated string returned by `WorkerOptions.resolveIdentity` (and
|
|
57
|
+
* validated by `defineIdentity(...)` at the worker's trust boundary). A
|
|
58
|
+
* resolver that forwards no `roles` claim yields no roles, so every
|
|
59
|
+
* role-branched policy is evaluated against `[]`. `auth.can`
|
|
56
60
|
* answers whether any of those roles grants a permission (see
|
|
57
61
|
* {@link Permission} / {@link RlsOptions}). `row` is present only on write
|
|
58
62
|
* policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
|
|
@@ -117,10 +121,13 @@ interface Permission {
|
|
|
117
121
|
readonly name: string;
|
|
118
122
|
}
|
|
119
123
|
/**
|
|
120
|
-
* A role declaration. Roles are string labels
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
+
* A role declaration. Roles are string labels the request carries in the
|
|
125
|
+
* `roles` claim of its resolved identity — `WorkerOptions.resolveIdentity`
|
|
126
|
+
* forwards every non-`userId` key verbatim, so a resolver returning
|
|
127
|
+
* `{ userId, roles: ["admin"] }` (or the comma-joined `"user,admin"` that
|
|
128
|
+
* better-auth's `admin()` plugin stores) is what puts them there. `permissions`
|
|
129
|
+
* lists the capabilities the role grants — at request time the middleware
|
|
130
|
+
* unions the permissions of every role in `ctx.auth.roles` so a policy can ask
|
|
124
131
|
* `ctx.auth.can(permission)` rather than enumerate roles.
|
|
125
132
|
*/
|
|
126
133
|
interface Role {
|
|
@@ -138,4 +145,4 @@ interface Role {
|
|
|
138
145
|
interface RlsOptions {
|
|
139
146
|
readonly roles?: ReadonlyArray<Role>;
|
|
140
147
|
}
|
|
141
|
-
export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a,
|
|
148
|
+
export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, RlsOptions as b, Permission as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };
|
|
@@ -32,7 +32,7 @@ type PolicyDecision = WhereInput | boolean | undefined;
|
|
|
32
32
|
* generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
|
|
33
33
|
* read policy may now return a Prisma-style relation predicate (the
|
|
34
34
|
* `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
|
|
35
|
-
* authoring surface accepts `WhereOf
|
|
35
|
+
* authoring surface accepts `WhereOf<DM, REL, T>` — column predicates **and**
|
|
36
36
|
* `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
|
|
37
37
|
* addition to the `boolean`/`undefined` decisions. Used by the project-bound
|
|
38
38
|
* `definePolicy` from `createPolicyDsl`.
|
|
@@ -51,8 +51,12 @@ interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T ext
|
|
|
51
51
|
when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Context handed to a policy. `auth.roles` is the per-request role list,
|
|
55
|
-
*
|
|
54
|
+
* Context handed to a policy. `auth.roles` is the per-request role list, read
|
|
55
|
+
* from the `roles` CLAIM on the resolved identity — a `string[]` or a
|
|
56
|
+
* comma-separated string returned by `WorkerOptions.resolveIdentity` (and
|
|
57
|
+
* validated by `defineIdentity(...)` at the worker's trust boundary). A
|
|
58
|
+
* resolver that forwards no `roles` claim yields no roles, so every
|
|
59
|
+
* role-branched policy is evaluated against `[]`. `auth.can`
|
|
56
60
|
* answers whether any of those roles grants a permission (see
|
|
57
61
|
* {@link Permission} / {@link RlsOptions}). `row` is present only on write
|
|
58
62
|
* policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
|
|
@@ -117,10 +121,13 @@ interface Permission {
|
|
|
117
121
|
readonly name: string;
|
|
118
122
|
}
|
|
119
123
|
/**
|
|
120
|
-
* A role declaration. Roles are string labels
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
+
* A role declaration. Roles are string labels the request carries in the
|
|
125
|
+
* `roles` claim of its resolved identity — `WorkerOptions.resolveIdentity`
|
|
126
|
+
* forwards every non-`userId` key verbatim, so a resolver returning
|
|
127
|
+
* `{ userId, roles: ["admin"] }` (or the comma-joined `"user,admin"` that
|
|
128
|
+
* better-auth's `admin()` plugin stores) is what puts them there. `permissions`
|
|
129
|
+
* lists the capabilities the role grants — at request time the middleware
|
|
130
|
+
* unions the permissions of every role in `ctx.auth.roles` so a policy can ask
|
|
124
131
|
* `ctx.auth.can(permission)` rather than enumerate roles.
|
|
125
132
|
*/
|
|
126
133
|
interface Role {
|
|
@@ -138,4 +145,4 @@ interface Role {
|
|
|
138
145
|
interface RlsOptions {
|
|
139
146
|
readonly roles?: ReadonlyArray<Role>;
|
|
140
147
|
}
|
|
141
|
-
export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a,
|
|
148
|
+
export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, RlsOptions as b, Permission as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };
|
package/dist/rls/testing.d.mts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-
|
|
1
|
+
import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-B7FLdYUD.mjs";
|
|
2
2
|
import "../data-model.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* The slice of a request identity a policy reads. Mirrors the
|
|
5
5
|
* `PolicyContext.auth` shape the middleware builds at request time — every
|
|
6
6
|
* field is optional and defaults the same way the middleware defaults it
|
|
7
|
-
* (`userId`/`identity` → `null`, `roles` → `
|
|
7
|
+
* (`userId`/`identity` → `null`, `roles` → the `roles` claim on `identity`).
|
|
8
|
+
*
|
|
9
|
+
* There is deliberately NO separate `roles` field: `auth.roles` is derived from
|
|
10
|
+
* the identity claims by the same `readIdentityRoles` the middleware uses, so
|
|
11
|
+
* the harness cannot set up a world the runtime is unable to produce. Give a
|
|
12
|
+
* role-branched policy its roles the way production does —
|
|
13
|
+
* `.as({ identity: { roles: ["admin"] }, userId: "u1" })`.
|
|
8
14
|
*/
|
|
9
15
|
interface TestIdentity {
|
|
10
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Raw identity claims a policy may branch on (`auth.identity.email`, …).
|
|
18
|
+
* The `roles` claim (a `string[]` or a comma-separated string) is what
|
|
19
|
+
* populates `auth.roles` and backs `auth.can(...)`.
|
|
20
|
+
*/
|
|
11
21
|
identity?: Record<string, unknown> | null;
|
|
12
|
-
/** Role labels the request carries; resolved to permissions via the harness `roles` registry. */
|
|
13
|
-
roles?: ReadonlyArray<string>;
|
|
14
22
|
/** The caller id (`auth.userId`); `null`/omitted is the anonymous caller. */
|
|
15
23
|
userId?: null | string;
|
|
16
24
|
}
|
package/dist/rls/testing.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-
|
|
1
|
+
import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-BCtjbIzl.js";
|
|
2
2
|
import "../data-model.js";
|
|
3
3
|
/**
|
|
4
4
|
* The slice of a request identity a policy reads. Mirrors the
|
|
5
5
|
* `PolicyContext.auth` shape the middleware builds at request time — every
|
|
6
6
|
* field is optional and defaults the same way the middleware defaults it
|
|
7
|
-
* (`userId`/`identity` → `null`, `roles` → `
|
|
7
|
+
* (`userId`/`identity` → `null`, `roles` → the `roles` claim on `identity`).
|
|
8
|
+
*
|
|
9
|
+
* There is deliberately NO separate `roles` field: `auth.roles` is derived from
|
|
10
|
+
* the identity claims by the same `readIdentityRoles` the middleware uses, so
|
|
11
|
+
* the harness cannot set up a world the runtime is unable to produce. Give a
|
|
12
|
+
* role-branched policy its roles the way production does —
|
|
13
|
+
* `.as({ identity: { roles: ["admin"] }, userId: "u1" })`.
|
|
8
14
|
*/
|
|
9
15
|
interface TestIdentity {
|
|
10
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Raw identity claims a policy may branch on (`auth.identity.email`, …).
|
|
18
|
+
* The `roles` claim (a `string[]` or a comma-separated string) is what
|
|
19
|
+
* populates `auth.roles` and backs `auth.can(...)`.
|
|
20
|
+
*/
|
|
11
21
|
identity?: Record<string, unknown> | null;
|
|
12
|
-
/** Role labels the request carries; resolved to permissions via the harness `roles` registry. */
|
|
13
|
-
roles?: ReadonlyArray<string>;
|
|
14
22
|
/** The caller id (`auth.userId`); `null`/omitted is the anonymous caller. */
|
|
15
23
|
userId?: null | string;
|
|
16
24
|
}
|
package/dist/rls/testing.mjs
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const expectPolicy = (policies, options = {}) => {
|
|
4
|
-
const rolePermissions = indexRolePermissions(options.roles);
|
|
5
|
-
const context = options.ctx ?? {};
|
|
6
|
-
return {
|
|
7
|
-
as: (identity) => {
|
|
8
|
-
const auth = identity ?? {};
|
|
9
|
-
const roles = auth.roles ?? [];
|
|
10
|
-
const granted = /* @__PURE__ */ new Set();
|
|
11
|
-
for (const roleName of roles) {
|
|
12
|
-
for (const name of rolePermissions.get(roleName) ?? []) {
|
|
13
|
-
granted.add(name);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const baseContext = {
|
|
17
|
-
auth: {
|
|
18
|
-
can: (permission) => granted.has(permissionName(permission)),
|
|
19
|
-
// eslint-disable-next-line unicorn/no-null -- PolicyContext.auth.identity is a public `… | null` type, mirroring the middleware
|
|
20
|
-
identity: auth.identity ?? null,
|
|
21
|
-
roles,
|
|
22
|
-
// eslint-disable-next-line unicorn/no-null -- PolicyContext.auth.userId is a public `null | string` type, mirroring the middleware
|
|
23
|
-
userId: auth.userId ?? null
|
|
24
|
-
},
|
|
25
|
-
ctx: context
|
|
26
|
-
};
|
|
27
|
-
const can = (op, table, row, nextRow) => {
|
|
28
|
-
const tablePolicies = policies.filter((policy) => policy.table === table);
|
|
29
|
-
if (tablePolicies.length === 0) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
if (op === "read") {
|
|
33
|
-
if (!tablePolicies.some((policy) => policy.on === "read")) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
const baseWhere = computeReadBaseWhere(tablePolicies, baseContext);
|
|
37
|
-
return baseWhere === void 0 || matchesWhere(row ?? {}, baseWhere);
|
|
38
|
-
}
|
|
39
|
-
return evaluateWrite(tablePolicies, op, { ...baseContext, row }, nextRow);
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
can,
|
|
43
|
-
cannot: (op, table, row, nextRow) => !can(op, table, row, nextRow)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { expectPolicy };
|
|
1
|
+
import{i as y,d as P,f as W,e as v,m as I,g as R}from"../packem_shared/middleware-6q14NoEG.mjs";const p=(m,o={})=>{const h=y(o.roles),x=o.ctx??{};return{as:f=>{const c=f??{},i=c.identity??null,l=P(i),u={auth:{can:W(l,h),identity:i,roles:l,userId:c.userId??null},ctx:x},d=(e,r,t,a)=>{const s=m.filter(n=>n.table===r);if(s.length===0)return!0;if(e==="read"){if(!s.some(b=>b.on==="read"))return!0;const n=v(s,u);return n===void 0||I(t??{},n)}return R(s,e,{...u,row:t},a)};return{can:d,cannot:(e,r,t,a)=>!d(e,r,t,a)}}}};export{p as expectPolicy};
|