@flipstream/sdk 0.4.0 → 0.5.0
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 +17 -0
- package/README.md +229 -18
- package/dist/auth/discovery.d.ts +2 -0
- package/dist/auth/discovery.js +4 -1
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +11 -2
- package/dist/auth/signIn.js +19 -27
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/tokenEndpoint.d.ts +18 -0
- package/dist/auth/tokenEndpoint.js +36 -0
- package/dist/auth/tokenEndpoint.js.map +1 -0
- package/dist/core/fetch.d.ts +8 -0
- package/dist/core/fetch.js +36 -11
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/result.d.ts +4 -2
- package/dist/core/result.js +3 -1
- package/dist/core/result.js.map +1 -1
- package/dist/flipstream.d.ts +7 -0
- package/dist/flipstream.js +14 -4
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/node/clientSecret.d.ts +41 -0
- package/dist/node/clientSecret.js +124 -0
- package/dist/node/clientSecret.js.map +1 -0
- package/dist/node/fileLock.d.ts +27 -0
- package/dist/node/fileLock.js +248 -0
- package/dist/node/fileLock.js.map +1 -0
- package/dist/node/headless.d.ts +7 -2
- package/dist/node/headless.js +15 -2
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +7 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/loopback.d.ts +24 -5
- package/dist/node/loopback.js +80 -23
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +192 -0
- package/dist/node/session.js +480 -0
- package/dist/node/session.js.map +1 -0
- package/dist/query/health.d.ts +16 -0
- package/dist/query/health.js +18 -0
- package/dist/query/health.js.map +1 -0
- package/dist/query/query.d.ts +8 -0
- package/dist/query/query.js +12 -0
- package/dist/query/query.js.map +1 -1
- package/package.json +10 -1
package/dist/core/fetch.js
CHANGED
|
@@ -4,15 +4,7 @@ const ABORTED = { kind: 'aborted' };
|
|
|
4
4
|
const REFUSED = { kind: 'refused', reason: 'destination' };
|
|
5
5
|
export function fetchTransport(options) {
|
|
6
6
|
const send = options.fetch ?? globalThis.fetch;
|
|
7
|
-
|
|
8
|
-
const origins = new Map();
|
|
9
|
-
for (const service of SERVICES) {
|
|
10
|
-
const host = options.hosts[service];
|
|
11
|
-
if (host !== undefined)
|
|
12
|
-
origins.set(service, new URL(host).origin);
|
|
13
|
-
}
|
|
14
|
-
const secure = (url) => url.protocol === 'https:' ||
|
|
15
|
-
(options.allowLocalhostHttp === true && url.protocol === 'http:' && LOOPBACK.has(url.hostname));
|
|
7
|
+
const allowed = destinations(options);
|
|
16
8
|
/**
|
|
17
9
|
* One send. The destination comes first, so a call that may not go asks for no token and spends
|
|
18
10
|
* no refresh. The Request is built once, and that same object is checked and sent, so a
|
|
@@ -20,8 +12,7 @@ export function fetchTransport(options) {
|
|
|
20
12
|
*/
|
|
21
13
|
async function attempt(call, ask) {
|
|
22
14
|
const built = call.makeRequest();
|
|
23
|
-
|
|
24
|
-
if (!secure(url) || origins.get(call.service) !== url.origin)
|
|
15
|
+
if (!allowed(call.service, built.url))
|
|
25
16
|
return REFUSED;
|
|
26
17
|
const token = await tokenFor(options.token, ask, call.signal);
|
|
27
18
|
if (token.kind !== 'token')
|
|
@@ -52,6 +43,40 @@ export function fetchTransport(options) {
|
|
|
52
43
|
return again.kind === 'sent' ? { kind: 'response', response: again.response } : again;
|
|
53
44
|
};
|
|
54
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The default transport without a token, for `GET /health` (#111): the same destinations and the
|
|
48
|
+
* same send, but it asks no token function and adds no `authorization` header, so it works
|
|
49
|
+
* signed out. It never resends after a 401: there is no token to renew.
|
|
50
|
+
*/
|
|
51
|
+
export function tokenlessTransport(options) {
|
|
52
|
+
const send = options.fetch ?? globalThis.fetch;
|
|
53
|
+
const allowed = destinations(options);
|
|
54
|
+
return async (call) => {
|
|
55
|
+
const built = call.makeRequest();
|
|
56
|
+
if (!allowed(call.service, built.url))
|
|
57
|
+
return REFUSED;
|
|
58
|
+
const sent = await sendRequest(send, built, new Headers(built.headers), call.signal);
|
|
59
|
+
return sent.kind === 'sent' ? { kind: 'response', response: sent.response } : sent;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Where a call may go: its own service's origin, over https, or over plain http to a loopback
|
|
64
|
+
* host when that is allowed. The hosts are parsed once: one that is not a URL throws here, at
|
|
65
|
+
* once, not on the first call.
|
|
66
|
+
*/
|
|
67
|
+
function destinations({ hosts, allowLocalhostHttp }) {
|
|
68
|
+
const origins = new Map();
|
|
69
|
+
for (const service of SERVICES) {
|
|
70
|
+
const host = hosts[service];
|
|
71
|
+
if (host !== undefined)
|
|
72
|
+
origins.set(service, new URL(host).origin);
|
|
73
|
+
}
|
|
74
|
+
return (service, href) => {
|
|
75
|
+
const url = new URL(href);
|
|
76
|
+
const secure = url.protocol === 'https:' || (allowLocalhostHttp === true && url.protocol === 'http:' && LOOPBACK.has(url.hostname));
|
|
77
|
+
return secure && origins.get(service) === url.origin;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
55
80
|
/**
|
|
56
81
|
* One request out, as every transport of the SDK's own sends it (sign-in's too, #63), with
|
|
57
82
|
* `headers` in place of `built`'s. Nothing is sent once `signal` has fired. No cookies, and no
|
package/dist/core/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/core/fetch.ts"],"names":[],"mappings":"AA2BA,MAAM,QAAQ,GAA2B,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AACjE,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAA;AAClF,MAAM,OAAO,GAAG,EAAE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,11 +68,13 @@ export type ApiError = Answered
|
|
|
68
68
|
readonly kind: 'timeout';
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
* Nothing was sent, by rule: the destination isn't one of the configured hosts over https,
|
|
72
|
-
* path value can't stay one segment ('', '.', '..')
|
|
71
|
+
* Nothing was sent, by rule: the destination isn't one of the configured hosts over https, a
|
|
72
|
+
* path value can't stay one segment ('', '.', '..'), or the request has keys the call doesn't
|
|
73
|
+
* send, named in `fields`. No token was asked for, and none went anywhere.
|
|
73
74
|
*/
|
|
74
75
|
| {
|
|
75
76
|
readonly kind: 'refused';
|
|
77
|
+
readonly fields?: readonly [string, ...string[]];
|
|
76
78
|
}
|
|
77
79
|
/** The token function failed, or gave no token, so nothing was sent; `cause` is what it threw. */
|
|
78
80
|
| {
|
package/dist/core/result.js
CHANGED
|
@@ -26,7 +26,9 @@ export function classifyStatus(status) {
|
|
|
26
26
|
export class ApiFailure extends Error {
|
|
27
27
|
error;
|
|
28
28
|
constructor(error) {
|
|
29
|
-
super(
|
|
29
|
+
super(error.kind === 'refused' && error.fields !== undefined
|
|
30
|
+
? `the call failed: refused, for fields it doesn't send: ${error.fields.join(', ')}`
|
|
31
|
+
: `the call failed: ${error.kind}`);
|
|
30
32
|
this.name = 'ApiFailure';
|
|
31
33
|
this.error = error;
|
|
32
34
|
}
|
package/dist/core/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAgFA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,kBAAkB,CAAA;IACxD,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,SAAS,CAAA;IACpD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,cAAc,CAAA;IACzC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,UAAU,CAAA;IACvD,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;QAAE,OAAO,aAAa,CAAA;IAC5E,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IACrD,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAED,mEAAmE;AACnE,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,KAAK,CAAU;IAExB,YAAY,KAAe;QACzB,KAAK,CACH,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;YACpD,CAAC,CAAC,yDAAyD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpF,CAAC,CAAC,oBAAoB,KAAK,CAAC,IAAI,EAAE,CACrC,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAI,MAAoB;IAC7C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClD,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC"}
|
package/dist/flipstream.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TokenAsk } from './core/fetch.js';
|
|
2
2
|
import type { ApiResult } from './core/result.js';
|
|
3
3
|
import type { ServiceName, Transport } from './core/transport.js';
|
|
4
|
+
import { type Health } from './query/health.js';
|
|
4
5
|
import { type QueryRequest } from './query/query.js';
|
|
5
6
|
import type { Catalog, CatalogSource, QueryResponse } from './spec/query-planner/types.gen.js';
|
|
6
7
|
/** Each service's base URL. Only public hosts (D410); a call goes only to its own service's. */
|
|
@@ -40,6 +41,12 @@ export interface Flipstream {
|
|
|
40
41
|
}, options?: CallOptions): Promise<ApiResult<CatalogSource>>;
|
|
41
42
|
};
|
|
42
43
|
query(request: QueryRequest, options?: CallOptions): Promise<ApiResult<QueryResponse>>;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the planner answers, signed out: `GET /health` with no token. It goes through neither
|
|
46
|
+
* the app's transport nor the token function, since they hold the token, but straight to the
|
|
47
|
+
* query host, under the same destination rule. A 200 with an object of strings is up.
|
|
48
|
+
*/
|
|
49
|
+
health(options?: CallOptions): Promise<ApiResult<Health>>;
|
|
43
50
|
}
|
|
44
51
|
/** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
|
|
45
52
|
export declare function createFlipstream(options: FlipstreamOptions): Flipstream;
|
package/dist/flipstream.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { call } from './core/call.js';
|
|
2
|
-
import { fetchTransport } from './core/fetch.js';
|
|
2
|
+
import { fetchTransport, tokenlessTransport } from './core/fetch.js';
|
|
3
3
|
import { catalogGet, catalogList } from './query/catalog.js';
|
|
4
|
-
import {
|
|
4
|
+
import { healthCheck } from './query/health.js';
|
|
5
|
+
import { queryRun, unsentFields } from './query/query.js';
|
|
5
6
|
const DEFAULT_HOSTS = { query: 'https://query.flipstream.io' };
|
|
6
7
|
/** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
|
|
7
8
|
export function createFlipstream(options) {
|
|
@@ -10,7 +11,10 @@ export function createFlipstream(options) {
|
|
|
10
11
|
? options.transport
|
|
11
12
|
: fetchTransport({ token: options.token, fetch: options.fetch, hosts, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
12
13
|
const base = (hosts.query ?? DEFAULT_HOSTS.query).replace(/\/+$/, '');
|
|
13
|
-
|
|
14
|
+
// For health alone (#111), whichever way the SDK was made: only the query host, so the call that
|
|
15
|
+
// works signed out can go nowhere else.
|
|
16
|
+
const signedOut = tokenlessTransport({ fetch: options.fetch, hosts: { query: base }, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
17
|
+
const send = (spec, { signal, deadlineMs } = {}, via = transport) => call(via, deadlineMs === undefined ? spec : { ...spec, deadlineMs }, signal);
|
|
14
18
|
return {
|
|
15
19
|
catalog: {
|
|
16
20
|
list: (callOptions) => send(catalogList(base), callOptions),
|
|
@@ -20,7 +24,13 @@ export function createFlipstream(options) {
|
|
|
20
24
|
return spec === null ? Promise.resolve({ ok: false, error: { kind: 'refused' } }) : send(spec, callOptions);
|
|
21
25
|
},
|
|
22
26
|
},
|
|
23
|
-
|
|
27
|
+
// Async, so a request that isn't an object rejects, as D436's do, rather than throwing here.
|
|
28
|
+
async query(request, callOptions) {
|
|
29
|
+
const fields = unsentFields(request);
|
|
30
|
+
// Refused before anything is sent, like catalog.get's: the token function isn't asked.
|
|
31
|
+
return fields === null ? send(queryRun(base, request), callOptions) : { ok: false, error: { kind: 'refused', fields } };
|
|
32
|
+
},
|
|
33
|
+
health: (callOptions) => send(healthCheck(base), callOptions, signedOut),
|
|
24
34
|
};
|
|
25
35
|
}
|
|
26
36
|
//# sourceMappingURL=flipstream.js.map
|
package/dist/flipstream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flipstream.js","sourceRoot":"","sources":["../src/flipstream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAiB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"flipstream.js","sourceRoot":"","sources":["../src/flipstream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA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ipstream, FlipstreamOptions, Hosts, TokenFunction } from './flipstream.js';
|
|
3
3
|
export type { QueryRequest } from './query/query.js';
|
|
4
|
+
export type { Health } from './query/health.js';
|
|
4
5
|
export { isPlannerCode } from './query/errors.js';
|
|
5
6
|
export { ApiFailure, orThrow } from './core/result.js';
|
|
6
7
|
export type { Answered, ApiError, ApiResult, ErrorCode, Said, StatusKind } from './core/result.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,gEAAgE;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,gEAAgE;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAkBtD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AuthServer } from '../auth/discovery.js';
|
|
2
|
+
import { type PendingSignIn, type SignInResult } from '../auth/signIn.js';
|
|
3
|
+
import type { AuthCallOptions } from '../auth/transport.js';
|
|
4
|
+
import type { ApiResult } from '../core/result.js';
|
|
5
|
+
/** What the Node `finishSignIn` takes. */
|
|
6
|
+
export interface ServerSignInOptions extends AuthCallOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The server, as the app's own `discover` gave it: the code is exchanged only at its token
|
|
9
|
+
* endpoint. `pending` is the app's to store, so an endpoint read from it may have been changed.
|
|
10
|
+
*/
|
|
11
|
+
readonly server: AuthServer;
|
|
12
|
+
/**
|
|
13
|
+
* The app's own OAuth client ID (D421), the one the secret belongs to: the Basic header carries
|
|
14
|
+
* it, and a `pending` that names another is refused (R3.B1). Another app's code, verifier and
|
|
15
|
+
* client ID edited into `pending` would otherwise sign that app's person in here.
|
|
16
|
+
*/
|
|
17
|
+
readonly clientId: string;
|
|
18
|
+
/**
|
|
19
|
+
* The app's client secret, as a confidential client. Only a server holds one, never browser
|
|
20
|
+
* code. Left out, the sign-in is a public client's, with PKCE alone. Never log it.
|
|
21
|
+
*/
|
|
22
|
+
readonly clientSecret?: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Finishes a sign-in as the main entry's `finishSignIn` does, on the app's server. With
|
|
26
|
+
* `clientSecret`, the token request carries `Authorization: Basic` with the client ID and the
|
|
27
|
+
* secret, and its body stays a public client's, PKCE included (RFC 9700 §2.1.1). Its failures
|
|
28
|
+
* keep the kind, the status and the OAuth code, never the server's description or body, which an
|
|
29
|
+
* echo of the request would fill with the credentials (`vouched`). A `pending` whose issuer or
|
|
30
|
+
* token endpoint isn't `server`'s, or whose client ID isn't `clientId`, is `refused`, with nothing
|
|
31
|
+
* sent. Rejects with a TypeError, with nothing sent, when `clientId` isn't a non-empty string, or
|
|
32
|
+
* `clientSecret` is given but isn't one.
|
|
33
|
+
*/
|
|
34
|
+
export declare function finishSignIn(callbackUrl: string | URL, pending: PendingSignIn, options: ServerSignInOptions): Promise<SignInResult>;
|
|
35
|
+
/**
|
|
36
|
+
* The Authorization header for a confidential client's calls, or none for a public client's.
|
|
37
|
+
* Throws a TypeError, naming `caller`, when the secret is given but isn't a non-empty string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function clientAuthorization(caller: string, clientId: string, clientSecret: string | undefined): string | undefined;
|
|
40
|
+
/** A call's result as `authorization` allows it to be seen: unchanged for a public client's call. */
|
|
41
|
+
export declare function vouched<T>(result: ApiResult<T>, authorization: string | undefined): ApiResult<T>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { exchangeCode, isPendingSignIn } from '../auth/signIn.js';
|
|
3
|
+
/**
|
|
4
|
+
* Finishes a sign-in as the main entry's `finishSignIn` does, on the app's server. With
|
|
5
|
+
* `clientSecret`, the token request carries `Authorization: Basic` with the client ID and the
|
|
6
|
+
* secret, and its body stays a public client's, PKCE included (RFC 9700 §2.1.1). Its failures
|
|
7
|
+
* keep the kind, the status and the OAuth code, never the server's description or body, which an
|
|
8
|
+
* echo of the request would fill with the credentials (`vouched`). A `pending` whose issuer or
|
|
9
|
+
* token endpoint isn't `server`'s, or whose client ID isn't `clientId`, is `refused`, with nothing
|
|
10
|
+
* sent. Rejects with a TypeError, with nothing sent, when `clientId` isn't a non-empty string, or
|
|
11
|
+
* `clientSecret` is given but isn't one.
|
|
12
|
+
*/
|
|
13
|
+
export async function finishSignIn(callbackUrl, pending, options) {
|
|
14
|
+
const { server, clientId, clientSecret, ...callOptions } = options;
|
|
15
|
+
if (typeof clientId !== 'string' || clientId === '')
|
|
16
|
+
throw new TypeError("finishSignIn: clientId is required: the app's own OAuth client ID");
|
|
17
|
+
checkSecret('finishSignIn', clientSecret);
|
|
18
|
+
if (!isPendingSignIn(pending) || !startedHere(pending, server, clientId))
|
|
19
|
+
return { ok: false, error: { kind: 'refused' } };
|
|
20
|
+
if (clientSecret === undefined)
|
|
21
|
+
return exchangeCode(callbackUrl, pending, callOptions);
|
|
22
|
+
const result = await exchangeCode(callbackUrl, pending, callOptions, basicAuthorization(clientId, clientSecret));
|
|
23
|
+
return result.ok ? result : { ok: false, error: vouchedSignIn(result.error) };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The Authorization header for a confidential client's calls, or none for a public client's.
|
|
27
|
+
* Throws a TypeError, naming `caller`, when the secret is given but isn't a non-empty string.
|
|
28
|
+
*/
|
|
29
|
+
export function clientAuthorization(caller, clientId, clientSecret) {
|
|
30
|
+
checkSecret(caller, clientSecret);
|
|
31
|
+
return clientSecret === undefined ? undefined : basicAuthorization(clientId, clientSecret);
|
|
32
|
+
}
|
|
33
|
+
/** A call's result as `authorization` allows it to be seen: unchanged for a public client's call. */
|
|
34
|
+
export function vouched(result, authorization) {
|
|
35
|
+
return result.ok || authorization === undefined ? result : { ok: false, error: vouchedFor(result.error) };
|
|
36
|
+
}
|
|
37
|
+
// A missing secret (undefined) is a public client. A blank or non-string one is a mistake, never
|
|
38
|
+
// one to send: a server that knows the client as confidential would only refuse it.
|
|
39
|
+
function checkSecret(caller, clientSecret) {
|
|
40
|
+
if (clientSecret !== undefined && (typeof clientSecret !== 'string' || clientSecret === '')) {
|
|
41
|
+
throw new TypeError(`${caller}: clientSecret, when given, must be a non-empty string`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// RFC 6749 §5.2: the error codes a token endpoint answers with, and RFC 7009 §2.2.1's one more for
|
|
45
|
+
// a revocation.
|
|
46
|
+
const OAUTH_CODES = new Set([
|
|
47
|
+
'invalid_request',
|
|
48
|
+
'invalid_client',
|
|
49
|
+
'invalid_grant',
|
|
50
|
+
'unauthorized_client',
|
|
51
|
+
'unsupported_grant_type',
|
|
52
|
+
'invalid_scope',
|
|
53
|
+
'unsupported_token_type',
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* A failure of a call that carried the credentials, with only what the SDK can vouch for: its
|
|
57
|
+
* kind, status and wait, a 2xx's issues (zod's, which never quote the body), and the OAuth code
|
|
58
|
+
* when it is one of §5.2's, with an empty message. The server's own words, its description and its
|
|
59
|
+
* body, are left out (an empty `message` or `text`): a server or proxy that echoes the request
|
|
60
|
+
* would put the credentials there, and no search for them could know every encoding they might
|
|
61
|
+
* come back in.
|
|
62
|
+
*/
|
|
63
|
+
function vouchedFor(error) {
|
|
64
|
+
switch (error.kind) {
|
|
65
|
+
case 'invalid':
|
|
66
|
+
return error.status === undefined ? { kind: 'invalid', issues: error.issues } : { kind: 'invalid', issues: error.issues, status: error.status };
|
|
67
|
+
case 'unauthorized':
|
|
68
|
+
case 'forbidden':
|
|
69
|
+
case 'not_found':
|
|
70
|
+
case 'conflict':
|
|
71
|
+
case 'rejected':
|
|
72
|
+
case 'unavailable': {
|
|
73
|
+
if (error.status === undefined)
|
|
74
|
+
return { kind: 'unavailable' };
|
|
75
|
+
const { kind, status, retryAfterMs } = error;
|
|
76
|
+
const said = error.code !== undefined && OAUTH_CODES.has(error.code) ? { code: error.code, message: '' } : { text: '' };
|
|
77
|
+
return { kind, status, ...(retryAfterMs === undefined ? {} : { retryAfterMs }), ...said };
|
|
78
|
+
}
|
|
79
|
+
// Nothing the server sent: the call's own outcomes.
|
|
80
|
+
case 'cancelled':
|
|
81
|
+
case 'aborted':
|
|
82
|
+
case 'timeout':
|
|
83
|
+
case 'refused':
|
|
84
|
+
case 'no_token':
|
|
85
|
+
return error;
|
|
86
|
+
default: {
|
|
87
|
+
const unhandled = error;
|
|
88
|
+
return unhandled;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** A sign-in's failure: the redirect's are read before any request, so only the exchange's are vouched for. */
|
|
93
|
+
function vouchedSignIn(error) {
|
|
94
|
+
switch (error.kind) {
|
|
95
|
+
case 'wrong_state':
|
|
96
|
+
case 'wrong_issuer':
|
|
97
|
+
case 'provider_error':
|
|
98
|
+
case 'no_code':
|
|
99
|
+
return error;
|
|
100
|
+
default:
|
|
101
|
+
return vouchedFor(error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The pending sign-in was started by this app with this server: its client ID, and the server's
|
|
106
|
+
* issuer, token endpoint and `iss` rule. #128's shared check (D470) replaces this one.
|
|
107
|
+
*/
|
|
108
|
+
function startedHere(pending, server, clientId) {
|
|
109
|
+
return (pending.clientId === clientId &&
|
|
110
|
+
pending.issuer === server.issuer &&
|
|
111
|
+
pending.tokenEndpoint === server.tokenEndpoint &&
|
|
112
|
+
pending.issuerOnRedirect === server.issuerOnRedirect);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* RFC 6749 §2.3.1's Basic credentials: the client ID and the secret, each form-encoded first
|
|
116
|
+
* (Appendix B), joined by a colon, in base64. pulse-auth decodes each half again (unquote_plus),
|
|
117
|
+
* so a colon, a `+` or a `%` in either reads back as itself.
|
|
118
|
+
*/
|
|
119
|
+
function basicAuthorization(clientId, clientSecret) {
|
|
120
|
+
return `Basic ${Buffer.from(`${formEncoded(clientId)}:${formEncoded(clientSecret)}`).toString('base64')}`;
|
|
121
|
+
}
|
|
122
|
+
// application/x-www-form-urlencoded, exactly as a form writes a value.
|
|
123
|
+
const formEncoded = (value) => new URLSearchParams([['', value]]).toString().slice(1);
|
|
124
|
+
//# sourceMappingURL=clientSecret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSecret.js","sourceRoot":"","sources":["../../src/node/clientSecret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,eAAe,EAA2D,MAAM,mBAAmB,CAAA;AAkC1H;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAyB,EAAE,OAAsB,EAAE,OAA4B;IAChH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAA;IAClE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAA;IAC7I,WAAW,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;IACzC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAA;IAC1H,IAAI,YAAY,KAAK,SAAS;QA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C,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SessionOptions } from './session.js';
|
|
2
|
+
/**
|
|
3
|
+
* A lock across processes, for `createSession`'s `lock` option: for a token store that several
|
|
4
|
+
* Node processes share, such as a CLI run several times at once. Give every process the same
|
|
5
|
+
* absolute path, on a local disk, beside the store.
|
|
6
|
+
*
|
|
7
|
+
* - **It is taken by creating the file exclusively,** and removed once `work` has settled, whether
|
|
8
|
+
* it succeeded or failed. Only then does the lock settle, with `work`'s outcome.
|
|
9
|
+
* - **While another process holds it,** it tries again every 100 ms. When `signal` fires it gives
|
|
10
|
+
* up, rejecting with `signal.reason`, and `work` never runs after that. With a signal that has
|
|
11
|
+
* already fired, it creates nothing.
|
|
12
|
+
* - **A process that dies holding it** leaves a file nobody touches any more: a holder touches it
|
|
13
|
+
* every second. The next process takes it over once the file is 10 s old by this machine's clock
|
|
14
|
+
* and it has seen it unchanged for 3 s, or, whatever the clock says, once it has seen it unchanged
|
|
15
|
+
* for 10 s.
|
|
16
|
+
* - **A holder that can't touch its file for 10 s loses it,** and its `work` goes on beside the next
|
|
17
|
+
* holder's: a thread blocked by a synchronous store, or a process stopped by Ctrl-Z or a
|
|
18
|
+
* debugger. Keep the store asynchronous.
|
|
19
|
+
* - **It isn't reentrant:** `work` that takes the same lock again waits for itself until its
|
|
20
|
+
* signal.
|
|
21
|
+
* - **When the file can't be removed,** `work`'s outcome still stands, and the next process takes
|
|
22
|
+
* the file over as stale.
|
|
23
|
+
*
|
|
24
|
+
* @param path - The lock file. Its folder is made when it isn't there (on POSIX, for this user
|
|
25
|
+
* only, as the file is).
|
|
26
|
+
*/
|
|
27
|
+
export declare function fileLock(path: string): NonNullable<SessionOptions['lock']>;
|