@apifuse/provider-sdk 2.2.0-beta.3 → 2.2.0-beta.31

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 (342) hide show
  1. package/AUTHORING.md +493 -5
  2. package/CHANGELOG.md +131 -1
  3. package/README.md +52 -6
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +106 -62
  6. package/bin/apifuse-create.ts +1 -1
  7. package/bin/apifuse-dev.ts +63 -55
  8. package/bin/apifuse-pack-check.ts +22 -2
  9. package/bin/apifuse-pack-smoke.ts +78 -82
  10. package/bin/apifuse-pack-types.ts +583 -0
  11. package/bin/apifuse-perf.ts +59 -140
  12. package/bin/apifuse-record.ts +698 -113
  13. package/bin/apifuse-submit-check.ts +517 -44
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/apifuse.ts +1 -1
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/bin/submit-check-xml.ts +1 -1
  18. package/dist/auth-turn/index.d.ts +4 -4
  19. package/dist/auth-turn/index.js +1 -1
  20. package/dist/auth.d.ts +16 -2
  21. package/dist/auth.js +76 -18
  22. package/dist/ceremonies/index.d.ts +9 -1
  23. package/dist/ceremonies/index.js +117 -29
  24. package/dist/cli/commands.d.ts +1 -1
  25. package/dist/cli/commands.js +8 -0
  26. package/dist/cli/create.d.ts +3 -0
  27. package/dist/cli/create.js +34 -35
  28. package/dist/cli/prompt-assets.d.ts +80 -0
  29. package/dist/cli/prompt-assets.js +743 -0
  30. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  31. package/dist/cli/templates/provider/README.md.tpl +4 -4
  32. package/dist/config/loader.d.ts +176 -17
  33. package/dist/config/loader.js +434 -161
  34. package/dist/contract-serialization.d.ts +2 -2
  35. package/dist/contract-serialization.js +7 -14
  36. package/dist/contract-types.d.ts +3 -2
  37. package/dist/contract.d.ts +3 -3
  38. package/dist/contract.js +6 -6
  39. package/dist/declaration-validation.d.ts +23 -0
  40. package/dist/declaration-validation.js +159 -0
  41. package/dist/define.d.ts +13 -1
  42. package/dist/define.js +391 -122
  43. package/dist/dev.d.ts +1 -1
  44. package/dist/dev.js +1 -1
  45. package/dist/error-resolution.d.ts +4 -0
  46. package/dist/error-resolution.js +123 -0
  47. package/dist/errors.d.ts +19 -1
  48. package/dist/errors.js +41 -3
  49. package/dist/fixture-sanitization.d.ts +26 -0
  50. package/dist/fixture-sanitization.js +216 -0
  51. package/dist/i18n/catalog.d.ts +2 -2
  52. package/dist/i18n/catalog.js +4 -10
  53. package/dist/i18n/index.d.ts +2 -2
  54. package/dist/i18n/index.js +2 -2
  55. package/dist/i18n/keys.d.ts +2 -2
  56. package/dist/index.d.ts +50 -42
  57. package/dist/index.js +41 -37
  58. package/dist/lint.d.ts +6 -1
  59. package/dist/lint.js +370 -18
  60. package/dist/native-address.d.ts +43 -0
  61. package/dist/native-address.js +281 -0
  62. package/dist/native-egress-policy.d.ts +31 -0
  63. package/dist/native-egress-policy.js +288 -0
  64. package/dist/observability.d.ts +5 -2
  65. package/dist/observability.js +48 -1
  66. package/dist/provider.d.ts +13 -11
  67. package/dist/provider.js +10 -9
  68. package/dist/public-schema-field-lint.d.ts +1 -1
  69. package/dist/recipes/gov-api.js +1 -1
  70. package/dist/runtime/auth-flow.d.ts +3 -1
  71. package/dist/runtime/auth-flow.js +8 -3
  72. package/dist/runtime/browser.d.ts +1 -1
  73. package/dist/runtime/browser.js +138 -40
  74. package/dist/runtime/cache.d.ts +2 -1
  75. package/dist/runtime/cache.js +173 -23
  76. package/dist/runtime/choice-wordlist.d.ts +9 -0
  77. package/dist/runtime/choice-wordlist.js +138 -0
  78. package/dist/runtime/choice.d.ts +14 -1
  79. package/dist/runtime/choice.js +566 -101
  80. package/dist/runtime/credential.d.ts +1 -1
  81. package/dist/runtime/credential.js +1 -1
  82. package/dist/runtime/env.d.ts +1 -1
  83. package/dist/runtime/executor.d.ts +1 -1
  84. package/dist/runtime/executor.js +25 -3
  85. package/dist/runtime/http.d.ts +3 -2
  86. package/dist/runtime/http.js +517 -55
  87. package/dist/runtime/insights.d.ts +1 -1
  88. package/dist/runtime/insights.js +6 -13
  89. package/dist/runtime/instrumentation.d.ts +2 -2
  90. package/dist/runtime/instrumentation.js +371 -23
  91. package/dist/runtime/keyring.js +1 -1
  92. package/dist/runtime/namespace.js +1 -1
  93. package/dist/runtime/native-network-errors.d.ts +33 -0
  94. package/dist/runtime/native-network-errors.js +69 -0
  95. package/dist/runtime/native-network.d.ts +96 -0
  96. package/dist/runtime/native-network.js +1232 -0
  97. package/dist/runtime/ocr.d.ts +29 -0
  98. package/dist/runtime/ocr.js +440 -0
  99. package/dist/runtime/otlp.d.ts +1 -1
  100. package/dist/runtime/perf.d.ts +1 -1
  101. package/dist/runtime/provider.d.ts +1 -1
  102. package/dist/runtime/provider.js +1 -2
  103. package/dist/runtime/proxy-errors.d.ts +1 -1
  104. package/dist/runtime/proxy-errors.js +9 -7
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-retry-policy.d.ts +2 -2
  108. package/dist/runtime/proxy-retry-policy.js +2 -2
  109. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  110. package/dist/runtime/proxy-telemetry.js +58 -52
  111. package/dist/runtime/redirects.d.ts +29 -0
  112. package/dist/runtime/redirects.js +36 -0
  113. package/dist/runtime/redis.d.ts +1 -1
  114. package/dist/runtime/redis.js +5 -5
  115. package/dist/runtime/request-options.d.ts +68 -1
  116. package/dist/runtime/request-options.js +548 -0
  117. package/dist/runtime/resolver-config.d.ts +6 -0
  118. package/dist/runtime/resolver-config.js +6 -0
  119. package/dist/runtime/resolver-public.d.ts +1 -0
  120. package/dist/runtime/resolver-public.js +1 -0
  121. package/dist/runtime/resolver-shared.d.ts +3 -0
  122. package/dist/runtime/resolver-shared.js +12 -0
  123. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  124. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  125. package/dist/runtime/resolver-vendors/browser.d.ts +20 -0
  126. package/dist/runtime/resolver-vendors/browser.js +282 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +368 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +83 -0
  132. package/dist/runtime/resolver-vendors/types.js +69 -0
  133. package/dist/runtime/resolver.d.ts +59 -0
  134. package/dist/runtime/resolver.js +705 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +5 -2
  138. package/dist/runtime/state.js +280 -74
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +30 -5
  142. package/dist/runtime/stealth.js +523 -259
  143. package/dist/runtime/stt.d.ts +1 -1
  144. package/dist/runtime/stt.js +12 -27
  145. package/dist/runtime/timeout.d.ts +5 -0
  146. package/dist/runtime/timeout.js +12 -0
  147. package/dist/runtime/trace.d.ts +2 -2
  148. package/dist/runtime/trace.js +2 -4
  149. package/dist/runtime/waterfall.d.ts +1 -1
  150. package/dist/schema.d.ts +1 -1
  151. package/dist/schema.js +7 -15
  152. package/dist/serve.d.ts +1 -1
  153. package/dist/serve.js +1 -1
  154. package/dist/server/index.d.ts +7 -7
  155. package/dist/server/index.js +6 -6
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test-redaction.d.ts +1 -1
  159. package/dist/server/self-test-redaction.js +1 -1
  160. package/dist/server/self-test.d.ts +117 -3
  161. package/dist/server/self-test.js +787 -151
  162. package/dist/server/serve-implementation.d.ts +210 -0
  163. package/dist/server/serve-implementation.js +2078 -0
  164. package/dist/server/serve.d.ts +1 -70
  165. package/dist/server/serve.js +1 -1143
  166. package/dist/server/types.d.ts +34 -9
  167. package/dist/server/types.js +8 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +1 -1
  207. package/dist/stealth/profiles.js +21 -21
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.d.ts +1 -1
  211. package/dist/stream.js +7 -1
  212. package/dist/testing/index.d.ts +3 -2
  213. package/dist/testing/index.js +3 -2
  214. package/dist/testing/run.d.ts +32 -2
  215. package/dist/testing/run.js +488 -28
  216. package/dist/types.d.ts +566 -19
  217. package/dist/types.js +1 -0
  218. package/dist/user-input.d.ts +30 -0
  219. package/dist/user-input.js +66 -0
  220. package/package.json +42 -7
  221. package/src/auth-turn/index.ts +2 -2
  222. package/src/auth.ts +146 -86
  223. package/src/ceremonies/index.ts +167 -92
  224. package/src/cli/commands.ts +10 -0
  225. package/src/cli/create.ts +42 -35
  226. package/src/cli/prompt-assets.ts +865 -0
  227. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  228. package/src/cli/templates/provider/README.md.tpl +4 -4
  229. package/src/config/loader.ts +667 -289
  230. package/src/contract-serialization.ts +10 -18
  231. package/src/contract-types.ts +3 -2
  232. package/src/contract.ts +14 -28
  233. package/src/declaration-validation.ts +202 -0
  234. package/src/define.ts +631 -495
  235. package/src/dev.ts +4 -9
  236. package/src/error-resolution.ts +128 -0
  237. package/src/errors.ts +56 -11
  238. package/src/fixture-sanitization.ts +247 -0
  239. package/src/i18n/catalog.ts +10 -32
  240. package/src/i18n/index.ts +2 -2
  241. package/src/i18n/keys.ts +5 -11
  242. package/src/index.ts +158 -44
  243. package/src/lint.ts +488 -154
  244. package/src/native-address.ts +340 -0
  245. package/src/native-egress-policy.ts +358 -0
  246. package/src/observability.ts +51 -1
  247. package/src/provider.ts +66 -11
  248. package/src/public-schema-field-lint.ts +7 -33
  249. package/src/recipes/gov-api.ts +2 -5
  250. package/src/runtime/auth-flow.ts +13 -7
  251. package/src/runtime/browser.ts +252 -207
  252. package/src/runtime/cache.ts +209 -81
  253. package/src/runtime/choice-wordlist.ts +145 -0
  254. package/src/runtime/choice.ts +758 -197
  255. package/src/runtime/credential.ts +2 -2
  256. package/src/runtime/env.ts +1 -1
  257. package/src/runtime/executor.ts +37 -19
  258. package/src/runtime/http.ts +645 -65
  259. package/src/runtime/insights.ts +15 -53
  260. package/src/runtime/instrumentation.ts +530 -67
  261. package/src/runtime/keyring.ts +7 -19
  262. package/src/runtime/namespace.ts +2 -7
  263. package/src/runtime/native-network-errors.ts +99 -0
  264. package/src/runtime/native-network.ts +1605 -0
  265. package/src/runtime/ocr.ts +523 -0
  266. package/src/runtime/otlp.ts +12 -23
  267. package/src/runtime/perf.ts +1 -1
  268. package/src/runtime/provider.ts +4 -9
  269. package/src/runtime/proxy-errors.ts +29 -42
  270. package/src/runtime/proxy-nodemaven.ts +221 -0
  271. package/src/runtime/proxy-retry-policy.ts +3 -3
  272. package/src/runtime/proxy-telemetry.ts +84 -77
  273. package/src/runtime/redirects.ts +66 -0
  274. package/src/runtime/redis.ts +10 -13
  275. package/src/runtime/request-options.ts +679 -9
  276. package/src/runtime/resolver-config.ts +6 -0
  277. package/src/runtime/resolver-public.ts +18 -0
  278. package/src/runtime/resolver-shared.ts +17 -0
  279. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  280. package/src/runtime/resolver-vendors/browser.ts +408 -0
  281. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  282. package/src/runtime/resolver-vendors/twocaptcha.ts +500 -0
  283. package/src/runtime/resolver-vendors/types.ts +173 -0
  284. package/src/runtime/resolver.ts +1060 -0
  285. package/src/runtime/secrets.ts +64 -0
  286. package/src/runtime/state.ts +399 -161
  287. package/src/runtime/stealth-cookies.ts +132 -0
  288. package/src/runtime/stealth.ts +681 -295
  289. package/src/runtime/stt.ts +39 -113
  290. package/src/runtime/timeout.ts +18 -0
  291. package/src/runtime/trace.ts +14 -44
  292. package/src/runtime/waterfall.ts +5 -18
  293. package/src/schema.ts +23 -84
  294. package/src/serve.ts +6 -1
  295. package/src/server/index.ts +30 -7
  296. package/src/server/self-test-input-tokens.ts +29 -14
  297. package/src/server/self-test-redaction.ts +2 -2
  298. package/src/server/self-test.ts +1030 -180
  299. package/src/server/serve-implementation.ts +3062 -0
  300. package/src/server/serve.ts +1 -1781
  301. package/src/server/types.ts +12 -13
  302. package/src/stateful/README.md +146 -0
  303. package/src/stateful/errors.ts +35 -0
  304. package/src/stateful/http-provider-event-emitter.ts +314 -0
  305. package/src/stateful/http-session-owner-registry.ts +306 -0
  306. package/src/stateful/index.ts +18 -0
  307. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  308. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  309. package/src/stateful/provider-event-pipeline.ts +61 -0
  310. package/src/stateful/provider-events.ts +462 -0
  311. package/src/stateful/session-key.ts +111 -0
  312. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  313. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  314. package/src/stateful/stateful-provider-adapter.ts +562 -0
  315. package/src/stateful/stateful-provider-observability.ts +261 -0
  316. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  317. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  318. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  319. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  320. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  321. package/src/stateful-signing.ts +46 -0
  322. package/src/stealth/profiles.ts +27 -33
  323. package/src/stream-evidence.ts +988 -0
  324. package/src/stream.ts +16 -20
  325. package/src/testing/index.ts +11 -2
  326. package/src/testing/run.ts +668 -74
  327. package/src/types.ts +665 -35
  328. package/src/user-input.ts +118 -0
  329. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  330. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  331. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  332. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  333. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  334. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  335. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  336. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  337. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  338. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  339. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  340. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  341. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  342. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/dist/dev.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderDefinition } from "./types";
1
+ import type { ProviderDefinition } from "./types.js";
2
2
  export interface DevServerOptions {
3
3
  port?: number;
4
4
  sessionDbPath?: string;
package/dist/dev.js CHANGED
@@ -1,4 +1,4 @@
1
- import { serve } from "./server/serve";
1
+ import { serve } from "./server/serve.js";
2
2
  export function createDevServer(provider, options) {
3
3
  const port = options?.port ?? 3900;
4
4
  return {
@@ -0,0 +1,4 @@
1
+ import type { ProviderErrorStatus } from "./types.js";
2
+ export declare const SDK_OWNED_PROVIDER_ERROR_CODES: Set<string>;
3
+ export declare const SDK_RUNTIME_OWNED_ERROR_CODES: Set<string>;
4
+ export declare const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES: ReadonlyMap<string, ProviderErrorStatus>;
@@ -0,0 +1,123 @@
1
+ // This set suppresses the unregistered-provider-error-code signal for codes
2
+ // intentionally emitted by SDK paths. It is not the complete authority for
3
+ // runtime error resolution: branded errors and additional canonical SDK codes
4
+ // must also remain immune to provider-declared status/retryability overrides.
5
+ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
6
+ "MISSING_SECRET",
7
+ "AUTH_PROMPT_UNAVAILABLE",
8
+ "BROWSER_CDP_POOL_REQUIRED",
9
+ "BROWSER_RUNTIME_UNSUPPORTED",
10
+ "STEALTH_RUNTIME_UNSUPPORTED",
11
+ "SSE_EVENT_UNDECLARED",
12
+ "STREAM_EVENT_TOO_LARGE",
13
+ "STREAM_CHUNK_TOO_LARGE",
14
+ "SSE_RESULT_UNSUPPORTED",
15
+ "STREAM_RESULT_UNSUPPORTED",
16
+ "AUTH_FLOW_NOT_CONFIGURED",
17
+ "refresh_not_supported",
18
+ "RUNTIME_UNSUPPORTED",
19
+ "PROVIDER_STATE_UNSUPPORTED",
20
+ "CHOICE_TOKEN_MASTER_SECRET_NOT_CONFIGURED",
21
+ "CHOICE_WORD_ISSUANCE_INVALID",
22
+ "CHOICE_STATE_PAYLOAD_TOO_LARGE",
23
+ "CHOICE_STATE_UNAVAILABLE",
24
+ "CHOICE_CONTEXT_REQUIRED",
25
+ "unsupported_stealth_cookie_store_version",
26
+ "provider_secret_error",
27
+ "credential_key_error",
28
+ "credential_mode_error",
29
+ "flow_expired",
30
+ "turn_validation_error",
31
+ "context_access_error",
32
+ "OCR_UPSTREAM_FAILED",
33
+ "UNSUPPORTED_STT_OPTION",
34
+ "INVALID_STT_AUDIO",
35
+ "STT_AUDIO_TOO_LARGE",
36
+ "STT_UPSTREAM_FAILED",
37
+ "INVALID_STT_VERIFICATION_CODE_OPTIONS",
38
+ "NO_CODE_FOUND",
39
+ "AMBIGUOUS_CODE",
40
+ "retry_invalid_policy",
41
+ "retry_unsafe_method",
42
+ "stealth_cookie_store_serialize_failed",
43
+ "response_too_large",
44
+ "transport_stream_unavailable",
45
+ "transport_invalid_method",
46
+ "http_transport_override_unsupported",
47
+ "http_redirect_policy_invalid",
48
+ "http_redirect_stopped",
49
+ "http_redirect_max_hops",
50
+ "http_redirect_missing_location",
51
+ "http_redirect_loop",
52
+ "transport_invalid_url",
53
+ "retry_exhausted",
54
+ "auth_abort_unsafe_data",
55
+ "credentials_auth_missing_credential_keys",
56
+ "credentials_auth_missing_credential",
57
+ "credentials_auth_invalid_login_result",
58
+ "credentials_auth_unknown_challenge",
59
+ "credentials_auth_unknown_pending_challenge",
60
+ "STATEFUL_FORWARDING_NOT_CONFIGURED",
61
+ "STATEFUL_FORWARDING_SIGNATURE_MISSING",
62
+ "STATEFUL_FORWARDING_NONCE_INVALID",
63
+ "STATEFUL_FORWARDING_TIMESTAMP_INVALID",
64
+ "STATEFUL_FORWARDING_SIGNATURE_INVALID",
65
+ "STATEFUL_FORWARDING_REPLAY_DETECTED",
66
+ "STATEFUL_FORWARDING_REPLAY_CACHE_FULL",
67
+ "STATEFUL_FORWARDING_ENVELOPE_INVALID",
68
+ "STATEFUL_FORWARDING_PROVIDER_MISMATCH",
69
+ "STATEFUL_FORWARDING_SOURCE_POD_MISMATCH",
70
+ "STATEFUL_FORWARDING_OWNER_FENCE_INVALID",
71
+ "STATEFUL_FORWARDING_REQUEST_FAILED",
72
+ "STATEFUL_FORWARDING_CONTEXT_MISSING",
73
+ "STATEFUL_FORWARDING_BAD_RESPONSE",
74
+ "STATEFUL_INTERNAL_EXECUTOR_NOT_CONFIGURED",
75
+ "STATEFUL_FILE_FORWARDING_UNSUPPORTED",
76
+ "STATEFUL_CONTROL_PLANE_OPERATION_AMBIGUOUS",
77
+ "STATEFUL_CONTROL_PLANE_REQUEST_FAILED",
78
+ "STATEFUL_CONTROL_PLANE_HTTP_ERROR",
79
+ "STATEFUL_CONTROL_PLANE_INVALID_RESPONSE",
80
+ ]);
81
+ // Complete code authority for provider-declared runtime resolution. Keep this
82
+ // separate from signal suppression: declarations may document these codes, but
83
+ // their status and retryability can never override the SDK's canonical result.
84
+ export const SDK_RUNTIME_OWNED_ERROR_CODES = new Set([
85
+ ...SDK_OWNED_PROVIDER_ERROR_CODES,
86
+ "reauth_required",
87
+ "OCR_UNAVAILABLE",
88
+ "UNSUPPORTED_OCR_BACKEND",
89
+ "STT_UNAVAILABLE",
90
+ "UNSUPPORTED_STT_BACKEND",
91
+ "OUTPUT_VALIDATION_FAILED",
92
+ "NOT_FOUND",
93
+ "not_found",
94
+ ]);
95
+ // Canonical SDK status mapping for recognized provider-thrown error codes.
96
+ // serve.ts toStatusCode consults this map (after operation-declared overrides
97
+ // for non-SDK-owned codes), and the authoring lint treats these codes as
98
+ // SDK-registered. Add new codes here instead of duplicating literals in
99
+ // either consumer.
100
+ export const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES = new Map([
101
+ ["AUTH_REQUIRED", 401],
102
+ ["reauth_required", 401],
103
+ // Unprovisioned declared secret: a deployment/config defect, never an
104
+ // upstream failure — explicit 400.
105
+ ["MISSING_SECRET", 400],
106
+ ["NOT_FOUND", 404],
107
+ ["not_found", 404],
108
+ ["NO_DATA", 404],
109
+ ["RATE_LIMITED", 429],
110
+ ["UPSTREAM_RATE_LIMIT", 429],
111
+ ["LIMITED_NUMBER_OF_SERVICE_REQUESTS_EXCEEDS_ERROR", 429],
112
+ // Deterministic upstream business refusal (honest-provider-error-
113
+ // contract): the upstream evaluated the request and said no under its
114
+ // own rules — a conflict with upstream state, never a 5xx.
115
+ ["UPSTREAM_REJECTED", 409],
116
+ ["UPSTREAM_ERROR", 502],
117
+ ["BLOCKED", 502],
118
+ ["OCR_UNAVAILABLE", 503],
119
+ ["UNSUPPORTED_OCR_BACKEND", 503],
120
+ ["STT_UNAVAILABLE", 503],
121
+ ["UNSUPPORTED_STT_BACKEND", 503],
122
+ ["STATEFUL_FORWARDING_REPLAY_CACHE_FULL", 503],
123
+ ]);
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { ProviderErrorCategory } from "./observability";
1
+ import type { ProviderErrorCategory } from "./observability.js";
2
+ import type { HttpRedirectFailureReason } from "./types.js";
2
3
  export type ProviderErrorOptions = {
3
4
  fix?: string;
4
5
  code?: string;
@@ -17,6 +18,11 @@ export declare class ProviderError extends Error {
17
18
  export declare class SDKError extends ProviderError {
18
19
  constructor(message: string, options?: ProviderErrorOptions);
19
20
  }
21
+ /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
22
+ export declare class StealthCookieStoreVersionError extends SDKError {
23
+ readonly version: unknown;
24
+ constructor(version: unknown);
25
+ }
20
26
  export declare class AuthError extends ProviderError {
21
27
  constructor(message: string, options?: ProviderErrorOptions);
22
28
  }
@@ -39,9 +45,21 @@ export declare class TransportError extends ProviderError {
39
45
  readonly upstreamStatus?: number;
40
46
  constructor(message: string, options?: TransportErrorOptions);
41
47
  }
48
+ export type HttpRedirectErrorOptions = TransportErrorOptions & {
49
+ reason: HttpRedirectFailureReason;
50
+ /** Redacted redirect target suitable for provider diagnostics. */
51
+ target?: string;
52
+ };
53
+ /** Raised when an opt-in ctx.http redirect policy refuses or cannot resolve a hop. */
54
+ export declare class HttpRedirectError extends TransportError {
55
+ readonly reason: HttpRedirectFailureReason;
56
+ readonly target?: string;
57
+ constructor(message: string, options: HttpRedirectErrorOptions);
58
+ }
42
59
  export declare function isProviderError(value: unknown): value is ProviderError;
43
60
  export declare function isSessionExpiredError(value: unknown): value is SessionExpiredError;
44
61
  export declare function isTransportError(value: unknown): value is TransportError;
62
+ export declare function isValidationError(value: unknown): value is ValidationError;
45
63
  export declare class ProviderSecretError extends ProviderError {
46
64
  constructor(message: string, options?: ProviderErrorOptions);
47
65
  }
package/dist/errors.js CHANGED
@@ -8,6 +8,7 @@ const PROVIDER_ERROR_BRAND = Symbol.for("@apifuse/provider-sdk/error-brand@1");
8
8
  const PROVIDER_ERROR_BRAND_VALUE = 1;
9
9
  const SESSION_EXPIRED_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/session-expired@1");
10
10
  const TRANSPORT_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/transport@1");
11
+ const VALIDATION_BRAND = Symbol.for("@apifuse/provider-sdk/error-kind/validation@1");
11
12
  // Defines a non-enumerable, non-writable, non-configurable own data property.
12
13
  // Immutable + own means a guard can trust it via a single descriptor read
13
14
  // without invoking attacker-controlled getters or accepting inherited brands.
@@ -28,9 +29,7 @@ function hasOwnBrand(value, brand, expected) {
28
29
  return false;
29
30
  }
30
31
  const descriptor = Object.getOwnPropertyDescriptor(value, brand);
31
- return (descriptor !== undefined &&
32
- Object.hasOwn(descriptor, "value") &&
33
- descriptor.value === expected);
32
+ return (descriptor !== undefined && Object.hasOwn(descriptor, "value") && descriptor.value === expected);
34
33
  }
35
34
  export class ProviderError extends Error {
36
35
  options;
@@ -59,6 +58,21 @@ export class SDKError extends ProviderError {
59
58
  this.name = "SDKError";
60
59
  }
61
60
  }
61
+ /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
62
+ export class StealthCookieStoreVersionError extends SDKError {
63
+ version;
64
+ constructor(version) {
65
+ const displayedVersion = typeof version === "string" || typeof version === "number"
66
+ ? String(version)
67
+ : "missing or invalid";
68
+ super(`Unsupported stealth cookie store version: ${displayedVersion}`, {
69
+ code: "unsupported_stealth_cookie_store_version",
70
+ details: { receivedVersion: version, supportedVersions: [1] },
71
+ });
72
+ this.version = version;
73
+ this.name = "StealthCookieStoreVersionError";
74
+ }
75
+ }
62
76
  export class AuthError extends ProviderError {
63
77
  constructor(message, options) {
64
78
  super(message, options);
@@ -83,6 +97,7 @@ export class ValidationError extends ProviderError {
83
97
  super(message, options);
84
98
  this.name = "ValidationError";
85
99
  this.zodError = options?.zodError;
100
+ defineErrorBrand(this, VALIDATION_BRAND, true);
86
101
  }
87
102
  }
88
103
  export class TransportError extends ProviderError {
@@ -96,6 +111,25 @@ export class TransportError extends ProviderError {
96
111
  defineErrorBrand(this, TRANSPORT_BRAND, true);
97
112
  }
98
113
  }
114
+ /** Raised when an opt-in ctx.http redirect policy refuses or cannot resolve a hop. */
115
+ export class HttpRedirectError extends TransportError {
116
+ reason;
117
+ target;
118
+ constructor(message, options) {
119
+ const { reason, target, ...transportOptions } = options;
120
+ super(message, {
121
+ ...transportOptions,
122
+ code: `http_redirect_${reason}`,
123
+ details: {
124
+ reason,
125
+ ...(target ? { target } : {}),
126
+ },
127
+ });
128
+ this.name = "HttpRedirectError";
129
+ this.reason = reason;
130
+ this.target = target;
131
+ }
132
+ }
99
133
  // Cross-module type guards. Prefer these over `instanceof` at any boundary that
100
134
  // may receive an error from a different copy/entrypoint of the SDK (see the HTTP
101
135
  // server error boundary). They recognize branded errors regardless of which
@@ -109,6 +143,10 @@ export function isSessionExpiredError(value) {
109
143
  export function isTransportError(value) {
110
144
  return isProviderError(value) && hasOwnBrand(value, TRANSPORT_BRAND, true);
111
145
  }
146
+ export function isValidationError(value) {
147
+ return (isProviderError(value) &&
148
+ (hasOwnBrand(value, VALIDATION_BRAND, true) || value.name === "ValidationError"));
149
+ }
112
150
  export class ProviderSecretError extends ProviderError {
113
151
  constructor(message, options) {
114
152
  super(message, { code: "provider_secret_error", ...options });
@@ -0,0 +1,26 @@
1
+ import type { JsonValue } from "./contract-json.js";
2
+ export declare const REDACTED_FIXTURE_VALUE = "[REDACTED]";
3
+ /** Matches credential field names without treating benign prefixes such as `author` as `auth`. */
4
+ export declare function isSensitiveFixtureKey(key: string): boolean;
5
+ /**
6
+ * Returns JSON fixture data with credential-bearing keys and heuristic-confirmed string secrets
7
+ * replaced. Ordinary short prose and identifiers are retained.
8
+ */
9
+ export declare function sanitizeFixture(value: JsonValue): JsonValue;
10
+ /** Applies the shared credential-key policy to ordinary JSON fixtures. */
11
+ export declare function sanitizeOrdinaryFixture(value: JsonValue): JsonValue;
12
+ /** Sanitizes a primitive fixture string only when textual-secret heuristics match. */
13
+ export declare function sanitizeFixtureString(value: string): string;
14
+ /** True for opaque values that are unsafe to retain in paths or unstructured text. */
15
+ export declare function isSensitiveFixtureValue(value: string): boolean;
16
+ /** Sanitizes every path segment and values following a credential-like segment name. */
17
+ export declare function sanitizePathname(pathname: string): string;
18
+ /** Removes userinfo, query values, fragments, and credential-like path segments from log URLs. */
19
+ export declare function sanitizeUrlForLogs(value: string): string;
20
+ /**
21
+ * Returns query-free request provenance with each path segment scrubbed for credential-like values.
22
+ * Origins, URL userinfo, query values, and fragments are never persisted in request provenance.
23
+ */
24
+ export declare function requestPathForFixture(value: string): string;
25
+ /** Scrubs secrets and terminal/log control characters before diagnostic text is emitted. */
26
+ export declare function sanitizeDiagnosticText(value: string): string;
@@ -0,0 +1,216 @@
1
+ export const REDACTED_FIXTURE_VALUE = "[REDACTED]";
2
+ const OPAQUE_TOKEN = /^[A-Za-z0-9_+/=.:~-]+$/;
3
+ const OPAQUE_TOKEN_RUN = /[A-Za-z0-9_+/=.:~-]{24,}/g;
4
+ const URL_RUN = /https?:\/\/[^\s"'<>]+/gi;
5
+ const PEM_PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g;
6
+ /** Matches credential field names without treating benign prefixes such as `author` as `auth`. */
7
+ export function isSensitiveFixtureKey(key) {
8
+ const normalized = key.replace(/[-_\s]/g, "").toLowerCase();
9
+ const candidates = [normalized, normalized.replace(/(?:value|payload|header)$/, "")];
10
+ return candidates.some((candidate) => /^(?:authorization|authentication|auth|bearer|cookie|credential|password|passwd|privatekey|secret|session|sessionid|token)$/.test(candidate) ||
11
+ /^(?:api|client|service|access|consumer)(?:key|secret|token)$/.test(candidate) ||
12
+ /(?:authorization|credential|password|passwd|privatekey|secret|sessionid|token)$/.test(candidate));
13
+ }
14
+ /**
15
+ * Returns JSON fixture data with credential-bearing keys and heuristic-confirmed string secrets
16
+ * replaced. Ordinary short prose and identifiers are retained.
17
+ */
18
+ export function sanitizeFixture(value) {
19
+ if (Array.isArray(value)) {
20
+ return value.map((item) => sanitizeFixture(item));
21
+ }
22
+ if (typeof value === "string")
23
+ return sanitizeFixtureString(value);
24
+ if (value === null || typeof value !== "object")
25
+ return value;
26
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
27
+ key,
28
+ isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeFixture(entryValue),
29
+ ]));
30
+ }
31
+ /** Applies the shared credential-key policy to ordinary JSON fixtures. */
32
+ export function sanitizeOrdinaryFixture(value) {
33
+ if (Array.isArray(value))
34
+ return value.map((item) => sanitizeOrdinaryFixture(item));
35
+ if (value === null || typeof value !== "object")
36
+ return value;
37
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
38
+ key,
39
+ isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeOrdinaryFixture(entryValue),
40
+ ]));
41
+ }
42
+ /** Sanitizes a primitive fixture string only when textual-secret heuristics match. */
43
+ export function sanitizeFixtureString(value) {
44
+ let sanitized = value.replace(PEM_PRIVATE_KEY, REDACTED_FIXTURE_VALUE);
45
+ const retainedUrls = [];
46
+ sanitized = sanitized.replace(URL_RUN, (url) => {
47
+ const index = retainedUrls.push(isCredentialBearingUrl(url) ? sanitizeUrlForLogs(url) : url) - 1;
48
+ return `APIFUSEURL${index}X`;
49
+ });
50
+ sanitized = redactSensitiveAssignments(sanitized);
51
+ sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate) => isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate);
52
+ sanitized = sanitized.replace(/APIFUSEURL(\d+)X/g, (_match, index) => retainedUrls[Number(index)] ?? REDACTED_FIXTURE_VALUE);
53
+ return sanitized;
54
+ }
55
+ /** True for opaque values that are unsafe to retain in paths or unstructured text. */
56
+ export function isSensitiveFixtureValue(value) {
57
+ const candidate = decodePathSegment(value);
58
+ if (/^bot(?:\d{6,}:)?[A-Za-z0-9_-]{16,}$/i.test(candidate))
59
+ return true;
60
+ if (/^\d{6,}:[A-Za-z0-9_-]{20,}$/.test(candidate))
61
+ return true;
62
+ if (/^(?:gh[opusr]_|sk[-_]|xox[baprs]-)[A-Za-z0-9_-]{16,}$/i.test(candidate))
63
+ return true;
64
+ if (!OPAQUE_TOKEN.test(candidate) || candidate.length < 24)
65
+ return false;
66
+ if (/^[a-f0-9]{32,}$/i.test(candidate))
67
+ return true;
68
+ return shannonEntropy(candidate) >= 3.5;
69
+ }
70
+ /** Sanitizes every path segment and values following a credential-like segment name. */
71
+ export function sanitizePathname(pathname) {
72
+ const segments = pathname.split("/");
73
+ return segments
74
+ .map((segment, index) => {
75
+ if (!segment)
76
+ return segment;
77
+ const decoded = decodePathSegment(segment);
78
+ const previous = index > 0 ? decodePathSegment(segments[index - 1]) : "";
79
+ if (isSensitivePathSegment(decoded) ||
80
+ isCredentialPathKey(previous) ||
81
+ isSensitiveFixtureValue(decoded)) {
82
+ return REDACTED_FIXTURE_VALUE;
83
+ }
84
+ return segment;
85
+ })
86
+ .join("/");
87
+ }
88
+ function isCredentialPathKey(key) {
89
+ const finalPathPart = key.split("/").at(-1) ?? "";
90
+ const baseSegment = finalPathPart.split(";", 1)[0] ?? "";
91
+ return isSensitiveFixtureKey(baseSegment.split(/[=:]/, 1)[0] ?? "");
92
+ }
93
+ function isSensitivePathSegment(segment) {
94
+ return segment
95
+ .split(/[;/]/)
96
+ .some((part) => isSensitiveFixtureKey(part.split(/[=:]/, 1)[0] ?? ""));
97
+ }
98
+ /** Removes userinfo, query values, fragments, and credential-like path segments from log URLs. */
99
+ export function sanitizeUrlForLogs(value) {
100
+ try {
101
+ const parsed = new URL(value, "https://fixture.invalid");
102
+ const queryMarker = parsed.search ? `?${REDACTED_FIXTURE_VALUE}` : "";
103
+ const path = sanitizePathname(parsed.pathname);
104
+ if (parsed.origin === "https://fixture.invalid" && !hasExplicitOrigin(value)) {
105
+ return `${path}${queryMarker}`;
106
+ }
107
+ return `${parsed.origin}${path}${queryMarker}`;
108
+ }
109
+ catch {
110
+ return sanitizePathname(value.split(/[?#]/, 1)[0]);
111
+ }
112
+ }
113
+ /**
114
+ * Returns query-free request provenance with each path segment scrubbed for credential-like values.
115
+ * Origins, URL userinfo, query values, and fragments are never persisted in request provenance.
116
+ */
117
+ export function requestPathForFixture(value) {
118
+ try {
119
+ return sanitizePathname(new URL(value, "https://fixture.invalid").pathname);
120
+ }
121
+ catch {
122
+ const path = value.split(/[?#]/, 1)[0];
123
+ return sanitizePathname(path.startsWith("/") ? path : `/${path}`);
124
+ }
125
+ }
126
+ /** Scrubs secrets and terminal/log control characters before diagnostic text is emitted. */
127
+ export function sanitizeDiagnosticText(value) {
128
+ let sanitized = value
129
+ .replace(URL_RUN, (url) => sanitizeUrlForLogs(url))
130
+ .replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, `Bearer ${REDACTED_FIXTURE_VALUE}`);
131
+ sanitized = redactSensitiveAssignments(sanitized);
132
+ sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate, offset, source) => {
133
+ if (/^(?:request|trace|correlation)[-_]?id[:=]/i.test(candidate))
134
+ return candidate;
135
+ const prefix = source.slice(Math.max(0, offset - 32), offset);
136
+ if (/(?:request|trace|correlation)[-_]?id\s*[:=]\s*$/i.test(prefix))
137
+ return candidate;
138
+ return isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate;
139
+ });
140
+ return encodeDiagnosticControls(sanitized);
141
+ }
142
+ function redactSensitiveAssignments(value) {
143
+ return value.replace(/((["']?)([\w-]+)\2\s*[:=]\s*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;&]+)/gi, (match, prefix, _quote, key, assignmentValue) => {
144
+ if (!isSensitiveFixtureKey(key) && key.toLowerCase() !== "key")
145
+ return match;
146
+ const quote = assignmentValue.startsWith('"')
147
+ ? '"'
148
+ : assignmentValue.startsWith("'")
149
+ ? "'"
150
+ : "";
151
+ return `${prefix}${quote}${REDACTED_FIXTURE_VALUE}${quote}`;
152
+ });
153
+ }
154
+ function isCredentialBearingUrl(value) {
155
+ try {
156
+ const parsed = new URL(value);
157
+ return (parsed.username !== "" ||
158
+ parsed.password !== "" ||
159
+ parsed.hash !== "" ||
160
+ parsed.search !== "" ||
161
+ parsed.pathname.split("/").some((segment, index, segments) => {
162
+ const decoded = decodePathSegment(segment);
163
+ const previous = decodePathSegment(segments[index - 1] ?? "");
164
+ return (isSensitiveFixtureKey(decoded) ||
165
+ isCredentialPathKey(previous) ||
166
+ isSensitiveFixtureValue(decoded));
167
+ }));
168
+ }
169
+ catch {
170
+ return false;
171
+ }
172
+ }
173
+ function encodeDiagnosticControls(value) {
174
+ let result = "";
175
+ for (const character of value) {
176
+ const code = character.codePointAt(0) ?? 0;
177
+ if (code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029) {
178
+ result += " ";
179
+ }
180
+ else if ((code >= 0 && code <= 0x1f) ||
181
+ (code >= 0x7f && code <= 0x9f) ||
182
+ code === 0x061c ||
183
+ code === 0x200e ||
184
+ code === 0x200f ||
185
+ (code >= 0x202a && code <= 0x202e) ||
186
+ (code >= 0x2066 && code <= 0x2069)) {
187
+ result += `\\u${code.toString(16).padStart(4, "0")}`;
188
+ }
189
+ else {
190
+ result += character;
191
+ }
192
+ }
193
+ return result;
194
+ }
195
+ function decodePathSegment(value) {
196
+ try {
197
+ return decodeURIComponent(value);
198
+ }
199
+ catch {
200
+ return value;
201
+ }
202
+ }
203
+ function hasExplicitOrigin(value) {
204
+ return /^[a-z][a-z\d+.-]*:\/\//i.test(value);
205
+ }
206
+ function shannonEntropy(value) {
207
+ const counts = new Map();
208
+ for (const character of value)
209
+ counts.set(character, (counts.get(character) ?? 0) + 1);
210
+ let entropy = 0;
211
+ for (const count of counts.values()) {
212
+ const probability = count / value.length;
213
+ entropy -= probability * Math.log2(probability);
214
+ }
215
+ return entropy;
216
+ }
@@ -1,5 +1,5 @@
1
- import type { AuthTurn } from "../types";
2
- import { type ProviderLocale, type ProviderLocaleCatalog, type ProviderLocaleKey, type ProviderLocaleValue } from "./keys";
1
+ import type { AuthTurn } from "../types.js";
2
+ import { type ProviderLocale, type ProviderLocaleCatalog, type ProviderLocaleKey, type ProviderLocaleValue } from "./keys.js";
3
3
  export type ProviderLocaleCatalogMap = Record<ProviderLocale, ProviderLocaleCatalog>;
4
4
  export interface LoadProviderLocaleCatalogsOptions {
5
5
  providerDir: string;
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { getProviderLocalePath, isProviderLocaleValue, providerLocaleKey, } from "./keys";
3
+ import { getProviderLocalePath, isProviderLocaleValue, providerLocaleKey, } from "./keys.js";
4
4
  export function loadProviderLocaleCatalogs(options) {
5
5
  const catalogs = {};
6
6
  for (const locale of options.locales) {
@@ -26,9 +26,7 @@ function isStringRecord(value) {
26
26
  function localizeAuthInputSchema(expectedInput, options) {
27
27
  if (!expectedInput)
28
28
  return undefined;
29
- const schema = isRecord(expectedInput.schema)
30
- ? expectedInput.schema
31
- : expectedInput;
29
+ const schema = isRecord(expectedInput.schema) ? expectedInput.schema : expectedInput;
32
30
  const localizedSchema = localizeAuthSchemaObject(schema, options);
33
31
  if (localizedSchema === schema)
34
32
  return undefined;
@@ -40,9 +38,7 @@ function isRecord(value) {
40
38
  return !!value && typeof value === "object" && !Array.isArray(value);
41
39
  }
42
40
  function localizeAuthSchemaObject(schema, options) {
43
- const properties = isRecord(schema.properties)
44
- ? schema.properties
45
- : undefined;
41
+ const properties = isRecord(schema.properties) ? schema.properties : undefined;
46
42
  if (!properties)
47
43
  return schema;
48
44
  let changed = false;
@@ -50,9 +46,7 @@ function localizeAuthSchemaObject(schema, options) {
50
46
  if (!isRecord(property))
51
47
  return [fieldName, property];
52
48
  const nameKey = typeof property.nameKey === "string" ? property.nameKey : undefined;
53
- const descriptionKey = typeof property.descriptionKey === "string"
54
- ? property.descriptionKey
55
- : undefined;
49
+ const descriptionKey = typeof property.descriptionKey === "string" ? property.descriptionKey : undefined;
56
50
  const title = nameKey
57
51
  ? asStringValue(resolveProviderLocaleValue(options.catalogs, nameKey, options.locale, options.fallbackLocale))
58
52
  : undefined;
@@ -1,2 +1,2 @@
1
- export * from "./catalog";
2
- export * from "./keys";
1
+ export * from "./catalog.js";
2
+ export * from "./keys.js";
@@ -1,2 +1,2 @@
1
- export * from "./catalog";
2
- export * from "./keys";
1
+ export * from "./catalog.js";
2
+ export * from "./keys.js";
@@ -1,5 +1,5 @@
1
- import type { ProviderLocaleKey } from "../types";
2
- export type { ProviderLocale, ProviderLocaleKey } from "../types";
1
+ import type { ProviderLocaleKey } from "../types.js";
2
+ export type { ProviderLocale, ProviderLocaleKey } from "../types.js";
3
3
  export declare function providerLocaleKey(key: string): ProviderLocaleKey;
4
4
  export declare function isProviderLocaleKey(value: unknown): value is ProviderLocaleKey;
5
5
  export declare function assertProviderLocaleKey(value: unknown): asserts value is ProviderLocaleKey;