@medusajs/core-flows 0.0.7 → 0.0.8
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/steps/remove-remote-links.d.ts +5 -0
- package/dist/common/steps/remove-remote-links.js +32 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.js +18 -0
- package/dist/defaults/steps/create-default-store.d.ts +7 -0
- package/dist/defaults/steps/create-default-store.js +34 -0
- package/dist/defaults/steps/index.d.ts +1 -0
- package/dist/defaults/steps/index.js +17 -0
- package/dist/defaults/workflows/create-defaults.d.ts +2 -0
- package/dist/defaults/workflows/create-defaults.js +21 -0
- package/dist/defaults/workflows/index.d.ts +1 -0
- package/dist/defaults/workflows/index.js +17 -0
- package/dist/definition/cart/steps/update-tax-lines.js +12 -4
- package/dist/handlers/product/update-product-variants.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/inventory/steps/index.d.ts +2 -1
- package/dist/inventory/steps/index.js +2 -1
- package/dist/inventory/steps/update-inventory-items.d.ts +3 -0
- package/dist/inventory/steps/update-inventory-items.js +25 -0
- package/dist/inventory/steps/update-inventory-levels.d.ts +3 -0
- package/dist/inventory/steps/update-inventory-levels.js +30 -0
- package/dist/inventory/workflows/delete-inventory-items.js +5 -1
- package/dist/inventory/workflows/index.d.ts +2 -0
- package/dist/inventory/workflows/index.js +2 -0
- package/dist/inventory/workflows/update-inventory-items.d.ts +7 -0
- package/dist/inventory/workflows/update-inventory-items.js +9 -0
- package/dist/inventory/workflows/update-inventory-levels.d.ts +7 -0
- package/dist/inventory/workflows/update-inventory-levels.js +9 -0
- package/dist/price-list/steps/delete-price-lists.js +2 -4
- package/dist/price-list/steps/get-existing-price-lists-price-ids.js +1 -1
- package/dist/price-list/steps/remove-price-list-prices.js +5 -6
- package/dist/price-list/steps/update-price-list-prices.js +6 -6
- package/dist/price-list/steps/upsert-price-list-prices.js +8 -8
- package/dist/product/steps/remove-variant-pricing-link.js +10 -14
- package/dist/product/steps/update-product-options.d.ts +1 -1
- package/dist/product/steps/update-product-options.js +2 -9
- package/dist/product/steps/update-product-variants.d.ts +1 -1
- package/dist/product/steps/update-product-variants.js +2 -9
- package/dist/product/workflows/delete-product-variants.js +0 -1
- package/dist/product/workflows/delete-products.js +0 -2
- package/dist/sales-channel/steps/create-default-sales-channel.d.ts +7 -0
- package/dist/sales-channel/steps/create-default-sales-channel.js +22 -0
- package/dist/sales-channel/steps/index.d.ts +1 -0
- package/dist/sales-channel/steps/index.js +1 -0
- package/dist/stock-location/index.d.ts +2 -0
- package/dist/stock-location/index.js +18 -0
- package/dist/stock-location/steps/create-stock-locations.d.ts +3 -0
- package/dist/stock-location/steps/create-stock-locations.js +17 -0
- package/dist/stock-location/steps/delete-stock-locations.d.ts +2 -0
- package/dist/stock-location/steps/delete-stock-locations.js +17 -0
- package/dist/stock-location/steps/index.d.ts +2 -0
- package/dist/stock-location/steps/index.js +18 -0
- package/dist/stock-location/workflows/create-stock-locations.d.ts +7 -0
- package/dist/stock-location/workflows/create-stock-locations.js +10 -0
- package/dist/stock-location/workflows/delete-stock-locations.d.ts +6 -0
- package/dist/stock-location/workflows/delete-stock-locations.js +14 -0
- package/dist/stock-location/workflows/index.d.ts +2 -0
- package/dist/stock-location/workflows/index.js +18 -0
- package/dist/user/workflows/create-user-account.d.ts +8 -0
- package/dist/user/workflows/create-user-account.js +17 -0
- package/dist/user/workflows/index.d.ts +2 -1
- package/dist/user/workflows/index.js +2 -1
- package/package.json +6 -6
- package/dist/inventory/steps/deatach-inventory-items.d.ts +0 -2
- package/dist/inventory/steps/deatach-inventory-items.js +0 -35
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DeleteEntityInput } from "@medusajs/modules-sdk";
|
|
2
|
+
type RemoveRemoteLinksStepInput = DeleteEntityInput | DeleteEntityInput[];
|
|
3
|
+
export declare const removeRemoteLinkStepId = "remove-remote-links";
|
|
4
|
+
export declare const removeRemoteLinkStep: import("@medusajs/workflows-sdk").StepFunction<RemoveRemoteLinksStepInput, undefined>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeRemoteLinkStep = exports.removeRemoteLinkStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/utils");
|
|
6
|
+
exports.removeRemoteLinkStepId = "remove-remote-links";
|
|
7
|
+
exports.removeRemoteLinkStep = (0, workflows_sdk_1.createStep)(exports.removeRemoteLinkStepId, async (data, { container }) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const entries = Array.isArray(data) ? data : [data];
|
|
10
|
+
const grouped = {};
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
for (const moduleName of Object.keys(entry)) {
|
|
13
|
+
grouped[moduleName] ?? (grouped[moduleName] = {});
|
|
14
|
+
for (const linkableKey of Object.keys(entry[moduleName])) {
|
|
15
|
+
(_a = grouped[moduleName])[linkableKey] ?? (_a[linkableKey] = []);
|
|
16
|
+
const keys = Array.isArray(entry[moduleName][linkableKey])
|
|
17
|
+
? entry[moduleName][linkableKey]
|
|
18
|
+
: [entry[moduleName][linkableKey]];
|
|
19
|
+
grouped[moduleName][linkableKey] = grouped[moduleName][linkableKey].concat(keys);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const link = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
24
|
+
await link.delete(grouped);
|
|
25
|
+
return new workflows_sdk_1.StepResponse(void 0, grouped);
|
|
26
|
+
}, async (removedLinks, { container }) => {
|
|
27
|
+
if (!removedLinks) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const link = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
31
|
+
await link.restore(removedLinks);
|
|
32
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./steps"), exports);
|
|
18
|
+
__exportStar(require("./workflows"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateStoreDTO } from "@medusajs/types";
|
|
2
|
+
type CreateDefaultStoreStepInput = {
|
|
3
|
+
store: CreateStoreDTO;
|
|
4
|
+
};
|
|
5
|
+
export declare const createDefaultStoreStepId = "create-default-store";
|
|
6
|
+
export declare const createDefaultStoreStep: import("@medusajs/workflows-sdk").StepFunction<CreateDefaultStoreStepInput, any>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultStoreStep = exports.createDefaultStoreStepId = void 0;
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
6
|
+
const store_1 = require("../../store");
|
|
7
|
+
exports.createDefaultStoreStepId = "create-default-store";
|
|
8
|
+
exports.createDefaultStoreStep = (0, workflows_sdk_1.createStep)(exports.createDefaultStoreStepId, async (data, { container }) => {
|
|
9
|
+
const storeService = container.resolve(modules_sdk_1.ModuleRegistrationName.STORE);
|
|
10
|
+
let shouldDelete = false;
|
|
11
|
+
let [store] = await storeService.list({}, { take: 1 });
|
|
12
|
+
if (!store) {
|
|
13
|
+
store = await (0, store_1.createStoresWorkflow)(container).run({
|
|
14
|
+
input: {
|
|
15
|
+
stores: [
|
|
16
|
+
{
|
|
17
|
+
// TODO: Revisit for a more sophisticated approach
|
|
18
|
+
...data.store,
|
|
19
|
+
supported_currency_codes: ["usd"],
|
|
20
|
+
default_currency_code: "usd",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
shouldDelete = true;
|
|
26
|
+
}
|
|
27
|
+
return new workflows_sdk_1.StepResponse(store, { storeId: store.id, shouldDelete });
|
|
28
|
+
}, async (data, { container }) => {
|
|
29
|
+
if (!data || !data.shouldDelete) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.STORE);
|
|
33
|
+
await service.delete(data.storeId);
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-default-store";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-default-store"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultsWorkflow = exports.createDefaultsWorkflowID = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const sales_channel_1 = require("../../sales-channel");
|
|
6
|
+
const create_default_store_1 = require("../steps/create-default-store");
|
|
7
|
+
exports.createDefaultsWorkflowID = "create-defaults";
|
|
8
|
+
exports.createDefaultsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.createDefaultsWorkflowID, (input) => {
|
|
9
|
+
const salesChannel = (0, sales_channel_1.createDefaultSalesChannelStep)({
|
|
10
|
+
data: {
|
|
11
|
+
name: "Default Sales Channel",
|
|
12
|
+
description: "Created by Medusa",
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const store = (0, create_default_store_1.createDefaultStoreStep)({
|
|
16
|
+
store: {
|
|
17
|
+
default_sales_channel_id: salesChannel.id,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
return store;
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-defaults";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-defaults"), exports);
|
|
@@ -4,8 +4,16 @@ exports.updateTaxLinesStep = exports.updateTaxLinesStepId = void 0;
|
|
|
4
4
|
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
5
|
const workflows_1 = require("../workflows");
|
|
6
6
|
exports.updateTaxLinesStepId = "update-tax-lines-step";
|
|
7
|
-
exports.updateTaxLinesStep = (0, workflows_sdk_1.createStep)(exports.updateTaxLinesStepId, async (input, { container }) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
exports.updateTaxLinesStep = (0, workflows_sdk_1.createStep)(exports.updateTaxLinesStepId, async (input, { container, idempotencyKey }) => {
|
|
8
|
+
const { transaction } = await (0, workflows_1.updateTaxLinesWorkflow)(container).run({
|
|
9
|
+
input,
|
|
10
|
+
});
|
|
11
|
+
return new workflows_sdk_1.StepResponse(null, { transaction });
|
|
12
|
+
}, async (flow, { container }) => {
|
|
13
|
+
if (!flow) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
await (0, workflows_1.updateTaxLinesWorkflow)(container).cancel({
|
|
17
|
+
transaction: flow.transaction,
|
|
18
|
+
});
|
|
11
19
|
});
|
|
@@ -12,7 +12,7 @@ async function updateProductVariants({ container, data, }) {
|
|
|
12
12
|
productsVariants.push(...variantsUpdateData);
|
|
13
13
|
}
|
|
14
14
|
if (updateVariantsData.length) {
|
|
15
|
-
await productModuleService.
|
|
15
|
+
await productModuleService.upsertVariants(updateVariantsData);
|
|
16
16
|
}
|
|
17
17
|
return productsVariants;
|
|
18
18
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./api-key";
|
|
|
2
2
|
export * from "./auth";
|
|
3
3
|
export * from "./customer";
|
|
4
4
|
export * from "./customer-group";
|
|
5
|
+
export * from "./defaults";
|
|
5
6
|
export * from "./definition";
|
|
6
7
|
export * from "./definitions";
|
|
7
8
|
export * from "./fulfillment";
|
|
@@ -16,6 +17,7 @@ export * from "./promotion";
|
|
|
16
17
|
export * from "./region";
|
|
17
18
|
export * from "./sales-channel";
|
|
18
19
|
export * from "./shipping-options";
|
|
20
|
+
export * from "./stock-location";
|
|
19
21
|
export * from "./store";
|
|
20
22
|
export * from "./tax";
|
|
21
23
|
export * from "./user";
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./api-key"), exports);
|
|
|
31
31
|
__exportStar(require("./auth"), exports);
|
|
32
32
|
__exportStar(require("./customer"), exports);
|
|
33
33
|
__exportStar(require("./customer-group"), exports);
|
|
34
|
+
__exportStar(require("./defaults"), exports);
|
|
34
35
|
__exportStar(require("./definition"), exports);
|
|
35
36
|
__exportStar(require("./definitions"), exports);
|
|
36
37
|
__exportStar(require("./fulfillment"), exports);
|
|
@@ -45,6 +46,7 @@ __exportStar(require("./promotion"), exports);
|
|
|
45
46
|
__exportStar(require("./region"), exports);
|
|
46
47
|
__exportStar(require("./sales-channel"), exports);
|
|
47
48
|
__exportStar(require("./shipping-options"), exports);
|
|
49
|
+
__exportStar(require("./stock-location"), exports);
|
|
48
50
|
__exportStar(require("./store"), exports);
|
|
49
51
|
__exportStar(require("./tax"), exports);
|
|
50
52
|
__exportStar(require("./user"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from "./delete-inventory-items";
|
|
2
|
-
export * from "./deatach-inventory-items";
|
|
3
2
|
export * from "./attach-inventory-items";
|
|
4
3
|
export * from "./create-inventory-items";
|
|
5
4
|
export * from "./validate-singular-inventory-items-for-tags";
|
|
6
5
|
export * from "./create-inventory-levels";
|
|
7
6
|
export * from "./validate-inventory-locations";
|
|
7
|
+
export * from "./update-inventory-items";
|
|
8
8
|
export * from "./delete-inventory-levels";
|
|
9
|
+
export * from "./update-inventory-levels";
|
|
@@ -15,10 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./delete-inventory-items"), exports);
|
|
18
|
-
__exportStar(require("./deatach-inventory-items"), exports);
|
|
19
18
|
__exportStar(require("./attach-inventory-items"), exports);
|
|
20
19
|
__exportStar(require("./create-inventory-items"), exports);
|
|
21
20
|
__exportStar(require("./validate-singular-inventory-items-for-tags"), exports);
|
|
22
21
|
__exportStar(require("./create-inventory-levels"), exports);
|
|
23
22
|
__exportStar(require("./validate-inventory-locations"), exports);
|
|
23
|
+
__exportStar(require("./update-inventory-items"), exports);
|
|
24
24
|
__exportStar(require("./delete-inventory-levels"), exports);
|
|
25
|
+
__exportStar(require("./update-inventory-levels"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InventoryNext } from "@medusajs/types";
|
|
2
|
+
export declare const updateInventoryItemsStepId = "update-inventory-items-step";
|
|
3
|
+
export declare const updateInventoryItemsStep: import("@medusajs/workflows-sdk").StepFunction<InventoryNext.UpdateInventoryItemInput[], InventoryNext.InventoryItemDTO[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateInventoryItemsStep = exports.updateInventoryItemsStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/utils");
|
|
6
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
7
|
+
exports.updateInventoryItemsStepId = "update-inventory-items-step";
|
|
8
|
+
exports.updateInventoryItemsStep = (0, workflows_sdk_1.createStep)(exports.updateInventoryItemsStepId, async (input, { container }) => {
|
|
9
|
+
const inventoryService = container.resolve(modules_sdk_1.ModuleRegistrationName.INVENTORY);
|
|
10
|
+
const { selects, relations } = (0, utils_1.getSelectsAndRelationsFromObjectArray)(input);
|
|
11
|
+
const dataBeforeUpdate = await inventoryService.list({ id: input.map(({ id }) => id) }, {});
|
|
12
|
+
const updatedInventoryItems = await inventoryService.update(input);
|
|
13
|
+
return new workflows_sdk_1.StepResponse(updatedInventoryItems, {
|
|
14
|
+
dataBeforeUpdate,
|
|
15
|
+
selects,
|
|
16
|
+
relations,
|
|
17
|
+
});
|
|
18
|
+
}, async (revertInput, { container }) => {
|
|
19
|
+
if (!revertInput?.dataBeforeUpdate?.length) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const { dataBeforeUpdate, selects, relations } = revertInput;
|
|
23
|
+
const inventoryService = container.resolve(modules_sdk_1.ModuleRegistrationName.INVENTORY);
|
|
24
|
+
await inventoryService.update(dataBeforeUpdate.map((data) => (0, utils_1.convertItemResponseToUpdateRequest)(data, selects, relations)));
|
|
25
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InventoryNext } from "@medusajs/types";
|
|
2
|
+
export declare const updateInventoryLevelsStepId = "update-inventory-levels-step";
|
|
3
|
+
export declare const updateInventoryLevelsStep: import("@medusajs/workflows-sdk").StepFunction<InventoryNext.BulkUpdateInventoryLevelInput[], InventoryNext.InventoryLevelDTO[]>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateInventoryLevelsStep = exports.updateInventoryLevelsStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/utils");
|
|
6
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
7
|
+
exports.updateInventoryLevelsStepId = "update-inventory-levels-step";
|
|
8
|
+
exports.updateInventoryLevelsStep = (0, workflows_sdk_1.createStep)(exports.updateInventoryLevelsStepId, async (input, { container }) => {
|
|
9
|
+
const inventoryService = container.resolve(modules_sdk_1.ModuleRegistrationName.INVENTORY);
|
|
10
|
+
const { selects, relations } = (0, utils_1.getSelectsAndRelationsFromObjectArray)(input);
|
|
11
|
+
const dataBeforeUpdate = await inventoryService.listInventoryLevels({
|
|
12
|
+
$or: input.map(({ inventory_item_id, location_id }) => ({
|
|
13
|
+
inventory_item_id,
|
|
14
|
+
location_id,
|
|
15
|
+
})),
|
|
16
|
+
}, {});
|
|
17
|
+
const updatedLevels = await inventoryService.updateInventoryLevels(input);
|
|
18
|
+
return new workflows_sdk_1.StepResponse(updatedLevels, {
|
|
19
|
+
dataBeforeUpdate,
|
|
20
|
+
selects,
|
|
21
|
+
relations,
|
|
22
|
+
});
|
|
23
|
+
}, async (revertInput, { container }) => {
|
|
24
|
+
if (!revertInput?.dataBeforeUpdate?.length) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { dataBeforeUpdate, selects, relations } = revertInput;
|
|
28
|
+
const inventoryService = container.resolve(modules_sdk_1.ModuleRegistrationName.INVENTORY);
|
|
29
|
+
await inventoryService.updateInventoryLevels(dataBeforeUpdate.map((data) => (0, utils_1.convertItemResponseToUpdateRequest)(data, selects, relations)));
|
|
30
|
+
});
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteInventoryItemWorkflow = exports.deleteInventoryItemWorkflowId = void 0;
|
|
4
4
|
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
6
|
const steps_1 = require("../steps");
|
|
7
|
+
const remove_remote_links_1 = require("../../common/steps/remove-remote-links");
|
|
6
8
|
exports.deleteInventoryItemWorkflowId = "delete-inventory-item-workflow";
|
|
7
9
|
exports.deleteInventoryItemWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.deleteInventoryItemWorkflowId, (input) => {
|
|
8
10
|
(0, steps_1.deleteInventoryItemStep)(input);
|
|
9
|
-
(0,
|
|
11
|
+
(0, remove_remote_links_1.removeRemoteLinkStep)({
|
|
12
|
+
[modules_sdk_1.Modules.INVENTORY]: { inventory_item_id: input },
|
|
13
|
+
});
|
|
10
14
|
return input;
|
|
11
15
|
});
|
|
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./delete-inventory-items"), exports);
|
|
18
18
|
__exportStar(require("./create-inventory-items"), exports);
|
|
19
19
|
__exportStar(require("./create-inventory-levels"), exports);
|
|
20
|
+
__exportStar(require("./update-inventory-items"), exports);
|
|
20
21
|
__exportStar(require("./delete-inventory-levels"), exports);
|
|
22
|
+
__exportStar(require("./update-inventory-levels"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InventoryNext } from "@medusajs/types";
|
|
2
|
+
interface WorkflowInput {
|
|
3
|
+
updates: InventoryNext.UpdateInventoryItemInput[];
|
|
4
|
+
}
|
|
5
|
+
export declare const updateInventoryItemsWorkflowId = "update-inventory-items-workflow";
|
|
6
|
+
export declare const updateInventoryItemsWorkflow: import("@medusajs/workflows-sdk").ReturnWorkflow<WorkflowInput, InventoryNext.InventoryItemDTO[], Record<string, Function>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateInventoryItemsWorkflow = exports.updateInventoryItemsWorkflowId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const steps_1 = require("../steps");
|
|
6
|
+
exports.updateInventoryItemsWorkflowId = "update-inventory-items-workflow";
|
|
7
|
+
exports.updateInventoryItemsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.updateInventoryItemsWorkflowId, (input) => {
|
|
8
|
+
return (0, steps_1.updateInventoryItemsStep)(input.updates);
|
|
9
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InventoryLevelDTO, InventoryNext } from "@medusajs/types";
|
|
2
|
+
interface WorkflowInput {
|
|
3
|
+
updates: InventoryNext.BulkUpdateInventoryLevelInput[];
|
|
4
|
+
}
|
|
5
|
+
export declare const updateInventoryLevelsWorkflowId = "update-inventory-levels-workflow";
|
|
6
|
+
export declare const updateInventoryLevelsWorkflow: import("@medusajs/workflows-sdk").ReturnWorkflow<WorkflowInput, InventoryLevelDTO[], Record<string, Function>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateInventoryLevelsWorkflow = exports.updateInventoryLevelsWorkflowId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const update_inventory_levels_1 = require("../steps/update-inventory-levels");
|
|
6
|
+
exports.updateInventoryLevelsWorkflowId = "update-inventory-levels-workflow";
|
|
7
|
+
exports.updateInventoryLevelsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.updateInventoryLevelsWorkflowId, (input) => {
|
|
8
|
+
return (0, update_inventory_levels_1.updateInventoryLevelsStep)(input.updates);
|
|
9
|
+
});
|
|
@@ -6,14 +6,12 @@ const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
|
6
6
|
exports.deletePriceListsStepId = "delete-campaigns";
|
|
7
7
|
exports.deletePriceListsStep = (0, workflows_sdk_1.createStep)(exports.deletePriceListsStepId, async (ids, { container }) => {
|
|
8
8
|
const pricingModule = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
|
|
9
|
-
|
|
10
|
-
await pricingModule.deletePriceLists(ids);
|
|
9
|
+
await pricingModule.softDeletePriceLists(ids);
|
|
11
10
|
return new workflows_sdk_1.StepResponse(void 0, ids);
|
|
12
11
|
}, async (idsToRestore, { container }) => {
|
|
13
12
|
if (!idsToRestore?.length) {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
15
|
const pricingModule = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
|
|
17
|
-
|
|
18
|
-
// await pricingModule.restorePriceLists(idsToRestore)
|
|
16
|
+
await pricingModule.restorePriceLists(idsToRestore);
|
|
19
17
|
});
|
|
@@ -9,7 +9,7 @@ exports.getExistingPriceListsPriceIdsStep = (0, workflows_sdk_1.createStep)(expo
|
|
|
9
9
|
const priceListPriceIdsMap = {};
|
|
10
10
|
const pricingModule = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
|
|
11
11
|
const existingPrices = priceListIds.length
|
|
12
|
-
? await pricingModule.
|
|
12
|
+
? await pricingModule.listPrices({ price_list_id: priceListIds }, { relations: ["price_list"] })
|
|
13
13
|
: [];
|
|
14
14
|
for (const price of existingPrices) {
|
|
15
15
|
const priceListId = price.price_list.id;
|
|
@@ -9,14 +9,13 @@ exports.removePriceListPricesStep = (0, workflows_sdk_1.createStep)(exports.remo
|
|
|
9
9
|
return new workflows_sdk_1.StepResponse(null, []);
|
|
10
10
|
}
|
|
11
11
|
const pricingModule = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
|
|
12
|
-
const
|
|
13
|
-
await pricingModule.
|
|
14
|
-
return new workflows_sdk_1.StepResponse(null,
|
|
12
|
+
const prices = await pricingModule.listPrices({ id: ids }, { relations: ["price_list"] });
|
|
13
|
+
await pricingModule.softDeletePrices(prices.map((price) => price.id));
|
|
14
|
+
return new workflows_sdk_1.StepResponse(null, prices.map((price) => price.id));
|
|
15
15
|
}, async (ids, { container }) => {
|
|
16
|
-
if (!ids) {
|
|
16
|
+
if (!ids?.length) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
const pricingModule = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
|
|
20
|
-
|
|
21
|
-
// pricingModule.restorePrices(ids)
|
|
20
|
+
await pricingModule.restorePrices(ids);
|
|
22
21
|
});
|
|
@@ -28,19 +28,19 @@ exports.updatePriceListPricesStep = (0, workflows_sdk_1.createStep)(exports.upda
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
const existingPrices = priceIds.length
|
|
31
|
-
? await pricingModule.
|
|
31
|
+
? await pricingModule.listPrices({ id: priceIds }, { relations: ["price_list"] })
|
|
32
32
|
: [];
|
|
33
|
-
const
|
|
33
|
+
const priceListPricesMap = new Map();
|
|
34
34
|
const dataBeforePriceUpdate = [];
|
|
35
35
|
for (const price of existingPrices) {
|
|
36
36
|
const priceListId = price.price_list.id;
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const prices = priceListPricesMap.get(priceListId) || [];
|
|
38
|
+
priceListPricesMap.set(priceListId, prices);
|
|
39
39
|
}
|
|
40
|
-
for (const [priceListId,
|
|
40
|
+
for (const [priceListId, prices] of Object.entries(priceListPricesMap)) {
|
|
41
41
|
dataBeforePriceUpdate.push({
|
|
42
42
|
price_list_id: priceListId,
|
|
43
|
-
prices: (0, utils_1.buildPriceSetPricesForModule)(
|
|
43
|
+
prices: (0, utils_1.buildPriceSetPricesForModule)(prices),
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
await pricingModule.updatePriceListPrices(priceListPricesToUpdate);
|
|
@@ -36,23 +36,23 @@ exports.upsertPriceListPricesStep = (0, workflows_sdk_1.createStep)(exports.upse
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
const
|
|
39
|
+
const updatedPrices = await pricingModule.listPrices({
|
|
40
40
|
id: priceListPricesToUpdate
|
|
41
41
|
.map((priceListData) => priceListData.prices.map((price) => price.id))
|
|
42
42
|
.filter(Boolean)
|
|
43
43
|
.flat(1),
|
|
44
44
|
}, { relations: ["price_list"] });
|
|
45
|
-
const
|
|
45
|
+
const priceListPricesMap = new Map();
|
|
46
46
|
const dataBeforePriceUpdate = [];
|
|
47
|
-
for (const
|
|
48
|
-
const priceListId =
|
|
49
|
-
const
|
|
50
|
-
|
|
47
|
+
for (const updatedPrice of updatedPrices) {
|
|
48
|
+
const priceListId = updatedPrice.price_list.id;
|
|
49
|
+
const prices = priceListPricesMap.get(priceListId) || [];
|
|
50
|
+
priceListPricesMap.set(priceListId, prices);
|
|
51
51
|
}
|
|
52
|
-
for (const [priceListId,
|
|
52
|
+
for (const [priceListId, prices] of Object.entries(priceListPricesMap)) {
|
|
53
53
|
dataBeforePriceUpdate.push({
|
|
54
54
|
price_list_id: priceListId,
|
|
55
|
-
prices: (0, utils_1.buildPriceSetPricesForModule)(
|
|
55
|
+
prices: (0, utils_1.buildPriceSetPricesForModule)(prices),
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
// TODO: `addPriceListPrices` will return a list of price lists
|
|
@@ -6,24 +6,20 @@ const utils_1 = require("@medusajs/utils");
|
|
|
6
6
|
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
7
7
|
exports.removeVariantPricingLinkStepId = "remove-variant-pricing-link";
|
|
8
8
|
exports.removeVariantPricingLinkStep = (0, workflows_sdk_1.createStep)(exports.removeVariantPricingLinkStepId, async (data, { container }) => {
|
|
9
|
+
if (!data.variant_ids.length) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
9
12
|
const remoteLink = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await remoteLink.delete(links.map((link) => link.id));
|
|
15
|
-
return new workflows_sdk_1.StepResponse(void 0, links);
|
|
13
|
+
await remoteLink.delete({
|
|
14
|
+
[modules_sdk_1.Modules.PRODUCT]: { variant_id: data.variant_ids },
|
|
15
|
+
});
|
|
16
|
+
return new workflows_sdk_1.StepResponse(void 0, data.variant_ids);
|
|
16
17
|
}, async (prevData, { container }) => {
|
|
17
18
|
if (!prevData?.length) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
const remoteLink = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
21
|
-
await remoteLink.
|
|
22
|
-
[modules_sdk_1.Modules.PRODUCT]: {
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
[modules_sdk_1.Modules.PRICING]: {
|
|
26
|
-
price_set_id: entry.price_set_id,
|
|
27
|
-
},
|
|
28
|
-
})));
|
|
22
|
+
await remoteLink.restore({
|
|
23
|
+
[modules_sdk_1.Modules.PRODUCT]: { variant_id: prevData },
|
|
24
|
+
});
|
|
29
25
|
});
|
|
@@ -4,5 +4,5 @@ type UpdateProductOptionsStepInput = {
|
|
|
4
4
|
update: ProductTypes.UpdateProductOptionDTO;
|
|
5
5
|
};
|
|
6
6
|
export declare const updateProductOptionsStepId = "update-product-options";
|
|
7
|
-
export declare const updateProductOptionsStep: import("@medusajs/workflows-sdk").StepFunction<UpdateProductOptionsStepInput,
|
|
7
|
+
export declare const updateProductOptionsStep: import("@medusajs/workflows-sdk").StepFunction<UpdateProductOptionsStepInput, ProductTypes.ProductOptionDTO[]>;
|
|
8
8
|
export {};
|
|
@@ -14,19 +14,12 @@ exports.updateProductOptionsStep = (0, workflows_sdk_1.createStep)(exports.updat
|
|
|
14
14
|
select: selects,
|
|
15
15
|
relations,
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
// const productOptions = await service.updateOptions(data.selector, data.update)
|
|
19
|
-
const productOptions = [];
|
|
17
|
+
const productOptions = await service.updateOptions(data.selector, data.update);
|
|
20
18
|
return new workflows_sdk_1.StepResponse(productOptions, prevData);
|
|
21
19
|
}, async (prevData, { container }) => {
|
|
22
20
|
if (!prevData?.length) {
|
|
23
21
|
return;
|
|
24
22
|
}
|
|
25
23
|
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.PRODUCT);
|
|
26
|
-
|
|
27
|
-
// await service.upsertOptions(
|
|
28
|
-
// prevData.map((r) => ({
|
|
29
|
-
// ...r,
|
|
30
|
-
// }))
|
|
31
|
-
// )
|
|
24
|
+
await service.upsertOptions(prevData);
|
|
32
25
|
});
|
|
@@ -4,5 +4,5 @@ type UpdateProductVariantsStepInput = {
|
|
|
4
4
|
update: ProductTypes.UpdateProductVariantDTO;
|
|
5
5
|
};
|
|
6
6
|
export declare const updateProductVariantsStepId = "update-product-variants";
|
|
7
|
-
export declare const updateProductVariantsStep: import("@medusajs/workflows-sdk").StepFunction<UpdateProductVariantsStepInput,
|
|
7
|
+
export declare const updateProductVariantsStep: import("@medusajs/workflows-sdk").StepFunction<UpdateProductVariantsStepInput, ProductTypes.ProductVariantDTO[]>;
|
|
8
8
|
export {};
|
|
@@ -14,19 +14,12 @@ exports.updateProductVariantsStep = (0, workflows_sdk_1.createStep)(exports.upda
|
|
|
14
14
|
select: selects,
|
|
15
15
|
relations,
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
// const productVariants = await service.updateVariants(data.selector, data.update)
|
|
19
|
-
const productVariants = [];
|
|
17
|
+
const productVariants = await service.updateVariants(data.selector, data.update);
|
|
20
18
|
return new workflows_sdk_1.StepResponse(productVariants, prevData);
|
|
21
19
|
}, async (prevData, { container }) => {
|
|
22
20
|
if (!prevData?.length) {
|
|
23
21
|
return;
|
|
24
22
|
}
|
|
25
23
|
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.PRODUCT);
|
|
26
|
-
|
|
27
|
-
// await service.upsertVariants(
|
|
28
|
-
// prevData.map((r) => ({
|
|
29
|
-
// ...r,
|
|
30
|
-
// }))
|
|
31
|
-
// )
|
|
24
|
+
await service.upsertVariants(prevData);
|
|
32
25
|
});
|
|
@@ -5,7 +5,6 @@ const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
|
5
5
|
const steps_1 = require("../steps");
|
|
6
6
|
exports.deleteProductVariantsWorkflowId = "delete-product-variants";
|
|
7
7
|
exports.deleteProductVariantsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.deleteProductVariantsWorkflowId, (input) => {
|
|
8
|
-
// Question: Should we also remove the price set manually, or would that be cascaded?
|
|
9
8
|
(0, steps_1.removeVariantPricingLinkStep)({ variant_ids: input.ids });
|
|
10
9
|
return (0, steps_1.deleteProductVariantsStep)(input.ids);
|
|
11
10
|
});
|
|
@@ -11,8 +11,6 @@ exports.deleteProductsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.del
|
|
|
11
11
|
.flatMap((product) => product.variants)
|
|
12
12
|
.map((variant) => variant.id);
|
|
13
13
|
});
|
|
14
|
-
// Question: Should we also remove the price set manually, or would that be cascaded?
|
|
15
|
-
// Question: Since we soft-delete the product, how do we restore the product with the prices and the links?
|
|
16
14
|
(0, steps_1.removeVariantPricingLinkStep)({ variant_ids: variantsToBeDeleted });
|
|
17
15
|
return (0, steps_1.deleteProductsStep)(input.ids);
|
|
18
16
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateSalesChannelDTO } from "@medusajs/types";
|
|
2
|
+
interface StepInput {
|
|
3
|
+
data: CreateSalesChannelDTO;
|
|
4
|
+
}
|
|
5
|
+
export declare const createDefaultSalesChannelStepId = "create-default-sales-channel";
|
|
6
|
+
export declare const createDefaultSalesChannelStep: import("@medusajs/workflows-sdk").StepFunction<StepInput, import("@medusajs/types").SalesChannelDTO>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultSalesChannelStep = exports.createDefaultSalesChannelStepId = void 0;
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
6
|
+
exports.createDefaultSalesChannelStepId = "create-default-sales-channel";
|
|
7
|
+
exports.createDefaultSalesChannelStep = (0, workflows_sdk_1.createStep)(exports.createDefaultSalesChannelStepId, async (input, { container }) => {
|
|
8
|
+
const salesChannelService = container.resolve(modules_sdk_1.ModuleRegistrationName.SALES_CHANNEL);
|
|
9
|
+
let shouldDelete = false;
|
|
10
|
+
let [salesChannel] = await salesChannelService.list({}, { take: 1 });
|
|
11
|
+
if (!salesChannel) {
|
|
12
|
+
salesChannel = await salesChannelService.create(input.data);
|
|
13
|
+
shouldDelete = true;
|
|
14
|
+
}
|
|
15
|
+
return new workflows_sdk_1.StepResponse(salesChannel, { id: salesChannel.id, shouldDelete });
|
|
16
|
+
}, async (data, { container }) => {
|
|
17
|
+
if (!data?.id || !data.shouldDelete) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.SALES_CHANNEL);
|
|
21
|
+
await service.delete(data.id);
|
|
22
|
+
});
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./associate-products-with-channels"), exports);
|
|
18
|
+
__exportStar(require("./create-default-sales-channel"), exports);
|
|
18
19
|
__exportStar(require("./create-sales-channels"), exports);
|
|
19
20
|
__exportStar(require("./delete-sales-channels"), exports);
|
|
20
21
|
__exportStar(require("./update-sales-channels"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./steps"), exports);
|
|
18
|
+
__exportStar(require("./workflows"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CreateStockLocationInput } from "@medusajs/types";
|
|
2
|
+
export declare const createStockLocationsStepId = "create-stock-locations";
|
|
3
|
+
export declare const createStockLocations: import("@medusajs/workflows-sdk").StepFunction<CreateStockLocationInput[], import("@medusajs/types").StockLocationDTO[]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStockLocations = exports.createStockLocationsStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
6
|
+
exports.createStockLocationsStepId = "create-stock-locations";
|
|
7
|
+
exports.createStockLocations = (0, workflows_sdk_1.createStep)(exports.createStockLocationsStepId, async (data, { container }) => {
|
|
8
|
+
const stockLocationService = container.resolve(modules_sdk_1.ModuleRegistrationName.STOCK_LOCATION);
|
|
9
|
+
const created = await stockLocationService.create(data);
|
|
10
|
+
return new workflows_sdk_1.StepResponse(created, created.map((i) => i.id));
|
|
11
|
+
}, async (createdStockLocationIds, { container }) => {
|
|
12
|
+
if (!createdStockLocationIds?.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const stockLocationService = container.resolve(modules_sdk_1.ModuleRegistrationName.STOCK_LOCATION);
|
|
16
|
+
await stockLocationService.delete(createdStockLocationIds);
|
|
17
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteStockLocationsStep = exports.deleteStockLocationsStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
6
|
+
exports.deleteStockLocationsStepId = "delete-stock-locations-step";
|
|
7
|
+
exports.deleteStockLocationsStep = (0, workflows_sdk_1.createStep)(exports.deleteStockLocationsStepId, async (input, { container }) => {
|
|
8
|
+
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.STOCK_LOCATION);
|
|
9
|
+
await service.softDelete(input);
|
|
10
|
+
return new workflows_sdk_1.StepResponse(void 0, input);
|
|
11
|
+
}, async (deletedLocaitonIds, { container }) => {
|
|
12
|
+
if (!deletedLocaitonIds?.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const service = container.resolve(modules_sdk_1.ModuleRegistrationName.STOCK_LOCATION);
|
|
16
|
+
await service.restore(deletedLocaitonIds);
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-stock-locations"), exports);
|
|
18
|
+
__exportStar(require("./delete-stock-locations"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateStockLocationInput } from "@medusajs/types";
|
|
2
|
+
interface WorkflowInput {
|
|
3
|
+
locations: CreateStockLocationInput[];
|
|
4
|
+
}
|
|
5
|
+
export declare const createStockLocationsWorkflowId = "create-stock-locations-workflow";
|
|
6
|
+
export declare const createStockLocationsWorkflow: import("@medusajs/workflows-sdk").ReturnWorkflow<WorkflowInput, import("@medusajs/types").StockLocationDTO[], Record<string, Function>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStockLocationsWorkflow = exports.createStockLocationsWorkflowId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const steps_1 = require("../steps");
|
|
6
|
+
exports.createStockLocationsWorkflowId = "create-stock-locations-workflow";
|
|
7
|
+
exports.createStockLocationsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.createStockLocationsWorkflowId, (input) => {
|
|
8
|
+
const locations = (0, steps_1.createStockLocations)(input.locations);
|
|
9
|
+
return locations;
|
|
10
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
interface WorkflowInput {
|
|
2
|
+
ids: string[];
|
|
3
|
+
}
|
|
4
|
+
export declare const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow";
|
|
5
|
+
export declare const deleteStockLocationsWorkflow: import("@medusajs/workflows-sdk").ReturnWorkflow<WorkflowInput, void, Record<string, Function>>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteStockLocationsWorkflow = exports.deleteStockLocationsWorkflowId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
6
|
+
const steps_1 = require("../steps");
|
|
7
|
+
const remove_remote_links_1 = require("../../common/steps/remove-remote-links");
|
|
8
|
+
exports.deleteStockLocationsWorkflowId = "delete-stock-locations-workflow";
|
|
9
|
+
exports.deleteStockLocationsWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.deleteStockLocationsWorkflowId, (input) => {
|
|
10
|
+
(0, steps_1.deleteStockLocationsStep)(input.ids);
|
|
11
|
+
(0, remove_remote_links_1.removeRemoteLinkStep)({
|
|
12
|
+
[modules_sdk_1.Modules.STOCK_LOCATION]: { stock_location_id: input.ids },
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-stock-locations"), exports);
|
|
18
|
+
__exportStar(require("./delete-stock-locations"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateUserDTO, UserDTO } from "@medusajs/types";
|
|
2
|
+
type WorkflowInput = {
|
|
3
|
+
authUserId: string;
|
|
4
|
+
userData: CreateUserDTO;
|
|
5
|
+
};
|
|
6
|
+
export declare const createUserAccountWorkflowId = "create-user-account";
|
|
7
|
+
export declare const createUserAccountWorkflow: import("@medusajs/workflows-sdk").ReturnWorkflow<WorkflowInput, UserDTO, Record<string, Function>>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUserAccountWorkflow = exports.createUserAccountWorkflowId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
5
|
+
const steps_1 = require("../../auth/steps");
|
|
6
|
+
const steps_2 = require("../steps");
|
|
7
|
+
exports.createUserAccountWorkflowId = "create-user-account";
|
|
8
|
+
exports.createUserAccountWorkflow = (0, workflows_sdk_1.createWorkflow)(exports.createUserAccountWorkflowId, (input) => {
|
|
9
|
+
const users = (0, steps_2.createUsersStep)([input.userData]);
|
|
10
|
+
const user = (0, workflows_sdk_1.transform)(users, (users) => users[0]);
|
|
11
|
+
(0, steps_1.setAuthAppMetadataStep)({
|
|
12
|
+
authUserId: input.authUserId,
|
|
13
|
+
key: "user_id",
|
|
14
|
+
value: user.id,
|
|
15
|
+
});
|
|
16
|
+
return user;
|
|
17
|
+
});
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./create-user-account"), exports);
|
|
18
18
|
__exportStar(require("./create-users"), exports);
|
|
19
|
+
__exportStar(require("./delete-users"), exports);
|
|
19
20
|
__exportStar(require("./update-users"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/core-flows",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Set of workflow definitions for Medusa",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "Medusa",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@medusajs/types": "^1.11.
|
|
24
|
+
"@medusajs/types": "^1.11.15",
|
|
25
25
|
"cross-env": "^5.2.1",
|
|
26
26
|
"jest": "^29.6.3",
|
|
27
27
|
"rimraf": "^5.0.1",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"typescript": "^5.1.6"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@medusajs/modules-sdk": "^1.12.
|
|
33
|
-
"@medusajs/orchestration": "^0.5.
|
|
34
|
-
"@medusajs/utils": "^1.11.
|
|
35
|
-
"@medusajs/workflows-sdk": "^0.1.
|
|
32
|
+
"@medusajs/modules-sdk": "^1.12.10",
|
|
33
|
+
"@medusajs/orchestration": "^0.5.6",
|
|
34
|
+
"@medusajs/utils": "^1.11.8",
|
|
35
|
+
"@medusajs/workflows-sdk": "^0.1.5",
|
|
36
36
|
"awilix": "^8.0.1",
|
|
37
37
|
"ulid": "^2.3.0"
|
|
38
38
|
},
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deatachInventoryItemStep = exports.deatachInventoryItemStepId = void 0;
|
|
4
|
-
const utils_1 = require("@medusajs/utils");
|
|
5
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
6
|
-
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
7
|
-
exports.deatachInventoryItemStepId = "deattach-inventory-items-step";
|
|
8
|
-
exports.deatachInventoryItemStep = (0, workflows_sdk_1.createStep)(exports.deatachInventoryItemStepId, async (ids, { container }) => {
|
|
9
|
-
const remoteLink = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
10
|
-
const linkModule = remoteLink.getLinkModule(modules_sdk_1.Modules.PRODUCT, "variant_id", modules_sdk_1.Modules.INVENTORY, "inventory_item_id");
|
|
11
|
-
const links = (await linkModule.list({ inventory_item_id: ids }, { select: ["variant_id", "inventory_item_id"] }));
|
|
12
|
-
await remoteLink.dismiss(links.map(({ inventory_item_id, variant_id }) => ({
|
|
13
|
-
[modules_sdk_1.Modules.PRODUCT]: {
|
|
14
|
-
variant_id,
|
|
15
|
-
},
|
|
16
|
-
[modules_sdk_1.Modules.INVENTORY]: {
|
|
17
|
-
inventory_item_id,
|
|
18
|
-
},
|
|
19
|
-
})));
|
|
20
|
-
return new workflows_sdk_1.StepResponse(void 0, links);
|
|
21
|
-
}, async (input, { container }) => {
|
|
22
|
-
if (!input?.length) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const remoteLink = container.resolve(utils_1.ContainerRegistrationKeys.REMOTE_LINK);
|
|
26
|
-
const linkDefinitions = input.map(({ inventory_item_id, variant_id }) => ({
|
|
27
|
-
[modules_sdk_1.Modules.PRODUCT]: {
|
|
28
|
-
variant_id,
|
|
29
|
-
},
|
|
30
|
-
[modules_sdk_1.Modules.INVENTORY]: {
|
|
31
|
-
inventory_item_id,
|
|
32
|
-
},
|
|
33
|
-
}));
|
|
34
|
-
const links = await remoteLink.create(linkDefinitions);
|
|
35
|
-
});
|