lightspeed-retail-sdk 2.0.10 → 2.0.11
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 +3 -1
- package/index.cjs +294 -14
- package/index.mjs +304 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ A JavaScript SDK for interacting with the Lightspeed Retail API. This SDK provid
|
|
|
4
4
|
|
|
5
5
|
## Update
|
|
6
6
|
|
|
7
|
-
This package has been enhanced to support both CommonJS and module usage. I have also added methods for fetching both a gift card, and all gift cards.
|
|
7
|
+
- This package has been enhanced to support both CommonJS and module usage. I have also added methods for fetching both a gift card, and all gift cards.
|
|
8
|
+
- I've added PUT and POST methods to many of the domains now.
|
|
8
9
|
|
|
9
10
|
## Features
|
|
10
11
|
|
|
@@ -70,6 +71,7 @@ console.log(item);
|
|
|
70
71
|
- `getSaleLinesByItem(itemID, relations)`: Retrieves sale lines for a specific item. Optionally, related data can be included.
|
|
71
72
|
- `getSaleLinesByItems(ids, startDate, endDate, relations)`: Retrieves sale lines for multiple items, filtered by date range. Optionally, related data can be included.
|
|
72
73
|
- `getSaleLinesByVendorID(id, startDate, endDate, relations)`: Fetches sale lines for a specific vendor, filtered by date range. Optionally, related data can be included.
|
|
74
|
+
- `getSpecialOrders(relations)`: Fetches special orders. Optionally, related data can be included.
|
|
73
75
|
|
|
74
76
|
## Contributing
|
|
75
77
|
|
package/index.cjs
CHANGED
|
@@ -69,7 +69,10 @@ class LightspeedRetailSDK {
|
|
|
69
69
|
const availableUnits = available - used;
|
|
70
70
|
if (requestUnits <= availableUnits) return 0;
|
|
71
71
|
|
|
72
|
-
const dripRate = parseInt(
|
|
72
|
+
const dripRate = parseInt(
|
|
73
|
+
this.lastResponse.headers["x-ls-api-drip-rate"],
|
|
74
|
+
10
|
|
75
|
+
);
|
|
73
76
|
|
|
74
77
|
// Check if dripRate is a valid number greater than 0
|
|
75
78
|
if (isNaN(dripRate) || dripRate <= 0) {
|
|
@@ -153,11 +156,17 @@ class LightspeedRetailSDK {
|
|
|
153
156
|
}
|
|
154
157
|
} catch (err) {
|
|
155
158
|
if (this.isRetryableError(err) && retries < this.maxRetries) {
|
|
156
|
-
this.handleError(
|
|
159
|
+
this.handleError(
|
|
160
|
+
`Network Error Retrying in 2 seconds...`,
|
|
161
|
+
err.message,
|
|
162
|
+
false
|
|
163
|
+
);
|
|
157
164
|
await sleep(2000);
|
|
158
165
|
return this.executeApiRequest(options, retries + 1);
|
|
159
166
|
} else {
|
|
160
|
-
this.handleError(
|
|
167
|
+
this.handleError(
|
|
168
|
+
`Failed Request statusText: ${err.response?.statusText}`
|
|
169
|
+
);
|
|
161
170
|
this.handleError(`Failed data: ${err.response?.data}`);
|
|
162
171
|
throw err;
|
|
163
172
|
}
|
|
@@ -225,6 +234,41 @@ class LightspeedRetailSDK {
|
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
|
|
237
|
+
async putCustomer(id, data) {
|
|
238
|
+
const options = {
|
|
239
|
+
url: `${this.baseUrl}/${this.accountID}/Customer/${id}.json`,
|
|
240
|
+
method: "PUT",
|
|
241
|
+
data,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
if (!id) return this.handleError("You need to provide a customerID");
|
|
245
|
+
if (!data) return this.handleError("You need to provide data");
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const response = await this.executeApiRequest(options);
|
|
249
|
+
return response;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return this.handleError("PUT CUSTOMER ERROR", error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async postCustomer(data) {
|
|
256
|
+
const options = {
|
|
257
|
+
url: `${this.baseUrl}/${this.accountID}/Customer.json`,
|
|
258
|
+
method: "POST",
|
|
259
|
+
data,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
if (!data) return this.handleError("You need to provide data");
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const response = await this.executeApiRequest(options);
|
|
266
|
+
return response;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
return this.handleError("POST CUSTOMER ERROR", error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
228
272
|
// Get item by ID
|
|
229
273
|
async getItem(id, relations) {
|
|
230
274
|
const options = {
|
|
@@ -282,6 +326,41 @@ class LightspeedRetailSDK {
|
|
|
282
326
|
}
|
|
283
327
|
}
|
|
284
328
|
|
|
329
|
+
async putItem(id, data) {
|
|
330
|
+
const options = {
|
|
331
|
+
url: `${this.baseUrl}/${this.accountID}/Item/${id}.json`,
|
|
332
|
+
method: "PUT",
|
|
333
|
+
data,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
if (!id) return this.handleError("You need to provide a itemID");
|
|
337
|
+
if (!data) return this.handleError("You need to provide data");
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
const response = await this.executeApiRequest(options);
|
|
341
|
+
return response;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return this.handleError("PUT ITEM ERROR", error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async postItem(data) {
|
|
348
|
+
const options = {
|
|
349
|
+
url: `${this.baseUrl}/${this.accountID}/Item.json`,
|
|
350
|
+
method: "POST",
|
|
351
|
+
data,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (!data) return this.handleError("You need to provide data");
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
const response = await this.executeApiRequest(options);
|
|
358
|
+
return response;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
return this.handleError("POST ITEM ERROR", error);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
285
364
|
// Get all items by vendor
|
|
286
365
|
async getvendorItems(vendorID, relations) {
|
|
287
366
|
const options = {
|
|
@@ -299,6 +378,25 @@ class LightspeedRetailSDK {
|
|
|
299
378
|
}
|
|
300
379
|
}
|
|
301
380
|
|
|
381
|
+
// Get Matrix Item by ID
|
|
382
|
+
async getMatrixItem(id, relations) {
|
|
383
|
+
const options = {
|
|
384
|
+
url: `${this.baseUrl}/${this.accountID}/ItemMatrix/${id}.json`,
|
|
385
|
+
method: "GET",
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
if (!id) return this.handleError("You need to provide a itemID");
|
|
389
|
+
|
|
390
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
const response = await this.getAllData(options);
|
|
394
|
+
return response;
|
|
395
|
+
} catch (error) {
|
|
396
|
+
return this.handleError("GET ITEM ERROR", error);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
302
400
|
// Get all Matrix Items
|
|
303
401
|
async getMatrixItems(relations) {
|
|
304
402
|
const options = {
|
|
@@ -316,22 +414,38 @@ class LightspeedRetailSDK {
|
|
|
316
414
|
}
|
|
317
415
|
}
|
|
318
416
|
|
|
319
|
-
|
|
320
|
-
async getMatrixItem(id, relations) {
|
|
417
|
+
async putMatrixItem(id, data) {
|
|
321
418
|
const options = {
|
|
322
419
|
url: `${this.baseUrl}/${this.accountID}/ItemMatrix/${id}.json`,
|
|
323
|
-
method: "
|
|
420
|
+
method: "PUT",
|
|
421
|
+
data,
|
|
324
422
|
};
|
|
325
423
|
|
|
326
424
|
if (!id) return this.handleError("You need to provide a itemID");
|
|
425
|
+
if (!data) return this.handleError("You need to provide data");
|
|
327
426
|
|
|
328
|
-
|
|
427
|
+
try {
|
|
428
|
+
const response = await this.executeApiRequest(options);
|
|
429
|
+
return response;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
return this.handleError("PUT ITEM ERROR", error);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async postMatrixItem(data) {
|
|
436
|
+
const options = {
|
|
437
|
+
url: `${this.baseUrl}/${this.accountID}/ItemMatrix.json`,
|
|
438
|
+
method: "POST",
|
|
439
|
+
data,
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
if (!data) return this.handleError("You need to provide data");
|
|
329
443
|
|
|
330
444
|
try {
|
|
331
|
-
const response = await this.
|
|
445
|
+
const response = await this.executeApiRequest(options);
|
|
332
446
|
return response;
|
|
333
447
|
} catch (error) {
|
|
334
|
-
return this.handleError("
|
|
448
|
+
return this.handleError("POST ITEM ERROR", error);
|
|
335
449
|
}
|
|
336
450
|
}
|
|
337
451
|
|
|
@@ -371,6 +485,41 @@ class LightspeedRetailSDK {
|
|
|
371
485
|
}
|
|
372
486
|
}
|
|
373
487
|
|
|
488
|
+
async putCategory(id, data) {
|
|
489
|
+
const options = {
|
|
490
|
+
url: `${this.baseUrl}/${this.accountID}/Category/${id}.json`,
|
|
491
|
+
method: "PUT",
|
|
492
|
+
data,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
if (!id) return this.handleError("You need to provide a categoryID");
|
|
496
|
+
if (!data) return this.handleError("You need to provide data");
|
|
497
|
+
|
|
498
|
+
try {
|
|
499
|
+
const response = await this.executeApiRequest(options);
|
|
500
|
+
return response;
|
|
501
|
+
} catch (error) {
|
|
502
|
+
return this.handleError("PUT CATEGORY ERROR", error);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async postCategory(data) {
|
|
507
|
+
const options = {
|
|
508
|
+
url: `${this.baseUrl}/${this.accountID}/Category.json`,
|
|
509
|
+
method: "POST",
|
|
510
|
+
data,
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
if (!data) return this.handleError("You need to provide data");
|
|
514
|
+
|
|
515
|
+
try {
|
|
516
|
+
const response = await this.executeApiRequest(options);
|
|
517
|
+
return response;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
return this.handleError("POST CATEGORY ERROR", error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
374
523
|
// Get Manufacturer by ID
|
|
375
524
|
async getManufacturer(id, relations) {
|
|
376
525
|
const options = {
|
|
@@ -407,6 +556,41 @@ class LightspeedRetailSDK {
|
|
|
407
556
|
}
|
|
408
557
|
}
|
|
409
558
|
|
|
559
|
+
async putManufacturer(id, data) {
|
|
560
|
+
const options = {
|
|
561
|
+
url: `${this.baseUrl}/${this.accountID}/Manufacturer/${id}.json`,
|
|
562
|
+
method: "PUT",
|
|
563
|
+
data,
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
if (!id) return this.handleError("You need to provide a manufacturerID");
|
|
567
|
+
if (!data) return this.handleError("You need to provide data");
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
const response = await this.executeApiRequest(options);
|
|
571
|
+
return response;
|
|
572
|
+
} catch (error) {
|
|
573
|
+
return this.handleError("PUT MANUFACTURER ERROR", error);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async postManufacturer(data) {
|
|
578
|
+
const options = {
|
|
579
|
+
url: `${this.baseUrl}/${this.accountID}/Manufacturer.json`,
|
|
580
|
+
method: "POST",
|
|
581
|
+
data,
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
if (!data) return this.handleError("You need to provide data");
|
|
585
|
+
|
|
586
|
+
try {
|
|
587
|
+
const response = await this.executeApiRequest(options);
|
|
588
|
+
return response;
|
|
589
|
+
} catch (error) {
|
|
590
|
+
return this.handleError("POST MANUFACTURER ERROR", error);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
410
594
|
// Get order by ID
|
|
411
595
|
async getOrder(id, relations) {
|
|
412
596
|
const options = {
|
|
@@ -517,6 +701,41 @@ class LightspeedRetailSDK {
|
|
|
517
701
|
}
|
|
518
702
|
}
|
|
519
703
|
|
|
704
|
+
async putVendor(id, data) {
|
|
705
|
+
const options = {
|
|
706
|
+
url: `${this.baseUrl}/${this.accountID}/Vendor/${id}.json`,
|
|
707
|
+
method: "PUT",
|
|
708
|
+
data,
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
if (!id) return this.handleError("You need to provide a vendorID");
|
|
712
|
+
if (!data) return this.handleError("You need to provide data");
|
|
713
|
+
|
|
714
|
+
try {
|
|
715
|
+
const response = await this.executeApiRequest(options);
|
|
716
|
+
return response;
|
|
717
|
+
} catch (error) {
|
|
718
|
+
return this.handleError("PUT VENDOR ERROR", error);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
async postVendor(data) {
|
|
723
|
+
const options = {
|
|
724
|
+
url: `${this.baseUrl}/${this.accountID}/Vendor.json`,
|
|
725
|
+
method: "POST",
|
|
726
|
+
data,
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
if (!data) return this.handleError("You need to provide data");
|
|
730
|
+
|
|
731
|
+
try {
|
|
732
|
+
const response = await this.executeApiRequest(options);
|
|
733
|
+
return response;
|
|
734
|
+
} catch (error) {
|
|
735
|
+
return this.handleError("POST VENDOR ERROR", error);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
520
739
|
// Get sale by ID
|
|
521
740
|
async getSale(id, relations) {
|
|
522
741
|
const options = {
|
|
@@ -569,6 +788,41 @@ class LightspeedRetailSDK {
|
|
|
569
788
|
}
|
|
570
789
|
}
|
|
571
790
|
|
|
791
|
+
async putSale(id, data) {
|
|
792
|
+
const options = {
|
|
793
|
+
url: `${this.baseUrl}/${this.accountID}/Sale/${id}.json`,
|
|
794
|
+
method: "PUT",
|
|
795
|
+
data,
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
if (!id) return this.handleError("You need to provide a saleID");
|
|
799
|
+
if (!data) return this.handleError("You need to provide data");
|
|
800
|
+
|
|
801
|
+
try {
|
|
802
|
+
const response = await this.executeApiRequest(options);
|
|
803
|
+
return response;
|
|
804
|
+
} catch (error) {
|
|
805
|
+
return this.handleError("PUT SALE ERROR", error);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
async postSale(data) {
|
|
810
|
+
const options = {
|
|
811
|
+
url: `${this.baseUrl}/${this.accountID}/Sale.json`,
|
|
812
|
+
method: "POST",
|
|
813
|
+
data,
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
if (!data) return this.handleError("You need to provide data");
|
|
817
|
+
|
|
818
|
+
try {
|
|
819
|
+
const response = await this.executeApiRequest(options);
|
|
820
|
+
return response;
|
|
821
|
+
} catch (error) {
|
|
822
|
+
return this.handleError("POST SALE ERROR", error);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
572
826
|
async getSaleLinesByItem(itemID, relations) {
|
|
573
827
|
const options = {
|
|
574
828
|
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=${itemID}`,
|
|
@@ -586,14 +840,20 @@ class LightspeedRetailSDK {
|
|
|
586
840
|
}
|
|
587
841
|
|
|
588
842
|
// Get sales lines by item ID's and date range
|
|
589
|
-
async getSaleLinesByItems(
|
|
843
|
+
async getSaleLinesByItems(
|
|
844
|
+
ids,
|
|
845
|
+
startDate = undefined,
|
|
846
|
+
endDate = undefined,
|
|
847
|
+
relations
|
|
848
|
+
) {
|
|
590
849
|
const options = {
|
|
591
850
|
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=IN,[${ids}]`,
|
|
592
851
|
method: "GET",
|
|
593
852
|
};
|
|
594
853
|
|
|
595
854
|
if (!ids) return this.handleError("You need to provide itemIDs");
|
|
596
|
-
if (startDate && !endDate)
|
|
855
|
+
if (startDate && !endDate)
|
|
856
|
+
return this.handleError("You need to provide an end date");
|
|
597
857
|
if (endDate && !startDate)
|
|
598
858
|
return this.handleError("You need to provide a start date");
|
|
599
859
|
|
|
@@ -601,7 +861,8 @@ class LightspeedRetailSDK {
|
|
|
601
861
|
|
|
602
862
|
if (startDate && endDate)
|
|
603
863
|
options.url =
|
|
604
|
-
options.url +
|
|
864
|
+
options.url +
|
|
865
|
+
`&timeStamp=%3E%3C%2C${startDate}%2C${endDate}&sort=timeStamp`;
|
|
605
866
|
|
|
606
867
|
try {
|
|
607
868
|
const response = await this.getAllData(options);
|
|
@@ -626,13 +887,15 @@ class LightspeedRetailSDK {
|
|
|
626
887
|
};
|
|
627
888
|
|
|
628
889
|
if (!id) return this.handleError("You need to provide a vendorID");
|
|
629
|
-
if (startDate && !endDate)
|
|
890
|
+
if (startDate && !endDate)
|
|
891
|
+
return this.handleError("You need to provide an end date");
|
|
630
892
|
if (endDate && !startDate)
|
|
631
893
|
return this.handleError("You need to provide a start date");
|
|
632
894
|
|
|
633
895
|
if (startDate && endDate)
|
|
634
896
|
options.url =
|
|
635
|
-
options.url +
|
|
897
|
+
options.url +
|
|
898
|
+
`&timeStamp=%3E%3C%2C${startDate}%2C${endDate}&sort=timeStamp`;
|
|
636
899
|
|
|
637
900
|
try {
|
|
638
901
|
const response = await this.getAllData(options);
|
|
@@ -677,6 +940,23 @@ class LightspeedRetailSDK {
|
|
|
677
940
|
return this.handleError("GET CREDIT ACCOUNT ERROR", error);
|
|
678
941
|
}
|
|
679
942
|
}
|
|
943
|
+
|
|
944
|
+
// Get special orders
|
|
945
|
+
async getSpecialOrders(relations) {
|
|
946
|
+
const options = {
|
|
947
|
+
url: `${this.baseUrl}/${this.accountID}/SpecialOrder.json?completed=0`,
|
|
948
|
+
method: "GET",
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
if (relations) options.url = options.url + `&load_relations=${relations}`;
|
|
952
|
+
|
|
953
|
+
try {
|
|
954
|
+
const response = await this.getAllData(options);
|
|
955
|
+
return response;
|
|
956
|
+
} catch (error) {
|
|
957
|
+
return this.handleError("GET SPECIAL ORDER ERROR", error);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
680
960
|
}
|
|
681
961
|
|
|
682
962
|
module.exports = LightspeedRetailSDK;
|
package/index.mjs
CHANGED
|
@@ -52,16 +52,16 @@ class LightspeedRetailSDK {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
// Check if error is retryable
|
|
56
|
+
isRetryableError = (err) => {
|
|
57
|
+
if (!err.response) {
|
|
58
|
+
// No response (network error or timeout)
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Retry for server errors (500-599)
|
|
63
|
+
return err.response.status >= 500 && err.response.status <= 599;
|
|
64
|
+
};
|
|
65
65
|
|
|
66
66
|
// Update the last response
|
|
67
67
|
setLastResponse = (response) => (this.lastResponse = response);
|
|
@@ -80,7 +80,10 @@ class LightspeedRetailSDK {
|
|
|
80
80
|
const availableUnits = available - used;
|
|
81
81
|
if (requestUnits <= availableUnits) return 0;
|
|
82
82
|
|
|
83
|
-
const dripRate = parseInt(
|
|
83
|
+
const dripRate = parseInt(
|
|
84
|
+
this.lastResponse.headers["x-ls-api-drip-rate"],
|
|
85
|
+
10
|
|
86
|
+
);
|
|
84
87
|
|
|
85
88
|
// Check if dripRate is a valid number greater than 0
|
|
86
89
|
if (isNaN(dripRate) || dripRate <= 0) {
|
|
@@ -164,11 +167,17 @@ class LightspeedRetailSDK {
|
|
|
164
167
|
}
|
|
165
168
|
} catch (err) {
|
|
166
169
|
if (this.isRetryableError(err) && retries < this.maxRetries) {
|
|
167
|
-
this.handleError(
|
|
170
|
+
this.handleError(
|
|
171
|
+
`Network Error Retrying in 2 seconds...`,
|
|
172
|
+
err.message,
|
|
173
|
+
false
|
|
174
|
+
);
|
|
168
175
|
await sleep(2000);
|
|
169
176
|
return this.executeApiRequest(options, retries + 1);
|
|
170
177
|
} else {
|
|
171
|
-
this.handleError(
|
|
178
|
+
this.handleError(
|
|
179
|
+
`Failed Request statusText: ${err.response?.statusText}`
|
|
180
|
+
);
|
|
172
181
|
this.handleError(`Failed data: ${err.response?.data}`);
|
|
173
182
|
throw err;
|
|
174
183
|
}
|
|
@@ -225,6 +234,41 @@ class LightspeedRetailSDK {
|
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
|
|
237
|
+
async putCustomer(id, data) {
|
|
238
|
+
const options = {
|
|
239
|
+
url: `${this.baseUrl}/${this.accountID}/Customer/${id}.json`,
|
|
240
|
+
method: "PUT",
|
|
241
|
+
data,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
if (!id) return this.handleError("You need to provide a customerID");
|
|
245
|
+
if (!data) return this.handleError("You need to provide data");
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const response = await this.executeApiRequest(options);
|
|
249
|
+
return response;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return this.handleError("PUT CUSTOMER ERROR", error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async postCustomer(data) {
|
|
256
|
+
const options = {
|
|
257
|
+
url: `${this.baseUrl}/${this.accountID}/Customer.json`,
|
|
258
|
+
method: "POST",
|
|
259
|
+
data,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
if (!data) return this.handleError("You need to provide data");
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const response = await this.executeApiRequest(options);
|
|
266
|
+
return response;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
return this.handleError("POST CUSTOMER ERROR", error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
228
272
|
// Get item by ID
|
|
229
273
|
async getItem(id, relations) {
|
|
230
274
|
const options = {
|
|
@@ -282,6 +326,41 @@ class LightspeedRetailSDK {
|
|
|
282
326
|
}
|
|
283
327
|
}
|
|
284
328
|
|
|
329
|
+
async putItem(id, data) {
|
|
330
|
+
const options = {
|
|
331
|
+
url: `${this.baseUrl}/${this.accountID}/Item/${id}.json`,
|
|
332
|
+
method: "PUT",
|
|
333
|
+
data,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
if (!id) return this.handleError("You need to provide a itemID");
|
|
337
|
+
if (!data) return this.handleError("You need to provide data");
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
const response = await this.executeApiRequest(options);
|
|
341
|
+
return response;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return this.handleError("PUT ITEM ERROR", error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async postItem(data) {
|
|
348
|
+
const options = {
|
|
349
|
+
url: `${this.baseUrl}/${this.accountID}/Item.json`,
|
|
350
|
+
method: "POST",
|
|
351
|
+
data,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (!data) return this.handleError("You need to provide data");
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
const response = await this.executeApiRequest(options);
|
|
358
|
+
return response;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
return this.handleError("POST ITEM ERROR", error);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
285
364
|
// Get all items by vendor
|
|
286
365
|
async getvendorItems(vendorID, relations) {
|
|
287
366
|
const options = {
|
|
@@ -299,6 +378,25 @@ class LightspeedRetailSDK {
|
|
|
299
378
|
}
|
|
300
379
|
}
|
|
301
380
|
|
|
381
|
+
// Get Matrix Item by ID
|
|
382
|
+
async getMatrixItem(id, relations) {
|
|
383
|
+
const options = {
|
|
384
|
+
url: `${this.baseUrl}/${this.accountID}/ItemMatrix/${id}.json`,
|
|
385
|
+
method: "GET",
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
if (!id) return this.handleError("You need to provide a itemID");
|
|
389
|
+
|
|
390
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
const response = await this.getAllData(options);
|
|
394
|
+
return response;
|
|
395
|
+
} catch (error) {
|
|
396
|
+
return this.handleError("GET ITEM ERROR", error);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
302
400
|
// Get all Matrix Items
|
|
303
401
|
async getMatrixItems(relations) {
|
|
304
402
|
const options = {
|
|
@@ -316,22 +414,38 @@ class LightspeedRetailSDK {
|
|
|
316
414
|
}
|
|
317
415
|
}
|
|
318
416
|
|
|
319
|
-
|
|
320
|
-
async getMatrixItem(id, relations) {
|
|
417
|
+
async putMatrixItem(id, data) {
|
|
321
418
|
const options = {
|
|
322
419
|
url: `${this.baseUrl}/${this.accountID}/ItemMatrix/${id}.json`,
|
|
323
|
-
method: "
|
|
420
|
+
method: "PUT",
|
|
421
|
+
data,
|
|
324
422
|
};
|
|
325
423
|
|
|
326
424
|
if (!id) return this.handleError("You need to provide a itemID");
|
|
425
|
+
if (!data) return this.handleError("You need to provide data");
|
|
327
426
|
|
|
328
|
-
|
|
427
|
+
try {
|
|
428
|
+
const response = await this.executeApiRequest(options);
|
|
429
|
+
return response;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
return this.handleError("PUT ITEM ERROR", error);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async postMatrixItem(data) {
|
|
436
|
+
const options = {
|
|
437
|
+
url: `${this.baseUrl}/${this.accountID}/ItemMatrix.json`,
|
|
438
|
+
method: "POST",
|
|
439
|
+
data,
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
if (!data) return this.handleError("You need to provide data");
|
|
329
443
|
|
|
330
444
|
try {
|
|
331
|
-
const response = await this.
|
|
445
|
+
const response = await this.executeApiRequest(options);
|
|
332
446
|
return response;
|
|
333
447
|
} catch (error) {
|
|
334
|
-
return this.handleError("
|
|
448
|
+
return this.handleError("POST ITEM ERROR", error);
|
|
335
449
|
}
|
|
336
450
|
}
|
|
337
451
|
|
|
@@ -371,6 +485,41 @@ class LightspeedRetailSDK {
|
|
|
371
485
|
}
|
|
372
486
|
}
|
|
373
487
|
|
|
488
|
+
async putCategory(id, data) {
|
|
489
|
+
const options = {
|
|
490
|
+
url: `${this.baseUrl}/${this.accountID}/Category/${id}.json`,
|
|
491
|
+
method: "PUT",
|
|
492
|
+
data,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
if (!id) return this.handleError("You need to provide a categoryID");
|
|
496
|
+
if (!data) return this.handleError("You need to provide data");
|
|
497
|
+
|
|
498
|
+
try {
|
|
499
|
+
const response = await this.executeApiRequest(options);
|
|
500
|
+
return response;
|
|
501
|
+
} catch (error) {
|
|
502
|
+
return this.handleError("PUT CATEGORY ERROR", error);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async postCategory(data) {
|
|
507
|
+
const options = {
|
|
508
|
+
url: `${this.baseUrl}/${this.accountID}/Category.json`,
|
|
509
|
+
method: "POST",
|
|
510
|
+
data,
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
if (!data) return this.handleError("You need to provide data");
|
|
514
|
+
|
|
515
|
+
try {
|
|
516
|
+
const response = await this.executeApiRequest(options);
|
|
517
|
+
return response;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
return this.handleError("POST CATEGORY ERROR", error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
374
523
|
// Get Manufacturer by ID
|
|
375
524
|
async getManufacturer(id, relations) {
|
|
376
525
|
const options = {
|
|
@@ -407,6 +556,41 @@ class LightspeedRetailSDK {
|
|
|
407
556
|
}
|
|
408
557
|
}
|
|
409
558
|
|
|
559
|
+
async putManufacturer(id, data) {
|
|
560
|
+
const options = {
|
|
561
|
+
url: `${this.baseUrl}/${this.accountID}/Manufacturer/${id}.json`,
|
|
562
|
+
method: "PUT",
|
|
563
|
+
data,
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
if (!id) return this.handleError("You need to provide a manufacturerID");
|
|
567
|
+
if (!data) return this.handleError("You need to provide data");
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
const response = await this.executeApiRequest(options);
|
|
571
|
+
return response;
|
|
572
|
+
} catch (error) {
|
|
573
|
+
return this.handleError("PUT MANUFACTURER ERROR", error);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async postManufacturer(data) {
|
|
578
|
+
const options = {
|
|
579
|
+
url: `${this.baseUrl}/${this.accountID}/Manufacturer.json`,
|
|
580
|
+
method: "POST",
|
|
581
|
+
data,
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
if (!data) return this.handleError("You need to provide data");
|
|
585
|
+
|
|
586
|
+
try {
|
|
587
|
+
const response = await this.executeApiRequest(options);
|
|
588
|
+
return response;
|
|
589
|
+
} catch (error) {
|
|
590
|
+
return this.handleError("POST MANUFACTURER ERROR", error);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
410
594
|
// Get order by ID
|
|
411
595
|
async getOrder(id, relations) {
|
|
412
596
|
const options = {
|
|
@@ -517,6 +701,41 @@ class LightspeedRetailSDK {
|
|
|
517
701
|
}
|
|
518
702
|
}
|
|
519
703
|
|
|
704
|
+
async putVendor(id, data) {
|
|
705
|
+
const options = {
|
|
706
|
+
url: `${this.baseUrl}/${this.accountID}/Vendor/${id}.json`,
|
|
707
|
+
method: "PUT",
|
|
708
|
+
data,
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
if (!id) return this.handleError("You need to provide a vendorID");
|
|
712
|
+
if (!data) return this.handleError("You need to provide data");
|
|
713
|
+
|
|
714
|
+
try {
|
|
715
|
+
const response = await this.executeApiRequest(options);
|
|
716
|
+
return response;
|
|
717
|
+
} catch (error) {
|
|
718
|
+
return this.handleError("PUT VENDOR ERROR", error);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
async postVendor(data) {
|
|
723
|
+
const options = {
|
|
724
|
+
url: `${this.baseUrl}/${this.accountID}/Vendor.json`,
|
|
725
|
+
method: "POST",
|
|
726
|
+
data,
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
if (!data) return this.handleError("You need to provide data");
|
|
730
|
+
|
|
731
|
+
try {
|
|
732
|
+
const response = await this.executeApiRequest(options);
|
|
733
|
+
return response;
|
|
734
|
+
} catch (error) {
|
|
735
|
+
return this.handleError("POST VENDOR ERROR", error);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
520
739
|
// Get sale by ID
|
|
521
740
|
async getSale(id, relations) {
|
|
522
741
|
const options = {
|
|
@@ -569,6 +788,41 @@ class LightspeedRetailSDK {
|
|
|
569
788
|
}
|
|
570
789
|
}
|
|
571
790
|
|
|
791
|
+
async putSale(id, data) {
|
|
792
|
+
const options = {
|
|
793
|
+
url: `${this.baseUrl}/${this.accountID}/Sale/${id}.json`,
|
|
794
|
+
method: "PUT",
|
|
795
|
+
data,
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
if (!id) return this.handleError("You need to provide a saleID");
|
|
799
|
+
if (!data) return this.handleError("You need to provide data");
|
|
800
|
+
|
|
801
|
+
try {
|
|
802
|
+
const response = await this.executeApiRequest(options);
|
|
803
|
+
return response;
|
|
804
|
+
} catch (error) {
|
|
805
|
+
return this.handleError("PUT SALE ERROR", error);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
async postSale(data) {
|
|
810
|
+
const options = {
|
|
811
|
+
url: `${this.baseUrl}/${this.accountID}/Sale.json`,
|
|
812
|
+
method: "POST",
|
|
813
|
+
data,
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
if (!data) return this.handleError("You need to provide data");
|
|
817
|
+
|
|
818
|
+
try {
|
|
819
|
+
const response = await this.executeApiRequest(options);
|
|
820
|
+
return response;
|
|
821
|
+
} catch (error) {
|
|
822
|
+
return this.handleError("POST SALE ERROR", error);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
572
826
|
async getSaleLinesByItem(itemID, relations) {
|
|
573
827
|
const options = {
|
|
574
828
|
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=${itemID}`,
|
|
@@ -586,14 +840,20 @@ class LightspeedRetailSDK {
|
|
|
586
840
|
}
|
|
587
841
|
|
|
588
842
|
// Get sales lines by item ID's and date range
|
|
589
|
-
async getSaleLinesByItems(
|
|
843
|
+
async getSaleLinesByItems(
|
|
844
|
+
ids,
|
|
845
|
+
startDate = undefined,
|
|
846
|
+
endDate = undefined,
|
|
847
|
+
relations
|
|
848
|
+
) {
|
|
590
849
|
const options = {
|
|
591
850
|
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=IN,[${ids}]`,
|
|
592
851
|
method: "GET",
|
|
593
852
|
};
|
|
594
853
|
|
|
595
854
|
if (!ids) return this.handleError("You need to provide itemIDs");
|
|
596
|
-
if (startDate && !endDate)
|
|
855
|
+
if (startDate && !endDate)
|
|
856
|
+
return this.handleError("You need to provide an end date");
|
|
597
857
|
if (endDate && !startDate)
|
|
598
858
|
return this.handleError("You need to provide a start date");
|
|
599
859
|
|
|
@@ -601,7 +861,8 @@ class LightspeedRetailSDK {
|
|
|
601
861
|
|
|
602
862
|
if (startDate && endDate)
|
|
603
863
|
options.url =
|
|
604
|
-
options.url +
|
|
864
|
+
options.url +
|
|
865
|
+
`&timeStamp=%3E%3C%2C${startDate}%2C${endDate}&sort=timeStamp`;
|
|
605
866
|
|
|
606
867
|
try {
|
|
607
868
|
const response = await this.getAllData(options);
|
|
@@ -626,13 +887,15 @@ class LightspeedRetailSDK {
|
|
|
626
887
|
};
|
|
627
888
|
|
|
628
889
|
if (!id) return this.handleError("You need to provide a vendorID");
|
|
629
|
-
if (startDate && !endDate)
|
|
890
|
+
if (startDate && !endDate)
|
|
891
|
+
return this.handleError("You need to provide an end date");
|
|
630
892
|
if (endDate && !startDate)
|
|
631
893
|
return this.handleError("You need to provide a start date");
|
|
632
894
|
|
|
633
895
|
if (startDate && endDate)
|
|
634
896
|
options.url =
|
|
635
|
-
options.url +
|
|
897
|
+
options.url +
|
|
898
|
+
`&timeStamp=%3E%3C%2C${startDate}%2C${endDate}&sort=timeStamp`;
|
|
636
899
|
|
|
637
900
|
try {
|
|
638
901
|
const response = await this.getAllData(options);
|
|
@@ -677,6 +940,23 @@ class LightspeedRetailSDK {
|
|
|
677
940
|
return this.handleError("GET CREDIT ACCOUNT ERROR", error);
|
|
678
941
|
}
|
|
679
942
|
}
|
|
943
|
+
|
|
944
|
+
// Get special orders
|
|
945
|
+
async getSpecialOrders(relations) {
|
|
946
|
+
const options = {
|
|
947
|
+
url: `${this.baseUrl}/${this.accountID}/SpecialOrder.json?completed=0`,
|
|
948
|
+
method: "GET",
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
if (relations) options.url = options.url + `&load_relations=${relations}`;
|
|
952
|
+
|
|
953
|
+
try {
|
|
954
|
+
const response = await this.getAllData(options);
|
|
955
|
+
return response;
|
|
956
|
+
} catch (error) {
|
|
957
|
+
return this.handleError("GET SPECIAL ORDER ERROR", error);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
680
960
|
}
|
|
681
961
|
|
|
682
962
|
export default LightspeedRetailSDK;
|