@diagramers/cli 1.0.24 → 1.0.26

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.
Files changed (47) hide show
  1. package/README.md +217 -391
  2. package/dist/services/template-updater.d.ts +0 -1
  3. package/dist/services/template-updater.d.ts.map +1 -1
  4. package/dist/services/template-updater.js +2 -41
  5. package/dist/services/template-updater.js.map +1 -1
  6. package/package.json +1 -1
  7. package/templates/api/certs/auth-app-cert.json +0 -13
  8. package/templates/api/main.ts +0 -10
  9. package/templates/api/package.json +0 -70
  10. package/templates/api/src/assets/css/email-template.css +0 -8
  11. package/templates/api/src/assets/images/logo_large.png +0 -0
  12. package/templates/api/src/assets/keys/certificate.pem +0 -22
  13. package/templates/api/src/assets/keys/private-key.pem +0 -28
  14. package/templates/api/src/config/config-interface.ts +0 -191
  15. package/templates/api/src/config/development.ts +0 -145
  16. package/templates/api/src/config/index.ts +0 -59
  17. package/templates/api/src/config/production.ts +0 -145
  18. package/templates/api/src/config/staging.ts +0 -144
  19. package/templates/api/src/config/uat.ts +0 -144
  20. package/templates/api/src/controllers/account-controller.ts +0 -162
  21. package/templates/api/src/entities/audit.ts +0 -12
  22. package/templates/api/src/entities/base-entity.ts +0 -10
  23. package/templates/api/src/entities/user.ts +0 -71
  24. package/templates/api/src/helpers/FrameworkHelper.ts +0 -157
  25. package/templates/api/src/helpers/auth.ts +0 -971
  26. package/templates/api/src/helpers/cronHelper.ts +0 -170
  27. package/templates/api/src/helpers/dbcontext.ts +0 -83
  28. package/templates/api/src/helpers/encryptionHelper.ts +0 -76
  29. package/templates/api/src/helpers/enums.ts +0 -258
  30. package/templates/api/src/helpers/handle-response.ts +0 -49
  31. package/templates/api/src/helpers/httpHelper.ts +0 -75
  32. package/templates/api/src/helpers/mailer.ts +0 -152
  33. package/templates/api/src/helpers/result.ts +0 -47
  34. package/templates/api/src/helpers/string-helper.ts +0 -27
  35. package/templates/api/src/routes/account-routes.ts +0 -37
  36. package/templates/api/src/routes/auth-routes.ts +0 -286
  37. package/templates/api/src/routes/index.ts +0 -92
  38. package/templates/api/src/schemas/audit.ts +0 -36
  39. package/templates/api/src/schemas/otp.ts +0 -52
  40. package/templates/api/src/schemas/session.ts +0 -57
  41. package/templates/api/src/schemas/user.ts +0 -125
  42. package/templates/api/src/server/index.ts +0 -86
  43. package/templates/api/src/server/socket-server-provider.ts +0 -209
  44. package/templates/api/src/services/account-service.ts +0 -243
  45. package/templates/api/src/services/audit-service.ts +0 -56
  46. package/templates/api/tsconfig.json +0 -16
  47. package/templates/api/webpack.config.js +0 -66
@@ -1,170 +0,0 @@
1
- import * as cron from 'node-cron';
2
- import { AuditMessageType, ResponseCode, ScheduleSlot } from '../helpers/enums';
3
- import { Result } from '../helpers/result';
4
- import { ObjectId } from 'bson';
5
- import { Config } from '../config';
6
-
7
- interface ScheduleData {
8
- cronExpression: string;
9
- startTime?: Date;
10
- timeZone?: string;
11
- frequency?: number; // Frequency in milliseconds for repetition
12
- }
13
-
14
- interface ScheduleOptions {
15
- _id: ObjectId;
16
- name: String;
17
- _taskScheduleId: ObjectId;
18
- slot: ScheduleSlot,
19
- _taskRunId: ObjectId;
20
- startAt: Date,
21
- onExecutionScript: String,
22
- onSuccessScript: String,
23
- onFailureScript: String,
24
- onFinalizeScript: String,
25
- className: String,
26
- methodName: String,
27
- taskType: Number
28
- }
29
-
30
- class CronHelper {
31
- private static instance: CronHelper;
32
- private scheduledJobs: Map<string, cron.ScheduledTask> = new Map();
33
- result: Result;
34
- className: 'CronHelper';
35
- private constructor(
36
- result: Result
37
- ) {
38
- this.result = result;
39
- }
40
-
41
- public static getInstance(): CronHelper {
42
- if (!CronHelper.instance) {
43
- CronHelper.instance = new CronHelper(new Result(null, ResponseCode.Incompelete, [], [], new ObjectId().toString(), {}, {}));
44
- }
45
- return CronHelper.instance;
46
- }
47
-
48
- public async scheduleTask(taskId): Promise<Result> {
49
- // const { slot, scheduleData, taskScript, onSuccess, onFailure, onFinish } = options //task-schedule-entity;
50
- try {
51
- this.result.addMessage(AuditMessageType.info, this.className, 'scheduleTask', `Started`);
52
- var taskService = null;//new TaskService(this.result);
53
- var scheduleTaskForRun = Object.assign({}, await taskService.StartTaskSchedule(taskId));
54
- if (scheduleTaskForRun.Status != ResponseCode.Ok) {
55
-
56
- }
57
- else {
58
- this.result.addMessage(AuditMessageType.info, this.className, 'scheduleTask', `Task {${scheduleTaskForRun.Data._id} - ${scheduleTaskForRun.Data.name}} scheduled for execution`);
59
- let cronExpression = '';
60
- var scheduleData: ScheduleOptions = scheduleTaskForRun.Data;
61
- if (scheduleData.slot === ScheduleSlot.CUSTOM) {
62
- cronExpression = scheduleData.slot;
63
- } else if (scheduleData.slot === ScheduleSlot.EVERY_DAY_AT) {
64
- cronExpression = `0 ${scheduleData.startAt?.getMinutes()} ${scheduleData.startAt?.getHours()} * * *`;
65
- } else if (scheduleData.slot === ScheduleSlot.EVERY_WEEK_AT) {
66
- cronExpression = `0 ${scheduleData.startAt?.getMinutes()} ${scheduleData.startAt?.getHours()} * * ${scheduleData.startAt?.getDay()}`;
67
- } else if (scheduleData.slot === ScheduleSlot.EVERY_MONTH_AT) {
68
- cronExpression = `0 ${scheduleData.startAt?.getMinutes()} ${scheduleData.startAt?.getHours()} ${scheduleData.startAt?.getDate()} * *`;
69
- } else {
70
- cronExpression = ScheduleSlot[scheduleData.slot];
71
- }
72
-
73
- // cronExpression = `*/1 * * * *`;
74
- const job = cron.schedule(
75
- cronExpression,
76
- async () => {
77
- try {
78
- await taskService.StartTaskExecution(scheduleData._taskRunId);
79
- if (scheduleData.onExecutionScript) {
80
- console.log(`Running scheduled task with ID: ${taskId}`);
81
- // var executionScript = new Function('result', `${scheduleData.onExecutionScript}`);
82
- var sandboxContext = {
83
- companyService: null,// new CompanyService(this.result),
84
- fireStoreService: null, //new FirestoreService(this.result),
85
- whatsappProviderService: null,//new WhatsappProviderService(this.result),
86
- enums: { ResponseCode: ResponseCode, AuditMessageType: AuditMessageType }
87
- }
88
- var result = null;//await processUserScript(scheduleData.onExecutionScript.toString(), sandboxContext, this.result)
89
- // var result = await executionScript(this.result);
90
- if (result.Status == ResponseCode.Error) {
91
- throw (this.result.Errors)
92
- }
93
- console.log(result);
94
- }
95
- if (scheduleData.onSuccessScript) {
96
- console.log(`On Success script started for task with ID: ${taskId}`);
97
- var successScript = new Function(null, scheduleData.onSuccessScript.toString());
98
- result = await successScript(this.result);
99
- console.log(result);
100
- }
101
- await taskService.StartTaskOnSuccess(scheduleData._taskRunId);
102
- } catch (error) {
103
- if (scheduleData.onFailureScript) {
104
- console.log(`Failure script started for task with ID: ${taskId}`);
105
- var failureScript = new Function(null, scheduleData.onFailureScript.toString());
106
- result = await failureScript(this.result);
107
- console.log(result);
108
- }
109
- await taskService.StartTaskOnFailure(scheduleData._taskRunId);
110
- } finally {
111
- if (scheduleData.onFinalizeScript) {
112
- console.log(`Finalizing script started for task with ID: ${taskId}`);
113
- var finalizeScirpt = new Function(null, scheduleData.onFinalizeScript.toString());
114
- result = await finalizeScirpt(this.result);
115
- console.log(result);
116
- }
117
- await taskService.StartTaskOnFinalize(scheduleData._taskRunId);
118
- }
119
- },
120
- {
121
- scheduled: scheduleData?.startAt !== undefined,
122
- timezone: 'utc',
123
- }
124
- );
125
-
126
- if (scheduleData?.startAt && Config.props.load_scheduled_tasks) {
127
- job.start();
128
- }
129
-
130
- // if (scheduleData?.frequency) {
131
- // setInterval(() => job.fireOnTick(), scheduleData.frequency);
132
- // }
133
-
134
- this.scheduledJobs.set(taskId, job);
135
- this.result.addMessage(AuditMessageType.info, this.className, 'scheduleTask', `Finished`);
136
- this.result.Status = ResponseCode.Ok;
137
- this.result.Data = `Scheduled task ${taskId} successfully`;
138
- }
139
- } catch (ex) {
140
- this.result.addException('CronHelper', 'scheduleTask', ex);
141
- this.result.Data = null;
142
- this.result.Status = ResponseCode.Error;
143
- }
144
-
145
- return this.result;
146
- }
147
-
148
- public async updateScheduledTask(taskId: string): Promise<Result> {
149
- await this.removeScheduledTask(taskId);
150
- return this.scheduleTask(taskId);
151
- }
152
-
153
- public async removeScheduledTask(taskId: string): Promise<Result> {
154
- try {
155
- const job = this.scheduledJobs.get(taskId);
156
- if (job) {
157
- job.stop();
158
- this.scheduledJobs.delete(taskId);
159
- }
160
- this.result.Status = ResponseCode.Ok;
161
- this.result.Data = `Removed scheduled task ${taskId} successfully`;
162
- } catch (ex) {
163
- this.result.addException('CronHelper', 'removeScheduledTask', ex);
164
- }
165
-
166
- return this.result;
167
- }
168
- }
169
-
170
- export { CronHelper, ScheduleSlot, ScheduleOptions };
@@ -1,83 +0,0 @@
1
- import * as mongoose from 'mongoose';
2
- import { AuditEntity } from '../schemas/audit';
3
- import { Config } from '../config';
4
- import { UserEntity } from '../schemas/user';
5
- import { SessionEntity } from '../schemas/session';
6
- import { OTPEntity } from '../schemas/otp';
7
-
8
- const connectDb = () => {
9
- console.log('db connection string' + Config.props.database_connectionstring)
10
- return mongoose.connect(Config.props.database_connectionstring);
11
- };
12
-
13
- export const dbcontext = {
14
- //A
15
- AuditEntity,
16
- //B
17
- //C
18
- //D
19
- //E
20
- //F
21
- //G
22
- //
23
- //I
24
- //J
25
- //K
26
- //L
27
- listCollections: async () => {
28
- return await mongoose.connection.db.listCollections()
29
- },
30
- //M
31
- //N
32
- //O
33
- //P
34
- //Q
35
- //R
36
- //S
37
- SessionEntity,
38
- //T
39
- //U
40
- UserEntity,
41
- //V
42
- //W
43
- //X
44
- //Y
45
- //Z
46
- OTPEntity,
47
- };
48
-
49
- export const dbcontextMapping: { [key: string]: any } = {
50
- //A
51
- //B
52
- //C
53
- //D
54
- //E
55
- //F
56
- //G
57
- //H
58
- //I
59
- //J
60
- //K
61
- //L
62
- //M
63
- //N
64
- //O
65
- //P
66
- //Q
67
- //R
68
- //S
69
- sessions: SessionEntity,
70
- //T
71
- //U
72
- users: UserEntity,
73
- //V
74
- //W
75
- //X
76
- //Y
77
- //Z
78
- otps: OTPEntity,
79
- };
80
-
81
- export { connectDb };
82
-
83
- export default dbcontext;
@@ -1,76 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import * as zlib from "zlib";
3
- export class EncryptionHelper {
4
- lightEncryption = (valueToEncrypt) => {
5
- const encodedURI = encodeURIComponent(valueToEncrypt);
6
- const base64Encoded = btoa(encodedURI);
7
- return base64Encoded;
8
- };
9
-
10
- lightDecryption = (encodedValue) => {
11
- const decodedURI = atob(encodedValue);
12
- const decoded = decodeURIComponent(decodedURI);
13
- return decoded;
14
- };
15
-
16
- encryptUserLogin = (valueToEncrypt) => {
17
- try {
18
- // Compress the value using zlib
19
- const compressed = zlib.deflateSync(valueToEncrypt, { level: zlib.constants.Z_BEST_COMPRESSION }).toString('base64');
20
- // Encode the compressed value to URI and then base64 encode
21
- const encodedURI = encodeURIComponent(compressed);
22
- const base64Encoded = Buffer.from(encodedURI).toString('base64');
23
- return base64Encoded;
24
- }
25
- catch (ex) {
26
- console.log(ex);
27
- return null;
28
- }
29
- };
30
-
31
- decryptUserLogin = (encodedValue) => {
32
- try {
33
- // Decode the base64 and URI encoded value
34
- const decodedURI = Buffer.from(encodedValue, 'base64').toString('utf-8');
35
- const decoded = decodeURIComponent(decodedURI);
36
- // Decompress the value using zlib
37
- const decompressed: any = zlib.inflateSync(Buffer.from(decoded, 'base64')).toString();
38
- return decompressed;
39
- }
40
- catch (ex) {
41
- console.log(ex);
42
- return null;
43
- }
44
- };
45
-
46
-
47
-
48
- // encryptUserLogin = (objectToEncrypt) => {
49
- // try {
50
- // const encrypted = this.lightEncryption(objectToEncrypt);
51
- // return encrypted;
52
- // }
53
- // catch (ex) {
54
- // return null;
55
- // }
56
- // }
57
-
58
- // decryptUserLogin = (objectToDecrypt) => {
59
- // try {
60
- // const decrypted = this.lightDecryption(objectToDecrypt);
61
- // return JSON.parse(decrypted);
62
- // }
63
- // catch (ex) {
64
- // return null;
65
- // }
66
- // }
67
-
68
- serializeXML = (xml) => {
69
- try {
70
- const xmlSerializer = new XMLSerializer();
71
- return xmlSerializer.serializeToString(xml);
72
- } catch {
73
- return null;
74
- }
75
- };
76
- }
@@ -1,258 +0,0 @@
1
- export enum CodeType {
2
- email_activation,
3
- mobile_activation
4
- }
5
-
6
- export enum ResponseCode {
7
- Ok = 1000,
8
- Duplicate = 1001,
9
- NotExist = 1002,
10
- Exist = 1003,
11
- Error = 0,
12
- Authorized = 1010,
13
- Unauthorized = 1011,
14
- NotRelated = 1004,
15
- NeedVerification = 1005,
16
- Incompelete = 1006,
17
- MissingRequiredFields = 1007
18
- }
19
-
20
- export enum SendifierServiceCode {
21
- WHATSAPP_API = "WAPI",
22
- USERS = "USRS",
23
- WORKFLOW = "WFLW"
24
- }
25
-
26
- export enum WhatsappProviders {
27
- twilio = 'twilio',
28
- wati = 'wati'
29
- }
30
-
31
- export enum CompanyUserRole {
32
- Creator = 0,
33
- Admin = 1,
34
- Agent = 2
35
- }
36
-
37
- export enum SendifierPlanStatus {
38
- Pending = 0,
39
- Approved = 1,
40
- Paid = 3,
41
- Active = 4,
42
- Expired = 5,
43
- Deactivated = 6,
44
- FreeTier = 10
45
- }
46
-
47
- export enum Status {
48
- NotActive = 0,
49
- Active = 1,
50
- PendingPayment = 5
51
- }
52
-
53
- export enum AssignmentStatus {
54
- NotActive = 0,
55
- Active = 1,
56
- AssignedToServiceUser = 3,
57
- AssignedToUser = 4,
58
- PermenantAssignment = 5,
59
- Deactivated = 6,
60
- }
61
-
62
-
63
- export enum AccountStatus {
64
- NotActive = 0,
65
- Active = 1,
66
- PendingConfirmation = 2,
67
- PendingRegisterationComplete = 3,
68
- Deleted = 4,
69
- PendingPayment = 5
70
- }
71
-
72
- export enum WorkflowExecutionStatus {
73
- Pending = 0,
74
- Processing = 1,
75
- Success = 2,
76
- Failed = 3,
77
- Expired = 4
78
- }
79
-
80
- export enum ContactTypes {
81
- whatsapp = 0,
82
- }
83
-
84
- export enum TaskType {
85
- REGULAR = 1,
86
- SCHEDULED = 2,
87
- SYSTEM = 3
88
- }
89
-
90
- export enum TaskAssignmentLevel {
91
- USER = 1,
92
- DEPARTMENT = 2,
93
- COMPANY = 3
94
- }
95
-
96
- export enum TaskStatus {
97
- TODO = 0,
98
- INPROGRESS = 1,
99
- PENDING = 2,
100
- DONE = 3,
101
- TRASH = 4
102
- }
103
-
104
- export enum ScheduleSlot {
105
- EVERY_MINUTE = '* * * * *',
106
- EVERY_TEN_MINUTES = '*/10 * * * *',
107
- EVERY_HOUR = '0 * * * *',
108
- EVERY_DAY_AT_MIDNIGHT = '0 0 * * *',
109
- EVERY_DAY_AT = 'custom_daily',
110
- EVERY_WEEK = '0 0 * * 6', // Saturday at midnight
111
- EVERY_WEEK_AT = 'custom_weekly',
112
- EVERY_MONTH = '0 0 1 * *', // First day of every month at midnight
113
- EVERY_MONTH_AT = 'custom_monthly',
114
- CUSTOM = 'custom',
115
- }
116
-
117
- export enum AuditMessageType {
118
- info = 1,
119
- warn = 2,
120
- error = 3,
121
- exception = 4,
122
- unknown = 10,
123
- trace = 11,
124
- socket = 12
125
- }
126
-
127
- export enum SocketEventCode {
128
- Connect = 'connection',
129
- ReloadClient = 'reload_web_channel',
130
- Error = 'error',
131
- UserLoggedIn = 'user_logged_in',
132
- UserLoggedOut = 'user_logged_out',
133
- MultipleTabLoggedIn = 'multiple_tab_login',
134
- Close = 'close_connection',
135
- RespondWhatsappMessage = 'respond_whatsapp_message',
136
- ReceiveWhatsappMessage = 'whatsapp_message_received',
137
- VerifyToken = 'verify_token',
138
- RefreshToken = 'refresh_token'
139
- }
140
-
141
- export enum SocketIdentifierType { //used in subscribe & trigger socket events to make the socket provider able to detect which socket will subscribe or trigger
142
- User = 'user',
143
- Socket = 'socket',
144
- Company = 'company',
145
- Room = 'room'
146
- }
147
-
148
- export enum MessageStatus {
149
- new = 0,
150
- delivered = 1,
151
- seen = 2,
152
- failed = 3
153
- }
154
-
155
- export enum ObjectStatus {
156
- Added = 'Added',
157
- Modified = 'Modified',
158
- Deleted = 'Deleted'
159
- }
160
-
161
- export enum TaskStatus {
162
- InActive = -1,
163
- ToDo = 0,
164
- InProgress = 1,
165
- Pending = 2,
166
- Done = 3,
167
- Trash = 4,
168
- Processing = 5,
169
- Succeeded = 6,
170
- Failed = 7,
171
- Expired = 8,
172
- Finished = 9
173
- }
174
-
175
- export enum MessagingOptionsSources {
176
- Actions = '0',
177
- Context = '1',
178
- Both = '2',
179
- None = '3'
180
- }
181
-
182
- export enum UserType {
183
- SYS = 'SYS',
184
- NOR = "NOR",
185
- }
186
-
187
- export enum AuthProvider {
188
- INTERNAL = 'internal',
189
- FIREBASE = 'firebase',
190
- GOOGLE = 'google',
191
- FACEBOOK = 'facebook',
192
- GITHUB = 'github',
193
- LINKEDIN = 'linkedin',
194
- TWITTER = 'twitter',
195
- SMS_OTP = 'sms_otp',
196
- EMAIL_OTP = 'email_otp'
197
- }
198
-
199
- export enum AuthMethod {
200
- PASSWORD = 'password',
201
- OAUTH = 'oauth',
202
- OTP = 'otp',
203
- MAGIC_LINK = 'magic_link',
204
- BIOMETRIC = 'biometric'
205
- }
206
-
207
- export enum OAuthProvider {
208
- GOOGLE = 'google',
209
- FACEBOOK = 'facebook',
210
- GITHUB = 'github',
211
- LINKEDIN = 'linkedin',
212
- TWITTER = 'twitter'
213
- }
214
-
215
- export enum CommentStatus {
216
- Delete = 0,
217
- Active = 1,
218
- }
219
-
220
- export enum ActivationStatus {
221
- InActive = -1,
222
- IsActive = -2,
223
- }
224
-
225
- export enum AssignmentStatus {
226
- Assigned = 0,
227
- NotAssigned = 1,
228
- }
229
-
230
- export enum TaskAssignmentStatus {
231
- WORKFLOWRUN = 1000,
232
- DEPARTMENT = 1001,
233
- }
234
-
235
- export enum WeekDays {
236
- Friday = 1,
237
- Saturday = 2,
238
- Sunday,
239
- Monday,
240
- Tuseday,
241
- Wednsday,
242
- Thursday
243
- }
244
-
245
- export enum CalendarDefaultView{
246
- Month = 1,
247
- Week = 2,
248
- Day = 3
249
- }
250
-
251
- export enum Period {
252
- Minute,
253
- Hour,
254
- Day,
255
- Week,
256
- Month,
257
- Year
258
- }
@@ -1,49 +0,0 @@
1
- import { ServerResponse } from "http";
2
- import { Result } from "./result";
3
- import { AuditService } from "../services/audit-service";
4
- import { ResponseCode } from "./enums";
5
- import { Config } from "../config";
6
-
7
- class ResponseHandler {
8
- HandleResponse(req: any, res: any, result: Result) {
9
- try {
10
- if (result.Errors.length == 0 && result.Status == ResponseCode.Ok) {
11
- result.Messages.push('Request completed successfully.')
12
- }
13
- delete result.addException;
14
- delete result.addMessage;
15
- delete result.additionalInfo;
16
- delete result.user;
17
- if (!Config.props.isDev) {
18
- delete result.Errors;
19
- delete result.Messages;
20
- }
21
-
22
- result.StatusMessage = ResponseCode[result.Status]
23
- res.json(result);
24
- }
25
- catch (ex) {
26
- res.status(500)
27
- }
28
- }
29
- }
30
-
31
- const handleResponse = (req: any, res: any, result: Result) => {
32
- try {
33
- var responseHandler = new ResponseHandler();
34
- var auditService = new AuditService();
35
- delete result.user;
36
- auditService.AddAuditBulk(result.Messages, result.Errors, result.additionalInfo ? JSON.stringify(result.additionalInfo) : null);
37
- responseHandler.HandleResponse(req, res, result);
38
- }
39
- catch (ex) {
40
- console.log(ex);
41
- }
42
- }
43
- export const handleSocketResponse = (result: Result) => {
44
- var auditService = new AuditService();
45
- auditService.AddAuditBulk(result.Messages, result.Errors, result.additionalInfo);
46
- return result;
47
- }
48
-
49
- export default handleResponse;
@@ -1,75 +0,0 @@
1
- import axios, { AxiosResponse, AxiosError, AxiosRequestConfig } from 'axios';
2
- import { Config } from '../config';
3
-
4
- class HttpHelper {
5
- private static instance: HttpHelper;
6
-
7
- constructor() { }
8
-
9
- public static getInstance(): HttpHelper {
10
- if (!HttpHelper.instance) {
11
- HttpHelper.instance = new HttpHelper();
12
- }
13
- return HttpHelper.instance;
14
- }
15
-
16
- public async get(url: string, config?: AxiosRequestConfig): Promise<any> {
17
- try {
18
- config.timeout = Config.props.external_http_request_timeout;
19
- const response = await axios.get(url, config);
20
- return response;
21
- } catch (error) {
22
- this.handleRequestError(error);
23
- return null;
24
- }
25
- }
26
-
27
- public async post(url: string, data?: any, config?: AxiosRequestConfig): Promise<any> {
28
- try {
29
- config.timeout = Config.props.external_http_request_timeout;
30
- const response: AxiosResponse = await axios.post(url, data, config);
31
- return response;
32
- } catch (error) {
33
- this.handleRequestError(error);
34
- return null;
35
- }
36
- }
37
-
38
- public async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<any> {
39
- try {
40
- config.timeout = Config.props.external_http_request_timeout;
41
- const response: AxiosResponse<T> = await axios.put(url, data, config);
42
- return response.data;
43
- } catch (error) {
44
- this.handleRequestError(error);
45
- throw error;
46
- }
47
- }
48
-
49
- public async delete<T>(url: string, config?: AxiosRequestConfig): Promise<any> {
50
- try {
51
- config.timeout = Config.props.external_http_request_timeout;
52
- const response: AxiosResponse<T> = await axios.delete(url, config);
53
- return response.data;
54
- } catch (error) {
55
- this.handleRequestError(error);
56
- throw error;
57
- }
58
- }
59
-
60
- private handleRequestError(error: AxiosError): void {
61
- if (error.response) {
62
- // The request was made, but the server responded with a status code that falls out of the range of 2xx
63
- console.error('Response Error:', error.response.data);
64
- console.error('Status Code:', error.response.status);
65
- } else if (error.request) {
66
- // The request was made but no response was received
67
- console.error('Request Error:', error.request);
68
- } else {
69
- // Something happened in setting up the request that triggered an Error
70
- console.error('General Error:', error.message);
71
- }
72
- }
73
- }
74
-
75
- export default HttpHelper;