@aglyn/plugins-commerce 1.29.2 → 1.30.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 (54) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/console/pos/pos-item-dialog.component.js +12 -0
  3. package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -1
  4. package/src/lib/components/console/pos-kiosk-page.component.js +3 -5
  5. package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
  6. package/src/lib/components/console/product-add-ons-fields.component.d.ts +11 -0
  7. package/src/lib/components/console/product-add-ons-fields.component.js +229 -13
  8. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  9. package/src/lib/components/console/products-hub-card.component.js +51 -14
  10. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  11. package/src/lib/components/console/quote-editor-dialog.component.js +38 -0
  12. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  13. package/src/lib/components/product-add-ons.d.ts +21 -0
  14. package/src/lib/components/product-add-ons.js +77 -1
  15. package/src/lib/components/product-add-ons.js.map +1 -1
  16. package/src/lib/components/product-builder-mockup.d.ts +1 -1
  17. package/src/lib/components/product-builder-mockup.js +17 -5
  18. package/src/lib/components/product-builder-mockup.js.map +1 -1
  19. package/src/lib/components/product-choice-cards.js +14 -2
  20. package/src/lib/components/product-choice-cards.js.map +1 -1
  21. package/src/lib/model/commerce-pos-kiosk.js +8 -2
  22. package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
  23. package/src/lib/model/commerce-pos-offline.d.ts +1 -1
  24. package/src/lib/model/commerce-pos-offline.js +8 -2
  25. package/src/lib/model/commerce-pos-offline.js.map +1 -1
  26. package/src/lib/model/commerce-quote-request.d.ts +1 -0
  27. package/src/lib/model/commerce-quote-request.js +6 -2
  28. package/src/lib/model/commerce-quote-request.js.map +1 -1
  29. package/src/lib/model/commerce-quotes.js +10 -5
  30. package/src/lib/model/commerce-quotes.js.map +1 -1
  31. package/src/lib/model/commerce-record-routes.d.ts +13 -1
  32. package/src/lib/model/commerce-record-routes.js +22 -2
  33. package/src/lib/model/commerce-record-routes.js.map +1 -1
  34. package/src/lib/model/commerce.js +1 -1
  35. package/src/lib/model/commerce.js.map +1 -1
  36. package/src/lib/model/product-modifiers.d.ts +53 -2
  37. package/src/lib/model/product-modifiers.js +127 -27
  38. package/src/lib/model/product-modifiers.js.map +1 -1
  39. package/src/lib/plan-entitlements.d.ts +1 -2
  40. package/src/lib/plan-entitlements.js +3 -12
  41. package/src/lib/plan-entitlements.js.map +1 -1
  42. package/src/lib/server/pos-kiosk.js +1 -4
  43. package/src/lib/server/pos-kiosk.js.map +1 -1
  44. package/src/lib/server/product.d.ts +5 -0
  45. package/src/lib/server/product.js +10 -2
  46. package/src/lib/server/product.js.map +1 -1
  47. package/src/lib/server/site-page-resolver.d.ts +12 -1
  48. package/src/lib/server/site-page-resolver.js +100 -9
  49. package/src/lib/server/site-page-resolver.js.map +1 -1
  50. package/src/lib/server.js +4 -2
  51. package/src/lib/server.js.map +1 -1
  52. package/src/lib/transfer/product-register-cells.d.ts +7 -0
  53. package/src/lib/transfer/product-register-cells.js +88 -10
  54. package/src/lib/transfer/product-register-cells.js.map +1 -1
@@ -40,9 +40,50 @@
40
40
  * one price for a bundle ("Weekend kit: 4 walls, 4 weights, a bag"), and the
41
41
  * card folds its contents out. Display only: a combo is priced and sold as
42
42
  * the one choice it is.
43
- *=========================================*/ /** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */ export const POS_MAX_MODIFIER_GROUPS = 10;
43
+ *
44
+ * WRITE-INS (write-ins). A group of `kind: 'text'` asks the
45
+ * shopper to type an answer instead of picking one: the name and number
46
+ * printed on a sign, an engraving, a cake message. It holds exactly one option, which carries what a
47
+ * filled answer adds to the price (by variant too) and its helper note, so
48
+ * pricing, ids and every path that carries picks stay the same; the pick
49
+ * adds the `text`. The answer is checked and cleaned on the server like any
50
+ * pick ({@link cleanWriteIn}) and prints on the line as "Engraving: For
51
+ * Sam". With write-ins and required size groups, one variant sells a set
52
+ * of pieces in any combination of sizes, with no cap on combinations.
53
+ *=========================================*/ /** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */ import { _ as _extends } from "@swc/helpers/_/_extends";
54
+ export const POS_MAX_MODIFIER_GROUPS = 10;
44
55
  export const POS_MAX_MODIFIER_OPTIONS = 20;
45
56
  /** $1,000 on one modifier: anything larger is a product, not an add-on. */ export const POS_MAX_MODIFIER_PRICE_CENTS = 100000;
57
+ /** The longest answer a write-in can take: a name or a short message fits well inside. */ export const MAX_WRITE_IN_LENGTH = 40;
58
+ /** A write-in's length when the merchant sets none. */ export const DEFAULT_WRITE_IN_LENGTH = 20;
59
+ /** How much of a typed answer is carried before its group checks it. */ const WRITE_IN_INPUT_BOUND = 200;
60
+ /** Whether a group is a write-in the shopper types. */ export function modifierGroupIsWriteIn(group) {
61
+ return (group == null ? void 0 : group.kind) === 'text';
62
+ }
63
+ /** A write-in's longest answer. */ export function writeInMaxLength(group) {
64
+ const length = group.maxLength;
65
+ return typeof length === 'number' && Number.isInteger(length) && length >= 1 && length <= MAX_WRITE_IN_LENGTH ? length : DEFAULT_WRITE_IN_LENGTH;
66
+ }
67
+ /**
68
+ * A write-in's answer cleaned for the order: control characters and runs of
69
+ * spaces gone, trimmed, cut at the group's length. Empty when nothing is left.
70
+ * Without a group the answer is only bounded, so a too-long one still reaches
71
+ * the check that names it.
72
+ */ export function cleanWriteIn(raw, group) {
73
+ if (typeof raw !== 'string') return '';
74
+ const limit = group ? writeInMaxLength(group) : WRITE_IN_INPUT_BOUND;
75
+ const flat = raw// eslint-disable-next-line no-control-regex
76
+ .replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ').replace(/\s+/g, ' ').trim();
77
+ return Array.from(flat).slice(0, limit).join('').trim();
78
+ }
79
+ /** Why a write-in's answer cannot be sold, or null when it can. An empty answer is the minimum's business. */ export function writeInProblem(group, raw) {
80
+ const typed = cleanWriteIn(raw);
81
+ if (!typed) return null;
82
+ const limit = writeInMaxLength(group);
83
+ if (Array.from(typed).length > limit) return `${group.name} takes up to ${limit} characters.`;
84
+ if (group.digitsOnly && !/^[0-9]+$/.test(typed)) return `${group.name} takes numbers only.`;
85
+ return null;
86
+ }
46
87
  /** Whether a choice is a combo: it lists what it includes (AGL-4205). */ export function modifierOptionIsCombo(option) {
47
88
  return Array.isArray(option.includes) && option.includes.length > 0 && option.includes.every((item)=>typeof item === 'string');
48
89
  }
@@ -62,6 +103,22 @@ function modifierPriceIsValid(price) {
62
103
  groupIds.add(group.id);
63
104
  if (!String((_group_name = group.name) != null ? _group_name : '').trim()) return 'Name every modifier group';
64
105
  const options = Array.isArray(group.options) ? group.options : [];
106
+ if (group.kind != null && group.kind !== 'text') return `“${group.name}” is a list of choices or a write-in`;
107
+ if (group.kind === 'text') {
108
+ if (options.length !== 1) return `“${group.name}” is a write-in and holds one field`;
109
+ if (group.max !== 1 || group.min !== 0 && group.min !== 1) {
110
+ return `“${group.name}” is a write-in: required or not, one answer`;
111
+ }
112
+ if (group.maxLength != null && (!Number.isInteger(group.maxLength) || group.maxLength < 1 || group.maxLength > MAX_WRITE_IN_LENGTH)) {
113
+ return `“${group.name}” takes 1 to ${MAX_WRITE_IN_LENGTH} characters`;
114
+ }
115
+ if (group.digitsOnly != null && typeof group.digitsOnly !== 'boolean') {
116
+ return `“${group.name}” takes numbers only or any text`;
117
+ }
118
+ }
119
+ if (group.nameOnOrder != null && typeof group.nameOnOrder !== 'boolean') {
120
+ return `“${group.name}” prints its name on the order or not`;
121
+ }
65
122
  if (options.length === 0) return `Add a choice to “${group.name}”`;
66
123
  if (options.length > POS_MAX_MODIFIER_OPTIONS) {
67
124
  return `“${group.name}” has more than ${POS_MAX_MODIFIER_OPTIONS} choices`;
@@ -132,12 +189,29 @@ function modifierPriceIsValid(price) {
132
189
  /** The picks a request names, as ids only, bounded; nothing for a value that is not a list. */ export function modifierSelectionFrom(raw) {
133
190
  return (Array.isArray(raw) ? raw : []).slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS).map((entry)=>{
134
191
  var _ref, _ref1;
135
- return {
192
+ const pick = {
136
193
  groupId: String((_ref = entry == null ? void 0 : entry.groupId) != null ? _ref : ''),
137
194
  optionId: String((_ref1 = entry == null ? void 0 : entry.optionId) != null ? _ref1 : '')
138
195
  };
196
+ // A write-in's answer, bounded here and checked against its group when priced.
197
+ const text = cleanWriteIn(entry == null ? void 0 : entry.text);
198
+ if (text) pick.text = text;
199
+ return pick;
139
200
  });
140
201
  }
202
+ /** A pick as the order keeps it: a choice, or a write-in with its answer. */ function soldModifier(group, option, variantId, text) {
203
+ return _extends({
204
+ groupId: group.id,
205
+ optionId: option.id,
206
+ group: group.name,
207
+ name: option.name,
208
+ priceCents: modifierOptionPriceCents(option, variantId)
209
+ }, text ? {
210
+ text
211
+ } : {}, group.nameOnOrder === true ? {
212
+ nameOnOrder: true
213
+ } : {});
214
+ }
141
215
  /**
142
216
  * Prices a line's chosen modifiers from the PRODUCT, in group order, and
143
217
  * checks every group's minimum and maximum. Unknown ids, a repeated choice
@@ -167,6 +241,20 @@ function modifierPriceIsValid(price) {
167
241
  }
168
242
  const modifiers = [];
169
243
  for (const group of groups){
244
+ if (modifierGroupIsWriteIn(group)) {
245
+ // A write-in (write-ins): its answer is checked, cleaned and kept.
246
+ const option = group.options[0];
247
+ const pick = picks.find((entry)=>entry.groupId === group.id && entry.optionId === option.id);
248
+ const problem = writeInProblem(group, pick == null ? void 0 : pick.text);
249
+ if (problem) return refuse(`${problem} (${product.name})`);
250
+ const text = cleanWriteIn(pick == null ? void 0 : pick.text, group);
251
+ if (!text) {
252
+ if (group.min > 0) return refuse(`Fill in ${group.name.toLowerCase()} for ${product.name}.`);
253
+ continue;
254
+ }
255
+ modifiers.push(soldModifier(group, option, variantId, text));
256
+ continue;
257
+ }
170
258
  const chosen = group.options.filter((option)=>picks.some((pick)=>pick.groupId === group.id && pick.optionId === option.id));
171
259
  if (chosen.length < group.min) {
172
260
  return refuse(`Choose ${group.name.toLowerCase()} for ${product.name}.`);
@@ -174,15 +262,7 @@ function modifierPriceIsValid(price) {
174
262
  if (chosen.length > group.max) {
175
263
  return refuse(`Choose at most ${group.max} for ${group.name.toLowerCase()} on ${product.name}.`);
176
264
  }
177
- for (const option of chosen){
178
- modifiers.push({
179
- groupId: group.id,
180
- optionId: option.id,
181
- group: group.name,
182
- name: option.name,
183
- priceCents: modifierOptionPriceCents(option, variantId)
184
- });
185
- }
265
+ for (const option of chosen)modifiers.push(soldModifier(group, option, variantId, undefined));
186
266
  }
187
267
  return {
188
268
  ok: true,
@@ -210,16 +290,13 @@ function modifierPriceIsValid(price) {
210
290
  const picks = modifierSelectionFrom(raw);
211
291
  const modifiers = [];
212
292
  for (const group of productModifierGroups(product)){
293
+ const writeIn = modifierGroupIsWriteIn(group);
213
294
  for (const option of group.options){
214
- if (picks.some((pick)=>pick.groupId === group.id && pick.optionId === option.id)) {
215
- modifiers.push({
216
- groupId: group.id,
217
- optionId: option.id,
218
- group: group.name,
219
- name: option.name,
220
- priceCents: modifierOptionPriceCents(option, variantId)
221
- });
222
- }
295
+ const pick = picks.find((entry)=>entry.groupId === group.id && entry.optionId === option.id);
296
+ if (!pick) continue;
297
+ const text = writeIn ? cleanWriteIn(pick.text, group) : undefined;
298
+ if (writeIn && !text) continue;
299
+ modifiers.push(soldModifier(group, option, variantId, text));
223
300
  }
224
301
  }
225
302
  return modifiers;
@@ -232,17 +309,24 @@ function modifierPriceIsValid(price) {
232
309
  return /Remove it and add it again/.test(reason) ? reason : `${reason} Remove it and add it again from its page.`;
233
310
  }
234
311
  /** The picks a priced line keeps: ids only, in the product's group order. */ export function modifierSelectionOf(modifiers) {
235
- return modifiers.map((modifier)=>({
312
+ return modifiers.map((modifier)=>_extends({
236
313
  groupId: modifier.groupId,
237
314
  optionId: modifier.optionId
238
- }));
315
+ }, modifier.text ? {
316
+ text: modifier.text
317
+ } : {}));
239
318
  }
240
319
  /**
241
320
  * The picks as one metadata value (AGL-4100), for a payment processor that
242
321
  * holds strings only: `[["group","option"],…]`. Empty for no picks.
243
322
  */ export function encodeModifierSelection(selection) {
244
323
  if (!(selection == null ? void 0 : selection.length)) return '';
245
- return JSON.stringify(selection.map((pick)=>[
324
+ // A write-in's answer rides as a third entry: `[["group","option","For Sam"],…]`.
325
+ return JSON.stringify(selection.map((pick)=>pick.text ? [
326
+ pick.groupId,
327
+ pick.optionId,
328
+ pick.text
329
+ ] : [
246
330
  pick.groupId,
247
331
  pick.optionId
248
332
  ]));
@@ -252,16 +336,32 @@ function modifierPriceIsValid(price) {
252
336
  try {
253
337
  const parsed = JSON.parse(value);
254
338
  if (!Array.isArray(parsed)) return [];
255
- return parsed.filter((pair)=>Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string').slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS).map(([groupId, optionId])=>({
339
+ return parsed.filter((pair)=>Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string').slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS).map(([groupId, optionId, typed])=>{
340
+ const text = cleanWriteIn(typed);
341
+ return text ? {
342
+ groupId,
343
+ optionId,
344
+ text
345
+ } : {
256
346
  groupId,
257
347
  optionId
258
- }));
348
+ };
349
+ });
259
350
  } catch (unused) {
260
351
  return [];
261
352
  }
262
353
  }
354
+ /**
355
+ * How one modifier prints on a line: its name (`Oat milk`), its group and
356
+ * name when the group asks for it (`Size: M`), or a write-in's name
357
+ * and answer (`Engraving: For Sam`).
358
+ */ export function modifierLineText(modifier) {
359
+ if (modifier.text) return `${modifier.group || modifier.name}: ${modifier.text}`;
360
+ if (modifier.nameOnOrder && modifier.group) return `${modifier.group}: ${modifier.name}`;
361
+ return modifier.name;
362
+ }
263
363
  /** The label a line prints: the variant, then each modifier (`Large / Oat milk, Extra shot`). */ export function lineLabelWithModifiers(variantLabel, modifiers) {
264
- const added = modifiers.map((modifier)=>modifier.name).join(', ');
364
+ const added = modifiers.map(modifierLineText).join(', ');
265
365
  return [
266
366
  variantLabel,
267
367
  added
@@ -270,7 +370,7 @@ function modifierPriceIsValid(price) {
270
370
  /** Two lines merge only when they are the same item with the same choices. */ export function modifierSelectionKey(selection) {
271
371
  return [
272
372
  ...selection != null ? selection : []
273
- ].map((pick)=>`${pick.groupId}:${pick.optionId}`).sort().join('|');
373
+ ].map((pick)=>pick.text ? `${pick.groupId}:${pick.optionId}=${pick.text}` : `${pick.groupId}:${pick.optionId}`).sort().join('|');
274
374
  }
275
375
 
276
376
  //# sourceMappingURL=product-modifiers.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-modifiers.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * REGISTER MODIFIERS AND QUICK KEYS (AGL-3607).\n *\n * A modifier is a choice added to an item as it is rung up — \"Oat milk\",\n * \"Extra shot +$0.75\", \"No onions\" — that is not a stocked variant. Groups\n * live on the product (`modifierGroups`); the register sends the chosen\n * option ids with each line and the SERVER prices them from the product\n * document, so a register never names what a modifier costs.\n *\n * A chosen modifier is folded into the line's `variantLabel` as well as kept\n * structured in `modifiers`: every receipt, email, order view and export\n * already prints the label, so the choice reaches all of them without each\n * learning a new field.\n *\n * ADD-ONS ON THE WEBSITE (AGL-4100). A group switched to \"Show on the\n * website\" (`online`) is offered on the product's page too, and a cart line,\n * Buy now and the order carry its picks the same way: ids from the shopper,\n * prices from the product. A choice may cost more on one variant than\n * another (`priceCentsByVariant`), which is how one page sells a canopy whose\n * walls cost more at a larger size without a variant for every combination.\n *\n * THE PRODUCT BUILDER (AGL-4205). A choice may carry a picture and a short\n * note, which a product page set to show its choices as picture cards draws\n * on the choice's card. A choice that lists what it `includes` is a combo:\n * one price for a bundle (\"Weekend kit: 4 walls, 4 weights, a bag\"), and the\n * card folds its contents out. Display only: a combo is priced and sold as\n * the one choice it is.\n *=========================================*/\n\n/** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */\nexport interface ProductModifierOption {\n id: string\n name: string\n priceCents: number\n /**\n * What the choice adds on one variant, keyed by variant id (AGL-4100):\n * walls cost more on a larger canopy. A variant not listed pays\n * `priceCents`. Read through {@link modifierOptionPriceCents}.\n */\n priceCentsByVariant?: Record<string, number>\n /** A picture of the choice, from the media library, for its card (AGL-4205). */\n imageUrl?: string\n /** A short line under the choice on its card (AGL-4205): \"Blocks wind on one side\". */\n note?: string\n /**\n * What a combo holds (AGL-4205), one item per entry: \"Full wall ×2\". A\n * choice with any is shown as a combo whose contents fold out.\n */\n includes?: string[]\n}\n\n/**\n * A set of choices offered together (\"Milk\", \"Add-ons\"). `min` of 1 or more\n * makes it required; `max` caps how many can be picked (1 = pick one).\n */\nexport interface ProductModifierGroup {\n id: string\n name: string\n min: number\n max: number\n options: ProductModifierOption[]\n /**\n * Offered on the product's page on the website as well as at the register\n * (AGL-4100), \"Show on the website\". Absent reads as register only, so a\n * group made before the switch changes nothing on a live store; the\n * console makes new groups with it on.\n */\n online?: boolean\n}\n\n/** A modifier as the order line keeps it: names and price as sold. */\nexport interface OrderLineModifier {\n groupId: string\n optionId: string\n group: string\n name: string\n priceCents: number\n}\n\n/** What the register sends for a line: the option ids it picked, nothing priced. */\nexport interface ModifierSelection {\n groupId: string\n optionId: string\n}\n\nexport const POS_MAX_MODIFIER_GROUPS = 10\nexport const POS_MAX_MODIFIER_OPTIONS = 20\n/** $1,000 on one modifier: anything larger is a product, not an add-on. */\nexport const POS_MAX_MODIFIER_PRICE_CENTS = 100_000\n/** Whether a choice is a combo: it lists what it includes (AGL-4205). */\nexport function modifierOptionIsCombo(option: Pick<ProductModifierOption, 'includes'>): boolean {\n return (\n Array.isArray(option.includes) &&\n option.includes.length > 0 &&\n option.includes.every((item) => typeof item === 'string')\n )\n}\n\nfunction modifierPriceIsValid(price: unknown): boolean {\n return (\n typeof price === 'number' &&\n Number.isInteger(price) &&\n price >= 0 &&\n price <= POS_MAX_MODIFIER_PRICE_CENTS\n )\n}\n\n/** Why a product's modifier groups cannot be saved, or null when they can. */\nexport function modifierGroupsProblem(groups: unknown): string | null {\n if (groups == null) return null\n if (!Array.isArray(groups)) return 'Modifiers must be a list'\n if (groups.length > POS_MAX_MODIFIER_GROUPS) {\n return `At most ${POS_MAX_MODIFIER_GROUPS} modifier groups per product`\n }\n const groupIds = new Set<string>()\n for (const group of groups as ProductModifierGroup[]) {\n if (!group?.id || groupIds.has(group.id)) return 'Modifier groups need unique ids'\n groupIds.add(group.id)\n if (!String(group.name ?? '').trim()) return 'Name every modifier group'\n const options = Array.isArray(group.options) ? group.options : []\n if (options.length === 0) return `Add a choice to “${group.name}”`\n if (options.length > POS_MAX_MODIFIER_OPTIONS) {\n return `“${group.name}” has more than ${POS_MAX_MODIFIER_OPTIONS} choices`\n }\n const optionIds = new Set<string>()\n for (const option of options) {\n if (!option?.id || optionIds.has(option.id)) return 'Modifier choices need unique ids'\n optionIds.add(option.id)\n if (!String(option.name ?? '').trim()) return `Name every choice in “${group.name}”`\n const price = option.priceCents\n if (!modifierPriceIsValid(price)) {\n return `“${option.name}” needs a price of $0 to $1,000`\n }\n const byVariant = option.priceCentsByVariant\n if (byVariant != null) {\n if (typeof byVariant !== 'object' || Array.isArray(byVariant)) {\n return `“${option.name}” has prices that are not a list by option`\n }\n if (Object.values(byVariant).some((cents) => !modifierPriceIsValid(cents))) {\n return `“${option.name}” needs a price of $0 to $1,000 for each option it is priced by`\n }\n }\n }\n if (group.online != null && typeof group.online !== 'boolean') {\n return `“${group.name}” is shown on the website or not`\n }\n const { min, max } = group\n if (!Number.isInteger(min) || min < 0) return `“${group.name}” needs a minimum of 0 or more`\n if (!Number.isInteger(max) || max < 1 || max > options.length) {\n return `“${group.name}” allows 1 to ${options.length} choices`\n }\n if (min > max) return `“${group.name}” requires more choices than it allows`\n }\n return null\n}\n\n/** How a variant is named in a choice's price list, in the editor and in an import file. */\nexport function variantPriceLabel(variant: { options?: Record<string, string> }): string {\n const values = Object.values(variant.options ?? {}).filter(Boolean)\n return values.length ? values.join(' / ') : 'Default'\n}\n\n/** The product's groups, or none when they are missing or malformed. */\nexport function productModifierGroups(product: {\n modifierGroups?: unknown\n}): ProductModifierGroup[] {\n const groups = product?.modifierGroups\n if (!Array.isArray(groups) || modifierGroupsProblem(groups)) return []\n return groups as ProductModifierGroup[]\n}\n\n/** Whether a group must be answered before the item can be added. */\nexport function modifierGroupRequired(group: ProductModifierGroup): boolean {\n return group.min > 0\n}\n\n/**\n * The groups the product's page on the website offers (AGL-4100): those\n * switched to \"Show on the website\". A register-only group is never sent to\n * a shopper, never asked of one and never priced on an online order.\n */\nexport function websiteModifierGroups(product: { modifierGroups?: unknown }): ProductModifierGroup[] {\n return productModifierGroups(product).filter((group) => group.online === true)\n}\n\n/** Whether the website must ask a shopper a choice before the item goes in a cart. */\nexport function websiteModifiersRequired(product: { modifierGroups?: unknown }): boolean {\n return websiteModifierGroups(product).some(modifierGroupRequired)\n}\n\n/**\n * What one choice adds to one unit of the picked variant (AGL-4100): its\n * price on that variant where it has one, else its own price.\n */\nexport function modifierOptionPriceCents(\n option: Pick<ProductModifierOption, 'priceCents' | 'priceCentsByVariant'>,\n variantId?: string | null,\n): number {\n const byVariant = variantId ? option.priceCentsByVariant?.[variantId] : undefined\n return typeof byVariant === 'number' && Number.isFinite(byVariant) ? byVariant : option.priceCents\n}\n\n/** A line's chosen modifiers, priced. */\nexport interface ResolvedLineModifiers {\n ok: boolean\n /** The chosen modifiers, in group order; empty when not `ok`. */\n modifiers: OrderLineModifier[]\n /** What they add to one unit, in cents. */\n extraCents: number\n /** What to fix, when not `ok`. */\n error?: string\n}\n\n/** The picks a request names, as ids only, bounded; nothing for a value that is not a list. */\nexport function modifierSelectionFrom(raw: unknown): ModifierSelection[] {\n return (Array.isArray(raw) ? raw : [])\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map((entry: any) => ({\n groupId: String(entry?.groupId ?? ''),\n optionId: String(entry?.optionId ?? ''),\n }))\n}\n\n/**\n * Prices a line's chosen modifiers from the PRODUCT, in group order, and\n * checks every group's minimum and maximum. Unknown ids, a repeated choice\n * and a group answered past its maximum are refused with what to fix.\n *\n * `variantId` is the variant the line sells (AGL-4100): a choice priced by\n * variant adds its price on that one. Without it every choice adds its own\n * `priceCents`, as it always did.\n */\nexport function resolveLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n const refuse = (error: string): ResolvedLineModifiers => ({\n ok: false,\n modifiers: [],\n extraCents: 0,\n error,\n })\n const groups = productModifierGroups(product)\n const picks = modifierSelectionFrom(raw)\n const seen = new Set<string>()\n for (const pick of picks) {\n const key = `${pick.groupId}:${pick.optionId}`\n if (seen.has(key)) return refuse(`A choice on ${product.name} was picked twice.`)\n seen.add(key)\n const group = groups.find((entry) => entry.id === pick.groupId)\n if (!group || !group.options.some((option) => option.id === pick.optionId)) {\n return refuse(`A choice on ${product.name} is no longer offered. Remove it and add it again.`)\n }\n }\n const modifiers: OrderLineModifier[] = []\n for (const group of groups) {\n const chosen = group.options.filter((option) =>\n picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id),\n )\n if (chosen.length < group.min) {\n return refuse(`Choose ${group.name.toLowerCase()} for ${product.name}.`)\n }\n if (chosen.length > group.max) {\n return refuse(`Choose at most ${group.max} for ${group.name.toLowerCase()} on ${product.name}.`)\n }\n for (const option of chosen) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n return {\n ok: true,\n modifiers,\n extraCents: modifiers.reduce((sum, modifier) => sum + modifier.priceCents, 0),\n }\n}\n\n/**\n * {@link resolveLineModifiers} for a sale made online (AGL-4100): only the\n * groups shown on the website are offered, asked or priced. A register-only\n * group, required or not, is not the shopper's to answer.\n */\nexport function resolveWebsiteLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n return resolveLineModifiers(\n { name: product.name, modifierGroups: websiteModifierGroups(product) },\n raw,\n variantId,\n )\n}\n\n/**\n * The modifiers a PAID line names, for its order record (AGL-4100): every\n * pick the product still offers, in group order, priced as it is now, with no\n * minimum or maximum asked. The money was taken when the sale was priced;\n * a choice the merchant removed since is left off the record, never a reason\n * to lose the order.\n */\nexport function soldLineModifiers(\n product: { modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): OrderLineModifier[] {\n const picks = modifierSelectionFrom(raw)\n const modifiers: OrderLineModifier[] = []\n for (const group of productModifierGroups(product)) {\n for (const option of group.options) {\n if (picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id)) {\n modifiers.push({\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n })\n }\n }\n }\n return modifiers\n}\n\n/**\n * What a shopper is told about a cart line whose add-ons no longer answer\n * the product (AGL-4100): the resolver's reason, and how to put it right.\n */\nexport function cartLineModifierProblem(error: string | undefined): string {\n const reason = String(error ?? '').trim() || 'The choices on this item have changed.'\n return /Remove it and add it again/.test(reason)\n ? reason\n : `${reason} Remove it and add it again from its page.`\n}\n\n/** The picks a priced line keeps: ids only, in the product's group order. */\nexport function modifierSelectionOf(\n modifiers: readonly Pick<OrderLineModifier, 'groupId' | 'optionId'>[],\n): ModifierSelection[] {\n return modifiers.map((modifier) => ({ groupId: modifier.groupId, optionId: modifier.optionId }))\n}\n\n/**\n * The picks as one metadata value (AGL-4100), for a payment processor that\n * holds strings only: `[[\"group\",\"option\"],…]`. Empty for no picks.\n */\nexport function encodeModifierSelection(selection: readonly ModifierSelection[] | undefined): string {\n if (!selection?.length) return ''\n return JSON.stringify(selection.map((pick) => [pick.groupId, pick.optionId]))\n}\n\n/** {@link encodeModifierSelection} read back; nothing for a value it did not write. */\nexport function decodeModifierSelection(value: unknown): ModifierSelection[] {\n if (typeof value !== 'string' || !value) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed\n .filter(\n (pair): pair is [string, string] =>\n Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string',\n )\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map(([groupId, optionId]) => ({ groupId, optionId }))\n } catch {\n return []\n }\n}\n\n/** The label a line prints: the variant, then each modifier (`Large / Oat milk, Extra shot`). */\nexport function lineLabelWithModifiers(\n variantLabel: string | undefined,\n modifiers: readonly Pick<OrderLineModifier, 'name'>[],\n): string {\n const added = modifiers.map((modifier) => modifier.name).join(', ')\n return [variantLabel, added].filter(Boolean).join(' / ')\n}\n\n/** Two lines merge only when they are the same item with the same choices. */\nexport function modifierSelectionKey(selection: readonly ModifierSelection[] | undefined): string {\n return [...(selection ?? [])]\n .map((pick) => `${pick.groupId}:${pick.optionId}`)\n .sort()\n .join('|')\n}\n"],"names":["POS_MAX_MODIFIER_GROUPS","POS_MAX_MODIFIER_OPTIONS","POS_MAX_MODIFIER_PRICE_CENTS","modifierOptionIsCombo","option","Array","isArray","includes","length","every","item","modifierPriceIsValid","price","Number","isInteger","modifierGroupsProblem","groups","groupIds","Set","group","id","has","add","String","name","trim","options","optionIds","priceCents","byVariant","priceCentsByVariant","Object","values","some","cents","online","min","max","variantPriceLabel","variant","filter","Boolean","join","productModifierGroups","product","modifierGroups","modifierGroupRequired","websiteModifierGroups","websiteModifiersRequired","modifierOptionPriceCents","variantId","undefined","isFinite","modifierSelectionFrom","raw","slice","map","entry","groupId","optionId","resolveLineModifiers","refuse","error","ok","modifiers","extraCents","picks","seen","pick","key","find","chosen","toLowerCase","push","reduce","sum","modifier","resolveWebsiteLineModifiers","soldLineModifiers","cartLineModifierProblem","reason","test","modifierSelectionOf","encodeModifierSelection","selection","JSON","stringify","decodeModifierSelection","value","parsed","parse","pair","lineLabelWithModifiers","variantLabel","added","modifierSelectionKey","sort"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA2B2C,GAE3C,mFAAmF,GAwDnF,OAAO,MAAMA,0BAA0B,GAAE;AACzC,OAAO,MAAMC,2BAA2B,GAAE;AAC1C,yEAAyE,GACzE,OAAO,MAAMC,+BAA+B,OAAO;AACnD,uEAAuE,GACvE,OAAO,SAASC,sBAAsBC,MAA+C;IACnF,OACEC,MAAMC,OAAO,CAACF,OAAOG,QAAQ,KAC7BH,OAAOG,QAAQ,CAACC,MAAM,GAAG,KACzBJ,OAAOG,QAAQ,CAACE,KAAK,CAAC,CAACC,OAAS,OAAOA,SAAS;AAEpD;AAEA,SAASC,qBAAqBC,KAAc;IAC1C,OACE,OAAOA,UAAU,YACjBC,OAAOC,SAAS,CAACF,UACjBA,SAAS,KACTA,SAASV;AAEb;AAEA,4EAA4E,GAC5E,OAAO,SAASa,sBAAsBC,MAAe;IACnD,IAAIA,UAAU,MAAM,OAAO;IAC3B,IAAI,CAACX,MAAMC,OAAO,CAACU,SAAS,OAAO;IACnC,IAAIA,OAAOR,MAAM,GAAGR,yBAAyB;QAC3C,OAAO,CAAC,QAAQ,EAAEA,wBAAwB,4BAA4B,CAAC;IACzE;IACA,MAAMiB,WAAW,IAAIC;IACrB,KAAK,MAAMC,SAASH,OAAkC;YAGxCG;QAFZ,IAAI,EAACA,yBAAAA,MAAOC,EAAE,KAAIH,SAASI,GAAG,CAACF,MAAM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OAAO,CAAC,CAAC,EAAEU,KAAKT,QAAQ,EAAE,EAChDqC,IAAI,GACJtD,IAAI,CAAC;AACV"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-modifiers.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * REGISTER MODIFIERS AND QUICK KEYS (AGL-3607).\n *\n * A modifier is a choice added to an item as it is rung up — \"Oat milk\",\n * \"Extra shot +$0.75\", \"No onions\" — that is not a stocked variant. Groups\n * live on the product (`modifierGroups`); the register sends the chosen\n * option ids with each line and the SERVER prices them from the product\n * document, so a register never names what a modifier costs.\n *\n * A chosen modifier is folded into the line's `variantLabel` as well as kept\n * structured in `modifiers`: every receipt, email, order view and export\n * already prints the label, so the choice reaches all of them without each\n * learning a new field.\n *\n * ADD-ONS ON THE WEBSITE (AGL-4100). A group switched to \"Show on the\n * website\" (`online`) is offered on the product's page too, and a cart line,\n * Buy now and the order carry its picks the same way: ids from the shopper,\n * prices from the product. A choice may cost more on one variant than\n * another (`priceCentsByVariant`), which is how one page sells a canopy whose\n * walls cost more at a larger size without a variant for every combination.\n *\n * THE PRODUCT BUILDER (AGL-4205). A choice may carry a picture and a short\n * note, which a product page set to show its choices as picture cards draws\n * on the choice's card. A choice that lists what it `includes` is a combo:\n * one price for a bundle (\"Weekend kit: 4 walls, 4 weights, a bag\"), and the\n * card folds its contents out. Display only: a combo is priced and sold as\n * the one choice it is.\n *\n * WRITE-INS (write-ins). A group of `kind: 'text'` asks the\n * shopper to type an answer instead of picking one: the name and number\n * printed on a sign, an engraving, a cake message. It holds exactly one option, which carries what a\n * filled answer adds to the price (by variant too) and its helper note, so\n * pricing, ids and every path that carries picks stay the same; the pick\n * adds the `text`. The answer is checked and cleaned on the server like any\n * pick ({@link cleanWriteIn}) and prints on the line as \"Engraving: For\n * Sam\". With write-ins and required size groups, one variant sells a set\n * of pieces in any combination of sizes, with no cap on combinations.\n *=========================================*/\n\n/** One choice in a modifier group. `priceCents` is added to the item, 0 for free. */\nexport interface ProductModifierOption {\n id: string\n name: string\n priceCents: number\n /**\n * What the choice adds on one variant, keyed by variant id (AGL-4100):\n * walls cost more on a larger canopy. A variant not listed pays\n * `priceCents`. Read through {@link modifierOptionPriceCents}.\n */\n priceCentsByVariant?: Record<string, number>\n /** A picture of the choice, from the media library, for its card (AGL-4205). */\n imageUrl?: string\n /** A short line under the choice on its card (AGL-4205): \"Blocks wind on one side\". */\n note?: string\n /**\n * What a combo holds (AGL-4205), one item per entry: \"Full wall ×2\". A\n * choice with any is shown as a combo whose contents fold out.\n */\n includes?: string[]\n}\n\n/**\n * A set of choices offered together (\"Milk\", \"Add-ons\"). `min` of 1 or more\n * makes it required; `max` caps how many can be picked (1 = pick one).\n */\nexport interface ProductModifierGroup {\n id: string\n name: string\n min: number\n max: number\n options: ProductModifierOption[]\n /**\n * `'text'` makes the group a write-in: the shopper types the answer (a\n * name, a number) into one field. Absent is a group of choices. A write-in\n * holds exactly one option, which names it and prices it.\n */\n kind?: ProductModifierGroupKind\n /** A write-in's longest answer, 1 to {@link MAX_WRITE_IN_LENGTH}; {@link DEFAULT_WRITE_IN_LENGTH} when absent. */\n maxLength?: number\n /** A write-in that takes digits only, such as a number. */\n digitsOnly?: boolean\n /**\n * Print the group's name before the choice on the order, receipt and\n * emails (\"Size: M\"), for choices that do not say what they are on\n * their own. A write-in always prints its name.\n */\n nameOnOrder?: boolean\n /**\n * Offered on the product's page on the website as well as at the register\n * (AGL-4100), \"Show on the website\". Absent reads as register only, so a\n * group made before the switch changes nothing on a live store; the\n * console makes new groups with it on.\n */\n online?: boolean\n}\n\n/** What a group is: choices to pick from, or a write-in the shopper types. */\nexport type ProductModifierGroupKind = 'text'\n\n/** A modifier as the order line keeps it: names and price as sold. */\nexport interface OrderLineModifier {\n groupId: string\n optionId: string\n group: string\n name: string\n priceCents: number\n /** A write-in's answer as sold, such as the text to engrave. */\n text?: string\n /** The group's name prints before the choice on the line (\"Size: M\"). */\n nameOnOrder?: boolean\n}\n\n/** What the register sends for a line: the option ids it picked, nothing priced. */\nexport interface ModifierSelection {\n groupId: string\n optionId: string\n /** A write-in's answer, as typed; the server cleans and checks it. */\n text?: string\n}\n\nexport const POS_MAX_MODIFIER_GROUPS = 10\nexport const POS_MAX_MODIFIER_OPTIONS = 20\n/** $1,000 on one modifier: anything larger is a product, not an add-on. */\nexport const POS_MAX_MODIFIER_PRICE_CENTS = 100_000\n/** The longest answer a write-in can take: a name or a short message fits well inside. */\nexport const MAX_WRITE_IN_LENGTH = 40\n/** A write-in's length when the merchant sets none. */\nexport const DEFAULT_WRITE_IN_LENGTH = 20\n/** How much of a typed answer is carried before its group checks it. */\nconst WRITE_IN_INPUT_BOUND = 200\n\n/** Whether a group is a write-in the shopper types. */\nexport function modifierGroupIsWriteIn(group: Pick<ProductModifierGroup, 'kind'> | null | undefined): boolean {\n return group?.kind === 'text'\n}\n\n/** A write-in's longest answer. */\nexport function writeInMaxLength(group: Pick<ProductModifierGroup, 'maxLength'>): number {\n const length = group.maxLength\n return typeof length === 'number' && Number.isInteger(length) && length >= 1 && length <= MAX_WRITE_IN_LENGTH\n ? length\n : DEFAULT_WRITE_IN_LENGTH\n}\n\n/**\n * A write-in's answer cleaned for the order: control characters and runs of\n * spaces gone, trimmed, cut at the group's length. Empty when nothing is left.\n * Without a group the answer is only bounded, so a too-long one still reaches\n * the check that names it.\n */\nexport function cleanWriteIn(raw: unknown, group?: Pick<ProductModifierGroup, 'maxLength'> | null): string {\n if (typeof raw !== 'string') return ''\n const limit = group ? writeInMaxLength(group) : WRITE_IN_INPUT_BOUND\n const flat = raw\n // eslint-disable-next-line no-control-regex\n .replace(/[\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029]/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim()\n return Array.from(flat).slice(0, limit).join('').trim()\n}\n\n/** Why a write-in's answer cannot be sold, or null when it can. An empty answer is the minimum's business. */\nexport function writeInProblem(\n group: Pick<ProductModifierGroup, 'name' | 'maxLength' | 'digitsOnly'>,\n raw: unknown,\n): string | null {\n const typed = cleanWriteIn(raw)\n if (!typed) return null\n const limit = writeInMaxLength(group)\n if (Array.from(typed).length > limit) return `${group.name} takes up to ${limit} characters.`\n if (group.digitsOnly && !/^[0-9]+$/.test(typed)) return `${group.name} takes numbers only.`\n return null\n}\n/** Whether a choice is a combo: it lists what it includes (AGL-4205). */\nexport function modifierOptionIsCombo(option: Pick<ProductModifierOption, 'includes'>): boolean {\n return (\n Array.isArray(option.includes) &&\n option.includes.length > 0 &&\n option.includes.every((item) => typeof item === 'string')\n )\n}\n\nfunction modifierPriceIsValid(price: unknown): boolean {\n return (\n typeof price === 'number' &&\n Number.isInteger(price) &&\n price >= 0 &&\n price <= POS_MAX_MODIFIER_PRICE_CENTS\n )\n}\n\n/** Why a product's modifier groups cannot be saved, or null when they can. */\nexport function modifierGroupsProblem(groups: unknown): string | null {\n if (groups == null) return null\n if (!Array.isArray(groups)) return 'Modifiers must be a list'\n if (groups.length > POS_MAX_MODIFIER_GROUPS) {\n return `At most ${POS_MAX_MODIFIER_GROUPS} modifier groups per product`\n }\n const groupIds = new Set<string>()\n for (const group of groups as ProductModifierGroup[]) {\n if (!group?.id || groupIds.has(group.id)) return 'Modifier groups need unique ids'\n groupIds.add(group.id)\n if (!String(group.name ?? '').trim()) return 'Name every modifier group'\n const options = Array.isArray(group.options) ? group.options : []\n if (group.kind != null && group.kind !== 'text') return `“${group.name}” is a list of choices or a write-in`\n if (group.kind === 'text') {\n if (options.length !== 1) return `“${group.name}” is a write-in and holds one field`\n if (group.max !== 1 || (group.min !== 0 && group.min !== 1)) {\n return `“${group.name}” is a write-in: required or not, one answer`\n }\n if (\n group.maxLength != null &&\n (!Number.isInteger(group.maxLength) || group.maxLength < 1 || group.maxLength > MAX_WRITE_IN_LENGTH)\n ) {\n return `“${group.name}” takes 1 to ${MAX_WRITE_IN_LENGTH} characters`\n }\n if (group.digitsOnly != null && typeof group.digitsOnly !== 'boolean') {\n return `“${group.name}” takes numbers only or any text`\n }\n }\n if (group.nameOnOrder != null && typeof group.nameOnOrder !== 'boolean') {\n return `“${group.name}” prints its name on the order or not`\n }\n if (options.length === 0) return `Add a choice to “${group.name}”`\n if (options.length > POS_MAX_MODIFIER_OPTIONS) {\n return `“${group.name}” has more than ${POS_MAX_MODIFIER_OPTIONS} choices`\n }\n const optionIds = new Set<string>()\n for (const option of options) {\n if (!option?.id || optionIds.has(option.id)) return 'Modifier choices need unique ids'\n optionIds.add(option.id)\n if (!String(option.name ?? '').trim()) return `Name every choice in “${group.name}”`\n const price = option.priceCents\n if (!modifierPriceIsValid(price)) {\n return `“${option.name}” needs a price of $0 to $1,000`\n }\n const byVariant = option.priceCentsByVariant\n if (byVariant != null) {\n if (typeof byVariant !== 'object' || Array.isArray(byVariant)) {\n return `“${option.name}” has prices that are not a list by option`\n }\n if (Object.values(byVariant).some((cents) => !modifierPriceIsValid(cents))) {\n return `“${option.name}” needs a price of $0 to $1,000 for each option it is priced by`\n }\n }\n }\n if (group.online != null && typeof group.online !== 'boolean') {\n return `“${group.name}” is shown on the website or not`\n }\n const { min, max } = group\n if (!Number.isInteger(min) || min < 0) return `“${group.name}” needs a minimum of 0 or more`\n if (!Number.isInteger(max) || max < 1 || max > options.length) {\n return `“${group.name}” allows 1 to ${options.length} choices`\n }\n if (min > max) return `“${group.name}” requires more choices than it allows`\n }\n return null\n}\n\n/** How a variant is named in a choice's price list, in the editor and in an import file. */\nexport function variantPriceLabel(variant: { options?: Record<string, string> }): string {\n const values = Object.values(variant.options ?? {}).filter(Boolean)\n return values.length ? values.join(' / ') : 'Default'\n}\n\n/** The product's groups, or none when they are missing or malformed. */\nexport function productModifierGroups(product: {\n modifierGroups?: unknown\n}): ProductModifierGroup[] {\n const groups = product?.modifierGroups\n if (!Array.isArray(groups) || modifierGroupsProblem(groups)) return []\n return groups as ProductModifierGroup[]\n}\n\n/** Whether a group must be answered before the item can be added. */\nexport function modifierGroupRequired(group: ProductModifierGroup): boolean {\n return group.min > 0\n}\n\n/**\n * The groups the product's page on the website offers (AGL-4100): those\n * switched to \"Show on the website\". A register-only group is never sent to\n * a shopper, never asked of one and never priced on an online order.\n */\nexport function websiteModifierGroups(product: { modifierGroups?: unknown }): ProductModifierGroup[] {\n return productModifierGroups(product).filter((group) => group.online === true)\n}\n\n/** Whether the website must ask a shopper a choice before the item goes in a cart. */\nexport function websiteModifiersRequired(product: { modifierGroups?: unknown }): boolean {\n return websiteModifierGroups(product).some(modifierGroupRequired)\n}\n\n/**\n * What one choice adds to one unit of the picked variant (AGL-4100): its\n * price on that variant where it has one, else its own price.\n */\nexport function modifierOptionPriceCents(\n option: Pick<ProductModifierOption, 'priceCents' | 'priceCentsByVariant'>,\n variantId?: string | null,\n): number {\n const byVariant = variantId ? option.priceCentsByVariant?.[variantId] : undefined\n return typeof byVariant === 'number' && Number.isFinite(byVariant) ? byVariant : option.priceCents\n}\n\n/** A line's chosen modifiers, priced. */\nexport interface ResolvedLineModifiers {\n ok: boolean\n /** The chosen modifiers, in group order; empty when not `ok`. */\n modifiers: OrderLineModifier[]\n /** What they add to one unit, in cents. */\n extraCents: number\n /** What to fix, when not `ok`. */\n error?: string\n}\n\n/** The picks a request names, as ids only, bounded; nothing for a value that is not a list. */\nexport function modifierSelectionFrom(raw: unknown): ModifierSelection[] {\n return (Array.isArray(raw) ? raw : [])\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map((entry: any): ModifierSelection => {\n const pick: ModifierSelection = {\n groupId: String(entry?.groupId ?? ''),\n optionId: String(entry?.optionId ?? ''),\n }\n // A write-in's answer, bounded here and checked against its group when priced.\n const text = cleanWriteIn(entry?.text)\n if (text) pick.text = text\n return pick\n })\n}\n\n/** A pick as the order keeps it: a choice, or a write-in with its answer. */\nfunction soldModifier(\n group: ProductModifierGroup,\n option: ProductModifierOption,\n variantId: string | null | undefined,\n text: string | undefined,\n): OrderLineModifier {\n return {\n groupId: group.id,\n optionId: option.id,\n group: group.name,\n name: option.name,\n priceCents: modifierOptionPriceCents(option, variantId),\n ...(text ? { text } : {}),\n ...(group.nameOnOrder === true ? { nameOnOrder: true } : {}),\n }\n}\n\n/**\n * Prices a line's chosen modifiers from the PRODUCT, in group order, and\n * checks every group's minimum and maximum. Unknown ids, a repeated choice\n * and a group answered past its maximum are refused with what to fix.\n *\n * `variantId` is the variant the line sells (AGL-4100): a choice priced by\n * variant adds its price on that one. Without it every choice adds its own\n * `priceCents`, as it always did.\n */\nexport function resolveLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n const refuse = (error: string): ResolvedLineModifiers => ({\n ok: false,\n modifiers: [],\n extraCents: 0,\n error,\n })\n const groups = productModifierGroups(product)\n const picks = modifierSelectionFrom(raw)\n const seen = new Set<string>()\n for (const pick of picks) {\n const key = `${pick.groupId}:${pick.optionId}`\n if (seen.has(key)) return refuse(`A choice on ${product.name} was picked twice.`)\n seen.add(key)\n const group = groups.find((entry) => entry.id === pick.groupId)\n if (!group || !group.options.some((option) => option.id === pick.optionId)) {\n return refuse(`A choice on ${product.name} is no longer offered. Remove it and add it again.`)\n }\n }\n const modifiers: OrderLineModifier[] = []\n for (const group of groups) {\n if (modifierGroupIsWriteIn(group)) {\n // A write-in (write-ins): its answer is checked, cleaned and kept.\n const option = group.options[0]\n const pick = picks.find((entry) => entry.groupId === group.id && entry.optionId === option.id)\n const problem = writeInProblem(group, pick?.text)\n if (problem) return refuse(`${problem} (${product.name})`)\n const text = cleanWriteIn(pick?.text, group)\n if (!text) {\n if (group.min > 0) return refuse(`Fill in ${group.name.toLowerCase()} for ${product.name}.`)\n continue\n }\n modifiers.push(soldModifier(group, option, variantId, text))\n continue\n }\n const chosen = group.options.filter((option) =>\n picks.some((pick) => pick.groupId === group.id && pick.optionId === option.id),\n )\n if (chosen.length < group.min) {\n return refuse(`Choose ${group.name.toLowerCase()} for ${product.name}.`)\n }\n if (chosen.length > group.max) {\n return refuse(`Choose at most ${group.max} for ${group.name.toLowerCase()} on ${product.name}.`)\n }\n for (const option of chosen) modifiers.push(soldModifier(group, option, variantId, undefined))\n }\n return {\n ok: true,\n modifiers,\n extraCents: modifiers.reduce((sum, modifier) => sum + modifier.priceCents, 0),\n }\n}\n\n/**\n * {@link resolveLineModifiers} for a sale made online (AGL-4100): only the\n * groups shown on the website are offered, asked or priced. A register-only\n * group, required or not, is not the shopper's to answer.\n */\nexport function resolveWebsiteLineModifiers(\n product: { name?: string; modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): ResolvedLineModifiers {\n return resolveLineModifiers(\n { name: product.name, modifierGroups: websiteModifierGroups(product) },\n raw,\n variantId,\n )\n}\n\n/**\n * The modifiers a PAID line names, for its order record (AGL-4100): every\n * pick the product still offers, in group order, priced as it is now, with no\n * minimum or maximum asked. The money was taken when the sale was priced;\n * a choice the merchant removed since is left off the record, never a reason\n * to lose the order.\n */\nexport function soldLineModifiers(\n product: { modifierGroups?: unknown },\n raw: unknown,\n variantId?: string | null,\n): OrderLineModifier[] {\n const picks = modifierSelectionFrom(raw)\n const modifiers: OrderLineModifier[] = []\n for (const group of productModifierGroups(product)) {\n const writeIn = modifierGroupIsWriteIn(group)\n for (const option of group.options) {\n const pick = picks.find((entry) => entry.groupId === group.id && entry.optionId === option.id)\n if (!pick) continue\n const text = writeIn ? cleanWriteIn(pick.text, group) : undefined\n if (writeIn && !text) continue\n modifiers.push(soldModifier(group, option, variantId, text))\n }\n }\n return modifiers\n}\n\n/**\n * What a shopper is told about a cart line whose add-ons no longer answer\n * the product (AGL-4100): the resolver's reason, and how to put it right.\n */\nexport function cartLineModifierProblem(error: string | undefined): string {\n const reason = String(error ?? '').trim() || 'The choices on this item have changed.'\n return /Remove it and add it again/.test(reason)\n ? reason\n : `${reason} Remove it and add it again from its page.`\n}\n\n/** The picks a priced line keeps: ids only, in the product's group order. */\nexport function modifierSelectionOf(\n modifiers: readonly (Pick<OrderLineModifier, 'groupId' | 'optionId'> & { text?: string })[],\n): ModifierSelection[] {\n return modifiers.map((modifier) => ({\n groupId: modifier.groupId,\n optionId: modifier.optionId,\n ...(modifier.text ? { text: modifier.text } : {}),\n }))\n}\n\n/**\n * The picks as one metadata value (AGL-4100), for a payment processor that\n * holds strings only: `[[\"group\",\"option\"],…]`. Empty for no picks.\n */\nexport function encodeModifierSelection(selection: readonly ModifierSelection[] | undefined): string {\n if (!selection?.length) return ''\n // A write-in's answer rides as a third entry: `[[\"group\",\"option\",\"For Sam\"],…]`.\n return JSON.stringify(\n selection.map((pick) => (pick.text ? [pick.groupId, pick.optionId, pick.text] : [pick.groupId, pick.optionId])),\n )\n}\n\n/** {@link encodeModifierSelection} read back; nothing for a value it did not write. */\nexport function decodeModifierSelection(value: unknown): ModifierSelection[] {\n if (typeof value !== 'string' || !value) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed\n .filter(\n (pair): pair is [string, string, unknown?] =>\n Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'string',\n )\n .slice(0, POS_MAX_MODIFIER_GROUPS * POS_MAX_MODIFIER_OPTIONS)\n .map(([groupId, optionId, typed]) => {\n const text = cleanWriteIn(typed)\n return text ? { groupId, optionId, text } : { groupId, optionId }\n })\n } catch {\n return []\n }\n}\n\n/** A modifier as {@link modifierLineText} reads it. */\nexport type PrintedModifier = Pick<OrderLineModifier, 'name'> &\n Partial<Pick<OrderLineModifier, 'group' | 'text' | 'nameOnOrder'>>\n\n/**\n * How one modifier prints on a line: its name (`Oat milk`), its group and\n * name when the group asks for it (`Size: M`), or a write-in's name\n * and answer (`Engraving: For Sam`).\n */\nexport function modifierLineText(modifier: PrintedModifier): string {\n if (modifier.text) return `${modifier.group || modifier.name}: ${modifier.text}`\n if (modifier.nameOnOrder && modifier.group) return `${modifier.group}: ${modifier.name}`\n return modifier.name\n}\n\n/** The label a line prints: the variant, then each modifier (`Large / Oat milk, Extra shot`). */\nexport function lineLabelWithModifiers(variantLabel: string | undefined, modifiers: readonly PrintedModifier[]): string {\n const added = modifiers.map(modifierLineText).join(', ')\n return [variantLabel, added].filter(Boolean).join(' / ')\n}\n\n/** Two lines merge only when they are the same item with the same choices. */\nexport function modifierSelectionKey(selection: readonly ModifierSelection[] | undefined): string {\n return [...(selection ?? [])]\n .map((pick) => (pick.text ? `${pick.groupId}:${pick.optionId}=${pick.text}` : `${pick.groupId}:${pick.optionId}`))\n .sort()\n .join('|')\n}\n"],"names":["POS_MAX_MODIFIER_GROUPS","POS_MAX_MODIFIER_OPTIONS","POS_MAX_MODIFIER_PRICE_CENTS","MAX_WRITE_IN_LENGTH","DEFAULT_WRITE_IN_LENGTH","WRITE_IN_INPUT_BOUND","modifierGroupIsWriteIn","group","kind","writeInMaxLength","length","maxLength","Number","isInteger","cleanWriteIn","raw","limit","flat","replace","trim","Array","from","slice","join","writeInProblem","typed","name","digitsOnly","test","modifierOptionIsCombo","option","isArray","includes","every","item","modifierPriceIsValid","price","modifierGroupsProblem","groups","groupIds","Set","id","has","add","String","options","max","min","nameOnOrder","optionIds","priceCents","byVariant","priceCentsByVariant","Object","values","some","cents","online","variantPriceLabel","variant","filter","Boolean","productModifierGroups","product","modifierGroups","modifierGroupRequired","websiteModifierGroups","websiteModifiersRequired","modifierOptionPriceCents","variantId","undefined","isFinite","modifierSelectionFrom","map","entry","pick","groupId","optionId","text","soldModifier","resolveLineModifiers","refuse","error","ok","modifiers","extraCents","picks","seen","key","find","problem","toLowerCase","push","chosen","reduce","sum","modifier","resolveWebsiteLineModifiers","soldLineModifiers","writeIn","cartLineModifierProblem","reason","modifierSelectionOf","encodeModifierSelection","selection","JSON","stringify","decodeModifierSelection","value","parsed","parse","pair","modifierLineText","lineLabelWithModifiers","variantLabel","added","modifierSelectionKey","sort"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAqC2C,GAE3C,mFAAmF;AAiFnF,OAAO,MAAMA,0BAA0B,GAAE;AACzC,OAAO,MAAMC,2BAA2B,GAAE;AAC1C,yEAAyE,GACzE,OAAO,MAAMC,+BAA+B,OAAO;AACnD,wFAAwF,GACxF,OAAO,MAAMC,sBAAsB,GAAE;AACrC,qDAAqD,GACrD,OAAO,MAAMC,0BAA0B,GAAE;AACzC,sEAAsE,GACtE,MAAMC,uBAAuB;AAE7B,qDAAqD,GACrD,OAAO,SAASC,uBAAuBC,KAA4D;IACjG,OAAOA,CAAAA,yBAAAA,MAAOC,IAAI,MAAK;AACzB;AAEA,iCAAiC,GACjC,OAAO,SAASC,iBAAiBF,KAA8C;IAC7E,MAAMG,SAASH,MAAMI,SAAS;IAC9B,OAAO,OAAOD,WAAW,YAAYE,OAAOC,SAAS,CAACH,WAAWA,UAAU,KAAKA,UAAUP,sBACtFO,SACAN;AACN;AAEA;;;;;CAKC,GACD,OAAO,SAASU,aAAaC,GAAY,EAAER,KAAsD;IAC/F,IAAI,OAAOQ,QAAQ,UAAU,OAAO;IACpC,MAAMC,QAAQT,QAAQE,iBAAiBF,SAASF;IAChD,MAAMY,OAAOF,GACX,4CAA4C;KAC3CG,OAAO,CAAC,6CAA6C,KACrDA,OAAO,CAAC,QAAQ,KAChBC,IAAI;IACP,OAAOC,MAAMC,IAAI,CAACJ,MAAMK,KAAK,CAAC,GAAGN,OAAOO,IAAI,CAAC,IAAIJ,IAAI;AACvD;AAEA,4GAA4G,GAC5G,OAAO,SAASK,eACdjB,KAAsE,EACtEQ,GAAY;IAEZ,MAAM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AACE,OAAUA,KAAKG,IAAI,GAAG,GAAGH,KAAKC,OAAO,CAAC,CAAC,EAAED,KAAKE,QAAQ,CAAC,CAAC,EAAEF,KAAKG,IAAI,EAAE,GAAG,GAAGH,KAAKC,OAAO,CAAC,CAAC,EAAED,KAAKE,QAAQ,EAAE,EAC/GwC,IAAI,GACJ9F,IAAI,CAAC;AACV"}
@@ -37,7 +37,6 @@ declare module '@aglyn/aglyn/plugin-manager/plugin-entitlement-keys' {
37
37
  * Recurring billing, paid memberships and gift cards start at Pro since
38
38
  * pricing v4 (2026-11-03, AGL-4126): every Business feature moved into Pro at
39
39
  * no charge, and the digital fee (1% on Pro since 2026-11-24) is their
40
- * usage price. `FROM_BUSINESS`
41
- * stays the shape a retired plan reads.
40
+ * usage price.
42
41
  */
43
42
  export declare function commercePlanEntitlements(): PluginPlanEntitlementsDeclaration;
@@ -15,28 +15,19 @@
15
15
  * limitations under the License.
16
16
  */ // Types only: the manifest generator loads this module on its own to compile
17
17
  // the plan figures, so nothing here may reach a core module at runtime.
18
- import { _ as _extends } from "@swc/helpers/_/_extends";
19
- /** Business and up. */ const FROM_BUSINESS = {
18
+ /** Pro and up. */ const FROM_PRO = {
20
19
  free: false,
21
20
  starter: false,
22
- pro: false,
23
- business: true,
24
- scale: true,
25
- advanced: true,
26
- agency: true,
21
+ pro: true,
27
22
  enterprise: true
28
23
  };
29
- /** Pro and up. */ const FROM_PRO = _extends({}, FROM_BUSINESS, {
30
- pro: true
31
- });
32
24
  /**
33
25
  * Commerce's plan gates, for the manifest generator.
34
26
  *
35
27
  * Recurring billing, paid memberships and gift cards start at Pro since
36
28
  * pricing v4 (2026-11-03, AGL-4126): every Business feature moved into Pro at
37
29
  * no charge, and the digital fee (1% on Pro since 2026-11-24) is their
38
- * usage price. `FROM_BUSINESS`
39
- * stays the shape a retired plan reads.
30
+ * usage price.
40
31
  */ export function commercePlanEntitlements() {
41
32
  return {
42
33
  features: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/plan-entitlements.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Types only: the manifest generator loads this module on its own to compile\n// the plan figures, so nothing here may reach a core module at runtime.\nimport type { OrgPlan } from '@aglyn/aglyn/foundation/definitions/org-billing.types'\nimport type { PluginPlanEntitlementsDeclaration } from '@aglyn/aglyn/plugin-manager/plugin-plan-entitlements'\n\n/**\n * COMMERCE'S PLAN GATES (AGL-3080): the storefront features that start above\n * the entry tiers. Compiled into core's `PLAN_ENTITLEMENTS` by the manifest\n * generator (`register.planEntitlements`), so the plan comparison and every\n * gate read the answers they always have.\n */\ndeclare module '@aglyn/aglyn/plugin-manager/plugin-entitlement-keys' {\n interface PluginEntitlementFeatures {\n /** Recurring storefront subscription products (AGL-303). */\n storefrontSubscriptions?: boolean\n /** Gift cards & store credit (AGL-322). */\n giftCards?: boolean\n /** Commerce analytics dashboard (AGL-327). */\n commerceAnalytics?: boolean\n }\n}\n\n/** Business and up. */\nconst FROM_BUSINESS: Readonly<Record<OrgPlan, boolean>> = {\n free: false,\n starter: false,\n pro: false,\n business: true,\n scale: true,\n advanced: true,\n agency: true,\n enterprise: true,\n}\n\n/** Pro and up. */\nconst FROM_PRO: Readonly<Record<OrgPlan, boolean>> = {\n ...FROM_BUSINESS,\n pro: true,\n}\n\n/**\n * Commerce's plan gates, for the manifest generator.\n *\n * Recurring billing, paid memberships and gift cards start at Pro since\n * pricing v4 (2026-11-03, AGL-4126): every Business feature moved into Pro at\n * no charge, and the digital fee (1% on Pro since 2026-11-24) is their\n * usage price. `FROM_BUSINESS`\n * stays the shape a retired plan reads.\n */\nexport function commercePlanEntitlements(): PluginPlanEntitlementsDeclaration {\n return {\n features: [\n {\n key: 'storefrontSubscriptions',\n label: 'Storefront subscriptions',\n byPlan: FROM_PRO,\n },\n { key: 'giftCards', label: 'Gift cards', byPlan: FROM_PRO },\n {\n key: 'commerceAnalytics',\n label: 'Commerce analytics',\n byPlan: FROM_PRO,\n },\n ],\n }\n}\n"],"names":["FROM_BUSINESS","free","starter","pro","business","scale","advanced","agency","enterprise","FROM_PRO","commercePlanEntitlements","features","key","label","byPlan"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,6EAA6E;AAC7E,wEAAwE;;AAqBxE,qBAAqB,GACrB,MAAMA,gBAAoD;IACxDC,MAAM;IACNC,SAAS;IACTC,KAAK;IACLC,UAAU;IACVC,OAAO;IACPC,UAAU;IACVC,QAAQ;IACRC,YAAY;AACd;AAEA,gBAAgB,GAChB,MAAMC,WAA+C,aAChDT;IACHG,KAAK;;AAGP;;;;;;;;CAQC,GACD,OAAO,SAASO;IACd,OAAO;QACLC,UAAU;YACR;gBACEC,KAAK;gBACLC,OAAO;gBACPC,QAAQL;YACV;YACA;gBAAEG,KAAK;gBAAaC,OAAO;gBAAcC,QAAQL;YAAS;YAC1D;gBACEG,KAAK;gBACLC,OAAO;gBACPC,QAAQL;YACV;SACD;IACH;AACF"}
1
+ {"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/plan-entitlements.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Types only: the manifest generator loads this module on its own to compile\n// the plan figures, so nothing here may reach a core module at runtime.\nimport type { OrgPlan } from '@aglyn/aglyn/foundation/definitions/org-billing.types'\nimport type { PluginPlanEntitlementsDeclaration } from '@aglyn/aglyn/plugin-manager/plugin-plan-entitlements'\n\n/**\n * COMMERCE'S PLAN GATES (AGL-3080): the storefront features that start above\n * the entry tiers. Compiled into core's `PLAN_ENTITLEMENTS` by the manifest\n * generator (`register.planEntitlements`), so the plan comparison and every\n * gate read the answers they always have.\n */\ndeclare module '@aglyn/aglyn/plugin-manager/plugin-entitlement-keys' {\n interface PluginEntitlementFeatures {\n /** Recurring storefront subscription products (AGL-303). */\n storefrontSubscriptions?: boolean\n /** Gift cards & store credit (AGL-322). */\n giftCards?: boolean\n /** Commerce analytics dashboard (AGL-327). */\n commerceAnalytics?: boolean\n }\n}\n\n/** Pro and up. */\nconst FROM_PRO: Readonly<Record<OrgPlan, boolean>> = {\n free: false,\n starter: false,\n pro: true,\n enterprise: true,\n}\n\n/**\n * Commerce's plan gates, for the manifest generator.\n *\n * Recurring billing, paid memberships and gift cards start at Pro since\n * pricing v4 (2026-11-03, AGL-4126): every Business feature moved into Pro at\n * no charge, and the digital fee (1% on Pro since 2026-11-24) is their\n * usage price.\n */\nexport function commercePlanEntitlements(): PluginPlanEntitlementsDeclaration {\n return {\n features: [\n {\n key: 'storefrontSubscriptions',\n label: 'Storefront subscriptions',\n byPlan: FROM_PRO,\n },\n { key: 'giftCards', label: 'Gift cards', byPlan: FROM_PRO },\n {\n key: 'commerceAnalytics',\n label: 'Commerce analytics',\n byPlan: FROM_PRO,\n },\n ],\n }\n}\n"],"names":["FROM_PRO","free","starter","pro","enterprise","commercePlanEntitlements","features","key","label","byPlan"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,6EAA6E;AAC7E,wEAAwE;AAqBxE,gBAAgB,GAChB,MAAMA,WAA+C;IACnDC,MAAM;IACNC,SAAS;IACTC,KAAK;IACLC,YAAY;AACd;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC;IACd,OAAO;QACLC,UAAU;YACR;gBACEC,KAAK;gBACLC,OAAO;gBACPC,QAAQT;YACV;YACA;gBAAEO,KAAK;gBAAaC,OAAO;gBAAcC,QAAQT;YAAS;YAC1D;gBACEO,KAAK;gBACLC,OAAO;gBACPC,QAAQT;YACV;SACD;IACH;AACF"}
@@ -955,10 +955,7 @@ async function staffAction(req, body, action) {
955
955
  unitAmountCents: line.unitAmountCents,
956
956
  quantity: line.quantity
957
957
  }, ((_line_modifiers = line.modifiers) == null ? void 0 : _line_modifiers.length) ? {
958
- modifiers: line.modifiers.map((modifier)=>({
959
- groupId: modifier.groupId,
960
- optionId: modifier.optionId
961
- }))
958
+ modifiers: CommerceModel.modifierSelectionOf(line.modifiers)
962
959
  } : {});
963
960
  })
964
961
  }