@apifuse/provider-sdk 2.2.0-beta.36 → 2.2.0-beta.38
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 +22 -8
- package/CHANGELOG.md +8 -0
- package/README.md +20 -8
- package/bin/apifuse-dev.ts +1 -1
- package/bin/apifuse-pack-types.ts +6 -5
- package/bin/apifuse-record.ts +1 -1
- package/bin/apifuse-submit-check.ts +23 -10
- package/dist/cli/templates/provider/index.ts.tpl +6 -3
- package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -1
- package/dist/declaration-validation.d.ts +2 -0
- package/dist/declaration-validation.js +29 -3
- package/dist/define.d.ts +39 -21
- package/dist/define.js +33 -9
- package/dist/health-scenario.d.ts +1842 -0
- package/dist/health-scenario.js +624 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -0
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +1 -0
- package/dist/runtime/browser.js +19 -11
- package/dist/runtime/resolver-public.d.ts +1 -1
- package/dist/runtime/resolver-public.js +1 -1
- package/dist/runtime/resolver-vendors/browser.js +57 -14
- package/dist/runtime/resolver-vendors/types.d.ts +9 -1
- package/dist/runtime/resolver-vendors/types.js +15 -0
- package/dist/runtime/resolver.d.ts +1 -0
- package/dist/runtime/resolver.js +13 -7
- package/dist/server/serve-implementation.d.ts +1 -1
- package/dist/server/serve-implementation.js +25 -0
- package/dist/server/types.d.ts +4 -4
- package/dist/types.d.ts +35 -25
- package/package.json +1 -1
- package/src/cli/templates/provider/index.ts.tpl +6 -3
- package/src/cli/templates/provider/operations/ping.ts.tpl +2 -1
- package/src/declaration-validation.ts +30 -3
- package/src/define.ts +144 -51
- package/src/health-scenario.ts +875 -0
- package/src/index.ts +78 -2
- package/src/provider.ts +81 -1
- package/src/runtime/browser.ts +34 -11
- package/src/runtime/resolver-public.ts +2 -0
- package/src/runtime/resolver-vendors/browser.ts +69 -11
- package/src/runtime/resolver-vendors/types.ts +21 -0
- package/src/runtime/resolver.ts +17 -5
- package/src/server/serve-implementation.ts +39 -1
- package/src/testing/run.ts +3 -3
- package/src/types.ts +52 -25
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type ms from "ms";
|
|
2
|
+
import type { HealthScenario } from "./health-scenario.js";
|
|
2
3
|
import type { SerializedCookieJar } from "tough-cookie";
|
|
3
4
|
|
|
4
5
|
import type { infer as ZodInfer, ZodType } from "zod";
|
|
@@ -308,16 +309,16 @@ export interface ProviderSttConfig {
|
|
|
308
309
|
}
|
|
309
310
|
|
|
310
311
|
/**
|
|
311
|
-
*
|
|
312
|
-
* `createBrowserClient`) and is a first-class vendor rather than an escape hatch:
|
|
313
|
-
* for fingerprint-family kinds, it was measured faster than a paid vendor
|
|
314
|
-
* (4.5 s vs 17.5 s) at zero marginal cost.
|
|
312
|
+
* Union order is documentation only.
|
|
315
313
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
314
|
+
* The SDK owns the default hosted-vendor fallback policy and derives the chain
|
|
315
|
+
* from each provider's declared challenge kinds. Hosted solvers are preferred
|
|
316
|
+
* with `capsolver` ahead of `2captcha` in that policy.
|
|
318
317
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
318
|
+
* `browser` is the in-house CDP pool and remains opt-in; it is excluded from the
|
|
319
|
+
* default chain. `custom` is likewise reserved for provider-specific configuration.
|
|
320
|
+
*
|
|
321
|
+
* `ProviderResolverConfig.vendors` overrides the SDK policy when declared.
|
|
321
322
|
*/
|
|
322
323
|
export type ProviderResolverVendor =
|
|
323
324
|
| "browser"
|
|
@@ -411,8 +412,8 @@ export type ChallengeSolution =
|
|
|
411
412
|
};
|
|
412
413
|
|
|
413
414
|
export interface ProviderResolverConfig {
|
|
414
|
-
/**
|
|
415
|
-
readonly vendors
|
|
415
|
+
/** Optional ordered override for the SDK-owned vendor fallback chain. */
|
|
416
|
+
readonly vendors?: readonly ProviderResolverVendor[];
|
|
416
417
|
/** Challenge kinds this provider is permitted to request. */
|
|
417
418
|
readonly kinds: readonly ProviderChallengeKind[];
|
|
418
419
|
/**
|
|
@@ -645,7 +646,7 @@ export interface HealthJourneyRunResult {
|
|
|
645
646
|
metadata?: Record<string, unknown>;
|
|
646
647
|
}
|
|
647
648
|
|
|
648
|
-
|
|
649
|
+
interface HealthJourneyDefinitionBase {
|
|
649
650
|
id: string;
|
|
650
651
|
title?: string;
|
|
651
652
|
description?: string;
|
|
@@ -657,15 +658,17 @@ export interface HealthJourneyDefinition {
|
|
|
657
658
|
requiredSecrets?: readonly string[];
|
|
658
659
|
manualTrigger?: HealthJourneyManualTriggerPolicy;
|
|
659
660
|
steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
|
|
660
|
-
/**
|
|
661
|
-
* Required: a journey always declares `coversOperations`, and the health
|
|
662
|
-
* monitor reports a run-less journey as `journey_run_missing`. Declaration
|
|
663
|
-
* validation rejects a missing `run` (`health-journey-executable`), so this
|
|
664
|
-
* is typed required to fail at compile time rather than at boot.
|
|
665
|
-
*/
|
|
666
|
-
run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
|
|
667
661
|
}
|
|
668
662
|
|
|
663
|
+
export type HealthJourneyDefinition = HealthJourneyDefinitionBase &
|
|
664
|
+
(
|
|
665
|
+
| {
|
|
666
|
+
run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
|
|
667
|
+
scenario?: never;
|
|
668
|
+
}
|
|
669
|
+
| { scenario: HealthScenario; run?: never }
|
|
670
|
+
);
|
|
671
|
+
|
|
669
672
|
/**
|
|
670
673
|
* Health-check authoring surface owned by `@apifuse/provider-sdk`.
|
|
671
674
|
*
|
|
@@ -1636,9 +1639,6 @@ export interface NativeContext {
|
|
|
1636
1639
|
readonly network: NativeNetworkClient;
|
|
1637
1640
|
}
|
|
1638
1641
|
|
|
1639
|
-
/** Consumer-facing alias for the native capability on provider contexts. */
|
|
1640
|
-
export type NativeProviderContext = NativeContext;
|
|
1641
|
-
|
|
1642
1642
|
export interface NativeProviderConfig {
|
|
1643
1643
|
readonly network?: {
|
|
1644
1644
|
readonly tcp?: readonly NativeTcpEgressRule[];
|
|
@@ -1816,6 +1816,10 @@ export interface BrowserPage extends BrowserFrame {
|
|
|
1816
1816
|
cookies(): Promise<readonly BrowserCookie[]>;
|
|
1817
1817
|
fill(selector: string, text: string): Promise<void>;
|
|
1818
1818
|
goto(url: string): Promise<void>;
|
|
1819
|
+
goto(
|
|
1820
|
+
url: string,
|
|
1821
|
+
options?: { readonly timeout?: number; readonly waitUntil?: "load" | "domcontentloaded" },
|
|
1822
|
+
): Promise<void>;
|
|
1819
1823
|
pageId?: string;
|
|
1820
1824
|
screenshot(options?: { fullPage?: boolean }): Promise<Buffer>;
|
|
1821
1825
|
click(selector: string): Promise<void>;
|
|
@@ -2139,7 +2143,7 @@ export interface FlowContext {
|
|
|
2139
2143
|
* un-keyed entries would be shared across all connectionless ceremonies. */
|
|
2140
2144
|
readonly state?: ProviderRuntimeState;
|
|
2141
2145
|
/** Present when the selected runtime supplies native network capabilities. */
|
|
2142
|
-
readonly native?:
|
|
2146
|
+
readonly native?: NativeContext;
|
|
2143
2147
|
stealth: StealthClient;
|
|
2144
2148
|
env: EnvContext;
|
|
2145
2149
|
credential?: CredentialContext;
|
|
@@ -2275,8 +2279,8 @@ export interface ProviderContext {
|
|
|
2275
2279
|
http: HttpClient;
|
|
2276
2280
|
/** Present for requests carrying runtime-resolvable file references. */
|
|
2277
2281
|
readonly files?: ProviderFilesContext;
|
|
2278
|
-
/**
|
|
2279
|
-
readonly native
|
|
2282
|
+
/** Native network capability selected by declaration-derived contexts. */
|
|
2283
|
+
readonly native: NativeContext;
|
|
2280
2284
|
cache: ProviderCache;
|
|
2281
2285
|
state: ProviderRuntimeState;
|
|
2282
2286
|
stealth: StealthClient;
|
|
@@ -2289,6 +2293,28 @@ export interface ProviderContext {
|
|
|
2289
2293
|
choice: ProviderChoiceContext;
|
|
2290
2294
|
}
|
|
2291
2295
|
|
|
2296
|
+
/**
|
|
2297
|
+
* The operation context exposed for one provider declaration. Capability
|
|
2298
|
+
* bindings are present only when their corresponding declaration is present;
|
|
2299
|
+
* trace and request remain ambient runtime bindings.
|
|
2300
|
+
*/
|
|
2301
|
+
export type ProviderContextFor<TConfig> =
|
|
2302
|
+
Pick<ProviderContext, "trace" | "request">
|
|
2303
|
+
& ("env" extends keyof TConfig ? Pick<ProviderContext, "env"> : Record<never, never>)
|
|
2304
|
+
& ("credential" extends keyof TConfig ? Pick<ProviderContext, "credential"> : Record<never, never>)
|
|
2305
|
+
& ("http" extends keyof TConfig ? Pick<ProviderContext, "http"> : Record<never, never>)
|
|
2306
|
+
& ("files" extends keyof TConfig ? Pick<ProviderContext, "files"> : Record<never, never>)
|
|
2307
|
+
& ("native" extends keyof TConfig ? Pick<ProviderContext, "native"> : Record<never, never>)
|
|
2308
|
+
& ("cache" extends keyof TConfig ? Pick<ProviderContext, "cache"> : Record<never, never>)
|
|
2309
|
+
& ("state" extends keyof TConfig ? Pick<ProviderContext, "state"> : Record<never, never>)
|
|
2310
|
+
& ("stealth" extends keyof TConfig ? Pick<ProviderContext, "stealth"> : Record<never, never>)
|
|
2311
|
+
& ("browser" extends keyof TConfig ? Pick<ProviderContext, "browser"> : Record<never, never>)
|
|
2312
|
+
& ("auth" extends keyof TConfig ? Pick<ProviderContext, "auth"> : Record<never, never>)
|
|
2313
|
+
& ("ocr" extends keyof TConfig ? Pick<ProviderContext, "ocr"> : Record<never, never>)
|
|
2314
|
+
& ("stt" extends keyof TConfig ? Pick<ProviderContext, "stt"> : Record<never, never>)
|
|
2315
|
+
& ("resolver" extends keyof TConfig ? Pick<ProviderContext, "resolver"> : Record<never, never>)
|
|
2316
|
+
& ("choice" extends keyof TConfig ? Pick<ProviderContext, "choice"> : Record<never, never>);
|
|
2317
|
+
|
|
2292
2318
|
export interface ProxiedOAuthConfig {
|
|
2293
2319
|
authorizeUrl: string;
|
|
2294
2320
|
tokenUrl: string;
|
|
@@ -2345,6 +2371,7 @@ export interface OperationContractMetadata {
|
|
|
2345
2371
|
export interface OperationDefinition<
|
|
2346
2372
|
TInput extends SchemaLike = SchemaLike,
|
|
2347
2373
|
TOutput extends SchemaLike = SchemaLike,
|
|
2374
|
+
TContext = ProviderContext,
|
|
2348
2375
|
> {
|
|
2349
2376
|
/**
|
|
2350
2377
|
* Short English display title for the operation. The SDK passes it through
|
|
@@ -2376,7 +2403,7 @@ export interface OperationDefinition<
|
|
|
2376
2403
|
input: TInput;
|
|
2377
2404
|
output: TOutput;
|
|
2378
2405
|
handler(
|
|
2379
|
-
ctx:
|
|
2406
|
+
ctx: TContext,
|
|
2380
2407
|
input: InferSchemaOutput<TInput>,
|
|
2381
2408
|
):
|
|
2382
2409
|
| OperationHandlerResult<InferSchemaOutput<TOutput>>
|