@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.51
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 +537 -33
- package/CHANGELOG.md +205 -1
- package/README.md +83 -22
- package/SUBMISSION.md +2 -2
- package/bin/apifuse-check.ts +165 -11
- package/bin/apifuse-dev.ts +57 -13
- package/bin/apifuse-migrate-operation-declaration.ts +55 -0
- package/bin/apifuse-migrate-shape.ts +202 -0
- package/bin/apifuse-pack-check.ts +22 -2
- package/bin/apifuse-pack-smoke.ts +57 -2
- package/bin/apifuse-pack-types.ts +357 -38
- package/bin/apifuse-perf.ts +14 -13
- package/bin/apifuse-record.ts +709 -72
- package/bin/apifuse-submit-check.ts +2344 -324
- package/bin/apifuse-sync-assets.ts +117 -0
- package/bin/submit-check-delimited-text.ts +50 -0
- package/dist/auth-turn/index.d.ts +3 -3
- package/dist/auth-turn/index.js +1 -1
- package/dist/auth.d.ts +14 -0
- package/dist/auth.js +67 -0
- package/dist/ceremonies/index.d.ts +16 -0
- package/dist/ceremonies/index.js +141 -36
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +27 -0
- package/dist/cli/create.d.ts +4 -1
- package/dist/cli/create.js +42 -37
- package/dist/cli/migrate-operation-declaration.d.ts +59 -0
- package/dist/cli/migrate-operation-declaration.js +1249 -0
- package/dist/cli/migrate-operation-shape.d.ts +44 -0
- package/dist/cli/migrate-operation-shape.js +113 -0
- package/dist/cli/migrate-provider-shape.d.ts +52 -0
- package/dist/cli/migrate-provider-shape.js +578 -0
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
- package/dist/cli/templates/provider/README.md.tpl +5 -5
- package/dist/cli/templates/provider/index.ts.tpl +6 -3
- package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
- package/dist/cli/templates/provider/provider.json.tpl +6 -0
- package/dist/config/loader.d.ts +179 -16
- package/dist/config/loader.js +435 -127
- package/dist/contract-serialization.js +4 -8
- package/dist/contract-types.d.ts +12 -5
- package/dist/contract.js +24 -10
- package/dist/declaration-validation.d.ts +33 -0
- package/dist/declaration-validation.js +266 -0
- package/dist/define.d.ts +66 -29
- package/dist/define.js +778 -69
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +1 -1
- package/dist/engine.d.ts +78 -0
- package/dist/engine.js +133 -0
- package/dist/error-observability.d.ts +7 -0
- package/dist/error-observability.js +61 -0
- package/dist/error-resolution.d.ts +4 -0
- package/dist/error-resolution.js +122 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +40 -0
- package/dist/fixture-sanitization.d.ts +28 -0
- package/dist/fixture-sanitization.js +227 -0
- package/dist/health-scenario.d.ts +1842 -0
- package/dist/health-scenario.js +624 -0
- package/dist/index.d.ts +21 -10
- package/dist/index.js +12 -7
- package/dist/lint.d.ts +23 -11
- package/dist/lint.js +572 -69
- package/dist/native-address.d.ts +43 -0
- package/dist/native-address.js +281 -0
- package/dist/native-egress-policy.d.ts +31 -0
- package/dist/native-egress-policy.js +288 -0
- package/dist/observability.d.ts +5 -2
- package/dist/observability.js +48 -1
- package/dist/provider.d.ts +10 -2
- package/dist/provider.js +4 -1
- package/dist/runtime/auth-flow.d.ts +5 -1
- package/dist/runtime/auth-flow.js +6 -0
- package/dist/runtime/browser.d.ts +1 -0
- package/dist/runtime/browser.js +492 -49
- package/dist/runtime/cache.d.ts +1 -0
- package/dist/runtime/cache.js +169 -15
- package/dist/runtime/choice-wordlist.d.ts +9 -0
- package/dist/runtime/choice-wordlist.js +138 -0
- package/dist/runtime/choice.d.ts +13 -1
- package/dist/runtime/choice.js +490 -102
- package/dist/runtime/chrome149-header-order.d.ts +58 -0
- package/dist/runtime/chrome149-header-order.js +289 -0
- package/dist/runtime/env.js +12 -0
- package/dist/runtime/executor.d.ts +3 -2
- package/dist/runtime/executor.js +26 -25
- package/dist/runtime/http.d.ts +1 -0
- package/dist/runtime/http.js +515 -53
- package/dist/runtime/insights.js +2 -2
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +366 -8
- package/dist/runtime/native-network-errors.d.ts +33 -0
- package/dist/runtime/native-network-errors.js +69 -0
- package/dist/runtime/native-network.d.ts +96 -0
- package/dist/runtime/native-network.js +1232 -0
- package/dist/runtime/ocr.d.ts +29 -0
- package/dist/runtime/ocr.js +440 -0
- package/dist/runtime/otlp.d.ts +71 -2
- package/dist/runtime/otlp.js +397 -16
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +146 -0
- package/dist/runtime/proxy-telemetry.d.ts +80 -1
- package/dist/runtime/proxy-telemetry.js +154 -47
- package/dist/runtime/redirects.d.ts +29 -0
- package/dist/runtime/redirects.js +36 -0
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +4 -2
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/resolver-config.d.ts +6 -0
- package/dist/runtime/resolver-config.js +6 -0
- package/dist/runtime/resolver-public.d.ts +1 -0
- package/dist/runtime/resolver-public.js +1 -0
- package/dist/runtime/resolver-shared.d.ts +14 -0
- package/dist/runtime/resolver-shared.js +12 -0
- package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
- package/dist/runtime/resolver-vendors/bindings.js +40 -0
- package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
- package/dist/runtime/resolver-vendors/browser.js +377 -0
- package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
- package/dist/runtime/resolver-vendors/capsolver.js +531 -0
- 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 +24 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
- package/dist/runtime/resolver-vendors/types.d.ts +94 -0
- package/dist/runtime/resolver-vendors/types.js +96 -0
- package/dist/runtime/resolver.d.ts +72 -0
- package/dist/runtime/resolver.js +771 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +277 -71
- package/dist/runtime/stealth-cookies.d.ts +20 -0
- package/dist/runtime/stealth-cookies.js +111 -0
- package/dist/runtime/stealth.d.ts +41 -5
- package/dist/runtime/stealth.js +997 -291
- package/dist/runtime/stt.js +1 -12
- package/dist/runtime/timeout.d.ts +5 -0
- package/dist/runtime/timeout.js +12 -0
- package/dist/runtime/trace-config.d.ts +12 -0
- package/dist/runtime/trace-config.js +62 -0
- package/dist/runtime/trace.d.ts +5 -0
- package/dist/runtime/trace.js +43 -10
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/error-observability.d.ts +1 -0
- package/dist/server/error-observability.js +1 -0
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.js +2 -2
- package/dist/server/self-test-input-tokens.d.ts +2 -1
- package/dist/server/self-test-input-tokens.js +18 -14
- package/dist/server/self-test.d.ts +14 -3
- package/dist/server/self-test.js +129 -58
- package/dist/server/serve-implementation.d.ts +230 -0
- package/dist/server/serve-implementation.js +2265 -0
- package/dist/server/serve.d.ts +1 -70
- package/dist/server/serve.js +1 -1131
- package/dist/server/trace-output.d.ts +6 -0
- package/dist/server/trace-output.js +79 -0
- package/dist/server/types.d.ts +30 -5
- package/dist/server/types.js +13 -1
- package/dist/stateful/errors.d.ts +19 -0
- package/dist/stateful/errors.js +24 -0
- package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
- package/dist/stateful/http-provider-event-emitter.js +237 -0
- package/dist/stateful/http-session-owner-registry.d.ts +44 -0
- package/dist/stateful/http-session-owner-registry.js +210 -0
- package/dist/stateful/index.d.ts +18 -0
- package/dist/stateful/index.js +18 -0
- package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
- package/dist/stateful/provider-event-delivery-failures.js +43 -0
- package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
- package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
- package/dist/stateful/provider-event-pipeline.d.ts +50 -0
- package/dist/stateful/provider-event-pipeline.js +1 -0
- package/dist/stateful/provider-events.d.ts +101 -0
- package/dist/stateful/provider-events.js +289 -0
- package/dist/stateful/session-key.d.ts +15 -0
- package/dist/stateful/session-key.js +86 -0
- package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
- package/dist/stateful/stateful-provider-adapter-context.js +42 -0
- package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
- package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
- package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
- package/dist/stateful/stateful-provider-adapter.js +287 -0
- package/dist/stateful/stateful-provider-observability.d.ts +62 -0
- package/dist/stateful/stateful-provider-observability.js +161 -0
- package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
- package/dist/stateful/stateful-provider-runtime-context.js +60 -0
- package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
- package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
- package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
- package/dist/stateful/stateful-provider-session-routing.js +345 -0
- package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
- package/dist/stateful/stateful-provider-session-runtime.js +245 -0
- package/dist/stateful-signing.d.ts +18 -0
- package/dist/stateful-signing.js +27 -0
- package/dist/stealth/profiles.d.ts +9 -4
- package/dist/stealth/profiles.js +160 -211
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.js +7 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +489 -21
- package/dist/trace-sanitization.d.ts +5 -0
- package/dist/trace-sanitization.js +45 -0
- package/dist/types.d.ts +673 -131
- package/dist/types.js +1 -0
- package/package.json +45 -5
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +118 -0
- package/src/ceremonies/index.ts +189 -46
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +15 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +9 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +24 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
- package/src/cli/commands.ts +33 -0
- package/src/cli/create.ts +50 -37
- package/src/cli/migrate-operation-declaration.ts +1751 -0
- package/src/cli/migrate-operation-shape.ts +184 -0
- package/src/cli/migrate-provider-shape.ts +772 -0
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/cli/templates/provider/Dockerfile.tpl +1 -1
- package/src/cli/templates/provider/README.md.tpl +5 -5
- package/src/cli/templates/provider/index.ts.tpl +6 -3
- package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
- package/src/cli/templates/provider/provider.json.tpl +6 -0
- package/src/config/loader.ts +690 -163
- package/src/contract-serialization.ts +5 -7
- package/src/contract-types.ts +12 -5
- package/src/contract.ts +24 -10
- package/src/declaration-validation.ts +330 -0
- package/src/define.ts +1048 -131
- package/src/dev.ts +4 -1
- package/src/engine.ts +279 -0
- package/src/error-observability.ts +64 -0
- package/src/error-resolution.ts +127 -0
- package/src/errors.ts +68 -0
- package/src/fixture-sanitization.ts +264 -0
- package/src/health-scenario.ts +875 -0
- package/src/index.ts +220 -13
- package/src/lint.ts +698 -90
- package/src/native-address.ts +340 -0
- package/src/native-egress-policy.ts +358 -0
- package/src/observability.ts +51 -1
- package/src/provider.ts +161 -3
- package/src/runtime/auth-flow.ts +12 -0
- package/src/runtime/browser.ts +661 -63
- package/src/runtime/cache.ts +189 -14
- package/src/runtime/choice-wordlist.ts +145 -0
- package/src/runtime/choice.ts +631 -120
- package/src/runtime/chrome149-header-order.ts +330 -0
- package/src/runtime/env.ts +13 -0
- package/src/runtime/executor.ts +43 -31
- package/src/runtime/http.ts +641 -61
- package/src/runtime/insights.ts +2 -2
- package/src/runtime/instrumentation.ts +520 -15
- package/src/runtime/native-network-errors.ts +99 -0
- package/src/runtime/native-network.ts +1605 -0
- package/src/runtime/ocr.ts +523 -0
- package/src/runtime/otlp.ts +467 -21
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +221 -0
- package/src/runtime/proxy-telemetry.ts +244 -75
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +7 -2
- package/src/runtime/request-options.ts +680 -1
- package/src/runtime/resolver-config.ts +6 -0
- package/src/runtime/resolver-public.ts +23 -0
- package/src/runtime/resolver-shared.ts +33 -0
- package/src/runtime/resolver-vendors/bindings.ts +56 -0
- package/src/runtime/resolver-vendors/browser.ts +533 -0
- package/src/runtime/resolver-vendors/capsolver.ts +707 -0
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
- package/src/runtime/resolver-vendors/types.ts +212 -0
- package/src/runtime/resolver.ts +1157 -0
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +394 -77
- package/src/runtime/stealth-cookies.ts +132 -0
- package/src/runtime/stealth.ts +1280 -336
- package/src/runtime/stt.ts +1 -19
- package/src/runtime/timeout.ts +18 -0
- package/src/runtime/trace-config.ts +78 -0
- package/src/runtime/trace.ts +57 -17
- package/src/serve.ts +6 -1
- package/src/server/error-observability.ts +1 -0
- package/src/server/index.ts +34 -2
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test.ts +191 -68
- package/src/server/serve-implementation.ts +3378 -0
- package/src/server/serve.ts +1 -1632
- package/src/server/trace-output.ts +129 -0
- package/src/server/types.ts +13 -1
- package/src/stateful/README.md +146 -0
- package/src/stateful/errors.ts +35 -0
- package/src/stateful/http-provider-event-emitter.ts +314 -0
- package/src/stateful/http-session-owner-registry.ts +306 -0
- package/src/stateful/index.ts +18 -0
- package/src/stateful/provider-event-delivery-failures.ts +80 -0
- package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
- package/src/stateful/provider-event-pipeline.ts +61 -0
- package/src/stateful/provider-events.ts +462 -0
- package/src/stateful/session-key.ts +111 -0
- package/src/stateful/stateful-provider-adapter-context.ts +59 -0
- package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
- package/src/stateful/stateful-provider-adapter.ts +562 -0
- package/src/stateful/stateful-provider-observability.ts +261 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
- package/src/stateful/stateful-provider-runtime-context.ts +92 -0
- package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
- package/src/stateful/stateful-provider-session-routing.ts +546 -0
- package/src/stateful/stateful-provider-session-runtime.ts +403 -0
- package/src/stateful-signing.ts +46 -0
- package/src/stealth/profiles.ts +202 -231
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +8 -1
- package/src/testing/index.ts +10 -1
- package/src/testing/run.ts +658 -15
- package/src/trace-sanitization.ts +63 -0
- package/src/types.ts +788 -174
- package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
- package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
- /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/bin/apifuse-dev.ts
CHANGED
|
@@ -2,21 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
|
-
import type { ProviderDefinition } from "../src/index.js";
|
|
6
5
|
import {
|
|
7
|
-
createBrowserClient,
|
|
8
6
|
createCredentialContext,
|
|
9
7
|
createEnvContext,
|
|
10
8
|
createHttpClient,
|
|
9
|
+
createInProcessProviderEngine,
|
|
10
|
+
createOcrClientFromEnv,
|
|
11
11
|
createProviderCache,
|
|
12
12
|
createProviderChoiceContext,
|
|
13
|
-
|
|
13
|
+
createProviderEnvironment,
|
|
14
|
+
createUnsupportedResolverClient,
|
|
14
15
|
createSttClientFromEnv,
|
|
15
16
|
PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV,
|
|
17
|
+
readEngineProxyCredentials,
|
|
18
|
+
type ProviderDefinition,
|
|
19
|
+
type ProviderEngineBindingCandidates,
|
|
16
20
|
ProviderError,
|
|
21
|
+
type ProviderProxyPolicy,
|
|
17
22
|
} from "../src/index.js";
|
|
23
|
+
import { createBrowserClient } from "../src/runtime/browser.js";
|
|
24
|
+
import { createResolverClientFromEnv } from "../src/runtime/resolver.js";
|
|
18
25
|
import { createMemoryProviderRuntimeState } from "../src/runtime/state.js";
|
|
26
|
+
import { createStealthClient } from "../src/runtime/stealth.js";
|
|
19
27
|
import { createTraceContext } from "../src/runtime/trace.js";
|
|
28
|
+
import { getStealthProfile } from "../src/stealth/profiles.js";
|
|
20
29
|
import type { BrowserClient, ProviderContext } from "../src/types.js";
|
|
21
30
|
|
|
22
31
|
const HELP_TEXT = `Usage: apifuse dev [path]
|
|
@@ -74,14 +83,20 @@ export async function main() {
|
|
|
74
83
|
export function createProviderContext(provider: ProviderDefinition): {
|
|
75
84
|
ctx: ProviderContext;
|
|
76
85
|
} {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
const providerEnvironment = createProviderEnvironment(
|
|
87
|
+
process.env,
|
|
88
|
+
provider.secrets?.map((secret) => secret.name) ?? [],
|
|
89
|
+
);
|
|
90
|
+
const providerEnv = { get: (key: string) => providerEnvironment[key] };
|
|
91
|
+
const engineEnv = createEnvContext([PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV]);
|
|
92
|
+
const engineCredentials = readEngineProxyCredentials();
|
|
81
93
|
const credential = createCredentialContext();
|
|
82
94
|
const state = createMemoryProviderRuntimeState();
|
|
83
|
-
const
|
|
84
|
-
|
|
95
|
+
const cache = createProviderCache({ providerId: provider.id });
|
|
96
|
+
const proxyPolicy = resolveNativeProxyPolicy(provider);
|
|
97
|
+
const stealthProfile = provider.stealth ? getStealthProfile(provider.stealth) : undefined;
|
|
98
|
+
const candidates: ProviderEngineBindingCandidates = {
|
|
99
|
+
env: providerEnv,
|
|
85
100
|
credential,
|
|
86
101
|
auth: createUnsupportedAuthStub(),
|
|
87
102
|
browser:
|
|
@@ -92,22 +107,51 @@ export function createProviderContext(provider: ProviderDefinition): {
|
|
|
92
107
|
})
|
|
93
108
|
: createUnsupportedBrowserStub(),
|
|
94
109
|
http: createHttpClient(),
|
|
95
|
-
cache
|
|
110
|
+
cache,
|
|
96
111
|
state,
|
|
97
112
|
trace: createTraceContext(),
|
|
98
|
-
stealth: createStealthClient("http://localhost"
|
|
113
|
+
stealth: createStealthClient("http://localhost", {
|
|
114
|
+
...(provider.stealth ? { stealth: provider.stealth } : {}),
|
|
115
|
+
}),
|
|
116
|
+
ocr: createOcrClientFromEnv(provider.ocr),
|
|
99
117
|
stt: createSttClientFromEnv(provider.stt),
|
|
118
|
+
resolver: provider.resolver
|
|
119
|
+
? createResolverClientFromEnv(provider.resolver, engineCredentials, {
|
|
120
|
+
allowedHosts: provider.allowedHosts,
|
|
121
|
+
cache,
|
|
122
|
+
...(proxyPolicy
|
|
123
|
+
? {
|
|
124
|
+
proxyIntent: {
|
|
125
|
+
mode: proxyPolicy.mode,
|
|
126
|
+
upstream: { proxy: provider.proxy },
|
|
127
|
+
...(stealthProfile ? { userAgent: stealthProfile.userAgent } : {}),
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
: {}),
|
|
131
|
+
})
|
|
132
|
+
: createUnsupportedResolverClient("Provider does not declare resolver capability"),
|
|
100
133
|
choice: createProviderChoiceContext({
|
|
101
134
|
providerId: provider.id,
|
|
102
|
-
env,
|
|
135
|
+
env: engineEnv,
|
|
103
136
|
credential,
|
|
104
137
|
state,
|
|
105
138
|
}),
|
|
106
139
|
};
|
|
140
|
+
const ctx = createInProcessProviderEngine().attach({
|
|
141
|
+
provider,
|
|
142
|
+
bindings: candidates,
|
|
143
|
+
}) as ProviderContext;
|
|
107
144
|
|
|
108
145
|
return { ctx };
|
|
109
146
|
}
|
|
110
147
|
|
|
148
|
+
function resolveNativeProxyPolicy(provider: ProviderDefinition): ProviderProxyPolicy | undefined {
|
|
149
|
+
if (typeof provider.proxy === "object") return provider.proxy;
|
|
150
|
+
if (provider.proxy === true) return { mode: "optional" };
|
|
151
|
+
if (provider.proxy === false) return { mode: "disabled" };
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
111
155
|
function normalizeArgs(argv: string[]): string[] {
|
|
112
156
|
return argv[0] === "dev" ? argv.slice(1) : argv;
|
|
113
157
|
}
|
|
@@ -216,7 +260,7 @@ function isProviderDefinition(value: unknown): value is ProviderDefinition {
|
|
|
216
260
|
return (
|
|
217
261
|
typeof value.id === "string" &&
|
|
218
262
|
typeof value.version === "string" &&
|
|
219
|
-
(value.runtime === "standard" || value.runtime === "browser") &&
|
|
263
|
+
(value.runtime === "standard" || value.runtime === "shared" || value.runtime === "browser") &&
|
|
220
264
|
typeof value.meta.displayName === "string" &&
|
|
221
265
|
typeof value.meta.category === "string"
|
|
222
266
|
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `apifuse migrate-operation-declaration [path] [--check] [--json]`
|
|
5
|
+
*
|
|
6
|
+
* Rewrites ADR-0009's legacy nested operation declarations to the flat
|
|
7
|
+
* authoring contract. The run is repository-atomic: any declaration the
|
|
8
|
+
* codemod cannot prove leaves every source file untouched and exits 2.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { resolve } from "node:path";
|
|
12
|
+
|
|
13
|
+
import { migrateOperationDeclarationRepository } from "../src/cli/migrate-operation-declaration.js";
|
|
14
|
+
|
|
15
|
+
export async function main(): Promise<number> {
|
|
16
|
+
const args = process.argv.slice(3);
|
|
17
|
+
const check = args.includes("--check");
|
|
18
|
+
const json = args.includes("--json");
|
|
19
|
+
const positional = args.filter((argument) => !argument.startsWith("--"));
|
|
20
|
+
const providerRoot = resolve(positional[0] ?? ".");
|
|
21
|
+
const result = migrateOperationDeclarationRepository(providerRoot, { check });
|
|
22
|
+
|
|
23
|
+
if (json) {
|
|
24
|
+
console.log(
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
schemaVersion: 1,
|
|
27
|
+
command: "migrate-operation-declaration",
|
|
28
|
+
...result,
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
} else if (result.status === "refused") {
|
|
32
|
+
console.error(
|
|
33
|
+
`migrate-operation-declaration: refused ${result.refusals.length} declaration(s); no files were written.`,
|
|
34
|
+
);
|
|
35
|
+
for (const item of result.refusals) {
|
|
36
|
+
console.error(` ${item.file} [${item.operationKey}] ${item.reason}: ${item.detail}`);
|
|
37
|
+
}
|
|
38
|
+
} else if (result.status === "unchanged") {
|
|
39
|
+
console.log("migrate-operation-declaration: already flat; nothing to do.");
|
|
40
|
+
} else {
|
|
41
|
+
const verb = result.status === "would-migrate" ? "would migrate" : "migrated";
|
|
42
|
+
const sidecar = result.sidecar === undefined ? "" : ` and ${result.sidecar}`;
|
|
43
|
+
console.log(
|
|
44
|
+
`migrate-operation-declaration: ${verb} ${result.operationCount} operation(s) across ${result.changedFiles.length} file(s)${sidecar}.`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const exitCode = result.status === "refused" ? 2 : 0;
|
|
49
|
+
process.exitCode = exitCode;
|
|
50
|
+
return exitCode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (import.meta.main) {
|
|
54
|
+
process.exit(await main());
|
|
55
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `apifuse migrate-shape [path] [--check] [--json]`
|
|
5
|
+
*
|
|
6
|
+
* Applies the provider authoring-shape migration for the phase-separated SDK
|
|
7
|
+
* (2.2.0-beta.37+) to a provider repository. Two coordinated transforms:
|
|
8
|
+
*
|
|
9
|
+
* 1. `index.ts`: single-phase `defineProvider({...operations})` becomes the
|
|
10
|
+
* two-phase declaration builder. The old shape default-exports a builder
|
|
11
|
+
* FUNCTION under the new SDK, so the module stops loading.
|
|
12
|
+
* 2. Every provider source file: legacy `defineOperation(config)` /
|
|
13
|
+
* `defineStreamOperation(config)` become the curried
|
|
14
|
+
* `defineOperation<ProviderContext>()(config)`. The legacy call returns
|
|
15
|
+
* the inner factory with the config swallowed, so every operation in the
|
|
16
|
+
* map turns into a function and finalizeProvider rejects the provider
|
|
17
|
+
* with a misleading health-check error.
|
|
18
|
+
*
|
|
19
|
+
* Both halves belong to the same SDK bump: this transform and the pin bump
|
|
20
|
+
* must land in one commit.
|
|
21
|
+
*
|
|
22
|
+
* Exit codes: 0 migrated or already migrated; 1 any skip (the transform
|
|
23
|
+
* refuses to guess) or a missing index.ts. `--check` reports without
|
|
24
|
+
* writing. A skip is a hard stop for fan-out callers — never pair a pin bump
|
|
25
|
+
* with a skipped migration.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
30
|
+
|
|
31
|
+
import { migrateOperationShape } from "../src/cli/migrate-operation-shape.js";
|
|
32
|
+
import { migrateProviderShape } from "../src/cli/migrate-provider-shape.js";
|
|
33
|
+
|
|
34
|
+
const SOURCE_SKIP_DIRECTORIES = new Set([
|
|
35
|
+
"node_modules",
|
|
36
|
+
"__tests__",
|
|
37
|
+
"__fixtures__",
|
|
38
|
+
".git",
|
|
39
|
+
"dist",
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
type FileOutcome = {
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly status: string;
|
|
45
|
+
readonly detail?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export async function main(): Promise<void> {
|
|
49
|
+
const args = process.argv.slice(3);
|
|
50
|
+
const check = args.includes("--check");
|
|
51
|
+
const json = args.includes("--json");
|
|
52
|
+
const positional = args.filter((argument) => !argument.startsWith("--"));
|
|
53
|
+
const providerRoot = resolve(positional[0] ?? ".");
|
|
54
|
+
const indexPath = resolve(providerRoot, "index.ts");
|
|
55
|
+
|
|
56
|
+
const report = (payload: Record<string, unknown>, humanText: string): void => {
|
|
57
|
+
if (json) {
|
|
58
|
+
console.log(
|
|
59
|
+
JSON.stringify({ schemaVersion: 2, providerRoot, ...payload }),
|
|
60
|
+
);
|
|
61
|
+
} else {
|
|
62
|
+
console.log(humanText);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (!existsSync(indexPath)) {
|
|
67
|
+
report(
|
|
68
|
+
{ status: "skipped", reason: "index.ts not found" },
|
|
69
|
+
`migrate-shape: ${indexPath} not found.`,
|
|
70
|
+
);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ── Pass 1: provider two-phase shape on index.ts
|
|
75
|
+
const indexSource = readFileSync(indexPath, "utf8");
|
|
76
|
+
const providerResult = migrateProviderShape(indexSource, indexPath);
|
|
77
|
+
|
|
78
|
+
if (providerResult.status === "skipped") {
|
|
79
|
+
report(
|
|
80
|
+
{ status: "skipped", stage: "provider-shape", reason: providerResult.reason },
|
|
81
|
+
`migrate-shape: skipped — ${providerResult.reason}\nThis provider needs a manual migration; do not bump its SDK pin without one.`,
|
|
82
|
+
);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── Pass 2: operation currying across the provider's source tree.
|
|
87
|
+
// The index.ts input for this pass is pass 1's OUTPUT, so a provider
|
|
88
|
+
// whose index both holds the declaration and defines operations gets
|
|
89
|
+
// both transforms in one write.
|
|
90
|
+
const indexAfterProvider = providerResult.code;
|
|
91
|
+
const outcomes: FileOutcome[] = [];
|
|
92
|
+
const pendingWrites = new Map<string, string>();
|
|
93
|
+
let operationRewrites = 0;
|
|
94
|
+
|
|
95
|
+
for (const sourcePath of collectSourceFiles(providerRoot)) {
|
|
96
|
+
const isIndex = sourcePath === indexPath;
|
|
97
|
+
const input = isIndex
|
|
98
|
+
? indexAfterProvider
|
|
99
|
+
: readFileSync(sourcePath, "utf8");
|
|
100
|
+
// Operation modules import the alias from the provider entry; the
|
|
101
|
+
// entry file declares it itself.
|
|
102
|
+
const contextSpecifier = isIndex
|
|
103
|
+
? "./index"
|
|
104
|
+
: relativeImportToIndex(sourcePath, providerRoot);
|
|
105
|
+
const result = migrateOperationShape(input, sourcePath, contextSpecifier);
|
|
106
|
+
|
|
107
|
+
if (result.status === "skipped") {
|
|
108
|
+
report(
|
|
109
|
+
{
|
|
110
|
+
status: "skipped",
|
|
111
|
+
stage: "operation-shape",
|
|
112
|
+
file: relative(providerRoot, sourcePath),
|
|
113
|
+
reason: result.reason,
|
|
114
|
+
},
|
|
115
|
+
`migrate-shape: skipped at ${relative(providerRoot, sourcePath)} — ${result.reason}\nThis provider needs a manual migration; do not bump its SDK pin without one.`,
|
|
116
|
+
);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
if (result.status === "migrated") {
|
|
120
|
+
operationRewrites += result.rewrites;
|
|
121
|
+
pendingWrites.set(sourcePath, result.code);
|
|
122
|
+
outcomes.push({
|
|
123
|
+
path: relative(providerRoot, sourcePath),
|
|
124
|
+
status: "curried",
|
|
125
|
+
detail: `${result.rewrites} call site(s)`,
|
|
126
|
+
});
|
|
127
|
+
} else if (isIndex && providerResult.status === "migrated") {
|
|
128
|
+
// Provider shape changed even though no operation calls did.
|
|
129
|
+
pendingWrites.set(sourcePath, result.code);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const providerChanged = providerResult.status === "migrated";
|
|
134
|
+
const anythingChanged = providerChanged || operationRewrites > 0;
|
|
135
|
+
|
|
136
|
+
if (!anythingChanged) {
|
|
137
|
+
report(
|
|
138
|
+
{ status: "unchanged" },
|
|
139
|
+
"migrate-shape: already migrated; nothing to do.",
|
|
140
|
+
);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (check) {
|
|
145
|
+
report(
|
|
146
|
+
{
|
|
147
|
+
status: "would-migrate",
|
|
148
|
+
providerShape: providerChanged ? providerResult.kind : "unchanged",
|
|
149
|
+
operationCallSites: operationRewrites,
|
|
150
|
+
files: outcomes,
|
|
151
|
+
},
|
|
152
|
+
`migrate-shape: would migrate (provider: ${providerChanged ? providerResult.kind : "unchanged"}, operation call sites: ${operationRewrites}). Run without --check to write.`,
|
|
153
|
+
);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const [path, code] of pendingWrites) {
|
|
158
|
+
writeFileSync(path, code, "utf8");
|
|
159
|
+
}
|
|
160
|
+
report(
|
|
161
|
+
{
|
|
162
|
+
status: "migrated",
|
|
163
|
+
providerShape: providerChanged ? providerResult.kind : "unchanged",
|
|
164
|
+
operationCallSites: operationRewrites,
|
|
165
|
+
files: outcomes,
|
|
166
|
+
},
|
|
167
|
+
`migrate-shape: migrated (provider: ${providerChanged ? providerResult.kind : "unchanged"}, operation call sites: ${operationRewrites} across ${pendingWrites.size} file(s)). Review the diff, then run \`apifuse check\` and \`bun test\`.`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Provider-authored .ts sources, excluding tests, fixtures, and build output. */
|
|
172
|
+
function collectSourceFiles(root: string): string[] {
|
|
173
|
+
const files: string[] = [];
|
|
174
|
+
const walk = (directory: string): void => {
|
|
175
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
176
|
+
if (entry.isDirectory()) {
|
|
177
|
+
if (SOURCE_SKIP_DIRECTORIES.has(entry.name)) continue;
|
|
178
|
+
walk(join(directory, entry.name));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!entry.name.endsWith(".ts")) continue;
|
|
182
|
+
if (entry.name.endsWith(".d.ts")) continue;
|
|
183
|
+
if (entry.name.endsWith(".test.ts")) continue;
|
|
184
|
+
files.push(join(directory, entry.name));
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
walk(root);
|
|
188
|
+
return files.sort();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** `operations/foo.ts` -> `../index`; `operations/a/b.ts` -> `../../index`. */
|
|
192
|
+
function relativeImportToIndex(sourcePath: string, providerRoot: string): string {
|
|
193
|
+
const fromDirectory = dirname(sourcePath);
|
|
194
|
+
let specifier = relative(fromDirectory, join(providerRoot, "index"));
|
|
195
|
+
specifier = specifier.split("\\").join("/");
|
|
196
|
+
if (!specifier.startsWith(".")) specifier = `./${specifier}`;
|
|
197
|
+
return specifier;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (import.meta.main) {
|
|
201
|
+
await main();
|
|
202
|
+
}
|
|
@@ -48,6 +48,13 @@ const requiredPaths = [
|
|
|
48
48
|
"src/cli/templates/provider/operations/ping.ts.tpl",
|
|
49
49
|
"src/cli/templates/provider/schemas/ping.ts.tpl",
|
|
50
50
|
"src/cli/templates/provider/upstream/README.md.tpl",
|
|
51
|
+
"src/cli/templates/provider/AGENTS.md.tpl",
|
|
52
|
+
"src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl",
|
|
53
|
+
"src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl",
|
|
54
|
+
"src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl",
|
|
55
|
+
"src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl",
|
|
56
|
+
"src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl",
|
|
57
|
+
"src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl",
|
|
51
58
|
"dist/cli/templates/provider/.dockerignore.tpl",
|
|
52
59
|
"dist/cli/templates/provider/.gitignore.tpl",
|
|
53
60
|
"dist/cli/templates/provider/Dockerfile.tpl",
|
|
@@ -60,6 +67,13 @@ const requiredPaths = [
|
|
|
60
67
|
"dist/cli/templates/provider/operations/ping.ts.tpl",
|
|
61
68
|
"dist/cli/templates/provider/schemas/ping.ts.tpl",
|
|
62
69
|
"dist/cli/templates/provider/upstream/README.md.tpl",
|
|
70
|
+
"dist/cli/templates/provider/AGENTS.md.tpl",
|
|
71
|
+
"dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl",
|
|
72
|
+
"dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl",
|
|
73
|
+
"dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl",
|
|
74
|
+
"dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl",
|
|
75
|
+
"dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl",
|
|
76
|
+
"dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl",
|
|
63
77
|
"dist/auth-turn/index.js",
|
|
64
78
|
"dist/auth-turn/index.d.ts",
|
|
65
79
|
"dist/auth-turn/auth-turn.v1.schema.json",
|
|
@@ -142,9 +156,9 @@ function assertPublicSmokeDocs(label: string, content: string): void {
|
|
|
142
156
|
);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
|
-
if (!content.includes("
|
|
159
|
+
if (!content.includes("wreq-js")) {
|
|
146
160
|
throw new Error(
|
|
147
|
-
`${label} must include
|
|
161
|
+
`${label} must include wreq-js stealth runtime guidance for TLS/browser bounties.`,
|
|
148
162
|
);
|
|
149
163
|
}
|
|
150
164
|
|
|
@@ -154,6 +168,12 @@ function assertPublicSmokeDocs(label: string, content: string): void {
|
|
|
154
168
|
);
|
|
155
169
|
}
|
|
156
170
|
|
|
171
|
+
if (!content.includes("Chrome, Firefox, and Safari")) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`${label} must document the browser families supported by the TypeScript stealth runtime.`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
157
177
|
if (
|
|
158
178
|
!content.includes('browser.engine: "playwright-stealth"') ||
|
|
159
179
|
!content.includes("nodriver")
|
|
@@ -59,6 +59,21 @@ try {
|
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
run("bun", ["install"], consumerDir);
|
|
62
|
+
run(
|
|
63
|
+
"bun",
|
|
64
|
+
[
|
|
65
|
+
"--eval",
|
|
66
|
+
[
|
|
67
|
+
'import { resolveProxy } from "@apifuse/provider-sdk";',
|
|
68
|
+
'if (typeof resolveProxy !== "function") throw new Error("resolveProxy is not exported");',
|
|
69
|
+
'const resolved = await resolveProxy({ proxy: "http://127.0.0.1:8080" });',
|
|
70
|
+
'if (resolved.url !== "http://127.0.0.1:8080") throw new Error("resolveProxy returned the wrong URL");',
|
|
71
|
+
'console.log("packed root resolveProxy export OK");',
|
|
72
|
+
].join("\n"),
|
|
73
|
+
],
|
|
74
|
+
consumerDir,
|
|
75
|
+
);
|
|
76
|
+
smokePackedStealthNative(consumerDir);
|
|
62
77
|
|
|
63
78
|
const cliBin = join(consumerDir, "node_modules", ".bin", "apifuse");
|
|
64
79
|
if (!existsSync(cliBin)) {
|
|
@@ -202,6 +217,43 @@ function run(command: string, args: string[], cwd: string): void {
|
|
|
202
217
|
}
|
|
203
218
|
}
|
|
204
219
|
|
|
220
|
+
function smokePackedStealthNative(consumerDir: string): void {
|
|
221
|
+
run(
|
|
222
|
+
"bun",
|
|
223
|
+
[
|
|
224
|
+
"--eval",
|
|
225
|
+
[
|
|
226
|
+
'import { createServer } from "node:http";',
|
|
227
|
+
'import { createStealthClient } from "@apifuse/provider-sdk/runtime/stealth";',
|
|
228
|
+
"const server = createServer((_request, response) => {",
|
|
229
|
+
' response.setHeader("set-cookie", "pack_native_cookie=landed; Path=/");',
|
|
230
|
+
' response.end("packed native stealth ok");',
|
|
231
|
+
"});",
|
|
232
|
+
"await new Promise((resolve, reject) => {",
|
|
233
|
+
' server.once("error", reject);',
|
|
234
|
+
' server.listen(0, "127.0.0.1", resolve);',
|
|
235
|
+
"});",
|
|
236
|
+
"const address = server.address();",
|
|
237
|
+
'if (!address || typeof address === "string") throw new Error("Local server has no TCP address");',
|
|
238
|
+
'const baseUrl = "http://127.0.0.1:" + address.port;',
|
|
239
|
+
'const session = createStealthClient(baseUrl).createSession({ stealth: { browser: "safari", os: "macos" } });',
|
|
240
|
+
"try {",
|
|
241
|
+
' const response = await session.fetch("/native");',
|
|
242
|
+
' if (response.body !== "packed native stealth ok") throw new Error("Unexpected stealth body: " + response.body);',
|
|
243
|
+
' if (session.cookies.get("pack_native_cookie", baseUrl + "/native") !== "landed") {',
|
|
244
|
+
' throw new Error("Packed stealth Set-Cookie did not land in the SDK jar");',
|
|
245
|
+
" }",
|
|
246
|
+
' console.log("packed native Safari stealth request OK");',
|
|
247
|
+
"} finally {",
|
|
248
|
+
" session.close();",
|
|
249
|
+
" await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));",
|
|
250
|
+
"}",
|
|
251
|
+
].join("\n"),
|
|
252
|
+
],
|
|
253
|
+
consumerDir,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
205
257
|
function assertGeneratedReadme(providerDir: string): void {
|
|
206
258
|
const readme = readFileSync(join(providerDir, "README.md"), "utf8");
|
|
207
259
|
if (!readme.includes('"requestId":"req_local_ping"')) {
|
|
@@ -213,8 +265,11 @@ function assertGeneratedReadme(providerDir: string): void {
|
|
|
213
265
|
if (!readme.includes("bunx playwright install chromium")) {
|
|
214
266
|
throw new Error("Generated README is missing browser runtime troubleshooting guidance.");
|
|
215
267
|
}
|
|
216
|
-
if (!readme.includes("
|
|
217
|
-
throw new Error("Generated README is missing
|
|
268
|
+
if (!readme.includes("wreq-js")) {
|
|
269
|
+
throw new Error("Generated README is missing wreq-js stealth runtime guidance.");
|
|
270
|
+
}
|
|
271
|
+
if (!readme.includes("Chrome, Firefox, and Safari")) {
|
|
272
|
+
throw new Error("Generated README is missing supported stealth browser families.");
|
|
218
273
|
}
|
|
219
274
|
if (!readme.includes("bun run submit-check")) {
|
|
220
275
|
throw new Error("Generated README must document the submit-check pre-submission workflow.");
|