@adaas/a-utils 0.0.2
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/.nvmrc +1 -0
- package/LICENSE +22 -0
- package/README.md +49 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/src/constants/errors.constants.d.ts +65 -0
- package/dist/src/constants/errors.constants.js +74 -0
- package/dist/src/constants/errors.constants.js.map +1 -0
- package/dist/src/global/ASEID.class.d.ts +77 -0
- package/dist/src/global/ASEID.class.js +129 -0
- package/dist/src/global/ASEID.class.js.map +1 -0
- package/dist/src/global/A_Deferred.class.d.ts +8 -0
- package/dist/src/global/A_Deferred.class.js +19 -0
- package/dist/src/global/A_Deferred.class.js.map +1 -0
- package/dist/src/global/A_Entity.class.d.ts +49 -0
- package/dist/src/global/A_Entity.class.js +94 -0
- package/dist/src/global/A_Entity.class.js.map +1 -0
- package/dist/src/global/A_Error.class.d.ts +13 -0
- package/dist/src/global/A_Error.class.js +54 -0
- package/dist/src/global/A_Error.class.js.map +1 -0
- package/dist/src/global/A_Polyfills.d.ts +21 -0
- package/dist/src/global/A_Polyfills.js +123 -0
- package/dist/src/global/A_Polyfills.js.map +1 -0
- package/dist/src/global/A_ScheduleObject.class.d.ts +9 -0
- package/dist/src/global/A_ScheduleObject.class.js +38 -0
- package/dist/src/global/A_ScheduleObject.class.js.map +1 -0
- package/dist/src/global/A_ServerError.class.d.ts +13 -0
- package/dist/src/global/A_ServerError.class.js +57 -0
- package/dist/src/global/A_ServerError.class.js.map +1 -0
- package/dist/src/helpers/A_Common.helper.d.ts +32 -0
- package/dist/src/helpers/A_Common.helper.js +184 -0
- package/dist/src/helpers/A_Common.helper.js.map +1 -0
- package/dist/src/helpers/A_Schedule.helper.d.ts +6 -0
- package/dist/src/helpers/A_Schedule.helper.js +21 -0
- package/dist/src/helpers/A_Schedule.helper.js.map +1 -0
- package/dist/src/types/ASEID.types.d.ts +65 -0
- package/dist/src/types/ASEID.types.js +5 -0
- package/dist/src/types/ASEID.types.js.map +1 -0
- package/dist/src/types/A_Common.types.d.ts +59 -0
- package/dist/src/types/A_Common.types.js +3 -0
- package/dist/src/types/A_Common.types.js.map +1 -0
- package/dist/src/types/A_Entity.types.d.ts +13 -0
- package/dist/src/types/A_Entity.types.js +4 -0
- package/dist/src/types/A_Entity.types.js.map +1 -0
- package/dist/src/types/A_Error.type.d.ts +7 -0
- package/dist/src/types/A_Error.type.js +3 -0
- package/dist/src/types/A_Error.type.js.map +1 -0
- package/dist/src/types/A_Error.types.d.ts +7 -0
- package/dist/src/types/A_Error.types.js +3 -0
- package/dist/src/types/A_Error.types.js.map +1 -0
- package/dist/src/types/A_ScheduleObject.types.d.ts +9 -0
- package/dist/src/types/A_ScheduleObject.types.js +3 -0
- package/dist/src/types/A_ScheduleObject.types.js.map +1 -0
- package/dist/src/types/A_ServerError.types.d.ts +4 -0
- package/dist/src/types/A_ServerError.types.js +3 -0
- package/dist/src/types/A_ServerError.types.js.map +1 -0
- package/docs/a-logo-docs.png +0 -0
- package/index.ts +64 -0
- package/jest.config.ts +19 -0
- package/package.json +73 -0
- package/src/constants/errors.constants.ts +78 -0
- package/src/global/ASEID.class.ts +208 -0
- package/src/global/A_Deferred.class.ts +20 -0
- package/src/global/A_Entity.class.ts +134 -0
- package/src/global/A_Error.class.ts +75 -0
- package/src/global/A_Polyfills.ts +112 -0
- package/src/global/A_ScheduleObject.class.ts +53 -0
- package/src/global/A_ServerError.class.ts +70 -0
- package/src/helpers/A_Common.helper.ts +229 -0
- package/src/helpers/A_Schedule.helper.ts +25 -0
- package/src/types/ASEID.types.ts +86 -0
- package/src/types/A_Common.types.ts +111 -0
- package/src/types/A_Entity.types.ts +17 -0
- package/src/types/A_Error.types.ts +10 -0
- package/src/types/A_ScheduleObject.types.ts +9 -0
- package/src/types/A_ServerError.types.ts +7 -0
- package/tests/default.test.ts +160 -0
- package/tests/polyfill.test.ts +37 -0
- package/tsconfig.json +58 -0
- package/tslint.json +98 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
import { A_TYPES__Error } from '../types/A_Error.types';
|
|
3
|
+
export declare class A_Error extends Error {
|
|
4
|
+
code: string;
|
|
5
|
+
description: string;
|
|
6
|
+
originalError?: Error | any;
|
|
7
|
+
link?: string;
|
|
8
|
+
constructor(params: A_TYPES__Error | Error | AxiosError | any);
|
|
9
|
+
get id(): string | undefined;
|
|
10
|
+
protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error): void;
|
|
11
|
+
get compilingData(): A_TYPES__Error;
|
|
12
|
+
toJSON(): A_TYPES__Error;
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_Error = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const errors_constants_1 = require("../constants/errors.constants");
|
|
6
|
+
class A_Error extends Error {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super((params === null || params === void 0 ? void 0 : params.message) || 'Oops... Something went wrong');
|
|
9
|
+
this.identifyErrorType(params);
|
|
10
|
+
}
|
|
11
|
+
get id() {
|
|
12
|
+
return this.code.split('@')[1];
|
|
13
|
+
}
|
|
14
|
+
identifyErrorType(error) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
if (error.code &&
|
|
17
|
+
error.description &&
|
|
18
|
+
error.serverCode) {
|
|
19
|
+
const target = error;
|
|
20
|
+
this.message = target.message;
|
|
21
|
+
this.code = target.code;
|
|
22
|
+
this.description = target.description;
|
|
23
|
+
this.originalError = target.originalError;
|
|
24
|
+
this.link = target.link;
|
|
25
|
+
}
|
|
26
|
+
else if (error instanceof Error) {
|
|
27
|
+
this.message = error.message;
|
|
28
|
+
this.code = errors_constants_1.A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
29
|
+
this.description = 'If you see this error please let us know.';
|
|
30
|
+
this.originalError = error;
|
|
31
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
32
|
+
}
|
|
33
|
+
else if (error instanceof axios_1.AxiosError) {
|
|
34
|
+
this.message = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message) || error.message;
|
|
35
|
+
this.code = ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data.code) || errors_constants_1.A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
36
|
+
this.description = ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data.description) || 'If you see this error please let us know.';
|
|
37
|
+
this.originalError = error.response;
|
|
38
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get compilingData() {
|
|
42
|
+
return {
|
|
43
|
+
message: this.message,
|
|
44
|
+
code: this.code,
|
|
45
|
+
description: this.description,
|
|
46
|
+
originalError: this.originalError
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return this.compilingData;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.A_Error = A_Error;
|
|
54
|
+
//# sourceMappingURL=A_Error.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Error.class.js","sourceRoot":"","sources":["../../../src/global/A_Error.class.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AAEnC,oEAAyE;AAGzE,MAAa,OAAQ,SAAQ,KAAK;IAQ9B,YACI,MAAiD;QAEjD,KAAK,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,KAAI,8BAA8B,CAAC,CAAC;QACzD,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAEnC,CAAC;IAGD,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAClC,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C,IAAI,CAAC,IAAI,GAAG,kCAAkC,GAAG,IAAI,CAAC,EAAE,CAAC;QAC7D,CAAC;IACL,CAAC;IAGD,IAAI,aAAa;QACb,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;SACpC,CAAA;IACL,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;CACJ;AAlED,0BAkEC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Ifspolyfill {
|
|
2
|
+
readFileSync: (path: string, encoding: string) => string;
|
|
3
|
+
existsSync: (path: string) => boolean;
|
|
4
|
+
createReadStream: (path: string, options?: BufferEncoding) => any;
|
|
5
|
+
}
|
|
6
|
+
interface ICryptoInterface {
|
|
7
|
+
createTextHash(text: string, algorithm: string): Promise<string>;
|
|
8
|
+
createFileHash(filePath: string, algorithm: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
declare class A_PolyfillsClass {
|
|
11
|
+
private _fs;
|
|
12
|
+
private _crypto;
|
|
13
|
+
private fsName;
|
|
14
|
+
private cryptoName;
|
|
15
|
+
fs(): Promise<Ifspolyfill>;
|
|
16
|
+
crypto(): Promise<ICryptoInterface>;
|
|
17
|
+
get env(): 'server' | 'browser';
|
|
18
|
+
private init;
|
|
19
|
+
}
|
|
20
|
+
export declare const A_Polyfills: A_PolyfillsClass;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.A_Polyfills = void 0;
|
|
36
|
+
class A_PolyfillsClass {
|
|
37
|
+
constructor() {
|
|
38
|
+
// eslint-disable-next-line no-use-before-define
|
|
39
|
+
this.fsName = 'fs';
|
|
40
|
+
this.cryptoName = 'crypto';
|
|
41
|
+
}
|
|
42
|
+
fs() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (!this._fs) {
|
|
45
|
+
yield this.init();
|
|
46
|
+
}
|
|
47
|
+
return this._fs;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
crypto() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!this._crypto) {
|
|
53
|
+
yield this.init();
|
|
54
|
+
}
|
|
55
|
+
return this._crypto;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
get env() {
|
|
59
|
+
let testEnvironment = 'browser';
|
|
60
|
+
try {
|
|
61
|
+
testEnvironment = window.location ? 'browser' : 'server';
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
testEnvironment = 'server';
|
|
65
|
+
}
|
|
66
|
+
return testEnvironment;
|
|
67
|
+
}
|
|
68
|
+
init() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
if (this.env === 'server') {
|
|
72
|
+
// eslint-disable-next-line no-use-before-define
|
|
73
|
+
this._fs = (yield Promise.resolve(`${'' + this.fsName}`).then(s => __importStar(require(s))));
|
|
74
|
+
// eslint-disable-next-line no-use-before-define
|
|
75
|
+
this._crypto = {
|
|
76
|
+
createTextHash: () => Promise.resolve(''),
|
|
77
|
+
createFileHash: (filePath, algorithm = 'sha384') => new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
const crypto = yield Promise.resolve(`${'' + this.cryptoName}`).then(s => __importStar(require(s)));
|
|
80
|
+
const hash = crypto.createHash(algorithm);
|
|
81
|
+
const fileStream = this._fs.createReadStream(filePath);
|
|
82
|
+
fileStream.on('data', (data) => hash.update(data));
|
|
83
|
+
fileStream.on('end', () => resolve(`${algorithm}-${hash.digest('base64')}`));
|
|
84
|
+
fileStream.on('error', (err) => reject(err));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return reject(error);
|
|
88
|
+
}
|
|
89
|
+
}))
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw new Error('Not Server Environment');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
this._fs = {
|
|
98
|
+
readFileSync: (path, encoding) => '',
|
|
99
|
+
existsSync: (path) => false,
|
|
100
|
+
createReadStream: (path) => ''
|
|
101
|
+
};
|
|
102
|
+
this._crypto = {
|
|
103
|
+
createFileHash: () => Promise.resolve(''),
|
|
104
|
+
createTextHash: (text, algorithm = 'SHA-384') => new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
try {
|
|
106
|
+
const encoder = new TextEncoder();
|
|
107
|
+
const data = encoder.encode(text);
|
|
108
|
+
const hashBuffer = yield crypto.subtle.digest(algorithm, data);
|
|
109
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
110
|
+
const hashBase64 = btoa(String.fromCharCode(...hashArray.map(byte => String.fromCharCode(byte))));
|
|
111
|
+
return resolve(`${algorithm}-${hashBase64}`);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return reject(error);
|
|
115
|
+
}
|
|
116
|
+
}))
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.A_Polyfills = new A_PolyfillsClass();
|
|
123
|
+
//# sourceMappingURL=A_Polyfills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Polyfills.js","sourceRoot":"","sources":["../../../src/global/A_Polyfills.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgB;IAAtB;QAKI,gDAAgD;QACxC,WAAM,GAAG,IAAI,CAAA;QACb,eAAU,GAAG,QAAQ,CAAA;IAyFjC,CAAC;IAtFS,EAAE;;YACJ,IAAI,CA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M,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;4BAClC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;4BAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;4BACzD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAQ,CAAC,CAAC,CAAC,CAAC;4BACzG,OAAO,OAAO,CAAC,GAAG,SAAS,IAAI,UAAU,EAAE,CAAC,CAAC;wBACjD,CAAC;wBAAC,OAAO,KAAK,EAAE,CAAC;4BACb,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;wBACzB,CAAC;oBACL,CAAC,CAAA,CAAC;iBACL,CAAC;YACN,CAAC;QACL,CAAC;KAAA;CAGJ;AAGY,QAAA,WAAW,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { A_TYPES__ScheduleObjectConfig } from "../types/A_ScheduleObject.types";
|
|
2
|
+
export declare class A_ScheduleObject<T> {
|
|
3
|
+
private timeout;
|
|
4
|
+
private deferred;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(ms: number, action: () => Promise<T>, config?: A_TYPES__ScheduleObjectConfig);
|
|
7
|
+
get promise(): Promise<T>;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_ScheduleObject = void 0;
|
|
4
|
+
const A_Deferred_class_1 = require("./A_Deferred.class");
|
|
5
|
+
const A_Error_class_1 = require("./A_Error.class");
|
|
6
|
+
class A_ScheduleObject {
|
|
7
|
+
constructor(ms, action, config) {
|
|
8
|
+
this.config = {
|
|
9
|
+
/**
|
|
10
|
+
* If the timeout is cleared, should the promise resolve or reject?
|
|
11
|
+
* BY Default it rejects
|
|
12
|
+
*
|
|
13
|
+
* !!!NOTE: If the property is set to true, the promise will resolve with undefined
|
|
14
|
+
*/
|
|
15
|
+
resolveOnClear: false
|
|
16
|
+
};
|
|
17
|
+
if (config)
|
|
18
|
+
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
19
|
+
this.deferred = new A_Deferred_class_1.A_Deferred();
|
|
20
|
+
this.timeout = setTimeout(() => action()
|
|
21
|
+
.then((...args) => this.deferred.resolve(...args))
|
|
22
|
+
.catch((...args) => this.deferred.reject(...args)), ms);
|
|
23
|
+
}
|
|
24
|
+
get promise() {
|
|
25
|
+
return this.deferred.promise;
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
if (this.timeout) {
|
|
29
|
+
clearTimeout(this.timeout);
|
|
30
|
+
if (this.config.resolveOnClear)
|
|
31
|
+
this.deferred.resolve(undefined);
|
|
32
|
+
else
|
|
33
|
+
this.deferred.reject(new A_Error_class_1.A_Error("Timeout Cleared"));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.A_ScheduleObject = A_ScheduleObject;
|
|
38
|
+
//# sourceMappingURL=A_ScheduleObject.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_ScheduleObject.class.js","sourceRoot":"","sources":["../../../src/global/A_ScheduleObject.class.ts"],"names":[],"mappings":";;;AACA,yDAAgD;AAChD,mDAA0C;AAE1C,MAAa,gBAAgB;IAezB,YACI,EAAU,EACV,MAAwB,EACxB,MAAsC;QAblC,WAAM,GAAkC;YAC5C;;;;;eAKG;YACH,cAAc,EAAE,KAAK;SACxB,CAAC;QAOE,IAAI,MAAM;YACN,IAAI,CAAC,MAAM,mCAAQ,IAAI,CAAC,MAAM,GAAK,MAAM,CAAE,CAAC;QAEhD,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAU,EAAK,CAAC;QAEpC,IAAI,CAAC,OAAO,GAAG,UAAU,CACrB,GAAG,EAAE,CAAC,MAAM,EAAE;aACT,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;aACjD,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,EACtD,EAAE,CACL,CAAC;IACN,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE3B,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc;gBAC1B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAc,CAAC,CAAC;;gBAEtC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,uBAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;CACJ;AA/CD,4CA+CC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { A_TYPES__ServerError } from '../types/A_ServerError.types';
|
|
2
|
+
import { AxiosError } from 'axios';
|
|
3
|
+
import { A_Error } from './A_Error.class';
|
|
4
|
+
export declare class A_ServerError extends A_Error {
|
|
5
|
+
code: string;
|
|
6
|
+
description: string;
|
|
7
|
+
serverCode: number;
|
|
8
|
+
originalError: Error | any;
|
|
9
|
+
constructor(params: A_TYPES__ServerError | Error | AxiosError | any);
|
|
10
|
+
protected identifyErrorType(error: Error | AxiosError | A_TYPES__ServerError): void;
|
|
11
|
+
get compilingData(): A_TYPES__ServerError;
|
|
12
|
+
toJSON(): A_TYPES__ServerError;
|
|
13
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_ServerError = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const A_Error_class_1 = require("./A_Error.class");
|
|
6
|
+
const errors_constants_1 = require("../constants/errors.constants");
|
|
7
|
+
class A_ServerError extends A_Error_class_1.A_Error {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
10
|
+
this.serverCode = 500;
|
|
11
|
+
this.identifyErrorType(params);
|
|
12
|
+
}
|
|
13
|
+
identifyErrorType(error) {
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
|
+
if (error.code &&
|
|
16
|
+
error.description &&
|
|
17
|
+
error.serverCode) {
|
|
18
|
+
const target = error;
|
|
19
|
+
this.message = target.message;
|
|
20
|
+
this.code = target.code;
|
|
21
|
+
this.description = target.description;
|
|
22
|
+
this.serverCode = target.serverCode;
|
|
23
|
+
this.originalError = target.originalError;
|
|
24
|
+
this.link = target.link;
|
|
25
|
+
}
|
|
26
|
+
else if (error instanceof Error) {
|
|
27
|
+
this.message = error.message;
|
|
28
|
+
this.code = errors_constants_1.A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
29
|
+
this.description = 'If you see this error please let us know.';
|
|
30
|
+
this.serverCode = 500;
|
|
31
|
+
this.originalError = error;
|
|
32
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
33
|
+
}
|
|
34
|
+
else if (error instanceof axios_1.AxiosError) {
|
|
35
|
+
this.message = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message) || error.message;
|
|
36
|
+
this.code = ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data.code) || errors_constants_1.A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
37
|
+
this.description = ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data.description) || 'If you see this error please let us know.';
|
|
38
|
+
this.serverCode = ((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) || 500;
|
|
39
|
+
this.originalError = error.response;
|
|
40
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
get compilingData() {
|
|
44
|
+
return {
|
|
45
|
+
message: this.message,
|
|
46
|
+
code: this.code,
|
|
47
|
+
description: this.description,
|
|
48
|
+
serverCode: this.serverCode,
|
|
49
|
+
originalError: this.originalError
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
toJSON() {
|
|
53
|
+
return this.compilingData;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.A_ServerError = A_ServerError;
|
|
57
|
+
//# sourceMappingURL=A_ServerError.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_ServerError.class.js","sourceRoot":"","sources":["../../../src/global/A_ServerError.class.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AACnC,mDAA0C;AAC1C,oEAAyE;AAGzE,MAAa,aAAc,SAAQ,uBAAO;IAQtC,YAAY,MAAuD;QAC/D,KAAK,CAAC,MAAM,CAAC,CAAC;QALlB,eAAU,GAAW,GAAG,CAAC;QAMrB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAGS,iBAAiB,CAAC,KAAgD;;QAExE,IAAK,KAA8B,CAAC,IAAI;YACnC,KAA8B,CAAC,WAAW;YAC1C,KAA8B,CAAC,UAAU,EAAE,CAAC;YAE7C,MAAM,MAAM,GAAG,KAA6B,CAAC;YAE7C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;YACtC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,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,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;SACpC,CAAA;IACL,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;CACJ;AA7DD,sCA6DC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { A_TYPES__DeepPartial } from "../types/A_Common.types";
|
|
2
|
+
export declare class A_CommonHelper {
|
|
3
|
+
static resolve(): Promise<undefined>;
|
|
4
|
+
static omitArrayProperties<T, S extends string>(array: Array<T>, fields: string[]): Omit<T, S>[];
|
|
5
|
+
static sanitizeHTML(html: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Omit properties from an object or array with nested objects
|
|
8
|
+
*
|
|
9
|
+
* @param input
|
|
10
|
+
* @param paths
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
static omitProperties<T, S extends string>(input: T, paths: string[]): Omit<T, S>;
|
|
14
|
+
/**
|
|
15
|
+
* Format a number with leading zeros to a fixed length
|
|
16
|
+
*
|
|
17
|
+
* @param number
|
|
18
|
+
* @param maxZeros
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
static formatWithLeadingZeros(number: any, maxZeros?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Remove leading zeros from a formatted number
|
|
24
|
+
*/
|
|
25
|
+
static removeLeadingZeros(formattedNumber: any): string;
|
|
26
|
+
static toUpperSnakeCase(str: string): string;
|
|
27
|
+
static toCamelCase(str: string): string;
|
|
28
|
+
static isObject(item: any): boolean;
|
|
29
|
+
static deepMerge<T = any>(target: any, source: any, visited?: Map<any, any>): T;
|
|
30
|
+
static deepClone<T>(target: T): T;
|
|
31
|
+
static deepCloneAndMerge<T>(target: A_TYPES__DeepPartial<T>, source: T): T;
|
|
32
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_CommonHelper = void 0;
|
|
4
|
+
class A_CommonHelper {
|
|
5
|
+
static resolve() {
|
|
6
|
+
return new Promise((resolve) => resolve(undefined));
|
|
7
|
+
}
|
|
8
|
+
static omitArrayProperties(array, fields) {
|
|
9
|
+
return array;
|
|
10
|
+
}
|
|
11
|
+
static sanitizeHTML(html) {
|
|
12
|
+
// Define the regular expression pattern to match all tags except <span>
|
|
13
|
+
const regex = /<(?!\/?span(?=>|\s.*>))\/?.*?>/g;
|
|
14
|
+
// Replace all matched tags with an empty string
|
|
15
|
+
return html.replace(regex, '');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Omit properties from an object or array with nested objects
|
|
19
|
+
*
|
|
20
|
+
* @param input
|
|
21
|
+
* @param paths
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
static omitProperties(input, paths) {
|
|
25
|
+
// Deep clone the input object or array
|
|
26
|
+
const result = JSON.parse(JSON.stringify(input));
|
|
27
|
+
// Helper function to recursively remove properties
|
|
28
|
+
function removeProperties(target, currPath) {
|
|
29
|
+
const currKey = currPath[0];
|
|
30
|
+
if (currPath.length === 1) {
|
|
31
|
+
// If current path has only one key, delete the property
|
|
32
|
+
delete target[currKey];
|
|
33
|
+
}
|
|
34
|
+
else if (target[currKey] !== undefined && typeof target[currKey] === 'object') {
|
|
35
|
+
// If current key exists and is an object, recursively call removeProperties
|
|
36
|
+
removeProperties(target[currKey], currPath.slice(1));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Iterate through each path and remove corresponding properties from the result
|
|
40
|
+
paths.forEach(path => {
|
|
41
|
+
const pathKeys = path.split('.');
|
|
42
|
+
removeProperties(result, pathKeys);
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Format a number with leading zeros to a fixed length
|
|
48
|
+
*
|
|
49
|
+
* @param number
|
|
50
|
+
* @param maxZeros
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
static formatWithLeadingZeros(number, maxZeros = 10) {
|
|
54
|
+
const formattedNumber = String(number).padStart(maxZeros + 1, '0');
|
|
55
|
+
return formattedNumber.slice(-maxZeros);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Remove leading zeros from a formatted number
|
|
59
|
+
*/
|
|
60
|
+
static removeLeadingZeros(formattedNumber) {
|
|
61
|
+
return String(Number(formattedNumber)); // Convert to number and back to string to remove leading zeros
|
|
62
|
+
}
|
|
63
|
+
static toUpperSnakeCase(str) {
|
|
64
|
+
return str
|
|
65
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2') // Handle lowercase followed by uppercase
|
|
66
|
+
.replace(/[-\s]([A-Z])/g, '_$1') // Handle non-alphabetical followed by uppercase
|
|
67
|
+
.replace('-', '_')
|
|
68
|
+
.toUpperCase();
|
|
69
|
+
}
|
|
70
|
+
static toCamelCase(str) {
|
|
71
|
+
return str.toLowerCase().replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
72
|
+
}
|
|
73
|
+
static isObject(item) {
|
|
74
|
+
return item !== null && typeof item === 'object' && !Array.isArray(item);
|
|
75
|
+
}
|
|
76
|
+
static deepMerge(target, source, visited = new Map()) {
|
|
77
|
+
if (this.isObject(target) && this.isObject(source)) {
|
|
78
|
+
for (const key in source) {
|
|
79
|
+
if (this.isObject(source[key])) {
|
|
80
|
+
if (!target[key]) {
|
|
81
|
+
target[key] = {};
|
|
82
|
+
}
|
|
83
|
+
// Check if the source object has already been visited
|
|
84
|
+
if (!visited.has(source[key])) {
|
|
85
|
+
visited.set(source[key], {});
|
|
86
|
+
this.deepMerge(target[key], source[key], visited);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
target[key] = visited.get(source[key]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
target[key] = source[key];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return target;
|
|
98
|
+
}
|
|
99
|
+
static deepClone(target) {
|
|
100
|
+
// Check if the value is null or undefined
|
|
101
|
+
if (target === null || target === undefined) {
|
|
102
|
+
return target;
|
|
103
|
+
}
|
|
104
|
+
// Handle primitive types (string, number, boolean, etc.)
|
|
105
|
+
if (typeof target !== 'object') {
|
|
106
|
+
return target;
|
|
107
|
+
}
|
|
108
|
+
// Handle Date
|
|
109
|
+
if (target instanceof Date) {
|
|
110
|
+
return new Date(target.getTime());
|
|
111
|
+
}
|
|
112
|
+
// Handle Array
|
|
113
|
+
if (Array.isArray(target)) {
|
|
114
|
+
return target.map(item => this.deepClone(item));
|
|
115
|
+
}
|
|
116
|
+
// Handle Function
|
|
117
|
+
if (typeof target === 'function') {
|
|
118
|
+
return target;
|
|
119
|
+
}
|
|
120
|
+
// Handle Object
|
|
121
|
+
if (target instanceof Object) {
|
|
122
|
+
const clone = {};
|
|
123
|
+
for (const key in target) {
|
|
124
|
+
if (target.hasOwnProperty(key)) {
|
|
125
|
+
clone[key] = this.deepClone(target[key]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return clone;
|
|
129
|
+
}
|
|
130
|
+
// For any other cases
|
|
131
|
+
throw new Error('Unable to clone the object. Unsupported type.');
|
|
132
|
+
}
|
|
133
|
+
static deepCloneAndMerge(target, source) {
|
|
134
|
+
if ((source === null || source === undefined) &&
|
|
135
|
+
(target === null || target === undefined))
|
|
136
|
+
return target;
|
|
137
|
+
// Check if the value is null or undefined
|
|
138
|
+
if ((target === null || target === undefined) &&
|
|
139
|
+
source) {
|
|
140
|
+
return this.deepClone(source);
|
|
141
|
+
}
|
|
142
|
+
// Handle primitive types (string, number, boolean, etc.)
|
|
143
|
+
if (typeof target !== 'object') {
|
|
144
|
+
return target;
|
|
145
|
+
}
|
|
146
|
+
// Handle Date
|
|
147
|
+
if (target instanceof Date) {
|
|
148
|
+
return new Date(target.getTime());
|
|
149
|
+
}
|
|
150
|
+
// Handle Array
|
|
151
|
+
if (Array.isArray(target)) {
|
|
152
|
+
return target.map(item => this.deepCloneAndMerge(item, source));
|
|
153
|
+
}
|
|
154
|
+
// Handle Function
|
|
155
|
+
if (typeof target === 'function') {
|
|
156
|
+
return target;
|
|
157
|
+
}
|
|
158
|
+
// Handle Object
|
|
159
|
+
if (target instanceof Object) {
|
|
160
|
+
const clone = {};
|
|
161
|
+
for (const key in target) {
|
|
162
|
+
if (source[key] !== null
|
|
163
|
+
&&
|
|
164
|
+
source[key] !== undefined)
|
|
165
|
+
clone[key] = this.deepCloneAndMerge(target[key], source[key]);
|
|
166
|
+
else
|
|
167
|
+
clone[key] = this.deepClone(target[key]);
|
|
168
|
+
}
|
|
169
|
+
for (const key in source) {
|
|
170
|
+
if (target[key] !== undefined
|
|
171
|
+
&&
|
|
172
|
+
target[key] !== null)
|
|
173
|
+
clone[key] = this.deepCloneAndMerge(target[key], source[key]);
|
|
174
|
+
else
|
|
175
|
+
clone[key] = this.deepClone(source[key]);
|
|
176
|
+
}
|
|
177
|
+
return clone;
|
|
178
|
+
}
|
|
179
|
+
// For any other cases
|
|
180
|
+
throw new Error('Unable to clone the object. Unsupported type.');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.A_CommonHelper = A_CommonHelper;
|
|
184
|
+
//# sourceMappingURL=A_Common.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Common.helper.js","sourceRoot":"","sources":["../../../src/helpers/A_Common.helper.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IAEvB,MAAM,CAAC,OAAO;QACV,OAAO,IAAI,OAAO,CAAY,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAsB,KAAe,EAAE,MAAgB;QAE7E,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,YAAY,CAA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
+
import { A_ScheduleObject } from "../global/A_ScheduleObject.class";
|
|
2
|
+
import { A_TYPES__ScheduleObjectConfig } from "../types/A_ScheduleObject.types";
|
|
3
|
+
export declare class A_ScheduleHelper {
|
|
4
|
+
static delay<T = void>(ms?: number, resolver?: Promise<T>): Promise<T>;
|
|
5
|
+
static schedule<T = void>(ms: number | undefined, resolver: () => Promise<T>, config?: A_TYPES__ScheduleObjectConfig): A_ScheduleObject<T>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_ScheduleHelper = void 0;
|
|
4
|
+
const A_ScheduleObject_class_1 = require("../global/A_ScheduleObject.class");
|
|
5
|
+
class A_ScheduleHelper {
|
|
6
|
+
static delay(ms = 1000, resolver) {
|
|
7
|
+
return new Promise((resolve, reject) => setTimeout(() => {
|
|
8
|
+
if (resolver) {
|
|
9
|
+
resolver.then(resolve).catch(reject);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resolve(0);
|
|
13
|
+
}
|
|
14
|
+
}, ms));
|
|
15
|
+
}
|
|
16
|
+
static schedule(ms = 1000, resolver, config) {
|
|
17
|
+
return new A_ScheduleObject_class_1.A_ScheduleObject(ms, resolver, config);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.A_ScheduleHelper = A_ScheduleHelper;
|
|
21
|
+
//# sourceMappingURL=A_Schedule.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Schedule.helper.js","sourceRoot":"","sources":["../../../src/helpers/A_Schedule.helper.ts"],"names":[],"mappings":";;;AAAA,6EAAoE;AAGpE,MAAa,gBAAgB;IAEzB,MAAM,CAAC,KAAK,CAAW,EAAE,GAAG,IAAI,EAAE,QAAqB;QACnD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE;YACvD,IAAI,QAAQ,EAAE,CAAC;gBACX,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACzC,CAAC;iBACI,CAAC;gBACF,OAAO,CAAC,CAAM,CAAC,CAAC;YACpB,CAAC;QACL,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACX,CAAC;IAGD,MAAM,CAAC,QAAQ,CACX,EAAE,GAAG,IAAI,EACT,QAA0B,EAC1B,MAAsC;QAEtC,OAAO,IAAI,yCAAgB,CAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACJ;AArBD,4CAqBC"}
|