@koda-sl/baker-cli 0.868.0-dev.009dcef7a → 0.868.0-dev.dd070597a
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 +0 -2
- package/dist/{account-reads-SUWXGTGW.js → account-reads-3LP4F3L4.js} +2 -2
- package/dist/{ads-66KVUF35.js → ads-O76TVWHX.js} +4 -4
- package/dist/{chunk-LJO3I2W2.js → chunk-BPIHAIWB.js} +11 -20
- package/dist/chunk-BPIHAIWB.js.map +1 -0
- package/dist/{chunk-LZ5DS4UB.js → chunk-N366L5EF.js} +32 -4
- package/dist/chunk-N366L5EF.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/{conversion-upload-command-Y4ABNNAT.js → conversion-upload-command-HJOVSWZD.js} +2 -2
- package/dist/{draft-CLNMIQXV.js → draft-OLSFLDME.js} +2 -2
- package/dist/{forecast-JAPRYH4F.js → forecast-AQDB4LLG.js} +2 -2
- package/dist/{google-HHKFDH7I.js → google-HLE7YIYM.js} +57 -40
- package/dist/google-HLE7YIYM.js.map +1 -0
- package/dist/{linkedin-OZGEZLN5.js → linkedin-EBOTX37R.js} +4 -8
- package/dist/{linkedin-OZGEZLN5.js.map → linkedin-EBOTX37R.js.map} +1 -1
- package/dist/{meta-C7VHIHDL.js → meta-SPPSYRMC.js} +2 -2
- package/dist/{preview-25YWCQBJ.js → preview-4GUQGDBD.js} +47 -130
- package/dist/preview-4GUQGDBD.js.map +1 -0
- package/dist/preview-HD3QAR53.js +104 -0
- package/dist/preview-HD3QAR53.js.map +1 -0
- package/dist/{search-terms-WLOW2FPP.js → search-terms-WKEPRHN2.js} +2 -2
- package/dist/{themes-Q5CSF6TJ.js → themes-2T5BOIZU.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-LJO3I2W2.js.map +0 -1
- package/dist/chunk-LZ5DS4UB.js.map +0 -1
- package/dist/google-HHKFDH7I.js.map +0 -1
- package/dist/preview-25YWCQBJ.js.map +0 -1
- package/dist/preview-TTIHEWK6.js +0 -147
- package/dist/preview-TTIHEWK6.js.map +0 -1
- /package/dist/{account-reads-SUWXGTGW.js.map → account-reads-3LP4F3L4.js.map} +0 -0
- /package/dist/{ads-66KVUF35.js.map → ads-O76TVWHX.js.map} +0 -0
- /package/dist/{conversion-upload-command-Y4ABNNAT.js.map → conversion-upload-command-HJOVSWZD.js.map} +0 -0
- /package/dist/{draft-CLNMIQXV.js.map → draft-OLSFLDME.js.map} +0 -0
- /package/dist/{forecast-JAPRYH4F.js.map → forecast-AQDB4LLG.js.map} +0 -0
- /package/dist/{meta-C7VHIHDL.js.map → meta-SPPSYRMC.js.map} +0 -0
- /package/dist/{search-terms-WLOW2FPP.js.map → search-terms-WKEPRHN2.js.map} +0 -0
- /package/dist/{themes-Q5CSF6TJ.js.map → themes-2T5BOIZU.js.map} +0 -0
|
@@ -122,7 +122,7 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
|
|
|
122
122
|
pixels: () => import("./pixels-EX6FHVHW.js").then((m) => m.pixelsCommand),
|
|
123
123
|
activities: () => import("./activities-LC64DAAK.js").then((m) => m.activitiesCommand),
|
|
124
124
|
insights: () => import("./insights-QU5A4XBO.js").then((m) => m.insightsCommand),
|
|
125
|
-
preview: () => import("./preview-
|
|
125
|
+
preview: () => import("./preview-4GUQGDBD.js").then((m) => m.previewCommand),
|
|
126
126
|
videos: () => import("./videos-TJG5CA7N.js").then((m) => m.videosCommand),
|
|
127
127
|
targeting: () => import("./targeting-7T7XHBIX.js").then((m) => m.targetingCommand),
|
|
128
128
|
"instagram-accounts": () => import("./account-assets-L6BX4YUQ.js").then((m) => m.instagramAccountsCommand),
|
|
@@ -149,4 +149,4 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
|
|
|
149
149
|
export {
|
|
150
150
|
metaCommand
|
|
151
151
|
};
|
|
152
|
-
//# sourceMappingURL=meta-
|
|
152
|
+
//# sourceMappingURL=meta-SPPSYRMC.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
AD_PREVIEW_DIR,
|
|
3
3
|
AD_PREVIEW_DIR_LABEL,
|
|
4
4
|
renderAdPreviews
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-BPIHAIWB.js";
|
|
6
6
|
import "./chunk-VN3WDB4O.js";
|
|
7
7
|
import {
|
|
8
8
|
FACEBOOK_PREVIEW_FORMATS,
|
|
@@ -15,10 +15,6 @@ import {
|
|
|
15
15
|
handleMetaError
|
|
16
16
|
} from "./chunk-DP76WGDV.js";
|
|
17
17
|
import "./chunk-QALAJNBG.js";
|
|
18
|
-
import {
|
|
19
|
-
apiFailure,
|
|
20
|
-
eachTarget
|
|
21
|
-
} from "./chunk-EMW6TSSB.js";
|
|
22
18
|
import {
|
|
23
19
|
NO_CACHE_ARG
|
|
24
20
|
} from "./chunk-TBT6NWDX.js";
|
|
@@ -151,86 +147,10 @@ function previewFileName(target) {
|
|
|
151
147
|
if (id) return `meta-${id}`;
|
|
152
148
|
return `meta-draft-${createHash("sha256").update(target.creative ?? "").digest("hex").slice(0, 12)}`;
|
|
153
149
|
}
|
|
154
|
-
var MAX_PREVIEWS = 24;
|
|
155
|
-
function listArg(value) {
|
|
156
|
-
if (typeof value !== "string") return [];
|
|
157
|
-
return [...new Set(value.split(",").map((item) => item.trim()))].filter(Boolean);
|
|
158
|
-
}
|
|
159
|
-
function previewSubjects(args) {
|
|
160
|
-
const subjects = [
|
|
161
|
-
...listArg(args["creative-id"]).map((creativeId) => ({ creativeId })),
|
|
162
|
-
...listArg(args["ad-id"]).map((adId) => ({ adId }))
|
|
163
|
-
];
|
|
164
|
-
if (subjects.length > 0) return subjects;
|
|
165
|
-
const text = (value) => typeof value === "string" ? value : void 0;
|
|
166
|
-
return [{ accountId: text(args["account-id"]), creative: text(args.creative) }];
|
|
167
|
-
}
|
|
168
|
-
function previewFormats(placements, args) {
|
|
169
|
-
const formats = placements.length > 0 ? placements.map((p) => resolvePlacement(p, args.platform)) : listArg(args["ad-format"]);
|
|
170
|
-
if (formats.length === 0) {
|
|
171
|
-
failPreviewValidation("pass --ad-format or --placement (see --list-formats)");
|
|
172
|
-
}
|
|
173
|
-
const invalid = formats.find((adFormat) => !VALID_AD_FORMATS.includes(adFormat));
|
|
174
|
-
if (invalid) {
|
|
175
|
-
failPreviewValidation(
|
|
176
|
-
`Invalid --ad-format "${invalid}". 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.`
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
return formats;
|
|
180
|
-
}
|
|
181
|
-
async function fetchPreviews(pairs, skipCache) {
|
|
182
|
-
const refusals = [];
|
|
183
|
-
const fetched = await eachTarget(
|
|
184
|
-
pairs.map((_, i) => String(i)),
|
|
185
|
-
(i) => {
|
|
186
|
-
const { subject, adFormat } = pairs[Number(i)];
|
|
187
|
-
return apiPost("/api/ads/meta/preview", {
|
|
188
|
-
...subject,
|
|
189
|
-
adFormat,
|
|
190
|
-
...skipCache ? { skipCache: true } : {}
|
|
191
|
-
});
|
|
192
|
-
},
|
|
193
|
-
(err) => {
|
|
194
|
-
refusals.push(err);
|
|
195
|
-
return apiFailure(err);
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
if (refusals.length === pairs.length) {
|
|
199
|
-
handleMetaError(refusals[0]);
|
|
200
|
-
}
|
|
201
|
-
return fetched;
|
|
202
|
-
}
|
|
203
|
-
function previewInputs(pairs, fetched, several) {
|
|
204
|
-
const inputs = [];
|
|
205
|
-
const owners = [];
|
|
206
|
-
const refused = [];
|
|
207
|
-
for (const [index, outcome] of fetched.entries()) {
|
|
208
|
-
const { subject, adFormat } = pairs[index];
|
|
209
|
-
const owner = several ? subjectId(subject) : {};
|
|
210
|
-
if (!outcome.ok) {
|
|
211
|
-
refused.push({ index: inputs.length, entry: { ...owner, placement: adFormat, error: outcome.error.message } });
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
for (const [i, d] of outcome.data.entries()) {
|
|
215
|
-
inputs.push({
|
|
216
|
-
placement: outcome.data.length > 1 ? `${adFormat}-${i + 1}` : adFormat,
|
|
217
|
-
html: d.body,
|
|
218
|
-
name: previewFileName(subject)
|
|
219
|
-
});
|
|
220
|
-
owners.push(owner);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return { inputs, owners, refused };
|
|
224
|
-
}
|
|
225
|
-
function subjectId(subject) {
|
|
226
|
-
if ("creativeId" in subject) return { creativeId: subject.creativeId };
|
|
227
|
-
if ("adId" in subject) return { adId: subject.adId };
|
|
228
|
-
return {};
|
|
229
|
-
}
|
|
230
150
|
var previewCommand = defineCommand({
|
|
231
151
|
meta: {
|
|
232
152
|
name: "preview",
|
|
233
|
-
description: `See
|
|
153
|
+
description: `See a creative or ad as Meta renders it in one placement: shownText (the text people see, in order)
|
|
234
154
|
plus a picture to Read for what text cannot tell (words in the artwork, cropping, how it looks).
|
|
235
155
|
--out-file also saves Meta's raw iframe HTML (its URL holds a short-lived access token \u2014 treat as secret).
|
|
236
156
|
|
|
@@ -239,31 +159,22 @@ image, the button). Start here too when you need to know what a creative looks l
|
|
|
239
159
|
Meta's own renderer, so it settles "does my video show as a still image there?" without guessing.
|
|
240
160
|
Pass the placement straight from an insights breakdown with --placement (a platform_position value),
|
|
241
161
|
or a Meta ad_format with --ad-format. Run --list-formats to see both sets.
|
|
242
|
-
To compare several creatives or placements, pass comma lists in ONE call \u2014 never loop the command:
|
|
243
|
-
every creative \xD7 format pair comes back as its own preview, fetched and drawn in parallel (at most ${MAX_PREVIEWS}).
|
|
244
162
|
|
|
245
163
|
Examples:
|
|
246
164
|
baker ads meta preview --creative-id 6123 --ad-format MOBILE_FEED_STANDARD
|
|
247
|
-
baker ads meta preview --creative-id 6123,6124 --ad-format MOBILE_FEED_STANDARD,INSTAGRAM_STORY,INSTAGRAM_REELS
|
|
248
165
|
baker ads meta preview --creative-id 6123 --placement facebook_reels_overlay --platform facebook
|
|
249
166
|
baker ads meta preview --ad-id 9988 --ad-format INSTAGRAM_REELS --out-dir /tmp/review
|
|
250
167
|
baker ads meta preview --account-id act_123 --creative '{"object_story_spec":{...}}' --ad-format MOBILE_FEED_STANDARD`
|
|
251
168
|
},
|
|
252
169
|
args: {
|
|
253
|
-
"creative-id": {
|
|
254
|
-
|
|
255
|
-
description: "Existing creative ID, or several comma-separated: --creative-id 6123,6124"
|
|
256
|
-
},
|
|
257
|
-
"ad-id": { type: "string", description: "Existing ad ID, or several comma-separated: --ad-id 9988,9989" },
|
|
170
|
+
"creative-id": { type: "string", description: "Existing creative ID" },
|
|
171
|
+
"ad-id": { type: "string", description: "Existing ad ID" },
|
|
258
172
|
"account-id": { type: "string", description: "Required when previewing an unpublished --creative spec" },
|
|
259
173
|
creative: { type: "string", description: "JSON spec of an unpublished creative (e.g. object_story_spec)" },
|
|
260
|
-
"ad-format": {
|
|
261
|
-
type: "string",
|
|
262
|
-
description: "Meta ad_format value, or several comma-separated: --ad-format MOBILE_FEED_STANDARD,INSTAGRAM_REELS (--list-formats to see them)"
|
|
263
|
-
},
|
|
174
|
+
"ad-format": { type: "string", description: "Meta ad_format enum value (--list-formats to see them)" },
|
|
264
175
|
placement: {
|
|
265
176
|
type: "string",
|
|
266
|
-
description: "platform_position from an insights breakdown (e.g. facebook_reels_overlay)
|
|
177
|
+
description: "platform_position from an insights breakdown (e.g. facebook_reels_overlay) \u2014 resolved to an ad_format"
|
|
267
178
|
},
|
|
268
179
|
platform: { type: "string", description: "facebook|instagram \u2014 required for --placement feed, which both report" },
|
|
269
180
|
"list-formats": { type: "boolean", description: "Print the ad_format values and placement mappings, then exit" },
|
|
@@ -282,48 +193,54 @@ Examples:
|
|
|
282
193
|
});
|
|
283
194
|
return;
|
|
284
195
|
}
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
196
|
+
const placement = args.placement;
|
|
197
|
+
const adFormat = placement ? resolvePlacement(placement, args.platform) : args["ad-format"];
|
|
198
|
+
if (!adFormat) {
|
|
199
|
+
failPreviewValidation("pass --ad-format or --placement (see --list-formats)");
|
|
200
|
+
}
|
|
201
|
+
if (!VALID_AD_FORMATS.includes(adFormat)) {
|
|
290
202
|
failPreviewValidation(
|
|
291
|
-
|
|
203
|
+
`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.`
|
|
292
204
|
);
|
|
293
205
|
}
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
if (args["
|
|
297
|
-
|
|
206
|
+
const body = { adFormat };
|
|
207
|
+
if (args["creative-id"]) body.creativeId = args["creative-id"];
|
|
208
|
+
if (args["ad-id"]) body.adId = args["ad-id"];
|
|
209
|
+
if (args["account-id"]) body.accountId = args["account-id"];
|
|
210
|
+
if (args.creative) body.creative = args.creative;
|
|
211
|
+
if (args["no-cache"]) body.skipCache = true;
|
|
212
|
+
try {
|
|
213
|
+
const data = await apiPost("/api/ads/meta/preview", body);
|
|
214
|
+
if (args["out-file"]) {
|
|
215
|
+
writeFileSync(args["out-file"], data.map((d) => d.body).join("\n"), "utf-8");
|
|
216
|
+
}
|
|
217
|
+
const rendered = await renderAdPreviews(
|
|
218
|
+
data.map((d, i) => ({ placement: data.length > 1 ? `${adFormat}-${i + 1}` : adFormat, html: d.body })),
|
|
219
|
+
{
|
|
220
|
+
dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
|
|
221
|
+
name: previewFileName({
|
|
222
|
+
adId: args["ad-id"],
|
|
223
|
+
creativeId: args["creative-id"],
|
|
224
|
+
creative: args.creative
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
const hints = placement ? [
|
|
229
|
+
`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.`,
|
|
230
|
+
...rendered.hints
|
|
231
|
+
] : rendered.hints;
|
|
232
|
+
writeJsonEnvelope({
|
|
233
|
+
ok: true,
|
|
234
|
+
data: { adFormat, previews: rendered.previews, ...args["out-file"] ? { file: args["out-file"] } : {} },
|
|
235
|
+
hints
|
|
236
|
+
});
|
|
237
|
+
} catch (err) {
|
|
238
|
+
handleMetaError(err);
|
|
298
239
|
}
|
|
299
|
-
const rendered = await renderAdPreviews(inputs, {
|
|
300
|
-
dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
|
|
301
|
-
name: "meta"
|
|
302
|
-
});
|
|
303
|
-
const previews = rendered.previews.map((p, i) => ({ ...owners[i], ...p }));
|
|
304
|
-
for (const { index, entry } of refused.reverse()) previews.splice(index, 0, entry);
|
|
305
|
-
const hints = [
|
|
306
|
-
...placements.map(
|
|
307
|
-
(p, i) => `Rendered ${p} as ad_format ${formats[i]}. Meta does not document what it renders for a creative a placement cannot take, so the picture is the evidence.`
|
|
308
|
-
),
|
|
309
|
-
...rendered.hints,
|
|
310
|
-
...refused.length > 0 ? [
|
|
311
|
-
"Meta refused some previews (each says why in its error). Say those could not be checked; the rest are real."
|
|
312
|
-
] : []
|
|
313
|
-
];
|
|
314
|
-
writeJsonEnvelope({
|
|
315
|
-
ok: true,
|
|
316
|
-
data: {
|
|
317
|
-
...formats.length === 1 ? { adFormat: formats[0] } : { adFormats: formats },
|
|
318
|
-
previews,
|
|
319
|
-
...args["out-file"] ? { file: args["out-file"] } : {}
|
|
320
|
-
},
|
|
321
|
-
hints
|
|
322
|
-
});
|
|
323
240
|
}
|
|
324
241
|
});
|
|
325
242
|
export {
|
|
326
243
|
previewCommand,
|
|
327
244
|
previewFileName
|
|
328
245
|
};
|
|
329
|
-
//# sourceMappingURL=preview-
|
|
246
|
+
//# sourceMappingURL=preview-4GUQGDBD.js.map
|
|
@@ -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;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,EAC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AgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleLinkedinError,
|
|
3
|
+
resolveAccountIdArg
|
|
4
|
+
} from "./chunk-SBID6GZZ.js";
|
|
5
|
+
import {
|
|
6
|
+
AD_PREVIEW_DIR,
|
|
7
|
+
AD_PREVIEW_DIR_LABEL,
|
|
8
|
+
renderAdPreviews
|
|
9
|
+
} from "./chunk-BPIHAIWB.js";
|
|
10
|
+
import "./chunk-VN3WDB4O.js";
|
|
11
|
+
import {
|
|
12
|
+
writeJsonEnvelope
|
|
13
|
+
} from "./chunk-NX4EB2TK.js";
|
|
14
|
+
import "./chunk-JGXB7NBP.js";
|
|
15
|
+
import "./chunk-RJHGIRU2.js";
|
|
16
|
+
import "./chunk-WCU362Z6.js";
|
|
17
|
+
import "./chunk-P7YPWBEV.js";
|
|
18
|
+
import "./chunk-GIWHHCD6.js";
|
|
19
|
+
import "./chunk-PNGXJPM5.js";
|
|
20
|
+
import "./chunk-SOPVIIUW.js";
|
|
21
|
+
import "./chunk-G4FG5EQO.js";
|
|
22
|
+
import "./chunk-CS4VA3GQ.js";
|
|
23
|
+
import "./chunk-CVAQZO4I.js";
|
|
24
|
+
import {
|
|
25
|
+
apiPost
|
|
26
|
+
} from "./chunk-EHEPW3O2.js";
|
|
27
|
+
import "./chunk-4OF7Q356.js";
|
|
28
|
+
import "./chunk-RNSC5JPH.js";
|
|
29
|
+
import "./chunk-2RTB2DDO.js";
|
|
30
|
+
import "./chunk-YQSBHWOI.js";
|
|
31
|
+
|
|
32
|
+
// src/commands/ads/linkedin/preview.ts
|
|
33
|
+
import { writeFileSync } from "fs";
|
|
34
|
+
import { defineCommand } from "citty";
|
|
35
|
+
var previewCommand = defineCommand({
|
|
36
|
+
meta: {
|
|
37
|
+
name: "preview",
|
|
38
|
+
description: `See an existing LinkedIn ad exactly as people see it in the feed \u2014 LinkedIn's own renderer,
|
|
39
|
+
for desktop and mobile. Returns shownText (the text displayed, in order) and a picture of each;
|
|
40
|
+
Read the picture only for what text cannot tell (words in the artwork, cropping, how it looks).
|
|
41
|
+
|
|
42
|
+
Start here before saying anything about how an ad LOOKS (which text shows, whether the headline
|
|
43
|
+
appears under the image, what the button says): the API fields say what is stored, the preview
|
|
44
|
+
shows what is displayed. Works for single image, carousel, video, event and job ads that already
|
|
45
|
+
exist on LinkedIn; staged (unpublished) ads have no preview yet.
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
baker ads linkedin preview 1611562694 --account-id 503001492
|
|
49
|
+
baker ads linkedin preview 1611562694 --placement mobile
|
|
50
|
+
baker ads linkedin preview 1611562694 --out-dir /tmp/review`
|
|
51
|
+
},
|
|
52
|
+
args: {
|
|
53
|
+
id: { type: "positional", description: "Creative id or urn:li:sponsoredCreative:N", required: true },
|
|
54
|
+
"account-id": { type: "string", description: "Numeric account ID or urn:li:sponsoredAccount:N" },
|
|
55
|
+
"account-urn": { type: "string", description: "Alias for --account-id" },
|
|
56
|
+
placement: { type: "string", description: "desktop|mobile|both (default: both)", default: "both" },
|
|
57
|
+
"out-dir": { type: "string", description: `Folder for the pictures (default: ${AD_PREVIEW_DIR_LABEL})` },
|
|
58
|
+
"html-file": { type: "string", description: "Also save LinkedIn's raw preview iframes to this file" }
|
|
59
|
+
},
|
|
60
|
+
run: async ({ args }) => {
|
|
61
|
+
const accountId = resolveAccountIdArg(args);
|
|
62
|
+
const placement = String(args.placement);
|
|
63
|
+
if (!["desktop", "mobile", "both"].includes(placement)) {
|
|
64
|
+
writeJsonEnvelope({
|
|
65
|
+
ok: false,
|
|
66
|
+
error: { code: "VALIDATION_ERROR", message: "--placement must be desktop, mobile or both" }
|
|
67
|
+
});
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const body = { accountId, creativeId: String(args.id) };
|
|
72
|
+
const data = await apiPost("/api/ads/linkedin/preview", body);
|
|
73
|
+
const wanted = data.previews.filter((p) => placement === "both" || p.placement === placement);
|
|
74
|
+
if (wanted.length === 0) {
|
|
75
|
+
writeJsonEnvelope({
|
|
76
|
+
ok: true,
|
|
77
|
+
data: { creativeId: data.creativeId, previews: [] },
|
|
78
|
+
hints: [
|
|
79
|
+
"LinkedIn returned no preview for this ad (its format may not support one). Say its look could not be checked; do not describe it from the API fields."
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (args["html-file"]) {
|
|
85
|
+
writeFileSync(String(args["html-file"]), wanted.map((p) => p.html).join("\n"), "utf-8");
|
|
86
|
+
}
|
|
87
|
+
const rendered = await renderAdPreviews(wanted, {
|
|
88
|
+
dir: args["out-dir"] ? String(args["out-dir"]) : AD_PREVIEW_DIR,
|
|
89
|
+
name: `linkedin-${data.creativeId}`
|
|
90
|
+
});
|
|
91
|
+
writeJsonEnvelope({
|
|
92
|
+
ok: true,
|
|
93
|
+
data: { creativeId: data.creativeId, previews: rendered.previews },
|
|
94
|
+
hints: rendered.hints
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
handleLinkedinError(err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export {
|
|
102
|
+
previewCommand
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=preview-HD3QAR53.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/linkedin/preview.ts"],"sourcesContent":["import { writeFileSync } from \"node:fs\";\nimport type { LinkedinAdPreviewRequest, LinkedinAdPreviewResponse } from \"@baker/api/ads-linkedin/preview\";\nimport { defineCommand } from \"citty\";\nimport { apiPost } from \"../../../client.ts\";\nimport { AD_PREVIEW_DIR, AD_PREVIEW_DIR_LABEL, renderAdPreviews } from \"../ad-preview-images.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport { handleLinkedinError, resolveAccountIdArg } from \"./shared.ts\";\n\nexport const previewCommand = defineCommand({\n meta: {\n name: \"preview\",\n description: `See an existing LinkedIn ad exactly as people see it in the feed — LinkedIn's own renderer,\nfor desktop and mobile. Returns shownText (the text displayed, in order) and a picture of each;\nRead the picture only for what text cannot tell (words in the artwork, cropping, how it looks).\n\nStart here before saying anything about how an ad LOOKS (which text shows, whether the headline\nappears under the image, what the button says): the API fields say what is stored, the preview\nshows what is displayed. Works for single image, carousel, video, event and job ads that already\nexist on LinkedIn; staged (unpublished) ads have no preview yet.\n\nExamples:\n baker ads linkedin preview 1611562694 --account-id 503001492\n baker ads linkedin preview 1611562694 --placement mobile\n baker ads linkedin preview 1611562694 --out-dir /tmp/review`,\n },\n args: {\n id: { type: \"positional\", description: \"Creative id or urn:li:sponsoredCreative:N\", required: true },\n \"account-id\": { type: \"string\", description: \"Numeric account ID or urn:li:sponsoredAccount:N\" },\n \"account-urn\": { type: \"string\", description: \"Alias for --account-id\" },\n placement: { type: \"string\", description: \"desktop|mobile|both (default: both)\", default: \"both\" },\n \"out-dir\": { type: \"string\", description: `Folder for the pictures (default: ${AD_PREVIEW_DIR_LABEL})` },\n \"html-file\": { type: \"string\", description: \"Also save LinkedIn's raw preview iframes to this file\" },\n },\n run: async ({ args }) => {\n const accountId = resolveAccountIdArg(args);\n const placement = String(args.placement);\n if (![\"desktop\", \"mobile\", \"both\"].includes(placement)) {\n writeJsonEnvelope({\n ok: false,\n error: { code: \"VALIDATION_ERROR\", message: \"--placement must be desktop, mobile or both\" },\n });\n process.exit(1);\n }\n try {\n const body: LinkedinAdPreviewRequest = { accountId, creativeId: String(args.id) };\n const data = await apiPost<LinkedinAdPreviewResponse>(\"/api/ads/linkedin/preview\", body);\n const wanted = data.previews.filter((p) => placement === \"both\" || p.placement === placement);\n if (wanted.length === 0) {\n writeJsonEnvelope({\n ok: true,\n data: { creativeId: data.creativeId, previews: [] },\n hints: [\n \"LinkedIn returned no preview for this ad (its format may not support one). Say its look could not be checked; do not describe it from the API fields.\",\n ],\n });\n return;\n }\n if (args[\"html-file\"]) {\n writeFileSync(String(args[\"html-file\"]), wanted.map((p) => p.html).join(\"\\n\"), \"utf-8\");\n }\n const rendered = await renderAdPreviews(wanted, {\n dir: args[\"out-dir\"] ? String(args[\"out-dir\"]) : AD_PREVIEW_DIR,\n name: `linkedin-${data.creativeId}`,\n });\n writeJsonEnvelope({\n ok: true,\n data: { creativeId: data.creativeId, previews: rendered.previews },\n hints: rendered.hints,\n });\n } catch (err) {\n handleLinkedinError(err);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAMvB,IAAM,iBAAiB,cAAc;AAAA,EAC1C,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaf;AAAA,EACA,MAAM;AAAA,IACJ,IAAI,EAAE,MAAM,cAAc,aAAa,6CAA6C,UAAU,KAAK;AAAA,IACnG,cAAc,EAAE,MAAM,UAAU,aAAa,kDAAkD;AAAA,IAC/F,eAAe,EAAE,MAAM,UAAU,aAAa,yBAAyB;AAAA,IACvE,WAAW,EAAE,MAAM,UAAU,aAAa,uCAAuC,SAAS,OAAO;AAAA,IACjG,WAAW,EAAE,MAAM,UAAU,aAAa,qCAAqC,oBAAoB,IAAI;AAAA,IACvG,aAAa,EAAE,MAAM,UAAU,aAAa,wDAAwD;AAAA,EACtG;AAAA,EACA,KAAK,OAAO,EAAE,KAAK,MAAM;AACvB,UAAM,YAAY,oBAAoB,IAAI;AAC1C,UAAM,YAAY,OAAO,KAAK,SAAS;AACvC,QAAI,CAAC,CAAC,WAAW,UAAU,MAAM,EAAE,SAAS,SAAS,GAAG;AACtD,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,OAAO,EAAE,MAAM,oBAAoB,SAAS,8CAA8C;AAAA,MAC5F,CAAC;AACD,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,QAAI;AACF,YAAM,OAAiC,EAAE,WAAW,YAAY,OAAO,KAAK,EAAE,EAAE;AAChF,YAAM,OAAO,MAAM,QAAmC,6BAA6B,IAAI;AACvF,YAAM,SAAS,KAAK,SAAS,OAAO,CAAC,MAAM,cAAc,UAAU,EAAE,cAAc,SAAS;AAC5F,UAAI,OAAO,WAAW,GAAG;AACvB,0BAAkB;AAAA,UAChB,IAAI;AAAA,UACJ,MAAM,EAAE,YAAY,KAAK,YAAY,UAAU,CAAC,EAAE;AAAA,UAClD,OAAO;AAAA,YACL;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AACA,UAAI,KAAK,WAAW,GAAG;AACrB,sBAAc,OAAO,KAAK,WAAW,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI,GAAG,OAAO;AAAA,MACxF;AACA,YAAM,WAAW,MAAM,iBAAiB,QAAQ;AAAA,QAC9C,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,CAAC,IAAI;AAAA,QACjD,MAAM,YAAY,KAAK,UAAU;AAAA,MACnC,CAAC;AACD,wBAAkB;AAAA,QAChB,IAAI;AAAA,QACJ,MAAM,EAAE,YAAY,KAAK,YAAY,UAAU,SAAS,SAAS;AAAA,QACjE,OAAO,SAAS;AAAA,MAClB,CAAC;AAAA,IACH,SAAS,KAAK;AACZ,0BAAoB,GAAG;AAAA,IACzB;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
keywordEntries,
|
|
10
10
|
listFlag,
|
|
11
11
|
requireCustomerId
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-N366L5EF.js";
|
|
13
13
|
import "./chunk-RHN5FEWA.js";
|
|
14
14
|
import "./chunk-XD7C5OE7.js";
|
|
15
15
|
import "./chunk-UKENQSZ2.js";
|
|
@@ -409,4 +409,4 @@ export {
|
|
|
409
409
|
searchTermsHints,
|
|
410
410
|
searchTermsRequest
|
|
411
411
|
};
|
|
412
|
-
//# sourceMappingURL=search-terms-
|
|
412
|
+
//# sourceMappingURL=search-terms-WKEPRHN2.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
failWriteValidation,
|
|
6
6
|
listFlag,
|
|
7
7
|
requireCustomerId
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-N366L5EF.js";
|
|
9
9
|
import "./chunk-RHN5FEWA.js";
|
|
10
10
|
import "./chunk-XD7C5OE7.js";
|
|
11
11
|
import "./chunk-UKENQSZ2.js";
|
|
@@ -99,4 +99,4 @@ Example:
|
|
|
99
99
|
export {
|
|
100
100
|
themesCommand
|
|
101
101
|
};
|
|
102
|
-
//# sourceMappingURL=themes-
|
|
102
|
+
//# sourceMappingURL=themes-2T5BOIZU.js.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/ads/ad-preview-images.ts"],"sourcesContent":["import { mkdirSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { launchBrowser } from \"../../engine/landing-library/browser.ts\";\n\n/**\n * Opens a platform's preview iframe and returns what it displays: the text\n * people read (`shownText`) and a picture for questions text cannot answer.\n *\n * The API's fields say what is stored, not what shows. A Session paused seven\n * live ads because a stored headline read like an internal code, with no way to\n * check whether the feed showed it. The rendered text settles that; the picture\n * covers what is not text — words drawn into the artwork, cropping, layout.\n */\n\nexport interface AdPreviewInput {\n placement: string;\n /** Where the platform shows it (LinkedIn FEED, …) when one placement renders on several surfaces. */\n surface?: string;\n html: string;\n /** The picture's file-name prefix when it differs from the call's `name` (one call previewing several ads). */\n name?: string;\n}\n\ntype AdPreviewWhere = { placement: string; surface?: string };\nexport type AdPreviewResult =\n | (AdPreviewWhere & { shownText: string[]; image: string })\n | (AdPreviewWhere & { error: string });\n\n/** Render `html` (a platform iframe): save a PNG at `file`, return the text it displays. */\nexport type DrawPreview = (html: string, file: string) => Promise<{ text: string }>;\n\nexport const AD_PREVIEW_DIR = join(tmpdir(), \"baker-ad-previews\");\n\n/**\n * The same folder as a sentence, for an arg description.\n *\n * `AD_PREVIEW_DIR` itself must never reach one: it is `tmpdir()` RESOLVED, which is\n * `/tmp/baker-ad-previews` on Linux and `/var/folders/<random>/T/baker-ad-previews` on a Mac — so\n * `catalog:export` wrote whichever machine ran it into `cli-catalog/families/ads-meta.json`, and\n * `catalog.test.ts` then failed for everyone else. The catalog is committed, so a description in it\n * has to be the same on every machine.\n */\nexport const AD_PREVIEW_DIR_LABEL = \"your system temp folder, under baker-ad-previews\";\n\n/** Pictures drawn at once. Each opens its own Chromium, so a long list must not open one per preview. */\nconst DRAW_CONCURRENCY = 4;\n\nexport async function renderAdPreviews(\n inputs: readonly AdPreviewInput[],\n target: { dir: string; name: string },\n draw: DrawPreview = drawPreviewInChromium,\n): Promise<{ previews: AdPreviewResult[]; hints: string[] }> {\n mkdirSync(target.dir, { recursive: true });\n const taken = new Map<string, number>();\n const jobs = inputs.map((input) => {\n const where: AdPreviewWhere = input.surface\n ? { placement: input.placement, surface: input.surface }\n : { placement: input.placement };\n // One file per rendering: a shared name would leave two results pointing at the last picture drawn.\n const base = [input.name ?? target.name, input.placement, input.surface?.toLowerCase()].filter(Boolean).join(\"-\");\n const seen = (taken.get(base) ?? 0) + 1;\n taken.set(base, seen);\n return { where, html: input.html, file: join(target.dir, `${seen > 1 ? `${base}-${seen}` : base}.png`) };\n });\n const previews: AdPreviewResult[] = new Array(jobs.length);\n let next = 0;\n const worker = async (): Promise<void> => {\n while (next < jobs.length) {\n const index = next++;\n const { where, html, file } = jobs[index] as (typeof jobs)[number];\n try {\n const { text } = await draw(html, file);\n previews[index] = { ...where, shownText: shownLines(text), image: file };\n } catch (err) {\n previews[index] = { ...where, error: err instanceof Error ? err.message : String(err) };\n }\n }\n };\n await Promise.all(Array.from({ length: Math.min(DRAW_CONCURRENCY, jobs.length) }, worker));\n return { previews, hints: previewHints(previews) };\n}\n\nfunction shownLines(text: string): string[] {\n return text\n .split(\"\\n\")\n .map((line) => line.replace(/\\s+/g, \" \").trim())\n .filter(Boolean);\n}\n\nfunction previewHints(previews: readonly AdPreviewResult[]): string[] {\n const hints: string[] = [];\n if (previews.some((p) => \"image\" in p)) {\n hints.push(\n \"shownText is what people see on the ad, in order — rendered by the platform itself, so it settles which text is displayed (headline under the image, button, cut-off intro). The API fields only say what is stored. Words drawn into the artwork are not in shownText: Read the image for those, and for cropping or how the ad looks.\",\n );\n }\n if (previews.some((p) => \"error\" in p)) {\n hints.push(\n \"Some previews could not be drawn. Do not describe how those look — say they could not be checked, and carry on with the rest.\",\n );\n }\n return hints;\n}\n\n/**\n * The platforms' iframes have a fixed window (Meta's 335×450) and scroll the rest,\n * which cuts the headline and button off a picture. The frame is grown to its\n * content's height first, so the picture holds the whole ad.\n */\nexport async function drawPreviewInChromium(html: string, file: string): Promise<{ text: string }> {\n const browser = await launchBrowser();\n try {\n const context = await browser.newContext({ viewport: { width: 900, height: 1200 }, deviceScaleFactor: 2 });\n const page = await context.newPage();\n await page.setContent(`<!doctype html><body style=\"margin:0;background:#fff\">${html}</body>`, {\n waitUntil: \"load\",\n timeout: 30_000,\n });\n await page.waitForLoadState(\"networkidle\", { timeout: 15_000 }).catch(() => undefined);\n const iframe = await page.$(\"iframe\");\n if (!iframe) throw new Error(\"the platform returned no preview frame\");\n const frame = await iframe.contentFrame();\n if (frame) {\n const height = await frame.evaluate(() =>\n Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight ?? 0),\n );\n if (height > 0) {\n await iframe.evaluate((node, h) => {\n node.removeAttribute(\"height\");\n (node as HTMLElement).style.height = `${h}px`;\n }, height);\n await frame.waitForLoadState(\"networkidle\", { timeout: 10_000 }).catch(() => undefined);\n }\n }\n await iframe.screenshot({ path: file });\n // innerText follows the layout: hidden elements drop out, line breaks stay.\n const text = frame ? await frame.evaluate(() => document.body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