@apifuse/provider-sdk 2.2.0-beta.26 → 2.2.0-beta.27

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/dist/contract.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { canonicalJson, compactObject, copyRecordWithout, toJsonValue, } from "./contract-json.js";
3
- import { describeSchema, OutputTextTrustProjectionError, serializeSmsMatcher, } from "./contract-serialization.js";
3
+ import { describeSchema, serializeSmsMatcher } from "./contract-serialization.js";
4
4
  import { PROVIDER_CONTRACT_SCHEMA_VERSION, } from "./contract-types.js";
5
5
  export { canonicalJson, PROVIDER_CONTRACT_SCHEMA_VERSION, };
6
- export { OutputTextTrustProjectionError };
7
6
  export function extractProviderContract(provider) {
8
7
  const auth = extractAuth(provider.auth);
9
8
  const stealth = toJsonValue(provider.stealth);
@@ -61,7 +60,7 @@ function extractOperation(operationId, operation) {
61
60
  const relatedOperations = toJsonValue(operation.relatedOperations);
62
61
  const toolRouter = toJsonValue(operation.toolRouter);
63
62
  const observability = toJsonValue(operation.observability);
64
- const transport = extractTransport(operation.transport, operationId);
63
+ const transport = extractTransport(operation.transport);
65
64
  const fixtures = toJsonValue(operation.fixtures);
66
65
  const upstream = toJsonValue(operation.upstream);
67
66
  const hints = toJsonValue(operation.hints);
@@ -70,7 +69,7 @@ function extractOperation(operationId, operation) {
70
69
  return {
71
70
  id: operationId,
72
71
  inputSchema: describeSchema(operation.input),
73
- outputSchema: describeSchema(operation.output, { operationId, outputTextTrust: true }),
72
+ outputSchema: describeSchema(operation.output),
74
73
  ...(descriptionKey === undefined ? {} : { descriptionKey }),
75
74
  ...(docs === undefined ? {} : { docs }),
76
75
  ...(whenToUseKeys === undefined ? {} : { whenToUseKeys }),
@@ -106,7 +105,7 @@ function extractAuth(value) {
106
105
  : undefined,
107
106
  });
108
107
  }
109
- function extractTransport(value, operationId) {
108
+ function extractTransport(value) {
110
109
  if (!value)
111
110
  return undefined;
112
111
  if (value.kind !== "sse")
@@ -115,10 +114,7 @@ function extractTransport(value, operationId) {
115
114
  ...copyRecordWithout(value, new Set(["events"])),
116
115
  events: Object.fromEntries(Object.entries(value.events)
117
116
  .sort(([leftId], [rightId]) => leftId.localeCompare(rightId))
118
- .map(([eventName, schema]) => [
119
- eventName,
120
- describeSchema(schema, { eventName, operationId, outputTextTrust: true }),
121
- ])),
117
+ .map(([eventName, schema]) => [eventName, describeSchema(schema)])),
122
118
  });
123
119
  }
124
120
  function extractHealthCheck(value) {
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from "./ceremonies/index.js";
3
3
  export * from "./choice-token.js";
4
4
  export type { ApiFuseConfig, BrowserConfig, ProxyProtocol, ProxyResolutionOptions, ProxyResolutionSource, ProxyVendorName, ResolvedProxyConfig, SessionConfig, } from "./config/loader.js";
5
5
  export { defineConfig, loadApiFuseConfig, resolveProxy } from "./config/loader.js";
6
- export { canonicalJson, digestProviderContract, extractProviderContract, type JsonPrimitive, type JsonValue, OutputTextTrustProjectionError, PROVIDER_CONTRACT_SCHEMA_VERSION, type ProviderContractOperation, type ProviderContractSnapshot, } from "./contract.js";
6
+ export { canonicalJson, digestProviderContract, extractProviderContract, type JsonPrimitive, type JsonValue, PROVIDER_CONTRACT_SCHEMA_VERSION, type ProviderContractOperation, type ProviderContractSnapshot, } from "./contract.js";
7
7
  export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, type ProviderConfig, } from "./define.js";
8
8
  export type { DevServerOptions } from "./dev.js";
9
9
  export { createDevServer, startDevServer } from "./dev.js";
@@ -37,7 +37,7 @@ export { createStealthClient } from "./runtime/stealth.js";
37
37
  export { APIFUSE__OCR__API_KEY_ENV, APIFUSE__OCR__BACKEND_ENV, APIFUSE__OCR__BASE_URL_ENV, APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__OCR__MODEL_ENV, CLOUDFLARE_ACCOUNT_ID_ENV, CLOUDFLARE_WORKERS_AI_OCR_BACKEND, createCloudflareWorkersAiOcrClient, createOcrClientFromEnv, createOpenAiCompatibleOcrClient, createUnsupportedOcrClient, DEFAULT_CLOUDFLARE_WORKERS_AI_OCR_MODEL, extractCaptchaCandidates, OPENAI_COMPATIBLE_OCR_BACKEND, } from "./runtime/ocr.js";
38
38
  export { APIFUSE__STT__BACKEND_ENV, APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__STT__MODEL_ENV, createSttClientFromEnv, createUnsupportedSttClient, extractVerificationCode, resolveSttPrompt, } from "./runtime/stt.js";
39
39
  export { type CreateTraceContextOptions, createTraceContext, type Span, type TraceContext, } from "./runtime/trace.js";
40
- export { APIFUSE_TEXT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, AUTO_TRUSTED_ZOD_STRING_FORMATS, collectOutputTextTrust, collectSensitivePaths, describeKey, field, fields, findUnclassifiedOutputTextPaths, isSensitiveSchema, OutputTextTrustCollectionError, OutputTextTrustSchemaError, redactPayload, type OutputTextTrustMap, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, textTrust, type TextTrust, type TextTrustMetadata, z, } from "./schema.js";
40
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema.js";
41
41
  export { createServerApp, ERROR_OBSERVABILITY_HEADER, type ServeOptions, serve, } from "./server/index.js";
42
42
  export { getStealthProfile, listStealthProfiles } from "./stealth/profiles.js";
43
43
  export * from "./stream.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export * from "./auth.js";
3
3
  export * from "./ceremonies/index.js";
4
4
  export * from "./choice-token.js";
5
5
  export { defineConfig, loadApiFuseConfig, resolveProxy } from "./config/loader.js";
6
- export { canonicalJson, digestProviderContract, extractProviderContract, OutputTextTrustProjectionError, PROVIDER_CONTRACT_SCHEMA_VERSION, } from "./contract.js";
6
+ export { canonicalJson, digestProviderContract, extractProviderContract, PROVIDER_CONTRACT_SCHEMA_VERSION, } from "./contract.js";
7
7
  export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, } from "./define.js";
8
8
  export { createDevServer, startDevServer } from "./dev.js";
9
9
  export * from "./errors.js";
@@ -33,7 +33,7 @@ export { createStealthClient } from "./runtime/stealth.js";
33
33
  export { APIFUSE__OCR__API_KEY_ENV, APIFUSE__OCR__BACKEND_ENV, APIFUSE__OCR__BASE_URL_ENV, APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__OCR__MODEL_ENV, CLOUDFLARE_ACCOUNT_ID_ENV, CLOUDFLARE_WORKERS_AI_OCR_BACKEND, createCloudflareWorkersAiOcrClient, createOcrClientFromEnv, createOpenAiCompatibleOcrClient, createUnsupportedOcrClient, DEFAULT_CLOUDFLARE_WORKERS_AI_OCR_MODEL, extractCaptchaCandidates, OPENAI_COMPATIBLE_OCR_BACKEND, } from "./runtime/ocr.js";
34
34
  export { APIFUSE__STT__BACKEND_ENV, APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__STT__MODEL_ENV, createSttClientFromEnv, createUnsupportedSttClient, extractVerificationCode, resolveSttPrompt, } from "./runtime/stt.js";
35
35
  export { createTraceContext, } from "./runtime/trace.js";
36
- export { APIFUSE_TEXT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, AUTO_TRUSTED_ZOD_STRING_FORMATS, collectOutputTextTrust, collectSensitivePaths, describeKey, field, fields, findUnclassifiedOutputTextPaths, isSensitiveSchema, OutputTextTrustCollectionError, OutputTextTrustSchemaError, redactPayload, sensitive, textTrust, z, } from "./schema.js";
36
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema.js";
37
37
  export { createServerApp, ERROR_OBSERVABILITY_HEADER, serve, } from "./server/index.js";
38
38
  export { getStealthProfile, listStealthProfiles } from "./stealth/profiles.js";
39
39
  export * from "./stream.js";
@@ -6,7 +6,7 @@ export { centered, delayed, defineHealthJourney, defineOperation, defineProvider
6
6
  export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
7
7
  export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
8
8
  export { type CreateProviderChoiceContextOptions, createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
9
- export { APIFUSE_TEXT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, AUTO_TRUSTED_ZOD_STRING_FORMATS, collectOutputTextTrust, collectSensitivePaths, describeKey, field, fields, findUnclassifiedOutputTextPaths, isSensitiveSchema, OutputTextTrustCollectionError, OutputTextTrustSchemaError, redactPayload, type OutputTextTrustMap, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, textTrust, type TextTrust, type TextTrustMetadata, z, } from "./schema.js";
9
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema.js";
10
10
  export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRedirectFailureReason, HttpRedirectPolicy, HttpRedirectPolicyMode, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, NativeContext, NativeNetworkClient, NativeNetworkCloseReason, NativeNetworkConnection, NativeNetworkConnectInput, NativeNetworkConnectOptions, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProviderContext, NativeProxyDrainHandler, NativeProxyEgressInfo, NativeProxyExpiringEvent, NativeProxyExpiringReason, NativeTcpDynamicEgressRule, NativeTcpEgressGrant, NativeTcpEgressRule, NativeTcpPortRange, NativeTcpTlsMode, NativeTlsConnectOptions, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationDocMeta, OperationErrorCode, ProviderErrorStatus, OperationInputExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationToolRouterMetadata, OperationTransport, ProviderAccessVisibility, ProviderChoiceBindingOptions, ProviderChoiceContext, ProviderChoiceIssueOptions, ProviderChoiceParseOptions, ProviderContext, ProviderDefinition, ProviderDeploymentOverrides, ProviderFileRef, ProviderFilesContext, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProxiedOAuthConfig, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderResolvedFile, ProviderRuntimeState, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, RedirectRunReason, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateNamespaceScope, StateValue, StateWriteOptions, } from "./types.js";
11
11
  export { createNativeNetworkClient, createEnvVendorCredentialResolver, deriveNativeCredentialAffinityKey, NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, resolveNativeGatewayProxy, type NativeGatewayProxy, type NativeGatewayProxyResolutionInput, type NativeGatewayProxySkipReason, type NativeGatewayProxySynthesizer, type NativeGatewayProxySynthesisResult, type NativeGatewayProxySynthesisInput, type NativeNetworkClientOptions, type NativeNetworkErrorCode, type VendorCredentialLookup, type VendorCredentialResolver, } from "./runtime/native-network.js";
12
12
  export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
package/dist/provider.js CHANGED
@@ -5,6 +5,6 @@ export { centered, delayed, defineHealthJourney, defineOperation, defineProvider
5
5
  export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
6
6
  export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
7
7
  export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
8
- export { APIFUSE_TEXT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, AUTO_TRUSTED_ZOD_STRING_FORMATS, collectOutputTextTrust, collectSensitivePaths, describeKey, field, fields, findUnclassifiedOutputTextPaths, isSensitiveSchema, OutputTextTrustCollectionError, OutputTextTrustSchemaError, redactPayload, sensitive, textTrust, z, } from "./schema.js";
8
+ export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema.js";
9
9
  export { createNativeNetworkClient, createEnvVendorCredentialResolver, deriveNativeCredentialAffinityKey, NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, resolveNativeGatewayProxy, } from "./runtime/native-network.js";
10
10
  export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
package/dist/schema.d.ts CHANGED
@@ -13,27 +13,7 @@ export declare function safeParseSchemaSync<TSchema extends SchemaLike>(schema:
13
13
  export declare const APIFUSE_SENSITIVE_META_KEY = "x-apifuse-sensitive";
14
14
  export declare const APIFUSE_SENSITIVE_KIND_META_KEY = "x-apifuse-sensitive-kind";
15
15
  export declare const APIFUSE_DESCRIPTION_KEY_META_KEY = "x-apifuse-description-key";
16
- export declare const APIFUSE_TEXT_TRUST_META_KEY = "x-apifuse-text-trust";
17
16
  export declare const APIFUSE_REDACTION_MARKER = "<redacted>";
18
- export type TextTrust = "trusted" | "untrusted";
19
- export interface TextTrustMetadata {
20
- readonly v: 1;
21
- readonly trust: TextTrust;
22
- readonly carrier?: "container";
23
- }
24
- export type OutputTextTrustMap = Readonly<Record<string, TextTrust>>;
25
- /**
26
- * Auto-trusted output leaves are string-valued `z.literal()` / `z.enum()`,
27
- * patterns whose every top-level alternative is anchored at both ends and
28
- * whose bodies use only finite quantifiers, have a maximum match length of 32,
29
- * and contain only digits and safe punctuation in positive whitespace-free
30
- * character classes, literals/escapes, and ordinary or non-capturing groups,
31
- * plus the structurally constrained formats listed here. A brand is trusted
32
- * only when its underlying schema meets one of those rules. Letter-bearing
33
- * identifiers, length-only strings, and other formats (including email, URL,
34
- * base64, and JWT) are not trusted.
35
- */
36
- export declare const AUTO_TRUSTED_ZOD_STRING_FORMATS: readonly ["cidrv4", "cidrv6", "date", "datetime", "duration", "e164", "ipv4", "ipv6", "time"];
37
17
  export type SensitivePathSegment = string | "*";
38
18
  export type SensitivePath = readonly SensitivePathSegment[];
39
19
  export type SensitiveFieldKind = "api_key" | "authorization" | "cookie" | "credential" | "otp" | "password" | "payment_url" | "personal_data" | "phone" | "secret" | "token";
@@ -52,12 +32,9 @@ export interface SensitiveFieldOptions {
52
32
  description?: string;
53
33
  }
54
34
  export declare function describeKey<TSchema extends ZodType>(schema: TSchema, key: ProviderLocaleKey | string): TSchema;
55
- /** Attach output text-trust authoring metadata without changing validation. */
56
- export declare function textTrust<TSchema extends ZodType>(schema: TSchema, trust: TextTrust): TSchema;
57
35
  declare module "zod" {
58
36
  interface ZodType {
59
37
  describeKey(key: ProviderLocaleKey | string): this;
60
- textTrust(trust: TextTrust): this;
61
38
  }
62
39
  }
63
40
  export declare function field<TSchema extends ZodType>(schema: TSchema, options?: SensitiveFieldOptions): TSchema;
@@ -92,46 +69,6 @@ export declare const fields: {
92
69
  description?: string;
93
70
  }) => ZodString;
94
71
  };
95
- export declare class OutputTextTrustSchemaError extends TypeError {
96
- readonly code = "invalid_output_text_trust_schema";
97
- constructor(value: unknown);
98
- }
99
- export declare class OutputTextTrustCollectionError extends Error {
100
- readonly schemaPath: string;
101
- readonly classification: "untrusted";
102
- readonly code = "output_text_trust_collection_failed";
103
- constructor(schemaPath: string, cause: unknown);
104
- }
105
- /**
106
- * Collect every textual leaf in a Zod output schema as a deterministic
107
- * schema-path-to-classification object. The path grammar is rooted at `$`:
108
- * object keys are `["key"]`, arrays and record values are `[*]`, tuple slots
109
- * are `[n]`, union/intersection alternatives are `<union:n>` / `<intersection:n>`,
110
- * record keys are `<record-key>`, and one bounded cycle expansion is marked
111
- * `<recursive>`.
112
- */
113
- export declare function collectOutputTextTrust(schema: ZodType): OutputTextTrustMap;
114
- /** Report textual output paths that lack a valid explicit or auto-derived classification. */
115
- export declare function findUnclassifiedOutputTextPaths(schema: ZodType): string[];
116
- /** @internal Used by contract JSON Schema projection. */
117
- export declare function resolveOutputTextTrust(schema: z.core.$ZodType, inheritedUntrusted?: boolean): TextTrust | undefined;
118
- /** @internal Resolve both projection states from one stable schema traversal. */
119
- export declare function resolveOutputTextTrustProjection(schema: z.core.$ZodType): {
120
- readonly inherited: TextTrust;
121
- readonly local: TextTrust;
122
- } | undefined;
123
- /** @internal Whether this node can bypass or mutate descendant validation guarantees. */
124
- export declare function invalidatesDescendantOutputTextAutoTrust(schema: z.core.$ZodType): boolean;
125
- /** @internal Run output projection without evaluating dynamic fallback callbacks. */
126
- export declare function suppressDynamicOutputFallbacksDuring<T>(project: () => T): T;
127
- /** @internal Whether this mutator has a static fallback that cannot contain text. */
128
- export declare function mutatorReturnIsProvablyNonText(schema: z.core.$ZodType): boolean;
129
- /** @internal Whether this mutator has a static array fallback. */
130
- export declare function mutatorUsesStaticArrayFallback(schema: z.core.$ZodType): boolean;
131
- /** @internal Whether this default or catch was authored with a callback. */
132
- export declare function hasDynamicOutputFallback(schema: z.core.$ZodType): boolean;
133
- /** @internal Used by contract JSON Schema projection. */
134
- export declare function inheritsUntrustedOutputTextTrust(schema: z.core.$ZodType): boolean;
135
72
  export declare function isSensitiveSchema(schema: unknown): boolean;
136
73
  export declare function collectSensitivePaths(schema: unknown): SensitivePath[];
137
74
  export declare function redactPayload(value: unknown, paths?: readonly SensitivePath[]): unknown;