-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
8fd1488
commit 1bcb13f
Showing
16 changed files
with
351 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
"@medusajs/core-flows": patch | ||
"@medusajs/link-modules": patch | ||
"@medusajs/modules-sdk": patch | ||
--- | ||
|
||
feat: Remove sales channels from pub keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/core-flows/src/api-key/steps/detach-sales-channels-from-publishable-keys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import { ContainerRegistrationKeys } from "@medusajs/utils" | ||
import { StepResponse, createStep } from "@medusajs/workflows-sdk" | ||
|
||
interface StepInput { | ||
links: { | ||
api_key_id: string | ||
sales_channel_ids: string[] | ||
}[] | ||
} | ||
|
||
export const detachApiKeysWithSalesChannelsStepId = | ||
"detach-sales-channels-with-api-keys" | ||
export const detachApiKeysWithSalesChannelsStep = createStep( | ||
detachApiKeysWithSalesChannelsStepId, | ||
async (input: StepInput, { container }) => { | ||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) | ||
|
||
const links = input.links | ||
.map((link) => { | ||
return link.sales_channel_ids.map((id) => { | ||
return { | ||
[Modules.API_KEY]: { | ||
publishable_key_id: link.api_key_id, | ||
}, | ||
[Modules.SALES_CHANNEL]: { | ||
sales_channel_id: id, | ||
}, | ||
} | ||
}) | ||
}) | ||
.flat() | ||
|
||
await remoteLink.dismiss(links) | ||
|
||
return new StepResponse(void 0, links) | ||
}, | ||
async (links, { container }) => { | ||
if (!links?.length) { | ||
return | ||
} | ||
|
||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) | ||
|
||
await remoteLink.create(links) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from "./associate-sales-channels-with-publishable-keys" | ||
export * from "./create-api-keys" | ||
export * from "./delete-api-keys" | ||
export * from "./detach-sales-channels-from-publishable-keys" | ||
export * from "./revoke-api-keys" | ||
export * from "./update-api-keys" | ||
export * from "./validate-sales-channel-exists" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/core-flows/src/api-key/workflows/remove-sales-channels-from-publishable-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
import { detachApiKeysWithSalesChannelsStep } from "../steps/detach-sales-channels-from-publishable-keys" | ||
|
||
type WorkflowInput = { | ||
data: { | ||
api_key_id: string | ||
sales_channel_ids: string[] | ||
}[] | ||
} | ||
|
||
export const removeSalesChannelsFromApiKeyWorkflowId = | ||
"remove-sales-channels-from-api-key" | ||
export const removeSalesChannelsFromApiKeyWorkflow = createWorkflow( | ||
removeSalesChannelsFromApiKeyWorkflowId, | ||
(input: WorkflowData<WorkflowInput>) => { | ||
detachApiKeysWithSalesChannelsStep({ links: input.data }) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.