@mondart/nestjs-common-module-request 3.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/dist/enums/http-methods.enum.d.ts +8 -0
- package/dist/enums/http-methods.enum.d.ts.map +1 -0
- package/dist/enums/http-methods.enum.js +12 -0
- package/dist/enums/http-methods.enum.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/request.module.d.ts +3 -0
- package/dist/request.module.d.ts.map +1 -0
- package/dist/request.module.js +24 -0
- package/dist/request.module.js.map +1 -0
- package/dist/request.service.d.ts +32 -0
- package/dist/request.service.d.ts.map +1 -0
- package/dist/request.service.js +76 -0
- package/dist/request.service.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-methods.enum.d.ts","sourceRoot":"","sources":["../../src/enums/http-methods.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,KAAK,UAAU;CAChB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = void 0;
|
|
4
|
+
var HttpMethods;
|
|
5
|
+
(function (HttpMethods) {
|
|
6
|
+
HttpMethods["POST"] = "post";
|
|
7
|
+
HttpMethods["GET"] = "get";
|
|
8
|
+
HttpMethods["DELETE"] = "delete";
|
|
9
|
+
HttpMethods["PUT"] = "put";
|
|
10
|
+
HttpMethods["PATCH"] = "patch";
|
|
11
|
+
})(HttpMethods || (exports.HttpMethods = HttpMethods = {}));
|
|
12
|
+
//# sourceMappingURL=http-methods.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-methods.enum.js","sourceRoot":"","sources":["../../src/enums/http-methods.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,4BAAa,CAAA;IACb,0BAAW,CAAA;IACX,gCAAiB,CAAA;IACjB,0BAAW,CAAA;IACX,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = exports.RequestService = exports.RequestModule = void 0;
|
|
4
|
+
const request_module_1 = require("./request.module");
|
|
5
|
+
Object.defineProperty(exports, "RequestModule", { enumerable: true, get: function () { return request_module_1.RequestModule; } });
|
|
6
|
+
const request_service_1 = require("./request.service");
|
|
7
|
+
Object.defineProperty(exports, "RequestService", { enumerable: true, get: function () { return request_service_1.RequestService; } });
|
|
8
|
+
const http_methods_enum_1 = require("./enums/http-methods.enum");
|
|
9
|
+
Object.defineProperty(exports, "HttpMethods", { enumerable: true, get: function () { return http_methods_enum_1.HttpMethods; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAIxC,8FAJA,8BAAa,OAIA;AAHtB,uDAAmD;AAG3B,+FAHf,gCAAc,OAGe;AAFtC,iEAAwD;AAEhB,4FAF/B,+BAAW,OAE+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.module.d.ts","sourceRoot":"","sources":["../src/request.module.ts"],"names":[],"mappings":"AAIA,qBAMa,aAAa;CAAG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RequestModule = void 0;
|
|
10
|
+
const axios_1 = require("@nestjs/axios");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const request_service_1 = require("./request.service");
|
|
13
|
+
let RequestModule = class RequestModule {
|
|
14
|
+
};
|
|
15
|
+
exports.RequestModule = RequestModule;
|
|
16
|
+
exports.RequestModule = RequestModule = __decorate([
|
|
17
|
+
(0, common_1.Global)(),
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [axios_1.HttpModule],
|
|
20
|
+
providers: [request_service_1.RequestService],
|
|
21
|
+
exports: [request_service_1.RequestService],
|
|
22
|
+
})
|
|
23
|
+
], RequestModule);
|
|
24
|
+
//# sourceMappingURL=request.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.module.js","sourceRoot":"","sources":["../src/request.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAA2C;AAC3C,2CAAgD;AAChD,uDAAmD;AAQ5C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IANzB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,kBAAU,CAAC;QACrB,SAAS,EAAE,CAAC,gCAAc,CAAC;QAC3B,OAAO,EAAE,CAAC,gCAAc,CAAC;KAC1B,CAAC;GACW,aAAa,CAAG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { HttpMethods } from './enums/http-methods.enum';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
interface ISendRequest {
|
|
5
|
+
method: HttpMethods;
|
|
6
|
+
body?: object;
|
|
7
|
+
path: string;
|
|
8
|
+
isAdditionalPath?: boolean;
|
|
9
|
+
token?: string;
|
|
10
|
+
headers?: object;
|
|
11
|
+
params?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ISubRequest {
|
|
14
|
+
body?: any;
|
|
15
|
+
path: string;
|
|
16
|
+
token?: string;
|
|
17
|
+
headers?: object;
|
|
18
|
+
params?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class RequestService<T> {
|
|
21
|
+
private readonly configService;
|
|
22
|
+
private readonly httpService;
|
|
23
|
+
constructor(configService: ConfigService, httpService: HttpService);
|
|
24
|
+
sendRaw({ method, body, isAdditionalPath, path, headers, token, }: ISendRequest): Promise<any>;
|
|
25
|
+
send({ method, body, path, headers, token, params, }: ISendRequest): Promise<any>;
|
|
26
|
+
post(payload: ISubRequest): Promise<any>;
|
|
27
|
+
get(payload: ISubRequest): Promise<any>;
|
|
28
|
+
patch(payload: ISubRequest): Promise<any>;
|
|
29
|
+
remove(payload: Omit<ISubRequest, 'body'>): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
export { HttpMethods };
|
|
32
|
+
//# sourceMappingURL=request.service.d.ts.map
|
|
@@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EAAE,WAAW;IAI1B,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;CAG1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpMethods = exports.RequestService = void 0;
|
|
13
|
+
const axios_1 = require("@nestjs/axios");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const rxjs_1 = require("rxjs");
|
|
16
|
+
const http_methods_enum_1 = require("./enums/http-methods.enum");
|
|
17
|
+
Object.defineProperty(exports, "HttpMethods", { enumerable: true, get: function () { return http_methods_enum_1.HttpMethods; } });
|
|
18
|
+
const config_1 = require("@nestjs/config");
|
|
19
|
+
let RequestService = class RequestService {
|
|
20
|
+
constructor(configService, httpService) {
|
|
21
|
+
this.configService = configService;
|
|
22
|
+
this.httpService = httpService;
|
|
23
|
+
}
|
|
24
|
+
async sendRaw({ method, body, isAdditionalPath, path, headers, token, }) {
|
|
25
|
+
const url = isAdditionalPath
|
|
26
|
+
? this.configService.get('app.baseUrl') + path
|
|
27
|
+
: path;
|
|
28
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.httpService.request({
|
|
29
|
+
method,
|
|
30
|
+
data: body || {},
|
|
31
|
+
url: url,
|
|
32
|
+
headers: {
|
|
33
|
+
...headers,
|
|
34
|
+
Authorization: `Bearer ${token}`,
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
async send({ method, body, path, headers, token, params, }) {
|
|
40
|
+
try {
|
|
41
|
+
const url = params ? path + `?${params}` : path;
|
|
42
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.httpService.request({
|
|
43
|
+
method,
|
|
44
|
+
url,
|
|
45
|
+
data: body || {},
|
|
46
|
+
headers: {
|
|
47
|
+
...headers,
|
|
48
|
+
Authorization: token ? `Bearer ${token}` : undefined,
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
return result?.data;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
post(payload) {
|
|
58
|
+
return this.send({ ...payload, method: http_methods_enum_1.HttpMethods.POST });
|
|
59
|
+
}
|
|
60
|
+
get(payload) {
|
|
61
|
+
return this.send({ ...payload, method: http_methods_enum_1.HttpMethods.GET });
|
|
62
|
+
}
|
|
63
|
+
patch(payload) {
|
|
64
|
+
return this.send({ ...payload, method: http_methods_enum_1.HttpMethods.PATCH });
|
|
65
|
+
}
|
|
66
|
+
remove(payload) {
|
|
67
|
+
return this.send({ ...payload, method: http_methods_enum_1.HttpMethods.DELETE });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.RequestService = RequestService;
|
|
71
|
+
exports.RequestService = RequestService = __decorate([
|
|
72
|
+
(0, common_1.Injectable)(),
|
|
73
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
74
|
+
axios_1.HttpService])
|
|
75
|
+
], RequestService);
|
|
76
|
+
//# sourceMappingURL=request.service.js.map
|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;gBACN,GAAG;gBACH,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,OAAO,EAAE;oBACP,GAAG,OAAO;oBACV,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS;iBACrD;aACF,CAAC,CACH,CAAC;YAEF,OAAO,MAAM,EAAE,IAAI,CAAC;QACtB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAoB;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,+BAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,GAAG,CAAC,OAAoB;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,+BAAW,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,OAAoB;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,+BAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,OAAkC;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,+BAAW,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA;AA5EY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGuB,sBAAa;QACf,mBAAW;GAHhC,cAAc,CA4E1B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mondart/nestjs-common-module-request",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "HTTP request module and service for NestJS.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Mondart"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@mondart/nestjs-common-module-core": "^3.0.0",
|
|
21
|
+
"@nestjs/axios": "^4.0.0",
|
|
22
|
+
"@nestjs/config": "^4.0.0",
|
|
23
|
+
"axios": "~1.15.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@nestjs/common": "^11.1.10",
|
|
27
|
+
"@nestjs/core": "^11.1.10",
|
|
28
|
+
"reflect-metadata": "^0.2.0",
|
|
29
|
+
"rxjs": "^7.8.2"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|