@medusajs/fulfillment 3.0.0-preview-20250410180148 → 3.0.0-preview-20251201152819

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 (64) hide show
  1. package/dist/loaders/providers.d.ts.map +1 -1
  2. package/dist/loaders/providers.js +1 -1
  3. package/dist/loaders/providers.js.map +1 -1
  4. package/dist/migrations/Migration20240311145700_InitialSetupMigration.d.ts +1 -1
  5. package/dist/migrations/Migration20240311145700_InitialSetupMigration.d.ts.map +1 -1
  6. package/dist/migrations/Migration20240311145700_InitialSetupMigration.js +1 -1
  7. package/dist/migrations/Migration20240311145700_InitialSetupMigration.js.map +1 -1
  8. package/dist/migrations/Migration20240821170957.d.ts +1 -1
  9. package/dist/migrations/Migration20240821170957.d.ts.map +1 -1
  10. package/dist/migrations/Migration20240821170957.js +1 -1
  11. package/dist/migrations/Migration20240821170957.js.map +1 -1
  12. package/dist/migrations/Migration20240917161003.d.ts +1 -1
  13. package/dist/migrations/Migration20240917161003.d.ts.map +1 -1
  14. package/dist/migrations/Migration20240917161003.js +1 -1
  15. package/dist/migrations/Migration20240917161003.js.map +1 -1
  16. package/dist/migrations/Migration20241217110416.d.ts +1 -1
  17. package/dist/migrations/Migration20241217110416.d.ts.map +1 -1
  18. package/dist/migrations/Migration20241217110416.js +1 -1
  19. package/dist/migrations/Migration20241217110416.js.map +1 -1
  20. package/dist/migrations/Migration20250113122235.d.ts +1 -1
  21. package/dist/migrations/Migration20250113122235.d.ts.map +1 -1
  22. package/dist/migrations/Migration20250113122235.js +1 -1
  23. package/dist/migrations/Migration20250113122235.js.map +1 -1
  24. package/dist/migrations/Migration20250120115002.d.ts +1 -1
  25. package/dist/migrations/Migration20250120115002.d.ts.map +1 -1
  26. package/dist/migrations/Migration20250120115002.js +1 -1
  27. package/dist/migrations/Migration20250120115002.js.map +1 -1
  28. package/dist/migrations/Migration20250822130931.d.ts +6 -0
  29. package/dist/migrations/Migration20250822130931.d.ts.map +1 -0
  30. package/dist/migrations/Migration20250822130931.js +12 -0
  31. package/dist/migrations/Migration20250822130931.js.map +1 -0
  32. package/dist/migrations/Migration20250825132614.d.ts +6 -0
  33. package/dist/migrations/Migration20250825132614.d.ts.map +1 -0
  34. package/dist/migrations/Migration20250825132614.js +42 -0
  35. package/dist/migrations/Migration20250825132614.js.map +1 -0
  36. package/dist/migrations/Migration20251114133146.d.ts +6 -0
  37. package/dist/migrations/Migration20251114133146.d.ts.map +1 -0
  38. package/dist/migrations/Migration20251114133146.js +14 -0
  39. package/dist/migrations/Migration20251114133146.js.map +1 -0
  40. package/dist/models/fulfillment-item.d.ts +14 -14
  41. package/dist/models/fulfillment-label.d.ts +14 -14
  42. package/dist/models/fulfillment.d.ts +14 -14
  43. package/dist/models/shipping-option-rule.d.ts +8 -8
  44. package/dist/models/shipping-option-type.d.ts +8 -8
  45. package/dist/models/shipping-option-type.js +4 -4
  46. package/dist/models/shipping-option-type.js.map +1 -1
  47. package/dist/models/shipping-option.d.ts +8 -8
  48. package/dist/models/shipping-option.js +4 -4
  49. package/dist/models/shipping-option.js.map +1 -1
  50. package/dist/models/shipping-profile.d.ts +7 -7
  51. package/dist/schema/index.d.ts +1 -1
  52. package/dist/schema/index.d.ts.map +1 -1
  53. package/dist/schema/index.js +0 -1
  54. package/dist/schema/index.js.map +1 -1
  55. package/dist/services/fulfillment-module-service.d.ts +10 -3
  56. package/dist/services/fulfillment-module-service.d.ts.map +1 -1
  57. package/dist/services/fulfillment-module-service.js +119 -202
  58. package/dist/services/fulfillment-module-service.js.map +1 -1
  59. package/dist/services/fulfillment-provider.d.ts +5 -1
  60. package/dist/services/fulfillment-provider.d.ts.map +1 -1
  61. package/dist/services/fulfillment-provider.js +2 -0
  62. package/dist/services/fulfillment-provider.js.map +1 -1
  63. package/dist/tsconfig.tsbuildinfo +1 -1
  64. package/package.json +14 -28
@@ -17,7 +17,6 @@ const utils_1 = require("@medusajs/framework/utils");
17
17
  const _models_1 = require("../models");
18
18
  const _utils_1 = require("../utils");
19
19
  const joiner_config_1 = require("../joiner-config");
20
- const events_1 = require("../utils/events");
21
20
  const generateMethodForModels = {
22
21
  FulfillmentSet: _models_1.FulfillmentSet,
23
22
  ServiceZone: _models_1.ServiceZone,
@@ -27,7 +26,7 @@ const generateMethodForModels = {
27
26
  ShippingOptionRule: _models_1.ShippingOptionRule,
28
27
  ShippingOptionType: _models_1.ShippingOptionType,
29
28
  FulfillmentProvider: _models_1.FulfillmentProvider,
30
- // Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose8
29
+ // Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose
31
30
  };
32
31
  class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels) {
33
32
  constructor({ baseRepository, fulfillmentSetService, serviceZoneService, geoZoneService, shippingProfileService, shippingOptionService, shippingOptionRuleService, shippingOptionTypeService, fulfillmentProviderService, fulfillmentService, fulfillmentAddressService, }, moduleDeclaration) {
@@ -108,10 +107,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
108
107
  }
109
108
  }
110
109
  const createdFulfillmentSets = await this.fulfillmentSetService_.create(data_, sharedContext);
111
- (0, _utils_1.buildCreatedFulfillmentSetEvents)({
112
- fulfillmentSets: createdFulfillmentSets,
113
- sharedContext,
114
- });
115
110
  return createdFulfillmentSets;
116
111
  }
117
112
  // @ts-expect-error
@@ -132,10 +127,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
132
127
  }
133
128
  }
134
129
  const createdServiceZones = await this.serviceZoneService_.create(data_, sharedContext);
135
- (0, _utils_1.buildCreatedServiceZoneEvents)({
136
- serviceZones: createdServiceZones,
137
- sharedContext,
138
- });
139
130
  return createdServiceZones;
140
131
  }
141
132
  // @ts-expect-error
@@ -153,19 +144,11 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
153
144
  (0, _utils_1.validateAndNormalizeRules)(rules);
154
145
  }
155
146
  const createdSO = await this.shippingOptionService_.create(data_, sharedContext);
156
- (0, events_1.buildCreatedShippingOptionEvents)({
157
- shippingOptions: createdSO,
158
- sharedContext,
159
- });
160
147
  return createdSO;
161
148
  }
162
149
  // @ts-expect-error
163
150
  async createShippingProfiles(data, sharedContext = {}) {
164
151
  const createdShippingProfiles = await this.createShippingProfiles_(data, sharedContext);
165
- _utils_1.eventBuilders.createdShippingProfile({
166
- data: createdShippingProfiles,
167
- sharedContext,
168
- });
169
152
  return await this.baseRepository_.serialize(Array.isArray(data) ? createdShippingProfiles : createdShippingProfiles[0]);
170
153
  }
171
154
  async createShippingProfiles_(data, sharedContext = {}) {
@@ -180,10 +163,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
180
163
  const data_ = Array.isArray(data) ? data : [data];
181
164
  FulfillmentModuleService.validateGeoZones(data_);
182
165
  const createdGeoZones = await this.geoZoneService_.create(data_, sharedContext);
183
- _utils_1.eventBuilders.createdGeoZone({
184
- data: createdGeoZones,
185
- sharedContext,
186
- });
187
166
  return await this.baseRepository_.serialize(Array.isArray(data) ? createdGeoZones : createdGeoZones[0]);
188
167
  }
189
168
  // @ts-expect-error
@@ -200,10 +179,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
200
179
  }
201
180
  (0, _utils_1.validateAndNormalizeRules)(data_);
202
181
  const createdSORules = await this.shippingOptionRuleService_.create(data_, sharedContext);
203
- _utils_1.eventBuilders.createdShippingOptionRule({
204
- data: createdSORules.map((sor) => ({ id: sor.id })),
205
- sharedContext,
206
- });
207
182
  return createdSORules;
208
183
  }
209
184
  async createFulfillment(data, sharedContext = {}) {
@@ -223,10 +198,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
223
198
  await this.fulfillmentService_.delete(fulfillment.id, sharedContext);
224
199
  throw error;
225
200
  }
226
- (0, _utils_1.buildCreatedFulfillmentEvents)({
227
- fulfillments: [fulfillment],
228
- sharedContext,
229
- });
230
201
  return await this.baseRepository_.serialize(fulfillment);
231
202
  }
232
203
  async deleteFulfillment(id, sharedContext = {}) {
@@ -258,10 +229,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
258
229
  await this.fulfillmentService_.delete(fulfillment.id, sharedContext);
259
230
  throw error;
260
231
  }
261
- (0, _utils_1.buildCreatedFulfillmentEvents)({
262
- fulfillments: [fulfillment],
263
- sharedContext,
264
- });
265
232
  return await this.baseRepository_.serialize(fulfillment);
266
233
  }
267
234
  // @ts-expect-error
@@ -349,14 +316,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
349
316
  }
350
317
  });
351
318
  if (serviceZoneIdsToDelete.length) {
352
- _utils_1.eventBuilders.deletedServiceZone({
353
- data: serviceZoneIdsToDelete.map((id) => ({ id })),
354
- sharedContext,
355
- });
356
- _utils_1.eventBuilders.deletedGeoZone({
357
- data: geoZoneIdsToDelete.map((id) => ({ id })),
358
- sharedContext,
359
- });
360
319
  await (0, utils_1.promiseAll)([
361
320
  this.geoZoneService_.delete({
362
321
  id: geoZoneIdsToDelete,
@@ -367,27 +326,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
367
326
  ]);
368
327
  }
369
328
  const updatedFulfillmentSets = await this.fulfillmentSetService_.update(data_, sharedContext);
370
- _utils_1.eventBuilders.updatedFulfillmentSet({
371
- data: updatedFulfillmentSets,
372
- sharedContext,
373
- });
374
- const createdServiceZoneIds = [];
375
- const createdGeoZoneIds = updatedFulfillmentSets
376
- .flatMap((f) => [...f.service_zones].flatMap((serviceZone) => {
377
- if (!existingServiceZoneIds.includes(serviceZone.id)) {
378
- createdServiceZoneIds.push(serviceZone.id);
379
- }
380
- return serviceZone.geo_zones.map((g) => g.id);
381
- }))
382
- .filter((id) => !existingGeoZoneIds.includes(id));
383
- _utils_1.eventBuilders.createdServiceZone({
384
- data: createdServiceZoneIds.map((id) => ({ id })),
385
- sharedContext,
386
- });
387
- _utils_1.eventBuilders.createdGeoZone({
388
- data: createdGeoZoneIds.map((id) => ({ id })),
389
- sharedContext,
390
- });
391
329
  return Array.isArray(data)
392
330
  ? updatedFulfillmentSets
393
331
  : updatedFulfillmentSets[0];
@@ -478,32 +416,11 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
478
416
  }
479
417
  });
480
418
  if (geoZoneIdsToDelete.length) {
481
- _utils_1.eventBuilders.deletedGeoZone({
482
- data: geoZoneIdsToDelete.map((id) => ({ id })),
483
- sharedContext,
484
- });
485
419
  await this.geoZoneService_.delete({
486
420
  id: geoZoneIdsToDelete,
487
421
  }, sharedContext);
488
422
  }
489
423
  const updatedServiceZones = await this.serviceZoneService_.update(data_, sharedContext);
490
- _utils_1.eventBuilders.updatedServiceZone({
491
- data: updatedServiceZones,
492
- sharedContext,
493
- });
494
- const createdGeoZoneIds = updatedServiceZones
495
- .flatMap((serviceZone) => {
496
- return serviceZone.geo_zones.map((g) => g.id);
497
- })
498
- .filter((id) => !existingGeoZoneIds.includes(id));
499
- _utils_1.eventBuilders.createdGeoZone({
500
- data: createdGeoZoneIds.map((id) => ({ id })),
501
- sharedContext,
502
- });
503
- _utils_1.eventBuilders.updatedGeoZone({
504
- data: updatedGeoZoneIds.map((id) => ({ id })),
505
- sharedContext,
506
- });
507
424
  return Array.isArray(data) ? updatedServiceZones : updatedServiceZones[0];
508
425
  }
509
426
  async upsertServiceZones(data, sharedContext = {}) {
@@ -571,11 +488,12 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
571
488
  const ruleIdsToDelete = [];
572
489
  const updatedRuleIds = [];
573
490
  const existingRuleIds = [];
574
- const optionTypeDeletedIds = [];
575
491
  dataArray.forEach((shippingOption) => {
576
- const existingShippingOption = existingShippingOptions.get(shippingOption.id); // Garuantueed to exist since the validation above have been performed
577
- if (shippingOption.type && !("id" in shippingOption.type)) {
578
- optionTypeDeletedIds.push(existingShippingOption.type.id);
492
+ const existingShippingOption = existingShippingOptions.get(shippingOption.id); // Guaranteed to exist since the validation above have been performed
493
+ // `type_id` doesn't exist on the entity/table, `type_id` argument is mapped to `shipping_option_type_id`
494
+ if (shippingOption.type_id) {
495
+ shippingOption.shipping_option_type_id = shippingOption.type_id;
496
+ delete shippingOption.type_id;
579
497
  }
580
498
  if (!shippingOption.rules) {
581
499
  return;
@@ -622,61 +540,13 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
622
540
  });
623
541
  });
624
542
  if (ruleIdsToDelete.length) {
625
- _utils_1.eventBuilders.deletedShippingOptionRule({
626
- data: ruleIdsToDelete.map((id) => ({ id })),
627
- sharedContext,
628
- });
629
543
  await this.shippingOptionRuleService_.delete(ruleIdsToDelete, sharedContext);
630
544
  }
631
545
  const updatedShippingOptions = await this.shippingOptionService_.update(dataArray, sharedContext);
632
- this.handleShippingOptionUpdateEvents({
633
- shippingOptionsData: dataArray,
634
- updatedShippingOptions,
635
- optionTypeDeletedIds,
636
- updatedRuleIds,
637
- existingRuleIds,
638
- sharedContext,
639
- });
640
546
  return Array.isArray(data)
641
547
  ? updatedShippingOptions
642
548
  : updatedShippingOptions[0];
643
549
  }
644
- handleShippingOptionUpdateEvents({ shippingOptionsData, updatedShippingOptions, optionTypeDeletedIds, updatedRuleIds, existingRuleIds, sharedContext, }) {
645
- _utils_1.eventBuilders.updatedShippingOption({
646
- data: updatedShippingOptions,
647
- sharedContext,
648
- });
649
- _utils_1.eventBuilders.deletedShippingOptionType({
650
- data: optionTypeDeletedIds.map((id) => ({ id })),
651
- sharedContext,
652
- });
653
- const createdOptionTypeIds = updatedShippingOptions
654
- .filter((so) => {
655
- const updateData = shippingOptionsData.find((sod) => sod.id === so.id);
656
- return updateData?.type && !("id" in updateData.type);
657
- })
658
- .map((so) => so.type.id);
659
- _utils_1.eventBuilders.createdShippingOptionType({
660
- data: createdOptionTypeIds.map((id) => ({ id })),
661
- sharedContext,
662
- });
663
- const createdRuleIds = updatedShippingOptions
664
- .flatMap((so) => [...so.rules].map((rule) => {
665
- if (existingRuleIds.includes(rule.id)) {
666
- return;
667
- }
668
- return rule.id;
669
- }))
670
- .filter((id) => !!id);
671
- _utils_1.eventBuilders.createdShippingOptionRule({
672
- data: createdRuleIds.map((id) => ({ id })),
673
- sharedContext,
674
- });
675
- _utils_1.eventBuilders.updatedShippingOptionRule({
676
- data: updatedRuleIds.map((id) => ({ id })),
677
- sharedContext,
678
- });
679
- }
680
550
  async upsertShippingOptions(data, sharedContext = {}) {
681
551
  const upsertedShippingOptions = await this.upsertShippingOptions_(data, sharedContext);
682
552
  const allShippingOptions = await this.baseRepository_.serialize(upsertedShippingOptions);
@@ -704,8 +574,42 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
704
574
  }
705
575
  return [...created, ...updated];
706
576
  }
577
+ async upsertShippingOptionTypes(data, sharedContext = {}) {
578
+ const results = await this.updateShippingOptionTypes_(data, sharedContext);
579
+ const allTypes = await this.baseRepository_.serialize(results);
580
+ return Array.isArray(data) ? allTypes : allTypes[0];
581
+ }
582
+ async updateShippingOptionTypes_(data, sharedContext) {
583
+ const input = Array.isArray(data) ? data : [data];
584
+ const results = await this.shippingOptionTypeService_.upsert(input, sharedContext);
585
+ return results;
586
+ }
587
+ // @ts-expect-error
588
+ async updateShippingOptionTypes(idOrSelector, data, sharedContext = {}) {
589
+ let normalizedInput = [];
590
+ if ((0, utils_1.isString)(idOrSelector)) {
591
+ // Check if the type exists in the first place
592
+ await this.shippingOptionTypeService_.retrieve(idOrSelector, {}, sharedContext);
593
+ normalizedInput = [{ id: idOrSelector, ...data }];
594
+ }
595
+ else {
596
+ const types = await this.shippingOptionTypeService_.list(idOrSelector, {}, sharedContext);
597
+ normalizedInput = types.map((type) => ({
598
+ id: type.id,
599
+ ...data,
600
+ }));
601
+ }
602
+ const types = await this.shippingOptionTypeService_.update(normalizedInput, sharedContext);
603
+ const updatedTypes = await this.baseRepository_.serialize(types);
604
+ return (0, utils_1.isString)(idOrSelector) ? updatedTypes[0] : updatedTypes;
605
+ }
707
606
  // @ts-expect-error
708
607
  async updateShippingProfiles(idOrSelector, data, sharedContext = {}) {
608
+ const profiles = await this.updateShippingProfiles_(idOrSelector, data, sharedContext);
609
+ const updatedProfiles = await this.baseRepository_.serialize(profiles);
610
+ return (0, utils_1.isString)(idOrSelector) ? updatedProfiles[0] : updatedProfiles;
611
+ }
612
+ async updateShippingProfiles_(idOrSelector, data, sharedContext = {}) {
709
613
  let normalizedInput = [];
710
614
  if ((0, utils_1.isString)(idOrSelector)) {
711
615
  await this.shippingProfileService_.retrieve(idOrSelector, {}, sharedContext);
@@ -719,10 +623,13 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
719
623
  }));
720
624
  }
721
625
  const profiles = await this.shippingProfileService_.update(normalizedInput, sharedContext);
722
- const updatedProfiles = await this.baseRepository_.serialize(profiles);
723
- return (0, utils_1.isString)(idOrSelector) ? updatedProfiles[0] : updatedProfiles;
626
+ return profiles;
724
627
  }
725
628
  async upsertShippingProfiles(data, sharedContext = {}) {
629
+ const profiles = await this.upsertShippingProfiles_(data, sharedContext);
630
+ return await this.baseRepository_.serialize(Array.isArray(data) ? profiles : profiles[0]);
631
+ }
632
+ async upsertShippingProfiles_(data, sharedContext = {}) {
726
633
  const input = Array.isArray(data) ? data : [data];
727
634
  const forUpdate = input.filter((prof) => !!prof.id);
728
635
  const forCreate = input.filter((prof) => !prof.id);
@@ -734,9 +641,7 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
734
641
  if (forUpdate.length) {
735
642
  updated = await this.shippingProfileService_.update(forUpdate, sharedContext);
736
643
  }
737
- const result = [...created, ...updated];
738
- const allProfiles = await this.baseRepository_.serialize(result);
739
- return Array.isArray(data) ? allProfiles : allProfiles[0];
644
+ return [...created, ...updated];
740
645
  }
741
646
  // @ts-expect-error
742
647
  async updateGeoZones(data, sharedContext = {}) {
@@ -746,10 +651,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
746
651
  }
747
652
  FulfillmentModuleService.validateGeoZones(data_);
748
653
  const updatedGeoZones = await this.geoZoneService_.update(data_, sharedContext);
749
- _utils_1.eventBuilders.updatedGeoZone({
750
- data: updatedGeoZones,
751
- sharedContext,
752
- });
753
654
  const serialized = await this.baseRepository_.serialize(updatedGeoZones);
754
655
  return Array.isArray(data) ? serialized : serialized[0];
755
656
  }
@@ -765,10 +666,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
765
666
  }
766
667
  (0, _utils_1.validateAndNormalizeRules)(data_);
767
668
  const updatedShippingOptionRules = await this.shippingOptionRuleService_.update(data_, sharedContext);
768
- _utils_1.eventBuilders.updatedShippingOptionRule({
769
- data: updatedShippingOptionRules.map((rule) => ({ id: rule.id })),
770
- sharedContext,
771
- });
772
669
  return Array.isArray(data)
773
670
  ? updatedShippingOptionRules
774
671
  : updatedShippingOptionRules[0];
@@ -782,8 +679,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
782
679
  relations: ["items", "labels"],
783
680
  }, sharedContext);
784
681
  const updatedLabelIds = [];
785
- let deletedLabelIds = [];
786
- const existingLabelIds = existingFulfillment.labels.map((label) => label.id);
787
682
  /**
788
683
  * @note
789
684
  * Since the relation is a one to many, the deletion, update and creation of labels
@@ -795,10 +690,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
795
690
  * and we also need to emit the events later on.
796
691
  */
797
692
  if ((0, utils_1.isDefined)(data.labels) && (0, utils_1.isPresent)(data.labels)) {
798
- const dataLabelIds = data.labels
799
- .filter((label) => "id" in label)
800
- .map((label) => label.id);
801
- deletedLabelIds = (0, utils_1.arrayDifference)(existingLabelIds, dataLabelIds);
802
693
  for (let label of data.labels) {
803
694
  if (!("id" in label)) {
804
695
  continue;
@@ -815,30 +706,8 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
815
706
  }
816
707
  }
817
708
  const [fulfillment] = await this.fulfillmentService_.update([{ id, ...data }], sharedContext);
818
- this.handleFulfillmentUpdateEvents(fulfillment, existingLabelIds, updatedLabelIds, deletedLabelIds, sharedContext);
819
709
  return fulfillment;
820
710
  }
821
- handleFulfillmentUpdateEvents(fulfillment, existingLabelIds, updatedLabelIds, deletedLabelIds, sharedContext) {
822
- _utils_1.eventBuilders.updatedFulfillment({
823
- data: [{ id: fulfillment.id }],
824
- sharedContext,
825
- });
826
- _utils_1.eventBuilders.deletedFulfillmentLabel({
827
- data: deletedLabelIds.map((id) => ({ id })),
828
- sharedContext,
829
- });
830
- _utils_1.eventBuilders.updatedFulfillmentLabel({
831
- data: updatedLabelIds.map((id) => ({ id })),
832
- sharedContext,
833
- });
834
- const createdLabels = fulfillment.labels.filter((label) => {
835
- return !existingLabelIds.includes(label.id);
836
- });
837
- _utils_1.eventBuilders.createdFulfillmentLabel({
838
- data: createdLabels.map((label) => ({ id: label.id })),
839
- sharedContext,
840
- });
841
- }
842
711
  async cancelFulfillment(id, sharedContext = {}) {
843
712
  const canceledAt = new Date();
844
713
  let fulfillment = await this.fulfillmentService_.retrieve(id, {}, sharedContext);
@@ -856,13 +725,9 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
856
725
  id,
857
726
  canceled_at: canceledAt,
858
727
  }, sharedContext);
859
- _utils_1.eventBuilders.updatedFulfillment({
860
- data: [{ id }],
861
- sharedContext,
862
- });
863
728
  }
864
729
  const result = await this.baseRepository_.serialize(fulfillment);
865
- return Array.isArray(result) ? result[0] : result;
730
+ return result;
866
731
  }
867
732
  async retrieveFulfillmentOptions(providerId) {
868
733
  return await this.fulfillmentProviderService_.getFulfillmentOptions(providerId);
@@ -1064,15 +929,22 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
1064
929
  * Define the hierarchy of required properties for the geo zones.
1065
930
  */
1066
931
  const geoZoneRequirePropertyHierarchy = {
1067
- postal_expression: [
1068
- "country_code",
1069
- "province_code",
1070
- "city",
1071
- "postal_expression",
1072
- ],
1073
- city: ["country_code", "province_code", "city"],
1074
- province_code: ["country_code", "province_code"],
1075
- country_code: ["country_code"],
932
+ postal_expression: {
933
+ props: ["country_code", "province_code", "city", "postal_expression"],
934
+ type: "zip",
935
+ },
936
+ city: {
937
+ props: ["country_code", "province_code", "city"],
938
+ type: "city",
939
+ },
940
+ province_code: {
941
+ props: ["country_code", "province_code"],
942
+ type: "province",
943
+ },
944
+ country_code: {
945
+ props: ["country_code"],
946
+ type: "country",
947
+ },
1076
948
  };
1077
949
  /**
1078
950
  * The following changes assume that the lowest level check (e.g postal expression) can't exist multiple times in the higher level (e.g country)
@@ -1080,14 +952,17 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
1080
952
  * to this pr https://github.com/medusajs/medusa/pull/8066
1081
953
  */
1082
954
  const geoZoneConstraints = Object.entries(geoZoneRequirePropertyHierarchy)
1083
- .map(([prop, requiredProps]) => {
955
+ .map(([prop, { props, type }]) => {
1084
956
  if (address[prop]) {
1085
- return requiredProps.reduce((geoZoneConstraint, prop) => {
1086
- if ((0, utils_1.isPresent)(address[prop])) {
1087
- geoZoneConstraint[prop] = address[prop];
1088
- }
1089
- return geoZoneConstraint;
1090
- }, {});
957
+ return {
958
+ type,
959
+ ...props.reduce((geoZoneConstraint, prop) => {
960
+ if ((0, utils_1.isPresent)(address[prop])) {
961
+ geoZoneConstraint[prop] = address[prop];
962
+ }
963
+ return geoZoneConstraint;
964
+ }, {}),
965
+ };
1091
966
  }
1092
967
  return null;
1093
968
  })
@@ -1185,7 +1060,7 @@ __decorate([
1185
1060
  __metadata("design:returntype", Promise)
1186
1061
  ], FulfillmentModuleService.prototype, "createShippingOptions_", null);
1187
1062
  __decorate([
1188
- (0, utils_1.InjectTransactionManager)(),
1063
+ (0, utils_1.InjectManager)(),
1189
1064
  (0, utils_1.EmitEvents)()
1190
1065
  // @ts-expect-error
1191
1066
  ,
@@ -1334,7 +1209,32 @@ __decorate([
1334
1209
  __metadata("design:returntype", Promise)
1335
1210
  ], FulfillmentModuleService.prototype, "upsertShippingOptions_", null);
1336
1211
  __decorate([
1337
- (0, utils_1.InjectTransactionManager)()
1212
+ (0, utils_1.InjectManager)(),
1213
+ (0, utils_1.EmitEvents)(),
1214
+ __param(1, (0, utils_1.MedusaContext)()),
1215
+ __metadata("design:type", Function),
1216
+ __metadata("design:paramtypes", [Object, Object]),
1217
+ __metadata("design:returntype", Promise)
1218
+ ], FulfillmentModuleService.prototype, "upsertShippingOptionTypes", null);
1219
+ __decorate([
1220
+ (0, utils_1.InjectTransactionManager)(),
1221
+ __metadata("design:type", Function),
1222
+ __metadata("design:paramtypes", [Object, Object]),
1223
+ __metadata("design:returntype", Promise)
1224
+ ], FulfillmentModuleService.prototype, "updateShippingOptionTypes_", null);
1225
+ __decorate([
1226
+ (0, utils_1.InjectManager)(),
1227
+ (0, utils_1.EmitEvents)()
1228
+ // @ts-expect-error
1229
+ ,
1230
+ __param(2, (0, utils_1.MedusaContext)()),
1231
+ __metadata("design:type", Function),
1232
+ __metadata("design:paramtypes", [Object, Object, Object]),
1233
+ __metadata("design:returntype", Promise)
1234
+ ], FulfillmentModuleService.prototype, "updateShippingOptionTypes", null);
1235
+ __decorate([
1236
+ (0, utils_1.InjectManager)(),
1237
+ (0, utils_1.EmitEvents)()
1338
1238
  // @ts-expect-error
1339
1239
  ,
1340
1240
  __param(2, (0, utils_1.MedusaContext)()),
@@ -1344,11 +1244,26 @@ __decorate([
1344
1244
  ], FulfillmentModuleService.prototype, "updateShippingProfiles", null);
1345
1245
  __decorate([
1346
1246
  (0, utils_1.InjectTransactionManager)(),
1247
+ __param(2, (0, utils_1.MedusaContext)()),
1248
+ __metadata("design:type", Function),
1249
+ __metadata("design:paramtypes", [Object, Object, Object]),
1250
+ __metadata("design:returntype", Promise)
1251
+ ], FulfillmentModuleService.prototype, "updateShippingProfiles_", null);
1252
+ __decorate([
1253
+ (0, utils_1.InjectManager)(),
1254
+ (0, utils_1.EmitEvents)(),
1347
1255
  __param(1, (0, utils_1.MedusaContext)()),
1348
1256
  __metadata("design:type", Function),
1349
1257
  __metadata("design:paramtypes", [Object, Object]),
1350
1258
  __metadata("design:returntype", Promise)
1351
1259
  ], FulfillmentModuleService.prototype, "upsertShippingProfiles", null);
1260
+ __decorate([
1261
+ (0, utils_1.InjectTransactionManager)(),
1262
+ __param(1, (0, utils_1.MedusaContext)()),
1263
+ __metadata("design:type", Function),
1264
+ __metadata("design:paramtypes", [Object, Object]),
1265
+ __metadata("design:returntype", Promise)
1266
+ ], FulfillmentModuleService.prototype, "upsertShippingProfiles_", null);
1352
1267
  __decorate([
1353
1268
  (0, utils_1.InjectManager)(),
1354
1269
  (0, utils_1.EmitEvents)()
@@ -1414,7 +1329,8 @@ __decorate([
1414
1329
  __metadata("design:returntype", Promise)
1415
1330
  ], FulfillmentModuleService.prototype, "validateShippingOptionsForPriceCalculation", null);
1416
1331
  __decorate([
1417
- (0, utils_1.InjectTransactionManager)()
1332
+ (0, utils_1.InjectTransactionManager)(),
1333
+ (0, utils_1.EmitEvents)()
1418
1334
  // @ts-expect-error
1419
1335
  ,
1420
1336
  __param(1, (0, utils_1.MedusaContext)()),
@@ -1423,7 +1339,8 @@ __decorate([
1423
1339
  __metadata("design:returntype", Promise)
1424
1340
  ], FulfillmentModuleService.prototype, "deleteShippingProfiles", null);
1425
1341
  __decorate([
1426
- (0, utils_1.InjectTransactionManager)()
1342
+ (0, utils_1.InjectTransactionManager)(),
1343
+ (0, utils_1.EmitEvents)()
1427
1344
  // @ts-expect-error
1428
1345
  ,
1429
1346
  __param(2, (0, utils_1.MedusaContext)()),