godprotocol 2.2.63 → 2.2.65
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
package/package.json
CHANGED
|
@@ -174,8 +174,9 @@ class Headers extends Services {
|
|
|
174
174
|
headers["authorization"] = `Bearer ${authorization}`;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
let third_party = xplatform === this.platform_uri;
|
|
177
178
|
let res = await fetch(
|
|
178
|
-
`${gp_services.profile}/${
|
|
179
|
+
`${gp_services.profile}/${third_party ? "me" : "third_party_me"}`,
|
|
179
180
|
{
|
|
180
181
|
method: "post",
|
|
181
182
|
headers: {
|
|
@@ -184,7 +185,7 @@ class Headers extends Services {
|
|
|
184
185
|
"x-api-version": "v3",
|
|
185
186
|
...headers,
|
|
186
187
|
},
|
|
187
|
-
body: JSON.stringify({ from: xplatform }),
|
|
188
|
+
body: JSON.stringify(third_party ? { from: xplatform } : {}),
|
|
188
189
|
},
|
|
189
190
|
);
|
|
190
191
|
res = await res.json();
|
|
@@ -214,7 +215,6 @@ class Headers extends Services {
|
|
|
214
215
|
handle_security = async (name, request) => {
|
|
215
216
|
let route = await this.get_route(name);
|
|
216
217
|
|
|
217
|
-
console.log(route?.config?.security, "SECURITY FOR ROUTE");
|
|
218
218
|
if (!route?.config?.security?.length) return true;
|
|
219
219
|
|
|
220
220
|
if (!this.check_security(route.config.security, request)) {
|
|
@@ -44,7 +44,7 @@ class Route_table extends Headers {
|
|
|
44
44
|
for (let name in routes) {
|
|
45
45
|
let { handler, ...config } = routes[name];
|
|
46
46
|
|
|
47
|
-
config.security = securities[config.security || "
|
|
47
|
+
config.security = securities[config.security || "auth_token"];
|
|
48
48
|
|
|
49
49
|
await this.add_route(name, handler, config);
|
|
50
50
|
}
|
|
@@ -123,11 +123,44 @@ class Services {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
handle_webhook_prior = async (req) => {
|
|
126
|
-
let
|
|
127
|
-
|
|
126
|
+
let fn = this.gp.webhook_prior;
|
|
127
|
+
|
|
128
|
+
if (typeof fn === "function") {
|
|
129
|
+
let res = await fn(req);
|
|
130
|
+
return res && Object.keys(res).hasOwnProperty("ok") ? res : { ok: false };
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
ok: true,
|
|
134
|
+
};
|
|
128
135
|
};
|
|
129
136
|
|
|
130
|
-
handle_webhook_after = async (req, result) => {
|
|
137
|
+
handle_webhook_after = async (req, result) => {
|
|
138
|
+
let { headers, body, route } = req;
|
|
139
|
+
let { xplatform, platform } = headers;
|
|
140
|
+
|
|
141
|
+
if (xplatform && xplatform.uri !== platform.uri) {
|
|
142
|
+
if (xplatform.webhook?.enabled) {
|
|
143
|
+
let { webhook } = xplatform;
|
|
144
|
+
await fetch(webhook?.url, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers: {
|
|
147
|
+
"Content-Type": "application/json",
|
|
148
|
+
Accept: "application/json",
|
|
149
|
+
"x-api-version": webhook?.api_version || "v1",
|
|
150
|
+
},
|
|
151
|
+
body: JSON.stringify({
|
|
152
|
+
me: xplatform,
|
|
153
|
+
profile,
|
|
154
|
+
platform,
|
|
155
|
+
body,
|
|
156
|
+
result,
|
|
157
|
+
route,
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
}
|
|
163
|
+
};
|
|
131
164
|
|
|
132
165
|
resolve_db = async (req) => {
|
|
133
166
|
let db = await this.platform_db();
|
|
@@ -80,8 +80,7 @@ const version_middleware = async (req, res, routers) => {
|
|
|
80
80
|
return res.end(
|
|
81
81
|
JSON.stringify({
|
|
82
82
|
ok: false,
|
|
83
|
-
|
|
84
|
-
version,
|
|
83
|
+
message: "Invalid API version",
|
|
85
84
|
}),
|
|
86
85
|
);
|
|
87
86
|
}
|
|
@@ -114,9 +113,9 @@ const version_middleware = async (req, res, routers) => {
|
|
|
114
113
|
// WEBHOOK PRIOR
|
|
115
114
|
// ----------------------------
|
|
116
115
|
if (!isWebhook) {
|
|
117
|
-
const webPrior = await router.handle_webhook_prior(req);
|
|
116
|
+
const webPrior = await router.handle_webhook_prior({ ...req, body });
|
|
118
117
|
|
|
119
|
-
if (webPrior
|
|
118
|
+
if (!webPrior?.ok) {
|
|
120
119
|
return respond(webPrior, res);
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -130,6 +129,7 @@ const version_middleware = async (req, res, routers) => {
|
|
|
130
129
|
// ----------------------------
|
|
131
130
|
const result = await router.execute(name, {
|
|
132
131
|
body,
|
|
132
|
+
route: name,
|
|
133
133
|
headers: req.headers,
|
|
134
134
|
db: db.db,
|
|
135
135
|
gp: router.gp,
|