@flipstream/sdk 0.0.0-stage → 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 +102 -0
- package/LICENSE +202 -0
- package/README.md +491 -2
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/auth/discovery.d.ts +23 -0
- package/dist/auth/discovery.js +71 -0
- package/dist/auth/discovery.js.map +1 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/pkce.d.ts +10 -0
- package/dist/auth/pkce.js +25 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/signIn.d.ts +106 -0
- package/dist/auth/signIn.js +125 -0
- package/dist/auth/signIn.js.map +1 -0
- 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/auth/transport.d.ts +18 -0
- package/dist/auth/transport.js +26 -0
- package/dist/auth/transport.js.map +1 -0
- package/dist/core/body.d.ts +14 -0
- package/dist/core/body.js +69 -0
- package/dist/core/body.js.map +1 -0
- package/dist/core/call.d.ts +17 -0
- package/dist/core/call.js +116 -0
- package/dist/core/call.js.map +1 -0
- package/dist/core/fetch.d.ts +43 -0
- package/dist/core/fetch.js +130 -0
- package/dist/core/fetch.js.map +1 -0
- package/dist/core/read.d.ts +17 -0
- package/dist/core/read.js +92 -0
- package/dist/core/read.js.map +1 -0
- package/dist/core/result.d.ts +96 -0
- package/dist/core/result.js +42 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/retry.d.ts +40 -0
- package/dist/core/retry.js +41 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/transport.d.ts +62 -0
- package/dist/core/transport.js +9 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/flipstream.d.ts +52 -0
- package/dist/flipstream.js +36 -0
- package/dist/flipstream.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- 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 +25 -0
- package/dist/node/headless.js +41 -0
- package/dist/node/headless.js.map +1 -0
- package/dist/node/index.d.ts +9 -0
- package/dist/node/index.js +11 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/loopback.d.ts +77 -0
- package/dist/node/loopback.js +183 -0
- package/dist/node/loopback.js.map +1 -0
- 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/catalog.d.ts +15 -0
- package/dist/query/catalog.js +41 -0
- package/dist/query/catalog.js.map +1 -0
- package/dist/query/errors.d.ts +8 -0
- package/dist/query/errors.js +16 -0
- package/dist/query/errors.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 +35 -0
- package/dist/query/query.js +47 -0
- package/dist/query/query.js.map +1 -0
- package/dist/recorded/query-planner/catalog-google_search_console.json +140 -0
- package/dist/recorded/query-planner/catalog.json +1234 -0
- package/dist/spec/query-planner/index.d.ts +1 -0
- package/dist/spec/query-planner/index.js +3 -0
- package/dist/spec/query-planner/index.js.map +1 -0
- package/dist/spec/query-planner/types.gen.d.ts +300 -0
- package/dist/spec/query-planner/types.gen.js +3 -0
- package/dist/spec/query-planner/types.gen.js.map +1 -0
- package/dist/spec/query-planner/zod.gen.d.ts +325 -0
- package/dist/spec/query-planner/zod.gen.js +137 -0
- package/dist/spec/query-planner/zod.gen.js.map +1 -0
- package/package.json +99 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { call } from './core/call.js';
|
|
2
|
+
import { fetchTransport, tokenlessTransport } from './core/fetch.js';
|
|
3
|
+
import { catalogGet, catalogList } from './query/catalog.js';
|
|
4
|
+
import { healthCheck } from './query/health.js';
|
|
5
|
+
import { queryRun, unsentFields } from './query/query.js';
|
|
6
|
+
const DEFAULT_HOSTS = { query: 'https://query.flipstream.io' };
|
|
7
|
+
/** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
|
|
8
|
+
export function createFlipstream(options) {
|
|
9
|
+
const hosts = { ...DEFAULT_HOSTS, ...options.hosts };
|
|
10
|
+
const transport = options.transport !== undefined
|
|
11
|
+
? options.transport
|
|
12
|
+
: fetchTransport({ token: options.token, fetch: options.fetch, hosts, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
13
|
+
const base = (hosts.query ?? DEFAULT_HOSTS.query).replace(/\/+$/, '');
|
|
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);
|
|
18
|
+
return {
|
|
19
|
+
catalog: {
|
|
20
|
+
list: (callOptions) => send(catalogList(base), callOptions),
|
|
21
|
+
get(request, callOptions) {
|
|
22
|
+
const spec = catalogGet(base, request.source);
|
|
23
|
+
// Refused before anything is sent: the token function isn't asked, and nothing is spent.
|
|
24
|
+
return spec === null ? Promise.resolve({ ok: false, error: { kind: 'refused' } }) : send(spec, callOptions);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
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),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=flipstream.js.map
|
|
@@ -0,0 +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,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAA;AAGnF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAqB,MAAM,kBAAkB,CAAA;AAkD5E,MAAM,aAAa,GAAG,EAAE,KAAK,EAAE,6BAA6B,EAAW,CAAA;AAEvE,uGAAuG;AACvG,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,MAAM,KAAK,GAAU,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAA;IAC3D,MAAM,SAAS,GACb,OAAO,CAAC,SAAS,KAAK,SAAS;QAC7B,CAAC,CAAC,OAAO,CAAC,SAAS;QACnB,CAAC,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAA;IAC3H,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACrE,iGAAiG;IACjG,wCAAwC;IACxC,MAAM,SAAS,GAAG,k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E,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAA;QACzH,CAAC;QACD,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC;KACzE,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { createFlipstream } from './flipstream.js';
|
|
2
|
+
export type { CallOptions, Flipstream, FlipstreamOptions, Hosts, TokenFunction } from './flipstream.js';
|
|
3
|
+
export type { QueryRequest } from './query/query.js';
|
|
4
|
+
export type { Health } from './query/health.js';
|
|
5
|
+
export { isPlannerCode } from './query/errors.js';
|
|
6
|
+
export { ApiFailure, orThrow } from './core/result.js';
|
|
7
|
+
export type { Answered, ApiError, ApiResult, ErrorCode, Said, StatusKind } from './core/result.js';
|
|
8
|
+
export type { ApiRequest, CancelReason, ServiceName, Transport, TransportResult } from './core/transport.js';
|
|
9
|
+
export type { TokenAsk } from './core/fetch.js';
|
|
10
|
+
export type { Catalog, CatalogSource, CustomDimensions, Dimension, ErrorBody, Format, Metric, PlannerErrorCode, QueryResponse, Row, SortSpec, Source, } from './spec/query-planner/types.gen.js';
|
|
11
|
+
export * from './auth/index.js';
|
|
12
|
+
export * from './api/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The package entry point (D421): createFlipstream and its calls, the results they give (D412),
|
|
2
|
+
// and the core types a console needs to pass its own transport.
|
|
3
|
+
export { createFlipstream } from './flipstream.js';
|
|
4
|
+
export { isPlannerCode } from './query/errors.js';
|
|
5
|
+
export { ApiFailure, orThrow } from './core/result.js';
|
|
6
|
+
export * from './auth/index.js';
|
|
7
|
+
export * from './api/index.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;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":["../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AC,CAAA;IAC5B,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,OAAsB,EAAE,MAAkB,EAAE,QAAgB;IAC/E,OAAO,CACL,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAC7B,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;QAChC,OAAO,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa;QAC9C,OAAO,CAAC,gBAAgB,KAAK,MAAM,CAAC,gBAAgB,CACrD,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,QAAgB,EAAE,YAAoB;IAChE,OAAO,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAA;AAC3G,CAAC;AAED,uEAAuE;AACvE,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,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']>;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, open, readFile, stat, unlink } from 'node:fs/promises';
|
|
3
|
+
import { dirname, isAbsolute } from 'node:path';
|
|
4
|
+
import { clearInterval, setInterval } from 'node:timers';
|
|
5
|
+
import { setTimeout as pause } from 'node:timers/promises';
|
|
6
|
+
/*
|
|
7
|
+
* The session's `lock` (D444), ready-made for Node processes that share one token store, such as
|
|
8
|
+
* the CLI run by several agents at once (#114): a lock file, created exclusively, held while `work`
|
|
9
|
+
* runs, and removed afterwards.
|
|
10
|
+
*
|
|
11
|
+
* A holder that died must not hold every other process off for ever, and a slow one must never be
|
|
12
|
+
* taken for dead: either way, two refreshes would spend one refresh token. So a holder touches its
|
|
13
|
+
* file every second, and a file nobody touches any more is taken over.
|
|
14
|
+
* - A timeout alone can't tell them apart: a hold lasts as long as its save, which the session
|
|
15
|
+
* waits out and never cuts short.
|
|
16
|
+
* - Nor can the holder's process ID: IDs are reused, and two containers sharing a folder each see
|
|
17
|
+
* the other's processes as gone.
|
|
18
|
+
* - A file is stale once a waiter has seen it unchanged over 10 s of its own tries, or over 3 s
|
|
19
|
+
* when its last touch is also 10 s old by this machine's clock. The second lets a sign-out, whose
|
|
20
|
+
* whole budget is 10 s (D445), take over a crashed holder's leftover (rev143 P1-1). Neither a
|
|
21
|
+
* clock that jumps forward nor a laptop waking from sleep (a sleep counts as one try) makes a
|
|
22
|
+
* live lock stale on its own: its holder would also have to go 2 to 3 s without a touch just
|
|
23
|
+
* then, as the waiter's watch starts at the last one. A holder on a clock 10 s or more behind
|
|
24
|
+
* this one, in a virtual machine sharing the folder say, has only those 2 to 3 s all the time.
|
|
25
|
+
*
|
|
26
|
+
* Waiters that judge a lock stale together take turns through a second file, so none removes a
|
|
27
|
+
* lock another has just taken (honest-typescript §5): of those, only the first finds it unchanged.
|
|
28
|
+
*/
|
|
29
|
+
/** How often a waiter tries again. */
|
|
30
|
+
const RETRY_MS = 100;
|
|
31
|
+
/** How often a holder touches its lock file. */
|
|
32
|
+
const TOUCH_MS = 1_000;
|
|
33
|
+
/** A file untouched this long has no live holder. */
|
|
34
|
+
const STALE_MS = 10_000;
|
|
35
|
+
/** How long a waiter watches a file whose last touch is already STALE_MS old by the clock. */
|
|
36
|
+
const OLD_WATCH_MS = 3_000;
|
|
37
|
+
/**
|
|
38
|
+
* A lock across processes, for `createSession`'s `lock` option: for a token store that several
|
|
39
|
+
* Node processes share, such as a CLI run several times at once. Give every process the same
|
|
40
|
+
* absolute path, on a local disk, beside the store.
|
|
41
|
+
*
|
|
42
|
+
* - **It is taken by creating the file exclusively,** and removed once `work` has settled, whether
|
|
43
|
+
* it succeeded or failed. Only then does the lock settle, with `work`'s outcome.
|
|
44
|
+
* - **While another process holds it,** it tries again every 100 ms. When `signal` fires it gives
|
|
45
|
+
* up, rejecting with `signal.reason`, and `work` never runs after that. With a signal that has
|
|
46
|
+
* already fired, it creates nothing.
|
|
47
|
+
* - **A process that dies holding it** leaves a file nobody touches any more: a holder touches it
|
|
48
|
+
* every second. The next process takes it over once the file is 10 s old by this machine's clock
|
|
49
|
+
* and it has seen it unchanged for 3 s, or, whatever the clock says, once it has seen it unchanged
|
|
50
|
+
* for 10 s.
|
|
51
|
+
* - **A holder that can't touch its file for 10 s loses it,** and its `work` goes on beside the next
|
|
52
|
+
* holder's: a thread blocked by a synchronous store, or a process stopped by Ctrl-Z or a
|
|
53
|
+
* debugger. Keep the store asynchronous.
|
|
54
|
+
* - **It isn't reentrant:** `work` that takes the same lock again waits for itself until its
|
|
55
|
+
* signal.
|
|
56
|
+
* - **When the file can't be removed,** `work`'s outcome still stands, and the next process takes
|
|
57
|
+
* the file over as stale.
|
|
58
|
+
*
|
|
59
|
+
* @param path - The lock file. Its folder is made when it isn't there (on POSIX, for this user
|
|
60
|
+
* only, as the file is).
|
|
61
|
+
*/
|
|
62
|
+
export function fileLock(path) {
|
|
63
|
+
// A relative path names another file in each working directory, and locks nothing.
|
|
64
|
+
if (!isAbsolute(path))
|
|
65
|
+
throw new TypeError(`fileLock needs an absolute path, the same in every process: ${path}`);
|
|
66
|
+
return async (work, signal) => {
|
|
67
|
+
const held = await take(path, signal);
|
|
68
|
+
try {
|
|
69
|
+
return await work();
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await held.release();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function take(path, signal) {
|
|
77
|
+
const id = randomUUID();
|
|
78
|
+
const lock = lookout(path);
|
|
79
|
+
const turns = lookout(turnsOf(path));
|
|
80
|
+
for (;;) {
|
|
81
|
+
if (signal.aborted)
|
|
82
|
+
return aborted(signal);
|
|
83
|
+
const handle = await createWith(path, id);
|
|
84
|
+
if (handle !== null) {
|
|
85
|
+
const held = hold(path, id, handle);
|
|
86
|
+
// Taken in the same moment the signal fired: let go at once, unused.
|
|
87
|
+
if (!signal.aborted)
|
|
88
|
+
return held;
|
|
89
|
+
await held.release();
|
|
90
|
+
return aborted(signal);
|
|
91
|
+
}
|
|
92
|
+
const stale = await lock();
|
|
93
|
+
if (stale !== null)
|
|
94
|
+
await takeOver(path, stale, id, turns);
|
|
95
|
+
// An abort ends the pause early; the loop's first line then gives up.
|
|
96
|
+
await pause(RETRY_MS, undefined, { signal }).catch(noop);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function hold(path, id, handle) {
|
|
100
|
+
let touching = false;
|
|
101
|
+
const touched = () => {
|
|
102
|
+
touching = false;
|
|
103
|
+
};
|
|
104
|
+
const touch = setInterval(() => {
|
|
105
|
+
// One at a time: on a hung disk, touches would pile up behind each other. A touch that fails
|
|
106
|
+
// is tried again a second later; ten seconds of them and the lock looks stale.
|
|
107
|
+
if (touching)
|
|
108
|
+
return;
|
|
109
|
+
touching = true;
|
|
110
|
+
const now = new Date();
|
|
111
|
+
handle.utimes(now, now).then(touched, touched);
|
|
112
|
+
}, TOUCH_MS);
|
|
113
|
+
// A process with nothing left to do but hold the lock exits, and its lock goes stale, rather
|
|
114
|
+
// than holding every other process off for ever.
|
|
115
|
+
touch.unref();
|
|
116
|
+
return {
|
|
117
|
+
release: async () => {
|
|
118
|
+
// Removed while it is still being touched, so no waiter can take it over as stale meanwhile.
|
|
119
|
+
await removeOwn(path, id);
|
|
120
|
+
clearInterval(touch);
|
|
121
|
+
await handle.close().catch(noop);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Removes a stale lock file, unless it changed since it was judged stale, while holding the turns
|
|
127
|
+
* file. A turns file left by a waiter that died is removed in its turn, once it too is stale.
|
|
128
|
+
*/
|
|
129
|
+
async function takeOver(path, stale, id, turns) {
|
|
130
|
+
const file = turnsOf(path);
|
|
131
|
+
const handle = await createWith(file, id);
|
|
132
|
+
if (handle === null) {
|
|
133
|
+
const dead = await turns();
|
|
134
|
+
if (dead !== null)
|
|
135
|
+
await removeIf(file, dead);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await removeIf(path, stale);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
await removeOwn(file, id);
|
|
143
|
+
await handle.close().catch(noop);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const turnsOf = (path) => `${path}.stale`;
|
|
147
|
+
/**
|
|
148
|
+
* The file, created exclusively for this user with `id` in it; null while another holds it.
|
|
149
|
+
* Windows removes an open file's name only once its last handle closes, so every removal here
|
|
150
|
+
* comes before its handle's close, and a name still pending removal reads as held (`createNew`).
|
|
151
|
+
*/
|
|
152
|
+
async function createWith(file, id) {
|
|
153
|
+
const handle = await createNew(file).catch(async (error) => {
|
|
154
|
+
if (codeOf(error) !== 'ENOENT')
|
|
155
|
+
throw error;
|
|
156
|
+
// The folder isn't there yet: a keychain store has none of its own.
|
|
157
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
158
|
+
return createNew(file);
|
|
159
|
+
});
|
|
160
|
+
if (handle === null)
|
|
161
|
+
return null;
|
|
162
|
+
try {
|
|
163
|
+
await handle.writeFile(id);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
// Nothing this attempt made is left behind (honest-typescript §7).
|
|
167
|
+
if (await isStill(file, handle).catch(() => false))
|
|
168
|
+
await unlink(file).catch(noop);
|
|
169
|
+
await handle.close().catch(noop);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
// A write that hung for 10 s can let a waiter take the file over while it is still empty (rev143
|
|
173
|
+
// P3-2): the name is then another's, and this handle holds nothing.
|
|
174
|
+
if (await isStill(file, handle))
|
|
175
|
+
return handle;
|
|
176
|
+
await handle.close().catch(noop);
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
async function createNew(file) {
|
|
180
|
+
try {
|
|
181
|
+
return await open(file, 'wx', 0o600);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (codeOf(error) === 'EEXIST' || deletePending(error))
|
|
185
|
+
return null;
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** Whether `file` names the file `handle` has open. */
|
|
190
|
+
async function isStill(file, handle) {
|
|
191
|
+
const [mine, now] = await Promise.all([handle.stat({ bigint: true }), stat(file, { bigint: true }).catch(() => null)]);
|
|
192
|
+
return now !== null && now.dev === mine.dev && now.ino === mine.ino;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* What a waiter sees of a file at each try: its holder and when it was last touched. It comes back
|
|
196
|
+
* as stale once it has been seen unchanged over STALE_MS of tries, or over OLD_WATCH_MS when its
|
|
197
|
+
* last touch is also STALE_MS old by the clock. Time seen is counted in tries, so a slow waiter
|
|
198
|
+
* only takes longer. Any change, or a try that found nothing, starts the count again.
|
|
199
|
+
*/
|
|
200
|
+
function lookout(file) {
|
|
201
|
+
let seen = null;
|
|
202
|
+
let tries = 0;
|
|
203
|
+
return async () => {
|
|
204
|
+
const now = await look(file);
|
|
205
|
+
tries = now !== null && now.key === seen ? tries + 1 : 0;
|
|
206
|
+
seen = now?.key ?? null;
|
|
207
|
+
if (now === null)
|
|
208
|
+
return null;
|
|
209
|
+
const watched = tries * RETRY_MS;
|
|
210
|
+
const old = Date.now() - now.touchedAt >= STALE_MS;
|
|
211
|
+
return watched >= STALE_MS || (old && watched >= OLD_WATCH_MS) ? now.key : null;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async function look(file) {
|
|
215
|
+
try {
|
|
216
|
+
// Read apart: a file replaced between the two only starts the count again.
|
|
217
|
+
const [holder, { mtimeMs }] = await Promise.all([readFile(file, 'utf8'), stat(file)]);
|
|
218
|
+
return { key: `${holder} ${String(mtimeMs)}`, touchedAt: mtimeMs };
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (codeOf(error) === 'ENOENT' || deletePending(error))
|
|
222
|
+
return null;
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** Removes `file` only if it is still as it was seen. */
|
|
227
|
+
async function removeIf(file, seen) {
|
|
228
|
+
if ((await look(file))?.key !== seen)
|
|
229
|
+
return;
|
|
230
|
+
await unlink(file).catch((error) => {
|
|
231
|
+
if (codeOf(error) !== 'ENOENT')
|
|
232
|
+
throw error;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/** Removes `file` only while it holds `id`: one taken over meanwhile is its new holder's. */
|
|
236
|
+
async function removeOwn(file, id) {
|
|
237
|
+
if ((await readFile(file, 'utf8').catch(() => null)) === id)
|
|
238
|
+
await unlink(file).catch(noop);
|
|
239
|
+
}
|
|
240
|
+
function aborted(signal) {
|
|
241
|
+
const reason = signal.reason;
|
|
242
|
+
throw reason;
|
|
243
|
+
}
|
|
244
|
+
/** Windows refuses to open a removed file's name while another process still has it open. */
|
|
245
|
+
const deletePending = (error) => process.platform === 'win32' && codeOf(error) === 'EPERM';
|
|
246
|
+
const codeOf = (error) => (error instanceof Error && 'code' in error ? error.code : undefined);
|
|
247
|
+
const noop = () => undefined;
|
|
248
|
+
//# sourceMappingURL=fileLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileLock.js","sourceRoot":"","sources":["../../src/node/fileLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAG1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,sCAAsC;AACtC,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,gDAAgD;AAChD,MAAM,QAA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C,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAEhH,MAAM,IAAI,GAAG,GAAc,EAAE,CAAC,SAAS,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CallbackError, type PendingSignIn } from '../auth/signIn.js';
|
|
2
|
+
/** No browser here to land the redirect: CI, an SSH session, or Linux without a display. */
|
|
3
|
+
export declare function isHeadless(env: Readonly<Record<string, string | undefined>>, platform?: string): boolean;
|
|
4
|
+
export type PastedRedirect =
|
|
5
|
+
/** Pass `callbackUrl` to `finishSignIn`, which exchanges its `code`. */
|
|
6
|
+
{
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly callbackUrl: URL;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly ok: false;
|
|
12
|
+
readonly error: CallbackError | {
|
|
13
|
+
readonly kind: 'not_a_url';
|
|
14
|
+
}
|
|
15
|
+
/** Not the address the sign-in sends the browser back to (`pending.redirectUri`). */
|
|
16
|
+
| {
|
|
17
|
+
readonly kind: 'wrong_redirect';
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The redirect the person pasted, checked as the loopback checks one, before anything is sent: its
|
|
22
|
+
* address first (the loopback answers only its own `/callback`), then its state, its issuer, the
|
|
23
|
+
* server's error, the code.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parsePastedRedirect(text: string, pending: PendingSignIn): PastedRedirect;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readCallback } from '../auth/signIn.js';
|
|
2
|
+
/*
|
|
3
|
+
* Signing in where no browser can come back to this machine (CI, SSH, a Linux box without a
|
|
4
|
+
* display): the person opens the URL elsewhere, and pastes back the address the browser then
|
|
5
|
+
* fails to load. Prompting for it is the app's. Ported from the CLI's headless.ts.
|
|
6
|
+
*/
|
|
7
|
+
/** No browser here to land the redirect: CI, an SSH session, or Linux without a display. */
|
|
8
|
+
export function isHeadless(env, platform = process.platform) {
|
|
9
|
+
if (nonEmpty(env['CI']))
|
|
10
|
+
return true;
|
|
11
|
+
if (nonEmpty(env['SSH_CONNECTION']) || nonEmpty(env['SSH_TTY']))
|
|
12
|
+
return true;
|
|
13
|
+
return platform === 'linux' && !nonEmpty(env['DISPLAY']) && !nonEmpty(env['WAYLAND_DISPLAY']);
|
|
14
|
+
}
|
|
15
|
+
const nonEmpty = (value) => value !== undefined && value !== '';
|
|
16
|
+
/**
|
|
17
|
+
* The redirect the person pasted, checked as the loopback checks one, before anything is sent: its
|
|
18
|
+
* address first (the loopback answers only its own `/callback`), then its state, its issuer, the
|
|
19
|
+
* server's error, the code.
|
|
20
|
+
*/
|
|
21
|
+
export function parsePastedRedirect(text, pending) {
|
|
22
|
+
const trimmed = text.trim();
|
|
23
|
+
if (!URL.canParse(trimmed))
|
|
24
|
+
return { ok: false, error: { kind: 'not_a_url' } };
|
|
25
|
+
const callbackUrl = new URL(trimmed);
|
|
26
|
+
if (!isRedirectTo(callbackUrl, pending.redirectUri))
|
|
27
|
+
return { ok: false, error: { kind: 'wrong_redirect' } };
|
|
28
|
+
const read = readCallback(callbackUrl, pending);
|
|
29
|
+
return read.kind === 'code' ? { ok: true, callbackUrl, code: read.code } : { ok: false, error: read };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The same scheme, host, port and path; the query is the redirect's own. Not `origin`, which is
|
|
33
|
+
* "null" for every private-use scheme (RFC 8252 §7.1), so any two of them would match.
|
|
34
|
+
*/
|
|
35
|
+
function isRedirectTo(url, redirectUri) {
|
|
36
|
+
if (!URL.canParse(redirectUri))
|
|
37
|
+
return false;
|
|
38
|
+
const expected = new URL(redirectUri);
|
|
39
|
+
return url.protocol === expected.protocol && url.host === expected.host && url.pathname === expected.pathname;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=headless.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless.js","sourceRoot":"","s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;IAC/C,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACvG,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,GAAQ,EAAE,WAAmB;IACjD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAA;IAC5C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAA;IACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CAAA;AAC/G,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { signInWithLoopback } from './loopback.js';
|
|
2
|
+
export type { LoopbackError, LoopbackResult, LoopbackSignInOptions } from './loopback.js';
|
|
3
|
+
export { isHeadless, parsePastedRedirect } from './headless.js';
|
|
4
|
+
export type { PastedRedirect } from './headless.js';
|
|
5
|
+
export { createSession, SessionError } from './session.js';
|
|
6
|
+
export { fileLock } from './fileLock.js';
|
|
7
|
+
export type { RevokeResult, Session, SessionFailure, SessionOptions, SessionTokens, TokenUpdate } from './session.js';
|
|
8
|
+
export { finishSignIn } from './clientSecret.js';
|
|
9
|
+
export type { ServerSignInOptions } from './clientSecret.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The `@flipstream/sdk/node` entry: sign-in for Node apps, which the main entry never pulls in,
|
|
2
|
+
// so a browser bundle has no node:http (#65), and the session, which holds a refresh token and so
|
|
3
|
+
// belongs on a backend or in a CLI, never in browser code (D452), with a lock for a store several
|
|
4
|
+
// processes share (#114).
|
|
5
|
+
export { signInWithLoopback } from './loopback.js';
|
|
6
|
+
export { isHeadless, parsePastedRedirect } from './headless.js';
|
|
7
|
+
export { createSession, SessionError } from './session.js';
|
|
8
|
+
export { fileLock } from './fileLock.js';
|
|
9
|
+
// An app with a server signs in as a confidential client, with its client secret (#123).
|
|
10
|
+
export { finishSignIn } from './clientSecret.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,kGAAkG;AAClG,kGAAkG;AAClG,0BAA0B;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,yFAAyF;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA"}
|