repzo 1.0.6 → 1.0.7

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/lib/index.js CHANGED
@@ -1,841 +1,1319 @@
1
- import axios from "axios";
2
- import { v4 as uuid } from "uuid";
3
- export default class Repzo {
4
- constructor(apiKey, options) {
5
- this.client = {
6
- _path: "/client",
7
- find: async (params) => {
8
- let res = await this._fetch(this.svAPIEndpoint, this.client._path, params);
9
- return res;
10
- },
11
- get: async (id, params) => {
12
- return await this._fetch(this.svAPIEndpoint, this.client._path + `/${id}`, params);
13
- },
14
- create: async (body) => {
15
- let res = await this._create(this.svAPIEndpoint, this.client._path, body);
16
- return res;
17
- },
18
- update: async (id, body) => {
19
- let res = await this._update(this.svAPIEndpoint, this.client._path + `/${id}`, body);
20
- return res;
21
- },
22
- remove: async (id) => {
23
- let res = await this._delete(this.svAPIEndpoint, this.client._path + `/${id}`);
24
- return res;
25
- },
26
- };
27
- this.product = {
28
- _path: "/product",
29
- find: async (params) => {
30
- let res = await this._fetch(this.svAPIEndpoint, this.product._path, params);
31
- return res;
32
- },
33
- get: async (id, params) => {
34
- return await this._fetch(this.svAPIEndpoint, this.product._path + `/${id}`, params);
35
- },
36
- create: async (body) => {
37
- let res = await this._create(this.svAPIEndpoint, this.product._path, body);
38
- return res;
39
- },
40
- update: async (id, body) => {
41
- let res = await this._update(this.svAPIEndpoint, this.product._path + `/${id}`, body);
42
- return res;
43
- },
44
- remove: async (id) => {
45
- let res = await this._delete(this.svAPIEndpoint, this.product._path + `/${id}`);
46
- return res;
47
- },
48
- };
49
- this.variant = {
50
- _path: "/variant",
51
- find: async (params) => {
52
- let res = await this._fetch(this.svAPIEndpoint, this.variant._path, params);
53
- return res;
54
- },
55
- get: async (id, params) => {
56
- return await this._fetch(this.svAPIEndpoint, this.variant._path + `/${id}`, params);
57
- },
58
- create: async (body) => {
59
- let res = await this._create(this.svAPIEndpoint, this.variant._path, body);
60
- return res;
61
- },
62
- update: async (id, body) => {
63
- let res = await this._update(this.svAPIEndpoint, this.variant._path + `/${id}`, body);
64
- return res;
65
- },
66
- remove: async (id) => {
67
- let res = await this._delete(this.svAPIEndpoint, this.variant._path + `/${id}`);
68
- return res;
69
- },
70
- };
71
- this.category = {
72
- _path: "/product-category",
73
- find: async (params) => {
74
- let res = await this._fetch(this.svAPIEndpoint, this.category._path, params);
75
- return res;
76
- },
77
- get: async (id) => {
78
- return await this._fetch(this.svAPIEndpoint, this.category._path + `/${id}`);
79
- },
80
- create: async (body) => {
81
- let res = await this._create(this.svAPIEndpoint, this.category._path, body);
82
- return res;
83
- },
84
- update: async (id, body) => {
85
- let res = await this._update(this.svAPIEndpoint, this.category._path + `/${id}`, body);
86
- return res;
87
- },
88
- remove: async (id) => {
89
- let res = await this._delete(this.svAPIEndpoint, this.category._path + `/${id}`);
90
- return res;
91
- },
92
- };
93
- this.sub_category = {
94
- _path: "/product-sub-category",
95
- find: async (params) => {
96
- let res = await this._fetch(this.svAPIEndpoint, this.sub_category._path, params);
97
- return res;
98
- },
99
- get: async (id, params) => {
100
- return await this._fetch(this.svAPIEndpoint, this.sub_category._path + `/${id}`, params);
101
- },
102
- create: async (body) => {
103
- let res = await this._create(this.svAPIEndpoint, this.sub_category._path, body);
104
- return res;
105
- },
106
- update: async (id, body) => {
107
- let res = await this._update(this.svAPIEndpoint, this.sub_category._path + `/${id}`, body);
108
- return res;
109
- },
110
- remove: async (id) => {
111
- let res = await this._delete(this.svAPIEndpoint, this.sub_category._path + `/${id}`);
112
- return res;
113
- },
114
- };
115
- this.brand = {
116
- _path: "/product-brand",
117
- find: async (params) => {
118
- let res = await this._fetch(this.svAPIEndpoint, this.brand._path, params);
119
- return res;
120
- },
121
- get: async (id) => {
122
- return await this._fetch(this.svAPIEndpoint, this.brand._path + `/${id}`);
123
- },
124
- create: async (body) => {
125
- let res = await this._create(this.svAPIEndpoint, this.brand._path, body);
126
- return res;
127
- },
128
- update: async (id, body) => {
129
- let res = await this._update(this.svAPIEndpoint, this.brand._path + `/${id}`, body);
130
- return res;
131
- },
132
- remove: async (id) => {
133
- let res = await this._delete(this.svAPIEndpoint, this.brand._path + `/${id}`);
134
- return res;
135
- },
136
- };
137
- this.product_group = {
138
- _path: "/product-group",
139
- find: async (params) => {
140
- let res = await this._fetch(this.svAPIEndpoint, this.product_group._path, params);
141
- return res;
142
- },
143
- get: async (id) => {
144
- return await this._fetch(this.svAPIEndpoint, this.product_group._path + `/${id}`);
145
- },
146
- create: async (body) => {
147
- let res = await this._create(this.svAPIEndpoint, this.product_group._path, body);
148
- return res;
149
- },
150
- update: async (id, body) => {
151
- let res = await this._update(this.svAPIEndpoint, this.product_group._path + `/${id}`, body);
152
- return res;
153
- },
154
- remove: async (id) => {
155
- let res = await this._delete(this.svAPIEndpoint, this.product_group._path + `/${id}`);
156
- return res;
157
- },
158
- };
159
- this.tax = {
160
- _path: "/tax",
161
- find: async (params) => {
162
- let res = await this._fetch(this.svAPIEndpoint, this.tax._path, params);
163
- return res;
164
- },
165
- get: async (id) => {
166
- return await this._fetch(this.svAPIEndpoint, this.tax._path + `/${id}`);
167
- },
168
- create: async (body) => {
169
- let res = await this._create(this.svAPIEndpoint, this.tax._path, body);
170
- return res;
171
- },
172
- update: async (id, body) => {
173
- let res = await this._update(this.svAPIEndpoint, this.tax._path + `/${id}`, body);
174
- return res;
175
- },
176
- remove: async (id) => {
177
- let res = await this._delete(this.svAPIEndpoint, this.tax._path + `/${id}`);
178
- return res;
179
- },
180
- };
181
- this.measureunit = {
182
- _path: "/measureunits",
183
- find: async (params) => {
184
- let res = await this._fetch(this.svAPIEndpoint, this.measureunit._path, params);
185
- return res;
186
- },
187
- get: async (id) => {
188
- return await this._fetch(this.svAPIEndpoint, this.measureunit._path + `/${id}`);
189
- },
190
- create: async (body) => {
191
- let res = await this._create(this.svAPIEndpoint, this.measureunit._path, body);
192
- return res;
193
- },
194
- update: async (id, body) => {
195
- let res = await this._update(this.svAPIEndpoint, this.measureunit._path + `/${id}`, body);
196
- return res;
197
- },
198
- remove: async (id) => {
199
- let res = await this._delete(this.svAPIEndpoint, this.measureunit._path + `/${id}`);
200
- return res;
201
- },
202
- };
203
- this.measureunitFamily = {
204
- _path: "/measureunit-family",
205
- find: async (params) => {
206
- let res = await this._fetch(this.svAPIEndpoint, this.measureunitFamily._path, params);
207
- return res;
208
- },
209
- get: async (id) => {
210
- return await this._fetch(this.svAPIEndpoint, this.measureunitFamily._path + `/${id}`);
211
- },
212
- create: async (body) => {
213
- let res = await this._create(this.svAPIEndpoint, this.measureunitFamily._path, body);
214
- return res;
215
- },
216
- update: async (id, body) => {
217
- let res = await this._update(this.svAPIEndpoint, this.measureunitFamily._path + `/${id}`, body);
218
- return res;
219
- },
220
- remove: async (id) => {
221
- let res = await this._delete(this.svAPIEndpoint, this.measureunitFamily._path + `/${id}`);
222
- return res;
223
- },
224
- };
225
- this.media = {
226
- _path: "/media",
227
- find: async (params) => {
228
- let res = await this._fetch(this.svAPIEndpoint, this.media._path, params);
229
- return res;
230
- },
231
- get: async (id) => {
232
- return await this._fetch(this.svAPIEndpoint, this.media._path + `/${id}`);
233
- },
234
- create: async (body) => {
235
- let res = await this._create(this.svAPIEndpoint, this.media._path, body);
236
- return res;
237
- },
238
- update: async (id, body) => {
239
- let res = await this._update(this.svAPIEndpoint, this.media._path + `/${id}`, body);
240
- return res;
241
- },
242
- remove: async (id) => {
243
- let res = await this._delete(this.svAPIEndpoint, this.media._path + `/${id}`);
244
- return res;
245
- },
246
- };
247
- this.priceList = {
248
- _path: "/pricelists",
249
- find: async (params) => {
250
- let res = await this._fetch(this.svAPIEndpoint, this.priceList._path, params);
251
- return res;
252
- },
253
- get: async (id) => {
254
- return await this._fetch(this.svAPIEndpoint, this.priceList._path + `/${id}`);
255
- },
256
- create: async (body) => {
257
- let res = await this._create(this.svAPIEndpoint, this.priceList._path, body);
258
- return res;
259
- },
260
- update: async (id, body) => {
261
- let res = await this._update(this.svAPIEndpoint, this.priceList._path + `/${id}`, body);
262
- return res;
263
- },
264
- remove: async (id) => {
265
- let res = await this._delete(this.svAPIEndpoint, this.priceList._path + `/${id}`);
266
- return res;
267
- },
268
- };
269
- this.priceListItem = {
270
- _path: "/pricelists",
271
- find: async (params) => {
272
- let res = await this._fetch(this.svAPIEndpoint, this.priceListItem._path, params);
273
- return res;
274
- },
275
- get: async (id) => {
276
- return await this._fetch(this.svAPIEndpoint, this.priceListItem._path + `/${id}`);
277
- },
278
- create: async (body) => {
279
- let res = await this._create(this.svAPIEndpoint, this.priceListItem._path, body);
280
- return res;
281
- },
282
- update: async (id, body) => {
283
- let res = await this._update(this.svAPIEndpoint, this.priceListItem._path + `/${id}`, body);
284
- return res;
285
- },
286
- remove: async (id) => {
287
- let res = await this._delete(this.svAPIEndpoint, this.priceListItem._path + `/${id}`);
288
- return res;
289
- },
290
- };
291
- this.team = {
292
- _path: "/teams",
293
- find: async (params) => {
294
- let res = await this._fetch(this.svAPIEndpoint, this.team._path, params);
295
- return res;
296
- },
297
- get: async (id) => {
298
- return await this._fetch(this.svAPIEndpoint, this.team._path + `/${id}`);
299
- },
300
- create: async (body) => {
301
- let res = await this._create(this.svAPIEndpoint, this.team._path, body);
302
- return res;
303
- },
304
- update: async (id, body) => {
305
- let res = await this._update(this.svAPIEndpoint, this.team._path + `/${id}`, body);
306
- return res;
307
- },
308
- remove: async (id) => {
309
- let res = await this._delete(this.svAPIEndpoint, this.team._path + `/${id}`);
310
- return res;
311
- },
312
- };
313
- this.rep = {
314
- _path: "/rep",
315
- find: async (params) => {
316
- let res = await this._fetch(this.svAPIEndpoint, this.rep._path, params);
317
- return res;
318
- },
319
- get: async (id, params) => {
320
- return await this._fetch(this.svAPIEndpoint, this.rep._path + `/${id}`, params);
321
- },
322
- create: async (body) => {
323
- let res = await this._create(this.svAPIEndpoint, this.rep._path, body);
324
- return res;
325
- },
326
- update: async (id, body) => {
327
- let res = await this._update(this.svAPIEndpoint, this.rep._path + `/${id}`, body);
328
- return res;
329
- },
330
- remove: async (id) => {
331
- let res = await this._delete(this.svAPIEndpoint, this.rep._path + `/${id}`);
332
- return res;
333
- },
334
- };
335
- this.tag = {
336
- _path: "/tag",
337
- find: async (params) => {
338
- let res = await this._fetch(this.svAPIEndpoint, this.tag._path, params);
339
- return res;
340
- },
341
- get: async (id) => {
342
- return await this._fetch(this.svAPIEndpoint, this.tag._path + `/${id}`);
343
- },
344
- create: async (body) => {
345
- let res = await this._create(this.svAPIEndpoint, this.tag._path, body);
346
- return res;
347
- },
348
- update: async (id, body) => {
349
- let res = await this._update(this.svAPIEndpoint, this.tag._path + `/${id}`, body);
350
- return res;
351
- },
352
- remove: async (id) => {
353
- let res = await this._delete(this.svAPIEndpoint, this.tag._path + `/${id}`);
354
- return res;
355
- },
356
- };
357
- this.warehouse = {
358
- _path: "/warehouse",
359
- find: async (params) => {
360
- let res = await this._fetch(this.svAPIEndpoint, this.warehouse._path, params);
361
- return res;
362
- },
363
- get: async (id) => {
364
- return await this._fetch(this.svAPIEndpoint, this.warehouse._path + `/${id}`);
365
- },
366
- create: async (body) => {
367
- let res = await this._create(this.svAPIEndpoint, this.warehouse._path, body);
368
- return res;
369
- },
370
- update: async (id, body) => {
371
- let res = await this._update(this.svAPIEndpoint, this.warehouse._path + `/${id}`, body);
372
- return res;
373
- },
374
- remove: async (id) => {
375
- let res = await this._delete(this.svAPIEndpoint, this.warehouse._path + `/${id}`);
376
- return res;
377
- },
378
- };
379
- this.channel = {
380
- _path: "/client-channel",
381
- find: async (params) => {
382
- let res = await this._fetch(this.svAPIEndpoint, this.channel._path, params);
383
- return res;
384
- },
385
- get: async (id) => {
386
- return await this._fetch(this.svAPIEndpoint, this.channel._path + `/${id}`);
387
- },
388
- create: async (body) => {
389
- let res = await this._create(this.svAPIEndpoint, this.channel._path, body);
390
- return res;
391
- },
392
- update: async (id, body) => {
393
- let res = await this._update(this.svAPIEndpoint, this.channel._path + `/${id}`, body);
394
- return res;
395
- },
396
- remove: async (id) => {
397
- let res = await this._delete(this.svAPIEndpoint, this.channel._path + `/${id}`);
398
- return res;
399
- },
400
- };
401
- this.paymentTerm = {
402
- _path: "/paymentterms",
403
- find: async (params) => {
404
- let res = await this._fetch(this.svAPIEndpoint, this.paymentTerm._path, params);
405
- return res;
406
- },
407
- get: async (id) => {
408
- return await this._fetch(this.svAPIEndpoint, this.paymentTerm._path + `/${id}`);
409
- },
410
- create: async (body) => {
411
- let res = await this._create(this.svAPIEndpoint, this.paymentTerm._path, body);
412
- return res;
413
- },
414
- update: async (id, body) => {
415
- let res = await this._update(this.svAPIEndpoint, this.paymentTerm._path + `/${id}`, body);
416
- return res;
417
- },
418
- remove: async (id) => {
419
- let res = await this._delete(this.svAPIEndpoint, this.paymentTerm._path + `/${id}`);
420
- return res;
421
- },
422
- };
423
- this.bank = {
424
- _path: "/banks",
425
- find: async (params) => {
426
- let res = await this._fetch(this.svAPIEndpoint, this.bank._path, params);
427
- return res;
428
- },
429
- get: async (id) => {
430
- return await this._fetch(this.svAPIEndpoint, this.bank._path + `/${id}`);
431
- },
432
- create: async (body) => {
433
- let res = await this._create(this.svAPIEndpoint, this.bank._path, body);
434
- return res;
435
- },
436
- update: async (id, body) => {
437
- let res = await this._update(this.svAPIEndpoint, this.bank._path + `/${id}`, body);
438
- return res;
439
- },
440
- };
441
- this.customStatus = {
442
- _path: "/custom-status",
443
- find: async (params) => {
444
- let res = await this._fetch(this.svAPIEndpoint, this.customStatus._path, params);
445
- return res;
446
- },
447
- get: async (id) => {
448
- return await this._fetch(this.svAPIEndpoint, this.customStatus._path + `/${id}`);
449
- },
450
- create: async (body) => {
451
- let res = await this._create(this.svAPIEndpoint, this.customStatus._path, body);
452
- return res;
453
- },
454
- update: async (id, body) => {
455
- let res = await this._update(this.svAPIEndpoint, this.customStatus._path + `/${id}`, body);
456
- return res;
457
- },
458
- remove: async (id) => {
459
- let res = await this._delete(this.svAPIEndpoint, this.customStatus._path + `/${id}`);
460
- return res;
461
- },
462
- };
463
- this.invoice = {
464
- _path: "/fullinvoices",
465
- find: async (params) => {
466
- let res = await this._fetch(this.svAPIEndpoint, this.invoice._path, params);
467
- return res;
468
- },
469
- get: async (id, params) => {
470
- return await this._fetch(this.svAPIEndpoint, this.invoice._path + `/${id}`, params);
471
- },
472
- create: async (body) => {
473
- let res = await this._create(this.svAPIEndpoint, this.invoice._path, body);
474
- return res;
475
- },
476
- update: async (id, body) => {
477
- let res = await this._update(this.svAPIEndpoint, this.invoice._path + `/${id}`, body);
478
- return res;
479
- },
480
- };
481
- this.proforma = {
482
- _path: "/proforma",
483
- find: async (params) => {
484
- let res = await this._fetch(this.svAPIEndpoint, this.proforma._path, params);
485
- return res;
486
- },
487
- get: async (id, params) => {
488
- return await this._fetch(this.svAPIEndpoint, this.proforma._path + `/${id}`, params);
489
- },
490
- create: async (body) => {
491
- let res = await this._create(this.svAPIEndpoint, this.proforma._path, body);
492
- return res;
493
- },
494
- update: async (id, body) => {
495
- let res = await this._update(this.svAPIEndpoint, this.proforma._path + `/${id}`, body);
496
- return res;
497
- },
498
- };
499
- this.payment = {
500
- _path: "/payments",
501
- find: async (params) => {
502
- let res = await this._fetch(this.svAPIEndpoint, this.payment._path, params);
503
- return res;
504
- },
505
- get: async (id, params) => {
506
- return await this._fetch(this.svAPIEndpoint, this.payment._path + `/${id}`, params);
507
- },
508
- create: async (body) => {
509
- let res = await this._create(this.svAPIEndpoint, this.payment._path, body);
510
- return res;
511
- },
512
- update: async (id, body) => {
513
- let res = await this._update(this.svAPIEndpoint, this.payment._path + `/${id}`, body);
514
- return res;
515
- },
516
- };
517
- this.transfer = {
518
- _path: "/transfer",
519
- find: async (params) => {
520
- let res = await this._fetch(this.svAPIEndpoint, this.transfer._path, params);
521
- return res;
522
- },
523
- get: async (id, params) => {
524
- return await this._fetch(this.svAPIEndpoint, this.transfer._path + `/${id}`, params);
525
- },
526
- create: async (body) => {
527
- let res = await this._create(this.svAPIEndpoint, this.transfer._path, body);
528
- return res;
529
- },
530
- update: async (id, body) => {
531
- let res = await this._update(this.svAPIEndpoint, this.transfer._path + `/${id}`, body);
532
- return res;
533
- },
534
- };
535
- this.adjustInventory = {
536
- _path: "/adjust-inventory",
537
- find: async (params) => {
538
- let res = await this._fetch(this.svAPIEndpoint, this.adjustInventory._path, params);
539
- return res;
540
- },
541
- get: async (id, params) => {
542
- return await this._fetch(this.svAPIEndpoint, this.adjustInventory._path + `/${id}`, params);
543
- },
544
- create: async (body) => {
545
- let res = await this._create(this.svAPIEndpoint, this.adjustInventory._path, body);
546
- return res;
547
- },
548
- };
549
- this.inventory = {
550
- _path: "/inventory",
551
- find: async (params) => {
552
- let res = await this._fetch(this.svAPIEndpoint, this.inventory._path, params);
553
- return res;
554
- },
555
- };
556
- this.svAPIEndpoint =
557
- !options?.env || options?.env == "production"
558
- ? "https://sv.api.repzo.me"
559
- : options?.env == "staging"
560
- ? "https://staging.sv.api.repzo.me"
561
- : options?.env == "local"
562
- ? "http://localhost:3030"
563
- : "";
564
- this.headers = {
565
- "api-key": apiKey,
566
- "Content-Type": "application/json",
567
- Accept: "application/json",
568
- };
569
- if (options?.headers)
570
- Object.assign(this.headers, options.headers);
571
- }
572
- async _fetch(baseUrl, path, params) {
573
- let res = await axios.get(baseUrl + path, {
574
- params,
575
- headers: this.headers,
576
- });
577
- return res.data;
578
- }
579
- async _create(baseUrl, path, body, params) {
580
- let res = await axios.post(baseUrl + path, body, {
581
- params,
582
- headers: this.headers,
583
- });
584
- return res.data;
585
- }
586
- async _update(baseUrl, path, body, params) {
587
- let res = await axios.put(baseUrl + path, body, {
588
- params,
589
- headers: this.headers,
590
- });
591
- return res.data;
592
- }
593
- async _delete(baseUrl, path, params) {
594
- let res = await axios.delete(baseUrl + path, {
595
- params,
596
- headers: this.headers,
597
- });
598
- return res.data;
599
- }
600
- }
601
- Repzo.ActionLogs = class {
602
- constructor(superThis, sync_id) {
603
- this.superThis = superThis;
604
- this._path = "/integration-action-log";
605
- this.available_app_name = "";
606
- this.available_app_id = "";
607
- this.app_id = "";
608
- this.action = "";
609
- this.start_time = Date.now();
610
- this.status = "processing";
611
- this.message = "Log Created";
612
- this.details = [];
613
- this.sync_id = sync_id;
614
- this.isOld = true;
615
- }
616
- async load(sync_id) {
617
- console.log(sync_id);
618
- const params = { sync_id: sync_id };
619
- const res = await this.superThis._fetch(this.superThis.svAPIEndpoint, this._path, params);
620
- if (res?.data?.length)
621
- throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
622
- const action_log = res.data[0];
623
- this.sync_id = sync_id;
624
- this.details = action_log.details;
625
- this.status = action_log.status;
626
- this.error = action_log.error;
627
- this.start_time = action_log.start_time;
628
- this.body = action_log.body;
629
- this.meta = action_log.meta;
630
- this.message = action_log.message;
631
- this.app_id = action_log._id;
632
- this.available_app_id = action_log.available_app_id;
633
- this.available_app_name = action_log.available_app_name;
634
- this.company_namespace = action_log.company_namespace;
635
- this.action = action_log.action;
636
- this.isOld = true;
637
- return this;
638
- }
639
- async setStatus(status, error) {
640
- this.details.push({
641
- timestamp: Date.now(),
642
- content: `status was changed from ${this.status} to ${status}`,
643
- });
644
- this.status = status;
645
- if (error) {
646
- this.error = error;
647
- }
648
- return this;
649
- }
650
- setBody(body) {
651
- this.body = body;
652
- return this;
653
- }
654
- setMeta(meta) {
655
- this.meta = meta;
656
- return this;
657
- }
658
- async commit() {
659
- let doc = {
660
- available_app_name: this.available_app_name,
661
- available_app_id: this.available_app_id,
662
- app_id: this.app_id,
663
- action: this.action,
664
- company_namespace: this.company_namespace,
665
- status: this.status,
666
- error: this.error ? this.error : undefined,
667
- start_time: this.start_time,
668
- end_time: Date.now(),
669
- total_time: Date.now() - this.start_time,
670
- body: this.body,
671
- meta: this.meta,
672
- message: this.message,
673
- details: this.details,
674
- sync_id: this.sync_id,
675
- };
676
- try {
677
- const res = await this.superThis._create(this.superThis.svAPIEndpoint, this._path, doc);
678
- }
679
- catch (e) {
680
- console.error(e);
681
- }
682
- return this;
683
- }
684
- addDetail(detail, meta) {
685
- let d = {
686
- timestamp: Date.now(),
687
- content: detail,
688
- };
689
- if (meta)
690
- d.meta = meta;
691
- this.details.push(d);
692
- return this;
693
- }
694
- };
695
- Repzo.CommandLog = class {
696
- constructor(superThis, app, command, trigger) {
697
- this.superThis = superThis;
698
- this._path = "/integration-command-log";
699
- this.app_id = app._id;
700
- this.available_app_id = app.available_app._id;
701
- this.available_app_name = app.available_app.name;
702
- this.company_namespace = app.company_namespace;
703
- this.start_time = Date.now();
704
- this.status = "received";
705
- this.message = "Request received";
706
- this.command = command;
707
- this.details = [{ timestamp: Date.now(), content: "Request received" }];
708
- this.sync_id = uuid();
709
- this.isOld = false;
710
- this.isPrioritized = false;
711
- this.retries = 1;
712
- this.trigger = trigger;
713
- this.onGoing = true;
714
- }
715
- async load(sync_id, retries) {
716
- if (sync_id) {
717
- const params = { sync_id: sync_id };
718
- const res = await this.superThis._fetch(this.superThis.svAPIEndpoint, this._path, params);
719
- if (res?.data?.length)
720
- throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
721
- const command_log = res.data[0];
722
- if (command_log) {
723
- this.sync_id = sync_id;
724
- this.details = command_log.details;
725
- this.status = command_log.status;
726
- this.error = command_log.error;
727
- this.start_time = command_log.start_time;
728
- this.body = command_log.body;
729
- this.meta = command_log.meta;
730
- this.message = command_log.message;
731
- this.retries =
732
- retries !== undefined
733
- ? retries
734
- : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
735
- this.isOld = true;
736
- this.failedAt = command_log.failedAt;
737
- this.succeededAt = command_log.succeededAt;
738
- this.skippedAt = command_log.skippedAt;
739
- this.receivedAt = command_log.receivedAt;
740
- this.processedAt = command_log.processedAt;
741
- this.onGoing = command_log.onGoing || false;
742
- this.trigger = command_log.trigger;
743
- // this.priority = command_log.priority
744
- // ? command_log.priority
745
- // : this.priority
746
- // ? this.priority
747
- // : undefined;
748
- }
749
- }
750
- return this;
751
- }
752
- setStatus(status, error) {
753
- this.addDetail(`status was changed from ${this.status} to ${status}`);
754
- this.status = status;
755
- if (error) {
756
- this.error = error;
757
- }
758
- switch (status) {
759
- case "fail":
760
- this.failedAt = new Date();
761
- this.onGoing = false;
762
- break;
763
- case "processing":
764
- this.processedAt = new Date();
765
- this.onGoing = true;
766
- break;
767
- case "queued":
768
- this.queuedAt = new Date();
769
- this.onGoing = true;
770
- break;
771
- case "received":
772
- this.receivedAt = new Date();
773
- this.onGoing = true;
774
- break;
775
- case "skipped":
776
- this.skippedAt = new Date();
777
- this.onGoing = false;
778
- break;
779
- case "success":
780
- this.succeededAt = new Date();
781
- this.onGoing = false;
782
- break;
783
- }
784
- return this;
785
- }
786
- setBody(body) {
787
- this.body = body;
788
- return this;
789
- }
790
- setMeta(meta) {
791
- this.meta = meta;
792
- return this;
793
- }
794
- async commit() {
795
- let doc = {
796
- available_app_name: this.available_app_name,
797
- available_app_id: this.available_app_id,
798
- app_id: this.app_id,
799
- command: this.command,
800
- status: this.status,
801
- error: this.error ? this.error : undefined,
802
- start_time: this.start_time,
803
- end_time: Date.now(),
804
- total_time: Date.now() - this.start_time,
805
- company_namespace: this.company_namespace,
806
- body: this.body,
807
- meta: this.meta,
808
- message: this.message,
809
- details: this.details,
810
- sync_id: this.sync_id,
811
- // priority: this.priority ? this.priority : undefined,
812
- queuedAt: this.queuedAt ? this.queuedAt : undefined,
813
- failedAt: this.failedAt ? this.failedAt : undefined,
814
- succeededAt: this.succeededAt ? this.succeededAt : undefined,
815
- skippedAt: this.skippedAt ? this.skippedAt : undefined,
816
- receivedAt: this.receivedAt ? this.receivedAt : undefined,
817
- processedAt: this.processedAt ? this.processedAt : undefined,
818
- onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
819
- retries: this.retries !== undefined ? this.retries : undefined,
820
- trigger: this.trigger,
821
- };
822
- try {
823
- const res = await this.superThis._create(this.superThis.svAPIEndpoint, this._path, doc);
824
- this.isOld = true;
825
- }
826
- catch (e) {
827
- console.error(e);
828
- }
829
- return this;
830
- }
831
- addDetail(detail, meta) {
832
- let d = {
833
- timestamp: Date.now(),
834
- content: detail,
835
- };
836
- if (meta)
837
- d.meta = meta;
838
- this.details.push(d);
839
- return this;
840
- }
841
- };
1
+ import axios from "axios";
2
+ import { v4 as uuid } from "uuid";
3
+ export default class Repzo {
4
+ constructor(apiKey, options) {
5
+ this.client = {
6
+ _path: "/client",
7
+ find: async (params) => {
8
+ let res = await this._fetch(
9
+ this.svAPIEndpoint,
10
+ this.client._path,
11
+ params
12
+ );
13
+ return res;
14
+ },
15
+ get: async (id, params) => {
16
+ return await this._fetch(
17
+ this.svAPIEndpoint,
18
+ this.client._path + `/${id}`,
19
+ params
20
+ );
21
+ },
22
+ create: async (body) => {
23
+ let res = await this._create(
24
+ this.svAPIEndpoint,
25
+ this.client._path,
26
+ body
27
+ );
28
+ return res;
29
+ },
30
+ update: async (id, body) => {
31
+ let res = await this._update(
32
+ this.svAPIEndpoint,
33
+ this.client._path + `/${id}`,
34
+ body
35
+ );
36
+ return res;
37
+ },
38
+ remove: async (id) => {
39
+ let res = await this._delete(
40
+ this.svAPIEndpoint,
41
+ this.client._path + `/${id}`
42
+ );
43
+ return res;
44
+ },
45
+ };
46
+ this.product = {
47
+ _path: "/product",
48
+ find: async (params) => {
49
+ let res = await this._fetch(
50
+ this.svAPIEndpoint,
51
+ this.product._path,
52
+ params
53
+ );
54
+ return res;
55
+ },
56
+ get: async (id, params) => {
57
+ return await this._fetch(
58
+ this.svAPIEndpoint,
59
+ this.product._path + `/${id}`,
60
+ params
61
+ );
62
+ },
63
+ create: async (body) => {
64
+ let res = await this._create(
65
+ this.svAPIEndpoint,
66
+ this.product._path,
67
+ body
68
+ );
69
+ return res;
70
+ },
71
+ update: async (id, body) => {
72
+ let res = await this._update(
73
+ this.svAPIEndpoint,
74
+ this.product._path + `/${id}`,
75
+ body
76
+ );
77
+ return res;
78
+ },
79
+ remove: async (id) => {
80
+ let res = await this._delete(
81
+ this.svAPIEndpoint,
82
+ this.product._path + `/${id}`
83
+ );
84
+ return res;
85
+ },
86
+ };
87
+ this.variant = {
88
+ _path: "/variant",
89
+ find: async (params) => {
90
+ let res = await this._fetch(
91
+ this.svAPIEndpoint,
92
+ this.variant._path,
93
+ params
94
+ );
95
+ return res;
96
+ },
97
+ get: async (id, params) => {
98
+ return await this._fetch(
99
+ this.svAPIEndpoint,
100
+ this.variant._path + `/${id}`,
101
+ params
102
+ );
103
+ },
104
+ create: async (body) => {
105
+ let res = await this._create(
106
+ this.svAPIEndpoint,
107
+ this.variant._path,
108
+ body
109
+ );
110
+ return res;
111
+ },
112
+ update: async (id, body) => {
113
+ let res = await this._update(
114
+ this.svAPIEndpoint,
115
+ this.variant._path + `/${id}`,
116
+ body
117
+ );
118
+ return res;
119
+ },
120
+ remove: async (id) => {
121
+ let res = await this._delete(
122
+ this.svAPIEndpoint,
123
+ this.variant._path + `/${id}`
124
+ );
125
+ return res;
126
+ },
127
+ };
128
+ this.category = {
129
+ _path: "/product-category",
130
+ find: async (params) => {
131
+ let res = await this._fetch(
132
+ this.svAPIEndpoint,
133
+ this.category._path,
134
+ params
135
+ );
136
+ return res;
137
+ },
138
+ get: async (id) => {
139
+ return await this._fetch(
140
+ this.svAPIEndpoint,
141
+ this.category._path + `/${id}`
142
+ );
143
+ },
144
+ create: async (body) => {
145
+ let res = await this._create(
146
+ this.svAPIEndpoint,
147
+ this.category._path,
148
+ body
149
+ );
150
+ return res;
151
+ },
152
+ update: async (id, body) => {
153
+ let res = await this._update(
154
+ this.svAPIEndpoint,
155
+ this.category._path + `/${id}`,
156
+ body
157
+ );
158
+ return res;
159
+ },
160
+ remove: async (id) => {
161
+ let res = await this._delete(
162
+ this.svAPIEndpoint,
163
+ this.category._path + `/${id}`
164
+ );
165
+ return res;
166
+ },
167
+ };
168
+ this.sub_category = {
169
+ _path: "/product-sub-category",
170
+ find: async (params) => {
171
+ let res = await this._fetch(
172
+ this.svAPIEndpoint,
173
+ this.sub_category._path,
174
+ params
175
+ );
176
+ return res;
177
+ },
178
+ get: async (id, params) => {
179
+ return await this._fetch(
180
+ this.svAPIEndpoint,
181
+ this.sub_category._path + `/${id}`,
182
+ params
183
+ );
184
+ },
185
+ create: async (body) => {
186
+ let res = await this._create(
187
+ this.svAPIEndpoint,
188
+ this.sub_category._path,
189
+ body
190
+ );
191
+ return res;
192
+ },
193
+ update: async (id, body) => {
194
+ let res = await this._update(
195
+ this.svAPIEndpoint,
196
+ this.sub_category._path + `/${id}`,
197
+ body
198
+ );
199
+ return res;
200
+ },
201
+ remove: async (id) => {
202
+ let res = await this._delete(
203
+ this.svAPIEndpoint,
204
+ this.sub_category._path + `/${id}`
205
+ );
206
+ return res;
207
+ },
208
+ };
209
+ this.brand = {
210
+ _path: "/product-brand",
211
+ find: async (params) => {
212
+ let res = await this._fetch(
213
+ this.svAPIEndpoint,
214
+ this.brand._path,
215
+ params
216
+ );
217
+ return res;
218
+ },
219
+ get: async (id) => {
220
+ return await this._fetch(
221
+ this.svAPIEndpoint,
222
+ this.brand._path + `/${id}`
223
+ );
224
+ },
225
+ create: async (body) => {
226
+ let res = await this._create(
227
+ this.svAPIEndpoint,
228
+ this.brand._path,
229
+ body
230
+ );
231
+ return res;
232
+ },
233
+ update: async (id, body) => {
234
+ let res = await this._update(
235
+ this.svAPIEndpoint,
236
+ this.brand._path + `/${id}`,
237
+ body
238
+ );
239
+ return res;
240
+ },
241
+ remove: async (id) => {
242
+ let res = await this._delete(
243
+ this.svAPIEndpoint,
244
+ this.brand._path + `/${id}`
245
+ );
246
+ return res;
247
+ },
248
+ };
249
+ this.product_group = {
250
+ _path: "/product-group",
251
+ find: async (params) => {
252
+ let res = await this._fetch(
253
+ this.svAPIEndpoint,
254
+ this.product_group._path,
255
+ params
256
+ );
257
+ return res;
258
+ },
259
+ get: async (id) => {
260
+ return await this._fetch(
261
+ this.svAPIEndpoint,
262
+ this.product_group._path + `/${id}`
263
+ );
264
+ },
265
+ create: async (body) => {
266
+ let res = await this._create(
267
+ this.svAPIEndpoint,
268
+ this.product_group._path,
269
+ body
270
+ );
271
+ return res;
272
+ },
273
+ update: async (id, body) => {
274
+ let res = await this._update(
275
+ this.svAPIEndpoint,
276
+ this.product_group._path + `/${id}`,
277
+ body
278
+ );
279
+ return res;
280
+ },
281
+ remove: async (id) => {
282
+ let res = await this._delete(
283
+ this.svAPIEndpoint,
284
+ this.product_group._path + `/${id}`
285
+ );
286
+ return res;
287
+ },
288
+ };
289
+ this.tax = {
290
+ _path: "/tax",
291
+ find: async (params) => {
292
+ let res = await this._fetch(this.svAPIEndpoint, this.tax._path, params);
293
+ return res;
294
+ },
295
+ get: async (id) => {
296
+ return await this._fetch(this.svAPIEndpoint, this.tax._path + `/${id}`);
297
+ },
298
+ create: async (body) => {
299
+ let res = await this._create(this.svAPIEndpoint, this.tax._path, body);
300
+ return res;
301
+ },
302
+ update: async (id, body) => {
303
+ let res = await this._update(
304
+ this.svAPIEndpoint,
305
+ this.tax._path + `/${id}`,
306
+ body
307
+ );
308
+ return res;
309
+ },
310
+ remove: async (id) => {
311
+ let res = await this._delete(
312
+ this.svAPIEndpoint,
313
+ this.tax._path + `/${id}`
314
+ );
315
+ return res;
316
+ },
317
+ };
318
+ this.measureunit = {
319
+ _path: "/measureunits",
320
+ find: async (params) => {
321
+ let res = await this._fetch(
322
+ this.svAPIEndpoint,
323
+ this.measureunit._path,
324
+ params
325
+ );
326
+ return res;
327
+ },
328
+ get: async (id) => {
329
+ return await this._fetch(
330
+ this.svAPIEndpoint,
331
+ this.measureunit._path + `/${id}`
332
+ );
333
+ },
334
+ create: async (body) => {
335
+ let res = await this._create(
336
+ this.svAPIEndpoint,
337
+ this.measureunit._path,
338
+ body
339
+ );
340
+ return res;
341
+ },
342
+ update: async (id, body) => {
343
+ let res = await this._update(
344
+ this.svAPIEndpoint,
345
+ this.measureunit._path + `/${id}`,
346
+ body
347
+ );
348
+ return res;
349
+ },
350
+ remove: async (id) => {
351
+ let res = await this._delete(
352
+ this.svAPIEndpoint,
353
+ this.measureunit._path + `/${id}`
354
+ );
355
+ return res;
356
+ },
357
+ };
358
+ this.measureunitFamily = {
359
+ _path: "/measureunit-family",
360
+ find: async (params) => {
361
+ let res = await this._fetch(
362
+ this.svAPIEndpoint,
363
+ this.measureunitFamily._path,
364
+ params
365
+ );
366
+ return res;
367
+ },
368
+ get: async (id) => {
369
+ return await this._fetch(
370
+ this.svAPIEndpoint,
371
+ this.measureunitFamily._path + `/${id}`
372
+ );
373
+ },
374
+ create: async (body) => {
375
+ let res = await this._create(
376
+ this.svAPIEndpoint,
377
+ this.measureunitFamily._path,
378
+ body
379
+ );
380
+ return res;
381
+ },
382
+ update: async (id, body) => {
383
+ let res = await this._update(
384
+ this.svAPIEndpoint,
385
+ this.measureunitFamily._path + `/${id}`,
386
+ body
387
+ );
388
+ return res;
389
+ },
390
+ remove: async (id) => {
391
+ let res = await this._delete(
392
+ this.svAPIEndpoint,
393
+ this.measureunitFamily._path + `/${id}`
394
+ );
395
+ return res;
396
+ },
397
+ };
398
+ this.media = {
399
+ _path: "/media",
400
+ find: async (params) => {
401
+ let res = await this._fetch(
402
+ this.svAPIEndpoint,
403
+ this.media._path,
404
+ params
405
+ );
406
+ return res;
407
+ },
408
+ get: async (id) => {
409
+ return await this._fetch(
410
+ this.svAPIEndpoint,
411
+ this.media._path + `/${id}`
412
+ );
413
+ },
414
+ create: async (body) => {
415
+ let res = await this._create(
416
+ this.svAPIEndpoint,
417
+ this.media._path,
418
+ body
419
+ );
420
+ return res;
421
+ },
422
+ update: async (id, body) => {
423
+ let res = await this._update(
424
+ this.svAPIEndpoint,
425
+ this.media._path + `/${id}`,
426
+ body
427
+ );
428
+ return res;
429
+ },
430
+ remove: async (id) => {
431
+ let res = await this._delete(
432
+ this.svAPIEndpoint,
433
+ this.media._path + `/${id}`
434
+ );
435
+ return res;
436
+ },
437
+ };
438
+ this.priceList = {
439
+ _path: "/pricelists",
440
+ find: async (params) => {
441
+ let res = await this._fetch(
442
+ this.svAPIEndpoint,
443
+ this.priceList._path,
444
+ params
445
+ );
446
+ return res;
447
+ },
448
+ get: async (id) => {
449
+ return await this._fetch(
450
+ this.svAPIEndpoint,
451
+ this.priceList._path + `/${id}`
452
+ );
453
+ },
454
+ create: async (body) => {
455
+ let res = await this._create(
456
+ this.svAPIEndpoint,
457
+ this.priceList._path,
458
+ body
459
+ );
460
+ return res;
461
+ },
462
+ update: async (id, body) => {
463
+ let res = await this._update(
464
+ this.svAPIEndpoint,
465
+ this.priceList._path + `/${id}`,
466
+ body
467
+ );
468
+ return res;
469
+ },
470
+ remove: async (id) => {
471
+ let res = await this._delete(
472
+ this.svAPIEndpoint,
473
+ this.priceList._path + `/${id}`
474
+ );
475
+ return res;
476
+ },
477
+ };
478
+ this.priceListItem = {
479
+ _path: "/pricelists",
480
+ find: async (params) => {
481
+ let res = await this._fetch(
482
+ this.svAPIEndpoint,
483
+ this.priceListItem._path,
484
+ params
485
+ );
486
+ return res;
487
+ },
488
+ get: async (id) => {
489
+ return await this._fetch(
490
+ this.svAPIEndpoint,
491
+ this.priceListItem._path + `/${id}`
492
+ );
493
+ },
494
+ create: async (body) => {
495
+ let res = await this._create(
496
+ this.svAPIEndpoint,
497
+ this.priceListItem._path,
498
+ body
499
+ );
500
+ return res;
501
+ },
502
+ update: async (id, body) => {
503
+ let res = await this._update(
504
+ this.svAPIEndpoint,
505
+ this.priceListItem._path + `/${id}`,
506
+ body
507
+ );
508
+ return res;
509
+ },
510
+ remove: async (id) => {
511
+ let res = await this._delete(
512
+ this.svAPIEndpoint,
513
+ this.priceListItem._path + `/${id}`
514
+ );
515
+ return res;
516
+ },
517
+ };
518
+ this.team = {
519
+ _path: "/teams",
520
+ find: async (params) => {
521
+ let res = await this._fetch(
522
+ this.svAPIEndpoint,
523
+ this.team._path,
524
+ params
525
+ );
526
+ return res;
527
+ },
528
+ get: async (id) => {
529
+ return await this._fetch(
530
+ this.svAPIEndpoint,
531
+ this.team._path + `/${id}`
532
+ );
533
+ },
534
+ create: async (body) => {
535
+ let res = await this._create(this.svAPIEndpoint, this.team._path, body);
536
+ return res;
537
+ },
538
+ update: async (id, body) => {
539
+ let res = await this._update(
540
+ this.svAPIEndpoint,
541
+ this.team._path + `/${id}`,
542
+ body
543
+ );
544
+ return res;
545
+ },
546
+ remove: async (id) => {
547
+ let res = await this._delete(
548
+ this.svAPIEndpoint,
549
+ this.team._path + `/${id}`
550
+ );
551
+ return res;
552
+ },
553
+ };
554
+ this.rep = {
555
+ _path: "/rep",
556
+ find: async (params) => {
557
+ let res = await this._fetch(this.svAPIEndpoint, this.rep._path, params);
558
+ return res;
559
+ },
560
+ get: async (id, params) => {
561
+ return await this._fetch(
562
+ this.svAPIEndpoint,
563
+ this.rep._path + `/${id}`,
564
+ params
565
+ );
566
+ },
567
+ create: async (body) => {
568
+ let res = await this._create(this.svAPIEndpoint, this.rep._path, body);
569
+ return res;
570
+ },
571
+ update: async (id, body) => {
572
+ let res = await this._update(
573
+ this.svAPIEndpoint,
574
+ this.rep._path + `/${id}`,
575
+ body
576
+ );
577
+ return res;
578
+ },
579
+ remove: async (id) => {
580
+ let res = await this._delete(
581
+ this.svAPIEndpoint,
582
+ this.rep._path + `/${id}`
583
+ );
584
+ return res;
585
+ },
586
+ };
587
+ this.tag = {
588
+ _path: "/tag",
589
+ find: async (params) => {
590
+ let res = await this._fetch(this.svAPIEndpoint, this.tag._path, params);
591
+ return res;
592
+ },
593
+ get: async (id) => {
594
+ return await this._fetch(this.svAPIEndpoint, this.tag._path + `/${id}`);
595
+ },
596
+ create: async (body) => {
597
+ let res = await this._create(this.svAPIEndpoint, this.tag._path, body);
598
+ return res;
599
+ },
600
+ update: async (id, body) => {
601
+ let res = await this._update(
602
+ this.svAPIEndpoint,
603
+ this.tag._path + `/${id}`,
604
+ body
605
+ );
606
+ return res;
607
+ },
608
+ remove: async (id) => {
609
+ let res = await this._delete(
610
+ this.svAPIEndpoint,
611
+ this.tag._path + `/${id}`
612
+ );
613
+ return res;
614
+ },
615
+ };
616
+ this.warehouse = {
617
+ _path: "/warehouse",
618
+ find: async (params) => {
619
+ let res = await this._fetch(
620
+ this.svAPIEndpoint,
621
+ this.warehouse._path,
622
+ params
623
+ );
624
+ return res;
625
+ },
626
+ get: async (id) => {
627
+ return await this._fetch(
628
+ this.svAPIEndpoint,
629
+ this.warehouse._path + `/${id}`
630
+ );
631
+ },
632
+ create: async (body) => {
633
+ let res = await this._create(
634
+ this.svAPIEndpoint,
635
+ this.warehouse._path,
636
+ body
637
+ );
638
+ return res;
639
+ },
640
+ update: async (id, body) => {
641
+ let res = await this._update(
642
+ this.svAPIEndpoint,
643
+ this.warehouse._path + `/${id}`,
644
+ body
645
+ );
646
+ return res;
647
+ },
648
+ remove: async (id) => {
649
+ let res = await this._delete(
650
+ this.svAPIEndpoint,
651
+ this.warehouse._path + `/${id}`
652
+ );
653
+ return res;
654
+ },
655
+ };
656
+ this.channel = {
657
+ _path: "/client-channel",
658
+ find: async (params) => {
659
+ let res = await this._fetch(
660
+ this.svAPIEndpoint,
661
+ this.channel._path,
662
+ params
663
+ );
664
+ return res;
665
+ },
666
+ get: async (id) => {
667
+ return await this._fetch(
668
+ this.svAPIEndpoint,
669
+ this.channel._path + `/${id}`
670
+ );
671
+ },
672
+ create: async (body) => {
673
+ let res = await this._create(
674
+ this.svAPIEndpoint,
675
+ this.channel._path,
676
+ body
677
+ );
678
+ return res;
679
+ },
680
+ update: async (id, body) => {
681
+ let res = await this._update(
682
+ this.svAPIEndpoint,
683
+ this.channel._path + `/${id}`,
684
+ body
685
+ );
686
+ return res;
687
+ },
688
+ remove: async (id) => {
689
+ let res = await this._delete(
690
+ this.svAPIEndpoint,
691
+ this.channel._path + `/${id}`
692
+ );
693
+ return res;
694
+ },
695
+ };
696
+ this.paymentTerm = {
697
+ _path: "/paymentterms",
698
+ find: async (params) => {
699
+ let res = await this._fetch(
700
+ this.svAPIEndpoint,
701
+ this.paymentTerm._path,
702
+ params
703
+ );
704
+ return res;
705
+ },
706
+ get: async (id) => {
707
+ return await this._fetch(
708
+ this.svAPIEndpoint,
709
+ this.paymentTerm._path + `/${id}`
710
+ );
711
+ },
712
+ create: async (body) => {
713
+ let res = await this._create(
714
+ this.svAPIEndpoint,
715
+ this.paymentTerm._path,
716
+ body
717
+ );
718
+ return res;
719
+ },
720
+ update: async (id, body) => {
721
+ let res = await this._update(
722
+ this.svAPIEndpoint,
723
+ this.paymentTerm._path + `/${id}`,
724
+ body
725
+ );
726
+ return res;
727
+ },
728
+ remove: async (id) => {
729
+ let res = await this._delete(
730
+ this.svAPIEndpoint,
731
+ this.paymentTerm._path + `/${id}`
732
+ );
733
+ return res;
734
+ },
735
+ };
736
+ this.bank = {
737
+ _path: "/banks",
738
+ find: async (params) => {
739
+ let res = await this._fetch(
740
+ this.svAPIEndpoint,
741
+ this.bank._path,
742
+ params
743
+ );
744
+ return res;
745
+ },
746
+ get: async (id) => {
747
+ return await this._fetch(
748
+ this.svAPIEndpoint,
749
+ this.bank._path + `/${id}`
750
+ );
751
+ },
752
+ create: async (body) => {
753
+ let res = await this._create(this.svAPIEndpoint, this.bank._path, body);
754
+ return res;
755
+ },
756
+ update: async (id, body) => {
757
+ let res = await this._update(
758
+ this.svAPIEndpoint,
759
+ this.bank._path + `/${id}`,
760
+ body
761
+ );
762
+ return res;
763
+ },
764
+ };
765
+ this.customStatus = {
766
+ _path: "/custom-status",
767
+ find: async (params) => {
768
+ let res = await this._fetch(
769
+ this.svAPIEndpoint,
770
+ this.customStatus._path,
771
+ params
772
+ );
773
+ return res;
774
+ },
775
+ get: async (id) => {
776
+ return await this._fetch(
777
+ this.svAPIEndpoint,
778
+ this.customStatus._path + `/${id}`
779
+ );
780
+ },
781
+ create: async (body) => {
782
+ let res = await this._create(
783
+ this.svAPIEndpoint,
784
+ this.customStatus._path,
785
+ body
786
+ );
787
+ return res;
788
+ },
789
+ update: async (id, body) => {
790
+ let res = await this._update(
791
+ this.svAPIEndpoint,
792
+ this.customStatus._path + `/${id}`,
793
+ body
794
+ );
795
+ return res;
796
+ },
797
+ remove: async (id) => {
798
+ let res = await this._delete(
799
+ this.svAPIEndpoint,
800
+ this.customStatus._path + `/${id}`
801
+ );
802
+ return res;
803
+ },
804
+ };
805
+ this.invoice = {
806
+ _path: "/fullinvoices",
807
+ find: async (params) => {
808
+ let res = await this._fetch(
809
+ this.svAPIEndpoint,
810
+ this.invoice._path,
811
+ params
812
+ );
813
+ return res;
814
+ },
815
+ get: async (id, params) => {
816
+ return await this._fetch(
817
+ this.svAPIEndpoint,
818
+ this.invoice._path + `/${id}`,
819
+ params
820
+ );
821
+ },
822
+ create: async (body) => {
823
+ let res = await this._create(
824
+ this.svAPIEndpoint,
825
+ this.invoice._path,
826
+ body
827
+ );
828
+ return res;
829
+ },
830
+ update: async (id, body) => {
831
+ let res = await this._update(
832
+ this.svAPIEndpoint,
833
+ this.invoice._path + `/${id}`,
834
+ body
835
+ );
836
+ return res;
837
+ },
838
+ };
839
+ this.proforma = {
840
+ _path: "/proforma",
841
+ find: async (params) => {
842
+ let res = await this._fetch(
843
+ this.svAPIEndpoint,
844
+ this.proforma._path,
845
+ params
846
+ );
847
+ return res;
848
+ },
849
+ get: async (id, params) => {
850
+ return await this._fetch(
851
+ this.svAPIEndpoint,
852
+ this.proforma._path + `/${id}`,
853
+ params
854
+ );
855
+ },
856
+ create: async (body) => {
857
+ let res = await this._create(
858
+ this.svAPIEndpoint,
859
+ this.proforma._path,
860
+ body
861
+ );
862
+ return res;
863
+ },
864
+ update: async (id, body) => {
865
+ let res = await this._update(
866
+ this.svAPIEndpoint,
867
+ this.proforma._path + `/${id}`,
868
+ body
869
+ );
870
+ return res;
871
+ },
872
+ };
873
+ this.payment = {
874
+ _path: "/payments",
875
+ find: async (params) => {
876
+ let res = await this._fetch(
877
+ this.svAPIEndpoint,
878
+ this.payment._path,
879
+ params
880
+ );
881
+ return res;
882
+ },
883
+ get: async (id, params) => {
884
+ return await this._fetch(
885
+ this.svAPIEndpoint,
886
+ this.payment._path + `/${id}`,
887
+ params
888
+ );
889
+ },
890
+ create: async (body) => {
891
+ let res = await this._create(
892
+ this.svAPIEndpoint,
893
+ this.payment._path,
894
+ body
895
+ );
896
+ return res;
897
+ },
898
+ update: async (id, body) => {
899
+ let res = await this._update(
900
+ this.svAPIEndpoint,
901
+ this.payment._path + `/${id}`,
902
+ body
903
+ );
904
+ return res;
905
+ },
906
+ };
907
+ this.transfer = {
908
+ _path: "/transfer",
909
+ find: async (params) => {
910
+ let res = await this._fetch(
911
+ this.svAPIEndpoint,
912
+ this.transfer._path,
913
+ params
914
+ );
915
+ return res;
916
+ },
917
+ get: async (id, params) => {
918
+ return await this._fetch(
919
+ this.svAPIEndpoint,
920
+ this.transfer._path + `/${id}`,
921
+ params
922
+ );
923
+ },
924
+ create: async (body) => {
925
+ let res = await this._create(
926
+ this.svAPIEndpoint,
927
+ this.transfer._path,
928
+ body
929
+ );
930
+ return res;
931
+ },
932
+ update: async (id, body) => {
933
+ let res = await this._update(
934
+ this.svAPIEndpoint,
935
+ this.transfer._path + `/${id}`,
936
+ body
937
+ );
938
+ return res;
939
+ },
940
+ };
941
+ this.adjustInventory = {
942
+ _path: "/adjust-inventory",
943
+ find: async (params) => {
944
+ let res = await this._fetch(
945
+ this.svAPIEndpoint,
946
+ this.adjustInventory._path,
947
+ params
948
+ );
949
+ return res;
950
+ },
951
+ get: async (id, params) => {
952
+ return await this._fetch(
953
+ this.svAPIEndpoint,
954
+ this.adjustInventory._path + `/${id}`,
955
+ params
956
+ );
957
+ },
958
+ create: async (body) => {
959
+ let res = await this._create(
960
+ this.svAPIEndpoint,
961
+ this.adjustInventory._path,
962
+ body
963
+ );
964
+ return res;
965
+ },
966
+ };
967
+ this.inventory = {
968
+ _path: "/inventory",
969
+ find: async (params) => {
970
+ let res = await this._fetch(
971
+ this.svAPIEndpoint,
972
+ this.inventory._path,
973
+ params
974
+ );
975
+ return res;
976
+ },
977
+ };
978
+ this.integrationApp = {
979
+ _path: "/integration-app",
980
+ find: async (params) => {
981
+ let res = await this._fetch(
982
+ this.svAPIEndpoint,
983
+ this.integrationApp._path,
984
+ params
985
+ );
986
+ return res;
987
+ },
988
+ get: async (id, params) => {
989
+ return await this._fetch(
990
+ this.svAPIEndpoint,
991
+ this.integrationApp._path + `/${id}`,
992
+ params
993
+ );
994
+ },
995
+ create: async (body) => {
996
+ let res = await this._create(
997
+ this.svAPIEndpoint,
998
+ this.integrationApp._path,
999
+ body
1000
+ );
1001
+ return res;
1002
+ },
1003
+ update: async (id, body) => {
1004
+ let res = await this._update(
1005
+ this.svAPIEndpoint,
1006
+ this.integrationApp._path + `/${id}`,
1007
+ body
1008
+ );
1009
+ return res;
1010
+ },
1011
+ };
1012
+ this.joinActionsWebHook = {
1013
+ _path: "/svix-integration",
1014
+ update: async (id, body) => {
1015
+ let res = await this._update(
1016
+ this.svAPIEndpoint,
1017
+ this.payment._path,
1018
+ body
1019
+ );
1020
+ return res;
1021
+ },
1022
+ };
1023
+ this.svAPIEndpoint =
1024
+ !options?.env || options?.env == "production"
1025
+ ? "https://sv.api.repzo.me"
1026
+ : options?.env == "staging"
1027
+ ? "https://staging.sv.api.repzo.me"
1028
+ : options?.env == "local"
1029
+ ? "http://localhost:3030"
1030
+ : "";
1031
+ this.headers = {
1032
+ "api-key": apiKey,
1033
+ "Content-Type": "application/json",
1034
+ Accept: "application/json",
1035
+ };
1036
+ if (options?.headers) Object.assign(this.headers, options.headers);
1037
+ }
1038
+ async _fetch(baseUrl, path, params) {
1039
+ let res = await axios.get(baseUrl + path, {
1040
+ params,
1041
+ headers: this.headers,
1042
+ });
1043
+ return res.data;
1044
+ }
1045
+ async _create(baseUrl, path, body, params) {
1046
+ let res = await axios.post(baseUrl + path, body, {
1047
+ params,
1048
+ headers: this.headers,
1049
+ });
1050
+ return res.data;
1051
+ }
1052
+ async _update(baseUrl, path, body, params) {
1053
+ let res = await axios.put(baseUrl + path, body, {
1054
+ params,
1055
+ headers: this.headers,
1056
+ });
1057
+ return res.data;
1058
+ }
1059
+ async _delete(baseUrl, path, params) {
1060
+ let res = await axios.delete(baseUrl + path, {
1061
+ params,
1062
+ headers: this.headers,
1063
+ });
1064
+ return res.data;
1065
+ }
1066
+ }
1067
+ Repzo.ActionLogs = class {
1068
+ constructor(superThis, sync_id) {
1069
+ this.superThis = superThis;
1070
+ this._path = "/integration-action-log";
1071
+ this.available_app_name = "";
1072
+ this.available_app_id = "";
1073
+ this.app_id = "";
1074
+ this.action = "";
1075
+ this.start_time = Date.now();
1076
+ this.status = "processing";
1077
+ this.message = "Log Created";
1078
+ this.details = [];
1079
+ this.sync_id = sync_id;
1080
+ this.isOld = true;
1081
+ }
1082
+ async load(sync_id) {
1083
+ console.log(sync_id);
1084
+ const params = { sync_id: sync_id };
1085
+ const res = await this.superThis._fetch(
1086
+ this.superThis.svAPIEndpoint,
1087
+ this._path,
1088
+ params
1089
+ );
1090
+ if (res?.data?.length)
1091
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1092
+ const action_log = res.data[0];
1093
+ this.sync_id = sync_id;
1094
+ this.details = action_log.details;
1095
+ this.status = action_log.status;
1096
+ this.error = action_log.error;
1097
+ this.start_time = action_log.start_time;
1098
+ this.body = action_log.body;
1099
+ this.meta = action_log.meta;
1100
+ this.message = action_log.message;
1101
+ this.app_id = action_log._id;
1102
+ this.available_app_id = action_log.available_app_id;
1103
+ this.available_app_name = action_log.available_app_name;
1104
+ this.company_namespace = action_log.company_namespace;
1105
+ this.action = action_log.action;
1106
+ this.isOld = true;
1107
+ return this;
1108
+ }
1109
+ async setStatus(status, error) {
1110
+ this.details.push({
1111
+ timestamp: Date.now(),
1112
+ content: `status was changed from ${this.status} to ${status}`,
1113
+ });
1114
+ this.status = status;
1115
+ if (error) {
1116
+ this.error = error;
1117
+ }
1118
+ return this;
1119
+ }
1120
+ setBody(body) {
1121
+ this.body = body;
1122
+ return this;
1123
+ }
1124
+ setMeta(meta) {
1125
+ this.meta = meta;
1126
+ return this;
1127
+ }
1128
+ async commit() {
1129
+ let doc = {
1130
+ available_app_name: this.available_app_name,
1131
+ available_app_id: this.available_app_id,
1132
+ app_id: this.app_id,
1133
+ action: this.action,
1134
+ company_namespace: this.company_namespace,
1135
+ status: this.status,
1136
+ error: this.error ? this.error : undefined,
1137
+ start_time: this.start_time,
1138
+ end_time: Date.now(),
1139
+ total_time: Date.now() - this.start_time,
1140
+ body: this.body,
1141
+ meta: this.meta,
1142
+ message: this.message,
1143
+ details: this.details,
1144
+ sync_id: this.sync_id,
1145
+ };
1146
+ try {
1147
+ const res = await this.superThis._create(
1148
+ this.superThis.svAPIEndpoint,
1149
+ this._path,
1150
+ doc
1151
+ );
1152
+ } catch (e) {
1153
+ console.error(e);
1154
+ }
1155
+ return this;
1156
+ }
1157
+ addDetail(detail, meta) {
1158
+ let d = {
1159
+ timestamp: Date.now(),
1160
+ content: detail,
1161
+ };
1162
+ this.message = detail;
1163
+ if (meta) d.meta = meta;
1164
+ this.details.push(d);
1165
+ return this;
1166
+ }
1167
+ };
1168
+ Repzo.CommandLog = class {
1169
+ constructor(superThis, app, command, trigger) {
1170
+ this.superThis = superThis;
1171
+ this._path = "/integration-command-log";
1172
+ this.app_id = app._id;
1173
+ this.available_app_id = app.available_app._id;
1174
+ this.available_app_name = app.available_app.name;
1175
+ this.company_namespace = app.company_namespace;
1176
+ this.start_time = Date.now();
1177
+ this.status = "received";
1178
+ this.message = "Request received";
1179
+ this.command = command;
1180
+ this.details = [{ timestamp: Date.now(), content: "Request received" }];
1181
+ this.sync_id = uuid();
1182
+ this.isOld = false;
1183
+ this.isPrioritized = false;
1184
+ this.retries = 1;
1185
+ this.trigger = trigger;
1186
+ this.onGoing = true;
1187
+ }
1188
+ async load(sync_id, retries) {
1189
+ if (sync_id) {
1190
+ const params = { sync_id: sync_id };
1191
+ const res = await this.superThis._fetch(
1192
+ this.superThis.svAPIEndpoint,
1193
+ this._path,
1194
+ params
1195
+ );
1196
+ if (res?.data?.length)
1197
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1198
+ const command_log = res.data[0];
1199
+ if (command_log) {
1200
+ this.sync_id = sync_id;
1201
+ this.details = command_log.details;
1202
+ this.status = command_log.status;
1203
+ this.error = command_log.error;
1204
+ this.start_time = command_log.start_time;
1205
+ this.body = command_log.body;
1206
+ this.meta = command_log.meta;
1207
+ this.message = command_log.message;
1208
+ this.retries =
1209
+ retries !== undefined ? retries : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
1210
+ this.isOld = true;
1211
+ this.failedAt = command_log.failedAt;
1212
+ this.succeededAt = command_log.succeededAt;
1213
+ this.skippedAt = command_log.skippedAt;
1214
+ this.receivedAt = command_log.receivedAt;
1215
+ this.processedAt = command_log.processedAt;
1216
+ this.onGoing = command_log.onGoing || false;
1217
+ this.trigger = command_log.trigger;
1218
+ // this.priority = command_log.priority
1219
+ // ? command_log.priority
1220
+ // : this.priority
1221
+ // ? this.priority
1222
+ // : undefined;
1223
+ }
1224
+ }
1225
+ return this;
1226
+ }
1227
+ setStatus(status, error) {
1228
+ this.addDetail(`status was changed from ${this.status} to ${status}`);
1229
+ this.status = status;
1230
+ if (error) {
1231
+ this.error = error;
1232
+ }
1233
+ switch (status) {
1234
+ case "fail":
1235
+ this.failedAt = new Date();
1236
+ this.onGoing = false;
1237
+ break;
1238
+ case "processing":
1239
+ this.processedAt = new Date();
1240
+ this.onGoing = true;
1241
+ break;
1242
+ case "queued":
1243
+ this.queuedAt = new Date();
1244
+ this.onGoing = true;
1245
+ break;
1246
+ case "received":
1247
+ this.receivedAt = new Date();
1248
+ this.onGoing = true;
1249
+ break;
1250
+ case "skipped":
1251
+ this.skippedAt = new Date();
1252
+ this.onGoing = false;
1253
+ break;
1254
+ case "success":
1255
+ this.succeededAt = new Date();
1256
+ this.onGoing = false;
1257
+ break;
1258
+ }
1259
+ return this;
1260
+ }
1261
+ setBody(body) {
1262
+ this.body = body;
1263
+ return this;
1264
+ }
1265
+ setMeta(meta) {
1266
+ this.meta = meta;
1267
+ return this;
1268
+ }
1269
+ async commit() {
1270
+ let doc = {
1271
+ available_app_name: this.available_app_name,
1272
+ available_app_id: this.available_app_id,
1273
+ app_id: this.app_id,
1274
+ command: this.command,
1275
+ status: this.status,
1276
+ error: this.error ? this.error : undefined,
1277
+ start_time: this.start_time,
1278
+ end_time: Date.now(),
1279
+ total_time: Date.now() - this.start_time,
1280
+ company_namespace: this.company_namespace,
1281
+ body: this.body,
1282
+ meta: this.meta,
1283
+ message: this.message,
1284
+ details: this.details,
1285
+ sync_id: this.sync_id,
1286
+ // priority: this.priority ? this.priority : undefined,
1287
+ queuedAt: this.queuedAt ? this.queuedAt : undefined,
1288
+ failedAt: this.failedAt ? this.failedAt : undefined,
1289
+ succeededAt: this.succeededAt ? this.succeededAt : undefined,
1290
+ skippedAt: this.skippedAt ? this.skippedAt : undefined,
1291
+ receivedAt: this.receivedAt ? this.receivedAt : undefined,
1292
+ processedAt: this.processedAt ? this.processedAt : undefined,
1293
+ onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
1294
+ retries: this.retries !== undefined ? this.retries : undefined,
1295
+ trigger: this.trigger,
1296
+ };
1297
+ try {
1298
+ const res = await this.superThis._create(
1299
+ this.superThis.svAPIEndpoint,
1300
+ this._path,
1301
+ doc
1302
+ );
1303
+ this.isOld = true;
1304
+ } catch (e) {
1305
+ console.error(e);
1306
+ }
1307
+ return this;
1308
+ }
1309
+ addDetail(detail, meta) {
1310
+ let d = {
1311
+ timestamp: Date.now(),
1312
+ content: detail,
1313
+ };
1314
+ this.message = detail;
1315
+ if (meta) d.meta = meta;
1316
+ this.details.push(d);
1317
+ return this;
1318
+ }
1319
+ };