@polymarket/relayer-client 0.0.9 → 0.0.11
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/dist/auth/handler.js +8 -12
- package/dist/client.js +5 -7
- package/package.json +1 -1
package/dist/auth/handler.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthHandler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable max-depth */
|
|
6
|
-
const browser_or_node_1 = require("browser-or-node");
|
|
7
5
|
const http_helpers_1 = require("../http-helpers");
|
|
8
6
|
const POLYMARKET_COOKIE_NAME = "polymarket";
|
|
9
7
|
class AuthHandler {
|
|
@@ -24,18 +22,16 @@ class AuthHandler {
|
|
|
24
22
|
if (this.cookie == undefined) {
|
|
25
23
|
// Logging in will set the session cookies on the httpClient
|
|
26
24
|
const resp = yield this.httpClient.send(`${this.url}/login`, http_helpers_1.GET, { Authorization: `Bearer ${this.token}` });
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
aggregatedCookie += `${cookie}; `;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (aggregatedCookie != "") {
|
|
36
|
-
this.cookie = aggregatedCookie;
|
|
25
|
+
const cookies = resp.headers['set-cookie'];
|
|
26
|
+
let aggregatedCookie = "";
|
|
27
|
+
for (const cookie of cookies) {
|
|
28
|
+
if (cookie.includes(POLYMARKET_COOKIE_NAME)) {
|
|
29
|
+
aggregatedCookie += `${cookie}; `;
|
|
37
30
|
}
|
|
38
31
|
}
|
|
32
|
+
if (aggregatedCookie != "") {
|
|
33
|
+
this.cookie = aggregatedCookie;
|
|
34
|
+
}
|
|
39
35
|
console.log(`Successfully logged in!`);
|
|
40
36
|
}
|
|
41
37
|
});
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RelayClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
|
-
const browser_or_node_1 = require("browser-or-node");
|
|
6
|
+
const browser_or_node_1 = tslib_1.__importDefault(require("browser-or-node"));
|
|
7
7
|
const http_helpers_1 = require("./http-helpers");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const endpoints_1 = require("./endpoints");
|
|
@@ -116,11 +116,10 @@ class RelayClient {
|
|
|
116
116
|
}
|
|
117
117
|
send(endpoint, method, headers, data, params) {
|
|
118
118
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
if (!browser_or_node_1.isBrowser) {
|
|
119
|
+
// Explicitly inject the polymarket session cookies
|
|
120
|
+
// In prod environments, this will be unnecessary as the browser will have the needed cookies
|
|
121
|
+
// Needed only for local testing
|
|
122
|
+
if (!browser_or_node_1.default) {
|
|
124
123
|
const cookie = yield this.authHandler.getPolymarketCookies();
|
|
125
124
|
if (headers != undefined) {
|
|
126
125
|
headers["Cookie"] = cookie;
|
|
@@ -129,7 +128,6 @@ class RelayClient {
|
|
|
129
128
|
headers = { "Cookie": cookie };
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
|
-
// If the client is instantiated on the browser, do not inject cookies
|
|
133
131
|
const resp = yield this.httpClient.send(endpoint, method, headers, data, params);
|
|
134
132
|
return resp.data;
|
|
135
133
|
});
|