shopoflex-types 1.0.184 → 1.0.186

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.
package/dist/common.d.ts CHANGED
@@ -356,7 +356,7 @@ export interface Vendor {
356
356
  };
357
357
  allowCustomPricing?: boolean;
358
358
  pixelsOptions?: PixelsOptions;
359
- taxManagement?: TaxManagement;
359
+ taxManagement?: TaxConfig;
360
360
  currentPlan?: {
361
361
  planDiscount?: any;
362
362
  planId?: IPlanPackage;
@@ -617,14 +617,18 @@ export interface successResponse {
617
617
  }
618
618
  export type Industry = "restaurant" | "grocery" | "retail" | "pharmacy" | "services";
619
619
  export interface TaxConfig {
620
- active: boolean;
621
- show: boolean;
622
- payer: 'vendor' | 'customer';
623
- percentage: number;
624
- }
625
- export interface TaxManagement {
626
- type: 'perCountry' | 'fixed';
627
- fixed: TaxConfig;
628
- perCountry: Record<string, TaxConfig>;
620
+ type: "fixed" | "perCountry";
621
+ fixed?: {
622
+ active: boolean;
623
+ show: boolean;
624
+ payer: "vendor" | "customer";
625
+ percentage: number;
626
+ };
627
+ perCountry?: Record<string, {
628
+ active: boolean;
629
+ show: boolean;
630
+ payer: "vendor" | "customer";
631
+ percentage: number;
632
+ }>;
629
633
  }
630
634
  export {};
package/dist/samples.d.ts CHANGED
@@ -1,21 +1,6 @@
1
- import { Address, Discount, IZone } from "./common";
2
- import { CartItem } from "./productCart";
3
- export interface SampleTaxConfig {
4
- type: "fixed" | "perCountry";
5
- fixed?: {
6
- active: boolean;
7
- show: boolean;
8
- payer: "vendor" | "customer";
9
- percentage: number;
10
- };
11
- perCountry?: Record<string, {
12
- active: boolean;
13
- show: boolean;
14
- payer: "vendor" | "customer";
15
- percentage: number;
16
- }>;
17
- }
18
- export declare const calculateCartTotalsWithDiscounts: (items: CartItem[], deliveryFee: number, allDiscounts: Discount[], manualDiscount?: Discount, vendorTaxConfig?: SampleTaxConfig, customerAddress?: Address | any) => {
1
+ import { Address, Discount, FileType, IZone, TaxConfig } from "./common";
2
+ import { CartItem, ProductType, sModifier, VariantType } from "./productCart";
3
+ export declare const calculateCartTotalsWithDiscounts: (items: CartItem[], deliveryFee: number, allDiscounts: Discount[], manualDiscount?: Discount, vendorTaxConfig?: TaxConfig, customerAddress?: Address | any, deliveryFeeOverride?: number, discountOverride?: number) => {
19
4
  items: CartItem[];
20
5
  subtotal: number;
21
6
  totalQuantity: number;
@@ -38,3 +23,13 @@ export declare const calculateDeliveryFeeForZones: (zones: IZone[], location: {
38
23
  fee: number;
39
24
  isValid: boolean;
40
25
  }>;
26
+ export declare const getImageUrl: (imageId?: string, vendorId?: string, params?: string) => string;
27
+ export declare const getImageZero: (files?: FileType[], vendorId?: string, params?: string) => string;
28
+ export declare const getAvailableStock: (product: ProductType, branchId?: string, variant?: null) => number;
29
+ export declare const calculateModifiersTotal: (selectedModifiers?: sModifier[]) => number;
30
+ export declare const calculateItemPrices: (vartiant: VariantType, selectedModifiers?: sModifier[], quantity?: number) => {
31
+ unitPrice: number;
32
+ totalPrice: number;
33
+ basePrice: number;
34
+ modifiersPrice: number;
35
+ };
package/dist/samples.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateDeliveryFeeForZones = exports.calculateCartTotalsWithDiscounts = void 0;
4
- const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manualDiscount, vendorTaxConfig, customerAddress) => {
3
+ exports.calculateItemPrices = exports.calculateModifiersTotal = exports.getAvailableStock = exports.getImageZero = exports.getImageUrl = exports.calculateDeliveryFeeForZones = exports.calculateCartTotalsWithDiscounts = void 0;
4
+ const defaultImage = "https://firebasestorage.googleapis.com/v0/b/navori-s.firebasestorage.app/o/picture.png?alt=media";
5
+ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manualDiscount, vendorTaxConfig, customerAddress, deliveryFeeOverride, discountOverride) => {
5
6
  // Calculate initial totals for each item
6
7
  const itemsWithTotals = items.map((item) => {
7
8
  const basePrice = item.selectedVariant?.priceModel?.price || 0;
@@ -18,14 +19,16 @@ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manu
18
19
  });
19
20
  const subtotal = itemsWithTotals.reduce((sum, item) => sum + (item.totalPrice ?? 0), 0);
20
21
  const totalQuantity = itemsWithTotals.reduce((sum, item) => sum + item.quantity, 0);
22
+ // Use delivery fee override if provided, otherwise use normal delivery fee
23
+ const finalDeliveryFee = deliveryFeeOverride !== undefined ? deliveryFeeOverride : deliveryFee;
21
24
  // Create base cart for discount calculations
22
25
  const baseCart = {
23
26
  items: itemsWithTotals,
24
27
  subtotal,
25
28
  totalQuantity,
26
- delivery: deliveryFee,
29
+ delivery: finalDeliveryFee,
27
30
  discount: 0,
28
- total: subtotal + deliveryFee,
31
+ total: subtotal + finalDeliveryFee,
29
32
  };
30
33
  // Apply discounts and get updated cart
31
34
  const applyDiscounts = (cart, allDiscounts, manualDiscount) => {
@@ -260,7 +263,25 @@ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manu
260
263
  totalDiscount: cappedCartLevelDiscountAmount + deliveryDiscountAmount,
261
264
  };
262
265
  };
263
- const { updatedCart, totalDiscount } = applyDiscounts(baseCart, allDiscounts, manualDiscount);
266
+ // Apply discount override if provided, otherwise calculate discounts normally
267
+ let updatedCart;
268
+ let totalDiscount;
269
+ if (discountOverride !== undefined) {
270
+ // Use discount override (percentage) - skip all discount calculations
271
+ const overrideDiscountAmount = (subtotal * discountOverride) / 100;
272
+ updatedCart = {
273
+ ...baseCart,
274
+ discount: overrideDiscountAmount,
275
+ total: Math.max(0, subtotal - overrideDiscountAmount + finalDeliveryFee),
276
+ };
277
+ totalDiscount = overrideDiscountAmount;
278
+ }
279
+ else {
280
+ // Apply normal discount calculations
281
+ const result = applyDiscounts(baseCart, allDiscounts, manualDiscount);
282
+ updatedCart = result.updatedCart;
283
+ totalDiscount = result.totalDiscount;
284
+ }
264
285
  // Calculate vendor tax if configuration is provided
265
286
  let taxInfo = {
266
287
  taxAmount: 0,
@@ -415,3 +436,47 @@ const calculateDeliveryFeeForZones = async (zones, location, mapkey) => {
415
436
  return { fee: totalFee, isValid };
416
437
  };
417
438
  exports.calculateDeliveryFeeForZones = calculateDeliveryFeeForZones;
439
+ const getImageUrl = (imageId = '', vendorId = '', params = "w=400") => {
440
+ if (!vendorId || !imageId)
441
+ return defaultImage;
442
+ const baseurl = "https://shopoflex.imgix.net/files/";
443
+ return baseurl + vendorId + "/" + imageId + "?" + params;
444
+ };
445
+ exports.getImageUrl = getImageUrl;
446
+ const getImageZero = (files = [], vendorId = '', params = "w=400") => {
447
+ if (files && files.length > 0) {
448
+ return (0, exports.getImageUrl)(files[0]?.name, vendorId, params);
449
+ }
450
+ else {
451
+ return defaultImage;
452
+ }
453
+ };
454
+ exports.getImageZero = getImageZero;
455
+ const getAvailableStock = (product, branchId, variant = null) => {
456
+ const v = variant || product.variants[0];
457
+ if (!v.stockHandle?.active || !branchId) {
458
+ return Infinity;
459
+ }
460
+ const branchStock = v.stockHandle.stockByBranch[branchId];
461
+ return branchStock?.stockQuantity || 0;
462
+ };
463
+ exports.getAvailableStock = getAvailableStock;
464
+ const calculateModifiersTotal = (selectedModifiers = []) => {
465
+ return selectedModifiers.reduce((total, modifier) => {
466
+ const modifierTotal = modifier.options?.reduce((optionSum, option) => {
467
+ const price = option.price || 0;
468
+ const quantity = option.quantity || 0;
469
+ return optionSum + (price * quantity);
470
+ }, 0) || 0;
471
+ return total + modifierTotal;
472
+ }, 0);
473
+ };
474
+ exports.calculateModifiersTotal = calculateModifiersTotal;
475
+ const calculateItemPrices = (vartiant, selectedModifiers = [], quantity = 1) => {
476
+ const basePrice = vartiant.priceModel.price || 0;
477
+ const modifiersPrice = (0, exports.calculateModifiersTotal)(selectedModifiers || []);
478
+ const unitPrice = basePrice + modifiersPrice;
479
+ const totalPrice = unitPrice * quantity;
480
+ return { unitPrice, totalPrice, basePrice, modifiersPrice };
481
+ };
482
+ exports.calculateItemPrices = calculateItemPrices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopoflex-types",
3
- "version": "1.0.184",
3
+ "version": "1.0.186",
4
4
  "description": "Shared TypeScript types for Shopoflex applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",