@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.
- package/AUTHORING.md +102 -0
- package/CHANGELOG.md +14 -0
- package/README.md +100 -28
- package/bin/apifuse-check.ts +78 -71
- package/bin/apifuse-create.ts +12 -0
- package/bin/apifuse-dev.ts +24 -61
- package/bin/apifuse-pack-check.ts +47 -0
- package/bin/apifuse-perf.ts +33 -32
- package/bin/apifuse-record.ts +17 -7
- package/bin/apifuse-test.ts +6 -4
- package/bin/apifuse.ts +36 -35
- package/package.json +28 -9
- package/src/ceremonies/index.ts +747 -0
- package/src/cli/commands.ts +87 -0
- package/src/cli/create.ts +845 -0
- package/src/cli/templates/provider/Dockerfile.tpl +7 -0
- package/src/cli/templates/provider/README.md.tpl +28 -0
- package/src/cli/templates/provider/dev.ts.tpl +5 -0
- package/src/cli/templates/provider/index.test.ts.tpl +13 -0
- package/src/cli/templates/provider/index.ts.tpl +54 -0
- package/src/cli/templates/provider/start.ts.tpl +5 -0
- package/src/composite.ts +43 -0
- package/src/define.ts +527 -41
- package/src/dev.ts +2 -6
- package/src/errors.ts +42 -0
- package/src/index.ts +50 -38
- package/src/lint.ts +574 -0
- package/src/provider.ts +14 -0
- package/src/runtime/auth-flow.ts +67 -0
- package/src/runtime/credential.ts +95 -0
- package/src/runtime/env.ts +13 -0
- package/src/runtime/executor.ts +13 -14
- package/src/runtime/http.ts +10 -2
- package/src/runtime/insights.ts +3 -3
- package/src/runtime/key-derivation.ts +122 -0
- package/src/runtime/keyring.ts +148 -0
- package/src/runtime/namespace.ts +33 -0
- package/src/runtime/prevalidate.ts +252 -0
- package/src/runtime/tls.ts +20 -5
- package/src/runtime/waterfall.ts +0 -1
- package/src/schema.ts +77 -0
- package/src/serve.ts +1 -664
- package/src/server/index.ts +22 -0
- package/src/server/serve.ts +610 -0
- package/src/server/types.ts +78 -0
- package/src/stealth/profiles.ts +10 -93
- package/src/testing/run.ts +391 -32
- package/src/types.ts +364 -41
- package/bin/apifuse-init.ts +0 -387
- package/src/__tests__/auth.test.ts +0 -396
- package/src/__tests__/browser-auth.test.ts +0 -180
- package/src/__tests__/browser.test.ts +0 -632
- package/src/__tests__/define.test.ts +0 -225
- package/src/__tests__/errors.test.ts +0 -69
- package/src/__tests__/executor.test.ts +0 -214
- package/src/__tests__/http.test.ts +0 -238
- package/src/__tests__/insights.test.ts +0 -210
- package/src/__tests__/instrumentation.test.ts +0 -290
- package/src/__tests__/otlp.test.ts +0 -141
- package/src/__tests__/perf.test.ts +0 -60
- package/src/__tests__/providers-yaml.test.ts +0 -135
- package/src/__tests__/proxy.test.ts +0 -359
- package/src/__tests__/recipes.test.ts +0 -36
- package/src/__tests__/serve.test.ts +0 -233
- package/src/__tests__/session.test.ts +0 -231
- package/src/__tests__/state.test.ts +0 -100
- package/src/__tests__/stealth.test.ts +0 -57
- package/src/__tests__/testing.test.ts +0 -97
- package/src/__tests__/tls.test.ts +0 -345
- package/src/__tests__/types.test.ts +0 -142
- package/src/__tests__/utils.test.ts +0 -62
- package/src/__tests__/waterfall.test.ts +0 -270
- package/src/config/providers-yaml.ts +0 -370
- package/src/index.test.ts +0 -1
- package/src/protocol.ts +0 -183
- package/src/runtime/auth.ts +0 -245
- package/src/runtime/session.ts +0 -573
- package/src/runtime/state.ts +0 -124
|
@@ -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,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
|
+
});
|
package/src/composite.ts
ADDED
|
@@ -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
|
+
}
|