@geekmidas/cloud 10.0.0-alpha.18 → 10.0.0-alpha.181

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 (35) hide show
  1. package/README.md +26 -6
  2. package/package.json +9 -8
  3. package/src/sst/__tests__/api.spec.ts +0 -46
  4. package/src/sst/__tests__/bootstrap.spec.ts +15 -0
  5. package/src/sst/__tests__/encryption.spec.ts +90 -0
  6. package/src/sst/__tests__/fromManifest.inbox.spec.ts +157 -0
  7. package/src/sst/__tests__/fromManifest.integration.spec.ts +87 -3
  8. package/src/sst/__tests__/fromManifest.secret.spec.ts +79 -0
  9. package/src/sst/__tests__/fromManifest.spec.ts +412 -18
  10. package/src/sst/__tests__/function.spec.ts +0 -71
  11. package/src/sst/__tests__/hostLabels.spec.ts +74 -0
  12. package/src/sst/__tests__/surfaces.spec.ts +68 -5
  13. package/src/sst/__tests__/websocket.spec.ts +207 -0
  14. package/src/sst/__tests__/wildcardSite.spec.ts +195 -0
  15. package/src/sst/__type-tests__/overrides.type-test.ts +152 -0
  16. package/src/sst/aws/Api.ts +0 -43
  17. package/src/sst/aws/Credential.ts +42 -9
  18. package/src/sst/aws/Cron.ts +5 -45
  19. package/src/sst/aws/DatabaseBootstrap.ts +6 -0
  20. package/src/sst/aws/Encryption.ts +91 -0
  21. package/src/sst/aws/ExternalApi.ts +58 -0
  22. package/src/sst/aws/Function.ts +9 -38
  23. package/src/sst/aws/Inbox.ts +141 -0
  24. package/src/sst/aws/ObjectStorage.ts +3 -3
  25. package/src/sst/aws/Queue.ts +34 -1
  26. package/src/sst/aws/RestApiSurface.ts +36 -14
  27. package/src/sst/aws/Secret.ts +6 -4
  28. package/src/sst/aws/StaticSite.ts +44 -1
  29. package/src/sst/aws/WebSocketApiSurface.ts +160 -0
  30. package/src/sst/aws/bootstrap/handler.ts +12 -1
  31. package/src/sst/errors.ts +37 -0
  32. package/src/sst/fromManifest.ts +624 -71
  33. package/src/sst/index.ts +21 -1
  34. package/src/sst/overrides.ts +149 -0
  35. package/src/sst/__type-tests__/manifest.type-test.ts +0 -77
@@ -1,13 +1,25 @@
1
1
  import { resolveEnvKeys } from '@geekmidas/envkit/sst';
2
- import { providedKeyFor, provideKey } from '@geekmidas/manifest';
2
+ import { NoUrlForStage, providedKeyFor } from '@geekmidas/manifest';
3
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';
4
9
  import { ObjectStorage } from '../aws/ObjectStorage';
10
+ import { RestApiSurface } from '../aws/RestApiSurface';
5
11
  import { type ProvidesMismatch, UnknownDeclarationKind } from '../errors';
6
12
  import {
7
13
  assertProvides,
14
+ mountRoutes,
15
+ PROVISIONED_ELSEWHERE,
8
16
  type ProvisionedManifest,
17
+ provisionCompute,
9
18
  provisionerFor,
19
+ provisionProcessors,
10
20
  resolveEdges,
21
+ subscribeConsumers,
22
+ vpcFor,
11
23
  } from '../fromManifest';
12
24
 
13
25
  /**
@@ -48,17 +60,21 @@ describe('provisionerFor', () => {
48
60
  describe('assertProvides', () => {
49
61
  it('passes when declared and supplied agree', () => {
50
62
  expect(() =>
51
- assertProvides('Uploads', ['UPLOADS_URL'], ['UPLOADS_URL']),
63
+ assertProvides(
64
+ 'Uploads',
65
+ ['UPLOADS_CONNECTION_STRING'],
66
+ ['UPLOADS_CONNECTION_STRING'],
67
+ ),
52
68
  ).not.toThrow();
53
69
  });
54
70
 
55
71
  it('catches infra supplying nothing for a declared key', () => {
56
72
  expect.assertions(2);
57
73
  try {
58
- assertProvides('Uploads', ['UPLOADS_URL'], []);
74
+ assertProvides('Uploads', ['UPLOADS_CONNECTION_STRING'], []);
59
75
  } catch (error) {
60
76
  const e = error as ProvidesMismatch;
61
- expect(e.missing).toEqual(['UPLOADS_URL']);
77
+ expect(e.missing).toEqual(['UPLOADS_CONNECTION_STRING']);
62
78
  expect(e.extra).toEqual([]);
63
79
  }
64
80
  });
@@ -68,8 +84,8 @@ describe('assertProvides', () => {
68
84
  try {
69
85
  assertProvides(
70
86
  'Uploads',
71
- ['UPLOADS_URL'],
72
- ['UPLOADS_URL', 'UPLOADS_CDN_URL'],
87
+ ['UPLOADS_CONNECTION_STRING'],
88
+ ['UPLOADS_CONNECTION_STRING', 'UPLOADS_CDN_URL'],
73
89
  );
74
90
  } catch (error) {
75
91
  const e = error as ProvidesMismatch;
@@ -97,14 +113,16 @@ describe('ObjectStorage', () => {
97
113
  const bucket = new ObjectStorage({} as never, 'Uploads');
98
114
 
99
115
  it('composes the url from the resource, not the stack', () => {
100
- expect(bucket.provides().url).toBe('s3://Uploads?region=stub-region');
116
+ expect(bucket.provides().connectionString).toBe(
117
+ 's3://Uploads?region=stub-region',
118
+ );
101
119
  });
102
120
 
103
121
  it('carries those values on the link, which is what reaches runtime', () => {
104
122
  const link = bucket.getSSTLink();
105
123
  expect(link.properties).toMatchObject({
106
124
  name: 'Uploads',
107
- url: 's3://Uploads?region=stub-region',
125
+ connectionString: 's3://Uploads?region=stub-region',
108
126
  });
109
127
  });
110
128
 
@@ -113,13 +131,13 @@ describe('ObjectStorage', () => {
113
131
  });
114
132
 
115
133
  it('supplies exactly the key the construct declares', () => {
116
- // The construct emits provides: ['UPLOADS_URL']; a role becomes that key.
134
+ // The construct emits provides: ['UPLOADS_CONNECTION_STRING']; a role becomes that key.
117
135
  expect(() =>
118
136
  assertProvides(
119
137
  'Uploads',
120
- ['UPLOADS_URL'],
138
+ ['UPLOADS_CONNECTION_STRING'],
121
139
  Object.keys(bucket.provides()).map((role) =>
122
- provideKey('Uploads', role),
140
+ providedKeyFor('Uploads', 'objects', role),
123
141
  ),
124
142
  ),
125
143
  ).not.toThrow();
@@ -127,7 +145,7 @@ describe('ObjectStorage', () => {
127
145
 
128
146
  it('is what envkit flattens into env', () => {
129
147
  expect(resolveEnvKeys({ Uploads: { type: bucket._type } })).toContain(
130
- 'UPLOADS_URL',
148
+ 'UPLOADS_CONNECTION_STRING',
131
149
  );
132
150
  });
133
151
  });
@@ -179,7 +197,7 @@ describe('resolveEdges', () => {
179
197
  provisioned,
180
198
  );
181
199
  expect(link.map((l) => l._id)).toEqual(['Uploads']);
182
- expect(envKeys).toContain('UPLOADS_URL');
200
+ expect(envKeys).toContain('UPLOADS_CONNECTION_STRING');
183
201
  });
184
202
 
185
203
  it('links nothing more — the property least privilege depends on', () => {
@@ -223,7 +241,9 @@ describe('resolveEdges', () => {
223
241
 
224
242
  describe('the key a provided role becomes', () => {
225
243
  it('qualifies an ordinary role by its id', () => {
226
- expect(providedKeyFor('Uploads', 'objects', 'url')).toBe('UPLOADS_URL');
244
+ expect(providedKeyFor('Uploads', 'objects', 'connectionString')).toBe(
245
+ 'UPLOADS_CONNECTION_STRING',
246
+ );
227
247
  });
228
248
 
229
249
  it('leaves a secret’s name as its key', () => {
@@ -249,18 +269,392 @@ describe('the key a provided role becomes', () => {
249
269
  describe('Credential', () => {
250
270
  it('provides under the role the declaration named', async () => {
251
271
  // The role *is* the contract: providing `value` against a declared
252
- // `STRIPE_CREDENTIAL` supplies `STRIPE_VALUE`, and assertProvides
272
+ // `STRIPE_CREDENTIALS` supplies `STRIPE_VALUE`, and assertProvides
253
273
  // rejects the stack at synth. Which is the check working.
254
274
  const { Credential } = await import('../aws/Credential');
255
275
 
256
276
  expect(
257
277
  Object.keys(new Credential({} as never, 'Stripe').provides()),
258
- ).toEqual(['credential']);
278
+ ).toEqual(['credentials']);
259
279
  });
260
280
 
261
281
  it('agrees with what the construct declares', () => {
262
- expect(providedKeyFor('Stripe', 'credential', 'credential')).toBe(
263
- 'STRIPE_CREDENTIAL',
282
+ expect(providedKeyFor('Stripe', 'credential', 'credentials')).toBe(
283
+ 'STRIPE_CREDENTIALS',
284
+ );
285
+ });
286
+
287
+ it('links under the key the construct reads, not the secret’s bare name', async () => {
288
+ const { Credential } = await import('../aws/Credential');
289
+ const stripe = new Credential({} as never, 'Stripe');
290
+
291
+ expect(resolveEnvKeys({ Stripe: { type: stripe._type } })).toEqual([
292
+ 'STRIPE_CREDENTIALS',
293
+ ]);
294
+ expect(stripe.getSSTLink().properties).toEqual(stripe.provides());
295
+ });
296
+
297
+ it('is what a function depending on it is linked to', async () => {
298
+ const { Credential } = await import('../aws/Credential');
299
+ const stripe = new Credential({} as never, 'Stripe');
300
+
301
+ const { link, envKeys } = resolveEdges(
302
+ [{ target: 'Stripe', kind: 'credential' }],
303
+ { Stripe: stripe },
304
+ );
305
+
306
+ expect(link).toEqual([stripe]);
307
+ expect(envKeys).toEqual(['STRIPE_CREDENTIALS']);
308
+ });
309
+ });
310
+
311
+ describe('ExternalApi', () => {
312
+ const stack = (stage: string) => ({ stage }) as never;
313
+
314
+ it('provides the URL for its stage and its credentials, under the declared keys', async () => {
315
+ const { ExternalApi } = await import('../aws/ExternalApi');
316
+ const payfast = new ExternalApi(stack('production'), 'PayFast', {
317
+ url: {
318
+ production: 'https://www.payfast.co.za',
319
+ default: 'https://sandbox.payfast.co.za',
320
+ },
321
+ });
322
+
323
+ expect(payfast.provides().url).toBe('https://www.payfast.co.za');
324
+ expect(
325
+ Object.keys(payfast.provides()).map((role) =>
326
+ providedKeyFor('PayFast', 'external-api', role),
327
+ ),
328
+ ).toEqual(['PAY_FAST_URL', 'PAY_FAST_CREDENTIALS']);
329
+ });
330
+
331
+ it('falls back to the default URL for a stage it does not name', async () => {
332
+ const { ExternalApi } = await import('../aws/ExternalApi');
333
+ const payfast = new ExternalApi(stack('staging'), 'PayFast', {
334
+ url: {
335
+ production: 'https://www.payfast.co.za',
336
+ default: 'https://sandbox.payfast.co.za',
337
+ },
338
+ });
339
+
340
+ expect(payfast.provides().url).toBe('https://sandbox.payfast.co.za');
341
+ });
342
+
343
+ it('fails synth for a stage it has no URL for', async () => {
344
+ const { ExternalApi } = await import('../aws/ExternalApi');
345
+
346
+ expect(
347
+ () =>
348
+ new ExternalApi(stack('staging'), 'PayFast', {
349
+ url: { production: 'https://www.payfast.co.za' },
350
+ }),
351
+ ).toThrow(NoUrlForStage);
352
+ });
353
+
354
+ it('flattens into the same keys at runtime', () => {
355
+ expect(
356
+ resolveEnvKeys({ PayFast: { type: 'gkm:aws:ExternalApi' } }).sort(),
357
+ ).toEqual(['PAY_FAST_CREDENTIALS', 'PAY_FAST_URL']);
358
+ });
359
+ });
360
+
361
+ describe('a queue’s one consumer', () => {
362
+ it('is subscribed from the handler the build wrote, linked to what it depends on', () => {
363
+ const consumed: { handler: string; link?: unknown[] }[] = [];
364
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
365
+ const provisioned = {
366
+ Uploads: uploads,
367
+ Emails: {
368
+ _id: 'Emails',
369
+ _type: 'sst.aws.Queue',
370
+ consume: (consumer: { handler: string; link?: unknown[] }) =>
371
+ consumed.push(consumer),
372
+ },
373
+ } as unknown as ProvisionedManifest;
374
+
375
+ subscribeConsumers(
376
+ {
377
+ Uploads: {
378
+ kind: 'objects',
379
+ id: 'Uploads',
380
+ provides: ['UPLOADS_CONNECTION_STRING'],
381
+ },
382
+ Emails: {
383
+ kind: 'queue',
384
+ id: 'Emails',
385
+ provides: ['EMAILS_PUBLISHER_CONNECTION_STRING'],
386
+ worker: {
387
+ id: 'EmailsWorker',
388
+ handler: 'apps/api/.gkm/aws/queues/emails.handler',
389
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
390
+ },
391
+ },
392
+ } as never,
393
+ provisioned,
264
394
  );
395
+
396
+ expect(consumed).toEqual([
397
+ { handler: 'apps/api/.gkm/aws/queues/emails.handler', link: [uploads] },
398
+ ]);
399
+ });
400
+
401
+ it('subscribes through SST, with the queue itself linked', async () => {
402
+ const { Queue } = await import('../aws/Queue');
403
+ const queue = new Queue({} as never, 'Emails');
404
+
405
+ queue.consume({ handler: 'emails.handler', link: [], batchSize: 5 });
406
+
407
+ const [{ subscriber, args }] = (
408
+ queue as unknown as { subscribed: { subscriber: any; args: unknown }[] }
409
+ ).subscribed;
410
+ expect(subscriber.handler).toBe('emails.handler');
411
+ expect(subscriber.link).toEqual([queue]);
412
+ expect(args).toEqual({ batch: { size: 5 } });
413
+ });
414
+ });
415
+
416
+ describe('a surface’s endpoints', () => {
417
+ const routesOf = (surface: RestApiSurface) =>
418
+ (
419
+ surface as unknown as {
420
+ routes: { key: string; handler: any; args: unknown }[];
421
+ }
422
+ ).routes;
423
+
424
+ it('are mounted from the handlers the build wrote, each linked to what it depends on', () => {
425
+ // An API Gateway with no routes 404s everything — which is what a deploy
426
+ // produced while the routes sat in the manifest with nothing reading them.
427
+ const api = new RestApiSurface({} as never, 'Api');
428
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
429
+
430
+ mountRoutes(
431
+ {
432
+ Uploads: {
433
+ kind: 'objects',
434
+ id: 'Uploads',
435
+ provides: ['UPLOADS_CONNECTION_STRING'],
436
+ },
437
+ Api: {
438
+ kind: 'rest-api',
439
+ id: 'Api',
440
+ provides: ['API_URL'],
441
+ endpoints: [
442
+ {
443
+ id: 'ApiGET/users/{id}',
444
+ method: 'GET',
445
+ path: '/users/{id}',
446
+ handler: 'apps/api/.gkm/aws/routes/getUser.handler',
447
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
448
+ authorizer: 'none',
449
+ },
450
+ {
451
+ id: 'ApiGET/health',
452
+ method: 'GET',
453
+ path: '/health',
454
+ handler: 'apps/api/.gkm/aws/routes/health.handler',
455
+ dependencies: [],
456
+ },
457
+ ],
458
+ },
459
+ } as never,
460
+ { Uploads: uploads, Api: api } as unknown as ProvisionedManifest,
461
+ );
462
+
463
+ const [getUser, health] = routesOf(api);
464
+ expect(getUser?.key).toBe('GET /users/{id}');
465
+ expect(getUser?.handler.handler).toBe(
466
+ 'apps/api/.gkm/aws/routes/getUser.handler',
467
+ );
468
+ expect(getUser?.handler.link).toEqual([uploads]);
469
+ expect(getUser?.args).toEqual({});
470
+ // Least privilege: an endpoint is linked to its own edges, not the app's.
471
+ expect(health?.key).toBe('GET /health');
472
+ expect(health?.handler.link).toEqual([]);
473
+ });
474
+
475
+ it('leaves IAM to the gateway, and every other authorizer to the handler', () => {
476
+ const api = new RestApiSurface({} as never, 'Api');
477
+
478
+ api.mount({
479
+ method: 'POST',
480
+ path: '/x',
481
+ handler: 'x.handler',
482
+ authorizer: 'iam',
483
+ });
484
+ api.mount({
485
+ method: 'POST',
486
+ path: '/y',
487
+ handler: 'y.handler',
488
+ authorizer: 'session',
489
+ });
490
+
491
+ const [x, y] = routesOf(api);
492
+ expect(x?.args).toEqual({ auth: { iam: true } });
493
+ expect(y?.args).toEqual({});
494
+ });
495
+
496
+ it('runs a handler that reaches a database inside the database’s network', () => {
497
+ const vpc = { id: 'stub-vpc' } as never;
498
+ const cluster = new Database({} as never, 'Orders', { vpc });
499
+ const tenant = new DatabaseSchema('Billing', cluster, 'billing');
500
+
501
+ expect(vpcFor([cluster as never])).toBe(vpc);
502
+ // A schema tenant lives in its parent's cluster, so in its network too.
503
+ expect(vpcFor([{ _id: 'Uploads' } as never, tenant as never])).toBe(vpc);
504
+ expect(vpcFor([{ _id: 'Uploads' } as never])).toBeUndefined();
505
+ });
506
+ });
507
+
508
+ describe('functions and crons', () => {
509
+ const stack = new App({
510
+ name: 'shop',
511
+ stage: 'prod',
512
+ domain: 'example.com',
513
+ hostedZoneId: 'Z',
514
+ region: 'eu-west-1',
515
+ }).stack('jobs');
516
+ const argsOf = (component: unknown) =>
517
+ (component as { args: Record<string, any> }).args;
518
+
519
+ it('are deployed from the declarations, each linked to its own edges', () => {
520
+ // The `manifest.crons` / `manifest.functions` tables they were built from
521
+ // are gone: the declarations carry the handler, schedule and edges.
522
+ const vpc = { id: 'stub-vpc' } as never;
523
+ const orders = new Database({} as never, 'Orders', { vpc });
524
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
525
+ const provisioned = {
526
+ Orders: orders,
527
+ Uploads: uploads,
528
+ } as unknown as ProvisionedManifest;
529
+
530
+ const [digest] = provisionCompute(
531
+ stack,
532
+ {
533
+ Orders: { kind: 'database', id: 'Orders' },
534
+ Uploads: {
535
+ kind: 'objects',
536
+ id: 'Uploads',
537
+ provides: ['UPLOADS_CONNECTION_STRING'],
538
+ },
539
+ Invoice: {
540
+ kind: 'function',
541
+ id: 'Invoice',
542
+ handler: 'apps/api/.gkm/aws/functions/invoice.handler',
543
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
544
+ provides: ['INVOICE_URL'],
545
+ },
546
+ Digest: {
547
+ kind: 'cron',
548
+ id: 'Digest',
549
+ handler: 'apps/api/.gkm/aws/crons/digest.handler',
550
+ schedule: 'rate(1 day)',
551
+ dependencies: [{ target: 'Orders', kind: 'database' }],
552
+ },
553
+ } as never,
554
+ provisioned,
555
+ );
556
+
557
+ const invoice = provisioned.Invoice as unknown as Function;
558
+ expect(invoice).toBeInstanceOf(Function);
559
+ expect(argsOf(invoice)).toMatchObject({
560
+ name: stack.logicalPrefixedName('Invoice'),
561
+ handler: 'apps/api/.gkm/aws/functions/invoice.handler',
562
+ link: [uploads],
563
+ url: { authorization: 'iam' },
564
+ });
565
+ expect(argsOf(invoice).vpc).toBeUndefined();
566
+
567
+ // A cron is a schedule, not something to link to; its Lambda reaches
568
+ // the database, so it runs in the database's network.
569
+ expect(provisioned.Digest).toBeUndefined();
570
+ expect(digest).toBeInstanceOf(Cron);
571
+ expect(argsOf(digest).schedule).toBe('rate(1 day)');
572
+ expect(argsOf(digest!.processor)).toMatchObject({
573
+ handler: 'apps/api/.gkm/aws/crons/digest.handler',
574
+ link: [orders],
575
+ vpc,
576
+ });
577
+ });
578
+ });
579
+
580
+ describe("a file server's processors", () => {
581
+ const stack = new App({
582
+ name: 'shop',
583
+ stage: 'production',
584
+ domain: 'example.com',
585
+ hostedZoneId: 'Z',
586
+ region: 'eu-west-1',
587
+ }).stack('media');
588
+ const argsOf = (component: unknown) =>
589
+ (component as { args: Record<string, any> }).args;
590
+
591
+ it('are Lambdas behind IAM-auth URLs, served through the router on their prefix', () => {
592
+ const media = { _id: 'Media', _type: 'sst.aws.Bucket' };
593
+ const router = { _id: 'MediaServer' };
594
+ const provisioned = {
595
+ Media: media,
596
+ MediaServer: router,
597
+ } as unknown as ProvisionedManifest;
598
+
599
+ const [thumbnails, pages] = provisionProcessors(
600
+ stack,
601
+ {
602
+ Media: { kind: 'objects', id: 'Media', provides: ['MEDIA_URL'] },
603
+ MediaServer: {
604
+ kind: 'file-server',
605
+ id: 'MediaServer',
606
+ of: 'Media',
607
+ processors: [
608
+ {
609
+ id: 'thumbnails',
610
+ handler: 'apps/api/.gkm/aws/processors/thumbnails.handler',
611
+ path: '/i/:width/*',
612
+ prefix: '/i/',
613
+ native: ['sharp'],
614
+ timeout: 15_000,
615
+ memorySize: 1536,
616
+ dependencies: [{ target: 'Media', kind: 'objects' }],
617
+ },
618
+ {
619
+ id: 'pages',
620
+ handler: 'apps/api/.gkm/aws/processors/pages.handler',
621
+ path: '/pdf/:page/*',
622
+ prefix: '/pdf/',
623
+ dependencies: [{ target: 'Media', kind: 'objects' }],
624
+ },
625
+ ],
626
+ },
627
+ } as never,
628
+ provisioned,
629
+ );
630
+
631
+ expect(thumbnails).toBeInstanceOf(Function);
632
+ expect(argsOf(thumbnails)).toMatchObject({
633
+ name: stack.logicalPrefixedName('MediaServerthumbnails'),
634
+ handler: 'apps/api/.gkm/aws/processors/thumbnails.handler',
635
+ link: [media],
636
+ timeout: '15 seconds',
637
+ memory: '1536 MB',
638
+ // Installed for the Lambda, never bundled.
639
+ nodejs: { install: ['sharp'] },
640
+ url: {
641
+ authorization: 'iam',
642
+ router: { instance: router, path: '/i' },
643
+ },
644
+ });
645
+ expect(argsOf(pages)).toMatchObject({
646
+ url: { router: { path: '/pdf' } },
647
+ });
648
+ expect(argsOf(pages).nodejs).toBeUndefined();
649
+ });
650
+ });
651
+
652
+ describe('kinds provisioned elsewhere', () => {
653
+ it('skips a worker, which is a process rather than a resource', () => {
654
+ // A worker in the manifest used to throw UnknownDeclarationKind at synth,
655
+ // so any app with background work could not be deployed to AWS at all.
656
+ expect(PROVISIONED_ELSEWHERE.has('worker')).toBe(true);
657
+ expect(PROVISIONED_ELSEWHERE.has('mobile-app')).toBe(true);
658
+ expect(PROVISIONED_ELSEWHERE.has('queue')).toBe(false);
265
659
  });
266
660
  });
@@ -79,46 +79,6 @@ describe('Function', () => {
79
79
  invalidVars: ['SMTP_URL'],
80
80
  });
81
81
  });
82
-
83
- it('builds one function per manifest entry, named for the stack', () => {
84
- const functions = Function.fromManifest(
85
- stack,
86
- {
87
- billing: [
88
- {
89
- name: 'Invoice',
90
- handler: '.gkm/aws-lambda/functions/invoice.handler',
91
- environment: ['DB_URL'],
92
- timeout: 60,
93
- memorySize: 512,
94
- },
95
- ],
96
- ops: [
97
- {
98
- name: 'Ping',
99
- handler: '.gkm/aws-lambda/functions/ping.handler',
100
- environment: [],
101
- },
102
- ],
103
- } as never,
104
- { links: [db] },
105
- );
106
-
107
- expect(functions.map((f) => argsOf(f))).toEqual([
108
- expect.objectContaining({
109
- name: stack.logicalPrefixedName('Invoice'),
110
- timeout: '60 seconds',
111
- memory: '512 MB',
112
- link: [db],
113
- }),
114
- expect.objectContaining({
115
- name: stack.logicalPrefixedName('Ping'),
116
- timeout: undefined,
117
- memory: undefined,
118
- link: [],
119
- }),
120
- ]);
121
- });
122
82
  });
123
83
 
124
84
  describe('Cron', () => {
@@ -136,37 +96,6 @@ describe('Cron', () => {
136
96
  function: processor.arn,
137
97
  });
138
98
  });
139
-
140
- it('builds a validated function and a schedule per manifest cron', () => {
141
- const crons = Cron.fromManifest(
142
- stack,
143
- [
144
- {
145
- name: 'Digest',
146
- handler: '.gkm/aws-lambda/crons/digest.handler',
147
- schedule: 'cron(0 8 * * ? *)',
148
- environment: ['DB_URL'],
149
- timeout: 120,
150
- memorySize: 1024,
151
- },
152
- {
153
- name: 'Sweep',
154
- handler: '.gkm/aws-lambda/crons/sweep.handler',
155
- schedule: 'rate(1 hour)',
156
- environment: [],
157
- },
158
- ] as never,
159
- { links: [db], enabled: true },
160
- );
161
-
162
- const [digest, sweep] = crons.map((c) => argsOf(c));
163
- expect(digest).toMatchObject({
164
- schedule: 'cron(0 8 * * ? *)',
165
- enabled: true,
166
- function: expect.stringContaining('DigestFunction'),
167
- });
168
- expect(sweep).toMatchObject({ schedule: 'rate(1 hour)' });
169
- });
170
99
  });
171
100
 
172
101
  describe('App and Stack', () => {
@@ -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
+ });