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

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 +367 -9
  2. package/CHANGELOG.md +8 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1 -0
  5. package/bin/apifuse-check.ts +84 -2
  6. package/bin/apifuse-dev.ts +11 -31
  7. package/bin/apifuse-migrate-deployment.ts +200 -0
  8. package/bin/apifuse-pack-check.ts +11 -4
  9. package/bin/apifuse-pack-types.ts +187 -4
  10. package/bin/apifuse-record.ts +44 -32
  11. package/bin/apifuse-submit-check.ts +9 -5
  12. package/bin/apifuse-test.ts +3 -1
  13. package/dist/cli/commands.d.ts +1 -1
  14. package/dist/cli/commands.js +11 -0
  15. package/dist/cli/deployment-intent.d.ts +178 -0
  16. package/dist/cli/deployment-intent.js +277 -0
  17. package/dist/cli/migrate-deployment-intent.d.ts +132 -0
  18. package/dist/cli/migrate-deployment-intent.js +1552 -0
  19. package/dist/cli/migrate-provider-shape.d.ts +5 -1
  20. package/dist/cli/migrate-provider-shape.js +4 -2
  21. package/dist/cli/resolver-runtime.d.ts +21 -0
  22. package/dist/cli/resolver-runtime.js +31 -0
  23. package/dist/define.d.ts +3 -0
  24. package/dist/define.js +5 -0
  25. package/dist/dev.d.ts +3 -1
  26. package/dist/dev.js +6 -1
  27. package/dist/engine.d.ts +35 -1
  28. package/dist/engine.js +21 -2
  29. package/dist/error-resolution.d.ts +1 -0
  30. package/dist/error-resolution.js +54 -0
  31. package/dist/errors.d.ts +39 -1
  32. package/dist/errors.js +50 -0
  33. package/dist/handle-meta.d.ts +36 -1
  34. package/dist/handle-meta.js +16 -0
  35. package/dist/handle.d.ts +23 -5
  36. package/dist/handle.js +54 -8
  37. package/dist/health-scenario.d.ts +38 -0
  38. package/dist/i18n/error-messages.d.ts +86 -0
  39. package/dist/i18n/error-messages.js +192 -0
  40. package/dist/i18n/index.d.ts +1 -0
  41. package/dist/i18n/index.js +1 -0
  42. package/dist/i18n/keys.d.ts +12 -0
  43. package/dist/i18n/keys.js +76 -5
  44. package/dist/index.d.ts +11 -3
  45. package/dist/index.js +9 -1
  46. package/dist/lint.d.ts +15 -0
  47. package/dist/lint.js +469 -82
  48. package/dist/provider.d.ts +6 -6
  49. package/dist/provider.js +3 -3
  50. package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
  51. package/dist/runtime/browser-telemetry-binding.js +83 -0
  52. package/dist/runtime/browser-telemetry.d.ts +76 -0
  53. package/dist/runtime/browser-telemetry.js +165 -0
  54. package/dist/runtime/browser.d.ts +3 -0
  55. package/dist/runtime/browser.js +208 -47
  56. package/dist/runtime/cache-telemetry.d.ts +71 -0
  57. package/dist/runtime/cache-telemetry.js +177 -0
  58. package/dist/runtime/cache.js +67 -7
  59. package/dist/runtime/capability-response.d.ts +3 -0
  60. package/dist/runtime/capability-response.js +56 -0
  61. package/dist/runtime/capability-telemetry.d.ts +46 -0
  62. package/dist/runtime/capability-telemetry.js +68 -0
  63. package/dist/runtime/diagnostic-env.d.ts +3 -0
  64. package/dist/runtime/diagnostic-env.js +10 -1
  65. package/dist/runtime/engine-mode.d.ts +74 -0
  66. package/dist/runtime/engine-mode.js +152 -0
  67. package/dist/runtime/handle.js +9 -1
  68. package/dist/runtime/http-telemetry-guard.d.ts +10 -0
  69. package/dist/runtime/http-telemetry-guard.js +62 -10
  70. package/dist/runtime/http.js +141 -35
  71. package/dist/runtime/instrumentation.js +92 -13
  72. package/dist/runtime/ocr-telemetry.d.ts +82 -0
  73. package/dist/runtime/ocr-telemetry.js +192 -0
  74. package/dist/runtime/ocr.js +35 -8
  75. package/dist/runtime/request-telemetry.d.ts +2 -0
  76. package/dist/runtime/request-telemetry.js +2 -1
  77. package/dist/runtime/resolver-runtime-options.d.ts +14 -0
  78. package/dist/runtime/resolver-runtime-options.js +33 -0
  79. package/dist/runtime/resolver-shared.d.ts +3 -2
  80. package/dist/runtime/resolver-shared.js +4 -4
  81. package/dist/runtime/resolver-telemetry.d.ts +1 -0
  82. package/dist/runtime/resolver-telemetry.js +1 -1
  83. package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
  84. package/dist/runtime/resolver-vendors/browser.js +46 -0
  85. package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
  86. package/dist/runtime/resolver-vendors/hosts.js +35 -0
  87. package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
  88. package/dist/runtime/resolver-vendors/types.d.ts +5 -4
  89. package/dist/runtime/resolver.d.ts +4 -1
  90. package/dist/runtime/resolver.js +46 -13
  91. package/dist/runtime/state-telemetry.d.ts +79 -0
  92. package/dist/runtime/state-telemetry.js +194 -0
  93. package/dist/runtime/state.d.ts +3 -0
  94. package/dist/runtime/state.js +26 -7
  95. package/dist/runtime/stealth-cookies.d.ts +5 -1
  96. package/dist/runtime/stealth-cookies.js +21 -1
  97. package/dist/runtime/stealth-owned-headers.d.ts +26 -0
  98. package/dist/runtime/stealth-owned-headers.js +37 -0
  99. package/dist/runtime/stealth-telemetry.d.ts +92 -0
  100. package/dist/runtime/stealth-telemetry.js +179 -0
  101. package/dist/runtime/stealth.d.ts +4 -1
  102. package/dist/runtime/stealth.js +228 -85
  103. package/dist/runtime/stt-telemetry.d.ts +77 -0
  104. package/dist/runtime/stt-telemetry.js +176 -0
  105. package/dist/runtime/stt.js +15 -6
  106. package/dist/runtime-boundary-lint.d.ts +132 -0
  107. package/dist/runtime-boundary-lint.js +586 -0
  108. package/dist/server/error-stack-frames.d.ts +35 -0
  109. package/dist/server/error-stack-frames.js +219 -0
  110. package/dist/server/index.d.ts +7 -0
  111. package/dist/server/index.js +4 -0
  112. package/dist/server/sdk-version.d.ts +3 -0
  113. package/dist/server/sdk-version.js +19 -0
  114. package/dist/server/self-test.js +1 -18
  115. package/dist/server/sensitive-values.d.ts +1 -1
  116. package/dist/server/sensitive-values.js +9 -0
  117. package/dist/server/serve-implementation.d.ts +51 -2
  118. package/dist/server/serve-implementation.js +337 -90
  119. package/dist/server/types.d.ts +1 -0
  120. package/dist/server/types.js +7 -0
  121. package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
  122. package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
  123. package/dist/stateful/stateful-provider-runtime-context.js +1 -0
  124. package/dist/types.d.ts +123 -1
  125. package/dist/typescript-module.d.ts +39 -0
  126. package/dist/typescript-module.js +72 -0
  127. package/package.json +6 -1
  128. package/src/cli/commands.ts +14 -0
  129. package/src/cli/deployment-intent.ts +364 -0
  130. package/src/cli/migrate-deployment-intent.ts +1908 -0
  131. package/src/cli/migrate-provider-shape.ts +10 -4
  132. package/src/cli/resolver-runtime.ts +72 -0
  133. package/src/define.ts +13 -0
  134. package/src/dev.ts +9 -2
  135. package/src/engine.ts +38 -2
  136. package/src/error-resolution.ts +58 -0
  137. package/src/errors.ts +77 -1
  138. package/src/handle-meta.ts +51 -1
  139. package/src/handle.ts +92 -10
  140. package/src/health-scenario.ts +38 -0
  141. package/src/i18n/error-messages.ts +255 -0
  142. package/src/i18n/index.ts +1 -0
  143. package/src/i18n/keys.ts +80 -6
  144. package/src/index.ts +86 -0
  145. package/src/lint.ts +604 -91
  146. package/src/provider.ts +12 -0
  147. package/src/runtime/browser-telemetry-binding.ts +92 -0
  148. package/src/runtime/browser-telemetry.ts +289 -0
  149. package/src/runtime/browser.ts +249 -65
  150. package/src/runtime/cache-telemetry.ts +247 -0
  151. package/src/runtime/cache.ts +68 -17
  152. package/src/runtime/capability-response.ts +53 -0
  153. package/src/runtime/capability-telemetry.ts +101 -0
  154. package/src/runtime/diagnostic-env.ts +11 -1
  155. package/src/runtime/engine-mode.ts +233 -0
  156. package/src/runtime/handle.ts +9 -1
  157. package/src/runtime/http-telemetry-guard.ts +66 -13
  158. package/src/runtime/http.ts +168 -37
  159. package/src/runtime/instrumentation.ts +105 -16
  160. package/src/runtime/ocr-telemetry.ts +308 -0
  161. package/src/runtime/ocr.ts +114 -74
  162. package/src/runtime/request-telemetry.ts +2 -1
  163. package/src/runtime/resolver-runtime-options.ts +50 -0
  164. package/src/runtime/resolver-shared.ts +9 -4
  165. package/src/runtime/resolver-telemetry.ts +1 -1
  166. package/src/runtime/resolver-vendors/browser.ts +65 -7
  167. package/src/runtime/resolver-vendors/hosts.ts +43 -0
  168. package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
  169. package/src/runtime/resolver-vendors/types.ts +5 -4
  170. package/src/runtime/resolver.ts +64 -21
  171. package/src/runtime/state-telemetry.ts +298 -0
  172. package/src/runtime/state.ts +46 -45
  173. package/src/runtime/stealth-cookies.ts +24 -1
  174. package/src/runtime/stealth-owned-headers.ts +41 -0
  175. package/src/runtime/stealth-telemetry.ts +304 -0
  176. package/src/runtime/stealth.ts +355 -150
  177. package/src/runtime/stt-telemetry.ts +282 -0
  178. package/src/runtime/stt.ts +93 -71
  179. package/src/runtime-boundary-lint.ts +703 -0
  180. package/src/server/error-stack-frames.ts +214 -0
  181. package/src/server/index.ts +53 -0
  182. package/src/server/sdk-version.ts +22 -0
  183. package/src/server/self-test.ts +1 -21
  184. package/src/server/sensitive-values.ts +14 -0
  185. package/src/server/serve-implementation.ts +569 -108
  186. package/src/server/types.ts +7 -0
  187. package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
  188. package/src/stateful/stateful-provider-runtime-context.ts +4 -0
  189. package/src/types.ts +128 -1
  190. package/src/typescript-module.ts +100 -0
  191. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
  192. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
  193. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
  194. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
  195. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
  196. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
  197. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
  198. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
  199. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
  200. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
  201. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
  202. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
  203. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
  204. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
  205. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
  206. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
  207. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
  208. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
  209. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
  210. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
  211. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
  212. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
  213. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
  214. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
  215. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
  216. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
  217. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
  218. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
  219. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
  220. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
  221. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
  222. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
  246. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
  247. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
  248. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
  249. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
  250. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
  251. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
  252. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
  253. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
  254. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
  255. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
  256. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
  257. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
  258. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
  259. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
  260. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
  261. 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;
@@ -15,25 +15,60 @@ export type HandleAccess = "bound" | "public";
15
15
  * `search-address` and `reverse-geocode` both issuing `location_token`).
16
16
  */
17
17
  export type HandleIssuedBy = string | readonly string[];
18
- /** Value stored under {@link APIFUSE_HANDLE_META_KEY} on a handle field. */
18
+ /** The schema side a handle field appears on. */
19
+ export type HandleFieldDirection = "input" | "output";
20
+ /**
21
+ * Direction-specific property keys for one handle kind, for the operations
22
+ * whose caller-facing contract names the same handle differently coming in and
23
+ * going out (the platform canon's `cursor` in, `next_cursor` out). The two keys
24
+ * are two spellings of ONE handle: the value a caller reads from `output` is
25
+ * the value it must send back under `input`, unedited.
26
+ */
27
+ export interface HandleFieldNames {
28
+ readonly input: string;
29
+ readonly output: string;
30
+ }
31
+ /**
32
+ * Value stored under {@link APIFUSE_HANDLE_META_KEY} on a handle field.
33
+ *
34
+ * `fieldName` is the INPUT property key — the name a caller sends the handle
35
+ * back under, and the name every runtime error message quotes. `outputFieldName`
36
+ * is present only when the output key differs, so a kind with one name emits
37
+ * exactly the meta it always did.
38
+ */
19
39
  export interface HandleFieldMeta {
20
40
  readonly kind: string;
21
41
  readonly type: HandleKindType;
22
42
  readonly fieldName: string;
43
+ readonly outputFieldName?: string;
23
44
  readonly issuedBy?: HandleIssuedBy;
24
45
  }
25
46
  /**
26
47
  * Structural view of a handle kind as seen by the provider declaration
27
48
  * (`handle: [WaitingDraft, PageCursor]`), lint, and the registry. The runtime
28
49
  * kinds returned by `defineCursor` / `defineDraft` satisfy this shape.
50
+ *
51
+ * `fieldName` / `outputFieldName` follow the {@link HandleFieldMeta} rule:
52
+ * `fieldName` is the input key, `outputFieldName` is set only when the output
53
+ * key differs.
29
54
  */
30
55
  export interface HandleKindDeclaration {
31
56
  readonly name: string;
32
57
  readonly type: HandleKindType;
33
58
  readonly fieldName: string;
59
+ readonly outputFieldName?: string;
34
60
  readonly access: HandleAccess;
35
61
  readonly issuedBy?: HandleIssuedBy;
36
62
  }
63
+ /**
64
+ * The property key a handle kind claims on one side of an operation.
65
+ *
66
+ * This is the single place that resolves a direction to a key, so lint, the
67
+ * runtime, and error text cannot disagree about which name belongs where.
68
+ */
69
+ export declare function handleFieldNameFor(kind: Pick<HandleKindDeclaration, "fieldName" | "outputFieldName">, direction: HandleFieldDirection): string;
70
+ /** True when a kind names the same handle differently on input and output. */
71
+ export declare function handleHasDirectionalFieldNames(kind: Pick<HandleKindDeclaration, "fieldName" | "outputFieldName">): boolean;
37
72
  /** Kind names are lowercase letters only so they never fuse with the word body. */
38
73
  export declare const HANDLE_KIND_NAME_PATTERN: RegExp;
39
74
  /** True for a single operation key or a non-empty list of operation keys. */
@@ -7,6 +7,21 @@
7
7
  */
8
8
  /** JSON Schema meta key placed on every schema field created by `kind.field()`. */
9
9
  export const APIFUSE_HANDLE_META_KEY = "x-apifuse-handle";
10
+ /**
11
+ * The property key a handle kind claims on one side of an operation.
12
+ *
13
+ * This is the single place that resolves a direction to a key, so lint, the
14
+ * runtime, and error text cannot disagree about which name belongs where.
15
+ */
16
+ export function handleFieldNameFor(kind, direction) {
17
+ if (direction === "input")
18
+ return kind.fieldName;
19
+ return kind.outputFieldName ?? kind.fieldName;
20
+ }
21
+ /** True when a kind names the same handle differently on input and output. */
22
+ export function handleHasDirectionalFieldNames(kind) {
23
+ return kind.outputFieldName !== undefined && kind.outputFieldName !== kind.fieldName;
24
+ }
10
25
  /** Kind names are lowercase letters only so they never fuse with the word body. */
11
26
  export const HANDLE_KIND_NAME_PATTERN = /^[a-z]{2,12}$/;
12
27
  /** True for a single operation key or a non-empty list of operation keys. */
@@ -43,6 +58,7 @@ export function isHandleFieldMeta(value) {
43
58
  return (typeof record.kind === "string" &&
44
59
  (record.type === "cursor" || record.type === "draft") &&
45
60
  typeof record.fieldName === "string" &&
61
+ (record.outputFieldName === undefined || typeof record.outputFieldName === "string") &&
46
62
  (record.issuedBy === undefined || isHandleIssuedBy(record.issuedBy)));
47
63
  }
48
64
  /**
package/dist/handle.d.ts CHANGED
@@ -9,9 +9,9 @@
9
9
  */
10
10
  import { type ZodString, type ZodType, z } from "zod";
11
11
  import { ProviderError, type ProviderErrorOptions } from "./errors.js";
12
- import { type HandleAccess, type HandleFieldMeta, type HandleIssuedBy, type HandleKindDeclaration, type HandleKindType } from "./handle-meta.js";
12
+ import { type HandleAccess, type HandleFieldDirection, type HandleFieldMeta, type HandleFieldNames, type HandleIssuedBy, type HandleKindDeclaration, type HandleKindType } from "./handle-meta.js";
13
13
  import type { ProviderStateDurationString } from "./types.js";
14
- export type { HandleAccess, HandleFieldMeta, HandleIssuedBy, HandleKindDeclaration, HandleKindType, };
14
+ export type { HandleAccess, HandleFieldDirection, HandleFieldMeta, HandleFieldNames, HandleIssuedBy, HandleKindDeclaration, HandleKindType, };
15
15
  export type HandleStrength = "standard" | "high";
16
16
  /** Words issued per handle: 2 for bound kinds, 4 for public, 5 for high-strength public. */
17
17
  export type HandleWordCount = 2 | 4 | 5;
@@ -30,6 +30,10 @@ export interface HandleKindBase<TSchema extends ZodType = ZodType> extends Handl
30
30
  /**
31
31
  * Schema for the handle field, usable in output and input positions. Carries
32
32
  * the `x-apifuse-handle` meta and an SDK-owned English description.
33
+ *
34
+ * One schema serves both directions even when the kind declares separate
35
+ * `input` / `output` property keys: the meta carries both names and lint
36
+ * checks the key against the side the field actually appears on.
33
37
  */
34
38
  field(): ZodString;
35
39
  }
@@ -131,6 +135,7 @@ export declare function isHandleError(value: unknown): value is HandleError;
131
135
  */
132
136
  export declare function handleRecoverySentence(kind: {
133
137
  readonly fieldName: string;
138
+ readonly outputFieldName?: string;
134
139
  readonly issuedBy?: HandleIssuedBy;
135
140
  }): string;
136
141
  /** Parses a `ProviderStateDurationString` to milliseconds; throws on invalid or non-positive input. */
@@ -138,8 +143,16 @@ export declare function parseHandleDurationMs(value: ProviderStateDurationString
138
143
  export interface DefineCursorOptions<TSchema extends ZodType> {
139
144
  /** Kind name, `/^[a-z]{2,12}$/`; becomes the handle prefix. */
140
145
  readonly name: string;
141
- /** Schema property key carrying the handle. Default `${name}_token`. */
142
- readonly fieldName?: string;
146
+ /**
147
+ * Schema property key carrying the handle. Default `${name}_token`.
148
+ *
149
+ * Pass `{ input, output }` when the caller-facing contract names the same
150
+ * handle differently in each direction — the canon's `{ input: "cursor",
151
+ * output: "next_cursor" }`. Both keys must be given; the handle's identity
152
+ * stays the kind, so a value issued under `output` is still only valid when
153
+ * sent back under `input`.
154
+ */
155
+ readonly fieldName?: string | HandleFieldNames;
143
156
  readonly schema: TSchema;
144
157
  readonly ttl: ProviderStateDurationString;
145
158
  /** `"bound"` (default): connection-scoped, 2 words. `"public"`: provider-scoped, 4-5 words. */
@@ -155,7 +168,12 @@ export interface DefineCursorOptions<TSchema extends ZodType> {
155
168
  }
156
169
  export interface DefineDraftOptions<TSchema extends ZodType, TResultSchema extends ZodType | undefined> {
157
170
  readonly name: string;
158
- readonly fieldName?: string;
171
+ /**
172
+ * Schema property key carrying the handle. Default `${name}_token`. Accepts
173
+ * `{ input, output }` for a contract that names the handle differently in
174
+ * each direction; see {@link DefineCursorOptions.fieldName}.
175
+ */
176
+ readonly fieldName?: string | HandleFieldNames;
159
177
  readonly schema: TSchema;
160
178
  /** Optional schema of the commit result (type-level). */
161
179
  readonly result?: TResultSchema;