godprotocol 2.2.50 → 2.2.51
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/Godprotocol.js
CHANGED
|
@@ -5,12 +5,16 @@ class GodProtocol {
|
|
|
5
5
|
constructor(config) {
|
|
6
6
|
this.db_config = config.db_config;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// debug(config, "uhh");
|
|
9
9
|
this.api_key = config.api_key;
|
|
10
10
|
this.platform_uri = config.platform_uri;
|
|
11
11
|
this.route_table = new Route_table(this);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
platform_db = async () => {
|
|
15
|
+
return await this.route_table.platform_db();
|
|
16
|
+
};
|
|
17
|
+
|
|
14
18
|
load_services = async (services) => {
|
|
15
19
|
await this.route_table.load_services(services);
|
|
16
20
|
};
|
|
@@ -27,6 +31,14 @@ class GodProtocol {
|
|
|
27
31
|
await this.route_table.load_routes(routes);
|
|
28
32
|
};
|
|
29
33
|
|
|
34
|
+
call = async (route, { headers, body }) => {
|
|
35
|
+
return await version_middleware(
|
|
36
|
+
{ path: route, headers, body },
|
|
37
|
+
null,
|
|
38
|
+
this.route_table,
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
30
42
|
on_request = async (req, res) => {
|
|
31
43
|
await version_middleware(req, res, this.route_table);
|
|
32
44
|
};
|
package/package.json
CHANGED
|
@@ -210,10 +210,11 @@ class Headers extends Services {
|
|
|
210
210
|
handle_security = async (name, request) => {
|
|
211
211
|
let route = await this.get_route(name);
|
|
212
212
|
|
|
213
|
+
console.log(route?.config?.security, "SECURITY FOR ROUTE");
|
|
213
214
|
if (!route?.config?.security?.length) return true;
|
|
214
215
|
|
|
215
216
|
if (!this.check_security(route.config.security, request)) {
|
|
216
|
-
|
|
217
|
+
// debug("Unauthorized access attempt to route:", name);
|
|
217
218
|
return {
|
|
218
219
|
ok: false,
|
|
219
220
|
status: 401,
|
|
@@ -230,12 +231,12 @@ class Headers extends Services {
|
|
|
230
231
|
if (xplatform) {
|
|
231
232
|
val = await this.validate_third_party(xplatform, authorisation);
|
|
232
233
|
} else {
|
|
233
|
-
|
|
234
|
+
// debug(api_key, authorisation);
|
|
234
235
|
val = await this.validate_api_key(api_key, authorisation);
|
|
235
|
-
|
|
236
|
+
// debug(val, "Uhh");
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
|
|
239
|
+
// debug(val);
|
|
239
240
|
if (!val?.ok) {
|
|
240
241
|
return val;
|
|
241
242
|
} else {
|
|
@@ -186,7 +186,7 @@ class Route_table extends Headers {
|
|
|
186
186
|
if (config.schema) {
|
|
187
187
|
let resp = await this.validate(config.schema, payload);
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
// debug("Validation result for route", name, ":", resp);
|
|
190
190
|
|
|
191
191
|
if (!resp.ok) return resp;
|
|
192
192
|
}
|
|
@@ -24,17 +24,17 @@ class Services {
|
|
|
24
24
|
get_token = async (service, id) => {
|
|
25
25
|
let token;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// debug(service, id, "gettok");
|
|
28
28
|
let db = await this.platform_db();
|
|
29
29
|
token = await db.read_cache(
|
|
30
30
|
{ platform_uri: service.uri, id: id.profile || id.platform },
|
|
31
31
|
"token",
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
// debug(token, "in-cache");
|
|
35
35
|
if (token) return token.token;
|
|
36
36
|
try {
|
|
37
|
-
|
|
37
|
+
// debug(this.api_key, gp_services.profile);
|
|
38
38
|
|
|
39
39
|
let ftch = await fetch(`${gp_services.profile}/get_token`, {
|
|
40
40
|
method: "POST",
|
|
@@ -47,9 +47,9 @@ class Services {
|
|
|
47
47
|
body: JSON.stringify({ platform_uri: service.uri, ...id }),
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
// debug("whats it like??");
|
|
51
51
|
token = await ftch.json();
|
|
52
|
-
|
|
52
|
+
// debug(token, "HOOWWW");
|
|
53
53
|
|
|
54
54
|
if (token?.ok) {
|
|
55
55
|
await db.save_cache(
|
|
@@ -121,6 +121,7 @@ class Services {
|
|
|
121
121
|
|
|
122
122
|
handle_webhook_prior = async (req) => {
|
|
123
123
|
let { platform } = req.headers;
|
|
124
|
+
if (!platform) return false;
|
|
124
125
|
|
|
125
126
|
let conf = await this.get_setting(
|
|
126
127
|
platform,
|
|
@@ -162,6 +163,7 @@ class Services {
|
|
|
162
163
|
|
|
163
164
|
handle_webhook_after = async (req, result) => {
|
|
164
165
|
let { platform } = req.headers;
|
|
166
|
+
if (!platform) return false;
|
|
165
167
|
|
|
166
168
|
let conf = await this.get_setting(
|
|
167
169
|
platform,
|
|
@@ -275,7 +277,7 @@ class Services {
|
|
|
275
277
|
resolve_db = async (req) => {
|
|
276
278
|
const { platform } = req.headers;
|
|
277
279
|
|
|
278
|
-
|
|
280
|
+
// debug(req.headers["x-api-key"], process.env.API_KEY);
|
|
279
281
|
// 🔹 Internal system call → use base DB
|
|
280
282
|
if (req.headers["x-api-key"] === process.env.API_KEY) {
|
|
281
283
|
const db = await this.platform_db();
|
|
@@ -7,6 +7,8 @@ const respond = async (result, res) => {
|
|
|
7
7
|
if (result.pagination) response.pagination = result.pagination;
|
|
8
8
|
if (result.token) response.token = result.token;
|
|
9
9
|
|
|
10
|
+
if (!res) return response;
|
|
11
|
+
|
|
10
12
|
res.status(result?.status || (result?.ok ? 200 : 403)).json(response);
|
|
11
13
|
};
|
|
12
14
|
|
|
@@ -32,6 +34,7 @@ const version_middleware = async (req, res, routers) => {
|
|
|
32
34
|
|
|
33
35
|
try {
|
|
34
36
|
result = await router.handle_security(name, req);
|
|
37
|
+
// console.log("Security check result:", result);
|
|
35
38
|
|
|
36
39
|
if (result !== true) {
|
|
37
40
|
return await respond(result, res);
|
|
@@ -45,9 +48,12 @@ const version_middleware = async (req, res, routers) => {
|
|
|
45
48
|
let db = await router.resolve_db(req);
|
|
46
49
|
let is_webhook = req.headers["is-webhook"];
|
|
47
50
|
|
|
51
|
+
// console.log(req.headers);
|
|
48
52
|
if (!is_webhook) {
|
|
49
53
|
let web_prior = await router.handle_webhook_prior(req);
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
if (web_prior === false) {
|
|
56
|
+
} else if (!web_prior?.ok) {
|
|
51
57
|
return await respond(web_prior, res);
|
|
52
58
|
} else {
|
|
53
59
|
req.headers.webhook_prior = web_prior;
|
|
@@ -58,13 +64,14 @@ const version_middleware = async (req, res, routers) => {
|
|
|
58
64
|
result = await router.execute(name, {
|
|
59
65
|
body: req.body,
|
|
60
66
|
headers: req.headers,
|
|
61
|
-
db,
|
|
67
|
+
db: db.db,
|
|
68
|
+
gp: router.gp,
|
|
62
69
|
services: router.get_service,
|
|
63
70
|
});
|
|
64
71
|
|
|
65
72
|
!is_webhook && (await router.handle_webhook_after(req, result));
|
|
66
73
|
|
|
67
|
-
await respond(result, res);
|
|
74
|
+
return await respond(result, res);
|
|
68
75
|
} catch (err) {
|
|
69
76
|
console.error(err);
|
|
70
77
|
|
|
@@ -73,10 +80,13 @@ const version_middleware = async (req, res, routers) => {
|
|
|
73
80
|
} catch (err) {
|
|
74
81
|
console.error("Version Middleware Error:", err);
|
|
75
82
|
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
return (
|
|
84
|
+
res &&
|
|
85
|
+
res.status(500).json({
|
|
86
|
+
ok: false,
|
|
87
|
+
message: "Internal server error",
|
|
88
|
+
})
|
|
89
|
+
);
|
|
80
90
|
}
|
|
81
91
|
};
|
|
82
92
|
|