@xylabs/axios 2.13.4

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/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ [![logo][]](https://xylabs.com)
2
+
3
+ # @xylabs/axios
4
+
5
+ [![npm-badge][]][npm-link]
6
+ [![npm-downloads-badge][]][npm-link]
7
+ [![jsdelivr-badge][]][jsdelivr-link]
8
+ [![npm-license-badge][]](LICENSE)
9
+ [![socket-badge][]][socket-link]
10
+
11
+ > XY Labs generalized Javascript library
12
+
13
+ ## Table of Contents
14
+
15
+ - [Description](#description)
16
+ - [Install](#install)
17
+ - [Maintainers](#maintainers)
18
+ - [License](#license)
19
+ - [Credits](#credits)
20
+
21
+ ## Description
22
+
23
+ Common Javascript code that is used throughout XYO projects that use React.
24
+
25
+ ## Install
26
+
27
+ Using npm:
28
+
29
+ ```sh
30
+ npm i --save @xylabs/axios
31
+ ```
32
+
33
+ Using yarn:
34
+
35
+ ```sh
36
+ yarn add @xylabs/axios
37
+ ```
38
+
39
+ ## Documentation
40
+ [Developer Reference](https://xylabs.github.io/sdk-js)
41
+
42
+ ## Maintainers
43
+
44
+ - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
45
+ - [Joel Carter](https://github.com/JoelBCarter)
46
+ - [Matt Jones](https://github.com/jonesmac)
47
+ - [Jordan Trouw](https://github.com/jordantrouw)
48
+
49
+ ## License
50
+
51
+ See the [LICENSE](LICENSE) file for license details
52
+
53
+ ## Credits
54
+
55
+ [Made with 🔥and ❄️ by XY Labs](https://xylabs.com)
56
+
57
+ [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
58
+
59
+ [npm-badge]: https://img.shields.io/npm/v/@xylabs/axios.svg
60
+ [npm-link]: https://www.npmjs.com/package/@xylabs/axios
61
+
62
+ [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/axios
63
+ [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/axios
64
+
65
+ [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/axios/badge
66
+ [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/axios
67
+
68
+ [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/axios
69
+ [socket-link]: https://socket.dev/npm/package/@xylabs/axios
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ AxiosJson: () => AxiosJson,
35
+ axios: () => import_axios2.default,
36
+ gzip: () => import_pako2.gzip
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+
40
+ // src/AxiosJson.ts
41
+ var import_axios = require("axios");
42
+ var import_pako = require("pako");
43
+ var AxiosJson = class _AxiosJson extends import_axios.Axios {
44
+ static defaultLogger;
45
+ constructor(config) {
46
+ super(_AxiosJson.axiosConfig(config));
47
+ }
48
+ static finalPath(response) {
49
+ if (response.request.path) {
50
+ return response.request.path.split("/").pop();
51
+ } else if (response.request.responseURL) {
52
+ return response.request.responseURL.split("/").pop();
53
+ } else {
54
+ this.defaultLogger?.warn("Failed to get final path from response");
55
+ }
56
+ }
57
+ static axiosConfig({ compressLength, headers, ...config } = {}) {
58
+ return {
59
+ headers: this.buildHeaders(headers),
60
+ transformRequest: (data, headers2) => {
61
+ const json = JSON.stringify(data);
62
+ if (headers2 && data) {
63
+ if (json.length > (compressLength ?? 1024)) {
64
+ headers2["Content-Encoding"] = "gzip";
65
+ return (0, import_pako.gzip)(JSON.stringify(data)).buffer;
66
+ }
67
+ }
68
+ return JSON.stringify(data);
69
+ },
70
+ transformResponse: (data) => {
71
+ try {
72
+ return JSON.parse(data);
73
+ } catch (ex) {
74
+ return null;
75
+ }
76
+ },
77
+ ...config
78
+ };
79
+ }
80
+ static buildHeaders(headers) {
81
+ const axiosHeaders = new import_axios.AxiosHeaders();
82
+ Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value));
83
+ axiosHeaders.set("Accept", "application/json, text/plain, *.*");
84
+ axiosHeaders.set("Content-Type", "application/json");
85
+ return axiosHeaders;
86
+ }
87
+ };
88
+
89
+ // src/index.ts
90
+ var import_axios2 = __toESM(require("axios"), 1);
91
+ var import_pako2 = require("pako");
92
+ __reExport(src_exports, require("axios"), module.exports);
93
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/AxiosJson.ts"],"sourcesContent":["export * from './AxiosJson'\nimport axios from 'axios'\nexport { gzip } from 'pako'\nexport { axios }\nexport * from 'axios'\n","import { Logger } from '@xylabs/logger'\nimport { Axios, AxiosHeaders, AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { gzip } from 'pako'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n //nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n //browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ compressLength, headers, ...config }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers && data) {\n if (json.length > (compressLength ?? 1024)) {\n headers['Content-Encoding'] = 'gzip'\n return gzip(JSON.stringify(data)).buffer\n }\n }\n return JSON.stringify(data)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch (ex) {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value))\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n return axiosHeaders\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,6BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACCA,mBAA0E;AAC1E,kBAAqB;AAKd,IAAM,YAAN,MAAM,mBAAkB,mBAAM;AAAA,EACnC,OAAO;AAAA,EAEP,YAAY,QAAoC;AAC9C,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,UAAU,UAAyB;AACxC,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,WAAK,eAAe,KAAK,wCAAwC;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,OAAe,YAAY,EAAE,gBAAgB,SAAS,GAAG,OAAO,IAA+B,CAAC,GAA8B;AAC5H,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,MAAMC,aAAY;AACnC,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,YAAIA,YAAW,MAAM;AACnB,cAAI,KAAK,UAAU,kBAAkB,OAAO;AAC1C,YAAAA,SAAQ,kBAAkB,IAAI;AAC9B,uBAAO,kBAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAAA,UACpC;AAAA,QACF;AACA,eAAO,KAAK,UAAU,IAAI;AAAA,MAC5B;AAAA,MACA,mBAAmB,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,SAAS,IAAI;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAA+C;AACzE,UAAM,eAAe,IAAI,0BAAa;AACtC,WAAO,QAAQ,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,aAAa,IAAI,KAAK,KAAK,CAAC;AACpF,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,WAAO;AAAA,EACT;AACF;;;ADxDA,IAAAC,gBAAkB;AAClB,IAAAC,eAAqB;AAErB,wBAAc,kBAJd;","names":["axios","headers","import_axios","import_pako"]}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,59 @@
1
+ // src/AxiosJson.ts
2
+ import { Axios, AxiosHeaders } from "axios";
3
+ import { gzip } from "pako";
4
+ var AxiosJson = class _AxiosJson extends Axios {
5
+ static defaultLogger;
6
+ constructor(config) {
7
+ super(_AxiosJson.axiosConfig(config));
8
+ }
9
+ static finalPath(response) {
10
+ if (response.request.path) {
11
+ return response.request.path.split("/").pop();
12
+ } else if (response.request.responseURL) {
13
+ return response.request.responseURL.split("/").pop();
14
+ } else {
15
+ this.defaultLogger?.warn("Failed to get final path from response");
16
+ }
17
+ }
18
+ static axiosConfig({ compressLength, headers, ...config } = {}) {
19
+ return {
20
+ headers: this.buildHeaders(headers),
21
+ transformRequest: (data, headers2) => {
22
+ const json = JSON.stringify(data);
23
+ if (headers2 && data) {
24
+ if (json.length > (compressLength ?? 1024)) {
25
+ headers2["Content-Encoding"] = "gzip";
26
+ return gzip(JSON.stringify(data)).buffer;
27
+ }
28
+ }
29
+ return JSON.stringify(data);
30
+ },
31
+ transformResponse: (data) => {
32
+ try {
33
+ return JSON.parse(data);
34
+ } catch (ex) {
35
+ return null;
36
+ }
37
+ },
38
+ ...config
39
+ };
40
+ }
41
+ static buildHeaders(headers) {
42
+ const axiosHeaders = new AxiosHeaders();
43
+ Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value));
44
+ axiosHeaders.set("Accept", "application/json, text/plain, *.*");
45
+ axiosHeaders.set("Content-Type", "application/json");
46
+ return axiosHeaders;
47
+ }
48
+ };
49
+
50
+ // src/index.ts
51
+ import axios from "axios";
52
+ import { gzip as gzip2 } from "pako";
53
+ export * from "axios";
54
+ export {
55
+ AxiosJson,
56
+ axios,
57
+ gzip2 as gzip
58
+ };
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/AxiosJson.ts","../../src/index.ts"],"sourcesContent":["import { Logger } from '@xylabs/logger'\nimport { Axios, AxiosHeaders, AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { gzip } from 'pako'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n //nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n //browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ compressLength, headers, ...config }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers && data) {\n if (json.length > (compressLength ?? 1024)) {\n headers['Content-Encoding'] = 'gzip'\n return gzip(JSON.stringify(data)).buffer\n }\n }\n return JSON.stringify(data)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch (ex) {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value))\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n return axiosHeaders\n }\n}\n","export * from './AxiosJson'\nimport axios from 'axios'\nexport { gzip } from 'pako'\nexport { axios }\nexport * from 'axios'\n"],"mappings":";AACA,SAAS,OAAO,oBAA0D;AAC1E,SAAS,YAAY;AAKd,IAAM,YAAN,MAAM,mBAAkB,MAAM;AAAA,EACnC,OAAO;AAAA,EAEP,YAAY,QAAoC;AAC9C,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,UAAU,UAAyB;AACxC,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,WAAK,eAAe,KAAK,wCAAwC;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,OAAe,YAAY,EAAE,gBAAgB,SAAS,GAAG,OAAO,IAA+B,CAAC,GAA8B;AAC5H,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,MAAMA,aAAY;AACnC,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,YAAIA,YAAW,MAAM;AACnB,cAAI,KAAK,UAAU,kBAAkB,OAAO;AAC1C,YAAAA,SAAQ,kBAAkB,IAAI;AAC9B,mBAAO,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAAA,UACpC;AAAA,QACF;AACA,eAAO,KAAK,UAAU,IAAI;AAAA,MAC5B;AAAA,MACA,mBAAmB,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,SAAS,IAAI;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAA+C;AACzE,UAAM,eAAe,IAAI,aAAa;AACtC,WAAO,QAAQ,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,aAAa,IAAI,KAAK,KAAK,CAAC;AACpF,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,WAAO;AAAA,EACT;AACF;;;ACxDA,OAAO,WAAW;AAClB,SAAS,QAAAC,aAAY;AAErB,cAAc;","names":["headers","gzip"]}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '@xylabs/logger';
2
+ import { Axios, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
4
+ compressLength?: number;
5
+ };
6
+ export declare class AxiosJson extends Axios {
7
+ static defaultLogger?: Logger;
8
+ constructor(config?: RawAxiosJsonRequestConfig);
9
+ static finalPath(response: AxiosResponse): any;
10
+ private static axiosConfig;
11
+ private static buildHeaders;
12
+ }
13
+ //# sourceMappingURL=AxiosJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAgB,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAIjF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ AxiosJson: () => AxiosJson,
35
+ axios: () => import_axios2.default,
36
+ gzip: () => import_pako2.gzip
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+
40
+ // src/AxiosJson.ts
41
+ var import_axios = require("axios");
42
+ var import_pako = require("pako");
43
+ var AxiosJson = class _AxiosJson extends import_axios.Axios {
44
+ static defaultLogger;
45
+ constructor(config) {
46
+ super(_AxiosJson.axiosConfig(config));
47
+ }
48
+ static finalPath(response) {
49
+ var _a;
50
+ if (response.request.path) {
51
+ return response.request.path.split("/").pop();
52
+ } else if (response.request.responseURL) {
53
+ return response.request.responseURL.split("/").pop();
54
+ } else {
55
+ (_a = this.defaultLogger) == null ? void 0 : _a.warn("Failed to get final path from response");
56
+ }
57
+ }
58
+ static axiosConfig({ compressLength, headers, ...config } = {}) {
59
+ return {
60
+ headers: this.buildHeaders(headers),
61
+ transformRequest: (data, headers2) => {
62
+ const json = JSON.stringify(data);
63
+ if (headers2 && data) {
64
+ if (json.length > (compressLength ?? 1024)) {
65
+ headers2["Content-Encoding"] = "gzip";
66
+ return (0, import_pako.gzip)(JSON.stringify(data)).buffer;
67
+ }
68
+ }
69
+ return JSON.stringify(data);
70
+ },
71
+ transformResponse: (data) => {
72
+ try {
73
+ return JSON.parse(data);
74
+ } catch (ex) {
75
+ return null;
76
+ }
77
+ },
78
+ ...config
79
+ };
80
+ }
81
+ static buildHeaders(headers) {
82
+ const axiosHeaders = new import_axios.AxiosHeaders();
83
+ Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value));
84
+ axiosHeaders.set("Accept", "application/json, text/plain, *.*");
85
+ axiosHeaders.set("Content-Type", "application/json");
86
+ return axiosHeaders;
87
+ }
88
+ };
89
+
90
+ // src/index.ts
91
+ var import_axios2 = __toESM(require("axios"), 1);
92
+ var import_pako2 = require("pako");
93
+ __reExport(src_exports, require("axios"), module.exports);
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ AxiosJson,
97
+ axios,
98
+ gzip,
99
+ ...require("axios")
100
+ });
101
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/AxiosJson.ts"],"sourcesContent":["export * from './AxiosJson'\nimport axios from 'axios'\nexport { gzip } from 'pako'\nexport { axios }\nexport * from 'axios'\n","import { Logger } from '@xylabs/logger'\nimport { Axios, AxiosHeaders, AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { gzip } from 'pako'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n //nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n //browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ compressLength, headers, ...config }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers && data) {\n if (json.length > (compressLength ?? 1024)) {\n headers['Content-Encoding'] = 'gzip'\n return gzip(JSON.stringify(data)).buffer\n }\n }\n return JSON.stringify(data)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch (ex) {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value))\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n return axiosHeaders\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,6BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACCA,mBAA0E;AAC1E,kBAAqB;AAKd,IAAM,YAAN,MAAM,mBAAkB,mBAAM;AAAA,EACnC,OAAO;AAAA,EAEP,YAAY,QAAoC;AAC9C,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,UAAU,UAAyB;AAd5C;AAeI,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,iBAAK,kBAAL,mBAAoB,KAAK;AAAA,IAC3B;AAAA,EACF;AAAA,EAEA,OAAe,YAAY,EAAE,gBAAgB,SAAS,GAAG,OAAO,IAA+B,CAAC,GAA8B;AAC5H,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,MAAMC,aAAY;AACnC,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,YAAIA,YAAW,MAAM;AACnB,cAAI,KAAK,UAAU,kBAAkB,OAAO;AAC1C,YAAAA,SAAQ,kBAAkB,IAAI;AAC9B,uBAAO,kBAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAAA,UACpC;AAAA,QACF;AACA,eAAO,KAAK,UAAU,IAAI;AAAA,MAC5B;AAAA,MACA,mBAAmB,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,SAAS,IAAI;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAA+C;AACzE,UAAM,eAAe,IAAI,0BAAa;AACtC,WAAO,QAAQ,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,aAAa,IAAI,KAAK,KAAK,CAAC;AACpF,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,WAAO;AAAA,EACT;AACF;;;ADxDA,IAAAC,gBAAkB;AAClB,IAAAC,eAAqB;AAErB,wBAAc,kBAJd;","names":["axios","headers","import_axios","import_pako"]}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './AxiosJson';
2
+ import axios from 'axios';
3
+ export { gzip } from 'pako';
4
+ export { axios };
5
+ export * from 'axios';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,cAAc,OAAO,CAAA"}
@@ -0,0 +1,60 @@
1
+ // src/AxiosJson.ts
2
+ import { Axios, AxiosHeaders } from "axios";
3
+ import { gzip } from "pako";
4
+ var AxiosJson = class _AxiosJson extends Axios {
5
+ static defaultLogger;
6
+ constructor(config) {
7
+ super(_AxiosJson.axiosConfig(config));
8
+ }
9
+ static finalPath(response) {
10
+ var _a;
11
+ if (response.request.path) {
12
+ return response.request.path.split("/").pop();
13
+ } else if (response.request.responseURL) {
14
+ return response.request.responseURL.split("/").pop();
15
+ } else {
16
+ (_a = this.defaultLogger) == null ? void 0 : _a.warn("Failed to get final path from response");
17
+ }
18
+ }
19
+ static axiosConfig({ compressLength, headers, ...config } = {}) {
20
+ return {
21
+ headers: this.buildHeaders(headers),
22
+ transformRequest: (data, headers2) => {
23
+ const json = JSON.stringify(data);
24
+ if (headers2 && data) {
25
+ if (json.length > (compressLength ?? 1024)) {
26
+ headers2["Content-Encoding"] = "gzip";
27
+ return gzip(JSON.stringify(data)).buffer;
28
+ }
29
+ }
30
+ return JSON.stringify(data);
31
+ },
32
+ transformResponse: (data) => {
33
+ try {
34
+ return JSON.parse(data);
35
+ } catch (ex) {
36
+ return null;
37
+ }
38
+ },
39
+ ...config
40
+ };
41
+ }
42
+ static buildHeaders(headers) {
43
+ const axiosHeaders = new AxiosHeaders();
44
+ Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value));
45
+ axiosHeaders.set("Accept", "application/json, text/plain, *.*");
46
+ axiosHeaders.set("Content-Type", "application/json");
47
+ return axiosHeaders;
48
+ }
49
+ };
50
+
51
+ // src/index.ts
52
+ import axios from "axios";
53
+ import { gzip as gzip2 } from "pako";
54
+ export * from "axios";
55
+ export {
56
+ AxiosJson,
57
+ axios,
58
+ gzip2 as gzip
59
+ };
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/AxiosJson.ts","../../src/index.ts"],"sourcesContent":["import { Logger } from '@xylabs/logger'\nimport { Axios, AxiosHeaders, AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { gzip } from 'pako'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport class AxiosJson extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n //nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n //browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ compressLength, headers, ...config }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers && data) {\n if (json.length > (compressLength ?? 1024)) {\n headers['Content-Encoding'] = 'gzip'\n return gzip(JSON.stringify(data)).buffer\n }\n }\n return JSON.stringify(data)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch (ex) {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value))\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n return axiosHeaders\n }\n}\n","export * from './AxiosJson'\nimport axios from 'axios'\nexport { gzip } from 'pako'\nexport { axios }\nexport * from 'axios'\n"],"mappings":";AACA,SAAS,OAAO,oBAA0D;AAC1E,SAAS,YAAY;AAKd,IAAM,YAAN,MAAM,mBAAkB,MAAM;AAAA,EACnC,OAAO;AAAA,EAEP,YAAY,QAAoC;AAC9C,UAAM,WAAU,YAAY,MAAM,CAAC;AAAA,EACrC;AAAA,EAEA,OAAO,UAAU,UAAyB;AAd5C;AAeI,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,iBAAK,kBAAL,mBAAoB,KAAK;AAAA,IAC3B;AAAA,EACF;AAAA,EAEA,OAAe,YAAY,EAAE,gBAAgB,SAAS,GAAG,OAAO,IAA+B,CAAC,GAA8B;AAC5H,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,MAAMA,aAAY;AACnC,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,YAAIA,YAAW,MAAM;AACnB,cAAI,KAAK,UAAU,kBAAkB,OAAO;AAC1C,YAAAA,SAAQ,kBAAkB,IAAI;AAC9B,mBAAO,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAAA,UACpC;AAAA,QACF;AACA,eAAO,KAAK,UAAU,IAAI;AAAA,MAC5B;AAAA,MACA,mBAAmB,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,SAAS,IAAI;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAA+C;AACzE,UAAM,eAAe,IAAI,aAAa;AACtC,WAAO,QAAQ,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,aAAa,IAAI,KAAK,KAAK,CAAC;AACpF,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,WAAO;AAAA,EACT;AACF;;;ACxDA,OAAO,WAAW;AAClB,SAAS,QAAAC,aAAY;AAErB,cAAc;","names":["headers","gzip"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@xylabs/axios",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@xylabs/logger": "~2.13.4",
14
+ "axios": "^1.6.2",
15
+ "pako": "^2.1.0"
16
+ },
17
+ "description": "Primary SDK for using XYO Protocol 2.0",
18
+ "devDependencies": {
19
+ "@types/pako": "^2.0.3",
20
+ "@xylabs/ts-scripts-yarn3": "^3.1.21",
21
+ "@xylabs/tsconfig": "^3.1.21",
22
+ "typescript": "^5.2.2"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "browser": {
27
+ "require": {
28
+ "types": "./dist/browser/index.d.cts",
29
+ "default": "./dist/browser/index.cjs"
30
+ },
31
+ "import": {
32
+ "types": "./dist/browser/index.d.mts",
33
+ "default": "./dist/browser/index.js"
34
+ }
35
+ },
36
+ "node": {
37
+ "require": {
38
+ "types": "./dist/node/index.d.cts",
39
+ "default": "./dist/node/index.cjs"
40
+ },
41
+ "import": {
42
+ "types": "./dist/node/index.d.mts",
43
+ "default": "./dist/node/index.js"
44
+ }
45
+ }
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "main": "dist/node/index.cjs",
50
+ "module": "dist/node/index.js",
51
+ "types": "dist/node/index.d.mts",
52
+ "homepage": "https://xyo.network",
53
+ "license": "LGPL-3.0-only",
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
60
+ },
61
+ "sideEffects": false,
62
+ "version": "2.13.4",
63
+ "type": "module"
64
+ }
@@ -0,0 +1,58 @@
1
+ import { Logger } from '@xylabs/logger'
2
+ import { Axios, AxiosHeaders, AxiosResponse, RawAxiosRequestConfig } from 'axios'
3
+ import { gzip } from 'pako'
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }
7
+
8
+ export class AxiosJson extends Axios {
9
+ static defaultLogger?: Logger
10
+
11
+ constructor(config?: RawAxiosJsonRequestConfig) {
12
+ super(AxiosJson.axiosConfig(config))
13
+ }
14
+
15
+ static finalPath(response: AxiosResponse) {
16
+ if (response.request.path) {
17
+ //nodejs
18
+ return response.request.path.split('/').pop()
19
+ } else if (response.request.responseURL) {
20
+ //browser
21
+ return response.request.responseURL.split('/').pop()
22
+ } else {
23
+ this.defaultLogger?.warn('Failed to get final path from response')
24
+ }
25
+ }
26
+
27
+ private static axiosConfig({ compressLength, headers, ...config }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {
28
+ return {
29
+ headers: this.buildHeaders(headers),
30
+ transformRequest: (data, headers) => {
31
+ const json = JSON.stringify(data)
32
+ if (headers && data) {
33
+ if (json.length > (compressLength ?? 1024)) {
34
+ headers['Content-Encoding'] = 'gzip'
35
+ return gzip(JSON.stringify(data)).buffer
36
+ }
37
+ }
38
+ return JSON.stringify(data)
39
+ },
40
+ transformResponse: (data) => {
41
+ try {
42
+ return JSON.parse(data)
43
+ } catch (ex) {
44
+ return null
45
+ }
46
+ },
47
+ ...config,
48
+ }
49
+ }
50
+
51
+ private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {
52
+ const axiosHeaders = new AxiosHeaders()
53
+ Object.entries(headers ?? {}).forEach(([key, value]) => axiosHeaders.set(key, value))
54
+ axiosHeaders.set('Accept', 'application/json, text/plain, *.*')
55
+ axiosHeaders.set('Content-Type', 'application/json')
56
+ return axiosHeaders
57
+ }
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './AxiosJson'
2
+ import axios from 'axios'
3
+ export { gzip } from 'pako'
4
+ export { axios }
5
+ export * from 'axios'
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["./src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }