@apifuse/provider-sdk 2.1.0-beta.2 → 2.1.0-beta.20

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 (215) hide show
  1. package/AUTHORING.md +330 -8
  2. package/CHANGELOG.md +85 -1
  3. package/README.md +64 -17
  4. package/SUBMISSION.md +86 -0
  5. package/bin/apifuse-check.ts +60 -6
  6. package/bin/apifuse-dev.ts +58 -8
  7. package/bin/apifuse-pack-check.ts +32 -2
  8. package/bin/apifuse-pack-smoke.ts +133 -6
  9. package/bin/apifuse-perf.ts +142 -49
  10. package/bin/apifuse-record.ts +182 -104
  11. package/bin/apifuse-submit-check.ts +2849 -0
  12. package/bin/apifuse.ts +1 -1
  13. package/dist/auth.d.ts +76 -0
  14. package/dist/auth.js +436 -0
  15. package/dist/ceremonies/index.d.ts +41 -0
  16. package/dist/ceremonies/index.js +490 -0
  17. package/dist/choice-token.d.ts +24 -0
  18. package/dist/choice-token.js +74 -0
  19. package/dist/cli/commands.d.ts +10 -0
  20. package/dist/cli/commands.js +80 -0
  21. package/dist/cli/create.d.ts +47 -0
  22. package/dist/cli/create.js +745 -0
  23. package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
  24. package/dist/cli/templates/provider/.gitignore.tpl +22 -0
  25. package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
  26. package/dist/cli/templates/provider/README.md.tpl +163 -0
  27. package/dist/cli/templates/provider/dev.ts.tpl +5 -0
  28. package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
  29. package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
  30. package/dist/cli/templates/provider/index.ts.tpl +15 -0
  31. package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
  32. package/dist/cli/templates/provider/meta.ts.tpl +7 -0
  33. package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
  34. package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
  35. package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  36. package/dist/cli/templates/provider/start.ts.tpl +5 -0
  37. package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
  38. package/dist/config/loader.d.ts +107 -0
  39. package/dist/config/loader.js +935 -0
  40. package/dist/contract-json.d.ts +9 -0
  41. package/dist/contract-json.js +51 -0
  42. package/dist/contract-serialization.d.ts +4 -0
  43. package/dist/contract-serialization.js +78 -0
  44. package/dist/contract-types.d.ts +49 -0
  45. package/dist/contract-types.js +1 -0
  46. package/dist/contract.d.ts +6 -0
  47. package/dist/contract.js +156 -0
  48. package/dist/define.d.ts +100 -0
  49. package/dist/define.js +1383 -0
  50. package/dist/dev.d.ts +9 -0
  51. package/dist/dev.js +15 -0
  52. package/dist/errors.d.ts +59 -0
  53. package/dist/errors.js +97 -0
  54. package/dist/i18n/catalog.d.ts +29 -0
  55. package/dist/i18n/catalog.js +159 -0
  56. package/dist/i18n/index.d.ts +2 -0
  57. package/dist/i18n/index.js +2 -0
  58. package/dist/i18n/keys.d.ts +10 -0
  59. package/dist/i18n/keys.js +34 -0
  60. package/dist/index.d.ts +42 -0
  61. package/dist/index.js +38 -0
  62. package/dist/lint.d.ts +74 -0
  63. package/dist/lint.js +729 -0
  64. package/dist/observability.d.ts +5 -0
  65. package/dist/observability.js +39 -0
  66. package/dist/provider.d.ts +11 -0
  67. package/dist/provider.js +9 -0
  68. package/dist/public-schema-field-lint.d.ts +2 -0
  69. package/dist/public-schema-field-lint.js +158 -0
  70. package/dist/recipes/gov-api.d.ts +19 -0
  71. package/dist/recipes/gov-api.js +72 -0
  72. package/dist/recipes/rest-api.d.ts +21 -0
  73. package/dist/recipes/rest-api.js +115 -0
  74. package/dist/runtime/auth-flow.d.ts +14 -0
  75. package/dist/runtime/auth-flow.js +46 -0
  76. package/dist/runtime/browser.d.ts +25 -0
  77. package/dist/runtime/browser.js +1237 -0
  78. package/dist/runtime/cache.d.ts +10 -0
  79. package/dist/runtime/cache.js +372 -0
  80. package/dist/runtime/choice.d.ts +15 -0
  81. package/dist/runtime/choice.js +435 -0
  82. package/dist/runtime/credential.d.ts +8 -0
  83. package/dist/runtime/credential.js +61 -0
  84. package/dist/runtime/env.d.ts +2 -0
  85. package/dist/runtime/env.js +10 -0
  86. package/dist/runtime/executor.d.ts +16 -0
  87. package/dist/runtime/executor.js +51 -0
  88. package/dist/runtime/http.d.ts +8 -0
  89. package/dist/runtime/http.js +726 -0
  90. package/dist/runtime/insights.d.ts +9 -0
  91. package/dist/runtime/insights.js +324 -0
  92. package/dist/runtime/instrumentation.d.ts +8 -0
  93. package/dist/runtime/instrumentation.js +269 -0
  94. package/dist/runtime/key-derivation.d.ts +24 -0
  95. package/dist/runtime/key-derivation.js +73 -0
  96. package/dist/runtime/keyring.d.ts +25 -0
  97. package/dist/runtime/keyring.js +93 -0
  98. package/dist/runtime/namespace.d.ts +9 -0
  99. package/dist/runtime/namespace.js +19 -0
  100. package/dist/runtime/otlp.d.ts +39 -0
  101. package/dist/runtime/otlp.js +103 -0
  102. package/dist/runtime/perf.d.ts +12 -0
  103. package/dist/runtime/perf.js +52 -0
  104. package/dist/runtime/prevalidate.d.ts +12 -0
  105. package/dist/runtime/prevalidate.js +173 -0
  106. package/dist/runtime/provider.d.ts +2 -0
  107. package/dist/runtime/provider.js +11 -0
  108. package/dist/runtime/proxy-errors.d.ts +21 -0
  109. package/dist/runtime/proxy-errors.js +83 -0
  110. package/dist/runtime/proxy-telemetry.d.ts +8 -0
  111. package/dist/runtime/proxy-telemetry.js +174 -0
  112. package/dist/runtime/redis.d.ts +17 -0
  113. package/dist/runtime/redis.js +82 -0
  114. package/dist/runtime/request-options.d.ts +3 -0
  115. package/dist/runtime/request-options.js +42 -0
  116. package/dist/runtime/state.d.ts +17 -0
  117. package/dist/runtime/state.js +344 -0
  118. package/dist/runtime/stealth.d.ts +21 -0
  119. package/dist/runtime/stealth.js +980 -0
  120. package/dist/runtime/stt.d.ts +22 -0
  121. package/dist/runtime/stt.js +480 -0
  122. package/dist/runtime/trace.d.ts +26 -0
  123. package/dist/runtime/trace.js +142 -0
  124. package/dist/runtime/waterfall.d.ts +12 -0
  125. package/dist/runtime/waterfall.js +147 -0
  126. package/dist/schema.d.ts +74 -0
  127. package/dist/schema.js +243 -0
  128. package/dist/serve.d.ts +1 -0
  129. package/dist/serve.js +1 -0
  130. package/dist/server/index.d.ts +3 -0
  131. package/dist/server/index.js +2 -0
  132. package/dist/server/serve.d.ts +64 -0
  133. package/dist/server/serve.js +1118 -0
  134. package/dist/server/types.d.ts +136 -0
  135. package/dist/server/types.js +86 -0
  136. package/dist/stealth/profiles.d.ts +4 -0
  137. package/dist/stealth/profiles.js +259 -0
  138. package/dist/stream.d.ts +44 -0
  139. package/dist/stream.js +151 -0
  140. package/dist/testing/helpers.d.ts +23 -0
  141. package/dist/testing/helpers.js +95 -0
  142. package/dist/testing/index.d.ts +2 -0
  143. package/dist/testing/index.js +2 -0
  144. package/dist/testing/run.d.ts +34 -0
  145. package/dist/testing/run.js +307 -0
  146. package/dist/types.d.ts +1467 -0
  147. package/dist/types.js +61 -0
  148. package/dist/utils/date.d.ts +6 -0
  149. package/dist/utils/date.js +101 -0
  150. package/dist/utils/parse.d.ts +16 -0
  151. package/dist/utils/parse.js +51 -0
  152. package/dist/utils/text.d.ts +4 -0
  153. package/dist/utils/text.js +14 -0
  154. package/dist/utils/transform.d.ts +8 -0
  155. package/dist/utils/transform.js +48 -0
  156. package/package.json +56 -29
  157. package/src/auth.ts +786 -0
  158. package/src/ceremonies/index.ts +8 -2
  159. package/src/choice-token.ts +165 -0
  160. package/src/cli/commands.ts +34 -11
  161. package/src/cli/create.ts +222 -128
  162. package/src/cli/templates/provider/.dockerignore.tpl +22 -0
  163. package/src/cli/templates/provider/.gitignore.tpl +22 -0
  164. package/src/cli/templates/provider/README.md.tpl +87 -7
  165. package/src/cli/templates/provider/dev.ts.tpl +1 -1
  166. package/src/cli/templates/provider/domain/README.md.tpl +3 -0
  167. package/src/cli/templates/provider/index.ts.tpl +5 -47
  168. package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
  169. package/src/cli/templates/provider/meta.ts.tpl +7 -0
  170. package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
  171. package/src/cli/templates/provider/operations/ping.ts.tpl +24 -0
  172. package/src/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  173. package/src/cli/templates/provider/start.ts.tpl +1 -1
  174. package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
  175. package/src/config/loader.ts +1224 -9
  176. package/src/contract-json.ts +75 -0
  177. package/src/contract-serialization.ts +89 -0
  178. package/src/contract-types.ts +52 -0
  179. package/src/contract.ts +216 -0
  180. package/src/define.ts +1820 -70
  181. package/src/errors.ts +27 -0
  182. package/src/i18n/catalog.ts +277 -0
  183. package/src/i18n/index.ts +2 -0
  184. package/src/i18n/keys.ts +64 -0
  185. package/src/index.ts +189 -9
  186. package/src/lint.ts +580 -73
  187. package/src/observability.ts +41 -0
  188. package/src/provider.ts +131 -4
  189. package/src/public-schema-field-lint.ts +237 -0
  190. package/src/runtime/auth-flow.ts +9 -0
  191. package/src/runtime/browser.ts +1054 -51
  192. package/src/runtime/cache.ts +528 -0
  193. package/src/runtime/choice.ts +760 -0
  194. package/src/runtime/executor.ts +32 -3
  195. package/src/runtime/http.ts +980 -195
  196. package/src/runtime/insights.ts +11 -11
  197. package/src/runtime/instrumentation.ts +12 -4
  198. package/src/runtime/key-derivation.ts +1 -1
  199. package/src/runtime/keyring.ts +4 -3
  200. package/src/runtime/proxy-errors.ts +132 -0
  201. package/src/runtime/proxy-telemetry.ts +253 -0
  202. package/src/runtime/redis.ts +116 -0
  203. package/src/runtime/request-options.ts +66 -0
  204. package/src/runtime/state.ts +563 -0
  205. package/src/runtime/stealth.ts +1336 -0
  206. package/src/runtime/stt.ts +629 -0
  207. package/src/runtime/trace.ts +1 -1
  208. package/src/schema.ts +363 -1
  209. package/src/server/serve.ts +1192 -75
  210. package/src/server/types.ts +37 -0
  211. package/src/stream.ts +210 -0
  212. package/src/testing/run.ts +40 -6
  213. package/src/types.ts +1283 -59
  214. package/src/runtime/tls.ts +0 -434
  215. package/src/types/playwright-stealth.d.ts +0 -9
@@ -8,6 +8,68 @@ Generated with `apifuse create`.
8
8
  bun run dev
9
9
  bun run check
10
10
  bun run test
11
+ bun run submit-check -- --smoke
12
+ bunx apifuse perf . --operation <operation-id> --runs 3
13
+ ```
14
+
15
+
16
+ ## Module layout
17
+
18
+ The generated provider uses the recommended split layout:
19
+
20
+ ```text
21
+ index.ts # composition root: defineProvider() and wiring only
22
+ meta.ts # provider metadata
23
+ operations/ # APIFuse operation contracts and handlers
24
+ schemas/ # public input/output schemas near operations
25
+ upstream/ # upstream ceremony: clients, auth, request builders
26
+ mappers/ # upstream-to-APIFuse normalization helpers
27
+ domain/ # shared provider-specific business ceremony
28
+ ```
29
+
30
+ Small providers may stay in one file, but larger providers are easier to
31
+ review when `index.ts` remains a short composition root.
32
+
33
+ ## Pre-submission report
34
+
35
+ Before posting bounty evidence, run:
36
+
37
+ ```bash
38
+ bun run submit-check -- --smoke
39
+ ```
40
+
41
+ This writes `submission-report.md` with a review-readiness score, blockers,
42
+ warnings, health coverage notes, fixture/schema evidence, and remediation. A
43
+ score is not a payout guarantee; blockers must be fixed before maintainer
44
+ review. The generated `ping` starter intentionally warns until you replace it
45
+ with real upstream-backed Operations. `APIFUSE__PROVIDER__*` env vars enable
46
+ live upstream calls; without them, structured provider errors can still verify
47
+ runtime routing. The full public-only checklist is shipped in
48
+ `node_modules/@apifuse/provider-sdk/SUBMISSION.md`.
49
+
50
+
51
+ ## Operation guide
52
+
53
+ ### Parameters
54
+
55
+ Starter `ping` accepts `{ "value": string }`. Replace this section with each
56
+ real operation's input schema, required fields, formats, limits, and examples
57
+ before submitting bounty evidence.
58
+
59
+ ### Response
60
+
61
+ Starter `ping` returns `{ "ok": boolean, "message": string }`. Replace this
62
+ section with the normalized response fields, units, enum values, pagination,
63
+ and upstream caveats for each real operation.
64
+
65
+ ### Example
66
+
67
+ ```json
68
+ {
69
+ "requestId": "req_local_ping",
70
+ "input": { "value": "hello" },
71
+ "headers": {}
72
+ }
11
73
  ```
12
74
 
13
75
  ## Provider server contract
@@ -51,18 +113,18 @@ Structured errors return an `error` object with `code`, `message`,
51
113
  `connection.secrets`, and read them with `ctx.credential`.
52
114
  - Auth flow: call `/auth/start`, then `/auth/continue` with the same `flowId`;
53
115
  carry returned `contextPatch` values into the next request's `context`.
54
- - TLS/browser runtime: if Bun blocks native dependency lifecycle scripts, run
55
- `bun pm untrusted` and trust SDK dependencies such as `koffi` before debugging
56
- `ctx.tls`; for TypeScript browser Providers use
57
- `browser.engine: "playwright-stealth"` (`nodriver` is Python-runtime only),
58
- then install local Chromium with `bunx playwright install chromium` or set
59
- `CDP_POOL_URL`.
116
+ - Stealth/browser runtime: keep access-sensitive operations on `ctx.stealth.fetch()` with an
117
+ SDK stealth `profile`; the TypeScript stealth runtime uses `impit` internally.
118
+ `ctx.stealth` supports Chrome/Firefox-style profiles. For TypeScript browser
119
+ Providers or Safari-specific behavior use `browser.engine: "playwright-stealth"`
120
+ (`nodriver` is Python-runtime only), then install local Chromium with
121
+ `bunx playwright install chromium` or set `APIFUSE__CDP_POOL__URL`.
60
122
 
61
123
  ## Next steps
62
124
 
63
125
  1. Replace the sample `ping` operation with real upstream logic.
64
126
  2. Once the real operation declares `upstream.baseUrl` and uses `ctx.http` or
65
- `ctx.tls`, record a fixture with:
127
+ `ctx.stealth`, record a fixture with:
66
128
  `bun run record -- --operation <operation> --params '<json-input>'`.
67
129
  3. Replace the starter `healthCheckUnsupported` with a real `healthCheck` for read-only upstream operations when safe.
68
130
  4. Extend tests and operation metadata until the provider is bounty-ready.
@@ -81,3 +143,21 @@ Every operation must declare exactly one of:
81
143
 
82
144
  The generated `ping` operation uses `healthCheckUnsupported` only because it is
83
145
  a local scaffold check, not a real upstream API probe.
146
+
147
+ `healthCheck.cases[].assertions` receives `{ data, status, durationMs, meta }`.
148
+ `data` is the parsed operation output. Use this shape in real operations:
149
+
150
+ ```ts
151
+ healthCheck: {
152
+ interval: "5m",
153
+ cases: [{
154
+ name: "lookup baseline",
155
+ input: { q: "btc" },
156
+ assertions: ({ data, status, durationMs }) => {
157
+ if (status !== 200 || data.results.length === 0 || durationMs > 3000) {
158
+ return { status: "degraded", label: "lookup baseline changed" };
159
+ }
160
+ },
161
+ }],
162
+ }
163
+ ```
@@ -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,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
+ );
@@ -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.