cqrs-boilerplate-code 1.0.11 → 1.0.13
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/common-infra/common-infra.module.js +7 -1
- package/dist/common-infra/common-infra.module.js.map +1 -1
- package/dist/common-infra/http/axios.provider.d.ts +3 -0
- package/dist/common-infra/http/axios.provider.js +27 -0
- package/dist/common-infra/http/axios.provider.js.map +1 -0
- package/dist/common-infra/http/http-module.options.d.ts +10 -0
- package/dist/common-infra/http/http-module.options.js +3 -0
- package/dist/common-infra/http/http-module.options.js.map +1 -0
- package/dist/common-infra/http/http.constant.d.ts +3 -0
- package/dist/common-infra/http/http.constant.js +7 -0
- package/dist/common-infra/http/http.constant.js.map +1 -0
- package/dist/common-infra/http/http.module.d.ts +10 -0
- package/dist/common-infra/http/http.module.js +46 -0
- package/dist/common-infra/http/http.module.js.map +1 -0
- package/dist/common-infra/http/https.service.d.ts +18 -0
- package/dist/common-infra/http/https.service.js +96 -0
- package/dist/common-infra/http/https.service.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -11,15 +11,21 @@ exports.CommonInfraModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const config_1 = require("@nestjs/config");
|
|
13
13
|
const database_module_1 = require("./database/database.module");
|
|
14
|
+
const http_module_1 = require("./http/http.module");
|
|
14
15
|
let CommonInfraModule = CommonInfraModule_1 = class CommonInfraModule {
|
|
15
16
|
static forRoot() {
|
|
16
17
|
return {
|
|
17
18
|
module: CommonInfraModule_1,
|
|
18
19
|
imports: [
|
|
19
20
|
config_1.ConfigModule,
|
|
21
|
+
http_module_1.HttpModule.forRoot(),
|
|
20
22
|
database_module_1.DBModule,
|
|
21
23
|
],
|
|
22
|
-
exports: [
|
|
24
|
+
exports: [
|
|
25
|
+
http_module_1.HttpModule.forRoot(),
|
|
26
|
+
database_module_1.DBModule,
|
|
27
|
+
config_1.ConfigModule
|
|
28
|
+
],
|
|
23
29
|
};
|
|
24
30
|
}
|
|
25
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-infra.module.js","sourceRoot":"","sources":["../../src/common-infra/common-infra.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,2CAA8C;AAC9C,gEAAsD;
|
|
1
|
+
{"version":3,"file":"common-infra.module.js","sourceRoot":"","sources":["../../src/common-infra/common-infra.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,2CAA8C;AAC9C,gEAAsD;AACtD,oDAAgD;AAGzC,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAC5B,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,OAAO,EAAE;gBACP,qBAAY;gBACZ,wBAAU,CAAC,OAAO,EAAE;gBACpB,0BAAQ;aACT;YACD,OAAO,EAAE;gBACP,wBAAU,CAAC,OAAO,EAAE;gBACpB,0BAAQ;gBACR,qBAAY;aAAC;SAChB,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CAe7B","sourcesContent":["import { DynamicModule, Module } from \"@nestjs/common\";\nimport { ConfigModule } from \"@nestjs/config\";\nimport { DBModule } from \"./database/database.module\";\nimport { HttpModule } from \"./http/http.module\";\n\n@Module({})\nexport class CommonInfraModule {\n static forRoot(): DynamicModule {\n return {\n module: CommonInfraModule,\n imports: [\n ConfigModule,\n HttpModule.forRoot(),\n DBModule,\n ],\n exports: [\n HttpModule.forRoot(),\n DBModule,\n ConfigModule],\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAxiosProvider = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
9
|
+
const http_constant_1 = require("./http.constant");
|
|
10
|
+
const createAxiosProvider = (options) => ({
|
|
11
|
+
provide: http_constant_1.AXIOS_INSTANCE_TOKEN,
|
|
12
|
+
useFactory: () => {
|
|
13
|
+
const instance = axios_1.default.create(options.axios);
|
|
14
|
+
(0, axios_retry_1.default)(instance, {
|
|
15
|
+
retries: options.retry?.retries ?? 3,
|
|
16
|
+
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
17
|
+
retryCondition: (error) => {
|
|
18
|
+
const status = error.response?.status;
|
|
19
|
+
return (axios_retry_1.default.isNetworkOrIdempotentRequestError(error) ||
|
|
20
|
+
options.retry?.retryOnStatuses?.includes(status));
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return instance;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
exports.createAxiosProvider = createAxiosProvider;
|
|
27
|
+
//# sourceMappingURL=axios.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios.provider.js","sourceRoot":"","sources":["../../../src/common-infra/http/axios.provider.ts"],"names":[],"mappings":";;;;;;AACA,kDAA6C;AAC7C,8DAAqC;AAErC,mDAAuD;AAGhD,MAAM,mBAAmB,GAAG,CACjC,OAA0B,EAChB,EAAE,CAAC,CAAC;IACd,OAAO,EAAE,oCAAoB;IAC7B,UAAU,EAAE,GAAkB,EAAE;QAC9B,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAA,qBAAU,EAAC,QAAQ,EAAE;YACnB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,CAAC;YACpC,UAAU,EAAE,qBAAU,CAAC,gBAAgB;YACvC,cAAc,EAAE,CAAC,KAAK,EAAE,EAAE;gBACxB,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACtC,OAAO,CACL,qBAAU,CAAC,iCAAiC,CAAC,KAAK,CAAC;oBACnD,OAAO,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CACjD,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC,CAAC;AAnBU,QAAA,mBAAmB,uBAmB7B","sourcesContent":["// src/providers/axios.provider.ts\nimport axios, { AxiosInstance } from 'axios';\nimport axiosRetry from 'axios-retry';\nimport { Provider } from '@nestjs/common';\nimport { AXIOS_INSTANCE_TOKEN } from './http.constant';\nimport { HttpModuleOptions } from './http-module.options';\n\nexport const createAxiosProvider = (\n options: HttpModuleOptions,\n): Provider => ({\n provide: AXIOS_INSTANCE_TOKEN,\n useFactory: (): AxiosInstance => {\n const instance = axios.create(options.axios);\n axiosRetry(instance, {\n retries: options.retry?.retries ?? 3,\n retryDelay: axiosRetry.exponentialDelay,\n retryCondition: (error) => {\n const status = error.response?.status;\n return (\n axiosRetry.isNetworkOrIdempotentRequestError(error) ||\n options.retry?.retryOnStatuses?.includes(status)\n );\n },\n });\n return instance;\n },\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-module.options.js","sourceRoot":"","sources":["../../../src/common-infra/http/http-module.options.ts"],"names":[],"mappings":"","sourcesContent":["// src/interfaces/http-module.options.ts\nimport { AxiosRequestConfig } from 'axios';\n\nexport interface RetryOptions {\n retries?: number;\n retryDelay?: number;\n retryOnStatuses?: number[];\n}\n\nexport interface HttpModuleOptions {\n axios?: AxiosRequestConfig;\n retry?: RetryOptions;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTP_MODULE_OPTIONS = exports.HTTP_MODULE_ID = exports.AXIOS_INSTANCE_TOKEN = void 0;
|
|
4
|
+
exports.AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN';
|
|
5
|
+
exports.HTTP_MODULE_ID = 'HTTP_MODULE_ID';
|
|
6
|
+
exports.HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS';
|
|
7
|
+
//# sourceMappingURL=http.constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.constant.js","sourceRoot":"","sources":["../../../src/common-infra/http/http.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAC9C,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,mBAAmB,GAAG,qBAAqB,CAAC","sourcesContent":["export const AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN';\nexport const HTTP_MODULE_ID = 'HTTP_MODULE_ID';\nexport const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS';\n\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { HttpModuleOptions } from "./http-module.options";
|
|
3
|
+
export declare class HttpModule {
|
|
4
|
+
static forRoot(options?: HttpModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: {
|
|
6
|
+
useFactory: (...args: any[]) => HttpModuleOptions;
|
|
7
|
+
inject?: any[];
|
|
8
|
+
imports?: any[];
|
|
9
|
+
}): DynamicModule;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 HttpModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HttpModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const axios_provider_1 = require("./axios.provider");
|
|
13
|
+
const http_constant_1 = require("./http.constant");
|
|
14
|
+
const https_service_1 = require("./https.service");
|
|
15
|
+
let HttpModule = HttpModule_1 = class HttpModule {
|
|
16
|
+
static forRoot(options = {}) {
|
|
17
|
+
return {
|
|
18
|
+
module: HttpModule_1,
|
|
19
|
+
providers: [
|
|
20
|
+
(0, axios_provider_1.createAxiosProvider)(options),
|
|
21
|
+
https_service_1.HttpService,
|
|
22
|
+
],
|
|
23
|
+
exports: [https_service_1.HttpService],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static forRootAsync(options) {
|
|
27
|
+
return {
|
|
28
|
+
module: HttpModule_1,
|
|
29
|
+
imports: options.imports,
|
|
30
|
+
providers: [
|
|
31
|
+
{
|
|
32
|
+
provide: http_constant_1.AXIOS_INSTANCE_TOKEN,
|
|
33
|
+
inject: options.inject,
|
|
34
|
+
useFactory: (...args) => (0, axios_provider_1.createAxiosProvider)(options.useFactory(...args)).useFactory(),
|
|
35
|
+
},
|
|
36
|
+
https_service_1.HttpService,
|
|
37
|
+
],
|
|
38
|
+
exports: [https_service_1.HttpService],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.HttpModule = HttpModule;
|
|
43
|
+
exports.HttpModule = HttpModule = HttpModule_1 = __decorate([
|
|
44
|
+
(0, common_1.Module)({})
|
|
45
|
+
], HttpModule);
|
|
46
|
+
//# sourceMappingURL=http.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.module.js","sourceRoot":"","sources":["../../../src/common-infra/http/http.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAwE;AACxE,qDAAuD;AAEvD,mDAAuD;AACvD,mDAA8C;AAGvC,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACnB,MAAM,CAAC,OAAO,CAAC,UAA6B,EAAE;QAC1C,OAAO;YACH,MAAM,EAAE,YAAU;YAClB,SAAS,EAAE;gBACP,IAAA,oCAAmB,EAAC,OAAO,CAAC;gBAC5B,2BAAW;aACd;YACD,OAAO,EAAE,CAAC,2BAAW,CAAC;SACzB,CAAC;IACN,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAInB;QACG,OAAO;YACH,MAAM,EAAE,YAAU;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,oCAAoB;oBAC7B,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,UAAU,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,CAC1B,IAAA,oCAAmB,EAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAqB,CAAC,UAAU,EAAE;iBACzF;gBACD,2BAAW;aACd;YACD,OAAO,EAAE,CAAC,2BAAW,CAAC;SACzB,CAAC;IACN,CAAC;CACJ,CAAA;AAhCY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAgCtB","sourcesContent":["import { DynamicModule, FactoryProvider, Module } from \"@nestjs/common\";\nimport { createAxiosProvider } from \"./axios.provider\";\nimport { HttpModuleOptions } from \"./http-module.options\";\nimport { AXIOS_INSTANCE_TOKEN } from \"./http.constant\";\nimport { HttpService } from \"./https.service\";\n\n@Module({})\nexport class HttpModule {\n static forRoot(options: HttpModuleOptions = {}): DynamicModule {\n return {\n module: HttpModule,\n providers: [\n createAxiosProvider(options),\n HttpService,\n ],\n exports: [HttpService],\n };\n }\n\n static forRootAsync(options: {\n useFactory: (...args: any[]) => HttpModuleOptions;\n inject?: any[];\n imports?: any[];\n }): DynamicModule {\n return {\n module: HttpModule,\n imports: options.imports,\n providers: [\n {\n provide: AXIOS_INSTANCE_TOKEN,\n inject: options.inject,\n useFactory: (...args: any[]) =>\n (createAxiosProvider(options.useFactory(...args)) as FactoryProvider).useFactory(),\n },\n HttpService,\n ],\n exports: [HttpService],\n };\n }\n}"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class HttpService {
|
|
4
|
+
protected readonly instance: AxiosInstance;
|
|
5
|
+
constructor(instance?: AxiosInstance);
|
|
6
|
+
request<T = any>(config: AxiosRequestConfig): Observable<AxiosResponse<T>>;
|
|
7
|
+
get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
8
|
+
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
9
|
+
head<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
10
|
+
post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
11
|
+
put<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
12
|
+
patch<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
13
|
+
postForm<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
14
|
+
putForm<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
15
|
+
patchForm<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Observable<AxiosResponse<T, D>>;
|
|
16
|
+
get axiosRef(): AxiosInstance;
|
|
17
|
+
protected makeObservable<T>(axios: (...args: any[]) => AxiosPromise<T>, ...args: any[]): Observable<AxiosResponse<T, any, {}>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HttpService = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const axios_1 = __importDefault(require("axios"));
|
|
21
|
+
const rxjs_1 = require("rxjs");
|
|
22
|
+
const http_constant_1 = require("./http.constant");
|
|
23
|
+
let HttpService = class HttpService {
|
|
24
|
+
instance;
|
|
25
|
+
constructor(instance = axios_1.default) {
|
|
26
|
+
this.instance = instance;
|
|
27
|
+
}
|
|
28
|
+
request(config) {
|
|
29
|
+
return this.makeObservable(this.instance.request, config);
|
|
30
|
+
}
|
|
31
|
+
get(url, config) {
|
|
32
|
+
return this.makeObservable(this.instance.get, url, config);
|
|
33
|
+
}
|
|
34
|
+
delete(url, config) {
|
|
35
|
+
return this.makeObservable(this.instance.delete, url, config);
|
|
36
|
+
}
|
|
37
|
+
head(url, config) {
|
|
38
|
+
return this.makeObservable(this.instance.head, url, config);
|
|
39
|
+
}
|
|
40
|
+
post(url, data, config) {
|
|
41
|
+
return this.makeObservable(this.instance.post, url, data, config);
|
|
42
|
+
}
|
|
43
|
+
put(url, data, config) {
|
|
44
|
+
return this.makeObservable(this.instance.put, url, data, config);
|
|
45
|
+
}
|
|
46
|
+
patch(url, data, config) {
|
|
47
|
+
return this.makeObservable(this.instance.patch, url, data, config);
|
|
48
|
+
}
|
|
49
|
+
postForm(url, data, config) {
|
|
50
|
+
return this.makeObservable(this.instance.postForm, url, data, config);
|
|
51
|
+
}
|
|
52
|
+
putForm(url, data, config) {
|
|
53
|
+
return this.makeObservable(this.instance.putForm, url, data, config);
|
|
54
|
+
}
|
|
55
|
+
patchForm(url, data, config) {
|
|
56
|
+
return this.makeObservable(this.instance.patchForm, url, data, config);
|
|
57
|
+
}
|
|
58
|
+
get axiosRef() {
|
|
59
|
+
return this.instance;
|
|
60
|
+
}
|
|
61
|
+
makeObservable(axios, ...args) {
|
|
62
|
+
return new rxjs_1.Observable(subscriber => {
|
|
63
|
+
const argsCopy = [...args];
|
|
64
|
+
const configIdx = argsCopy.length - 1;
|
|
65
|
+
const config = { ...(argsCopy[configIdx] || {}) };
|
|
66
|
+
argsCopy[configIdx] = config;
|
|
67
|
+
let cancelSource;
|
|
68
|
+
if (!config.cancelToken) {
|
|
69
|
+
cancelSource = axios_1.default.CancelToken.source();
|
|
70
|
+
config.cancelToken = cancelSource.token;
|
|
71
|
+
}
|
|
72
|
+
axios(...argsCopy)
|
|
73
|
+
.then(res => {
|
|
74
|
+
subscriber.next(res);
|
|
75
|
+
subscriber.complete();
|
|
76
|
+
})
|
|
77
|
+
.catch(err => {
|
|
78
|
+
subscriber.error(err);
|
|
79
|
+
});
|
|
80
|
+
return () => {
|
|
81
|
+
if (config.responseType === 'stream') {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (cancelSource) {
|
|
85
|
+
cancelSource.cancel();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.HttpService = HttpService;
|
|
92
|
+
exports.HttpService = HttpService = __decorate([
|
|
93
|
+
__param(0, (0, common_1.Inject)(http_constant_1.AXIOS_INSTANCE_TOKEN)),
|
|
94
|
+
__metadata("design:paramtypes", [Function])
|
|
95
|
+
], HttpService);
|
|
96
|
+
//# sourceMappingURL=https.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"https.service.js","sourceRoot":"","sources":["../../../src/common-infra/http/https.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAwC;AACxC,kDAMe;AACf,+BAAkC;AAClC,mDAAuD;AAEvD,IAAa,WAAW,GAAxB,MAAa,WAAW;IAGD;IAFrB,YAEqB,WAA0B,eAAK;QAA/B,aAAQ,GAAR,QAAQ,CAAuB;IACjD,CAAC;IAEJ,OAAO,CAAU,MAA0B;QACzC,OAAO,IAAI,CAAC,cAAc,CAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,GAAG,CACD,GAAW,EACX,MAA8B;QAE9B,OAAO,IAAI,CAAC,cAAc,CAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CACJ,GAAW,EACX,MAA8B;QAE9B,O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CACF,CAAA;AApJY,kCAAW;sBAAX,WAAW;IAEnB,WAAA,IAAA,eAAM,EAAC,oCAAoB,CAAC,CAAA;;GAFpB,WAAW,CAoJvB","sourcesContent":["import { Inject } from '@nestjs/common';\nimport Axios, {\n AxiosInstance,\n AxiosPromise,\n AxiosRequestConfig,\n AxiosResponse,\n CancelTokenSource,\n} from 'axios';\nimport { Observable } from 'rxjs';\nimport { AXIOS_INSTANCE_TOKEN } from './http.constant';\n\nexport class HttpService {\n constructor(\n @Inject(AXIOS_INSTANCE_TOKEN)\n protected readonly instance: AxiosInstance = Axios,\n ) {}\n\n request<T = any>(config: AxiosRequestConfig): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.request, config);\n }\n\n get<T = any, D = any>(\n url: string,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>> {\n return this.makeObservable<T>(this.instance.get, url, config);\n }\n\n delete<T = any, D = any>(\n url: string,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>> {\n return this.makeObservable<T>(this.instance.delete, url, config);\n }\n\n head<T = any, D = any>(\n url: string,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>> {\n return this.makeObservable<T>(this.instance.head, url, config);\n }\n\n post<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n post<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.post, url, data, config);\n }\n\n put<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n put<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.put, url, data, config);\n }\n\n patch<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n patch<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.patch, url, data, config);\n }\n\n postForm<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n postForm<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.postForm, url, data, config);\n }\n\n putForm<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n putForm<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.putForm, url, data, config);\n }\n\n patchForm<T = any, D = any>(\n url: string,\n data?: D,\n config?: AxiosRequestConfig<D>,\n ): Observable<AxiosResponse<T, D>>;\n patchForm<T = any>(\n url: string,\n data?: any,\n config?: AxiosRequestConfig,\n ): Observable<AxiosResponse<T>> {\n return this.makeObservable<T>(this.instance.patchForm, url, data, config);\n }\n\n get axiosRef(): AxiosInstance {\n return this.instance;\n }\n\n protected makeObservable<T>(\n axios: (...args: any[]) => AxiosPromise<T>,\n ...args: any[]\n ) {\n return new Observable<AxiosResponse<T>>(subscriber => {\n const argsCopy = [...args];\n const configIdx = argsCopy.length - 1;\n const config: AxiosRequestConfig = { ...(argsCopy[configIdx] || {}) };\n argsCopy[configIdx] = config;\n\n let cancelSource: CancelTokenSource;\n if (!config.cancelToken) {\n cancelSource = Axios.CancelToken.source();\n config.cancelToken = cancelSource.token;\n }\n\n axios(...argsCopy)\n .then(res => {\n subscriber.next(res);\n subscriber.complete();\n })\n .catch(err => {\n subscriber.error(err);\n });\n return () => {\n if (config.responseType === 'stream') {\n return;\n }\n\n if (cancelSource) {\n cancelSource.cancel();\n }\n };\n });\n }\n}"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,3 +21,7 @@ export * from './core-common/core-common.module';
|
|
|
21
21
|
export * from './core-common/constant/app.constant';
|
|
22
22
|
export * from './common-infra/common-infra.module';
|
|
23
23
|
export * from './common-infra/database/typeorm.config';
|
|
24
|
+
export * from './common-infra/http/http.module';
|
|
25
|
+
export * from './common-infra/http/https.service';
|
|
26
|
+
export * from './common-infra/http/http.constant';
|
|
27
|
+
export * from './common-infra/http/http-module.options';
|
package/dist/index.js
CHANGED
|
@@ -37,4 +37,8 @@ __exportStar(require("./core-common/core-common.module"), exports);
|
|
|
37
37
|
__exportStar(require("./core-common/constant/app.constant"), exports);
|
|
38
38
|
__exportStar(require("./common-infra/common-infra.module"), exports);
|
|
39
39
|
__exportStar(require("./common-infra/database/typeorm.config"), exports);
|
|
40
|
+
__exportStar(require("./common-infra/http/http.module"), exports);
|
|
41
|
+
__exportStar(require("./common-infra/http/https.service"), exports);
|
|
42
|
+
__exportStar(require("./common-infra/http/http.constant"), exports);
|
|
43
|
+
__exportStar(require("./common-infra/http/http-module.options"), exports);
|
|
40
44
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,sEAAmD;AAGnD,wFAAqE;AACrE,mFAAgE;AAChE,oFAAiE;AACjE,yFAAsE;AACtE,sFAAmE;AACnE,6FAA0E;AAC1E,oEAAiD;AACjD,qFAAkE;AAClE,2FAAwE;AACxE,mFAAgE;AAChE,0FAAuE;AACvE,kFAA+D;AAG/D,oEAAiD;AACjD,4FAAyE;AACzE,8FAA2E;AAG3E,wEAAqD;AACrD,qEAAkD;AAClD,sEAAmD;AAGnD,mEAAgD;AAChD,sEAAmD;AACnD,qEAAmD;AACnD,yEAAuD","sourcesContent":["\nexport * from './core-common/constant/app.constant'\n\n// Error Exports\nexport * from './core-common/error/custom-error/already-exists.error'\nexport * from './core-common/error/custom-error/not-found.error'\nexport * from './core-common/error/custom-error/validation.error'\nexport * from './core-common/error/custom-error/internal-server.error'\nexport * from './core-common/error/custom-error/unauthorized.error'\nexport * from './core-common/error/custom-error/service-unavailable.error'\nexport * from './core-common/error/generic.error'\nexport * from './core-common/error/custom-error/bad-request.error'\nexport * from './core-common/error/custom-error/custom-validation-error'\nexport * from './core-common/error/custom-error/forbidden.error'\nexport * from './core-common/error/custom-error/unprocess-entity.error'\nexport * from './core-common/error/custom-error/conflict.error'\n\n// Model Exports\nexport * from './core-common/result-model/result'\nexport * from './core-common/response-model/generic-error-response.model'\nexport * from './core-common/response-model/generic-success-response.model'\n\n// Logger Exports\nexport * from './core-common/logger/logger.interface'\nexport * from './core-common/logger/logger.module'\nexport * from './core-common/logger/logger.service'\n\n// Module Exports\nexport * from './core-common/core-common.module'\nexport * from './core-common/constant/app.constant'\nexport * from './common-infra/common-infra.module';\nexport * from './common-infra/database/typeorm.config';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,sEAAmD;AAGnD,wFAAqE;AACrE,mFAAgE;AAChE,oFAAiE;AACjE,yFAAsE;AACtE,sFAAmE;AACnE,6FAA0E;AAC1E,oEAAiD;AACjD,qFAAkE;AAClE,2FAAwE;AACxE,mFAAgE;AAChE,0FAAuE;AACvE,kFAA+D;AAG/D,oEAAiD;AACjD,4FAAyE;AACzE,8FAA2E;AAG3E,wEAAqD;AACrD,qEAAkD;AAClD,sEAAmD;AAGnD,mEAAgD;AAChD,sEAAmD;AACnD,qEAAmD;AACnD,yEAAuD;AAGvD,kEAAgD;AAChD,oEAAkD;AAClD,oEAAkD;AAClD,0EAAwD","sourcesContent":["\nexport * from './core-common/constant/app.constant'\n\n// Error Exports\nexport * from './core-common/error/custom-error/already-exists.error'\nexport * from './core-common/error/custom-error/not-found.error'\nexport * from './core-common/error/custom-error/validation.error'\nexport * from './core-common/error/custom-error/internal-server.error'\nexport * from './core-common/error/custom-error/unauthorized.error'\nexport * from './core-common/error/custom-error/service-unavailable.error'\nexport * from './core-common/error/generic.error'\nexport * from './core-common/error/custom-error/bad-request.error'\nexport * from './core-common/error/custom-error/custom-validation-error'\nexport * from './core-common/error/custom-error/forbidden.error'\nexport * from './core-common/error/custom-error/unprocess-entity.error'\nexport * from './core-common/error/custom-error/conflict.error'\n\n// Model Exports\nexport * from './core-common/result-model/result'\nexport * from './core-common/response-model/generic-error-response.model'\nexport * from './core-common/response-model/generic-success-response.model'\n\n// Logger Exports\nexport * from './core-common/logger/logger.interface'\nexport * from './core-common/logger/logger.module'\nexport * from './core-common/logger/logger.service'\n\n// Module Exports\nexport * from './core-common/core-common.module'\nexport * from './core-common/constant/app.constant'\nexport * from './common-infra/common-infra.module';\nexport * from './common-infra/database/typeorm.config';\n\n// HTTP Exports\nexport * from './common-infra/http/http.module';\nexport * from './common-infra/http/https.service';\nexport * from './common-infra/http/http.constant';\nexport * from './common-infra/http/http-module.options';\n"]}
|