@ps-aux/api-client-axios 0.7.0-rc.1 → 0.7.0-rc.3

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.
@@ -1,110 +0,0 @@
1
- const convertToFormData = (payload, platform) => {
2
- const formData = platform.newFormData();
3
- const addProp = (key, val) => {
4
- if (Array.isArray(val) || platform.isFileList(val)) {
5
- for (const valItem of val) {
6
- addProp(key, valItem);
7
- }
8
- } else if (typeof val === "object" && val != null && !platform.isFile(val)) {
9
- throw new Error(
10
- `Object serialization into FormData not supported: ${JSON.stringify(val)}`
11
- );
12
- } else {
13
- if (platform.isFile(val)) {
14
- const { file, name, contentType } = platform.getFileAndName(val);
15
- if (contentType) {
16
- formData.append(key, file, {
17
- filename: name,
18
- contentType
19
- });
20
- } else {
21
- formData.append(key, file, name);
22
- }
23
- } else {
24
- formData.append(key, val);
25
- }
26
- }
27
- };
28
- Object.entries(payload).forEach(([key, val]) => addProp(key, val));
29
- return {
30
- data: formData,
31
- headers: platform.getHeaders(formData)
32
- };
33
- };
34
-
35
- const fileResFilenameRegex = /filename="([^"]+)"/;
36
- const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
37
- if (!contentDispositionHeader) return "download-file";
38
- const match = contentDispositionHeader.match(fileResFilenameRegex);
39
- const fileName = match ? match[1] : "downloaded-file";
40
- return fileName;
41
- };
42
-
43
- const createHttpClient$1 = (axios, opts) => {
44
- const { platform, querySerializer } = opts;
45
- return {
46
- request: (req) => {
47
- const { query, requestContentType, body, headers: reqHeaders } = req;
48
- const paramsSerializer = querySerializer ? (r) => querySerializer({ queryParams: r }).queryString : void 0;
49
- const isBlobResponse = req.format === "document";
50
- let headers = { ...reqHeaders || {} };
51
- let data = body;
52
- if (requestContentType === "multipart/form-data") {
53
- const form = convertToFormData(body, platform);
54
- data = form.data;
55
- headers = form.headers;
56
- } else if (requestContentType) {
57
- headers["Content-Type"] = requestContentType;
58
- }
59
- return axios.request({
60
- method: req.method,
61
- url: req.path,
62
- params: query,
63
- paramsSerializer,
64
- data,
65
- headers,
66
- responseType: isBlobResponse ? platform.getFileAxiosResponseType() : "json"
67
- }).then((r) => {
68
- const { data: data2 } = r;
69
- if (isBlobResponse) {
70
- const contDist = r.headers["content-disposition"];
71
- const fileName = getFileNameFromContentDispositionHeader(contDist);
72
- const type = r.headers["content-type"];
73
- return new File([data2], fileName, {
74
- type
75
- });
76
- }
77
- return data2;
78
- });
79
- }
80
- };
81
- };
82
-
83
- var __defProp = Object.defineProperty;
84
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
85
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
86
- class BrowserPlatFormHelper {
87
- constructor() {
88
- __publicField(this, "isFile", (obj) => obj instanceof File);
89
- __publicField(this, "getFileAndName", (obj) => {
90
- if (!(obj instanceof File)) throw new Error(`Obj ${obj} is not a file`);
91
- return {
92
- file: obj,
93
- name: obj.name
94
- };
95
- });
96
- __publicField(this, "getHeaders", () => ({}));
97
- __publicField(this, "isFileList", (obj) => obj instanceof FileList);
98
- __publicField(this, "newFormData", () => new FormData());
99
- __publicField(this, "getFileAxiosResponseType", () => "blob");
100
- }
101
- }
102
-
103
- const createHttpClient = (axios, opts) => {
104
- return createHttpClient$1(axios, {
105
- platform: new BrowserPlatFormHelper(),
106
- querySerializer: opts.querySerializer
107
- });
108
- };
109
-
110
- export { createHttpClient };
package/dist/browser.js DELETED
@@ -1,112 +0,0 @@
1
- 'use strict';
2
-
3
- const convertToFormData = (payload, platform) => {
4
- const formData = platform.newFormData();
5
- const addProp = (key, val) => {
6
- if (Array.isArray(val) || platform.isFileList(val)) {
7
- for (const valItem of val) {
8
- addProp(key, valItem);
9
- }
10
- } else if (typeof val === "object" && val != null && !platform.isFile(val)) {
11
- throw new Error(
12
- `Object serialization into FormData not supported: ${JSON.stringify(val)}`
13
- );
14
- } else {
15
- if (platform.isFile(val)) {
16
- const { file, name, contentType } = platform.getFileAndName(val);
17
- if (contentType) {
18
- formData.append(key, file, {
19
- filename: name,
20
- contentType
21
- });
22
- } else {
23
- formData.append(key, file, name);
24
- }
25
- } else {
26
- formData.append(key, val);
27
- }
28
- }
29
- };
30
- Object.entries(payload).forEach(([key, val]) => addProp(key, val));
31
- return {
32
- data: formData,
33
- headers: platform.getHeaders(formData)
34
- };
35
- };
36
-
37
- const fileResFilenameRegex = /filename="([^"]+)"/;
38
- const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
39
- if (!contentDispositionHeader) return "download-file";
40
- const match = contentDispositionHeader.match(fileResFilenameRegex);
41
- const fileName = match ? match[1] : "downloaded-file";
42
- return fileName;
43
- };
44
-
45
- const createHttpClient$1 = (axios, opts) => {
46
- const { platform, querySerializer } = opts;
47
- return {
48
- request: (req) => {
49
- const { query, requestContentType, body, headers: reqHeaders } = req;
50
- const paramsSerializer = querySerializer ? (r) => querySerializer({ queryParams: r }).queryString : void 0;
51
- const isBlobResponse = req.format === "document";
52
- let headers = { ...reqHeaders || {} };
53
- let data = body;
54
- if (requestContentType === "multipart/form-data") {
55
- const form = convertToFormData(body, platform);
56
- data = form.data;
57
- headers = form.headers;
58
- } else if (requestContentType) {
59
- headers["Content-Type"] = requestContentType;
60
- }
61
- return axios.request({
62
- method: req.method,
63
- url: req.path,
64
- params: query,
65
- paramsSerializer,
66
- data,
67
- headers,
68
- responseType: isBlobResponse ? platform.getFileAxiosResponseType() : "json"
69
- }).then((r) => {
70
- const { data: data2 } = r;
71
- if (isBlobResponse) {
72
- const contDist = r.headers["content-disposition"];
73
- const fileName = getFileNameFromContentDispositionHeader(contDist);
74
- const type = r.headers["content-type"];
75
- return new File([data2], fileName, {
76
- type
77
- });
78
- }
79
- return data2;
80
- });
81
- }
82
- };
83
- };
84
-
85
- var __defProp = Object.defineProperty;
86
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
87
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
88
- class BrowserPlatFormHelper {
89
- constructor() {
90
- __publicField(this, "isFile", (obj) => obj instanceof File);
91
- __publicField(this, "getFileAndName", (obj) => {
92
- if (!(obj instanceof File)) throw new Error(`Obj ${obj} is not a file`);
93
- return {
94
- file: obj,
95
- name: obj.name
96
- };
97
- });
98
- __publicField(this, "getHeaders", () => ({}));
99
- __publicField(this, "isFileList", (obj) => obj instanceof FileList);
100
- __publicField(this, "newFormData", () => new FormData());
101
- __publicField(this, "getFileAxiosResponseType", () => "blob");
102
- }
103
- }
104
-
105
- const createHttpClient = (axios, opts) => {
106
- return createHttpClient$1(axios, {
107
- platform: new BrowserPlatFormHelper(),
108
- querySerializer: opts.querySerializer
109
- });
110
- };
111
-
112
- exports.createHttpClient = createHttpClient;
package/dist/node.esm.js DELETED
@@ -1,132 +0,0 @@
1
- import NodeFormData from 'form-data';
2
- import stream from 'stream';
3
-
4
- const convertToFormData = (payload, platform) => {
5
- const formData = platform.newFormData();
6
- const addProp = (key, val) => {
7
- if (Array.isArray(val) || platform.isFileList(val)) {
8
- for (const valItem of val) {
9
- addProp(key, valItem);
10
- }
11
- } else if (typeof val === "object" && val != null && !platform.isFile(val)) {
12
- throw new Error(
13
- `Object serialization into FormData not supported: ${JSON.stringify(val)}`
14
- );
15
- } else {
16
- if (platform.isFile(val)) {
17
- const { file, name, contentType } = platform.getFileAndName(val);
18
- if (contentType) {
19
- formData.append(key, file, {
20
- filename: name,
21
- contentType
22
- });
23
- } else {
24
- formData.append(key, file, name);
25
- }
26
- } else {
27
- formData.append(key, val);
28
- }
29
- }
30
- };
31
- Object.entries(payload).forEach(([key, val]) => addProp(key, val));
32
- return {
33
- data: formData,
34
- headers: platform.getHeaders(formData)
35
- };
36
- };
37
-
38
- const fileResFilenameRegex = /filename="([^"]+)"/;
39
- const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
40
- if (!contentDispositionHeader) return "download-file";
41
- const match = contentDispositionHeader.match(fileResFilenameRegex);
42
- const fileName = match ? match[1] : "downloaded-file";
43
- return fileName;
44
- };
45
-
46
- const createHttpClient$1 = (axios, opts) => {
47
- const { platform, querySerializer } = opts;
48
- return {
49
- request: (req) => {
50
- const { query, requestContentType, body, headers: reqHeaders } = req;
51
- const paramsSerializer = querySerializer ? (r) => querySerializer({ queryParams: r }).queryString : void 0;
52
- const isBlobResponse = req.format === "document";
53
- let headers = { ...reqHeaders || {} };
54
- let data = body;
55
- if (requestContentType === "multipart/form-data") {
56
- const form = convertToFormData(body, platform);
57
- data = form.data;
58
- headers = form.headers;
59
- } else if (requestContentType) {
60
- headers["Content-Type"] = requestContentType;
61
- }
62
- return axios.request({
63
- method: req.method,
64
- url: req.path,
65
- params: query,
66
- paramsSerializer,
67
- data,
68
- headers,
69
- responseType: isBlobResponse ? platform.getFileAxiosResponseType() : "json"
70
- }).then((r) => {
71
- const { data: data2 } = r;
72
- if (isBlobResponse) {
73
- const contDist = r.headers["content-disposition"];
74
- const fileName = getFileNameFromContentDispositionHeader(contDist);
75
- const type = r.headers["content-type"];
76
- return new File([data2], fileName, {
77
- type
78
- });
79
- }
80
- return data2;
81
- });
82
- }
83
- };
84
- };
85
-
86
- var __defProp = Object.defineProperty;
87
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
88
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
89
- class NodePlatFormHelper {
90
- constructor() {
91
- __publicField(this, "isFile", (obj) => {
92
- if (typeof obj !== "object") return false;
93
- if (obj == null) return false;
94
- if (typeof File !== "undefined" && obj instanceof File) {
95
- return true;
96
- }
97
- const { file, name } = obj;
98
- return typeof name === "string" && (Buffer.isBuffer(file) || file instanceof stream.Readable);
99
- });
100
- __publicField(this, "getFileAndName", (obj) => {
101
- if (typeof File !== "undefined" && obj instanceof File) {
102
- return {
103
- file: stream.Readable.fromWeb(obj.stream()),
104
- name: obj.name,
105
- contentType: obj.type || void 0
106
- };
107
- }
108
- if (!this.isFile(obj)) throw new Error(`Obj ${obj} is not a file`);
109
- return {
110
- file: obj.file,
111
- name: obj.name,
112
- contentType: typeof obj.type === "string" && obj.type.length > 0 ? obj.type : void 0
113
- };
114
- });
115
- __publicField(this, "isFileList", (obj) => typeof FileList !== "undefined" && obj instanceof FileList);
116
- // @ts-ignore
117
- __publicField(this, "newFormData", () => new NodeFormData());
118
- __publicField(this, "getHeaders", (data) => {
119
- return data.getHeaders();
120
- });
121
- __publicField(this, "getFileAxiosResponseType", () => "arraybuffer");
122
- }
123
- }
124
-
125
- const createHttpClient = (axios, opts) => {
126
- return createHttpClient$1(axios, {
127
- platform: new NodePlatFormHelper(),
128
- querySerializer: opts.querySerializer
129
- });
130
- };
131
-
132
- export { createHttpClient };
package/dist/node.js DELETED
@@ -1,134 +0,0 @@
1
- 'use strict';
2
-
3
- var NodeFormData = require('form-data');
4
- var stream = require('stream');
5
-
6
- const convertToFormData = (payload, platform) => {
7
- const formData = platform.newFormData();
8
- const addProp = (key, val) => {
9
- if (Array.isArray(val) || platform.isFileList(val)) {
10
- for (const valItem of val) {
11
- addProp(key, valItem);
12
- }
13
- } else if (typeof val === "object" && val != null && !platform.isFile(val)) {
14
- throw new Error(
15
- `Object serialization into FormData not supported: ${JSON.stringify(val)}`
16
- );
17
- } else {
18
- if (platform.isFile(val)) {
19
- const { file, name, contentType } = platform.getFileAndName(val);
20
- if (contentType) {
21
- formData.append(key, file, {
22
- filename: name,
23
- contentType
24
- });
25
- } else {
26
- formData.append(key, file, name);
27
- }
28
- } else {
29
- formData.append(key, val);
30
- }
31
- }
32
- };
33
- Object.entries(payload).forEach(([key, val]) => addProp(key, val));
34
- return {
35
- data: formData,
36
- headers: platform.getHeaders(formData)
37
- };
38
- };
39
-
40
- const fileResFilenameRegex = /filename="([^"]+)"/;
41
- const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
42
- if (!contentDispositionHeader) return "download-file";
43
- const match = contentDispositionHeader.match(fileResFilenameRegex);
44
- const fileName = match ? match[1] : "downloaded-file";
45
- return fileName;
46
- };
47
-
48
- const createHttpClient$1 = (axios, opts) => {
49
- const { platform, querySerializer } = opts;
50
- return {
51
- request: (req) => {
52
- const { query, requestContentType, body, headers: reqHeaders } = req;
53
- const paramsSerializer = querySerializer ? (r) => querySerializer({ queryParams: r }).queryString : void 0;
54
- const isBlobResponse = req.format === "document";
55
- let headers = { ...reqHeaders || {} };
56
- let data = body;
57
- if (requestContentType === "multipart/form-data") {
58
- const form = convertToFormData(body, platform);
59
- data = form.data;
60
- headers = form.headers;
61
- } else if (requestContentType) {
62
- headers["Content-Type"] = requestContentType;
63
- }
64
- return axios.request({
65
- method: req.method,
66
- url: req.path,
67
- params: query,
68
- paramsSerializer,
69
- data,
70
- headers,
71
- responseType: isBlobResponse ? platform.getFileAxiosResponseType() : "json"
72
- }).then((r) => {
73
- const { data: data2 } = r;
74
- if (isBlobResponse) {
75
- const contDist = r.headers["content-disposition"];
76
- const fileName = getFileNameFromContentDispositionHeader(contDist);
77
- const type = r.headers["content-type"];
78
- return new File([data2], fileName, {
79
- type
80
- });
81
- }
82
- return data2;
83
- });
84
- }
85
- };
86
- };
87
-
88
- var __defProp = Object.defineProperty;
89
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
90
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
91
- class NodePlatFormHelper {
92
- constructor() {
93
- __publicField(this, "isFile", (obj) => {
94
- if (typeof obj !== "object") return false;
95
- if (obj == null) return false;
96
- if (typeof File !== "undefined" && obj instanceof File) {
97
- return true;
98
- }
99
- const { file, name } = obj;
100
- return typeof name === "string" && (Buffer.isBuffer(file) || file instanceof stream.Readable);
101
- });
102
- __publicField(this, "getFileAndName", (obj) => {
103
- if (typeof File !== "undefined" && obj instanceof File) {
104
- return {
105
- file: stream.Readable.fromWeb(obj.stream()),
106
- name: obj.name,
107
- contentType: obj.type || void 0
108
- };
109
- }
110
- if (!this.isFile(obj)) throw new Error(`Obj ${obj} is not a file`);
111
- return {
112
- file: obj.file,
113
- name: obj.name,
114
- contentType: typeof obj.type === "string" && obj.type.length > 0 ? obj.type : void 0
115
- };
116
- });
117
- __publicField(this, "isFileList", (obj) => typeof FileList !== "undefined" && obj instanceof FileList);
118
- // @ts-ignore
119
- __publicField(this, "newFormData", () => new NodeFormData());
120
- __publicField(this, "getHeaders", (data) => {
121
- return data.getHeaders();
122
- });
123
- __publicField(this, "getFileAxiosResponseType", () => "arraybuffer");
124
- }
125
- }
126
-
127
- const createHttpClient = (axios, opts) => {
128
- return createHttpClient$1(axios, {
129
- platform: new NodePlatFormHelper(),
130
- querySerializer: opts.querySerializer
131
- });
132
- };
133
-
134
- exports.createHttpClient = createHttpClient;