@project-ajax/cli 0.0.14 → 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/api/client.d.ts +0 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.impl.d.ts +2 -3
- package/dist/commands/auth.impl.d.ts.map +1 -1
- package/dist/commands/auth.impl.js +65 -101
- package/dist/commands/auth.js +0 -27
- package/dist/commands/deploy.impl.d.ts.map +1 -1
- package/dist/commands/deploy.impl.js +6 -7
- package/dist/commands/exec.impl.js +1 -1
- package/dist/commands/utils/testing.d.ts +20 -5
- package/dist/commands/utils/testing.d.ts.map +1 -1
- package/dist/commands/utils/testing.js +66 -25
- package/dist/config.d.ts +144 -42
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +322 -140
- package/dist/deploy.d.ts +2 -1
- package/dist/deploy.d.ts.map +1 -1
- package/dist/flags.d.ts +2 -3
- package/dist/flags.d.ts.map +1 -1
- package/dist/flags.js +4 -10
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +13 -9
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +2 -3
- package/dist/token.d.ts +35 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +58 -0
- package/package.json +5 -2
package/dist/token.d.ts
ADDED
|
@@ -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.
|
|
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
|
-
"
|
|
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
|
}
|