@lunora/server 1.0.0-alpha.28 → 1.0.0-alpha.280

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.
Files changed (104) hide show
  1. package/LICENSE.md +414 -104
  2. package/README.md +21 -15
  3. package/dist/data-model.d.mts +323 -78
  4. package/dist/data-model.d.ts +323 -78
  5. package/dist/data-model.mjs +0 -1
  6. package/dist/drizzle.mjs +1 -1
  7. package/dist/in-process.d.mts +115 -0
  8. package/dist/in-process.d.ts +115 -0
  9. package/dist/in-process.mjs +1 -0
  10. package/dist/index.d.mts +3593 -1124
  11. package/dist/index.d.ts +3593 -1124
  12. package/dist/index.mjs +1 -29
  13. package/dist/otel.d.mts +597 -0
  14. package/dist/otel.d.ts +597 -0
  15. package/dist/otel.mjs +1 -0
  16. package/dist/packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-Dv4DKrj0.mjs +1 -0
  17. package/dist/packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs +1 -0
  18. package/dist/packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BCa6sLSJ.mjs +1 -0
  19. package/dist/packem_shared/LunoraEnvError-06_Zc4yc.mjs +3 -0
  20. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-aj9Ec70J.mjs +1 -0
  21. package/dist/packem_shared/PROCEDURE_META-DVzrXpfa.mjs +1 -0
  22. package/dist/packem_shared/allowAll-DkRAgItV.mjs +1 -0
  23. package/dist/packem_shared/apply-output-C5wZ5EAL.mjs +1 -0
  24. package/dist/packem_shared/asBucketStorage-DoGYOjq3.mjs +1 -0
  25. package/dist/packem_shared/assertShapesDeclareReadPolicies-C09SMvM4.mjs +1 -0
  26. package/dist/packem_shared/authorize-CVLZJxf_.mjs +1 -0
  27. package/dist/packem_shared/beginDeferredDeletes-DhwFBbvs.mjs +1 -0
  28. package/dist/packem_shared/beginDeferredSchedules-BTwq-NUO.mjs +1 -0
  29. package/dist/packem_shared/bindOrm-D5mVDvbi.mjs +1 -0
  30. package/dist/packem_shared/buildMaskRegistry-DpWMtalG.mjs +1 -0
  31. package/dist/packem_shared/compose-middleware-BK9FlblN.mjs +1 -0
  32. package/dist/packem_shared/composePluginMiddleware-3e7F9JIa.mjs +1 -0
  33. package/dist/packem_shared/context-identity-B2XYGA0B.mjs +1 -0
  34. package/dist/packem_shared/createPolicyDsl-BZa6SqLJ.mjs +1 -0
  35. package/dist/packem_shared/createSecrets-D6rLB42U.mjs +1 -0
  36. package/dist/packem_shared/createServices-IJvoqi0e.mjs +1 -0
  37. package/dist/packem_shared/defineAggregateIndex-C3xWV-Dr.mjs +1 -0
  38. package/dist/packem_shared/defineIdentity-DwkNKwYa.mjs +1 -0
  39. package/dist/packem_shared/defineIdentityGuard-Bt8N65Zs.mjs +1 -0
  40. package/dist/packem_shared/defineLiveStream-q9yO3wl6.mjs +1 -0
  41. package/dist/packem_shared/defineMigration-CXOS0Bvq.mjs +1 -0
  42. package/dist/packem_shared/defineModule-OecXWM3U.mjs +1 -0
  43. package/dist/packem_shared/defineMutator-DlLFSWbO.mjs +1 -0
  44. package/dist/packem_shared/defineRoom-CoGi-xwm.mjs +1 -0
  45. package/dist/packem_shared/defineShape-H-0IbZlb.mjs +1 -0
  46. package/dist/packem_shared/defineStorageRule-Dv4nJE0H.mjs +1 -0
  47. package/dist/packem_shared/defineWebSocket-BHoy6_ox.mjs +1 -0
  48. package/dist/packem_shared/fnv1a-D3ueNTWB.mjs +1 -0
  49. package/dist/packem_shared/functions-QFoBUe9t.mjs +1 -0
  50. package/dist/packem_shared/httpAction-Bfw3qwLG.mjs +1 -0
  51. package/dist/packem_shared/initLunora-DcvCGLL_.mjs +1 -0
  52. package/dist/packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs +1 -0
  53. package/dist/packem_shared/isSafeHeaderValue-DswDADFy.mjs +6 -0
  54. package/dist/packem_shared/mask-DHJtsP7t.mjs +1 -0
  55. package/dist/packem_shared/middleware-CHYtnvZP.mjs +1 -0
  56. package/dist/packem_shared/onConnect-BLRoOpv2.mjs +1 -0
  57. package/dist/packem_shared/onQueryChange-iuLzmyPs.mjs +1 -0
  58. package/dist/packem_shared/onWhisper-CfDbFLQh.mjs +1 -0
  59. package/dist/packem_shared/platformAdmin-kczXQme8.mjs +1 -0
  60. package/dist/packem_shared/plugin-CyLqvCB9.mjs +1 -0
  61. package/dist/packem_shared/policy-tag-V0lqFzgS.mjs +1 -0
  62. package/dist/packem_shared/protectPublic-Bi5_95aP.mjs +1 -0
  63. package/dist/packem_shared/redact-secrets-BpatNz48.mjs +2 -0
  64. package/dist/packem_shared/redactSecrets-Dmh9pHZu.mjs +1 -0
  65. package/dist/packem_shared/rls-CvWnjgtq.mjs +1 -0
  66. package/dist/packem_shared/run-middleware-BefYq7Xd.mjs +1 -0
  67. package/dist/packem_shared/serveStorageObject-CLz3qhNI.mjs +1 -0
  68. package/dist/packem_shared/storageRules-BVIXkoRg.mjs +1 -0
  69. package/dist/packem_shared/{types.d-C4CMJK8x.d.mts → types.d-B7FLdYUD.d.mts} +15 -8
  70. package/dist/packem_shared/{types.d-DdYF8E18.d.ts → types.d-BCtjbIzl.d.ts} +15 -8
  71. package/dist/packem_shared/types.d-CJnJltzy.d.mts +3025 -0
  72. package/dist/packem_shared/types.d-CJnJltzy.d.ts +3025 -0
  73. package/dist/rls/testing.d.mts +13 -5
  74. package/dist/rls/testing.d.ts +13 -5
  75. package/dist/rls/testing.mjs +1 -49
  76. package/dist/types.d.mts +2 -1373
  77. package/dist/types.d.ts +2 -1373
  78. package/dist/types.mjs +0 -31
  79. package/package.json +28 -8
  80. package/dist/packem_shared/LunoraEnvError-BGmd1Qs0.mjs +0 -187
  81. package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +0 -9
  82. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-Cv1UPaJj.mjs +0 -114
  83. package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
  84. package/dist/packem_shared/bindOrm-Bfgl7f-Q.mjs +0 -146
  85. package/dist/packem_shared/buildRlsReadRegistry-D54vUQe4.mjs +0 -107
  86. package/dist/packem_shared/composePluginMiddleware-z62dttBo.mjs +0 -103
  87. package/dist/packem_shared/createPolicyDsl-By3QB4he.mjs +0 -32
  88. package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +0 -58
  89. package/dist/packem_shared/defineAggregateIndex-DTULzh09.mjs +0 -333
  90. package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +0 -35
  91. package/dist/packem_shared/defineMigration-Hx01yIht.mjs +0 -10
  92. package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
  93. package/dist/packem_shared/defineShape-C5scNOrf.mjs +0 -18
  94. package/dist/packem_shared/defineStorageRule-B5nL4Z1P.mjs +0 -23
  95. package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
  96. package/dist/packem_shared/httpAction-DCXoYPIk.mjs +0 -355
  97. package/dist/packem_shared/initLunora-CmMVk4i7.mjs +0 -107
  98. package/dist/packem_shared/mask-CZuu9WAF.mjs +0 -331
  99. package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
  100. package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
  101. package/dist/packem_shared/protectPublic-BlcGpiRc.mjs +0 -15
  102. package/dist/packem_shared/rls-B_ZWgslr.mjs +0 -595
  103. package/dist/packem_shared/run-middleware-I6EiQfxL.mjs +0 -20
  104. package/dist/packem_shared/storageRules-6QxzDOcx.mjs +0 -88
@@ -1,16 +1,24 @@
1
- import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-C4CMJK8x.mjs";
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
- /** Raw identity claims a policy may branch on (`auth.identity.email`, …). */
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
  }
@@ -1,16 +1,24 @@
1
- import { P as PolicyOperation, R as Role, a as Policy } from "../packem_shared/types.d-DdYF8E18.js";
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
- /** Raw identity claims a policy may branch on (`auth.identity.email`, …). */
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
  }
@@ -1,49 +1 @@
1
- import { indexRolePermissions, computeReadBaseWhere, matchesWhere, evaluateWrite, permissionName } from '../packem_shared/rls-B_ZWgslr.mjs';
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,e as P,g as W,f as v,m as I,h as R}from"../packem_shared/middleware-CHYtnvZP.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};