@geekmidas/cloud 10.0.0-alpha.168 → 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 +7 -7
- package/src/sst/__tests__/hostLabels.spec.ts +74 -0
- package/src/sst/errors.ts +22 -0
- package/src/sst/fromManifest.ts +41 -4
- package/src/sst/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cloud",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
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.
|
|
45
|
-
"@geekmidas/manifest": "10.0.0-alpha.
|
|
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.
|
|
62
|
-
"@geekmidas/storage": ">=10.0.0-alpha.
|
|
63
|
-
"@geekmidas/events": ">=10.0.0-alpha.
|
|
64
|
-
"@geekmidas/db": ">=10.0.0-alpha.
|
|
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": {
|
|
@@ -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
|
+
});
|
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
|
+
}
|
package/src/sst/fromManifest.ts
CHANGED
|
@@ -28,9 +28,11 @@ 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
38
|
PUBLIC_PREFIX,
|
|
@@ -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,
|
|
@@ -733,6 +736,22 @@ export function describeRoutes(manifest: ConstructManifest): string[] {
|
|
|
733
736
|
return lines;
|
|
734
737
|
}
|
|
735
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
|
+
|
|
736
755
|
/** A promise with its settle function, for a value that arrives later. */
|
|
737
756
|
function defer(): Deferred {
|
|
738
757
|
let resolve!: Deferred['resolve'];
|
|
@@ -764,6 +783,8 @@ async function callersOf(
|
|
|
764
783
|
provisioned: ProvisionedManifest,
|
|
765
784
|
/** The app's name — a mobile caller's scheme base when it gives none. */
|
|
766
785
|
project: string,
|
|
786
|
+
/** The stack's domain, which a caller's aliases are labels under. */
|
|
787
|
+
domain?: string,
|
|
767
788
|
): Promise<{ trustedOrigins: string; cookieDomain?: string }> {
|
|
768
789
|
// Every address here is a Pulumi output, not a string — a CloudFront domain
|
|
769
790
|
// and an API Gateway endpoint are both known only after their resource
|
|
@@ -777,16 +798,29 @@ async function callersOf(
|
|
|
777
798
|
),
|
|
778
799
|
);
|
|
779
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
|
+
|
|
780
814
|
const origins = [
|
|
781
815
|
...new Set(
|
|
782
|
-
urls
|
|
816
|
+
[...urls, ...aliases]
|
|
783
817
|
.map((url) => (url ? originOf(url) : undefined))
|
|
784
818
|
.filter((origin): origin is string => Boolean(origin)),
|
|
785
819
|
),
|
|
786
820
|
].sort();
|
|
787
821
|
|
|
788
822
|
const own = await resolved(provisioned[id]?.provides().url);
|
|
789
|
-
const
|
|
823
|
+
const shared = cookieDomain([...(own ? [own] : []), ...origins]);
|
|
790
824
|
|
|
791
825
|
// A mobile caller is reached by its scheme — the bare one, deployed: what
|
|
792
826
|
// the store build registers.
|
|
@@ -799,7 +833,7 @@ async function callersOf(
|
|
|
799
833
|
|
|
800
834
|
return {
|
|
801
835
|
trustedOrigins: [...origins, ...schemes].join(','),
|
|
802
|
-
...(
|
|
836
|
+
...(shared ? { cookieDomain: shared } : {}),
|
|
803
837
|
};
|
|
804
838
|
}
|
|
805
839
|
|
|
@@ -1243,6 +1277,7 @@ export function fromManifest<
|
|
|
1243
1277
|
*/
|
|
1244
1278
|
backends: B = {} as B,
|
|
1245
1279
|
): ProvisionedManifest {
|
|
1280
|
+
assertNoHostLabels(manifest);
|
|
1246
1281
|
const provisioned: ProvisionedManifest = {};
|
|
1247
1282
|
|
|
1248
1283
|
// In provisioning order, so a derived node finds the component its parent
|
|
@@ -1332,7 +1367,9 @@ export function fromManifest<
|
|
|
1332
1367
|
for (const [id, deferred] of callers) {
|
|
1333
1368
|
// Resolved with the promise itself: the addresses it needs are Pulumi
|
|
1334
1369
|
// outputs, so the answer arrives when they do.
|
|
1335
|
-
deferred.resolve(
|
|
1370
|
+
deferred.resolve(
|
|
1371
|
+
callersOf(id, manifest, provisioned, $app.name, stack.domain),
|
|
1372
|
+
);
|
|
1336
1373
|
}
|
|
1337
1374
|
|
|
1338
1375
|
// Last, and only now: the roles exist as passwords and secrets from the
|