@medusajs/fulfillment 3.0.0-snapshot-20250410112222 → 3.0.0-snapshot-20251104004624
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/loaders/providers.d.ts.map +1 -1
- package/dist/loaders/providers.js +1 -1
- package/dist/loaders/providers.js.map +1 -1
- package/dist/migrations/Migration20240311145700_InitialSetupMigration.d.ts +1 -1
- package/dist/migrations/Migration20240311145700_InitialSetupMigration.d.ts.map +1 -1
- package/dist/migrations/Migration20240311145700_InitialSetupMigration.js +1 -1
- package/dist/migrations/Migration20240311145700_InitialSetupMigration.js.map +1 -1
- package/dist/migrations/Migration20240821170957.d.ts +1 -1
- package/dist/migrations/Migration20240821170957.d.ts.map +1 -1
- package/dist/migrations/Migration20240821170957.js +1 -1
- package/dist/migrations/Migration20240821170957.js.map +1 -1
- package/dist/migrations/Migration20240917161003.d.ts +1 -1
- package/dist/migrations/Migration20240917161003.d.ts.map +1 -1
- package/dist/migrations/Migration20240917161003.js +1 -1
- package/dist/migrations/Migration20240917161003.js.map +1 -1
- package/dist/migrations/Migration20241217110416.d.ts +1 -1
- package/dist/migrations/Migration20241217110416.d.ts.map +1 -1
- package/dist/migrations/Migration20241217110416.js +1 -1
- package/dist/migrations/Migration20241217110416.js.map +1 -1
- package/dist/migrations/Migration20250113122235.d.ts +1 -1
- package/dist/migrations/Migration20250113122235.d.ts.map +1 -1
- package/dist/migrations/Migration20250113122235.js +1 -1
- package/dist/migrations/Migration20250113122235.js.map +1 -1
- package/dist/migrations/Migration20250120115002.d.ts +1 -1
- package/dist/migrations/Migration20250120115002.d.ts.map +1 -1
- package/dist/migrations/Migration20250120115002.js +1 -1
- package/dist/migrations/Migration20250120115002.js.map +1 -1
- package/dist/migrations/Migration20250822130931.d.ts +6 -0
- package/dist/migrations/Migration20250822130931.d.ts.map +1 -0
- package/dist/migrations/Migration20250822130931.js +12 -0
- package/dist/migrations/Migration20250822130931.js.map +1 -0
- package/dist/migrations/Migration20250825132614.d.ts +6 -0
- package/dist/migrations/Migration20250825132614.d.ts.map +1 -0
- package/dist/migrations/Migration20250825132614.js +42 -0
- package/dist/migrations/Migration20250825132614.js.map +1 -0
- package/dist/models/fulfillment-item.d.ts +12 -12
- package/dist/models/fulfillment-label.d.ts +12 -12
- package/dist/models/fulfillment.d.ts +12 -12
- package/dist/models/shipping-option-rule.d.ts +7 -7
- package/dist/models/shipping-option-type.d.ts +7 -7
- package/dist/models/shipping-option-type.js +3 -3
- package/dist/models/shipping-option-type.js.map +1 -1
- package/dist/models/shipping-option.d.ts +7 -7
- package/dist/models/shipping-option.js +2 -2
- package/dist/models/shipping-option.js.map +1 -1
- package/dist/models/shipping-profile.d.ts +6 -6
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +0 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/services/fulfillment-module-service.d.ts +10 -3
- package/dist/services/fulfillment-module-service.d.ts.map +1 -1
- package/dist/services/fulfillment-module-service.js +117 -200
- package/dist/services/fulfillment-module-service.js.map +1 -1
- package/dist/services/fulfillment-provider.d.ts +5 -1
- package/dist/services/fulfillment-provider.d.ts.map +1 -1
- package/dist/services/fulfillment-provider.js +2 -0
- package/dist/services/fulfillment-provider.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -28
|
@@ -14,10 +14,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const types_1 = require("@medusajs/framework/types");
|
|
16
16
|
const utils_1 = require("@medusajs/framework/utils");
|
|
17
|
+
const utils_2 = require("@medusajs/utils");
|
|
17
18
|
const _models_1 = require("../models");
|
|
18
19
|
const _utils_1 = require("../utils");
|
|
19
20
|
const joiner_config_1 = require("../joiner-config");
|
|
20
|
-
const events_1 = require("../utils/events");
|
|
21
21
|
const generateMethodForModels = {
|
|
22
22
|
FulfillmentSet: _models_1.FulfillmentSet,
|
|
23
23
|
ServiceZone: _models_1.ServiceZone,
|
|
@@ -27,7 +27,7 @@ const generateMethodForModels = {
|
|
|
27
27
|
ShippingOptionRule: _models_1.ShippingOptionRule,
|
|
28
28
|
ShippingOptionType: _models_1.ShippingOptionType,
|
|
29
29
|
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
|
|
30
|
+
// Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose
|
|
31
31
|
};
|
|
32
32
|
class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels) {
|
|
33
33
|
constructor({ baseRepository, fulfillmentSetService, serviceZoneService, geoZoneService, shippingProfileService, shippingOptionService, shippingOptionRuleService, shippingOptionTypeService, fulfillmentProviderService, fulfillmentService, fulfillmentAddressService, }, moduleDeclaration) {
|
|
@@ -108,10 +108,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
const createdFulfillmentSets = await this.fulfillmentSetService_.create(data_, sharedContext);
|
|
111
|
-
(0, _utils_1.buildCreatedFulfillmentSetEvents)({
|
|
112
|
-
fulfillmentSets: createdFulfillmentSets,
|
|
113
|
-
sharedContext,
|
|
114
|
-
});
|
|
115
111
|
return createdFulfillmentSets;
|
|
116
112
|
}
|
|
117
113
|
// @ts-expect-error
|
|
@@ -132,10 +128,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
130
|
const createdServiceZones = await this.serviceZoneService_.create(data_, sharedContext);
|
|
135
|
-
(0, _utils_1.buildCreatedServiceZoneEvents)({
|
|
136
|
-
serviceZones: createdServiceZones,
|
|
137
|
-
sharedContext,
|
|
138
|
-
});
|
|
139
131
|
return createdServiceZones;
|
|
140
132
|
}
|
|
141
133
|
// @ts-expect-error
|
|
@@ -153,19 +145,11 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
153
145
|
(0, _utils_1.validateAndNormalizeRules)(rules);
|
|
154
146
|
}
|
|
155
147
|
const createdSO = await this.shippingOptionService_.create(data_, sharedContext);
|
|
156
|
-
(0, events_1.buildCreatedShippingOptionEvents)({
|
|
157
|
-
shippingOptions: createdSO,
|
|
158
|
-
sharedContext,
|
|
159
|
-
});
|
|
160
148
|
return createdSO;
|
|
161
149
|
}
|
|
162
150
|
// @ts-expect-error
|
|
163
151
|
async createShippingProfiles(data, sharedContext = {}) {
|
|
164
152
|
const createdShippingProfiles = await this.createShippingProfiles_(data, sharedContext);
|
|
165
|
-
_utils_1.eventBuilders.createdShippingProfile({
|
|
166
|
-
data: createdShippingProfiles,
|
|
167
|
-
sharedContext,
|
|
168
|
-
});
|
|
169
153
|
return await this.baseRepository_.serialize(Array.isArray(data) ? createdShippingProfiles : createdShippingProfiles[0]);
|
|
170
154
|
}
|
|
171
155
|
async createShippingProfiles_(data, sharedContext = {}) {
|
|
@@ -180,10 +164,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
180
164
|
const data_ = Array.isArray(data) ? data : [data];
|
|
181
165
|
FulfillmentModuleService.validateGeoZones(data_);
|
|
182
166
|
const createdGeoZones = await this.geoZoneService_.create(data_, sharedContext);
|
|
183
|
-
_utils_1.eventBuilders.createdGeoZone({
|
|
184
|
-
data: createdGeoZones,
|
|
185
|
-
sharedContext,
|
|
186
|
-
});
|
|
187
167
|
return await this.baseRepository_.serialize(Array.isArray(data) ? createdGeoZones : createdGeoZones[0]);
|
|
188
168
|
}
|
|
189
169
|
// @ts-expect-error
|
|
@@ -200,10 +180,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
200
180
|
}
|
|
201
181
|
(0, _utils_1.validateAndNormalizeRules)(data_);
|
|
202
182
|
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
183
|
return createdSORules;
|
|
208
184
|
}
|
|
209
185
|
async createFulfillment(data, sharedContext = {}) {
|
|
@@ -223,10 +199,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
223
199
|
await this.fulfillmentService_.delete(fulfillment.id, sharedContext);
|
|
224
200
|
throw error;
|
|
225
201
|
}
|
|
226
|
-
(0, _utils_1.buildCreatedFulfillmentEvents)({
|
|
227
|
-
fulfillments: [fulfillment],
|
|
228
|
-
sharedContext,
|
|
229
|
-
});
|
|
230
202
|
return await this.baseRepository_.serialize(fulfillment);
|
|
231
203
|
}
|
|
232
204
|
async deleteFulfillment(id, sharedContext = {}) {
|
|
@@ -258,10 +230,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
258
230
|
await this.fulfillmentService_.delete(fulfillment.id, sharedContext);
|
|
259
231
|
throw error;
|
|
260
232
|
}
|
|
261
|
-
(0, _utils_1.buildCreatedFulfillmentEvents)({
|
|
262
|
-
fulfillments: [fulfillment],
|
|
263
|
-
sharedContext,
|
|
264
|
-
});
|
|
265
233
|
return await this.baseRepository_.serialize(fulfillment);
|
|
266
234
|
}
|
|
267
235
|
// @ts-expect-error
|
|
@@ -349,14 +317,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
349
317
|
}
|
|
350
318
|
});
|
|
351
319
|
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
320
|
await (0, utils_1.promiseAll)([
|
|
361
321
|
this.geoZoneService_.delete({
|
|
362
322
|
id: geoZoneIdsToDelete,
|
|
@@ -367,27 +327,6 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
367
327
|
]);
|
|
368
328
|
}
|
|
369
329
|
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
330
|
return Array.isArray(data)
|
|
392
331
|
? updatedFulfillmentSets
|
|
393
332
|
: updatedFulfillmentSets[0];
|
|
@@ -478,32 +417,11 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
478
417
|
}
|
|
479
418
|
});
|
|
480
419
|
if (geoZoneIdsToDelete.length) {
|
|
481
|
-
_utils_1.eventBuilders.deletedGeoZone({
|
|
482
|
-
data: geoZoneIdsToDelete.map((id) => ({ id })),
|
|
483
|
-
sharedContext,
|
|
484
|
-
});
|
|
485
420
|
await this.geoZoneService_.delete({
|
|
486
421
|
id: geoZoneIdsToDelete,
|
|
487
422
|
}, sharedContext);
|
|
488
423
|
}
|
|
489
424
|
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
425
|
return Array.isArray(data) ? updatedServiceZones : updatedServiceZones[0];
|
|
508
426
|
}
|
|
509
427
|
async upsertServiceZones(data, sharedContext = {}) {
|
|
@@ -573,8 +491,8 @@ class FulfillmentModuleService extends utils_1.ModulesSdkUtils.MedusaService(gen
|
|
|
573
491
|
const existingRuleIds = [];
|
|
574
492
|
const optionTypeDeletedIds = [];
|
|
575
493
|
dataArray.forEach((shippingOption) => {
|
|
576
|
-
const existingShippingOption = existingShippingOptions.get(shippingOption.id); //
|
|
577
|
-
if (shippingOption.type && !("id" in shippingOption.type)) {
|
|
494
|
+
const existingShippingOption = existingShippingOptions.get(shippingOption.id); // Guaranteed to exist since the validation above have been performed
|
|
495
|
+
if ((0, utils_2.isObject)(shippingOption.type) && !("id" in shippingOption.type)) {
|
|
578
496
|
optionTypeDeletedIds.push(existingShippingOption.type.id);
|
|
579
497
|
}
|
|
580
498
|
if (!shippingOption.rules) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
"
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
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,
|
|
955
|
+
.map(([prop, { props, type }]) => {
|
|
1084
956
|
if (address[prop]) {
|
|
1085
|
-
return
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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.
|
|
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.
|
|
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)()),
|