@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
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@apifuse/provider-sdk",
3
- "version": "2.1.0-beta.3",
3
+ "version": "2.1.0-beta.5",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "ApiFuse Provider SDK — Build providers with zero architectural constraints",
6
+ "description": "APIFuse Provider SDK — Build providers with zero architectural constraints",
7
7
  "license": "MIT",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./src/index.ts",
@@ -53,6 +53,11 @@
53
53
  "default": "./src/testing/index.ts",
54
54
  "import": "./src/testing/index.ts",
55
55
  "types": "./src/testing/index.ts"
56
+ },
57
+ "./create": {
58
+ "default": "./src/cli/create.ts",
59
+ "import": "./src/cli/create.ts",
60
+ "types": "./src/cli/create.ts"
56
61
  }
57
62
  },
58
63
  "scripts": {
@@ -66,20 +71,24 @@
66
71
  "pack:smoke": "bun bin/apifuse-pack-smoke.ts"
67
72
  },
68
73
  "devDependencies": {
69
- "@biomejs/biome": "^2.4.15",
74
+ "@biomejs/biome": "^2.5.0",
70
75
  "@types/bun": "latest",
71
- "@types/node": "^25.8.0",
76
+ "@types/node": "^25.9.3",
72
77
  "typescript": "^6.0.3"
73
78
  },
74
79
  "dependencies": {
75
- "@clack/prompts": "^1.4.0",
80
+ "@clack/prompts": "^1.5.1",
81
+ "@types/ms": "^2.1.0",
76
82
  "ajv": "^8.17",
77
- "hono": "^4.12.19",
83
+ "hono": "^4.12.25",
84
+ "impit": "0.14.1",
85
+ "ioredis": "^5.11.1",
86
+ "ms": "^2.1.3",
78
87
  "playwright": "^1.55.1",
79
- "playwright-stealth": "^0.0.1",
88
+ "playwright-extra": "^4.3.6",
89
+ "puppeteer-extra-plugin-stealth": "^2.11.2",
80
90
  "re2-wasm": "^1.0",
81
91
  "safe-regex": "^2.1",
82
- "tlsclientwrapper": "^4.2.0",
83
92
  "zod": "^4.4.3"
84
93
  }
85
94
  }
@@ -0,0 +1,164 @@
1
+ import {
2
+ createCipheriv,
3
+ createDecipheriv,
4
+ createHash,
5
+ createHmac,
6
+ randomBytes,
7
+ timingSafeEqual,
8
+ } from "node:crypto";
9
+
10
+ export type ProviderChoiceTokenPayload = Record<string, unknown>;
11
+
12
+ export type ProviderChoiceTokenErrorReason =
13
+ | "invalid_shape"
14
+ | "invalid_signature"
15
+ | "invalid_payload"
16
+ | "stale";
17
+
18
+ export class ProviderChoiceTokenError extends Error {
19
+ readonly reason: ProviderChoiceTokenErrorReason;
20
+
21
+ constructor(reason: ProviderChoiceTokenErrorReason, message: string) {
22
+ super(message);
23
+ this.name = "ProviderChoiceTokenError";
24
+ this.reason = reason;
25
+ }
26
+ }
27
+
28
+ export interface CreateProviderChoiceTokenOptions<
29
+ TPayload extends ProviderChoiceTokenPayload,
30
+ > {
31
+ prefix: string;
32
+ payload: TPayload;
33
+ secret: string;
34
+ }
35
+
36
+ export interface ParseProviderChoiceTokenOptions {
37
+ token: string;
38
+ prefix: string;
39
+ secret: string;
40
+ }
41
+
42
+ export interface FreshProviderChoiceIssuedAtOptions {
43
+ ttlMs: number;
44
+ nowMs?: number;
45
+ futureToleranceMs?: number;
46
+ }
47
+
48
+ export function createProviderChoiceToken<
49
+ TPayload extends ProviderChoiceTokenPayload,
50
+ >(options: CreateProviderChoiceTokenOptions<TPayload>): string {
51
+ const iv = randomBytes(12);
52
+ const cipher = createCipheriv(
53
+ "aes-256-gcm",
54
+ choiceEncryptionKey(options.secret),
55
+ iv,
56
+ );
57
+ const encryptedPayload = Buffer.concat([
58
+ cipher.update(JSON.stringify(options.payload), "utf8"),
59
+ cipher.final(),
60
+ ]).toString("base64url");
61
+ const authTag = cipher.getAuthTag().toString("base64url");
62
+ const encodedIv = iv.toString("base64url");
63
+ const signature = signProviderChoiceTokenBody(
64
+ `${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}`,
65
+ options.secret,
66
+ );
67
+ return `${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}.${signature}`;
68
+ }
69
+
70
+ export function parseProviderChoiceToken(
71
+ options: ParseProviderChoiceTokenOptions,
72
+ ): ProviderChoiceTokenPayload {
73
+ const [
74
+ actualPrefix,
75
+ encodedIv,
76
+ encryptedPayload,
77
+ authTag,
78
+ signature,
79
+ ...extra
80
+ ] = options.token.split(".");
81
+ if (
82
+ actualPrefix !== options.prefix ||
83
+ !encodedIv ||
84
+ !encryptedPayload ||
85
+ !authTag ||
86
+ !signature ||
87
+ extra.length > 0
88
+ ) {
89
+ throw new ProviderChoiceTokenError(
90
+ "invalid_shape",
91
+ "Provider choice token shape is invalid.",
92
+ );
93
+ }
94
+
95
+ const signedBody = `${options.prefix}.${encodedIv}.${encryptedPayload}.${authTag}`;
96
+ const expectedSignature = signProviderChoiceTokenBody(
97
+ signedBody,
98
+ options.secret,
99
+ );
100
+ const actualBuffer = Buffer.from(signature);
101
+ const expectedBuffer = Buffer.from(expectedSignature);
102
+ if (
103
+ actualBuffer.length !== expectedBuffer.length ||
104
+ !timingSafeEqual(actualBuffer, expectedBuffer)
105
+ ) {
106
+ throw new ProviderChoiceTokenError(
107
+ "invalid_signature",
108
+ "Provider choice token signature is invalid.",
109
+ );
110
+ }
111
+
112
+ try {
113
+ const decipher = createDecipheriv(
114
+ "aes-256-gcm",
115
+ choiceEncryptionKey(options.secret),
116
+ Buffer.from(encodedIv, "base64url"),
117
+ );
118
+ decipher.setAuthTag(Buffer.from(authTag, "base64url"));
119
+ const decrypted = Buffer.concat([
120
+ decipher.update(Buffer.from(encryptedPayload, "base64url")),
121
+ decipher.final(),
122
+ ]).toString("utf8");
123
+ const parsed = JSON.parse(decrypted);
124
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
125
+ throw new Error("payload is not an object");
126
+ }
127
+ return Object.fromEntries(Object.entries(parsed));
128
+ } catch {
129
+ throw new ProviderChoiceTokenError(
130
+ "invalid_payload",
131
+ "Provider choice token payload is invalid.",
132
+ );
133
+ }
134
+ }
135
+
136
+ export function assertFreshProviderChoiceIssuedAt(
137
+ issuedAtMs: unknown,
138
+ options: FreshProviderChoiceIssuedAtOptions,
139
+ ): number {
140
+ const parsed =
141
+ typeof issuedAtMs === "number" ? issuedAtMs : Number(issuedAtMs);
142
+ const nowMs = options.nowMs ?? Date.now();
143
+ const futureToleranceMs = options.futureToleranceMs ?? 30_000;
144
+ if (
145
+ !Number.isFinite(parsed) ||
146
+ parsed <= 0 ||
147
+ nowMs - parsed > options.ttlMs ||
148
+ parsed - nowMs > futureToleranceMs
149
+ ) {
150
+ throw new ProviderChoiceTokenError(
151
+ "stale",
152
+ "Provider choice token is stale.",
153
+ );
154
+ }
155
+ return parsed;
156
+ }
157
+
158
+ function choiceEncryptionKey(secret: string): Buffer {
159
+ return createHash("sha256").update(secret).digest();
160
+ }
161
+
162
+ function signProviderChoiceTokenBody(body: string, secret: string): string {
163
+ return createHmac("sha256", secret).update(body).digest("base64url");
164
+ }
@@ -24,11 +24,9 @@ export const COMMAND_MANIFEST: Record<
24
24
  name: "create",
25
25
  summary:
26
26
  "Scaffold a provider, install dependencies, run baseline validation, and print the next local-dev command.",
27
- usage:
28
- "apifuse create <provider-name> [--preset standalone|monorepo] [--json] [--dry-run]",
27
+ usage: "apifuse create <provider-name> [--json] [--dry-run]",
29
28
  examples: [
30
29
  "apifuse create weather-provider",
31
- "apifuse create weather-provider --preset monorepo",
32
30
  "apifuse create --config ./apifuse.create.json --json",
33
31
  ],
34
32
  modulePath: "./apifuse-create",
@@ -74,7 +72,6 @@ export const COMMAND_MANIFEST: Record<
74
72
  usage:
75
73
  'apifuse record [path] --operation <operation> --params \'{"value":"hello"}\'',
76
74
  examples: [
77
- 'apifuse record . --operation ping --params \'{"value":"hello"}\'',
78
75
  'apifuse record providers/airkorea --operation realtime --params \'{"stationName":"종로구"}\'',
79
76
  ],
80
77
  modulePath: "./apifuse-record",
@@ -90,10 +87,10 @@ export const COMMAND_MANIFEST: Record<
90
87
  name: "perf",
91
88
  summary:
92
89
  "Profile a provider operation and export latency/trace diagnostics.",
93
- usage: "apifuse perf <path> --operation <operation> [options]",
90
+ usage:
91
+ "apifuse perf <path> --operation <operation> [--params '<json>'] [options]",
94
92
  examples: [
95
- "apifuse perf . --operation ping",
96
- "apifuse perf providers/airkorea --operation realtime --runs 5",
93
+ 'apifuse perf providers/airkorea --operation realtime --params \'{"stationName":"종로구"}\' --runs 5',
97
94
  ],
98
95
  modulePath: "./apifuse-perf",
99
96
  },
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 standalone dependency resolution
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 detectedWorkspaceRoot = findWorkspaceRoot(cwd);
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 ?? detectedPreset,
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.APIFUSE_SDK_SPECIFIER,
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" && !detectedWorkspaceRoot) {
293
+ if (partial.preset === "monorepo" && !internalWorkspaceRoot) {
299
294
  throw new Error(
300
- "Monorepo preset requires a workspace root with a providers/ directory.",
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 ?? detectedPreset,
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 ApiFuse provider");
322
+ intro("Create a new APIFuse provider");
328
323
  note(
329
- `Preset precedence: explicit flags > config file > workspace detection > standalone default\nDetected workspace preset: ${detectedPreset}`,
330
- "Preset resolution",
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 workspaceRoot =
433
- options.preset === "monorepo" ? findWorkspaceRoot(cwd) : undefined;
434
- if (options.preset === "monorepo" && !workspaceRoot) {
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 requires a workspace root with a providers/ directory.",
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,95 @@ 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" ? "workspace:*" : `^${packageJson.version}`);
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
- RUNTIME: options.runtime,
480
- BROWSER_BLOCK:
481
- options.runtime === "browser"
482
- ? ',\n browser: {\n engine: "playwright-stealth",\n }'
483
- : "",
484
- SECRETS_BLOCK: renderSecretsBlock(options.authMode),
485
- CREDENTIAL_BLOCK: renderCredentialBlock(options.authMode),
486
- AUTH_BLOCK: renderAuthBlock(options.authMode),
487
495
  }),
488
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
+ }),
506
+ },
507
+ {
508
+ path: resolve(providerRoot, "schemas", "ping.ts"),
509
+ content: await renderTemplate("schemas/ping.ts.tpl", {}),
510
+ },
511
+ {
512
+ path: resolve(providerRoot, "upstream", "README.md"),
513
+ content: await renderTemplate("upstream/README.md.tpl", {}),
514
+ },
515
+ {
516
+ path: resolve(providerRoot, "mappers", "README.md"),
517
+ content: await renderTemplate("mappers/README.md.tpl", {}),
518
+ },
519
+ {
520
+ path: resolve(providerRoot, "domain", "README.md"),
521
+ content: await renderTemplate("domain/README.md.tpl", {}),
522
+ },
523
+ {
524
+ path: resolve(providerRoot, "locales", "en.json"),
525
+ content: renderStarterLocaleCatalog(options.displayName, "en"),
526
+ },
527
+ {
528
+ path: resolve(providerRoot, "locales", "ko.json"),
529
+ content: renderStarterLocaleCatalog(options.displayName, "ko"),
530
+ },
489
531
  {
490
532
  path: resolve(providerRoot, "package.json"),
491
533
  content: renderPackageJson({
@@ -540,6 +582,7 @@ export async function buildProviderCreatePlan(
540
582
  providerRoot,
541
583
  validationCommands: [
542
584
  "bun run check",
585
+ "bun run type-check",
543
586
  "bun run submit-check",
544
587
  "bun run test",
545
588
  ],
@@ -571,7 +614,8 @@ function renderPackageJson(input: {
571
614
  main: "./index.ts",
572
615
  scripts: {
573
616
  dev: "apifuse dev .",
574
- check: "apifuse check .",
617
+ check: "apifuse check . && bun run type-check",
618
+ "type-check": "tsc --noEmit",
575
619
  "submit-check":
576
620
  "apifuse submit-check . --markdown submission-report.md",
577
621
  test: "apifuse test .",
@@ -584,6 +628,7 @@ function renderPackageJson(input: {
584
628
  },
585
629
  devDependencies: {
586
630
  "@types/bun": "latest",
631
+ typescript: "^6.0.3",
587
632
  },
588
633
  },
589
634
  null,
@@ -602,6 +647,7 @@ function renderTsconfig(): string {
602
647
  noEmit: true,
603
648
  skipLibCheck: true,
604
649
  resolveJsonModule: true,
650
+ types: ["bun"],
605
651
  },
606
652
  include: ["**/*.ts"],
607
653
  exclude: ["node_modules"],
@@ -611,6 +657,56 @@ function renderTsconfig(): string {
611
657
  )}\n`;
612
658
  }
613
659
 
660
+ function renderStarterLocaleCatalog(
661
+ displayName: string,
662
+ locale: "en" | "ko",
663
+ ): string {
664
+ const catalog = {
665
+ meta: {
666
+ displayName,
667
+ description:
668
+ locale === "ko"
669
+ ? `${displayName} APIFuse 커뮤니티 기여용 provider starter입니다.`
670
+ : `${displayName} provider starter for APIFuse community contributions.`,
671
+ },
672
+ operations: {
673
+ ping: {
674
+ description:
675
+ locale === "ko"
676
+ ? "생성된 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을 수행하는지 증명하기 위한 용도입니다."
677
+ : "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.",
678
+ },
679
+ },
680
+ schemaDescriptions: {
681
+ input: {
682
+ root:
683
+ locale === "ko"
684
+ ? "생성된 ping operation의 입력 payload"
685
+ : "Input payload for the generated ping operation.",
686
+ value:
687
+ locale === "ko"
688
+ ? "생성된 provider scaffold wiring 검증에 사용하는 샘플 입력값"
689
+ : "Sample input value used to verify the generated provider scaffold is wired correctly.",
690
+ },
691
+ output: {
692
+ root:
693
+ locale === "ko"
694
+ ? "생성된 ping operation이 반환하는 출력 payload"
695
+ : "Output payload returned by the generated ping operation.",
696
+ ok:
697
+ locale === "ko"
698
+ ? "생성된 provider가 샘플 요청을 성공적으로 처리했는지 여부"
699
+ : "Whether the generated provider handled the sample request successfully.",
700
+ message:
701
+ locale === "ko"
702
+ ? "생성된 provider가 샘플 payload를 round-trip했음을 보여주는 사람이 읽을 수 있는 확인 메시지"
703
+ : "Human-readable confirmation that the generated provider round-tripped the sample payload.",
704
+ },
705
+ },
706
+ };
707
+ return `${JSON.stringify(catalog, null, 2)}\n`;
708
+ }
709
+
614
710
  function renderAuthBlock(authMode: CreateAuthMode): string {
615
711
  switch (authMode) {
616
712
  case "none":
@@ -719,11 +815,11 @@ export function toDisplayName(name: string): string {
719
815
  .join(" ");
720
816
  }
721
817
 
722
- function findWorkspaceRoot(cwd: string): string | undefined {
818
+ function findApifuseInternalWorkspaceRoot(cwd: string): string | undefined {
723
819
  let currentDirectory = cwd;
724
820
 
725
821
  while (true) {
726
- if (existsSync(resolve(currentDirectory, "providers"))) {
822
+ if (isApifuseInternalWorkspaceRoot(currentDirectory)) {
727
823
  return currentDirectory;
728
824
  }
729
825
 
@@ -736,6 +832,31 @@ function findWorkspaceRoot(cwd: string): string | undefined {
736
832
  }
737
833
  }
738
834
 
835
+ function isApifuseInternalWorkspaceRoot(workspaceRoot: string): boolean {
836
+ const providerSdkPackageJsonPath = resolve(
837
+ workspaceRoot,
838
+ "packages",
839
+ "provider-sdk",
840
+ "package.json",
841
+ );
842
+ if (!existsSync(providerSdkPackageJsonPath)) {
843
+ return false;
844
+ }
845
+ try {
846
+ const packageJson = JSON.parse(
847
+ readFileSync(providerSdkPackageJsonPath, "utf8"),
848
+ );
849
+ return (
850
+ typeof packageJson === "object" &&
851
+ packageJson !== null &&
852
+ "name" in packageJson &&
853
+ packageJson.name === "@apifuse/provider-sdk"
854
+ );
855
+ } catch {
856
+ return false;
857
+ }
858
+ }
859
+
739
860
  async function writePlan(plan: ProviderCreatePlan): Promise<void> {
740
861
  for (const file of plan.files) {
741
862
  await mkdir(dirname(file.path), { recursive: true });
@@ -843,6 +964,14 @@ function printResult(
843
964
  console.log(`Validation: (cd ${plan.providerRoot} && ${command})`);
844
965
  }
845
966
  console.log(`Next local dev: ${plan.nextDevCommand}`);
967
+ console.log(
968
+ "Submission evidence: run `bun run submit-check`, save the generated report, and note `/health` plus `POST /v1/{operation}` smoke results.",
969
+ );
970
+ if (plan.files.some((file) => file.content.includes('runtime: "browser"'))) {
971
+ console.log(
972
+ "Browser runtime: run `bunx playwright install chromium` locally or set `APIFUSE__CDP_POOL__URL` before browser-backed smoke tests.",
973
+ );
974
+ }
846
975
  }
847
976
 
848
977
  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