@adtrackify/at-service-common 3.19.24 → 3.19.25

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 (61) hide show
  1. package/dist/cjs/__tests__/db/products-db-service.spec.d.ts +1 -0
  2. package/dist/cjs/__tests__/db/products-db-service.spec.js +90 -0
  3. package/dist/cjs/__tests__/db/products-db-service.spec.js.map +1 -0
  4. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -0
  5. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js +24 -0
  6. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -0
  7. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -0
  8. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +207 -0
  9. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -0
  10. package/dist/cjs/services/cost/index.d.ts +1 -0
  11. package/dist/cjs/services/cost/index.js +1 -0
  12. package/dist/cjs/services/cost/index.js.map +1 -1
  13. package/dist/cjs/services/cost/order-cost/index.d.ts +2 -0
  14. package/dist/cjs/services/cost/order-cost/index.js +19 -0
  15. package/dist/cjs/services/cost/order-cost/index.js.map +1 -0
  16. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -0
  17. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js +362 -0
  18. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js.map +1 -0
  19. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.d.ts +37 -0
  20. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.js +3 -0
  21. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.js.map +1 -0
  22. package/dist/cjs/services/db/index.d.ts +2 -0
  23. package/dist/cjs/services/db/index.js +2 -0
  24. package/dist/cjs/services/db/index.js.map +1 -1
  25. package/dist/cjs/services/db/products-db-service-types.d.ts +10 -0
  26. package/dist/cjs/services/db/products-db-service-types.js +3 -0
  27. package/dist/cjs/services/db/products-db-service-types.js.map +1 -0
  28. package/dist/cjs/services/db/products-db-service.d.ts +19 -0
  29. package/dist/cjs/services/db/products-db-service.js +282 -0
  30. package/dist/cjs/services/db/products-db-service.js.map +1 -0
  31. package/dist/esm/__tests__/db/products-db-service.spec.d.ts +1 -0
  32. package/dist/esm/__tests__/db/products-db-service.spec.js +88 -0
  33. package/dist/esm/__tests__/db/products-db-service.spec.js.map +1 -0
  34. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -0
  35. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js +22 -0
  36. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -0
  37. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -0
  38. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +205 -0
  39. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -0
  40. package/dist/esm/services/cost/index.d.ts +1 -0
  41. package/dist/esm/services/cost/index.js +1 -0
  42. package/dist/esm/services/cost/index.js.map +1 -1
  43. package/dist/esm/services/cost/order-cost/index.d.ts +2 -0
  44. package/dist/esm/services/cost/order-cost/index.js +3 -0
  45. package/dist/esm/services/cost/order-cost/index.js.map +1 -0
  46. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -0
  47. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js +356 -0
  48. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js.map +1 -0
  49. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.d.ts +37 -0
  50. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.js +2 -0
  51. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.js.map +1 -0
  52. package/dist/esm/services/db/index.d.ts +2 -0
  53. package/dist/esm/services/db/index.js +2 -0
  54. package/dist/esm/services/db/index.js.map +1 -1
  55. package/dist/esm/services/db/products-db-service-types.d.ts +10 -0
  56. package/dist/esm/services/db/products-db-service-types.js +2 -0
  57. package/dist/esm/services/db/products-db-service-types.js.map +1 -0
  58. package/dist/esm/services/db/products-db-service.d.ts +19 -0
  59. package/dist/esm/services/db/products-db-service.js +278 -0
  60. package/dist/esm/services/db/products-db-service.js.map +1 -0
  61. package/package.json +1 -1
@@ -0,0 +1,362 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OrderCostResolutionService = void 0;
7
+ const big_js_1 = __importDefault(require("big.js"));
8
+ const luxon_1 = require("luxon");
9
+ const logging_helper_js_1 = require("../../../helpers/logging-helper.js");
10
+ const cost_calculator_service_js_1 = require("../cost-calculator-service.js");
11
+ const EMPTY_ORDER_COST_RESULT = {
12
+ orderLevelHandlingCost: 0,
13
+ lineItemLevelHandlingCost: 0,
14
+ totalHandlingCost: 0,
15
+ orderLevelOtherCost: 0,
16
+ lineItemLevelOtherCost: 0,
17
+ totalOtherCost: 0,
18
+ totalGatewayCost: 0,
19
+ totalShippingCost: 0,
20
+ lineItemCosts: {},
21
+ categoryCosts: {
22
+ totalOtherCogs: 0,
23
+ otherFulfillmentCost: 0,
24
+ otherTransactionCost: 0,
25
+ marketingCost: 0,
26
+ agencyFeesCost: 0,
27
+ opexCost: 0,
28
+ totalOtherCost: 0,
29
+ },
30
+ };
31
+ exports.OrderCostResolutionService = {
32
+ selectCostHistoryRecordForOrderDate: (costHistory, orderCreatedAt) => {
33
+ try {
34
+ if (!costHistory || costHistory.length === 0) {
35
+ return null;
36
+ }
37
+ if (!orderCreatedAt) {
38
+ return null;
39
+ }
40
+ const orderDateTime = luxon_1.DateTime.fromISO(orderCreatedAt).toUTC();
41
+ if (!orderDateTime.isValid) {
42
+ return null;
43
+ }
44
+ const validCostHistory = costHistory.filter(entry => luxon_1.DateTime.fromISO(entry.effectiveStartDate).isValid);
45
+ if (validCostHistory.length === 0) {
46
+ return null;
47
+ }
48
+ const sortedCostHistory = [...validCostHistory].sort((a, b) => {
49
+ const dateA = luxon_1.DateTime.fromISO(a.effectiveStartDate);
50
+ const dateB = luxon_1.DateTime.fromISO(b.effectiveStartDate);
51
+ return dateA.toMillis() - dateB.toMillis();
52
+ });
53
+ for (const costRecord of sortedCostHistory) {
54
+ const effectiveStartDate = luxon_1.DateTime.fromISO(costRecord.effectiveStartDate);
55
+ if (orderDateTime >= effectiveStartDate) {
56
+ if (costRecord.effectiveEndDate === null) {
57
+ return costRecord;
58
+ }
59
+ const effectiveEndDate = luxon_1.DateTime.fromISO(costRecord.effectiveEndDate);
60
+ if (!effectiveEndDate.isValid) {
61
+ continue;
62
+ }
63
+ if (orderDateTime <= effectiveEndDate) {
64
+ return costRecord;
65
+ }
66
+ }
67
+ }
68
+ return sortedCostHistory.length > 0 ? sortedCostHistory[0] : null;
69
+ }
70
+ catch (error) {
71
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.selectCostHistoryRecordForOrderDate: failed', { error, orderCreatedAt });
72
+ return null;
73
+ }
74
+ },
75
+ isValidCost: (cost) => {
76
+ try {
77
+ return typeof cost === 'number' && !Number.isNaN(cost) && cost >= 0 && cost <= 1000000;
78
+ }
79
+ catch (error) {
80
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.isValidCost: failed', { error, cost });
81
+ return false;
82
+ }
83
+ },
84
+ resolveOrderLineItemUnitCosts: (lineItems, pixelId, orderCreatedAt, variantRecords, costConfigsByPixelId) => {
85
+ const result = {};
86
+ try {
87
+ const defaultCogsPercent = costConfigsByPixelId[pixelId]?.globalProductOverride?.defaultCogs;
88
+ let resolvedFromHistoryCount = 0;
89
+ let defaultCogsFallbackCount = 0;
90
+ for (const li of lineItems) {
91
+ const lineItemId = String(li.id);
92
+ const productId = li.product_id ? String(li.product_id) : '';
93
+ const variantId = li.variant_id ? String(li.variant_id) : '';
94
+ const variantKey = `${pixelId}_${productId}_${variantId}`;
95
+ const variantRecord = variantRecords[variantKey];
96
+ const lineItemPrice = li.price ? parseFloat(li.price) : 0;
97
+ const lineItemQuantity = li.quantity ?? 1;
98
+ if (variantRecord) {
99
+ const costHistory = variantRecord.shopifyCostHistory ?? [];
100
+ const applicableCostRecord = exports.OrderCostResolutionService.selectCostHistoryRecordForOrderDate(costHistory, orderCreatedAt);
101
+ if (applicableCostRecord?.cost !== undefined) {
102
+ const cost = applicableCostRecord.cost;
103
+ if (cost > 0 && exports.OrderCostResolutionService.isValidCost(cost)) {
104
+ result[lineItemId] = cost;
105
+ resolvedFromHistoryCount++;
106
+ continue;
107
+ }
108
+ }
109
+ }
110
+ if (typeof defaultCogsPercent === 'number' && defaultCogsPercent >= 0 && defaultCogsPercent <= 100) {
111
+ if (lineItemPrice > 0 && lineItemQuantity > 0) {
112
+ const grossSalePrice = new big_js_1.default(lineItemPrice).times(lineItemQuantity);
113
+ const totalCost = grossSalePrice.times(defaultCogsPercent).div(100);
114
+ const unitCost = totalCost.div(lineItemQuantity).toNumber();
115
+ if (exports.OrderCostResolutionService.isValidCost(unitCost)) {
116
+ result[lineItemId] = unitCost;
117
+ defaultCogsFallbackCount++;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ logging_helper_js_1.Logger.debug('OrderCostResolutionService.resolveOrderLineItemUnitCosts: complete', {
123
+ totalLineItems: lineItems.length,
124
+ resolvedFromHistory: resolvedFromHistoryCount,
125
+ defaultCogsFallback: defaultCogsFallbackCount,
126
+ totalResolved: Object.keys(result).length,
127
+ });
128
+ return result;
129
+ }
130
+ catch (error) {
131
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.resolveOrderLineItemUnitCosts: failed', { error, pixelId });
132
+ return result;
133
+ }
134
+ },
135
+ getOrderCreatedAt: (order, useProcessedAtForNonWebOrders = false) => {
136
+ try {
137
+ const isNonWebOrder = order.source_name !== 'web';
138
+ const shouldOverrideCreatedAt = useProcessedAtForNonWebOrders && isNonWebOrder;
139
+ if (shouldOverrideCreatedAt) {
140
+ return order?.processed_at ?? order?.created_at;
141
+ }
142
+ return order?.created_at;
143
+ }
144
+ catch (error) {
145
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getOrderCreatedAt: failed', { error, order });
146
+ return order?.created_at;
147
+ }
148
+ },
149
+ getGrossSalePrice: (order) => {
150
+ try {
151
+ let grossSalePrice = 0;
152
+ order?.line_items?.forEach((lineItem) => {
153
+ const lineItemPrice = parseFloat(lineItem?.price ?? '0');
154
+ const quantity = lineItem?.quantity ?? 0;
155
+ const lineItemSalePrice = lineItemPrice * quantity;
156
+ if (lineItemSalePrice) {
157
+ grossSalePrice += lineItemSalePrice;
158
+ }
159
+ });
160
+ return grossSalePrice;
161
+ }
162
+ catch (error) {
163
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getGrossSalePrice: failed', { error });
164
+ return undefined;
165
+ }
166
+ },
167
+ getTotalRefundsFromOrder: (order) => {
168
+ try {
169
+ const sumBig = (values) => values.reduce((acc, v) => acc.plus(v), new big_js_1.default(0));
170
+ const refundAmounts = order?.refunds?.map((refund) => {
171
+ const refunds = refund?.transactions?.map((t) => {
172
+ if (t.status === 'success' && t.amount) {
173
+ const receipt = t?.receipt;
174
+ const exchangeRate = receipt?.balance_transaction?.exchange_rate;
175
+ if (exchangeRate) {
176
+ return new big_js_1.default(t.amount).times(exchangeRate).div(100);
177
+ }
178
+ else {
179
+ return new big_js_1.default(t.amount);
180
+ }
181
+ }
182
+ else {
183
+ return new big_js_1.default(0);
184
+ }
185
+ });
186
+ return sumBig(refunds ?? []);
187
+ });
188
+ const refund = sumBig(refundAmounts ?? []).toFixed(2);
189
+ return parseFloat(refund);
190
+ }
191
+ catch (error) {
192
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getTotalRefundsFromOrder: failed', { error });
193
+ return 0;
194
+ }
195
+ },
196
+ getNetSalePrice: (order) => {
197
+ try {
198
+ let netSalePrice;
199
+ const grossSalePrice = exports.OrderCostResolutionService.getGrossSalePrice(order);
200
+ const totalRefunds = exports.OrderCostResolutionService.getTotalRefundsFromOrder(order);
201
+ let totalDiscounts = 0;
202
+ if (order?.total_discounts_set?.shop_money?.amount) {
203
+ totalDiscounts = parseFloat(order?.total_discounts_set?.shop_money?.amount ?? '0');
204
+ }
205
+ if (grossSalePrice) {
206
+ netSalePrice = grossSalePrice - (totalRefunds + totalDiscounts);
207
+ }
208
+ return netSalePrice;
209
+ }
210
+ catch (error) {
211
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getNetSalePrice: failed', { error });
212
+ return undefined;
213
+ }
214
+ },
215
+ getTotalProductCost: (order, lineItemUnitCosts) => {
216
+ try {
217
+ let totalProductCost = new big_js_1.default(0);
218
+ let hasValidCosts = false;
219
+ order?.line_items?.forEach((lineItem) => {
220
+ const lineItemId = lineItem.id !== undefined ? String(lineItem.id) : '';
221
+ if (!lineItemId)
222
+ return;
223
+ const unitCost = lineItemUnitCosts[lineItemId];
224
+ if (unitCost !== undefined) {
225
+ const quantity = lineItem.quantity ?? 0;
226
+ totalProductCost = totalProductCost.plus(new big_js_1.default(unitCost).times(quantity));
227
+ hasValidCosts = true;
228
+ }
229
+ });
230
+ return hasValidCosts ? new big_js_1.default(totalProductCost.toFixed(2)).toNumber() : undefined;
231
+ }
232
+ catch (error) {
233
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getTotalProductCost: failed', { error });
234
+ return undefined;
235
+ }
236
+ },
237
+ getLineItemsRefundInfo: (order) => {
238
+ try {
239
+ const lineItemRefunds = {};
240
+ order?.line_items?.forEach((li) => {
241
+ if (li.id !== undefined) {
242
+ lineItemRefunds[li.id] = {
243
+ hasRefund: false,
244
+ refundQuantity: 0,
245
+ refundAmount: 0,
246
+ };
247
+ }
248
+ });
249
+ order?.refunds?.forEach((refund) => {
250
+ let totalRefundAmount = 0;
251
+ refund?.transactions?.forEach((transaction) => {
252
+ if (transaction.status === 'success' && transaction.amount) {
253
+ totalRefundAmount += parseFloat(transaction.amount);
254
+ }
255
+ });
256
+ refund?.refund_line_items?.forEach((refundLineItem) => {
257
+ if (refundLineItem.line_item_id === undefined)
258
+ return;
259
+ const target = lineItemRefunds[refundLineItem.line_item_id];
260
+ if (!target)
261
+ return;
262
+ target.hasRefund = true;
263
+ target.refundQuantity += refundLineItem?.quantity ?? 0;
264
+ const lineItemRefundAmount = parseFloat(String(refundLineItem?.subtotal ?? '0')) + parseFloat(String(refundLineItem?.total_tax ?? '0'));
265
+ if (totalRefundAmount >= lineItemRefundAmount) {
266
+ target.refundAmount += lineItemRefundAmount;
267
+ totalRefundAmount -= lineItemRefundAmount;
268
+ }
269
+ });
270
+ });
271
+ return lineItemRefunds;
272
+ }
273
+ catch (error) {
274
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.getLineItemsRefundInfo: failed', { error });
275
+ return {};
276
+ }
277
+ },
278
+ buildOrderCostContext: (params) => {
279
+ const { pixelId, order, variantRecords, productRecords, orderCreatedAt, refundInfoByLineItemId, saleTotals } = params;
280
+ const orderTags = order?.tags?.split(',').map((t) => t.trim()).filter(Boolean) ?? [];
281
+ const paymentGateways = order?.payment_gateway_names ?? [];
282
+ const shippingTitles = (order?.shipping_lines?.map((s) => s.title).filter(Boolean) ?? []);
283
+ const shipCountryCode = order?.shipping_address?.country_code;
284
+ const orderFilterContext = {
285
+ tags: orderTags,
286
+ sourceName: order?.source_name,
287
+ paymentGateways,
288
+ shippingTitles,
289
+ shipCountryCode,
290
+ };
291
+ const lineItems = (order?.line_items ?? []).map((li) => {
292
+ const productId = li?.product_id ? String(li.product_id) : '';
293
+ const variantId = li?.variant_id ? String(li.variant_id) : '';
294
+ const variantKey = `${pixelId}_${productId}_${variantId}`;
295
+ const productKey = `${pixelId}_${productId}`;
296
+ const variantRecord = variantRecords[variantKey];
297
+ const productRecord = productRecords[productKey];
298
+ const filterContext = {
299
+ vendor: variantRecord?.vendor,
300
+ productType: variantRecord?.productType,
301
+ tags: variantRecord?.tags ?? [],
302
+ category: productRecord?.product?.category?.fullName,
303
+ productId,
304
+ variantId,
305
+ };
306
+ const lineItemId = li.id !== undefined ? String(li.id) : '';
307
+ return {
308
+ lineItemId,
309
+ quantity: li.quantity ?? 0,
310
+ refundedQuantity: lineItemId ? (refundInfoByLineItemId?.[lineItemId]?.refundQuantity ?? 0) : 0,
311
+ filterContext,
312
+ variantHandlingFee: variantRecord?.handlingFee,
313
+ };
314
+ });
315
+ const totalWeight = order?.total_weight ?? 0;
316
+ const totalQuantity = lineItems.reduce((sum, li) => sum + li.quantity, 0);
317
+ const shopifyShippingAmount = parseFloat(String(order?.total_shipping_price_set?.shop_money?.amount ?? '0'));
318
+ return {
319
+ orderCreatedAt: orderCreatedAt ?? order?.created_at ?? '',
320
+ totalPrice: parseFloat(String(order?.total_price_set?.shop_money?.amount ?? '0')),
321
+ grossSalePrice: saleTotals?.grossSalePrice ?? 0,
322
+ netSalePrice: saleTotals?.netSalePrice ?? 0,
323
+ totalProductCost: saleTotals?.totalProductCost ?? 0,
324
+ totalShipping: shopifyShippingAmount,
325
+ totalWeight,
326
+ totalQuantity,
327
+ hasRefund: (order?.refunds?.length ?? 0) > 0,
328
+ orderFilterContext,
329
+ lineItems,
330
+ };
331
+ },
332
+ computeOrderCostResult: (params) => {
333
+ const { pixelId, order, variantRecords, productRecords, costConfigs, exchangeRatesMap, useProcessedAtForNonWebOrders } = params;
334
+ try {
335
+ const orderCurrency = params.orderCurrency ?? order?.currency ?? '';
336
+ const orderCreatedAt = exports.OrderCostResolutionService.getOrderCreatedAt(order, useProcessedAtForNonWebOrders) ?? order?.created_at ?? '';
337
+ const costConfigsByPixelId = costConfigs ? { [pixelId]: costConfigs } : {};
338
+ const lineItemUnitCosts = exports.OrderCostResolutionService.resolveOrderLineItemUnitCosts(order?.line_items ?? [], pixelId, orderCreatedAt, variantRecords, costConfigsByPixelId);
339
+ const saleTotals = {
340
+ grossSalePrice: exports.OrderCostResolutionService.getGrossSalePrice(order) ?? 0,
341
+ netSalePrice: exports.OrderCostResolutionService.getNetSalePrice(order) ?? 0,
342
+ totalProductCost: exports.OrderCostResolutionService.getTotalProductCost(order, lineItemUnitCosts) ?? 0,
343
+ };
344
+ const refundInfoByLineItemId = exports.OrderCostResolutionService.getLineItemsRefundInfo(order);
345
+ const context = exports.OrderCostResolutionService.buildOrderCostContext({
346
+ pixelId,
347
+ order,
348
+ variantRecords,
349
+ productRecords,
350
+ orderCreatedAt,
351
+ refundInfoByLineItemId,
352
+ saleTotals,
353
+ });
354
+ return cost_calculator_service_js_1.CostCalculatorService.calculateOrderCosts(costConfigs, context, orderCurrency, exchangeRatesMap);
355
+ }
356
+ catch (error) {
357
+ logging_helper_js_1.Logger.error('OrderCostResolutionService.computeOrderCostResult: failed', { error, pixelId, orderId: order?.id });
358
+ return EMPTY_ORDER_COST_RESULT;
359
+ }
360
+ },
361
+ };
362
+ //# sourceMappingURL=order-cost-resolution-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-cost-resolution-service.js","sourceRoot":"","sources":["../../../../../src/services/cost/order-cost/order-cost-resolution-service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAyB;AACzB,iCAAiC;AAEjC,0EAA4D;AAW5D,8EAAsE;AAOtE,MAAM,uBAAuB,GAAoB;IAC/C,sBAAsB,EAAE,CAAC;IACzB,yBAAyB,EAAE,CAAC;IAC5B,iBAAiB,EAAE,CAAC;IACpB,mBAAmB,EAAE,CAAC;IACtB,sBAAsB,EAAE,CAAC;IACzB,cAAc,EAAE,CAAC;IACjB,gBAAgB,EAAE,CAAC;IACnB,iBAAiB,EAAE,CAAC;IACpB,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE;QACb,cAAc,EAAE,CAAC;QACjB,oBAAoB,EAAE,CAAC;QACvB,oBAAoB,EAAE,CAAC;QACvB,aAAa,EAAE,CAAC;QAChB,cAAc,EAAE,CAAC;QACjB,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,CAA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KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;YAClH,OAAO,uBAAuB,CAAC;SAChC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type ProductRecord, type ProductVariantRecord } from '@adtrackify/at-tracking-event-types';
2
+ import { ShopifyRest } from '../../../types/index.js';
3
+ import { type CostConfigsBundle } from '../cost-calculation-types.js';
4
+ import { type ExchangeRatesMap } from '../cost-currency-service.js';
5
+ export interface LineItemRefundInfo {
6
+ hasRefund: boolean;
7
+ refundQuantity: number;
8
+ refundAmount: number;
9
+ }
10
+ export type LineItemsRefundInfo = Record<string, LineItemRefundInfo>;
11
+ export type RefundInfoByLineItemId = Record<string, {
12
+ refundQuantity?: number;
13
+ } | undefined>;
14
+ export interface OrderSaleTotals {
15
+ grossSalePrice?: number;
16
+ netSalePrice?: number;
17
+ totalProductCost?: number;
18
+ }
19
+ export interface BuildOrderCostContextParams {
20
+ pixelId: string;
21
+ order: ShopifyRest.IOrder;
22
+ variantRecords: Record<string, ProductVariantRecord>;
23
+ productRecords: Record<string, ProductRecord>;
24
+ orderCreatedAt: string;
25
+ refundInfoByLineItemId: RefundInfoByLineItemId;
26
+ saleTotals: OrderSaleTotals;
27
+ }
28
+ export interface ComputeOrderCostResultParams {
29
+ pixelId: string;
30
+ order: ShopifyRest.IOrder;
31
+ variantRecords: Record<string, ProductVariantRecord>;
32
+ productRecords: Record<string, ProductRecord>;
33
+ costConfigs: CostConfigsBundle | null;
34
+ exchangeRatesMap: ExchangeRatesMap;
35
+ orderCurrency?: string;
36
+ useProcessedAtForNonWebOrders?: boolean;
37
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=order-cost-resolution-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-cost-resolution-types.js","sourceRoot":"","sources":["../../../../../src/services/cost/order-cost/order-cost-resolution-types.ts"],"names":[],"mappings":""}
@@ -15,3 +15,5 @@ export * from './subscriptions-db-service.js';
15
15
  export * from './user-accounts-db-service.js';
16
16
  export * from './api-keys-db-service.js';
17
17
  export * from './custom-measures-db-service.js';
18
+ export * from './products-db-service.js';
19
+ export * from './products-db-service-types.js';
@@ -31,4 +31,6 @@ __exportStar(require("./subscriptions-db-service.js"), exports);
31
31
  __exportStar(require("./user-accounts-db-service.js"), exports);
32
32
  __exportStar(require("./api-keys-db-service.js"), exports);
33
33
  __exportStar(require("./custom-measures-db-service.js"), exports);
34
+ __exportStar(require("./products-db-service.js"), exports);
35
+ __exportStar(require("./products-db-service-types.js"), exports);
34
36
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,6DAA2C;AAC3C,yDAAuC;AACvC,uEAAqD;AACrD,gEAA8C;AAC9C,sEAAoD;AACpD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD;AACrD,iEAA+C;AAC/C,uEAAqD;AACrD,0EAAwD;AACxD,2DAAyC;AACzC,gEAA8C;AAC9C,gEAA8C;AAC9C,2DAAyC;AACzC,kEAAgD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,6DAA2C;AAC3C,yDAAuC;AACvC,uEAAqD;AACrD,gEAA8C;AAC9C,sEAAoD;AACpD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD;AACrD,iEAA+C;AAC/C,uEAAqD;AACrD,0EAAwD;AACxD,2DAAyC;AACzC,gEAA8C;AAC9C,gEAA8C;AAC9C,2DAAyC;AACzC,kEAAgD;AAChD,2DAAyC;AACzC,iEAA+C"}
@@ -0,0 +1,10 @@
1
+ export interface BatchPutResult<T> {
2
+ successfulRecords: T[];
3
+ failedRecords: T[];
4
+ }
5
+ export interface BatchGetOptions {
6
+ concurrency?: number;
7
+ }
8
+ export interface BatchPutOptions {
9
+ concurrency?: number;
10
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=products-db-service-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"products-db-service-types.js","sourceRoot":"","sources":["../../../../src/services/db/products-db-service-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { type ProductRecord, type ProductVariantRecord } from '@adtrackify/at-tracking-event-types';
2
+ import { type BatchGetOptions, type BatchPutOptions, type BatchPutResult } from './products-db-service-types.js';
3
+ export declare class ProductsDbService {
4
+ TABLE_NAME: string;
5
+ TABLE_KEY: string;
6
+ constructor(tableName: string, tableKey: string);
7
+ buildVariantPk: (pixelId: string, productId: string, variantId: string) => string;
8
+ buildProductPk: (pixelId: string, productId: string) => string;
9
+ getVariant: (pixelId: string, productId: string, variantId: string) => Promise<ProductVariantRecord | null>;
10
+ putVariant: (record: ProductVariantRecord) => Promise<ProductVariantRecord | null>;
11
+ batchPutVariants: (records: ProductVariantRecord[], options?: BatchPutOptions) => Promise<BatchPutResult<ProductVariantRecord>>;
12
+ batchGetVariants: (pixelIdProductIdVariantIds: string[], options?: BatchGetOptions) => Promise<ProductVariantRecord[]>;
13
+ batchGetVariantsMap: (pixelIdProductIdVariantIds: string[], options?: BatchGetOptions) => Promise<Record<string, ProductVariantRecord>>;
14
+ getProduct: (pixelId: string, productId: string) => Promise<ProductRecord | null>;
15
+ putProduct: (record: ProductRecord) => Promise<ProductRecord | null>;
16
+ batchGetProducts: (pixelIdProductIds: string[], options?: BatchGetOptions) => Promise<ProductRecord[]>;
17
+ batchGetProductsMap: (pixelIdProductIds: string[], options?: BatchGetOptions) => Promise<Record<string, ProductRecord>>;
18
+ batchPutProducts: (records: ProductRecord[], options?: BatchPutOptions) => Promise<BatchPutResult<ProductRecord>>;
19
+ }