lightspeed-retail-sdk 2.0.9 → 2.0.10
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/LICENSE +20 -0
- package/README.md +1 -1
- package/index.cjs +36 -0
- package/index.mjs +47 -11
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright 2024, Darryl Morley
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
8
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
9
|
+
so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ 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.
|
|
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
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
package/index.cjs
CHANGED
|
@@ -641,6 +641,42 @@ class LightspeedRetailSDK {
|
|
|
641
641
|
return this.handleError("GET SALE ERROR", error);
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
|
+
|
|
645
|
+
// Fetch all Credit Accounts
|
|
646
|
+
async getGiftCards(relations) {
|
|
647
|
+
const options = {
|
|
648
|
+
url: `${this.baseUrl}/${this.accountID}/CreditAccount.json?giftCard=true`,
|
|
649
|
+
method: "GET",
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
const response = await this.getAllData(options);
|
|
656
|
+
return response;
|
|
657
|
+
} catch (error) {
|
|
658
|
+
return this.handleError("GET CREDIT ACCOUNTS ERROR", error);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Fetch a Credit Account by ID
|
|
663
|
+
async getGiftCard(id, relations) {
|
|
664
|
+
const options = {
|
|
665
|
+
url: `${this.baseUrl}/${this.accountID}/CreditAccount.json?giftCard=true&code=${id}`,
|
|
666
|
+
method: "GET",
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
if (!id) return this.handleError("You need to provide a gift card code");
|
|
670
|
+
|
|
671
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
672
|
+
|
|
673
|
+
try {
|
|
674
|
+
const response = await this.getAllData(options);
|
|
675
|
+
return response;
|
|
676
|
+
} catch (error) {
|
|
677
|
+
return this.handleError("GET CREDIT ACCOUNT ERROR", error);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
644
680
|
}
|
|
645
681
|
|
|
646
682
|
module.exports = LightspeedRetailSDK;
|
package/index.mjs
CHANGED
|
@@ -52,6 +52,17 @@ class LightspeedRetailSDK {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
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
|
+
|
|
55
66
|
// Update the last response
|
|
56
67
|
setLastResponse = (response) => (this.lastResponse = response);
|
|
57
68
|
|
|
@@ -178,17 +189,6 @@ class LightspeedRetailSDK {
|
|
|
178
189
|
return allData;
|
|
179
190
|
}
|
|
180
191
|
|
|
181
|
-
// Check if error is retryable
|
|
182
|
-
isRetryableError = (err) => {
|
|
183
|
-
if (!err.response) {
|
|
184
|
-
// No response (network error or timeout)
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Retry for server errors (500-599)
|
|
189
|
-
return err.response.status >= 500 && err.response.status <= 599;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
192
|
// Get customer by ID
|
|
193
193
|
async getCustomer(id, relations) {
|
|
194
194
|
const options = {
|
|
@@ -641,6 +641,42 @@ class LightspeedRetailSDK {
|
|
|
641
641
|
return this.handleError("GET SALE ERROR", error);
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
|
+
|
|
645
|
+
// Fetch all Credit Accounts
|
|
646
|
+
async getGiftCards(relations) {
|
|
647
|
+
const options = {
|
|
648
|
+
url: `${this.baseUrl}/${this.accountID}/CreditAccount.json?giftCard=true`,
|
|
649
|
+
method: "GET",
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
const response = await this.getAllData(options);
|
|
656
|
+
return response;
|
|
657
|
+
} catch (error) {
|
|
658
|
+
return this.handleError("GET CREDIT ACCOUNTS ERROR", error);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Fetch a Credit Account by ID
|
|
663
|
+
async getGiftCard(id, relations) {
|
|
664
|
+
const options = {
|
|
665
|
+
url: `${this.baseUrl}/${this.accountID}/CreditAccount.json?giftCard=true&code=${id}`,
|
|
666
|
+
method: "GET",
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
if (!id) return this.handleError("You need to provide a gift card code");
|
|
670
|
+
|
|
671
|
+
if (relations) options.url = options.url + `?load_relations=${relations}`;
|
|
672
|
+
|
|
673
|
+
try {
|
|
674
|
+
const response = await this.getAllData(options);
|
|
675
|
+
return response;
|
|
676
|
+
} catch (error) {
|
|
677
|
+
return this.handleError("GET CREDIT ACCOUNT ERROR", error);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
644
680
|
}
|
|
645
681
|
|
|
646
682
|
export default LightspeedRetailSDK;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightspeed-retail-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Another unofficial Lightspeed Retail API SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.cjs",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"author": "https://github.com/darrylmorley",
|
|
15
|
-
"license": "
|
|
15
|
+
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"axios": "^1.3.4",
|
|
18
18
|
"dotenv": "^16.4.4"
|