@apifuse/provider-sdk 2.2.0-beta.24 → 2.2.0-beta.26
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 +7 -6
- package/CHANGELOG.md +9 -1
- package/README.md +3 -3
- package/bin/apifuse-check.ts +62 -3
- package/bin/apifuse-pack-check.ts +8 -2
- package/bin/apifuse-pack-smoke.ts +43 -2
- package/bin/apifuse-pack-types.ts +58 -0
- package/bin/apifuse-submit-check.ts +15 -2
- package/dist/auth.js +29 -0
- package/dist/cli/templates/provider/README.md.tpl +4 -4
- package/dist/contract-serialization.d.ts +20 -1
- package/dist/contract-serialization.js +583 -8
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +9 -5
- package/dist/declaration-validation.d.ts +23 -0
- package/dist/declaration-validation.js +159 -0
- package/dist/define.d.ts +1 -1
- package/dist/define.js +13 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -3
- package/dist/lint.js +85 -3
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +1 -1
- package/dist/runtime/cache.d.ts +1 -0
- package/dist/runtime/cache.js +169 -15
- package/dist/runtime/resolver-vendors/bindings.d.ts +42 -2
- package/dist/runtime/resolver-vendors/bindings.js +31 -6
- package/dist/runtime/resolver-vendors/browser.d.ts +3 -7
- package/dist/runtime/resolver-vendors/browser.js +7 -22
- package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
- package/dist/runtime/resolver-vendors/hosts.js +33 -0
- package/dist/runtime/resolver-vendors/twocaptcha.d.ts +23 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +264 -0
- package/dist/runtime/resolver-vendors/types.d.ts +44 -3
- package/dist/runtime/resolver-vendors/types.js +10 -0
- package/dist/runtime/resolver.d.ts +17 -2
- package/dist/runtime/resolver.js +237 -15
- package/dist/runtime/stealth.d.ts +26 -4
- package/dist/runtime/stealth.js +224 -114
- package/dist/schema.d.ts +63 -0
- package/dist/schema.js +808 -8
- package/dist/server/serve.js +8 -0
- package/dist/stealth/profiles.js +16 -7
- package/dist/types.d.ts +37 -4
- package/package.json +2 -2
- package/src/auth.ts +40 -0
- package/src/cli/templates/provider/README.md.tpl +4 -4
- package/src/contract-serialization.ts +857 -8
- package/src/contract.ts +16 -5
- package/src/declaration-validation.ts +202 -0
- package/src/define.ts +23 -2
- package/src/index.ts +13 -0
- package/src/lint.ts +98 -3
- package/src/provider.ts +10 -0
- package/src/runtime/cache.ts +189 -14
- package/src/runtime/resolver-vendors/bindings.ts +40 -15
- package/src/runtime/resolver-vendors/browser.ts +9 -31
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +366 -0
- package/src/runtime/resolver-vendors/types.ts +54 -0
- package/src/runtime/resolver.ts +304 -24
- package/src/runtime/stealth.ts +317 -136
- package/src/schema.ts +1060 -9
- package/src/server/serve.ts +8 -0
- package/src/stealth/profiles.ts +17 -7
- package/src/types.ts +39 -6
package/src/server/serve.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { Hono } from "hono";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { AuthAbortError, createAuthFlowHelpers } from "../auth.js";
|
|
7
|
+
import { validateFailClosedDeclaration } from "../declaration-validation.js";
|
|
7
8
|
import {
|
|
8
9
|
SDK_OWNED_PROVIDER_ERROR_CODES,
|
|
9
10
|
SDK_RUNTIME_OWNED_ERROR_CODES,
|
|
@@ -1840,6 +1841,11 @@ export function createServerApp(
|
|
|
1840
1841
|
provider: ProviderDefinition,
|
|
1841
1842
|
options: ProviderServerOptions = {},
|
|
1842
1843
|
): Hono {
|
|
1844
|
+
// Fail-closed validation runs here rather than only in serve(): createServerApp
|
|
1845
|
+
// is a public export, so a cast-bypassed declaration would otherwise reach the
|
|
1846
|
+
// request path unvalidated. serve() calls into this function, so validating
|
|
1847
|
+
// here covers both entry points exactly once per app construction.
|
|
1848
|
+
validateFailClosedDeclaration(provider);
|
|
1843
1849
|
validateStatefulServerConfig(options);
|
|
1844
1850
|
const app = new Hono();
|
|
1845
1851
|
const logger = options.logger ?? defaultProviderServerLogger;
|
|
@@ -2439,6 +2445,8 @@ export async function serve(
|
|
|
2439
2445
|
provider: ProviderDefinition,
|
|
2440
2446
|
options: ServeOptions = {},
|
|
2441
2447
|
): Promise<ProviderServerHandle> {
|
|
2448
|
+
// Declaration validation happens inside createServerApp (the shared app
|
|
2449
|
+
// construction path), so serve() does not duplicate the call here.
|
|
2442
2450
|
const bunRuntime = getBunServeRuntime();
|
|
2443
2451
|
|
|
2444
2452
|
if (bunRuntime === undefined) {
|
package/src/stealth/profiles.ts
CHANGED
|
@@ -68,7 +68,7 @@ const FIREFOX_H2_SETTINGS = {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
const SAFARI_H2_SETTINGS = {
|
|
71
|
-
|
|
71
|
+
// Safari 17 also sends a connection-level WINDOW_UPDATE increment of 10485760.
|
|
72
72
|
ENABLE_PUSH: 0,
|
|
73
73
|
INITIAL_WINDOW_SIZE: 4194304,
|
|
74
74
|
MAX_CONCURRENT_STREAMS: 100,
|
|
@@ -192,9 +192,9 @@ const STEALTH_PROFILES: Record<string, StealthProfile> = {
|
|
|
192
192
|
}),
|
|
193
193
|
"firefox-132": createProfile("firefox-132", {
|
|
194
194
|
platform: "macos",
|
|
195
|
-
version: "
|
|
195
|
+
version: "133.0",
|
|
196
196
|
userAgent:
|
|
197
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:
|
|
197
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0",
|
|
198
198
|
tlsClientIdentifier: "firefox_132",
|
|
199
199
|
ja3: FIREFOX_JA3,
|
|
200
200
|
h2Settings: FIREFOX_H2_SETTINGS,
|
|
@@ -210,6 +210,16 @@ const STEALTH_PROFILES: Record<string, StealthProfile> = {
|
|
|
210
210
|
h2Settings: SAFARI_H2_SETTINGS,
|
|
211
211
|
headerOrder: SAFARI_HEADER_ORDER,
|
|
212
212
|
}),
|
|
213
|
+
"safari-17": createProfile("safari-17", {
|
|
214
|
+
platform: "macos",
|
|
215
|
+
version: "17.0",
|
|
216
|
+
userAgent:
|
|
217
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
|
|
218
|
+
tlsClientIdentifier: "safari_17_0",
|
|
219
|
+
ja3: SAFARI_JA3,
|
|
220
|
+
h2Settings: SAFARI_H2_SETTINGS,
|
|
221
|
+
headerOrder: SAFARI_HEADER_ORDER,
|
|
222
|
+
}),
|
|
213
223
|
"safari-15": createProfile("safari-15", {
|
|
214
224
|
platform: "macos",
|
|
215
225
|
version: "15.6.1",
|
|
@@ -232,9 +242,9 @@ const STEALTH_PROFILES: Record<string, StealthProfile> = {
|
|
|
232
242
|
}),
|
|
233
243
|
"ios-safari-18": createProfile("ios-safari-18", {
|
|
234
244
|
platform: "ios",
|
|
235
|
-
version: "18.
|
|
245
|
+
version: "18.1.1",
|
|
236
246
|
userAgent:
|
|
237
|
-
"Mozilla/5.0 (iPhone; CPU iPhone OS
|
|
247
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Mobile/15E148 Safari/604.1",
|
|
238
248
|
tlsClientIdentifier: "safari_ios_18_0",
|
|
239
249
|
ja3: SAFARI_JA3,
|
|
240
250
|
h2Settings: SAFARI_H2_SETTINGS,
|
|
@@ -242,9 +252,9 @@ const STEALTH_PROFILES: Record<string, StealthProfile> = {
|
|
|
242
252
|
}),
|
|
243
253
|
"ios-safari-17": createProfile("ios-safari-17", {
|
|
244
254
|
platform: "ios",
|
|
245
|
-
version: "17.
|
|
255
|
+
version: "17.2",
|
|
246
256
|
userAgent:
|
|
247
|
-
"Mozilla/5.0 (iPhone; CPU iPhone OS
|
|
257
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1",
|
|
248
258
|
tlsClientIdentifier: "safari_ios_17_0",
|
|
249
259
|
ja3: SAFARI_JA3,
|
|
250
260
|
h2Settings: SAFARI_H2_SETTINGS,
|
package/src/types.ts
CHANGED
|
@@ -366,9 +366,29 @@ export type ProviderChallenge =
|
|
|
366
366
|
| {
|
|
367
367
|
readonly kind: "aws_waf";
|
|
368
368
|
readonly pageUrl: string;
|
|
369
|
+
/** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
|
|
370
|
+
readonly siteKey?: string;
|
|
369
371
|
readonly captchaScript?: string;
|
|
370
372
|
readonly context?: string;
|
|
371
373
|
readonly iv?: string;
|
|
374
|
+
}
|
|
375
|
+
| {
|
|
376
|
+
readonly kind: "akamai_sec_cpt";
|
|
377
|
+
readonly pageUrl: string;
|
|
378
|
+
/** The admitted challenge document, needed for tile/context extraction. */
|
|
379
|
+
readonly challengeHtml?: string;
|
|
380
|
+
}
|
|
381
|
+
| {
|
|
382
|
+
readonly kind: "akamai_sensor";
|
|
383
|
+
readonly pageUrl: string;
|
|
384
|
+
/** Upstream sensor script URL the payload must be POSTed to. */
|
|
385
|
+
readonly scriptUrl: string;
|
|
386
|
+
/** Current `_abck` cookie value, rotates each round. */
|
|
387
|
+
readonly abck?: string;
|
|
388
|
+
/** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
|
|
389
|
+
readonly bmsz?: string;
|
|
390
|
+
/** Bot Manager major version when known ("3" measured on zozo.jp). */
|
|
391
|
+
readonly version?: string;
|
|
372
392
|
};
|
|
373
393
|
|
|
374
394
|
export type ProviderChallengeKind = ProviderChallenge["kind"];
|
|
@@ -386,6 +406,8 @@ export type ChallengeSolution =
|
|
|
386
406
|
readonly form: "cookies";
|
|
387
407
|
readonly cookies: Readonly<Record<string, string>>;
|
|
388
408
|
readonly userAgent: string;
|
|
409
|
+
/** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
|
|
410
|
+
readonly expires?: number;
|
|
389
411
|
};
|
|
390
412
|
|
|
391
413
|
export interface ProviderResolverConfig {
|
|
@@ -393,6 +415,13 @@ export interface ProviderResolverConfig {
|
|
|
393
415
|
readonly vendors: readonly ProviderResolverVendor[];
|
|
394
416
|
/** Challenge kinds this provider is permitted to request. */
|
|
395
417
|
readonly kinds: readonly ProviderChallengeKind[];
|
|
418
|
+
/**
|
|
419
|
+
* Client fingerprint profile the SDK must use when reaching this upstream.
|
|
420
|
+
* Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
|
|
421
|
+
* challenge is served, while a Safari profile is admitted. Provider-declared
|
|
422
|
+
* because only the provider knows its upstream's admission rule.
|
|
423
|
+
*/
|
|
424
|
+
readonly clientProfile?: string;
|
|
396
425
|
}
|
|
397
426
|
|
|
398
427
|
export type SttAudioInput = {
|
|
@@ -628,9 +657,13 @@ export interface HealthJourneyDefinition {
|
|
|
628
657
|
requiredSecrets?: readonly string[];
|
|
629
658
|
manualTrigger?: HealthJourneyManualTriggerPolicy;
|
|
630
659
|
steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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>;
|
|
634
667
|
}
|
|
635
668
|
|
|
636
669
|
/**
|
|
@@ -1615,9 +1648,9 @@ export interface NativeProviderConfig {
|
|
|
1615
1648
|
|
|
1616
1649
|
export interface ProviderCacheKeyOptions {
|
|
1617
1650
|
/**
|
|
1618
|
-
* Additional field names
|
|
1619
|
-
*
|
|
1620
|
-
* cookie, token, password, and secret.
|
|
1651
|
+
* Additional field names whose values are hashed in stable key material. The
|
|
1652
|
+
* SDK always hashes values under known secret-bearing names such as serviceKey,
|
|
1653
|
+
* authorization, cookie, token, password, and secret.
|
|
1621
1654
|
*/
|
|
1622
1655
|
redactFields?: string[];
|
|
1623
1656
|
}
|