@liquidcommerce/cloud-sdk 1.0.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/README.md +256 -0
- package/dist/index.cjs +1 -0
- package/dist/index.esm.js +1 -0
- package/dist/liquidcommerce-cloud-sdk.ssr.js +1 -0
- package/dist/types/constants/core.constant.d.ts +4 -0
- package/dist/types/core/authenticated.service.d.ts +125 -0
- package/dist/types/core/cart-helper.service.d.ts +48 -0
- package/dist/types/core/catalog-helper.service.d.ts +113 -0
- package/dist/types/core/checkout-helper.service.d.ts +76 -0
- package/dist/types/core/index.d.ts +7 -0
- package/dist/types/core/location-helper.service.d.ts +47 -0
- package/dist/types/core/payment-provider.service.d.ts +91 -0
- package/dist/types/core/singleton.service.d.ts +138 -0
- package/dist/types/enums.d.ts +265 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.umd.d.ts +2 -0
- package/dist/types/interfaces/address.interface.d.ts +21 -0
- package/dist/types/interfaces/cart.interface.d.ts +188 -0
- package/dist/types/interfaces/catalog.interface.d.ts +69 -0
- package/dist/types/interfaces/catalog.service.interface.d.ts +65 -0
- package/dist/types/interfaces/checkout.interface.d.ts +118 -0
- package/dist/types/interfaces/liquid-commerce-client.interface.d.ts +597 -0
- package/dist/types/interfaces/payment.interface.d.ts +88 -0
- package/dist/types/interfaces/retailer.interface.d.ts +63 -0
- package/dist/types/interfaces/user.interface.d.ts +53 -0
- package/dist/types/liquid-commerce-client.d.ts +189 -0
- package/dist/types/services/address.service.d.ts +44 -0
- package/dist/types/services/cart.service.d.ts +31 -0
- package/dist/types/services/catalog.service.d.ts +38 -0
- package/dist/types/services/checkout.service.d.ts +28 -0
- package/dist/types/services/payment.service.d.ts +39 -0
- package/dist/types/services/user.service.d.ts +43 -0
- package/dist/types/types.d.ts +36 -0
- package/package.json +108 -0
- package/umd/liquidcommerce-cloud-sdk.min.js +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { DAYS_OF_WEEK, ENUM_MODALITIES } from '../enums';
|
|
2
|
+
import type { IAddress } from './address.interface';
|
|
3
|
+
export interface IRetailerTimes {
|
|
4
|
+
startsAt: string;
|
|
5
|
+
endsAt: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IRetailerHoursConfig {
|
|
8
|
+
active: boolean;
|
|
9
|
+
times: IRetailerTimes[];
|
|
10
|
+
}
|
|
11
|
+
export type RetailerHours = {
|
|
12
|
+
[day in DAYS_OF_WEEK]: IRetailerHoursConfig;
|
|
13
|
+
};
|
|
14
|
+
export interface IRetailerExpectation {
|
|
15
|
+
detail: string;
|
|
16
|
+
short: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IRetailerFreeDelivery {
|
|
19
|
+
min: number;
|
|
20
|
+
active: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface IFeeShippingConfig {
|
|
23
|
+
maxQuantity: number;
|
|
24
|
+
fee: number;
|
|
25
|
+
active: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface IRetailerFeeShipping {
|
|
28
|
+
individual: IFeeShippingConfig;
|
|
29
|
+
pack: IFeeShippingConfig;
|
|
30
|
+
free: IRetailerFreeDelivery;
|
|
31
|
+
}
|
|
32
|
+
export interface IRetailerFeeDelivery {
|
|
33
|
+
min: number;
|
|
34
|
+
fee: number;
|
|
35
|
+
free: IRetailerFreeDelivery;
|
|
36
|
+
}
|
|
37
|
+
export type IRetailerFees = IRetailerFeeShipping | IRetailerFeeDelivery;
|
|
38
|
+
export interface IRetailerFulfillments {
|
|
39
|
+
id: string;
|
|
40
|
+
type: ENUM_MODALITIES;
|
|
41
|
+
deliveryFee?: number;
|
|
42
|
+
shippingFee?: number;
|
|
43
|
+
engravingFee?: number;
|
|
44
|
+
subtotal?: number;
|
|
45
|
+
timezone?: string;
|
|
46
|
+
fees: IRetailerFees;
|
|
47
|
+
expectation: IRetailerExpectation;
|
|
48
|
+
hours: RetailerHours;
|
|
49
|
+
breaks: IRetailerTimes[];
|
|
50
|
+
items: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface IRetailer {
|
|
53
|
+
name: string;
|
|
54
|
+
id: string;
|
|
55
|
+
platformFee?: number;
|
|
56
|
+
deliveryFee?: number;
|
|
57
|
+
shippingFee?: number;
|
|
58
|
+
engravingFee?: number;
|
|
59
|
+
subtotal?: number;
|
|
60
|
+
total?: number;
|
|
61
|
+
address?: IAddress;
|
|
62
|
+
fulfillments: IRetailerFulfillments[];
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ENUM_ADDRESS_TYPE } from '../enums';
|
|
2
|
+
import type { ICoreParams } from '../types';
|
|
3
|
+
export interface IUserSession {
|
|
4
|
+
key: string | null;
|
|
5
|
+
secret: string | null;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface IUserAddress {
|
|
9
|
+
id: string;
|
|
10
|
+
one: string;
|
|
11
|
+
two?: string | null;
|
|
12
|
+
city: string;
|
|
13
|
+
state: string;
|
|
14
|
+
zip: string;
|
|
15
|
+
country: string;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
isDefault?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface IUser {
|
|
21
|
+
id: string;
|
|
22
|
+
email: string;
|
|
23
|
+
firstName: string | null;
|
|
24
|
+
lastName: string | null;
|
|
25
|
+
phone: string | null;
|
|
26
|
+
birthDate: string | null;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
updatedAt: Date;
|
|
29
|
+
addresses: IUserAddress[];
|
|
30
|
+
session: IUserSession;
|
|
31
|
+
}
|
|
32
|
+
export interface IUserSessionParams extends ICoreParams {
|
|
33
|
+
id?: string;
|
|
34
|
+
email?: string;
|
|
35
|
+
firstName?: string | null;
|
|
36
|
+
lastName?: string | null;
|
|
37
|
+
phone?: string | null;
|
|
38
|
+
birthDate?: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface IPurgeResponse {
|
|
41
|
+
deleted: boolean;
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IUserAddressParams extends ICoreParams {
|
|
45
|
+
customerId: string;
|
|
46
|
+
one: string;
|
|
47
|
+
two?: string | null;
|
|
48
|
+
city: string;
|
|
49
|
+
state: string;
|
|
50
|
+
zip: string;
|
|
51
|
+
isDefault?: boolean;
|
|
52
|
+
type: ENUM_ADDRESS_TYPE;
|
|
53
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { LIQUID_COMMERCE_ENV } from './enums';
|
|
2
|
+
import type { ICart, ICartUpdateParams } from './interfaces/cart.interface';
|
|
3
|
+
import type { ICatalog, ICatalogParams } from './interfaces/catalog.service.interface';
|
|
4
|
+
import type { ICheckoutCompleteParams, ICheckoutCompleteResponse, ICheckoutPrepareParams, ICheckoutPrepareResponse } from './interfaces/checkout.interface';
|
|
5
|
+
import type { IAddressMethod, ICartMethod, ICatalogMethod, ICheckoutMethod, ILiquidCommerceClient, IPaymentMethod, IUserMethod } from './interfaces/liquid-commerce-client.interface';
|
|
6
|
+
import type { ILiquidPaymentConfig, ILiquidPaymentToken, IPaymentElementEventMap } from './interfaces/payment.interface';
|
|
7
|
+
import type { IPurgeResponse, IUser, IUserAddress, IUserAddressParams, IUserSessionParams } from './interfaces/user.interface';
|
|
8
|
+
import type { IAddressAutocompleteParams, IAddressAutocompleteResult, IAddressDetailsParams, IAddressDetailsResult } from './services/address.service';
|
|
9
|
+
import type { IAvailabilityParams, IAvailabilityResponse } from './services/catalog.service';
|
|
10
|
+
import type { IApiResponseWithData, IApiResponseWithoutData, ILiquidCommerceConfig } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* The LiquidCommerceClient class is a client for interacting with the LiquidCommerce Cloud APIs.
|
|
13
|
+
* This client encapsulates the logic for working with various services, including addresses, catalog products,
|
|
14
|
+
* carts, users, payments, checkouts, and orders.
|
|
15
|
+
*
|
|
16
|
+
* The client handles authentication, service initialization, and ensures secure interaction with the
|
|
17
|
+
* LiquidCommerce Cloud API by managing token expiration and re-authentication automatically.
|
|
18
|
+
*
|
|
19
|
+
* @class
|
|
20
|
+
* @implements {ILiquidCommerceClient}
|
|
21
|
+
*/
|
|
22
|
+
declare class LiquidCommerceClient implements ILiquidCommerceClient {
|
|
23
|
+
private readonly authenticatedClient;
|
|
24
|
+
private addressService;
|
|
25
|
+
private catalogService;
|
|
26
|
+
private cartService;
|
|
27
|
+
private userService;
|
|
28
|
+
private paymentService;
|
|
29
|
+
private checkoutService;
|
|
30
|
+
private config;
|
|
31
|
+
private singletonManager;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of LiquidCommerceClient.
|
|
34
|
+
*
|
|
35
|
+
* @constructor
|
|
36
|
+
* @param {string} apiKey - The API key used for authenticating with the LiquidCommerce Cloud API.
|
|
37
|
+
* @param {ILiquidCommerceConfig} config - Configuration options including environment settings, base URLs, and other preferences.
|
|
38
|
+
*/
|
|
39
|
+
constructor(apiKey: string, config: ILiquidCommerceConfig);
|
|
40
|
+
/**
|
|
41
|
+
* Determines the appropriate base URL for the API based on the environment.
|
|
42
|
+
*
|
|
43
|
+
* @private
|
|
44
|
+
* @param {ILiquidCommerceConfig} config - Configuration options.
|
|
45
|
+
* @return {string} - The base URL for the selected environment.
|
|
46
|
+
*/
|
|
47
|
+
private determineBaseURL;
|
|
48
|
+
/**
|
|
49
|
+
* Initializes the client by authenticating with the LiquidCommerce API.
|
|
50
|
+
* This method should be called before making any API requests.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
* @return {Promise<void>} - Resolves when initialization is successful.
|
|
54
|
+
* @throws {Error} - Throws an error if authentication fails.
|
|
55
|
+
*/
|
|
56
|
+
init(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Ensures that the client is authenticated before making API requests.
|
|
59
|
+
* If the authentication token is expired, it will attempt to re-authenticate.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @return {Promise<void>} - Resolves when the client is authenticated.
|
|
63
|
+
* @throws {Error} - Throws an error if re-authentication fails.
|
|
64
|
+
*/
|
|
65
|
+
private ensureAuthenticated;
|
|
66
|
+
/**
|
|
67
|
+
* Address object that provides methods for performing address autocompletion and retrieving address details.
|
|
68
|
+
*
|
|
69
|
+
* @interface IAddressMethod address
|
|
70
|
+
*
|
|
71
|
+
* @property {function(Omit<IAddressAutocompleteParams, 'key'>): Promise<IApiResponseWithData<IAddressAutocompleteResult[]>>} autocomplete -
|
|
72
|
+
* Method for performing address autocompletion based on the provided parameters.
|
|
73
|
+
*
|
|
74
|
+
* @property {function(Omit<IAddressDetailsParams, 'key'>): Promise<IApiResponseWithData<IAddressDetailsResult>>} details -
|
|
75
|
+
* Method for retrieving address details based on the provided parameters.
|
|
76
|
+
*/
|
|
77
|
+
address: IAddressMethod;
|
|
78
|
+
/**
|
|
79
|
+
* Catalog object that provides methods for availability and search operations.
|
|
80
|
+
*
|
|
81
|
+
* @interface ICatalogMethod catalog
|
|
82
|
+
*
|
|
83
|
+
* @property {function(params: IAvailabilityParams): Promise<IApiResponseWithoutData<IAvailabilityResponse>>} availability -
|
|
84
|
+
* Method to check the availability of a specific item in the catalog.
|
|
85
|
+
*
|
|
86
|
+
* @property {function(params: ICatalogParams): Promise<IApiResponseWithoutData<ICatalog>>} search -
|
|
87
|
+
* Method to perform a search in the catalog based on the provided parameters.
|
|
88
|
+
*
|
|
89
|
+
* @see {@link IApiResponseWithoutData} for the structure of the promise returned by both methods.
|
|
90
|
+
*/
|
|
91
|
+
catalog: ICatalogMethod;
|
|
92
|
+
/**
|
|
93
|
+
* Represents a cart object with methods for updating and retrieving cart data.
|
|
94
|
+
*
|
|
95
|
+
* @interface ICartMethod cart
|
|
96
|
+
*
|
|
97
|
+
* @property {function(id: string): Promise<IApiResponseWithoutData<ICart>>} get -
|
|
98
|
+
* Retrieves the cart by its ID, or returns a new cart if no ID is provided.
|
|
99
|
+
* @property {function(params: ICartUpdateParams): Promise<IApiResponseWithoutData<ICart>>} update -
|
|
100
|
+
* Method to update the cart with the provided parameters.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link ICartUpdateParams} for the structure of the parameters required to update the cart.
|
|
103
|
+
* @see {@link IApiResponseWithoutData} for the structure of the promise returned by both methods.
|
|
104
|
+
* @see {@link ICart} for the structure of the cart data returned.
|
|
105
|
+
*/
|
|
106
|
+
cart: ICartMethod;
|
|
107
|
+
/**
|
|
108
|
+
* User object that provides methods for user-related operations.
|
|
109
|
+
*
|
|
110
|
+
* @interface IUserMethod user
|
|
111
|
+
*
|
|
112
|
+
* @property {function(params: IUserSessionParams): Promise<IApiResponseWithData<IUser>>} session -
|
|
113
|
+
* Method for creating or updating a user session.
|
|
114
|
+
* @property {function(identifier: string): Promise<IApiResponseWithData<IPurgeResponse>>} purge -
|
|
115
|
+
* Method for purging a user's data from the system.
|
|
116
|
+
* @property {function(params: IUserAddressParams): Promise<IApiResponseWithData<IUserAddress>>} updateAddress -
|
|
117
|
+
* Method for updating or creating a user's address.
|
|
118
|
+
* @property {function(addressId: string): Promise<IApiResponseWithData<IPurgeResponse>>} purgeAddress -
|
|
119
|
+
* Method for purging a user's address.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link IUserSessionParams} for the structure of the session request parameters.
|
|
122
|
+
* @see {@link IUserAddressParams} for the structure of the address update request parameters.
|
|
123
|
+
* @see {@link IUser} for the structure of the user data returned.
|
|
124
|
+
* @see {@link IUserAddress} for the structure of the user's address data returned.
|
|
125
|
+
* @see {@link IPurgeResponse} for the structure of the user data returned.
|
|
126
|
+
*
|
|
127
|
+
* */
|
|
128
|
+
user: IUserMethod;
|
|
129
|
+
/**
|
|
130
|
+
* Payment object that provides methods for payment-related operations.
|
|
131
|
+
*
|
|
132
|
+
* @interface IPaymentMethod payment
|
|
133
|
+
*
|
|
134
|
+
* @property {function(config: ILiquidPaymentConfig): Promise<void>} mount -
|
|
135
|
+
* Method for mounting the payment element into the DOM.
|
|
136
|
+
*
|
|
137
|
+
* @property {function(): Promise<ILiquidPaymentToken>} generateToken -
|
|
138
|
+
* Method for generating a payment token for the current payment information.
|
|
139
|
+
*
|
|
140
|
+
* @property {function(eventType: K, handler: function): void} subscribe -
|
|
141
|
+
* Method for subscribing to payment element events.
|
|
142
|
+
*
|
|
143
|
+
* @property {function(eventType: K, handler?: function): void} unsubscribe -
|
|
144
|
+
* Method for unsubscribing from payment element events.
|
|
145
|
+
*
|
|
146
|
+
* @see {@link ILiquidPaymentConfig} Represents the configuration for Liquid payment.
|
|
147
|
+
* @see {@link ILiquidPaymentToken} Represents a payment token for liquid payments.
|
|
148
|
+
* @see {@link ILiquidPaymentError} Represents an error that occurs during a liquid payment.
|
|
149
|
+
* @see {@link ILiquidPaymentElementOptions} The options for the payment element.
|
|
150
|
+
* @see {@link IPaymentElementEventMap} The map of payment element event types to their corresponding event objects.
|
|
151
|
+
*/
|
|
152
|
+
payment: IPaymentMethod;
|
|
153
|
+
/**
|
|
154
|
+
* Checkout object that provides methods for checkout-related operations.
|
|
155
|
+
*
|
|
156
|
+
* @interface ICheckoutMethod checkout
|
|
157
|
+
*
|
|
158
|
+
* @property {function(params: ICheckoutPrepareParams): Promise<IApiResponseWithoutData<ICheckoutPrepareResponse>>} prepare -
|
|
159
|
+
* Method to prepare a checkout based on the provided parameters.
|
|
160
|
+
* @property {function(params: ICheckoutCompleteParams): Promise<IApiResponseWithoutData<ICheckoutCompleteResponse>>} complete -
|
|
161
|
+
* Method completes a checkout process with the provided token and payment information.
|
|
162
|
+
*
|
|
163
|
+
* @see {@link ICheckoutPrepareParams} for the structure of the prepare request parameters.
|
|
164
|
+
* @see {@link IApiResponseWithoutData} for the structure of the promise returned by the prepare method.
|
|
165
|
+
* @see {@link ICheckoutPrepareResponse} for the structure of the prepared checkout data returned.
|
|
166
|
+
* @see {@link ICheckoutCompleteParams} for the structure of the complete request parameters.
|
|
167
|
+
* @see {@link ICheckoutCompleteResponse} for the structure of the complete checkout data returned.
|
|
168
|
+
*/
|
|
169
|
+
checkout: ICheckoutMethod;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Factory function to create and initialize a LiquidCommerceClient instance.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} apiKey - The API key used for authenticating with the Liquid Commerce Cloud API.
|
|
175
|
+
* @param {ILiquidCommerceConfig} config - The configuration object containing options such as environment settings, base URLs, and other preferences.
|
|
176
|
+
* @return {Promise<LiquidCommerceClient>} - A promise that resolves to a fully initialized LiquidCommerceClient instance.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* // Example usage:
|
|
180
|
+
* const liquidClient = await LiquidCommerce('your-api-key', {
|
|
181
|
+
* env: LIQUID_COMMERCE_ENV.STAGE,
|
|
182
|
+
* googlePlacesApiKey: 'your-google-places-api-key',
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* @throws {Error} - Throws an error if the client initialization fails.
|
|
186
|
+
*/
|
|
187
|
+
export declare function LiquidCommerce(apiKey: string, config: ILiquidCommerceConfig): Promise<LiquidCommerceClient>;
|
|
188
|
+
export { LIQUID_COMMERCE_ENV };
|
|
189
|
+
export type { IAddressAutocompleteParams, IAddressAutocompleteResult, IAddressDetailsParams, IAddressDetailsResult, IAddressMethod, IApiResponseWithData, IApiResponseWithoutData, IAvailabilityParams, IAvailabilityResponse, ICart, ICartMethod, ICartUpdateParams, ICatalog, ICatalogMethod, ICatalogParams, ICheckoutCompleteParams, ICheckoutCompleteResponse, ICheckoutMethod, ICheckoutPrepareParams, ICheckoutPrepareResponse, ILiquidCommerceClient, ILiquidCommerceConfig, ILiquidPaymentConfig, ILiquidPaymentToken, IPaymentElementEventMap, IPaymentMethod, IPurgeResponse, IUser, IUserAddress, IUserAddressParams, IUserMethod, IUserSessionParams, };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AuthenticatedService } from '../core';
|
|
2
|
+
import type { ICoords } from '../interfaces/address.interface';
|
|
3
|
+
import type { IApiResponseWithData, ICoreParams } from '../types';
|
|
4
|
+
export interface IAddressAutocompleteParams extends ICoreParams {
|
|
5
|
+
input: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IAddressAutocompleteResult {
|
|
8
|
+
id: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IAddressDetailsParams extends ICoreParams {
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IAddressDetailsResult {
|
|
15
|
+
formattedAddress: string;
|
|
16
|
+
coords: ICoords;
|
|
17
|
+
}
|
|
18
|
+
type AddressServiceResponse<T> = IApiResponseWithData<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Represents a service for interacting with address-related functionality.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AddressService {
|
|
23
|
+
private client;
|
|
24
|
+
constructor(client: AuthenticatedService);
|
|
25
|
+
/**
|
|
26
|
+
* Performs autocomplete on an address using the Google Places API.
|
|
27
|
+
* @param {IAddressAutocompleteParams} params - The parameters for the autocomplete request.
|
|
28
|
+
* @param {string} googlePlacesApiKey - The API key for accessing the Google Places API.
|
|
29
|
+
* @return {Promise<AddressServiceResponse<IAddressAutocompleteResult[]>>} - A Promise that resolves to the autocomplete response.
|
|
30
|
+
* @throws {Error} - If the autocomplete request fails.
|
|
31
|
+
*/
|
|
32
|
+
autocomplete(params: IAddressAutocompleteParams, googlePlacesApiKey: string): Promise<AddressServiceResponse<IAddressAutocompleteResult[]>>;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves detailed information about an address using Google Places API.
|
|
35
|
+
*
|
|
36
|
+
* @async
|
|
37
|
+
* @param {IAddressDetailsParams} params - The parameters for retrieving address details.
|
|
38
|
+
* @param {string} googlePlacesApiKey - The API key for accessing Google Places API.
|
|
39
|
+
* @return {Promise<AddressServiceResponse<IAddressDetailsResult>>} A promise that resolves to the response containing the detailed information about an address.
|
|
40
|
+
* @throws {Error} if the request to retrieve address details fails.
|
|
41
|
+
*/
|
|
42
|
+
details(params: IAddressDetailsParams, googlePlacesApiKey: string): Promise<AddressServiceResponse<IAddressDetailsResult>>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AuthenticatedService, CartHelperService } from '../core';
|
|
2
|
+
import type { ICart, ICartUpdateParams } from '../interfaces/cart.interface';
|
|
3
|
+
import type { IApiResponseWithoutData } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* The CartService class is responsible for fetching and updating cart data from the server.
|
|
6
|
+
*
|
|
7
|
+
* @class CartService
|
|
8
|
+
*/
|
|
9
|
+
export declare class CartService {
|
|
10
|
+
private client;
|
|
11
|
+
private cartHelperService;
|
|
12
|
+
private readonly servicePath;
|
|
13
|
+
constructor(client: AuthenticatedService, cartHelperService: CartHelperService);
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the cart with the specified ID or a new cart from the server.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} id - The ID of the cart to retrieve.
|
|
18
|
+
* @param {boolean} refresh - A flag that if true return a refreshed access token.
|
|
19
|
+
* @return {Promise<IApiResponseWithoutData<ICart>>} A Promise that resolves to the cart object.
|
|
20
|
+
* @throws {Error} If the request to update the cart fails.
|
|
21
|
+
*/
|
|
22
|
+
get(id?: string, refresh?: boolean): Promise<IApiResponseWithoutData<ICart>>;
|
|
23
|
+
/**
|
|
24
|
+
* Updates the cart with the provided parameters.
|
|
25
|
+
*
|
|
26
|
+
* @param {ICartUpdateParams} params - The parameters for updating the cart.
|
|
27
|
+
* @returns {Promise<IApiResponseWithoutData<ICart>>} A promise that resolves to the updated cart data.
|
|
28
|
+
* @throws {Error} If the cart update request fails.
|
|
29
|
+
*/
|
|
30
|
+
update(params: ICartUpdateParams): Promise<IApiResponseWithoutData<ICart>>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AuthenticatedService, CatalogHelperService } from '../core';
|
|
2
|
+
import type { ILocBase } from '../interfaces/address.interface';
|
|
3
|
+
import type { IProduct } from '../interfaces/catalog.interface';
|
|
4
|
+
import type { ICatalog, ICatalogParams } from '../interfaces/catalog.service.interface';
|
|
5
|
+
import type { IRetailer } from '../interfaces/retailer.interface';
|
|
6
|
+
import type { IApiResponseWithoutData } from '../types';
|
|
7
|
+
export interface IAvailabilityParams extends ILocBase {
|
|
8
|
+
upcs: string[];
|
|
9
|
+
shouldShowOffHours?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface IAvailabilityResponse {
|
|
12
|
+
products: IProduct[];
|
|
13
|
+
retailers: IRetailer[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The CatalogService class provides methods for interacting with the catalog API.
|
|
17
|
+
*/
|
|
18
|
+
export declare class CatalogService {
|
|
19
|
+
private client;
|
|
20
|
+
private catalogHelperService;
|
|
21
|
+
private readonly servicePath;
|
|
22
|
+
constructor(client: AuthenticatedService, catalogHelperService: CatalogHelperService);
|
|
23
|
+
/**
|
|
24
|
+
* Makes an asynchronous request to check the availability of a specific item in the catalog.
|
|
25
|
+
* @param {IAvailabilityParams} params - The parameters for the availability request.
|
|
26
|
+
* @return {Promise<IApiResponseWithoutData<IAvailabilityResponse>>} - A Promise that resolves to an API response object without data, containing availability information.
|
|
27
|
+
* @throws {Error} - If the availability request fails, an error is thrown.
|
|
28
|
+
*/
|
|
29
|
+
availability(params: IAvailabilityParams): Promise<IApiResponseWithoutData<IAvailabilityResponse>>;
|
|
30
|
+
/**
|
|
31
|
+
* Performs a search in the catalog based on the provided parameters.
|
|
32
|
+
*
|
|
33
|
+
* @param {ICatalogParams} params - The search parameters.
|
|
34
|
+
* @return {Promise<IApiResponseWithoutData<ICatalog>>} - A promise that resolves to the catalog search response.
|
|
35
|
+
* @throws {Error} - If the search parameters are invalid or if the search request fails.
|
|
36
|
+
*/
|
|
37
|
+
search(params: ICatalogParams): Promise<IApiResponseWithoutData<ICatalog>>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AuthenticatedService, CheckoutHelperService } from '../core';
|
|
2
|
+
import type { ICheckoutCompleteParams, ICheckoutCompleteResponse, ICheckoutPrepareParams, ICheckoutPrepareResponse } from '../interfaces/checkout.interface';
|
|
3
|
+
import type { IApiResponseWithoutData } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* A service for managing the checkout process.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CheckoutService {
|
|
8
|
+
private client;
|
|
9
|
+
private checkoutHelperService;
|
|
10
|
+
private readonly servicePath;
|
|
11
|
+
constructor(client: AuthenticatedService, checkoutHelperService: CheckoutHelperService);
|
|
12
|
+
/**
|
|
13
|
+
* Prepares a checkout based on the provided parameters.
|
|
14
|
+
*
|
|
15
|
+
* @param {ICheckoutPrepareParams} params - The parameters for preparing the checkout.
|
|
16
|
+
* @returns {Promise<IApiResponseWithoutData<ICheckoutPrepareResponse>>} A promise that resolves to the prepared checkout data.
|
|
17
|
+
* @throws {Error} If the checkout preparation request fails.
|
|
18
|
+
*/
|
|
19
|
+
prepare(params: ICheckoutPrepareParams): Promise<IApiResponseWithoutData<ICheckoutPrepareResponse>>;
|
|
20
|
+
/**
|
|
21
|
+
* Completes the checkout process.
|
|
22
|
+
*
|
|
23
|
+
* @param params - The parameters required to complete the checkout.
|
|
24
|
+
* @returns A promise that resolves to the API response without data for the completed checkout.
|
|
25
|
+
* @throws Throws an error if the checkout complete request fails.
|
|
26
|
+
*/
|
|
27
|
+
complete(params: ICheckoutCompleteParams): Promise<IApiResponseWithoutData<ICheckoutCompleteResponse>>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PaymentProviderService } from '../core';
|
|
2
|
+
import type { ILiquidPaymentConfig, ILiquidPaymentError, ILiquidPaymentToken, IPaymentElementEventMap } from '../interfaces/payment.interface';
|
|
3
|
+
/**
|
|
4
|
+
* The PaymentService class provides methods for interacting with payment functionality.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PaymentService {
|
|
7
|
+
private paymentProvider;
|
|
8
|
+
constructor(paymentProvider: PaymentProviderService);
|
|
9
|
+
/**
|
|
10
|
+
* Injects a payment element using the provided configuration.
|
|
11
|
+
*
|
|
12
|
+
* @param config - The configuration object to be used for injecting the payment element.
|
|
13
|
+
* @returns A Promise that resolves when the payment element has been successfully injected.
|
|
14
|
+
* @throws If a failure occurs while injecting the payment element.
|
|
15
|
+
*/
|
|
16
|
+
mount(config: ILiquidPaymentConfig): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates a payment token.
|
|
19
|
+
*
|
|
20
|
+
* @return {Promise<ILiquidPaymentToken | ILiquidPaymentError>} - A promise that resolves to either a payment token or an error.
|
|
21
|
+
*/
|
|
22
|
+
generateToken(): Promise<ILiquidPaymentToken | ILiquidPaymentError>;
|
|
23
|
+
/**
|
|
24
|
+
* Subscribes a handler function to a specific event type in the payment element.
|
|
25
|
+
*
|
|
26
|
+
* @param eventType - The type of event to subscribe to. Must be one of the keys in IPaymentElementEventMap.
|
|
27
|
+
* @param handler - The handler function to be called when the specified event occurs.
|
|
28
|
+
* @return void
|
|
29
|
+
*/
|
|
30
|
+
subscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler: (event: IPaymentElementEventMap[K]) => void): void;
|
|
31
|
+
/**
|
|
32
|
+
* Unsubscribes a handler function from a specific event type for the payment element.
|
|
33
|
+
*
|
|
34
|
+
* @param eventType - The event type to unsubscribe from.
|
|
35
|
+
* @param handler - Optional. The handler function to unsubscribe. If provided, only the specific handler will be unsubscribed. If not provided, all handlers for the event type will be unsubscribed.
|
|
36
|
+
* @return void
|
|
37
|
+
*/
|
|
38
|
+
unsubscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler?: (event: IPaymentElementEventMap[K]) => void): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AuthenticatedService } from '../core';
|
|
2
|
+
import type { IPurgeResponse, IUser, IUserAddress, IUserAddressParams, IUserSessionParams } from '../interfaces/user.interface';
|
|
3
|
+
import type { IApiResponseWithData } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* A class representing a user service.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UserService {
|
|
8
|
+
private client;
|
|
9
|
+
private readonly servicePath;
|
|
10
|
+
constructor(client: AuthenticatedService);
|
|
11
|
+
/**
|
|
12
|
+
* Creates or updates a user session.
|
|
13
|
+
*
|
|
14
|
+
* @param {IUserSessionParams} params - The parameters for creating or updating a user session.
|
|
15
|
+
* @returns {Promise<IApiResponseWithData<IUser>>} A promise that resolves to the user data.
|
|
16
|
+
* @throws {Error} If the session creation/update request fails or if neither id nor email is provided.
|
|
17
|
+
*/
|
|
18
|
+
createOrUpdateSession(params: IUserSessionParams): Promise<IApiResponseWithData<IUser>>;
|
|
19
|
+
/**
|
|
20
|
+
* Purges a user's data from the system.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} identifier - The user's ID or email.
|
|
23
|
+
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
|
|
24
|
+
* @throws {Error} If the purge request fails or if the identifier is not provided.
|
|
25
|
+
*/
|
|
26
|
+
purge(identifier: string): Promise<IApiResponseWithData<IPurgeResponse>>;
|
|
27
|
+
/**
|
|
28
|
+
* Updates or creates a new address for a user.
|
|
29
|
+
*
|
|
30
|
+
* @param {IUserAddressParams} params - The parameters for updating or creating an address.
|
|
31
|
+
* @returns {Promise<IApiResponseWithData<IUserAddress>>} A promise that resolves to the updated or created address.
|
|
32
|
+
* @throws {Error} If the address update request fails or if required parameters are missing.
|
|
33
|
+
*/
|
|
34
|
+
updateAddress(params: IUserAddressParams): Promise<IApiResponseWithData<IUserAddress>>;
|
|
35
|
+
/**
|
|
36
|
+
* Purges an address for a user.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} addressId - The ID of the address to purge.
|
|
39
|
+
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
|
|
40
|
+
* @throws {Error} If the address purge request fails or if the address ID is not provided.
|
|
41
|
+
*/
|
|
42
|
+
purgeAddress(addressId: string): Promise<IApiResponseWithData<IPurgeResponse>>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ENUM_BEER, ENUM_FOOD, ENUM_MERCHANDISE, ENUM_NON_ALCOHOLIC, ENUM_READY_TO_DRINK, ENUM_SPIRITS, ENUM_WINE, LIQUID_COMMERCE_ENV } from './enums';
|
|
2
|
+
export interface ICoreParams {
|
|
3
|
+
refresh?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface IAuthResponse {
|
|
6
|
+
auth?: IAuthResponse;
|
|
7
|
+
}
|
|
8
|
+
export interface IResponseMetadata {
|
|
9
|
+
languages: string[];
|
|
10
|
+
timestamp: number;
|
|
11
|
+
timezone: string;
|
|
12
|
+
requestId: string;
|
|
13
|
+
path: string;
|
|
14
|
+
version: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IApiResponseBase extends IAuthResponse {
|
|
17
|
+
statusCode: number;
|
|
18
|
+
message: string;
|
|
19
|
+
metadata: IResponseMetadata;
|
|
20
|
+
}
|
|
21
|
+
export type IApiResponseWithData<T> = IApiResponseBase & {
|
|
22
|
+
data: T;
|
|
23
|
+
};
|
|
24
|
+
export type IApiResponseWithoutData<T> = IApiResponseBase & {
|
|
25
|
+
[K in keyof T]: T[K];
|
|
26
|
+
};
|
|
27
|
+
export type IApiResponse<T> = IApiResponseWithData<T> | IApiResponseWithoutData<T>;
|
|
28
|
+
export declare function isApiResponseWithData<T>(response: IApiResponse<T>): response is IApiResponseWithData<T>;
|
|
29
|
+
export interface ILiquidCommerceConfig {
|
|
30
|
+
googlePlacesApiKey: string;
|
|
31
|
+
env: LIQUID_COMMERCE_ENV;
|
|
32
|
+
baseUrl?: {
|
|
33
|
+
stage?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export type LiquidTaxonomy = ENUM_BEER | ENUM_FOOD | ENUM_MERCHANDISE | ENUM_NON_ALCOHOLIC | ENUM_READY_TO_DRINK | ENUM_SPIRITS | ENUM_WINE;
|