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

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 (165) hide show
  1. package/AUTHORING.md +53 -0
  2. package/CHANGELOG.md +8 -0
  3. package/bin/apifuse-check.ts +18 -58
  4. package/bin/apifuse-create.ts +1 -1
  5. package/bin/apifuse-dev.ts +27 -52
  6. package/bin/apifuse-pack-smoke.ts +22 -81
  7. package/bin/apifuse-pack-types.ts +266 -0
  8. package/bin/apifuse-perf.ts +45 -127
  9. package/bin/apifuse-record.ts +23 -61
  10. package/bin/apifuse-submit-check.ts +266 -34
  11. package/bin/apifuse.ts +1 -1
  12. package/bin/submit-check-xml.ts +1 -1
  13. package/dist/auth-turn/index.d.ts +1 -1
  14. package/dist/auth.d.ts +2 -2
  15. package/dist/auth.js +9 -18
  16. package/dist/ceremonies/index.d.ts +1 -1
  17. package/dist/ceremonies/index.js +8 -18
  18. package/dist/config/loader.d.ts +2 -2
  19. package/dist/config/loader.js +19 -42
  20. package/dist/contract-serialization.d.ts +2 -2
  21. package/dist/contract-serialization.js +3 -6
  22. package/dist/contract-types.d.ts +2 -2
  23. package/dist/contract.d.ts +3 -3
  24. package/dist/contract.js +4 -6
  25. package/dist/define.d.ts +8 -1
  26. package/dist/define.js +57 -115
  27. package/dist/dev.d.ts +1 -1
  28. package/dist/dev.js +1 -1
  29. package/dist/errors.d.ts +1 -1
  30. package/dist/errors.js +1 -3
  31. package/dist/i18n/catalog.d.ts +2 -2
  32. package/dist/i18n/catalog.js +4 -10
  33. package/dist/i18n/index.d.ts +2 -2
  34. package/dist/i18n/index.js +2 -2
  35. package/dist/i18n/keys.d.ts +2 -2
  36. package/dist/index.d.ts +43 -42
  37. package/dist/index.js +38 -37
  38. package/dist/lint.js +8 -15
  39. package/dist/provider.d.ts +11 -11
  40. package/dist/provider.js +9 -9
  41. package/dist/public-schema-field-lint.d.ts +1 -1
  42. package/dist/recipes/gov-api.js +1 -1
  43. package/dist/runtime/auth-flow.d.ts +1 -1
  44. package/dist/runtime/auth-flow.js +3 -3
  45. package/dist/runtime/browser.d.ts +1 -1
  46. package/dist/runtime/browser.js +15 -29
  47. package/dist/runtime/cache.d.ts +1 -1
  48. package/dist/runtime/cache.js +4 -8
  49. package/dist/runtime/choice.d.ts +1 -1
  50. package/dist/runtime/choice.js +12 -34
  51. package/dist/runtime/credential.d.ts +1 -1
  52. package/dist/runtime/credential.js +1 -1
  53. package/dist/runtime/env.d.ts +1 -1
  54. package/dist/runtime/executor.d.ts +1 -1
  55. package/dist/runtime/executor.js +2 -2
  56. package/dist/runtime/http.d.ts +2 -2
  57. package/dist/runtime/http.js +5 -5
  58. package/dist/runtime/insights.d.ts +1 -1
  59. package/dist/runtime/insights.js +6 -13
  60. package/dist/runtime/instrumentation.d.ts +2 -2
  61. package/dist/runtime/instrumentation.js +5 -15
  62. package/dist/runtime/keyring.js +1 -1
  63. package/dist/runtime/namespace.js +1 -1
  64. package/dist/runtime/otlp.d.ts +1 -1
  65. package/dist/runtime/perf.d.ts +1 -1
  66. package/dist/runtime/provider.d.ts +1 -1
  67. package/dist/runtime/provider.js +1 -2
  68. package/dist/runtime/proxy-errors.d.ts +1 -1
  69. package/dist/runtime/proxy-errors.js +3 -5
  70. package/dist/runtime/proxy-retry-policy.d.ts +2 -2
  71. package/dist/runtime/proxy-retry-policy.js +2 -2
  72. package/dist/runtime/proxy-telemetry.d.ts +1 -1
  73. package/dist/runtime/proxy-telemetry.js +16 -48
  74. package/dist/runtime/redis.d.ts +1 -1
  75. package/dist/runtime/redis.js +2 -4
  76. package/dist/runtime/request-options.d.ts +1 -1
  77. package/dist/runtime/state.d.ts +2 -2
  78. package/dist/runtime/state.js +3 -3
  79. package/dist/runtime/stealth.d.ts +2 -2
  80. package/dist/runtime/stealth.js +6 -6
  81. package/dist/runtime/stt.d.ts +1 -1
  82. package/dist/runtime/stt.js +11 -15
  83. package/dist/runtime/trace.d.ts +2 -2
  84. package/dist/runtime/trace.js +2 -4
  85. package/dist/runtime/waterfall.d.ts +1 -1
  86. package/dist/schema.d.ts +1 -1
  87. package/dist/schema.js +7 -15
  88. package/dist/serve.d.ts +1 -1
  89. package/dist/serve.js +1 -1
  90. package/dist/server/index.d.ts +7 -7
  91. package/dist/server/index.js +6 -6
  92. package/dist/server/self-test-redaction.d.ts +1 -1
  93. package/dist/server/self-test-redaction.js +1 -1
  94. package/dist/server/self-test.d.ts +104 -3
  95. package/dist/server/self-test.js +673 -115
  96. package/dist/server/serve.d.ts +3 -3
  97. package/dist/server/serve.js +37 -49
  98. package/dist/server/types.js +2 -7
  99. package/dist/stealth/profiles.d.ts +1 -1
  100. package/dist/stealth/profiles.js +5 -14
  101. package/dist/stream.d.ts +1 -1
  102. package/dist/testing/index.d.ts +2 -2
  103. package/dist/testing/index.js +2 -2
  104. package/dist/testing/run.d.ts +1 -1
  105. package/dist/testing/run.js +7 -14
  106. package/dist/types.d.ts +57 -0
  107. package/dist/user-input.d.ts +30 -0
  108. package/dist/user-input.js +66 -0
  109. package/package.json +6 -4
  110. package/src/auth-turn/index.ts +1 -1
  111. package/src/auth.ts +28 -86
  112. package/src/ceremonies/index.ts +24 -78
  113. package/src/config/loader.ts +58 -176
  114. package/src/contract-serialization.ts +5 -11
  115. package/src/contract-types.ts +2 -2
  116. package/src/contract.ts +12 -28
  117. package/src/define.ts +174 -495
  118. package/src/dev.ts +4 -9
  119. package/src/errors.ts +4 -11
  120. package/src/i18n/catalog.ts +10 -32
  121. package/src/i18n/index.ts +2 -2
  122. package/src/i18n/keys.ts +5 -11
  123. package/src/index.ts +44 -42
  124. package/src/lint.ts +89 -159
  125. package/src/provider.ts +12 -11
  126. package/src/public-schema-field-lint.ts +7 -33
  127. package/src/recipes/gov-api.ts +2 -5
  128. package/src/runtime/auth-flow.ts +5 -7
  129. package/src/runtime/browser.ts +64 -187
  130. package/src/runtime/cache.ts +20 -67
  131. package/src/runtime/choice.ts +55 -129
  132. package/src/runtime/credential.ts +2 -2
  133. package/src/runtime/env.ts +1 -1
  134. package/src/runtime/executor.ts +9 -19
  135. package/src/runtime/http.ts +7 -7
  136. package/src/runtime/insights.ts +15 -53
  137. package/src/runtime/instrumentation.ts +19 -58
  138. package/src/runtime/keyring.ts +7 -19
  139. package/src/runtime/namespace.ts +2 -7
  140. package/src/runtime/otlp.ts +12 -23
  141. package/src/runtime/perf.ts +1 -1
  142. package/src/runtime/provider.ts +4 -9
  143. package/src/runtime/proxy-errors.ts +17 -38
  144. package/src/runtime/proxy-retry-policy.ts +3 -3
  145. package/src/runtime/proxy-telemetry.ts +23 -72
  146. package/src/runtime/redis.ts +4 -12
  147. package/src/runtime/request-options.ts +4 -13
  148. package/src/runtime/state.ts +30 -109
  149. package/src/runtime/stealth.ts +8 -8
  150. package/src/runtime/stt.ts +38 -94
  151. package/src/runtime/trace.ts +14 -44
  152. package/src/runtime/waterfall.ts +5 -18
  153. package/src/schema.ts +23 -84
  154. package/src/serve.ts +1 -1
  155. package/src/server/index.ts +12 -7
  156. package/src/server/self-test-redaction.ts +2 -2
  157. package/src/server/self-test.ts +857 -132
  158. package/src/server/serve.ts +89 -238
  159. package/src/server/types.ts +6 -19
  160. package/src/stealth/profiles.ts +10 -26
  161. package/src/stream.ts +8 -19
  162. package/src/testing/index.ts +2 -2
  163. package/src/testing/run.ts +19 -67
  164. package/src/types.ts +58 -0
  165. package/src/user-input.ts +118 -0
package/dist/index.js CHANGED
@@ -1,38 +1,39 @@
1
1
  // @apifuse/provider-sdk
2
- export * from "./auth";
3
- export * from "./ceremonies";
4
- export * from "./choice-token";
5
- export { defineConfig, loadApiFuseConfig } from "./config/loader";
6
- export { canonicalJson, digestProviderContract, extractProviderContract, PROVIDER_CONTRACT_SCHEMA_VERSION, } from "./contract";
7
- export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, } from "./define";
8
- export { createDevServer, startDevServer } from "./dev";
9
- export * from "./errors";
10
- export * from "./i18n";
11
- export { lintOperation, lintProvider, } from "./lint";
12
- export * from "./recipes/gov-api";
13
- export * from "./recipes/rest-api";
14
- export { createFlowContext, createScratchpad } from "./runtime/auth-flow";
15
- export { BrowserClient, createBrowserClient } from "./runtime/browser";
16
- export { createBypassProviderCache, createProviderCache, resetProviderCacheForTests, } from "./runtime/cache";
17
- export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice";
18
- export { createCredentialContext, } from "./runtime/credential";
19
- export { createEnvContext } from "./runtime/env";
20
- export { executeOperation } from "./runtime/executor";
21
- export { createHttpClient } from "./runtime/http";
22
- export { generateInsights } from "./runtime/insights";
23
- export { wrapWithInstrumentation, } from "./runtime/instrumentation";
24
- export { prevalidate } from "./runtime/prevalidate";
25
- export { getProviderBaseUrl } from "./runtime/provider";
26
- export { createUnsupportedProviderRuntimeState, UnsupportedProviderStateError, } from "./runtime/state";
27
- export { createStealthClient } from "./runtime/stealth";
28
- export { APIFUSE__STT__BACKEND_ENV, APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__STT__MODEL_ENV, createSttClientFromEnv, createUnsupportedSttClient, extractVerificationCode, resolveSttPrompt, } from "./runtime/stt";
29
- export { createTraceContext, } from "./runtime/trace";
30
- export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema";
31
- export { createServerApp, serve } from "./server";
32
- export { getStealthProfile, listStealthProfiles } from "./stealth/profiles";
33
- export * from "./stream";
34
- export { DEFAULT_OPERATION_TRANSPORT, HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, PROBE_INTERVALS, STREAM_CHUNK_BYTES_MAX, STREAM_CHUNK_BYTES_MIN, STREAM_HEARTBEAT_MS_MAX, STREAM_HEARTBEAT_MS_MIN, STREAM_IDLE_TIMEOUT_MS_MAX, STREAM_IDLE_TIMEOUT_MS_MIN, STREAM_MAX_DURATION_MS_MAX, STREAM_MAX_DURATION_MS_MIN, } from "./types";
35
- export * from "./utils/date";
36
- export * from "./utils/parse";
37
- export * from "./utils/text";
38
- export * from "./utils/transform";
2
+ export * from "./auth.js";
3
+ export * from "./ceremonies/index.js";
4
+ export * from "./choice-token.js";
5
+ export { defineConfig, loadApiFuseConfig } from "./config/loader.js";
6
+ export { canonicalJson, digestProviderContract, extractProviderContract, PROVIDER_CONTRACT_SCHEMA_VERSION, } from "./contract.js";
7
+ export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, } from "./define.js";
8
+ export { createDevServer, startDevServer } from "./dev.js";
9
+ export * from "./errors.js";
10
+ export * from "./user-input.js";
11
+ export * from "./i18n/index.js";
12
+ export { lintOperation, lintProvider, } from "./lint.js";
13
+ export * from "./recipes/gov-api.js";
14
+ export * from "./recipes/rest-api.js";
15
+ export { createFlowContext, createScratchpad } from "./runtime/auth-flow.js";
16
+ export { BrowserClient, createBrowserClient } from "./runtime/browser.js";
17
+ export { createBypassProviderCache, createProviderCache, resetProviderCacheForTests, } from "./runtime/cache.js";
18
+ export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
19
+ export { createCredentialContext, } from "./runtime/credential.js";
20
+ export { createEnvContext } from "./runtime/env.js";
21
+ export { executeOperation } from "./runtime/executor.js";
22
+ export { createHttpClient } from "./runtime/http.js";
23
+ export { generateInsights } from "./runtime/insights.js";
24
+ export { wrapWithInstrumentation, } from "./runtime/instrumentation.js";
25
+ export { prevalidate } from "./runtime/prevalidate.js";
26
+ export { getProviderBaseUrl } from "./runtime/provider.js";
27
+ export { createUnsupportedProviderRuntimeState, UnsupportedProviderStateError, } from "./runtime/state.js";
28
+ export { createStealthClient } from "./runtime/stealth.js";
29
+ export { APIFUSE__STT__BACKEND_ENV, APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__STT__MODEL_ENV, createSttClientFromEnv, createUnsupportedSttClient, extractVerificationCode, resolveSttPrompt, } from "./runtime/stt.js";
30
+ export { createTraceContext, } from "./runtime/trace.js";
31
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema.js";
32
+ export { createServerApp, serve } from "./server/index.js";
33
+ export { getStealthProfile, listStealthProfiles } from "./stealth/profiles.js";
34
+ export * from "./stream.js";
35
+ export { DEFAULT_OPERATION_TRANSPORT, HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, PROBE_INTERVALS, STREAM_CHUNK_BYTES_MAX, STREAM_CHUNK_BYTES_MIN, STREAM_HEARTBEAT_MS_MAX, STREAM_HEARTBEAT_MS_MIN, STREAM_IDLE_TIMEOUT_MS_MAX, STREAM_IDLE_TIMEOUT_MS_MIN, STREAM_MAX_DURATION_MS_MAX, STREAM_MAX_DURATION_MS_MIN, } from "./types.js";
36
+ export * from "./utils/date.js";
37
+ export * from "./utils/parse.js";
38
+ export * from "./utils/text.js";
39
+ export * from "./utils/transform.js";
package/dist/lint.js CHANGED
@@ -1,5 +1,5 @@
1
- import { lintPublicSchemaFieldNames } from "./public-schema-field-lint";
2
- import { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_SENSITIVE_META_KEY, } from "./schema";
1
+ import { lintPublicSchemaFieldNames } from "./public-schema-field-lint.js";
2
+ import { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_SENSITIVE_META_KEY } from "./schema.js";
3
3
  const AUTH_OPERATION_ID_PATTERN = /^(?:auth[-_])?(?:login|exchange|continue|refresh|callback)(?:[-_]|$)/i;
4
4
  function lintAllowedHosts(providerId, allowedHosts) {
5
5
  const prefix = providerId ? `Provider "${providerId}"` : "Provider";
@@ -120,8 +120,7 @@ function lintAuthModel(provider) {
120
120
  });
121
121
  }
122
122
  if (hasReusableSecretKeys(credentialKeys) &&
123
- (!provider.credential?.storesReusableSecret ||
124
- !provider.credential.justification)) {
123
+ (!provider.credential?.storesReusableSecret || !provider.credential.justification)) {
125
124
  diagnostics.push({
126
125
  rule: "credential-reusable-secret",
127
126
  level: "error",
@@ -131,8 +130,7 @@ function lintAuthModel(provider) {
131
130
  }
132
131
  if (typeof provider.auth?.flow?.refresh === "function" &&
133
132
  hasReusableReloginSecretKeys(credentialKeys) &&
134
- (!provider.credential?.storesReusableSecret ||
135
- !provider.credential.justification)) {
133
+ (!provider.credential?.storesReusableSecret || !provider.credential.justification)) {
136
134
  diagnostics.push({
137
135
  rule: "auth-refresh-reusable-secret",
138
136
  level: "error",
@@ -149,8 +147,7 @@ function lintAuthModel(provider) {
149
147
  });
150
148
  }
151
149
  const authFlowSource = getAuthFlowSource(provider);
152
- if (authFlowSource.includes("ctx.context") &&
153
- (provider.context?.keys?.length ?? 0) === 0) {
150
+ if (authFlowSource.includes("ctx.context") && (provider.context?.keys?.length ?? 0) === 0) {
154
151
  diagnostics.push({
155
152
  rule: "context-keys-required",
156
153
  level: "warn",
@@ -435,8 +432,7 @@ function isComplexSchema(schema, seen = new Set()) {
435
432
  const childChildren = getChildSchemas(child);
436
433
  return childChildren.length > 0;
437
434
  });
438
- return (hasNestedComposite ||
439
- children.some(({ schema: child }) => isComplexSchema(child, seen)));
435
+ return hasNestedComposite || children.some(({ schema: child }) => isComplexSchema(child, seen));
440
436
  }
441
437
  function hasBidirectionalFixtures(fixtures) {
442
438
  if (!fixtures || typeof fixtures !== "object") {
@@ -448,9 +444,7 @@ function getOperationSource(operation) {
448
444
  if (operation.source) {
449
445
  return operation.source;
450
446
  }
451
- return typeof operation.handler === "function"
452
- ? operation.handler.toString()
453
- : "";
447
+ return typeof operation.handler === "function" ? operation.handler.toString() : "";
454
448
  }
455
449
  function lintStealthTransportUsage(provider) {
456
450
  if (provider.stealth || !provider.operations) {
@@ -621,8 +615,7 @@ export function lintOperation(op) {
621
615
  message: "Operation whenToUse must use whenToUseKeys instead of raw static prose.",
622
616
  });
623
617
  }
624
- if ((op.whenNotToUse?.length ?? 0) > 0 &&
625
- !(op.whenNotToUseKeys?.length ?? 0)) {
618
+ if ((op.whenNotToUse?.length ?? 0) > 0 && !(op.whenNotToUseKeys?.length ?? 0)) {
626
619
  diagnostics.push({
627
620
  rule: "operation-when-not-to-use-raw-prose",
628
621
  level: "error",
@@ -1,11 +1,11 @@
1
- export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth";
2
- export type { CredentialsAuthChallengeDefinition, CredentialsAuthChallengeRequest, CredentialsAuthCompleteResult, CredentialsAuthCredential, CredentialsAuthField, CredentialsAuthFields, CredentialsAuthFieldType, CredentialsAuthInput, CredentialsAuthLoginResult, DefineCredentialsAuthOptions, DefinedCredentialsAuth, } from "./auth";
3
- export { createFormCeremony } from "./ceremonies";
4
- export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, type ProviderChoiceTokenErrorReason, type ProviderChoiceTokenPayload, parseProviderChoiceToken, } from "./choice-token";
5
- export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define";
6
- export { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors";
7
- export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n";
8
- export { type CreateProviderChoiceContextOptions, createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice";
9
- export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema";
10
- export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationDocMeta, OperationErrorCode, OperationInputExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationToolRouterMetadata, OperationTransport, ProviderAccessVisibility, ProviderChoiceBindingOptions, ProviderChoiceContext, ProviderChoiceIssueOptions, ProviderChoiceParseOptions, ProviderContext, ProviderDefinition, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderRuntimeState, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateValue, StateWriteOptions, } from "./types";
11
- export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types";
1
+ export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth.js";
2
+ export type { CredentialsAuthChallengeDefinition, CredentialsAuthChallengeRequest, CredentialsAuthCompleteResult, CredentialsAuthCredential, CredentialsAuthField, CredentialsAuthFields, CredentialsAuthFieldType, CredentialsAuthInput, CredentialsAuthLoginResult, DefineCredentialsAuthOptions, DefinedCredentialsAuth, } from "./auth.js";
3
+ export { createFormCeremony } from "./ceremonies/index.js";
4
+ export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, type ProviderChoiceTokenErrorReason, type ProviderChoiceTokenPayload, parseProviderChoiceToken, } from "./choice-token.js";
5
+ export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define.js";
6
+ export { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
7
+ export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
8
+ export { type CreateProviderChoiceContextOptions, createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
9
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema.js";
10
+ export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationDocMeta, OperationErrorCode, OperationInputExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationToolRouterMetadata, OperationTransport, ProviderAccessVisibility, ProviderChoiceBindingOptions, ProviderChoiceContext, ProviderChoiceIssueOptions, ProviderChoiceParseOptions, ProviderContext, ProviderDefinition, ProviderDeploymentOverrides, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderRuntimeState, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateValue, StateWriteOptions, } from "./types.js";
11
+ export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
package/dist/provider.js CHANGED
@@ -1,9 +1,9 @@
1
- export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth";
2
- export { createFormCeremony } from "./ceremonies";
3
- export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, parseProviderChoiceToken, } from "./choice-token";
4
- export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define";
5
- export { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors";
6
- export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n";
7
- export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice";
8
- export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema";
9
- export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types";
1
+ export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth.js";
2
+ export { createFormCeremony } from "./ceremonies/index.js";
3
+ export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, parseProviderChoiceToken, } from "./choice-token.js";
4
+ export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define.js";
5
+ export { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
6
+ export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
7
+ export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
8
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema.js";
9
+ export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
@@ -1,2 +1,2 @@
1
- import type { LintDiagnostic } from "./lint";
1
+ import type { LintDiagnostic } from "./lint.js";
2
2
  export declare function lintPublicSchemaFieldNames(providerId: string | undefined, operationId: string, input: unknown, output: unknown, enforce: boolean): LintDiagnostic[];
@@ -1,4 +1,4 @@
1
- import { unwrapEnvelope } from "../utils/parse";
1
+ import { unwrapEnvelope } from "../utils/parse.js";
2
2
  function getResultCode(raw) {
3
3
  if (!raw || typeof raw !== "object") {
4
4
  return undefined;
@@ -1,4 +1,4 @@
1
- import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, StealthClient, SttContext } from "../types";
1
+ import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, StealthClient, SttContext } from "../types.js";
2
2
  export declare function createScratchpad(allowedKeys: string[], initial?: Record<string, unknown>): ContextScratchpad;
3
3
  export declare function createFlowContext(options: {
4
4
  http: HttpClient;
@@ -1,6 +1,6 @@
1
- import { ContextAccessError } from "../errors";
2
- import { createAuthFlowHelpers } from "../auth";
3
- import { createUnsupportedSttClient } from "./stt";
1
+ import { ContextAccessError } from "../errors.js";
2
+ import { createAuthFlowHelpers } from "../auth.js";
3
+ import { createUnsupportedSttClient } from "./stt.js";
4
4
  function normalizeAllowedKeys(allowedKeys) {
5
5
  return new Set(allowedKeys.filter((key) => key.trim().length > 0));
6
6
  }
@@ -1,4 +1,4 @@
1
- import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types";
1
+ import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types.js";
2
2
  type BrowserPageContract = BrowserPage;
3
3
  export type BrowserClientOptions = BrowserOptions & {
4
4
  allowedHosts?: string[];
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { ProviderError } from "../errors";
2
+ import { ProviderError } from "../errors.js";
3
3
  const require = createRequire(import.meta.url);
4
4
  const DEFAULT_WAIT_TIMEOUT_MS = 30_000;
5
5
  const SELECTOR_POLL_INTERVAL_MS = 100;
@@ -83,13 +83,14 @@ function matchesResourceRoute(match, request) {
83
83
  function toCdpFulfillParams(requestId, decision) {
84
84
  const body = toResourceBody(decision.body);
85
85
  return {
86
- ...(body === undefined
87
- ? {}
88
- : { body: Buffer.from(body).toString("base64") }),
86
+ ...(body === undefined ? {} : { body: Buffer.from(body).toString("base64") }),
89
87
  ...(decision.headers === undefined
90
88
  ? {}
91
89
  : {
92
- responseHeaders: Object.entries(decision.headers).map(([name, value]) => ({ name, value })),
90
+ responseHeaders: Object.entries(decision.headers).map(([name, value]) => ({
91
+ name,
92
+ value,
93
+ })),
93
94
  }),
94
95
  requestId,
95
96
  responseCode: decision.status ?? 200,
@@ -574,16 +575,13 @@ function parsePoolAcquireResponse(value) {
574
575
  code: "BROWSER_RUNTIME_UNSUPPORTED",
575
576
  });
576
577
  }
577
- if (value.browserContextId !== undefined &&
578
- typeof value.browserContextId !== "string") {
578
+ if (value.browserContextId !== undefined && typeof value.browserContextId !== "string") {
579
579
  throw new ProviderError("CDP Pool returned an invalid acquire response", {
580
580
  code: "BROWSER_RUNTIME_UNSUPPORTED",
581
581
  });
582
582
  }
583
583
  return {
584
- ...(value.browserContextId
585
- ? { browserContextId: value.browserContextId }
586
- : {}),
584
+ ...(value.browserContextId ? { browserContextId: value.browserContextId } : {}),
587
585
  pageId: value.pageId,
588
586
  wsEndpoint: value.wsEndpoint,
589
587
  };
@@ -605,9 +603,7 @@ function parseCdpFrameTreeNode(value) {
605
603
  frame: {
606
604
  id: frameId,
607
605
  name: typeof value.frame.name === "string" ? value.frame.name : undefined,
608
- parentId: typeof value.frame.parentId === "string"
609
- ? value.frame.parentId
610
- : undefined,
606
+ parentId: typeof value.frame.parentId === "string" ? value.frame.parentId : undefined,
611
607
  url: typeof value.frame.url === "string" ? value.frame.url : undefined,
612
608
  },
613
609
  ...(childFrames ? { childFrames } : {}),
@@ -620,9 +616,7 @@ function getCdpExecutionContext(params) {
620
616
  const contextId = params.context.id;
621
617
  const auxData = params.context.auxData;
622
618
  return {
623
- frameId: isRecord(auxData) && typeof auxData.frameId === "string"
624
- ? auxData.frameId
625
- : undefined,
619
+ frameId: isRecord(auxData) && typeof auxData.frameId === "string" ? auxData.frameId : undefined,
626
620
  id: typeof contextId === "number" ? contextId : undefined,
627
621
  };
628
622
  }
@@ -773,8 +767,7 @@ class CdpPoolBrowserPage {
773
767
  returnByValue: true,
774
768
  });
775
769
  if (result.exceptionDetails) {
776
- throw new Error(String(result.exceptionDetails.text ??
777
- "Browser evaluation failed"));
770
+ throw new Error(String(result.exceptionDetails.text ?? "Browser evaluation failed"));
778
771
  }
779
772
  return result.result?.value;
780
773
  }
@@ -859,9 +852,7 @@ class CdpPoolBrowserPage {
859
852
  this.closed = true;
860
853
  try {
861
854
  await this.release({
862
- ...(this.browserContextId
863
- ? { browserContextId: this.browserContextId }
864
- : {}),
855
+ ...(this.browserContextId ? { browserContextId: this.browserContextId } : {}),
865
856
  pageId: this.pageId,
866
857
  });
867
858
  }
@@ -1002,12 +993,8 @@ class CdpPoolBrowserClient {
1002
993
  }
1003
994
  async acquirePage(options) {
1004
995
  const acquireResult = parsePoolAcquireResponse(await this.poolClient.send("acquire", {
1005
- ...(this.allowedHosts.length > 0
1006
- ? { allowedHosts: this.allowedHosts }
1007
- : {}),
1008
- ...(options?.isolatedContext
1009
- ? { isolationMode: "browserContext" }
1010
- : {}),
996
+ ...(this.allowedHosts.length > 0 ? { allowedHosts: this.allowedHosts } : {}),
997
+ ...(options?.isolatedContext ? { isolationMode: "browserContext" } : {}),
1011
998
  }));
1012
999
  const pageClient = new JsonRpcWebSocketClient(acquireResult.wsEndpoint);
1013
1000
  const page = new CdpPoolBrowserPage(acquireResult.pageId, acquireResult.browserContextId, pageClient, async (request) => {
@@ -1223,8 +1210,7 @@ async function solveRecaptchaChallenge(page, request) {
1223
1210
  async function findRecaptchaFrame(frames, siteKey) {
1224
1211
  for (const frame of frames) {
1225
1212
  const url = await frame.url();
1226
- const matchesRecaptcha = url.includes("google.com/recaptcha") ||
1227
- url.includes("recaptcha.net/recaptcha");
1213
+ const matchesRecaptcha = url.includes("google.com/recaptcha") || url.includes("recaptcha.net/recaptcha");
1228
1214
  const matchesSiteKey = !siteKey || url.includes(siteKey);
1229
1215
  if (matchesRecaptcha && matchesSiteKey) {
1230
1216
  return frame;
@@ -1,4 +1,4 @@
1
- import type { ProviderCache } from "../types";
1
+ import type { ProviderCache } from "../types.js";
2
2
  export type ProviderCacheOptions = {
3
3
  providerId: string;
4
4
  redisUrl?: string;
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
- import { providerCacheRedisUrlFromEnv } from "../config/loader";
3
- import { createProviderRedisClient, ensureRedisReady, withRedisTimeout, } from "./redis";
2
+ import { providerCacheRedisUrlFromEnv } from "../config/loader.js";
3
+ import { createProviderRedisClient, ensureRedisReady, withRedisTimeout, } from "./redis.js";
4
4
  const DEFAULT_PREFIX = "apifuse:provider-cache:v1";
5
5
  const DEFAULT_MEMORY_MAX_ENTRIES = 1_000;
6
6
  const DEFAULT_REDIS_TIMEOUT_MS = 150;
@@ -71,10 +71,7 @@ function normalizeKeyPart(value, extra) {
71
71
  return value;
72
72
  }
73
73
  function stableHash(value) {
74
- return createHash("sha256")
75
- .update(JSON.stringify(value))
76
- .digest("hex")
77
- .slice(0, 32);
74
+ return createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 32);
78
75
  }
79
76
  function jitteredTtlMs(ttlMs, jitterPct) {
80
77
  if (!jitterPct || jitterPct <= 0)
@@ -282,8 +279,7 @@ export function createProviderCache(options) {
282
279
  async delete(key) {
283
280
  backend.memory.delete(key);
284
281
  const redis = backend.redis;
285
- if (!redis ||
286
- !(await ensureRedisReady(redis, DEFAULT_REDIS_TIMEOUT_MS))) {
282
+ if (!redis || !(await ensureRedisReady(redis, DEFAULT_REDIS_TIMEOUT_MS))) {
287
283
  return;
288
284
  }
289
285
  await withRedisFallback(() => redis.del(key));
@@ -1,4 +1,4 @@
1
- import type { CredentialContext, EnvContext, ProviderChoiceContext, ProviderRequestContext, ProviderRuntimeState } from "../types";
1
+ import type { CredentialContext, EnvContext, ProviderChoiceContext, ProviderRequestContext, ProviderRuntimeState } from "../types.js";
2
2
  export declare const PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV = "APIFUSE__PROVIDER_RUNTIME__CHOICE_TOKEN_MASTER_SECRET";
3
3
  export type CreateProviderChoiceContextOptions = {
4
4
  readonly providerId: string;
@@ -1,6 +1,6 @@
1
1
  import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes, timingSafeEqual, } from "node:crypto";
2
- import { assertFreshProviderChoiceIssuedAt, ProviderChoiceTokenError, } from "../choice-token";
3
- import { ProviderError } from "../errors";
2
+ import { assertFreshProviderChoiceIssuedAt, ProviderChoiceTokenError, } from "../choice-token.js";
3
+ import { ProviderError } from "../errors.js";
4
4
  export const PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV = "APIFUSE__PROVIDER_RUNTIME__CHOICE_TOKEN_MASTER_SECRET";
5
5
  const PRIMARY_CHOICE_TOKEN_KID = "v1";
6
6
  const MANAGED_CHOICE_TOKEN_VERSION = 1;
@@ -53,7 +53,7 @@ export function createProviderChoiceContext(options) {
53
53
  });
54
54
  }
55
55
  function parse(parseOptions) {
56
- const [actualPrefix, tokenKid, encodedIv, encryptedPayload, authTag, signature,] = parseManagedChoiceTokenParts(parseOptions.token);
56
+ const [actualPrefix, tokenKid, encodedIv, encryptedPayload, authTag, signature] = parseManagedChoiceTokenParts(parseOptions.token);
57
57
  if (actualPrefix !== parseOptions.prefix ||
58
58
  tokenKid !== kid ||
59
59
  !encodedIv ||
@@ -68,13 +68,7 @@ export function createProviderChoiceContext(options) {
68
68
  purpose: parseOptions.purpose,
69
69
  kid: tokenKid,
70
70
  });
71
- const signedBody = [
72
- parseOptions.prefix,
73
- tokenKid,
74
- encodedIv,
75
- encryptedPayload,
76
- authTag,
77
- ].join(".");
71
+ const signedBody = [parseOptions.prefix, tokenKid, encodedIv, encryptedPayload, authTag].join(".");
78
72
  assertManagedChoiceSignature({
79
73
  signedBody,
80
74
  signature,
@@ -117,13 +111,11 @@ export function createProviderChoiceContext(options) {
117
111
  export function createTestProviderChoiceContext(options) {
118
112
  return createProviderChoiceContext({
119
113
  ...options,
120
- masterSecret: options.masterSecret ??
121
- "apifuse-test-provider-runtime-choice-token-master-secret",
114
+ masterSecret: options.masterSecret ?? "apifuse-test-provider-runtime-choice-token-master-secret",
122
115
  });
123
116
  }
124
117
  function resolveChoiceMasterSecret(options) {
125
- const configured = options.masterSecret ??
126
- options.env?.get(PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV);
118
+ const configured = options.masterSecret ?? options.env?.get(PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV);
127
119
  const trimmed = configured?.trim();
128
120
  if (trimmed)
129
121
  return trimmed;
@@ -165,13 +157,7 @@ function encryptManagedChoiceToken(options) {
165
157
  ]).toString("base64url");
166
158
  const authTag = cipher.getAuthTag().toString("base64url");
167
159
  const encodedIv = iv.toString("base64url");
168
- const signedBody = [
169
- options.prefix,
170
- options.kid,
171
- encodedIv,
172
- encryptedPayload,
173
- authTag,
174
- ].join(".");
160
+ const signedBody = [options.prefix, options.kid, encodedIv, encryptedPayload, authTag].join(".");
175
161
  const signature = createHmac("sha256", options.keys.signing)
176
162
  .update(signedBody)
177
163
  .digest("base64url");
@@ -345,9 +331,7 @@ function isManagedChoiceEnvelope(value) {
345
331
  typeof value.issued_at_ms === "number" &&
346
332
  "ttl_ms" in value &&
347
333
  typeof value.ttl_ms === "number" &&
348
- (!("binding" in value) ||
349
- value.binding === undefined ||
350
- isChoiceBinding(value.binding)));
334
+ (!("binding" in value) || value.binding === undefined || isChoiceBinding(value.binding)));
351
335
  }
352
336
  function isChoicePayload(value) {
353
337
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
@@ -355,29 +339,23 @@ function isChoicePayload(value) {
355
339
  function isChoiceBinding(value) {
356
340
  if (!value || typeof value !== "object" || Array.isArray(value))
357
341
  return false;
358
- return ((!("connection_hash" in value) ||
359
- typeof value.connection_hash === "string") &&
342
+ return ((!("connection_hash" in value) || typeof value.connection_hash === "string") &&
360
343
  (!("credential_hash" in value) || typeof value.credential_hash === "string"));
361
344
  }
362
345
  function assertManagedChoiceEnvelope(envelope, options) {
363
- if (envelope.provider_id !== options.providerId ||
364
- envelope.purpose !== options.purpose) {
346
+ if (envelope.provider_id !== options.providerId || envelope.purpose !== options.purpose) {
365
347
  throw new ProviderChoiceTokenError("invalid_payload", "Provider choice token payload is invalid.");
366
348
  }
367
349
  assertFreshProviderChoiceIssuedAt(envelope.issued_at_ms, {
368
350
  // Clamp to the issuer's embedded TTL so a caller-supplied value cannot
369
351
  // silently extend token validity past the deadline the issuer intended.
370
- ttlMs: options.ttlMs != null
371
- ? Math.min(options.ttlMs, envelope.ttl_ms)
372
- : envelope.ttl_ms,
352
+ ttlMs: options.ttlMs != null ? Math.min(options.ttlMs, envelope.ttl_ms) : envelope.ttl_ms,
373
353
  nowMs: options.nowMs,
374
354
  futureToleranceMs: options.futureToleranceMs,
375
355
  });
376
356
  }
377
357
  function createChoiceBinding(options) {
378
- const connectionHash = options.options?.connection
379
- ? hashRequiredConnection(options)
380
- : undefined;
358
+ const connectionHash = options.options?.connection ? hashRequiredConnection(options) : undefined;
381
359
  const credentialHash = options.options?.credentialKeys?.length
382
360
  ? hashCredentialKeys(options)
383
361
  : undefined;
@@ -1,4 +1,4 @@
1
- import type { AuthMode, CredentialContext } from "../types";
1
+ import type { AuthMode, CredentialContext } from "../types.js";
2
2
  export interface CreateCredentialContextOptions {
3
3
  allowedKeys?: string[];
4
4
  mode?: AuthMode;
@@ -1,4 +1,4 @@
1
- import { CredentialModeError } from "../errors";
1
+ import { CredentialModeError } from "../errors.js";
2
2
  function getAllowedKeys(allowedKeys, values) {
3
3
  if (allowedKeys) {
4
4
  return allowedKeys;
@@ -1,2 +1,2 @@
1
- import type { EnvContext } from "../types";
1
+ import type { EnvContext } from "../types.js";
2
2
  export declare function createEnvContext(allowedKeys?: string[]): EnvContext;
@@ -1,4 +1,4 @@
1
- import type { ProviderContext, ProviderDefinition } from "../types";
1
+ import type { ProviderContext, ProviderDefinition } from "../types.js";
2
2
  export declare function isStreamingOperation(provider: ProviderDefinition, operationId: string): boolean;
3
3
  /**
4
4
  * Execute a provider operation by calling its handler.
@@ -1,5 +1,5 @@
1
- import { isSessionExpiredError, ProviderError, SessionExpiredError } from "../errors";
2
- import { parseSchema } from "../schema";
1
+ import { isSessionExpiredError, ProviderError, SessionExpiredError } from "../errors.js";
2
+ import { parseSchema } from "../schema.js";
3
3
  export function isStreamingOperation(provider, operationId) {
4
4
  const kind = provider.operations[operationId]?.transport?.kind ?? "json";
5
5
  return kind !== "json";
@@ -1,5 +1,5 @@
1
- import type { ProxyResolutionOptions } from "../config/loader";
2
- import type { HttpClient, HttpRetrySummary } from "../types";
1
+ import type { ProxyResolutionOptions } from "../config/loader.js";
2
+ import type { HttpClient, HttpRetrySummary } from "../types.js";
3
3
  export type HttpClientOptions = ProxyResolutionOptions & {
4
4
  warn?: (message: string) => void;
5
5
  userAgent?: string;
@@ -1,8 +1,8 @@
1
- import { resolveProxyConfigAsync } from "../config/loader";
2
- import { ProviderError, TransportError } from "../errors";
3
- import { parseSseStream, readableBytes, readableLines, readableTextChunks } from "../stream";
4
- import { computeProxyAttemptIndex, computeProxyTransportRetryDelayMs, createDefaultProxyTransportRetryOptions, isProxyTransportRetryMethod, normalizeProxyTransportRetryOptions, proxyTransportRetryErrorCode, proxyTransportRetryErrorStatus, shouldRetryProxyTransportAttempt, validateUnsafeProxyTransportRetryMethods, } from "./proxy-retry-policy";
5
- import { appendQueryParams, normalizeHttpRequestBody } from "./request-options";
1
+ import { resolveProxyConfigAsync } from "../config/loader.js";
2
+ import { ProviderError, TransportError } from "../errors.js";
3
+ import { parseSseStream, readableBytes, readableLines, readableTextChunks } from "../stream.js";
4
+ import { computeProxyAttemptIndex, computeProxyTransportRetryDelayMs, createDefaultProxyTransportRetryOptions, isProxyTransportRetryMethod, normalizeProxyTransportRetryOptions, proxyTransportRetryErrorCode, proxyTransportRetryErrorStatus, shouldRetryProxyTransportAttempt, validateUnsafeProxyTransportRetryMethods, } from "./proxy-retry-policy.js";
5
+ import { appendQueryParams, normalizeHttpRequestBody } from "./request-options.js";
6
6
  const DEFAULT_HTTP_BASE_URL = "http://localhost";
7
7
  function isHttpStatusOutcome(outcome) {
8
8
  return "kind" in outcome && outcome.kind === "http-status";
@@ -1,4 +1,4 @@
1
- import type { Span } from "./trace";
1
+ import type { Span } from "./trace.js";
2
2
  export type InsightSeverity = "info" | "warning" | "error";
3
3
  export type Insight = {
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { computePercentile } from "./perf";
1
+ import { computePercentile } from "./perf.js";
2
2
  const LARGE_RESPONSE_BYTES = 100_000;
3
3
  const SLOW_TRANSFORM_MS = 10;
4
4
  const DNS_WARN_MS = 5;
@@ -188,8 +188,7 @@ function getDnsRepeatedCandidate(spans) {
188
188
  if (entry.totalCount < 2) {
189
189
  continue;
190
190
  }
191
- const avgDnsMs = entry.dnsDurations.reduce((sum, value) => sum + value, 0) /
192
- entry.dnsDurations.length;
191
+ const avgDnsMs = entry.dnsDurations.reduce((sum, value) => sum + value, 0) / entry.dnsDurations.length;
193
192
  const reuseRate = entry.reuseCount / entry.totalCount;
194
193
  if (avgDnsMs > DNS_WARN_MS && reuseRate < 0.2) {
195
194
  if (!candidate || avgDnsMs > candidate.avgDnsMs) {
@@ -218,9 +217,7 @@ function getDnsRepeatedInsight(spans) {
218
217
  }
219
218
  function getProxyOverheadInsight(spans) {
220
219
  const requestSpans = spans.filter(isRequestSpan);
221
- const proxiedDurations = requestSpans
222
- .filter(hasProxy)
223
- .map((span) => span.duration_ms);
220
+ const proxiedDurations = requestSpans.filter(hasProxy).map((span) => span.duration_ms);
224
221
  const directDurations = requestSpans
225
222
  .filter((span) => !hasProxy(span))
226
223
  .map((span) => span.duration_ms);
@@ -230,10 +227,8 @@ function getProxyOverheadInsight(spans) {
230
227
  message: "✓ Proxy overhead: insufficient proxy/direct samples",
231
228
  };
232
229
  }
233
- const proxyAvg = proxiedDurations.reduce((sum, value) => sum + value, 0) /
234
- proxiedDurations.length;
235
- const directAvg = directDurations.reduce((sum, value) => sum + value, 0) /
236
- directDurations.length;
230
+ const proxyAvg = proxiedDurations.reduce((sum, value) => sum + value, 0) / proxiedDurations.length;
231
+ const directAvg = directDurations.reduce((sum, value) => sum + value, 0) / directDurations.length;
237
232
  if (directAvg > 0 && proxyAvg >= directAvg * 2) {
238
233
  return {
239
234
  triggered: true,
@@ -254,9 +249,7 @@ function getBrowserIdleInsight(spans) {
254
249
  if (waitMs !== undefined) {
255
250
  return waitMs;
256
251
  }
257
- return span.name.toLowerCase().includes("wait")
258
- ? span.duration_ms
259
- : undefined;
252
+ return span.name.toLowerCase().includes("wait") ? span.duration_ms : undefined;
260
253
  })
261
254
  .filter((value) => value !== undefined);
262
255
  if (waits.length === 0) {