@stacksjs/commerce 0.75.89 โ 0.75.90
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/README.md +22 -0
- package/dist/catalog.d.ts +43 -0
- package/dist/catalog.js +2 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +5 -5
- package/dist/register.d.ts +56 -0
- package/dist/register.js +2 -0
- package/dist/releases.d.ts +48 -0
- package/dist/releases.js +2 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -26,6 +26,28 @@ import * as commerce from '@stacksjs/commerce'
|
|
|
26
26
|
// wip
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
### Shop rules in the browser
|
|
30
|
+
|
|
31
|
+
Four modules are pure and import nothing, so a page bundles them on its own
|
|
32
|
+
instead of the barrel (which imports the database):
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { formatCurrency, parseMoneyInput } from '@stacksjs/commerce/money'
|
|
36
|
+
import { addToBasket, basketTotal, stockLabel, CENTS_FIELDS } from '@stacksjs/commerce/register'
|
|
37
|
+
import { compareCatalog, matchesSearch, isLowStock } from '@stacksjs/commerce/catalog'
|
|
38
|
+
import { releaseSchedule, rolloutFromProduct, describeRollout } from '@stacksjs/commerce/releases'
|
|
39
|
+
|
|
40
|
+
// A front desk's basket, held to the stock on the shelf
|
|
41
|
+
let basket = addToBasket([], gatorade, CENTS_FIELDS)
|
|
42
|
+
basketTotal(basket, catalog, CENTS_FIELDS)
|
|
43
|
+
|
|
44
|
+
// A catalog by category, then name, sizes small to large
|
|
45
|
+
products.sort(compareCatalog(['Drinks', 'Apparel']))
|
|
46
|
+
|
|
47
|
+
// When each video or week of a digital product opens for a buyer
|
|
48
|
+
releaseSchedule(rolloutFromProduct(product), weeks, purchasedAt, new Date())
|
|
49
|
+
```
|
|
50
|
+
|
|
29
51
|
Learn more in the docs.
|
|
30
52
|
|
|
31
53
|
## ๐งช Testing
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A name's trailing size split off and ranked: `"Logo Tee โ M"` is the base
|
|
3
|
+
* `"Logo Tee"` at rank 3. A dash, en dash, em dash or slash may separate it.
|
|
4
|
+
* A name with no size has rank -1.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sizeOf(name: string): { base: string, size: string | null, rank: number };
|
|
7
|
+
/**
|
|
8
|
+
* Where a category sits in a chosen order. Named ones come in that order, any
|
|
9
|
+
* other after them, and none at all last.
|
|
10
|
+
*/
|
|
11
|
+
export declare function categoryRank(category: string | null | undefined, order?: readonly string[]): number;
|
|
12
|
+
/**
|
|
13
|
+
* A comparator for a catalog: by category in `order` (then alphabetically),
|
|
14
|
+
* then by name, with sizes of the same garment small to large.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* products.sort(compareCatalog(['Drinks', 'Apparel']))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function compareCatalog(order?: readonly string[]): (a: Orderable, b: Orderable) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Whether something matches a search: every word of the query somewhere in
|
|
23
|
+
* the given fields, ignoring case. An empty query matches everything.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* matchesSearch([product.name, product.sku, product.category], 'gat lemon')
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function matchesSearch(fields: unknown[], query: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether counted stock is at or under the level to reorder at (`defaultLow`
|
|
32
|
+
* when the product sets none). Uncounted stock is never low.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isLowStock(stock: number | null | undefined, reorderAt?: number | null, defaultLow?: number): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* How a catalog is shown: its order (by category, then name, with a
|
|
37
|
+
* garment's sizes small to large), its search, and when stock is low. Pure
|
|
38
|
+
* and dependency-free, so the browser bundles it
|
|
39
|
+
* (`@stacksjs/commerce/catalog`) and a server sorts the same way.
|
|
40
|
+
*/
|
|
41
|
+
/** Garment sizes, smallest first. */
|
|
42
|
+
export declare const SIZES: readonly ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', '2XL', '3XL', '4XL'];
|
|
43
|
+
export declare interface Orderable { name?: string | null, category?: string | null }
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var u=Object.defineProperty;var g=(e)=>e;function c(e,n){this[e]=g.bind(null,n)}var f=(e,n)=>{for(var r in n)u(e,r,{get:n[r],enumerable:!0,configurable:!0,set:c.bind(n,r)})};var L=(e,n,r)=>()=>{if(e)try{n=e(e=0)}catch(t){r=[t]}if(r)throw r[0];return n};var m={};f(m,{SIZES:()=>l,categoryRank:()=>o,compareCatalog:()=>S,isLowStock:()=>b,matchesSearch:()=>X,sizeOf:()=>a});var l=["XXS","XS","S","M","L","XL","XXL","2XL","3XL","4XL"];function a(e){let n=/^(.*?)\s*[\u2014\u2013\-/]\s*(XXS|XS|S|M|L|XL|XXL|2XL|3XL|4XL)$/i.exec(String(e).trim());if(!n)return{base:String(e).trim(),size:null,rank:-1};let r=n[2].toUpperCase();return{base:n[1],size:r,rank:l.indexOf(r)}}function o(e,n=[]){let r=n.indexOf(String(e||""));if(r!==-1)return r;return e?n.length:n.length+1}function S(e=[]){return(n,r)=>{let t=o(n.category,e)-o(r.category,e)||String(n.category||"").localeCompare(String(r.category||""));if(t)return t;let i=a(String(n.name||"")),s=a(String(r.name||""));return i.base.localeCompare(s.base)||i.rank-s.rank}}function X(e,n){let r=String(n||"").toLowerCase().split(/\s+/).filter(Boolean);if(!r.length)return!0;let t=e.map((i)=>String(i??"")).join(" ").toLowerCase();return r.every((i)=>t.includes(i))}function b(e,n,r=5){if(e===null||e===void 0)return!1;return Number(e)<=(n===null||n===void 0?r:Number(n))}export{l as SIZES,o as categoryRank,S as compareCatalog,b as isLowStock,X as matchesSearch,a as sizeOf};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as auctions from './auctions/index';
|
|
2
2
|
import * as carts from './carts/index';
|
|
3
|
+
import * as catalog from './catalog';
|
|
3
4
|
import * as catalogImport from './imports/index';
|
|
4
5
|
import * as coupons from './coupons/index';
|
|
5
6
|
import * as customers from './customers/index';
|
|
@@ -11,6 +12,8 @@ import * as orders from './orders/index';
|
|
|
11
12
|
import * as payments from './payments/index';
|
|
12
13
|
import * as products from './products/index';
|
|
13
14
|
import * as receipts from './receipts/index';
|
|
15
|
+
import * as register from './register';
|
|
16
|
+
import * as releases from './releases';
|
|
14
17
|
import * as restaurant from './waitlists/restaurant/index';
|
|
15
18
|
import * as shippings from './shippings/index';
|
|
16
19
|
import * as tax from './tax/index';
|
|
@@ -20,6 +23,7 @@ export declare const commerce: CommerceNamespace;
|
|
|
20
23
|
export declare interface CommerceNamespace {
|
|
21
24
|
auctions: AuctionsModule
|
|
22
25
|
carts: CartsModule
|
|
26
|
+
catalog: CatalogModule
|
|
23
27
|
coupons: CouponsModule
|
|
24
28
|
customers: CustomersModule
|
|
25
29
|
errors: ErrorsModule
|
|
@@ -27,6 +31,8 @@ export declare interface CommerceNamespace {
|
|
|
27
31
|
orders: OrdersModule
|
|
28
32
|
payments: PaymentsModule
|
|
29
33
|
products: ProductsModule
|
|
34
|
+
register: RegisterModule
|
|
35
|
+
releases: ReleasesModule
|
|
30
36
|
restaurant: RestaurantModule
|
|
31
37
|
shippings: ShippingsModule
|
|
32
38
|
tax: TaxModule
|
|
@@ -36,6 +42,9 @@ export declare interface CommerceNamespace {
|
|
|
36
42
|
}
|
|
37
43
|
declare type AuctionsModule = typeof auctions;
|
|
38
44
|
declare type CartsModule = typeof carts;
|
|
45
|
+
declare type CatalogModule = typeof catalog;
|
|
46
|
+
declare type RegisterModule = typeof register;
|
|
47
|
+
declare type ReleasesModule = typeof releases;
|
|
39
48
|
declare type CouponsModule = typeof coupons;
|
|
40
49
|
declare type CustomersModule = typeof customers;
|
|
41
50
|
declare type ErrorsModule = typeof errors;
|
|
@@ -54,6 +63,7 @@ declare type ReceiptsModule = typeof receipts;
|
|
|
54
63
|
export {
|
|
55
64
|
auctions,
|
|
56
65
|
carts,
|
|
66
|
+
catalog,
|
|
57
67
|
catalogImport,
|
|
58
68
|
coupons,
|
|
59
69
|
customers,
|
|
@@ -65,6 +75,8 @@ export {
|
|
|
65
75
|
payments,
|
|
66
76
|
products,
|
|
67
77
|
receipts,
|
|
78
|
+
register,
|
|
79
|
+
releases,
|
|
68
80
|
restaurant,
|
|
69
81
|
shippings,
|
|
70
82
|
tax,
|