@getpaseo/cli 0.3.0 → 0.3.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.
Files changed (41) hide show
  1. package/dist/commands/hub/authority.d.ts +17 -0
  2. package/dist/commands/hub/authority.js +18 -0
  3. package/dist/commands/hub/client.d.ts +55 -3
  4. package/dist/commands/hub/client.js +158 -38
  5. package/dist/commands/hub/connect.d.ts +21 -0
  6. package/dist/commands/hub/connect.js +34 -0
  7. package/dist/commands/hub/credentials.d.ts +21 -0
  8. package/dist/commands/hub/credentials.js +143 -0
  9. package/dist/commands/hub/daemon-client.d.ts +27 -0
  10. package/dist/commands/hub/daemon-client.js +14 -0
  11. package/dist/commands/hub/deploy-input.js +28 -28
  12. package/dist/commands/hub/deploy.d.ts +23 -3
  13. package/dist/commands/hub/deploy.js +51 -42
  14. package/dist/commands/hub/disconnect.d.ts +16 -0
  15. package/dist/commands/hub/disconnect.js +24 -0
  16. package/dist/commands/hub/error.d.ts +1 -1
  17. package/dist/commands/hub/error.js +2 -2
  18. package/dist/commands/hub/help.d.ts +3 -0
  19. package/dist/commands/hub/help.js +5 -0
  20. package/dist/commands/hub/index.d.ts +15 -25
  21. package/dist/commands/hub/index.js +64 -74
  22. package/dist/commands/hub/{device-authorization.d.ts → login-flow.d.ts} +12 -15
  23. package/dist/commands/hub/login-flow.js +78 -0
  24. package/dist/commands/hub/login.d.ts +21 -0
  25. package/dist/commands/hub/login.js +34 -0
  26. package/dist/commands/hub/logout.d.ts +31 -0
  27. package/dist/commands/hub/logout.js +65 -0
  28. package/dist/commands/hub/origin.d.ts +2 -0
  29. package/dist/commands/hub/origin.js +27 -0
  30. package/dist/commands/hub/projects.d.ts +24 -0
  31. package/dist/commands/hub/projects.js +49 -0
  32. package/dist/commands/hub/reporter.d.ts +10 -0
  33. package/dist/commands/hub/reporter.js +11 -0
  34. package/dist/commands/hub/status-output.d.ts +13 -0
  35. package/dist/commands/hub/status-output.js +30 -0
  36. package/dist/commands/schedule/types.d.ts +1 -4
  37. package/dist/output/types.d.ts +1 -1
  38. package/package.json +4 -4
  39. package/dist/commands/hub/cloud-device-authorization.d.ts +0 -45
  40. package/dist/commands/hub/cloud-device-authorization.js +0 -92
  41. package/dist/commands/hub/device-authorization.js +0 -87
@@ -1,87 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { platform } from "node:os";
3
- import { CloudDeviceAuthorizationClient, } from "./cloud-device-authorization.js";
4
- export class SystemBrowser {
5
- constructor(options = {}) {
6
- this.hostPlatform = options.hostPlatform ?? platform();
7
- this.launch = options.launch ?? launchDetached;
8
- }
9
- async open(url) {
10
- if (this.hostPlatform === "win32") {
11
- await this.launch("rundll32.exe", ["url.dll,FileProtocolHandler", url]);
12
- return;
13
- }
14
- await this.launch(this.hostPlatform === "darwin" ? "open" : "xdg-open", [url]);
15
- }
16
- }
17
- export class DeviceAuthorizationWorkflow {
18
- constructor(options) {
19
- this.options = options;
20
- }
21
- async authorize(hubUrl, displayName) {
22
- const authorization = await this.options.cloud.start(hubUrl, displayName);
23
- this.options.reporter.instructions(authorization.verificationUri, authorization.userCode);
24
- if (this.options.openBrowser !== false) {
25
- await this.options.browser.open(authorization.verificationUriComplete).catch(() => undefined);
26
- }
27
- let interval = authorization.interval;
28
- const expiresAt = Date.parse(authorization.expiresAt);
29
- while (true) {
30
- const remaining = expiresAt - this.options.waiter.now();
31
- if (remaining <= 0)
32
- throw new Error("Daemon registration expired");
33
- await this.options.waiter.wait(Math.min(interval * 1000, remaining));
34
- if (this.options.waiter.now() >= expiresAt)
35
- throw new Error("Daemon registration expired");
36
- const pollLifetime = expiresAt - this.options.waiter.now();
37
- if (pollLifetime <= 0)
38
- throw new Error("Daemon registration expired");
39
- const outcome = await this.options.cloud.poll(hubUrl, authorization.deviceCode, pollLifetime);
40
- if (this.options.waiter.now() >= expiresAt)
41
- throw new Error("Daemon registration expired");
42
- if (outcome.status === "retry_later")
43
- continue;
44
- interval = outcome.interval;
45
- if (outcome.status === "approved")
46
- return outcome.enrollmentToken;
47
- if (outcome.status === "denied")
48
- throw new Error("Daemon registration was denied");
49
- if (outcome.status === "expired")
50
- throw new Error("Daemon registration expired");
51
- if (outcome.status === "enrolled") {
52
- throw new Error("Daemon registration was already used");
53
- }
54
- }
55
- }
56
- }
57
- export function createDeviceAuthorizationWorkflow() {
58
- return new DeviceAuthorizationWorkflow({
59
- cloud: new CloudDeviceAuthorizationClient(),
60
- waiter: {
61
- wait: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)),
62
- now: Date.now,
63
- },
64
- browser: new SystemBrowser(),
65
- reporter: {
66
- instructions(verificationUri, userCode) {
67
- process.stderr.write(`Open ${verificationUri} and enter code ${userCode}\n`);
68
- },
69
- },
70
- openBrowser: process.stderr.isTTY === true,
71
- });
72
- }
73
- async function launchDetached(command, args) {
74
- await new Promise((resolve, reject) => {
75
- const child = spawn(command, args, {
76
- detached: true,
77
- shell: false,
78
- stdio: "ignore",
79
- });
80
- child.once("spawn", () => {
81
- child.unref();
82
- resolve();
83
- });
84
- child.once("error", reject);
85
- });
86
- }
87
- //# sourceMappingURL=device-authorization.js.map