@geekmidas/cloud 10.0.0-alpha.167 → 10.0.0-alpha.169

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/cloud",
3
- "version": "10.0.0-alpha.167",
3
+ "version": "10.0.0-alpha.169",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "lodash.snakecase": "~4.1.1",
44
- "@geekmidas/envkit": "10.0.0-alpha.167",
45
- "@geekmidas/manifest": "10.0.0-alpha.167"
44
+ "@geekmidas/envkit": "10.0.0-alpha.169",
45
+ "@geekmidas/manifest": "10.0.0-alpha.169"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/lodash.get": "~4.4.9",
@@ -58,10 +58,10 @@
58
58
  "@pulumi/aws": ">=7.47.0",
59
59
  "@pulumi/random": ">=4.21.2",
60
60
  "@pulumi/pulumi": ">=3.263.0",
61
- "@geekmidas/manifest": ">=10.0.0-alpha.167 <10.0.0",
62
- "@geekmidas/storage": ">=10.0.0-alpha.167 <10.0.0",
63
- "@geekmidas/events": ">=10.0.0-alpha.167 <10.0.0",
64
- "@geekmidas/db": ">=10.0.0-alpha.167 <10.0.0"
61
+ "@geekmidas/manifest": ">=10.0.0-alpha.169 <10.0.0",
62
+ "@geekmidas/storage": ">=10.0.0-alpha.169 <10.0.0",
63
+ "@geekmidas/events": ">=10.0.0-alpha.169 <10.0.0",
64
+ "@geekmidas/db": ">=10.0.0-alpha.169 <10.0.0"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@geekmidas/manifest": {
@@ -1,5 +1,5 @@
1
1
  import { ResourceType } from '@geekmidas/envkit/sst';
2
- import { providedKeyFor, provideKey } from '@geekmidas/manifest';
2
+ import { providedKeyFor } from '@geekmidas/manifest';
3
3
  import { describe, expect, it, vi } from 'vitest';
4
4
  import { Encryption } from '../aws/Encryption';
5
5
  import { provisionerFor, resolveEdges } from '../fromManifest';
@@ -51,7 +51,7 @@ describe('Encryption on AWS', () => {
51
51
  Object.keys(pii.provides()).map((role) =>
52
52
  providedKeyFor('Pii', 'encryption', role),
53
53
  ),
54
- ).toEqual([provideKey('Pii', 'url')]);
54
+ ).toEqual([providedKeyFor('Pii', 'encryption', 'url')]);
55
55
  expect(pii._type).toBe(ResourceType.Encryption);
56
56
  });
57
57
 
@@ -1,10 +1,6 @@
1
1
  import { resolveEnvKeys } from '@geekmidas/envkit/sst';
2
2
  import * as snsUrl from '@geekmidas/events/sns/url';
3
- import {
4
- type ConstructManifest,
5
- providedKeyFor,
6
- provideKey,
7
- } from '@geekmidas/manifest';
3
+ import { type ConstructManifest, providedKeyFor } from '@geekmidas/manifest';
8
4
  import { beforeEach, describe, expect, it } from 'vitest';
9
5
  import { type Inbox, InboxNotProvisioned, InboxTopic } from '../aws/Inbox';
10
6
  import { Topic } from '../aws/Topic';
@@ -78,10 +74,11 @@ function manifest(): ConstructManifest {
78
74
  const env = {
79
75
  REQUESTS_URL: URL,
80
76
  REQUESTS_DOMAIN: 'shop.example',
81
- [provideKey('RequestsMail', 'publisherConnectionString')]: snsUrl.build({
82
- topicArn: TOPIC_ARN,
83
- region: 'eu-west-1',
84
- }),
77
+ [providedKeyFor('RequestsMail', 'topic', 'publisherConnectionString')]:
78
+ snsUrl.build({
79
+ topicArn: TOPIC_ARN,
80
+ region: 'eu-west-1',
81
+ }),
85
82
  };
86
83
 
87
84
  beforeEach(() => {
@@ -1,5 +1,5 @@
1
1
  import { resolveEnvKeys } from '@geekmidas/envkit/sst';
2
- import { NoUrlForStage, providedKeyFor, provideKey } from '@geekmidas/manifest';
2
+ import { NoUrlForStage, providedKeyFor } from '@geekmidas/manifest';
3
3
  import { describe, expect, it } from 'vitest';
4
4
  import { App } from '../App';
5
5
  import { Cron } from '../aws/Cron';
@@ -137,7 +137,7 @@ describe('ObjectStorage', () => {
137
137
  'Uploads',
138
138
  ['UPLOADS_CONNECTION_STRING'],
139
139
  Object.keys(bucket.provides()).map((role) =>
140
- provideKey('Uploads', role),
140
+ providedKeyFor('Uploads', 'objects', role),
141
141
  ),
142
142
  ),
143
143
  ).not.toThrow();
@@ -0,0 +1,74 @@
1
+ import { type ConstructManifest, providedKeyFor } from '@geekmidas/manifest';
2
+ import { afterEach, describe, expect, it, vi } from 'vitest';
3
+ import { App } from '../App';
4
+ import { HostLabelNeedsCustomDomain } from '../errors';
5
+ import { assertNoHostLabels, fromManifest } from '../fromManifest';
6
+
7
+ /**
8
+ * Aliases and redirects on AWS: no surface but a wildcard site has a custom
9
+ * domain there, so either one fails the deploy, naming the construct, rather
10
+ * than deploying a host that never answers.
11
+ */
12
+
13
+ const keys = (id: string, kind: string, roles: string[]) =>
14
+ roles.map((role) => providedKeyFor(id, kind as never, role));
15
+
16
+ function manifest(
17
+ web: { aliases?: string[]; redirects?: string[] } = {},
18
+ ): ConstructManifest {
19
+ return {
20
+ Api: {
21
+ kind: 'rest-api',
22
+ id: 'Api',
23
+ path: 'apps/api',
24
+ endpoints: [],
25
+ provides: keys('Api', 'rest-api', [
26
+ 'url',
27
+ 'trustedOrigins',
28
+ 'cookieDomain',
29
+ ]),
30
+ },
31
+ Web: {
32
+ kind: 'site',
33
+ id: 'Web',
34
+ variant: 'static',
35
+ app: { path: 'apps/web' },
36
+ dependencies: [{ target: 'Api', kind: 'rest-api' }],
37
+ provides: keys('Web', 'site', ['url']),
38
+ ...web,
39
+ },
40
+ } as unknown as ConstructManifest;
41
+ }
42
+
43
+ const stack = () =>
44
+ new App({
45
+ name: 'shop',
46
+ stage: 'production',
47
+ domain: 'example.com',
48
+ hostedZoneId: 'Z123',
49
+ region: 'eu-west-1',
50
+ }).stack('shop');
51
+
52
+ describe('aliases and redirects on AWS', () => {
53
+ afterEach(() => vi.restoreAllMocks());
54
+
55
+ it('pass a manifest that declares none', () => {
56
+ expect(() => assertNoHostLabels(manifest())).not.toThrow();
57
+ });
58
+
59
+ it.each([
60
+ [{ aliases: ['store'] }, ['store']],
61
+ [{ redirects: ['www'] }, ['www']],
62
+ ])('fail the deploy, naming the construct and its labels', (web, labels) => {
63
+ vi.spyOn(console, 'log').mockImplementation(() => {});
64
+
65
+ expect.assertions(3);
66
+ try {
67
+ fromManifest(stack(), manifest(web), {}, {});
68
+ } catch (error) {
69
+ expect(error).toBeInstanceOf(HostLabelNeedsCustomDomain);
70
+ expect((error as HostLabelNeedsCustomDomain).id).toBe('Web');
71
+ expect((error as HostLabelNeedsCustomDomain).labels).toEqual(labels);
72
+ }
73
+ });
74
+ });
@@ -1,6 +1,6 @@
1
1
  // The codec alone — see the note in `Queue.ts`.
2
2
  import * as snsUrl from '@geekmidas/events/sns/url';
3
- import { provideKey } from '@geekmidas/manifest';
3
+ import { providedKeyFor } from '@geekmidas/manifest';
4
4
  import { type GkmLinkable, ResourceType } from '../Linkable';
5
5
  import { regionOfArn } from '../naming';
6
6
  import type { StackType } from '../Stack';
@@ -53,10 +53,13 @@ export class Inbox<
53
53
  return value;
54
54
  };
55
55
 
56
- this.url = read(props.url, provideKey(name, 'url'));
57
- this.domain = read(props.domain, provideKey(name, 'domain'));
56
+ this.url = read(props.url, providedKeyFor(name, 'inbox', 'url'));
57
+ this.domain = read(props.domain, providedKeyFor(name, 'inbox', 'domain'));
58
58
  this.topicArn = snsUrl.parse(
59
- read(props.topic, provideKey(props.topicId, 'publisherConnectionString')),
59
+ read(
60
+ props.topic,
61
+ providedKeyFor(props.topicId, 'topic', 'publisherConnectionString'),
62
+ ),
60
63
  ).topicArn;
61
64
  }
62
65
 
@@ -39,7 +39,7 @@ export class ObjectStorage<
39
39
 
40
40
  /**
41
41
  * The values this bucket resolves onto anything that depends on it, keyed by
42
- * role. `provideKey` turns a role into the env key the app declared, so
42
+ * role. `providedKeyFor` turns a role into the env key the app declared, so
43
43
  * `connectionString` here is `UPLOADS_CONNECTION_STRING` there.
44
44
  *
45
45
  * Composed *here* because only the resource knows its own shape: the name may
@@ -46,7 +46,7 @@ export class Secret<
46
46
  /**
47
47
  * The one value this secret resolves onto anything that depends on it.
48
48
  *
49
- * `value` is the role, so `provideKey` turns it into the key the app
49
+ * `value` is the role, so `providedKeyFor` turns it into the key the app
50
50
  * declared. Note that a secret's key is its *name* rather than
51
51
  * `<NAME>_VALUE` — `Auth` signs with `AUTH_SECRET`, which is also what
52
52
  * better-auth's own tooling looks for — so the manifest declares that key
package/src/sst/errors.ts CHANGED
@@ -78,3 +78,25 @@ export class WildcardSiteNeedsDomain extends Error {
78
78
  this.name = 'WildcardSiteNeedsDomain';
79
79
  }
80
80
  }
81
+
82
+ /**
83
+ * A surface or site with `aliases` or `redirects` on an AWS stage. Only a
84
+ * wildcard site is given a custom domain there; every other surface answers
85
+ * on the address AWS assigns it, so there is no domain to put the extra
86
+ * labels under — and dropping them silently would deploy a host that never
87
+ * answers.
88
+ */
89
+ export class HostLabelNeedsCustomDomain extends Error {
90
+ constructor(
91
+ readonly id: string,
92
+ readonly labels: readonly string[],
93
+ ) {
94
+ super(
95
+ `'${id}' answers on ${labels.map((label) => `'${label}'`).join(', ')} ` +
96
+ `besides its own host, but on AWS it has no custom domain to put ` +
97
+ `them under. Deploy this stage with gkm compose, or drop its ` +
98
+ `\`aliases\` and \`redirects\` for it.`,
99
+ );
100
+ this.name = 'HostLabelNeedsCustomDomain';
101
+ }
102
+ }
@@ -28,15 +28,17 @@ import {
28
28
  cookieDomain,
29
29
  DEFAULT_POSTGRES_VERSION,
30
30
  dependentsOf,
31
+ hostLabels,
31
32
  IMAGE_ORIGINS_KEY,
32
33
  imageOriginSources,
33
34
  imageOrigins,
35
+ isHostedDeclaration,
34
36
  isWildcardSite,
35
37
  mobileOrigins,
36
- PUBLIC,
37
38
  PUBLIC_PREFIX,
38
39
  providedKeyFor,
39
40
  provisionOrder,
41
+ publicValues,
40
42
  SECRET_LENGTH,
41
43
  SECRET_SYMBOLS,
42
44
  schemeBase,
@@ -69,6 +71,7 @@ import { StaticSite } from './aws/StaticSite';
69
71
  import { Topic } from './aws/Topic';
70
72
  import { WebSocketApiSurface } from './aws/WebSocketApiSurface';
71
73
  import {
74
+ HostLabelNeedsCustomDomain,
72
75
  ProvidesMismatch,
73
76
  UnknownDeclarationKind,
74
77
  UnresolvedDependency,
@@ -497,53 +500,32 @@ export function siteEnvironment(
497
500
  }
498
501
  }
499
502
 
500
- const inline = (id: string, target: Declaration) => {
501
- const roles = PUBLIC[target.kind] ?? [];
502
- if (roles.length === 0) return;
503
-
503
+ // The one walk of a frontend's edges every target makes (`publicValues`):
504
+ // each value is read off the component that provides it.
505
+ for (const { id, kind, role, key } of publicValues(
506
+ declaration,
507
+ context.manifest,
508
+ )) {
504
509
  const component = context.provisioned[id];
505
510
  if (!component) {
506
511
  throw new UnresolvedDependency(id, Object.keys(context.provisioned));
507
512
  }
508
513
 
509
- const provided = { ...component.provides() };
514
+ const provided = component.provides();
515
+ let value = provided[role];
510
516
  // A bucket's signed origin is derived from its connection, not
511
517
  // provided: where its presigned links point is a function of it.
512
- if (target.kind === 'objects' && provided.connectionString !== undefined) {
513
- provided.signedOrigin ??= $util
518
+ if (
519
+ value === undefined &&
520
+ kind === 'objects' &&
521
+ role === 'signedOrigin' &&
522
+ provided.connectionString !== undefined
523
+ ) {
524
+ value = $util
514
525
  .output(provided.connectionString)
515
526
  .apply((connection) => s3Url.signedOrigin(s3Url.parse(connection)));
516
527
  }
517
- for (const role of roles) {
518
- const value = provided[role as string];
519
- if (value === undefined) continue;
520
-
521
- environment[
522
- `${prefix}${providedKeyFor(id, target.kind, role as string)}`
523
- ] = value;
524
- }
525
- };
526
-
527
- for (const edge of declaration.dependencies) {
528
- const target = context.manifest[edge.target];
529
- if (!target) continue;
530
- inline(edge.target, target);
531
-
532
- // An edge to a bucket still shows its objects from where they are
533
- // served — the same rule `publicEnvFor` follows.
534
- if (target.kind === 'objects') {
535
- for (const [id, other] of Object.entries(context.manifest)) {
536
- if (other.kind === 'file-server' && other.of === edge.target) {
537
- inline(id, other);
538
- }
539
- }
540
- }
541
- // And an edge to a file server gets where its bucket's signed links
542
- // point.
543
- if (target.kind === 'file-server') {
544
- const bucket = context.manifest[target.of];
545
- if (bucket) inline(target.of, bucket);
546
- }
528
+ if (value !== undefined) environment[`${prefix}${key}`] = value;
547
529
  }
548
530
 
549
531
  // The origins its pages load files from, as one list: composed from the
@@ -754,6 +736,22 @@ export function describeRoutes(manifest: ConstructManifest): string[] {
754
736
  return lines;
755
737
  }
756
738
 
739
+ /**
740
+ * An AWS stage refuses aliases and redirects outright: no surface but a
741
+ * wildcard site has a custom domain there to put them under.
742
+ *
743
+ * @throws {HostLabelNeedsCustomDomain} naming the first construct with either
744
+ */
745
+ export function assertNoHostLabels(manifest: ConstructManifest): void {
746
+ for (const [id, declaration] of Object.entries(manifest)) {
747
+ if (!isHostedDeclaration(declaration)) continue;
748
+ const { aliases, redirects } = hostLabels(declaration);
749
+ if (aliases.length || redirects.length) {
750
+ throw new HostLabelNeedsCustomDomain(id, [...aliases, ...redirects]);
751
+ }
752
+ }
753
+ }
754
+
757
755
  /** A promise with its settle function, for a value that arrives later. */
758
756
  function defer(): Deferred {
759
757
  let resolve!: Deferred['resolve'];
@@ -785,6 +783,8 @@ async function callersOf(
785
783
  provisioned: ProvisionedManifest,
786
784
  /** The app's name — a mobile caller's scheme base when it gives none. */
787
785
  project: string,
786
+ /** The stack's domain, which a caller's aliases are labels under. */
787
+ domain?: string,
788
788
  ): Promise<{ trustedOrigins: string; cookieDomain?: string }> {
789
789
  // Every address here is a Pulumi output, not a string — a CloudFront domain
790
790
  // and an API Gateway endpoint are both known only after their resource
@@ -798,16 +798,29 @@ async function callersOf(
798
798
  ),
799
799
  );
800
800
 
801
+ // A caller's aliases are hosts it really answers on, so each is an
802
+ // origin beside its own; its redirects never run a page, so none is.
803
+ const aliases = domain
804
+ ? dependentsOf(manifest, id).flatMap((caller) => {
805
+ const declaration = manifest[caller];
806
+ return isHostedDeclaration(declaration)
807
+ ? hostLabels(declaration).aliases.map(
808
+ (label) => `https://${label}.${domain}`,
809
+ )
810
+ : [];
811
+ })
812
+ : [];
813
+
801
814
  const origins = [
802
815
  ...new Set(
803
- urls
816
+ [...urls, ...aliases]
804
817
  .map((url) => (url ? originOf(url) : undefined))
805
818
  .filter((origin): origin is string => Boolean(origin)),
806
819
  ),
807
820
  ].sort();
808
821
 
809
822
  const own = await resolved(provisioned[id]?.provides().url);
810
- const domain = cookieDomain([...(own ? [own] : []), ...origins]);
823
+ const shared = cookieDomain([...(own ? [own] : []), ...origins]);
811
824
 
812
825
  // A mobile caller is reached by its scheme — the bare one, deployed: what
813
826
  // the store build registers.
@@ -820,7 +833,7 @@ async function callersOf(
820
833
 
821
834
  return {
822
835
  trustedOrigins: [...origins, ...schemes].join(','),
823
- ...(domain ? { cookieDomain: domain } : {}),
836
+ ...(shared ? { cookieDomain: shared } : {}),
824
837
  };
825
838
  }
826
839
 
@@ -1264,6 +1277,7 @@ export function fromManifest<
1264
1277
  */
1265
1278
  backends: B = {} as B,
1266
1279
  ): ProvisionedManifest {
1280
+ assertNoHostLabels(manifest);
1267
1281
  const provisioned: ProvisionedManifest = {};
1268
1282
 
1269
1283
  // In provisioning order, so a derived node finds the component its parent
@@ -1353,7 +1367,9 @@ export function fromManifest<
1353
1367
  for (const [id, deferred] of callers) {
1354
1368
  // Resolved with the promise itself: the addresses it needs are Pulumi
1355
1369
  // outputs, so the answer arrives when they do.
1356
- deferred.resolve(callersOf(id, manifest, provisioned, $app.name));
1370
+ deferred.resolve(
1371
+ callersOf(id, manifest, provisioned, $app.name, stack.domain),
1372
+ );
1357
1373
  }
1358
1374
 
1359
1375
  // Last, and only now: the roles exist as passwords and secrets from the
package/src/sst/index.ts CHANGED
@@ -69,6 +69,7 @@ export {
69
69
  type WebSocketSurfaceRoute,
70
70
  } from './aws/WebSocketApiSurface';
71
71
  export {
72
+ HostLabelNeedsCustomDomain,
72
73
  ProvidesMismatch,
73
74
  UnknownDeclarationKind,
74
75
  UnresolvedDependency,