Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

add 2 test block to registry

vholikf1eb4cf97f6a
diff --git a/packages/registry/registry.json b/packages/registry/registry.json
index ef257b451..8b7504544 100644
--- a/packages/registry/registry.json
+++ b/packages/registry/registry.json
@@ -7,7 +7,9 @@
"name": "block-1",
"description": "A block with a test module, product-test link, and API route.",
"dependencies": [],
- "registryDependencies": [],
+ "registryDependencies": [
+ "block-2"
+ ],
"docs": "## Test Block Configuration\n\nAdd the test module to your `medusa-config.ts`:\n\n```ts\nmodules: [\n {\n resolve: './modules/test',\n options: {\n apiKey: process.env.TEST_API_KEY,\n },\n },\n]\n```\n\n## Environment Variables\n\nAdd the following to your `.env` file:\n\n```\nTEST_API_KEY=your-api-key\n```",
"files": [
{
@@ -34,6 +36,43 @@
"categories": [
"test"
]
+ },
+ {
+ "name": "block-2",
+ "description": "A block with a sample module, product-sample link, workflow, and API route.",
+ "dependencies": [],
+ "registryDependencies": [],
+ "docs": "## Sample Block Configuration\n\nAdd the sample module to your `medusa-config.ts`:\n\n```ts\nmodules: [\n {\n resolve: './modules/sample',\n options: {\n apiKey: process.env.SAMPLE_API_KEY,\n },\n },\n]\n```\n\n## Environment Variables\n\nAdd the following to your `.env` file:\n\n```\nSAMPLE_API_KEY=your-api-key\n```",
+ "files": [
+ {
+ "path": "block-2/modules/sample/index.ts",
+ "type": "registry:module"
+ },
+ {
+ "path": "block-2/modules/sample/service.ts",
+ "type": "registry:module"
+ },
+ {
+ "path": "block-2/modules/sample/models/sample.ts",
+ "type": "registry:module"
+ },
+ {
+ "path": "block-2/links/product-sample.ts",
+ "type": "registry:link"
+ },
+ {
+ "path": "block-2/workflows/hello-world/hello-world.ts",
+ "type": "registry:workflow"
+ },
+ {
+ "path": "block-2/api/hello/workflow/route.ts",
+ "type": "registry:api"
+ }
+ ],
+ "categories": [
+ "sample",
+ "workflow"
+ ]
}
]
}
\ No newline at end of file
diff --git a/packages/registry/src/block-2/api/hello/workflow/route.ts b/packages/registry/src/block-2/api/hello/workflow/route.ts
new file mode 100644
index 000000000..3c33949a6
--- /dev/null
+++ b/packages/registry/src/block-2/api/hello/workflow/route.ts
@@ -0,0 +1,12 @@
+import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
+import helloWorldWorkflow from "../../../workflows/hello-world/hello-world"
+
+export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
+ const { result } = await helloWorldWorkflow(req.scope).run({
+ input: {
+ name: (req.query.name as string) || "World",
+ },
+ })
+
+ res.json(result)
+}
diff --git a/packages/registry/src/block-2/links/product-sample.ts b/packages/registry/src/block-2/links/product-sample.ts
new file mode 100644
index 000000000..d82a5f3b1
--- /dev/null
+++ b/packages/registry/src/block-2/links/product-sample.ts
@@ -0,0 +1,8 @@
+import { defineLink } from "@medusajs/framework/utils"
+import ProductModule from "@medusajs/medusa/product"
+import SampleModule from "../modules/sample"
+
+export default defineLink(
+ ProductModule.linkable.product,
+ SampleModule.linkable.sample
+)
diff --git a/packages/registry/src/block-2/modules/sample/index.ts b/packages/registry/src/block-2/modules/sample/index.ts
new file mode 100644
index 000000000..8d371eccc
--- /dev/null
+++ b/packages/registry/src/block-2/modules/sample/index.ts
@@ -0,0 +1,8 @@
+import { Module } from "@medusajs/framework/utils"
+import SampleModuleService from "./service"
+
+export const SAMPLE_MODULE = "sample"
+
+export default Module(SAMPLE_MODULE, {
+ service: SampleModuleService,
+})
diff --git a/packages/registry/src/block-2/modules/sample/models/sample.ts b/packages/registry/src/block-2/modules/sample/models/sample.ts
new file mode 100644
index 000000000..1b59c8180
--- /dev/null
+++ b/packages/registry/src/block-2/modules/sample/models/sample.ts
@@ -0,0 +1,8 @@
+import { model } from "@medusajs/framework/utils"
+
+const Sample = model.define("sample", {
+ id: model.id().primaryKey(),
+ name: model.text(),
+})
+
+export default Sample
diff --git a/packages/registry/src/block-2/modules/sample/service.ts b/packages/registry/src/block-2/modules/sample/service.ts
new file mode 100644
index 000000000..3d7c11168
--- /dev/null
+++ b/packages/registry/src/block-2/modules/sample/service.ts
@@ -0,0 +1,8 @@
+import { MedusaService } from "@medusajs/framework/utils"
+import Sample from "./models/sample"
+
+class SampleModuleService extends MedusaService({
+ Sample,
+}) {}
+
+export default SampleModuleService
diff --git a/packages/registry/src/block-2/workflows/hello-world/hello-world.ts b/packages/registry/src/block-2/workflows/hello-world/hello-world.ts
new file mode 100644
index 000000000..cdd3a15d0
--- /dev/null
+++ b/packages/registry/src/block-2/workflows/hello-world/hello-world.ts
@@ -0,0 +1,41 @@
+import {
+ createStep,
+ createWorkflow,
+ WorkflowResponse,
+ StepResponse,
+} from "@medusajs/framework/workflows-sdk"
+
+const step1 = createStep("step-1", async () => {
+ return new StepResponse(`Hello from step one!`)
+})
+
+type WorkflowInput = {
+ name: string
+}
+
+const step2 = createStep(
+ "step-2",
+ async ({ name }: WorkflowInput) => {
+ return new StepResponse(`Hello ${name} from step two!`)
+ }
+)
+
+type WorkflowOutput = {
+ message1: string
+ message2: string
+}
+
+const helloWorldWorkflow = createWorkflow(
+ "hello-world",
+ (input: WorkflowInput) => {
+ const greeting1 = step1()
+ const greeting2 = step2(input)
+
+ return new WorkflowResponse({
+ message1: greeting1,
+ message2: greeting2,
+ })
+ }
+)
+
+export default helloWorldWorkflow