@apifuse/provider-sdk 2.2.0-beta.4 → 2.2.0-beta.7

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 (51) hide show
  1. package/AUTHORING.md +92 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +5 -1
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +26 -1
  6. package/bin/apifuse-pack-check.ts +14 -0
  7. package/bin/apifuse-submit-check.ts +433 -15
  8. package/bin/apifuse-sync-assets.ts +117 -0
  9. package/dist/cli/commands.d.ts +1 -1
  10. package/dist/cli/commands.js +8 -0
  11. package/dist/cli/create.d.ts +3 -0
  12. package/dist/cli/create.js +34 -35
  13. package/dist/cli/prompt-assets.d.ts +80 -0
  14. package/dist/cli/prompt-assets.js +743 -0
  15. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/runtime/executor.js +7 -0
  19. package/dist/runtime/secrets.d.ts +27 -0
  20. package/dist/runtime/secrets.js +51 -0
  21. package/dist/server/index.d.ts +1 -1
  22. package/dist/server/index.js +1 -1
  23. package/dist/server/self-test.d.ts +101 -0
  24. package/dist/server/self-test.js +670 -112
  25. package/dist/server/serve.d.ts +5 -0
  26. package/dist/server/serve.js +41 -1
  27. package/package.json +1 -1
  28. package/src/cli/commands.ts +10 -0
  29. package/src/cli/create.ts +42 -35
  30. package/src/cli/prompt-assets.ts +865 -0
  31. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  32. package/src/index.ts +5 -0
  33. package/src/runtime/executor.ts +8 -0
  34. package/src/runtime/secrets.ts +64 -0
  35. package/src/server/index.ts +5 -0
  36. package/src/server/self-test.ts +852 -127
  37. package/src/server/serve.ts +60 -1
  38. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  39. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  40. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  41. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  42. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  43. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  44. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  45. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  46. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  47. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  48. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  49. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  50. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  51. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -42,6 +42,11 @@ import {
42
42
  PROXY_POOL_EXHAUSTED_CODE,
43
43
  } from "../runtime/proxy-errors.js";
44
44
  import { PROVIDER_TELEMETRY_HEADER, ProxyTelemetryCollector } from "../runtime/proxy-telemetry.js";
45
+ import {
46
+ assertRequiredSecretsPresent,
47
+ listMissingRequiredSecrets,
48
+ MISSING_SECRET_CODE,
49
+ } from "../runtime/secrets.js";
45
50
  import {
46
51
  createProviderRuntimeStateFromEnv,
47
52
  createUnsupportedProviderRuntimeState,
@@ -74,7 +79,12 @@ import type {
74
79
  StealthClient,
75
80
  SttContext,
76
81
  } from "../types.js";
77
- import { createSelfTestApp, createSelfTestInvoke, resolveSelfTestPort } from "./self-test.js";
82
+ import {
83
+ createSelfTestApp,
84
+ createSelfTestAuthFlowInvoke,
85
+ createSelfTestInvoke,
86
+ resolveSelfTestPort,
87
+ } from "./self-test.js";
78
88
  import { resolveSelfTestMasterSecrets } from "./self-test-token.js";
79
89
  import {
80
90
  type AuthFlowRequest,
@@ -403,6 +413,12 @@ export type ProviderServerLogEvent =
403
413
  retryable?: boolean;
404
414
  issues?: Array<{ path: string; code: string; message: string }>;
405
415
  })
416
+ | {
417
+ level: "warn";
418
+ event: "provider_secrets_missing";
419
+ providerId: string;
420
+ missingSecrets: string[];
421
+ }
406
422
  | {
407
423
  level: "warn";
408
424
  event: "provider_cleanup_failed";
@@ -553,6 +569,18 @@ function providerObservabilityDetails(error: unknown):
553
569
  retryable: error.options?.retryable ?? false,
554
570
  };
555
571
  }
572
+ // Missing-secret errors carry the canonical credential_unavailable category
573
+ // so Gateway/observability can attribute the failure to provisioning, not
574
+ // the upstream. Matched by code (not constructor) so both the SDK-owned
575
+ // runtime gate and any not-yet-migrated provider-thrown MISSING_SECRET
576
+ // serialize identically, including across duplicate SDK module instances.
577
+ if (isProviderError(error) && error.code === MISSING_SECRET_CODE) {
578
+ return {
579
+ category: error.options?.category ?? "credential_unavailable",
580
+ taxonomyVersion: PROVIDER_OBSERVABILITY_TAXONOMY_VERSION,
581
+ retryable: error.options?.retryable ?? false,
582
+ };
583
+ }
556
584
  if (!isTransportError(error)) {
557
585
  return undefined;
558
586
  }
@@ -623,6 +651,10 @@ function toStatusCode(error: unknown): 400 | 401 | 404 | 429 | 500 | 502 | 503 |
623
651
  case "AUTH_REQUIRED":
624
652
  case "reauth_required":
625
653
  return 401;
654
+ // Unprovisioned declared secret: a deployment/config defect, never an
655
+ // upstream failure — explicit 400 (was only reached via fallthrough).
656
+ case MISSING_SECRET_CODE:
657
+ return 400;
626
658
  case "NOT_FOUND":
627
659
  case "not_found":
628
660
  case "NO_DATA":
@@ -1219,8 +1251,16 @@ async function handleAuthFlow(
1219
1251
  });
1220
1252
  }
1221
1253
 
1254
+ // Same SDK-owned gate as executeOperation: OAuth/credentials ceremonies
1255
+ // depend on declared secrets (client ids/secrets), so fail structured before
1256
+ // any flow code runs instead of at whatever point the ceremony first reads
1257
+ // the env. `abort` stays exempt: a user must always be able to cancel a
1258
+ // stranded flow even when provisioning is broken.
1222
1259
  const { context, getPatch } = createAuthFlowContext(provider, request, options, signal);
1223
1260
  try {
1261
+ if (route !== "abort") {
1262
+ assertRequiredSecretsPresent(provider, context.env);
1263
+ }
1224
1264
  const result =
1225
1265
  route === "start"
1226
1266
  ? await flow.start(context)
@@ -1275,6 +1315,24 @@ export function createServerApp(
1275
1315
  allowMemoryFallback: options.allowMemoryStateFallback === true,
1276
1316
  });
1277
1317
 
1318
+ // Boot-time visibility for unprovisioned declared secrets: emit a structured
1319
+ // warn so deploy tooling/alerting sees the gap the moment the pod boots,
1320
+ // instead of discovering it request-by-request. Deliberately log-only — a
1321
+ // boot crash would trade a structured MISSING_SECRET signal for
1322
+ // CrashLoopBackOff. Requests still fail closed via the executeOperation gate.
1323
+ const missingSecretsAtBoot = listMissingRequiredSecrets(
1324
+ provider,
1325
+ createEnvContext(provider.secrets?.map((secret) => secret.name)),
1326
+ );
1327
+ if (missingSecretsAtBoot.length > 0) {
1328
+ logger({
1329
+ level: "warn",
1330
+ event: "provider_secrets_missing",
1331
+ providerId: provider.id,
1332
+ missingSecrets: missingSecretsAtBoot,
1333
+ });
1334
+ }
1335
+
1278
1336
  app.notFound((c) =>
1279
1337
  c.json(
1280
1338
  {
@@ -1615,6 +1673,7 @@ export async function serve(
1615
1673
  const selfTestApp = createSelfTestApp(provider, {
1616
1674
  secrets: selfTestSecrets,
1617
1675
  invoke: createSelfTestInvoke(app),
1676
+ authFlow: createSelfTestAuthFlowInvoke(app),
1618
1677
  });
1619
1678
  bunRuntime.serve({
1620
1679
  port: options.selfTestPort ?? resolveSelfTestPort(),
@@ -1 +0,0 @@
1
- @AGENTS.md
@@ -1 +0,0 @@
1
- @AGENTS.md