@flipstream/sdk 0.8.0 → 0.10.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 +92 -0
- package/README.md +707 -66
- package/dist/api/backend.d.ts +182 -0
- package/dist/api/backend.js +314 -0
- package/dist/api/backend.js.map +1 -0
- package/dist/api/created.d.ts +5 -0
- package/dist/api/created.js +15 -0
- package/dist/api/created.js.map +1 -0
- package/dist/api/credentials.d.ts +36 -0
- package/dist/api/credentials.js +94 -0
- package/dist/api/credentials.js.map +1 -0
- package/dist/api/datasets.d.ts +94 -0
- package/dist/api/datasets.js +212 -0
- package/dist/api/datasets.js.map +1 -0
- package/dist/api/handoff.d.ts +34 -0
- package/dist/api/handoff.js +52 -0
- package/dist/api/handoff.js.map +1 -0
- package/dist/api/ids.d.ts +7 -0
- package/dist/api/ids.js +27 -0
- package/dist/api/ids.js.map +1 -0
- package/dist/api/index.d.ts +9 -1
- package/dist/api/log.d.ts +95 -0
- package/dist/api/log.js +213 -0
- package/dist/api/log.js.map +1 -0
- package/dist/api/me.d.ts +58 -0
- package/dist/api/me.js +64 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/members.d.ts +48 -0
- package/dist/api/members.js +102 -0
- package/dist/api/members.js.map +1 -0
- package/dist/api/organization.d.ts +11 -0
- package/dist/api/organization.js +15 -0
- package/dist/api/organization.js.map +1 -0
- package/dist/api/page.d.ts +33 -0
- package/dist/api/page.js +38 -0
- package/dist/api/page.js.map +1 -0
- package/dist/api/time.d.ts +3 -0
- package/dist/api/time.js +49 -0
- package/dist/api/time.js.map +1 -0
- package/dist/api/unsent.d.ts +6 -0
- package/dist/api/unsent.js +9 -0
- package/dist/api/unsent.js.map +1 -0
- package/dist/api/wallet.d.ts +45 -0
- package/dist/api/wallet.js +102 -0
- package/dist/api/wallet.js.map +1 -0
- package/dist/api/workspaces.d.ts +70 -0
- package/dist/api/workspaces.js +108 -0
- package/dist/api/workspaces.js.map +1 -0
- package/dist/auth/discovery.js +1 -1
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.js +7 -2
- package/dist/auth/signIn.js.map +1 -1
- package/dist/core/body.js +23 -5
- package/dist/core/body.js.map +1 -1
- package/dist/core/call.d.ts +6 -0
- package/dist/core/call.js +1 -1
- package/dist/core/call.js.map +1 -1
- package/dist/core/fetch.d.ts +5 -0
- package/dist/core/fetch.js +7 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/identify.d.ts +63 -0
- package/dist/core/identify.js +122 -0
- package/dist/core/identify.js.map +1 -0
- package/dist/core/names.d.ts +100 -0
- package/dist/core/names.js +114 -0
- package/dist/core/names.js.map +1 -0
- package/dist/core/read.d.ts +1 -1
- package/dist/core/read.js +15 -6
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +67 -6
- package/dist/core/result.js +39 -6
- package/dist/core/result.js.map +1 -1
- package/dist/core/secrets.d.ts +2 -0
- package/dist/core/secrets.js +33 -0
- package/dist/core/secrets.js.map +1 -0
- package/dist/core/transport.d.ts +12 -4
- package/dist/flipstream.d.ts +341 -5
- package/dist/flipstream.js +203 -13
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node/clientSecret.js +2 -1
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +10 -6
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainStore.d.ts +6 -3
- package/dist/node/keychainStore.js +6 -3
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/session.d.ts +78 -29
- package/dist/node/session.js +74 -52
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +11 -1
- package/dist/node/store.js +14 -1
- package/dist/node/store.js.map +1 -1
- package/dist/query/query.d.ts +15 -10
- package/dist/query/query.js +21 -11
- package/dist/query/query.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/dist/version.gen.js.map +1 -1
- package/package.json +2 -2
package/dist/core/read.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { parseJson, said } from './body.js';
|
|
3
3
|
import { classifyStatus } from './result.js';
|
|
4
|
+
// The reasons a transport may give, tied to its type: a reason TransportResult gains fails to
|
|
5
|
+
// compile here until it's mapped. Checked as an own key, because an app's own transport may be
|
|
6
|
+
// plain JavaScript and give any (#199).
|
|
7
|
+
const FROM_TRANSPORT = { destination: true, identification: true };
|
|
4
8
|
/** Why a transport has no answer to read. */
|
|
5
9
|
export function noAnswer(sent) {
|
|
6
10
|
switch (sent.kind) {
|
|
7
|
-
case 'refused':
|
|
8
|
-
|
|
11
|
+
case 'refused': {
|
|
12
|
+
const { reason } = sent;
|
|
13
|
+
return Object.hasOwn(FROM_TRANSPORT, reason) ? { kind: 'refused', reason } : { kind: 'refused' };
|
|
14
|
+
}
|
|
9
15
|
case 'unavailable':
|
|
10
16
|
return { kind: 'unavailable' };
|
|
11
17
|
case 'cancelled':
|
|
@@ -27,7 +33,7 @@ export function noAnswer(sent) {
|
|
|
27
33
|
* not JSON, or fails its schema, is `invalid`: reported, never shown as empty. Zod's issues name
|
|
28
34
|
* paths and expected types, never the body's values.
|
|
29
35
|
*/
|
|
30
|
-
export async function readJson(sent, schema, signal, service) {
|
|
36
|
+
export async function readJson(sent, schema, signal, service, keepsNoText = false) {
|
|
31
37
|
if (sent.kind !== 'response')
|
|
32
38
|
return failed(noAnswer(sent));
|
|
33
39
|
const { response } = sent;
|
|
@@ -40,11 +46,14 @@ export async function readJson(sent, schema, signal, service) {
|
|
|
40
46
|
const body = await readText(response, signal);
|
|
41
47
|
if (!body.ok)
|
|
42
48
|
return failed(body.error);
|
|
43
|
-
if (meaning !== 'success')
|
|
44
|
-
|
|
49
|
+
if (meaning !== 'success') {
|
|
50
|
+
const told = said(body.text, service);
|
|
51
|
+
// A body that isn't the host's own error is its text: never kept when it may hold a secret.
|
|
52
|
+
return failed(keepsNoText && told.text !== undefined ? { kind: meaning, status } : { kind: meaning, status, ...told });
|
|
53
|
+
}
|
|
45
54
|
const json = parseJson(body.text);
|
|
46
55
|
if (!json.ok)
|
|
47
|
-
return failed({ kind: 'invalid', issues: 'the body is not JSON', status, text: body.text });
|
|
56
|
+
return failed(keepsNoText ? { kind: 'invalid', issues: 'the body is not JSON', status } : { kind: 'invalid', issues: 'the body is not JSON', status, text: body.text });
|
|
48
57
|
const parsed = schema.safeParse(json.value);
|
|
49
58
|
if (!parsed.success)
|
|
50
59
|
return failed({ kind: 'invalid', issues: z.prettifyError(parsed.error), status });
|
package/dist/core/read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAiC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAiC,MAAM,aAAa,CAAA;AAM3E,8FAA8F;AAC9F,+FAA+F;AAC/F,wCAAwC;AACxC,MAAM,cAAc,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAoD,CAAA;AAEpH,6CAA6C;AAC7C,MAAM,UAAU,QAAQ,CAAC,IAAc;IACrC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,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KAAK,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACvD,CAAC;QACD,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAA;QACxB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,CAAA;IACjF,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,KAAe,EAAoD,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
package/dist/core/result.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { PlannerErrorCode } from '../spec/query-planner/types.gen.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* What every call returns: its data, or one failure with one meaning (D412). `traceId` is the W3C
|
|
4
|
+
* trace-id the call's requests carried (#251), so a person can find them in Logs: there when a
|
|
5
|
+
* request carrying it went out, on either arm, and absent when nothing was sent.
|
|
6
|
+
*/
|
|
3
7
|
export type ApiResult<T> = {
|
|
4
8
|
readonly ok: true;
|
|
5
9
|
readonly data: T;
|
|
10
|
+
readonly traceId?: string;
|
|
6
11
|
} | {
|
|
7
12
|
readonly ok: false;
|
|
8
13
|
readonly error: ApiError;
|
|
14
|
+
readonly traceId?: string;
|
|
9
15
|
};
|
|
10
16
|
/** The failures a status gives: the host answered, and said no. */
|
|
11
17
|
export type StatusKind = 'unauthorized' | 'forbidden' | 'not_found' | 'conflict' | 'rejected' | 'unavailable';
|
|
@@ -19,6 +25,8 @@ export type ErrorCode = PlannerErrorCode | (string & Record<never, never>);
|
|
|
19
25
|
/**
|
|
20
26
|
* What came with a failure status: the host's error, read from its body (today the planner's
|
|
21
27
|
* `{ code, message }`, D429), or the body as it came, when it is not one (a proxy's `Bad gateway`).
|
|
28
|
+
* Neither, when the call's answer may hold a secret's value (a sign-in's, #70): then a body that
|
|
29
|
+
* isn't the host's error is never kept, and the kind and status are all there is (#278).
|
|
22
30
|
*/
|
|
23
31
|
export type Said = {
|
|
24
32
|
readonly code: ErrorCode;
|
|
@@ -31,6 +39,11 @@ export type Said = {
|
|
|
31
39
|
readonly code?: never;
|
|
32
40
|
readonly message?: never;
|
|
33
41
|
readonly requestId?: never;
|
|
42
|
+
} | {
|
|
43
|
+
readonly text?: never;
|
|
44
|
+
readonly code?: never;
|
|
45
|
+
readonly message?: never;
|
|
46
|
+
readonly requestId?: never;
|
|
34
47
|
};
|
|
35
48
|
/** A failure the host answered with a status, and what came with it. */
|
|
36
49
|
export type Answered = {
|
|
@@ -68,29 +81,77 @@ export type ApiError = Answered
|
|
|
68
81
|
readonly kind: 'timeout';
|
|
69
82
|
}
|
|
70
83
|
/**
|
|
71
|
-
* Nothing was sent, by rule
|
|
72
|
-
*
|
|
73
|
-
*
|
|
84
|
+
* Nothing was sent, by rule, and `reason` says which (#199). Every refusal the SDK returns has
|
|
85
|
+
* one; only an error an app builds itself may leave it out. No token was asked for, and none went
|
|
86
|
+
* anywhere, but for `identification`: the token was asked for, to check, and went nowhere.
|
|
74
87
|
*/
|
|
75
88
|
| {
|
|
76
89
|
readonly kind: 'refused';
|
|
90
|
+
readonly reason?: RefusedReason;
|
|
77
91
|
readonly fields?: readonly [string, ...string[]];
|
|
78
92
|
}
|
|
79
93
|
/** The token function failed, or gave no token, so nothing was sent; `cause` is what it threw. */
|
|
80
94
|
| {
|
|
81
95
|
readonly kind: 'no_token';
|
|
82
96
|
readonly cause: unknown;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The call is a person's to do, in the console, and the SDK doesn't do it (D542): a rename, or a
|
|
100
|
+
* delete a person confirms. It never writes, so `ok` is false and nothing was changed.
|
|
101
|
+
*/
|
|
102
|
+
| {
|
|
103
|
+
readonly kind: 'needs_person';
|
|
104
|
+
readonly action: HandOffAction;
|
|
105
|
+
/** Why a person does it, in plain words, for an agent to pass on. The SDK's own text, never a value the caller gave. */
|
|
106
|
+
readonly why: string;
|
|
107
|
+
/** Where the person does it: the console's page, when one can be named. */
|
|
108
|
+
readonly url?: string;
|
|
109
|
+
/** What the person will see there. Present when `url` is. */
|
|
110
|
+
readonly sees?: string;
|
|
83
111
|
};
|
|
112
|
+
/** What a hand-off asks a person to do (D542, D546). */
|
|
113
|
+
export type HandOffAction = 'workspace.rename' | 'workspace.delete' | 'dataset.delete' | 'member.remove' | 'organization.rename' | 'credential.revoke' | 'credential.delete';
|
|
84
114
|
/**
|
|
85
115
|
* What an HTTP status means (the console's table, D412). Only 2xx is a success. A status no host
|
|
86
116
|
* should send (1xx, 3xx, 0 from an opaque redirect, or not a whole number) is outside the
|
|
87
117
|
* contract, so it is reported, never quietly passed.
|
|
88
118
|
*/
|
|
89
119
|
export declare function classifyStatus(status: number): 'success' | StatusKind | 'outside-contract';
|
|
90
|
-
/**
|
|
120
|
+
/** Why a call was refused before anything was sent (#199, D536). */
|
|
121
|
+
export type RefusedReason =
|
|
122
|
+
/**
|
|
123
|
+
* Not an allowed host: a configured one, or for sign-in the issuer's own, over https, or over
|
|
124
|
+
* http on this machine with `allowLocalhostHttp`, for the client as for sign-in.
|
|
125
|
+
*/
|
|
126
|
+
'destination'
|
|
127
|
+
/** A value identifying the app, its agent or the conversation holds the access token (#192). */
|
|
128
|
+
| 'identification'
|
|
129
|
+
/** A path value that can't stay one segment: '', '.' or '..'. */
|
|
130
|
+
| 'path'
|
|
131
|
+
/** A call's own `conversationId` that breaks its rule. */
|
|
132
|
+
| 'conversation-id'
|
|
133
|
+
/** The request has keys the call doesn't send, named in `fields` (D513). */
|
|
134
|
+
| 'fields'
|
|
135
|
+
/**
|
|
136
|
+
* Sign-in: a pending sign-in that isn't one, wasn't started by this app at this server, or whose
|
|
137
|
+
* token endpoint breaks its issuer's rule (an app's own server can give it one).
|
|
138
|
+
*/
|
|
139
|
+
| 'pending'
|
|
140
|
+
/** Sign-in: a callback URL that can't be read. */
|
|
141
|
+
| 'callback';
|
|
142
|
+
/**
|
|
143
|
+
* A failed call, thrown by `orThrow`, carrying its `ApiError`. When the call's requests went out
|
|
144
|
+
* under a trace (#251), it carries that `traceId` too (#262), and its message ends with
|
|
145
|
+
* `(request <traceId>)`, so whoever catches or prints it can find them in Logs.
|
|
146
|
+
*/
|
|
91
147
|
export declare class ApiFailure extends Error {
|
|
92
148
|
readonly error: ApiError;
|
|
93
|
-
|
|
149
|
+
/**
|
|
150
|
+
* The call's W3C trace-id, when its requests went out under one; absent otherwise. Declared, not
|
|
151
|
+
* defined, so a class field doesn't make it an own property holding `undefined`.
|
|
152
|
+
*/
|
|
153
|
+
readonly traceId?: string;
|
|
154
|
+
constructor(error: ApiError, traceId?: string);
|
|
94
155
|
}
|
|
95
156
|
/** The data, or the failure thrown as `ApiFailure`, for callers who want exceptions (D412). */
|
|
96
157
|
export declare function orThrow<T>(result: ApiResult<T>): T;
|
package/dist/core/result.js
CHANGED
|
@@ -22,21 +22,54 @@ export function classifyStatus(status) {
|
|
|
22
22
|
return 'rejected';
|
|
23
23
|
return 'outside-contract';
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
// What orThrow's message says of each reason. A message names the rule, never a value: not the
|
|
26
|
+
// token, a conversationId or a URL, which may be secrets in the wrong place.
|
|
27
|
+
const REFUSED_BECAUSE = {
|
|
28
|
+
destination: "its destination isn't an allowed host (https, or http on this machine with allowLocalhostHttp)",
|
|
29
|
+
identification: 'a value identifying the app, its agent or the conversation holds the access token',
|
|
30
|
+
path: "a path value can't be '', '.' or '..'",
|
|
31
|
+
'conversation-id': "the call's conversationId isn't 1 to 128 of A-Z, a-z, 0-9, ., _, : and -",
|
|
32
|
+
pending: "the pending sign-in isn't one this app started at this server, or its token endpoint breaks its issuer's rule",
|
|
33
|
+
callback: "the callback URL can't be read",
|
|
34
|
+
};
|
|
35
|
+
function failureMessage(error) {
|
|
36
|
+
// `why` is the SDK's own text, never a value the caller gave, so it's safe to say.
|
|
37
|
+
if (error.kind === 'needs_person')
|
|
38
|
+
return `the call needs a person: ${error.why}`;
|
|
39
|
+
if (error.kind !== 'refused')
|
|
40
|
+
return `the call failed: ${error.kind}`;
|
|
41
|
+
if (error.fields !== undefined)
|
|
42
|
+
return `the call failed: refused, for fields it doesn't send: ${error.fields.join(', ')}`;
|
|
43
|
+
// An own key only: a reason outside the type, from plain JavaScript or another version, says
|
|
44
|
+
// nothing more than "refused", never "as undefined".
|
|
45
|
+
const { reason } = error;
|
|
46
|
+
const because = reason !== undefined && reason !== 'fields' && Object.hasOwn(REFUSED_BECAUSE, reason) ? REFUSED_BECAUSE[reason] : undefined;
|
|
47
|
+
return because === undefined ? 'the call failed: refused' : `the call failed: refused, as ${because}`;
|
|
48
|
+
}
|
|
49
|
+
// A W3C trace-id: only one of these is said in a message, never another value an app's own result holds.
|
|
50
|
+
const TRACE_ID = /^[0-9a-f]{32}$/;
|
|
51
|
+
/**
|
|
52
|
+
* A failed call, thrown by `orThrow`, carrying its `ApiError`. When the call's requests went out
|
|
53
|
+
* under a trace (#251), it carries that `traceId` too (#262), and its message ends with
|
|
54
|
+
* `(request <traceId>)`, so whoever catches or prints it can find them in Logs.
|
|
55
|
+
*/
|
|
26
56
|
export class ApiFailure extends Error {
|
|
27
57
|
error;
|
|
28
|
-
constructor(error) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
constructor(error, traceId) {
|
|
59
|
+
// A string first: RegExp's test turns a String object or [id] into text, and that would pass.
|
|
60
|
+
const traced = typeof traceId === 'string' && TRACE_ID.test(traceId) ? traceId : undefined;
|
|
61
|
+
super(traced === undefined ? failureMessage(error) : `${failureMessage(error)} (request ${traced})`);
|
|
32
62
|
this.name = 'ApiFailure';
|
|
33
63
|
this.error = error;
|
|
64
|
+
// Only a trace-id, and only when there is one, so `'traceId' in failure` means one went out.
|
|
65
|
+
if (traced !== undefined)
|
|
66
|
+
this.traceId = traced;
|
|
34
67
|
}
|
|
35
68
|
}
|
|
36
69
|
/** The data, or the failure thrown as `ApiFailure`, for callers who want exceptions (D412). */
|
|
37
70
|
export function orThrow(result) {
|
|
38
71
|
if (!result.ok)
|
|
39
|
-
throw new ApiFailure(result.error);
|
|
72
|
+
throw new ApiFailure(result.error, result.traceId);
|
|
40
73
|
return result.data;
|
|
41
74
|
}
|
|
42
75
|
//# sourceMappingURL=result.js.map
|
package/dist/core/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAoHA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,kBAAkB,CAAA;IACxD,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,SAAS,CAAA;IACpD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,cAAc,CAAA;IACzC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,UAAU,CAAA;IACvD,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;QAAE,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AAU;IAOxB,YAAY,KAAe,EAAE,OAAgB;QAC3C,8FAA8F;QAC9F,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;QAC1F,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,aAAa,MAAM,GAAG,CAAC,CAAA;QACpG,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,6FAA6F;QAC7F,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACjD,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAI,MAAoB;IAC7C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IAClE,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The keys that may hold a credential's value, wherever they sit in an answer (#70): one list, read
|
|
3
|
+
* by the SDK's sign-in check, which fails closed on them, and by the live scripts' redaction
|
|
4
|
+
* (scripts/live/redact.mjs reads it from the build), so the two can't drift. A key counts however
|
|
5
|
+
* it's spelt: in any case, with or without `_` or `-`, so `refreshToken`, `access-token` and
|
|
6
|
+
* `apiKey` count too (#278 round 1). A dataset's export to S3 holds one too (`data_export.s3_credentials`,
|
|
7
|
+
* with its `secret_access_key`, #240).
|
|
8
|
+
*/
|
|
9
|
+
const SECRET_KEYS = [
|
|
10
|
+
'value',
|
|
11
|
+
'secret',
|
|
12
|
+
'secret_text',
|
|
13
|
+
'secret_file',
|
|
14
|
+
'secret_key',
|
|
15
|
+
'token',
|
|
16
|
+
'access_token',
|
|
17
|
+
'refresh_token',
|
|
18
|
+
'client_secret',
|
|
19
|
+
'password',
|
|
20
|
+
'private_key',
|
|
21
|
+
'credentials',
|
|
22
|
+
'api_key',
|
|
23
|
+
'auth_values',
|
|
24
|
+
's3_credentials',
|
|
25
|
+
'secret_access_key',
|
|
26
|
+
];
|
|
27
|
+
const spelling = (key) => key.toLowerCase().replace(/[_-]/g, '');
|
|
28
|
+
const SPELLINGS = new Set(SECRET_KEYS.map(spelling));
|
|
29
|
+
/** Whether `key` may hold a credential's value, however it's spelt. */
|
|
30
|
+
export function isSecretKey(key) {
|
|
31
|
+
return SPELLINGS.has(spelling(key));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/core/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,GAAG;IAClB,OAAO;IACP,QAAQ;IACR,aAAa;IACb,aAAa;IACb,YAAY;IACZ,OAAO;IACP,cAAc;IACd,eAAe;IACf,eAAe;IACf,UAAU;IACV,aAAa;IACb,aAAa;IACb,SAAS;IACT,aAAa;IACb,gBAAgB;IAChB,mBAAmB;CACX,CAAA;AAEV,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AAChF,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEzE,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AACrC,CAAC"}
|
package/dist/core/transport.d.ts
CHANGED
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
* the token and answers. Nothing above it ever sees a token, and it never reads a body: reading
|
|
6
6
|
* happens in `readJson`, under the call's signal (D409).
|
|
7
7
|
*/
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The hosts the SDK calls, by what they are, never by URL: the planner, the auth server, and today's
|
|
10
|
+
* admin and wallet APIs behind #67's seam (D541). `api` is reserved for the public API
|
|
11
|
+
* (pulse-admin#91), which the seam moves onto once it exists.
|
|
12
|
+
*/
|
|
13
|
+
export type ServiceName = 'query' | 'api' | 'auth' | 'admin' | 'wallet';
|
|
10
14
|
/** Every call says what it does. Required fields, so no endpoint can leave one out. */
|
|
11
15
|
export interface ApiRequest {
|
|
12
16
|
/**
|
|
@@ -30,10 +34,14 @@ export type Transport = (call: ApiRequest) => Promise<TransportResult>;
|
|
|
30
34
|
*/
|
|
31
35
|
export type CancelReason = 'principal-changed' | 'scope-changed' | 'aborted';
|
|
32
36
|
export type TransportResult =
|
|
33
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Nothing was sent. `destination`: outside the allowlist, so no token went anywhere.
|
|
39
|
+
* `identification`: a value that identifies the app, its agent or the conversation holds the
|
|
40
|
+
* access token, which goes in the authorization header only (#192).
|
|
41
|
+
*/
|
|
34
42
|
{
|
|
35
43
|
readonly kind: 'refused';
|
|
36
|
-
readonly reason: 'destination';
|
|
44
|
+
readonly reason: 'destination' | 'identification';
|
|
37
45
|
} | {
|
|
38
46
|
readonly kind: 'response';
|
|
39
47
|
readonly response: Response;
|