Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core-flows): [1] export types and types, add basic TSDocs #8504

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { CreateApiKeyDTO, IApiKeyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type CreateApiKeysStepInput = {
export type CreateApiKeysStepInput = {
api_keys: CreateApiKeyDTO[]
}

export const createApiKeysStepId = "create-api-keys"
/**
* This step creates one or more API keys.
*/
export const createApiKeysStep = createStep(
createApiKeysStepId,
async (data: CreateApiKeysStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

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 }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ContainerRegistrationKeys, Modules, promiseAll } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const linkSalesChannelsToApiKeyStepId = "link-sales-channels-to-api-key"
/**
* This step links sales channels to API keys.
*/
export const linkSalesChannelsToApiKeyStep = createStep(
linkSalesChannelsToApiKeyStepId,
async (input: LinkWorkflowInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import {
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type RevokeApiKeysStepInput = {
export type RevokeApiKeysStepInput = {
selector: FilterableApiKeyProps
revoke: RevokeApiKeyDTO
}

export const revokeApiKeysStepId = "revoke-api-keys"
/**
* This step revokes one or more API keys.
*/
export const revokeApiKeysStep = createStep(
{ name: revokeApiKeysStepId, noCompensation: true },
async (data: RevokeApiKeysStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type UpdateApiKeysStepInput = {
export type UpdateApiKeysStepInput = {
selector: FilterableApiKeyProps
update: UpdateApiKeyDTO
}

export const updateApiKeysStepId = "update-api-keys"
/**
* This step updates one or more API keys.
*/
export const updateApiKeysStep = createStep(
updateApiKeysStepId,
async (data: UpdateApiKeysStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface ValidateSalesChannelsExistStepInput {
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.
*/
export const validateSalesChannelsExistStep = createStep(
validateSalesChannelsExistStepId,
async (data: StepInput, { container }) => {
async (data: ValidateSalesChannelsExistStepInput, { container }) => {
const salesChannelModuleService =
container.resolve<ISalesChannelModuleService>(
ModuleRegistrationName.SALES_CHANNEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import {
} from "@medusajs/workflows-sdk"
import { createApiKeysStep } from "../steps"

type WorkflowInput = { api_keys: CreateApiKeyDTO[] }
export type CreateApiKeysWorkflowInput = { api_keys: CreateApiKeyDTO[] }

export const createApiKeysWorkflowId = "create-api-keys"
/**
* This workflow creates one or more API keys.
*/
export const createApiKeysWorkflow = createWorkflow(
createApiKeysWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
(input: WorkflowData<CreateApiKeysWorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
return new WorkflowResponse(createApiKeysStep(input))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
import { deleteApiKeysStep } from "../steps"
import { Modules } from "@medusajs/utils"

type WorkflowInput = { ids: string[] }
export type DeleteApiKeysWorkflowInput = { ids: string[] }

export const deleteApiKeysWorkflowId = "delete-api-keys"
/**
* This workflow deletes one or more API keys.
*/
export const deleteApiKeysWorkflow = createWorkflow(
deleteApiKeysWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<DeleteApiKeysWorkflowInput>): WorkflowData<void> => {
deleteApiKeysStep(input.ids)

// Please note, the ids here should be publishable key IDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {

export const linkSalesChannelsToApiKeyWorkflowId =
"link-sales-channels-to-api-key"
/**
* This workflow links sales channels to API keys.
*/
export const linkSalesChannelsToApiKeyWorkflow = createWorkflow(
linkSalesChannelsToApiKeyWorkflowId,
(input: WorkflowData<LinkWorkflowInput>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import {
} from "@medusajs/workflows-sdk"
import { revokeApiKeysStep } from "../steps"

type RevokeApiKeysStepInput = {
export type RevokeApiKeysWorkflowInput = {
selector: FilterableApiKeyProps
revoke: RevokeApiKeyDTO
}

type WorkflowInput = RevokeApiKeysStepInput

export const revokeApiKeysWorkflowId = "revoke-api-keys"
/**
* This workflow revokes one or more API keys.
*/
export const revokeApiKeysWorkflow = createWorkflow(
revokeApiKeysWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
(input: WorkflowData<RevokeApiKeysWorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
return new WorkflowResponse(revokeApiKeysStep(input))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import {
} from "@medusajs/workflows-sdk"
import { updateApiKeysStep } from "../steps"

type UpdateApiKeysStepInput = {
export type UpdateApiKeysWorkflowInput = {
selector: FilterableApiKeyProps
update: UpdateApiKeyDTO
}

type WorkflowInput = UpdateApiKeysStepInput

export const updateApiKeysWorkflowId = "update-api-keys"
/**
* This workflow creates one or more API keys.
*/
export const updateApiKeysWorkflow = createWorkflow(
updateApiKeysWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
(input: WorkflowData<UpdateApiKeysWorkflowInput>): WorkflowResponse<ApiKeyDTO[]> => {
return new WorkflowResponse(updateApiKeysStep(input))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { createStep, StepResponse } from "@medusajs/workflows-sdk"
import { IAuthModuleService } from "@medusajs/types"
import { isDefined, ModuleRegistrationName } from "@medusajs/utils"

type StepInput = {
export type SetAuthAppMetadataStepInput = {
authIdentityId: string
actorType: string
value: string
}

export const setAuthAppMetadataStepId = "set-auth-app-metadata"
/**
* This step sets the `app_metadata` property of an auth identity.
*/
export const setAuthAppMetadataStep = createStep(
setAuthAppMetadataStepId,
async (data: StepInput, { container }) => {
async (data: SetAuthAppMetadataStepInput, { container }) => {
const service = container.resolve<IAuthModuleService>(
ModuleRegistrationName.AUTH
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { dismissRemoteLinkStep } from "../steps/dismiss-remote-links"
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.
*/
export const batchLinksWorkflow = createWorkflow(
batchLinksWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { createRemoteLinkStep } from "../steps/create-remote-links"

export const createLinksWorkflowId = "create-link"
/**
* This workflow creates one or more links between records.
*/
export const createLinksWorkflow = createWorkflow(
createLinksWorkflowId,
(input: WorkflowData<LinkDefinition[]>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { dismissRemoteLinkStep } from "../steps/dismiss-remote-links"

export const dismissLinksWorkflowId = "dismiss-link"
/**
* This workflow dismisses one or more links between records.
*/
export const dismissLinksWorkflow = createWorkflow(
dismissLinksWorkflowId,
(input: WorkflowData<LinkDefinition[]>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { updateRemoteLinksStep } from "../steps/update-remote-links"

export const updateLinksWorkflowId = "update-link"
/**
* This workflow updates one or more links between records.
*/
export const updateLinksWorkflow = createWorkflow(
updateLinksWorkflowId,
(input: WorkflowData<LinkDefinition[]>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const createCustomerAddressesStepId = "create-customer-addresses"
/**
* This step creates one or more customer addresses.
*/
export const createCustomerAddressesStep = createStep(
createCustomerAddressesStepId,
async (data: CreateCustomerAddressDTO[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const createCustomersStepId = "create-customers"
/**
* This step creates one or more customers.
*/
export const createCustomersStep = createStep(
createCustomersStepId,
async (data: CreateCustomerDTO[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

type DeleteCustomerAddressStepInput = string[]
export const deleteCustomerAddressesStepId = "delete-customer-addresses"
/**
* This step deletes one or more customer addresses.
*/
export const deleteCustomerAddressesStep = createStep(
deleteCustomerAddressesStepId,
async (ids: DeleteCustomerAddressStepInput, { container }) => {
async (ids: string[], { container }) => {
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

type DeleteCustomerStepInput = string[]

export const deleteCustomersStepId = "delete-customers"
/**
* This step deletes one or more customers.
*/
export const deleteCustomersStep = createStep(
deleteCustomersStepId,
async (ids: DeleteCustomerStepInput, { container }) => {
async (ids: string[], { container }) => {
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ModuleRegistrationName, isDefined } from "@medusajs/utils"
import { createStep } from "@medusajs/workflows-sdk"
import { unsetForCreate, unsetForUpdate } from "./utils"

type StepInput = {
export type MaybeUnsetDefaultBillingAddressStepInput = {
create?: CreateCustomerAddressDTO[]
update?: {
selector: FilterableCustomerAddressProps
Expand All @@ -18,9 +18,12 @@ type StepInput = {

export const maybeUnsetDefaultBillingAddressesStepId =
"maybe-unset-default-billing-customer-addresses"
/**
* This step unsets the `is_default_billing` property of one or more addresses.
*/
export const maybeUnsetDefaultBillingAddressesStep = createStep(
maybeUnsetDefaultBillingAddressesStepId,
async (data: StepInput, { container }) => {
async (data: MaybeUnsetDefaultBillingAddressStepInput, { container }) => {
const customerModuleService = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ModuleRegistrationName, isDefined } from "@medusajs/utils"
import { createStep } from "@medusajs/workflows-sdk"
import { unsetForCreate, unsetForUpdate } from "./utils"

type StepInput = {
export type MaybeUnsetDefaultShippingAddressesStepInput = {
create?: CreateCustomerAddressDTO[]
update?: {
selector: FilterableCustomerAddressProps
Expand All @@ -18,9 +18,12 @@ type StepInput = {

export const maybeUnsetDefaultShippingAddressesStepId =
"maybe-unset-default-shipping-customer-addresses"
/**
* This step unsets the `is_default_shipping` property of one or more addresses.
*/
export const maybeUnsetDefaultShippingAddressesStep = createStep(
maybeUnsetDefaultShippingAddressesStepId,
async (data: StepInput, { container }) => {
async (data: MaybeUnsetDefaultShippingAddressesStepInput, { container }) => {
const customerModuleService = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type UpdateCustomerAddresseStepInput = {
export type UpdateCustomerAddresseStepInput = {
selector: FilterableCustomerAddressProps
update: UpdateCustomerAddressDTO
}

export const updateCustomerAddresseStepId = "update-customer-addresses"
/**
* This step updates one or more customer addresses.
*/
export const updateCustomerAddressesStep = createStep(
updateCustomerAddresseStepId,
async (data: UpdateCustomerAddresseStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type UpdateCustomersStepInput = {
export type UpdateCustomersStepInput = {
selector: FilterableCustomerProps
update: CustomerUpdatableFields
}

export const updateCustomersStepId = "update-customer"
/**
* This step updates one or more customers.
*/
export const updateCustomersStep = createStep(
updateCustomersStepId,
async (data: UpdateCustomersStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import {
maybeUnsetDefaultShippingAddressesStep,
} from "../steps"

type WorkflowInput = { addresses: CreateCustomerAddressDTO[] } & AdditionalData
export type CreateCustomerAddressesWorkflowInput = { addresses: CreateCustomerAddressDTO[] } & AdditionalData

export const createCustomerAddressesWorkflowId = "create-customer-addresses"
/**
* This workflow creates one or more customer address.
*/
export const createCustomerAddressesWorkflow = createWorkflow(
createCustomerAddressesWorkflowId,
(input: WorkflowData<WorkflowInput>) => {
(input: WorkflowData<CreateCustomerAddressesWorkflowInput>) => {
const unsetInput = transform(input, (data) => ({
create: data.addresses,
}))
Expand Down
Loading
Loading