@adkit/cli 1.13.7 → 1.13.8
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/cli.js +40 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7406,6 +7406,8 @@ var open_default = open;
|
|
|
7406
7406
|
import { unlinkSync, existsSync as existsSync2 } from "node:fs";
|
|
7407
7407
|
import { hostname } from "node:os";
|
|
7408
7408
|
var MAX_POLL_ATTEMPTS = 450;
|
|
7409
|
+
var MAX_CONSECUTIVE_POLL_NETWORK_FAILURES = 5;
|
|
7410
|
+
var POLL_INTERVAL_MS = 2e3;
|
|
7409
7411
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
7410
7412
|
function isSessionResponse(v) {
|
|
7411
7413
|
return v !== null && typeof v === "object" && "session" in v && v.session !== null && typeof v.session === "object" && "sessionId" in v.session && typeof v.session.sessionId === "string";
|
|
@@ -7511,6 +7513,9 @@ async function fetchPollResponse(baseUrl, sessionId) {
|
|
|
7511
7513
|
throw new Error("Network connection failed during polling");
|
|
7512
7514
|
}
|
|
7513
7515
|
}
|
|
7516
|
+
async function waitForNextPoll() {
|
|
7517
|
+
await new Promise((resolveDelay) => setTimeout(resolveDelay, POLL_INTERVAL_MS));
|
|
7518
|
+
}
|
|
7514
7519
|
async function readPollData(baseUrl, sessionId) {
|
|
7515
7520
|
const pollResponse = await fetchPollResponse(baseUrl, sessionId);
|
|
7516
7521
|
if (!pollResponse.ok) {
|
|
@@ -7526,8 +7531,19 @@ async function readPollData(baseUrl, sessionId) {
|
|
|
7526
7531
|
}
|
|
7527
7532
|
}
|
|
7528
7533
|
async function waitForSetupConfig(baseUrl, sessionId) {
|
|
7534
|
+
let consecutiveNetworkFailures = 0;
|
|
7529
7535
|
for (let attempt = 0; attempt < MAX_POLL_ATTEMPTS; attempt++) {
|
|
7530
|
-
|
|
7536
|
+
let pollData;
|
|
7537
|
+
try {
|
|
7538
|
+
pollData = await readPollData(baseUrl, sessionId);
|
|
7539
|
+
consecutiveNetworkFailures = 0;
|
|
7540
|
+
} catch (error) {
|
|
7541
|
+
if (!(error instanceof Error) || error.message !== "Network connection failed during polling") throw error;
|
|
7542
|
+
consecutiveNetworkFailures++;
|
|
7543
|
+
if (consecutiveNetworkFailures > MAX_CONSECUTIVE_POLL_NETWORK_FAILURES) throw error;
|
|
7544
|
+
await waitForNextPoll();
|
|
7545
|
+
continue;
|
|
7546
|
+
}
|
|
7531
7547
|
if (!pollData) continue;
|
|
7532
7548
|
const status2 = pollData.session?.status;
|
|
7533
7549
|
if (status2 === "complete") {
|
|
@@ -7539,7 +7555,7 @@ async function waitForSetupConfig(baseUrl, sessionId) {
|
|
|
7539
7555
|
return { apiKey, projects };
|
|
7540
7556
|
}
|
|
7541
7557
|
if (status2 === "expired") throw new Error("Session expired \u2014 timed out waiting for authentication");
|
|
7542
|
-
await
|
|
7558
|
+
await waitForNextPoll();
|
|
7543
7559
|
}
|
|
7544
7560
|
throw new Error("Login timed out \u2014 max poll attempts exceeded");
|
|
7545
7561
|
}
|
|
@@ -7760,6 +7776,22 @@ function mediaUploadBody(source, flags) {
|
|
|
7760
7776
|
if (flags) mergeAccountId(body, flags);
|
|
7761
7777
|
return body;
|
|
7762
7778
|
}
|
|
7779
|
+
function wrapMetaCreateData(data, key) {
|
|
7780
|
+
if (Array.isArray(data)) return { [key]: data };
|
|
7781
|
+
if (typeof data !== "object" || data === null) return { [key]: [data] };
|
|
7782
|
+
const item = {};
|
|
7783
|
+
const body = {};
|
|
7784
|
+
for (const [entryKey, value] of Object.entries(data)) {
|
|
7785
|
+
if (entryKey === "accountId") body.accountId = value;
|
|
7786
|
+
else item[entryKey] = value;
|
|
7787
|
+
}
|
|
7788
|
+
if (key in item) {
|
|
7789
|
+
if ("accountId" in body) item.accountId = body.accountId;
|
|
7790
|
+
return item;
|
|
7791
|
+
}
|
|
7792
|
+
body[key] = [item];
|
|
7793
|
+
return body;
|
|
7794
|
+
}
|
|
7763
7795
|
function readFirstMediaUploadResult(value) {
|
|
7764
7796
|
if (typeof value !== "object" || value === null || !("assets" in value) || !Array.isArray(value.assets)) return null;
|
|
7765
7797
|
const first = value.assets[0];
|
|
@@ -7836,7 +7868,8 @@ var MEDIA_FLAGS = ["file", "url", "account"];
|
|
|
7836
7868
|
var ADSET_BID_STRATEGIES_REQUIRING_AMOUNT = /* @__PURE__ */ new Set(["cost_cap", "bid_cap"]);
|
|
7837
7869
|
async function createCampaign(client, _args, flags) {
|
|
7838
7870
|
if (typeof flags.data === "string") {
|
|
7839
|
-
const
|
|
7871
|
+
const data = parseDataFlag(flags, "Check JSON syntax in --data");
|
|
7872
|
+
const body2 = wrapMetaCreateData(data, "campaigns");
|
|
7840
7873
|
mergeAccountId(body2, flags);
|
|
7841
7874
|
const publish2 = flags.publish === true ? "?publish=true" : "";
|
|
7842
7875
|
return client.post(`/manage/meta/campaigns${publish2}`, body2);
|
|
@@ -7915,7 +7948,8 @@ async function listMetaAdSets(client, _args, flags) {
|
|
|
7915
7948
|
}
|
|
7916
7949
|
async function createAdSet(client, _args, flags) {
|
|
7917
7950
|
if (typeof flags.data === "string") {
|
|
7918
|
-
const
|
|
7951
|
+
const data = parseDataFlag(flags, "Check JSON syntax in --data");
|
|
7952
|
+
const body2 = wrapMetaCreateData(data, "adsets");
|
|
7919
7953
|
mergeAccountId(body2, flags);
|
|
7920
7954
|
const publish2 = flags.publish === true ? "?publish=true" : "";
|
|
7921
7955
|
return client.post(`/manage/meta/adsets${publish2}`, body2);
|
|
@@ -8000,7 +8034,8 @@ async function listResults(client, args, flags) {
|
|
|
8000
8034
|
}
|
|
8001
8035
|
async function createAd(client, _args, flags) {
|
|
8002
8036
|
if (typeof flags.data === "string") {
|
|
8003
|
-
const
|
|
8037
|
+
const data = parseDataFlag(flags, "Check JSON syntax in --data");
|
|
8038
|
+
const body2 = wrapMetaCreateData(data, "ads");
|
|
8004
8039
|
mergeAccountId(body2, flags);
|
|
8005
8040
|
const publish2 = flags.publish === true ? "?publish=true" : "";
|
|
8006
8041
|
return client.post(`/manage/meta/ads${publish2}`, body2);
|
package/package.json
CHANGED