@wtfalch/foundry 0.19.0 → 0.20.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.
@@ -3,6 +3,11 @@ import type { DeclaredOrg, HostingBuildPack } from '../org.js';
3
3
  import type { DeclaredOrgStore } from '../store.js';
4
4
  import { type BrokerPort } from './broker-entries.js';
5
5
  import { type StepAction } from './diff.js';
6
+ import { type AccessPort, type EdgePlatformAccess } from './edge-access.js';
7
+ import { type DnsPort, type EdgePlatformDns } from './edge-dns.js';
8
+ import { type EdgePlatformRateLimits, type RateLimitPort } from './edge-ratelimits.js';
9
+ import { type EdgePlatformTunnels, type TunnelPort } from './edge-tunnels.js';
10
+ import { type EdgePlatformZones, type ZonePort } from './edge-zones.js';
6
11
  import { type LoginHostBindingsPort } from './login-host.js';
7
12
  import { type MailCopyPort } from './mail-copy.js';
8
13
  import type { DestroyTarget, StepDestroyer, StepExecutionContext, StepExecutor } from './plan-apply.js';
@@ -415,8 +420,10 @@ export interface CoolifyPort {
415
420
  }>;
416
421
  }
417
422
  /**
418
- * The Cloudflare calls this executor makes, shaped to match
419
- * `@wtfalch/providers/cloudflare`'s `CloudflareClient` method-for-method.
423
+ * The Cloudflare zone calls the platform steps make directly, shaped to match
424
+ * `@wtfalch/providers/cloudflare`'s `CloudflareClient` method-for-method. They
425
+ * run before edge exists (edge's own step finds the apex zone), so they cannot
426
+ * go through edge. An org's steps use {@link ZonePort}, which does.
420
427
  */
421
428
  export interface CloudflarePort {
422
429
  findZoneByApex(domain: string): Promise<{
@@ -427,132 +434,6 @@ export interface CloudflarePort {
427
434
  id: string;
428
435
  name: string;
429
436
  }>;
430
- findTunnelByName(name: string): Promise<{
431
- id: string;
432
- name: string;
433
- } | undefined>;
434
- createTunnel(name: string): Promise<{
435
- id: string;
436
- name: string;
437
- }>;
438
- putTunnelConfig(tunnelId: string, config: unknown): Promise<unknown>;
439
- /**
440
- * The tunnel's connector token (#197) -- a `cloudflared` container reads
441
- * this at boot to dial into the tunnel. A live credential: matches
442
- * `@wtfalch/providers`' `CloudflareClient.getTunnelToken` method-for-method.
443
- * A caller must hand this straight to `bulkUpsertEnvs` and nowhere else --
444
- * never a log, an error, a return value or a recorded scope id (see
445
- * `cloudflared-connector.ts`'s `ensureCloudflaredConnector`).
446
- */
447
- getTunnelToken(tunnelId: string): Promise<string>;
448
- /** `FoundryPlanApply.destroy`'s teardown of the org's own Cloudflare tunnel. */
449
- deleteTunnel(tunnelId: string): Promise<void>;
450
- /** `cloudflareAccess` finds the org's Access app by domain before creating one (#84). */
451
- listAccessApps(): Promise<Array<{
452
- id: string;
453
- name: string;
454
- domain: string;
455
- }>>;
456
- createAccessApp(app: {
457
- name: string;
458
- domain: string;
459
- type: string;
460
- }): Promise<{
461
- id: string;
462
- }>;
463
- listAccessPolicies(appId: string): Promise<Array<{
464
- id: string;
465
- name: string;
466
- include?: unknown[];
467
- }>>;
468
- createAccessPolicy(appId: string, policy: {
469
- name: string;
470
- decision: string;
471
- include: unknown[];
472
- }): Promise<{
473
- id: string;
474
- }>;
475
- /**
476
- * `cloudflareAccess` resolves a `kind: 'service-token'` rule's named
477
- * token to its id (#246) -- the token itself is a live Cloudflare
478
- * resource this package never mints; `undefined` when no token by that
479
- * name exists yet.
480
- */
481
- findServiceTokenByName(name: string): Promise<{
482
- id: string;
483
- } | undefined>;
484
- deleteAccessApp(appId: string): Promise<void>;
485
- /**
486
- * `FoundryPlanApply.destroy`'s teardown of any DNS record foundry created
487
- * for the org -- `destroy`'s `cloudflare:tunnel` case uses it to remove
488
- * every CNAME {@link publishTunnelDnsRecords} published (#236).
489
- */
490
- deleteDnsRecord(zoneId: string, recordId: string): Promise<void>;
491
- /** `coolify:mail`'s lookup of an existing MX/TXT record before upserting it, filtered by type so a stale record of a different type is never mistaken for a match. */
492
- findDnsRecord(zoneId: string, name: string, type?: string): Promise<Array<{
493
- id: string;
494
- type: string;
495
- content: string;
496
- name: string;
497
- }>>;
498
- /**
499
- * #236: `destroy`'s `cloudflare:tunnel` case and
500
- * {@link FoundryStepExecutor.deleteStaleTunnelDnsRecords} each fall back to
501
- * this for a domain recorded before
502
- * {@link CLOUDFLARE_TUNNEL_DNS_HOSTNAMES_SCOPE_KEY} existed, with no
503
- * hostname list to look up instead -- the one case left that must still
504
- * see every CNAME in the zone, not one matched by name. Round 3: this is
505
- * no longer either caller's normal path, since the real adapter
506
- * (`@wtfalch/providers`' `cloudflare.ts`) asks for one page of 100 and
507
- * never walks `result_info.total_pages`, so a zone with more records than
508
- * that would silently lose everything past the first page.
509
- */
510
- listDnsRecords(zoneId: string, opts?: {
511
- type?: string;
512
- name?: string;
513
- }): Promise<Array<{
514
- id: string;
515
- type: string;
516
- content: string;
517
- name: string;
518
- }>>;
519
- createDnsRecord(zoneId: string, rec: {
520
- type: string;
521
- name: string;
522
- content: string;
523
- proxied?: boolean;
524
- ttl?: number;
525
- /** Required by Cloudflare for an `MX` record. */
526
- priority?: number;
527
- }): Promise<{
528
- id: string;
529
- name: string;
530
- content: string;
531
- }>;
532
- updateDnsRecord(zoneId: string, recordId: string, rec: {
533
- type: string;
534
- name: string;
535
- content: string;
536
- proxied?: boolean;
537
- ttl?: number;
538
- priority?: number;
539
- }): Promise<{
540
- id: string;
541
- name: string;
542
- content: string;
543
- }>;
544
- /**
545
- * Escape hatch (mirrors `CoolifyPort.raw`'s own precedent above) --
546
- * `@wtfalch/providers` 0.5.0's `CloudflareClient` has no typed method for
547
- * Health Checks or zone rulesets/rate-limiting rules
548
- * (https://github.com/wtfalch/foundry/issues/43), only this public,
549
- * generic `request<T>(method, path, body?, missingOkay?)`, which
550
- * this port names directly rather than inventing a narrower method no real
551
- * client could structurally satisfy. `cloudflareRateLimit` below is its one
552
- * caller today. `missingOkay` makes a 404 resolve to `undefined` instead of
553
- * throwing, matching `CloudflareClient`'s own real behavior exactly.
554
- */
555
- request<T>(method: string, path: string, body?: unknown, missingOkay?: boolean): Promise<T>;
556
437
  }
557
438
  /**
558
439
  * One Cloudflare Workers rate limiting binding, Cloudflare's own "simple"
@@ -569,7 +450,8 @@ export interface WorkersRateLimitBinding {
569
450
  };
570
451
  }
571
452
  /**
572
- * The Cloudflare Workers calls `cloudflareWorker` makes (#318, F8): deploys
453
+ * The Workers calls `cloudflareWorker` makes (#318, F8), served by edge's
454
+ * `platform.workers` through `createEdgeWorkers` (`edge-workers.ts`): deploys
573
455
  * a plain Worker from an entry's `worker` declaration and routes it on the
574
456
  * org's own zone. Optional on {@link FoundryStepExecutorPorts} -- a host
575
457
  * with no Workers rights on its Cloudflare token (the issue's own "Human
@@ -583,15 +465,13 @@ export interface WorkersRateLimitBinding {
583
465
  * package (estate DECISIONS.md, 2026-10-04, "offline.tf Worker setup" --
584
466
  * "Foundry consumes and deploys the artifact through the provider
585
467
  * boundary... No manual build step and no source checkout/bundling in
586
- * Foundry"). The real adapter refuses a fetched body whose digest does not
587
- * match. The upload itself is a multipart request Cloudflare's API wants (a
588
- * `metadata` part naming `main_module` and `bindings`, plus the module) --
589
- * `CloudflarePort.request` sends JSON only, so this port names the call
590
- * directly rather than forcing it through that escape hatch.
468
+ * Foundry"). The host hands `createEdgeWorkers` a `fetchArtifact(url, sha256)`
469
+ * that fetches and verifies the bytes; the adapter sends them to edge as
470
+ * base64 with the digest, and edge checks the digest again.
591
471
  *
592
472
  * `deleteRoute`/`deleteScript` are idempotent: deleting a route or script
593
473
  * that is already gone resolves rather than throwing, the same contract
594
- * `CloudflarePort.deleteDnsRecord`/`deleteAccessApp` give their own
474
+ * `DnsPort.deleteDnsRecord`/`deleteAccessApp` give their own
595
475
  * already-gone case via `isNotFoundError` at the call site -- here it is
596
476
  * the port's own job, since `cloudflareWorker` deletes a route or script by
597
477
  * id/name it already recorded, with nothing live to re-check first.
@@ -1373,6 +1253,37 @@ export interface EdgePort {
1373
1253
  secret: string;
1374
1254
  }>;
1375
1255
  revokeKey(organisationId: string, keyId: string): Promise<void>;
1256
+ /**
1257
+ * F4.dns: edge's platform DNS client (`createEdgeClient({ baseUrl, key
1258
+ * }).platform.dns`), built with the same platform key that mints and
1259
+ * revokes. Foundry reads and writes every DNS record through it.
1260
+ */
1261
+ dns: EdgePlatformDns;
1262
+ /**
1263
+ * F4.tunnels: edge's platform tunnel client (`createEdgeClient({ baseUrl,
1264
+ * key }).platform.tunnels`), built with the same platform key. Foundry
1265
+ * creates, configures, reads the token of and deletes every tunnel through it.
1266
+ */
1267
+ tunnels: EdgePlatformTunnels;
1268
+ /**
1269
+ * F4.access: edge's platform Access client (`createEdgeClient({ baseUrl,
1270
+ * key }).platform.access`), built with the same platform key. Foundry
1271
+ * finds, creates, adopts and deletes every Access app, and adds its
1272
+ * policies, through it.
1273
+ */
1274
+ access: EdgePlatformAccess;
1275
+ /**
1276
+ * F4.ratelimits: edge's platform rate limiting client (`createEdgeClient({
1277
+ * baseUrl, key }).platform.ratelimits`), built with the same platform key.
1278
+ * Foundry lists, adopts and creates every rate limiting rule through it.
1279
+ */
1280
+ ratelimits: EdgePlatformRateLimits;
1281
+ /**
1282
+ * F4.zones: edge's platform zones client (`createEdgeClient({ baseUrl,
1283
+ * key }).platform.zones`), built with the same platform key. Foundry
1284
+ * looks up and creates every org zone through it.
1285
+ */
1286
+ zones: EdgePlatformZones;
1376
1287
  /** Refuses a label any hosting entry of `organisationId` already holds. Rerun whenever the org's own label set changes. */
1377
1288
  setReservedLabels(organisationId: string, labels: string[]): Promise<void>;
1378
1289
  }
@@ -1420,7 +1331,6 @@ export interface PlatformOrgPortSource {
1420
1331
  }
1421
1332
  export interface FoundryStepExecutorPorts {
1422
1333
  coolify: CoolifyPort;
1423
- cloudflare: CloudflarePort;
1424
1334
  zitadel: ZitadelPort;
1425
1335
  mail: MailPort;
1426
1336
  lettermint: LettermintPort;
@@ -1455,6 +1365,31 @@ export interface FoundryStepExecutorPorts {
1455
1365
  * throw.
1456
1366
  */
1457
1367
  edge?: EdgePort;
1368
+ /**
1369
+ * F4.dns: overrides the DNS calls, which otherwise go through `edge.dns`
1370
+ * (see {@link EdgePort.dns}). Kept for a host or a test that supplies its own.
1371
+ */
1372
+ dns?: DnsPort;
1373
+ /**
1374
+ * F4.tunnels: overrides the tunnel calls, which otherwise go through
1375
+ * `edge.tunnels` (see {@link EdgePort.tunnels}). Kept for a host or a test that supplies its own.
1376
+ */
1377
+ tunnels?: TunnelPort;
1378
+ /**
1379
+ * F4.access: overrides the Access calls, which otherwise go through
1380
+ * `edge.access` (see {@link EdgePort.access}). Kept for a host or a test that supplies its own.
1381
+ */
1382
+ access?: AccessPort;
1383
+ /**
1384
+ * F4.ratelimits: overrides the rate limiting rule calls, which otherwise go through
1385
+ * `edge.ratelimits` (see {@link EdgePort.ratelimits}). Kept for a host or a test that supplies its own.
1386
+ */
1387
+ ratelimits?: RateLimitPort;
1388
+ /**
1389
+ * F4.zones: overrides the zone calls, which otherwise go through
1390
+ * `edge.zones` (see {@link EdgePort.zones}). Kept for a host or a test that supplies its own.
1391
+ */
1392
+ zones?: ZonePort;
1458
1393
  /**
1459
1394
  * #177: builds the files, AI and jobs ports from the platform's addresses
1460
1395
  * and held keys. A port set above overrides it (tests); with neither, the
@@ -1579,6 +1514,12 @@ export declare const databaseStartWait: {
1579
1514
  };
1580
1515
  export declare class FoundryStepExecutor implements StepExecutor, StepDestroyer {
1581
1516
  private readonly ports;
1517
+ private edgeDns;
1518
+ private edgeTunnels;
1519
+ private edgeAccess;
1520
+ private edgeRateLimits;
1521
+ private edgeZones;
1522
+ private edgeWriteSlot;
1582
1523
  constructor(ports: FoundryStepExecutorPorts);
1583
1524
  execute(action: StepAction, context: StepExecutionContext): Promise<{
1584
1525
  resourceId?: string;
@@ -1615,12 +1556,10 @@ export declare class FoundryStepExecutor implements StepExecutor, StepDestroyer
1615
1556
  * gate), so `org.domain` is set and that zone is the org's alone, never
1616
1557
  * shared with another org the way `oikos.host` is.
1617
1558
  *
1618
- * Rate limiting rules attach to a zone's `http_ratelimit` phase entry
1619
- * point ruleset, one `GET`/`PUT` pair per zone (`@wtfalch/providers` 0.5.0
1620
- * has no typed method for either -- `CloudflarePort.request`'s own doc
1621
- * comment) -- so "find by name" here means reading that one ruleset's
1622
- * `rules[]` and matching `RATE_LIMIT_RULE_DESCRIPTION`, the same shape
1623
- * `cloudflareAccess` above finds its own Access app by name. The Free
1559
+ * Rate limiting rules go through edge (`RateLimitPort`) -- so "find by
1560
+ * name" here means listing the zone's rules and matching
1561
+ * `RATE_LIMIT_RULE_DESCRIPTION`, the same shape `cloudflareAccess` above
1562
+ * finds its own Access app by name. The Free
1624
1563
  * plan allows exactly one rule per zone, so a rule already there under a
1625
1564
  * different description is refused, never adopted or replaced, mirroring
1626
1565
  * `cloudflareAccess`'s own refusal when a foreign Access app already
@@ -2228,6 +2167,18 @@ export declare class FoundryStepExecutor implements StepExecutor, StepDestroyer
2228
2167
  * so an existing one is always re-written.
2229
2168
  */
2230
2169
  private ensureCallsFileStorage;
2170
+ /**
2171
+ * The chat service's introspection client: an API app in the org's
2172
+ * messaging project (the audience Agora's token carries), so ZITADEL's
2173
+ * introspection accepts it. The chat service authenticates as it with
2174
+ * `client_secret_basic`. Minted once, the way {@link callsTokenEnvs} does:
2175
+ * the id is recorded under an undelivered key and persisted before the
2176
+ * secret leaves, the secret goes to `deliverSecret` and to the caller's env
2177
+ * write, never to a log, error or return beyond that. A re-run reads the id
2178
+ * and secret back from the service's own env and mints nothing. `changed`
2179
+ * is true only for a fresh mint.
2180
+ */
2181
+ private ensureChatIntrospection;
2231
2182
  /**
2232
2183
  * Creates the `chat.admin` role on the org's messaging project and grants
2233
2184
  * it to each owner whose invite is recorded (`zitadel:owner:<orgId>:<email>`,
@@ -2407,6 +2358,36 @@ export declare class FoundryStepExecutor implements StepExecutor, StepDestroyer
2407
2358
  /** #177: the host's own port when it supplies one, else the platform's, built from its address and held key. */
2408
2359
  private filesPort;
2409
2360
  private aiPort;
2361
+ /**
2362
+ * Every DNS record call runs through edge (`edge.dns`, the platform
2363
+ * credential), adopting live records before it first changes them. `dns` on
2364
+ * the ports is a seam for a host or test that supplies its own {@link DnsPort}.
2365
+ */
2366
+ private dnsPort;
2367
+ /**
2368
+ * Every tunnel call runs through edge (`edge.tunnels`, the platform
2369
+ * credential), adopting a live tunnel before it first configures, reads the
2370
+ * token of or deletes it. Shares edge's write slot with {@link dnsPort}.
2371
+ */
2372
+ private tunnelPort;
2373
+ /**
2374
+ * Every Access call runs through edge (`edge.access`, the platform
2375
+ * credential), adopting a live app before it first adds a policy to or
2376
+ * deletes it. Shares edge's write slot with {@link dnsPort}.
2377
+ */
2378
+ private accessPort;
2379
+ /**
2380
+ * Every rate limiting rule call runs through edge (`edge.ratelimits`, the
2381
+ * platform credential), adopting the live rule before it first creates it.
2382
+ * Shares edge's write slot with {@link dnsPort}.
2383
+ */
2384
+ private rateLimitPort;
2385
+ /**
2386
+ * Every zone lookup and create runs through edge (`edge.zones`, the
2387
+ * platform credential), adopting a live zone before it first creates it.
2388
+ * Shares edge's write slot with {@link dnsPort}.
2389
+ */
2390
+ private zonePort;
2410
2391
  private jobsPort;
2411
2392
  private jobsRegistration;
2412
2393
  /** `deliverSecret`, tried up to {@link JOBS_DELIVERY_ATTEMPTS} times; true once one attempt succeeds. */
@@ -2635,7 +2616,7 @@ export declare class FoundryStepExecutor implements StepExecutor, StepDestroyer
2635
2616
  * a record someone proxied by hand is put back. An `MX` record carries the
2636
2617
  * priority it was given, which Cloudflare requires.
2637
2618
  *
2638
- * Found by an exact name+type match (`CloudflarePort.findDnsRecord`'s own
2619
+ * Found by an exact name+type match (`DnsPort.findDnsRecord`'s own
2639
2620
  * doc comment) so a stale record of a different type is never taken for a
2640
2621
  * match. A name can hold several `TXT` records (an apex often holds a site
2641
2622
  * verification beside SPF), so a `TXT` record only replaces one that