jordy 0.12.0 → 0.13.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/esm5/http-api/BaseInterceptorHttpApi.js +53 -0
- package/esm5/http-api/BasicHttpApi.js +155 -0
- package/esm5/http-api/BasicHttpUploadApi.js +60 -0
- package/esm5/http-api/ErrorParser.decorator.js +83 -0
- package/esm5/http-api/axios/AxiosHttpNetworkProvider.js +57 -0
- package/esm5/http-api/axios/AxiosHttpUploadProvider.js +52 -0
- package/esm5/http-api/axios/axios.util.js +7 -0
- package/esm5/http-api/axios/index.js +2 -0
- package/esm5/http-api/axios/throwableAxiosErrorParser.js +23 -0
- package/esm5/http-api/createHttpApi.factory.js +10 -0
- package/esm5/http-api/createHttpHeaderPipe.js +34 -0
- package/esm5/http-api/createHttpUploadApi.factory.js +10 -0
- package/esm5/http-api/httpHeaderOperator.js +15 -0
- package/esm5/http-api/index.js +7 -2
- package/esm5/http-api/network.util.js +72 -0
- package/esm5/index.js +4 -4
- package/esm5/storage/ExpiableStorageAdapter.js +13 -2
- package/esm5/storage/RefreshableJWTProvider.js +124 -0
- package/esm5/storage/StorageTokenProvider.js +16 -0
- package/esm5/storage/createJWTProvider.factory.js +6 -0
- package/esm5/storage/{storage.factory.js → createStorage.factory.js} +0 -0
- package/esm5/storage/createTokenProvider.factory.js +5 -0
- package/esm5/storage/index.js +12 -3
- package/esm5/storage/storage.util.js +8 -0
- package/esm5/types/HttpRestError.js +126 -0
- package/esm5/types/etc.type.js +1 -0
- package/esm5/types/index.js +2 -0
- package/esm5/util/AsyncQueue.js +53 -0
- package/esm5/util/index.js +1 -0
- package/esm5/util/typeCheck.js +9 -1
- package/libs/http-api/BaseInterceptorHttpApi.d.ts +12 -0
- package/libs/http-api/BasicHttpApi.d.ts +17 -0
- package/libs/http-api/BasicHttpUploadApi.d.ts +11 -0
- package/libs/http-api/ErrorParser.decorator.d.ts +19 -0
- package/libs/http-api/axios/AxiosHttpNetworkProvider.d.ts +11 -0
- package/libs/http-api/axios/AxiosHttpUploadProvider.d.ts +9 -0
- package/libs/http-api/axios/axios.util.d.ts +2 -0
- package/libs/http-api/axios/index.d.ts +2 -0
- package/libs/http-api/axios/throwableAxiosErrorParser.d.ts +1 -0
- package/libs/http-api/createHttpApi.factory.d.ts +2 -0
- package/libs/http-api/createHttpHeaderPipe.d.ts +46 -0
- package/libs/http-api/createHttpUploadApi.factory.d.ts +2 -0
- package/libs/http-api/httpHeaderOperator.d.ts +43 -0
- package/libs/http-api/index.d.ts +7 -2
- package/libs/http-api/network.type.d.ts +109 -13
- package/libs/http-api/network.util.d.ts +5 -0
- package/libs/index.d.ts +5 -5
- package/libs/storage/ExpiableStorageAdapter.d.ts +2 -1
- package/libs/storage/RefreshableJWTProvider.d.ts +20 -0
- package/libs/storage/StorageTokenProvider.d.ts +11 -0
- package/libs/storage/createJWTProvider.factory.d.ts +2 -0
- package/libs/storage/{storage.factory.d.ts → createStorage.factory.d.ts} +1 -1
- package/libs/storage/{token-provider.factory.d.ts → createTokenProvider.factory.d.ts} +0 -0
- package/libs/storage/index.d.ts +12 -3
- package/libs/storage/storage.type.d.ts +45 -3
- package/libs/storage/storage.util.d.ts +2 -0
- package/libs/types/HttpRestError.d.ts +37 -0
- package/libs/types/etc.type.d.ts +5 -0
- package/libs/types/index.d.ts +2 -0
- package/libs/util/AsyncQueue.d.ts +55 -0
- package/libs/util/index.d.ts +1 -0
- package/libs/util/typeCheck.d.ts +2 -0
- package/package.json +1 -1
- package/esm5/http-api/httpApi.factory.js +0 -143
- package/esm5/http-api/httpHeader.factory.js +0 -46
- package/esm5/http-api/networkParser.js +0 -73
- package/esm5/storage/token-provider.factory.js +0 -23
- package/libs/http-api/httpApi.factory.d.ts +0 -9
- package/libs/http-api/httpHeader.factory.d.ts +0 -15
- package/libs/http-api/networkParser.d.ts +0 -9
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
var BaseInterceptorHttpApi = (function () {
|
|
3
|
+
function BaseInterceptorHttpApi(paramsSerializer) {
|
|
4
|
+
var _this = this;
|
|
5
|
+
this.paramsSerializer = paramsSerializer;
|
|
6
|
+
this._interceptor = {};
|
|
7
|
+
this.mergeParams = function (method, url, paramsOriginal) {
|
|
8
|
+
if (_this._interceptor.params) {
|
|
9
|
+
var paramsAdditional = _this._interceptor.params(method, url, paramsOriginal);
|
|
10
|
+
if (paramsAdditional) {
|
|
11
|
+
if (paramsOriginal) {
|
|
12
|
+
return __assign(__assign({}, paramsOriginal), paramsAdditional);
|
|
13
|
+
}
|
|
14
|
+
return paramsAdditional;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return paramsOriginal;
|
|
18
|
+
};
|
|
19
|
+
this.mergeQueries = function (method, url, paramsOriginal) {
|
|
20
|
+
if (_this._interceptor.params) {
|
|
21
|
+
var paramsAdditional = _this._interceptor.params(method, url, paramsOriginal);
|
|
22
|
+
if (!paramsAdditional) {
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
return (url +
|
|
26
|
+
(url.includes('?') ? '&' : '?') +
|
|
27
|
+
_this.paramsSerializer(paramsAdditional));
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
};
|
|
31
|
+
this.throwWithInterceptor = function (err) {
|
|
32
|
+
if (_this._interceptor.error) {
|
|
33
|
+
var nextError = _this._interceptor.error(err);
|
|
34
|
+
if (nextError) {
|
|
35
|
+
throw nextError;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
Object.defineProperty(BaseInterceptorHttpApi.prototype, "interceptor", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return this._interceptor;
|
|
44
|
+
},
|
|
45
|
+
set: function (value) {
|
|
46
|
+
this._interceptor = value;
|
|
47
|
+
},
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
return BaseInterceptorHttpApi;
|
|
52
|
+
}());
|
|
53
|
+
export { BaseInterceptorHttpApi };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { getFileName } from '../util';
|
|
3
|
+
import { BaseInterceptorHttpApi } from './BaseInterceptorHttpApi';
|
|
4
|
+
var BasicHttpApi = (function (_super) {
|
|
5
|
+
__extends(BasicHttpApi, _super);
|
|
6
|
+
function BasicHttpApi(provider, baseUrl, headersCreator, paramsSerializer, withCredentials) {
|
|
7
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
8
|
+
var _this = _super.call(this, paramsSerializer) || this;
|
|
9
|
+
_this.provider = provider;
|
|
10
|
+
_this.baseUrl = baseUrl;
|
|
11
|
+
_this.headersCreator = headersCreator;
|
|
12
|
+
_this.withCredentials = withCredentials;
|
|
13
|
+
return _this;
|
|
14
|
+
}
|
|
15
|
+
BasicHttpApi.prototype.get = function (url, params, timeout) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17
|
+
var headers;
|
|
18
|
+
return __generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0: return [4, this.headersCreator()];
|
|
21
|
+
case 1:
|
|
22
|
+
headers = _a.sent();
|
|
23
|
+
return [2, this.provider
|
|
24
|
+
.get({
|
|
25
|
+
url: "".concat(this.baseUrl).concat(url),
|
|
26
|
+
headers: headers,
|
|
27
|
+
withCredentials: this.withCredentials,
|
|
28
|
+
paramsSerializer: this.paramsSerializer,
|
|
29
|
+
params: this.mergeParams('get', url, params),
|
|
30
|
+
timeout: timeout,
|
|
31
|
+
})
|
|
32
|
+
.catch(this.throwWithInterceptor)];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
BasicHttpApi.prototype.post = function (url, body, timeout) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
39
|
+
var headers;
|
|
40
|
+
return __generator(this, function (_a) {
|
|
41
|
+
switch (_a.label) {
|
|
42
|
+
case 0: return [4, this.headersCreator()];
|
|
43
|
+
case 1:
|
|
44
|
+
headers = _a.sent();
|
|
45
|
+
return [2, this.provider
|
|
46
|
+
.post({
|
|
47
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('post', url, body)),
|
|
48
|
+
headers: headers,
|
|
49
|
+
withCredentials: this.withCredentials,
|
|
50
|
+
paramsSerializer: this.paramsSerializer,
|
|
51
|
+
params: body,
|
|
52
|
+
timeout: timeout,
|
|
53
|
+
})
|
|
54
|
+
.catch(this.throwWithInterceptor)];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
BasicHttpApi.prototype.put = function (url, body, timeout) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var headers;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0: return [4, this.headersCreator()];
|
|
65
|
+
case 1:
|
|
66
|
+
headers = _a.sent();
|
|
67
|
+
return [2, this.provider
|
|
68
|
+
.put({
|
|
69
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('put', url, body)),
|
|
70
|
+
headers: headers,
|
|
71
|
+
withCredentials: this.withCredentials,
|
|
72
|
+
paramsSerializer: this.paramsSerializer,
|
|
73
|
+
params: body,
|
|
74
|
+
timeout: timeout,
|
|
75
|
+
})
|
|
76
|
+
.catch(this.throwWithInterceptor)];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
BasicHttpApi.prototype.patch = function (url, body, timeout) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var headers;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0: return [4, this.headersCreator()];
|
|
87
|
+
case 1:
|
|
88
|
+
headers = _a.sent();
|
|
89
|
+
return [2, this.provider
|
|
90
|
+
.patch({
|
|
91
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('patch', url, body)),
|
|
92
|
+
headers: headers,
|
|
93
|
+
withCredentials: this.withCredentials,
|
|
94
|
+
paramsSerializer: this.paramsSerializer,
|
|
95
|
+
params: body,
|
|
96
|
+
timeout: timeout,
|
|
97
|
+
})
|
|
98
|
+
.catch(this.throwWithInterceptor)];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
BasicHttpApi.prototype.delete = function (url, body, timeout) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var headers;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0: return [4, this.headersCreator()];
|
|
109
|
+
case 1:
|
|
110
|
+
headers = _a.sent();
|
|
111
|
+
return [2, this.provider
|
|
112
|
+
.delete({
|
|
113
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('delete', url, body)),
|
|
114
|
+
headers: headers,
|
|
115
|
+
withCredentials: this.withCredentials,
|
|
116
|
+
paramsSerializer: this.paramsSerializer,
|
|
117
|
+
params: body,
|
|
118
|
+
timeout: timeout,
|
|
119
|
+
})
|
|
120
|
+
.catch(this.throwWithInterceptor)];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
BasicHttpApi.prototype.getFile = function (url, params, filename) {
|
|
126
|
+
return this.getBlob(url, params)
|
|
127
|
+
.then(function (blob) {
|
|
128
|
+
return new File([blob], filename || getFileName(url));
|
|
129
|
+
})
|
|
130
|
+
.catch(this.throwWithInterceptor);
|
|
131
|
+
};
|
|
132
|
+
BasicHttpApi.prototype.getBlob = function (url, params) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var headers;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0: return [4, this.headersCreator()];
|
|
138
|
+
case 1:
|
|
139
|
+
headers = _a.sent();
|
|
140
|
+
return [2, this.provider
|
|
141
|
+
.getBlob({
|
|
142
|
+
url: "".concat(this.baseUrl).concat(url),
|
|
143
|
+
headers: headers,
|
|
144
|
+
withCredentials: this.withCredentials,
|
|
145
|
+
paramsSerializer: this.paramsSerializer,
|
|
146
|
+
params: this.mergeParams('get', url, params),
|
|
147
|
+
})
|
|
148
|
+
.catch(this.throwWithInterceptor)];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
return BasicHttpApi;
|
|
154
|
+
}(BaseInterceptorHttpApi));
|
|
155
|
+
export { BasicHttpApi };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __awaiter, __extends, __generator } from "tslib";
|
|
2
|
+
import { BaseInterceptorHttpApi } from './BaseInterceptorHttpApi';
|
|
3
|
+
var BasicHttpUploadApi = (function (_super) {
|
|
4
|
+
__extends(BasicHttpUploadApi, _super);
|
|
5
|
+
function BasicHttpUploadApi(provider, baseUrl, headersCreator, paramsSerializer, withCredentials) {
|
|
6
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
7
|
+
var _this = _super.call(this, paramsSerializer) || this;
|
|
8
|
+
_this.provider = provider;
|
|
9
|
+
_this.baseUrl = baseUrl;
|
|
10
|
+
_this.headersCreator = headersCreator;
|
|
11
|
+
_this.withCredentials = withCredentials;
|
|
12
|
+
return _this;
|
|
13
|
+
}
|
|
14
|
+
BasicHttpUploadApi.prototype.postUpload = function (url, data, progressCallback, timeout) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16
|
+
var headers;
|
|
17
|
+
return __generator(this, function (_a) {
|
|
18
|
+
switch (_a.label) {
|
|
19
|
+
case 0: return [4, this.headersCreator()];
|
|
20
|
+
case 1:
|
|
21
|
+
headers = _a.sent();
|
|
22
|
+
return [2, this.provider
|
|
23
|
+
.post({
|
|
24
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('post', url, data)),
|
|
25
|
+
headers: headers,
|
|
26
|
+
withCredentials: this.withCredentials,
|
|
27
|
+
data: data,
|
|
28
|
+
timeout: timeout,
|
|
29
|
+
onProgress: progressCallback,
|
|
30
|
+
})
|
|
31
|
+
.catch(this.throwWithInterceptor)];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
BasicHttpUploadApi.prototype.putUpload = function (url, data, progressCallback, timeout) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
38
|
+
var headers;
|
|
39
|
+
return __generator(this, function (_a) {
|
|
40
|
+
switch (_a.label) {
|
|
41
|
+
case 0: return [4, this.headersCreator()];
|
|
42
|
+
case 1:
|
|
43
|
+
headers = _a.sent();
|
|
44
|
+
return [2, this.provider
|
|
45
|
+
.put({
|
|
46
|
+
url: "".concat(this.baseUrl).concat(this.mergeQueries('put', url, data)),
|
|
47
|
+
headers: headers,
|
|
48
|
+
withCredentials: this.withCredentials,
|
|
49
|
+
data: data,
|
|
50
|
+
timeout: timeout,
|
|
51
|
+
onProgress: progressCallback,
|
|
52
|
+
})
|
|
53
|
+
.catch(this.throwWithInterceptor)];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return BasicHttpUploadApi;
|
|
59
|
+
}(BaseInterceptorHttpApi));
|
|
60
|
+
export { BasicHttpUploadApi };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
import { throwHttpRestError } from './network.util';
|
|
3
|
+
function isConstructor(val) {
|
|
4
|
+
return typeof val === 'function';
|
|
5
|
+
}
|
|
6
|
+
export function ErrorParser(throwableParser) {
|
|
7
|
+
return function (ClassConstructor) {
|
|
8
|
+
if (isConstructor(ClassConstructor) === false) {
|
|
9
|
+
throw new Error('ErrorParser: argument is not function.');
|
|
10
|
+
}
|
|
11
|
+
return (function () {
|
|
12
|
+
function ErrorParserDecoratedUnionHttpNetworkProvider() {
|
|
13
|
+
var args = [];
|
|
14
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
+
args[_i] = arguments[_i];
|
|
16
|
+
}
|
|
17
|
+
this.network = new ClassConstructor(args[0], args[1], args[2]);
|
|
18
|
+
}
|
|
19
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.parse = function (error) {
|
|
20
|
+
var nextError = throwableParser(error);
|
|
21
|
+
if (nextError) {
|
|
22
|
+
throw nextError;
|
|
23
|
+
}
|
|
24
|
+
throwHttpRestError(error);
|
|
25
|
+
};
|
|
26
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.get = function () {
|
|
27
|
+
var args = [];
|
|
28
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
29
|
+
args[_i] = arguments[_i];
|
|
30
|
+
}
|
|
31
|
+
return this.network.get
|
|
32
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
33
|
+
.catch(this.parse);
|
|
34
|
+
};
|
|
35
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.post = function () {
|
|
36
|
+
var args = [];
|
|
37
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
38
|
+
args[_i] = arguments[_i];
|
|
39
|
+
}
|
|
40
|
+
return this.network.post
|
|
41
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
42
|
+
.catch(this.parse);
|
|
43
|
+
};
|
|
44
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.put = function () {
|
|
45
|
+
var args = [];
|
|
46
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
47
|
+
args[_i] = arguments[_i];
|
|
48
|
+
}
|
|
49
|
+
return this.network.put
|
|
50
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
51
|
+
.catch(this.parse);
|
|
52
|
+
};
|
|
53
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.patch = function () {
|
|
54
|
+
var args = [];
|
|
55
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
56
|
+
args[_i] = arguments[_i];
|
|
57
|
+
}
|
|
58
|
+
return this.network.patch
|
|
59
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
60
|
+
.catch(this.parse);
|
|
61
|
+
};
|
|
62
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.delete = function () {
|
|
63
|
+
var args = [];
|
|
64
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
65
|
+
args[_i] = arguments[_i];
|
|
66
|
+
}
|
|
67
|
+
return this.network.delete
|
|
68
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
69
|
+
.catch(this.parse);
|
|
70
|
+
};
|
|
71
|
+
ErrorParserDecoratedUnionHttpNetworkProvider.prototype.getBlob = function () {
|
|
72
|
+
var args = [];
|
|
73
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
74
|
+
args[_i] = arguments[_i];
|
|
75
|
+
}
|
|
76
|
+
return this.network.getBlob
|
|
77
|
+
.apply(this.network, __spreadArray([], args, true))
|
|
78
|
+
.catch(this.parse);
|
|
79
|
+
};
|
|
80
|
+
return ErrorParserDecoratedUnionHttpNetworkProvider;
|
|
81
|
+
}());
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { __assign, __decorate, __rest } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { ErrorParser } from '../ErrorParser.decorator';
|
|
4
|
+
import { throwableAxiosErrorParser } from './throwableAxiosErrorParser';
|
|
5
|
+
var AxiosHttpNetworkProvider = (function () {
|
|
6
|
+
function AxiosHttpNetworkProvider() {
|
|
7
|
+
}
|
|
8
|
+
AxiosHttpNetworkProvider.prototype.extractData = function (axiosRes) {
|
|
9
|
+
return axiosRes.data;
|
|
10
|
+
};
|
|
11
|
+
AxiosHttpNetworkProvider.prototype.makeAxiosHeaders = function (headers) {
|
|
12
|
+
return {
|
|
13
|
+
common: headers,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
AxiosHttpNetworkProvider.prototype.get = function (_a) {
|
|
17
|
+
var url = _a.url, headers = _a.headers, config = __rest(_a, ["url", "headers"]);
|
|
18
|
+
return axios
|
|
19
|
+
.get(url, __assign(__assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
20
|
+
.then(this.extractData);
|
|
21
|
+
};
|
|
22
|
+
AxiosHttpNetworkProvider.prototype.post = function (_a) {
|
|
23
|
+
var url = _a.url, headers = _a.headers, data = _a.params, config = __rest(_a, ["url", "headers", "params"]);
|
|
24
|
+
return axios
|
|
25
|
+
.post(url, data, __assign(__assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
26
|
+
.then(this.extractData);
|
|
27
|
+
};
|
|
28
|
+
AxiosHttpNetworkProvider.prototype.put = function (_a) {
|
|
29
|
+
var url = _a.url, headers = _a.headers, data = _a.params, config = __rest(_a, ["url", "headers", "params"]);
|
|
30
|
+
return axios
|
|
31
|
+
.put(url, data, __assign(__assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
32
|
+
.then(this.extractData);
|
|
33
|
+
};
|
|
34
|
+
AxiosHttpNetworkProvider.prototype.patch = function (_a) {
|
|
35
|
+
var url = _a.url, headers = _a.headers, data = _a.params, config = __rest(_a, ["url", "headers", "params"]);
|
|
36
|
+
return axios
|
|
37
|
+
.patch(url, data, __assign(__assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
38
|
+
.then(this.extractData);
|
|
39
|
+
};
|
|
40
|
+
AxiosHttpNetworkProvider.prototype.delete = function (_a) {
|
|
41
|
+
var url = _a.url, headers = _a.headers, data = _a.params, config = __rest(_a, ["url", "headers", "params"]);
|
|
42
|
+
return axios
|
|
43
|
+
.delete(url, __assign(__assign({}, config), { data: data, headers: this.makeAxiosHeaders(headers) }))
|
|
44
|
+
.then(this.extractData);
|
|
45
|
+
};
|
|
46
|
+
AxiosHttpNetworkProvider.prototype.getBlob = function (_a) {
|
|
47
|
+
var url = _a.url, headers = _a.headers, config = __rest(_a, ["url", "headers"]);
|
|
48
|
+
return axios
|
|
49
|
+
.get(url, __assign(__assign({}, config), { headers: this.makeAxiosHeaders(headers), responseType: 'blob' }))
|
|
50
|
+
.then(this.extractData);
|
|
51
|
+
};
|
|
52
|
+
AxiosHttpNetworkProvider = __decorate([
|
|
53
|
+
ErrorParser(throwableAxiosErrorParser)
|
|
54
|
+
], AxiosHttpNetworkProvider);
|
|
55
|
+
return AxiosHttpNetworkProvider;
|
|
56
|
+
}());
|
|
57
|
+
export { AxiosHttpNetworkProvider };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { ErrorParser } from '../ErrorParser.decorator';
|
|
4
|
+
import { convertToFormData } from '../network.util';
|
|
5
|
+
import { throwableAxiosErrorParser } from './throwableAxiosErrorParser';
|
|
6
|
+
var AxiosHttpUploadProvider = (function () {
|
|
7
|
+
function AxiosHttpUploadProvider() {
|
|
8
|
+
this.handleDownloadProgressCurried = function (onProgress) {
|
|
9
|
+
return function (_a) {
|
|
10
|
+
var loaded = _a.loaded, total = _a.total;
|
|
11
|
+
return onProgress({
|
|
12
|
+
completed: loaded >= total,
|
|
13
|
+
loaded: loaded,
|
|
14
|
+
progress: Math.floor((loaded * 1000) / total) / 10,
|
|
15
|
+
total: total,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
AxiosHttpUploadProvider.prototype.extractData = function (axiosRes) {
|
|
21
|
+
return axiosRes.data;
|
|
22
|
+
};
|
|
23
|
+
AxiosHttpUploadProvider.prototype.makeAxiosHeaders = function (headers) {
|
|
24
|
+
return {
|
|
25
|
+
common: headers,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
AxiosHttpUploadProvider.prototype.upload = function (method, _a) {
|
|
29
|
+
var url = _a.url, data = _a.data, headers = _a.headers, withCredentials = _a.withCredentials, timeout = _a.timeout, onProgress = _a.onProgress;
|
|
30
|
+
return axios(url, {
|
|
31
|
+
method: method,
|
|
32
|
+
data: convertToFormData(data),
|
|
33
|
+
headers: this.makeAxiosHeaders(headers),
|
|
34
|
+
withCredentials: withCredentials,
|
|
35
|
+
timeout: timeout,
|
|
36
|
+
onDownloadProgress: onProgress
|
|
37
|
+
? this.handleDownloadProgressCurried(onProgress)
|
|
38
|
+
: undefined,
|
|
39
|
+
}).then(this.extractData);
|
|
40
|
+
};
|
|
41
|
+
AxiosHttpUploadProvider.prototype.post = function (config) {
|
|
42
|
+
return this.upload('POST', config);
|
|
43
|
+
};
|
|
44
|
+
AxiosHttpUploadProvider.prototype.put = function (config) {
|
|
45
|
+
return this.upload('PUT', config);
|
|
46
|
+
};
|
|
47
|
+
AxiosHttpUploadProvider = __decorate([
|
|
48
|
+
ErrorParser(throwableAxiosErrorParser)
|
|
49
|
+
], AxiosHttpUploadProvider);
|
|
50
|
+
return AxiosHttpUploadProvider;
|
|
51
|
+
}());
|
|
52
|
+
export { AxiosHttpUploadProvider };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpRestError } from '../../types';
|
|
2
|
+
import { isAxiosError } from './axios.util';
|
|
3
|
+
export function throwableAxiosErrorParser(error) {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
if (isAxiosError(error)) {
|
|
6
|
+
var errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
7
|
+
var meta = {
|
|
8
|
+
url: error.config.url || '',
|
|
9
|
+
status: ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || 0,
|
|
10
|
+
rawData: errorData,
|
|
11
|
+
};
|
|
12
|
+
if (HttpRestError.isErrorLike(errorData)) {
|
|
13
|
+
throw new HttpRestError(errorData.message, meta);
|
|
14
|
+
}
|
|
15
|
+
if (typeof errorData === 'string' && errorData) {
|
|
16
|
+
if (errorData.substring(0, 200).toLowerCase().includes('<html')) {
|
|
17
|
+
throw new HttpRestError(HttpRestError.DEFAULT_MESSAGE, meta);
|
|
18
|
+
}
|
|
19
|
+
throw new HttpRestError(errorData, meta);
|
|
20
|
+
}
|
|
21
|
+
throw new HttpRestError(HttpRestError.DEFAULT_MESSAGE, meta);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { qs } from '../util';
|
|
2
|
+
import { AxiosHttpNetworkProvider } from './axios';
|
|
3
|
+
import { BasicHttpApi } from './BasicHttpApi';
|
|
4
|
+
import { defaultHeaderCreator } from './network.util';
|
|
5
|
+
export function createHttpApi(baseUrl, headerCreator, paramsSerializer, withCredentials) {
|
|
6
|
+
if (headerCreator === void 0) { headerCreator = defaultHeaderCreator; }
|
|
7
|
+
if (paramsSerializer === void 0) { paramsSerializer = qs.serialize; }
|
|
8
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
9
|
+
return new BasicHttpApi(new AxiosHttpNetworkProvider(), baseUrl, headerCreator, paramsSerializer, withCredentials);
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { isServer } from '../util/envCheck';
|
|
3
|
+
function makeHeaders(pipes, token) {
|
|
4
|
+
if (token === void 0) { token = ''; }
|
|
5
|
+
var rawMap = pipes.reduce(function (prev, fn) { return fn(prev, token); }, new Map());
|
|
6
|
+
return Object.fromEntries(rawMap);
|
|
7
|
+
}
|
|
8
|
+
export var createHttpHeaderPipe = function (provider, loginRequiredMessage) {
|
|
9
|
+
if (loginRequiredMessage === void 0) { loginRequiredMessage = '로그인 상태가 만료 되었습니다.\n다시 로그인 하여 주시기 바랍니다.'; }
|
|
10
|
+
return function headerPipe() {
|
|
11
|
+
var pipes = [];
|
|
12
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
+
pipes[_i] = arguments[_i];
|
|
14
|
+
}
|
|
15
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16
|
+
var token;
|
|
17
|
+
return __generator(this, function (_a) {
|
|
18
|
+
switch (_a.label) {
|
|
19
|
+
case 0:
|
|
20
|
+
token = '';
|
|
21
|
+
if (!provider) return [3, 2];
|
|
22
|
+
return [4, provider.get()];
|
|
23
|
+
case 1:
|
|
24
|
+
token = _a.sent();
|
|
25
|
+
if (!token && !isServer()) {
|
|
26
|
+
throw new Error(loginRequiredMessage);
|
|
27
|
+
}
|
|
28
|
+
_a.label = 2;
|
|
29
|
+
case 2: return [2, makeHeaders(pipes, token)];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { qs } from '../util';
|
|
2
|
+
import { AxiosHttpUploadProvider } from './axios';
|
|
3
|
+
import { BasicHttpUploadApi } from './BasicHttpUploadApi';
|
|
4
|
+
import { defaultHeaderCreator } from './network.util';
|
|
5
|
+
export function createHttpUploadApi(baseUrl, headerCreator, paramsSerializer, withCredentials) {
|
|
6
|
+
if (headerCreator === void 0) { headerCreator = defaultHeaderCreator; }
|
|
7
|
+
if (paramsSerializer === void 0) { paramsSerializer = qs.serialize; }
|
|
8
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
9
|
+
return new BasicHttpUploadApi(new AxiosHttpUploadProvider(), baseUrl, headerCreator, paramsSerializer, withCredentials);
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var pipeHeaderDataCurried = function (key, value) { return function (headerData) {
|
|
2
|
+
return headerData.set(key, value);
|
|
3
|
+
}; };
|
|
4
|
+
export var httpHeaderOperator = {
|
|
5
|
+
acceptContentType: pipeHeaderDataCurried('Accept', 'application/json'),
|
|
6
|
+
contentTypeFormPost: pipeHeaderDataCurried('Content-Type', 'application/x-www-form-urlencoded'),
|
|
7
|
+
contentTypeFormMultipart: pipeHeaderDataCurried('Content-Type', 'multipart/form-data'),
|
|
8
|
+
contentTypeJson: pipeHeaderDataCurried('Content-Type', 'application/json; charset=utf-8'),
|
|
9
|
+
bearerToken: function (headerData, token) {
|
|
10
|
+
if (token) {
|
|
11
|
+
headerData.set('Authorization', "Bearer ".concat(token));
|
|
12
|
+
}
|
|
13
|
+
return headerData;
|
|
14
|
+
},
|
|
15
|
+
};
|
package/esm5/http-api/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './BasicHttpApi';
|
|
2
|
+
export * from './BasicHttpUploadApi';
|
|
3
|
+
export * from './ErrorParser.decorator';
|
|
4
|
+
export * from './createHttpApi.factory';
|
|
5
|
+
export * from './createHttpHeaderPipe';
|
|
6
|
+
export * from './createHttpUploadApi.factory';
|
|
3
7
|
export * from './network.type';
|
|
8
|
+
export * from './httpHeaderOperator';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { HttpRestError } from '../types';
|
|
2
|
+
import { isNumber, isObject, isString, isUndefined } from '../util/typeCheck';
|
|
3
|
+
function isOptionalBoolean(value) {
|
|
4
|
+
if (isUndefined(value)) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (value === true || value === false) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
function isOptionalNumber(value) {
|
|
13
|
+
if (isUndefined(value)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (isNumber(value)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export function isBaseAsyncHttpNetworkConfig(value) {
|
|
22
|
+
if (!value) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
var target = value;
|
|
26
|
+
if (!target.url || isString(target.url) === false) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!target.headers || isObject(target.headers) === false) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (isOptionalBoolean(target.withCredentials) === false) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (isOptionalNumber(target.timeout) === false) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
export function throwHttpRestError(error) {
|
|
41
|
+
if (error &&
|
|
42
|
+
(HttpRestError.isHttpRestErrorLike(error) ||
|
|
43
|
+
HttpRestError.isErrorLike(error) ||
|
|
44
|
+
typeof error === 'string')) {
|
|
45
|
+
throw HttpRestError.from(error);
|
|
46
|
+
}
|
|
47
|
+
throw new HttpRestError(HttpRestError.DEFAULT_MESSAGE, {
|
|
48
|
+
url: '',
|
|
49
|
+
status: 0,
|
|
50
|
+
rawData: error,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function convertToFormData(data) {
|
|
54
|
+
return Object.entries(data).reduce(function (formData, _a) {
|
|
55
|
+
var key = _a[0], value = _a[1];
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
return value.reduce(function (innerFormData, file) {
|
|
58
|
+
innerFormData.append(key, file, file.name);
|
|
59
|
+
return innerFormData;
|
|
60
|
+
}, formData);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
formData.set(key, value);
|
|
64
|
+
return formData;
|
|
65
|
+
}
|
|
66
|
+
formData.set(key, value, value.name);
|
|
67
|
+
return formData;
|
|
68
|
+
}, new FormData());
|
|
69
|
+
}
|
|
70
|
+
export function defaultHeaderCreator() {
|
|
71
|
+
return Promise.resolve({});
|
|
72
|
+
}
|