@universis/janitor 1.4.1 → 1.6.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/README.md +48 -0
- package/dist/OAuth2ClientService.d.ts +98 -0
- package/dist/OAuth2ClientService.js +251 -0
- package/dist/OAuth2ClientService.js.map +1 -0
- package/dist/RedisClientStore.js +20 -36
- package/dist/RedisClientStore.js.map +1 -1
- package/dist/RemoteAddressValidator.d.ts +10 -0
- package/dist/RemoteAddressValidator.js +88 -0
- package/dist/RemoteAddressValidator.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/src/OAuth2ClientService.d.ts +98 -0
- package/src/OAuth2ClientService.js +255 -0
- package/src/RedisClientStore.js +20 -36
- package/src/RemoteAddressValidator.d.ts +10 -0
- package/src/RemoteAddressValidator.js +92 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
package/README.md
CHANGED
|
@@ -295,3 +295,51 @@ app.use('/api', passport.authenticate('bearer', {session: false}), validateScope
|
|
|
295
295
|
```
|
|
296
296
|
|
|
297
297
|
A `403 - Access denied due to authorization scopes` error will be thrown if the user does not have access to the resource.
|
|
298
|
+
|
|
299
|
+
## RemoteAddressValidator
|
|
300
|
+
|
|
301
|
+
`RemoteAddressValidator` is a configurable application service for validating access to service endpoints based on remote address provided by OAuth2 token.
|
|
302
|
+
|
|
303
|
+
Register service under application services:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"services": [
|
|
308
|
+
{
|
|
309
|
+
"serviceType": "@universis/janitor#RemoteAddressValidator"
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
`RemoteAddressValidator` validates the remote address of the request with the remote address provided by the OAuth2 token. If the addresses do not match, a `403 - Access denied due to remote address` error will be thrown. Token remote address is provided by the `remoteAddress` claim in the token payload. It can be configured in the OAuth2 server configuration and may have a different name. This name may be configured in the `settings/universis/janitor/remoteAddress` configuration e.g.
|
|
316
|
+
|
|
317
|
+
```json
|
|
318
|
+
{
|
|
319
|
+
"settings": {
|
|
320
|
+
"universis": {
|
|
321
|
+
"janitor": {
|
|
322
|
+
"remoteAddress": {
|
|
323
|
+
"claim": "ipAddress"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
where `claim` is the name of the remote address claim in the token payload.
|
|
332
|
+
|
|
333
|
+
**Important Note**: If api server is served by a proxy, the remote address may be different from the client address. In this case, the proxy should be configured to forward the client address to the server. This scenario should be configured in application settings under `settings/universis/api/` section e.g.
|
|
334
|
+
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"settings": {
|
|
338
|
+
"universis": {
|
|
339
|
+
"api": {
|
|
340
|
+
"proxyAddressForwarding": true
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
```
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ApplicationService, ApplicationBase } from '@themost/common';
|
|
2
|
+
import { DataContext } from '@themost/data';
|
|
3
|
+
|
|
4
|
+
export declare interface OAuth2MethodOptions {
|
|
5
|
+
access_token: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare interface OAuth2AuthorizeUser {
|
|
9
|
+
client_id?: string;
|
|
10
|
+
client_secret?: string;
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
grant_type: string;
|
|
14
|
+
scope?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare interface OAuth2ServiceSettings {
|
|
18
|
+
unattendedExecutionAccount?: string;
|
|
19
|
+
client_id: string;
|
|
20
|
+
client_secret?: string;
|
|
21
|
+
server_uri: string;
|
|
22
|
+
userinfo_uri?: string;
|
|
23
|
+
introspect_uri?: string;
|
|
24
|
+
admin_uri?: string;
|
|
25
|
+
well_known_configuration_uri?: string;
|
|
26
|
+
adminAccount: {
|
|
27
|
+
username: string;
|
|
28
|
+
password: string;
|
|
29
|
+
client_id: string;
|
|
30
|
+
client_secret?: string;
|
|
31
|
+
scope?: string;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare interface OAuth2UserProfile {
|
|
36
|
+
sub: string;
|
|
37
|
+
name: string;
|
|
38
|
+
preferred_username: string;
|
|
39
|
+
given_name: string;
|
|
40
|
+
family_name: string;
|
|
41
|
+
email: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare interface GenericUser {
|
|
45
|
+
id?: any;
|
|
46
|
+
additionalType?: string;
|
|
47
|
+
alternateName?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
givenName?: string;
|
|
50
|
+
familyName?: string;
|
|
51
|
+
image?: string;
|
|
52
|
+
name?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
dateCreated?: Date;
|
|
55
|
+
dateModified?: Date;
|
|
56
|
+
createdBy?: any;
|
|
57
|
+
modifiedBy?: any;
|
|
58
|
+
lockoutTime?: Date;
|
|
59
|
+
logonCount?: number;
|
|
60
|
+
enabled?: boolean;
|
|
61
|
+
lastLogon?: Date;
|
|
62
|
+
userCredentials?: {
|
|
63
|
+
userPassword?: string;
|
|
64
|
+
userActivated?: boolean;
|
|
65
|
+
temporary?: boolean;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare interface OAuth2User {
|
|
70
|
+
id?: any;
|
|
71
|
+
username?: string;
|
|
72
|
+
email?: string;
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
emailVerified?: boolean;
|
|
75
|
+
firstName?: string;
|
|
76
|
+
lastName?: string;
|
|
77
|
+
credentials?: {
|
|
78
|
+
algorithm?: string,
|
|
79
|
+
temporary?: boolean,
|
|
80
|
+
type?: string,
|
|
81
|
+
value?: string
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export declare class OAuth2ClientService extends ApplicationService {
|
|
86
|
+
get settings(): OAuth2ServiceSettings;
|
|
87
|
+
constructor(app: ApplicationBase)
|
|
88
|
+
getUserInfo(context: DataContext, token: string): Promise<OAuth2UserProfile>;
|
|
89
|
+
getTokenInfo(context: DataContext, token: string): Promise<any>;
|
|
90
|
+
getContextTokenInfo(context: DataContext): Promise<any>;
|
|
91
|
+
authorize(authorizeUser: OAuth2AuthorizeUser): Promise<{ access_token?: string, refresh_token?: string}>;
|
|
92
|
+
getUser(username: string, options: OAuth2MethodOptions): Promise<any>;
|
|
93
|
+
getUserById(user_id: any, options: OAuth2MethodOptions): Promise<any>;
|
|
94
|
+
getUserByEmail(email: string, options: OAuth2MethodOptions): Promise<any>;
|
|
95
|
+
updateUser(user: GenericUser | any, options: OAuth2MethodOptions): Promise<any>;
|
|
96
|
+
createUser(user: GenericUser | any, options: OAuth2MethodOptions): Promise<any>;
|
|
97
|
+
deleteUser(user: { id: any }, options: OAuth2MethodOptions): Promise<any>;
|
|
98
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.OAuth2ClientService = void 0;var _superagent = require("superagent");
|
|
2
|
+
var _url = require("url");
|
|
3
|
+
var _common = require("@themost/common");
|
|
4
|
+
|
|
5
|
+
function responseHander(resolve, reject) {
|
|
6
|
+
return function (err, response) {
|
|
7
|
+
if (err) {
|
|
8
|
+
/**
|
|
9
|
+
* @type {import('superagent').Response}
|
|
10
|
+
*/
|
|
11
|
+
const response = err.response;
|
|
12
|
+
if (response && response.headers['content-type'] === 'application/json') {
|
|
13
|
+
// get body
|
|
14
|
+
const clientError = response.body;
|
|
15
|
+
const error = new _common.HttpError(response.status);
|
|
16
|
+
return reject(Object.assign(error, {
|
|
17
|
+
clientError
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
return reject(err);
|
|
21
|
+
}
|
|
22
|
+
if (response.status === 204 && response.headers['content-type'] === 'application/json') {
|
|
23
|
+
return resolve(null);
|
|
24
|
+
}
|
|
25
|
+
return resolve(response.body);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @class
|
|
31
|
+
*/
|
|
32
|
+
class OAuth2ClientService extends _common.ApplicationService {
|
|
33
|
+
/**
|
|
34
|
+
* @param {import('@themost/express').ExpressDataApplication} app
|
|
35
|
+
*/
|
|
36
|
+
constructor(app) {
|
|
37
|
+
super(app);
|
|
38
|
+
/**
|
|
39
|
+
* @name OAuth2ClientService#settings
|
|
40
|
+
* @type {{server_uri:string,token_uri?:string}}
|
|
41
|
+
*/
|
|
42
|
+
Object.defineProperty(this, 'settings', {
|
|
43
|
+
writable: false,
|
|
44
|
+
value: app.getConfiguration().getSourceAt('settings/auth'),
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: false
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets keycloak server root
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
getServer() {
|
|
55
|
+
return this.settings.server_uri;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Gets keycloak server root
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
getAdminRoot() {
|
|
63
|
+
return this.settings.admin_uri;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// noinspection JSUnusedGlobalSymbols
|
|
67
|
+
/**
|
|
68
|
+
* Gets user's profile by calling OAuth2 server profile endpoint
|
|
69
|
+
* @param {ExpressDataContext} context
|
|
70
|
+
* @param {string} token
|
|
71
|
+
*/
|
|
72
|
+
getUserInfo(token) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const userinfo_uri = this.settings.userinfo_uri ? new _url.URL(this.settings.userinfo_uri, this.getServer()) : new _url.URL('me', this.getServer());
|
|
75
|
+
return new _superagent.Request('GET', userinfo_uri).
|
|
76
|
+
set({
|
|
77
|
+
'Authorization': `Bearer ${token}`,
|
|
78
|
+
'Accept': 'application/json'
|
|
79
|
+
}).
|
|
80
|
+
query({
|
|
81
|
+
'access_token': token
|
|
82
|
+
}).end(responseHander(resolve, reject));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// noinspection JSUnusedGlobalSymbols
|
|
87
|
+
/**
|
|
88
|
+
* Gets the token info of the current context
|
|
89
|
+
* @param {ExpressDataContext} context
|
|
90
|
+
*/
|
|
91
|
+
getContextTokenInfo(context) {
|
|
92
|
+
if (context.user == null) {
|
|
93
|
+
return Promise.reject(new Error('Context user may not be null'));
|
|
94
|
+
}
|
|
95
|
+
if (context.user.authenticationType !== 'Bearer') {
|
|
96
|
+
return Promise.reject(new Error('Invalid context authentication type'));
|
|
97
|
+
}
|
|
98
|
+
if (context.user.authenticationToken == null) {
|
|
99
|
+
return Promise.reject(new Error('Context authentication data may not be null'));
|
|
100
|
+
}
|
|
101
|
+
return this.getTokenInfo(context, context.user.authenticationToken);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gets token info by calling OAuth2 server endpoint
|
|
105
|
+
* @param {ExpressDataContext} _context
|
|
106
|
+
* @param {string} token
|
|
107
|
+
*/
|
|
108
|
+
getTokenInfo(_context, token) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const introspection_uri = this.settings.introspection_uri ? new _url.URL(this.settings.introspection_uri, this.getServer()) : new _url.URL('tokeninfo', this.getServer());
|
|
111
|
+
return new _superagent.Request('POST', introspection_uri).
|
|
112
|
+
auth(this.settings.client_id, this.settings.client_secret).
|
|
113
|
+
set('Accept', 'application/json').
|
|
114
|
+
type('form').
|
|
115
|
+
send({
|
|
116
|
+
'token_type_hint': 'access_token',
|
|
117
|
+
'token': token
|
|
118
|
+
}).end(responseHander(resolve, reject));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {AuthorizeUser} authorizeUser
|
|
124
|
+
*/
|
|
125
|
+
authorize(authorizeUser) {
|
|
126
|
+
const tokenURL = this.settings.token_uri ? new _url.URL(this.settings.token_uri) : new _url.URL('authorize', this.getServer());
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
return new _superagent.Request('POST', tokenURL).
|
|
129
|
+
type('form').
|
|
130
|
+
send(authorizeUser).end(responseHander(resolve, reject));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Gets a user by name
|
|
136
|
+
* @param {*} user_id
|
|
137
|
+
* @param {AdminMethodOptions} options
|
|
138
|
+
*/
|
|
139
|
+
getUserById(user_id, options) {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
return new _superagent.Request('GET', new _url.URL(`users/${user_id}`, this.getAdminRoot())).
|
|
142
|
+
set('Authorization', `Bearer ${options.access_token}`).
|
|
143
|
+
end(responseHander(resolve, reject));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Gets a user by name
|
|
149
|
+
* @param {string} username
|
|
150
|
+
* @param {AdminMethodOptions} options
|
|
151
|
+
*/
|
|
152
|
+
getUser(username, options) {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
return new _superagent.Request('GET', new _url.URL('users', this.getAdminRoot())).
|
|
155
|
+
set('Authorization', `Bearer ${options.access_token}`).
|
|
156
|
+
query({
|
|
157
|
+
'$filter': `name eq '${username}'`
|
|
158
|
+
}).
|
|
159
|
+
end(responseHander(resolve, reject));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Gets a user by email address
|
|
165
|
+
* @param {string} email
|
|
166
|
+
* @param {AdminMethodOptions} options
|
|
167
|
+
*/
|
|
168
|
+
getUserByEmail(email, options) {
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
return new _superagent.Request('GET', new _url.URL('users', this.getAdminRoot())).
|
|
171
|
+
set('Authorization', `Bearer ${options.access_token}`).
|
|
172
|
+
query({
|
|
173
|
+
'$filter': `alternateName eq '${email}'`
|
|
174
|
+
}).
|
|
175
|
+
end(responseHander(resolve, reject));
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Updates an existing user
|
|
181
|
+
* @param {*} user
|
|
182
|
+
* @param {AdminMethodOptions} options
|
|
183
|
+
*/
|
|
184
|
+
updateUser(user, options) {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
if (user.id == null) {
|
|
187
|
+
return reject(new _common.DataError('E_IDENTIFIER', 'User may not be empty at this context.', null, 'User', 'id'));
|
|
188
|
+
}
|
|
189
|
+
const request = new _superagent.Request('PUT', new _url.URL(`users/${user.id}`, this.getAdminRoot()));
|
|
190
|
+
return request.set('Authorization', `Bearer ${options.access_token}`).
|
|
191
|
+
set('Content-Type', 'application/json').
|
|
192
|
+
send(user).
|
|
193
|
+
end(responseHander(resolve, reject));
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Creates a new user
|
|
199
|
+
* @param {*} user
|
|
200
|
+
* @param {AdminMethodOptions} options
|
|
201
|
+
*/
|
|
202
|
+
createUser(user, options) {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
const request = new _superagent.Request('POST', new _url.URL('users', this.getAdminRoot()));
|
|
205
|
+
return request.set('Authorization', `Bearer ${options.access_token}`).
|
|
206
|
+
set('Content-Type', 'application/json').
|
|
207
|
+
send(Object.assign({}, user, {
|
|
208
|
+
$state: 1 // for create
|
|
209
|
+
})).
|
|
210
|
+
end(responseHander(resolve, reject));
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Deletes a user
|
|
216
|
+
* @param {{id: any}} user
|
|
217
|
+
* @param {AdminMethodOptions} options
|
|
218
|
+
*/
|
|
219
|
+
deleteUser(user, options) {
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
if (user.id == null) {
|
|
222
|
+
return reject(new _common.DataError('E_IDENTIFIER', 'User may not be empty at this context.', null, 'User', 'id'));
|
|
223
|
+
}
|
|
224
|
+
const request = new _superagent.Request('DELETE', new _url.URL(`users/${user.id}`, this.getAdminRoot()));
|
|
225
|
+
return request.set('Authorization', `Bearer ${options.access_token}`).
|
|
226
|
+
end(responseHander(resolve, reject));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @param {boolean=} force
|
|
232
|
+
* @returns {*}
|
|
233
|
+
*/
|
|
234
|
+
getWellKnownConfiguration(force) {
|
|
235
|
+
if (force) {
|
|
236
|
+
this.well_known_configuration = null;
|
|
237
|
+
}
|
|
238
|
+
if (this.well_known_configuration) {
|
|
239
|
+
return Promise.resolve(this.well_known_configuration);
|
|
240
|
+
}
|
|
241
|
+
return new Promise((resolve, reject) => {
|
|
242
|
+
const well_known_configuration_uri = this.settings.well_known_configuration_uri ? new _url.URL(this.settings.well_known_configuration_uri, this.getServer()) : new _url.URL('.well-known/openid-configuration', this.getServer());
|
|
243
|
+
return new _superagent.Request('GET', well_known_configuration_uri).
|
|
244
|
+
end(responseHander(resolve, reject));
|
|
245
|
+
}).then((configuration) => {
|
|
246
|
+
this.well_known_configuration = configuration;
|
|
247
|
+
return configuration;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}exports.OAuth2ClientService = OAuth2ClientService;
|
|
251
|
+
//# sourceMappingURL=OAuth2ClientService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuth2ClientService.js","names":["_superagent","require","_url","_common","responseHander","resolve","reject","err","response","headers","clientError","body","error","HttpError","status","Object","assign","OAuth2ClientService","ApplicationService","constructor","app","defineProperty","writable","value","getConfiguration","getSourceAt","enumerable","configurable","getServer","settings","server_uri","getAdminRoot","admin_uri","getUserInfo","token","Promise","userinfo_uri","URL","Request","set","query","end","getContextTokenInfo","context","user","Error","authenticationType","authenticationToken","getTokenInfo","_context","introspection_uri","auth","client_id","client_secret","type","send","authorize","authorizeUser","tokenURL","token_uri","getUserById","user_id","options","access_token","getUser","username","getUserByEmail","email","updateUser","id","DataError","request","createUser","$state","deleteUser","getWellKnownConfiguration","force","well_known_configuration","well_known_configuration_uri","then","configuration","exports"],"sources":["../src/OAuth2ClientService.js"],"sourcesContent":["import {Request} from 'superagent'\nimport {URL} from 'url';\nimport {ApplicationService, DataError, HttpError} from '@themost/common';\n\nfunction responseHander(resolve, reject) {\n return function (err, response) {\n if (err) {\n /**\n * @type {import('superagent').Response}\n */\n const response = err.response\n if (response && response.headers['content-type'] === 'application/json') {\n // get body\n const clientError = response.body;\n const error = new HttpError(response.status);\n return reject(Object.assign(error, {\n clientError\n }));\n }\n return reject(err);\n }\n if (response.status === 204 && response.headers['content-type'] === 'application/json') {\n return resolve(null);\n }\n return resolve(response.body);\n };\n}\n\n/**\n * @class\n */\nclass OAuth2ClientService extends ApplicationService {\n /**\n * @param {import('@themost/express').ExpressDataApplication} app\n */\n constructor(app) {\n super(app);\n /**\n * @name OAuth2ClientService#settings\n * @type {{server_uri:string,token_uri?:string}}\n */\n Object.defineProperty(this, 'settings', {\n writable: false,\n value: app.getConfiguration().getSourceAt('settings/auth'),\n enumerable: false,\n configurable: false\n });\n }\n\n /**\n * Gets keycloak server root\n * @returns {string}\n */\n getServer() {\n return this.settings.server_uri;\n }\n\n /**\n * Gets keycloak server root\n * @returns {string}\n */\n getAdminRoot() {\n return this.settings.admin_uri;\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * Gets user's profile by calling OAuth2 server profile endpoint\n * @param {ExpressDataContext} context\n * @param {string} token\n */\n getUserInfo(token) {\n return new Promise((resolve, reject) => {\n const userinfo_uri = this.settings.userinfo_uri ? new URL(this.settings.userinfo_uri, this.getServer()) : new URL('me', this.getServer());\n return new Request('GET', userinfo_uri)\n .set({\n 'Authorization': `Bearer ${token}`,\n 'Accept': 'application/json'\n })\n .query({\n 'access_token':token\n }).end(responseHander(resolve, reject));\n });\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * Gets the token info of the current context\n * @param {ExpressDataContext} context\n */\n getContextTokenInfo(context) {\n if (context.user == null) {\n return Promise.reject(new Error('Context user may not be null'));\n }\n if (context.user.authenticationType !== 'Bearer') {\n return Promise.reject(new Error('Invalid context authentication type'));\n }\n if (context.user.authenticationToken == null) {\n return Promise.reject(new Error('Context authentication data may not be null'));\n }\n return this.getTokenInfo(context, context.user.authenticationToken);\n }\n /**\n * Gets token info by calling OAuth2 server endpoint\n * @param {ExpressDataContext} _context\n * @param {string} token\n */\n getTokenInfo(_context, token) {\n return new Promise((resolve, reject) => {\n const introspection_uri = this.settings.introspection_uri ? new URL(this.settings.introspection_uri, this.getServer()) : new URL('tokeninfo', this.getServer());\n return new Request('POST', introspection_uri)\n .auth(this.settings.client_id, this.settings.client_secret)\n .set('Accept', 'application/json')\n .type('form')\n .send({\n 'token_type_hint': 'access_token',\n 'token': token,\n }).end(responseHander(resolve, reject));\n });\n }\n\n /**\n * @param {AuthorizeUser} authorizeUser\n */\n authorize(authorizeUser) {\n const tokenURL = this.settings.token_uri ? new URL(this.settings.token_uri) : new URL('authorize', this.getServer());\n return new Promise((resolve, reject)=> {\n return new Request('POST', tokenURL)\n .type('form')\n .send(authorizeUser).end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Gets a user by name\n * @param {*} user_id \n * @param {AdminMethodOptions} options \n */\n getUserById(user_id, options) {\n return new Promise((resolve, reject) => {\n return new Request('GET', new URL(`users/${user_id}`, this.getAdminRoot()))\n .set('Authorization', `Bearer ${options.access_token}`)\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Gets a user by name\n * @param {string} username \n * @param {AdminMethodOptions} options \n */\n getUser(username, options) {\n return new Promise((resolve, reject)=> {\n return new Request('GET', new URL('users', this.getAdminRoot()))\n .set('Authorization', `Bearer ${options.access_token}`)\n .query({\n '$filter': `name eq '${username}'`\n })\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Gets a user by email address\n * @param {string} email \n * @param {AdminMethodOptions} options \n */\n getUserByEmail(email, options) {\n return new Promise((resolve, reject)=> {\n return new Request('GET', new URL('users', this.getAdminRoot()))\n .set('Authorization', `Bearer ${options.access_token}`)\n .query({\n '$filter': `alternateName eq '${email}'`\n })\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Updates an existing user\n * @param {*} user \n * @param {AdminMethodOptions} options \n */\n updateUser(user, options) {\n return new Promise((resolve, reject)=> {\n if (user.id == null) {\n return reject(new DataError('E_IDENTIFIER', 'User may not be empty at this context.', null, 'User', 'id'));\n }\n const request = new Request('PUT', new URL(`users/${user.id}`, this.getAdminRoot()));\n return request.set('Authorization', `Bearer ${options.access_token}`)\n .set('Content-Type', 'application/json')\n .send(user)\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Creates a new user\n * @param {*} user \n * @param {AdminMethodOptions} options \n */\n createUser(user, options) {\n return new Promise((resolve, reject)=> {\n const request = new Request('POST', new URL('users', this.getAdminRoot()));\n return request.set('Authorization', `Bearer ${options.access_token}`)\n .set('Content-Type', 'application/json')\n .send(Object.assign({}, user, {\n $state: 1 // for create\n }))\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * Deletes a user\n * @param {{id: any}} user \n * @param {AdminMethodOptions} options \n */\n deleteUser(user, options) {\n return new Promise((resolve, reject)=> {\n if (user.id == null) {\n return reject(new DataError('E_IDENTIFIER', 'User may not be empty at this context.', null, 'User', 'id'));\n }\n const request = new Request('DELETE', new URL(`users/${user.id}`, this.getAdminRoot()));\n return request.set('Authorization', `Bearer ${options.access_token}`)\n .end(responseHander(resolve, reject));\n });\n }\n\n /**\n * @param {boolean=} force \n * @returns {*}\n */\n getWellKnownConfiguration(force) {\n if (force) {\n this.well_known_configuration = null;\n }\n if (this.well_known_configuration) {\n return Promise.resolve(this.well_known_configuration);\n }\n return new Promise((resolve, reject) => {\n const well_known_configuration_uri = this.settings.well_known_configuration_uri ? new URL(this.settings.well_known_configuration_uri, this.getServer()) : new URL('.well-known/openid-configuration', this.getServer());\n return new Request('GET', well_known_configuration_uri)\n .end(responseHander(resolve, reject));\n }).then((configuration) => {\n this.well_known_configuration = configuration;\n return configuration;\n });\n }\n}\n\nexport {\n OAuth2ClientService\n}\n\n"],"mappings":"gHAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;;AAEA,SAASG,cAAcA,CAACC,OAAO,EAAEC,MAAM,EAAE;EACrC,OAAO,UAAUC,GAAG,EAAEC,QAAQ,EAAE;IAC5B,IAAID,GAAG,EAAE;MACL;AACZ;AACA;MACY,MAAMC,QAAQ,GAAGD,GAAG,CAACC,QAAQ;MAC7B,IAAIA,QAAQ,IAAIA,QAAQ,CAACC,OAAO,CAAC,cAAc,CAAC,KAAK,kBAAkB,EAAE;QACrE;QACA,MAAMC,WAAW,GAAGF,QAAQ,CAACG,IAAI;QACjC,MAAMC,KAAK,GAAG,IAAIC,iBAAS,CAACL,QAAQ,CAACM,MAAM,CAAC;QAC5C,OAAOR,MAAM,CAACS,MAAM,CAACC,MAAM,CAACJ,KAAK,EAAE;UAC/BF;QACJ,CAAC,CAAC,CAAC;MACP;MACA,OAAOJ,MAAM,CAACC,GAAG,CAAC;IACtB;IACA,IAAIC,QAAQ,CAACM,MAAM,KAAK,GAAG,IAAIN,QAAQ,CAACC,OAAO,CAAC,cAAc,CAAC,KAAK,kBAAkB,EAAE;MACpF,OAAOJ,OAAO,CAAC,IAAI,CAAC;IACxB;IACA,OAAOA,OAAO,CAACG,QAAQ,CAACG,IAAI,CAAC;EACjC,CAAC;AACL;;AAEA;AACA;AACA;AACA,MA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Object.defineProperty(exports, "__esModule", { value: true });exports.RedisClientStore = void 0;var _common = require("@themost/common");
|
|
2
2
|
var _rateLimitRedis = _interopRequireDefault(require("rate-limit-redis"));
|
|
3
|
-
var
|
|
3
|
+
var _ioredis = require("ioredis");
|
|
4
4
|
require("@themost/promise-sequence");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _defineProperty(obj, key, value) {key = _toPropertyKey(key);if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}function _toPropertyKey(arg) {var key = _toPrimitive(arg, "string");return typeof key === "symbol" ? key : String(key);}function _toPrimitive(input, hint) {if (typeof input !== "object" || input === null) return input;var prim = input[Symbol.toPrimitive];if (prim !== undefined) {var res = prim.call(input, hint || "default");if (typeof res !== "object") return res;throw new TypeError("@@toPrimitive must return a primitive value.");}return (hint === "string" ? String : Number)(input);}
|
|
5
5
|
|
|
6
6
|
let superLoadIncrementScript;
|
|
@@ -46,16 +46,15 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
46
46
|
*/
|
|
47
47
|
sendCommand: function () {
|
|
48
48
|
const args = Array.from(arguments);
|
|
49
|
+
const [command] = args.splice(0, 1);
|
|
49
50
|
const self = this;
|
|
50
|
-
if (
|
|
51
|
+
if (command === 'SCRIPT') {
|
|
51
52
|
const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {
|
|
52
53
|
host: '127.0.0.1',
|
|
53
54
|
port: 6379
|
|
54
55
|
};
|
|
55
|
-
const client =
|
|
56
|
-
return client.
|
|
57
|
-
return client.sendCommand(args);
|
|
58
|
-
}).catch((error) => {
|
|
56
|
+
const client = new _ioredis.Redis(connectOptions);
|
|
57
|
+
return client.call(command, args).catch((error) => {
|
|
59
58
|
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
60
59
|
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
61
60
|
}
|
|
@@ -73,45 +72,30 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
73
72
|
host: '127.0.0.1',
|
|
74
73
|
port: 6379
|
|
75
74
|
};
|
|
76
|
-
self.client =
|
|
77
|
-
// handle socket close error
|
|
78
|
-
self.client.on('error', (err) => {
|
|
79
|
-
_common.TraceUtils.error('An error occurred while using redis client as speed limit service client store.');
|
|
80
|
-
_common.TraceUtils.error(err);
|
|
81
|
-
// handle socket close error
|
|
82
|
-
if (err.message === 'Socket closed unexpectedly') {
|
|
83
|
-
_common.TraceUtils.info('Socket closed unexpectedly. Disconnecting...');
|
|
84
|
-
// delete increment script sha
|
|
85
|
-
self.incrementScriptSha = null;
|
|
86
|
-
// quit client
|
|
87
|
-
self.client.disconnect();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
75
|
+
self.client = new _ioredis.Redis(connectOptions);
|
|
90
76
|
}
|
|
91
77
|
if (self.client.isOpen) {
|
|
92
|
-
return self.client.
|
|
78
|
+
return self.client.call(command, args).catch((error) => {
|
|
93
79
|
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
94
80
|
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
95
81
|
}
|
|
96
82
|
return Promise.reject(error);
|
|
97
83
|
});
|
|
98
84
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
85
|
+
// send load script commands once
|
|
86
|
+
return (() => {
|
|
87
|
+
if (self.incrementScriptSha == null) {
|
|
88
|
+
return this.postInit();
|
|
89
|
+
}
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
})().then(() => {
|
|
92
|
+
// send command
|
|
93
|
+
args[0] = self.incrementScriptSha;
|
|
94
|
+
return self.client.call(command, args).catch((error) => {
|
|
95
|
+
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
96
|
+
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
104
97
|
}
|
|
105
|
-
return Promise.
|
|
106
|
-
})().then(() => {
|
|
107
|
-
// send command
|
|
108
|
-
args[1] = self.incrementScriptSha;
|
|
109
|
-
return self.client.sendCommand(args).catch((error) => {
|
|
110
|
-
if (error instanceof TypeError && error.message === 'Invalid argument type') {
|
|
111
|
-
_common.TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));
|
|
112
|
-
}
|
|
113
|
-
return Promise.reject(error);
|
|
114
|
-
});
|
|
98
|
+
return Promise.reject(error);
|
|
115
99
|
});
|
|
116
100
|
});
|
|
117
101
|
}
|
|
@@ -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","superLoadGetScript","noLoadGetScript","noLoadIncrementScript","RedisStore","prototype","loadIncrementScript","name","loadGetScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","self","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","createClient","connect","then","catch","error","message","TraceUtils","warn","JSON","stringify","Promise","reject","finally","isOpen","disconnect","errDisconnect","on","err","info","incrementScriptSha","postInit","resolve","init","debug","getScriptSha","sequence","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { createClient } from 'redis';\nimport '@themost/promise-sequence';\n\nlet superLoadIncrementScript;\nlet superLoadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (RedisStore.prototype.loadIncrementScript.name === 'loadIncrementScript') {\n // get super method for future use\n superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (RedisStore.prototype.loadGetScript.name === 'loadGetScript') {\n // get super method\n superLoadGetScript = RedisStore.prototype.loadGetScript;\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 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 client.disconnect().catch((errDisconnect) => {\n TraceUtils.error(errDisconnect);\n });\n }\n });\n }\n if (self.client == null) {\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 // handle socket close error\n self.client.on('error', (err) => {\n TraceUtils.error('An error occurred while using redis client as speed limit service client store.');\n TraceUtils.error(err);\n // handle socket close error\n if (err.message === 'Socket closed unexpectedly') {\n TraceUtils.info('Socket closed unexpectedly. Disconnecting...');\n // delete increment script sha\n self.incrementScriptSha = null;\n // quit client\n self.client.disconnect();\n }\n });\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 return self.client.connect().then(() => {\n // send load script commands once\n return (() => {\n if (self.incrementScriptSha == null) {\n return this.postInit();\n }\n return Promise.resolve();\n })().then(() => {\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 TraceUtils.debug('RedisClientStore: Starting up and loading increment and get scripts.');\n void this.postInit().then(() => {\n TraceUtils.debug('RedisClientStore: Successfully loaded increment and get scripts.');\n }).catch((err) => {\n TraceUtils.error('RedisClientStore: Failed to load increment and get scripts.');\n TraceUtils.error(err);\n });\n }\n async postInit() {\n const [incrementScriptSha, getScriptSha] = await Promise.sequence([\n () => superLoadIncrementScript.call(this),\n () => superLoadGetScript.call(this)\n ]);\n this.incrementScriptSha = incrementScriptSha;\n this.getScriptSha = getScriptSha;\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;AACAA,OAAA,8BAAmC,SAAAE,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA,aAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,GAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,MAAAA,GAAA,IAAAJ,GAAA,GAAAO,MAAA,CAAAC,cAAA,CAAAR,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,kBAAAX,GAAA,CAAAI,GAAA,IAAAC,KAAA,SAAAL,GAAA,WAAAM,eAAAM,GAAA,OAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,0BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA,YAAAS,aAAAE,KAAA,EAAAC,IAAA,cAA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CAACC,SAAS,CAACrB,IAAI,CAAC,CAAC;cACvF;cACA,OAAOsB,OAAO,CAACC,MAAM,CAACP,KAAK,CAAC;YAChC,CAAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,CAAC,CAvFP;AACJ;AACA,OAFIpD,eAAA,yBAwFI,IAAI,CAACsE,IAAI,CAACpC,OAAO,CAAC,CAClBoB,kBAAU,CAACiB,KAAK,CAAC,sEAAsE,CAAC;IACxF,KAAK,IAAI,CAACH,QAAQ,EAAE,CAAClB,IAAI,CAAC,MAAM;MAC5BI,kBAAU,CAACiB,KAAK,CAAC,kEAAkE,CAAC;IACxF,CAAC,CAAC,CAACpB,KAAK,CAAC,CAACc,GAAG,KAAK;MACdX,kBAAU,CAACF,KAAK,CAAC,6DAA6D,CAAC;MAC/EE,kBAAU,CAACF,KAAK,CAACa,GAAG,CAAC;IACzB,CAAC,CAAC;EACN;EACA,MAAMG,QAAQA,CAAA,EAAG;IACb,MAAM,CAACD,kBAAkB,EAAEK,YAAY,CAAC,GAAG,MAAMd,OAAO,CAACe,QAAQ,CAAC;IAC9D,MAAMnD,wBAAwB,CAACH,IAAI,CAAC,IAAI,CAAC;IACzC,MAAMI,kBAAkB,CAACJ,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;;IACF,IAAI,CAACgD,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACK,YAAY,GAAGA,YAAY;EACpC;;AAEJ,CAACE,OAAA,CAAA3C,gBAAA,GAAAA,gBAAA"}
|
|
1
|
+
{"version":3,"file":"RedisClientStore.js","names":["_common","require","_rateLimitRedis","_interopRequireDefault","_ioredis","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","superLoadGetScript","noLoadGetScript","noLoadIncrementScript","RedisStore","prototype","loadIncrementScript","name","loadGetScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","command","splice","self","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","Redis","catch","error","message","TraceUtils","warn","JSON","stringify","Promise","reject","finally","isOpen","disconnect","errDisconnect","incrementScriptSha","postInit","resolve","then","init","debug","err","getScriptSha","sequence","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { Redis } from 'ioredis';\nimport '@themost/promise-sequence';\n\nlet superLoadIncrementScript;\nlet superLoadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (RedisStore.prototype.loadIncrementScript.name === 'loadIncrementScript') {\n // get super method for future use\n superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (RedisStore.prototype.loadGetScript.name === 'loadGetScript') {\n // get super method\n superLoadGetScript = RedisStore.prototype.loadGetScript;\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 [command] = args.splice(0, 1);\n const self = this;\n if (command === 'SCRIPT') {\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n const client = new Redis(connectOptions);\n return client.call(command, 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 }).finally(() => {\n if (client.isOpen) {\n client.disconnect().catch((errDisconnect) => {\n TraceUtils.error(errDisconnect);\n });\n }\n });\n }\n if (self.client == null) {\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n self.client = new Redis(connectOptions);\n }\n if (self.client.isOpen) {\n return self.client.call(command, 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 // send load script commands once\n return (() => {\n if (self.incrementScriptSha == null) {\n return this.postInit();\n }\n return Promise.resolve();\n })().then(() => {\n // send command \n args[0] = self.incrementScriptSha;\n return self.client.call(command, 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 this.init(options);\n TraceUtils.debug('RedisClientStore: Starting up and loading increment and get scripts.');\n void this.postInit().then(() => {\n TraceUtils.debug('RedisClientStore: Successfully loaded increment and get scripts.');\n }).catch((err) => {\n TraceUtils.error('RedisClientStore: Failed to load increment and get scripts.');\n TraceUtils.error(err);\n });\n }\n async postInit() {\n const [incrementScriptSha, getScriptSha] = await Promise.sequence([\n () => superLoadIncrementScript.call(this),\n () => superLoadGetScript.call(this)\n ]);\n this.incrementScriptSha = incrementScriptSha;\n this.getScriptSha = getScriptSha;\n }\n\n}\n\nexport {\n RedisClientStore\n}"],"mappings":"6GAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACAA,OAAA,8BAAmC,SAAAE,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA,aAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,GAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,MAAAA,GAAA,IAA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AC;QACN,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,CAAC,CAvEP;AACJ;AACA,OAFIpD,eAAA,yBAwEI,IAAI,CAACoE,IAAI,CAAClC,OAAO,CAAC,CAClBoB,kBAAU,CAACe,KAAK,CAAC,sEAAsE,CAAC;IACxF,KAAK,IAAI,CAACJ,QAAQ,EAAE,CAACE,IAAI,CAAC,MAAM;MAC5Bb,kBAAU,CAACe,KAAK,CAAC,kEAAkE,CAAC;IACxF,CAAC,CAAC,CAAClB,KAAK,CAAC,CAACmB,GAAG,KAAK;MACdhB,kBAAU,CAACF,KAAK,CAAC,6DAA6D,CAAC;MAC/EE,kBAAU,CAACF,KAAK,CAACkB,GAAG,CAAC;IACzB,CAAC,CAAC;EACN;EACA,MAAML,QAAQA,CAAA,EAAG;IACb,MAAM,CAACD,kBAAkB,EAAEO,YAAY,CAAC,GAAG,MAAMb,OAAO,CAACc,QAAQ,CAAC;IAC9D,MAAMlD,wBAAwB,CAACH,IAAI,CAAC,IAAI,CAAC;IACzC,MAAMI,kBAAkB,CAACJ,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;;IACF,IAAI,CAAC6C,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACO,YAAY,GAAGA,YAAY;EACpC;;AAEJ,CAACE,OAAA,CAAA1C,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApplicationService } from '@themost/common';
|
|
2
|
+
import { Request } from 'express';
|
|
3
|
+
|
|
4
|
+
export declare class RemoteAddressValidator extends ApplicationService {
|
|
5
|
+
|
|
6
|
+
constructor(app: ApplicationService);
|
|
7
|
+
validateRemoteAddress(request: Request): Promise<boolean>;
|
|
8
|
+
getRemoteAddress(request: Request): string;
|
|
9
|
+
|
|
10
|
+
}
|