@project-ajax/cli 0.0.10 → 0.0.11

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.
@@ -1,4 +1,6 @@
1
1
  import type { GlobalFlags } from "../flags.js";
2
+ import { type HandlerContext } from "../handler.js";
3
+ export declare function runLogin(context: HandlerContext, token?: string): Promise<void>;
2
4
  export declare const login: (this: import("../context.js").LocalContext, flags: GlobalFlags, token?: string | undefined) => Promise<void>;
3
5
  export declare const show: (this: import("../context.js").LocalContext, flags: GlobalFlags) => Promise<void>;
4
6
  export declare const logout: (this: import("../context.js").LocalContext, flags: GlobalFlags) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.impl.d.ts","sourceRoot":"","sources":["../../src/commands/auth.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA0E/C,eAAO,MAAM,KAAK,+GA8FhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
1
+ {"version":3,"file":"auth.impl.d.ts","sourceRoot":"","sources":["../../src/commands/auth.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAyElE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,iBA0FrE;AAED,eAAO,MAAM,KAAK,+GAMhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
@@ -30,9 +30,9 @@ async function pollLoginRedeem(baseUrl, sessionId, timeoutMs = 3e5, intervalMs =
30
30
  }
31
31
  return { status: "expired" };
32
32
  }
33
- const login = buildHandler(async function(_, token) {
34
- const environment = this.config.environment;
35
- const baseUrl = this.config.baseUrl;
33
+ async function runLogin(context, token) {
34
+ const environment = context.config.environment;
35
+ const baseUrl = context.config.baseUrl;
36
36
  if (token) {
37
37
  const update2 = {
38
38
  token,
@@ -41,11 +41,11 @@ const login = buildHandler(async function(_, token) {
41
41
  if (environment !== "prod") {
42
42
  update2.environment = environment;
43
43
  }
44
- await this.config.update(update2);
45
- this.io.writeErr("Successfully logged in!");
44
+ await context.config.update(update2);
45
+ context.io.writeErr("Successfully logged in!");
46
46
  return;
47
47
  }
48
- this.io.writeErr("Starting browser login...\n");
48
+ context.io.writeErr("Starting browser login...\n");
49
49
  let initResponse;
50
50
  try {
51
51
  initResponse = await loginFetch(
@@ -54,18 +54,18 @@ const login = buildHandler(async function(_, token) {
54
54
  {}
55
55
  );
56
56
  } catch (error) {
57
- this.io.writeErr(
57
+ context.io.writeErr(
58
58
  `Failed to start login: ${error instanceof Error ? error.message : String(error)}`
59
59
  );
60
60
  process.exit(1);
61
61
  }
62
62
  const { sessionId, verificationCode, browserUrl } = initResponse;
63
- this.io.writeErr(
63
+ context.io.writeErr(
64
64
  "Copy this verification code and paste it in your browser:\n"
65
65
  );
66
- this.io.writeErr(` ${verificationCode}
66
+ context.io.writeErr(` ${verificationCode}
67
67
  `);
68
- await this.io.input({
68
+ await context.io.input({
69
69
  message: `Press Enter to open the browser, or visit: ${browserUrl}`,
70
70
  noTTY: `Please visit this URL to authenticate:
71
71
  ${browserUrl}`
@@ -73,21 +73,21 @@ const login = buildHandler(async function(_, token) {
73
73
  try {
74
74
  await openNotionUrl(environment, browserUrl);
75
75
  } catch (_error) {
76
- this.io.writeErr(
76
+ context.io.writeErr(
77
77
  `Could not open browser automatically. Please visit:
78
78
  ${browserUrl}`
79
79
  );
80
80
  }
81
- this.io.writeErr("");
82
- this.io.writeErr("Waiting for browser confirmation...");
83
- this.io.writeErr("(Press Ctrl+C to cancel)\n");
81
+ context.io.writeErr("");
82
+ context.io.writeErr("Waiting for browser confirmation...");
83
+ context.io.writeErr("(Press Ctrl+C to cancel)\n");
84
84
  const redeemResponse = await pollLoginRedeem(baseUrl, sessionId);
85
85
  if (redeemResponse.status === "expired") {
86
- this.io.writeErr("Login session expired. Please try again.");
86
+ context.io.writeErr("Login session expired. Please try again.");
87
87
  process.exit(1);
88
88
  }
89
89
  if (redeemResponse.status !== "confirmed") {
90
- this.io.writeErr("Login failed. Please try again.");
90
+ context.io.writeErr("Login failed. Please try again.");
91
91
  process.exit(1);
92
92
  }
93
93
  const update = {
@@ -97,8 +97,11 @@ const login = buildHandler(async function(_, token) {
97
97
  if (environment !== "prod") {
98
98
  update.environment = environment;
99
99
  }
100
- await this.config.update(update);
101
- this.io.writeErr("\u2713 Successfully logged in!");
100
+ await context.config.update(update);
101
+ context.io.writeErr("\u2713 Successfully logged in!");
102
+ }
103
+ const login = buildHandler(async function(_, token) {
104
+ await runLogin(this, token);
102
105
  });
103
106
  const show = buildHandler(function() {
104
107
  this.io.writeOut(`${this.config.token ?? ""}`);
@@ -111,5 +114,6 @@ const logout = buildHandler(async function() {
111
114
  export {
112
115
  login,
113
116
  logout,
117
+ runLogin,
114
118
  show
115
119
  };
@@ -1,6 +1,7 @@
1
+ import type { GlobalFlags } from "../flags.js";
1
2
  interface DeployFlags {
2
3
  name?: string;
3
4
  }
4
- export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & DeployFlags) => Promise<void>;
5
+ export declare const deploy: (this: import("../context.js").LocalContext, flags: GlobalFlags & DeployFlags) => Promise<void>;
5
6
  export {};
6
7
  //# sourceMappingURL=deploy.impl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.impl.ts"],"names":[],"mappings":"AAKA,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,uHA+DjB,CAAC"}
1
+ {"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,iGAgFjB,CAAC"}
@@ -1,14 +1,28 @@
1
+ import { ApiClient } from "../api/client.js";
1
2
  import { Result } from "../api/result.js";
2
3
  import { deployWorker } from "../deploy.js";
3
- import { buildAuthedHandler } from "../handler.js";
4
- const deploy = buildAuthedHandler(async function(flags) {
5
- const { token } = this.config.tokenInfo;
4
+ import { buildHandler } from "../handler.js";
5
+ import { runLogin } from "./auth.impl.js";
6
+ const deploy = buildHandler(async function(flags) {
7
+ if (!this.config.token) {
8
+ this.io.writeErr("No authentication token found. Starting login flow...");
9
+ await runLogin(this);
10
+ }
11
+ const { token, cellId } = this.config.tokenInfo;
6
12
  const workerId = this.config.workerId;
7
13
  const environment = this.config.environment;
8
14
  if (!environment) {
9
15
  throw new Error("Unexpected error: Environment not set");
10
16
  }
11
17
  const workerPath = this.process.cwd();
18
+ const apiClient = new ApiClient({
19
+ token,
20
+ environment,
21
+ baseUrl: this.config.baseUrl,
22
+ cellId,
23
+ writer: this.io
24
+ });
25
+ const authedContext = { ...this, apiClient };
12
26
  this.io.writeErr("Deploying worker...");
13
27
  const name = flags.name;
14
28
  if (workerId && name) {
@@ -16,7 +30,7 @@ const deploy = buildAuthedHandler(async function(flags) {
16
30
  }
17
31
  let result;
18
32
  if (workerId) {
19
- result = await deployWorker(this, {
33
+ result = await deployWorker(authedContext, {
20
34
  workerPath,
21
35
  workerId,
22
36
  token,
@@ -38,7 +52,7 @@ const deploy = buildAuthedHandler(async function(flags) {
38
52
  }
39
53
  validatedName = trimmedName;
40
54
  }
41
- result = await deployWorker(this, {
55
+ result = await deployWorker(authedContext, {
42
56
  name: validatedName,
43
57
  workerPath,
44
58
  token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "A CLI for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",