repzo 1.0.10 → 1.0.13

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,1799 +1,1814 @@
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
-
1484
- joinActionsWebHook = {
1485
- _path: "/svix-integration",
1486
- update: async (
1487
- id: null,
1488
- body: Service.JoinActionsWeHook.Data
1489
- ): Promise<Service.JoinActionsWeHook.Result> => {
1490
- let res: Service.JoinActionsWeHook.Result = await this._update(
1491
- this.svAPIEndpoint,
1492
- this.joinActionsWebHook._path,
1493
- body
1494
- );
1495
- return res;
1496
- },
1497
- };
1498
-
1499
- static ActionLogs = class {
1500
- _path: string = "/integration-action-log";
1501
- available_app_name: string = "";
1502
- available_app_id: StringId = "";
1503
- app_id: StringId = "";
1504
- action: string = "";
1505
- status: Service.ActionLogs.Status;
1506
- error?: any;
1507
- start_time: number;
1508
- end_time?: number;
1509
- total_time?: number;
1510
- company_namespace?: NameSpaces;
1511
- body?: any;
1512
- meta?: any;
1513
- message: string;
1514
- details: Service.ActionLogs.Detail[];
1515
- sync_id: string;
1516
- isOld: boolean;
1517
- constructor(public superThis: Repzo, sync_id: string) {
1518
- this.start_time = Date.now();
1519
- this.status = "processing";
1520
- this.message = "Log Created";
1521
- this.details = [];
1522
- this.sync_id = sync_id;
1523
- this.isOld = true;
1524
- }
1525
- async load(sync_id: string) {
1526
- console.log(sync_id);
1527
- const params: Service.ActionLogs.Find.Params = { sync_id: sync_id };
1528
- const res: Service.ActionLogs.Find.Result = await this.superThis._fetch(
1529
- this.superThis.svAPIEndpoint,
1530
- this._path,
1531
- params
1532
- );
1533
- if (res?.data?.length)
1534
- throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1535
- const action_log: Service.ActionLogs.Schema = res.data[0];
1536
- this.sync_id = sync_id;
1537
- this.details = action_log.details;
1538
- this.status = action_log.status;
1539
- this.error = action_log.error;
1540
- this.start_time = action_log.start_time;
1541
- this.body = action_log.body;
1542
- this.meta = action_log.meta;
1543
- this.message = action_log.message;
1544
- this.app_id = action_log._id;
1545
- this.available_app_id = action_log.available_app_id;
1546
- this.available_app_name = action_log.available_app_name;
1547
- this.company_namespace = action_log.company_namespace;
1548
- this.action = action_log.action;
1549
- this.isOld = true;
1550
-
1551
- return this;
1552
- }
1553
- setStatus(status: Service.ActionLogs.Status, error?: any) {
1554
- this.details.push({
1555
- timestamp: Date.now(),
1556
- content: `status was changed from ${this.status} to ${status}`,
1557
- });
1558
- this.status = status;
1559
- if (error) {
1560
- this.error = error;
1561
- }
1562
- return this;
1563
- }
1564
- setBody(body: any) {
1565
- this.body = body;
1566
- return this;
1567
- }
1568
- setMeta(meta: any) {
1569
- this.meta = meta;
1570
- return this;
1571
- }
1572
- async commit() {
1573
- let doc: Service.ActionLogs.Create.Body = {
1574
- available_app_name: this.available_app_name,
1575
- available_app_id: this.available_app_id,
1576
- app_id: this.app_id,
1577
- action: this.action,
1578
- company_namespace: this.company_namespace,
1579
- status: this.status,
1580
- error: this.error ? this.error : undefined,
1581
- start_time: this.start_time,
1582
- end_time: Date.now(),
1583
- total_time: Date.now() - this.start_time,
1584
- body: this.body,
1585
- meta: this.meta,
1586
- message: this.message,
1587
- details: this.details,
1588
- sync_id: this.sync_id,
1589
- };
1590
- try {
1591
- const res: Service.ActionLogs.Create.Result = await this.superThis._create(
1592
- this.superThis.svAPIEndpoint,
1593
- this._path,
1594
- doc
1595
- );
1596
- } catch (e) {
1597
- console.error(e);
1598
- }
1599
- return this;
1600
- }
1601
- addDetail(detail: string, meta?: any) {
1602
- let d: Service.ActionLogs.Detail = {
1603
- timestamp: Date.now(),
1604
- content: detail,
1605
- };
1606
- this.message = detail;
1607
- if (meta) d.meta = meta;
1608
- this.details.push(d);
1609
- return this;
1610
- }
1611
- };
1612
-
1613
- static CommandLog = class {
1614
- _path: string = "/integration-command-log";
1615
- available_app_name: string;
1616
- available_app_id: StringId;
1617
- app_id: StringId;
1618
- command: string;
1619
- status: Service.CommandLog.Status;
1620
- error?: any;
1621
- start_time: number;
1622
- end_time?: number;
1623
- total_time?: number;
1624
- company_namespace: NameSpaces;
1625
- body?: any;
1626
- meta?: any;
1627
- message: string;
1628
- details: Service.CommandLog.Detail[];
1629
- sync_id: string;
1630
- isOld: boolean;
1631
- priority?: number;
1632
- isPrioritized: boolean;
1633
- retries: number;
1634
- queuedAt?: Date;
1635
- failedAt?: Date;
1636
- succeededAt?: Date;
1637
- skippedAt?: Date;
1638
- receivedAt?: Date;
1639
- processedAt?: Date;
1640
- onGoing: boolean;
1641
- trigger?: string;
1642
- constructor(
1643
- public superThis: Repzo,
1644
- app: Service.App.Schema_with_populated_AvailableApp,
1645
- command: string,
1646
- trigger?: string
1647
- ) {
1648
- this.app_id = app._id;
1649
- this.available_app_id = app.available_app._id;
1650
- this.available_app_name = app.available_app.name;
1651
- this.company_namespace = app.company_namespace;
1652
- this.start_time = Date.now();
1653
- this.status = "received";
1654
- this.message = "Request received";
1655
- this.command = command;
1656
- this.details = [{ timestamp: Date.now(), content: "Request received" }];
1657
- this.sync_id = uuid();
1658
- this.isOld = false;
1659
- this.isPrioritized = false;
1660
- this.retries = 1;
1661
- this.trigger = trigger;
1662
- this.onGoing = true;
1663
- }
1664
- async load(sync_id?: string, retries?: number) {
1665
- if (sync_id) {
1666
- const params: Service.CommandLog.Find.Params = { sync_id: sync_id };
1667
- const res: Service.CommandLog.Find.Result = await this.superThis._fetch(
1668
- this.superThis.svAPIEndpoint,
1669
- this._path,
1670
- params
1671
- );
1672
- if (res?.data?.length)
1673
- throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1674
- const command_log: Service.CommandLog.Schema = res.data[0];
1675
-
1676
- if (command_log) {
1677
- this.sync_id = sync_id;
1678
- this.details = command_log.details;
1679
- this.status = command_log.status;
1680
- this.error = command_log.error;
1681
- this.start_time = command_log.start_time;
1682
- this.body = command_log.body;
1683
- this.meta = command_log.meta;
1684
- this.message = command_log.message;
1685
- this.retries =
1686
- retries !== undefined
1687
- ? retries
1688
- : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
1689
- this.isOld = true;
1690
- this.failedAt = command_log.failedAt;
1691
- this.succeededAt = command_log.succeededAt;
1692
- this.skippedAt = command_log.skippedAt;
1693
- this.receivedAt = command_log.receivedAt;
1694
- this.processedAt = command_log.processedAt;
1695
- this.onGoing = command_log.onGoing || false;
1696
- this.trigger = command_log.trigger;
1697
- // this.priority = command_log.priority
1698
- // ? command_log.priority
1699
- // : this.priority
1700
- // ? this.priority
1701
- // : undefined;
1702
- }
1703
- }
1704
- return this;
1705
- }
1706
- setStatus(status: Service.CommandLog.Status, error?: any) {
1707
- this.addDetail(`status was changed from ${this.status} to ${status}`);
1708
- this.status = status;
1709
- if (error) {
1710
- this.error = error;
1711
- }
1712
- switch (status) {
1713
- case "fail":
1714
- this.failedAt = new Date();
1715
- this.onGoing = false;
1716
- break;
1717
- case "processing":
1718
- this.processedAt = new Date();
1719
- this.onGoing = true;
1720
- break;
1721
- case "queued":
1722
- this.queuedAt = new Date();
1723
- this.onGoing = true;
1724
- break;
1725
- case "received":
1726
- this.receivedAt = new Date();
1727
- this.onGoing = true;
1728
- break;
1729
- case "skipped":
1730
- this.skippedAt = new Date();
1731
- this.onGoing = false;
1732
- break;
1733
- case "success":
1734
- this.succeededAt = new Date();
1735
- this.onGoing = false;
1736
- break;
1737
- }
1738
- return this;
1739
- }
1740
- setBody(body: any) {
1741
- this.body = body;
1742
- return this;
1743
- }
1744
- setMeta(meta: any) {
1745
- this.meta = meta;
1746
- return this;
1747
- }
1748
- async commit() {
1749
- let doc: Service.CommandLog.Create.Body = {
1750
- available_app_name: this.available_app_name,
1751
- available_app_id: this.available_app_id,
1752
- app_id: this.app_id,
1753
- command: this.command,
1754
- status: this.status,
1755
- error: this.error ? this.error : undefined,
1756
- start_time: this.start_time,
1757
- end_time: Date.now(),
1758
- total_time: Date.now() - this.start_time,
1759
- company_namespace: this.company_namespace,
1760
- body: this.body,
1761
- meta: this.meta,
1762
- message: this.message,
1763
- details: this.details,
1764
- sync_id: this.sync_id,
1765
- // priority: this.priority ? this.priority : undefined,
1766
- queuedAt: this.queuedAt ? this.queuedAt : undefined,
1767
- failedAt: this.failedAt ? this.failedAt : undefined,
1768
- succeededAt: this.succeededAt ? this.succeededAt : undefined,
1769
- skippedAt: this.skippedAt ? this.skippedAt : undefined,
1770
- receivedAt: this.receivedAt ? this.receivedAt : undefined,
1771
- processedAt: this.processedAt ? this.processedAt : undefined,
1772
- onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
1773
- retries: this.retries !== undefined ? this.retries : undefined,
1774
- trigger: this.trigger,
1775
- };
1776
- try {
1777
- const res: Service.CommandLog.Create.Result = await this.superThis._create(
1778
- this.superThis.svAPIEndpoint,
1779
- this._path,
1780
- doc
1781
- );
1782
- this.isOld = true;
1783
- } catch (e) {
1784
- console.error(e);
1785
- }
1786
- return this;
1787
- }
1788
- addDetail(detail: string, meta?: any) {
1789
- let d: Service.CommandLog.Detail = {
1790
- timestamp: Date.now(),
1791
- content: detail,
1792
- };
1793
- this.message = detail;
1794
- if (meta) d.meta = meta;
1795
- this.details.push(d);
1796
- return this;
1797
- }
1798
- };
1799
- }
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
+
1484
+ joinActionsWebHook = {
1485
+ _path: "/svix-integration",
1486
+ update: async (
1487
+ id: null,
1488
+ body: Service.JoinActionsWeHook.Data
1489
+ ): Promise<Service.JoinActionsWeHook.Result> => {
1490
+ let res: Service.JoinActionsWeHook.Result = await this._update(
1491
+ this.svAPIEndpoint,
1492
+ this.joinActionsWebHook._path,
1493
+ body
1494
+ );
1495
+ return res;
1496
+ },
1497
+ };
1498
+
1499
+ static ActionLogs = class {
1500
+ _path: string = "/integration-action-log";
1501
+ available_app_name: string = "";
1502
+ available_app_id: StringId = "";
1503
+ app_id: StringId = "";
1504
+ action: string = "";
1505
+ status: Service.ActionLogs.Status;
1506
+ error?: any;
1507
+ start_time: number;
1508
+ end_time?: number;
1509
+ total_time?: number;
1510
+ company_namespace?: NameSpaces;
1511
+ body?: any;
1512
+ meta?: any;
1513
+ message: string;
1514
+ details: Service.ActionLogs.Detail[];
1515
+ sync_id: string;
1516
+ isOld: boolean;
1517
+ constructor(public superThis: Repzo, sync_id: string) {
1518
+ this.start_time = Date.now();
1519
+ this.status = "processing";
1520
+ this.message = "Log Created";
1521
+ this.details = [];
1522
+ this.sync_id = sync_id;
1523
+ this.isOld = true;
1524
+ }
1525
+ async load(sync_id: string) {
1526
+ const params: Service.ActionLogs.Find.Params = { sync_id: sync_id };
1527
+ const res: Service.ActionLogs.Find.Result = await this.superThis._fetch(
1528
+ this.superThis.svAPIEndpoint,
1529
+ this._path,
1530
+ params
1531
+ );
1532
+ if (!res?.data?.length)
1533
+ throw new Error(`Action Log Not found, sync_id: ${sync_id}`);
1534
+ const action_log: Service.ActionLogs.Schema = res.data[0];
1535
+ this.sync_id = sync_id;
1536
+ this.details = action_log.details;
1537
+ this.status = action_log.status;
1538
+ this.error = action_log.error;
1539
+ this.start_time = action_log.start_time;
1540
+ this.body = action_log.body;
1541
+ this.meta = action_log.meta;
1542
+ this.message = action_log.message;
1543
+ this.app_id = action_log.app_id;
1544
+ this.available_app_id = action_log.available_app_id;
1545
+ this.available_app_name = action_log.available_app_name;
1546
+ this.company_namespace = action_log.company_namespace;
1547
+ this.action = action_log.action;
1548
+ this.isOld = true;
1549
+
1550
+ return this;
1551
+ }
1552
+ setStatus(status: Service.ActionLogs.Status, error?: any) {
1553
+ this.details.push({
1554
+ timestamp: Date.now(),
1555
+ content: `status was changed from ${this.status} to ${status}`,
1556
+ });
1557
+ this.status = status;
1558
+ if (error) {
1559
+ if (typeof error == "string") {
1560
+ this.error = { message: error };
1561
+ } else {
1562
+ this.error = {
1563
+ message: error.message,
1564
+ responseData: error.response?.data,
1565
+ };
1566
+ }
1567
+ return this;
1568
+ }
1569
+ return this;
1570
+ }
1571
+ setBody(body: any) {
1572
+ this.body = body;
1573
+ return this;
1574
+ }
1575
+ setMeta(meta: any) {
1576
+ this.meta = meta;
1577
+ return this;
1578
+ }
1579
+ async commit() {
1580
+ let doc: Service.ActionLogs.Create.Body = {
1581
+ available_app_name: this.available_app_name,
1582
+ available_app_id: this.available_app_id,
1583
+ app_id: this.app_id,
1584
+ action: this.action,
1585
+ company_namespace: this.company_namespace,
1586
+ status: this.status,
1587
+ error: this.error ? this.error : undefined,
1588
+ start_time: this.start_time,
1589
+ end_time: Date.now(),
1590
+ total_time: Date.now() - this.start_time,
1591
+ body: this.body,
1592
+ meta: this.meta,
1593
+ message: this.message,
1594
+ details: this.details,
1595
+ sync_id: this.sync_id,
1596
+ };
1597
+ try {
1598
+ const res: Service.ActionLogs.Create.Result = await this.superThis._create(
1599
+ this.superThis.svAPIEndpoint,
1600
+ this._path,
1601
+ doc
1602
+ );
1603
+ } catch (e) {
1604
+ console.error(e);
1605
+ }
1606
+ return this;
1607
+ }
1608
+ addDetail(detail: string, meta?: any) {
1609
+ let d: Service.ActionLogs.Detail = {
1610
+ timestamp: Date.now(),
1611
+ content: detail,
1612
+ };
1613
+ this.message = detail;
1614
+ if (meta) d.meta = meta;
1615
+ this.details.push(d);
1616
+ return this;
1617
+ }
1618
+ };
1619
+
1620
+ static CommandLog = class {
1621
+ _path: string = "/integration-command-log";
1622
+ available_app_name: string;
1623
+ available_app_id: StringId;
1624
+ app_id: StringId;
1625
+ command: string;
1626
+ status: Service.CommandLog.Status;
1627
+ error?: any;
1628
+ start_time: number;
1629
+ end_time?: number;
1630
+ total_time?: number;
1631
+ company_namespace: NameSpaces;
1632
+ body?: any;
1633
+ meta?: any;
1634
+ message: string;
1635
+ details: Service.CommandLog.Detail[];
1636
+ sync_id: string;
1637
+ isOld: boolean;
1638
+ priority?: number;
1639
+ isPrioritized: boolean;
1640
+ retries: number;
1641
+ queuedAt?: Date;
1642
+ failedAt?: Date;
1643
+ succeededAt?: Date;
1644
+ skippedAt?: Date;
1645
+ receivedAt?: Date;
1646
+ processedAt?: Date;
1647
+ onGoing: boolean;
1648
+ trigger?: string;
1649
+ constructor(
1650
+ public superThis: Repzo,
1651
+ app: Service.App.Schema_with_populated_AvailableApp,
1652
+ command: string,
1653
+ trigger?: string
1654
+ ) {
1655
+ this.app_id = app._id;
1656
+ this.available_app_id = app.available_app._id;
1657
+ this.available_app_name = app.available_app.name;
1658
+ this.company_namespace = app.company_namespace;
1659
+ this.start_time = Date.now();
1660
+ this.status = "received";
1661
+ this.message = "Request received";
1662
+ this.command = command;
1663
+ this.details = [{ timestamp: Date.now(), content: "Request received" }];
1664
+ this.sync_id = uuid();
1665
+ this.isOld = false;
1666
+ this.isPrioritized = false;
1667
+ this.retries = 1;
1668
+ this.trigger = trigger;
1669
+ this.onGoing = true;
1670
+ }
1671
+ async load(sync_id?: string, retries?: number) {
1672
+ if (sync_id) {
1673
+ const params: Service.CommandLog.Find.Params = { sync_id: sync_id };
1674
+ const res: Service.CommandLog.Find.Result = await this.superThis._fetch(
1675
+ this.superThis.svAPIEndpoint,
1676
+ this._path,
1677
+ params
1678
+ );
1679
+ if (!res?.data?.length)
1680
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1681
+ const command_log: Service.CommandLog.Schema = res.data[0];
1682
+
1683
+ if (command_log) {
1684
+ this.sync_id = sync_id;
1685
+ this.details = command_log.details;
1686
+ this.status = command_log.status;
1687
+ this.error = command_log.error;
1688
+ this.start_time = command_log.start_time;
1689
+ this.body = command_log.body;
1690
+ this.meta = command_log.meta;
1691
+ this.message = command_log.message;
1692
+ this.retries =
1693
+ retries !== undefined
1694
+ ? retries
1695
+ : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
1696
+ this.isOld = true;
1697
+ this.failedAt = command_log.failedAt;
1698
+ this.succeededAt = command_log.succeededAt;
1699
+ this.skippedAt = command_log.skippedAt;
1700
+ this.receivedAt = command_log.receivedAt;
1701
+ this.processedAt = command_log.processedAt;
1702
+ this.onGoing = command_log.onGoing || false;
1703
+ this.trigger = command_log.trigger;
1704
+ // this.priority = command_log.priority
1705
+ // ? command_log.priority
1706
+ // : this.priority
1707
+ // ? this.priority
1708
+ // : undefined;
1709
+ }
1710
+ }
1711
+ return this;
1712
+ }
1713
+ setStatus(status: Service.CommandLog.Status, error?: any) {
1714
+ this.addDetail(`status was changed from ${this.status} to ${status}`);
1715
+ this.status = status;
1716
+ if (error) {
1717
+ if (typeof error == "string") {
1718
+ this.error = { message: error };
1719
+ } else {
1720
+ this.error = {
1721
+ message: error.message,
1722
+ responseData: error.response?.data,
1723
+ };
1724
+ }
1725
+ return this;
1726
+ }
1727
+ switch (status) {
1728
+ case "fail":
1729
+ this.failedAt = new Date();
1730
+ this.onGoing = false;
1731
+ break;
1732
+ case "processing":
1733
+ this.processedAt = new Date();
1734
+ this.onGoing = true;
1735
+ break;
1736
+ case "queued":
1737
+ this.queuedAt = new Date();
1738
+ this.onGoing = true;
1739
+ break;
1740
+ case "received":
1741
+ this.receivedAt = new Date();
1742
+ this.onGoing = true;
1743
+ break;
1744
+ case "skipped":
1745
+ this.skippedAt = new Date();
1746
+ this.onGoing = false;
1747
+ break;
1748
+ case "success":
1749
+ this.succeededAt = new Date();
1750
+ this.onGoing = false;
1751
+ break;
1752
+ }
1753
+ return this;
1754
+ }
1755
+ setBody(body: any) {
1756
+ this.body = body;
1757
+ return this;
1758
+ }
1759
+ setMeta(meta: any) {
1760
+ this.meta = meta;
1761
+ return this;
1762
+ }
1763
+ async commit() {
1764
+ let doc: Service.CommandLog.Create.Body = {
1765
+ available_app_name: this.available_app_name,
1766
+ available_app_id: this.available_app_id,
1767
+ app_id: this.app_id,
1768
+ command: this.command,
1769
+ status: this.status,
1770
+ error: this.error ? this.error : undefined,
1771
+ start_time: this.start_time,
1772
+ end_time: Date.now(),
1773
+ total_time: Date.now() - this.start_time,
1774
+ company_namespace: this.company_namespace,
1775
+ body: this.body,
1776
+ meta: this.meta,
1777
+ message: this.message,
1778
+ details: this.details,
1779
+ sync_id: this.sync_id,
1780
+ // priority: this.priority ? this.priority : undefined,
1781
+ queuedAt: this.queuedAt ? this.queuedAt : undefined,
1782
+ failedAt: this.failedAt ? this.failedAt : undefined,
1783
+ succeededAt: this.succeededAt ? this.succeededAt : undefined,
1784
+ skippedAt: this.skippedAt ? this.skippedAt : undefined,
1785
+ receivedAt: this.receivedAt ? this.receivedAt : undefined,
1786
+ processedAt: this.processedAt ? this.processedAt : undefined,
1787
+ onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
1788
+ retries: this.retries !== undefined ? this.retries : undefined,
1789
+ trigger: this.trigger,
1790
+ };
1791
+ try {
1792
+ const res: Service.CommandLog.Create.Result = await this.superThis._create(
1793
+ this.superThis.svAPIEndpoint,
1794
+ this._path,
1795
+ doc
1796
+ );
1797
+ this.isOld = true;
1798
+ } catch (e) {
1799
+ console.error(e);
1800
+ }
1801
+ return this;
1802
+ }
1803
+ addDetail(detail: string, meta?: any) {
1804
+ let d: Service.CommandLog.Detail = {
1805
+ timestamp: Date.now(),
1806
+ content: detail,
1807
+ };
1808
+ this.message = detail;
1809
+ if (meta) d.meta = meta;
1810
+ this.details.push(d);
1811
+ return this;
1812
+ }
1813
+ };
1814
+ }