@sentinelconnector/cli 0.0.0-stage → 0.1.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/LICENSE +11 -0
- package/README.md +218 -2
- package/dist/api/client.d.ts +63 -0
- package/dist/api/client.js +115 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/config.d.ts +21 -0
- package/dist/api/config.js +62 -0
- package/dist/api/config.js.map +1 -0
- package/dist/api/errors.d.ts +34 -0
- package/dist/api/errors.js +92 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/http.d.ts +24 -0
- package/dist/api/http.js +60 -0
- package/dist/api/http.js.map +1 -0
- package/dist/auth/credentials.d.ts +48 -0
- package/dist/auth/credentials.js +144 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/deviceFlow.d.ts +52 -0
- package/dist/auth/deviceFlow.js +106 -0
- package/dist/auth/deviceFlow.js.map +1 -0
- package/dist/auth/lock.d.ts +2 -0
- package/dist/auth/lock.js +86 -0
- package/dist/auth/lock.js.map +1 -0
- package/dist/auth/store.d.ts +87 -0
- package/dist/auth/store.js +281 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +8 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +111 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/mergeChecks.d.ts +9 -0
- package/dist/commands/mergeChecks.js +57 -0
- package/dist/commands/mergeChecks.js.map +1 -0
- package/dist/commands/routes.d.ts +21 -0
- package/dist/commands/routes.js +306 -0
- package/dist/commands/routes.js.map +1 -0
- package/dist/commands/session.d.ts +44 -0
- package/dist/commands/session.js +137 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/context.d.ts +31 -0
- package/dist/context.js +42 -0
- package/dist/context.js.map +1 -0
- package/dist/journeys/mergeChecks.d.ts +70 -0
- package/dist/journeys/mergeChecks.js +127 -0
- package/dist/journeys/mergeChecks.js.map +1 -0
- package/dist/mcp/main.d.ts +13 -0
- package/dist/mcp/main.js +39 -0
- package/dist/mcp/main.js.map +1 -0
- package/dist/mcp/server.d.ts +181 -0
- package/dist/mcp/server.js +282 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/untrusted.d.ts +38 -0
- package/dist/mcp/untrusted.js +125 -0
- package/dist/mcp/untrusted.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +7 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mfa.d.ts +12 -0
- package/dist/mfa.js +29 -0
- package/dist/mfa.js.map +1 -0
- package/dist/prompt.d.ts +4 -0
- package/dist/prompt.js +54 -0
- package/dist/prompt.js.map +1 -0
- package/dist/routes/call.d.ts +26 -0
- package/dist/routes/call.js +120 -0
- package/dist/routes/call.js.map +1 -0
- package/dist/routes/catalogue.d.ts +47 -0
- package/dist/routes/catalogue.js +69 -0
- package/dist/routes/catalogue.js.map +1 -0
- package/dist/routes/routes.json +11367 -0
- package/dist/skill.d.ts +13 -0
- package/dist/skill.js +61 -0
- package/dist/skill.js.map +1 -0
- package/package.json +40 -4
- package/skills/sentinel/SKILL.md +150 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** JSON over fetch with a timeout; the one place requests leave the process. */
|
|
2
|
+
import { SentinelError } from './errors.js';
|
|
3
|
+
export declare const CLIENT_HEADER = "X-Sentinel-Client";
|
|
4
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
5
|
+
export type Fetch = (input: Request) => Promise<Response>;
|
|
6
|
+
export interface HttpOptions {
|
|
7
|
+
fetch?: Fetch;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when the request never got an answer; safe to retry idempotent work. */
|
|
11
|
+
export declare class NetworkError extends SentinelError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Send one request. Redirects are refused: a 307 would re-post a body
|
|
16
|
+
* holding a refresh token or device code to wherever it points. The
|
|
17
|
+
* caller's abort signal is kept alongside the timeout.
|
|
18
|
+
*/
|
|
19
|
+
export declare function send(request: Request, options?: HttpOptions): Promise<Response>;
|
|
20
|
+
/** POST a JSON body and return the parsed answer, or throw the API's error. */
|
|
21
|
+
export declare function postJson<T>(url: string, body: unknown, options?: HttpOptions & {
|
|
22
|
+
client?: string;
|
|
23
|
+
}): Promise<T>;
|
|
24
|
+
export declare function getJson<T>(url: string, options?: HttpOptions): Promise<T>;
|
package/dist/api/http.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** JSON over fetch with a timeout; the one place requests leave the process. */
|
|
2
|
+
import { errorFromResponse, SentinelError } from './errors.js';
|
|
3
|
+
export const CLIENT_HEADER = 'X-Sentinel-Client';
|
|
4
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
5
|
+
/** Thrown when the request never got an answer; safe to retry idempotent work. */
|
|
6
|
+
export class NetworkError extends SentinelError {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message, 3);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Send one request. Redirects are refused: a 307 would re-post a body
|
|
13
|
+
* holding a refresh token or device code to wherever it points. The
|
|
14
|
+
* caller's abort signal is kept alongside the timeout.
|
|
15
|
+
*/
|
|
16
|
+
export async function send(request, options = {}) {
|
|
17
|
+
const fetcher = options.fetch ?? ((input) => fetch(input));
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
const timer = setTimeout(() => controller.abort(new DOMException('timed out', 'TimeoutError')), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
20
|
+
const forward = () => controller.abort(request.signal.reason);
|
|
21
|
+
if (request.signal.aborted)
|
|
22
|
+
forward();
|
|
23
|
+
else
|
|
24
|
+
request.signal.addEventListener('abort', forward, { once: true });
|
|
25
|
+
try {
|
|
26
|
+
return await fetcher(new Request(request, { signal: controller.signal, redirect: 'error' }));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
if (request.signal.aborted)
|
|
30
|
+
throw new SentinelError('Cancelled.', 130);
|
|
31
|
+
const timedOut = controller.signal.aborted;
|
|
32
|
+
throw new NetworkError(`Request to ${new URL(request.url).origin} ${timedOut ? 'timed out' : 'failed'}.`);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
request.signal.removeEventListener('abort', forward);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** POST a JSON body and return the parsed answer, or throw the API's error. */
|
|
40
|
+
export async function postJson(url, body, options = {}) {
|
|
41
|
+
const response = await send(new Request(url, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
Accept: 'application/json',
|
|
46
|
+
[CLIENT_HEADER]: options.client ?? 'cli',
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(body),
|
|
49
|
+
}), options);
|
|
50
|
+
if (!response.ok)
|
|
51
|
+
throw await errorFromResponse(response);
|
|
52
|
+
return (await response.json());
|
|
53
|
+
}
|
|
54
|
+
export async function getJson(url, options = {}) {
|
|
55
|
+
const response = await send(new Request(url, { headers: { Accept: 'application/json' } }), options);
|
|
56
|
+
if (!response.ok)
|
|
57
|
+
throw await errorFromResponse(response);
|
|
58
|
+
return (await response.json());
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AASzC,kFAAkF;AAClF,MAAM,OAAO,YAAa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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { HttpOptions } from '../api/http.js';
|
|
2
|
+
import { type TokenSet } from './deviceFlow.js';
|
|
3
|
+
import type { CredentialStore, StoredSession } from './store.js';
|
|
4
|
+
export declare const PERSONAL_TOKEN_SHAPE: RegExp;
|
|
5
|
+
export interface Credential {
|
|
6
|
+
readonly kind: 'personal_token' | 'cli_session';
|
|
7
|
+
/** The environment the credential was made for, when the client knows it. */
|
|
8
|
+
readonly environment: string | undefined;
|
|
9
|
+
/** The dashboard origin learned at sign-in, if any. */
|
|
10
|
+
readonly dashboardUrl: string | undefined;
|
|
11
|
+
/** A bearer value for the next request. */
|
|
12
|
+
accessToken(): Promise<string>;
|
|
13
|
+
/** After a 401: renew once if this credential can, and say whether it did. */
|
|
14
|
+
renew(): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export declare function sessionFromTokens(apiUrl: string, tokens: TokenSet, now?: number): StoredSession;
|
|
17
|
+
export declare class EnvTokenCredential implements Credential {
|
|
18
|
+
private readonly token;
|
|
19
|
+
readonly kind: "personal_token";
|
|
20
|
+
readonly environment: undefined;
|
|
21
|
+
readonly dashboardUrl: undefined;
|
|
22
|
+
constructor(token: string);
|
|
23
|
+
accessToken(): Promise<string>;
|
|
24
|
+
renew(): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
export declare class SessionCredential implements Credential {
|
|
27
|
+
private session;
|
|
28
|
+
private readonly store;
|
|
29
|
+
private readonly options;
|
|
30
|
+
readonly kind: "cli_session";
|
|
31
|
+
constructor(session: StoredSession, store: CredentialStore, options?: HttpOptions & {
|
|
32
|
+
lockDir?: string;
|
|
33
|
+
now?: () => number;
|
|
34
|
+
});
|
|
35
|
+
get environment(): string;
|
|
36
|
+
get dashboardUrl(): string | undefined;
|
|
37
|
+
get current(): StoredSession;
|
|
38
|
+
private now;
|
|
39
|
+
accessToken(): Promise<string>;
|
|
40
|
+
renew(): Promise<boolean>;
|
|
41
|
+
private refresh;
|
|
42
|
+
}
|
|
43
|
+
/** Hold the per-session lock that refresh, login and logout share. */
|
|
44
|
+
export declare function withSessionLock<T>(apiUrl: string, lockDir: string | undefined, task: () => Promise<T>): Promise<T>;
|
|
45
|
+
/** The credential for this API URL, or NotSignedInError. */
|
|
46
|
+
export declare function resolveCredential(apiUrl: string, store: () => Promise<CredentialStore>, env?: NodeJS.ProcessEnv, options?: HttpOptions & {
|
|
47
|
+
lockDir?: string;
|
|
48
|
+
}): Promise<Credential>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which credential a call uses. SENTINEL_TOKEN (a personal API token,
|
|
3
|
+
* `snt_pat_…`) wins when set and needs no stored state. Otherwise the sign-in
|
|
4
|
+
* stored for this API URL by `sentinel login`, its access token renewed with
|
|
5
|
+
* the refresh token when it is about to expire.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { configDir, TOKEN_ENV } from '../api/config.js';
|
|
9
|
+
import { NotSignedInError, SentinelError } from '../api/errors.js';
|
|
10
|
+
import { GrantError, isTransient, requestToken } from './deviceFlow.js';
|
|
11
|
+
import { withLock } from './lock.js';
|
|
12
|
+
/** Renew this long before the access token expires. */
|
|
13
|
+
const EARLY_MS = 60_000;
|
|
14
|
+
export const PERSONAL_TOKEN_SHAPE = /^snt_pat_[0-9A-Za-z]{46}$/;
|
|
15
|
+
export function sessionFromTokens(apiUrl, tokens, now = Date.now()) {
|
|
16
|
+
return {
|
|
17
|
+
version: 1,
|
|
18
|
+
apiUrl,
|
|
19
|
+
environment: tokens.environment,
|
|
20
|
+
sessionId: tokens.session_id,
|
|
21
|
+
scope: tokens.scope,
|
|
22
|
+
accessToken: tokens.access_token,
|
|
23
|
+
accessExpiresAt: new Date(now + tokens.expires_in * 1000).toISOString(),
|
|
24
|
+
refreshToken: tokens.refresh_token,
|
|
25
|
+
sessionExpiresAt: new Date(now + tokens.refresh_token_expires_in * 1000).toISOString(),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export class EnvTokenCredential {
|
|
29
|
+
token;
|
|
30
|
+
kind = 'personal_token';
|
|
31
|
+
environment = undefined;
|
|
32
|
+
dashboardUrl = undefined;
|
|
33
|
+
constructor(token) {
|
|
34
|
+
this.token = token;
|
|
35
|
+
if (!PERSONAL_TOKEN_SHAPE.test(token)) {
|
|
36
|
+
throw new SentinelError(`${TOKEN_ENV} is not a personal API token (snt_pat_…).`, 4);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async accessToken() {
|
|
40
|
+
return this.token;
|
|
41
|
+
}
|
|
42
|
+
async renew() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class SessionCredential {
|
|
47
|
+
session;
|
|
48
|
+
store;
|
|
49
|
+
options;
|
|
50
|
+
kind = 'cli_session';
|
|
51
|
+
constructor(session, store, options = {}) {
|
|
52
|
+
this.session = session;
|
|
53
|
+
this.store = store;
|
|
54
|
+
this.options = options;
|
|
55
|
+
}
|
|
56
|
+
get environment() {
|
|
57
|
+
return this.session.environment;
|
|
58
|
+
}
|
|
59
|
+
get dashboardUrl() {
|
|
60
|
+
return this.session.dashboardUrl;
|
|
61
|
+
}
|
|
62
|
+
get current() {
|
|
63
|
+
return this.session;
|
|
64
|
+
}
|
|
65
|
+
now() {
|
|
66
|
+
return (this.options.now ?? Date.now)();
|
|
67
|
+
}
|
|
68
|
+
async accessToken() {
|
|
69
|
+
const ends = Date.parse(this.session.sessionExpiresAt);
|
|
70
|
+
if (!(ends > this.now())) {
|
|
71
|
+
// Left in the store: the next login replaces it.
|
|
72
|
+
throw new NotSignedInError('Your sign-in has ended. Run `sentinel login`.');
|
|
73
|
+
}
|
|
74
|
+
if (!(Date.parse(this.session.accessExpiresAt) - EARLY_MS > this.now()))
|
|
75
|
+
await this.refresh(this.session.accessToken);
|
|
76
|
+
return this.session.accessToken;
|
|
77
|
+
}
|
|
78
|
+
async renew() {
|
|
79
|
+
await this.refresh(this.session.accessToken);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
async refresh(seen) {
|
|
83
|
+
const { apiUrl } = this.session;
|
|
84
|
+
await withSessionLock(apiUrl, this.options.lockDir, async () => {
|
|
85
|
+
// Another command may have refreshed while this one waited.
|
|
86
|
+
const latest = await this.store.get(apiUrl);
|
|
87
|
+
if (latest && latest.accessToken !== seen && Date.parse(latest.accessExpiresAt) - EARLY_MS > this.now()) {
|
|
88
|
+
this.session = latest;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const refreshToken = (latest ?? this.session).refreshToken;
|
|
92
|
+
const body = { grant_type: 'refresh_token', refresh_token: refreshToken };
|
|
93
|
+
let tokens;
|
|
94
|
+
try {
|
|
95
|
+
try {
|
|
96
|
+
tokens = await requestToken(apiUrl, body, this.options);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
// The server may have rotated before the answer was lost: it
|
|
100
|
+
// accepts the same refresh token again for a short grace.
|
|
101
|
+
if (!isTransient(error))
|
|
102
|
+
throw error;
|
|
103
|
+
tokens = await requestToken(apiUrl, body, this.options);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof GrantError && error.error === 'invalid_grant') {
|
|
108
|
+
await this.store.delete(apiUrl);
|
|
109
|
+
throw new NotSignedInError('Your sign-in has ended. Run `sentinel login`.');
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
this.session = {
|
|
114
|
+
...sessionFromTokens(apiUrl, tokens, this.now()),
|
|
115
|
+
email: this.session.email,
|
|
116
|
+
dashboardUrl: this.session.dashboardUrl,
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
await this.store.set(this.session);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw new SentinelError(`The sign-in was renewed but could not be saved (${error.message}). ` +
|
|
123
|
+
'Run `sentinel login` again before the next command.', 4);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Hold the per-session lock that refresh, login and logout share. */
|
|
129
|
+
export function withSessionLock(apiUrl, lockDir, task) {
|
|
130
|
+
const name = `customer-session-${createHash('sha256').update(apiUrl).digest('hex').slice(0, 16)}`;
|
|
131
|
+
return withLock(lockDir ?? configDir(), name, task);
|
|
132
|
+
}
|
|
133
|
+
/** The credential for this API URL, or NotSignedInError. */
|
|
134
|
+
export async function resolveCredential(apiUrl, store, env = process.env, options = {}) {
|
|
135
|
+
const token = env[TOKEN_ENV]?.trim();
|
|
136
|
+
if (token)
|
|
137
|
+
return new EnvTokenCredential(token);
|
|
138
|
+
const opened = await store();
|
|
139
|
+
const session = await opened.get(apiUrl);
|
|
140
|
+
if (!session)
|
|
141
|
+
throw new NotSignedInError();
|
|
142
|
+
return new SessionCredential(session, opened, options);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/auth/credentials.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,uDAAuD;AACvD,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAchE,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,MAAgB,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG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E,OAAO,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth 2.0 device authorization (RFC 8628) against Sentinel's customer
|
|
3
|
+
* `/api/v1/account/cli` endpoints (truecms/sentinel#1623).
|
|
4
|
+
*/
|
|
5
|
+
import { SentinelApiError, SentinelError } from '../api/errors.js';
|
|
6
|
+
import { type HttpOptions } from '../api/http.js';
|
|
7
|
+
export declare const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
8
|
+
export interface DeviceAuthorization {
|
|
9
|
+
device_code: string;
|
|
10
|
+
user_code: string;
|
|
11
|
+
verification_uri: string;
|
|
12
|
+
verification_uri_complete: string;
|
|
13
|
+
expires_in: number;
|
|
14
|
+
interval: number;
|
|
15
|
+
environment: string;
|
|
16
|
+
scope: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TokenSet {
|
|
19
|
+
access_token: string;
|
|
20
|
+
token_type: string;
|
|
21
|
+
expires_in: number;
|
|
22
|
+
refresh_token: string;
|
|
23
|
+
refresh_token_expires_in: number;
|
|
24
|
+
scope: string;
|
|
25
|
+
environment: string;
|
|
26
|
+
session_id: number;
|
|
27
|
+
}
|
|
28
|
+
/** A token endpoint error (`{"error": ...}`), such as `invalid_grant`. */
|
|
29
|
+
export declare class GrantError extends SentinelError {
|
|
30
|
+
readonly error: string;
|
|
31
|
+
constructor(error: string, description: string);
|
|
32
|
+
}
|
|
33
|
+
/** Busy or failing server (429, 5xx): worth trying again later. */
|
|
34
|
+
export declare class TransientError extends SentinelError {
|
|
35
|
+
readonly apiError: SentinelApiError;
|
|
36
|
+
readonly retryAfterSeconds: number | undefined;
|
|
37
|
+
constructor(apiError: SentinelApiError, retryAfterSeconds: number | undefined);
|
|
38
|
+
}
|
|
39
|
+
export declare function isTransient(error: unknown): boolean;
|
|
40
|
+
/** `scope` is `read` or `read write`; the person may still approve read only. */
|
|
41
|
+
export declare function startDeviceAuthorization(apiUrl: string, clientName: string, scope: string, options?: HttpOptions): Promise<DeviceAuthorization>;
|
|
42
|
+
/** One call to the token endpoint; RFC 6749 errors become GrantError. */
|
|
43
|
+
export declare function requestToken(apiUrl: string, body: Record<string, string>, options?: HttpOptions): Promise<TokenSet>;
|
|
44
|
+
/** Sign out: the server ends the sign-in either token belongs to. Always 200. */
|
|
45
|
+
export declare function revokeToken(apiUrl: string, token: string, options?: HttpOptions): Promise<void>;
|
|
46
|
+
export interface PollOptions extends HttpOptions {
|
|
47
|
+
sleep?: (ms: number) => Promise<void>;
|
|
48
|
+
now?: () => number;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
/** Poll until the person approves or denies the code in the dashboard, or it expires. */
|
|
52
|
+
export declare function pollForTokens(apiUrl: string, device: DeviceAuthorization, options?: PollOptions): Promise<TokenSet>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth 2.0 device authorization (RFC 8628) against Sentinel's customer
|
|
3
|
+
* `/api/v1/account/cli` endpoints (truecms/sentinel#1623).
|
|
4
|
+
*/
|
|
5
|
+
import { errorFromResponse, SentinelApiError, SentinelError } from '../api/errors.js';
|
|
6
|
+
import { CLIENT_HEADER, NetworkError, postJson, send } from '../api/http.js';
|
|
7
|
+
export const DEVICE_CODE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code';
|
|
8
|
+
const BASE = '/api/v1/account/cli';
|
|
9
|
+
/** A token endpoint error (`{"error": ...}`), such as `invalid_grant`. */
|
|
10
|
+
export class GrantError extends SentinelError {
|
|
11
|
+
error;
|
|
12
|
+
constructor(error, description) {
|
|
13
|
+
super(description || error, 4);
|
|
14
|
+
this.error = error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Busy or failing server (429, 5xx): worth trying again later. */
|
|
18
|
+
export class TransientError extends SentinelError {
|
|
19
|
+
apiError;
|
|
20
|
+
retryAfterSeconds;
|
|
21
|
+
constructor(apiError, retryAfterSeconds) {
|
|
22
|
+
super(apiError.message, 3);
|
|
23
|
+
this.apiError = apiError;
|
|
24
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function isTransient(error) {
|
|
28
|
+
return error instanceof TransientError || error instanceof NetworkError;
|
|
29
|
+
}
|
|
30
|
+
/** `scope` is `read` or `read write`; the person may still approve read only. */
|
|
31
|
+
export function startDeviceAuthorization(apiUrl, clientName, scope, options = {}) {
|
|
32
|
+
return postJson(`${apiUrl}${BASE}/device/authorize`, { client_name: clientName, scope }, options);
|
|
33
|
+
}
|
|
34
|
+
/** One call to the token endpoint; RFC 6749 errors become GrantError. */
|
|
35
|
+
export async function requestToken(apiUrl, body, options = {}) {
|
|
36
|
+
const response = await send(new Request(`${apiUrl}${BASE}/token`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json', [CLIENT_HEADER]: 'cli' },
|
|
39
|
+
body: JSON.stringify(body),
|
|
40
|
+
}), options);
|
|
41
|
+
if (response.ok)
|
|
42
|
+
return (await response.json());
|
|
43
|
+
if (response.status === 429 || response.status >= 500) {
|
|
44
|
+
const error = await errorFromResponse(response);
|
|
45
|
+
const retryAfter = Number(response.headers.get('Retry-After'));
|
|
46
|
+
throw new TransientError(error, Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter : undefined);
|
|
47
|
+
}
|
|
48
|
+
if (response.status === 400 || response.status === 401) {
|
|
49
|
+
const payload = (await response.json().catch(() => ({})));
|
|
50
|
+
// The server answers RFC 6749 errors at the top level or inside `detail`.
|
|
51
|
+
const fields = (payload.detail && typeof payload.detail === 'object' ? payload.detail : payload);
|
|
52
|
+
if (typeof fields.error === 'string') {
|
|
53
|
+
throw new GrantError(fields.error, typeof fields.error_description === 'string' ? fields.error_description : '');
|
|
54
|
+
}
|
|
55
|
+
throw new SentinelApiError(response.status, undefined, `HTTP ${response.status}`, payload);
|
|
56
|
+
}
|
|
57
|
+
throw await errorFromResponse(response);
|
|
58
|
+
}
|
|
59
|
+
/** Sign out: the server ends the sign-in either token belongs to. Always 200. */
|
|
60
|
+
export async function revokeToken(apiUrl, token, options = {}) {
|
|
61
|
+
await postJson(`${apiUrl}${BASE}/revoke`, { token }, options);
|
|
62
|
+
}
|
|
63
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
64
|
+
/** Poll until the person approves or denies the code in the dashboard, or it expires. */
|
|
65
|
+
export async function pollForTokens(apiUrl, device, options = {}) {
|
|
66
|
+
const sleep = options.sleep ?? wait;
|
|
67
|
+
const now = options.now ?? Date.now;
|
|
68
|
+
const deadline = now() + device.expires_in * 1000;
|
|
69
|
+
let interval = Number.isFinite(device.interval) && device.interval > 0 ? device.interval : 5;
|
|
70
|
+
let pause = interval;
|
|
71
|
+
for (;;) {
|
|
72
|
+
await sleep(pause * 1000);
|
|
73
|
+
pause = interval;
|
|
74
|
+
if (options.signal?.aborted)
|
|
75
|
+
throw new SentinelError('Sign-in cancelled.', 130);
|
|
76
|
+
if (now() >= deadline)
|
|
77
|
+
throw new SentinelError('The sign-in code expired. Run `sentinel login` again.', 4);
|
|
78
|
+
try {
|
|
79
|
+
return await requestToken(apiUrl, { grant_type: DEVICE_CODE_GRANT, device_code: device.device_code }, options);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (isTransient(error)) {
|
|
83
|
+
// A busy server or a dropped connection does not end the sign-in.
|
|
84
|
+
const retryAfter = error instanceof TransientError ? error.retryAfterSeconds : undefined;
|
|
85
|
+
pause = Math.min(Math.max(retryAfter ?? interval * 2, interval), 60);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (!(error instanceof GrantError))
|
|
89
|
+
throw error;
|
|
90
|
+
if (error.error === 'authorization_pending')
|
|
91
|
+
continue;
|
|
92
|
+
if (error.error === 'slow_down') {
|
|
93
|
+
interval += 5;
|
|
94
|
+
pause = interval;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (error.error === 'access_denied')
|
|
98
|
+
throw new SentinelError('The sign-in was denied in the dashboard.', 4);
|
|
99
|
+
if (error.error === 'expired_token') {
|
|
100
|
+
throw new SentinelError('The sign-in code expired. Run `sentinel login` again.', 4);
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=deviceFlow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceFlow.js","sourceRoot":"","sources":["../../src/auth/deviceFlow.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAoB,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AAChF,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAwBnC,0EAA0E;AAC1E,MAAM,OAAO,UAAW,SAAQ,aAAa;IAEhC;IADX,YACW,KAAa,EACtB,WAAmB;QAEnB,KAAK,CAAC,WAAW,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC;QAHtB,UAAK,GAAL,KAAK,CAAQ;IAIxB,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,cAAe,SAAQ,aAAa;IAEpC;IACA;IAFX,YACW,QAA0B,EAC1B,iBAAqC;QAE9C,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAHlB,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,sBAAiB,GAAjB,iBAAiB,CAAoB;IAGhD,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,cAAc,IAAI,KAAK,YAAY,YAAY,CAAC;AAC1E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C,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;gBACrE,SAAS;YACX,CAAC;YACD,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;gBAAE,MAAM,KAAK,CAAC;YAChD,IAAI,KAAK,CAAC,KAAK,KAAK,uBAAuB;gBAAE,SAAS;YACtD,IAAI,KAAK,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;gBAChC,QAAQ,IAAI,CAAC,CAAC;gBACd,KAAK,GAAG,QAAQ,CAAC;gBACjB,SAAS;YACX,CAAC;YACD,IAAI,KAAK,CAAC,KAAK,KAAK,eAAe;gBAAE,MAAM,IAAI,aAAa,CAAC,0CAA0C,EAAE,CAAC,CAAC,CAAC;YAC5G,IAAI,KAAK,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;gBACpC,MAAM,IAAI,aAAa,CAAC,uDAAuD,EAAE,CAAC,CAAC,CAAC;YACtF,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cross-process lock file. Refresh tokens rotate, and the server revokes a
|
|
3
|
+
* session whose replaced refresh token is used again after a short grace, so
|
|
4
|
+
* two commands must never refresh one session at once, and the credentials
|
|
5
|
+
* file must never be rewritten by two commands at once.
|
|
6
|
+
*
|
|
7
|
+
* The lock file holds a random owner id: only its owner removes it. A lock
|
|
8
|
+
* older than STALE_MS (far longer than any refresh: two 30-second requests
|
|
9
|
+
* plus a key derivation) is taken over by renaming it away first, so two
|
|
10
|
+
* waiters cannot both take it.
|
|
11
|
+
*/
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import { link, mkdir, open, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
14
|
+
import { SentinelError } from '../api/errors.js';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
export const STALE_MS = 120_000;
|
|
17
|
+
async function tryCreate(path, owner) {
|
|
18
|
+
try {
|
|
19
|
+
const handle = await open(path, 'wx', 0o600);
|
|
20
|
+
try {
|
|
21
|
+
await handle.writeFile(owner);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await handle.close();
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === 'EEXIST')
|
|
30
|
+
return false;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function removeStale(path) {
|
|
35
|
+
const info = await stat(path).catch(() => undefined);
|
|
36
|
+
if (!info || Date.now() - info.mtimeMs <= STALE_MS)
|
|
37
|
+
return;
|
|
38
|
+
const aside = `${path}.stale.${randomBytes(6).toString('hex')}`;
|
|
39
|
+
try {
|
|
40
|
+
// Atomic: of several waiters, one renames the stale lock away.
|
|
41
|
+
await rename(path, aside);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const moved = await stat(aside).catch(() => undefined);
|
|
47
|
+
if (moved && Date.now() - moved.mtimeMs <= STALE_MS) {
|
|
48
|
+
// Someone took the lock between our stat and rename: put it back, unless
|
|
49
|
+
// another waiter has created one meanwhile (link never overwrites).
|
|
50
|
+
try {
|
|
51
|
+
await link(aside, path);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code !== 'EEXIST') {
|
|
55
|
+
// No hard links on this filesystem: put it back the old way.
|
|
56
|
+
await rename(aside, path).catch(() => undefined);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
await rm(aside, { force: true });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await rm(aside, { force: true });
|
|
64
|
+
}
|
|
65
|
+
export async function withLock(dir, name, task, timeoutMs = 60_000) {
|
|
66
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
67
|
+
const path = join(dir, `${name}.lock`);
|
|
68
|
+
const owner = randomBytes(16).toString('hex');
|
|
69
|
+
const started = Date.now();
|
|
70
|
+
while (!(await tryCreate(path, owner))) {
|
|
71
|
+
await removeStale(path);
|
|
72
|
+
if (Date.now() - started > timeoutMs) {
|
|
73
|
+
throw new SentinelError('Timed out waiting for another sentinel command to finish.', 1);
|
|
74
|
+
}
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return await task();
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
const current = await readFile(path, 'utf8').catch(() => undefined);
|
|
82
|
+
if (current === owner)
|
|
83
|
+
await rm(path, { force: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/auth/lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEjF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEhC,KAAK,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,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AAM,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export declare const STORE_ENV = "SENTINEL_CREDENTIAL_STORE";
|
|
2
|
+
export declare const PASSPHRASE_ENV = "SENTINEL_CREDENTIALS_PASSPHRASE";
|
|
3
|
+
/** One signed-in CLI session (truecms/sentinel#1623). */
|
|
4
|
+
export interface StoredSession {
|
|
5
|
+
version: 1;
|
|
6
|
+
apiUrl: string;
|
|
7
|
+
environment: string;
|
|
8
|
+
sessionId: number;
|
|
9
|
+
/** `read`, or `read write`, as approved. */
|
|
10
|
+
scope?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
/** The dashboard origin, from the sign-in link: where person-only steps happen. */
|
|
13
|
+
dashboardUrl?: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
/** ISO time the access token expires. */
|
|
16
|
+
accessExpiresAt: string;
|
|
17
|
+
refreshToken: string;
|
|
18
|
+
/** ISO time the session ends, refresh or not. */
|
|
19
|
+
sessionExpiresAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CredentialStore {
|
|
22
|
+
readonly kind: 'keychain' | 'file' | 'memory';
|
|
23
|
+
get(apiUrl: string): Promise<StoredSession | undefined>;
|
|
24
|
+
set(session: StoredSession): Promise<void>;
|
|
25
|
+
delete(apiUrl: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class MemoryStore implements CredentialStore {
|
|
28
|
+
readonly kind: "memory";
|
|
29
|
+
readonly entries: Map<string, StoredSession>;
|
|
30
|
+
get(apiUrl: string): Promise<StoredSession | undefined>;
|
|
31
|
+
set(session: StoredSession): Promise<void>;
|
|
32
|
+
delete(apiUrl: string): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
interface KeyringEntry {
|
|
35
|
+
getPassword(): string | null | undefined;
|
|
36
|
+
setPassword(value: string): void;
|
|
37
|
+
deletePassword(): boolean | void;
|
|
38
|
+
}
|
|
39
|
+
type EntryClass = new (service: string, account: string, options?: {
|
|
40
|
+
linux?: {
|
|
41
|
+
store?: 'secret-service' | 'keyutils';
|
|
42
|
+
};
|
|
43
|
+
}) => KeyringEntry;
|
|
44
|
+
export declare class KeychainStore implements CredentialStore {
|
|
45
|
+
private readonly Entry;
|
|
46
|
+
readonly kind: "keychain";
|
|
47
|
+
constructor(Entry: EntryClass);
|
|
48
|
+
private entry;
|
|
49
|
+
get(apiUrl: string): Promise<StoredSession | undefined>;
|
|
50
|
+
set(session: StoredSession): Promise<void>;
|
|
51
|
+
delete(apiUrl: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/** Load the keychain and prove it can store and read a value, or undefined. */
|
|
54
|
+
export declare function loadKeychain(): Promise<KeychainStore | undefined>;
|
|
55
|
+
interface Sealed {
|
|
56
|
+
version: 1;
|
|
57
|
+
kdf: 'scrypt';
|
|
58
|
+
salt: string;
|
|
59
|
+
iv: string;
|
|
60
|
+
tag: string;
|
|
61
|
+
data: string;
|
|
62
|
+
}
|
|
63
|
+
export declare function seal(entries: Record<string, StoredSession>, passphrase: string, salt?: Buffer): Promise<Sealed>;
|
|
64
|
+
export declare function unseal(sealed: Sealed, passphrase: string): Promise<Record<string, StoredSession>>;
|
|
65
|
+
/** `creating`: the file is new, so a typed passphrase is asked twice. */
|
|
66
|
+
export type PassphraseSource = (options?: {
|
|
67
|
+
creating?: boolean;
|
|
68
|
+
}) => Promise<string>;
|
|
69
|
+
export declare function defaultPassphrase(env?: NodeJS.ProcessEnv): PassphraseSource;
|
|
70
|
+
/** An encrypted file, mode 0600 in a 0700 directory. */
|
|
71
|
+
export declare class EncryptedFileStore implements CredentialStore {
|
|
72
|
+
private readonly dir;
|
|
73
|
+
private readonly passphrase;
|
|
74
|
+
readonly kind: "file";
|
|
75
|
+
readonly path: string;
|
|
76
|
+
constructor(dir: string, passphrase: PassphraseSource);
|
|
77
|
+
private readAll;
|
|
78
|
+
private writeAll;
|
|
79
|
+
/** Read, change and write the whole file under one lock for all commands. */
|
|
80
|
+
private change;
|
|
81
|
+
get(apiUrl: string): Promise<StoredSession | undefined>;
|
|
82
|
+
set(session: StoredSession): Promise<void>;
|
|
83
|
+
delete(apiUrl: string): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
/** The store this process uses: the keychain when it works, else the file. */
|
|
86
|
+
export declare function openStore(env?: NodeJS.ProcessEnv): Promise<CredentialStore>;
|
|
87
|
+
export {};
|