@universis/janitor 1.1.0 → 1.2.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/dist/RedisClientStore.js
CHANGED
|
@@ -52,7 +52,9 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
52
52
|
return client.connect().then(() => {
|
|
53
53
|
return client.sendCommand(args);
|
|
54
54
|
}).catch((error) => {
|
|
55
|
-
|
|
55
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
56
|
+
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
57
|
+
}
|
|
56
58
|
return Promise.reject(error);
|
|
57
59
|
}).finally(() => {
|
|
58
60
|
if (client.isOpen) {
|
|
@@ -72,7 +74,12 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
72
74
|
self.client = (0, _redis.createClient)(connectOptions);
|
|
73
75
|
}
|
|
74
76
|
if (self.client.isOpen) {
|
|
75
|
-
return self.client.sendCommand(args)
|
|
77
|
+
return self.client.sendCommand(args).catch((error) => {
|
|
78
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
79
|
+
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
80
|
+
}
|
|
81
|
+
return Promise.reject(error);
|
|
82
|
+
});
|
|
76
83
|
}
|
|
77
84
|
_common.TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');
|
|
78
85
|
return self.client.connect().then(() => {
|
|
@@ -85,7 +92,12 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
85
92
|
self.getScriptSha = results[1];
|
|
86
93
|
// send command
|
|
87
94
|
args[1] = self.incrementScriptSha;
|
|
88
|
-
return self.client.sendCommand(args)
|
|
95
|
+
return self.client.sendCommand(args).catch((error) => {
|
|
96
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
97
|
+
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
98
|
+
}
|
|
99
|
+
return Promise.reject(error);
|
|
100
|
+
});
|
|
89
101
|
});
|
|
90
102
|
});
|
|
91
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisClientStore.js","names":["_common","require","_rateLimitRedis","_interopRequireDefault","_redis","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","superLoadIncrementScript","RedisStore","prototype","loadIncrementScript","superLoadGetScript","loadGetScript","noLoadGetScript","noLoadIncrementScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","self","TraceUtils","debug","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","createClient","connect","then","catch","error","Promise","reject","finally","isOpen","disconnect","errDisconnect","all","results","incrementScriptSha","getScriptSha","init","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { createClient } from 'redis';\n\nconst superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\nconst superLoadGetScript = RedisStore.prototype.loadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (superLoadIncrementScript != noLoadIncrementScript) {\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (superLoadGetScript != noLoadGetScript) {\n RedisStore.prototype.loadGetScript = noLoadGetScript;\n}\n\nclass RedisClientStore extends RedisStore {\n\n /**\n * @type {import('redis').RedisClientType}\n */\n client;\n\n /**\n * \n * @param {import('@themost/common').ApplicationService} service\n * @param {{windowMs: number}} options\n */\n constructor(service, options) {\n super({\n /**\n * @param {...string} args\n * @returns {Promise<*>}\n */\n sendCommand: function () {\n const args = Array.from(arguments);\n const self = this;\n if (args[0] === 'SCRIPT') {\n TraceUtils.debug('RedisClientStore: Creating new client for sending script command');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n const client = createClient(connectOptions);\n return client.connect().then(() => {\n return client.sendCommand(args);\n }).catch((error) => {\n TraceUtils.
|
|
1
|
+
{"version":3,"file":"RedisClientStore.js","names":["_common","require","_rateLimitRedis","_interopRequireDefault","_redis","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","superLoadIncrementScript","RedisStore","prototype","loadIncrementScript","superLoadGetScript","loadGetScript","noLoadGetScript","noLoadIncrementScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","self","TraceUtils","debug","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","createClient","connect","then","catch","error","message","warn","JSON","stringify","Promise","reject","finally","isOpen","disconnect","errDisconnect","all","results","incrementScriptSha","getScriptSha","init","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { createClient } from 'redis';\n\nconst superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\nconst superLoadGetScript = RedisStore.prototype.loadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (superLoadIncrementScript != noLoadIncrementScript) {\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (superLoadGetScript != noLoadGetScript) {\n RedisStore.prototype.loadGetScript = noLoadGetScript;\n}\n\nclass RedisClientStore extends RedisStore {\n\n /**\n * @type {import('redis').RedisClientType}\n */\n client;\n\n /**\n * \n * @param {import('@themost/common').ApplicationService} service\n * @param {{windowMs: number}} options\n */\n constructor(service, options) {\n super({\n /**\n * @param {...string} args\n * @returns {Promise<*>}\n */\n sendCommand: function () {\n const args = Array.from(arguments);\n const self = this;\n if (args[0] === 'SCRIPT') {\n TraceUtils.debug('RedisClientStore: Creating new client for sending script command');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n const client = createClient(connectOptions);\n return client.connect().then(() => {\n return client.sendCommand(args);\n }).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n }).finally(() => {\n if (client.isOpen) {\n TraceUtils.debug('RedisClientStore: Closing client of sending script command');\n client.disconnect().catch((errDisconnect) => {\n TraceUtils.error(errDisconnect);\n });\n }\n });\n }\n if (self.client == null) {\n TraceUtils.debug('RedisClientStore: Creating store client for sending commands');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n self.client = createClient(connectOptions);\n }\n if (self.client.isOpen) {\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n }\n TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');\n return self.client.connect().then(() => {\n // send load script commands once\n return Promise.all([\n superLoadIncrementScript.call(self),\n superLoadGetScript.call(self)\n ]).then((results) => {\n self.incrementScriptSha = results[0];\n self.getScriptSha = results[1];\n // send command \n args[1] = self.incrementScriptSha;\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n });\n });\n }\n });\n this.init(options)\n \n }\n\n}\n\nexport {\n RedisClientStore\n}"],"mappings":"6GAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA,UAAqC,SAAAE,uBAA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;YAC9B;YACA9B,IAAI,CAAC,CAAC,CAAC,GAAGI,IAAI,CAAC2B,kBAAkB;YACjC,OAAO3B,IAAI,CAACS,MAAM,CAACd,WAAW,CAACC,IAAI,CAAC,CAACiB,KAAK,CAAC,CAACC,KAAK,KAAK;cAClD,IAAIA,KAAK,YAAYjC,SAAS,IAAIiC,KAAK,CAACC,OAAO,KAAK,uBAAuB,EAAE;gBACzEd,kBAAU,CAACe,IAAI,CAAC,2CAA2C,GAAGC,IAAI,CAACC,SAAS,CAACtB,IAAI,CAAC,CAAC;cACvF;cACA,OAAOuB,OAAO,CAACC,MAAM,CAACN,KAAK,CAAC;YAChC,CAAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,CAAC,CA9EP;AACJ;AACA,OAFIrD,eAAA,yBA+EI,IAAI,CAACoE,IAAI,CAACnC,OAAO,CAAC;EAEtB;;AAEJ,CAACoC,OAAA,CAAAvC,gBAAA,GAAAA,gBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universis/janitor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Universis api plugin for rate limiting requests",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"express-rate-limit": "^7.1.1",
|
|
33
33
|
"express-slow-down": "^1.6.0",
|
|
34
|
-
"rate-limit-redis": "^4.
|
|
34
|
+
"rate-limit-redis": "^4.2.0",
|
|
35
35
|
"redis": "^4.6.10"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
package/src/RedisClientStore.js
CHANGED
|
@@ -52,7 +52,9 @@ class RedisClientStore extends RedisStore {
|
|
|
52
52
|
return client.connect().then(() => {
|
|
53
53
|
return client.sendCommand(args);
|
|
54
54
|
}).catch((error) => {
|
|
55
|
-
|
|
55
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
56
|
+
TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
57
|
+
}
|
|
56
58
|
return Promise.reject(error);
|
|
57
59
|
}).finally(() => {
|
|
58
60
|
if (client.isOpen) {
|
|
@@ -72,7 +74,12 @@ class RedisClientStore extends RedisStore {
|
|
|
72
74
|
self.client = createClient(connectOptions);
|
|
73
75
|
}
|
|
74
76
|
if (self.client.isOpen) {
|
|
75
|
-
return self.client.sendCommand(args)
|
|
77
|
+
return self.client.sendCommand(args).catch((error) => {
|
|
78
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
79
|
+
TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
80
|
+
}
|
|
81
|
+
return Promise.reject(error);
|
|
82
|
+
});
|
|
76
83
|
}
|
|
77
84
|
TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');
|
|
78
85
|
return self.client.connect().then(() => {
|
|
@@ -85,7 +92,12 @@ class RedisClientStore extends RedisStore {
|
|
|
85
92
|
self.getScriptSha = results[1];
|
|
86
93
|
// send command
|
|
87
94
|
args[1] = self.incrementScriptSha;
|
|
88
|
-
return self.client.sendCommand(args)
|
|
95
|
+
return self.client.sendCommand(args).catch((error) => {
|
|
96
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
97
|
+
TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
98
|
+
}
|
|
99
|
+
return Promise.reject(error);
|
|
100
|
+
});
|
|
89
101
|
});
|
|
90
102
|
});
|
|
91
103
|
}
|