@sylphx/cli 0.12.0 → 0.12.1
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 +6 -0
- package/README.md +1 -1
- package/dist/main.js +130 -19
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @sylphx/cli
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1172](https://github.com/SylphxAI/platform/pull/1172) [`c14a894`](https://github.com/SylphxAI/platform/commit/c14a894e9a3792a4f491f3acff3517008355e35f) Thanks [@shtse8](https://github.com/shtse8)! - Harden OAuth refresh for local agent fleets: stale refresh-token rejection no longer clears a newer stored session, refresh outages now surface as transient failures instead of hidden logouts, and handled CLI auth errors no longer print Effect runtime stack noise.
|
|
8
|
+
|
|
3
9
|
## 0.12.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The CLI supports three auth paths (ADR-059 + ADR-074):
|
|
|
46
46
|
|
|
47
47
|
Legacy `slx_*` personal access tokens were eliminated 2026-04-21 (ADR-059 §1.4) and are no longer accepted by the API.
|
|
48
48
|
|
|
49
|
-
Under ADR-059, OAuth tokens are stored as an atomic `{ accessToken, refreshToken, expiresAt, refreshExpiresAt }` record with mode `0600` on disk. The refresh interceptor (`utils/oauth-refresh.ts`) transparently rotates the access token when it's within the refresh window
|
|
49
|
+
Under ADR-059, OAuth tokens are stored as an atomic `{ accessToken, refreshToken, expiresAt, refreshExpiresAt }` record with mode `0600` on disk. The refresh interceptor (`utils/oauth-refresh.ts`) transparently rotates the access token when it's within the refresh window. Reuse/expiry clears only the rejected refresh-token chain; refresh transport failures are reported as outages and never silently erase the stored login.
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
52
|
# Interactive (developers)
|
package/dist/main.js
CHANGED
|
@@ -15,7 +15,7 @@ var init_package = __esm({
|
|
|
15
15
|
"package.json"() {
|
|
16
16
|
package_default = {
|
|
17
17
|
name: "@sylphx/cli",
|
|
18
|
-
version: "0.12.
|
|
18
|
+
version: "0.12.1",
|
|
19
19
|
description: "Sylphx Platform CLI \u2014 deploy and manage your applications from the terminal. 63 commands across deployment, logs, env vars, domains, databases, storage, monitoring, self-service (user), admin (users/quotas/audit/invitations/jwt-keys/project-migrate), and more.",
|
|
20
20
|
type: "module",
|
|
21
21
|
homepage: "https://sylphx.com",
|
|
@@ -12338,7 +12338,7 @@ var init_project_manifest2 = __esm({
|
|
|
12338
12338
|
|
|
12339
12339
|
// ../contract/dist/schemas/project.js
|
|
12340
12340
|
import { Schema as Schema92 } from "effect";
|
|
12341
|
-
var ProjectEnvironmentSummary, PreviewTierPolicy, Project, CreateProjectResult, DeleteProjectResult, CreateProjectInput, UpdateProjectInput;
|
|
12341
|
+
var ProjectEnvironmentSummary, PreviewTierPolicy, RegionCode, Project, CreateProjectResult, DeleteProjectResult, CreateProjectInput, UpdateProjectInput;
|
|
12342
12342
|
var init_project = __esm({
|
|
12343
12343
|
"../contract/dist/schemas/project.js"() {
|
|
12344
12344
|
"use strict";
|
|
@@ -12358,6 +12358,7 @@ var init_project = __esm({
|
|
|
12358
12358
|
updatedAt: Schema92.optional(Schema92.String)
|
|
12359
12359
|
});
|
|
12360
12360
|
PreviewTierPolicy = Schema92.Literal("selective", "strict", "auto-all", "off");
|
|
12361
|
+
RegionCode = Schema92.Literal("fsn1", "hel1", "ash1");
|
|
12361
12362
|
Project = Schema92.Struct({
|
|
12362
12363
|
id: ProjectId,
|
|
12363
12364
|
slug: Schema92.String,
|
|
@@ -12376,6 +12377,10 @@ var init_project = __esm({
|
|
|
12376
12377
|
buildMachineType: Schema92.optional(Schema92.String),
|
|
12377
12378
|
/** ADR-130 §2.2 — per-project preview tier policy. */
|
|
12378
12379
|
previewTierPolicy: Schema92.optional(PreviewTierPolicy),
|
|
12380
|
+
/** ADR-163 §2.2.1 — home region, read-only observable metadata. `fsn1`
|
|
12381
|
+
* for every project today; on the wire so the prospective second-region
|
|
12382
|
+
* rollout has the field from day one. Not settable by customers (§3). */
|
|
12383
|
+
region: Schema92.optional(RegionCode),
|
|
12379
12384
|
settings: Schema92.optional(Schema92.NullOr(Schema92.Record({ key: Schema92.String, value: Schema92.Unknown }))),
|
|
12380
12385
|
createdAt: Schema92.optional(Schema92.String),
|
|
12381
12386
|
updatedAt: Schema92.optional(Schema92.String),
|
|
@@ -12400,6 +12405,10 @@ var init_project = __esm({
|
|
|
12400
12405
|
dockerImage: Schema92.optional(Schema92.String),
|
|
12401
12406
|
port: Schema92.optional(Schema92.Number),
|
|
12402
12407
|
domain: Schema92.optional(Schema92.String)
|
|
12408
|
+
// ADR-163 §3 — no `region` on create input. Customer-facing region
|
|
12409
|
+
// selection is intentionally withheld until the reconciler can deploy
|
|
12410
|
+
// across clusters (see docs/catalog/iaas/regions.md invariant). `region`
|
|
12411
|
+
// is read-only observable metadata on the Project response, not a knob.
|
|
12403
12412
|
});
|
|
12404
12413
|
UpdateProjectInput = Schema92.Struct({
|
|
12405
12414
|
name: Schema92.optional(Schema92.String),
|
|
@@ -18438,6 +18447,24 @@ var init_config = __esm({
|
|
|
18438
18447
|
clearCredentials() {
|
|
18439
18448
|
store.delete("oauth");
|
|
18440
18449
|
},
|
|
18450
|
+
/**
|
|
18451
|
+
* Remove the OAuth credential only when the caller is invalidating the
|
|
18452
|
+
* refresh token that is still current on disk.
|
|
18453
|
+
*
|
|
18454
|
+
* OAuth refresh tokens rotate on every use. In a local agent fleet, another
|
|
18455
|
+
* process may legitimately consume `ref_A`, persist `ref_B`, and release the
|
|
18456
|
+
* refresh lock while a slower process is still unwinding a stale `ref_A`
|
|
18457
|
+
* failure. Unconditional clearing at that point destroys the valid `ref_B`
|
|
18458
|
+
* session and looks like a random logout. This compare-and-delete keeps
|
|
18459
|
+
* reuse detection fail-closed for the current token without trampling a
|
|
18460
|
+
* newer chain.
|
|
18461
|
+
*/
|
|
18462
|
+
clearCredentialsIfRefreshToken(refreshToken) {
|
|
18463
|
+
const current2 = store.get("oauth");
|
|
18464
|
+
if (!current2 || current2.refreshToken !== refreshToken) return false;
|
|
18465
|
+
store.delete("oauth");
|
|
18466
|
+
return true;
|
|
18467
|
+
},
|
|
18441
18468
|
/** Get default org */
|
|
18442
18469
|
getDefaultOrg() {
|
|
18443
18470
|
return store.get("defaultOrg");
|
|
@@ -18595,9 +18622,9 @@ function isExternalAuthActive() {
|
|
|
18595
18622
|
}
|
|
18596
18623
|
function unauthenticatedMessage(auth = resolveAuthToken()) {
|
|
18597
18624
|
if (auth.error) {
|
|
18598
|
-
return `${auth.error}. Fix ${AUTH_TOKEN_FILE_ENV_VAR} or unset it
|
|
18625
|
+
return `${auth.error}. Fix ${AUTH_TOKEN_FILE_ENV_VAR} or unset it. For agents and CI, set ${AUTH_TOKEN_FILE_ENV_VAR} or ${AUTH_ENV_VAR}; for an interactive shell, run \`sylphx login\`.`;
|
|
18599
18626
|
}
|
|
18600
|
-
return `
|
|
18627
|
+
return `Authentication required. Run \`sylphx login\` for an interactive session, or set \`${AUTH_TOKEN_FILE_ENV_VAR}\` / \`${AUTH_ENV_VAR}\` for agents and CI.`;
|
|
18601
18628
|
}
|
|
18602
18629
|
var AUTH_ENV_VAR, AUTH_TOKEN_FILE_ENV_VAR;
|
|
18603
18630
|
var init_auth_source = __esm({
|
|
@@ -18819,13 +18846,10 @@ function rotateAndPersist(refreshToken) {
|
|
|
18819
18846
|
const failure = Cause.failureOption(exit.cause);
|
|
18820
18847
|
const err = failure._tag === "Some" ? failure.value : void 0;
|
|
18821
18848
|
if (err?._tag === "RefreshReuseDetectedError" || err?._tag === "RefreshExpiredError") {
|
|
18822
|
-
config.clearCredentials();
|
|
18823
18849
|
if (debug) {
|
|
18824
18850
|
const ms = Date.now() - startedAt;
|
|
18825
|
-
process.stderr.write(
|
|
18826
|
-
|
|
18827
|
-
`
|
|
18828
|
-
);
|
|
18851
|
+
process.stderr.write(`[sylphx] oauth: refresh rejected (${ms}ms; ${err._tag})
|
|
18852
|
+
`);
|
|
18829
18853
|
}
|
|
18830
18854
|
} else if (debug) {
|
|
18831
18855
|
const ms = Date.now() - startedAt;
|
|
@@ -18836,6 +18860,30 @@ function rotateAndPersist(refreshToken) {
|
|
|
18836
18860
|
throw err ?? new RefreshNetworkError({ message: "refresh failed (defect)" });
|
|
18837
18861
|
});
|
|
18838
18862
|
}
|
|
18863
|
+
function isTerminalRefreshError(err) {
|
|
18864
|
+
if (typeof err !== "object" || err === null || !("_tag" in err)) return false;
|
|
18865
|
+
const tag = err._tag;
|
|
18866
|
+
return tag === "RefreshReuseDetectedError" || tag === "RefreshExpiredError" || tag === "NoOAuthCredentialError";
|
|
18867
|
+
}
|
|
18868
|
+
function reconcileTerminalRefreshFailure(refreshToken, err) {
|
|
18869
|
+
if (err._tag === "NoOAuthCredentialError") return void 0;
|
|
18870
|
+
const latest = config.getOAuth();
|
|
18871
|
+
if (latest && latest.refreshToken !== refreshToken) {
|
|
18872
|
+
if (isDebug()) {
|
|
18873
|
+
process.stderr.write(
|
|
18874
|
+
"[sylphx] oauth: rejected stale refresh token; preserved newer stored session\n"
|
|
18875
|
+
);
|
|
18876
|
+
}
|
|
18877
|
+
return needsRefresh(latest) ? void 0 : latest;
|
|
18878
|
+
}
|
|
18879
|
+
const cleared = config.clearCredentialsIfRefreshToken(refreshToken);
|
|
18880
|
+
if (isDebug()) {
|
|
18881
|
+
process.stderr.write(
|
|
18882
|
+
cleared ? "[sylphx] oauth: current stored session rejected; credentials cleared\n" : "[sylphx] oauth: rejected session was no longer current; credentials left untouched\n"
|
|
18883
|
+
);
|
|
18884
|
+
}
|
|
18885
|
+
return void 0;
|
|
18886
|
+
}
|
|
18839
18887
|
function runRefresh(opts) {
|
|
18840
18888
|
if (inflight) return inflight;
|
|
18841
18889
|
inflight = withRefreshLock(async () => {
|
|
@@ -18845,7 +18893,15 @@ function runRefresh(opts) {
|
|
|
18845
18893
|
if (!opts.force || anotherProcessRotated) {
|
|
18846
18894
|
if (!needsRefresh(latest)) return latest;
|
|
18847
18895
|
}
|
|
18848
|
-
|
|
18896
|
+
const refreshToken = latest.refreshToken;
|
|
18897
|
+
try {
|
|
18898
|
+
return await rotateAndPersist(refreshToken);
|
|
18899
|
+
} catch (err) {
|
|
18900
|
+
if (!isTerminalRefreshError(err)) throw err;
|
|
18901
|
+
const preserved = reconcileTerminalRefreshFailure(refreshToken, err);
|
|
18902
|
+
if (preserved) return preserved;
|
|
18903
|
+
throw err;
|
|
18904
|
+
}
|
|
18849
18905
|
}).finally(() => {
|
|
18850
18906
|
inflight = null;
|
|
18851
18907
|
});
|
|
@@ -18858,7 +18914,8 @@ async function ensureFreshAccessToken() {
|
|
|
18858
18914
|
try {
|
|
18859
18915
|
const rotated = await runRefresh({ force: false });
|
|
18860
18916
|
return rotated.accessToken;
|
|
18861
|
-
} catch {
|
|
18917
|
+
} catch (err) {
|
|
18918
|
+
if (!isTerminalRefreshError(err)) throw err;
|
|
18862
18919
|
return void 0;
|
|
18863
18920
|
}
|
|
18864
18921
|
}
|
|
@@ -18868,7 +18925,8 @@ async function forceRefresh() {
|
|
|
18868
18925
|
try {
|
|
18869
18926
|
const rotated = await runRefresh({ force: true, failedAccessToken: credential.accessToken });
|
|
18870
18927
|
return rotated.accessToken;
|
|
18871
|
-
} catch {
|
|
18928
|
+
} catch (err) {
|
|
18929
|
+
if (!isTerminalRefreshError(err)) throw err;
|
|
18872
18930
|
return null;
|
|
18873
18931
|
}
|
|
18874
18932
|
}
|
|
@@ -18909,6 +18967,39 @@ function resolvePreferredOrgId() {
|
|
|
18909
18967
|
}
|
|
18910
18968
|
return config.getDefaultOrg();
|
|
18911
18969
|
}
|
|
18970
|
+
function mapRefreshFailure(cause) {
|
|
18971
|
+
if (cause instanceof ApiError2) return cause;
|
|
18972
|
+
if (cause instanceof RefreshMalformedResponseError) {
|
|
18973
|
+
return new ApiError2(
|
|
18974
|
+
502,
|
|
18975
|
+
`Unable to refresh Sylphx session: OAuth server returned an invalid response (${cause.message}). Your stored login was not cleared; retry or run \`sylphx doctor\`.`
|
|
18976
|
+
);
|
|
18977
|
+
}
|
|
18978
|
+
if (cause instanceof RefreshNetworkError) {
|
|
18979
|
+
return new ApiError2(
|
|
18980
|
+
503,
|
|
18981
|
+
`Unable to refresh Sylphx session: ${cause.message}. Your stored login was not cleared; retry or run \`sylphx doctor\`.`
|
|
18982
|
+
);
|
|
18983
|
+
}
|
|
18984
|
+
return new ApiError2(
|
|
18985
|
+
503,
|
|
18986
|
+
`Unable to refresh Sylphx session: ${cause instanceof Error ? cause.message : String(cause)}. Your stored login was not cleared; retry or run \`sylphx doctor\`.`
|
|
18987
|
+
);
|
|
18988
|
+
}
|
|
18989
|
+
function externalAuthRejectedMessage() {
|
|
18990
|
+
const auth = resolveAuthToken();
|
|
18991
|
+
if (auth.source === "token-file") {
|
|
18992
|
+
return "Authentication failed. The token from `SYLPHX_TOKEN_FILE` was rejected by the Sylphx API (HTTP 401). Rotate the service token or update the token file, then retry.";
|
|
18993
|
+
}
|
|
18994
|
+
if (auth.source === "env") {
|
|
18995
|
+
return "Authentication failed. `SYLPHX_TOKEN` was rejected by the Sylphx API (HTTP 401). Rotate the service token or OAuth access token, then retry.";
|
|
18996
|
+
}
|
|
18997
|
+
return "Authentication failed. The configured credential was rejected by the Sylphx API (HTTP 401). Run `sylphx doctor` to inspect the active auth source.";
|
|
18998
|
+
}
|
|
18999
|
+
function mapExternalAuthFailure(cause) {
|
|
19000
|
+
if (!(cause instanceof ApiError2) || cause.status !== 401 || !isExternalAuthActive()) return cause;
|
|
19001
|
+
return new ApiError2(401, externalAuthRejectedMessage(), cause.body);
|
|
19002
|
+
}
|
|
18912
19003
|
function getClient() {
|
|
18913
19004
|
const auth = resolveAuthToken();
|
|
18914
19005
|
const { token, source } = auth;
|
|
@@ -18929,14 +19020,27 @@ function withAuthedSdk(fn) {
|
|
|
18929
19020
|
}
|
|
18930
19021
|
async function withFreshAuth(fn) {
|
|
18931
19022
|
if (isExternalAuthActive()) {
|
|
18932
|
-
|
|
19023
|
+
try {
|
|
19024
|
+
return await fn();
|
|
19025
|
+
} catch (err) {
|
|
19026
|
+
throw mapExternalAuthFailure(err);
|
|
19027
|
+
}
|
|
19028
|
+
}
|
|
19029
|
+
try {
|
|
19030
|
+
await ensureFreshAccessToken();
|
|
19031
|
+
} catch (err) {
|
|
19032
|
+
throw mapRefreshFailure(err);
|
|
18933
19033
|
}
|
|
18934
|
-
await ensureFreshAccessToken();
|
|
18935
19034
|
try {
|
|
18936
19035
|
return await fn();
|
|
18937
19036
|
} catch (err) {
|
|
18938
19037
|
if (!(err instanceof ApiError2) || err.status !== 401) throw err;
|
|
18939
|
-
|
|
19038
|
+
let refreshed;
|
|
19039
|
+
try {
|
|
19040
|
+
refreshed = await forceRefresh();
|
|
19041
|
+
} catch (refreshErr) {
|
|
19042
|
+
throw mapRefreshFailure(refreshErr);
|
|
19043
|
+
}
|
|
18940
19044
|
if (!refreshed) {
|
|
18941
19045
|
throw new ApiError2(401, "Session expired. Run `sylphx login` again to re-authenticate.");
|
|
18942
19046
|
}
|
|
@@ -19011,11 +19115,18 @@ async function createLogStream(projectId, envType, options) {
|
|
|
19011
19115
|
params.set("envType", envType);
|
|
19012
19116
|
}
|
|
19013
19117
|
const preferredOrgId = options?.orgId ?? resolvePreferredOrgId();
|
|
19014
|
-
|
|
19118
|
+
let token;
|
|
19119
|
+
if (isExternalAuthActive()) {
|
|
19015
19120
|
const auth = resolveAuthToken();
|
|
19016
19121
|
if (!auth.token) throw new ApiError2(401, unauthenticatedMessage(auth));
|
|
19017
|
-
|
|
19018
|
-
}
|
|
19122
|
+
token = auth.token;
|
|
19123
|
+
} else {
|
|
19124
|
+
try {
|
|
19125
|
+
token = await ensureFreshAccessToken();
|
|
19126
|
+
} catch (err) {
|
|
19127
|
+
throw mapRefreshFailure(err);
|
|
19128
|
+
}
|
|
19129
|
+
}
|
|
19019
19130
|
if (!token) throw new ApiError2(401, unauthenticatedMessage());
|
|
19020
19131
|
return {
|
|
19021
19132
|
url: `${API_BASE}/projects/${encodeURIComponent(projectId)}/logs?${params.toString()}`,
|
|
@@ -38704,7 +38815,7 @@ var cli = Command70.run(root, {
|
|
|
38704
38815
|
version: package_default.version
|
|
38705
38816
|
});
|
|
38706
38817
|
cli(process.argv).pipe(
|
|
38707
|
-
Effect80.
|
|
38818
|
+
Effect80.catchAll(
|
|
38708
38819
|
(err) => Effect80.sync(() => {
|
|
38709
38820
|
const format = resolveErrorOutputFormat();
|
|
38710
38821
|
if (err instanceof CliCommandError) {
|