sm-utility 1.4.4 → 2.0.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/index.js +20 -0
- package/package.json +11 -14
- package/request/index.d.ts +9 -3
- package/request/index.js +7 -8
- package/request/types.d.ts +0 -5
- package/request/types.js +0 -2
package/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// Packages below are not fully implemented yet
|
|
14
|
+
// export * from './array';
|
|
15
|
+
// export * from './string';
|
|
16
|
+
__exportStar(require("./date"), exports);
|
|
17
|
+
__exportStar(require("./general"), exports);
|
|
18
|
+
__exportStar(require("./infrastructure"), exports);
|
|
19
|
+
__exportStar(require("./logger"), exports);
|
|
20
|
+
__exportStar(require("./request"), exports);
|
package/package.json
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sm-utility",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "reusable utility codes for sm projects",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"typings": "./index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
|
-
"clean": "rm -rf
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
9
|
+
"clean": "rm -rf dist",
|
|
10
|
+
"prebuild":"npm run clean",
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"postbuild": "npm run copy-files",
|
|
13
|
+
"copy-files": "copyfiles package.json README.md ./dist",
|
|
14
|
+
"publish-package": "npm run build && cd ./dist && npm publish"
|
|
12
15
|
},
|
|
13
16
|
"author": "Caio Poyares",
|
|
14
17
|
"license": "ISC",
|
|
15
18
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"/general",
|
|
18
|
-
"/date",
|
|
19
|
-
"/string",
|
|
20
|
-
"/array",
|
|
21
|
-
"/logger",
|
|
22
|
-
"/request",
|
|
23
|
-
"/typings"
|
|
19
|
+
"*/**"
|
|
24
20
|
],
|
|
25
21
|
"devDependencies": {
|
|
26
22
|
"@types/express": "^4.17.11",
|
|
27
23
|
"@types/node": "^14.14.40",
|
|
28
24
|
"@types/uuid": "^8.3.1",
|
|
25
|
+
"copyfiles": "^2.4.1",
|
|
29
26
|
"typescript": "^4.2.4"
|
|
30
27
|
},
|
|
31
28
|
"dependencies": {
|
package/request/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
declare module 'axios' {
|
|
3
|
+
interface AxiosRequestConfig {
|
|
4
|
+
meta?: Record<string, any>;
|
|
5
|
+
logRequest?: boolean;
|
|
6
|
+
logResponse?: boolean;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare function createApi(axiosConfig?: Omit<AxiosRequestConfig, "meta">): AxiosInstance;
|
package/request/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const logger_1 = require("../logger");
|
|
|
10
10
|
function createApi(axiosConfig) {
|
|
11
11
|
const axiosApi = axios_1.default.create(axiosConfig);
|
|
12
12
|
axiosApi.interceptors.request.use((request) => {
|
|
13
|
-
if (
|
|
13
|
+
if (request === null || request === void 0 ? void 0 : request.logRequest) {
|
|
14
14
|
const { data, params, method } = request;
|
|
15
15
|
const fullUrl = getFullUrlFromConfig(request);
|
|
16
16
|
request.meta = request.meta || {};
|
|
@@ -21,7 +21,8 @@ function createApi(axiosConfig) {
|
|
|
21
21
|
return request;
|
|
22
22
|
});
|
|
23
23
|
axiosApi.interceptors.response.use((response) => {
|
|
24
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
if ((_a = response.config) === null || _a === void 0 ? void 0 : _a.logResponse) {
|
|
25
26
|
const { status, data, config } = response;
|
|
26
27
|
const { method, meta } = config;
|
|
27
28
|
const fullUrl = getFullUrlFromConfig(config);
|
|
@@ -30,12 +31,10 @@ function createApi(axiosConfig) {
|
|
|
30
31
|
}
|
|
31
32
|
return response;
|
|
32
33
|
}, (error) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
logError(meta === null || meta === void 0 ? void 0 : meta.requestId, method, fullUrl, response === null || response === void 0 ? void 0 : response.data, response === null || response === void 0 ? void 0 : response.status, message);
|
|
38
|
-
}
|
|
34
|
+
const { config, message, response } = error;
|
|
35
|
+
const { method, meta } = config;
|
|
36
|
+
const fullUrl = getFullUrlFromConfig(config);
|
|
37
|
+
logError(meta === null || meta === void 0 ? void 0 : meta.requestId, method, fullUrl, response === null || response === void 0 ? void 0 : response.data, response === null || response === void 0 ? void 0 : response.status, message);
|
|
39
38
|
throw error;
|
|
40
39
|
});
|
|
41
40
|
return axiosApi;
|
package/request/types.d.ts
DELETED
package/request/types.js
DELETED