@wrangled/cli 0.3.50 → 0.3.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/guide.js +3 -0
- package/dist/main.js +67 -17
- package/dist/meta-ad.js +35 -0
- package/package.json +1 -1
package/dist/guide.js
CHANGED
|
@@ -185,6 +185,8 @@ Save anything you make before it goes anywhere: an ad written without a tool, an
|
|
|
185
185
|
|
|
186
186
|
The \`meta_ads\` publisher puts an approved ad on Facebook, always paused, in an ad set that already exists, \`--to meta_ads --target '{"accountId": "act_<id>", "adsetId": "<id>"}'\`, or in one made with \`${cli} meta adset publish\` (below), \`"adsetPublicationId": "<id>"\` in place of \`adsetId\`. \`"urlTags": "sku"\` (the default) adds the SKU tracking tags to the link; \`"urlTags": "none"\` sends the link exactly as written, Meta macros such as \`{{ad.name}}\` included. The ad needs pictures or a video (not both), body text and an https link in \`fields.link_urls\` (\`fields.cta\`, such as "Shop now", sets the button; \`fields.bodies\`, \`fields.titles\` and \`fields.descriptions\` add variations). The account, the ad set's campaign and the ad set must all be on the hand's publish list, which only an operator sets, and the ad set and campaign must be in the last Meta sync and not archived. A live send also needs a run of the Facebook ads hand, Meta numbers pulled under 12 hours ago, and room under the daily limit of new ads. The ad is named \`<SKU> | <name>\` and its creative's \`url_tags\` carry the SKU. In practice mode the same command stores the full request for review and sends nothing. Each publication's \`targetSnapshot\` names the campaign and ad set as they were at publish time.
|
|
187
187
|
|
|
188
|
+
\`${cli} meta ad create --account act_<id> --adset <id> --file ad.png --text "<primary text>" --headline "<headline>" --link <https url>\` does all of that in one step: it saves the files and words as an ad with a new SKU, approves it and publishes it with \`meta_ads\` into the ad set, then prints the SKU, the publication, the Meta ad id and its status. Repeat \`--file\` for more pictures; a big file is uploaded first. \`--cta SHOP_NOW\` sets the button and \`--name\` names the ad (the headline otherwise). The same rules apply and are all checked before anything is saved, so a refusal leaves nothing behind. Your own key sends to Facebook without \`--run\`, but the account and campaign must also be on the workspace's control list; from a hand's run in practice mode it is recorded and nothing is sent. The ad starts paused; \`--status active --reason "<why>"\` switches it on 15 seconds after it is made, as a change in the change log that \`${cli} meta changes undo <change-id>\` reverses, and needs room under the day's limit of on/off changes. Without \`--idempotency-key\` the key comes from the files and the flags, so the same command run twice makes one ad.
|
|
189
|
+
|
|
188
190
|
\`${cli} meta adset publish --plan '<json>' --idempotency-key <key> --run <run-id>\` makes one new Meta ad set, always paused, for ads to go into. A copy, \`{"kind": "copy", "accountId": "act_<id>", "campaignId": "<id>", "sourceAdsetId": "<id>", "name": "<new name>"}\`, copies a proven ad set without its ads; the source must be on the hand's list of ad sets that may be copied. A new one from settings is \`{"kind": "create", "accountId": ..., "campaignId": ..., "name": ..., "settings": {"optimizationGoal": "...", "billingEvent": "...", "targeting": {...}, "dailyBudget": 5000}}\`, with the budget in the currency's smallest unit (5000 is 50.00 USD) and left out when the campaign holds it. The account and campaign must be on the publish list, the name unused in the campaign, and the day under the limit of new ad sets (3 unless an operator sets another). Ad sets and ads share one account's turn: one unfinished send at a time, and at least 15 seconds apart. ${brand.name} reads the new ad set back and checks it: paused, in the right campaign, with the right name, and for a copy, targeting equal to the source's. Its \`verification.ok\` must be true before you add ads; an ad set that fails the check stays paused and takes none. In practice mode nothing is sent and the ad set is recorded as \`not_sent_practice\`, and ads published into it are practice too. \`${cli} meta adset show <id>\` prints it with its budget. One left \`sending\` or \`unknown\` is never sent again; \`${cli} meta adset reconcile <id>\` looks for it in the campaign by its exact name.
|
|
189
191
|
|
|
190
192
|
When you send something yourself instead, record it in ${brand.name} before anything is sent, so the record never depends on the platform remembering it:
|
|
@@ -382,6 +384,7 @@ ${cli} content reconcile <publication-id> check whether a publish left sending
|
|
|
382
384
|
${cli} content unpublish <deployment-id> [--force] take one deployed landing page down
|
|
383
385
|
${cli} meta adset publish --plan '<json>' --idempotency-key <key> [--run <run-id>] make a paused Meta ad set to add ads to
|
|
384
386
|
${cli} meta adset show <id> | meta adset reconcile <id> read an ad set publication, or check whether one left sending landed
|
|
387
|
+
${cli} meta ad create --account act_<id> --adset <id> --file <path> --text "<words>" --headline "<h>" --link <url> [--cta <type>] [--name <n>] [--status paused|active --reason "<why>"] [--run <run-id>] make a Facebook ad from files in one step
|
|
385
388
|
${cli} content publish-record <sku> --file <publication.json> record a publish before sending it
|
|
386
389
|
${cli} content publish-finish <publication-id> --status sending|published|failed|not_sent_practice [--input '<json>']
|
|
387
390
|
${cli} content track-link <sku> <url> [--channel facebook|email|sms|web] [--campaign <id>] tag a link with its SKU
|
package/dist/main.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
import { api, ApiError, apiDownload, apiText, apiUpload, CliError, exitCodes, getSigned, IMPORT_LIMITS, META_IDS_MAX, IMPORT_NAME_PATTERN, putSigned, CLIENT_FILE, parseClientName, readSavedLogins, removeCredentials, resolveApiUrl, resolveConnection, resolveLogin, UnreadableCredentialsError, writeCredentials, entryTagFlags, streamSigned, } from "./api.js";
|
|
9
9
|
import { brand, envPrefix } from "./brand.js";
|
|
10
|
+
import { META_AD_CREATE_USAGE, metaAdCreateBody } from "./meta-ad.js";
|
|
10
11
|
import { firstSymlink, inRunFolder, writeFileAtomic } from "./files.js";
|
|
11
12
|
import { scheduleCreateBody, scheduleIdFor, SCHEDULES_CREATE_USAGE } from "./schedules.js";
|
|
12
13
|
import { secretBody, secretProvider, SECRETS_SET_USAGE } from "./secrets.js";
|
|
@@ -999,6 +1000,31 @@ const commands = {
|
|
|
999
1000
|
printAdSetPublication(adsetPublication, options.format);
|
|
1000
1001
|
},
|
|
1001
1002
|
},
|
|
1003
|
+
"meta ad create": {
|
|
1004
|
+
usage: `${META_AD_CREATE_USAGE} make a Facebook ad from pictures or a video in one step`,
|
|
1005
|
+
async run(args, options) {
|
|
1006
|
+
if (args.length !== 0)
|
|
1007
|
+
throw new CliError(`Usage: ${META_AD_CREATE_USAGE}`, exitCodes.usage);
|
|
1008
|
+
const read = await readContentFiles(options.files);
|
|
1009
|
+
const body = metaAdCreateBody({ ...options, text: options.text === undefined ? undefined : await textOrFile(options.text) }, read.map(({ data }) => createHash("sha256").update(data).digest("hex")));
|
|
1010
|
+
const connection = await resolveConnection(options);
|
|
1011
|
+
const created = await api(connection, "/api/v1/meta/ads", { ...body, files: await sendableFiles(read, connection, 0) });
|
|
1012
|
+
if (options.format === "json")
|
|
1013
|
+
return printJson(created);
|
|
1014
|
+
const { publication, change } = created;
|
|
1015
|
+
printFields({
|
|
1016
|
+
sku: created.sku,
|
|
1017
|
+
publication: publication.id,
|
|
1018
|
+
"meta ad": publication.externalId,
|
|
1019
|
+
status: publication.status,
|
|
1020
|
+
error: publication.error,
|
|
1021
|
+
change: change && `${change.id} (${change.before.status} -> ${change.after.status}, ${change.status})`,
|
|
1022
|
+
"idempotency key": body.idempotencyKey,
|
|
1023
|
+
});
|
|
1024
|
+
if (publication.status === "not_sent_practice")
|
|
1025
|
+
console.log("Practice mode: the ad was recorded with its full request and nothing was sent to Meta.");
|
|
1026
|
+
},
|
|
1027
|
+
},
|
|
1002
1028
|
"meta ads pause": metaStatusCommand("ads", "pause"),
|
|
1003
1029
|
"meta ads resume": metaStatusCommand("ads", "resume"),
|
|
1004
1030
|
"meta adset pause": metaStatusCommand("adset", "pause"),
|
|
@@ -2861,7 +2887,13 @@ Options:
|
|
|
2861
2887
|
--tool-run <id> a succeeded tool run content create and edit link; repeat for several
|
|
2862
2888
|
--run <id> the agent run making the content (content) or the Meta change (meta ads|adset), the tool run to
|
|
2863
2889
|
record (creatives create), or the tool run whose outputs media list shows
|
|
2864
|
-
--reason <why> why: what meta ads|adset pause|resume
|
|
2890
|
+
--reason <why> why: what meta ads|adset pause|resume, meta changes undo and meta ad create --status active record in the change log
|
|
2891
|
+
--account <act_id> meta ad create: the ad account
|
|
2892
|
+
--adset <id> meta ad create: the ad set the new ad goes into
|
|
2893
|
+
--text <text | @file> meta ad create: the ad's primary text
|
|
2894
|
+
--link <https url> meta ad create: where the ad links; the SKU's tracking tags are added
|
|
2895
|
+
--cta <type> meta ad create: the button, such as SHOP_NOW
|
|
2896
|
+
--status paused|active meta ad create: how the new ad starts (default paused)
|
|
2865
2897
|
--sku <sku> with media list, only the output that became this creative
|
|
2866
2898
|
--tool <tool> with media list, only this tool's outputs, such as kie:nano-banana
|
|
2867
2899
|
--kind image|video with media list, only images or only videos
|
|
@@ -2987,6 +3019,10 @@ function parseOptions(argv) {
|
|
|
2987
3019
|
grain: { type: "string" },
|
|
2988
3020
|
channel: { type: "string" },
|
|
2989
3021
|
campaign: { type: "string" },
|
|
3022
|
+
account: { type: "string" },
|
|
3023
|
+
adset: { type: "string" },
|
|
3024
|
+
link: { type: "string" },
|
|
3025
|
+
cta: { type: "string" },
|
|
2990
3026
|
top: { type: "string" },
|
|
2991
3027
|
week: { type: "string" },
|
|
2992
3028
|
days: { type: "string" },
|
|
@@ -3114,6 +3150,10 @@ function parseOptions(argv) {
|
|
|
3114
3150
|
grain: values.grain,
|
|
3115
3151
|
channel: values.channel,
|
|
3116
3152
|
campaign: values.campaign,
|
|
3153
|
+
account: values.account,
|
|
3154
|
+
adset: values.adset,
|
|
3155
|
+
link: values.link,
|
|
3156
|
+
cta: values.cta,
|
|
3117
3157
|
top: values.top,
|
|
3118
3158
|
week: values.week,
|
|
3119
3159
|
days: values.days,
|
|
@@ -3364,21 +3404,7 @@ const INLINE_CONTENT_BYTES = 3 * 1024 * 1024;
|
|
|
3364
3404
|
*/
|
|
3365
3405
|
async function contentInput(options, connection) {
|
|
3366
3406
|
const html = options.html === undefined ? undefined : await textOrFile(options.html);
|
|
3367
|
-
|
|
3368
|
-
const files = [];
|
|
3369
|
-
for (const path of options.files) {
|
|
3370
|
-
const contentType = FILE_TYPES[extname(path).toLowerCase()];
|
|
3371
|
-
if (!contentType)
|
|
3372
|
-
throw new CliError(`${path}: --file takes ${Object.keys(FILE_TYPES).join(", ")} files.`, exitCodes.usage);
|
|
3373
|
-
const data = await readFile(await inRunFolder(path));
|
|
3374
|
-
if (inline + data.byteLength <= INLINE_CONTENT_BYTES) {
|
|
3375
|
-
inline += data.byteLength;
|
|
3376
|
-
files.push({ base64: data.toString("base64"), contentType });
|
|
3377
|
-
}
|
|
3378
|
-
else {
|
|
3379
|
-
files.push({ uploadId: await uploadContentFile(connection, data, contentType) });
|
|
3380
|
-
}
|
|
3381
|
-
}
|
|
3407
|
+
const files = await sendableFiles(await readContentFiles(options.files), connection, html === undefined ? 0 : Buffer.byteLength(html));
|
|
3382
3408
|
const input = {
|
|
3383
3409
|
name: options.name,
|
|
3384
3410
|
subject: options.subject,
|
|
@@ -3400,6 +3426,30 @@ function deploymentLine(d) {
|
|
|
3400
3426
|
return line;
|
|
3401
3427
|
return `${line}, read as ${d.pageItemId} v${d.currentPageVersion}, edited on the host ${d.editedOnHost} ${d.editedOnHost === 1 ? "time" : "times"} since it went live`;
|
|
3402
3428
|
}
|
|
3429
|
+
async function readContentFiles(paths) {
|
|
3430
|
+
const read = [];
|
|
3431
|
+
for (const path of paths) {
|
|
3432
|
+
const contentType = FILE_TYPES[extname(path).toLowerCase()];
|
|
3433
|
+
if (!contentType)
|
|
3434
|
+
throw new CliError(`${path}: --file takes ${Object.keys(FILE_TYPES).join(", ")} files.`, exitCodes.usage);
|
|
3435
|
+
read.push({ contentType, data: await readFile(await inRunFolder(path)) });
|
|
3436
|
+
}
|
|
3437
|
+
return read;
|
|
3438
|
+
}
|
|
3439
|
+
/** Files go base64 while they fit in one request beside `inline` bytes already in it; any other file goes to storage first. */
|
|
3440
|
+
async function sendableFiles(read, connection, inline) {
|
|
3441
|
+
const files = [];
|
|
3442
|
+
for (const { contentType, data } of read) {
|
|
3443
|
+
if (inline + data.byteLength <= INLINE_CONTENT_BYTES) {
|
|
3444
|
+
inline += data.byteLength;
|
|
3445
|
+
files.push({ base64: data.toString("base64"), contentType });
|
|
3446
|
+
}
|
|
3447
|
+
else {
|
|
3448
|
+
files.push({ uploadId: await uploadContentFile(connection, data, contentType) });
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
return files;
|
|
3452
|
+
}
|
|
3403
3453
|
async function uploadContentFile(connection, data, contentType) {
|
|
3404
3454
|
const upload = await api(connection, "/api/v1/content/uploads", { contentType, bytes: data.byteLength });
|
|
3405
3455
|
await putSigned(upload.url, data, contentType);
|
package/dist/meta-ad.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { CliError, exitCodes } from "./api.js";
|
|
3
|
+
export const META_AD_CREATE_USAGE = 'meta ad create --account act_<id> --adset <id> --file <path> [--file <path>...] --text "<primary text>" --headline "<headline>" --link <https url> ' +
|
|
4
|
+
'[--cta SHOP_NOW] [--name "<name>"] [--status paused|active] [--reason "<why>"] [--run <run-id>] [--idempotency-key <key>]';
|
|
5
|
+
const usage = (problem) => new CliError(`${problem}\nUsage: ${META_AD_CREATE_USAGE}`, exitCodes.usage);
|
|
6
|
+
/**
|
|
7
|
+
* The request for `meta ad create`. Without --idempotency-key the key comes from the files' sha256 and every flag that
|
|
8
|
+
* shapes the ad, so the same command sent again returns the ad it made instead of making a second.
|
|
9
|
+
*/
|
|
10
|
+
export function metaAdCreateBody(flags, fileSha256s) {
|
|
11
|
+
const { account, adset, text, headline, link } = flags;
|
|
12
|
+
if (!account || !adset || !text || !headline || !link || fileSha256s.length === 0) {
|
|
13
|
+
throw usage("meta ad create needs --account, --adset, at least one --file, --text, --headline and --link.");
|
|
14
|
+
}
|
|
15
|
+
const status = flags.status ?? "paused";
|
|
16
|
+
if (status !== "paused" && status !== "active")
|
|
17
|
+
throw usage(`--status must be paused or active; got '${status}'.`);
|
|
18
|
+
if (status === "active" && !flags.reason)
|
|
19
|
+
throw usage("--status active needs --reason, which goes in the change log.");
|
|
20
|
+
const shape = { accountId: account, adsetId: adset, primaryText: text, headline, linkUrl: link, cta: flags.cta ?? null, name: flags.name ?? null, status };
|
|
21
|
+
const derived = `meta-ad-${createHash("sha256").update(JSON.stringify({ files: fileSha256s, ...shape })).digest("hex")}`;
|
|
22
|
+
return {
|
|
23
|
+
accountId: account,
|
|
24
|
+
adsetId: adset,
|
|
25
|
+
primaryText: text,
|
|
26
|
+
headline,
|
|
27
|
+
linkUrl: link,
|
|
28
|
+
...(flags.cta === undefined ? {} : { cta: flags.cta }),
|
|
29
|
+
...(flags.name === undefined ? {} : { name: flags.name }),
|
|
30
|
+
status,
|
|
31
|
+
...(flags.reason === undefined ? {} : { reason: flags.reason }),
|
|
32
|
+
...(flags.run === undefined ? {} : { runId: flags.run }),
|
|
33
|
+
idempotencyKey: flags.idempotencyKey ?? derived,
|
|
34
|
+
};
|
|
35
|
+
}
|