Find or Create Customer Step (steps/find-or-create-customer.ts)

medusa · packages/core/core-flows/src/cart/steps/find-or-create-customer.ts · typescript · MIT
crm, payments, email, tag:medusa, tag:workflow-step

Workflow step that finds a customer by ID or email, or creates a new customer when none exists. Reuse in cart and checkout flows needing customer resolution.

// Source: https://github.com/medusajs/medusa | License: MIT | Copyright 2021 Medusajs
// Provided via justclaw.it.com; keep this notice with the code.
import type {
  CustomerDTO,
  ICustomerModuleService,
  MedusaContainer,
} from "@medusajs/framework/types"
import {
  isDefined,
  Modules,
  useCache,
  validateEmail,
} from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"

/**
 * The details of the customer to find or create.
 */
export interface FindOrCreateCustomerStepInput {
  /**
   * The ID of the customer to find.
   */
  customerId?: string | null
  /**
   * If the `customerId` isn't specified,
   * find a customer with this email or create a new customer having this email.
   */
  email?: string | null
}

/**
 * The detail

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key