repzo 1.0.5 → 1.0.6

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/changelog.md CHANGED
@@ -9,6 +9,7 @@
9
9
  - add Services: Category @maramalshen
10
10
  - add Services: SubCategory, Brand, ProductGroup, measureunit, measureunitFamily, media, priceList, priceListItem, teams, Rep, Tag, warehouse, channel, paymentTerm, bank, customList, full_invoice, proforma, payment, cycle, transfer, AdjustInventory, inventory @maramalshen
11
11
  - update Product schema with populatedKeys @maramalshen
12
+ - add ActionLogs, CommandLog @maramalshen
12
13
 
13
14
  ### Changed
14
15
 
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Service, Options, Headers } from "./types/index";
1
+ import { Service, Options, Headers, StringId, NameSpaces } from "./types/index";
2
2
  export default class Repzo {
3
3
  private svAPIEndpoint;
4
4
  headers: Headers;
@@ -212,4 +212,71 @@ export default class Repzo {
212
212
  _path: string;
213
213
  find: (params?: Service.Inventory.Find.Params | undefined) => Promise<Service.Inventory.Find.Result>;
214
214
  };
215
+ static ActionLogs: {
216
+ new (superThis: Repzo, sync_id: string): {
217
+ _path: string;
218
+ available_app_name: string;
219
+ available_app_id: StringId;
220
+ app_id: StringId;
221
+ action: string;
222
+ status: Service.ActionLogs.Status;
223
+ error?: any;
224
+ start_time: number;
225
+ end_time?: number | undefined;
226
+ total_time?: number | undefined;
227
+ company_namespace?: NameSpaces | undefined;
228
+ body?: any;
229
+ meta?: any;
230
+ message: string;
231
+ details: Service.ActionLogs.Detail[];
232
+ sync_id: string;
233
+ isOld: boolean;
234
+ superThis: Repzo;
235
+ load(sync_id: string): Promise<any>;
236
+ setStatus(status: Service.ActionLogs.Status, error?: any): Promise<any>;
237
+ setBody(body: any): any;
238
+ setMeta(meta: any): any;
239
+ commit(): Promise<any>;
240
+ addDetail(detail: string, meta: any): any;
241
+ };
242
+ };
243
+ static CommandLog: {
244
+ new (superThis: Repzo, app: Service.App.Schema_with_populated_AvailableApp, command: string, trigger?: string | undefined): {
245
+ _path: string;
246
+ available_app_name: string;
247
+ available_app_id: StringId;
248
+ app_id: StringId;
249
+ command: string;
250
+ status: Service.CommandLog.Status;
251
+ error?: any;
252
+ start_time: number;
253
+ end_time?: number | undefined;
254
+ total_time?: number | undefined;
255
+ company_namespace: NameSpaces;
256
+ body?: any;
257
+ meta?: any;
258
+ message: string;
259
+ details: Service.CommandLog.Detail[];
260
+ sync_id: string;
261
+ isOld: boolean;
262
+ priority?: number | undefined;
263
+ isPrioritized: boolean;
264
+ retries: number;
265
+ queuedAt?: Date | undefined;
266
+ failedAt?: Date | undefined;
267
+ succeededAt?: Date | undefined;
268
+ skippedAt?: Date | undefined;
269
+ receivedAt?: Date | undefined;
270
+ processedAt?: Date | undefined;
271
+ onGoing: boolean;
272
+ trigger?: string | undefined;
273
+ superThis: Repzo;
274
+ load(sync_id?: string | undefined, retries?: number | undefined): Promise<any>;
275
+ setStatus(status: Service.CommandLog.Status, error?: any): any;
276
+ setBody(body: any): any;
277
+ setMeta(meta: any): any;
278
+ commit(): Promise<any>;
279
+ addDetail(detail: string, meta?: any): any;
280
+ };
281
+ };
215
282
  }
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import axios from "axios";
2
+ import { v4 as uuid } from "uuid";
2
3
  export default class Repzo {
3
4
  constructor(apiKey, options) {
4
5
  this.client = {
@@ -597,3 +598,244 @@ export default class Repzo {
597
598
  return res.data;
598
599
  }
599
600
  }
601
+ Repzo.ActionLogs = class {
602
+ constructor(superThis, sync_id) {
603
+ this.superThis = superThis;
604
+ this._path = "/integration-action-log";
605
+ this.available_app_name = "";
606
+ this.available_app_id = "";
607
+ this.app_id = "";
608
+ this.action = "";
609
+ this.start_time = Date.now();
610
+ this.status = "processing";
611
+ this.message = "Log Created";
612
+ this.details = [];
613
+ this.sync_id = sync_id;
614
+ this.isOld = true;
615
+ }
616
+ async load(sync_id) {
617
+ console.log(sync_id);
618
+ const params = { sync_id: sync_id };
619
+ const res = await this.superThis._fetch(this.superThis.svAPIEndpoint, this._path, params);
620
+ if (res?.data?.length)
621
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
622
+ const action_log = res.data[0];
623
+ this.sync_id = sync_id;
624
+ this.details = action_log.details;
625
+ this.status = action_log.status;
626
+ this.error = action_log.error;
627
+ this.start_time = action_log.start_time;
628
+ this.body = action_log.body;
629
+ this.meta = action_log.meta;
630
+ this.message = action_log.message;
631
+ this.app_id = action_log._id;
632
+ this.available_app_id = action_log.available_app_id;
633
+ this.available_app_name = action_log.available_app_name;
634
+ this.company_namespace = action_log.company_namespace;
635
+ this.action = action_log.action;
636
+ this.isOld = true;
637
+ return this;
638
+ }
639
+ async setStatus(status, error) {
640
+ this.details.push({
641
+ timestamp: Date.now(),
642
+ content: `status was changed from ${this.status} to ${status}`,
643
+ });
644
+ this.status = status;
645
+ if (error) {
646
+ this.error = error;
647
+ }
648
+ return this;
649
+ }
650
+ setBody(body) {
651
+ this.body = body;
652
+ return this;
653
+ }
654
+ setMeta(meta) {
655
+ this.meta = meta;
656
+ return this;
657
+ }
658
+ async commit() {
659
+ let doc = {
660
+ available_app_name: this.available_app_name,
661
+ available_app_id: this.available_app_id,
662
+ app_id: this.app_id,
663
+ action: this.action,
664
+ company_namespace: this.company_namespace,
665
+ status: this.status,
666
+ error: this.error ? this.error : undefined,
667
+ start_time: this.start_time,
668
+ end_time: Date.now(),
669
+ total_time: Date.now() - this.start_time,
670
+ body: this.body,
671
+ meta: this.meta,
672
+ message: this.message,
673
+ details: this.details,
674
+ sync_id: this.sync_id,
675
+ };
676
+ try {
677
+ const res = await this.superThis._create(this.superThis.svAPIEndpoint, this._path, doc);
678
+ }
679
+ catch (e) {
680
+ console.error(e);
681
+ }
682
+ return this;
683
+ }
684
+ addDetail(detail, meta) {
685
+ let d = {
686
+ timestamp: Date.now(),
687
+ content: detail,
688
+ };
689
+ if (meta)
690
+ d.meta = meta;
691
+ this.details.push(d);
692
+ return this;
693
+ }
694
+ };
695
+ Repzo.CommandLog = class {
696
+ constructor(superThis, app, command, trigger) {
697
+ this.superThis = superThis;
698
+ this._path = "/integration-command-log";
699
+ this.app_id = app._id;
700
+ this.available_app_id = app.available_app._id;
701
+ this.available_app_name = app.available_app.name;
702
+ this.company_namespace = app.company_namespace;
703
+ this.start_time = Date.now();
704
+ this.status = "received";
705
+ this.message = "Request received";
706
+ this.command = command;
707
+ this.details = [{ timestamp: Date.now(), content: "Request received" }];
708
+ this.sync_id = uuid();
709
+ this.isOld = false;
710
+ this.isPrioritized = false;
711
+ this.retries = 1;
712
+ this.trigger = trigger;
713
+ this.onGoing = true;
714
+ }
715
+ async load(sync_id, retries) {
716
+ if (sync_id) {
717
+ const params = { sync_id: sync_id };
718
+ const res = await this.superThis._fetch(this.superThis.svAPIEndpoint, this._path, params);
719
+ if (res?.data?.length)
720
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
721
+ const command_log = res.data[0];
722
+ if (command_log) {
723
+ this.sync_id = sync_id;
724
+ this.details = command_log.details;
725
+ this.status = command_log.status;
726
+ this.error = command_log.error;
727
+ this.start_time = command_log.start_time;
728
+ this.body = command_log.body;
729
+ this.meta = command_log.meta;
730
+ this.message = command_log.message;
731
+ this.retries =
732
+ retries !== undefined
733
+ ? retries
734
+ : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
735
+ this.isOld = true;
736
+ this.failedAt = command_log.failedAt;
737
+ this.succeededAt = command_log.succeededAt;
738
+ this.skippedAt = command_log.skippedAt;
739
+ this.receivedAt = command_log.receivedAt;
740
+ this.processedAt = command_log.processedAt;
741
+ this.onGoing = command_log.onGoing || false;
742
+ this.trigger = command_log.trigger;
743
+ // this.priority = command_log.priority
744
+ // ? command_log.priority
745
+ // : this.priority
746
+ // ? this.priority
747
+ // : undefined;
748
+ }
749
+ }
750
+ return this;
751
+ }
752
+ setStatus(status, error) {
753
+ this.addDetail(`status was changed from ${this.status} to ${status}`);
754
+ this.status = status;
755
+ if (error) {
756
+ this.error = error;
757
+ }
758
+ switch (status) {
759
+ case "fail":
760
+ this.failedAt = new Date();
761
+ this.onGoing = false;
762
+ break;
763
+ case "processing":
764
+ this.processedAt = new Date();
765
+ this.onGoing = true;
766
+ break;
767
+ case "queued":
768
+ this.queuedAt = new Date();
769
+ this.onGoing = true;
770
+ break;
771
+ case "received":
772
+ this.receivedAt = new Date();
773
+ this.onGoing = true;
774
+ break;
775
+ case "skipped":
776
+ this.skippedAt = new Date();
777
+ this.onGoing = false;
778
+ break;
779
+ case "success":
780
+ this.succeededAt = new Date();
781
+ this.onGoing = false;
782
+ break;
783
+ }
784
+ return this;
785
+ }
786
+ setBody(body) {
787
+ this.body = body;
788
+ return this;
789
+ }
790
+ setMeta(meta) {
791
+ this.meta = meta;
792
+ return this;
793
+ }
794
+ async commit() {
795
+ let doc = {
796
+ available_app_name: this.available_app_name,
797
+ available_app_id: this.available_app_id,
798
+ app_id: this.app_id,
799
+ command: this.command,
800
+ status: this.status,
801
+ error: this.error ? this.error : undefined,
802
+ start_time: this.start_time,
803
+ end_time: Date.now(),
804
+ total_time: Date.now() - this.start_time,
805
+ company_namespace: this.company_namespace,
806
+ body: this.body,
807
+ meta: this.meta,
808
+ message: this.message,
809
+ details: this.details,
810
+ sync_id: this.sync_id,
811
+ // priority: this.priority ? this.priority : undefined,
812
+ queuedAt: this.queuedAt ? this.queuedAt : undefined,
813
+ failedAt: this.failedAt ? this.failedAt : undefined,
814
+ succeededAt: this.succeededAt ? this.succeededAt : undefined,
815
+ skippedAt: this.skippedAt ? this.skippedAt : undefined,
816
+ receivedAt: this.receivedAt ? this.receivedAt : undefined,
817
+ processedAt: this.processedAt ? this.processedAt : undefined,
818
+ onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
819
+ retries: this.retries !== undefined ? this.retries : undefined,
820
+ trigger: this.trigger,
821
+ };
822
+ try {
823
+ const res = await this.superThis._create(this.superThis.svAPIEndpoint, this._path, doc);
824
+ this.isOld = true;
825
+ }
826
+ catch (e) {
827
+ console.error(e);
828
+ }
829
+ return this;
830
+ }
831
+ addDetail(detail, meta) {
832
+ let d = {
833
+ timestamp: Date.now(),
834
+ content: detail,
835
+ };
836
+ if (meta)
837
+ d.meta = meta;
838
+ this.details.push(d);
839
+ return this;
840
+ }
841
+ };
@@ -3658,5 +3658,282 @@ export declare namespace Service {
3658
3658
  }
3659
3659
  }
3660
3660
  }
3661
+ namespace ActionLogs {
3662
+ export type Status = "success" | "fail" | "processing";
3663
+ export type Detail = {
3664
+ timestamp: number;
3665
+ content: string;
3666
+ meta?: {
3667
+ [key: string]: any;
3668
+ };
3669
+ };
3670
+ export interface Schema {
3671
+ _id: string;
3672
+ available_app_name: string;
3673
+ available_app_id: string;
3674
+ app_id: string;
3675
+ sync_id: string;
3676
+ action: string;
3677
+ status: Status;
3678
+ error?: {
3679
+ [key: string]: any;
3680
+ };
3681
+ start_time: number;
3682
+ end_time?: number;
3683
+ total_time?: number;
3684
+ company_namespace: string[];
3685
+ body?: {
3686
+ [key: string]: any;
3687
+ };
3688
+ meta?: {
3689
+ [key: string]: any;
3690
+ };
3691
+ message: string;
3692
+ details: Detail[];
3693
+ createdAt: string;
3694
+ updatedAt: string;
3695
+ __v: number;
3696
+ }
3697
+ interface Data {
3698
+ available_app_name: string;
3699
+ available_app_id: string;
3700
+ app_id: string;
3701
+ sync_id?: string;
3702
+ action: string;
3703
+ status: Status;
3704
+ error?: {
3705
+ [key: string]: any;
3706
+ };
3707
+ start_time: number;
3708
+ end_time?: number;
3709
+ total_time?: number;
3710
+ company_namespace?: string[];
3711
+ body?: {
3712
+ [key: string]: any;
3713
+ };
3714
+ meta?: {
3715
+ [key: string]: any;
3716
+ };
3717
+ message: string;
3718
+ details: Detail[];
3719
+ }
3720
+ export namespace Find {
3721
+ type Params = DefaultPaginationQueryParams & {
3722
+ _id?: string[] | string;
3723
+ available_app_name?: string[] | string;
3724
+ available_app_id?: string[] | string;
3725
+ app_id?: string[] | string;
3726
+ action?: string[] | string;
3727
+ status?: Status[] | Status;
3728
+ sync_id?: string[] | string;
3729
+ disabled?: boolean;
3730
+ start_time?: number;
3731
+ end_time?: number;
3732
+ total_time?: number;
3733
+ };
3734
+ interface Result extends DefaultPaginationResult {
3735
+ data: Schema[];
3736
+ }
3737
+ }
3738
+ export namespace Get {
3739
+ type ID = string;
3740
+ interface Params {
3741
+ available_app_name?: string[] | string;
3742
+ available_app_id?: string[] | string;
3743
+ app_id?: string[] | string;
3744
+ action?: string[] | string;
3745
+ status?: Status[] | Status;
3746
+ sync_id?: string[] | string;
3747
+ disabled?: boolean;
3748
+ start_time?: number;
3749
+ end_time?: number;
3750
+ total_time?: number;
3751
+ }
3752
+ type Result = Schema;
3753
+ }
3754
+ export namespace Create {
3755
+ type Body = Data;
3756
+ type Result = Schema;
3757
+ }
3758
+ export namespace Update {
3759
+ type ID = string;
3760
+ interface Body extends Data {
3761
+ _id?: string;
3762
+ sync_id: string;
3763
+ createdAt?: string;
3764
+ updatedAt?: string;
3765
+ __v?: number;
3766
+ }
3767
+ type Result = Schema;
3768
+ }
3769
+ export {};
3770
+ }
3771
+ namespace CommandLog {
3772
+ export type Status = "success" | "fail" | "processing" | "queued" | "received" | "skipped";
3773
+ export type Detail = {
3774
+ timestamp: number;
3775
+ content: string;
3776
+ meta?: {
3777
+ [key: string]: any;
3778
+ };
3779
+ };
3780
+ export interface Schema {
3781
+ _id: string;
3782
+ command: string;
3783
+ available_app_name: string;
3784
+ available_app_id: string;
3785
+ app_id: string;
3786
+ status: Status;
3787
+ error?: {
3788
+ [key: string]: any;
3789
+ };
3790
+ start_time: number;
3791
+ end_time?: number;
3792
+ total_time?: number;
3793
+ company_namespace: string[];
3794
+ body?: {
3795
+ [key: string]: any;
3796
+ };
3797
+ meta?: {
3798
+ [key: string]: any;
3799
+ };
3800
+ message: string;
3801
+ details: Detail[];
3802
+ sync_id: string;
3803
+ queuedAt?: Date;
3804
+ failedAt?: Date;
3805
+ succeededAt?: Date;
3806
+ skippedAt?: Date;
3807
+ receivedAt?: Date;
3808
+ processedAt?: Date;
3809
+ onGoing?: boolean;
3810
+ retries?: number;
3811
+ trigger?: string;
3812
+ createdAt: string;
3813
+ updatedAt: string;
3814
+ __v: number;
3815
+ }
3816
+ interface Data {
3817
+ command: string;
3818
+ available_app_name: string;
3819
+ available_app_id: string;
3820
+ app_id: string;
3821
+ status: Status;
3822
+ error?: {
3823
+ [key: string]: any;
3824
+ };
3825
+ start_time: number;
3826
+ end_time?: number;
3827
+ total_time?: number;
3828
+ company_namespace: string[];
3829
+ body?: {
3830
+ [key: string]: any;
3831
+ };
3832
+ meta?: {
3833
+ [key: string]: any;
3834
+ };
3835
+ message: string;
3836
+ details: Detail[];
3837
+ sync_id?: string;
3838
+ queuedAt?: Date;
3839
+ failedAt?: Date;
3840
+ succeededAt?: Date;
3841
+ skippedAt?: Date;
3842
+ receivedAt?: Date;
3843
+ processedAt?: Date;
3844
+ onGoing?: boolean;
3845
+ retries?: number;
3846
+ trigger?: string;
3847
+ }
3848
+ export namespace Find {
3849
+ type Params = DefaultPaginationQueryParams & {
3850
+ _id?: string[] | string;
3851
+ available_app_name?: string[] | string;
3852
+ available_app_id?: string[] | string;
3853
+ app_id?: string[] | string;
3854
+ command?: string[] | string;
3855
+ status?: Status[] | Status;
3856
+ sync_id?: string[] | string;
3857
+ disabled?: boolean;
3858
+ start_time?: number;
3859
+ end_time?: number;
3860
+ total_time?: number;
3861
+ };
3862
+ interface Result extends DefaultPaginationResult {
3863
+ data: Schema[];
3864
+ }
3865
+ }
3866
+ export namespace Get {
3867
+ type ID = string;
3868
+ interface Params {
3869
+ available_app_name?: string[] | string;
3870
+ available_app_id?: string[] | string;
3871
+ app_id?: string[] | string;
3872
+ command?: string[] | string;
3873
+ status?: Status[] | Status;
3874
+ sync_id?: string[] | string;
3875
+ disabled?: boolean;
3876
+ start_time?: number;
3877
+ end_time?: number;
3878
+ total_time?: number;
3879
+ }
3880
+ type Result = Schema;
3881
+ }
3882
+ export namespace Create {
3883
+ type Body = Data;
3884
+ type Result = Schema;
3885
+ }
3886
+ export namespace Update {
3887
+ type ID = string;
3888
+ interface Body extends Data {
3889
+ _id?: string;
3890
+ sync_id: string;
3891
+ createdAt?: string;
3892
+ updatedAt?: string;
3893
+ __v?: number;
3894
+ }
3895
+ type Result = Schema;
3896
+ }
3897
+ export {};
3898
+ }
3899
+ namespace App {
3900
+ interface Schema {
3901
+ _id: string;
3902
+ name: string;
3903
+ disabled?: boolean;
3904
+ available_app: string;
3905
+ formData: any;
3906
+ company_namespace: string[];
3907
+ createdAt: string;
3908
+ updatedAt: string;
3909
+ __v: number;
3910
+ }
3911
+ interface Schema_with_populated_AvailableApp {
3912
+ _id: string;
3913
+ name: string;
3914
+ disabled?: boolean;
3915
+ available_app: AvailableApp;
3916
+ formData: any;
3917
+ company_namespace: string[];
3918
+ createdAt: string;
3919
+ updatedAt: string;
3920
+ __v: number;
3921
+ }
3922
+ }
3923
+ interface AvailableApp {
3924
+ _id: StringId;
3925
+ name: string;
3926
+ disabled: boolean;
3927
+ JSONSchema: any;
3928
+ UISchema: any;
3929
+ app_settings: {
3930
+ repo: string;
3931
+ serviceEndPoint: string;
3932
+ meta: {};
3933
+ };
3934
+ app_category: string;
3935
+ }
3661
3936
  }
3937
+ export declare type StringId = string;
3938
+ export declare type NameSpaces = string[];
3662
3939
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repzo",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Repzo TypeScript SDK",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -23,12 +23,14 @@
23
23
  },
24
24
  "homepage": "https://github.com/Repzo/repzo-ts#readme",
25
25
  "dependencies": {
26
- "@babel/parser": "^7.14.7"
26
+ "@babel/parser": "^7.14.7",
27
+ "uuid": "^8.3.2"
27
28
  },
28
29
  "devDependencies": {
30
+ "@types/uuid": "^8.3.4",
31
+ "axios": "^0.26.1",
29
32
  "prettier": "2.1.2",
30
- "typescript": "^4.3.4",
31
- "axios": "^0.26.1"
33
+ "typescript": "^4.3.4"
32
34
  },
33
35
  "build": "tsc"
34
36
  }
package/src/index.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import axios from "axios";
2
- import { Params, Data, Service, Options, Headers } from "./types/index";
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";
3
12
 
4
13
  export default class Repzo {
5
14
  private svAPIEndpoint: string;
@@ -1423,4 +1432,303 @@ export default class Repzo {
1423
1432
  return res;
1424
1433
  },
1425
1434
  };
1435
+
1436
+ static ActionLogs = class {
1437
+ _path: string = "/integration-action-log";
1438
+ available_app_name: string = "";
1439
+ available_app_id: StringId = "";
1440
+ app_id: StringId = "";
1441
+ action: string = "";
1442
+ status: Service.ActionLogs.Status;
1443
+ error?: any;
1444
+ start_time: number;
1445
+ end_time?: number;
1446
+ total_time?: number;
1447
+ company_namespace?: NameSpaces;
1448
+ body?: any;
1449
+ meta?: any;
1450
+ message: string;
1451
+ details: Service.ActionLogs.Detail[];
1452
+ sync_id: string;
1453
+ isOld: boolean;
1454
+ constructor(public superThis: Repzo, sync_id: string) {
1455
+ this.start_time = Date.now();
1456
+ this.status = "processing";
1457
+ this.message = "Log Created";
1458
+ this.details = [];
1459
+ this.sync_id = sync_id;
1460
+ this.isOld = true;
1461
+ }
1462
+ async load(sync_id: string) {
1463
+ console.log(sync_id);
1464
+ const params: Service.ActionLogs.Find.Params = { sync_id: sync_id };
1465
+ const res: Service.ActionLogs.Find.Result = await this.superThis._fetch(
1466
+ this.superThis.svAPIEndpoint,
1467
+ this._path,
1468
+ params
1469
+ );
1470
+ if (res?.data?.length)
1471
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1472
+ const action_log: Service.ActionLogs.Schema = res.data[0];
1473
+ this.sync_id = sync_id;
1474
+ this.details = action_log.details;
1475
+ this.status = action_log.status;
1476
+ this.error = action_log.error;
1477
+ this.start_time = action_log.start_time;
1478
+ this.body = action_log.body;
1479
+ this.meta = action_log.meta;
1480
+ this.message = action_log.message;
1481
+ this.app_id = action_log._id;
1482
+ this.available_app_id = action_log.available_app_id;
1483
+ this.available_app_name = action_log.available_app_name;
1484
+ this.company_namespace = action_log.company_namespace;
1485
+ this.action = action_log.action;
1486
+ this.isOld = true;
1487
+
1488
+ return this;
1489
+ }
1490
+ async setStatus(status: Service.ActionLogs.Status, error?: any) {
1491
+ this.details.push({
1492
+ timestamp: Date.now(),
1493
+ content: `status was changed from ${this.status} to ${status}`,
1494
+ });
1495
+ this.status = status;
1496
+ if (error) {
1497
+ this.error = error;
1498
+ }
1499
+ return this;
1500
+ }
1501
+ setBody(body: any) {
1502
+ this.body = body;
1503
+ return this;
1504
+ }
1505
+ setMeta(meta: any) {
1506
+ this.meta = meta;
1507
+ return this;
1508
+ }
1509
+ async commit() {
1510
+ let doc: Service.ActionLogs.Create.Body = {
1511
+ available_app_name: this.available_app_name,
1512
+ available_app_id: this.available_app_id,
1513
+ app_id: this.app_id,
1514
+ action: this.action,
1515
+ company_namespace: this.company_namespace,
1516
+ status: this.status,
1517
+ error: this.error ? this.error : undefined,
1518
+ start_time: this.start_time,
1519
+ end_time: Date.now(),
1520
+ total_time: Date.now() - this.start_time,
1521
+ body: this.body,
1522
+ meta: this.meta,
1523
+ message: this.message,
1524
+ details: this.details,
1525
+ sync_id: this.sync_id,
1526
+ };
1527
+ try {
1528
+ const res: Service.ActionLogs.Create.Result = await this.superThis._create(
1529
+ this.superThis.svAPIEndpoint,
1530
+ this._path,
1531
+ doc
1532
+ );
1533
+ } catch (e) {
1534
+ console.error(e);
1535
+ }
1536
+ return this;
1537
+ }
1538
+ addDetail(detail: string, meta: any) {
1539
+ let d: Service.ActionLogs.Detail = {
1540
+ timestamp: Date.now(),
1541
+ content: detail,
1542
+ };
1543
+ if (meta) d.meta = meta;
1544
+ this.details.push(d);
1545
+ return this;
1546
+ }
1547
+ };
1548
+
1549
+ static CommandLog = class {
1550
+ _path: string = "/integration-command-log";
1551
+ available_app_name: string;
1552
+ available_app_id: StringId;
1553
+ app_id: StringId;
1554
+ command: string;
1555
+ status: Service.CommandLog.Status;
1556
+ error?: any;
1557
+ start_time: number;
1558
+ end_time?: number;
1559
+ total_time?: number;
1560
+ company_namespace: NameSpaces;
1561
+ body?: any;
1562
+ meta?: any;
1563
+ message: string;
1564
+ details: Service.CommandLog.Detail[];
1565
+ sync_id: string;
1566
+ isOld: boolean;
1567
+ priority?: number;
1568
+ isPrioritized: boolean;
1569
+ retries: number;
1570
+ queuedAt?: Date;
1571
+ failedAt?: Date;
1572
+ succeededAt?: Date;
1573
+ skippedAt?: Date;
1574
+ receivedAt?: Date;
1575
+ processedAt?: Date;
1576
+ onGoing: boolean;
1577
+ trigger?: string;
1578
+ constructor(
1579
+ public superThis: Repzo,
1580
+ app: Service.App.Schema_with_populated_AvailableApp,
1581
+ command: string,
1582
+ trigger?: string
1583
+ ) {
1584
+ this.app_id = app._id;
1585
+ this.available_app_id = app.available_app._id;
1586
+ this.available_app_name = app.available_app.name;
1587
+ this.company_namespace = app.company_namespace;
1588
+ this.start_time = Date.now();
1589
+ this.status = "received";
1590
+ this.message = "Request received";
1591
+ this.command = command;
1592
+ this.details = [{ timestamp: Date.now(), content: "Request received" }];
1593
+ this.sync_id = uuid();
1594
+ this.isOld = false;
1595
+ this.isPrioritized = false;
1596
+ this.retries = 1;
1597
+ this.trigger = trigger;
1598
+ this.onGoing = true;
1599
+ }
1600
+ async load(sync_id?: string, retries?: number) {
1601
+ if (sync_id) {
1602
+ const params: Service.CommandLog.Find.Params = { sync_id: sync_id };
1603
+ const res: Service.CommandLog.Find.Result = await this.superThis._fetch(
1604
+ this.superThis.svAPIEndpoint,
1605
+ this._path,
1606
+ params
1607
+ );
1608
+ if (res?.data?.length)
1609
+ throw new Error(`Command Log Not found, sync_id: ${sync_id}`);
1610
+ const command_log: Service.CommandLog.Schema = res.data[0];
1611
+
1612
+ if (command_log) {
1613
+ this.sync_id = sync_id;
1614
+ this.details = command_log.details;
1615
+ this.status = command_log.status;
1616
+ this.error = command_log.error;
1617
+ this.start_time = command_log.start_time;
1618
+ this.body = command_log.body;
1619
+ this.meta = command_log.meta;
1620
+ this.message = command_log.message;
1621
+ this.retries =
1622
+ retries !== undefined
1623
+ ? retries
1624
+ : command_log.retries || this.retries; // retries !== undefined ? retries : command_log.retries;
1625
+ this.isOld = true;
1626
+ this.failedAt = command_log.failedAt;
1627
+ this.succeededAt = command_log.succeededAt;
1628
+ this.skippedAt = command_log.skippedAt;
1629
+ this.receivedAt = command_log.receivedAt;
1630
+ this.processedAt = command_log.processedAt;
1631
+ this.onGoing = command_log.onGoing || false;
1632
+ this.trigger = command_log.trigger;
1633
+ // this.priority = command_log.priority
1634
+ // ? command_log.priority
1635
+ // : this.priority
1636
+ // ? this.priority
1637
+ // : undefined;
1638
+ }
1639
+ }
1640
+ return this;
1641
+ }
1642
+ setStatus(status: Service.CommandLog.Status, error?: any) {
1643
+ this.addDetail(`status was changed from ${this.status} to ${status}`);
1644
+ this.status = status;
1645
+ if (error) {
1646
+ this.error = error;
1647
+ }
1648
+ switch (status) {
1649
+ case "fail":
1650
+ this.failedAt = new Date();
1651
+ this.onGoing = false;
1652
+ break;
1653
+ case "processing":
1654
+ this.processedAt = new Date();
1655
+ this.onGoing = true;
1656
+ break;
1657
+ case "queued":
1658
+ this.queuedAt = new Date();
1659
+ this.onGoing = true;
1660
+ break;
1661
+ case "received":
1662
+ this.receivedAt = new Date();
1663
+ this.onGoing = true;
1664
+ break;
1665
+ case "skipped":
1666
+ this.skippedAt = new Date();
1667
+ this.onGoing = false;
1668
+ break;
1669
+ case "success":
1670
+ this.succeededAt = new Date();
1671
+ this.onGoing = false;
1672
+ break;
1673
+ }
1674
+ return this;
1675
+ }
1676
+ setBody(body: any) {
1677
+ this.body = body;
1678
+ return this;
1679
+ }
1680
+ setMeta(meta: any) {
1681
+ this.meta = meta;
1682
+ return this;
1683
+ }
1684
+ async commit() {
1685
+ let doc: Service.CommandLog.Create.Body = {
1686
+ available_app_name: this.available_app_name,
1687
+ available_app_id: this.available_app_id,
1688
+ app_id: this.app_id,
1689
+ command: this.command,
1690
+ status: this.status,
1691
+ error: this.error ? this.error : undefined,
1692
+ start_time: this.start_time,
1693
+ end_time: Date.now(),
1694
+ total_time: Date.now() - this.start_time,
1695
+ company_namespace: this.company_namespace,
1696
+ body: this.body,
1697
+ meta: this.meta,
1698
+ message: this.message,
1699
+ details: this.details,
1700
+ sync_id: this.sync_id,
1701
+ // priority: this.priority ? this.priority : undefined,
1702
+ queuedAt: this.queuedAt ? this.queuedAt : undefined,
1703
+ failedAt: this.failedAt ? this.failedAt : undefined,
1704
+ succeededAt: this.succeededAt ? this.succeededAt : undefined,
1705
+ skippedAt: this.skippedAt ? this.skippedAt : undefined,
1706
+ receivedAt: this.receivedAt ? this.receivedAt : undefined,
1707
+ processedAt: this.processedAt ? this.processedAt : undefined,
1708
+ onGoing: this.onGoing !== undefined ? this.onGoing : undefined,
1709
+ retries: this.retries !== undefined ? this.retries : undefined,
1710
+ trigger: this.trigger,
1711
+ };
1712
+ try {
1713
+ const res: Service.CommandLog.Create.Result = await this.superThis._create(
1714
+ this.superThis.svAPIEndpoint,
1715
+ this._path,
1716
+ doc
1717
+ );
1718
+ this.isOld = true;
1719
+ } catch (e) {
1720
+ console.error(e);
1721
+ }
1722
+ return this;
1723
+ }
1724
+ addDetail(detail: string, meta?: any) {
1725
+ let d: Service.CommandLog.Detail = {
1726
+ timestamp: Date.now(),
1727
+ content: detail,
1728
+ };
1729
+ if (meta) d.meta = meta;
1730
+ this.details.push(d);
1731
+ return this;
1732
+ }
1733
+ };
1426
1734
  }
@@ -3750,4 +3750,268 @@ export namespace Service {
3750
3750
  }
3751
3751
  }
3752
3752
  }
3753
+
3754
+ export namespace ActionLogs {
3755
+ export type Status = "success" | "fail" | "processing";
3756
+ export type Detail = {
3757
+ timestamp: number;
3758
+ content: string;
3759
+ meta?: { [key: string]: any };
3760
+ };
3761
+ export interface Schema {
3762
+ _id: string;
3763
+ available_app_name: string;
3764
+ available_app_id: string;
3765
+ app_id: string;
3766
+ sync_id: string;
3767
+ action: string;
3768
+ status: Status;
3769
+ error?: { [key: string]: any };
3770
+ start_time: number;
3771
+ end_time?: number;
3772
+ total_time?: number;
3773
+ company_namespace: string[];
3774
+ body?: { [key: string]: any };
3775
+ meta?: { [key: string]: any };
3776
+ message: string;
3777
+ details: Detail[];
3778
+ createdAt: string;
3779
+ updatedAt: string;
3780
+ __v: number;
3781
+ }
3782
+
3783
+ interface Data {
3784
+ available_app_name: string;
3785
+ available_app_id: string;
3786
+ app_id: string;
3787
+ sync_id?: string;
3788
+ action: string;
3789
+ status: Status;
3790
+ error?: { [key: string]: any };
3791
+ start_time: number;
3792
+ end_time?: number;
3793
+ total_time?: number;
3794
+ company_namespace?: string[];
3795
+ body?: { [key: string]: any };
3796
+ meta?: { [key: string]: any };
3797
+ message: string;
3798
+ details: Detail[];
3799
+ }
3800
+
3801
+ export namespace Find {
3802
+ export type Params = DefaultPaginationQueryParams & {
3803
+ _id?: string[] | string;
3804
+ available_app_name?: string[] | string;
3805
+ available_app_id?: string[] | string;
3806
+ app_id?: string[] | string;
3807
+ action?: string[] | string;
3808
+ status?: Status[] | Status;
3809
+ sync_id?: string[] | string;
3810
+ disabled?: boolean;
3811
+ start_time?: number;
3812
+ end_time?: number;
3813
+ total_time?: number;
3814
+ };
3815
+ export interface Result extends DefaultPaginationResult {
3816
+ data: Schema[];
3817
+ }
3818
+ }
3819
+
3820
+ export namespace Get {
3821
+ export type ID = string;
3822
+ export interface Params {
3823
+ available_app_name?: string[] | string;
3824
+ available_app_id?: string[] | string;
3825
+ app_id?: string[] | string;
3826
+ action?: string[] | string;
3827
+ status?: Status[] | Status;
3828
+ sync_id?: string[] | string;
3829
+ disabled?: boolean;
3830
+ start_time?: number;
3831
+ end_time?: number;
3832
+ total_time?: number;
3833
+ }
3834
+ export type Result = Schema;
3835
+ }
3836
+
3837
+ export namespace Create {
3838
+ export type Body = Data;
3839
+ export type Result = Schema;
3840
+ }
3841
+
3842
+ export namespace Update {
3843
+ export type ID = string;
3844
+ export interface Body extends Data {
3845
+ _id?: string;
3846
+ sync_id: string;
3847
+ createdAt?: string;
3848
+ updatedAt?: string;
3849
+ __v?: number;
3850
+ }
3851
+ export type Result = Schema;
3852
+ }
3853
+ }
3854
+
3855
+ export namespace CommandLog {
3856
+ export type Status =
3857
+ | "success"
3858
+ | "fail"
3859
+ | "processing"
3860
+ | "queued"
3861
+ | "received"
3862
+ | "skipped";
3863
+ export type Detail = {
3864
+ timestamp: number;
3865
+ content: string;
3866
+ meta?: { [key: string]: any };
3867
+ };
3868
+ export interface Schema {
3869
+ _id: string;
3870
+ command: string;
3871
+ available_app_name: string;
3872
+ available_app_id: string;
3873
+ app_id: string;
3874
+ status: Status;
3875
+ error?: { [key: string]: any };
3876
+ start_time: number;
3877
+ end_time?: number;
3878
+ total_time?: number;
3879
+ company_namespace: string[];
3880
+ body?: { [key: string]: any };
3881
+ meta?: { [key: string]: any };
3882
+ message: string;
3883
+ details: Detail[];
3884
+ sync_id: string;
3885
+ queuedAt?: Date;
3886
+ failedAt?: Date;
3887
+ succeededAt?: Date;
3888
+ skippedAt?: Date;
3889
+ receivedAt?: Date;
3890
+ processedAt?: Date;
3891
+ onGoing?: boolean;
3892
+ retries?: number;
3893
+ trigger?: string;
3894
+ createdAt: string;
3895
+ updatedAt: string;
3896
+ __v: number;
3897
+ }
3898
+
3899
+ interface Data {
3900
+ command: string;
3901
+ available_app_name: string;
3902
+ available_app_id: string;
3903
+ app_id: string;
3904
+ status: Status;
3905
+ error?: { [key: string]: any };
3906
+ start_time: number;
3907
+ end_time?: number;
3908
+ total_time?: number;
3909
+ company_namespace: string[];
3910
+ body?: { [key: string]: any };
3911
+ meta?: { [key: string]: any };
3912
+ message: string;
3913
+ details: Detail[];
3914
+ sync_id?: string;
3915
+ queuedAt?: Date;
3916
+ failedAt?: Date;
3917
+ succeededAt?: Date;
3918
+ skippedAt?: Date;
3919
+ receivedAt?: Date;
3920
+ processedAt?: Date;
3921
+ onGoing?: boolean;
3922
+ retries?: number;
3923
+ trigger?: string;
3924
+ }
3925
+
3926
+ export namespace Find {
3927
+ export type Params = DefaultPaginationQueryParams & {
3928
+ _id?: string[] | string;
3929
+ available_app_name?: string[] | string;
3930
+ available_app_id?: string[] | string;
3931
+ app_id?: string[] | string;
3932
+ command?: string[] | string;
3933
+ status?: Status[] | Status;
3934
+ sync_id?: string[] | string;
3935
+ disabled?: boolean;
3936
+ start_time?: number;
3937
+ end_time?: number;
3938
+ total_time?: number;
3939
+ };
3940
+ export interface Result extends DefaultPaginationResult {
3941
+ data: Schema[];
3942
+ }
3943
+ }
3944
+
3945
+ export namespace Get {
3946
+ export type ID = string;
3947
+ export interface Params {
3948
+ available_app_name?: string[] | string;
3949
+ available_app_id?: string[] | string;
3950
+ app_id?: string[] | string;
3951
+ command?: string[] | string;
3952
+ status?: Status[] | Status;
3953
+ sync_id?: string[] | string;
3954
+ disabled?: boolean;
3955
+ start_time?: number;
3956
+ end_time?: number;
3957
+ total_time?: number;
3958
+ }
3959
+ export type Result = Schema;
3960
+ }
3961
+
3962
+ export namespace Create {
3963
+ export type Body = Data;
3964
+ export type Result = Schema;
3965
+ }
3966
+
3967
+ export namespace Update {
3968
+ export type ID = string;
3969
+ export interface Body extends Data {
3970
+ _id?: string;
3971
+ sync_id: string;
3972
+ createdAt?: string;
3973
+ updatedAt?: string;
3974
+ __v?: number;
3975
+ }
3976
+ export type Result = Schema;
3977
+ }
3978
+ }
3979
+
3980
+ export namespace App {
3981
+ export interface Schema {
3982
+ _id: string;
3983
+ name: string;
3984
+ disabled?: boolean;
3985
+ available_app: string;
3986
+ formData: any;
3987
+ company_namespace: string[];
3988
+ createdAt: string;
3989
+ updatedAt: string;
3990
+ __v: number;
3991
+ }
3992
+ export interface Schema_with_populated_AvailableApp {
3993
+ _id: string;
3994
+ name: string;
3995
+ disabled?: boolean;
3996
+ available_app: AvailableApp;
3997
+ formData: any;
3998
+ company_namespace: string[];
3999
+ createdAt: string;
4000
+ updatedAt: string;
4001
+ __v: number;
4002
+ }
4003
+ }
4004
+
4005
+ export interface AvailableApp {
4006
+ _id: StringId;
4007
+ name: string;
4008
+ disabled: boolean;
4009
+ JSONSchema: any;
4010
+ UISchema: any;
4011
+ app_settings: { repo: string; serviceEndPoint: string; meta: {} };
4012
+ app_category: string;
4013
+ }
3753
4014
  }
4015
+
4016
+ export type StringId = string;
4017
+ export type NameSpaces = string[];