@vibiz/cli 0.2.4 → 0.3.1

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/vibiz.js CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  connectHostMessage,
7
7
  deployDirectory,
8
8
  deployPathProblem,
9
+ formatMinor,
9
10
  formatUnits,
10
11
  formatUsd,
11
12
  mergeEnvFile,
12
13
  oneKeyMessage
13
- } from "./chunk-5SMCAX6T.js";
14
+ } from "./chunk-RH4VCBQY.js";
14
15
 
15
16
  // packages/cli/src/main.ts
16
17
  import { spawn } from "node:child_process";
@@ -361,7 +362,9 @@ var VibizApp = class _VibizApp {
361
362
  /**
362
363
  * Any action, billed to the project: web data (`web.scrape`, `web.search`, `web.crawl`,
363
364
  * `web.screenshot`, `web.design`, `ads.library`, `places.search`, `reviews`, `social.profile`,
364
- * `social.posts`, `ecommerce.product`, `linkedin.company`) or `email.send`.
365
+ * `social.posts`, `ecommerce.product`, `linkedin.company`, and SEO data: `seo.serp`,
366
+ * `seo.keywords`, `seo.keyword_ideas`, `seo.domain`, `seo.backlinks`, `seo.audit`,
367
+ * `seo.ai_mentions`) or `email.send`.
365
368
  */
366
369
  actions = {
367
370
  run: (name, input) => this.request(`/app/actions/${encodeURIComponent(name)}`, {
@@ -373,6 +376,11 @@ var VibizApp = class _VibizApp {
373
376
  * first call, before the owner has verified anything. Refunds and
374
377
  * withdrawals are the owner's, in the console.
375
378
  */
379
+ entitlementList(user) {
380
+ return this.request(
381
+ `/app/payments/entitlements?user=${encodeURIComponent(user)}`
382
+ );
383
+ }
376
384
  payments = {
377
385
  /** A hosted checkout page for a price (one-time or a subscription) or an ad-hoc item. */
378
386
  checkout: (input) => this.request(
@@ -386,8 +394,33 @@ var VibizApp = class _VibizApp {
386
394
  );
387
395
  return r.data[0] ?? null;
388
396
  },
389
- /** Whether the user has an active (or trialing) subscription, optionally to one price id or lookup key. */
397
+ /**
398
+ * What the user has now, across web checkout subscriptions and App Store / Google Play
399
+ * purchases: one entry per thing it gives, with its `source`. Server-side only.
400
+ */
401
+ entitlements: async (user) => (await this.entitlementList(user)).data,
402
+ /**
403
+ * Whether the user has it now: anything (no `key`), or one thing, matched in this order:
404
+ * an entitlement key (`pro`; a string that is one of the project's entitlement keys is
405
+ * matched only as that), else a lookup key (`pro-monthly`), a price id, a store product id.
406
+ * Counts the web checkout and the App Store / Google Play alike.
407
+ */
390
408
  hasActive: async (user, price) => {
409
+ let list2 = null;
410
+ try {
411
+ list2 = await this.entitlementList(user);
412
+ } catch (err) {
413
+ if (!(err instanceof VibizAppError) || err.status !== 404) throw err;
414
+ }
415
+ if (list2) {
416
+ const grants = list2.data;
417
+ if (!price) return grants.length > 0;
418
+ if (grants.some((g) => g.key === price)) return true;
419
+ if (list2.entitlement_keys?.includes(price)) return false;
420
+ return grants.some(
421
+ (g) => g.lookup_key === price || g.price_id === price || g.store_product_id === price
422
+ );
423
+ }
391
424
  const r = await this.request(
392
425
  `/app/payments/subscriptions?user=${encodeURIComponent(user)}&status=active,trialing`
393
426
  );
@@ -2772,10 +2805,177 @@ function printOutput(io, action, out) {
2772
2805
  `);
2773
2806
  }
2774
2807
  return;
2808
+ case "seo.serp":
2809
+ io.log(
2810
+ `${out.keyword} (${out.location}, ${out.device}${out.total_results ? `, ${num(out.total_results)} results` : ""})
2811
+ `
2812
+ );
2813
+ table2(
2814
+ io,
2815
+ ["#", "type", "domain", "title"],
2816
+ (out.results ?? []).map((r) => [r.position, r.type, r.domain ?? "", r.title ?? r.url])
2817
+ );
2818
+ if (out.features?.length) io.log(`
2819
+ on the page: ${out.features.join(", ")}`);
2820
+ return;
2821
+ case "seo.keywords":
2822
+ table2(
2823
+ io,
2824
+ ["keyword", "searches/mo", "cpc", "competition"],
2825
+ (out.keywords ?? []).map((k) => [
2826
+ k.keyword,
2827
+ num(k.search_volume),
2828
+ money2(k.cpc_usd),
2829
+ k.competition ?? ""
2830
+ ])
2831
+ );
2832
+ return;
2833
+ case "seo.keyword_ideas":
2834
+ table2(
2835
+ io,
2836
+ ["keyword", "searches/mo", "cpc", "competition", "difficulty"],
2837
+ (out.ideas ?? []).map((k) => [
2838
+ k.keyword,
2839
+ num(k.search_volume),
2840
+ money2(k.cpc_usd),
2841
+ k.competition ?? "",
2842
+ k.difficulty ?? ""
2843
+ ])
2844
+ );
2845
+ if (out.total) io.log(`
2846
+ ${num(out.total)} ideas in all`);
2847
+ return;
2848
+ case "seo.domain":
2849
+ io.log(
2850
+ `${out.domain} ${num(out.organic?.keywords)} keywords \xB7 ~${num(out.organic?.traffic_estimate)} visits/mo \xB7 worth ${money2(out.organic?.traffic_value_usd)}/mo in ads
2851
+ `
2852
+ );
2853
+ table2(
2854
+ io,
2855
+ ["#", "keyword", "searches/mo", "url"],
2856
+ (out.top_keywords ?? []).map((k) => [
2857
+ k.position ?? "",
2858
+ k.keyword,
2859
+ num(k.search_volume),
2860
+ k.url ?? ""
2861
+ ])
2862
+ );
2863
+ io.log("\ncompetitors");
2864
+ table2(
2865
+ io,
2866
+ ["domain", "shared keywords", "visits/mo"],
2867
+ (out.competitors ?? []).map((c) => [
2868
+ c.domain,
2869
+ num(c.common_keywords),
2870
+ num(c.traffic_estimate)
2871
+ ])
2872
+ );
2873
+ return;
2874
+ case "seo.backlinks": {
2875
+ const s = out.summary ?? {};
2876
+ io.log(
2877
+ `${out.target} ${num(s.backlinks)} backlinks from ${num(s.referring_domains)} domains \xB7 rank ${s.rank ?? "?"} \xB7 ${num(s.broken_backlinks)} broken
2878
+ `
2879
+ );
2880
+ table2(
2881
+ io,
2882
+ ["from", "anchor", "follow", "since"],
2883
+ (out.backlinks ?? []).map((b) => [
2884
+ b.from_url,
2885
+ b.anchor ?? "",
2886
+ b.dofollow === false ? "nofollow" : "follow",
2887
+ b.first_seen?.slice(0, 10) ?? ""
2888
+ ])
2889
+ );
2890
+ return;
2891
+ }
2892
+ case "seo.audit":
2893
+ io.log(
2894
+ `${out.url} ${out.status_code ?? "?"} score ${out.score ?? "?"} ${out.load_time_ms ?? "?"} ms ${out.word_count ?? "?"} words links ${out.links?.internal ?? "?"} in / ${out.links?.external ?? "?"} out`
2895
+ );
2896
+ io.log(`title ${out.title ?? "(none)"}`);
2897
+ io.log(`description ${out.description ?? "(none)"}`);
2898
+ io.log(`h1 ${out.h1?.length ? out.h1.join(" | ") : "(none)"}
2899
+ `);
2900
+ if (!out.issues?.length) io.log("No issues found.");
2901
+ for (const i of out.issues ?? []) io.log(`${String(i.severity).padEnd(7)} ${i.message}`);
2902
+ return;
2903
+ case "seo.ai_mentions":
2904
+ io.log(
2905
+ `${out.target} ${out.total} mentions (${Object.entries(out.by_platform ?? {}).map(([p, n]) => `${p} ${n}`).join(", ")})
2906
+ `
2907
+ );
2908
+ for (const m of out.mentions ?? []) {
2909
+ io.log(`${m.platform}: ${m.question ?? ""}`);
2910
+ if (m.answer_excerpt) io.log(` ${m.answer_excerpt}`);
2911
+ if (m.url) io.log(` ${m.url}`);
2912
+ io.log("");
2913
+ }
2914
+ return;
2775
2915
  default:
2776
2916
  io.log(JSON.stringify(out, null, 2));
2777
2917
  }
2778
2918
  }
2919
+ var num = (v) => typeof v === "number" ? Math.round(v).toLocaleString("en-US") : "\u2013";
2920
+ var money2 = (v) => typeof v === "number" ? `$${v.toFixed(2)}` : "\u2013";
2921
+ function table2(io, head, rows) {
2922
+ if (!rows.length) return io.log("(none)");
2923
+ const cells = [head, ...rows.map((r) => r.map((c) => String(c ?? "")))].map(
2924
+ (r) => r.map((c) => c.length > 60 ? `${c.slice(0, 59)}\u2026` : c)
2925
+ );
2926
+ const widths = head.map((_, i) => Math.max(...cells.map((r) => (r[i] ?? "").length)));
2927
+ for (const r of cells) {
2928
+ io.log(
2929
+ r.map((c, i) => c.padEnd(widths[i] ?? 0)).join(" ").trimEnd()
2930
+ );
2931
+ }
2932
+ }
2933
+ var SEO_USAGE = 'vibiz seo serp "<keyword>" | keywords k1,k2 | ideas "<keyword>" | domain example.com | backlinks example.com | audit <url> | ai example.com [--location "United States"] [--language en] [--limit n] [--project id] [--json]';
2934
+ var SEO_ACTIONS = {
2935
+ serp: "seo.serp",
2936
+ keywords: "seo.keywords",
2937
+ ideas: "seo.keyword_ideas",
2938
+ keyword_ideas: "seo.keyword_ideas",
2939
+ domain: "seo.domain",
2940
+ backlinks: "seo.backlinks",
2941
+ audit: "seo.audit",
2942
+ ai: "seo.ai_mentions",
2943
+ ai_mentions: "seo.ai_mentions"
2944
+ };
2945
+ async function seoCommand(io, args, flags) {
2946
+ const [what = "", ...rest] = args;
2947
+ const target = rest.join(" ").trim();
2948
+ const action = SEO_ACTIONS[what.replace(/-/g, "_")];
2949
+ if (!action || !target) throw usage(SEO_USAGE);
2950
+ const extra = flags.input ? JSON.parse(flags.input) : {};
2951
+ const limit = int(flags.limit, "limit");
2952
+ const depth = int(flags.depth, "depth");
2953
+ const locale = {
2954
+ ...flags.location ? { location: flags.location } : {},
2955
+ ...flags.language ? { language: flags.language } : {}
2956
+ };
2957
+ const lim = limit ? { limit } : {};
2958
+ const keywords = target.split(/[,\n]/).map((k) => k.trim()).filter(Boolean);
2959
+ const input = {
2960
+ "seo.serp": {
2961
+ keyword: target,
2962
+ ...locale,
2963
+ ...depth ? { depth } : {},
2964
+ ...flags.device ? { device: flags.device } : {}
2965
+ },
2966
+ "seo.keywords": { keywords, ...locale },
2967
+ "seo.keyword_ideas": { keywords, ...locale, ...lim },
2968
+ "seo.domain": { domain: target, ...locale, ...lim },
2969
+ "seo.backlinks": { target, ...lim },
2970
+ "seo.audit": { url: target },
2971
+ "seo.ai_mentions": {
2972
+ target,
2973
+ ...lim,
2974
+ ...flags.platform ? { platform: flags.platform } : {}
2975
+ }
2976
+ };
2977
+ return runOne(io, await io.client(), action, { ...input[action], ...extra }, flags);
2978
+ }
2779
2979
  async function runOne(io, vibiz2, action, input, flags) {
2780
2980
  const res = flags.project ? await vibiz2.projects.runAction(flags.project, action, input) : await vibiz2.actions.run(action, input);
2781
2981
  if (flags.json) {
@@ -3008,9 +3208,12 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3008
3208
  vibiz payments [--dev] [--json] take payments: balance, getting paid, the next step
3009
3209
  (production for full-access keys; --dev test mode)
3010
3210
  vibiz payments products [--dev] the catalog; add one with
3011
- products add <name> --amount <cents> [--interval month|year] [--lookup-key k]
3211
+ products add <name> --amount <cents> [--currency eur] [--interval month|year] [--lookup-key k]
3212
+ (--amount in the currency's smallest unit; usd by default)
3012
3213
  vibiz payments checkout <price_id|lookup_key> --success-url <u> --cancel-url <u> [--user id]
3013
- a checkout link to pay right now
3214
+ [--brand-name n] [--brand-logo https://\u2026] [--brand-icon https://\u2026] [--brand-color #hex]
3215
+ [--brand-background #hex] [--brand-font inter] [--brand-border pill|rounded|rectangular]
3216
+ a checkout link to pay right now, in your brand
3014
3217
  vibiz payments list [--dev] payments, newest first
3015
3218
  vibiz payments webhook <url|none> [--dev] where Vibiz POSTs payment events (the app verifies
3016
3219
  them with VIBIZ_WEBHOOK_SECRET: vibiz docs webhooks)
@@ -3024,7 +3227,30 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3024
3227
  vibiz payments connect [--dev] [--open] a link for the owner to connect their own Stripe
3025
3228
  account instead (sales charged and paid out there);
3026
3229
  give it to them: only they can complete it
3027
- vibiz payments disconnect [--dev] owner: back to payments through Vibiz
3230
+ vibiz payments disconnect [--dev] owner: back to payments through Vibiz (an opt-out:
3231
+ account apply leaves the project alone)
3232
+ vibiz payments use-account [--dev] owner: put the project on your Stripe account for
3233
+ every project
3234
+ vibiz payments account [--json] your Stripe connected once for every project: each
3235
+ environment, and how each project uses it
3236
+ vibiz payments account connect [--dev] [--open]
3237
+ a link for the owner to connect it once (Settings \u25B8
3238
+ Payments); only they can complete it
3239
+ vibiz payments account default <on|off> owner: new projects start on it (or not)
3240
+ vibiz payments account apply [--dev] [--yes]
3241
+ owner: switch existing projects to it for new sales;
3242
+ lists what changes and asks you to confirm
3243
+ vibiz payments account disconnect [--dev] owner: projects on it go back to payments through Vibiz
3244
+ vibiz payments app-store connect [--open] a link for the owner to connect their own RevenueCat
3245
+ account (they paste its secret key there, once)
3246
+ vibiz payments app-store setup --ios <bundle id> [--android <package>] [--store-project <id>] [--dev]
3247
+ iOS/Android in-app purchases: the app in their
3248
+ RevenueCat account, this catalog mirrored, the public
3249
+ SDK key and the App Store product ids (safe to re-run)
3250
+ vibiz payments app-store [--dev] [--json] what is set up and the steps left (no Vibiz fee on
3251
+ store purchases)
3252
+ vibiz payments app-store subscriptions [--user id] [--dev]
3253
+ App Store and Google Play purchases recorded
3028
3254
  vibiz social [--dev] [--json] the project's social and ad accounts, posts waiting for
3029
3255
  you, scheduled and failed (docs/SOCIAL.md); --dev is the
3030
3256
  sandbox: nothing is posted, nothing is spent
@@ -3044,6 +3270,13 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3044
3270
  vibiz social campaigns [--dev] ad campaigns with budget and spend
3045
3271
  vibiz social pause|resume <campaign> [--dev] | budget <campaign> --budget <cents>
3046
3272
  change a campaign (live: you confirm; agents ask the owner)
3273
+ vibiz social campaigns create --type search|display|pmax --name "<name>" --budget <minor units/day>
3274
+ --final-url <https> --headline "\u2026"\u2026 --desc "\u2026"\u2026 --country US[,CA] [--keyword "text[:phrase|exact]"]\u2026
3275
+ [--language en] [--business-name n] [--long-headline t] [--image landscape|square|logo=<file|url>]\u2026
3276
+ [--bidding maximize_clicks|maximize_conversions] [--max-cpc c] [--target-cpa c]
3277
+ [--start-date YYYY-MM-DD] [--end-date \u2026] [--file campaign.json] [--active] [--dev]
3278
+ a Google Ads campaign, created PAUSED (--active starts
3279
+ spending; live: you confirm; agents ask the owner)
3047
3280
  vibiz connectors [list] [--json] your own APIs, called through Vibiz, which holds their
3048
3281
  keys (docs/CONNECTORS.md)
3049
3282
  vibiz connectors import <spec-url|file> [--name n] [--enable op,op] [--add]
@@ -3084,6 +3317,11 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3084
3317
  vibiz replays [--errors] [--rage] [--dead] [--path /x] [--period 7d] [--json]
3085
3318
  what went wrong for visitors, then sessions to watch
3086
3319
  vibiz replay <id> [--json] one session's signals and a link to watch it
3320
+ vibiz replays frames <id> [--at <ms>] [--moments error,rage_click] [--limit 6] [--out dir] [--open] [--json]
3321
+ pictures of what the visitor saw at each page, error,
3322
+ rage/dead click, abandoned form and the end (or at one
3323
+ instant): look for broken layout. --out saves the PNGs.
3324
+ Each new picture is one page screenshot; repeats free
3087
3325
  vibiz projects list your projects
3088
3326
  Web data (billed per call; every run is kept: vibiz runs, console \u25B8 Web data)
3089
3327
  vibiz scrape <url> [--json] one page as markdown
@@ -3101,6 +3339,18 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3101
3339
  ads on Facebook and Instagram from the Meta Ad Library;
3102
3340
  a page URL or page id (or --page "<name>") is one
3103
3341
  advertiser's ads; --all includes stopped ads
3342
+ vibiz seo serp "<keyword>" [--location "United States"] [--language en] [--depth 10] [--device mobile]
3343
+ who ranks on Google for a keyword
3344
+ vibiz seo keywords k1,k2,\u2026 monthly searches, CPC and competition (up to 1000)
3345
+ vibiz seo ideas "<keyword>" [--limit 50] related keywords with volume and difficulty
3346
+ vibiz seo domain example.com [--limit 20] a site's search traffic, top keywords, competitors
3347
+ vibiz seo backlinks example.com [--limit 20]
3348
+ who links to a domain or page
3349
+ vibiz seo audit <url> one page's on-page SEO and the issues to fix
3350
+ vibiz seo ai example.com [--platform chatgpt|google]
3351
+ how often ChatGPT and Google AI Overviews mention it.
3352
+ Every seo command: --location, --language, --project,
3353
+ --json
3104
3354
  vibiz runs [--action a] [--since 1d] [--project id] [--json] past runs, newest first
3105
3355
  vibiz runs <run_id> [--json] one run's input and output again
3106
3356
  vibiz actions [--json] every action and its input fields
@@ -3118,6 +3368,9 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3118
3368
  social.posts Instagram or TikTok posts for a hashtag
3119
3369
  ecommerce.product price, stock, images of a product
3120
3370
  linkedin.company a public LinkedIn company page
3371
+ seo.serp, seo.keywords, seo.keyword_ideas,
3372
+ seo.domain, seo.backlinks, seo.audit,
3373
+ seo.ai_mentions SEO data (vibiz seo)
3121
3374
  vibiz send --to <addr> --subject <s> --text <body> [--html-file f] [--from info]
3122
3375
  send email from this project's address
3123
3376
  vibiz email inbox [--view inbox|starred|sent|archive|spam|trash|all] [--q words] [--unread] [--mailbox id]
@@ -3639,6 +3892,84 @@ async function emailForwardCommand(io, vibiz2, values, positionals) {
3639
3892
  );
3640
3893
  }
3641
3894
  var positionalsAfter = (a, b) => b ? `${a} ${b}` : a;
3895
+ async function framesCommand(io, id, values) {
3896
+ if (!id) {
3897
+ throw new Error(
3898
+ "usage: vibiz replays frames <replay id> [--at <ms>] [--moments error,rage_click] [--limit 6] [--out dir] [--open]"
3899
+ );
3900
+ }
3901
+ const at = values.at === void 0 ? void 0 : Number(values.at);
3902
+ if (at !== void 0 && (!Number.isFinite(at) || at < 0)) {
3903
+ throw new Error(
3904
+ "--at is milliseconds from the session start (offset_ms in `vibiz replay <id>`)"
3905
+ );
3906
+ }
3907
+ const limit = values.limit === void 0 ? void 0 : Number(values.limit);
3908
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1 || limit > 12)) {
3909
+ throw new Error("--limit is 1 to 12");
3910
+ }
3911
+ const kinds = values.moments?.split(",").map((k) => k.trim()).filter(Boolean);
3912
+ const out = await (await io.client()).replays.frames(id, {
3913
+ ...at !== void 0 ? { at } : {},
3914
+ ...limit !== void 0 ? { limit } : {},
3915
+ ...kinds?.length ? { moments: kinds } : {}
3916
+ });
3917
+ const saved = /* @__PURE__ */ new Map();
3918
+ if (values.out) {
3919
+ const local = io.local();
3920
+ const dir = resolve2(local.cwd(), values.out);
3921
+ await local.mkdir(dir, { recursive: true });
3922
+ const vibiz2 = await io.client();
3923
+ for (const f of out.frames) {
3924
+ if (!f.image || !f.id) continue;
3925
+ const bytes = await vibiz2.replays.frameImage(f.image.url).catch((err) => {
3926
+ io.error(` could not download ${f.id}: ${err instanceof Error ? err.message : err}`);
3927
+ return null;
3928
+ });
3929
+ if (!bytes) continue;
3930
+ const file = join7(dir, `${String(f.offset_ms).padStart(7, "0")}-${f.kind}-${f.id}.png`);
3931
+ await local.writeFile(file, bytes);
3932
+ saved.set(f.id, file);
3933
+ }
3934
+ }
3935
+ if (values.open) {
3936
+ for (const f of out.frames) if (f.image) io.openUrl(f.image.url);
3937
+ }
3938
+ if (values.json) {
3939
+ io.log(
3940
+ JSON.stringify(
3941
+ {
3942
+ ...out,
3943
+ frames: out.frames.map((f) => ({
3944
+ ...f,
3945
+ ...f.id && saved.has(f.id) ? { file: saved.get(f.id) } : {}
3946
+ }))
3947
+ },
3948
+ null,
3949
+ 2
3950
+ )
3951
+ );
3952
+ return;
3953
+ }
3954
+ io.log(`Frames of ${out.replay_id} (${clock(out.duration_ms)}):`);
3955
+ if (!out.frames.length) io.log(" none");
3956
+ for (const f of out.frames) {
3957
+ const where = `${clock(f.offset_ms).padStart(6)} ${f.kind.padEnd(14)} ${f.page}`;
3958
+ const size = f.viewport ? ` ${f.viewport.width}x${f.viewport.height}` : "";
3959
+ const label = f.label === f.page ? "" : ` ${f.label}`;
3960
+ io.log(` ${dot(f.status === "ready" ? "ready" : "failed")} ${where}${size}${label}`);
3961
+ if (f.id && saved.has(f.id)) io.log(` saved ${saved.get(f.id)}`);
3962
+ else if (f.image) io.log(` ${f.image.url}`);
3963
+ if (f.error) io.log(` ${f.error.message} ${f.error.next_step}`);
3964
+ }
3965
+ const usd5 = (out.cost_micro_usd / 1e6).toFixed(4);
3966
+ const n = out.new_frames;
3967
+ io.log(
3968
+ `
3969
+ ${n} new picture${n === 1 ? "" : "s"} ($${usd5}); pictures taken before are free. Links work for an hour.`
3970
+ );
3971
+ io.log(` ${out.note}`);
3972
+ }
3642
3973
  var RESOURCE_NAMES = [
3643
3974
  "hosting",
3644
3975
  "database",
@@ -3755,6 +4086,19 @@ var SOCIAL_LABELS = {
3755
4086
  };
3756
4087
  var socialLabel = (platform3) => SOCIAL_LABELS[platform3] ?? platform3;
3757
4088
  var cents2 = (n) => `$${(n / 100).toFixed(2)}`;
4089
+ var money3 = (n, currency = "usd") => {
4090
+ if (currency === "usd") return cents2(n);
4091
+ try {
4092
+ const f = new Intl.NumberFormat("en-US", {
4093
+ style: "currency",
4094
+ currency: currency.toUpperCase()
4095
+ });
4096
+ const digits = f.resolvedOptions().maximumFractionDigits ?? 2;
4097
+ return f.format(n / 10 ** digits);
4098
+ } catch {
4099
+ return `${n} ${currency}`;
4100
+ }
4101
+ };
3758
4102
  var companyName = (c) => c.legal_name ?? (c.names[0] ? `${c.names[0].name} ${c.names[0].ending}` : "(no name yet)");
3759
4103
  function printCompany(io, c) {
3760
4104
  const label = c.entity_type === "llc" ? "LLC" : "C-Corp";
@@ -3784,6 +4128,101 @@ function printCompany(io, c) {
3784
4128
  if (next) io.log(`
3785
4129
  next: ${next}`);
3786
4130
  }
4131
+ var USAGE_WORDS = {
4132
+ account: "your Stripe account (every project)",
4133
+ other_account: "its own Stripe account",
4134
+ vibiz: "through Vibiz",
4135
+ opted_out: "through Vibiz (opted out)",
4136
+ not_started: "no payments yet"
4137
+ };
4138
+ async function ownerStripeCommand(io, vibiz2, [sub, arg], flags) {
4139
+ const env = flags.dev ? "development" : "production";
4140
+ const out = (x, text) => flags.json ? io.log(JSON.stringify(x, null, 2)) : text();
4141
+ const print = (s) => {
4142
+ for (const e of ["production", "development"]) {
4143
+ const x = s.environments[e];
4144
+ io.log(
4145
+ `${e}: ${x.connected ? `connected${x.account_name ? ` (${x.account_name})` : ""}` : x.available ? "not connected" : "not available right now"}`
4146
+ );
4147
+ }
4148
+ io.log(`Use for every new project: ${s.use_for_all_projects ? "on" : "off"}`);
4149
+ for (const p of s.projects) {
4150
+ io.log(
4151
+ ` ${p.name} production: ${USAGE_WORDS[p.production]} \xB7 development: ${USAGE_WORDS[p.development]}`
4152
+ );
4153
+ }
4154
+ io.log(`
4155
+ ${s.note}`);
4156
+ };
4157
+ if (!sub) {
4158
+ const s = await vibiz2.payments.ownAccount.get();
4159
+ out(s, () => print(s));
4160
+ return;
4161
+ }
4162
+ if (sub === "connect") {
4163
+ const link = await vibiz2.payments.ownAccount.link(env);
4164
+ out(link, () => {
4165
+ io.log(
4166
+ `Give this link to the account's owner (until ${link.expires_at.slice(0, 16).replace("T", " ")}):
4167
+ ${link.url}`
4168
+ );
4169
+ io.log(
4170
+ "\n They sign in to the console and connect their Stripe account once, for every project. Nobody else can complete it."
4171
+ );
4172
+ });
4173
+ if (flags.open) io.openUrl(link.url);
4174
+ return;
4175
+ }
4176
+ if (sub === "default") {
4177
+ if (arg !== "on" && arg !== "off")
4178
+ throw new Error("usage: vibiz payments account default <on|off>");
4179
+ const s = await vibiz2.payments.ownAccount.update({ use_for_all_projects: arg === "on" });
4180
+ out(s, () => print(s));
4181
+ return;
4182
+ }
4183
+ if (sub === "apply") {
4184
+ const input = flags.dev ? { env } : {};
4185
+ const preview = await vibiz2.payments.ownAccount.apply({ ...input, dry_run: true });
4186
+ const show = (r2) => {
4187
+ for (const c of r2.changed) {
4188
+ io.log(
4189
+ ` ${r2.dry_run ? "will switch" : "switched"}: ${c.name} (${c.environment})${c.balance_cents ? ` \xB7 ${cents2(c.balance_cents)} stays in its balance to withdraw` : ""}${c.vibiz_subscriptions ? ` \xB7 ${c.vibiz_subscriptions} subscription(s) keep billing through Vibiz` : ""}`
4190
+ );
4191
+ }
4192
+ for (const x of r2.skipped) io.log(` skipped: ${x.name} (${x.environment}): ${x.message}`);
4193
+ io.log(`
4194
+ ${r2.note}`);
4195
+ };
4196
+ if (!preview.changed.length || flags.json) {
4197
+ if (flags.yes && preview.changed.length) {
4198
+ const r2 = await vibiz2.payments.ownAccount.apply(input);
4199
+ out(r2, () => show(r2));
4200
+ return;
4201
+ }
4202
+ out(preview, () => {
4203
+ if (!preview.changed.length) io.log("Nothing to switch.");
4204
+ show(preview);
4205
+ });
4206
+ return;
4207
+ }
4208
+ show(preview);
4209
+ if (!flags.yes) {
4210
+ const typed = await io.promptLine('Type "yes" to switch these projects: ');
4211
+ if (typed.trim().toLowerCase() !== "yes") throw new Error("Not confirmed: nothing changed.");
4212
+ }
4213
+ const r = await vibiz2.payments.ownAccount.apply(input);
4214
+ out(r, () => show(r));
4215
+ return;
4216
+ }
4217
+ if (sub === "disconnect") {
4218
+ const r = await vibiz2.payments.ownAccount.disconnect(env);
4219
+ out(r, () => io.log(r.note));
4220
+ return;
4221
+ }
4222
+ throw new Error(
4223
+ "usage: vibiz payments account [connect | default <on|off> | apply | disconnect]"
4224
+ );
4225
+ }
3787
4226
  function printPayments(io, a) {
3788
4227
  const b = a.balance;
3789
4228
  const own = a.account?.mode === "own";
@@ -3828,25 +4267,25 @@ function printAnalytics(io, r) {
3828
4267
  io.log(
3829
4268
  ` ${r.timeseries.map((p) => bars[Math.round(p.visitors / peak * (bars.length - 1))]).join("")}`
3830
4269
  );
3831
- const table2 = (title, rows) => {
4270
+ const table3 = (title, rows) => {
3832
4271
  if (!rows.length) return;
3833
4272
  io.log(`
3834
4273
  ${title}`);
3835
4274
  for (const [label, n] of rows) io.log(` ${String(n).padStart(6)} ${label}`);
3836
4275
  };
3837
- table2(
4276
+ table3(
3838
4277
  "top pages (pageviews)",
3839
4278
  r.top_pages.map((p) => [p.path, p.pageviews])
3840
4279
  );
3841
- table2(
4280
+ table3(
3842
4281
  "sources (visitors)",
3843
4282
  r.sources.map((s) => [s.source, s.visitors])
3844
4283
  );
3845
- table2(
4284
+ table3(
3846
4285
  "countries (visitors)",
3847
4286
  r.countries.map((c) => [c.country, c.visitors])
3848
4287
  );
3849
- table2(
4288
+ table3(
3850
4289
  "events",
3851
4290
  r.events.map((e) => [e.name, e.count])
3852
4291
  );
@@ -3956,6 +4395,82 @@ function commandHelp(command) {
3956
4395
 
3957
4396
  Everything: vibiz help` : HELP;
3958
4397
  }
4398
+ async function campaignCreateInputFrom(values, vibiz2, id, env, mediaUrl, readFile4) {
4399
+ const v = values;
4400
+ let base = {};
4401
+ if (v.file) {
4402
+ const file = String(v.file);
4403
+ const text = await readFile4(file);
4404
+ try {
4405
+ base = JSON.parse(text);
4406
+ } catch (e) {
4407
+ throw new Error(
4408
+ `${file} is not valid JSON (${e instanceof Error ? e.message : String(e)}): fix it, or use the flags instead.`
4409
+ );
4410
+ }
4411
+ if (!base || typeof base !== "object" || Array.isArray(base))
4412
+ throw new Error(`${file} must hold one JSON object with the campaign's fields.`);
4413
+ delete base.confirm;
4414
+ }
4415
+ const list2 = (k) => Array.isArray(v[k]) ? v[k] : void 0;
4416
+ const str = (k) => typeof v[k] === "string" ? v[k] : void 0;
4417
+ const cents3 = (k, what) => {
4418
+ const raw = str(k);
4419
+ if (raw === void 0) return void 0;
4420
+ const n = Number(raw);
4421
+ if (!Number.isInteger(n) || n < 1) throw new Error(`--${k} is ${what} in cents, such as 2000`);
4422
+ return n;
4423
+ };
4424
+ const input = { ...base };
4425
+ if (str("type")) input.campaign_type = str("type");
4426
+ if (str("name")) input.name = str("name");
4427
+ const budget = cents3("budget", "the daily budget");
4428
+ if (budget) input.daily_budget_cents = budget;
4429
+ if (str("final-url")) input.final_url = str("final-url");
4430
+ if (list2("headline")) input.headlines = list2("headline");
4431
+ if (list2("desc")) input.descriptions = list2("desc");
4432
+ if (str("long-headline")) input.long_headline = str("long-headline");
4433
+ if (str("business-name")) input.business_name = str("business-name");
4434
+ if (list2("keyword")) {
4435
+ input.keywords = (list2("keyword") ?? []).map((k) => {
4436
+ const m = /^(.*):(broad|phrase|exact)$/.exec(k);
4437
+ return m?.[1] ? { text: m[1], match_type: m[2] } : k;
4438
+ });
4439
+ }
4440
+ if (str("country"))
4441
+ input.countries = String(str("country")).split(",").map((c) => c.trim().toUpperCase()).filter(Boolean);
4442
+ if (input.countries) input.countries = input.countries.map((c) => c.trim().toUpperCase());
4443
+ if (str("language")) input.languages = String(str("language")).split(",").filter(Boolean);
4444
+ if (str("start-date")) input.start_date = str("start-date");
4445
+ if (str("end-date")) input.end_date = str("end-date");
4446
+ if (str("bidding")) input.bidding = str("bidding");
4447
+ const maxCpc = cents3("max-cpc", "a cap per click");
4448
+ if (maxCpc) input.max_cpc_cents = maxCpc;
4449
+ const cpa = cents3("target-cpa", "a target cost per conversion");
4450
+ if (cpa) input.target_cpa_cents = cpa;
4451
+ if (v.active) input.start = "active";
4452
+ for (const spec of list2("image") ?? []) {
4453
+ const m = /^(landscape|square|logo)=(.+)$/.exec(spec);
4454
+ if (!m?.[1] || !m[2]) throw new Error("--image is landscape=<file|url>, square=\u2026 or logo=\u2026");
4455
+ const role = m[1];
4456
+ input.images = {
4457
+ ...input.images,
4458
+ [role]: [...input.images?.[role] ?? [], await mediaUrl(m[2])]
4459
+ };
4460
+ }
4461
+ if (!input.account_id || !input.ad_account_id) {
4462
+ const accounts = (await vibiz2.projects.social.accounts(id, { env, kind: "ads" })).data;
4463
+ const google = str("account") ? accounts.find((a) => a.id === str("account")) : accounts.find((a) => a.platform === "google" && a.status === "connected");
4464
+ if (!google)
4465
+ throw new Error(
4466
+ "No Google Ads connection on this project: vibiz social connect google --ads (add --dev for the sandbox)."
4467
+ );
4468
+ input.account_id ??= google.id;
4469
+ const adAccounts = google.details.ad_accounts ?? [];
4470
+ input.ad_account_id ??= str("ad-account") ?? adAccounts[0]?.id;
4471
+ }
4472
+ return input;
4473
+ }
3959
4474
  async function runCli(argv2, io) {
3960
4475
  const [command, ...all] = argv2;
3961
4476
  const cut = all.indexOf("--");
@@ -4018,6 +4533,17 @@ async function runCli(argv2, io) {
4018
4533
  amount: { type: "string" },
4019
4534
  interval: { type: "string" },
4020
4535
  "lookup-key": { type: "string" },
4536
+ ios: { type: "string" },
4537
+ android: { type: "string" },
4538
+ "store-project": { type: "string" },
4539
+ currency: { type: "string" },
4540
+ "brand-name": { type: "string" },
4541
+ "brand-logo": { type: "string" },
4542
+ "brand-icon": { type: "string" },
4543
+ "brand-color": { type: "string" },
4544
+ "brand-background": { type: "string" },
4545
+ "brand-font": { type: "string" },
4546
+ "brand-border": { type: "string" },
4021
4547
  user: { type: "string" },
4022
4548
  "success-url": { type: "string" },
4023
4549
  "cancel-url": { type: "string" },
@@ -4035,6 +4561,7 @@ async function runCli(argv2, io) {
4035
4561
  ads: { type: "boolean", default: false },
4036
4562
  media: { type: "string", multiple: true },
4037
4563
  at: { type: "string" },
4564
+ moments: { type: "string" },
4038
4565
  draft: { type: "boolean", default: false },
4039
4566
  opt: { type: "string", multiple: true },
4040
4567
  status: { type: "string" },
@@ -4082,6 +4609,10 @@ async function runCli(argv2, io) {
4082
4609
  tag: { type: "string" },
4083
4610
  limit: { type: "string" },
4084
4611
  country: { type: "string" },
4612
+ location: { type: "string" },
4613
+ depth: { type: "string" },
4614
+ device: { type: "string" },
4615
+ platform: { type: "string" },
4085
4616
  "max-pages": { type: "string" },
4086
4617
  action: { type: "string" },
4087
4618
  cursor: { type: "string" },
@@ -4118,7 +4649,22 @@ async function runCli(argv2, io) {
4118
4649
  "business-name": { type: "string" },
4119
4650
  "double-opt-in": { type: "string" },
4120
4651
  "agent-limit": { type: "string" },
4121
- description: { type: "string" }
4652
+ description: { type: "string" },
4653
+ // vibiz social campaigns create
4654
+ headline: { type: "string", multiple: true },
4655
+ desc: { type: "string", multiple: true },
4656
+ keyword: { type: "string", multiple: true },
4657
+ image: { type: "string", multiple: true },
4658
+ "final-url": { type: "string" },
4659
+ "long-headline": { type: "string" },
4660
+ "start-date": { type: "string" },
4661
+ "end-date": { type: "string" },
4662
+ bidding: { type: "string" },
4663
+ "max-cpc": { type: "string" },
4664
+ "target-cpa": { type: "string" },
4665
+ account: { type: "string" },
4666
+ "ad-account": { type: "string" },
4667
+ active: { type: "boolean", default: false }
4122
4668
  }
4123
4669
  });
4124
4670
  const usagePeriod = (fallback) => {
@@ -4385,9 +4931,91 @@ ${await oneKeyLines(vibiz2, project.id)}`);
4385
4931
  }
4386
4932
  case "company": {
4387
4933
  const vibiz2 = await io.client();
4934
+ if (positionals[0] === "app-store" && positionals[1] === "connect") {
4935
+ const link = await vibiz2.payments.appStore.link();
4936
+ if (values.json) io.log(JSON.stringify(link, null, 2));
4937
+ else {
4938
+ io.log(
4939
+ `Give this link to the account's owner (until ${link.expires_at.slice(0, 16).replace("T", " ")}):
4940
+ ${link.url}`
4941
+ );
4942
+ io.log(
4943
+ "\n Signed in to the console, they paste a V2 secret key from their RevenueCat dashboard \u25B8 Project settings \u25B8 API keys. Never paste it in a chat."
4944
+ );
4945
+ }
4946
+ if (values.open) io.openUrl(link.url);
4947
+ return;
4948
+ }
4388
4949
  const id = await io.project();
4389
4950
  const env = values.dev ? "development" : void 0;
4390
4951
  const [sub, arg, arg2] = positionals;
4952
+ if (sub === "app-store") {
4953
+ const out = (x, text) => values.json ? io.log(JSON.stringify(x, null, 2)) : text();
4954
+ const steps = (next) => {
4955
+ for (const n of next) io.log(` - ${n}`);
4956
+ };
4957
+ if (arg === "setup") {
4958
+ const r2 = await vibiz2.projects.payments.appStore.setup(
4959
+ id,
4960
+ {
4961
+ ...values.ios ? { ios_bundle_id: values.ios } : {},
4962
+ ...values.android ? { android_package: values.android } : {},
4963
+ ...values["store-project"] ? { store_project_id: values["store-project"] } : {}
4964
+ },
4965
+ env
4966
+ );
4967
+ out(r2, () => {
4968
+ io.log(`App Store & Google Play (${r2.environment}) on ${r2.store_project.name}`);
4969
+ if (r2.ios)
4970
+ io.log(` iOS ${r2.ios.bundle_id}: ${r2.ios.env_var}=${r2.ios.public_key ?? "\u2013"}`);
4971
+ if (r2.android)
4972
+ io.log(
4973
+ ` Android ${r2.android.package}: ${r2.android.env_var}=${r2.android.public_key ?? "\u2013"}`
4974
+ );
4975
+ for (const p of r2.products) {
4976
+ io.log(
4977
+ ` ${p.lookup_key} \u2192 entitlement ${p.entitlement}${p.app_store_product_id ? ` \xB7 App Store ${p.app_store_product_id}` : ""}${p.play_product_id ? ` \xB7 Play ${p.play_product_id}` : ""}`
4978
+ );
4979
+ }
4980
+ io.log(
4981
+ ` webhook: ${r2.webhook.registered ? "registered" : "not registered"} (${r2.webhook.url})`
4982
+ );
4983
+ io.log("\nNext:");
4984
+ steps(r2.next);
4985
+ });
4986
+ return;
4987
+ }
4988
+ if (arg === "subscriptions") {
4989
+ const r2 = await vibiz2.projects.payments.appStore.subscriptions(id, {
4990
+ ...env ? { env } : {},
4991
+ ...values.user ? { user: values.user } : {}
4992
+ });
4993
+ out(r2, () => {
4994
+ if (!r2.data.length) io.log("No App Store or Google Play purchases yet.");
4995
+ for (const x of r2.data) {
4996
+ io.log(
4997
+ `${x.id} ${x.source} ${x.user} ${x.store_product_id} ${x.status}${x.current_period_end ? ` until ${x.current_period_end.slice(0, 10)}` : ""}`
4998
+ );
4999
+ }
5000
+ });
5001
+ return;
5002
+ }
5003
+ if (arg) {
5004
+ throw new Error(
5005
+ "usage: vibiz payments app-store [connect | setup --ios <bundle id> [--android <package>] | subscriptions]"
5006
+ );
5007
+ }
5008
+ const r = await vibiz2.projects.payments.appStore.get(id, env);
5009
+ out(r, () => {
5010
+ io.log(
5011
+ `App Store & Google Play (${r.environment}): ${r.connected ? r.app ? "set up" : "connected, not set up" : "not connected"}`
5012
+ );
5013
+ steps(r.next);
5014
+ io.log(`
5015
+ ${r.fees_note}`);
5016
+ });
5017
+ return;
5018
+ }
4391
5019
  const show = (c) => values.json ? io.log(JSON.stringify(c, null, 2)) : printCompany(io, c);
4392
5020
  if (!sub) {
4393
5021
  try {
@@ -4475,13 +5103,24 @@ ${link.url}`);
4475
5103
  }
4476
5104
  case "payments": {
4477
5105
  const vibiz2 = await io.client();
5106
+ if (positionals[0] === "account") {
5107
+ await ownerStripeCommand(io, vibiz2, positionals.slice(1), {
5108
+ dev: !!values.dev,
5109
+ json: !!values.json,
5110
+ open: !!values.open,
5111
+ yes: !!values.yes
5112
+ });
5113
+ return;
5114
+ }
4478
5115
  const id = await io.project();
4479
5116
  const env = values.dev ? "development" : void 0;
4480
5117
  const [sub, arg, arg2] = positionals;
4481
5118
  const out = (x, text) => values.json ? io.log(JSON.stringify(x, null, 2)) : text();
4482
5119
  const amount = values.amount !== void 0 ? Number(values.amount) : void 0;
4483
5120
  if (amount !== void 0 && !Number.isInteger(amount)) {
4484
- throw new Error("--amount is in cents: --amount 1500");
5121
+ throw new Error(
5122
+ "--amount is in the currency's smallest unit (cents; whole yen for jpy): --amount 1500"
5123
+ );
4485
5124
  }
4486
5125
  if (!sub) {
4487
5126
  const a = await vibiz2.projects.payments.get(id, env);
@@ -4502,6 +5141,7 @@ ${link.url}`);
4502
5141
  name: arg2,
4503
5142
  price: {
4504
5143
  unit_amount_cents: amount,
5144
+ ...values.currency ? { currency: values.currency.toLowerCase() } : {},
4505
5145
  type: interval ? "recurring" : "one_time",
4506
5146
  ...interval ? { interval } : {},
4507
5147
  ...values["lookup-key"] ? { lookup_key: values["lookup-key"] } : {}
@@ -4521,7 +5161,7 @@ ${link.url}`);
4521
5161
  for (const x of p.prices) {
4522
5162
  const every = x.interval ? ` / ${x.interval_count && x.interval_count > 1 ? `${x.interval_count} ` : ""}${x.interval}` : "";
4523
5163
  io.log(
4524
- ` ${x.id} ${cents2(x.unit_amount_cents)}${every}${x.lookup_key ? ` ${x.lookup_key}` : ""}${x.active ? "" : " (inactive)"}`
5164
+ ` ${x.id} ${money3(x.unit_amount_cents, x.currency)}${every}${x.lookup_key ? ` ${x.lookup_key}` : ""}${x.active ? "" : " (inactive)"}`
4525
5165
  );
4526
5166
  }
4527
5167
  }
@@ -4534,11 +5174,23 @@ ${link.url}`);
4534
5174
  "usage: vibiz payments checkout <price_id|lookup_key> --success-url <u> --cancel-url <u> [--user id]"
4535
5175
  );
4536
5176
  }
5177
+ const brand = Object.fromEntries(
5178
+ [
5179
+ ["name", values["brand-name"]],
5180
+ ["logo_url", values["brand-logo"]],
5181
+ ["icon_url", values["brand-icon"]],
5182
+ ["button_color", values["brand-color"]],
5183
+ ["background_color", values["brand-background"]],
5184
+ ["font", values["brand-font"]],
5185
+ ["border_style", values["brand-border"]]
5186
+ ].filter(([, v]) => v !== void 0)
5187
+ );
4537
5188
  const c = await vibiz2.projects.payments.checkout(
4538
5189
  id,
4539
5190
  {
4540
5191
  ...arg.startsWith("pprice_") ? { price_id: arg } : { lookup_key: arg },
4541
5192
  ...values.user ? { user: values.user } : {},
5193
+ ...Object.keys(brand).length ? { brand } : {},
4542
5194
  success_url: values["success-url"],
4543
5195
  cancel_url: values["cancel-url"]
4544
5196
  },
@@ -4555,7 +5207,7 @@ ${c.url}`));
4555
5207
  if (!list2.data.length) io.log("No payments yet.");
4556
5208
  for (const p of list2.data) {
4557
5209
  io.log(
4558
- `${p.created_at.slice(0, 10)} ${p.id} ${cents2(p.amount_cents).padStart(10)} net ${cents2(p.net_cents)} ${p.status}${p.customer_email ? ` ${p.customer_email}` : ""}`
5210
+ `${p.created_at.slice(0, 10)} ${p.id} ${money3(p.amount_cents, p.currency).padStart(10)} net ${p.account === "own" ? money3(p.net_cents, p.currency) : cents2(p.net_cents)} ${p.status}${p.customer_email ? ` ${p.customer_email}` : ""}`
4559
5211
  );
4560
5212
  }
4561
5213
  });
@@ -4651,8 +5303,13 @@ ${link.url}`
4651
5303
  out(a, () => printPayments(io, a));
4652
5304
  return;
4653
5305
  }
5306
+ if (sub === "use-account") {
5307
+ const a = await vibiz2.projects.payments.ownAccount.useAccount(id, env);
5308
+ out(a, () => printPayments(io, a));
5309
+ return;
5310
+ }
4654
5311
  throw new Error(
4655
- "usage: vibiz payments [products [add] | checkout <price> | list | webhook <url> | withdraw | simulate <event> | connect | disconnect]"
5312
+ "usage: vibiz payments [products [add] | checkout <price> | list | webhook <url> | withdraw | simulate <event> | connect | disconnect | use-account | account | app-store]"
4656
5313
  );
4657
5314
  }
4658
5315
  case "social": {
@@ -4676,6 +5333,29 @@ ${link.url}`
4676
5333
  if (typed.trim().toLowerCase() !== "yes")
4677
5334
  throw new Error("Not confirmed: nothing was sent.");
4678
5335
  };
5336
+ const mediaUrl = async (m) => {
5337
+ if (/^https?:\/\//.test(m)) return m;
5338
+ const bytes = new Uint8Array(await io.local().readFile(m));
5339
+ const ext = m.split(".").pop()?.toLowerCase() ?? "";
5340
+ const contentType = {
5341
+ jpg: "image/jpeg",
5342
+ jpeg: "image/jpeg",
5343
+ png: "image/png",
5344
+ webp: "image/webp",
5345
+ gif: "image/gif",
5346
+ mp4: "video/mp4",
5347
+ mov: "video/quicktime",
5348
+ webm: "video/webm",
5349
+ pdf: "application/pdf"
5350
+ }[ext];
5351
+ if (!contentType) throw new Error(`${m}: jpg, png, webp, gif, mp4, mov, webm or pdf`);
5352
+ const up = await vibiz2.projects.social.upload(
5353
+ id,
5354
+ { bytes, contentType, filename: m.split("/").pop() },
5355
+ env
5356
+ );
5357
+ return up.url;
5358
+ };
4679
5359
  if (!sub) {
4680
5360
  const o = await vibiz2.projects.social.get(id, env);
4681
5361
  out(o, () => {
@@ -4746,31 +5426,7 @@ ${link.url}`
4746
5426
  options[kv.slice(0, i)] = v === "true" ? true : v === "false" ? false : v;
4747
5427
  }
4748
5428
  const media = [];
4749
- for (const m of values.media ?? []) {
4750
- if (/^https?:\/\//.test(m)) media.push({ url: m });
4751
- else {
4752
- const bytes = new Uint8Array(await io.local().readFile(m));
4753
- const ext = m.split(".").pop()?.toLowerCase() ?? "";
4754
- const contentType = {
4755
- jpg: "image/jpeg",
4756
- jpeg: "image/jpeg",
4757
- png: "image/png",
4758
- webp: "image/webp",
4759
- gif: "image/gif",
4760
- mp4: "video/mp4",
4761
- mov: "video/quicktime",
4762
- webm: "video/webm",
4763
- pdf: "application/pdf"
4764
- }[ext];
4765
- if (!contentType) throw new Error(`${m}: jpg, png, webp, gif, mp4, mov, webm or pdf`);
4766
- const up = await vibiz2.projects.social.upload(
4767
- id,
4768
- { bytes, contentType, filename: m.split("/").pop() },
4769
- env
4770
- );
4771
- media.push({ url: up.url });
4772
- }
4773
- }
5429
+ for (const m of values.media ?? []) media.push({ url: await mediaUrl(m) });
4774
5430
  const input = {
4775
5431
  text: arg ?? "",
4776
5432
  media,
@@ -4818,15 +5474,51 @@ ${link.url}`
4818
5474
  showPost(p);
4819
5475
  return;
4820
5476
  }
5477
+ if (sub === "campaigns" && arg === "create") {
5478
+ const input = await campaignCreateInputFrom(
5479
+ values,
5480
+ vibiz2,
5481
+ id,
5482
+ env,
5483
+ mediaUrl,
5484
+ (f) => io.local().readFile(f, "utf8")
5485
+ );
5486
+ let ch;
5487
+ try {
5488
+ ch = await vibiz2.projects.social.createCampaign(id, input, env);
5489
+ } catch (e) {
5490
+ if (!(e instanceof VibizApiError) || e.details?.reason !== "confirmation_required")
5491
+ throw e;
5492
+ const google = (await vibiz2.projects.social.accounts(id, { env, kind: "ads" })).data.find(
5493
+ (a) => a.id === input.account_id
5494
+ );
5495
+ const currency = google?.details.ad_accounts?.find((a) => a.id === input.ad_account_id)?.currency ?? null;
5496
+ const money4 = formatMinor(input.daily_budget_cents, currency);
5497
+ await sure(
5498
+ `This creates the ${input.campaign_type} campaign "${input.name}" (${money4} a day) on the live Google Ads account, ${input.start === "active" ? "ACTIVE: it starts spending" : "paused: nothing is spent until you resume it"}.`
5499
+ );
5500
+ ch = await vibiz2.projects.social.createCampaign(id, { ...input, confirm: true }, env);
5501
+ }
5502
+ out(ch, () => {
5503
+ io.log(`${ch.id} create_campaign ${ch.status}`);
5504
+ if (ch.result?.campaign_id)
5505
+ io.log(
5506
+ ` campaign ${ch.result.campaign_id} (${input.start === "active" ? "active" : "paused"}): vibiz social resume ${ch.result.campaign_id} starts it`
5507
+ );
5508
+ if (ch.next_step) io.log(` ${ch.next_step}`);
5509
+ if (ch.error) io.log(` ${ch.error}`);
5510
+ });
5511
+ return;
5512
+ }
4821
5513
  if (sub === "campaigns") {
4822
5514
  const list2 = await vibiz2.projects.social.campaigns(id, { env });
4823
5515
  out(list2.data, () => {
4824
5516
  if (!list2.data.length)
4825
5517
  io.log("No campaigns (connect ads: vibiz social connect meta --ads).");
4826
5518
  for (const c of list2.data) {
4827
- const money2 = (v) => v === null ? "\u2013" : `${(v / 100).toFixed(2)} ${c.currency ?? ""}`.trim();
5519
+ const money4 = (v) => formatMinor(v, c.currency);
4828
5520
  io.log(
4829
- `${c.id} ${c.status.padEnd(14)} ${money2(c.daily_budget_cents)}/day spent ${money2(c.spend_cents)} ${c.name}`
5521
+ `${c.id} ${c.status.padEnd(14)} ${money4(c.daily_budget_cents)}/day spent ${money4(c.spend_cents)} ${c.name}`
4830
5522
  );
4831
5523
  }
4832
5524
  });
@@ -4855,7 +5547,7 @@ ${link.url}`
4855
5547
  if (!(e instanceof VibizApiError) || e.details?.reason !== "confirmation_required")
4856
5548
  throw e;
4857
5549
  await sure(
4858
- `This ${sub === "pause" ? "pauses" : sub === "resume" ? "resumes (spends money on)" : `sets ${budget} cents a day on`} the live campaign "${c.name}".`
5550
+ `This ${sub === "pause" ? "pauses" : sub === "resume" ? "resumes (spends money on)" : `sets ${formatMinor(budget, c.currency)} a day on`} the live campaign "${c.name}".`
4859
5551
  );
4860
5552
  ch = await vibiz2.projects.social.adChange(id, { ...input, confirm: true }, env);
4861
5553
  }
@@ -4867,7 +5559,7 @@ ${link.url}`
4867
5559
  return;
4868
5560
  }
4869
5561
  throw new Error(
4870
- "usage: vibiz social [connect|accounts|post|posts|approve|reject|cancel|campaigns|pause|resume|budget]"
5562
+ "usage: vibiz social [connect|accounts|post|posts|approve|reject|cancel|campaigns [create]|pause|resume|budget]"
4871
5563
  );
4872
5564
  }
4873
5565
  case "connectors": {
@@ -5247,6 +5939,19 @@ ${await oneKeyLines(vibiz2, id)}`);
5247
5939
  ...values.cursor ? { cursor: values.cursor } : {}
5248
5940
  });
5249
5941
  }
5942
+ // SEO data (docs: actions, seo.*): `vibiz seo <what> …`.
5943
+ case "seo":
5944
+ return seoCommand(io, positionals, {
5945
+ json: values.json,
5946
+ ...values.input ? { input: values.input } : {},
5947
+ ...values.location ? { location: values.location } : {},
5948
+ ...values.language ? { language: values.language } : {},
5949
+ ...values.limit ? { limit: values.limit } : {},
5950
+ ...values.depth ? { depth: values.depth } : {},
5951
+ ...values.device ? { device: values.device } : {},
5952
+ ...values.platform ? { platform: values.platform } : {},
5953
+ ...values.project ? { project: values.project } : {}
5954
+ });
5250
5955
  case "run": {
5251
5956
  if (!passthrough.length) {
5252
5957
  const action = positionals[0];
@@ -5441,6 +6146,10 @@ ${await oneKeyLines(vibiz2, id)}`);
5441
6146
  return;
5442
6147
  }
5443
6148
  case "replays": {
6149
+ if (positionals[0] === "frames") {
6150
+ await framesCommand(io, positionals[1], values);
6151
+ return;
6152
+ }
5444
6153
  const period = values.period ?? "7d";
5445
6154
  if (!["24h", "7d", "30d"].includes(period)) throw new Error("--period is 24h, 7d or 30d");
5446
6155
  const vibiz2 = await io.client();
@@ -5876,7 +6585,7 @@ Store the key now: it is not shown again.`
5876
6585
  return;
5877
6586
  }
5878
6587
  case "docs": {
5879
- const { DOC_TOPICS, DOCS } = await import("./src-HBX5XNYH.js");
6588
+ const { DOC_TOPICS, DOCS } = await import("./src-KEH4ULRK.js");
5880
6589
  const topic = positionals[0];
5881
6590
  if (!topic || !DOC_TOPICS.includes(topic)) {
5882
6591
  for (const t of DOC_TOPICS) io.log(` vibiz docs ${t.padEnd(13)} ${DOCS[t].title}`);
@@ -5901,7 +6610,7 @@ ${DOCS[topic].body}`);
5901
6610
  if (positionals[0])
5902
6611
  throw new Error('usage: vibiz mcp (serve over stdio) | vibiz mcp add --clients "<client>"');
5903
6612
  io.local();
5904
- const { serveStdio } = await import("./src-HBX5XNYH.js");
6613
+ const { serveStdio } = await import("./src-KEH4ULRK.js");
5905
6614
  await serveStdio({ version: cliVersion() });
5906
6615
  return;
5907
6616
  }