@aptos-labs/aptos-client 0.0.1 → 0.1.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/dist/browser/index.browser.d.mts +21 -0
- package/dist/browser/index.browser.d.ts +2 -2
- package/dist/browser/index.browser.js +4 -2
- package/dist/browser/index.browser.js.map +1 -1
- package/dist/browser/index.browser.mjs.map +1 -1
- package/dist/node/index.node.d.mts +21 -0
- package/dist/node/index.node.d.ts +2 -2
- package/dist/node/index.node.js +7 -16
- package/dist/node/index.node.js.map +1 -1
- package/dist/node/index.node.mjs +3 -14
- package/dist/node/index.node.mjs.map +1 -1
- package/dist/types/cookieJar.js +2 -2
- package/dist/types/index.node.js +7 -20
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.js +1 -1
- package/package.json +39 -14
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type AptosClientResponse<Res> = {
|
|
2
|
+
status: number;
|
|
3
|
+
statusText: string;
|
|
4
|
+
data: Res;
|
|
5
|
+
config?: any;
|
|
6
|
+
request?: any;
|
|
7
|
+
response?: any;
|
|
8
|
+
headers?: any;
|
|
9
|
+
};
|
|
10
|
+
type AptosClientRequest = {
|
|
11
|
+
url: string;
|
|
12
|
+
method: "GET" | "POST";
|
|
13
|
+
body?: any;
|
|
14
|
+
params?: any;
|
|
15
|
+
headers?: any;
|
|
16
|
+
overrides?: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare function aptosClient<Res>(options: AptosClientRequest): Promise<AptosClientResponse<Res>>;
|
|
20
|
+
|
|
21
|
+
export { aptosClient as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type AptosClientResponse<Res> = {
|
|
2
2
|
status: number;
|
|
3
3
|
statusText: string;
|
|
4
4
|
data: Res;
|
|
@@ -7,7 +7,7 @@ declare type AptosClientResponse<Res> = {
|
|
|
7
7
|
response?: any;
|
|
8
8
|
headers?: any;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type AptosClientRequest = {
|
|
11
11
|
url: string;
|
|
12
12
|
method: "GET" | "POST";
|
|
13
13
|
body?: any;
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -58,6 +62,4 @@ async function aptosClient(options) {
|
|
|
58
62
|
throw error;
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {});
|
|
63
65
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["import axios, { AxiosRequestConfig, AxiosError } from \"axios\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nexport default async function aptosClient<Res>(options: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body, overrides } = options;\n const requestConfig: AxiosRequestConfig = {\n headers,\n method,\n url,\n params,\n data: body,\n withCredentials: overrides?.WITH_CREDENTIALS ?? true,\n };\n\n try {\n const response = await axios(requestConfig);\n return {\n status: response.status,\n statusText: response.statusText!,\n data: response.data,\n headers: response.headers,\n config: response.config,\n };\n } catch (error) {\n const axiosError = error as AxiosError<Res>;\n if (axiosError.response) {\n return axiosError.response;\n }\n throw error;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["import axios, { AxiosRequestConfig, AxiosError } from \"axios\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nexport default async function aptosClient<Res>(options: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body, overrides } = options;\n const requestConfig: AxiosRequestConfig = {\n headers,\n method,\n url,\n params,\n data: body,\n withCredentials: overrides?.WITH_CREDENTIALS ?? true,\n };\n\n try {\n const response = await axios(requestConfig);\n return {\n status: response.status,\n statusText: response.statusText!,\n data: response.data,\n headers: response.headers,\n config: response.config,\n };\n } catch (error) {\n const axiosError = error as AxiosError<Res>;\n if (axiosError.response) {\n return axiosError.response;\n }\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsD;AAGtD,eAAO,YAAwC,SAAgE;AAH/G;AAIE,QAAM,EAAE,QAAQ,QAAQ,KAAK,SAAS,MAAM,UAAU,IAAI;AAC1D,QAAM,gBAAoC;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,kBAAiB,4CAAW,qBAAX,YAA+B;AAAA,EAClD;AAEA,MAAI;AACF,UAAM,WAAW,UAAM,aAAAA,SAAM,aAAa;AAC1C,WAAO;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,MAAM,SAAS;AAAA,MACf,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,SAAS,OAAO;AACd,UAAM,aAAa;AACnB,QAAI,WAAW,UAAU;AACvB,aAAO,WAAW;AAAA,IACpB;AACA,UAAM;AAAA,EACR;AACF;","names":["axios"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["import axios, { AxiosRequestConfig, AxiosError } from \"axios\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nexport default async function aptosClient<Res>(options: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body, overrides } = options;\n const requestConfig: AxiosRequestConfig = {\n headers,\n method,\n url,\n params,\n data: body,\n withCredentials: overrides?.WITH_CREDENTIALS ?? true,\n };\n\n try {\n const response = await axios(requestConfig);\n return {\n status: response.status,\n statusText: response.statusText!,\n data: response.data,\n headers: response.headers,\n config: response.config,\n };\n } catch (error) {\n const axiosError = error as AxiosError<Res>;\n if (axiosError.response) {\n return axiosError.response;\n }\n throw error;\n }\n}\n"],"mappings":";AAAA,OAAO,WAA+C;AAGtD,eAAO,YAAwC,SAAgE;AAH/G;AAIE,QAAM,EAAE,QAAQ,QAAQ,KAAK,SAAS,MAAM,UAAU,IAAI;AAC1D,QAAM,gBAAoC;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,kBAAiB,4CAAW,qBAAX,YAA+B;AAAA,EAClD;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,aAAa;AAC1C,WAAO;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,MAAM,SAAS;AAAA,MACf,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["import axios, { AxiosRequestConfig, AxiosError } from \"axios\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nexport default async function aptosClient<Res>(options: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body, overrides } = options;\n const requestConfig: AxiosRequestConfig = {\n headers,\n method,\n url,\n params,\n data: body,\n withCredentials: overrides?.WITH_CREDENTIALS ?? true,\n };\n\n try {\n const response = await axios(requestConfig);\n return {\n status: response.status,\n statusText: response.statusText!,\n data: response.data,\n headers: response.headers,\n config: response.config,\n };\n } catch (error) {\n const axiosError = error as AxiosError<Res>;\n if (axiosError.response) {\n return axiosError.response;\n }\n throw error;\n }\n}\n"],"mappings":";AAAA,OAAO,WAA+C;AAGtD,eAAO,YAAwC,SAAgE;AAH/G;AAIE,QAAM,EAAE,QAAQ,QAAQ,KAAK,SAAS,MAAM,UAAU,IAAI;AAC1D,QAAM,gBAAoC;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,kBAAiB,4CAAW,qBAAX,YAA+B;AAAA,EAClD;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,aAAa;AAC1C,WAAO;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,MAAM,SAAS;AAAA,MACf,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,SAAS,OAAO;AACd,UAAM,aAAa;AACnB,QAAI,WAAW,UAAU;AACvB,aAAO,WAAW;AAAA,IACpB;AACA,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type AptosClientResponse<Res> = {
|
|
2
|
+
status: number;
|
|
3
|
+
statusText: string;
|
|
4
|
+
data: Res;
|
|
5
|
+
config?: any;
|
|
6
|
+
request?: any;
|
|
7
|
+
response?: any;
|
|
8
|
+
headers?: any;
|
|
9
|
+
};
|
|
10
|
+
type AptosClientRequest = {
|
|
11
|
+
url: string;
|
|
12
|
+
method: "GET" | "POST";
|
|
13
|
+
body?: any;
|
|
14
|
+
params?: any;
|
|
15
|
+
headers?: any;
|
|
16
|
+
overrides?: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare function aptosClient<Res>(requestOptions: AptosClientRequest): Promise<AptosClientResponse<Res>>;
|
|
20
|
+
|
|
21
|
+
export { aptosClient as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type AptosClientResponse<Res> = {
|
|
2
2
|
status: number;
|
|
3
3
|
statusText: string;
|
|
4
4
|
data: Res;
|
|
@@ -7,7 +7,7 @@ declare type AptosClientResponse<Res> = {
|
|
|
7
7
|
response?: any;
|
|
8
8
|
headers?: any;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type AptosClientRequest = {
|
|
11
11
|
url: string;
|
|
12
12
|
method: "GET" | "POST";
|
|
13
13
|
body?: any;
|
package/dist/node/index.node.js
CHANGED
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -32,7 +36,7 @@ module.exports = __toCommonJS(index_node_exports);
|
|
|
32
36
|
var import_got = __toESM(require("got"));
|
|
33
37
|
|
|
34
38
|
// src/cookieJar.ts
|
|
35
|
-
var CookieJar = class {
|
|
39
|
+
var CookieJar = class _CookieJar {
|
|
36
40
|
constructor(jar = /* @__PURE__ */ new Map()) {
|
|
37
41
|
this.jar = jar;
|
|
38
42
|
}
|
|
@@ -42,7 +46,7 @@ var CookieJar = class {
|
|
|
42
46
|
if (!this.jar.has(key)) {
|
|
43
47
|
this.jar.set(key, []);
|
|
44
48
|
}
|
|
45
|
-
const cookie =
|
|
49
|
+
const cookie = _CookieJar.parse(cookieStr);
|
|
46
50
|
this.jar.set(key, [...((_a = this.jar.get(key)) == null ? void 0 : _a.filter((c) => c.name !== cookie.name)) || [], cookie]);
|
|
47
51
|
}
|
|
48
52
|
getCookies(url) {
|
|
@@ -51,7 +55,7 @@ var CookieJar = class {
|
|
|
51
55
|
if (!this.jar.get(key)) {
|
|
52
56
|
return [];
|
|
53
57
|
}
|
|
54
|
-
return ((_a = this.jar.get(key)) == null ? void 0 : _a.filter((cookie) => !cookie.expires || cookie.expires > new Date())) || [];
|
|
58
|
+
return ((_a = this.jar.get(key)) == null ? void 0 : _a.filter((cookie) => !cookie.expires || cookie.expires > /* @__PURE__ */ new Date())) || [];
|
|
55
59
|
}
|
|
56
60
|
static parse(str) {
|
|
57
61
|
if (typeof str !== "string") {
|
|
@@ -139,7 +143,6 @@ async function aptosClient(requestOptions) {
|
|
|
139
143
|
}
|
|
140
144
|
try {
|
|
141
145
|
const response = await (0, import_got.default)(request);
|
|
142
|
-
parseHeaders(response);
|
|
143
146
|
return parseResponse(response);
|
|
144
147
|
} catch (error) {
|
|
145
148
|
const gotError = error;
|
|
@@ -160,16 +163,6 @@ function parseResponse(response) {
|
|
|
160
163
|
headers: response.headers
|
|
161
164
|
};
|
|
162
165
|
}
|
|
163
|
-
function parseHeaders(response) {
|
|
164
|
-
if (response.request.options.headers.authorization) {
|
|
165
|
-
response.request.options.headers.Authorization = response.request.options.headers.authorization;
|
|
166
|
-
delete response.request.options.headers.authorization;
|
|
167
|
-
}
|
|
168
|
-
if (response.request.options.headers["content-type"]) {
|
|
169
|
-
response.request.options.headers["Content-Type"] = response.request.options.headers["content-type"];
|
|
170
|
-
delete response.request.options.headers["content-type"];
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
166
|
function convertBigIntToString(obj) {
|
|
174
167
|
const result = {};
|
|
175
168
|
if (!obj)
|
|
@@ -185,6 +178,4 @@ function convertBigIntToString(obj) {
|
|
|
185
178
|
});
|
|
186
179
|
return result;
|
|
187
180
|
}
|
|
188
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
-
0 && (module.exports = {});
|
|
190
181
|
//# sourceMappingURL=index.node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.node.ts","../../src/cookieJar.ts"],"sourcesContent":["import got, { OptionsOfJSONResponseBody, RequestError, Response } from \"got\";\nimport { CookieJar } from \"./cookieJar\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nconst cookieJar = new CookieJar();\n\nexport default async function aptosClient<Res>(requestOptions: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body } = requestOptions;\n\n const request: OptionsOfJSONResponseBody = {\n http2: true,\n searchParams: convertBigIntToString(params),\n method,\n url,\n responseType: \"json\",\n headers,\n hooks: {\n beforeRequest: [\n (options) => {\n const cookies = cookieJar.getCookies(new URL(options.url!));\n\n if (cookies?.length > 0 && options.headers) {\n /* eslint-disable no-param-reassign */\n options.headers.cookie = cookies.map((cookie: any) => `${cookie.name}=${cookie.value}`).join(\"; \");\n }\n },\n ],\n afterResponse: [\n (response) => {\n if (Array.isArray(response.headers[\"set-cookie\"])) {\n response.headers[\"set-cookie\"].forEach((c) => {\n cookieJar.setCookie(new URL(response.url!), c);\n });\n }\n return response;\n },\n ],\n },\n };\n\n if (body) {\n if (body instanceof Uint8Array) {\n request.body = Buffer.from(body);\n } else {\n request.body = Buffer.from(JSON.stringify(body));\n }\n }\n\n try {\n const response = await got<Res>(request);\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.node.ts","../../src/cookieJar.ts"],"sourcesContent":["import got, { OptionsOfJSONResponseBody, RequestError, Response } from \"got\";\nimport { CookieJar } from \"./cookieJar\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nconst cookieJar = new CookieJar();\n\nexport default async function aptosClient<Res>(requestOptions: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body } = requestOptions;\n\n const request: OptionsOfJSONResponseBody = {\n http2: true,\n searchParams: convertBigIntToString(params),\n method,\n url,\n responseType: \"json\",\n headers,\n hooks: {\n beforeRequest: [\n (options) => {\n const cookies = cookieJar.getCookies(new URL(options.url!));\n\n if (cookies?.length > 0 && options.headers) {\n /* eslint-disable no-param-reassign */\n options.headers.cookie = cookies.map((cookie: any) => `${cookie.name}=${cookie.value}`).join(\"; \");\n }\n },\n ],\n afterResponse: [\n (response) => {\n if (Array.isArray(response.headers[\"set-cookie\"])) {\n response.headers[\"set-cookie\"].forEach((c) => {\n cookieJar.setCookie(new URL(response.url!), c);\n });\n }\n return response;\n },\n ],\n },\n };\n\n if (body) {\n if (body instanceof Uint8Array) {\n request.body = Buffer.from(body);\n } else {\n request.body = Buffer.from(JSON.stringify(body));\n }\n }\n\n try {\n const response = await got<Res>(request);\n return parseResponse<Res>(response);\n } catch (error) {\n const gotError = error as RequestError;\n if (gotError.response) {\n return parseResponse<Res>(gotError.response as Response<Res>);\n }\n throw error;\n }\n}\n\nfunction parseResponse<Res>(response: Response<Res>): AptosClientResponse<Res> {\n return {\n status: response.statusCode,\n statusText: response.statusMessage || \"\",\n data: response.body,\n config: response.request.options,\n request: response.request,\n response,\n headers: response.headers,\n };\n}\n\n/**\n * got supports only - string | number | boolean | null | undefined as searchParam value,\n * so if we have bigint type, convert it to string\n */\nfunction convertBigIntToString(obj: any): any {\n const result: any = {};\n if (!obj) return result;\n\n Object.entries(obj).forEach(([key, value]) => {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n if (typeof value === \"bigint\") {\n result[key] = String(value);\n } else {\n result[key] = value;\n }\n }\n });\n\n return result;\n}\n","interface Cookie {\n name: string;\n value: string;\n expires?: Date;\n path?: string;\n sameSite?: \"Lax\" | \"None\" | \"Strict\";\n secure?: boolean;\n}\n\nexport class CookieJar {\n constructor(private jar = new Map<string, Cookie[]>()) {}\n\n setCookie(url: URL, cookieStr: string) {\n const key = url.origin.toLowerCase();\n if (!this.jar.has(key)) {\n this.jar.set(key, []);\n }\n\n const cookie = CookieJar.parse(cookieStr);\n this.jar.set(key, [...(this.jar.get(key)?.filter((c) => c.name !== cookie.name) || []), cookie]);\n }\n\n getCookies(url: URL): Cookie[] {\n const key = url.origin.toLowerCase();\n if (!this.jar.get(key)) {\n return [];\n }\n\n // Filter out expired cookies\n return this.jar.get(key)?.filter((cookie) => !cookie.expires || cookie.expires > new Date()) || [];\n }\n\n static parse(str: string): Cookie {\n if (typeof str !== \"string\") {\n throw new Error(\"argument str must be a string\");\n }\n\n const parts = str.split(\";\").map((part) => part.trim());\n\n let cookie: Cookie;\n\n if (parts.length > 0) {\n const [name, value] = parts[0].split(\"=\");\n if (!name || !value) {\n throw new Error(\"Invalid cookie\");\n }\n\n cookie = {\n name,\n value,\n };\n } else {\n throw new Error(\"Invalid cookie\");\n }\n\n parts.slice(1).forEach((part) => {\n const [name, value] = part.split(\"=\");\n if (!name.trim()) {\n throw new Error(\"Invalid cookie\");\n }\n\n const nameLow = name.toLowerCase();\n // eslint-disable-next-line quotes\n const val = value?.charAt(0) === \"'\" || value?.charAt(0) === '\"' ? value?.slice(1, -1) : value;\n if (nameLow === \"expires\") {\n cookie.expires = new Date(val);\n }\n if (nameLow === \"path\") {\n cookie.path = val;\n }\n if (nameLow === \"samesite\") {\n if (val !== \"Lax\" && val !== \"None\" && val !== \"Strict\") {\n throw new Error(\"Invalid cookie SameSite value\");\n }\n cookie.sameSite = val;\n }\n if (nameLow === \"secure\") {\n cookie.secure = true;\n }\n });\n\n return cookie;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAuE;;;ACShE,IAAM,YAAN,MAAM,WAAU;AAAA,EACrB,YAAoB,MAAM,oBAAI,IAAsB,GAAG;AAAnC;AAAA,EAAoC;AAAA,EAExD,UAAU,KAAU,WAAmB;AAZzC;AAaI,UAAM,MAAM,IAAI,OAAO,YAAY;AACnC,QAAI,CAAC,KAAK,IAAI,IAAI,GAAG,GAAG;AACtB,WAAK,IAAI,IAAI,KAAK,CAAC,CAAC;AAAA,IACtB;AAEA,UAAM,SAAS,WAAU,MAAM,SAAS;AACxC,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MAAM;AACR,QAAI,gBAAgB,YAAY;AAC9B,cAAQ,OAAO,OAAO,KAAK,IAAI;AAAA,IACjC,OAAO;AACL,cAAQ,OAAO,OAAO,KAAK,KAAK,UAAU,IAAI,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,MAAI;AACF,UAAM,WAAW,UAAM,WAAAA,SAAS,OAAO;AACvC,WAAO,cAAmB,QAAQ;AAAA,EACpC,SAAS,OAAO;AACd,UAAM,WAAW;AACjB,QAAI,SAAS,UAAU;AACrB,aAAO,cAAmB,SAAS,QAAyB;AAAA,IAC9D;AACA,UAAM;AAAA,EACR;AACF;AAEA,SAAS,cAAmB,UAAmD;AAC7E,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS,iBAAiB;AAAA,IACtC,MAAM,SAAS;AAAA,IACf,QAAQ,SAAS,QAAQ;AAAA,IACzB,SAAS,SAAS;AAAA,IAClB;AAAA,IACA,SAAS,SAAS;AAAA,EACpB;AACF;AAMA,SAAS,sBAAsB,KAAe;AAC5C,QAAM,SAAc,CAAC;AACrB,MAAI,CAAC;AAAK,WAAO;AAEjB,SAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC5C,QAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AAClD,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAI,OAAO,KAAK;AAAA,MAC5B,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":["got"]}
|
package/dist/node/index.node.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import got from "got";
|
|
3
3
|
|
|
4
4
|
// src/cookieJar.ts
|
|
5
|
-
var CookieJar = class {
|
|
5
|
+
var CookieJar = class _CookieJar {
|
|
6
6
|
constructor(jar = /* @__PURE__ */ new Map()) {
|
|
7
7
|
this.jar = jar;
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@ var CookieJar = class {
|
|
|
12
12
|
if (!this.jar.has(key)) {
|
|
13
13
|
this.jar.set(key, []);
|
|
14
14
|
}
|
|
15
|
-
const cookie =
|
|
15
|
+
const cookie = _CookieJar.parse(cookieStr);
|
|
16
16
|
this.jar.set(key, [...((_a = this.jar.get(key)) == null ? void 0 : _a.filter((c) => c.name !== cookie.name)) || [], cookie]);
|
|
17
17
|
}
|
|
18
18
|
getCookies(url) {
|
|
@@ -21,7 +21,7 @@ var CookieJar = class {
|
|
|
21
21
|
if (!this.jar.get(key)) {
|
|
22
22
|
return [];
|
|
23
23
|
}
|
|
24
|
-
return ((_a = this.jar.get(key)) == null ? void 0 : _a.filter((cookie) => !cookie.expires || cookie.expires > new Date())) || [];
|
|
24
|
+
return ((_a = this.jar.get(key)) == null ? void 0 : _a.filter((cookie) => !cookie.expires || cookie.expires > /* @__PURE__ */ new Date())) || [];
|
|
25
25
|
}
|
|
26
26
|
static parse(str) {
|
|
27
27
|
if (typeof str !== "string") {
|
|
@@ -109,7 +109,6 @@ async function aptosClient(requestOptions) {
|
|
|
109
109
|
}
|
|
110
110
|
try {
|
|
111
111
|
const response = await got(request);
|
|
112
|
-
parseHeaders(response);
|
|
113
112
|
return parseResponse(response);
|
|
114
113
|
} catch (error) {
|
|
115
114
|
const gotError = error;
|
|
@@ -130,16 +129,6 @@ function parseResponse(response) {
|
|
|
130
129
|
headers: response.headers
|
|
131
130
|
};
|
|
132
131
|
}
|
|
133
|
-
function parseHeaders(response) {
|
|
134
|
-
if (response.request.options.headers.authorization) {
|
|
135
|
-
response.request.options.headers.Authorization = response.request.options.headers.authorization;
|
|
136
|
-
delete response.request.options.headers.authorization;
|
|
137
|
-
}
|
|
138
|
-
if (response.request.options.headers["content-type"]) {
|
|
139
|
-
response.request.options.headers["Content-Type"] = response.request.options.headers["content-type"];
|
|
140
|
-
delete response.request.options.headers["content-type"];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
132
|
function convertBigIntToString(obj) {
|
|
144
133
|
const result = {};
|
|
145
134
|
if (!obj)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.node.ts","../../src/cookieJar.ts"],"sourcesContent":["import got, { OptionsOfJSONResponseBody, RequestError, Response } from \"got\";\nimport { CookieJar } from \"./cookieJar\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nconst cookieJar = new CookieJar();\n\nexport default async function aptosClient<Res>(requestOptions: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body } = requestOptions;\n\n const request: OptionsOfJSONResponseBody = {\n http2: true,\n searchParams: convertBigIntToString(params),\n method,\n url,\n responseType: \"json\",\n headers,\n hooks: {\n beforeRequest: [\n (options) => {\n const cookies = cookieJar.getCookies(new URL(options.url!));\n\n if (cookies?.length > 0 && options.headers) {\n /* eslint-disable no-param-reassign */\n options.headers.cookie = cookies.map((cookie: any) => `${cookie.name}=${cookie.value}`).join(\"; \");\n }\n },\n ],\n afterResponse: [\n (response) => {\n if (Array.isArray(response.headers[\"set-cookie\"])) {\n response.headers[\"set-cookie\"].forEach((c) => {\n cookieJar.setCookie(new URL(response.url!), c);\n });\n }\n return response;\n },\n ],\n },\n };\n\n if (body) {\n if (body instanceof Uint8Array) {\n request.body = Buffer.from(body);\n } else {\n request.body = Buffer.from(JSON.stringify(body));\n }\n }\n\n try {\n const response = await got<Res>(request);\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.node.ts","../../src/cookieJar.ts"],"sourcesContent":["import got, { OptionsOfJSONResponseBody, RequestError, Response } from \"got\";\nimport { CookieJar } from \"./cookieJar\";\nimport { AptosClientRequest, AptosClientResponse } from \"./types\";\n\nconst cookieJar = new CookieJar();\n\nexport default async function aptosClient<Res>(requestOptions: AptosClientRequest): Promise<AptosClientResponse<Res>> {\n const { params, method, url, headers, body } = requestOptions;\n\n const request: OptionsOfJSONResponseBody = {\n http2: true,\n searchParams: convertBigIntToString(params),\n method,\n url,\n responseType: \"json\",\n headers,\n hooks: {\n beforeRequest: [\n (options) => {\n const cookies = cookieJar.getCookies(new URL(options.url!));\n\n if (cookies?.length > 0 && options.headers) {\n /* eslint-disable no-param-reassign */\n options.headers.cookie = cookies.map((cookie: any) => `${cookie.name}=${cookie.value}`).join(\"; \");\n }\n },\n ],\n afterResponse: [\n (response) => {\n if (Array.isArray(response.headers[\"set-cookie\"])) {\n response.headers[\"set-cookie\"].forEach((c) => {\n cookieJar.setCookie(new URL(response.url!), c);\n });\n }\n return response;\n },\n ],\n },\n };\n\n if (body) {\n if (body instanceof Uint8Array) {\n request.body = Buffer.from(body);\n } else {\n request.body = Buffer.from(JSON.stringify(body));\n }\n }\n\n try {\n const response = await got<Res>(request);\n return parseResponse<Res>(response);\n } catch (error) {\n const gotError = error as RequestError;\n if (gotError.response) {\n return parseResponse<Res>(gotError.response as Response<Res>);\n }\n throw error;\n }\n}\n\nfunction parseResponse<Res>(response: Response<Res>): AptosClientResponse<Res> {\n return {\n status: response.statusCode,\n statusText: response.statusMessage || \"\",\n data: response.body,\n config: response.request.options,\n request: response.request,\n response,\n headers: response.headers,\n };\n}\n\n/**\n * got supports only - string | number | boolean | null | undefined as searchParam value,\n * so if we have bigint type, convert it to string\n */\nfunction convertBigIntToString(obj: any): any {\n const result: any = {};\n if (!obj) return result;\n\n Object.entries(obj).forEach(([key, value]) => {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n if (typeof value === \"bigint\") {\n result[key] = String(value);\n } else {\n result[key] = value;\n }\n }\n });\n\n return result;\n}\n","interface Cookie {\n name: string;\n value: string;\n expires?: Date;\n path?: string;\n sameSite?: \"Lax\" | \"None\" | \"Strict\";\n secure?: boolean;\n}\n\nexport class CookieJar {\n constructor(private jar = new Map<string, Cookie[]>()) {}\n\n setCookie(url: URL, cookieStr: string) {\n const key = url.origin.toLowerCase();\n if (!this.jar.has(key)) {\n this.jar.set(key, []);\n }\n\n const cookie = CookieJar.parse(cookieStr);\n this.jar.set(key, [...(this.jar.get(key)?.filter((c) => c.name !== cookie.name) || []), cookie]);\n }\n\n getCookies(url: URL): Cookie[] {\n const key = url.origin.toLowerCase();\n if (!this.jar.get(key)) {\n return [];\n }\n\n // Filter out expired cookies\n return this.jar.get(key)?.filter((cookie) => !cookie.expires || cookie.expires > new Date()) || [];\n }\n\n static parse(str: string): Cookie {\n if (typeof str !== \"string\") {\n throw new Error(\"argument str must be a string\");\n }\n\n const parts = str.split(\";\").map((part) => part.trim());\n\n let cookie: Cookie;\n\n if (parts.length > 0) {\n const [name, value] = parts[0].split(\"=\");\n if (!name || !value) {\n throw new Error(\"Invalid cookie\");\n }\n\n cookie = {\n name,\n value,\n };\n } else {\n throw new Error(\"Invalid cookie\");\n }\n\n parts.slice(1).forEach((part) => {\n const [name, value] = part.split(\"=\");\n if (!name.trim()) {\n throw new Error(\"Invalid cookie\");\n }\n\n const nameLow = name.toLowerCase();\n // eslint-disable-next-line quotes\n const val = value?.charAt(0) === \"'\" || value?.charAt(0) === '\"' ? value?.slice(1, -1) : value;\n if (nameLow === \"expires\") {\n cookie.expires = new Date(val);\n }\n if (nameLow === \"path\") {\n cookie.path = val;\n }\n if (nameLow === \"samesite\") {\n if (val !== \"Lax\" && val !== \"None\" && val !== \"Strict\") {\n throw new Error(\"Invalid cookie SameSite value\");\n }\n cookie.sameSite = val;\n }\n if (nameLow === \"secure\") {\n cookie.secure = true;\n }\n });\n\n return cookie;\n }\n}\n"],"mappings":";AAAA,OAAO,SAAgE;;;ACShE,IAAM,YAAN,MAAM,WAAU;AAAA,EACrB,YAAoB,MAAM,oBAAI,IAAsB,GAAG;AAAnC;AAAA,EAAoC;AAAA,EAExD,UAAU,KAAU,WAAmB;AAZzC;AAaI,UAAM,MAAM,IAAI,OAAO,YAAY;AACnC,QAAI,CAAC,KAAK,IAAI,IAAI,GAAG,GAAG;AACtB,WAAK,IAAI,IAAI,KAAK,CAAC,CAAC;AAAA,IACtB;AAEA,UAAM,SAAS,WAAU,MAAM,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AAEA,MAAI,MAAM;AACR,QAAI,gBAAgB,YAAY;AAC9B,cAAQ,OAAO,OAAO,KAAK,IAAI;AAAA,IACjC,OAAO;AACL,cAAQ,OAAO,OAAO,KAAK,KAAK,UAAU,IAAI,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,IAAS,OAAO;AACvC,WAAO,cAAmB,QAAQ;AAAA,EACpC,SAAS,OAAO;AACd,UAAM,WAAW;AACjB,QAAI,SAAS,UAAU;AACrB,aAAO,cAAmB,SAAS,QAAyB;AAAA,IAC9D;AACA,UAAM;AAAA,EACR;AACF;AAEA,SAAS,cAAmB,UAAmD;AAC7E,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS,iBAAiB;AAAA,IACtC,MAAM,SAAS;AAAA,IACf,QAAQ,SAAS,QAAQ;AAAA,IACzB,SAAS,SAAS;AAAA,IAClB;AAAA,IACA,SAAS,SAAS;AAAA,EACpB;AACF;AAMA,SAAS,sBAAsB,KAAe;AAC5C,QAAM,SAAc,CAAC;AACrB,MAAI,CAAC;AAAK,WAAO;AAEjB,SAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC5C,QAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AAClD,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAI,OAAO,KAAK;AAAA,MAC5B,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
|
package/dist/types/cookieJar.js
CHANGED
|
@@ -8,7 +8,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
8
8
|
}
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
|
-
exports
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CookieJar = void 0;
|
|
13
13
|
var CookieJar = /** @class */ (function () {
|
|
14
14
|
function CookieJar(jar) {
|
|
@@ -46,7 +46,7 @@ var CookieJar = /** @class */ (function () {
|
|
|
46
46
|
}
|
|
47
47
|
cookie = {
|
|
48
48
|
name: name_1,
|
|
49
|
-
value: value
|
|
49
|
+
value: value,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
else {
|
package/dist/types/index.node.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
exports
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var got_1 = require("got");
|
|
40
40
|
var cookieJar_1 = require("./cookieJar");
|
|
41
41
|
var cookieJar = new cookieJar_1.CookieJar();
|
|
@@ -72,8 +72,8 @@ function aptosClient(requestOptions) {
|
|
|
72
72
|
}
|
|
73
73
|
return response;
|
|
74
74
|
},
|
|
75
|
-
]
|
|
76
|
-
}
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
77
|
};
|
|
78
78
|
if (body) {
|
|
79
79
|
if (body instanceof Uint8Array) {
|
|
@@ -86,10 +86,9 @@ function aptosClient(requestOptions) {
|
|
|
86
86
|
_a.label = 1;
|
|
87
87
|
case 1:
|
|
88
88
|
_a.trys.push([1, 3, , 4]);
|
|
89
|
-
return [4 /*yield*/, (0, got_1
|
|
89
|
+
return [4 /*yield*/, (0, got_1.default)(request)];
|
|
90
90
|
case 2:
|
|
91
91
|
response = _a.sent();
|
|
92
|
-
parseHeaders(response);
|
|
93
92
|
return [2 /*return*/, parseResponse(response)];
|
|
94
93
|
case 3:
|
|
95
94
|
error_1 = _a.sent();
|
|
@@ -103,7 +102,7 @@ function aptosClient(requestOptions) {
|
|
|
103
102
|
});
|
|
104
103
|
});
|
|
105
104
|
}
|
|
106
|
-
exports
|
|
105
|
+
exports.default = aptosClient;
|
|
107
106
|
function parseResponse(response) {
|
|
108
107
|
return {
|
|
109
108
|
status: response.statusCode,
|
|
@@ -112,21 +111,9 @@ function parseResponse(response) {
|
|
|
112
111
|
config: response.request.options,
|
|
113
112
|
request: response.request,
|
|
114
113
|
response: response,
|
|
115
|
-
headers: response.headers
|
|
114
|
+
headers: response.headers,
|
|
116
115
|
};
|
|
117
116
|
}
|
|
118
|
-
function parseHeaders(response) {
|
|
119
|
-
// capitalize authorization key to be compatible with axios response
|
|
120
|
-
if (response.request.options.headers.authorization) {
|
|
121
|
-
response.request.options.headers.Authorization = response.request.options.headers.authorization;
|
|
122
|
-
delete response.request.options.headers.authorization;
|
|
123
|
-
}
|
|
124
|
-
// capitalize content-type key to be compatible with axios response
|
|
125
|
-
if (response.request.options.headers["content-type"]) {
|
|
126
|
-
response.request.options.headers["Content-Type"] = response.request.options.headers["content-type"];
|
|
127
|
-
delete response.request.options.headers["content-type"];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
117
|
/**
|
|
131
118
|
* got supports only - string | number | boolean | null | undefined as searchParam value,
|
|
132
119
|
* so if we have bigint type, convert it to string
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type AptosClientResponse<Res> = {
|
|
2
2
|
status: number;
|
|
3
3
|
statusText: string;
|
|
4
4
|
data: Res;
|
|
@@ -7,7 +7,7 @@ export declare type AptosClientResponse<Res> = {
|
|
|
7
7
|
response?: any;
|
|
8
8
|
headers?: any;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type AptosClientRequest = {
|
|
11
11
|
url: string;
|
|
12
12
|
method: "GET" | "POST";
|
|
13
13
|
body?: any;
|
package/dist/types/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/aptos-client",
|
|
3
|
-
"
|
|
3
|
+
"description": "client package for accessing the Aptos network API",
|
|
4
|
+
"packageManager": "pnpm@8.3.1",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=15.10.0"
|
|
8
|
+
},
|
|
4
9
|
"exports": {
|
|
5
10
|
"browser": {
|
|
6
11
|
"import": "./dist/browser/index.browser.mjs",
|
|
@@ -29,22 +34,42 @@
|
|
|
29
34
|
"_build:browser": "tsup src/index.browser.ts --format cjs,esm --dts --out-dir dist/browser",
|
|
30
35
|
"_build:node": "tsup src/index.node.ts --format cjs,esm --dts --out-dir dist/node",
|
|
31
36
|
"_build:types": "tsc src/types.ts src/index.node.ts --outDir dist/types --declaration",
|
|
32
|
-
"lint": "eslint \"**/*.ts\""
|
|
37
|
+
"lint": "eslint \"**/*.ts\"",
|
|
38
|
+
"fmt": "pnpm _fmt --write",
|
|
39
|
+
"_fmt": "prettier 'src/**/*.ts' '.eslintrc.js' '*.md'"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/aptos-labs/aptos-core.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/aptos-labs/aptos-core",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/aptos-labs/aptos-core/issues"
|
|
33
48
|
},
|
|
49
|
+
"author": "aptoslabs.com",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"Aptos",
|
|
52
|
+
"Aptos Labs",
|
|
53
|
+
"Aptos SDK"
|
|
54
|
+
],
|
|
34
55
|
"dependencies": {
|
|
35
|
-
"axios": "
|
|
36
|
-
"got": "^11.
|
|
56
|
+
"axios": "1.6.2",
|
|
57
|
+
"got": "^11.8.6"
|
|
37
58
|
},
|
|
38
59
|
"devDependencies": {
|
|
39
|
-
"@types/node": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"eslint": "
|
|
60
|
+
"@types/node": "20.10.4",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "6.13.2",
|
|
62
|
+
"@typescript-eslint/parser": "6.13.2",
|
|
63
|
+
"eslint": "8.55.0",
|
|
64
|
+
"eslint-config-prettier": "9.1.0",
|
|
44
65
|
"eslint-config-airbnb-base": "15.0.0",
|
|
45
|
-
"eslint-config-airbnb-typescript": "17.
|
|
46
|
-
"eslint-plugin-import": "2.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
66
|
+
"eslint-config-airbnb-typescript": "17.1.0",
|
|
67
|
+
"eslint-plugin-import": "2.29.0",
|
|
68
|
+
"prettier": "3.1.0",
|
|
69
|
+
"semver": "6.3.1",
|
|
70
|
+
"ts-node": "10.9.2",
|
|
71
|
+
"tsup": "8.0.1",
|
|
72
|
+
"typescript": "5.3.3"
|
|
73
|
+
},
|
|
74
|
+
"version": "0.1.0"
|
|
50
75
|
}
|