@apifuse/provider-sdk 2.2.0-beta.62 → 2.2.0-beta.63

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 (243) hide show
  1. package/AUTHORING.md +268 -9
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +1 -0
  4. package/bin/apifuse-check.ts +84 -2
  5. package/bin/apifuse-dev.ts +11 -31
  6. package/bin/apifuse-migrate-deployment.ts +200 -0
  7. package/bin/apifuse-pack-check.ts +11 -4
  8. package/bin/apifuse-pack-types.ts +187 -4
  9. package/bin/apifuse-record.ts +44 -32
  10. package/bin/apifuse-test.ts +3 -1
  11. package/dist/cli/commands.d.ts +1 -1
  12. package/dist/cli/commands.js +11 -0
  13. package/dist/cli/deployment-intent.d.ts +178 -0
  14. package/dist/cli/deployment-intent.js +277 -0
  15. package/dist/cli/migrate-deployment-intent.d.ts +132 -0
  16. package/dist/cli/migrate-deployment-intent.js +1552 -0
  17. package/dist/cli/migrate-provider-shape.d.ts +5 -1
  18. package/dist/cli/migrate-provider-shape.js +4 -2
  19. package/dist/cli/resolver-runtime.d.ts +21 -0
  20. package/dist/cli/resolver-runtime.js +31 -0
  21. package/dist/define.d.ts +3 -0
  22. package/dist/define.js +5 -0
  23. package/dist/dev.d.ts +3 -1
  24. package/dist/dev.js +6 -1
  25. package/dist/engine.d.ts +35 -1
  26. package/dist/engine.js +21 -2
  27. package/dist/error-resolution.d.ts +1 -0
  28. package/dist/error-resolution.js +54 -0
  29. package/dist/errors.d.ts +39 -1
  30. package/dist/errors.js +50 -0
  31. package/dist/i18n/error-messages.d.ts +86 -0
  32. package/dist/i18n/error-messages.js +192 -0
  33. package/dist/i18n/index.d.ts +1 -0
  34. package/dist/i18n/index.js +1 -0
  35. package/dist/i18n/keys.d.ts +12 -0
  36. package/dist/i18n/keys.js +76 -5
  37. package/dist/index.d.ts +7 -1
  38. package/dist/index.js +6 -0
  39. package/dist/lint.d.ts +10 -0
  40. package/dist/lint.js +412 -49
  41. package/dist/provider.d.ts +5 -5
  42. package/dist/provider.js +2 -2
  43. package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
  44. package/dist/runtime/browser-telemetry-binding.js +83 -0
  45. package/dist/runtime/browser-telemetry.d.ts +76 -0
  46. package/dist/runtime/browser-telemetry.js +165 -0
  47. package/dist/runtime/browser.d.ts +3 -0
  48. package/dist/runtime/browser.js +208 -47
  49. package/dist/runtime/cache-telemetry.d.ts +71 -0
  50. package/dist/runtime/cache-telemetry.js +177 -0
  51. package/dist/runtime/cache.js +67 -7
  52. package/dist/runtime/capability-response.d.ts +3 -0
  53. package/dist/runtime/capability-response.js +56 -0
  54. package/dist/runtime/capability-telemetry.d.ts +46 -0
  55. package/dist/runtime/capability-telemetry.js +68 -0
  56. package/dist/runtime/diagnostic-env.d.ts +3 -0
  57. package/dist/runtime/diagnostic-env.js +10 -1
  58. package/dist/runtime/engine-mode.d.ts +74 -0
  59. package/dist/runtime/engine-mode.js +152 -0
  60. package/dist/runtime/http-telemetry-guard.d.ts +10 -0
  61. package/dist/runtime/http-telemetry-guard.js +62 -10
  62. package/dist/runtime/http.js +141 -35
  63. package/dist/runtime/instrumentation.js +92 -13
  64. package/dist/runtime/ocr-telemetry.d.ts +82 -0
  65. package/dist/runtime/ocr-telemetry.js +192 -0
  66. package/dist/runtime/ocr.js +30 -8
  67. package/dist/runtime/request-telemetry.d.ts +2 -0
  68. package/dist/runtime/request-telemetry.js +2 -1
  69. package/dist/runtime/resolver-runtime-options.d.ts +14 -0
  70. package/dist/runtime/resolver-runtime-options.js +33 -0
  71. package/dist/runtime/resolver-shared.d.ts +3 -2
  72. package/dist/runtime/resolver-shared.js +4 -4
  73. package/dist/runtime/resolver-telemetry.d.ts +1 -0
  74. package/dist/runtime/resolver-telemetry.js +1 -1
  75. package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
  76. package/dist/runtime/resolver-vendors/browser.js +46 -0
  77. package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
  78. package/dist/runtime/resolver-vendors/hosts.js +35 -0
  79. package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
  80. package/dist/runtime/resolver-vendors/types.d.ts +5 -4
  81. package/dist/runtime/resolver.d.ts +4 -1
  82. package/dist/runtime/resolver.js +46 -13
  83. package/dist/runtime/state-telemetry.d.ts +79 -0
  84. package/dist/runtime/state-telemetry.js +194 -0
  85. package/dist/runtime/state.d.ts +3 -0
  86. package/dist/runtime/state.js +26 -7
  87. package/dist/runtime/stealth-cookies.d.ts +5 -1
  88. package/dist/runtime/stealth-cookies.js +21 -1
  89. package/dist/runtime/stealth-owned-headers.d.ts +26 -0
  90. package/dist/runtime/stealth-owned-headers.js +37 -0
  91. package/dist/runtime/stealth-telemetry.d.ts +92 -0
  92. package/dist/runtime/stealth-telemetry.js +179 -0
  93. package/dist/runtime/stealth.d.ts +4 -1
  94. package/dist/runtime/stealth.js +228 -85
  95. package/dist/runtime/stt-telemetry.d.ts +77 -0
  96. package/dist/runtime/stt-telemetry.js +176 -0
  97. package/dist/runtime/stt.js +15 -6
  98. package/dist/server/error-stack-frames.d.ts +35 -0
  99. package/dist/server/error-stack-frames.js +219 -0
  100. package/dist/server/index.d.ts +7 -0
  101. package/dist/server/index.js +4 -0
  102. package/dist/server/sdk-version.d.ts +3 -0
  103. package/dist/server/sdk-version.js +19 -0
  104. package/dist/server/self-test.js +1 -18
  105. package/dist/server/sensitive-values.d.ts +1 -1
  106. package/dist/server/sensitive-values.js +9 -0
  107. package/dist/server/serve-implementation.d.ts +51 -2
  108. package/dist/server/serve-implementation.js +337 -90
  109. package/dist/server/types.d.ts +1 -0
  110. package/dist/server/types.js +7 -0
  111. package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
  112. package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
  113. package/dist/stateful/stateful-provider-runtime-context.js +1 -0
  114. package/dist/types.d.ts +94 -1
  115. package/package.json +6 -1
  116. package/src/cli/commands.ts +14 -0
  117. package/src/cli/deployment-intent.ts +364 -0
  118. package/src/cli/migrate-deployment-intent.ts +1908 -0
  119. package/src/cli/migrate-provider-shape.ts +10 -4
  120. package/src/cli/resolver-runtime.ts +72 -0
  121. package/src/define.ts +13 -0
  122. package/src/dev.ts +9 -2
  123. package/src/engine.ts +38 -2
  124. package/src/error-resolution.ts +58 -0
  125. package/src/errors.ts +77 -1
  126. package/src/i18n/error-messages.ts +255 -0
  127. package/src/i18n/index.ts +1 -0
  128. package/src/i18n/keys.ts +80 -6
  129. package/src/index.ts +72 -0
  130. package/src/lint.ts +522 -50
  131. package/src/provider.ts +10 -0
  132. package/src/runtime/browser-telemetry-binding.ts +92 -0
  133. package/src/runtime/browser-telemetry.ts +289 -0
  134. package/src/runtime/browser.ts +249 -65
  135. package/src/runtime/cache-telemetry.ts +247 -0
  136. package/src/runtime/cache.ts +68 -17
  137. package/src/runtime/capability-response.ts +53 -0
  138. package/src/runtime/capability-telemetry.ts +101 -0
  139. package/src/runtime/diagnostic-env.ts +11 -1
  140. package/src/runtime/engine-mode.ts +233 -0
  141. package/src/runtime/http-telemetry-guard.ts +66 -13
  142. package/src/runtime/http.ts +168 -37
  143. package/src/runtime/instrumentation.ts +105 -16
  144. package/src/runtime/ocr-telemetry.ts +308 -0
  145. package/src/runtime/ocr.ts +109 -74
  146. package/src/runtime/request-telemetry.ts +2 -1
  147. package/src/runtime/resolver-runtime-options.ts +50 -0
  148. package/src/runtime/resolver-shared.ts +9 -4
  149. package/src/runtime/resolver-telemetry.ts +1 -1
  150. package/src/runtime/resolver-vendors/browser.ts +65 -7
  151. package/src/runtime/resolver-vendors/hosts.ts +43 -0
  152. package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
  153. package/src/runtime/resolver-vendors/types.ts +5 -4
  154. package/src/runtime/resolver.ts +64 -21
  155. package/src/runtime/state-telemetry.ts +298 -0
  156. package/src/runtime/state.ts +46 -45
  157. package/src/runtime/stealth-cookies.ts +24 -1
  158. package/src/runtime/stealth-owned-headers.ts +41 -0
  159. package/src/runtime/stealth-telemetry.ts +304 -0
  160. package/src/runtime/stealth.ts +355 -150
  161. package/src/runtime/stt-telemetry.ts +282 -0
  162. package/src/runtime/stt.ts +93 -71
  163. package/src/server/error-stack-frames.ts +214 -0
  164. package/src/server/index.ts +53 -0
  165. package/src/server/sdk-version.ts +22 -0
  166. package/src/server/self-test.ts +1 -21
  167. package/src/server/sensitive-values.ts +14 -0
  168. package/src/server/serve-implementation.ts +569 -108
  169. package/src/server/types.ts +7 -0
  170. package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
  171. package/src/stateful/stateful-provider-runtime-context.ts +4 -0
  172. package/src/types.ts +99 -1
  173. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
  174. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
  175. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
  176. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
  177. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
  178. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
  179. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
  180. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
  181. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
  182. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
  183. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
  184. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
  185. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
  186. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
  187. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
  188. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
  189. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
  190. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
  191. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
  192. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
  193. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
  194. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
  195. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
  196. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
  197. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
  198. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
  199. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
  200. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
  201. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
  202. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
  203. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
  204. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
  205. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
  206. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
  207. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
  208. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
  209. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
  210. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
  211. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
  212. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
  213. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
  214. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
  215. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
  216. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
  217. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
  218. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
  219. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
  220. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
  221. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
  222. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +0 -12
@@ -24,7 +24,11 @@ export type ProviderShapeKind =
24
24
  "single-phase-default-export"
25
25
  /** `const p = defineProvider({ ..., operations }); export default p;` */
26
26
  | "single-phase-variable-export"
27
- /** `const p = defineProvider({ ..., operations }); export default { ...p, deployment };` */
27
+ /**
28
+ * `const p = defineProvider({ ..., operations }); export default { ...p, extra };`
29
+ * — extras stay on the spread export; a `deployment` extra is a legacy
30
+ * surface that `apifuse migrate-deployment` hoists into the declaration.
31
+ */
28
32
  | "single-phase-variable-spread-export"
29
33
  /** Already `const b = defineProvider(...); export default b({ operations })` */
30
34
  | "two-phase";
@@ -218,7 +218,7 @@ function defaultExportCallsBuilder(exportAssignment, declarationCall) {
218
218
  * resolves to a builder-call result. Covers the three migrated layouts —
219
219
  * `export default buildProvider({...})`, an intermediate
220
220
  * `const provider = buildProvider({...}); export default provider;`, and the
221
- * spread export `export default { ...provider, deployment }` over such a
221
+ * spread export `export default { ...provider, ...extras }` over such a
222
222
  * binding. Without the latter two, re-running the transform on its own
223
223
  * spread-shape output reports "ambiguous" instead of "unchanged", which
224
224
  * breaks idempotency for repeated fan-out runs.
@@ -376,7 +376,9 @@ function rewriteDefaultExport(source, exportAssignment, shape, builderName, oper
376
376
  ];
377
377
  }
378
378
  // Spread export: re-introduce the provider binding so the extra properties
379
- // (currently `deployment`) still spread over a built provider.
379
+ // (e.g. `healthAccountSeedInputs`, or a legacy `deployment` that
380
+ // `apifuse migrate-deployment` later hoists) still spread over a built
381
+ // provider.
380
382
  const providerName = shape.variableName ?? "provider";
381
383
  const extras = shape.spreadExportExtras ?? "";
382
384
  const rebuilt = extras.length > 0
@@ -0,0 +1,21 @@
1
+ import { ResolverTelemetryCollector } from "../runtime/resolver-telemetry.js";
2
+ import type { ProviderCache, ProviderDefinition, ResolverContext } from "../types.js";
3
+ export interface CliResolverRuntime {
4
+ readonly resolver: ResolverContext;
5
+ /** Per-context sink; `toLogPayload()` is the `resolver` sibling of the server request log. */
6
+ readonly resolverTelemetry: ResolverTelemetryCollector;
7
+ /**
8
+ * Extend the collector's redaction with values learned after construction (request-scoped
9
+ * `sensitiveParams` the recorder captures); the collector redacts at record time, before it
10
+ * truncates, so values must be registered before the vendor call that may echo them.
11
+ */
12
+ readonly registerSensitiveValues: (values: readonly string[]) => void;
13
+ }
14
+ /**
15
+ * Resolver chain for the CLI helper contexts (`apifuse record`, the `apifuse dev` helper), built
16
+ * like a server request scope: engine-owned solver keys, the CDP pool URL, and the resolver
17
+ * timeout come from the process environment, the runtime options come from the shared builder,
18
+ * and every vendor invocation lands in a collector redacted with the provider's static sensitive
19
+ * inventory. A CLI context has no server-owned identity scope and no proxy telemetry.
20
+ */
21
+ export declare function createCliResolverRuntime(provider: ProviderDefinition, cache: ProviderCache): CliResolverRuntime;
@@ -0,0 +1,31 @@
1
+ import { compileProcessDiagnosticSensitiveValues, createDiagnosticRedactor, } from "../runtime/diagnostic-redactor.js";
2
+ import { createResolverClientFromEnv, createUnsupportedResolverClient, } from "../runtime/resolver.js";
3
+ import { createResolverRuntimeOptions, resolveNativeProxyPolicy, } from "../runtime/resolver-runtime-options.js";
4
+ import { ResolverTelemetryCollector } from "../runtime/resolver-telemetry.js";
5
+ import { collectStaticDiagnosticSensitiveValues } from "../server/sensitive-values.js";
6
+ import { getStealthProfile } from "../stealth/profiles.js";
7
+ /**
8
+ * Resolver chain for the CLI helper contexts (`apifuse record`, the `apifuse dev` helper), built
9
+ * like a server request scope: engine-owned solver keys, the CDP pool URL, and the resolver
10
+ * timeout come from the process environment, the runtime options come from the shared builder,
11
+ * and every vendor invocation lands in a collector redacted with the provider's static sensitive
12
+ * inventory. A CLI context has no server-owned identity scope and no proxy telemetry.
13
+ */
14
+ export function createCliResolverRuntime(provider, cache) {
15
+ const sensitiveValues = createDiagnosticRedactor([], compileProcessDiagnosticSensitiveValues(collectStaticDiagnosticSensitiveValues(provider)));
16
+ const resolverTelemetry = new ResolverTelemetryCollector({ redact: sensitiveValues.redact });
17
+ const registerSensitiveValues = (values) => sensitiveValues.add(values);
18
+ if (!provider.resolver) {
19
+ return {
20
+ resolver: createUnsupportedResolverClient("Provider does not declare resolver capability"),
21
+ resolverTelemetry,
22
+ registerSensitiveValues,
23
+ };
24
+ }
25
+ const stealthProfile = provider.stealth ? getStealthProfile(provider.stealth) : undefined;
26
+ return {
27
+ resolver: createResolverClientFromEnv(provider.resolver, process.env, createResolverRuntimeOptions(provider, cache, undefined, resolveNativeProxyPolicy(provider), { upstream: { proxy: provider.proxy } }, stealthProfile, resolverTelemetry)),
28
+ resolverTelemetry,
29
+ registerSensitiveValues,
30
+ };
31
+ }
package/dist/define.d.ts CHANGED
@@ -54,6 +54,9 @@ export interface ProviderDeclaration {
54
54
  * provider definition. The SDK types this field but does not deep-validate
55
55
  * it — the APIFuse registry builder owns deployment validation and
56
56
  * resolves omitted fields against the runtime deployment profiles.
57
+ *
58
+ * This is the only authored deployment surface (no standalone
59
+ * `deploy.ts`); declare only the fields that differ from the profile.
57
60
  */
58
61
  deployment?: ProviderDeploymentOverrides;
59
62
  /** Declares the HTTP capability binding. A bare object states use without configuration. */
package/dist/define.js CHANGED
@@ -636,6 +636,11 @@ function validateProviderImplementationShape(config) {
636
636
  }
637
637
  function validateProviderProxy(config) {
638
638
  for (const secret of config.secrets ?? []) {
639
+ if (secret.issuer !== undefined &&
640
+ secret.issuer !== "apifuse" &&
641
+ secret.issuer !== "contributor") {
642
+ throw new ValidationError(`Provider "${config.id}" secret "${secret.name}" has invalid issuer "${String(secret.issuer)}"`, { fix: `Set issuer to "apifuse" or "contributor", or omit it.` });
643
+ }
639
644
  const engineName = engineOwnedResolverCredentialTarget(secret.name);
640
645
  if (engineName !== undefined) {
641
646
  throw new ValidationError(`Provider "${config.id}" cannot declare engine-owned resolver credential "${secret.name}"`, {
package/dist/dev.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import type { ProviderEngine } from "./engine.js";
1
+ import type { ProviderEngine, ProviderEngineMode } from "./engine.js";
2
2
  import type { ProviderDefinition } from "./types.js";
3
3
  export interface DevServerOptions {
4
4
  port?: number;
5
5
  sessionDbPath?: string;
6
6
  /** Override the default in-process engine attachment. */
7
7
  engine?: ProviderEngine;
8
+ /** Explicit engine mode; `APIFUSE__ENGINE__MODE` outranks it when both are set. */
9
+ engineMode?: ProviderEngineMode;
8
10
  }
9
11
  export declare function createDevServer(provider: ProviderDefinition, options?: DevServerOptions): {
10
12
  start: () => void;
package/dist/dev.js CHANGED
@@ -5,7 +5,12 @@ export function createDevServer(provider, options) {
5
5
  start: () => {
6
6
  // Local development has no Redis by default; handles (ADR-0012) need a
7
7
  // state backend, so fall back to memory state when none is configured.
8
- void serve(provider, { port, engine: options?.engine, allowMemoryStateFallback: true });
8
+ void serve(provider, {
9
+ port,
10
+ engine: options?.engine,
11
+ engineMode: options?.engineMode,
12
+ allowMemoryStateFallback: true,
13
+ });
9
14
  console.log(`[apifuse dev] ${provider.id}@${provider.version} running at http://localhost:${port}`);
10
15
  console.log(`[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`);
11
16
  console.log(`[apifuse dev] Health: http://localhost:${port}/health`);
package/dist/engine.d.ts CHANGED
@@ -2,6 +2,25 @@ import type { HandleContext } from "./handle.js";
2
2
  import type { AuthContext, BrowserClient, CredentialContext, EnvContext, HttpClient, NativeContext, OcrContext, ProviderCache, ProviderContext, ProviderDefinition, ProviderFilesContext, ProviderRequestContext, ProviderRuntimeState, ResolverContext, StealthClient, SttContext, TraceContext } from "./types.js";
3
3
  /** Versioned envelope protocol used by out-of-process engine transports. */
4
4
  export declare const PROVIDER_ENGINE_PROTOCOL_VERSION: "provider-engine.v1";
5
+ /**
6
+ * Environment variable that selects how a provider process attaches its capability
7
+ * bindings. Engine-owned by prefix (`APIFUSE__ENGINE__*`): never declarable as a
8
+ * provider secret and never projected into `ctx.env`.
9
+ *
10
+ * Values are trimmed and case-folded; absent or blank means "unset". An
11
+ * unrecognized value is reported on the `provider_engine_mode` boot event and
12
+ * ignored — a deployment-authored typo must never turn into CrashLoopBackOff.
13
+ */
14
+ export declare const PROVIDER_ENGINE_MODE_ENV = "APIFUSE__ENGINE__MODE";
15
+ /**
16
+ * How a provider process attaches its capability bindings: `"in-process"` today,
17
+ * `"remote"` for the authenticated engine (ADR-0011).
18
+ *
19
+ * The union is intentionally open so further lanes (for example a provider hosted
20
+ * inside the engine) can be named without a breaking change. Unknown values are
21
+ * rejected at runtime, not by the type.
22
+ */
23
+ export type ProviderEngineMode = "in-process" | "remote" | (string & {});
5
24
  /** Credential names owned by the engine and forbidden in provider declarations. */
6
25
  export declare const ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES: readonly ["APIFUSE__PROXY__SMARTPROXY_APP_KEY", "APIFUSE__PROXY__NODEMAVEN_USERNAME", "APIFUSE__PROXY__NODEMAVEN_PASSWORD"];
7
26
  export declare function isEngineOwnedProxyCredentialName(name: string): boolean;
@@ -89,7 +108,22 @@ export interface ProviderEngineAttachmentInput {
89
108
  }
90
109
  /** Attachment boundary shared by in-process development and remote RPC bridges. */
91
110
  export interface ProviderEngine {
111
+ /**
112
+ * Which attachment this engine performs. Lets the server report a truthful
113
+ * mode at boot and compare an explicit engine object against a requested
114
+ * `engineMode`; omit for opaque host engines (reported as `custom`).
115
+ */
116
+ readonly kind?: ProviderEngineMode;
92
117
  attach<TDeclaration extends object = Record<string, unknown>>(input: ProviderEngineAttachmentInput): ProviderContext<TDeclaration>;
93
118
  }
94
- /** Local engine attachment; deployed bridges implement the same interface with RPC clients. */
119
+ /**
120
+ * Local engine attachment; deployed bridges implement the same interface with RPC clients.
121
+ *
122
+ * ADR-0011 makes the authenticated remote engine the only attachment, so this one
123
+ * is scheduled for removal — but not deprecated yet: the remote client ships in a
124
+ * later release, and deprecating the only working constructor before its
125
+ * replacement exists would flag every current caller with no fix available. Until
126
+ * then it stays the default, and the server reports each in-process boot as
127
+ * `provider_engine_mode` with `deprecated: true`.
128
+ */
95
129
  export declare function createInProcessProviderEngine(): ProviderEngine;
package/dist/engine.js CHANGED
@@ -4,6 +4,16 @@ import { APIFUSE__RESOLVER__2CAPTCHA__API_KEY, APIFUSE__RESOLVER__CAPMONSTER__AP
4
4
  import { OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, } from "./runtime/otlp.js";
5
5
  /** Versioned envelope protocol used by out-of-process engine transports. */
6
6
  export const PROVIDER_ENGINE_PROTOCOL_VERSION = "provider-engine.v1";
7
+ /**
8
+ * Environment variable that selects how a provider process attaches its capability
9
+ * bindings. Engine-owned by prefix (`APIFUSE__ENGINE__*`): never declarable as a
10
+ * provider secret and never projected into `ctx.env`.
11
+ *
12
+ * Values are trimmed and case-folded; absent or blank means "unset". An
13
+ * unrecognized value is reported on the `provider_engine_mode` boot event and
14
+ * ignored — a deployment-authored typo must never turn into CrashLoopBackOff.
15
+ */
16
+ export const PROVIDER_ENGINE_MODE_ENV = "APIFUSE__ENGINE__MODE";
7
17
  /** Credential names owned by the engine and forbidden in provider declarations. */
8
18
  export const ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES = [
9
19
  "APIFUSE__PROXY__SMARTPROXY_APP_KEY",
@@ -184,7 +194,16 @@ function attachInProcess(input) {
184
194
  },
185
195
  });
186
196
  }
187
- /** Local engine attachment; deployed bridges implement the same interface with RPC clients. */
197
+ /**
198
+ * Local engine attachment; deployed bridges implement the same interface with RPC clients.
199
+ *
200
+ * ADR-0011 makes the authenticated remote engine the only attachment, so this one
201
+ * is scheduled for removal — but not deprecated yet: the remote client ships in a
202
+ * later release, and deprecating the only working constructor before its
203
+ * replacement exists would flag every current caller with no fix available. Until
204
+ * then it stays the default, and the server reports each in-process boot as
205
+ * `provider_engine_mode` with `deprecated: true`.
206
+ */
188
207
  export function createInProcessProviderEngine() {
189
- return { attach: attachInProcess };
208
+ return { kind: "in-process", attach: attachInProcess };
190
209
  }
@@ -2,3 +2,4 @@ import type { ProviderErrorStatus } from "./types.js";
2
2
  export declare const SDK_OWNED_PROVIDER_ERROR_CODES: Set<string>;
3
3
  export declare const SDK_RUNTIME_OWNED_ERROR_CODES: Set<string>;
4
4
  export declare const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES: ReadonlyMap<string, ProviderErrorStatus>;
5
+ export declare const SDK_CANONICAL_ERROR_CODE_RETRYABILITY: ReadonlyMap<string, boolean>;
@@ -18,6 +18,14 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
18
18
  "refresh_not_supported",
19
19
  "RUNTIME_UNSUPPORTED",
20
20
  "PROVIDER_STATE_UNSUPPORTED",
21
+ // Engine attachment (ADR-0011). Registered here so an engine failure is served
22
+ // as a known SDK code instead of raising a false
23
+ // `unregistered_provider_error_code` signal on a 500.
24
+ "PROVIDER_ENGINE_AUTHENTICATION_FAILED",
25
+ "PROVIDER_ENGINE_PROTOCOL_VERSION_MISMATCH",
26
+ "PROVIDER_ENGINE_UNAVAILABLE",
27
+ "PROVIDER_ENGINE_MODE_UNSUPPORTED",
28
+ "PROVIDER_EGRESS_DENIED",
21
29
  "HANDLE_INVALID",
22
30
  "HANDLE_NOT_FOUND",
23
31
  "HANDLE_EXPIRED",
@@ -57,6 +65,7 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
57
65
  "http_redirect_missing_location",
58
66
  "http_redirect_loop",
59
67
  "transport_invalid_url",
68
+ "http_header_factory_failed",
60
69
  "EGRESS_LEASE_INVALID",
61
70
  "EGRESS_LEASE_BINDING_INVALID",
62
71
  "EGRESS_LEASE_KEY_MISSING",
@@ -84,6 +93,7 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
84
93
  "STATEFUL_FORWARDING_OWNER_FENCE_INVALID",
85
94
  "STATEFUL_FORWARDING_REQUEST_FAILED",
86
95
  "STATEFUL_FORWARDING_CONTEXT_MISSING",
96
+ "STATEFUL_FORWARDING_CONTEXT_INVALID",
87
97
  "STATEFUL_FORWARDING_BAD_RESPONSE",
88
98
  "STATEFUL_INTERNAL_EXECUTOR_NOT_CONFIGURED",
89
99
  "STATEFUL_FILE_FORWARDING_UNSUPPORTED",
@@ -144,9 +154,53 @@ export const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES = new Map([
144
154
  ["HANDLE_BUSY", 409],
145
155
  ["UPSTREAM_ERROR", 502],
146
156
  ["BLOCKED", 502],
157
+ // Fleet-consensus provider codes. These are thrown by provider code, not
158
+ // by the SDK, so they are registered here (status mapping) and not in
159
+ // SDK_RUNTIME_OWNED_ERROR_CODES: an operation-declared status still wins,
160
+ // exactly as it does for UPSTREAM_ERROR and BLOCKED above. Registering
161
+ // them stops the fleet from re-declaring the same three rows on every
162
+ // operation, and stops an undeclared throw from being served as 500.
163
+ //
164
+ // A platform-managed upstream service key the upstream refuses. With
165
+ // `auth.mode: "platform-managed"` the caller holds no credential, so 401
166
+ // ("re-authenticate") tells the caller to do something it cannot do, and
167
+ // 502 ("upstream is sick") promises a recovery that will never come. It is
168
+ // a deployment/config defect — the same class as MISSING_SECRET above,
169
+ // which is already an explicit 400 for that reason.
170
+ ["UPSTREAM_AUTH_ERROR", 400],
171
+ // The upstream changed its response shape and the provider cannot
172
+ // normalize it. 502 because the fault is upstream of us, non-retryable
173
+ // because a retry returns the same broken payload.
174
+ ["UPSTREAM_SCHEMA_ERROR", 502],
175
+ // Caller-side bad input rejected by the provider. The minority spellings
176
+ // (INVALID_INPUT / VALIDATION_ERROR / BAD_REQUEST) are deliberately not
177
+ // registered: they migrate to this spelling on the contract track, and
178
+ // registering them here would freeze the divergence.
179
+ ["INVALID_REQUEST", 400],
147
180
  ["OCR_UNAVAILABLE", 503],
148
181
  ["UNSUPPORTED_OCR_BACKEND", 503],
149
182
  ["STT_UNAVAILABLE", 503],
150
183
  ["UNSUPPORTED_STT_BACKEND", 503],
151
184
  ["STATEFUL_FORWARDING_REPLAY_CACHE_FULL", 503],
185
+ // The engine is reachable-in-principle but not now: retryable, so the
186
+ // caller may retry once the engine recovers. Authentication, protocol
187
+ // mismatch, an unsupported mode and denied egress stay unmapped (500) and
188
+ // non-retryable: they are deployment or provider faults that no caller
189
+ // retry can clear, and a retryable 5xx there would turn one bad rollout
190
+ // into gateway-driven load.
191
+ ["PROVIDER_ENGINE_UNAVAILABLE", 503],
192
+ ]);
193
+ // Canonical retryability for the fleet-consensus codes registered above.
194
+ //
195
+ // Runtime retryability still resolves as `instance option ?? declared ??
196
+ // false`, so this map changes no served response: an undeclared throw already
197
+ // defaults to false, which is what every entry here says. It exists so the
198
+ // authoring lint can tell a provider that its declared `retryable` contradicts
199
+ // the registered meaning of the code, instead of the fleet quietly shipping two
200
+ // answers for the same code. Only codes whose retryability was fixed as part of
201
+ // registration belong here — do not backfill opinions the SDK never made.
202
+ export const SDK_CANONICAL_ERROR_CODE_RETRYABILITY = new Map([
203
+ ["UPSTREAM_AUTH_ERROR", false],
204
+ ["UPSTREAM_SCHEMA_ERROR", false],
205
+ ["INVALID_REQUEST", false],
152
206
  ]);
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { ProviderErrorMessageParams } from "./i18n/error-messages.js";
1
2
  import type { ProviderErrorCategory } from "./observability.js";
2
- import type { HttpRedirectFailureReason } from "./types.js";
3
+ import type { HttpRedirectFailureReason, ProviderLocaleKeyInput } from "./types.js";
3
4
  export type ProviderErrorOptions = {
4
5
  fix?: string;
5
6
  code?: string;
@@ -9,6 +10,25 @@ export type ProviderErrorOptions = {
9
10
  retryable?: boolean;
10
11
  /** Provider-authored, bounded metadata safe for operational logs and error headers. */
11
12
  observability?: ProviderErrorObservability;
13
+ /**
14
+ * Locale catalog key for the client-facing `message`, e.g.
15
+ * `"errors.upstreamSchema.message"`. Resolved at serve time against the
16
+ * provider's `locales/{en,ko,ja}.json` with the caller's `Accept-Language`,
17
+ * falling back to `en` and then to the positional `message`.
18
+ *
19
+ * The positional `message` stays English: it is what `error.message`, cause
20
+ * frames, logs and OTLP attributes carry. Only the response envelope is
21
+ * localized.
22
+ */
23
+ messageKey?: ProviderLocaleKeyInput;
24
+ /** Locale catalog key for the client-facing `fix`. Same resolution as {@link ProviderErrorOptions.messageKey}. */
25
+ fixKey?: ProviderLocaleKeyInput;
26
+ /**
27
+ * Values substituted into `{name}` placeholders of the resolved text.
28
+ * Strings and finite numbers only; string values are scrubbed and length
29
+ * capped before substitution because upstream text routinely lands here.
30
+ */
31
+ params?: ProviderErrorMessageParams;
12
32
  };
13
33
  /**
14
34
  * Provider-authored error diagnostics whose runtime values are validated before emission.
@@ -33,6 +53,24 @@ export declare class ProviderError extends Error {
33
53
  export declare class SDKError extends ProviderError {
34
54
  constructor(message: string, options?: ProviderErrorOptions);
35
55
  }
56
+ /** Raised when the remote provider engine speaks an incompatible protocol version. */
57
+ export declare class ProviderEngineProtocolVersionError extends SDKError {
58
+ readonly receivedVersion: unknown;
59
+ readonly expectedVersion: string;
60
+ constructor(receivedVersion: unknown, expectedVersion: string);
61
+ }
62
+ /** Raised when the remote provider engine rejects a workspace API key. */
63
+ export declare class ProviderEngineAuthenticationError extends SDKError {
64
+ constructor(message?: string, options?: ProviderErrorOptions);
65
+ }
66
+ /** Raised when the remote engine cannot be reached. There is no local fallback. */
67
+ export declare class ProviderEngineUnavailableError extends SDKError {
68
+ constructor(message?: string, cause?: Error);
69
+ }
70
+ /** Raised when the engine refuses egress outside the workspace's pinned allowlist. */
71
+ export declare class ProviderEgressDeniedError extends ProviderError {
72
+ constructor(message: string, details?: unknown);
73
+ }
36
74
  /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
37
75
  export declare class StealthCookieStoreVersionError extends SDKError {
38
76
  readonly version: unknown;
package/dist/errors.js CHANGED
@@ -59,6 +59,56 @@ export class SDKError extends ProviderError {
59
59
  this.name = "SDKError";
60
60
  }
61
61
  }
62
+ /** Raised when the remote provider engine speaks an incompatible protocol version. */
63
+ export class ProviderEngineProtocolVersionError extends SDKError {
64
+ receivedVersion;
65
+ expectedVersion;
66
+ constructor(receivedVersion, expectedVersion) {
67
+ super(`Provider engine protocol version mismatch: expected ${expectedVersion}, received ${String(receivedVersion)}`, {
68
+ code: "PROVIDER_ENGINE_PROTOCOL_VERSION_MISMATCH",
69
+ details: { receivedVersion, expectedVersion },
70
+ fix: "Update @apifuse/provider-sdk or use a compatible APIFuse provider engine.",
71
+ });
72
+ this.receivedVersion = receivedVersion;
73
+ this.expectedVersion = expectedVersion;
74
+ this.name = "ProviderEngineProtocolVersionError";
75
+ }
76
+ }
77
+ /** Raised when the remote provider engine rejects a workspace API key. */
78
+ export class ProviderEngineAuthenticationError extends SDKError {
79
+ constructor(message = "Provider engine authentication failed", options) {
80
+ super(message, {
81
+ code: "PROVIDER_ENGINE_AUTHENTICATION_FAILED",
82
+ fix: "Set APIFUSE__ENGINE__API_KEY to the workspace API key from your APIFuse bounty dashboard.",
83
+ ...options,
84
+ });
85
+ this.name = "ProviderEngineAuthenticationError";
86
+ }
87
+ }
88
+ /** Raised when the remote engine cannot be reached. There is no local fallback. */
89
+ export class ProviderEngineUnavailableError extends SDKError {
90
+ constructor(message = "The remote APIFuse provider engine is unavailable", cause) {
91
+ super(message, {
92
+ code: "PROVIDER_ENGINE_UNAVAILABLE",
93
+ retryable: true,
94
+ fix: "Check network access and the provider engine endpoint, then retry.",
95
+ ...(cause ? { cause } : {}),
96
+ });
97
+ this.name = "ProviderEngineUnavailableError";
98
+ }
99
+ }
100
+ /** Raised when the engine refuses egress outside the workspace's pinned allowlist. */
101
+ export class ProviderEgressDeniedError extends ProviderError {
102
+ constructor(message, details) {
103
+ super(message, {
104
+ code: "PROVIDER_EGRESS_DENIED",
105
+ retryable: false,
106
+ details,
107
+ fix: "Use a host in the provider's pinned allowedHosts declaration, or request a trusted pin update.",
108
+ });
109
+ this.name = "ProviderEgressDeniedError";
110
+ }
111
+ }
62
112
  /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
63
113
  export class StealthCookieStoreVersionError extends SDKError {
64
114
  version;
@@ -0,0 +1,86 @@
1
+ import type { ProviderLocaleCatalogMap } from "./catalog.js";
2
+ import { type ProviderLocale } from "./keys.js";
3
+ /**
4
+ * Values interpolated into a localized provider error message or fix.
5
+ *
6
+ * Strings and finite numbers only. String values are treated as untrusted
7
+ * (upstream bodies frequently end up here), so they are scrubbed and capped by
8
+ * {@link interpolateProviderErrorText} before substitution.
9
+ */
10
+ export type ProviderErrorMessageParams = Readonly<Record<string, string | number>>;
11
+ /** Locales the SDK negotiates for client-facing provider text. */
12
+ export declare const PROVIDER_ERROR_LOCALES: readonly ["en", "ko", "ja"];
13
+ /** Locale used when the caller asks for nothing the provider catalog covers. */
14
+ export declare const DEFAULT_PROVIDER_ERROR_LOCALE = "en";
15
+ /** Catalog namespace for derived `errors.<code>.message` / `errors.<code>.fix` lookups. */
16
+ export declare const PROVIDER_ERROR_CATALOG_NAMESPACE = "errors";
17
+ /** Per-value cap applied to every interpolated param, before substitution. */
18
+ export declare const MAX_INTERPOLATED_PARAM_LENGTH = 200;
19
+ /** Cap applied to a rendered localized message or fix. */
20
+ export declare const MAX_LOCALIZED_ERROR_TEXT_LENGTH = 2000;
21
+ /**
22
+ * Negotiates an `Accept-Language` header against {@link PROVIDER_ERROR_LOCALES}.
23
+ *
24
+ * Quality values are honoured (`ko;q=0.1, ja;q=0.9` selects `ja`) and `q=0`
25
+ * means "not acceptable". Ranges are matched on the primary subtag, so `ko-KR`
26
+ * selects `ko`. Returns `undefined` when the header is absent or names no
27
+ * supported locale, so callers can consult a lower-precedence source before
28
+ * defaulting.
29
+ */
30
+ export declare function providerLocaleFromAcceptLanguage(header: string | null | undefined): ProviderLocale | undefined;
31
+ /** Reads `accept-language` from a case-insensitive header record. */
32
+ export declare function acceptLanguageHeaderValue(headers: Readonly<Record<string, unknown>> | undefined): string | undefined;
33
+ /**
34
+ * Picks the first supported locale across header sources, in precedence order,
35
+ * falling back to {@link DEFAULT_PROVIDER_ERROR_LOCALE}.
36
+ */
37
+ export declare function resolveProviderErrorLocale(...headerValues: readonly (string | null | undefined)[]): ProviderLocale;
38
+ /**
39
+ * Renders one param value as substitution text, or `undefined` when the value
40
+ * cannot be substituted (absent, non-finite, or not a string/number).
41
+ */
42
+ export declare function interpolatedParamText(value: unknown): string | undefined;
43
+ /**
44
+ * Substitutes `{name}` placeholders in a catalog template.
45
+ *
46
+ * - `{{` and `}}` are the literal `{` and `}` escapes.
47
+ * - A placeholder with no usable param is left verbatim, so an authoring gap is
48
+ * visible in the response instead of silently deleting text.
49
+ * - Substituted text is never rescanned, so a param value containing `{other}`
50
+ * cannot trigger a second round of interpolation.
51
+ */
52
+ export declare function interpolateProviderErrorText(template: string, params?: ProviderErrorMessageParams): string;
53
+ /** A key candidate considered by {@link localizeProviderErrorText}, in priority order. */
54
+ export type ProviderErrorTextCandidate =
55
+ /** An explicit dot-path key from a throw site or an `errorCodes[]` declaration. */
56
+ {
57
+ readonly kind: "key";
58
+ readonly key: string | undefined;
59
+ }
60
+ /** The `errors.<code>.<field>` convention; `code` is used verbatim as a segment. */
61
+ | {
62
+ readonly kind: "derived";
63
+ readonly code: string | undefined;
64
+ readonly field: string;
65
+ };
66
+ export interface LocalizeProviderErrorTextOptions {
67
+ readonly catalogs?: ProviderLocaleCatalogMap;
68
+ readonly locale: ProviderLocale;
69
+ readonly fallbackLocale?: ProviderLocale;
70
+ readonly candidates: readonly ProviderErrorTextCandidate[];
71
+ readonly params?: ProviderErrorMessageParams;
72
+ /** Literal text returned when no candidate resolves. May be `undefined` for `fix`. */
73
+ readonly fallback: string | undefined;
74
+ }
75
+ /**
76
+ * Resolves client-facing error text against the provider locale catalogs.
77
+ *
78
+ * Candidates are tried in order and each one is resolved in the caller's locale
79
+ * before the `en` catalog, so a more specific key always beats a more specific
80
+ * locale. Nothing here throws: a malformed key, an absent catalog, a
81
+ * non-string catalog value and a missing key all fall through to the next
82
+ * candidate and ultimately to `fallback`.
83
+ */
84
+ export declare function localizeProviderErrorText(options: LocalizeProviderErrorTextOptions): string | undefined;
85
+ /** The `errors.<code>.<field>` dot path this SDK derives for an undeclared key. */
86
+ export declare function derivedProviderErrorCatalogPath(code: string, field: "message" | "fix"): string;