@qte/nest-axios 1.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/http.constants.d.ts +1 -0
- package/dist/http.constants.js +4 -0
- package/dist/http.module.d.ts +6 -0
- package/dist/http.module.js +42 -0
- package/dist/http.service.d.ts +13 -0
- package/dist/http.service.js +53 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/package.json +61 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 QTE Development AB
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# @qte/nest-axios
|
2
|
+
This small library is a rewrite of [@nestjs/axios](https://github.com/nestjs/axios/tree/master/lib) returning `Promises` instead of `Observables`.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
```bash
|
6
|
+
$ yarn add @qte/nest-axios
|
7
|
+
```
|
8
|
+
|
9
|
+
## License
|
10
|
+
@qte/nest-axios is [MIT licensed](LICENSE).
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const AXIOS_INSTANCE_TOKEN: unique symbol;
|
@@ -0,0 +1,42 @@
|
|
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 http_service_1 = require("./http.service");
|
13
|
+
const http_constants_1 = require("./http.constants");
|
14
|
+
const axios_1 = require("axios");
|
15
|
+
let HttpModule = HttpModule_1 = class HttpModule {
|
16
|
+
static register(config) {
|
17
|
+
return {
|
18
|
+
module: HttpModule_1,
|
19
|
+
providers: [
|
20
|
+
http_service_1.HttpService,
|
21
|
+
{
|
22
|
+
provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
|
23
|
+
useValue: axios_1.default.create(config),
|
24
|
+
},
|
25
|
+
],
|
26
|
+
exports: [http_service_1.HttpService],
|
27
|
+
};
|
28
|
+
}
|
29
|
+
};
|
30
|
+
HttpModule = HttpModule_1 = __decorate([
|
31
|
+
(0, common_1.Module)({
|
32
|
+
providers: [
|
33
|
+
http_service_1.HttpService,
|
34
|
+
{
|
35
|
+
provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
|
36
|
+
useValue: axios_1.default,
|
37
|
+
},
|
38
|
+
],
|
39
|
+
exports: [http_service_1.HttpService],
|
40
|
+
})
|
41
|
+
], HttpModule);
|
42
|
+
exports.HttpModule = HttpModule;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
2
|
+
export declare class HttpService {
|
3
|
+
protected readonly instance: AxiosInstance;
|
4
|
+
constructor(instance?: AxiosInstance);
|
5
|
+
request<T = unknown>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
6
|
+
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
7
|
+
delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
8
|
+
head<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
9
|
+
post<T = unknown>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
10
|
+
put<T = unknown>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
11
|
+
patch<T = unknown>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
12
|
+
get axiosRef(): AxiosInstance;
|
13
|
+
}
|
@@ -0,0 +1,53 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.HttpService = void 0;
|
16
|
+
const common_1 = require("@nestjs/common");
|
17
|
+
const axios_1 = require("axios");
|
18
|
+
const http_constants_1 = require("./http.constants");
|
19
|
+
let HttpService = class HttpService {
|
20
|
+
constructor(instance = axios_1.default) {
|
21
|
+
this.instance = instance;
|
22
|
+
}
|
23
|
+
request(config) {
|
24
|
+
return this.instance.request(config);
|
25
|
+
}
|
26
|
+
get(url, config) {
|
27
|
+
return this.instance.get(url, config);
|
28
|
+
}
|
29
|
+
delete(url, config) {
|
30
|
+
return this.instance.delete(url, config);
|
31
|
+
}
|
32
|
+
head(url, config) {
|
33
|
+
return this.instance.head(url, config);
|
34
|
+
}
|
35
|
+
post(url, data, config) {
|
36
|
+
return this.instance.post(url, data, config);
|
37
|
+
}
|
38
|
+
put(url, data, config) {
|
39
|
+
return this.instance.put(url, data, config);
|
40
|
+
}
|
41
|
+
patch(url, data, config) {
|
42
|
+
return this.instance.patch(url, data, config);
|
43
|
+
}
|
44
|
+
get axiosRef() {
|
45
|
+
return this.instance;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
HttpService = __decorate([
|
49
|
+
(0, common_1.Injectable)(),
|
50
|
+
__param(0, (0, common_1.Inject)(http_constants_1.AXIOS_INSTANCE_TOKEN)),
|
51
|
+
__metadata("design:paramtypes", [Function])
|
52
|
+
], HttpService);
|
53
|
+
exports.HttpService = HttpService;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { HttpModule } from './http.module';
|
package/dist/index.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.HttpModule = void 0;
|
4
|
+
var http_module_1 = require("./http.module");
|
5
|
+
Object.defineProperty(exports, "HttpModule", { enumerable: true, get: function () { return http_module_1.HttpModule; } });
|
package/package.json
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
{
|
2
|
+
"name": "@qte/nest-axios",
|
3
|
+
"version": "1.0.0-alpha.1",
|
4
|
+
"private": false,
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"author": "Jakob Råhlén <jakob@qte.se>",
|
7
|
+
"license": "MIT",
|
8
|
+
"files": [
|
9
|
+
"/dist"
|
10
|
+
],
|
11
|
+
"scripts": {
|
12
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
13
|
+
"test": "jest --config ./jest.json --runInBand",
|
14
|
+
"test:watch": "jest --config ./jest.json --watch --runInBand",
|
15
|
+
"prepare": "husky install",
|
16
|
+
"lint": "eslint .",
|
17
|
+
"lint:fix": "eslint . --fix",
|
18
|
+
"prerelease": "yarn build",
|
19
|
+
"release": "semantic-release"
|
20
|
+
},
|
21
|
+
"devDependencies": {
|
22
|
+
"@commitlint/cli": "^17.3.0",
|
23
|
+
"@commitlint/config-conventional": "^17.3.0",
|
24
|
+
"@nestjs/common": "^9.2.0",
|
25
|
+
"@nestjs/core": "^9.2.0",
|
26
|
+
"@nestjs/platform-express": "^9.2.0",
|
27
|
+
"@nestjs/testing": "^9.2.0",
|
28
|
+
"@types/express": "^4.17.14",
|
29
|
+
"@types/jest": "^29.2.3",
|
30
|
+
"@types/node": "^18.11.9",
|
31
|
+
"@types/supertest": "^2.0.12",
|
32
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
33
|
+
"@typescript-eslint/parser": "^5.44.0",
|
34
|
+
"eslint": "^8.28.0",
|
35
|
+
"eslint-config-prettier": "^8.5.0",
|
36
|
+
"eslint-plugin-jest": "^27.1.5",
|
37
|
+
"eslint-plugin-prettier": "^4.2.1",
|
38
|
+
"express": "^4.18.2",
|
39
|
+
"husky": "^8.0.2",
|
40
|
+
"jest": "^29.3.1",
|
41
|
+
"prettier": "^2.8.0",
|
42
|
+
"reflect-metadata": "^0.1.13",
|
43
|
+
"rxjs": "^7.2.0",
|
44
|
+
"semantic-release": "^19.0.5",
|
45
|
+
"supertest": "^6.3.1",
|
46
|
+
"ts-jest": "^29.0.3",
|
47
|
+
"typescript": "^4.9.3"
|
48
|
+
},
|
49
|
+
"peerDependencies": {
|
50
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0",
|
51
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0",
|
52
|
+
"reflect-metadata": "^0.1.13",
|
53
|
+
"rxjs": "^7.2.0"
|
54
|
+
},
|
55
|
+
"publishConfig": {
|
56
|
+
"access": "public"
|
57
|
+
},
|
58
|
+
"dependencies": {
|
59
|
+
"axios": "^1.2.0"
|
60
|
+
}
|
61
|
+
}
|