@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.
Files changed (63) hide show
  1. package/AUTHORING.md +187 -8
  2. package/CHANGELOG.md +13 -1
  3. package/README.md +40 -18
  4. package/SUBMISSION.md +4 -4
  5. package/bin/apifuse-dev.ts +12 -5
  6. package/bin/apifuse-pack-check.ts +9 -2
  7. package/bin/apifuse-pack-smoke.ts +127 -6
  8. package/bin/apifuse-perf.ts +76 -31
  9. package/bin/apifuse-record.ts +148 -94
  10. package/bin/apifuse-submit-check.ts +243 -7
  11. package/bin/apifuse.ts +1 -1
  12. package/package.json +17 -8
  13. package/src/choice-token.ts +164 -0
  14. package/src/cli/commands.ts +4 -7
  15. package/src/cli/create.ts +180 -51
  16. package/src/cli/templates/provider/.dockerignore.tpl +22 -0
  17. package/src/cli/templates/provider/.gitignore.tpl +22 -0
  18. package/src/cli/templates/provider/README.md.tpl +42 -7
  19. package/src/cli/templates/provider/dev.ts.tpl +1 -1
  20. package/src/cli/templates/provider/domain/README.md.tpl +3 -0
  21. package/src/cli/templates/provider/index.ts.tpl +5 -47
  22. package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
  23. package/src/cli/templates/provider/meta.ts.tpl +7 -0
  24. package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
  25. package/src/cli/templates/provider/operations/ping.ts.tpl +23 -0
  26. package/src/cli/templates/provider/schemas/ping.ts.tpl +16 -0
  27. package/src/cli/templates/provider/start.ts.tpl +1 -1
  28. package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
  29. package/src/config/loader.ts +1206 -9
  30. package/src/define.ts +1620 -106
  31. package/src/errors.ts +12 -0
  32. package/src/i18n/catalog.ts +121 -0
  33. package/src/i18n/index.ts +2 -0
  34. package/src/i18n/keys.ts +64 -0
  35. package/src/index.ts +149 -8
  36. package/src/lint.ts +306 -51
  37. package/src/observability.ts +41 -0
  38. package/src/provider.ts +60 -3
  39. package/src/public-schema-field-lint.ts +237 -0
  40. package/src/runtime/auth-flow.ts +7 -0
  41. package/src/runtime/browser.ts +77 -21
  42. package/src/runtime/cache.ts +582 -0
  43. package/src/runtime/executor.ts +13 -1
  44. package/src/runtime/http.ts +939 -195
  45. package/src/runtime/insights.ts +11 -11
  46. package/src/runtime/instrumentation.ts +12 -4
  47. package/src/runtime/key-derivation.ts +1 -1
  48. package/src/runtime/keyring.ts +4 -3
  49. package/src/runtime/proxy-errors.ts +132 -0
  50. package/src/runtime/proxy-telemetry.ts +253 -0
  51. package/src/runtime/request-options.ts +66 -0
  52. package/src/runtime/state.ts +76 -0
  53. package/src/runtime/stealth.ts +1145 -0
  54. package/src/runtime/stt.ts +629 -0
  55. package/src/runtime/trace.ts +1 -1
  56. package/src/schema.ts +363 -1
  57. package/src/server/serve.ts +816 -58
  58. package/src/server/types.ts +35 -0
  59. package/src/stream.ts +210 -0
  60. package/src/testing/run.ts +17 -4
  61. package/src/types.ts +876 -53
  62. package/src/runtime/tls.ts +0 -434
  63. 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
- - TLS/browser runtime: if Bun blocks native dependency lifecycle scripts, run
97
- `bun pm untrusted` and trust SDK dependencies such as `koffi` before debugging
98
- `ctx.tls`; for TypeScript browser Providers use
99
- `browser.engine: "playwright-stealth"` (`nodriver` is Python-runtime only),
100
- then install local Chromium with `bunx playwright install chromium` or set
101
- `CDP_POOL_URL`.
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.tls`, record a fixture with:
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
+ ```
@@ -2,4 +2,4 @@ import { startDevServer } from "@apifuse/provider-sdk";
2
2
 
3
3
  import provider from "./index";
4
4
 
5
- startDevServer(provider, { port: Number(process.env.PORT) || 3900 });
5
+ startDevServer(provider, { port: Number(process.env.APIFUSE__RUNTIME__PORT) || 3900 });
@@ -0,0 +1,3 @@
1
+ # Domain
2
+
3
+ Put provider-specific business ceremony here when it is shared across operations and too complex to live inside one operation module.
@@ -1,23 +1,7 @@
1
- import { defineProvider, z } from "@apifuse/provider-sdk";
1
+ import { defineProvider } from "@apifuse/provider-sdk/provider";
2
2
 
3
- const InputSchema = z
4
- .object({
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
- displayName: "{{DISPLAY_NAME}}",
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,3 @@
1
+ # Mappers
2
+
3
+ Put normalization helpers here when upstream responses need to become public APIFuse operation outputs.
@@ -0,0 +1,7 @@
1
+ export const providerMeta = {
2
+ displayName: "{{PROVIDER_ID}}",
3
+ displayNameKey: "meta.displayName",
4
+ descriptionKey: "meta.description",
5
+ category: "{{CATEGORY}}",
6
+ tags: ["{{PROVIDER_ID}}", "starter", "community"],
7
+ } as const;
@@ -0,0 +1,5 @@
1
+ import { pingOperation } from "./ping";
2
+
3
+ export const operations = {
4
+ ping: pingOperation,
5
+ };
@@ -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
+ );
@@ -2,4 +2,4 @@ import { serve } from "@apifuse/provider-sdk";
2
2
 
3
3
  import provider from "./index";
4
4
 
5
- await serve(provider, { port: Number(process.env.PORT) || 3000 });
5
+ await serve(provider, { port: Number(process.env.APIFUSE__RUNTIME__PORT) || 3000 });
@@ -0,0 +1,3 @@
1
+ # Upstream
2
+
3
+ Put upstream HTTP clients, auth ceremony helpers, request builders, and protocol-specific types here once the provider talks to the real upstream service.