@geekmidas/cloud 10.0.0-alpha.14 → 10.0.0-alpha.140

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.
@@ -19,6 +19,8 @@ import type {
19
19
  Declaration,
20
20
  DeclarationKind,
21
21
  Dependency,
22
+ SecretDeclaration,
23
+ SecretFormat,
22
24
  SiteDeclaration,
23
25
  } from '@geekmidas/manifest';
24
26
  import {
@@ -26,11 +28,17 @@ import {
26
28
  cookieDomain,
27
29
  DEFAULT_POSTGRES_VERSION,
28
30
  dependentsOf,
31
+ isWildcardSite,
32
+ mobileOrigins,
29
33
  PUBLIC,
30
34
  PUBLIC_PREFIX,
31
35
  providedKeyFor,
32
36
  provisionOrder,
37
+ SECRET_LENGTH,
38
+ SECRET_SYMBOLS,
39
+ schemeBase,
33
40
  } from '@geekmidas/manifest';
41
+ import { RandomPassword } from '@pulumi/random';
34
42
  import {
35
43
  Cache,
36
44
  CacheIsAmbiguous,
@@ -39,15 +47,19 @@ import {
39
47
  withCacheTable,
40
48
  } from './aws/Cache';
41
49
  import { Credential } from './aws/Credential';
42
- import { Database, DatabaseNeedsVpc } from './aws/Database';
50
+ import { Cron, type CronSchedule } from './aws/Cron';
51
+ import { Database, DatabaseNeedsVpc, type DatabaseProps } from './aws/Database';
43
52
  import { DatabaseBootstrap } from './aws/DatabaseBootstrap';
44
53
  import { DatabaseReader, DatabaseSchema } from './aws/DerivedDatabase';
45
54
  import { Email, EmailNeedsSender } from './aws/Email';
55
+ import { Encryption, type EncryptionProps } from './aws/Encryption';
56
+ import { ExternalApi, type ExternalApiProps } from './aws/ExternalApi';
46
57
  import { FileServer } from './aws/FileServer';
58
+ import { Function } from './aws/Function';
47
59
  import { ObjectStorage } from './aws/ObjectStorage';
48
60
  import { Queue } from './aws/Queue';
49
61
  import { RestApiSurface } from './aws/RestApiSurface';
50
- import { Secret } from './aws/Secret';
62
+ import { Secret, type SecretProps } from './aws/Secret';
51
63
  import { StaticSite } from './aws/StaticSite';
52
64
  import { Topic } from './aws/Topic';
53
65
  import {
@@ -56,6 +68,7 @@ import {
56
68
  UnresolvedDependency,
57
69
  } from './errors';
58
70
  import type { GkmLinkable } from './Linkable';
71
+ import type { ManifestBackends, ManifestOverrides } from './overrides';
59
72
  import type { StackType } from './Stack';
60
73
 
61
74
  /**
@@ -105,6 +118,8 @@ export interface ProvisionContext {
105
118
  */
106
119
  cache?: 'upstash' | 'elasticache' | 'db';
107
120
  email?: 'resend' | 'ses' | 'smtp';
121
+ /** The labels no tenant of a wildcard site may take. */
122
+ protectedSubdomains?: readonly string[];
108
123
  /**
109
124
  * One deferred caller list per surface, resolved once everything exists.
110
125
  *
@@ -133,21 +148,6 @@ type Provisioner = (
133
148
  context: ProvisionContext,
134
149
  ) => Provisioned;
135
150
 
136
- /**
137
- * Provider-specific props, per construct id.
138
- *
139
- * Neutral options — `versioned`, and later `cdn` — travel in the declaration,
140
- * because the app legitimately has an opinion about them. Anything with S3 in
141
- * its name does not belong in application code, so lifecycle rules, CORS, and
142
- * canned ACLs are supplied here, in the deploy layer, keyed by the id they
143
- * apply to and typed against the component that receives them.
144
- *
145
- * A third escape hatch needs no API at all: `fromManifest` returns the
146
- * components, so `provisioned.Uploads.nodes.bucket` is reachable for anything
147
- * neither route covers.
148
- */
149
- export type ComponentOverrides = Record<string, Record<string, unknown>>;
150
-
151
151
  /**
152
152
  * Which component provisions which kind.
153
153
  *
@@ -189,7 +189,15 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
189
189
  return new StaticSite(stack, d.id, {
190
190
  path: d.app.path,
191
191
  variant: d.variant,
192
- environment: siteEnvironment(d, context),
192
+ environment: siteEnvironment(d, context, stack),
193
+ // Every subdomain, on one distribution: see `StaticSite`.
194
+ ...(isWildcardSite(d)
195
+ ? {
196
+ tenants: {
197
+ protectedSubdomains: context.protectedSubdomains ?? [],
198
+ },
199
+ }
200
+ : {}),
193
201
  ...props,
194
202
  });
195
203
  },
@@ -220,7 +228,11 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
220
228
  // rather than whatever Aurora defaults to that month. Local ran 18
221
229
  // while this ran 17.7, and neither was written down anywhere.
222
230
  version: String(d.version ?? DEFAULT_POSTGRES_VERSION),
223
- ...(props as unknown as sst.aws.PostgresArgs),
231
+ // `DatabaseProps`, not `sst.aws.PostgresArgs`: the database needs the
232
+ // `Vpc` component itself (its bootstrap function runs in the same VPC
233
+ // and needs the security groups too), where RDS would accept bare
234
+ // subnet ids. TS 7 checks the spread; 6 let the wider type through.
235
+ ...(props as unknown as Omit<DatabaseProps, 'schema'>),
224
236
  });
225
237
 
226
238
  // A database needs its own roles, not just its tenants'. Registering only
@@ -237,6 +249,10 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
237
249
  schema: d.schema,
238
250
  runtime,
239
251
  owner: ownerRole(runtime),
252
+ ownsDatabase: true,
253
+ // RDS ships PostGIS, so the image is not a question here — only the
254
+ // `CREATE EXTENSION`, which the master can run and the owner cannot.
255
+ ...(d.extensions?.length ? { extensions: d.extensions } : {}),
240
256
  ...(hasReader(d.id, context) ? { reader: readerRole(runtime) } : {}),
241
257
  });
242
258
 
@@ -370,17 +386,12 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
370
386
  },
371
387
 
372
388
  /**
373
- * The surface, without its routes.
374
- *
375
- * An API Gateway with no routes 404s everything, and that is the honest
376
- * state: the *surface* is what this kind declares, and mounting handlers on
377
- * it is the endpoint merge that has not landed — routes still reach the
378
- * deploy target through the separate `RouteInfo[]` pipeline.
389
+ * The surface, without its routes yet.
379
390
  *
380
- * Provisioning it anyway is not ceremony. Its address is what a site inlines
381
- * as `VITE_API_URL`, what an auth server puts on its trusted-origin list, and
382
- * what the cookie domain derives from — so everything downstream of the API
383
- * is blocked on the API *existing*, not on it answering.
391
+ * Its address is what a site inlines as `VITE_API_URL`, what an auth server
392
+ * puts on its trusted-origin list, and what the cookie domain derives from —
393
+ * so it is provisioned in order, and its endpoints are mounted by
394
+ * {@link mountRoutes} once everything they link to exists.
384
395
  */
385
396
  'rest-api': (stack, d, props, context) =>
386
397
  new RestApiSurface(stack, d.id, {
@@ -388,10 +399,41 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
388
399
  callers: context.callers?.get(d.id)?.promise,
389
400
  }),
390
401
 
391
- secret: (stack, d, props) => new Secret(stack, d.id, props),
402
+ // Generated on the first deploy and kept in the stage's state, as a server
403
+ // stage keeps it in its secrets: every later deploy reads the same value
404
+ // back. One set with `sst secret set` wins over it.
405
+ secret: (stack, d, props) =>
406
+ new Secret(stack, d.id, {
407
+ placeholder: generatedSecret(d.id, d as SecretDeclaration),
408
+ ...(props as SecretProps),
409
+ }),
392
410
 
393
411
  // The same storage as a secret, under a different role — see the component.
394
412
  credential: (stack, d, props) => new Credential(stack, d.id, props),
413
+
414
+ // In the stage's region, as mail is: a key in another region is a key
415
+ // every call crosses the world to reach.
416
+ encryption: (stack, d, props) =>
417
+ new Encryption(stack, d.id, {
418
+ ...(props as Partial<EncryptionProps>),
419
+ region:
420
+ (props as Partial<EncryptionProps>).region ??
421
+ $app.providers?.aws?.region ??
422
+ 'us-east-1',
423
+ }),
424
+
425
+ // Nothing to provision: the URL this stage calls, and the credentials kept
426
+ // as a secret.
427
+ 'external-api': (stack, d, props) => {
428
+ if (d.kind !== 'external-api') {
429
+ throw new UnknownDeclarationKind(d.kind, []);
430
+ }
431
+
432
+ return new ExternalApi(stack, d.id, {
433
+ ...(props as Partial<ExternalApiProps>),
434
+ url: d.url,
435
+ });
436
+ },
395
437
  };
396
438
 
397
439
  /**
@@ -410,10 +452,25 @@ const PROVISIONERS: Partial<Record<DeclarationKind, Provisioner>> = {
410
452
  export function siteEnvironment(
411
453
  declaration: SiteDeclaration,
412
454
  context: ProvisionContext,
455
+ stack?: StackType,
413
456
  ): Record<string, $util.Input<string>> {
414
457
  const prefix = PUBLIC_PREFIX[declaration.variant];
415
458
  const environment: Record<string, $util.Input<string>> = {};
416
459
 
460
+ // A wildcard site takes its tenant off the host it is reached on, so it
461
+ // inlines the domain to take the label off against, and the labels no
462
+ // tenant may be — the same two keys `publicEnvFor` names locally.
463
+ if (isWildcardSite(declaration) && stack?.domain) {
464
+ const own = {
465
+ domain: stack.domain,
466
+ protectedSubdomains: (context.protectedSubdomains ?? []).join(','),
467
+ };
468
+ for (const [role, value] of Object.entries(own)) {
469
+ environment[`${prefix}${providedKeyFor(declaration.id, 'site', role)}`] =
470
+ value;
471
+ }
472
+ }
473
+
417
474
  for (const edge of declaration.dependencies) {
418
475
  const target = context.manifest[edge.target];
419
476
  if (!target) continue;
@@ -572,9 +629,7 @@ function rootCluster(component: Provisioned): Database {
572
629
  * printed: one line per route, naming what it can reach.
573
630
  *
574
631
  * A surface with no routes says so rather than printing nothing, because "no
575
- * routes yet" and "this printed nothing" look identical otherwise — and for an
576
- * application's own API that is currently the true state, pending the endpoint
577
- * merge.
632
+ * routes" and "this printed nothing" look identical otherwise.
578
633
  *
579
634
  * Pure, so what gets printed can be asserted without a deploy.
580
635
  */
@@ -587,8 +642,8 @@ export function describeRoutes(manifest: ConstructManifest): string[] {
587
642
  lines.push(`${id}:`);
588
643
 
589
644
  if (declaration.endpoints.length === 0) {
590
- // Empty is now genuinely empty: the build folds discovered routes into
591
- // the surface that serves them, so a surface with none has none.
645
+ // Empty is genuinely empty: discovery nests every route in the
646
+ // surface that serves it, so a surface with none has none.
592
647
  lines.push(' (no routes)');
593
648
  }
594
649
 
@@ -602,11 +657,11 @@ export function describeRoutes(manifest: ConstructManifest): string[] {
602
657
  );
603
658
  }
604
659
 
605
- // A caller relationship, printed apart from the routes because it grants
606
- // nothing — see `RestApiDeclaration.calls`.
607
- if (declaration.calls?.length) {
660
+ // What authenticates it, printed apart from the routes because it grants
661
+ // nothing: the auth server learns this surface's origin.
662
+ if (declaration.auth) {
608
663
  lines.push(
609
- ` calls ${declaration.calls.map((edge) => edge.target).join(', ')} (origin only; grants nothing)`,
664
+ ` auth ${declaration.auth.target} (origin only; grants nothing)`,
610
665
  );
611
666
  }
612
667
  }
@@ -643,6 +698,8 @@ async function callersOf(
643
698
  id: string,
644
699
  manifest: ConstructManifest,
645
700
  provisioned: ProvisionedManifest,
701
+ /** The app's name — a mobile caller's scheme base when it gives none. */
702
+ project: string,
646
703
  ): Promise<{ trustedOrigins: string; cookieDomain?: string }> {
647
704
  // Every address here is a Pulumi output, not a string — a CloudFront domain
648
705
  // and an API Gateway endpoint are both known only after their resource
@@ -667,8 +724,17 @@ async function callersOf(
667
724
  const own = await resolved(provisioned[id]?.provides().url);
668
725
  const domain = cookieDomain([...(own ? [own] : []), ...origins]);
669
726
 
727
+ // A mobile caller is reached by its scheme — the bare one, deployed: what
728
+ // the store build registers.
729
+ const schemes = dependentsOf(manifest, id).flatMap((caller) => {
730
+ const app = manifest[caller];
731
+ return app?.kind === 'mobile-app'
732
+ ? mobileOrigins(schemeBase(project, app.scheme))
733
+ : [];
734
+ });
735
+
670
736
  return {
671
- trustedOrigins: origins.join(','),
737
+ trustedOrigins: [...origins, ...schemes].join(','),
672
738
  ...(domain ? { cookieDomain: domain } : {}),
673
739
  };
674
740
  }
@@ -718,6 +784,229 @@ export function isServed(id: string, manifest: ConstructManifest): boolean {
718
784
  );
719
785
  }
720
786
 
787
+ /**
788
+ * Kinds the in-order pass skips.
789
+ *
790
+ * - `mobile-app` ships through EAS and the stores. It is in the manifest for
791
+ * what it makes the surfaces trust, which `callersOf` reads off the graph.
792
+ * - `worker` is a process, not a resource: what it runs is provisioned as
793
+ * what it is — a queue's consumer by {@link subscribeConsumers}.
794
+ * - `cron` and `function` are Lambdas linked to what they depend on, so they
795
+ * are provisioned once all of it exists, by {@link provisionCompute}.
796
+ * - `telemetry` provisions nothing: where it goes is the stage's
797
+ * `deploy.telemetry`, a provider somebody else runs.
798
+ */
799
+ export const PROVISIONED_ELSEWHERE: ReadonlySet<DeclarationKind> =
800
+ new Set<DeclarationKind>([
801
+ 'mobile-app',
802
+ 'worker',
803
+ 'cron',
804
+ 'function',
805
+ 'telemetry',
806
+ ]);
807
+
808
+ /**
809
+ * Every function and cron: a Lambda running the handler the build wrote,
810
+ * linked to exactly what it depends on, in the database's network when it
811
+ * reaches one. A cron is that Lambda on its schedule; a function is reached
812
+ * at its URL, which only callers granted IAM access can invoke.
813
+ *
814
+ * After everything else is provisioned, because each links to things
815
+ * `provisionOrder` does not order before it.
816
+ */
817
+ export function provisionCompute(
818
+ stack: StackType,
819
+ manifest: ConstructManifest,
820
+ provisioned: ProvisionedManifest,
821
+ ): Cron[] {
822
+ const crons: Cron[] = [];
823
+
824
+ for (const [id, declaration] of Object.entries(manifest)) {
825
+ if (declaration?.kind !== 'function' && declaration?.kind !== 'cron') {
826
+ continue;
827
+ }
828
+
829
+ const { link } = resolveEdges(declaration.dependencies, provisioned);
830
+ const vpc = vpcFor(link);
831
+ const lambda = new Function(
832
+ stack,
833
+ declaration.kind === 'cron' ? `${id}Function` : id,
834
+ {
835
+ name: stack.logicalPrefixedName(id),
836
+ handler: declaration.handler,
837
+ link,
838
+ ...(vpc ? { vpc } : {}),
839
+ ...(declaration.kind === 'function'
840
+ ? { url: { authorization: 'iam' } }
841
+ : {}),
842
+ },
843
+ );
844
+
845
+ if (declaration.kind === 'cron') {
846
+ crons.push(
847
+ new Cron(stack, id, {
848
+ processor: lambda,
849
+ schedule: declaration.schedule as CronSchedule,
850
+ }),
851
+ );
852
+ continue;
853
+ }
854
+
855
+ assertProvides(
856
+ id,
857
+ declaration.provides,
858
+ Object.keys(lambda.provides()).map((role) =>
859
+ providedKeyFor(id, declaration.kind, role),
860
+ ),
861
+ );
862
+ provisioned[id] = lambda;
863
+ }
864
+
865
+ return crons;
866
+ }
867
+
868
+ /**
869
+ * Every file server's processors: each a Lambda behind a function URL with
870
+ * IAM auth, served through the file server's router on its pattern's prefix
871
+ * — so the CDN signs each request (origin access control) and the URL cannot
872
+ * be called around the cache. Linked to the bucket it reads and what it
873
+ * depends on; its native packages installed for the Lambda, not bundled.
874
+ *
875
+ * After everything else, for the reason {@link provisionCompute} is.
876
+ */
877
+ export function provisionProcessors(
878
+ stack: StackType,
879
+ manifest: ConstructManifest,
880
+ provisioned: ProvisionedManifest,
881
+ ): Function[] {
882
+ const lambdas: Function[] = [];
883
+
884
+ for (const [id, declaration] of Object.entries(manifest)) {
885
+ if (declaration?.kind !== 'file-server') continue;
886
+ const router = provisioned[id];
887
+ if (!router) continue;
888
+
889
+ for (const processor of declaration.processors ?? []) {
890
+ const { link } = resolveEdges(processor.dependencies, provisioned);
891
+ const vpc = vpcFor(link);
892
+ const native = processor.native ?? [];
893
+ lambdas.push(
894
+ new Function(stack, `${id}${processor.id}`, {
895
+ name: stack.logicalPrefixedName(`${id}${processor.id}`),
896
+ handler: processor.handler,
897
+ link,
898
+ ...(vpc ? { vpc } : {}),
899
+ ...(processor.timeout !== undefined
900
+ ? {
901
+ timeout:
902
+ `${Math.ceil(processor.timeout / 1000)} seconds` as sst.aws.FunctionArgs['timeout'],
903
+ }
904
+ : {}),
905
+ ...(processor.memorySize !== undefined
906
+ ? {
907
+ memory:
908
+ `${processor.memorySize} MB` as sst.aws.FunctionArgs['memory'],
909
+ }
910
+ : {}),
911
+ ...(native.length ? { nodejs: { install: [...native] } } : {}),
912
+ url: {
913
+ authorization: 'iam',
914
+ router: {
915
+ instance: router as unknown as sst.aws.Router,
916
+ path: processor.prefix.replace(/\/$/, ''),
917
+ },
918
+ },
919
+ }),
920
+ );
921
+ }
922
+ }
923
+
924
+ return lambdas;
925
+ }
926
+
927
+ /** A provisioned queue: what {@link subscribeConsumers} subscribes through. */
928
+ interface Consumable {
929
+ consume(consumer: {
930
+ handler: string;
931
+ link?: unknown[];
932
+ vpc?: sst.aws.Vpc;
933
+ }): unknown;
934
+ }
935
+
936
+ /**
937
+ * The network a function has to run in to reach what it links to.
938
+ *
939
+ * A database is private to its VPC, so a handler linked to one — or to a
940
+ * schema tenant or reader of one — runs inside it, or its connection times out.
941
+ */
942
+ export function vpcFor(link: readonly Provisioned[]): sst.aws.Vpc | undefined {
943
+ for (const component of link) {
944
+ const cluster = rootCluster(component);
945
+ if (cluster instanceof Database) return cluster.vpc;
946
+ }
947
+
948
+ return undefined;
949
+ }
950
+
951
+ /**
952
+ * Mount every surface's endpoints — the handlers the build wrote, each linked
953
+ * to exactly what that endpoint depends on.
954
+ *
955
+ * After every construct is provisioned, for the reason consumers are: an
956
+ * endpoint links to things `provisionOrder` does not order before its surface.
957
+ */
958
+ export function mountRoutes(
959
+ manifest: ConstructManifest,
960
+ provisioned: ProvisionedManifest,
961
+ ): void {
962
+ for (const [id, declaration] of Object.entries(manifest)) {
963
+ if (declaration?.kind !== 'rest-api') continue;
964
+
965
+ const surface = provisioned[id];
966
+ if (!(surface instanceof RestApiSurface)) continue;
967
+
968
+ for (const endpoint of declaration.endpoints) {
969
+ const { link } = resolveEdges(endpoint.dependencies, provisioned);
970
+ const vpc = vpcFor(link);
971
+ surface.mount({
972
+ method: endpoint.method,
973
+ path: endpoint.path,
974
+ handler: endpoint.handler,
975
+ link,
976
+ ...(vpc ? { vpc } : {}),
977
+ ...(endpoint.authorizer ? { authorizer: endpoint.authorizer } : {}),
978
+ });
979
+ }
980
+ }
981
+ }
982
+
983
+ /**
984
+ * Subscribe every queue's one consumer — the handler the build wrote for it,
985
+ * linked to what that consumer depends on.
986
+ *
987
+ * After every construct is provisioned, because a consumer links to things
988
+ * that `provisionOrder` does not order before the queue.
989
+ */
990
+ export function subscribeConsumers(
991
+ manifest: ConstructManifest,
992
+ provisioned: ProvisionedManifest,
993
+ ): void {
994
+ for (const [id, declaration] of Object.entries(manifest)) {
995
+ if (declaration?.kind !== 'queue') continue;
996
+
997
+ const queue = provisioned[id] as unknown as Consumable | undefined;
998
+ if (!queue) continue;
999
+
1000
+ const { link } = resolveEdges(declaration.worker.dependencies, provisioned);
1001
+ const vpc = vpcFor(link);
1002
+ queue.consume({
1003
+ handler: declaration.worker.handler,
1004
+ link,
1005
+ ...(vpc ? { vpc } : {}),
1006
+ });
1007
+ }
1008
+ }
1009
+
721
1010
  /** The provisioner for a kind. Pure — the lookup is testable without Pulumi. */
722
1011
  export function provisionerFor(kind: DeclarationKind): Provisioner {
723
1012
  const provisioner = PROVISIONERS[kind];
@@ -756,20 +1045,34 @@ export function assertProvides(
756
1045
  * tenant, a read replica, and the surface over a bucket all resolve an address
757
1046
  * off something else, and a pass in map order would find it half the time.
758
1047
  */
759
- export function fromManifest(
1048
+ export function fromManifest<
1049
+ const M extends ConstructManifest,
1050
+ const B extends ManifestBackends = {},
1051
+ >(
760
1052
  stack: StackType,
761
- manifest: ConstructManifest,
762
- overrides: ComponentOverrides = {},
1053
+ manifest: M,
1054
+ /**
1055
+ * Provider-specific props, per construct id — typed from the manifest, so
1056
+ * only its ids are keys, each takes what its kind's component reads, and
1057
+ * what the synth cannot guess (a database's `vpc`, mail's `from`) is
1058
+ * required. See {@link ManifestOverrides}.
1059
+ *
1060
+ * Neutral options — `versioned`, `fifo` — travel in the declaration,
1061
+ * because the app legitimately has an opinion about them. Anything with S3
1062
+ * in its name does not belong in application code, so it is supplied here.
1063
+ * A third escape hatch needs no API: the components are returned, so
1064
+ * `provisioned.Uploads.nodes.bucket` is reachable for anything else.
1065
+ */
1066
+ overrides: ManifestOverrides<M, B>,
763
1067
  /**
764
1068
  * The backend choices that are config rather than declaration.
765
1069
  *
766
1070
  * Defaulted the same way the local target defaults them, so a stage deployed
767
- * without saying gets the same backend a developer ran against.
1071
+ * without saying gets the same backend a developer ran against. Typed
1072
+ * literally, because the backend decides what is required above: an
1073
+ * ElastiCache cache needs a `vpc`, Resend or SMTP mail a `url`.
768
1074
  */
769
- backends: {
770
- cache?: 'upstash' | 'elasticache' | 'db';
771
- email?: 'resend' | 'ses' | 'smtp';
772
- } = {},
1075
+ backends: B = {} as B,
773
1076
  ): ProvisionedManifest {
774
1077
  const provisioned: ProvisionedManifest = {};
775
1078
 
@@ -801,16 +1104,20 @@ export function fromManifest(
801
1104
  bootstraps: new Map<string, DatabaseBootstrap>(),
802
1105
  ...(backends.cache ? { cache: backends.cache } : {}),
803
1106
  ...(backends.email ? { email: backends.email } : {}),
1107
+ ...(backends.protectedSubdomains
1108
+ ? { protectedSubdomains: backends.protectedSubdomains }
1109
+ : {}),
804
1110
  };
805
1111
 
806
1112
  for (const id of [...rest, ...sites]) {
807
1113
  const declaration = manifest[id];
808
1114
  if (!declaration) continue;
1115
+ if (PROVISIONED_ELSEWHERE.has(declaration.kind)) continue;
809
1116
 
810
1117
  const component = provisionerFor(declaration.kind)(
811
1118
  stack,
812
1119
  declaration,
813
- overrides[id] ?? {},
1120
+ (overrides as Record<string, Record<string, unknown>>)[id] ?? {},
814
1121
  context,
815
1122
  );
816
1123
 
@@ -829,6 +1136,13 @@ export function fromManifest(
829
1136
  provisioned[id] = component;
830
1137
  }
831
1138
 
1139
+ // The functions and crons, each queue's one consumer and each surface's
1140
+ // endpoints, once everything they link to exists.
1141
+ provisionCompute(stack, manifest, provisioned);
1142
+ provisionProcessors(stack, manifest, provisioned);
1143
+ subscribeConsumers(manifest, provisioned);
1144
+ mountRoutes(manifest, provisioned);
1145
+
832
1146
  for (const line of describeRoutes(manifest)) console.log(line);
833
1147
 
834
1148
  // Now everything exists, so every surface's callers can be resolved — the
@@ -836,7 +1150,7 @@ export function fromManifest(
836
1150
  for (const [id, deferred] of callers) {
837
1151
  // Resolved with the promise itself: the addresses it needs are Pulumi
838
1152
  // outputs, so the answer arrives when they do.
839
- deferred.resolve(callersOf(id, manifest, provisioned));
1153
+ deferred.resolve(callersOf(id, manifest, provisioned, $app.name));
840
1154
  }
841
1155
 
842
1156
  // Last, and only now: the roles exist as passwords and secrets from the
@@ -851,6 +1165,30 @@ export function fromManifest(
851
1165
  return provisioned;
852
1166
  }
853
1167
 
1168
+ /**
1169
+ * A secret in its declared format — the alphabet `drawSecret` draws from on
1170
+ * every other stage, with one symbol guaranteed as it guarantees one.
1171
+ *
1172
+ * The format is fixed at the first deploy, as a server stage's is: changing it
1173
+ * would replace the password, and every later deploy is meant to read back the
1174
+ * one it had.
1175
+ */
1176
+ function generatedSecret(id: string, format: SecretFormat) {
1177
+ const symbols = [...new Set(format.symbols ?? SECRET_SYMBOLS)].join('');
1178
+
1179
+ return new RandomPassword(
1180
+ `${id}Generated`,
1181
+ {
1182
+ length: format.length ?? SECRET_LENGTH,
1183
+ special: symbols.length > 0,
1184
+ ...(symbols ? { overrideSpecial: symbols, minSpecial: 1 } : {}),
1185
+ },
1186
+ {
1187
+ ignoreChanges: ['length', 'special', 'overrideSpecial', 'minSpecial'],
1188
+ },
1189
+ ).result;
1190
+ }
1191
+
854
1192
  /** What one function receives from its edges. */
855
1193
  export interface ResolvedEdges {
856
1194
  /** The components it may reach. SST turns these into IAM *and* injects their
package/src/sst/index.ts CHANGED
@@ -34,6 +34,7 @@ export {
34
34
  } from './aws/DatabaseBootstrap';
35
35
  export { DatabaseReader, DatabaseSchema } from './aws/DerivedDatabase';
36
36
  export { Email, EmailNeedsUrl, type EmailProps } from './aws/Email';
37
+ export { Encryption, type EncryptionProps } from './aws/Encryption';
37
38
  export { FileServer, type FileServerProps } from './aws/FileServer';
38
39
  export { Function, type FunctionProps } from './aws/Function';
39
40
  export {
@@ -58,10 +59,10 @@ export {
58
59
  ProvidesMismatch,
59
60
  UnknownDeclarationKind,
60
61
  UnresolvedDependency,
62
+ WildcardSiteNeedsDomain,
61
63
  } from './errors';
62
64
  export {
63
65
  assertProvides,
64
- type ComponentOverrides,
65
66
  describeRoutes,
66
67
  fromManifest,
67
68
  isServed,
@@ -75,4 +76,9 @@ export {
75
76
  } from './fromManifest';
76
77
  export { type GkmLinkable, ResourceType } from './Linkable';
77
78
  export { kebab, prefixedName, regionOfArn } from './naming';
79
+ export type {
80
+ ManifestBackends,
81
+ ManifestOverrides,
82
+ OverrideFor,
83
+ } from './overrides';
78
84
  export { Stack, type StackType } from './Stack';