@apifuse/provider-sdk 2.2.0-beta.58 → 2.2.0-beta.60
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 +25 -0
- package/CHANGELOG.md +8 -0
- package/README.md +18 -2
- package/bin/apifuse-dev.ts +2 -1
- package/bin/apifuse-pack-types.ts +49 -0
- package/bin/apifuse-perf.ts +41 -4
- package/bin/apifuse-record.ts +9 -2
- package/dist/cli/templates/provider/README.md.tpl +15 -3
- package/dist/config/loader.d.ts +7 -0
- package/dist/config/loader.js +43 -18
- package/dist/declaration-validation.d.ts +2 -1
- package/dist/declaration-validation.js +39 -0
- package/dist/define.d.ts +4 -4
- package/dist/define.js +25 -1
- package/dist/engine.d.ts +16 -0
- package/dist/engine.js +59 -3
- package/dist/error-resolution.js +13 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +4 -2
- package/dist/lint.js +38 -17
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +2 -2
- package/dist/runtime/bounded-expiring-map.d.ts +21 -0
- package/dist/runtime/bounded-expiring-map.js +64 -0
- package/dist/runtime/browser.js +2 -1
- package/dist/runtime/cache.d.ts +2 -0
- package/dist/runtime/cache.js +11 -3
- package/dist/runtime/diagnostic-env-values.d.ts +5 -0
- package/dist/runtime/diagnostic-env-values.js +57 -0
- package/dist/runtime/diagnostic-env.d.ts +11 -0
- package/dist/runtime/diagnostic-env.js +35 -0
- package/dist/runtime/diagnostic-redactor.d.ts +49 -0
- package/dist/runtime/diagnostic-redactor.js +569 -0
- package/dist/runtime/egress-lease.d.ts +65 -0
- package/dist/runtime/egress-lease.js +236 -0
- package/dist/runtime/env.js +2 -1
- package/dist/runtime/http.js +1 -0
- package/dist/runtime/instrumentation.js +3 -0
- package/dist/runtime/ocr.js +2 -1
- package/dist/runtime/otlp.js +5 -4
- package/dist/runtime/proxy-nodemaven.js +3 -2
- package/dist/runtime/proxy-retry-policy.d.ts +4 -1
- package/dist/runtime/proxy-retry-policy.js +11 -2
- package/dist/runtime/request-options.d.ts +7 -0
- package/dist/runtime/request-options.js +62 -22
- package/dist/runtime/request-telemetry.d.ts +7 -9
- package/dist/runtime/resolver-config.d.ts +7 -0
- package/dist/runtime/resolver-config.js +8 -0
- package/dist/runtime/resolver-public.d.ts +3 -1
- package/dist/runtime/resolver-public.js +1 -1
- package/dist/runtime/resolver-shared.d.ts +9 -0
- package/dist/runtime/resolver-shared.js +57 -0
- package/dist/runtime/resolver-telemetry.d.ts +134 -0
- package/dist/runtime/resolver-telemetry.js +204 -0
- package/dist/runtime/resolver-usage.d.ts +24 -0
- package/dist/runtime/resolver-usage.js +60 -0
- package/dist/runtime/resolver-vendors/bindings.d.ts +5 -0
- package/dist/runtime/resolver-vendors/bindings.js +5 -0
- package/dist/runtime/resolver-vendors/browser.js +0 -1
- package/dist/runtime/resolver-vendors/capsolver.d.ts +2 -2
- package/dist/runtime/resolver-vendors/capsolver.js +21 -9
- package/dist/runtime/resolver-vendors/hypersolutions.d.ts +27 -0
- package/dist/runtime/resolver-vendors/hypersolutions.js +369 -0
- package/dist/runtime/resolver-vendors/twocaptcha.d.ts +2 -2
- package/dist/runtime/resolver-vendors/twocaptcha.js +26 -10
- package/dist/runtime/resolver-vendors/types.d.ts +35 -5
- package/dist/runtime/resolver-vendors/types.js +20 -10
- package/dist/runtime/resolver.d.ts +5 -1
- package/dist/runtime/resolver.js +400 -111
- package/dist/runtime/stealth-akamai-sbsd.d.ts +54 -0
- package/dist/runtime/stealth-akamai-sbsd.js +142 -0
- package/dist/runtime/stealth.js +547 -53
- package/dist/runtime/stt.js +3 -2
- package/dist/runtime/trace.d.ts +5 -0
- package/dist/runtime/trace.js +115 -20
- package/dist/schema.d.ts +20 -0
- package/dist/schema.js +72 -2
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/server/self-test-redaction.js +8 -33
- package/dist/server/self-test.d.ts +4 -0
- package/dist/server/self-test.js +10 -1
- package/dist/server/sensitive-values.d.ts +26 -0
- package/dist/server/sensitive-values.js +131 -0
- package/dist/server/serve-implementation.d.ts +7 -1
- package/dist/server/serve-implementation.js +394 -125
- package/dist/server/trace-output.d.ts +2 -1
- package/dist/server/trace-output.js +46 -14
- package/dist/server/types.d.ts +6 -0
- package/dist/server/types.js +14 -0
- package/dist/stealth/profiles.d.ts +7 -1
- package/dist/stealth/profiles.js +9 -0
- package/dist/testing/run.js +6 -0
- package/dist/trace-sanitization.d.ts +4 -3
- package/dist/trace-sanitization.js +45 -22
- package/dist/types.d.ts +106 -10
- package/package.json +2 -1
- package/src/cli/templates/provider/README.md.tpl +15 -3
- package/src/config/loader.ts +47 -18
- package/src/declaration-validation.ts +47 -1
- package/src/define.ts +45 -3
- package/src/engine.ts +78 -3
- package/src/error-resolution.ts +13 -0
- package/src/index.ts +34 -1
- package/src/lint.ts +44 -18
- package/src/provider.ts +10 -0
- package/src/runtime/bounded-expiring-map.ts +67 -0
- package/src/runtime/browser.ts +2 -1
- package/src/runtime/cache.ts +13 -3
- package/src/runtime/diagnostic-env-values.ts +56 -0
- package/src/runtime/diagnostic-env.ts +55 -0
- package/src/runtime/diagnostic-redactor.ts +662 -0
- package/src/runtime/egress-lease.ts +341 -0
- package/src/runtime/env.ts +2 -1
- package/src/runtime/http.ts +1 -0
- package/src/runtime/instrumentation.ts +3 -0
- package/src/runtime/ocr.ts +2 -1
- package/src/runtime/otlp.ts +5 -4
- package/src/runtime/proxy-nodemaven.ts +3 -2
- package/src/runtime/proxy-retry-policy.ts +12 -1
- package/src/runtime/request-options.ts +76 -28
- package/src/runtime/request-telemetry.ts +5 -7
- package/src/runtime/resolver-config.ts +12 -0
- package/src/runtime/resolver-public.ts +21 -0
- package/src/runtime/resolver-shared.ts +75 -0
- package/src/runtime/resolver-telemetry.ts +362 -0
- package/src/runtime/resolver-usage.ts +96 -0
- package/src/runtime/resolver-vendors/bindings.ts +5 -0
- package/src/runtime/resolver-vendors/browser.ts +0 -1
- package/src/runtime/resolver-vendors/capsolver.ts +22 -3
- package/src/runtime/resolver-vendors/hypersolutions.ts +480 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +26 -12
- package/src/runtime/resolver-vendors/types.ts +60 -12
- package/src/runtime/resolver.ts +468 -126
- package/src/runtime/stealth-akamai-sbsd.ts +207 -0
- package/src/runtime/stealth.ts +727 -95
- package/src/runtime/stt.ts +3 -2
- package/src/runtime/trace.ts +168 -26
- package/src/schema.ts +80 -2
- package/src/server/index.ts +21 -0
- package/src/server/self-test-redaction.ts +10 -40
- package/src/server/self-test.ts +13 -0
- package/src/server/sensitive-values.ts +200 -0
- package/src/server/serve-implementation.ts +561 -136
- package/src/server/trace-output.ts +77 -17
- package/src/server/types.ts +14 -0
- package/src/stealth/profiles.ts +10 -0
- package/src/testing/run.ts +6 -0
- package/src/trace-sanitization.ts +70 -23
- package/src/types.ts +124 -19
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolvedStringVariants,
|
|
3
|
+
urlCredentialComponents,
|
|
4
|
+
otlpHeaderCredentialValues,
|
|
5
|
+
} from "../runtime/diagnostic-env-values.js";
|
|
6
|
+
import {
|
|
7
|
+
PROVIDER_CACHE_REDIS_URL_ENV,
|
|
8
|
+
PROVIDER_STATE_REDIS_URL_ENV,
|
|
9
|
+
REDIS_URL_ENV,
|
|
10
|
+
} from "../config/loader.js";
|
|
11
|
+
import {
|
|
12
|
+
ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES,
|
|
13
|
+
ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES,
|
|
14
|
+
} from "../engine.js";
|
|
15
|
+
import { APIFUSE__CACHE__KEY_PEPPER_ENV } from "../runtime/cache.js";
|
|
16
|
+
import { PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV } from "../runtime/choice.js";
|
|
17
|
+
import { APIFUSE__ENGINE__CEREMONY_LEASE_KEY } from "../runtime/egress-lease.js";
|
|
18
|
+
import {
|
|
19
|
+
APIFUSE__OCR__API_KEY_ENV,
|
|
20
|
+
APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV,
|
|
21
|
+
} from "../runtime/ocr.js";
|
|
22
|
+
import {
|
|
23
|
+
OTEL_EXPORTER_OTLP_HEADERS,
|
|
24
|
+
OTEL_EXPORTER_OTLP_TRACES_HEADERS,
|
|
25
|
+
OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
26
|
+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
|
|
27
|
+
} from "../runtime/otlp.js";
|
|
28
|
+
import { APIFUSE__CDP_POOL__URL } from "../runtime/resolver-config.js";
|
|
29
|
+
import { APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV } from "../runtime/stt.js";
|
|
30
|
+
import type { ProviderDefinition } from "../types.js";
|
|
31
|
+
import {
|
|
32
|
+
PROVIDER_RUNTIME_SELF_TEST_MASTER_SECRET_ENV,
|
|
33
|
+
PROVIDER_RUNTIME_SELF_TEST_MASTER_SECRET_PREVIOUS_ENV,
|
|
34
|
+
} from "./self-test-token.js";
|
|
35
|
+
|
|
36
|
+
export const SELF_TEST_SENSITIVE_SOURCE_KINDS = [
|
|
37
|
+
"selfTestMasterSecrets",
|
|
38
|
+
"providerSecrets",
|
|
39
|
+
"healthProbeSecrets",
|
|
40
|
+
"requestCredentials",
|
|
41
|
+
] as const;
|
|
42
|
+
|
|
43
|
+
/** Explicit source allowlist: no environment-name or payload-shape secret sweep. */
|
|
44
|
+
export const DIAGNOSTIC_SENSITIVE_SOURCE_KINDS = [
|
|
45
|
+
...SELF_TEST_SENSITIVE_SOURCE_KINDS,
|
|
46
|
+
"engineProxyCredentials",
|
|
47
|
+
"engineSolverKeys",
|
|
48
|
+
"engineCeremonyLeaseCredentials",
|
|
49
|
+
"choiceMasterSecret",
|
|
50
|
+
"ocrCredentials",
|
|
51
|
+
"sttCredentials",
|
|
52
|
+
"cdpCredentials",
|
|
53
|
+
"statefulForwardingSecret",
|
|
54
|
+
"redisCredentials",
|
|
55
|
+
"otlpHeaders",
|
|
56
|
+
"cacheKeyPepper",
|
|
57
|
+
"sensitiveParams",
|
|
58
|
+
] as const;
|
|
59
|
+
export type DiagnosticSensitiveSourceKind = (typeof DIAGNOSTIC_SENSITIVE_SOURCE_KINDS)[number];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Startup inventory; request-scoped readers additionally register live values on access.
|
|
63
|
+
*/
|
|
64
|
+
export function collectStaticDiagnosticSensitiveValues(
|
|
65
|
+
provider: ProviderDefinition,
|
|
66
|
+
options: {
|
|
67
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
68
|
+
statefulForwardingSecret?: string;
|
|
69
|
+
} = {},
|
|
70
|
+
): string[] {
|
|
71
|
+
return collectDiagnosticSensitiveValues(provider, {
|
|
72
|
+
...options,
|
|
73
|
+
sourceKinds: DIAGNOSTIC_SENSITIVE_SOURCE_KINDS.filter(
|
|
74
|
+
(kind) => kind !== "requestCredentials" && kind !== "sensitiveParams",
|
|
75
|
+
),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Generalised self-test collector, also used to seed and enrich ordinary request scopes. */
|
|
80
|
+
export function collectDiagnosticSensitiveValues(
|
|
81
|
+
provider: ProviderDefinition,
|
|
82
|
+
options: {
|
|
83
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
84
|
+
credentialInputs?: Readonly<Record<string, unknown>>;
|
|
85
|
+
connectionSecrets?: Readonly<Record<string, string | undefined>>;
|
|
86
|
+
sensitiveParams?: readonly string[];
|
|
87
|
+
statefulForwardingSecret?: string;
|
|
88
|
+
sourceKinds?: readonly DiagnosticSensitiveSourceKind[];
|
|
89
|
+
minimumLength?: number;
|
|
90
|
+
/** Preserve the legacy self-test response collector when false. */
|
|
91
|
+
includeResolvedEnvVariants?: boolean;
|
|
92
|
+
} = {},
|
|
93
|
+
): string[] {
|
|
94
|
+
const env = options.env ?? process.env;
|
|
95
|
+
const envValues = (names: readonly string[]) => names.map((name) => env[name]);
|
|
96
|
+
const resolvedEnvValues = (names: readonly string[]) =>
|
|
97
|
+
envValues(names).flatMap((value) =>
|
|
98
|
+
value === undefined
|
|
99
|
+
? []
|
|
100
|
+
: options.includeResolvedEnvVariants === false
|
|
101
|
+
? [value]
|
|
102
|
+
: [value, value.trim()],
|
|
103
|
+
);
|
|
104
|
+
const healthProbe = provider.healthProbe ?? provider.healthMonitor;
|
|
105
|
+
const sources: Record<DiagnosticSensitiveSourceKind, () => readonly unknown[]> = {
|
|
106
|
+
selfTestMasterSecrets: () =>
|
|
107
|
+
resolvedEnvValues([
|
|
108
|
+
PROVIDER_RUNTIME_SELF_TEST_MASTER_SECRET_ENV,
|
|
109
|
+
PROVIDER_RUNTIME_SELF_TEST_MASTER_SECRET_PREVIOUS_ENV,
|
|
110
|
+
]),
|
|
111
|
+
providerSecrets: () => resolvedEnvValues((provider.secrets ?? []).map((secret) => secret.name)),
|
|
112
|
+
healthProbeSecrets: () =>
|
|
113
|
+
resolvedEnvValues([
|
|
114
|
+
...(healthProbe?.requiredSecrets ?? []),
|
|
115
|
+
...Object.values(healthProbe?.credentialInputs ?? {}),
|
|
116
|
+
]),
|
|
117
|
+
requestCredentials: () => [
|
|
118
|
+
...Object.values(options.credentialInputs ?? {}),
|
|
119
|
+
...Object.values(options.connectionSecrets ?? {}),
|
|
120
|
+
],
|
|
121
|
+
engineProxyCredentials: () => resolvedEnvValues(ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES),
|
|
122
|
+
// These are the resolver-config API keys after #251's engine credential projection.
|
|
123
|
+
engineSolverKeys: () => resolvedEnvValues(ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES),
|
|
124
|
+
engineCeremonyLeaseCredentials: () => resolvedEnvValues([APIFUSE__ENGINE__CEREMONY_LEASE_KEY]),
|
|
125
|
+
choiceMasterSecret: () => resolvedEnvValues([PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV]),
|
|
126
|
+
ocrCredentials: () =>
|
|
127
|
+
resolvedEnvValues([APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__OCR__API_KEY_ENV]),
|
|
128
|
+
sttCredentials: () => resolvedEnvValues([APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV]),
|
|
129
|
+
cdpCredentials: () =>
|
|
130
|
+
resolvedStringVariants(env[APIFUSE__CDP_POOL__URL]).flatMap((url) => [
|
|
131
|
+
url,
|
|
132
|
+
...urlCredentialComponents(url, { includePathAndQuery: true }),
|
|
133
|
+
]),
|
|
134
|
+
statefulForwardingSecret: () => resolvedStringVariants(options.statefulForwardingSecret),
|
|
135
|
+
redisCredentials: () =>
|
|
136
|
+
[PROVIDER_CACHE_REDIS_URL_ENV, PROVIDER_STATE_REDIS_URL_ENV, REDIS_URL_ENV]
|
|
137
|
+
.flatMap((name) => resolvedStringVariants(env[name]))
|
|
138
|
+
.flatMap((url) => urlCredentialComponents(url, { includePathAndQuery: false })),
|
|
139
|
+
otlpHeaders: () => [
|
|
140
|
+
...[OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_HEADERS].flatMap((name) =>
|
|
141
|
+
env[name] === undefined ? [] : otlpHeaderCredentialValues(env[name]),
|
|
142
|
+
),
|
|
143
|
+
...[OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT].flatMap((name) =>
|
|
144
|
+
resolvedStringVariants(env[name]).flatMap((url) =>
|
|
145
|
+
urlCredentialComponents(url, { includePathAndQuery: false }),
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
],
|
|
149
|
+
cacheKeyPepper: () => resolvedEnvValues([APIFUSE__CACHE__KEY_PEPPER_ENV]),
|
|
150
|
+
sensitiveParams: () => options.sensitiveParams ?? [],
|
|
151
|
+
};
|
|
152
|
+
const values = new Set<string>();
|
|
153
|
+
for (const kind of options.sourceKinds ?? DIAGNOSTIC_SENSITIVE_SOURCE_KINDS) {
|
|
154
|
+
for (const value of sources[kind]()) {
|
|
155
|
+
if (typeof value === "string" && value.length >= (options.minimumLength ?? 1))
|
|
156
|
+
values.add(value);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return [...values];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const diagnosticEnvNames = new WeakMap<ProviderDefinition, Set<string>>();
|
|
163
|
+
|
|
164
|
+
/** Derive the live-read allowlist from the same collector as the startup inventory. */
|
|
165
|
+
export function createDiagnosticEnvObserver(
|
|
166
|
+
provider: ProviderDefinition,
|
|
167
|
+
register: (values: readonly string[]) => void,
|
|
168
|
+
has?: (value: string) => boolean,
|
|
169
|
+
): (name: string, value: string) => void {
|
|
170
|
+
let names = diagnosticEnvNames.get(provider);
|
|
171
|
+
if (!names) {
|
|
172
|
+
names = new Set<string>();
|
|
173
|
+
const captured = names;
|
|
174
|
+
collectStaticDiagnosticSensitiveValues(provider, {
|
|
175
|
+
env: new Proxy(
|
|
176
|
+
{},
|
|
177
|
+
{
|
|
178
|
+
get: (_target, key) => {
|
|
179
|
+
if (typeof key === "string") captured.add(key);
|
|
180
|
+
return undefined;
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
diagnosticEnvNames.set(provider, names);
|
|
186
|
+
}
|
|
187
|
+
const seen = new Map<string, string>();
|
|
188
|
+
return (name, value) => {
|
|
189
|
+
if (!names.has(name) || seen.get(name) === value) return;
|
|
190
|
+
if (has?.(value) && has(value.trim())) return;
|
|
191
|
+
// Includes URL userinfo/CDP components and OTLP auth values, using the same rules.
|
|
192
|
+
register([
|
|
193
|
+
...resolvedStringVariants(value),
|
|
194
|
+
...collectStaticDiagnosticSensitiveValues(provider, {
|
|
195
|
+
env: { [name]: value },
|
|
196
|
+
}),
|
|
197
|
+
]);
|
|
198
|
+
seen.set(name, value);
|
|
199
|
+
};
|
|
200
|
+
}
|