@purpleturret/cli 0.4.0 → 0.5.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,7 @@ 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
+ | `offers` | `{ [key]: { title, subtitle? } }` | Optional. A note shown under the price when the link carries `?offer=<key>`. |
100
101
 
101
102
  **Rules to know before you edit:**
102
103
 
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.5.0";
13
13
 
14
14
  // ../sdk/src/config/schema.ts
15
15
  import { z } from "zod";
@@ -78,7 +78,11 @@ 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()
82
86
  });
83
87
  var configSchema = z.strictObject({
84
88
  products: z.array(productInputSchema)
@@ -172,7 +176,8 @@ function toWireProduct(input) {
172
176
  slug: input.slug,
173
177
  stripe: input.stripe ? { price_id: input.stripe.priceId } : void 0,
174
178
  active: input.active,
175
- buyer_emails: input.buyerEmails
179
+ buyer_emails: input.buyerEmails,
180
+ offers: input.offers
176
181
  };
177
182
  return omitUndefined(wire);
178
183
  }
@@ -221,6 +226,7 @@ function fromWireProduct(wire) {
221
226
  stripe: wire.stripe ? fromWireStripe(wire.stripe) : void 0,
222
227
  active: wire.active,
223
228
  buyerEmails: wire.buyer_emails ?? void 0,
229
+ offers: wire.offers,
224
230
  bumps: wire.bumps ? camelizeKeys(wire.bumps) : void 0,
225
231
  upsell: wire.upsell === void 0 ? void 0 : wire.upsell && camelizeKeys(wire.upsell),
226
232
  pixelId: wire.pixel_id,
@@ -282,7 +288,8 @@ function productToInput(product3) {
282
288
  stripe: product3.stripe,
283
289
  active: product3.active,
284
290
  // The API always reports buyer_emails; only the opt-out is worth writing into a config.
285
- buyerEmails: product3.buyerEmails === false ? false : void 0
291
+ buyerEmails: product3.buyerEmails === false ? false : void 0,
292
+ offers: product3.offers && Object.keys(product3.offers).length > 0 ? product3.offers : void 0
286
293
  });
287
294
  }
288
295
  function fromWirePlanItem(item) {
@@ -645,7 +652,8 @@ function pagesApi(client) {
645
652
 
646
653
  // ../sdk/src/client/areas/tracking.ts
647
654
  function snakeKeys(value) {
648
- if (value && typeof value === "object" && !Array.isArray(value)) {
655
+ if (Array.isArray(value)) return value.map(snakeKeys);
656
+ if (value && typeof value === "object") {
649
657
  const out = {};
650
658
  for (const [key, entry] of Object.entries(value)) {
651
659
  out[key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`)] = snakeKeys(entry);
@@ -1093,7 +1101,7 @@ function stripUndefined(value) {
1093
1101
  import dotenv from "dotenv";
1094
1102
 
1095
1103
  // src/version.ts
1096
- var CLI_VERSION = "0.4.0";
1104
+ var CLI_VERSION = "0.5.0";
1097
1105
 
1098
1106
  // src/lib/credentials.ts
1099
1107
  import { chmod, mkdir, readFile, rename, writeFile } from "fs/promises";
@@ -2566,6 +2574,9 @@ function printTracking(ctx, tracking2) {
2566
2574
  return `${state}${id8 ? ` (${id8})` : ""}${section.hasConversionsApiToken ? ", CAPI token set" : ""}${events ? palette.dim(` events: ${events}`) : ""}`;
2567
2575
  };
2568
2576
  ctx.out.print(`${palette.dim("Meta")} ${describe(tracking2.meta, tracking2.meta.pixelId)}`);
2577
+ for (const p of tracking2.meta.paths ?? []) {
2578
+ ctx.out.print(`${palette.dim(" ")}${p.path} \u2192 ${p.pixelId}${p.hasConversionsApiToken ? ", CAPI token set" : ""}`);
2579
+ }
2569
2580
  ctx.out.print(`${palette.dim("GA ")} ${describe(tracking2.googleAnalytics, tracking2.googleAnalytics.measurementId)}`);
2570
2581
  }
2571
2582
  var metaArgs = {
@@ -2608,6 +2619,24 @@ var overrideArgs = {
2608
2619
  "meta-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a pixel id or token is given)" },
2609
2620
  "ga-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a measurement id is given)" }
2610
2621
  };
2622
+ var pageOverrideArgs = {
2623
+ ...overrideArgs,
2624
+ "meta-paths": {
2625
+ type: "string",
2626
+ description: 'Pages only: per-path pixels as "/path=PIXEL_ID[:CAPI_TOKEN],\u2026" ("" clears them; an omitted token keeps the stored one)'
2627
+ }
2628
+ };
2629
+ function parseMetaPaths(raw) {
2630
+ return raw.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
2631
+ const eq = part.indexOf("=");
2632
+ if (eq < 1) throw new Error(`--meta-paths entry "${part}" must look like /path=PIXEL_ID[:CAPI_TOKEN]`);
2633
+ const [pixelId2 = "", ...token2] = part.slice(eq + 1).split(":");
2634
+ return { path: part.slice(0, eq), pixelId: pixelId2, conversionsApiToken: token2.length > 0 ? token2.join(":") : void 0 };
2635
+ });
2636
+ }
2637
+ function currentMetaInput(current) {
2638
+ return { mode: current.mode, pixelId: current.pixelId ?? void 0, events: current.events };
2639
+ }
2611
2640
  function overrideInput(args) {
2612
2641
  const metaMode = args["meta-mode"] ?? (args["meta-pixel-id"] !== void 0 || args["meta-token"] !== void 0 ? "custom" : void 0);
2613
2642
  const gaMode = args["ga-mode"] ?? (args["ga-measurement-id"] !== void 0 ? "custom" : void 0);
@@ -2652,9 +2681,15 @@ var page = defineCommand9({
2652
2681
  }),
2653
2682
  set: defineCommand9({
2654
2683
  meta: { name: "set", description: "Set a hosted page's tracking override" },
2655
- args: overrideArgs,
2684
+ args: pageOverrideArgs,
2656
2685
  run: defineRun(async (ctx, args) => {
2657
- const result = await ctx.client().tracking.setPage(args.id, overrideInput(args));
2686
+ const input = overrideInput(args);
2687
+ const paths = args["meta-paths"] === void 0 ? void 0 : parseMetaPaths(args["meta-paths"]);
2688
+ let meta = input.meta;
2689
+ if (paths !== void 0) {
2690
+ meta = { ...meta ?? currentMetaInput((await ctx.client().tracking.getPage(args.id)).meta), paths };
2691
+ }
2692
+ const result = await ctx.client().tracking.setPage(args.id, { ...input, meta });
2658
2693
  ctx.json ? ctx.out.printJson(result) : printTracking(ctx, result);
2659
2694
  })
2660
2695
  })
@@ -3004,7 +3039,8 @@ var PRODUCT_KEY_ORDER = [
3004
3039
  "theme",
3005
3040
  "stripe",
3006
3041
  "active",
3007
- "buyerEmails"
3042
+ "buyerEmails",
3043
+ "offers"
3008
3044
  ];
3009
3045
  var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
3010
3046
  function renderConfigSource(products2, format = "ts") {
@@ -3885,7 +3921,13 @@ var productInput = z7.object({
3885
3921
  googleAnalytics: z7.object({ mode, measurementId, eventsMode, events: gaEvents }).optional()
3886
3922
  });
3887
3923
  var pageInput = z7.object({
3888
- meta: z7.object({ mode, pixelId, conversionsApiToken: token, events: z7.object({ lead: z7.boolean().optional() }).optional() }).optional(),
3924
+ meta: z7.object({
3925
+ mode,
3926
+ pixelId,
3927
+ conversionsApiToken: token,
3928
+ events: z7.object({ lead: z7.boolean().optional() }).optional(),
3929
+ 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.")
3930
+ }).optional(),
3889
3931
  googleAnalytics: z7.object({ mode, measurementId, events: z7.object({ generateLead: z7.boolean().optional() }).optional() }).optional()
3890
3932
  });
3891
3933
  function registerTrackingTools(tool, client) {