@agency-tbd/cli 0.0.0-stage → 0.1.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/dist/schema.js ADDED
@@ -0,0 +1,36 @@
1
+ import { resources } from "./catalog.js";
2
+ import { CliError } from "./errors.js";
3
+ import { rpc } from "./transport.js";
4
+ export function operationPath(resource, parts) {
5
+ if (!resources.includes(resource))
6
+ throw new CliError("UNKNOWN_RESOURCE", `Unknown resource: ${resource}. Run resources.`, 2);
7
+ if (!parts.length ||
8
+ parts.some((part) => !/^[a-zA-Z0-9_-]+$/.test(part) ||
9
+ ["__proto__", "constructor", "prototype", "__cli"].includes(part)))
10
+ throw new CliError("INVALID_OPERATION", "Provide a valid operation path; run schema <resource>", 2);
11
+ return parts;
12
+ }
13
+ export async function describe(connection, resource, path) {
14
+ if (connection.sponsorshipTenantId && resource !== "sponsorships")
15
+ throw new CliError("INVALID_TENANT_SCOPE", "--sponsor-tenant applies only to sponsorships", 2);
16
+ if (connection.sponsorshipTenantId && !/^[0-9a-f-]{36}$/i.test(connection.sponsorshipTenantId))
17
+ throw new CliError("INVALID_TENANT_SCOPE", "Invalid sponsorship tenant identifier", 2);
18
+ operationPath(resource, path?.length ? path : ["schema"]);
19
+ const result = await rpc(connection, resource, ["__cli", "schema"], path?.length ? { path } : undefined, "GET");
20
+ if (!result ||
21
+ typeof result !== "object" ||
22
+ !("protocolVersion" in result) ||
23
+ result.protocolVersion !== 1 ||
24
+ !("operations" in result) ||
25
+ !Array.isArray(result.operations))
26
+ throw new CliError("INCOMPATIBLE_SERVER", "Server does not support CLI discovery v1; deploy the matching server changes", 5);
27
+ return result;
28
+ }
29
+ export async function resolveOperation(connection, resource, path) {
30
+ const result = await describe(connection, resource, operationPath(resource, path));
31
+ const operation = result.operations.find((item) => item.path.join(".") === path.join("."));
32
+ if (!operation)
33
+ throw new CliError("UNKNOWN_OPERATION", "Select a concrete operation from schema", 2);
34
+ return operation;
35
+ }
36
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1,48 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { RPCLink } from "@orpc/client/fetch";
3
+ import { CliError } from "./errors.js";
4
+ import { cliVersion } from "./version.js";
5
+ export function rpc(connection, resource, path, input, method = "POST") {
6
+ const link = new RPCLink({
7
+ url: `${connection.origin}/api/v1/${resource}`,
8
+ method: method === "GET" ? "GET" : "POST",
9
+ headers: {
10
+ Authorization: `Bearer ${connection.token}`,
11
+ "x-correlation-id": connection.requestId ?? randomUUID(),
12
+ "x-influmode-cli-version": cliVersion,
13
+ ...(connection.sponsorshipTenantId && resource === "sponsorships"
14
+ ? { "x-sponsorship-tenant-id": connection.sponsorshipTenantId }
15
+ : {}),
16
+ },
17
+ fetch: (request, init) => fetch(request, { ...init, redirect: "error" }),
18
+ });
19
+ return link.call(path, input, { context: {}, signal: AbortSignal.timeout(connection.timeout) });
20
+ }
21
+ export function apiPath(origin, value) {
22
+ const url = new URL(value, origin);
23
+ if (url.origin !== origin ||
24
+ !url.pathname.startsWith("/api/") ||
25
+ url.username ||
26
+ url.password ||
27
+ url.hash)
28
+ throw new CliError("INVALID_PATH", "HTTP requests must target /api/ on the selected Influmode origin", 2);
29
+ return url;
30
+ }
31
+ export async function http(connection, pathname, method = "GET", body, extraHeaders = {}) {
32
+ const response = await fetch(apiPath(connection.origin, pathname), {
33
+ method,
34
+ headers: {
35
+ Authorization: `Bearer ${connection.token}`,
36
+ ...extraHeaders,
37
+ "content-type": "application/json",
38
+ "x-correlation-id": connection.requestId ?? randomUUID(),
39
+ },
40
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
41
+ redirect: "manual",
42
+ signal: AbortSignal.timeout(connection.timeout),
43
+ });
44
+ if (!response.ok)
45
+ throw new CliError("HTTP_ERROR", `HTTP ${response.status}`, response.status === 401 ? 3 : response.status === 403 ? 4 : 1, { status: response.status, requestId: response.headers.get("x-request-id") });
46
+ return response;
47
+ }
48
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1,11 @@
1
+ import { readFileSync } from "node:fs";
2
+ const INVALID_PACKAGE_VERSION = "INFLUMODE_PACKAGE_VERSION_MISSING";
3
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
4
+ if (!manifest ||
5
+ typeof manifest !== "object" ||
6
+ !("version" in manifest) ||
7
+ typeof manifest.version !== "string" ||
8
+ !manifest.version)
9
+ throw new Error(INVALID_PACKAGE_VERSION);
10
+ export const cliVersion = manifest.version;
11
+ //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@agency-tbd/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Operate InfluMode from your terminal or AI assistant using your own account and permissions",
5
+ "bin": {
6
+ "influmode": "dist/main.js"
7
+ },
8
+ "files": [
9
+ "dist/*.js"
10
+ ],
11
+ "type": "module",
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "registry": "https://registry.npmjs.org/"
15
+ },
16
+ "dependencies": {
17
+ "@orpc/client": "^1.16.0"
18
+ },
19
+ "devDependencies": {
20
+ "@agency-tbd/config": "0.0.0",
21
+ "@orpc/server": "^1.16.0",
22
+ "@types/node": "24.19.2",
23
+ "tsx": "^4.23.15",
24
+ "typescript": "^6.0.3",
25
+ "vitest": "^5.0.5",
26
+ "zod": "^4.6.7"
27
+ },
28
+ "engines": {
29
+ "node": ">=24.22.1"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "catalog:check": "node scripts/catalog.mjs --check",
34
+ "catalog:generate": "node scripts/catalog.mjs",
35
+ "check-types": "tsc --noEmit",
36
+ "dev": "tsx src/main.ts",
37
+ "release:check": "pnpm check-types && pnpm test && node scripts/check-package.mjs",
38
+ "release:publish": "pnpm release:check && pnpm publish --access public",
39
+ "test": "pnpm build && vitest run --config vitest.config.ts"
40
+ }
6
41
  }