@geekmidas/cloud 10.0.0-alpha.13 → 10.0.0-alpha.130

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.
@@ -1,13 +1,25 @@
1
1
  import { resolveEnvKeys } from '@geekmidas/envkit/sst';
2
- import { providedKeyFor, provideKey } from '@geekmidas/manifest';
2
+ import { NoUrlForStage, providedKeyFor, provideKey } 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
  /**
@@ -249,18 +261,380 @@ describe('the key a provided role becomes', () => {
249
261
  describe('Credential', () => {
250
262
  it('provides under the role the declaration named', async () => {
251
263
  // The role *is* the contract: providing `value` against a declared
252
- // `STRIPE_CREDENTIAL` supplies `STRIPE_VALUE`, and assertProvides
264
+ // `STRIPE_CREDENTIALS` supplies `STRIPE_VALUE`, and assertProvides
253
265
  // rejects the stack at synth. Which is the check working.
254
266
  const { Credential } = await import('../aws/Credential');
255
267
 
256
268
  expect(
257
269
  Object.keys(new Credential({} as never, 'Stripe').provides()),
258
- ).toEqual(['credential']);
270
+ ).toEqual(['credentials']);
259
271
  });
260
272
 
261
273
  it('agrees with what the construct declares', () => {
262
- expect(providedKeyFor('Stripe', 'credential', 'credential')).toBe(
263
- 'STRIPE_CREDENTIAL',
274
+ expect(providedKeyFor('Stripe', 'credential', 'credentials')).toBe(
275
+ 'STRIPE_CREDENTIALS',
264
276
  );
265
277
  });
278
+
279
+ it('links under the key the construct reads, not the secret’s bare name', async () => {
280
+ const { Credential } = await import('../aws/Credential');
281
+ const stripe = new Credential({} as never, 'Stripe');
282
+
283
+ expect(resolveEnvKeys({ Stripe: { type: stripe._type } })).toEqual([
284
+ 'STRIPE_CREDENTIALS',
285
+ ]);
286
+ expect(stripe.getSSTLink().properties).toEqual(stripe.provides());
287
+ });
288
+
289
+ it('is what a function depending on it is linked to', async () => {
290
+ const { Credential } = await import('../aws/Credential');
291
+ const stripe = new Credential({} as never, 'Stripe');
292
+
293
+ const { link, envKeys } = resolveEdges(
294
+ [{ target: 'Stripe', kind: 'credential' }],
295
+ { Stripe: stripe },
296
+ );
297
+
298
+ expect(link).toEqual([stripe]);
299
+ expect(envKeys).toEqual(['STRIPE_CREDENTIALS']);
300
+ });
301
+ });
302
+
303
+ describe('ExternalApi', () => {
304
+ const stack = (stage: string) => ({ stage }) as never;
305
+
306
+ it('provides the URL for its stage and its credentials, under the declared keys', async () => {
307
+ const { ExternalApi } = await import('../aws/ExternalApi');
308
+ const payfast = new ExternalApi(stack('production'), 'PayFast', {
309
+ url: {
310
+ production: 'https://www.payfast.co.za',
311
+ default: 'https://sandbox.payfast.co.za',
312
+ },
313
+ });
314
+
315
+ expect(payfast.provides().url).toBe('https://www.payfast.co.za');
316
+ expect(
317
+ Object.keys(payfast.provides()).map((role) =>
318
+ providedKeyFor('PayFast', 'external-api', role),
319
+ ),
320
+ ).toEqual(['PAY_FAST_URL', 'PAY_FAST_CREDENTIALS']);
321
+ });
322
+
323
+ it('falls back to the default URL for a stage it does not name', async () => {
324
+ const { ExternalApi } = await import('../aws/ExternalApi');
325
+ const payfast = new ExternalApi(stack('staging'), 'PayFast', {
326
+ url: {
327
+ production: 'https://www.payfast.co.za',
328
+ default: 'https://sandbox.payfast.co.za',
329
+ },
330
+ });
331
+
332
+ expect(payfast.provides().url).toBe('https://sandbox.payfast.co.za');
333
+ });
334
+
335
+ it('fails synth for a stage it has no URL for', async () => {
336
+ const { ExternalApi } = await import('../aws/ExternalApi');
337
+
338
+ expect(
339
+ () =>
340
+ new ExternalApi(stack('staging'), 'PayFast', {
341
+ url: { production: 'https://www.payfast.co.za' },
342
+ }),
343
+ ).toThrow(NoUrlForStage);
344
+ });
345
+
346
+ it('flattens into the same keys at runtime', () => {
347
+ expect(
348
+ resolveEnvKeys({ PayFast: { type: 'gkm:aws:ExternalApi' } }).sort(),
349
+ ).toEqual(['PAY_FAST_CREDENTIALS', 'PAY_FAST_URL']);
350
+ });
351
+ });
352
+
353
+ describe('a queue’s one consumer', () => {
354
+ it('is subscribed from the handler the build wrote, linked to what it depends on', () => {
355
+ const consumed: { handler: string; link?: unknown[] }[] = [];
356
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
357
+ const provisioned = {
358
+ Uploads: uploads,
359
+ Emails: {
360
+ _id: 'Emails',
361
+ _type: 'sst.aws.Queue',
362
+ consume: (consumer: { handler: string; link?: unknown[] }) =>
363
+ consumed.push(consumer),
364
+ },
365
+ } as unknown as ProvisionedManifest;
366
+
367
+ subscribeConsumers(
368
+ {
369
+ Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
370
+ Emails: {
371
+ kind: 'queue',
372
+ id: 'Emails',
373
+ provides: ['EMAILS_PUBLISHER_CONNECTION_STRING'],
374
+ worker: {
375
+ id: 'EmailsWorker',
376
+ handler: 'apps/api/.gkm/aws/queues/emails.handler',
377
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
378
+ },
379
+ },
380
+ } as never,
381
+ provisioned,
382
+ );
383
+
384
+ expect(consumed).toEqual([
385
+ { handler: 'apps/api/.gkm/aws/queues/emails.handler', link: [uploads] },
386
+ ]);
387
+ });
388
+
389
+ it('subscribes through SST, with the queue itself linked', async () => {
390
+ const { Queue } = await import('../aws/Queue');
391
+ const queue = new Queue({} as never, 'Emails');
392
+
393
+ queue.consume({ handler: 'emails.handler', link: [], batchSize: 5 });
394
+
395
+ const [{ subscriber, args }] = (
396
+ queue as unknown as { subscribed: { subscriber: any; args: unknown }[] }
397
+ ).subscribed;
398
+ expect(subscriber.handler).toBe('emails.handler');
399
+ expect(subscriber.link).toEqual([queue]);
400
+ expect(args).toEqual({ batch: { size: 5 } });
401
+ });
402
+ });
403
+
404
+ describe('a surface’s endpoints', () => {
405
+ const routesOf = (surface: RestApiSurface) =>
406
+ (
407
+ surface as unknown as {
408
+ routes: { key: string; handler: any; args: unknown }[];
409
+ }
410
+ ).routes;
411
+
412
+ it('are mounted from the handlers the build wrote, each linked to what it depends on', () => {
413
+ // An API Gateway with no routes 404s everything — which is what a deploy
414
+ // produced while the routes sat in the manifest with nothing reading them.
415
+ const api = new RestApiSurface({} as never, 'Api');
416
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
417
+
418
+ mountRoutes(
419
+ {
420
+ Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
421
+ Api: {
422
+ kind: 'rest-api',
423
+ id: 'Api',
424
+ provides: ['API_URL'],
425
+ endpoints: [
426
+ {
427
+ id: 'ApiGET/users/{id}',
428
+ method: 'GET',
429
+ path: '/users/{id}',
430
+ handler: 'apps/api/.gkm/aws/routes/getUser.handler',
431
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
432
+ authorizer: 'none',
433
+ },
434
+ {
435
+ id: 'ApiGET/health',
436
+ method: 'GET',
437
+ path: '/health',
438
+ handler: 'apps/api/.gkm/aws/routes/health.handler',
439
+ dependencies: [],
440
+ },
441
+ ],
442
+ },
443
+ } as never,
444
+ { Uploads: uploads, Api: api } as unknown as ProvisionedManifest,
445
+ );
446
+
447
+ const [getUser, health] = routesOf(api);
448
+ expect(getUser?.key).toBe('GET /users/{id}');
449
+ expect(getUser?.handler.handler).toBe(
450
+ 'apps/api/.gkm/aws/routes/getUser.handler',
451
+ );
452
+ expect(getUser?.handler.link).toEqual([uploads]);
453
+ expect(getUser?.args).toEqual({});
454
+ // Least privilege: an endpoint is linked to its own edges, not the app's.
455
+ expect(health?.key).toBe('GET /health');
456
+ expect(health?.handler.link).toEqual([]);
457
+ });
458
+
459
+ it('leaves IAM to the gateway, and every other authorizer to the handler', () => {
460
+ const api = new RestApiSurface({} as never, 'Api');
461
+
462
+ api.mount({
463
+ method: 'POST',
464
+ path: '/x',
465
+ handler: 'x.handler',
466
+ authorizer: 'iam',
467
+ });
468
+ api.mount({
469
+ method: 'POST',
470
+ path: '/y',
471
+ handler: 'y.handler',
472
+ authorizer: 'session',
473
+ });
474
+
475
+ const [x, y] = routesOf(api);
476
+ expect(x?.args).toEqual({ auth: { iam: true } });
477
+ expect(y?.args).toEqual({});
478
+ });
479
+
480
+ it('runs a handler that reaches a database inside the database’s network', () => {
481
+ const vpc = { id: 'stub-vpc' } as never;
482
+ const cluster = new Database({} as never, 'Orders', { vpc });
483
+ const tenant = new DatabaseSchema('Billing', cluster, 'billing');
484
+
485
+ expect(vpcFor([cluster as never])).toBe(vpc);
486
+ // A schema tenant lives in its parent's cluster, so in its network too.
487
+ expect(vpcFor([{ _id: 'Uploads' } as never, tenant as never])).toBe(vpc);
488
+ expect(vpcFor([{ _id: 'Uploads' } as never])).toBeUndefined();
489
+ });
490
+ });
491
+
492
+ describe('functions and crons', () => {
493
+ const stack = new App({
494
+ name: 'shop',
495
+ stage: 'prod',
496
+ domain: 'example.com',
497
+ hostedZoneId: 'Z',
498
+ region: 'eu-west-1',
499
+ }).stack('jobs');
500
+ const argsOf = (component: unknown) =>
501
+ (component as { args: Record<string, any> }).args;
502
+
503
+ it('are deployed from the declarations, each linked to its own edges', () => {
504
+ // The `manifest.crons` / `manifest.functions` tables they were built from
505
+ // are gone: the declarations carry the handler, schedule and edges.
506
+ const vpc = { id: 'stub-vpc' } as never;
507
+ const orders = new Database({} as never, 'Orders', { vpc });
508
+ const uploads = { _id: 'Uploads', _type: 'sst.aws.Bucket' };
509
+ const provisioned = {
510
+ Orders: orders,
511
+ Uploads: uploads,
512
+ } as unknown as ProvisionedManifest;
513
+
514
+ const [digest] = provisionCompute(
515
+ stack,
516
+ {
517
+ Orders: { kind: 'database', id: 'Orders' },
518
+ Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
519
+ Invoice: {
520
+ kind: 'function',
521
+ id: 'Invoice',
522
+ handler: 'apps/api/.gkm/aws/functions/invoice.handler',
523
+ dependencies: [{ target: 'Uploads', kind: 'objects' }],
524
+ provides: ['INVOICE_URL'],
525
+ },
526
+ Digest: {
527
+ kind: 'cron',
528
+ id: 'Digest',
529
+ handler: 'apps/api/.gkm/aws/crons/digest.handler',
530
+ schedule: 'rate(1 day)',
531
+ dependencies: [{ target: 'Orders', kind: 'database' }],
532
+ },
533
+ } as never,
534
+ provisioned,
535
+ );
536
+
537
+ const invoice = provisioned.Invoice as unknown as Function;
538
+ expect(invoice).toBeInstanceOf(Function);
539
+ expect(argsOf(invoice)).toMatchObject({
540
+ name: stack.logicalPrefixedName('Invoice'),
541
+ handler: 'apps/api/.gkm/aws/functions/invoice.handler',
542
+ link: [uploads],
543
+ url: { authorization: 'iam' },
544
+ });
545
+ expect(argsOf(invoice).vpc).toBeUndefined();
546
+
547
+ // A cron is a schedule, not something to link to; its Lambda reaches
548
+ // the database, so it runs in the database's network.
549
+ expect(provisioned.Digest).toBeUndefined();
550
+ expect(digest).toBeInstanceOf(Cron);
551
+ expect(argsOf(digest).schedule).toBe('rate(1 day)');
552
+ expect(argsOf(digest!.processor)).toMatchObject({
553
+ handler: 'apps/api/.gkm/aws/crons/digest.handler',
554
+ link: [orders],
555
+ vpc,
556
+ });
557
+ });
558
+ });
559
+
560
+ describe("a file server's processors", () => {
561
+ const stack = new App({
562
+ name: 'shop',
563
+ stage: 'production',
564
+ domain: 'example.com',
565
+ hostedZoneId: 'Z',
566
+ region: 'eu-west-1',
567
+ }).stack('media');
568
+ const argsOf = (component: unknown) =>
569
+ (component as { args: Record<string, any> }).args;
570
+
571
+ it('are Lambdas behind IAM-auth URLs, served through the router on their prefix', () => {
572
+ const media = { _id: 'Media', _type: 'sst.aws.Bucket' };
573
+ const router = { _id: 'MediaServer' };
574
+ const provisioned = {
575
+ Media: media,
576
+ MediaServer: router,
577
+ } as unknown as ProvisionedManifest;
578
+
579
+ const [thumbnails, pages] = provisionProcessors(
580
+ stack,
581
+ {
582
+ Media: { kind: 'objects', id: 'Media', provides: ['MEDIA_URL'] },
583
+ MediaServer: {
584
+ kind: 'file-server',
585
+ id: 'MediaServer',
586
+ of: 'Media',
587
+ processors: [
588
+ {
589
+ id: 'thumbnails',
590
+ handler: 'apps/api/.gkm/aws/processors/thumbnails.handler',
591
+ path: '/i/:width/*',
592
+ prefix: '/i/',
593
+ native: ['sharp'],
594
+ timeout: 15_000,
595
+ memorySize: 1536,
596
+ dependencies: [{ target: 'Media', kind: 'objects' }],
597
+ },
598
+ {
599
+ id: 'pages',
600
+ handler: 'apps/api/.gkm/aws/processors/pages.handler',
601
+ path: '/pdf/:page/*',
602
+ prefix: '/pdf/',
603
+ dependencies: [{ target: 'Media', kind: 'objects' }],
604
+ },
605
+ ],
606
+ },
607
+ } as never,
608
+ provisioned,
609
+ );
610
+
611
+ expect(thumbnails).toBeInstanceOf(Function);
612
+ expect(argsOf(thumbnails)).toMatchObject({
613
+ name: stack.logicalPrefixedName('MediaServerthumbnails'),
614
+ handler: 'apps/api/.gkm/aws/processors/thumbnails.handler',
615
+ link: [media],
616
+ timeout: '15 seconds',
617
+ memory: '1536 MB',
618
+ // Installed for the Lambda, never bundled.
619
+ nodejs: { install: ['sharp'] },
620
+ url: {
621
+ authorization: 'iam',
622
+ router: { instance: router, path: '/i' },
623
+ },
624
+ });
625
+ expect(argsOf(pages)).toMatchObject({
626
+ url: { router: { path: '/pdf' } },
627
+ });
628
+ expect(argsOf(pages).nodejs).toBeUndefined();
629
+ });
630
+ });
631
+
632
+ describe('kinds provisioned elsewhere', () => {
633
+ it('skips a worker, which is a process rather than a resource', () => {
634
+ // A worker in the manifest used to throw UnknownDeclarationKind at synth,
635
+ // so any app with background work could not be deployed to AWS at all.
636
+ expect(PROVISIONED_ELSEWHERE.has('worker')).toBe(true);
637
+ expect(PROVISIONED_ELSEWHERE.has('mobile-app')).toBe(true);
638
+ expect(PROVISIONED_ELSEWHERE.has('queue')).toBe(false);
639
+ });
266
640
  });
@@ -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', () => {
@@ -28,6 +28,11 @@ const manifest = {
28
28
  provides: ['API_URL', 'API_TRUSTED_ORIGINS', 'API_COOKIE_DOMAIN'],
29
29
  },
30
30
  Orders: { kind: 'database', id: 'Orders', provides: ['ORDERS_URL'] },
31
+ Mailer: {
32
+ kind: 'email',
33
+ id: 'Mailer',
34
+ provides: ['MAILER_URL', 'MAILER_FROM'],
35
+ },
31
36
  Console: {
32
37
  kind: 'site',
33
38
  id: 'Console',
@@ -37,6 +42,7 @@ const manifest = {
37
42
  { target: 'Api', kind: 'rest-api' },
38
43
  { target: 'Orders', kind: 'database' },
39
44
  { target: 'UploadsServer', kind: 'file-server' },
45
+ { target: 'Mailer', kind: 'email' },
40
46
  ],
41
47
  provides: ['CONSOLE_URL'],
42
48
  },
@@ -101,6 +107,10 @@ describe('siteEnvironment', () => {
101
107
  Api: provided({ url: 'https://api.example.com' }),
102
108
  Orders: provided({ url: 'postgres://user:pw@db/orders' }),
103
109
  UploadsServer: provided({ url: 'https://files.example.com' }),
110
+ Mailer: provided({
111
+ url: 'smtp://user:pw@email-smtp.example.com:587',
112
+ from: 'hello@shop.test',
113
+ }),
104
114
  }),
105
115
  );
106
116
 
@@ -122,6 +132,13 @@ describe('siteEnvironment', () => {
122
132
  expect(built()).not.toHaveProperty('VITE_ORDERS_URL');
123
133
  });
124
134
 
135
+ it('has no inbox to share for deployed mail, and never shares the mail URL', () => {
136
+ // The inbox is Mailpit's, and exists only locally: deployed, an app that
137
+ // reads it falls back to the phone's own mail app.
138
+ expect(built()).not.toHaveProperty('VITE_MAILER_INBOX_URL');
139
+ expect(built()).not.toHaveProperty('VITE_MAILER_URL');
140
+ });
141
+
125
142
  it('fails loudly on an edge nothing provisioned', () => {
126
143
  // A smaller environment builds and then fails at runtime against
127
144
  // `http:///`, with nothing to point at.
@@ -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' } });