@ductape/sdk 0.0.4-v4 → 0.0.4-v40
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/dist/api/services/appApi.service.d.ts +48 -2
- package/dist/api/services/appApi.service.js +101 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +12 -2
- package/dist/api/services/processorApi.service.js +12 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +39 -1
- package/dist/api/services/productsApi.service.js +76 -0
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/userApi.service.js +1 -0
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/services/workspaceApi.service.js +1 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +6 -1
- package/dist/api/urls.js +12 -2
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +41 -33
- package/dist/apps/services/app.service.js +473 -185
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
- package/dist/clients/apps.client.js +1 -1
- package/dist/clients/apps.client.js.map +1 -1
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +7 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +29 -2
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +1009 -91
- package/dist/index.js +969 -126
- package/dist/index.js.map +1 -1
- package/dist/inputs/inputs.service.js +2 -2
- package/dist/inputs/inputs.service.js.map +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/logs/logs.service.js +1 -0
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +5 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.d.ts +0 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/messagebrokers/kafka.service.js +0 -2
- package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +40 -9
- package/dist/processor/services/processor.service.js +638 -276
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.d.ts +3 -0
- package/dist/processor/utils/processor.utils.js +89 -6
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/processor/utils/storage.util.js +54 -40
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +98 -77
- package/dist/products/services/products.service.js +569 -325
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/services/utils/crypt.utils.d.ts +1 -0
- package/dist/products/services/utils/crypt.utils.js +17 -0
- package/dist/products/services/utils/crypt.utils.js.map +1 -0
- package/dist/products/services/utils/functions.utils.d.ts +13 -0
- package/dist/products/services/utils/functions.utils.js +294 -0
- package/dist/products/services/utils/functions.utils.js.map +1 -0
- package/dist/products/services/utils/objects.utils.d.ts +13 -0
- package/dist/products/services/utils/objects.utils.js +89 -0
- package/dist/products/services/utils/objects.utils.js.map +1 -0
- package/dist/products/services/utils/string.utils.d.ts +12 -0
- package/dist/products/services/utils/string.utils.js +168 -0
- package/dist/products/services/utils/string.utils.js.map +1 -0
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +2 -1
- package/dist/products/validators/index.js +3 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +9 -4
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/test/test.health.d.ts +1 -0
- package/dist/test/test.health.js +49 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.js +51 -4
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.imports.js +22 -7
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.notifiers.d.ts +1 -0
- package/dist/test/test.notifiers.js +85 -0
- package/dist/test/test.notifiers.js.map +1 -0
- package/dist/test/test.processor.js +32 -115
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +4 -11
- package/dist/types/enums.d.ts +3 -1
- package/dist/types/enums.js +2 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -0
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +66 -9
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +52 -8
- package/dist/types/productsBuilder.types.js +9 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.d.ts +0 -0
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +15 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
import { IRequestCounter } from "../types/request.types";
|
|
3
|
+
export interface IRequestTrackerService {
|
|
4
|
+
incrementRequest(app_id: string, workspace_id: string): Promise<IRequestCounter>;
|
|
5
|
+
getRequestCount(app_id: string, workspace_id: string): Promise<IRequestCounter>;
|
|
6
|
+
cleanup(maxAge?: number): Promise<void>;
|
|
7
|
+
disconnect(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default class RequestTrackerService implements IRequestTrackerService {
|
|
10
|
+
private static instance;
|
|
11
|
+
private redis;
|
|
12
|
+
private readonly KEY_PREFIX;
|
|
13
|
+
private readonly LOCK_PREFIX;
|
|
14
|
+
constructor(redis_client: Redis, redisUrl?: string);
|
|
15
|
+
static getInstance(redis_client: Redis, redisUrl?: string): RequestTrackerService;
|
|
16
|
+
private getUniqueKey;
|
|
17
|
+
private getRedisKey;
|
|
18
|
+
private getLockKey;
|
|
19
|
+
private initializeCounter;
|
|
20
|
+
private shouldResetCounter;
|
|
21
|
+
private resetCounterIfNeeded;
|
|
22
|
+
private getCounterFromRedis;
|
|
23
|
+
private setCounterInRedis;
|
|
24
|
+
private acquireLock;
|
|
25
|
+
private releaseLock;
|
|
26
|
+
incrementRequest(app_id: string, workspace_id: string): Promise<IRequestCounter>;
|
|
27
|
+
getRequestCount(app_id: string, workspace_id: string): Promise<IRequestCounter>;
|
|
28
|
+
cleanup(maxAge?: number): Promise<void>;
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
healthCheck(): Promise<boolean>;
|
|
31
|
+
getConnectionStatus(): string;
|
|
32
|
+
getMultipleRequestCounts(requests: Array<{
|
|
33
|
+
app_id: string;
|
|
34
|
+
workspace_id: string;
|
|
35
|
+
}>): Promise<Map<string, IRequestCounter>>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
14
|
+
const constants_1 = require("../../utils/constants");
|
|
15
|
+
class RequestTrackerService {
|
|
16
|
+
constructor(redis_client, redisUrl = constants_1.REDIS_URL) {
|
|
17
|
+
this.KEY_PREFIX = 'request_tracker';
|
|
18
|
+
this.LOCK_PREFIX = 'lock:request_tracker';
|
|
19
|
+
this.redis = redis_client || new ioredis_1.default(redisUrl, {
|
|
20
|
+
enableReadyCheck: false,
|
|
21
|
+
lazyConnect: true,
|
|
22
|
+
maxRetriesPerRequest: 3,
|
|
23
|
+
connectTimeout: 10000,
|
|
24
|
+
commandTimeout: 5000,
|
|
25
|
+
});
|
|
26
|
+
this.redis.on('error', (err) => {
|
|
27
|
+
console.error('Redis connection error:', err);
|
|
28
|
+
});
|
|
29
|
+
this.redis.on('ready', () => {
|
|
30
|
+
console.log('Redis connection established');
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static getInstance(redis_client, redisUrl = constants_1.REDIS_URL) {
|
|
34
|
+
if (!RequestTrackerService.instance) {
|
|
35
|
+
if (!redisUrl) {
|
|
36
|
+
throw new Error('Redis URL is required for first initialization');
|
|
37
|
+
}
|
|
38
|
+
RequestTrackerService.instance = new RequestTrackerService(redis_client, redisUrl);
|
|
39
|
+
}
|
|
40
|
+
return RequestTrackerService.instance;
|
|
41
|
+
}
|
|
42
|
+
getUniqueKey(app_id, workspace_id) {
|
|
43
|
+
return `${app_id}:${workspace_id}`;
|
|
44
|
+
}
|
|
45
|
+
getRedisKey(app_id, workspace_id) {
|
|
46
|
+
return `${this.KEY_PREFIX}:${app_id}:${workspace_id}`;
|
|
47
|
+
}
|
|
48
|
+
getLockKey(app_id, workspace_id) {
|
|
49
|
+
return `${this.LOCK_PREFIX}:${app_id}:${workspace_id}`;
|
|
50
|
+
}
|
|
51
|
+
initializeCounter() {
|
|
52
|
+
const now = new Date();
|
|
53
|
+
return {
|
|
54
|
+
per_minute: 0,
|
|
55
|
+
per_hour: 0,
|
|
56
|
+
per_day: 0,
|
|
57
|
+
per_week: 0,
|
|
58
|
+
per_month: 0,
|
|
59
|
+
last_reset: {
|
|
60
|
+
minute: now,
|
|
61
|
+
hour: now,
|
|
62
|
+
day: now,
|
|
63
|
+
week: now,
|
|
64
|
+
month: now,
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
shouldResetCounter(lastReset, interval) {
|
|
69
|
+
const now = new Date();
|
|
70
|
+
const diff = now.getTime() - lastReset.getTime();
|
|
71
|
+
switch (interval) {
|
|
72
|
+
case 'minute':
|
|
73
|
+
return diff >= 60 * 1000; // 1 minute
|
|
74
|
+
case 'hour':
|
|
75
|
+
return diff >= 60 * 60 * 1000; // 1 hour
|
|
76
|
+
case 'day':
|
|
77
|
+
return diff >= 24 * 60 * 60 * 1000; // 1 day
|
|
78
|
+
case 'week':
|
|
79
|
+
return diff >= 7 * 24 * 60 * 60 * 1000; // 1 week
|
|
80
|
+
case 'month':
|
|
81
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
82
|
+
return lastReset < monthStart;
|
|
83
|
+
default:
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
resetCounterIfNeeded(counter) {
|
|
88
|
+
const now = new Date();
|
|
89
|
+
const intervals = ['minute', 'hour', 'day', 'week', 'month'];
|
|
90
|
+
let wasReset = false;
|
|
91
|
+
intervals.forEach(interval => {
|
|
92
|
+
if (this.shouldResetCounter(counter.last_reset[interval], interval)) {
|
|
93
|
+
counter[`per_${interval}`] = 0;
|
|
94
|
+
counter.last_reset[interval] = now;
|
|
95
|
+
wasReset = true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return wasReset;
|
|
99
|
+
}
|
|
100
|
+
async getCounterFromRedis(key) {
|
|
101
|
+
try {
|
|
102
|
+
const data = await this.redis.get(key);
|
|
103
|
+
if (!data)
|
|
104
|
+
return null;
|
|
105
|
+
const parsed = JSON.parse(data);
|
|
106
|
+
// Convert date strings back to Date objects
|
|
107
|
+
Object.keys(parsed.last_reset).forEach(interval => {
|
|
108
|
+
parsed.last_reset[interval] = new Date(parsed.last_reset[interval]);
|
|
109
|
+
});
|
|
110
|
+
return parsed;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error('Error getting counter from Redis:', error);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async setCounterInRedis(key, counter) {
|
|
118
|
+
try {
|
|
119
|
+
// Set TTL based on the longest interval (1 month + buffer)
|
|
120
|
+
const ttl = 32 * 24 * 60 * 60; // 32 days in seconds
|
|
121
|
+
await this.redis.setex(key, ttl, JSON.stringify(counter));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('Error setting counter in Redis:', error);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async acquireLock(lockKey, ttl = 5) {
|
|
129
|
+
try {
|
|
130
|
+
const result = await this.redis.set(lockKey, '1', 'EX', ttl, 'NX');
|
|
131
|
+
return result === 'OK';
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error('Error acquiring lock:', error);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async releaseLock(lockKey) {
|
|
139
|
+
try {
|
|
140
|
+
await this.redis.del(lockKey);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error('Error releasing lock:', error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async incrementRequest(app_id, workspace_id) {
|
|
147
|
+
const key = this.getRedisKey(app_id, workspace_id);
|
|
148
|
+
const lockKey = this.getLockKey(app_id, workspace_id);
|
|
149
|
+
// Acquire lock to prevent race conditions
|
|
150
|
+
const lockAcquired = await this.acquireLock(lockKey);
|
|
151
|
+
if (!lockAcquired) {
|
|
152
|
+
// If we can't acquire lock, wait a bit and try to get current count
|
|
153
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
154
|
+
return this.getRequestCount(app_id, workspace_id);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
let counter = await this.getCounterFromRedis(key);
|
|
158
|
+
if (!counter) {
|
|
159
|
+
counter = this.initializeCounter();
|
|
160
|
+
}
|
|
161
|
+
this.resetCounterIfNeeded(counter);
|
|
162
|
+
// Increment all counters
|
|
163
|
+
counter.per_minute++;
|
|
164
|
+
counter.per_hour++;
|
|
165
|
+
counter.per_day++;
|
|
166
|
+
counter.per_week++;
|
|
167
|
+
counter.per_month++;
|
|
168
|
+
await this.setCounterInRedis(key, counter);
|
|
169
|
+
return Object.assign({}, counter);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
await this.releaseLock(lockKey);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async getRequestCount(app_id, workspace_id) {
|
|
176
|
+
const key = this.getRedisKey(app_id, workspace_id);
|
|
177
|
+
let counter = await this.getCounterFromRedis(key);
|
|
178
|
+
if (!counter) {
|
|
179
|
+
counter = this.initializeCounter();
|
|
180
|
+
await this.setCounterInRedis(key, counter);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const wasReset = this.resetCounterIfNeeded(counter);
|
|
184
|
+
if (wasReset) {
|
|
185
|
+
await this.setCounterInRedis(key, counter);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return Object.assign({}, counter);
|
|
189
|
+
}
|
|
190
|
+
async cleanup(maxAge = 24 * 60 * 60 * 1000) {
|
|
191
|
+
var _a, e_1, _b, _c;
|
|
192
|
+
try {
|
|
193
|
+
const pattern = `${this.KEY_PREFIX}:*`;
|
|
194
|
+
const stream = this.redis.scanStream({
|
|
195
|
+
match: pattern,
|
|
196
|
+
count: 100
|
|
197
|
+
});
|
|
198
|
+
const now = new Date();
|
|
199
|
+
const keysToDelete = [];
|
|
200
|
+
try {
|
|
201
|
+
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = await stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
|
|
202
|
+
_c = stream_1_1.value;
|
|
203
|
+
_d = false;
|
|
204
|
+
const keys = _c;
|
|
205
|
+
for (const key of keys) {
|
|
206
|
+
try {
|
|
207
|
+
const counter = await this.getCounterFromRedis(key);
|
|
208
|
+
if (counter) {
|
|
209
|
+
const oldestReset = Math.min(...Object.values(counter.last_reset).map(d => d.getTime()));
|
|
210
|
+
if (now.getTime() - oldestReset > maxAge) {
|
|
211
|
+
keysToDelete.push(key);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
console.error(`Error checking key ${key} for cleanup:`, error);
|
|
217
|
+
// If we can't read the key, it's probably corrupt, so delete it
|
|
218
|
+
keysToDelete.push(key);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
224
|
+
finally {
|
|
225
|
+
try {
|
|
226
|
+
if (!_d && !_a && (_b = stream_1.return)) await _b.call(stream_1);
|
|
227
|
+
}
|
|
228
|
+
finally { if (e_1) throw e_1.error; }
|
|
229
|
+
}
|
|
230
|
+
if (keysToDelete.length > 0) {
|
|
231
|
+
await this.redis.del(...keysToDelete);
|
|
232
|
+
console.log(`Cleaned up ${keysToDelete.length} expired request counters`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
console.error('Error during cleanup:', error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async disconnect() {
|
|
240
|
+
try {
|
|
241
|
+
await this.redis.quit();
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
console.error('Error disconnecting from Redis:', error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Health check method
|
|
248
|
+
async healthCheck() {
|
|
249
|
+
try {
|
|
250
|
+
const result = await this.redis.ping();
|
|
251
|
+
return result === 'PONG';
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
console.error('Redis health check failed:', error);
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Get Redis connection status
|
|
259
|
+
getConnectionStatus() {
|
|
260
|
+
return this.redis.status;
|
|
261
|
+
}
|
|
262
|
+
// Batch operations for efficiency
|
|
263
|
+
async getMultipleRequestCounts(requests) {
|
|
264
|
+
const pipeline = this.redis.pipeline();
|
|
265
|
+
const keys = requests.map(req => this.getRedisKey(req.app_id, req.workspace_id));
|
|
266
|
+
keys.forEach(key => {
|
|
267
|
+
pipeline.get(key);
|
|
268
|
+
});
|
|
269
|
+
try {
|
|
270
|
+
const results = await pipeline.exec();
|
|
271
|
+
const counters = new Map();
|
|
272
|
+
for (let i = 0; i < requests.length; i++) {
|
|
273
|
+
const result = results === null || results === void 0 ? void 0 : results[i];
|
|
274
|
+
const request = requests[i];
|
|
275
|
+
const uniqueKey = this.getUniqueKey(request.app_id, request.workspace_id);
|
|
276
|
+
if (result && result[1]) {
|
|
277
|
+
try {
|
|
278
|
+
const parsed = JSON.parse(result[1]);
|
|
279
|
+
// Convert date strings back to Date objects
|
|
280
|
+
Object.keys(parsed.last_reset).forEach(interval => {
|
|
281
|
+
parsed.last_reset[interval] = new Date(parsed.last_reset[interval]);
|
|
282
|
+
});
|
|
283
|
+
this.resetCounterIfNeeded(parsed);
|
|
284
|
+
counters.set(uniqueKey, parsed);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error(`Error parsing counter for ${uniqueKey}:`, error);
|
|
288
|
+
counters.set(uniqueKey, this.initializeCounter());
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
counters.set(uniqueKey, this.initializeCounter());
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return counters;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
console.error('Error in batch get operation:', error);
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.default = RequestTrackerService;
|
|
304
|
+
//# sourceMappingURL=request.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.service.js","sourceRoot":"","sources":["../../../src/processor/services/request.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAA4B;AAE5B,qDAAkD;AAUlD,MAAqB,qBAAqB;IAMtC,YAAY,YAAmB,EAAE,WAAmB,qBAAS;QAH5C,eAAU,GAAG,iBAAiB,CAAC;QAC/B,gBAAW,GAAG,sBAAsB,CAAC;QAGlD,IAAI,CAAC,KAAK,GAAG,YAAY,IAAI,IAAI,iBAAK,CAAC,QAAQ,EAAE;YAC7C,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,IA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M,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACxE,CAAC,CAAC,CAAC;wBAEH,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;wBAClC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBACpC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACb,OAAO,CAAC,KAAK,CAAC,6BAA6B,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;wBAChE,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;oBACtD,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;gBACtD,CAAC;YACL,CAAC;YAED,OAAO,QAAQ,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AApTD,wCAoTC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.types.js","sourceRoot":"","sources":["../../../src/processor/types/request.types.ts"],"names":[],"mappings":""}
|
|
@@ -13,6 +13,7 @@ export declare const encrypt: (text: string, key: string) => string;
|
|
|
13
13
|
export declare const decrypt: (text: string, key: string) => string;
|
|
14
14
|
export declare const extractNumberFromArrayString: (str: string) => number | null;
|
|
15
15
|
export declare const calculateExpiry: (expiry: number, period: TokenPeriods) => number;
|
|
16
|
+
export declare const calculateJWTExpiry: (expiry: number, period: TokenPeriods) => string;
|
|
16
17
|
export declare function parameterizeResource(resource: string, key: string, datapoint: string | undefined): string;
|
|
17
18
|
export declare function validateNotification({ push_notification }: IProductNotificationTemplate, payload: INotificationPayload): void;
|
|
18
19
|
export declare const isValidSqsUrl: (url: string) => boolean;
|
|
@@ -37,6 +38,7 @@ export declare const structuredClone: (data: any) => any;
|
|
|
37
38
|
export declare const cleanBlob: (data: any) => any;
|
|
38
39
|
export declare const generateIndexes: (operator: string, //">" | "<" | ">=" | "<=" | "==" | "!==",
|
|
39
40
|
iter: number, init: number, value: number) => number[];
|
|
41
|
+
export declare function parseTimeToMs(interval: string): number;
|
|
40
42
|
export declare const validateStringsInObject: (obj: Record<string, unknown>) => boolean;
|
|
41
43
|
export declare const extractAxiosErrorDetails: (error: any) => {
|
|
42
44
|
code: any;
|
|
@@ -93,4 +95,5 @@ export declare const generateMockData: (resource: string, env: string, payload:
|
|
|
93
95
|
export declare function anonymizeObject<T>(obj: T): T;
|
|
94
96
|
export declare function anonymizeValue(value: string): string;
|
|
95
97
|
export declare function toFormUrlEncoded(json: Record<string, any>): string;
|
|
98
|
+
export declare function extractSelectorValue(schema: Record<string, unknown>, stages: Array<string>, selector: string): any;
|
|
96
99
|
export {};
|
|
@@ -36,21 +36,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.generateMockData = exports.getMigrationsToRun = exports.validateFeatureJSONInput = exports.updateUrlsInObject = exports.extractAxiosErrorDetails = exports.validateStringsInObject = exports.generateIndexes = exports.cleanBlob = exports.structuredClone = exports.compareValues = exports.generateDatabaseQuery = exports.transformToJson = exports.mailerClient = exports.replacePlaceholderString = exports.removeWrappingQuotes = exports.isValidSqsUrl = exports.calculateExpiry = exports.extractNumberFromArrayString = exports.decrypt = exports.encrypt = exports.generateObjectId = exports.generateAxiosConfig = void 0;
|
|
39
|
+
exports.generateMockData = exports.getMigrationsToRun = exports.validateFeatureJSONInput = exports.updateUrlsInObject = exports.extractAxiosErrorDetails = exports.validateStringsInObject = exports.generateIndexes = exports.cleanBlob = exports.structuredClone = exports.compareValues = exports.generateDatabaseQuery = exports.transformToJson = exports.mailerClient = exports.replacePlaceholderString = exports.removeWrappingQuotes = exports.isValidSqsUrl = exports.calculateJWTExpiry = exports.calculateExpiry = exports.extractNumberFromArrayString = exports.decrypt = exports.encrypt = exports.generateObjectId = exports.generateAxiosConfig = void 0;
|
|
40
40
|
exports.parameterizeResource = parameterizeResource;
|
|
41
41
|
exports.validateNotification = validateNotification;
|
|
42
42
|
exports.generateNotificationTemplate = generateNotificationTemplate;
|
|
43
43
|
exports.convertStringToObject = convertStringToObject;
|
|
44
44
|
exports.generateSqlQuery = generateSqlQuery;
|
|
45
|
+
exports.parseTimeToMs = parseTimeToMs;
|
|
45
46
|
exports.anonymizeObject = anonymizeObject;
|
|
46
47
|
exports.anonymizeValue = anonymizeValue;
|
|
47
48
|
exports.toFormUrlEncoded = toFormUrlEncoded;
|
|
49
|
+
exports.extractSelectorValue = extractSelectorValue;
|
|
48
50
|
//import * as crypto from 'crypto';
|
|
49
51
|
const CryptoJS = __importStar(require("crypto-js"));
|
|
50
52
|
const enums_1 = require("../../types/enums");
|
|
51
53
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
52
54
|
const enums_2 = require("../../types/enums");
|
|
53
|
-
const string_utils_1 = require("../../products/utils/string.utils");
|
|
55
|
+
const string_utils_1 = require("../../products/services/utils/string.utils");
|
|
54
56
|
const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"));
|
|
55
57
|
const types_1 = require("../../types");
|
|
56
58
|
const crypto_1 = require("crypto");
|
|
@@ -136,8 +138,36 @@ const calculateExpiry = (expiry, period) => {
|
|
|
136
138
|
}
|
|
137
139
|
};
|
|
138
140
|
exports.calculateExpiry = calculateExpiry;
|
|
141
|
+
const calculateJWTExpiry = (expiry, period) => {
|
|
142
|
+
if (expiry === null) {
|
|
143
|
+
return '100y'; // fallback for near-infinite expiry
|
|
144
|
+
}
|
|
145
|
+
switch (period) {
|
|
146
|
+
case enums_1.TokenPeriods.SECONDS:
|
|
147
|
+
return `${expiry}s`;
|
|
148
|
+
case enums_1.TokenPeriods.MINUTES:
|
|
149
|
+
return `${expiry}m`;
|
|
150
|
+
case enums_1.TokenPeriods.HOURS:
|
|
151
|
+
return `${expiry}h`;
|
|
152
|
+
case enums_1.TokenPeriods.DAYS:
|
|
153
|
+
return `${expiry}d`;
|
|
154
|
+
case enums_1.TokenPeriods.WEEKS:
|
|
155
|
+
return `${expiry * 7}d`; // JWT doesn't support 'w' in all libs
|
|
156
|
+
case enums_1.TokenPeriods.MONTHS:
|
|
157
|
+
return `${expiry * 30}d`; // approximate
|
|
158
|
+
case enums_1.TokenPeriods.YEARS:
|
|
159
|
+
return `${expiry}y`;
|
|
160
|
+
default:
|
|
161
|
+
throw new Error('Invalid token period');
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
exports.calculateJWTExpiry = calculateJWTExpiry;
|
|
139
165
|
function parameterizeResource(resource, key, datapoint) {
|
|
140
|
-
|
|
166
|
+
if (!datapoint)
|
|
167
|
+
return resource;
|
|
168
|
+
// Regex matches :key or {{key}} (with optional whitespace)
|
|
169
|
+
const regex = new RegExp(`(:${key})|(\{\{\s*${key}\s*\}\})`, 'g');
|
|
170
|
+
return resource.replace(regex, datapoint);
|
|
141
171
|
}
|
|
142
172
|
function validateNotification({ push_notification }, payload) {
|
|
143
173
|
const requiredFields = {
|
|
@@ -458,8 +488,8 @@ const structuredClone = (data) => {
|
|
|
458
488
|
exports.structuredClone = structuredClone;
|
|
459
489
|
const cleanBlob = (data) => {
|
|
460
490
|
var _a;
|
|
461
|
-
if ((_a = data.input) === null || _a === void 0 ? void 0 : _a.
|
|
462
|
-
data.input.
|
|
491
|
+
if ((_a = data.input) === null || _a === void 0 ? void 0 : _a.buffer) {
|
|
492
|
+
data.input.buffer = data.input.buffer.slice(0, 100) + '...';
|
|
463
493
|
}
|
|
464
494
|
return data;
|
|
465
495
|
};
|
|
@@ -495,6 +525,22 @@ iter, init, value) => {
|
|
|
495
525
|
return indexes;
|
|
496
526
|
};
|
|
497
527
|
exports.generateIndexes = generateIndexes;
|
|
528
|
+
function parseTimeToMs(interval) {
|
|
529
|
+
const match = interval.match(/^(\d+)\s*(s|m|h|d|w|mo)$/);
|
|
530
|
+
if (!match)
|
|
531
|
+
throw new Error(`Invalid interval: ${interval}`);
|
|
532
|
+
const [, valueStr, unit] = match;
|
|
533
|
+
const value = parseInt(valueStr, 10);
|
|
534
|
+
const unitToMs = {
|
|
535
|
+
s: 1000,
|
|
536
|
+
m: 60 * 1000,
|
|
537
|
+
h: 60 * 60 * 1000,
|
|
538
|
+
d: 24 * 60 * 60 * 1000,
|
|
539
|
+
w: 7 * 24 * 60 * 60 * 1000,
|
|
540
|
+
mo: 30 * 24 * 60 * 60 * 1000, // Approximate
|
|
541
|
+
};
|
|
542
|
+
return value * unitToMs[unit];
|
|
543
|
+
}
|
|
498
544
|
const validateStringsInObject = (obj) => {
|
|
499
545
|
let isValid = true;
|
|
500
546
|
const invalidPrefixes = ['$Input{', '$Sequence{', '$Size{', '$Length{'];
|
|
@@ -904,12 +950,37 @@ function anonymizeObject(obj) {
|
|
|
904
950
|
return anonymized;
|
|
905
951
|
}
|
|
906
952
|
function anonymizeValue(value) {
|
|
953
|
+
const [localPart, domainPart] = value.split("@");
|
|
954
|
+
if (!localPart || !domainPart) {
|
|
955
|
+
throw new Error("Invalid email format");
|
|
956
|
+
}
|
|
957
|
+
// Mask Local Part (Username)
|
|
958
|
+
const localSegments = localPart.split(".");
|
|
959
|
+
const maskedLocal = localSegments
|
|
960
|
+
.map(segment => {
|
|
961
|
+
if (segment.length <= 2)
|
|
962
|
+
return segment[0] + "*";
|
|
963
|
+
return segment[0] + "*".repeat(segment.length - 2) + segment.slice(-1);
|
|
964
|
+
})
|
|
965
|
+
.join(".");
|
|
966
|
+
// Mask Domain Part (e.g., example.com)
|
|
967
|
+
const domainSegments = domainPart.split(".");
|
|
968
|
+
const maskedDomain = domainSegments
|
|
969
|
+
.map(segment => {
|
|
970
|
+
if (segment.length <= 2)
|
|
971
|
+
return segment[0] + "*";
|
|
972
|
+
return segment[0] + "*".repeat(segment.length - 2) + segment.slice(-1);
|
|
973
|
+
})
|
|
974
|
+
.join(".");
|
|
975
|
+
return `${maskedLocal}@${maskedDomain}`;
|
|
976
|
+
}
|
|
977
|
+
// Your existing mask logic, renamed for clarity
|
|
978
|
+
function maskString(value) {
|
|
907
979
|
if (value.length <= 3)
|
|
908
980
|
return '***'; // Short values get fully masked
|
|
909
981
|
const chars = value.split('');
|
|
910
982
|
const maskCount = Math.floor((2 / 3) * chars.length);
|
|
911
983
|
const maskIndexes = new Set();
|
|
912
|
-
// Select random indexes to mask
|
|
913
984
|
while (maskIndexes.size < maskCount) {
|
|
914
985
|
maskIndexes.add(Math.floor(Math.random() * chars.length));
|
|
915
986
|
}
|
|
@@ -918,4 +989,16 @@ function anonymizeValue(value) {
|
|
|
918
989
|
function toFormUrlEncoded(json) {
|
|
919
990
|
return new URLSearchParams(json).toString();
|
|
920
991
|
}
|
|
992
|
+
function extractSelectorValue(schema, stages, selector) {
|
|
993
|
+
let current = schema;
|
|
994
|
+
for (const stage of stages) {
|
|
995
|
+
if (current && typeof current === 'object' && stage in current) {
|
|
996
|
+
current = current[stage];
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
throw new Error(`${selector} not found in event sample`);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return current;
|
|
1003
|
+
}
|
|
921
1004
|
//# sourceMappingURL=processor.utils.js.map
|