@wtfalch/foundry 0.5.0 → 0.6.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 (42) hide show
  1. package/dist/bootstrap/bootstrap.d.ts +16 -1
  2. package/dist/bootstrap/bootstrap.js +40 -2
  3. package/dist/bootstrap/declare.js +6 -1
  4. package/dist/calls-sfu-deploy-support.d.ts +8 -0
  5. package/dist/calls-sfu-deploy-support.js +10 -1
  6. package/dist/calls-sfu.d.ts +31 -8
  7. package/dist/calls-sfu.js +36 -5
  8. package/dist/index.d.ts +8 -2
  9. package/dist/index.js +5 -2
  10. package/dist/migrations/0019_mail_owner_mailbox.sql +15 -0
  11. package/dist/migrations/0020_mail_apps.sql +7 -0
  12. package/dist/migrations/0021_mail_role_mailboxes.sql +6 -0
  13. package/dist/org.d.ts +81 -0
  14. package/dist/org.js +88 -0
  15. package/dist/plan/diff.js +93 -10
  16. package/dist/plan/executor.d.ts +236 -35
  17. package/dist/plan/executor.js +274 -76
  18. package/dist/plan/index.d.ts +7 -1
  19. package/dist/plan/index.js +4 -1
  20. package/dist/plan/mail-copy.d.ts +125 -0
  21. package/dist/plan/mail-copy.js +166 -0
  22. package/dist/plan/mail-identity-allowlist.d.ts +50 -0
  23. package/dist/plan/mail-identity-allowlist.js +11 -0
  24. package/dist/plan/mail-identity.d.ts +68 -0
  25. package/dist/plan/mail-identity.js +17 -0
  26. package/dist/plan/plan-apply.d.ts +5 -0
  27. package/dist/plan/platform-diff.d.ts +184 -9
  28. package/dist/plan/platform-diff.js +368 -15
  29. package/dist/plan/platform-org.d.ts +3 -2
  30. package/dist/plan/platform-providers.d.ts +138 -24
  31. package/dist/plan/platform-providers.js +1460 -79
  32. package/dist/plan/platform-sfu.d.ts +54 -19
  33. package/dist/plan/platform-sfu.js +64 -22
  34. package/dist/plan/zitadel-machine-user.d.ts +60 -11
  35. package/dist/plan/zitadel-machine-user.js +182 -39
  36. package/dist/requested-changes.d.ts +17 -7
  37. package/dist/requested-changes.js +37 -7
  38. package/dist/store/postgres.js +31 -2
  39. package/dist/store/schema.d.ts +72 -0
  40. package/dist/store/schema.js +13 -0
  41. package/dist/store.d.ts +7 -0
  42. package/package.json +1 -1
@@ -55,6 +55,17 @@ export declare const PLATFORM_ARCHON_KEY = "platform:archon";
55
55
  */
56
56
  export declare const PLATFORM_ARCHON_APPLIED_HOSTNAME_SCOPE_KEY = "archon_applied_hostname";
57
57
  export declare const PLATFORM_ARCHON_APPLIED_GIT_REF_SCOPE_KEY = "archon_applied_git_ref";
58
+ /**
59
+ * #211 round 4: the broker app id Archon last registered its entry with.
60
+ * `provisionPlatformArchon` reads the broker to register with from
61
+ * {@link PLATFORM_AUTH_BROKER_SCOPE_KEY} alone, so a broker recreated under a
62
+ * new app id (the old one deleted by hand, or `platform:auth` minting a fresh
63
+ * one) leaves Archon "applied" against a broker that no longer holds its
64
+ * entry. `planArchon` plans the step again whenever this differs from the
65
+ * currently recorded {@link PLATFORM_AUTH_BROKER_SCOPE_KEY}, the same way a
66
+ * changed hostname or `gitRef` does.
67
+ */
68
+ export declare const PLATFORM_ARCHON_APPLIED_BROKER_SCOPE_KEY = "archon_applied_broker_app";
58
69
  /**
59
70
  * #175: set to '1' before the step points the tunnel at `http_status:404`
60
71
  * (Access app rebuild), cleared to '' once the real ingress is written back.
@@ -64,6 +75,121 @@ export declare const PLATFORM_ARCHON_APPLIED_GIT_REF_SCOPE_KEY = "archon_applied
64
75
  export declare const PLATFORM_ARCHON_GATE_CLOSED_SCOPE_KEY = "archon_gate_closed";
65
76
  export declare const PLATFORM_AUTH_ADMIN_USER_SCOPE_KEY = "zitadel_platform_admin_user_id";
66
77
  export declare const PLATFORM_AUTH_ADMIN_UNDELIVERED_SCOPE_KEY = "zitadel_platform_admin_user_undelivered";
78
+ /**
79
+ * #216 (building on #209/#215): the `IAM_LOGIN_CLIENT` machine user minted
80
+ * for the login app and the broker, mirroring
81
+ * {@link PLATFORM_AUTH_ADMIN_USER_SCOPE_KEY}/
82
+ * {@link PLATFORM_AUTH_ADMIN_UNDELIVERED_SCOPE_KEY} in shape -- a recorded
83
+ * id once delivered, an undelivered id recorded first, the moment the user
84
+ * is minted.
85
+ *
86
+ * Unlike the admin pair, an undelivered login-client key never blocks
87
+ * {@link planAuth} from planning the step again -- #216 round 2: `planAuth`
88
+ * below does read it, but only to surface a non-blocking note (alongside a
89
+ * planned step, the way #211 round 3's broker-deploy block already is)
90
+ * rather than to hold the step back. Revoking a stale login-client PAT
91
+ * destroys nothing -- unlike the admin user's, whose loss the admin pair's
92
+ * own "delete that user by hand" message exists for because nothing else
93
+ * here re-derives the ZITADEL masterkey a lost admin PAT might have been the
94
+ * only record of -- so `mintLoginClientMachineUser` (`zitadel-machine-user.ts`)
95
+ * always lists and deletes every PAT the user already holds before minting a
96
+ * fresh one. That is what lets `provisionPlatformAuth` simply re-mint on the
97
+ * next run, with no manual step, which is #216's whole fix for the bug PR
98
+ * #215 shipped with: PR #215 mirrored the admin pair's forever-blocking
99
+ * behaviour for this key too, which meant one failed Coolify call lost the
100
+ * login-client token for good.
101
+ *
102
+ * #216 round 4: the value recorded here is JSON ({@link
103
+ * PlatformAuthLoginClientRecord}, parsed back by
104
+ * {@link parseLoginClientRecord}), not the bare user id round 2-3 wrote --
105
+ * the user id alone can never tell a healthy delivery from one a concurrent
106
+ * apply has since clobbered, because `mintLoginClientMachineUser` reuses the
107
+ * same user on every mint. The PAT id travels alongside it so {@link
108
+ * planAuth} can ask ZITADEL, on every plan, whether that exact PAT is still
109
+ * the sole live one.
110
+ *
111
+ * #216 round 5: that alone is still not enough -- a recorded PAT can be the
112
+ * sole live one in ZITADEL while Coolify holds a *different*, already-dead
113
+ * token, when two concurrent applies interleave their own writes and
114
+ * records in the right (wrong) order (see `authLoginClientDrifted`'s own
115
+ * doc comment in `platform-providers.ts` for the exact ordering). So the
116
+ * record also carries `tokenHash`, a sha256 of the exact token that was
117
+ * delivered -- never the token itself -- which `authLoginClientDrifted`
118
+ * compares against what is actually live in both apps' Coolify envs.
119
+ */
120
+ export declare const PLATFORM_AUTH_LOGIN_CLIENT_USER_SCOPE_KEY = "zitadel_platform_login_client_user_id";
121
+ export declare const PLATFORM_AUTH_LOGIN_CLIENT_UNDELIVERED_SCOPE_KEY = "zitadel_platform_login_client_user_undelivered";
122
+ /**
123
+ * #216 round 4/5: what {@link PLATFORM_AUTH_LOGIN_CLIENT_USER_SCOPE_KEY}
124
+ * records once delivery succeeds -- the minted machine user's id, the exact
125
+ * PAT id that was handed to the login app and the broker, and (round 5) a
126
+ * sha256 of the exact token value, never the value itself.
127
+ */
128
+ export interface PlatformAuthLoginClientRecord {
129
+ readonly userId: string;
130
+ readonly patId: string;
131
+ readonly tokenHash: string;
132
+ }
133
+ /**
134
+ * Parses a {@link PLATFORM_AUTH_LOGIN_CLIENT_USER_SCOPE_KEY} scope id back
135
+ * into a {@link PlatformAuthLoginClientRecord}. `null` for anything that is
136
+ * not one -- absent, the pre-round-4 plain user-id string, the round 2-4
137
+ * `{userId, patId}` shape with no `tokenHash`, or corrupt JSON -- the same
138
+ * "malformed reads as unapplied, never throws" rule
139
+ * {@link parseBrokerDeployRecord} follows and for the same reason: this is a
140
+ * planning read, not a validation boundary. A pre-round-5 record reading as
141
+ * unapplied is the intended migration: the next apply's fresh mint recomputes
142
+ * it in the new shape, the same way a pre-round-4 plain-string record already
143
+ * did.
144
+ */
145
+ export declare function parseLoginClientRecord(raw: string | undefined): PlatformAuthLoginClientRecord | null;
146
+ /**
147
+ * #204/#211: the sign-in broker app `provisionPlatformAuth` creates alongside
148
+ * ZITADEL and the login app. Defined here, not in `platform-providers.ts`
149
+ * (which imports it), because `planAuth` below needs it too -- a recorded
150
+ * `coolify:app:platform:auth` key with no recorded broker id is a platform
151
+ * provisioned before #204 shipped, and must still plan the step again so the
152
+ * broker gets created rather than being read as fully applied.
153
+ */
154
+ export declare const PLATFORM_AUTH_BROKER_SCOPE_KEY = "coolify_platform_auth_broker_app";
155
+ /**
156
+ * #211: recorded once the broker has actually been deployed -- distinct from
157
+ * {@link PLATFORM_AUTH_BROKER_SCOPE_KEY} (the app exists) precisely because
158
+ * the app can exist for a while before it is ever deployed (see
159
+ * `missingBrokerInputs` in `platform-providers.ts`). Defined here, not there,
160
+ * for the same reason as {@link PLATFORM_AUTH_BROKER_SCOPE_KEY}: `planAuth`
161
+ * below needs it too, so a broker that is created but not yet deployed still
162
+ * plans the step again instead of reading as fully applied for good.
163
+ */
164
+ export declare const PLATFORM_AUTH_BROKER_DEPLOYED_SCOPE_KEY = "coolify_platform_auth_broker_deployed";
165
+ /**
166
+ * #211 round 5: what {@link PLATFORM_AUTH_BROKER_DEPLOYED_SCOPE_KEY} records
167
+ * once a deploy succeeds -- the broker app id that was deployed, and a sha256
168
+ * of the exact `AUTH_APPS` value that was live at that deploy, never the
169
+ * value itself (`platform-providers.ts`'s `hashAuthApps`: a secret must never
170
+ * reach a recorded scope id). Round 2-4 recorded a plain broker-id string
171
+ * there, which could only ever mean "deployed at least once" -- it could not
172
+ * tell a broker recreated under a new app id, or a crash between writing
173
+ * `AUTH_APPS` and deploying, from one still fully applied. This record is
174
+ * what lets `brokerDeployNeeded` (`platform-providers.ts`) and {@link planAuth}
175
+ * below answer both, from one mechanism instead of two ad hoc booleans.
176
+ */
177
+ export interface BrokerDeployRecord {
178
+ readonly brokerAppId: string;
179
+ readonly authAppsHash: string;
180
+ }
181
+ /**
182
+ * Parses a {@link PLATFORM_AUTH_BROKER_DEPLOYED_SCOPE_KEY} scope id back into
183
+ * a {@link BrokerDeployRecord}. `null` for anything that is not one --
184
+ * absent, the pre-round-5 plain broker-id string, or corrupt JSON -- because
185
+ * this is a planning read, not a validation boundary: a malformed record
186
+ * must read as "not deployed" so the step plans (and overwrites it) again,
187
+ * never throw and take the rest of the plan down with it. Exported here
188
+ * rather than defined in `platform-providers.ts` for the same reason
189
+ * {@link PLATFORM_AUTH_BROKER_DEPLOYED_SCOPE_KEY} itself was moved here in
190
+ * round 2 -- {@link planAuth} below needs it too, without a circular import.
191
+ */
192
+ export declare function parseBrokerDeployRecord(raw: string | undefined): BrokerDeployRecord | null;
67
193
  /**
68
194
  * #197: the `cloudflared` connector app `provisionPlatformAuth` runs for its
69
195
  * own tunnel. Consulted by `planAuth` below so that a tunnel recorded with no
@@ -76,6 +202,21 @@ export declare const PLATFORM_AUTH_CONNECTOR_APP_SCOPE_KEY = "coolify_platform_a
76
202
  export declare const PLATFORM_MAIL_CONNECTOR_APP_SCOPE_KEY = "coolify_platform_mail_connector_app";
77
203
  /** #197: the same connector scope id for the Archon step's own tunnel, read by `planArchon`. */
78
204
  export declare const PLATFORM_ARCHON_CONNECTOR_APP_SCOPE_KEY = "coolify_platform_archon_connector_app";
205
+ /**
206
+ * #213: the three held-key refs, under tenant `platform`, Archon's own
207
+ * onboarding reads before it can start (archon#101 round 3, archon#104).
208
+ * `planArchon`'s step puts each one, once, before Archon's app deploys; an
209
+ * entry already held is left alone, never overwritten
210
+ * (`putArchonMasterKeys` in `platform-providers.ts`). The Coolify URL and
211
+ * token are values this package already deploys with; the Cloudflare
212
+ * parent token ("API Tokens Write", so Archon can mint its own scoped
213
+ * child tokens from it) is a human-created credential the host supplies --
214
+ * neither Coolify nor Cloudflare lets either be minted over an API (#213
215
+ * "Human steps").
216
+ */
217
+ export declare const PLATFORM_ARCHON_MASTER_COOLIFY_URL_REF = "platform:master:coolify-url";
218
+ export declare const PLATFORM_ARCHON_MASTER_COOLIFY_TOKEN_REF = "platform:master:coolify-token";
219
+ export declare const PLATFORM_ARCHON_MASTER_CLOUDFLARE_TOKEN_REF = "platform:master:cloudflare-token";
79
220
  /**
80
221
  * #169: `platform:<service>` for the platform's own mail server (Stalwart),
81
222
  * mirroring {@link PLATFORM_AUTH_KEY} exactly.
@@ -150,6 +291,27 @@ export declare const PLATFORM_AI_INTERNAL_URL_SCOPE_KEY = "ai_platform_internal_
150
291
  */
151
292
  export declare const PLATFORM_AI_MANAGEMENT_KEY_SCOPE_KEY = "ai_platform_management_key_id";
152
293
  export declare const PLATFORM_AI_MANAGEMENT_KEY_UNDELIVERED_SCOPE_KEY = "ai_platform_management_key_undelivered";
294
+ /**
295
+ * #201: set when ai's `POST /v1/platform/keys` reports its `archon` key
296
+ * already exists but returns no secret -- a mint this record never learned
297
+ * about (most likely the crash window {@link PLATFORM_AI_MANAGEMENT_KEY_UNDELIVERED_SCOPE_KEY}'s
298
+ * own comment describes: the secret returned once and was never recorded).
299
+ * ai shows a credential's secret only at mint time, so it cannot be
300
+ * recovered; the planner reports this instead of minting under another
301
+ * name. A person revokes the live `archon` key in ai and removes this
302
+ * recorded key to let the step mint a fresh one.
303
+ */
304
+ export declare const PLATFORM_AI_MANAGEMENT_KEY_CONFLICT_SCOPE_KEY = "ai_platform_management_key_conflict";
305
+ /**
306
+ * #201: the same two-key discipline as {@link PLATFORM_INTEGRATIONS_KEY_UNDELIVERED_SCOPE_KEY}
307
+ * and {@link PLATFORM_INTEGRATIONS_KEY_SET_SCOPE_KEY}, for the Ed25519 pair
308
+ * foundry mints to sign its calls to ai's `POST /v1/platform/keys`. The
309
+ * undelivered key is recorded the moment the pair is minted; the set key,
310
+ * only once the private half was delivered and the public half pinned on
311
+ * the runner as `MANAGEMENT_PUBLIC_KEYS`.
312
+ */
313
+ export declare const PLATFORM_AI_SIGNING_KEY_UNDELIVERED_SCOPE_KEY = "ai_platform_signing_key_undelivered";
314
+ export declare const PLATFORM_AI_SIGNING_KEY_SET_SCOPE_KEY = "ai_platform_signing_key_set";
153
315
  /**
154
316
  * #172: ai's platform (operator) tenant id, which the management key belongs
155
317
  * to -- what ai's own README calls `AI_ORGANISATION_ID`. Not a secret.
@@ -175,14 +337,6 @@ export declare const PLATFORM_AI_MIGRATE_BLOCKED_SCOPE_KEY = "ai_platform_migrat
175
337
  * that throws) is repaired by the next one.
176
338
  */
177
339
  export declare const PLATFORM_AI_DEPLOY_PENDING_SCOPE_KEY = "ai_platform_deploy_pending";
178
- /**
179
- * #172: what the planner says while no AI management key minter is supplied.
180
- * A fixed text: it is part of the stale-plan comparison. ai issues its first
181
- * platform credential only through its `keys:issue-archon` script, run
182
- * against its database with its keys worker credential; it has no HTTP route
183
- * for that, so foundry cannot build a minter over ai's admin API yet.
184
- */
185
- export declare const PLATFORM_AI_MINTER_BLOCKED = "the platform's AI host is blocked, not planned: no AI management key minter was supplied. ai mints its first platform key only through its keys:issue-archon script against its database, so the host must supply PlatformAiDeps.managementKeyMinter";
186
340
  /**
187
341
  * #171: the resource key `planFiles` plans under and `FoundryPlatformStepExecutor`
188
342
  * dispatches on, the {@link PLATFORM_AUTH_KEY} shape for the files host.
@@ -243,6 +397,23 @@ export interface PlanPlatformOptions {
243
397
  /** Per-step block reasons the executor reports (default `{}`). */
244
398
  blocked?: {
245
399
  auth?: string;
400
+ /**
401
+ * #211 round 6: set once the auth block is "the host built the platform
402
+ * executor without its auth dependencies" -- distinct from `auth` itself,
403
+ * which also covers "the broker exists but cannot deploy yet" (#209/#210
404
+ * still pending). `planAuth` must withhold the step for the former
405
+ * whatever the recorded ids say; it must not for the latter.
406
+ */
407
+ authExecutorMissing?: boolean;
408
+ /**
409
+ * #216 round 5: the broker's required inputs other than
410
+ * `ZITADEL_SERVICE_USER_TOKEN` that are still missing (a subset of what
411
+ * `auth`'s own text already names, filtered) -- {@link planAuth} reads
412
+ * this to say, accurately, whether a needed login-client re-mint can
413
+ * actually happen on the next apply or is itself waiting on one of
414
+ * these. Default `[]`.
415
+ */
416
+ authOtherInputsMissing?: string[];
246
417
  files?: string;
247
418
  integrations?: string;
248
419
  ai?: string;
@@ -252,10 +423,14 @@ export interface PlanPlatformOptions {
252
423
  /**
253
424
  * Steps whose live state differs from the declared one in a way the recorded
254
425
  * ids cannot show (default `{}`). `archon`: the Cloudflare Access policy's
255
- * include list is not the declared one.
426
+ * include list is not the declared one. `auth` (#216 round 4): the
427
+ * login-client PAT recorded under
428
+ * {@link PLATFORM_AUTH_LOGIN_CLIENT_USER_SCOPE_KEY} is no longer the sole
429
+ * live PAT on that ZITADEL machine user.
256
430
  */
257
431
  drifted?: {
258
432
  archon?: boolean;
433
+ auth?: boolean;
259
434
  };
260
435
  }
261
436
  /**