@apifuse/provider-sdk 2.1.0-beta.3 → 2.1.0-beta.5
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 +187 -8
- package/CHANGELOG.md +13 -1
- package/README.md +40 -18
- package/SUBMISSION.md +4 -4
- package/bin/apifuse-dev.ts +12 -5
- package/bin/apifuse-pack-check.ts +9 -2
- package/bin/apifuse-pack-smoke.ts +127 -6
- package/bin/apifuse-perf.ts +76 -31
- package/bin/apifuse-record.ts +148 -94
- package/bin/apifuse-submit-check.ts +243 -7
- package/bin/apifuse.ts +1 -1
- package/package.json +17 -8
- package/src/choice-token.ts +164 -0
- package/src/cli/commands.ts +4 -7
- package/src/cli/create.ts +180 -51
- 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 +42 -7
- 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 -47
- 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 +23 -0
- package/src/cli/templates/provider/schemas/ping.ts.tpl +16 -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 +1206 -9
- package/src/define.ts +1620 -106
- package/src/errors.ts +12 -0
- package/src/i18n/catalog.ts +121 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/keys.ts +64 -0
- package/src/index.ts +149 -8
- package/src/lint.ts +306 -51
- package/src/observability.ts +41 -0
- package/src/provider.ts +60 -3
- package/src/public-schema-field-lint.ts +237 -0
- package/src/runtime/auth-flow.ts +7 -0
- package/src/runtime/browser.ts +77 -21
- package/src/runtime/cache.ts +582 -0
- package/src/runtime/executor.ts +13 -1
- package/src/runtime/http.ts +939 -195
- 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/request-options.ts +66 -0
- package/src/runtime/state.ts +76 -0
- package/src/runtime/stealth.ts +1145 -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 +816 -58
- package/src/server/types.ts +35 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +17 -4
- package/src/types.ts +876 -53
- package/src/runtime/tls.ts +0 -434
- package/src/types/playwright-stealth.d.ts +0 -9
|
@@ -12,6 +12,23 @@ bun run submit-check
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
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
|
+
|
|
15
32
|
## Pre-submission report
|
|
16
33
|
|
|
17
34
|
Before posting bounty evidence, run:
|
|
@@ -93,18 +110,18 @@ Structured errors return an `error` object with `code`, `message`,
|
|
|
93
110
|
`connection.secrets`, and read them with `ctx.credential`.
|
|
94
111
|
- Auth flow: call `/auth/start`, then `/auth/continue` with the same `flowId`;
|
|
95
112
|
carry returned `contextPatch` values into the next request's `context`.
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
`ctx.
|
|
99
|
-
`browser.engine: "playwright-stealth"`
|
|
100
|
-
then install local Chromium with
|
|
101
|
-
`
|
|
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`.
|
|
102
119
|
|
|
103
120
|
## Next steps
|
|
104
121
|
|
|
105
122
|
1. Replace the sample `ping` operation with real upstream logic.
|
|
106
123
|
2. Once the real operation declares `upstream.baseUrl` and uses `ctx.http` or
|
|
107
|
-
`ctx.
|
|
124
|
+
`ctx.stealth`, record a fixture with:
|
|
108
125
|
`bun run record -- --operation <operation> --params '<json-input>'`.
|
|
109
126
|
3. Replace the starter `healthCheckUnsupported` with a real `healthCheck` for read-only upstream operations when safe.
|
|
110
127
|
4. Extend tests and operation metadata until the provider is bounty-ready.
|
|
@@ -123,3 +140,21 @@ Every operation must declare exactly one of:
|
|
|
123
140
|
|
|
124
141
|
The generated `ping` operation uses `healthCheckUnsupported` only because it is
|
|
125
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
|
+
```
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import { defineProvider
|
|
1
|
+
import { defineProvider } from "@apifuse/provider-sdk/provider";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: z
|
|
6
|
-
.string()
|
|
7
|
-
.describe("Sample input value used to verify the generated provider scaffold is wired correctly."),
|
|
8
|
-
})
|
|
9
|
-
.describe("Input payload for the generated ping operation.");
|
|
10
|
-
|
|
11
|
-
const OutputSchema = z
|
|
12
|
-
.object({
|
|
13
|
-
ok: z
|
|
14
|
-
.boolean()
|
|
15
|
-
.describe("Whether the generated provider handled the sample request successfully."),
|
|
16
|
-
message: z
|
|
17
|
-
.string()
|
|
18
|
-
.describe("Human-readable confirmation that the generated provider round-tripped the sample payload."),
|
|
19
|
-
})
|
|
20
|
-
.describe("Output payload returned by the generated ping operation.");
|
|
3
|
+
import { providerMeta } from "./meta";
|
|
4
|
+
import { operations } from "./operations";
|
|
21
5
|
|
|
22
6
|
export default defineProvider({
|
|
23
7
|
id: "{{PROVIDER_ID}}",
|
|
@@ -26,32 +10,6 @@ export default defineProvider({
|
|
|
26
10
|
allowedHosts: ["api.example.com"],
|
|
27
11
|
reviewed: "community",
|
|
28
12
|
{{SECRETS_BLOCK}}{{CREDENTIAL_BLOCK}}auth: {{AUTH_BLOCK}},
|
|
29
|
-
meta:
|
|
30
|
-
|
|
31
|
-
description: "{{DISPLAY_NAME}} provider starter for ApiFuse community contributions.",
|
|
32
|
-
category: "{{CATEGORY}}",
|
|
33
|
-
tags: ["{{PROVIDER_ID}}", "starter", "community"],
|
|
34
|
-
},
|
|
35
|
-
operations: {
|
|
36
|
-
ping: {
|
|
37
|
-
description:
|
|
38
|
-
"Confirms the generated provider wiring is operational by echoing a small sample payload through the ApiFuse runtime contract. Use when validating local development, baseline checks, or first-pass bounty scaffolds. Do NOT use for production data retrieval or upstream-specific workflows because this starter operation exists only to prove the generated project compiles, serves, and round-trips input/output correctly. Returns a success flag plus a message containing the supplied value.",
|
|
39
|
-
input: InputSchema,
|
|
40
|
-
output: OutputSchema,
|
|
41
|
-
handler: async (_ctx, input) => {
|
|
42
|
-
return {
|
|
43
|
-
ok: true,
|
|
44
|
-
message: "{{DISPLAY_NAME}} received: " + input.value,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
fixtures: {
|
|
48
|
-
request: { value: "hello" },
|
|
49
|
-
response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
|
|
50
|
-
},
|
|
51
|
-
healthCheckUnsupported: {
|
|
52
|
-
reason:
|
|
53
|
-
"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.",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
13
|
+
meta: providerMeta,
|
|
14
|
+
operations: operations,
|
|
57
15
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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 (_ctx, input) => {
|
|
10
|
+
return {
|
|
11
|
+
ok: true,
|
|
12
|
+
message: "{{DISPLAY_NAME}} received: " + input.value,
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
fixtures: {
|
|
16
|
+
request: { value: "hello" },
|
|
17
|
+
response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
|
|
18
|
+
},
|
|
19
|
+
healthCheckUnsupported: {
|
|
20
|
+
reason:
|
|
21
|
+
"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.",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}),
|
|
15
|
+
"schemaDescriptions.output.root",
|
|
16
|
+
);
|