@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.
- package/AUTHORING.md +53 -0
- package/CHANGELOG.md +8 -0
- package/bin/apifuse-check.ts +18 -58
- package/bin/apifuse-create.ts +1 -1
- package/bin/apifuse-dev.ts +27 -52
- package/bin/apifuse-pack-smoke.ts +22 -81
- package/bin/apifuse-pack-types.ts +266 -0
- package/bin/apifuse-perf.ts +45 -127
- package/bin/apifuse-record.ts +23 -61
- package/bin/apifuse-submit-check.ts +266 -34
- package/bin/apifuse.ts +1 -1
- package/bin/submit-check-xml.ts +1 -1
- package/dist/auth-turn/index.d.ts +1 -1
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +9 -18
- package/dist/ceremonies/index.d.ts +1 -1
- package/dist/ceremonies/index.js +8 -18
- package/dist/config/loader.d.ts +2 -2
- package/dist/config/loader.js +19 -42
- package/dist/contract-serialization.d.ts +2 -2
- package/dist/contract-serialization.js +3 -6
- package/dist/contract-types.d.ts +2 -2
- package/dist/contract.d.ts +3 -3
- package/dist/contract.js +4 -6
- package/dist/define.d.ts +8 -1
- package/dist/define.js +57 -115
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -3
- package/dist/i18n/catalog.d.ts +2 -2
- package/dist/i18n/catalog.js +4 -10
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/keys.d.ts +2 -2
- package/dist/index.d.ts +43 -42
- package/dist/index.js +38 -37
- package/dist/lint.js +8 -15
- package/dist/provider.d.ts +11 -11
- package/dist/provider.js +9 -9
- package/dist/public-schema-field-lint.d.ts +1 -1
- package/dist/recipes/gov-api.js +1 -1
- package/dist/runtime/auth-flow.d.ts +1 -1
- package/dist/runtime/auth-flow.js +3 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +15 -29
- package/dist/runtime/cache.d.ts +1 -1
- package/dist/runtime/cache.js +4 -8
- package/dist/runtime/choice.d.ts +1 -1
- package/dist/runtime/choice.js +12 -34
- package/dist/runtime/credential.d.ts +1 -1
- package/dist/runtime/credential.js +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/runtime/executor.d.ts +1 -1
- package/dist/runtime/executor.js +2 -2
- package/dist/runtime/http.d.ts +2 -2
- package/dist/runtime/http.js +5 -5
- package/dist/runtime/insights.d.ts +1 -1
- package/dist/runtime/insights.js +6 -13
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +5 -15
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- package/dist/runtime/otlp.d.ts +1 -1
- package/dist/runtime/perf.d.ts +1 -1
- package/dist/runtime/provider.d.ts +1 -1
- package/dist/runtime/provider.js +1 -2
- package/dist/runtime/proxy-errors.d.ts +1 -1
- package/dist/runtime/proxy-errors.js +3 -5
- package/dist/runtime/proxy-retry-policy.d.ts +2 -2
- package/dist/runtime/proxy-retry-policy.js +2 -2
- package/dist/runtime/proxy-telemetry.d.ts +1 -1
- package/dist/runtime/proxy-telemetry.js +16 -48
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +2 -4
- package/dist/runtime/request-options.d.ts +1 -1
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +3 -3
- package/dist/runtime/stealth.d.ts +2 -2
- package/dist/runtime/stealth.js +6 -6
- package/dist/runtime/stt.d.ts +1 -1
- package/dist/runtime/stt.js +11 -15
- package/dist/runtime/trace.d.ts +2 -2
- package/dist/runtime/trace.js +2 -4
- package/dist/runtime/waterfall.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +7 -15
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +6 -6
- package/dist/server/self-test-redaction.d.ts +1 -1
- package/dist/server/self-test-redaction.js +1 -1
- package/dist/server/self-test.d.ts +104 -3
- package/dist/server/self-test.js +673 -115
- package/dist/server/serve.d.ts +3 -3
- package/dist/server/serve.js +37 -49
- package/dist/server/types.js +2 -7
- package/dist/stealth/profiles.d.ts +1 -1
- package/dist/stealth/profiles.js +5 -14
- package/dist/stream.d.ts +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/run.d.ts +1 -1
- package/dist/testing/run.js +7 -14
- package/dist/types.d.ts +57 -0
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +6 -4
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +28 -86
- package/src/ceremonies/index.ts +24 -78
- package/src/config/loader.ts +58 -176
- package/src/contract-serialization.ts +5 -11
- package/src/contract-types.ts +2 -2
- package/src/contract.ts +12 -28
- package/src/define.ts +174 -495
- package/src/dev.ts +4 -9
- package/src/errors.ts +4 -11
- package/src/i18n/catalog.ts +10 -32
- package/src/i18n/index.ts +2 -2
- package/src/i18n/keys.ts +5 -11
- package/src/index.ts +44 -42
- package/src/lint.ts +89 -159
- package/src/provider.ts +12 -11
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +5 -7
- package/src/runtime/browser.ts +64 -187
- package/src/runtime/cache.ts +20 -67
- package/src/runtime/choice.ts +55 -129
- package/src/runtime/credential.ts +2 -2
- package/src/runtime/env.ts +1 -1
- package/src/runtime/executor.ts +9 -19
- package/src/runtime/http.ts +7 -7
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +19 -58
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- package/src/runtime/otlp.ts +12 -23
- package/src/runtime/perf.ts +1 -1
- package/src/runtime/provider.ts +4 -9
- package/src/runtime/proxy-errors.ts +17 -38
- package/src/runtime/proxy-retry-policy.ts +3 -3
- package/src/runtime/proxy-telemetry.ts +23 -72
- package/src/runtime/redis.ts +4 -12
- package/src/runtime/request-options.ts +4 -13
- package/src/runtime/state.ts +30 -109
- package/src/runtime/stealth.ts +8 -8
- package/src/runtime/stt.ts +38 -94
- package/src/runtime/trace.ts +14 -44
- package/src/runtime/waterfall.ts +5 -18
- package/src/schema.ts +23 -84
- package/src/serve.ts +1 -1
- package/src/server/index.ts +12 -7
- package/src/server/self-test-redaction.ts +2 -2
- package/src/server/self-test.ts +857 -132
- package/src/server/serve.ts +89 -238
- package/src/server/types.ts +6 -19
- package/src/stealth/profiles.ts +10 -26
- package/src/stream.ts +8 -19
- package/src/testing/index.ts +2 -2
- package/src/testing/run.ts +19 -67
- package/src/types.ts +58 -0
- 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
|