medusa-strapi-plugin 0.0.13 → 0.0.16

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 (54) hide show
  1. package/.medusa/server/src/modules/strapi/service.js +34 -1
  2. package/CHANGELOG.md +79 -0
  3. package/package.json +1 -1
  4. package/src/admin/README.md +34 -0
  5. package/src/admin/lib/sdk.ts +9 -0
  6. package/src/admin/routes/strapi/page.tsx +44 -0
  7. package/src/admin/tsconfig.json +24 -0
  8. package/src/admin/vite-env.d.ts +1 -0
  9. package/src/api/README.md +123 -0
  10. package/src/api/admin/strapi/sync/route.ts +38 -0
  11. package/src/jobs/README.md +36 -0
  12. package/src/links/README.md +26 -0
  13. package/src/links/strapi-categories.ts +23 -0
  14. package/src/links/strapi-collections.ts +23 -0
  15. package/src/links/strapi-product-variants.ts +23 -0
  16. package/src/links/strapi-products.ts +23 -0
  17. package/src/modules/README.md +113 -0
  18. package/src/modules/strapi/index.ts +10 -0
  19. package/src/modules/strapi/loader/create-content-models.ts +144 -0
  20. package/src/modules/strapi/service.ts +576 -0
  21. package/src/providers/README.md +30 -0
  22. package/src/subscribers/README.md +54 -0
  23. package/src/subscribers/create-category.ts +25 -0
  24. package/src/subscribers/create-collection.ts +25 -0
  25. package/src/subscribers/create-product.ts +25 -0
  26. package/src/subscribers/create-variant.ts +25 -0
  27. package/src/subscribers/delete-category.ts +25 -0
  28. package/src/subscribers/delete-collection.ts +25 -0
  29. package/src/subscribers/delete-product.ts +25 -0
  30. package/src/subscribers/delete-variant.ts +25 -0
  31. package/src/subscribers/sync-categories.ts +44 -0
  32. package/src/subscribers/sync-collections.ts +44 -0
  33. package/src/subscribers/sync-products.ts +44 -0
  34. package/src/subscribers/update-category.ts +25 -0
  35. package/src/subscribers/update-collection.ts +25 -0
  36. package/src/subscribers/update-product.ts +25 -0
  37. package/src/subscribers/update-variant.ts +25 -0
  38. package/src/workflows/README.md +69 -0
  39. package/src/workflows/delete-categories-strapi.ts +20 -0
  40. package/src/workflows/delete-collections-strapi.ts +20 -0
  41. package/src/workflows/delete-product-variants-strapi.ts +20 -0
  42. package/src/workflows/delete-products-strapi.ts +20 -0
  43. package/src/workflows/steps/delete-categories-strapi.ts +29 -0
  44. package/src/workflows/steps/delete-collections-strapi.ts +31 -0
  45. package/src/workflows/steps/delete-product-variants-strapi.ts +31 -0
  46. package/src/workflows/steps/delete-products-strapi.ts +29 -0
  47. package/src/workflows/steps/upsert-categories-strapi.ts +84 -0
  48. package/src/workflows/steps/upsert-collections-strapi.ts +84 -0
  49. package/src/workflows/steps/upsert-product-variants-strapi.ts +83 -0
  50. package/src/workflows/steps/upsert-products-strapi.ts +81 -0
  51. package/src/workflows/upsert-categories-strapi.ts +30 -0
  52. package/src/workflows/upsert-collections-strapi.ts +30 -0
  53. package/src/workflows/upsert-product-variants-strapi.ts +30 -0
  54. package/src/workflows/upsert-products-strapi.ts +36 -0
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertProductsStrapiWorkflow } from "../workflows/upsert-products-strapi";
7
+
8
+ export default async function handleProductCreate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertProductsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ product_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product created in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product.created",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertProductVariantsStrapiWorkflow } from "../workflows/upsert-product-variants-strapi";
7
+
8
+ export default async function handleProductVariantCreate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertProductVariantsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ variant_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product Variant created in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-variant.created",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { deleteCategoriesStrapiWorkflow } from "../workflows/delete-categories-strapi";
7
+
8
+ export default async function handleCategoryDelete({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await deleteCategoriesStrapiWorkflow(container as any).run({
15
+ input: {
16
+ category_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Category deleted in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-category.deleted",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { deleteCollectionsStrapiWorkflow } from "../workflows/delete-collections-strapi";
7
+
8
+ export default async function handleCollectionDelete({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await deleteCollectionsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ collection_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Collection deleted in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-collection.deleted",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { deleteProductsStrapiWorkflow } from "../workflows/delete-products-strapi";
7
+
8
+ export default async function handleProductDelete({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await deleteProductsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ product_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product deleted in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product.deleted",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { deleteProductVariantsStrapiWorkflow } from "../workflows/delete-product-variants-strapi";
7
+
8
+ export default async function handleProductVariantDelete({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await deleteProductVariantsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ variant_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product variant deleted in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-variant.deleted",
25
+ };
@@ -0,0 +1,44 @@
1
+ import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
2
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
3
+ import { upsertCategoriesStrapiWorkflow } from "../workflows/upsert-categories-strapi";
4
+
5
+ export default async function syncCategoriesHandler({
6
+ container,
7
+ }: SubscriberArgs<Record<string, unknown>>) {
8
+ const query = container.resolve(ContainerRegistrationKeys.QUERY);
9
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
10
+
11
+ const batchSize = 100;
12
+ let hasMore = true;
13
+ let offset = 0;
14
+ let totalCount = 0;
15
+
16
+ while (hasMore) {
17
+ const { data: categories, metadata: { count } = {} } = await query.graph({
18
+ entity: "product_category",
19
+ fields: ["id"],
20
+ pagination: {
21
+ skip: offset,
22
+ take: batchSize,
23
+ },
24
+ });
25
+
26
+ if (categories.length) {
27
+ await upsertCategoriesStrapiWorkflow(container as any).run({
28
+ input: {
29
+ category_ids: categories.map((category) => category.id),
30
+ },
31
+ });
32
+ }
33
+
34
+ hasMore = categories.length === batchSize;
35
+ offset += batchSize;
36
+ totalCount = count ?? 0;
37
+ }
38
+
39
+ logger.log(`Synced ${totalCount} categories to Strapi`);
40
+ }
41
+
42
+ export const config: SubscriberConfig = {
43
+ event: "strapi-categories.sync",
44
+ };
@@ -0,0 +1,44 @@
1
+ import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
2
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
3
+ import { upsertCollectionsStrapiWorkflow } from "../workflows/upsert-collections-strapi";
4
+
5
+ export default async function syncCollectionsHandler({
6
+ container,
7
+ }: SubscriberArgs<Record<string, unknown>>) {
8
+ const query = container.resolve(ContainerRegistrationKeys.QUERY);
9
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
10
+
11
+ const batchSize = 100;
12
+ let hasMore = true;
13
+ let offset = 0;
14
+ let totalCount = 0;
15
+
16
+ while (hasMore) {
17
+ const { data: collections, metadata: { count } = {} } = await query.graph({
18
+ entity: "product_collection",
19
+ fields: ["id"],
20
+ pagination: {
21
+ skip: offset,
22
+ take: batchSize,
23
+ },
24
+ });
25
+
26
+ if (collections.length) {
27
+ await upsertCollectionsStrapiWorkflow(container as any).run({
28
+ input: {
29
+ collection_ids: collections.map((collection) => collection.id),
30
+ },
31
+ });
32
+ }
33
+
34
+ hasMore = collections.length === batchSize;
35
+ offset += batchSize;
36
+ totalCount = count ?? 0;
37
+ }
38
+
39
+ logger.log(`Synced ${totalCount} collections to Strapi`);
40
+ }
41
+
42
+ export const config: SubscriberConfig = {
43
+ event: "strapi-collections.sync",
44
+ };
@@ -0,0 +1,44 @@
1
+ import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
2
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
3
+ import { upsertProductsStrapiWorkflow } from "../workflows/upsert-products-strapi";
4
+
5
+ export default async function syncProductsHandler({
6
+ container,
7
+ }: SubscriberArgs<Record<string, unknown>>) {
8
+ const query = container.resolve(ContainerRegistrationKeys.QUERY);
9
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
10
+
11
+ const batchSize = 100;
12
+ let hasMore = true;
13
+ let offset = 0;
14
+ let totalCount = 0;
15
+
16
+ while (hasMore) {
17
+ const { data: products, metadata: { count } = {} } = await query.graph({
18
+ entity: "product",
19
+ fields: ["id"],
20
+ pagination: {
21
+ skip: offset,
22
+ take: batchSize,
23
+ },
24
+ });
25
+
26
+ if (products.length) {
27
+ await upsertProductsStrapiWorkflow(container as any).run({
28
+ input: {
29
+ product_ids: products.map((product) => product.id),
30
+ },
31
+ });
32
+ }
33
+
34
+ hasMore = products.length === batchSize;
35
+ offset += batchSize;
36
+ totalCount = count ?? 0;
37
+ }
38
+
39
+ logger.log(`Synced ${totalCount} products to Strapi`);
40
+ }
41
+
42
+ export const config: SubscriberConfig = {
43
+ event: "strapi-products.sync",
44
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertCategoriesStrapiWorkflow } from "../workflows/upsert-categories-strapi";
7
+
8
+ export default async function handleCategoryUpdate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertCategoriesStrapiWorkflow(container as any).run({
15
+ input: {
16
+ category_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Category updated in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-category.updated",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertCollectionsStrapiWorkflow } from "../workflows/upsert-collections-strapi";
7
+
8
+ export default async function handleCollectionUpdate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertCollectionsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ collection_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Collection updated in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-collection.updated",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertProductsStrapiWorkflow } from "../workflows/upsert-products-strapi";
7
+
8
+ export default async function handleProductUpdate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertProductsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ product_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product updated in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product.updated",
25
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ type SubscriberArgs,
3
+ type SubscriberConfig,
4
+ } from "@medusajs/framework";
5
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
6
+ import { upsertProductVariantsStrapiWorkflow } from "../workflows/upsert-product-variants-strapi";
7
+
8
+ export default async function handleProductVariantUpdate({
9
+ event: { data },
10
+ container,
11
+ }: SubscriberArgs<{ id: string }>) {
12
+ const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
13
+
14
+ await upsertProductVariantsStrapiWorkflow(container as any).run({
15
+ input: {
16
+ variant_ids: [data.id],
17
+ },
18
+ });
19
+
20
+ logger.log("Product Variant updated in Strapi");
21
+ }
22
+
23
+ export const config: SubscriberConfig = {
24
+ event: "product-variant.updated",
25
+ };
@@ -0,0 +1,69 @@
1
+ # Custom Workflows
2
+
3
+ A workflow is a series of queries and actions that complete a task.
4
+
5
+ The workflow is created in a TypeScript or JavaScript file under the `src/workflows` directory.
6
+
7
+ For example:
8
+
9
+ ```ts
10
+ import {
11
+ createStep,
12
+ createWorkflow,
13
+ WorkflowResponse,
14
+ StepResponse,
15
+ } from "@medusajs/framework/workflows-sdk";
16
+
17
+ const step1 = createStep("step-1", async () => {
18
+ return new StepResponse(`Hello from step one!`);
19
+ });
20
+
21
+ type WorkflowInput = {
22
+ name: string;
23
+ };
24
+
25
+ const step2 = createStep("step-2", async ({ name }: WorkflowInput) => {
26
+ return new StepResponse(`Hello ${name} from step two!`);
27
+ });
28
+
29
+ type WorkflowOutput = {
30
+ message1: string;
31
+ message2: string;
32
+ };
33
+
34
+ const helloWorldWorkflow = createWorkflow(
35
+ "hello-world",
36
+ (input: WorkflowInput) => {
37
+ const greeting1 = step1();
38
+ const greeting2 = step2(input);
39
+
40
+ return new WorkflowResponse({
41
+ message1: greeting1,
42
+ message2: greeting2,
43
+ });
44
+ },
45
+ );
46
+
47
+ export default helloWorldWorkflow;
48
+ ```
49
+
50
+ ## Execute Workflow
51
+
52
+ You can execute the workflow from other resources, such as API routes, scheduled jobs, or subscribers.
53
+
54
+ For example, to execute the workflow in an API route:
55
+
56
+ ```ts
57
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework";
58
+ import myWorkflow from "../../../workflows/hello-world";
59
+
60
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
61
+ const { result } = await myWorkflow(req.scope).run({
62
+ input: {
63
+ name: req.query.name as string,
64
+ },
65
+ });
66
+
67
+ res.send(result);
68
+ }
69
+ ```
@@ -0,0 +1,20 @@
1
+ import {
2
+ createWorkflow,
3
+ WorkflowResponse,
4
+ } from "@medusajs/framework/workflows-sdk";
5
+ import { deleteCategoriesStrapiStep } from "./steps/delete-categories-strapi";
6
+
7
+ type WorkflowInput = {
8
+ category_ids: string[];
9
+ };
10
+
11
+ export const deleteCategoriesStrapiWorkflow = createWorkflow(
12
+ { name: "delete-categories-strapi-workflow" },
13
+ (input: WorkflowInput) => {
14
+ const strapiCategories = deleteCategoriesStrapiStep({
15
+ category_ids: input.category_ids,
16
+ });
17
+
18
+ return new WorkflowResponse(strapiCategories);
19
+ },
20
+ );
@@ -0,0 +1,20 @@
1
+ import {
2
+ createWorkflow,
3
+ WorkflowResponse,
4
+ } from "@medusajs/framework/workflows-sdk";
5
+ import { deleteCollectionsStrapiStep } from "./steps/delete-collections-strapi";
6
+
7
+ type WorkflowInput = {
8
+ collection_ids: string[];
9
+ };
10
+
11
+ export const deleteCollectionsStrapiWorkflow = createWorkflow(
12
+ { name: "delete-collections-strapi-workflow" },
13
+ (input: WorkflowInput) => {
14
+ const strapiCollections = deleteCollectionsStrapiStep({
15
+ collection_ids: input.collection_ids,
16
+ });
17
+
18
+ return new WorkflowResponse(strapiCollections);
19
+ },
20
+ );
@@ -0,0 +1,20 @@
1
+ import {
2
+ createWorkflow,
3
+ WorkflowResponse,
4
+ } from "@medusajs/framework/workflows-sdk";
5
+ import { deleteProductVariantsStrapiStep } from "./steps/delete-product-variants-strapi";
6
+
7
+ type WorkflowInput = {
8
+ variant_ids: string[];
9
+ };
10
+
11
+ export const deleteProductVariantsStrapiWorkflow = createWorkflow(
12
+ { name: "delete-product-variants-strapi-workflow" },
13
+ (input: WorkflowInput) => {
14
+ const strapiProductVariants = deleteProductVariantsStrapiStep({
15
+ variant_ids: input.variant_ids,
16
+ });
17
+
18
+ return new WorkflowResponse(strapiProductVariants);
19
+ },
20
+ );
@@ -0,0 +1,20 @@
1
+ import {
2
+ createWorkflow,
3
+ WorkflowResponse,
4
+ } from "@medusajs/framework/workflows-sdk";
5
+ import { deleteProductsStrapiStep } from "./steps/delete-products-strapi";
6
+
7
+ type WorkflowInput = {
8
+ product_ids: string[];
9
+ };
10
+
11
+ export const deleteProductsStrapiWorkflow = createWorkflow(
12
+ { name: "delete-products-strapi-workflow" },
13
+ (input: WorkflowInput) => {
14
+ const strapiProducts = deleteProductsStrapiStep({
15
+ product_ids: input.product_ids,
16
+ });
17
+
18
+ return new WorkflowResponse(strapiProducts);
19
+ },
20
+ );
@@ -0,0 +1,29 @@
1
+ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk";
2
+ import { STRAPI_MODULE } from "../../modules/strapi";
3
+ import StrapiModuleService from "../../modules/strapi/service";
4
+
5
+ type StepInput = {
6
+ category_ids: string[];
7
+ };
8
+
9
+ export const deleteCategoriesStrapiStep = createStep(
10
+ "delete-categories-strapi-step",
11
+ async (input: StepInput, { container }) => {
12
+ const strapiModuleService: StrapiModuleService =
13
+ container.resolve(STRAPI_MODULE);
14
+
15
+ const categories: (string | null)[] = [];
16
+
17
+ try {
18
+ for (const category_id of input.category_ids) {
19
+ categories.push(await strapiModuleService.deleteCategory(category_id));
20
+ }
21
+ } catch (e) {
22
+ return StepResponse.permanentFailure(
23
+ `Error deleting categories in Strapi: ${e.message}`,
24
+ );
25
+ }
26
+
27
+ return new StepResponse(categories, categories);
28
+ },
29
+ );
@@ -0,0 +1,31 @@
1
+ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk";
2
+ import { STRAPI_MODULE } from "../../modules/strapi";
3
+ import StrapiModuleService from "../../modules/strapi/service";
4
+
5
+ type StepInput = {
6
+ collection_ids: string[];
7
+ };
8
+
9
+ export const deleteCollectionsStrapiStep = createStep(
10
+ "delete-collections-strapi-step",
11
+ async (input: StepInput, { container }) => {
12
+ const strapiModuleService: StrapiModuleService =
13
+ container.resolve(STRAPI_MODULE);
14
+
15
+ const collections: (string | null)[] = [];
16
+
17
+ try {
18
+ for (const collection_id of input.collection_ids) {
19
+ collections.push(
20
+ await strapiModuleService.deleteCollection(collection_id),
21
+ );
22
+ }
23
+ } catch (e) {
24
+ return StepResponse.permanentFailure(
25
+ `Error deleting collections in Strapi: ${e.message}`,
26
+ );
27
+ }
28
+
29
+ return new StepResponse(collections, collections);
30
+ },
31
+ );
@@ -0,0 +1,31 @@
1
+ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk";
2
+ import { STRAPI_MODULE } from "../../modules/strapi";
3
+ import StrapiModuleService from "../../modules/strapi/service";
4
+
5
+ type StepInput = {
6
+ variant_ids: string[];
7
+ };
8
+
9
+ export const deleteProductVariantsStrapiStep = createStep(
10
+ "delete-product-variants-strapi-step",
11
+ async (input: StepInput, { container }) => {
12
+ const strapiModuleService: StrapiModuleService =
13
+ container.resolve(STRAPI_MODULE);
14
+
15
+ const variants: (string | null)[] = [];
16
+
17
+ try {
18
+ for (const variant_id of input.variant_ids) {
19
+ variants.push(
20
+ await strapiModuleService.deleteProductVariant(variant_id),
21
+ );
22
+ }
23
+ } catch (e) {
24
+ return StepResponse.permanentFailure(
25
+ `Error deleting product variants in Strapi: ${e.message}`,
26
+ );
27
+ }
28
+
29
+ return new StepResponse(variants, variants);
30
+ },
31
+ );
@@ -0,0 +1,29 @@
1
+ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk";
2
+ import { STRAPI_MODULE } from "../../modules/strapi";
3
+ import StrapiModuleService from "../../modules/strapi/service";
4
+
5
+ type StepInput = {
6
+ product_ids: string[];
7
+ };
8
+
9
+ export const deleteProductsStrapiStep = createStep(
10
+ "delete-products-strapi-step",
11
+ async (input: StepInput, { container }) => {
12
+ const strapiModuleService: StrapiModuleService =
13
+ container.resolve(STRAPI_MODULE);
14
+
15
+ const products: (string | null)[] = [];
16
+
17
+ try {
18
+ for (const product_id of input.product_ids) {
19
+ products.push(await strapiModuleService.deleteProduct(product_id));
20
+ }
21
+ } catch (e) {
22
+ return StepResponse.permanentFailure(
23
+ `Error deleting products in Strapi: ${e.message}`,
24
+ );
25
+ }
26
+
27
+ return new StepResponse(products, products);
28
+ },
29
+ );