@apifuse/provider-sdk 2.1.0-beta.2 → 2.1.0-beta.4
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 +172 -8
- package/CHANGELOG.md +15 -1
- package/README.md +29 -15
- package/SUBMISSION.md +86 -0
- package/bin/apifuse-dev.ts +12 -5
- package/bin/apifuse-pack-check.ts +17 -2
- package/bin/apifuse-pack-smoke.ts +133 -6
- package/bin/apifuse-perf.ts +19 -15
- package/bin/apifuse-record.ts +41 -53
- package/bin/apifuse-submit-check.ts +1052 -0
- package/bin/apifuse.ts +1 -1
- package/package.json +19 -9
- package/src/choice-token.ts +164 -0
- package/src/cli/commands.ts +24 -3
- package/src/cli/create.ts +166 -51
- package/src/cli/templates/provider/README.md.tpl +66 -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 +1648 -43
- 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 +152 -8
- package/src/lint.ts +297 -42
- 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/schema.ts +363 -1
- package/src/server/serve.ts +827 -60
- package/src/server/types.ts +35 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +17 -4
- package/src/types.ts +889 -50
- package/src/runtime/tls.ts +0 -434
- package/src/types/playwright-stealth.d.ts +0 -9
|
@@ -8,6 +8,65 @@ Generated with `apifuse create`.
|
|
|
8
8
|
bun run dev
|
|
9
9
|
bun run check
|
|
10
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
|
+
}
|
|
11
70
|
```
|
|
12
71
|
|
|
13
72
|
## Provider server contract
|
|
@@ -51,18 +110,18 @@ Structured errors return an `error` object with `code`, `message`,
|
|
|
51
110
|
`connection.secrets`, and read them with `ctx.credential`.
|
|
52
111
|
- Auth flow: call `/auth/start`, then `/auth/continue` with the same `flowId`;
|
|
53
112
|
carry returned `contextPatch` values into the next request's `context`.
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
`ctx.
|
|
57
|
-
`browser.engine: "playwright-stealth"`
|
|
58
|
-
then install local Chromium with
|
|
59
|
-
`
|
|
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`.
|
|
60
119
|
|
|
61
120
|
## Next steps
|
|
62
121
|
|
|
63
122
|
1. Replace the sample `ping` operation with real upstream logic.
|
|
64
123
|
2. Once the real operation declares `upstream.baseUrl` and uses `ctx.http` or
|
|
65
|
-
`ctx.
|
|
124
|
+
`ctx.stealth`, record a fixture with:
|
|
66
125
|
`bun run record -- --operation <operation> --params '<json-input>'`.
|
|
67
126
|
3. Replace the starter `healthCheckUnsupported` with a real `healthCheck` for read-only upstream operations when safe.
|
|
68
127
|
4. Extend tests and operation metadata until the provider is bounty-ready.
|
|
@@ -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
|
+
);
|