@rebuy/rebuy 3.35.0 → 3.36.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.
Files changed (31) hide show
  1. package/dist/index.cjs +689 -571
  2. package/dist/index.mjs +689 -571
  3. package/dist/schema/index.d.ts +3 -0
  4. package/dist/schema/postPurchaseGroup.d.ts +15 -0
  5. package/dist/schema/postPurchaseProduct.d.ts +74 -24
  6. package/dist/schema/postPurchaseProductCalculation.d.ts +87 -0
  7. package/dist/schema/postPurchaseProductCollectionView.d.ts +724 -3
  8. package/dist/schema/postPurchaseProductDisplay.d.ts +41 -12
  9. package/dist/schema/postPurchaseProductView.d.ts +708 -0
  10. package/dist/schema/postPurchaseQuantity.d.ts +16 -3
  11. package/dist/schema/postPurchaseSubscriptionProduct.d.ts +74 -17
  12. package/dist/server/__fixtures__/postPurchaseGroup.d.ts +3 -0
  13. package/dist/server/index.cjs +818 -310
  14. package/dist/server/index.d.ts +13 -2
  15. package/dist/server/index.mjs +818 -310
  16. package/dist/server/postPurchaseProductDisplay.d.ts +38 -6
  17. package/dist/server/preparePostPurchaseAdmissionView.d.ts +418 -0
  18. package/dist/server/preparePostPurchaseCollectionGroup.d.ts +458 -0
  19. package/dist/server/preparePostPurchaseCollectionView.d.ts +442 -0
  20. package/dist/server/preparePostPurchaseGroupAdmissionView.d.ts +459 -0
  21. package/dist/server/preparePostPurchaseGroupDefault.d.ts +459 -0
  22. package/dist/server/preparePostPurchaseGroupView.d.ts +458 -0
  23. package/dist/server/preparePostPurchaseMemberView.d.ts +1466 -0
  24. package/dist/server/preparePostPurchaseProduct.d.ts +11 -0
  25. package/dist/server/preparePostPurchaseQuantityAdmissionView.d.ts +440 -0
  26. package/dist/server/preparePostPurchaseQuantityView.d.ts +427 -0
  27. package/dist/server/preparePostPurchaseSubscription.d.ts +37 -5
  28. package/dist/server/preparePostPurchaseView.d.ts +8 -0
  29. package/dist/server/projectPostPurchaseProduct.d.ts +37 -5
  30. package/dist/transforms/postPurchase/convertDescriptionRte.d.ts +11 -0
  31. package/package.json +1 -1
@@ -2119,7 +2119,7 @@ var stripContentBlockHtml = (text2) => text2.replace(HTML_COMMENT_RE, "").replac
2119
2119
  var convertTextToTiptapParagraph = ({
2120
2120
  color,
2121
2121
  fontSize,
2122
- marks = [],
2122
+ marks: marks2 = [],
2123
2123
  text: text2,
2124
2124
  textAlign
2125
2125
  }) => {
@@ -2128,7 +2128,7 @@ var convertTextToTiptapParagraph = ({
2128
2128
  attrs: { textAlign },
2129
2129
  content: sanitizedText ? [
2130
2130
  {
2131
- marks: [{ attrs: { color, fontSize }, type: "textStyle" }, ...marks],
2131
+ marks: [{ attrs: { color, fontSize }, type: "textStyle" }, ...marks2],
2132
2132
  text: sanitizedText,
2133
2133
  type: "text"
2134
2134
  }
@@ -2585,11 +2585,11 @@ var pushText = (state, rawText) => {
2585
2585
  decodeTextEntities(rawText).split("\n").forEach((segment, index) => {
2586
2586
  if (index > 0) flushParagraph(state);
2587
2587
  if (!segment) return;
2588
- const marks = state.stack.flatMap((entry) => entry.marks);
2589
- if (state.defaultTextStyleMark && !marks.some((mark) => mark.type === "textStyle")) {
2590
- marks.push(state.defaultTextStyleMark);
2588
+ const marks2 = state.stack.flatMap((entry) => entry.marks);
2589
+ if (state.defaultTextStyleMark && !marks2.some((mark) => mark.type === "textStyle")) {
2590
+ marks2.push(state.defaultTextStyleMark);
2591
2591
  }
2592
- state.currentRuns.push(TiptapText.parse(marks.length > 0 ? { marks, text: segment } : { text: segment }));
2592
+ state.currentRuns.push(TiptapText.parse(marks2.length > 0 ? { marks: marks2, text: segment } : { text: segment }));
2593
2593
  });
2594
2594
  };
2595
2595
 
@@ -3164,10 +3164,10 @@ var SWITCH_LABEL_TOKENS2 = ["subscriptionDiscount", "frequency", "interval"];
3164
3164
  var QUANTITY_ERROR_TOKENS = ["max", "min", "step"];
3165
3165
  var VARIANT_SELECTOR = { button: "button", radio: "radio", select: "menu" };
3166
3166
  var buildStyledText = (token, style, fontSize = style?.textSize ?? "base") => {
3167
- const marks = [{ attrs: { color: "base", fontSize }, type: "textStyle" }];
3168
- if (style?.textEmphasis === "bold") marks.push({ type: "bold" });
3169
- if (style?.textEmphasis === "italic") marks.push({ type: "italic" });
3170
- return { content: [{ content: [{ marks, text: token, type: "text" }], type: "paragraph" }], type: "doc" };
3167
+ const marks2 = [{ attrs: { color: "base", fontSize }, type: "textStyle" }];
3168
+ if (style?.textEmphasis === "bold") marks2.push({ type: "bold" });
3169
+ if (style?.textEmphasis === "italic") marks2.push({ type: "italic" });
3170
+ return { content: [{ content: [{ marks: marks2, text: token, type: "text" }], type: "paragraph" }], type: "doc" };
3171
3171
  };
3172
3172
  var buildPriceContent = () => ({
3173
3173
  content: [
@@ -5917,14 +5917,10 @@ var PostPurchasePrimaryImageSource = z51.string().default(
5917
5917
  "https://cdn.shopify.com/shopifycloud/shopify/assets/no-image-2048-5e88c1b20e087fb7bbe9a3771824e743c244f437e4f8ba93bbf7b11b53f7824c.gif"
5918
5918
  );
5919
5919
  var PostPurchaseProductDisplay = z51.object({
5920
+ descriptionDocument: TiptapDocument.optional(),
5920
5921
  discountedFrom: PostPurchaseSettings.shape.discountedFrom,
5921
5922
  gallery: PostPurchaseProductGallery.optional(),
5922
- language: language.pick({
5923
- description: true,
5924
- descriptionEnabled: true,
5925
- descriptionRte: true,
5926
- descriptionSpacing: true
5927
- }),
5923
+ language: language.pick({ description: true, descriptionEnabled: true }),
5928
5924
  primaryImage: z51.object({ description: z51.string(), source: z51.string() }),
5929
5925
  productOptions: PostPurchaseSettings.shape.productOptions.pick({
5930
5926
  showDeclineAll: true,
@@ -6042,7 +6038,7 @@ var subscriptionUnavailable = (normalized, plan, allowCollection, quantity2) =>
6042
6038
  };
6043
6039
 
6044
6040
  // src/server/postPurchaseProductDisplay.ts
6045
- import { z as z55 } from "zod";
6041
+ import { z as z56 } from "zod";
6046
6042
 
6047
6043
  // src/server/postPurchasePrimaryImage.ts
6048
6044
  var postPurchasePrimaryImage = (product) => {
@@ -6063,9 +6059,67 @@ var postPurchaseProductGallery = (product, limit) => ({
6063
6059
  selectedImageId: product.images?.find((image) => image.id === product.variants[0].imageId)?.id
6064
6060
  });
6065
6061
 
6062
+ // src/transforms/postPurchase/convertDescriptionRte.ts
6063
+ import { z as z55 } from "zod";
6064
+ var alignments = { center: "center", left: "start", right: "end" };
6065
+ var colors = ["critical", "subdued", "success", "warning"];
6066
+ var sizes2 = ["extraSmall", "small", "medium", "large", "extraLarge"];
6067
+ var spacings2 = {
6068
+ default: "base",
6069
+ loose: "loose",
6070
+ none: "none",
6071
+ tight: "tight",
6072
+ xloose: "extraLoose",
6073
+ xtight: "extraTight"
6074
+ };
6075
+ var Block = z55.object({
6076
+ attrs: z55.object({ alignment: z55.enum(["left", "center", "right"]).optional().catch(void 0) }).catch({}),
6077
+ content: z55.array(z55.unknown()).catch([]),
6078
+ type: z55.literal("ShopifyTextBlock")
6079
+ });
6080
+ var Run = z55.object({ marks: z55.array(z55.unknown()).catch([]), text: z55.string().min(1), type: z55.literal("text") });
6081
+ var Inline = z55.object({
6082
+ attrs: z55.object({
6083
+ color: z55.enum(colors).optional().catch(void 0),
6084
+ emphasis: z55.array(z55.unknown()).catch([]),
6085
+ size: z55.enum(sizes2).optional().catch(void 0)
6086
+ }),
6087
+ type: z55.literal("ShopifyTextInline")
6088
+ });
6089
+ var marks = (raw) => {
6090
+ const found = raw.map((mark) => Inline.safeParse(mark)).find(({ success }) => success)?.data;
6091
+ if (!found) return [];
6092
+ const { color = "base", emphasis, size = "base" } = found.attrs;
6093
+ return [
6094
+ ...emphasis.includes("bold") ? [{ type: "bold" }] : [],
6095
+ ...emphasis.includes("strikethrough") ? [{ type: "strike" }] : [],
6096
+ { attrs: { color, fontSize: size }, type: "textStyle" }
6097
+ ];
6098
+ };
6099
+ var convertDescriptionRte = (rte, spacing) => TiptapDocument.parse({
6100
+ attrs: { blockSpacing: spacings2[spacing ?? "none"] },
6101
+ content: rte.content.flatMap((node) => {
6102
+ const block = Block.safeParse(node);
6103
+ if (!block.success) return [];
6104
+ const { alignment } = block.data.attrs;
6105
+ return [
6106
+ {
6107
+ attrs: { textAlign: alignment ? alignments[alignment] : "start" },
6108
+ content: block.data.content.flatMap((inline) => {
6109
+ const run = Run.safeParse(inline);
6110
+ return run.success ? [{ marks: marks(run.data.marks), text: run.data.text }] : [];
6111
+ }),
6112
+ type: "paragraph"
6113
+ }
6114
+ ];
6115
+ }),
6116
+ type: "doc"
6117
+ });
6118
+
6066
6119
  // src/server/postPurchaseProductDisplay.ts
6067
- var ResponseLanguage = z55.object({ description: PostPurchaseProductDisplay.shape.responseDescription }).default({ description: "" });
6120
+ var ResponseLanguage = z56.object({ description: PostPurchaseProductDisplay.shape.responseDescription }).default({ description: "" });
6068
6121
  var projectPostPurchaseProductDisplay = (effective, metadata, product) => PostPurchaseProductDisplay.parse({
6122
+ descriptionDocument: effective.language.descriptionRte && convertDescriptionRte(effective.language.descriptionRte, effective.language.descriptionSpacing),
6069
6123
  discountedFrom: effective.discountedFrom,
6070
6124
  gallery: postPurchaseProductGallery(product, effective.subImages),
6071
6125
  language: effective.language,
@@ -6134,72 +6188,262 @@ var preparePostPurchaseSubscription = (settings, response, report) => {
6134
6188
  );
6135
6189
  };
6136
6190
 
6137
- // src/schema/postPurchaseOfferEligibility.ts
6138
- import { z as z57 } from "zod";
6191
+ // src/server/postPurchaseProductEligibility.ts
6192
+ var oneTimeUnavailable = (normalized, allowCollection, quantity2) => {
6193
+ const { data, effective, original } = normalized;
6194
+ if (data.length !== 1 || data[0].variants.length !== 1) return "Only one fixed product and variant are supported";
6195
+ if (effective.productType === "subscription" || [original, effective].some(
6196
+ (config) => !allowCollection && config.productLimit !== 1 || config.upgradeToSubscription.allow || !quantity2 && config.quantityInputs.enabled && (config.quantityInputs.minValue !== config.quantityInputs.maxValue || config.quantityInputs.defaultQuantity !== config.quantityInputs.minValue)
6197
+ ))
6198
+ return "Only fixed one-time configuration is supported";
6199
+ const product = data[0];
6200
+ const variant2 = product.variants[0];
6201
+ if (product.productGroupVariants.length || product.sellingPlanGroups?.some((group) => group.requiresSellingPlan) || !postPurchaseVariantAvailable(variant2))
6202
+ return "An available one-time variant without product groups is required";
6203
+ if (variant2.productId !== product.id) throw new Error("Product variant identity mismatch");
6204
+ };
6139
6205
 
6140
- // src/schema/postPurchaseProductCollectionView.ts
6141
- import { z as z56 } from "zod";
6142
- var PostPurchaseExcludedProductIds = z56.array(PostPurchaseProductId).default([]);
6206
+ // src/server/preparePostPurchaseProduct.ts
6207
+ var prepareNormalizedProduct = (normalized, report, quantity2, allowCollection = false) => {
6208
+ const reason = oneTimeUnavailable(normalized, allowCollection, quantity2);
6209
+ if (reason) return { reason, status: "unsupported" };
6210
+ const { effective } = normalized;
6211
+ return PreparedPostPurchaseProduct.parse({
6212
+ ...projectPostPurchaseProduct(normalized, quantity2),
6213
+ status: "prepared",
6214
+ terms: {
6215
+ discount: { ...effective.discount, title: effective.language.global.save },
6216
+ shipping: effective.shipping
6217
+ }
6218
+ });
6219
+ };
6220
+ var preparePostPurchaseProduct = (settings, response, report) => prepareNormalizedProduct(normalizePostPurchaseProduct(settings, response), report);
6143
6221
 
6144
- // src/schema/postPurchaseOfferEligibility.ts
6145
- var selection = PreparedPostPurchaseProduct.shape.selection;
6146
- var PostPurchaseOfferSkipReason = z57.enum(["empty", "no-eligible-subscription"]);
6147
- var PostPurchaseOfferEligibilityContext = z57.object({
6148
- excludedProductIds: PostPurchaseExcludedProductIds,
6149
- originalLineItems: z57.array(selection.pick({ productId: true, sellingPlanId: true, variantId: true }))
6150
- });
6151
- var PostPurchaseOfferEligibility = z57.discriminatedUnion("status", [
6152
- z57.object({
6153
- members: z57.array(
6154
- z57.object({ productId: selection.shape.productId, productIndex: z57.number().int().nonnegative() })
6155
- ),
6156
- status: z57.literal("retain")
6157
- }),
6158
- z57.object({ reason: PostPurchaseOfferSkipReason, status: z57.literal("skip") }),
6159
- z57.object({ reason: z57.literal("eligible-upgrade").optional(), status: z57.literal("unavailable") })
6222
+ // src/schema/postPurchaseProductView.ts
6223
+ import { z as z60 } from "zod";
6224
+
6225
+ // src/schema/postPurchaseChoice.ts
6226
+ import { z as z57 } from "zod";
6227
+ var PostPurchaseChoice = z57.discriminatedUnion("mode", [
6228
+ z57.object({ mode: z57.literal("one-time") }).strict(),
6229
+ z57.object({ mode: z57.literal("subscription"), sellingPlanId: PostPurchasePlanOption.shape.id }).strict()
6160
6230
  ]);
6231
+ var PostPurchaseOptions = z57.object({
6232
+ defaultChoice: PostPurchaseChoice,
6233
+ modes: z57.array(z57.enum(["one-time", "subscription"])).min(1).max(2),
6234
+ selector: PostPurchaseSettings.shape.productTypeSelector
6235
+ });
6161
6236
 
6162
- // src/server/normalizePostPurchaseCollection.ts
6163
- import { z as z58 } from "zod";
6164
- var normalizePostPurchaseCollection = (settings, response, excludedProductIds) => {
6165
- const normalized = normalizePostPurchaseProduct(settings, response);
6166
- const limit = z58.number().int().positive();
6167
- limit.parse(normalized.original.productLimit);
6168
- const prefix = normalized.data.slice(0, limit.parse(normalized.effective.productLimit));
6169
- if (new Set(prefix.map(({ id }) => id)).size !== prefix.length)
6170
- throw new Error("Ambiguous post-purchase collection");
6171
- const excluded = new Set(PostPurchaseExcludedProductIds.parse(excludedProductIds));
6172
- const members = prefix.map((product, productIndex) => ({ product, productIndex })).filter(({ product }) => !excluded.has(product.id));
6173
- return { members, normalized };
6174
- };
6237
+ // src/schema/postPurchaseGroupCatalog.ts
6238
+ import { z as z59 } from "zod";
6175
6239
 
6176
6240
  // src/schema/postPurchaseVariantCatalog.ts
6177
- import { z as z59 } from "zod";
6178
- var PostPurchaseVariantSelector = z59.object({ variantId: PostPurchaseVariantId }).strict();
6241
+ import { z as z58 } from "zod";
6242
+ var PostPurchaseVariantSelector = z58.object({ variantId: PostPurchaseVariantId }).strict();
6179
6243
  var PostPurchaseVariantOption = OfferProduct.shape.options.element.extend({
6180
- id: z59.number().int().positive(),
6181
- position: z59.number().int().min(1).max(3)
6244
+ id: z58.number().int().positive(),
6245
+ position: z58.number().int().min(1).max(3)
6182
6246
  });
6183
6247
  var PostPurchaseVariantValues = OfferProduct.shape.variants.element.pick({
6184
6248
  option1: true,
6185
6249
  option2: true,
6186
6250
  option3: true
6187
6251
  });
6188
- var PostPurchaseVariantCatalog = z59.object({
6252
+ var PostPurchaseVariantCatalog = z58.object({
6189
6253
  displayMode: PostPurchaseSettings.shape.productOptions.shape.variantSelectorDisplayMode,
6190
- options: z59.array(PostPurchaseVariantOption),
6254
+ options: z58.array(PostPurchaseVariantOption),
6191
6255
  productId: PostPurchaseProductId,
6192
6256
  showSelectors: PostPurchaseSettings.shape.productOptions.shape.showVariantSelectors,
6193
- variants: z59.array(
6257
+ variants: z58.array(
6194
6258
  PostPurchaseVariantValues.partial().extend({
6195
- available: z59.boolean(),
6259
+ available: z58.boolean(),
6196
6260
  id: PostPurchaseVariantId,
6197
- imageId: z59.number().int().nonnegative().nullish(),
6261
+ imageId: z58.number().int().nonnegative().nullish(),
6198
6262
  title: OfferProduct.shape.variants.element.shape.title
6199
6263
  })
6200
6264
  )
6201
6265
  });
6202
6266
 
6267
+ // src/schema/postPurchaseGroupCatalog.ts
6268
+ var productId = PreparedPostPurchaseProduct.shape.selection.shape.productId;
6269
+ var source = PostPurchaseProductSource.shape.data.element;
6270
+ var PostPurchaseGroupDescription = source.pick({ description: true, id: true, image: true, images: true, title: true }).extend({
6271
+ description: source.shape.description.default(null),
6272
+ image: source.shape.image.default(null),
6273
+ options: PostPurchaseVariantCatalog.shape.options.default([])
6274
+ });
6275
+ var PostPurchaseGroupCatalog = z59.object({
6276
+ memberProductId: productId,
6277
+ options: z59.array(z59.object({ productId, title: z59.string(), variantCatalog: PostPurchaseVariantCatalog }))
6278
+ });
6279
+ var PostPurchaseGroupSelection = z59.object({
6280
+ memberProductId: productId,
6281
+ productId
6282
+ });
6283
+
6284
+ // src/schema/postPurchaseProductView.ts
6285
+ var PostPurchaseProductView = z60.union([
6286
+ z60.object({
6287
+ groupCatalog: PostPurchaseGroupCatalog.optional(),
6288
+ initialVariant: PostPurchaseVariantSelector.optional(),
6289
+ planCatalog: PostPurchasePlanCatalog.nullable().optional(),
6290
+ preparation: PreparedPostPurchaseProduct.extend({
6291
+ display: PreparedPostPurchaseProduct.shape.display.extend({ description: z60.string().nullable() }).refine(
6292
+ ({ description, descriptionDocument }) => description === null === (descriptionDocument !== void 0),
6293
+ "Exactly one of the plain and rich descriptions is shown"
6294
+ )
6295
+ }),
6296
+ purchaseOptions: PostPurchaseOptions.optional(),
6297
+ sections: CABRootSection,
6298
+ variantCatalog: PostPurchaseVariantCatalog.optional()
6299
+ }),
6300
+ z60.object({
6301
+ groupCatalog: PostPurchaseGroupCatalog.optional(),
6302
+ initialVariant: PostPurchaseVariantSelector.optional(),
6303
+ planCatalog: PostPurchasePlanCatalog.nullable().optional(),
6304
+ preparation: PostPurchasePreparation.options[1],
6305
+ purchaseOptions: PostPurchaseOptions.optional(),
6306
+ sections: z60.null(),
6307
+ variantCatalog: PostPurchaseVariantCatalog.optional()
6308
+ })
6309
+ ]);
6310
+
6311
+ // src/server/postPurchaseOfferCopy.ts
6312
+ import { z as z61 } from "zod";
6313
+ var Copy = z61.object({
6314
+ superTitle: CalloutBannerBlock.shape.settings.shape.superTitle.unwrap().optional().catch(void 0),
6315
+ title: CalloutBannerBlock.shape.settings.shape.title.unwrap().optional().catch(void 0)
6316
+ });
6317
+ var Callout = z61.object({ settings: z61.record(z61.string(), z61.unknown()), type: z61.literal("callout_banner") });
6318
+ var postPurchaseOfferCopy = (blocks, metadata) => {
6319
+ const copy = Copy.safeParse(metadata.widget.language);
6320
+ if (!blocks || !copy.success) return blocks;
6321
+ const first = blocks.findIndex((block) => Callout.pick({ type: true }).safeParse(block).success);
6322
+ return blocks.map((block, index) => {
6323
+ if (index !== first) return block;
6324
+ const callout = Callout.passthrough().safeParse(block);
6325
+ if (!callout.success) return block;
6326
+ return {
6327
+ ...callout.data,
6328
+ settings: {
6329
+ ...callout.data.settings,
6330
+ ...copy.data.title && { title: copy.data.title },
6331
+ ...copy.data.superTitle && { superTitle: copy.data.superTitle }
6332
+ }
6333
+ };
6334
+ });
6335
+ };
6336
+
6337
+ // src/server/selectPostPurchaseChoice.ts
6338
+ var selectPostPurchaseChoice = (normalized, projected, requested, allowCollection, quantity2) => {
6339
+ const { data, effective } = normalized;
6340
+ const modes = [];
6341
+ const catalog = projected && projected.productId === data[0]?.id && projected.variantId === data[0].variants[0]?.id ? projected : null;
6342
+ const firstPlan = catalog?.plans[0];
6343
+ const oneTimeReason = oneTimeUnavailable(normalized, allowCollection, quantity2);
6344
+ const subscriptionReason = subscriptionUnavailable(normalized, firstPlan, allowCollection, quantity2);
6345
+ if (!oneTimeReason) modes.push("one-time");
6346
+ if (!subscriptionReason) modes.push("subscription");
6347
+ if (oneTimeReason && subscriptionReason)
6348
+ return {
6349
+ choice: void 0,
6350
+ options: void 0,
6351
+ plan: void 0,
6352
+ reason: effective.productType === "one-time" ? oneTimeReason : subscriptionReason
6353
+ };
6354
+ const defaultChoice = firstPlan && modes.includes("subscription") && (modes[0] === "subscription" || effective.subscriptionIsDefault) ? { mode: "subscription", sellingPlanId: firstPlan.id } : { mode: "one-time" };
6355
+ const options2 = PostPurchaseOptions.parse({ defaultChoice, modes, selector: effective.productTypeSelector });
6356
+ const choice = requested ?? defaultChoice;
6357
+ const plan = choice.mode === "subscription" ? catalog?.plans.find(({ id }) => id === choice.sellingPlanId) : void 0;
6358
+ const bound = modes.includes(choice.mode) && (choice.mode === "one-time" || plan) ? choice : void 0;
6359
+ return {
6360
+ choice: bound,
6361
+ options: options2,
6362
+ plan: bound ? plan : void 0,
6363
+ reason: bound ? void 0 : "Requested purchase choice is unavailable"
6364
+ };
6365
+ };
6366
+
6367
+ // src/server/preparePostPurchaseView.ts
6368
+ var resolveDescription = ({ descriptionDocument, ...display }, productDescription) => {
6369
+ const plain = display.language.descriptionEnabled && productDescription || display.responseDescription || (descriptionDocument ? null : display.language.description);
6370
+ return plain === null ? { ...display, description: null, descriptionDocument } : { ...display, description: plain };
6371
+ };
6372
+ var prepareNormalizedPostPurchaseView = (widgetId, normalized, report, choice, quantity2, allowCollection = false) => {
6373
+ const planCatalog = projectPostPurchasePlanCatalog(normalized, report);
6374
+ const selected = selectPostPurchaseChoice(normalized, planCatalog, choice, allowCollection, quantity2);
6375
+ const purchaseOptions = selected.options;
6376
+ const preparation = !selected.choice ? { reason: selected.reason, status: "unsupported" } : selected.choice.mode === "subscription" ? prepareNormalizedSubscription(normalized, report, selected.plan, quantity2, allowCollection) : prepareNormalizedProduct(normalized, report, quantity2, allowCollection);
6377
+ const unsupported = (reason) => ({
6378
+ planCatalog,
6379
+ preparation: { reason, status: "unsupported" },
6380
+ purchaseOptions,
6381
+ sections: null
6382
+ });
6383
+ if (preparation.status === "unsupported") return { planCatalog, preparation, purchaseOptions, sections: null };
6384
+ if (!normalized.effective.blocks?.length) return unsupported("One fixed product information block is required");
6385
+ const sections = convertMessagePreview(
6386
+ widgetId,
6387
+ {
6388
+ blocks: postPurchaseOfferCopy(normalized.effective.blocks, normalized.metadata),
6389
+ type: "shopify_post_purchase_extension"
6390
+ },
6391
+ report
6392
+ );
6393
+ if (sections.sections.filter((section) => section.sectionType === "offers").length !== 1)
6394
+ return unsupported("One fixed product information block is required");
6395
+ return PostPurchaseProductView.parse({
6396
+ planCatalog,
6397
+ preparation: {
6398
+ ...preparation,
6399
+ display: resolveDescription(preparation.display, preparation.product.description)
6400
+ },
6401
+ purchaseOptions,
6402
+ sections
6403
+ });
6404
+ };
6405
+ var preparePostPurchaseView = (widgetId, settings, response, report, choice) => prepareNormalizedPostPurchaseView(widgetId, normalizePostPurchaseProduct(settings, response), report, choice);
6406
+
6407
+ // src/server/preparePostPurchaseAdmissionView.ts
6408
+ var preparePostPurchaseAdmissionView = (widgetId, settings, response, report, choice) => {
6409
+ const normalized = normalizePostPurchaseProduct(settings, response);
6410
+ const view = prepareNormalizedPostPurchaseView(widgetId, normalized, report, choice);
6411
+ const { removePartialOrder } = PostPurchaseSettings.shape.advance.parse(normalized.effective.advance);
6412
+ return { removePartialOrder, view };
6413
+ };
6414
+
6415
+ // src/schema/postPurchaseProductCollectionView.ts
6416
+ import { z as z62 } from "zod";
6417
+ var PostPurchaseProductCollectionView = z62.object({
6418
+ members: z62.array(
6419
+ z62.object({
6420
+ productId: PostPurchaseProductId,
6421
+ productIndex: z62.number().int().nonnegative(),
6422
+ view: PostPurchaseProductView
6423
+ })
6424
+ )
6425
+ });
6426
+ var PostPurchaseCollectionChoice = z62.object({
6427
+ choice: PostPurchaseChoice.optional(),
6428
+ productId: PostPurchaseProductId,
6429
+ variantId: PostPurchaseVariantSelector.shape.variantId.optional()
6430
+ }).strict();
6431
+ var PostPurchaseExcludedProductIds = z62.array(PostPurchaseProductId).default([]);
6432
+
6433
+ // src/server/normalizePostPurchaseCollection.ts
6434
+ import { z as z63 } from "zod";
6435
+ var normalizePostPurchaseCollection = (settings, response, excludedProductIds) => {
6436
+ const normalized = normalizePostPurchaseProduct(settings, response);
6437
+ const limit = z63.number().int().positive();
6438
+ limit.parse(normalized.original.productLimit);
6439
+ const prefix = normalized.data.slice(0, limit.parse(normalized.effective.productLimit));
6440
+ if (new Set(prefix.map(({ id }) => id)).size !== prefix.length)
6441
+ throw new Error("Ambiguous post-purchase collection");
6442
+ const excluded = new Set(PostPurchaseExcludedProductIds.parse(excludedProductIds));
6443
+ const members = prefix.map((product, productIndex) => ({ product, productIndex })).filter(({ product }) => !excluded.has(product.id));
6444
+ return { members, normalized };
6445
+ };
6446
+
6203
6447
  // src/server/postPurchaseVariantCatalog.ts
6204
6448
  var projectPostPurchaseVariantCatalog = (product, settings) => {
6205
6449
  const options2 = PostPurchaseVariantCatalog.shape.options.parse(product.options === void 0 ? [] : product.options).sort((a, b) => a.position - b.position);
@@ -6233,22 +6477,216 @@ var projectPostPurchaseVariantCatalog = (product, settings) => {
6233
6477
  });
6234
6478
  };
6235
6479
 
6236
- // src/schema/postPurchaseGroupCatalog.ts
6237
- import { z as z60 } from "zod";
6238
- var productId = PreparedPostPurchaseProduct.shape.selection.shape.productId;
6239
- var source = PostPurchaseProductSource.shape.data.element;
6240
- var PostPurchaseGroupDescription = source.pick({ description: true, id: true, image: true, images: true, title: true }).extend({
6241
- description: source.shape.description.default(null),
6242
- image: source.shape.image.default(null),
6243
- options: PostPurchaseVariantCatalog.shape.options.default([])
6480
+ // src/schema/postPurchaseQuantity.ts
6481
+ import { z as z64 } from "zod";
6482
+ var quantity = PreparedPostPurchaseProduct.shape.selection.shape.quantity;
6483
+ var PostPurchaseQuantityChoice = PostPurchaseCollectionChoice.extend({ quantity: quantity.optional() });
6484
+ var PostPurchaseQuantityPolicy = PostPurchaseSettings.shape.quantityInputs.omit({ defaultQuantity: true }).extend({
6485
+ initialQuantity: quantity,
6486
+ maxValue: quantity,
6487
+ minValue: z64.literal(0).transform(() => 1).or(quantity)
6488
+ }).refine(({ maxValue, minValue }) => minValue <= maxValue, "Quantity bounds are reversed");
6489
+
6490
+ // src/server/readPostPurchaseQuantity.ts
6491
+ var PostPurchaseQuantityUnavailable = class extends Error {
6492
+ };
6493
+ var readPostPurchaseQuantity = ({
6494
+ data,
6495
+ effective,
6496
+ original
6497
+ }, selection3) => {
6498
+ const positive = PreparedPostPurchaseProduct.shape.selection.shape.quantity;
6499
+ for (const config of [original, effective]) {
6500
+ if (!config.quantityInputs.enabled) continue;
6501
+ const initialQuantity2 = positive.parse(config.quantityInputs.defaultQuantity);
6502
+ const policy2 = PostPurchaseQuantityPolicy.parse({ ...config.quantityInputs, initialQuantity: initialQuantity2 });
6503
+ if (initialQuantity2 < policy2.minValue || initialQuantity2 > policy2.maxValue)
6504
+ throw new Error("Configured quantity default is outside its bounds");
6505
+ }
6506
+ const initialQuantity = data[0]?.metadata?.productQuantity ?? (original.quantityInputs.enabled ? original.quantityInputs.defaultQuantity : 1);
6507
+ const policy = PostPurchaseQuantityPolicy.parse(
6508
+ effective.quantityInputs.enabled ? { ...effective.quantityInputs, initialQuantity } : { enabled: false, initialQuantity, maxValue: initialQuantity, minValue: initialQuantity }
6509
+ );
6510
+ const requested = "quantity" in selection3 ? selection3.quantity : selection3.expectedQuantity === initialQuantity ? void 0 : selection3.expectedQuantity;
6511
+ const quantity2 = positive.parse(requested ?? initialQuantity);
6512
+ if (requested !== void 0 && (policy.enabled ? quantity2 < policy.minValue || quantity2 > policy.maxValue : quantity2 !== initialQuantity))
6513
+ throw new PostPurchaseQuantityUnavailable("Requested quantity is unavailable");
6514
+ return { policy, quantity: quantity2 };
6515
+ };
6516
+
6517
+ // src/schema/postPurchaseVariantDefault.ts
6518
+ import { z as z65 } from "zod";
6519
+ var values = PostPurchaseVariantValues.partial().extend({
6520
+ option1: PostPurchaseVariantValues.shape.option1.nullish()
6244
6521
  });
6245
- var PostPurchaseGroupCatalog = z60.object({
6246
- memberProductId: productId,
6247
- options: z60.array(z60.object({ productId, title: z60.string(), variantCatalog: PostPurchaseVariantCatalog }))
6522
+ var variant = values.extend({
6523
+ id: PostPurchaseVariantId,
6524
+ inventoryManagement: z65.string().nullable(),
6525
+ inventoryPolicy: z65.string(),
6526
+ inventoryQuantity: z65.number()
6248
6527
  });
6249
- var PostPurchaseGroupSelection = z60.object({
6250
- memberProductId: productId,
6251
- productId
6528
+ var options = z65.array(PostPurchaseVariantOption.pick({ name: true, values: true }));
6529
+ var PostPurchaseVariantDefaultProduct = z65.object({
6530
+ id: PostPurchaseProductId,
6531
+ options,
6532
+ selectedVariant: variant.optional(),
6533
+ variants: z65.array(variant)
6534
+ });
6535
+ var PostPurchaseVariantDefaultSettings = PostPurchaseSettings.shape.productOptions.pick({
6536
+ hideOutOfStockVariants: true,
6537
+ matchVariant: true
6538
+ });
6539
+ var PostPurchaseOrderAttributes = z65.record(z65.string(), z65.array(z65.string())).default({});
6540
+ var PostPurchaseOriginalVariants = z65.array(
6541
+ z65.object({ productId: PostPurchaseProductId, variantId: PostPurchaseVariantId })
6542
+ );
6543
+ var PostPurchaseAttributeProducts = z65.array(
6544
+ z65.object({ id: PostPurchaseProductId, options, variants: z65.array(values.extend({ id: PostPurchaseVariantId })) })
6545
+ );
6546
+
6547
+ // src/schema/postPurchaseVariantDefaultContext.ts
6548
+ import { z as z66 } from "zod";
6549
+ var PostPurchaseVariantDefaultContext = z66.object({
6550
+ enrichedLineItems: z66.unknown().optional(),
6551
+ originalVariants: PostPurchaseOriginalVariants
6552
+ });
6553
+
6554
+ // src/server/createPostPurchaseOrderAttributes.ts
6555
+ var createPostPurchaseOrderAttributes = (original, enriched) => {
6556
+ const products = PostPurchaseAttributeProducts.parse(enriched);
6557
+ const attributes = {};
6558
+ for (const item of PostPurchaseOriginalVariants.parse(original)) {
6559
+ const product = products.find(({ id }) => id === item.productId);
6560
+ const variant2 = product?.variants.find(({ id }) => id === item.variantId);
6561
+ if (!variant2 || !product) continue;
6562
+ ["option1", "option2", "option3"].forEach((key, index) => {
6563
+ const value = variant2[key];
6564
+ const option = product.options[index];
6565
+ if (!value || !option) return;
6566
+ const values2 = attributes[option.name] ?? [];
6567
+ if (!values2.includes(value)) attributes[option.name] = [...values2, value];
6568
+ });
6569
+ }
6570
+ return attributes;
6571
+ };
6572
+
6573
+ // src/server/matchPostPurchaseVariantDefault.ts
6574
+ var matchPostPurchaseVariantDefault = (product, attributes, filterOutOfStock) => {
6575
+ const keys = ["option1", "option2", "option3"];
6576
+ const values2 = keys.map((_, index) => {
6577
+ const option = product.options[index];
6578
+ return option ? option.values.filter((value) => attributes[option.name]?.includes(value)) : [];
6579
+ });
6580
+ if (!values2.some((entries) => entries.length)) return;
6581
+ let bestRank = 1;
6582
+ let best;
6583
+ for (const variant2 of product.variants) {
6584
+ if (filterOutOfStock && variant2.inventoryPolicy !== "continue" && variant2.inventoryQuantity <= 0) continue;
6585
+ const rank = keys.reduce((total, key, index) => {
6586
+ const value = variant2[key];
6587
+ return total + Number(!value && !values2[index].length || !!value && values2[index].includes(value));
6588
+ }, 0);
6589
+ if (rank > bestRank) {
6590
+ best = variant2;
6591
+ bestRank = rank;
6592
+ }
6593
+ }
6594
+ return best;
6595
+ };
6596
+
6597
+ // src/server/resolvePostPurchaseVariantDefault.ts
6598
+ var resolvePostPurchaseVariantDefault = (source2, settings, originalAttributes) => {
6599
+ const product = PostPurchaseVariantDefaultProduct.parse(source2);
6600
+ const policy = PostPurchaseVariantDefaultSettings.parse(settings);
6601
+ const attributes = PostPurchaseOrderAttributes.parse(originalAttributes);
6602
+ let selected = source2.selectedVariant && source2.selectedVariant === source2.variants[0] ? product.variants[0] : product.selectedVariant;
6603
+ if (!selected && policy.matchVariant)
6604
+ selected = matchPostPurchaseVariantDefault(product, attributes, policy.hideOutOfStockVariants);
6605
+ selected ?? (selected = product.variants[0]);
6606
+ if (!selected || selected === product.variants[0])
6607
+ selected = product.variants.find(postPurchaseVariantAvailable) ?? selected;
6608
+ return selected?.id ?? null;
6609
+ };
6610
+
6611
+ // src/server/resolvePostPurchaseMemberDefault.ts
6612
+ var resolvePostPurchaseMemberDefault = (product, original, context) => {
6613
+ const originals = PostPurchaseVariantDefaultContext.parse(context);
6614
+ if (product.variants.length < 2 && product.selectedVariant === void 0) return product.variants[0]?.id ?? null;
6615
+ const source2 = PostPurchaseVariantDefaultProduct.parse(product);
6616
+ const settings = PostPurchaseVariantDefaultSettings.parse(original.productOptions);
6617
+ const attributes = settings.matchVariant && !source2.selectedVariant && source2.options.some(({ values: values2 }) => values2.length > 0) && originals.originalVariants.length > 0 && originals.enrichedLineItems != null ? createPostPurchaseOrderAttributes(
6618
+ originals.originalVariants,
6619
+ PostPurchaseAttributeProducts.parse(deepCamelCase(originals.enrichedLineItems))
6620
+ ) : void 0;
6621
+ return resolvePostPurchaseVariantDefault(source2, settings, attributes);
6622
+ };
6623
+
6624
+ // src/server/preparePostPurchaseMemberView.ts
6625
+ var prepareMember = (widgetId, settings, response, requested, report, excludedProductIds, requestedQuantity, defaults) => {
6626
+ const selected = PostPurchaseCollectionChoice.parse(requested);
6627
+ const { members, normalized } = normalizePostPurchaseCollection(settings, response, excludedProductIds);
6628
+ const found = members.find(({ product: product2 }) => product2.id === selected.productId);
6629
+ if (!found) return null;
6630
+ const variantId = selected.variantId ?? (defaults && resolvePostPurchaseMemberDefault(found.product, normalized.original, defaults));
6631
+ const product = variantId === void 0 ? found.product : {
6632
+ ...found.product,
6633
+ variants: found.product.variants.filter(({ id }) => id === variantId)
6634
+ };
6635
+ const selectedInput = { ...normalized, data: [product] };
6636
+ const quantity2 = requestedQuantity ? readPostPurchaseQuantity(selectedInput, requestedQuantity) : void 0;
6637
+ const view = prepareNormalizedPostPurchaseView(widgetId, selectedInput, report, selected.choice, quantity2, true);
6638
+ if (selected.variantId !== void 0 || found.product.variants.length > 1)
6639
+ view.variantCatalog = projectPostPurchaseVariantCatalog(found.product, normalized.effective);
6640
+ if (defaults && selected.variantId === void 0 && variantId && view.variantCatalog?.variants.some(({ id }) => id === variantId))
6641
+ view.initialVariant = { variantId };
6642
+ return { member: { productId: found.product.id, productIndex: found.productIndex, view }, normalized, quantity: quantity2 };
6643
+ };
6644
+ var preparePostPurchaseMemberView = (widgetId, settings, response, requested, report, excludedProductIds) => prepareMember(widgetId, settings, response, requested, report, excludedProductIds)?.member ?? null;
6645
+ var preparePostPurchaseMemberAdmissionView = (widgetId, settings, response, requested, report, excludedProductIds) => {
6646
+ const prepared = prepareMember(widgetId, settings, response, requested, report, excludedProductIds);
6647
+ if (!prepared) return null;
6648
+ const { removePartialOrder } = PostPurchaseSettings.shape.advance.parse(prepared.normalized.effective.advance);
6649
+ return { ...prepared.member, removePartialOrder };
6650
+ };
6651
+
6652
+ // src/server/preparePostPurchaseQuantityView.ts
6653
+ var preparePostPurchaseQuantityView = (widgetId, settings, response, requested, report, excludedProductIds, defaults) => {
6654
+ const { quantity: quantity2, ...selection3 } = PostPurchaseQuantityChoice.parse(requested);
6655
+ const prepared = prepareMember(
6656
+ widgetId,
6657
+ settings,
6658
+ response,
6659
+ selection3,
6660
+ report,
6661
+ excludedProductIds,
6662
+ { quantity: quantity2 },
6663
+ defaults
6664
+ );
6665
+ return prepared ? { ...prepared.member, quantityPolicy: prepared.quantity.policy } : null;
6666
+ };
6667
+
6668
+ // src/server/preparePostPurchaseQuantityAdmissionView.ts
6669
+ var selection = PostPurchaseQuantityChoice.required({ quantity: true });
6670
+ var preparePostPurchaseQuantityAdmissionView = (widgetId, settings, response, expected, report, excludedProductIds, defaults) => {
6671
+ const { quantity: expectedQuantity, ...requested } = selection.parse(expected);
6672
+ const prepared = prepareMember(
6673
+ widgetId,
6674
+ settings,
6675
+ response,
6676
+ requested,
6677
+ report,
6678
+ excludedProductIds,
6679
+ { expectedQuantity },
6680
+ defaults
6681
+ );
6682
+ if (!prepared) return null;
6683
+ const { removePartialOrder } = PostPurchaseSettings.shape.advance.parse(prepared.normalized.effective.advance);
6684
+ return { ...prepared.member, quantityPolicy: prepared.quantity.policy, removePartialOrder };
6685
+ };
6686
+
6687
+ // src/schema/postPurchaseGroup.ts
6688
+ var PostPurchaseGroupChoice = PostPurchaseQuantityChoice.extend({
6689
+ memberProductId: PreparedPostPurchaseProduct.shape.selection.shape.productId
6252
6690
  });
6253
6691
 
6254
6692
  // src/server/readPostPurchaseGroup.ts
@@ -6281,6 +6719,195 @@ var readPostPurchaseGroup = (product, settings, excludedProductIds) => {
6281
6719
  };
6282
6720
  };
6283
6721
 
6722
+ // src/server/readPostPurchaseGroupSelection.ts
6723
+ var readPostPurchaseGroupSelection = (settings, response, requested, excludedProductIds) => {
6724
+ const selection3 = PostPurchaseGroupSelection.parse(requested);
6725
+ const { members, normalized } = normalizePostPurchaseCollection(settings, response);
6726
+ const member = members.find(({ product }) => product.id === selection3.memberProductId);
6727
+ if (!member || !member.product.productGroupVariants.length) return null;
6728
+ const group = readPostPurchaseGroup(member.product, normalized.effective, excludedProductIds);
6729
+ const entry = group.entries.find(({ product }) => product.id === selection3.productId);
6730
+ if (!entry) return null;
6731
+ return {
6732
+ groupCatalog: group.catalog,
6733
+ memberProductId: member.product.id,
6734
+ productIndex: member.productIndex,
6735
+ reportingProduct: { id: member.product.id, title: member.product.title },
6736
+ response: { data: [entry.product], metadata: normalized.metadata },
6737
+ variantCatalog: entry.variantCatalog
6738
+ };
6739
+ };
6740
+
6741
+ // src/server/preparePostPurchaseGroupView.ts
6742
+ var preparePostPurchaseGroupView = (widgetId, settings, response, requested, report, excludedProductIds) => {
6743
+ const { memberProductId, ...selection3 } = PostPurchaseGroupChoice.parse(requested);
6744
+ const group = readPostPurchaseGroupSelection(settings, response, requested, excludedProductIds);
6745
+ if (!group) return null;
6746
+ const variantId = selection3.variantId ?? group.variantCatalog.variants.find(({ available }) => available)?.id;
6747
+ if (variantId === void 0) return null;
6748
+ const prepared = preparePostPurchaseQuantityView(
6749
+ widgetId,
6750
+ settings,
6751
+ group.response,
6752
+ { ...selection3, variantId },
6753
+ report
6754
+ );
6755
+ return prepared && {
6756
+ ...prepared,
6757
+ groupCatalog: group.groupCatalog,
6758
+ memberProductId,
6759
+ productIndex: group.productIndex,
6760
+ reportingProduct: group.reportingProduct
6761
+ };
6762
+ };
6763
+
6764
+ // src/server/preparePostPurchaseGroupAdmissionView.ts
6765
+ var preparePostPurchaseGroupAdmissionView = (widgetId, settings, response, requested, report, excludedProductIds) => {
6766
+ const { memberProductId, ...selection3 } = PostPurchaseGroupChoice.required({ quantity: true }).parse(requested);
6767
+ const group = readPostPurchaseGroupSelection(settings, response, requested, excludedProductIds);
6768
+ if (!group) return null;
6769
+ const variantId = selection3.variantId ?? group.variantCatalog.variants.find(({ available }) => available)?.id;
6770
+ if (variantId === void 0) return null;
6771
+ const prepared = preparePostPurchaseQuantityAdmissionView(
6772
+ widgetId,
6773
+ settings,
6774
+ group.response,
6775
+ { ...selection3, variantId },
6776
+ report
6777
+ );
6778
+ return prepared && {
6779
+ ...prepared,
6780
+ groupCatalog: group.groupCatalog,
6781
+ memberProductId,
6782
+ productIndex: group.productIndex,
6783
+ reportingProduct: group.reportingProduct
6784
+ };
6785
+ };
6786
+
6787
+ // src/server/preparePostPurchaseGroupDefault.ts
6788
+ var preparePostPurchaseGroupDefault = (widgetId, settings, response, memberProductId, context, report, excludedProductIds) => {
6789
+ const { members, normalized } = normalizePostPurchaseCollection(settings, response);
6790
+ const member = members.find(({ product }) => product.id === memberProductId);
6791
+ if (!member || !member.product.productGroupVariants.length) return null;
6792
+ const group = readPostPurchaseGroup(member.product, normalized.effective, excludedProductIds);
6793
+ const ids = new Set(group.entries.map(({ product }) => product.id));
6794
+ const variants = member.product.variants.filter(({ productId: productId2 }) => ids.has(productId2));
6795
+ const selected = PostPurchaseVariantDefaultProduct.shape.selectedVariant.parse(member.product.selectedVariant);
6796
+ const selectedOwner = selected && member.product.variants.find(({ id }) => id === selected.id);
6797
+ const variantId = resolvePostPurchaseMemberDefault(
6798
+ {
6799
+ ...member.product,
6800
+ selectedVariant: selectedOwner && !ids.has(selectedOwner.productId) ? void 0 : member.product.selectedVariant,
6801
+ variants
6802
+ },
6803
+ normalized.original,
6804
+ context
6805
+ );
6806
+ const entry = group.entries.find(({ product }) => product.variants.some(({ id }) => id === variantId));
6807
+ if (!entry || variantId === null) return null;
6808
+ const prepared = preparePostPurchaseGroupView(
6809
+ widgetId,
6810
+ settings,
6811
+ response,
6812
+ { memberProductId, productId: entry.product.id, variantId },
6813
+ report,
6814
+ excludedProductIds
6815
+ );
6816
+ return prepared && { ...prepared, view: { ...prepared.view, initialVariant: { variantId } } };
6817
+ };
6818
+
6819
+ // src/server/preparePostPurchaseCollectionGroup.ts
6820
+ var preparePostPurchaseCollectionGroup = (widgetId, settings, response, member, normalized, excluded, defaults, report) => {
6821
+ const group = readPostPurchaseGroup(member.product, normalized.effective, excluded);
6822
+ if (!group.entries.length) return null;
6823
+ const prepared = preparePostPurchaseGroupDefault(
6824
+ widgetId,
6825
+ settings,
6826
+ response,
6827
+ member.product.id,
6828
+ defaults,
6829
+ report,
6830
+ excluded
6831
+ );
6832
+ return {
6833
+ productId: member.product.id,
6834
+ productIndex: member.productIndex,
6835
+ reportingProduct: { id: member.product.id, title: member.product.title },
6836
+ view: prepared ? { ...prepared.view, groupCatalog: prepared.groupCatalog } : {
6837
+ groupCatalog: group.catalog,
6838
+ preparation: { reason: "Post-purchase group default is unavailable", status: "unsupported" },
6839
+ sections: null
6840
+ }
6841
+ };
6842
+ };
6843
+
6844
+ // src/server/preparePostPurchaseCollectionView.ts
6845
+ var CollectionChoice = PostPurchaseCollectionChoice.omit({ variantId: true });
6846
+ var preparePostPurchaseCollectionView = (widgetId, settings, response, report, requested, excludedProductIds, defaults = { originalVariants: [] }) => {
6847
+ const { members, normalized } = normalizePostPurchaseCollection(settings, response);
6848
+ const excluded = PostPurchaseExcludedProductIds.parse(excludedProductIds);
6849
+ const selected = CollectionChoice.optional().parse(requested);
6850
+ const projected = members.map((member) => {
6851
+ if (member.product.productGroupVariants.length) {
6852
+ if (selected?.productId === member.product.id && selected.choice)
6853
+ throw new Error("Grouped choices require selected merchandise");
6854
+ const group = preparePostPurchaseCollectionGroup(
6855
+ widgetId,
6856
+ settings,
6857
+ response,
6858
+ member,
6859
+ normalized,
6860
+ excluded,
6861
+ defaults,
6862
+ report
6863
+ );
6864
+ return group;
6865
+ }
6866
+ if (excluded.includes(member.product.id)) return null;
6867
+ return {
6868
+ productId: member.product.id,
6869
+ productIndex: member.productIndex,
6870
+ reportingProduct: void 0,
6871
+ view: prepareNormalizedPostPurchaseView(
6872
+ widgetId,
6873
+ { ...normalized, data: [member.product] },
6874
+ report,
6875
+ member.product.id === selected?.productId ? selected.choice : void 0,
6876
+ void 0,
6877
+ true
6878
+ )
6879
+ };
6880
+ }).filter((member) => member !== null);
6881
+ if (selected && !projected.some(({ productId: productId2 }) => productId2 === selected.productId))
6882
+ throw new Error("Requested product is outside the prepared collection");
6883
+ const collection = PostPurchaseProductCollectionView.parse({ members: projected });
6884
+ return {
6885
+ members: collection.members.map((member, index) => ({
6886
+ ...member,
6887
+ ...projected[index].reportingProduct && { reportingProduct: projected[index].reportingProduct }
6888
+ }))
6889
+ };
6890
+ };
6891
+
6892
+ // src/schema/postPurchaseOfferEligibility.ts
6893
+ import { z as z67 } from "zod";
6894
+ var selection2 = PreparedPostPurchaseProduct.shape.selection;
6895
+ var PostPurchaseOfferSkipReason = z67.enum(["empty", "no-eligible-subscription"]);
6896
+ var PostPurchaseOfferEligibilityContext = z67.object({
6897
+ excludedProductIds: PostPurchaseExcludedProductIds,
6898
+ originalLineItems: z67.array(selection2.pick({ productId: true, sellingPlanId: true, variantId: true }))
6899
+ });
6900
+ var PostPurchaseOfferEligibility = z67.discriminatedUnion("status", [
6901
+ z67.object({
6902
+ members: z67.array(
6903
+ z67.object({ productId: selection2.shape.productId, productIndex: z67.number().int().nonnegative() })
6904
+ ),
6905
+ status: z67.literal("retain")
6906
+ }),
6907
+ z67.object({ reason: PostPurchaseOfferSkipReason, status: z67.literal("skip") }),
6908
+ z67.object({ reason: z67.literal("eligible-upgrade").optional(), status: z67.literal("unavailable") })
6909
+ ]);
6910
+
6284
6911
  // src/server/postPurchaseMemberEligibility.ts
6285
6912
  var PostPurchaseInventoryUnavailable = class extends Error {
6286
6913
  };
@@ -6356,74 +6983,6 @@ var classifyPostPurchaseOffer = (settings, response, context) => {
6356
6983
  }
6357
6984
  };
6358
6985
 
6359
- // src/schema/postPurchaseVariantDefault.ts
6360
- import { z as z61 } from "zod";
6361
- var values = PostPurchaseVariantValues.partial().extend({
6362
- option1: PostPurchaseVariantValues.shape.option1.nullish()
6363
- });
6364
- var variant = values.extend({
6365
- id: PostPurchaseVariantId,
6366
- inventoryManagement: z61.string().nullable(),
6367
- inventoryPolicy: z61.string(),
6368
- inventoryQuantity: z61.number()
6369
- });
6370
- var options = z61.array(PostPurchaseVariantOption.pick({ name: true, values: true }));
6371
- var PostPurchaseVariantDefaultProduct = z61.object({
6372
- id: PostPurchaseProductId,
6373
- options,
6374
- selectedVariant: variant.optional(),
6375
- variants: z61.array(variant)
6376
- });
6377
- var PostPurchaseVariantDefaultSettings = PostPurchaseSettings.shape.productOptions.pick({
6378
- hideOutOfStockVariants: true,
6379
- matchVariant: true
6380
- });
6381
- var PostPurchaseOrderAttributes = z61.record(z61.string(), z61.array(z61.string())).default({});
6382
- var PostPurchaseOriginalVariants = z61.array(
6383
- z61.object({ productId: PostPurchaseProductId, variantId: PostPurchaseVariantId })
6384
- );
6385
- var PostPurchaseAttributeProducts = z61.array(
6386
- z61.object({ id: PostPurchaseProductId, options, variants: z61.array(values.extend({ id: PostPurchaseVariantId })) })
6387
- );
6388
-
6389
- // src/server/createPostPurchaseOrderAttributes.ts
6390
- var createPostPurchaseOrderAttributes = (original, enriched) => {
6391
- const products = PostPurchaseAttributeProducts.parse(enriched);
6392
- const attributes = {};
6393
- for (const item of PostPurchaseOriginalVariants.parse(original)) {
6394
- const product = products.find(({ id }) => id === item.productId);
6395
- const variant2 = product?.variants.find(({ id }) => id === item.variantId);
6396
- if (!variant2 || !product) continue;
6397
- ["option1", "option2", "option3"].forEach((key, index) => {
6398
- const value = variant2[key];
6399
- const option = product.options[index];
6400
- if (!value || !option) return;
6401
- const values2 = attributes[option.name] ?? [];
6402
- if (!values2.includes(value)) attributes[option.name] = [...values2, value];
6403
- });
6404
- }
6405
- return attributes;
6406
- };
6407
-
6408
- // src/server/readPostPurchaseGroupSelection.ts
6409
- var readPostPurchaseGroupSelection = (settings, response, requested, excludedProductIds) => {
6410
- const selection2 = PostPurchaseGroupSelection.parse(requested);
6411
- const { members, normalized } = normalizePostPurchaseCollection(settings, response);
6412
- const member = members.find(({ product }) => product.id === selection2.memberProductId);
6413
- if (!member || !member.product.productGroupVariants.length) return null;
6414
- const group = readPostPurchaseGroup(member.product, normalized.effective, excludedProductIds);
6415
- const entry = group.entries.find(({ product }) => product.id === selection2.productId);
6416
- if (!entry) return null;
6417
- return {
6418
- groupCatalog: group.catalog,
6419
- memberProductId: member.product.id,
6420
- productIndex: member.productIndex,
6421
- reportingProduct: { id: member.product.id, title: member.product.title },
6422
- response: { data: [entry.product], metadata: normalized.metadata },
6423
- variantCatalog: entry.variantCatalog
6424
- };
6425
- };
6426
-
6427
6986
  // src/server/preparePostPurchaseGroupDeclineDisplay.ts
6428
6987
  var preparePostPurchaseGroupDeclineDisplay = (settings, response, requested, excludedProductIds) => {
6429
6988
  const group = readPostPurchaseGroupSelection(settings, response, requested, excludedProductIds);
@@ -6440,47 +6999,21 @@ var preparePostPurchaseGroupDeclineDisplay = (settings, response, requested, exc
6440
6999
 
6441
7000
  // src/server/preparePostPurchaseOfferPresentation.ts
6442
7001
  import { merge as merge2 } from "es-toolkit/compat";
6443
- import { z as z64 } from "zod";
7002
+ import { z as z69 } from "zod";
6444
7003
 
6445
7004
  // src/schema/postPurchaseOfferPresentation.ts
6446
- import { z as z62 } from "zod";
7005
+ import { z as z68 } from "zod";
6447
7006
  var language2 = PostPurchaseSettings.shape.language.shape.global.unwrap().unwrap();
6448
- var PostPurchaseOfferPresentation = z62.strictObject({
7007
+ var PostPurchaseOfferPresentation = z68.strictObject({
6449
7008
  labels: language2.pick({ declineAll: true, declineThisOffer: true }),
6450
7009
  layout: PostPurchaseSettings.shape.offersLayout,
6451
7010
  sections: CABRootSection.nullable(),
6452
7011
  showDeclineAll: PostPurchaseSettings.shape.productOptions.shape.showDeclineAll
6453
7012
  });
6454
7013
 
6455
- // src/server/postPurchaseOfferCopy.ts
6456
- import { z as z63 } from "zod";
6457
- var Copy = z63.object({
6458
- superTitle: CalloutBannerBlock.shape.settings.shape.superTitle.unwrap().optional().catch(void 0),
6459
- title: CalloutBannerBlock.shape.settings.shape.title.unwrap().optional().catch(void 0)
6460
- });
6461
- var Callout = z63.object({ settings: z63.record(z63.string(), z63.unknown()), type: z63.literal("callout_banner") });
6462
- var postPurchaseOfferCopy = (blocks, metadata) => {
6463
- const copy = Copy.safeParse(metadata.widget.language);
6464
- if (!blocks || !copy.success) return blocks;
6465
- const first = blocks.findIndex((block) => Callout.pick({ type: true }).safeParse(block).success);
6466
- return blocks.map((block, index) => {
6467
- if (index !== first) return block;
6468
- const callout = Callout.passthrough().safeParse(block);
6469
- if (!callout.success) return block;
6470
- return {
6471
- ...callout.data,
6472
- settings: {
6473
- ...callout.data.settings,
6474
- ...copy.data.title && { title: copy.data.title },
6475
- ...copy.data.superTitle && { superTitle: copy.data.superTitle }
6476
- }
6477
- };
6478
- });
6479
- };
6480
-
6481
7014
  // src/server/preparePostPurchaseOfferPresentation.ts
6482
7015
  var FrameSettings = PostPurchaseSettings.pick({ language: true, offersLayout: true, productOptions: true }).extend({
6483
- blocks: z64.array(z64.unknown()).optional()
7016
+ blocks: z69.array(z69.unknown()).optional()
6484
7017
  });
6485
7018
  var preparePostPurchaseOfferPresentation = (widgetId, settings, response, report) => {
6486
7019
  const { metadata } = PostPurchaseProductSource.pick({ metadata: true }).parse(deepCamelCase(response));
@@ -6504,42 +7037,6 @@ var preparePostPurchaseOfferPresentation = (widgetId, settings, response, report
6504
7037
  });
6505
7038
  };
6506
7039
 
6507
- // src/schema/postPurchaseQuantity.ts
6508
- import { z as z65 } from "zod";
6509
- var quantity = PreparedPostPurchaseProduct.shape.selection.shape.quantity;
6510
- var PostPurchaseQuantityPolicy = PostPurchaseSettings.shape.quantityInputs.omit({ defaultQuantity: true }).extend({
6511
- initialQuantity: quantity,
6512
- maxValue: quantity,
6513
- minValue: z65.literal(0).transform(() => 1).or(quantity)
6514
- }).refine(({ maxValue, minValue }) => minValue <= maxValue, "Quantity bounds are reversed");
6515
-
6516
- // src/server/readPostPurchaseQuantity.ts
6517
- var PostPurchaseQuantityUnavailable = class extends Error {
6518
- };
6519
- var readPostPurchaseQuantity = ({
6520
- data,
6521
- effective,
6522
- original
6523
- }, selection2) => {
6524
- const positive = PreparedPostPurchaseProduct.shape.selection.shape.quantity;
6525
- for (const config of [original, effective]) {
6526
- if (!config.quantityInputs.enabled) continue;
6527
- const initialQuantity2 = positive.parse(config.quantityInputs.defaultQuantity);
6528
- const policy2 = PostPurchaseQuantityPolicy.parse({ ...config.quantityInputs, initialQuantity: initialQuantity2 });
6529
- if (initialQuantity2 < policy2.minValue || initialQuantity2 > policy2.maxValue)
6530
- throw new Error("Configured quantity default is outside its bounds");
6531
- }
6532
- const initialQuantity = data[0]?.metadata?.productQuantity ?? (original.quantityInputs.enabled ? original.quantityInputs.defaultQuantity : 1);
6533
- const policy = PostPurchaseQuantityPolicy.parse(
6534
- effective.quantityInputs.enabled ? { ...effective.quantityInputs, initialQuantity } : { enabled: false, initialQuantity, maxValue: initialQuantity, minValue: initialQuantity }
6535
- );
6536
- const requested = "quantity" in selection2 ? selection2.quantity : selection2.expectedQuantity === initialQuantity ? void 0 : selection2.expectedQuantity;
6537
- const quantity2 = positive.parse(requested ?? initialQuantity);
6538
- if (requested !== void 0 && (policy.enabled ? quantity2 < policy.minValue || quantity2 > policy.maxValue : quantity2 !== initialQuantity))
6539
- throw new PostPurchaseQuantityUnavailable("Requested quantity is unavailable");
6540
- return { policy, quantity: quantity2 };
6541
- };
6542
-
6543
7040
  // src/server/analytics.ts
6544
7041
  import { chunk } from "es-toolkit";
6545
7042
 
@@ -6676,7 +7173,7 @@ var postAnalyticsEvents = async (input, ctx) => {
6676
7173
  };
6677
7174
 
6678
7175
  // src/server/requestSchemas.ts
6679
- import { z as z66 } from "zod";
7176
+ import { z as z70 } from "zod";
6680
7177
  var REQUEST_BOUNDS = {
6681
7178
  /** Cart-level attributes per cart. */
6682
7179
  CART_ATTRIBUTES_MAX: 100,
@@ -6707,42 +7204,42 @@ var REQUEST_BOUNDS = {
6707
7204
  /** Rich ads transaction lines — the engine's ads contract. */
6708
7205
  TRANSACTION_ITEMS_MAX: 50
6709
7206
  };
6710
- var KeyValue = z66.object({
6711
- key: z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
6712
- value: z66.string().max(REQUEST_BOUNDS.STRING_VALUE_MAX).optional()
7207
+ var KeyValue = z70.object({
7208
+ key: z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
7209
+ value: z70.string().max(REQUEST_BOUNDS.STRING_VALUE_MAX).optional()
6713
7210
  });
6714
- var CartLineInputSchema = z66.object({
6715
- productId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6716
- properties: z66.array(KeyValue).max(REQUEST_BOUNDS.LINE_PROPERTIES_MAX).optional(),
6717
- quantity: z66.number(),
6718
- subscriptionId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6719
- variantId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX)
7211
+ var CartLineInputSchema = z70.object({
7212
+ productId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7213
+ properties: z70.array(KeyValue).max(REQUEST_BOUNDS.LINE_PROPERTIES_MAX).optional(),
7214
+ quantity: z70.number(),
7215
+ subscriptionId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7216
+ variantId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX)
6720
7217
  });
6721
- var CartInputSchema = z66.object({
6722
- attributes: z66.array(KeyValue).max(REQUEST_BOUNDS.CART_ATTRIBUTES_MAX).optional(),
7218
+ var CartInputSchema = z70.object({
7219
+ attributes: z70.array(KeyValue).max(REQUEST_BOUNDS.CART_ATTRIBUTES_MAX).optional(),
6723
7220
  /**
6724
7221
  * Presentment-per-shop-currency FX rate (buyer price ÷ shop price, e.g. `1.35` for a USD shop
6725
7222
  * selling in CAD). Money rule thresholds are authored in SHOP currency, so the engine subtotal is
6726
7223
  * divided by this before evaluation. Omit (or send 1) when the cart is already in the shop's currency.
6727
7224
  */
6728
- currencyRate: z66.number().optional(),
7225
+ currencyRate: z70.number().optional(),
6729
7226
  /** Applied discount codes; the engine evaluates `discount_code` rules against them (sent as `[{code}]`). */
6730
- discountCodes: z66.array(z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX)).max(REQUEST_BOUNDS.DISCOUNT_CODES_MAX).optional(),
7227
+ discountCodes: z70.array(z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX)).max(REQUEST_BOUNDS.DISCOUNT_CODES_MAX).optional(),
6731
7228
  /** Presentment cents of cart-level discount allocations, subtracted from `subtotal` for the engine. */
6732
- discountTotal: z66.number().optional(),
6733
- items: z66.array(CartLineInputSchema).max(REQUEST_BOUNDS.CART_ITEMS_MAX),
7229
+ discountTotal: z70.number().optional(),
7230
+ items: z70.array(CartLineInputSchema).max(REQUEST_BOUNDS.CART_ITEMS_MAX),
6734
7231
  /** Presentment subtotal in cents. */
6735
- subtotal: z66.number()
7232
+ subtotal: z70.number()
6736
7233
  });
6737
- var UserConfigInputSchema = z66.object({ shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX) });
6738
- var DataSourceInputSchema = z66.object({
7234
+ var UserConfigInputSchema = z70.object({ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX) });
7235
+ var DataSourceInputSchema = z70.object({
6739
7236
  cart: CartInputSchema,
6740
7237
  /**
6741
7238
  * Numeric Shopify company-location id when the buyer is a B2B session (`buyerIdentity.purchasingCompany`).
6742
7239
  * Present ⇒ the orchestrator filters results by the location's catalog via admin-api (REB-23713); the
6743
7240
  * client's country-context market check is bypassed for B2B (it false-negatives B2B-catalog products).
6744
7241
  */
6745
- companyLocationId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7242
+ companyLocationId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6746
7243
  /**
6747
7244
  * Buyer's market country (ISO 3166-1 alpha-2) — forwarded to the engine as the `country_code` PARAM
6748
7245
  * when the shop's markets toggle is on (REB-21688; the sink was the `X-Country-Code` header under
@@ -6751,16 +7248,16 @@ var DataSourceInputSchema = z66.object({
6751
7248
  * uppercase (the wire value is forwarded verbatim as the param) so a case-sensitive engine lookup
6752
7249
  * can't silently miss a lowercase code — `adsEngine.ts` uppercases for the same reason.
6753
7250
  */
6754
- country: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z]{2}$/, "must be an ISO 3166-1 alpha-2 country code (e.g. CA)").transform((value) => value.toUpperCase()).optional(),
6755
- customerId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6756
- dataSourcePath: z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
7251
+ country: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z]{2}$/, "must be an ISO 3166-1 alpha-2 country code (e.g. CA)").transform((value) => value.toUpperCase()).optional(),
7252
+ customerId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7253
+ dataSourcePath: z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
6757
7254
  /**
6758
7255
  * Engine `filter_inputs` override: `'no'` keeps in-cart (input) products in the results/rule
6759
7256
  * outputs — gift validation sends it so a gift's own product can appear in its answer. Omitted = the
6760
7257
  * engine's default filtering.
6761
7258
  */
6762
- filterInputs: z66.enum(["no", "yes"]).optional(),
6763
- integrations: z66.record(z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX), z66.boolean()).refine((record) => Object.keys(record).length <= REQUEST_BOUNDS.INTEGRATION_KEYS_MAX, {
7259
+ filterInputs: z70.enum(["no", "yes"]).optional(),
7260
+ integrations: z70.record(z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX), z70.boolean()).refine((record) => Object.keys(record).length <= REQUEST_BOUNDS.INTEGRATION_KEYS_MAX, {
6764
7261
  message: `Too many integration keys (max ${REQUEST_BOUNDS.INTEGRATION_KEYS_MAX})`
6765
7262
  }).optional(),
6766
7263
  /**
@@ -6773,31 +7270,31 @@ var DataSourceInputSchema = z66.object({
6773
7270
  * request header) fails the regex. Callers should send the buyer's resolved locale (e.g. Shopify
6774
7271
  * checkout's `localization.language.isoCode`), not the request header verbatim.
6775
7272
  */
6776
- language: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z0-9-]+$/, "must be a single BCP-47 tag (e.g. fr-CA), not a q-value list").optional(),
6777
- limit: z66.number().max(REQUEST_BOUNDS.LIMIT_MAX),
6778
- productType: z66.enum(["both", "one-time", "subscription"]).optional(),
6779
- shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6780
- visitorId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6781
- });
6782
- var GiftInputSchema = z66.object({
6783
- cost: z66.number(),
6784
- discounted: z66.boolean(),
7273
+ language: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z0-9-]+$/, "must be a single BCP-47 tag (e.g. fr-CA), not a q-value list").optional(),
7274
+ limit: z70.number().max(REQUEST_BOUNDS.LIMIT_MAX),
7275
+ productType: z70.enum(["both", "one-time", "subscription"]).optional(),
7276
+ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7277
+ visitorId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7278
+ });
7279
+ var GiftInputSchema = z70.object({
7280
+ cost: z70.number(),
7281
+ discounted: z70.boolean(),
6785
7282
  /**
6786
7283
  * Which gift attribution the line carries (REB-24363). Defaults to `gwp` because a client that predates
6787
7284
  * the field only ever sent GWP lines — without the default an older extension's request would 422.
6788
7285
  */
6789
- kind: z66.enum(GIFT_KINDS).default("gwp"),
6790
- lineId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6791
- productId: z66.number(),
7286
+ kind: z70.enum(GIFT_KINDS).default("gwp"),
7287
+ lineId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7288
+ productId: z70.number(),
6792
7289
  /**
6793
7290
  * The line's unit count (REB-24363) — the selectable-GWP verdict trims surplus units against milestone
6794
7291
  * capacity. The second deliberate default: a client predating the field sent only GWP lines, whose
6795
7292
  * verdict is whole-line, so a missing quantity reads as one unit rather than 422ing the older request.
6796
7293
  */
6797
- quantity: z66.number().int().min(1).default(1),
6798
- widgetId: z66.number()
7294
+ quantity: z70.number().int().min(1).default(1),
7295
+ widgetId: z70.number()
6799
7296
  });
6800
- var GiftValidationInputSchema = z66.object({
7297
+ var GiftValidationInputSchema = z70.object({
6801
7298
  cart: CartInputSchema,
6802
7299
  /**
6803
7300
  * Buyer's market country — threaded into the per-widget data-source evaluations, which forward it to
@@ -6806,25 +7303,25 @@ var GiftValidationInputSchema = z66.object({
6806
7303
  * turns markets off); regex-bound and uppercase-normalized for the same reasons as
6807
7304
  * `DataSourceInputSchema`'s `country`.
6808
7305
  */
6809
- country: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z]{2}$/, "must be an ISO 3166-1 alpha-2 country code (e.g. CA)").transform((value) => value.toUpperCase()).optional(),
6810
- customerId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6811
- gifts: z66.array(GiftInputSchema).max(REQUEST_BOUNDS.GIFTS_MAX),
7306
+ country: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z]{2}$/, "must be an ISO 3166-1 alpha-2 country code (e.g. CA)").transform((value) => value.toUpperCase()).optional(),
7307
+ customerId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7308
+ gifts: z70.array(GiftInputSchema).max(REQUEST_BOUNDS.GIFTS_MAX),
6812
7309
  /**
6813
7310
  * Buyer's checkout language — threaded into the per-widget data-source evaluations, which normalize
6814
7311
  * and forward it as the engine `locale` param under the same markets-toggle gate (REB-21688). MUST be
6815
7312
  * a single BCP-47 tag, for the same reason as `DataSourceInputSchema`'s `language` above.
6816
7313
  */
6817
- language: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z0-9-]+$/, "must be a single BCP-47 tag (e.g. fr-CA), not a q-value list").optional(),
6818
- shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6819
- visitorId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7314
+ language: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).regex(/^[A-Za-z0-9-]+$/, "must be a single BCP-47 tag (e.g. fr-CA), not a q-value list").optional(),
7315
+ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7316
+ visitorId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6820
7317
  });
6821
- var GiftAdjustmentSchema = z66.object({
6822
- lineId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6823
- quantity: z66.number().int().nonnegative()
7318
+ var GiftAdjustmentSchema = z70.object({
7319
+ lineId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7320
+ quantity: z70.number().int().nonnegative()
6824
7321
  });
6825
- var GiftValidationResponseSchema = z66.object({
6826
- adjust: z66.array(GiftAdjustmentSchema).max(REQUEST_BOUNDS.GIFTS_MAX).default([]),
6827
- remove: z66.array(z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX)).max(REQUEST_BOUNDS.GIFTS_MAX).refine(
7322
+ var GiftValidationResponseSchema = z70.object({
7323
+ adjust: z70.array(GiftAdjustmentSchema).max(REQUEST_BOUNDS.GIFTS_MAX).default([]),
7324
+ remove: z70.array(z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX)).max(REQUEST_BOUNDS.GIFTS_MAX).refine(
6828
7325
  (remove) => new Set(remove).size === remove.length,
6829
7326
  "a line id may appear at most once in `remove`"
6830
7327
  )
@@ -6835,47 +7332,47 @@ var GiftValidationResponseSchema = z66.object({
6835
7332
  ({ adjust }) => new Set(adjust.map(({ lineId }) => lineId)).size === adjust.length,
6836
7333
  "a line id may appear at most once in `adjust`"
6837
7334
  );
6838
- var MonetizeTransactionItemSchema = z66.object({
6839
- id: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6840
- priceCents: z66.number(),
6841
- quantity: z66.number(),
6842
- title: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX),
6843
- type: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX)
6844
- });
6845
- var MonetizeInputSchema = z66.object({
7335
+ var MonetizeTransactionItemSchema = z70.object({
7336
+ id: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7337
+ priceCents: z70.number(),
7338
+ quantity: z70.number(),
7339
+ title: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX),
7340
+ type: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX)
7341
+ });
7342
+ var MonetizeInputSchema = z70.object({
6846
7343
  cart: CartInputSchema,
6847
7344
  /** Client-minted render-beacon correlation id; forwarded to the ads engine as `client_request_id`. */
6848
- clientRequestId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6849
- country: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6850
- currency: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7345
+ clientRequestId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7346
+ country: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7347
+ currency: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6851
7348
  /** Ads-targeting identity/geo/locale fields (React parity); folded into the engine query verbatim. */
6852
- customerEmail: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
6853
- customerFirstName: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
6854
- customerId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6855
- customerLastName: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
6856
- language: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7349
+ customerEmail: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
7350
+ customerFirstName: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
7351
+ customerId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7352
+ customerLastName: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
7353
+ language: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6857
7354
  /** Buyer-facing order name (e.g. `#1001`) for the server-composed "Order … Confirmed" chrome line. */
6858
- orderName: z66.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
7355
+ orderName: z70.string().max(REQUEST_BOUNDS.STRING_TEXT_MAX).optional(),
6859
7356
  /** Ads surface label, forwarded verbatim; `customer_account` is measured/floored as its own surface (the account-area order list). */
6860
- placement: z66.enum(["customer_account", "order_status", "thank_you_page"]),
7357
+ placement: z70.enum(["customer_account", "order_status", "thank_you_page"]),
6861
7358
  /** Privacy Policy footer href — the Monetize widget's `privacy_policy_url` setting (React parity). */
6862
- privacyPolicyUrl: z66.string().max(REQUEST_BOUNDS.STRING_URL_MAX).optional(),
7359
+ privacyPolicyUrl: z70.string().max(REQUEST_BOUNDS.STRING_URL_MAX).optional(),
6863
7360
  /** 30-min rolling session id (React parity); used for the ads `session_id`, else the visitor id. */
6864
- sessionId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6865
- shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7361
+ sessionId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7362
+ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6866
7363
  /** Editor/QA indicator; OR-ed into the ads-engine `testing` flag so it stays out of billing/reporting. */
6867
- testing: z66.boolean().optional(),
6868
- timezone: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7364
+ testing: z70.boolean().optional(),
7365
+ timezone: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6869
7366
  /** Decorated (numeric) order id → the ads `transaction_id`. */
6870
- transactionId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7367
+ transactionId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6871
7368
  /** Rich per-line ads items; capped at the engine's ads contract. Preferred over `cart.items`. */
6872
- transactionItems: z66.array(MonetizeTransactionItemSchema).max(REQUEST_BOUNDS.TRANSACTION_ITEMS_MAX).optional(),
7369
+ transactionItems: z70.array(MonetizeTransactionItemSchema).max(REQUEST_BOUNDS.TRANSACTION_ITEMS_MAX).optional(),
6873
7370
  /** Order total in presentment cents (React prefers total over subtotal); else `cart.subtotal`. */
6874
- transactionTotal: z66.number().optional(),
6875
- visitorId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6876
- zipCode: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7371
+ transactionTotal: z70.number().optional(),
7372
+ visitorId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7373
+ zipCode: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6877
7374
  });
6878
- var WidgetSettingsInputSchema = z66.object({
7375
+ var WidgetSettingsInputSchema = z70.object({
6879
7376
  /**
6880
7377
  * Same domain as `CabShopConfig.cacheKey`, for the same reason: this side WINS the orchestrator's
6881
7378
  * `input.cacheKey ?? config.shop.cacheKey` (and an explicit value skips the config read entirely), so
@@ -6883,9 +7380,9 @@ var WidgetSettingsInputSchema = z66.object({
6883
7380
  * and pin the edge copy permanently stale. `.catch(undefined)` because a bogus buster should degrade
6884
7381
  * the read to un-busted, never 400 a widget render.
6885
7382
  */
6886
- cacheKey: z66.number().int().positive().optional().catch(void 0),
6887
- id: z66.number(),
6888
- key: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7383
+ cacheKey: z70.number().int().positive().optional().catch(void 0),
7384
+ id: z70.number(),
7385
+ key: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6889
7386
  /**
6890
7387
  * Monetize context for inline hydration: when present AND the widget converts to a Monetize marker,
6891
7388
  * the server fetches/composes the offer cards inside this same request (no second `/cab/monetize`
@@ -6894,36 +7391,36 @@ var WidgetSettingsInputSchema = z66.object({
6894
7391
  * `privacyPolicyUrl` comes from the widget settings server-side (more authoritative than a relay).
6895
7392
  */
6896
7393
  monetize: MonetizeInputSchema.omit({ privacyPolicyUrl: true, shop: true }).optional(),
6897
- shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7394
+ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6898
7395
  /** Stable per-buyer id; when present, enables sticky server-side A/B variant selection. */
6899
- visitorId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7396
+ visitorId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6900
7397
  });
6901
- var AnalyticsEventInputSchema = z66.object({
6902
- name: z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
6903
- properties: z66.record(z66.string().max(REQUEST_BOUNDS.STRING_KEY_MAX), z66.unknown()).optional(),
6904
- sentAt: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7398
+ var AnalyticsEventInputSchema = z70.object({
7399
+ name: z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX),
7400
+ properties: z70.record(z70.string().max(REQUEST_BOUNDS.STRING_KEY_MAX), z70.unknown()).optional(),
7401
+ sentAt: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6905
7402
  });
6906
- var AnalyticsSegmentsInputSchema = z66.object({
6907
- device: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0),
6908
- source: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0),
6909
- visitor: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0)
7403
+ var AnalyticsSegmentsInputSchema = z70.object({
7404
+ device: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0),
7405
+ source: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0),
7406
+ visitor: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional().catch(void 0)
6910
7407
  });
6911
- var AnalyticsInputSchema = z66.object({
7408
+ var AnalyticsInputSchema = z70.object({
6912
7409
  /** Rebuy cart token (the `r_cart_token` cart attribute), when available — primary aggregation key. */
6913
- cartToken: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7410
+ cartToken: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6914
7411
  /** Shopify checkout token, when available — drives cart/checkout aggregation downstream. */
6915
- checkoutToken: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
6916
- events: z66.array(AnalyticsEventInputSchema).max(REQUEST_BOUNDS.EVENTS_MAX),
7412
+ checkoutToken: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional(),
7413
+ events: z70.array(AnalyticsEventInputSchema).max(REQUEST_BOUNDS.EVENTS_MAX),
6917
7414
  /**
6918
7415
  * Request-scoped like the tokens: one visitor's segments apply to every event in the batch. The container
6919
7416
  * degrades too (`null` is a realistic wire artifact of `attributes ? {…} : null`), so the degrade rule is
6920
7417
  * total: nothing about `segments` can cost the envelope.
6921
7418
  */
6922
7419
  segments: AnalyticsSegmentsInputSchema.optional().catch(void 0),
6923
- shop: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6924
- visitorId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7420
+ shop: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
7421
+ visitorId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX),
6925
7422
  /** The widget id (smartBlockId) the events belong to. */
6926
- widgetId: z66.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
7423
+ widgetId: z70.string().max(REQUEST_BOUNDS.STRING_ID_MAX).optional()
6927
7424
  });
6928
7425
  export {
6929
7426
  AnalyticsEventInputSchema,
@@ -6953,9 +7450,20 @@ export {
6953
7450
  fetchMonetizeOffers,
6954
7451
  fetchUserConfig,
6955
7452
  postAnalyticsEvents,
7453
+ preparePostPurchaseAdmissionView,
7454
+ preparePostPurchaseCollectionView,
7455
+ preparePostPurchaseGroupAdmissionView,
6956
7456
  preparePostPurchaseGroupDeclineDisplay,
7457
+ preparePostPurchaseGroupDefault,
7458
+ preparePostPurchaseGroupView,
7459
+ preparePostPurchaseMemberAdmissionView,
7460
+ preparePostPurchaseMemberView,
6957
7461
  preparePostPurchaseOfferPresentation,
7462
+ preparePostPurchaseProduct,
7463
+ preparePostPurchaseQuantityAdmissionView,
7464
+ preparePostPurchaseQuantityView,
6958
7465
  preparePostPurchaseSubscription,
7466
+ preparePostPurchaseView,
6959
7467
  readPostPurchaseGroupSelection,
6960
7468
  readPostPurchaseQuantity,
6961
7469
  translateAnalyticsEvent,