repzo 1.0.5 → 1.0.8

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/src/index.ts CHANGED
@@ -1,1426 +1,1797 @@
1
- import axios from "axios";
2
- import { Params, Data, Service, Options, Headers } from "./types/index";
3
-
4
- export default class Repzo {
5
- private svAPIEndpoint: string;
6
- headers: Headers;
7
- constructor(apiKey: string, options?: Options) {
8
- this.svAPIEndpoint =
9
- !options?.env || options?.env == "production"
10
- ? "https://sv.api.repzo.me"
11
- : options?.env == "staging"
12
- ? "https://staging.sv.api.repzo.me"
13
- : options?.env == "local"
14
- ? "http://localhost:3030"
15
- : "";
16
-
17
- this.headers = {
18
- "api-key": apiKey,
19
- "Content-Type": "application/json",
20
- Accept: "application/json",
21
- };
22
- if (options?.headers) Object.assign(this.headers, options.headers);
23
- }
24
-
25
- private async _fetch(baseUrl: string, path: string, params?: Params) {
26
- let res = await axios.get(baseUrl + path, {
27
- params,
28
- headers: this.headers,
29
- });
30
- return res.data;
31
- }
32
-
33
- private async _create(
34
- baseUrl: string,
35
- path: string,
36
- body: Data,
37
- params?: Params
38
- ) {
39
- let res = await axios.post(baseUrl + path, body, {
40
- params,
41
- headers: this.headers,
42
- });
43
- return res.data;
44
- }
45
-
46
- private async _update(
47
- baseUrl: string,
48
- path: string,
49
- body: Data,
50
- params?: Params
51
- ) {
52
- let res = await axios.put(baseUrl + path, body, {
53
- params,
54
- headers: this.headers,
55
- });
56
- return res.data;
57
- }
58
-
59
- private async _delete(baseUrl: string, path: string, params?: Params) {
60
- let res = await axios.delete(baseUrl + path, {
61
- params,
62
- headers: this.headers,
63
- });
64
- return res.data;
65
- }
66
-
67
- client = {
68
- _path: "/client",
69
- find: async (
70
- params?: Service.Client.Find.Params
71
- ): Promise<Service.Client.Find.Result> => {
72
- let res: Service.Client.Find.Result = await this._fetch(
73
- this.svAPIEndpoint,
74
- this.client._path,
75
- params
76
- );
77
- return res;
78
- },
79
-
80
- get: async (
81
- id: Service.Client.Get.ID,
82
- params?: Service.Client.Get.Params
83
- ): Promise<Service.Client.Get.Result> => {
84
- return await this._fetch(
85
- this.svAPIEndpoint,
86
- this.client._path + `/${id}`,
87
- params
88
- );
89
- },
90
-
91
- create: async (
92
- body: Service.Client.Create.Body
93
- ): Promise<Service.Client.Create.Result> => {
94
- let res = await this._create(this.svAPIEndpoint, this.client._path, body);
95
- return res;
96
- },
97
-
98
- update: async (
99
- id: Service.Client.Update.ID,
100
- body: Service.Client.Update.Body
101
- ): Promise<Service.Client.Update.Result> => {
102
- let res: Service.Client.Update.Result = await this._update(
103
- this.svAPIEndpoint,
104
- this.client._path + `/${id}`,
105
- body
106
- );
107
- return res;
108
- },
109
-
110
- remove: async (
111
- id: Service.Client.Remove.ID
112
- ): Promise<Service.Client.Remove.Result> => {
113
- let res: Service.Client.Remove.Result = await this._delete(
114
- this.svAPIEndpoint,
115
- this.client._path + `/${id}`
116
- );
117
- return res;
118
- },
119
- };
120
-
121
- product = {
122
- _path: "/product",
123
- find: async (
124
- params?: Service.Product.Find.Params
125
- ): Promise<Service.Product.Find.Result> => {
126
- let res: Service.Product.Find.Result = await this._fetch(
127
- this.svAPIEndpoint,
128
- this.product._path,
129
- params
130
- );
131
- return res;
132
- },
133
-
134
- get: async (
135
- id: Service.Product.Get.ID,
136
- params?: Service.Product.Get.Params
137
- ): Promise<Service.Product.Get.Result> => {
138
- return await this._fetch(
139
- this.svAPIEndpoint,
140
- this.product._path + `/${id}`,
141
- params
142
- );
143
- },
144
-
145
- create: async (
146
- body: Service.Product.Create.Body
147
- ): Promise<Service.Product.Create.Result> => {
148
- let res = await this._create(
149
- this.svAPIEndpoint,
150
- this.product._path,
151
- body
152
- );
153
- return res;
154
- },
155
-
156
- update: async (
157
- id: Service.Product.Update.ID,
158
- body: Service.Product.Update.Body
159
- ): Promise<Service.Product.Update.Result> => {
160
- let res: Service.Product.Update.Result = await this._update(
161
- this.svAPIEndpoint,
162
- this.product._path + `/${id}`,
163
- body
164
- );
165
- return res;
166
- },
167
-
168
- remove: async (
169
- id: Service.Product.Remove.ID
170
- ): Promise<Service.Product.Remove.Result> => {
171
- let res: Service.Product.Remove.Result = await this._delete(
172
- this.svAPIEndpoint,
173
- this.product._path + `/${id}`
174
- );
175
- return res;
176
- },
177
- };
178
-
179
- variant = {
180
- _path: "/variant",
181
- find: async (
182
- params?: Service.Variant.Find.Params
183
- ): Promise<Service.Variant.Find.Result> => {
184
- let res: Service.Variant.Find.Result = await this._fetch(
185
- this.svAPIEndpoint,
186
- this.variant._path,
187
- params
188
- );
189
- return res;
190
- },
191
-
192
- get: async (
193
- id: Service.Variant.Get.ID,
194
- params?: Service.Variant.Get.Params
195
- ): Promise<Service.Variant.Get.Result> => {
196
- return await this._fetch(
197
- this.svAPIEndpoint,
198
- this.variant._path + `/${id}`,
199
- params
200
- );
201
- },
202
-
203
- create: async (
204
- body: Service.Variant.Create.Body
205
- ): Promise<Service.Variant.Create.Result> => {
206
- let res = await this._create(
207
- this.svAPIEndpoint,
208
- this.variant._path,
209
- body
210
- );
211
- return res;
212
- },
213
-
214
- update: async (
215
- id: Service.Variant.Update.ID,
216
- body: Service.Variant.Update.Body
217
- ): Promise<Service.Variant.Update.Result> => {
218
- let res: Service.Variant.Update.Result = await this._update(
219
- this.svAPIEndpoint,
220
- this.variant._path + `/${id}`,
221
- body
222
- );
223
- return res;
224
- },
225
-
226
- remove: async (
227
- id: Service.Variant.Remove.ID
228
- ): Promise<Service.Variant.Remove.Result> => {
229
- let res: Service.Variant.Remove.Result = await this._delete(
230
- this.svAPIEndpoint,
231
- this.variant._path + `/${id}`
232
- );
233
- return res;
234
- },
235
- };
236
-
237
- category = {
238
- _path: "/product-category",
239
- find: async (
240
- params?: Service.Category.Find.Params
241
- ): Promise<Service.Category.Find.Result> => {
242
- let res: Service.Category.Find.Result = await this._fetch(
243
- this.svAPIEndpoint,
244
- this.category._path,
245
- params
246
- );
247
- return res;
248
- },
249
-
250
- get: async (
251
- id: Service.Category.Get.ID
252
- ): Promise<Service.Category.Get.Result> => {
253
- return await this._fetch(
254
- this.svAPIEndpoint,
255
- this.category._path + `/${id}`
256
- );
257
- },
258
-
259
- create: async (
260
- body: Service.Category.Create.Body
261
- ): Promise<Service.Category.Create.Result> => {
262
- let res = await this._create(
263
- this.svAPIEndpoint,
264
- this.category._path,
265
- body
266
- );
267
- return res;
268
- },
269
-
270
- update: async (
271
- id: Service.Category.Update.ID,
272
- body: Service.Category.Update.Body
273
- ): Promise<Service.Category.Update.Result> => {
274
- let res: Service.Category.Update.Result = await this._update(
275
- this.svAPIEndpoint,
276
- this.category._path + `/${id}`,
277
- body
278
- );
279
- return res;
280
- },
281
-
282
- remove: async (
283
- id: Service.Category.Remove.ID
284
- ): Promise<Service.Category.Remove.Result> => {
285
- let res: Service.Category.Remove.Result = await this._delete(
286
- this.svAPIEndpoint,
287
- this.category._path + `/${id}`
288
- );
289
- return res;
290
- },
291
- };
292
-
293
- sub_category = {
294
- _path: "/product-sub-category",
295
- find: async (
296
- params?: Service.SubCategory.Find.Params
297
- ): Promise<Service.SubCategory.Find.Result> => {
298
- let res: Service.SubCategory.Find.Result = await this._fetch(
299
- this.svAPIEndpoint,
300
- this.sub_category._path,
301
- params
302
- );
303
- return res;
304
- },
305
-
306
- get: async (
307
- id: Service.SubCategory.Get.ID,
308
- params?: Service.SubCategory.Get.Params
309
- ): Promise<Service.SubCategory.Get.Result> => {
310
- return await this._fetch(
311
- this.svAPIEndpoint,
312
- this.sub_category._path + `/${id}`,
313
- params
314
- );
315
- },
316
-
317
- create: async (
318
- body: Service.SubCategory.Create.Body
319
- ): Promise<Service.SubCategory.Create.Result> => {
320
- let res = await this._create(
321
- this.svAPIEndpoint,
322
- this.sub_category._path,
323
- body
324
- );
325
- return res;
326
- },
327
-
328
- update: async (
329
- id: Service.SubCategory.Update.ID,
330
- body: Service.SubCategory.Update.Body
331
- ): Promise<Service.SubCategory.Update.Result> => {
332
- let res: Service.SubCategory.Update.Result = await this._update(
333
- this.svAPIEndpoint,
334
- this.sub_category._path + `/${id}`,
335
- body
336
- );
337
- return res;
338
- },
339
-
340
- remove: async (
341
- id: Service.SubCategory.Remove.ID
342
- ): Promise<Service.SubCategory.Remove.Result> => {
343
- let res: Service.SubCategory.Remove.Result = await this._delete(
344
- this.svAPIEndpoint,
345
- this.sub_category._path + `/${id}`
346
- );
347
- return res;
348
- },
349
- };
350
-
351
- brand = {
352
- _path: "/product-brand",
353
- find: async (
354
- params?: Service.Brand.Find.Params
355
- ): Promise<Service.Brand.Find.Result> => {
356
- let res: Service.Brand.Find.Result = await this._fetch(
357
- this.svAPIEndpoint,
358
- this.brand._path,
359
- params
360
- );
361
- return res;
362
- },
363
-
364
- get: async (
365
- id: Service.Brand.Get.ID
366
- ): Promise<Service.Brand.Get.Result> => {
367
- return await this._fetch(this.svAPIEndpoint, this.brand._path + `/${id}`);
368
- },
369
-
370
- create: async (
371
- body: Service.Brand.Create.Body
372
- ): Promise<Service.Brand.Create.Result> => {
373
- let res = await this._create(this.svAPIEndpoint, this.brand._path, body);
374
- return res;
375
- },
376
-
377
- update: async (
378
- id: Service.Brand.Update.ID,
379
- body: Service.Brand.Update.Body
380
- ): Promise<Service.Brand.Update.Result> => {
381
- let res: Service.Brand.Update.Result = await this._update(
382
- this.svAPIEndpoint,
383
- this.brand._path + `/${id}`,
384
- body
385
- );
386
- return res;
387
- },
388
-
389
- remove: async (
390
- id: Service.Brand.Remove.ID
391
- ): Promise<Service.Brand.Remove.Result> => {
392
- let res: Service.Brand.Remove.Result = await this._delete(
393
- this.svAPIEndpoint,
394
- this.brand._path + `/${id}`
395
- );
396
- return res;
397
- },
398
- };
399
-
400
- product_group = {
401
- _path: "/product-group",
402
- find: async (
403
- params?: Service.ProductGroup.Find.Params
404
- ): Promise<Service.ProductGroup.Find.Result> => {
405
- let res: Service.ProductGroup.Find.Result = await this._fetch(
406
- this.svAPIEndpoint,
407
- this.product_group._path,
408
- params
409
- );
410
- return res;
411
- },
412
-
413
- get: async (
414
- id: Service.ProductGroup.Get.ID
415
- ): Promise<Service.ProductGroup.Get.Result> => {
416
- return await this._fetch(
417
- this.svAPIEndpoint,
418
- this.product_group._path + `/${id}`
419
- );
420
- },
421
-
422
- create: async (
423
- body: Service.ProductGroup.Create.Body
424
- ): Promise<Service.ProductGroup.Create.Result> => {
425
- let res = await this._create(
426
- this.svAPIEndpoint,
427
- this.product_group._path,
428
- body
429
- );
430
- return res;
431
- },
432
-
433
- update: async (
434
- id: Service.ProductGroup.Update.ID,
435
- body: Service.ProductGroup.Update.Body
436
- ): Promise<Service.ProductGroup.Update.Result> => {
437
- let res: Service.ProductGroup.Update.Result = await this._update(
438
- this.svAPIEndpoint,
439
- this.product_group._path + `/${id}`,
440
- body
441
- );
442
- return res;
443
- },
444
-
445
- remove: async (
446
- id: Service.ProductGroup.Remove.ID
447
- ): Promise<Service.ProductGroup.Remove.Result> => {
448
- let res: Service.ProductGroup.Remove.Result = await this._delete(
449
- this.svAPIEndpoint,
450
- this.product_group._path + `/${id}`
451
- );
452
- return res;
453
- },
454
- };
455
-
456
- tax = {
457
- _path: "/tax",
458
- find: async (
459
- params?: Service.Tax.Find.Params
460
- ): Promise<Service.Tax.Find.Result> => {
461
- let res: Service.Tax.Find.Result = await this._fetch(
462
- this.svAPIEndpoint,
463
- this.tax._path,
464
- params
465
- );
466
- return res;
467
- },
468
-
469
- get: async (id: Service.Tax.Get.ID): Promise<Service.Tax.Get.Result> => {
470
- return await this._fetch(this.svAPIEndpoint, this.tax._path + `/${id}`);
471
- },
472
-
473
- create: async (
474
- body: Service.Tax.Create.Body
475
- ): Promise<Service.Tax.Create.Result> => {
476
- let res = await this._create(this.svAPIEndpoint, this.tax._path, body);
477
- return res;
478
- },
479
-
480
- update: async (
481
- id: Service.Tax.Update.ID,
482
- body: Service.Tax.Update.Body
483
- ): Promise<Service.Tax.Update.Result> => {
484
- let res: Service.Tax.Update.Result = await this._update(
485
- this.svAPIEndpoint,
486
- this.tax._path + `/${id}`,
487
- body
488
- );
489
- return res;
490
- },
491
-
492
- remove: async (
493
- id: Service.Tax.Remove.ID
494
- ): Promise<Service.Tax.Remove.Result> => {
495
- let res: Service.Tax.Remove.Result = await this._delete(
496
- this.svAPIEndpoint,
497
- this.tax._path + `/${id}`
498
- );
499
- return res;
500
- },
501
- };
502
-
503
- measureunit = {
504
- _path: "/measureunits",
505
- find: async (
506
- params?: Service.MeasureUnit.Find.Params
507
- ): Promise<Service.MeasureUnit.Find.Result> => {
508
- let res: Service.MeasureUnit.Find.Result = await this._fetch(
509
- this.svAPIEndpoint,
510
- this.measureunit._path,
511
- params
512
- );
513
- return res;
514
- },
515
-
516
- get: async (
517
- id: Service.MeasureUnit.Get.ID
518
- ): Promise<Service.MeasureUnit.Get.Result> => {
519
- return await this._fetch(
520
- this.svAPIEndpoint,
521
- this.measureunit._path + `/${id}`
522
- );
523
- },
524
-
525
- create: async (
526
- body: Service.MeasureUnit.Create.Body
527
- ): Promise<Service.MeasureUnit.Create.Result> => {
528
- let res = await this._create(
529
- this.svAPIEndpoint,
530
- this.measureunit._path,
531
- body
532
- );
533
- return res;
534
- },
535
-
536
- update: async (
537
- id: Service.MeasureUnit.Update.ID,
538
- body: Service.MeasureUnit.Update.Body
539
- ): Promise<Service.MeasureUnit.Update.Result> => {
540
- let res: Service.MeasureUnit.Update.Result = await this._update(
541
- this.svAPIEndpoint,
542
- this.measureunit._path + `/${id}`,
543
- body
544
- );
545
- return res;
546
- },
547
-
548
- remove: async (
549
- id: Service.MeasureUnit.Remove.ID
550
- ): Promise<Service.MeasureUnit.Remove.Result> => {
551
- let res: Service.MeasureUnit.Remove.Result = await this._delete(
552
- this.svAPIEndpoint,
553
- this.measureunit._path + `/${id}`
554
- );
555
- return res;
556
- },
557
- };
558
-
559
- measureunitFamily = {
560
- _path: "/measureunit-family",
561
- find: async (
562
- params?: Service.MeasureUnitFamily.Find.Params
563
- ): Promise<Service.MeasureUnitFamily.Find.Result> => {
564
- let res: Service.MeasureUnitFamily.Find.Result = await this._fetch(
565
- this.svAPIEndpoint,
566
- this.measureunitFamily._path,
567
- params
568
- );
569
- return res;
570
- },
571
-
572
- get: async (
573
- id: Service.MeasureUnitFamily.Get.ID
574
- ): Promise<Service.MeasureUnitFamily.Get.Result> => {
575
- return await this._fetch(
576
- this.svAPIEndpoint,
577
- this.measureunitFamily._path + `/${id}`
578
- );
579
- },
580
-
581
- create: async (
582
- body: Service.MeasureUnitFamily.Create.Body
583
- ): Promise<Service.MeasureUnitFamily.Create.Result> => {
584
- let res = await this._create(
585
- this.svAPIEndpoint,
586
- this.measureunitFamily._path,
587
- body
588
- );
589
- return res;
590
- },
591
-
592
- update: async (
593
- id: Service.MeasureUnitFamily.Update.ID,
594
- body: Service.MeasureUnitFamily.Update.Body
595
- ): Promise<Service.MeasureUnitFamily.Update.Result> => {
596
- let res: Service.MeasureUnitFamily.Update.Result = await this._update(
597
- this.svAPIEndpoint,
598
- this.measureunitFamily._path + `/${id}`,
599
- body
600
- );
601
- return res;
602
- },
603
-
604
- remove: async (
605
- id: Service.MeasureUnitFamily.Remove.ID
606
- ): Promise<Service.MeasureUnitFamily.Remove.Result> => {
607
- let res: Service.MeasureUnitFamily.Remove.Result = await this._delete(
608
- this.svAPIEndpoint,
609
- this.measureunitFamily._path + `/${id}`
610
- );
611
- return res;
612
- },
613
- };
614
-
615
- media = {
616
- _path: "/media",
617
- find: async (
618
- params?: Service.Media.Find.Params
619
- ): Promise<Service.Media.Find.Result> => {
620
- let res: Service.Media.Find.Result = await this._fetch(
621
- this.svAPIEndpoint,
622
- this.media._path,
623
- params
624
- );
625
- return res;
626
- },
627
-
628
- get: async (
629
- id: Service.Media.Get.ID
630
- ): Promise<Service.Media.Get.Result> => {
631
- return await this._fetch(this.svAPIEndpoint, this.media._path + `/${id}`);
632
- },
633
-
634
- create: async (
635
- body: Service.Media.Create.Body
636
- ): Promise<Service.Media.Create.Result> => {
637
- let res = await this._create(this.svAPIEndpoint, this.media._path, body);
638
- return res;
639
- },
640
-
641
- update: async (
642
- id: Service.Media.Update.ID,
643
- body: Service.Media.Update.Body
644
- ): Promise<Service.Media.Update.Result> => {
645
- let res: Service.Media.Update.Result = await this._update(
646
- this.svAPIEndpoint,
647
- this.media._path + `/${id}`,
648
- body
649
- );
650
- return res;
651
- },
652
-
653
- remove: async (
654
- id: Service.Media.Remove.ID
655
- ): Promise<Service.Media.Remove.Result> => {
656
- let res: Service.Media.Remove.Result = await this._delete(
657
- this.svAPIEndpoint,
658
- this.media._path + `/${id}`
659
- );
660
- return res;
661
- },
662
- };
663
-
664
- priceList = {
665
- _path: "/pricelists",
666
- find: async (
667
- params?: Service.PriceList.Find.Params
668
- ): Promise<Service.PriceList.Find.Result> => {
669
- let res: Service.PriceList.Find.Result = await this._fetch(
670
- this.svAPIEndpoint,
671
- this.priceList._path,
672
- params
673
- );
674
- return res;
675
- },
676
-
677
- get: async (
678
- id: Service.PriceList.Get.ID
679
- ): Promise<Service.PriceList.Get.Result> => {
680
- return await this._fetch(
681
- this.svAPIEndpoint,
682
- this.priceList._path + `/${id}`
683
- );
684
- },
685
-
686
- create: async (
687
- body: Service.PriceList.Create.Body
688
- ): Promise<Service.PriceList.Create.Result> => {
689
- let res = await this._create(
690
- this.svAPIEndpoint,
691
- this.priceList._path,
692
- body
693
- );
694
- return res;
695
- },
696
-
697
- update: async (
698
- id: Service.PriceList.Update.ID,
699
- body: Service.PriceList.Update.Body
700
- ): Promise<Service.PriceList.Update.Result> => {
701
- let res: Service.PriceList.Update.Result = await this._update(
702
- this.svAPIEndpoint,
703
- this.priceList._path + `/${id}`,
704
- body
705
- );
706
- return res;
707
- },
708
-
709
- remove: async (
710
- id: Service.PriceList.Remove.ID
711
- ): Promise<Service.PriceList.Remove.Result> => {
712
- let res: Service.PriceList.Remove.Result = await this._delete(
713
- this.svAPIEndpoint,
714
- this.priceList._path + `/${id}`
715
- );
716
- return res;
717
- },
718
- };
719
-
720
- priceListItem = {
721
- _path: "/pricelists",
722
- find: async (
723
- params?: Service.PriceListItem.Find.Params
724
- ): Promise<Service.PriceListItem.Find.Result> => {
725
- let res: Service.PriceListItem.Find.Result = await this._fetch(
726
- this.svAPIEndpoint,
727
- this.priceListItem._path,
728
- params
729
- );
730
- return res;
731
- },
732
-
733
- get: async (
734
- id: Service.PriceListItem.Get.ID
735
- ): Promise<Service.PriceListItem.Get.Result> => {
736
- return await this._fetch(
737
- this.svAPIEndpoint,
738
- this.priceListItem._path + `/${id}`
739
- );
740
- },
741
-
742
- create: async (
743
- body: Service.PriceListItem.Create.Body
744
- ): Promise<Service.PriceListItem.Create.Result> => {
745
- let res = await this._create(
746
- this.svAPIEndpoint,
747
- this.priceListItem._path,
748
- body
749
- );
750
- return res;
751
- },
752
-
753
- update: async (
754
- id: Service.PriceListItem.Update.ID,
755
- body: Service.PriceListItem.Update.Body
756
- ): Promise<Service.PriceListItem.Update.Result> => {
757
- let res: Service.PriceListItem.Update.Result = await this._update(
758
- this.svAPIEndpoint,
759
- this.priceListItem._path + `/${id}`,
760
- body
761
- );
762
- return res;
763
- },
764
-
765
- remove: async (
766
- id: Service.PriceListItem.Remove.ID
767
- ): Promise<Service.PriceListItem.Remove.Result> => {
768
- let res: Service.PriceListItem.Remove.Result = await this._delete(
769
- this.svAPIEndpoint,
770
- this.priceListItem._path + `/${id}`
771
- );
772
- return res;
773
- },
774
- };
775
-
776
- team = {
777
- _path: "/teams",
778
- find: async (
779
- params?: Service.Team.Find.Params
780
- ): Promise<Service.Team.Find.Result> => {
781
- let res: Service.Team.Find.Result = await this._fetch(
782
- this.svAPIEndpoint,
783
- this.team._path,
784
- params
785
- );
786
- return res;
787
- },
788
-
789
- get: async (id: Service.Team.Get.ID): Promise<Service.Team.Get.Result> => {
790
- return await this._fetch(this.svAPIEndpoint, this.team._path + `/${id}`);
791
- },
792
-
793
- create: async (
794
- body: Service.Team.Create.Body
795
- ): Promise<Service.Team.Create.Result> => {
796
- let res = await this._create(this.svAPIEndpoint, this.team._path, body);
797
- return res;
798
- },
799
-
800
- update: async (
801
- id: Service.Team.Update.ID,
802
- body: Service.Team.Update.Body
803
- ): Promise<Service.Team.Update.Result> => {
804
- let res: Service.Team.Update.Result = await this._update(
805
- this.svAPIEndpoint,
806
- this.team._path + `/${id}`,
807
- body
808
- );
809
- return res;
810
- },
811
-
812
- remove: async (
813
- id: Service.Team.Remove.ID
814
- ): Promise<Service.Team.Remove.Result> => {
815
- let res: Service.Team.Remove.Result = await this._delete(
816
- this.svAPIEndpoint,
817
- this.team._path + `/${id}`
818
- );
819
- return res;
820
- },
821
- };
822
-
823
- rep = {
824
- _path: "/rep",
825
- find: async (
826
- params?: Service.Rep.Find.Params
827
- ): Promise<Service.Rep.Find.Result> => {
828
- let res: Service.Rep.Find.Result = await this._fetch(
829
- this.svAPIEndpoint,
830
- this.rep._path,
831
- params
832
- );
833
- return res;
834
- },
835
-
836
- get: async (
837
- id: Service.Rep.Get.ID,
838
- params?: Service.Client.Get.Params
839
- ): Promise<Service.Rep.Get.Result> => {
840
- return await this._fetch(
841
- this.svAPIEndpoint,
842
- this.rep._path + `/${id}`,
843
- params
844
- );
845
- },
846
-
847
- create: async (
848
- body: Service.Rep.Create.Body
849
- ): Promise<Service.Rep.Create.Result> => {
850
- let res = await this._create(this.svAPIEndpoint, this.rep._path, body);
851
- return res;
852
- },
853
-
854
- update: async (
855
- id: Service.Rep.Update.ID,
856
- body: Service.Rep.Update.Body
857
- ): Promise<Service.Rep.Update.Result> => {
858
- let res: Service.Rep.Update.Result = await this._update(
859
- this.svAPIEndpoint,
860
- this.rep._path + `/${id}`,
861
- body
862
- );
863
- return res;
864
- },
865
-
866
- remove: async (
867
- id: Service.Rep.Remove.ID
868
- ): Promise<Service.Rep.Remove.Result> => {
869
- let res: Service.Rep.Remove.Result = await this._delete(
870
- this.svAPIEndpoint,
871
- this.rep._path + `/${id}`
872
- );
873
- return res;
874
- },
875
- };
876
-
877
- tag = {
878
- _path: "/tag",
879
- find: async (
880
- params?: Service.Tag.Find.Params
881
- ): Promise<Service.Tag.Find.Result> => {
882
- let res: Service.Tag.Find.Result = await this._fetch(
883
- this.svAPIEndpoint,
884
- this.tag._path,
885
- params
886
- );
887
- return res;
888
- },
889
-
890
- get: async (id: Service.Tag.Get.ID): Promise<Service.Tag.Get.Result> => {
891
- return await this._fetch(this.svAPIEndpoint, this.tag._path + `/${id}`);
892
- },
893
-
894
- create: async (
895
- body: Service.Tag.Create.Body
896
- ): Promise<Service.Tag.Create.Result> => {
897
- let res = await this._create(this.svAPIEndpoint, this.tag._path, body);
898
- return res;
899
- },
900
-
901
- update: async (
902
- id: Service.Tag.Update.ID,
903
- body: Service.Tag.Update.Body
904
- ): Promise<Service.Tag.Update.Result> => {
905
- let res: Service.Tag.Update.Result = await this._update(
906
- this.svAPIEndpoint,
907
- this.tag._path + `/${id}`,
908
- body
909
- );
910
- return res;
911
- },
912
-
913
- remove: async (
914
- id: Service.Tag.Remove.ID
915
- ): Promise<Service.Tag.Remove.Result> => {
916
- let res: Service.Tag.Remove.Result = await this._delete(
917
- this.svAPIEndpoint,
918
- this.tag._path + `/${id}`
919
- );
920
- return res;
921
- },
922
- };
923
-
924
- warehouse = {
925
- _path: "/warehouse",
926
- find: async (
927
- params?: Service.Warehouse.Find.Params
928
- ): Promise<Service.Warehouse.Find.Result> => {
929
- let res: Service.Warehouse.Find.Result = await this._fetch(
930
- this.svAPIEndpoint,
931
- this.warehouse._path,
932
- params
933
- );
934
- return res;
935
- },
936
-
937
- get: async (
938
- id: Service.Warehouse.Get.ID
939
- ): Promise<Service.Warehouse.Get.Result> => {
940
- return await this._fetch(
941
- this.svAPIEndpoint,
942
- this.warehouse._path + `/${id}`
943
- );
944
- },
945
-
946
- create: async (
947
- body: Service.Warehouse.Create.Body
948
- ): Promise<Service.Warehouse.Create.Result> => {
949
- let res = await this._create(
950
- this.svAPIEndpoint,
951
- this.warehouse._path,
952
- body
953
- );
954
- return res;
955
- },
956
-
957
- update: async (
958
- id: Service.Warehouse.Update.ID,
959
- body: Service.Warehouse.Update.Body
960
- ): Promise<Service.Warehouse.Update.Result> => {
961
- let res: Service.Warehouse.Update.Result = await this._update(
962
- this.svAPIEndpoint,
963
- this.warehouse._path + `/${id}`,
964
- body
965
- );
966
- return res;
967
- },
968
-
969
- remove: async (
970
- id: Service.Warehouse.Remove.ID
971
- ): Promise<Service.Warehouse.Remove.Result> => {
972
- let res: Service.Warehouse.Remove.Result = await this._delete(
973
- this.svAPIEndpoint,
974
- this.warehouse._path + `/${id}`
975
- );
976
- return res;
977
- },
978
- };
979
-
980
- channel = {
981
- _path: "/client-channel",
982
- find: async (
983
- params?: Service.Channel.Find.Params
984
- ): Promise<Service.Channel.Find.Result> => {
985
- let res: Service.Channel.Find.Result = await this._fetch(
986
- this.svAPIEndpoint,
987
- this.channel._path,
988
- params
989
- );
990
- return res;
991
- },
992
-
993
- get: async (
994
- id: Service.Channel.Get.ID
995
- ): Promise<Service.Channel.Get.Result> => {
996
- return await this._fetch(
997
- this.svAPIEndpoint,
998
- this.channel._path + `/${id}`
999
- );
1000
- },
1001
-
1002
- create: async (
1003
- body: Service.Channel.Create.Body
1004
- ): Promise<Service.Channel.Create.Result> => {
1005
- let res = await this._create(
1006
- this.svAPIEndpoint,
1007
- this.channel._path,
1008
- body
1009
- );
1010
- return res;
1011
- },
1012
-
1013
- update: async (
1014
- id: Service.Channel.Update.ID,
1015
- body: Service.Channel.Update.Body
1016
- ): Promise<Service.Channel.Update.Result> => {
1017
- let res: Service.Channel.Update.Result = await this._update(
1018
- this.svAPIEndpoint,
1019
- this.channel._path + `/${id}`,
1020
- body
1021
- );
1022
- return res;
1023
- },
1024
-
1025
- remove: async (
1026
- id: Service.Channel.Remove.ID
1027
- ): Promise<Service.Channel.Remove.Result> => {
1028
- let res: Service.Channel.Remove.Result = await this._delete(
1029
- this.svAPIEndpoint,
1030
- this.channel._path + `/${id}`
1031
- );
1032
- return res;
1033
- },
1034
- };
1035
-
1036
- paymentTerm = {
1037
- _path: "/paymentterms",
1038
- find: async (
1039
- params?: Service.PaymentTerm.Find.Params
1040
- ): Promise<Service.PaymentTerm.Find.Result> => {
1041
- let res: Service.PaymentTerm.Find.Result = await this._fetch(
1042
- this.svAPIEndpoint,
1043
- this.paymentTerm._path,
1044
- params
1045
- );
1046
- return res;
1047
- },
1048
-
1049
- get: async (
1050
- id: Service.PaymentTerm.Get.ID
1051
- ): Promise<Service.PaymentTerm.Get.Result> => {
1052
- return await this._fetch(
1053
- this.svAPIEndpoint,
1054
- this.paymentTerm._path + `/${id}`
1055
- );
1056
- },
1057
-
1058
- create: async (
1059
- body: Service.PaymentTerm.Create.Body
1060
- ): Promise<Service.PaymentTerm.Create.Result> => {
1061
- let res = await this._create(
1062
- this.svAPIEndpoint,
1063
- this.paymentTerm._path,
1064
- body
1065
- );
1066
- return res;
1067
- },
1068
-
1069
- update: async (
1070
- id: Service.PaymentTerm.Update.ID,
1071
- body: Service.PaymentTerm.Update.Body
1072
- ): Promise<Service.PaymentTerm.Update.Result> => {
1073
- let res: Service.PaymentTerm.Update.Result = await this._update(
1074
- this.svAPIEndpoint,
1075
- this.paymentTerm._path + `/${id}`,
1076
- body
1077
- );
1078
- return res;
1079
- },
1080
-
1081
- remove: async (
1082
- id: Service.PaymentTerm.Remove.ID
1083
- ): Promise<Service.PaymentTerm.Remove.Result> => {
1084
- let res: Service.PaymentTerm.Remove.Result = await this._delete(
1085
- this.svAPIEndpoint,
1086
- this.paymentTerm._path + `/${id}`
1087
- );
1088
- return res;
1089
- },
1090
- };
1091
-
1092
- bank = {
1093
- _path: "/banks",
1094
- find: async (
1095
- params?: Service.Bank.Find.Params
1096
- ): Promise<Service.Bank.Find.Result> => {
1097
- let res: Service.Bank.Find.Result = await this._fetch(
1098
- this.svAPIEndpoint,
1099
- this.bank._path,
1100
- params
1101
- );
1102
- return res;
1103
- },
1104
-
1105
- get: async (id: Service.Bank.Get.ID): Promise<Service.Bank.Get.Result> => {
1106
- return await this._fetch(this.svAPIEndpoint, this.bank._path + `/${id}`);
1107
- },
1108
-
1109
- create: async (
1110
- body: Service.Bank.Create.Body
1111
- ): Promise<Service.Bank.Create.Result> => {
1112
- let res = await this._create(this.svAPIEndpoint, this.bank._path, body);
1113
- return res;
1114
- },
1115
-
1116
- update: async (
1117
- id: Service.Bank.Update.ID,
1118
- body: Service.Bank.Update.Body
1119
- ): Promise<Service.Bank.Update.Result> => {
1120
- let res: Service.Bank.Update.Result = await this._update(
1121
- this.svAPIEndpoint,
1122
- this.bank._path + `/${id}`,
1123
- body
1124
- );
1125
- return res;
1126
- },
1127
- };
1128
-
1129
- customStatus = {
1130
- _path: "/custom-status",
1131
- find: async (
1132
- params?: Service.CustomStatus.Find.Params
1133
- ): Promise<Service.CustomStatus.Find.Result> => {
1134
- let res: Service.CustomStatus.Find.Result = await this._fetch(
1135
- this.svAPIEndpoint,
1136
- this.customStatus._path,
1137
- params
1138
- );
1139
- return res;
1140
- },
1141
-
1142
- get: async (
1143
- id: Service.CustomStatus.Get.ID
1144
- ): Promise<Service.CustomStatus.Get.Result> => {
1145
- return await this._fetch(
1146
- this.svAPIEndpoint,
1147
- this.customStatus._path + `/${id}`
1148
- );
1149
- },
1150
-
1151
- create: async (
1152
- body: Service.CustomStatus.Create.Body
1153
- ): Promise<Service.CustomStatus.Create.Result> => {
1154
- let res = await this._create(
1155
- this.svAPIEndpoint,
1156
- this.customStatus._path,
1157
- body
1158
- );
1159
- return res;
1160
- },
1161
-
1162
- update: async (
1163
- id: Service.CustomStatus.Update.ID,
1164
- body: Service.CustomStatus.Update.Body
1165
- ): Promise<Service.CustomStatus.Update.Result> => {
1166
- let res: Service.CustomStatus.Update.Result = await this._update(
1167
- this.svAPIEndpoint,
1168
- this.customStatus._path + `/${id}`,
1169
- body
1170
- );
1171
- return res;
1172
- },
1173
-
1174
- remove: async (
1175
- id: Service.CustomStatus.Remove.ID
1176
- ): Promise<Service.CustomStatus.Remove.Result> => {
1177
- let res: Service.CustomStatus.Remove.Result = await this._delete(
1178
- this.svAPIEndpoint,
1179
- this.customStatus._path + `/${id}`
1180
- );
1181
- return res;
1182
- },
1183
- };
1184
-
1185
- invoice = {
1186
- _path: "/fullinvoices",
1187
- find: async (
1188
- params?: Service.FullInvoice.Find.Params
1189
- ): Promise<Service.FullInvoice.Find.Result> => {
1190
- let res: Service.FullInvoice.Find.Result = await this._fetch(
1191
- this.svAPIEndpoint,
1192
- this.invoice._path,
1193
- params
1194
- );
1195
- return res;
1196
- },
1197
-
1198
- get: async (
1199
- id: Service.FullInvoice.Get.ID,
1200
- params?: Service.FullInvoice.Get.Params
1201
- ): Promise<Service.FullInvoice.Get.Result> => {
1202
- return await this._fetch(
1203
- this.svAPIEndpoint,
1204
- this.invoice._path + `/${id}`,
1205
- params
1206
- );
1207
- },
1208
-
1209
- create: async (
1210
- body: Service.FullInvoice.Create.Body
1211
- ): Promise<Service.FullInvoice.Create.Result> => {
1212
- let res = await this._create(
1213
- this.svAPIEndpoint,
1214
- this.invoice._path,
1215
- body
1216
- );
1217
- return res;
1218
- },
1219
-
1220
- update: async (
1221
- id: Service.FullInvoice.Update.ID,
1222
- body: Service.FullInvoice.Update.Body
1223
- ): Promise<Service.FullInvoice.Update.Result> => {
1224
- let res: Service.FullInvoice.Update.Result = await this._update(
1225
- this.svAPIEndpoint,
1226
- this.invoice._path + `/${id}`,
1227
- body
1228
- );
1229
- return res;
1230
- },
1231
- };
1232
-
1233
- proforma = {
1234
- _path: "/proforma",
1235
- find: async (
1236
- params?: Service.Proforma.Find.Params
1237
- ): Promise<Service.Proforma.Find.Result> => {
1238
- let res: Service.Proforma.Find.Result = await this._fetch(
1239
- this.svAPIEndpoint,
1240
- this.proforma._path,
1241
- params
1242
- );
1243
- return res;
1244
- },
1245
-
1246
- get: async (
1247
- id: Service.Proforma.Get.ID,
1248
- params?: Service.Proforma.Get.Params
1249
- ): Promise<Service.Proforma.Get.Result> => {
1250
- return await this._fetch(
1251
- this.svAPIEndpoint,
1252
- this.proforma._path + `/${id}`,
1253
- params
1254
- );
1255
- },
1256
-
1257
- create: async (
1258
- body: Service.Proforma.Create.Body
1259
- ): Promise<Service.Proforma.Create.Result> => {
1260
- let res = await this._create(
1261
- this.svAPIEndpoint,
1262
- this.proforma._path,
1263
- body
1264
- );
1265
- return res;
1266
- },
1267
-
1268
- update: async (
1269
- id: Service.Proforma.Update.ID,
1270
- body: Service.Proforma.Update.Body
1271
- ): Promise<Service.Proforma.Update.Result> => {
1272
- let res: Service.Proforma.Update.Result = await this._update(
1273
- this.svAPIEndpoint,
1274
- this.proforma._path + `/${id}`,
1275
- body
1276
- );
1277
- return res;
1278
- },
1279
- };
1280
-
1281
- payment = {
1282
- _path: "/payments",
1283
- find: async (
1284
- params?: Service.Payment.Find.Params
1285
- ): Promise<Service.Payment.Find.Result> => {
1286
- let res: Service.Payment.Find.Result = await this._fetch(
1287
- this.svAPIEndpoint,
1288
- this.payment._path,
1289
- params
1290
- );
1291
- return res;
1292
- },
1293
-
1294
- get: async (
1295
- id: Service.Payment.Get.ID,
1296
- params?: Service.Payment.Get.Params
1297
- ): Promise<Service.Payment.Get.Result> => {
1298
- return await this._fetch(
1299
- this.svAPIEndpoint,
1300
- this.payment._path + `/${id}`,
1301
- params
1302
- );
1303
- },
1304
-
1305
- create: async (
1306
- body: Service.Payment.Create.Body
1307
- ): Promise<Service.Payment.Create.Result> => {
1308
- let res = await this._create(
1309
- this.svAPIEndpoint,
1310
- this.payment._path,
1311
- body
1312
- );
1313
- return res;
1314
- },
1315
-
1316
- update: async (
1317
- id: Service.Payment.Update.ID,
1318
- body: Service.Payment.Update.Body
1319
- ): Promise<Service.Payment.Update.Result> => {
1320
- let res: Service.Payment.Update.Result = await this._update(
1321
- this.svAPIEndpoint,
1322
- this.payment._path + `/${id}`,
1323
- body
1324
- );
1325
- return res;
1326
- },
1327
- };
1328
-
1329
- transfer = {
1330
- _path: "/transfer",
1331
- find: async (
1332
- params?: Service.Transfer.Find.Params
1333
- ): Promise<Service.Transfer.Find.Result> => {
1334
- let res: Service.Transfer.Find.Result = await this._fetch(
1335
- this.svAPIEndpoint,
1336
- this.transfer._path,
1337
- params
1338
- );
1339
- return res;
1340
- },
1341
-
1342
- get: async (
1343
- id: Service.Transfer.Get.ID,
1344
- params?: Service.Transfer.Get.Params
1345
- ): Promise<Service.Transfer.Get.Result> => {
1346
- return await this._fetch(
1347
- this.svAPIEndpoint,
1348
- this.transfer._path + `/${id}`,
1349
- params
1350
- );
1351
- },
1352
-
1353
- create: async (
1354
- body: Service.Transfer.Create.Body
1355
- ): Promise<Service.Transfer.Create.Result> => {
1356
- let res = await this._create(
1357
- this.svAPIEndpoint,
1358
- this.transfer._path,
1359
- body
1360
- );
1361
- return res;
1362
- },
1363
-
1364
- update: async (
1365
- id: Service.Transfer.Update.ID,
1366
- body: Service.Transfer.Update.Body
1367
- ): Promise<Service.Transfer.Update.Result> => {
1368
- let res: Service.Transfer.Update.Result = await this._update(
1369
- this.svAPIEndpoint,
1370
- this.transfer._path + `/${id}`,
1371
- body
1372
- );
1373
- return res;
1374
- },
1375
- };
1376
-
1377
- adjustInventory = {
1378
- _path: "/adjust-inventory",
1379
- find: async (
1380
- params?: Service.AdjustAccount.Find.Params
1381
- ): Promise<Service.AdjustAccount.Find.Result> => {
1382
- let res: Service.AdjustAccount.Find.Result = await this._fetch(
1383
- this.svAPIEndpoint,
1384
- this.adjustInventory._path,
1385
- params
1386
- );
1387
- return res;
1388
- },
1389
-
1390
- get: async (
1391
- id: Service.AdjustAccount.Get.ID,
1392
- params?: Service.AdjustAccount.Get.Params
1393
- ): Promise<Service.AdjustAccount.Get.Result> => {
1394
- return await this._fetch(
1395
- this.svAPIEndpoint,
1396
- this.adjustInventory._path + `/${id}`,
1397
- params
1398
- );
1399
- },
1400
-
1401
- create: async (
1402
- body: Service.AdjustAccount.Create.Body
1403
- ): Promise<Service.AdjustAccount.Create.Result> => {
1404
- let res = await this._create(
1405
- this.svAPIEndpoint,
1406
- this.adjustInventory._path,
1407
- body
1408
- );
1409
- return res;
1410
- },
1411
- };
1412
-
1413
- inventory = {
1414
- _path: "/inventory",
1415
- find: async (
1416
- params?: Service.Inventory.Find.Params
1417
- ): Promise<Service.Inventory.Find.Result> => {
1418
- let res: Service.Inventory.Find.Result = await this._fetch(
1419
- this.svAPIEndpoint,
1420
- this.inventory._path,
1421
- params
1422
- );
1423
- return res;
1424
- },
1425
- };
1426
- }
1
+ import axios from "axios";
2
+ import { v4 as uuid } from "uuid";
3
+ import {
4
+ Params,
5
+ Data,
6
+ Service,
7
+ Options,
8
+ Headers,
9
+ StringId,
10
+ NameSpaces,
11
+ } from "./types/index";
12
+
13
+ export default class Repzo {
14
+ private svAPIEndpoint: string;
15
+ headers: Headers;
16
+ constructor(apiKey: string, options?: Options) {
17
+ this.svAPIEndpoint =
18
+ !options?.env || options?.env == "production"
19
+ ? "https://sv.api.repzo.me"
20
+ : options?.env == "staging"
21
+ ? "https://staging.sv.api.repzo.me"
22
+ : options?.env == "local"
23
+ ? "http://localhost:3030"
24
+ : "";
25
+
26
+ this.headers = {
27
+ "api-key": apiKey,
28
+ "Content-Type": "application/json",
29
+ Accept: "application/json",
30
+ };
31
+ if (options?.headers) Object.assign(this.headers, options.headers);
32
+ }
33
+
34
+ private async _fetch(baseUrl: string, path: string, params?: Params) {
35
+ let res = await axios.get(baseUrl + path, {
36
+ params,
37
+ headers: this.headers,
38
+ });
39
+ return res.data;
40
+ }
41
+
42
+ private async _create(
43
+ baseUrl: string,
44
+ path: string,
45
+ body: Data,
46
+ params?: Params
47
+ ) {
48
+ let res = await axios.post(baseUrl + path, body, {
49
+ params,
50
+ headers: this.headers,
51
+ });
52
+ return res.data;
53
+ }
54
+
55
+ private async _update(
56
+ baseUrl: string,
57
+ path: string,
58
+ body: Data,
59
+ params?: Params
60
+ ) {
61
+ let res = await axios.put(baseUrl + path, body, {
62
+ params,
63
+ headers: this.headers,
64
+ });
65
+ return res.data;
66
+ }
67
+
68
+ private async _delete(baseUrl: string, path: string, params?: Params) {
69
+ let res = await axios.delete(baseUrl + path, {
70
+ params,
71
+ headers: this.headers,
72
+ });
73
+ return res.data;
74
+ }
75
+
76
+ client = {
77
+ _path: "/client",
78
+ find: async (
79
+ params?: Service.Client.Find.Params
80
+ ): Promise<Service.Client.Find.Result> => {
81
+ let res: Service.Client.Find.Result = await this._fetch(
82
+ this.svAPIEndpoint,
83
+ this.client._path,
84
+ params
85
+ );
86
+ return res;
87
+ },
88
+
89
+ get: async (
90
+ id: Service.Client.Get.ID,
91
+ params?: Service.Client.Get.Params
92
+ ): Promise<Service.Client.Get.Result> => {
93
+ return await this._fetch(
94
+ this.svAPIEndpoint,
95
+ this.client._path + `/${id}`,
96
+ params
97
+ );
98
+ },
99
+
100
+ create: async (
101
+ body: Service.Client.Create.Body
102
+ ): Promise<Service.Client.Create.Result> => {
103
+ let res = await this._create(this.svAPIEndpoint, this.client._path, body);
104
+ return res;
105
+ },
106
+
107
+ update: async (
108
+ id: Service.Client.Update.ID,
109
+ body: Service.Client.Update.Body
110
+ ): Promise<Service.Client.Update.Result> => {
111
+ let res: Service.Client.Update.Result = await this._update(
112
+ this.svAPIEndpoint,
113
+ this.client._path + `/${id}`,
114
+ body
115
+ );
116
+ return res;
117
+ },
118
+
119
+ remove: async (
120
+ id: Service.Client.Remove.ID
121
+ ): Promise<Service.Client.Remove.Result> => {
122
+ let res: Service.Client.Remove.Result = await this._delete(
123
+ this.svAPIEndpoint,
124
+ this.client._path + `/${id}`
125
+ );
126
+ return res;
127
+ },
128
+ };
129
+
130
+ product = {
131
+ _path: "/product",
132
+ find: async (
133
+ params?: Service.Product.Find.Params
134
+ ): Promise<Service.Product.Find.Result> => {
135
+ let res: Service.Product.Find.Result = await this._fetch(
136
+ this.svAPIEndpoint,
137
+ this.product._path,
138
+ params
139
+ );
140
+ return res;
141
+ },
142
+
143
+ get: async (
144
+ id: Service.Product.Get.ID,
145
+ params?: Service.Product.Get.Params
146
+ ): Promise<Service.Product.Get.Result> => {
147
+ return await this._fetch(
148
+ this.svAPIEndpoint,
149
+ this.product._path + `/${id}`,
150
+ params
151
+ );
152
+ },
153
+
154
+ create: async (
155
+ body: Service.Product.Create.Body
156
+ ): Promise<Service.Product.Create.Result> => {
157
+ let res = await this._create(
158
+ this.svAPIEndpoint,
159
+ this.product._path,
160
+ body
161
+ );
162
+ return res;
163
+ },
164
+
165
+ update: async (
166
+ id: Service.Product.Update.ID,
167
+ body: Service.Product.Update.Body
168
+ ): Promise<Service.Product.Update.Result> => {
169
+ let res: Service.Product.Update.Result = await this._update(
170
+ this.svAPIEndpoint,
171
+ this.product._path + `/${id}`,
172
+ body
173
+ );
174
+ return res;
175
+ },
176
+
177
+ remove: async (
178
+ id: Service.Product.Remove.ID
179
+ ): Promise<Service.Product.Remove.Result> => {
180
+ let res: Service.Product.Remove.Result = await this._delete(
181
+ this.svAPIEndpoint,
182
+ this.product._path + `/${id}`
183
+ );
184
+ return res;
185
+ },
186
+ };
187
+
188
+ variant = {
189
+ _path: "/variant",
190
+ find: async (
191
+ params?: Service.Variant.Find.Params
192
+ ): Promise<Service.Variant.Find.Result> => {
193
+ let res: Service.Variant.Find.Result = await this._fetch(
194
+ this.svAPIEndpoint,
195
+ this.variant._path,
196
+ params
197
+ );
198
+ return res;
199
+ },
200
+
201
+ get: async (
202
+ id: Service.Variant.Get.ID,
203
+ params?: Service.Variant.Get.Params
204
+ ): Promise<Service.Variant.Get.Result> => {
205
+ return await this._fetch(
206
+ this.svAPIEndpoint,
207
+ this.variant._path + `/${id}`,
208
+ params
209
+ );
210
+ },
211
+
212
+ create: async (
213
+ body: Service.Variant.Create.Body
214
+ ): Promise<Service.Variant.Create.Result> => {
215
+ let res = await this._create(
216
+ this.svAPIEndpoint,
217
+ this.variant._path,
218
+ body
219
+ );
220
+ return res;
221
+ },
222
+
223
+ update: async (
224
+ id: Service.Variant.Update.ID,
225
+ body: Service.Variant.Update.Body
226
+ ): Promise<Service.Variant.Update.Result> => {
227
+ let res: Service.Variant.Update.Result = await this._update(
228
+ this.svAPIEndpoint,
229
+ this.variant._path + `/${id}`,
230
+ body
231
+ );
232
+ return res;
233
+ },
234
+
235
+ remove: async (
236
+ id: Service.Variant.Remove.ID
237
+ ): Promise<Service.Variant.Remove.Result> => {
238
+ let res: Service.Variant.Remove.Result = await this._delete(
239
+ this.svAPIEndpoint,
240
+ this.variant._path + `/${id}`
241
+ );
242
+ return res;
243
+ },
244
+ };
245
+
246
+ category = {
247
+ _path: "/product-category",
248
+ find: async (
249
+ params?: Service.Category.Find.Params
250
+ ): Promise<Service.Category.Find.Result> => {
251
+ let res: Service.Category.Find.Result = await this._fetch(
252
+ this.svAPIEndpoint,
253
+ this.category._path,
254
+ params
255
+ );
256
+ return res;
257
+ },
258
+
259
+ get: async (
260
+ id: Service.Category.Get.ID
261
+ ): Promise<Service.Category.Get.Result> => {
262
+ return await this._fetch(
263
+ this.svAPIEndpoint,
264
+ this.category._path + `/${id}`
265
+ );
266
+ },
267
+
268
+ create: async (
269
+ body: Service.Category.Create.Body
270
+ ): Promise<Service.Category.Create.Result> => {
271
+ let res = await this._create(
272
+ this.svAPIEndpoint,
273
+ this.category._path,
274
+ body
275
+ );
276
+ return res;
277
+ },
278
+
279
+ update: async (
280
+ id: Service.Category.Update.ID,
281
+ body: Service.Category.Update.Body
282
+ ): Promise<Service.Category.Update.Result> => {
283
+ let res: Service.Category.Update.Result = await this._update(
284
+ this.svAPIEndpoint,
285
+ this.category._path + `/${id}`,
286
+ body
287
+ );
288
+ return res;
289
+ },
290
+
291
+ remove: async (
292
+ id: Service.Category.Remove.ID
293
+ ): Promise<Service.Category.Remove.Result> => {
294
+ let res: Service.Category.Remove.Result = await this._delete(
295
+ this.svAPIEndpoint,
296
+ this.category._path + `/${id}`
297
+ );
298
+ return res;
299
+ },
300
+ };
301
+
302
+ sub_category = {
303
+ _path: "/product-sub-category",
304
+ find: async (
305
+ params?: Service.SubCategory.Find.Params
306
+ ): Promise<Service.SubCategory.Find.Result> => {
307
+ let res: Service.SubCategory.Find.Result = await this._fetch(
308
+ this.svAPIEndpoint,
309
+ this.sub_category._path,
310
+ params
311
+ );
312
+ return res;
313
+ },
314
+
315
+ get: async (
316
+ id: Service.SubCategory.Get.ID,
317
+ params?: Service.SubCategory.Get.Params
318
+ ): Promise<Service.SubCategory.Get.Result> => {
319
+ return await this._fetch(
320
+ this.svAPIEndpoint,
321
+ this.sub_category._path + `/${id}`,
322
+ params
323
+ );
324
+ },
325
+
326
+ create: async (
327
+ body: Service.SubCategory.Create.Body
328
+ ): Promise<Service.SubCategory.Create.Result> => {
329
+ let res = await this._create(
330
+ this.svAPIEndpoint,
331
+ this.sub_category._path,
332
+ body
333
+ );
334
+ return res;
335
+ },
336
+
337
+ update: async (
338
+ id: Service.SubCategory.Update.ID,
339
+ body: Service.SubCategory.Update.Body
340
+ ): Promise<Service.SubCategory.Update.Result> => {
341
+ let res: Service.SubCategory.Update.Result = await this._update(
342
+ this.svAPIEndpoint,
343
+ this.sub_category._path + `/${id}`,
344
+ body
345
+ );
346
+ return res;
347
+ },
348
+
349
+ remove: async (
350
+ id: Service.SubCategory.Remove.ID
351
+ ): Promise<Service.SubCategory.Remove.Result> => {
352
+ let res: Service.SubCategory.Remove.Result = await this._delete(
353
+ this.svAPIEndpoint,
354
+ this.sub_category._path + `/${id}`
355
+ );
356
+ return res;
357
+ },
358
+ };
359
+
360
+ brand = {
361
+ _path: "/product-brand",
362
+ find: async (
363
+ params?: Service.Brand.Find.Params
364
+ ): Promise<Service.Brand.Find.Result> => {
365
+ let res: Service.Brand.Find.Result = await this._fetch(
366
+ this.svAPIEndpoint,
367
+ this.brand._path,
368
+ params
369
+ );
370
+ return res;
371
+ },
372
+
373
+ get: async (
374
+ id: Service.Brand.Get.ID
375
+ ): Promise<Service.Brand.Get.Result> => {
376
+ return await this._fetch(this.svAPIEndpoint, this.brand._path + `/${id}`);
377
+ },
378
+
379
+ create: async (
380
+ body: Service.Brand.Create.Body
381
+ ): Promise<Service.Brand.Create.Result> => {
382
+ let res = await this._create(this.svAPIEndpoint, this.brand._path, body);
383
+ return res;
384
+ },
385
+
386
+ update: async (
387
+ id: Service.Brand.Update.ID,
388
+ body: Service.Brand.Update.Body
389
+ ): Promise<Service.Brand.Update.Result> => {
390
+ let res: Service.Brand.Update.Result = await this._update(
391
+ this.svAPIEndpoint,
392
+ this.brand._path + `/${id}`,
393
+ body
394
+ );
395
+ return res;
396
+ },
397
+
398
+ remove: async (
399
+ id: Service.Brand.Remove.ID
400
+ ): Promise<Service.Brand.Remove.Result> => {
401
+ let res: Service.Brand.Remove.Result = await this._delete(
402
+ this.svAPIEndpoint,
403
+ this.brand._path + `/${id}`
404
+ );
405
+ return res;
406
+ },
407
+ };
408
+
409
+ product_group = {
410
+ _path: "/product-group",
411
+ find: async (
412
+ params?: Service.ProductGroup.Find.Params
413
+ ): Promise<Service.ProductGroup.Find.Result> => {
414
+ let res: Service.ProductGroup.Find.Result = await this._fetch(
415
+ this.svAPIEndpoint,
416
+ this.product_group._path,
417
+ params
418
+ );
419
+ return res;
420
+ },
421
+
422
+ get: async (
423
+ id: Service.ProductGroup.Get.ID
424
+ ): Promise<Service.ProductGroup.Get.Result> => {
425
+ return await this._fetch(
426
+ this.svAPIEndpoint,
427
+ this.product_group._path + `/${id}`
428
+ );
429
+ },
430
+
431
+ create: async (
432
+ body: Service.ProductGroup.Create.Body
433
+ ): Promise<Service.ProductGroup.Create.Result> => {
434
+ let res = await this._create(
435
+ this.svAPIEndpoint,
436
+ this.product_group._path,
437
+ body
438
+ );
439
+ return res;
440
+ },
441
+
442
+ update: async (
443
+ id: Service.ProductGroup.Update.ID,
444
+ body: Service.ProductGroup.Update.Body
445
+ ): Promise<Service.ProductGroup.Update.Result> => {
446
+ let res: Service.ProductGroup.Update.Result = await this._update(
447
+ this.svAPIEndpoint,
448
+ this.product_group._path + `/${id}`,
449
+ body
450
+ );
451
+ return res;
452
+ },
453
+
454
+ remove: async (
455
+ id: Service.ProductGroup.Remove.ID
456
+ ): Promise<Service.ProductGroup.Remove.Result> => {
457
+ let res: Service.ProductGroup.Remove.Result = await this._delete(
458
+ this.svAPIEndpoint,
459
+ this.product_group._path + `/${id}`
460
+ );
461
+ return res;
462
+ },
463
+ };
464
+
465
+ tax = {
466
+ _path: "/tax",
467
+ find: async (
468
+ params?: Service.Tax.Find.Params
469
+ ): Promise<Service.Tax.Find.Result> => {
470
+ let res: Service.Tax.Find.Result = await this._fetch(
471
+ this.svAPIEndpoint,
472
+ this.tax._path,
473
+ params
474
+ );
475
+ return res;
476
+ },
477
+
478
+ get: async (id: Service.Tax.Get.ID): Promise<Service.Tax.Get.Result> => {
479
+ return await this._fetch(this.svAPIEndpoint, this.tax._path + `/${id}`);
480
+ },
481
+
482
+ create: async (
483
+ body: Service.Tax.Create.Body
484
+ ): Promise<Service.Tax.Create.Result> => {
485
+ let res = await this._create(this.svAPIEndpoint, this.tax._path, body);
486
+ return res;
487
+ },
488
+
489
+ update: async (
490
+ id: Service.Tax.Update.ID,
491
+ body: Service.Tax.Update.Body
492
+ ): Promise<Service.Tax.Update.Result> => {
493
+ let res: Service.Tax.Update.Result = await this._update(
494
+ this.svAPIEndpoint,
495
+ this.tax._path + `/${id}`,
496
+ body
497
+ );
498
+ return res;
499
+ },
500
+
501
+ remove: async (
502
+ id: Service.Tax.Remove.ID
503
+ ): Promise<Service.Tax.Remove.Result> => {
504
+ let res: Service.Tax.Remove.Result = await this._delete(
505
+ this.svAPIEndpoint,
506
+ this.tax._path + `/${id}`
507
+ );
508
+ return res;
509
+ },
510
+ };
511
+
512
+ measureunit = {
513
+ _path: "/measureunits",
514
+ find: async (
515
+ params?: Service.MeasureUnit.Find.Params
516
+ ): Promise<Service.MeasureUnit.Find.Result> => {
517
+ let res: Service.MeasureUnit.Find.Result = await this._fetch(
518
+ this.svAPIEndpoint,
519
+ this.measureunit._path,
520
+ params
521
+ );
522
+ return res;
523
+ },
524
+
525
+ get: async (
526
+ id: Service.MeasureUnit.Get.ID
527
+ ): Promise<Service.MeasureUnit.Get.Result> => {
528
+ return await this._fetch(
529
+ this.svAPIEndpoint,
530
+ this.measureunit._path + `/${id}`
531
+ );
532
+ },
533
+
534
+ create: async (
535
+ body: Service.MeasureUnit.Create.Body
536
+ ): Promise<Service.MeasureUnit.Create.Result> => {
537
+ let res = await this._create(
538
+ this.svAPIEndpoint,
539
+ this.measureunit._path,
540
+ body
541
+ );
542
+ return res;
543
+ },
544
+
545
+ update: async (
546
+ id: Service.MeasureUnit.Update.ID,
547
+ body: Service.MeasureUnit.Update.Body
548
+ ): Promise<Service.MeasureUnit.Update.Result> => {
549
+ let res: Service.MeasureUnit.Update.Result = await this._update(
550
+ this.svAPIEndpoint,
551
+ this.measureunit._path + `/${id}`,
552
+ body
553
+ );
554
+ return res;
555
+ },
556
+
557
+ remove: async (
558
+ id: Service.MeasureUnit.Remove.ID
559
+ ): Promise<Service.MeasureUnit.Remove.Result> => {
560
+ let res: Service.MeasureUnit.Remove.Result = await this._delete(
561
+ this.svAPIEndpoint,
562
+ this.measureunit._path + `/${id}`
563
+ );
564
+ return res;
565
+ },
566
+ };
567
+
568
+ measureunitFamily = {
569
+ _path: "/measureunit-family",
570
+ find: async (
571
+ params?: Service.MeasureUnitFamily.Find.Params
572
+ ): Promise<Service.MeasureUnitFamily.Find.Result> => {
573
+ let res: Service.MeasureUnitFamily.Find.Result = await this._fetch(
574
+ this.svAPIEndpoint,
575
+ this.measureunitFamily._path,
576
+ params
577
+ );
578
+ return res;
579
+ },
580
+
581
+ get: async (
582
+ id: Service.MeasureUnitFamily.Get.ID
583
+ ): Promise<Service.MeasureUnitFamily.Get.Result> => {
584
+ return await this._fetch(
585
+ this.svAPIEndpoint,
586
+ this.measureunitFamily._path + `/${id}`
587
+ );
588
+ },
589
+
590
+ create: async (
591
+ body: Service.MeasureUnitFamily.Create.Body
592
+ ): Promise<Service.MeasureUnitFamily.Create.Result> => {
593
+ let res = await this._create(
594
+ this.svAPIEndpoint,
595
+ this.measureunitFamily._path,
596
+ body
597
+ );
598
+ return res;
599
+ },
600
+
601
+ update: async (
602
+ id: Service.MeasureUnitFamily.Update.ID,
603
+ body: Service.MeasureUnitFamily.Update.Body
604
+ ): Promise<Service.MeasureUnitFamily.Update.Result> => {
605
+ let res: Service.MeasureUnitFamily.Update.Result = await this._update(
606
+ this.svAPIEndpoint,
607
+ this.measureunitFamily._path + `/${id}`,
608
+ body
609
+ );
610
+ return res;
611
+ },
612
+
613
+ remove: async (
614
+ id: Service.MeasureUnitFamily.Remove.ID
615
+ ): Promise<Service.MeasureUnitFamily.Remove.Result> => {
616
+ let res: Service.MeasureUnitFamily.Remove.Result = await this._delete(
617
+ this.svAPIEndpoint,
618
+ this.measureunitFamily._path + `/${id}`
619
+ );
620
+ return res;
621
+ },
622
+ };
623
+
624
+ media = {
625
+ _path: "/media",
626
+ find: async (
627
+ params?: Service.Media.Find.Params
628
+ ): Promise<Service.Media.Find.Result> => {
629
+ let res: Service.Media.Find.Result = await this._fetch(
630
+ this.svAPIEndpoint,
631
+ this.media._path,
632
+ params
633
+ );
634
+ return res;
635
+ },
636
+
637
+ get: async (
638
+ id: Service.Media.Get.ID
639
+ ): Promise<Service.Media.Get.Result> => {
640
+ return await this._fetch(this.svAPIEndpoint, this.media._path + `/${id}`);
641
+ },
642
+
643
+ create: async (
644
+ body: Service.Media.Create.Body
645
+ ): Promise<Service.Media.Create.Result> => {
646
+ let res = await this._create(this.svAPIEndpoint, this.media._path, body);
647
+ return res;
648
+ },
649
+
650
+ update: async (
651
+ id: Service.Media.Update.ID,
652
+ body: Service.Media.Update.Body
653
+ ): Promise<Service.Media.Update.Result> => {
654
+ let res: Service.Media.Update.Result = await this._update(
655
+ this.svAPIEndpoint,
656
+ this.media._path + `/${id}`,
657
+ body
658
+ );
659
+ return res;
660
+ },
661
+
662
+ remove: async (
663
+ id: Service.Media.Remove.ID
664
+ ): Promise<Service.Media.Remove.Result> => {
665
+ let res: Service.Media.Remove.Result = await this._delete(
666
+ this.svAPIEndpoint,
667
+ this.media._path + `/${id}`
668
+ );
669
+ return res;
670
+ },
671
+ };
672
+
673
+ priceList = {
674
+ _path: "/pricelists",
675
+ find: async (
676
+ params?: Service.PriceList.Find.Params
677
+ ): Promise<Service.PriceList.Find.Result> => {
678
+ let res: Service.PriceList.Find.Result = await this._fetch(
679
+ this.svAPIEndpoint,
680
+ this.priceList._path,
681
+ params
682
+ );
683
+ return res;
684
+ },
685
+
686
+ get: async (
687
+ id: Service.PriceList.Get.ID
688
+ ): Promise<Service.PriceList.Get.Result> => {
689
+ return await this._fetch(
690
+ this.svAPIEndpoint,
691
+ this.priceList._path + `/${id}`
692
+ );
693
+ },
694
+
695
+ create: async (
696
+ body: Service.PriceList.Create.Body
697
+ ): Promise<Service.PriceList.Create.Result> => {
698
+ let res = await this._create(
699
+ this.svAPIEndpoint,
700
+ this.priceList._path,
701
+ body
702
+ );
703
+ return res;
704
+ },
705
+
706
+ update: async (
707
+ id: Service.PriceList.Update.ID,
708
+ body: Service.PriceList.Update.Body
709
+ ): Promise<Service.PriceList.Update.Result> => {
710
+ let res: Service.PriceList.Update.Result = await this._update(
711
+ this.svAPIEndpoint,
712
+ this.priceList._path + `/${id}`,
713
+ body
714
+ );
715
+ return res;
716
+ },
717
+
718
+ remove: async (
719
+ id: Service.PriceList.Remove.ID
720
+ ): Promise<Service.PriceList.Remove.Result> => {
721
+ let res: Service.PriceList.Remove.Result = await this._delete(
722
+ this.svAPIEndpoint,
723
+ this.priceList._path + `/${id}`
724
+ );
725
+ return res;
726
+ },
727
+ };
728
+
729
+ priceListItem = {
730
+ _path: "/pricelists",
731
+ find: async (
732
+ params?: Service.PriceListItem.Find.Params
733
+ ): Promise<Service.PriceListItem.Find.Result> => {
734
+ let res: Service.PriceListItem.Find.Result = await this._fetch(
735
+ this.svAPIEndpoint,
736
+ this.priceListItem._path,
737
+ params
738
+ );
739
+ return res;
740
+ },
741
+
742
+ get: async (
743
+ id: Service.PriceListItem.Get.ID
744
+ ): Promise<Service.PriceListItem.Get.Result> => {
745
+ return await this._fetch(
746
+ this.svAPIEndpoint,
747
+ this.priceListItem._path + `/${id}`
748
+ );
749
+ },
750
+
751
+ create: async (
752
+ body: Service.PriceListItem.Create.Body
753
+ ): Promise<Service.PriceListItem.Create.Result> => {
754
+ let res = await this._create(
755
+ this.svAPIEndpoint,
756
+ this.priceListItem._path,
757
+ body
758
+ );
759
+ return res;
760
+ },
761
+
762
+ update: async (
763
+ id: Service.PriceListItem.Update.ID,
764
+ body: Service.PriceListItem.Update.Body
765
+ ): Promise<Service.PriceListItem.Update.Result> => {
766
+ let res: Service.PriceListItem.Update.Result = await this._update(
767
+ this.svAPIEndpoint,
768
+ this.priceListItem._path + `/${id}`,
769
+ body
770
+ );
771
+ return res;
772
+ },
773
+
774
+ remove: async (
775
+ id: Service.PriceListItem.Remove.ID
776
+ ): Promise<Service.PriceListItem.Remove.Result> => {
777
+ let res: Service.PriceListItem.Remove.Result = await this._delete(
778
+ this.svAPIEndpoint,
779
+ this.priceListItem._path + `/${id}`
780
+ );
781
+ return res;
782
+ },
783
+ };
784
+
785
+ team = {
786
+ _path: "/teams",
787
+ find: async (
788
+ params?: Service.Team.Find.Params
789
+ ): Promise<Service.Team.Find.Result> => {
790
+ let res: Service.Team.Find.Result = await this._fetch(
791
+ this.svAPIEndpoint,
792
+ this.team._path,
793
+ params
794
+ );
795
+ return res;
796
+ },
797
+
798
+ get: async (id: Service.Team.Get.ID): Promise<Service.Team.Get.Result> => {
799
+ return await this._fetch(this.svAPIEndpoint, this.team._path + `/${id}`);
800
+ },
801
+
802
+ create: async (
803
+ body: Service.Team.Create.Body
804
+ ): Promise<Service.Team.Create.Result> => {
805
+ let res = await this._create(this.svAPIEndpoint, this.team._path, body);
806
+ return res;
807
+ },
808
+
809
+ update: async (
810
+ id: Service.Team.Update.ID,
811
+ body: Service.Team.Update.Body
812
+ ): Promise<Service.Team.Update.Result> => {
813
+ let res: Service.Team.Update.Result = await this._update(
814
+ this.svAPIEndpoint,
815
+ this.team._path + `/${id}`,
816
+ body
817
+ );
818
+ return res;
819
+ },
820
+
821
+ remove: async (
822
+ id: Service.Team.Remove.ID
823
+ ): Promise<Service.Team.Remove.Result> => {
824
+ let res: Service.Team.Remove.Result = await this._delete(
825
+ this.svAPIEndpoint,
826
+ this.team._path + `/${id}`
827
+ );
828
+ return res;
829
+ },
830
+ };
831
+
832
+ rep = {
833
+ _path: "/rep",
834
+ find: async (
835
+ params?: Service.Rep.Find.Params
836
+ ): Promise<Service.Rep.Find.Result> => {
837
+ let res: Service.Rep.Find.Result = await this._fetch(
838
+ this.svAPIEndpoint,
839
+ this.rep._path,
840
+ params
841
+ );
842
+ return res;
843
+ },
844
+
845
+ get: async (
846
+ id: Service.Rep.Get.ID,
847
+ params?: Service.Client.Get.Params
848
+ ): Promise<Service.Rep.Get.Result> => {
849
+ return await this._fetch(
850
+ this.svAPIEndpoint,
851
+ this.rep._path + `/${id}`,
852
+ params
853
+ );
854
+ },
855
+
856
+ create: async (
857
+ body: Service.Rep.Create.Body
858
+ ): Promise<Service.Rep.Create.Result> => {
859
+ let res = await this._create(this.svAPIEndpoint, this.rep._path, body);
860
+ return res;
861
+ },
862
+
863
+ update: async (
864
+ id: Service.Rep.Update.ID,
865
+ body: Service.Rep.Update.Body
866
+ ): Promise<Service.Rep.Update.Result> => {
867
+ let res: Service.Rep.Update.Result = await this._update(
868
+ this.svAPIEndpoint,
869
+ this.rep._path + `/${id}`,
870
+ body
871
+ );
872
+ return res;
873
+ },
874
+
875
+ remove: async (
876
+ id: Service.Rep.Remove.ID
877
+ ): Promise<Service.Rep.Remove.Result> => {
878
+ let res: Service.Rep.Remove.Result = await this._delete(
879
+ this.svAPIEndpoint,
880
+ this.rep._path + `/${id}`
881
+ );
882
+ return res;
883
+ },
884
+ };
885
+
886
+ tag = {
887
+ _path: "/tag",
888
+ find: async (
889
+ params?: Service.Tag.Find.Params
890
+ ): Promise<Service.Tag.Find.Result> => {
891
+ let res: Service.Tag.Find.Result = await this._fetch(
892
+ this.svAPIEndpoint,
893
+ this.tag._path,
894
+ params
895
+ );
896
+ return res;
897
+ },
898
+
899
+ get: async (id: Service.Tag.Get.ID): Promise<Service.Tag.Get.Result> => {
900
+ return await this._fetch(this.svAPIEndpoint, this.tag._path + `/${id}`);
901
+ },
902
+
903
+ create: async (
904
+ body: Service.Tag.Create.Body
905
+ ): Promise<Service.Tag.Create.Result> => {
906
+ let res = await this._create(this.svAPIEndpoint, this.tag._path, body);
907
+ return res;
908
+ },
909
+
910
+ update: async (
911
+ id: Service.Tag.Update.ID,
912
+ body: Service.Tag.Update.Body
913
+ ): Promise<Service.Tag.Update.Result> => {
914
+ let res: Service.Tag.Update.Result = await this._update(
915
+ this.svAPIEndpoint,
916
+ this.tag._path + `/${id}`,
917
+ body
918
+ );
919
+ return res;
920
+ },
921
+
922
+ remove: async (
923
+ id: Service.Tag.Remove.ID
924
+ ): Promise<Service.Tag.Remove.Result> => {
925
+ let res: Service.Tag.Remove.Result = await this._delete(
926
+ this.svAPIEndpoint,
927
+ this.tag._path + `/${id}`
928
+ );
929
+ return res;
930
+ },
931
+ };
932
+
933
+ warehouse = {
934
+ _path: "/warehouse",
935
+ find: async (
936
+ params?: Service.Warehouse.Find.Params
937
+ ): Promise<Service.Warehouse.Find.Result> => {
938
+ let res: Service.Warehouse.Find.Result = await this._fetch(
939
+ this.svAPIEndpoint,
940
+ this.warehouse._path,
941
+ params
942
+ );
943
+ return res;
944
+ },
945
+
946
+ get: async (
947
+ id: Service.Warehouse.Get.ID
948
+ ): Promise<Service.Warehouse.Get.Result> => {
949
+ return await this._fetch(
950
+ this.svAPIEndpoint,
951
+ this.warehouse._path + `/${id}`
952
+ );
953
+ },
954
+
955
+ create: async (
956
+ body: Service.Warehouse.Create.Body
957
+ ): Promise<Service.Warehouse.Create.Result> => {
958
+ let res = await this._create(
959
+ this.svAPIEndpoint,
960
+ this.warehouse._path,
961
+ body
962
+ );
963
+ return res;
964
+ },
965
+
966
+ update: async (
967
+ id: Service.Warehouse.Update.ID,
968
+ body: Service.Warehouse.Update.Body
969
+ ): Promise<Service.Warehouse.Update.Result> => {
970
+ let res: Service.Warehouse.Update.Result = await this._update(
971
+ this.svAPIEndpoint,
972
+ this.warehouse._path + `/${id}`,
973
+ body
974
+ );
975
+ return res;
976
+ },
977
+
978
+ remove: async (
979
+ id: Service.Warehouse.Remove.ID
980
+ ): Promise<Service.Warehouse.Remove.Result> => {
981
+ let res: Service.Warehouse.Remove.Result = await this._delete(
982
+ this.svAPIEndpoint,
983
+ this.warehouse._path + `/${id}`
984
+ );
985
+ return res;
986
+ },
987
+ };
988
+
989
+ channel = {
990
+ _path: "/client-channel",
991
+ find: async (
992
+ params?: Service.Channel.Find.Params
993
+ ): Promise<Service.Channel.Find.Result> => {
994
+ let res: Service.Channel.Find.Result = await this._fetch(
995
+ this.svAPIEndpoint,
996
+ this.channel._path,
997
+ params
998
+ );
999
+ return res;
1000
+ },
1001
+
1002
+ get: async (
1003
+ id: Service.Channel.Get.ID
1004
+ ): Promise<Service.Channel.Get.Result> => {
1005
+ return await this._fetch(
1006
+ this.svAPIEndpoint,
1007
+ this.channel._path + `/${id}`
1008
+ );
1009
+ },
1010
+
1011
+ create: async (
1012
+ body: Service.Channel.Create.Body
1013
+ ): Promise<Service.Channel.Create.Result> => {
1014
+ let res = await this._create(
1015
+ this.svAPIEndpoint,
1016
+ this.channel._path,
1017
+ body
1018
+ );
1019
+ return res;
1020
+ },
1021
+
1022
+ update: async (
1023
+ id: Service.Channel.Update.ID,
1024
+ body: Service.Channel.Update.Body
1025
+ ): Promise<Service.Channel.Update.Result> => {
1026
+ let res: Service.Channel.Update.Result = await this._update(
1027
+ this.svAPIEndpoint,
1028
+ this.channel._path + `/${id}`,
1029
+ body
1030
+ );
1031
+ return res;
1032
+ },
1033
+
1034
+ remove: async (
1035
+ id: Service.Channel.Remove.ID
1036
+ ): Promise<Service.Channel.Remove.Result> => {
1037
+ let res: Service.Channel.Remove.Result = await this._delete(
1038
+ this.svAPIEndpoint,
1039
+ this.channel._path + `/${id}`
1040
+ );
1041
+ return res;
1042
+ },
1043
+ };
1044
+
1045
+ paymentTerm = {
1046
+ _path: "/paymentterms",
1047
+ find: async (
1048
+ params?: Service.PaymentTerm.Find.Params
1049
+ ): Promise<Service.PaymentTerm.Find.Result> => {
1050
+ let res: Service.PaymentTerm.Find.Result = await this._fetch(
1051
+ this.svAPIEndpoint,
1052
+ this.paymentTerm._path,
1053
+ params
1054
+ );
1055
+ return res;
1056
+ },
1057
+
1058
+ get: async (
1059
+ id: Service.PaymentTerm.Get.ID
1060
+ ): Promise<Service.PaymentTerm.Get.Result> => {
1061
+ return await this._fetch(
1062
+ this.svAPIEndpoint,
1063
+ this.paymentTerm._path + `/${id}`
1064
+ );
1065
+ },
1066
+
1067
+ create: async (
1068
+ body: Service.PaymentTerm.Create.Body
1069
+ ): Promise<Service.PaymentTerm.Create.Result> => {
1070
+ let res = await this._create(
1071
+ this.svAPIEndpoint,
1072
+ this.paymentTerm._path,
1073
+ body
1074
+ );
1075
+ return res;
1076
+ },
1077
+
1078
+ update: async (
1079
+ id: Service.PaymentTerm.Update.ID,
1080
+ body: Service.PaymentTerm.Update.Body
1081
+ ): Promise<Service.PaymentTerm.Update.Result> => {
1082
+ let res: Service.PaymentTerm.Update.Result = await this._update(
1083
+ this.svAPIEndpoint,
1084
+ this.paymentTerm._path + `/${id}`,
1085
+ body
1086
+ );
1087
+ return res;
1088
+ },
1089
+
1090
+ remove: async (
1091
+ id: Service.PaymentTerm.Remove.ID
1092
+ ): Promise<Service.PaymentTerm.Remove.Result> => {
1093
+ let res: Service.PaymentTerm.Remove.Result = await this._delete(
1094
+ this.svAPIEndpoint,
1095
+ this.paymentTerm._path + `/${id}`
1096
+ );
1097
+ return res;
1098
+ },
1099
+ };
1100
+
1101
+ bank = {
1102
+ _path: "/banks",
1103
+ find: async (
1104
+ params?: Service.Bank.Find.Params
1105
+ ): Promise<Service.Bank.Find.Result> => {
1106
+ let res: Service.Bank.Find.Result = await this._fetch(
1107
+ this.svAPIEndpoint,
1108
+ this.bank._path,
1109
+ params
1110
+ );
1111
+ return res;
1112
+ },
1113
+
1114
+ get: async (id: Service.Bank.Get.ID): Promise<Service.Bank.Get.Result> => {
1115
+ return await this._fetch(this.svAPIEndpoint, this.bank._path + `/${id}`);
1116
+ },
1117
+
1118
+ create: async (
1119
+ body: Service.Bank.Create.Body
1120
+ ): Promise<Service.Bank.Create.Result> => {
1121
+ let res = await this._create(this.svAPIEndpoint, this.bank._path, body);
1122
+ return res;
1123
+ },
1124
+
1125
+ update: async (
1126
+ id: Service.Bank.Update.ID,
1127
+ body: Service.Bank.Update.Body
1128
+ ): Promise<Service.Bank.Update.Result> => {
1129
+ let res: Service.Bank.Update.Result = await this._update(
1130
+ this.svAPIEndpoint,
1131
+ this.bank._path + `/${id}`,
1132
+ body
1133
+ );
1134
+ return res;
1135
+ },
1136
+ };
1137
+
1138
+ customStatus = {
1139
+ _path: "/custom-status",
1140
+ find: async (
1141
+ params?: Service.CustomStatus.Find.Params
1142
+ ): Promise<Service.CustomStatus.Find.Result> => {
1143
+ let res: Service.CustomStatus.Find.Result = await this._fetch(
1144
+ this.svAPIEndpoint,
1145
+ this.customStatus._path,
1146
+ params
1147
+ );
1148
+ return res;
1149
+ },
1150
+
1151
+ get: async (
1152
+ id: Service.CustomStatus.Get.ID
1153
+ ): Promise<Service.CustomStatus.Get.Result> => {
1154
+ return await this._fetch(
1155
+ this.svAPIEndpoint,
1156
+ this.customStatus._path + `/${id}`
1157
+ );
1158
+ },
1159
+
1160
+ create: async (
1161
+ body: Service.CustomStatus.Create.Body
1162
+ ): Promise<Service.CustomStatus.Create.Result> => {
1163
+ let res = await this._create(
1164
+ this.svAPIEndpoint,
1165
+ this.customStatus._path,
1166
+ body
1167
+ );
1168
+ return res;
1169
+ },
1170
+
1171
+ update: async (
1172
+ id: Service.CustomStatus.Update.ID,
1173
+ body: Service.CustomStatus.Update.Body
1174
+ ): Promise<Service.CustomStatus.Update.Result> => {
1175
+ let res: Service.CustomStatus.Update.Result = await this._update(
1176
+ this.svAPIEndpoint,
1177
+ this.customStatus._path + `/${id}`,
1178
+ body
1179
+ );
1180
+ return res;
1181
+ },
1182
+
1183
+ remove: async (
1184
+ id: Service.CustomStatus.Remove.ID
1185
+ ): Promise<Service.CustomStatus.Remove.Result> => {
1186
+ let res: Service.CustomStatus.Remove.Result = await this._delete(
1187
+ this.svAPIEndpoint,
1188
+ this.customStatus._path + `/${id}`
1189
+ );
1190
+ return res;
1191
+ },
1192
+ };
1193
+
1194
+ invoice = {
1195
+ _path: "/fullinvoices",
1196
+ find: async (
1197
+ params?: Service.FullInvoice.Find.Params
1198
+ ): Promise<Service.FullInvoice.Find.Result> => {
1199
+ let res: Service.FullInvoice.Find.Result = await this._fetch(
1200
+ this.svAPIEndpoint,
1201
+ this.invoice._path,
1202
+ params
1203
+ );
1204
+ return res;
1205
+ },
1206
+
1207
+ get: async (
1208
+ id: Service.FullInvoice.Get.ID,
1209
+ params?: Service.FullInvoice.Get.Params
1210
+ ): Promise<Service.FullInvoice.Get.Result> => {
1211
+ return await this._fetch(
1212
+ this.svAPIEndpoint,
1213
+ this.invoice._path + `/${id}`,
1214
+ params
1215
+ );
1216
+ },
1217
+
1218
+ create: async (
1219
+ body: Service.FullInvoice.Create.Body
1220
+ ): Promise<Service.FullInvoice.Create.Result> => {
1221
+ let res = await this._create(
1222
+ this.svAPIEndpoint,
1223
+ this.invoice._path,
1224
+ body
1225
+ );
1226
+ return res;
1227
+ },
1228
+
1229
+ update: async (
1230
+ id: Service.FullInvoice.Update.ID,
1231
+ body: Service.FullInvoice.Update.Body
1232
+ ): Promise<Service.FullInvoice.Update.Result> => {
1233
+ let res: Service.FullInvoice.Update.Result = await this._update(
1234
+ this.svAPIEndpoint,
1235
+ this.invoice._path + `/${id}`,
1236
+ body
1237
+ );
1238
+ return res;
1239
+ },
1240
+ };
1241
+
1242
+ proforma = {
1243
+ _path: "/proforma",
1244
+ find: async (
1245
+ params?: Service.Proforma.Find.Params
1246
+ ): Promise<Service.Proforma.Find.Result> => {
1247
+ let res: Service.Proforma.Find.Result = await this._fetch(
1248
+ this.svAPIEndpoint,
1249
+ this.proforma._path,
1250
+ params
1251
+ );
1252
+ return res;
1253
+ },
1254
+
1255
+ get: async (
1256
+ id: Service.Proforma.Get.ID,
1257
+ params?: Service.Proforma.Get.Params
1258
+ ): Promise<Service.Proforma.Get.Result> => {
1259
+ return await this._fetch(
1260
+ this.svAPIEndpoint,
1261
+ this.proforma._path + `/${id}`,
1262
+ params
1263
+ );
1264
+ },
1265
+
1266
+ create: async (
1267
+ body: Service.Proforma.Create.Body
1268
+ ): Promise<Service.Proforma.Create.Result> => {
1269
+ let res = await this._create(
1270
+ this.svAPIEndpoint,
1271
+ this.proforma._path,
1272
+ body
1273
+ );
1274
+ return res;
1275
+ },
1276
+
1277
+ update: async (
1278
+ id: Service.Proforma.Update.ID,
1279
+ body: Service.Proforma.Update.Body
1280
+ ): Promise<Service.Proforma.Update.Result> => {
1281
+ let res: Service.Proforma.Update.Result = await this._update(
1282
+ this.svAPIEndpoint,
1283
+ this.proforma._path + `/${id}`,
1284
+ body
1285
+ );
1286
+ return res;
1287
+ },
1288
+ };
1289
+
1290
+ payment = {
1291
+ _path: "/payments",
1292
+ find: async (
1293
+ params?: Service.Payment.Find.Params
1294
+ ): Promise<Service.Payment.Find.Result> => {
1295
+ let res: Service.Payment.Find.Result = await this._fetch(
1296
+ this.svAPIEndpoint,
1297
+ this.payment._path,
1298
+ params
1299
+ );
1300
+ return res;
1301
+ },
1302
+
1303
+ get: async (
1304
+ id: Service.Payment.Get.ID,
1305
+ params?: Service.Payment.Get.Params
1306
+ ): Promise<Service.Payment.Get.Result> => {
1307
+ return await this._fetch(
1308
+ this.svAPIEndpoint,
1309
+ this.payment._path + `/${id}`,
1310
+ params
1311
+ );
1312
+ },
1313
+
1314
+ create: async (
1315
+ body: Service.Payment.Create.Body
1316
+ ): Promise<Service.Payment.Create.Result> => {
1317
+ let res = await this._create(
1318
+ this.svAPIEndpoint,
1319
+ this.payment._path,
1320
+ body
1321
+ );
1322
+ return res;
1323
+ },
1324
+
1325
+ update: async (
1326
+ id: Service.Payment.Update.ID,
1327
+ body: Service.Payment.Update.Body
1328
+ ): Promise<Service.Payment.Update.Result> => {
1329
+ let res: Service.Payment.Update.Result = await this._update(
1330
+ this.svAPIEndpoint,
1331
+ this.payment._path + `/${id}`,
1332
+ body
1333
+ );
1334
+ return res;
1335
+ },
1336
+ };
1337
+
1338
+ transfer = {
1339
+ _path: "/transfer",
1340
+ find: async (
1341
+ params?: Service.Transfer.Find.Params
1342
+ ): Promise<Service.Transfer.Find.Result> => {
1343
+ let res: Service.Transfer.Find.Result = await this._fetch(
1344
+ this.svAPIEndpoint,
1345
+ this.transfer._path,
1346
+ params
1347
+ );
1348
+ return res;
1349
+ },
1350
+
1351
+ get: async (
1352
+ id: Service.Transfer.Get.ID,
1353
+ params?: Service.Transfer.Get.Params
1354
+ ): Promise<Service.Transfer.Get.Result> => {
1355
+ return await this._fetch(
1356
+ this.svAPIEndpoint,
1357
+ this.transfer._path + `/${id}`,
1358
+ params
1359
+ );
1360
+ },
1361
+
1362
+ create: async (
1363
+ body: Service.Transfer.Create.Body
1364
+ ): Promise<Service.Transfer.Create.Result> => {
1365
+ let res = await this._create(
1366
+ this.svAPIEndpoint,
1367
+ this.transfer._path,
1368
+ body
1369
+ );
1370
+ return res;
1371
+ },
1372
+
1373
+ update: async (
1374
+ id: Service.Transfer.Update.ID,
1375
+ body: Service.Transfer.Update.Body
1376
+ ): Promise<Service.Transfer.Update.Result> => {
1377
+ let res: Service.Transfer.Update.Result = await this._update(
1378
+ this.svAPIEndpoint,
1379
+ this.transfer._path + `/${id}`,
1380
+ body
1381
+ );
1382
+ return res;
1383
+ },
1384
+ };
1385
+
1386
+ adjustInventory = {
1387
+ _path: "/adjust-inventory",
1388
+ find: async (
1389
+ params?: Service.AdjustAccount.Find.Params
1390
+ ): Promise<Service.AdjustAccount.Find.Result> => {
1391
+ let res: Service.AdjustAccount.Find.Result = await this._fetch(
1392
+ this.svAPIEndpoint,
1393
+ this.adjustInventory._path,
1394
+ params
1395
+ );
1396
+ return res;
1397
+ },
1398
+
1399
+ get: async (
1400
+ id: Service.AdjustAccount.Get.ID,
1401
+ params?: Service.AdjustAccount.Get.Params
1402
+ ): Promise<Service.AdjustAccount.Get.Result> => {
1403
+ return await this._fetch(
1404
+ this.svAPIEndpoint,
1405
+ this.adjustInventory._path + `/${id}`,
1406
+ params
1407
+ );
1408
+ },
1409
+
1410
+ create: async (
1411
+ body: Service.AdjustAccount.Create.Body
1412
+ ): Promise<Service.AdjustAccount.Create.Result> => {
1413
+ let res = await this._create(
1414
+ this.svAPIEndpoint,
1415
+ this.adjustInventory._path,
1416
+ body
1417
+ );
1418
+ return res;
1419
+ },
1420
+ };
1421
+
1422
+ inventory = {
1423
+ _path: "/inventory",
1424
+ find: async (
1425
+ params?: Service.Inventory.Find.Params
1426
+ ): Promise<Service.Inventory.Find.Result> => {
1427
+ let res: Service.Inventory.Find.Result = await this._fetch(
1428
+ this.svAPIEndpoint,
1429
+ this.inventory._path,
1430
+ params
1431
+ );
1432
+ return res;
1433
+ },
1434
+ };
1435
+
1436
+ integrationApp = {
1437
+ _path: "/integration-app",
1438
+ find: async (
1439
+ params?: Service.App.Find.Params
1440
+ ): Promise<Service.App.Find.Result> => {
1441
+ let res: Service.App.Find.Result = await this._fetch(
1442
+ this.svAPIEndpoint,
1443
+ this.integrationApp._path,
1444
+ params
1445
+ );
1446
+ return res;
1447
+ },
1448
+
1449
+ get: async (
1450
+ id: Service.App.Get.ID,
1451
+ params?: Service.App.Find.Params
1452
+ ): Promise<Service.App.Get.Result> => {
1453
+ return await this._fetch(
1454
+ this.svAPIEndpoint,
1455
+ this.integrationApp._path + `/${id}`,
1456
+ params
1457
+ );
1458
+ },
1459
+
1460
+ create: async (
1461
+ body: Service.App.Create.Body
1462
+ ): Promise<Service.App.Create.Result> => {
1463
+ let res = await this._create(
1464
+ this.svAPIEndpoint,
1465
+ this.integrationApp._path,
1466
+ body
1467
+ );
1468
+ return res;
1469
+ },
1470
+
1471
+ update: async (
1472
+ id: Service.App.Update.ID,
1473
+ body: Service.App.Update.Body
1474
+ ): Promise<Service.App.Update.Result> => {
1475
+ let res: Service.App.Update.Result = await this._update(
1476
+ this.svAPIEndpoint,
1477
+ this.integrationApp._path + `/${id}`,
1478
+ body
1479
+ );
1480
+ return res;
1481
+ },
1482
+ };
1483
+ joinActionsWebHook = {
1484
+ _path: "/svix-integration",
1485
+ update: async (
1486
+ id: null,
1487
+ body: Service.JoinActionsWeHook.Data
1488
+ ): Promise<Service.JoinActionsWeHook.Result> => {
1489
+ let res: Service.JoinActionsWeHook.Result = await this._update(
1490
+ this.svAPIEndpoint,
1491
+ this.payment._path,
1492
+ body
1493
+ );
1494
+ return res;
1495
+ },
1496
+ };
1497
+ static ActionLogs = class {
1498
+ _path: string = "/integration-action-log";
1499
+ available_app_name: string = "";
1500
+ available_app_id: StringId = "";
1501
+ app_id: StringId = "";
1502
+ action: string = "";
1503
+ status: Service.ActionLogs.Status;
1504
+ error?: any;
1505
+ start_time: number;
1506
+ end_time?: number;
1507
+ total_time?: number;
1508
+ company_namespace?: NameSpaces;
1509
+ body?: any;
1510
+ meta?: any;
1511
+ message: string;
1512
+ details: Service.ActionLogs.Detail[];
1513
+ sync_id: string;
1514
+ isOld: boolean;
1515
+ constructor(public superThis: Repzo, sync_id: string) {
1516
+ this.start_time = Date.now();
1517
+ this.status = "processing";
1518
+ this.message = "Log Created";
1519
+ this.details = [];
1520
+ this.sync_id = sync_id;
1521
+ this.isOld = true;
1522
+ }
1523
+ async load(sync_id: string) {
1524
+ console.log(sync_id);
1525
+ const params: Service.ActionLogs.Find.Params = { sync_id: sync_id };
1526
+ const res: Service.ActionLogs.Find.Result = await this.superThis._fetch(
1527
+ this.superThis.svAPIEndpoint,
1528
+ this._path,
1529
+ params
1530
+ );
1531
+ if (res?.data?.length)
1532
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1533
+ const action_log: Service.ActionLogs.Schema = res.data[0];
1534
+ this.sync_id = sync_id;
1535
+ this.details = action_log.details;
1536
+ this.status = action_log.status;
1537
+ this.error = action_log.error;
1538
+ this.start_time = action_log.start_time;
1539
+ this.body = action_log.body;
1540
+ this.meta = action_log.meta;
1541
+ this.message = action_log.message;
1542
+ this.app_id = action_log._id;
1543
+ this.available_app_id = action_log.available_app_id;
1544
+ this.available_app_name = action_log.available_app_name;
1545
+ this.company_namespace = action_log.company_namespace;
1546
+ this.action = action_log.action;
1547
+ this.isOld = true;
1548
+
1549
+ return this;
1550
+ }
1551
+ async setStatus(status: Service.ActionLogs.Status, error?: any) {
1552
+ this.details.push({
1553
+ timestamp: Date.now(),
1554
+ content: `status was changed from ${this.status} to ${status}`,
1555
+ });
1556
+ this.status = status;
1557
+ if (error) {
1558
+ this.error = error;
1559
+ }
1560
+ return this;
1561
+ }
1562
+ setBody(body: any) {
1563
+ this.body = body;
1564
+ return this;
1565
+ }
1566
+ setMeta(meta: any) {
1567
+ this.meta = meta;
1568
+ return this;
1569
+ }
1570
+ async commit() {
1571
+ let doc: Service.ActionLogs.Create.Body = {
1572
+ available_app_name: this.available_app_name,
1573
+ available_app_id: this.available_app_id,
1574
+ app_id: this.app_id,
1575
+ action: this.action,
1576
+ company_namespace: this.company_namespace,
1577
+ status: this.status,
1578
+ error: this.error ? this.error : undefined,
1579
+ start_time: this.start_time,
1580
+ end_time: Date.now(),
1581
+ total_time: Date.now() - this.start_time,
1582
+ body: this.body,
1583
+ meta: this.meta,
1584
+ message: this.message,
1585
+ details: this.details,
1586
+ sync_id: this.sync_id,
1587
+ };
1588
+ try {
1589
+ const res: Service.ActionLogs.Create.Result = await this.superThis._create(
1590
+ this.superThis.svAPIEndpoint,
1591
+ this._path,
1592
+ doc
1593
+ );
1594
+ } catch (e) {
1595
+ console.error(e);
1596
+ }
1597
+ return this;
1598
+ }
1599
+ addDetail(detail: string, meta: any) {
1600
+ let d: Service.ActionLogs.Detail = {
1601
+ timestamp: Date.now(),
1602
+ content: detail,
1603
+ };
1604
+ this.message = detail;
1605
+ if (meta) d.meta = meta;
1606
+ this.details.push(d);
1607
+ return this;
1608
+ }
1609
+ };
1610
+
1611
+ static CommandLog = class {
1612
+ _path: string = "/integration-command-log";
1613
+ available_app_name: string;
1614
+ available_app_id: StringId;
1615
+ app_id: StringId;
1616
+ command: string;
1617
+ status: Service.CommandLog.Status;
1618
+ error?: any;
1619
+ start_time: number;
1620
+ end_time?: number;
1621
+ total_time?: number;
1622
+ company_namespace: NameSpaces;
1623
+ body?: any;
1624
+ meta?: any;
1625
+ message: string;
1626
+ details: Service.CommandLog.Detail[];
1627
+ sync_id: string;
1628
+ isOld: boolean;
1629
+ priority?: number;
1630
+ isPrioritized: boolean;
1631
+ retries: number;
1632
+ queuedAt?: Date;
1633
+ failedAt?: Date;
1634
+ succeededAt?: Date;
1635
+ skippedAt?: Date;
1636
+ receivedAt?: Date;
1637
+ processedAt?: Date;
1638
+ onGoing: boolean;
1639
+ trigger?: string;
1640
+ constructor(
1641
+ public superThis: Repzo,
1642
+ app: Service.App.Schema_with_populated_AvailableApp,
1643
+ command: string,
1644
+ trigger?: string
1645
+ ) {
1646
+ this.app_id = app._id;
1647
+ this.available_app_id = app.available_app._id;
1648
+ this.available_app_name = app.available_app.name;
1649
+ this.company_namespace = app.company_namespace;
1650
+ this.start_time = Date.now();
1651
+ this.status = "received";
1652
+ this.message = "Request received";
1653
+ this.command = command;
1654
+ this.details = [{ timestamp: Date.now(), content: "Request received" }];
1655
+ this.sync_id = uuid();
1656
+ this.isOld = false;
1657
+ this.isPrioritized = false;
1658
+ this.retries = 1;
1659
+ this.trigger = trigger;
1660
+ this.onGoing = true;
1661
+ }
1662
+ async load(sync_id?: string, retries?: number) {
1663
+ if (sync_id) {
1664
+ const params: Service.CommandLog.Find.Params = { sync_id: sync_id };
1665
+ const res: Service.CommandLog.Find.Result = await this.superThis._fetch(
1666
+ this.superThis.svAPIEndpoint,
1667
+ this._path,
1668
+ params
1669
+ );
1670
+ if (res?.data?.length)
1671
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1672
+ const command_log: Service.CommandLog.Schema = res.data[0];
1673
+
1674
+ if (command_log) {
1675
+ this.sync_id = sync_id;
1676
+ this.details = command_log.details;
1677
+ this.status = command_log.status;
1678
+ this.error = command_log.error;
1679
+ this.start_time = command_log.start_time;
1680
+ this.body = command_log.body;
1681
+ this.meta = command_log.meta;
1682
+ this.message = command_log.message;
1683
+ this.retries =
1684
+ retries !== undefined
1685
+ ? retries
1686
+ : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
1687
+ this.isOld = true;
1688
+ this.failedAt = command_log.failedAt;
1689
+ this.succeededAt = command_log.succeededAt;
1690
+ this.skippedAt = command_log.skippedAt;
1691
+ this.receivedAt = command_log.receivedAt;
1692
+ this.processedAt = command_log.processedAt;
1693
+ this.onGoing = command_log.onGoing || false;
1694
+ this.trigger = command_log.trigger;
1695
+ // this.priority = command_log.priority
1696
+ // ? command_log.priority
1697
+ // : this.priority
1698
+ // ? this.priority
1699
+ // : undefined;
1700
+ }
1701
+ }
1702
+ return this;
1703
+ }
1704
+ setStatus(status: Service.CommandLog.Status, error?: any) {
1705
+ this.addDetail(`status was changed from ${this.status} to ${status}`);
1706
+ this.status = status;
1707
+ if (error) {
1708
+ this.error = error;
1709
+ }
1710
+ switch (status) {
1711
+ case "fail":
1712
+ this.failedAt = new Date();
1713
+ this.onGoing = false;
1714
+ break;
1715
+ case "processing":
1716
+ this.processedAt = new Date();
1717
+ this.onGoing = true;
1718
+ break;
1719
+ case "queued":
1720
+ this.queuedAt = new Date();
1721
+ this.onGoing = true;
1722
+ break;
1723
+ case "received":
1724
+ this.receivedAt = new Date();
1725
+ this.onGoing = true;
1726
+ break;
1727
+ case "skipped":
1728
+ this.skippedAt = new Date();
1729
+ this.onGoing = false;
1730
+ break;
1731
+ case "success":
1732
+ this.succeededAt = new Date();
1733
+ this.onGoing = false;
1734
+ break;
1735
+ }
1736
+ return this;
1737
+ }
1738
+ setBody(body: any) {
1739
+ this.body = body;
1740
+ return this;
1741
+ }
1742
+ setMeta(meta: any) {
1743
+ this.meta = meta;
1744
+ return this;
1745
+ }
1746
+ async commit() {
1747
+ let doc: Service.CommandLog.Create.Body = {
1748
+ available_app_name: this.available_app_name,
1749
+ available_app_id: this.available_app_id,
1750
+ app_id: this.app_id,
1751
+ command: this.command,
1752
+ status: this.status,
1753
+ error: this.error ? this.error : undefined,
1754
+ start_time: this.start_time,
1755
+ end_time: Date.now(),
1756
+ total_time: Date.now() - this.start_time,
1757
+ company_namespace: this.company_namespace,
1758
+ body: this.body,
1759
+ meta: this.meta,
1760
+ message: this.message,
1761
+ details: this.details,
1762
+ sync_id: this.sync_id,
1763
+ // priority: this.priority ? this.priority : undefined,
1764
+ queuedAt: this.queuedAt ? this.queuedAt : undefined,
1765
+ failedAt: this.failedAt ? this.failedAt : undefined,
1766
+ succeededAt: this.succeededAt ? this.succeededAt : undefined,
1767
+ skippedAt: this.skippedAt ? this.skippedAt : undefined,
1768
+ receivedAt: this.receivedAt ? this.receivedAt : undefined,
1769
+ processedAt: this.processedAt ? this.processedAt : undefined,
1770
+ onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
1771
+ retries: this.retries !== undefined ? this.retries : undefined,
1772
+ trigger: this.trigger,
1773
+ };
1774
+ try {
1775
+ const res: Service.CommandLog.Create.Result = await this.superThis._create(
1776
+ this.superThis.svAPIEndpoint,
1777
+ this._path,
1778
+ doc
1779
+ );
1780
+ this.isOld = true;
1781
+ } catch (e) {
1782
+ console.error(e);
1783
+ }
1784
+ return this;
1785
+ }
1786
+ addDetail(detail: string, meta?: any) {
1787
+ let d: Service.CommandLog.Detail = {
1788
+ timestamp: Date.now(),
1789
+ content: detail,
1790
+ };
1791
+ this.message = detail;
1792
+ if (meta) d.meta = meta;
1793
+ this.details.push(d);
1794
+ return this;
1795
+ }
1796
+ };
1797
+ }