@stacksjs/commerce 0.70.54 → 0.70.55
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/package.json +3 -2
- package/src/carts/destroy.ts +54 -0
- package/src/carts/fetch.ts +20 -0
- package/src/carts/index.ts +13 -0
- package/src/carts/store.ts +75 -0
- package/src/carts/update.ts +78 -0
- package/src/coupons/destroy.ts +49 -0
- package/src/coupons/fetch.ts +510 -0
- package/src/coupons/index.ts +30 -0
- package/src/coupons/store.ts +46 -0
- package/src/coupons/update.ts +147 -0
- package/src/customers/destroy.ts +62 -0
- package/src/customers/fetch.ts +20 -0
- package/src/customers/index.ts +17 -0
- package/src/customers/store.ts +45 -0
- package/src/customers/update.ts +44 -0
- package/src/devices/destroy.ts +54 -0
- package/src/devices/export.ts +98 -0
- package/src/devices/fetch.ts +125 -0
- package/src/devices/index.ts +31 -0
- package/src/devices/store.ts +82 -0
- package/src/devices/update.ts +125 -0
- package/src/errors/destroy.ts +54 -0
- package/src/errors/fetch.ts +197 -0
- package/src/errors/index.ts +28 -0
- package/src/errors/update.ts +116 -0
- package/src/gift-cards/destroy.ts +87 -0
- package/src/gift-cards/fetch.ts +431 -0
- package/src/gift-cards/index.ts +26 -0
- package/src/gift-cards/store.ts +56 -0
- package/src/gift-cards/update.ts +102 -0
- package/src/index.ts +78 -0
- package/src/orders/destroy.ts +111 -0
- package/src/orders/events.ts +121 -0
- package/src/orders/export.ts +158 -0
- package/src/orders/fetch.ts +379 -0
- package/src/orders/guards.ts +261 -0
- package/src/orders/index.ts +91 -0
- package/src/orders/place-order.ts +274 -0
- package/src/orders/store.ts +51 -0
- package/src/orders/totals.ts +190 -0
- package/src/orders/update.ts +164 -0
- package/src/orders/webhook.ts +312 -0
- package/src/payments/destroy.ts +56 -0
- package/src/payments/fetch.ts +288 -0
- package/src/payments/index.ts +16 -0
- package/src/payments/store.ts +63 -0
- package/src/payments/update.ts +52 -0
- package/src/product.ts +0 -0
- package/src/products/categories/destroy.ts +103 -0
- package/src/products/categories/fetch.ts +285 -0
- package/src/products/categories/index.ts +36 -0
- package/src/products/categories/store.ts +87 -0
- package/src/products/categories/update.ts +251 -0
- package/src/products/index.ts +35 -0
- package/src/products/items/destroy.ts +54 -0
- package/src/products/items/fetch.ts +282 -0
- package/src/products/items/index.ts +26 -0
- package/src/products/items/store.ts +84 -0
- package/src/products/items/update.ts +324 -0
- package/src/products/manufacturers/destroy.ts +56 -0
- package/src/products/manufacturers/fetch.ts +117 -0
- package/src/products/manufacturers/index.ts +24 -0
- package/src/products/manufacturers/store.ts +82 -0
- package/src/products/manufacturers/update.ts +113 -0
- package/src/products/reviews/destroy.ts +56 -0
- package/src/products/reviews/fetch.ts +63 -0
- package/src/products/reviews/index.ts +25 -0
- package/src/products/reviews/store.ts +46 -0
- package/src/products/reviews/update.ts +82 -0
- package/src/products/units/destroy.ts +56 -0
- package/src/products/units/fetch.ts +20 -0
- package/src/products/units/index.ts +13 -0
- package/src/products/units/store.ts +162 -0
- package/src/products/units/update.ts +159 -0
- package/src/products/variants/destroy.ts +56 -0
- package/src/products/variants/fetch.ts +20 -0
- package/src/products/variants/index.ts +21 -0
- package/src/products/variants/store.ts +136 -0
- package/src/products/variants/update.ts +104 -0
- package/src/receipts/destroy.ts +54 -0
- package/src/receipts/export.ts +0 -0
- package/src/receipts/fetch.ts +222 -0
- package/src/receipts/index.ts +24 -0
- package/src/receipts/printer.ts +69 -0
- package/src/receipts/store.ts +69 -0
- package/src/receipts/update.ts +124 -0
- package/src/shippings/delivery-routes/destroy.ts +54 -0
- package/src/shippings/delivery-routes/fetch.ts +42 -0
- package/src/shippings/delivery-routes/index.ts +26 -0
- package/src/shippings/delivery-routes/store.ts +69 -0
- package/src/shippings/delivery-routes/update.ts +120 -0
- package/src/shippings/digital-deliveries/destroy.ts +111 -0
- package/src/shippings/digital-deliveries/fetch.ts +20 -0
- package/src/shippings/digital-deliveries/index.ts +26 -0
- package/src/shippings/digital-deliveries/store.ts +76 -0
- package/src/shippings/digital-deliveries/update.ts +129 -0
- package/src/shippings/drivers/destroy.ts +78 -0
- package/src/shippings/drivers/fetch.ts +20 -0
- package/src/shippings/drivers/index.ts +24 -0
- package/src/shippings/drivers/store.ts +69 -0
- package/src/shippings/drivers/update.ts +117 -0
- package/src/shippings/index.ts +39 -0
- package/src/shippings/license-keys/destroy.ts +111 -0
- package/src/shippings/license-keys/fetch.ts +20 -0
- package/src/shippings/license-keys/index.ts +26 -0
- package/src/shippings/license-keys/store.ts +77 -0
- package/src/shippings/license-keys/update.ts +117 -0
- package/src/shippings/shipping-methods/destroy.ts +111 -0
- package/src/shippings/shipping-methods/fetch.ts +62 -0
- package/src/shippings/shipping-methods/index.ts +28 -0
- package/src/shippings/shipping-methods/store.ts +123 -0
- package/src/shippings/shipping-methods/update.ts +120 -0
- package/src/shippings/shipping-rates/destroy.ts +102 -0
- package/src/shippings/shipping-rates/fetch.ts +320 -0
- package/src/shippings/shipping-rates/index.ts +36 -0
- package/src/shippings/shipping-rates/store.ts +102 -0
- package/src/shippings/shipping-rates/update.ts +139 -0
- package/src/shippings/shipping-zones/destroy.ts +111 -0
- package/src/shippings/shipping-zones/fetch.ts +96 -0
- package/src/shippings/shipping-zones/index.ts +26 -0
- package/src/shippings/shipping-zones/store.ts +74 -0
- package/src/shippings/shipping-zones/update.ts +156 -0
- package/src/tax/destroy.ts +54 -0
- package/src/tax/fetch.ts +20 -0
- package/src/tax/index.ts +24 -0
- package/src/tax/store.ts +69 -0
- package/src/tax/update.ts +119 -0
- package/src/tests/coupons.test.ts +90 -0
- package/src/tests/customers.test.ts +39 -0
- package/src/tests/device.test.ts +111 -0
- package/src/tests/digitals.test.ts +31 -0
- package/src/tests/drivers.test.ts +25 -0
- package/src/tests/gift-cards.test.ts +36 -0
- package/src/tests/license.test.ts +31 -0
- package/src/tests/manufacturers.test.ts +80 -0
- package/src/tests/orders.test.ts +25 -0
- package/src/tests/payments.test.ts +75 -0
- package/src/tests/rates.test.ts +367 -0
- package/src/tests/receipts.test.ts +287 -0
- package/src/tests/restaurant.test.ts +522 -0
- package/src/tests/reviews.test.ts +165 -0
- package/src/tests/routes.test.ts +51 -0
- package/src/tests/setup.ts +149 -0
- package/src/tests/shipping.test.ts +88 -0
- package/src/tests/tax.test.ts +25 -0
- package/src/tests/units.test.ts +110 -0
- package/src/tests/variants.test.ts +133 -0
- package/src/tests/waitlist.test.ts +303 -0
- package/src/tests/zones.test.ts +86 -0
- package/src/types.ts +312 -0
- package/src/utils/typed-stats.ts +67 -0
- package/src/waitlists/index.ts +19 -0
- package/src/waitlists/products/destroy.ts +65 -0
- package/src/waitlists/products/export.ts +113 -0
- package/src/waitlists/products/fetch.ts +362 -0
- package/src/waitlists/products/index.ts +33 -0
- package/src/waitlists/products/store.ts +112 -0
- package/src/waitlists/products/update.ts +125 -0
- package/src/waitlists/restaurant/destroy.ts +65 -0
- package/src/waitlists/restaurant/export.ts +107 -0
- package/src/waitlists/restaurant/fetch.ts +538 -0
- package/src/waitlists/restaurant/index.ts +43 -0
- package/src/waitlists/restaurant/store.ts +109 -0
- package/src/waitlists/restaurant/update.ts +198 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/commerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.55",
|
|
5
5
|
"description": "Stacks commerce utilities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"types": "dist/index.d.ts",
|
|
41
41
|
"files": [
|
|
42
42
|
"README.md",
|
|
43
|
-
"dist"
|
|
43
|
+
"dist",
|
|
44
|
+
"src"
|
|
44
45
|
],
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "bun build.ts",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delete a cart by ID
|
|
5
|
+
*
|
|
6
|
+
* @param id The ID of the cart to delete
|
|
7
|
+
* @returns True if the cart was deleted, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export async function destroy(id: number): Promise<boolean> {
|
|
10
|
+
try {
|
|
11
|
+
const result = await db
|
|
12
|
+
.deleteFrom('carts')
|
|
13
|
+
.where('id', '=', id)
|
|
14
|
+
.executeTakeFirst()
|
|
15
|
+
|
|
16
|
+
return Number(result.numDeletedRows) > 0
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
throw new TypeError(`Failed to delete cart: ${error.message}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Delete multiple carts by ID
|
|
29
|
+
*
|
|
30
|
+
* @param ids Array of cart IDs to delete
|
|
31
|
+
* @returns Number of carts deleted
|
|
32
|
+
*/
|
|
33
|
+
export async function bulkDestroy(ids: number[]): Promise<number> {
|
|
34
|
+
if (!ids.length)
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Perform the delete operation
|
|
39
|
+
const result = await db
|
|
40
|
+
.deleteFrom('carts')
|
|
41
|
+
.where('id', 'in', ids)
|
|
42
|
+
.executeTakeFirst()
|
|
43
|
+
|
|
44
|
+
// Return the number of deleted rows
|
|
45
|
+
return Number(result.numDeletedRows)
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof Error) {
|
|
49
|
+
throw new TypeError(`Failed to delete carts: ${error.message}`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
throw error
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type CartJsonResponse = ModelRow<typeof Cart>
|
|
2
|
+
import { db } from '@stacksjs/database'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetch a cart by ID
|
|
6
|
+
*/
|
|
7
|
+
export async function fetchById(id: number): Promise<CartJsonResponse | undefined> {
|
|
8
|
+
return await db
|
|
9
|
+
.selectFrom('carts')
|
|
10
|
+
.where('id', '=', id)
|
|
11
|
+
.selectAll()
|
|
12
|
+
.executeTakeFirst() as CartJsonResponse | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetch all carts
|
|
17
|
+
*/
|
|
18
|
+
export async function fetchAll(): Promise<CartJsonResponse[]> {
|
|
19
|
+
return await db.selectFrom('carts').selectAll().execute() as CartJsonResponse[]
|
|
20
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
type CartJsonResponse = ModelRow<typeof Cart>
|
|
2
|
+
type NewCart = NewModelData<typeof Cart>
|
|
3
|
+
import { randomUUIDv7 } from 'bun'
|
|
4
|
+
import { db } from '@stacksjs/database'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a new cart
|
|
8
|
+
*
|
|
9
|
+
* @param data Cart data to store
|
|
10
|
+
* @returns The newly created cart record
|
|
11
|
+
*/
|
|
12
|
+
export async function store(data: NewCart): Promise<CartJsonResponse> {
|
|
13
|
+
try {
|
|
14
|
+
const cartData = {
|
|
15
|
+
...data,
|
|
16
|
+
uuid: randomUUIDv7(),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result = await db
|
|
20
|
+
.insertInto('carts')
|
|
21
|
+
.values(cartData as NewCart)
|
|
22
|
+
.returningAll()
|
|
23
|
+
.executeTakeFirst()
|
|
24
|
+
|
|
25
|
+
if (!result)
|
|
26
|
+
throw new Error('Failed to create cart')
|
|
27
|
+
|
|
28
|
+
return result as CartJsonResponse
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error)
|
|
32
|
+
throw new TypeError(`Failed to create cart: ${error.message}`)
|
|
33
|
+
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create multiple carts at once
|
|
40
|
+
*
|
|
41
|
+
* @param data Array of cart data to store
|
|
42
|
+
* @returns Number of carts created
|
|
43
|
+
*/
|
|
44
|
+
export async function bulkStore(data: NewCart[]): Promise<number> {
|
|
45
|
+
if (!data.length)
|
|
46
|
+
return 0
|
|
47
|
+
|
|
48
|
+
let createdCount = 0
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await (db as any).transaction().execute(async (trx: any) => {
|
|
52
|
+
for (const cart of data) {
|
|
53
|
+
const cartData = {
|
|
54
|
+
...cart,
|
|
55
|
+
uuid: randomUUIDv7(),
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await trx
|
|
59
|
+
.insertInto('carts')
|
|
60
|
+
.values(cartData as NewCart)
|
|
61
|
+
.execute()
|
|
62
|
+
|
|
63
|
+
createdCount++
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return createdCount
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof Error)
|
|
71
|
+
throw new TypeError(`Failed to create carts in bulk: ${error.message}`)
|
|
72
|
+
|
|
73
|
+
throw error
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
import { formatDate } from '@stacksjs/orm'
|
|
3
|
+
type CartJsonResponse = ModelRow<typeof Cart>
|
|
4
|
+
type CartUpdate = UpdateModelData<typeof Cart>
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Update a cart
|
|
8
|
+
*
|
|
9
|
+
* @param id The ID of the cart to update
|
|
10
|
+
* @param data The cart data to update
|
|
11
|
+
* @returns The updated cart record
|
|
12
|
+
*/
|
|
13
|
+
export async function update(id: number, data: Omit<CartUpdate, 'id'>): Promise<CartJsonResponse> {
|
|
14
|
+
try {
|
|
15
|
+
const result = await db
|
|
16
|
+
.updateTable('carts')
|
|
17
|
+
.set({
|
|
18
|
+
...data,
|
|
19
|
+
updated_at: formatDate(new Date()),
|
|
20
|
+
})
|
|
21
|
+
.where('id', '=', id)
|
|
22
|
+
.returningAll()
|
|
23
|
+
.executeTakeFirst()
|
|
24
|
+
|
|
25
|
+
if (!result)
|
|
26
|
+
throw new Error('Failed to update cart')
|
|
27
|
+
|
|
28
|
+
return result as CartJsonResponse
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error)
|
|
32
|
+
throw new TypeError(`Failed to update cart: ${error.message}`)
|
|
33
|
+
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Update multiple carts at once
|
|
40
|
+
*
|
|
41
|
+
* @param data Array of objects containing cart ID and update data
|
|
42
|
+
* @returns Number of carts updated
|
|
43
|
+
*/
|
|
44
|
+
export async function bulkUpdate(data: CartUpdate[]): Promise<number> {
|
|
45
|
+
if (!data.length)
|
|
46
|
+
return 0
|
|
47
|
+
|
|
48
|
+
let updatedCount = 0
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await (db as any).transaction().execute(async (trx: any) => {
|
|
52
|
+
for (const cart of data) {
|
|
53
|
+
if (!(cart as Record<string, unknown>).id)
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
const result = await trx
|
|
57
|
+
.updateTable('carts')
|
|
58
|
+
.set({
|
|
59
|
+
...cart,
|
|
60
|
+
updated_at: formatDate(new Date()),
|
|
61
|
+
})
|
|
62
|
+
.where('id', '=', (cart as Record<string, unknown>).id)
|
|
63
|
+
.executeTakeFirst()
|
|
64
|
+
|
|
65
|
+
if (Number(result.numUpdatedRows) > 0)
|
|
66
|
+
updatedCount++
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return updatedCount
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof Error)
|
|
74
|
+
throw new TypeError(`Failed to update carts in bulk: ${error.message}`)
|
|
75
|
+
|
|
76
|
+
throw error
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
import { formatDate } from '@stacksjs/orm'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Delete a coupon by ID
|
|
6
|
+
* @param id The ID of the coupon to delete
|
|
7
|
+
* @returns A boolean indicating success
|
|
8
|
+
*/
|
|
9
|
+
export async function deleteCoupon(id: number): Promise<boolean> {
|
|
10
|
+
const result = await db
|
|
11
|
+
.deleteFrom('coupons')
|
|
12
|
+
.where('id', '=', id)
|
|
13
|
+
.executeTakeFirst()
|
|
14
|
+
|
|
15
|
+
return !!result
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Delete multiple coupons by IDs
|
|
20
|
+
* @param ids Array of coupon IDs to delete
|
|
21
|
+
* @returns Number of deleted coupons
|
|
22
|
+
*/
|
|
23
|
+
export async function deleteCoupons(ids: number[]): Promise<number> {
|
|
24
|
+
if (!ids.length) {
|
|
25
|
+
return 0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result = await db
|
|
29
|
+
.deleteFrom('coupons')
|
|
30
|
+
.where('id', 'in', ids)
|
|
31
|
+
.execute()
|
|
32
|
+
|
|
33
|
+
return (result as any).length || 0
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Delete expired coupons
|
|
38
|
+
* @returns The number of deleted coupons
|
|
39
|
+
*/
|
|
40
|
+
export async function deleteExpiredCoupons(): Promise<number> {
|
|
41
|
+
const currentDate = formatDate(new Date())
|
|
42
|
+
|
|
43
|
+
const result = await db
|
|
44
|
+
.deleteFrom('coupons')
|
|
45
|
+
.where('end_date', '<', currentDate)
|
|
46
|
+
.executeTakeFirst()
|
|
47
|
+
|
|
48
|
+
return Number(result?.numDeletedRows) || 0
|
|
49
|
+
}
|