godprotocol 2.3.19 → 2.3.20

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
@@ -28,10 +28,6 @@ class GodProtocol {
28
28
  }
29
29
 
30
30
  uri_default_domain = (uri) => {
31
- if (!uri.includes(".")) {
32
- uri = `${uri}.savvyaisolution.com`;
33
- }
34
-
35
31
  return uri;
36
32
  };
37
33
 
@@ -52,6 +48,8 @@ class GodProtocol {
52
48
  };
53
49
 
54
50
  add_router = async (version, routes, opts = {}) => {
51
+ if (opts?.prefix) version = `${opts.prefix}:${version}`;
52
+
55
53
  if (typeof routes === "function" && !opts.is_old) routes = await routes();
56
54
 
57
55
  if (opts.is_old) {
@@ -62,7 +60,7 @@ class GodProtocol {
62
60
 
63
61
  await this.route_table.init_version(version);
64
62
 
65
- await this.route_table.load_routes(routes);
63
+ await this.route_table.load_routes(routes, opts);
66
64
  };
67
65
 
68
66
  call = async (route, { headers, body }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "2.3.19",
3
+ "version": "2.3.20",
4
4
  "description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
5
5
  "main": "Index.js",
6
6
  "type": "module",
@@ -142,7 +142,7 @@ class Headers extends Services {
142
142
  headers["authorization"] = `Bearer ${authorization}`;
143
143
  }
144
144
 
145
- let gp_profile = gp_services().profile;
145
+ let gp_profile = gp_services().identity;
146
146
  let res = await fetch(`${gp_profile.url}/validate`, {
147
147
  method: "post",
148
148
  headers: {
@@ -204,7 +204,7 @@ class Headers extends Services {
204
204
  hst = hst.replace("10.0.2.2", "localhost");
205
205
  }
206
206
 
207
- let gp_profile = gp_services().profile;
207
+ let gp_profile = gp_services().identity;
208
208
 
209
209
  let third_party =
210
210
  xplatform !== this.platform_uri && !gp_profile.url.endsWith(hst);
@@ -46,12 +46,12 @@ class Route_table extends Headers {
46
46
  this.validators[name] = fn;
47
47
  };
48
48
 
49
- load_routes = async (routes) => {
49
+ load_routes = async (routes, opts) => {
50
50
  if (this.active_version === "*") {
51
51
  this.versions[this.active_version] = {
52
52
  handler: routes.handler,
53
53
  config: {
54
- security: securities[config.security || "none"],
54
+ security: securities[config.security || "auth_token"],
55
55
  schema: routes.schema,
56
56
  },
57
57
  };
@@ -65,6 +65,11 @@ class Route_table extends Headers {
65
65
 
66
66
  await this.add_route(name, handler, config);
67
67
  }
68
+
69
+ if (opts?.services) {
70
+ let services = await opts.service(opts.services_config);
71
+ await this.load_services(services, this.active_version);
72
+ }
68
73
  };
69
74
 
70
75
  add_route = async (name, handler, config) => {
@@ -1,31 +1,7 @@
1
1
  import { DB } from "./Header.js";
2
2
 
3
3
  let gp_services = () => {
4
- let DEV = process.env.DEV;
5
-
6
- return {
7
- profile: {
8
- url: DEV
9
- ? "http://localhost:4000"
10
- : "https://profile-api.savvyaisolution.com",
11
- api_version: "v3",
12
- uri: "profiles.savvyaisolution.com",
13
- },
14
- settings: {
15
- url: DEV
16
- ? "http://localhost:4005"
17
- : "https://settings-api.savvyaisolution.com",
18
- api_version: "v1",
19
- uri: "settings.savvyaisolution.com",
20
- },
21
- godprotocol: {
22
- url: DEV
23
- ? "http://localhost:4001"
24
- : "https://godprotocol-api.savvyaisolution.com",
25
- api_version: "v1",
26
- uri: "godprotocol.savvyaisolution.com",
27
- },
28
- };
4
+ return {};
29
5
  };
30
6
 
31
7
  export { gp_services };
@@ -36,10 +12,21 @@ class Services {
36
12
 
37
13
  this.dbs = new Object();
38
14
  this.load_services(gp_services);
15
+ this.version_services = {};
39
16
  }
40
17
 
41
- load_services = async (services) => {
42
- if (typeof services === "function") services = await services();
18
+ load_services = async (services, version) => {
19
+ if (typeof services === "function")
20
+ services = await services(this.gp, version);
21
+
22
+ if (version) {
23
+ let servs = this.version_services[version];
24
+ if (!servs) servs = {};
25
+ servs = { ...servs, ...services };
26
+
27
+ this.version_services[version] = servs;
28
+ return;
29
+ }
43
30
 
44
31
  this.services = { ...this.services, ...services };
45
32
  };
@@ -55,7 +42,7 @@ class Services {
55
42
 
56
43
  if (token) return token.token;
57
44
  try {
58
- let gp_profile = gp_services().profile;
45
+ let gp_profile = gp_services().identity;
59
46
  let ftch = await fetch(`${gp_profile.url}/get_token`, {
60
47
  method: "POST",
61
48
  headers: {
@@ -91,7 +78,10 @@ class Services {
91
78
  };
92
79
 
93
80
  get_service = async (service) => {
94
- let servic = this.services[service];
81
+ let servic =
82
+ this.version_services[this.active_version]?.[service] ||
83
+ this.services[service];
84
+
95
85
  if (!servic) return;
96
86
 
97
87
  return {
@@ -100,7 +90,9 @@ class Services {
100
90
  let headers = {
101
91
  "Content-Type": "application/json",
102
92
  Accept: "application/json",
103
- "x-api-version": servic.api_version || "v1",
93
+ "x-api-version": servic.local
94
+ ? `${servic.local}:${servic.api_version}`
95
+ : servic.api_version || "v1",
104
96
  };
105
97
  let token;
106
98
  if (servic.profile_key) {
@@ -134,11 +126,14 @@ class Services {
134
126
  };
135
127
  }
136
128
  try {
137
- let response = await fetch(`${servic.url}/${path}`, {
138
- method: "POST",
139
- headers,
140
- body: JSON.stringify(body || {}),
141
- });
129
+ let response = await fetch(
130
+ `${servic.local ? this.gp.server.domain : servic.url}/${path}`,
131
+ {
132
+ method: "POST",
133
+ headers,
134
+ body: JSON.stringify(body || {}),
135
+ },
136
+ );
142
137
 
143
138
  return await response.json();
144
139
  } catch (e) {