@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.
- package/AUTHORING.md +240 -0
- package/CHANGELOG.md +93 -0
- package/README.md +26 -10
- package/SUBMISSION.md +11 -12
- package/bin/apifuse-check.ts +44 -59
- package/bin/apifuse-create.ts +1 -1
- package/bin/apifuse-dev.ts +27 -52
- package/bin/apifuse-pack-check.ts +36 -0
- package/bin/apifuse-pack-smoke.ts +22 -81
- package/bin/apifuse-pack-types.ts +266 -0
- package/bin/apifuse-perf.ts +45 -127
- package/bin/apifuse-record.ts +53 -70
- package/bin/apifuse-submit-check.ts +2177 -353
- package/bin/apifuse-sync-assets.ts +117 -0
- package/bin/apifuse.ts +1 -1
- package/bin/submit-check-delimited-text.ts +50 -0
- package/bin/submit-check-xml-semantics.ts +204 -0
- package/bin/submit-check-xml.ts +134 -0
- package/dist/auth-turn/auth-turn.v1.schema.json +89 -0
- package/dist/auth-turn/fixtures/invalid/empty-kind.json +4 -0
- package/dist/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
- package/dist/auth-turn/fixtures/invalid/missing-kind.json +3 -0
- package/dist/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
- package/dist/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
- package/dist/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
- package/dist/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
- package/dist/auth-turn/fixtures/valid/abort.json +8 -0
- package/dist/auth-turn/fixtures/valid/challenge.json +17 -0
- package/dist/auth-turn/fixtures/valid/complete.json +13 -0
- package/dist/auth-turn/fixtures/valid/form.json +14 -0
- package/dist/auth-turn/fixtures/valid/message.json +13 -0
- package/dist/auth-turn/fixtures/valid/multi_choice.json +15 -0
- package/dist/auth-turn/fixtures/valid/pending.json +5 -0
- package/dist/auth-turn/fixtures/valid/poll.json +9 -0
- package/dist/auth-turn/fixtures/valid/redirect.json +16 -0
- package/dist/auth-turn/fixtures/valid/retry.json +8 -0
- package/dist/auth-turn/fixtures/valid/unknown-kind.json +7 -0
- package/dist/auth-turn/index.d.ts +195 -0
- package/dist/auth-turn/index.js +133 -0
- package/dist/auth.d.ts +76 -0
- package/dist/auth.js +427 -0
- package/dist/ceremonies/index.d.ts +1 -1
- package/dist/ceremonies/index.js +14 -48
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +8 -0
- package/dist/cli/create.d.ts +3 -0
- package/dist/cli/create.js +47 -33
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
- package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
- package/dist/cli/templates/provider/.gitignore.tpl +22 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +96 -0
- package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
- package/dist/cli/templates/provider/README.md.tpl +163 -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 +149 -8
- package/dist/config/loader.js +378 -89
- package/dist/contract-serialization.d.ts +2 -2
- package/dist/contract-serialization.js +3 -6
- package/dist/contract-types.d.ts +2 -2
- package/dist/contract.d.ts +3 -3
- package/dist/contract.js +5 -6
- package/dist/define.d.ts +13 -1
- package/dist/define.js +245 -178
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +48 -0
- package/dist/i18n/catalog.d.ts +2 -2
- package/dist/i18n/catalog.js +4 -10
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/keys.d.ts +2 -2
- package/dist/index.d.ts +44 -41
- package/dist/index.js +39 -36
- package/dist/lint.d.ts +1 -0
- package/dist/lint.js +35 -15
- package/dist/provider.d.ts +11 -9
- package/dist/provider.js +9 -8
- package/dist/public-schema-field-lint.d.ts +1 -1
- package/dist/recipes/gov-api.js +1 -1
- package/dist/runtime/auth-flow.d.ts +1 -1
- package/dist/runtime/auth-flow.js +4 -2
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +214 -25
- package/dist/runtime/cache.d.ts +1 -1
- package/dist/runtime/cache.js +4 -8
- package/dist/runtime/choice.d.ts +1 -1
- package/dist/runtime/choice.js +31 -35
- package/dist/runtime/credential.d.ts +1 -1
- package/dist/runtime/credential.js +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/runtime/executor.d.ts +1 -1
- package/dist/runtime/executor.js +15 -3
- package/dist/runtime/http.d.ts +2 -2
- package/dist/runtime/http.js +160 -344
- package/dist/runtime/insights.d.ts +1 -1
- package/dist/runtime/insights.js +6 -13
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +56 -19
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- package/dist/runtime/otlp.d.ts +1 -1
- package/dist/runtime/perf.d.ts +1 -1
- package/dist/runtime/provider.d.ts +1 -1
- package/dist/runtime/provider.js +1 -2
- package/dist/runtime/proxy-errors.d.ts +1 -1
- package/dist/runtime/proxy-errors.js +9 -7
- package/dist/runtime/proxy-nodemaven.d.ts +35 -0
- package/dist/runtime/proxy-nodemaven.js +128 -0
- package/dist/runtime/proxy-retry-policy.d.ts +40 -0
- package/dist/runtime/proxy-retry-policy.js +326 -0
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +55 -52
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +2 -4
- package/dist/runtime/request-options.d.ts +1 -1
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +15 -4
- package/dist/runtime/stealth.d.ts +7 -4
- package/dist/runtime/stealth.js +257 -215
- package/dist/runtime/stt.d.ts +1 -1
- package/dist/runtime/stt.js +11 -15
- package/dist/runtime/trace.d.ts +2 -2
- package/dist/runtime/trace.js +2 -4
- package/dist/runtime/waterfall.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +7 -15
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/index.d.ts +7 -3
- package/dist/server/index.js +6 -2
- package/dist/server/self-test-input-tokens.d.ts +1 -0
- package/dist/server/self-test-input-tokens.js +37 -0
- package/dist/server/self-test-redaction.d.ts +20 -0
- package/dist/server/self-test-redaction.js +70 -0
- package/dist/server/self-test-token.d.ts +30 -0
- package/dist/server/self-test-token.js +50 -0
- package/dist/server/self-test.d.ts +199 -0
- package/dist/server/self-test.js +1113 -0
- package/dist/server/serve.d.ts +14 -3
- package/dist/server/serve.js +135 -64
- package/dist/server/types.d.ts +10 -9
- package/dist/server/types.js +3 -7
- package/dist/stealth/profiles.d.ts +1 -1
- package/dist/stealth/profiles.js +5 -14
- package/dist/stream.d.ts +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/run.d.ts +1 -1
- package/dist/testing/run.js +12 -15
- package/dist/types.d.ts +237 -1
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +16 -5
- package/src/auth-turn/auth-turn.v1.schema.json +89 -0
- package/src/auth-turn/fixtures/invalid/empty-kind.json +4 -0
- package/src/auth-turn/fixtures/invalid/expires-at-not-string.json +5 -0
- package/src/auth-turn/fixtures/invalid/missing-kind.json +3 -0
- package/src/auth-turn/fixtures/invalid/missing-turn-id.json +3 -0
- package/src/auth-turn/fixtures/invalid/timing-unknown-field.json +7 -0
- package/src/auth-turn/fixtures/invalid/turn-id-snake-case.json +4 -0
- package/src/auth-turn/fixtures/invalid/unknown-top-level-field.json +5 -0
- package/src/auth-turn/fixtures/valid/abort.json +8 -0
- package/src/auth-turn/fixtures/valid/challenge.json +17 -0
- package/src/auth-turn/fixtures/valid/complete.json +13 -0
- package/src/auth-turn/fixtures/valid/form.json +14 -0
- package/src/auth-turn/fixtures/valid/message.json +13 -0
- package/src/auth-turn/fixtures/valid/multi_choice.json +15 -0
- package/src/auth-turn/fixtures/valid/pending.json +5 -0
- package/src/auth-turn/fixtures/valid/poll.json +9 -0
- package/src/auth-turn/fixtures/valid/redirect.json +16 -0
- package/src/auth-turn/fixtures/valid/retry.json +8 -0
- package/src/auth-turn/fixtures/valid/unknown-kind.json +7 -0
- package/src/auth-turn/index.ts +177 -0
- package/src/auth.ts +728 -0
- package/src/ceremonies/index.ts +33 -121
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +69 -99
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl +13 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +96 -0
- package/src/cli/templates/provider/README.md.tpl +7 -4
- package/src/config/loader.ts +543 -208
- package/src/contract-serialization.ts +5 -11
- package/src/contract-types.ts +2 -2
- package/src/contract.ts +13 -28
- package/src/define.ts +397 -528
- package/src/dev.ts +4 -9
- package/src/errors.ts +58 -5
- package/src/i18n/catalog.ts +10 -32
- package/src/i18n/index.ts +2 -2
- package/src/i18n/keys.ts +5 -11
- package/src/index.ts +64 -41
- package/src/lint.ts +122 -159
- package/src/provider.ts +40 -9
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +6 -6
- package/src/runtime/browser.ts +320 -151
- package/src/runtime/cache.ts +20 -67
- package/src/runtime/choice.ts +79 -132
- package/src/runtime/credential.ts +2 -2
- package/src/runtime/env.ts +1 -1
- package/src/runtime/executor.ts +23 -20
- package/src/runtime/http.ts +216 -539
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +78 -65
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- package/src/runtime/otlp.ts +12 -23
- package/src/runtime/perf.ts +1 -1
- package/src/runtime/provider.ts +4 -9
- package/src/runtime/proxy-errors.ts +29 -42
- package/src/runtime/proxy-nodemaven.ts +178 -0
- package/src/runtime/proxy-retry-policy.ts +469 -0
- package/src/runtime/proxy-telemetry.ts +79 -77
- package/src/runtime/redis.ts +4 -12
- package/src/runtime/request-options.ts +4 -13
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +41 -110
- package/src/runtime/stealth.ts +331 -369
- package/src/runtime/stt.ts +38 -94
- package/src/runtime/trace.ts +14 -44
- package/src/runtime/waterfall.ts +5 -18
- package/src/schema.ts +23 -84
- package/src/serve.ts +1 -1
- package/src/server/index.ts +44 -3
- package/src/server/self-test-input-tokens.ts +46 -0
- package/src/server/self-test-redaction.ts +97 -0
- package/src/server/self-test-token.ts +70 -0
- package/src/server/self-test.ts +1450 -0
- package/src/server/serve.ts +206 -216
- package/src/server/types.ts +7 -19
- package/src/stealth/profiles.ts +10 -26
- package/src/stream.ts +8 -19
- package/src/testing/index.ts +2 -2
- package/src/testing/run.ts +24 -64
- package/src/types.ts +274 -1
- package/src/user-input.ts +118 -0
package/src/ceremonies/index.ts
CHANGED
|
@@ -1,67 +1,28 @@
|
|
|
1
1
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
2
2
|
|
|
3
|
-
import
|
|
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
|
-
|
|
13
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
package/src/cli/commands.ts
CHANGED
|
@@ -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",
|