@oimlsmart/platform-server 0.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.
Files changed (48) hide show
  1. package/README.md +92 -0
  2. package/migrations/0001_init.sql +69 -0
  3. package/migrations/0002_identity.sql +24 -0
  4. package/migrations/0003_federation_peers.sql +21 -0
  5. package/migrations/0003_users_rbac.sql +8 -0
  6. package/migrations/0004_oidc_op.sql +61 -0
  7. package/migrations/0005_upstream_providers.sql +34 -0
  8. package/migrations/0006_op_accounts.sql +28 -0
  9. package/migrations/0007_org_join_requests.sql +26 -0
  10. package/migrations/0008_op_client_roles.sql +19 -0
  11. package/migrations/0009_account_console.sql +32 -0
  12. package/migrations/0009_sso_states.sql +13 -0
  13. package/migrations/0010_notify_events.sql +23 -0
  14. package/migrations/0011_op_launch.sql +18 -0
  15. package/migrations/0011_org_memberships.sql +62 -0
  16. package/migrations/0012_notify_subscriptions.sql +57 -0
  17. package/migrations/0012_strong_auth.sql +109 -0
  18. package/migrations/0013_org_registry.sql +53 -0
  19. package/migrations/0014_notify_inbox.sql +34 -0
  20. package/migrations/0015_certificate_holder_attribution.sql +63 -0
  21. package/migrations/0016_instrument_registrations.sql +78 -0
  22. package/package.json +52 -0
  23. package/src/client-info.ts +25 -0
  24. package/src/context.ts +31 -0
  25. package/src/github.ts +284 -0
  26. package/src/mailer.ts +309 -0
  27. package/src/oidc.ts +369 -0
  28. package/src/profile/node.ts +83 -0
  29. package/src/profile.ts +582 -0
  30. package/src/rbac/node.ts +42 -0
  31. package/src/rbac.ts +53 -0
  32. package/src/session.ts +45 -0
  33. package/src/store/d1.ts +2850 -0
  34. package/src/store/sqlite/entities.ts +71 -0
  35. package/src/store/sqlite/events.ts +82 -0
  36. package/src/store/sqlite/factors-store.ts +348 -0
  37. package/src/store/sqlite/notify.ts +247 -0
  38. package/src/store/sqlite/op-accounts-store.ts +470 -0
  39. package/src/store/sqlite/op-store.ts +280 -0
  40. package/src/store/sqlite/schema.sql +745 -0
  41. package/src/store/sqlite/store.ts +1390 -0
  42. package/src/store/sqlite/upstream-store.ts +148 -0
  43. package/src/store/sqlite.ts +1027 -0
  44. package/src/store.ts +1826 -0
  45. package/src/vocab/index.ts +12 -0
  46. package/src/vocab/permissions.ts +398 -0
  47. package/src/vocab/rbac.ts +281 -0
  48. package/src/vocab/roles.ts +162 -0
package/src/session.ts ADDED
@@ -0,0 +1,45 @@
1
+ // ═══════════════════════════════════════════════════════════════════
2
+ // The session seam (TODO.identity-extract/01, the map: PROGRESS/41
3
+ // §1.4): the `oiml-session` cookie + the store's getSessionUser,
4
+ // unified from the per-router inline copies (routes/auth.ts, op.ts,
5
+ // op-accounts.ts and their nine federation/entity siblings). The cookie
6
+ // name is the contract — live sessions survive the extraction.
7
+ //
8
+ // WORKER-SAFE: hono's cookie/adapter helpers only, no node built-ins.
9
+ // The public signatures take the structural KernelContext (see
10
+ // context.ts) — never hono's own Context — so the consumer's and the
11
+ // kernel's hono instances never meet nominally.
12
+ // ═══════════════════════════════════════════════════════════════════
13
+
14
+ import type { Context } from 'hono'
15
+ import { getCookie } from 'hono/cookie'
16
+ import { env as runtimeEnv } from 'hono/adapter'
17
+ import { getStore, type AuthUserPayload } from './store'
18
+ import type { KernelContext } from './context'
19
+
20
+ export type { KernelContext } from './context'
21
+
22
+ export const SESSION_COOKIE = 'oiml-session'
23
+
24
+ /** The session's user payload for the request, or null (no cookie or
25
+ * an expired/unknown token). */
26
+ export async function sessionUser(c: KernelContext): Promise<AuthUserPayload | null> {
27
+ // The cast is the seam: a KernelContext IS a hono Context at runtime
28
+ // (every caller passes one); the structural type only keeps the two
29
+ // hono module instances from meeting in the type graph.
30
+ const token = getCookie(c as Context, SESSION_COOKIE)
31
+ return token ? getStore().getSessionUser(token) : null
32
+ }
33
+
34
+ /** The cookie posture follows the request's runtime env (hono/adapter
35
+ * reads c.env on the Worker, process.env on node — the one env seam
36
+ * both platforms share, TODO.cs-e2e/14). */
37
+ export function sessionCookieOpts(c: KernelContext) {
38
+ return {
39
+ httpOnly: true,
40
+ secure: runtimeEnv<{ NODE_ENV?: string }>(c as Context).NODE_ENV === 'production',
41
+ sameSite: 'Lax' as const,
42
+ maxAge: 7 * 24 * 60 * 60,
43
+ path: '/',
44
+ }
45
+ }