feat: Remove sales channels from pub keys (#6876)
**What** - Add workflow + step for detaching sales channels from pub API keys - Tweak linking error message to be more helpful - Add `removeRemoteLink` step to delete API key workflow
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
|
||||
import { isObject, promiseAll, toPascalCase } from "@medusajs/utils"
|
||||
import { MedusaModule } from "./medusa-module"
|
||||
import { linkingErrorMessage } from "./utils/linking-error"
|
||||
|
||||
export type DeleteEntityInput = {
|
||||
[moduleName: string]: { [linkableKey: string]: string | string[] }
|
||||
@@ -353,7 +354,13 @@ export class RemoteLink {
|
||||
|
||||
if (!service) {
|
||||
throw new Error(
|
||||
`Module to link ${moduleA}[${moduleAKey}] and ${moduleB}[${moduleBKey}] was not found.`
|
||||
linkingErrorMessage({
|
||||
moduleA,
|
||||
moduleAKey,
|
||||
moduleB,
|
||||
moduleBKey,
|
||||
type: "link",
|
||||
})
|
||||
)
|
||||
} else if (!serviceLinks.has(service.__definition.key)) {
|
||||
serviceLinks.set(service.__definition.key, [])
|
||||
@@ -404,7 +411,13 @@ export class RemoteLink {
|
||||
|
||||
if (!service) {
|
||||
throw new Error(
|
||||
`Module to dismiss link ${moduleA}[${moduleAKey}] and ${moduleB}[${moduleBKey}] was not found.`
|
||||
linkingErrorMessage({
|
||||
moduleA,
|
||||
moduleAKey,
|
||||
moduleB,
|
||||
moduleBKey,
|
||||
type: "dismiss",
|
||||
})
|
||||
)
|
||||
} else if (!serviceLinks.has(service.__definition.key)) {
|
||||
serviceLinks.set(service.__definition.key, [])
|
||||
|
||||
24
packages/modules-sdk/src/utils/linking-error.ts
Normal file
24
packages/modules-sdk/src/utils/linking-error.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const typeToMethod = new Map([
|
||||
[`dismiss`, `dismiss`],
|
||||
[`link`, `create`],
|
||||
])
|
||||
|
||||
type LinkingErrorMessageInput = {
|
||||
moduleA: string
|
||||
moduleAKey: string
|
||||
moduleB: string
|
||||
moduleBKey: string
|
||||
type: "dismiss" | "link"
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Example: Module to dismiss salesChannel and apiKey by keys sales_channel_id and api_key_id was not found. Ensure the link exists, keys are correct, and the link is passed in the correct order to method 'remoteLink.dismiss'
|
||||
*/
|
||||
export const linkingErrorMessage = (input: LinkingErrorMessageInput) => {
|
||||
const { moduleA, moduleB, moduleAKey, moduleBKey, type } = input
|
||||
return `Module to type ${moduleA} and ${moduleB} by keys ${moduleAKey} and ${moduleBKey} was not found. Ensure the link exists, keys are correct, and link is passed in the correct order to method 'remoteLink.${typeToMethod.get(
|
||||
type
|
||||
)}'.
|
||||
`
|
||||
}
|
||||
Reference in New Issue
Block a user