@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
@@ -1,8 +1,8 @@
1
1
  import { Hono } from "hono";
2
2
  import { z } from "zod";
3
- import type { OperationDefinition, ProviderDefinition } from "../types";
4
- import { type SelfTestMasterSecrets } from "./self-test-token";
5
- import type { OperationConnection } from "./types";
3
+ import type { OperationDefinition, ProviderDefinition } from "../types.js";
4
+ import { type SelfTestMasterSecrets } from "./self-test-token.js";
5
+ import type { OperationConnection } from "./types.js";
6
6
  export declare const SELF_TEST_SCHEMA_VERSION: 1;
7
7
  export declare const SELF_TEST_PATH = "/internal/health/self-test";
8
8
  export declare const SELF_TEST_HEALTHZ_PATH = "/healthz";
@@ -61,11 +61,53 @@ export type SelfTestOperationInvoke = (args: {
61
61
  data: unknown;
62
62
  meta?: Record<string, unknown>;
63
63
  }>;
64
+ export type SelfTestAuthFlowRoute = "start" | "continue";
65
+ /**
66
+ * In-process driver for the tenant app's /auth pipeline. Self-test uses it to
67
+ * materialize `requiresConnection` credentials through the provider's declared
68
+ * auth flow — the exact path production connections take — instead of
69
+ * injecting raw credential inputs as connection secrets.
70
+ */
71
+ export type SelfTestAuthFlowInvoke = (args: {
72
+ route: SelfTestAuthFlowRoute;
73
+ requestId: string;
74
+ flowId: string;
75
+ /** Stable per-credential connection id — keeps login on the probe's affinity. */
76
+ connectionId?: string;
77
+ /** The probe connection's externalRef — flows reading ctx.externalRef see the same identity. */
78
+ externalRef?: string;
79
+ input?: Record<string, unknown>;
80
+ context?: Record<string, unknown>;
81
+ }) => Promise<{
82
+ status: number;
83
+ body: unknown;
84
+ }>;
85
+ /**
86
+ * Skip reason reported when a declared auth flow does not complete in a single
87
+ * continue (OTP, retry loop). Cross-repo contract: the health-monitor maps
88
+ * this exact string to `self_test_incapable`; never vary it.
89
+ */
90
+ export declare const SELF_TEST_AUTH_FLOW_MULTI_TURN_SKIP_REASON = "auth_flow_multi_turn";
91
+ /**
92
+ * A `retry` turn after credential submission: the flow REJECTED the
93
+ * configured inputs (bad password, exchange failure). Distinct from the
94
+ * multi-turn gap so monitoring surfaces it as a real credential outage, and
95
+ * memoized like multi-turn so the probe does not re-submit rejected
96
+ * credentials every cycle (lockout safety).
97
+ */
98
+ export declare const SELF_TEST_AUTH_FLOW_REJECTED_SKIP_REASON = "auth_flow_rejected";
64
99
  export interface SelfTestAppOptions {
65
100
  /** Derived-token verification secrets; without them every self-test route 404s. */
66
101
  secrets?: SelfTestMasterSecrets;
67
102
  /** In-process invoke bound to the tenant-facing app's /v1 pipeline. */
68
103
  invoke: SelfTestOperationInvoke;
104
+ /**
105
+ * In-process auth-flow driver bound to the tenant-facing app's /auth
106
+ * pipeline. Required for providers that declare `auth.mode: "credentials"`
107
+ * with a flow; without it their requiresConnection cases report a visible
108
+ * auth_flow_unavailable error instead of probing with raw inputs.
109
+ */
110
+ authFlow?: SelfTestAuthFlowInvoke;
69
111
  /** Overall request budget; defaults to env / 120s. */
70
112
  requestBudgetMs?: number;
71
113
  /** Env override for secret collection + budget resolution (tests). */
@@ -88,6 +130,65 @@ export declare function isSelfTestReadOnlyOperation(operation: OperationDefiniti
88
130
  export declare function createSelfTestInvoke(app: {
89
131
  request: (input: string, requestInit?: RequestInit) => Response | Promise<Response>;
90
132
  }): SelfTestOperationInvoke;
133
+ /** Binds the self-test auth-flow driver to a tenant app's /auth pipeline in-process. */
134
+ export declare function createSelfTestAuthFlowInvoke(app: {
135
+ request: (input: string, requestInit?: RequestInit) => Response | Promise<Response>;
136
+ }): SelfTestAuthFlowInvoke;
137
+ /**
138
+ * How long a memoized multi-turn flow outcome suppresses re-driving the auth
139
+ * flow. Generous on purpose: a multi-turn ceremony (OTP, device approval) is a
140
+ * provider property that changes on the timescale of releases, not probe
141
+ * cycles, and every re-drive is a REAL upstream login submission. The cache is
142
+ * in-process, so a pod restart also clears the entry.
143
+ */
144
+ export declare const SELF_TEST_MULTI_TURN_RETRY_AFTER_MS: number;
145
+ /**
146
+ * Age bound for POSITIVE cached credentials. Expiry modes that never produce
147
+ * a 401/403 (a 200 login page, an assertion failure) would otherwise replay
148
+ * the same stale session until pod restart — one re-login per day is the
149
+ * upstream-safe recovery for them.
150
+ */
151
+ export declare const SELF_TEST_CREDENTIAL_MAX_AGE_MS: number;
152
+ export type SelfTestCredentialSessionEntry =
153
+ /** Flow-materialized credential reused across probe cycles. */
154
+ {
155
+ kind: "credential";
156
+ credential: Record<string, string>;
157
+ cachedAtMs: number;
158
+ }
159
+ /**
160
+ * Negative entry: the flow did not complete in a single continue turn
161
+ * (`auth_flow_multi_turn`). Memoized so subsequent cycles report the skip
162
+ * WITHOUT contacting the upstream again — the first attempt already
163
+ * submitted real credentials (and may have triggered an OTP send).
164
+ */
165
+ | {
166
+ kind: "multi_turn";
167
+ cachedAtMs: number;
168
+ }
169
+ /**
170
+ * Negative entry: the flow REJECTED the submitted credential inputs
171
+ * (`retry` turn after continue — bad password, exchange failure).
172
+ * Memoized so the probe does not re-submit rejected credentials every
173
+ * cycle; a new entry is attempted when the inputs rotate (new hash),
174
+ * the TTL lapses, or the process restarts.
175
+ */
176
+ | {
177
+ kind: "rejected";
178
+ cachedAtMs: number;
179
+ };
180
+ /**
181
+ * In-process cache of per-(providerId + stable hash of credentialInputs) auth
182
+ * flow outcomes, so consecutive probe cycles reuse the session — or the
183
+ * memoized multi-turn skip — instead of logging in every cycle (upstream
184
+ * account safety, DR-7). Credential entries are invalidated on a probe auth
185
+ * failure, at most once; multi-turn entries expire after
186
+ * `SELF_TEST_MULTI_TURN_RETRY_AFTER_MS` or on process restart. Flow ERRORS
187
+ * (transport/protocol failures, thrown start/continue) are deliberately NEVER
188
+ * cached: they are typically transient, and retrying a failed request next
189
+ * cycle is not a repeated login submission.
190
+ */
191
+ export type SelfTestCredentialSessionCache = Map<string, SelfTestCredentialSessionEntry>;
91
192
  export declare function resolveSelfTestPort(env?: Readonly<Record<string, string | undefined>>): number;
92
193
  /**
93
194
  * Builds the internal self-test Hono app. This app is served on a SEPARATE