@liquidcommerce/cloud-sdk 1.6.0 → 1.7.0

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.
Files changed (37) hide show
  1. package/README.md +154 -85
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.esm.js +1 -1
  4. package/dist/liquidcommerce-cloud-sdk.ssr.js +1 -1
  5. package/dist/types/core/authenticated.service.d.ts +6 -38
  6. package/dist/types/core/catalog-helper.service.d.ts +18 -5
  7. package/dist/types/core/checkout-helper.service.d.ts +9 -1
  8. package/dist/types/core/index.d.ts +3 -0
  9. package/dist/types/core/order-authenticated.service.d.ts +98 -0
  10. package/dist/types/core/order-singleton.service.d.ts +62 -0
  11. package/dist/types/core/payment-session-helper.service.d.ts +12 -0
  12. package/dist/types/core/singleton.service.d.ts +23 -3
  13. package/dist/types/core/utils.d.ts +48 -0
  14. package/dist/types/enums/enums.d.ts +70 -1
  15. package/dist/types/index.d.ts +2 -0
  16. package/dist/types/index.umd.d.ts +2 -2
  17. package/dist/types/interfaces/address.interface.d.ts +2 -0
  18. package/dist/types/interfaces/cart.interface.d.ts +5 -15
  19. package/dist/types/interfaces/catalog.interface.d.ts +54 -6
  20. package/dist/types/interfaces/checkout.interface.d.ts +40 -56
  21. package/dist/types/interfaces/index.d.ts +3 -0
  22. package/dist/types/interfaces/liquid-commerce-client.interface.d.ts +83 -4
  23. package/dist/types/interfaces/liquid-commerce-order-client.interface.d.ts +54 -0
  24. package/dist/types/interfaces/order.interface.d.ts +197 -0
  25. package/dist/types/interfaces/payment-element.interface.d.ts +88 -0
  26. package/dist/types/interfaces/payment.interface.d.ts +11 -1
  27. package/dist/types/interfaces/retailer.interface.d.ts +2 -0
  28. package/dist/types/interfaces/user.interface.d.ts +13 -9
  29. package/dist/types/liquid-commerce-order-client.d.ts +19 -0
  30. package/dist/types/liquid-commerce-payment-element.d.ts +10 -0
  31. package/dist/types/services/index.d.ts +3 -0
  32. package/dist/types/services/order.service.d.ts +15 -0
  33. package/dist/types/services/user.service.d.ts +22 -4
  34. package/dist/types/services/webhook.service.d.ts +14 -0
  35. package/dist/types/types.d.ts +9 -0
  36. package/package.json +4 -4
  37. package/umd/liquidcommerce-cloud-sdk.min.js +1 -1
package/README.md CHANGED
@@ -14,14 +14,17 @@ The LiquidCommerce Cloud SDK provides an easy way to interact with our APIs thro
14
14
 
15
15
  - [Installation](#installation)
16
16
  - [Configuration](#configuration)
17
- - [Usage](#usage)
18
- - [Services](#services)
17
+ - [API Key Authentication](#api-key-authentication)
18
+ - [Order API Authentication](#order-api-authentication)
19
+ - [Services & Usage](#services-and-usage)
19
20
  - [Address](#address)
20
21
  - [Catalog](#catalog)
21
22
  - [Cart](#cart)
22
23
  - [User](#user)
23
24
  - [Payment](#payment)
24
25
  - [Checkout](#checkout)
26
+ - [Order](#order)
27
+ - [Webhook](#webhook)
25
28
  - [Response Types](#response-types)
26
29
  - [Error Handling](#error-handling)
27
30
  - [Documentation](#documentation)
@@ -40,19 +43,40 @@ pnpm add @liquidcommerce/cloud-sdk
40
43
 
41
44
  ## Configuration
42
45
 
43
- The SDK requires configuration during initialization:
46
+ ### API Key Authentication
44
47
 
45
- ```typescript
46
- import { LiquidCommerce, LIQUID_COMMERCE_ENV } from '@liquidcommerce/cloud-sdk';
48
+ The LiquidCommerce API Key Authentication provides a secure method to obtain an access token for all other API calls to LiquidCommerce Services.
49
+
50
+ Example using LiquidCommerce client:
47
51
 
52
+ ```typescript
53
+ // The SDK automatically handles authentication
48
54
  const client = await LiquidCommerce('YOUR_LIQUIDCOMMERCE_API_KEY', {
49
55
  googlePlacesApiKey: 'YOUR_GOOGLE_PLACES_API_KEY', // Required for address services
50
- env: LIQUID_COMMERCE_ENV.STAGE // STAGE or PROD
56
+ env: LIQUID_COMMERCE_ENV.STAGE, // or PROD
51
57
  });
58
+ ```
59
+
60
+ [Click Here For Manual Authentication](https://docs.liquidcommerce.cloud/authentication-api-integration/get-access-token)
61
+
62
+ ### Order API Authentication
63
+
64
+ LiquidCommerce provides a separate authentication mechanism for Order API endpoints. The Order client uses Basic Authentication with a username and password.
65
+
66
+ Example using OrderLiquidCommerce client:
52
67
 
53
- await client.init();
68
+ ```typescript
69
+ const orderClient = await OrderLiquidCommerce({
70
+ userID: 'YOUR_ORDER_API_USER_ID',
71
+ password: 'YOUR_ORDER_API_PASSWORD',
72
+ env: LIQUID_COMMERCE_ENV.STAGE, // or PROD
73
+ });
54
74
  ```
55
75
 
76
+ [Click Here For Manual Authentication](https://docs.liquidcommerce.cloud/services/orders-api/authentication)
77
+
78
+ Note: Order authentication credentials are required to access Order API. The SDK will return appropriate authentication errors if these credentials are missing or invalid.
79
+
56
80
  ## Response Types
57
81
 
58
82
  All API responses follow a consistent structure:
@@ -73,7 +97,7 @@ interface ApiResponse<T> {
73
97
  }
74
98
  ```
75
99
 
76
- ## Services
100
+ ## Services and Usage
77
101
 
78
102
  ### Address
79
103
 
@@ -82,7 +106,7 @@ Services for address validation and lookup:
82
106
  ```typescript
83
107
  // Address autocompletion
84
108
  const autocompleteResponse = await client.address.autocomplete({
85
- input: '100 Madison Ave, New York'
109
+ input: '100 Madison Ave, New York',
86
110
  });
87
111
 
88
112
  // Response type: IApiResponseWithData<IAddressAutocompleteResult[]>
@@ -93,7 +117,7 @@ const autocompleteResponse = await client.address.autocomplete({
93
117
 
94
118
  // Get detailed address information
95
119
  const detailsResponse = await client.address.details({
96
- id: 'ChIJd8BlQ2BZwokRjMKtTjMezRw'
120
+ id: 'ChIJd8BlQ2BZwokRjMKtTjMezRw',
97
121
  });
98
122
 
99
123
  // Response type: IApiResponseWithData<IAddressDetailsResult>
@@ -103,6 +127,14 @@ const detailsResponse = await client.address.details({
103
127
  // lat: number;
104
128
  // long: number;
105
129
  // }
130
+ // address: {
131
+ // one: string,
132
+ // two: string,
133
+ // city": string,
134
+ // state: string,
135
+ // zip: string,
136
+ // country: "US"
137
+ // }
106
138
  // }
107
139
  ```
108
140
 
@@ -121,41 +153,43 @@ const availabilityResponse = await client.catalog.availability({
121
153
  one: '123 Main St',
122
154
  city: 'New York',
123
155
  state: 'NY',
124
- zip: '10001'
125
- }
156
+ zip: '10001',
157
+ },
126
158
  },
127
- shouldShowOffHours: true
159
+ shouldShowOffHours: true,
128
160
  });
129
161
 
130
162
  // Search catalog with filters
131
163
  const searchResponse = await client.catalog.search({
132
164
  search: 'whiskey',
165
+ pageToken: '',
166
+ entity: '',
133
167
  page: 1,
134
168
  perPage: 20,
135
169
  orderBy: ENUM_ORDER_BY.PRICE,
136
170
  orderDirection: ENUM_NAVIGATION_ORDER_DIRECTION_TYPE.ASC,
137
171
  filters: [
138
- {
139
- key: ENUM_FILTER_KEYS.CATEGORIES,
140
- values: [ENUM_SPIRITS.WHISKEY]
172
+ {
173
+ key: ENUM_FILTER_KEYS.CATEGORIES,
174
+ values: [ENUM_SPIRITS.WHISKEY],
141
175
  },
142
- {
143
- key: ENUM_FILTER_KEYS.PRICE,
144
- values: { min: 2000, max: 10000 } // Prices in cents
176
+ {
177
+ key: ENUM_FILTER_KEYS.PRICE,
178
+ values: { min: 2000, max: 10000 }, // Prices in cents
145
179
  },
146
180
  {
147
181
  key: ENUM_FILTER_KEYS.AVAILABILITY,
148
- values: ENUM_AVAILABILITY_VALUE.IN_STOCK
149
- }
182
+ values: ENUM_AVAILABILITY_VALUE.IN_STOCK,
183
+ },
150
184
  ],
151
185
  loc: {
152
186
  address: {
153
187
  one: '123 Main St',
154
188
  city: 'New York',
155
189
  state: 'NY',
156
- zip: '10001'
157
- }
158
- }
190
+ zip: '10001',
191
+ },
192
+ },
159
193
  });
160
194
  ```
161
195
 
@@ -180,18 +214,18 @@ const updatedCart = await client.cart.update({
180
214
  fulfillmentId: 'fulfillment_id',
181
215
  engravingLines: ['Line 1', 'Line 2'], // Optional
182
216
  scheduledFor: '2024-12-25', // Optional
183
- }
217
+ },
184
218
  ],
185
219
  loc: {
186
220
  address: {
187
221
  one: '123 Main St',
188
222
  city: 'New York',
189
223
  state: 'NY',
190
- zip: '10001'
191
- }
224
+ zip: '10001',
225
+ },
192
226
  },
193
227
  promoCode: 'DISCOUNT10', // Optional
194
- giftCards: ['GC123456'] // Optional
228
+ giftCards: ['GC123456'], // Optional
195
229
  });
196
230
  ```
197
231
 
@@ -202,13 +236,14 @@ User profile and preferences management:
202
236
  ```typescript
203
237
  // Create/update user session
204
238
  const userSession = await client.user.session({
205
- email: "user@example.com",
206
- firstName: "John",
207
- lastName: "Smith",
208
- phone: "2125551234",
209
- company: "Company Inc",
210
- profileImage: "https://...",
211
- birthDate: "1990-01-01"
239
+ email: 'user@example.com',
240
+ firstName: 'John',
241
+ lastName: 'Smith',
242
+ phone: '2125551234',
243
+ company: 'Company Inc',
244
+ profileImage: 'https://...',
245
+ birthDate: '1990-01-01',
246
+ id: 'user_id', // Existing user identifier (for updates only), email becomes optional
212
247
  });
213
248
 
214
249
  // Fetch user by ID or email
@@ -216,7 +251,7 @@ const userData = await client.user.fetch('user_id_or_email');
216
251
 
217
252
  // Address management
218
253
  const newAddress = await client.user.addAddress({
219
- customerId: 'customer_id',
254
+ userId: 'user_id',
220
255
  placesId: 'google_places_id', // Optional if providing address details
221
256
  one: '100 Madison St',
222
257
  two: 'Apt 4B',
@@ -225,9 +260,9 @@ const newAddress = await client.user.addAddress({
225
260
  zip: '10004',
226
261
  country: 'US',
227
262
  lat: 40.7128, // Optional
228
- long: -74.0060, // Optional
263
+ long: -74.006, // Optional
229
264
  type: ENUM_ADDRESS_TYPE.SHIPPING,
230
- isDefault: true
265
+ isDefault: true,
231
266
  });
232
267
 
233
268
  const updatedAddress = await client.user.updateAddress({
@@ -238,13 +273,13 @@ const updatedAddress = await client.user.updateAddress({
238
273
  const newPayment = await client.user.addPayment({
239
274
  customerId: 'customer_id',
240
275
  paymentMethodId: 'payment_method_id',
241
- isDefault: true
276
+ isDefault: true,
242
277
  });
243
278
 
244
279
  const updatedPayment = await client.user.updatePayment({
245
280
  customerId: 'customer_id',
246
281
  paymentMethodId: 'payment_method_id',
247
- isDefault: true // Required for updates
282
+ isDefault: true, // Required for updates
248
283
  });
249
284
 
250
285
  // Data removal
@@ -260,10 +295,11 @@ The payment system uses secure elements for handling sensitive payment data. Bef
260
295
  #### Prerequisites
261
296
 
262
297
  1. User Session Creation:
298
+
263
299
  ```typescript
264
300
  // First create or get a user session
265
301
  const userSession = await client.user.session({
266
- email: "user@example.com",
302
+ email: 'user@example.com',
267
303
  // ... other user details
268
304
  });
269
305
 
@@ -276,15 +312,15 @@ const { setupIntent, publicKey } = userSession.data.session;
276
312
  ```typescript
277
313
  // Initialize payment form using session credentials
278
314
  await client.payment.mount({
279
- clientSecret: userSession.data.session.setupIntent, // Required: from session
280
- key: userSession.data.session.publicKey, // Required: from session
281
- elementId: 'payment-element-container', // Your DOM element ID
282
- appearance: {
283
- theme: 'night' // 'default' | 'night' | 'flat'
315
+ clientSecret: userSession.data.session.setupIntent, // Required: from session
316
+ key: userSession.data.session.publicKey, // Required: from session
317
+ elementId: 'payment-element-container', // Your DOM element ID
318
+ appearance: {
319
+ theme: 'night', // 'stripe' | 'night' | 'flat'
320
+ },
321
+ elementOptions: {
322
+ layout: 'tabs', // 'tabs' | 'accordion' | 'auto'
284
323
  },
285
- elementOptions: {
286
- layout: 'tabs' // 'tabs' | 'accordion' | 'auto'
287
- }
288
324
  });
289
325
 
290
326
  // Monitor payment element state
@@ -327,11 +363,12 @@ client.payment.destroy();
327
363
  #### Best Practices
328
364
 
329
365
  1. **Error Handling**: Always implement proper error handling:
366
+
330
367
  ```typescript
331
368
  try {
332
369
  const token = await client.payment.generateToken();
333
370
  if ('error' in token) {
334
- switch(token.error.type) {
371
+ switch (token.error.type) {
335
372
  case 'validation_error':
336
373
  // Handle invalid card data
337
374
  break;
@@ -352,12 +389,14 @@ try {
352
389
  ```
353
390
 
354
391
  2. **Cleanup**: Always clean up payment elements when done:
392
+
355
393
  - When navigation away from payment page
356
394
  - After successful payment
357
395
  - After failed payment attempt
358
396
  - Before unmounting payment component
359
397
 
360
398
  3. **Event Handling**: Monitor element state for better user experience:
399
+
361
400
  ```typescript
362
401
  client.payment.subscribe('change', (event) => {
363
402
  // Update UI based on validation state
@@ -374,6 +413,7 @@ client.payment.subscribe('loaderror', (event) => {
374
413
  #### Responsive Design
375
414
 
376
415
  The payment element automatically adapts to:
416
+
377
417
  - Mobile and desktop viewports
378
418
  - Right-to-left languages
379
419
  - Dark/light themes
@@ -383,7 +423,7 @@ The payment element automatically adapts to:
383
423
 
384
424
  When testing payments in staging environment, use these test cards:
385
425
 
386
- ```typescript
426
+ ```
387
427
  // Test Visa Card
388
428
  Card Number: 4242 4242 4242 4242
389
429
  Expiry: Any future date
@@ -408,6 +448,7 @@ ZIP: Any 5 digits
408
448
  These cards will be accepted in test mode and will simulate successful payments. They should only be used in the staging environment, never in production.
409
449
 
410
450
  **Important Notes:**
451
+
411
452
  - These cards work only in test/staging environment
412
453
  - Real cards will be declined in test mode
413
454
  - Test cards will be declined in production
@@ -425,59 +466,61 @@ Checkout process management:
425
466
  ```typescript
426
467
  // Prepare checkout
427
468
  const preparedCheckout = await client.checkout.prepare({
428
- cartId: "cart_id",
469
+ cartId: 'cart_id',
429
470
  customer: {
430
- id: "customer_id", // Optional
431
- email: "customer@example.com",
432
- firstName: "John",
433
- lastName: "Smith",
434
- phone: "2125551234",
435
- birthDate: "1990-01-01"
471
+ id: 'customer_id', // Optional
472
+ email: 'customer@example.com',
473
+ firstName: 'John',
474
+ lastName: 'Smith',
475
+ phone: '2125551234',
476
+ birthDate: '1990-01-01',
436
477
  },
437
478
  hasAgeVerify: true,
438
479
  billingAddress: {
439
- firstName: "John",
440
- lastName: "Smith",
441
- email: "billing@example.com",
442
- phone: "2125551234",
443
- one: "123 Main St",
444
- two: "Apt 4B",
445
- city: "New York",
446
- state: "NY",
447
- zip: "10001",
448
- country: "US"
480
+ firstName: 'John',
481
+ lastName: 'Smith',
482
+ email: 'billing@example.com',
483
+ phone: '2125551234',
484
+ one: '123 Main St',
485
+ two: 'Apt 4B',
486
+ city: 'New York',
487
+ state: 'NY',
488
+ zip: '10001',
489
+ country: 'US',
449
490
  },
450
491
  hasSubstitutionPolicy: true,
451
492
  isGift: true,
452
493
  billingSameAsShipping: false,
453
494
  giftOptions: {
454
- message: "Happy Birthday!",
495
+ message: 'Happy Birthday!',
455
496
  recipient: {
456
- name: "Jane Smith",
457
- email: "jane@example.com",
458
- phone: "2125555678"
459
- }
497
+ name: 'Jane Smith',
498
+ email: 'jane@example.com',
499
+ phone: '2125555678',
500
+ },
460
501
  },
461
502
  marketingPreferences: {
462
503
  canEmail: true,
463
- canSms: true
504
+ canSms: true,
464
505
  },
465
506
  deliveryTips: [
466
507
  {
467
- fulfillmentId: "fulfillment_id",
468
- tip: 500 // Amount in cents
469
- }
508
+ fulfillmentId: 'fulfillment_id',
509
+ tip: 500, // Amount in cents
510
+ },
470
511
  ],
471
512
  acceptedAccountCreation: true,
472
- scheduledDelivery: "2024-12-25T14:00:00Z"
513
+ scheduledDelivery: '2024-12-25T14:00:00Z',
514
+ promoCode: 'DISCOUNT10', // Optional
515
+ giftCards: ['GC123456'], // Optional
473
516
  });
474
517
 
475
518
  // Complete checkout
476
519
  const completedCheckout = await client.checkout.complete({
477
520
  token: preparedCheckout.token,
478
- payment: "payment_token"
521
+ payment: 'payment_id',
479
522
  });
480
- ```_
523
+ ```
481
524
 
482
525
  #### Checkout Payment
483
526
 
@@ -486,17 +529,17 @@ For direct checkout payments, the flow is similar but uses the checkout session:
486
529
  ```typescript
487
530
  // 1. First prepare the checkout
488
531
  const preparedCheckout = await client.checkout.prepare({
489
- cartId: "cart_id",
532
+ cartId: 'cart_id',
490
533
  // ... other checkout details
491
534
  });
492
535
 
493
536
  // 2. Initialize payment form with checkout data
494
537
  await client.payment.mount({
495
538
  clientSecret: preparedCheckout.payment.clientSecret, // From checkout prepare response
496
- key: preparedCheckout.payment.publicKey, // From checkout prepare response
539
+ key: preparedCheckout.payment.publicKey, // From checkout prepare response
497
540
  elementId: 'payment-element-container',
498
541
  appearance: { theme: 'night' },
499
- elementOptions: { layout: 'tabs' }
542
+ elementOptions: { layout: 'tabs' },
500
543
  });
501
544
 
502
545
  // 3. Handle payment element events
@@ -511,7 +554,7 @@ if (!('error' in tokenResult)) {
511
554
  // 5. Complete checkout with payment token
512
555
  const completedCheckout = await client.checkout.complete({
513
556
  token: preparedCheckout.token,
514
- payment: tokenResult.id
557
+ payment: tokenResult.id,
515
558
  });
516
559
  }
517
560
 
@@ -520,6 +563,30 @@ client.payment.unmount();
520
563
  client.payment.destroy();
521
564
  ```
522
565
 
566
+ ### Order
567
+
568
+ Order retrieval services:
569
+
570
+ ```typescript
571
+ // Fetch order details by ID or number
572
+ const orderResponse = await client.order.fetch(/* reference id or order number */);
573
+ ```
574
+
575
+ [Click here to access the docs for the order response structure](https://docs.liquidcommerce.cloud/types/order)
576
+
577
+ ### Webhook
578
+
579
+ Webhook test services:
580
+
581
+ ```typescript
582
+ // Test webhook endpoint
583
+ const webhookTestResult = await client.webhook.test(/* endpoint */);
584
+
585
+ // Response is a simple boolean indicating success or failure
586
+ // true = webhook test was successful
587
+ // false = webhook test failed
588
+ ```
589
+
523
590
  ## Error Handling
524
591
 
525
592
  The SDK throws errors for various scenarios. Always wrap SDK calls in try-catch blocks:
@@ -534,6 +601,7 @@ try {
534
601
  ```
535
602
 
536
603
  Common error scenarios:
604
+
537
605
  - Authentication failures
538
606
  - Invalid parameters
539
607
  - Network errors
@@ -544,10 +612,11 @@ Common error scenarios:
544
612
  ## Price Handling
545
613
 
546
614
  All monetary values in the SDK are handled in cents (the smallest currency unit). For example:
615
+
547
616
  - $10.00 is represented as 1000
548
617
  - $5.99 is represented as 599
549
618
  - $0.50 is represented as 50
550
619
 
551
620
  ## Documentation
552
621
 
553
- For more detailed information about each method and its parameters, please refer to our [official documentation](https://docs.liquidcommerce.cloud).
622
+ For more detailed information about each method and its parameters, please refer to our [official documentation](https://docs.liquidcommerce.cloud).