@geekmidas/cloud 10.0.0-alpha.17 → 10.0.0-alpha.171
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/README.md +26 -6
- package/package.json +9 -8
- package/src/sst/__tests__/api.spec.ts +0 -46
- package/src/sst/__tests__/bootstrap.spec.ts +15 -0
- package/src/sst/__tests__/encryption.spec.ts +90 -0
- package/src/sst/__tests__/fromManifest.inbox.spec.ts +157 -0
- package/src/sst/__tests__/fromManifest.integration.spec.ts +87 -3
- package/src/sst/__tests__/fromManifest.secret.spec.ts +79 -0
- package/src/sst/__tests__/fromManifest.spec.ts +412 -18
- package/src/sst/__tests__/function.spec.ts +0 -71
- package/src/sst/__tests__/hostLabels.spec.ts +74 -0
- package/src/sst/__tests__/surfaces.spec.ts +68 -5
- package/src/sst/__tests__/websocket.spec.ts +207 -0
- package/src/sst/__tests__/wildcardSite.spec.ts +195 -0
- package/src/sst/__type-tests__/overrides.type-test.ts +152 -0
- package/src/sst/aws/Api.ts +0 -43
- package/src/sst/aws/Credential.ts +42 -9
- package/src/sst/aws/Cron.ts +5 -45
- package/src/sst/aws/DatabaseBootstrap.ts +6 -0
- package/src/sst/aws/Encryption.ts +91 -0
- package/src/sst/aws/ExternalApi.ts +58 -0
- package/src/sst/aws/Function.ts +9 -38
- package/src/sst/aws/Inbox.ts +141 -0
- package/src/sst/aws/ObjectStorage.ts +3 -3
- package/src/sst/aws/Queue.ts +34 -1
- package/src/sst/aws/RestApiSurface.ts +36 -14
- package/src/sst/aws/Secret.ts +6 -4
- package/src/sst/aws/StaticSite.ts +44 -1
- package/src/sst/aws/WebSocketApiSurface.ts +160 -0
- package/src/sst/aws/bootstrap/handler.ts +12 -1
- package/src/sst/errors.ts +37 -0
- package/src/sst/fromManifest.ts +624 -71
- package/src/sst/index.ts +21 -1
- package/src/sst/overrides.ts +149 -0
- package/src/sst/__type-tests__/manifest.type-test.ts +0 -77
|
@@ -12,15 +12,23 @@ import {
|
|
|
12
12
|
const stack = {} as never;
|
|
13
13
|
|
|
14
14
|
const manifest = {
|
|
15
|
-
Uploads: {
|
|
15
|
+
Uploads: {
|
|
16
|
+
kind: 'objects',
|
|
17
|
+
id: 'Uploads',
|
|
18
|
+
provides: ['UPLOADS_CONNECTION_STRING'],
|
|
19
|
+
},
|
|
16
20
|
UploadsServer: {
|
|
17
21
|
kind: 'file-server',
|
|
18
22
|
id: 'UploadsServer',
|
|
19
23
|
of: 'Uploads',
|
|
20
24
|
open: ['brand/**'],
|
|
21
|
-
provides: ['
|
|
25
|
+
provides: ['UPLOADS_URL'],
|
|
26
|
+
},
|
|
27
|
+
Assets: {
|
|
28
|
+
kind: 'objects',
|
|
29
|
+
id: 'Assets',
|
|
30
|
+
provides: ['ASSETS_CONNECTION_STRING'],
|
|
22
31
|
},
|
|
23
|
-
Assets: { kind: 'objects', id: 'Assets', provides: ['ASSETS_URL'] },
|
|
24
32
|
Api: {
|
|
25
33
|
kind: 'rest-api',
|
|
26
34
|
id: 'Api',
|
|
@@ -28,6 +36,11 @@ const manifest = {
|
|
|
28
36
|
provides: ['API_URL', 'API_TRUSTED_ORIGINS', 'API_COOKIE_DOMAIN'],
|
|
29
37
|
},
|
|
30
38
|
Orders: { kind: 'database', id: 'Orders', provides: ['ORDERS_URL'] },
|
|
39
|
+
Mailer: {
|
|
40
|
+
kind: 'email',
|
|
41
|
+
id: 'Mailer',
|
|
42
|
+
provides: ['MAILER_URL', 'MAILER_FROM'],
|
|
43
|
+
},
|
|
31
44
|
Console: {
|
|
32
45
|
kind: 'site',
|
|
33
46
|
id: 'Console',
|
|
@@ -37,6 +50,7 @@ const manifest = {
|
|
|
37
50
|
{ target: 'Api', kind: 'rest-api' },
|
|
38
51
|
{ target: 'Orders', kind: 'database' },
|
|
39
52
|
{ target: 'UploadsServer', kind: 'file-server' },
|
|
53
|
+
{ target: 'Mailer', kind: 'email' },
|
|
40
54
|
],
|
|
41
55
|
provides: ['CONSOLE_URL'],
|
|
42
56
|
},
|
|
@@ -100,7 +114,14 @@ describe('siteEnvironment', () => {
|
|
|
100
114
|
context({
|
|
101
115
|
Api: provided({ url: 'https://api.example.com' }),
|
|
102
116
|
Orders: provided({ url: 'postgres://user:pw@db/orders' }),
|
|
117
|
+
Uploads: provided({
|
|
118
|
+
connectionString: 's3://uploads-x1?region=eu-west-1',
|
|
119
|
+
}),
|
|
103
120
|
UploadsServer: provided({ url: 'https://files.example.com' }),
|
|
121
|
+
Mailer: provided({
|
|
122
|
+
url: 'smtp://user:pw@email-smtp.example.com:587',
|
|
123
|
+
from: 'hello@shop.test',
|
|
124
|
+
}),
|
|
104
125
|
}),
|
|
105
126
|
);
|
|
106
127
|
|
|
@@ -111,8 +132,43 @@ describe('siteEnvironment', () => {
|
|
|
111
132
|
it('inlines a served bucket’s address, but never the bucket’s own', () => {
|
|
112
133
|
// A served URL is what a browser fetches; the bucket's presigns, and a
|
|
113
134
|
// presigner in a bundle is a credential in a bundle.
|
|
114
|
-
expect(built().
|
|
115
|
-
expect(built()).not.toHaveProperty('
|
|
135
|
+
expect(built().VITE_UPLOADS_URL).toBe('https://files.example.com');
|
|
136
|
+
expect(built()).not.toHaveProperty('VITE_UPLOADS_CONNECTION_STRING');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("inlines where a served bucket's signed links point", () => {
|
|
140
|
+
expect(built().VITE_UPLOADS_SIGNED_ORIGIN).toBe(
|
|
141
|
+
'https://uploads-x1.s3.eu-west-1.amazonaws.com',
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("inlines a bucket's served address on an edge to the bucket itself", () => {
|
|
146
|
+
// A full-stack site's `.dependsOn([uploads.server])`: the server half
|
|
147
|
+
// holds the bucket, and the bundle still shows its objects from where
|
|
148
|
+
// they are served.
|
|
149
|
+
const env = siteEnvironment(
|
|
150
|
+
{
|
|
151
|
+
...manifest.Console,
|
|
152
|
+
dependencies: [{ target: 'Uploads', kind: 'objects' }],
|
|
153
|
+
},
|
|
154
|
+
context({
|
|
155
|
+
Uploads: provided({
|
|
156
|
+
connectionString: 's3://uploads-x1?region=eu-west-1',
|
|
157
|
+
}),
|
|
158
|
+
UploadsServer: provided({ url: 'https://files.example.com' }),
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// And where the bucket's signed links point, derived from its
|
|
163
|
+
// connection — never the connection itself.
|
|
164
|
+
expect(env).toEqual({
|
|
165
|
+
VITE_UPLOADS_SIGNED_ORIGIN:
|
|
166
|
+
'https://uploads-x1.s3.eu-west-1.amazonaws.com',
|
|
167
|
+
VITE_UPLOADS_URL: 'https://files.example.com',
|
|
168
|
+
// Both, as the one list a page's image config reads.
|
|
169
|
+
VITE_GKM_IMAGE_ORIGINS:
|
|
170
|
+
'https://files.example.com,https://uploads-x1.s3.eu-west-1.amazonaws.com',
|
|
171
|
+
});
|
|
116
172
|
});
|
|
117
173
|
|
|
118
174
|
it('keeps a connection string out of the bundle entirely', () => {
|
|
@@ -122,6 +178,13 @@ describe('siteEnvironment', () => {
|
|
|
122
178
|
expect(built()).not.toHaveProperty('VITE_ORDERS_URL');
|
|
123
179
|
});
|
|
124
180
|
|
|
181
|
+
it('has no inbox to share for deployed mail, and never shares the mail URL', () => {
|
|
182
|
+
// The inbox is Mailpit's, and exists only locally: deployed, an app that
|
|
183
|
+
// reads it falls back to the phone's own mail app.
|
|
184
|
+
expect(built()).not.toHaveProperty('VITE_MAILER_INBOX_URL');
|
|
185
|
+
expect(built()).not.toHaveProperty('VITE_MAILER_URL');
|
|
186
|
+
});
|
|
187
|
+
|
|
125
188
|
it('fails loudly on an edge nothing provisioned', () => {
|
|
126
189
|
// A smaller environment builds and then fails at runtime against
|
|
127
190
|
// `http:///`, with nothing to point at.
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { resolveEnvKeys } from '@geekmidas/envkit/sst';
|
|
2
|
+
import {
|
|
3
|
+
type ConstructManifest,
|
|
4
|
+
parseApiGatewayWebSocketUrl,
|
|
5
|
+
providedKeyFor,
|
|
6
|
+
} from '@geekmidas/manifest';
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import { RestApiSurface } from '../aws/RestApiSurface';
|
|
9
|
+
import {
|
|
10
|
+
regionOfEndpoint,
|
|
11
|
+
routeSelectionExpression,
|
|
12
|
+
type WebSocketApiSurface,
|
|
13
|
+
} from '../aws/WebSocketApiSurface';
|
|
14
|
+
import {
|
|
15
|
+
assertProvides,
|
|
16
|
+
describeRoutes,
|
|
17
|
+
mountWebSocketRoutes,
|
|
18
|
+
type ProvisionedManifest,
|
|
19
|
+
provisionerFor,
|
|
20
|
+
} from '../fromManifest';
|
|
21
|
+
|
|
22
|
+
const stack = {} as never;
|
|
23
|
+
|
|
24
|
+
const SURFACE_KEYS = [
|
|
25
|
+
'REALTIME_URL',
|
|
26
|
+
'REALTIME_TRUSTED_ORIGINS',
|
|
27
|
+
'REALTIME_PUBLISHER_CONNECTION_STRING',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const manifest = {
|
|
31
|
+
Realtime: {
|
|
32
|
+
kind: 'websocket-api',
|
|
33
|
+
id: 'Realtime',
|
|
34
|
+
path: 'apps/realtime',
|
|
35
|
+
discriminator: 'type',
|
|
36
|
+
auth: { target: 'Auth', kind: 'rest-api' },
|
|
37
|
+
routes: [
|
|
38
|
+
{
|
|
39
|
+
id: 'Realtime$connect',
|
|
40
|
+
action: '$connect',
|
|
41
|
+
handler: 'apps/realtime/.gkm/aws/websocket/connect.handler',
|
|
42
|
+
dependencies: [],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'Realtimechat.send',
|
|
46
|
+
action: 'chat.send',
|
|
47
|
+
handler: 'apps/realtime/.gkm/aws/websocket/route-chat_send.handler',
|
|
48
|
+
dependencies: [{ target: 'Api', kind: 'rest-api' }],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
provides: SURFACE_KEYS,
|
|
52
|
+
},
|
|
53
|
+
Api: {
|
|
54
|
+
kind: 'rest-api',
|
|
55
|
+
id: 'Api',
|
|
56
|
+
path: 'apps/api',
|
|
57
|
+
endpoints: [],
|
|
58
|
+
provides: ['API_URL', 'API_TRUSTED_ORIGINS', 'API_COOKIE_DOMAIN'],
|
|
59
|
+
},
|
|
60
|
+
Auth: {
|
|
61
|
+
kind: 'rest-api',
|
|
62
|
+
id: 'Auth',
|
|
63
|
+
path: 'apps/auth',
|
|
64
|
+
endpoints: [],
|
|
65
|
+
provides: ['AUTH_URL', 'AUTH_TRUSTED_ORIGINS', 'AUTH_COOKIE_DOMAIN'],
|
|
66
|
+
},
|
|
67
|
+
} as const satisfies ConstructManifest;
|
|
68
|
+
|
|
69
|
+
function provision(): ProvisionedManifest {
|
|
70
|
+
const context = { manifest, provisioned: {}, bootstraps: new Map() };
|
|
71
|
+
return {
|
|
72
|
+
Realtime: provisionerFor('websocket-api')(
|
|
73
|
+
stack,
|
|
74
|
+
manifest.Realtime,
|
|
75
|
+
{},
|
|
76
|
+
context,
|
|
77
|
+
),
|
|
78
|
+
Api: new RestApiSurface(stack, 'Api'),
|
|
79
|
+
Auth: new RestApiSurface(stack, 'Auth'),
|
|
80
|
+
} as ProvisionedManifest;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('WebSocketApiSurface', () => {
|
|
84
|
+
it('provides the keys a websocket-api declares', () => {
|
|
85
|
+
const surface = provision().Realtime!;
|
|
86
|
+
|
|
87
|
+
expect(() =>
|
|
88
|
+
assertProvides(
|
|
89
|
+
'Realtime',
|
|
90
|
+
manifest.Realtime.provides,
|
|
91
|
+
Object.keys(surface.provides()).map((role) =>
|
|
92
|
+
providedKeyFor('Realtime', 'websocket-api', role),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('resolves to the same keys a linked function reads', () => {
|
|
99
|
+
const surface = provision().Realtime!;
|
|
100
|
+
|
|
101
|
+
expect(
|
|
102
|
+
[...resolveEnvKeys({ Realtime: { type: surface._type } })].sort(),
|
|
103
|
+
).toEqual([...SURFACE_KEYS].sort());
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('hands its publisher the management API and its own connection table', () => {
|
|
107
|
+
const surface = provision().Realtime as unknown as WebSocketApiSurface;
|
|
108
|
+
|
|
109
|
+
expect(
|
|
110
|
+
parseApiGatewayWebSocketUrl(
|
|
111
|
+
surface.provides().publisherConnectionString as string,
|
|
112
|
+
),
|
|
113
|
+
).toEqual({
|
|
114
|
+
region: 'stub-region',
|
|
115
|
+
endpoint:
|
|
116
|
+
'https://Realtime.execute-api.stub-region.amazonaws.com/$default',
|
|
117
|
+
table: 'RealtimeConnections',
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('grants a linked function the management API and the table, with the keys', () => {
|
|
122
|
+
const surface = provision().Realtime as unknown as WebSocketApiSurface;
|
|
123
|
+
const link = surface.getSSTLink();
|
|
124
|
+
|
|
125
|
+
expect(link.include).toEqual([
|
|
126
|
+
{ permission: { actions: ['execute-api:ManageConnections'] } },
|
|
127
|
+
{ permission: { actions: ['dynamodb:*'] } },
|
|
128
|
+
]);
|
|
129
|
+
expect(link.properties).toMatchObject({
|
|
130
|
+
url: 'wss://Realtime.execute-api.stub-region.amazonaws.com/$default',
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('routes on the key its frames name their action under', () => {
|
|
135
|
+
const surface = provision().Realtime as unknown as {
|
|
136
|
+
args: { transform: { api: (api: object) => void } };
|
|
137
|
+
};
|
|
138
|
+
const api: { routeSelectionExpression?: string } = {};
|
|
139
|
+
|
|
140
|
+
surface.args.transform.api(api);
|
|
141
|
+
|
|
142
|
+
expect(api.routeSelectionExpression).toBe('$request.body.type');
|
|
143
|
+
expect(routeSelectionExpression()).toBe('$request.body.action');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('mountWebSocketRoutes', () => {
|
|
148
|
+
const mounted = () => {
|
|
149
|
+
const provisioned = provision();
|
|
150
|
+
mountWebSocketRoutes(manifest, provisioned);
|
|
151
|
+
const surface = provisioned.Realtime as unknown as {
|
|
152
|
+
routes: { key: string; handler: { handler: string; link: unknown[] } }[];
|
|
153
|
+
};
|
|
154
|
+
return { provisioned, routes: surface.routes };
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
it('mounts every route on its key, running the handler the build wrote', () => {
|
|
158
|
+
expect(
|
|
159
|
+
mounted().routes.map(({ key, handler }) => [key, handler.handler]),
|
|
160
|
+
).toEqual([
|
|
161
|
+
['$connect', 'apps/realtime/.gkm/aws/websocket/connect.handler'],
|
|
162
|
+
['chat.send', 'apps/realtime/.gkm/aws/websocket/route-chat_send.handler'],
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('links a route to its surface and what it depends on, and nothing else', () => {
|
|
167
|
+
const { provisioned, routes } = mounted();
|
|
168
|
+
const send = routes.find((route) => route.key === 'chat.send')!;
|
|
169
|
+
|
|
170
|
+
expect(send.handler.link).toEqual([provisioned.Realtime, provisioned.Api]);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('links $connect to what authenticates the surface', () => {
|
|
174
|
+
const { provisioned, routes } = mounted();
|
|
175
|
+
const connect = routes.find((route) => route.key === '$connect')!;
|
|
176
|
+
|
|
177
|
+
expect(connect.handler.link).toEqual([
|
|
178
|
+
provisioned.Realtime,
|
|
179
|
+
provisioned.Auth,
|
|
180
|
+
]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('describeRoutes', () => {
|
|
185
|
+
it('prints what each WebSocket route reaches', () => {
|
|
186
|
+
expect(describeRoutes(manifest)).toEqual(
|
|
187
|
+
expect.arrayContaining([
|
|
188
|
+
'Realtime:',
|
|
189
|
+
' $connect → its connections',
|
|
190
|
+
' chat.send → Api (rest-api)',
|
|
191
|
+
' auth Auth ($connect verifies)',
|
|
192
|
+
]),
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('regionOfEndpoint', () => {
|
|
198
|
+
it('reads the region out of a management endpoint', () => {
|
|
199
|
+
expect(
|
|
200
|
+
regionOfEndpoint('https://abc.execute-api.eu-west-1.amazonaws.com/prod'),
|
|
201
|
+
).toBe('eu-west-1');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('is undefined for a custom domain', () => {
|
|
205
|
+
expect(regionOfEndpoint('https://ws.example.com')).toBeUndefined();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConstructManifest,
|
|
3
|
+
PUBLIC_PREFIX,
|
|
4
|
+
providedKeyFor,
|
|
5
|
+
trustsOrigin,
|
|
6
|
+
} from '@geekmidas/manifest';
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
import { App } from '../App';
|
|
9
|
+
import { WildcardSiteNeedsDomain } from '../errors';
|
|
10
|
+
import { fromManifest } from '../fromManifest';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A site on every subdomain, on AWS: one distribution under `*.<domain>`, a
|
|
14
|
+
* wildcard certificate validated through the stack's zone, one alias record,
|
|
15
|
+
* and nothing per tenant.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const keys = (id: string, kind: string, roles: string[]) =>
|
|
19
|
+
roles.map((role) => providedKeyFor(id, kind as never, role));
|
|
20
|
+
|
|
21
|
+
function manifest(): ConstructManifest {
|
|
22
|
+
return {
|
|
23
|
+
Api: {
|
|
24
|
+
kind: 'rest-api',
|
|
25
|
+
id: 'Api',
|
|
26
|
+
path: 'apps/api',
|
|
27
|
+
endpoints: [
|
|
28
|
+
{
|
|
29
|
+
id: 'TenantHosts',
|
|
30
|
+
handler: 'hosts.handler',
|
|
31
|
+
method: 'GET',
|
|
32
|
+
path: '/tenants/hosts',
|
|
33
|
+
dependencies: [],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
provides: keys('Api', 'rest-api', [
|
|
37
|
+
'url',
|
|
38
|
+
'trustedOrigins',
|
|
39
|
+
'cookieDomain',
|
|
40
|
+
]),
|
|
41
|
+
},
|
|
42
|
+
Admin: {
|
|
43
|
+
kind: 'site',
|
|
44
|
+
id: 'Admin',
|
|
45
|
+
variant: 'static',
|
|
46
|
+
subdomain: 'admin',
|
|
47
|
+
app: { path: 'apps/admin' },
|
|
48
|
+
dependencies: [{ target: 'Api', kind: 'rest-api' }],
|
|
49
|
+
provides: keys('Admin', 'site', ['url']),
|
|
50
|
+
},
|
|
51
|
+
App: {
|
|
52
|
+
kind: 'site',
|
|
53
|
+
id: 'App',
|
|
54
|
+
variant: 'next',
|
|
55
|
+
subdomain: '*',
|
|
56
|
+
hosts: { surface: 'Api', path: '/tenants/hosts' },
|
|
57
|
+
app: { path: 'apps/web' },
|
|
58
|
+
dependencies: [{ target: 'Api', kind: 'rest-api' }],
|
|
59
|
+
provides: keys('App', 'site', ['url', 'domain', 'protectedSubdomains']),
|
|
60
|
+
},
|
|
61
|
+
} as unknown as ConstructManifest;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const stackOn = (domain: string, hostedZoneId: string = 'Z123') =>
|
|
65
|
+
new App({
|
|
66
|
+
name: 'shop',
|
|
67
|
+
stage: 'production',
|
|
68
|
+
domain,
|
|
69
|
+
hostedZoneId,
|
|
70
|
+
region: 'eu-west-1',
|
|
71
|
+
}).stack('shop');
|
|
72
|
+
|
|
73
|
+
const argsOf = (component: unknown) =>
|
|
74
|
+
(component as { args: Record<string, any> }).args;
|
|
75
|
+
|
|
76
|
+
const settle = async (value: unknown): Promise<unknown> =>
|
|
77
|
+
typeof value === 'object' && value && 'apply' in value
|
|
78
|
+
? (value as { apply: (fn: (v: unknown) => unknown) => unknown }).apply(
|
|
79
|
+
(v) => v,
|
|
80
|
+
)
|
|
81
|
+
: value;
|
|
82
|
+
|
|
83
|
+
const PROTECTED = ['admin', 'api', 'www'];
|
|
84
|
+
|
|
85
|
+
describe('a wildcard site on AWS', () => {
|
|
86
|
+
afterEach(() => vi.restoreAllMocks());
|
|
87
|
+
|
|
88
|
+
it('is one distribution under *.<domain>, its certificate and alias through the stack’s zone', () => {
|
|
89
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
90
|
+
|
|
91
|
+
const provisioned = fromManifest(
|
|
92
|
+
stackOn('example.com'),
|
|
93
|
+
manifest(),
|
|
94
|
+
{},
|
|
95
|
+
{
|
|
96
|
+
protectedSubdomains: PROTECTED,
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(argsOf(provisioned.App).domain).toEqual({
|
|
101
|
+
name: '*.example.com',
|
|
102
|
+
dns: { dns: { zone: 'Z123' } },
|
|
103
|
+
});
|
|
104
|
+
// A named site keeps its own: nothing about it changed.
|
|
105
|
+
expect(argsOf(provisioned.Admin).domain).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('looks its zone up by name when the stack has none resolved', () => {
|
|
109
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
110
|
+
|
|
111
|
+
const provisioned = fromManifest(
|
|
112
|
+
stackOn('example.com', ''),
|
|
113
|
+
manifest(),
|
|
114
|
+
{},
|
|
115
|
+
{ protectedSubdomains: PROTECTED },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(argsOf(provisioned.App).domain.dns).toEqual({ dns: {} });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('provides its address, domain and protected labels, and inlines the last two', () => {
|
|
122
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
123
|
+
|
|
124
|
+
const provisioned = fromManifest(
|
|
125
|
+
stackOn('example.com'),
|
|
126
|
+
manifest(),
|
|
127
|
+
{},
|
|
128
|
+
{
|
|
129
|
+
protectedSubdomains: PROTECTED,
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(provisioned.App!.provides()).toEqual({
|
|
134
|
+
url: 'https://*.example.com',
|
|
135
|
+
domain: 'example.com',
|
|
136
|
+
protectedSubdomains: 'admin,api,www',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const env = argsOf(provisioned.App).environment as Record<string, unknown>;
|
|
140
|
+
const prefix = PUBLIC_PREFIX.next;
|
|
141
|
+
expect(env[`${prefix}${providedKeyFor('App', 'site', 'domain')}`]).toBe(
|
|
142
|
+
'example.com',
|
|
143
|
+
);
|
|
144
|
+
expect(
|
|
145
|
+
env[`${prefix}${providedKeyFor('App', 'site', 'protectedSubdomains')}`],
|
|
146
|
+
).toBe('admin,api,www');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('has the surfaces it calls trust every tenant’s origin, one label deep', async () => {
|
|
150
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
151
|
+
|
|
152
|
+
const provisioned = fromManifest(
|
|
153
|
+
stackOn('example.com'),
|
|
154
|
+
manifest(),
|
|
155
|
+
{},
|
|
156
|
+
{
|
|
157
|
+
protectedSubdomains: PROTECTED,
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
const trusted = String(
|
|
161
|
+
await settle(provisioned.Api!.provides().trustedOrigins),
|
|
162
|
+
).split(',');
|
|
163
|
+
|
|
164
|
+
expect(trusted).toContain('https://*.example.com');
|
|
165
|
+
expect(trustsOrigin('https://acme.example.com', trusted)).toBe(true);
|
|
166
|
+
expect(trustsOrigin('https://a.b.example.com', trusted)).toBe(false);
|
|
167
|
+
expect(trustsOrigin('https://example.com', trusted)).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('lets an override win, as every other prop does', () => {
|
|
171
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
172
|
+
|
|
173
|
+
const domain = { name: '*.tenants.example.com' };
|
|
174
|
+
const provisioned = fromManifest(
|
|
175
|
+
stackOn('example.com'),
|
|
176
|
+
manifest(),
|
|
177
|
+
{ App: { domain } } as never,
|
|
178
|
+
{ protectedSubdomains: PROTECTED },
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(argsOf(provisioned.App).domain).toBe(domain);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('is refused on a stack with no domain, naming the site', () => {
|
|
185
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
186
|
+
|
|
187
|
+
expect.assertions(2);
|
|
188
|
+
try {
|
|
189
|
+
fromManifest(stackOn(''), manifest(), {}, {});
|
|
190
|
+
} catch (error) {
|
|
191
|
+
expect(error).toBeInstanceOf(WildcardSiteNeedsDomain);
|
|
192
|
+
expect((error as WildcardSiteNeedsDomain).id).toBe('App');
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Type-level tests for `fromManifest`'s overrides, inferred from the manifest.
|
|
2
|
+
// Checked by `ts:check:sst`; each `@ts-expect-error` self-validates: if the
|
|
3
|
+
// inference regresses, the now-unused directive becomes a TS error the gate
|
|
4
|
+
// catches.
|
|
5
|
+
|
|
6
|
+
import type { ConstructManifest } from '@geekmidas/manifest';
|
|
7
|
+
import { App } from '../App';
|
|
8
|
+
import { fromManifest } from '../fromManifest';
|
|
9
|
+
|
|
10
|
+
const stack = new App({
|
|
11
|
+
name: 'a',
|
|
12
|
+
stage: 'dev',
|
|
13
|
+
domain: 'example.com',
|
|
14
|
+
hostedZoneId: 'Z',
|
|
15
|
+
region: 'us-east-1',
|
|
16
|
+
}).stack('shop');
|
|
17
|
+
|
|
18
|
+
declare const vpc: sst.aws.Vpc;
|
|
19
|
+
|
|
20
|
+
// The shape `gkm build` emits: `as const satisfies ConstructManifest`.
|
|
21
|
+
const constructs = {
|
|
22
|
+
Orders: {
|
|
23
|
+
kind: 'database',
|
|
24
|
+
id: 'Orders',
|
|
25
|
+
engine: 'postgres',
|
|
26
|
+
provides: ['ORDERS_URL'],
|
|
27
|
+
},
|
|
28
|
+
Billing: {
|
|
29
|
+
kind: 'database-schema',
|
|
30
|
+
id: 'Billing',
|
|
31
|
+
of: 'Orders',
|
|
32
|
+
schema: 'billing',
|
|
33
|
+
provides: ['BILLING_URL'],
|
|
34
|
+
},
|
|
35
|
+
Sessions: { kind: 'cache', id: 'Sessions', provides: ['SESSIONS_URL'] },
|
|
36
|
+
Rates: {
|
|
37
|
+
kind: 'cache',
|
|
38
|
+
id: 'Rates',
|
|
39
|
+
of: 'Orders',
|
|
40
|
+
provides: ['RATES_URL'],
|
|
41
|
+
},
|
|
42
|
+
Mail: { kind: 'email', id: 'Mail', provides: ['MAIL_URL'] },
|
|
43
|
+
Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
|
|
44
|
+
Api: {
|
|
45
|
+
kind: 'rest-api',
|
|
46
|
+
id: 'Api',
|
|
47
|
+
path: 'apps/api',
|
|
48
|
+
endpoints: [],
|
|
49
|
+
provides: ['API_URL'],
|
|
50
|
+
},
|
|
51
|
+
} as const satisfies ConstructManifest;
|
|
52
|
+
|
|
53
|
+
// Valid: the two the synth cannot guess, plus an optional bucket prop.
|
|
54
|
+
export const ok = fromManifest(stack, constructs, {
|
|
55
|
+
Orders: { vpc },
|
|
56
|
+
Mail: { from: 'no-reply@example.com' },
|
|
57
|
+
Uploads: { cors: false },
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// A database without its VPC.
|
|
61
|
+
// @ts-expect-error — `Orders` is a database: `vpc` is required.
|
|
62
|
+
fromManifest(stack, constructs, { Mail: { from: 'a@example.com' } });
|
|
63
|
+
|
|
64
|
+
// Mail without a sender.
|
|
65
|
+
fromManifest(stack, constructs, {
|
|
66
|
+
Orders: { vpc },
|
|
67
|
+
// @ts-expect-error — every provider rejects an unverified sender.
|
|
68
|
+
Mail: {},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// A misspelt id.
|
|
72
|
+
fromManifest(stack, constructs, {
|
|
73
|
+
Orders: { vpc },
|
|
74
|
+
Mail: { from: 'a@example.com' },
|
|
75
|
+
// @ts-expect-error — not a construct in this manifest.
|
|
76
|
+
Ordrs: { vpc },
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// A prop the kind's component never reads.
|
|
80
|
+
fromManifest(stack, constructs, {
|
|
81
|
+
Orders: { vpc },
|
|
82
|
+
Mail: { from: 'a@example.com' },
|
|
83
|
+
// @ts-expect-error — a surface takes API Gateway args, not bucket ones.
|
|
84
|
+
Api: { versioning: true },
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// What the declaration already decides is not overridable.
|
|
88
|
+
fromManifest(stack, constructs, {
|
|
89
|
+
// @ts-expect-error — the schema is the declaration's, not the deploy's.
|
|
90
|
+
Orders: { vpc, schema: 'other' },
|
|
91
|
+
Mail: { from: 'a@example.com' },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// A kind with nothing to override takes no key.
|
|
95
|
+
fromManifest(stack, constructs, {
|
|
96
|
+
Orders: { vpc },
|
|
97
|
+
Mail: { from: 'a@example.com' },
|
|
98
|
+
// @ts-expect-error — a schema derives from its database.
|
|
99
|
+
Billing: {},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Nor does a cache in a database: same address, one more table.
|
|
103
|
+
fromManifest(stack, constructs, {
|
|
104
|
+
Orders: { vpc },
|
|
105
|
+
Mail: { from: 'a@example.com' },
|
|
106
|
+
// @ts-expect-error — `Rates` lives in `Orders`.
|
|
107
|
+
Rates: { region: 'eu-west-1' },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// The backend decides too: ElastiCache needs a VPC to live in…
|
|
111
|
+
fromManifest(
|
|
112
|
+
stack,
|
|
113
|
+
constructs,
|
|
114
|
+
// @ts-expect-error — `Sessions` on ElastiCache needs `vpc`.
|
|
115
|
+
{ Orders: { vpc }, Mail: { from: 'a@example.com' } },
|
|
116
|
+
{ cache: 'elasticache' },
|
|
117
|
+
);
|
|
118
|
+
export const elasticache = fromManifest(
|
|
119
|
+
stack,
|
|
120
|
+
constructs,
|
|
121
|
+
{
|
|
122
|
+
Orders: { vpc },
|
|
123
|
+
Sessions: { vpc: { subnets: [], securityGroups: [] } },
|
|
124
|
+
Mail: { from: 'a@example.com' },
|
|
125
|
+
},
|
|
126
|
+
{ cache: 'elasticache' },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// …and mail that is not SES is an account somebody created, with its URL.
|
|
130
|
+
fromManifest(
|
|
131
|
+
stack,
|
|
132
|
+
constructs,
|
|
133
|
+
{
|
|
134
|
+
Orders: { vpc },
|
|
135
|
+
// @ts-expect-error — Resend's URL is not something a deploy can mint.
|
|
136
|
+
Mail: { from: 'a@example.com' },
|
|
137
|
+
},
|
|
138
|
+
{ email: 'resend' },
|
|
139
|
+
);
|
|
140
|
+
export const resend = fromManifest(
|
|
141
|
+
stack,
|
|
142
|
+
constructs,
|
|
143
|
+
{
|
|
144
|
+
Orders: { vpc },
|
|
145
|
+
Mail: { from: 'a@example.com', url: 'smtp://resend' },
|
|
146
|
+
},
|
|
147
|
+
{ email: 'resend' },
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
// A manifest whose ids are not known statically keeps the untyped record.
|
|
151
|
+
declare const untyped: ConstructManifest;
|
|
152
|
+
export const loose = fromManifest(stack, untyped, { Anything: { at: 'all' } });
|