@djust-b2b/djust-front-sdk 1.10.2 → 1.11.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.
@@ -1,41 +1,108 @@
1
1
  "use strict";
2
+ /**
3
+ * @packageDocumentation
4
+ *
5
+ * @document documents/cart.md
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCart = getCart;
4
- exports.getCarts = getCarts;
5
- exports.deleteCart = deleteCart;
6
8
  exports.deleteCarts = deleteCarts;
9
+ exports.getCarts = getCarts;
7
10
  exports.createCart = createCart;
11
+ exports.deleteCart = deleteCart;
12
+ exports.getCart = getCart;
8
13
  exports.updateCart = updateCart;
9
14
  exports.initializeOrdersFromCart = initializeOrdersFromCart;
10
- exports.getCartLines = getCartLines;
11
15
  exports.deleteCartLines = deleteCartLines;
16
+ exports.getCartLines = getCartLines;
12
17
  exports.updateCartLines = updateCartLines;
13
18
  exports.updateCartLinesByVariant = updateCartLinesByVariant;
14
19
  const parameters_validation_1 = require("../../helpers/parameters-validation");
15
20
  const fetch_instance_1 = require("../../settings/fetch-instance");
16
21
  /**
17
- * Get cart
18
- * @param {GetCartParameters} params - The parameters for getting a cart
19
- * @returns {Promise<GetCartResponse>} The response containing the cart data
22
+ * CART ENDPOINT
20
23
  */
21
- async function getCart({ cartId, currency, nbFirstLines, }) {
22
- (0, parameters_validation_1.required)({ cartId, currency });
24
+ /**
25
+ * APICODE(cART135)
26
+ * Deletes all carts associated with the user.
27
+ *
28
+ * This function sends a request to delete all carts of the logged-in user.
29
+ *
30
+ * @returns {Promise<DeleteCartsResponse>} - An array of objects containing details about the deleted carts.
31
+ *
32
+ * @example
33
+ * #### input
34
+ * ```typescript
35
+ * const deletedCarts = await deleteCarts();
36
+ * ```
37
+ * #### output
38
+ * ```json
39
+ * [
40
+ * {
41
+ * "id": "cart1",
42
+ * "detail": "Deleted successfully"
43
+ * },
44
+ * {
45
+ * "id": "cart2",
46
+ * "detail": "Deleted successfully"
47
+ * }
48
+ * ]
49
+ * ```
50
+ */
51
+ async function deleteCarts() {
23
52
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
24
- method: "GET",
25
- path: `/v2/shop/carts/${cartId}`,
26
- params: {
27
- currency,
28
- nbFirstLines,
29
- },
53
+ method: "DELETE",
54
+ path: `/v2/shop/carts`,
30
55
  });
31
56
  return data;
32
57
  }
33
58
  /**
34
- * Get carts
35
- * @param {GetCartsParameters} params - The parameters for getting multiple carts
36
- * @returns {Promise<GetCartsResponse>} The response containing the carts data
59
+ * APICODE(cART550)
60
+ * Retrieves all active carts of the logged-in user.
61
+ *
62
+ * This function allows fetching the list of active carts based on the provided parameters.
63
+ *
64
+ * @param {GetCartsParameters} params - The parameters for retrieving the carts, including:
65
+ * #### currency - `string` | <strong style={{ color: 'red' }}>required</strong>
66
+ *
67
+ * The currency in which to display the carts.
68
+ * #### pageable - `object` | <strong style={{ color: 'red' }}>required</strong>
69
+ *
70
+ * The pagination parameters.
71
+ * #### status - `string[]` | <strong style={{ color: 'red' }}>required</strong>
72
+ *
73
+ * The status of the carts to retrieve.
74
+ * #### type - `string[]` | <strong style={{ color: 'red' }}>required</strong>
75
+ *
76
+ * The type of carts to retrieve.
77
+ *
78
+ * @returns {Promise<GetCartsResponse>} - An object containing the list of carts and pagination information.
79
+ *
80
+ * @example
81
+ * #### input
82
+ * ```typescript
83
+ * const carts = await getCarts({ currency: 'USD', pageable: { page: 1, size: 10 } });
84
+ * ```
85
+ * #### output
86
+ * ```json
87
+ * {
88
+ * carts: [
89
+ * {
90
+ * id: 'cart1',
91
+ * name: 'My Cart'
92
+ * },
93
+ * {
94
+ * id: 'cart2',
95
+ * name: 'Another Cart'
96
+ * }
97
+ * ],
98
+ * page: 1,
99
+ * size: 10,
100
+ * totalElement: 2
101
+ * }
102
+ * ```
37
103
  */
38
- async function getCarts({ currency, pageable, status, type, }) {
104
+ async function getCarts(params) {
105
+ const { currency, pageable, status, type } = params;
39
106
  (0, parameters_validation_1.required)({ currency, pageable });
40
107
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
41
108
  method: "GET",
@@ -50,11 +117,66 @@ async function getCarts({ currency, pageable, status, type, }) {
50
117
  return data;
51
118
  }
52
119
  /**
53
- * Delete cart
54
- * @param {DeleteCartParameters} params - The parameters for deleting a cart
55
- * @returns {Promise<void>} A promise that resolves when the cart is deleted
120
+ * APICODE(cART100)
121
+ * Creates a new cart.
122
+ *
123
+ * This function sends a request to create a new cart with the specified name.
124
+ *
125
+ * @param {CreateCartParameters} params - The parameters for creating the cart, including:
126
+ * #### name - `string` | <strong style={{ color: 'red' }}>required</strong>
127
+ *
128
+ * The name of the cart to create.
129
+ *
130
+ * @returns {Promise<GetCartResponse>} - A promise that resolves when the cart is created.
131
+ *
132
+ * @example
133
+ * #### input
134
+ * ```typescript
135
+ * await createCart({ name: 'New Cart' });
136
+ * ```
137
+ * #### output
138
+ * ```json
139
+ * {
140
+ * "message": "Cart created successfully"
141
+ * }
142
+ * ```
143
+ */
144
+ async function createCart(params) {
145
+ const { name } = params;
146
+ const { data } = await (0, fetch_instance_1.enhancedFetch)({
147
+ method: "POST",
148
+ path: `/v2/shop/carts`,
149
+ body: JSON.stringify({ name }),
150
+ });
151
+ return data;
152
+ }
153
+ /**
154
+ * APICODE(cART300)
155
+ * Deletes a specific cart.
156
+ *
157
+ * This function sends a request to delete the cart identified by its ID.
158
+ *
159
+ * @param {DeleteCartParameters} params - The parameters to identify the cart to delete, including:
160
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
161
+ *
162
+ * The ID of the cart to delete.
163
+ *
164
+ * @returns {Promise<void>} - A promise that resolves when the cart is deleted.
165
+ *
166
+ * @example
167
+ * #### input
168
+ * ```typescript
169
+ * await deleteCart({ cartId: 'cart1' });
170
+ * ```
171
+ * #### output
172
+ * ```json
173
+ * {
174
+ * "message": "Cart deleted successfully"
175
+ * }
176
+ * ```
56
177
  */
57
- async function deleteCart({ cartId, }) {
178
+ async function deleteCart(params) {
179
+ const { cartId } = params;
58
180
  (0, parameters_validation_1.required)({ cartId });
59
181
  (0, fetch_instance_1.enhancedFetch)({
60
182
  method: "DELETE",
@@ -62,34 +184,87 @@ async function deleteCart({ cartId, }) {
62
184
  });
63
185
  }
64
186
  /**
65
- * Delete carts
66
- * @returns {Promise<DeleteCartsResponse>} The response containing the delete carts data
187
+ * APICODE(cART500)
188
+ * Retrieves the details of a specific cart.
189
+ *
190
+ * This function allows fetching the information of a cart based on its ID.
191
+ *
192
+ * @param {GetCartParameters} params - The parameters for identifying the cart, including:
193
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
194
+ *
195
+ * The ID of the cart to retrieve.
196
+ * #### currency - `string` | <strong style={{ color: 'red' }}>required</strong>
197
+ *
198
+ * The currency in which to display the cart.
199
+ * #### nbFirstLines - `number[]`
200
+ *
201
+ * The number of lines to retrieve.
202
+ *
203
+ * @returns {Promise<GetCartResponse>} - An object containing the details of the cart.
204
+ *
205
+ * @example
206
+ * #### input
207
+ * ```typescript
208
+ * const cartDetails = await getCart({ cartId: 'cart1', currency: 'USD' });
209
+ * ```
210
+ * #### output
211
+ * ```json
212
+ * {
213
+ * "id": "cart1",
214
+ * "name": "My Cart",
215
+ * "totalPrice": 100,
216
+ * "lines": [
217
+ * {
218
+ * "productName": "Product A",
219
+ * "quantity": 2
220
+ * }
221
+ * ]
222
+ * }
223
+ * ```
67
224
  */
68
- async function deleteCarts() {
225
+ async function getCart(params) {
226
+ const { cartId, currency, nbFirstLines } = params;
227
+ (0, parameters_validation_1.required)({ cartId, currency });
69
228
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
70
- method: "DELETE",
71
- path: `/v2/shop/carts`,
229
+ method: "GET",
230
+ path: `/v2/shop/carts/${cartId}`,
231
+ params: {
232
+ currency,
233
+ nbFirstLines,
234
+ },
72
235
  });
73
236
  return data;
74
237
  }
75
238
  /**
76
- * Create cart
77
- * @param {CreateCartParameters} params - The parameters for creating a cart
78
- * @returns {Promise<void>} A promise that resolves when the cart is created
79
- */
80
- async function createCart({ name, }) {
81
- (0, fetch_instance_1.enhancedFetch)({
82
- method: "POST",
83
- path: `/v2/shop/carts`,
84
- body: JSON.stringify({ name }),
85
- });
86
- }
87
- /**
88
- * Update cart
89
- * @param {UpdateCartParameters} params - The parameters for updating a cart
90
- * @returns {Promise<void>} A promise that resolves when the cart is updated
239
+ * APICODE(cART200)
240
+ * Updates an existing cart.
241
+ *
242
+ * This function sends a request to update the name of a cart identified by its ID.
243
+ *
244
+ * @param {UpdateCartParameters} params - The parameters for updating the cart, including:
245
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
246
+ *
247
+ * The ID of the cart to update.
248
+ * #### name - `string` | <strong style={{ color: 'red' }}>required</strong>
249
+ *
250
+ * The new name of the cart.
251
+ *
252
+ * @returns {Promise<void>} - A promise that resolves when the cart is updated.
253
+ *
254
+ * @example
255
+ * #### input
256
+ * ```typescript
257
+ * await updateCart({ cartId: 'cart1', name: 'Updated Cart Name' });
258
+ * ```
259
+ * #### output
260
+ * ```json
261
+ * {
262
+ * "message": "Cart updated successfully"
263
+ * }
264
+ * ```
91
265
  */
92
- async function updateCart({ cartId, name, }) {
266
+ async function updateCart(params) {
267
+ const { cartId, name } = params;
93
268
  (0, parameters_validation_1.required)({ cartId, name });
94
269
  (0, fetch_instance_1.enhancedFetch)({
95
270
  method: "PUT",
@@ -98,11 +273,32 @@ async function updateCart({ cartId, name, }) {
98
273
  });
99
274
  }
100
275
  /**
101
- * Initialize orders from cart
102
- * @param {InitializeOrdersFromCartParameters} params - The parameters for initializing orders from a cart
103
- * @returns {Promise<string>} The response containing the order data
276
+ * APICODE(cART101)
277
+ * Initializes orders from a cart.
278
+ *
279
+ * This function sends a request to initialize an order from a specified cart.
280
+ *
281
+ * @param {InitializeOrdersFromCartParameters} params - The parameters for initializing orders, including:
282
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
283
+ *
284
+ * The ID of the cart from which to initialize the order.
285
+ *
286
+ * @returns {Promise<string>} - The business ID of the commercial order if the initialization succeeds.
287
+ *
288
+ * @example
289
+ * #### input
290
+ * ```typescript
291
+ * const orderId = await initializeOrdersFromCart({ cartId: 'cart1' });
292
+ * ```
293
+ * #### output
294
+ * ```json
295
+ * {
296
+ * "orderId": "order123"
297
+ * }
298
+ * ```
104
299
  */
105
- async function initializeOrdersFromCart({ cartId, }) {
300
+ async function initializeOrdersFromCart(params) {
301
+ const { cartId } = params;
106
302
  (0, parameters_validation_1.required)({ cartId });
107
303
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
108
304
  method: "POST",
@@ -111,46 +307,154 @@ async function initializeOrdersFromCart({ cartId, }) {
111
307
  return data;
112
308
  }
113
309
  /**
114
- * Get cart lines
115
- * @param {GetCartLinesParameters} params - The parameters for getting cart lines
116
- * @returns {Promise<GetCartLinesResponse>} The response containing the cart lines data
310
+ * CARTLINES ENDPOINT
311
+ */
312
+ /**
313
+ * APICODE(cART350)
314
+ * Deletes lines from a cart.
315
+ *
316
+ * This function sends a request to delete specific lines from a cart.
317
+ *
318
+ * @param {DeleteCartLinesParameters} params - The parameters for deleting lines from the cart, including:
319
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
320
+ *
321
+ * The ID of the cart.
322
+ * #### `lineIdsToDelete` - `string[]` | <strong style={{ color: 'red' }}>required</strong>
323
+ *
324
+ * The IDs of the lines to delete.
325
+ *
326
+ * @returns {Promise<DeleteCartLinesResponse>} - An object containing information about the deleted lines.
327
+ *
328
+ * @example
329
+ * #### input
330
+ * ```typescript
331
+ * const response = await deleteCartLines({ cartId: 'cart1', lineIdsToDelete: ['line1', 'line2'] });
332
+ * ```
333
+ * #### output
334
+ * ```json
335
+ * {
336
+ * "singleWarningReportDto": []
337
+ * }
338
+ * ```
117
339
  */
118
- async function getCartLines({ cartId, currency, pageable, supplierId, productVariantId, offerPriceId, }) {
340
+ async function deleteCartLines(params) {
341
+ const { cartId, lineIdsToDelete } = params;
119
342
  (0, parameters_validation_1.required)({ cartId });
343
+ const body = lineIdsToDelete.map((lineId) => ({ offerPriceId: lineId }));
120
344
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
121
- method: "GET",
345
+ method: "DELETE",
122
346
  path: `/v2/shop/carts/${cartId}/lines`,
123
- params: {
124
- currency,
125
- pageable,
126
- supplierId,
127
- productVariantId,
128
- offerPriceId,
129
- },
347
+ body: JSON.stringify(body),
130
348
  });
131
349
  return data;
132
350
  }
133
351
  /**
134
- * Delete cart lines
135
- * @param {DeleteCartLinesParameters} params - The parameters for deleting cart lines
136
- * @returns {Promise<DeleteCartLinesResponse>} The response containing the delete cart lines data
352
+ * APICODE(cART551)
353
+ * Fetches the lines of a shopping cart based on the provided parameters.
354
+ *
355
+ * This function retrieves detailed information about the items (lines) in a shopping cart.
356
+ * It supports filtering by supplier, product variant, or offer price and handles pagination.
357
+ *
358
+ * @param {GetCartLinesParameters} params - The parameters for retrieving cart lines, including:
359
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
360
+ *
361
+ * The ID of the cart.
362
+ * #### currency - `string` | <strong style={{ color: 'red' }}>required</strong>
363
+ *
364
+ * The currency in which prices should be returned (e.g., "USD").
365
+ * #### pageable - `object` | <strong style={{ color: 'red' }}>required</strong>
366
+ *
367
+ * Pagination details, such as page number and size.
368
+ * #### supplierId - `string[]`
369
+ *
370
+ * Filter by a specific supplier's ID.
371
+ * #### productVariantId - `string[]`
372
+ *
373
+ * Filter by a specific product variant's ID.
374
+ * #### offerPriceId - `string[]`
375
+ *
376
+ * Filter by a specific offer price ID.
377
+ *
378
+ * @returns {Promise<GetCartLinesResponse>} - A promise resolving to the response containing cart lines information.
379
+ *
380
+ * @example
381
+ * #### input
382
+ * ```typescript
383
+ * const cartLines = await getCartLines({
384
+ * cartId: 'cart1',
385
+ * currency: 'USD',
386
+ * pageable: { page: 1, size: 10 },
387
+ * supplierId: ['supplier1'],
388
+ * productVariantId: ['variant1'],
389
+ * offerPriceId: ['offer1']
390
+ * });
391
+ * ```
392
+ * #### output
393
+ * ```json
394
+ * {
395
+ * "lines": [
396
+ * {
397
+ * "productName": "Product A",
398
+ * "quantity": 2,
399
+ * "price": 20
400
+ * }
401
+ * ],
402
+ * "totalItems": 1,
403
+ * "totalPages": 1
404
+ * }
405
+ * ```
137
406
  */
138
- async function deleteCartLines({ cartId, lineIdsToDelete, }) {
407
+ async function getCartLines(params) {
408
+ const { cartId, currency, pageable, supplierId, productVariantId, offerPriceId, } = params;
139
409
  (0, parameters_validation_1.required)({ cartId });
140
- const body = lineIdsToDelete.map((lineId) => ({ offerPriceId: lineId }));
141
410
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
142
- method: "DELETE",
411
+ method: "GET",
143
412
  path: `/v2/shop/carts/${cartId}/lines`,
144
- body: JSON.stringify(body),
413
+ params: {
414
+ currency,
415
+ pageable,
416
+ supplierId,
417
+ productVariantId,
418
+ offerPriceId,
419
+ },
145
420
  });
146
421
  return data;
147
422
  }
148
423
  /**
149
- * Update cart lines
150
- * @param {UpdateCartLinesParameters} params - The parameters for updating cart lines
151
- * @returns {Promise<UpdateCartLinesResponse>} The response containing the update cart lines data
424
+ * APICODE(cART150)
425
+ * Updates the lines of a cart.
426
+ *
427
+ * This function sends a request to update the lines of a specified cart.
428
+ *
429
+ * @param {UpdateCartLinesParameters} params - The parameters for updating the cart lines, including:
430
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
431
+ *
432
+ * The ID of the cart.
433
+ * #### `linesToUpdate` - `object[]` | <strong style={{ color: 'red' }}>required</strong>
434
+ *
435
+ * The lines to update with their details.
436
+ *
437
+ * @returns {Promise<UpdateCartLinesResponse>} - An object containing information about the updated lines.
438
+ *
439
+ * @example
440
+ * #### input
441
+ * ```typescript
442
+ * const response = await updateCartLines({
443
+ * cartId: 'cart1',
444
+ * linesToUpdate: [
445
+ * { offerPriceId: 'line1', quantity: 3, updateAction: 'update' }
446
+ * ],
447
+ * });
448
+ * ```
449
+ * #### output
450
+ * ```json
451
+ * {
452
+ * "singleWarningReportDto": []
453
+ * }
454
+ * ```
152
455
  */
153
- async function updateCartLines({ cartId, linesToUpdate, }) {
456
+ async function updateCartLines(params) {
457
+ const { cartId, linesToUpdate } = params;
154
458
  (0, parameters_validation_1.required)({ cartId, linesToUpdate });
155
459
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
156
460
  method: "PUT",
@@ -160,11 +464,40 @@ async function updateCartLines({ cartId, linesToUpdate, }) {
160
464
  return data;
161
465
  }
162
466
  /**
163
- * Update cart lines by variant
164
- * @param {UpdateCartLinesByVariantParameters} params - The parameters for updating cart lines by variant
165
- * @returns {Promise<UpdateCartLinesByVariantResponse>} The response containing the update cart lines by variant data
467
+ * APICODE(cART151)
468
+ * Updates the lines of a cart by variant.
469
+ *
470
+ * This function sends a request to update the lines of a cart based on the product variant.
471
+ *
472
+ * @param {UpdateCartLinesByVariantParameters} params - The parameters for updating the cart lines by variant, including:
473
+ * #### cartId - `string` | <strong style={{ color: 'red' }}>required</strong>
474
+ *
475
+ * The ID of the cart.
476
+ * #### linesToUpdate - `object[]` | <strong style={{ color: 'red' }}>required</strong>
477
+ *
478
+ * The lines to update with their details.
479
+ *
480
+ * @returns {Promise<UpdateCartLinesByVariantResponse>} - An object containing information about the updated lines by variant.
481
+ *
482
+ * @example
483
+ * #### input
484
+ * ```typescript
485
+ * const response = await updateCartLinesByVariant({
486
+ * cartId: 'cart1',
487
+ * linesToUpdate: [
488
+ * { offerPriceId: 'variant1', quantity: 2, updateAction: 'update' }
489
+ * ],
490
+ * });
491
+ * ```
492
+ * #### output
493
+ * ```json
494
+ * {
495
+ * "singleWarningReportDto": []
496
+ * }
497
+ * ```
166
498
  */
167
- async function updateCartLinesByVariant({ cartId, linesToUpdate, }) {
499
+ async function updateCartLinesByVariant(params) {
500
+ const { cartId, linesToUpdate } = params;
168
501
  (0, parameters_validation_1.required)({ cartId, linesToUpdate });
169
502
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
170
503
  method: "PUT",