@apifuse/provider-sdk 2.0.0-beta.1 → 2.1.0-beta.0

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 (78) hide show
  1. package/AUTHORING.md +102 -0
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +100 -28
  4. package/bin/apifuse-check.ts +78 -71
  5. package/bin/apifuse-create.ts +12 -0
  6. package/bin/apifuse-dev.ts +24 -61
  7. package/bin/apifuse-pack-check.ts +47 -0
  8. package/bin/apifuse-perf.ts +33 -32
  9. package/bin/apifuse-record.ts +17 -7
  10. package/bin/apifuse-test.ts +6 -4
  11. package/bin/apifuse.ts +36 -35
  12. package/package.json +28 -9
  13. package/src/ceremonies/index.ts +747 -0
  14. package/src/cli/commands.ts +87 -0
  15. package/src/cli/create.ts +845 -0
  16. package/src/cli/templates/provider/Dockerfile.tpl +7 -0
  17. package/src/cli/templates/provider/README.md.tpl +28 -0
  18. package/src/cli/templates/provider/dev.ts.tpl +5 -0
  19. package/src/cli/templates/provider/index.test.ts.tpl +13 -0
  20. package/src/cli/templates/provider/index.ts.tpl +54 -0
  21. package/src/cli/templates/provider/start.ts.tpl +5 -0
  22. package/src/composite.ts +43 -0
  23. package/src/define.ts +527 -41
  24. package/src/dev.ts +2 -6
  25. package/src/errors.ts +42 -0
  26. package/src/index.ts +50 -38
  27. package/src/lint.ts +574 -0
  28. package/src/provider.ts +14 -0
  29. package/src/runtime/auth-flow.ts +67 -0
  30. package/src/runtime/credential.ts +95 -0
  31. package/src/runtime/env.ts +13 -0
  32. package/src/runtime/executor.ts +13 -14
  33. package/src/runtime/http.ts +10 -2
  34. package/src/runtime/insights.ts +3 -3
  35. package/src/runtime/key-derivation.ts +122 -0
  36. package/src/runtime/keyring.ts +148 -0
  37. package/src/runtime/namespace.ts +33 -0
  38. package/src/runtime/prevalidate.ts +252 -0
  39. package/src/runtime/tls.ts +20 -5
  40. package/src/runtime/waterfall.ts +0 -1
  41. package/src/schema.ts +77 -0
  42. package/src/serve.ts +1 -664
  43. package/src/server/index.ts +22 -0
  44. package/src/server/serve.ts +610 -0
  45. package/src/server/types.ts +78 -0
  46. package/src/stealth/profiles.ts +10 -93
  47. package/src/testing/run.ts +391 -32
  48. package/src/types.ts +364 -41
  49. package/bin/apifuse-init.ts +0 -387
  50. package/src/__tests__/auth.test.ts +0 -396
  51. package/src/__tests__/browser-auth.test.ts +0 -180
  52. package/src/__tests__/browser.test.ts +0 -632
  53. package/src/__tests__/define.test.ts +0 -225
  54. package/src/__tests__/errors.test.ts +0 -69
  55. package/src/__tests__/executor.test.ts +0 -214
  56. package/src/__tests__/http.test.ts +0 -238
  57. package/src/__tests__/insights.test.ts +0 -210
  58. package/src/__tests__/instrumentation.test.ts +0 -290
  59. package/src/__tests__/otlp.test.ts +0 -141
  60. package/src/__tests__/perf.test.ts +0 -60
  61. package/src/__tests__/providers-yaml.test.ts +0 -135
  62. package/src/__tests__/proxy.test.ts +0 -359
  63. package/src/__tests__/recipes.test.ts +0 -36
  64. package/src/__tests__/serve.test.ts +0 -233
  65. package/src/__tests__/session.test.ts +0 -231
  66. package/src/__tests__/state.test.ts +0 -100
  67. package/src/__tests__/stealth.test.ts +0 -57
  68. package/src/__tests__/testing.test.ts +0 -97
  69. package/src/__tests__/tls.test.ts +0 -345
  70. package/src/__tests__/types.test.ts +0 -142
  71. package/src/__tests__/utils.test.ts +0 -62
  72. package/src/__tests__/waterfall.test.ts +0 -270
  73. package/src/config/providers-yaml.ts +0 -370
  74. package/src/index.test.ts +0 -1
  75. package/src/protocol.ts +0 -183
  76. package/src/runtime/auth.ts +0 -245
  77. package/src/runtime/session.ts +0 -573
  78. package/src/runtime/state.ts +0 -124
@@ -0,0 +1,7 @@
1
+ FROM oven/bun:1.2-alpine
2
+ WORKDIR /provider
3
+ COPY package.json bun.lockb* ./
4
+ RUN bun install --frozen-lockfile
5
+ COPY . .
6
+ EXPOSE 3000
7
+ CMD ["bun", "run", "start"]
@@ -0,0 +1,28 @@
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
+ ```
12
+
13
+ ## Provider server contract
14
+
15
+ - Dev default: `3900`
16
+ - Start/Docker/container contract: `3000`
17
+ - `GET /health`
18
+ - `POST /v1/{operation}`
19
+ - `POST /auth/start`
20
+ - `POST /auth/continue`
21
+ - `POST /auth/poll`
22
+ - `POST /auth/disconnect`
23
+
24
+ ## Next steps
25
+
26
+ 1. Replace the sample `ping` operation with real upstream logic.
27
+ 2. Record a real fixture with `bun run record:sample` or a provider-specific equivalent.
28
+ 3. Extend tests and operation metadata until the provider is bounty-ready.
@@ -0,0 +1,5 @@
1
+ import { startDevServer } from "@apifuse/provider-sdk";
2
+
3
+ import provider from "./index";
4
+
5
+ startDevServer(provider, { port: Number(process.env.PORT) || 3900 });
@@ -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,54 @@
1
+ import { defineProvider, z } from "@apifuse/provider-sdk";
2
+
3
+ const InputSchema = z
4
+ .object({
5
+ value: z
6
+ .string()
7
+ .default("hello")
8
+ .describe("Sample input value used to verify the generated provider scaffold is wired correctly."),
9
+ })
10
+ .describe("Input payload for the generated ping operation.");
11
+
12
+ const OutputSchema = z
13
+ .object({
14
+ ok: z
15
+ .boolean()
16
+ .describe("Whether the generated provider handled the sample request successfully."),
17
+ message: z
18
+ .string()
19
+ .describe("Human-readable confirmation that the generated provider round-tripped the sample payload."),
20
+ })
21
+ .describe("Output payload returned by the generated ping operation.");
22
+
23
+ export default defineProvider({
24
+ id: "{{PROVIDER_ID}}",
25
+ version: "1.0.0",
26
+ runtime: "{{RUNTIME}}"{{BROWSER_BLOCK}},
27
+ allowedHosts: ["api.example.com"],
28
+ reviewed: "community",
29
+ {{SECRETS_BLOCK}}{{CREDENTIAL_BLOCK}}auth: {{AUTH_BLOCK}},
30
+ meta: {
31
+ displayName: "{{DISPLAY_NAME}}",
32
+ description: "{{DISPLAY_NAME}} provider starter for ApiFuse community contributions.",
33
+ category: "{{CATEGORY}}",
34
+ tags: ["{{PROVIDER_ID}}", "starter", "community"],
35
+ },
36
+ operations: {
37
+ ping: {
38
+ description:
39
+ "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.",
40
+ input: InputSchema,
41
+ output: OutputSchema,
42
+ handler: async (_ctx, input) => {
43
+ return {
44
+ ok: true,
45
+ message: "{{DISPLAY_NAME}} received: " + input.value,
46
+ };
47
+ },
48
+ fixtures: {
49
+ request: { value: "hello" },
50
+ response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
51
+ },
52
+ },
53
+ },
54
+ });
@@ -0,0 +1,5 @@
1
+ import { serve } from "@apifuse/provider-sdk";
2
+
3
+ import provider from "./index";
4
+
5
+ await serve(provider, { port: Number(process.env.PORT) || 3000 });
@@ -0,0 +1,43 @@
1
+ import type { infer as ZodInfer, ZodType } from "zod";
2
+
3
+ export interface ClarifyResponse {
4
+ _type: "clarify";
5
+ question: string;
6
+ missing: Array<{ name: string; description: string }>;
7
+ }
8
+
9
+ export interface CompositeContext {
10
+ chain: {
11
+ call: <T>(operationKey: string, params: unknown) => Promise<T>;
12
+ };
13
+ clarify: (opts: {
14
+ question: string;
15
+ missing: Array<{ name: string; description: string }>;
16
+ }) => ClarifyResponse;
17
+ setSlot: (name: string, value: unknown) => void;
18
+ }
19
+
20
+ export interface CompositeOperationDefinition<
21
+ TInput extends ZodType = ZodType,
22
+ TOutput extends ZodType = ZodType,
23
+ > {
24
+ id: string;
25
+ description: string;
26
+ input: TInput;
27
+ output: TOutput;
28
+ tags?: string[];
29
+ chainsWith?: string[];
30
+ steps: (
31
+ ctx: CompositeContext,
32
+ input: ZodInfer<TInput>,
33
+ ) => Promise<ZodInfer<TOutput> | ClarifyResponse>;
34
+ }
35
+
36
+ export function defineCompositeOperation<
37
+ TInput extends ZodType,
38
+ TOutput extends ZodType,
39
+ >(
40
+ config: CompositeOperationDefinition<TInput, TOutput>,
41
+ ): CompositeOperationDefinition<TInput, TOutput> {
42
+ return config;
43
+ }