@encore.dev/sdk 2.0.0-beta.8 → 2.0.0-beta.9

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 (186) hide show
  1. package/README.md +54 -0
  2. package/app_meta.test.ts +25 -5
  3. package/app_meta.ts +43 -12
  4. package/config/config.test.ts +8 -12
  5. package/config/config.ts +16 -12
  6. package/config/secrets.ts +19 -10
  7. package/config/value.ts +13 -17
  8. package/cron/mod.test.ts +52 -0
  9. package/cron/mod.ts +9 -2
  10. package/dist/app_meta.d.ts +37 -12
  11. package/dist/app_meta.d.ts.map +1 -1
  12. package/dist/app_meta.js +1 -0
  13. package/dist/app_meta.js.map +1 -1
  14. package/dist/config/config.d.ts +16 -12
  15. package/dist/config/config.d.ts.map +1 -1
  16. package/dist/config/config.js +5 -2
  17. package/dist/config/config.js.map +1 -1
  18. package/dist/config/secrets.d.ts +19 -10
  19. package/dist/config/secrets.d.ts.map +1 -1
  20. package/dist/config/secrets.js +19 -10
  21. package/dist/config/secrets.js.map +1 -1
  22. package/dist/config/value.d.ts +7 -5
  23. package/dist/config/value.d.ts.map +1 -1
  24. package/dist/config/value.js +10 -7
  25. package/dist/config/value.js.map +1 -1
  26. package/dist/cron/mod.d.ts +5 -1
  27. package/dist/cron/mod.d.ts.map +1 -1
  28. package/dist/cron/mod.js +8 -1
  29. package/dist/cron/mod.js.map +1 -1
  30. package/dist/frontends/mod.d.ts +39 -0
  31. package/dist/frontends/mod.d.ts.map +1 -0
  32. package/dist/frontends/mod.js +47 -0
  33. package/dist/frontends/mod.js.map +1 -0
  34. package/dist/gateway/mod.d.ts +3 -2
  35. package/dist/gateway/mod.d.ts.map +1 -1
  36. package/dist/gateway/mod.js +3 -2
  37. package/dist/gateway/mod.js.map +1 -1
  38. package/dist/gateways/mod.d.ts +42 -0
  39. package/dist/gateways/mod.d.ts.map +1 -0
  40. package/dist/gateways/mod.js +55 -0
  41. package/dist/gateways/mod.js.map +1 -0
  42. package/dist/internal/fetch.d.ts +4 -0
  43. package/dist/internal/fetch.d.ts.map +1 -1
  44. package/dist/internal/fetch.js +12 -1
  45. package/dist/internal/fetch.js.map +1 -1
  46. package/dist/internal/otel/http.d.ts +11 -0
  47. package/dist/internal/otel/http.d.ts.map +1 -0
  48. package/dist/internal/otel/http.js +64 -0
  49. package/dist/internal/otel/http.js.map +1 -0
  50. package/dist/internal/otel/index.d.ts +1 -1
  51. package/dist/internal/otel/index.d.ts.map +1 -1
  52. package/dist/internal/otel/index.js +1 -1
  53. package/dist/internal/otel/index.js.map +1 -1
  54. package/dist/internal/otel/provider.d.ts +3 -0
  55. package/dist/internal/otel/provider.d.ts.map +1 -1
  56. package/dist/internal/otel/provider.js +3 -0
  57. package/dist/internal/otel/provider.js.map +1 -1
  58. package/dist/internal/otel/span.d.ts +11 -1
  59. package/dist/internal/otel/span.d.ts.map +1 -1
  60. package/dist/internal/otel/span.js +25 -2
  61. package/dist/internal/otel/span.js.map +1 -1
  62. package/dist/internal/reqfields.d.ts +26 -6
  63. package/dist/internal/reqfields.d.ts.map +1 -1
  64. package/dist/internal/reqfields.js +44 -7
  65. package/dist/internal/reqfields.js.map +1 -1
  66. package/dist/internal/runtime/napi/napi.cjs +36 -4
  67. package/dist/internal/runtime/napi/napi.d.cts +99 -4
  68. package/dist/internal/testing/carry.d.ts +49 -0
  69. package/dist/internal/testing/carry.d.ts.map +1 -0
  70. package/dist/internal/testing/carry.js +77 -0
  71. package/dist/internal/testing/carry.js.map +1 -0
  72. package/dist/internal/testing/scope.d.ts +34 -6
  73. package/dist/internal/testing/scope.d.ts.map +1 -1
  74. package/dist/internal/testing/scope.js +103 -5
  75. package/dist/internal/testing/scope.js.map +1 -1
  76. package/dist/internal/testing/steps.d.ts +55 -0
  77. package/dist/internal/testing/steps.d.ts.map +1 -0
  78. package/dist/internal/testing/steps.js +295 -0
  79. package/dist/internal/testing/steps.js.map +1 -0
  80. package/dist/internal/testing/telemetry.d.ts +305 -0
  81. package/dist/internal/testing/telemetry.d.ts.map +1 -0
  82. package/dist/internal/testing/telemetry.js +188 -0
  83. package/dist/internal/testing/telemetry.js.map +1 -0
  84. package/dist/mod.d.ts +1 -1
  85. package/dist/mod.d.ts.map +1 -1
  86. package/dist/mod.js.map +1 -1
  87. package/dist/pubsub/mod.d.ts +1 -1
  88. package/dist/pubsub/mod.d.ts.map +1 -1
  89. package/dist/pubsub/subscription.d.ts +6 -5
  90. package/dist/pubsub/subscription.d.ts.map +1 -1
  91. package/dist/pubsub/subscription.js.map +1 -1
  92. package/dist/pubsub/topic.d.ts +14 -8
  93. package/dist/pubsub/topic.d.ts.map +1 -1
  94. package/dist/pubsub/topic.js +36 -22
  95. package/dist/pubsub/topic.js.map +1 -1
  96. package/dist/reqctx/mod.d.ts +1 -18
  97. package/dist/reqctx/mod.d.ts.map +1 -1
  98. package/dist/reqctx/mod.js +1 -17
  99. package/dist/reqctx/mod.js.map +1 -1
  100. package/dist/services/index.d.ts +2 -1
  101. package/dist/services/index.d.ts.map +1 -1
  102. package/dist/services/index.js +2 -1
  103. package/dist/services/index.js.map +1 -1
  104. package/dist/storage/objects/bucket.d.ts +2 -1
  105. package/dist/storage/objects/bucket.d.ts.map +1 -1
  106. package/dist/storage/objects/bucket.js +2 -1
  107. package/dist/storage/objects/bucket.js.map +1 -1
  108. package/dist/storage/postgres/database.d.ts +5 -1
  109. package/dist/storage/postgres/database.d.ts.map +1 -1
  110. package/dist/storage/postgres/database.js +7 -3
  111. package/dist/storage/postgres/database.js.map +1 -1
  112. package/dist/storage/redis/commands.d.ts +5 -5
  113. package/dist/storage/redis/commands.d.ts.map +1 -1
  114. package/dist/storage/redis/commands.js +5 -5
  115. package/dist/storage/redis/commands.js.map +1 -1
  116. package/dist/testing/mod.d.ts +28 -5
  117. package/dist/testing/mod.d.ts.map +1 -1
  118. package/dist/testing/mod.js +52 -8
  119. package/dist/testing/mod.js.map +1 -1
  120. package/dist/testing/playwright.d.ts +93 -0
  121. package/dist/testing/playwright.d.ts.map +1 -0
  122. package/dist/testing/playwright.js +164 -0
  123. package/dist/testing/playwright.js.map +1 -0
  124. package/dist/testing/puppeteer.d.ts +36 -0
  125. package/dist/testing/puppeteer.d.ts.map +1 -0
  126. package/dist/testing/puppeteer.js +70 -0
  127. package/dist/testing/puppeteer.js.map +1 -0
  128. package/dist/testing/system.d.ts +181 -0
  129. package/dist/testing/system.d.ts.map +1 -0
  130. package/dist/testing/system.js +255 -0
  131. package/dist/testing/system.js.map +1 -0
  132. package/dist/tracing/http.d.ts +11 -0
  133. package/dist/tracing/http.d.ts.map +1 -0
  134. package/dist/tracing/http.js +34 -0
  135. package/dist/tracing/http.js.map +1 -0
  136. package/dist/tracing/mod.d.ts +1 -0
  137. package/dist/tracing/mod.d.ts.map +1 -1
  138. package/dist/tracing/mod.js +1 -0
  139. package/dist/tracing/mod.js.map +1 -1
  140. package/dist/tracing/node.d.ts +10 -0
  141. package/dist/tracing/node.d.ts.map +1 -0
  142. package/dist/tracing/node.js +142 -0
  143. package/dist/tracing/node.js.map +1 -0
  144. package/dist/tsconfig.build.tsbuildinfo +1 -1
  145. package/frontends/mod.test.ts +51 -0
  146. package/frontends/mod.ts +50 -0
  147. package/gateway/mod.ts +3 -2
  148. package/gateways/mod.ts +60 -0
  149. package/internal/fetch.ts +12 -1
  150. package/internal/otel/http.ts +91 -0
  151. package/internal/otel/index.ts +1 -1
  152. package/internal/otel/provider.ts +3 -0
  153. package/internal/otel/span.ts +25 -2
  154. package/internal/reqfields.ts +43 -10
  155. package/internal/runtime/napi/napi.cjs +36 -4
  156. package/internal/runtime/napi/napi.d.cts +99 -4
  157. package/internal/testing/carry.test.ts +242 -0
  158. package/internal/testing/carry.ts +101 -0
  159. package/internal/testing/scope.ts +106 -7
  160. package/internal/testing/steps.test.ts +152 -0
  161. package/internal/testing/steps.ts +342 -0
  162. package/internal/testing/telemetry.test.ts +210 -0
  163. package/internal/testing/telemetry.ts +466 -0
  164. package/mod.ts +1 -0
  165. package/package.json +26 -1
  166. package/pubsub/mod.ts +6 -1
  167. package/pubsub/pubsub.test.ts +1 -0
  168. package/pubsub/subscription.ts +6 -5
  169. package/pubsub/topic.ts +45 -21
  170. package/reqctx/mod.ts +1 -18
  171. package/reqctx/reqctx.test.ts +23 -0
  172. package/scripts/postprocess-docs.test.ts +11 -1
  173. package/services/index.ts +2 -1
  174. package/storage/objects/bucket.ts +2 -1
  175. package/storage/postgres/database.ts +7 -3
  176. package/storage/redis/commands.ts +5 -5
  177. package/testing/mod.ts +63 -7
  178. package/testing/playwright.ts +247 -0
  179. package/testing/puppeteer.ts +101 -0
  180. package/testing/system.test.ts +108 -0
  181. package/testing/system.ts +373 -0
  182. package/tracing/http.ts +49 -0
  183. package/tracing/mod.ts +1 -0
  184. package/tracing/native.test.ts +101 -4
  185. package/tracing/node.ts +176 -0
  186. package/tracing/tracing.test.ts +660 -24
package/README.md CHANGED
@@ -171,6 +171,60 @@ that use the global API; Encore never does this automatically. `tracerProvider`
171
171
  remains available from `@encore.dev/sdk`. See the paired
172
172
  [tracing fixtures](../../../tests/ts/telemetry) for runnable examples.
173
173
 
174
+ ### HTTP handlers
175
+
176
+ Wrap a Web `Request` → `Response` handler to continue incoming traces:
177
+
178
+ ```typescript
179
+ import {instrumentHTTP} from '@encore.dev/sdk/tracing';
180
+
181
+ Bun.serve({fetch: instrumentHTTP(handleRequest)});
182
+ ```
183
+
184
+ `instrumentHTTP` extracts W3C trace context and Encore Request Context, then
185
+ runs the handler with an Encore-owned SERVER span active. Nested spans, logs,
186
+ metrics and service calls inherit it. Extra handler arguments and `this` are
187
+ preserved; no OTel globals are registered or replaced.
188
+
189
+ Span names use the HTTP method. Raw URL paths and queries are not recorded:
190
+ paths may contain credentials or personal identifiers. Framework adapters can
191
+ add a safe `http.route` template. Response status is recorded;
192
+ 5xx responses and thrown errors mark the span ERROR. Exceptions are rethrown.
193
+ The original response and its body are untouched: the span ends when the
194
+ handler returns a response, not when a streaming body finishes. Handlers must
195
+ return a `Response`; WebSocket upgrades need a runtime-specific adapter.
196
+ Only accept Encore Request Context headers from trusted Encore ingress; the
197
+ wrapper decodes them, not authenticates them.
198
+
199
+ ### Node HTTP handlers
200
+
201
+ ```typescript
202
+ import {createServer} from 'node:http';
203
+ import {instrumentHTTP} from '@encore.dev/sdk/tracing/node';
204
+
205
+ createServer(
206
+ instrumentHTTP((request, response) => {
207
+ response.writeHead(200);
208
+ response.end('ok');
209
+ }),
210
+ ).listen(3000);
211
+ ```
212
+
213
+ The Node adapter accepts native `IncomingMessage`/`ServerResponse` listeners;
214
+ request and response bodies are not converted or buffered. It shares trace
215
+ and Request Context extraction with the Fetch wrapper and preserves `this`.
216
+ During response processing, request/response event callbacks run in the
217
+ request's context.
218
+
219
+ Its span lasts until response `finish`, premature `close`, response error,
220
+ or a thrown/rejected handler failure. A handler returning before a streamed
221
+ response finishes does not end the span. Premature closes mark it ERROR.
222
+ The adapter records and rethrows handler failures; the application remains
223
+ responsible for error responses and handling rejected async listeners.
224
+ Failures before headers are sent have no recorded HTTP response status.
225
+ Synchronous return values are preserved; PromiseLike results become Promises.
226
+ HTTP upgrade and CONNECT events require separate instrumentation.
227
+
174
228
  ## Formatting and linting
175
229
 
176
230
  Use Node.js 24 LTS for SDK development and install dependencies with `npm ci`.
package/app_meta.test.ts CHANGED
@@ -53,11 +53,23 @@ describe('appMeta', () => {
53
53
  expect(Object.keys(md.gateways).sort()).toEqual(['admin', 'api']);
54
54
  expect(md.gateways.api).toEqual({
55
55
  name: 'api',
56
- baseUrl: 'https://api.example.com',
56
+ url: 'https://api.example.com',
57
+ origins: ['https://api.example.com', '*'],
57
58
  });
58
59
  expect(md.gateways.admin).toEqual({
59
60
  name: 'admin',
60
- baseUrl: 'https://admin.example.com',
61
+ url: 'https://admin.example.com',
62
+ origins: ['https://admin.example.com'],
63
+ });
64
+ });
65
+
66
+ test('reports every frontend, keyed by name', () => {
67
+ expect(md.frontends).toEqual({
68
+ web: {
69
+ name: 'web',
70
+ url: 'https://example.com',
71
+ origins: ['https://example.com', 'https://*.example.com'],
72
+ },
61
73
  });
62
74
  });
63
75
 
@@ -108,19 +120,27 @@ function runtimeConfig(): string {
108
120
  ...enumField(5, 1), // TYPE_DEVELOPMENT
109
121
  ...enumField(6, 4), // CLOUD_GCP
110
122
  ];
111
- // Gateway{rid=1, encore_name=2, base_url=3}
123
+ // Gateway{rid=1, encore_name=2, origins=3}
112
124
  const api = [
113
125
  ...str(1, 'gw:api'),
114
126
  ...str(2, 'api'),
115
127
  ...str(3, 'https://api.example.com'),
128
+ ...str(3, '*'),
116
129
  ];
117
130
  const admin = [
118
131
  ...str(1, 'gw:admin'),
119
132
  ...str(2, 'admin'),
120
133
  ...str(3, 'https://admin.example.com'),
121
134
  ];
122
- // Infrastructure.Resources{gateways=1}; Infrastructure{resources=1}
123
- const infra = msg(1, [...msg(1, api), ...msg(1, admin)]);
135
+ // Frontend{rid=1, encore_name=2, origins=3}
136
+ const web = [
137
+ ...str(1, 'fe:web'),
138
+ ...str(2, 'web'),
139
+ ...str(3, 'https://example.com'),
140
+ ...str(3, 'https://*.example.com'),
141
+ ];
142
+ // Infrastructure.Resources{gateways=1, frontends=11}; Infrastructure{resources=1}
143
+ const infra = msg(1, [...msg(1, api), ...msg(1, admin), ...msg(11, web)]);
124
144
  // Deployment{deploy_id=1, hosted_services=5, revision=11}
125
145
  const deployment = [
126
146
  ...str(1, 'deploy-1'),
package/app_meta.ts CHANGED
@@ -19,15 +19,25 @@ export interface AppMeta {
19
19
  appSlug: string;
20
20
 
21
21
  /**
22
- * The API gateways that serve this application, keyed by gateway name.
22
+ * The API gateways of this application this service is given, keyed by
23
+ * gateway name: those its code looks up the URL of, and the one it hosts.
23
24
  *
24
25
  * An application can declare several gateways, so there is no single base URL for
25
- * the API — look up the gateway you mean by name. Every process lists them,
26
- * whether it serves one or not; one told of none, as under `encore test`,
27
- * reports an empty object.
26
+ * the API — look up the gateway you mean by name. A service's processes, its
27
+ * Workers' included, list the gateways its code names (`url("api")` from
28
+ * `@encore.dev/sdk/gateways`) and the one it hosts, and no other, the default
29
+ * included; one told of none, as under `encore test`, reports an empty object.
28
30
  */
29
31
  gateways: Record<string, GatewayMeta>;
30
32
 
33
+ /**
34
+ * The frontends of this application this service is given — those its code
35
+ * looks up the URL of (`url("web")` from `@encore.dev/sdk/frontends`), and
36
+ * the one it hosts — keyed by name, with where each is reached. One the
37
+ * environment gives no origins is left out.
38
+ */
39
+ frontends: Record<string, FrontendMeta>;
40
+
31
41
  /** Information about the environment the app is running in. */
32
42
  environment: EnvironmentMeta;
33
43
 
@@ -44,15 +54,35 @@ export interface GatewayMeta {
44
54
  name: string;
45
55
 
46
56
  /**
47
- * The base URL which can be used to call the API of this running application
48
- * through this gateway.
49
- *
50
- * For local development it is "http://localhost:<port>", typically "http://localhost:4000".
51
- *
52
- * If a custom domain is used for this environment it is returned here, but note that
53
- * changes only take effect at the time of deployment while custom domains can be updated at any time.
57
+ * The URL the API of this running application is called at through this
58
+ * gateway: the first of its origins. Empty when the environment gives the
59
+ * gateway no origins.
60
+ */
61
+ url: string;
62
+
63
+ /**
64
+ * Every origin the gateway is reached at in this environment
65
+ * (`scheme://host[:port]`), the first its URL. After the first, an entry may
66
+ * be a pattern of one, `https://*.example.com`, or `*`, which makes the
67
+ * gateway the one serving requests no other origin matches.
68
+ */
69
+ origins: string[];
70
+ }
71
+
72
+ /** Describes a frontend of the application, and where it is reached. */
73
+ export interface FrontendMeta {
74
+ /** The name of the frontend: for one a service hosts, the service's. */
75
+ name: string;
76
+
77
+ /** The URL the frontend is reached at: the first of its origins. */
78
+ url: string;
79
+
80
+ /**
81
+ * Every origin the frontend is reached at in this environment, the first its
82
+ * URL; after the first, an entry may be a pattern of one,
83
+ * `https://*.example.com`.
54
84
  */
55
- baseUrl: string;
85
+ origins: string[];
56
86
  }
57
87
 
58
88
  /** Describes the environment the Encore application is running in. */
@@ -139,6 +169,7 @@ export function appMeta(): AppMeta {
139
169
  appId: rt.appId,
140
170
  appSlug: rt.appSlug,
141
171
  gateways: rt.gateways,
172
+ frontends: rt.frontends,
142
173
  environment: {
143
174
  name: rt.environment.name,
144
175
  type: envType(rt.environment.type),
@@ -86,7 +86,7 @@ describe('build', () => {
86
86
  },
87
87
  ],
88
88
  },
89
- apiKey: {'x-encore-secret': {name: 'StripeKey', scope: 'shared'}},
89
+ apiKey: {'x-encore-secret': 'StripeKey'},
90
90
  name: {type: 'string'},
91
91
  },
92
92
  };
@@ -100,10 +100,10 @@ describe('build', () => {
100
100
  retries: ['1s', '5s'],
101
101
  windows: {eu: '2m'},
102
102
  payment: {kind: 'card', hold: '10m'},
103
- apiKey: {$encore_secret: {name: 'StripeKey', scope: 'shared'}},
103
+ apiKey: {$encore_secret: 'StripeKey'},
104
104
  name: '30s',
105
105
  },
106
- (name, scope) => `secret ${name} (${scope})`,
106
+ name => `secret ${name}`,
107
107
  ) as any;
108
108
  expect(value.timeout).toBeInstanceOf(Duration);
109
109
  expect(value.timeout.seconds).toBe(30);
@@ -111,13 +111,13 @@ describe('build', () => {
111
111
  expect(value.retries.map((d: Duration) => d.seconds)).toEqual([1, 5]);
112
112
  expect(value.windows.eu.seconds).toBe(120);
113
113
  expect(value.payment.hold.seconds).toBe(600);
114
- expect(value.apiKey).toBe('secret StripeKey (shared)');
114
+ expect(value.apiKey).toBe('secret StripeKey');
115
115
  // A string the schema doesn't mark stays a string.
116
116
  expect(value.name).toBe('30s');
117
117
  });
118
118
 
119
119
  test('makes a secret only of a field the schema says reads one', () => {
120
- const forged = {$encore_secret: {name: 'StripeKey', scope: 'shared'}};
120
+ const forged = {$encore_secret: 'StripeKey'};
121
121
  const value = build(
122
122
  {type: 'object', properties: {extra: {}, name: {type: 'string'}}},
123
123
  {extra: forged},
@@ -129,11 +129,7 @@ describe('build', () => {
129
129
 
130
130
  const secretOf = (name: string) => `secret ${name}`;
131
131
  expect(() =>
132
- build(
133
- schema,
134
- {apiKey: {$encore_secret: {name: 'Other', scope: 'shared'}}},
135
- secretOf,
136
- ),
132
+ build(schema, {apiKey: {$encore_secret: 'Other'}}, secretOf),
137
133
  ).toThrow('a secret field reads the secret StripeKey');
138
134
  expect(() => build(schema, {apiKey: 'sk_live_123'}, secretOf)).not.toThrow(
139
135
  /sk_live/,
@@ -326,7 +322,7 @@ function runtimeConfig(live: string): string {
326
322
  properties: {
327
323
  max_items: {type: 'integer', minimum: 1},
328
324
  timeout: {type: 'string', 'x-encore-format': 'duration'},
329
- stripe_key: {'x-encore-secret': {name: 'StripeKey', scope: 'service'}},
325
+ stripe_key: {'x-encore-secret': 'StripeKey'},
330
326
  },
331
327
  required: ['max_items'],
332
328
  additionalProperties: false,
@@ -335,7 +331,7 @@ function runtimeConfig(live: string): string {
335
331
  type: 'object',
336
332
  properties: {
337
333
  new_checkout: {type: 'boolean'},
338
- key: {'x-encore-secret': {name: 'FlagKey', scope: 'shared'}},
334
+ key: {'x-encore-secret': 'FlagKey'},
339
335
  },
340
336
  additionalProperties: false,
341
337
  };
package/config/config.ts CHANGED
@@ -13,19 +13,20 @@ export {Duration} from './value';
13
13
  * argument. Encore reads that type to know what the config's files may hold,
14
14
  * and checks them against it before the value reaches the code.
15
15
  *
16
- * @example
17
- * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
16
+ * ```ts
17
+ * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
18
18
  *
19
- * interface Checkout {
20
- * // Most items one order may hold.
21
- * maxItems: number & Int & Min<1> & Max<500>;
22
- * currencies?: string[];
23
- * paymentTimeout: Duration;
24
- * }
19
+ * interface Checkout {
20
+ * // Most items one order may hold.
21
+ * maxItems: number & Int & Min<1> & Max<500>;
22
+ * currencies?: string[];
23
+ * paymentTimeout: Duration;
24
+ * }
25
25
  *
26
- * export const checkout = config<Checkout>("checkout");
26
+ * export const checkout = config<Checkout>("checkout");
27
27
  *
28
- * if (items.length > checkout().maxItems) { ... }
28
+ * if (items.length > checkout().maxItems) { ... }
29
+ * ```
29
30
  *
30
31
  * # Values
31
32
  *
@@ -90,8 +91,11 @@ export interface ConfigOptions {
90
91
  * declares it (see {@link ConfigOptions.scope}). The declaration is a
91
92
  * module-level `export const`, with the name a string literal.
92
93
  *
93
- * @example a config several services read
94
- * export const flags = config<Flags>("flags", {scope: "shared"});
94
+ * @example
95
+ * ```ts
96
+ * // A config several services read.
97
+ * export const flags = config<Flags>("flags", {scope: "shared"});
98
+ * ```
95
99
  */
96
100
  export function config<T>(
97
101
  name: string,
package/config/secrets.ts CHANGED
@@ -100,18 +100,27 @@ export interface SecretOptions {
100
100
  * A doc comment on the declaration, or a `description` option, is shown
101
101
  * wherever the secret's values are managed.
102
102
  *
103
- * @example loading a single secret
104
- * import {secret} from "@encore.dev/sdk/config";
105
- * const foo = secret("foo");
103
+ * @example
104
+ * ```ts
105
+ * // Loading a single secret.
106
+ * import {secret} from "@encore.dev/sdk/config";
107
+ * const foo = secret("foo");
108
+ * ```
106
109
  *
107
- * @example a secret several services share
108
- * import {secret} from "@encore.dev/sdk/config";
109
- * const signingKey = secret("SigningKey", {scope: "shared"});
110
+ * @example
111
+ * ```ts
112
+ * // A secret several services share.
113
+ * import {secret} from "@encore.dev/sdk/config";
114
+ * const signingKey = secret("SigningKey", {scope: "shared"});
115
+ * ```
110
116
  *
111
- * @example documenting it
112
- * const apiKey = secret("ApiKey", {
113
- * description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
114
- * });
117
+ * @example
118
+ * ```ts
119
+ * // Documenting it.
120
+ * const apiKey = secret("ApiKey", {
121
+ * description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
122
+ * });
123
+ * ```
115
124
  */
116
125
  export function secret<Name extends string>(
117
126
  name: StringLiteral<Name>,
package/config/value.ts CHANGED
@@ -103,14 +103,15 @@ export class Duration {
103
103
  }
104
104
  }
105
105
 
106
- /** The key of the runtime's placeholder for a secret field. */
106
+ /**
107
+ * The key of the runtime's placeholder for a secret field:
108
+ * `{"$encore_secret": "<name>"}`. The name alone says which secret it is: a
109
+ * secret's name has one scope across the app.
110
+ */
107
111
  export const PLACEHOLDER_KEY = '$encore_secret';
108
112
 
109
- /** A secret's scope, as a placeholder names it. */
110
- export type SecretScope = 'service' | 'shared' | 'global';
111
-
112
- /** Builds the secret a placeholder stands for. */
113
- export type SecretOf = (name: string, scope: SecretScope) => unknown;
113
+ /** Builds the secret a placeholder stands for, by its name. */
114
+ export type SecretOf = (name: string) => unknown;
114
115
 
115
116
  type Schema = Record<string, any>;
116
117
 
@@ -154,19 +155,16 @@ function convert(
154
155
 
155
156
  // Only a field the schema says reads a secret is one: anywhere else, a
156
157
  // value shaped like a placeholder is just data, and must not reach a secret.
158
+ // The keyword is the secret's name: its scope is the config's.
157
159
  const secret = schema['x-encore-secret'];
158
- if (secret) {
159
- if (
160
- !isPlaceholder(value) ||
161
- value[PLACEHOLDER_KEY].name !== secret.name ||
162
- value[PLACEHOLDER_KEY].scope !== secret.scope
163
- ) {
160
+ if (typeof secret === 'string') {
161
+ if (!isPlaceholder(value) || value[PLACEHOLDER_KEY] !== secret) {
164
162
  // Never say what the value is: it may be a pasted secret.
165
163
  throw new Error(
166
- `a secret field reads the secret ${secret.name}, and is not set in config`,
164
+ `a secret field reads the secret ${secret}, and is not set in config`,
167
165
  );
168
166
  }
169
- return secretOf(secret.name, secret.scope);
167
+ return secretOf(secret);
170
168
  }
171
169
 
172
170
  if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
@@ -233,9 +231,7 @@ function branchOf(
233
231
  return undefined;
234
232
  }
235
233
 
236
- function isPlaceholder(
237
- value: unknown,
238
- ): value is {[PLACEHOLDER_KEY]: {name: string; scope: SecretScope}} {
234
+ function isPlaceholder(value: unknown): value is {[PLACEHOLDER_KEY]: string} {
239
235
  if (value === null || typeof value !== 'object' || Array.isArray(value))
240
236
  return false;
241
237
  const keys = Object.keys(value);
@@ -0,0 +1,52 @@
1
+ import {describe, expect, test} from 'bun:test';
2
+
3
+ import {CronJob} from './mod';
4
+
5
+ describe('CronJob', () => {
6
+ test('reads as it was declared', () => {
7
+ const job = new CronJob('cleanup', {
8
+ title: 'Nightly cleanup',
9
+ every: '24h',
10
+ path: '/internal/cleanup',
11
+ });
12
+ expect(job.name).toBe('cleanup');
13
+ expect(job.cfg).toEqual({
14
+ title: 'Nightly cleanup',
15
+ every: '24h',
16
+ path: '/internal/cleanup',
17
+ });
18
+ });
19
+
20
+ // Encore requests the declared path: a route from a changed one would
21
+ // never be called. `tsc` refuses the writes (below); an app run without it
22
+ // has them throw.
23
+ test('cannot be changed', () => {
24
+ const cfg = {every: '24h' as const, path: '/internal/cleanup'};
25
+ const job = new CronJob('cleanup', cfg);
26
+ const writable = job as unknown as {name: string; cfg: {path: string}};
27
+ expect(() => {
28
+ writable.cfg.path = '/other';
29
+ }).toThrow(TypeError);
30
+ expect(() => {
31
+ writable.cfg = {path: '/other'};
32
+ }).toThrow(TypeError);
33
+ expect(() => {
34
+ writable.name = 'other';
35
+ }).toThrow(TypeError);
36
+ expect(job.cfg.path).toBe('/internal/cleanup');
37
+ // The declaration's own object is the app's, and is left as it was.
38
+ expect(Object.isFrozen(cfg)).toBe(false);
39
+ });
40
+ });
41
+
42
+ // Compile-only: `tsc` checks that a job's config can be read but not changed.
43
+ // Never called.
44
+ function _cfgTyping(job: CronJob) {
45
+ const path: string = job.cfg.path;
46
+ void path;
47
+ // @ts-expect-error Encore requests the declared path, not a changed one
48
+ job.cfg.path = '/other';
49
+ // @ts-expect-error the title is read from the source, too
50
+ job.cfg.title = 'Other';
51
+ }
52
+ void _cfgTyping;
package/cron/mod.ts CHANGED
@@ -27,10 +27,17 @@ export const TRIGGER_HEADER = 'x-encore-cron-trigger';
27
27
 
28
28
  export class CronJob {
29
29
  readonly name: string;
30
- readonly cfg: CronJobConfig;
30
+ /**
31
+ * What the job was declared with. Read-only: Encore schedules the job from
32
+ * the declaration in the source, so a changed path would not be requested.
33
+ */
34
+ readonly cfg: Readonly<CronJobConfig>;
31
35
  constructor(name: string, cfg: CronJobConfig) {
32
36
  this.name = name;
33
- this.cfg = cfg;
37
+ // Frozen as well as typed `readonly`, so a write throws in an app that
38
+ // runs without `tsc` checking it.
39
+ this.cfg = Object.freeze({...cfg});
40
+ Object.freeze(this);
34
41
  }
35
42
  }
36
43
 
@@ -15,14 +15,23 @@ export interface AppMeta {
15
15
  */
16
16
  appSlug: string;
17
17
  /**
18
- * The API gateways that serve this application, keyed by gateway name.
18
+ * The API gateways of this application this service is given, keyed by
19
+ * gateway name: those its code looks up the URL of, and the one it hosts.
19
20
  *
20
21
  * An application can declare several gateways, so there is no single base URL for
21
- * the API — look up the gateway you mean by name. Every process lists them,
22
- * whether it serves one or not; one told of none, as under `encore test`,
23
- * reports an empty object.
22
+ * the API — look up the gateway you mean by name. A service's processes, its
23
+ * Workers' included, list the gateways its code names (`url("api")` from
24
+ * `@encore.dev/sdk/gateways`) and the one it hosts, and no other, the default
25
+ * included; one told of none, as under `encore test`, reports an empty object.
24
26
  */
25
27
  gateways: Record<string, GatewayMeta>;
28
+ /**
29
+ * The frontends of this application this service is given — those its code
30
+ * looks up the URL of (`url("web")` from `@encore.dev/sdk/frontends`), and
31
+ * the one it hosts — keyed by name, with where each is reached. One the
32
+ * environment gives no origins is left out.
33
+ */
34
+ frontends: Record<string, FrontendMeta>;
26
35
  /** Information about the environment the app is running in. */
27
36
  environment: EnvironmentMeta;
28
37
  /** Information about the build. */
@@ -35,15 +44,31 @@ export interface GatewayMeta {
35
44
  /** The name of the gateway, as declared by the application. */
36
45
  name: string;
37
46
  /**
38
- * The base URL which can be used to call the API of this running application
39
- * through this gateway.
40
- *
41
- * For local development it is "http://localhost:<port>", typically "http://localhost:4000".
42
- *
43
- * If a custom domain is used for this environment it is returned here, but note that
44
- * changes only take effect at the time of deployment while custom domains can be updated at any time.
47
+ * The URL the API of this running application is called at through this
48
+ * gateway: the first of its origins. Empty when the environment gives the
49
+ * gateway no origins.
50
+ */
51
+ url: string;
52
+ /**
53
+ * Every origin the gateway is reached at in this environment
54
+ * (`scheme://host[:port]`), the first its URL. After the first, an entry may
55
+ * be a pattern of one, `https://*.example.com`, or `*`, which makes the
56
+ * gateway the one serving requests no other origin matches.
57
+ */
58
+ origins: string[];
59
+ }
60
+ /** Describes a frontend of the application, and where it is reached. */
61
+ export interface FrontendMeta {
62
+ /** The name of the frontend: for one a service hosts, the service's. */
63
+ name: string;
64
+ /** The URL the frontend is reached at: the first of its origins. */
65
+ url: string;
66
+ /**
67
+ * Every origin the frontend is reached at in this environment, the first its
68
+ * URL; after the first, an entry may be a pattern of one,
69
+ * `https://*.example.com`.
45
70
  */
46
- baseUrl: string;
71
+ origins: string[];
47
72
  }
48
73
  /** Describes the environment the Encore application is running in. */
49
74
  export interface EnvironmentMeta {
@@ -1 +1 @@
1
- {"version":3,"file":"app_meta.d.ts","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAEA,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEtC,+DAA+D;IAC/D,WAAW,EAAE,eAAe,CAAC;IAE7B,mCAAmC;IACnC,KAAK,EAAE,SAAS,CAAC;IAEjB,wCAAwC;IACxC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,wDAAwD;AACxD,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,eAAe,CAAC;IAEtB;;;OAGG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAEvB,YAA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.gateways,
16
+ frontends: rt.frontends,
16
17
  environment: {
17
18
  name: rt.environment.name,
18
19
  type: envType(rt.environment.type),
@@ -1 +1 @@
1
- {"version":3,"file":"app_meta.js","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA+HlD;;;;;GAKG;AACH,MAAM,UAAU,OAAO;IACrB,qCAAqC;IACrC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,GAAG;YACP,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,OAAO,EAAE,EAAE,CAAC,OAAO;YACnB,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,WAAW,EAAE;gBACX,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI;gBACzB,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;gBAClC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;aAC3C;YACD,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ;aAC5B;YACD,MAAM,EAAE;gBACN,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE;gBAChB,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC;gBACpC,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc;gBACxC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,SAAS;aACtC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAC,MAA+B;IAC9C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,CAAC,eAAe,CAAC,UAAU;YACrC,OAAO,YAAY,CAAC;QACtB,KAAK,O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AO,QAAQ,CAAC;QAClB,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK;YAC9B,OAAO,OAAO,CAAC;QACjB;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC;AAED,6CAA6C;AAC7C,IAAI,MAAM,GAAmB,IAAI,CAAC"}
@@ -8,19 +8,20 @@ export { Duration } from './value.js';
8
8
  * argument. Encore reads that type to know what the config's files may hold,
9
9
  * and checks them against it before the value reaches the code.
10
10
  *
11
- * @example
12
- * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
11
+ * ```ts
12
+ * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
13
13
  *
14
- * interface Checkout {
15
- * // Most items one order may hold.
16
- * maxItems: number & Int & Min<1> & Max<500>;
17
- * currencies?: string[];
18
- * paymentTimeout: Duration;
19
- * }
14
+ * interface Checkout {
15
+ * // Most items one order may hold.
16
+ * maxItems: number & Int & Min<1> & Max<500>;
17
+ * currencies?: string[];
18
+ * paymentTimeout: Duration;
19
+ * }
20
20
  *
21
- * export const checkout = config<Checkout>("checkout");
21
+ * export const checkout = config<Checkout>("checkout");
22
22
  *
23
- * if (items.length > checkout().maxItems) { ... }
23
+ * if (items.length > checkout().maxItems) { ... }
24
+ * ```
24
25
  *
25
26
  * # Values
26
27
  *
@@ -80,8 +81,11 @@ export interface ConfigOptions {
80
81
  * declares it (see {@link ConfigOptions.scope}). The declaration is a
81
82
  * module-level `export const`, with the name a string literal.
82
83
  *
83
- * @example a config several services read
84
- * export const flags = config<Flags>("flags", {scope: "shared"});
84
+ * @example
85
+ * ```ts
86
+ * // A config several services read.
87
+ * export const flags = config<Flags>("flags", {scope: "shared"});
88
+ * ```
85
89
  */
86
90
  export declare function config<T>(name: string, opts?: ConfigOptions): Config<T>;
87
91
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,KAAK,EAAC,MAAM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zE,kEAAkE;AAClE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAA;CAAC,CAAC;AAE5E,kEAAkE;AAClE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAA;CAAC,CAAC"}
@@ -8,8 +8,11 @@ export { Duration } from './value.js';
8
8
  * declares it (see {@link ConfigOptions.scope}). The declaration is a
9
9
  * module-level `export const`, with the name a string literal.
10
10
  *
11
- * @example a config several services read
12
- * export const flags = config<Flags>("flags", {scope: "shared"});
11
+ * @example
12
+ * ```ts
13
+ * // A config several services read.
14
+ * export const flags = config<Flags>("flags", {scope: "shared"});
15
+ * ```
13
16
  */
14
17
  export function config(name,
15
18
  // The options are Encore's parser's to read: a config is read by name