chore(core-flows,types): improve TSDocs for remaining workflows (#11021)
This commit is contained in:
@@ -5,13 +5,30 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to create API keys.
|
||||
*/
|
||||
export type CreateApiKeysStepInput = {
|
||||
/**
|
||||
* The API keys to create.
|
||||
*/
|
||||
api_keys: CreateApiKeyDTO[]
|
||||
}
|
||||
|
||||
export const createApiKeysStepId = "create-api-keys"
|
||||
/**
|
||||
* This step creates one or more API keys.
|
||||
*
|
||||
* @example
|
||||
* const data = createApiKeysStep({
|
||||
* api_keys: [
|
||||
* {
|
||||
* type: "publishable",
|
||||
* title: "Storefront",
|
||||
* created_by: "user_123"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const createApiKeysStep = createStep(
|
||||
createApiKeysStepId,
|
||||
|
||||
@@ -2,13 +2,18 @@ import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the API keys to delete.
|
||||
*/
|
||||
export type DeleteApiKeysStepInput = string[]
|
||||
|
||||
export const deleteApiKeysStepId = "delete-api-keys"
|
||||
/**
|
||||
* This step deletes one or more API keys.
|
||||
*/
|
||||
export const deleteApiKeysStep = createStep(
|
||||
{ name: deleteApiKeysStepId, noCompensation: true },
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteApiKeysStepInput, { container }) => {
|
||||
const service = container.resolve<IApiKeyModuleService>(Modules.API_KEY)
|
||||
|
||||
await service.deleteApiKeys(ids)
|
||||
|
||||
@@ -6,13 +6,29 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to manage the sales channels of a publishable API key.
|
||||
*
|
||||
* @property id - The ID of the publishable API key.
|
||||
* @property add - The sales channel IDs to add to the publishable API key.
|
||||
* @property remove - The sales channel IDs to remove from the publishable API key.
|
||||
*/
|
||||
export type LinkSalesChannelsToApiKeyStepInput = LinkWorkflowInput
|
||||
|
||||
export const linkSalesChannelsToApiKeyStepId = "link-sales-channels-to-api-key"
|
||||
/**
|
||||
* This step links sales channels to API keys.
|
||||
* This step manages the sales channels of a publishable API key.
|
||||
*
|
||||
* @example
|
||||
* const data = linkSalesChannelsToApiKeyStep({
|
||||
* id: "apk_123",
|
||||
* add: ["sc_123"],
|
||||
* remove: ["sc_456"]
|
||||
* })
|
||||
*/
|
||||
export const linkSalesChannelsToApiKeyStep = createStep(
|
||||
linkSalesChannelsToApiKeyStepId,
|
||||
async (input: LinkWorkflowInput, { container }) => {
|
||||
async (input: LinkSalesChannelsToApiKeyStepInput, { container }) => {
|
||||
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
|
||||
if (!input || (!input.add?.length && !input.remove?.length)) {
|
||||
return
|
||||
|
||||
@@ -6,14 +6,33 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to revoke API keys.
|
||||
*/
|
||||
export type RevokeApiKeysStepInput = {
|
||||
/**
|
||||
* The filters to select the API keys to revoke.
|
||||
*/
|
||||
selector: FilterableApiKeyProps
|
||||
/**
|
||||
* The data to revoke the API keys.
|
||||
*/
|
||||
revoke: RevokeApiKeyDTO
|
||||
}
|
||||
|
||||
export const revokeApiKeysStepId = "revoke-api-keys"
|
||||
/**
|
||||
* This step revokes one or more API keys.
|
||||
*
|
||||
* @example
|
||||
* const data = revokeApiKeysStep({
|
||||
* selector: {
|
||||
* id: "apk_123"
|
||||
* },
|
||||
* revoke: {
|
||||
* revoked_by: "user_123"
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const revokeApiKeysStep = createStep(
|
||||
{ name: revokeApiKeysStepId, noCompensation: true },
|
||||
|
||||
@@ -9,14 +9,33 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to update API keys.
|
||||
*/
|
||||
export type UpdateApiKeysStepInput = {
|
||||
/**
|
||||
* The filters to select the API keys to update.
|
||||
*/
|
||||
selector: FilterableApiKeyProps
|
||||
/**
|
||||
* The data to update the API keys.
|
||||
*/
|
||||
update: UpdateApiKeyDTO
|
||||
}
|
||||
|
||||
export const updateApiKeysStepId = "update-api-keys"
|
||||
/**
|
||||
* This step updates one or more API keys.
|
||||
*
|
||||
* @example
|
||||
* const data = updateApiKeysStep({
|
||||
* selector: {
|
||||
* id: "apk_123"
|
||||
* },
|
||||
* update: {
|
||||
* title: "Storefront"
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateApiKeysStep = createStep(
|
||||
updateApiKeysStepId,
|
||||
|
||||
@@ -6,13 +6,20 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to validate that the sales channels exist.
|
||||
*/
|
||||
export interface ValidateSalesChannelsExistStepInput {
|
||||
/**
|
||||
* The IDs of the sales channels to validate.
|
||||
*/
|
||||
sales_channel_ids: string[]
|
||||
}
|
||||
|
||||
export const validateSalesChannelsExistStepId = "validate-sales-channels-exist"
|
||||
/**
|
||||
* This step validates that a sales channel exists before linking it to an API key.
|
||||
* If the sales channel does not exist, the step throws an error.
|
||||
*/
|
||||
export const validateSalesChannelsExistStep = createStep(
|
||||
validateSalesChannelsExistStepId,
|
||||
|
||||
@@ -6,17 +6,52 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { createApiKeysStep } from "../steps"
|
||||
|
||||
export type CreateApiKeysWorkflowInput = { api_keys: CreateApiKeyDTO[] }
|
||||
/**
|
||||
* The data to create API keys.
|
||||
*/
|
||||
export type CreateApiKeysWorkflowInput = {
|
||||
/**
|
||||
* The API keys to create.
|
||||
*/
|
||||
api_keys: CreateApiKeyDTO[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The created API keys.
|
||||
*/
|
||||
export type CreateApiKeysWorkflowOutput = ApiKeyDTO[]
|
||||
|
||||
export const createApiKeysWorkflowId = "create-api-keys"
|
||||
/**
|
||||
* This workflow creates one or more API keys.
|
||||
* This workflow creates one or more API keys, which can be secret or publishable. It's used by the
|
||||
* [Create API Key Admin API Route](https://docs.medusajs.com/api/admin#api-keys_postapikeys).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create API keys within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createApiKeysWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* api_keys: [
|
||||
* {
|
||||
* type: "publishable",
|
||||
* title: "Storefront",
|
||||
* created_by: "user_123"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create secret or publishable API keys.
|
||||
*/
|
||||
export const createApiKeysWorkflow = createWorkflow(
|
||||
createApiKeysWorkflowId,
|
||||
(
|
||||
input: WorkflowData<CreateApiKeysWorkflowInput>
|
||||
): WorkflowResponse<ApiKeyDTO[]> => {
|
||||
): WorkflowResponse<CreateApiKeysWorkflowOutput> => {
|
||||
return new WorkflowResponse(createApiKeysStep(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -3,11 +3,35 @@ import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||
import { deleteApiKeysStep } from "../steps"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export type DeleteApiKeysWorkflowInput = { ids: string[] }
|
||||
/**
|
||||
* The data to delete API keys.
|
||||
*/
|
||||
export type DeleteApiKeysWorkflowInput = {
|
||||
/**
|
||||
* The IDs of the API keys to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteApiKeysWorkflowId = "delete-api-keys"
|
||||
/**
|
||||
* This workflow deletes one or more API keys.
|
||||
* This workflow deletes one or more secret or publishable API keys. It's used by the
|
||||
* [Delete API Key Admin API Route](https://docs.medusajs.com/api/admin#api-keys_deleteapikeysid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete API keys within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteApiKeysWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["apk_123"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete secret or publishable API keys.
|
||||
*/
|
||||
export const deleteApiKeysWorkflow = createWorkflow(
|
||||
deleteApiKeysWorkflowId,
|
||||
|
||||
@@ -5,14 +5,37 @@ import {
|
||||
validateSalesChannelsExistStep,
|
||||
} from "../steps"
|
||||
|
||||
/**
|
||||
* The data to manage the sales channels of a publishable API key.
|
||||
*
|
||||
* @property id - The ID of the publishable API key.
|
||||
* @property add - The sales channel IDs to add to the publishable API key.
|
||||
* @property remove - The sales channel IDs to remove from the publishable API key.
|
||||
*/
|
||||
export type LinkSalesChannelsToApiKeyWorkflowInput = LinkWorkflowInput
|
||||
|
||||
export const linkSalesChannelsToApiKeyWorkflowId =
|
||||
"link-sales-channels-to-api-key"
|
||||
/**
|
||||
* This workflow links sales channels to API keys.
|
||||
* This workflow manages the sales channels of a publishable API key. It's used by the
|
||||
* [Manage Sales Channels API Route](https://docs.medusajs.com/api/admin#api-keys_postapikeysidsaleschannels).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* manage the sales channels of a publishable API key within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await linkSalesChannelsToApiKeyWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* id: "apk_132",
|
||||
* add: ["sc_123"],
|
||||
* remove: ["sc_321"]
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const linkSalesChannelsToApiKeyWorkflow = createWorkflow(
|
||||
linkSalesChannelsToApiKeyWorkflowId,
|
||||
(input: WorkflowData<LinkWorkflowInput>) => {
|
||||
(input: WorkflowData<LinkSalesChannelsToApiKeyWorkflowInput>) => {
|
||||
validateSalesChannelsExistStep({
|
||||
sales_channel_ids: input.add ?? [],
|
||||
})
|
||||
|
||||
@@ -10,20 +10,57 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { revokeApiKeysStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to revoke API keys.
|
||||
*/
|
||||
export type RevokeApiKeysWorkflowInput = {
|
||||
/**
|
||||
* The filters to select the API keys to revoke.
|
||||
*/
|
||||
selector: FilterableApiKeyProps
|
||||
/**
|
||||
* The data to revoke the API keys.
|
||||
*/
|
||||
revoke: RevokeApiKeyDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* The revoked API keys.
|
||||
*/
|
||||
export type RevokeApiKeysWorkflowOutput = ApiKeyDTO[]
|
||||
|
||||
export const revokeApiKeysWorkflowId = "revoke-api-keys"
|
||||
/**
|
||||
* This workflow revokes one or more API keys.
|
||||
* This workflow revokes one or more API keys. If the API key is a secret,
|
||||
* it can't be used for authentication anymore. If it's publishable, it can't be used by client applications.
|
||||
*
|
||||
* This workflow is used by the [Revoke API Key API Route](https://docs.medusajs.com/api/admin#api-keys_postapikeysidrevoke).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* revoke API keys within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await revokeApiKeysWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "apk_123"
|
||||
* },
|
||||
* revoke: {
|
||||
* revoked_by: "user_123"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Revoke secret or publishable API keys.
|
||||
*/
|
||||
export const revokeApiKeysWorkflow = createWorkflow(
|
||||
revokeApiKeysWorkflowId,
|
||||
(
|
||||
input: WorkflowData<RevokeApiKeysWorkflowInput>
|
||||
): WorkflowResponse<ApiKeyDTO[]> => {
|
||||
): WorkflowResponse<RevokeApiKeysWorkflowOutput> => {
|
||||
return new WorkflowResponse(revokeApiKeysStep(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,20 +10,55 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { updateApiKeysStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to update API keys.
|
||||
*/
|
||||
export type UpdateApiKeysWorkflowInput = {
|
||||
/**
|
||||
* The filters to select the API keys to update.
|
||||
*/
|
||||
selector: FilterableApiKeyProps
|
||||
/**
|
||||
* The data to update the API keys.
|
||||
*/
|
||||
update: UpdateApiKeyDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* The updated API keys.
|
||||
*/
|
||||
export type UpdateApiKeysWorkflowOutput = ApiKeyDTO[]
|
||||
|
||||
export const updateApiKeysWorkflowId = "update-api-keys"
|
||||
/**
|
||||
* This workflow creates one or more API keys.
|
||||
* This workflow updates one or more secret or publishable API keys. It's used by the
|
||||
* [Update API Key Admin API Route](https://docs.medusajs.com/api/admin#api-keys_postapikeysid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update API keys within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateApiKeysWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "apk_123"
|
||||
* },
|
||||
* update: {
|
||||
* title: "Storefront"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update secret or publishable API keys.
|
||||
*/
|
||||
export const updateApiKeysWorkflow = createWorkflow(
|
||||
updateApiKeysWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdateApiKeysWorkflowInput>
|
||||
): WorkflowResponse<ApiKeyDTO[]> => {
|
||||
): WorkflowResponse<UpdateApiKeysWorkflowOutput> => {
|
||||
return new WorkflowResponse(updateApiKeysStep(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,29 +10,14 @@ export const createLinksStepId = "create-remote-links"
|
||||
* Learn more in the [Remote Link documentation.](https://docs.medusajs.com/learn/fundamentals/module-links/remote-link#create-link).
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* createRemoteLinkStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
* import {
|
||||
* Modules
|
||||
* } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* createRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }])
|
||||
* }
|
||||
* )
|
||||
* createRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }])
|
||||
*/
|
||||
export const createRemoteLinkStep = createStep(
|
||||
createLinksStepId,
|
||||
|
||||
@@ -14,29 +14,14 @@ export const dismissRemoteLinkStepId = "dismiss-remote-links"
|
||||
* Learn more in the [Remote Link documentation.](https://docs.medusajs.com/learn/fundamentals/module-links/remote-link#dismiss-link).
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* dismissRemoteLinkStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
* import {
|
||||
* Modules
|
||||
* } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* dismissRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }])
|
||||
* }
|
||||
* )
|
||||
* dismissRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }])
|
||||
*/
|
||||
export const dismissRemoteLinkStep = createStep(
|
||||
dismissRemoteLinkStepId,
|
||||
|
||||
@@ -41,24 +41,12 @@ export const emitEventStepId = "emit-event-step"
|
||||
* Emit an event.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* emitEventStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* emitEventStep({
|
||||
* eventName: "custom.created",
|
||||
* data: {
|
||||
* id: "123"
|
||||
* }
|
||||
* })
|
||||
* emitEventStep({
|
||||
* eventName: "custom.created",
|
||||
* data: {
|
||||
* id: "123"
|
||||
* }
|
||||
* )
|
||||
* })
|
||||
*/
|
||||
export const emitEventStep = createStep(
|
||||
emitEventStepId,
|
||||
|
||||
@@ -12,26 +12,11 @@ export const removeRemoteLinkStepId = "remove-remote-links"
|
||||
* Learn more in the [Remote Link documentation](https://docs.medusajs.com/learn/fundamentals/module-links/remote-link#cascade-delete-linked-records)
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* removeRemoteLinkStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
* import {
|
||||
* Modules
|
||||
* } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* removeRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* }])
|
||||
* }
|
||||
* )
|
||||
* removeRemoteLinkStep([{
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* }])
|
||||
*/
|
||||
export const removeRemoteLinkStep = createStep(
|
||||
removeRemoteLinkStepId,
|
||||
|
||||
@@ -7,6 +7,28 @@ import {
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
export const updateRemoteLinksStepId = "update-remote-links-step"
|
||||
/**
|
||||
* This step updates remote links between two records of linked data models.
|
||||
*
|
||||
* Learn more in the [Remote Link documentation.](https://docs.medusajs.com/learn/fundamentals/module-links/remote-link#create-link).
|
||||
*
|
||||
* @example
|
||||
* const data = updateRemoteLinksStep([
|
||||
* {
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_321",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_321",
|
||||
* },
|
||||
* data: {
|
||||
* metadata: {
|
||||
* test: false
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ])
|
||||
*/
|
||||
export const updateRemoteLinksStep = createStep(
|
||||
updateRemoteLinksStepId,
|
||||
async (data: LinkDefinition[], { container }) => {
|
||||
|
||||
@@ -35,25 +35,13 @@ const step = createStep(
|
||||
* To retrieve a list of records of a data model:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* useQueryGraphStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* const { data: products } = useQueryGraphStep({
|
||||
* entity: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ]
|
||||
* })
|
||||
* }
|
||||
* )
|
||||
* const { data: products } = useQueryGraphStep({
|
||||
* entity: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ]
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To retrieve a single item instead of a an array:
|
||||
|
||||
@@ -63,86 +63,50 @@ export const useRemoteQueryStepId = "use-remote-query"
|
||||
* To retrieve a list of records of a data model:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* useRemoteQueryStep
|
||||
* } from "@medusajs/medusa/core-flows"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* const products = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ]
|
||||
* })
|
||||
* }
|
||||
* )
|
||||
* const products = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ]
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To retrieve a single item instead of a an array:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* useRemoteQueryStep
|
||||
* } from "@medusajs/core-flows"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* const product = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ],
|
||||
* variables: {
|
||||
* filters: {
|
||||
* id: "123"
|
||||
* }
|
||||
* },
|
||||
* list: false
|
||||
* })
|
||||
* }
|
||||
* )
|
||||
* const product = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ],
|
||||
* variables: {
|
||||
* filters: {
|
||||
* id: "123"
|
||||
* }
|
||||
* },
|
||||
* list: false
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To throw an error if a record isn't found matching the specified ID:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* createWorkflow
|
||||
* } from "@medusajs/framework/workflows-sdk"
|
||||
* import {
|
||||
* useRemoteQueryStep
|
||||
* } from "@medusajs/core-flows"
|
||||
*
|
||||
* const helloWorldWorkflow = createWorkflow(
|
||||
* "hello-world",
|
||||
* () => {
|
||||
* const product = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ],
|
||||
* variables: {
|
||||
* filters: {
|
||||
* id: "123"
|
||||
* }
|
||||
* },
|
||||
* list: false,
|
||||
* throw_if_key_not_found: true
|
||||
* })
|
||||
* }
|
||||
* )
|
||||
* const product = useRemoteQueryStep({
|
||||
* entry_point: "product",
|
||||
* fields: [
|
||||
* "*",
|
||||
* "variants.*"
|
||||
* ],
|
||||
* variables: {
|
||||
* filters: {
|
||||
* id: "123"
|
||||
* }
|
||||
* },
|
||||
* list: false,
|
||||
* throw_if_key_not_found: true
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export const useRemoteQueryStep = createStep(
|
||||
|
||||
@@ -12,6 +12,57 @@ import { updateRemoteLinksStep } from "../steps/update-remote-links"
|
||||
export const batchLinksWorkflowId = "batch-links"
|
||||
/**
|
||||
* This workflow manages one or more links to create, update, or dismiss them.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* manage links within your custom flows.
|
||||
*
|
||||
* Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links/link).
|
||||
*
|
||||
* @example
|
||||
* const { result } = await batchLinksWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* create: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }
|
||||
* ],
|
||||
* update: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_321",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_321",
|
||||
* },
|
||||
* data: {
|
||||
* metadata: {
|
||||
* test: false
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ],
|
||||
* delete: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_321",
|
||||
* },
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Manage links between two records of linked data models.
|
||||
*/
|
||||
export const batchLinksWorkflow = createWorkflow(
|
||||
batchLinksWorkflowId,
|
||||
|
||||
@@ -9,6 +9,31 @@ import { createRemoteLinkStep } from "../steps/create-remote-links"
|
||||
export const createLinksWorkflowId = "create-link"
|
||||
/**
|
||||
* This workflow creates one or more links between records.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create links within your custom flows.
|
||||
*
|
||||
* Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links/link).
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createLinksWorkflow(container)
|
||||
* .run({
|
||||
* input: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create links between two records of linked data models.
|
||||
*/
|
||||
export const createLinksWorkflow = createWorkflow(
|
||||
createLinksWorkflowId,
|
||||
|
||||
@@ -9,6 +9,31 @@ import { dismissRemoteLinkStep } from "../steps/dismiss-remote-links"
|
||||
export const dismissLinksWorkflowId = "dismiss-link"
|
||||
/**
|
||||
* This workflow dismisses one or more links between records.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* dismiss links within your custom flows.
|
||||
*
|
||||
* Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links/link).
|
||||
*
|
||||
* @example
|
||||
* const { result } = await dismissLinksWorkflow(container)
|
||||
* .run({
|
||||
* input: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Dismiss links between two records of linked data models.
|
||||
*/
|
||||
export const dismissLinksWorkflow = createWorkflow(
|
||||
dismissLinksWorkflowId,
|
||||
|
||||
@@ -9,6 +9,36 @@ import { updateRemoteLinksStep } from "../steps/update-remote-links"
|
||||
export const updateLinksWorkflowId = "update-link"
|
||||
/**
|
||||
* This workflow updates one or more links between records.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update links within your custom flows.
|
||||
*
|
||||
* Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links/link).
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateLinksWorkflow(container)
|
||||
* .run({
|
||||
* input: [
|
||||
* {
|
||||
* // import { Modules } from "@medusajs/framework/utils"
|
||||
* [Modules.PRODUCT]: {
|
||||
* product_id: "prod_123",
|
||||
* },
|
||||
* "helloModuleService": {
|
||||
* my_custom_id: "mc_123",
|
||||
* },
|
||||
* data: {
|
||||
* metadata: {
|
||||
* test: false,
|
||||
* },
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update links between two records of linked data models.
|
||||
*/
|
||||
export const updateLinksWorkflow = createWorkflow(
|
||||
updateLinksWorkflowId,
|
||||
|
||||
@@ -7,13 +7,33 @@ import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { createStoresWorkflow } from "../../store"
|
||||
|
||||
/**
|
||||
* The data to create a default store.
|
||||
*/
|
||||
type CreateDefaultStoreStepInput = {
|
||||
/**
|
||||
* The store to create.
|
||||
*/
|
||||
store: CreateStoreDTO
|
||||
}
|
||||
|
||||
export const createDefaultStoreStepId = "create-default-store"
|
||||
/**
|
||||
* This step creates a default store.
|
||||
* This step creates a default store. Useful if creating a workflow
|
||||
* that seeds data into Medusa.
|
||||
*
|
||||
* @example
|
||||
* const data = createDefaultStoreStep({
|
||||
* store: {
|
||||
* name: "Acme",
|
||||
* supported_currencies: [
|
||||
* {
|
||||
* currency_code: "usd",
|
||||
* is_default: true
|
||||
* }
|
||||
* ],
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const createDefaultStoreStep = createStep(
|
||||
createDefaultStoreStepId,
|
||||
|
||||
@@ -7,7 +7,20 @@ import { createDefaultStoreStep } from "../steps/create-default-store"
|
||||
|
||||
export const createDefaultsWorkflowID = "create-defaults"
|
||||
/**
|
||||
* This workflow creates default data for a Medusa application.
|
||||
* This workflow creates default data for a Medusa application, including
|
||||
* a default sales channel and store. The Medusa application uses this workflow
|
||||
* to create the default data, if not existing, when the application is first started.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create default data within your custom flows, such as seed scripts.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createDefaultsWorkflow(container)
|
||||
* .run()
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create default data for a Medusa application.
|
||||
*/
|
||||
export const createDefaultsWorkflow = createWorkflow(
|
||||
createDefaultsWorkflowID,
|
||||
|
||||
@@ -2,13 +2,25 @@ import { IFileModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the files to delete.
|
||||
*/
|
||||
export type DeleteFilesStepInput = string[]
|
||||
|
||||
export const deleteFilesStepId = "delete-files"
|
||||
/**
|
||||
* This step deletes one or more files.
|
||||
* This step deletes one or more files using the installed
|
||||
* [File Module Provider](https://docs.medusajs.com/resources/architectural-modules/file). The files
|
||||
* will be removed from the database and the storage.
|
||||
*
|
||||
* @example
|
||||
* const data = deleteFilesStep([
|
||||
* "id_123"
|
||||
* ])
|
||||
*/
|
||||
export const deleteFilesStep = createStep(
|
||||
{ name: deleteFilesStepId, noCompensation: true },
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteFilesStepInput, { container }) => {
|
||||
const service = container.resolve<IFileModuleService>(Modules.FILE)
|
||||
|
||||
await service.deleteFiles(ids)
|
||||
|
||||
@@ -2,18 +2,57 @@ import { IFileModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to upload files.
|
||||
*/
|
||||
export type UploadFilesStepInput = {
|
||||
/**
|
||||
* The files to upload.
|
||||
*/
|
||||
files: {
|
||||
/**
|
||||
* The name of the file.
|
||||
*/
|
||||
filename: string
|
||||
/**
|
||||
* The MIME type of the file.
|
||||
*
|
||||
* @example
|
||||
* img/jpg
|
||||
*/
|
||||
mimeType: string
|
||||
/**
|
||||
* The content of the file. For images, for example,
|
||||
* use base64 encoding. For CSV files, use the CSV content.
|
||||
*/
|
||||
content: string
|
||||
/**
|
||||
* The access level of the file. Use `public` for the file that
|
||||
* can be accessed by anyone. For example, for images that are displayed
|
||||
* on the storefront. Use `private` for files that are only accessible
|
||||
* by authenticated users. For example, for CSV files used to
|
||||
* import data.
|
||||
*/
|
||||
access: "public" | "private"
|
||||
}[]
|
||||
}
|
||||
|
||||
export const uploadFilesStepId = "upload-files"
|
||||
/**
|
||||
* This step uploads one or more files.
|
||||
* This step uploads one or more files using the installed
|
||||
* [File Module Provider](https://docs.medusajs.com/resources/architectural-modules/file).
|
||||
*
|
||||
* @example
|
||||
* const data = uploadFilesStep({
|
||||
* files: [
|
||||
* {
|
||||
* filename: "test.jpg",
|
||||
* mimeType: "img/jpg",
|
||||
* content: "base64Content",
|
||||
* access: "public"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const uploadFilesStep = createStep(
|
||||
uploadFilesStepId,
|
||||
|
||||
@@ -5,7 +5,26 @@ export type DeleteFilesWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteFilesWorkflowId = "delete-files"
|
||||
/**
|
||||
* This workflow deletes one or more files.
|
||||
* This workflow deletes one or more files. It's used by the
|
||||
* [Delete File Upload Admin API Route](https://docs.medusajs.com/api/admin#uploads_deleteuploadsid).
|
||||
*
|
||||
* The [File Module Provider](https://docs.medusajs.com/resources/architectural-modules/file) installed
|
||||
* in your application will be used to delete the file from storage.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete files within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteFilesWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["123"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete files from the database and storage.
|
||||
*/
|
||||
export const deleteFilesWorkflow = createWorkflow(
|
||||
deleteFilesWorkflowId,
|
||||
|
||||
@@ -6,18 +6,68 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { uploadFilesStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to upload files.
|
||||
*/
|
||||
export type UploadFilesWorkflowInput = {
|
||||
/**
|
||||
* The files to upload.
|
||||
*/
|
||||
files: {
|
||||
/**
|
||||
* The name of the file.
|
||||
*/
|
||||
filename: string
|
||||
/**
|
||||
* The MIME type of the file.
|
||||
*
|
||||
* @example
|
||||
* img/jpg
|
||||
*/
|
||||
mimeType: string
|
||||
/**
|
||||
* The content of the file. For images, for example,
|
||||
* use base64 encoding. For CSV files, use the CSV content.
|
||||
*/
|
||||
content: string
|
||||
/**
|
||||
* The access level of the file. Use `public` for the file that
|
||||
* can be accessed by anyone. For example, for images that are displayed
|
||||
* on the storefront. Use `private` for files that are only accessible
|
||||
* by authenticated users. For example, for CSV files used to
|
||||
* import data.
|
||||
*/
|
||||
access: "public" | "private"
|
||||
}[]
|
||||
}
|
||||
|
||||
export const uploadFilesWorkflowId = "upload-files"
|
||||
/**
|
||||
* This workflow uploads one or more files.
|
||||
* This workflow uploads one or more files using the installed
|
||||
* [File Module Provider](https://docs.medusajs.com/resources/architectural-modules/file). The workflow is used by the
|
||||
* [Upload Files Admin API Route](https://docs.medusajs.com/api/admin#uploads_postuploads).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* upload files within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await uploadFilesWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* files: [
|
||||
* {
|
||||
* filename: "test.jpg",
|
||||
* mimeType: "img/jpg",
|
||||
* content: "base64Content",
|
||||
* access: "public"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Upload files using the installed File Module Provider.
|
||||
*/
|
||||
export const uploadFilesWorkflow = createWorkflow(
|
||||
uploadFilesWorkflowId,
|
||||
|
||||
@@ -28,3 +28,4 @@ export * from "./stock-location"
|
||||
export * from "./store"
|
||||
export * from "./tax"
|
||||
export * from "./user"
|
||||
export * from "./notification"
|
||||
@@ -2,13 +2,18 @@ import { ICartModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the line items to delete.
|
||||
*/
|
||||
export type DeleteLineItemsStepInput = string[]
|
||||
|
||||
export const deleteLineItemsStepId = "delete-line-items"
|
||||
/**
|
||||
* This step deletes line items.
|
||||
*/
|
||||
export const deleteLineItemsStep = createStep(
|
||||
deleteLineItemsStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteLineItemsStepInput, { container }) => {
|
||||
const service = container.resolve<ICartModuleService>(Modules.CART)
|
||||
|
||||
await service.softDeleteLineItems(ids)
|
||||
|
||||
@@ -7,8 +7,20 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to list line items.
|
||||
*/
|
||||
export interface ListLineItemsStepInput {
|
||||
/**
|
||||
* The filters to select the line items.
|
||||
*/
|
||||
filters: FilterableLineItemProps
|
||||
/**
|
||||
* Configurations to select the line items' fields
|
||||
* and relations, and to paginate the results.
|
||||
*
|
||||
* Learn more in the [service factory reference](https://docs.medusajs.com/resources/service-factory-reference/methods/list).
|
||||
*/
|
||||
config?: FindConfig<CartLineItemDTO>
|
||||
}
|
||||
|
||||
@@ -16,6 +28,37 @@ export const listLineItemsStepId = "list-line-items"
|
||||
/**
|
||||
* This step retrieves a list of a cart's line items
|
||||
* matching the specified filters.
|
||||
*
|
||||
* @example
|
||||
* To retrieve the line items of a cart:
|
||||
*
|
||||
* ```ts
|
||||
* const data = listLineItemsStep({
|
||||
* filters: {
|
||||
* cart_id: "cart_123"
|
||||
* },
|
||||
* config: {
|
||||
* select: ["*"]
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To retrieve the line items of a cart with pagination:
|
||||
*
|
||||
* ```ts
|
||||
* const data = listLineItemsStep({
|
||||
* filters: {
|
||||
* cart_id: "cart_123"
|
||||
* },
|
||||
* config: {
|
||||
* select: ["*"],
|
||||
* skip: 0,
|
||||
* take: 15
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Learn more about listing items in [this service factory reference](https://docs.medusajs.com/resources/service-factory-reference/methods/list).
|
||||
*/
|
||||
export const listLineItemsStep = createStep(
|
||||
listLineItemsStepId,
|
||||
|
||||
@@ -14,6 +14,16 @@ export const updateLineItemsStepWithSelectorId =
|
||||
"update-line-items-with-selector"
|
||||
/**
|
||||
* This step updates line items.
|
||||
*
|
||||
* @example
|
||||
* const data = updateLineItemsStepWithSelector({
|
||||
* selector: {
|
||||
* cart_id: "cart_123"
|
||||
* },
|
||||
* data: {
|
||||
* quantity: 1
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateLineItemsStepWithSelector = createStep(
|
||||
updateLineItemsStepWithSelectorId,
|
||||
|
||||
@@ -2,11 +2,40 @@ import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||
import { refreshCartItemsWorkflow } from "../../cart/workflows/refresh-cart-items"
|
||||
import { deleteLineItemsStep } from "../steps/delete-line-items"
|
||||
|
||||
export type DeleteLineItemsWorkflowInput = { cart_id: string; ids: string[] }
|
||||
/**
|
||||
* The data to delete line items from a cart.
|
||||
*/
|
||||
export type DeleteLineItemsWorkflowInput = {
|
||||
/**
|
||||
* The cart's ID.
|
||||
*/
|
||||
cart_id: string
|
||||
/**
|
||||
* The IDs of the line items to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteLineItemsWorkflowId = "delete-line-items"
|
||||
/**
|
||||
* This workflow deletes line items from a cart.
|
||||
* This workflow deletes line items from a cart. It's used by the
|
||||
* [Delete Line Item Store API Route](https://docs.medusajs.com/api/store#carts_deletecartsidlineitemsline_id).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete line items from a cart within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteLineItemsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* cart_id: "cart_123",
|
||||
* ids: ["li_123"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete line items from a cart.
|
||||
*/
|
||||
export const deleteLineItemsWorkflow = createWorkflow(
|
||||
deleteLineItemsWorkflowId,
|
||||
|
||||
@@ -2,24 +2,74 @@ import { INotificationModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The notifications to send.
|
||||
*/
|
||||
export type NotifyOnFailureStepInput = {
|
||||
/**
|
||||
* The address to send the notification to, depending on
|
||||
* the channel. For example, the email address for the email channel.
|
||||
*/
|
||||
to: string
|
||||
/**
|
||||
* The channel to send the notification through. For example, `email`.
|
||||
* A [Notification Module Provider](https://docs.medusajs.com/resources/architectural-modules/notification)
|
||||
* must be installed and configured for the specified channel.
|
||||
*/
|
||||
channel: string
|
||||
/**
|
||||
* The ID of the template to use for the notification. This template ID may be defined
|
||||
* in a third-party service used to send the notification.
|
||||
*/
|
||||
template: string
|
||||
/**
|
||||
* The data to use in the notification template. This data may be used to personalize
|
||||
* the notification, such as the user's name or the order number.
|
||||
*/
|
||||
data?: Record<string, unknown> | null
|
||||
/**
|
||||
* The type of trigger that caused the notification to be sent. For example, `order_created`.
|
||||
*/
|
||||
trigger_type?: string | null
|
||||
/**
|
||||
* The ID of the resource that triggered the notification. For example, the ID of the order
|
||||
* that triggered the notification.
|
||||
*/
|
||||
resource_id?: string | null
|
||||
/**
|
||||
* The type of the resource that triggered the notification. For example, `order`.
|
||||
*/
|
||||
resource_type?: string | null
|
||||
/**
|
||||
* The ID of the user receiving the notification.
|
||||
*/
|
||||
receiver_id?: string | null
|
||||
/**
|
||||
* The ID of the original notification if it's being resent.
|
||||
*/
|
||||
original_notification_id?: string | null
|
||||
/**
|
||||
* A key to ensure that the notification is sent only once. If the notification
|
||||
* is sent multiple times, the key ensures that the notification is sent only once.
|
||||
*/
|
||||
idempotency_key?: string | null
|
||||
}[]
|
||||
|
||||
export const notifyOnFailureStepId = "notify-on-failure"
|
||||
/**
|
||||
* This step sends one or more notification when a workflow fails. This
|
||||
* step can be used in a workflow for its compensation function. When the workflow fails,
|
||||
* its compensation function is triggered to send the notification.
|
||||
* step can be used in the beginning of a workflow so that, when the workflow fails,
|
||||
* the step's compensation function is triggered to send the notification.
|
||||
*
|
||||
* @example
|
||||
* const data = notifyOnFailureStep([{
|
||||
* to: "example@gmail.com",
|
||||
* channel: "email",
|
||||
* template: "order-failed",
|
||||
* data: {
|
||||
* order_id: "order_123",
|
||||
* }
|
||||
* }])
|
||||
*/
|
||||
export const notifyOnFailureStep = createStep(
|
||||
notifyOnFailureStepId,
|
||||
|
||||
@@ -2,16 +2,54 @@ import { INotificationModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The notifications to send.
|
||||
*/
|
||||
export type SendNotificationsStepInput = {
|
||||
/**
|
||||
* The address to send the notification to, depending on
|
||||
* the channel. For example, the email address for the email channel.
|
||||
*/
|
||||
to: string
|
||||
/**
|
||||
* The channel to send the notification through. For example, `email`.
|
||||
*/
|
||||
channel: string
|
||||
/**
|
||||
* The ID of the template to use for the notification. This template ID may be defined
|
||||
* in a third-party service used to send the notification.
|
||||
*/
|
||||
template: string
|
||||
/**
|
||||
* The data to use in the notification template. This data may be used to personalize
|
||||
* the notification, such as the user's name or the order number.
|
||||
*/
|
||||
data?: Record<string, unknown> | null
|
||||
/**
|
||||
* The type of trigger that caused the notification to be sent. For example, `order_created`.
|
||||
*/
|
||||
trigger_type?: string | null
|
||||
/**
|
||||
* The ID of the resource that triggered the notification. For example, the ID of the order
|
||||
* that triggered the notification.
|
||||
*/
|
||||
resource_id?: string | null
|
||||
/**
|
||||
* The type of the resource that triggered the notification. For example, `order`.
|
||||
*/
|
||||
resource_type?: string | null
|
||||
/**
|
||||
* The ID of the user receiving the notification.
|
||||
*/
|
||||
receiver_id?: string | null
|
||||
/**
|
||||
* The ID of the original notification if it's being resent.
|
||||
*/
|
||||
original_notification_id?: string | null
|
||||
/**
|
||||
* A key to ensure that the notification is sent only once. If the notification
|
||||
* is sent multiple times, the key ensures that the notification is sent only once.
|
||||
*/
|
||||
idempotency_key?: string | null
|
||||
}[]
|
||||
|
||||
|
||||
@@ -5,13 +5,28 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to create product categories.
|
||||
*/
|
||||
export type CreateProductCategoriesStepInput = {
|
||||
/**
|
||||
* The product categories to create.
|
||||
*/
|
||||
product_categories: CreateProductCategoryDTO[]
|
||||
}
|
||||
|
||||
export const createProductCategoriesStepId = "create-product-categories"
|
||||
/**
|
||||
* This step creates one or more product categories.
|
||||
*
|
||||
* @example
|
||||
* const data = createProductCategoriesStep({
|
||||
* product_categories: [
|
||||
* {
|
||||
* name: "Shoes",
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const createProductCategoriesStep = createStep(
|
||||
createProductCategoriesStepId,
|
||||
|
||||
@@ -2,13 +2,18 @@ import { IProductModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the product categories to delete.
|
||||
*/
|
||||
export type DeleteProductCategoriesStepInput = string[]
|
||||
|
||||
export const deleteProductCategoriesStepId = "delete-product-categories"
|
||||
/**
|
||||
* This step deletes one or more product categories.
|
||||
*/
|
||||
export const deleteProductCategoriesStep = createStep(
|
||||
deleteProductCategoriesStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteProductCategoriesStepInput, { container }) => {
|
||||
const service = container.resolve<IProductModuleService>(Modules.PRODUCT)
|
||||
|
||||
await service.softDeleteProductCategories(ids)
|
||||
|
||||
@@ -9,14 +9,33 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to update the product categories.
|
||||
*/
|
||||
export type UpdateProductCategoriesStepInput = {
|
||||
/**
|
||||
* The filters to select the product categories to update.
|
||||
*/
|
||||
selector: FilterableProductCategoryProps
|
||||
/**
|
||||
* The data to update in the product categories.
|
||||
*/
|
||||
update: UpdateProductCategoryDTO
|
||||
}
|
||||
|
||||
export const updateProductCategoriesStepId = "update-product-categories"
|
||||
/**
|
||||
* This step updates product categories matching specified filters.
|
||||
*
|
||||
* @example
|
||||
* const data = updateProductCategoriesStep({
|
||||
* selector: {
|
||||
* id: "pcat_123",
|
||||
* },
|
||||
* update: {
|
||||
* name: "Shoes",
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateProductCategoriesStep = createStep(
|
||||
updateProductCategoriesStepId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ProductCategoryWorkflow } from "@medusajs/framework/types"
|
||||
import { ProductCategoryDTO, ProductCategoryWorkflow } from "@medusajs/framework/types"
|
||||
import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
@@ -9,15 +9,40 @@ import {
|
||||
import { emitEventStep } from "../../common"
|
||||
import { createProductCategoriesStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The created product categories.
|
||||
*/
|
||||
export type CreateProductCategoriesWorkflowOutput = ProductCategoryDTO[]
|
||||
|
||||
export const createProductCategoriesWorkflowId = "create-product-categories"
|
||||
/**
|
||||
* This workflow creates one or more product categories.
|
||||
* This workflow creates one or more product categories. It's used by the
|
||||
* [Create Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategories).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create product categories within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createProductCategoriesWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* product_categories: [
|
||||
* {
|
||||
* name: "Shoes",
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create product categories.
|
||||
*/
|
||||
export const createProductCategoriesWorkflow = createWorkflow(
|
||||
createProductCategoriesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<ProductCategoryWorkflow.CreateProductCategoriesWorkflowInput>
|
||||
) => {
|
||||
): WorkflowResponse<CreateProductCategoriesWorkflowOutput> => {
|
||||
const createdProducts = createProductCategoriesStep(input)
|
||||
|
||||
const productCategoryIdEvents = transform(
|
||||
|
||||
@@ -8,13 +8,32 @@ import {
|
||||
import { emitEventStep } from "../../common"
|
||||
import { deleteProductCategoriesStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The IDs of product categories to delete.
|
||||
*/
|
||||
export type DeleteProductCategoriesWorkflowInput = string[]
|
||||
|
||||
export const deleteProductCategoriesWorkflowId = "delete-product-categories"
|
||||
/**
|
||||
* This workflow deletes one or more product categories.
|
||||
* This workflow deletes one or more product categories. It's used by the
|
||||
* [Delete Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_deleteproductcategoriesid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete product categories within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteProductCategoriesWorkflow(container)
|
||||
* .run({
|
||||
* input: ["pcat_123"]
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete product categories.
|
||||
*/
|
||||
export const deleteProductCategoriesWorkflow = createWorkflow(
|
||||
deleteProductCategoriesWorkflowId,
|
||||
(input: WorkflowData<string[]>) => {
|
||||
(input: WorkflowData<DeleteProductCategoriesWorkflowInput>) => {
|
||||
const deleted = deleteProductCategoriesStep(input)
|
||||
|
||||
const productCategoryIdEvents = transform({ input }, ({ input }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ProductCategoryWorkflow } from "@medusajs/framework/types"
|
||||
import { ProductCategoryDTO, ProductCategoryWorkflow } from "@medusajs/framework/types"
|
||||
import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
@@ -9,15 +9,41 @@ import {
|
||||
import { emitEventStep } from "../../common"
|
||||
import { updateProductCategoriesStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The updated product categories.
|
||||
*/
|
||||
export type UpdateProductCategoriesWorkflowOutput = ProductCategoryDTO[]
|
||||
|
||||
export const updateProductCategoriesWorkflowId = "update-product-categories"
|
||||
/**
|
||||
* This workflow updates product categories matching specified filters.
|
||||
* This workflow updates product categories matching specified filters. It's used by the
|
||||
* [Update Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategoriesid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update product categories within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateProductCategoriesWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "pcat_123",
|
||||
* },
|
||||
* update: {
|
||||
* name: "Shoes",
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update product categories.
|
||||
*/
|
||||
export const updateProductCategoriesWorkflow = createWorkflow(
|
||||
updateProductCategoriesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<ProductCategoryWorkflow.UpdateProductCategoriesWorkflowInput>
|
||||
) => {
|
||||
): WorkflowResponse<UpdateProductCategoriesWorkflowOutput> => {
|
||||
const updatedCategories = updateProductCategoriesStep(input)
|
||||
|
||||
const productCategoryIdEvents = transform(
|
||||
|
||||
@@ -8,6 +8,14 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
export const createReturnReasonsStepId = "create-return-reasons"
|
||||
/**
|
||||
* This step creates one or more return reasons.
|
||||
*
|
||||
* @example
|
||||
* const data = createReturnReasonsStep([
|
||||
* {
|
||||
* label: "Damaged",
|
||||
* value: "damaged",
|
||||
* }
|
||||
* ])
|
||||
*/
|
||||
export const createReturnReasonsStep = createStep(
|
||||
createReturnReasonsStepId,
|
||||
|
||||
@@ -2,13 +2,21 @@ import { IOrderModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the return reasons to delete.
|
||||
*/
|
||||
export type DeleteReturnReasonStepInput = string[]
|
||||
|
||||
export const deleteReturnReasonStepId = "delete-return-reasons"
|
||||
/**
|
||||
* This step deletes one or more return reasons.
|
||||
*
|
||||
* @example
|
||||
* const data = deleteReturnReasonStep(["rr_123"])
|
||||
*/
|
||||
export const deleteReturnReasonStep = createStep(
|
||||
deleteReturnReasonStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteReturnReasonStepInput, { container }) => {
|
||||
const service = container.resolve<IOrderModuleService>(Modules.ORDER)
|
||||
|
||||
await service.softDeleteReturnReasons(ids)
|
||||
|
||||
@@ -10,14 +10,33 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to update return reasons.
|
||||
*/
|
||||
type UpdateReturnReasonStepInput = {
|
||||
/**
|
||||
* The filters to select the return reasons to update.
|
||||
*/
|
||||
selector: FilterableOrderReturnReasonProps
|
||||
/**
|
||||
* The data to update in the return reasons.
|
||||
*/
|
||||
update: ReturnReasonUpdatableFields
|
||||
}
|
||||
|
||||
export const updateReturnReasonStepId = "update-return-reasons"
|
||||
/**
|
||||
* This step updates return reasons matching the specified filters.
|
||||
*
|
||||
* @example
|
||||
* const data = updateReturnReasonsStep({
|
||||
* selector: {
|
||||
* id: "rr_123",
|
||||
* },
|
||||
* update: {
|
||||
* value: "damaged",
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateReturnReasonsStep = createStep(
|
||||
updateReturnReasonStepId,
|
||||
|
||||
@@ -9,19 +9,51 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { createReturnReasonsStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to create return reasons.
|
||||
*/
|
||||
export type CreateReturnReasonsWorkflowInput = {
|
||||
/**
|
||||
* The return reasons to create.
|
||||
*/
|
||||
data: CreateOrderReturnReasonDTO[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The created return reasons.
|
||||
*/
|
||||
export type CreateReturnReasonsWorkflowOutput = OrderReturnReasonDTO[]
|
||||
|
||||
export const createReturnReasonsWorkflowId = "create-return-reasons"
|
||||
/**
|
||||
* This workflow creates one or more return reasons.
|
||||
* This workflow creates one or more return reasons. It's used by the
|
||||
* [Create Return Reason Admin API Route](https://docs.medusajs.com/api/admin#return-reasons_postreturnreasons).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create return reasons within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createReturnReasonsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* data: [
|
||||
* {
|
||||
* label: "Damaged",
|
||||
* value: "damaged",
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create return reasons.
|
||||
*/
|
||||
export const createReturnReasonsWorkflow = createWorkflow(
|
||||
createReturnReasonsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<CreateReturnReasonsWorkflowInput>
|
||||
): WorkflowResponse<OrderReturnReasonDTO[]> => {
|
||||
): WorkflowResponse<CreateReturnReasonsWorkflowOutput> => {
|
||||
return new WorkflowResponse(createReturnReasonsStep(input.data))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||
import { deleteReturnReasonStep } from "../steps"
|
||||
|
||||
export type DeleteReturnReasonsWorkflowInput = { ids: string[] }
|
||||
/**
|
||||
* The IDs of return reasons to delete.
|
||||
*/
|
||||
export type DeleteReturnReasonsWorkflowInput = {
|
||||
/**
|
||||
* The IDs of return reasons to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteReturnReasonsWorkflowId = "delete-return-reasons"
|
||||
/**
|
||||
* This workflow deletes one or more return reasons.
|
||||
* This workflow deletes one or more return reasons. It's used by the
|
||||
* [Delete Return Reasons Admin API Route](https://docs.medusajs.com/api/admin#return-reasons_deletereturnreasonsid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete return reasons within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteReturnReasonsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["rr_123"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete return reasons.
|
||||
*/
|
||||
export const deleteReturnReasonsWorkflow = createWorkflow(
|
||||
deleteReturnReasonsWorkflowId,
|
||||
|
||||
@@ -10,20 +10,55 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { updateReturnReasonsStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to update return reasons.
|
||||
*/
|
||||
export type UpdateReturnReasonsWorkflowInput = {
|
||||
/**
|
||||
* The filters to select the return reasons to update.
|
||||
*/
|
||||
selector: FilterableOrderReturnReasonProps
|
||||
/**
|
||||
* The data to update the return reasons.
|
||||
*/
|
||||
update: ReturnReasonUpdatableFields
|
||||
}
|
||||
|
||||
/**
|
||||
* The updated return reasons.
|
||||
*/
|
||||
export type UpdateReturnReasonsWorkflowOutput = OrderReturnReasonDTO[]
|
||||
|
||||
export const updateReturnReasonsWorkflowId = "update-return-reasons"
|
||||
/**
|
||||
* This workflow updates return reasons matching the specified filters.
|
||||
* This workflow updates return reasons matching the specified filters. It's used by the
|
||||
* [Update Return Reason Admin API Route](https://docs.medusajs.com/api/admin#return-reasons_postreturnreasonsid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update return reasons within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateReturnReasonsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "rr_123",
|
||||
* },
|
||||
* update: {
|
||||
* value: "damaged",
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update return reasons.
|
||||
*/
|
||||
export const updateReturnReasonsWorkflow = createWorkflow(
|
||||
updateReturnReasonsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdateReturnReasonsWorkflowInput>
|
||||
): WorkflowResponse<OrderReturnReasonDTO[]> => {
|
||||
): WorkflowResponse<UpdateReturnReasonsWorkflowOutput> => {
|
||||
return new WorkflowResponse(updateReturnReasonsStep(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -2,9 +2,21 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
* The data to associate locations with sales channels.
|
||||
*/
|
||||
export interface AssociateLocationsWithSalesChannelsStepInput {
|
||||
/**
|
||||
* The links to create between locations and sales channels.
|
||||
*/
|
||||
links: {
|
||||
/**
|
||||
* The ID of the sales channel.
|
||||
*/
|
||||
sales_channel_id: string
|
||||
/**
|
||||
* The ID of the location.
|
||||
*/
|
||||
location_id: string
|
||||
}[]
|
||||
}
|
||||
@@ -12,7 +24,17 @@ export interface AssociateLocationsWithSalesChannelsStepInput {
|
||||
export const associateLocationsWithSalesChannelsStepId =
|
||||
"associate-locations-with-sales-channels-step"
|
||||
/**
|
||||
* This step creates links between locations and sales channel records.
|
||||
* This step creates links between stock locations and sales channel records.
|
||||
*
|
||||
* @example
|
||||
* const data = associateLocationsWithSalesChannelsStep({
|
||||
* links: [
|
||||
* {
|
||||
* sales_channel_id: "sc_123",
|
||||
* location_id: "sloc_123"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const associateLocationsWithSalesChannelsStep = createStep(
|
||||
associateLocationsWithSalesChannelsStepId,
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to associate products with sales channels.
|
||||
*/
|
||||
export interface AssociateProductsWithSalesChannelsStepInput {
|
||||
/**
|
||||
* The links to create between products and sales channels.
|
||||
*/
|
||||
links: {
|
||||
/**
|
||||
* The ID of the sales channel.
|
||||
*/
|
||||
sales_channel_id: string
|
||||
/**
|
||||
* The ID of the product.
|
||||
*/
|
||||
product_id: string
|
||||
}[]
|
||||
}
|
||||
@@ -12,6 +24,16 @@ export const associateProductsWithSalesChannelsStepId =
|
||||
"associate-products-with-channels"
|
||||
/**
|
||||
* This step creates links between products and sales channel records.
|
||||
*
|
||||
* @example
|
||||
* const data = associateProductsWithSalesChannelsStep({
|
||||
* links: [
|
||||
* {
|
||||
* sales_channel_id: "sc_123",
|
||||
* product_id: "prod_123"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const associateProductsWithSalesChannelsStep = createStep(
|
||||
associateProductsWithSalesChannelsStepId,
|
||||
|
||||
@@ -1,12 +1,32 @@
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
* The data to validate if sales channels can be deleted.
|
||||
*/
|
||||
export type CanDeleteSalesChannelsOrThrowStepInput = {
|
||||
/**
|
||||
* The IDs of the sales channels to validate.
|
||||
*/
|
||||
ids: string | string[]
|
||||
}
|
||||
|
||||
export const canDeleteSalesChannelsOrThrowStepId =
|
||||
"can-delete-sales-channels-or-throw-step"
|
||||
|
||||
/**
|
||||
* This step validates that the specified sales channels can be deleted.
|
||||
* If any of the sales channels are default sales channels for a store,
|
||||
* the step will throw an error.
|
||||
*
|
||||
* @example
|
||||
* const data = canDeleteSalesChannelsOrThrowStep({
|
||||
* ids: ["sc_123"]
|
||||
* })
|
||||
*/
|
||||
export const canDeleteSalesChannelsOrThrowStep = createStep(
|
||||
canDeleteSalesChannelsOrThrowStepId,
|
||||
async ({ ids }: { ids: string | string[] }, { container }) => {
|
||||
async ({ ids }: CanDeleteSalesChannelsOrThrowStepInput, { container }) => {
|
||||
const salesChannelIdsToDelete = Array.isArray(ids) ? ids : [ids]
|
||||
|
||||
const storeModule = await container.resolve(Modules.STORE)
|
||||
|
||||
@@ -5,13 +5,27 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to create a default sales channel.
|
||||
*/
|
||||
export interface CreateDefaultSalesChannelStepInput {
|
||||
/**
|
||||
* The default sales channel data.
|
||||
*/
|
||||
data: CreateSalesChannelDTO
|
||||
}
|
||||
|
||||
export const createDefaultSalesChannelStepId = "create-default-sales-channel"
|
||||
/**
|
||||
* This step creates a default sales channel.
|
||||
* This step creates a default sales channel if none exist in the application.
|
||||
* This is useful when creating seed scripts.
|
||||
*
|
||||
* @example
|
||||
* const data = createDefaultSalesChannelStep({
|
||||
* data: {
|
||||
* name: "Webshop",
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const createDefaultSalesChannelStep = createStep(
|
||||
createDefaultSalesChannelStepId,
|
||||
|
||||
@@ -5,13 +5,26 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to create sales channels.
|
||||
*/
|
||||
export interface CreateSalesChannelsStepInput {
|
||||
/**
|
||||
* The sales channels to create.
|
||||
*/
|
||||
data: CreateSalesChannelDTO[]
|
||||
}
|
||||
|
||||
export const createSalesChannelsStepId = "create-sales-channels"
|
||||
/**
|
||||
* This step creates one or more sales channels.
|
||||
*
|
||||
* @example
|
||||
* const data = createSalesChannelsStep({
|
||||
* data: [{
|
||||
* name: "Webshop",
|
||||
* }]
|
||||
* })
|
||||
*/
|
||||
export const createSalesChannelsStep = createStep(
|
||||
createSalesChannelsStepId,
|
||||
|
||||
@@ -2,13 +2,18 @@ import { ISalesChannelModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the sales channels to delete.
|
||||
*/
|
||||
export type DeleteSalesChannelsStepInput = string[]
|
||||
|
||||
export const deleteSalesChannelsStepId = "delete-sales-channels"
|
||||
/**
|
||||
* This step deletes one or more sales channels.
|
||||
*/
|
||||
export const deleteSalesChannelsStep = createStep(
|
||||
deleteSalesChannelsStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteSalesChannelsStepInput, { container }) => {
|
||||
const service = container.resolve<ISalesChannelModuleService>(
|
||||
Modules.SALES_CHANNEL
|
||||
)
|
||||
|
||||
@@ -3,9 +3,21 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
* The data to detach stock locations from sales channels.
|
||||
*/
|
||||
export interface DetachLocationsFromSalesChannelsStepInput {
|
||||
/**
|
||||
* The links to dismiss between locations and sales channels.
|
||||
*/
|
||||
links: {
|
||||
/**
|
||||
* The ID of the sales channel.
|
||||
*/
|
||||
sales_channel_id: string
|
||||
/**
|
||||
* The ID of the location.
|
||||
*/
|
||||
location_id: string
|
||||
}[]
|
||||
}
|
||||
@@ -13,7 +25,17 @@ export interface DetachLocationsFromSalesChannelsStepInput {
|
||||
export const detachLocationsFromSalesChannelsStepId =
|
||||
"detach-locations-from-sales-channels"
|
||||
/**
|
||||
* This step dismisses links between location and sales channel records.
|
||||
* This step dismisses links between stock location and sales channel records.
|
||||
*
|
||||
* @example
|
||||
* const data = detachLocationsFromSalesChannelsStep({
|
||||
* links: [
|
||||
* {
|
||||
* sales_channel_id: "sc_123",
|
||||
* location_id: "sloc_123"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const detachLocationsFromSalesChannelsStep = createStep(
|
||||
detachLocationsFromSalesChannelsStepId,
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to detach products from sales channels.
|
||||
*/
|
||||
export interface DetachProductsFromSalesChannelsStepInput {
|
||||
/**
|
||||
* The links to dismiss between products and sales channels.
|
||||
*/
|
||||
links: {
|
||||
/**
|
||||
* The ID of the sales channel.
|
||||
*/
|
||||
sales_channel_id: string
|
||||
/**
|
||||
* The ID of the product.
|
||||
*/
|
||||
product_id: string
|
||||
}[]
|
||||
}
|
||||
@@ -12,6 +24,16 @@ export const detachProductsFromSalesChannelsStepId =
|
||||
"detach-products-from-sales-channels-step"
|
||||
/**
|
||||
* This step dismisses links between product and sales channel records.
|
||||
*
|
||||
* @example
|
||||
* const data = detachProductsFromSalesChannelsStep({
|
||||
* links: [
|
||||
* {
|
||||
* sales_channel_id: "sc_123",
|
||||
* product_id: "prod_123"
|
||||
* }
|
||||
* ]
|
||||
* })
|
||||
*/
|
||||
export const detachProductsFromSalesChannelsStep = createStep(
|
||||
detachProductsFromSalesChannelsStepId,
|
||||
|
||||
@@ -9,14 +9,33 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to update sales channels.
|
||||
*/
|
||||
export type UpdateSalesChannelsStepInput = {
|
||||
/**
|
||||
* The filters to select the sales channels to update.
|
||||
*/
|
||||
selector: FilterableSalesChannelProps
|
||||
/**
|
||||
* The data to update the sales channels.
|
||||
*/
|
||||
update: UpdateSalesChannelDTO
|
||||
}
|
||||
|
||||
export const updateSalesChannelsStepId = "update-sales-channels"
|
||||
/**
|
||||
* This step updates sales channels matching the specified filters.
|
||||
*
|
||||
* @example
|
||||
* const data = updateSalesChannelsStep({
|
||||
* selector: {
|
||||
* id: "sc_123"
|
||||
* },
|
||||
* update: {
|
||||
* name: "Webshop"
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateSalesChannelsStep = createStep(
|
||||
updateSalesChannelsStepId,
|
||||
|
||||
@@ -12,19 +12,50 @@ import {
|
||||
import { emitEventStep } from "../../common/steps/emit-event"
|
||||
import { createSalesChannelsStep } from "../steps/create-sales-channels"
|
||||
|
||||
/**
|
||||
* The data to create sales channels.
|
||||
*/
|
||||
export type CreateSalesChannelsWorkflowInput = {
|
||||
/**
|
||||
* The sales channels to create.
|
||||
*/
|
||||
salesChannelsData: CreateSalesChannelDTO[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The created sales channels.
|
||||
*/
|
||||
export type CreateSalesChannelsWorkflowOutput = SalesChannelDTO[]
|
||||
|
||||
export const createSalesChannelsWorkflowId = "create-sales-channels"
|
||||
/**
|
||||
* This workflow creates one or more sales channels.
|
||||
* This workflow creates one or more sales channels. It's used by the
|
||||
* [Create Sales Channel Admin API Route](https://docs.medusajs.com/api/admin#sales-channels_postsaleschannels).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create sales channels within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createSalesChannelsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* salesChannelsData: [
|
||||
* {
|
||||
* name: "Webshop"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create sales channels.
|
||||
*/
|
||||
export const createSalesChannelsWorkflow = createWorkflow(
|
||||
createSalesChannelsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<CreateSalesChannelsWorkflowInput>
|
||||
): WorkflowResponse<SalesChannelDTO[]> => {
|
||||
): WorkflowResponse<CreateSalesChannelsWorkflowOutput> => {
|
||||
const createdSalesChannels = createSalesChannelsStep({
|
||||
data: input.salesChannelsData,
|
||||
})
|
||||
|
||||
@@ -9,11 +9,35 @@ import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||
import { deleteSalesChannelsStep } from "../steps/delete-sales-channels"
|
||||
import { canDeleteSalesChannelsOrThrowStep } from "../steps"
|
||||
|
||||
export type DeleteSalesChannelsWorkflowInput = { ids: string[] }
|
||||
/**
|
||||
* The data to delete sales channels.
|
||||
*/
|
||||
export type DeleteSalesChannelsWorkflowInput = {
|
||||
/**
|
||||
* The IDs of the sales channels to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteSalesChannelsWorkflowId = "delete-sales-channels"
|
||||
/**
|
||||
* This workflow deletes one or more sales channels.
|
||||
* This workflow deletes one or more sales channels. It's used by the
|
||||
* [Delete Sales Channel Admin API Route](https://docs.medusajs.com/api/admin#sales-channels_deletesaleschannelsid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete sales channels within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteSalesChannelsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["sc_123"],
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete sales channels.
|
||||
*/
|
||||
export const deleteSalesChannelsWorkflow = createWorkflow(
|
||||
deleteSalesChannelsWorkflowId,
|
||||
|
||||
@@ -4,14 +4,41 @@ import { associateProductsWithSalesChannelsStep } from "../steps/associate-produ
|
||||
import { transform } from "@medusajs/framework/workflows-sdk"
|
||||
import { detachProductsFromSalesChannelsStep } from "../steps"
|
||||
|
||||
/**
|
||||
* The data to manage products available in a sales channel.
|
||||
*
|
||||
* @property id - The ID of the sales channel.
|
||||
* @property add - The products to add to the sales channel.
|
||||
* @property remove - The products to remove from the sales channel.
|
||||
*/
|
||||
export type LinkProductsToSalesChannelWorkflowInput = LinkWorkflowInput
|
||||
|
||||
export const linkProductsToSalesChannelWorkflowId =
|
||||
"link-products-to-sales-channel"
|
||||
/**
|
||||
* This workflow creates or dismisses links between product and sales channel records.
|
||||
* This workflow manages the products available in a sales channel. It's used by the
|
||||
* [Manage Products Admin API Route](https://docs.medusajs.com/api/admin#sales-channels_postsaleschannelsidproducts).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* manage the products available in a sales channel within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await linkProductsToSalesChannelWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* id: "sc_123",
|
||||
* add: ["prod_123"],
|
||||
* remove: ["prod_321"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Manage the products available in a sales channel.
|
||||
*/
|
||||
export const linkProductsToSalesChannelWorkflow = createWorkflow(
|
||||
linkProductsToSalesChannelWorkflowId,
|
||||
(input: WorkflowData<LinkWorkflowInput>): WorkflowData<void> => {
|
||||
(input: WorkflowData<LinkProductsToSalesChannelWorkflowInput>): WorkflowData<void> => {
|
||||
const toAdd = transform({ input }, (data) => {
|
||||
return data.input.add?.map((productId) => ({
|
||||
sales_channel_id: data.input.id,
|
||||
|
||||
@@ -13,20 +13,55 @@ import {
|
||||
import { emitEventStep } from "../../common"
|
||||
import { updateSalesChannelsStep } from "../steps/update-sales-channels"
|
||||
|
||||
/**
|
||||
* The data to update sales channels.
|
||||
*/
|
||||
export type UpdateSalesChannelsWorkflowInput = {
|
||||
/**
|
||||
* The filters to select the sales channels to update.
|
||||
*/
|
||||
selector: FilterableSalesChannelProps
|
||||
/**
|
||||
* The data to update the sales channels.
|
||||
*/
|
||||
update: UpdateSalesChannelDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* The updated sales channels.
|
||||
*/
|
||||
export type UpdateSalesChannelsWorkflowOutput = SalesChannelDTO[]
|
||||
|
||||
export const updateSalesChannelsWorkflowId = "update-sales-channels"
|
||||
/**
|
||||
* This workflow updates sales channels matching the specified conditions.
|
||||
* This workflow updates sales channels matching the specified conditions. It's used by the
|
||||
* [Update Sales Channel Admin API Route](https://docs.medusajs.com/api/admin#sales-channels_postsaleschannelsid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update sales channels within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateSalesChannelsWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "sc_123"
|
||||
* },
|
||||
* update: {
|
||||
* name: "Webshop"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update sales channels.
|
||||
*/
|
||||
export const updateSalesChannelsWorkflow = createWorkflow(
|
||||
updateSalesChannelsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdateSalesChannelsWorkflowInput>
|
||||
): WorkflowResponse<SalesChannelDTO[]> => {
|
||||
): WorkflowResponse<UpdateSalesChannelsWorkflowOutput> => {
|
||||
const updatedSalesChannels = updateSalesChannelsStep(input)
|
||||
|
||||
const salesChannelIdEvents = transform(
|
||||
|
||||
@@ -6,15 +6,60 @@ import {
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to retrieve the list of shipping options.
|
||||
*/
|
||||
export interface ListShippingOptionsForContextStepInput {
|
||||
/**
|
||||
* The context of retrieving the shipping options. This context
|
||||
* will be compared against shipping options' rules. The key
|
||||
* of the context is a name of an attribute, and the value is
|
||||
* the attribute's value. Shipping options that have rules
|
||||
* matching this context are retrieved.
|
||||
*/
|
||||
context: Record<string, unknown>
|
||||
/**
|
||||
* The fields and relations to select in the returned shipping options,
|
||||
* along with pagination and sorting options.
|
||||
*
|
||||
* Learn more in the [service factory reference](https://docs.medusajs.com/resources/service-factory-reference/methods/list).
|
||||
*/
|
||||
config?: FindConfig<ShippingOptionDTO>
|
||||
}
|
||||
|
||||
export const listShippingOptionsForContextStepId =
|
||||
"list-shipping-options-for-context"
|
||||
/**
|
||||
* This step retrieves shipping options that can be used in the specified context.
|
||||
* This step retrieves shipping options that can be used in the specified context, based on
|
||||
* the shipping options' rules.
|
||||
*
|
||||
* @example
|
||||
* To retrieve shipping options matching a context:
|
||||
*
|
||||
* ```ts
|
||||
* const data = listShippingOptionsForContextStep({
|
||||
* context: {
|
||||
* region_id: "reg_123"
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To retrieve shipping options matching a context with pagination:
|
||||
*
|
||||
* ```ts
|
||||
* const data = listShippingOptionsForContextStep({
|
||||
* context: {
|
||||
* region_id: "reg_123"
|
||||
* },
|
||||
* config: {
|
||||
* skip: 0,
|
||||
* take: 10
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Learn more about paginating records and selecting fields in the
|
||||
* [service factory reference](https://docs.medusajs.com/resources/service-factory-reference/methods/list).
|
||||
*/
|
||||
export const listShippingOptionsForContextStep = createStep(
|
||||
listShippingOptionsForContextStepId,
|
||||
|
||||
@@ -2,13 +2,18 @@ import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the shipping profiles to delete.
|
||||
*/
|
||||
export type DeleteShippingProfilesStepInput = string[]
|
||||
|
||||
export const deleteShippingProfilesStepId = "delete-shipping-profile"
|
||||
/**
|
||||
* This step deletes one or more shipping profiles.
|
||||
*/
|
||||
export const deleteShippingProfilesStep = createStep(
|
||||
deleteShippingProfilesStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteShippingProfilesStepInput, { container }) => {
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
Modules.FULFILLMENT
|
||||
)
|
||||
|
||||
@@ -4,14 +4,40 @@ import { deleteShippingProfilesStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
* The data to delete shipping profiles.
|
||||
*/
|
||||
export type DeleteShippingProfilesWorkflowInput = {
|
||||
/**
|
||||
* The IDs of the shipping profiles to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteShippingProfileWorkflowId =
|
||||
"delete-shipping-profile-workflow"
|
||||
/**
|
||||
* This workflow deletes one or more shipping profiles.
|
||||
* This workflow deletes one or more shipping profiles. It's used by the
|
||||
* [Delete Shipping Profile Admin API Route](https://docs.medusajs.com/api/admin#shipping-profiles_deleteshippingprofilesid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete shipping profiles within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteShippingProfileWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["sp_123"]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Delete shipping profiles.
|
||||
*/
|
||||
export const deleteShippingProfileWorkflow = createWorkflow(
|
||||
deleteShippingProfileWorkflowId,
|
||||
(input: WorkflowData<{ ids: string[] }>) => {
|
||||
(input: WorkflowData<DeleteShippingProfilesWorkflowInput>) => {
|
||||
deleteShippingProfilesStep(input.ids)
|
||||
|
||||
removeRemoteLinkStep({
|
||||
|
||||
@@ -5,6 +5,11 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
export const createStoresStepId = "create-stores"
|
||||
/**
|
||||
* This step creates one or more stores.
|
||||
*
|
||||
* @example
|
||||
* const data = createStoresStep([{
|
||||
* name: "Acme"
|
||||
* }])
|
||||
*/
|
||||
export const createStoresStep = createStep(
|
||||
createStoresStepId,
|
||||
|
||||
@@ -2,13 +2,18 @@ import { IStoreModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The IDs of the stores to delete.
|
||||
*/
|
||||
export type DeleteStoresStepInput = string[]
|
||||
|
||||
export const deleteStoresStepId = "delete-stores"
|
||||
/**
|
||||
* This step deletes one or more stores.
|
||||
*/
|
||||
export const deleteStoresStep = createStep(
|
||||
deleteStoresStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
async (ids: DeleteStoresStepInput, { container }) => {
|
||||
const storeModule = container.resolve<IStoreModuleService>(Modules.STORE)
|
||||
|
||||
await storeModule.softDeleteStores(ids)
|
||||
|
||||
@@ -9,14 +9,33 @@ import {
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to update in a store.
|
||||
*/
|
||||
export type UpdateStoresStepInput = {
|
||||
/**
|
||||
* The filters to select the stores to update.
|
||||
*/
|
||||
selector: FilterableStoreProps
|
||||
/**
|
||||
* The data to update in the stores.
|
||||
*/
|
||||
update: UpdateStoreDTO
|
||||
}
|
||||
|
||||
export const updateStoresStepId = "update-stores"
|
||||
/**
|
||||
* This step updates stores matching the specified filters.
|
||||
*
|
||||
* @example
|
||||
* const data = updateStoresStep({
|
||||
* selector: {
|
||||
* id: "store_123"
|
||||
* },
|
||||
* update: {
|
||||
* name: "Acme"
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const updateStoresStep = createStep(
|
||||
updateStoresStepId,
|
||||
|
||||
@@ -8,19 +8,54 @@ import {
|
||||
import { createStoresStep } from "../steps"
|
||||
import { updatePricePreferencesAsArrayStep } from "../../pricing"
|
||||
|
||||
type CreateStoresWorkflowInput = {
|
||||
/**
|
||||
* The data to create stores.
|
||||
*/
|
||||
export type CreateStoresWorkflowInput = {
|
||||
/**
|
||||
* The stores to create.
|
||||
*/
|
||||
stores: StoreWorkflow.CreateStoreWorkflowInput[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The created stores.
|
||||
*/
|
||||
export type CreateStoresWorkflowOutput = StoreDTO[]
|
||||
|
||||
export const createStoresWorkflowId = "create-stores"
|
||||
/**
|
||||
* This workflow creates one or more stores.
|
||||
* This workflow creates one or more stores. By default, Medusa uses a single store. This is useful
|
||||
* if you're building a multi-tenant application or a marketplace where each tenant has its own store.
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* create stores within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createStoresWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* stores: [
|
||||
* {
|
||||
* name: "Acme",
|
||||
* supported_currencies: [{
|
||||
* currency_code: "usd",
|
||||
* is_default: true
|
||||
* }]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Create one or more stores.
|
||||
*/
|
||||
export const createStoresWorkflow = createWorkflow(
|
||||
createStoresWorkflowId,
|
||||
(
|
||||
input: WorkflowData<CreateStoresWorkflowInput>
|
||||
): WorkflowResponse<StoreDTO[]> => {
|
||||
): WorkflowResponse<CreateStoresWorkflowOutput> => {
|
||||
const normalizedInput = transform({ input }, (data) => {
|
||||
return data.input.stores.map((store) => {
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,38 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||
import { deleteStoresStep } from "../steps"
|
||||
|
||||
export type DeleteStoresWorkflowInput = { ids: string[] }
|
||||
/**
|
||||
* The data to delete stores.
|
||||
*/
|
||||
export type DeleteStoresWorkflowInput = {
|
||||
/**
|
||||
* The IDs of the stores to delete.
|
||||
*/
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deleteStoresWorkflowId = "delete-stores"
|
||||
/**
|
||||
* This workflow deletes one or more stores.
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
* By default, Medusa uses a single store. This is useful
|
||||
* if you're building a multi-tenant application or a marketplace where each tenant has its own store.
|
||||
* If you delete the only store in your application, the Medusa application will re-create it on application start-up.
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* delete stores within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await deleteStoresWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* ids: ["store_123"]
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const deleteStoresWorkflow = createWorkflow(
|
||||
deleteStoresWorkflowId,
|
||||
|
||||
@@ -9,15 +9,41 @@ import {
|
||||
import { updateStoresStep } from "../steps"
|
||||
import { updatePricePreferencesAsArrayStep } from "../../pricing"
|
||||
|
||||
/**
|
||||
* The updated stores.
|
||||
*/
|
||||
export type UpdateStoresWorkflowOutput = StoreDTO[]
|
||||
|
||||
export const updateStoresWorkflowId = "update-stores"
|
||||
/**
|
||||
* This workflow updates stores matching the specified filters.
|
||||
* This workflow updates stores matching the specified filters. It's used by the
|
||||
* [Update Store Admin API Route](https://docs.medusajs.com/api/admin#stores_poststoresid).
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||
* update stores within your custom flows.
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateStoresWorkflow(container)
|
||||
* .run({
|
||||
* input: {
|
||||
* selector: {
|
||||
* id: "store_123"
|
||||
* },
|
||||
* update: {
|
||||
* name: "Acme"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
* Update stores.
|
||||
*/
|
||||
export const updateStoresWorkflow = createWorkflow(
|
||||
updateStoresWorkflowId,
|
||||
(
|
||||
input: WorkflowData<StoreWorkflow.UpdateStoreWorkflowInput>
|
||||
): WorkflowResponse<StoreDTO[]> => {
|
||||
): WorkflowResponse<UpdateStoresWorkflowOutput> => {
|
||||
const normalizedInput = transform({ input }, (data) => {
|
||||
if (!data.input.update.supported_currencies?.length) {
|
||||
return data.input
|
||||
|
||||
@@ -16,6 +16,8 @@ export interface CreateApiKeyDTO {
|
||||
|
||||
/**
|
||||
* Who created the API key.
|
||||
* If the API key type is `secret`, the user can use the created API key's token to authenticate
|
||||
* as explained in the [API Reference](https://docs.medusajs.com/api/admin#2-api-token).
|
||||
*/
|
||||
created_by: string
|
||||
// We could add revoked_at as a parameter (or expires_at that gets mapped to revoked_at internally) in order to support expiring tokens
|
||||
|
||||
@@ -1,14 +1,52 @@
|
||||
interface AdminUpdateStoreSupportedCurrency {
|
||||
/**
|
||||
* The details of a supported currency in a store.
|
||||
*/
|
||||
export interface AdminUpdateStoreSupportedCurrency {
|
||||
/**
|
||||
* The currency's ISO 3 code.
|
||||
*
|
||||
* @example
|
||||
* usd
|
||||
*/
|
||||
currency_code: string
|
||||
/**
|
||||
* Whether this currency is the default currency in the store.
|
||||
*/
|
||||
is_default?: boolean
|
||||
/**
|
||||
* Whether prices in this currency are tax inclusive.
|
||||
*
|
||||
* Learn more in [this documentation](https://docs.medusajs.com/resources/commerce-modules/pricing/tax-inclusive-pricing).
|
||||
*/
|
||||
is_tax_inclusive?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* The data to update in a store.
|
||||
*/
|
||||
export interface AdminUpdateStore {
|
||||
/**
|
||||
* The name of the store.
|
||||
*/
|
||||
name?: string
|
||||
/**
|
||||
* The supported currencies of the store.
|
||||
*/
|
||||
supported_currencies?: AdminUpdateStoreSupportedCurrency[]
|
||||
/**
|
||||
* The ID of the default sales channel of the store.
|
||||
*/
|
||||
default_sales_channel_id?: string | null
|
||||
/**
|
||||
* The ID of the default region of the store.
|
||||
*/
|
||||
default_region_id?: string | null
|
||||
/**
|
||||
* The ID of the default stock location of the store.
|
||||
*/
|
||||
default_location_id?: string | null
|
||||
/**
|
||||
* Custom key-value pairs to store custom data in the store.
|
||||
*/
|
||||
metadata?: Record<string, any> | null
|
||||
}
|
||||
|
||||
@@ -5,11 +5,26 @@ import {
|
||||
UpdateProductCategoryDTO,
|
||||
} from "../../product"
|
||||
|
||||
/**
|
||||
* The data to create product categories.
|
||||
*/
|
||||
export interface CreateProductCategoriesWorkflowInput {
|
||||
/**
|
||||
* The product categories to create.
|
||||
*/
|
||||
product_categories: CreateProductCategoryDTO[]
|
||||
}
|
||||
/**
|
||||
* The data to update product categories.
|
||||
*/
|
||||
export interface UpdateProductCategoriesWorkflowInput {
|
||||
/**
|
||||
* The filters to select the product categories to update.
|
||||
*/
|
||||
selector: FilterableProductCategoryProps
|
||||
/**
|
||||
* The data to update in the product categories.
|
||||
*/
|
||||
update: UpdateProductCategoryDTO
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,47 @@
|
||||
import { AdminUpdateStore } from "../../http"
|
||||
import { CreateStoreDTO, FilterableStoreProps } from "../../store"
|
||||
|
||||
/**
|
||||
* The stores to create.
|
||||
*/
|
||||
export type CreateStoreWorkflowInput = Omit<
|
||||
CreateStoreDTO,
|
||||
"supported_currencies"
|
||||
> & {
|
||||
/**
|
||||
* The supported currencies of the store.
|
||||
*/
|
||||
supported_currencies: {
|
||||
/**
|
||||
* The currency ISO 3 code.
|
||||
*
|
||||
* @example
|
||||
* usd
|
||||
*/
|
||||
currency_code: string
|
||||
/**
|
||||
* Whether this currency is the default currency in the store.
|
||||
*/
|
||||
is_default?: boolean
|
||||
/**
|
||||
* Whether prices in this currency are tax inclusive.
|
||||
*
|
||||
* Learn more in [this documentation](https://docs.medusajs.com/resources/commerce-modules/pricing/tax-inclusive-pricing).
|
||||
*/
|
||||
is_tax_inclusive?: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The data to update stores.
|
||||
*/
|
||||
export interface UpdateStoreWorkflowInput {
|
||||
/**
|
||||
* The filters to select the stores to update.
|
||||
*/
|
||||
selector: FilterableStoreProps
|
||||
/**
|
||||
* The data to update in the stores.
|
||||
*/
|
||||
update: AdminUpdateStore
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user