@koda-sl/baker-cli 0.869.0-dev.0631d8a3c → 0.869.0-dev.620009099
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 +1 -3
- package/dist/{account-LHY6YM6L.js → account-5VOZ4R2X.js} +2 -2
- package/dist/{account-assets-L6BX4YUQ.js → account-assets-DOHOKM2L.js} +54 -46
- package/dist/account-assets-DOHOKM2L.js.map +1 -0
- package/dist/{account-level-OX34JQ7C.js → account-level-HLSTNJHR.js} +4 -4
- package/dist/{accounts-LNFU27BU.js → accounts-SNH3LJ2H.js} +2 -2
- package/dist/{activities-LC64DAAK.js → activities-QHDGHXMI.js} +21 -12
- package/dist/activities-QHDGHXMI.js.map +1 -0
- package/dist/{ads-VSU53JN3.js → ads-MYACXO5A.js} +3 -3
- package/dist/{ads-ZR5D7BZT.js → ads-ZDSRE7D6.js} +27 -19
- package/dist/ads-ZDSRE7D6.js.map +1 -0
- package/dist/{adsets-3NIYL2GQ.js → adsets-CZQMTJ2T.js} +48 -30
- package/dist/adsets-CZQMTJ2T.js.map +1 -0
- package/dist/{asset-writes-5ZKZDPQ4.js → asset-writes-TXYCARXJ.js} +4 -4
- package/dist/{audience-writes-NL6NRLLY.js → audience-writes-DJG7XTFA.js} +29 -15
- package/dist/audience-writes-DJG7XTFA.js.map +1 -0
- package/dist/{audiences-DL267GNQ.js → audiences-QHM26I5Y.js} +27 -15
- package/dist/audiences-QHM26I5Y.js.map +1 -0
- package/dist/{businesses-RQ6P4DOS.js → businesses-ALNQZFB4.js} +2 -2
- package/dist/{campaigns-RXDC5FSQ.js → campaigns-55VLNVCE.js} +29 -18
- package/dist/campaigns-55VLNVCE.js.map +1 -0
- package/dist/{catalogs-QAZ7ZZ5R.js → catalogs-B24HAEXZ.js} +3 -3
- package/dist/{chunk-OMJ7DVFJ.js → chunk-2WHALQOJ.js} +2 -2
- package/dist/{chunk-XFTN3ARP.js → chunk-BPIHAIWB.js} +13 -22
- package/dist/chunk-BPIHAIWB.js.map +1 -0
- package/dist/{chunk-EGM42UKF.js → chunk-EJ6B5OS5.js} +2 -2
- package/dist/{chunk-WKRVHRWY.js → chunk-VBIKO56A.js} +14 -3
- package/dist/chunk-VBIKO56A.js.map +1 -0
- package/dist/{chunk-UE5ZFTDL.js → chunk-VUJPKIJN.js} +2 -2
- package/dist/{chunk-DP76WGDV.js → chunk-YF57BX3S.js} +87 -8
- package/dist/chunk-YF57BX3S.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/{copy-writes-QYN6PBU2.js → copy-writes-S4X5XUSK.js} +4 -4
- package/dist/{creatives-CPLH3KHQ.js → creatives-BCTG6PV4.js} +32 -19
- package/dist/creatives-BCTG6PV4.js.map +1 -0
- package/dist/{custom-conversions-CTJVAZKC.js → custom-conversions-56VXFOWV.js} +27 -15
- package/dist/custom-conversions-56VXFOWV.js.map +1 -0
- package/dist/{draft-UU3F2VMJ.js → draft-OMGA2NYG.js} +2 -2
- package/dist/{insights-QU5A4XBO.js → insights-3SQWIU4E.js} +2 -2
- package/dist/{instant-experiences-EJWYFWDT.js → instant-experiences-HSRGMQ5T.js} +3 -3
- package/dist/{leads-FEEWX7OO.js → leads-LWWPMZRY.js} +3 -3
- package/dist/{linkedin-RMZMQ2ZA.js → linkedin-EBOTX37R.js} +4 -8
- package/dist/{linkedin-RMZMQ2ZA.js.map → linkedin-EBOTX37R.js.map} +1 -1
- package/dist/{media-PUOLJUN3.js → media-UODVM47L.js} +3 -3
- package/dist/{meta-HOFABFAK.js → meta-4IOVQSFF.js} +40 -40
- package/dist/{page-photos-ZBMJLL5V.js → page-photos-BCEDWPGX.js} +3 -3
- package/dist/{pages-YZC44QR2.js → pages-TZBFJXNR.js} +2 -2
- package/dist/{pixels-EX6FHVHW.js → pixels-2BG3XMZP.js} +25 -12
- package/dist/pixels-2BG3XMZP.js.map +1 -0
- package/dist/preview-HD3QAR53.js +104 -0
- package/dist/preview-HD3QAR53.js.map +1 -0
- package/dist/{preview-XXQ5AHXP.js → preview-WHUVS5JJ.js} +43 -135
- package/dist/preview-WHUVS5JJ.js.map +1 -0
- package/dist/{rule-writes-6XP7G35U.js → rule-writes-Q5NLSBF5.js} +3 -3
- package/dist/{rules-BRULCGRV.js → rules-Z7MMVOZ2.js} +41 -24
- package/dist/rules-Z7MMVOZ2.js.map +1 -0
- package/dist/{shared-64RE42DL.js → shared-AXONQS3M.js} +16 -4
- package/dist/{studies-357M2C2K.js → studies-HUINRZHD.js} +33 -16
- package/dist/studies-HUINRZHD.js.map +1 -0
- package/dist/{study-writes-HXUQRPIK.js → study-writes-SI5QXY7F.js} +3 -3
- package/dist/{targeting-7T7XHBIX.js → targeting-3XK4OLPG.js} +3 -3
- package/dist/{videos-TJG5CA7N.js → videos-C5OCSAIF.js} +2 -2
- package/dist/{write-commands-4KI6T2NF.js → write-commands-T46SVSQ7.js} +7 -7
- package/package.json +1 -1
- package/dist/account-assets-L6BX4YUQ.js.map +0 -1
- package/dist/activities-LC64DAAK.js.map +0 -1
- package/dist/ads-ZR5D7BZT.js.map +0 -1
- package/dist/adsets-3NIYL2GQ.js.map +0 -1
- package/dist/audience-writes-NL6NRLLY.js.map +0 -1
- package/dist/audiences-DL267GNQ.js.map +0 -1
- package/dist/campaigns-RXDC5FSQ.js.map +0 -1
- package/dist/chunk-DP76WGDV.js.map +0 -1
- package/dist/chunk-WKRVHRWY.js.map +0 -1
- package/dist/chunk-XFTN3ARP.js.map +0 -1
- package/dist/creatives-CPLH3KHQ.js.map +0 -1
- package/dist/custom-conversions-CTJVAZKC.js.map +0 -1
- package/dist/pixels-EX6FHVHW.js.map +0 -1
- package/dist/preview-4DDR337D.js +0 -151
- package/dist/preview-4DDR337D.js.map +0 -1
- package/dist/preview-XXQ5AHXP.js.map +0 -1
- package/dist/rules-BRULCGRV.js.map +0 -1
- package/dist/studies-357M2C2K.js.map +0 -1
- /package/dist/{account-LHY6YM6L.js.map → account-5VOZ4R2X.js.map} +0 -0
- /package/dist/{account-level-OX34JQ7C.js.map → account-level-HLSTNJHR.js.map} +0 -0
- /package/dist/{accounts-LNFU27BU.js.map → accounts-SNH3LJ2H.js.map} +0 -0
- /package/dist/{ads-VSU53JN3.js.map → ads-MYACXO5A.js.map} +0 -0
- /package/dist/{asset-writes-5ZKZDPQ4.js.map → asset-writes-TXYCARXJ.js.map} +0 -0
- /package/dist/{businesses-RQ6P4DOS.js.map → businesses-ALNQZFB4.js.map} +0 -0
- /package/dist/{catalogs-QAZ7ZZ5R.js.map → catalogs-B24HAEXZ.js.map} +0 -0
- /package/dist/{chunk-OMJ7DVFJ.js.map → chunk-2WHALQOJ.js.map} +0 -0
- /package/dist/{chunk-EGM42UKF.js.map → chunk-EJ6B5OS5.js.map} +0 -0
- /package/dist/{chunk-UE5ZFTDL.js.map → chunk-VUJPKIJN.js.map} +0 -0
- /package/dist/{copy-writes-QYN6PBU2.js.map → copy-writes-S4X5XUSK.js.map} +0 -0
- /package/dist/{draft-UU3F2VMJ.js.map → draft-OMGA2NYG.js.map} +0 -0
- /package/dist/{insights-QU5A4XBO.js.map → insights-3SQWIU4E.js.map} +0 -0
- /package/dist/{instant-experiences-EJWYFWDT.js.map → instant-experiences-HSRGMQ5T.js.map} +0 -0
- /package/dist/{leads-FEEWX7OO.js.map → leads-LWWPMZRY.js.map} +0 -0
- /package/dist/{media-PUOLJUN3.js.map → media-UODVM47L.js.map} +0 -0
- /package/dist/{meta-HOFABFAK.js.map → meta-4IOVQSFF.js.map} +0 -0
- /package/dist/{page-photos-ZBMJLL5V.js.map → page-photos-BCEDWPGX.js.map} +0 -0
- /package/dist/{pages-YZC44QR2.js.map → pages-TZBFJXNR.js.map} +0 -0
- /package/dist/{rule-writes-6XP7G35U.js.map → rule-writes-Q5NLSBF5.js.map} +0 -0
- /package/dist/{shared-64RE42DL.js.map → shared-AXONQS3M.js.map} +0 -0
- /package/dist/{study-writes-HXUQRPIK.js.map → study-writes-SI5QXY7F.js.map} +0 -0
- /package/dist/{targeting-7T7XHBIX.js.map → targeting-3XK4OLPG.js.map} +0 -0
- /package/dist/{videos-TJG5CA7N.js.map → videos-C5OCSAIF.js.map} +0 -0
- /package/dist/{write-commands-4KI6T2NF.js.map → write-commands-T46SVSQ7.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/preview.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { writeFileSync } from \"node:fs\";\nimport {\n FACEBOOK_PREVIEW_FORMATS,\n INSTAGRAM_PREVIEW_FORMATS,\n PLATFORM_SCOPED_POSITIONS,\n previewFormatForPosition,\n} from \"@baker/api/ads-meta\";\nimport { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiPost } from \"../../../client.ts\";\nimport { AD_PREVIEW_DIR, AD_PREVIEW_DIR_LABEL, renderAdPreviews } from \"../ad-preview-images.ts\";\nimport { writeAdsJson, writeJsonEnvelope } from \"../output.ts\";\nimport { handleMetaError } from \"./shared.ts\";\n\n/**\n * The `ad_format` enum of `generatepreviews` as Meta's reference lists it (every value rendered live on v26.0, 2026-10-15)\n * (read 2026-10-14), plus INSTAGRAM_SHOP — dropped from that list yet still\n * rendered live the same day, so a format an older answer named keeps working.\n */\nconst VALID_AD_FORMATS = [\n \"AUDIENCE_NETWORK_INSTREAM_VIDEO\",\n \"AUDIENCE_NETWORK_INSTREAM_VIDEO_MOBILE\",\n \"AUDIENCE_NETWORK_OUTSTREAM_VIDEO\",\n \"AUDIENCE_NETWORK_REWARDED_VIDEO\",\n \"BIZ_DISCO_FEED_MOBILE\",\n \"DESKTOP_FEED_STANDARD\",\n \"FACEBOOK_IFU_REELS_MOBILE\",\n \"FACEBOOK_PROFILE_FEED_DESKTOP\",\n \"FACEBOOK_PROFILE_FEED_MOBILE\",\n \"FACEBOOK_PROFILE_REELS_MOBILE\",\n \"FACEBOOK_REELS_BANNER\",\n \"FACEBOOK_REELS_BANNER_DESKTOP\",\n \"FACEBOOK_REELS_BANNER_FEED_ANDROID\",\n \"FACEBOOK_REELS_BANNER_FEED_ANDROID_LARGE\",\n \"FACEBOOK_REELS_BANNER_FULLSCREEN_IOS\",\n \"FACEBOOK_REELS_BANNER_FULLSCREEN_MOBILE\",\n \"FACEBOOK_REELS_MOBILE\",\n \"FACEBOOK_REELS_POSTLOOP\",\n \"FACEBOOK_REELS_POSTLOOP_FEED\",\n \"FACEBOOK_REELS_SIMILAR_PRODUCTS_MOBILE\",\n \"FACEBOOK_REELS_STICKER\",\n \"FACEBOOK_STORY_MOBILE\",\n \"FACEBOOK_STORY_STICKER_MOBILE\",\n \"INSTAGRAM_EXPLORE_CONTEXTUAL\",\n \"INSTAGRAM_EXPLORE_GRID_HOME\",\n \"INSTAGRAM_EXPLORE_IMMERSIVE\",\n \"INSTAGRAM_FEED_WEB\",\n \"INSTAGRAM_FEED_WEB_M_SITE\",\n \"INSTAGRAM_LEAD_GEN_MULTI_SUBMIT_ADS\",\n \"INSTAGRAM_PROFILE_FEED\",\n \"INSTAGRAM_PROFILE_REELS\",\n \"INSTAGRAM_REELS\",\n \"INSTAGRAM_REELS_OVERLAY\",\n \"INSTAGRAM_REELS_WEB\",\n \"INSTAGRAM_REELS_WEB_M_SITE\",\n \"INSTAGRAM_SEARCH_CHAIN\",\n \"INSTAGRAM_SEARCH_GRID\",\n \"INSTAGRAM_SHOP\",\n \"INSTAGRAM_STANDARD\",\n \"INSTAGRAM_STORY\",\n \"INSTAGRAM_STORY_EFFECT_TRAY\",\n \"INSTAGRAM_STORY_WEB\",\n \"INSTAGRAM_STORY_WEB_M_SITE\",\n \"INSTANT_ARTICLE_RECIRCULATION_AD\",\n \"INSTANT_ARTICLE_STANDARD\",\n \"INSTREAM_BANNER_DESKTOP\",\n \"INSTREAM_BANNER_FEED_IOS\",\n \"INSTREAM_BANNER_FULLSCREEN_IOS\",\n \"INSTREAM_BANNER_FULLSCREEN_MOBILE\",\n \"INSTREAM_BANNER_IMMERSIVE_MOBILE\",\n \"INSTREAM_BANNER_MOBILE\",\n \"INSTREAM_VIDEO_DESKTOP\",\n \"INSTREAM_VIDEO_FULLSCREEN_IOS\",\n \"INSTREAM_VIDEO_FULLSCREEN_MOBILE\",\n \"INSTREAM_VIDEO_IMAGE\",\n \"INSTREAM_VIDEO_IMMERSIVE_MOBILE\",\n \"INSTREAM_VIDEO_MOBILE\",\n \"JOB_BROWSER_DESKTOP\",\n \"JOB_BROWSER_MOBILE\",\n \"MARKETPLACE_MOBILE\",\n \"MESSENGER_MOBILE_INBOX_MEDIA\",\n \"MESSENGER_MOBILE_STORY_MEDIA\",\n \"MOBILE_BANNER\",\n \"MOBILE_FEED_BASIC\",\n \"MOBILE_FEED_STANDARD\",\n \"MOBILE_FULLWIDTH\",\n \"MOBILE_INTERSTITIAL\",\n \"MOBILE_MEDIUM_RECTANGLE\",\n \"MOBILE_NATIVE\",\n \"RIGHT_COLUMN_STANDARD\",\n \"SUGGESTED_VIDEO_DESKTOP\",\n \"SUGGESTED_VIDEO_FULLSCREEN_MOBILE\",\n \"SUGGESTED_VIDEO_IMMERSIVE_MOBILE\",\n \"SUGGESTED_VIDEO_MOBILE\",\n \"WATCH_FEED_HOME\",\n \"WATCH_FEED_MOBILE\",\n \"WHATSAPP_STATUS_MEDIA\",\n];\n\n/** A bad flag is not a network failure — mislabelling it invites a retry of the same doomed call. */\nfunction failPreviewValidation(message: string): never {\n writeAdsJson({ ok: false, error: { code: \"VALIDATION_ERROR\", message } });\n process.exit(1);\n}\n\n/**\n * Preview is the free way to see what Meta actually renders for a creative in a\n * given surface — the check that turns \"this placement must be showing a still\"\n * from a claim into an observation. It was being used by guessing format names,\n * so both doors are open now: the Meta `ad_format` enum via `--ad-format`, and\n * the `platform_position` an insights breakdown reports via `--placement`.\n */\nfunction resolvePlacement(position: string, platform: unknown): string {\n const platformArg = typeof platform === \"string\" ? platform.toLowerCase() : undefined;\n if (platformArg && platformArg !== \"facebook\" && platformArg !== \"instagram\") {\n failPreviewValidation(\"--platform must be facebook or instagram\");\n }\n const format = previewFormatForPosition(position, platformArg);\n if (format) {\n return format;\n }\n if (PLATFORM_SCOPED_POSITIONS.has(position) && !platformArg) {\n failPreviewValidation(\n `--placement ${position} names a different surface on Facebook and on Instagram — add --platform facebook or --platform instagram (the breakdown row's publisher_platform)`,\n );\n }\n failPreviewValidation(\n `No Meta preview format is published for placement \"${position}\". Meta does not document one for every placement (facebook_notification among them), so this placement cannot be previewed — report it as unverified rather than inferring what it renders. Pass the platform_position exactly as the insights breakdown spelled it: targeting names a few surfaces differently (story, reels, explore_home) and those names never appear in a breakdown. Previewable placements: ${listPlacements()}`,\n );\n}\n\nfunction listPlacements(): string {\n const facebook = Object.keys(FACEBOOK_PREVIEW_FORMATS).join(\", \");\n const instagram = Object.keys(INSTAGRAM_PREVIEW_FORMATS).join(\", \");\n return `facebook — ${facebook}; instagram — ${instagram}`;\n}\n\n/** File name for a preview's picture. An unpublished spec has no id, so its content names it. */\nexport function previewFileName(target: { adId?: string; creativeId?: string; creative?: string }): string {\n const id = target.adId ?? target.creativeId;\n if (id) return `meta-${id}`;\n return `meta-draft-${createHash(\"sha256\")\n .update(target.creative ?? \"\")\n .digest(\"hex\")\n .slice(0, 12)}`;\n}\n\nexport const previewCommand = defineCommand({\n meta: {\n name: \"preview\",\n description: `See a creative or ad as Meta renders it in one placement: shownText (the text people see, in order)\nplus a picture to Read for what text cannot tell (words in the artwork, cropping, how it looks).\n--out-file also saves Meta's raw iframe HTML (its URL holds a short-lived access token — treat as secret).\n\nStart here before saying anything about how an ad LOOKS (which text shows, the headline under the\nimage, the button). Start here too when you need to know what a creative looks like in one specific placement — this is\nMeta's own renderer, so it settles \"does my video show as a still image there?\" without guessing.\nPass the placement straight from an insights breakdown with --placement (a platform_position value),\nor a Meta ad_format with --ad-format. Run --list-formats to see both sets.\n\nExamples:\n baker ads meta preview --creative-id 6123 --ad-format MOBILE_FEED_STANDARD\n baker ads meta preview --creative-id 6123 --placement facebook_reels_overlay --platform facebook\n baker ads meta preview --ad-id 9988 --ad-format INSTAGRAM_REELS --out-dir /tmp/review\n baker ads meta preview --account-id act_123 --creative '{\"object_story_spec\":{...}}' --ad-format MOBILE_FEED_STANDARD`,\n },\n args: {\n \"creative-id\": { type: \"string\", description: \"Existing creative ID\" },\n \"ad-id\": { type: \"string\", description: \"Existing ad ID\" },\n \"account-id\": { type: \"string\", description: \"Required when previewing an unpublished --creative spec\" },\n creative: { type: \"string\", description: \"JSON spec of an unpublished creative (e.g. object_story_spec)\" },\n \"ad-format\": { type: \"string\", description: \"Meta ad_format enum value (--list-formats to see them)\" },\n placement: {\n type: \"string\",\n description:\n \"platform_position from an insights breakdown (e.g. facebook_reels_overlay) — resolved to an ad_format\",\n },\n platform: { type: \"string\", description: \"facebook|instagram — required for --placement feed, which both report\" },\n \"list-formats\": { type: \"boolean\", description: \"Print the ad_format values and placement mappings, then exit\" },\n \"out-file\": { type: \"string\", description: \"Also save Meta's iframe HTML to this path\" },\n \"out-dir\": { type: \"string\", description: `Folder for the picture (default: ${AD_PREVIEW_DIR_LABEL})` },\n \"no-cache\": NO_CACHE_ARG,\n },\n run: async ({ args }) => {\n if (args[\"list-formats\"]) {\n writeAdsJson({\n ok: true,\n data: {\n adFormats: VALID_AD_FORMATS,\n placements: { facebook: FACEBOOK_PREVIEW_FORMATS, instagram: INSTAGRAM_PREVIEW_FORMATS },\n },\n });\n return;\n }\n\n const placement = args.placement as string | undefined;\n const adFormat = placement ? resolvePlacement(placement, args.platform) : (args[\"ad-format\"] as string);\n if (!adFormat) {\n failPreviewValidation(\"pass --ad-format or --placement (see --list-formats)\");\n }\n if (!VALID_AD_FORMATS.includes(adFormat)) {\n failPreviewValidation(\n `Invalid --ad-format \"${adFormat}\". Meta's ad_format values: ${VALID_AD_FORMATS.join(\", \")}. To preview a placement you saw in an insights breakdown, pass --placement <platform_position> instead of guessing a format name.`,\n );\n }\n const body: Record<string, unknown> = { adFormat };\n if (args[\"creative-id\"]) body.creativeId = args[\"creative-id\"];\n if (args[\"ad-id\"]) body.adId = args[\"ad-id\"];\n if (args[\"account-id\"]) body.accountId = args[\"account-id\"];\n if (args.creative) body.creative = args.creative;\n if (args[\"no-cache\"]) body.skipCache = true;\n\n try {\n const data = await apiPost<Array<{ body: string }>>(\"/api/ads/meta/preview\", body);\n if (args[\"out-file\"]) {\n writeFileSync(args[\"out-file\"] as string, data.map((d) => d.body).join(\"\\n\"), \"utf-8\");\n }\n const rendered = await renderAdPreviews(\n data.map((d, i) => ({ placement: data.length > 1 ? `${adFormat}-${i + 1}` : adFormat, html: d.body })),\n {\n dir: args[\"out-dir\"] ? String(args[\"out-dir\"]) : AD_PREVIEW_DIR,\n name: previewFileName({\n adId: args[\"ad-id\"] as string | undefined,\n creativeId: args[\"creative-id\"] as string | undefined,\n creative: args.creative as string | undefined,\n }),\n },\n );\n const hints = placement\n ? [\n `Rendered ${placement} as ad_format ${adFormat}. Meta does not document what it renders for a creative a placement cannot take, so the picture is the evidence.`,\n ...rendered.hints,\n ]\n : rendered.hints;\n writeJsonEnvelope({\n ok: true,\n data: { adFormat, previews: rendered.previews, ...(args[\"out-file\"] ? { file: args[\"out-file\"] } : {}) },\n hints,\n });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAO9B,SAAS,qBAAqB;AAY9B,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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QAC9C,GAAG,SAAS;AAAA,MACd,IACA,SAAS;AACb,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,MAAM,EAAE,UAAU,UAAU,SAAS,UAAU,GAAI,KAAK,UAAU,IAAI,EAAE,MAAM,KAAK,UAAU,EAAE,IAAI,CAAC,EAAG;AAAA,QACvG;AAAA,MACF,CAAC;AAAA,IACH,SAAS,KAAK;AACZ,sBAAgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
fileArg,
|
|
8
8
|
requireTarget,
|
|
9
9
|
stageOp
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2WHALQOJ.js";
|
|
11
11
|
import "./chunk-3R62EYYX.js";
|
|
12
12
|
import "./chunk-GDFJOCDO.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-YF57BX3S.js";
|
|
14
14
|
import "./chunk-XD7C5OE7.js";
|
|
15
15
|
import "./chunk-UKENQSZ2.js";
|
|
16
16
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -531,4 +531,4 @@ export {
|
|
|
531
531
|
rulesRunCommand,
|
|
532
532
|
rulesUpdateCommand
|
|
533
533
|
};
|
|
534
|
-
//# sourceMappingURL=rule-writes-
|
|
534
|
+
//# sourceMappingURL=rule-writes-Q5NLSBF5.js.map
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
LISTING_ACCOUNT_ARG,
|
|
3
|
+
accountsInScope,
|
|
2
4
|
handleMetaError,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
listingLimit,
|
|
6
|
+
loggedAt,
|
|
7
|
+
readEachAccount,
|
|
8
|
+
resolveAccountIdArg,
|
|
9
|
+
withAccountColumn
|
|
10
|
+
} from "./chunk-YF57BX3S.js";
|
|
5
11
|
import "./chunk-QALAJNBG.js";
|
|
6
12
|
import {
|
|
7
13
|
writeJsonEnvelope
|
|
@@ -50,9 +56,9 @@ function ruleListHints(rows) {
|
|
|
50
56
|
}
|
|
51
57
|
registerSchema({
|
|
52
58
|
command: "ads.meta.rules",
|
|
53
|
-
description: "List the automated rules on a Meta ad account (Ads Manager \u2192 Automated rules): each rule's status and what it does, in words. --rule-id reads one; --full adds its evaluation_spec, execution_spec and schedule_spec in the shape `rules update --file` takes (money in major units of the account currency).",
|
|
59
|
+
description: "List the automated rules on a Meta ad account (Ads Manager \u2192 Automated rules): each rule's status and what it does, in words. --rule-id reads one; --full adds its evaluation_spec, execution_spec and schedule_spec in the shape `rules update --file` takes (money in major units of the account currency). With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
54
60
|
args: {
|
|
55
|
-
"account-id": {
|
|
61
|
+
"account-id": { ...LISTING_ACCOUNT_ARG, required: false },
|
|
56
62
|
"rule-id": { type: "string", description: "Read one rule", required: false },
|
|
57
63
|
full: { type: "boolean", description: "Include the specs and timestamps", required: false }
|
|
58
64
|
}
|
|
@@ -63,18 +69,23 @@ var listCommand = defineCommand({
|
|
|
63
69
|
description: "List automated rules. Runs by default. Example: baker ads meta rules --account-id act_123 \xB7 one rule in full: baker ads meta rules --rule-id 1132635173044914 --full"
|
|
64
70
|
},
|
|
65
71
|
args: {
|
|
66
|
-
"account-id":
|
|
72
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
67
73
|
"rule-id": { type: "string", description: "Read one rule" },
|
|
68
74
|
full: { type: "boolean", description: "Include the specs and timestamps" }
|
|
69
75
|
},
|
|
70
76
|
run: async ({ args }) => {
|
|
71
|
-
const
|
|
77
|
+
const accounts = await accountsInScope(args);
|
|
72
78
|
try {
|
|
73
|
-
const params = {
|
|
79
|
+
const params = {};
|
|
74
80
|
if (args["rule-id"]) params["rule-id"] = String(args["rule-id"]);
|
|
75
|
-
const
|
|
81
|
+
const read = await readEachAccount(
|
|
82
|
+
accounts,
|
|
83
|
+
(accountId) => apiGet("/api/ads/meta/rules", { ...params, "account-id": accountId })
|
|
84
|
+
);
|
|
85
|
+
const rows = read.rows;
|
|
76
86
|
const full = Boolean(args.full) || Boolean(args["rule-id"]);
|
|
77
|
-
|
|
87
|
+
const data = full ? withAccountColumn(rows, read.accountOf) : withAccountColumn(rows.map(compactRule), read.accountOf);
|
|
88
|
+
writeJsonEnvelope({ ok: true, data, hints: [...read.hints, ...ruleListHints(rows)] });
|
|
78
89
|
} catch (err) {
|
|
79
90
|
handleMetaError(err);
|
|
80
91
|
}
|
|
@@ -100,9 +111,9 @@ function compactHistory(row) {
|
|
|
100
111
|
}
|
|
101
112
|
registerSchema({
|
|
102
113
|
command: "ads.meta.rules.history",
|
|
103
|
-
description: "What automated rules did and when: each run with the objects it changed (PAUSED, CHANGED_BUDGET, \u2026, old \u2192 new value). Without --rule-id, every rule on the account, newest first.",
|
|
114
|
+
description: "What automated rules did and when: each run with the objects it changed (PAUSED, CHANGED_BUDGET, \u2026, old \u2192 new value). Without --rule-id, every rule on the account, newest first. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
104
115
|
args: {
|
|
105
|
-
"account-id": {
|
|
116
|
+
"account-id": { ...LISTING_ACCOUNT_ARG, required: false },
|
|
106
117
|
"rule-id": { type: "string", description: "One rule's runs", required: false },
|
|
107
118
|
"object-id": { type: "string", description: "Only runs that touched this ad, ad set or campaign", required: false },
|
|
108
119
|
action: { type: "string", description: "Only this action, e.g. PAUSED, CHANGED_BUDGET", required: false },
|
|
@@ -117,7 +128,7 @@ var historyCommand = defineCommand({
|
|
|
117
128
|
description: "What rules did and when. Example: baker ads meta rules history --rule-id 1132635173044914 --hide-no-changes \xB7 every rule: baker ads meta rules history --account-id act_123"
|
|
118
129
|
},
|
|
119
130
|
args: {
|
|
120
|
-
"account-id":
|
|
131
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
121
132
|
"rule-id": { type: "string", description: "One rule's runs" },
|
|
122
133
|
"object-id": { type: "string", description: "Only runs that touched this object" },
|
|
123
134
|
action: { type: "string", description: "Only this action (PAUSED, CHANGED_BUDGET, \u2026)" },
|
|
@@ -126,18 +137,24 @@ var historyCommand = defineCommand({
|
|
|
126
137
|
full: { type: "boolean", description: "Include the rule's specs at each run" }
|
|
127
138
|
},
|
|
128
139
|
run: async ({ args }) => {
|
|
129
|
-
const
|
|
140
|
+
const accounts = await accountsInScope(args);
|
|
130
141
|
try {
|
|
131
|
-
const params = {
|
|
142
|
+
const params = {};
|
|
132
143
|
for (const key of ["rule-id", "object-id", "action", "limit"]) {
|
|
133
144
|
if (args[key]) params[key] = String(args[key]);
|
|
134
145
|
}
|
|
135
146
|
if (args["hide-no-changes"]) params["hide-no-changes"] = "true";
|
|
136
|
-
const
|
|
147
|
+
const read = await readEachAccount(
|
|
148
|
+
accounts,
|
|
149
|
+
(accountId) => apiGet("/api/ads/meta/rules/history", { ...params, "account-id": accountId }),
|
|
150
|
+
{ limit: listingLimit(args, 50), time: (row) => loggedAt(row.timestamp) }
|
|
151
|
+
);
|
|
152
|
+
const rows = read.rows;
|
|
137
153
|
const hints = rows.length === 0 ? [
|
|
138
154
|
"No runs recorded. A daily rule first runs just after midnight in the ad account's time zone; a switched-off rule never runs."
|
|
139
155
|
] : [];
|
|
140
|
-
|
|
156
|
+
const data = withAccountColumn(args.full ? rows : rows.map(compactHistory), read.accountOf);
|
|
157
|
+
writeJsonEnvelope({ ok: true, data, hints: [...read.hints, ...hints] });
|
|
141
158
|
} catch (err) {
|
|
142
159
|
handleMetaError(err);
|
|
143
160
|
}
|
|
@@ -194,15 +211,15 @@ Examples:
|
|
|
194
211
|
list: listCommand,
|
|
195
212
|
history: historyCommand,
|
|
196
213
|
preview: previewCommand,
|
|
197
|
-
create: () => import("./rule-writes-
|
|
198
|
-
update: () => import("./rule-writes-
|
|
199
|
-
enable: () => import("./rule-writes-
|
|
200
|
-
disable: () => import("./rule-writes-
|
|
201
|
-
delete: () => import("./rule-writes-
|
|
202
|
-
run: () => import("./rule-writes-
|
|
214
|
+
create: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesCreateCommand),
|
|
215
|
+
update: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesUpdateCommand),
|
|
216
|
+
enable: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesEnableCommand),
|
|
217
|
+
disable: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesDisableCommand),
|
|
218
|
+
delete: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesDeleteCommand),
|
|
219
|
+
run: () => import("./rule-writes-Q5NLSBF5.js").then((m) => m.rulesRunCommand)
|
|
203
220
|
},
|
|
204
221
|
args: {
|
|
205
|
-
"account-id":
|
|
222
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
206
223
|
"rule-id": { type: "string", description: "Read one rule" },
|
|
207
224
|
full: { type: "boolean", description: "Include the specs and timestamps" }
|
|
208
225
|
},
|
|
@@ -214,4 +231,4 @@ export {
|
|
|
214
231
|
ruleListHints,
|
|
215
232
|
rulesCommand
|
|
216
233
|
};
|
|
217
|
-
//# sourceMappingURL=rules-
|
|
234
|
+
//# sourceMappingURL=rules-Z7MMVOZ2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/rules.ts"],"sourcesContent":["import type { MetaAdRuleHistoryRow, MetaAdRuleRow } from \"@baker/api/ads-meta/adRules\";\nimport { defineCommand } from \"citty\";\nimport { apiGet } from \"../../../client.ts\";\nimport { registerSchema } from \"../../../schemas.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport {\n accountsInScope,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n listingLimit,\n loggedAt,\n readEachAccount,\n resolveAccountIdArg,\n withAccountColumn,\n} from \"./shared.ts\";\n\n/**\n * Meta automated rules — reads. A rule is Meta's own automation: it runs on\n * Meta, on Meta's schedule, with no Baker involvement once created. Writes\n * (create / update / enable / disable / delete) stage like every Meta change\n * and live in `rule-writes.ts`.\n */\n\n/** What an agent needs to pick a rule and know what it does. Specs sit behind --full. */\nexport function compactRule(row: MetaAdRuleRow): Record<string, unknown> {\n return {\n id: row.id,\n name: row.name,\n status: row.status,\n does: row.description,\n ...(row.disable_error_code ? { disable_error_code: row.disable_error_code } : {}),\n updated_time: row.updated_time,\n };\n}\n\nexport function ruleListHints(rows: readonly MetaAdRuleRow[]): string[] {\n const hints: string[] = [];\n if (rows.length === 0) {\n hints.push(\n 'No automated rules on this account. Stage one with `baker ads meta rules create --name … --apply-to ad --when \"cost_per_result>20\" --action pause`.',\n );\n }\n const issues = rows.filter((row) => row.status === \"HAS_ISSUES\");\n if (issues.length > 0) {\n hints.push(\n `${issues.map((row) => row.name ?? row.id).join(\", \")} ${issues.length === 1 ? \"has\" : \"have\"} been stopped by Meta (HAS_ISSUES) — read it with --rule-id and fix the spec with \\`rules update\\`.`,\n );\n }\n if (rows.length > 0) {\n hints.push(\n \"`rules history --rule-id <id>` shows what a rule did and when; `rules preview <id>` what it would act on now.\",\n );\n }\n return hints;\n}\n\nregisterSchema({\n command: \"ads.meta.rules\",\n description:\n \"List the automated rules on a Meta ad account (Ads Manager → Automated rules): each rule's status and what it does, in words. --rule-id reads one; --full adds its evaluation_spec, execution_spec and schedule_spec in the shape `rules update --file` takes (money in major units of the account currency). With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n args: {\n \"account-id\": { ...LISTING_ACCOUNT_ARG, required: false },\n \"rule-id\": { type: \"string\", description: \"Read one rule\", required: false },\n full: { type: \"boolean\", description: \"Include the specs and timestamps\", required: false },\n },\n});\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List automated rules. Runs by default. Example: baker ads meta rules --account-id act_123 · one rule in full: baker ads meta rules --rule-id 1132635173044914 --full\",\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"rule-id\": { type: \"string\", description: \"Read one rule\" },\n full: { type: \"boolean\", description: \"Include the specs and timestamps\" },\n },\n run: async ({ args }) => {\n const accounts = await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n if (args[\"rule-id\"]) params[\"rule-id\"] = String(args[\"rule-id\"]);\n const read = await readEachAccount(accounts, (accountId) =>\n apiGet<MetaAdRuleRow[]>(\"/api/ads/meta/rules\", { ...params, \"account-id\": accountId }),\n );\n const rows = read.rows;\n const full = Boolean(args.full) || Boolean(args[\"rule-id\"]);\n const data = full\n ? withAccountColumn(rows, read.accountOf)\n : withAccountColumn(rows.map(compactRule), read.accountOf);\n writeJsonEnvelope({ ok: true, data, hints: [...read.hints, ...ruleListHints(rows)] });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n/** A run in a line an agent can read: when, which rule, and what it changed. */\nexport function compactHistory(row: MetaAdRuleHistoryRow): Record<string, unknown> {\n const changes = (row.results ?? []).flatMap((result) =>\n (result.actions ?? []).map((action) => ({\n object_id: result.object_id,\n action: action.action,\n ...(action.field ? { field: action.field } : {}),\n ...(action.old_value !== undefined ? { from: action.old_value } : {}),\n ...(action.new_value !== undefined ? { to: action.new_value } : {}),\n })),\n );\n return {\n timestamp: row.timestamp,\n rule_id: row.rule_id,\n ...(row.is_manual ? { manual: true } : {}),\n changes,\n ...(row.exception_message ? { error: row.exception_message } : {}),\n };\n}\n\nregisterSchema({\n command: \"ads.meta.rules.history\",\n description:\n \"What automated rules did and when: each run with the objects it changed (PAUSED, CHANGED_BUDGET, …, old → new value). Without --rule-id, every rule on the account, newest first. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n args: {\n \"account-id\": { ...LISTING_ACCOUNT_ARG, required: false },\n \"rule-id\": { type: \"string\", description: \"One rule's runs\", required: false },\n \"object-id\": { type: \"string\", description: \"Only runs that touched this ad, ad set or campaign\", required: false },\n action: { type: \"string\", description: \"Only this action, e.g. PAUSED, CHANGED_BUDGET\", required: false },\n \"hide-no-changes\": { type: \"boolean\", description: \"Drop runs that changed nothing\", required: false },\n limit: { type: \"string\", description: \"Max runs (default 50)\", required: false },\n full: { type: \"boolean\", description: \"Include the rule's specs at each run\", required: false },\n },\n});\n\nconst historyCommand = defineCommand({\n meta: {\n name: \"history\",\n description:\n \"What rules did and when. Example: baker ads meta rules history --rule-id 1132635173044914 --hide-no-changes · every rule: baker ads meta rules history --account-id act_123\",\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"rule-id\": { type: \"string\", description: \"One rule's runs\" },\n \"object-id\": { type: \"string\", description: \"Only runs that touched this object\" },\n action: { type: \"string\", description: \"Only this action (PAUSED, CHANGED_BUDGET, …)\" },\n \"hide-no-changes\": { type: \"boolean\", description: \"Drop runs that changed nothing\" },\n limit: { type: \"string\", description: \"Max runs (default 50)\" },\n full: { type: \"boolean\", description: \"Include the rule's specs at each run\" },\n },\n run: async ({ args }) => {\n const accounts = await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n for (const key of [\"rule-id\", \"object-id\", \"action\", \"limit\"] as const) {\n if (args[key]) params[key] = String(args[key]);\n }\n if (args[\"hide-no-changes\"]) params[\"hide-no-changes\"] = \"true\";\n const read = await readEachAccount(\n accounts,\n (accountId) =>\n apiGet<MetaAdRuleHistoryRow[]>(\"/api/ads/meta/rules/history\", { ...params, \"account-id\": accountId }),\n { limit: listingLimit(args, 50), time: (row) => loggedAt(row.timestamp) },\n );\n const rows = read.rows;\n const hints =\n rows.length === 0\n ? [\n \"No runs recorded. A daily rule first runs just after midnight in the ad account's time zone; a switched-off rule never runs.\",\n ]\n : [];\n const data = withAccountColumn(args.full ? rows : rows.map(compactHistory), read.accountOf);\n writeJsonEnvelope({ ok: true, data, hints: [...read.hints, ...hints] });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nregisterSchema({\n command: \"ads.meta.rules.preview\",\n description:\n \"Which ads, ad sets or campaigns a live schedule rule would act on right now, by Meta's own evaluation. Changes nothing.\",\n args: {\n id: { type: \"positional\", description: \"Rule id\", required: true },\n \"account-id\": { type: \"string\", description: \"Meta ad account ID (act_123)\", required: false },\n },\n});\n\nconst previewCommand = defineCommand({\n meta: {\n name: \"preview\",\n description:\n \"What a rule would act on right now (changes nothing). Example: baker ads meta rules preview 1132635173044914\",\n },\n args: {\n id: { type: \"positional\", description: \"Rule id\", required: true },\n \"account-id\": { type: \"string\", description: \"Meta ad account ID\" },\n },\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n try {\n const data = await apiGet<{ ruleId: string; matched: unknown[] }>(\"/api/ads/meta/rules/preview\", {\n \"account-id\": accountId,\n \"rule-id\": String(args.id),\n });\n const hints =\n data.matched.length === 0 ? [\"Nothing matches right now — the rule would change nothing if it ran now.\"] : [];\n writeJsonEnvelope({ ok: true, data, hints });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const rulesCommand = defineCommand({\n meta: {\n name: \"rules\",\n description: `Meta automated rules — Meta's own automation, which runs on Meta with no Baker involvement once created.\nUse one for a standing \"if this metric crosses that line, do X\" that needs no judgement; use a Baker scheduled agent when the call needs reasoning.\n\nExamples:\n baker ads meta rules --account-id act_123 # every rule, what it does\n baker ads meta rules --rule-id 1132635173044914 # one rule with its specs\n baker ads meta rules history --rule-id 1132635173044914 --hide-no-changes # what it did\n baker ads meta rules preview 1132635173044914 # what it would act on now\n baker ads meta rules create --name \"Stop expensive ads\" --apply-to ad --when \"cost_per_result>20\" --action pause\n baker ads meta rules update 1132635173044914 --name \"Stop very expensive ads\"\n baker ads meta rules disable|enable|delete 1132635173044914\n baker ads meta rules run 1132635173044914 # run it once, at publish`,\n },\n subCommands: {\n list: listCommand,\n history: historyCommand,\n preview: previewCommand,\n create: () => import(\"./rule-writes.ts\").then((m) => m.rulesCreateCommand),\n update: () => import(\"./rule-writes.ts\").then((m) => m.rulesUpdateCommand),\n enable: () => import(\"./rule-writes.ts\").then((m) => m.rulesEnableCommand),\n disable: () => import(\"./rule-writes.ts\").then((m) => m.rulesDisableCommand),\n delete: () => import(\"./rule-writes.ts\").then((m) => m.rulesDeleteCommand),\n run: () => import(\"./rule-writes.ts\").then((m) => m.rulesRunCommand),\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"rule-id\": { type: \"string\", description: \"Read one rule\" },\n full: { type: \"boolean\", description: \"Include the specs and timestamps\" },\n },\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,qBAAqB;AAuBvB,SAAS,YAAY,KAA6C;AACvE,SAAO;AAAA,IACL,IAAI,IAAI;AAAA,IACR,MAAM,IAAI;AAAA,IACV,QAAQ,IAAI;AAAA,IACZ,MAAM,IAAI;AAAA,IACV,GAAI,IAAI,qBAAqB,EAAE,oBAAoB,IAAI,mBAAmB,IAAI,CAAC;AAAA,IAC/E,cAAc,IAAI;AAAA,EACpB;AACF;AAEO,SAAS,cAAc,MAA0C;AACtE,QAAM,QAAkB,CAAC;AACzB,MAAI,KAAK,WAAW,GAAG;AACrB,UAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,KAAK,OAAO,CAAC,QAAQ,IAAI,WAAW,YAAY;AAC/D,MAAI,OAAO,SAAS,GAAG;AACrB,UAAM;AAAA,MACJ,GAAG,OAAO,IAAI,CAAC,QAAQ,IAAI,QAAQ,IAAI,EAAE,EAAE,KAAK,IAAI,CAAC,IAAI,OAAO,WAAW,IAAI,QAAQ,MAAM;AAAA,IAC/F;AAAA,EACF;AACA,MAAI,KAAK,SAAS,GAAG;AACnB,UAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,eAAe;AAAA,EACb,SAAS;AAAA,EACT,aACE;AAAA,EACF,MAAM;AAAA,IACJ,cAAc,EAAE,GAAG,qBAAqB,UAAU,MAAM;AAAA,IACxD,WAAW,EAAE,MAAM,UAAU,aAAa,iBAAiB,UAAU,MAAM;AAAA,IAC3E,MAAM,EAAE,MAAM,WAAW,aAAa,oCAAoC,UAAU,MAAM;AAAA,EAC5F;AACF,CAAC;AAED,IAAM,cAAc,cAAc;AAAA,EAChC,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,a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AM,UAAU,aAAa,gBAAgB;AAAA,IAC1D,MAAM,EAAE,MAAM,WAAW,aAAa,mCAAmC;AAAA,EAC3E;AAAA,EACA,SAAS;AACX,CAAC;","names":[]}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
LISTING_ACCOUNT_ARG,
|
|
2
3
|
NAME_CONTAINS_ARG,
|
|
4
|
+
accountsInScope,
|
|
3
5
|
csvOrJson,
|
|
4
6
|
daysAgoIso,
|
|
5
7
|
getDateRange,
|
|
6
8
|
handleMetaError,
|
|
9
|
+
listingLimit,
|
|
10
|
+
loggedAt,
|
|
7
11
|
metaForbiddenFix,
|
|
8
12
|
normalizeMetaAccountId,
|
|
13
|
+
readEachAccount,
|
|
9
14
|
resolveAccountIdArg,
|
|
10
15
|
resolveEffectiveStatus,
|
|
11
16
|
statusFilterHints,
|
|
12
|
-
todayIso
|
|
13
|
-
|
|
17
|
+
todayIso,
|
|
18
|
+
withAccountColumn
|
|
19
|
+
} from "./chunk-YF57BX3S.js";
|
|
14
20
|
import "./chunk-QALAJNBG.js";
|
|
15
21
|
import "./chunk-NX4EB2TK.js";
|
|
16
22
|
import "./chunk-EHEPW3O2.js";
|
|
@@ -19,16 +25,22 @@ import "./chunk-RNSC5JPH.js";
|
|
|
19
25
|
import "./chunk-2RTB2DDO.js";
|
|
20
26
|
import "./chunk-YQSBHWOI.js";
|
|
21
27
|
export {
|
|
28
|
+
LISTING_ACCOUNT_ARG,
|
|
22
29
|
NAME_CONTAINS_ARG,
|
|
30
|
+
accountsInScope,
|
|
23
31
|
csvOrJson,
|
|
24
32
|
daysAgoIso,
|
|
25
33
|
getDateRange,
|
|
26
34
|
handleMetaError,
|
|
35
|
+
listingLimit,
|
|
36
|
+
loggedAt,
|
|
27
37
|
metaForbiddenFix,
|
|
28
38
|
normalizeMetaAccountId,
|
|
39
|
+
readEachAccount,
|
|
29
40
|
resolveAccountIdArg,
|
|
30
41
|
resolveEffectiveStatus,
|
|
31
42
|
statusFilterHints,
|
|
32
|
-
todayIso
|
|
43
|
+
todayIso,
|
|
44
|
+
withAccountColumn
|
|
33
45
|
};
|
|
34
|
-
//# sourceMappingURL=shared-
|
|
46
|
+
//# sourceMappingURL=shared-AXONQS3M.js.map
|
|
@@ -4,9 +4,12 @@ import {
|
|
|
4
4
|
unixSeconds
|
|
5
5
|
} from "./chunk-GDFJOCDO.js";
|
|
6
6
|
import {
|
|
7
|
+
LISTING_ACCOUNT_ARG,
|
|
8
|
+
accountsInScope,
|
|
7
9
|
handleMetaError,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
readEachAccount,
|
|
11
|
+
withAccountColumn
|
|
12
|
+
} from "./chunk-YF57BX3S.js";
|
|
10
13
|
import "./chunk-QALAJNBG.js";
|
|
11
14
|
import {
|
|
12
15
|
NO_CACHE_ARG
|
|
@@ -167,9 +170,9 @@ function studyHints(detail) {
|
|
|
167
170
|
}
|
|
168
171
|
registerSchema({
|
|
169
172
|
command: "ads.meta.studies",
|
|
170
|
-
description: "Meta A/B tests (ad studies) whose versions run in an ad account \u2014 what each compares, when it runs and its state (scheduled, running, ended). --study-id reads one: every version with its cell id and share, and each measure with Meta's results. --business-id lists every test on a Business. Stage new ones with `studies create`.",
|
|
173
|
+
description: "Meta A/B tests (ad studies) whose versions run in an ad account \u2014 what each compares, when it runs and its state (scheduled, running, ended). --study-id reads one: every version with its cell id and share, and each measure with Meta's results. --business-id lists every test on a Business. Stage new ones with `studies create`. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
171
174
|
args: {
|
|
172
|
-
"account-id": {
|
|
175
|
+
"account-id": { ...LISTING_ACCOUNT_ARG, required: false },
|
|
173
176
|
"business-id": { type: "string", description: "List every test on this Business instead", required: false },
|
|
174
177
|
"study-id": { type: "string", description: "One test: its versions and results", required: false },
|
|
175
178
|
full: { type: "boolean", description: "The tests as Meta returns them", required: false },
|
|
@@ -177,7 +180,7 @@ registerSchema({
|
|
|
177
180
|
}
|
|
178
181
|
});
|
|
179
182
|
var listArgs = {
|
|
180
|
-
"account-id":
|
|
183
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
181
184
|
"business-id": { type: "string", description: "List every test on this Business instead" },
|
|
182
185
|
"study-id": { type: "string", description: "Read one test: versions, cell ids, results" },
|
|
183
186
|
full: { type: "boolean", description: "The tests as Meta returns them" },
|
|
@@ -206,12 +209,26 @@ var listCommand = defineCommand({
|
|
|
206
209
|
writeJsonEnvelope({ ok: true, data: args.full ? row : detail, hints: studyHints(detail) });
|
|
207
210
|
return;
|
|
208
211
|
}
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
const listed = args["business-id"] ? {
|
|
213
|
+
rows: await read(
|
|
214
|
+
"/api/ads/meta/studies",
|
|
215
|
+
{ "business-id": String(args["business-id"]) },
|
|
216
|
+
args["no-cache"]
|
|
217
|
+
),
|
|
218
|
+
hints: []
|
|
219
|
+
} : await readEachAccount(
|
|
220
|
+
await accountsInScope(args),
|
|
221
|
+
(accountId) => read("/api/ads/meta/studies", { "account-id": accountId }, args["no-cache"])
|
|
222
|
+
);
|
|
223
|
+
const { rows } = listed;
|
|
224
|
+
const hints = [
|
|
225
|
+
...listed.hints,
|
|
226
|
+
...rows.length === 0 ? [
|
|
227
|
+
"No A/B tests. To set one up: duplicate the ad set (`adsets duplicate`), change ONE thing on the copy, then `studies create --adsets <original>,<copy>`."
|
|
228
|
+
] : ["`studies --study-id <id>` reads one test's versions and results."]
|
|
229
|
+
];
|
|
230
|
+
const data = withAccountColumn(args.full ? rows : rows.map((row) => compactStudy(row, now)), listed.accountOf);
|
|
231
|
+
writeJsonEnvelope({ ok: true, data, hints });
|
|
215
232
|
} catch (err) {
|
|
216
233
|
handleMetaError(err);
|
|
217
234
|
}
|
|
@@ -232,10 +249,10 @@ Examples:
|
|
|
232
249
|
},
|
|
233
250
|
subCommands: {
|
|
234
251
|
list: listCommand,
|
|
235
|
-
create: () => import("./study-writes-
|
|
236
|
-
update: () => import("./study-writes-
|
|
237
|
-
end: () => import("./study-writes-
|
|
238
|
-
delete: () => import("./study-writes-
|
|
252
|
+
create: () => import("./study-writes-SI5QXY7F.js").then((m) => m.studiesCreateCommand),
|
|
253
|
+
update: () => import("./study-writes-SI5QXY7F.js").then((m) => m.studiesUpdateCommand),
|
|
254
|
+
end: () => import("./study-writes-SI5QXY7F.js").then((m) => m.studiesEndCommand),
|
|
255
|
+
delete: () => import("./study-writes-SI5QXY7F.js").then((m) => m.studiesDeleteCommand)
|
|
239
256
|
},
|
|
240
257
|
args: listArgs,
|
|
241
258
|
default: "list"
|
|
@@ -247,4 +264,4 @@ export {
|
|
|
247
264
|
studyHints,
|
|
248
265
|
studyState
|
|
249
266
|
};
|
|
250
|
-
//# sourceMappingURL=studies-
|
|
267
|
+
//# sourceMappingURL=studies-HUINRZHD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../api/src/ads-meta/adStudyDescription.ts","../src/commands/ads/meta/studies.ts"],"sourcesContent":["/**\n * A Meta A/B test in words — the one reading shared by the staged summary, the\n * draft review rows and the CLI, so all three say the same thing: what each\n * version runs and how much of the audience it gets, what decides the winner,\n * for how long, and how sure Meta has to be.\n */\nimport type { AdStudyCell, AdStudyObjective } from \"./adStudies\";\n\nexport interface AdStudyWordsInput {\n type?: string;\n start_time?: number;\n end_time?: number;\n confidence_level?: number;\n cells?: readonly Pick<\n AdStudyCell,\n \"name\" | \"treatment_percentage\" | \"control_percentage\" | \"adsets\" | \"campaigns\" | \"ads\"\n >[];\n objectives?: readonly AdStudyObjective[];\n}\n\nexport interface AdStudyWords {\n sentence: string;\n versions?: string;\n measuring: string;\n /** The measures besides the primary one, by name. */\n alsoMeasured?: string;\n schedule?: string;\n confidence?: string;\n}\n\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nexport function adStudyTime(seconds: number): string {\n const date = new Date(seconds * 1000);\n const hh = String(date.getUTCHours()).padStart(2, \"0\");\n const mm = String(date.getUTCMinutes()).padStart(2, \"0\");\n return `${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}, ${hh}:${mm} UTC`;\n}\n\nfunction daysLabel(seconds: number): string {\n const days = Math.round((seconds / 86_400) * 10) / 10;\n return `${days} ${days === 1 ? \"day\" : \"days\"}`;\n}\n\nfunction quoted(id: string, names: Record<string, string>): string {\n const name = names[id];\n return name ? `\"${name}\"` : id;\n}\n\nfunction cellWords(\n cell: Pick<AdStudyCell, \"name\" | \"treatment_percentage\" | \"control_percentage\" | \"adsets\" | \"campaigns\" | \"ads\">,\n names: Record<string, string>,\n): string {\n const [noun, ids] = cell.ads\n ? [\"ad\", cell.ads]\n : cell.adsets\n ? [\"ad set\", cell.adsets]\n : [\"campaign\", cell.campaigns ?? []];\n const plural = ids.length > 1 ? `${noun}s` : noun;\n const runs = ids.length > 0 ? ` (${plural} ${ids.map((id) => quoted(id, names)).join(\", \")})` : \"\";\n const share =\n cell.control_percentage === undefined\n ? `${cell.treatment_percentage}%`\n : `${cell.treatment_percentage}% see the ads, ${cell.control_percentage}% held out`;\n return `${cell.name}${runs} ${share}`;\n}\n\nconst STUDY_KIND: Record<string, string> = {\n SPLIT_TEST: \"Split test\",\n LIFT: \"Lift study\",\n SPLIT_TEST_V2: \"Creative test\",\n};\n\nfunction primaryObjective(objectives: readonly AdStudyObjective[] | undefined): AdStudyObjective | undefined {\n if (!objectives || objectives.length === 0) {\n return undefined;\n }\n return objectives.find((objective) => objective.is_primary === true) ?? objectives[0];\n}\n\nconst SOURCE_NOUN: Record<\"adspixels\" | \"applications\" | \"offsite_datasets\", string> = {\n adspixels: \"pixel\",\n applications: \"app\",\n offsite_datasets: \"dataset\",\n};\n\n/** \"Lead on pixel \"Site\"\", one per event source. */\nfunction sourceWords(objective: AdStudyObjective, names: Record<string, string>): string[] {\n const words: string[] = [];\n for (const key of [\"adspixels\", \"applications\", \"offsite_datasets\"] as const) {\n for (const source of objective[key] ?? []) {\n const events = source.event_names?.join(\" or \") ?? \"any event\";\n words.push(`${events} on ${SOURCE_NOUN[key]} ${quoted(source.id, names)}`);\n }\n }\n for (const source of objective.customconversions ?? []) {\n words.push(`custom conversion ${quoted(source.id, names)}`);\n }\n return words;\n}\n\n/** What decides the winner. Meta's split test compares cost per result of the primary measure. */\nfunction measuringWords(objectives: readonly AdStudyObjective[] | undefined, names: Record<string, string>): string {\n const primary = primaryObjective(objectives);\n if (!primary) {\n return \"cost per result on the campaigns' objective\";\n }\n const sources = sourceWords(primary, names);\n return `cost per \"${primary.name}\"${sources.length > 0 ? ` (${sources.join(\", \")})` : \"\"}`;\n}\n\n/** What the sentence says the study measures: a lift study reads the lift, a test the cost per result. */\nfunction measuringPhrase(type: string | undefined, primary: AdStudyObjective | undefined, measuring: string): string {\n if (type === \"LIFT\") return `measuring the lift in ${primary ? `\"${primary.name}\"` : \"results\"}`;\n return `measuring ${primary ? `cost per \"${primary.name}\"` : measuring}`;\n}\n\nexport function describeAdStudy(\n study: AdStudyWordsInput,\n { names = {} }: { names?: Record<string, string> } = {},\n): AdStudyWords {\n const versions =\n study.cells && study.cells.length > 0 ? study.cells.map((cell) => cellWords(cell, names)).join(\" vs \") : undefined;\n const measuring = measuringWords(study.objectives, names);\n const primary = primaryObjective(study.objectives);\n const others = (study.objectives ?? []).filter((objective) => objective !== primary);\n const alsoMeasured = others.length > 0 ? others.map((objective) => `\"${objective.name}\"`).join(\", \") : undefined;\n const hasSchedule = study.start_time !== undefined && study.end_time !== undefined;\n const length = hasSchedule ? daysLabel((study.end_time ?? 0) - (study.start_time ?? 0)) : undefined;\n const schedule = hasSchedule\n ? `${adStudyTime(study.start_time ?? 0)} → ${adStudyTime(study.end_time ?? 0)} · ${length}`\n : undefined;\n const confidence = study.confidence_level !== undefined ? `${Math.round(study.confidence_level * 100)}%` : undefined;\n const parts = [\n versions,\n measuringPhrase(study.type, primary, measuring),\n length,\n confidence ? `${confidence} confidence` : undefined,\n ].filter((part): part is string => part !== undefined);\n const kind = STUDY_KIND[study.type ?? \"SPLIT_TEST\"] ?? \"Split test\";\n return { sentence: `${kind}: ${parts.join(\", \")}`, versions, measuring, alsoMeasured, schedule, confidence };\n}\n","import { adStudyFromWire, cellObjects, unixSeconds } from \"@baker/api/ads-meta/adStudies\";\nimport { adStudyTime, describeAdStudy } from \"@baker/api/ads-meta/adStudyDescription\";\nimport { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { registerSchema } from \"../../../schemas.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport {\n type AccountsRead,\n accountsInScope,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n readEachAccount,\n withAccountColumn,\n} from \"./shared.ts\";\n\n/**\n * Meta A/B tests (ad studies) — reads. A test splits one audience between\n * versions (ad sets, campaigns, or a creative test's ads) so each person sees one, and Meta calls the\n * winner. Writes (create / update / end / delete) stage like every Meta change\n * and live in `study-writes.ts`.\n */\n\ntype Row = Record<string, unknown>;\n\nexport type StudyState = \"scheduled\" | \"running\" | \"ended\" | \"cancelled\";\n\nexport function studyState(row: Row, nowSeconds: number): StudyState {\n if (row.canceled_time) return \"cancelled\";\n const start = unixSeconds(row.start_time) ?? 0;\n const end = unixSeconds(row.end_time) ?? Number.POSITIVE_INFINITY;\n if (nowSeconds < start) return \"scheduled\";\n return nowSeconds < end ? \"running\" : \"ended\";\n}\n\n/** What an agent needs to pick a test and know what it compares. The raw node sits behind --full. */\nexport function compactStudy(row: Row, nowSeconds: number): Row {\n const study = adStudyFromWire(row);\n const words = describeAdStudy(study, { names: study.names });\n return {\n id: study.id,\n name: study.name,\n state: studyState(row, nowSeconds),\n compares: words.versions,\n ...(study.start_time !== undefined ? { starts: adStudyTime(study.start_time) } : {}),\n ...(study.end_time !== undefined ? { ends: adStudyTime(study.end_time) } : {}),\n ...(row.results_first_available_date ? { results_from: row.results_first_available_date } : {}),\n };\n}\n\n/** One test in full: each version with its cell id (what `studies update --split` names), each measure with Meta's results. */\nexport function studyDetail(row: Row, nowSeconds: number): Row {\n const study = adStudyFromWire(row);\n const measures = ((row.objectives as { data?: Row[] } | undefined)?.data ?? []).map((objective) => ({\n id: objective.id,\n name: objective.name,\n primary: objective.is_primary === true,\n ...(objective.results !== undefined ? { results: objective.results } : {}),\n }));\n return {\n ...compactStudy(row, nowSeconds),\n ...(study.description ? { description: study.description } : {}),\n versions: study.cells.map((cell) => ({\n cell_id: cell.id,\n name: cell.name,\n share: `${cell.treatment_percentage}%`,\n runs: cellObjects(cell).map((id) => ({ id, name: study.names[id] })),\n level: cell.ads ? \"ad\" : cell.adsets ? \"ad set\" : \"campaign\",\n })),\n measures,\n };\n}\n\nexport function studyHints(detail: Row): string[] {\n const state = detail.state as StudyState;\n if (state === \"scheduled\") {\n return [\n \"Not started: it can still be re-timed, re-split (`studies update --split <cell_id>=60 …`) or deleted. Results appear once it runs.\",\n ];\n }\n const measures = (detail.measures as Row[] | undefined) ?? [];\n const hasResults = measures.some((measure) => measure.results !== undefined);\n return [\n hasResults\n ? \"Meta's verdict is in each measure's results, with its confidence. Report a winner only when Meta names one at the test's confidence level; otherwise say the versions performed alike.\"\n : \"No results yet — Meta publishes them once the test has gathered enough. Compare per-version delivery meanwhile with `baker ads meta insights --object <ad set or campaign id>`, and do not call a winner from it.\",\n state === \"running\"\n ? \"Running: its split and start are fixed; it can be renamed, its end moved, ended now (`studies end`) or deleted (results and all).\"\n : \"Over. Read the per-version numbers with `baker ads meta insights --object <id>` for the period it ran.\",\n ];\n}\n\nregisterSchema({\n command: \"ads.meta.studies\",\n description:\n \"Meta A/B tests (ad studies) whose versions run in an ad account — what each compares, when it runs and its state (scheduled, running, ended). --study-id reads one: every version with its cell id and share, and each measure with Meta's results. --business-id lists every test on a Business. Stage new ones with `studies create`. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n args: {\n \"account-id\": { ...LISTING_ACCOUNT_ARG, required: false },\n \"business-id\": { type: \"string\", description: \"List every test on this Business instead\", required: false },\n \"study-id\": { type: \"string\", description: \"One test: its versions and results\", required: false },\n full: { type: \"boolean\", description: \"The tests as Meta returns them\", required: false },\n \"no-cache\": { type: \"boolean\", description: \"Bypass the cache\", required: false },\n },\n});\n\nconst listArgs = {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"business-id\": { type: \"string\", description: \"List every test on this Business instead\" },\n \"study-id\": { type: \"string\", description: \"Read one test: versions, cell ids, results\" },\n full: { type: \"boolean\", description: \"The tests as Meta returns them\" },\n \"no-cache\": NO_CACHE_ARG,\n} as const;\n\nasync function read<T>(path: string, params: Record<string, string>, noCache: unknown): Promise<T> {\n if (noCache) params[\"skip-cache\"] = \"true\";\n return await apiGet<T>(path, params);\n}\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List A/B tests. Runs by default. Example: baker ads meta studies --account-id act_123 · one test: baker ads meta studies --study-id 6123\",\n },\n args: listArgs,\n run: async ({ args }) => {\n const now = Math.floor(Date.now() / 1000);\n try {\n if (args[\"study-id\"]) {\n const row = await read<Row>(\n \"/api/ads/meta/study-results\",\n { \"study-id\": String(args[\"study-id\"]) },\n args[\"no-cache\"],\n );\n const detail = studyDetail(row, now);\n writeJsonEnvelope({ ok: true, data: args.full ? row : detail, hints: studyHints(detail) });\n return;\n }\n const listed: AccountsRead<Row> = args[\"business-id\"]\n ? {\n rows: await read<Row[]>(\n \"/api/ads/meta/studies\",\n { \"business-id\": String(args[\"business-id\"]) },\n args[\"no-cache\"],\n ),\n hints: [],\n }\n : await readEachAccount(await accountsInScope(args), (accountId) =>\n read<Row[]>(\"/api/ads/meta/studies\", { \"account-id\": accountId }, args[\"no-cache\"]),\n );\n const { rows } = listed;\n const hints = [\n ...listed.hints,\n ...(rows.length === 0\n ? [\n \"No A/B tests. To set one up: duplicate the ad set (`adsets duplicate`), change ONE thing on the copy, then `studies create --adsets <original>,<copy>`.\",\n ]\n : [\"`studies --study-id <id>` reads one test's versions and results.\"]),\n ];\n const data = withAccountColumn(args.full ? rows : rows.map((row) => compactStudy(row, now)), listed.accountOf);\n writeJsonEnvelope({ ok: true, data, hints });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const studiesCommand = defineCommand({\n meta: {\n name: \"studies\",\n description: `Meta A/B tests (ad studies): Meta splits one audience between versions — ad sets or campaigns — so each person sees one, and calls the winner.\nNot Baker's own page experiments (\\`baker experiment\\`), which test landing pages.\n\nExamples:\n baker ads meta studies --account-id act_123 # tests on this account and their state\n baker ads meta studies --study-id 6123 # versions, cell ids, Meta's results\n baker ads meta studies create --name \"Broad vs lookalike\" --adsets 6123,6124 --start 2026-10-20T08:00Z --days 14 --confidence 90\n baker ads meta studies update 6123 --end 2026-11-10T08:00Z\n baker ads meta studies end 6123 | delete 6123`,\n },\n subCommands: {\n list: listCommand,\n create: () => import(\"./study-writes.ts\").then((m) => m.studiesCreateCommand),\n update: () => import(\"./study-writes.ts\").then((m) => m.studiesUpdateCommand),\n end: () => import(\"./study-writes.ts\").then((m) => m.studiesEndCommand),\n delete: () => import(\"./study-writes.ts\").then((m) => m.studiesDeleteCommand),\n },\n args: listArgs,\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAM,SAAS,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAE3F,SAAS,YAAY,SAAyB;AACnD,QAAM,OAAO,IAAI,KAAK,UAAU,GAAI;AACpC,QAAM,KAAK,OAAO,KAAK,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG;AACrD,QAAM,KAAK,OAAO,KAAK,cAAc,CAAC,EAAE,SAAS,GAAG,GAAG;AACvD,SAAO,GAAG,KAAK,WAAW,CAAC,IAAI,OAAO,KAAK,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ACtE,QAAQ,MAAM,OAAO,4BAAmB,EAAE,KAAK,CAAC,MAAM,EAAE,oBAAoB;AAAA,EAC9E;AAAA,EACA,MAAM;AAAA,EACN,SAAS;AACX,CAAC;","names":[]}
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
loadJsonFileArg,
|
|
6
6
|
requireTarget,
|
|
7
7
|
stageOp
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2WHALQOJ.js";
|
|
9
9
|
import "./chunk-3R62EYYX.js";
|
|
10
10
|
import "./chunk-GDFJOCDO.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-YF57BX3S.js";
|
|
12
12
|
import "./chunk-XD7C5OE7.js";
|
|
13
13
|
import "./chunk-UKENQSZ2.js";
|
|
14
14
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -472,4 +472,4 @@ export {
|
|
|
472
472
|
studiesUpdateCommand,
|
|
473
473
|
studyFlagsFromArgs
|
|
474
474
|
};
|
|
475
|
-
//# sourceMappingURL=study-writes-
|
|
475
|
+
//# sourceMappingURL=study-writes-SI5QXY7F.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-PRPSV4VB.js";
|
|
5
5
|
import {
|
|
6
6
|
loadJsonFileArg
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-2WHALQOJ.js";
|
|
8
8
|
import {
|
|
9
9
|
metaTargetingSchema
|
|
10
10
|
} from "./chunk-3R62EYYX.js";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
csvOrJson,
|
|
14
14
|
handleMetaError,
|
|
15
15
|
resolveAccountIdArg
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-YF57BX3S.js";
|
|
17
17
|
import "./chunk-XD7C5OE7.js";
|
|
18
18
|
import "./chunk-UKENQSZ2.js";
|
|
19
19
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -774,4 +774,4 @@ Start here before writing interests, behaviors, places or languages into an ad s
|
|
|
774
774
|
export {
|
|
775
775
|
targetingCommand
|
|
776
776
|
};
|
|
777
|
-
//# sourceMappingURL=targeting-
|
|
777
|
+
//# sourceMappingURL=targeting-3XK4OLPG.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleMetaError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YF57BX3S.js";
|
|
4
4
|
import "./chunk-QALAJNBG.js";
|
|
5
5
|
import {
|
|
6
6
|
writeJsonEnvelope
|
|
@@ -143,4 +143,4 @@ export {
|
|
|
143
143
|
downloadHints,
|
|
144
144
|
videosCommand
|
|
145
145
|
};
|
|
146
|
-
//# sourceMappingURL=videos-
|
|
146
|
+
//# sourceMappingURL=videos-C5OCSAIF.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
budgetBoostsFromFlags,
|
|
8
8
|
clearArg,
|
|
9
9
|
clearFromFlags
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EJ6B5OS5.js";
|
|
11
11
|
import {
|
|
12
12
|
bareAccountId,
|
|
13
13
|
failWriteValidation,
|
|
@@ -25,14 +25,14 @@ import {
|
|
|
25
25
|
stageOp,
|
|
26
26
|
stageStatusChange,
|
|
27
27
|
upper
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-2WHALQOJ.js";
|
|
29
29
|
import {
|
|
30
30
|
buildCustomConversionRule
|
|
31
31
|
} from "./chunk-3R62EYYX.js";
|
|
32
32
|
import {
|
|
33
33
|
VISUAL_ENHANCEMENT_FEATURES
|
|
34
34
|
} from "./chunk-GDFJOCDO.js";
|
|
35
|
-
import "./chunk-
|
|
35
|
+
import "./chunk-YF57BX3S.js";
|
|
36
36
|
import "./chunk-XD7C5OE7.js";
|
|
37
37
|
import "./chunk-UKENQSZ2.js";
|
|
38
38
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -481,7 +481,7 @@ Example: baker ads meta adsets create --campaign 6123 --name "Reach ES" --optimi
|
|
|
481
481
|
const file = loadJsonFileArg(args.file);
|
|
482
482
|
const payload = mergePayload(file, adSetPayloadFromFlags(args, rawArgs, file));
|
|
483
483
|
if (args["saved-audience"]) {
|
|
484
|
-
const { savedAudienceTargeting, targetingFromSavedAudience } = await import("./audience-writes-
|
|
484
|
+
const { savedAudienceTargeting, targetingFromSavedAudience } = await import("./audience-writes-DJG7XTFA.js");
|
|
485
485
|
const saved = await savedAudienceTargeting(accountId, String(args["saved-audience"]));
|
|
486
486
|
const merged = targetingFromSavedAudience(saved, payload.targeting);
|
|
487
487
|
if ("refusal" in merged) failWriteValidation(merged.refusal);
|
|
@@ -945,7 +945,7 @@ Example: baker ads meta ads retag 120252158038400247 --url-tags "utm_source={{si
|
|
|
945
945
|
const { apiPost } = await import("./client-T7LLEL5L.js");
|
|
946
946
|
const { requireChatId } = await import("./env-Q5OHLIQU.js");
|
|
947
947
|
const { writeJsonEnvelope } = await import("./output-CYHSMLZ6.js");
|
|
948
|
-
const { handleMetaError } = await import("./shared-
|
|
948
|
+
const { handleMetaError } = await import("./shared-AXONQS3M.js");
|
|
949
949
|
try {
|
|
950
950
|
const accountId = await bareAccountId(args);
|
|
951
951
|
const urlTags = typeof args["url-tags"] === "string" ? args["url-tags"] : void 0;
|
|
@@ -1183,7 +1183,7 @@ function duplicateCommand(entity, label) {
|
|
|
1183
1183
|
const { apiPost } = await import("./client-T7LLEL5L.js");
|
|
1184
1184
|
const { requireChatId } = await import("./env-Q5OHLIQU.js");
|
|
1185
1185
|
const { writeJsonEnvelope } = await import("./output-CYHSMLZ6.js");
|
|
1186
|
-
const { handleMetaError } = await import("./shared-
|
|
1186
|
+
const { handleMetaError } = await import("./shared-AXONQS3M.js");
|
|
1187
1187
|
try {
|
|
1188
1188
|
const accountId = await bareAccountId(args);
|
|
1189
1189
|
const chatId = requireChatId();
|
|
@@ -1258,4 +1258,4 @@ export {
|
|
|
1258
1258
|
retagSetPairs,
|
|
1259
1259
|
targetingFromFlags
|
|
1260
1260
|
};
|
|
1261
|
-
//# sourceMappingURL=write-commands-
|
|
1261
|
+
//# sourceMappingURL=write-commands-T46SVSQ7.js.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/ads/meta/account-assets.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { registerSchema } from \"../../../schemas.ts\";\nimport { writeAdsOutput, writeJsonEnvelope } from \"../output.ts\";\nimport { csvOrJson, handleMetaError, resolveAccountIdArg } from \"./shared.ts\";\n\n/**\n * The account's identities and libraries an ad is built from — reads that used\n * to exist only as backend routes. They were left off the CLI as \"rarely\n * needed in isolation\", but each answers a question staging otherwise answers\n * with a refusal: which Instagram account an ad can run as, which apps it can\n * promote, whom an EU ad names, what an image hash or label id is, which\n * product sets a catalog ad can use, what an A/B test found.\n */\n\ntype Row = Record<string, unknown>;\ntype Args = Record<string, unknown>;\n\nfunction emit(rows: Row[], args: Args, hints: string[]): void {\n const fmt = csvOrJson(args);\n if (fmt !== \"json\") {\n writeAdsOutput(rows, fmt, undefined, hints);\n return;\n }\n writeJsonEnvelope(hints.length > 0 ? { ok: true, data: rows, hints } : { ok: true, data: rows });\n}\n\nasync function read<T>(path: string, params: Record<string, string>, args: Args): Promise<T> {\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n return await apiGet<T>(path, params);\n}\n\nconst outputArg = { type: \"string\", description: \"json|csv|jsonl|md\", default: \"json\" } as const;\nconst accountArg = { type: \"string\", description: \"Meta ad account ID (act_...)\" } as const;\nconst schemaAccount = { type: \"string\", description: \"Meta ad account ID (act_123)\", required: false };\nconst schemaNoCache = { type: \"boolean\", description: \"Bypass the cache\", required: false };\nconst schemaOutput = { type: \"string\", description: \"json|csv|jsonl|md\", required: false, default: \"json\" };\n\n// --- Instagram identities ---\n\nexport interface MetaInstagramIdentity {\n id: string;\n username?: string;\n sources: Array<\"ad_account\" | \"connected\" | \"page\" | \"page_backed\">;\n pageId?: string;\n pageName?: string;\n}\n\nexport function instagramIdentityHints(rows: readonly MetaInstagramIdentity[]): string[] {\n if (rows.length === 0) {\n return [\n \"No Instagram account is linked to this ad account or its Pages. A creative without --instagram-user cannot run in Instagram feeds, Stories or Reels — the account owner links one in Meta Business settings (Accounts → Instagram accounts) and assigns it to the ad account.\",\n ];\n }\n const listed = rows.filter((row) => row.sources.includes(\"ad_account\") || row.sources.includes(\"connected\"));\n const hints = [\"Pass the id as `creatives create --instagram-user <id>`.\"];\n if (listed.length > 0 && listed.length < rows.length) {\n hints.push(\n `Use one listed on the ad account (${listed.map((row) => row.username ?? row.id).join(\", \")}): when the account lists any, staging refuses an identity it does not list.`,\n );\n } else if (listed.length === 0) {\n hints.push(\n \"Only Page identities are listed (page = the Page's linked Instagram account, page_backed = an Instagram presence Meta made for a Page with none). Meta accepts either as --instagram-user; a page_backed one shows the Page's name and picture on Instagram.\",\n );\n }\n if (new Set(rows.map((row) => row.pageId).filter(Boolean)).size > 1) {\n hints.push(\"Several Pages are involved — use the identity of the Page the creative runs from (--page).\");\n }\n return hints;\n}\n\nregisterSchema({\n command: \"ads.meta.instagram-accounts\",\n description:\n \"The Instagram accounts an ad on this account can run as — the id `creatives create --instagram-user` takes. Lists accounts assigned or connected to the ad account and each promotable Page's linked or page-backed one.\",\n args: {\n \"account-id\": schemaAccount,\n \"no-cache\": schemaNoCache,\n output: { type: \"string\", description: \"json|csv\", required: false, default: \"json\" },\n },\n});\n\nexport const instagramAccountsCommand = defineCommand({\n meta: {\n name: \"instagram-accounts\",\n description:\n \"Instagram identities an ad can run as (the --instagram-user id). Start here before creatives create: baker ads meta instagram-accounts --account-id act_123\",\n },\n args: { \"account-id\": accountArg, \"no-cache\": NO_CACHE_ARG, output: outputArg },\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n try {\n const rows = await read<MetaInstagramIdentity[]>(\n \"/api/ads/meta/instagram-accounts\",\n { \"account-id\": accountId },\n args,\n );\n emit(\n rows.map((row) => ({ ...row, sources: row.sources.join(\",\") })),\n args,\n instagramIdentityHints(rows),\n );\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n// --- Apps ---\n\nregisterSchema({\n command: \"ads.meta.apps\",\n description:\n \"The apps this ad account can promote (app installs / app engagement), with their store URLs — the application_id and object_store_url an app ad set's promoted_object takes.\",\n args: { \"account-id\": schemaAccount, \"no-cache\": schemaNoCache, output: schemaOutput },\n});\n\nexport const appsCommand = defineCommand({\n meta: {\n name: \"apps\",\n description:\n \"Apps the ad account can promote, for an app ad set's promoted_object. Example: baker ads meta apps --account-id act_123\",\n },\n args: { \"account-id\": accountArg, \"no-cache\": NO_CACHE_ARG, output: outputArg },\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n try {\n const rows = await read<Array<{ id: string; name?: string; object_store_urls?: Record<string, string> }>>(\n \"/api/ads/meta/apps\",\n { \"account-id\": accountId },\n args,\n );\n emit(\n rows.map((row) => ({ ...row })),\n args,\n rows.length > 0\n ? [\n 'An app ad set promotes one: promoted_object {\"application_id\":\"<id>\",\"object_store_url\":\"<store url>\"}. Use a real store URL (itunes / google_play); fb_canvas and instant_game are not app stores.',\n ]\n : [\n \"No promotable apps. The app has to be registered in Meta for Developers and its owner has to add this ad account under the app's Advanced settings → Advertising accounts.\",\n ],\n );\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n// --- DSA ---\n\nregisterSchema({\n command: \"ads.meta.dsa-recommendations\",\n description:\n \"Names Meta suggests for the EU Digital Services Act disclosure (who benefits from and who pays for an ad) on this account.\",\n args: { \"account-id\": schemaAccount, \"no-cache\": schemaNoCache },\n});\n\nexport const dsaRecommendationsCommand = defineCommand({\n meta: {\n name: \"dsa-recommendations\",\n description:\n \"Meta's suggested DSA beneficiary/payor names for EU ad sets. Example: baker ads meta dsa-recommendations --account-id act_123\",\n },\n args: { \"account-id\": accountArg, \"no-cache\": NO_CACHE_ARG },\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n try {\n const names = await read<string[]>(\"/api/ads/meta/dsa-recommendations\", { \"account-id\": accountId }, args);\n writeJsonEnvelope({\n ok: true,\n data: names,\n hints: [\n \"An ad set reaching the EU needs dsa_beneficiary and dsa_payor. When they are missing Baker fills both from the ad account's saved EU advertiser and payer, else the first of these, else the business name; pass one of these instead when the user names someone else (an agency paying for a client).\",\n ],\n });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n// --- Images and labels ---\n\nfunction compactImage(row: Row): Row {\n return {\n hash: row.hash,\n name: row.name,\n width: row.width,\n height: row.height,\n status: row.status,\n created_time: row.created_time,\n };\n}\n\nregisterSchema({\n command: \"ads.meta.images\",\n description:\n \"The ad account's image library — each image_hash a creative can reuse without uploading again. --hash looks one up.\",\n args: {\n \"account-id\": schemaAccount,\n hash: { type: \"string\", description: \"One image hash\", required: false },\n limit: { type: \"string\", description: \"Max rows (default 500)\", required: false },\n full: { type: \"boolean\", description: \"URLs, permalink and which creatives use it\", required: false },\n \"no-cache\": schemaNoCache,\n output: schemaOutput,\n },\n});\n\nexport const imagesCommand = defineCommand({\n meta: {\n name: \"images\",\n description:\n \"Image library of the ad account (image hashes). Example: baker ads meta images --account-id act_123 --limit 20; --hash <hash> for one\",\n },\n args: {\n \"account-id\": accountArg,\n hash: { type: \"string\", description: \"Look up one image hash\" },\n limit: { type: \"string\", description: \"Max rows (default 500)\" },\n full: { type: \"boolean\", description: \"Every field: url, permalink_url, creatives\" },\n \"no-cache\": NO_CACHE_ARG,\n output: outputArg,\n },\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n const params: Record<string, string> = { \"account-id\": accountId };\n if (args.hash) params.hash = args.hash as string;\n if (args.limit) params.limit = args.limit as string;\n try {\n const rows = await read<Row[]>(\"/api/ads/meta/images\", params, args);\n emit(args.full ? rows : rows.map(compactImage), args, [\n \"A creative reuses one with its hash (the `image_hash` of a creative file). To push a Baker-library image, stage `media upload` instead.\",\n ]);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nregisterSchema({\n command: \"ads.meta.labels\",\n description: \"Ad labels defined on the account (Meta's tags for campaigns, ad sets, ads and creatives).\",\n args: { \"account-id\": schemaAccount, \"no-cache\": schemaNoCache, output: schemaOutput },\n});\n\nconst labelsListArgs = { \"account-id\": accountArg, \"no-cache\": NO_CACHE_ARG, output: outputArg };\n\nexport const labelsCommand = defineCommand({\n meta: {\n name: \"labels\",\n description: `Ad labels on the account (list), or stage label writes: create, rename, delete, attach (file campaigns/ad sets/ads/creatives under one), detach.\n baker ads meta labels --account-id act_123\n baker ads meta labels create --name \"Q4 launch\"\n baker ads meta labels attach <labelId|meta_temp_…> --campaigns 6123,6124 --ads 6125`,\n },\n subCommands: {\n list: () => labelsListCommand,\n create: () => import(\"./asset-writes.ts\").then((m) => m.labelsCreateCommand),\n rename: () => import(\"./asset-writes.ts\").then((m) => m.labelsRenameCommand),\n delete: () => import(\"./asset-writes.ts\").then((m) => m.labelsDeleteCommand),\n attach: () => import(\"./asset-writes.ts\").then((m) => m.labelsAttachCommand),\n detach: () => import(\"./asset-writes.ts\").then((m) => m.labelsDetachCommand),\n },\n args: labelsListArgs,\n default: \"list\",\n});\n\nconst labelsListCommand = defineCommand({\n meta: {\n name: \"list\",\n description: \"Ad labels on the account. Runs by default. Example: baker ads meta labels --account-id act_123\",\n },\n args: labelsListArgs,\n run: async ({ args }) => {\n const accountId = await resolveAccountIdArg(args);\n try {\n const rows = await read<Row[]>(\"/api/ads/meta/labels\", { \"account-id\": accountId }, args);\n emit(rows, args, rows.length === 0 ? [\"This account has no ad labels.\"] : []);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n// --- High-demand periods ---\n\nregisterSchema({\n command: \"ads.meta.high-demand-periods\",\n description: \"The budget boosts (high-demand periods) set on a campaign or ad set: when each runs and by how much.\",\n args: {\n \"campaign-id\": { type: \"string\", description: \"Campaign or ad set ID\", required: true },\n \"no-cache\": schemaNoCache,\n output: schemaOutput,\n },\n});\n\nexport const highDemandPeriodsCommand = defineCommand({\n meta: {\n name: \"high-demand-periods\",\n description:\n \"Budget boosts on a campaign or ad set. Example: baker ads meta high-demand-periods --campaign-id 6123 (stage new ones with --budget-boost on campaigns or adsets create|update)\",\n },\n args: {\n \"campaign-id\": { type: \"string\", description: \"Campaign (or ad set) ID\", required: true },\n \"no-cache\": NO_CACHE_ARG,\n output: outputArg,\n },\n run: async ({ args }) => {\n try {\n const rows = await read<Row[]>(\n \"/api/ads/meta/high-demand-periods\",\n { \"campaign-id\": args[\"campaign-id\"] as string },\n args,\n );\n emit(rows, args, rows.length === 0 ? [\"No budget boosts on this campaign.\"] : []);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAmB9B,SAAS,KAAK,MAAa,MAAY,OAAuB;AAC5D,QAAM,MAAM,UAAU,IAAI;AAC1B,MAAI,QAAQ,QAAQ;AAClB,mBAAe,MAAM,KAAK,QAAW,KAAK;AAC1C;AAAA,EACF;AACA,oBAAkB,MAAM,SAAS,IAAI,EAAE,IAAI,MAAM,MAAM,MAAM,MAAM,IAAI,EAAE,IAAI,MAAM,MAAM,KAAK,CAAC;AACjG;AAEA,eAAe,KAAQ,MAAc,QAAgC,MAAwB;AAC3F,MAAI,KAAK,UAAU,EAAG,QAAO,YAAY,IAAI;AAC7C,SAAO,MAAM,OAAU,MAAM,MAAM;AACrC;AAEA,IAAM,YAAY,EAAE,MAAM,UAAU,aAAa,qBAAqB,SAAS,OAAO;AACtF,IAAM,aAAa,EAAE,MAAM,UAAU,aAAa,+BAA+B;AACjF,IAAM,gBAAgB,EAAE,MAAM,UAAU,aAAa,gCAAgC,UAAU,MAAM;AACrG,IAAM,gBAAgB,EAAE,MAAM,WAAW,aAAa,oBAAoB,UAAU,MAAM;AAC1F,IAAM,eAAe,EAAE,M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