@zalify/cli 0.21.0 → 0.22.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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +257 -97
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -103,6 +103,8 @@ its new home under `shop`.
103
103
  | `ads` / `ads list` | List the workspace's brand instances and their provisioning status |
104
104
  | `ads new <name> [--objective] [--budget] [--country] [--link]` | Scaffold a campaign FOLDER — the drag-and-drop form: `campaign.yaml` for budget/audience/copy defaults, `creatives/` for the files that become ads. Three questions when interactive, flags otherwise. `cp -r` an existing folder to duplicate a campaign |
105
105
  | `ads pull [--account <act_id>] [--days <n>] [--force]` | The existing account as files: every ingested campaign lands as `campaigns/<slug>.yaml` (imported form — names in `label:`, budgets, statuses, core audience) plus `campaigns/.bindings.json` mapping YAML nodes to platform ids. A hash ledger protects local edits: unedited files fast-forward, edited ones are kept and named, deletions never happen automatically |
106
+ | `ads diff` | Desired (your campaign files) vs actual (the ingested account), keyed through bindings: bound nodes compare budget/status, unbound nodes become creations. Read-only |
107
+ | `ads apply [-y] [--activate]` | Execute the diff after showing it and asking. Creations land **PAUSED** — always; budget edits apply to bound entities; `paused→active` is refused without `--activate` (turning spend on is said twice; `active→paused` always executes). Created ids merge into the bindings ledger |
106
108
  | `ads remove <slug>` | Deprecate a brand instance — soft-deletes the record (drops out of `ads list` and the service's repo-token minting; survives for history). The GitHub repo is deliberately untouched: deleting real campaign intent is a human-on-GitHub decision |
107
109
  | `ads status` | The instance at a glance: brand + consent, platform access and credential expiry, ingestion freshness (with per-account failures), first-party join coverage, plan and pending-proposal counts. Exits non-zero when the service reports problems |
108
110
  | `ads report [--date <YYYY-MM-DD>] [--platform <all\|meta\|google>]` | The daily report in the terminal — totals vs the day before, where the money moved, what changed in the account |
package/dist/cli.js CHANGED
@@ -18234,7 +18234,7 @@ function updateNotifier(options) {
18234
18234
 
18235
18235
  // src/cli.ts
18236
18236
  import { createRequire as createRequire2 } from "node:module";
18237
- import { dirname as dirname3, join as join12 } from "node:path";
18237
+ import { dirname as dirname3, join as join13 } from "node:path";
18238
18238
  import { fileURLToPath as fileURLToPath3 } from "node:url";
18239
18239
 
18240
18240
  // src/auth.ts
@@ -20338,33 +20338,235 @@ async function adsList() {
20338
20338
  }
20339
20339
  }
20340
20340
 
20341
+ // src/ads-diff.ts
20342
+ import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync8 } from "node:fs";
20343
+ import { join as join9, resolve as resolve7 } from "node:path";
20344
+ import { createInterface as createInterface2 } from "node:readline/promises";
20345
+
20346
+ // node_modules/yaml/dist/index.js
20347
+ var composer = require_composer();
20348
+ var Document = require_Document();
20349
+ var Schema = require_Schema();
20350
+ var errors = require_errors();
20351
+ var Alias = require_Alias();
20352
+ var identity = require_identity();
20353
+ var Pair = require_Pair();
20354
+ var Scalar = require_Scalar();
20355
+ var YAMLMap = require_YAMLMap();
20356
+ var YAMLSeq = require_YAMLSeq();
20357
+ var cst = require_cst();
20358
+ var lexer = require_lexer();
20359
+ var lineCounter = require_line_counter();
20360
+ var parser = require_parser();
20361
+ var publicApi = require_public_api();
20362
+ var visit = require_visit();
20363
+ var $Composer = composer.Composer;
20364
+ var $Document = Document.Document;
20365
+ var $Schema = Schema.Schema;
20366
+ var $YAMLError = errors.YAMLError;
20367
+ var $YAMLParseError = errors.YAMLParseError;
20368
+ var $YAMLWarning = errors.YAMLWarning;
20369
+ var $Alias = Alias.Alias;
20370
+ var $isAlias = identity.isAlias;
20371
+ var $isCollection = identity.isCollection;
20372
+ var $isDocument = identity.isDocument;
20373
+ var $isMap = identity.isMap;
20374
+ var $isNode = identity.isNode;
20375
+ var $isPair = identity.isPair;
20376
+ var $isScalar = identity.isScalar;
20377
+ var $isSeq = identity.isSeq;
20378
+ var $Pair = Pair.Pair;
20379
+ var $Scalar = Scalar.Scalar;
20380
+ var $YAMLMap = YAMLMap.YAMLMap;
20381
+ var $YAMLSeq = YAMLSeq.YAMLSeq;
20382
+ var $Lexer = lexer.Lexer;
20383
+ var $LineCounter = lineCounter.LineCounter;
20384
+ var $Parser = parser.Parser;
20385
+ var $parse = publicApi.parse;
20386
+ var $parseAllDocuments = publicApi.parseAllDocuments;
20387
+ var $parseDocument = publicApi.parseDocument;
20388
+ var $stringify = publicApi.stringify;
20389
+ var $visit = visit.visit;
20390
+ var $visitAsync = visit.visitAsync;
20391
+
20392
+ // src/ads-diff.ts
20393
+ function root() {
20394
+ const cwd = resolve7(".");
20395
+ if (existsSync9(join9(cwd, ".zalify", "brand-repo.json")) || existsSync9(join9(cwd, "campaigns"))) {
20396
+ return cwd;
20397
+ }
20398
+ throw new Error("Not inside a brand-instance checkout — run from the repo `zalify ads create` made.");
20399
+ }
20400
+ function collect(base) {
20401
+ const dir2 = join9(base, "campaigns");
20402
+ if (!existsSync9(dir2))
20403
+ return { files: [], folders: 0 };
20404
+ const files = [];
20405
+ let folders = 0;
20406
+ for (const entry of readdirSync3(dir2, { withFileTypes: true })) {
20407
+ if (entry.isDirectory()) {
20408
+ if (existsSync9(join9(dir2, entry.name, "campaign.yaml")))
20409
+ folders += 1;
20410
+ continue;
20411
+ }
20412
+ if (!entry.name.endsWith(".yaml") || entry.name.endsWith(".copy.yaml")) {
20413
+ continue;
20414
+ }
20415
+ const path9 = `campaigns/${entry.name}`;
20416
+ try {
20417
+ files.push({ path: path9, doc: $parse(readFileSync7(join9(base, path9), "utf8")) });
20418
+ } catch (err) {
20419
+ throw new Error(`${path9} is not valid YAML: ${String(err).slice(0, 120)}`);
20420
+ }
20421
+ }
20422
+ return { files, folders };
20423
+ }
20424
+ function ledger(base) {
20425
+ const path9 = join9(base, "campaigns", ".bindings.json");
20426
+ if (!existsSync9(path9))
20427
+ return { nodes: {}, pulled: {} };
20428
+ const raw = JSON.parse(readFileSync7(path9, "utf8"));
20429
+ return { nodes: raw.nodes ?? {}, pulled: raw.pulled ?? {} };
20430
+ }
20431
+ async function post(auth, path9, payload) {
20432
+ const res = await fetch(`${auth.appUrl}/api/autopilot/${path9}`, {
20433
+ method: "POST",
20434
+ headers: {
20435
+ Authorization: `Bearer ${auth.key}`,
20436
+ "x-zalify-workspace-id": auth.workspaceId,
20437
+ "Content-Type": "application/json"
20438
+ },
20439
+ body: JSON.stringify(payload)
20440
+ });
20441
+ const json = await res.json().catch(() => ({}));
20442
+ if (!res.ok)
20443
+ throw new Error(`${path9}: ${res.status} ${json.error ?? ""}`.trim());
20444
+ return json;
20445
+ }
20446
+ function renderPlan(result, folders) {
20447
+ for (const f of result.issues) {
20448
+ console.log(`✗ ${f.file}`);
20449
+ for (const i of f.issues)
20450
+ console.log(` ${i.path} — ${i.message}`);
20451
+ }
20452
+ for (const e of result.plan) {
20453
+ if (e.action === "create_campaign") {
20454
+ console.log(`+ campaign "${e.name}" (${e.adSets} ad sets, ${e.ads} ads) ${e.file}`);
20455
+ } else if (e.action === "create_ad_set") {
20456
+ console.log(`+ ad set "${e.name}" (${e.ads} ads) ${e.file}`);
20457
+ } else if (e.action === "create_ad") {
20458
+ console.log(`+ ad "${e.name}" ${e.file}`);
20459
+ } else if (e.action === "set_budget") {
20460
+ console.log(`~ ${e.kind} "${e.name}": budget ${e.from ?? "—"} → ${e.to}`);
20461
+ } else if (e.action === "set_status") {
20462
+ console.log(`~ ${e.kind} "${e.name}": status ${e.from ?? "—"} → ${e.to}`);
20463
+ }
20464
+ }
20465
+ const s = result.summary;
20466
+ console.log(`
20467
+ ${s.creates} to create, ${s.updates} to update, ${s.unchanged} unchanged` + `${result.issues.length ? `, ${result.issues.length} files invalid` : ""}` + `${folders ? ` (${folders} folder campaigns skipped — sync is coming)` : ""}`);
20468
+ }
20469
+ async function adsDiff() {
20470
+ const auth = requireActive();
20471
+ const base = root();
20472
+ const { files, folders } = collect(base);
20473
+ if (files.length === 0 && folders === 0) {
20474
+ console.log("No campaign files — `zalify ads pull` or `zalify ads new` first.");
20475
+ return;
20476
+ }
20477
+ const led = ledger(base);
20478
+ const result = await post(auth, "ads-code/diff", {
20479
+ files,
20480
+ bindings: led.nodes
20481
+ });
20482
+ renderPlan(result, folders);
20483
+ if (result.issues.length > 0)
20484
+ process.exitCode = 1;
20485
+ }
20486
+ async function adsApply(opts) {
20487
+ const auth = requireActive();
20488
+ const base = root();
20489
+ const { files, folders } = collect(base);
20490
+ if (files.length === 0) {
20491
+ console.log("No campaign files — `zalify ads pull` or `zalify ads new` first.");
20492
+ return;
20493
+ }
20494
+ const led = ledger(base);
20495
+ const diff = await post(auth, "ads-code/diff", {
20496
+ files,
20497
+ bindings: led.nodes
20498
+ });
20499
+ renderPlan(diff, folders);
20500
+ if (diff.issues.length > 0) {
20501
+ throw new Error("Fix the invalid files before applying.");
20502
+ }
20503
+ if (diff.plan.length === 0) {
20504
+ console.log("Nothing to apply.");
20505
+ return;
20506
+ }
20507
+ if (!opts.yes) {
20508
+ if (!process.stdin.isTTY) {
20509
+ throw new Error("Not a terminal — pass -y to apply without the prompt.");
20510
+ }
20511
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
20512
+ const answer = (await rl.question(`
20513
+ Apply? [y/N]: `)).trim().toLowerCase();
20514
+ rl.close();
20515
+ if (answer !== "y" && answer !== "yes") {
20516
+ console.log("Nothing applied.");
20517
+ return;
20518
+ }
20519
+ }
20520
+ const result = await post(auth, "ads-code/apply", {
20521
+ files,
20522
+ bindings: led.nodes,
20523
+ activate: Boolean(opts.activate)
20524
+ });
20525
+ for (const r of result.receipts) {
20526
+ console.log(`${r.ok ? "✓" : "✗"} ${r.action.replaceAll("_", " ")} ${r.name}` + `${r.id ? ` (${r.id})` : ""}${r.error ? ` — ${r.error}` : ""}`);
20527
+ }
20528
+ if (result.refusedActivations > 0) {
20529
+ console.log(`
20530
+ ${result.refusedActivations} activation${result.refusedActivations > 1 ? "s" : ""} refused — turning spend on needs --activate.`);
20531
+ }
20532
+ if (Object.keys(result.newBindings).length > 0) {
20533
+ Object.assign(led.nodes, result.newBindings);
20534
+ writeFileSync8(join9(base, "campaigns", ".bindings.json"), `${JSON.stringify(led, null, 2)}
20535
+ `);
20536
+ console.log(`
20537
+ ${Object.keys(result.newBindings).length} new bindings recorded — everything created is PAUSED.`);
20538
+ }
20539
+ if (result.receipts.some((r) => !r.ok))
20540
+ process.exitCode = 1;
20541
+ }
20542
+
20341
20543
  // src/ads-pull.ts
20342
20544
  import { createHash as createHash2 } from "node:crypto";
20343
20545
  import {
20344
- existsSync as existsSync9,
20546
+ existsSync as existsSync10,
20345
20547
  mkdirSync as mkdirSync4,
20346
- readFileSync as readFileSync7,
20347
- writeFileSync as writeFileSync8
20548
+ readFileSync as readFileSync8,
20549
+ writeFileSync as writeFileSync9
20348
20550
  } from "node:fs";
20349
- import { dirname as dirname2, join as join9, resolve as resolve7 } from "node:path";
20551
+ import { dirname as dirname2, join as join10, resolve as resolve8 } from "node:path";
20350
20552
  var sha = (s) => createHash2("sha256").update(s).digest("hex");
20351
20553
  function checkoutRoot() {
20352
- const cwd = resolve7(".");
20353
- if (existsSync9(join9(cwd, ".zalify", "brand-repo.json")) || existsSync9(join9(cwd, "campaigns"))) {
20554
+ const cwd = resolve8(".");
20555
+ if (existsSync10(join10(cwd, ".zalify", "brand-repo.json")) || existsSync10(join10(cwd, "campaigns"))) {
20354
20556
  return cwd;
20355
20557
  }
20356
20558
  throw new Error("Not inside a brand-instance checkout — run from the repo `zalify ads create` made.");
20357
20559
  }
20358
- function readBindings(root) {
20359
- const path9 = join9(root, "campaigns", ".bindings.json");
20360
- if (!existsSync9(path9))
20560
+ function readBindings(root2) {
20561
+ const path9 = join10(root2, "campaigns", ".bindings.json");
20562
+ if (!existsSync10(path9))
20361
20563
  return { nodes: {}, pulled: {} };
20362
- const raw = JSON.parse(readFileSync7(path9, "utf8"));
20564
+ const raw = JSON.parse(readFileSync8(path9, "utf8"));
20363
20565
  return { nodes: raw.nodes ?? {}, pulled: raw.pulled ?? {} };
20364
20566
  }
20365
20567
  async function adsPull(opts) {
20366
20568
  const auth = requireActive();
20367
- const root = checkoutRoot();
20569
+ const root2 = checkoutRoot();
20368
20570
  const params = new URLSearchParams;
20369
20571
  if (opts.account)
20370
20572
  params.set("account", opts.account);
@@ -20382,16 +20584,16 @@ async function adsPull(opts) {
20382
20584
  throw new Error(`export failed (${res.status}): ${body.error ?? ""}`);
20383
20585
  }
20384
20586
  const result = await res.json();
20385
- const bindings = readBindings(root);
20587
+ const bindings = readBindings(root2);
20386
20588
  let written = 0;
20387
20589
  let unchanged = 0;
20388
20590
  const skipped = [];
20389
20591
  for (const f of result.files) {
20390
- const abs = join9(root, f.path);
20592
+ const abs = join10(root2, f.path);
20391
20593
  const nextHash = sha(f.yaml);
20392
20594
  const lastPulled = bindings.pulled[f.path];
20393
- if (existsSync9(abs)) {
20394
- const current = readFileSync7(abs, "utf8");
20595
+ if (existsSync10(abs)) {
20596
+ const current = readFileSync8(abs, "utf8");
20395
20597
  if (sha(current) === nextHash) {
20396
20598
  unchanged += 1;
20397
20599
  bindings.pulled[f.path] = nextHash;
@@ -20404,17 +20606,17 @@ async function adsPull(opts) {
20404
20606
  }
20405
20607
  }
20406
20608
  mkdirSync4(dirname2(abs), { recursive: true });
20407
- writeFileSync8(abs, f.yaml);
20609
+ writeFileSync9(abs, f.yaml);
20408
20610
  bindings.pulled[f.path] = nextHash;
20409
20611
  written += 1;
20410
20612
  }
20411
20613
  Object.assign(bindings.nodes, result.bindings);
20412
- const bindingsPath = join9(root, "campaigns", ".bindings.json");
20614
+ const bindingsPath = join10(root2, "campaigns", ".bindings.json");
20413
20615
  mkdirSync4(dirname2(bindingsPath), { recursive: true });
20414
- writeFileSync8(bindingsPath, `${JSON.stringify(bindings, null, 2)}
20616
+ writeFileSync9(bindingsPath, `${JSON.stringify(bindings, null, 2)}
20415
20617
  `);
20416
20618
  const exported = new Set(result.files.map((f) => f.path));
20417
- const gone = Object.keys(bindings.pulled).filter((p) => !exported.has(p) && existsSync9(join9(root, p)));
20619
+ const gone = Object.keys(bindings.pulled).filter((p) => !exported.has(p) && existsSync10(join10(root2, p)));
20418
20620
  const s = result.summary;
20419
20621
  console.log(`pulled ${s.campaigns} campaigns (${s.adSets} ad sets, ${s.ads} ads): ` + `${written} written, ${unchanged} unchanged, ${skipped.length} kept (locally edited)`);
20420
20622
  for (const p of skipped)
@@ -20435,56 +20637,8 @@ Review with git diff; commit when it reads right.`);
20435
20637
 
20436
20638
  // src/ads-read.ts
20437
20639
  import { spawn as spawn4 } from "node:child_process";
20438
- import { existsSync as existsSync10, readFileSync as readFileSync8 } from "node:fs";
20439
- import { join as join10, resolve as resolve8 } from "node:path";
20440
-
20441
- // node_modules/yaml/dist/index.js
20442
- var composer = require_composer();
20443
- var Document = require_Document();
20444
- var Schema = require_Schema();
20445
- var errors = require_errors();
20446
- var Alias = require_Alias();
20447
- var identity = require_identity();
20448
- var Pair = require_Pair();
20449
- var Scalar = require_Scalar();
20450
- var YAMLMap = require_YAMLMap();
20451
- var YAMLSeq = require_YAMLSeq();
20452
- var cst = require_cst();
20453
- var lexer = require_lexer();
20454
- var lineCounter = require_line_counter();
20455
- var parser = require_parser();
20456
- var publicApi = require_public_api();
20457
- var visit = require_visit();
20458
- var $Composer = composer.Composer;
20459
- var $Document = Document.Document;
20460
- var $Schema = Schema.Schema;
20461
- var $YAMLError = errors.YAMLError;
20462
- var $YAMLParseError = errors.YAMLParseError;
20463
- var $YAMLWarning = errors.YAMLWarning;
20464
- var $Alias = Alias.Alias;
20465
- var $isAlias = identity.isAlias;
20466
- var $isCollection = identity.isCollection;
20467
- var $isDocument = identity.isDocument;
20468
- var $isMap = identity.isMap;
20469
- var $isNode = identity.isNode;
20470
- var $isPair = identity.isPair;
20471
- var $isScalar = identity.isScalar;
20472
- var $isSeq = identity.isSeq;
20473
- var $Pair = Pair.Pair;
20474
- var $Scalar = Scalar.Scalar;
20475
- var $YAMLMap = YAMLMap.YAMLMap;
20476
- var $YAMLSeq = YAMLSeq.YAMLSeq;
20477
- var $Lexer = lexer.Lexer;
20478
- var $LineCounter = lineCounter.LineCounter;
20479
- var $Parser = parser.Parser;
20480
- var $parse = publicApi.parse;
20481
- var $parseAllDocuments = publicApi.parseAllDocuments;
20482
- var $parseDocument = publicApi.parseDocument;
20483
- var $stringify = publicApi.stringify;
20484
- var $visit = visit.visit;
20485
- var $visitAsync = visit.visitAsync;
20486
-
20487
- // src/ads-read.ts
20640
+ import { existsSync as existsSync11, readFileSync as readFileSync9 } from "node:fs";
20641
+ import { join as join11, resolve as resolve9 } from "node:path";
20488
20642
  async function serviceGet(auth, path9) {
20489
20643
  const res = await fetch(`${auth.appUrl}/api/autopilot/${path9}`, {
20490
20644
  headers: {
@@ -20572,12 +20726,12 @@ account changes: not tracked for this platform yet` : `
20572
20726
  account changes: ${a.byPerson} by people, ${a.byMeta} automated`);
20573
20727
  }
20574
20728
  function adsDigest(dir2) {
20575
- const root = resolve8(dir2 ?? ".");
20576
- const path9 = join10(root, "signals", "latest.json");
20577
- if (!existsSync10(path9)) {
20729
+ const root2 = resolve9(dir2 ?? ".");
20730
+ const path9 = join11(root2, "signals", "latest.json");
20731
+ if (!existsSync11(path9)) {
20578
20732
  throw new Error("signals/latest.json not found — run from a brand-instance checkout " + "(and pull: the service commits a digest daily).");
20579
20733
  }
20580
- const d = JSON.parse(readFileSync8(path9, "utf8"));
20734
+ const d = JSON.parse(readFileSync9(path9, "utf8"));
20581
20735
  console.log(`digest of ${d.window.days} days (${d.window.first_date ?? "—"} … ${d.window.last_date ?? "—"}), generated ${when(d.generated_at)}`);
20582
20736
  const t = d.totals;
20583
20737
  console.log(` spend ${money(t.spend)} purchases ${num(t.purchases)} roas ${t.platform_roas ?? "—"}`);
@@ -20616,26 +20770,26 @@ function adsOpen() {
20616
20770
  }
20617
20771
  async function adsDoctor(dir2) {
20618
20772
  const auth = requireActive();
20619
- const root = resolve8(dir2 ?? ".");
20773
+ const root2 = resolve9(dir2 ?? ".");
20620
20774
  let failed = 0;
20621
20775
  const ok = (msg) => console.log(` ✓ ${msg}`);
20622
20776
  const bad = (msg) => {
20623
20777
  console.log(` ✗ ${msg}`);
20624
20778
  failed += 1;
20625
20779
  };
20626
- const linkPath = join10(root, ".zalify", "brand-repo.json");
20780
+ const linkPath = join11(root2, ".zalify", "brand-repo.json");
20627
20781
  let link = null;
20628
- if (existsSync10(linkPath)) {
20629
- link = JSON.parse(readFileSync8(linkPath, "utf8"));
20782
+ if (existsSync11(linkPath)) {
20783
+ link = JSON.parse(readFileSync9(linkPath, "utf8"));
20630
20784
  ok(`checkout linked to ${link?.repo} (slug ${link?.slug})`);
20631
20785
  } else {
20632
20786
  console.log(" - not inside a brand-instance checkout (repo checks only)");
20633
20787
  }
20634
20788
  let identity2 = null;
20635
- const identityPath = join10(root, "identity.yaml");
20636
- if (existsSync10(identityPath)) {
20789
+ const identityPath = join11(root2, "identity.yaml");
20790
+ if (existsSync11(identityPath)) {
20637
20791
  try {
20638
- identity2 = $parse(readFileSync8(identityPath, "utf8"));
20792
+ identity2 = $parse(readFileSync9(identityPath, "utf8"));
20639
20793
  ok("identity.yaml parses");
20640
20794
  if (identity2?.workspace_id && identity2.workspace_id !== auth.workspaceId) {
20641
20795
  bad(`identity.yaml workspace_id (${identity2.workspace_id}) ≠ active workspace (${auth.workspaceId}) — is the CLI on the right workspace?`);
@@ -20701,8 +20855,8 @@ ${failed} problem${failed > 1 ? "s" : ""}.`);
20701
20855
  }
20702
20856
 
20703
20857
  // src/brand.ts
20704
- import { existsSync as existsSync11, mkdirSync as mkdirSync5, readdirSync as readdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync9 } from "node:fs";
20705
- import { basename as basename5, join as join11, resolve as resolve9 } from "node:path";
20858
+ import { existsSync as existsSync12, mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync10, writeFileSync as writeFileSync10 } from "node:fs";
20859
+ import { basename as basename5, join as join12, resolve as resolve10 } from "node:path";
20706
20860
  var AUTHORING_MD = `# Brand authoring guide
20707
20861
 
20708
20862
  The rules for filling in this folder. An author — human or AI agent —
@@ -21003,19 +21157,19 @@ var MANIFEST_JSON = JSON.stringify({
21003
21157
  }, null, 2) + `
21004
21158
  `;
21005
21159
  function brandInit(dir2 = ".", opts = {}) {
21006
- const target = resolve9(dir2);
21160
+ const target = resolve10(dir2);
21007
21161
  const slug = basename5(target).toLowerCase().replaceAll(/[^a-z0-9-]+/g, "-").replaceAll(/^-+|-+$/g, "");
21008
- if (existsSync11(target) && readdirSync3(target).length > 0) {
21162
+ if (existsSync12(target) && readdirSync4(target).length > 0) {
21009
21163
  throw new Error(`${dir2} already exists and is not empty`);
21010
21164
  }
21011
21165
  const name = opts.name ?? slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
21012
21166
  const currency = (opts.currency ?? "USD").toUpperCase();
21013
- mkdirSync5(join11(target, "images"), { recursive: true });
21014
- writeFileSync9(join11(target, "AUTHORING.md"), AUTHORING_MD);
21015
- writeFileSync9(join11(target, "brand.md"), BRAND_MD(name));
21016
- writeFileSync9(join11(target, "store.json"), STORE_JSON(name, slug, opts.vertical ?? "<vertical>", currency));
21017
- writeFileSync9(join11(target, "catalog.json"), CATALOG_JSON(name, currency));
21018
- writeFileSync9(join11(target, "images", "manifest.json"), MANIFEST_JSON);
21167
+ mkdirSync5(join12(target, "images"), { recursive: true });
21168
+ writeFileSync10(join12(target, "AUTHORING.md"), AUTHORING_MD);
21169
+ writeFileSync10(join12(target, "brand.md"), BRAND_MD(name));
21170
+ writeFileSync10(join12(target, "store.json"), STORE_JSON(name, slug, opts.vertical ?? "<vertical>", currency));
21171
+ writeFileSync10(join12(target, "catalog.json"), CATALOG_JSON(name, currency));
21172
+ writeFileSync10(join12(target, "images", "manifest.json"), MANIFEST_JSON);
21019
21173
  console.log(`Scaffolded brand data in ${dir2}:`);
21020
21174
  for (const f of ["AUTHORING.md", "brand.md", "store.json", "catalog.json", "images/manifest.json"]) {
21021
21175
  console.log(` + ${f}`);
@@ -21026,23 +21180,23 @@ Author in this order: brand.md → catalog.json → images/manifest.json` + `
21026
21180
  }
21027
21181
  var MANIFEST_SIZES = new Set(["1024x1024", "1536x1024", "1024x1536"]);
21028
21182
  function brandValidate(dir2 = ".") {
21029
- const target = resolve9(dir2);
21183
+ const target = resolve10(dir2);
21030
21184
  const problems = [];
21031
21185
  const warnings = [];
21032
21186
  const readJson2 = (rel) => {
21033
- const path9 = join11(target, rel);
21034
- if (!existsSync11(path9)) {
21187
+ const path9 = join12(target, rel);
21188
+ if (!existsSync12(path9)) {
21035
21189
  problems.push(`missing ${rel}`);
21036
21190
  return null;
21037
21191
  }
21038
21192
  try {
21039
- return JSON.parse(readFileSync9(path9, "utf8"));
21193
+ return JSON.parse(readFileSync10(path9, "utf8"));
21040
21194
  } catch (err) {
21041
21195
  problems.push(`${rel}: invalid JSON — ${err instanceof Error ? err.message : err}`);
21042
21196
  return null;
21043
21197
  }
21044
21198
  };
21045
- if (!existsSync11(join11(target, "brand.md")))
21199
+ if (!existsSync12(join12(target, "brand.md")))
21046
21200
  problems.push("missing brand.md");
21047
21201
  const store = readJson2("store.json");
21048
21202
  if (store && (!store.name || !store.slug))
@@ -21218,7 +21372,7 @@ function brandValidate(dir2 = ".") {
21218
21372
  // src/cli.ts
21219
21373
  var __dirname4 = dirname3(fileURLToPath3(import.meta.url));
21220
21374
  var require2 = createRequire2(import.meta.url);
21221
- var pkg = require2(join12(__dirname4, "..", "package.json"));
21375
+ var pkg = require2(join13(__dirname4, "..", "package.json"));
21222
21376
  try {
21223
21377
  updateNotifier({ pkg }).notify({
21224
21378
  isGlobal: true,
@@ -21306,6 +21460,12 @@ ads.command("new <name>").description("Scaffold a campaign folder — drop image
21306
21460
  ads.command("pull").description("The existing account as files — campaigns/<slug>.yaml + bindings, from what the service has ingested").option("--account <act_id>", "one ad account only").option("--days <n>", "ads seen in the trailing window (default 30)").option("--force", "overwrite locally edited files").action(async (options) => {
21307
21461
  await adsPull(options);
21308
21462
  });
21463
+ ads.command("diff").description("Desired (your files) vs actual (the ingested account) — what apply would do").action(async () => {
21464
+ await adsDiff();
21465
+ });
21466
+ ads.command("apply").description("Execute the diff: creations land PAUSED; budget edits apply; activation needs --activate").option("--activate", "allow paused → active status changes (turning spend ON)").option("-y, --yes", "skip the confirmation prompt").action(async (options) => {
21467
+ await adsApply(options);
21468
+ });
21309
21469
  ads.command("status").description("The brand instance at a glance: access, ingestion freshness, plans, pending proposals").action(async () => {
21310
21470
  await adsStatus();
21311
21471
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalify/cli",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Zalify CLI - command-line interface for Zalify",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",