lightspeed-retail-sdk 1.0.9 → 1.0.12
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 +2 -0
- package/index.js +51 -17
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -73,7 +73,7 @@ class LightspeedRetailSDK {
|
|
|
73
73
|
"Content-Type": "application/json",
|
|
74
74
|
},
|
|
75
75
|
data: JSON.stringify(body),
|
|
76
|
-
}).catch((error) => console.error(error.
|
|
76
|
+
}).catch((error) => console.error(error.data));
|
|
77
77
|
|
|
78
78
|
const tokenData = await response.data;
|
|
79
79
|
const token = tokenData.access_token;
|
|
@@ -105,7 +105,7 @@ class LightspeedRetailSDK {
|
|
|
105
105
|
if (retries < this.maxRetries) {
|
|
106
106
|
console.log(`Error: ${err}, retrying in 2 seconds...`);
|
|
107
107
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
108
|
-
return await this.getResource(url, retries + 1);
|
|
108
|
+
return await this.getResource(options.url, retries + 1);
|
|
109
109
|
} else {
|
|
110
110
|
console.error(`Failed Request statusText: `, res.statusText);
|
|
111
111
|
console.log(`Failed data: `, response.data);
|
|
@@ -140,7 +140,7 @@ class LightspeedRetailSDK {
|
|
|
140
140
|
const response = await this.getAllData(options);
|
|
141
141
|
return response;
|
|
142
142
|
} catch (error) {
|
|
143
|
-
return this.handleError("GET CUSTOMERS ERROR", error
|
|
143
|
+
return this.handleError("GET CUSTOMERS ERROR", error);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -160,7 +160,7 @@ class LightspeedRetailSDK {
|
|
|
160
160
|
const response = await this.getAllData(options);
|
|
161
161
|
return response;
|
|
162
162
|
} catch (error) {
|
|
163
|
-
return this.handleError("GET ITEMS ERROR", error
|
|
163
|
+
return this.handleError("GET ITEMS ERROR", error);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -176,7 +176,7 @@ class LightspeedRetailSDK {
|
|
|
176
176
|
const response = await this.getAllData(options);
|
|
177
177
|
return response;
|
|
178
178
|
} catch (error) {
|
|
179
|
-
return this.handleError("GET ITEMS ERROR", error
|
|
179
|
+
return this.handleError("GET ITEMS ERROR", error);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -192,7 +192,7 @@ class LightspeedRetailSDK {
|
|
|
192
192
|
const response = await this.getAllData(options);
|
|
193
193
|
return response;
|
|
194
194
|
} catch (error) {
|
|
195
|
-
return this.handleError("GET ITEMS ERROR", error
|
|
195
|
+
return this.handleError("GET ITEMS ERROR", error);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -208,7 +208,7 @@ class LightspeedRetailSDK {
|
|
|
208
208
|
const response = await this.getAllData(options);
|
|
209
209
|
return response;
|
|
210
210
|
} catch (error) {
|
|
211
|
-
return this.handleError("GET ITEM ERROR", error
|
|
211
|
+
return this.handleError("GET ITEM ERROR", error);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -224,7 +224,7 @@ class LightspeedRetailSDK {
|
|
|
224
224
|
const response = await this.getAllData(options);
|
|
225
225
|
return response;
|
|
226
226
|
} catch (error) {
|
|
227
|
-
return this.handleError("GET CATEGORIES ERROR", error
|
|
227
|
+
return this.handleError("GET CATEGORIES ERROR", error);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -240,7 +240,7 @@ class LightspeedRetailSDK {
|
|
|
240
240
|
const response = await this.getAllData(options);
|
|
241
241
|
return response;
|
|
242
242
|
} catch (error) {
|
|
243
|
-
return this.handleError("GET CATEGORY ERROR", error
|
|
243
|
+
return this.handleError("GET CATEGORY ERROR", error);
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
|
|
@@ -256,7 +256,7 @@ class LightspeedRetailSDK {
|
|
|
256
256
|
const response = await this.getAllData(options);
|
|
257
257
|
return response;
|
|
258
258
|
} catch (error) {
|
|
259
|
-
return this.handleError("GET MANUFACTURERS ERROR", error
|
|
259
|
+
return this.handleError("GET MANUFACTURERS ERROR", error);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -272,7 +272,7 @@ class LightspeedRetailSDK {
|
|
|
272
272
|
const response = await this.getAllData(options);
|
|
273
273
|
return response;
|
|
274
274
|
} catch (error) {
|
|
275
|
-
return this.handleError("GET MANUFACTURER ERROR", error
|
|
275
|
+
return this.handleError("GET MANUFACTURER ERROR", error);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
|
|
@@ -288,7 +288,7 @@ class LightspeedRetailSDK {
|
|
|
288
288
|
const response = await this.getAllData(options);
|
|
289
289
|
return response;
|
|
290
290
|
} catch (error) {
|
|
291
|
-
return this.handleError("GET ORDERS ERROR", error
|
|
291
|
+
return this.handleError("GET ORDERS ERROR", error);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
@@ -304,7 +304,7 @@ class LightspeedRetailSDK {
|
|
|
304
304
|
const response = await this.getAllData(options);
|
|
305
305
|
return response;
|
|
306
306
|
} catch (error) {
|
|
307
|
-
return this.handleError("GET ORDER ERROR", error
|
|
307
|
+
return this.handleError("GET ORDER ERROR", error);
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
|
|
@@ -352,7 +352,7 @@ class LightspeedRetailSDK {
|
|
|
352
352
|
const response = await this.getAllData(options);
|
|
353
353
|
return response;
|
|
354
354
|
} catch (error) {
|
|
355
|
-
return this.handleError("GET VENDORS ERROR", error
|
|
355
|
+
return this.handleError("GET VENDORS ERROR", error);
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
|
|
@@ -368,7 +368,7 @@ class LightspeedRetailSDK {
|
|
|
368
368
|
const response = await this.getAllData(options);
|
|
369
369
|
return response;
|
|
370
370
|
} catch (error) {
|
|
371
|
-
return this.handleError("GET VENDOR ERROR", error
|
|
371
|
+
return this.handleError("GET VENDOR ERROR", error);
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
|
|
@@ -384,7 +384,7 @@ class LightspeedRetailSDK {
|
|
|
384
384
|
const response = await this.getAllData(options);
|
|
385
385
|
return response;
|
|
386
386
|
} catch (error) {
|
|
387
|
-
return this.handleError("GET SALES ERROR", error
|
|
387
|
+
return this.handleError("GET SALES ERROR", error);
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
|
|
@@ -400,7 +400,41 @@ class LightspeedRetailSDK {
|
|
|
400
400
|
const response = await this.getAllData(options);
|
|
401
401
|
return response;
|
|
402
402
|
} catch (error) {
|
|
403
|
-
return this.handleError("GET SALE ERROR", error
|
|
403
|
+
return this.handleError("GET SALE ERROR", error);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async getSaleLinesByItem(itemID, relations) {
|
|
408
|
+
const options = {
|
|
409
|
+
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=${itemID}`,
|
|
410
|
+
method: "GET",
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
if (relations) options.url = options.url + `&load_relations=${relations}`;
|
|
414
|
+
|
|
415
|
+
try {
|
|
416
|
+
const response = await this.getAllData(options);
|
|
417
|
+
return response;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
return this.handleError("GET SALE ERROR", error);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async getSaleLinesByItems(itemIDs, startDate = undefined, endDate = undefined) {
|
|
424
|
+
const options = {
|
|
425
|
+
url: `${this.baseUrl}/${this.accountID}/SaleLine.json?itemID=IN,[${itemIDs}]`,
|
|
426
|
+
method: "GET",
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
if (startDate && endDate)
|
|
430
|
+
options.url =
|
|
431
|
+
options.url + `&timeStamp=%3E%3C%2C${startDate}%2C${endDate}&sort=timeStamp`;
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
const response = await this.getAllData(options);
|
|
435
|
+
return response;
|
|
436
|
+
} catch (error) {
|
|
437
|
+
return this.handleError("GET SALE ERROR", error);
|
|
404
438
|
}
|
|
405
439
|
}
|
|
406
440
|
}
|