@purpleturret/cli 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,6 +97,8 @@ The CLI finds `purpleturret.config.{ts,mts,js,mjs,json}` in the current director
97
97
  | `stripe` | `{ priceId }` | Optional. Adopt an existing Stripe price on create. Immutable. |
98
98
  | `active` | `boolean` | Optional. Inactive products stop accepting checkouts. |
99
99
  | `buyerEmails` | `boolean` | Optional. `false` turns off Purpleturret's receipt, delivery and refund emails. |
100
+ | `tabTitle` | `string` | Optional. The checkout page's browser tab title, in place of `<name> — Purpleturret`. |
101
+ | `offers` | `{ [key]: { title, subtitle? } }` | Optional. A note shown under the price when the link carries `?offer=<key>`. |
100
102
 
101
103
  **Rules to know before you edit:**
102
104
 
package/dist/cli.js CHANGED
@@ -9,7 +9,7 @@ import { existsSync } from "fs";
9
9
  import { join as join2 } from "path";
10
10
 
11
11
  // ../sdk/src/version.ts
12
- var SDK_VERSION = "0.4.0";
12
+ var SDK_VERSION = "0.6.0";
13
13
 
14
14
  // ../sdk/src/config/schema.ts
15
15
  import { z } from "zod";
@@ -78,7 +78,12 @@ var productInputSchema = z.strictObject({
78
78
  slug: z.string().regex(SLUG_PATTERN, "must be 3-64 characters of lowercase letters, digits, or '-'").optional(),
79
79
  stripe: stripeSchema.optional(),
80
80
  active: z.boolean().optional(),
81
- buyerEmails: z.boolean().optional()
81
+ buyerEmails: z.boolean().optional(),
82
+ offers: z.record(
83
+ z.string().regex(/^[a-z0-9-]{1,32}$/, "must be 1-32 characters of lowercase letters, digits, or '-'"),
84
+ z.strictObject({ title: z.string().trim().min(1, "must not be empty").max(120), subtitle: z.string().trim().max(120).optional() })
85
+ ).refine((offers) => Object.keys(offers).length <= 10, "must have 10 entries or fewer").optional(),
86
+ tabTitle: z.string().trim().max(80).optional()
82
87
  });
83
88
  var configSchema = z.strictObject({
84
89
  products: z.array(productInputSchema)
@@ -172,7 +177,9 @@ function toWireProduct(input) {
172
177
  slug: input.slug,
173
178
  stripe: input.stripe ? { price_id: input.stripe.priceId } : void 0,
174
179
  active: input.active,
175
- buyer_emails: input.buyerEmails
180
+ buyer_emails: input.buyerEmails,
181
+ offers: input.offers,
182
+ tab_title: input.tabTitle
176
183
  };
177
184
  return omitUndefined(wire);
178
185
  }
@@ -221,6 +228,8 @@ function fromWireProduct(wire) {
221
228
  stripe: wire.stripe ? fromWireStripe(wire.stripe) : void 0,
222
229
  active: wire.active,
223
230
  buyerEmails: wire.buyer_emails ?? void 0,
231
+ offers: wire.offers,
232
+ tabTitle: wire.tab_title ?? void 0,
224
233
  bumps: wire.bumps ? camelizeKeys(wire.bumps) : void 0,
225
234
  upsell: wire.upsell === void 0 ? void 0 : wire.upsell && camelizeKeys(wire.upsell),
226
235
  pixelId: wire.pixel_id,
@@ -282,7 +291,9 @@ function productToInput(product3) {
282
291
  stripe: product3.stripe,
283
292
  active: product3.active,
284
293
  // The API always reports buyer_emails; only the opt-out is worth writing into a config.
285
- buyerEmails: product3.buyerEmails === false ? false : void 0
294
+ buyerEmails: product3.buyerEmails === false ? false : void 0,
295
+ offers: product3.offers && Object.keys(product3.offers).length > 0 ? product3.offers : void 0,
296
+ tabTitle: product3.tabTitle || void 0
286
297
  });
287
298
  }
288
299
  function fromWirePlanItem(item) {
@@ -645,7 +656,8 @@ function pagesApi(client) {
645
656
 
646
657
  // ../sdk/src/client/areas/tracking.ts
647
658
  function snakeKeys(value) {
648
- if (value && typeof value === "object" && !Array.isArray(value)) {
659
+ if (Array.isArray(value)) return value.map(snakeKeys);
660
+ if (value && typeof value === "object") {
649
661
  const out = {};
650
662
  for (const [key, entry] of Object.entries(value)) {
651
663
  out[key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`)] = snakeKeys(entry);
@@ -1093,7 +1105,7 @@ function stripUndefined(value) {
1093
1105
  import dotenv from "dotenv";
1094
1106
 
1095
1107
  // src/version.ts
1096
- var CLI_VERSION = "0.4.0";
1108
+ var CLI_VERSION = "0.6.0";
1097
1109
 
1098
1110
  // src/lib/credentials.ts
1099
1111
  import { chmod, mkdir, readFile, rename, writeFile } from "fs/promises";
@@ -2566,6 +2578,9 @@ function printTracking(ctx, tracking2) {
2566
2578
  return `${state}${id8 ? ` (${id8})` : ""}${section.hasConversionsApiToken ? ", CAPI token set" : ""}${events ? palette.dim(` events: ${events}`) : ""}`;
2567
2579
  };
2568
2580
  ctx.out.print(`${palette.dim("Meta")} ${describe(tracking2.meta, tracking2.meta.pixelId)}`);
2581
+ for (const p of tracking2.meta.paths ?? []) {
2582
+ ctx.out.print(`${palette.dim(" ")}${p.path} \u2192 ${p.pixelId}${p.hasConversionsApiToken ? ", CAPI token set" : ""}`);
2583
+ }
2569
2584
  ctx.out.print(`${palette.dim("GA ")} ${describe(tracking2.googleAnalytics, tracking2.googleAnalytics.measurementId)}`);
2570
2585
  }
2571
2586
  var metaArgs = {
@@ -2608,6 +2623,24 @@ var overrideArgs = {
2608
2623
  "meta-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a pixel id or token is given)" },
2609
2624
  "ga-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a measurement id is given)" }
2610
2625
  };
2626
+ var pageOverrideArgs = {
2627
+ ...overrideArgs,
2628
+ "meta-paths": {
2629
+ type: "string",
2630
+ description: 'Pages only: per-path pixels as "/path=PIXEL_ID[:CAPI_TOKEN],\u2026" ("" clears them; an omitted token keeps the stored one)'
2631
+ }
2632
+ };
2633
+ function parseMetaPaths(raw) {
2634
+ return raw.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
2635
+ const eq = part.indexOf("=");
2636
+ if (eq < 1) throw new Error(`--meta-paths entry "${part}" must look like /path=PIXEL_ID[:CAPI_TOKEN]`);
2637
+ const [pixelId2 = "", ...token2] = part.slice(eq + 1).split(":");
2638
+ return { path: part.slice(0, eq), pixelId: pixelId2, conversionsApiToken: token2.length > 0 ? token2.join(":") : void 0 };
2639
+ });
2640
+ }
2641
+ function currentMetaInput(current) {
2642
+ return { mode: current.mode, pixelId: current.pixelId ?? void 0, events: current.events };
2643
+ }
2611
2644
  function overrideInput(args) {
2612
2645
  const metaMode = args["meta-mode"] ?? (args["meta-pixel-id"] !== void 0 || args["meta-token"] !== void 0 ? "custom" : void 0);
2613
2646
  const gaMode = args["ga-mode"] ?? (args["ga-measurement-id"] !== void 0 ? "custom" : void 0);
@@ -2652,9 +2685,15 @@ var page = defineCommand9({
2652
2685
  }),
2653
2686
  set: defineCommand9({
2654
2687
  meta: { name: "set", description: "Set a hosted page's tracking override" },
2655
- args: overrideArgs,
2688
+ args: pageOverrideArgs,
2656
2689
  run: defineRun(async (ctx, args) => {
2657
- const result = await ctx.client().tracking.setPage(args.id, overrideInput(args));
2690
+ const input = overrideInput(args);
2691
+ const paths = args["meta-paths"] === void 0 ? void 0 : parseMetaPaths(args["meta-paths"]);
2692
+ let meta = input.meta;
2693
+ if (paths !== void 0) {
2694
+ meta = { ...meta ?? currentMetaInput((await ctx.client().tracking.getPage(args.id)).meta), paths };
2695
+ }
2696
+ const result = await ctx.client().tracking.setPage(args.id, { ...input, meta });
2658
2697
  ctx.json ? ctx.out.printJson(result) : printTracking(ctx, result);
2659
2698
  })
2660
2699
  })
@@ -3004,7 +3043,9 @@ var PRODUCT_KEY_ORDER = [
3004
3043
  "theme",
3005
3044
  "stripe",
3006
3045
  "active",
3007
- "buyerEmails"
3046
+ "buyerEmails",
3047
+ "offers",
3048
+ "tabTitle"
3008
3049
  ];
3009
3050
  var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
3010
3051
  function renderConfigSource(products2, format = "ts") {
@@ -3885,7 +3926,13 @@ var productInput = z7.object({
3885
3926
  googleAnalytics: z7.object({ mode, measurementId, eventsMode, events: gaEvents }).optional()
3886
3927
  });
3887
3928
  var pageInput = z7.object({
3888
- meta: z7.object({ mode, pixelId, conversionsApiToken: token, events: z7.object({ lead: z7.boolean().optional() }).optional() }).optional(),
3929
+ meta: z7.object({
3930
+ mode,
3931
+ pixelId,
3932
+ conversionsApiToken: token,
3933
+ events: z7.object({ lead: z7.boolean().optional() }).optional(),
3934
+ paths: z7.array(z7.object({ path: z7.string(), pixelId: z7.string(), conversionsApiToken: z7.string().optional() })).optional().describe("A different Meta pixel + token for URLs under a path prefix (e.g. /ad1). Omit to keep stored overrides; [] clears them.")
3935
+ }).optional(),
3889
3936
  googleAnalytics: z7.object({ mode, measurementId, events: z7.object({ generateLead: z7.boolean().optional() }).optional() }).optional()
3890
3937
  });
3891
3938
  function registerTrackingTools(tool, client) {