@apifuse/provider-sdk 2.2.0-beta.16 → 2.2.0-beta.17

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.
@@ -1,10 +1,11 @@
1
1
  import { Socket } from "node:net";
2
2
  import { type TLSSocket } from "node:tls";
3
+ import { type ProxyProtocol } from "../config/loader.js";
3
4
  import { TransportError } from "../errors.js";
4
- import type { NativeNetworkClient, NativeNetworkConnection, NativeNetworkConnectInput, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyEgressInfo, ProviderProxyPolicy, ProviderProxyProvider } from "../types.js";
5
+ import type { NativeNetworkClient, NativeNetworkConnectInput, NativeNetworkConnection, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyEgressInfo, ProviderProxyPolicy, ProviderProxyProvider, EnvContext } from "../types.js";
5
6
  export type NativeNetworkErrorCode = "native_connection_aborted" | "native_connection_closed" | "native_connection_failed" | "native_connection_idle_timeout" | "native_connection_timeout" | "native_egress_authorization_failed" | "native_egress_grant_expired" | "native_egress_grant_invalid" | "native_egress_grant_limit_exceeded" | "native_egress_input_invalid" | "native_egress_not_declared" | "native_egress_policy_invalid" | "native_dynamic_egress_unsupported" | "native_proxy_expired" | "native_proxy_invalid";
6
7
  export declare class NativeNetworkError extends TransportError {
7
- constructor(message: string, code: NativeNetworkErrorCode);
8
+ constructor(message: string, code: NativeNetworkErrorCode, cause?: Error);
8
9
  get code(): NativeNetworkErrorCode;
9
10
  }
10
11
  export declare class NativeProxyExpiredError extends NativeNetworkError {
@@ -13,9 +14,9 @@ export declare class NativeProxyExpiredError extends NativeNetworkError {
13
14
  }
14
15
  /** Raised before transport setup when a native destination is not authorized. */
15
16
  export declare class NativeEgressNotDeclaredError extends NativeNetworkError {
16
- readonly host: string;
17
17
  readonly port: number;
18
18
  readonly tls: "required" | "disabled";
19
+ readonly host: string;
19
20
  constructor(host: string, port: number, tls: "required" | "disabled");
20
21
  }
21
22
  /**
@@ -23,10 +24,10 @@ export declare class NativeEgressNotDeclaredError extends NativeNetworkError {
23
24
  * its expiry remains in the client's bounded recent-expiry evidence window.
24
25
  */
25
26
  export declare class NativeEgressGrantExpiredError extends NativeNetworkError {
26
- readonly host: string;
27
27
  readonly port: number;
28
28
  readonly tls: "required" | "disabled";
29
29
  readonly expiresAt: string;
30
+ readonly host: string;
30
31
  constructor(host: string, port: number, tls: "required" | "disabled", expiresAt: string);
31
32
  }
32
33
  /** Raised when an established connection exceeds its opt-in read-idle window. */
@@ -41,13 +42,42 @@ export type NativeGatewayProxySynthesisInput = {
41
42
  readonly policy: ProviderProxyPolicy;
42
43
  readonly affinityKey?: string;
43
44
  readonly now: number;
45
+ readonly protocol: ProxyProtocol;
46
+ readonly credentials: VendorCredentialResolver;
47
+ };
48
+ export type VendorCredentialLookup = {
49
+ readonly kind: "present";
50
+ readonly values: Readonly<Record<string, string>>;
51
+ } | {
52
+ readonly kind: "absent";
53
+ readonly missing: readonly string[];
54
+ };
55
+ export type VendorCredentialResolver = (vendor: ProviderProxyProvider) => VendorCredentialLookup;
56
+ export type NativeGatewayProxySkipReason = {
57
+ readonly kind: "credentials_absent";
58
+ readonly missing: readonly string[];
59
+ } | {
60
+ readonly kind: "protocol_unsupported";
61
+ readonly protocol: string;
62
+ } | {
63
+ readonly kind: "allocation_failed";
64
+ readonly cause: Error;
65
+ } | {
66
+ readonly kind: "credential_lookup_failed";
67
+ readonly cause: Error;
44
68
  };
69
+ export type NativeGatewayProxySynthesisResult = NativeGatewayProxy | {
70
+ readonly kind: "skipped";
71
+ readonly reason: NativeGatewayProxySkipReason;
72
+ } | undefined;
45
73
  /** A vendor adapter in the ordered native gateway resolution chain. */
46
- export type NativeGatewayProxySynthesizer = (input: NativeGatewayProxySynthesisInput) => NativeGatewayProxy | undefined;
74
+ export type NativeGatewayProxySynthesizer = (input: NativeGatewayProxySynthesisInput) => NativeGatewayProxySynthesisResult | Promise<NativeGatewayProxySynthesisResult>;
47
75
  export type NativeGatewayProxyResolutionInput = {
48
76
  readonly policy: ProviderProxyPolicy;
49
77
  readonly affinityKey?: string;
50
78
  readonly now?: number;
79
+ readonly protocol?: ProxyProtocol;
80
+ readonly credentials?: VendorCredentialResolver;
51
81
  readonly gatewaySynthesizers?: readonly NativeGatewayProxySynthesizer[];
52
82
  };
53
83
  export type NativeNetworkClientOptions = {
@@ -55,6 +85,10 @@ export type NativeNetworkClientOptions = {
55
85
  readonly affinityKey?: string;
56
86
  /** Stable credential/account identity; hashed before vendor synthesis. */
57
87
  readonly credentialIdentity?: string;
88
+ /** Vendor credential lookup; defaults to the process EnvContext. */
89
+ readonly credentials?: VendorCredentialResolver;
90
+ /** Explicit CONNECT/SOCKS5 override; vendors otherwise choose their default. */
91
+ readonly proxyProtocol?: ProxyProtocol;
58
92
  /** Vendor adapters in priority order within each policy vendor slot. */
59
93
  readonly gatewaySynthesizers?: readonly NativeGatewayProxySynthesizer[];
60
94
  /** Warning-level lifecycle diagnostic sink. */
@@ -67,10 +101,12 @@ export type NativeNetworkClientOptions = {
67
101
  /** Additional deployment authorization layered on top of SDK enforcement. */
68
102
  readonly grantTcpEgress?: (input: NativeNetworkDynamicGrantOptions) => NativeNetworkEgressGrant;
69
103
  };
104
+ /** Build a resolver over the SDK's existing injectable environment context. */
105
+ export declare function createEnvVendorCredentialResolver(env?: EnvContext): VendorCredentialResolver;
70
106
  /** Domain-separated, process-independent affinity derived from credential identity. */
71
107
  export declare function deriveNativeCredentialAffinityKey(credentialIdentity: string): string;
72
- /** Resolve the first configured native gateway without invoking an allocator API. */
73
- export declare function resolveNativeGatewayProxy(input: NativeGatewayProxyResolutionInput): NativeGatewayProxy | undefined;
108
+ /** Resolve the first configured native gateway, including allocation vendors. */
109
+ export declare function resolveNativeGatewayProxy(input: NativeGatewayProxyResolutionInput): Promise<NativeGatewayProxy | undefined>;
74
110
  export declare function createNativeNetworkConnection(socket: Socket | TLSSocket, proxy: NativeGatewayProxy | undefined, options: NativeNetworkClientOptions, idleTimeoutMs?: number): NativeNetworkConnection;
75
111
  type NativeConnectTls = "required" | "disabled";
76
112
  export declare const NATIVE_EGRESS_EXPIRED_EVIDENCE_LIMIT = 256;