drapcode-utility 1.0.0
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/build/encryption/index.d.ts +15 -0
- package/build/encryption/index.js +255 -0
- package/build/errors/app-error.d.ts +6 -0
- package/build/errors/app-error.js +30 -0
- package/build/errors/axios-error.d.ts +13 -0
- package/build/errors/axios-error.js +78 -0
- package/build/errors/bad-request-error.d.ts +9 -0
- package/build/errors/bad-request-error.js +32 -0
- package/build/errors/custom-error.d.ts +8 -0
- package/build/errors/custom-error.js +26 -0
- package/build/errors/not-found.d.ts +8 -0
- package/build/errors/not-found.js +31 -0
- package/build/index.d.ts +17 -0
- package/build/index.js +29 -0
- package/build/middlewares/api-limiter.d.ts +1 -0
- package/build/middlewares/api-limiter.js +21 -0
- package/build/middlewares/error-logger.d.ts +3 -0
- package/build/middlewares/error-logger.js +74 -0
- package/build/middlewares/interceptor-logger-new.d.ts +2 -0
- package/build/middlewares/interceptor-logger-new.js +54 -0
- package/build/middlewares/interceptor-logger.d.ts +2 -0
- package/build/middlewares/interceptor-logger.js +42 -0
- package/build/middlewares/redis/request-log.d.ts +1 -0
- package/build/middlewares/redis/request-log.js +79 -0
- package/build/utils/check-error.d.ts +9 -0
- package/build/utils/check-error.js +188 -0
- package/build/utils/date-util.d.ts +8 -0
- package/build/utils/date-util.js +104 -0
- package/build/utils/prepare-query.d.ts +132 -0
- package/build/utils/prepare-query.js +94 -0
- package/build/utils/query-parser.d.ts +11 -0
- package/build/utils/query-parser.js +778 -0
- package/build/utils/query-paser-new.d.ts +1 -0
- package/build/utils/query-paser-new.js +682 -0
- package/build/utils/util.d.ts +27 -0
- package/build/utils/util.js +373 -0
- package/build/utils/uuid-generator.d.ts +1 -0
- package/build/utils/uuid-generator.js +65 -0
- package/package.json +47 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type AwsConfig = {
|
|
2
|
+
accessKeyId: string;
|
|
3
|
+
secretAccessKey: string;
|
|
4
|
+
region: string;
|
|
5
|
+
};
|
|
6
|
+
declare type Encryption = {
|
|
7
|
+
encryptionType: string;
|
|
8
|
+
algorithm: string;
|
|
9
|
+
key: string;
|
|
10
|
+
awsConfig: AwsConfig;
|
|
11
|
+
};
|
|
12
|
+
export declare const crypt: (data: any, fields: Array<object>, encryption: Encryption, decrypt: boolean) => Promise<any>;
|
|
13
|
+
export declare const createKMSDataKey: (awsConfig: object, KeyId: string) => Promise<any>;
|
|
14
|
+
export declare const decryptDataKey: (dataKey: string, awsConfig: object) => Promise<any>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.decryptDataKey = exports.createKMSDataKey = exports.crypt = void 0;
|
|
43
|
+
var aws_sdk_1 = require("aws-sdk");
|
|
44
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
45
|
+
var prefix = "rec";
|
|
46
|
+
var randomCharLen = 8;
|
|
47
|
+
var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
+
var _a, accessKeyId, secretAccessKey, region, config, key, promises;
|
|
49
|
+
return __generator(this, function (_b) {
|
|
50
|
+
switch (_b.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
if (!(encryption.encryptionType === "KMS")) return [3 /*break*/, 2];
|
|
53
|
+
_a = encryption.awsConfig, accessKeyId = _a.accessKeyId, secretAccessKey = _a.secretAccessKey, region = _a.region;
|
|
54
|
+
config = {
|
|
55
|
+
region: region,
|
|
56
|
+
credentials: {
|
|
57
|
+
accessKeyId: accessKeyId,
|
|
58
|
+
secretAccessKey: secretAccessKey,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return [4 /*yield*/, exports.decryptDataKey(encryption.key, config)];
|
|
62
|
+
case 1:
|
|
63
|
+
key = _b.sent();
|
|
64
|
+
encryption.key = key.toString("base64");
|
|
65
|
+
_b.label = 2;
|
|
66
|
+
case 2:
|
|
67
|
+
if (!Array.isArray(data)) return [3 /*break*/, 4];
|
|
68
|
+
promises = data.map(function (item) {
|
|
69
|
+
return cryptItem(item, fields, encryption, decrypt);
|
|
70
|
+
});
|
|
71
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
72
|
+
case 3:
|
|
73
|
+
data = _b.sent();
|
|
74
|
+
return [3 /*break*/, 6];
|
|
75
|
+
case 4: return [4 /*yield*/, cryptItem(data, fields, encryption, decrypt)];
|
|
76
|
+
case 5:
|
|
77
|
+
data = _b.sent();
|
|
78
|
+
_b.label = 6;
|
|
79
|
+
case 6: return [2 /*return*/, data];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); };
|
|
83
|
+
exports.crypt = crypt;
|
|
84
|
+
var cryptItem = function (item, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
Object.keys(item).forEach(function (fieldName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var field, _a, _b;
|
|
88
|
+
return __generator(this, function (_c) {
|
|
89
|
+
switch (_c.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
field = fields.find(function (field) { return field.fieldName === fieldName; });
|
|
92
|
+
if (!(field && field.encrypted)) return [3 /*break*/, 2];
|
|
93
|
+
_a = item;
|
|
94
|
+
_b = fieldName;
|
|
95
|
+
return [4 /*yield*/, cryptData(item[fieldName], encryption, decrypt)];
|
|
96
|
+
case 1:
|
|
97
|
+
_a[_b] = _c.sent();
|
|
98
|
+
_c.label = 2;
|
|
99
|
+
case 2: return [2 /*return*/];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}); });
|
|
103
|
+
return [2 /*return*/, item];
|
|
104
|
+
});
|
|
105
|
+
}); };
|
|
106
|
+
var cryptData = function (data, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
+
var encryptionType, algorithm, key, _a, _b;
|
|
108
|
+
return __generator(this, function (_c) {
|
|
109
|
+
switch (_c.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
encryptionType = encryption.encryptionType, algorithm = encryption.algorithm, key = encryption.key;
|
|
112
|
+
if (!data)
|
|
113
|
+
return [2 /*return*/, data];
|
|
114
|
+
_a = encryptionType;
|
|
115
|
+
switch (_a) {
|
|
116
|
+
case "BASE64": return [3 /*break*/, 1];
|
|
117
|
+
case "CUSTOM": return [3 /*break*/, 2];
|
|
118
|
+
case "KMS": return [3 /*break*/, 3];
|
|
119
|
+
}
|
|
120
|
+
return [3 /*break*/, 8];
|
|
121
|
+
case 1: return [2 /*return*/, decrypt ? decryptBase64(data) : encryptBase64(data)];
|
|
122
|
+
case 2: return [2 /*return*/, decrypt
|
|
123
|
+
? decryptCustom(data, algorithm, key)
|
|
124
|
+
: encryptCustom(data, algorithm, key)];
|
|
125
|
+
case 3:
|
|
126
|
+
if (!decrypt) return [3 /*break*/, 5];
|
|
127
|
+
return [4 /*yield*/, decryptWithKMS(data, algorithm, key)];
|
|
128
|
+
case 4:
|
|
129
|
+
_b = _c.sent();
|
|
130
|
+
return [3 /*break*/, 7];
|
|
131
|
+
case 5: return [4 /*yield*/, encryptWithKMS(data, algorithm, key)];
|
|
132
|
+
case 6:
|
|
133
|
+
_b = _c.sent();
|
|
134
|
+
_c.label = 7;
|
|
135
|
+
case 7: return [2 /*return*/, _b];
|
|
136
|
+
case 8: return [2 /*return*/, data];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}); };
|
|
140
|
+
var encryptBase64 = function (data) {
|
|
141
|
+
if (data.startsWith(prefix))
|
|
142
|
+
return data;
|
|
143
|
+
var randomFront = getRandomAlphaNumeric(randomCharLen);
|
|
144
|
+
var randomback = getRandomAlphaNumeric(randomCharLen);
|
|
145
|
+
var base64Data = btoa(data);
|
|
146
|
+
return prefix + randomFront + base64Data + randomback;
|
|
147
|
+
};
|
|
148
|
+
var decryptBase64 = function (encryptedData) {
|
|
149
|
+
if (encryptedData.startsWith(prefix)) {
|
|
150
|
+
encryptedData = encryptedData.replace(prefix, "");
|
|
151
|
+
encryptedData = encryptedData.substring(randomCharLen, encryptedData.length - randomCharLen);
|
|
152
|
+
encryptedData = atob(encryptedData);
|
|
153
|
+
}
|
|
154
|
+
return encryptedData;
|
|
155
|
+
};
|
|
156
|
+
var encryptCustom = function (data, alogrithm, key) {
|
|
157
|
+
return data;
|
|
158
|
+
};
|
|
159
|
+
var decryptCustom = function (encryptedData, alogrithm, key) {
|
|
160
|
+
return encryptedData;
|
|
161
|
+
};
|
|
162
|
+
var getRandomAlphaNumeric = function (length) {
|
|
163
|
+
return Math.random().toString(36).substr(2, length);
|
|
164
|
+
};
|
|
165
|
+
var createKMSDataKey = function (awsConfig, KeyId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var kms_1;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
try {
|
|
169
|
+
kms_1 = new aws_sdk_1.KMS(awsConfig);
|
|
170
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
171
|
+
var params = {
|
|
172
|
+
KeyId: KeyId,
|
|
173
|
+
KeySpec: "AES_256",
|
|
174
|
+
};
|
|
175
|
+
kms_1.generateDataKey(params, function (err, data) {
|
|
176
|
+
if (err) {
|
|
177
|
+
console.log("\n Error", err);
|
|
178
|
+
reject(err);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
resolve(data);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
})];
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.log("\n Error: ", error);
|
|
188
|
+
}
|
|
189
|
+
return [2 /*return*/];
|
|
190
|
+
});
|
|
191
|
+
}); };
|
|
192
|
+
exports.createKMSDataKey = createKMSDataKey;
|
|
193
|
+
var decryptDataKey = function (dataKey, awsConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
|
194
|
+
var kms_2, CiphertextBlob_1;
|
|
195
|
+
return __generator(this, function (_a) {
|
|
196
|
+
try {
|
|
197
|
+
kms_2 = new aws_sdk_1.KMS(awsConfig);
|
|
198
|
+
CiphertextBlob_1 = Buffer.from(dataKey, "base64");
|
|
199
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
200
|
+
var params = { CiphertextBlob: CiphertextBlob_1 };
|
|
201
|
+
kms_2.decrypt(params, function (err, data) {
|
|
202
|
+
if (err) {
|
|
203
|
+
console.log("\n Error", err);
|
|
204
|
+
reject(err);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
resolve(data.Plaintext);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
})];
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
console.log("\n Error: ", error);
|
|
214
|
+
}
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
});
|
|
217
|
+
}); };
|
|
218
|
+
exports.decryptDataKey = decryptDataKey;
|
|
219
|
+
var encryptWithKMS = function (data, algorithm, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
|
+
var iv, keyBuffer, cipher, encryptedDataBuffer;
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
try {
|
|
223
|
+
iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
|
|
224
|
+
keyBuffer = Buffer.from(key, "base64");
|
|
225
|
+
cipher = crypto_1.default.createCipheriv(algorithm, keyBuffer, iv);
|
|
226
|
+
encryptedDataBuffer = cipher.update(data);
|
|
227
|
+
encryptedDataBuffer = Buffer.concat([encryptedDataBuffer, cipher.final()]);
|
|
228
|
+
return [2 /*return*/, encryptedDataBuffer.toString("base64")];
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.log("\n Error: ", error);
|
|
232
|
+
return [2 /*return*/, data];
|
|
233
|
+
}
|
|
234
|
+
return [2 /*return*/];
|
|
235
|
+
});
|
|
236
|
+
}); };
|
|
237
|
+
var decryptWithKMS = function (data, algorithm, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
238
|
+
var iv, encryptedData, keyBuffer, decipher, decryptedBuffer;
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
try {
|
|
241
|
+
iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
|
|
242
|
+
encryptedData = Buffer.from(data, "base64");
|
|
243
|
+
keyBuffer = Buffer.from(key, "base64");
|
|
244
|
+
decipher = crypto_1.default.createDecipheriv(algorithm, keyBuffer, iv);
|
|
245
|
+
decryptedBuffer = decipher.update(encryptedData);
|
|
246
|
+
decryptedBuffer = Buffer.concat([decryptedBuffer, decipher.final()]);
|
|
247
|
+
return [2 /*return*/, decryptedBuffer.toString()];
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
console.log("\n Error: ", error);
|
|
251
|
+
return [2 /*return*/, data];
|
|
252
|
+
}
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
});
|
|
255
|
+
}); };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AppError = void 0;
|
|
17
|
+
var AppError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(AppError, _super);
|
|
19
|
+
function AppError(message, statusCode) {
|
|
20
|
+
var _this = _super.call(this, message) || this;
|
|
21
|
+
_this.message = message;
|
|
22
|
+
_this.statusCode = statusCode;
|
|
23
|
+
_this.statusCode = statusCode;
|
|
24
|
+
_this.isOperational = true;
|
|
25
|
+
Object.setPrototypeOf(_this, AppError.prototype);
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
return AppError;
|
|
29
|
+
}(Error));
|
|
30
|
+
exports.AppError = AppError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
2
|
+
export declare const parseAxiosError: (error: AxiosError) => {
|
|
3
|
+
success?: undefined;
|
|
4
|
+
error?: undefined;
|
|
5
|
+
status?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
success: boolean;
|
|
8
|
+
error: any;
|
|
9
|
+
status: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const parseXanoConfigError: (error: any) => string;
|
|
12
|
+
export declare const parseAirtableConfigError: (error: any) => string;
|
|
13
|
+
export declare const parseSupabaseConfigError: (error: any) => string;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSupabaseConfigError = exports.parseAirtableConfigError = exports.parseXanoConfigError = exports.parseAxiosError = void 0;
|
|
4
|
+
var parseAxiosError = function (error) {
|
|
5
|
+
if (!error) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
var response = error.response, request = error.request, message = error.message;
|
|
9
|
+
var errData = "", errStatus = 400;
|
|
10
|
+
if (response) {
|
|
11
|
+
console.log("err.response.data: ", response.data);
|
|
12
|
+
console.log("err.response.status: ", response.status);
|
|
13
|
+
console.log("err.response.headers", response.headers);
|
|
14
|
+
errData = response.data;
|
|
15
|
+
errStatus = response.status;
|
|
16
|
+
}
|
|
17
|
+
else if (request) {
|
|
18
|
+
errData = "No Response Received from the API";
|
|
19
|
+
console.log("err.request: ", request);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (message.includes("ECONNABORTED")) {
|
|
23
|
+
errData = "No response received from the REST API";
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
errData = message;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { success: false, error: errData, status: errStatus };
|
|
30
|
+
};
|
|
31
|
+
exports.parseAxiosError = parseAxiosError;
|
|
32
|
+
var parseXanoConfigError = function (error) {
|
|
33
|
+
if (!error || !error.code) {
|
|
34
|
+
return "Failed from Xano";
|
|
35
|
+
}
|
|
36
|
+
var errorMessage = "";
|
|
37
|
+
switch (error.code) {
|
|
38
|
+
case "ERROR_CODE_UNAUTHORIZED":
|
|
39
|
+
errorMessage = "Developer API Key is wrong";
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
errorMessage = "Failed from Xano";
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return errorMessage;
|
|
46
|
+
};
|
|
47
|
+
exports.parseXanoConfigError = parseXanoConfigError;
|
|
48
|
+
var parseAirtableConfigError = function (error) {
|
|
49
|
+
if (!error || !error.error || !error.error.type) {
|
|
50
|
+
return "Failed from Airtable";
|
|
51
|
+
}
|
|
52
|
+
var errorMessage = "";
|
|
53
|
+
switch (error.error.type) {
|
|
54
|
+
case "AUTHENTICATION_REQUIRED":
|
|
55
|
+
errorMessage = "Authorization is missing/wrong.";
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
errorMessage = "Failed from Airtable";
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return errorMessage;
|
|
62
|
+
};
|
|
63
|
+
exports.parseAirtableConfigError = parseAirtableConfigError;
|
|
64
|
+
var parseSupabaseConfigError = function (error) {
|
|
65
|
+
if (!error) {
|
|
66
|
+
return "Failed from Supabase";
|
|
67
|
+
}
|
|
68
|
+
var errorMessage = "";
|
|
69
|
+
switch (error) {
|
|
70
|
+
case "ENOTFOUND":
|
|
71
|
+
errorMessage = "Given Supabase URL does not exists/API Key is wrong";
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
return errorMessage;
|
|
77
|
+
};
|
|
78
|
+
exports.parseSupabaseConfigError = parseSupabaseConfigError;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.BadRequestError = void 0;
|
|
17
|
+
var custom_error_1 = require("./custom-error");
|
|
18
|
+
var BadRequestError = /** @class */ (function (_super) {
|
|
19
|
+
__extends(BadRequestError, _super);
|
|
20
|
+
function BadRequestError(message) {
|
|
21
|
+
var _this = _super.call(this, message) || this;
|
|
22
|
+
_this.message = message;
|
|
23
|
+
_this.statusCode = 400;
|
|
24
|
+
Object.setPrototypeOf(_this, BadRequestError.prototype);
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
BadRequestError.prototype.serializeErrors = function () {
|
|
28
|
+
return [{ message: this.message }];
|
|
29
|
+
};
|
|
30
|
+
return BadRequestError;
|
|
31
|
+
}(custom_error_1.CustomError));
|
|
32
|
+
exports.BadRequestError = BadRequestError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.CustomError = void 0;
|
|
17
|
+
var CustomError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(CustomError, _super);
|
|
19
|
+
function CustomError(message) {
|
|
20
|
+
var _this = _super.call(this) || this;
|
|
21
|
+
Object.setPrototypeOf(_this, CustomError.prototype);
|
|
22
|
+
return _this;
|
|
23
|
+
}
|
|
24
|
+
return CustomError;
|
|
25
|
+
}(Error));
|
|
26
|
+
exports.CustomError = CustomError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NotFoundError = void 0;
|
|
17
|
+
var custom_error_1 = require("./custom-error");
|
|
18
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
19
|
+
__extends(NotFoundError, _super);
|
|
20
|
+
function NotFoundError() {
|
|
21
|
+
var _this = _super.call(this, "Route Not Found") || this;
|
|
22
|
+
_this.statusCode = 404;
|
|
23
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
NotFoundError.prototype.serializeErrors = function () {
|
|
27
|
+
return [{ message: "Not Found" }];
|
|
28
|
+
};
|
|
29
|
+
return NotFoundError;
|
|
30
|
+
}(custom_error_1.CustomError));
|
|
31
|
+
exports.NotFoundError = NotFoundError;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./errors/bad-request-error";
|
|
2
|
+
export * from "./errors/custom-error";
|
|
3
|
+
export * from "./errors/not-found";
|
|
4
|
+
export * from "./errors/app-error";
|
|
5
|
+
export * from "./errors/axios-error";
|
|
6
|
+
export * from "./middlewares/error-logger";
|
|
7
|
+
export * from "./middlewares/interceptor-logger";
|
|
8
|
+
export * from "./middlewares/interceptor-logger-new";
|
|
9
|
+
export * from "./middlewares/api-limiter";
|
|
10
|
+
export * from "./utils/date-util";
|
|
11
|
+
export * from "./utils/query-parser";
|
|
12
|
+
export * from "./utils/query-paser-new";
|
|
13
|
+
export * from "./utils/util";
|
|
14
|
+
export * from "./utils/uuid-generator";
|
|
15
|
+
export * from "./utils/check-error";
|
|
16
|
+
export * from "./utils/prepare-query";
|
|
17
|
+
export * from "./encryption/index";
|
package/build/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
14
|
+
__exportStar(require("./errors/custom-error"), exports);
|
|
15
|
+
__exportStar(require("./errors/not-found"), exports);
|
|
16
|
+
__exportStar(require("./errors/app-error"), exports);
|
|
17
|
+
__exportStar(require("./errors/axios-error"), exports);
|
|
18
|
+
__exportStar(require("./middlewares/error-logger"), exports);
|
|
19
|
+
__exportStar(require("./middlewares/interceptor-logger"), exports);
|
|
20
|
+
__exportStar(require("./middlewares/interceptor-logger-new"), exports);
|
|
21
|
+
__exportStar(require("./middlewares/api-limiter"), exports);
|
|
22
|
+
__exportStar(require("./utils/date-util"), exports);
|
|
23
|
+
__exportStar(require("./utils/query-parser"), exports);
|
|
24
|
+
__exportStar(require("./utils/query-paser-new"), exports);
|
|
25
|
+
__exportStar(require("./utils/util"), exports);
|
|
26
|
+
__exportStar(require("./utils/uuid-generator"), exports);
|
|
27
|
+
__exportStar(require("./utils/check-error"), exports);
|
|
28
|
+
__exportStar(require("./utils/prepare-query"), exports);
|
|
29
|
+
__exportStar(require("./encryption/index"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const apiLimiter: any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiLimiter = void 0;
|
|
4
|
+
var rateLimit = require("express-rate-limit");
|
|
5
|
+
exports.apiLimiter = rateLimit({
|
|
6
|
+
windowMs: 1 * 60 * 1000,
|
|
7
|
+
max: 5,
|
|
8
|
+
message: "You have crossed your limit. please try after some time",
|
|
9
|
+
headers: true,
|
|
10
|
+
keyGenerator: function (req, res) {
|
|
11
|
+
var subdomains = req.subdomains;
|
|
12
|
+
var ip = req.headers["x-forwarded-for"] ||
|
|
13
|
+
req.connection.remoteAddress ||
|
|
14
|
+
req.socket.remoteAddress ||
|
|
15
|
+
(req.connection.socket ? req.connection.socket.remoteAddress : null);
|
|
16
|
+
var key = Array.isArray(subdomains) && subdomains.length
|
|
17
|
+
? ip + "-" + subdomains[1]
|
|
18
|
+
: ip;
|
|
19
|
+
return key;
|
|
20
|
+
},
|
|
21
|
+
});
|