@stacksjs/commerce 0.75.105 → 0.75.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/dist/orders/index.d.ts +2 -0
- package/dist/orders/transition.d.ts +8 -0
- package/dist/orders/update.d.ts +3 -0
- package/dist/refund-allocation.d.ts +4 -0
- package/dist/refund-allocation.js +2 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.js +1 -1
- package/dist/tsconfig.json +5 -0
- package/package.json +12 -12
package/dist/orders/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { PlaceOrderInput, PlaceOrderLineItem, PlaceOrderResult } from './place-order';
|
|
2
|
+
export type { OrderTransitionOptions } from './transition';
|
|
2
3
|
export type { OrderStatus } from './events';
|
|
3
4
|
export type {
|
|
4
5
|
RecomputeLineItem,
|
|
@@ -39,6 +40,7 @@ export {
|
|
|
39
40
|
// Wraps order + lines + payment + inventory + idempotency in a
|
|
40
41
|
// single transaction so any failure rolls back the rest.
|
|
41
42
|
export { findOrderByIdempotencyKey, placeOrder } from './place-order';
|
|
43
|
+
export { transitionStatus } from './transition';
|
|
42
44
|
// Event bus integration + status-transition state machine
|
|
43
45
|
// (stacksjs/stacks#1879 Co-18, Co-4). Emit helpers fire
|
|
44
46
|
// order:created / order:paid / order:shipped / order:delivered /
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database/runtime';
|
|
2
|
+
import type { OrderStatus } from './events';
|
|
3
|
+
/** A conditional status change and its delivery share one commit and one event. */
|
|
4
|
+
export declare function transitionStatus(id: number, from: OrderStatus, to: OrderStatus, options?: OrderTransitionOptions): Promise<boolean>;
|
|
5
|
+
export declare interface OrderTransitionOptions {
|
|
6
|
+
values?: Record<string, unknown>
|
|
7
|
+
apply?: (transaction: Parameters<Parameters<typeof db.transaction>[0]>[0], order: Record<string, unknown>) => Promise<void>
|
|
8
|
+
}
|
package/dist/orders/update.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transitionStatus } from './transition';
|
|
1
2
|
import type { ModelRow, Order, UpdateModelData } from '@stacksjs/orm';
|
|
2
3
|
import type { OrderStatus } from './events';
|
|
3
4
|
/**
|
|
@@ -25,5 +26,7 @@ export declare function updateStatus(id: number, status: OrderStatus): Promise<O
|
|
|
25
26
|
* @returns The updated order
|
|
26
27
|
*/
|
|
27
28
|
export declare function updateDeliveryInfo(id: number, delivery_address?: string, estimated_delivery_time?: string): Promise<OrderJsonResponse | undefined>;
|
|
29
|
+
// Import dependencies
|
|
28
30
|
declare type OrderJsonResponse = ModelRow<typeof Order>;
|
|
29
31
|
declare type OrderUpdate = UpdateModelData<typeof Order>;
|
|
32
|
+
export { transitionStatus } from './transition';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Allocate a requested refund against its original cash and account-credit tenders. */
|
|
2
|
+
export declare function allocateRefund(amount: number, cashRemaining: number, creditRemaining: number): { cash: number, credit: number };
|
|
3
|
+
/** Difference of cumulative rounded tax keeps split refunds equal to a full refund. */
|
|
4
|
+
export declare function refundTaxDelta(before: number, amount: number, total: number, tax: number): number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function d(r,n,e){if(![r,n,e].every((b)=>Number.isSafeInteger(b)&&b>=0)||r<1||r>n+e)throw Error("Refund amount exceeds remaining refundable amount");let u=Math.min(r,n);return{cash:u,credit:r-u}}function f(r,n,e,u){if(![r,n,e,u].every((b)=>Number.isSafeInteger(b)&&b>=0)||r+n>e)throw Error("Invalid refund tax amounts");if(e===0)return 0;return Math.round((r+n)*u/e)-Math.round(r*u/e)}export{d as allocateRefund,f as refundTaxDelta};
|
package/dist/register.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Combine repeated products into one validated line before checking or writing stock. */
|
|
2
|
+
export declare function normalizeBasket(basket: readonly BasketLine[]): BasketLine[];
|
|
1
3
|
/** Units still on the shelf once the basket is taken off it; null when stock is not counted. */
|
|
2
4
|
export declare function shelfLeft(product: Product, basket: BasketLine[], fields?: RegisterFields): number | null;
|
|
3
5
|
/** Whether one more can be rung up. */
|
package/dist/register.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var g=Object.defineProperty;var k=(t)=>t;function x(t,r){this[t]=k.bind(null,r)}var b=(t,r)=>{for(var e in r)g(t,e,{get:r[e],enumerable:!0,configurable:!0,set:x.bind(r,e)})};var R=(t,r,e)=>()=>{if(t)try{r=t(t=0)}catch(n){e=[n]}if(e)throw e[0];return r};var q={};b(q,{CENTS_FIELDS:()=>y,DEFAULT_FIELDS:()=>u,addToBasket:()=>L,basketCount:()=>w,basketLines:()=>p,basketTaxable:()=>F,basketTotal:()=>I,canAdd:()=>m,groupsOf:()=>h,normalizeBasket:()=>d,setQuantity:()=>B,shelfLeft:()=>l,stockLabel:()=>S});var u={id:"id",price:"price",inventory:"inventory",lowStock:"low_stock_threshold",taxable:"taxable"},y={id:"id",price:"price_cents",inventory:"inventory_quantity",lowStock:"low_stock_threshold",taxable:"taxable"};function a(t,r){return Number(t[r.id])}function f(t,r){let e=t[r.inventory];return e===null||e===void 0||e===""?null:Number(e)}function d(t){let r=new Map;for(let{productId:e,quantity:n}of t){if(!Number.isSafeInteger(e)||e<1||!Number.isSafeInteger(n)||n<1)throw Error("Basket products and quantities must be positive safe integers");let o=(r.get(e)||0)+n;if(!Number.isSafeInteger(o))throw Error("Basket quantity exceeds the safe integer range");r.set(e,o)}return[...r].map(([e,n])=>({productId:e,quantity:n}))}function l(t,r,e=u){let n=f(t,e);if(n===null)return null;let o=r.filter((i)=>i.productId===a(t,e)).reduce((i,c)=>i+c.quantity,0);return Math.max(0,n-o)}function m(t,r,e=u){let n=l(t,r,e);return n===null||n>0}function L(t,r,e=u){let n=d(t);if(!m(r,n,e))return t;t=n;let o=a(r,e);return t.some((i)=>i.productId===o)?t.map((i)=>i.productId===o?{...i,quantity:i.quantity+1}:i):[...t,{productId:o,quantity:1}]}function B(t,r,e,n=u){let o=a(r,n),i=f(r,n);t=d(t);let c=Math.min(Math.max(0,Math.floor(Number(e)||0)),i===null?Number.POSITIVE_INFINITY:i);if(c===0)return t.filter((s)=>s.productId!==o);return t.some((s)=>s.productId===o)?t.map((s)=>s.productId===o?{...s,quantity:c}:s):[...t,{productId:o,quantity:c}]}function p(t,r,e=u){return d(t).map((n)=>({...n,product:r.find((o)=>a(o,e)===n.productId)})).filter((n)=>!!n.product)}function I(t,r,e=u){return p(t,r,e).reduce((n,o)=>n+Number(o.product[e.price]||0)*o.quantity,0)}function F(t,r,e=u){return p(t,r,e).filter((n)=>n.product[e.taxable]!==!1).reduce((n,o)=>n+Number(o.product[e.price]||0)*o.quantity,0)}function w(t){return t.reduce((r,e)=>r+e.quantity,0)}function S(t,r=[],e=u,n=5){let o=l(t,r,e);if(o===null)return null;if(o===0)return{text:"Sold out",tone:"out"};let i=t[e.lowStock]===null||t[e.lowStock]===void 0?n:Number(t[e.lowStock]);return{text:`${o} left`,tone:o<=i?"low":"ok"}}function h(t,r){let e=[];for(let n of t){let o=r(n);if(!e.includes(o))e.push(o)}return e}export{y as CENTS_FIELDS,u as DEFAULT_FIELDS,L as addToBasket,w as basketCount,p as basketLines,F as basketTaxable,I as basketTotal,m as canAdd,h as groupsOf,d as normalizeBasket,B as setQuantity,l as shelfLeft,S as stockLabel};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/commerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.75.
|
|
4
|
+
"version": "0.75.107",
|
|
5
5
|
"description": "Stacks commerce utilities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
"prepublishOnly": "bun run build"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@stacksjs/cache": "0.75.
|
|
61
|
-
"@stacksjs/config": "0.75.
|
|
62
|
-
"@stacksjs/database": "0.75.
|
|
63
|
-
"@stacksjs/env": "0.75.
|
|
64
|
-
"@stacksjs/error-handling": "0.75.
|
|
65
|
-
"@stacksjs/events": "0.75.
|
|
66
|
-
"@stacksjs/logging": "0.75.
|
|
67
|
-
"@stacksjs/orm": "0.75.
|
|
68
|
-
"@stacksjs/payments": "0.75.
|
|
69
|
-
"@stacksjs/realtime": "0.75.
|
|
70
|
-
"@stacksjs/strings": "0.75.
|
|
60
|
+
"@stacksjs/cache": "0.75.107",
|
|
61
|
+
"@stacksjs/config": "0.75.107",
|
|
62
|
+
"@stacksjs/database": "0.75.107",
|
|
63
|
+
"@stacksjs/env": "0.75.107",
|
|
64
|
+
"@stacksjs/error-handling": "0.75.107",
|
|
65
|
+
"@stacksjs/events": "0.75.107",
|
|
66
|
+
"@stacksjs/logging": "0.75.107",
|
|
67
|
+
"@stacksjs/orm": "0.75.107",
|
|
68
|
+
"@stacksjs/payments": "0.75.107",
|
|
69
|
+
"@stacksjs/realtime": "0.75.107",
|
|
70
|
+
"@stacksjs/strings": "0.75.107",
|
|
71
71
|
"ts-spreadsheets": "^0.2.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|