{"_id":"@dullaz/commerce","_rev":"2-6753bbcc5e3a41d065b3407b5b78df18","name":"@dullaz/commerce","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@dullaz/commerce","version":"0.1.0","keywords":["emdash","emdash-plugin","ecommerce","commerce","astro","cms","cart","checkout","orders"],"author":{"name":"Abdullah Hasan","email":"dev@dullaz.com"},"license":"MIT","_id":"@dullaz/commerce@0.1.0","maintainers":[{"name":"dullaz","email":"dev@dullaz.com"}],"homepage":"https://github.com/Dullaz/emdash-commerce#readme","bugs":{"url":"https://github.com/Dullaz/emdash-commerce/issues"},"dist":{"shasum":"c5c53e6c6d820ea2bf1f82b62345fd515121a44f","tarball":"https://registry.npmjs.org/@dullaz/commerce/-/commerce-0.1.0.tgz","fileCount":29,"integrity":"sha512-UxrIqY1GLe3+TzR9MjncYwj4SNj7XbVEjAcxaB/D/RFmjnAT4pTAs58OxmwjwJnwSG40psz2HJZc1l1vV+tVZw==","signatures":[{"sig":"MEUCIQC3gQ+bQ3N8cCiHUBdHTw35n15i/osZIOBm46ggmTSHyQIgepJZwAGf+qLY6k5EEUVrl/Zabz/ynjPB0so1xlMMJd0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":145938},"type":"module","exports":{".":"./src/index.ts","./admin":"./src/admin.tsx","./shared":"./src/constants.ts"},"gitHead":"bad3f0ccc10efec6fff6a49cb3ade97e4569f57b","scripts":{"test":"bun test","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"dullaz","email":"dev@dullaz.com"},"repository":{"url":"git+https://github.com/Dullaz/emdash-commerce.git","type":"git"},"_npmVersion":"10.9.2","description":"Ecommerce for EmDash: products, inventory, orders, checkout, and a pluggable payment-provider abstraction.","directories":{},"_nodeVersion":"22.17.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"astro":"^6.3.0","react":"^19.2.0","emdash":"^0.18.0","react-dom":"^19.2.0","typescript":"^5.6.0","@types/node":"^22.0.0","@emdash-cms/admin":"^0.18.0"},"peerDependencies":{"react":"^19.0.0","emdash":"^0.18.0","react-dom":"^19.0.0","@emdash-cms/admin":"^0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/commerce_0.1.0_1782221619843_0.629621328784681","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@dullaz/commerce","version":"0.1.1","type":"module","description":"Ecommerce for EmDash: products, inventory, orders, checkout, and a pluggable payment-provider abstraction.","author":{"name":"Abdullah Hasan","email":"dev@dullaz.com"},"license":"MIT","homepage":"https://github.com/Dullaz/emdash-commerce#readme","repository":{"type":"git","url":"git+https://github.com/Dullaz/emdash-commerce.git"},"bugs":{"url":"https://github.com/Dullaz/emdash-commerce/issues"},"keywords":["emdash","emdash-plugin","ecommerce","commerce","astro","cms","cart","checkout","orders"],"exports":{".":"./src/index.ts","./admin":"./src/admin.tsx","./shared":"./src/constants.ts"},"publishConfig":{"access":"public"},"scripts":{"test":"bun test","typecheck":"tsc -p tsconfig.json --noEmit"},"peerDependencies":{"@emdash-cms/admin":"^0.18.0","emdash":"^0.18.0","react":"^19.0.0","react-dom":"^19.0.0"},"devDependencies":{"@emdash-cms/admin":"^0.18.0","@types/node":"^22.0.0","astro":"^6.3.0","emdash":"^0.18.0","react":"^19.2.0","react-dom":"^19.2.0","typescript":"^5.6.0"},"gitHead":"e99224d031d93180cc4b11b589bbed37e370372f","_id":"@dullaz/commerce@0.1.1","_nodeVersion":"22.22.3","_npmVersion":"11.17.0","dist":{"integrity":"sha512-TubZScvnL0GYAssWtOYRCXDA0Omyw/nPwdkNvJjO4hoMkGr+H/Y1OGwTLYxTe08AUcP4VBqsTX5+5MTWset9RQ==","shasum":"f77d7432ed65e12d56990d6f37c97ea2f2f15b1f","tarball":"https://registry.npmjs.org/@dullaz/commerce/-/commerce-0.1.1.tgz","fileCount":29,"unpackedSize":145938,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@dullaz%2fcommerce@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDTbEGImufcx1m9TK5Jyr/LvtYFXJfpNLz9JeqaUgt5QQIhAIIyu27VT7exV5JXfBPkKR41znQyktFE2gUIsZSrY1Q2"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:1c207d54-6515-45bc-909c-12055490d301"}},"directories":{},"maintainers":[{"name":"dullaz","email":"dev@dullaz.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/commerce_0.1.1_1782228372397_0.18425130305220372"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-23T13:33:39.611Z","modified":"2026-06-23T15:26:12.816Z","0.1.0":"2026-06-23T13:33:39.992Z","0.1.1":"2026-06-23T15:26:12.546Z"},"bugs":{"url":"https://github.com/Dullaz/emdash-commerce/issues"},"author":{"name":"Abdullah Hasan","email":"dev@dullaz.com"},"license":"MIT","homepage":"https://github.com/Dullaz/emdash-commerce#readme","keywords":["emdash","emdash-plugin","ecommerce","commerce","astro","cms","cart","checkout","orders"],"repository":{"type":"git","url":"git+https://github.com/Dullaz/emdash-commerce.git"},"description":"Ecommerce for EmDash: products, inventory, orders, checkout, and a pluggable payment-provider abstraction.","maintainers":[{"name":"dullaz","email":"dev@dullaz.com"}],"readme":"# @dullaz/commerce\n\nEcommerce for EmDash: products, inventory, orders, checkout, and a pluggable\npayment-provider abstraction. Native-format plugin (runs in-process; ships a\nReact admin UI).\n\n## What it does\n\n- **Products** are a normal EmDash **content collection** (so you get the full\n  CMS editor, images, drafts, SEO, search). The plugin is *configured* to point\n  at a collection — it does not own product schema.\n- **Orders, inventory, carts, payments** live in the plugin's own storage.\n- **Payments** go through a `PaymentProvider` interface. A working **mock**\n  provider ships for development; **rootline** (staging) is scaffolded behind the\n  same interface.\n\nEmDash plugins cannot create or alter content-collection schema from their\nruntime context (no `schema:write` capability). The setup panel works around\nthis by calling the official admin schema API **as the logged-in admin**.\n\n## Install\n\n```js\n// astro.config.mjs\nimport { commercePlugin } from \"@dullaz/commerce\";\n\nexport default defineConfig({\n  integrations: [\n    emdash({\n      database: d1({ binding: \"DB\" }),\n      storage: r2({ binding: \"MEDIA\" }),\n      plugins: [commercePlugin({ defaultCurrency: \"USD\" })],\n    }),\n  ],\n});\n```\n\n## Store setup (admin)\n\nOpen **Store setup** in the admin (`/_emdash/admin/plugins/dullaz-commerce/setup`):\n\n- **Create a new collection** — provisions a `products` collection with all\n  required fields, or\n- **Use an existing collection** — pick one, validate the required fields, and\n  one-click **add any missing fields**.\n\nThe chosen collection slug + field mapping are saved to plugin KV. If nothing is\nconfigured, the store falls back to a collection named `products`.\n\n### Required product fields\n\n| Role          | Default slug  | Type           | Notes                                   |\n| ------------- | ------------- | -------------- | --------------------------------------- |\n| title         | `title`       | string         | required                                |\n| price         | `price`       | integer        | required — **minor units** (2500 = $25) |\n| currency      | `currency`    | string         | ISO-4217; falls back to store default   |\n| sku           | `sku`         | string         |                                         |\n| image         | `image`       | image          |                                         |\n| description   | `description` | portableText   |                                         |\n| active        | `active`      | boolean        | `false` hides from the store            |\n\n## Payments\n\nSet the provider under the plugin's **settings** (auto-generated form):\n\n- `provider` — `mock` (default) or `rootline`\n- `rootlineBaseUrl`, `rootlineApiKey`, `rootlineWebhookSecret` — rootline staging\n  credentials (stored encrypted)\n\n### Adding a provider\n\nImplement `PaymentProvider` (`src/payments/provider.ts`) and register it in\n`src/payments/index.ts`:\n\n```ts\nexport interface PaymentProvider {\n  id: string;\n  label: string;\n  createCheckout(args): Promise<{ checkoutId: string; redirectUrl: string }>;\n  handleWebhook(args): Promise<{ orderId: string; outcome: \"paid\" | \"failed\" | \"cancelled\"; providerPaymentId?: string }>;\n  refund(args): Promise<{ refunded: boolean; providerRefundId?: string }>;\n}\n```\n\n`createCheckout` returns where to send the buyer; `handleWebhook` maps the\nprovider's callback to an order outcome (the order id travels as the provider\n`reference`); `refund` reverses a captured payment. Read credentials from plugin\nsettings via `getPluginSetting()` — never hardcode secrets.\n\n> **rootline** endpoints/auth/webhook signature are provisional (see\n> `src/payments/rootline.ts` TODOs) and finalised once staging details land.\n> Until configured, rootline fails fast with a clear \"not configured\" error.\n\n## Email\n\nThis plugin is an email **consumer** — it builds messages (order confirmations,\nmagic links, verification, reset; see `src/email/templates.ts`) and sends them\nvia `ctx.email.send()`. **Delivery is handled by a separate transport plugin**\n(`@dullaz/email`), which you configure and activate\nunder the admin's **Settings → Email**. Commerce only declares the `email:send`\ncapability and doesn't know or care which provider delivers.\n\nOrder-confirmation sends are best-effort: if no transport is active (or it\nerrors), checkout still completes.\n\n## Order lifecycle\n\n```\npending → awaiting_payment → paid → fulfilled\n                 │             └→ refunded\n                 ├→ cancelled\n                 └→ expired\n```\n\nStock is **reserved** at checkout, **committed** (decremented) on payment, and\n**released** on cancel/expiry. Untracked products sell without limit; enable\ntracking per product on the **Inventory** admin page.\n\n## Order history, accounts & refund requests\n\nEmail is **required** at checkout and stored (normalized, indexed) on the order.\n\n- **Guest lookup** — `/orders/lookup` finds an order by its code + matching\n  email (both required so a code alone never reveals an order).\n- **Accounts** — customers sign in with a password **or** a passwordless\n  magic link, and see all orders for their email at `/account`. Email\n  verification and password reset are emailed (need the email transport).\n  Sessions are an httpOnly cookie backed by `customer_sessions`; passwords are\n  PBKDF2 (`src/auth.ts`).\n- **Refund requests** — a customer flags an order from its detail view; the\n  admin sees a \"refund requested\" badge on the Orders page and approves with\n  the existing refund action.\n\nIdentity is the **email**; magic-link sign-in creates the account on first use.\n\n## API routes\n\nMounted at `/_emdash/api/plugins/dullaz-commerce/<route>`.\n\n| Route            | Method | Auth   | Purpose                          |\n| ---------------- | ------ | ------ | -------------------------------- |\n| `availability`   | GET    | public | Live stock for product ids       |\n| `cart`           | GET    | public | Read cart by `?token=`           |\n| `cart/add`       | POST   | public | Add a product                    |\n| `cart/set`       | POST   | public | Set/remove a line quantity       |\n| `cart/clear`     | POST   | public | Empty the cart                   |\n| `checkout`       | POST   | public | Reserve + start provider checkout |\n| `webhook`        | POST   | public | Provider callback → order outcome |\n| `order`          | GET    | public | Sanitised order (success page)   |\n| `orders/lookup`  | POST   | public | Guest lookup by code + email     |\n| `orders/request-refund` | POST | public | Flag a refund request         |\n| `account/register` | POST | public | Create a password account        |\n| `account/login`  | POST   | public | Password sign-in                 |\n| `account/logout` | POST   | public | End the session                  |\n| `account/me`     | GET    | public | Session's customer + orders      |\n| `account/magic`  | POST   | public | Email a sign-in link             |\n| `account/consume`| POST   | public | Consume a magic/verify token     |\n| `account/reset-request` | POST | public | Email a reset link            |\n| `account/reset`  | POST   | public | Set a new password via token     |\n| `config`         | GET    | admin  | Effective store config           |\n| `config/save`    | POST   | admin  | Save collection + field map      |\n| `orders`         | GET    | admin  | List orders                      |\n| `orders/refund`  | POST   | admin  | Refund + restock                 |\n| `orders/fulfill` | POST   | admin  | Mark fulfilled                   |\n| `inventory`      | GET    | admin  | Products joined with stock       |\n| `inventory/set`  | POST   | admin  | Set tracking + on-hand           |\n| `stats`          | GET    | admin  | Dashboard metrics                |\n\n## Development\n\n```bash\nbun test                            # domain + provider unit tests\nbunx tsc -p tsconfig.json --noEmit\n```\n\nMoney is always integer minor units. Domain logic (`src/domain.ts`) is pure and\nunit-tested; storage binding is in `src/store.ts`.\n","readmeFilename":"README.md"}