@stacksjs/commerce 0.72.103 → 0.73.1

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.
@@ -29,6 +29,7 @@ export {
29
29
  fetchAll,
30
30
  fetchById,
31
31
  fetchDailyOrderTrends,
32
+ fetchRecent,
32
33
  fetchStats,
33
34
  } from './fetch';
34
35
  export {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Delete a courier by ID
3
+ *
4
+ * @param id The ID of the courier to delete
5
+ * @returns True if the courier was deleted, false otherwise
6
+ */
7
+ export declare function destroy(id: number): Promise<boolean>;
8
+ /**
9
+ * Delete multiple couriers at once
10
+ *
11
+ * @param ids Array of courier IDs to delete
12
+ * @returns Number of couriers deleted
13
+ */
14
+ export declare function bulkDestroy(ids: number[]): Promise<number>;
@@ -0,0 +1,10 @@
1
+ import type { Courier, ModelRow } from '@stacksjs/orm';
2
+ /**
3
+ * Fetch a courier by ID
4
+ */
5
+ export declare function fetchById(id: number): Promise<CourierJsonResponse | undefined>;
6
+ /**
7
+ * Fetch all couriers
8
+ */
9
+ export declare function fetchAll(): Promise<CourierJsonResponse[]>;
10
+ declare type CourierJsonResponse = ModelRow<typeof Courier>;
@@ -0,0 +1,17 @@
1
+ import type { Courier, ModelRow, NewModelData } from '@stacksjs/orm';
2
+ /**
3
+ * Create a new courier
4
+ *
5
+ * @param data The courier data to store
6
+ * @returns The newly created courier record
7
+ */
8
+ export declare function store(data: NewCourier): Promise<CourierJsonResponse>;
9
+ /**
10
+ * Create multiple couriers at once
11
+ *
12
+ * @param data Array of courier data to store
13
+ * @returns Number of couriers created
14
+ */
15
+ export declare function bulkStore(data: NewCourier[]): Promise<number>;
16
+ declare type CourierJsonResponse = ModelRow<typeof Courier>;
17
+ declare type NewCourier = NewModelData<typeof Courier>;
@@ -0,0 +1,27 @@
1
+ import type { Courier, ModelRow, UpdateModelData } from '@stacksjs/orm';
2
+ /**
3
+ * Update a courier
4
+ *
5
+ * @param id The id of the courier to update
6
+ * @param data The courier data to update
7
+ * @returns The updated courier record
8
+ */
9
+ export declare function update(id: number, data: CourierUpdate): Promise<CourierJsonResponse | undefined>;
10
+ /**
11
+ * Update a courier's status
12
+ *
13
+ * @param id The ID of the courier
14
+ * @param status The new status (active, on_delivery, on_break)
15
+ * @returns The updated courier with the new status
16
+ */
17
+ export declare function updateStatus(id: number, status: 'active' | 'on_delivery' | 'on_break'): Promise<CourierJsonResponse>;
18
+ /**
19
+ * Update courier's contact information
20
+ *
21
+ * @param id The ID of the courier
22
+ * @param phone The updated phone number
23
+ * @returns The updated courier
24
+ */
25
+ export declare function updateContact(id: number, phone?: string): Promise<CourierJsonResponse>;
26
+ declare type CourierJsonResponse = ModelRow<typeof Courier>;
27
+ declare type CourierUpdate = UpdateModelData<typeof Courier>;
@@ -12,7 +12,7 @@ export declare function fetchAll(): Promise<DeliveryRouteJsonResponse[]>;
12
12
  */
13
13
  export declare function fetchActive(): Promise<DeliveryRouteJsonResponse[]>;
14
14
  /**
15
- * Fetch delivery routes by driver
15
+ * Fetch delivery routes by courier
16
16
  */
17
- export declare function fetchByDriver(driver: string): Promise<DeliveryRouteJsonResponse[]>;
17
+ export declare function fetchByCourier(courier: string): Promise<DeliveryRouteJsonResponse[]>;
18
18
  declare type DeliveryRouteJsonResponse = RowOf<'delivery_routes'>;
@@ -7,7 +7,7 @@ export {
7
7
  export {
8
8
  fetchActive,
9
9
  fetchAll,
10
- fetchByDriver,
10
+ fetchByCourier,
11
11
  fetchById,
12
12
  } from './fetch';
13
13
  // Functions from store.ts
@@ -1,5 +1,5 @@
1
+ import * as couriers from './couriers/index';
1
2
  import * as digital from './digital-deliveries/index';
2
- import * as drivers from './drivers/index';
3
3
  import * as geocoding from './geocoding/index';
4
4
  import * as licenses from './license-keys/index';
5
5
  import * as methods from './shipping-methods/index';
@@ -10,7 +10,7 @@ import * as zones from './shipping-zones/index';
10
10
  declare const shippings: ShippingsNamespace;
11
11
  declare interface ShippingsNamespace {
12
12
  digital: typeof digital
13
- drivers: typeof drivers
13
+ couriers: typeof couriers
14
14
  geocoding: typeof geocoding
15
15
  licenses: typeof licenses
16
16
  methods: typeof methods
@@ -21,7 +21,7 @@ declare interface ShippingsNamespace {
21
21
  }
22
22
  export {
23
23
  digital,
24
- drivers,
24
+ couriers,
25
25
  geocoding,
26
26
  licenses,
27
27
  methods,
@@ -7,37 +7,37 @@ export declare function routeTrackingChannel(routeId: number | string): string;
7
7
  * Best-effort broadcast to a realtime channel.
8
8
  *
9
9
  * Private rather than public: the payload is a named customer's address and a
10
- * driver's live position. Authorisation happens in the app's websocket
10
+ * courier's live position. Authorisation happens in the app's websocket
11
11
  * authenticator (`setWsAuthenticator`), which is where the tracking token is
12
12
  * checked.
13
13
  */
14
14
  export declare function broadcastToChannel(channelName: string, event: string, payload: Record<string, unknown>): Promise<void>;
15
15
  /**
16
- * A driver moved.
16
+ * A courier moved.
17
17
  *
18
18
  * Broadcast only — this fires several times a minute per active delivery and
19
19
  * has no business waking every event listener in the application.
20
20
  */
21
21
  export declare function emitDeliveryPosition(orderIds: readonly (number | string)[], routeId: number | null | undefined, payload: DeliveryPositionPayload): Promise<void>;
22
- /** A stop was assigned to a route and a driver. Both paths. */
22
+ /** A stop was assigned to a route and a courier. Both paths. */
23
23
  export declare function emitDeliveryAssigned(stop: Record<string, unknown>): Promise<void>;
24
24
  /** The vehicle left with this order on it. Both paths. */
25
25
  export declare function emitDeliveryStarted(stop: Record<string, unknown>): Promise<void>;
26
26
  /**
27
- * The driver came within the "nearly there" radius.
27
+ * The courier came within the "nearly there" radius.
28
28
  *
29
29
  * The event worth sending an SMS for, and the reason the whole ingest path
30
30
  * computes distance per ping rather than leaving it to the client.
31
31
  */
32
32
  export declare function emitDeliveryNearby(stop: Record<string, unknown>, distanceMeters: number, etaSeconds: number | null): Promise<void>;
33
- /** The driver reached the address. Both paths. */
33
+ /** The courier reached the address. Both paths. */
34
34
  export declare function emitDeliveryArrived(stop: Record<string, unknown>): Promise<void>;
35
35
  /** Handover done. Both paths. */
36
36
  export declare function emitDeliveryCompleted(stop: Record<string, unknown>): Promise<void>;
37
37
  /** The stop could not be completed. Event bus only; there is no live view to update. */
38
38
  export declare function emitDeliveryFailed(stop: Record<string, unknown>, reason?: string): Promise<void>;
39
39
  export declare interface DeliveryPositionPayload extends Coordinates, Record<string, unknown> {
40
- driverId: number
40
+ courierId: number
41
41
  routeId?: number | null
42
42
  heading?: number | null
43
43
  speed?: number | null
@@ -23,7 +23,7 @@ export declare function bearingInDegrees(from: Coordinates, to: Coordinates): nu
23
23
  * great circles, and clamped below by `minimumSeconds` so an ETA never reads
24
24
  * "arriving now" from two blocks away.
25
25
  *
26
- * Returns null when the driver is stopped, because dividing by zero speed
26
+ * Returns null when the courier is stopped, because dividing by zero speed
27
27
  * produces Infinity and showing "arriving in ∞ minutes" is worse than showing
28
28
  * nothing.
29
29
  */
@@ -1,11 +1,11 @@
1
1
  export type { DeliveryPositionPayload } from './events';
2
2
  export type { Coordinates } from './geo';
3
- export type { DriverPingInput, DriverPingResult } from './ping';
3
+ export type { CourierPingInput, CourierPingResult } from './ping';
4
4
  export type { AssignStopInput } from './stops';
5
5
  /**
6
6
  * Live delivery tracking.
7
7
  *
8
- * `drivers` and `delivery-routes` are CRUD over the records. This is the part
8
+ * `couriers` and `delivery-routes` are CRUD over the records. This is the part
9
9
  * that moves: position ingest, the stop lifecycle, the geodesy the ETA is
10
10
  * derived from, and the two fan-outs (event bus for the application, realtime
11
11
  * channel for the browser).
@@ -32,7 +32,7 @@ export {
32
32
  export {
33
33
  ARRIVAL_RADIUS_METERS,
34
34
  NEARBY_RADIUS_METERS,
35
- recordDriverPing,
35
+ recordCourierPing,
36
36
  } from './ping';
37
37
  export {
38
38
  assignStop,
@@ -1,15 +1,15 @@
1
1
  import type { Coordinates } from './geo';
2
- export declare function recordDriverPing(input: DriverPingInput): Promise<DriverPingResult>;
2
+ export declare function recordCourierPing(input: CourierPingInput): Promise<CourierPingResult>;
3
3
  /**
4
- * Driver position ingest.
4
+ * Courier position ingest.
5
5
  *
6
- * One entry point for "the driver's device says it is here". Everything that
6
+ * One entry point for "the courier's device says it is here". Everything that
7
7
  * has to happen on a fix happens here, in one place, because splitting it
8
8
  * across the route handler and a listener is how a tracking page ends up
9
9
  * showing a position that the ETA disagrees with:
10
10
  *
11
- * 1. Append to the `driver_pings` series.
12
- * 2. Update the driver's denormalised present position.
11
+ * 1. Append to the `courier_pings` series.
12
+ * 2. Update the courier's denormalised present position.
13
13
  * 3. Recompute distance and ETA for the stop being served.
14
14
  * 4. Push position to everyone watching (broadcast only).
15
15
  * 5. Raise `delivery:nearby` and `delivery:arrived` on threshold crossings,
@@ -17,16 +17,16 @@ export declare function recordDriverPing(input: DriverPingInput): Promise<Driver
17
17
  */
18
18
  /** Within this many metres of the destination, the customer is told to expect the door. */
19
19
  export declare const NEARBY_RADIUS_METERS: 400;
20
- /** Within this, the driver is treated as arrived. */
20
+ /** Within this, the courier is treated as arrived. */
21
21
  export declare const ARRIVAL_RADIUS_METERS: 60;
22
- export declare interface DriverPingInput extends Coordinates {
23
- driverId: number
22
+ export declare interface CourierPingInput extends Coordinates {
23
+ courierId: number
24
24
  heading?: number | null
25
25
  speed?: number | null
26
26
  accuracy?: number | null
27
27
  recordedAt?: string
28
28
  }
29
- export declare interface DriverPingResult {
29
+ export declare interface CourierPingResult {
30
30
  pingId: number | null
31
31
  routeId: number | null
32
32
  stopId: number | null
@@ -1,7 +1,7 @@
1
1
  /** Put an order on a route. */
2
2
  export declare function assignStop(input: AssignStopInput): Promise<Record<string, unknown>>;
3
3
  /**
4
- * The driver is now driving to this stop.
4
+ * The courier is now driving to this stop.
5
5
  *
6
6
  * Also moves the order to OUT_FOR_DELIVERY, which is the state the customer's
7
7
  * tracking page and notifications key on.
@@ -17,20 +17,8 @@ export declare function completeStop(stopId: number, notes?: string): Promise<Re
17
17
  * told a vehicle is still coming.
18
18
  */
19
19
  export declare function failStop(stopId: number, reason: string): Promise<Record<string, unknown> | null>;
20
- /** Start a route. Until this runs, pings from its driver find no active route. */
20
+ /** Start a route. Until this runs, pings from its courier find no active route. */
21
21
  export declare function startRoute(routeId: number): Promise<void>;
22
- /**
23
- * Stop lifecycle.
24
- *
25
- * Every state change a driver makes goes through one of these, so the order's
26
- * status, the stop's timestamps and the outgoing events stay in step. Writing
27
- * `delivery_stops.status` directly works and is how a tracking page ends up
28
- * saying "out for delivery" about an order that was delivered ten minutes ago.
29
- *
30
- * The order status is kept in lockstep on purpose: `OUT_FOR_DELIVERY` and
31
- * `DELIVERED` are the two states a customer actually sees, and they mean the
32
- * same thing as the stop being `en_route` and `completed`.
33
- */
34
22
  export declare interface AssignStopInput {
35
23
  deliveryRouteId: number
36
24
  orderId?: number | null
@@ -41,4 +29,18 @@ export declare interface AssignStopInput {
41
29
  recipientName?: string | null
42
30
  recipientPhone?: string | null
43
31
  etaAt?: string | null
32
+ type?: StopType
44
33
  }
34
+ /**
35
+ * Stop lifecycle.
36
+ *
37
+ * Every state change a courier makes goes through one of these, so the order's
38
+ * status, the stop's timestamps and the outgoing events stay in step. Writing
39
+ * `delivery_stops.status` directly works and is how a tracking page ends up
40
+ * saying "out for delivery" about an order that was delivered ten minutes ago.
41
+ *
42
+ * The order status is kept in lockstep on purpose: `OUT_FOR_DELIVERY` and
43
+ * `DELIVERED` are the two states a customer actually sees, and they mean the
44
+ * same thing as the stop being `en_route` and `completed`.
45
+ */
46
+ export type StopType = 'pickup' | 'dropoff';
@@ -3,7 +3,7 @@ export declare function shippingRateWriteData(input: ShippingWriteInput): Record
3
3
  export declare function shippingZoneWriteData(input: ShippingWriteInput): Record<string, unknown>;
4
4
  export declare function digitalDeliveryWriteData(input: ShippingWriteInput): Record<string, unknown>;
5
5
  export declare function licenseKeyWriteData(input: ShippingWriteInput): Record<string, unknown>;
6
- export declare function driverWriteData(input: ShippingWriteInput): Record<string, unknown>;
6
+ export declare function courierWriteData(input: ShippingWriteInput): Record<string, unknown>;
7
7
  export declare function deliveryRouteWriteData(input: ShippingWriteInput): Record<string, unknown>;
8
8
  declare type ShippingWriteInput = Record<string, unknown>;
9
9
  declare type ShippingColumnAliases = Readonly<Record<string, readonly string[]>>;
@@ -1,19 +1,6 @@
1
1
  /** Every active rate, in the order they should be listed. */
2
2
  export declare function activeTaxRates(options?: BreakdownOptions): Promise<any[]>;
3
- /**
4
- * Tax on `taxable` cents, itemised.
5
- *
6
- * Each component is rounded on its own rather than the total being rounded
7
- * once. That is what a receipt has to show — the parts have to add up to the
8
- * figure charged, and a single rounding at the end leaves a line that is a
9
- * cent out from the sum above it.
10
- *
11
- * Every component is applied to `taxable` directly. Jurisdictions that compound
12
- * — where one tax forms part of the base for another — need an explicit order,
13
- * and that is a bigger claim than this should make quietly; an app that needs
14
- * it should compose two calls.
15
- */
16
- export declare function breakdownFor(taxable: number, rates: any[], options?: BreakdownOptions): TaxBreakdown;
3
+ export declare function breakdownFor(taxable: number, rates: readonly TaxRateRow[], options?: BreakdownOptions): TaxBreakdown;
17
4
  /**
18
5
  * Read the active rates and apply them.
19
6
  *
@@ -42,3 +29,24 @@ export declare interface BreakdownOptions {
42
29
  codes?: string[]
43
30
  country?: string
44
31
  }
32
+ /**
33
+ * Tax on `taxable` cents, itemised.
34
+ *
35
+ * Each component is rounded on its own rather than the total being rounded
36
+ * once. That is what a receipt has to show — the parts have to add up to the
37
+ * figure charged, and a single rounding at the end leaves a line that is a
38
+ * cent out from the sum above it.
39
+ *
40
+ * Every component is applied to `taxable` directly. Jurisdictions that compound
41
+ * — where one tax forms part of the base for another — need an explicit order,
42
+ * and that is a bigger claim than this should make quietly; an app that needs
43
+ * it should compose two calls.
44
+ */
45
+ /** One tax rate row, in the terms the breakdown reads it. */
46
+ export declare interface TaxRateRow {
47
+ id?: number | string
48
+ name?: string
49
+ code?: string
50
+ rate?: number | string
51
+ exemptible?: boolean
52
+ }
package/dist/types.d.ts CHANGED
@@ -203,6 +203,8 @@ export declare interface FetchManufacturersOptions {
203
203
  country?: string
204
204
  featured?: boolean
205
205
  search?: string
206
+ page?: number
207
+ limit?: number
206
208
  }
207
209
  export declare interface FetchCouponsOptions {
208
210
  page?: number
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The id of the row an INSERT just created, or `undefined` when the driver did
3
+ * not report one.
4
+ *
5
+ * Every driver spells it differently, and one of them does not answer at all:
6
+ * SQLite reports `lastInsertRowid`, MySQL reports `insertId`, and Postgres
7
+ * reports neither without a `RETURNING` clause. A caller that only reads one
8
+ * spelling silently loses the row it just wrote on every other dialect.
9
+ *
10
+ * **Row counts are deliberately not consulted.** `numInsertedOrUpdatedRows` and
11
+ * its siblings say how MANY rows changed, not WHICH one. Reading a count as an
12
+ * id is worse than reading nothing: a successful single-row insert reports `1`,
13
+ * so the caller fetches id 1 and returns the FIRST row of the table as though
14
+ * it were the new one. Use {@link mutationCount} when the count is what you
15
+ * want.
16
+ *
17
+ * @param result Whatever `executeTakeFirst()` resolved to.
18
+ * @returns A positive integer id, or `undefined` when the driver reported none.
19
+ */
20
+ export declare function insertedId(result: unknown): number | undefined;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/commerce",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.72.103",
5
+ "version": "0.73.1",
6
6
  "description": "Stacks commerce utilities.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -1,14 +0,0 @@
1
- /**
2
- * Delete a driver by ID
3
- *
4
- * @param id The ID of the driver to delete
5
- * @returns True if the driver was deleted, false otherwise
6
- */
7
- export declare function destroy(id: number): Promise<boolean>;
8
- /**
9
- * Delete multiple drivers at once
10
- *
11
- * @param ids Array of driver IDs to delete
12
- * @returns Number of drivers deleted
13
- */
14
- export declare function bulkDestroy(ids: number[]): Promise<number>;
@@ -1,10 +0,0 @@
1
- import type { Driver, ModelRow } from '@stacksjs/orm';
2
- /**
3
- * Fetch a driver by ID
4
- */
5
- export declare function fetchById(id: number): Promise<DriverJsonResponse | undefined>;
6
- /**
7
- * Fetch all drivers
8
- */
9
- export declare function fetchAll(): Promise<DriverJsonResponse[]>;
10
- declare type DriverJsonResponse = ModelRow<typeof Driver>;
@@ -1,17 +0,0 @@
1
- import type { Driver, ModelRow, NewModelData } from '@stacksjs/orm';
2
- /**
3
- * Create a new driver
4
- *
5
- * @param data The driver data to store
6
- * @returns The newly created driver record
7
- */
8
- export declare function store(data: NewDriver): Promise<DriverJsonResponse>;
9
- /**
10
- * Create multiple drivers at once
11
- *
12
- * @param data Array of driver data to store
13
- * @returns Number of drivers created
14
- */
15
- export declare function bulkStore(data: NewDriver[]): Promise<number>;
16
- declare type DriverJsonResponse = ModelRow<typeof Driver>;
17
- declare type NewDriver = NewModelData<typeof Driver>;
@@ -1,27 +0,0 @@
1
- import type { Driver, ModelRow, UpdateModelData } from '@stacksjs/orm';
2
- /**
3
- * Update a driver
4
- *
5
- * @param id The id of the driver to update
6
- * @param data The driver data to update
7
- * @returns The updated driver record
8
- */
9
- export declare function update(id: number, data: DriverUpdate): Promise<DriverJsonResponse | undefined>;
10
- /**
11
- * Update a driver's status
12
- *
13
- * @param id The ID of the driver
14
- * @param status The new status (active, on_delivery, on_break)
15
- * @returns The updated driver with the new status
16
- */
17
- export declare function updateStatus(id: number, status: 'active' | 'on_delivery' | 'on_break'): Promise<DriverJsonResponse>;
18
- /**
19
- * Update driver's contact information
20
- *
21
- * @param id The ID of the driver
22
- * @param phone The updated phone number
23
- * @returns The updated driver
24
- */
25
- export declare function updateContact(id: number, phone?: string): Promise<DriverJsonResponse>;
26
- declare type DriverJsonResponse = ModelRow<typeof Driver>;
27
- declare type DriverUpdate = UpdateModelData<typeof Driver>;
File without changes