@buildinternet/uploads 0.26.0 → 0.26.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/LICENSE +202 -21
- package/dist/cli.js +5 -0
- package/dist/client.d.ts +5 -0
- package/dist/commands/config.js +6 -1
- package/dist/commands/login.js +25 -13
- package/dist/commands/session.js +7 -5
- package/dist/commands.js +4 -3
- package/dist/config-file.d.ts +1 -1
- package/dist/config-file.js +2 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +14 -0
- package/dist/format-bytes.d.ts +6 -2
- package/dist/format-bytes.js +19 -5
- package/dist/format-usage.d.ts +9 -0
- package/dist/format-usage.js +34 -5
- package/dist/session-cli-version.d.ts +15 -0
- package/dist/session-cli-version.js +85 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Build Internet
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ import { runReport } from "./commands/report.js";
|
|
|
19
19
|
import { runScreenshot } from "./commands/screenshot.js";
|
|
20
20
|
import { packageVersion } from "./package-version.js";
|
|
21
21
|
import { checkForUpdate, maybeHintUpdate } from "./update-check.js";
|
|
22
|
+
import { maybeSyncSessionCliVersion } from "./session-cli-version.js";
|
|
22
23
|
import { errorCodeFromUnknown, maybeShowFirstRunNotice, recordEvent, telemetryCommandName, } from "./telemetry.js";
|
|
23
24
|
async function writeRootHelp(options = {}) {
|
|
24
25
|
// Best-effort version check so the help header can show a banner when outdated.
|
|
@@ -197,6 +198,10 @@ export async function runCli(argv) {
|
|
|
197
198
|
const json = parsed.globals.json ?? false;
|
|
198
199
|
const quiet = parsed.globals.quiet ?? false;
|
|
199
200
|
apiUrl = resolveApiUrl(parsed.globals);
|
|
201
|
+
// Refresh session.cliVersion when the installed package changes (no-op without a session token).
|
|
202
|
+
if (parsed.command && parsed.command !== "login" && parsed.command !== "logout") {
|
|
203
|
+
maybeSyncSessionCliVersion({ apiUrl, envFile: parsed.globals.envFile });
|
|
204
|
+
}
|
|
200
205
|
if (parsed.globals.version) {
|
|
201
206
|
process.stdout.write(`${packageVersion()}\n`);
|
|
202
207
|
return 0;
|
package/dist/client.d.ts
CHANGED
|
@@ -291,6 +291,11 @@ export interface UsageResult {
|
|
|
291
291
|
uploadsRemaining?: number;
|
|
292
292
|
/** File scopes of the presented token (servers ≥ this field's release). */
|
|
293
293
|
scopes?: Array<TokenScope>;
|
|
294
|
+
/**
|
|
295
|
+
* Workspace plan catalog id (`free` | `pro`). Present on API workers that
|
|
296
|
+
* ship plan-aware usage; omitted on older servers.
|
|
297
|
+
*/
|
|
298
|
+
plan?: string;
|
|
294
299
|
}
|
|
295
300
|
export interface ReconcileResult {
|
|
296
301
|
workspace: string;
|
package/dist/commands/config.js
CHANGED
|
@@ -19,6 +19,7 @@ Keys:
|
|
|
19
19
|
UPLOADS_API_URL API base URL (default: ${DEFAULT_API_URL})
|
|
20
20
|
UPLOADS_WORKSPACE Workspace / bucket tenant (default: ${DEFAULT_WORKSPACE})
|
|
21
21
|
UPLOADS_TOKEN Bearer token for the workspace
|
|
22
|
+
UPLOADS_SESSION_TOKEN Device-flow session (CLI version on account sessions)
|
|
22
23
|
UPLOADS_DEFAULT_PREFIX Default key prefix for put/list
|
|
23
24
|
UPLOADS_DEFAULT_REPO Default repo segment for put
|
|
24
25
|
UPLOADS_DEFAULT_REF Default ref segment for put
|
|
@@ -195,7 +196,11 @@ Examples:
|
|
|
195
196
|
const path = flagString(parsed.flags, "--path") ?? resolveConfigPath({ envFile: opts.envFile });
|
|
196
197
|
const force = flagBool(parsed.flags, "--force");
|
|
197
198
|
const result = writeConfigKeys(path, { [key]: value }, { force });
|
|
198
|
-
const payload = {
|
|
199
|
+
const payload = {
|
|
200
|
+
...result,
|
|
201
|
+
key,
|
|
202
|
+
value: key === "UPLOADS_TOKEN" || key === "UPLOADS_SESSION_TOKEN" ? redactToken(value) : value,
|
|
203
|
+
};
|
|
199
204
|
if (opts.json)
|
|
200
205
|
writeJson(payload);
|
|
201
206
|
else
|
package/dist/commands/login.js
CHANGED
|
@@ -2,12 +2,13 @@ import { hostname } from "node:os";
|
|
|
2
2
|
import { createInterface } from "node:readline/promises";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { stdin, stdout } from "node:process";
|
|
5
|
-
import { loadConfigFile, redactToken, resolveConfigPath, writeConfigKeys, workspaceFromToken, } from "../config.js";
|
|
5
|
+
import { authUrlFromApi, loadConfigFile, redactToken, removeConfigKeys, resolveConfigPath, writeConfigKeys, workspaceFromToken, } from "../config.js";
|
|
6
6
|
import { createUploadsClient, createWorkspaceRequest, exchangeEnrollment, listMintWorkspaces, mintWorkspaceToken, requestDeviceCode, requestDeviceToken, } from "../client.js";
|
|
7
7
|
import { flagBool, flagString, parseCommandArgs, UsageError } from "../cli-args.js";
|
|
8
8
|
import { parseScopes } from "./admin-enrollment.js";
|
|
9
9
|
import { writeCommandHelp } from "../cli-style.js";
|
|
10
10
|
import { UploadsError } from "../errors.js";
|
|
11
|
+
import { syncSessionCliVersion } from "../session-cli-version.js";
|
|
11
12
|
const HELP = `uploads login [options]
|
|
12
13
|
|
|
13
14
|
Sign in and save workspace credentials. With no flags, opens a browser to
|
|
@@ -168,17 +169,7 @@ export function resolveAuthUrl(parsed, apiUrl) {
|
|
|
168
169
|
const explicit = flagString(parsed.flags, "--auth-url") ?? process.env.UPLOADS_AUTH_URL;
|
|
169
170
|
if (explicit)
|
|
170
171
|
return explicit.replace(/\/$/, "");
|
|
171
|
-
|
|
172
|
-
const url = new URL(apiUrl);
|
|
173
|
-
if (url.hostname.startsWith("api.")) {
|
|
174
|
-
url.hostname = `auth.${url.hostname.slice(4)}`;
|
|
175
|
-
return url.origin;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
// fall through to the default
|
|
180
|
-
}
|
|
181
|
-
return "https://auth.uploads.sh";
|
|
172
|
+
return authUrlFromApi(apiUrl);
|
|
182
173
|
}
|
|
183
174
|
/** Best-effort browser open. The URL is always printed too, so failures are silent. */
|
|
184
175
|
function openUrl(url) {
|
|
@@ -288,7 +279,13 @@ async function runDeviceLogin(parsed, opts, io) {
|
|
|
288
279
|
scopes,
|
|
289
280
|
label,
|
|
290
281
|
}).catch((err) => describeMintFailure(opts.apiUrl, session.accessToken, workspace, err));
|
|
291
|
-
return {
|
|
282
|
+
return {
|
|
283
|
+
workspace: minted.workspace,
|
|
284
|
+
token: minted.token,
|
|
285
|
+
apiUrl: opts.apiUrl,
|
|
286
|
+
sessionToken: session.accessToken,
|
|
287
|
+
authUrl: opts.authUrl,
|
|
288
|
+
};
|
|
292
289
|
}
|
|
293
290
|
function safeHostname() {
|
|
294
291
|
try {
|
|
@@ -408,9 +405,24 @@ export async function runLogin(args, opts, help = false, deviceIo = defaultDevic
|
|
|
408
405
|
UPLOADS_API_URL: savedApiUrl,
|
|
409
406
|
UPLOADS_WORKSPACE: result.workspace,
|
|
410
407
|
UPLOADS_TOKEN: result.token,
|
|
408
|
+
// Device login only — enables throttled session.cliVersion refresh.
|
|
409
|
+
...(result.sessionToken ? { UPLOADS_SESSION_TOKEN: result.sessionToken } : {}),
|
|
411
410
|
}, { force });
|
|
412
411
|
if (!["UPLOADS_API_URL", "UPLOADS_WORKSPACE", "UPLOADS_TOKEN"].every((key) => write.updated.includes(key)))
|
|
413
412
|
throw new UsageError("credentials were not fully written; retry with --force");
|
|
413
|
+
// Enrollment path: drop any stale device session so we don't heartbeat a dead token.
|
|
414
|
+
if (!result.sessionToken) {
|
|
415
|
+
removeConfigKeys(path, ["UPLOADS_SESSION_TOKEN"]);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
// Seed session.cliVersion immediately (don't wait for the next command).
|
|
419
|
+
await syncSessionCliVersion({
|
|
420
|
+
sessionToken: result.sessionToken,
|
|
421
|
+
authUrl: result.authUrl,
|
|
422
|
+
apiUrl: savedApiUrl,
|
|
423
|
+
force: true,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
414
426
|
const checked = !flagBool(parsed.flags, "--no-check");
|
|
415
427
|
let doctor = { ok: true, error: undefined };
|
|
416
428
|
if (checked) {
|
package/dist/commands/session.js
CHANGED
|
@@ -23,8 +23,9 @@ Examples:
|
|
|
23
23
|
`;
|
|
24
24
|
const LOGOUT_HELP = `uploads logout
|
|
25
25
|
|
|
26
|
-
Remove the saved UPLOADS_TOKEN
|
|
27
|
-
no longer signed in for the CLI. Does not
|
|
26
|
+
Remove the saved UPLOADS_TOKEN (and device session token) from the shared
|
|
27
|
+
config file so this machine is no longer signed in for the CLI. Does not
|
|
28
|
+
revoke tokens on the server.
|
|
28
29
|
|
|
29
30
|
Environment variables (UPLOADS_TOKEN) are not unset — export them yourself if set.
|
|
30
31
|
|
|
@@ -112,7 +113,7 @@ export async function runLogout(args, opts, help = false) {
|
|
|
112
113
|
const path = flagString(parsed.flags, "--path") ?? resolveConfigPath({ envFile: opts.envFile });
|
|
113
114
|
const hadFileToken = Boolean(loadConfigFile(path).UPLOADS_TOKEN);
|
|
114
115
|
const envTokenStillSet = Boolean(process.env.UPLOADS_TOKEN);
|
|
115
|
-
const result = removeConfigKeys(path, ["UPLOADS_TOKEN"]);
|
|
116
|
+
const result = removeConfigKeys(path, ["UPLOADS_TOKEN", "UPLOADS_SESSION_TOKEN"]);
|
|
116
117
|
const payload = {
|
|
117
118
|
path: result.path,
|
|
118
119
|
removed: result.removed,
|
|
@@ -124,8 +125,9 @@ export async function runLogout(args, opts, help = false) {
|
|
|
124
125
|
await writeJson(payload);
|
|
125
126
|
return 0;
|
|
126
127
|
}
|
|
127
|
-
if (result.removed.includes("UPLOADS_TOKEN")
|
|
128
|
-
|
|
128
|
+
if (result.removed.includes("UPLOADS_TOKEN") ||
|
|
129
|
+
result.removed.includes("UPLOADS_SESSION_TOKEN")) {
|
|
130
|
+
process.stdout.write(`signed out — removed credentials from ${result.path}\n`);
|
|
129
131
|
}
|
|
130
132
|
else if (!result.existed) {
|
|
131
133
|
process.stdout.write(`no config file at ${result.path} — already signed out\n`);
|
package/dist/commands.js
CHANGED
|
@@ -2424,9 +2424,10 @@ const USAGE_HELP = `uploads usage [--workspace <name>]
|
|
|
2424
2424
|
Show workspace storage and monthly upload counters.
|
|
2425
2425
|
|
|
2426
2426
|
When the API reports workspace quotas (typical on uploads.sh cloud /
|
|
2427
|
-
self-serve
|
|
2428
|
-
|
|
2429
|
-
|
|
2427
|
+
self-serve Free and Pro), human output includes the plan name and progress
|
|
2428
|
+
bars toward those caps. Free is not unlimited — storage and monthly upload
|
|
2429
|
+
limits show on the meters. Self-hosted or unlimited operator workspaces get
|
|
2430
|
+
usage totals only, plus a short unmetered note — no invented limits.
|
|
2430
2431
|
|
|
2431
2432
|
Examples:
|
|
2432
2433
|
uploads --env-file .env usage
|
package/dist/config-file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UploadsClientConfig } from "./config.js";
|
|
2
|
-
export declare const UPLOADS_CONFIG_KEYS: readonly ["UPLOADS_API_URL", "UPLOADS_WORKSPACE", "UPLOADS_TOKEN", "UPLOADS_DEFAULT_PREFIX", "UPLOADS_DEFAULT_REPO", "UPLOADS_DEFAULT_REF", "UPLOADS_DEFAULT_WIDTH", "UPLOADS_NO_GIT", "UPLOADS_NO_OPTIMIZE", "UPLOADS_KEEP_EXIF", "UPLOADS_NO_AUTO_META", "UPLOADS_SCREENSHOT_VIA", "UPLOADS_NO_NUDGE"];
|
|
2
|
+
export declare const UPLOADS_CONFIG_KEYS: readonly ["UPLOADS_API_URL", "UPLOADS_WORKSPACE", "UPLOADS_TOKEN", "UPLOADS_SESSION_TOKEN", "UPLOADS_DEFAULT_PREFIX", "UPLOADS_DEFAULT_REPO", "UPLOADS_DEFAULT_REF", "UPLOADS_DEFAULT_WIDTH", "UPLOADS_NO_GIT", "UPLOADS_NO_OPTIMIZE", "UPLOADS_KEEP_EXIF", "UPLOADS_NO_AUTO_META", "UPLOADS_SCREENSHOT_VIA", "UPLOADS_NO_NUDGE"];
|
|
3
3
|
export type UploadsConfigKey = (typeof UPLOADS_CONFIG_KEYS)[number];
|
|
4
4
|
export type UploadsConfigValues = Partial<Record<UploadsConfigKey, string>>;
|
|
5
5
|
export interface PutDefaults {
|
package/dist/config-file.js
CHANGED
|
@@ -5,6 +5,8 @@ export const UPLOADS_CONFIG_KEYS = [
|
|
|
5
5
|
"UPLOADS_API_URL",
|
|
6
6
|
"UPLOADS_WORKSPACE",
|
|
7
7
|
"UPLOADS_TOKEN",
|
|
8
|
+
/** Better Auth device-flow session bearer — keeps session.cliVersion fresh. */
|
|
9
|
+
"UPLOADS_SESSION_TOKEN",
|
|
8
10
|
"UPLOADS_DEFAULT_PREFIX",
|
|
9
11
|
"UPLOADS_DEFAULT_REPO",
|
|
10
12
|
"UPLOADS_DEFAULT_REF",
|
package/dist/config.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface UploadsClientConfig {
|
|
|
4
4
|
workspace: string;
|
|
5
5
|
token: string;
|
|
6
6
|
}
|
|
7
|
+
/** Derive auth origin from an API base (`api.` → `auth.`), else production default. */
|
|
8
|
+
export declare function authUrlFromApi(apiUrl: string): string;
|
|
7
9
|
export declare const DEFAULT_API_URL = "https://api.uploads.sh";
|
|
8
10
|
export declare const DEFAULT_WORKSPACE = "default";
|
|
9
11
|
/** Workspace encoded in minted tokens: `up_<workspace>_…` */
|
package/dist/config.js
CHANGED
|
@@ -2,6 +2,20 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { loadConfigFile, resolveConfigPath } from "./config-file.js";
|
|
3
3
|
import { UploadsError } from "./errors.js";
|
|
4
4
|
export { defaultConfigPath, resolveConfigPath, loadConfigFile, redactToken, writeConfigKeys, removeConfigKeys, configValuesFromClient, putDefaultsToConfigValues, resolvePutDefaults, mergePutDefaults, resolveScreenshotDefaults, UPLOADS_CONFIG_KEYS, } from "./config-file.js";
|
|
5
|
+
/** Derive auth origin from an API base (`api.` → `auth.`), else production default. */
|
|
6
|
+
export function authUrlFromApi(apiUrl) {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(apiUrl);
|
|
9
|
+
if (url.hostname.startsWith("api.")) {
|
|
10
|
+
url.hostname = `auth.${url.hostname.slice(4)}`;
|
|
11
|
+
return url.origin;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// fall through
|
|
16
|
+
}
|
|
17
|
+
return "https://auth.uploads.sh";
|
|
18
|
+
}
|
|
5
19
|
export const DEFAULT_API_URL = "https://api.uploads.sh";
|
|
6
20
|
export const DEFAULT_WORKSPACE = "default";
|
|
7
21
|
const TOKEN_WORKSPACE_RE = /^up_([a-z0-9][a-z0-9-]{1,62})_/;
|
package/dist/format-bytes.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Decimal (SI) human sizes for CLI output. Plan catalog caps are round decimal
|
|
3
|
+
* numbers (250 MB free, 10 GB pro); binary units made Free look like 238.4 MB.
|
|
4
|
+
* Used for usage meters, list sizes, optimize notes, and doctor — same base
|
|
5
|
+
* as apps/web `formatBytes` / `formatMarketedBytes`.
|
|
4
6
|
*/
|
|
5
7
|
export declare function formatByteSize(bytes: number): string;
|
|
8
|
+
/** Alias for call sites that want plan-cap wording; same SI formatter. */
|
|
9
|
+
export declare function formatMarketedBytes(bytes: number): string;
|
package/dist/format-bytes.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Decimal (SI) human sizes for CLI output. Plan catalog caps are round decimal
|
|
3
|
+
* numbers (250 MB free, 10 GB pro); binary units made Free look like 238.4 MB.
|
|
4
|
+
* Used for usage meters, list sizes, optimize notes, and doctor — same base
|
|
5
|
+
* as apps/web `formatBytes` / `formatMarketedBytes`.
|
|
4
6
|
*/
|
|
5
7
|
export function formatByteSize(bytes) {
|
|
6
8
|
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
7
9
|
return "0 B";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
if (bytes < 1000)
|
|
11
|
+
return `${Math.round(bytes)} B`;
|
|
12
|
+
const units = ["KB", "MB", "GB", "TB"];
|
|
13
|
+
let value = bytes / 1000;
|
|
14
|
+
let unit = 0;
|
|
15
|
+
while (value >= 1000 && unit < units.length - 1) {
|
|
16
|
+
value /= 1000;
|
|
17
|
+
unit += 1;
|
|
18
|
+
}
|
|
19
|
+
const rounded = value >= 10 ? Math.round(value) : Math.round(value * 10) / 10;
|
|
20
|
+
return `${rounded} ${units[unit]}`;
|
|
21
|
+
}
|
|
22
|
+
/** Alias for call sites that want plan-cap wording; same SI formatter. */
|
|
23
|
+
export function formatMarketedBytes(bytes) {
|
|
24
|
+
return formatByteSize(bytes);
|
|
11
25
|
}
|
package/dist/format-usage.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type UsageSnapshotLike = {
|
|
|
9
9
|
storageRemainingBytes?: number;
|
|
10
10
|
maxUploadsPerPeriod?: number;
|
|
11
11
|
uploadsRemaining?: number;
|
|
12
|
+
/** Catalog plan id when the API reports it (`free` | `pro`). */
|
|
13
|
+
plan?: string;
|
|
12
14
|
};
|
|
13
15
|
export type FormatUsageOptions = {
|
|
14
16
|
/** IANA zone or undefined for the host local zone. */
|
|
@@ -34,5 +36,12 @@ export declare function formatProgressBar(pct: number, opts?: {
|
|
|
34
36
|
}): string;
|
|
35
37
|
/** Host-local time by default; pass `timeZone` for stable tests. */
|
|
36
38
|
export declare function formatUsageTimestamp(iso: string, timeZone?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Display label for a plan catalog id. Free is shown too — free workspaces
|
|
41
|
+
* still have quotas (storage / monthly uploads) that usage meters report.
|
|
42
|
+
*/
|
|
43
|
+
export declare function planLabel(plan: string | undefined): string | null;
|
|
44
|
+
/** @deprecated use planLabel — kept as an alias for any external importers. */
|
|
45
|
+
export declare const paidPlanLabel: typeof planLabel;
|
|
37
46
|
/** Human-readable lines for `uploads usage` (not JSON). */
|
|
38
47
|
export declare function formatUsageHuman(result: UsageSnapshotLike, opts?: FormatUsageOptions): string[];
|
package/dist/format-usage.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* and operator workspaces usually omit them (unlimited). Progress bars only
|
|
8
8
|
* appear for fields that have a positive cap — never invent a budget.
|
|
9
9
|
*/
|
|
10
|
-
import { formatByteSize } from "./format-bytes.js";
|
|
10
|
+
import { formatByteSize, formatMarketedBytes } from "./format-bytes.js";
|
|
11
11
|
import { BRAND } from "./cli-brand.js";
|
|
12
12
|
/** True when the API reported any cumulative workspace quota. */
|
|
13
13
|
export function isUsageMetered(result) {
|
|
@@ -87,17 +87,39 @@ export function formatUsageTimestamp(iso, timeZone) {
|
|
|
87
87
|
return iso;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Display label for a plan catalog id. Free is shown too — free workspaces
|
|
92
|
+
* still have quotas (storage / monthly uploads) that usage meters report.
|
|
93
|
+
*/
|
|
94
|
+
export function planLabel(plan) {
|
|
95
|
+
if (!plan)
|
|
96
|
+
return null;
|
|
97
|
+
if (plan === "free")
|
|
98
|
+
return "Free";
|
|
99
|
+
if (plan === "pro")
|
|
100
|
+
return "Pro";
|
|
101
|
+
// Future tiers: title-case the id rather than hiding them.
|
|
102
|
+
return plan.charAt(0).toUpperCase() + plan.slice(1);
|
|
103
|
+
}
|
|
104
|
+
/** @deprecated use planLabel — kept as an alias for any external importers. */
|
|
105
|
+
export const paidPlanLabel = planLabel;
|
|
90
106
|
/** Human-readable lines for `uploads usage` (not JSON). */
|
|
91
107
|
export function formatUsageHuman(result, opts = {}) {
|
|
92
108
|
const width = opts.barWidth ?? 20;
|
|
93
109
|
const color = opts.color === true;
|
|
94
110
|
const metered = isUsageMetered(result);
|
|
95
111
|
const lines = [`workspace: ${result.workspace}`];
|
|
112
|
+
const label = planLabel(result.plan);
|
|
113
|
+
if (label)
|
|
114
|
+
lines.push(`plan: ${label}`);
|
|
96
115
|
const storagePct = usagePct(result.bytes, result.maxStorageBytes);
|
|
97
116
|
if (storagePct !== null && result.maxStorageBytes != null) {
|
|
98
|
-
|
|
117
|
+
// Caps (and remaining-against-cap) use SI marketed formatting so Free's
|
|
118
|
+
// 250_000_000 reads as "250 MB", not binary "238.4 MB". Used bytes share
|
|
119
|
+
// the same base on this line so the three numbers stay coherent.
|
|
120
|
+
const detail = `${formatMarketedBytes(result.bytes)} / ${formatMarketedBytes(result.maxStorageBytes)}` +
|
|
99
121
|
(result.storageRemainingBytes != null
|
|
100
|
-
? ` (${
|
|
122
|
+
? ` (${formatMarketedBytes(result.storageRemainingBytes)} free)`
|
|
101
123
|
: "");
|
|
102
124
|
const bar = formatProgressBar(storagePct, { width, color });
|
|
103
125
|
lines.push(`storage: ${bar} ${detail}`);
|
|
@@ -118,8 +140,15 @@ export function formatUsageHuman(result, opts = {}) {
|
|
|
118
140
|
}
|
|
119
141
|
lines.push(`updated: ${formatUsageTimestamp(result.updatedAt, opts.timeZone)}`);
|
|
120
142
|
if (!metered) {
|
|
121
|
-
// Self-host / operator unlimited
|
|
122
|
-
|
|
143
|
+
// Self-host / operator unlimited, or a plan without reported caps.
|
|
144
|
+
// Free self-serve normally reports maxStorageBytes / maxUploadsPerPeriod;
|
|
145
|
+
// when those are missing, say so explicitly rather than implying unlimited free.
|
|
146
|
+
if (result.plan === "free") {
|
|
147
|
+
lines.push("note: free plan — no quotas reported for this workspace (limits may still apply server-side)");
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
lines.push("note: unmetered — no storage or upload quotas on this workspace");
|
|
151
|
+
}
|
|
123
152
|
}
|
|
124
153
|
return lines;
|
|
125
154
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SyncCliVersionOptions {
|
|
2
|
+
sessionToken?: string;
|
|
3
|
+
authUrl?: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
envFile?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
/** Skip the local "already synced this version" short-circuit. */
|
|
8
|
+
force?: boolean;
|
|
9
|
+
cachePath?: string;
|
|
10
|
+
fetchImpl?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
/** Best-effort POST; never throws. */
|
|
13
|
+
export declare function syncSessionCliVersion(opts?: SyncCliVersionOptions): Promise<boolean>;
|
|
14
|
+
/** Fire-and-forget for CLI command starts. */
|
|
15
|
+
export declare function maybeSyncSessionCliVersion(opts?: SyncCliVersionOptions): void;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep Better Auth session.cliVersion in sync with the installed package.
|
|
3
|
+
*
|
|
4
|
+
* Device login stores UPLOADS_SESSION_TOKEN; later commands POST
|
|
5
|
+
* /api/auth/update-session when the local version changes (fire-and-forget).
|
|
6
|
+
*/
|
|
7
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { authUrlFromApi } from "./config.js";
|
|
11
|
+
import { loadConfigFile, removeConfigKeys, resolveConfigPath } from "./config-file.js";
|
|
12
|
+
import { packageVersion } from "./package-version.js";
|
|
13
|
+
const POST_TIMEOUT_MS = 1500;
|
|
14
|
+
function defaultCachePath() {
|
|
15
|
+
const base = process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
|
|
16
|
+
return join(base, "uploads", "cli-version-sync");
|
|
17
|
+
}
|
|
18
|
+
function readLastSyncedVersion(path) {
|
|
19
|
+
try {
|
|
20
|
+
const v = readFileSync(path, "utf8").trim();
|
|
21
|
+
return v || undefined;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function writeLastSyncedVersion(path, version) {
|
|
28
|
+
try {
|
|
29
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
30
|
+
writeFileSync(path, version + "\n", { mode: 0o600 });
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// best-effort
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Best-effort POST; never throws. */
|
|
37
|
+
export async function syncSessionCliVersion(opts = {}) {
|
|
38
|
+
const version = opts.version ?? packageVersion();
|
|
39
|
+
const configPath = resolveConfigPath({ envFile: opts.envFile });
|
|
40
|
+
const fromFile = loadConfigFile(configPath);
|
|
41
|
+
const sessionToken = opts.sessionToken ?? fromFile.UPLOADS_SESSION_TOKEN;
|
|
42
|
+
if (!sessionToken)
|
|
43
|
+
return false;
|
|
44
|
+
const cachePath = opts.cachePath ?? defaultCachePath();
|
|
45
|
+
if (!opts.force && readLastSyncedVersion(cachePath) === version)
|
|
46
|
+
return true;
|
|
47
|
+
const apiUrl = opts.apiUrl ?? fromFile.UPLOADS_API_URL ?? process.env.UPLOADS_API_URL;
|
|
48
|
+
const authUrl = (opts.authUrl ??
|
|
49
|
+
process.env.UPLOADS_AUTH_URL ??
|
|
50
|
+
(apiUrl ? authUrlFromApi(apiUrl) : "https://auth.uploads.sh")).replace(/\/$/, "");
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timer = setTimeout(() => controller.abort(), POST_TIMEOUT_MS);
|
|
53
|
+
try {
|
|
54
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
55
|
+
const res = await fetchImpl(`${authUrl}/api/auth/update-session`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
60
|
+
"User-Agent": `@buildinternet/uploads/${version} (session-version)`,
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify({ cliVersion: version }),
|
|
63
|
+
signal: controller.signal,
|
|
64
|
+
});
|
|
65
|
+
if (res.ok) {
|
|
66
|
+
writeLastSyncedVersion(cachePath, version);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
// Stale session: drop it so we stop retrying every command.
|
|
70
|
+
if (res.status === 401 || res.status === 403) {
|
|
71
|
+
removeConfigKeys(configPath, ["UPLOADS_SESSION_TOKEN"]);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Fire-and-forget for CLI command starts. */
|
|
83
|
+
export function maybeSyncSessionCliVersion(opts = {}) {
|
|
84
|
+
void syncSessionCliVersion(opts);
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildinternet/uploads",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "CLI and client for uploads.sh — workspace-scoped image hosting for GitHub embeds",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/buildinternet/uploads.git",
|