@getrouter/getrouter-cli 0.1.6 → 0.1.8

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/dist/bin.mjs CHANGED
@@ -8,7 +8,7 @@ import { randomInt } from "node:crypto";
8
8
  import prompts from "prompts";
9
9
 
10
10
  //#region package.json
11
- var version = "0.1.5";
11
+ var version = "0.1.8";
12
12
 
13
13
  //#endregion
14
14
  //#region src/generated/router/dashboard/v1/index.ts
@@ -29,6 +29,25 @@ function createSubscriptionServiceClient(handler) {
29
29
  });
30
30
  } };
31
31
  }
32
+ function createUsageServiceClient(handler) {
33
+ return { ListUsage(request) {
34
+ const path$1 = `v1/dashboard/usages`;
35
+ const body = null;
36
+ const queryParams = [];
37
+ if (request.pageSize) queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`);
38
+ if (request.pageToken) queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`);
39
+ let uri = path$1;
40
+ if (queryParams.length > 0) uri += `?${queryParams.join("&")}`;
41
+ return handler({
42
+ path: uri,
43
+ method: "GET",
44
+ body
45
+ }, {
46
+ service: "UsageService",
47
+ method: "ListUsage"
48
+ });
49
+ } };
50
+ }
32
51
  function createConsumerServiceClient(handler) {
33
52
  return {
34
53
  CreateConsumer(request) {
@@ -113,6 +132,26 @@ function createConsumerServiceClient(handler) {
113
132
  }
114
133
  };
115
134
  }
135
+ function createModelServiceClient(handler) {
136
+ return { ListModels(request) {
137
+ const path$1 = `v1/dashboard/models`;
138
+ const body = null;
139
+ const queryParams = [];
140
+ if (request.pageSize) queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`);
141
+ if (request.pageToken) queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`);
142
+ if (request.filter) queryParams.push(`filter=${encodeURIComponent(request.filter.toString())}`);
143
+ let uri = path$1;
144
+ if (queryParams.length > 0) uri += `?${queryParams.join("&")}`;
145
+ return handler({
146
+ path: uri,
147
+ method: "GET",
148
+ body
149
+ }, {
150
+ service: "ModelService",
151
+ method: "ListModels"
152
+ });
153
+ } };
154
+ }
116
155
  function createAuthServiceClient(handler) {
117
156
  return {
118
157
  Authorize(request) {
@@ -162,45 +201,6 @@ function createAuthServiceClient(handler) {
162
201
  }
163
202
  };
164
203
  }
165
- function createModelServiceClient(handler) {
166
- return { ListModels(request) {
167
- const path$1 = `v1/dashboard/models`;
168
- const body = null;
169
- const queryParams = [];
170
- if (request.pageSize) queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`);
171
- if (request.pageToken) queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`);
172
- if (request.filter) queryParams.push(`filter=${encodeURIComponent(request.filter.toString())}`);
173
- let uri = path$1;
174
- if (queryParams.length > 0) uri += `?${queryParams.join("&")}`;
175
- return handler({
176
- path: uri,
177
- method: "GET",
178
- body
179
- }, {
180
- service: "ModelService",
181
- method: "ListModels"
182
- });
183
- } };
184
- }
185
- function createUsageServiceClient(handler) {
186
- return { ListUsage(request) {
187
- const path$1 = `v1/dashboard/usages`;
188
- const body = null;
189
- const queryParams = [];
190
- if (request.pageSize) queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`);
191
- if (request.pageToken) queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`);
192
- let uri = path$1;
193
- if (queryParams.length > 0) uri += `?${queryParams.join("&")}`;
194
- return handler({
195
- path: uri,
196
- method: "GET",
197
- body
198
- }, {
199
- service: "UsageService",
200
- method: "ListUsage"
201
- });
202
- } };
203
- }
204
204
 
205
205
  //#endregion
206
206
  //#region src/core/config/fs.ts
@@ -445,32 +445,39 @@ const generateAuthCode = () => {
445
445
  for (let i = 0; i < 13; i += 1) out += alphabet[randomInt(32)];
446
446
  return out;
447
447
  };
448
- const buildLoginUrl = (authCode) => `https://getrouter.dev/#/a/${authCode}`;
448
+ const buildLoginUrl = (authCode) => `https://getrouter.dev/auth/${authCode}`;
449
+ const spawnBrowser = (command, args) => {
450
+ try {
451
+ const child = spawn(command, args, {
452
+ stdio: "ignore",
453
+ detached: true
454
+ });
455
+ child.on("error", (err) => {
456
+ const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
457
+ const reason = code === "ENOENT" ? ` (${command} not found)` : code ? ` (${code})` : "";
458
+ console.log(`⚠️ Unable to open browser${reason}. Please open the URL manually.`);
459
+ });
460
+ child.unref();
461
+ } catch {
462
+ console.log("⚠️ Unable to open browser. Please open the URL manually.");
463
+ }
464
+ };
449
465
  const openLoginUrl = async (url) => {
450
466
  try {
451
467
  if (process.platform === "darwin") {
452
- spawn("open", [url], {
453
- stdio: "ignore",
454
- detached: true
455
- }).unref();
468
+ spawnBrowser("open", [url]);
456
469
  return;
457
470
  }
458
471
  if (process.platform === "win32") {
459
- spawn("cmd", [
472
+ spawnBrowser("cmd", [
460
473
  "/c",
461
474
  "start",
462
475
  "",
463
476
  url
464
- ], {
465
- stdio: "ignore",
466
- detached: true
467
- }).unref();
477
+ ]);
468
478
  return;
469
479
  }
470
- spawn("xdg-open", [url], {
471
- stdio: "ignore",
472
- detached: true
473
- }).unref();
480
+ spawnBrowser("xdg-open", [url]);
474
481
  } catch {}
475
482
  };
476
483
  const pollAuthorize = async ({ authorize, code, timeoutMs = 300 * 1e3, initialDelayMs = 1e3, maxDelayMs = 1e4, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), now = () => Date.now(), onRetry }) => {
@@ -6,7 +6,7 @@
6
6
 
7
7
  现有 CLI 的 `auth login` 仅提示 OAuth 未就绪。根据最新 auth 流程,CLI 需改为类似 tailscale 的设备码式登录:
8
8
  - CLI 本地生成 `auth_code`(13 位小写 base32)
9
- - 打开浏览器访问 `https://getrouter.dev/#/a/{auth_code}`
9
+ - 打开浏览器访问 `https://getrouter.dev/auth/{auth_code}`
10
10
  - CLI 轮询 `POST /v1/dashboard/auth/authorize`,body `{ code: auth_code }`
11
11
  - 成功返回 `AuthToken` 后写入 `~/.getrouter/auth.json`
12
12
 
@@ -42,7 +42,7 @@
42
42
 
43
43
  ```
44
44
  To authenticate, visit:
45
- https://getrouter.dev/#/a/<auth_code>
45
+ https://getrouter.dev/auth/<auth_code>
46
46
  Waiting for confirmation...
47
47
  ```
48
48
 
@@ -222,7 +222,7 @@ export const generateAuthCode = () => {
222
222
  };
223
223
 
224
224
  export const buildLoginUrl = (authCode: string) =>
225
- `https://getrouter.dev/#/a/${authCode}`;
225
+ `https://getrouter.dev/auth/${authCode}`;
226
226
 
227
227
  export const openLoginUrl = async (url: string) => {
228
228
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getrouter/getrouter-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "CLI for getrouter.dev",
6
6
  "bin": {
@@ -31,31 +31,46 @@ export const generateAuthCode = () => {
31
31
  };
32
32
 
33
33
  export const buildLoginUrl = (authCode: string) =>
34
- `https://getrouter.dev/#/a/${authCode}`;
34
+ `https://getrouter.dev/auth/${authCode}`;
35
+
36
+ const spawnBrowser = (command: string, args: string[]) => {
37
+ try {
38
+ const child = spawn(command, args, {
39
+ stdio: "ignore",
40
+ detached: true,
41
+ });
42
+ child.on("error", (err) => {
43
+ const code =
44
+ typeof err === "object" && err !== null && "code" in err
45
+ ? (err as { code?: string }).code
46
+ : undefined;
47
+ const reason =
48
+ code === "ENOENT"
49
+ ? ` (${command} not found)`
50
+ : code
51
+ ? ` (${code})`
52
+ : "";
53
+ console.log(
54
+ `⚠️ Unable to open browser${reason}. Please open the URL manually.`,
55
+ );
56
+ });
57
+ child.unref();
58
+ } catch {
59
+ console.log("⚠️ Unable to open browser. Please open the URL manually.");
60
+ }
61
+ };
35
62
 
36
63
  export const openLoginUrl = async (url: string) => {
37
64
  try {
38
65
  if (process.platform === "darwin") {
39
- const child = spawn("open", [url], {
40
- stdio: "ignore",
41
- detached: true,
42
- });
43
- child.unref();
66
+ spawnBrowser("open", [url]);
44
67
  return;
45
68
  }
46
69
  if (process.platform === "win32") {
47
- const child = spawn("cmd", ["/c", "start", "", url], {
48
- stdio: "ignore",
49
- detached: true,
50
- });
51
- child.unref();
70
+ spawnBrowser("cmd", ["/c", "start", "", url]);
52
71
  return;
53
72
  }
54
- const child = spawn("xdg-open", [url], {
55
- stdio: "ignore",
56
- detached: true,
57
- });
58
- child.unref();
73
+ spawnBrowser("xdg-open", [url]);
59
74
  } catch {
60
75
  // best effort
61
76
  }