@flipstream/sdk 0.5.0 → 0.7.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 +69 -0
- package/README.md +325 -53
- package/dist/auth/discovery.d.ts +5 -4
- package/dist/auth/discovery.js +10 -8
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.js +10 -5
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/transport.d.ts +20 -2
- package/dist/auth/transport.js +25 -5
- package/dist/auth/transport.js.map +1 -1
- package/dist/core/fetch.d.ts +5 -0
- package/dist/core/fetch.js +8 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/flipstream.d.ts +8 -0
- package/dist/flipstream.js +4 -3
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/node/fileLock.d.ts +21 -0
- package/dist/node/fileLock.js +36 -48
- package/dist/node/fileLock.js.map +1 -1
- package/dist/node/fileStore.d.ts +41 -0
- package/dist/node/fileStore.js +137 -0
- package/dist/node/fileStore.js.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +3 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.d.ts +1 -0
- package/dist/node/keychainChild.js +136 -0
- package/dist/node/keychainChild.js.map +1 -0
- package/dist/node/keychainStore.d.ts +34 -0
- package/dist/node/keychainStore.js +268 -0
- package/dist/node/keychainStore.js.map +1 -0
- package/dist/node/loopback.js +1 -1
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +73 -12
- package/dist/node/session.js +248 -35
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +48 -0
- package/dist/node/store.js +99 -0
- package/dist/node/store.js.map +1 -0
- package/dist/query/catalog.d.ts +271 -2
- package/dist/query/catalog.js +93 -5
- package/dist/query/catalog.js.map +1 -1
- package/dist/query/query.d.ts +14 -5
- package/dist/query/query.js +21 -6
- package/dist/query/query.js.map +1 -1
- package/dist/spec/query-planner/index.d.ts +1 -1
- package/dist/spec/query-planner/types.gen.d.ts +35 -4
- package/dist/spec/query-planner/zod.gen.d.ts +257 -64
- package/dist/spec/query-planner/zod.gen.js +31 -5
- package/dist/spec/query-planner/zod.gen.js.map +1 -1
- package/dist/version.gen.d.ts +2 -0
- package/dist/version.gen.js +4 -0
- package/dist/version.gen.js.map +1 -0
- package/package.json +9 -3
package/dist/auth/signIn.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
3
|
import { challengeOf, randomValue } from './pkce.js';
|
|
4
4
|
import { tokenCall } from './tokenEndpoint.js';
|
|
5
|
-
import { authTransport,
|
|
5
|
+
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
6
6
|
const nonEmpty = (value) => typeof value === 'string' && value !== '';
|
|
7
7
|
/**
|
|
8
8
|
* The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
|
|
@@ -64,16 +64,21 @@ export function readCallback(callbackUrl, pending) {
|
|
|
64
64
|
const code = params.get('code');
|
|
65
65
|
return nonEmpty(code) ? { kind: 'code', code } : { kind: 'no_code' };
|
|
66
66
|
}
|
|
67
|
-
const zPending = z
|
|
67
|
+
const zPending = z
|
|
68
|
+
.object({
|
|
68
69
|
state: z.string().min(1),
|
|
69
70
|
verifier: z.string().min(43).max(128),
|
|
70
71
|
clientId: z.string().min(1),
|
|
71
72
|
redirectUri: z.string().min(1),
|
|
72
73
|
scope: z.string().min(1),
|
|
73
74
|
issuer: z.string().min(1),
|
|
74
|
-
tokenEndpoint: z.string()
|
|
75
|
+
tokenEndpoint: z.string(),
|
|
75
76
|
issuerOnRedirect: z.boolean(),
|
|
76
|
-
})
|
|
77
|
+
})
|
|
78
|
+
// A pending from storage may have been edited. Its token endpoint is held to the issuer's rule:
|
|
79
|
+
// https for an https issuer; for an http one on this machine, its own origin, which `finishSignIn`
|
|
80
|
+
// then sends to only with `allowLocalhostHttp` (#164).
|
|
81
|
+
.refine((pending) => endpointProblem(pending.issuer, [pending.tokenEndpoint]) === null);
|
|
77
82
|
/** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
|
|
78
83
|
export const isPendingSignIn = (value) => zPending.safeParse(value).success;
|
|
79
84
|
/**
|
|
@@ -91,7 +96,7 @@ export function finishSignIn(callbackUrl, pending, options = {}) {
|
|
|
91
96
|
* entry never exports this, so browser code has no way to send client credentials.
|
|
92
97
|
*/
|
|
93
98
|
export async function exchangeCode(callbackUrl, pending, options, authorization) {
|
|
94
|
-
if (!isPendingSignIn(pending) || !URL.canParse(callbackUrl))
|
|
99
|
+
if (!isPendingSignIn(pending) || !isSignInUrl(pending.tokenEndpoint, options.allowLocalhostHttp) || !URL.canParse(callbackUrl))
|
|
95
100
|
return { ok: false, error: { kind: 'refused' } };
|
|
96
101
|
const callback = readCallback(callbackUrl, pending);
|
|
97
102
|
if (callback.kind !== 'code')
|
package/dist/auth/signIn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA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C,QAAQ;QAC3B,aAAa,EAAE,OAAO,CAAC,QAAQ;KAChC,CAAA;IACD,0EAA0E;IAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9I,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;IACtE,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,WAAW,EAAE,YAAY;YACzB,+FAA+F;YAC/F,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC;YAC9E,wFAAwF;YACxF,wBAAwB;YACxB,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK;SAC9B;KACF,CAAA;AACH,CAAC"}
|
package/dist/auth/transport.d.ts
CHANGED
|
@@ -5,14 +5,32 @@ export interface AuthCallOptions {
|
|
|
5
5
|
readonly signal?: AbortSignal | undefined;
|
|
6
6
|
/** The app's own fetch, called as a plain function; the global one when it is undefined. */
|
|
7
7
|
readonly fetch?: typeof fetch | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Plain http to an auth server on this machine (localhost, 127.0.0.1, [::1]), as
|
|
10
|
+
* `createFlipstream`'s option: for developing against a local pulse-auth, never in production.
|
|
11
|
+
* Off unless set, and only ever the app's choice, never read from the environment (D503). An http
|
|
12
|
+
* issuer's endpoints must then all be on its own origin.
|
|
13
|
+
*/
|
|
14
|
+
readonly allowLocalhostHttp?: boolean | undefined;
|
|
8
15
|
}
|
|
9
16
|
/**
|
|
10
17
|
* An absolute https URL a Request can be made for: one with a user or password in it is refused
|
|
11
18
|
* by fetch, so it is no endpoint either.
|
|
12
19
|
*/
|
|
13
20
|
export declare function isHttpsUrl(value: string): boolean;
|
|
21
|
+
/** As `isHttpsUrl`, and with `allowLocalhostHttp`, an http URL on this machine too (#164). */
|
|
22
|
+
export declare function isSignInUrl(value: string, allowLocalhostHttp: boolean | undefined): boolean;
|
|
14
23
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
24
|
+
* What's wrong with an issuer's endpoints, or null (#164). An https issuer's must be https, with or
|
|
25
|
+
* without `allowLocalhostHttp`, as before. An http issuer, which only the option lets through, is a
|
|
26
|
+
* server on this machine: its endpoints must all be on its own origin (scheme, host and port), so
|
|
27
|
+
* it can't send the sign-in elsewhere. The one rule for every place endpoints come from:
|
|
28
|
+
* `discover`, a pending sign-in from storage, a server the app builds.
|
|
29
|
+
*/
|
|
30
|
+
export declare function endpointProblem(issuer: string, endpoints: readonly string[]): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Sign-in's transport: https only, or with `allowLocalhostHttp` http to this machine, and no
|
|
33
|
+
* token, since these calls are how a token is had. It sends as the default transport does
|
|
34
|
+
* (`sendRequest`): no cookies, and no redirect followed.
|
|
17
35
|
*/
|
|
18
36
|
export declare function authTransport(options: AuthCallOptions): Transport;
|
package/dist/auth/transport.js
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
import { sendRequest } from '../core/fetch.js';
|
|
1
|
+
import { isLoopbackHttp, sendRequest } from '../core/fetch.js';
|
|
2
2
|
/**
|
|
3
3
|
* An absolute https URL a Request can be made for: one with a user or password in it is refused
|
|
4
4
|
* by fetch, so it is no endpoint either.
|
|
5
5
|
*/
|
|
6
6
|
export function isHttpsUrl(value) {
|
|
7
|
+
return isSignInUrl(value, false);
|
|
8
|
+
}
|
|
9
|
+
/** As `isHttpsUrl`, and with `allowLocalhostHttp`, an http URL on this machine too (#164). */
|
|
10
|
+
export function isSignInUrl(value, allowLocalhostHttp) {
|
|
7
11
|
if (!URL.canParse(value))
|
|
8
12
|
return false;
|
|
9
13
|
const url = new URL(value);
|
|
10
|
-
return url.protocol === 'https:' && url.username === '' && url.password === '';
|
|
14
|
+
return (url.protocol === 'https:' || (allowLocalhostHttp === true && isLoopbackHttp(url))) && url.username === '' && url.password === '';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What's wrong with an issuer's endpoints, or null (#164). An https issuer's must be https, with or
|
|
18
|
+
* without `allowLocalhostHttp`, as before. An http issuer, which only the option lets through, is a
|
|
19
|
+
* server on this machine: its endpoints must all be on its own origin (scheme, host and port), so
|
|
20
|
+
* it can't send the sign-in elsewhere. The one rule for every place endpoints come from:
|
|
21
|
+
* `discover`, a pending sign-in from storage, a server the app builds.
|
|
22
|
+
*/
|
|
23
|
+
export function endpointProblem(issuer, endpoints) {
|
|
24
|
+
if (URL.canParse(issuer) && new URL(issuer).protocol === 'http:') {
|
|
25
|
+
const { origin } = new URL(issuer);
|
|
26
|
+
return endpoints.every((endpoint) => isSignInUrl(endpoint, true) && new URL(endpoint).origin === origin) ? null : "an endpoint is not on the issuer's origin";
|
|
27
|
+
}
|
|
28
|
+
return endpoints.every(isHttpsUrl) ? null : 'an endpoint is not an https URL';
|
|
11
29
|
}
|
|
12
30
|
/**
|
|
13
|
-
* Sign-in's transport: https only,
|
|
14
|
-
*
|
|
31
|
+
* Sign-in's transport: https only, or with `allowLocalhostHttp` http to this machine, and no
|
|
32
|
+
* token, since these calls are how a token is had. It sends as the default transport does
|
|
33
|
+
* (`sendRequest`): no cookies, and no redirect followed.
|
|
15
34
|
*/
|
|
16
35
|
export function authTransport(options) {
|
|
17
36
|
const send = options.fetch ?? globalThis.fetch;
|
|
18
37
|
return async (call) => {
|
|
19
38
|
const built = call.makeRequest();
|
|
20
|
-
|
|
39
|
+
const url = new URL(built.url);
|
|
40
|
+
if (url.protocol !== 'https:' && !(options.allowLocalhostHttp === true && isLoopbackHttp(url)))
|
|
21
41
|
return { kind: 'refused', reason: 'destination' };
|
|
22
42
|
const sent = await sendRequest(send, built, new Headers(built.headers), call.signal);
|
|
23
43
|
return sent.kind === 'sent' ? { kind: 'response', response: sent.response } : sent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/auth/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/auth/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAkB9D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAClC,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,kBAAuC;IAChF,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACtC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,kBAAkB,KAAK,IAAI,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,CAAA;AAC1I,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,SAA4B;IAC1E,IAA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C,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;IACpF,CAAC,CAAA;AACH,CAAC"}
|
package/dist/core/fetch.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface FetchTransportOptions {
|
|
|
16
16
|
/** Plain http to a loopback host (localhost, 127.0.0.1, [::1]): development and tests only. */
|
|
17
17
|
readonly allowLocalhostHttp?: boolean | undefined;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Plain http to this machine (localhost, 127.0.0.1, [::1]), which `allowLocalhostHttp` lets
|
|
21
|
+
* through, here and in sign-in (#164): one set, so the two can't drift.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isLoopbackHttp(url: URL): boolean;
|
|
19
24
|
declare const ABORTED: {
|
|
20
25
|
readonly kind: "aborted";
|
|
21
26
|
};
|
package/dist/core/fetch.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const SERVICES = ['query', 'api', 'auth'];
|
|
2
2
|
const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
3
|
+
/**
|
|
4
|
+
* Plain http to this machine (localhost, 127.0.0.1, [::1]), which `allowLocalhostHttp` lets
|
|
5
|
+
* through, here and in sign-in (#164): one set, so the two can't drift.
|
|
6
|
+
*/
|
|
7
|
+
export function isLoopbackHttp(url) {
|
|
8
|
+
return url.protocol === 'http:' && LOOPBACK.has(url.hostname);
|
|
9
|
+
}
|
|
3
10
|
const ABORTED = { kind: 'aborted' };
|
|
4
11
|
const REFUSED = { kind: 'refused', reason: 'destination' };
|
|
5
12
|
export function fetchTransport(options) {
|
|
@@ -73,7 +80,7 @@ function destinations({ hosts, allowLocalhostHttp }) {
|
|
|
73
80
|
}
|
|
74
81
|
return (service, href) => {
|
|
75
82
|
const url = new URL(href);
|
|
76
|
-
const secure = url.protocol === 'https:' || (allowLocalhostHttp === true &&
|
|
83
|
+
const secure = url.protocol === 'https:' || (allowLocalhostHttp === true && isLoopbackHttp(url));
|
|
77
84
|
return secure && origins.get(service) === url.origin;
|
|
78
85
|
};
|
|
79
86
|
}
|
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;
|
|
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;AAElF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,GAAQ;IACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC/D,CAAC;AACD,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAW,CAAA;AAC5C,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAW,CAAA;AAOnE,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;IAC9C,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IAErC;;;;OAIG;IACH,KAAK,UAAU,OAAO,CAAC,IAAgB,EAAE,GAAa;QACpD,MAAM,KAAK,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,EAAE,KAAK,EAAE,CAAC,CACzD,CAAA;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAC7C,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC"}
|
package/dist/flipstream.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export type FlipstreamOptions =
|
|
|
13
13
|
{
|
|
14
14
|
readonly transport: Transport;
|
|
15
15
|
readonly hosts?: Hosts;
|
|
16
|
+
/**
|
|
17
|
+
* Where the SDK's warnings go: today one note for each catalogue format type it doesn't know,
|
|
18
|
+
* once per process. `console.warn` when left out; `() => {}` silences them. A handler that
|
|
19
|
+
* throws is ignored, so the read that warned still answers (#171).
|
|
20
|
+
*/
|
|
21
|
+
readonly onWarning?: (message: string) => void;
|
|
16
22
|
readonly token?: never;
|
|
17
23
|
readonly fetch?: never;
|
|
18
24
|
readonly allowLocalhostHttp?: never;
|
|
@@ -22,6 +28,8 @@ export type FlipstreamOptions =
|
|
|
22
28
|
readonly token: TokenFunction;
|
|
23
29
|
readonly fetch?: typeof fetch;
|
|
24
30
|
readonly hosts?: Hosts;
|
|
31
|
+
/** Where the SDK's warnings go, as for a client with a transport. */
|
|
32
|
+
readonly onWarning?: (message: string) => void;
|
|
25
33
|
/** Plain http to a loopback host, for development and tests only. Off unless set. */
|
|
26
34
|
readonly allowLocalhostHttp?: boolean;
|
|
27
35
|
readonly transport?: never;
|
package/dist/flipstream.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { call } from './core/call.js';
|
|
2
2
|
import { fetchTransport, tokenlessTransport } from './core/fetch.js';
|
|
3
|
-
import { catalogGet, catalogList } from './query/catalog.js';
|
|
3
|
+
import { catalogGet, catalogList, consoleWarn } from './query/catalog.js';
|
|
4
4
|
import { healthCheck } from './query/health.js';
|
|
5
5
|
import { queryRun, unsentFields } from './query/query.js';
|
|
6
6
|
const DEFAULT_HOSTS = { query: 'https://query.flipstream.io' };
|
|
@@ -11,15 +11,16 @@ export function createFlipstream(options) {
|
|
|
11
11
|
? options.transport
|
|
12
12
|
: fetchTransport({ token: options.token, fetch: options.fetch, hosts, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
13
13
|
const base = (hosts.query ?? DEFAULT_HOSTS.query).replace(/\/+$/, '');
|
|
14
|
+
const warn = options.onWarning ?? consoleWarn;
|
|
14
15
|
// For health alone (#111), whichever way the SDK was made: only the query host, so the call that
|
|
15
16
|
// works signed out can go nowhere else.
|
|
16
17
|
const signedOut = tokenlessTransport({ fetch: options.fetch, hosts: { query: base }, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
17
18
|
const send = (spec, { signal, deadlineMs } = {}, via = transport) => call(via, deadlineMs === undefined ? spec : { ...spec, deadlineMs }, signal);
|
|
18
19
|
return {
|
|
19
20
|
catalog: {
|
|
20
|
-
list: (callOptions) => send(catalogList(base), callOptions),
|
|
21
|
+
list: (callOptions) => send(catalogList(base, warn), callOptions),
|
|
21
22
|
get(request, callOptions) {
|
|
22
|
-
const spec = catalogGet(base, request.source);
|
|
23
|
+
const spec = catalogGet(base, request.source, warn);
|
|
23
24
|
// Refused before anything is sent: the token function isn't asked, and nothing is spent.
|
|
24
25
|
return spec === null ? Promise.resolve({ ok: false, error: { kind: 'refused' } }) : send(spec, callOptions);
|
|
25
26
|
},
|
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,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAA;AAGnF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+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AW,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC;KACzE,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createFlipstream } from './flipstream.js';
|
|
2
2
|
export type { CallOptions, Flipstream, FlipstreamOptions, Hosts, TokenFunction } from './flipstream.js';
|
|
3
|
+
export { refusedQueryFields } from './query/query.js';
|
|
3
4
|
export type { QueryRequest } from './query/query.js';
|
|
4
5
|
export type { Health } from './query/health.js';
|
|
5
6
|
export { isPlannerCode } from './query/errors.js';
|
|
@@ -7,6 +8,7 @@ export { ApiFailure, orThrow } from './core/result.js';
|
|
|
7
8
|
export type { Answered, ApiError, ApiResult, ErrorCode, Said, StatusKind } from './core/result.js';
|
|
8
9
|
export type { ApiRequest, CancelReason, ServiceName, Transport, TransportResult } from './core/transport.js';
|
|
9
10
|
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 type { Catalog, CatalogSource, CurrencyFormat, CustomDimensions, DateFormat, Dimension, ErrorBody, Format, Metric, NumberFormat, PercentageFormat, PlannerErrorCode, QueryResponse, Row, SortSpec, Source, StringFormat, UnknownFormat, } from './spec/query-planner/types.gen.js';
|
|
11
12
|
export * from './auth/index.js';
|
|
12
13
|
export * from './api/index.js';
|
|
14
|
+
export { version } from './version.gen.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// The package entry point (D421): createFlipstream and its calls, the results they give (D412),
|
|
2
2
|
// and the core types a console needs to pass its own transport.
|
|
3
3
|
export { createFlipstream } from './flipstream.js';
|
|
4
|
+
// fs.query's field check, for an app to run before anything else it does (#183).
|
|
5
|
+
export { refusedQueryFields } from './query/query.js';
|
|
4
6
|
export { isPlannerCode } from './query/errors.js';
|
|
5
7
|
export { ApiFailure, orThrow } from './core/result.js';
|
|
6
8
|
export * from './auth/index.js';
|
|
7
9
|
export * from './api/index.js';
|
|
10
|
+
// The SDK's own version, written from package.json at build time (tools/write-version.mjs, #132).
|
|
11
|
+
export { version } from './version.gen.js';
|
|
8
12
|
//# sourceMappingURL=index.js.map
|
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;AAElD,iFAAiF;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAwBtD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,kGAAkG;AAClG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/node/fileLock.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import type { SessionOptions } from './session.js';
|
|
2
|
+
/**
|
|
3
|
+
* The lock's timings. `fileLock` always runs on `TIMINGS`; `createFileLock`, which the package
|
|
4
|
+
* doesn't export, runs the same rules on shorter ones, for the tests.
|
|
5
|
+
*/
|
|
6
|
+
export interface Timings {
|
|
7
|
+
/** How often a waiter tries again. */
|
|
8
|
+
readonly retryMs: number;
|
|
9
|
+
/** How often a holder touches its lock file. */
|
|
10
|
+
readonly touchMs: number;
|
|
11
|
+
/** A file untouched this long has no live holder. */
|
|
12
|
+
readonly staleMs: number;
|
|
13
|
+
/** How long a waiter watches a file whose last touch is already `staleMs` old by the clock. */
|
|
14
|
+
readonly oldWatchMs: number;
|
|
15
|
+
/** The clock moving this much further than time did between two tries is a jump. */
|
|
16
|
+
readonly jumpMs: number;
|
|
17
|
+
/** Two tries this far apart by the clock alone are a jump too: a wake, whichever clock counts sleep. */
|
|
18
|
+
readonly wakeMs: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const TIMINGS: Timings;
|
|
2
21
|
/**
|
|
3
22
|
* A lock across processes, for `createSession`'s `lock` option: for a token store that several
|
|
4
23
|
* Node processes share, such as a CLI run several times at once. Give every process the same
|
|
@@ -25,3 +44,5 @@ import type { SessionOptions } from './session.js';
|
|
|
25
44
|
* only, as the file is).
|
|
26
45
|
*/
|
|
27
46
|
export declare function fileLock(path: string): NonNullable<SessionOptions['lock']>;
|
|
47
|
+
/** `fileLock` on other timings. The package doesn't export it: the tests use it, to run faster. */
|
|
48
|
+
export declare function createFileLock(path: string, timings: Timings): NonNullable<SessionOptions['lock']>;
|
package/dist/node/fileLock.js
CHANGED
|
@@ -3,37 +3,7 @@ import { mkdir, open, readFile, stat, unlink } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, isAbsolute } from 'node:path';
|
|
4
4
|
import { clearInterval, setInterval } from 'node:timers';
|
|
5
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;
|
|
6
|
+
export const TIMINGS = { retryMs: 100, touchMs: 1_000, staleMs: 10_000, oldWatchMs: 3_000, jumpMs: 1_000, wakeMs: 5_000 };
|
|
37
7
|
/**
|
|
38
8
|
* A lock across processes, for `createSession`'s `lock` option: for a token store that several
|
|
39
9
|
* Node processes share, such as a CLI run several times at once. Give every process the same
|
|
@@ -60,11 +30,15 @@ const OLD_WATCH_MS = 3_000;
|
|
|
60
30
|
* only, as the file is).
|
|
61
31
|
*/
|
|
62
32
|
export function fileLock(path) {
|
|
33
|
+
return createFileLock(path, TIMINGS);
|
|
34
|
+
}
|
|
35
|
+
/** `fileLock` on other timings. The package doesn't export it: the tests use it, to run faster. */
|
|
36
|
+
export function createFileLock(path, timings) {
|
|
63
37
|
// A relative path names another file in each working directory, and locks nothing.
|
|
64
38
|
if (!isAbsolute(path))
|
|
65
39
|
throw new TypeError(`fileLock needs an absolute path, the same in every process: ${path}`);
|
|
66
40
|
return async (work, signal) => {
|
|
67
|
-
const held = await take(path, signal);
|
|
41
|
+
const held = await take(path, signal, timings);
|
|
68
42
|
try {
|
|
69
43
|
return await work();
|
|
70
44
|
}
|
|
@@ -73,16 +47,16 @@ export function fileLock(path) {
|
|
|
73
47
|
}
|
|
74
48
|
};
|
|
75
49
|
}
|
|
76
|
-
async function take(path, signal) {
|
|
50
|
+
async function take(path, signal, timings) {
|
|
77
51
|
const id = randomUUID();
|
|
78
|
-
const lock = lookout(path);
|
|
79
|
-
const turns = lookout(turnsOf(path));
|
|
52
|
+
const lock = lookout(path, timings);
|
|
53
|
+
const turns = lookout(turnsOf(path), timings);
|
|
80
54
|
for (;;) {
|
|
81
55
|
if (signal.aborted)
|
|
82
56
|
return aborted(signal);
|
|
83
57
|
const handle = await createWith(path, id);
|
|
84
58
|
if (handle !== null) {
|
|
85
|
-
const held = hold(path, id, handle);
|
|
59
|
+
const held = hold(path, id, handle, timings.touchMs);
|
|
86
60
|
// Taken in the same moment the signal fired: let go at once, unused.
|
|
87
61
|
if (!signal.aborted)
|
|
88
62
|
return held;
|
|
@@ -93,23 +67,23 @@ async function take(path, signal) {
|
|
|
93
67
|
if (stale !== null)
|
|
94
68
|
await takeOver(path, stale, id, turns);
|
|
95
69
|
// An abort ends the pause early; the loop's first line then gives up.
|
|
96
|
-
await pause(
|
|
70
|
+
await pause(timings.retryMs, undefined, { signal }).catch(noop);
|
|
97
71
|
}
|
|
98
72
|
}
|
|
99
|
-
function hold(path, id, handle) {
|
|
73
|
+
function hold(path, id, handle, touchMs) {
|
|
100
74
|
let touching = false;
|
|
101
75
|
const touched = () => {
|
|
102
76
|
touching = false;
|
|
103
77
|
};
|
|
104
78
|
const touch = setInterval(() => {
|
|
105
79
|
// One at a time: on a hung disk, touches would pile up behind each other. A touch that fails
|
|
106
|
-
// is tried again
|
|
80
|
+
// is tried again at the next; failing for the whole stale time, the lock looks stale.
|
|
107
81
|
if (touching)
|
|
108
82
|
return;
|
|
109
83
|
touching = true;
|
|
110
84
|
const now = new Date();
|
|
111
85
|
handle.utimes(now, now).then(touched, touched);
|
|
112
|
-
},
|
|
86
|
+
}, touchMs);
|
|
113
87
|
// A process with nothing left to do but hold the lock exits, and its lock goes stale, rather
|
|
114
88
|
// than holding every other process off for ever.
|
|
115
89
|
touch.unref();
|
|
@@ -193,22 +167,36 @@ async function isStill(file, handle) {
|
|
|
193
167
|
}
|
|
194
168
|
/**
|
|
195
169
|
* 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
|
|
197
|
-
* last touch is also
|
|
198
|
-
* only takes longer. Any change,
|
|
170
|
+
* as stale once it has been seen unchanged over `staleMs` of tries, or over `oldWatchMs` when its
|
|
171
|
+
* last touch is also `staleMs` old by the clock. Time seen is counted in tries, so a slow waiter
|
|
172
|
+
* only takes longer. Any change, a try that found nothing, or a jump starts the count again.
|
|
173
|
+
*
|
|
174
|
+
* A jump is either of two things since the last try:
|
|
175
|
+
* - the clock moving `jumpMs` further than `performance.now()` did: the clock stepped forward. Load,
|
|
176
|
+
* or a thread blocked between tries, moves both alike, so it never counts;
|
|
177
|
+
* - the clock moving over `wakeMs` at all: the machine slept. macOS's monotonic clock counts sleep
|
|
178
|
+
* (libuv's `mach_continuous_time`), and Windows' may, so the first can't see a wake there. Only a
|
|
179
|
+
* step or a sleep of 9 s or more can make a live holder's file, touched every second, look 10 s
|
|
180
|
+
* old, and those all show as gaps of over 5 s. A waiter that stalls over 5 s at every try
|
|
181
|
+
* restarts each time.
|
|
199
182
|
*/
|
|
200
|
-
function lookout(file) {
|
|
183
|
+
function lookout(file, timings) {
|
|
201
184
|
let seen = null;
|
|
202
185
|
let tries = 0;
|
|
186
|
+
let triedAt = { clock: Date.now(), time: performance.now() };
|
|
203
187
|
return async () => {
|
|
204
188
|
const now = await look(file);
|
|
205
|
-
|
|
189
|
+
const at = { clock: Date.now(), time: performance.now() };
|
|
190
|
+
const moved = at.clock - triedAt.clock;
|
|
191
|
+
const jumped = moved - (at.time - triedAt.time) > timings.jumpMs || moved > timings.wakeMs;
|
|
192
|
+
triedAt = at;
|
|
193
|
+
tries = now !== null && now.key === seen && !jumped ? tries + 1 : 0;
|
|
206
194
|
seen = now?.key ?? null;
|
|
207
195
|
if (now === null)
|
|
208
196
|
return null;
|
|
209
|
-
const watched = tries *
|
|
210
|
-
const old = Date.now() - now.touchedAt >=
|
|
211
|
-
return watched >=
|
|
197
|
+
const watched = tries * timings.retryMs;
|
|
198
|
+
const old = Date.now() - now.touchedAt >= timings.staleMs;
|
|
199
|
+
return watched >= timings.staleMs || (old && watched >= timings.oldWatchMs) ? now.key : null;
|
|
212
200
|
};
|
|
213
201
|
}
|
|
214
202
|
async function look(file) {
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"fileLock.js","sourceRoot":"","sources":["../../src/node/fileLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA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AA;AAEhH,MAAM,IAAI,GAAG,GAAc,EAAE,CAAC,SAAS,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type TokenStore } from './store.js';
|
|
2
|
+
import type { SessionOptions } from './session.js';
|
|
3
|
+
/**
|
|
4
|
+
* The tokens in one file, readable by its owner only (mode 0600), for a CLI or a backend on any
|
|
5
|
+
* platform Node runs on. A save writes the whole file under a temporary name in the same folder,
|
|
6
|
+
* flushes it to disk (fsync), renames it over the old one, and flushes the folder: a reader, in this
|
|
7
|
+
* process or another, sees the old tokens or the new ones, never half of either, and a power cut
|
|
8
|
+
* can't bring back the old file with its spent refresh token.
|
|
9
|
+
*
|
|
10
|
+
* - **A missing file** is nobody signed in. A file that holds anything else, or that this user
|
|
11
|
+
* doesn't own alone, fails the read: a symbolic link, a pipe, another user's file, or one that
|
|
12
|
+
* others may read or write.
|
|
13
|
+
* - **The folder** is made (mode 0700) when it doesn't exist. A read or a save in a folder that
|
|
14
|
+
* another user owns or that others may write to fails: they could swap the file. A clear still
|
|
15
|
+
* deletes there, since a deleted file is what a sign-out wants. Only the mode bits are read, so
|
|
16
|
+
* an access list that lets others write (macOS `chmod +a`) goes unseen.
|
|
17
|
+
* - **On Windows** the folder isn't flushed, since it can't be opened to be, the file's mode is what
|
|
18
|
+
* Windows makes of 0600, and nothing checks who owns what.
|
|
19
|
+
* - **With `{ lock: true }`** it also returns `lock`, for every process that opens this file. See
|
|
20
|
+
* the second signature.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fileStore(path: string, options?: {
|
|
23
|
+
readonly lock?: false;
|
|
24
|
+
}): TokenStore;
|
|
25
|
+
/**
|
|
26
|
+
* The same store, with its own `lock` for the processes that share the file (D519): `fileLock` on
|
|
27
|
+
* the file's absolute path with `.lock` added, beside it, so every process and every version of an
|
|
28
|
+
* app that opens this file takes one lock file.
|
|
29
|
+
*
|
|
30
|
+
* - **Spread it into `createSession`,** and the session takes `lock` for its refreshes and
|
|
31
|
+
* sign-outs. Take `lock` too around a sign-in's `save` and your own `clear`. Don't pass a `lock`
|
|
32
|
+
* of your own as well: the session would hold one, and your steps the other.
|
|
33
|
+
* - **The store's own steps never take it,** so a step inside `lock` doesn't wait for itself, and a
|
|
34
|
+
* clear leaves the lock file alone. `lock` isn't reentrant, though: a session call made inside it
|
|
35
|
+
* waits for it, and fails at its own time limit.
|
|
36
|
+
*/
|
|
37
|
+
export declare function fileStore(path: string, options: {
|
|
38
|
+
readonly lock: true;
|
|
39
|
+
}): TokenStore & {
|
|
40
|
+
readonly lock: NonNullable<SessionOptions['lock']>;
|
|
41
|
+
};
|