@lyxa.ai/core 1.0.256 → 1.0.257

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.
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.0.256
25
+ Version: 1.0.257
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.0.256",
3
+ "version": "1.0.257",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -0,0 +1,4 @@
1
+ import { PipelineStage } from 'mongoose';
2
+ export declare function addProductMarketingInfo(exchangeRate: number, secondaryCurrencyRoundTo: number, secondaryCurrencyName: string): PipelineStage[];
3
+ export declare function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number, secondaryCurrencyRoundTo: number): PipelineStage;
4
+ export declare function addDiscountAmountsToPriceBreakdowns(): PipelineStage;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProductMarketingInfo = addProductMarketingInfo;
4
+ exports.addSecondaryCurrencyToPriceBreakdowns = addSecondaryCurrencyToPriceBreakdowns;
5
+ exports.addDiscountAmountsToPriceBreakdowns = addDiscountAmountsToPriceBreakdowns;
6
+ const common_pipeline_functions_1 = require("./common-pipeline-functions");
7
+ const enum_1 = require("../enum");
8
+ function addProductMarketingInfo(exchangeRate, secondaryCurrencyRoundTo, secondaryCurrencyName) {
9
+ return [
10
+ {
11
+ $lookup: {
12
+ from: 'productMarketings',
13
+ let: { productId: '$_id', now: new Date() },
14
+ pipeline: [
15
+ {
16
+ $match: {
17
+ $expr: { $eq: ['$product', '$$productId'] },
18
+ },
19
+ },
20
+ {
21
+ $lookup: {
22
+ from: 'marketings',
23
+ localField: 'marketing',
24
+ foreignField: '_id',
25
+ as: 'marketing',
26
+ },
27
+ },
28
+ {
29
+ $unwind: '$marketing',
30
+ },
31
+ {
32
+ $match: {
33
+ $expr: {
34
+ $and: [
35
+ { $eq: ['$marketing.status', 'active'] },
36
+ { $eq: ['$marketing.pausedAt', null] },
37
+ { $lte: ['$marketing.duration.start', '$$now'] },
38
+ { $gte: ['$marketing.duration.end', '$$now'] },
39
+ ],
40
+ },
41
+ },
42
+ },
43
+ {
44
+ $addFields: {
45
+ secondaryCurrencyValue: {
46
+ $cond: [
47
+ { $eq: ['$valueType', 'fixed'] },
48
+ (0, common_pipeline_functions_1.getSecondaryCurrencyStage)({
49
+ valuePath: '$value',
50
+ exchangeRate,
51
+ roundTo: secondaryCurrencyRoundTo,
52
+ }),
53
+ '$$REMOVE',
54
+ ],
55
+ },
56
+ },
57
+ },
58
+ {
59
+ $addFields: {
60
+ label: {
61
+ $switch: {
62
+ branches: [
63
+ {
64
+ case: { $eq: ['$marketing.marketingType', enum_1.MarketingType.BUY1GET1] },
65
+ then: 'Buy 1 Get 1',
66
+ },
67
+ {
68
+ case: { $eq: ['$marketing.marketingType', enum_1.MarketingType.PUNCH_MARKETING] },
69
+ then: 'Punch',
70
+ },
71
+ {
72
+ case: { $eq: ['$marketing.marketingType', enum_1.MarketingType.DISCOUNT] },
73
+ then: {
74
+ $switch: {
75
+ branches: [
76
+ {
77
+ case: { $eq: ['$valueType', enum_1.ValueType.FIXED] },
78
+ then: {
79
+ $concat: [
80
+ secondaryCurrencyName,
81
+ ' ',
82
+ { $toString: '$secondaryCurrencyValue' },
83
+ ],
84
+ },
85
+ },
86
+ {
87
+ case: { $eq: ['$valueType', enum_1.ValueType.PERCENTAGE] },
88
+ then: {
89
+ $concat: [{ $toString: '$value' }, '%'],
90
+ },
91
+ },
92
+ ],
93
+ default: 'Discount',
94
+ },
95
+ },
96
+ },
97
+ ],
98
+ default: '$marketing.marketingType',
99
+ },
100
+ },
101
+ },
102
+ },
103
+ {
104
+ $project: {
105
+ marketing: '$marketing._id',
106
+ loyaltyPointCategory: '$loyaltyPointCategory',
107
+ isBuy1Get1: '$isBuy1Get1',
108
+ valueType: '$valueType',
109
+ value: '$value',
110
+ secondaryCurrencyValue: '$secondaryCurrencyValue',
111
+ label: '$label',
112
+ },
113
+ },
114
+ ],
115
+ as: 'productMarketing',
116
+ },
117
+ },
118
+ {
119
+ $unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },
120
+ },
121
+ ];
122
+ }
123
+ function addSecondaryCurrencyToPriceBreakdowns(exchangeRate, secondaryCurrencyRoundTo) {
124
+ return {
125
+ $addFields: {
126
+ priceBreakdowns: {
127
+ $map: {
128
+ input: '$priceBreakdowns',
129
+ as: 'breakdown',
130
+ in: {
131
+ $mergeObjects: [
132
+ '$$breakdown',
133
+ {
134
+ secondaryPrice: (0, common_pipeline_functions_1.getSecondaryCurrencyStage)({
135
+ valuePath: '$$breakdown.price',
136
+ exchangeRate,
137
+ roundTo: secondaryCurrencyRoundTo,
138
+ }),
139
+ secondaryDiscountAmount: {
140
+ $cond: [
141
+ { $gt: ['$productMarketing', null] },
142
+ (0, common_pipeline_functions_1.getSecondaryCurrencyStage)({
143
+ valuePath: '$$breakdown.discountAmount',
144
+ exchangeRate,
145
+ roundTo: secondaryCurrencyRoundTo,
146
+ }),
147
+ '$$REMOVE',
148
+ ],
149
+ },
150
+ secondaryDiscountedPrice: {
151
+ $cond: [
152
+ { $gt: ['$productMarketing', null] },
153
+ (0, common_pipeline_functions_1.getSecondaryCurrencyStage)({
154
+ valuePath: '$$breakdown.discountedPrice',
155
+ exchangeRate,
156
+ roundTo: secondaryCurrencyRoundTo,
157
+ }),
158
+ '$$REMOVE',
159
+ ],
160
+ },
161
+ },
162
+ ],
163
+ },
164
+ },
165
+ },
166
+ },
167
+ };
168
+ }
169
+ function addDiscountAmountsToPriceBreakdowns() {
170
+ return {
171
+ $addFields: {
172
+ priceBreakdowns: {
173
+ $map: {
174
+ input: '$priceBreakdowns',
175
+ as: 'breakdown',
176
+ in: {
177
+ $mergeObjects: [
178
+ '$$breakdown',
179
+ {
180
+ discountAmount: {
181
+ $cond: [
182
+ { $gt: ['$productMarketing', null] },
183
+ {
184
+ $cond: [
185
+ { $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
186
+ '$productMarketing.value',
187
+ {
188
+ $multiply: [
189
+ '$productMarketing.value',
190
+ {
191
+ $divide: ['$$breakdown.price', 100],
192
+ },
193
+ ],
194
+ },
195
+ ],
196
+ },
197
+ '$$REMOVE',
198
+ ],
199
+ },
200
+ discountedPrice: {
201
+ $cond: [
202
+ { $gt: ['$productMarketing', null] },
203
+ {
204
+ $subtract: [
205
+ '$$breakdown.price',
206
+ {
207
+ $cond: [
208
+ { $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
209
+ '$productMarketing.value',
210
+ {
211
+ $multiply: [
212
+ '$productMarketing.value',
213
+ {
214
+ $divide: ['$$breakdown.price', 100],
215
+ },
216
+ ],
217
+ },
218
+ ],
219
+ },
220
+ ],
221
+ },
222
+ '$$REMOVE',
223
+ ],
224
+ },
225
+ },
226
+ ],
227
+ },
228
+ },
229
+ },
230
+ },
231
+ };
232
+ }
233
+ //# sourceMappingURL=product-pipeline-stages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-pipeline-stages.js","sourceRoot":"/","sources":["utilities/pipelines/product-pipeline-stages.ts"],"names":[],"mappings":";;AAIA,0DAuHC;AAED,sFAgDC;AAED,kFAkEC;AAhPD,2EAAwE;AACxE,kCAAmD;AAEnD,SAAgB,uBAAuB,CACtC,YAAoB,EACpB,wBAAgC,EAChC,qBAA6B;IAE7B,OAAO;QACN;YACC,OAAO,EAAE;gBACR,IAAI,EAAE,mBAAmB;gBACzB,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;gBAC3C,QAAQ,EAAE;oBACT;wBACC,MAAM,EAAE;4BACP,KAAK,EAAE,EAAE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AE;wCACN,EAAE,GAAG,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,EAAE;wCACpC;4CACC,SAAS,EAAE;gDACV,mBAAmB;gDACnB;oDACC,KAAK,EAAE;wDACN,EAAE,GAAG,EAAE,CAAC,6BAA6B,EAAE,gBAAS,CAAC,KAAK,CAAC,EAAE;wDACzD,yBAAyB;wDACzB;4DACC,SAAS,EAAE;gEACV,yBAAyB;gEACzB;oEACC,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,CAAC;iEACnC;6DACD;yDACD;qDACD;iDACD;6CACD;yCACD;wCACD,UAAU;qCACV;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { PipelineStage } from 'mongoose';\nimport { getSecondaryCurrencyStage } from './common-pipeline-functions';\nimport { MarketingType, ValueType } from '../enum';\n\nexport function addProductMarketingInfo(\n\texchangeRate: number,\n\tsecondaryCurrencyRoundTo: number,\n\tsecondaryCurrencyName: string\n): PipelineStage[] {\n\treturn [\n\t\t{\n\t\t\t$lookup: {\n\t\t\t\tfrom: 'productMarketings',\n\t\t\t\tlet: { productId: '$_id', now: new Date() },\n\t\t\t\tpipeline: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: { $eq: ['$product', '$$productId'] },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'marketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$unwind: '$marketing',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.status', 'active'] },\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.pausedAt', null] },\n\t\t\t\t\t\t\t\t\t{ $lte: ['$marketing.duration.start', '$$now'] },\n\t\t\t\t\t\t\t\t\t{ $gte: ['$marketing.duration.end', '$$now'] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Compute and add secondary currency values to coupon documents\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tsecondaryCurrencyValue: {\n\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$valueType', 'fixed'] },\n\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\tvaluePath: '$value',\n\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tlabel: {\n\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.BUY1GET1] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Buy 1 Get 1',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.PUNCH_MARKETING] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Punch',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.DISCOUNT] },\n\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsecondaryCurrencyName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $toString: '$secondaryCurrencyValue' },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.PERCENTAGE] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [{ $toString: '$value' }, '%'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefault: 'Discount',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tdefault: '$marketing.marketingType',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\tmarketing: '$marketing._id',\n\t\t\t\t\t\t\tloyaltyPointCategory: '$loyaltyPointCategory',\n\t\t\t\t\t\t\tisBuy1Get1: '$isBuy1Get1',\n\t\t\t\t\t\t\tvalueType: '$valueType',\n\t\t\t\t\t\t\tvalue: '$value',\n\t\t\t\t\t\t\tsecondaryCurrencyValue: '$secondaryCurrencyValue',\n\t\t\t\t\t\t\tlabel: '$label',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tas: 'productMarketing',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t$unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },\n\t\t},\n\t];\n}\n\nexport function addSecondaryCurrencyToPriceBreakdowns(\n\texchangeRate: number,\n\tsecondaryCurrencyRoundTo: number\n): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsecondaryPrice: getSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.price',\n\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tsecondaryDiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.discountAmount',\n\t\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsecondaryDiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.discountedPrice',\n\t\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function addDiscountAmountsToPriceBreakdowns(): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$$breakdown.price', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Add discounted price\n\t\t\t\t\t\t\t\tdiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$$breakdown.price', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.0.256",
3
+ "version": "1.0.257",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",