@geekmidas/cloud 10.0.0-alpha.98 → 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,209 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { Cache, CacheNeedsProvider, CacheNeedsVpc } from '../aws/Cache';
3
- import { Database } from '../aws/Database';
4
- import { DatabaseReader, DatabaseSchema } from '../aws/DerivedDatabase';
5
- import { Email } from '../aws/Email';
6
- import { FileServer } from '../aws/FileServer';
7
- import { Queue } from '../aws/Queue';
8
- import { RestApiSurface } from '../aws/RestApiSurface';
9
- import { Secret } from '../aws/Secret';
10
- import { StaticSite } from '../aws/StaticSite';
11
- import { Storage } from '../aws/Storage';
12
- import { Topic } from '../aws/Topic';
13
- import { ResourceType } from '../Linkable';
14
-
15
- /**
16
- * What a linked function receives from each component, and the type that
17
- * decides which variables a link provides. `getSSTLink()` is the payload SST
18
- * injects into every handler linked to the resource; `_type` is what
19
- * `LinkedEnvironment` keys the variable names off.
20
- */
21
-
22
- const stack = {} as never;
23
- const vpc = { subnets: ['subnet-1'], securityGroups: ['sg-1'] } as never;
24
-
25
- /** Resolves `$util.output(promise)`, which the stub leaves as the promise. */
26
- const settle = async (value: unknown) =>
27
- (value as { apply: (fn: (v: unknown) => unknown) => unknown }).apply(
28
- (v) => v,
29
- );
30
-
31
- describe('link payloads', () => {
32
- it('a queue adds its ARN and connection string to SST’s own link', () => {
33
- const queue = new Queue(stack, 'Emails');
34
-
35
- expect(queue._type).toBe(ResourceType.Queue);
36
- // The connection string itself is parsed back in provides.spec; here, the
37
- // link carries exactly what `provides()` resolved.
38
- expect(queue.getSSTLink().properties).toEqual({
39
- name: 'Emails',
40
- arn: queue.arn,
41
- ...queue.provides(),
42
- });
43
- });
44
-
45
- it('a topic carries its publisher connection string', () => {
46
- const topic = new Topic(stack, 'Users');
47
-
48
- expect(topic._type).toBe(ResourceType.SnsTopic);
49
- expect(topic.getSSTLink().properties).toEqual({
50
- name: 'Users',
51
- ...topic.provides(),
52
- });
53
- });
54
-
55
- it('a secret carries its value', () => {
56
- const secret = new Secret(stack, 'AuthSecret');
57
-
58
- expect(secret._type).toBe(ResourceType.SSTSecret);
59
- expect(secret.getSSTLink().properties).toMatchObject(secret.provides());
60
- });
61
-
62
- it('a mailer carries its URL and sending identity, and nothing else', () => {
63
- const email = new Email(stack, 'Mail', {
64
- backend: 'smtp',
65
- url: 'smtp://relay.test:587',
66
- from: 'hello@shop.test',
67
- } as never);
68
-
69
- expect(email._type).toBe(ResourceType.Email);
70
- expect(email.getSSTLink()).toEqual({
71
- properties: { url: 'smtp://relay.test:587', from: 'hello@shop.test' },
72
- });
73
- });
74
-
75
- it('a file server routes everything to its bucket, and links its URL', () => {
76
- const origin = new Storage(stack, 'Uploads');
77
- const server = new FileServer(stack, 'Files', { origin } as never);
78
-
79
- expect(origin._type).toBe(ResourceType.ObjectStorage);
80
- expect(origin._id).toBe('Uploads');
81
- expect(server._type).toBe(ResourceType.FileServer);
82
- expect((server as unknown as { routed: unknown[] }).routed).toEqual([
83
- { pattern: '/*', bucket: origin },
84
- ]);
85
- expect(server.getSSTLink().properties).toMatchObject({
86
- url: server.url,
87
- });
88
- });
89
-
90
- it('a site is built the way its variant builds, and links its URL', () => {
91
- const vite = new StaticSite(stack, 'Web');
92
- const next = new StaticSite(stack, 'Admin', {
93
- variant: 'next',
94
- build: { command: 'pnpm build:custom', output: 'out' },
95
- } as never);
96
- const args = (site: unknown) => (site as { args: { build: unknown } }).args;
97
-
98
- expect(vite._type).toBe(ResourceType.StaticSite);
99
- expect(args(vite).build).toEqual(expect.objectContaining({}));
100
- // A build the caller supplied wins over the variant's.
101
- expect(args(next).build).toEqual({
102
- command: 'pnpm build:custom',
103
- output: 'out',
104
- });
105
- expect(vite.getSSTLink().properties).toMatchObject({ url: vite.url });
106
- });
107
-
108
- it('a surface links its address and, once resolved, who may call it', async () => {
109
- const bare = new RestApiSurface(stack, 'Api');
110
- const called = new RestApiSurface(stack, 'Api', {
111
- callers: Promise.resolve({
112
- trustedOrigins: 'https://web.shop.test',
113
- cookieDomain: 'shop.test',
114
- }),
115
- });
116
-
117
- expect(bare._type).toBe(ResourceType.ApiGatewayV2);
118
- expect(await settle(bare.provides().trustedOrigins)).toBe('');
119
- expect(await settle(bare.provides().cookieDomain)).toBe('');
120
-
121
- const link = called.getSSTLink().properties as Record<string, unknown>;
122
- expect(link.url).toBe(called.url);
123
- expect(await settle(link.trustedOrigins)).toBe('https://web.shop.test');
124
- expect(await settle(link.cookieDomain)).toBe('shop.test');
125
- });
126
-
127
- it('a database and the nodes derived from it each link only their own URL', () => {
128
- const cluster = new Database(stack, 'Orders', { vpc, schema: 'app' });
129
- const reader = new DatabaseReader('OrdersReader', cluster);
130
- const tenant = new DatabaseSchema('AuthDb', cluster, 'authdb');
131
-
132
- expect(cluster._type).toBe(ResourceType.SSTPostgres);
133
- expect(reader._type).toBe(ResourceType.SSTPostgres);
134
- expect(tenant._type).toBe(ResourceType.SSTPostgres);
135
- expect(cluster.getSSTLink().properties).toMatchObject({
136
- url: cluster.provides().url,
137
- });
138
- // Least privilege: the reader's link is its URL and not the writer's.
139
- expect(reader.getSSTLink()).toEqual({
140
- properties: { url: reader.provides().url },
141
- });
142
- expect(tenant.getSSTLink()).toEqual({
143
- properties: { url: tenant.provides().url },
144
- });
145
- });
146
-
147
- it('a cache given its URL links it as-is', () => {
148
- const cache = new Cache(stack, 'Sessions', {
149
- backend: 'db',
150
- url: 'postgres://db.test/app',
151
- });
152
-
153
- expect(cache._type).toBe(ResourceType.Cache);
154
- expect(cache.getSSTLink()).toEqual({
155
- properties: { url: 'postgres://db.test/app' },
156
- });
157
- });
158
- });
159
-
160
- describe('Cache on Upstash', () => {
161
- /** `sst add upstash` installs this global; here, a recording stand-in. */
162
- const created: { name: string; args: Record<string, unknown> }[] = [];
163
- class RedisDatabase {
164
- readonly endpoint = 'eu1-cache.upstash.io';
165
- readonly restToken = 'tok/en+1';
166
- constructor(name: string, args: Record<string, unknown>) {
167
- created.push({ name, args });
168
- }
169
- }
170
-
171
- it('creates a TLS database and puts its token in the URL', () => {
172
- (globalThis as Record<string, unknown>).upstash = { RedisDatabase };
173
- try {
174
- const defaulted = new Cache(stack, 'Sessions', { backend: 'upstash' });
175
- new Cache(stack, 'Rates', { backend: 'upstash', region: 'us-east-1' });
176
-
177
- expect(created).toEqual([
178
- {
179
- name: 'SessionsCache',
180
- args: { databaseName: 'Sessions', region: 'eu-west-1', tls: true },
181
- },
182
- {
183
- name: 'RatesCache',
184
- args: { databaseName: 'Rates', region: 'us-east-1', tls: true },
185
- },
186
- ]);
187
- // The address and the credential that opens it are one fact.
188
- expect(defaulted.provides().url).toBe(
189
- `https://:${encodeURIComponent('tok/en+1')}@eu1-cache.upstash.io`,
190
- );
191
- } finally {
192
- delete (globalThis as Record<string, unknown>).upstash;
193
- }
194
- });
195
- });
196
-
197
- describe('Cache provisioning refusals', () => {
198
- it('asks for the Upstash provider when it is not installed', () => {
199
- expect(() => new Cache(stack, 'Sessions', { backend: 'upstash' })).toThrow(
200
- CacheNeedsProvider,
201
- );
202
- });
203
-
204
- it('asks for a VPC before creating an ElastiCache', () => {
205
- expect(
206
- () => new Cache(stack, 'Sessions', { backend: 'elasticache' }),
207
- ).toThrow(CacheNeedsVpc);
208
- });
209
- });
@@ -1,107 +0,0 @@
1
- import { snsUrl } from '@geekmidas/events/sns';
2
- import { sqsUrl } from '@geekmidas/events/sqs';
3
- import { describe, expect, it } from 'vitest';
4
- import { fifoName, Queue } from '../aws/Queue';
5
- import { Secret } from '../aws/Secret';
6
- import { Topic } from '../aws/Topic';
7
- import { regionOfArn } from '../naming';
8
-
9
- /**
10
- * What each component resolves onto its consumers.
11
- *
12
- * Asserted by parsing the string back with the client's own codec, not by
13
- * matching text: the contract is that the publisher can read what the deploy
14
- * target wrote, and a string comparison would pass on a value nothing can
15
- * consume.
16
- */
17
-
18
- const stack = {} as never;
19
-
20
- describe('Queue', () => {
21
- it('provides a connection string its publisher can parse', () => {
22
- const provided = new Queue(stack, 'Emails').provides();
23
-
24
- expect(
25
- sqsUrl.parse(provided.publisherConnectionString as string),
26
- ).toMatchObject({
27
- queueUrl: expect.stringContaining('/Emails'),
28
- region: 'stub-region',
29
- });
30
- });
31
-
32
- it('provides one key, the producer’s', () => {
33
- // A worker is reached *through* the queue, so there is no second address
34
- // and nothing can depend on the handler.
35
- expect(Object.keys(new Queue(stack, 'Emails').provides())).toEqual([
36
- 'publisherConnectionString',
37
- ]);
38
- });
39
- });
40
-
41
- describe('Topic', () => {
42
- it('provides a connection string its publisher can parse', () => {
43
- const provided = new Topic(stack, 'Users').provides();
44
-
45
- expect(
46
- snsUrl.parse(provided.publisherConnectionString as string),
47
- ).toMatchObject({
48
- topicArn: expect.stringContaining(':Users'),
49
- region: 'stub-region',
50
- });
51
- });
52
-
53
- it('names no queue, so a subscriber cannot be reached by holding it', () => {
54
- const provided = new Topic(stack, 'Users').provides();
55
-
56
- expect(
57
- snsUrl.parse(provided.publisherConnectionString as string).queueName,
58
- ).toBeUndefined();
59
- });
60
- });
61
-
62
- describe('Secret', () => {
63
- it('provides a value, because it has no address to hand out instead', () => {
64
- expect(new Secret(stack, 'AuthSecret').provides()).toEqual({
65
- value: 'stub-secret-AuthSecret',
66
- });
67
- });
68
- });
69
-
70
- describe('regionOfArn', () => {
71
- it('reads the region out of an ARN', () => {
72
- // Carried explicitly because AWS_REGION inside a Lambda is the
73
- // *function's* region: a queue elsewhere works until it doesn't.
74
- expect(regionOfArn('arn:aws:sqs:eu-west-1:123:emails')).toBe('eu-west-1');
75
- });
76
-
77
- it('is undefined where an ARN carries no region', () => {
78
- expect(regionOfArn('arn:aws:iam::123:role/x')).toBeUndefined();
79
- expect(regionOfArn('not-an-arn')).toBeUndefined();
80
- });
81
- });
82
-
83
- describe('fifoName', () => {
84
- it('appends .fifo to a FIFO queue’s name', () => {
85
- // AWS rejects the mistake at the API call rather than at plan time, so
86
- // the component fixes it where the fact lives.
87
- expect(fifoName('emails', true)).toBe('emails.fifo');
88
- });
89
-
90
- it('does not append it twice', () => {
91
- // `.fifo` counts toward the 80-character limit.
92
- expect(fifoName('emails.fifo', true)).toBe('emails.fifo');
93
- });
94
-
95
- it('treats the object form as FIFO', () => {
96
- expect(fifoName('emails', { contentBasedDeduplication: true })).toBe(
97
- 'emails.fifo',
98
- );
99
- });
100
-
101
- it('strips it from a standard queue’s name', () => {
102
- // The rule runs both ways: a standard queue whose name ends in `.fifo`
103
- // is rejected just as loudly.
104
- expect(fifoName('emails.fifo', false)).toBe('emails');
105
- expect(fifoName('emails.fifo', undefined)).toBe('emails');
106
- });
107
- });
@@ -1,93 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- NoSmtpEndpoint,
4
- SMTP_REGIONS,
5
- sesSmtpUrl,
6
- smtpEndpoint,
7
- smtpPassword,
8
- } from '../aws/ses';
9
-
10
- /**
11
- * AWS documents the recipe and publishes no worked example, so there is no
12
- * golden value to assert against. These check the properties the recipe implies
13
- * instead — which is weaker, and worth being explicit about rather than
14
- * inventing an expected string.
15
- */
16
-
17
- const KEY = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY';
18
-
19
- describe('smtpPassword', () => {
20
- it('carries the version byte SES looks for', () => {
21
- // Without it the password is the right bytes and still rejected.
22
- const decoded = Buffer.from(smtpPassword(KEY, 'us-east-1'), 'base64');
23
-
24
- expect(decoded[0]).toBe(0x04);
25
- });
26
-
27
- it('is a version byte and one SHA-256 digest, and nothing else', () => {
28
- expect(Buffer.from(smtpPassword(KEY, 'us-east-1'), 'base64')).toHaveLength(
29
- 33,
30
- );
31
- });
32
-
33
- it('is deterministic, because it is a signature and not a secret', () => {
34
- // A password that changed per call would rotate itself out from under
35
- // every deploy.
36
- expect(smtpPassword(KEY, 'us-east-1')).toBe(smtpPassword(KEY, 'us-east-1'));
37
- });
38
-
39
- it('differs per region, which is why credentials are not portable', () => {
40
- expect(smtpPassword(KEY, 'us-east-1')).not.toBe(
41
- smtpPassword(KEY, 'eu-west-1'),
42
- );
43
- });
44
-
45
- it('differs per key', () => {
46
- expect(smtpPassword(KEY, 'us-east-1')).not.toBe(
47
- smtpPassword(`${KEY}x`, 'us-east-1'),
48
- );
49
- });
50
-
51
- it('refuses a region with no SMTP endpoint', () => {
52
- // The set is smaller than the set of regions SES runs in, so this is a
53
- // real mistake to make — and it would surface at the first send.
54
- expect(() => smtpPassword(KEY, 'af-south-1')).toThrow(NoSmtpEndpoint);
55
- expect(SMTP_REGIONS).not.toContain('af-south-1');
56
- });
57
- });
58
-
59
- describe('sesSmtpUrl', () => {
60
- it('is an smtp:// URL like every other backend’s', () => {
61
- // The whole reason the declaration promises `smtp://` and names no
62
- // provider: what changes is a host and a credential, not the client.
63
- const url = sesSmtpUrl({
64
- accessKeyId: 'AKIAEXAMPLE',
65
- secretAccessKey: KEY,
66
- region: 'eu-west-1',
67
- });
68
-
69
- expect(url.startsWith('smtp://AKIAEXAMPLE:')).toBe(true);
70
- expect(url.endsWith('@email-smtp.eu-west-1.amazonaws.com:587')).toBe(true);
71
- });
72
-
73
- it('encodes the password, which is base64 and may contain + and /', () => {
74
- // Both mean something else in a URL's authority section.
75
- const url = sesSmtpUrl({
76
- accessKeyId: 'AKIAEXAMPLE',
77
- secretAccessKey: KEY,
78
- region: 'eu-west-1',
79
- });
80
-
81
- // Round-tripped through the URL parser, which is the consumer that has
82
- // to get the password back out intact.
83
- expect(decodeURIComponent(new URL(url).password)).toBe(
84
- smtpPassword(KEY, 'eu-west-1'),
85
- );
86
- });
87
-
88
- it('derives the endpoint rather than taking one', () => {
89
- expect(smtpEndpoint('ap-southeast-2')).toBe(
90
- 'email-smtp.ap-southeast-2.amazonaws.com',
91
- );
92
- });
93
- });
@@ -1,149 +0,0 @@
1
- import type { ConstructManifest } from '@geekmidas/manifest';
2
- import { describe, expect, it } from 'vitest';
3
- import { ObjectStorage } from '../aws/ObjectStorage';
4
- import { UnresolvedDependency } from '../errors';
5
- import {
6
- isServed,
7
- type ProvisionContext,
8
- provisionerFor,
9
- siteEnvironment,
10
- } from '../fromManifest';
11
-
12
- const stack = {} as never;
13
-
14
- const manifest = {
15
- Uploads: { kind: 'objects', id: 'Uploads', provides: ['UPLOADS_URL'] },
16
- UploadsServer: {
17
- kind: 'file-server',
18
- id: 'UploadsServer',
19
- of: 'Uploads',
20
- open: ['brand/**'],
21
- provides: ['UPLOADS_SERVER_URL'],
22
- },
23
- Assets: { kind: 'objects', id: 'Assets', provides: ['ASSETS_URL'] },
24
- Api: {
25
- kind: 'rest-api',
26
- id: 'Api',
27
- endpoints: [],
28
- provides: ['API_URL', 'API_TRUSTED_ORIGINS', 'API_COOKIE_DOMAIN'],
29
- },
30
- Orders: { kind: 'database', id: 'Orders', provides: ['ORDERS_URL'] },
31
- Mailer: {
32
- kind: 'email',
33
- id: 'Mailer',
34
- provides: ['MAILER_URL', 'MAILER_FROM'],
35
- },
36
- Console: {
37
- kind: 'site',
38
- id: 'Console',
39
- variant: 'static',
40
- path: 'apps/console',
41
- dependencies: [
42
- { target: 'Api', kind: 'rest-api' },
43
- { target: 'Orders', kind: 'database' },
44
- { target: 'UploadsServer', kind: 'file-server' },
45
- { target: 'Mailer', kind: 'email' },
46
- ],
47
- provides: ['CONSOLE_URL'],
48
- },
49
- } as const satisfies ConstructManifest;
50
-
51
- /** A provisioned stand-in that provides whatever it was handed. */
52
- const provided = (values: Record<string, string>) =>
53
- ({ provides: () => values }) as never;
54
-
55
- const context = (
56
- provisioned: Record<string, unknown> = {},
57
- ): ProvisionContext => ({
58
- manifest,
59
- provisioned: provisioned as never,
60
- bootstraps: new Map(),
61
- });
62
-
63
- describe('isServed', () => {
64
- it('finds the surface pointing at a bucket', () => {
65
- // The cost this design named: the bucket alone no longer says whether it
66
- // is served, so you find whoever points at it.
67
- expect(isServed('Uploads', manifest)).toBe(true);
68
- });
69
-
70
- it('leaves an unserved bucket alone', () => {
71
- expect(isServed('Assets', manifest)).toBe(false);
72
- });
73
- });
74
-
75
- describe('file-server provisioning', () => {
76
- it('refuses an origin that was not provisioned', () => {
77
- expect(() =>
78
- provisionerFor('file-server')(
79
- stack,
80
- manifest.UploadsServer,
81
- {},
82
- context(),
83
- ),
84
- ).toThrow(UnresolvedDependency);
85
- });
86
-
87
- it('routes everything at the root, so a served path is a bucket key', () => {
88
- const origin = new ObjectStorage(stack, 'Uploads');
89
- const server = provisionerFor('file-server')(
90
- stack,
91
- manifest.UploadsServer,
92
- {},
93
- context({ Uploads: origin }),
94
- ) as unknown as { routed: { pattern: string }[] };
95
-
96
- expect(server.routed).toEqual([
97
- { pattern: '/*', bucket: expect.anything() },
98
- ]);
99
- });
100
- });
101
-
102
- describe('siteEnvironment', () => {
103
- const built = () =>
104
- siteEnvironment(
105
- manifest.Console,
106
- context({
107
- Api: provided({ url: 'https://api.example.com' }),
108
- Orders: provided({ url: 'postgres://user:pw@db/orders' }),
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
- }),
114
- }),
115
- );
116
-
117
- it('inlines an address under the name the bundler expects', () => {
118
- expect(built().VITE_API_URL).toBe('https://api.example.com');
119
- });
120
-
121
- it('inlines a served bucket’s address, but never the bucket’s own', () => {
122
- // A served URL is what a browser fetches; the bucket's presigns, and a
123
- // presigner in a bundle is a credential in a bundle.
124
- expect(built().VITE_UPLOADS_SERVER_URL).toBe('https://files.example.com');
125
- expect(built()).not.toHaveProperty('VITE_UPLOADS_URL');
126
- });
127
-
128
- it('keeps a connection string out of the bundle entirely', () => {
129
- // A site may legitimately depend on a database — its server half, where
130
- // it has one, reads env like anything else. `PUBLIC` decides only what
131
- // may be *prefixed*, and a password may not.
132
- expect(built()).not.toHaveProperty('VITE_ORDERS_URL');
133
- });
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
-
142
- it('fails loudly on an edge nothing provisioned', () => {
143
- // A smaller environment builds and then fails at runtime against
144
- // `http:///`, with nothing to point at.
145
- expect(() =>
146
- siteEnvironment(manifest.Console, context({ Api: provided({}) })),
147
- ).toThrow(UnresolvedDependency);
148
- });
149
- });