Skip to content

Commit

Permalink
feat: deprecate remote link (#10768)
Browse files Browse the repository at this point in the history
Co-authored-by: Oli Juhl <[email protected]>
  • Loading branch information
thetutlage and olivermrbl authored Dec 30, 2024
1 parent 1e6d56b commit bbf790e
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 79 deletions.
8 changes: 8 additions & 0 deletions .changeset/metal-weeks-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/core-flows": patch
"@medusajs/framework": patch
"@medusajs/modules-sdk": patch
"@medusajs/utils": patch
---

Refactor/deprecate remote link
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const linkSalesChannelsToApiKeyStepId = "link-sales-channels-to-api-key"
export const linkSalesChannelsToApiKeyStep = createStep(
linkSalesChannelsToApiKeyStepId,
async (input: LinkWorkflowInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
if (!input || (!input.add?.length && !input.remove?.length)) {
return
}
Expand Down Expand Up @@ -56,7 +56,7 @@ export const linkSalesChannelsToApiKeyStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
if (prevData.linksToCreate.length) {
await remoteLink.dismiss(prevData.linksToCreate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const updateCartPromotionsStep = createStep(
updateCartPromotionsStepId,
async (data: UpdateCartPromotionStepInput, { container }) => {
const { promo_codes = [], id, action = PromotionActions.ADD } = data
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
Expand Down Expand Up @@ -94,7 +94,7 @@ export const updateCartPromotionsStep = createStep(
})
},
async (revertData, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

if (revertData?.dismissedLinks?.length) {
await remoteLink.create(revertData.dismissedLinks)
Expand Down
10 changes: 3 additions & 7 deletions packages/core/core-flows/src/common/steps/create-remote-links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import { LinkDefinition } from "@medusajs/framework/types"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
Expand Down Expand Up @@ -37,9 +37,7 @@ export const createLinksStepId = "create-remote-links"
export const createRemoteLinkStep = createStep(
createLinksStepId,
async (data: LinkDefinition[], { container }) => {
const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)

if (!data.length) {
return new StepResponse([], [])
Expand All @@ -54,9 +52,7 @@ export const createRemoteLinkStep = createStep(
return
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)
await link.dismiss(createdLinks)
}
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import { LinkDefinition } from "@medusajs/framework/types"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"

Expand Down Expand Up @@ -47,9 +47,7 @@ export const dismissRemoteLinkStep = createStep(
return new StepResponse([], [])
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)

// Our current revert strategy for dismissed links are to recreate it again.
// This works when its just the primary keys, but when you have additional data
Expand All @@ -67,9 +65,7 @@ export const dismissRemoteLinkStep = createStep(
return
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)

await link.create(dataBeforeDismiss)
}
Expand Down
10 changes: 3 additions & 7 deletions packages/core/core-flows/src/common/steps/remove-remote-links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeleteEntityInput, RemoteLink } from "@medusajs/framework/modules-sdk"
import { DeleteEntityInput, Link } from "@medusajs/framework/modules-sdk"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"

import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
Expand Down Expand Up @@ -62,9 +62,7 @@ export const removeRemoteLinkStep = createStep(
}
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)
await link.delete(grouped)

return new StepResponse(grouped, grouped)
Expand All @@ -74,9 +72,7 @@ export const removeRemoteLinkStep = createStep(
return
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)
await link.restore(removedLinks)
}
)
10 changes: 3 additions & 7 deletions packages/core/core-flows/src/common/steps/update-remote-links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import { LinkDefinition } from "@medusajs/framework/types"
import {
ContainerRegistrationKeys,
Expand All @@ -14,9 +14,7 @@ export const updateRemoteLinksStep = createStep(
return new StepResponse([], [])
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)

// Fetch all existing links and throw an error if any weren't found
const dataBeforeUpdate = (await link.list(data, {
Expand All @@ -43,9 +41,7 @@ export const updateRemoteLinksStep = createStep(
return
}

const link = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const link = container.resolve<Link>(ContainerRegistrationKeys.LINK)

await link.create(dataBeforeUpdate)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import { RemoteQueryFunction } from "@medusajs/framework/types"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
import {
Expand Down Expand Up @@ -70,9 +70,7 @@ export const setShippingOptionsPriceSetsStep = createStep(
return
}

const remoteLink = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const remoteLink = container.resolve<Link>(ContainerRegistrationKeys.LINK)
const remoteQuery = container.resolve<RemoteQueryFunction>(
ContainerRegistrationKeys.REMOTE_QUERY
)
Expand Down Expand Up @@ -152,9 +150,7 @@ export const setShippingOptionsPriceSetsStep = createStep(
return
}

const remoteLink = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const remoteLink = container.resolve<Link>(ContainerRegistrationKeys.LINK)

const promises: Promise<unknown[]>[] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const attachInventoryItemToVariants = createStep(
}[],
{ container }
) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

const linkDefinitions = input
.filter(({ tag }) => !!tag)
Expand All @@ -38,7 +38,7 @@ export const attachInventoryItemToVariants = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

await remoteLink.dismiss(linkDefinitions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const validateInventoryItemsForCreate = createStep(
}[],
{ container }
) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

const linkService = remoteLink.getLinkModule(
Modules.PRODUCT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createVariantPricingLinkStepId = "create-variant-pricing-link"
export const createVariantPricingLinkStep = createStep(
createVariantPricingLinkStepId,
async (data: CreateVariantPricingLinkStepInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
await remoteLink.create(
data.links.map((entry) => ({
[Modules.PRODUCT]: {
Expand All @@ -34,7 +34,7 @@ export const createVariantPricingLinkStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
const links = data.links.map((entry) => ({
[Modules.PRODUCT]: {
variant_id: entry.variant_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getVariantPricingLinkStep = createStep(
return new StepResponse([])
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

const linkService = remoteLink.getLinkModule(
Modules.PRODUCT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import {
IPaymentModuleService,
RemoteQueryFunction,
Expand Down Expand Up @@ -107,9 +107,7 @@ export const setRegionsPaymentProvidersStep = createStep(
const paymentService = container.resolve<IPaymentModuleService>(
Modules.PAYMENT
)
const remoteLink = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const remoteLink = container.resolve<Link>(ContainerRegistrationKeys.LINK)
const remoteQuery = container.resolve<RemoteQueryFunction>(
ContainerRegistrationKeys.REMOTE_QUERY
)
Expand Down Expand Up @@ -199,9 +197,7 @@ export const setRegionsPaymentProvidersStep = createStep(
return
}

const remoteLink = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const remoteLink = container.resolve<Link>(ContainerRegistrationKeys.LINK)

const promises: Promise<unknown[]>[] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const associateLocationsWithSalesChannelsStep = createStep(
return new StepResponse([], [])
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
const links = data.links.map((link) => {
return {
[Modules.SALES_CHANNEL]: {
Expand All @@ -41,7 +41,7 @@ export const associateLocationsWithSalesChannelsStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
await remoteLink.dismiss(links)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const associateProductsWithSalesChannelsStep = createStep(
return new StepResponse([], [])
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
const links = input.links.map((link) => {
return {
[Modules.PRODUCT]: {
Expand All @@ -40,7 +40,7 @@ export const associateProductsWithSalesChannelsStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

await remoteLink.dismiss(links)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteLink } from "@medusajs/framework/modules-sdk"
import { Link } from "@medusajs/framework/modules-sdk"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"

import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
Expand All @@ -22,9 +22,7 @@ export const detachLocationsFromSalesChannelsStep = createStep(
return new StepResponse([], [])
}

const remoteLink = container.resolve<RemoteLink>(
ContainerRegistrationKeys.REMOTE_LINK
)
const remoteLink = container.resolve<Link>(ContainerRegistrationKeys.LINK)

const links = data.links.map((link) => {
return {
Expand All @@ -45,7 +43,7 @@ export const detachLocationsFromSalesChannelsStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
await remoteLink.create(links)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const detachProductsFromSalesChannelsStep = createStep(
return new StepResponse(void 0, [])
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
const links = input.links.map((link) => {
return {
[Modules.PRODUCT]: {
Expand All @@ -41,7 +41,7 @@ export const detachProductsFromSalesChannelsStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

await remoteLink.create(links)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const associateFulfillmentSetsWithLocationStep = createStep(
return new StepResponse([], [])
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

const links = data.input
.map((link) => {
Expand All @@ -49,7 +49,7 @@ export const associateFulfillmentSetsWithLocationStep = createStep(
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)

await remoteLink.dismiss(links)
}
Expand Down
Loading

0 comments on commit bbf790e

Please sign in to comment.