@flipstream/sdk 0.6.0 → 0.8.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 +63 -0
- package/README.md +260 -43
- 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/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +146 -54
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +53 -0
- package/dist/node/keychainError.js +48 -0
- package/dist/node/keychainError.js.map +1 -0
- package/dist/node/keychainStore.d.ts +20 -9
- package/dist/node/keychainStore.js +207 -58
- 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 +42 -3
- package/dist/node/session.js +95 -18
- 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
|
@@ -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,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAmB,MAAM,YAAY,CAAA;
|
|
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,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAmB,MAAM,YAAY,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AACH,CAAC;AAED,kHAAkH;AAClH,KAAK,UAAU,UAAU,CAAC,MAAc;IACtC,IAAI,CAAC,KAAK;QAAE,OAAM;IAClB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2EAA2E,MAAM,EAAE,CAAC,CAAA;AAC3J,CAAC;AAED,MAAM,IAAI,GAAG,gEAAgE,CAAA;AAE7E,MAAM,SAAS,GAAG,CAAC,KAAY,EAAW,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAA;AAE7E,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"}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -10,4 +10,6 @@ export type { ServerSignInOptions } from './clientSecret.js';
|
|
|
10
10
|
export { fileStore } from './fileStore.js';
|
|
11
11
|
export { keychainStore } from './keychainStore.js';
|
|
12
12
|
export type { KeychainStoreOptions } from './keychainStore.js';
|
|
13
|
+
export { KeychainError } from './keychainError.js';
|
|
14
|
+
export type { KeychainFailure } from './keychainError.js';
|
|
13
15
|
export type { TokenStore } from './store.js';
|
package/dist/node/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export { fileLock } from './fileLock.js';
|
|
|
10
10
|
export { finishSignIn } from './clientSecret.js';
|
|
11
11
|
export { fileStore } from './fileStore.js';
|
|
12
12
|
export { keychainStore } from './keychainStore.js';
|
|
13
|
+
export { KeychainError } from './keychainError.js';
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,kGAAkG;AAClG,kGAAkG;AAClG,+DAA+D;AAC/D,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;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,kGAAkG;AAClG,kGAAkG;AAClG,+DAA+D;AAC/D,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;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,85 +1,158 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
3
|
-
* (D485, after the CLI's keychain-child.ts). A keychain call can
|
|
4
|
-
* keychain wants a prompt that no screen can show, the call never
|
|
5
|
-
* the process can end it then, not an AbortSignal, a worker's
|
|
6
|
-
* joins the stuck thread. A process can be killed.
|
|
2
|
+
* The keychain helper: one process that keychainStore keeps warm, sends its steps to one at a time,
|
|
3
|
+
* and kills at a step's deadline (D485, D495, after the CLI's keychain-child.ts). A keychain call can
|
|
4
|
+
* park forever: on macOS, when the keychain wants a prompt that no screen can show, the call never
|
|
5
|
+
* returns (cli#119). Nothing inside the process can end it then, not an AbortSignal, a worker's
|
|
6
|
+
* terminate, or process.exit, which joins the stuck thread. A process can be killed.
|
|
7
7
|
*
|
|
8
|
-
* - **
|
|
9
|
-
* variable of this process, which other users can read.
|
|
10
|
-
* - **Standard input stays open as the parent's heartbeat.** When it closes, the parent is gone
|
|
11
|
-
* this process
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* - **Each request is one line on standard input,** with its id: the tokens never become an
|
|
9
|
+
* argument or a variable of this process, which other users can read.
|
|
10
|
+
* - **Standard input stays open as the parent's heartbeat.** When it closes, the parent is gone (it
|
|
11
|
+
* exited, threw, or was killed), and this process ends, rather than being left behind, warm or on
|
|
12
|
+
* a call that never returns: at once when idle or on a read, or once it has answered the save or
|
|
13
|
+
* delete it's on. That step is cut off when its own time left (`msLeft`, in each request) runs
|
|
14
|
+
* out, and `afterParentMs` (1 s) after the parent went at the latest. For this process's first
|
|
15
|
+
* request, that 1 s counts from this process's own start: the request was written as it started,
|
|
16
|
+
* and the parent may have gone any time after (#157 item 15). Before each step, it also checks
|
|
17
|
+
* that its parent is still the app that sent the request. So a save the app started is made even
|
|
18
|
+
* if the app has ended, and a refresh's new tokens aren't lost.
|
|
19
|
+
* - **A terminal Ctrl-C is ignored** (#169). It reaches this process too, as one of the app's
|
|
20
|
+
* process group. The app decides whether to stop, and if it does, this process follows through
|
|
21
|
+
* the heartbeat. Other signals still end it.
|
|
22
|
+
* - **Each answer is one line on file descriptor 3,** a pipe of its own, with the request's id, in
|
|
23
|
+
* one synchronous write: whatever else prints to standard output (a preload in NODE_OPTIONS, say)
|
|
24
|
+
* can't garble it.
|
|
25
|
+
* - **One request at a time,** in the order they came.
|
|
26
|
+
* - **After an answer, nothing here refers to a token:** not the request line, the parsed request,
|
|
27
|
+
* the secret's bytes or the answer. The bytes this process holds, the ones it saves and the ones
|
|
28
|
+
* a read returns, are zeroed once the keychain call is done. Strings can't be: the request line,
|
|
29
|
+
* the tokens' JSON and the answer stay in this process's heap until the garbage collector reclaims
|
|
30
|
+
* them, as the same tokens do in the app itself.
|
|
14
31
|
*/
|
|
15
32
|
import { writeSync } from 'node:fs';
|
|
33
|
+
import { createInterface } from 'node:readline';
|
|
16
34
|
import { z } from 'zod';
|
|
17
35
|
/** The tokens to save are the `set` step's `secret`. */
|
|
18
36
|
const zRequest = z.discriminatedUnion('op', [
|
|
19
|
-
z.strictObject({ op: z.literal('get'), service: z.string(), account: z.string() }),
|
|
20
|
-
z.strictObject({ op: z.literal('delete'), service: z.string(), account: z.string() }),
|
|
21
|
-
z.strictObject({ op: z.literal('set'), service: z.string(), account: z.string(), secret: z.string() }),
|
|
37
|
+
z.strictObject({ id: z.number().int(), msLeft: z.number().int().positive(), afterParentMs: z.number().int().nonnegative(), parent: z.number().int().positive(), op: z.literal('get'), service: z.string(), account: z.string() }),
|
|
38
|
+
z.strictObject({ id: z.number().int(), msLeft: z.number().int().positive(), afterParentMs: z.number().int().nonnegative(), parent: z.number().int().positive(), op: z.literal('delete'), service: z.string(), account: z.string() }),
|
|
39
|
+
z.strictObject({ id: z.number().int(), msLeft: z.number().int().positive(), afterParentMs: z.number().int().nonnegative(), parent: z.number().int().positive(), op: z.literal('set'), service: z.string(), account: z.string(), secret: z.string() }),
|
|
22
40
|
]);
|
|
23
41
|
// SIGKILL, never process.exit: a call stuck in the kernel would hold up an exit too.
|
|
24
|
-
const
|
|
42
|
+
const die = () => {
|
|
25
43
|
process.kill(process.pid, 'SIGKILL');
|
|
26
44
|
};
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
process
|
|
30
|
-
|
|
45
|
+
// A terminal Ctrl-C: the app decides whether to stop, and this process follows it (above).
|
|
46
|
+
process.on('SIGINT', () => undefined);
|
|
47
|
+
// For each request not yet answered, in the order they came, by this process's monotonic clock:
|
|
48
|
+
// - `until`: when it is cut off if the parent goes. A save or a delete keeps its own time left. A
|
|
49
|
+
// read, whose answer nobody would take, and a line that is no request get none;
|
|
50
|
+
// - `first`: whether it is this process's first request. The parent wrote that one as it started
|
|
51
|
+
// this process, before anything here could read, so the parent may have gone any time from about
|
|
52
|
+
// 0 on this clock, which starts with the process. A slow start (a loaded machine, a heavy preload)
|
|
53
|
+
// must not stretch the 1 s past the soonest the parent's lock can pass on. A later request was
|
|
54
|
+
// written while this process was reading, so the parent's end shows here at once.
|
|
55
|
+
const unanswered = [];
|
|
56
|
+
let requests = 0;
|
|
57
|
+
// And how long a step may go on once the parent has gone, at most, as the parent last said
|
|
58
|
+
// (`afterParentMs`, under the soonest the parent's lock may pass to another process).
|
|
59
|
+
let afterParentMs = 0;
|
|
60
|
+
let parentGone = false;
|
|
61
|
+
// Installed first, for the whole life of the process: a parent that dies right after writing a
|
|
62
|
+
// request still takes this process with it, once that request is answered or cut off.
|
|
63
|
+
const parentLeft = () => {
|
|
64
|
+
if (parentGone)
|
|
65
|
+
return;
|
|
66
|
+
parentGone = true;
|
|
67
|
+
const now = performance.now();
|
|
68
|
+
// Each step's cut: its own time left, or `afterParentMs` from when its parent may have gone.
|
|
69
|
+
const cut = Math.max(...unanswered.map((step) => Math.min(step.until, (step.first ? 0 : now) + afterParentMs)));
|
|
70
|
+
// At once when it has passed, so a step can't start meanwhile.
|
|
71
|
+
if (unanswered.length === 0 || cut <= now)
|
|
72
|
+
die();
|
|
73
|
+
else
|
|
74
|
+
setTimeout(die, cut - now);
|
|
75
|
+
};
|
|
76
|
+
process.stdin.on('end', parentLeft);
|
|
77
|
+
process.stdin.on('close', parentLeft);
|
|
31
78
|
const ANSWER_FD = 3;
|
|
32
79
|
const emit = (answer) => {
|
|
33
|
-
|
|
80
|
+
try {
|
|
81
|
+
writeSync(ANSWER_FD, `${JSON.stringify(answer)}\n`);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Nobody reads the answers any more (EPIPE): the parent is gone.
|
|
85
|
+
die();
|
|
86
|
+
}
|
|
34
87
|
};
|
|
35
|
-
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
let buffered = '';
|
|
38
|
-
process.stdin.setEncoding('utf8');
|
|
39
|
-
process.stdin.on('data', (chunk) => {
|
|
40
|
-
buffered += chunk;
|
|
41
|
-
const end = buffered.indexOf('\n');
|
|
42
|
-
if (end !== -1)
|
|
43
|
-
resolve(buffered.slice(0, end));
|
|
44
|
-
});
|
|
45
|
-
process.stdin.on('error', reject);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
88
|
+
/** The request in one line, or the id of a line that is no request (null when it has none). */
|
|
48
89
|
function requestOf(line) {
|
|
49
90
|
let parsed;
|
|
50
91
|
try {
|
|
51
92
|
parsed = JSON.parse(line);
|
|
52
93
|
}
|
|
53
94
|
catch {
|
|
54
|
-
return
|
|
95
|
+
return { id: null };
|
|
55
96
|
}
|
|
56
97
|
const request = zRequest.safeParse(parsed);
|
|
57
|
-
|
|
98
|
+
if (request.success)
|
|
99
|
+
return { request: request.data };
|
|
100
|
+
const id = z.object({ id: z.number().int() }).safeParse(parsed);
|
|
101
|
+
return { id: id.success ? id.data.id : null };
|
|
58
102
|
}
|
|
103
|
+
let keyring;
|
|
104
|
+
const loadKeyring = () => (keyring ??= import('@napi-rs/keyring').then((module) => ({ ok: true, module }), (error) => {
|
|
105
|
+
const missing = error instanceof Error && 'code' in error && error.code === 'ERR_MODULE_NOT_FOUND';
|
|
106
|
+
const outcome = missing ? { ok: false, error: 'not installed', missing: true } : { ok: false, error: `the keyring couldn't load: ${messageOf(error)}` };
|
|
107
|
+
return { ok: false, outcome };
|
|
108
|
+
}));
|
|
59
109
|
async function step(request) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
catch (error) {
|
|
65
|
-
const missing = error instanceof Error && 'code' in error && error.code === 'ERR_MODULE_NOT_FOUND';
|
|
66
|
-
return missing ? { ok: false, error: 'not installed', missing: true } : { ok: false, error: `the keyring couldn't load: ${messageOf(error)}` };
|
|
67
|
-
}
|
|
110
|
+
const loaded = await loadKeyring();
|
|
111
|
+
if (!loaded.ok)
|
|
112
|
+
return loaded.outcome;
|
|
113
|
+
const keyring = loaded.module;
|
|
68
114
|
// Linux: the Secret Service only. Without one, the library falls back to the kernel's keyring,
|
|
69
115
|
// which forgets everything at a reboot; a step that fails is better than a sign-in that vanishes.
|
|
70
116
|
try {
|
|
71
117
|
const entry = new keyring.AsyncEntry(request.service, request.account, { linux: { store: 'secret-service' } });
|
|
72
118
|
switch (request.op) {
|
|
73
119
|
case 'get': {
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
120
|
+
// 2.1.0's typings say `Uint8Array | undefined`, but its Rust returns `Option<Vec<u8>>`, which
|
|
121
|
+
// napi gives as a plain Array of numbers, or null for no item (Michel's live checks: on #142,
|
|
122
|
+
// 17 Oct, a read after a clear failed on null; on #159, 18 Oct, a read of a saved item failed
|
|
123
|
+
// on the Array's missing `.buffer`). A Uint8Array or a Buffer, as another version may give,
|
|
124
|
+
// reads the same. Anything else is no answer about the keychain, never nobody signed in.
|
|
77
125
|
const secret = await entry.getSecret();
|
|
78
|
-
|
|
126
|
+
if (secret === undefined || secret === null)
|
|
127
|
+
return { ok: true, value: null };
|
|
128
|
+
const isBytes = secret instanceof Uint8Array || (Array.isArray(secret) && secret.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255));
|
|
129
|
+
if (!isBytes)
|
|
130
|
+
return { ok: false, error: `the keyring gave the secret as ${Array.isArray(secret) ? 'an array of non-bytes' : typeof secret}, not bytes` };
|
|
131
|
+
// Bytes of their own, never Buffer's shared pool, so they can be zeroed once decoded.
|
|
132
|
+
const bytes = Uint8Array.from(secret);
|
|
133
|
+
try {
|
|
134
|
+
// An empty secret is nothing stored too: no save writes one.
|
|
135
|
+
if (bytes.length === 0)
|
|
136
|
+
return { ok: true, value: null };
|
|
137
|
+
return { ok: true, value: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('utf8') };
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
bytes.fill(0);
|
|
141
|
+
secret.fill(0);
|
|
142
|
+
}
|
|
79
143
|
}
|
|
80
|
-
case 'set':
|
|
81
|
-
|
|
144
|
+
case 'set': {
|
|
145
|
+
// Bytes of their own, never Buffer's shared pool, so they can be zeroed once saved.
|
|
146
|
+
const bytes = new Uint8Array(Buffer.byteLength(request.secret, 'utf8'));
|
|
147
|
+
Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).write(request.secret, 'utf8');
|
|
148
|
+
try {
|
|
149
|
+
await entry.setSecret(bytes);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
bytes.fill(0);
|
|
153
|
+
}
|
|
82
154
|
return { ok: true, value: null };
|
|
155
|
+
}
|
|
83
156
|
// Deleted, or nothing there to delete: either way nothing is saved now.
|
|
84
157
|
case 'delete':
|
|
85
158
|
await entry.deletePassword();
|
|
@@ -92,9 +165,28 @@ async function step(request) {
|
|
|
92
165
|
}
|
|
93
166
|
}
|
|
94
167
|
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
168
|
+
// One request at a time, in order: each waits for the one before it to be answered. Each is counted
|
|
169
|
+
// as it comes, before its turn: the parent may be gone by then.
|
|
170
|
+
let tail = Promise.resolve();
|
|
171
|
+
createInterface({ input: process.stdin, crlfDelay: Infinity }).on('line', (line) => {
|
|
172
|
+
const read = requestOf(line);
|
|
173
|
+
unanswered.push({ until: 'request' in read && read.request.op !== 'get' ? performance.now() + read.request.msLeft : 0, first: requests++ === 0 });
|
|
174
|
+
if ('request' in read)
|
|
175
|
+
afterParentMs = read.request.afterParentMs;
|
|
176
|
+
tail = tail.then(async () => {
|
|
177
|
+
// A parent gone before this step's turn, perhaps while this process was still starting: the
|
|
178
|
+
// end of standard input that came with the request is seen only after a quick step has run,
|
|
179
|
+
// so ask the system who the parent is now. An orphan's parent is no longer the app (#157 item
|
|
180
|
+
// 15). On Windows, which doesn't reparent, only the end of standard input says so.
|
|
181
|
+
if ('request' in read && process.ppid !== read.request.parent)
|
|
182
|
+
parentLeft();
|
|
183
|
+
if ('request' in read)
|
|
184
|
+
emit({ id: read.request.id, ...(await step(read.request)) });
|
|
185
|
+
else
|
|
186
|
+
emit({ id: read.id, ok: false, error: 'the keychain step got no readable request' });
|
|
187
|
+
unanswered.shift();
|
|
188
|
+
if (parentGone && unanswered.length === 0)
|
|
189
|
+
die();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
100
192
|
//# sourceMappingURL=keychainChild.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keychainChild.js","sourceRoot":"","sources":["../../src/node/keychainChild.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"keychainChild.js","sourceRoot":"","sources":["../../src/node/keychainChild.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,wDAAwD;AACxD,MAAM,QAAQ,GAAG,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE;IAC1C,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CA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/**
|
|
2
|
+
* Why a `keychainStore` step failed, in `KeychainError.failure`. Switch on `kind`:
|
|
3
|
+
* - `unavailable`: there's no keychain here, as on Linux with no Secret Service or no D-Bus
|
|
4
|
+
* session (most servers and containers). The only kind after which a file may stand in for the
|
|
5
|
+
* keychain, if the app or the person chooses it.
|
|
6
|
+
* - `locked`: the keychain is locked and can't ask to be unlocked, as on a Mac over SSH after a
|
|
7
|
+
* reboot, before anyone has logged in at the screen.
|
|
8
|
+
* - `refused`: any other refusal by the keychain, in its own words in the message.
|
|
9
|
+
* - `timeout`: the step took longer than its `timeoutMs`, so its helper was ended: a keychain
|
|
10
|
+
* prompt nobody answered, say.
|
|
11
|
+
* - `helper`: the helper process failed. It couldn't start, or it ended or answered something else
|
|
12
|
+
* before it answered. `exit` says how it ended, when it did.
|
|
13
|
+
* - `missing`: the optional package `@napi-rs/keyring` isn't installed.
|
|
14
|
+
* - `too-long`: the tokens are over the 2,560 bytes every platform can keep, so nothing was saved.
|
|
15
|
+
*
|
|
16
|
+
* `unavailable` and `locked` are read from the keychain library's words, which carry no code. Only
|
|
17
|
+
* words known for each match. Anything else is `refused`, never `unavailable`, so that a broken
|
|
18
|
+
* keychain can't send the tokens to a file.
|
|
19
|
+
*/
|
|
20
|
+
export type KeychainFailure = {
|
|
21
|
+
readonly kind: 'unavailable';
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'locked';
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'refused';
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'timeout';
|
|
28
|
+
readonly timeoutMs: number;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'helper';
|
|
31
|
+
readonly exit: {
|
|
32
|
+
readonly code: number | null;
|
|
33
|
+
readonly signal: string | null;
|
|
34
|
+
} | null;
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: 'missing';
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'too-long';
|
|
39
|
+
readonly bytes: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* What `keychainStore`'s `tokens`, `save` and `clear` reject with when the keychain or its helper
|
|
43
|
+
* fails, and so the `cause` of a session's `store_failed` on that store. The store's own checks
|
|
44
|
+
* fail as they do for every store: tokens with no access token, or an item holding something
|
|
45
|
+
* other than tokens. The message says what happened, never with a token in it.
|
|
46
|
+
*/
|
|
47
|
+
export declare class KeychainError extends Error {
|
|
48
|
+
/** Why the step failed: switch on `failure.kind`. */
|
|
49
|
+
readonly failure: KeychainFailure;
|
|
50
|
+
constructor(message: string, failure: KeychainFailure, options?: ErrorOptions);
|
|
51
|
+
}
|
|
52
|
+
/** The kind of a refusal, from the keychain library's words. */
|
|
53
|
+
export declare function refusalKind(said: string): 'unavailable' | 'locked' | 'refused';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `keychainStore`'s `tokens`, `save` and `clear` reject with when the keychain or its helper
|
|
3
|
+
* fails, and so the `cause` of a session's `store_failed` on that store. The store's own checks
|
|
4
|
+
* fail as they do for every store: tokens with no access token, or an item holding something
|
|
5
|
+
* other than tokens. The message says what happened, never with a token in it.
|
|
6
|
+
*/
|
|
7
|
+
export class KeychainError extends Error {
|
|
8
|
+
/** Why the step failed: switch on `failure.kind`. */
|
|
9
|
+
failure;
|
|
10
|
+
constructor(message, failure, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.name = 'KeychainError';
|
|
13
|
+
this.failure = failure;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/*
|
|
17
|
+
* @napi-rs/keyring 2.1.0's words for each kind. It passes keyring-core 1.0's errors on as text,
|
|
18
|
+
* "Platform failure: …" or "Couldn't access platform storage: …", around the platform's own words.
|
|
19
|
+
* Each pattern says where its words come from: a run in a container, the library's source, or a
|
|
20
|
+
* guess still to be checked live.
|
|
21
|
+
*/
|
|
22
|
+
const UNAVAILABLE = [
|
|
23
|
+
// Run (Debian in Docker, a D-Bus session but no Secret Service): the item's constructor throws it.
|
|
24
|
+
/^Platform failure: DBus error: The name org\.freedesktop\.secrets was not provided by any \.service files/,
|
|
25
|
+
// Run (Debian in Docker, no D-Bus session at all).
|
|
26
|
+
/^Platform failure: DBus error: .*DBUS_SESSION_BUS_ADDRESS/,
|
|
27
|
+
// Source: dbus-secret-service's Error::Unavailable. Not run.
|
|
28
|
+
/^Platform failure: No DBus session or Secret Service provider found/,
|
|
29
|
+
// Guessed: macOS's errSecNotAvailable (-25291), which the library calls NoStorageAccess, in
|
|
30
|
+
// macOS's English words. Not run.
|
|
31
|
+
/^Couldn't access platform storage: No keychain is available/,
|
|
32
|
+
];
|
|
33
|
+
const LOCKED = [
|
|
34
|
+
// Source: dbus-secret-service's Error::Locked, which the library calls NoStorageAccess. Not run.
|
|
35
|
+
/^Couldn't access platform storage: Secret Service: object locked/,
|
|
36
|
+
// Guessed: macOS's errSecInteractionNotAllowed (-25308), a locked keychain with no screen to ask
|
|
37
|
+
// on, in macOS's English words. Michel's live check shows the real words.
|
|
38
|
+
/^Platform failure: User interaction is not allowed/,
|
|
39
|
+
];
|
|
40
|
+
/** The kind of a refusal, from the keychain library's words. */
|
|
41
|
+
export function refusalKind(said) {
|
|
42
|
+
if (UNAVAILABLE.some((words) => words.test(said)))
|
|
43
|
+
return 'unavailable';
|
|
44
|
+
if (LOCKED.some((words) => words.test(said)))
|
|
45
|
+
return 'locked';
|
|
46
|
+
return 'refused';
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=keychainError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychainError.js","sourceRoot":"","sources":["../../src/node/keychainError.ts"],"names":[],"mappings":"AA4BA;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,qDAAqD;IAC5C,OAAO,CAAiB;IAEjC,YAAY,OAAe,EAAE,OAAwB,EAAE,OAAsB;QAC3E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,WAAW,GAAsB;IACrC,mGAAmG;IACnG,2GAA2G;IAC3G,mDAAmD;IACnD,2DAA2D;IAC3D,6DAA6D;IAC7D,qEAAqE;IACrE,4FAA4F;IAC5F,kCAAkC;IAClC,6DAA6D;CAC9D,CAAA;AAED,MAAM,MAAM,GAAsB;IAChC,iGAAiG;IACjG,kEAAkE;IAClE,iGAAiG;IACjG,0EAA0E;IAC1E,oDAAoD;CACrD,CAAA;AAED,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,aAAa,CAAA;IACvE,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAA;IAC7D,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -5,10 +5,10 @@ export interface KeychainStoreOptions {
|
|
|
5
5
|
/** The item's account, such as the issuer the tokens are for. */
|
|
6
6
|
readonly account: string;
|
|
7
7
|
/**
|
|
8
|
-
* How long one step may take before it is ended, as `
|
|
8
|
+
* How long one step may take before it is ended, as a `timeout`: 30 s unless you say. A
|
|
9
9
|
* keychain prompt that a person must answer may need longer. Through `session.token()`, a read
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* is also held to the caller's wait, `createSession`'s `waitMs` (15 s by default), past which it
|
|
11
|
+
* is `unavailable`: give that as long too. This limit is each step's own, whatever the caller's.
|
|
12
12
|
*/
|
|
13
13
|
readonly timeoutMs?: number;
|
|
14
14
|
}
|
|
@@ -18,13 +18,24 @@ export interface KeychainStoreOptions {
|
|
|
18
18
|
* KWallet). One item (`service`, `account`) holds them; a save is one write, seen whole once it has
|
|
19
19
|
* succeeded, or not at all.
|
|
20
20
|
*
|
|
21
|
+
* - **Every failure of the keychain or its helper is a `KeychainError`,** whose `failure.kind` says
|
|
22
|
+
* why: the cause of a session's `store_failed`. The store's own two are not: tokens with no access
|
|
23
|
+
* token (a `TypeError`, before any step) and an item holding something other than tokens.
|
|
21
24
|
* - **It needs `@napi-rs/keyring`** (`npm install @napi-rs/keyring`), which nothing else in the
|
|
22
|
-
* SDK uses. Without it, every step fails as `
|
|
23
|
-
* - **Linux without a Secret Service** (a server, a container) fails as `
|
|
25
|
+
* SDK uses. Without it, every step fails as `missing`, and says so.
|
|
26
|
+
* - **Linux without a Secret Service** (a server, a container) fails as `unavailable`: use
|
|
24
27
|
* `fileStore` there.
|
|
25
|
-
* - **
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* - **Its steps run in one helper process,** one at a time: started by the first step and kept
|
|
29
|
+
* warm while the app runs, for every keychain store of the process. A step past its `timeoutMs`
|
|
30
|
+
* (30 s) kills it, and the next step starts another. It ignores a terminal Ctrl-C. A step whose
|
|
31
|
+
* helper died before it answered runs once more on a fresh one, within its `timeoutMs`. It never
|
|
32
|
+
* keeps the app running. When the app ends, it ends too: at once when idle or on a read, or once
|
|
33
|
+
* the save or delete it's on is done, within that step's `timeoutMs` and 1 s at most, so a
|
|
34
|
+
* refresh's save isn't lost to a Ctrl-C. 1 s is less than the soonest `fileLock` lets another
|
|
35
|
+
* process take the app's lock. For a helper's first step, the 1 s counts from the helper's own
|
|
36
|
+
* start, so a slow start can't stretch it, and that step may be cut sooner. It is `process.execPath`, so it needs a Node that runs a script: not an Electron
|
|
37
|
+
* app (without `ELECTRON_RUN_AS_NODE`), a Node single-executable application, or a compiled Bun
|
|
38
|
+
* binary.
|
|
39
|
+
* - **Tokens over 2,560 bytes** fail the save as `too-long`, with nothing written.
|
|
29
40
|
*/
|
|
30
41
|
export declare function keychainStore(options: KeychainStoreOptions): TokenStore;
|