@camox/cli 0.58.1 → 0.59.0
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/README.md +52 -210
- package/dist/api-DOHUrl0V.mjs +2 -0
- package/dist/api-DU0iBFMw.mjs +56 -0
- package/dist/index.mjs +273 -1374
- package/dist/lib/auth-core.mjs +1 -1
- package/package.json +2 -2
- package/dist/api-CBYfBQrH.mjs +0 -105
- package/dist/api-Ph2yMPXw.mjs +0 -2
- package/dist/{auth-core-xLeorUUV.mjs → auth-core-BpVsNVnR.mjs} +1 -1
package/dist/lib/auth-core.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export { t as createPreviewSignInUrl, n as isLoopbackUrl, r as normalizeUrl, i as readAuthTokenForUrl, a as removeAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "../auth-core-
|
|
2
|
+
export { t as createPreviewSignInUrl, n as isLoopbackUrl, r as normalizeUrl, i as readAuthTokenForUrl, a as removeAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "../auth-core-BpVsNVnR.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camox/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"camox": "./dist/index.mjs"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.12.4",
|
|
30
30
|
"vite-plus": "1.3.0",
|
|
31
|
-
"@camox/api-contract": "0.
|
|
31
|
+
"@camox/api-contract": "0.59.0"
|
|
32
32
|
},
|
|
33
33
|
"nx": {
|
|
34
34
|
"tags": [
|
package/dist/api-CBYfBQrH.mjs
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { t as installLocalhostDns } from "./local-dns-DQIT1ucr.mjs";
|
|
3
|
-
import { createORPCClient } from "@orpc/client";
|
|
4
|
-
import { RPCLink } from "@orpc/client/fetch";
|
|
5
|
-
//#region ../api-contract/src/drafts.ts
|
|
6
|
-
/** Request header naming the draft a request reads and writes (ADR 0011). Absent means Live. */
|
|
7
|
-
const DRAFT_HEADER = "x-camox-draft";
|
|
8
|
-
/**
|
|
9
|
-
* The `x-camox-draft` value naming the caller's own development draft in the project a request
|
|
10
|
-
* acts on (ADR 0006, ADR 0011). Dev mode and the CLI always send it.
|
|
11
|
-
*/
|
|
12
|
-
const DEVELOPMENT_DRAFT = "development";
|
|
13
|
-
/**
|
|
14
|
-
* oRPC error code for a request naming the development draft before dev mode created it: the
|
|
15
|
-
* first dev-mode sync after login does, so the site has to run locally once first.
|
|
16
|
-
*/
|
|
17
|
-
const NO_DEVELOPMENT_DRAFT_ERROR = "NO_DEVELOPMENT_DRAFT";
|
|
18
|
-
/**
|
|
19
|
-
* The oRPC error code a request naming an ended draft fails with. Its `data` is an `EndedDraft`,
|
|
20
|
-
* so a page can render Live and say who published or deleted the draft.
|
|
21
|
-
*/
|
|
22
|
-
const DRAFT_ENDED_ERROR_CODE = "DRAFT_ENDED";
|
|
23
|
-
/**
|
|
24
|
-
* Why the publish tool published nothing of a draft with changes, and returned a fresh preview to
|
|
25
|
-
* review again, by the error code of each: Live changed since the preview, the draft has blockers,
|
|
26
|
-
* translations are still running, or the draft's code changed since the preview.
|
|
27
|
-
*/
|
|
28
|
-
const NOT_PUBLISHED_CODES = {
|
|
29
|
-
conflictsChanged: "CONFLICTS_CHANGED",
|
|
30
|
-
blocked: "PUBLISH_BLOCKED",
|
|
31
|
-
translating: "TRANSLATIONS_PENDING",
|
|
32
|
-
revisionChanged: "REVISION_CHANGED"
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/lib/api.ts
|
|
36
|
-
const CAMOX_API_URL = process.env.CAMOX_API_URL || "https://api.camox.ai";
|
|
37
|
-
installLocalhostDns(new URL(CAMOX_API_URL).hostname);
|
|
38
|
-
function authHeaders(token) {
|
|
39
|
-
return {
|
|
40
|
-
Authorization: `Bearer ${token}`,
|
|
41
|
-
"Content-Type": "application/json"
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Headers of every request a command sends about a project: the CLI works only in the
|
|
46
|
-
* caller's development draft (ADR 0010).
|
|
47
|
-
*/
|
|
48
|
-
function developmentDraftHeaders(token, disableTelemetry) {
|
|
49
|
-
const headers = {
|
|
50
|
-
Authorization: `Bearer ${token}`,
|
|
51
|
-
"x-camox-client": "cli",
|
|
52
|
-
[DRAFT_HEADER]: DEVELOPMENT_DRAFT
|
|
53
|
-
};
|
|
54
|
-
if (disableTelemetry) headers["x-camox-telemetry-disabled"] = "1";
|
|
55
|
-
return headers;
|
|
56
|
-
}
|
|
57
|
-
function createRpcClient(token, apiUrl = CAMOX_API_URL, options = {}) {
|
|
58
|
-
installLocalhostDns(new URL(apiUrl).hostname);
|
|
59
|
-
const headers = options.developmentDraft ? developmentDraftHeaders(token, options.disableTelemetry) : {
|
|
60
|
-
Authorization: `Bearer ${token}`,
|
|
61
|
-
"x-camox-client": "cli"
|
|
62
|
-
};
|
|
63
|
-
const link = new RPCLink({
|
|
64
|
-
url: `${apiUrl}/rpc`,
|
|
65
|
-
headers
|
|
66
|
-
});
|
|
67
|
-
return createORPCClient(link);
|
|
68
|
-
}
|
|
69
|
-
async function verifySession(token) {
|
|
70
|
-
return (await fetch(`${CAMOX_API_URL}/api/auth/get-session`, {
|
|
71
|
-
method: "GET",
|
|
72
|
-
headers: authHeaders(token)
|
|
73
|
-
})).ok;
|
|
74
|
-
}
|
|
75
|
-
const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
76
|
-
/**
|
|
77
|
-
* Load a project named by its Project ID or its Project Slug. A UUID-shaped name is a
|
|
78
|
-
* Project ID, which the API validates; anything else is a slug.
|
|
79
|
-
*/
|
|
80
|
-
async function getProject(token, project, apiUrl) {
|
|
81
|
-
const client = createRpcClient(token, apiUrl, { developmentDraft: true });
|
|
82
|
-
return UUID_SHAPE.test(project) ? client.projects.getByUuid({ projectUuid: project }) : client.projects.getBySlug({ slug: project });
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* The caller's development draft in a project, summarized: it fails with
|
|
86
|
-
* `NO_DEVELOPMENT_DRAFT` until dev mode created it.
|
|
87
|
-
*/
|
|
88
|
-
async function getDevelopmentDraft(params) {
|
|
89
|
-
return createRpcClient(params.token, params.apiUrl, {
|
|
90
|
-
developmentDraft: true,
|
|
91
|
-
disableTelemetry: params.disableTelemetry
|
|
92
|
-
}).drafts.get({ projectId: params.projectId });
|
|
93
|
-
}
|
|
94
|
-
async function callTool(params) {
|
|
95
|
-
return await createRpcClient(params.token, params.apiUrl, {
|
|
96
|
-
developmentDraft: true,
|
|
97
|
-
disableTelemetry: params.disableTelemetry
|
|
98
|
-
}).agent.callTool({
|
|
99
|
-
projectId: params.projectId,
|
|
100
|
-
name: params.name,
|
|
101
|
-
arguments: params.args
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
export { verifySession as a, NOT_PUBLISHED_CODES as c, getProject as i, NO_DEVELOPMENT_DRAFT_ERROR as l, developmentDraftHeaders as n, DEVELOPMENT_DRAFT as o, getDevelopmentDraft as r, DRAFT_ENDED_ERROR_CODE as s, callTool as t };
|
package/dist/api-Ph2yMPXw.mjs
DELETED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as installLocalhostDns } from "./local-dns-DQIT1ucr.mjs";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
6
|
//#region src/lib/auth-core.ts
|
|
7
7
|
function globalAuthFile() {
|
|
8
8
|
return path.join(os.homedir(), ".camox", "auth.json");
|