@stacksjs/commerce 0.72.103 → 0.73.0

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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Delete a cart by ID
3
+ *
4
+ * @param id The ID of the cart to delete
5
+ * @returns True if the cart was deleted, false otherwise
6
+ */
7
+ export declare function destroy(id: number): Promise<boolean>;
8
+ /**
9
+ * Delete multiple carts by ID
10
+ *
11
+ * @param ids Array of cart IDs to delete
12
+ * @returns Number of carts deleted
13
+ */
14
+ export declare function bulkDestroy(ids: number[]): Promise<number>;
@@ -0,0 +1,10 @@
1
+ import type { Cart, ModelRow } from '@stacksjs/orm';
2
+ /**
3
+ * Fetch a cart by ID
4
+ */
5
+ export declare function fetchById(id: number): Promise<CartJsonResponse | undefined>;
6
+ /**
7
+ * Fetch all carts
8
+ */
9
+ export declare function fetchAll(): Promise<CartJsonResponse[]>;
10
+ declare type CartJsonResponse = ModelRow<typeof Cart>;
@@ -0,0 +1,16 @@
1
+ export {
2
+ bulkDestroy,
3
+ destroy,
4
+ } from './destroy';
5
+ export {
6
+ fetchAll,
7
+ fetchById,
8
+ } from './fetch';
9
+ export {
10
+ bulkStore,
11
+ store,
12
+ } from './store';
13
+ export {
14
+ bulkUpdate,
15
+ update,
16
+ } from './update';
@@ -0,0 +1,17 @@
1
+ import type { Cart, ModelRow, NewModelData } from '@stacksjs/orm';
2
+ /**
3
+ * Create a new cart
4
+ *
5
+ * @param data Cart data to store
6
+ * @returns The newly created cart record
7
+ */
8
+ export declare function store(data: NewCart): Promise<CartJsonResponse>;
9
+ /**
10
+ * Create multiple carts at once
11
+ *
12
+ * @param data Array of cart data to store
13
+ * @returns Number of carts created
14
+ */
15
+ export declare function bulkStore(data: NewCart[]): Promise<number>;
16
+ declare type CartJsonResponse = ModelRow<typeof Cart>;
17
+ declare type NewCart = NewModelData<typeof Cart>;
@@ -0,0 +1,18 @@
1
+ import type { Cart, ModelRow, UpdateModelData } from '@stacksjs/orm';
2
+ /**
3
+ * Update a cart
4
+ *
5
+ * @param id The ID of the cart to update
6
+ * @param data The cart data to update
7
+ * @returns The updated cart record
8
+ */
9
+ export declare function update(id: number, data: Omit<CartUpdate, 'id'>): Promise<CartJsonResponse>;
10
+ /**
11
+ * Update multiple carts at once
12
+ *
13
+ * @param data Array of objects containing cart ID and update data
14
+ * @returns Number of carts updated
15
+ */
16
+ export declare function bulkUpdate(data: CartUpdate[]): Promise<number>;
17
+ declare type CartJsonResponse = ModelRow<typeof Cart>;
18
+ declare type CartUpdate = UpdateModelData<typeof Cart>;
@@ -1,6 +1,8 @@
1
1
  export {
2
2
  bulkDestroy,
3
+ deactivate,
3
4
  destroy,
5
+ destroyExpired,
4
6
  } from './destroy';
5
7
  export {
6
8
  calculateGiftCardValues,
@@ -10,7 +10,7 @@ export declare function update(id: number, data: Omit<GiftCardUpdate, 'id'>): Pr
10
10
  /**
11
11
  * Update a gift card's balance atomically (stacksjs/stacks#1879 Co-8).
12
12
  *
13
- * Pre-fix: read balance compute new write. Two parallel $50
13
+ * Pre-fix: read balance -> compute new -> write. Two parallel $50
14
14
  * redemptions of a $100 card both saw `current_balance = 100`,
15
15
  * both wrote `50`, leaving `50` instead of `0`. The post-read
16
16
  * negative-balance guard only caught single-threaded misuse.
@@ -19,8 +19,14 @@ export declare function update(id: number, data: Omit<GiftCardUpdate, 'id'>): Pr
19
19
  * enforces every precondition in the WHERE clause. The database
20
20
  * guarantees only one writer wins the race. Throws when the row
21
21
  * was found but the precondition failed (insufficient balance,
22
- * inactive, missing) so the caller can distinguish from a
23
- * not-found row.
22
+ * inactive, expired, not reloadable) so the caller can distinguish
23
+ * from a not-found row.
24
+ *
25
+ * A negative `amount` is a redemption and a positive one a reload.
26
+ * The two are not symmetric, so the statement is shaped per direction:
27
+ * only a redemption stamps `last_used_date`, and only a reload may
28
+ * touch a card already spent down to `USED` (and then only when the
29
+ * card is `is_reloadable`, which is otherwise a field nothing honours).
24
30
  *
25
31
  * @param id The ID of the gift card
26
32
  * @param amount The amount to adjust (positive to add, negative to deduct)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as auctions from './auctions/index';
2
+ import * as carts from './carts/index';
2
3
  import * as coupons from './coupons/index';
3
4
  import * as customers from './customers/index';
4
5
  import * as devices from './devices/index';
@@ -15,6 +16,7 @@ import * as waitlists from './waitlists/index';
15
16
  export declare const commerce: CommerceNamespace;
16
17
  export declare interface CommerceNamespace {
17
18
  auctions: AuctionsModule
19
+ carts: CartsModule
18
20
  coupons: CouponsModule
19
21
  customers: CustomersModule
20
22
  errors: ErrorsModule
@@ -30,6 +32,7 @@ export declare interface CommerceNamespace {
30
32
  receipts: ReceiptsModule
31
33
  }
32
34
  declare type AuctionsModule = typeof auctions;
35
+ declare type CartsModule = typeof carts;
33
36
  declare type CouponsModule = typeof coupons;
34
37
  declare type CustomersModule = typeof customers;
35
38
  declare type ErrorsModule = typeof errors;
@@ -45,6 +48,7 @@ declare type DevicesModule = typeof devices;
45
48
  declare type ReceiptsModule = typeof receipts;
46
49
  export {
47
50
  auctions,
51
+ carts,
48
52
  coupons,
49
53
  customers,
50
54
  devices,