@apifuse/provider-sdk 2.1.0-beta.1 → 2.1.0-beta.10
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 +208 -2
- package/CHANGELOG.md +47 -0
- package/README.md +114 -10
- package/SUBMISSION.md +87 -0
- package/bin/apifuse-check.ts +86 -4
- package/bin/apifuse-dev.ts +87 -13
- package/bin/apifuse-pack-check.ts +80 -0
- package/bin/apifuse-pack-smoke.ts +303 -2
- package/bin/apifuse-perf.ts +142 -49
- package/bin/apifuse-record.ts +182 -104
- package/bin/apifuse-submit-check.ts +2538 -0
- package/bin/apifuse.ts +1 -1
- package/dist/ceremonies/index.d.ts +41 -0
- package/dist/ceremonies/index.js +490 -0
- package/dist/choice-token.d.ts +24 -0
- package/dist/choice-token.js +74 -0
- package/dist/cli/commands.d.ts +10 -0
- package/dist/cli/commands.js +80 -0
- package/dist/cli/create.d.ts +47 -0
- package/dist/cli/create.js +762 -0
- package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
- package/dist/cli/templates/provider/.gitignore.tpl +22 -0
- package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
- package/dist/cli/templates/provider/README.md.tpl +160 -0
- package/dist/cli/templates/provider/dev.ts.tpl +5 -0
- package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
- package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
- package/dist/cli/templates/provider/index.ts.tpl +15 -0
- package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/dist/cli/templates/provider/meta.ts.tpl +7 -0
- package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/start.ts.tpl +5 -0
- package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/dist/config/loader.d.ts +107 -0
- package/dist/config/loader.js +935 -0
- package/dist/contract-json.d.ts +9 -0
- package/dist/contract-json.js +51 -0
- package/dist/contract-serialization.d.ts +4 -0
- package/dist/contract-serialization.js +78 -0
- package/dist/contract-types.d.ts +49 -0
- package/dist/contract-types.js +1 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +155 -0
- package/dist/define.d.ts +97 -0
- package/dist/define.js +1320 -0
- package/dist/dev.d.ts +9 -0
- package/dist/dev.js +15 -0
- package/dist/errors.d.ts +59 -0
- package/dist/errors.js +97 -0
- package/dist/i18n/catalog.d.ts +29 -0
- package/dist/i18n/catalog.js +159 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/keys.d.ts +10 -0
- package/dist/i18n/keys.js +34 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +37 -0
- package/dist/lint.d.ts +73 -0
- package/dist/lint.js +702 -0
- package/dist/observability.d.ts +5 -0
- package/dist/observability.js +39 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +8 -0
- package/dist/public-schema-field-lint.d.ts +2 -0
- package/dist/public-schema-field-lint.js +158 -0
- package/dist/recipes/gov-api.d.ts +19 -0
- package/dist/recipes/gov-api.js +72 -0
- package/dist/recipes/rest-api.d.ts +21 -0
- package/dist/recipes/rest-api.js +115 -0
- package/dist/runtime/auth-flow.d.ts +14 -0
- package/dist/runtime/auth-flow.js +44 -0
- package/dist/runtime/browser.d.ts +25 -0
- package/dist/runtime/browser.js +1034 -0
- package/dist/runtime/cache.d.ts +10 -0
- package/dist/runtime/cache.js +372 -0
- package/dist/runtime/choice.d.ts +15 -0
- package/dist/runtime/choice.js +435 -0
- package/dist/runtime/credential.d.ts +8 -0
- package/dist/runtime/credential.js +61 -0
- package/dist/runtime/env.d.ts +2 -0
- package/dist/runtime/env.js +10 -0
- package/dist/runtime/executor.d.ts +16 -0
- package/dist/runtime/executor.js +51 -0
- package/dist/runtime/http.d.ts +8 -0
- package/dist/runtime/http.js +706 -0
- package/dist/runtime/insights.d.ts +9 -0
- package/dist/runtime/insights.js +324 -0
- package/dist/runtime/instrumentation.d.ts +8 -0
- package/dist/runtime/instrumentation.js +269 -0
- package/dist/runtime/key-derivation.d.ts +24 -0
- package/dist/runtime/key-derivation.js +73 -0
- package/dist/runtime/keyring.d.ts +25 -0
- package/dist/runtime/keyring.js +93 -0
- package/dist/runtime/namespace.d.ts +9 -0
- package/dist/runtime/namespace.js +19 -0
- package/dist/runtime/otlp.d.ts +39 -0
- package/dist/runtime/otlp.js +103 -0
- package/dist/runtime/perf.d.ts +12 -0
- package/dist/runtime/perf.js +52 -0
- package/dist/runtime/prevalidate.d.ts +12 -0
- package/dist/runtime/prevalidate.js +173 -0
- package/dist/runtime/provider.d.ts +2 -0
- package/dist/runtime/provider.js +11 -0
- package/dist/runtime/proxy-errors.d.ts +21 -0
- package/dist/runtime/proxy-errors.js +83 -0
- package/dist/runtime/proxy-telemetry.d.ts +8 -0
- package/dist/runtime/proxy-telemetry.js +174 -0
- package/dist/runtime/redis.d.ts +17 -0
- package/dist/runtime/redis.js +82 -0
- package/dist/runtime/request-options.d.ts +3 -0
- package/dist/runtime/request-options.js +42 -0
- package/dist/runtime/state.d.ts +17 -0
- package/dist/runtime/state.js +344 -0
- package/dist/runtime/stealth.d.ts +18 -0
- package/dist/runtime/stealth.js +834 -0
- package/dist/runtime/stt.d.ts +22 -0
- package/dist/runtime/stt.js +480 -0
- package/dist/runtime/trace.d.ts +26 -0
- package/dist/runtime/trace.js +142 -0
- package/dist/runtime/waterfall.d.ts +12 -0
- package/dist/runtime/waterfall.js +147 -0
- package/dist/schema.d.ts +74 -0
- package/dist/schema.js +243 -0
- package/dist/serve.d.ts +1 -0
- package/dist/serve.js +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/serve.d.ts +64 -0
- package/dist/server/serve.js +1110 -0
- package/dist/server/types.d.ts +136 -0
- package/dist/server/types.js +86 -0
- package/dist/stealth/profiles.d.ts +4 -0
- package/dist/stealth/profiles.js +259 -0
- package/dist/stream.d.ts +44 -0
- package/dist/stream.js +151 -0
- package/dist/testing/helpers.d.ts +23 -0
- package/dist/testing/helpers.js +95 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/run.d.ts +34 -0
- package/dist/testing/run.js +303 -0
- package/dist/types.d.ts +1326 -0
- package/dist/types.js +61 -0
- package/dist/utils/date.d.ts +6 -0
- package/dist/utils/date.js +101 -0
- package/dist/utils/parse.d.ts +16 -0
- package/dist/utils/parse.js +51 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +14 -0
- package/dist/utils/transform.d.ts +8 -0
- package/dist/utils/transform.js +48 -0
- package/package.json +57 -30
- package/src/ceremonies/index.ts +8 -2
- package/src/choice-token.ts +165 -0
- package/src/cli/commands.ts +34 -11
- package/src/cli/create.ts +214 -52
- package/src/cli/templates/provider/.dockerignore.tpl +22 -0
- package/src/cli/templates/provider/.gitignore.tpl +22 -0
- package/src/cli/templates/provider/README.md.tpl +120 -1
- 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 -48
- 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 +24 -0
- package/src/cli/templates/provider/schemas/ping.ts.tpl +24 -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 +1224 -9
- package/src/contract-json.ts +75 -0
- package/src/contract-serialization.ts +89 -0
- package/src/contract-types.ts +52 -0
- package/src/contract.ts +215 -0
- package/src/define.ts +1688 -48
- package/src/errors.ts +27 -0
- package/src/i18n/catalog.ts +277 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/keys.ts +64 -0
- package/src/index.ts +174 -9
- package/src/lint.ts +547 -73
- package/src/observability.ts +41 -0
- package/src/provider.ts +104 -4
- package/src/public-schema-field-lint.ts +237 -0
- package/src/runtime/auth-flow.ts +7 -0
- package/src/runtime/browser.ts +762 -51
- package/src/runtime/cache.ts +528 -0
- package/src/runtime/choice.ts +760 -0
- package/src/runtime/executor.ts +32 -3
- 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/redis.ts +116 -0
- package/src/runtime/request-options.ts +66 -0
- package/src/runtime/state.ts +563 -0
- package/src/runtime/stealth.ts +1159 -0
- package/src/runtime/stt.ts +629 -0
- package/src/runtime/trace.ts +1 -1
- package/src/schema.ts +363 -1
- package/src/server/serve.ts +1157 -75
- package/src/server/types.ts +37 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +31 -5
- package/src/types.ts +1107 -59
- package/src/runtime/tls.ts +0 -434
- package/src/types/playwright-stealth.d.ts +0 -9
package/src/cli/commands.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type ApifuseCommandName =
|
|
|
2
2
|
| "create"
|
|
3
3
|
| "dev"
|
|
4
4
|
| "check"
|
|
5
|
+
| "submit-check"
|
|
6
|
+
| "bounty-check"
|
|
5
7
|
| "record"
|
|
6
8
|
| "test"
|
|
7
9
|
| "perf";
|
|
@@ -22,11 +24,9 @@ export const COMMAND_MANIFEST: Record<
|
|
|
22
24
|
name: "create",
|
|
23
25
|
summary:
|
|
24
26
|
"Scaffold a provider, install dependencies, run baseline validation, and print the next local-dev command.",
|
|
25
|
-
usage:
|
|
26
|
-
"apifuse create <provider-name> [--preset standalone|monorepo] [--json] [--dry-run]",
|
|
27
|
+
usage: "apifuse create <provider-name> [--json] [--dry-run]",
|
|
27
28
|
examples: [
|
|
28
29
|
"apifuse create weather-provider",
|
|
29
|
-
"apifuse create weather-provider --preset monorepo",
|
|
30
30
|
"apifuse create --config ./apifuse.create.json --json",
|
|
31
31
|
],
|
|
32
32
|
modulePath: "./apifuse-create",
|
|
@@ -36,24 +36,43 @@ export const COMMAND_MANIFEST: Record<
|
|
|
36
36
|
summary:
|
|
37
37
|
"Start the local provider dev server with the standard provider server contract.",
|
|
38
38
|
usage: "apifuse dev [path]",
|
|
39
|
-
examples: ["apifuse dev .", "apifuse dev providers/
|
|
39
|
+
examples: ["apifuse dev .", "apifuse dev providers/korea-air-quality"],
|
|
40
40
|
modulePath: "./apifuse-dev",
|
|
41
41
|
},
|
|
42
42
|
check: {
|
|
43
43
|
name: "check",
|
|
44
44
|
summary: "Validate provider structure, metadata, fixtures, and schemas.",
|
|
45
45
|
usage: "apifuse check [path]",
|
|
46
|
-
examples: ["apifuse check .", "apifuse check providers/
|
|
46
|
+
examples: ["apifuse check .", "apifuse check providers/korea-air-quality"],
|
|
47
47
|
modulePath: "./apifuse-check",
|
|
48
48
|
},
|
|
49
|
+
"submit-check": {
|
|
50
|
+
name: "submit-check",
|
|
51
|
+
summary:
|
|
52
|
+
"Score provider bounty submission readiness and emit checklist evidence.",
|
|
53
|
+
usage:
|
|
54
|
+
"apifuse submit-check [path] [--tier bronze|silver|gold|diamond] [--json] [--markdown <path>] [--smoke-note <text>]",
|
|
55
|
+
examples: [
|
|
56
|
+
"apifuse submit-check .",
|
|
57
|
+
"apifuse submit-check . --tier silver --markdown submission-report.md",
|
|
58
|
+
],
|
|
59
|
+
modulePath: "./apifuse-submit-check",
|
|
60
|
+
},
|
|
61
|
+
"bounty-check": {
|
|
62
|
+
name: "bounty-check",
|
|
63
|
+
summary: "Alias for submit-check.",
|
|
64
|
+
usage:
|
|
65
|
+
"apifuse bounty-check [path] [--tier bronze|silver|gold|diamond] [--json] [--markdown <path>] [--smoke-note <text>]",
|
|
66
|
+
examples: ["apifuse bounty-check . --markdown submission-report.md"],
|
|
67
|
+
modulePath: "./apifuse-submit-check",
|
|
68
|
+
},
|
|
49
69
|
record: {
|
|
50
70
|
name: "record",
|
|
51
71
|
summary: "Call a provider operation and capture upstream raw fixture data.",
|
|
52
72
|
usage:
|
|
53
73
|
'apifuse record [path] --operation <operation> --params \'{"value":"hello"}\'',
|
|
54
74
|
examples: [
|
|
55
|
-
'apifuse record
|
|
56
|
-
'apifuse record providers/airkorea --operation realtime --params \'{"stationName":"종로구"}\'',
|
|
75
|
+
'apifuse record providers/korea-air-quality --operation realtime --params \'{"stationName":"종로구"}\'',
|
|
57
76
|
],
|
|
58
77
|
modulePath: "./apifuse-record",
|
|
59
78
|
},
|
|
@@ -61,17 +80,20 @@ export const COMMAND_MANIFEST: Record<
|
|
|
61
80
|
name: "test",
|
|
62
81
|
summary: "Run provider-focused tests and surface actionable failures.",
|
|
63
82
|
usage: "apifuse test [path] [--json] [--verbose]",
|
|
64
|
-
examples: [
|
|
83
|
+
examples: [
|
|
84
|
+
"apifuse test .",
|
|
85
|
+
"apifuse test providers/korea-air-quality --json",
|
|
86
|
+
],
|
|
65
87
|
modulePath: "./apifuse-test",
|
|
66
88
|
},
|
|
67
89
|
perf: {
|
|
68
90
|
name: "perf",
|
|
69
91
|
summary:
|
|
70
92
|
"Profile a provider operation and export latency/trace diagnostics.",
|
|
71
|
-
usage:
|
|
93
|
+
usage:
|
|
94
|
+
"apifuse perf <path> --operation <operation> [--params '<json>'] [options]",
|
|
72
95
|
examples: [
|
|
73
|
-
|
|
74
|
-
"apifuse perf providers/airkorea --operation realtime --runs 5",
|
|
96
|
+
'apifuse perf providers/korea-air-quality --operation realtime --params \'{"stationName":"종로구"}\' --runs 5',
|
|
75
97
|
],
|
|
76
98
|
modulePath: "./apifuse-perf",
|
|
77
99
|
},
|
|
@@ -81,6 +103,7 @@ export const COMMAND_ORDER: ApifuseCommandName[] = [
|
|
|
81
103
|
"create",
|
|
82
104
|
"dev",
|
|
83
105
|
"check",
|
|
106
|
+
"submit-check",
|
|
84
107
|
"record",
|
|
85
108
|
"test",
|
|
86
109
|
"perf",
|
package/src/cli/create.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -101,11 +101,9 @@ const TEMPLATE_DIR = fileURLToPath(
|
|
|
101
101
|
const HELP_TEXT = `Usage: apifuse create <provider-name> [options]
|
|
102
102
|
Examples:
|
|
103
103
|
apifuse create my-provider
|
|
104
|
-
apifuse create my-provider --preset monorepo
|
|
105
104
|
apifuse create --config ./apifuse.create.json --json
|
|
106
105
|
|
|
107
106
|
Options:
|
|
108
|
-
--preset <standalone|monorepo>
|
|
109
107
|
--config <path>
|
|
110
108
|
--output-dir <path>
|
|
111
109
|
--display-name <name>
|
|
@@ -115,7 +113,7 @@ Options:
|
|
|
115
113
|
--yes
|
|
116
114
|
--dry-run
|
|
117
115
|
--json
|
|
118
|
-
--sdk-specifier <specifier> # internal/testing override for
|
|
116
|
+
--sdk-specifier <specifier> # internal/testing override for dependency resolution
|
|
119
117
|
--help, -h`;
|
|
120
118
|
|
|
121
119
|
export async function main() {
|
|
@@ -273,14 +271,11 @@ async function resolveCreateOptions(
|
|
|
273
271
|
config: CreateConfigFile | undefined,
|
|
274
272
|
cwd: string,
|
|
275
273
|
): Promise<CreateResolvedOptions> {
|
|
276
|
-
const
|
|
277
|
-
const detectedPreset: CreatePreset = detectedWorkspaceRoot
|
|
278
|
-
? "monorepo"
|
|
279
|
-
: "standalone";
|
|
274
|
+
const internalWorkspaceRoot = findApifuseInternalWorkspaceRoot(cwd);
|
|
280
275
|
|
|
281
276
|
const partial: Partial<CreateResolvedOptions> = {
|
|
282
277
|
name: parsed.name ?? config?.name,
|
|
283
|
-
preset: parsed.preset ?? config?.preset ??
|
|
278
|
+
preset: parsed.preset ?? config?.preset ?? "standalone",
|
|
284
279
|
outputDir: parsed.outputDir ?? config?.outputDir,
|
|
285
280
|
displayName: parsed.displayName ?? config?.displayName,
|
|
286
281
|
category: parsed.category ?? config?.category,
|
|
@@ -289,15 +284,15 @@ async function resolveCreateOptions(
|
|
|
289
284
|
sdkSpecifier:
|
|
290
285
|
parsed.sdkSpecifier ??
|
|
291
286
|
config?.sdkSpecifier ??
|
|
292
|
-
process.env.
|
|
287
|
+
process.env.APIFUSE__SDK__SPECIFIER,
|
|
293
288
|
dryRun: parsed.dryRun,
|
|
294
289
|
json: parsed.json,
|
|
295
290
|
yes: parsed.yes,
|
|
296
291
|
};
|
|
297
292
|
|
|
298
|
-
if (partial.preset === "monorepo" && !
|
|
293
|
+
if (partial.preset === "monorepo" && !internalWorkspaceRoot) {
|
|
299
294
|
throw new Error(
|
|
300
|
-
"Monorepo preset
|
|
295
|
+
"Monorepo preset is internal to the APIFuse repository. External bounty workspaces are one-provider repositories; use the standalone default create flow.",
|
|
301
296
|
);
|
|
302
297
|
}
|
|
303
298
|
|
|
@@ -314,7 +309,7 @@ async function resolveCreateOptions(
|
|
|
314
309
|
category: partial.category ?? "other",
|
|
315
310
|
authMode: partial.authMode ?? "none",
|
|
316
311
|
runtime: partial.runtime ?? "standard",
|
|
317
|
-
preset: partial.preset ??
|
|
312
|
+
preset: partial.preset ?? "standalone",
|
|
318
313
|
outputDir: partial.outputDir,
|
|
319
314
|
dryRun: partial.dryRun ?? false,
|
|
320
315
|
json: partial.json ?? false,
|
|
@@ -324,10 +319,10 @@ async function resolveCreateOptions(
|
|
|
324
319
|
}
|
|
325
320
|
|
|
326
321
|
if (!partial.json) {
|
|
327
|
-
intro("Create a new
|
|
322
|
+
intro("Create a new APIFuse provider");
|
|
328
323
|
note(
|
|
329
|
-
|
|
330
|
-
"
|
|
324
|
+
"External bounty workspaces are one-provider repositories. The public create flow defaults to standalone.",
|
|
325
|
+
"Provider workspace",
|
|
331
326
|
);
|
|
332
327
|
}
|
|
333
328
|
|
|
@@ -392,22 +387,7 @@ async function resolveCreateOptions(
|
|
|
392
387
|
initialValue: "standard",
|
|
393
388
|
}),
|
|
394
389
|
)),
|
|
395
|
-
preset:
|
|
396
|
-
partial.preset ??
|
|
397
|
-
(await promptValue(
|
|
398
|
-
select({
|
|
399
|
-
message: "Generation preset",
|
|
400
|
-
options: PRESET_OPTIONS.map((value) => ({
|
|
401
|
-
label: value,
|
|
402
|
-
value,
|
|
403
|
-
hint:
|
|
404
|
-
value === "standalone"
|
|
405
|
-
? "Create a clean-room npm-ready provider package."
|
|
406
|
-
: "Create the provider inside the current ApiFuse monorepo.",
|
|
407
|
-
})),
|
|
408
|
-
initialValue: detectedPreset,
|
|
409
|
-
}),
|
|
410
|
-
)),
|
|
390
|
+
preset: partial.preset ?? "standalone",
|
|
411
391
|
outputDir: partial.outputDir,
|
|
412
392
|
dryRun: partial.dryRun ?? false,
|
|
413
393
|
json: partial.json ?? false,
|
|
@@ -429,15 +409,15 @@ export async function buildProviderCreatePlan(
|
|
|
429
409
|
options: CreateResolvedOptions,
|
|
430
410
|
cwd: string,
|
|
431
411
|
): Promise<ProviderCreatePlan> {
|
|
432
|
-
const
|
|
433
|
-
options.preset === "monorepo"
|
|
434
|
-
|
|
412
|
+
const resolvedWorkspaceRoot =
|
|
413
|
+
options.preset === "monorepo"
|
|
414
|
+
? findApifuseInternalWorkspaceRoot(cwd)
|
|
415
|
+
: undefined;
|
|
416
|
+
if (options.preset === "monorepo" && !resolvedWorkspaceRoot) {
|
|
435
417
|
throw new Error(
|
|
436
|
-
"Monorepo preset
|
|
418
|
+
"Monorepo preset is internal to the APIFuse repository. External bounty workspaces are one-provider repositories; use the standalone default create flow.",
|
|
437
419
|
);
|
|
438
420
|
}
|
|
439
|
-
const resolvedWorkspaceRoot =
|
|
440
|
-
options.preset === "monorepo" ? workspaceRoot : undefined;
|
|
441
421
|
let providerRoot: string;
|
|
442
422
|
let installCwd: string;
|
|
443
423
|
|
|
@@ -459,33 +439,104 @@ export async function buildProviderCreatePlan(
|
|
|
459
439
|
throw new Error(`Target directory already exists: ${providerRoot}`);
|
|
460
440
|
}
|
|
461
441
|
|
|
442
|
+
if (
|
|
443
|
+
options.sdkSpecifier?.startsWith("workspace:") &&
|
|
444
|
+
!resolvedWorkspaceRoot
|
|
445
|
+
) {
|
|
446
|
+
throw new Error(
|
|
447
|
+
"workspace:* is only valid inside the APIFuse monorepo because public Provider SDK scaffolds must install from npm or an explicit tarball/file specifier.",
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
462
451
|
const sdkSpecifier =
|
|
463
452
|
options.sdkSpecifier ??
|
|
464
|
-
(options.preset === "monorepo"
|
|
453
|
+
(options.preset === "monorepo" && resolvedWorkspaceRoot
|
|
454
|
+
? "workspace:*"
|
|
455
|
+
: `^${packageJson.version}`);
|
|
465
456
|
const relativeProviderRoot = relative(cwd, providerRoot) || options.name;
|
|
466
457
|
const nextDevCommand = `cd ${relativeProviderRoot} && bun run dev`;
|
|
467
458
|
const packageName =
|
|
468
459
|
options.preset === "monorepo"
|
|
469
460
|
? `@apifuse/provider-${options.name}`
|
|
470
461
|
: `apifuse-provider-${options.name}`;
|
|
462
|
+
const templateValues = {
|
|
463
|
+
PROVIDER_ID: options.name,
|
|
464
|
+
DISPLAY_NAME: escapeTemplate(options.displayName),
|
|
465
|
+
CATEGORY: options.category,
|
|
466
|
+
RUNTIME: options.runtime,
|
|
467
|
+
BROWSER_BLOCK:
|
|
468
|
+
options.runtime === "browser"
|
|
469
|
+
? ',\n browser: {\n engine: "playwright-stealth",\n }'
|
|
470
|
+
: "",
|
|
471
|
+
SECRETS_BLOCK: renderSecretsBlock(options.authMode),
|
|
472
|
+
CREDENTIAL_BLOCK: renderCredentialBlock(options.authMode),
|
|
473
|
+
AUTH_BLOCK: renderAuthBlock(options.authMode),
|
|
474
|
+
};
|
|
471
475
|
|
|
472
476
|
const files: ProviderPlanFile[] = [
|
|
477
|
+
{
|
|
478
|
+
path: resolve(providerRoot, ".dockerignore"),
|
|
479
|
+
content: await renderTemplate(".dockerignore.tpl", {}),
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
path: resolve(providerRoot, ".gitignore"),
|
|
483
|
+
content: await renderTemplate(".gitignore.tpl", {}),
|
|
484
|
+
},
|
|
473
485
|
{
|
|
474
486
|
path: resolve(providerRoot, "index.ts"),
|
|
475
|
-
content: await renderTemplate("index.ts.tpl",
|
|
487
|
+
content: await renderTemplate("index.ts.tpl", templateValues),
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
path: resolve(providerRoot, "meta.ts"),
|
|
491
|
+
content: await renderTemplate("meta.ts.tpl", {
|
|
476
492
|
PROVIDER_ID: options.name,
|
|
477
493
|
DISPLAY_NAME: escapeTemplate(options.displayName),
|
|
478
494
|
CATEGORY: options.category,
|
|
479
|
-
|
|
480
|
-
|
|
495
|
+
}),
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
path: resolve(providerRoot, "operations", "index.ts"),
|
|
499
|
+
content: await renderTemplate("operations/index.ts.tpl", {}),
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
path: resolve(providerRoot, "operations", "ping.ts"),
|
|
503
|
+
content: await renderTemplate("operations/ping.ts.tpl", {
|
|
504
|
+
DISPLAY_NAME: escapeTemplate(options.displayName),
|
|
505
|
+
HANDLER_CTX: options.runtime === "browser" ? "ctx" : "_ctx",
|
|
506
|
+
BROWSER_HANDLER_BLOCK:
|
|
481
507
|
options.runtime === "browser"
|
|
482
|
-
? '
|
|
508
|
+
? '\n const page = await ctx.browser.newPage();\n await page.goto("https://example.com");\n const title = await page.title();\n const frames = await page.frames();\n await page.close();\n'
|
|
509
|
+
: "",
|
|
510
|
+
BROWSER_RESPONSE_FIELDS:
|
|
511
|
+
options.runtime === "browser"
|
|
512
|
+
? ",\n pageTitle: title,\n frameCount: frames.length"
|
|
483
513
|
: "",
|
|
484
|
-
SECRETS_BLOCK: renderSecretsBlock(options.authMode),
|
|
485
|
-
CREDENTIAL_BLOCK: renderCredentialBlock(options.authMode),
|
|
486
|
-
AUTH_BLOCK: renderAuthBlock(options.authMode),
|
|
487
514
|
}),
|
|
488
515
|
},
|
|
516
|
+
{
|
|
517
|
+
path: resolve(providerRoot, "schemas", "ping.ts"),
|
|
518
|
+
content: await renderTemplate("schemas/ping.ts.tpl", {}),
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
path: resolve(providerRoot, "upstream", "README.md"),
|
|
522
|
+
content: await renderTemplate("upstream/README.md.tpl", {}),
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
path: resolve(providerRoot, "mappers", "README.md"),
|
|
526
|
+
content: await renderTemplate("mappers/README.md.tpl", {}),
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
path: resolve(providerRoot, "domain", "README.md"),
|
|
530
|
+
content: await renderTemplate("domain/README.md.tpl", {}),
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
path: resolve(providerRoot, "locales", "en.json"),
|
|
534
|
+
content: renderStarterLocaleCatalog(options.displayName, "en"),
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
path: resolve(providerRoot, "locales", "ko.json"),
|
|
538
|
+
content: renderStarterLocaleCatalog(options.displayName, "ko"),
|
|
539
|
+
},
|
|
489
540
|
{
|
|
490
541
|
path: resolve(providerRoot, "package.json"),
|
|
491
542
|
content: renderPackageJson({
|
|
@@ -538,7 +589,12 @@ export async function buildProviderCreatePlan(
|
|
|
538
589
|
packageName,
|
|
539
590
|
preset: options.preset,
|
|
540
591
|
providerRoot,
|
|
541
|
-
validationCommands: [
|
|
592
|
+
validationCommands: [
|
|
593
|
+
"bun run check",
|
|
594
|
+
"bun run type-check",
|
|
595
|
+
"bun run submit-check",
|
|
596
|
+
"bun run test",
|
|
597
|
+
],
|
|
542
598
|
workspaceRoot: resolvedWorkspaceRoot,
|
|
543
599
|
};
|
|
544
600
|
}
|
|
@@ -567,10 +623,12 @@ function renderPackageJson(input: {
|
|
|
567
623
|
main: "./index.ts",
|
|
568
624
|
scripts: {
|
|
569
625
|
dev: "apifuse dev .",
|
|
570
|
-
check: "apifuse check .",
|
|
571
|
-
"
|
|
572
|
-
|
|
626
|
+
check: "apifuse check . && bun run type-check",
|
|
627
|
+
"type-check": "tsc --noEmit",
|
|
628
|
+
"submit-check":
|
|
629
|
+
"apifuse submit-check . --markdown submission-report.md",
|
|
573
630
|
test: "apifuse test .",
|
|
631
|
+
record: "apifuse record .",
|
|
574
632
|
"perf:sample": "apifuse perf . --operation ping --runs 3",
|
|
575
633
|
start: "bun start.ts",
|
|
576
634
|
},
|
|
@@ -579,6 +637,7 @@ function renderPackageJson(input: {
|
|
|
579
637
|
},
|
|
580
638
|
devDependencies: {
|
|
581
639
|
"@types/bun": "latest",
|
|
640
|
+
typescript: "^6.0.3",
|
|
582
641
|
},
|
|
583
642
|
},
|
|
584
643
|
null,
|
|
@@ -597,6 +656,7 @@ function renderTsconfig(): string {
|
|
|
597
656
|
noEmit: true,
|
|
598
657
|
skipLibCheck: true,
|
|
599
658
|
resolveJsonModule: true,
|
|
659
|
+
types: ["bun"],
|
|
600
660
|
},
|
|
601
661
|
include: ["**/*.ts"],
|
|
602
662
|
exclude: ["node_modules"],
|
|
@@ -606,6 +666,64 @@ function renderTsconfig(): string {
|
|
|
606
666
|
)}\n`;
|
|
607
667
|
}
|
|
608
668
|
|
|
669
|
+
function renderStarterLocaleCatalog(
|
|
670
|
+
displayName: string,
|
|
671
|
+
locale: "en" | "ko",
|
|
672
|
+
): string {
|
|
673
|
+
const catalog = {
|
|
674
|
+
meta: {
|
|
675
|
+
displayName,
|
|
676
|
+
description:
|
|
677
|
+
locale === "ko"
|
|
678
|
+
? `${displayName} APIFuse 커뮤니티 기여용 provider starter입니다.`
|
|
679
|
+
: `${displayName} provider starter for APIFuse community contributions.`,
|
|
680
|
+
},
|
|
681
|
+
operations: {
|
|
682
|
+
ping: {
|
|
683
|
+
description:
|
|
684
|
+
locale === "ko"
|
|
685
|
+
? "생성된 provider wiring이 APIFuse runtime contract를 통해 작은 샘플 payload를 정상적으로 round-trip하는지 확인합니다. 로컬 개발, baseline check, 첫 bounty scaffold 검증에 사용합니다. production data retrieval이나 upstream-specific workflow에는 사용하지 마세요. 이 starter operation은 생성된 프로젝트가 compile, serve, input/output round-trip을 수행하는지 증명하기 위한 용도입니다."
|
|
686
|
+
: "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.",
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
schemaDescriptions: {
|
|
690
|
+
input: {
|
|
691
|
+
root:
|
|
692
|
+
locale === "ko"
|
|
693
|
+
? "생성된 ping operation의 입력 payload"
|
|
694
|
+
: "Input payload for the generated ping operation.",
|
|
695
|
+
value:
|
|
696
|
+
locale === "ko"
|
|
697
|
+
? "생성된 provider scaffold wiring 검증에 사용하는 샘플 입력값"
|
|
698
|
+
: "Sample input value used to verify the generated provider scaffold is wired correctly.",
|
|
699
|
+
},
|
|
700
|
+
output: {
|
|
701
|
+
root:
|
|
702
|
+
locale === "ko"
|
|
703
|
+
? "생성된 ping operation이 반환하는 출력 payload"
|
|
704
|
+
: "Output payload returned by the generated ping operation.",
|
|
705
|
+
ok:
|
|
706
|
+
locale === "ko"
|
|
707
|
+
? "생성된 provider가 샘플 요청을 성공적으로 처리했는지 여부"
|
|
708
|
+
: "Whether the generated provider handled the sample request successfully.",
|
|
709
|
+
message:
|
|
710
|
+
locale === "ko"
|
|
711
|
+
? "생성된 provider가 샘플 payload를 round-trip했음을 보여주는 사람이 읽을 수 있는 확인 메시지"
|
|
712
|
+
: "Human-readable confirmation that the generated provider round-tripped the sample payload.",
|
|
713
|
+
pageTitle:
|
|
714
|
+
locale === "ko"
|
|
715
|
+
? "browser 런타임 provider일 때 로드된 페이지의 제목 (해당되지 않으면 생략)"
|
|
716
|
+
: "Title of the loaded page when the provider uses the browser runtime; omitted otherwise.",
|
|
717
|
+
frameCount:
|
|
718
|
+
locale === "ko"
|
|
719
|
+
? "browser 런타임 provider일 때 로드된 페이지의 frame 개수 (해당되지 않으면 생략)"
|
|
720
|
+
: "Number of frames in the loaded page when the provider uses the browser runtime; omitted otherwise.",
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
};
|
|
724
|
+
return `${JSON.stringify(catalog, null, 2)}\n`;
|
|
725
|
+
}
|
|
726
|
+
|
|
609
727
|
function renderAuthBlock(authMode: CreateAuthMode): string {
|
|
610
728
|
switch (authMode) {
|
|
611
729
|
case "none":
|
|
@@ -643,6 +761,17 @@ function renderAuthBlock(authMode: CreateAuthMode): string {
|
|
|
643
761
|
},
|
|
644
762
|
hint: "Generated placeholder credential flow completed. Replace this with real auth logic.",
|
|
645
763
|
}),
|
|
764
|
+
refresh: async () => ({
|
|
765
|
+
kind: "complete",
|
|
766
|
+
turnId: crypto.randomUUID(),
|
|
767
|
+
data: {
|
|
768
|
+
credential: {
|
|
769
|
+
username: "replace-with-refreshed-username",
|
|
770
|
+
password: "replace-with-refreshed-password",
|
|
771
|
+
},
|
|
772
|
+
},
|
|
773
|
+
hint: "Return refreshed credential data here, or throw AuthError with code AUTH_REQUIRED when silent refresh is not possible.",
|
|
774
|
+
}),
|
|
646
775
|
},
|
|
647
776
|
}`;
|
|
648
777
|
case "oauth2":
|
|
@@ -714,11 +843,11 @@ export function toDisplayName(name: string): string {
|
|
|
714
843
|
.join(" ");
|
|
715
844
|
}
|
|
716
845
|
|
|
717
|
-
function
|
|
846
|
+
function findApifuseInternalWorkspaceRoot(cwd: string): string | undefined {
|
|
718
847
|
let currentDirectory = cwd;
|
|
719
848
|
|
|
720
849
|
while (true) {
|
|
721
|
-
if (
|
|
850
|
+
if (isApifuseInternalWorkspaceRoot(currentDirectory)) {
|
|
722
851
|
return currentDirectory;
|
|
723
852
|
}
|
|
724
853
|
|
|
@@ -731,6 +860,31 @@ function findWorkspaceRoot(cwd: string): string | undefined {
|
|
|
731
860
|
}
|
|
732
861
|
}
|
|
733
862
|
|
|
863
|
+
function isApifuseInternalWorkspaceRoot(workspaceRoot: string): boolean {
|
|
864
|
+
const providerSdkPackageJsonPath = resolve(
|
|
865
|
+
workspaceRoot,
|
|
866
|
+
"packages",
|
|
867
|
+
"provider-sdk",
|
|
868
|
+
"package.json",
|
|
869
|
+
);
|
|
870
|
+
if (!existsSync(providerSdkPackageJsonPath)) {
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
try {
|
|
874
|
+
const packageJson = JSON.parse(
|
|
875
|
+
readFileSync(providerSdkPackageJsonPath, "utf8"),
|
|
876
|
+
);
|
|
877
|
+
return (
|
|
878
|
+
typeof packageJson === "object" &&
|
|
879
|
+
packageJson !== null &&
|
|
880
|
+
"name" in packageJson &&
|
|
881
|
+
packageJson.name === "@apifuse/provider-sdk"
|
|
882
|
+
);
|
|
883
|
+
} catch {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
734
888
|
async function writePlan(plan: ProviderCreatePlan): Promise<void> {
|
|
735
889
|
for (const file of plan.files) {
|
|
736
890
|
await mkdir(dirname(file.path), { recursive: true });
|
|
@@ -838,6 +992,14 @@ function printResult(
|
|
|
838
992
|
console.log(`Validation: (cd ${plan.providerRoot} && ${command})`);
|
|
839
993
|
}
|
|
840
994
|
console.log(`Next local dev: ${plan.nextDevCommand}`);
|
|
995
|
+
console.log(
|
|
996
|
+
"Submission evidence: run `bun run submit-check`, save the generated report, and note `/health` plus `POST /v1/{operation}` smoke results.",
|
|
997
|
+
);
|
|
998
|
+
if (plan.files.some((file) => file.content.includes('runtime: "browser"'))) {
|
|
999
|
+
console.log(
|
|
1000
|
+
"Browser runtime: run `bunx playwright install chromium` locally or set `APIFUSE__CDP_POOL__URL` before browser-backed smoke tests.",
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
841
1003
|
}
|
|
842
1004
|
|
|
843
1005
|
function escapeTemplate(value: string): string {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
.git/
|
|
3
|
+
.github/
|
|
4
|
+
|
|
5
|
+
# Environment and local secrets
|
|
6
|
+
.env
|
|
7
|
+
.env.*
|
|
8
|
+
!.env.example
|
|
9
|
+
|
|
10
|
+
# Local reports and generated artifacts
|
|
11
|
+
submission-report.md
|
|
12
|
+
coverage/
|
|
13
|
+
dist/
|
|
14
|
+
.cache/
|
|
15
|
+
.turbo/
|
|
16
|
+
.bun/
|
|
17
|
+
*.tsbuildinfo
|
|
18
|
+
|
|
19
|
+
# OS/editor junk
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
*.swp
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
|
|
3
|
+
# Environment and local secrets
|
|
4
|
+
.env
|
|
5
|
+
.env.*
|
|
6
|
+
!.env.example
|
|
7
|
+
|
|
8
|
+
# Build, coverage, cache, and local runtime artifacts
|
|
9
|
+
coverage/
|
|
10
|
+
dist/
|
|
11
|
+
.cache/
|
|
12
|
+
.turbo/
|
|
13
|
+
.bun/
|
|
14
|
+
*.tsbuildinfo
|
|
15
|
+
|
|
16
|
+
# Bounty submission output
|
|
17
|
+
submission-report.md
|
|
18
|
+
|
|
19
|
+
# OS/editor junk
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
*.swp
|