@koda-sl/baker-cli 0.131.0 → 0.132.1
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 +20 -0
- package/dist/chunk-7I2POXSJ.js +153 -0
- package/dist/chunk-7I2POXSJ.js.map +1 -0
- package/dist/{chunk-AVJ3B6LC.js → chunk-BFZELBTE.js} +4 -4
- package/dist/{chunk-AEBAUSIN.js → chunk-MWR25ZMU.js} +25 -2
- package/dist/chunk-MWR25ZMU.js.map +1 -0
- package/dist/{chunk-ISFSUDEQ.js → chunk-PEBP6G74.js} +3 -3
- package/dist/chunk-RK67WL4O.js +72 -0
- package/dist/{chunk-YTEAWSEM.js.map → chunk-RK67WL4O.js.map} +1 -1
- package/dist/{chunk-K47Q73CK.js → chunk-SCI57ZZ6.js} +40 -4
- package/dist/chunk-SCI57ZZ6.js.map +1 -0
- package/dist/cli.js +15 -10
- package/dist/cli.js.map +1 -1
- package/dist/client-N7XWYCHT.js +15 -0
- package/dist/engine/index.js +3 -2
- package/dist/env-3JMYIH25.js +11 -0
- package/dist/{output-2LGBISBQ.js → output-7M5VQPTZ.js} +5 -5
- package/dist/{shared-CQC3YRBA.js → shared-6SZHAUM2.js} +6 -6
- package/package.json +1 -1
- package/dist/chunk-5WRI5ZAA.js +0 -31
- package/dist/chunk-AEBAUSIN.js.map +0 -1
- package/dist/chunk-K47Q73CK.js.map +0 -1
- package/dist/chunk-YTEAWSEM.js +0 -39
- package/dist/client-PGOTU24X.js +0 -15
- package/dist/env-TD4VXCQ7.js +0 -10
- package/dist/shared-CQC3YRBA.js.map +0 -1
- /package/dist/{chunk-AVJ3B6LC.js.map → chunk-BFZELBTE.js.map} +0 -0
- /package/dist/{chunk-ISFSUDEQ.js.map → chunk-PEBP6G74.js.map} +0 -0
- /package/dist/{chunk-5WRI5ZAA.js.map → client-N7XWYCHT.js.map} +0 -0
- /package/dist/{client-PGOTU24X.js.map → env-3JMYIH25.js.map} +0 -0
- /package/dist/{env-TD4VXCQ7.js.map → output-7M5VQPTZ.js.map} +0 -0
- /package/dist/{output-2LGBISBQ.js.map → shared-6SZHAUM2.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
apiGet
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SCI57ZZ6.js";
|
|
4
4
|
import {
|
|
5
5
|
getEnv
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RK67WL4O.js";
|
|
7
7
|
|
|
8
8
|
// src/commands/ads/cache.ts
|
|
9
9
|
import { createHash } from "crypto";
|
|
@@ -261,4 +261,4 @@ export {
|
|
|
261
261
|
writeAdsOutput,
|
|
262
262
|
resolveCustomerId
|
|
263
263
|
};
|
|
264
|
-
//# sourceMappingURL=chunk-
|
|
264
|
+
//# sourceMappingURL=chunk-PEBP6G74.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// src/env.ts
|
|
28
|
+
import { createEnv } from "@t3-oss/env-core";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
var cached;
|
|
31
|
+
function getEnv() {
|
|
32
|
+
if (!cached) {
|
|
33
|
+
cached = createEnv({
|
|
34
|
+
server: {
|
|
35
|
+
BAKER_API_KEY: z.string().startsWith("bk_", "API key must start with 'bk_'"),
|
|
36
|
+
BAKER_API_URL: z.url("BAKER_API_URL must be a valid URL"),
|
|
37
|
+
BAKER_CHAT_ID: z.string().optional(),
|
|
38
|
+
BAKER_ACTING_USER_ID: z.string().optional(),
|
|
39
|
+
BAKER_GOOGLE_ADS_CUSTOMER_ID: z.string().regex(/^\d{10}$/).optional(),
|
|
40
|
+
BAKER_GA4_PROPERTY_ID: z.string().optional(),
|
|
41
|
+
BAKER_GSC_SITE_URL: z.string().optional(),
|
|
42
|
+
BAKER_X_ADS_ACCOUNT_ID: z.string().regex(/^[a-z0-9]+$/, "X Ads account ID must be a base36 string").optional(),
|
|
43
|
+
BAKER_META_AD_ACCOUNT_ID: z.string().optional(),
|
|
44
|
+
BAKER_LINKEDIN_AD_ACCOUNT_ID: z.string().regex(/^\d+$/, "LinkedIn ad account ID must be the numeric portion of urn:li:sponsoredAccount:N").optional()
|
|
45
|
+
},
|
|
46
|
+
runtimeEnv: process.env
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return cached;
|
|
50
|
+
}
|
|
51
|
+
function debugLogSetting() {
|
|
52
|
+
const raw = process.env.BAKER_DEBUG_LOG?.trim();
|
|
53
|
+
return raw ? raw : void 0;
|
|
54
|
+
}
|
|
55
|
+
function requireChatId() {
|
|
56
|
+
const env = getEnv();
|
|
57
|
+
if (!env.BAKER_CHAT_ID) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
"BAKER_CHAT_ID is not set. This command stages changes against a chat \u2014 run it from a chat-attached environment."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return env.BAKER_CHAT_ID;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
__commonJS,
|
|
67
|
+
__toESM,
|
|
68
|
+
getEnv,
|
|
69
|
+
debugLogSetting,
|
|
70
|
+
requireChatId
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-RK67WL4O.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/env.ts"],"sourcesContent":["import { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\ntype Env = {\n BAKER_API_KEY: string;\n BAKER_API_URL: string;\n BAKER_CHAT_ID?: string;\n BAKER_ACTING_USER_ID?: string;\n BAKER_GOOGLE_ADS_CUSTOMER_ID?: string;\n BAKER_GA4_PROPERTY_ID?: string;\n BAKER_GSC_SITE_URL?: string;\n BAKER_X_ADS_ACCOUNT_ID?: string;\n BAKER_META_AD_ACCOUNT_ID?: string;\n BAKER_LINKEDIN_AD_ACCOUNT_ID?: string;\n};\n\nlet cached: Env | undefined;\n\nexport function getEnv(): Env {\n if (!cached) {\n cached = createEnv({\n server: {\n BAKER_API_KEY: z.string().startsWith(\"bk_\", \"API key must start with 'bk_'\"),\n BAKER_API_URL: z.url(\"BAKER_API_URL must be a valid URL\"),\n BAKER_CHAT_ID: z.string().optional(),\n BAKER_ACTING_USER_ID: z.string().optional(),\n BAKER_GOOGLE_ADS_CUSTOMER_ID: z\n .string()\n .regex(/^\\d{10}$/)\n .optional(),\n BAKER_GA4_PROPERTY_ID: z.string().optional(),\n BAKER_GSC_SITE_URL: z.string().optional(),\n BAKER_X_ADS_ACCOUNT_ID: z\n .string()\n .regex(/^[a-z0-9]+$/, \"X Ads account ID must be a base36 string\")\n .optional(),\n BAKER_META_AD_ACCOUNT_ID: z.string().optional(),\n BAKER_LINKEDIN_AD_ACCOUNT_ID: z\n .string()\n .regex(/^\\d+$/, \"LinkedIn ad account ID must be the numeric portion of urn:li:sponsoredAccount:N\")\n .optional(),\n },\n runtimeEnv: process.env,\n });\n }\n return cached;\n}\n\nexport function requireChatId(): string {\n const env = getEnv();\n if (!env.BAKER_CHAT_ID) {\n throw new Error(\n \"BAKER_CHAT_ID is not set. This command stages changes against a chat — run it from a chat-attached environment.\",\n );\n }\n return env.BAKER_CHAT_ID;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/env.ts"],"sourcesContent":["import { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\ntype Env = {\n BAKER_API_KEY: string;\n BAKER_API_URL: string;\n BAKER_CHAT_ID?: string;\n BAKER_ACTING_USER_ID?: string;\n BAKER_GOOGLE_ADS_CUSTOMER_ID?: string;\n BAKER_GA4_PROPERTY_ID?: string;\n BAKER_GSC_SITE_URL?: string;\n BAKER_X_ADS_ACCOUNT_ID?: string;\n BAKER_META_AD_ACCOUNT_ID?: string;\n BAKER_LINKEDIN_AD_ACCOUNT_ID?: string;\n};\n\nlet cached: Env | undefined;\n\nexport function getEnv(): Env {\n if (!cached) {\n cached = createEnv({\n server: {\n BAKER_API_KEY: z.string().startsWith(\"bk_\", \"API key must start with 'bk_'\"),\n BAKER_API_URL: z.url(\"BAKER_API_URL must be a valid URL\"),\n BAKER_CHAT_ID: z.string().optional(),\n BAKER_ACTING_USER_ID: z.string().optional(),\n BAKER_GOOGLE_ADS_CUSTOMER_ID: z\n .string()\n .regex(/^\\d{10}$/)\n .optional(),\n BAKER_GA4_PROPERTY_ID: z.string().optional(),\n BAKER_GSC_SITE_URL: z.string().optional(),\n BAKER_X_ADS_ACCOUNT_ID: z\n .string()\n .regex(/^[a-z0-9]+$/, \"X Ads account ID must be a base36 string\")\n .optional(),\n BAKER_META_AD_ACCOUNT_ID: z.string().optional(),\n BAKER_LINKEDIN_AD_ACCOUNT_ID: z\n .string()\n .regex(/^\\d+$/, \"LinkedIn ad account ID must be the numeric portion of urn:li:sponsoredAccount:N\")\n .optional(),\n },\n runtimeEnv: process.env,\n });\n }\n return cached;\n}\n\n// Read directly (not via the validated schema): debug logging must work even when\n// the required BAKER_API_KEY/BAKER_API_URL are missing or malformed.\nexport function debugLogSetting(): string | undefined {\n const raw = process.env.BAKER_DEBUG_LOG?.trim();\n return raw ? raw : undefined;\n}\n\nexport function requireChatId(): string {\n const env = getEnv();\n if (!env.BAKER_CHAT_ID) {\n throw new Error(\n \"BAKER_CHAT_ID is not set. This command stages changes against a chat — run it from a chat-attached environment.\",\n );\n }\n return env.BAKER_CHAT_ID;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAelB,IAAI;AAEG,SAAS,SAAc;AAC5B,MAAI,CAAC,QAAQ;AACX,aAAS,UAAU;AAAA,MACjB,QAAQ;AAAA,QACN,eAAe,EAAE,OAAO,EAAE,WAAW,OAAO,+BAA+B;AAAA,QAC3E,eAAe,EAAE,IAAI,mCAAmC;AAAA,QACxD,eAAe,EAAE,OAAO,EAAE,SAAS;AAAA,QACnC,sBAAsB,EAAE,OAAO,EAAE,SAAS;AAAA,QAC1C,8BAA8B,EAC3B,OAAO,EACP,MAAM,UAAU,EAChB,SAAS;AAAA,QACZ,uBAAuB,EAAE,OAAO,EAAE,SAAS;AAAA,QAC3C,oBAAoB,EAAE,OAAO,EAAE,SAAS;AAAA,QACxC,wBAAwB,EACrB,OAAO,EACP,MAAM,eAAe,0CAA0C,EAC/D,SAAS;AAAA,QACZ,0BAA0B,EAAE,OAAO,EAAE,SAAS;AAAA,QAC9C,8BAA8B,EAC3B,OAAO,EACP,MAAM,SAAS,iFAAiF,EAChG,SAAS;AAAA,MACd;AAAA,MACA,YAAY,QAAQ;AAAA,IACtB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAIO,SAAS,kBAAsC;AACpD,QAAM,MAAM,QAAQ,IAAI,iBAAiB,KAAK;AAC9C,SAAO,MAAM,MAAM;AACrB;AAEO,SAAS,gBAAwB;AACtC,QAAM,MAAM,OAAO;AACnB,MAAI,CAAC,IAAI,eAAe;AACtB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,IAAI;AACb;","names":[]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debugLogHttp,
|
|
3
|
+
readBodyForLog
|
|
4
|
+
} from "./chunk-7I2POXSJ.js";
|
|
1
5
|
import {
|
|
2
6
|
getEnv
|
|
3
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-RK67WL4O.js";
|
|
4
8
|
|
|
5
9
|
// src/client.ts
|
|
6
10
|
var MAX_RATE_LIMIT_RETRIES = 3;
|
|
@@ -105,9 +109,11 @@ async function apiGet(path, params) {
|
|
|
105
109
|
url.searchParams.set(key, value);
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
const urlStr = url.toString();
|
|
113
|
+
const startedAt = Date.now();
|
|
108
114
|
let response;
|
|
109
115
|
try {
|
|
110
|
-
response = await fetchWithRateLimitRetry(
|
|
116
|
+
response = await fetchWithRateLimitRetry(urlStr, {
|
|
111
117
|
method: "GET",
|
|
112
118
|
headers: {
|
|
113
119
|
Authorization: `Bearer ${env.BAKER_API_KEY}`,
|
|
@@ -116,19 +122,31 @@ async function apiGet(path, params) {
|
|
|
116
122
|
signal: AbortSignal.timeout(6e4)
|
|
117
123
|
});
|
|
118
124
|
} catch (err) {
|
|
125
|
+
debugLogHttp({ source: "cli", method: "GET", url: urlStr, durationMs: Date.now() - startedAt, error: err });
|
|
119
126
|
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
120
127
|
throw new ApiError("TIMEOUT", "Request timed out after 60 seconds");
|
|
121
128
|
}
|
|
122
129
|
throw new ApiError("NETWORK_ERROR", `Request failed: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
123
130
|
}
|
|
131
|
+
debugLogHttp({
|
|
132
|
+
source: "cli",
|
|
133
|
+
method: "GET",
|
|
134
|
+
url: urlStr,
|
|
135
|
+
status: response.status,
|
|
136
|
+
ok: response.ok,
|
|
137
|
+
responseBody: await readBodyForLog(response),
|
|
138
|
+
durationMs: Date.now() - startedAt
|
|
139
|
+
});
|
|
124
140
|
return handleResponse(response);
|
|
125
141
|
}
|
|
126
142
|
async function apiPost(path, body, opts) {
|
|
127
143
|
const env = getEnv();
|
|
128
144
|
const timeoutMs = opts?.timeoutMs ?? 6e4;
|
|
145
|
+
const urlStr = new URL(path, env.BAKER_API_URL).toString();
|
|
146
|
+
const startedAt = Date.now();
|
|
129
147
|
let response;
|
|
130
148
|
try {
|
|
131
|
-
response = await fetchWithRateLimitRetry(
|
|
149
|
+
response = await fetchWithRateLimitRetry(urlStr, {
|
|
132
150
|
method: "POST",
|
|
133
151
|
headers: {
|
|
134
152
|
Authorization: `Bearer ${env.BAKER_API_KEY}`,
|
|
@@ -139,11 +157,29 @@ async function apiPost(path, body, opts) {
|
|
|
139
157
|
signal: AbortSignal.timeout(timeoutMs)
|
|
140
158
|
});
|
|
141
159
|
} catch (err) {
|
|
160
|
+
debugLogHttp({
|
|
161
|
+
source: "cli",
|
|
162
|
+
method: "POST",
|
|
163
|
+
url: urlStr,
|
|
164
|
+
requestBody: body,
|
|
165
|
+
durationMs: Date.now() - startedAt,
|
|
166
|
+
error: err
|
|
167
|
+
});
|
|
142
168
|
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
143
169
|
throw new ApiError("TIMEOUT", `Request timed out after ${Math.round(timeoutMs / 1e3)} seconds`);
|
|
144
170
|
}
|
|
145
171
|
throw new ApiError("NETWORK_ERROR", `Request failed: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
146
172
|
}
|
|
173
|
+
debugLogHttp({
|
|
174
|
+
source: "cli",
|
|
175
|
+
method: "POST",
|
|
176
|
+
url: urlStr,
|
|
177
|
+
requestBody: body,
|
|
178
|
+
status: response.status,
|
|
179
|
+
ok: response.ok,
|
|
180
|
+
responseBody: await readBodyForLog(response),
|
|
181
|
+
durationMs: Date.now() - startedAt
|
|
182
|
+
});
|
|
147
183
|
return handleResponse(response);
|
|
148
184
|
}
|
|
149
185
|
|
|
@@ -153,4 +189,4 @@ export {
|
|
|
153
189
|
apiGet,
|
|
154
190
|
apiPost
|
|
155
191
|
};
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
192
|
+
//# sourceMappingURL=chunk-SCI57ZZ6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { debugLogHttp, readBodyForLog } from \"./debugLog.ts\";\nimport { getEnv } from \"./env.ts\";\n\nconst MAX_RATE_LIMIT_RETRIES = 3;\nconst MAX_TOTAL_WAIT_MS = 2 * 60 * 1000;\n\nasync function fetchWithRateLimitRetry(url: string, init: RequestInit): Promise<Response> {\n let totalWaited = 0;\n\n for (let attempt = 0; attempt <= MAX_RATE_LIMIT_RETRIES; attempt++) {\n const response = await fetch(url, init);\n\n if (response.status !== 429 || attempt >= MAX_RATE_LIMIT_RETRIES) {\n return response;\n }\n\n const retryAfterHeader = response.headers.get(\"Retry-After\");\n const waitMs = retryAfterHeader ? Number(retryAfterHeader) * 1000 : 2000 * 2 ** attempt;\n\n if (totalWaited + waitMs > MAX_TOTAL_WAIT_MS) {\n return response;\n }\n\n totalWaited += waitMs;\n await new Promise((resolve) => setTimeout(resolve, waitMs));\n }\n\n return fetch(url, init);\n}\n\ntype ErrorCode =\n | \"UNAUTHORIZED\"\n | \"NOT_FOUND\"\n | \"VALIDATION_ERROR\"\n | \"RATE_LIMITED\"\n | \"INTERNAL_ERROR\"\n | \"NETWORK_ERROR\"\n | \"TIMEOUT\"\n | \"IMAGE_PROCESSING_ERROR\";\n\nexport class ApiError extends Error {\n code: ErrorCode;\n\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.name = \"ApiError\";\n this.code = code;\n }\n}\n\nconst CONVEX_ID_RE = /^[a-zA-Z0-9_]+$/;\n\nfunction hasControlCharacters(value: string): boolean {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n // Allow tab (9), newline (10), carriage return (13)\n if (code < 32 && code !== 9 && code !== 10 && code !== 13) {\n return true;\n }\n }\n return false;\n}\n\nfunction validateStringValue(value: string): void {\n if (hasControlCharacters(value)) {\n throw new ApiError(\"VALIDATION_ERROR\", \"String value contains invalid control characters\");\n }\n}\n\nexport function validateConvexId(id: string): void {\n if (!CONVEX_ID_RE.test(id)) {\n throw new ApiError(\"VALIDATION_ERROR\", `Invalid ID format: \"${id}\". Expected alphanumeric string.`);\n }\n}\n\nfunction sanitizeParams(params: Record<string, string>): Record<string, string> {\n const sanitized: Record<string, string> = {};\n for (const [key, value] of Object.entries(params)) {\n validateStringValue(value);\n sanitized[key] = value;\n }\n return sanitized;\n}\n\nfunction mapHttpError(status: number): ErrorCode {\n if (status === 401 || status === 403) {\n return \"UNAUTHORIZED\";\n }\n if (status === 404) {\n return \"NOT_FOUND\";\n }\n if (status === 422 || status === 400) {\n return \"VALIDATION_ERROR\";\n }\n if (status === 429) {\n return \"RATE_LIMITED\";\n }\n return \"INTERNAL_ERROR\";\n}\n\nasync function handleResponse<T>(response: Response): Promise<T> {\n const body = await response.text();\n\n if (!response.ok) {\n let message = `HTTP ${response.status}: ${response.statusText}`;\n try {\n const parsed = JSON.parse(body) as { error?: string | { message?: string }; message?: string };\n if (typeof parsed.error === \"string\") {\n message = parsed.error;\n } else if (parsed.error?.message) {\n message = parsed.error.message;\n } else if (parsed.message) {\n message = parsed.message;\n }\n } catch {\n // Use default message\n }\n throw new ApiError(mapHttpError(response.status), message);\n }\n\n try {\n return JSON.parse(body) as T;\n } catch {\n throw new ApiError(\"INTERNAL_ERROR\", \"Failed to parse API response as JSON\");\n }\n}\n\nexport async function apiGet<T>(path: string, params?: Record<string, string>): Promise<T> {\n const env = getEnv();\n const url = new URL(path, env.BAKER_API_URL);\n if (params) {\n const clean = sanitizeParams(params);\n for (const [key, value] of Object.entries(clean)) {\n url.searchParams.set(key, value);\n }\n }\n\n const urlStr = url.toString();\n const startedAt = Date.now();\n let response: Response;\n try {\n response = await fetchWithRateLimitRetry(urlStr, {\n method: \"GET\",\n headers: {\n Authorization: `Bearer ${env.BAKER_API_KEY}`,\n Accept: \"application/json\",\n },\n signal: AbortSignal.timeout(60_000),\n });\n } catch (err) {\n debugLogHttp({ source: \"cli\", method: \"GET\", url: urlStr, durationMs: Date.now() - startedAt, error: err });\n if (err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\")) {\n throw new ApiError(\"TIMEOUT\", \"Request timed out after 60 seconds\");\n }\n throw new ApiError(\"NETWORK_ERROR\", `Request failed: ${err instanceof Error ? err.message : \"Unknown error\"}`);\n }\n\n debugLogHttp({\n source: \"cli\",\n method: \"GET\",\n url: urlStr,\n status: response.status,\n ok: response.ok,\n responseBody: await readBodyForLog(response),\n durationMs: Date.now() - startedAt,\n });\n return handleResponse<T>(response);\n}\n\nexport async function apiPost<T>(path: string, body: unknown, opts?: { timeoutMs?: number }): Promise<T> {\n const env = getEnv();\n const timeoutMs = opts?.timeoutMs ?? 60_000;\n const urlStr = new URL(path, env.BAKER_API_URL).toString();\n const startedAt = Date.now();\n let response: Response;\n try {\n response = await fetchWithRateLimitRetry(urlStr, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${env.BAKER_API_KEY}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (err) {\n debugLogHttp({\n source: \"cli\",\n method: \"POST\",\n url: urlStr,\n requestBody: body,\n durationMs: Date.now() - startedAt,\n error: err,\n });\n if (err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\")) {\n throw new ApiError(\"TIMEOUT\", `Request timed out after ${Math.round(timeoutMs / 1000)} seconds`);\n }\n throw new ApiError(\"NETWORK_ERROR\", `Request failed: ${err instanceof Error ? err.message : \"Unknown error\"}`);\n }\n\n debugLogHttp({\n source: \"cli\",\n method: \"POST\",\n url: urlStr,\n requestBody: body,\n status: response.status,\n ok: response.ok,\n responseBody: await readBodyForLog(response),\n durationMs: Date.now() - startedAt,\n });\n return handleResponse<T>(response);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAM,yBAAyB;AAC/B,IAAM,oBAAoB,IAAI,KAAK;AAEnC,eAAe,wBAAwB,KAAa,MAAsC;AACxF,MAAI,cAAc;AAElB,WAAS,UAAU,GAAG,WAAW,wBAAwB,WAAW;AAClE,UAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AAEtC,QAAI,SAAS,WAAW,OAAO,WAAW,wBAAwB;AAChE,aAAO;AAAA,IACT;AAEA,UAAM,mBAAmB,SAAS,QAAQ,IAAI,aAAa;AAC3D,UAAM,SAAS,mBAAmB,OAAO,gBAAgB,IAAI,MAAO,MAAO,KAAK;AAEhF,QAAI,cAAc,SAAS,mBAAmB;AAC5C,aAAO;AAAA,IACT;AAEA,mBAAe;AACf,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,MAAM,CAAC;AAAA,EAC5D;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAYO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC;AAAA,EAEA,YAAY,MAAiB,SAAiB;AAC5C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAEA,IAAM,eAAe;AAErB,SAAS,qBAAqB,OAAwB;AACpD,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAC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/dist/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
toModelSafeImage,
|
|
32
32
|
ulid,
|
|
33
33
|
validateCanvasDeep
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-MWR25ZMU.js";
|
|
35
35
|
import {
|
|
36
36
|
csvOrJson,
|
|
37
37
|
daysAgoIso,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
resolveAccountIdArg,
|
|
41
41
|
resolveEffectiveStatus,
|
|
42
42
|
todayIso
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-BFZELBTE.js";
|
|
44
44
|
import {
|
|
45
45
|
buildQueryCacheKey,
|
|
46
46
|
cacheGet,
|
|
@@ -53,18 +53,21 @@ import {
|
|
|
53
53
|
writeAdsJson,
|
|
54
54
|
writeAdsOutput,
|
|
55
55
|
writeJsonEnvelope
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-PEBP6G74.js";
|
|
57
57
|
import {
|
|
58
58
|
ApiError,
|
|
59
59
|
apiGet,
|
|
60
60
|
apiPost,
|
|
61
61
|
validateConvexId
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-SCI57ZZ6.js";
|
|
63
|
+
import {
|
|
64
|
+
installStreamTaps,
|
|
65
|
+
logInvocation
|
|
66
|
+
} from "./chunk-7I2POXSJ.js";
|
|
63
67
|
import {
|
|
64
68
|
getEnv,
|
|
65
69
|
requireChatId
|
|
66
|
-
} from "./chunk-
|
|
67
|
-
import "./chunk-5WRI5ZAA.js";
|
|
70
|
+
} from "./chunk-RK67WL4O.js";
|
|
68
71
|
|
|
69
72
|
// src/cli.ts
|
|
70
73
|
import { defineCommand as defineCommand171, runMain } from "citty";
|
|
@@ -12120,10 +12123,10 @@ function duplicateCommand2(entity, label) {
|
|
|
12120
12123
|
replace: { type: "boolean", description: "Pause the original once the copy publishes" }
|
|
12121
12124
|
},
|
|
12122
12125
|
run: async ({ args }) => {
|
|
12123
|
-
const { apiPost: apiPost2 } = await import("./client-
|
|
12124
|
-
const { requireChatId: requireChatId2 } = await import("./env-
|
|
12125
|
-
const { writeJsonEnvelope: writeJsonEnvelope2 } = await import("./output-
|
|
12126
|
-
const { handleMetaError: handleMetaError2 } = await import("./shared-
|
|
12126
|
+
const { apiPost: apiPost2 } = await import("./client-N7XWYCHT.js");
|
|
12127
|
+
const { requireChatId: requireChatId2 } = await import("./env-3JMYIH25.js");
|
|
12128
|
+
const { writeJsonEnvelope: writeJsonEnvelope2 } = await import("./output-7M5VQPTZ.js");
|
|
12129
|
+
const { handleMetaError: handleMetaError2 } = await import("./shared-6SZHAUM2.js");
|
|
12127
12130
|
try {
|
|
12128
12131
|
const accountId = bareAccountId2(args);
|
|
12129
12132
|
const chatId = requireChatId2();
|
|
@@ -28076,5 +28079,7 @@ Introspection: Run 'baker schema <command>' to inspect argument schemas.`
|
|
|
28076
28079
|
schema: schemaCommand
|
|
28077
28080
|
}
|
|
28078
28081
|
});
|
|
28082
|
+
installStreamTaps();
|
|
28083
|
+
logInvocation(process.argv.slice(2));
|
|
28079
28084
|
runMain(main);
|
|
28080
28085
|
//# sourceMappingURL=cli.js.map
|