@irtio/cli 0.5.2 → 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.
Files changed (37) hide show
  1. package/dist/api.d.ts +52 -0
  2. package/dist/api.js +15 -0
  3. package/dist/bundle.js +1 -1
  4. package/dist/{chunk-GBNHBWES.js → chunk-3HQMVCYA.js} +10 -6
  5. package/dist/{chunk-32QTPKVT.js → chunk-DKWG7MGO.js} +1 -1
  6. package/dist/{chunk-KRQUAEN2.js → chunk-OTSFRVJN.js} +12 -6
  7. package/dist/chunk-RNAH5T4W.js +96 -0
  8. package/dist/chunk-RQSJZWQC.js +452 -0
  9. package/dist/chunk-UPHQM6NZ.js +72 -0
  10. package/dist/chunk-ZD4ND6X6.js +31 -0
  11. package/dist/chunk-ZK5JLUD4.js +94 -0
  12. package/dist/credentials.d.ts +61 -0
  13. package/dist/credentials.js +20 -0
  14. package/dist/delete-project-VENS2B44.js +118 -0
  15. package/dist/deploy.d.ts +149 -0
  16. package/dist/{deploy-3SABPL3T.js → deploy.js} +166 -44
  17. package/dist/{dev-QJOGXLKM.js → dev-QM26ONKS.js} +2957 -231
  18. package/dist/index.js +97 -25
  19. package/dist/init.d.ts +1 -1
  20. package/dist/init.js +20 -4
  21. package/dist/{keys-XBORZAPI.js → keys-JHLMEGRA.js} +8 -4
  22. package/dist/leaderboard-SYPSBPS3.js +352 -0
  23. package/dist/{login-3EXB4CGX.js → login-2M73HBZT.js} +12 -5
  24. package/dist/{logs-2EOXLNWF.js → logs-2W7CPZO5.js} +9 -5
  25. package/dist/{migrate-WUO2GBMX.js → migrate-T3DZJREY.js} +12 -8
  26. package/dist/ratings-VG32WFDG.js +297 -0
  27. package/dist/{rollback-GA6UY772.js → rollback-SO74MVZV.js} +9 -5
  28. package/dist/{rooms-B66LQIIF.js → rooms-VI33P4RA.js} +36 -10
  29. package/dist/simulate.d.ts +147 -4
  30. package/dist/simulate.js +680 -53
  31. package/dist/{static-deploy-5TBH4VNA.js → static-deploy-KOWFKWZA.js} +6 -4
  32. package/dist/status-HF3ZEKB7.js +219 -0
  33. package/dist/usage-4G23QXCH.js +213 -0
  34. package/dist/{whoami-CI5D5RCC.js → whoami-KTMTQNHM.js} +8 -4
  35. package/package.json +23 -7
  36. package/dist/chunk-BPE452KF.js +0 -180
  37. package/dist/chunk-TV66QHFP.js +0 -167
@@ -1,167 +0,0 @@
1
- // src/credentials.ts
2
- import { existsSync } from "fs";
3
- import { chmod, mkdir, readFile, writeFile } from "fs/promises";
4
- import * as os from "os";
5
- import * as path from "path";
6
- function credentialsPath() {
7
- if (process.env.IRT_CREDENTIALS_FILE) return process.env.IRT_CREDENTIALS_FILE;
8
- if (process.platform === "win32") {
9
- const appData = process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming");
10
- return path.join(appData, "irtio", "credentials.json");
11
- }
12
- return path.join(os.homedir(), ".config", "irtio", "credentials.json");
13
- }
14
- async function readCredentials() {
15
- const file = credentialsPath();
16
- if (!existsSync(file)) return {};
17
- try {
18
- const raw = await readFile(file, "utf8");
19
- const parsed = JSON.parse(raw);
20
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
21
- return parsed;
22
- } catch {
23
- return {};
24
- }
25
- }
26
- async function readCredential(controlUrl) {
27
- const all = await readCredentials();
28
- return all[controlUrl];
29
- }
30
- async function writeCredential(controlUrl, credential) {
31
- const file = credentialsPath();
32
- await mkdir(path.dirname(file), { recursive: true });
33
- const all = await readCredentials();
34
- all[controlUrl] = credential;
35
- await writeFile(file, `${JSON.stringify(all, null, 2)}
36
- `, { mode: 384 });
37
- await chmod(file, 384).catch(() => {
38
- });
39
- return file;
40
- }
41
- var DEFAULT_CONTROL_URL = "https://control.irt.io";
42
- function resolveControlUrl(flag) {
43
- return flag ?? process.env.IRT_CONTROL_URL ?? DEFAULT_CONTROL_URL;
44
- }
45
- async function resolveControlUrlForUser(flag) {
46
- const explicit = flag ?? process.env.IRT_CONTROL_URL;
47
- if (explicit !== void 0) return explicit;
48
- const all = await readCredentials();
49
- const now = Date.now();
50
- const live = Object.entries(all).filter(([, cred]) => new Date(cred.expiresAt).getTime() > now).map(([url]) => url);
51
- const urls = live.length > 0 ? live : Object.keys(all);
52
- return urls.length === 1 ? urls[0] : DEFAULT_CONTROL_URL;
53
- }
54
-
55
- // src/api-client.ts
56
- var ApiClientError = class extends Error {
57
- name = "ApiClientError";
58
- status;
59
- code;
60
- changes;
61
- hint;
62
- constructor(status, body) {
63
- super(body.message);
64
- this.status = status;
65
- this.code = body.code;
66
- this.changes = body.changes;
67
- this.hint = body.hint;
68
- }
69
- };
70
- var NotLoggedInError = class extends Error {
71
- constructor(controlUrl) {
72
- super(`not logged in to ${controlUrl} \u2014 run: irtio login`);
73
- this.controlUrl = controlUrl;
74
- }
75
- controlUrl;
76
- name = "NotLoggedInError";
77
- };
78
- async function createApiClient(controlUrl) {
79
- const credential = await readCredential(controlUrl);
80
- if (!credential) throw new NotLoggedInError(controlUrl);
81
- return createApiClientWithToken(controlUrl, credential.token);
82
- }
83
- function createApiClientWithToken(controlUrl, token) {
84
- async function request(method, path2, init = {}) {
85
- const headers = {
86
- Authorization: `Bearer ${token}`,
87
- Accept: "application/json"
88
- };
89
- let requestBody;
90
- if (init.bytes !== void 0) {
91
- headers["content-type"] = "application/octet-stream";
92
- requestBody = init.bytes;
93
- } else if (init.body !== void 0) {
94
- headers["content-type"] = "application/json";
95
- requestBody = JSON.stringify(init.body);
96
- }
97
- const response = await fetch(`${controlUrl}${path2}`, {
98
- method,
99
- headers,
100
- ...requestBody !== void 0 ? { body: requestBody } : {}
101
- });
102
- const text = await response.text();
103
- const parsed = text.length > 0 ? JSON.parse(text) : void 0;
104
- if (!response.ok) {
105
- const body = parsed !== void 0 && typeof parsed === "object" && parsed !== null && "code" in parsed && "message" in parsed ? parsed : {
106
- code: "E_UNKNOWN",
107
- message: text || `${method} ${path2} failed with ${response.status}`
108
- };
109
- throw new ApiClientError(response.status, body);
110
- }
111
- return parsed;
112
- }
113
- return {
114
- controlUrl,
115
- get(path2, query) {
116
- const qs = query ? Object.entries(query).filter((e) => e[1] !== void 0).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&") : "";
117
- return request("GET", qs ? `${path2}?${qs}` : path2);
118
- },
119
- post(path2, body) {
120
- return request("POST", path2, { body });
121
- },
122
- patch(path2, body) {
123
- return request("PATCH", path2, { body });
124
- },
125
- postBytes(path2, bytes) {
126
- return request("POST", path2, { bytes });
127
- }
128
- };
129
- }
130
- function isLoginRequired(err) {
131
- return err instanceof NotLoggedInError || err instanceof ApiClientError && err.status === 401;
132
- }
133
-
134
- // src/help.ts
135
- function helpRequested(args) {
136
- return args.some((arg) => arg === "--help" || arg === "-h");
137
- }
138
- var HelpRequested = class extends Error {
139
- constructor(usage) {
140
- super(usage);
141
- this.usage = usage;
142
- }
143
- usage;
144
- name = "HelpRequested";
145
- };
146
- function helpFor(usage) {
147
- return new HelpRequested(usage);
148
- }
149
- function trailerFor(err, hints = []) {
150
- if (err instanceof ApiClientError && err.hint !== void 0 && err.hint !== "") return err.hint;
151
- const grounded = hints.filter((h) => h !== "");
152
- return grounded.length > 0 ? grounded.join("\n") : void 0;
153
- }
154
-
155
- export {
156
- credentialsPath,
157
- writeCredential,
158
- resolveControlUrl,
159
- resolveControlUrlForUser,
160
- ApiClientError,
161
- createApiClient,
162
- isLoginRequired,
163
- helpRequested,
164
- HelpRequested,
165
- helpFor,
166
- trailerFor
167
- };