@flipstream/sdk 0.6.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 +44 -0
- package/README.md +212 -34
- 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 +2 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/node/fileLock.d.ts +21 -0
- package/dist/node/fileLock.js +23 -54
- package/dist/node/fileLock.js.map +1 -1
- package/dist/node/fileStore.d.ts +23 -1
- package/dist/node/fileStore.js +20 -18
- package/dist/node/fileStore.js.map +1 -1
- package/dist/node/keychainChild.js +84 -48
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainStore.d.ts +7 -3
- package/dist/node/keychainStore.js +169 -51
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.js +1 -1
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +31 -2
- package/dist/node/session.js +88 -17
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +5 -1
- package/dist/node/store.js +12 -4
- package/dist/node/store.js.map +1 -1
- 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.js +1 -1
- package/package.json +1 -1
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,CA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K,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,kBAAkB,KAAK,IAAI,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;QACjJ,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACpF,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,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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AAK,CAAC,GAAG,CAAC,CAAC;SACtB,IAAI,CACH,CAAC,KAAK,EAAS,EAAE,CACf,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE;QACvC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;QACjC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,kCAAkC,CAAC,EAAE,EACpF,CAAC,KAAc,EAAS,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,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
|
+
{"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,WAAW,EAAa,MAAM,oBAAoB,CAAA;AACpF,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAqB,MAAM,kBAAkB,CAAA;AA0D5E,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,CA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MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;YACpC,uFAAuF;YACvF,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,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
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,7 +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';
|
|
13
14
|
export { version } from './version.gen.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
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,42 +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).
|
|
21
|
-
* - Neither a clock that jumps forward nor a laptop waking from sleep makes a live lock stale on
|
|
22
|
-
* its own: a jump starts the waiter's watch again (`lookout`), so the holder, whose file may only
|
|
23
|
-
* now look old, has 3 s from then to touch it (#144, R2-1). A holder on a clock 10 s or more
|
|
24
|
-
* behind this one, in a virtual machine sharing the folder say, has only 2 to 3 s without a
|
|
25
|
-
* touch, all the time.
|
|
26
|
-
*
|
|
27
|
-
* Waiters that judge a lock stale together take turns through a second file, so none removes a
|
|
28
|
-
* lock another has just taken (honest-typescript §5): of those, only the first finds it unchanged.
|
|
29
|
-
*/
|
|
30
|
-
/** How often a waiter tries again. */
|
|
31
|
-
const RETRY_MS = 100;
|
|
32
|
-
/** How often a holder touches its lock file. */
|
|
33
|
-
const TOUCH_MS = 1_000;
|
|
34
|
-
/** A file untouched this long has no live holder. */
|
|
35
|
-
const STALE_MS = 10_000;
|
|
36
|
-
/** How long a waiter watches a file whose last touch is already STALE_MS old by the clock. */
|
|
37
|
-
const OLD_WATCH_MS = 3_000;
|
|
38
|
-
/** The clock moving this much further than time did between two tries is a jump. */
|
|
39
|
-
const JUMP_MS = 1_000;
|
|
40
|
-
/** Two tries this far apart by the clock alone are a jump too: a wake, whichever clock counts sleep. */
|
|
41
|
-
const WAKE_MS = 5_000;
|
|
6
|
+
export const TIMINGS = { retryMs: 100, touchMs: 1_000, staleMs: 10_000, oldWatchMs: 3_000, jumpMs: 1_000, wakeMs: 5_000 };
|
|
42
7
|
/**
|
|
43
8
|
* A lock across processes, for `createSession`'s `lock` option: for a token store that several
|
|
44
9
|
* Node processes share, such as a CLI run several times at once. Give every process the same
|
|
@@ -65,11 +30,15 @@ const WAKE_MS = 5_000;
|
|
|
65
30
|
* only, as the file is).
|
|
66
31
|
*/
|
|
67
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) {
|
|
68
37
|
// A relative path names another file in each working directory, and locks nothing.
|
|
69
38
|
if (!isAbsolute(path))
|
|
70
39
|
throw new TypeError(`fileLock needs an absolute path, the same in every process: ${path}`);
|
|
71
40
|
return async (work, signal) => {
|
|
72
|
-
const held = await take(path, signal);
|
|
41
|
+
const held = await take(path, signal, timings);
|
|
73
42
|
try {
|
|
74
43
|
return await work();
|
|
75
44
|
}
|
|
@@ -78,16 +47,16 @@ export function fileLock(path) {
|
|
|
78
47
|
}
|
|
79
48
|
};
|
|
80
49
|
}
|
|
81
|
-
async function take(path, signal) {
|
|
50
|
+
async function take(path, signal, timings) {
|
|
82
51
|
const id = randomUUID();
|
|
83
|
-
const lock = lookout(path);
|
|
84
|
-
const turns = lookout(turnsOf(path));
|
|
52
|
+
const lock = lookout(path, timings);
|
|
53
|
+
const turns = lookout(turnsOf(path), timings);
|
|
85
54
|
for (;;) {
|
|
86
55
|
if (signal.aborted)
|
|
87
56
|
return aborted(signal);
|
|
88
57
|
const handle = await createWith(path, id);
|
|
89
58
|
if (handle !== null) {
|
|
90
|
-
const held = hold(path, id, handle);
|
|
59
|
+
const held = hold(path, id, handle, timings.touchMs);
|
|
91
60
|
// Taken in the same moment the signal fired: let go at once, unused.
|
|
92
61
|
if (!signal.aborted)
|
|
93
62
|
return held;
|
|
@@ -98,23 +67,23 @@ async function take(path, signal) {
|
|
|
98
67
|
if (stale !== null)
|
|
99
68
|
await takeOver(path, stale, id, turns);
|
|
100
69
|
// An abort ends the pause early; the loop's first line then gives up.
|
|
101
|
-
await pause(
|
|
70
|
+
await pause(timings.retryMs, undefined, { signal }).catch(noop);
|
|
102
71
|
}
|
|
103
72
|
}
|
|
104
|
-
function hold(path, id, handle) {
|
|
73
|
+
function hold(path, id, handle, touchMs) {
|
|
105
74
|
let touching = false;
|
|
106
75
|
const touched = () => {
|
|
107
76
|
touching = false;
|
|
108
77
|
};
|
|
109
78
|
const touch = setInterval(() => {
|
|
110
79
|
// One at a time: on a hung disk, touches would pile up behind each other. A touch that fails
|
|
111
|
-
// is tried again
|
|
80
|
+
// is tried again at the next; failing for the whole stale time, the lock looks stale.
|
|
112
81
|
if (touching)
|
|
113
82
|
return;
|
|
114
83
|
touching = true;
|
|
115
84
|
const now = new Date();
|
|
116
85
|
handle.utimes(now, now).then(touched, touched);
|
|
117
|
-
},
|
|
86
|
+
}, touchMs);
|
|
118
87
|
// A process with nothing left to do but hold the lock exits, and its lock goes stale, rather
|
|
119
88
|
// than holding every other process off for ever.
|
|
120
89
|
touch.unref();
|
|
@@ -198,20 +167,20 @@ async function isStill(file, handle) {
|
|
|
198
167
|
}
|
|
199
168
|
/**
|
|
200
169
|
* What a waiter sees of a file at each try: its holder and when it was last touched. It comes back
|
|
201
|
-
* as stale once it has been seen unchanged over
|
|
202
|
-
* last touch is also
|
|
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
|
|
203
172
|
* only takes longer. Any change, a try that found nothing, or a jump starts the count again.
|
|
204
173
|
*
|
|
205
174
|
* A jump is either of two things since the last try:
|
|
206
|
-
* - the clock moving
|
|
175
|
+
* - the clock moving `jumpMs` further than `performance.now()` did: the clock stepped forward. Load,
|
|
207
176
|
* or a thread blocked between tries, moves both alike, so it never counts;
|
|
208
|
-
* - the clock moving over
|
|
177
|
+
* - the clock moving over `wakeMs` at all: the machine slept. macOS's monotonic clock counts sleep
|
|
209
178
|
* (libuv's `mach_continuous_time`), and Windows' may, so the first can't see a wake there. Only a
|
|
210
179
|
* step or a sleep of 9 s or more can make a live holder's file, touched every second, look 10 s
|
|
211
180
|
* old, and those all show as gaps of over 5 s. A waiter that stalls over 5 s at every try
|
|
212
181
|
* restarts each time.
|
|
213
182
|
*/
|
|
214
|
-
function lookout(file) {
|
|
183
|
+
function lookout(file, timings) {
|
|
215
184
|
let seen = null;
|
|
216
185
|
let tries = 0;
|
|
217
186
|
let triedAt = { clock: Date.now(), time: performance.now() };
|
|
@@ -219,15 +188,15 @@ function lookout(file) {
|
|
|
219
188
|
const now = await look(file);
|
|
220
189
|
const at = { clock: Date.now(), time: performance.now() };
|
|
221
190
|
const moved = at.clock - triedAt.clock;
|
|
222
|
-
const jumped = moved - (at.time - triedAt.time) >
|
|
191
|
+
const jumped = moved - (at.time - triedAt.time) > timings.jumpMs || moved > timings.wakeMs;
|
|
223
192
|
triedAt = at;
|
|
224
193
|
tries = now !== null && now.key === seen && !jumped ? tries + 1 : 0;
|
|
225
194
|
seen = now?.key ?? null;
|
|
226
195
|
if (now === null)
|
|
227
196
|
return null;
|
|
228
|
-
const watched = tries *
|
|
229
|
-
const old = Date.now() - now.touchedAt >=
|
|
230
|
-
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;
|
|
231
200
|
};
|
|
232
201
|
}
|
|
233
202
|
async function look(file) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileLock.js","sourceRoot":"","sources":["../../src/node/fileLock.ts"],"names":[],"m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,IAAI,CAAC,CAAA;AAC7F,CAAC;AAED,SAAS,OAAO,CAAC,MAAmB;IAClC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAA;IACrC,MAAM,MAAM,CAAA;AACd,CAAC;AAED,6FAA6F;AAC7F,MAAM,aAAa,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,CAAA;AAE5G,MAAM,MAAM,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAEhH,MAAM,IAAI,GAAG,GAAc,EAAE,CAAC,SAAS,CAAA"}
|
package/dist/node/fileStore.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TokenStore } from './store.js';
|
|
2
|
+
import type { SessionOptions } from './session.js';
|
|
2
3
|
/**
|
|
3
4
|
* The tokens in one file, readable by its owner only (mode 0600), for a CLI or a backend on any
|
|
4
5
|
* platform Node runs on. A save writes the whole file under a temporary name in the same folder,
|
|
@@ -15,5 +16,26 @@ import { type TokenStore } from './store.js';
|
|
|
15
16
|
* an access list that lets others write (macOS `chmod +a`) goes unseen.
|
|
16
17
|
* - **On Windows** the folder isn't flushed, since it can't be opened to be, the file's mode is what
|
|
17
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.
|
|
18
21
|
*/
|
|
19
|
-
export declare function fileStore(path: string
|
|
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
|
+
};
|
package/dist/node/fileStore.js
CHANGED
|
@@ -2,27 +2,29 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
3
|
import { mkdir, open, readdir, rename, stat, unlink } from 'node:fs/promises';
|
|
4
4
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileLock } from './fileLock.js';
|
|
5
6
|
import { parse, storeOf } from './store.js';
|
|
7
|
+
export function fileStore(path, options = {}) {
|
|
8
|
+
const file = resolve(path);
|
|
9
|
+
const store = storeOf(`file:${file}`, () => read(file), (tokens) => (tokens === null ? remove(file) : replace(file, tokens)), () => folderPlace(file));
|
|
10
|
+
return options.lock === true ? { ...store, lock: fileLock(`${file}.lock`) } : store;
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* can't bring back the old file with its spent refresh token.
|
|
12
|
-
*
|
|
13
|
-
* - **A missing file** is nobody signed in. A file that holds anything else, or that this user
|
|
14
|
-
* doesn't own alone, fails the read: a symbolic link, a pipe, another user's file, or one that
|
|
15
|
-
* others may read or write.
|
|
16
|
-
* - **The folder** is made (mode 0700) when it doesn't exist. A read or a save in a folder that
|
|
17
|
-
* another user owns or that others may write to fails: they could swap the file. A clear still
|
|
18
|
-
* deletes there, since a deleted file is what a sign-out wants. Only the mode bits are read, so
|
|
19
|
-
* an access list that lets others write (macOS `chmod +a`) goes unseen.
|
|
20
|
-
* - **On Windows** the folder isn't flushed, since it can't be opened to be, the file's mode is what
|
|
21
|
-
* Windows makes of 0600, and nothing checks who owns what.
|
|
13
|
+
* The file as its folder's device and inode with its name, which two spellings of it share: a path
|
|
14
|
+
* through a linked folder, or a folder spelt in another case on macOS (D504). A name that differs
|
|
15
|
+
* only in case still takes its own turn. Before the folder exists there is nothing to share: the
|
|
16
|
+
* first save makes it.
|
|
22
17
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
async function folderPlace(file) {
|
|
19
|
+
try {
|
|
20
|
+
const { dev, ino } = await stat(dirname(file), { bigint: true });
|
|
21
|
+
return `file-in:${String(dev)}:${String(ino)}:${basename(file)}`;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (codeOf(error) === 'ENOENT')
|
|
25
|
+
return undefined;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
29
|
const POSIX = process.platform !== 'win32';
|
|
28
30
|
// Not through a link, and not waiting on a pipe that nobody writes to (O_NONBLOCK): what is opened
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileStore.js","sourceRoot":"","sources":["../../src/node/fileStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAc,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAA;AAC9F,OAAO,EAAE,QAAQ,EAAE,OAAO,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