@apifuse/provider-sdk 2.2.0-beta.12 → 2.2.0-beta.13

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 (52) hide show
  1. package/AUTHORING.md +201 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +26 -2
  4. package/bin/apifuse-pack-types.ts +30 -1
  5. package/bin/apifuse-record.ts +622 -57
  6. package/bin/apifuse-submit-check.ts +43 -10
  7. package/dist/define.d.ts +2 -1
  8. package/dist/define.js +61 -3
  9. package/dist/fixture-sanitization.d.ts +26 -0
  10. package/dist/fixture-sanitization.js +216 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +1 -0
  13. package/dist/provider.d.ts +2 -1
  14. package/dist/provider.js +1 -0
  15. package/dist/runtime/http.js +86 -32
  16. package/dist/runtime/instrumentation.js +295 -9
  17. package/dist/runtime/native-network.d.ts +53 -0
  18. package/dist/runtime/native-network.js +477 -0
  19. package/dist/runtime/proxy-nodemaven.d.ts +14 -0
  20. package/dist/runtime/proxy-nodemaven.js +20 -2
  21. package/dist/runtime/request-options.d.ts +68 -1
  22. package/dist/runtime/request-options.js +548 -0
  23. package/dist/runtime/stealth.d.ts +3 -1
  24. package/dist/runtime/stealth.js +239 -39
  25. package/dist/server/index.d.ts +1 -1
  26. package/dist/server/index.js +1 -1
  27. package/dist/server/self-test-input-tokens.d.ts +2 -1
  28. package/dist/server/self-test-input-tokens.js +18 -14
  29. package/dist/stream-evidence.d.ts +74 -0
  30. package/dist/stream-evidence.js +785 -0
  31. package/dist/testing/index.d.ts +1 -1
  32. package/dist/testing/index.js +1 -1
  33. package/dist/testing/run.d.ts +32 -2
  34. package/dist/testing/run.js +451 -19
  35. package/dist/types.d.ts +162 -0
  36. package/package.json +2 -1
  37. package/src/define.ts +81 -3
  38. package/src/fixture-sanitization.ts +247 -0
  39. package/src/index.ts +37 -0
  40. package/src/provider.ts +37 -0
  41. package/src/runtime/http.ts +144 -38
  42. package/src/runtime/instrumentation.ts +424 -8
  43. package/src/runtime/native-network.ts +600 -0
  44. package/src/runtime/proxy-nodemaven.ts +37 -2
  45. package/src/runtime/request-options.ts +680 -1
  46. package/src/runtime/stealth.ts +293 -40
  47. package/src/server/index.ts +4 -1
  48. package/src/server/self-test-input-tokens.ts +29 -14
  49. package/src/stream-evidence.ts +988 -0
  50. package/src/testing/index.ts +9 -1
  51. package/src/testing/run.ts +608 -12
  52. package/src/types.ts +194 -0
package/src/types.ts CHANGED
@@ -824,6 +824,12 @@ export interface ProviderProxyPolicy {
824
824
  affinity?: ProviderProxySessionAffinity;
825
825
  lifetimeMinutes?: number;
826
826
  poolSize?: number;
827
+ /**
828
+ * Seconds before hard sticky expiry at which native connections receive
829
+ * the `expiring` event so the provider can drain and reconnect cleanly.
830
+ * Declared by the provider; the SDK does not assume a default cut point.
831
+ */
832
+ drainLeadSeconds?: number;
827
833
  };
828
834
  }
829
835
 
@@ -1000,6 +1006,11 @@ export interface HttpRetrySummary {
1000
1006
  export interface RequestOptions {
1001
1007
  headers?: Record<string, string>;
1002
1008
  params?: RequestParams;
1009
+ /**
1010
+ * Query parameters whose values contain credentials or other secret material.
1011
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1012
+ */
1013
+ sensitiveParams?: Record<string, string>;
1003
1014
  proxy?: string;
1004
1015
  timeout?: number;
1005
1016
  /**
@@ -1032,6 +1043,12 @@ export interface StealthFetchOptions extends RequestOptions {
1032
1043
  method?: HttpMethod;
1033
1044
  body?: string | Buffer;
1034
1045
  redirect?: "follow" | "manual" | "error";
1046
+ /**
1047
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1048
+ * transport aborts the response and throws `response_too_large` if the
1049
+ * declared or streamed body exceeds this limit.
1050
+ */
1051
+ maxBodyBytes?: number;
1035
1052
  /**
1036
1053
  * Offsets policy-managed proxy pool selection for caller-managed retries.
1037
1054
  * Use when a request receives an upstream challenge page rather than a
@@ -1232,6 +1249,171 @@ export interface HttpClient {
1232
1249
  ): Promise<AsyncIterable<SseMessage>>;
1233
1250
  }
1234
1251
 
1252
+ /** Request-scoped file reference accepted by provider operation inputs. */
1253
+ export interface ProviderFileRef {
1254
+ readonly type: "request_file";
1255
+ readonly id: string;
1256
+ readonly filename: string;
1257
+ readonly mime_type?: string;
1258
+ readonly size: number;
1259
+ readonly sha256?: string;
1260
+ }
1261
+
1262
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1263
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1264
+ readonly mimeType?: string;
1265
+ arrayBuffer(): Promise<ArrayBuffer>;
1266
+ bytes(): Promise<Uint8Array>;
1267
+ stream(): ReadableStream<Uint8Array>;
1268
+ };
1269
+
1270
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1271
+ export interface ProviderFilesContext {
1272
+ has(input: string | ProviderFileRef): boolean;
1273
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1274
+ }
1275
+
1276
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1277
+
1278
+ export interface NativeTcpPortRange {
1279
+ readonly start: number;
1280
+ readonly end: number;
1281
+ }
1282
+
1283
+ /** Static native TCP egress declared by a provider. */
1284
+ export interface NativeTcpEgressRule {
1285
+ readonly host: string;
1286
+ readonly ports: readonly number[];
1287
+ readonly tls: NativeTcpTlsMode;
1288
+ }
1289
+
1290
+ /**
1291
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1292
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1293
+ */
1294
+ export interface NativeTcpDynamicEgressRule {
1295
+ readonly sourceHost?: string;
1296
+ readonly sourceHostSuffixes?: readonly string[];
1297
+ readonly sourcePorts?: readonly number[];
1298
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1299
+ readonly targetHostSuffixes: readonly string[];
1300
+ readonly targetPorts?: readonly number[];
1301
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1302
+ readonly tls: NativeTcpTlsMode;
1303
+ readonly ttlMs?: number;
1304
+ readonly maxGrants?: number;
1305
+ }
1306
+
1307
+ /** Common TCP/TLS connection input supported by the native runtime. */
1308
+ export interface NativeNetworkConnectInput {
1309
+ readonly host: string;
1310
+ readonly port: number;
1311
+ readonly serverName?: string;
1312
+ readonly rejectUnauthorized?: boolean;
1313
+ /**
1314
+ * Maximum time without a successful socket read before the connection is
1315
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1316
+ */
1317
+ readonly idleTimeoutMs?: number;
1318
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1319
+ readonly timeoutMs?: number;
1320
+ readonly signal?: AbortSignal;
1321
+ /** Overrides the credential-derived sticky affinity key. */
1322
+ readonly affinityKey?: string;
1323
+ }
1324
+
1325
+ export type NativeNetworkConnectOptions = Omit<
1326
+ NativeNetworkConnectInput,
1327
+ "serverName" | "rejectUnauthorized"
1328
+ >;
1329
+
1330
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1331
+
1332
+ export interface NativeNetworkDynamicGrantOptions {
1333
+ readonly sourceHost: string;
1334
+ readonly sourcePort: number;
1335
+ readonly host: string;
1336
+ readonly port: number;
1337
+ readonly tls: NativeTcpTlsMode;
1338
+ readonly ttlMs?: number;
1339
+ }
1340
+
1341
+ export interface NativeNetworkEgressGrant {
1342
+ revoke(): void;
1343
+ }
1344
+
1345
+ /** Consumer-facing alias used by native TCP providers. */
1346
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1347
+
1348
+ /** Resolved egress identity for a native connection routed through a proxy. */
1349
+ export interface NativeProxyEgressInfo {
1350
+ readonly vendor: ProviderProxyProvider;
1351
+ readonly sticky: boolean;
1352
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1353
+ readonly sessionId?: string;
1354
+ /** Hard expiry of the sticky binding, ISO 8601. */
1355
+ readonly expiresAt?: string;
1356
+ }
1357
+
1358
+ export type NativeProxyExpiringReason = "sticky_expiry";
1359
+
1360
+ export interface NativeProxyExpiringEvent {
1361
+ readonly expiresAt: string;
1362
+ readonly leadSeconds: number;
1363
+ readonly reason: NativeProxyExpiringReason;
1364
+ }
1365
+
1366
+ /**
1367
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1368
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1369
+ */
1370
+ export type NativeProxyDrainHandler = (
1371
+ event: NativeProxyExpiringEvent,
1372
+ ) => void | Promise<void>;
1373
+
1374
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1375
+ export interface NativeNetworkCloseReason {
1376
+ readonly code: string;
1377
+ readonly message: string;
1378
+ }
1379
+
1380
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1381
+ export interface NativeNetworkConnection {
1382
+ /** Present when the connection was routed through a proxy. */
1383
+ readonly proxy?: NativeProxyEgressInfo;
1384
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1385
+ readonly closeReason?: NativeNetworkCloseReason;
1386
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1387
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1388
+ read(): Promise<Uint8Array | null>;
1389
+ write(data: Uint8Array): Promise<void>;
1390
+ close(): Promise<void>;
1391
+ }
1392
+
1393
+ export interface NativeNetworkClient {
1394
+ connectTcp(
1395
+ input: NativeNetworkConnectOptions,
1396
+ ): Promise<NativeNetworkConnection>;
1397
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1398
+ grantTcpEgress(
1399
+ input: NativeNetworkDynamicGrantOptions,
1400
+ ): NativeNetworkEgressGrant;
1401
+ }
1402
+
1403
+ export interface NativeContext {
1404
+ readonly network: NativeNetworkClient;
1405
+ }
1406
+
1407
+ /** Consumer-facing alias for the native capability on provider contexts. */
1408
+ export type NativeProviderContext = NativeContext;
1409
+
1410
+ export interface NativeProviderConfig {
1411
+ readonly network?: {
1412
+ readonly tcp?: readonly NativeTcpEgressRule[];
1413
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1414
+ };
1415
+ }
1416
+
1235
1417
  export interface ProviderCacheKeyOptions {
1236
1418
  /**
1237
1419
  * Additional field names to omit from stable key material. The SDK always
@@ -1649,6 +1831,8 @@ export interface FlowContext {
1649
1831
  tenantId: string;
1650
1832
  providerId: string;
1651
1833
  http: HttpClient;
1834
+ /** Present when the selected runtime supplies native network capabilities. */
1835
+ readonly native?: NativeProviderContext;
1652
1836
  stealth: StealthClient;
1653
1837
  env: EnvContext;
1654
1838
  credential?: CredentialContext;
@@ -1768,6 +1952,10 @@ export interface ProviderContext {
1768
1952
  credential: CredentialContext;
1769
1953
  request?: ProviderRequestContext;
1770
1954
  http: HttpClient;
1955
+ /** Present for requests carrying runtime-resolvable file references. */
1956
+ readonly files?: ProviderFilesContext;
1957
+ /** Present when the selected runtime supplies native network capabilities. */
1958
+ readonly native?: NativeProviderContext;
1771
1959
  cache: ProviderCache;
1772
1960
  state: ProviderRuntimeState;
1773
1961
  stealth: StealthClient;
@@ -1860,6 +2048,11 @@ export interface OperationDefinition<
1860
2048
  fixtures?: {
1861
2049
  request: InferSchemaOutput<TInput>;
1862
2050
  response: InferSchemaOutput<TOutput>;
2051
+ /**
2052
+ * KST calendar date when `response` evidence was captured. Date fields in
2053
+ * the response align with this date, not a resolved relative request date.
2054
+ */
2055
+ recordedAt?: string;
1863
2056
  };
1864
2057
  upstream?: {
1865
2058
  baseUrl?: string;
@@ -1923,6 +2116,7 @@ export interface ProviderDefinition {
1923
2116
  */
1924
2117
  deployment?: ProviderDeploymentOverrides;
1925
2118
  allowedHosts?: string[];
2119
+ native?: NativeProviderConfig;
1926
2120
  stealth?: {
1927
2121
  profile: string;
1928
2122
  platform: StealthPlatform;