@apifuse/provider-sdk 2.1.0-beta.9 → 2.2.0-beta.10

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 (263) hide show
  1. package/AUTHORING.md +240 -0
  2. package/CHANGELOG.md +93 -0
  3. package/README.md +26 -10
  4. package/SUBMISSION.md +11 -12
  5. package/bin/apifuse-check.ts +44 -59
  6. package/bin/apifuse-create.ts +1 -1
  7. package/bin/apifuse-dev.ts +27 -52
  8. package/bin/apifuse-pack-check.ts +36 -0
  9. package/bin/apifuse-pack-smoke.ts +22 -81
  10. package/bin/apifuse-pack-types.ts +266 -0
  11. package/bin/apifuse-perf.ts +45 -127
  12. package/bin/apifuse-record.ts +53 -70
  13. package/bin/apifuse-submit-check.ts +2177 -353
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/apifuse.ts +1 -1
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/bin/submit-check-xml-semantics.ts +204 -0
  18. package/bin/submit-check-xml.ts +134 -0
  19. package/dist/auth-turn/auth-turn.v1.schema.json +89 -0
  20. package/dist/auth-turn/fixtures/invalid/empty-kind.json +4 -0
  21. package/dist/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
  22. package/dist/auth-turn/fixtures/invalid/missing-kind.json +3 -0
  23. package/dist/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
  24. package/dist/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
  25. package/dist/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
  26. package/dist/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
  27. package/dist/auth-turn/fixtures/valid/abort.json +8 -0
  28. package/dist/auth-turn/fixtures/valid/challenge.json +17 -0
  29. package/dist/auth-turn/fixtures/valid/complete.json +13 -0
  30. package/dist/auth-turn/fixtures/valid/form.json +14 -0
  31. package/dist/auth-turn/fixtures/valid/message.json +13 -0
  32. package/dist/auth-turn/fixtures/valid/multi_choice.json +15 -0
  33. package/dist/auth-turn/fixtures/valid/pending.json +5 -0
  34. package/dist/auth-turn/fixtures/valid/poll.json +9 -0
  35. package/dist/auth-turn/fixtures/valid/redirect.json +16 -0
  36. package/dist/auth-turn/fixtures/valid/retry.json +8 -0
  37. package/dist/auth-turn/fixtures/valid/unknown-kind.json +7 -0
  38. package/dist/auth-turn/index.d.ts +195 -0
  39. package/dist/auth-turn/index.js +133 -0
  40. package/dist/auth.d.ts +76 -0
  41. package/dist/auth.js +427 -0
  42. package/dist/ceremonies/index.d.ts +1 -1
  43. package/dist/ceremonies/index.js +14 -48
  44. package/dist/cli/commands.d.ts +1 -1
  45. package/dist/cli/commands.js +8 -0
  46. package/dist/cli/create.d.ts +3 -0
  47. package/dist/cli/create.js +47 -33
  48. package/dist/cli/prompt-assets.d.ts +80 -0
  49. package/dist/cli/prompt-assets.js +743 -0
  50. package/dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  51. package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  52. package/dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
  53. package/dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  54. package/dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  55. package/dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
  56. package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
  57. package/dist/cli/templates/provider/.gitignore.tpl +22 -0
  58. package/dist/cli/templates/provider/AGENTS.md.tpl +96 -0
  59. package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
  60. package/dist/cli/templates/provider/README.md.tpl +163 -0
  61. package/dist/cli/templates/provider/dev.ts.tpl +5 -0
  62. package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
  63. package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
  64. package/dist/cli/templates/provider/index.ts.tpl +15 -0
  65. package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
  66. package/dist/cli/templates/provider/meta.ts.tpl +7 -0
  67. package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
  68. package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
  69. package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  70. package/dist/cli/templates/provider/start.ts.tpl +5 -0
  71. package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
  72. package/dist/config/loader.d.ts +149 -8
  73. package/dist/config/loader.js +378 -89
  74. package/dist/contract-serialization.d.ts +2 -2
  75. package/dist/contract-serialization.js +3 -6
  76. package/dist/contract-types.d.ts +2 -2
  77. package/dist/contract.d.ts +3 -3
  78. package/dist/contract.js +5 -6
  79. package/dist/define.d.ts +13 -1
  80. package/dist/define.js +245 -178
  81. package/dist/dev.d.ts +1 -1
  82. package/dist/dev.js +1 -1
  83. package/dist/errors.d.ts +4 -1
  84. package/dist/errors.js +48 -0
  85. package/dist/i18n/catalog.d.ts +2 -2
  86. package/dist/i18n/catalog.js +4 -10
  87. package/dist/i18n/index.d.ts +2 -2
  88. package/dist/i18n/index.js +2 -2
  89. package/dist/i18n/keys.d.ts +2 -2
  90. package/dist/index.d.ts +44 -41
  91. package/dist/index.js +39 -36
  92. package/dist/lint.d.ts +1 -0
  93. package/dist/lint.js +35 -15
  94. package/dist/provider.d.ts +11 -9
  95. package/dist/provider.js +9 -8
  96. package/dist/public-schema-field-lint.d.ts +1 -1
  97. package/dist/recipes/gov-api.js +1 -1
  98. package/dist/runtime/auth-flow.d.ts +1 -1
  99. package/dist/runtime/auth-flow.js +4 -2
  100. package/dist/runtime/browser.d.ts +1 -1
  101. package/dist/runtime/browser.js +214 -25
  102. package/dist/runtime/cache.d.ts +1 -1
  103. package/dist/runtime/cache.js +4 -8
  104. package/dist/runtime/choice.d.ts +1 -1
  105. package/dist/runtime/choice.js +31 -35
  106. package/dist/runtime/credential.d.ts +1 -1
  107. package/dist/runtime/credential.js +1 -1
  108. package/dist/runtime/env.d.ts +1 -1
  109. package/dist/runtime/executor.d.ts +1 -1
  110. package/dist/runtime/executor.js +15 -3
  111. package/dist/runtime/http.d.ts +2 -2
  112. package/dist/runtime/http.js +160 -344
  113. package/dist/runtime/insights.d.ts +1 -1
  114. package/dist/runtime/insights.js +6 -13
  115. package/dist/runtime/instrumentation.d.ts +2 -2
  116. package/dist/runtime/instrumentation.js +56 -19
  117. package/dist/runtime/keyring.js +1 -1
  118. package/dist/runtime/namespace.js +1 -1
  119. package/dist/runtime/otlp.d.ts +1 -1
  120. package/dist/runtime/perf.d.ts +1 -1
  121. package/dist/runtime/provider.d.ts +1 -1
  122. package/dist/runtime/provider.js +1 -2
  123. package/dist/runtime/proxy-errors.d.ts +1 -1
  124. package/dist/runtime/proxy-errors.js +9 -7
  125. package/dist/runtime/proxy-nodemaven.d.ts +35 -0
  126. package/dist/runtime/proxy-nodemaven.js +128 -0
  127. package/dist/runtime/proxy-retry-policy.d.ts +40 -0
  128. package/dist/runtime/proxy-retry-policy.js +326 -0
  129. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  130. package/dist/runtime/proxy-telemetry.js +55 -52
  131. package/dist/runtime/redis.d.ts +1 -1
  132. package/dist/runtime/redis.js +2 -4
  133. package/dist/runtime/request-options.d.ts +1 -1
  134. package/dist/runtime/secrets.d.ts +27 -0
  135. package/dist/runtime/secrets.js +51 -0
  136. package/dist/runtime/state.d.ts +2 -2
  137. package/dist/runtime/state.js +15 -4
  138. package/dist/runtime/stealth.d.ts +7 -4
  139. package/dist/runtime/stealth.js +257 -215
  140. package/dist/runtime/stt.d.ts +1 -1
  141. package/dist/runtime/stt.js +11 -15
  142. package/dist/runtime/trace.d.ts +2 -2
  143. package/dist/runtime/trace.js +2 -4
  144. package/dist/runtime/waterfall.d.ts +1 -1
  145. package/dist/schema.d.ts +1 -1
  146. package/dist/schema.js +7 -15
  147. package/dist/serve.d.ts +1 -1
  148. package/dist/serve.js +1 -1
  149. package/dist/server/index.d.ts +7 -3
  150. package/dist/server/index.js +6 -2
  151. package/dist/server/self-test-input-tokens.d.ts +1 -0
  152. package/dist/server/self-test-input-tokens.js +37 -0
  153. package/dist/server/self-test-redaction.d.ts +20 -0
  154. package/dist/server/self-test-redaction.js +70 -0
  155. package/dist/server/self-test-token.d.ts +30 -0
  156. package/dist/server/self-test-token.js +50 -0
  157. package/dist/server/self-test.d.ts +199 -0
  158. package/dist/server/self-test.js +1113 -0
  159. package/dist/server/serve.d.ts +14 -3
  160. package/dist/server/serve.js +135 -64
  161. package/dist/server/types.d.ts +10 -9
  162. package/dist/server/types.js +3 -7
  163. package/dist/stealth/profiles.d.ts +1 -1
  164. package/dist/stealth/profiles.js +5 -14
  165. package/dist/stream.d.ts +1 -1
  166. package/dist/testing/index.d.ts +2 -2
  167. package/dist/testing/index.js +2 -2
  168. package/dist/testing/run.d.ts +1 -1
  169. package/dist/testing/run.js +12 -15
  170. package/dist/types.d.ts +237 -1
  171. package/dist/user-input.d.ts +30 -0
  172. package/dist/user-input.js +66 -0
  173. package/package.json +16 -5
  174. package/src/auth-turn/auth-turn.v1.schema.json +89 -0
  175. package/src/auth-turn/fixtures/invalid/empty-kind.json +4 -0
  176. package/src/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
  177. package/src/auth-turn/fixtures/invalid/missing-kind.json +3 -0
  178. package/src/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
  179. package/src/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
  180. package/src/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
  181. package/src/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
  182. package/src/auth-turn/fixtures/valid/abort.json +8 -0
  183. package/src/auth-turn/fixtures/valid/challenge.json +17 -0
  184. package/src/auth-turn/fixtures/valid/complete.json +13 -0
  185. package/src/auth-turn/fixtures/valid/form.json +14 -0
  186. package/src/auth-turn/fixtures/valid/message.json +13 -0
  187. package/src/auth-turn/fixtures/valid/multi_choice.json +15 -0
  188. package/src/auth-turn/fixtures/valid/pending.json +5 -0
  189. package/src/auth-turn/fixtures/valid/poll.json +9 -0
  190. package/src/auth-turn/fixtures/valid/redirect.json +16 -0
  191. package/src/auth-turn/fixtures/valid/retry.json +8 -0
  192. package/src/auth-turn/fixtures/valid/unknown-kind.json +7 -0
  193. package/src/auth-turn/index.ts +177 -0
  194. package/src/auth.ts +728 -0
  195. package/src/ceremonies/index.ts +33 -121
  196. package/src/cli/commands.ts +10 -0
  197. package/src/cli/create.ts +69 -99
  198. package/src/cli/prompt-assets.ts +865 -0
  199. package/src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  200. package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  201. package/src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
  202. package/src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  203. package/src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  204. package/src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
  205. package/src/cli/templates/provider/AGENTS.md.tpl +96 -0
  206. package/src/cli/templates/provider/README.md.tpl +7 -4
  207. package/src/config/loader.ts +543 -208
  208. package/src/contract-serialization.ts +5 -11
  209. package/src/contract-types.ts +2 -2
  210. package/src/contract.ts +13 -28
  211. package/src/define.ts +397 -528
  212. package/src/dev.ts +4 -9
  213. package/src/errors.ts +58 -5
  214. package/src/i18n/catalog.ts +10 -32
  215. package/src/i18n/index.ts +2 -2
  216. package/src/i18n/keys.ts +5 -11
  217. package/src/index.ts +64 -41
  218. package/src/lint.ts +122 -159
  219. package/src/provider.ts +40 -9
  220. package/src/public-schema-field-lint.ts +7 -33
  221. package/src/recipes/gov-api.ts +2 -5
  222. package/src/runtime/auth-flow.ts +6 -6
  223. package/src/runtime/browser.ts +320 -151
  224. package/src/runtime/cache.ts +20 -67
  225. package/src/runtime/choice.ts +79 -132
  226. package/src/runtime/credential.ts +2 -2
  227. package/src/runtime/env.ts +1 -1
  228. package/src/runtime/executor.ts +23 -20
  229. package/src/runtime/http.ts +216 -539
  230. package/src/runtime/insights.ts +15 -53
  231. package/src/runtime/instrumentation.ts +78 -65
  232. package/src/runtime/keyring.ts +7 -19
  233. package/src/runtime/namespace.ts +2 -7
  234. package/src/runtime/otlp.ts +12 -23
  235. package/src/runtime/perf.ts +1 -1
  236. package/src/runtime/provider.ts +4 -9
  237. package/src/runtime/proxy-errors.ts +29 -42
  238. package/src/runtime/proxy-nodemaven.ts +178 -0
  239. package/src/runtime/proxy-retry-policy.ts +469 -0
  240. package/src/runtime/proxy-telemetry.ts +79 -77
  241. package/src/runtime/redis.ts +4 -12
  242. package/src/runtime/request-options.ts +4 -13
  243. package/src/runtime/secrets.ts +64 -0
  244. package/src/runtime/state.ts +41 -110
  245. package/src/runtime/stealth.ts +331 -369
  246. package/src/runtime/stt.ts +38 -94
  247. package/src/runtime/trace.ts +14 -44
  248. package/src/runtime/waterfall.ts +5 -18
  249. package/src/schema.ts +23 -84
  250. package/src/serve.ts +1 -1
  251. package/src/server/index.ts +44 -3
  252. package/src/server/self-test-input-tokens.ts +46 -0
  253. package/src/server/self-test-redaction.ts +97 -0
  254. package/src/server/self-test-token.ts +70 -0
  255. package/src/server/self-test.ts +1450 -0
  256. package/src/server/serve.ts +206 -216
  257. package/src/server/types.ts +7 -19
  258. package/src/stealth/profiles.ts +10 -26
  259. package/src/stream.ts +8 -19
  260. package/src/testing/index.ts +2 -2
  261. package/src/testing/run.ts +24 -64
  262. package/src/types.ts +274 -1
  263. package/src/user-input.ts +118 -0
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import { type ProviderErrorCategory } from "../observability";
3
- import type { ProviderDefinition, ProviderRuntimeState, SttContext } from "../types";
4
- import { type OperationRequest } from "./types";
2
+ import { type ProviderErrorCategory } from "../observability.js";
3
+ import type { ProviderDefinition, ProviderRuntimeState, SttContext } from "../types.js";
4
+ import { type OperationRequest } from "./types.js";
5
5
  export declare function resolveProviderProxyAffinityKey(provider: ProviderDefinition, request: OperationRequest, operationId: string): string;
6
6
  type ProviderRequestCost = {
7
7
  durationMs: number;
@@ -35,6 +35,11 @@ export type ProviderServerLogEvent = (ProviderServerLogEventBase & {
35
35
  message: string;
36
36
  }>;
37
37
  }) | {
38
+ level: "warn";
39
+ event: "provider_secrets_missing";
40
+ providerId: string;
41
+ missingSecrets: string[];
42
+ } | {
38
43
  level: "warn";
39
44
  event: "provider_cleanup_failed";
40
45
  providerId: string;
@@ -59,6 +64,12 @@ export declare function createServerApp(provider: ProviderDefinition, options?:
59
64
  export interface ServeOptions extends ProviderServerOptions {
60
65
  host?: string;
61
66
  port?: number;
67
+ /**
68
+ * Port for the internal self-test listener (default 3001 or
69
+ * APIFUSE__PROVIDER_RUNTIME__SELF_TEST_PORT). The listener only starts
70
+ * when APIFUSE__PROVIDER_RUNTIME__SELF_TEST_MASTER_SECRET is present.
71
+ */
72
+ selfTestPort?: number;
62
73
  }
63
74
  export declare function serve(provider: ProviderDefinition, options?: ServeOptions): Promise<void>;
64
75
  export {};
@@ -2,29 +2,33 @@ import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { Hono } from "hono";
4
4
  import { z } from "zod";
5
- import { AuthError, ProviderError, SessionExpiredError, TransportError, } from "../errors";
6
- import { loadProviderLocaleCatalogs, localizeAuthTurn, } from "../i18n/catalog";
7
- import { categoryForStatus, isRetryableCategory, PROVIDER_OBSERVABILITY_TAXONOMY_VERSION, } from "../observability";
8
- import { createScratchpad } from "../runtime/auth-flow";
9
- import { createBrowserClient } from "../runtime/browser";
10
- import { createProviderCache } from "../runtime/cache";
11
- import { createProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "../runtime/choice";
12
- import { createCredentialContext } from "../runtime/credential";
13
- import { createEnvContext } from "../runtime/env";
14
- import { executeOperation } from "../runtime/executor";
15
- import { createHttpClient } from "../runtime/http";
16
- import { wrapWithInstrumentation } from "../runtime/instrumentation";
17
- import { getProviderBaseUrl } from "../runtime/provider";
18
- import { PROXY_AUTH_IP_DENIED_CODE, PROXY_EDGE_AUTH_REJECTED_CODE, PROXY_POOL_EXHAUSTED_CODE, } from "../runtime/proxy-errors";
19
- import { PROVIDER_TELEMETRY_HEADER, ProxyTelemetryCollector, } from "../runtime/proxy-telemetry";
20
- import { createProviderRuntimeStateFromEnv, createUnsupportedProviderRuntimeState, } from "../runtime/state";
21
- import { createStealthClient } from "../runtime/stealth";
22
- import { createSttClientFromEnv } from "../runtime/stt";
23
- import { createTraceContext } from "../runtime/trace";
24
- import { parseSchema } from "../schema";
25
- import { getStealthProfile } from "../stealth/profiles";
26
- import { APIFUSE_STREAM_DONE_EVENT, APIFUSE_STREAM_ERROR_EVENT, encodeSseEvent, error as streamError, } from "../stream";
27
- import { AuthFlowRequestSchema, OperationRequestSchema, } from "./types";
5
+ import { AuthAbortError, createAuthFlowHelpers } from "../auth.js";
6
+ import { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, } from "../errors.js";
7
+ import { loadProviderLocaleCatalogs, localizeAuthTurn, } from "../i18n/catalog.js";
8
+ import { categoryForStatus, isRetryableCategory, PROVIDER_OBSERVABILITY_TAXONOMY_VERSION, } from "../observability.js";
9
+ import { createScratchpad } from "../runtime/auth-flow.js";
10
+ import { createBrowserClient } from "../runtime/browser.js";
11
+ import { createProviderCache } from "../runtime/cache.js";
12
+ import { createProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "../runtime/choice.js";
13
+ import { createCredentialContext } from "../runtime/credential.js";
14
+ import { createEnvContext } from "../runtime/env.js";
15
+ import { executeOperation } from "../runtime/executor.js";
16
+ import { createHttpClient } from "../runtime/http.js";
17
+ import { wrapWithInstrumentation } from "../runtime/instrumentation.js";
18
+ import { getProviderBaseUrl } from "../runtime/provider.js";
19
+ import { PROXY_AUTH_IP_DENIED_CODE, PROXY_EDGE_AUTH_REJECTED_CODE, PROXY_POOL_EXHAUSTED_CODE, } from "../runtime/proxy-errors.js";
20
+ import { PROVIDER_TELEMETRY_HEADER, ProxyTelemetryCollector } from "../runtime/proxy-telemetry.js";
21
+ import { assertRequiredSecretsPresent, listMissingRequiredSecrets, MISSING_SECRET_CODE, } from "../runtime/secrets.js";
22
+ import { createProviderRuntimeStateFromEnv, createUnsupportedProviderRuntimeState, } from "../runtime/state.js";
23
+ import { createStealthClient } from "../runtime/stealth.js";
24
+ import { createSttClientFromEnv } from "../runtime/stt.js";
25
+ import { createTraceContext } from "../runtime/trace.js";
26
+ import { parseSchema } from "../schema.js";
27
+ import { getStealthProfile } from "../stealth/profiles.js";
28
+ import { APIFUSE_STREAM_DONE_EVENT, APIFUSE_STREAM_ERROR_EVENT, encodeSseEvent, error as streamError, } from "../stream.js";
29
+ import { createSelfTestApp, createSelfTestAuthFlowInvoke, createSelfTestInvoke, resolveSelfTestPort, } from "./self-test.js";
30
+ import { resolveSelfTestMasterSecrets } from "./self-test-token.js";
31
+ import { AuthFlowRequestSchema, OperationRequestSchema, } from "./types.js";
28
32
  const DEFAULT_HOST = "0.0.0.0";
29
33
  const DEFAULT_PORT = 3000;
30
34
  const AUTH_FLOW_LOCALES = ["en", "ko", "ja"];
@@ -90,9 +94,7 @@ function getProviderStealthBaseUrl(provider) {
90
94
  return firstHost ? `https://${firstHost}` : undefined;
91
95
  }
92
96
  function getProviderStealthProfile(provider) {
93
- return provider.stealth?.profile
94
- ? getStealthProfile(provider.stealth.profile)
95
- : undefined;
97
+ return provider.stealth?.profile ? getStealthProfile(provider.stealth.profile) : undefined;
96
98
  }
97
99
  function isProductionProviderBrowserMode(provider, env = process.env) {
98
100
  if (provider.runtime !== "browser") {
@@ -101,18 +103,19 @@ function isProductionProviderBrowserMode(provider, env = process.env) {
101
103
  if (env.APIFUSE__PROVIDER__RUNTIME === "browser") {
102
104
  return true;
103
105
  }
104
- return (env.NODE_ENV === "production" && env.APIFUSE__PROVIDER__ID === provider.id);
106
+ return env.NODE_ENV === "production" && env.APIFUSE__PROVIDER__ID === provider.id;
105
107
  }
106
108
  export function resolveProviderProxyAffinityKey(provider, request, operationId) {
107
- const connectionKey = request.connection?.id ?? request.connection?.externalRef;
108
- const affinity = typeof provider.proxy === "object"
109
- ? provider.proxy.session?.affinity
110
- : undefined;
109
+ const connectionKey = resolveOperationConnectionId(request) ?? request.connection?.externalRef;
110
+ const affinity = typeof provider.proxy === "object" ? provider.proxy.session?.affinity : undefined;
111
111
  if (affinity === "operation") {
112
112
  return `${provider.id}/${operationId}`;
113
113
  }
114
114
  return connectionKey ?? provider.id;
115
115
  }
116
+ function resolveOperationConnectionId(request) {
117
+ return request.connection?.id ?? request.connectionId;
118
+ }
116
119
  function createProviderContext(provider, request, operationId, options = {}, state = createUnsupportedProviderRuntimeState(), proxyTelemetry) {
117
120
  const baseUrl = getProviderBaseUrl(provider);
118
121
  const stealthBaseUrl = getProviderStealthBaseUrl(provider);
@@ -139,7 +142,7 @@ function createProviderContext(provider, request, operationId, options = {}, sta
139
142
  values: request.connection?.secrets,
140
143
  });
141
144
  const requestContext = {
142
- connectionId: request.connection?.id,
145
+ connectionId: resolveOperationConnectionId(request),
143
146
  headers: request.headers ?? {},
144
147
  };
145
148
  const context = wrapWithInstrumentation({
@@ -209,7 +212,7 @@ function createFlowContextStore(allowedKeys, initialContext = {}) {
209
212
  },
210
213
  };
211
214
  }
212
- function createAuthFlowContext(provider, request, options = {}) {
215
+ function createAuthFlowContext(provider, request, options = {}, signal) {
213
216
  const baseUrl = getProviderBaseUrl(provider);
214
217
  const stealthBaseUrl = getProviderStealthBaseUrl(provider);
215
218
  const stealthProfile = getProviderStealthProfile(provider);
@@ -251,6 +254,7 @@ function createAuthFlowContext(provider, request, options = {}) {
251
254
  credential,
252
255
  context: flowContextStore.context,
253
256
  stt: options.stt ?? createSttClientFromEnv(provider.stt),
257
+ auth: createAuthFlowHelpers({ signal }),
254
258
  },
255
259
  getPatch: flowContextStore.getPatch,
256
260
  };
@@ -286,7 +290,7 @@ function zodDetails(error) {
286
290
  }));
287
291
  }
288
292
  function toErrorResponse(error, requestId) {
289
- if (error instanceof ProviderError) {
293
+ if (isProviderError(error)) {
290
294
  const details = publicProviderErrorDetails(error);
291
295
  return {
292
296
  error: {
@@ -308,11 +312,22 @@ function toErrorResponse(error, requestId) {
308
312
  },
309
313
  };
310
314
  }
315
+ // A masked internal error MUST NOT be advertised as retryable: without an
316
+ // explicit retryable:false the hub (bori provider-backed engine) defaults 5xx
317
+ // to retryable:true, which turns a deterministic pre-upstream crash into an
318
+ // infinite START->CONTINUE->restart loop (2026-07-22 catchtable reserve RCA).
319
+ // We still refuse to leak message/stack — only the error class name (or the
320
+ // primitive type for non-Error throwables) is surfaced for ops triage.
311
321
  return {
312
322
  error: {
313
323
  code: "internal_error",
314
324
  message: "Internal error",
315
325
  ...(requestId ? { requestId } : {}),
326
+ details: {
327
+ retryable: false,
328
+ category: "internal_error",
329
+ errorClass: error instanceof Error ? error.name : typeof error,
330
+ },
316
331
  },
317
332
  };
318
333
  }
@@ -336,20 +351,37 @@ function publicProviderErrorDetails(error) {
336
351
  function isPlainRecord(value) {
337
352
  return value !== null && typeof value === "object" && !Array.isArray(value);
338
353
  }
354
+ // Accepts `unknown` so the branded guards narrow cleanly from the top: the
355
+ // subtype error classes are structurally compatible with ProviderError, so
356
+ // narrowing from a ProviderError-typed value would collapse the negative branch
357
+ // to `never`. Narrowing from unknown avoids that while still recognizing errors
358
+ // from a duplicate SDK module instance.
339
359
  function providerObservabilityDetails(error) {
340
360
  // Session-expiry surfaces the credential_expired category + the opt-in
341
361
  // retryable signal so Gateway/Credential Service can refresh and re-drive the
342
362
  // operation (see design.md §4.3 D3). Without this branch the auth error would
343
363
  // serialize as a bare 401 with no retryable/category, losing the refresh
344
364
  // signal for exactly the retryOnAuthRefresh operations it is meant to enable.
345
- if (error instanceof SessionExpiredError) {
365
+ if (isSessionExpiredError(error)) {
346
366
  return {
347
367
  category: error.options?.category ?? "credential_expired",
348
368
  taxonomyVersion: PROVIDER_OBSERVABILITY_TAXONOMY_VERSION,
349
369
  retryable: error.options?.retryable ?? false,
350
370
  };
351
371
  }
352
- if (!(error instanceof TransportError)) {
372
+ // Missing-secret errors carry the canonical credential_unavailable category
373
+ // so Gateway/observability can attribute the failure to provisioning, not
374
+ // the upstream. Matched by code (not constructor) so both the SDK-owned
375
+ // runtime gate and any not-yet-migrated provider-thrown MISSING_SECRET
376
+ // serialize identically, including across duplicate SDK module instances.
377
+ if (isProviderError(error) && error.code === MISSING_SECRET_CODE) {
378
+ return {
379
+ category: error.options?.category ?? "credential_unavailable",
380
+ taxonomyVersion: PROVIDER_OBSERVABILITY_TAXONOMY_VERSION,
381
+ retryable: error.options?.retryable ?? false,
382
+ };
383
+ }
384
+ if (!isTransportError(error)) {
353
385
  return undefined;
354
386
  }
355
387
  const isProxyPoolCode = error.code === PROXY_POOL_EXHAUSTED_CODE ||
@@ -378,7 +410,7 @@ function providerObservabilityDetails(error) {
378
410
  };
379
411
  }
380
412
  function publicProviderErrorMessage(error) {
381
- if (error instanceof TransportError) {
413
+ if (isTransportError(error)) {
382
414
  if (error.code === PROXY_AUTH_IP_DENIED_CODE) {
383
415
  return error.message;
384
416
  }
@@ -406,14 +438,18 @@ function toStatusCode(error) {
406
438
  if (error instanceof z.ZodError) {
407
439
  return 400;
408
440
  }
409
- if (error instanceof TransportError) {
441
+ if (isTransportError(error)) {
410
442
  return error.code === "transport_timeout" ? 504 : 502;
411
443
  }
412
- if (error instanceof ProviderError) {
444
+ if (isProviderError(error)) {
413
445
  switch (error.code) {
414
446
  case "AUTH_REQUIRED":
415
447
  case "reauth_required":
416
448
  return 401;
449
+ // Unprovisioned declared secret: a deployment/config defect, never an
450
+ // upstream failure — explicit 400 (was only reached via fallthrough).
451
+ case MISSING_SECRET_CODE:
452
+ return 400;
417
453
  case "NOT_FOUND":
418
454
  case "not_found":
419
455
  case "NO_DATA":
@@ -441,16 +477,14 @@ function extractRequestId(raw) {
441
477
  return typeof value === "string" ? value : undefined;
442
478
  }
443
479
  function logProviderError(logger, provider, kind, route, requestId, error, status, cost) {
444
- const code = error instanceof ProviderError
480
+ const code = isProviderError(error)
445
481
  ? (error.code ?? "provider_error")
446
482
  : error instanceof z.ZodError
447
483
  ? "invalid_request"
448
484
  : "internal_error";
449
485
  const errorClass = error instanceof Error ? error.name : typeof error;
450
486
  const message = error instanceof Error ? error.message : String(error);
451
- const details = error instanceof ProviderError
452
- ? providerObservabilityDetails(error)
453
- : undefined;
487
+ const details = isProviderError(error) ? providerObservabilityDetails(error) : undefined;
454
488
  const emit = typeof logger === "function" ? logger : defaultProviderServerLogger;
455
489
  emit({
456
490
  level: status >= 500 ? "error" : "warn",
@@ -464,7 +498,7 @@ function logProviderError(logger, provider, kind, route, requestId, error, statu
464
498
  code,
465
499
  errorClass,
466
500
  message,
467
- ...(error instanceof TransportError && error.upstreamStatus
501
+ ...(isTransportError(error) && error.upstreamStatus
468
502
  ? { upstreamStatus: error.upstreamStatus }
469
503
  : {}),
470
504
  ...(details
@@ -587,8 +621,7 @@ async function validateSseEvent(operation, event) {
587
621
  const transport = getSseTransport(operation);
588
622
  const schema = transport?.events?.[event.event];
589
623
  if (!schema) {
590
- if (event.event === APIFUSE_STREAM_ERROR_EVENT ||
591
- event.event === APIFUSE_STREAM_DONE_EVENT) {
624
+ if (event.event === APIFUSE_STREAM_ERROR_EVENT || event.event === APIFUSE_STREAM_DONE_EVENT) {
592
625
  return event;
593
626
  }
594
627
  throw new ProviderError(`SSE event "${event.event}" is not declared in operation transport.events.`, {
@@ -707,8 +740,7 @@ function enforceStreamChunkLimit(body, maxChunkBytes) {
707
740
  }
708
741
  function toStreamingResponse(operation, result, cleanup, requestId) {
709
742
  const transport = operation.transport?.kind ?? "json";
710
- if (transport === "sse" &&
711
- (result instanceof Response || result instanceof ReadableStream)) {
743
+ if (transport === "sse" && (result instanceof Response || result instanceof ReadableStream)) {
712
744
  void cleanup();
713
745
  throw new ProviderError("SSE operations must return an AsyncIterable of typed stream.event(...) values.", {
714
746
  code: "SSE_RESULT_UNSUPPORTED",
@@ -719,9 +751,7 @@ function toStreamingResponse(operation, result, cleanup, requestId) {
719
751
  }
720
752
  if (result instanceof Response) {
721
753
  const httpTransport = getHttpStreamTransport(operation);
722
- if (httpTransport &&
723
- result.body &&
724
- httpTransport?.maxChunkBytes !== undefined) {
754
+ if (httpTransport && result.body && httpTransport?.maxChunkBytes !== undefined) {
725
755
  return responseWithCleanup(new Response(enforceStreamChunkLimit(result.body, httpTransport.maxChunkBytes), {
726
756
  headers: result.headers,
727
757
  status: result.status,
@@ -740,8 +770,7 @@ function toStreamingResponse(operation, result, cleanup, requestId) {
740
770
  ? { "Content-Type": "text/event-stream; charset=utf-8" }
741
771
  : {
742
772
  "Content-Type": operation.transport?.kind === "http-stream"
743
- ? (operation.transport.contentType ??
744
- "application/octet-stream")
773
+ ? (operation.transport.contentType ?? "application/octet-stream")
745
774
  : "application/octet-stream",
746
775
  },
747
776
  }), cleanup);
@@ -759,9 +788,7 @@ function getSseTransport(operation) {
759
788
  return operation.transport?.kind === "sse" ? operation.transport : undefined;
760
789
  }
761
790
  function getHttpStreamTransport(operation) {
762
- return operation.transport?.kind === "http-stream"
763
- ? operation.transport
764
- : undefined;
791
+ return operation.transport?.kind === "http-stream" ? operation.transport : undefined;
765
792
  }
766
793
  function toAuthFlowResponse(result, contextPatch) {
767
794
  if (result instanceof Response) {
@@ -789,7 +816,7 @@ function isAuthFlowLocale(value) {
789
816
  return value === "en" || value === "ko" || value === "ja";
790
817
  }
791
818
  function isAuthTurn(value) {
792
- return (!!value && typeof value === "object" && "kind" in value && "turnId" in value);
819
+ return !!value && typeof value === "object" && "kind" in value && "turnId" in value;
793
820
  }
794
821
  function loadAuthFlowLocaleCatalogs(provider) {
795
822
  for (const providerDir of [
@@ -879,15 +906,23 @@ function responseWithProviderTelemetry(response, proxyTelemetry) {
879
906
  statusText: response.statusText,
880
907
  });
881
908
  }
882
- async function handleAuthFlow(provider, request, route, options = {}) {
909
+ async function handleAuthFlow(provider, request, route, options = {}, signal) {
883
910
  const flow = provider.auth?.flow;
884
911
  if (!flow) {
885
912
  throw new ProviderError("Auth flow is not configured", {
886
913
  code: "AUTH_FLOW_NOT_CONFIGURED",
887
914
  });
888
915
  }
889
- const { context, getPatch } = createAuthFlowContext(provider, request, options);
916
+ // Same SDK-owned gate as executeOperation: OAuth/credentials ceremonies
917
+ // depend on declared secrets (client ids/secrets), so fail structured before
918
+ // any flow code runs instead of at whatever point the ceremony first reads
919
+ // the env. `abort` stays exempt: a user must always be able to cancel a
920
+ // stranded flow even when provisioning is broken.
921
+ const { context, getPatch } = createAuthFlowContext(provider, request, options, signal);
890
922
  try {
923
+ if (route !== "abort") {
924
+ assertRequiredSecretsPresent(provider, context.env);
925
+ }
891
926
  const result = route === "start"
892
927
  ? await flow.start(context)
893
928
  : route === "continue"
@@ -916,6 +951,12 @@ async function handleAuthFlow(provider, request, route, options = {}) {
916
951
  : result;
917
952
  return toAuthFlowResponse(materializedResult, getPatch());
918
953
  }
954
+ catch (error) {
955
+ if (error instanceof AuthAbortError) {
956
+ return toAuthFlowResponse(error.turn, getPatch());
957
+ }
958
+ throw error;
959
+ }
919
960
  finally {
920
961
  context.stealth.close?.();
921
962
  }
@@ -928,6 +969,20 @@ export function createServerApp(provider, options = {}) {
928
969
  providerId: provider.id,
929
970
  allowMemoryFallback: options.allowMemoryStateFallback === true,
930
971
  });
972
+ // Boot-time visibility for unprovisioned declared secrets: emit a structured
973
+ // warn so deploy tooling/alerting sees the gap the moment the pod boots,
974
+ // instead of discovering it request-by-request. Deliberately log-only — a
975
+ // boot crash would trade a structured MISSING_SECRET signal for
976
+ // CrashLoopBackOff. Requests still fail closed via the executeOperation gate.
977
+ const missingSecretsAtBoot = listMissingRequiredSecrets(provider, createEnvContext(provider.secrets?.map((secret) => secret.name)));
978
+ if (missingSecretsAtBoot.length > 0) {
979
+ logger({
980
+ level: "warn",
981
+ event: "provider_secrets_missing",
982
+ providerId: provider.id,
983
+ missingSecrets: missingSecretsAtBoot,
984
+ });
985
+ }
931
986
  app.notFound((c) => c.json({
932
987
  error: {
933
988
  code: "not_found",
@@ -982,7 +1037,7 @@ export function createServerApp(provider, options = {}) {
982
1037
  .json()
983
1038
  .catch(() => undefined);
984
1039
  const body = withAuthRequestHeaders(AuthFlowRequestSchema.parse(rawBody), c.req.raw.headers);
985
- const response = await handleAuthFlow(provider, body, "start", options);
1040
+ const response = await handleAuthFlow(provider, body, "start", options, c.req.raw.signal);
986
1041
  logProviderSuccess(logger, provider, "auth", "start", body.requestId, response instanceof Response ? response.status : 200, finishRequestCost(requestCost));
987
1042
  return response instanceof Response ? response : c.json(response);
988
1043
  }
@@ -1002,7 +1057,7 @@ export function createServerApp(provider, options = {}) {
1002
1057
  .json()
1003
1058
  .catch(() => undefined);
1004
1059
  const body = withAuthRequestHeaders(AuthFlowRequestSchema.parse(rawBody), c.req.raw.headers);
1005
- const response = await handleAuthFlow(provider, body, "continue", options);
1060
+ const response = await handleAuthFlow(provider, body, "continue", options, c.req.raw.signal);
1006
1061
  logProviderSuccess(logger, provider, "auth", "continue", body.requestId, response instanceof Response ? response.status : 200, finishRequestCost(requestCost));
1007
1062
  return response instanceof Response ? response : c.json(response);
1008
1063
  }
@@ -1022,7 +1077,7 @@ export function createServerApp(provider, options = {}) {
1022
1077
  .json()
1023
1078
  .catch(() => undefined);
1024
1079
  const body = withAuthRequestHeaders(AuthFlowRequestSchema.parse(rawBody), c.req.raw.headers);
1025
- const response = await handleAuthFlow(provider, body, "poll", options);
1080
+ const response = await handleAuthFlow(provider, body, "poll", options, c.req.raw.signal);
1026
1081
  logProviderSuccess(logger, provider, "auth", "poll", body.requestId, response instanceof Response ? response.status : 200, finishRequestCost(requestCost));
1027
1082
  return response instanceof Response ? response : c.json(response);
1028
1083
  }
@@ -1042,7 +1097,7 @@ export function createServerApp(provider, options = {}) {
1042
1097
  .json()
1043
1098
  .catch(() => undefined);
1044
1099
  const body = withAuthRequestHeaders(AuthFlowRequestSchema.parse(rawBody), c.req.raw.headers);
1045
- const response = await handleAuthFlow(provider, body, "refresh", options);
1100
+ const response = await handleAuthFlow(provider, body, "refresh", options, c.req.raw.signal);
1046
1101
  logProviderSuccess(logger, provider, "auth", "refresh", body.requestId, response instanceof Response ? response.status : 200, finishRequestCost(requestCost));
1047
1102
  return response instanceof Response ? response : c.json(response);
1048
1103
  }
@@ -1062,7 +1117,7 @@ export function createServerApp(provider, options = {}) {
1062
1117
  .json()
1063
1118
  .catch(() => undefined);
1064
1119
  const body = withAuthRequestHeaders(AuthFlowRequestSchema.parse(rawBody), c.req.raw.headers);
1065
- const response = await handleAuthFlow(provider, body, "abort", options);
1120
+ const response = await handleAuthFlow(provider, body, "abort", options, c.req.raw.signal);
1066
1121
  logProviderSuccess(logger, provider, "auth", "disconnect", body.requestId, response instanceof Response ? response.status : 200, finishRequestCost(requestCost));
1067
1122
  return response instanceof Response ? response : c.json(response);
1068
1123
  }
@@ -1106,5 +1161,21 @@ export async function serve(provider, options = {}) {
1106
1161
  hostname: options.host ?? DEFAULT_HOST,
1107
1162
  fetch: app.fetch,
1108
1163
  });
1164
+ // Internal self-test listener (health dependency inversion): a SEPARATE
1165
+ // socket the tenant-facing gateway never dials. Off by default — it only
1166
+ // starts when the shared self-test master secret env is present.
1167
+ const selfTestSecrets = resolveSelfTestMasterSecrets();
1168
+ if (selfTestSecrets) {
1169
+ const selfTestApp = createSelfTestApp(provider, {
1170
+ secrets: selfTestSecrets,
1171
+ invoke: createSelfTestInvoke(app),
1172
+ authFlow: createSelfTestAuthFlowInvoke(app),
1173
+ });
1174
+ bunRuntime.serve({
1175
+ port: options.selfTestPort ?? resolveSelfTestPort(),
1176
+ hostname: options.host ?? DEFAULT_HOST,
1177
+ fetch: selfTestApp.fetch,
1178
+ });
1179
+ }
1109
1180
  await Promise.resolve();
1110
1181
  }
@@ -1,15 +1,15 @@
1
1
  import { z } from "zod";
2
2
  export declare const ConnectionModeSchema: z.ZodEnum<{
3
- credentials: "credentials";
4
3
  none: "none";
4
+ credentials: "credentials";
5
5
  oauth2: "oauth2";
6
6
  "platform-managed": "platform-managed";
7
7
  }>;
8
8
  export declare const OperationConnectionSchema: z.ZodObject<{
9
9
  id: z.ZodString;
10
10
  mode: z.ZodEnum<{
11
- credentials: "credentials";
12
11
  none: "none";
12
+ credentials: "credentials";
13
13
  oauth2: "oauth2";
14
14
  "platform-managed": "platform-managed";
15
15
  }>;
@@ -21,11 +21,12 @@ export declare const OperationConnectionSchema: z.ZodObject<{
21
21
  export declare const OperationRequestSchema: z.ZodObject<{
22
22
  requestId: z.ZodString;
23
23
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
24
+ connectionId: z.ZodOptional<z.ZodString>;
24
25
  connection: z.ZodOptional<z.ZodObject<{
25
26
  id: z.ZodString;
26
27
  mode: z.ZodEnum<{
27
- credentials: "credentials";
28
28
  none: "none";
29
+ credentials: "credentials";
29
30
  oauth2: "oauth2";
30
31
  "platform-managed": "platform-managed";
31
32
  }>;
@@ -54,21 +55,21 @@ export declare const OperationSuccessResponseSchema: z.ZodObject<{
54
55
  stale: z.ZodBoolean;
55
56
  keys: z.ZodArray<z.ZodString>;
56
57
  source: z.ZodOptional<z.ZodEnum<{
57
- loader: "loader";
58
- memory: "memory";
59
58
  mixed: "mixed";
60
59
  redis: "redis";
60
+ memory: "memory";
61
+ loader: "loader";
61
62
  }>>;
62
63
  }, z.core.$strip>>;
63
64
  retry: z.ZodOptional<z.ZodObject<{
64
65
  attempts: z.ZodNumber;
65
66
  retries: z.ZodNumber;
66
67
  preset: z.ZodOptional<z.ZodEnum<{
67
- aggressive_read: "aggressive_read";
68
68
  off: "off";
69
- rate_limit_aware: "rate_limit_aware";
70
- safe_read: "safe_read";
71
69
  transport_transient: "transport_transient";
70
+ safe_read: "safe_read";
71
+ aggressive_read: "aggressive_read";
72
+ rate_limit_aware: "rate_limit_aware";
72
73
  }>>;
73
74
  transport: z.ZodEnum<{
74
75
  native: "native";
@@ -100,8 +101,8 @@ export declare const AuthFlowRequestSchema: z.ZodObject<{
100
101
  connection: z.ZodOptional<z.ZodObject<{
101
102
  id: z.ZodString;
102
103
  mode: z.ZodEnum<{
103
- credentials: "credentials";
104
104
  none: "none";
105
+ credentials: "credentials";
105
106
  oauth2: "oauth2";
106
107
  "platform-managed": "platform-managed";
107
108
  }>;
@@ -1,11 +1,6 @@
1
1
  import { z } from "zod";
2
- import { HttpRetryPreset } from "../types";
3
- export const ConnectionModeSchema = z.enum([
4
- "oauth2",
5
- "credentials",
6
- "platform-managed",
7
- "none",
8
- ]);
2
+ import { HttpRetryPreset } from "../types.js";
3
+ export const ConnectionModeSchema = z.enum(["oauth2", "credentials", "platform-managed", "none"]);
9
4
  export const OperationConnectionSchema = z.object({
10
5
  id: z.string(),
11
6
  mode: ConnectionModeSchema,
@@ -17,6 +12,7 @@ export const OperationConnectionSchema = z.object({
17
12
  export const OperationRequestSchema = z.object({
18
13
  requestId: z.string(),
19
14
  input: z.record(z.string(), z.unknown()),
15
+ connectionId: z.string().optional(),
20
16
  connection: OperationConnectionSchema.optional(),
21
17
  headers: z.record(z.string(), z.string()).optional(),
22
18
  trace: z.record(z.string(), z.string()).optional(),
@@ -1,4 +1,4 @@
1
- import type { StealthProfile } from "../types";
1
+ import type { StealthProfile } from "../types.js";
2
2
  export declare function generateLayer2Headers(profile: StealthProfile): Record<string, string>;
3
3
  export declare function getStealthProfile(name: string): StealthProfile;
4
4
  export declare function listStealthProfiles(): string[];
@@ -1,4 +1,4 @@
1
- import { SDKError } from "../errors";
1
+ import { SDKError } from "../errors.js";
2
2
  const CHROMIUM_HEADER_ORDER = [
3
3
  ":method",
4
4
  ":authority",
@@ -74,12 +74,8 @@ function createProfile(name, definition) {
74
74
  tlsClientIdentifier: definition.tlsClientIdentifier,
75
75
  ja3: definition.ja3,
76
76
  ja4: definition.ja4,
77
- h2Settings: definition.h2Settings
78
- ? { ...definition.h2Settings }
79
- : undefined,
80
- headerOrder: definition.headerOrder
81
- ? [...definition.headerOrder]
82
- : undefined,
77
+ h2Settings: definition.h2Settings ? { ...definition.h2Settings } : undefined,
78
+ headerOrder: definition.headerOrder ? [...definition.headerOrder] : undefined,
83
79
  };
84
80
  }
85
81
  function extractBrowserMajorVersion(profile) {
@@ -120,9 +116,7 @@ export function generateLayer2Headers(profile) {
120
116
  : `"Chromium";v="${majorVersion}", "Google Chrome";v="${majorVersion}", "Not)A;Brand";v="99"`;
121
117
  headers["Sec-Ch-Ua-Platform"] = toPlatformHeaderValue(profile.platform);
122
118
  headers["Sec-Ch-Ua-Mobile"] =
123
- profile.platform === "android" || profile.platform === "ios"
124
- ? "?1"
125
- : "?0";
119
+ profile.platform === "android" || profile.platform === "ios" ? "?1" : "?0";
126
120
  }
127
121
  return headers;
128
122
  }
@@ -252,8 +246,5 @@ export function getStealthProfile(name) {
252
246
  };
253
247
  }
254
248
  export function listStealthProfiles() {
255
- return [
256
- ...Object.keys(STEALTH_PROFILES),
257
- ...Object.keys(STEALTH_PROFILE_ALIASES),
258
- ];
249
+ return [...Object.keys(STEALTH_PROFILES), ...Object.keys(STEALTH_PROFILE_ALIASES)];
259
250
  }
package/dist/stream.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SseMessage } from "./types";
1
+ import type { SseMessage } from "./types.js";
2
2
  export interface SseEvent<TData = unknown> {
3
3
  event: string;
4
4
  data: TData;
@@ -1,2 +1,2 @@
1
- export { describeTransform, snapshotTransform, toMatchShape } from "./helpers";
2
- export { runStandardTests } from "./run";
1
+ export { describeTransform, snapshotTransform, toMatchShape } from "./helpers.js";
2
+ export { runStandardTests } from "./run.js";
@@ -1,2 +1,2 @@
1
- export { describeTransform, snapshotTransform, toMatchShape } from "./helpers";
2
- export { runStandardTests } from "./run";
1
+ export { describeTransform, snapshotTransform, toMatchShape } from "./helpers.js";
2
+ export { runStandardTests } from "./run.js";
@@ -1,4 +1,4 @@
1
- import type { AuthMode, ProviderDefinition } from "../types";
1
+ import type { AuthMode, ProviderDefinition } from "../types.js";
2
2
  export interface StandardTestsManifest {
3
3
  id?: string;
4
4
  displayName?: string;