@apifuse/provider-sdk 2.2.0-beta.33 → 2.2.0-beta.36
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/CHANGELOG.md +14 -1
- package/dist/ceremonies/index.d.ts +8 -0
- package/dist/ceremonies/index.js +32 -25
- package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
- package/dist/define.d.ts +7 -4
- package/dist/define.js +353 -0
- package/dist/index.d.ts +1 -1
- package/dist/runtime/auth-flow.d.ts +3 -1
- package/dist/runtime/auth-flow.js +1 -0
- package/dist/runtime/browser.js +6 -0
- package/dist/runtime/choice.js +33 -55
- package/dist/runtime/resolver-vendors/browser.js +1 -1
- package/dist/runtime/resolver-vendors/twocaptcha.js +15 -9
- package/dist/runtime/resolver-vendors/types.d.ts +4 -1
- package/dist/runtime/resolver-vendors/types.js +10 -1
- package/dist/runtime/resolver.js +13 -2
- package/dist/server/serve-implementation.d.ts +2 -1
- package/dist/server/serve-implementation.js +26 -15
- package/dist/testing/run.js +1 -0
- package/dist/types.d.ts +16 -2
- package/package.json +8 -2
- package/src/ceremonies/index.ts +45 -31
- package/src/cli/templates/provider/Dockerfile.tpl +1 -1
- package/src/define.ts +327 -8
- package/src/index.ts +1 -0
- package/src/runtime/auth-flow.ts +4 -0
- package/src/runtime/browser.ts +8 -0
- package/src/runtime/choice.ts +34 -68
- package/src/runtime/resolver-vendors/browser.ts +1 -1
- package/src/runtime/resolver-vendors/twocaptcha.ts +15 -11
- package/src/runtime/resolver-vendors/types.ts +16 -1
- package/src/runtime/resolver.ts +18 -2
- package/src/server/serve-implementation.ts +74 -15
- package/src/testing/run.ts +1 -0
- package/src/types.ts +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @apifuse/provider-sdk Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0-beta.36
|
|
4
|
+
|
|
5
|
+
- Release candidate for main commit c6858f8b87d78b3b755adeb28982e875434be406.
|
|
6
|
+
|
|
7
|
+
## 2.2.0-beta.35
|
|
8
|
+
|
|
9
|
+
- Release candidate for main commit 027fa0087b883a6281bc6d8bdaaf6d0be382000f.
|
|
10
|
+
|
|
11
|
+
## 2.2.0-beta.34
|
|
12
|
+
|
|
13
|
+
- Release candidate for main commit 383a97e7d0ce995d098d5f95c9ffdcbeed13de31.
|
|
14
|
+
|
|
3
15
|
## 2.2.0-beta.33
|
|
4
16
|
|
|
5
17
|
- Release candidate for main commit e7d854ec3e859702b22e2b37eaa2ae6bd4545c80.
|
|
@@ -50,7 +62,8 @@
|
|
|
50
62
|
|
|
51
63
|
## Unreleased
|
|
52
64
|
|
|
53
|
-
- Server-stored provider choices now issue word-format tokens unconditionally. The runtime issuance setting and legacy issuance path were removed
|
|
65
|
+
- Server-stored provider choices now issue word-format tokens unconditionally. The runtime issuance setting and legacy issuance path were removed.
|
|
66
|
+
- **Breaking:** Legacy encrypted server-handle choice tokens are no longer parsed. They are rejected with the uniform choice-not-found error; server-stored choices are now word-only. Encrypted inline choice tokens remain supported.
|
|
54
67
|
- Added the `thrown-error-code-undeclared` authoring lint (warning level): `apifuse check` now statically flags literal `ProviderError`/`ValidationError` codes that are neither SDK-registered nor declared in any operation's `docs.errorCodes`, surfacing the runtime `unregistered_provider_error_code` signal at check time. The canonical SDK code→status mapping moved to `SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES` in `error-resolution.ts`, shared by the runtime status resolver and the lint.
|
|
55
68
|
|
|
56
69
|
## 2.2.0-beta.21
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import type { AuthStartNoInputGuard } from "../define.js";
|
|
1
2
|
import type { AuthFlowDefinition, AuthTurn } from "../types.js";
|
|
2
3
|
type JsonObject = Record<string, unknown>;
|
|
3
4
|
export declare const OAUTH2_PROXIED_AUTH_PROXY_ORIGIN_ENV_KEY = "APIFUSE__AUTH_PROXY__URL";
|
|
4
5
|
export declare const OAUTH2_PROXIED_PKCE_VERIFIER_KEY = "__oauth2_proxied_pkce_verifier";
|
|
5
6
|
export declare function validateCeremonyOutput(turn: unknown): AuthTurn;
|
|
7
|
+
/**
|
|
8
|
+
* Defines an auth flow while preserving its concrete type for downstream checks.
|
|
9
|
+
* The compile-time guard validates the inferred literal; annotating or widening
|
|
10
|
+
* a flow to `AuthFlowDefinition` before passing it defeats the check. Full
|
|
11
|
+
* enforcement requires branding, which is deferred to a future major.
|
|
12
|
+
*/
|
|
13
|
+
export declare function defineAuthFlow<const TFlow extends AuthFlowDefinition>(flow: TFlow & AuthStartNoInputGuard<TFlow>): TFlow;
|
|
6
14
|
export declare function createOAuth2Ceremony(options: {
|
|
7
15
|
authorizeUrl: string;
|
|
8
16
|
tokenUrl: string;
|
package/dist/ceremonies/index.js
CHANGED
|
@@ -163,8 +163,17 @@ export function validateCeremonyOutput(turn) {
|
|
|
163
163
|
}
|
|
164
164
|
return turn;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Defines an auth flow while preserving its concrete type for downstream checks.
|
|
168
|
+
* The compile-time guard validates the inferred literal; annotating or widening
|
|
169
|
+
* a flow to `AuthFlowDefinition` before passing it defeats the check. Full
|
|
170
|
+
* enforcement requires branding, which is deferred to a future major.
|
|
171
|
+
*/
|
|
172
|
+
export function defineAuthFlow(flow) {
|
|
173
|
+
return flow;
|
|
174
|
+
}
|
|
166
175
|
export function createOAuth2Ceremony(options) {
|
|
167
|
-
return {
|
|
176
|
+
return defineAuthFlow({
|
|
168
177
|
start: (ctx) => runCeremonyHandler(async () => {
|
|
169
178
|
const clientId = getRequiredEnv(ctx, options.clientIdEnvKey);
|
|
170
179
|
getRequiredEnv(ctx, options.clientSecretEnvKey);
|
|
@@ -221,7 +230,7 @@ export function createOAuth2Ceremony(options) {
|
|
|
221
230
|
});
|
|
222
231
|
}, "OAuth token exchange failed", ctx, input),
|
|
223
232
|
abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "OAuth flow aborted." })),
|
|
224
|
-
};
|
|
233
|
+
});
|
|
225
234
|
}
|
|
226
235
|
/**
|
|
227
236
|
* Builds the start handler for a custom-scheme OAuth provider. The shared
|
|
@@ -272,7 +281,7 @@ export function createOAuth2ProxiedStart(options) {
|
|
|
272
281
|
}, "OAuth2 proxied start failed", ctx);
|
|
273
282
|
}
|
|
274
283
|
export function createDeviceFlowCeremony(options) {
|
|
275
|
-
return {
|
|
284
|
+
return defineAuthFlow({
|
|
276
285
|
start: (ctx) => runCeremonyHandler(async () => {
|
|
277
286
|
const response = await ctx.http.post(options.deviceCodeUrl, {
|
|
278
287
|
client_id: getRequiredEnv(ctx, options.clientIdEnvKey),
|
|
@@ -330,10 +339,10 @@ export function createDeviceFlowCeremony(options) {
|
|
|
330
339
|
});
|
|
331
340
|
}, "Device flow polling failed", ctx),
|
|
332
341
|
abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "Device flow aborted." })),
|
|
333
|
-
};
|
|
342
|
+
});
|
|
334
343
|
}
|
|
335
344
|
export function createWebAuthnCeremony(options) {
|
|
336
|
-
return {
|
|
345
|
+
return defineAuthFlow({
|
|
337
346
|
start: (ctx) => runCeremonyHandler(async () => {
|
|
338
347
|
const challenge = toBase64Url(randomBytes(32));
|
|
339
348
|
ctx.context.set("__webauthn_challenge", challenge);
|
|
@@ -375,21 +384,23 @@ export function createWebAuthnCeremony(options) {
|
|
|
375
384
|
});
|
|
376
385
|
}, "WebAuthn verification failed", ctx, input),
|
|
377
386
|
abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "WebAuthn ceremony aborted." })),
|
|
378
|
-
};
|
|
387
|
+
});
|
|
379
388
|
}
|
|
380
389
|
export function createMagicLinkCeremony(options) {
|
|
381
390
|
const emailField = options.emailField ?? "email";
|
|
382
|
-
|
|
383
|
-
|
|
391
|
+
const buildEmailForm = () => buildJsonSchemaForm({
|
|
392
|
+
type: "object",
|
|
393
|
+
required: [emailField],
|
|
394
|
+
properties: {
|
|
395
|
+
[emailField]: { type: "string", format: "email" },
|
|
396
|
+
},
|
|
397
|
+
}, "Provide the email address to receive a magic link.");
|
|
398
|
+
return defineAuthFlow({
|
|
399
|
+
start: (ctx) => runCeremonyHandler(async () => buildEmailForm(), "Magic link start failed", ctx),
|
|
400
|
+
continue: (ctx, input = {}) => runCeremonyHandler(async () => {
|
|
384
401
|
const email = getString(input, emailField);
|
|
385
402
|
if (!email) {
|
|
386
|
-
return
|
|
387
|
-
type: "object",
|
|
388
|
-
required: [emailField],
|
|
389
|
-
properties: {
|
|
390
|
-
[emailField]: { type: "string", format: "email" },
|
|
391
|
-
},
|
|
392
|
-
}, "Provide the email address to receive a magic link.");
|
|
403
|
+
return buildEmailForm();
|
|
393
404
|
}
|
|
394
405
|
await ctx.http.post(options.sendUrl, { email });
|
|
395
406
|
ctx.context.set(MAGIC_LINK_KEY, {
|
|
@@ -401,11 +412,7 @@ export function createMagicLinkCeremony(options) {
|
|
|
401
412
|
hint: "Check your email for the magic link, then poll for completion.",
|
|
402
413
|
timing: { suggestedPollIntervalMs: 5_000, maxWaitMs: 300_000 },
|
|
403
414
|
});
|
|
404
|
-
}, "Magic link
|
|
405
|
-
continue: async () => validateCeremonyOutput(createTurn("poll", {
|
|
406
|
-
hint: "Continue polling for magic link completion.",
|
|
407
|
-
timing: { suggestedPollIntervalMs: 5_000, maxWaitMs: 300_000 },
|
|
408
|
-
})),
|
|
415
|
+
}, "Magic link continuation failed", ctx, input),
|
|
409
416
|
poll: (ctx) => runCeremonyHandler(async () => {
|
|
410
417
|
const state = getNestedRecord(ctx, MAGIC_LINK_KEY);
|
|
411
418
|
const email = getString(state, "email");
|
|
@@ -431,10 +438,10 @@ export function createMagicLinkCeremony(options) {
|
|
|
431
438
|
});
|
|
432
439
|
}, "Magic link polling failed", ctx),
|
|
433
440
|
abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "Magic link flow aborted." })),
|
|
434
|
-
};
|
|
441
|
+
});
|
|
435
442
|
}
|
|
436
443
|
export function createFormCeremony(options) {
|
|
437
|
-
return {
|
|
444
|
+
return defineAuthFlow({
|
|
438
445
|
start: async () => validateCeremonyOutput(buildJsonSchemaForm(options.schema, options.hint ?? "Provide the required input to continue.")),
|
|
439
446
|
continue: (ctx, input = {}) => runCeremonyHandler(async () => {
|
|
440
447
|
const { prevalidate } = await import("../runtime/prevalidate.js");
|
|
@@ -452,7 +459,7 @@ export function createFormCeremony(options) {
|
|
|
452
459
|
});
|
|
453
460
|
}, "Form submission failed", ctx, input),
|
|
454
461
|
abort: async () => validateCeremonyOutput(createTurn("abort", { hint: "Form ceremony aborted." })),
|
|
455
|
-
};
|
|
462
|
+
});
|
|
456
463
|
}
|
|
457
464
|
export function combineCeremonies(...ceremonies) {
|
|
458
465
|
function getStage(ctx) {
|
|
@@ -504,7 +511,7 @@ export function combineCeremonies(...ceremonies) {
|
|
|
504
511
|
}
|
|
505
512
|
export function createSwitchCeremony(options) {
|
|
506
513
|
const choiceKeys = Object.keys(options.choices);
|
|
507
|
-
return {
|
|
514
|
+
return defineAuthFlow({
|
|
508
515
|
start: async () => validateCeremonyOutput(createTurn("multi_choice", {
|
|
509
516
|
data: { choices: choiceKeys },
|
|
510
517
|
hint: options.prompt ?? "Choose an authentication method.",
|
|
@@ -550,5 +557,5 @@ export function createSwitchCeremony(options) {
|
|
|
550
557
|
}
|
|
551
558
|
return createTurn("abort", { hint: "Switch ceremony aborted." });
|
|
552
559
|
}, "Switch ceremony abort failed", ctx),
|
|
553
|
-
};
|
|
560
|
+
});
|
|
554
561
|
}
|
package/dist/define.d.ts
CHANGED
|
@@ -30,15 +30,18 @@ type WebSocketOperationConfig<TInput extends SchemaLike, TOutput extends SchemaL
|
|
|
30
30
|
transport: OperationWebSocketTransport;
|
|
31
31
|
handler(ctx: Parameters<OperationDefinition<TInput, TOutput>["handler"]>[0], input: InferSchemaOutput<TInput>): Response | ReadableStream<Uint8Array> | Promise<Response | ReadableStream<Uint8Array>>;
|
|
32
32
|
};
|
|
33
|
-
type
|
|
33
|
+
type AuthStartHandlerNoInputGuard<TStart> = TStart extends (...args: infer TArgs) => unknown ? TArgs["length"] extends 0 | 1 ? unknown : {
|
|
34
|
+
"auth start handlers must not declare input parameters; return a form turn from start and receive user input in continue": never;
|
|
35
|
+
} : unknown;
|
|
36
|
+
export type AuthStartNoInputGuard<TConfig> = TConfig extends {
|
|
34
37
|
auth?: {
|
|
35
38
|
flow?: {
|
|
36
39
|
start: infer TStart;
|
|
37
40
|
};
|
|
38
41
|
};
|
|
39
|
-
} ? TStart
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
+
} ? AuthStartHandlerNoInputGuard<TStart> : TConfig extends {
|
|
43
|
+
start: infer TStart;
|
|
44
|
+
} ? AuthStartHandlerNoInputGuard<TStart> : unknown;
|
|
42
45
|
export interface ProviderConfig<TOperations extends Record<string, ProviderOperation>> {
|
|
43
46
|
id: string;
|
|
44
47
|
version: string;
|
package/dist/define.js
CHANGED
|
@@ -109,6 +109,346 @@ function parsePositiveMsDuration(value) {
|
|
|
109
109
|
return undefined;
|
|
110
110
|
return parsed;
|
|
111
111
|
}
|
|
112
|
+
function splitAuthStartParameters(parameters) {
|
|
113
|
+
const parts = [];
|
|
114
|
+
let start = 0;
|
|
115
|
+
let round = 0;
|
|
116
|
+
let square = 0;
|
|
117
|
+
let curly = 0;
|
|
118
|
+
let quote;
|
|
119
|
+
let escaped = false;
|
|
120
|
+
let lineComment = false;
|
|
121
|
+
let blockComment = false;
|
|
122
|
+
const templateDepths = [0];
|
|
123
|
+
templateDepths.length = 0;
|
|
124
|
+
for (let index = 0; index < parameters.length; index++) {
|
|
125
|
+
const character = parameters[index];
|
|
126
|
+
const nextCharacter = parameters[index + 1];
|
|
127
|
+
if (lineComment) {
|
|
128
|
+
if (character === "\n" || character === "\r")
|
|
129
|
+
lineComment = false;
|
|
130
|
+
else
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (blockComment) {
|
|
134
|
+
if (character === "*" && nextCharacter === "/") {
|
|
135
|
+
blockComment = false;
|
|
136
|
+
index++;
|
|
137
|
+
}
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (quote) {
|
|
141
|
+
if (escaped) {
|
|
142
|
+
escaped = false;
|
|
143
|
+
}
|
|
144
|
+
else if (character === "\\") {
|
|
145
|
+
escaped = true;
|
|
146
|
+
}
|
|
147
|
+
else if (quote === "`" && character === "$" && nextCharacter === "{") {
|
|
148
|
+
curly++;
|
|
149
|
+
templateDepths.push(curly);
|
|
150
|
+
quote = undefined;
|
|
151
|
+
index++;
|
|
152
|
+
}
|
|
153
|
+
else if (character === quote) {
|
|
154
|
+
quote = undefined;
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (character === "'" || character === '"' || character === "`") {
|
|
159
|
+
quote = character;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (character === "/" && nextCharacter === "/") {
|
|
163
|
+
lineComment = true;
|
|
164
|
+
index++;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (character === "/" && nextCharacter === "*") {
|
|
168
|
+
blockComment = true;
|
|
169
|
+
index++;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (character === "/")
|
|
173
|
+
return undefined;
|
|
174
|
+
// Annex B HTML-like comments are not lexed here; give up rather than
|
|
175
|
+
// risk misreading the parameter list.
|
|
176
|
+
if (character === "<" && parameters.startsWith("!--", index + 1))
|
|
177
|
+
return undefined;
|
|
178
|
+
if (character === "-" && parameters.startsWith("->", index + 1))
|
|
179
|
+
return undefined;
|
|
180
|
+
if (character === "(")
|
|
181
|
+
round++;
|
|
182
|
+
else if (character === ")")
|
|
183
|
+
round--;
|
|
184
|
+
else if (character === "[")
|
|
185
|
+
square++;
|
|
186
|
+
else if (character === "]")
|
|
187
|
+
square--;
|
|
188
|
+
else if (character === "{")
|
|
189
|
+
curly++;
|
|
190
|
+
else if (character === "}") {
|
|
191
|
+
if (templateDepths.at(-1) === curly) {
|
|
192
|
+
templateDepths.pop();
|
|
193
|
+
curly--;
|
|
194
|
+
quote = "`";
|
|
195
|
+
}
|
|
196
|
+
else
|
|
197
|
+
curly--;
|
|
198
|
+
}
|
|
199
|
+
else if (character === "," && round === 0 && square === 0 && curly === 0) {
|
|
200
|
+
parts.push(parameters.slice(start, index));
|
|
201
|
+
start = index + 1;
|
|
202
|
+
}
|
|
203
|
+
if (round < 0 || square < 0 || curly < 0)
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
if (quote ||
|
|
207
|
+
blockComment ||
|
|
208
|
+
templateDepths.length > 0 ||
|
|
209
|
+
round !== 0 ||
|
|
210
|
+
square !== 0 ||
|
|
211
|
+
curly !== 0)
|
|
212
|
+
return undefined;
|
|
213
|
+
parts.push(parameters.slice(start));
|
|
214
|
+
return parts;
|
|
215
|
+
}
|
|
216
|
+
function authStartParameterList(source) {
|
|
217
|
+
let index = 0;
|
|
218
|
+
while (index < source.length && /\s/.test(source[index] ?? ""))
|
|
219
|
+
index++;
|
|
220
|
+
if (index >= source.length)
|
|
221
|
+
return undefined;
|
|
222
|
+
let openIndex = -1;
|
|
223
|
+
let parenthesizedArrow = false;
|
|
224
|
+
let asyncMethodOrArrow = false;
|
|
225
|
+
const skipTrivia = () => {
|
|
226
|
+
while (index < source.length) {
|
|
227
|
+
if (/\s/.test(source[index] ?? "")) {
|
|
228
|
+
index++;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (source[index] === "/" && source[index + 1] === "/") {
|
|
232
|
+
index += 2;
|
|
233
|
+
while (index < source.length && source[index] !== "\n" && source[index] !== "\r")
|
|
234
|
+
index++;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (source[index] === "/" && source[index + 1] === "*") {
|
|
238
|
+
const end = source.indexOf("*/", index + 2);
|
|
239
|
+
if (end < 0) {
|
|
240
|
+
index = source.length;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
index = end + 2;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const initial = source.slice(index);
|
|
250
|
+
const isAsync = initial.startsWith("async") && !/[\w$]/.test(initial[5] ?? "");
|
|
251
|
+
if (isAsync) {
|
|
252
|
+
index += 5;
|
|
253
|
+
skipTrivia();
|
|
254
|
+
}
|
|
255
|
+
const afterAsync = source.slice(index);
|
|
256
|
+
const isFunction = afterAsync.startsWith("function") && !/[\w$]/.test(afterAsync[8] ?? "");
|
|
257
|
+
if (isFunction) {
|
|
258
|
+
index += 8;
|
|
259
|
+
skipTrivia();
|
|
260
|
+
if (source[index] === "*") {
|
|
261
|
+
index++;
|
|
262
|
+
skipTrivia();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else if (source[index] === "*") {
|
|
266
|
+
index++;
|
|
267
|
+
skipTrivia();
|
|
268
|
+
}
|
|
269
|
+
if (source[index] === "(") {
|
|
270
|
+
openIndex = index;
|
|
271
|
+
parenthesizedArrow = !isFunction;
|
|
272
|
+
asyncMethodOrArrow = isAsync && !isFunction;
|
|
273
|
+
}
|
|
274
|
+
else if (isFunction) {
|
|
275
|
+
if (!/[A-Za-z_$]/.test(source[index] ?? ""))
|
|
276
|
+
return undefined;
|
|
277
|
+
index++;
|
|
278
|
+
while (index < source.length && /[A-Za-z0-9_$]/.test(source[index] ?? ""))
|
|
279
|
+
index++;
|
|
280
|
+
skipTrivia();
|
|
281
|
+
if (source[index] !== "(")
|
|
282
|
+
return undefined;
|
|
283
|
+
openIndex = index;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
const identifierStart = index;
|
|
287
|
+
if (!/[A-Za-z_$]/.test(source[index] ?? ""))
|
|
288
|
+
return undefined;
|
|
289
|
+
index++;
|
|
290
|
+
while (index < source.length && /[A-Za-z0-9_$]/.test(source[index] ?? ""))
|
|
291
|
+
index++;
|
|
292
|
+
const firstIdentifier = source.slice(identifierStart, index);
|
|
293
|
+
skipTrivia();
|
|
294
|
+
if (source[index] === "=" && source[index + 1] === ">")
|
|
295
|
+
return undefined;
|
|
296
|
+
if (source[index] !== "(") {
|
|
297
|
+
if (firstIdentifier !== "get" && firstIdentifier !== "set")
|
|
298
|
+
return undefined;
|
|
299
|
+
if (!/[A-Za-z_$]/.test(source[index] ?? ""))
|
|
300
|
+
return undefined;
|
|
301
|
+
index++;
|
|
302
|
+
while (index < source.length && /[A-Za-z0-9_$]/.test(source[index] ?? ""))
|
|
303
|
+
index++;
|
|
304
|
+
skipTrivia();
|
|
305
|
+
}
|
|
306
|
+
if (source[index] !== "(")
|
|
307
|
+
return undefined;
|
|
308
|
+
openIndex = index;
|
|
309
|
+
}
|
|
310
|
+
if (openIndex < 0)
|
|
311
|
+
return undefined;
|
|
312
|
+
let depth = 1;
|
|
313
|
+
let square = 0;
|
|
314
|
+
let curly = 0;
|
|
315
|
+
let quote;
|
|
316
|
+
let escaped = false;
|
|
317
|
+
let lineComment = false;
|
|
318
|
+
let blockComment = false;
|
|
319
|
+
const templateDepths = [0];
|
|
320
|
+
templateDepths.length = 0;
|
|
321
|
+
for (index = openIndex + 1; index < source.length; index++) {
|
|
322
|
+
const character = source[index];
|
|
323
|
+
const nextCharacter = source[index + 1];
|
|
324
|
+
if (lineComment) {
|
|
325
|
+
if (character === "\n" || character === "\r")
|
|
326
|
+
lineComment = false;
|
|
327
|
+
else
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (blockComment) {
|
|
331
|
+
if (character === "*" && nextCharacter === "/") {
|
|
332
|
+
blockComment = false;
|
|
333
|
+
index++;
|
|
334
|
+
}
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (quote) {
|
|
338
|
+
if (escaped)
|
|
339
|
+
escaped = false;
|
|
340
|
+
else if (character === "\\")
|
|
341
|
+
escaped = true;
|
|
342
|
+
else if (quote === "`" && character === "$" && nextCharacter === "{") {
|
|
343
|
+
curly++;
|
|
344
|
+
templateDepths.push(curly);
|
|
345
|
+
quote = undefined;
|
|
346
|
+
index++;
|
|
347
|
+
}
|
|
348
|
+
else if (character === quote)
|
|
349
|
+
quote = undefined;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (character === "'" || character === '"' || character === "`") {
|
|
353
|
+
quote = character;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (character === "/" && nextCharacter === "/") {
|
|
357
|
+
lineComment = true;
|
|
358
|
+
index++;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (character === "/" && nextCharacter === "*") {
|
|
362
|
+
blockComment = true;
|
|
363
|
+
index++;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (character === "/")
|
|
367
|
+
return undefined;
|
|
368
|
+
// Annex B HTML-like comments are not lexed here; give up rather than
|
|
369
|
+
// risk misreading the parameter list.
|
|
370
|
+
if (character === "<" && source.startsWith("!--", index + 1))
|
|
371
|
+
return undefined;
|
|
372
|
+
if (character === "-" && source.startsWith("->", index + 1))
|
|
373
|
+
return undefined;
|
|
374
|
+
if (character === "(")
|
|
375
|
+
depth++;
|
|
376
|
+
else if (character === ")") {
|
|
377
|
+
depth--;
|
|
378
|
+
if (depth === 0 && square === 0 && curly === 0) {
|
|
379
|
+
const closeIndex = index;
|
|
380
|
+
if (parenthesizedArrow) {
|
|
381
|
+
index++;
|
|
382
|
+
skipTrivia();
|
|
383
|
+
const hasArrow = source[index] === "=" && source[index + 1] === ">";
|
|
384
|
+
if (!hasArrow && (!asyncMethodOrArrow || source[index] !== "{"))
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
return source.slice(openIndex + 1, closeIndex);
|
|
388
|
+
}
|
|
389
|
+
if (depth < 0)
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
else if (character === "[")
|
|
393
|
+
square++;
|
|
394
|
+
else if (character === "]") {
|
|
395
|
+
square--;
|
|
396
|
+
if (square < 0)
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
else if (character === "{")
|
|
400
|
+
curly++;
|
|
401
|
+
else if (character === "}") {
|
|
402
|
+
if (templateDepths.at(-1) === curly) {
|
|
403
|
+
templateDepths.pop();
|
|
404
|
+
curly--;
|
|
405
|
+
quote = "`";
|
|
406
|
+
}
|
|
407
|
+
else
|
|
408
|
+
curly--;
|
|
409
|
+
if (curly < 0)
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Conservative defense in depth for defaulted second parameters, which
|
|
417
|
+
* JavaScript intentionally omits from Function.length. Ambiguous source is
|
|
418
|
+
* ignored so this check can never reject a valid provider on weak evidence.
|
|
419
|
+
*/
|
|
420
|
+
function authStartHasHiddenInput(start) {
|
|
421
|
+
let source;
|
|
422
|
+
try {
|
|
423
|
+
source = Function.prototype.toString.call(start);
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
if (!source ||
|
|
429
|
+
source.includes("[native code]") ||
|
|
430
|
+
/^\s*(?:async\s+)?function\s+bound\b/.test(source))
|
|
431
|
+
return false;
|
|
432
|
+
const parameters = authStartParameterList(source);
|
|
433
|
+
if (!parameters)
|
|
434
|
+
return false;
|
|
435
|
+
const parts = splitAuthStartParameters(parameters);
|
|
436
|
+
if (!parts || parts.length < 2)
|
|
437
|
+
return false;
|
|
438
|
+
// Require ordinary, readable source formatting. This intentionally fails
|
|
439
|
+
// open for minified output and for transpilers that rewrite defaults.
|
|
440
|
+
const commaIndex = parameters.indexOf(",");
|
|
441
|
+
if (commaIndex < 0 || !/\s/.test(parameters[commaIndex + 1] ?? ""))
|
|
442
|
+
return false;
|
|
443
|
+
const first = parts[0].trim();
|
|
444
|
+
const second = parts[1].trim();
|
|
445
|
+
const identifier = /^[_$A-Za-z][_$A-Za-z0-9]*/;
|
|
446
|
+
const firstName = first.match(identifier)?.[0];
|
|
447
|
+
const secondName = second.match(identifier)?.[0];
|
|
448
|
+
if (!firstName || !secondName || firstName.length < 3 || secondName.length < 3)
|
|
449
|
+
return false;
|
|
450
|
+
return /\s=\s/.test(second);
|
|
451
|
+
}
|
|
112
452
|
/** Define one provider operation with schema-driven handler inference. */
|
|
113
453
|
export function defineOperation(operation) {
|
|
114
454
|
return operation;
|
|
@@ -241,6 +581,19 @@ function validateProviderShape(config) {
|
|
|
241
581
|
fix: "Return a form turn from start(ctx), then receive user input in continue(ctx, input).",
|
|
242
582
|
});
|
|
243
583
|
}
|
|
584
|
+
if (auth &&
|
|
585
|
+
typeof auth === "object" &&
|
|
586
|
+
"flow" in auth &&
|
|
587
|
+
auth.flow &&
|
|
588
|
+
typeof auth.flow === "object" &&
|
|
589
|
+
"start" in auth.flow &&
|
|
590
|
+
typeof auth.flow.start === "function" &&
|
|
591
|
+
auth.flow.start.length <= 1 &&
|
|
592
|
+
authStartHasHiddenInput(auth.flow.start)) {
|
|
593
|
+
throw new ProviderError(`Provider "${String(config.id)}" auth.flow.start must not declare an input parameter`, {
|
|
594
|
+
fix: "Return a form turn from start(ctx), then receive user input in continue(ctx, input).",
|
|
595
|
+
});
|
|
596
|
+
}
|
|
244
597
|
const access = config.access;
|
|
245
598
|
if (access !== undefined) {
|
|
246
599
|
if (!access || typeof access !== "object" || Array.isArray(access)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from "./choice-token.js";
|
|
|
4
4
|
export type { ApiFuseConfig, BrowserConfig, ProxyProtocol, ProxyResolutionOptions, ProxyResolutionSource, ProxyVendorName, ResolvedProxyConfig, SessionConfig, } from "./config/loader.js";
|
|
5
5
|
export { defineConfig, loadApiFuseConfig, resolveProxy } from "./config/loader.js";
|
|
6
6
|
export { canonicalJson, digestProviderContract, extractProviderContract, type JsonPrimitive, type JsonValue, PROVIDER_CONTRACT_SCHEMA_VERSION, type ProviderContractOperation, type ProviderContractSnapshot, } from "./contract.js";
|
|
7
|
-
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, type ProviderConfig, } from "./define.js";
|
|
7
|
+
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, defineStreamOperation, every, type AuthStartNoInputGuard, type ProviderConfig, } from "./define.js";
|
|
8
8
|
export type { DevServerOptions } from "./dev.js";
|
|
9
9
|
export { createDevServer, startDevServer } from "./dev.js";
|
|
10
10
|
export * from "./errors.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, OcrContext, StealthClient, SttContext } from "../types.js";
|
|
1
|
+
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, OcrContext, ProviderRuntimeState, StealthClient, SttContext } from "../types.js";
|
|
2
2
|
export declare function createScratchpad(allowedKeys: string[], initial?: Record<string, unknown>): ContextScratchpad;
|
|
3
3
|
export declare function createFlowContext(options: {
|
|
4
4
|
flowId?: string;
|
|
@@ -9,6 +9,8 @@ export declare function createFlowContext(options: {
|
|
|
9
9
|
providerId: string;
|
|
10
10
|
connectionId?: string;
|
|
11
11
|
externalRef?: string;
|
|
12
|
+
/** Host-agnostic: callers pass an already-scoped runtime state, which this helper forwards verbatim. */
|
|
13
|
+
state?: ProviderRuntimeState;
|
|
12
14
|
allowedKeys: string[];
|
|
13
15
|
initialContext?: Record<string, unknown>;
|
|
14
16
|
ocr?: OcrContext;
|
|
@@ -40,6 +40,7 @@ export function createFlowContext(options) {
|
|
|
40
40
|
tenantId: options.tenantId,
|
|
41
41
|
providerId: options.providerId,
|
|
42
42
|
http: options.http,
|
|
43
|
+
state: options.state,
|
|
43
44
|
stealth: options.stealth,
|
|
44
45
|
env: options.env,
|
|
45
46
|
context: createScratchpad(options.allowedKeys, options.initialContext),
|
package/dist/runtime/browser.js
CHANGED
|
@@ -557,6 +557,9 @@ class PlaywrightBrowserPage {
|
|
|
557
557
|
}
|
|
558
558
|
return await this.page.evaluate(fn);
|
|
559
559
|
}
|
|
560
|
+
async userAgent() {
|
|
561
|
+
return await this.evaluate("navigator.userAgent");
|
|
562
|
+
}
|
|
560
563
|
async waitForSelector(selector, options) {
|
|
561
564
|
await this.page.waitForSelector(selector, options);
|
|
562
565
|
}
|
|
@@ -1117,6 +1120,9 @@ class CdpPoolBrowserPage {
|
|
|
1117
1120
|
await this.initialize();
|
|
1118
1121
|
return await this.evaluateWithContext(fn);
|
|
1119
1122
|
}
|
|
1123
|
+
async userAgent() {
|
|
1124
|
+
return await this.evaluate("navigator.userAgent");
|
|
1125
|
+
}
|
|
1120
1126
|
async evaluateInFrame(frameId, fn) {
|
|
1121
1127
|
await this.initialize();
|
|
1122
1128
|
const contextId = await this.getFrameExecutionContextId(frameId);
|