chore: Inject sandbox handle in cloud config (#13879)

* chore: Inject sandbox handle in cloud config

* Create wet-seas-lie.md

* chore: rename medusaCloudOptions to cloud

* fix tests
This commit is contained in:
Oli Juhl
2025-10-29 10:02:37 +01:00
committed by GitHub
parent 85b1f3d43a
commit 1defb3c29b
7 changed files with 248 additions and 22 deletions

View File

@@ -15,6 +15,21 @@ import {
} from "@types"
import { MedusaCloudEmailNotificationProvider } from "../providers/medusa-cloud-email"
const validateCloudOptions = (options: NotificationModuleOptions["cloud"]) => {
const { api_key, endpoint, environment_handle, sandbox_handle } =
options ?? {}
if (!environment_handle && !sandbox_handle) {
return false
}
if (!api_key || !endpoint) {
return false
}
return true
}
const registrationFn = async (klass, container, pluginOptions) => {
container.register({
[NotificationProviderRegistrationPrefix + pluginOptions.id]: asFunction(
@@ -48,8 +63,11 @@ export default async ({
provider.options?.channels?.some((channel) => channel === "email")
)
if (!hasEmailProvider) {
const { api_key, endpoint, environment_handle } = options?.cloud ?? {}
if (api_key && endpoint && environment_handle) {
const shouldRegisterMedusaCloudEmailProvider = validateCloudOptions(
options?.cloud
)
if (shouldRegisterMedusaCloudEmailProvider) {
await registrationFn(MedusaCloudEmailNotificationProvider, container, {
options: options?.cloud,
id: "cloud",

View File

@@ -16,14 +16,23 @@ export class MedusaCloudEmailNotificationProvider extends AbstractNotificationPr
async send(
notification: NotificationTypes.ProviderSendNotificationDTO
): Promise<NotificationTypes.ProviderSendNotificationResultsDTO> {
const headers = {
"Content-Type": "application/json",
Authorization: `Basic ${this.options_.api_key}`,
}
if (this.options_.sandbox_handle) {
headers["x-medusa-sandbox-handle"] = this.options_.sandbox_handle
}
if (this.options_.environment_handle) {
headers["x-medusa-environment-handle"] = this.options_.environment_handle
}
try {
const response = await fetch(`${this.options_.endpoint}/send`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${this.options_.api_key}`,
"x-medusa-environment-handle": this.options_.environment_handle,
},
headers,
body: JSON.stringify({
to: notification.to,
from: notification.from,

View File

@@ -42,5 +42,6 @@ export type NotificationModuleOptions =
export type MedusaCloudEmailOptions = {
api_key: string
endpoint: string
environment_handle: string
environment_handle?: string
sandbox_handle?: string
}