feeef 0.5.38-dev.1 → 0.5.38-dev.3

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/build/index.js CHANGED
@@ -315,6 +315,277 @@ var CategoryRepository = class extends ModelRepository {
315
315
  }
316
316
  };
317
317
 
318
+ // src/feeef/repositories/countries.ts
319
+ var CountryRepository = class extends ModelRepository {
320
+ /**
321
+ * Constructs a new CountryRepository instance.
322
+ * @param client The AxiosInstance used for making HTTP requests.
323
+ */
324
+ constructor(client) {
325
+ super("countries", client);
326
+ }
327
+ /**
328
+ * Finds a country by its code (ID is the country code).
329
+ * @param code - The country code (ISO 3166-1 alpha-2).
330
+ * @param params - Optional query parameters.
331
+ * @returns A Promise that resolves to the found Country entity.
332
+ */
333
+ async findByCode(code, params) {
334
+ return this.find({ id: code.toUpperCase(), params });
335
+ }
336
+ };
337
+
338
+ // src/feeef/repositories/states.ts
339
+ var StateRepository = class extends ModelRepository {
340
+ /**
341
+ * Constructs a new StateRepository instance.
342
+ * @param client The AxiosInstance used for making HTTP requests.
343
+ */
344
+ constructor(client) {
345
+ super("states", client);
346
+ }
347
+ /**
348
+ * Lists states, optionally filtered by country code.
349
+ * @param options - The options for listing states, including countryCode filter.
350
+ * @returns A Promise that resolves to a list of State entities.
351
+ */
352
+ async list(options) {
353
+ const { countryCode, ...listOptions } = options || {};
354
+ const params = {
355
+ ...listOptions.params,
356
+ ...countryCode && { country_code: countryCode }
357
+ };
358
+ return super.list({ ...listOptions, params });
359
+ }
360
+ /**
361
+ * Lists states for a specific country (nested route).
362
+ * @param countryCode - The country code.
363
+ * @param options - Optional list options.
364
+ * @returns A Promise that resolves to a list of State entities.
365
+ */
366
+ async listByCountry(countryCode, options) {
367
+ const res = await this.client.get(`/countries/${countryCode}/states`, {
368
+ params: {
369
+ page: options?.page,
370
+ offset: options?.offset,
371
+ limit: options?.limit,
372
+ ...options?.params
373
+ }
374
+ });
375
+ if (Array.isArray(res.data)) {
376
+ return { data: res.data };
377
+ } else {
378
+ return {
379
+ data: res.data.data,
380
+ total: res.data.meta.total,
381
+ page: res.data.meta.currentPage,
382
+ limit: res.data.meta.perPage
383
+ };
384
+ }
385
+ }
386
+ /**
387
+ * Finds a state by country code and state code.
388
+ * @param countryCode - The country code.
389
+ * @param stateCode - The state code.
390
+ * @param params - Optional query parameters.
391
+ * @returns A Promise that resolves to the found State entity.
392
+ */
393
+ async findByCode(countryCode, stateCode, params) {
394
+ const res = await this.client.get(`/countries/${countryCode}/states/${stateCode}`, { params });
395
+ return res.data;
396
+ }
397
+ /**
398
+ * Creates a new state (nested under country).
399
+ * @param countryCode - The country code.
400
+ * @param data - The state data.
401
+ * @param params - Optional query parameters.
402
+ * @returns A Promise that resolves to the created State entity.
403
+ */
404
+ async createByCountry(countryCode, data, params) {
405
+ const res = await this.client.post(`/countries/${countryCode}/states`, data, { params });
406
+ return res.data;
407
+ }
408
+ /**
409
+ * Updates a state (nested under country).
410
+ * @param countryCode - The country code.
411
+ * @param stateCode - The state code.
412
+ * @param data - The update data.
413
+ * @param params - Optional query parameters.
414
+ * @returns A Promise that resolves to the updated State entity.
415
+ */
416
+ async updateByCountry(countryCode, stateCode, data, params) {
417
+ const res = await this.client.put(`/countries/${countryCode}/states/${stateCode}`, data, {
418
+ params
419
+ });
420
+ return res.data;
421
+ }
422
+ /**
423
+ * Deletes a state (nested under country).
424
+ * @param countryCode - The country code.
425
+ * @param stateCode - The state code.
426
+ * @param params - Optional query parameters.
427
+ * @returns A Promise that resolves when the state is deleted.
428
+ */
429
+ async deleteByCountry(countryCode, stateCode, params) {
430
+ await this.client.delete(`/countries/${countryCode}/states/${stateCode}`, { params });
431
+ }
432
+ };
433
+
434
+ // src/feeef/repositories/cities.ts
435
+ var CityRepository = class extends ModelRepository {
436
+ /**
437
+ * Constructs a new CityRepository instance.
438
+ * @param client The AxiosInstance used for making HTTP requests.
439
+ */
440
+ constructor(client) {
441
+ super("cities", client);
442
+ }
443
+ /**
444
+ * Lists cities, optionally filtered by country code and/or state code.
445
+ * @param options - The options for listing cities, including filters.
446
+ * @returns A Promise that resolves to a list of City entities.
447
+ */
448
+ async list(options) {
449
+ const { countryCode, stateCode, ...listOptions } = options || {};
450
+ const params = {
451
+ ...listOptions.params,
452
+ ...countryCode && { country_code: countryCode },
453
+ ...stateCode && { state_code: stateCode }
454
+ };
455
+ return super.list({ ...listOptions, params });
456
+ }
457
+ /**
458
+ * Lists cities for a specific country and state (nested route).
459
+ * @param countryCode - The country code.
460
+ * @param stateCode - The state code.
461
+ * @param options - Optional list options.
462
+ * @returns A Promise that resolves to a list of City entities.
463
+ */
464
+ async listByState(countryCode, stateCode, options) {
465
+ const res = await this.client.get(`/countries/${countryCode}/states/${stateCode}/cities`, {
466
+ params: {
467
+ page: options?.page,
468
+ offset: options?.offset,
469
+ limit: options?.limit,
470
+ ...options?.params
471
+ }
472
+ });
473
+ if (Array.isArray(res.data)) {
474
+ return { data: res.data };
475
+ } else {
476
+ return {
477
+ data: res.data.data,
478
+ total: res.data.meta.total,
479
+ page: res.data.meta.currentPage,
480
+ limit: res.data.meta.perPage
481
+ };
482
+ }
483
+ }
484
+ /**
485
+ * Finds a city by country code, state code, and city name.
486
+ * @param countryCode - The country code.
487
+ * @param stateCode - The state code.
488
+ * @param cityName - The city name.
489
+ * @param params - Optional query parameters.
490
+ * @returns A Promise that resolves to the found City entity.
491
+ */
492
+ async findByName(countryCode, stateCode, cityName, params) {
493
+ const res = await this.client.get(
494
+ `/countries/${countryCode}/states/${stateCode}/cities/${cityName}`,
495
+ { params }
496
+ );
497
+ return res.data;
498
+ }
499
+ /**
500
+ * Creates a new city (nested under country/state).
501
+ * @param countryCode - The country code.
502
+ * @param stateCode - The state code.
503
+ * @param data - The city data.
504
+ * @param params - Optional query parameters.
505
+ * @returns A Promise that resolves to the created City entity.
506
+ */
507
+ async createByState(countryCode, stateCode, data, params) {
508
+ const res = await this.client.post(
509
+ `/countries/${countryCode}/states/${stateCode}/cities`,
510
+ data,
511
+ { params }
512
+ );
513
+ return res.data;
514
+ }
515
+ /**
516
+ * Updates a city (nested under country/state).
517
+ * @param countryCode - The country code.
518
+ * @param stateCode - The state code.
519
+ * @param cityName - The city name.
520
+ * @param data - The update data.
521
+ * @param params - Optional query parameters.
522
+ * @returns A Promise that resolves to the updated City entity.
523
+ */
524
+ async updateByState(countryCode, stateCode, cityName, data, params) {
525
+ const res = await this.client.put(
526
+ `/countries/${countryCode}/states/${stateCode}/cities/${cityName}`,
527
+ data,
528
+ { params }
529
+ );
530
+ return res.data;
531
+ }
532
+ /**
533
+ * Deletes a city (nested under country/state).
534
+ * @param countryCode - The country code.
535
+ * @param stateCode - The state code.
536
+ * @param cityName - The city name.
537
+ * @param params - Optional query parameters.
538
+ * @returns A Promise that resolves when the city is deleted.
539
+ */
540
+ async deleteByState(countryCode, stateCode, cityName, params) {
541
+ await this.client.delete(`/countries/${countryCode}/states/${stateCode}/cities/${cityName}`, {
542
+ params
543
+ });
544
+ }
545
+ /**
546
+ * Searches cities by name (autocomplete).
547
+ * @param query - The search query.
548
+ * @param options - Optional filters (countryCode, stateCode).
549
+ * @returns A Promise that resolves to a list of matching City entities.
550
+ */
551
+ async search(query, options) {
552
+ const params = { q: query };
553
+ if (options?.countryCode) params.country_code = options.countryCode;
554
+ if (options?.stateCode) params.state_code = options.stateCode;
555
+ const res = await this.client.get("/cities/search", { params });
556
+ return res.data;
557
+ }
558
+ };
559
+
560
+ // src/feeef/repositories/shipping_prices.ts
561
+ var ShippingPriceRepository = class extends ModelRepository {
562
+ /**
563
+ * Constructs a new ShippingPriceRepository instance.
564
+ * @param client The AxiosInstance used for making HTTP requests.
565
+ */
566
+ constructor(client) {
567
+ super("shipping_prices", client);
568
+ }
569
+ /**
570
+ * Creates a new ShippingPrice entity.
571
+ * @param options The options for creating the ShippingPrice entity.
572
+ * @returns A Promise that resolves to the created ShippingPrice entity.
573
+ */
574
+ async create(options) {
575
+ const output = options.data;
576
+ return super.create({ ...options, data: output });
577
+ }
578
+ /**
579
+ * Finds a ShippingPrice by store ID.
580
+ * @param storeId The store ID to search for.
581
+ * @returns A Promise that resolves to the ShippingPrice entities for the store.
582
+ */
583
+ async listByStore(storeId) {
584
+ const response = await this.list({ params: { storeId } });
585
+ return response.data;
586
+ }
587
+ };
588
+
318
589
  // src/core/entities/order.ts
319
590
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
320
591
  OrderStatus2["draft"] = "draft";
@@ -376,6 +647,44 @@ var ShippingMethodPolicy = /* @__PURE__ */ ((ShippingMethodPolicy2) => {
376
647
  return ShippingMethodPolicy2;
377
648
  })(ShippingMethodPolicy || {});
378
649
 
650
+ // src/core/entities/shipping_price.ts
651
+ var ShippingPriceStatus = /* @__PURE__ */ ((ShippingPriceStatus2) => {
652
+ ShippingPriceStatus2["draft"] = "draft";
653
+ ShippingPriceStatus2["published"] = "published";
654
+ return ShippingPriceStatus2;
655
+ })(ShippingPriceStatus || {});
656
+ function getShippingPrice(prices, countryCode, stateCode, type) {
657
+ const countryRates = prices[countryCode];
658
+ if (!countryRates) return null;
659
+ const stateRates = countryRates[stateCode];
660
+ if (!stateRates) return null;
661
+ return stateRates[type] ?? null;
662
+ }
663
+ function isShippingAvailable(prices, countryCode, stateCode) {
664
+ const countryRates = prices[countryCode];
665
+ if (!countryRates) return false;
666
+ const stateRates = countryRates[stateCode];
667
+ if (!stateRates) return false;
668
+ return stateRates.home !== null || stateRates.desk !== null || stateRates.pickup !== null;
669
+ }
670
+ function getAvailableShippingTypes(prices, countryCode, stateCode) {
671
+ const countryRates = prices[countryCode];
672
+ if (!countryRates) return [];
673
+ const stateRates = countryRates[stateCode];
674
+ if (!stateRates) return [];
675
+ const available = [];
676
+ if (stateRates.home !== null) {
677
+ available.push({ type: "home", price: stateRates.home });
678
+ }
679
+ if (stateRates.desk !== null) {
680
+ available.push({ type: "desk", price: stateRates.desk });
681
+ }
682
+ if (stateRates.pickup !== null) {
683
+ available.push({ type: "pickup", price: stateRates.pickup });
684
+ }
685
+ return available;
686
+ }
687
+
379
688
  // src/feeef/services/service.ts
380
689
  var NotifiableService = class {
381
690
  // Array of listeners (functions) to notify when changes occur
@@ -422,6 +731,10 @@ var CartService = class extends NotifiableService {
422
731
  items = [];
423
732
  // Array to support multiple items with same product but different variants
424
733
  shippingMethod = null;
734
+ shippingPrice = null;
735
+ // New shipping price system
736
+ store = null;
737
+ // Store entity for accessing shippingPriceId
425
738
  shippingAddress = {
426
739
  name: null,
427
740
  phone: null,
@@ -773,6 +1086,7 @@ var CartService = class extends NotifiableService {
773
1086
  const store = method?.defaultShippingRates ? method : null;
774
1087
  const shippingMethod = method?.rates ? method : null;
775
1088
  if (store) {
1089
+ this.store = store;
776
1090
  this.shippingMethod = {
777
1091
  id: store.id,
778
1092
  name: store.name,
@@ -804,25 +1118,231 @@ var CartService = class extends NotifiableService {
804
1118
  throw new Error("Invalid shipping method");
805
1119
  }
806
1120
  }
807
- // getAvailableShippingTypes
808
1121
  /**
809
- * Retrieves the available shipping types for the current shipping method.
1122
+ * Sets the shipping price (new system).
1123
+ * @param shippingPrice - The shipping price entity.
1124
+ * @param notify - Whether to notify listeners.
1125
+ */
1126
+ setShippingPrice(shippingPrice, notify = true) {
1127
+ this.shippingPrice = shippingPrice;
1128
+ if (notify) {
1129
+ this.notify();
1130
+ }
1131
+ }
1132
+ /**
1133
+ * Sets the store entity.
1134
+ * @param store - The store entity.
1135
+ * @param notify - Whether to notify listeners.
1136
+ */
1137
+ setStore(store, notify = true) {
1138
+ this.store = store;
1139
+ if (notify) {
1140
+ this.notify();
1141
+ }
1142
+ }
1143
+ /**
1144
+ * Maps ShippingType enum to ShippingPriceType string.
1145
+ * @param shippingType - The shipping type enum.
1146
+ * @returns The corresponding shipping price type.
1147
+ */
1148
+ mapShippingTypeToPriceType(shippingType) {
1149
+ switch (shippingType) {
1150
+ case "home" /* home */:
1151
+ return "home";
1152
+ case "pickup" /* pickup */:
1153
+ return "pickup";
1154
+ case "store" /* store */:
1155
+ return "desk";
1156
+ default:
1157
+ return "home";
1158
+ }
1159
+ }
1160
+ /**
1161
+ * Resolves shipping price using the priority chain.
1162
+ * Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
1163
+ *
1164
+ * Note: Shipping prices must be loaded and set via setShippingPrice() for the new system to work.
1165
+ * If shipping prices are not loaded, the method falls back to the legacy system.
1166
+ *
1167
+ * @param countryCode - ISO 3166-1 alpha-2 country code (optional, required for new system)
1168
+ * @param stateCode - State/province code
1169
+ * @param shippingType - The shipping type
1170
+ * @returns The shipping price or null if not available
1171
+ */
1172
+ resolveShippingPrice(countryCode, stateCode, shippingType) {
1173
+ if (!stateCode) return null;
1174
+ const priceType = this.mapShippingTypeToPriceType(shippingType);
1175
+ const allProducts = [...this.items];
1176
+ if (this.currentItem && !this.hasItem(this.currentItem)) {
1177
+ allProducts.push(this.currentItem);
1178
+ }
1179
+ console.log("[resolveShippingPrice]", {
1180
+ countryCode,
1181
+ stateCode,
1182
+ shippingType,
1183
+ priceType,
1184
+ hasShippingPrice: !!this.shippingPrice,
1185
+ shippingPriceId: this.shippingPrice?.id,
1186
+ allProductsCount: allProducts.length
1187
+ });
1188
+ if (countryCode && this.shippingPrice) {
1189
+ const productShippingPriceIds = allProducts.map((item) => item.product.shippingPriceId).filter((id) => id !== null);
1190
+ console.log("[resolveShippingPrice] Product shippingPriceIds:", productShippingPriceIds);
1191
+ if (productShippingPriceIds.length > 0) {
1192
+ const uniqueIds = new Set(productShippingPriceIds);
1193
+ if (uniqueIds.size === 1 && this.shippingPrice.id === productShippingPriceIds[0]) {
1194
+ console.log(
1195
+ "[resolveShippingPrice] Using product shippingPriceId:",
1196
+ productShippingPriceIds[0]
1197
+ );
1198
+ const price = getShippingPrice(
1199
+ this.shippingPrice.prices,
1200
+ countryCode,
1201
+ stateCode,
1202
+ priceType
1203
+ );
1204
+ console.log("[resolveShippingPrice] Product price result:", price);
1205
+ if (price !== null) {
1206
+ return price;
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1211
+ if (countryCode && this.store?.shippingPriceId && this.shippingPrice && this.shippingPrice.id === this.store.shippingPriceId) {
1212
+ console.log("[resolveShippingPrice] Using store shippingPriceId:", this.store.shippingPriceId);
1213
+ const price = getShippingPrice(
1214
+ this.shippingPrice.prices,
1215
+ countryCode,
1216
+ stateCode,
1217
+ priceType
1218
+ );
1219
+ console.log("[resolveShippingPrice] Store price result:", price);
1220
+ if (price !== null) {
1221
+ return price;
1222
+ }
1223
+ }
1224
+ const productShippingMethodIds = allProducts.map((item) => item.product.shippingMethodId).filter((id) => id !== null);
1225
+ if (productShippingMethodIds.length > 0) {
1226
+ const uniqueIds = new Set(productShippingMethodIds);
1227
+ if (uniqueIds.size === 1 && this.shippingMethod && this.shippingMethod.id === productShippingMethodIds[0]) {
1228
+ const legacyPrice = this.getShippingPriceForTypeLegacy(shippingType);
1229
+ if (legacyPrice !== null) {
1230
+ return legacyPrice;
1231
+ }
1232
+ }
1233
+ }
1234
+ if (this.shippingMethod?.rates) {
1235
+ console.log("[resolveShippingPrice] Falling back to legacy system");
1236
+ const legacyPrice = this.getShippingPriceForTypeLegacy(shippingType);
1237
+ console.log("[resolveShippingPrice] Legacy price result:", legacyPrice);
1238
+ return legacyPrice;
1239
+ }
1240
+ console.log("[resolveShippingPrice] No shipping price found, returning null");
1241
+ return null;
1242
+ }
1243
+ /**
1244
+ * Gets shipping price using legacy system (array-based rates).
1245
+ * @param type - The shipping type
1246
+ * @returns The shipping price or null if not available
1247
+ */
1248
+ getShippingPriceForTypeLegacy(type) {
1249
+ if (!this.shippingMethod?.rates || !this.shippingAddress.state) return null;
1250
+ const stateIndex = Number.parseInt(this.shippingAddress.state, 10) - 1;
1251
+ const rates = this.shippingMethod.rates[stateIndex];
1252
+ if (!rates) return null;
1253
+ switch (type) {
1254
+ case "pickup" /* pickup */:
1255
+ return rates[0];
1256
+ case "home" /* home */:
1257
+ return rates[1];
1258
+ case "store" /* store */:
1259
+ return rates[2];
1260
+ default:
1261
+ return null;
1262
+ }
1263
+ }
1264
+ /**
1265
+ * Retrieves the available shipping types using the priority chain.
1266
+ * Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
810
1267
  *
811
- * rates is a 2D array for example `[[10, 20, 30], [5, 10, 15]]`
812
- * where the first array is for `home` fees and the second is for `pickup` fees, and the third is for `store` fees
813
- * if the fee value is 0, then it's free shipping, and if it's null, then it's not available
1268
+ * Note: Shipping prices must be loaded and set via setShippingPrice() for the new system to work.
1269
+ * If shipping prices are not loaded, the method falls back to the legacy system.
814
1270
  *
815
1271
  * @returns An array of available shipping types.
816
1272
  */
817
1273
  getAvailableShippingTypes() {
1274
+ if (!this.shippingAddress.state) return [];
1275
+ let countryCode;
1276
+ if (this.shippingAddress.country && this.shippingAddress.country.toLowerCase() !== "dz") {
1277
+ countryCode = this.shippingAddress.country.toUpperCase();
1278
+ } else if (this.store?.configs?.selectedCountry) {
1279
+ countryCode = this.store.configs.selectedCountry.toUpperCase();
1280
+ } else {
1281
+ countryCode = void 0;
1282
+ }
1283
+ const allProducts = [...this.items];
1284
+ if (this.currentItem && !this.hasItem(this.currentItem)) {
1285
+ allProducts.push(this.currentItem);
1286
+ }
1287
+ if (countryCode && this.shippingPrice) {
1288
+ const productShippingPriceIds = allProducts.map((item) => item.product.shippingPriceId).filter((id) => id !== null);
1289
+ if (productShippingPriceIds.length > 0) {
1290
+ const uniqueIds = new Set(productShippingPriceIds);
1291
+ if (uniqueIds.size === 1 && this.shippingPrice.id === productShippingPriceIds[0]) {
1292
+ const available = getAvailableShippingTypes(
1293
+ this.shippingPrice.prices,
1294
+ countryCode,
1295
+ this.shippingAddress.state
1296
+ );
1297
+ if (available.length > 0) {
1298
+ return available.map((a) => {
1299
+ switch (a.type) {
1300
+ case "home":
1301
+ return "home" /* home */;
1302
+ case "pickup":
1303
+ return "pickup" /* pickup */;
1304
+ case "desk":
1305
+ return "store" /* store */;
1306
+ default:
1307
+ return "home" /* home */;
1308
+ }
1309
+ });
1310
+ }
1311
+ }
1312
+ }
1313
+ }
1314
+ if (countryCode && this.store?.shippingPriceId && this.shippingPrice && this.shippingPrice.id === this.store.shippingPriceId) {
1315
+ const available = getAvailableShippingTypes(
1316
+ this.shippingPrice.prices,
1317
+ countryCode,
1318
+ this.shippingAddress.state
1319
+ );
1320
+ if (available.length > 0) {
1321
+ return available.map((a) => {
1322
+ switch (a.type) {
1323
+ case "home":
1324
+ return "home" /* home */;
1325
+ case "pickup":
1326
+ return "pickup" /* pickup */;
1327
+ case "desk":
1328
+ return "store" /* store */;
1329
+ default:
1330
+ return "home" /* home */;
1331
+ }
1332
+ });
1333
+ }
1334
+ }
818
1335
  if (!this.shippingMethod?.rates) return [];
819
- var state = Number.parseInt(this.shippingAddress.state);
820
- var stateRates = this.shippingMethod.rates[state - 1];
1336
+ const state = Number.parseInt(this.shippingAddress.state, 10);
1337
+ const stateRates = this.shippingMethod.rates[state - 1];
821
1338
  if (!stateRates) return [];
822
- var availableTypes = [];
823
- if (stateRates[0] || stateRates[0] === 0) availableTypes.push("pickup" /* pickup */);
824
- if (stateRates[1] || stateRates[1] === 0) availableTypes.push("home" /* home */);
825
- if (stateRates[2] || stateRates[2] === 0) availableTypes.push("store" /* store */);
1339
+ const availableTypes = [];
1340
+ if (stateRates[0] !== null && stateRates[0] !== void 0)
1341
+ availableTypes.push("pickup" /* pickup */);
1342
+ if (stateRates[1] !== null && stateRates[1] !== void 0)
1343
+ availableTypes.push("home" /* home */);
1344
+ if (stateRates[2] !== null && stateRates[2] !== void 0)
1345
+ availableTypes.push("store" /* store */);
826
1346
  return availableTypes;
827
1347
  }
828
1348
  /**
@@ -856,43 +1376,71 @@ var CartService = class extends NotifiableService {
856
1376
  * @returns The shipping price or 0 if not applicable.
857
1377
  */
858
1378
  getShippingPrice() {
859
- for (const item of this.items) {
1379
+ const allItems = [...this.items];
1380
+ if (this.currentItem && !this.hasItem(this.currentItem)) {
1381
+ allItems.push(this.currentItem);
1382
+ }
1383
+ for (const item of allItems) {
860
1384
  if (item.offer?.freeShipping) return 0;
861
1385
  }
862
1386
  if (!this.shippingMethod) return 0;
863
1387
  if (!this.shippingAddress.state) return this.shippingMethod.price ?? 0;
864
1388
  const shippings = this.getAvailableShippingTypes();
865
1389
  const currentOne = this.getShippingPriceForType(this.shippingAddress.type);
866
- if (currentOne) {
1390
+ if (currentOne !== null) {
867
1391
  return currentOne;
868
1392
  }
869
1393
  for (const type of shippings) {
870
- if (this.getShippingPriceForType(type) !== null) {
871
- return this.getShippingPriceForType(type);
1394
+ const price = this.getShippingPriceForType(type);
1395
+ if (price !== null) {
1396
+ return price;
872
1397
  }
873
1398
  }
874
1399
  return 0;
875
1400
  }
876
1401
  /**
877
- * Gets the shipping price for a specific shipping type using the current shipping address state.
1402
+ * Gets the shipping price for a specific shipping type using the priority chain.
1403
+ * Priority: 1. Product shippingPriceId, 2. Store shippingPriceId, 3. Product shippingMethodId, 4. Store defaultShippingRates
878
1404
  * @param type - The shipping type to check (pickup, home, store)
879
1405
  * @returns The shipping price for the specified type, or null if not available
880
1406
  */
881
1407
  getShippingPriceForType(type) {
882
- if (!this.shippingMethod?.rates || !this.shippingAddress.state) return null;
883
- const stateIndex = Number.parseInt(this.shippingAddress.state, 10) - 1;
884
- const rates = this.shippingMethod.rates[stateIndex];
885
- if (!rates) return null;
886
- switch (type) {
887
- case "pickup" /* pickup */:
888
- return rates[0];
889
- case "home" /* home */:
890
- return rates[1];
891
- case "store" /* store */:
892
- return rates[2];
893
- default:
894
- return null;
1408
+ if (!this.shippingAddress.state) {
1409
+ console.log("[getShippingPriceForType] No state, returning null");
1410
+ return null;
895
1411
  }
1412
+ let countryCode;
1413
+ if (this.shippingAddress.country && this.shippingAddress.country.toLowerCase() !== "dz") {
1414
+ countryCode = this.shippingAddress.country.toUpperCase();
1415
+ } else if (this.store?.configs?.selectedCountry) {
1416
+ countryCode = this.store.configs.selectedCountry.toUpperCase();
1417
+ } else {
1418
+ countryCode = void 0;
1419
+ }
1420
+ console.log("[getShippingPriceForType]", {
1421
+ type,
1422
+ state: this.shippingAddress.state,
1423
+ country: this.shippingAddress.country,
1424
+ countryCode,
1425
+ storeSelectedCountry: this.store?.configs?.selectedCountry,
1426
+ hasShippingPrice: !!this.shippingPrice,
1427
+ shippingPriceId: this.shippingPrice?.id
1428
+ });
1429
+ if (countryCode) {
1430
+ const newSystemPrice = this.resolveShippingPrice(
1431
+ countryCode,
1432
+ this.shippingAddress.state,
1433
+ type
1434
+ );
1435
+ if (newSystemPrice !== null) {
1436
+ console.log("[getShippingPriceForType] New system price:", newSystemPrice);
1437
+ return newSystemPrice;
1438
+ }
1439
+ }
1440
+ console.log("[getShippingPriceForType] Falling back to legacy system");
1441
+ const legacyPrice = this.getShippingPriceForTypeLegacy(type);
1442
+ console.log("[getShippingPriceForType] Legacy price:", legacyPrice);
1443
+ return legacyPrice;
896
1444
  }
897
1445
  /**
898
1446
  * Calculates the total cost of the cart including shipping.
@@ -1011,6 +1559,22 @@ var FeeeF = class {
1011
1559
  * The repository for managing categories.
1012
1560
  */
1013
1561
  categories;
1562
+ /**
1563
+ * The repository for managing countries.
1564
+ */
1565
+ countries;
1566
+ /**
1567
+ * The repository for managing states.
1568
+ */
1569
+ states;
1570
+ /**
1571
+ * The repository for managing cities.
1572
+ */
1573
+ cities;
1574
+ /**
1575
+ * The repository for managing shipping prices.
1576
+ */
1577
+ shippingPrices;
1014
1578
  /**
1015
1579
  * The cart service for managing the cart.
1016
1580
  */
@@ -1039,6 +1603,10 @@ var FeeeF = class {
1039
1603
  this.orders = new OrderRepository(this.client);
1040
1604
  this.deposits = new DepositRepository(this.client);
1041
1605
  this.categories = new CategoryRepository(this.client);
1606
+ this.countries = new CountryRepository(this.client);
1607
+ this.states = new StateRepository(this.client);
1608
+ this.cities = new CityRepository(this.client);
1609
+ this.shippingPrices = new ShippingPriceRepository(this.client);
1042
1610
  this.cart = new CartService();
1043
1611
  this.actions = new ActionsService(this.client);
1044
1612
  }
@@ -1413,6 +1981,8 @@ export {
1413
1981
  ProductVariantView,
1414
1982
  ShippingMethodPolicy,
1415
1983
  ShippingMethodStatus,
1984
+ ShippingPriceRepository,
1985
+ ShippingPriceStatus,
1416
1986
  ShippingType,
1417
1987
  StoreActionType,
1418
1988
  StoreMemberRole,
@@ -1441,6 +2011,9 @@ export {
1441
2011
  generatePublicStoreIntegrationTiktokPixel,
1442
2012
  generatePublicStoreIntegrationWebhooks,
1443
2013
  generatePublicStoreIntegrations,
2014
+ getAvailableShippingTypes,
2015
+ getShippingPrice,
2016
+ isShippingAvailable,
1444
2017
  tryFixPhoneNumber,
1445
2018
  validatePhoneNumber
1446
2019
  };