@geekmidas/cloud 10.0.0-alpha.99 → 10.0.0

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.
Files changed (74) hide show
  1. package/README.md +6 -14
  2. package/dist/index-ByEJy40r.d.cts +56 -0
  3. package/dist/index-ByEJy40r.d.cts.map +1 -0
  4. package/dist/index-DZ0QrJQr.d.mts +56 -0
  5. package/dist/index-DZ0QrJQr.d.mts.map +1 -0
  6. package/dist/index.cjs +3 -3
  7. package/dist/index.d.cts +1 -1
  8. package/dist/index.d.mts +1 -1
  9. package/dist/index.mjs +3 -2
  10. package/dist/utils/index.cjs +5 -106
  11. package/dist/utils/index.d.cts +2 -62
  12. package/dist/utils/index.d.mts +2 -62
  13. package/dist/utils/index.mjs +2 -78
  14. package/dist/utils-BdKG20_m.mjs +83 -0
  15. package/dist/utils-BdKG20_m.mjs.map +1 -0
  16. package/dist/utils-CtMjuIMR.cjs +129 -0
  17. package/dist/utils-CtMjuIMR.cjs.map +1 -0
  18. package/package.json +9 -47
  19. package/src/sst/{aws/Api.ts → Api.ts} +47 -19
  20. package/src/sst/{aws/Cron.ts → Cron.ts} +46 -6
  21. package/src/sst/{aws/Function.ts → Function.ts} +41 -12
  22. package/src/sst/Queue.ts +46 -0
  23. package/src/sst/{aws/Storage.ts → Storage.ts} +3 -3
  24. package/src/sst/Topic.ts +37 -0
  25. package/src/sst/__tests__/LinkedEnvironment.spec.ts +1 -4
  26. package/src/sst/__type-tests__/authorizers.type-test.ts +2 -2
  27. package/src/sst/__type-tests__/manifest.type-test.ts +77 -0
  28. package/src/sst/__type-tests__/messaging.type-test.ts +3 -3
  29. package/src/sst/__type-tests__/storage.type-test.ts +2 -2
  30. package/src/sst/index.ts +7 -67
  31. package/src/sst/naming.ts +16 -37
  32. package/src/sst/tsconfig.json +2 -2
  33. package/dist/utils/index.cjs.map +0 -1
  34. package/dist/utils/index.d.cts.map +0 -1
  35. package/dist/utils/index.d.mts.map +0 -1
  36. package/dist/utils/index.mjs.map +0 -1
  37. package/src/dokploy/Application.ts +0 -306
  38. package/src/dokploy/__tests__/Application.provider.spec.ts +0 -206
  39. package/src/dokploy/__tests__/Application.spec.ts +0 -69
  40. package/src/dokploy/index.ts +0 -18
  41. package/src/sst/__tests__/api.spec.ts +0 -185
  42. package/src/sst/__tests__/backends.spec.ts +0 -249
  43. package/src/sst/__tests__/bootstrap.spec.ts +0 -140
  44. package/src/sst/__tests__/database.spec.ts +0 -119
  45. package/src/sst/__tests__/encryption.spec.ts +0 -90
  46. package/src/sst/__tests__/fromManifest.integration.spec.ts +0 -427
  47. package/src/sst/__tests__/fromManifest.spec.ts +0 -567
  48. package/src/sst/__tests__/function.spec.ts +0 -121
  49. package/src/sst/__tests__/links.spec.ts +0 -209
  50. package/src/sst/__tests__/provides.spec.ts +0 -107
  51. package/src/sst/__tests__/ses.spec.ts +0 -93
  52. package/src/sst/__tests__/surfaces.spec.ts +0 -149
  53. package/src/sst/__type-tests__/overrides.type-test.ts +0 -152
  54. package/src/sst/aws/Cache.ts +0 -259
  55. package/src/sst/aws/Credential.ts +0 -61
  56. package/src/sst/aws/Database.ts +0 -204
  57. package/src/sst/aws/DatabaseBootstrap.ts +0 -312
  58. package/src/sst/aws/DerivedDatabase.ts +0 -117
  59. package/src/sst/aws/Email.ts +0 -181
  60. package/src/sst/aws/Encryption.ts +0 -91
  61. package/src/sst/aws/ExternalApi.ts +0 -58
  62. package/src/sst/aws/FileServer.ts +0 -82
  63. package/src/sst/aws/ObjectStorage.ts +0 -76
  64. package/src/sst/aws/Queue.ts +0 -149
  65. package/src/sst/aws/RestApiSurface.ts +0 -114
  66. package/src/sst/aws/Secret.ts +0 -76
  67. package/src/sst/aws/StaticSite.ts +0 -92
  68. package/src/sst/aws/Topic.ts +0 -68
  69. package/src/sst/aws/bootstrap/handler.ts +0 -119
  70. package/src/sst/aws/ses.ts +0 -132
  71. package/src/sst/errors.ts +0 -65
  72. package/src/sst/fromManifest.ts +0 -1116
  73. package/src/sst/overrides.ts +0 -133
  74. package/src/sst/upstash.d.ts +0 -38
@@ -1,567 +0,0 @@
1
- import { resolveEnvKeys } from '@geekmidas/envkit/sst';
2
- import { NoUrlForStage, providedKeyFor, provideKey } from '@geekmidas/manifest';
3
- import { describe, expect, it } from 'vitest';
4
- import { App } from '../App';
5
- import { Cron } from '../aws/Cron';
6
- import { Database } from '../aws/Database';
7
- import { DatabaseSchema } from '../aws/DerivedDatabase';
8
- import { Function } from '../aws/Function';
9
- import { ObjectStorage } from '../aws/ObjectStorage';
10
- import { RestApiSurface } from '../aws/RestApiSurface';
11
- import { type ProvidesMismatch, UnknownDeclarationKind } from '../errors';
12
- import {
13
- assertProvides,
14
- mountRoutes,
15
- PROVISIONED_ELSEWHERE,
16
- type ProvisionedManifest,
17
- provisionCompute,
18
- provisionerFor,
19
- resolveEdges,
20
- subscribeConsumers,
21
- vpcFor,
22
- } from '../fromManifest';
23
-
24
- /**
25
- * The decisions, tested as data. Instantiating a component needs Pulumi, so the
26
- * adapter keeps its decisions in pure functions and its Pulumi in three lines —
27
- * otherwise nothing here would be reachable without a deploy.
28
- */
29
-
30
- describe('provisionerFor', () => {
31
- it('resolves a kind this adapter can provision', () => {
32
- expect(provisionerFor('objects')).toBeTypeOf('function');
33
- });
34
-
35
- it.each([
36
- 'objects',
37
- 'queue',
38
- 'topic',
39
- 'secret',
40
- ] as const)('provisions %s', (kind) => {
41
- expect(provisionerFor(kind)).toBeTypeOf('function');
42
- });
43
-
44
- it('reports what is supported when a kind has no provisioner', () => {
45
- expect.assertions(3);
46
- try {
47
- // A kind no adapter will ever have, so this test does not go stale
48
- // every time one more kind becomes provisionable.
49
- provisionerFor('carrier-pigeon' as never);
50
- } catch (error) {
51
- const e = error as UnknownDeclarationKind;
52
- expect(e).toBeInstanceOf(UnknownDeclarationKind);
53
- expect(e.kind).toBe('carrier-pigeon');
54
- expect(e.supported).toContain('objects');
55
- }
56
- });
57
- });
58
-
59
- describe('assertProvides', () => {
60
- it('passes when declared and supplied agree', () => {
61
- expect(() =>
62
- assertProvides('Uploads', ['UPLOADS_URL'], ['UPLOADS_URL']),
63
- ).not.toThrow();
64
- });
65
-
66
- it('catches infra supplying nothing for a declared key', () => {
67
- expect.assertions(2);
68
- try {
69
- assertProvides('Uploads', ['UPLOADS_URL'], []);
70
- } catch (error) {
71
- const e = error as ProvidesMismatch;
72
- expect(e.missing).toEqual(['UPLOADS_URL']);
73
- expect(e.extra).toEqual([]);
74
- }
75
- });
76
-
77
- it('catches infra supplying a key the app never declared', () => {
78
- expect.assertions(2);
79
- try {
80
- assertProvides(
81
- 'Uploads',
82
- ['UPLOADS_URL'],
83
- ['UPLOADS_URL', 'UPLOADS_CDN_URL'],
84
- );
85
- } catch (error) {
86
- const e = error as ProvidesMismatch;
87
- expect(e.missing).toEqual([]);
88
- // adding cdn to the component without declaring it is caught here
89
- expect(e.extra).toEqual(['UPLOADS_CDN_URL']);
90
- }
91
- });
92
-
93
- it('treats both sides as empty by default, so a resource may provide nothing', () => {
94
- expect(() => assertProvides('Nothing')).not.toThrow();
95
- });
96
-
97
- it('names the construct, since a manifest has many', () => {
98
- expect.assertions(1);
99
- try {
100
- assertProvides('Avatars', ['AVATARS_URL'], []);
101
- } catch (error) {
102
- expect((error as ProvidesMismatch).id).toBe('Avatars');
103
- }
104
- });
105
- });
106
-
107
- describe('ObjectStorage', () => {
108
- const bucket = new ObjectStorage({} as never, 'Uploads');
109
-
110
- it('composes the url from the resource, not the stack', () => {
111
- expect(bucket.provides().url).toBe('s3://Uploads?region=stub-region');
112
- });
113
-
114
- it('carries those values on the link, which is what reaches runtime', () => {
115
- const link = bucket.getSSTLink();
116
- expect(link.properties).toMatchObject({
117
- name: 'Uploads',
118
- url: 's3://Uploads?region=stub-region',
119
- });
120
- });
121
-
122
- it('leaves the permissions super grants alone', () => {
123
- expect(bucket.getSSTLink()).toHaveProperty('include');
124
- });
125
-
126
- it('supplies exactly the key the construct declares', () => {
127
- // The construct emits provides: ['UPLOADS_URL']; a role becomes that key.
128
- expect(() =>
129
- assertProvides(
130
- 'Uploads',
131
- ['UPLOADS_URL'],
132
- Object.keys(bucket.provides()).map((role) =>
133
- provideKey('Uploads', role),
134
- ),
135
- ),
136
- ).not.toThrow();
137
- });
138
-
139
- it('is what envkit flattens into env', () => {
140
- expect(resolveEnvKeys({ Uploads: { type: bucket._type } })).toContain(
141
- 'UPLOADS_URL',
142
- );
143
- });
144
- });
145
-
146
- describe('component settings', () => {
147
- const provision = (
148
- declaration: never,
149
- props = {},
150
- manifest: ConstructManifest = {},
151
- ) =>
152
- provisionerFor('objects')({} as never, declaration, props, {
153
- manifest,
154
- provisioned: {},
155
- }) as unknown as {
156
- name: string;
157
- props?: Record<string, unknown>;
158
- };
159
-
160
- it('maps a declared neutral option to this provider’s word for it', () => {
161
- // `versioned` is the app's vocabulary; `versioning` is S3's.
162
- const bucket = provision({
163
- kind: 'objects',
164
- id: 'Uploads',
165
- versioned: true,
166
- } as never);
167
- expect(bucket.name).toBe('Uploads');
168
- });
169
-
170
- it('accepts provider-specific props the declaration cannot express', () => {
171
- expect(() =>
172
- provision({ kind: 'objects', id: 'Uploads' } as never, {
173
- cors: [{ allowOrigins: ['*'] }],
174
- }),
175
- ).not.toThrow();
176
- });
177
- });
178
-
179
- describe('resolveEdges', () => {
180
- const stub = (id: string) => ({ _id: id, _type: 'sst.aws.Bucket' }) as never;
181
-
182
- const provisioned = {
183
- Uploads: stub('Uploads'),
184
- Avatars: stub('Avatars'),
185
- } as unknown as ProvisionedManifest;
186
-
187
- it('links what the function declared, and yields its keys', () => {
188
- const { link, envKeys } = resolveEdges(
189
- [{ target: 'Uploads', kind: 'objects' }],
190
- provisioned,
191
- );
192
- expect(link.map((l) => l._id)).toEqual(['Uploads']);
193
- expect(envKeys).toContain('UPLOADS_URL');
194
- });
195
-
196
- it('links nothing more — the property least privilege depends on', () => {
197
- const { link, envKeys } = resolveEdges(
198
- [{ target: 'Uploads', kind: 'objects' }],
199
- provisioned,
200
- );
201
- expect(link.map((l) => l._id)).not.toContain('Avatars');
202
- expect(envKeys.some((k) => k.startsWith('AVATARS'))).toBe(false);
203
- });
204
-
205
- it('is unchanged when an unrelated construct joins the manifest', () => {
206
- const before = resolveEdges(
207
- [{ target: 'Uploads', kind: 'objects' }],
208
- provisioned,
209
- );
210
- const after = resolveEdges([{ target: 'Uploads', kind: 'objects' }], {
211
- ...provisioned,
212
- Reports: stub('Reports'),
213
- } as unknown as ProvisionedManifest);
214
-
215
- expect(after.envKeys).toEqual(before.envKeys);
216
- expect(after.link.map((l) => l._id)).toEqual(before.link.map((l) => l._id));
217
- });
218
-
219
- it('gives a function with no edges nothing at all', () => {
220
- expect(resolveEdges([], provisioned)).toEqual({ link: [], envKeys: [] });
221
- });
222
-
223
- it('names what is available when an edge does not resolve', () => {
224
- expect.assertions(2);
225
- try {
226
- resolveEdges([{ target: 'Missing', kind: 'objects' }], provisioned);
227
- } catch (error) {
228
- const e = error as UnresolvedDependency;
229
- expect(e.target).toBe('Missing');
230
- expect(e.available).toContain('Uploads');
231
- }
232
- });
233
- });
234
-
235
- describe('the key a provided role becomes', () => {
236
- it('qualifies an ordinary role by its id', () => {
237
- expect(providedKeyFor('Uploads', 'objects', 'url')).toBe('UPLOADS_URL');
238
- });
239
-
240
- it('leaves a secret’s name as its key', () => {
241
- // `Auth` signs with `AUTH_SECRET`, which is also what better-auth's own
242
- // tooling looks for — and qualifying it would produce
243
- // `AUTH_SECRET_VALUE`, which nothing reads.
244
- expect(providedKeyFor('AuthSecret', 'secret', 'value')).toBe('AUTH_SECRET');
245
- });
246
-
247
- it('is the same derivation the contract check uses', () => {
248
- // The point of sharing it: a check deriving the key differently from the
249
- // thing it checks passes on drift instead of catching it.
250
- expect(() =>
251
- assertProvides(
252
- 'AuthSecret',
253
- ['AUTH_SECRET'],
254
- ['value'].map((role) => providedKeyFor('AuthSecret', 'secret', role)),
255
- ),
256
- ).not.toThrow();
257
- });
258
- });
259
-
260
- describe('Credential', () => {
261
- it('provides under the role the declaration named', async () => {
262
- // The role *is* the contract: providing `value` against a declared
263
- // `STRIPE_CREDENTIALS` supplies `STRIPE_VALUE`, and assertProvides
264
- // rejects the stack at synth. Which is the check working.
265
- const { Credential } = await import('../aws/Credential');
266
-
267
- expect(
268
- Object.keys(new Credential({} as never, 'Stripe').provides()),
269
- ).toEqual(['credentials']);
270
- });
271
-
272
- it('agrees with what the construct declares', () => {
273
- expect(providedKeyFor('Stripe', 'credential', 'credentials')).toBe(
274
- 'STRIPE_CREDENTIALS',
275
- );
276
- });
277
-
278
- it('links under the key the construct reads, not the secret’s bare name', async () => {
279
- const { Credential } = await import('../aws/Credential');
280
- const stripe = new Credential({} as never, 'Stripe');
281
-
282
- expect(resolveEnvKeys({ Stripe: { type: stripe._type } })).toEqual([
283
- 'STRIPE_CREDENTIALS',
284
- ]);
285
- expect(stripe.getSSTLink().properties).toEqual(stripe.provides());
286
- });
287
-
288
- it('is what a function depending on it is linked to', async () => {
289
- const { Credential } = await import('../aws/Credential');
290
- const stripe = new Credential({} as never, 'Stripe');
291
-
292
- const { link, envKeys } = resolveEdges(
293
- [{ target: 'Stripe', kind: 'credential' }],
294
- { Stripe: stripe },
295
- );
296
-
297
- expect(link).toEqual([stripe]);
298
- expect(envKeys).toEqual(['STRIPE_CREDENTIALS']);
299
- });
300
- });
301
-
302
- describe('ExternalApi', () => {
303
- const stack = (stage: string) => ({ stage }) as never;
304
-
305
- it('provides the URL for its stage and its credentials, under the declared keys', async () => {
306
- const { ExternalApi } = await import('../aws/ExternalApi');
307
- const payfast = new ExternalApi(stack('production'), 'PayFast', {
308
- url: {
309
- production: 'https://www.payfast.co.za',
310
- default: 'https://sandbox.payfast.co.za',
311
- },
312
- });
313
-
314
- expect(payfast.provides().url).toBe('https://www.payfast.co.za');
315
- expect(
316
- Object.keys(payfast.provides()).map((role) =>
317
- providedKeyFor('PayFast', 'external-api', role),
318
- ),
319
- ).toEqual(['PAY_FAST_URL', 'PAY_FAST_CREDENTIALS']);
320
- });
321
-
322
- it('falls back to the default URL for a stage it does not name', async () => {
323
- const { ExternalApi } = await import('../aws/ExternalApi');
324
- const payfast = new ExternalApi(stack('staging'), 'PayFast', {
325
- url: {
326
- production: 'https://www.payfast.co.za',
327
- default: 'https://sandbox.payfast.co.za',
328
- },
329
- });
330
-
331
- expect(payfast.provides().url).toBe('https://sandbox.payfast.co.za');
332
- });
333
-
334
- it('fails synth for a stage it has no URL for', async () => {
335
- const { ExternalApi } = await import('../aws/ExternalApi');
336
-
337
- expect(
338
- () =>
339
- new ExternalApi(stack('staging'), 'PayFast', {
340
- url: { production: 'https://www.payfast.co.za' },
341
- }),
342
- ).toThrow(NoUrlForStage);
343
- });
344
-
345
- it('flattens into the same keys at runtime', () => {
346
- expect(
347
- resolveEnvKeys({ PayFast: { type: 'gkm:aws:ExternalApi' } }).sort(),
348
- ).toEqual(['PAY_FAST_CREDENTIALS', 'PAY_FAST_URL']);
349
- });
350
- });
351
-
352
- describe('a queue’s one consumer', () => {
353
- it('is subscribed from the handler the build wrote, linked to what it depends on', () => {
354
- const consumed: { handler: string; link?: unknown[] }[] = [];
355
- const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
356
- const provisioned = {
357
- Uploads: uploads,
358
- Emails: {
359
- _id: 'Emails',
360
- _type: 'sst.aws.Queue',
361
- consume: (consumer: { handler: string; link?: unknown[] }) =>
362
- consumed.push(consumer),
363
- },
364
- } as unknown as ProvisionedManifest;
365
-
366
- subscribeConsumers(
367
- {
368
- Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
369
- Emails: {
370
- kind: 'queue',
371
- id: 'Emails',
372
- provides: ['EMAILS_PUBLISHER_CONNECTION_STRING'],
373
- worker: {
374
- id: 'EmailsWorker',
375
- handler: 'apps/api/.gkm/aws/queues/emails.handler',
376
- dependencies: [{ target: 'Uploads', kind: 'objects' }],
377
- },
378
- },
379
- } as never,
380
- provisioned,
381
- );
382
-
383
- expect(consumed).toEqual([
384
- { handler: 'apps/api/.gkm/aws/queues/emails.handler', link: [uploads] },
385
- ]);
386
- });
387
-
388
- it('subscribes through SST, with the queue itself linked', async () => {
389
- const { Queue } = await import('../aws/Queue');
390
- const queue = new Queue({} as never, 'Emails');
391
-
392
- queue.consume({ handler: 'emails.handler', link: [], batchSize: 5 });
393
-
394
- const [{ subscriber, args }] = (
395
- queue as unknown as { subscribed: { subscriber: any; args: unknown }[] }
396
- ).subscribed;
397
- expect(subscriber.handler).toBe('emails.handler');
398
- expect(subscriber.link).toEqual([queue]);
399
- expect(args).toEqual({ batch: { size: 5 } });
400
- });
401
- });
402
-
403
- describe('a surface’s endpoints', () => {
404
- const routesOf = (surface: RestApiSurface) =>
405
- (
406
- surface as unknown as {
407
- routes: { key: string; handler: any; args: unknown }[];
408
- }
409
- ).routes;
410
-
411
- it('are mounted from the handlers the build wrote, each linked to what it depends on', () => {
412
- // An API Gateway with no routes 404s everything — which is what a deploy
413
- // produced while the routes sat in the manifest with nothing reading them.
414
- const api = new RestApiSurface({} as never, 'Api');
415
- const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
416
-
417
- mountRoutes(
418
- {
419
- Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
420
- Api: {
421
- kind: 'rest-api',
422
- id: 'Api',
423
- provides: ['API_URL'],
424
- endpoints: [
425
- {
426
- id: 'ApiGET/users/{id}',
427
- method: 'GET',
428
- path: '/users/{id}',
429
- handler: 'apps/api/.gkm/aws/routes/getUser.handler',
430
- dependencies: [{ target: 'Uploads', kind: 'objects' }],
431
- authorizer: 'none',
432
- },
433
- {
434
- id: 'ApiGET/health',
435
- method: 'GET',
436
- path: '/health',
437
- handler: 'apps/api/.gkm/aws/routes/health.handler',
438
- dependencies: [],
439
- },
440
- ],
441
- },
442
- } as never,
443
- { Uploads: uploads, Api: api } as unknown as ProvisionedManifest,
444
- );
445
-
446
- const [getUser, health] = routesOf(api);
447
- expect(getUser?.key).toBe('GET /users/{id}');
448
- expect(getUser?.handler.handler).toBe(
449
- 'apps/api/.gkm/aws/routes/getUser.handler',
450
- );
451
- expect(getUser?.handler.link).toEqual([uploads]);
452
- expect(getUser?.args).toEqual({});
453
- // Least privilege: an endpoint is linked to its own edges, not the app's.
454
- expect(health?.key).toBe('GET /health');
455
- expect(health?.handler.link).toEqual([]);
456
- });
457
-
458
- it('leaves IAM to the gateway, and every other authorizer to the handler', () => {
459
- const api = new RestApiSurface({} as never, 'Api');
460
-
461
- api.mount({
462
- method: 'POST',
463
- path: '/x',
464
- handler: 'x.handler',
465
- authorizer: 'iam',
466
- });
467
- api.mount({
468
- method: 'POST',
469
- path: '/y',
470
- handler: 'y.handler',
471
- authorizer: 'session',
472
- });
473
-
474
- const [x, y] = routesOf(api);
475
- expect(x?.args).toEqual({ auth: { iam: true } });
476
- expect(y?.args).toEqual({});
477
- });
478
-
479
- it('runs a handler that reaches a database inside the database’s network', () => {
480
- const vpc = { id: 'stub-vpc' } as never;
481
- const cluster = new Database({} as never, 'Orders', { vpc });
482
- const tenant = new DatabaseSchema('Billing', cluster, 'billing');
483
-
484
- expect(vpcFor([cluster as never])).toBe(vpc);
485
- // A schema tenant lives in its parent's cluster, so in its network too.
486
- expect(vpcFor([{ _id: 'Uploads' } as never, tenant as never])).toBe(vpc);
487
- expect(vpcFor([{ _id: 'Uploads' } as never])).toBeUndefined();
488
- });
489
- });
490
-
491
- describe('functions and crons', () => {
492
- const stack = new App({
493
- name: 'shop',
494
- stage: 'prod',
495
- domain: 'example.com',
496
- hostedZoneId: 'Z',
497
- region: 'eu-west-1',
498
- }).stack('jobs');
499
- const argsOf = (component: unknown) =>
500
- (component as { args: Record<string, any> }).args;
501
-
502
- it('are deployed from the declarations, each linked to its own edges', () => {
503
- // The `manifest.crons` / `manifest.functions` tables they were built from
504
- // are gone: the declarations carry the handler, schedule and edges.
505
- const vpc = { id: 'stub-vpc' } as never;
506
- const orders = new Database({} as never, 'Orders', { vpc });
507
- const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
508
- const provisioned = {
509
- Orders: orders,
510
- Uploads: uploads,
511
- } as unknown as ProvisionedManifest;
512
-
513
- const [digest] = provisionCompute(
514
- stack,
515
- {
516
- Orders: { kind: 'database', id: 'Orders' },
517
- Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
518
- Invoice: {
519
- kind: 'function',
520
- id: 'Invoice',
521
- handler: 'apps/api/.gkm/aws/functions/invoice.handler',
522
- dependencies: [{ target: 'Uploads', kind: 'objects' }],
523
- provides: ['INVOICE_URL'],
524
- },
525
- Digest: {
526
- kind: 'cron',
527
- id: 'Digest',
528
- handler: 'apps/api/.gkm/aws/crons/digest.handler',
529
- schedule: 'rate(1 day)',
530
- dependencies: [{ target: 'Orders', kind: 'database' }],
531
- },
532
- } as never,
533
- provisioned,
534
- );
535
-
536
- const invoice = provisioned.Invoice as unknown as Function;
537
- expect(invoice).toBeInstanceOf(Function);
538
- expect(argsOf(invoice)).toMatchObject({
539
- name: stack.logicalPrefixedName('Invoice'),
540
- handler: 'apps/api/.gkm/aws/functions/invoice.handler',
541
- link: [uploads],
542
- url: { authorization: 'iam' },
543
- });
544
- expect(argsOf(invoice).vpc).toBeUndefined();
545
-
546
- // A cron is a schedule, not something to link to; its Lambda reaches
547
- // the database, so it runs in the database's network.
548
- expect(provisioned.Digest).toBeUndefined();
549
- expect(digest).toBeInstanceOf(Cron);
550
- expect(argsOf(digest).schedule).toBe('rate(1 day)');
551
- expect(argsOf(digest!.processor)).toMatchObject({
552
- handler: 'apps/api/.gkm/aws/crons/digest.handler',
553
- link: [orders],
554
- vpc,
555
- });
556
- });
557
- });
558
-
559
- describe('kinds provisioned elsewhere', () => {
560
- it('skips a worker, which is a process rather than a resource', () => {
561
- // A worker in the manifest used to throw UnknownDeclarationKind at synth,
562
- // so any app with background work could not be deployed to AWS at all.
563
- expect(PROVISIONED_ELSEWHERE.has('worker')).toBe(true);
564
- expect(PROVISIONED_ELSEWHERE.has('mobile-app')).toBe(true);
565
- expect(PROVISIONED_ELSEWHERE.has('queue')).toBe(false);
566
- });
567
- });
@@ -1,121 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { App } from '../App';
3
- import { Cron } from '../aws/Cron';
4
- import { Function } from '../aws/Function';
5
- import { type GkmLinkable, ResourceType } from '../Linkable';
6
-
7
- /**
8
- * A Lambda and a schedule as data: the args each hands SST (a recording stub
9
- * in `test/sst-globals.ts`), and the env validation that fails before deploy.
10
- */
11
-
12
- const app = new App({
13
- name: 'shop',
14
- stage: 'prod',
15
- domain: 'shop.test',
16
- hostedZoneId: 'Z1',
17
- region: 'eu-west-1',
18
- });
19
- const stack = app.stack('jobs');
20
- const db: GkmLinkable = { _id: 'db', _type: ResourceType.Postgres };
21
-
22
- const argsOf = (component: unknown) =>
23
- (component as { args: Record<string, unknown> }).args;
24
-
25
- describe('Function', () => {
26
- it('defaults the runtime and logging, and links only what its variables need', () => {
27
- const fn = new Function(stack, 'Reports', {
28
- handler: 'reports.handler',
29
- links: [db],
30
- envVars: ['DB_URL'],
31
- environment: { FEATURE: 'on' },
32
- });
33
-
34
- expect(fn._type).toBe(ResourceType.Function);
35
- expect(argsOf(fn)).toMatchObject({
36
- handler: 'reports.handler',
37
- runtime: 'nodejs24.x',
38
- logging: { format: 'json' },
39
- link: [db],
40
- environment: expect.objectContaining({
41
- SERVICE_NAME: 'Reports',
42
- STAGE: 'prod',
43
- FEATURE: 'on',
44
- }),
45
- });
46
- expect(fn.validate().valid).toBe(true);
47
- });
48
-
49
- it('keeps a runtime and logging it was given', () => {
50
- const fn = new Function(stack, 'Legacy', {
51
- handler: 'legacy.handler',
52
- runtime: 'nodejs20.x',
53
- logging: { format: 'text' },
54
- });
55
-
56
- expect(argsOf(fn)).toMatchObject({
57
- runtime: 'nodejs20.x',
58
- logging: { format: 'text' },
59
- link: [],
60
- });
61
- });
62
-
63
- it('fails the synth on a variable no link provides, unless told not to check', () => {
64
- expect(
65
- () =>
66
- new Function(stack, 'Mailer', {
67
- handler: 'mailer.handler',
68
- envVars: ['SMTP_URL'],
69
- }),
70
- ).toThrow(/SMTP_URL/);
71
-
72
- const unchecked = new Function(stack, 'Mailer', {
73
- handler: 'mailer.handler',
74
- envVars: ['SMTP_URL'],
75
- autoValidate: false,
76
- });
77
- expect(unchecked.validate()).toMatchObject({
78
- valid: false,
79
- invalidVars: ['SMTP_URL'],
80
- });
81
- });
82
- });
83
-
84
- describe('Cron', () => {
85
- it('schedules the function it is given, by ARN', () => {
86
- const processor = { arn: 'arn:aws:lambda:eu-west-1:1:function:nightly' };
87
- const cron = new Cron(stack, 'Nightly', {
88
- processor: processor as never,
89
- schedule: 'rate(1 day)',
90
- enabled: false,
91
- });
92
-
93
- expect(argsOf(cron)).toEqual({
94
- enabled: false,
95
- schedule: 'rate(1 day)',
96
- function: processor.arn,
97
- });
98
- });
99
- });
100
-
101
- describe('App and Stack', () => {
102
- it('pick a value for the stage, falling back to the default', () => {
103
- expect(app.select({ prod: 'live', default: 'test' })).toBe('live');
104
- expect(stack.select({ staging: 'test', default: 'dev' } as never)).toBe(
105
- 'dev',
106
- );
107
- });
108
-
109
- it('name subdomains and URLs under the root domain', () => {
110
- expect(stack.domain).toBe('shop.test');
111
- expect(stack.getSubdomain('api')).toBe('api.shop.test');
112
- expect(stack.getURL('api')).toBe('https://api.shop.test');
113
- expect(stack.getURL()).toBe('https://shop.test');
114
- expect(app.getURL()).toBe('https://shop.test');
115
- });
116
-
117
- it('prefix physical names with the stage, app and stack', () => {
118
- expect(app.logicalPrefixedName('Uploads')).toBe('prod-shop-uploads');
119
- expect(stack.logicalPrefixedName('Uploads')).toBe('prod-shop-jobs-uploads');
120
- });
121
- });