diff --git a/packages/core/package.json b/packages/core/package.json index 36e0190318..ccf4fc6199 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/core", - "version": "2.7.5", + "version": "2.7.6", "sideEffects": false, "main": "lib/index.cjs.js", "module": "lib/index.es.js", diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index a23c7ce056..6e8a0524d7 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -31,9 +31,9 @@ export const VSF_CHANNEL_COOKIE = 'vsf-channel'; export type ComputedProperty = Readonly>>; -export type CustomQuery = Record +export type CustomQuery = Record>; -export type ComposableFunctionArgs = T & { customQuery?: CustomQuery } +export type ComposableFunctionArgs = T & { customQuery?: CustomQuery }; export interface ProductsSearchParams { perPage?: number; @@ -63,24 +63,18 @@ export interface Context { } export type PlatformApi = { - [functionName: string]: (context: Context, ...args: any[]) => Promise -} + [functionName: string]: (context: Context, ...args: any[]) => Promise; +}; export type ContextedPlatformApi = { - [P in keyof T]: T[P] extends (context: Context, ...arg: infer X) => Promise - ? (...arg: X) => Promise - : never -} + [P in keyof T]: T[P] extends (context: Context, ...arg: infer X) => Promise ? (...arg: X) => Promise : never; +}; export interface Composable { - api?: ContextedPlatformApi + api?: ContextedPlatformApi; } -export interface UseProduct< - PRODUCTS, - PRODUCT_SEARCH_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseProduct extends Composable { products: ComputedProperty; loading: ComputedProperty; error: ComputedProperty; @@ -97,7 +91,7 @@ export interface UseForgotPassword { result: ComputedProperty; loading: ComputedProperty; error: ComputedProperty; - setNew(params: ComposableFunctionArgs<{ tokenValue: string, newPassword: string }>): Promise; + setNew(params: ComposableFunctionArgs<{ tokenValue: string; newPassword: string }>): Promise; request(params: ComposableFunctionArgs<{ email: string }>): Promise; } @@ -130,20 +124,15 @@ export interface UseUserErrors { load: Error; } -export interface UseUser -< - USER, - UPDATE_USER_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseUser extends Composable { user: ComputedProperty; setUser: (user: USER) => void; updateUser: (params: { user: UPDATE_USER_PARAMS; customQuery?: CustomQuery }) => Promise; register: (params: { user: UseUserRegisterParams; customQuery?: CustomQuery }) => Promise; login: (params: { user: UseUserLoginParams; customQuery?: CustomQuery }) => Promise; - logout: (params?: {customQuery: CustomQuery}) => Promise; - changePassword: (params: { current: string; new: string, customQuery?: CustomQuery }) => Promise; - load: (params?: {customQuery: CustomQuery}) => Promise; + logout: (params?: { customQuery: CustomQuery }) => Promise; + changePassword: (params: { current: string; new: string; customQuery?: CustomQuery }) => Promise; + load: (params?: { customQuery: CustomQuery }) => Promise; isAuthenticated: Ref; loading: ComputedProperty; error: ComputedProperty; @@ -158,11 +147,7 @@ export interface UseUserOrderSearchParams { export interface UseUserOrderErrors { search: Error; } -export interface UseUserOrder< - ORDERS, - ORDER_SEARCH_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseUserOrder extends Composable { orders: ComputedProperty; search(params: ComposableFunctionArgs): Promise; loading: ComputedProperty; @@ -185,17 +170,13 @@ export interface UseUserShippingErrors { load: Error; setDefaultAddress: Error; } -export interface UseUserShipping< -USER_SHIPPING, -USER_SHIPPING_ITEM, -API extends PlatformApi = any -> extends Composable { +export interface UseUserShipping extends Composable { shipping: ComputedProperty; - addAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - deleteAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - updateAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery}) => Promise; + addAddress: (params: { address: USER_SHIPPING_ITEM; customQuery?: CustomQuery }) => Promise; + deleteAddress: (params: { address: USER_SHIPPING_ITEM; customQuery?: CustomQuery }) => Promise; + updateAddress: (params: { address: USER_SHIPPING_ITEM; customQuery?: CustomQuery }) => Promise; load: () => Promise; - setDefaultAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; + setDefaultAddress: (params: { address: USER_SHIPPING_ITEM; customQuery?: CustomQuery }) => Promise; loading: ComputedProperty; error: ComputedProperty; } @@ -228,17 +209,13 @@ export interface UseUserBillingErrors { load: Error; setDefaultAddress: Error; } -export interface UseUserBilling< - USER_BILLING, - USER_BILLING_ITEM, - API extends PlatformApi = any -> extends Composable { +export interface UseUserBilling extends Composable { billing: ComputedProperty; - addAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - deleteAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - updateAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; + addAddress: (params: { address: USER_BILLING_ITEM; customQuery?: CustomQuery }) => Promise; + deleteAddress: (params: { address: USER_BILLING_ITEM; customQuery?: CustomQuery }) => Promise; + updateAddress: (params: { address: USER_BILLING_ITEM; customQuery?: CustomQuery }) => Promise; load: () => Promise; - setDefaultAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; + setDefaultAddress: (params: { address: USER_BILLING_ITEM; customQuery?: CustomQuery }) => Promise; loading: ComputedProperty; error: ComputedProperty; } @@ -267,11 +244,7 @@ export interface UserBillingGetters { export interface UseCategoryErrors { search: Error; } -export interface UseCategory< - CATEGORY, - CATEGORY_SEARCH_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseCategory extends Composable { categories: ComputedProperty; search(params: ComposableFunctionArgs): Promise; loading: ComputedProperty; @@ -287,17 +260,11 @@ export interface UseCartErrors { applyCoupon: Error; removeCoupon: Error; } -export interface UseCart -< - CART, - CART_ITEM, - PRODUCT, - API extends PlatformApi = any -> extends Composable { +export interface UseCart extends Composable { cart: ComputedProperty; setCart(cart: CART): void; addItem(params: { product: PRODUCT; quantity: number; customQuery?: CustomQuery }): Promise; - isInCart: (params: {product: PRODUCT, customQuery?: CustomQuery, [k: string]: unknown}) => boolean; + isInCart: (params: { product: PRODUCT; customQuery?: CustomQuery; [k: string]: unknown }) => boolean; removeItem(params: { product: CART_ITEM; customQuery?: CustomQuery }): Promise; updateItemQty(params: { product: CART_ITEM; quantity?: number; customQuery?: CustomQuery }): Promise; clear(): Promise; @@ -314,13 +281,7 @@ export interface UseWishlistErrors { load: Error; clear: Error; } -export interface UseWishlist -< - WISHLIST, - WISHLIST_ITEM, - PRODUCT, - API extends PlatformApi = any -> extends Composable { +export interface UseWishlist extends Composable { wishlist: ComputedProperty; loading: ComputedProperty; addItem(params: { product: PRODUCT; customQuery?: CustomQuery }): Promise; @@ -329,7 +290,7 @@ export interface UseWishlist load(params: { customQuery?: CustomQuery }): Promise; clear(): Promise; setWishlist: (wishlist: WISHLIST) => void; - isInWishlist(params: {product: PRODUCT, customQuery?: CustomQuery, [k: string]: unknown}): boolean; + isInWishlist(params: { product: PRODUCT; customQuery?: CustomQuery; [k: string]: unknown }): boolean; error: ComputedProperty; } @@ -352,8 +313,7 @@ export interface UseMakeOrder extends Comp loading: ComputedProperty; } -export interface UseCheckout -< +export interface UseCheckout< PAYMENT_METHODS, SHIPPING_METHODS, PERSONAL_DETAILS, @@ -378,12 +338,7 @@ export interface UseReviewErrors { search: Error; addReview: Error; } -export interface UseReview< -REVIEW, -REVIEWS_SEARCH_PARAMS, -REVIEW_ADD_PARAMS, -API extends PlatformApi = any -> extends Composable { +export interface UseReview extends Composable { search(params: ComposableFunctionArgs): Promise; addReview(params: ComposableFunctionArgs): Promise; error: ComputedProperty; @@ -396,11 +351,7 @@ export interface UseShippingErrors { load: Error; save: Error; } -export interface UseShipping< -SHIPPING, -SHIPPING_PARAMS, -API extends PlatformApi = any -> extends Composable { +export interface UseShipping extends Composable { error: ComputedProperty; loading: ComputedProperty; shipping: ComputedProperty; @@ -412,18 +363,14 @@ export interface UseShippingProviderErrors { load: Error; save: Error; } -export interface UseShippingProvider< -STATE, -SHIPPING_METHOD, -API extends PlatformApi = any -> extends Composable { +export interface UseShippingProvider extends Composable { error: ComputedProperty; loading: ComputedProperty; state: ComputedProperty; setState(state: STATE): void; load(): Promise; load(params: { customQuery?: CustomQuery }): Promise; - save(params: { shippingMethod: SHIPPING_METHOD, customQuery?: CustomQuery }): Promise; + save(params: { shippingMethod: SHIPPING_METHOD; customQuery?: CustomQuery }): Promise; } export interface UseBillingErrors { @@ -431,11 +378,7 @@ export interface UseBillingErrors { save: Error; } -export interface UseBilling< - BILLING, - BILLING_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseBilling extends Composable { error: ComputedProperty; loading: ComputedProperty; billing: ComputedProperty; @@ -472,11 +415,7 @@ export interface UseFacet { export interface UseContentErrors { search: Error; } -export interface UseContent< - CONTENT, - CONTENT_SEARCH_PARAMS, - API extends PlatformApi = any -> extends Composable { +export interface UseContent extends Composable { search: (params: CONTENT_SEARCH_PARAMS) => Promise; content: ComputedProperty; loading: ComputedProperty; @@ -550,7 +489,7 @@ export interface AgnosticFilter { count?: number; label: string; value: string; - }[] + }[]; } export interface AgnosticProductReview { @@ -600,7 +539,7 @@ export enum AgnosticOrderStatus { Shipped = 'Shipped', Complete = 'Complete', Cancelled = 'Cancelled', - Refunded = 'Refunded' + Refunded = 'Refunded', } export interface AgnosticFacet { @@ -650,7 +589,7 @@ export interface AgnosticStore { id: string; description?: string; locales?: AgnosticLocale[]; - currencies?: AgnosticCurrency[] + currencies?: AgnosticCurrency[]; address?: AgnosticAddress; geoLocation?: AgnosticGeoLocation; [x: string]: unknown; @@ -730,12 +669,7 @@ export interface UserOrderGetters { getItemQty: (item: ORDER_ITEM) => number; getItemPrice: (item: ORDER_ITEM) => number; getFormattedPrice: (price: number) => string; - getOrdersTotal: (orders: { - offset: number; - count: number; - total: number; - results: Array; - }) => number; + getOrdersTotal: (orders: { offset: number; count: number; total: number; results: Array }) => number; [getterName: string]: (element: any, options?: any) => unknown; } @@ -764,8 +698,8 @@ export interface FacetsGetters { } export interface ForgotPasswordGetters { - getResetPasswordToken: (result: FORGOT_PASSWORD_RESULT) => string - isPasswordChanged: (result: FORGOT_PASSWORD_RESULT) => boolean + getResetPasswordToken: (result: FORGOT_PASSWORD_RESULT) => string; + isPasswordChanged: (result: FORGOT_PASSWORD_RESULT) => boolean; } export interface UseSearchGetters { @@ -775,7 +709,7 @@ export interface UseSearchGetters { getItemPrice: (item: ITEM) => AgnosticPrice; getSortOptions: (result: RESULT) => AgnosticSort; getBreadcrumbs: (result: RESULT) => AgnosticBreadcrumb[]; - getItemImages: (item: ITEM) => AgnosticMediaGalleryItem[] + getItemImages: (item: ITEM) => AgnosticMediaGalleryItem[]; getFilters: (result: RESULT) => AgnosticFilter[]; getItemName: (item: ITEM) => string; getItemId: (item: ITEM) => string; @@ -805,7 +739,7 @@ export interface CallHookParams extends HookParams { export type BeforeCallArgs = any; export type AfterCallArgs = any; -export interface BeforeCallParams< C> extends CallHookParams { +export interface BeforeCallParams extends CallHookParams { args: BeforeCallArgs; } @@ -826,12 +760,12 @@ export type CustomQueryFn = ({ query, variables, metadata }) => { metadata: any; }; -export type ApiClientMethod = (...args: any) => Promise +export type ApiClientMethod = (...args: any) => Promise; export interface ApiClientExtension { name: string; extendApiMethods?: Record; - extendApp?: (params: { app: Express, configuration: any }) => void; + extendApp?: (params: { app: Express; configuration: any }) => void; hooks?: (req: Request, res: Response) => ApiClientExtensionHooks; } @@ -842,7 +776,7 @@ export interface Integration { customQueries?: Record; } -export type IntegrationsSection = Record +export type IntegrationsSection = Record; export interface MiddlewareConfig { integrations: Record; @@ -881,11 +815,8 @@ export interface ApiClientConfig { } export type ApiClientMethods = { - [K in keyof T]: - T[K] extends (...args: any) => any ? - (...args: [...Parameters, CustomQuery?]) => ReturnType : - T[K] -} + [K in keyof T]: T[K] extends (...args: any) => any ? (...args: [...Parameters, CustomQuery?]) => ReturnType : T[K]; +}; export interface UseStoreErrors { load: Error | null; @@ -903,8 +834,8 @@ export interface UseStoreFactoryLoadParamArguments { } export interface UseStoreFactoryParams extends FactoryParams { - load(context: Context, params: UseStoreFactoryLoadParamArguments): Promise - change(context: Context, params: UseStoreFactoryChangeParamArguments): Promise + load(context: Context, params: UseStoreFactoryLoadParamArguments): Promise; + change(context: Context, params: UseStoreFactoryChangeParamArguments): Promise; } export interface UseStoreInterface { change(params: UseStoreFactoryChangeParamArguments): Promise; @@ -920,5 +851,5 @@ export interface UseStore { export interface UseStoreGetters { getItems(stores: STORES, criteria?: CRITERIA): AgnosticStore[]; - getSelected(stores: STORES): AgnosticStore | undefined + getSelected(stores: STORES): AgnosticStore | undefined; }