@apifuse/provider-sdk 2.2.0-beta.1 → 2.2.0-beta.11

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 (261) hide show
  1. package/AUTHORING.md +106 -0
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +5 -1
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +44 -59
  6. package/bin/apifuse-create.ts +1 -1
  7. package/bin/apifuse-dev.ts +27 -52
  8. package/bin/apifuse-pack-check.ts +14 -0
  9. package/bin/apifuse-pack-smoke.ts +22 -81
  10. package/bin/apifuse-pack-types.ts +266 -0
  11. package/bin/apifuse-perf.ts +45 -127
  12. package/bin/apifuse-record.ts +53 -70
  13. package/bin/apifuse-submit-check.ts +510 -45
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/apifuse.ts +1 -1
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/bin/submit-check-xml-semantics.ts +204 -0
  18. package/bin/submit-check-xml.ts +134 -0
  19. package/dist/auth-turn/index.d.ts +3 -3
  20. package/dist/auth.d.ts +2 -2
  21. package/dist/auth.js +9 -18
  22. package/dist/ceremonies/index.d.ts +1 -1
  23. package/dist/ceremonies/index.js +8 -18
  24. package/dist/cli/commands.d.ts +1 -1
  25. package/dist/cli/commands.js +8 -0
  26. package/dist/cli/create.d.ts +3 -0
  27. package/dist/cli/create.js +34 -35
  28. package/dist/cli/prompt-assets.d.ts +80 -0
  29. package/dist/cli/prompt-assets.js +743 -0
  30. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  31. package/dist/config/loader.d.ts +149 -8
  32. package/dist/config/loader.js +378 -89
  33. package/dist/contract-serialization.d.ts +2 -2
  34. package/dist/contract-serialization.js +3 -6
  35. package/dist/contract-types.d.ts +2 -2
  36. package/dist/contract.d.ts +3 -3
  37. package/dist/contract.js +4 -6
  38. package/dist/define.d.ts +8 -1
  39. package/dist/define.js +119 -122
  40. package/dist/dev.d.ts +1 -1
  41. package/dist/dev.js +1 -1
  42. package/dist/errors.d.ts +4 -1
  43. package/dist/errors.js +48 -0
  44. package/dist/i18n/catalog.d.ts +2 -2
  45. package/dist/i18n/catalog.js +4 -10
  46. package/dist/i18n/index.d.ts +2 -2
  47. package/dist/i18n/index.js +2 -2
  48. package/dist/i18n/keys.d.ts +2 -2
  49. package/dist/index.d.ts +44 -42
  50. package/dist/index.js +39 -37
  51. package/dist/lint.js +8 -15
  52. package/dist/provider.d.ts +11 -11
  53. package/dist/provider.js +9 -9
  54. package/dist/public-schema-field-lint.d.ts +1 -1
  55. package/dist/recipes/gov-api.js +1 -1
  56. package/dist/runtime/auth-flow.d.ts +1 -1
  57. package/dist/runtime/auth-flow.js +3 -3
  58. package/dist/runtime/browser.d.ts +1 -1
  59. package/dist/runtime/browser.js +15 -29
  60. package/dist/runtime/cache.d.ts +1 -1
  61. package/dist/runtime/cache.js +4 -8
  62. package/dist/runtime/choice.d.ts +1 -1
  63. package/dist/runtime/choice.js +31 -35
  64. package/dist/runtime/credential.d.ts +1 -1
  65. package/dist/runtime/credential.js +1 -1
  66. package/dist/runtime/env.d.ts +1 -1
  67. package/dist/runtime/executor.d.ts +1 -1
  68. package/dist/runtime/executor.js +15 -3
  69. package/dist/runtime/http.d.ts +2 -2
  70. package/dist/runtime/http.js +144 -348
  71. package/dist/runtime/insights.d.ts +1 -1
  72. package/dist/runtime/insights.js +6 -13
  73. package/dist/runtime/instrumentation.d.ts +2 -2
  74. package/dist/runtime/instrumentation.js +56 -19
  75. package/dist/runtime/keyring.js +1 -1
  76. package/dist/runtime/namespace.js +1 -1
  77. package/dist/runtime/otlp.d.ts +1 -1
  78. package/dist/runtime/perf.d.ts +1 -1
  79. package/dist/runtime/provider.d.ts +1 -1
  80. package/dist/runtime/provider.js +1 -2
  81. package/dist/runtime/proxy-errors.d.ts +1 -1
  82. package/dist/runtime/proxy-errors.js +9 -7
  83. package/dist/runtime/proxy-nodemaven.d.ts +35 -0
  84. package/dist/runtime/proxy-nodemaven.js +128 -0
  85. package/dist/runtime/proxy-retry-policy.d.ts +40 -0
  86. package/dist/runtime/proxy-retry-policy.js +326 -0
  87. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  88. package/dist/runtime/proxy-telemetry.js +55 -52
  89. package/dist/runtime/redis.d.ts +1 -1
  90. package/dist/runtime/redis.js +2 -4
  91. package/dist/runtime/request-options.d.ts +1 -1
  92. package/dist/runtime/secrets.d.ts +27 -0
  93. package/dist/runtime/secrets.js +51 -0
  94. package/dist/runtime/state.d.ts +2 -2
  95. package/dist/runtime/state.js +15 -4
  96. package/dist/runtime/stealth.d.ts +2 -2
  97. package/dist/runtime/stealth.js +108 -212
  98. package/dist/runtime/stt.d.ts +1 -1
  99. package/dist/runtime/stt.js +11 -15
  100. package/dist/runtime/trace.d.ts +2 -2
  101. package/dist/runtime/trace.js +2 -4
  102. package/dist/runtime/waterfall.d.ts +1 -1
  103. package/dist/schema.d.ts +1 -1
  104. package/dist/schema.js +7 -15
  105. package/dist/serve.d.ts +1 -1
  106. package/dist/serve.js +1 -1
  107. package/dist/server/index.d.ts +7 -7
  108. package/dist/server/index.js +6 -6
  109. package/dist/server/self-test-redaction.d.ts +1 -1
  110. package/dist/server/self-test-redaction.js +1 -1
  111. package/dist/server/self-test.d.ts +104 -3
  112. package/dist/server/self-test.js +673 -115
  113. package/dist/server/serve.d.ts +105 -4
  114. package/dist/server/serve.js +588 -80
  115. package/dist/server/types.d.ts +10 -9
  116. package/dist/server/types.js +3 -7
  117. package/dist/stateful/errors.d.ts +14 -0
  118. package/dist/stateful/errors.js +14 -0
  119. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  120. package/dist/stateful/http-provider-event-emitter.js +237 -0
  121. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  122. package/dist/stateful/http-session-owner-registry.js +210 -0
  123. package/dist/stateful/index.d.ts +18 -0
  124. package/dist/stateful/index.js +18 -0
  125. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  126. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  127. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  128. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  129. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  130. package/dist/stateful/provider-event-pipeline.js +1 -0
  131. package/dist/stateful/provider-events.d.ts +101 -0
  132. package/dist/stateful/provider-events.js +289 -0
  133. package/dist/stateful/session-key.d.ts +15 -0
  134. package/dist/stateful/session-key.js +86 -0
  135. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  136. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  137. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  138. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  139. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  140. package/dist/stateful/stateful-provider-adapter.js +287 -0
  141. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  142. package/dist/stateful/stateful-provider-observability.js +161 -0
  143. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  144. package/dist/stateful/stateful-provider-owner-forwarder.js +207 -0
  145. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  146. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  147. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  148. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  149. package/dist/stateful/stateful-provider-session-routing.d.ts +71 -0
  150. package/dist/stateful/stateful-provider-session-routing.js +353 -0
  151. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  152. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  153. package/dist/stateful-signing.d.ts +18 -0
  154. package/dist/stateful-signing.js +27 -0
  155. package/dist/stealth/profiles.d.ts +1 -1
  156. package/dist/stealth/profiles.js +5 -14
  157. package/dist/stream.d.ts +1 -1
  158. package/dist/testing/index.d.ts +2 -2
  159. package/dist/testing/index.js +2 -2
  160. package/dist/testing/run.d.ts +1 -1
  161. package/dist/testing/run.js +7 -14
  162. package/dist/types.d.ts +87 -1
  163. package/dist/user-input.d.ts +30 -0
  164. package/dist/user-input.js +66 -0
  165. package/package.json +14 -5
  166. package/src/auth-turn/index.ts +1 -1
  167. package/src/auth.ts +28 -86
  168. package/src/ceremonies/index.ts +24 -78
  169. package/src/cli/commands.ts +10 -0
  170. package/src/cli/create.ts +42 -35
  171. package/src/cli/prompt-assets.ts +865 -0
  172. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  173. package/src/config/loader.ts +543 -208
  174. package/src/contract-serialization.ts +5 -11
  175. package/src/contract-types.ts +2 -2
  176. package/src/contract.ts +12 -28
  177. package/src/define.ts +247 -505
  178. package/src/dev.ts +4 -9
  179. package/src/errors.ts +58 -5
  180. package/src/i18n/catalog.ts +10 -32
  181. package/src/i18n/index.ts +2 -2
  182. package/src/i18n/keys.ts +5 -11
  183. package/src/index.ts +49 -42
  184. package/src/lint.ts +89 -159
  185. package/src/provider.ts +15 -11
  186. package/src/public-schema-field-lint.ts +7 -33
  187. package/src/recipes/gov-api.ts +2 -5
  188. package/src/runtime/auth-flow.ts +5 -7
  189. package/src/runtime/browser.ts +64 -187
  190. package/src/runtime/cache.ts +20 -67
  191. package/src/runtime/choice.ts +79 -132
  192. package/src/runtime/credential.ts +2 -2
  193. package/src/runtime/env.ts +1 -1
  194. package/src/runtime/executor.ts +23 -20
  195. package/src/runtime/http.ts +195 -559
  196. package/src/runtime/insights.ts +15 -53
  197. package/src/runtime/instrumentation.ts +78 -65
  198. package/src/runtime/keyring.ts +7 -19
  199. package/src/runtime/namespace.ts +2 -7
  200. package/src/runtime/otlp.ts +12 -23
  201. package/src/runtime/perf.ts +1 -1
  202. package/src/runtime/provider.ts +4 -9
  203. package/src/runtime/proxy-errors.ts +29 -42
  204. package/src/runtime/proxy-nodemaven.ts +178 -0
  205. package/src/runtime/proxy-retry-policy.ts +469 -0
  206. package/src/runtime/proxy-telemetry.ts +79 -77
  207. package/src/runtime/redis.ts +4 -12
  208. package/src/runtime/request-options.ts +4 -13
  209. package/src/runtime/secrets.ts +64 -0
  210. package/src/runtime/state.ts +41 -110
  211. package/src/runtime/stealth.ts +162 -377
  212. package/src/runtime/stt.ts +38 -94
  213. package/src/runtime/trace.ts +14 -44
  214. package/src/runtime/waterfall.ts +5 -18
  215. package/src/schema.ts +23 -84
  216. package/src/serve.ts +1 -1
  217. package/src/server/index.ts +24 -7
  218. package/src/server/self-test-redaction.ts +2 -2
  219. package/src/server/self-test.ts +857 -132
  220. package/src/server/serve.ts +859 -266
  221. package/src/server/types.ts +7 -19
  222. package/src/stateful/README.md +146 -0
  223. package/src/stateful/errors.ts +23 -0
  224. package/src/stateful/http-provider-event-emitter.ts +314 -0
  225. package/src/stateful/http-session-owner-registry.ts +306 -0
  226. package/src/stateful/index.ts +18 -0
  227. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  228. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  229. package/src/stateful/provider-event-pipeline.ts +61 -0
  230. package/src/stateful/provider-events.ts +462 -0
  231. package/src/stateful/session-key.ts +111 -0
  232. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  233. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  234. package/src/stateful/stateful-provider-adapter.ts +562 -0
  235. package/src/stateful/stateful-provider-observability.ts +261 -0
  236. package/src/stateful/stateful-provider-owner-forwarder.ts +279 -0
  237. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  238. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  239. package/src/stateful/stateful-provider-session-routing.ts +555 -0
  240. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  241. package/src/stateful-signing.ts +46 -0
  242. package/src/stealth/profiles.ts +10 -26
  243. package/src/stream.ts +8 -19
  244. package/src/testing/index.ts +2 -2
  245. package/src/testing/run.ts +19 -67
  246. package/src/types.ts +88 -1
  247. package/src/user-input.ts +118 -0
  248. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  249. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  250. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  251. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  252. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  253. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  254. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  255. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  256. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  257. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  258. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  259. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  260. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  261. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/src/dev.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { serve } from "./server/serve";
2
- import type { ProviderDefinition } from "./types";
1
+ import { serve } from "./server/serve.js";
2
+ import type { ProviderDefinition } from "./types.js";
3
3
 
4
4
  export interface DevServerOptions {
5
5
  port?: number;
@@ -18,17 +18,12 @@ export function createDevServer(
18
18
  console.log(
19
19
  `[apifuse dev] ${provider.id}@${provider.version} running at http://localhost:${port}`,
20
20
  );
21
- console.log(
22
- `[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`,
23
- );
21
+ console.log(`[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`);
24
22
  console.log(`[apifuse dev] Health: http://localhost:${port}/health`);
25
23
  },
26
24
  };
27
25
  }
28
26
 
29
- export function startDevServer(
30
- provider: ProviderDefinition,
31
- options?: DevServerOptions,
32
- ): void {
27
+ export function startDevServer(provider: ProviderDefinition, options?: DevServerOptions): void {
33
28
  createDevServer(provider, options).start();
34
29
  }
package/src/errors.ts CHANGED
@@ -1,4 +1,41 @@
1
- import type { ProviderErrorCategory } from "./observability";
1
+ import type { ProviderErrorCategory } from "./observability.js";
2
+
3
+ // Versioned, cross-realm brands. `Symbol.for` resolves to the same symbol in
4
+ // any copy/entrypoint of this SDK major version, so an error created by a
5
+ // duplicate module instance (e.g. the packaged CLI's src/* server vs a
6
+ // provider's dist/* import) still carries a brand the server can recognize even
7
+ // though `instanceof` splits across the two constructors. The `@1` suffix lets a
8
+ // future breaking change to this contract mint a distinct key.
9
+ const PROVIDER_ERROR_BRAND = Symbol.for("@apifuse/provider-sdk/error-brand@1");
10
+ const PROVIDER_ERROR_BRAND_VALUE = 1;
11
+ const SESSION_EXPIRED_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/session-expired@1");
12
+ const TRANSPORT_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/transport@1");
13
+
14
+ // Defines a non-enumerable, non-writable, non-configurable own data property.
15
+ // Immutable + own means a guard can trust it via a single descriptor read
16
+ // without invoking attacker-controlled getters or accepting inherited brands.
17
+ function defineErrorBrand(target: object, brand: symbol, value: number | true): void {
18
+ Object.defineProperty(target, brand, {
19
+ value,
20
+ enumerable: false,
21
+ writable: false,
22
+ configurable: false,
23
+ });
24
+ }
25
+
26
+ // Recognizes an own data-property brand with the expected value. Rejects
27
+ // missing brands (unbranded lookalikes), accessor brands (no own `value`
28
+ // slot — the getter is never called), and inherited brands (own-descriptor
29
+ // lookup returns undefined on the child).
30
+ function hasOwnBrand(value: unknown, brand: symbol, expected: number | true): boolean {
31
+ if (value === null || (typeof value !== "object" && typeof value !== "function")) {
32
+ return false;
33
+ }
34
+ const descriptor = Object.getOwnPropertyDescriptor(value, brand);
35
+ return (
36
+ descriptor !== undefined && Object.hasOwn(descriptor, "value") && descriptor.value === expected
37
+ );
38
+ }
2
39
 
3
40
  export type ProviderErrorOptions = {
4
41
  fix?: string;
@@ -19,6 +56,7 @@ export class ProviderError extends Error {
19
56
  if (options?.cause) {
20
57
  this.cause = options.cause;
21
58
  }
59
+ defineErrorBrand(this, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
22
60
  }
23
61
 
24
62
  get fix(): string | undefined {
@@ -49,10 +87,7 @@ export class AuthError extends ProviderError {
49
87
  }
50
88
 
51
89
  export class SessionExpiredError extends AuthError {
52
- constructor(
53
- message = "Provider session expired",
54
- options?: ProviderErrorOptions,
55
- ) {
90
+ constructor(message = "Provider session expired", options?: ProviderErrorOptions) {
56
91
  super(message, {
57
92
  code: "reauth_required",
58
93
  category: "credential_expired",
@@ -60,6 +95,7 @@ export class SessionExpiredError extends AuthError {
60
95
  ...options,
61
96
  });
62
97
  this.name = "SessionExpiredError";
98
+ defineErrorBrand(this, SESSION_EXPIRED_BRAND, true);
63
99
  }
64
100
  }
65
101
 
@@ -91,9 +127,26 @@ export class TransportError extends ProviderError {
91
127
  this.name = "TransportError";
92
128
  this.status = options?.status;
93
129
  this.upstreamStatus = options?.upstreamStatus ?? options?.status;
130
+ defineErrorBrand(this, TRANSPORT_BRAND, true);
94
131
  }
95
132
  }
96
133
 
134
+ // Cross-module type guards. Prefer these over `instanceof` at any boundary that
135
+ // may receive an error from a different copy/entrypoint of the SDK (see the HTTP
136
+ // server error boundary). They recognize branded errors regardless of which
137
+ // module instance constructed them, while rejecting unbranded lookalikes.
138
+ export function isProviderError(value: unknown): value is ProviderError {
139
+ return hasOwnBrand(value, PROVIDER_ERROR_BRAND, PROVIDER_ERROR_BRAND_VALUE);
140
+ }
141
+
142
+ export function isSessionExpiredError(value: unknown): value is SessionExpiredError {
143
+ return isProviderError(value) && hasOwnBrand(value, SESSION_EXPIRED_BRAND, true);
144
+ }
145
+
146
+ export function isTransportError(value: unknown): value is TransportError {
147
+ return isProviderError(value) && hasOwnBrand(value, TRANSPORT_BRAND, true);
148
+ }
149
+
97
150
  export class ProviderSecretError extends ProviderError {
98
151
  constructor(message: string, options?: ProviderErrorOptions) {
99
152
  super(message, { code: "provider_secret_error", ...options });
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
 
4
- import type { AuthTurn } from "../types";
4
+ import type { AuthTurn } from "../types.js";
5
5
  import {
6
6
  getProviderLocalePath,
7
7
  isProviderLocaleValue,
@@ -10,12 +10,9 @@ import {
10
10
  type ProviderLocaleKey,
11
11
  type ProviderLocaleValue,
12
12
  providerLocaleKey,
13
- } from "./keys";
13
+ } from "./keys.js";
14
14
 
15
- export type ProviderLocaleCatalogMap = Record<
16
- ProviderLocale,
17
- ProviderLocaleCatalog
18
- >;
15
+ export type ProviderLocaleCatalogMap = Record<ProviderLocale, ProviderLocaleCatalog>;
19
16
 
20
17
  export interface LoadProviderLocaleCatalogsOptions {
21
18
  providerDir: string;
@@ -58,9 +55,7 @@ export function resolveProviderLocaleValue(
58
55
  );
59
56
  }
60
57
 
61
- function asStringValue(
62
- value: ProviderLocaleValue | undefined,
63
- ): string | undefined {
58
+ function asStringValue(value: ProviderLocaleValue | undefined): string | undefined {
64
59
  return typeof value === "string" ? value : undefined;
65
60
  }
66
61
 
@@ -82,9 +77,7 @@ function localizeAuthInputSchema(
82
77
  },
83
78
  ): Record<string, unknown> | undefined {
84
79
  if (!expectedInput) return undefined;
85
- const schema = isRecord(expectedInput.schema)
86
- ? expectedInput.schema
87
- : expectedInput;
80
+ const schema = isRecord(expectedInput.schema) ? expectedInput.schema : expectedInput;
88
81
  const localizedSchema = localizeAuthSchemaObject(schema, options);
89
82
  if (localizedSchema === schema) return undefined;
90
83
  return isRecord(expectedInput.schema)
@@ -104,21 +97,16 @@ function localizeAuthSchemaObject(
104
97
  fallbackLocale: ProviderLocale;
105
98
  },
106
99
  ): Record<string, unknown> {
107
- const properties = isRecord(schema.properties)
108
- ? schema.properties
109
- : undefined;
100
+ const properties = isRecord(schema.properties) ? schema.properties : undefined;
110
101
  if (!properties) return schema;
111
102
 
112
103
  let changed = false;
113
104
  const localizedProperties = Object.fromEntries(
114
105
  Object.entries(properties).map(([fieldName, property]) => {
115
106
  if (!isRecord(property)) return [fieldName, property];
116
- const nameKey =
117
- typeof property.nameKey === "string" ? property.nameKey : undefined;
107
+ const nameKey = typeof property.nameKey === "string" ? property.nameKey : undefined;
118
108
  const descriptionKey =
119
- typeof property.descriptionKey === "string"
120
- ? property.descriptionKey
121
- : undefined;
109
+ typeof property.descriptionKey === "string" ? property.descriptionKey : undefined;
122
110
  const title = nameKey
123
111
  ? asStringValue(
124
112
  resolveProviderLocaleValue(
@@ -166,12 +154,7 @@ export function localizeAuthTurn(
166
154
  const fallbackLocale = options.fallbackLocale ?? "en";
167
155
  const hint = turn.hintKey
168
156
  ? asStringValue(
169
- resolveProviderLocaleValue(
170
- options.catalogs,
171
- turn.hintKey,
172
- options.locale,
173
- fallbackLocale,
174
- ),
157
+ resolveProviderLocaleValue(options.catalogs, turn.hintKey, options.locale, fallbackLocale),
175
158
  )
176
159
  : undefined;
177
160
  const expectedInput = localizeAuthInputSchema(turn.expectedInput, {
@@ -184,12 +167,7 @@ export function localizeAuthTurn(
184
167
  ? Object.fromEntries(
185
168
  Object.entries(fieldErrorKeys).flatMap(([fieldName, key]) => {
186
169
  const message = asStringValue(
187
- resolveProviderLocaleValue(
188
- options.catalogs,
189
- key,
190
- options.locale,
191
- fallbackLocale,
192
- ),
170
+ resolveProviderLocaleValue(options.catalogs, key, options.locale, fallbackLocale),
193
171
  );
194
172
  return message ? [[fieldName, message]] : [];
195
173
  }),
package/src/i18n/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./catalog";
2
- export * from "./keys";
1
+ export * from "./catalog.js";
2
+ export * from "./keys.js";
package/src/i18n/keys.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ProviderLocaleKey } from "../types";
1
+ import type { ProviderLocaleKey } from "../types.js";
2
2
 
3
- export type { ProviderLocale, ProviderLocaleKey } from "../types";
3
+ export type { ProviderLocale, ProviderLocaleKey } from "../types.js";
4
4
 
5
5
  const PROVIDER_LOCALE_KEY_RE =
6
6
  /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]+)*(?:\.[a-z][a-z0-9]*(?:[A-Z][a-z0-9]+)*|\.[0-9]+)*$/;
@@ -10,15 +10,11 @@ export function providerLocaleKey(key: string): ProviderLocaleKey {
10
10
  return key;
11
11
  }
12
12
 
13
- export function isProviderLocaleKey(
14
- value: unknown,
15
- ): value is ProviderLocaleKey {
13
+ export function isProviderLocaleKey(value: unknown): value is ProviderLocaleKey {
16
14
  return typeof value === "string" && PROVIDER_LOCALE_KEY_RE.test(value);
17
15
  }
18
16
 
19
- export function assertProviderLocaleKey(
20
- value: unknown,
21
- ): asserts value is ProviderLocaleKey {
17
+ export function assertProviderLocaleKey(value: unknown): asserts value is ProviderLocaleKey {
22
18
  if (!isProviderLocaleKey(value)) {
23
19
  throw new Error(
24
20
  `Provider locale key must be a dot path such as "meta.description" or "operations.search.description"; received ${JSON.stringify(value)}`,
@@ -50,9 +46,7 @@ export function getProviderLocalePath(
50
46
  export type ProviderLocaleValue = string | readonly string[];
51
47
  export type ProviderLocaleCatalog = Record<string, unknown>;
52
48
 
53
- export function isProviderLocaleValue(
54
- value: unknown,
55
- ): value is ProviderLocaleValue {
49
+ export function isProviderLocaleValue(value: unknown): value is ProviderLocaleValue {
56
50
  return (
57
51
  typeof value === "string" ||
58
52
  (Array.isArray(value) && value.every((entry) => typeof entry === "string"))
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  // @apifuse/provider-sdk
2
2
 
3
- export * from "./auth";
4
- export * from "./ceremonies";
5
- export * from "./choice-token";
3
+ export * from "./auth.js";
4
+ export * from "./ceremonies/index.js";
5
+ export * from "./choice-token.js";
6
6
  export type {
7
7
  ApiFuseConfig,
8
8
  BrowserConfig,
9
9
  ProxyConfig,
10
10
  SessionConfig,
11
- } from "./config/loader";
12
- export { defineConfig, loadApiFuseConfig } from "./config/loader";
11
+ } from "./config/loader.js";
12
+ export { defineConfig, loadApiFuseConfig } from "./config/loader.js";
13
13
  export {
14
14
  canonicalJson,
15
15
  digestProviderContract,
@@ -19,7 +19,7 @@ export {
19
19
  PROVIDER_CONTRACT_SCHEMA_VERSION,
20
20
  type ProviderContractOperation,
21
21
  type ProviderContractSnapshot,
22
- } from "./contract";
22
+ } from "./contract.js";
23
23
  export {
24
24
  centered,
25
25
  delayed,
@@ -30,54 +30,60 @@ export {
30
30
  defineStreamOperation,
31
31
  every,
32
32
  type ProviderConfig,
33
- } from "./define";
34
- export type { DevServerOptions } from "./dev";
35
- export { createDevServer, startDevServer } from "./dev";
36
- export * from "./errors";
37
- export * from "./i18n";
33
+ } from "./define.js";
34
+ export type { DevServerOptions } from "./dev.js";
35
+ export { createDevServer, startDevServer } from "./dev.js";
36
+ export * from "./errors.js";
37
+ export * from "./user-input.js";
38
+ export * from "./i18n/index.js";
38
39
  export {
39
40
  type LintDiagnostic,
40
41
  lintOperation,
41
42
  lintProvider,
42
- } from "./lint";
43
- export * from "./recipes/gov-api";
44
- export * from "./recipes/rest-api";
45
- export { createFlowContext, createScratchpad } from "./runtime/auth-flow";
46
- export type { BrowserClientOptions } from "./runtime/browser";
47
- export { BrowserClient, createBrowserClient } from "./runtime/browser";
43
+ } from "./lint.js";
44
+ export * from "./recipes/gov-api.js";
45
+ export * from "./recipes/rest-api.js";
46
+ export { createFlowContext, createScratchpad } from "./runtime/auth-flow.js";
47
+ export type { BrowserClientOptions } from "./runtime/browser.js";
48
+ export { BrowserClient, createBrowserClient } from "./runtime/browser.js";
48
49
  export {
49
50
  createBypassProviderCache,
50
51
  createProviderCache,
51
52
  type ProviderCacheOptions,
52
53
  resetProviderCacheForTests,
53
- } from "./runtime/cache";
54
+ } from "./runtime/cache.js";
54
55
  export {
55
56
  type CreateProviderChoiceContextOptions,
56
57
  createProviderChoiceContext,
57
58
  createTestProviderChoiceContext,
58
59
  PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV,
59
- } from "./runtime/choice";
60
+ } from "./runtime/choice.js";
60
61
  export {
61
62
  type CreateCredentialContextOptions,
62
63
  createCredentialContext,
63
- } from "./runtime/credential";
64
- export { createEnvContext } from "./runtime/env";
65
- export { executeOperation } from "./runtime/executor";
66
- export { createHttpClient } from "./runtime/http";
67
- export type { Insight, InsightSeverity } from "./runtime/insights";
68
- export { generateInsights } from "./runtime/insights";
64
+ } from "./runtime/credential.js";
65
+ export { createEnvContext } from "./runtime/env.js";
66
+ export { executeOperation } from "./runtime/executor.js";
67
+ export { createHttpClient } from "./runtime/http.js";
68
+ export type { Insight, InsightSeverity } from "./runtime/insights.js";
69
+ export { generateInsights } from "./runtime/insights.js";
69
70
  export {
70
71
  type InstrumentationOptions,
71
72
  type InstrumentedProviderContext,
72
73
  wrapWithInstrumentation,
73
- } from "./runtime/instrumentation";
74
- export { type PrevalidateResult, prevalidate } from "./runtime/prevalidate";
75
- export { getProviderBaseUrl } from "./runtime/provider";
74
+ } from "./runtime/instrumentation.js";
75
+ export { type PrevalidateResult, prevalidate } from "./runtime/prevalidate.js";
76
+ export { getProviderBaseUrl } from "./runtime/provider.js";
77
+ export {
78
+ assertRequiredSecretsPresent,
79
+ listMissingRequiredSecrets,
80
+ MISSING_SECRET_CODE,
81
+ } from "./runtime/secrets.js";
76
82
  export {
77
83
  createUnsupportedProviderRuntimeState,
78
84
  UnsupportedProviderStateError,
79
- } from "./runtime/state";
80
- export { createStealthClient } from "./runtime/stealth";
85
+ } from "./runtime/state.js";
86
+ export { createStealthClient } from "./runtime/stealth.js";
81
87
  export {
82
88
  APIFUSE__STT__BACKEND_ENV,
83
89
  APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV,
@@ -86,13 +92,13 @@ export {
86
92
  createUnsupportedSttClient,
87
93
  extractVerificationCode,
88
94
  resolveSttPrompt,
89
- } from "./runtime/stt";
95
+ } from "./runtime/stt.js";
90
96
  export {
91
97
  type CreateTraceContextOptions,
92
98
  createTraceContext,
93
99
  type Span,
94
100
  type TraceContext,
95
- } from "./runtime/trace";
101
+ } from "./runtime/trace.js";
96
102
  export {
97
103
  APIFUSE_DESCRIPTION_KEY_META_KEY,
98
104
  APIFUSE_REDACTION_MARKER,
@@ -109,10 +115,10 @@ export {
109
115
  type SensitivePath,
110
116
  sensitive,
111
117
  z,
112
- } from "./schema";
113
- export { createServerApp, type ServeOptions, serve } from "./server";
114
- export { getStealthProfile, listStealthProfiles } from "./stealth/profiles";
115
- export * from "./stream";
118
+ } from "./schema.js";
119
+ export { createServerApp, type ServeOptions, serve } from "./server/index.js";
120
+ export { getStealthProfile, listStealthProfiles } from "./stealth/profiles.js";
121
+ export * from "./stream.js";
116
122
  export type {
117
123
  ApiFuseResponse,
118
124
  AuthConfig,
@@ -201,6 +207,7 @@ export type {
201
207
  ProviderChoiceParseOptions,
202
208
  ProviderContext,
203
209
  ProviderDefinition,
210
+ ProviderDeploymentOverrides,
204
211
  ProviderHealthMonitorConfig,
205
212
  ProviderHealthProbeConfig,
206
213
  ProviderLocale,
@@ -263,7 +270,7 @@ export type {
263
270
  VerificationCodeCandidate,
264
271
  VerificationCodeCandidateSource,
265
272
  VerificationCodeExtractionResult,
266
- } from "./types";
273
+ } from "./types.js";
267
274
  export {
268
275
  DEFAULT_OPERATION_TRANSPORT,
269
276
  HttpRetryAfterPolicy,
@@ -280,8 +287,8 @@ export {
280
287
  STREAM_IDLE_TIMEOUT_MS_MIN,
281
288
  STREAM_MAX_DURATION_MS_MAX,
282
289
  STREAM_MAX_DURATION_MS_MIN,
283
- } from "./types";
284
- export * from "./utils/date";
285
- export * from "./utils/parse";
286
- export * from "./utils/text";
287
- export * from "./utils/transform";
290
+ } from "./types.js";
291
+ export * from "./utils/date.js";
292
+ export * from "./utils/parse.js";
293
+ export * from "./utils/text.js";
294
+ export * from "./utils/transform.js";