not-node 6.1.8 → 6.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/index.js
CHANGED
|
@@ -54,3 +54,9 @@ module.exports.Generic = require("./src/generic/index.js");
|
|
|
54
54
|
module.exports.notMetasStyler = require("./src/metas.js");
|
|
55
55
|
//for http headers files, web pages, XHR etc
|
|
56
56
|
module.exports.notHeadersStyler = require("./src/headers.js");
|
|
57
|
+
|
|
58
|
+
/** Interconnect between instances */
|
|
59
|
+
//static interface
|
|
60
|
+
module.exports.notCluster = require("./src/cluster");
|
|
61
|
+
//static provider
|
|
62
|
+
module.exports.notClusterRedisProvider = require("./src/cluster/cluster.redis");
|
package/package.json
CHANGED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const notEnv = require("../env.js");
|
|
2
|
+
const notCommon = require("../common");
|
|
3
|
+
const { error } = require("not-log")(module, "ClusterRedis");
|
|
4
|
+
|
|
5
|
+
module.exports = class notClusterRedisProvider {
|
|
6
|
+
static #clientGetter = null;
|
|
7
|
+
static #clientName = "db.redis";
|
|
8
|
+
static #subscriber = null;
|
|
9
|
+
static #publisher = null;
|
|
10
|
+
|
|
11
|
+
static async setClientName(name) {
|
|
12
|
+
try {
|
|
13
|
+
this.#clientName = name;
|
|
14
|
+
await this.#resetClient();
|
|
15
|
+
} catch (e) {
|
|
16
|
+
error(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static async setClientGetter(getter) {
|
|
21
|
+
try {
|
|
22
|
+
this.#clientGetter = getter;
|
|
23
|
+
await this.#resetClient();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
error(e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static async #resetClient() {
|
|
30
|
+
try {
|
|
31
|
+
if (this.#publisher) {
|
|
32
|
+
await this.#publisher.disconnect();
|
|
33
|
+
this.#publisher = null;
|
|
34
|
+
}
|
|
35
|
+
if (this.#subscriber) {
|
|
36
|
+
await this.#subscriber.disconnect();
|
|
37
|
+
this.#subscriber = null;
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
error(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static #getClient() {
|
|
45
|
+
try {
|
|
46
|
+
if (this.#clientGetter) {
|
|
47
|
+
return this.#clientGetter();
|
|
48
|
+
} else {
|
|
49
|
+
return notEnv.getEnv(this.#clientName);
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
error(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static async #getPublisher() {
|
|
57
|
+
try {
|
|
58
|
+
if (!this.#publisher) {
|
|
59
|
+
this.#publisher = this.#getClient().duplicate();
|
|
60
|
+
await this.#publisher.connect();
|
|
61
|
+
}
|
|
62
|
+
return this.#publisher;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
error(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static async #getSubscriber() {
|
|
69
|
+
try {
|
|
70
|
+
if (!this.#subscriber) {
|
|
71
|
+
this.#subscriber = this.#getClient().duplicate();
|
|
72
|
+
await this.#subscriber.connect();
|
|
73
|
+
}
|
|
74
|
+
return this.#subscriber;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
error(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static #createListener(func) {
|
|
81
|
+
return async (message) => {
|
|
82
|
+
try {
|
|
83
|
+
await notCommon.executeFunctionAsAsync(func, [
|
|
84
|
+
JSON.parse(message),
|
|
85
|
+
]);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
error(e);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static async on(eventName, func) {
|
|
93
|
+
try {
|
|
94
|
+
const listener = this.#createListener(func);
|
|
95
|
+
const subscriber = await this.#getSubscriber();
|
|
96
|
+
await subscriber.subscribe(eventName, listener);
|
|
97
|
+
return listener;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
error(e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static async off(eventName, listener) {
|
|
104
|
+
try {
|
|
105
|
+
const subscriber = await this.#getSubscriber();
|
|
106
|
+
return subscriber.unsubscribe(eventName, listener);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
error(e);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static async emit(eventName, message) {
|
|
113
|
+
try {
|
|
114
|
+
const publisher = await this.#getPublisher();
|
|
115
|
+
return publisher.publish(eventName, JSON.stringify(message));
|
|
116
|
+
} catch (e) {
|
|
117
|
+
error(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { log } = require("not-log")(module, "notCluster");
|
|
2
|
+
const notClusterRedis = require("./cluster.redis.js");
|
|
3
|
+
|
|
4
|
+
module.exports = class notCluster {
|
|
5
|
+
static #provider = notClusterRedis;
|
|
6
|
+
|
|
7
|
+
static setProvider(newProvider) {
|
|
8
|
+
log(
|
|
9
|
+
`Setting new cluster messaging provider: ${newProvider.prototype.constructor.name}`
|
|
10
|
+
);
|
|
11
|
+
this.#provider = newProvider;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static on() {
|
|
15
|
+
return this.#provider.on(...arguments);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static off() {
|
|
19
|
+
return this.#provider.off(...arguments);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static emit() {
|
|
23
|
+
return this.#provider.emit(...arguments);
|
|
24
|
+
}
|
|
25
|
+
};
|
package/src/identity/identity.js
CHANGED
|
@@ -22,16 +22,16 @@ class Identity {
|
|
|
22
22
|
|
|
23
23
|
static setPrimaryRoles(list = []) {
|
|
24
24
|
this.#primaryRoles = [...list];
|
|
25
|
-
this.#providers.forEach((itm) => {
|
|
26
|
-
itm.setPrimaryRoles([...list]);
|
|
25
|
+
Object.keys(this.#providers).forEach((itm) => {
|
|
26
|
+
this.#providers[itm].setPrimaryRoles([...list]);
|
|
27
27
|
});
|
|
28
28
|
return this;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static setSecondaryRoles(list = []) {
|
|
32
32
|
this.#secondaryRoles = [...list];
|
|
33
|
-
this.#providers.forEach((itm) => {
|
|
34
|
-
itm.setSecondaryRoles([...list]);
|
|
33
|
+
Object.keys(this.#providers).forEach((itm) => {
|
|
34
|
+
this.#providers[itm].setSecondaryRoles([...list]);
|
|
35
35
|
});
|
|
36
36
|
return this;
|
|
37
37
|
}
|
|
@@ -13,11 +13,11 @@ module.exports = class IdentityProviderSession {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
static setPrimaryRoles(list = []) {
|
|
16
|
-
|
|
16
|
+
IdentityProviderSession.#getOptions().primaryRoles = [...list];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
static setSecondaryRoles(list = []) {
|
|
20
|
-
|
|
20
|
+
IdentityProviderSession.#getOptions().secondaryRoles = [...list];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
constructor(req) {
|
|
@@ -42,7 +42,11 @@ module.exports = class IdentityProviderSession {
|
|
|
42
42
|
getPrimaryRole() {
|
|
43
43
|
const roles = this.getRole();
|
|
44
44
|
for (let role of roles) {
|
|
45
|
-
if (
|
|
45
|
+
if (
|
|
46
|
+
IdentityProviderSession.#getOptions().primaryRoles.includes(
|
|
47
|
+
role
|
|
48
|
+
)
|
|
49
|
+
) {
|
|
46
50
|
return role;
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -22,11 +22,11 @@ module.exports = class IdentityProviderToken {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
static setPrimaryRoles(list = []) {
|
|
25
|
-
|
|
25
|
+
IdentityProviderToken.#getOptions().primaryRoles = [...list];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
static setSecondaryRoles(list = []) {
|
|
29
|
-
|
|
29
|
+
IdentityProviderToken.#getOptions().secondaryRoles = [...list];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
constructor(req) {
|
|
@@ -186,7 +186,9 @@ module.exports = class IdentityProviderToken {
|
|
|
186
186
|
getPrimaryRole() {
|
|
187
187
|
const roles = this.getRole();
|
|
188
188
|
for (let role of roles) {
|
|
189
|
-
if (
|
|
189
|
+
if (
|
|
190
|
+
IdentityProviderToken.#getOptions().primaryRoles.includes(role)
|
|
191
|
+
) {
|
|
190
192
|
return role;
|
|
191
193
|
}
|
|
192
194
|
}
|