JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 70
  • Score
    100M100P100Q82941F
  • License MIT

Customer management module for 86d commerce platform

Package Exports

  • @86d-app/customers/__tests__/controllers.test.ts
  • @86d-app/customers/__tests__/endpoint-security.test.ts
  • @86d-app/customers/__tests__/service-impl.test.ts
  • @86d-app/customers/__tests__/store-endpoints.test.ts
  • @86d-app/customers/__tests__/store-loyalty-endpoints.test.ts
  • @86d-app/customers/admin/components/customer-detail.mdx
  • @86d-app/customers/admin/components/customer-detail.tsx
  • @86d-app/customers/admin/components/customer-list.mdx
  • @86d-app/customers/admin/components/customer-list.tsx
  • @86d-app/customers/admin/components/customer-tags.tsx
  • @86d-app/customers/admin/components/index.tsx
  • @86d-app/customers/admin/components/loyalty-admin.tsx
  • @86d-app/customers/admin/endpoints/bulk-tags.ts
  • @86d-app/customers/admin/endpoints/delete-customer.ts
  • @86d-app/customers/admin/endpoints/export-customers.ts
  • @86d-app/customers/admin/endpoints/get-customer.ts
  • @86d-app/customers/admin/endpoints/import-customers.ts
  • @86d-app/customers/admin/endpoints/index.ts
  • @86d-app/customers/admin/endpoints/list-customers.ts
  • @86d-app/customers/admin/endpoints/list-tags.ts
  • @86d-app/customers/admin/endpoints/loyalty-adjust.ts
  • @86d-app/customers/admin/endpoints/loyalty-balance.ts
  • @86d-app/customers/admin/endpoints/loyalty-earn.ts
  • @86d-app/customers/admin/endpoints/loyalty-redeem.ts
  • @86d-app/customers/admin/endpoints/loyalty-stats.ts
  • @86d-app/customers/admin/endpoints/manage-tags.ts
  • @86d-app/customers/admin/endpoints/update-customer.ts
  • @86d-app/customers/index.ts
  • @86d-app/customers/mdx.d.ts
  • @86d-app/customers/schema.ts
  • @86d-app/customers/service-impl.ts
  • @86d-app/customers/service.ts
  • @86d-app/customers/store/components/_hooks.ts
  • @86d-app/customers/store/components/account-profile.mdx
  • @86d-app/customers/store/components/account-profile.tsx
  • @86d-app/customers/store/components/address-book.mdx
  • @86d-app/customers/store/components/address-book.tsx
  • @86d-app/customers/store/components/index.tsx
  • @86d-app/customers/store/components/loyalty-card.mdx
  • @86d-app/customers/store/components/loyalty-card.tsx
  • @86d-app/customers/store/endpoints/create-address.ts
  • @86d-app/customers/store/endpoints/delete-address.ts
  • @86d-app/customers/store/endpoints/get-me.ts
  • @86d-app/customers/store/endpoints/index.ts
  • @86d-app/customers/store/endpoints/list-addresses.ts
  • @86d-app/customers/store/endpoints/loyalty-balance.ts
  • @86d-app/customers/store/endpoints/loyalty-history.ts
  • @86d-app/customers/store/endpoints/update-address.ts
  • @86d-app/customers/store/endpoints/update-me.ts

Readme

86d

Dynamic Commerce

X ยท LinkedIn


[!WARNING] This project is under active development and is not ready for production use. Please proceed with caution. Use at your own risk.

Customers Module

๐Ÿ“š Documentation: 86d.app/docs/modules/customers

Customer profile and address management. Authenticated customers can view and edit their profile and saved addresses. Admins have full read/write access to all customer records.

Installation

npm install @86d-app/customers

Usage

import customers from "@86d-app/customers";

const module = customers({
  autoCreateOnSignup: true,
});

Configuration

Option Type Default Description
autoCreateOnSignup boolean true Automatically create a customer record when a user signs up

Store Endpoints

All store endpoints require an authenticated session.

Method Path Description
GET /customers/me Get the authenticated customer's profile
PUT /customers/me/update Update the authenticated customer's profile
GET /customers/me/addresses List all addresses for the authenticated customer
POST /customers/me/addresses/create Add a new address
PUT /customers/me/addresses/:id Update an existing address
DELETE /customers/me/addresses/:id/delete Delete an address

Admin Endpoints

Method Path Description
GET /admin/customers List all customers (paginated, searchable)
GET /admin/customers/:id Get a customer by ID
PUT /admin/customers/:id/update Update a customer
DELETE /admin/customers/:id/delete Delete a customer

Controller API

interface CustomerController {
  /** Look up a customer by their ID */
  getById(id: string): Promise<Customer | null>;

  /** Look up a customer by their email address */
  getByEmail(email: string): Promise<Customer | null>;

  /** Create a new customer record */
  create(params: {
    id?: string;
    email: string;
    firstName: string;
    lastName: string;
    phone?: string;
    dateOfBirth?: Date;
    metadata?: Record<string, unknown>;
  }): Promise<Customer>;

  /** Update an existing customer's profile fields */
  update(
    id: string,
    params: {
      firstName?: string;
      lastName?: string;
      phone?: string | null;
      dateOfBirth?: Date | null;
      metadata?: Record<string, unknown>;
    },
  ): Promise<Customer | null>;

  /** Hard-delete a customer */
  delete(id: string): Promise<void>;

  /** List customers with optional search and pagination */
  list(params: {
    limit?: number;
    offset?: number;
    search?: string;
  }): Promise<{ customers: Customer[]; total: number }>;

  /** Get all saved addresses for a customer */
  listAddresses(customerId: string): Promise<CustomerAddress[]>;

  /** Get a single address by ID */
  getAddress(id: string): Promise<CustomerAddress | null>;

  /** Add an address to a customer's account */
  createAddress(params: {
    customerId: string;
    type?: "billing" | "shipping";
    firstName: string;
    lastName: string;
    company?: string;
    line1: string;
    line2?: string;
    city: string;
    state: string;
    postalCode: string;
    country: string;           // ISO 3166-1 alpha-2 (e.g. "US")
    phone?: string;
    isDefault?: boolean;
  }): Promise<CustomerAddress>;

  /** Update fields on an existing address */
  updateAddress(
    id: string,
    params: {
      type?: "billing" | "shipping";
      firstName?: string;
      lastName?: string;
      company?: string | null;
      line1?: string;
      line2?: string | null;
      city?: string;
      state?: string;
      postalCode?: string;
      country?: string;
      phone?: string | null;
      isDefault?: boolean;
    },
  ): Promise<CustomerAddress | null>;

  /** Remove an address */
  deleteAddress(id: string): Promise<void>;

  /**
   * Mark an address as default for its type.
   * Automatically clears the previous default of the same type.
   */
  setDefaultAddress(
    customerId: string,
    addressId: string,
  ): Promise<CustomerAddress | null>;
}

Types

interface Customer {
  id: string;
  email: string;
  firstName: string;
  lastName: string;
  phone?: string;
  dateOfBirth?: Date;
  metadata?: Record<string, unknown>;
  createdAt: Date;
  updatedAt: Date;
}

interface CustomerAddress {
  id: string;
  customerId: string;
  type: "billing" | "shipping";
  firstName: string;
  lastName: string;
  company?: string;
  line1: string;
  line2?: string;
  city: string;
  state: string;
  postalCode: string;
  country: string;             // ISO 3166-1 alpha-2
  phone?: string;
  isDefault: boolean;
  createdAt: Date;
  updatedAt: Date;
}

Store Components

AccountProfile

Displays the authenticated customer's profile (name, email, phone) with inline editing support for updating personal information.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<AccountProfile />

Use this component on a customer account or profile settings page.

AddressBook

Manages the authenticated customer's saved addresses with full CRUD support for creating, editing, and deleting billing and shipping addresses.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<AddressBook />

Use this component on a customer account page to let users manage their saved addresses.

LoyaltyCard

Displays the authenticated customer's loyalty points balance, tier, and transaction history.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<LoyaltyCard />

Use this component on a customer account or rewards page to show loyalty program status and point history.

Notes

  • Store endpoints resolve the customer ID from the active session (ctx.context.session?.user.id). Unauthenticated requests are rejected.
  • Address ownership is verified before any update or delete operation โ€” customers cannot modify each other's addresses.
  • setDefaultAddress is idempotent: calling it on an already-default address is a no-op.
  • Each customer can have one default billing address and one default shipping address independently.