@purpleturret/cli 0.3.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.3.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) {
@@ -560,7 +567,9 @@ function pixelsApi(client) {
560
567
  query: { ...rangeQuery(options), conversion: options.conversion, attribution: options.attribution }
561
568
  })
562
569
  ),
563
- people: async (id8, range4 = {}) => camelizeKeys(await client.request("GET", `${p(id8)}/people`, { query: rangeQuery(range4) })),
570
+ people: async (id8, options = {}) => camelizeKeys(
571
+ await client.request("GET", `${p(id8)}/people`, { query: { ...rangeQuery(options), offset: options.offset, limit: options.limit } })
572
+ ),
564
573
  session: async (id8, sid) => fromWireTimeline(await client.request("GET", `${p(id8)}/sessions/${encodeURIComponent(sid)}`)),
565
574
  person: async (id8, sid, options = {}) => fromWireTimeline(
566
575
  await client.request("GET", `${p(id8)}/people/${encodeURIComponent(sid)}`, { query: { sids: options.sids?.join(",") } })
@@ -643,7 +652,8 @@ function pagesApi(client) {
643
652
 
644
653
  // ../sdk/src/client/areas/tracking.ts
645
654
  function snakeKeys(value) {
646
- if (value && typeof value === "object" && !Array.isArray(value)) {
655
+ if (Array.isArray(value)) return value.map(snakeKeys);
656
+ if (value && typeof value === "object") {
647
657
  const out = {};
648
658
  for (const [key, entry] of Object.entries(value)) {
649
659
  out[key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`)] = snakeKeys(entry);
@@ -1091,7 +1101,7 @@ function stripUndefined(value) {
1091
1101
  import dotenv from "dotenv";
1092
1102
 
1093
1103
  // src/version.ts
1094
- var CLI_VERSION = "0.3.0";
1104
+ var CLI_VERSION = "0.5.0";
1095
1105
 
1096
1106
  // src/lib/credentials.ts
1097
1107
  import { chmod, mkdir, readFile, rename, writeFile } from "fs/promises";
@@ -2293,9 +2303,19 @@ var ads = defineCommand7({
2293
2303
  });
2294
2304
  var people = defineCommand7({
2295
2305
  meta: { name: "people", description: "Identified visitors active in the range" },
2296
- args: { ...globalArgs, ...idArg, ...rangeArgs },
2306
+ args: {
2307
+ ...globalArgs,
2308
+ ...idArg,
2309
+ ...rangeArgs,
2310
+ offset: { type: "string", description: "People to skip (default 0)" },
2311
+ limit: { type: "string", description: "Page size, up to 100 (default 100)" }
2312
+ },
2297
2313
  run: defineRun(async (ctx, args) => {
2298
- const r = await ctx.client().pixels.people(args.id, range(args));
2314
+ const r = await ctx.client().pixels.people(args.id, {
2315
+ ...range(args),
2316
+ offset: args.offset ? Number(args.offset) : void 0,
2317
+ limit: args.limit ? Number(args.limit) : void 0
2318
+ });
2299
2319
  if (ctx.json) return ctx.out.printJson(r);
2300
2320
  printTable(
2301
2321
  ctx,
@@ -2554,6 +2574,9 @@ function printTracking(ctx, tracking2) {
2554
2574
  return `${state}${id8 ? ` (${id8})` : ""}${section.hasConversionsApiToken ? ", CAPI token set" : ""}${events ? palette.dim(` events: ${events}`) : ""}`;
2555
2575
  };
2556
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
+ }
2557
2580
  ctx.out.print(`${palette.dim("GA ")} ${describe(tracking2.googleAnalytics, tracking2.googleAnalytics.measurementId)}`);
2558
2581
  }
2559
2582
  var metaArgs = {
@@ -2596,6 +2619,24 @@ var overrideArgs = {
2596
2619
  "meta-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a pixel id or token is given)" },
2597
2620
  "ga-mode": { type: "string", description: "inherit | custom | disabled (defaults to custom when a measurement id is given)" }
2598
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
+ }
2599
2640
  function overrideInput(args) {
2600
2641
  const metaMode = args["meta-mode"] ?? (args["meta-pixel-id"] !== void 0 || args["meta-token"] !== void 0 ? "custom" : void 0);
2601
2642
  const gaMode = args["ga-mode"] ?? (args["ga-measurement-id"] !== void 0 ? "custom" : void 0);
@@ -2640,9 +2681,15 @@ var page = defineCommand9({
2640
2681
  }),
2641
2682
  set: defineCommand9({
2642
2683
  meta: { name: "set", description: "Set a hosted page's tracking override" },
2643
- args: overrideArgs,
2684
+ args: pageOverrideArgs,
2644
2685
  run: defineRun(async (ctx, args) => {
2645
- 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 });
2646
2693
  ctx.json ? ctx.out.printJson(result) : printTracking(ctx, result);
2647
2694
  })
2648
2695
  })
@@ -2992,7 +3039,8 @@ var PRODUCT_KEY_ORDER = [
2992
3039
  "theme",
2993
3040
  "stripe",
2994
3041
  "active",
2995
- "buyerEmails"
3042
+ "buyerEmails",
3043
+ "offers"
2996
3044
  ];
2997
3045
  var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
2998
3046
  function renderConfigSource(products2, format = "ts") {
@@ -3699,8 +3747,13 @@ function registerPixelsTools(tool, client) {
3699
3747
  );
3700
3748
  tool(
3701
3749
  "get_pixel_people",
3702
- "Identified visitors (by external id, email or cookie) active in the range, with spend and recent sessions.",
3703
- z5.object({ id: id5, ...range2 }),
3750
+ "Identified visitors (by external id, email or cookie) active in the range, with spend and recent sessions. Paged: total counts everyone, offset/limit pick the page.",
3751
+ z5.object({
3752
+ id: id5,
3753
+ ...range2,
3754
+ offset: z5.number().int().min(0).optional().describe("People to skip, most recently seen first"),
3755
+ limit: z5.number().int().min(1).max(100).optional().describe("Page size; default 100")
3756
+ }),
3704
3757
  READ,
3705
3758
  ({ id: id8, ...r }) => client.pixels.people(id8, r)
3706
3759
  );
@@ -3868,7 +3921,13 @@ var productInput = z7.object({
3868
3921
  googleAnalytics: z7.object({ mode, measurementId, eventsMode, events: gaEvents }).optional()
3869
3922
  });
3870
3923
  var pageInput = z7.object({
3871
- 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(),
3872
3931
  googleAnalytics: z7.object({ mode, measurementId, events: z7.object({ generateLead: z7.boolean().optional() }).optional() }).optional()
3873
3932
  });
3874
3933
  function registerTrackingTools(tool, client) {
@@ -3914,7 +3973,7 @@ function registerTrackingTools(tool, client) {
3914
3973
  import { z as z8 } from "zod";
3915
3974
  var id6 = z8.string().describe("Domain id");
3916
3975
  function registerDomainsTools(tool, client) {
3917
- tool("list_domains", "List the seller's custom domains (at most 5) with status and DNS records.", z8.object({}), READ, () => client.domains.list());
3976
+ tool("list_domains", "List the seller's custom domains with status and DNS records.", z8.object({}), READ, () => client.domains.list());
3918
3977
  tool(
3919
3978
  "get_domain",
3920
3979
  "Get one custom domain, including the DNS records the seller must create.",