@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,597 @@
|
|
|
1
|
+
import type { IAddressAutocompleteParams, IAddressAutocompleteResult, IAddressDetailsParams, IAddressDetailsResult } from '../services/address.service';
|
|
2
|
+
import type { IAvailabilityParams, IAvailabilityResponse } from '../services/catalog.service';
|
|
3
|
+
import type { IApiResponseWithData, IApiResponseWithoutData, ILiquidCommerceConfig } from '../types';
|
|
4
|
+
import type { ICart, ICartUpdateParams } from './cart.interface';
|
|
5
|
+
import type { ICatalog, ICatalogParams } from './catalog.service.interface';
|
|
6
|
+
import type { ICheckoutCompleteParams, ICheckoutCompleteResponse, ICheckoutPrepareParams, ICheckoutPrepareResponse } from './checkout.interface';
|
|
7
|
+
import type { ILiquidPaymentConfig, ILiquidPaymentToken, IPaymentElementEventMap } from './payment.interface';
|
|
8
|
+
import type { IPurgeResponse, IUser, IUserAddress, IUserAddressParams, IUserSessionParams } from './user.interface';
|
|
9
|
+
/**
|
|
10
|
+
* Interface representing the LiquidCommerce client.
|
|
11
|
+
* Provides access to methods related to addresses, catalogs, carts, and initialization.
|
|
12
|
+
*
|
|
13
|
+
* @interface
|
|
14
|
+
*/
|
|
15
|
+
export interface ILiquidCommerceClient {
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the client by authenticating with the LiquidCommerce API.
|
|
18
|
+
* Should be called before making any API requests.
|
|
19
|
+
*
|
|
20
|
+
* @return {Promise<void>} - Resolves when the client is successfully initialized.
|
|
21
|
+
* @throws {Error} - Throws an error if initialization fails.
|
|
22
|
+
*/
|
|
23
|
+
init(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Provides methods for performing address autocompletion and retrieving address details.
|
|
26
|
+
* See {@link IAddressMethod} for more details on the available methods.
|
|
27
|
+
*/
|
|
28
|
+
address: IAddressMethod;
|
|
29
|
+
/**
|
|
30
|
+
* Provides methods for checking item availability and performing catalog searches.
|
|
31
|
+
* See {@link ICatalogMethod} for more details on the available methods.
|
|
32
|
+
*/
|
|
33
|
+
catalog: ICatalogMethod;
|
|
34
|
+
/**
|
|
35
|
+
* Provides methods for retrieving and updating cart data.
|
|
36
|
+
* See {@link ICartMethod} for more details on the available methods.
|
|
37
|
+
*/
|
|
38
|
+
cart: ICartMethod;
|
|
39
|
+
/**
|
|
40
|
+
* Represents a payment method for processing a payment.
|
|
41
|
+
* @type {IPaymentMethod} - The interface representing the payment method.
|
|
42
|
+
*/
|
|
43
|
+
payment: IPaymentMethod;
|
|
44
|
+
/**
|
|
45
|
+
* Represents a method of checking out items in a shopping system.
|
|
46
|
+
*
|
|
47
|
+
* @type {ICheckoutMethod} - The interface representing the checkout method.
|
|
48
|
+
*/
|
|
49
|
+
checkout: ICheckoutMethod;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type for the LiquidCommerceClient constructor.
|
|
53
|
+
* Used to define the expected constructor signature.
|
|
54
|
+
*
|
|
55
|
+
* @type {new (apiKey: string, config: ILiquidCommerceConfig) => ILiquidCommerceClient} ILiquidCommerceClientConstructor
|
|
56
|
+
*/
|
|
57
|
+
export type ILiquidCommerceClientConstructor = new (apiKey: string, config: ILiquidCommerceConfig) => ILiquidCommerceClient;
|
|
58
|
+
/**
|
|
59
|
+
* Interface for methods related to address operations, including autocompletion and address details retrieval.
|
|
60
|
+
*
|
|
61
|
+
* @interface
|
|
62
|
+
*/
|
|
63
|
+
export interface IAddressMethod {
|
|
64
|
+
/**
|
|
65
|
+
* Performs address autocompletion based on the provided parameters.
|
|
66
|
+
*
|
|
67
|
+
* @param {Omit<IAddressAutocompleteParams, 'key'>} params - The parameters for the autocomplete request, excluding the API key.
|
|
68
|
+
* @returns {Promise<IApiResponseWithData<IAddressAutocompleteResult[]>>} - A promise that resolves to an API response containing a list of autocomplete results.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
72
|
+
*
|
|
73
|
+
* try {
|
|
74
|
+
* const autocompleteResults = await liquidCommerce.address.autocomplete({
|
|
75
|
+
* input: '123 Main',
|
|
76
|
+
* refresh: false
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* console.log('Autocomplete results:', autocompleteResults.data);
|
|
80
|
+
* // This will log an array of IAddressAutocompleteResult objects
|
|
81
|
+
* } catch (error) {
|
|
82
|
+
* console.error('Address autocomplete failed:', error);
|
|
83
|
+
* }
|
|
84
|
+
* const liquidClient = await LiquidCommerce('your-api-key', {
|
|
85
|
+
* env: LIQUID_COMMERCE_ENV.STAGE,
|
|
86
|
+
* googlePlacesApiKey: 'your-google-places-api-key',
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* @throws {Error} - Throws an error if the autocompletion request fails or if authentication is unsuccessful.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link IAddressAutocompleteParams} for the structure of the autocomplete request parameters.
|
|
92
|
+
* @see {@link IAddressAutocompleteResult} for the structure of the autocomplete result data.
|
|
93
|
+
*/
|
|
94
|
+
autocomplete: (params: Omit<IAddressAutocompleteParams, 'key'>) => Promise<IApiResponseWithData<IAddressAutocompleteResult[]>>;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves address details based on the provided parameters.
|
|
97
|
+
*
|
|
98
|
+
* @param {Omit<IAddressDetailsParams, 'key'>} params - The parameters for the address details request, excluding the API key.
|
|
99
|
+
* @returns {Promise<IApiResponseWithData<IAddressDetailsResult>>} - A promise that resolves to an API response containing address details.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
103
|
+
*
|
|
104
|
+
* try {
|
|
105
|
+
* const addressDetails = await liquidCommerce.address.details({
|
|
106
|
+
* id: 'ChIJd8BlQ2BZwokRjMKtTjMezRw',
|
|
107
|
+
* refresh: true
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* console.log('Address details:', addressDetails.data);
|
|
111
|
+
* // This will log an IAddressDetailsResult object
|
|
112
|
+
* } catch (error) {
|
|
113
|
+
* console.error('Address details retrieval failed:', error);
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* @throws {Error} - Throws an error if the address details request fails or if authentication is unsuccessful.
|
|
117
|
+
*
|
|
118
|
+
* @see {@link IAddressDetailsParams} for the structure of the details request parameters.
|
|
119
|
+
* @see {@link IAddressDetailsResult} for the structure of the address details result data.
|
|
120
|
+
*/
|
|
121
|
+
details: (params: Omit<IAddressDetailsParams, 'key'>) => Promise<IApiResponseWithData<IAddressDetailsResult>>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Interface for methods related to catalog operations, including item availability checks and catalog searches.
|
|
125
|
+
*
|
|
126
|
+
* @interface
|
|
127
|
+
*/
|
|
128
|
+
export interface ICatalogMethod {
|
|
129
|
+
/**
|
|
130
|
+
* Checks the availability of a specific item in the catalog.
|
|
131
|
+
*
|
|
132
|
+
* @param {IAvailabilityParams} params - The parameters for the availability request.
|
|
133
|
+
* @return {Promise<IApiResponseWithoutData<IAvailabilityResponse>>} - A promise that resolves to an API response object containing availability information.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
137
|
+
*
|
|
138
|
+
* try {
|
|
139
|
+
* const availabilityResponse = await liquidCommerce.catalog.availability({
|
|
140
|
+
* upcs: ['123456789012', '210987654321'],
|
|
141
|
+
* loc: {
|
|
142
|
+
* address: {
|
|
143
|
+
* one: '123 Main St',
|
|
144
|
+
* city: 'New York',
|
|
145
|
+
* state: 'NY',
|
|
146
|
+
* zip: '10001'
|
|
147
|
+
* }
|
|
148
|
+
* },
|
|
149
|
+
* shouldShowOffHours: true,
|
|
150
|
+
* refresh: false
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* console.log('Availability results:', availabilityResponse);
|
|
154
|
+
* // This will log an IAvailabilityResponse object
|
|
155
|
+
* } catch (error) {
|
|
156
|
+
* console.error('Availability check failed:', error);
|
|
157
|
+
* }
|
|
158
|
+
*
|
|
159
|
+
* @throws {Error} - Throws an error if the availability request fails.
|
|
160
|
+
*
|
|
161
|
+
* @see {@link IAvailabilityParams} for the structure of the availability request parameters.
|
|
162
|
+
* @see {@link IAvailabilityResponse} for the structure of the availability response.
|
|
163
|
+
*/
|
|
164
|
+
availability: (params: IAvailabilityParams) => Promise<IApiResponseWithoutData<IAvailabilityResponse>>;
|
|
165
|
+
/**
|
|
166
|
+
* Searches the catalog based on the provided parameters.
|
|
167
|
+
*
|
|
168
|
+
* @param {ICatalogParams} params - The search parameters.
|
|
169
|
+
* @return {Promise<IApiResponseWithoutData<ICatalog>>} - A promise that resolves to an API response object containing catalog search results.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
173
|
+
*
|
|
174
|
+
* try {
|
|
175
|
+
* const searchResults = await liquidCommerce.catalog.search({
|
|
176
|
+
* search: 'whiskey',
|
|
177
|
+
* pageToken: '',
|
|
178
|
+
* page: 1,
|
|
179
|
+
* perPage: 20,
|
|
180
|
+
* orderBy: ENUM_ORDER_BY.PRICE,
|
|
181
|
+
* orderDirection: ENUM_NAVIGATION_ORDER_DIRECTION_TYPE.ASC,
|
|
182
|
+
* filters: [
|
|
183
|
+
* { key: ENUM_FILTER_KEYS.CATEGORIES, values: [ENUM_SPIRITS.WHISKEY] },
|
|
184
|
+
* { key: ENUM_FILTER_KEYS.PRICE, values: { min: 20, max: 100 } }
|
|
185
|
+
* ],
|
|
186
|
+
* loc: {
|
|
187
|
+
* address: {
|
|
188
|
+
* one: '123 Main St',
|
|
189
|
+
* city: 'New York',
|
|
190
|
+
* state: 'NY',
|
|
191
|
+
* zip: '10001'
|
|
192
|
+
* }
|
|
193
|
+
* }
|
|
194
|
+
* });
|
|
195
|
+
*
|
|
196
|
+
* console.log('Search results:', searchResults);
|
|
197
|
+
* // This will log an ICatalog object
|
|
198
|
+
* } catch (error) {
|
|
199
|
+
* console.error('Catalog search failed:', error);
|
|
200
|
+
* }
|
|
201
|
+
*
|
|
202
|
+
* @throws {Error} - Throws an error if the search request fails or if the parameters are invalid.
|
|
203
|
+
*
|
|
204
|
+
* @see {@link ICatalogParams} for the structure of the search request parameters.
|
|
205
|
+
* @see {@link ICatalog} for the structure of the catalog data returned.
|
|
206
|
+
*/
|
|
207
|
+
search: (params: ICatalogParams) => Promise<IApiResponseWithoutData<ICatalog>>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Interface for methods related to cart operations, including retrieving and updating cart data.
|
|
211
|
+
*
|
|
212
|
+
* @interface
|
|
213
|
+
*/
|
|
214
|
+
export interface ICartMethod {
|
|
215
|
+
/**
|
|
216
|
+
* Retrieves a cart by its ID, or returns a new cart if no ID is provided.
|
|
217
|
+
*
|
|
218
|
+
* @param {string} [id] - The ID of the cart to retrieve. If not provided, a new cart is returned.
|
|
219
|
+
* @return {Promise<IApiResponseWithoutData<ICart>>} - A promise that resolves to an API response containing the cart data.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
223
|
+
*
|
|
224
|
+
* try {
|
|
225
|
+
* // Get an existing cart
|
|
226
|
+
* const existingCart = await liquidCommerce.cart.get('existing_cart_id');
|
|
227
|
+
* console.log('Existing cart:', existingCart);
|
|
228
|
+
*
|
|
229
|
+
* // Get a new cart
|
|
230
|
+
* const newCart = await liquidCommerce.cart.get();
|
|
231
|
+
* console.log('New cart:', newCart);
|
|
232
|
+
*
|
|
233
|
+
* // Both will log an ICart object
|
|
234
|
+
* } catch (error) {
|
|
235
|
+
* console.error('Cart retrieval failed:', error);
|
|
236
|
+
* }
|
|
237
|
+
*
|
|
238
|
+
* @throws {Error} - Throws an error if the cart retrieval request fails or if authentication is unsuccessful.
|
|
239
|
+
*
|
|
240
|
+
* @see {@link ICart} for the structure of the cart data returned.
|
|
241
|
+
*/
|
|
242
|
+
get: (id?: string) => Promise<IApiResponseWithoutData<ICart>>;
|
|
243
|
+
/**
|
|
244
|
+
* Updates the cart with the provided parameters.
|
|
245
|
+
*
|
|
246
|
+
* @param {ICartUpdateParams} params - The parameters required for updating the cart.
|
|
247
|
+
* @return {Promise<IApiResponseWithoutData<ICart>>} - A promise that resolves to an API response containing the updated cart data.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
251
|
+
*
|
|
252
|
+
* try {
|
|
253
|
+
* const updatedCart = await liquidCommerce.cart.update({
|
|
254
|
+
* id: 'existing_cart_id',
|
|
255
|
+
* items: [
|
|
256
|
+
* {
|
|
257
|
+
* id: 'item_id_1',
|
|
258
|
+
* partNumber: '123456789012_retailer_id',
|
|
259
|
+
* quantity: 2,
|
|
260
|
+
* engravingLines: ['Happy Birthday', 'John!'],
|
|
261
|
+
* fulfillmentId: 'fulfillment_id_1'
|
|
262
|
+
* },
|
|
263
|
+
* {
|
|
264
|
+
* id: 'item_id_2',
|
|
265
|
+
* partNumber: '210987654321_retailer_id',
|
|
266
|
+
* quantity: 1,
|
|
267
|
+
* fulfillmentId: 'fulfillment_id_2'
|
|
268
|
+
* }
|
|
269
|
+
* ],
|
|
270
|
+
* loc: {
|
|
271
|
+
* address: {
|
|
272
|
+
* one: '123 Main St',
|
|
273
|
+
* city: 'New York',
|
|
274
|
+
* state: 'NY',
|
|
275
|
+
* zip: '10001'
|
|
276
|
+
* }
|
|
277
|
+
* },
|
|
278
|
+
* refresh: true
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* console.log('Updated cart:', updatedCart);
|
|
282
|
+
* // This will log an ICart object
|
|
283
|
+
* } catch (error) {
|
|
284
|
+
* console.error('Cart update failed:', error);
|
|
285
|
+
* }
|
|
286
|
+
*
|
|
287
|
+
* @throws {Error} - Throws an error if the cart update request fails or if authentication is unsuccessful.
|
|
288
|
+
*
|
|
289
|
+
* @see {@link ICartUpdateParams} for the structure of the update request parameters.
|
|
290
|
+
* @see {@link ICart} for the structure of the cart data returned.
|
|
291
|
+
*/
|
|
292
|
+
update: (params: ICartUpdateParams) => Promise<IApiResponseWithoutData<ICart>>;
|
|
293
|
+
}
|
|
294
|
+
export interface IUserMethod {
|
|
295
|
+
/**
|
|
296
|
+
* Represents a session object used for user authentication and authorization.
|
|
297
|
+
*
|
|
298
|
+
* @param {IUserSessionParams} params - The parameters for creating a session.
|
|
299
|
+
* @returns {Promise<IApiResponseWithData<IUser>>} A Promise that resolves to the API response with user data.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
303
|
+
*
|
|
304
|
+
* try {
|
|
305
|
+
* const userSession = await liquidCommerce.user.session({
|
|
306
|
+
* email: "user@example.com",
|
|
307
|
+
* firstName: "John"
|
|
308
|
+
* });
|
|
309
|
+
*
|
|
310
|
+
* console.log('User session:', userSession?.data);
|
|
311
|
+
* } catch (error) {
|
|
312
|
+
* console.error('Failed to create/update user session:', error);
|
|
313
|
+
* }
|
|
314
|
+
*
|
|
315
|
+
* @throws {Error} - Throws an error if the sessions request fails or if authentication is unsuccessful.
|
|
316
|
+
*
|
|
317
|
+
* @see {@link IUserSessionParams} for the structure of the session request parameters.
|
|
318
|
+
* @see {@link IUser} for the structure of the user data returned.
|
|
319
|
+
*/
|
|
320
|
+
session: (params: IUserSessionParams) => Promise<IApiResponseWithData<IUser>>;
|
|
321
|
+
/**
|
|
322
|
+
* Purges a user's data from the system.
|
|
323
|
+
*
|
|
324
|
+
* @param {string} identifier - The user's ID or email.
|
|
325
|
+
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
329
|
+
*
|
|
330
|
+
* try {
|
|
331
|
+
* // Purge by user ID
|
|
332
|
+
* const purgeResponse1 = await liquidCommerce.user.purge('c1fbd454-a540-4f42-86e9-f87a98bf1812');
|
|
333
|
+
* console.log('User purge response:', purgeResponse1.data);
|
|
334
|
+
*
|
|
335
|
+
* // Purge by email
|
|
336
|
+
* const purgeResponse2 = await liquidCommerce.user.purge('user@example.com');
|
|
337
|
+
* console.log('User purge response:', purgeResponse2.data);
|
|
338
|
+
* } catch (error) {
|
|
339
|
+
* console.error('Failed to purge user data:', error);
|
|
340
|
+
* }
|
|
341
|
+
*
|
|
342
|
+
* @throws {Error} - Throws an error if the sessions request fails or if authentication is unsuccessful.
|
|
343
|
+
*
|
|
344
|
+
* @see {@link IPurgeResponse} for the structure of the user data returned.
|
|
345
|
+
*/
|
|
346
|
+
purge: (identifier: string) => Promise<IApiResponseWithData<IPurgeResponse>>;
|
|
347
|
+
/**
|
|
348
|
+
* Updates or creates a new address for a user.
|
|
349
|
+
*
|
|
350
|
+
* @param {IUserAddressParams} params - The parameters for updating or creating an address.
|
|
351
|
+
* @returns {Promise<IApiResponseWithData<IUserAddress>>} A promise that resolves to the updated or created address.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
355
|
+
*
|
|
356
|
+
* try {
|
|
357
|
+
* const addressResponse = await liquidCommerce.user.updateAddress({
|
|
358
|
+
* customerId: 'c1fbd454-a540-4f42-86e9-f87a98bf1812',
|
|
359
|
+
* one: '100 Madison St',
|
|
360
|
+
* two: 'Apt 1707',
|
|
361
|
+
* city: 'New York',
|
|
362
|
+
* state: 'NY',
|
|
363
|
+
* zip: '10004',
|
|
364
|
+
* type: 'shipping',
|
|
365
|
+
* isDefault: true
|
|
366
|
+
* });
|
|
367
|
+
*
|
|
368
|
+
* console.log('Updated/Created address:', addressResponse?.data);
|
|
369
|
+
* } catch (error) {
|
|
370
|
+
* console.error('Failed to update/create address:', error);
|
|
371
|
+
* }
|
|
372
|
+
*
|
|
373
|
+
* @throws {Error} - Throws an error if the sessions request fails or if authentication is unsuccessful.
|
|
374
|
+
*
|
|
375
|
+
* @see {@link IUserAddressParams} for the structure of the address update request parameters.
|
|
376
|
+
* @see {@link IUserAddress} for the structure of the user's address data returned.
|
|
377
|
+
*/
|
|
378
|
+
updateAddress: (params: IUserAddressParams) => Promise<IApiResponseWithData<IUserAddress>>;
|
|
379
|
+
/**
|
|
380
|
+
* Purges an address for a user.
|
|
381
|
+
*
|
|
382
|
+
* @param {string} addressId - The ID of the address to purge.
|
|
383
|
+
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
387
|
+
*
|
|
388
|
+
* try {
|
|
389
|
+
* const addressPurgeResponse = await liquidCommerce.user.purgeAddress('26af8958-0deb-44ec-b9fd-ca150b198e45');
|
|
390
|
+
*
|
|
391
|
+
* console.log('Address purge response:', addressPurgeResponse?.data);
|
|
392
|
+
* } catch (error) {
|
|
393
|
+
* console.error('Failed to purge address:', error);
|
|
394
|
+
* }
|
|
395
|
+
*
|
|
396
|
+
* @throws {Error} - Throws an error if the sessions request fails or if authentication is unsuccessful.
|
|
397
|
+
*
|
|
398
|
+
* @see {@link IPurgeResponse} for the structure of the user's purged data state.
|
|
399
|
+
*/
|
|
400
|
+
purgeAddress: (addressId: string) => Promise<IApiResponseWithData<IPurgeResponse>>;
|
|
401
|
+
}
|
|
402
|
+
export interface IPaymentMethod {
|
|
403
|
+
/**
|
|
404
|
+
* Mounts the payment element into the DOM.
|
|
405
|
+
*
|
|
406
|
+
* @param {ILiquidPaymentConfig} config - Configuration for the payment element.
|
|
407
|
+
* @returns {Promise<void>} A promise that resolves when the element is mounted.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
411
|
+
*
|
|
412
|
+
* try {
|
|
413
|
+
* await liquidCommerce.payment.mount({
|
|
414
|
+
* clientSecret: 'client_secret_from_server',
|
|
415
|
+
* elementId: 'payment-element-container',
|
|
416
|
+
* appearance: { theme: 'night' },
|
|
417
|
+
* elementOptions: { layout: 'tabs' }
|
|
418
|
+
* });
|
|
419
|
+
* console.log('Payment element mounted');
|
|
420
|
+
* } catch (error) {
|
|
421
|
+
* console.error('Failed to mount payment element:', error);
|
|
422
|
+
* }
|
|
423
|
+
*
|
|
424
|
+
* @throws {Error} - Throws an error if injection fails.
|
|
425
|
+
*/
|
|
426
|
+
mount(config: ILiquidPaymentConfig): Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Generates a payment token for the current payment information.
|
|
429
|
+
*
|
|
430
|
+
* @returns {Promise<ILiquidPaymentToken>} A promise that resolves to the payment token or an error.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
434
|
+
*
|
|
435
|
+
* try {
|
|
436
|
+
* const token = await liquidCommerce.payment.generateToken();
|
|
437
|
+
* if ('error' in token) {
|
|
438
|
+
* console.error('Failed to generate payment token:', token.error.message);
|
|
439
|
+
* } else {
|
|
440
|
+
* console.log('Generated payment token:', token);
|
|
441
|
+
* }
|
|
442
|
+
* } catch (error) {
|
|
443
|
+
* console.error('An unexpected error occurred:', error);
|
|
444
|
+
* }
|
|
445
|
+
*
|
|
446
|
+
* @throws {Error} - Throws an error if token generation fails.
|
|
447
|
+
*/
|
|
448
|
+
generateToken(): Promise<ILiquidPaymentToken>;
|
|
449
|
+
/**
|
|
450
|
+
* Subscribes to a specific event type on the payment element.
|
|
451
|
+
*
|
|
452
|
+
* @param {K} eventType - The type of event to subscribe to.
|
|
453
|
+
* @param {function} handler - The function to be called when the event occurs.
|
|
454
|
+
* @returns {void}
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
458
|
+
*
|
|
459
|
+
* try {
|
|
460
|
+
* liquidCommerce.payment.subscribe('change', (event) => {
|
|
461
|
+
* console.log('Payment element changed:', event);
|
|
462
|
+
* });
|
|
463
|
+
*
|
|
464
|
+
* liquidCommerce.payment.subscribe('ready', () => {
|
|
465
|
+
* console.log('Payment element is ready');
|
|
466
|
+
* });
|
|
467
|
+
* } catch (error) {
|
|
468
|
+
* console.error('Failed to subscribe to payment element event:', error);
|
|
469
|
+
* }
|
|
470
|
+
*
|
|
471
|
+
* @throws {Error} - Throws an error if the payment element has not been initialized.
|
|
472
|
+
*/
|
|
473
|
+
subscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler: (event: IPaymentElementEventMap[K]) => void): void;
|
|
474
|
+
/**
|
|
475
|
+
* Unsubscribes from a specific event type on the payment element.
|
|
476
|
+
*
|
|
477
|
+
* @param {K} eventType - The type of event to unsubscribe from.
|
|
478
|
+
* @param {function} [handler] - The function to be removed. If not provided, all handlers for the event type will be removed.
|
|
479
|
+
* @returns {void}
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
483
|
+
*
|
|
484
|
+
* const changeHandler = (event) => {
|
|
485
|
+
* console.log('Payment element changed:', event);
|
|
486
|
+
* };
|
|
487
|
+
*
|
|
488
|
+
* try {
|
|
489
|
+
* // Subscribe to the event
|
|
490
|
+
* liquidCommerce.payment.subscribe('change', changeHandler);
|
|
491
|
+
*
|
|
492
|
+
* // Later, unsubscribe from the event
|
|
493
|
+
* liquidCommerce.payment.unsubscribe('change', changeHandler);
|
|
494
|
+
*
|
|
495
|
+
* // Or, remove all handlers for the 'change' event
|
|
496
|
+
* liquidCommerce.payment.unsubscribe('change');
|
|
497
|
+
* } catch (error) {
|
|
498
|
+
* console.error('Failed to unsubscribe from payment element event:', error);
|
|
499
|
+
* }
|
|
500
|
+
*
|
|
501
|
+
* @throws {Error} - Throws an error if the payment element has not been initialized.
|
|
502
|
+
*/
|
|
503
|
+
unsubscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler?: (event: IPaymentElementEventMap[K]) => void): void;
|
|
504
|
+
}
|
|
505
|
+
export interface ICheckoutMethod {
|
|
506
|
+
/**
|
|
507
|
+
* Prepares a checkout based on the provided parameters.
|
|
508
|
+
*
|
|
509
|
+
* @param {ICheckoutPrepareParams} params - The parameters for preparing the checkout.
|
|
510
|
+
* @returns {Promise<IApiResponseWithoutData<ICheckoutPrepareResponse>>} A promise that resolves to an API response containing the prepared checkout data.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
514
|
+
*
|
|
515
|
+
* try {
|
|
516
|
+
* const preparedCheckout = await liquidCommerce.checkout.prepare({
|
|
517
|
+
* cartId: "65df5c***********512f", // create a new cart and add the cart id
|
|
518
|
+
* recipient: {
|
|
519
|
+
* firstName: "Jack",
|
|
520
|
+
* lastName: "Smith",
|
|
521
|
+
* email: "sample.jack@gmail.com",
|
|
522
|
+
* phone: "2129983315",
|
|
523
|
+
* birthDate: "11-22-1998",
|
|
524
|
+
* hasAgeVerify: false
|
|
525
|
+
* },
|
|
526
|
+
* billingAddress: {
|
|
527
|
+
* firstName: "Jenna",
|
|
528
|
+
* lastName: "Smith",
|
|
529
|
+
* email: "sample.jenna@gmail.com",
|
|
530
|
+
* phone: "2129983315",
|
|
531
|
+
* one: "251 Mercer St",
|
|
532
|
+
* two: "",
|
|
533
|
+
* city: "New York",
|
|
534
|
+
* state: "NY",
|
|
535
|
+
* zip: "10012"
|
|
536
|
+
* },
|
|
537
|
+
* hasSubstitutionPolicy: true,
|
|
538
|
+
* isGift: false,
|
|
539
|
+
* billingSameAsShipping: false,
|
|
540
|
+
* giftOptions: {
|
|
541
|
+
* message: "",
|
|
542
|
+
* recipient: {
|
|
543
|
+
* name: "",
|
|
544
|
+
* phone: "",
|
|
545
|
+
* email: ""
|
|
546
|
+
* }
|
|
547
|
+
* },
|
|
548
|
+
* marketingPreferences: {
|
|
549
|
+
* canEmail: true,
|
|
550
|
+
* canSms: true
|
|
551
|
+
* },
|
|
552
|
+
* deliveryTips: [
|
|
553
|
+
* {
|
|
554
|
+
* fulfillmentId: "6570c3e********1910c105",
|
|
555
|
+
* tip: 2500
|
|
556
|
+
* }
|
|
557
|
+
* ],
|
|
558
|
+
* });
|
|
559
|
+
*
|
|
560
|
+
* console.log('Prepared checkout:', preparedCheckout);
|
|
561
|
+
* } catch (error) {
|
|
562
|
+
* console.error('Checkout preparation failed:', error);
|
|
563
|
+
* }
|
|
564
|
+
*
|
|
565
|
+
* @throws {Error} Throws an error if the checkout preparation request fails or if authentication is unsuccessful.
|
|
566
|
+
*
|
|
567
|
+
* @see {@link ICheckoutPrepareParams} for the structure of the prepare request parameters.
|
|
568
|
+
* @see {@link ICheckoutPrepareResponse} for the structure of the prepared checkout data returned.
|
|
569
|
+
*/
|
|
570
|
+
prepare: (params: ICheckoutPrepareParams) => Promise<IApiResponseWithoutData<ICheckoutPrepareResponse>>;
|
|
571
|
+
/**
|
|
572
|
+
* Completes a checkout process with the provided token and payment information.
|
|
573
|
+
*
|
|
574
|
+
* @param {ICheckoutCompleteParams} params - The parameters for completing the checkout.
|
|
575
|
+
* @returns {Promise<IApiResponseWithoutData<ICheckoutCompleteResponse>>} A promise that resolves to the completed checkout data.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* const liquidCommerce = await LiquidCommerce(apiKey, config);
|
|
579
|
+
*
|
|
580
|
+
* try {
|
|
581
|
+
* const completedCheckout = await liquidCommerce.checkout.complete({
|
|
582
|
+
* token: 'checkout_token_123',
|
|
583
|
+
* payment: 'payment_id_456'
|
|
584
|
+
* });
|
|
585
|
+
* console.log('Completed checkout:', completedCheckout);
|
|
586
|
+
* } catch (error) {
|
|
587
|
+
* console.error('Checkout completion failed:', error);
|
|
588
|
+
* }
|
|
589
|
+
*
|
|
590
|
+
* @throws {Error} If the checkout completion request fails.
|
|
591
|
+
*
|
|
592
|
+
* @see {@link ICheckoutCompleteParams} for the structure of the complete request parameters.
|
|
593
|
+
* @see {@link ICheckoutCompleteResponse} for the structure of the complete checkout data returned.
|
|
594
|
+
*
|
|
595
|
+
*/
|
|
596
|
+
complete: (params: ICheckoutCompleteParams) => Promise<IApiResponseWithoutData<ICheckoutCompleteResponse>>;
|
|
597
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { StripePaymentElementChangeEvent } from '@stripe/stripe-js';
|
|
2
|
+
import type { StripeError } from '@stripe/stripe-js/dist/stripe-js/stripe';
|
|
3
|
+
export interface ILiquidPaymentElementOptions {
|
|
4
|
+
layout?: 'tabs' | 'accordion' | 'auto';
|
|
5
|
+
}
|
|
6
|
+
export interface ILiquidPaymentConfig {
|
|
7
|
+
clientSecret: string;
|
|
8
|
+
key: string;
|
|
9
|
+
elementId: string;
|
|
10
|
+
appearance?: {
|
|
11
|
+
theme?: 'default' | 'night' | 'flat';
|
|
12
|
+
};
|
|
13
|
+
elementOptions?: ILiquidPaymentElementOptions;
|
|
14
|
+
}
|
|
15
|
+
export interface ILiquidPaymentToken {
|
|
16
|
+
id?: string;
|
|
17
|
+
type?: string;
|
|
18
|
+
card?: {
|
|
19
|
+
brand: string;
|
|
20
|
+
country: string;
|
|
21
|
+
expMonth: number;
|
|
22
|
+
expYear: number;
|
|
23
|
+
last4: string;
|
|
24
|
+
funding: string;
|
|
25
|
+
};
|
|
26
|
+
created?: number;
|
|
27
|
+
error?: {
|
|
28
|
+
message: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ILiquidPaymentError {
|
|
33
|
+
type: 'validation_error' | 'api_error' | 'client_error';
|
|
34
|
+
message: string;
|
|
35
|
+
code?: string;
|
|
36
|
+
param?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface IPaymentElementEventMap {
|
|
39
|
+
change: StripePaymentElementChangeEvent;
|
|
40
|
+
ready: StripePaymentElementChangeEvent;
|
|
41
|
+
loaderror: {
|
|
42
|
+
elementType: 'payment';
|
|
43
|
+
error: StripeError;
|
|
44
|
+
};
|
|
45
|
+
loaderstart: {
|
|
46
|
+
elementType: 'payment';
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Interface for the payment provider.
|
|
51
|
+
* @interface
|
|
52
|
+
*/
|
|
53
|
+
export interface IPaymentProvider {
|
|
54
|
+
/**
|
|
55
|
+
* Mounts the payment configuration for the Liquid payment gateway.
|
|
56
|
+
*
|
|
57
|
+
* @param {ILiquidPaymentConfig} config - The configuration object for the Liquid payment gateway.
|
|
58
|
+
*
|
|
59
|
+
* @return {Promise<void>} A promise that resolves when the payment configuration is successfully mounted.
|
|
60
|
+
*/
|
|
61
|
+
mount(config: ILiquidPaymentConfig): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Generates a Liquid Payment Token.
|
|
64
|
+
*
|
|
65
|
+
* This method returns a Promise that resolves either with a LiquidPaymentToken object or an error object of type ILiquidPaymentError.
|
|
66
|
+
*
|
|
67
|
+
* @returns {Promise<ILiquidPaymentToken | ILiquidPaymentError>} - A Promise that resolves with a LiquidPaymentToken or an error object of type ILiquidPaymentError.
|
|
68
|
+
*/
|
|
69
|
+
generateToken(): Promise<ILiquidPaymentToken | ILiquidPaymentError>;
|
|
70
|
+
/**
|
|
71
|
+
* Subscribes a handler function to a specific event type in the IPaymentElementEventMap.
|
|
72
|
+
*
|
|
73
|
+
* @param eventType - The type of the event to subscribe to. Must be one of the keys in the IPaymentElementEventMap.
|
|
74
|
+
* @param handler - The handler function to be called when the specified event occurs. The function receives the event object as its argument.
|
|
75
|
+
*
|
|
76
|
+
* @return void
|
|
77
|
+
*/
|
|
78
|
+
subscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler: (event: IPaymentElementEventMap[K]) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Unsubscribes the specified event handler from the specified event type.
|
|
81
|
+
*
|
|
82
|
+
* @param eventType - The type of event to unsubscribe from.
|
|
83
|
+
* @param handler - (optional) The event handler function to unsubscribe. If not specified, all event handlers for the specified event type will be unsubscribed.
|
|
84
|
+
*
|
|
85
|
+
* @return void
|
|
86
|
+
*/
|
|
87
|
+
unsubscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler?: (event: IPaymentElementEventMap[K]) => void): void;
|
|
88
|
+
}
|