@scayle/storefront-core 8.13.0 → 8.14.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.14.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Update `getUniqueItemsFromOrder` and `getItemQuantityFromOrder` to accept order
8
+ `Product` and `Variant` generics to ensure correct types. Morover, both methods
9
+ are deprecated as they should be handled within Storefront project itself.
10
+
11
+ ## 8.14.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Expose `PackageDeliveryStatus` type. This new type clearly defines the allowed values for a package's delivery status. This improves code clarity and helps prevent typos. It's used to replace the inline string literal types in the `ListOfPackages` type.
16
+ - Refactor the `Order` and `OrderItem` interfaces to be generic, allowing them to accept custom `Product` and `Variant` types. This allows to strongly type the `product` and `variant` data within orders and order items, leading to better type checking and potentially fewer runtime errors. This allows for compile-time checks and autocompletion when working with product and variant properties of `OrderItem` and items property of `Order`.
17
+
3
18
  ## 8.13.0
4
19
 
5
20
  ### Minor Changes
@@ -113,7 +113,7 @@ export declare class CustomerAPIClient {
113
113
  *
114
114
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
115
115
  */
116
- getOrder(shopId: number, orderId: number): Promise<Order>;
116
+ getOrder(shopId: number, orderId: number): Promise<Order<Record<string, unknown>, Record<string, unknown>>>;
117
117
  /**
118
118
  * Update contact details of a customer.
119
119
  *
@@ -5,8 +5,10 @@ import type { Order } from '../types';
5
5
  * @param order The order object.
6
6
  *
7
7
  * @returns An array of unique order items.
8
+ *
9
+ * @deprecated getting unique items from order should be handled within the Storefront project itself.
8
10
  */
9
- export declare const getUniqueItemsFromOrder: (order: Order) => import("../types").OrderItem[] | undefined;
11
+ export declare const getUniqueItemsFromOrder: <P, V>(order: Order<P, V>) => import("../types").OrderItem<P, V>[] | undefined;
10
12
  /**
11
13
  * Gets the quantity of a specific item in an order based on its variant ID.
12
14
  *
@@ -14,5 +16,7 @@ export declare const getUniqueItemsFromOrder: (order: Order) => import("../types
14
16
  * @param variantId The ID of the variant to count.
15
17
  *
16
18
  * @returns The quantity of the item in the order, or undefined if the order or items are undefined.
19
+ *
20
+ * @deprecated getting item quantity from order should be handled within the Storefront project itself.
17
21
  */
18
- export declare const getItemQuantityFromOrder: (order: Order, variantId: number) => number | undefined;
22
+ export declare const getItemQuantityFromOrder: <P, V>(order: Order<P, V>, variantId: number) => number | undefined;
@@ -12,4 +12,4 @@ import type { Order, RpcContext } from '../../types';
12
12
  */
13
13
  export declare const getOrderDataByCbd: ({ cbdToken }: {
14
14
  cbdToken: string;
15
- }, context: RpcContext) => Promise<ErrorResponse | Order>;
15
+ }, context: RpcContext) => Promise<ErrorResponse | Order<Record<string, unknown>, Record<string, unknown>>>;
@@ -36,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
36
36
  carrier,
37
37
  basketId: context.basketKey,
38
38
  campaignKey
39
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.13.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.14.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
40
40
  return {
41
41
  accessToken: refreshedAccessToken,
42
42
  checkoutJwt
@@ -14,4 +14,4 @@ import type { Order } from '../../../types';
14
14
  */
15
15
  export declare const getOrderById: ({ orderId }: {
16
16
  orderId: number;
17
- }, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order>;
17
+ }, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order<Record<string, unknown>, Record<string, unknown>>>;
@@ -4,6 +4,7 @@ import type { CentAmount } from './product';
4
4
  * Items are grouped by package, depending on the item's supplier configuration. The `packageId` references an entry in the packages list with delivery estimates and expected carrier.
5
5
  */
6
6
  export type PackageReference = number;
7
+ export type PackageDeliveryStatus = 'open' | 'shipment_pending' | 'delegation_pending' | 'shipment_completed' | 'cancellation_completed';
7
8
  /**
8
9
  * The distribution of items across packages is calculated based on the supplierId. Once shipments are processed, the packages may be updated to reflect the actual shipments.
9
10
  */
@@ -20,7 +21,7 @@ export type ListOfPackages = {
20
21
  maximum: string;
21
22
  minimum: string;
22
23
  };
23
- deliveryStatus: 'open' | 'shipment_pending' | 'delegation_pending' | 'shipment_completed' | 'cancellation_completed';
24
+ deliveryStatus: PackageDeliveryStatus;
24
25
  returnIdentCode?: null | string;
25
26
  shipmentKey?: string;
26
27
  tracking?: {
@@ -104,7 +105,7 @@ export type OrderStatus = 'order_open' | 'payment_pending' | 'payment_reserved'
104
105
  export type OrderStatusCode = 'order_created' | 'order_open' | 'order_pended' | 'order_confirmed' | 'order_delegated' | 'order_shipped' | 'order_invoiced' | 'order_aborted' | 'order_cancelled' | 'order_imported' | 'order_invoice_error';
105
106
  export type BillingStatusCode = 'billing_open' | 'billing_pending' | 'billing_payment_pending' | 'billing_completed' | 'billing_payment_cancelled' | 'billing_partially_refunded' | 'billing_refunded';
106
107
  export type ShippingStatusCode = 'shipping_open' | 'shipping_not_deliveable' | 'shipping_ordered' | 'shipping_delivered' | 'shipping_cancelled' | 'shipping_undeliverable' | 'shipping_returned' | 'shipping_partially_returned' | 'shipping_partially_undeliverable';
107
- export interface OrderItem {
108
+ export interface OrderItem<Product = Record<string, unknown>, Variant = Record<string, unknown>> {
108
109
  id?: string;
109
110
  /**
110
111
  * The number of deliverable items available in the warehouse for immediate shipping.
@@ -117,9 +118,7 @@ export interface OrderItem {
117
118
  /**
118
119
  * customData allows the tenant to attach data to an item. The data will remain attached to the item from the basket through the process of order creation and delegation and may be displayed to the customer during the order lifecycle.
119
120
  */
120
- customData?: {
121
- [k: string]: unknown;
122
- };
121
+ customData?: Record<string, unknown>;
123
122
  deliveryForecast?: DeliveryForecastFromWarehouse;
124
123
  /**
125
124
  * Whether the return shipment got triggered manually. Is missing in case there is no return shipment.
@@ -204,17 +203,13 @@ export interface OrderItem {
204
203
  */
205
204
  withTax: CentAmount;
206
205
  };
207
- product: {
208
- [k: string]: unknown;
209
- };
206
+ product: Product;
210
207
  /**
211
208
  * Reference set in the checkout when an item was reserved successfully.
212
209
  */
213
210
  reservationKey?: string;
214
211
  status: 'available' | 'cancelled' | 'delivered' | 'undeliverable' | 'returned' | 'unavailable';
215
- variant: {
216
- [k: string]: unknown;
217
- };
212
+ variant: Variant;
218
213
  /**
219
214
  * The warehouse id where the item are being picking from.
220
215
  */
@@ -223,7 +218,7 @@ export interface OrderItem {
223
218
  createdAt: string;
224
219
  updatedAt: string;
225
220
  }
226
- export interface Order {
221
+ export interface Order<Product = Record<string, unknown>, Variant = Record<string, unknown>> {
227
222
  /**
228
223
  * The `id` can be applied as a parameter on the url to retrieve an individual order in the [Fetch Order by ID](#fetch-order-by-id) endpoint.
229
224
  */
@@ -318,9 +313,7 @@ export interface Order {
318
313
  };
319
314
  currencyCode: string;
320
315
  customData?: {
321
- score?: {
322
- [k: string]: unknown;
323
- } | string | number | unknown[] | boolean;
316
+ score?: Record<string, unknown> | string | number | unknown[] | boolean;
324
317
  [k: string]: unknown;
325
318
  };
326
319
  customer?: {
@@ -337,9 +330,7 @@ export interface Order {
337
330
  * Additional data attached by the client to enhance the customer
338
331
  */
339
332
  customData?: {
340
- score?: {
341
- [k: string]: unknown;
342
- } | string | number | unknown[] | boolean;
333
+ score?: Record<string, unknown> | string | number | unknown[] | boolean;
343
334
  [k: string]: unknown;
344
335
  };
345
336
  email?: string;
@@ -387,7 +378,7 @@ export interface Order {
387
378
  [k: string]: unknown;
388
379
  };
389
380
  invoicedAt?: string;
390
- items?: OrderItem[];
381
+ items?: OrderItem<Product, Variant>[];
391
382
  loyaltyCard?: {
392
383
  cardNumber?: string;
393
384
  points: number;
@@ -399,9 +390,7 @@ export interface Order {
399
390
  /**
400
391
  * The `data` attribute will contain the data pushed to the Checkout by the Payment Provider in use (or internally generated, should the payment not be provided by an external PSP). This object's structure depends on the PSP itself, however, it will contain the minimum dataset necessary for further processing of the Order.
401
392
  */
402
- data?: {
403
- [k: string]: unknown;
404
- };
393
+ data?: Record<string, unknown>;
405
394
  /**
406
395
  * Details about installments, included as a listing of the values involved in the Installments transaction.
407
396
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.13.0",
3
+ "version": "8.14.1",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",