@experiture/xyra-cli 0.4.0 → 0.6.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/README.md +57 -15
- package/dist/auth/oauthClient.js +12 -2
- package/dist/auth/oauthClient.js.map +1 -1
- package/dist/auth/session.js +41 -13
- package/dist/auth/session.js.map +1 -1
- package/dist/chat/runtimeChatClient.js +23102 -0
- package/dist/chat/runtimeChatClient.js.map +7 -0
- package/dist/commands/chat.js +145 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/login.js +4 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/mcpContext.js +16 -6
- package/dist/commands/mcpContext.js.map +1 -1
- package/dist/commands/session.js +11 -6
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/tools.js +1 -1
- package/dist/commands/tools.js.map +1 -1
- package/dist/config/configStore.js +25 -1
- package/dist/config/configStore.js.map +1 -1
- package/dist/config/environments.js +13 -0
- package/dist/config/environments.js.map +1 -1
- package/dist/diagnostics/latency.js +139 -0
- package/dist/diagnostics/latency.js.map +1 -0
- package/dist/errors/CliError.js +4 -1
- package/dist/errors/CliError.js.map +1 -1
- package/dist/evaluation/localSession.js +62 -0
- package/dist/evaluation/localSession.js.map +1 -0
- package/dist/index.js +39 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp/confirmation.js +14 -17
- package/dist/mcp/confirmation.js.map +1 -1
- package/dist/mcp/mcpClient.js +17 -1
- package/dist/mcp/mcpClient.js.map +1 -1
- package/dist/output/console.js +3 -1
- package/dist/output/console.js.map +1 -1
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -5,9 +5,10 @@ delegated user via OAuth 2.0 Authorization Code + PKCE, then discovers and
|
|
|
5
5
|
invokes Xyra tools over MCP JSON-RPC. Tool visibility and execution are governed
|
|
6
6
|
by the signed-in user's real product roles and concrete permissions.
|
|
7
7
|
|
|
8
|
-
> CLI-0 … CLI-9 are implemented. CLI-10
|
|
9
|
-
>
|
|
10
|
-
>
|
|
8
|
+
> CLI-0 … CLI-9 are implemented. CLI-10 remains an enterprise-maturity backlog
|
|
9
|
+
> for completion, richer non-secret config/profile commands, optional metadata
|
|
10
|
+
> cache, and CI/service-principal mode. Opt-in latency diagnostics and public
|
|
11
|
+
> npm release trust are implemented.
|
|
11
12
|
> Spec: `docs/todo/MCP/TODO-XYRA-CLI-HEADLESS-APPLICATION-RUNNER.md` (in the
|
|
12
13
|
> monorepo).
|
|
13
14
|
|
|
@@ -31,9 +32,10 @@ xyra --version
|
|
|
31
32
|
|
|
32
33
|
Releases are published to public npm from a versioned `xyra-cli-v*` Git tag.
|
|
33
34
|
The workflow builds, tests, packs, publishes with npm trusted publishing, and
|
|
34
|
-
smoke-installs the exact public package. The
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
smoke-installs the exact public package. The npm package is bound to
|
|
36
|
+
`Experiture-git-ORG/ExperitureAI-Headless` and
|
|
37
|
+
`.github/workflows/publish-xyra-cli.yml` as its GitHub OIDC trusted publisher;
|
|
38
|
+
no long-lived npm publish token is stored in GitHub.
|
|
37
39
|
|
|
38
40
|
For local smoke testing before publishing, install from a packed tarball
|
|
39
41
|
(keychain support installs automatically where the native module builds,
|
|
@@ -41,7 +43,7 @@ otherwise the CLI falls back per the security model below):
|
|
|
41
43
|
|
|
42
44
|
```bash
|
|
43
45
|
npm pack --workspace=apps/xyra-cli --pack-destination /tmp
|
|
44
|
-
npm install -g /tmp/experiture-xyra-cli-0.
|
|
46
|
+
npm install -g /tmp/experiture-xyra-cli-0.6.0.tgz
|
|
45
47
|
xyra --version
|
|
46
48
|
```
|
|
47
49
|
|
|
@@ -66,24 +68,42 @@ pointing at your working tree.
|
|
|
66
68
|
encrypted-file fallback is disabled unless
|
|
67
69
|
`XYRA_CLI_ALLOW_INSECURE_TOKEN_STORE=true` (dev only). Tokens are never
|
|
68
70
|
printed or logged; diagnostic output is redacted.
|
|
69
|
-
- **
|
|
70
|
-
|
|
71
|
+
- **Tools use MCP. Chat uses Orchestrator.** `xyra tools` discovers and runs
|
|
72
|
+
tools through the MCP server. `xyra chat` creates and continues a
|
|
73
|
+
conversation through Orchestrator's public runtime. Neither path invents
|
|
74
|
+
identity headers or calls a product API directly. Requires Node 20 or newer.
|
|
71
75
|
|
|
72
76
|
## Commands
|
|
73
77
|
|
|
74
78
|
```bash
|
|
75
|
-
xyra env list | env use <name> | env show # connection profiles (dev, local)
|
|
76
|
-
xyra login [--no-browser]
|
|
77
|
-
xyra whoami [--json]
|
|
78
|
-
xyra logout
|
|
79
|
+
xyra env list | env use <name> | env show # connection profiles (dev, staging, local)
|
|
80
|
+
xyra login [--no-browser] [--session <name>] # delegated OAuth sign-in
|
|
81
|
+
xyra whoami [--json] [--session <name>] # inspect the selected login without printing tokens
|
|
82
|
+
xyra logout [--session <name>] # remove only the selected login
|
|
83
|
+
xyra chat start [--title <text>] [--json] # create a conversation
|
|
84
|
+
xyra chat send --conversation <id> "<message>" # continue one conversation
|
|
85
|
+
xyra chat send --new "<message>" # create, then send one turn
|
|
79
86
|
xyra mcp metadata [--json] # public OAuth resource metadata (no login)
|
|
80
87
|
xyra mcp initialize [--json] # MCP handshake / capabilities
|
|
81
88
|
xyra tools list [--domain <id>] [--task <k>] [--limit <n>] [--json]
|
|
82
89
|
xyra tools describe <toolKey> [--json]
|
|
83
90
|
xyra tools schema <toolKey> # JSON input schema only
|
|
84
91
|
xyra tools call <toolKey> --arg k=v [--input <json>|--input-file <path>] [--json|--raw]
|
|
92
|
+
|
|
93
|
+
# Add local-only caller, auth, MCP, render, edge, trace and correlation timing.
|
|
94
|
+
xyra --timings tools list --limit 1
|
|
95
|
+
xyra --timings-json tools call <toolKey> --arg k=v
|
|
85
96
|
```
|
|
86
97
|
|
|
98
|
+
Named logins store independent credentials under the existing secure token store;
|
|
99
|
+
refreshing or removing one does not replace the other.
|
|
100
|
+
Names use up to 64 lowercase letters, numbers, hyphens or underscores and begin
|
|
101
|
+
with a letter. Changing a named session's configured Auth or runtime destination
|
|
102
|
+
requires signing in again. A session name does not approve an identity or grant
|
|
103
|
+
permissions. Commands without `--session` use the ordinary login; the named
|
|
104
|
+
selector is available on login, whoami and logout. Evaluations run through the
|
|
105
|
+
browser and managed worker, so this CLI has no separate evaluation command.
|
|
106
|
+
|
|
87
107
|
Live tool visibility is owned by MCP, not by a duplicated CLI policy layer:
|
|
88
108
|
`tools/list` returns only the tools visible to the current token's concrete
|
|
89
109
|
permissions, and `tools/call` still goes through the governed MCP execution rail
|
|
@@ -95,6 +115,22 @@ but actual calls always go back through MCP.
|
|
|
95
115
|
persisting** it — the active environment on disk is unchanged. Use
|
|
96
116
|
`xyra env use <name>` to change the persistent default.
|
|
97
117
|
|
|
118
|
+
`--timings` and `--timings-json` are explicit, local-only diagnostics. They
|
|
119
|
+
create and propagate standard W3C trace context, read only safe response
|
|
120
|
+
linkage (`X-Trace-Id`, `X-Correlation-Id`, and `Server-Timing`), write the
|
|
121
|
+
report to stderr, and install no telemetry exporter. Normal commands remain
|
|
122
|
+
unchanged when neither flag is present.
|
|
123
|
+
|
|
124
|
+
For repeatable percentile evidence, build the CLI and use the bounded benchmark
|
|
125
|
+
harness. It records aggregate timings and at most five trace IDs, never command
|
|
126
|
+
arguments, payloads, or tokens:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm run benchmark:latency --workspace=apps/xyra-cli -- \
|
|
130
|
+
--scenario warm-tools-list --label tools-list --release <revision> -- \
|
|
131
|
+
--env dev tools list --limit 1 --json
|
|
132
|
+
```
|
|
133
|
+
|
|
98
134
|
Canonical Xyra error codes and correlation IDs from MCP results are preserved
|
|
99
135
|
verbatim; local failures use stable `XYRA.CLI.*` codes. Any tool that returns
|
|
100
136
|
`isError` yields exit code 1 while still printing its payload.
|
|
@@ -106,6 +142,11 @@ safety-net exception: fields whose **names** are secret-bearing (`access_token`,
|
|
|
106
142
|
practice output is byte-for-byte the server payload; the redaction only ever
|
|
107
143
|
triggers on genuinely secret-named keys.
|
|
108
144
|
|
|
145
|
+
Ordinary fields named `code`, including Xyra error codes and JSON Schema
|
|
146
|
+
properties, are not secrets and remain unchanged. OAuth authorization codes are
|
|
147
|
+
protected at the login callback and token-exchange boundary and never enter the
|
|
148
|
+
generic command-output path.
|
|
149
|
+
|
|
109
150
|
## Test
|
|
110
151
|
|
|
111
152
|
```bash
|
|
@@ -115,5 +156,6 @@ npm test --workspace=apps/xyra-cli
|
|
|
115
156
|
Covers PKCE (S256/length), secret redaction, config validation (gates G1/G2),
|
|
116
157
|
encrypted token round-trip, silent refresh, rotated refresh-token persistence,
|
|
117
158
|
concurrent refresh serialization, loopback state-mismatch rejection, JSON-RPC
|
|
118
|
-
401 auth handling, `tools/list` pagination,
|
|
119
|
-
preservation
|
|
159
|
+
401 auth handling, `tools/list` pagination, canonical error/correlation-id
|
|
160
|
+
preservation, W3C trace propagation, safe response linkage, opt-in latency
|
|
161
|
+
phases, and inert default diagnostics.
|
package/dist/auth/oauthClient.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACCESS_TOKEN_OPERATION_SAFETY_SECONDS = void 0;
|
|
3
4
|
exports.buildAuthorizeUrl = buildAuthorizeUrl;
|
|
4
5
|
exports.exchangeCode = exchangeCode;
|
|
5
6
|
exports.refreshToken = refreshToken;
|
|
6
7
|
exports.decodeJwtClaims = decodeJwtClaims;
|
|
7
8
|
exports.toStoredToken = toStoredToken;
|
|
8
9
|
const CliError_1 = require("../errors/CliError");
|
|
10
|
+
/**
|
|
11
|
+
* Keep enough access-token lifetime for one long-running Xyra operation.
|
|
12
|
+
*
|
|
13
|
+
* Authentication is checked before a command starts, while a streamed turn can
|
|
14
|
+
* legitimately continue for more than one minute. Refreshing two minutes
|
|
15
|
+
* before the issuer's expiry prevents a token that was valid at dispatch from
|
|
16
|
+
* expiring during owner-API calls later in the same turn.
|
|
17
|
+
*/
|
|
18
|
+
exports.ACCESS_TOKEN_OPERATION_SAFETY_SECONDS = 120;
|
|
9
19
|
/** Build the browser authorization URL (authorization_code + PKCE, public client). */
|
|
10
20
|
function buildAuthorizeUrl(env, params) {
|
|
11
21
|
const url = new URL(env.authorizationEndpoint);
|
|
@@ -90,8 +100,8 @@ function toStoredToken(response) {
|
|
|
90
100
|
refreshToken: response.refresh_token,
|
|
91
101
|
tokenType: response.token_type || 'Bearer',
|
|
92
102
|
scope: response.scope,
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
expiresAt: Date.now()
|
|
104
|
+
+ Math.max(0, response.expires_in - exports.ACCESS_TOKEN_OPERATION_SAFETY_SECONDS) * 1000,
|
|
95
105
|
subjectType,
|
|
96
106
|
};
|
|
97
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauthClient.js","sourceRoot":"","sources":["../../src/auth/oauthClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"oauthClient.js","sourceRoot":"","sources":["../../src/auth/oauthClient.ts"],"names":[],"mappings":";;;AA8BA,8CAWC;AA6BD,oCAaC;AAGD,oCAQC;AAGD,0CASC;AAED,sCAYC;AAxHD,iDAA6D;AAmB7D;;;;;;;GAOG;AACU,QAAA,qCAAqC,GAAG,GAAG,CAAC;AAEzD,sFAAsF;AACtF,SAAgB,iBAAiB,CAAC,GAAoB,EAAE,MAAuB;IAC7E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC/C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC9C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACzD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,E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,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACpG,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAgB,aAAa,CAAC,QAAuB;IACnD,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IACxE,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,YAAY;QAClC,YAAY,EAAE,QAAQ,CAAC,aAAa;QACpC,SAAS,EAAE,QAAQ,CAAC,UAAU,IAAI,QAAQ;QAC1C,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;cACjB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,6CAAqC,CAAC,GAAG,IAAI;QACnF,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/auth/session.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.accountKey = accountKey;
|
|
4
|
+
exports.saveSessionToken = saveSessionToken;
|
|
5
|
+
exports.deleteSessionToken = deleteSessionToken;
|
|
4
6
|
exports.getValidToken = getValidToken;
|
|
5
7
|
const CliError_1 = require("../errors/CliError");
|
|
6
8
|
const oauthClient_1 = require("./oauthClient");
|
|
@@ -8,9 +10,23 @@ const node_crypto_1 = require("node:crypto");
|
|
|
8
10
|
const node_fs_1 = require("node:fs");
|
|
9
11
|
const node_os_1 = require("node:os");
|
|
10
12
|
const node_path_1 = require("node:path");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const latency_1 = require("../diagnostics/latency");
|
|
14
|
+
/** Named sessions separate concurrent identities; their names confer no authority. */
|
|
15
|
+
function accountKey(env, sessionName) {
|
|
16
|
+
if (sessionName === undefined)
|
|
17
|
+
return `${env.name}:${env.clientId}`;
|
|
18
|
+
if (!/^[a-z][a-z0-9_-]{0,63}$/.test(sessionName)) {
|
|
19
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.InvalidArguments, 'Session names must start with a lowercase letter and contain at most 64 lowercase letters, numbers, hyphens or underscores.');
|
|
20
|
+
}
|
|
21
|
+
// A renamed destination must require its own login rather than sending an
|
|
22
|
+
// existing subject's bearer or refresh token to the replacement endpoint.
|
|
23
|
+
const destination = (0, node_crypto_1.createHash)('sha256').update(JSON.stringify([
|
|
24
|
+
env.name, sessionName, env.authorizationEndpoint, env.tokenEndpoint, env.oauthResource,
|
|
25
|
+
env.mcpUrl, env.orchestratorUrl, env.clientId,
|
|
26
|
+
])).digest('hex');
|
|
27
|
+
// FileTokenStore encodes account keys into filenames, so the whole named
|
|
28
|
+
// account must remain bounded even for long valid names and client IDs.
|
|
29
|
+
return `session:v1:${destination}`;
|
|
14
30
|
}
|
|
15
31
|
const REFRESH_LOCK_TIMEOUT_MS = 20_000;
|
|
16
32
|
const REFRESH_LOCK_STALE_MS = 60_000;
|
|
@@ -27,7 +43,7 @@ function writeRefreshLockHeartbeat(fd) {
|
|
|
27
43
|
(0, node_fs_1.ftruncateSync)(fd, 0);
|
|
28
44
|
(0, node_fs_1.writeSync)(fd, JSON.stringify({ pid: process.pid, updatedAt: new Date().toISOString() }), 0, 'utf8');
|
|
29
45
|
}
|
|
30
|
-
async function
|
|
46
|
+
async function withSessionLock(account, action) {
|
|
31
47
|
const path = refreshLockPath(account);
|
|
32
48
|
(0, node_fs_1.mkdirSync)(REFRESH_LOCK_DIR, { recursive: true, mode: 0o700 });
|
|
33
49
|
const startedAt = Date.now();
|
|
@@ -57,7 +73,7 @@ async function withRefreshLock(account, action) {
|
|
|
57
73
|
continue;
|
|
58
74
|
}
|
|
59
75
|
if (Date.now() - startedAt > REFRESH_LOCK_TIMEOUT_MS) {
|
|
60
|
-
throw new CliError_1.CliError(CliError_1.CliErrorCodes.TokenExchangeFailed, 'Timed out waiting for another Xyra CLI process to
|
|
76
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.TokenExchangeFailed, 'Timed out waiting for another Xyra CLI process to update the session.', 'Retry the command. If this repeats, run xyra logout then xyra login.');
|
|
61
77
|
}
|
|
62
78
|
await sleep(150);
|
|
63
79
|
}
|
|
@@ -82,35 +98,47 @@ async function withRefreshLock(account, action) {
|
|
|
82
98
|
}
|
|
83
99
|
}
|
|
84
100
|
}
|
|
101
|
+
/** Serialize login replacement with refresh, so an older refresh cannot overwrite it. */
|
|
102
|
+
async function saveSessionToken(env, store, token, sessionName) {
|
|
103
|
+
const key = accountKey(env, sessionName);
|
|
104
|
+
await withSessionLock(key, () => store.set(key, token));
|
|
105
|
+
}
|
|
106
|
+
/** Logout waits for an in-flight refresh before deleting its resulting credential. */
|
|
107
|
+
async function deleteSessionToken(env, store, sessionName) {
|
|
108
|
+
const key = accountKey(env, sessionName);
|
|
109
|
+
await withSessionLock(key, () => store.delete(key));
|
|
110
|
+
}
|
|
85
111
|
/**
|
|
86
112
|
* Return a non-expired access token for the environment, silently refreshing
|
|
87
113
|
* with the refresh token when the 300s access token has lapsed (gate G2).
|
|
88
114
|
* Throws NotAuthenticated when there is no usable session.
|
|
89
115
|
*/
|
|
90
|
-
async function getValidToken(env, store) {
|
|
91
|
-
const key = accountKey(env);
|
|
116
|
+
async function getValidToken(env, store, sessionName) {
|
|
117
|
+
const key = accountKey(env, sessionName);
|
|
118
|
+
const sessionLabel = sessionName === undefined ? `'${env.name}'` : `'${env.name}' session '${sessionName}'`;
|
|
119
|
+
const loginHint = sessionName === undefined ? "Run 'xyra login'." : `Run 'xyra login --session ${sessionName}'.`;
|
|
92
120
|
const stored = await store.get(key);
|
|
93
121
|
if (!stored) {
|
|
94
|
-
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Not signed in to
|
|
122
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Not signed in to ${sessionLabel}.`, loginHint);
|
|
95
123
|
}
|
|
96
124
|
if (Date.now() < stored.expiresAt) {
|
|
97
125
|
return stored;
|
|
98
126
|
}
|
|
99
127
|
if (!stored.refreshToken) {
|
|
100
|
-
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `
|
|
128
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Login for ${sessionLabel} expired and no refresh token is available.`, loginHint);
|
|
101
129
|
}
|
|
102
|
-
return
|
|
130
|
+
return withSessionLock(key, async () => {
|
|
103
131
|
const latest = await store.get(key);
|
|
104
132
|
if (!latest) {
|
|
105
|
-
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Not signed in to
|
|
133
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Not signed in to ${sessionLabel}.`, loginHint);
|
|
106
134
|
}
|
|
107
135
|
if (Date.now() < latest.expiresAt) {
|
|
108
136
|
return latest;
|
|
109
137
|
}
|
|
110
138
|
if (!latest.refreshToken) {
|
|
111
|
-
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `
|
|
139
|
+
throw new CliError_1.CliError(CliError_1.CliErrorCodes.NotAuthenticated, `Login for ${sessionLabel} expired and no refresh token is available.`, loginHint);
|
|
112
140
|
}
|
|
113
|
-
const refreshed = (0, oauthClient_1.toStoredToken)(await (0, oauthClient_1.refreshToken)(env, latest.refreshToken));
|
|
141
|
+
const refreshed = (0, oauthClient_1.toStoredToken)(await (0, latency_1.measureLatencyPhase)('auth.token_refresh', () => (0, oauthClient_1.refreshToken)(env, latest.refreshToken)));
|
|
114
142
|
// Keep the prior refresh token only for non-rotating providers. Auth returns
|
|
115
143
|
// a rotated refresh_token; persisting it here is mandatory.
|
|
116
144
|
if (!refreshed.refreshToken)
|
package/dist/auth/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":";;AAWA,gCAiBC;AA8ED,4CAKC;AAGD,gDAKC;AAOD,sCAiDC;AA/KD,iDAA6D;AAE7D,+CAA4D;AAE5D,6CAAyC;AACzC,qCAAyG;AACzG,qCAAiC;AACjC,yCAAiC;AACjC,oDAA6D;AAE7D,sFAAsF;AACtF,SAAgB,UAAU,CAAC,GAAoB,EAAE,WAAoB;IACnE,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;IACpE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,mBAAQ,CAChB,wBAAa,CAAC,gBAAgB,EAC9B,6HAA6H,CAC9H,CAAC;IACJ,CAAC;IACD,0EAA0E;IAC1E,0EAA0E;IAC1E,MAAM,WAAW,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;QAC7D,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,aAAa;QACtF,GAAG,C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