@plitzi/sdk-kernel 0.0.0-stage → 0.39.2

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 (142) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +80 -2
  3. package/dist/build/esbuild.d.ts +16 -0
  4. package/dist/build/index.d.ts +1 -0
  5. package/dist/build/index.mjs +35 -0
  6. package/dist/cache/CompressedFileCache.d.ts +18 -0
  7. package/dist/cache/TtlCache.d.ts +65 -0
  8. package/dist/cache/index.d.ts +3 -0
  9. package/dist/cache/index.mjs +1 -0
  10. package/dist/chunks/TtlCache-J_jG9oL9.mjs +200 -0
  11. package/dist/chunks/channel-DnVf7PJB.mjs +190 -0
  12. package/dist/chunks/csrf-BLWcaYOV.mjs +295 -0
  13. package/dist/chunks/link-C9wyDS9H.mjs +124 -0
  14. package/dist/chunks/query-DGbrN3mN.mjs +20 -0
  15. package/dist/chunks/scopes-Co6ZjhAm.mjs +46 -0
  16. package/dist/chunks/serverLog-BKaKjjc4.mjs +137 -0
  17. package/dist/chunks/session-B-dTEjeG.mjs +253 -0
  18. package/dist/chunks/sessionActivity-Ch7xuQ_o.mjs +43 -0
  19. package/dist/chunks/spaceDeployment-J2IMLfij.mjs +76 -0
  20. package/dist/chunks/stage-y6deE9LJ.mjs +345 -0
  21. package/dist/chunks/supervisor-Dh34v1vq.mjs +117 -0
  22. package/dist/chunks/tail-D-USrZIR.mjs +55 -0
  23. package/dist/chunks/tokens-CBd5tXut.mjs +262 -0
  24. package/dist/data/index.d.ts +2 -0
  25. package/dist/data/index.mjs +68 -0
  26. package/dist/data/projectData.d.ts +21 -0
  27. package/dist/deployment/hostDeployment.d.ts +8 -0
  28. package/dist/deployment/index.d.ts +3 -0
  29. package/dist/deployment/index.mjs +19 -0
  30. package/dist/deployment/spaceDeployment.d.ts +11 -0
  31. package/dist/engine/index.d.ts +2 -0
  32. package/dist/engine/index.mjs +1 -0
  33. package/dist/engine/page.d.ts +49 -0
  34. package/dist/engine/rsc.d.ts +32 -0
  35. package/dist/files/atomicFile.d.ts +10 -0
  36. package/dist/files/index.d.ts +1 -0
  37. package/dist/files/index.mjs +32 -0
  38. package/dist/http/bearer.d.ts +5 -0
  39. package/dist/http/buildResponseHelpers.d.ts +23 -0
  40. package/dist/http/closeOnSignals.d.ts +28 -0
  41. package/dist/http/compress.d.ts +20 -0
  42. package/dist/http/dispatcher.d.ts +15 -0
  43. package/dist/http/drain.d.ts +18 -0
  44. package/dist/http/fleet/channel.d.ts +103 -0
  45. package/dist/http/fleet/link.d.ts +28 -0
  46. package/dist/http/fleet/role.d.ts +46 -0
  47. package/dist/http/fleet/supervisor.d.ts +29 -0
  48. package/dist/http/freePort.d.ts +24 -0
  49. package/dist/http/health.d.ts +21 -0
  50. package/dist/http/index.d.ts +48 -0
  51. package/dist/http/index.mjs +1313 -0
  52. package/dist/http/middlewares/auth.d.ts +2 -0
  53. package/dist/http/middlewares/basicAuth.d.ts +6 -0
  54. package/dist/http/mimeTypes.d.ts +13 -0
  55. package/dist/http/navigation.d.ts +14 -0
  56. package/dist/http/onAbort.d.ts +12 -0
  57. package/dist/http/probes.d.ts +4 -0
  58. package/dist/http/requestParser.d.ts +22 -0
  59. package/dist/http/runMiddlewares.d.ts +6 -0
  60. package/dist/http/securityHeaders.d.ts +18 -0
  61. package/dist/http/server.d.ts +39 -0
  62. package/dist/http/socketResponse.d.ts +18 -0
  63. package/dist/http/sse.d.ts +26 -0
  64. package/dist/http/stages/crossSiteWrites.d.ts +24 -0
  65. package/dist/http/stages/health.d.ts +11 -0
  66. package/dist/http/stages/middlewares.d.ts +3 -0
  67. package/dist/http/stages/static.d.ts +4 -0
  68. package/dist/http/staticFiles.d.ts +3 -0
  69. package/dist/http/stopping.d.ts +11 -0
  70. package/dist/http/transports.d.ts +31 -0
  71. package/dist/http/types.d.ts +29 -0
  72. package/dist/http/unusedPort.d.ts +10 -0
  73. package/dist/http/webExchange.d.ts +18 -0
  74. package/dist/http/wsFrame.d.ts +3 -0
  75. package/dist/identity/accounts.d.ts +278 -0
  76. package/dist/identity/authorize.d.ts +96 -0
  77. package/dist/identity/credentials.d.ts +40 -0
  78. package/dist/identity/csrf.d.ts +139 -0
  79. package/dist/identity/debugAuthorization.d.ts +24 -0
  80. package/dist/identity/domains.d.ts +41 -0
  81. package/dist/identity/identity.d.ts +119 -0
  82. package/dist/identity/index.d.ts +21 -0
  83. package/dist/identity/index.mjs +731 -0
  84. package/dist/identity/passwords.d.ts +15 -0
  85. package/dist/identity/previewToken.d.ts +21 -0
  86. package/dist/identity/requestIdentity.d.ts +14 -0
  87. package/dist/identity/scopes.d.ts +56 -0
  88. package/dist/identity/session.d.ts +185 -0
  89. package/dist/identity/sessionActivity.d.ts +11 -0
  90. package/dist/identity/spaceTokens.d.ts +174 -0
  91. package/dist/index.d.ts +17 -0
  92. package/dist/index.mjs +1 -0
  93. package/dist/log/index.d.ts +3 -0
  94. package/dist/log/index.mjs +3 -0
  95. package/dist/log/serverLog.d.ts +49 -0
  96. package/dist/log/tail.d.ts +43 -0
  97. package/dist/mysql/accounts.d.ts +4 -0
  98. package/dist/mysql/admin.d.ts +58 -0
  99. package/dist/mysql/config.d.ts +82 -0
  100. package/dist/mysql/identities.d.ts +35 -0
  101. package/dist/mysql/index.d.ts +7 -0
  102. package/dist/mysql/index.mjs +1203 -0
  103. package/dist/mysql/pool.d.ts +3 -0
  104. package/dist/mysql/query.d.ts +12 -0
  105. package/dist/mysql/schema.d.ts +43 -0
  106. package/dist/mysql/sessions.d.ts +23 -0
  107. package/dist/mysql/spaceTokens.d.ts +11 -0
  108. package/dist/mysql/store.d.ts +66 -0
  109. package/dist/outbound/index.d.ts +4 -0
  110. package/dist/outbound/index.mjs +314 -0
  111. package/dist/outbound/inside.d.ts +36 -0
  112. package/dist/outbound/outboundGuard.d.ts +69 -0
  113. package/dist/pubsub/index.d.ts +3 -0
  114. package/dist/pubsub/index.mjs +76 -0
  115. package/dist/pubsub/memoryPubSub.d.ts +10 -0
  116. package/dist/pubsub/redisPubSub.d.ts +24 -0
  117. package/dist/stats/index.d.ts +9 -0
  118. package/dist/stats/index.mjs +228 -0
  119. package/dist/stats/load.d.ts +31 -0
  120. package/dist/stats/memory.d.ts +20 -0
  121. package/dist/stats/pools.d.ts +15 -0
  122. package/dist/stats/recorder.d.ts +34 -0
  123. package/dist/stats/stage.d.ts +15 -0
  124. package/dist/stats/types.d.ts +309 -0
  125. package/dist/testing/certificates.d.ts +21 -0
  126. package/dist/testing/fleet.d.ts +28 -0
  127. package/dist/testing/goneRuns.d.ts +5 -0
  128. package/dist/testing/index.d.ts +5 -0
  129. package/dist/testing/index.mjs +270 -0
  130. package/dist/testing/keys.d.ts +2 -0
  131. package/dist/testing/runNames.d.ts +10 -0
  132. package/dist/tokens/index.d.ts +2 -0
  133. package/dist/tokens/index.mjs +1 -0
  134. package/dist/tokens/tokens.d.ts +190 -0
  135. package/dist/types/adapters.d.ts +388 -0
  136. package/dist/types/config.d.ts +240 -0
  137. package/dist/types/index.d.ts +5 -0
  138. package/dist/types/index.mjs +1 -0
  139. package/dist/types/log.d.ts +119 -0
  140. package/dist/types/oauth.d.ts +246 -0
  141. package/dist/types/pipeline.d.ts +239 -0
  142. package/package.json +67 -3
@@ -0,0 +1,58 @@
1
+ import { Tables } from './config';
2
+ import { SpaceScope } from '../identity';
3
+ import { Pool } from 'mysql2/promise';
4
+ export interface AccountSeed {
5
+ username: string;
6
+ email: string;
7
+ /** Plain text, hashed here. Omit for an account that signs in through an identity provider and has no password. */
8
+ password?: string;
9
+ verified?: boolean;
10
+ /** Global roles. They must exist — `ensureRole` first, or an unknown name is a mistake worth failing on. */
11
+ roles?: string[];
12
+ }
13
+ export interface SpaceTokenSeed {
14
+ token: string;
15
+ scope?: SpaceScope;
16
+ isDefault?: boolean;
17
+ origins?: string[];
18
+ expiresAt?: number | null;
19
+ accountId?: number;
20
+ }
21
+ /**
22
+ * Everything that puts rows in these tables that no request ever will.
23
+ *
24
+ * The auth flows read accounts, roles and memberships; almost none of them create one. Signing up creates an
25
+ * account and that is the whole of it — a role, a permission, a space membership and a space's first credential all
26
+ * come from somewhere else: a seed script, an admin screen, the moment a space is created. That somewhere else
27
+ * needs statements, and a deployment writing them by hand against a schema it did not design is a deployment about
28
+ * to get a join wrong.
29
+ *
30
+ * Every operation is idempotent, because the place they are called from is usually a startup path that runs again.
31
+ */
32
+ export declare const createAdmin: (pool: Pool, t: Tables) => {
33
+ ensurePermissions: (names: string[]) => Promise<void>;
34
+ ensureRole: (name: string, options?: {
35
+ permissions?: string[];
36
+ description?: string;
37
+ }) => Promise<number>;
38
+ grantRole: (accountId: number, role: string) => Promise<void>;
39
+ revokeRole: (accountId: number, role: string) => Promise<void>;
40
+ ensureAccount: (seed: AccountSeed) => Promise<number>;
41
+ /** Membership of one space, with the role that decides what they may do inside it. */
42
+ addMember: (spaceId: number, accountId: number, role: string, options?: {
43
+ owner?: boolean;
44
+ }) => Promise<void>;
45
+ removeMember: (spaceId: number, accountId: number) => Promise<void>;
46
+ listMembers: (spaceId: number) => Promise<{
47
+ accountId: number;
48
+ username: string;
49
+ role: string;
50
+ owner: boolean;
51
+ }[]>;
52
+ /**
53
+ * A space's credential row. Replaces the default one rather than adding a second: exactly one row per space
54
+ * carries `is_default`, and two of them make `loadDefault` answer whichever the database happened to return.
55
+ */
56
+ createSpaceToken: (spaceId: number, seed: SpaceTokenSeed) => Promise<number>;
57
+ };
58
+ export type MysqlAdmin = ReturnType<typeof createAdmin>;
@@ -0,0 +1,82 @@
1
+ import { Pool, PoolOptions } from 'mysql2/promise';
2
+ /**
3
+ * Where the database is, and what this deployment calls the tables in it.
4
+ *
5
+ * `url` and the discrete fields are two ways of saying the same thing — a hosted database hands you one string, a
6
+ * docker-compose hands you five values — and the discrete fields win where both are given, so a single override
7
+ * does not mean re-assembling the URL.
8
+ */
9
+ export interface MysqlConfig {
10
+ /** `mysql://user:password@host:port/database`. Whatever a managed database hands you, unedited. */
11
+ url?: string;
12
+ host?: string;
13
+ port?: number;
14
+ user?: string;
15
+ password?: string;
16
+ database?: string;
17
+ /** Passed to the driver as given. `true` turns TLS on with the system CA set. */
18
+ ssl?: PoolOptions['ssl'];
19
+ connectionLimit?: number;
20
+ /**
21
+ * Prefix for every table below. **Required**, and deliberately so.
22
+ *
23
+ * `account`, `role`, `permission` and `session` are among the most ordinary table names there are, and this
24
+ * module exists to be pointed at a database that has other things in it. Optional, the default was the empty
25
+ * string — the one value guaranteed to collide — so the guard that refuses to adopt somebody else's tables fired
26
+ * on the common case rather than the dangerous one. A prefix you chose makes a collision mean what it says.
27
+ *
28
+ * `'plitzi_'` is a fine answer. So is your product's name. Say it once: nothing outside this module ever writes
29
+ * a table name.
30
+ */
31
+ tablePrefix: string;
32
+ /**
33
+ * Create and update the tables at startup. On by default, which is what makes a fresh database work with no step
34
+ * before it. A deployment whose database user cannot run DDL — the usual arrangement in production — turns it off
35
+ * and applies the statements from `schemaStatements()` through whatever it migrates with.
36
+ */
37
+ autoMigrate?: boolean;
38
+ /**
39
+ * Create the database itself if the server has not got it, before connecting to it. Off by default and meant for
40
+ * development, where "point it at a MySQL and go" is the whole appeal and the alternative is one `CREATE DATABASE`
41
+ * that nobody remembers until the first run fails. In production the database exists before the application does,
42
+ * made by somebody holding rights the application should not have.
43
+ */
44
+ ensureDatabase?: boolean;
45
+ /**
46
+ * Use tables with these names that already exist and were not created here.
47
+ *
48
+ * Off by default, and the default is the safe one: this module is meant to be pointed at a database that has
49
+ * unrelated tables in it, and `role`, `permission` and `session` are among the most ordinary names there are.
50
+ * `CREATE TABLE IF NOT EXISTS` would silently adopt somebody else's, and the failure would surface much later as
51
+ * a query against columns that are not there. Turn it on only when re-attaching to tables that really are this
52
+ * schema's — a restored backup whose `schema_version` row was lost, say.
53
+ */
54
+ adoptExisting?: boolean;
55
+ /** An existing pool, for a deployment that already has one. Given, nothing here creates or ends a connection. */
56
+ pool?: Pool;
57
+ log?: (message: string) => void;
58
+ }
59
+ /**
60
+ * The tables the auth kernel needs. Named after the kernel's own vocabulary — an `AccountRecord` is stored in
61
+ * `account` — rather than after any one deployment's user table, which is a thing it maps ONTO these.
62
+ */
63
+ export declare const TABLE_NAMES: {
64
+ readonly schemaVersion: "schema_version";
65
+ readonly account: "account";
66
+ readonly session: "session";
67
+ readonly identity: "account_identity";
68
+ readonly mfa: "account_mfa";
69
+ readonly otp: "account_otp";
70
+ readonly role: "role";
71
+ readonly permission: "permission";
72
+ readonly rolePermission: "role_permission";
73
+ readonly accountRole: "account_role";
74
+ readonly spaceMember: "space_member";
75
+ readonly spaceToken: "space_token";
76
+ };
77
+ export type TableKey = keyof typeof TABLE_NAMES;
78
+ /** Table names, already prefixed and already backticked — the only form the rest of the module ever sees. */
79
+ export type Tables = Record<TableKey, string>;
80
+ export declare const resolveTables: (prefix: string) => Tables;
81
+ /** The bare, unquoted names — for a migration tool, or an error that has to say which table it meant. */
82
+ export declare const tableNames: (prefix: string) => Record<TableKey, string>;
@@ -0,0 +1,35 @@
1
+ import { Tables } from './config';
2
+ import { Queryable } from './query';
3
+ /** The same person at somebody else's identity provider. */
4
+ export interface LinkedIdentity {
5
+ id: number;
6
+ provider: string;
7
+ subject: string;
8
+ email?: string;
9
+ createdAt: number;
10
+ }
11
+ /**
12
+ * External identities, as rows.
13
+ *
14
+ * Deliberately NOT part of the auth adapters: whether a Google account with a matching email is the same person is
15
+ * a judgement only a deployment can make, and it lives in `exchangeCredential` / the social `linkAccount` hook.
16
+ * What is mechanical is the storage, and a self-hoster should not have to design the table for it.
17
+ *
18
+ * The unique key is `(provider, subject)`, never the email. A provider that does not verify addresses lets anybody
19
+ * claim any account by signing up with one — which is the single most common way social linking is got wrong.
20
+ */
21
+ export declare const createIdentityStore: (db: Queryable, t: Tables) => {
22
+ find: (provider: string, subject: string) => Promise<{
23
+ accountId: number;
24
+ } | undefined>;
25
+ /** Idempotent: signing in again with the same provider identity must not be an error. */
26
+ link: (accountId: number, identity: {
27
+ provider: string;
28
+ subject: string;
29
+ email?: string;
30
+ }) => Promise<void>;
31
+ list: (accountId: number) => Promise<LinkedIdentity[]>;
32
+ /** Scoped by account, or one person could unlink another's provider by guessing a number. */
33
+ unlink: (accountId: number, provider: string) => Promise<boolean>;
34
+ };
35
+ export type IdentityStore = ReturnType<typeof createIdentityStore>;
@@ -0,0 +1,7 @@
1
+ export { createMysqlStore, dropSchema, mysqlSchemaStatements, SCHEMA_VERSION, TABLE_NAMES, tableNames } from './store';
2
+ export { resolveTables } from './config';
3
+ export { createPool } from './pool';
4
+ export { execute, selectOne, selectRows } from './query';
5
+ export { migrate } from './schema';
6
+ export type { MysqlStore, MysqlConfig, TableKey, Tables, AccountSeed, MysqlAdmin, SpaceTokenSeed, SessionStore, IdentityStore, LinkedIdentity } from './store';
7
+ export type { Queryable } from './query';