@apifuse/provider-sdk 2.1.0-beta.9 → 2.2.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.
Files changed (263) hide show
  1. package/AUTHORING.md +240 -0
  2. package/CHANGELOG.md +93 -0
  3. package/README.md +26 -10
  4. package/SUBMISSION.md +11 -12
  5. package/bin/apifuse-check.ts +44 -59
  6. package/bin/apifuse-create.ts +1 -1
  7. package/bin/apifuse-dev.ts +27 -52
  8. package/bin/apifuse-pack-check.ts +36 -0
  9. package/bin/apifuse-pack-smoke.ts +22 -81
  10. package/bin/apifuse-pack-types.ts +266 -0
  11. package/bin/apifuse-perf.ts +45 -127
  12. package/bin/apifuse-record.ts +53 -70
  13. package/bin/apifuse-submit-check.ts +2177 -353
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/apifuse.ts +1 -1
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/bin/submit-check-xml-semantics.ts +204 -0
  18. package/bin/submit-check-xml.ts +134 -0
  19. package/dist/auth-turn/auth-turn.v1.schema.json +89 -0
  20. package/dist/auth-turn/fixtures/invalid/empty-kind.json +4 -0
  21. package/dist/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
  22. package/dist/auth-turn/fixtures/invalid/missing-kind.json +3 -0
  23. package/dist/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
  24. package/dist/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
  25. package/dist/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
  26. package/dist/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
  27. package/dist/auth-turn/fixtures/valid/abort.json +8 -0
  28. package/dist/auth-turn/fixtures/valid/challenge.json +17 -0
  29. package/dist/auth-turn/fixtures/valid/complete.json +13 -0
  30. package/dist/auth-turn/fixtures/valid/form.json +14 -0
  31. package/dist/auth-turn/fixtures/valid/message.json +13 -0
  32. package/dist/auth-turn/fixtures/valid/multi_choice.json +15 -0
  33. package/dist/auth-turn/fixtures/valid/pending.json +5 -0
  34. package/dist/auth-turn/fixtures/valid/poll.json +9 -0
  35. package/dist/auth-turn/fixtures/valid/redirect.json +16 -0
  36. package/dist/auth-turn/fixtures/valid/retry.json +8 -0
  37. package/dist/auth-turn/fixtures/valid/unknown-kind.json +7 -0
  38. package/dist/auth-turn/index.d.ts +195 -0
  39. package/dist/auth-turn/index.js +133 -0
  40. package/dist/auth.d.ts +76 -0
  41. package/dist/auth.js +427 -0
  42. package/dist/ceremonies/index.d.ts +1 -1
  43. package/dist/ceremonies/index.js +14 -48
  44. package/dist/cli/commands.d.ts +1 -1
  45. package/dist/cli/commands.js +8 -0
  46. package/dist/cli/create.d.ts +3 -0
  47. package/dist/cli/create.js +47 -33
  48. package/dist/cli/prompt-assets.d.ts +80 -0
  49. package/dist/cli/prompt-assets.js +743 -0
  50. package/dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  51. package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  52. package/dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
  53. package/dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  54. package/dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  55. package/dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
  56. package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
  57. package/dist/cli/templates/provider/.gitignore.tpl +22 -0
  58. package/dist/cli/templates/provider/AGENTS.md.tpl +96 -0
  59. package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
  60. package/dist/cli/templates/provider/README.md.tpl +163 -0
  61. package/dist/cli/templates/provider/dev.ts.tpl +5 -0
  62. package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
  63. package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
  64. package/dist/cli/templates/provider/index.ts.tpl +15 -0
  65. package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
  66. package/dist/cli/templates/provider/meta.ts.tpl +7 -0
  67. package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
  68. package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
  69. package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  70. package/dist/cli/templates/provider/start.ts.tpl +5 -0
  71. package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
  72. package/dist/config/loader.d.ts +149 -8
  73. package/dist/config/loader.js +378 -89
  74. package/dist/contract-serialization.d.ts +2 -2
  75. package/dist/contract-serialization.js +3 -6
  76. package/dist/contract-types.d.ts +2 -2
  77. package/dist/contract.d.ts +3 -3
  78. package/dist/contract.js +5 -6
  79. package/dist/define.d.ts +13 -1
  80. package/dist/define.js +245 -178
  81. package/dist/dev.d.ts +1 -1
  82. package/dist/dev.js +1 -1
  83. package/dist/errors.d.ts +4 -1
  84. package/dist/errors.js +48 -0
  85. package/dist/i18n/catalog.d.ts +2 -2
  86. package/dist/i18n/catalog.js +4 -10
  87. package/dist/i18n/index.d.ts +2 -2
  88. package/dist/i18n/index.js +2 -2
  89. package/dist/i18n/keys.d.ts +2 -2
  90. package/dist/index.d.ts +44 -41
  91. package/dist/index.js +39 -36
  92. package/dist/lint.d.ts +1 -0
  93. package/dist/lint.js +35 -15
  94. package/dist/provider.d.ts +11 -9
  95. package/dist/provider.js +9 -8
  96. package/dist/public-schema-field-lint.d.ts +1 -1
  97. package/dist/recipes/gov-api.js +1 -1
  98. package/dist/runtime/auth-flow.d.ts +1 -1
  99. package/dist/runtime/auth-flow.js +4 -2
  100. package/dist/runtime/browser.d.ts +1 -1
  101. package/dist/runtime/browser.js +214 -25
  102. package/dist/runtime/cache.d.ts +1 -1
  103. package/dist/runtime/cache.js +4 -8
  104. package/dist/runtime/choice.d.ts +1 -1
  105. package/dist/runtime/choice.js +31 -35
  106. package/dist/runtime/credential.d.ts +1 -1
  107. package/dist/runtime/credential.js +1 -1
  108. package/dist/runtime/env.d.ts +1 -1
  109. package/dist/runtime/executor.d.ts +1 -1
  110. package/dist/runtime/executor.js +15 -3
  111. package/dist/runtime/http.d.ts +2 -2
  112. package/dist/runtime/http.js +160 -344
  113. package/dist/runtime/insights.d.ts +1 -1
  114. package/dist/runtime/insights.js +6 -13
  115. package/dist/runtime/instrumentation.d.ts +2 -2
  116. package/dist/runtime/instrumentation.js +56 -19
  117. package/dist/runtime/keyring.js +1 -1
  118. package/dist/runtime/namespace.js +1 -1
  119. package/dist/runtime/otlp.d.ts +1 -1
  120. package/dist/runtime/perf.d.ts +1 -1
  121. package/dist/runtime/provider.d.ts +1 -1
  122. package/dist/runtime/provider.js +1 -2
  123. package/dist/runtime/proxy-errors.d.ts +1 -1
  124. package/dist/runtime/proxy-errors.js +9 -7
  125. package/dist/runtime/proxy-nodemaven.d.ts +35 -0
  126. package/dist/runtime/proxy-nodemaven.js +128 -0
  127. package/dist/runtime/proxy-retry-policy.d.ts +40 -0
  128. package/dist/runtime/proxy-retry-policy.js +326 -0
  129. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  130. package/dist/runtime/proxy-telemetry.js +55 -52
  131. package/dist/runtime/redis.d.ts +1 -1
  132. package/dist/runtime/redis.js +2 -4
  133. package/dist/runtime/request-options.d.ts +1 -1
  134. package/dist/runtime/secrets.d.ts +27 -0
  135. package/dist/runtime/secrets.js +51 -0
  136. package/dist/runtime/state.d.ts +2 -2
  137. package/dist/runtime/state.js +15 -4
  138. package/dist/runtime/stealth.d.ts +7 -4
  139. package/dist/runtime/stealth.js +257 -215
  140. package/dist/runtime/stt.d.ts +1 -1
  141. package/dist/runtime/stt.js +11 -15
  142. package/dist/runtime/trace.d.ts +2 -2
  143. package/dist/runtime/trace.js +2 -4
  144. package/dist/runtime/waterfall.d.ts +1 -1
  145. package/dist/schema.d.ts +1 -1
  146. package/dist/schema.js +7 -15
  147. package/dist/serve.d.ts +1 -1
  148. package/dist/serve.js +1 -1
  149. package/dist/server/index.d.ts +7 -3
  150. package/dist/server/index.js +6 -2
  151. package/dist/server/self-test-input-tokens.d.ts +1 -0
  152. package/dist/server/self-test-input-tokens.js +37 -0
  153. package/dist/server/self-test-redaction.d.ts +20 -0
  154. package/dist/server/self-test-redaction.js +70 -0
  155. package/dist/server/self-test-token.d.ts +30 -0
  156. package/dist/server/self-test-token.js +50 -0
  157. package/dist/server/self-test.d.ts +199 -0
  158. package/dist/server/self-test.js +1113 -0
  159. package/dist/server/serve.d.ts +14 -3
  160. package/dist/server/serve.js +135 -64
  161. package/dist/server/types.d.ts +10 -9
  162. package/dist/server/types.js +3 -7
  163. package/dist/stealth/profiles.d.ts +1 -1
  164. package/dist/stealth/profiles.js +5 -14
  165. package/dist/stream.d.ts +1 -1
  166. package/dist/testing/index.d.ts +2 -2
  167. package/dist/testing/index.js +2 -2
  168. package/dist/testing/run.d.ts +1 -1
  169. package/dist/testing/run.js +12 -15
  170. package/dist/types.d.ts +237 -1
  171. package/dist/user-input.d.ts +30 -0
  172. package/dist/user-input.js +66 -0
  173. package/package.json +16 -5
  174. package/src/auth-turn/auth-turn.v1.schema.json +89 -0
  175. package/src/auth-turn/fixtures/invalid/empty-kind.json +4 -0
  176. package/src/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
  177. package/src/auth-turn/fixtures/invalid/missing-kind.json +3 -0
  178. package/src/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
  179. package/src/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
  180. package/src/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
  181. package/src/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
  182. package/src/auth-turn/fixtures/valid/abort.json +8 -0
  183. package/src/auth-turn/fixtures/valid/challenge.json +17 -0
  184. package/src/auth-turn/fixtures/valid/complete.json +13 -0
  185. package/src/auth-turn/fixtures/valid/form.json +14 -0
  186. package/src/auth-turn/fixtures/valid/message.json +13 -0
  187. package/src/auth-turn/fixtures/valid/multi_choice.json +15 -0
  188. package/src/auth-turn/fixtures/valid/pending.json +5 -0
  189. package/src/auth-turn/fixtures/valid/poll.json +9 -0
  190. package/src/auth-turn/fixtures/valid/redirect.json +16 -0
  191. package/src/auth-turn/fixtures/valid/retry.json +8 -0
  192. package/src/auth-turn/fixtures/valid/unknown-kind.json +7 -0
  193. package/src/auth-turn/index.ts +177 -0
  194. package/src/auth.ts +728 -0
  195. package/src/ceremonies/index.ts +33 -121
  196. package/src/cli/commands.ts +10 -0
  197. package/src/cli/create.ts +69 -99
  198. package/src/cli/prompt-assets.ts +865 -0
  199. package/src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  200. package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  201. package/src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
  202. package/src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  203. package/src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  204. package/src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
  205. package/src/cli/templates/provider/AGENTS.md.tpl +96 -0
  206. package/src/cli/templates/provider/README.md.tpl +7 -4
  207. package/src/config/loader.ts +543 -208
  208. package/src/contract-serialization.ts +5 -11
  209. package/src/contract-types.ts +2 -2
  210. package/src/contract.ts +13 -28
  211. package/src/define.ts +397 -528
  212. package/src/dev.ts +4 -9
  213. package/src/errors.ts +58 -5
  214. package/src/i18n/catalog.ts +10 -32
  215. package/src/i18n/index.ts +2 -2
  216. package/src/i18n/keys.ts +5 -11
  217. package/src/index.ts +64 -41
  218. package/src/lint.ts +122 -159
  219. package/src/provider.ts +40 -9
  220. package/src/public-schema-field-lint.ts +7 -33
  221. package/src/recipes/gov-api.ts +2 -5
  222. package/src/runtime/auth-flow.ts +6 -6
  223. package/src/runtime/browser.ts +320 -151
  224. package/src/runtime/cache.ts +20 -67
  225. package/src/runtime/choice.ts +79 -132
  226. package/src/runtime/credential.ts +2 -2
  227. package/src/runtime/env.ts +1 -1
  228. package/src/runtime/executor.ts +23 -20
  229. package/src/runtime/http.ts +216 -539
  230. package/src/runtime/insights.ts +15 -53
  231. package/src/runtime/instrumentation.ts +78 -65
  232. package/src/runtime/keyring.ts +7 -19
  233. package/src/runtime/namespace.ts +2 -7
  234. package/src/runtime/otlp.ts +12 -23
  235. package/src/runtime/perf.ts +1 -1
  236. package/src/runtime/provider.ts +4 -9
  237. package/src/runtime/proxy-errors.ts +29 -42
  238. package/src/runtime/proxy-nodemaven.ts +178 -0
  239. package/src/runtime/proxy-retry-policy.ts +469 -0
  240. package/src/runtime/proxy-telemetry.ts +79 -77
  241. package/src/runtime/redis.ts +4 -12
  242. package/src/runtime/request-options.ts +4 -13
  243. package/src/runtime/secrets.ts +64 -0
  244. package/src/runtime/state.ts +41 -110
  245. package/src/runtime/stealth.ts +331 -369
  246. package/src/runtime/stt.ts +38 -94
  247. package/src/runtime/trace.ts +14 -44
  248. package/src/runtime/waterfall.ts +5 -18
  249. package/src/schema.ts +23 -84
  250. package/src/serve.ts +1 -1
  251. package/src/server/index.ts +44 -3
  252. package/src/server/self-test-input-tokens.ts +46 -0
  253. package/src/server/self-test-redaction.ts +97 -0
  254. package/src/server/self-test-token.ts +70 -0
  255. package/src/server/self-test.ts +1450 -0
  256. package/src/server/serve.ts +206 -216
  257. package/src/server/types.ts +7 -19
  258. package/src/stealth/profiles.ts +10 -26
  259. package/src/stream.ts +8 -19
  260. package/src/testing/index.ts +2 -2
  261. package/src/testing/run.ts +24 -64
  262. package/src/types.ts +274 -1
  263. package/src/user-input.ts +118 -0
@@ -1,67 +1,28 @@
1
1
  import { createHash, randomBytes, randomUUID } from "node:crypto";
2
2
 
3
- import Ajv from "ajv";
3
+ import Ajv2020 from "ajv/dist/2020.js";
4
4
 
5
+ import { AUTH_TURN_SCHEMA, type KnownAuthTurnKind } from "../auth-turn/index.js";
5
6
  import {
6
7
  FlowExpiredError,
7
8
  ProviderSecretError,
8
9
  TurnValidationError,
9
10
  ValidationError,
10
- } from "../errors";
11
- import type {
12
- AuthFlowDefinition,
13
- AuthFlowInputHandler,
14
- AuthTurn,
15
- FlowContext,
16
- } from "../types";
17
-
18
- type TurnKind =
19
- | "abort"
20
- | "challenge"
21
- | "complete"
22
- | "form"
23
- | "message"
24
- | "multi_choice"
25
- | "poll"
26
- | "redirect"
27
- | "retry";
11
+ } from "../errors.js";
12
+ import type { AuthFlowDefinition, AuthFlowInputHandler, AuthTurn, FlowContext } from "../types.js";
13
+
14
+ type TurnKind = KnownAuthTurnKind;
28
15
 
29
16
  type CeremonyHandler = AuthFlowInputHandler;
30
17
 
31
18
  type JsonObject = Record<string, unknown>;
32
19
 
33
- const ajv = new Ajv({ allErrors: true, strict: true, strictSchema: true });
34
-
35
- const authTurnSchema = {
36
- type: "object",
37
- additionalProperties: false,
38
- required: ["kind", "turnId"],
39
- properties: {
40
- kind: { type: "string", minLength: 1 },
41
- turnId: { type: "string", minLength: 1 },
42
- expiresAt: { type: "string", minLength: 1 },
43
- data: {
44
- type: "object",
45
- additionalProperties: true,
46
- },
47
- expectedInput: {
48
- type: "object",
49
- additionalProperties: true,
50
- },
51
- hint: { type: "string" },
52
- hintKey: { type: "string" },
53
- timing: {
54
- type: "object",
55
- additionalProperties: false,
56
- properties: {
57
- suggestedPollIntervalMs: { type: "number", minimum: 1 },
58
- maxWaitMs: { type: "number", minimum: 1 },
59
- },
60
- },
61
- },
62
- } as const;
63
-
64
- const validateAuthTurn = ajv.compile(authTurnSchema);
20
+ const ajv = new Ajv2020({ allErrors: true, strict: true, strictSchema: true });
21
+
22
+ // Runtime ceremony-output validation derives from the exported versioned
23
+ // contract: it compiles the exact AUTH_TURN_SCHEMA document shipped at
24
+ // dist/auth-turn/auth-turn.v1.schema.json, so the two cannot drift.
25
+ const validateAuthTurn = ajv.compile(AUTH_TURN_SCHEMA);
65
26
 
66
27
  const OAUTH2_STATE_KEY = "__oauth2_state";
67
28
  const OAUTH2_PKCE_VERIFIER_KEY = "__oauth2_pkce_verifier";
@@ -79,10 +40,7 @@ function ensureRecord(value: unknown): JsonObject {
79
40
  return isRecord(value) ? value : {};
80
41
  }
81
42
 
82
- function createTurn(
83
- kind: TurnKind,
84
- options: Omit<AuthTurn, "kind" | "turnId"> = {},
85
- ): AuthTurn {
43
+ function createTurn(kind: TurnKind, options: Omit<AuthTurn, "kind" | "turnId"> = {}): AuthTurn {
86
44
  return {
87
45
  kind,
88
46
  turnId: randomUUID(),
@@ -103,11 +61,7 @@ function getRequiredEnv(ctx: FlowContext, key: string): string {
103
61
  }
104
62
 
105
63
  function toBase64Url(input: Buffer): string {
106
- return input
107
- .toString("base64")
108
- .replace(/\+/g, "-")
109
- .replace(/\//g, "_")
110
- .replace(/=+$/g, "");
64
+ return input.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
111
65
  }
112
66
 
113
67
  function createCodeVerifier(): string {
@@ -164,10 +118,7 @@ async function runCeremonyHandler(
164
118
  }
165
119
  }
166
120
 
167
- function getString(
168
- input: Record<string, unknown>,
169
- key: string,
170
- ): string | undefined {
121
+ function getString(input: Record<string, unknown>, key: string): string | undefined {
171
122
  const value = input[key];
172
123
  return typeof value === "string" ? value : undefined;
173
124
  }
@@ -176,10 +127,7 @@ function getNestedRecord(ctx: FlowContext, key: string): JsonObject {
176
127
  return ensureRecord(ctx.context.get(key));
177
128
  }
178
129
 
179
- function buildJsonSchemaForm(
180
- expectedInput: JsonObject,
181
- hint: string,
182
- ): AuthTurn {
130
+ function buildJsonSchemaForm(expectedInput: JsonObject, hint: string): AuthTurn {
183
131
  return createTurn("form", {
184
132
  hint,
185
133
  expectedInput: withDeclaredFormFieldOrder(expectedInput),
@@ -194,10 +142,7 @@ function withDeclaredFormFieldOrder(expectedInput: JsonObject): JsonObject {
194
142
  }
195
143
 
196
144
  const existingOrder = expectedInput[FORM_FIELD_ORDER_EXTENSION];
197
- if (
198
- Array.isArray(existingOrder) &&
199
- existingOrder.every((value) => typeof value === "string")
200
- ) {
145
+ if (Array.isArray(existingOrder) && existingOrder.every((value) => typeof value === "string")) {
201
146
  return expectedInput;
202
147
  }
203
148
 
@@ -210,9 +155,7 @@ function withDeclaredFormFieldOrder(expectedInput: JsonObject): JsonObject {
210
155
  export function validateCeremonyOutput(turn: unknown): AuthTurn {
211
156
  if (!validateAuthTurn(turn)) {
212
157
  const detail = validateAuthTurn.errors
213
- ?.map(
214
- (error) => `${error.instancePath || "$"} ${error.message ?? "invalid"}`,
215
- )
158
+ ?.map((error) => `${error.instancePath || "$"} ${error.message ?? "invalid"}`)
216
159
  .join("; ");
217
160
  throw new TurnValidationError(detail || "Invalid AuthTurn output");
218
161
  }
@@ -248,10 +191,7 @@ export function createOAuth2Ceremony(options: {
248
191
  if (options.usePKCE) {
249
192
  const verifier = createCodeVerifier();
250
193
  ctx.context.set(OAUTH2_PKCE_VERIFIER_KEY, verifier);
251
- authorizeUrl.searchParams.set(
252
- "code_challenge",
253
- createCodeChallenge(verifier),
254
- );
194
+ authorizeUrl.searchParams.set("code_challenge", createCodeChallenge(verifier));
255
195
  authorizeUrl.searchParams.set("code_challenge_method", "S256");
256
196
  }
257
197
 
@@ -304,10 +244,7 @@ export function createOAuth2Ceremony(options: {
304
244
  ctx,
305
245
  input,
306
246
  ),
307
- abort: async () =>
308
- validateCeremonyOutput(
309
- createTurn("abort", { hint: "OAuth flow aborted." }),
310
- ),
247
+ abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "OAuth flow aborted." })),
311
248
  };
312
249
  }
313
250
 
@@ -363,26 +300,19 @@ export function createDeviceFlowCeremony(options: {
363
300
  client_id: getRequiredEnv(ctx, options.clientIdEnvKey),
364
301
  ...(options.clientSecretEnvKey
365
302
  ? {
366
- client_secret: getRequiredEnv(
367
- ctx,
368
- options.clientSecretEnvKey,
369
- ),
303
+ client_secret: getRequiredEnv(ctx, options.clientSecretEnvKey),
370
304
  }
371
305
  : {}),
372
306
  });
373
307
  const data = ensureRecord(response.data);
374
308
  const errorCode = getString(data, "error");
375
309
 
376
- if (
377
- errorCode === "authorization_pending" ||
378
- errorCode === "slow_down"
379
- ) {
310
+ if (errorCode === "authorization_pending" || errorCode === "slow_down") {
380
311
  return createTurn("poll", {
381
312
  data,
382
313
  hint: "Authorization pending.",
383
314
  timing: {
384
- suggestedPollIntervalMs:
385
- errorCode === "slow_down" ? 10_000 : 5_000,
315
+ suggestedPollIntervalMs: errorCode === "slow_down" ? 10_000 : 5_000,
386
316
  maxWaitMs: 120_000,
387
317
  },
388
318
  });
@@ -401,9 +331,7 @@ export function createDeviceFlowCeremony(options: {
401
331
  ctx,
402
332
  ),
403
333
  abort: async () =>
404
- validateCeremonyOutput(
405
- createTurn("abort", { hint: "Device flow aborted." }),
406
- ),
334
+ validateCeremonyOutput(createTurn("abort", { hint: "Device flow aborted." })),
407
335
  };
408
336
  }
409
337
 
@@ -471,9 +399,7 @@ export function createWebAuthnCeremony(options: {
471
399
  input,
472
400
  ),
473
401
  abort: async () =>
474
- validateCeremonyOutput(
475
- createTurn("abort", { hint: "WebAuthn ceremony aborted." }),
476
- ),
402
+ validateCeremonyOutput(createTurn("abort", { hint: "WebAuthn ceremony aborted." })),
477
403
  };
478
404
  }
479
405
 
@@ -560,9 +486,7 @@ export function createMagicLinkCeremony(options: {
560
486
  ctx,
561
487
  ),
562
488
  abort: async () =>
563
- validateCeremonyOutput(
564
- createTurn("abort", { hint: "Magic link flow aborted." }),
565
- ),
489
+ validateCeremonyOutput(createTurn("abort", { hint: "Magic link flow aborted." })),
566
490
  };
567
491
  }
568
492
 
@@ -582,7 +506,7 @@ export function createFormCeremony(options: {
582
506
  continue: (ctx, input = {}) =>
583
507
  runCeremonyHandler(
584
508
  async () => {
585
- const { prevalidate } = await import("../runtime/prevalidate");
509
+ const { prevalidate } = await import("../runtime/prevalidate.js");
586
510
  const result = prevalidate(options.schema, input);
587
511
  if (!result.valid) {
588
512
  throw new ValidationError("Form input failed validation.", {
@@ -592,9 +516,7 @@ export function createFormCeremony(options: {
592
516
 
593
517
  return createTurn("complete", {
594
518
  data: {
595
- credential: options.mapCredential
596
- ? options.mapCredential(input)
597
- : input,
519
+ credential: options.mapCredential ? options.mapCredential(input) : input,
598
520
  },
599
521
  hint: "Form completed.",
600
522
  });
@@ -604,15 +526,11 @@ export function createFormCeremony(options: {
604
526
  input,
605
527
  ),
606
528
  abort: async () =>
607
- validateCeremonyOutput(
608
- createTurn("abort", { hint: "Form ceremony aborted." }),
609
- ),
529
+ validateCeremonyOutput(createTurn("abort", { hint: "Form ceremony aborted." })),
610
530
  };
611
531
  }
612
532
 
613
- export function combineCeremonies(
614
- ...ceremonies: AuthFlowDefinition[]
615
- ): AuthFlowDefinition {
533
+ export function combineCeremonies(...ceremonies: AuthFlowDefinition[]): AuthFlowDefinition {
616
534
  function getStage(ctx: FlowContext): number {
617
535
  const rawStage = ctx.context.get(COMBINED_STAGE_KEY);
618
536
  return typeof rawStage === "number" ? rawStage : 0;
@@ -664,9 +582,7 @@ export function combineCeremonies(
664
582
  async () => {
665
583
  const current = ceremonies[getStage(ctx)];
666
584
  if (!current?.poll) {
667
- throw new ValidationError(
668
- "Current ceremony does not support polling.",
669
- );
585
+ throw new ValidationError("Current ceremony does not support polling.");
670
586
  }
671
587
  return await current.poll(ctx);
672
588
  },
@@ -714,9 +630,7 @@ export function createSwitchCeremony(options: {
714
630
  async () => {
715
631
  const storedChoice = ctx.context.get(SWITCH_SELECTION_KEY);
716
632
  const choice =
717
- typeof storedChoice === "string"
718
- ? storedChoice
719
- : getString(input, "choice");
633
+ typeof storedChoice === "string" ? storedChoice : getString(input, "choice");
720
634
 
721
635
  if (!choice || !options.choices[choice]) {
722
636
  throw new ValidationError("A valid choice is required.");
@@ -744,9 +658,7 @@ export function createSwitchCeremony(options: {
744
658
 
745
659
  const ceremony = options.choices[choice];
746
660
  if (!ceremony?.poll) {
747
- throw new ValidationError(
748
- "Selected ceremony does not support polling.",
749
- );
661
+ throw new ValidationError("Selected ceremony does not support polling.");
750
662
  }
751
663
 
752
664
  return await ceremony.poll(ctx);
@@ -2,6 +2,7 @@ export type ApifuseCommandName =
2
2
  | "create"
3
3
  | "dev"
4
4
  | "check"
5
+ | "sync-assets"
5
6
  | "submit-check"
6
7
  | "bounty-check"
7
8
  | "record"
@@ -46,6 +47,14 @@ export const COMMAND_MANIFEST: Record<
46
47
  examples: ["apifuse check .", "apifuse check providers/korea-air-quality"],
47
48
  modulePath: "./apifuse-check",
48
49
  },
50
+ "sync-assets": {
51
+ name: "sync-assets",
52
+ summary:
53
+ "Regenerate SDK-managed agent prompt assets (AGENTS.md, .agents/skills, symlinks, manifest) for the installed SDK version.",
54
+ usage: "apifuse sync-assets [path] [--check]",
55
+ examples: ["apifuse sync-assets .", "apifuse sync-assets . --check"],
56
+ modulePath: "./apifuse-sync-assets",
57
+ },
49
58
  "submit-check": {
50
59
  name: "submit-check",
51
60
  summary:
@@ -103,6 +112,7 @@ export const COMMAND_ORDER: ApifuseCommandName[] = [
103
112
  "create",
104
113
  "dev",
105
114
  "check",
115
+ "sync-assets",
106
116
  "submit-check",
107
117
  "record",
108
118
  "test",