@pdg/api 1.0.20 → 1.0.22
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/README.md +1 -1
- package/dist/Api/Api.d.ts +12 -6
- package/dist/Api/Api.types.d.ts +18 -9
- package/dist/index.esm.js +62 -7
- package/dist/index.js +64 -9
- package/package.json +10 -13
package/README.md
CHANGED
package/dist/Api/Api.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
2
|
import { ApiRequestData, ApiOption, ApiRequestOption } from './Api.types';
|
|
3
|
-
declare class Api<T = any> {
|
|
3
|
+
declare class Api<T = any, D extends ApiRequestData = {}> {
|
|
4
4
|
option: ApiOption;
|
|
5
|
+
/********************************************************************************************************************
|
|
6
|
+
* constructor
|
|
7
|
+
* ******************************************************************************************************************/
|
|
5
8
|
constructor(option: ApiOption<T>);
|
|
6
|
-
get(path: string, data?:
|
|
7
|
-
post(path: string, data?:
|
|
8
|
-
patch(path: string, data?:
|
|
9
|
-
delete(path: string, data?:
|
|
10
|
-
|
|
9
|
+
get(path: string, data?: D, option?: ApiRequestOption): Promise<T>;
|
|
10
|
+
post(path: string, data?: D, option?: ApiRequestOption): Promise<T>;
|
|
11
|
+
patch(path: string, data?: D, option?: ApiRequestOption): Promise<T>;
|
|
12
|
+
delete(path: string, data?: D, option?: ApiRequestOption): Promise<T>;
|
|
13
|
+
/********************************************************************************************************************
|
|
14
|
+
* run
|
|
15
|
+
* ******************************************************************************************************************/
|
|
16
|
+
run: (method: Method, path: string, data?: D, option?: ApiRequestOption) => Promise<T>;
|
|
11
17
|
}
|
|
12
18
|
export default Api;
|
package/dist/Api/Api.types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, ResponseType } from 'axios';
|
|
2
|
+
/********************************************************************************************************************
|
|
3
|
+
* ApiRequestData, ApiRequestOption, ApiRequestConfig
|
|
4
|
+
* ******************************************************************************************************************/
|
|
2
5
|
export interface ApiRequestData {
|
|
3
6
|
[key: string]: any;
|
|
4
7
|
}
|
|
@@ -7,28 +10,34 @@ export interface ApiRequestOption {
|
|
|
7
10
|
rawResponseType?: ResponseType;
|
|
8
11
|
silent?: boolean;
|
|
9
12
|
}
|
|
10
|
-
export interface ApiRequestConfig extends AxiosRequestConfig {
|
|
13
|
+
export interface ApiRequestConfig<D = ApiRequestData> extends AxiosRequestConfig<D> {
|
|
11
14
|
silent?: boolean;
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
/********************************************************************************************************************
|
|
17
|
+
* ApiError
|
|
18
|
+
* ******************************************************************************************************************/
|
|
19
|
+
export declare class ApiError<T = any, D = ApiRequestData> extends Error {
|
|
14
20
|
code?: string;
|
|
15
|
-
config?: ApiRequestConfig
|
|
21
|
+
config?: ApiRequestConfig<D>;
|
|
16
22
|
baseUrl?: string;
|
|
17
23
|
path?: string;
|
|
18
|
-
requestData?:
|
|
24
|
+
requestData?: D;
|
|
19
25
|
requestOption?: ApiRequestOption;
|
|
20
|
-
response?: AxiosResponse<T>;
|
|
26
|
+
response?: AxiosResponse<T, D>;
|
|
21
27
|
status?: number;
|
|
22
28
|
isAxiosError: boolean;
|
|
23
29
|
constructor(message?: string, code?: string);
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
/********************************************************************************************************************
|
|
32
|
+
* ApiOption
|
|
33
|
+
* ******************************************************************************************************************/
|
|
34
|
+
export interface ApiOption<T = any, D = ApiRequestData> {
|
|
26
35
|
baseUrl: string;
|
|
27
36
|
timeParamName: string;
|
|
28
37
|
withCredentials?: boolean;
|
|
29
38
|
headers?: AxiosRequestConfig['headers'];
|
|
30
|
-
onRequest?(config: InternalAxiosRequestConfig
|
|
31
|
-
onResponse?(response: AxiosResponse<T>, config: AxiosRequestConfig
|
|
32
|
-
onError?(err: ApiError): void;
|
|
39
|
+
onRequest?(config: InternalAxiosRequestConfig<D>, baseUrl: string, path: string, requestData?: D, requestOption?: ApiRequestOption): Promise<InternalAxiosRequestConfig<D>>;
|
|
40
|
+
onResponse?(response: AxiosResponse<T, D>, config: AxiosRequestConfig<D>, baseUrl: string, path: string, requestData?: D, requestOption?: ApiRequestOption): Promise<T>;
|
|
41
|
+
onError?(err: ApiError<T, D>): void;
|
|
33
42
|
dataKeysToLowerCase?: boolean;
|
|
34
43
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import axios from'axios'
|
|
1
|
+
import axios from'axios';/******************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation.
|
|
3
3
|
|
|
4
4
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -81,7 +81,9 @@ function __generator(thisArg, body) {
|
|
|
81
81
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
82
82
|
var e = new Error(message);
|
|
83
83
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
84
|
-
}
|
|
84
|
+
};/********************************************************************************************************************
|
|
85
|
+
* ApiError
|
|
86
|
+
* ******************************************************************************************************************/
|
|
85
87
|
var ApiError = /** @class */ (function (_super) {
|
|
86
88
|
__extends(ApiError, _super);
|
|
87
89
|
function ApiError(message, code) {
|
|
@@ -94,10 +96,14 @@ var ApiError = /** @class */ (function (_super) {
|
|
|
94
96
|
}(Error));var _a;
|
|
95
97
|
var AxiosCreate = axios.create ? axios.create : (_a = require('axios').default) === null || _a === void 0 ? void 0 : _a.create;
|
|
96
98
|
var Api = /** @class */ (function () {
|
|
97
|
-
|
|
99
|
+
/********************************************************************************************************************
|
|
100
|
+
* constructor
|
|
101
|
+
* ******************************************************************************************************************/
|
|
98
102
|
function Api(option) {
|
|
99
103
|
var _this = this;
|
|
100
|
-
|
|
104
|
+
/********************************************************************************************************************
|
|
105
|
+
* run
|
|
106
|
+
* ******************************************************************************************************************/
|
|
101
107
|
this.run = function (method, path, data, option) {
|
|
102
108
|
return new Promise(function (resolve, reject) {
|
|
103
109
|
var _a;
|
|
@@ -187,8 +193,7 @@ var Api = /** @class */ (function () {
|
|
|
187
193
|
.then(function (res) {
|
|
188
194
|
var resData = res.data;
|
|
189
195
|
if (_this.option.onResponse) {
|
|
190
|
-
_this.option
|
|
191
|
-
.onResponse(res, requestConfig, _this.option.baseUrl, path, data, option)
|
|
196
|
+
_this.option.onResponse(res, requestConfig, _this.option.baseUrl, path, data, option)
|
|
192
197
|
.then(function (finalResData) {
|
|
193
198
|
resolve(finalResData);
|
|
194
199
|
})
|
|
@@ -224,4 +229,54 @@ var Api = /** @class */ (function () {
|
|
|
224
229
|
return this.run('delete', path, data, option);
|
|
225
230
|
};
|
|
226
231
|
return Api;
|
|
227
|
-
}());
|
|
232
|
+
}());
|
|
233
|
+
/********************************************************************************************************************
|
|
234
|
+
* empty
|
|
235
|
+
* ******************************************************************************************************************/
|
|
236
|
+
function empty(v) {
|
|
237
|
+
var result = false;
|
|
238
|
+
if (v == null) {
|
|
239
|
+
result = true;
|
|
240
|
+
}
|
|
241
|
+
else if (typeof v === 'string') {
|
|
242
|
+
result = v === '';
|
|
243
|
+
}
|
|
244
|
+
else if (typeof v === 'object') {
|
|
245
|
+
if (Array.isArray(v)) {
|
|
246
|
+
result = v.length === 0;
|
|
247
|
+
}
|
|
248
|
+
else if (!(v instanceof Date)) {
|
|
249
|
+
result = Object.entries(v).length === 0;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
/********************************************************************************************************************
|
|
255
|
+
* notEmpty
|
|
256
|
+
* ******************************************************************************************************************/
|
|
257
|
+
function notEmpty(v) {
|
|
258
|
+
return !empty(v);
|
|
259
|
+
}
|
|
260
|
+
/********************************************************************************************************************
|
|
261
|
+
* urlJoin
|
|
262
|
+
* ******************************************************************************************************************/
|
|
263
|
+
function urlJoin() {
|
|
264
|
+
var parts = [];
|
|
265
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
266
|
+
parts[_i] = arguments[_i];
|
|
267
|
+
}
|
|
268
|
+
return parts.reduce(function (acc, part) {
|
|
269
|
+
if (acc === '') {
|
|
270
|
+
return part;
|
|
271
|
+
}
|
|
272
|
+
else if (part.startsWith('?')) {
|
|
273
|
+
return "".concat(acc).concat(part);
|
|
274
|
+
}
|
|
275
|
+
else if (acc.endsWith('/')) {
|
|
276
|
+
return "".concat(acc).concat(part.startsWith('/') ? part.substring(1) : part);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
return "".concat(acc).concat(part.startsWith('/') ? part : "/".concat(part));
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}export{Api,ApiError};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var axios=require('axios')
|
|
1
|
+
'use strict';var axios=require('axios');/******************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation.
|
|
3
3
|
|
|
4
4
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -81,7 +81,9 @@ function __generator(thisArg, body) {
|
|
|
81
81
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
82
82
|
var e = new Error(message);
|
|
83
83
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
84
|
-
}
|
|
84
|
+
};/********************************************************************************************************************
|
|
85
|
+
* ApiError
|
|
86
|
+
* ******************************************************************************************************************/
|
|
85
87
|
var ApiError = /** @class */ (function (_super) {
|
|
86
88
|
__extends(ApiError, _super);
|
|
87
89
|
function ApiError(message, code) {
|
|
@@ -94,10 +96,14 @@ var ApiError = /** @class */ (function (_super) {
|
|
|
94
96
|
}(Error));var _a;
|
|
95
97
|
var AxiosCreate = axios.create ? axios.create : (_a = require('axios').default) === null || _a === void 0 ? void 0 : _a.create;
|
|
96
98
|
var Api = /** @class */ (function () {
|
|
97
|
-
|
|
99
|
+
/********************************************************************************************************************
|
|
100
|
+
* constructor
|
|
101
|
+
* ******************************************************************************************************************/
|
|
98
102
|
function Api(option) {
|
|
99
103
|
var _this = this;
|
|
100
|
-
|
|
104
|
+
/********************************************************************************************************************
|
|
105
|
+
* run
|
|
106
|
+
* ******************************************************************************************************************/
|
|
101
107
|
this.run = function (method, path, data, option) {
|
|
102
108
|
return new Promise(function (resolve, reject) {
|
|
103
109
|
var _a;
|
|
@@ -116,10 +122,10 @@ var Api = /** @class */ (function () {
|
|
|
116
122
|
if (option === null || option === void 0 ? void 0 : option.raw) {
|
|
117
123
|
requestConfig.responseType = (option === null || option === void 0 ? void 0 : option.rawResponseType) || 'arraybuffer';
|
|
118
124
|
}
|
|
119
|
-
requestConfig.url =
|
|
125
|
+
requestConfig.url = urlJoin(_this.option.baseUrl, path.replace(/\./g, '/'));
|
|
120
126
|
if (data) {
|
|
121
127
|
if (method === 'get') {
|
|
122
|
-
if (
|
|
128
|
+
if (notEmpty(data)) {
|
|
123
129
|
var finalData = {};
|
|
124
130
|
finalData[_this.option.timeParamName] = new Date().getTime();
|
|
125
131
|
for (var key in data) {
|
|
@@ -187,8 +193,7 @@ var Api = /** @class */ (function () {
|
|
|
187
193
|
.then(function (res) {
|
|
188
194
|
var resData = res.data;
|
|
189
195
|
if (_this.option.onResponse) {
|
|
190
|
-
_this.option
|
|
191
|
-
.onResponse(res, requestConfig, _this.option.baseUrl, path, data, option)
|
|
196
|
+
_this.option.onResponse(res, requestConfig, _this.option.baseUrl, path, data, option)
|
|
192
197
|
.then(function (finalResData) {
|
|
193
198
|
resolve(finalResData);
|
|
194
199
|
})
|
|
@@ -224,4 +229,54 @@ var Api = /** @class */ (function () {
|
|
|
224
229
|
return this.run('delete', path, data, option);
|
|
225
230
|
};
|
|
226
231
|
return Api;
|
|
227
|
-
}());
|
|
232
|
+
}());
|
|
233
|
+
/********************************************************************************************************************
|
|
234
|
+
* empty
|
|
235
|
+
* ******************************************************************************************************************/
|
|
236
|
+
function empty(v) {
|
|
237
|
+
var result = false;
|
|
238
|
+
if (v == null) {
|
|
239
|
+
result = true;
|
|
240
|
+
}
|
|
241
|
+
else if (typeof v === 'string') {
|
|
242
|
+
result = v === '';
|
|
243
|
+
}
|
|
244
|
+
else if (typeof v === 'object') {
|
|
245
|
+
if (Array.isArray(v)) {
|
|
246
|
+
result = v.length === 0;
|
|
247
|
+
}
|
|
248
|
+
else if (!(v instanceof Date)) {
|
|
249
|
+
result = Object.entries(v).length === 0;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
/********************************************************************************************************************
|
|
255
|
+
* notEmpty
|
|
256
|
+
* ******************************************************************************************************************/
|
|
257
|
+
function notEmpty(v) {
|
|
258
|
+
return !empty(v);
|
|
259
|
+
}
|
|
260
|
+
/********************************************************************************************************************
|
|
261
|
+
* urlJoin
|
|
262
|
+
* ******************************************************************************************************************/
|
|
263
|
+
function urlJoin() {
|
|
264
|
+
var parts = [];
|
|
265
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
266
|
+
parts[_i] = arguments[_i];
|
|
267
|
+
}
|
|
268
|
+
return parts.reduce(function (acc, part) {
|
|
269
|
+
if (acc === '') {
|
|
270
|
+
return part;
|
|
271
|
+
}
|
|
272
|
+
else if (part.startsWith('?')) {
|
|
273
|
+
return "".concat(acc).concat(part);
|
|
274
|
+
}
|
|
275
|
+
else if (acc.endsWith('/')) {
|
|
276
|
+
return "".concat(acc).concat(part.startsWith('/') ? part.substring(1) : part);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
return "".concat(acc).concat(part.startsWith('/') ? part : "/".concat(part));
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}exports.Api=Api;exports.ApiError=ApiError;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdg/api",
|
|
3
3
|
"title": "API Module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.22",
|
|
5
5
|
"description": "API Module",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -36,24 +36,21 @@
|
|
|
36
36
|
"javascript"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"axios": "^1.9.0"
|
|
39
|
+
"axios": "^1.3.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@eslint/js": "^9.
|
|
42
|
+
"@eslint/js": "^9.28.0",
|
|
44
43
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
45
44
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
46
|
-
"@types/node": "^22.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
-
"eslint": "9.
|
|
50
|
-
"eslint-config-prettier": "^10.1.
|
|
45
|
+
"@types/node": "^22.15.29",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
48
|
+
"eslint": "9.28.0",
|
|
49
|
+
"eslint-config-prettier": "^10.1.5",
|
|
51
50
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
52
|
-
"eslint-plugin-prettier": "^5.
|
|
53
|
-
"i": "^0.3.7",
|
|
54
|
-
"npm": "^11.3.0",
|
|
51
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
55
52
|
"prettier": "^3.5.3",
|
|
56
|
-
"rollup": "^4.
|
|
53
|
+
"rollup": "^4.41.1",
|
|
57
54
|
"rollup-plugin-delete": "^2.2.0",
|
|
58
55
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
59
56
|
"rollup-plugin-typescript2": "^0.36.0",
|