@apifuse/provider-sdk 2.1.0-beta.0 → 2.1.0-beta.10
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 +218 -21
- package/CHANGELOG.md +54 -0
- package/README.md +147 -10
- package/SUBMISSION.md +87 -0
- package/bin/apifuse-check.ts +86 -4
- package/bin/apifuse-dev.ts +87 -13
- package/bin/apifuse-pack-check.ts +120 -0
- package/bin/apifuse-pack-smoke.ts +423 -0
- package/bin/apifuse-perf.ts +142 -49
- package/bin/apifuse-record.ts +182 -104
- package/bin/apifuse-submit-check.ts +2538 -0
- package/bin/apifuse.ts +1 -1
- package/dist/ceremonies/index.d.ts +41 -0
- package/dist/ceremonies/index.js +490 -0
- package/dist/choice-token.d.ts +24 -0
- package/dist/choice-token.js +74 -0
- package/dist/cli/commands.d.ts +10 -0
- package/dist/cli/commands.js +80 -0
- package/dist/cli/create.d.ts +47 -0
- package/dist/cli/create.js +762 -0
- package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
- package/dist/cli/templates/provider/.gitignore.tpl +22 -0
- package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
- package/dist/cli/templates/provider/README.md.tpl +160 -0
- package/dist/cli/templates/provider/dev.ts.tpl +5 -0
- package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
- package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
- package/dist/cli/templates/provider/index.ts.tpl +15 -0
- package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/dist/cli/templates/provider/meta.ts.tpl +7 -0
- package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/start.ts.tpl +5 -0
- package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/dist/config/loader.d.ts +107 -0
- package/dist/config/loader.js +935 -0
- package/dist/contract-json.d.ts +9 -0
- package/dist/contract-json.js +51 -0
- package/dist/contract-serialization.d.ts +4 -0
- package/dist/contract-serialization.js +78 -0
- package/dist/contract-types.d.ts +49 -0
- package/dist/contract-types.js +1 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +155 -0
- package/dist/define.d.ts +97 -0
- package/dist/define.js +1320 -0
- package/dist/dev.d.ts +9 -0
- package/dist/dev.js +15 -0
- package/dist/errors.d.ts +59 -0
- package/dist/errors.js +97 -0
- package/dist/i18n/catalog.d.ts +29 -0
- package/dist/i18n/catalog.js +159 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/keys.d.ts +10 -0
- package/dist/i18n/keys.js +34 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +37 -0
- package/dist/lint.d.ts +73 -0
- package/dist/lint.js +702 -0
- package/dist/observability.d.ts +5 -0
- package/dist/observability.js +39 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +8 -0
- package/dist/public-schema-field-lint.d.ts +2 -0
- package/dist/public-schema-field-lint.js +158 -0
- package/dist/recipes/gov-api.d.ts +19 -0
- package/dist/recipes/gov-api.js +72 -0
- package/dist/recipes/rest-api.d.ts +21 -0
- package/dist/recipes/rest-api.js +115 -0
- package/dist/runtime/auth-flow.d.ts +14 -0
- package/dist/runtime/auth-flow.js +44 -0
- package/dist/runtime/browser.d.ts +25 -0
- package/dist/runtime/browser.js +1034 -0
- package/dist/runtime/cache.d.ts +10 -0
- package/dist/runtime/cache.js +372 -0
- package/dist/runtime/choice.d.ts +15 -0
- package/dist/runtime/choice.js +435 -0
- package/dist/runtime/credential.d.ts +8 -0
- package/dist/runtime/credential.js +61 -0
- package/dist/runtime/env.d.ts +2 -0
- package/dist/runtime/env.js +10 -0
- package/dist/runtime/executor.d.ts +16 -0
- package/dist/runtime/executor.js +51 -0
- package/dist/runtime/http.d.ts +8 -0
- package/dist/runtime/http.js +706 -0
- package/dist/runtime/insights.d.ts +9 -0
- package/dist/runtime/insights.js +324 -0
- package/dist/runtime/instrumentation.d.ts +8 -0
- package/dist/runtime/instrumentation.js +269 -0
- package/dist/runtime/key-derivation.d.ts +24 -0
- package/dist/runtime/key-derivation.js +73 -0
- package/dist/runtime/keyring.d.ts +25 -0
- package/dist/runtime/keyring.js +93 -0
- package/dist/runtime/namespace.d.ts +9 -0
- package/dist/runtime/namespace.js +19 -0
- package/dist/runtime/otlp.d.ts +39 -0
- package/dist/runtime/otlp.js +103 -0
- package/dist/runtime/perf.d.ts +12 -0
- package/dist/runtime/perf.js +52 -0
- package/dist/runtime/prevalidate.d.ts +12 -0
- package/dist/runtime/prevalidate.js +173 -0
- package/dist/runtime/provider.d.ts +2 -0
- package/dist/runtime/provider.js +11 -0
- package/dist/runtime/proxy-errors.d.ts +21 -0
- package/dist/runtime/proxy-errors.js +83 -0
- package/dist/runtime/proxy-telemetry.d.ts +8 -0
- package/dist/runtime/proxy-telemetry.js +174 -0
- package/dist/runtime/redis.d.ts +17 -0
- package/dist/runtime/redis.js +82 -0
- package/dist/runtime/request-options.d.ts +3 -0
- package/dist/runtime/request-options.js +42 -0
- package/dist/runtime/state.d.ts +17 -0
- package/dist/runtime/state.js +344 -0
- package/dist/runtime/stealth.d.ts +18 -0
- package/dist/runtime/stealth.js +834 -0
- package/dist/runtime/stt.d.ts +22 -0
- package/dist/runtime/stt.js +480 -0
- package/dist/runtime/trace.d.ts +26 -0
- package/dist/runtime/trace.js +142 -0
- package/dist/runtime/waterfall.d.ts +12 -0
- package/dist/runtime/waterfall.js +147 -0
- package/dist/schema.d.ts +74 -0
- package/dist/schema.js +243 -0
- package/dist/serve.d.ts +1 -0
- package/dist/serve.js +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/serve.d.ts +64 -0
- package/dist/server/serve.js +1110 -0
- package/dist/server/types.d.ts +136 -0
- package/dist/server/types.js +86 -0
- package/dist/stealth/profiles.d.ts +4 -0
- package/dist/stealth/profiles.js +259 -0
- package/dist/stream.d.ts +44 -0
- package/dist/stream.js +151 -0
- package/dist/testing/helpers.d.ts +23 -0
- package/dist/testing/helpers.js +95 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/run.d.ts +34 -0
- package/dist/testing/run.js +303 -0
- package/dist/types.d.ts +1326 -0
- package/dist/types.js +61 -0
- package/dist/utils/date.d.ts +6 -0
- package/dist/utils/date.js +101 -0
- package/dist/utils/parse.d.ts +16 -0
- package/dist/utils/parse.js +51 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +14 -0
- package/dist/utils/transform.d.ts +8 -0
- package/dist/utils/transform.js +48 -0
- package/package.json +57 -29
- package/src/ceremonies/index.ts +30 -3
- package/src/choice-token.ts +165 -0
- package/src/cli/commands.ts +34 -11
- package/src/cli/create.ts +214 -52
- package/src/cli/templates/provider/.dockerignore.tpl +22 -0
- package/src/cli/templates/provider/.gitignore.tpl +22 -0
- package/src/cli/templates/provider/README.md.tpl +134 -2
- package/src/cli/templates/provider/dev.ts.tpl +1 -1
- package/src/cli/templates/provider/domain/README.md.tpl +3 -0
- package/src/cli/templates/provider/index.ts.tpl +5 -44
- package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/src/cli/templates/provider/meta.ts.tpl +7 -0
- package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/src/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/src/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/src/cli/templates/provider/start.ts.tpl +1 -1
- package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/src/config/loader.ts +1282 -7
- package/src/contract-json.ts +75 -0
- package/src/contract-serialization.ts +89 -0
- package/src/contract-types.ts +52 -0
- package/src/contract.ts +215 -0
- package/src/define.ts +1726 -48
- package/src/errors.ts +27 -0
- package/src/i18n/catalog.ts +277 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/keys.ts +64 -0
- package/src/index.ts +174 -15
- package/src/lint.ts +547 -73
- package/src/observability.ts +41 -0
- package/src/provider.ts +104 -5
- package/src/public-schema-field-lint.ts +237 -0
- package/src/runtime/auth-flow.ts +7 -0
- package/src/runtime/browser.ts +762 -51
- package/src/runtime/cache.ts +528 -0
- package/src/runtime/choice.ts +760 -0
- package/src/runtime/executor.ts +32 -3
- package/src/runtime/http.ts +945 -185
- package/src/runtime/insights.ts +11 -11
- package/src/runtime/instrumentation.ts +12 -4
- package/src/runtime/key-derivation.ts +1 -1
- package/src/runtime/keyring.ts +4 -3
- package/src/runtime/proxy-errors.ts +132 -0
- package/src/runtime/proxy-telemetry.ts +253 -0
- package/src/runtime/redis.ts +116 -0
- package/src/runtime/request-options.ts +66 -0
- package/src/runtime/state.ts +563 -0
- package/src/runtime/stealth.ts +1159 -0
- package/src/runtime/stt.ts +629 -0
- package/src/runtime/trace.ts +1 -1
- package/src/schema.ts +363 -1
- package/src/server/serve.ts +1172 -76
- package/src/server/types.ts +37 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +31 -5
- package/src/types.ts +1118 -44
- package/src/composite.ts +0 -43
- package/src/runtime/tls.ts +0 -425
- package/src/types/playwright-stealth.d.ts +0 -9
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
.git/
|
|
3
|
+
.github/
|
|
4
|
+
|
|
5
|
+
# Environment and local secrets
|
|
6
|
+
.env
|
|
7
|
+
.env.*
|
|
8
|
+
!.env.example
|
|
9
|
+
|
|
10
|
+
# Local reports and generated artifacts
|
|
11
|
+
submission-report.md
|
|
12
|
+
coverage/
|
|
13
|
+
dist/
|
|
14
|
+
.cache/
|
|
15
|
+
.turbo/
|
|
16
|
+
.bun/
|
|
17
|
+
*.tsbuildinfo
|
|
18
|
+
|
|
19
|
+
# OS/editor junk
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
*.swp
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
|
|
3
|
+
# Environment and local secrets
|
|
4
|
+
.env
|
|
5
|
+
.env.*
|
|
6
|
+
!.env.example
|
|
7
|
+
|
|
8
|
+
# Build, coverage, cache, and local runtime artifacts
|
|
9
|
+
coverage/
|
|
10
|
+
dist/
|
|
11
|
+
.cache/
|
|
12
|
+
.turbo/
|
|
13
|
+
.bun/
|
|
14
|
+
*.tsbuildinfo
|
|
15
|
+
|
|
16
|
+
# Bounty submission output
|
|
17
|
+
submission-report.md
|
|
18
|
+
|
|
19
|
+
# OS/editor junk
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
*.swp
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# {{DISPLAY_NAME}}
|
|
2
|
+
|
|
3
|
+
Generated with `apifuse create`.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun run dev
|
|
9
|
+
bun run check
|
|
10
|
+
bun run test
|
|
11
|
+
bun run submit-check
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Module layout
|
|
16
|
+
|
|
17
|
+
The generated provider uses the recommended split layout:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
index.ts # composition root: defineProvider() and wiring only
|
|
21
|
+
meta.ts # provider metadata
|
|
22
|
+
operations/ # APIFuse operation contracts and handlers
|
|
23
|
+
schemas/ # public input/output schemas near operations
|
|
24
|
+
upstream/ # upstream ceremony: clients, auth, request builders
|
|
25
|
+
mappers/ # upstream-to-APIFuse normalization helpers
|
|
26
|
+
domain/ # shared provider-specific business ceremony
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Small providers may stay in one file, but larger providers are easier to
|
|
30
|
+
review when `index.ts` remains a short composition root.
|
|
31
|
+
|
|
32
|
+
## Pre-submission report
|
|
33
|
+
|
|
34
|
+
Before posting bounty evidence, run:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun run submit-check
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This writes `submission-report.md` with a review-readiness score, blockers,
|
|
41
|
+
warnings, health coverage notes, fixture/schema evidence, and remediation. A
|
|
42
|
+
score is not a payout guarantee; blockers must be fixed before maintainer
|
|
43
|
+
review. The generated `ping` starter intentionally warns until you replace it
|
|
44
|
+
with real upstream-backed Operations. The full public-only checklist is shipped
|
|
45
|
+
in `node_modules/@apifuse/provider-sdk/SUBMISSION.md`.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Operation guide
|
|
49
|
+
|
|
50
|
+
### Parameters
|
|
51
|
+
|
|
52
|
+
Starter `ping` accepts `{ "value": string }`. Replace this section with each
|
|
53
|
+
real operation's input schema, required fields, formats, limits, and examples
|
|
54
|
+
before submitting bounty evidence.
|
|
55
|
+
|
|
56
|
+
### Response
|
|
57
|
+
|
|
58
|
+
Starter `ping` returns `{ "ok": boolean, "message": string }`. Replace this
|
|
59
|
+
section with the normalized response fields, units, enum values, pagination,
|
|
60
|
+
and upstream caveats for each real operation.
|
|
61
|
+
|
|
62
|
+
### Example
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"requestId": "req_local_ping",
|
|
67
|
+
"input": { "value": "hello" },
|
|
68
|
+
"headers": {}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Provider server contract
|
|
73
|
+
|
|
74
|
+
- Dev default: `3900`
|
|
75
|
+
- Start/Docker/container contract: `3000`
|
|
76
|
+
- `GET /health`
|
|
77
|
+
- `POST /v1/{operation}`
|
|
78
|
+
- `POST /auth/start`
|
|
79
|
+
- `POST /auth/continue`
|
|
80
|
+
- `POST /auth/poll`
|
|
81
|
+
- `POST /auth/disconnect`
|
|
82
|
+
|
|
83
|
+
## Local smoke
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -s http://localhost:3900/health
|
|
87
|
+
curl -s -X POST http://localhost:3900/v1/ping \
|
|
88
|
+
-H 'Content-Type: application/json' \
|
|
89
|
+
-d '{"requestId":"req_local_ping","input":{"value":"hello"},"headers":{}}'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `POST /v1/{operation}` body is a request envelope:
|
|
93
|
+
|
|
94
|
+
- `requestId` is required and can be any unique local debugging string.
|
|
95
|
+
- `input` contains the operation input shape.
|
|
96
|
+
- `headers` is optional.
|
|
97
|
+
- `connection` is optional; omit it for no-auth/public operations. For
|
|
98
|
+
credential debugging, pass `{ "id", "mode", "secrets", "metadata",
|
|
99
|
+
"externalRef" }` with local-only secret values.
|
|
100
|
+
|
|
101
|
+
Structured errors return an `error` object with `code`, `message`,
|
|
102
|
+
`requestId`, and optional `details`; validation failures include field paths in
|
|
103
|
+
`details`, and the `apifuse dev` terminal prints a structured provider log.
|
|
104
|
+
|
|
105
|
+
## Debugging checklist
|
|
106
|
+
|
|
107
|
+
- `invalid_request`: include `requestId` and `input`; omit `connection` for
|
|
108
|
+
public/no-auth operations and never send `connection: null`.
|
|
109
|
+
- Credentials: declare `credential.keys`, pass local-only values through
|
|
110
|
+
`connection.secrets`, and read them with `ctx.credential`.
|
|
111
|
+
- Auth flow: call `/auth/start`, then `/auth/continue` with the same `flowId`;
|
|
112
|
+
carry returned `contextPatch` values into the next request's `context`.
|
|
113
|
+
- Stealth/browser runtime: keep access-sensitive operations on `ctx.stealth.fetch()` with an
|
|
114
|
+
SDK stealth `profile`; the TypeScript stealth runtime uses `impit` internally.
|
|
115
|
+
`ctx.stealth` supports Chrome/Firefox-style profiles. For TypeScript browser
|
|
116
|
+
Providers or Safari-specific behavior use `browser.engine: "playwright-stealth"`
|
|
117
|
+
(`nodriver` is Python-runtime only), then install local Chromium with
|
|
118
|
+
`bunx playwright install chromium` or set `APIFUSE__CDP_POOL__URL`.
|
|
119
|
+
|
|
120
|
+
## Next steps
|
|
121
|
+
|
|
122
|
+
1. Replace the sample `ping` operation with real upstream logic.
|
|
123
|
+
2. Once the real operation declares `upstream.baseUrl` and uses `ctx.http` or
|
|
124
|
+
`ctx.stealth`, record a fixture with:
|
|
125
|
+
`bun run record -- --operation <operation> --params '<json-input>'`.
|
|
126
|
+
3. Replace the starter `healthCheckUnsupported` with a real `healthCheck` for read-only upstream operations when safe.
|
|
127
|
+
4. Extend tests and operation metadata until the provider is bounty-ready.
|
|
128
|
+
|
|
129
|
+
`apifuse record` is not expected to work with the generated local-only `ping`
|
|
130
|
+
operation because it intentionally has no upstream response to capture.
|
|
131
|
+
|
|
132
|
+
## Health-check authorship
|
|
133
|
+
|
|
134
|
+
Every operation must declare exactly one of:
|
|
135
|
+
|
|
136
|
+
- `healthCheck` — preferred for safe read-only upstream probes.
|
|
137
|
+
- `healthCheckUnsupported` — allowed only when a probe is destructive, paid,
|
|
138
|
+
credential-sensitive, flaky by design, or otherwise unsafe. Use a specific
|
|
139
|
+
reason; reviewers reject placeholder reasons such as "TODO" or "later".
|
|
140
|
+
|
|
141
|
+
The generated `ping` operation uses `healthCheckUnsupported` only because it is
|
|
142
|
+
a local scaffold check, not a real upstream API probe.
|
|
143
|
+
|
|
144
|
+
`healthCheck.cases[].assertions` receives `{ data, status, durationMs, meta }`.
|
|
145
|
+
`data` is the parsed operation output. Use this shape in real operations:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
healthCheck: {
|
|
149
|
+
interval: "5m",
|
|
150
|
+
cases: [{
|
|
151
|
+
name: "lookup baseline",
|
|
152
|
+
input: { q: "btc" },
|
|
153
|
+
assertions: ({ data, status, durationMs }) => {
|
|
154
|
+
if (status !== 200 || data.results.length === 0 || durationMs > 3000) {
|
|
155
|
+
return { status: "degraded", label: "lookup baseline changed" };
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
}],
|
|
159
|
+
}
|
|
160
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { runStandardTests } from "@apifuse/provider-sdk/testing";
|
|
3
|
+
|
|
4
|
+
import provider from "../index";
|
|
5
|
+
|
|
6
|
+
runStandardTests(provider);
|
|
7
|
+
|
|
8
|
+
describe("{{PROVIDER_ID}}", () => {
|
|
9
|
+
it("exposes provider metadata from defineProvider", () => {
|
|
10
|
+
expect(provider.id).toBe("{{PROVIDER_ID}}");
|
|
11
|
+
expect(provider.reviewed).toBe("community");
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineProvider } from "@apifuse/provider-sdk/provider";
|
|
2
|
+
|
|
3
|
+
import { providerMeta } from "./meta";
|
|
4
|
+
import { operations } from "./operations";
|
|
5
|
+
|
|
6
|
+
export default defineProvider({
|
|
7
|
+
id: "{{PROVIDER_ID}}",
|
|
8
|
+
version: "1.0.0",
|
|
9
|
+
runtime: "{{RUNTIME}}"{{BROWSER_BLOCK}},
|
|
10
|
+
allowedHosts: ["api.example.com"],
|
|
11
|
+
reviewed: "community",
|
|
12
|
+
{{SECRETS_BLOCK}}{{CREDENTIAL_BLOCK}}auth: {{AUTH_BLOCK}},
|
|
13
|
+
meta: providerMeta,
|
|
14
|
+
operations: operations,
|
|
15
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineOperation } from "@apifuse/provider-sdk/provider";
|
|
2
|
+
|
|
3
|
+
import { pingInputSchema, pingOutputSchema } from "../schemas/ping";
|
|
4
|
+
|
|
5
|
+
export const pingOperation = defineOperation({
|
|
6
|
+
descriptionKey: "operations.ping.description",
|
|
7
|
+
input: pingInputSchema,
|
|
8
|
+
output: pingOutputSchema,
|
|
9
|
+
handler: async ({{HANDLER_CTX}}, input) => {
|
|
10
|
+
{{BROWSER_HANDLER_BLOCK}}
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
message: "{{DISPLAY_NAME}} received: " + input.value{{BROWSER_RESPONSE_FIELDS}},
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
fixtures: {
|
|
17
|
+
request: { value: "hello" },
|
|
18
|
+
response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
|
|
19
|
+
},
|
|
20
|
+
healthCheckUnsupported: {
|
|
21
|
+
reason:
|
|
22
|
+
"Generated local-only scaffold operation. Replace this with a real healthCheck for upstream-backed bounty operations when safe; keep healthCheckUnsupported only for destructive, paid, credential-sensitive, or otherwise unprobeable operations with a specific rationale.",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describeKey, z } from "@apifuse/provider-sdk/provider";
|
|
2
|
+
|
|
3
|
+
export const pingInputSchema = describeKey(
|
|
4
|
+
z.object({
|
|
5
|
+
value: describeKey(z.string(), "schemaDescriptions.input.value"),
|
|
6
|
+
}),
|
|
7
|
+
"schemaDescriptions.input.root",
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const pingOutputSchema = describeKey(
|
|
11
|
+
z.object({
|
|
12
|
+
ok: describeKey(z.boolean(), "schemaDescriptions.output.ok"),
|
|
13
|
+
message: describeKey(z.string(), "schemaDescriptions.output.message"),
|
|
14
|
+
pageTitle: describeKey(
|
|
15
|
+
z.string().optional(),
|
|
16
|
+
"schemaDescriptions.output.pageTitle",
|
|
17
|
+
),
|
|
18
|
+
frameCount: describeKey(
|
|
19
|
+
z.number().int().nonnegative().optional(),
|
|
20
|
+
"schemaDescriptions.output.frameCount",
|
|
21
|
+
),
|
|
22
|
+
}),
|
|
23
|
+
"schemaDescriptions.output.root",
|
|
24
|
+
);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import Redis from "ioredis";
|
|
2
|
+
import type { ProviderProxyPolicy, TraceConfig } from "../types";
|
|
3
|
+
export declare const SMARTPROXY_APP_KEY_ENV = "APIFUSE__PROXY__SMARTPROXY_APP_KEY";
|
|
4
|
+
export declare const SMARTPROXY_MAX_LIFETIME_MINUTES = 2000;
|
|
5
|
+
export declare const DEFAULT_SMARTPROXY_POOL_SIZE = 20;
|
|
6
|
+
export declare const SMARTPROXY_MAX_POOL_SIZE = 20;
|
|
7
|
+
export declare const DEFAULT_PROXY_PROVIDER_ENV = "APIFUSE__PROXY__PROVIDER";
|
|
8
|
+
export declare const DEFAULT_PROXY_COUNTRY_ENV = "APIFUSE__PROXY__DEFAULT_COUNTRY";
|
|
9
|
+
export declare const DEFAULT_PROXY_LIFETIME_ENV = "APIFUSE__PROXY__DEFAULT_LIFETIME_MINUTES";
|
|
10
|
+
export declare const PROVIDER_CACHE_REDIS_URL_ENV = "APIFUSE__PROVIDER__CACHE_REDIS_URL";
|
|
11
|
+
export declare const PROVIDER_STATE_REDIS_URL_ENV = "APIFUSE__PROVIDER__STATE_REDIS_URL";
|
|
12
|
+
export declare const REDIS_URL_ENV = "APIFUSE__REDIS__URL";
|
|
13
|
+
export type ProxyOptions = {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
export type ProxyConfig = Partial<ProxyOptions> & {
|
|
17
|
+
provider?: string;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
};
|
|
20
|
+
export type BrowserConfig = {
|
|
21
|
+
executablePath?: string;
|
|
22
|
+
headless?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type SessionConfig = {
|
|
25
|
+
storage?: "sqlite" | "supabase";
|
|
26
|
+
path?: string;
|
|
27
|
+
};
|
|
28
|
+
export type ApiFuseConfig = {
|
|
29
|
+
proxy?: ProxyConfig;
|
|
30
|
+
browser?: BrowserConfig;
|
|
31
|
+
session?: SessionConfig;
|
|
32
|
+
trace?: TraceConfig;
|
|
33
|
+
credentials?: Record<string, Record<string, string>>;
|
|
34
|
+
};
|
|
35
|
+
export type ProxyResolutionOptions = {
|
|
36
|
+
proxy?: string;
|
|
37
|
+
upstream?: {
|
|
38
|
+
proxy?: boolean | ProviderProxyPolicy;
|
|
39
|
+
};
|
|
40
|
+
apifuseConfig?: Pick<ApiFuseConfig, "proxy">;
|
|
41
|
+
proxyPolicy?: ProviderProxyPolicy;
|
|
42
|
+
affinityKey?: string;
|
|
43
|
+
/** Zero-based proxy-pool attempt index used by SDK transports for failover. */
|
|
44
|
+
proxyAttempt?: number;
|
|
45
|
+
telemetry?: ProxyTelemetrySink;
|
|
46
|
+
};
|
|
47
|
+
export type ProxyCacheStatus = "memory_hit" | "redis_hit" | "allocator" | "soft_stale_refresh" | "lock_wait" | "redis_error" | "redis_corrupt" | "disabled";
|
|
48
|
+
export type SmartproxyAllocatorBodyClass = "network_error" | "http_error" | "empty" | "json_without_proxies" | "text_without_proxies" | "usable_proxy_endpoints";
|
|
49
|
+
export type ProxyResolutionTelemetryEvent = {
|
|
50
|
+
provider: "smartproxy";
|
|
51
|
+
cacheStatus: ProxyCacheStatus;
|
|
52
|
+
cacheHit: boolean;
|
|
53
|
+
resolutionMs: number;
|
|
54
|
+
allocatorMs?: number;
|
|
55
|
+
allocatorStatus?: number;
|
|
56
|
+
allocatorBodyClass?: SmartproxyAllocatorBodyClass;
|
|
57
|
+
allocatorAttempts?: number;
|
|
58
|
+
lockWaitMs?: number;
|
|
59
|
+
redisReadMs?: number;
|
|
60
|
+
redisWriteMs?: number;
|
|
61
|
+
poolAgeMs?: number;
|
|
62
|
+
poolExpiresInMs?: number;
|
|
63
|
+
attempts: number;
|
|
64
|
+
refreshes?: number;
|
|
65
|
+
};
|
|
66
|
+
export type ProxyAttemptTelemetryEvent = {
|
|
67
|
+
provider: "smartproxy";
|
|
68
|
+
attempt: number;
|
|
69
|
+
poolIndex?: number;
|
|
70
|
+
proxyHash?: string;
|
|
71
|
+
outcome: "ok" | "error";
|
|
72
|
+
errorCode?: string;
|
|
73
|
+
status?: number;
|
|
74
|
+
durationMs?: number;
|
|
75
|
+
};
|
|
76
|
+
export type ProxyTelemetrySink = {
|
|
77
|
+
recordProxyResolution(event: ProxyResolutionTelemetryEvent): void;
|
|
78
|
+
recordProxyAttempt?(event: ProxyAttemptTelemetryEvent): void;
|
|
79
|
+
};
|
|
80
|
+
export type ResolvedProxyConfig = {
|
|
81
|
+
shouldWarn: boolean;
|
|
82
|
+
url?: string;
|
|
83
|
+
source?: "explicit" | "env" | "config" | "smartproxy-allocator";
|
|
84
|
+
diagnostics?: Record<string, string | number | boolean>;
|
|
85
|
+
};
|
|
86
|
+
export declare class ProxyResolutionError extends Error {
|
|
87
|
+
readonly code: "PROXY_REQUIRED" | "PROXY_ALLOCATION_FAILED";
|
|
88
|
+
readonly telemetry?: ProxyResolutionTelemetryEvent;
|
|
89
|
+
constructor(code: "PROXY_REQUIRED" | "PROXY_ALLOCATION_FAILED", message: string, options?: {
|
|
90
|
+
cause?: unknown;
|
|
91
|
+
telemetry?: ProxyResolutionTelemetryEvent;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
type ProxyRedisClient = Pick<Redis, "connect" | "del" | "eval" | "get" | "on" | "pttl" | "set" | "status">;
|
|
95
|
+
export declare function providerCacheRedisUrlFromEnv(): string | undefined;
|
|
96
|
+
export declare function providerStateRedisUrlFromEnv(): string | undefined;
|
|
97
|
+
/** @internal Test-only hook for exercising shared proxy-cache behavior. */
|
|
98
|
+
export declare function __setProxyRedisForTests(redis: ProxyRedisClient | undefined): void;
|
|
99
|
+
export declare function __setSmartproxyAllocatorDeadlineMsForTests(deadlineMs: number | undefined): void;
|
|
100
|
+
export declare function resolveProxyConfig(options?: ProxyResolutionOptions): ResolvedProxyConfig;
|
|
101
|
+
export declare function resolveProxyConfigAsync(options?: ProxyResolutionOptions): Promise<ResolvedProxyConfig>;
|
|
102
|
+
export declare function clearProxyResolutionCache(): void;
|
|
103
|
+
export declare function invalidateProxyResolutionCache(options?: ProxyResolutionOptions): boolean;
|
|
104
|
+
export declare function invalidateProxyResolutionCacheAsync(options?: ProxyResolutionOptions): Promise<boolean>;
|
|
105
|
+
export declare function defineConfig(config: ApiFuseConfig): ApiFuseConfig;
|
|
106
|
+
export declare function loadApiFuseConfig(dir?: string): Promise<ApiFuseConfig>;
|
|
107
|
+
export {};
|