dsh-keys-manager 0.2.4 → 0.2.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.
- package/CHANGELOG.md +23 -0
- package/README.md +49 -4
- package/README.zh-CN.md +24 -4
- package/lib/client/types.d.ts +2 -0
- package/lib/client.js +103 -15
- package/lib/domain.d.ts +14 -1
- package/lib/host-types.d.ts +12 -3
- package/lib/index.d.ts +102 -4
- package/lib/index.js +445 -66
- package/lib/index.js.map +1 -1
- package/lib/oauth/adapter.d.ts +59 -0
- package/lib/oauth/adapter.js +47 -0
- package/lib/oauth/adapter.js.map +1 -0
- package/lib/oauth/providers.d.ts +31 -0
- package/lib/oauth/providers.js +34 -0
- package/lib/oauth/providers.js.map +1 -0
- package/lib/oauth/signin.d.ts +58 -0
- package/lib/oauth/signin.js +112 -0
- package/lib/oauth/signin.js.map +1 -0
- package/lib/omp-oauth/oauth.mjs +1785 -0
- package/locale/en.json +5 -1
- package/locale/zh.json +5 -1
- package/package.json +9 -4
- package/scripts/verify-dist.mjs +18 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one module that knows where the build-time omp sign-in bundle lives.
|
|
3
|
+
*
|
|
4
|
+
* `scripts/omp-oauth/build-oauth.mjs` inlines the two omp login flows into
|
|
5
|
+
* `lib/omp-oauth/oauth.mjs`; nothing else in `src/` may reference that artifact.
|
|
6
|
+
* The specifier is built from `import.meta.url` and held in a variable so `tsc`
|
|
7
|
+
* and any bundler cannot follow it: from `lib/oauth/adapter.js` it resolves to
|
|
8
|
+
* `lib/omp-oauth/oauth.mjs`, and under `vitest` (which runs `src/`) it resolves
|
|
9
|
+
* to a path that does not exist — which is exactly why the host takes an
|
|
10
|
+
* injectable adapter and no unit test ever loads the real artifact.
|
|
11
|
+
*
|
|
12
|
+
* The load is cached: a sign-in attempt may run repeatedly, and the artifact is
|
|
13
|
+
* one static module. A failed load is cached too — a missing artifact is a
|
|
14
|
+
* packaging defect, not a transient condition.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-keys-manager/oauth/adapter
|
|
17
|
+
*/
|
|
18
|
+
/** The controller surface omp's flows call back into. */
|
|
19
|
+
export interface OmpOAuthController {
|
|
20
|
+
onAuth?: (info: {
|
|
21
|
+
url: string;
|
|
22
|
+
launchUrl?: string;
|
|
23
|
+
instructions?: string;
|
|
24
|
+
}) => void;
|
|
25
|
+
onProgress?: (message: string) => void;
|
|
26
|
+
onManualCodeInput?: (signal?: AbortSignal) => Promise<string>;
|
|
27
|
+
onPrompt?: (prompt: {
|
|
28
|
+
message: string;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
allowEmpty?: boolean;
|
|
31
|
+
secret?: boolean;
|
|
32
|
+
}) => Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Deliberately not wired: an isolated host-owned browser is a capability
|
|
35
|
+
* this surface has no equivalent for. A flow that needs it (no flow in this
|
|
36
|
+
* batch does) fails as unsupported instead of silently hanging on a callback
|
|
37
|
+
* that never arrives.
|
|
38
|
+
*/
|
|
39
|
+
onBrowserSession?: never;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
fetch?: typeof fetch;
|
|
42
|
+
}
|
|
43
|
+
/** The credential omp's flows resolve with (static tokens carry `refresh: ''`). */
|
|
44
|
+
export interface OmpOAuthCredentials {
|
|
45
|
+
access: string;
|
|
46
|
+
refresh: string;
|
|
47
|
+
expires: number;
|
|
48
|
+
}
|
|
49
|
+
/** The two drivers the artifact exports, and nothing else. */
|
|
50
|
+
export interface OmpOAuthAdapter {
|
|
51
|
+
loginKilo(controller: OmpOAuthController): Promise<OmpOAuthCredentials>;
|
|
52
|
+
loginZaiCodingPlan(controller: OmpOAuthController): Promise<OmpOAuthCredentials>;
|
|
53
|
+
}
|
|
54
|
+
/** The artifact is absent or does not export the expected drivers. */
|
|
55
|
+
export declare class OmpOAuthBundleMissingError extends Error {
|
|
56
|
+
constructor(cause: unknown);
|
|
57
|
+
}
|
|
58
|
+
/** Load (once) and return the bundled omp sign-in drivers. */
|
|
59
|
+
export declare function ompOAuthAdapter(): Promise<OmpOAuthAdapter>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one module that knows where the build-time omp sign-in bundle lives.
|
|
3
|
+
*
|
|
4
|
+
* `scripts/omp-oauth/build-oauth.mjs` inlines the two omp login flows into
|
|
5
|
+
* `lib/omp-oauth/oauth.mjs`; nothing else in `src/` may reference that artifact.
|
|
6
|
+
* The specifier is built from `import.meta.url` and held in a variable so `tsc`
|
|
7
|
+
* and any bundler cannot follow it: from `lib/oauth/adapter.js` it resolves to
|
|
8
|
+
* `lib/omp-oauth/oauth.mjs`, and under `vitest` (which runs `src/`) it resolves
|
|
9
|
+
* to a path that does not exist — which is exactly why the host takes an
|
|
10
|
+
* injectable adapter and no unit test ever loads the real artifact.
|
|
11
|
+
*
|
|
12
|
+
* The load is cached: a sign-in attempt may run repeatedly, and the artifact is
|
|
13
|
+
* one static module. A failed load is cached too — a missing artifact is a
|
|
14
|
+
* packaging defect, not a transient condition.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-keys-manager/oauth/adapter
|
|
17
|
+
*/
|
|
18
|
+
/** The artifact is absent or does not export the expected drivers. */
|
|
19
|
+
export class OmpOAuthBundleMissingError extends Error {
|
|
20
|
+
constructor(cause) {
|
|
21
|
+
super('The bundled omp sign-in flows are missing from this build; run `pnpm build` (lib/omp-oauth/oauth.mjs) '
|
|
22
|
+
+ 'or reinstall the package', { cause });
|
|
23
|
+
this.name = 'OmpOAuthBundleMissingError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Variable specifier: `tsc` and bundlers must not resolve the build artifact. */
|
|
27
|
+
const ARTIFACT = new URL('../omp-oauth/oauth.mjs', import.meta.url).href;
|
|
28
|
+
let load;
|
|
29
|
+
async function loadArtifact() {
|
|
30
|
+
let module;
|
|
31
|
+
try {
|
|
32
|
+
module = (await import(ARTIFACT));
|
|
33
|
+
}
|
|
34
|
+
catch (cause) {
|
|
35
|
+
throw new OmpOAuthBundleMissingError(cause);
|
|
36
|
+
}
|
|
37
|
+
if (typeof module.loginKilo !== 'function' || typeof module.loginZaiCodingPlan !== 'function') {
|
|
38
|
+
throw new OmpOAuthBundleMissingError(new Error('the artifact does not export both sign-in drivers'));
|
|
39
|
+
}
|
|
40
|
+
return { loginKilo: module.loginKilo, loginZaiCodingPlan: module.loginZaiCodingPlan };
|
|
41
|
+
}
|
|
42
|
+
/** Load (once) and return the bundled omp sign-in drivers. */
|
|
43
|
+
export function ompOAuthAdapter() {
|
|
44
|
+
load ??= loadArtifact();
|
|
45
|
+
return load;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/oauth/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAgCH,sEAAsE;AACtE,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,KAAc;QACxB,KAAK,CACH,wGAAwG;cACpG,0BAA0B,EAC9B,EAAE,KAAK,EAAE,CACV,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAExE,IAAI,IAA0C,CAAA;AAE9C,KAAK,UAAU,YAAY;IACzB,IAAI,MAAgC,CAAA;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,CAA6B,CAAA;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,0BAA0B,CAAC,KAAK,CAAC,CAAA;IAC7C,CAAC;IACD,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,IAAI,OAAO,MAAM,CAAC,kBAAkB,KAAK,UAAU,EAAE,CAAC;QAC9F,MAAM,IAAI,0BAA0B,CAAC,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC,CAAA;IACtG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,EAAE,CAAA;AACvF,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,eAAe;IAC7B,IAAI,KAAK,YAAY,EAAE,CAAA;IACvB,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which providers this plugin can sign in to, and with which omp driver.
|
|
3
|
+
*
|
|
4
|
+
* This table is the *second* source of the account-capability verdict in
|
|
5
|
+
* `src/index.ts`: the first is the Harness authorization seam's flow list
|
|
6
|
+
* (`llm-pi-ai/<provider>`). A sign-in listed here runs in-process — see
|
|
7
|
+
* `.mstar/sdd/issue15-batch2/oauth-clients-design.md` §4.6 for why the seam's
|
|
8
|
+
* `registerFlow` cannot express a per-account-row pool.
|
|
9
|
+
*
|
|
10
|
+
* Both drivers mint a *static* credential (a one-year bearer, a durable
|
|
11
|
+
* `id.secret` key), so their output lands in the pool as an ordinary api-key
|
|
12
|
+
* row and never as a refreshable grant.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-keys-manager/oauth/providers
|
|
15
|
+
*/
|
|
16
|
+
/** One sign-in-capable provider: the omp driver it runs and its display label. */
|
|
17
|
+
export interface SignInProvider {
|
|
18
|
+
/** The exported driver inside `lib/omp-oauth/oauth.mjs`. */
|
|
19
|
+
readonly driver: 'kilo' | 'zai-coding-plan';
|
|
20
|
+
/** Human label used in notices and the default row alias. */
|
|
21
|
+
readonly label: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Provider id → its sign-in. The ids are the *routes* the credentials serve,
|
|
25
|
+
* which for `zai` is the shipped DSH route (the omp flow is `zai-coding-plan`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const SIGN_IN_PROVIDERS: Readonly<Record<string, SignInProvider>>;
|
|
28
|
+
/** Whether this plugin can obtain a credential for `provider` by signing in. */
|
|
29
|
+
export declare function signInCapable(provider: string): boolean;
|
|
30
|
+
/** The sign-in driver for `provider`, or `undefined` when it is not supported. */
|
|
31
|
+
export declare function signInProvider(provider: string): SignInProvider | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which providers this plugin can sign in to, and with which omp driver.
|
|
3
|
+
*
|
|
4
|
+
* This table is the *second* source of the account-capability verdict in
|
|
5
|
+
* `src/index.ts`: the first is the Harness authorization seam's flow list
|
|
6
|
+
* (`llm-pi-ai/<provider>`). A sign-in listed here runs in-process — see
|
|
7
|
+
* `.mstar/sdd/issue15-batch2/oauth-clients-design.md` §4.6 for why the seam's
|
|
8
|
+
* `registerFlow` cannot express a per-account-row pool.
|
|
9
|
+
*
|
|
10
|
+
* Both drivers mint a *static* credential (a one-year bearer, a durable
|
|
11
|
+
* `id.secret` key), so their output lands in the pool as an ordinary api-key
|
|
12
|
+
* row and never as a refreshable grant.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-keys-manager/oauth/providers
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Provider id → its sign-in. The ids are the *routes* the credentials serve,
|
|
18
|
+
* which for `zai` is the shipped DSH route (the omp flow is `zai-coding-plan`).
|
|
19
|
+
*/
|
|
20
|
+
export const SIGN_IN_PROVIDERS = Object.freeze({
|
|
21
|
+
kilo: { driver: 'kilo', label: 'Kilo' },
|
|
22
|
+
zai: { driver: 'zai-coding-plan', label: 'Z.AI (GLM Coding Plan)' },
|
|
23
|
+
});
|
|
24
|
+
/** Whether this plugin can obtain a credential for `provider` by signing in. */
|
|
25
|
+
export function signInCapable(provider) {
|
|
26
|
+
// Own-property check: a plain-object index would answer `true` for
|
|
27
|
+
// `constructor`, `toString` or `__proto__` and hand a function to the driver.
|
|
28
|
+
return Object.hasOwn(SIGN_IN_PROVIDERS, provider);
|
|
29
|
+
}
|
|
30
|
+
/** The sign-in driver for `provider`, or `undefined` when it is not supported. */
|
|
31
|
+
export function signInProvider(provider) {
|
|
32
|
+
return Object.hasOwn(SIGN_IN_PROVIDERS, provider) ? SIGN_IN_PROVIDERS[provider] : undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/oauth/providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA6C,MAAM,CAAC,MAAM,CAAC;IACvF,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IACvC,GAAG,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,wBAAwB,EAAE;CACpE,CAAC,CAAA;AAEF,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,mEAAmE;IACnE,8EAA8E;IAC9E,OAAO,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;AACnD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,OAAO,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7F,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drive one omp sign-in flow on top of the manager's existing attempt surface.
|
|
3
|
+
*
|
|
4
|
+
* A Keys Manager attempt already exposes exactly what an omp flow needs: a
|
|
5
|
+
* notice sink (`notify`), a prompt that parks the UI (`prompt`), and an
|
|
6
|
+
* `AbortSignal` that is released when the attempt finishes or is pruned. This
|
|
7
|
+
* module maps omp's `OAuthController` onto that surface and returns the minted
|
|
8
|
+
* credential; it owns no storage, no network and no policy — the host commits
|
|
9
|
+
* the result (`src/index.ts` `commitSignIn`).
|
|
10
|
+
*
|
|
11
|
+
* Cancellation is translated rather than swallowed: omp throws its own
|
|
12
|
+
* `LoginCancelledError`, the host needs its own named error so a cancelled
|
|
13
|
+
* attempt is never mistaken for a provider failure. Every other error is
|
|
14
|
+
* rethrown untouched, because the attempt view renders the provider's text.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-keys-manager/oauth/signin
|
|
17
|
+
*/
|
|
18
|
+
import type { AuthorizationInteractionLike } from '../host-types.js';
|
|
19
|
+
import { type OmpOAuthAdapter } from './adapter.js';
|
|
20
|
+
export interface SignInRequest {
|
|
21
|
+
/** The attempt's notify/prompt surface. */
|
|
22
|
+
interaction: AuthorizationInteractionLike;
|
|
23
|
+
/** The attempt's abort signal; cancellation reaches the omp controller. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
/** Injectable fetch for tests and for a host that owns its fetch layer. */
|
|
26
|
+
fetch?: typeof fetch;
|
|
27
|
+
/**
|
|
28
|
+
* The bundled drivers. Production callers leave this unset and the lazy
|
|
29
|
+
* artifact load answers; tests inject a double so no test ever imports the
|
|
30
|
+
* real bundle.
|
|
31
|
+
*/
|
|
32
|
+
adapter?: OmpOAuthAdapter;
|
|
33
|
+
}
|
|
34
|
+
/** What a successful sign-in yields: a static credential, ready for the pool. */
|
|
35
|
+
export interface MintedCredential {
|
|
36
|
+
/** The bearer / `id.secret` key string. */
|
|
37
|
+
access: string;
|
|
38
|
+
/** Epoch ms of the credential's expiry (a far-future value for durable keys). */
|
|
39
|
+
expires: number;
|
|
40
|
+
}
|
|
41
|
+
/** The attempt was cancelled; the host records `cancelled`, not `failed`. */
|
|
42
|
+
export declare class SignInCancelledError extends Error {
|
|
43
|
+
constructor(provider: string);
|
|
44
|
+
}
|
|
45
|
+
/** The provider has no sign-in driver in this plugin. */
|
|
46
|
+
export declare class SignInUnavailableError extends Error {
|
|
47
|
+
constructor(provider: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run one provider's sign-in to completion.
|
|
51
|
+
*
|
|
52
|
+
* @param provider - the route id (`kilo` / `zai`).
|
|
53
|
+
* @param request - the attempt surface plus the optional test seams.
|
|
54
|
+
* @returns the minted static credential.
|
|
55
|
+
* @throws SignInUnavailableError when the route has no driver.
|
|
56
|
+
* @throws SignInCancelledError when the attempt's signal released the flow.
|
|
57
|
+
*/
|
|
58
|
+
export declare function runSignIn(provider: string, request: SignInRequest): Promise<MintedCredential>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ompOAuthAdapter } from './adapter.js';
|
|
2
|
+
import { signInProvider } from './providers.js';
|
|
3
|
+
/** The wording omp's paste flow needs; the redirect is a `zcode://` URL. */
|
|
4
|
+
const MANUAL_CODE_PROMPT = 'Paste the final redirect URL or the authorization code';
|
|
5
|
+
/** The attempt was cancelled; the host records `cancelled`, not `failed`. */
|
|
6
|
+
export class SignInCancelledError extends Error {
|
|
7
|
+
constructor(provider) {
|
|
8
|
+
super(`The ${provider} sign-in was cancelled`);
|
|
9
|
+
this.name = 'SignInCancelledError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** The provider has no sign-in driver in this plugin. */
|
|
13
|
+
export class SignInUnavailableError extends Error {
|
|
14
|
+
constructor(provider) {
|
|
15
|
+
super(`Provider "${provider}" offers no in-process sign-in`);
|
|
16
|
+
this.name = 'SignInUnavailableError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Aborted-signal predicate; a function call so a live signal is re-read. */
|
|
20
|
+
function isAborted(signal) {
|
|
21
|
+
return signal?.aborted === true;
|
|
22
|
+
}
|
|
23
|
+
/** Whether a driver failure is the attempt's cancellation. */
|
|
24
|
+
function isCancellation(error, signal) {
|
|
25
|
+
if (isAborted(signal))
|
|
26
|
+
return true;
|
|
27
|
+
return error instanceof Error && error.name === 'LoginCancelledError';
|
|
28
|
+
}
|
|
29
|
+
/** The controller one attempt hands to omp. */
|
|
30
|
+
function controllerOf(provider, signIn, request) {
|
|
31
|
+
return {
|
|
32
|
+
onAuth: info => {
|
|
33
|
+
// Kilo's user code travels inside `instructions` ("Enter code: …"), so
|
|
34
|
+
// the notice is a verbatim copy — no parsing, no extra field.
|
|
35
|
+
request.interaction.notify({
|
|
36
|
+
message: info.instructions ?? signIn.label,
|
|
37
|
+
...(info.url === undefined ? {} : { url: info.url }),
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
onProgress: message => request.interaction.notify({ message }),
|
|
41
|
+
// Neither batch-1 flow prompts today; wiring it keeps parity with the seam
|
|
42
|
+
// path and means a future flow cannot silently drop a prompt.
|
|
43
|
+
onPrompt: async (prompt) => request.interaction.prompt({
|
|
44
|
+
kind: prompt.secret === true ? 'secret' : 'text',
|
|
45
|
+
message: prompt.message,
|
|
46
|
+
...(prompt.placeholder === undefined ? {} : { placeholder: prompt.placeholder }),
|
|
47
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
48
|
+
}),
|
|
49
|
+
// zai only: the browser lands on `zcode://…`, which the user pastes back.
|
|
50
|
+
// omp re-asks when the input yields no code, so this must tolerate repeats.
|
|
51
|
+
onManualCodeInput: async (signal) => request.interaction.prompt({
|
|
52
|
+
kind: 'manual-code',
|
|
53
|
+
message: MANUAL_CODE_PROMPT,
|
|
54
|
+
...(signal === undefined && request.signal === undefined
|
|
55
|
+
? {}
|
|
56
|
+
: { signal: signal ?? request.signal }),
|
|
57
|
+
}),
|
|
58
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
59
|
+
...(request.fetch === undefined ? {} : { fetch: request.fetch }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Run the provider's bundled driver. */
|
|
63
|
+
async function drive(provider, adapter, controller, signIn) {
|
|
64
|
+
switch (signIn.driver) {
|
|
65
|
+
case 'kilo':
|
|
66
|
+
return adapter.loginKilo(controller);
|
|
67
|
+
case 'zai-coding-plan':
|
|
68
|
+
return adapter.loginZaiCodingPlan(controller);
|
|
69
|
+
default: {
|
|
70
|
+
// Exhaustiveness: a new driver must be wired here before it can ship.
|
|
71
|
+
const unreachable = signIn.driver;
|
|
72
|
+
throw new SignInUnavailableError(`${provider} (${String(unreachable)})`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Run one provider's sign-in to completion.
|
|
78
|
+
*
|
|
79
|
+
* @param provider - the route id (`kilo` / `zai`).
|
|
80
|
+
* @param request - the attempt surface plus the optional test seams.
|
|
81
|
+
* @returns the minted static credential.
|
|
82
|
+
* @throws SignInUnavailableError when the route has no driver.
|
|
83
|
+
* @throws SignInCancelledError when the attempt's signal released the flow.
|
|
84
|
+
*/
|
|
85
|
+
export async function runSignIn(provider, request) {
|
|
86
|
+
const signIn = signInProvider(provider);
|
|
87
|
+
if (signIn === undefined)
|
|
88
|
+
throw new SignInUnavailableError(provider);
|
|
89
|
+
if (request.signal?.aborted === true)
|
|
90
|
+
throw new SignInCancelledError(provider);
|
|
91
|
+
const adapter = request.adapter ?? (await ompOAuthAdapter());
|
|
92
|
+
const controller = controllerOf(provider, signIn, request);
|
|
93
|
+
let credentials;
|
|
94
|
+
try {
|
|
95
|
+
credentials = await drive(provider, adapter, controller, signIn);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (isCancellation(error, request.signal))
|
|
99
|
+
throw new SignInCancelledError(provider);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
// A flow can resolve after the attempt's signal released it (an abort that
|
|
103
|
+
// lands between the driver's last await and its return); the credential of a
|
|
104
|
+
// cancelled attempt must never reach the pool.
|
|
105
|
+
if (isAborted(request.signal))
|
|
106
|
+
throw new SignInCancelledError(provider);
|
|
107
|
+
if (typeof credentials?.access !== 'string' || credentials.access.length === 0) {
|
|
108
|
+
throw new Error(`The ${signIn.label} sign-in returned no credential`);
|
|
109
|
+
}
|
|
110
|
+
return { access: credentials.access, expires: credentials.expires };
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=signin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signin.js","sourceRoot":"","sources":["../../src/oauth/signin.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,eAAe,EAA2E,MAAM,cAAc,CAAA;AACvH,OAAO,EAAE,cAAc,EAAuB,MAAM,gBAAgB,CAAA;AAEpE,4EAA4E;AAC5E,MAAM,kBAAkB,GAAG,wDAAwD,CAAA;AAyBnF,6EAA6E;AAC7E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,QAAgB;QAC1B,KAAK,CAAC,OAAO,QAAQ,wBAAwB,CAAC,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,yDAAyD;AACzD,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,QAAgB;QAC1B,KAAK,CAAC,aAAa,QAAQ,gCAAgC,CAAC,CAAA;QAC5D,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AAED,6EAA6E;AAC7E,SAAS,SAAS,CAAC,MAA+B;IAChD,OAAO,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AACjC,CAAC;AAED,8DAA8D;AAC9D,SAAS,cAAc,CAAC,KAAc,EAAE,MAA+B;IACrE,IAAI,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAClC,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,CAAA;AACvE,CAAC;AAED,+CAA+C;AAC/C,SAAS,YAAY,CAAC,QAAgB,EAAE,MAAsB,EAAE,OAAsB;IACpF,OAA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