@geekmidas/cloud 10.0.0-alpha.165 → 10.0.0-alpha.167
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.
|
|
3
|
+
"version": "10.0.0-alpha.167",
|
|
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.167",
|
|
45
|
+
"@geekmidas/manifest": "10.0.0-alpha.167"
|
|
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.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"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@geekmidas/manifest": {
|
|
@@ -60,17 +60,21 @@ describe('provisionerFor', () => {
|
|
|
60
60
|
describe('assertProvides', () => {
|
|
61
61
|
it('passes when declared and supplied agree', () => {
|
|
62
62
|
expect(() =>
|
|
63
|
-
assertProvides(
|
|
63
|
+
assertProvides(
|
|
64
|
+
'Uploads',
|
|
65
|
+
['UPLOADS_CONNECTION_STRING'],
|
|
66
|
+
['UPLOADS_CONNECTION_STRING'],
|
|
67
|
+
),
|
|
64
68
|
).not.toThrow();
|
|
65
69
|
});
|
|
66
70
|
|
|
67
71
|
it('catches infra supplying nothing for a declared key', () => {
|
|
68
72
|
expect.assertions(2);
|
|
69
73
|
try {
|
|
70
|
-
assertProvides('Uploads', ['
|
|
74
|
+
assertProvides('Uploads', ['UPLOADS_CONNECTION_STRING'], []);
|
|
71
75
|
} catch (error) {
|
|
72
76
|
const e = error as ProvidesMismatch;
|
|
73
|
-
expect(e.missing).toEqual(['
|
|
77
|
+
expect(e.missing).toEqual(['UPLOADS_CONNECTION_STRING']);
|
|
74
78
|
expect(e.extra).toEqual([]);
|
|
75
79
|
}
|
|
76
80
|
});
|
|
@@ -80,8 +84,8 @@ describe('assertProvides', () => {
|
|
|
80
84
|
try {
|
|
81
85
|
assertProvides(
|
|
82
86
|
'Uploads',
|
|
83
|
-
['
|
|
84
|
-
['
|
|
87
|
+
['UPLOADS_CONNECTION_STRING'],
|
|
88
|
+
['UPLOADS_CONNECTION_STRING', 'UPLOADS_CDN_URL'],
|
|
85
89
|
);
|
|
86
90
|
} catch (error) {
|
|
87
91
|
const e = error as ProvidesMismatch;
|
|
@@ -109,14 +113,16 @@ describe('ObjectStorage', () => {
|
|
|
109
113
|
const bucket = new ObjectStorage({} as never, 'Uploads');
|
|
110
114
|
|
|
111
115
|
it('composes the url from the resource, not the stack', () => {
|
|
112
|
-
expect(bucket.provides().
|
|
116
|
+
expect(bucket.provides().connectionString).toBe(
|
|
117
|
+
's3://Uploads?region=stub-region',
|
|
118
|
+
);
|
|
113
119
|
});
|
|
114
120
|
|
|
115
121
|
it('carries those values on the link, which is what reaches runtime', () => {
|
|
116
122
|
const link = bucket.getSSTLink();
|
|
117
123
|
expect(link.properties).toMatchObject({
|
|
118
124
|
name: 'Uploads',
|
|
119
|
-
|
|
125
|
+
connectionString: 's3://Uploads?region=stub-region',
|
|
120
126
|
});
|
|
121
127
|
});
|
|
122
128
|
|
|
@@ -125,11 +131,11 @@ describe('ObjectStorage', () => {
|
|
|
125
131
|
});
|
|
126
132
|
|
|
127
133
|
it('supplies exactly the key the construct declares', () => {
|
|
128
|
-
// The construct emits provides: ['
|
|
134
|
+
// The construct emits provides: ['UPLOADS_CONNECTION_STRING']; a role becomes that key.
|
|
129
135
|
expect(() =>
|
|
130
136
|
assertProvides(
|
|
131
137
|
'Uploads',
|
|
132
|
-
['
|
|
138
|
+
['UPLOADS_CONNECTION_STRING'],
|
|
133
139
|
Object.keys(bucket.provides()).map((role) =>
|
|
134
140
|
provideKey('Uploads', role),
|
|
135
141
|
),
|
|
@@ -139,7 +145,7 @@ describe('ObjectStorage', () => {
|
|
|
139
145
|
|
|
140
146
|
it('is what envkit flattens into env', () => {
|
|
141
147
|
expect(resolveEnvKeys({ Uploads: { type: bucket._type } })).toContain(
|
|
142
|
-
'
|
|
148
|
+
'UPLOADS_CONNECTION_STRING',
|
|
143
149
|
);
|
|
144
150
|
});
|
|
145
151
|
});
|
|
@@ -191,7 +197,7 @@ describe('resolveEdges', () => {
|
|
|
191
197
|
provisioned,
|
|
192
198
|
);
|
|
193
199
|
expect(link.map((l) => l._id)).toEqual(['Uploads']);
|
|
194
|
-
expect(envKeys).toContain('
|
|
200
|
+
expect(envKeys).toContain('UPLOADS_CONNECTION_STRING');
|
|
195
201
|
});
|
|
196
202
|
|
|
197
203
|
it('links nothing more — the property least privilege depends on', () => {
|
|
@@ -235,7 +241,9 @@ describe('resolveEdges', () => {
|
|
|
235
241
|
|
|
236
242
|
describe('the key a provided role becomes', () => {
|
|
237
243
|
it('qualifies an ordinary role by its id', () => {
|
|
238
|
-
expect(providedKeyFor('Uploads', 'objects', '
|
|
244
|
+
expect(providedKeyFor('Uploads', 'objects', 'connectionString')).toBe(
|
|
245
|
+
'UPLOADS_CONNECTION_STRING',
|
|
246
|
+
);
|
|
239
247
|
});
|
|
240
248
|
|
|
241
249
|
it('leaves a secret’s name as its key', () => {
|
|
@@ -366,7 +374,11 @@ describe('a queue’s one consumer', () => {
|
|
|
366
374
|
|
|
367
375
|
subscribeConsumers(
|
|
368
376
|
{
|
|
369
|
-
Uploads: {
|
|
377
|
+
Uploads: {
|
|
378
|
+
kind: 'objects',
|
|
379
|
+
id: 'Uploads',
|
|
380
|
+
provides: ['UPLOADS_CONNECTION_STRING'],
|
|
381
|
+
},
|
|
370
382
|
Emails: {
|
|
371
383
|
kind: 'queue',
|
|
372
384
|
id: 'Emails',
|
|
@@ -417,7 +429,11 @@ describe('a surface’s endpoints', () => {
|
|
|
417
429
|
|
|
418
430
|
mountRoutes(
|
|
419
431
|
{
|
|
420
|
-
Uploads: {
|
|
432
|
+
Uploads: {
|
|
433
|
+
kind: 'objects',
|
|
434
|
+
id: 'Uploads',
|
|
435
|
+
provides: ['UPLOADS_CONNECTION_STRING'],
|
|
436
|
+
},
|
|
421
437
|
Api: {
|
|
422
438
|
kind: 'rest-api',
|
|
423
439
|
id: 'Api',
|
|
@@ -515,7 +531,11 @@ describe('functions and crons', () => {
|
|
|
515
531
|
stack,
|
|
516
532
|
{
|
|
517
533
|
Orders: { kind: 'database', id: 'Orders' },
|
|
518
|
-
Uploads: {
|
|
534
|
+
Uploads: {
|
|
535
|
+
kind: 'objects',
|
|
536
|
+
id: 'Uploads',
|
|
537
|
+
provides: ['UPLOADS_CONNECTION_STRING'],
|
|
538
|
+
},
|
|
519
539
|
Invoice: {
|
|
520
540
|
kind: 'function',
|
|
521
541
|
id: 'Invoice',
|
|
@@ -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',
|
|
@@ -106,6 +114,9 @@ describe('siteEnvironment', () => {
|
|
|
106
114
|
context({
|
|
107
115
|
Api: provided({ url: 'https://api.example.com' }),
|
|
108
116
|
Orders: provided({ url: 'postgres://user:pw@db/orders' }),
|
|
117
|
+
Uploads: provided({
|
|
118
|
+
connectionString: 's3://uploads-x1?region=eu-west-1',
|
|
119
|
+
}),
|
|
109
120
|
UploadsServer: provided({ url: 'https://files.example.com' }),
|
|
110
121
|
Mailer: provided({
|
|
111
122
|
url: 'smtp://user:pw@email-smtp.example.com:587',
|
|
@@ -121,8 +132,43 @@ describe('siteEnvironment', () => {
|
|
|
121
132
|
it('inlines a served bucket’s address, but never the bucket’s own', () => {
|
|
122
133
|
// A served URL is what a browser fetches; the bucket's presigns, and a
|
|
123
134
|
// presigner in a bundle is a credential in a bundle.
|
|
124
|
-
expect(built().
|
|
125
|
-
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
|
+
});
|
|
126
172
|
});
|
|
127
173
|
|
|
128
174
|
it('keeps a connection string out of the bundle entirely', () => {
|
|
@@ -40,7 +40,7 @@ export class ObjectStorage<
|
|
|
40
40
|
/**
|
|
41
41
|
* The values this bucket resolves onto anything that depends on it, keyed by
|
|
42
42
|
* role. `provideKey` 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
46
|
* be supplied through props or generated, and the region is the bucket's, not
|
|
@@ -50,7 +50,7 @@ export class ObjectStorage<
|
|
|
50
50
|
*/
|
|
51
51
|
provides(): Record<string, $util.Input<string>> {
|
|
52
52
|
return {
|
|
53
|
-
|
|
53
|
+
connectionString: $util
|
|
54
54
|
.all([this.name, this.nodes.bucket.region])
|
|
55
55
|
.apply(([bucket, region]) => s3Url.build({ bucket, region })),
|
|
56
56
|
};
|
package/src/sst/fromManifest.ts
CHANGED
|
@@ -28,6 +28,9 @@ import {
|
|
|
28
28
|
cookieDomain,
|
|
29
29
|
DEFAULT_POSTGRES_VERSION,
|
|
30
30
|
dependentsOf,
|
|
31
|
+
IMAGE_ORIGINS_KEY,
|
|
32
|
+
imageOriginSources,
|
|
33
|
+
imageOrigins,
|
|
31
34
|
isWildcardSite,
|
|
32
35
|
mobileOrigins,
|
|
33
36
|
PUBLIC,
|
|
@@ -38,6 +41,7 @@ import {
|
|
|
38
41
|
SECRET_SYMBOLS,
|
|
39
42
|
schemeBase,
|
|
40
43
|
} from '@geekmidas/manifest';
|
|
44
|
+
import { s3Url } from '@geekmidas/storage/aws';
|
|
41
45
|
import { RandomPassword } from '@pulumi/random';
|
|
42
46
|
import {
|
|
43
47
|
Cache,
|
|
@@ -493,30 +497,76 @@ export function siteEnvironment(
|
|
|
493
497
|
}
|
|
494
498
|
}
|
|
495
499
|
|
|
496
|
-
|
|
497
|
-
const target = context.manifest[edge.target];
|
|
498
|
-
if (!target) continue;
|
|
499
|
-
|
|
500
|
+
const inline = (id: string, target: Declaration) => {
|
|
500
501
|
const roles = PUBLIC[target.kind] ?? [];
|
|
501
|
-
if (roles.length === 0)
|
|
502
|
+
if (roles.length === 0) return;
|
|
502
503
|
|
|
503
|
-
const component = context.provisioned[
|
|
504
|
+
const component = context.provisioned[id];
|
|
504
505
|
if (!component) {
|
|
505
|
-
throw new UnresolvedDependency(
|
|
506
|
-
edge.target,
|
|
507
|
-
Object.keys(context.provisioned),
|
|
508
|
-
);
|
|
506
|
+
throw new UnresolvedDependency(id, Object.keys(context.provisioned));
|
|
509
507
|
}
|
|
510
508
|
|
|
511
|
-
const provided = component.provides();
|
|
509
|
+
const provided = { ...component.provides() };
|
|
510
|
+
// A bucket's signed origin is derived from its connection, not
|
|
511
|
+
// provided: where its presigned links point is a function of it.
|
|
512
|
+
if (target.kind === 'objects' && provided.connectionString !== undefined) {
|
|
513
|
+
provided.signedOrigin ??= $util
|
|
514
|
+
.output(provided.connectionString)
|
|
515
|
+
.apply((connection) => s3Url.signedOrigin(s3Url.parse(connection)));
|
|
516
|
+
}
|
|
512
517
|
for (const role of roles) {
|
|
513
518
|
const value = provided[role as string];
|
|
514
519
|
if (value === undefined) continue;
|
|
515
520
|
|
|
516
521
|
environment[
|
|
517
|
-
`${prefix}${providedKeyFor(
|
|
522
|
+
`${prefix}${providedKeyFor(id, target.kind, role as string)}`
|
|
518
523
|
] = value;
|
|
519
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
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// The origins its pages load files from, as one list: composed from the
|
|
550
|
+
// values just inlined, under the names `imageOriginSources` gives them.
|
|
551
|
+
const inlined = imageOriginSources(declaration, context.manifest).flatMap(
|
|
552
|
+
(source) => {
|
|
553
|
+
const value = environment[`${prefix}${source}`];
|
|
554
|
+
return value === undefined ? [] : [{ source, value }];
|
|
555
|
+
},
|
|
556
|
+
);
|
|
557
|
+
if (inlined.length > 0) {
|
|
558
|
+
environment[`${prefix}${IMAGE_ORIGINS_KEY}`] = $util
|
|
559
|
+
.all(inlined.map(({ value }) => value))
|
|
560
|
+
.apply((values) => {
|
|
561
|
+
const resolved = new Map(
|
|
562
|
+
inlined.map(({ source }, index) => [source, values[index]]),
|
|
563
|
+
);
|
|
564
|
+
return (
|
|
565
|
+
imageOrigins([...resolved.keys()], (source) =>
|
|
566
|
+
resolved.get(source),
|
|
567
|
+
) ?? ''
|
|
568
|
+
);
|
|
569
|
+
});
|
|
520
570
|
}
|
|
521
571
|
|
|
522
572
|
return environment;
|