@ancon/wildcat-utils 1.48.0 → 1.49.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.
@@ -1 +1 @@
1
- "use strict";const l=/(\/{.+?})/g,c=/[/{}]/g;function f(s,t){const o={url:s,params:t??{}};if(!t)return o;const n=s.match(l);return n!=null&&n.length?n.reduce((e,p)=>{const r=p.replace(c,""),g=t[r];return g?(delete e.params[r],e.url=e.url.replace(new RegExp(p,"g"),`/${g}`)):e.params[r]=t[r],e},{url:s,params:{...t}}):o}module.exports=f;
1
+ "use strict";const l=/(\/{.+?})/g,c=/[/{}]/g;function f(s,t){const p={url:s,params:t??{}};if(!t)return p;const n=s.match(l);return n!=null&&n.length?n.reduce((e,g)=>{const r=g.replace(c,""),o=t[r];return!o&&o!==0?e.params[r]=t[r]:(delete e.params[r],e.url=e.url.replace(new RegExp(g,"g"),`/${o}`)),e},{url:s,params:{...t}}):p}module.exports=f;
@@ -1,22 +1,22 @@
1
1
  const f = /(\/{.+?})/g, g = /[/{}]/g;
2
2
  function a(o, e) {
3
- const s = { url: o, params: e ?? {} };
3
+ const l = { url: o, params: e ?? {} };
4
4
  if (!e)
5
- return s;
5
+ return l;
6
6
  const t = o.match(f);
7
7
  return t != null && t.length ? t.reduce(
8
- (n, l) => {
9
- const r = l.replace(g, ""), p = e[r];
10
- return p ? (delete n.params[r], n.url = n.url.replace(
11
- new RegExp(l, "g"),
12
- `/${p}`
13
- )) : n.params[r] = e[r], n;
8
+ (n, p) => {
9
+ const r = p.replace(g, ""), s = e[r];
10
+ return !s && s !== 0 ? n.params[r] = e[r] : (delete n.params[r], n.url = n.url.replace(
11
+ new RegExp(p, "g"),
12
+ `/${s}`
13
+ )), n;
14
14
  },
15
15
  {
16
16
  url: o,
17
17
  params: { ...e }
18
18
  }
19
- ) : s;
19
+ ) : l;
20
20
  }
21
21
  export {
22
22
  a as default
@@ -1 +1 @@
1
- "use strict";const t=require("@ancon/wildcat-types");function o(d){const n=[];return d.selectedIngredients.forEach(e=>{e.selected?e.replacementId&&n.push({modification:t.ModificationType.Replace,ingredientId:e.id,replaceId:e.replacementId}):n.push({modification:t.ModificationType.Remove,ingredientId:e.id})}),d.selectedAddons.forEach(e=>{if(e.selectedIngredientId){n.push({addOnGroupId:e.addonId,modification:t.ModificationType.Add,ingredientId:e.selectedIngredientId,quantity:1,freeAmount:e.ingredients.some(i=>i.freeAmount===1)?1:0});return}e.ingredients.forEach(i=>{i.selectedCount&&n.push({addOnGroupId:e.addonId,modification:t.ModificationType.Add,ingredientId:i.id,quantity:i.selectedCount,freeAmount:i.freeAmount})})}),{modifications:n,quantity:d.quantity,variantId:d.selectedVariantId,showingPrice:d.selectedVariantShowingPrice}}module.exports=o;
1
+ "use strict";const n=require("@ancon/wildcat-types");function s(i){const t=[],o=[];return i.selectedIngredients.forEach(e=>{e.selected?e.replacementId&&t.push({modification:n.ModificationType.Replace,ingredientId:e.id,replaceId:e.replacementId}):t.push({modification:n.ModificationType.Remove,ingredientId:e.id})}),i.selectedAddons.forEach(e=>{var c;if(e.selectedIngredientId){t.push({addOnGroupId:e.addonId,modification:n.ModificationType.Add,ingredientId:e.selectedIngredientId,quantity:1,freeAmount:e.ingredients.some(d=>d.freeAmount===1)?1:0});return}e.ingredients.forEach(d=>{d.selectedCount&&t.push({addOnGroupId:e.addonId,modification:n.ModificationType.Add,ingredientId:d.id,quantity:d.selectedCount,freeAmount:d.freeAmount})}),(c=e.products)==null||c.forEach(d=>{d.selectedCount&&o.push({variantId:d.selectedVariantId,addOnGroupId:e.addonId,quantity:d.selectedCount,freeAmount:d.freeAmount,unitQuantity:d.selectedCount})})}),{modifications:t,quantity:i.quantity,variantId:i.selectedVariantId,showingPrice:i.selectedVariantShowingPrice,addOnProducts:o}}module.exports=s;
@@ -1,20 +1,21 @@
1
- import { ModificationType as t } from "@ancon/wildcat-types";
2
- function o(i) {
3
- const n = [];
4
- return i.selectedIngredients.forEach((e) => {
5
- e.selected ? e.replacementId && n.push({
6
- modification: t.Replace,
1
+ import { ModificationType as n } from "@ancon/wildcat-types";
2
+ function r(t) {
3
+ const i = [], o = [];
4
+ return t.selectedIngredients.forEach((e) => {
5
+ e.selected ? e.replacementId && i.push({
6
+ modification: n.Replace,
7
7
  ingredientId: e.id,
8
8
  replaceId: e.replacementId
9
- }) : n.push({
10
- modification: t.Remove,
9
+ }) : i.push({
10
+ modification: n.Remove,
11
11
  ingredientId: e.id
12
12
  });
13
- }), i.selectedAddons.forEach((e) => {
13
+ }), t.selectedAddons.forEach((e) => {
14
+ var s;
14
15
  if (e.selectedIngredientId) {
15
- n.push({
16
+ i.push({
16
17
  addOnGroupId: e.addonId,
17
- modification: t.Add,
18
+ modification: n.Add,
18
19
  ingredientId: e.selectedIngredientId,
19
20
  quantity: 1,
20
21
  freeAmount: e.ingredients.some((d) => d.freeAmount === 1) ? 1 : 0
@@ -22,21 +23,30 @@ function o(i) {
22
23
  return;
23
24
  }
24
25
  e.ingredients.forEach((d) => {
25
- d.selectedCount && n.push({
26
+ d.selectedCount && i.push({
26
27
  addOnGroupId: e.addonId,
27
- modification: t.Add,
28
+ modification: n.Add,
28
29
  ingredientId: d.id,
29
30
  quantity: d.selectedCount,
30
31
  freeAmount: d.freeAmount
31
32
  });
33
+ }), (s = e.products) == null || s.forEach((d) => {
34
+ d.selectedCount && o.push({
35
+ variantId: d.selectedVariantId,
36
+ addOnGroupId: e.addonId,
37
+ quantity: d.selectedCount,
38
+ freeAmount: d.freeAmount,
39
+ unitQuantity: d.selectedCount
40
+ });
32
41
  });
33
42
  }), {
34
- modifications: n,
35
- quantity: i.quantity,
36
- variantId: i.selectedVariantId,
37
- showingPrice: i.selectedVariantShowingPrice
43
+ modifications: i,
44
+ quantity: t.quantity,
45
+ variantId: t.selectedVariantId,
46
+ showingPrice: t.selectedVariantShowingPrice,
47
+ addOnProducts: o
38
48
  };
39
49
  }
40
50
  export {
41
- o as default
51
+ r as default
42
52
  };
@@ -7,6 +7,13 @@ export declare type CheckoutRequestItemModification = {
7
7
  addOnGroupId?: string;
8
8
  replaceId?: string;
9
9
  };
10
+ export declare type CheckoutRequestItemAddOnProduct = {
11
+ variantId: string;
12
+ addOnGroupId: string;
13
+ quantity: number;
14
+ freeAmount: number;
15
+ unitQuantity: number;
16
+ };
10
17
  export declare type CheckoutRequestItem = {
11
18
  variantId?: string;
12
19
  variantType?: VariantType;
@@ -14,6 +21,7 @@ export declare type CheckoutRequestItem = {
14
21
  productType?: ProductType;
15
22
  quantity: number;
16
23
  modifications: CheckoutRequestItemModification[];
24
+ addOnProducts?: CheckoutRequestItemAddOnProduct[];
17
25
  upsellGroupId?: string | null;
18
26
  showingPrice?: number;
19
27
  price?: CheckoutRequestItemUnitPrice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.48.0",
3
+ "version": "1.49.0",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",