@project-ajax/cli 0.0.15 → 0.0.16

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/routes.js CHANGED
@@ -10,7 +10,7 @@ import { oauthCommands } from "./commands/oauth.js";
10
10
  import pack from "./commands/pack.js";
11
11
  import { runsCommands } from "./commands/runs.js";
12
12
  import { secretsCommands } from "./commands/secrets.js";
13
- import { TokenNotSetError } from "./config.js";
13
+ import { TokenNotSetError } from "./token.js";
14
14
  const routes = buildRouteMap({
15
15
  docs: {
16
16
  brief: "A CLI for the Project Ajax platform",
@@ -22,10 +22,9 @@ data, providing tools to Custom Agents, or running automation tasks.
22
22
  Most flags are configured either with a config file or flags, but environment
23
23
  variables can also be provided:
24
24
 
25
- - WORKERS_CONFIG_FILE_PATH: The path to the config file to use (e.g. ./workers.dev.json)
25
+ - WORKERS_CONFIG: The path to the config file to use (e.g. ./workers.dev.json)
26
26
  - WORKERS_TOKEN: The token to use for authentication
27
27
  - WORKERS_ENVIRONMENT: The environment to use
28
- - WORKERS_WORKER_ID: The worker ID to use
29
28
  - WORKERS_BASE_URL: The base API URL to use
30
29
  `.trim(),
31
30
  hideRoute: {
@@ -0,0 +1,35 @@
1
+ export type TokenInfo = {
2
+ spaceId: string;
3
+ cellId: string;
4
+ };
5
+ export declare class InvalidTokenError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ export declare class TokenNotSetError extends Error {
9
+ constructor(message?: string);
10
+ }
11
+ /**
12
+ * Fetch a token and token information from the keychain, given a space ID.
13
+ *
14
+ * @param spaceId The space ID to fetch the token for.
15
+ * @returns The token and token information, or null if no token is found.
16
+ */
17
+ export declare function fetchToken(spaceId: string): Promise<string | null>;
18
+ /**
19
+ * Store a token in the keychain.
20
+ *
21
+ * @param token The token to store.
22
+ */
23
+ export declare function storeToken(spaceId: string, token: string): Promise<void>;
24
+ /**
25
+ * Given a token string, parse its info and return the info.
26
+ *
27
+ * v1 format:
28
+ *
29
+ * v1.<type>.<encoded-info-json>.<encoded-signature>
30
+ *
31
+ * @param token The token string to parse.
32
+ * @returns The parsed token info.
33
+ */
34
+ export declare function parseToken(token: string): TokenInfo;
35
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI3B;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAEzC,OAAO,GAAE,MAAiF;CAK3F;AAID;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxE;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAQnD"}
package/dist/token.js ADDED
@@ -0,0 +1,58 @@
1
+ import { getPassword, setPassword } from "cross-keychain";
2
+ class InvalidTokenError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "InvalidTokenError";
6
+ }
7
+ }
8
+ class TokenNotSetError extends Error {
9
+ constructor(message = "Not authenticated. Run 'workers auth login' or 'workers deploy' first.") {
10
+ super(message);
11
+ this.name = "TokenNotSetError";
12
+ }
13
+ }
14
+ const SERVICE_NAME = "notion-workers-cli";
15
+ async function fetchToken(spaceId) {
16
+ const password = await getPassword(SERVICE_NAME, spaceId);
17
+ return password;
18
+ }
19
+ async function storeToken(spaceId, token) {
20
+ await setPassword(SERVICE_NAME, spaceId, token);
21
+ }
22
+ function parseToken(token) {
23
+ const parts = splitToken(token);
24
+ if (parts[0] !== "v1") {
25
+ throw new InvalidTokenError("Invalid token version");
26
+ }
27
+ return decodeInfo(parts[2]);
28
+ }
29
+ function splitToken(token) {
30
+ const parts = token.split(".");
31
+ if (parts.length !== 4) {
32
+ throw new InvalidTokenError("Invalid token format");
33
+ }
34
+ return [parts[0], parts[1], parts[2], parts[3]];
35
+ }
36
+ function decodeInfo(encodedInfo) {
37
+ const infoJson = Buffer.from(encodedInfo, "base64url").toString("utf-8");
38
+ let info;
39
+ try {
40
+ info = JSON.parse(infoJson);
41
+ } catch {
42
+ throw new InvalidTokenError("Invalid token info");
43
+ }
44
+ if (typeof info !== "object" || info === null) {
45
+ throw new InvalidTokenError("Invalid token info");
46
+ }
47
+ if (!("spaceId" in info) || !("cellId" in info) || typeof info.spaceId !== "string" || typeof info.cellId !== "string") {
48
+ throw new InvalidTokenError("Invalid token info");
49
+ }
50
+ return { spaceId: info.spaceId, cellId: info.cellId };
51
+ }
52
+ export {
53
+ InvalidTokenError,
54
+ TokenNotSetError,
55
+ fetchToken,
56
+ parseToken,
57
+ storeToken
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/cli",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "A CLI for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -39,6 +39,9 @@
39
39
  "@stricli/core": "^1.2.4",
40
40
  "@visulima/tabular": "^3.1.1",
41
41
  "ajv": "^8.17.1",
42
- "esbuild": "^0.25.12"
42
+ "cross-keychain": "^1.1.0",
43
+ "debug": "^4.4.3",
44
+ "esbuild": "^0.25.12",
45
+ "zod": "^4.3.6"
43
46
  }
44
47
  }