@mintlify/http-client 0.0.4 → 0.0.7
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 +93 -0
- package/README.md +16 -16
- package/dist/client/baseClient.d.ts +64 -63
- package/dist/client/baseClient.d.ts.map +1 -0
- package/dist/client/baseClient.js +94 -89
- package/dist/client/baseClient.js.map +1 -0
- package/dist/client/clientError.d.ts +33 -32
- package/dist/client/clientError.d.ts.map +1 -0
- package/dist/client/clientError.js +89 -81
- package/dist/client/clientError.js.map +1 -0
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -3
- package/dist/client/index.js.map +1 -0
- package/dist/client/interfaces.d.ts +94 -93
- package/dist/client/interfaces.d.ts.map +1 -0
- package/dist/client/interfaces.js +3 -1
- package/dist/client/interfaces.js.map +1 -0
- package/dist/client/types.d.ts +10 -9
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -1
- package/dist/client/types.js.map +1 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -0
- package/dist/leaves-client/constants.d.ts +22 -18
- package/dist/leaves-client/constants.d.ts.map +1 -0
- package/dist/leaves-client/constants.js +20 -13
- package/dist/leaves-client/constants.js.map +1 -0
- package/dist/leaves-client/index.d.ts +6 -5
- package/dist/leaves-client/index.d.ts.map +1 -0
- package/dist/leaves-client/index.js +24 -3
- package/dist/leaves-client/index.js.map +1 -0
- package/dist/leaves-client/interfaces.d.ts +19 -16
- package/dist/leaves-client/interfaces.d.ts.map +1 -0
- package/dist/leaves-client/interfaces.js +3 -1
- package/dist/leaves-client/interfaces.js.map +1 -0
- package/dist/leaves-client/leavesClient.d.ts +8 -7
- package/dist/leaves-client/leavesClient.d.ts.map +1 -0
- package/dist/leaves-client/leavesClient.js +96 -88
- package/dist/leaves-client/leavesClient.js.map +1 -0
- package/dist/leaves-client/types.d.ts +8 -11
- package/dist/leaves-client/types.d.ts.map +1 -0
- package/dist/leaves-client/types.js +3 -1
- package/dist/leaves-client/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +78 -78
- package/dist/setup-jest.d.ts +0 -1
- package/dist/setup-jest.js +0 -5
- package/dist/src/client/baseClient.d.ts +0 -63
- package/dist/src/client/baseClient.js +0 -180
- package/dist/src/client/clientError.d.ts +0 -32
- package/dist/src/client/clientError.js +0 -160
- package/dist/src/client/index.d.ts +0 -6
- package/dist/src/client/index.js +0 -7
- package/dist/src/client/interfaces.d.ts +0 -93
- package/dist/src/client/interfaces.js +0 -2
- package/dist/src/client/types.d.ts +0 -9
- package/dist/src/client/types.js +0 -2
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -18
- package/dist/src/leaves-client/constants.d.ts +0 -18
- package/dist/src/leaves-client/constants.js +0 -16
- package/dist/src/leaves-client/index.d.ts +0 -4
- package/dist/src/leaves-client/index.js +0 -8
- package/dist/src/leaves-client/interfaces.d.ts +0 -15
- package/dist/src/leaves-client/interfaces.js +0 -2
- package/dist/src/leaves-client/leavesClient.d.ts +0 -7
- package/dist/src/leaves-client/leavesClient.js +0 -157
- package/dist/src/leaves-client/types.d.ts +0 -11
- package/dist/src/leaves-client/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mintlify/http-client",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "The Mintlify http client package",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=18.0.0"
|
|
7
|
-
},
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
|
-
"author": "Mintlify, Inc.",
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/mintlify/docs/issues"
|
|
16
|
-
},
|
|
17
|
-
"license": "Elastic-2.0",
|
|
18
|
-
"keywords": [
|
|
19
|
-
"mintlify",
|
|
20
|
-
"mint",
|
|
21
|
-
"client",
|
|
22
|
-
"http"
|
|
23
|
-
],
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"format": "prettier \"./src/**/*.ts\" --
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"@mintlify/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@mintlify/eslint-config": "1.0.
|
|
56
|
-
"@mintlify/
|
|
57
|
-
"@mintlify/
|
|
58
|
-
"@mintlify/
|
|
59
|
-
"@mintlify/
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@types/
|
|
65
|
-
"@
|
|
66
|
-
"@typescript-eslint/
|
|
67
|
-
"
|
|
68
|
-
"eslint": "8.x",
|
|
69
|
-
"eslint-
|
|
70
|
-
"
|
|
71
|
-
"jest": "^
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"ts-jest": "^
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mintlify/http-client",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "The Mintlify http client package",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.0.0"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"author": "Mintlify, Inc.",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/mintlify/docs/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "Elastic-2.0",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mintlify",
|
|
20
|
+
"mint",
|
|
21
|
+
"client",
|
|
22
|
+
"http"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"prepare": "npm run build",
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"watch": "tsc --watch",
|
|
32
|
+
"lint": "eslint src --cache",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"format": "prettier \"./src/**/*.ts\" --write",
|
|
35
|
+
"format:check": "prettier \"./src/**/*.ts\" --check"
|
|
36
|
+
},
|
|
37
|
+
"jest": {
|
|
38
|
+
"preset": "ts-jest",
|
|
39
|
+
"resolver": "ts-jest-resolver",
|
|
40
|
+
"testEnvironment": "node",
|
|
41
|
+
"moduleDirectories": [
|
|
42
|
+
"node_modules",
|
|
43
|
+
"<rootDir>/"
|
|
44
|
+
],
|
|
45
|
+
"setupFilesAfterEnv": [
|
|
46
|
+
"<rootDir>/setup-jest.ts"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@mintlify/models": ">= 0.0.16 < 1",
|
|
51
|
+
"@mintlify/validation": ">= 0.1.52 < 1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@mintlify/eslint-config": "1.0.3",
|
|
55
|
+
"@mintlify/eslint-config-typescript": "1.0.7",
|
|
56
|
+
"@mintlify/models": "0.0.17",
|
|
57
|
+
"@mintlify/prettier-config": "1.0.1",
|
|
58
|
+
"@mintlify/ts-config": "1.0.7",
|
|
59
|
+
"@mintlify/validation": "0.1.52",
|
|
60
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
61
|
+
"@trivago/prettier-plugin-sort-imports": "3.x",
|
|
62
|
+
"@tsconfig/recommended": "1.x",
|
|
63
|
+
"@types/jest": "^29.4.0",
|
|
64
|
+
"@types/node": "^18.7.13",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "5.x",
|
|
66
|
+
"@typescript-eslint/parser": "5.x",
|
|
67
|
+
"eslint": "8.x",
|
|
68
|
+
"eslint-config-prettier": "8.x",
|
|
69
|
+
"eslint-plugin-unused-imports": "2.x",
|
|
70
|
+
"jest": "^29.4.3",
|
|
71
|
+
"jest-fetch-mock": "^3.0.3",
|
|
72
|
+
"prettier": "2.x",
|
|
73
|
+
"ts-jest": "^29.0.5",
|
|
74
|
+
"ts-jest-resolver": "^2.0.1",
|
|
75
|
+
"typescript": "^4.9.5"
|
|
76
|
+
},
|
|
77
|
+
"gitHead": "0ca9ce25f7c6def7d80e19ed2cf68b3a8a428374"
|
|
78
|
+
}
|
package/dist/setup-jest.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
package/dist/setup-jest.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { IBaseClient } from './interfaces';
|
|
2
|
-
import { HttpMethods, QueryType, RequestInitType } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* BaseClient serves as the base class for API clients.
|
|
5
|
-
* Provides basic functionalities for making HTTP requests to a server.
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class BaseClient implements IBaseClient {
|
|
8
|
-
readonly host: string;
|
|
9
|
-
protected readonly reqInit: RequestInit | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* @param host - The server's address.
|
|
12
|
-
* @param reqInit - Optional default request initializer.
|
|
13
|
-
*/
|
|
14
|
-
protected constructor(host: string, reqInit?: RequestInit | undefined);
|
|
15
|
-
fetch(path: string, query?: QueryType, init?: RequestInit): Promise<{
|
|
16
|
-
uri: string;
|
|
17
|
-
res: Response;
|
|
18
|
-
req: RequestInit;
|
|
19
|
-
}>;
|
|
20
|
-
get(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
21
|
-
put(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
22
|
-
delete(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
23
|
-
post(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
24
|
-
text(path: string, query?: QueryType, init?: RequestInit): Promise<string>;
|
|
25
|
-
json<T extends object>(path: string, query?: QueryType, init?: RequestInit): Promise<T>;
|
|
26
|
-
method(method: HttpMethods, path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
27
|
-
/**
|
|
28
|
-
* Constructs a URI path by joining URI components.
|
|
29
|
-
* @param paths - Paths to encode and join.
|
|
30
|
-
* @returns encoded URI path.
|
|
31
|
-
*/
|
|
32
|
-
getPath(...paths: string[]): string;
|
|
33
|
-
/**
|
|
34
|
-
* Constructs a URI by appending a path to the host.
|
|
35
|
-
* @param path - The path to append to the host.
|
|
36
|
-
* @returns URI string.
|
|
37
|
-
*/
|
|
38
|
-
getUri(path: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Handles text responses from the server.
|
|
41
|
-
* @param req - The request object.
|
|
42
|
-
* @param res - The response object.
|
|
43
|
-
* @param uri - The request URI.
|
|
44
|
-
* @returns Promise that resolves with the text data.
|
|
45
|
-
*/
|
|
46
|
-
protected handleText({ req, res, uri, }: {
|
|
47
|
-
req: RequestInit;
|
|
48
|
-
res: Response;
|
|
49
|
-
uri: string;
|
|
50
|
-
}): Promise<string>;
|
|
51
|
-
/**
|
|
52
|
-
* Handles JSON responses from the server.
|
|
53
|
-
* @param req - The request object.
|
|
54
|
-
* @param res - The response object.
|
|
55
|
-
* @param uri - The request URI.
|
|
56
|
-
* @returns Promise that resolves with the JSON data.
|
|
57
|
-
*/
|
|
58
|
-
protected handleJson<T>({ req, res, uri, }: {
|
|
59
|
-
req: RequestInit;
|
|
60
|
-
res: Response;
|
|
61
|
-
uri: string;
|
|
62
|
-
}): Promise<T>;
|
|
63
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.BaseClient = void 0;
|
|
51
|
-
var clientError_1 = require("./clientError");
|
|
52
|
-
/**
|
|
53
|
-
* BaseClient serves as the base class for API clients.
|
|
54
|
-
* Provides basic functionalities for making HTTP requests to a server.
|
|
55
|
-
*/
|
|
56
|
-
var BaseClient = /** @class */ (function () {
|
|
57
|
-
/**
|
|
58
|
-
* @param host - The server's address.
|
|
59
|
-
* @param reqInit - Optional default request initializer.
|
|
60
|
-
*/
|
|
61
|
-
function BaseClient(host, reqInit) {
|
|
62
|
-
if (reqInit === void 0) { reqInit = undefined; }
|
|
63
|
-
this.host = host;
|
|
64
|
-
this.reqInit = reqInit;
|
|
65
|
-
}
|
|
66
|
-
BaseClient.prototype.fetch = function (path, query, init) {
|
|
67
|
-
var _a;
|
|
68
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
-
var req, uri;
|
|
70
|
-
var _b;
|
|
71
|
-
return __generator(this, function (_c) {
|
|
72
|
-
switch (_c.label) {
|
|
73
|
-
case 0:
|
|
74
|
-
req = __assign(__assign(__assign({}, this.reqInit), init), { headers: __assign(__assign({}, (_a = this.reqInit) === null || _a === void 0 ? void 0 : _a.headers), init === null || init === void 0 ? void 0 : init.headers) });
|
|
75
|
-
uri = this.getUri(path);
|
|
76
|
-
uri = query ? "".concat(uri, "?").concat(new URLSearchParams(query)) : uri;
|
|
77
|
-
_b = { uri: uri };
|
|
78
|
-
return [4 /*yield*/, fetch(uri, req)];
|
|
79
|
-
case 1: return [2 /*return*/, (_b.res = _c.sent(), _b.req = req, _b)];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
BaseClient.prototype.get = function (path, query, init) {
|
|
85
|
-
return this.method('get', path, query, init);
|
|
86
|
-
};
|
|
87
|
-
BaseClient.prototype.put = function (path, query, init) {
|
|
88
|
-
return this.method('put', path, query, init);
|
|
89
|
-
};
|
|
90
|
-
BaseClient.prototype.delete = function (path, query, init) {
|
|
91
|
-
return this.method('delete', path, query, init);
|
|
92
|
-
};
|
|
93
|
-
BaseClient.prototype.post = function (path, query, init) {
|
|
94
|
-
return this.method('post', path, query, init);
|
|
95
|
-
};
|
|
96
|
-
BaseClient.prototype.text = function (path, query, init) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
-
var result;
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
switch (_a.label) {
|
|
101
|
-
case 0: return [4 /*yield*/, this.fetch(path, query, init)];
|
|
102
|
-
case 1:
|
|
103
|
-
result = _a.sent();
|
|
104
|
-
return [2 /*return*/, this.handleText(result)];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
BaseClient.prototype.json = function (path, query, init) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
-
var result;
|
|
112
|
-
return __generator(this, function (_a) {
|
|
113
|
-
switch (_a.label) {
|
|
114
|
-
case 0: return [4 /*yield*/, this.fetch(path, query, init)];
|
|
115
|
-
case 1:
|
|
116
|
-
result = _a.sent();
|
|
117
|
-
return [2 /*return*/, this.handleJson(result)];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
BaseClient.prototype.method = function (method, path, query, init) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
var result;
|
|
125
|
-
return __generator(this, function (_a) {
|
|
126
|
-
switch (_a.label) {
|
|
127
|
-
case 0: return [4 /*yield*/, this.fetch(path, query, __assign(__assign({}, init), { method: method }))];
|
|
128
|
-
case 1:
|
|
129
|
-
result = _a.sent();
|
|
130
|
-
return [2 /*return*/, result.res];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Constructs a URI path by joining URI components.
|
|
137
|
-
* @param paths - Paths to encode and join.
|
|
138
|
-
* @returns encoded URI path.
|
|
139
|
-
*/
|
|
140
|
-
BaseClient.prototype.getPath = function () {
|
|
141
|
-
var paths = [];
|
|
142
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
143
|
-
paths[_i] = arguments[_i];
|
|
144
|
-
}
|
|
145
|
-
return paths.map(encodeURIComponent).join('/');
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Constructs a URI by appending a path to the host.
|
|
149
|
-
* @param path - The path to append to the host.
|
|
150
|
-
* @returns URI string.
|
|
151
|
-
*/
|
|
152
|
-
BaseClient.prototype.getUri = function (path) {
|
|
153
|
-
return encodeURI("".concat(this.host, "/").concat(path));
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Handles text responses from the server.
|
|
157
|
-
* @param req - The request object.
|
|
158
|
-
* @param res - The response object.
|
|
159
|
-
* @param uri - The request URI.
|
|
160
|
-
* @returns Promise that resolves with the text data.
|
|
161
|
-
*/
|
|
162
|
-
BaseClient.prototype.handleText = function (_a) {
|
|
163
|
-
var req = _a.req, res = _a.res, uri = _a.uri;
|
|
164
|
-
return clientError_1.handleText.bind(this)(req, res, uri);
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Handles JSON responses from the server.
|
|
168
|
-
* @param req - The request object.
|
|
169
|
-
* @param res - The response object.
|
|
170
|
-
* @param uri - The request URI.
|
|
171
|
-
* @returns Promise that resolves with the JSON data.
|
|
172
|
-
*/
|
|
173
|
-
BaseClient.prototype.handleJson = function (_a) {
|
|
174
|
-
var req = _a.req, res = _a.res, uri = _a.uri;
|
|
175
|
-
var handle = (clientError_1.handleJson);
|
|
176
|
-
return handle.bind(this)(req, res, uri);
|
|
177
|
-
};
|
|
178
|
-
return BaseClient;
|
|
179
|
-
}());
|
|
180
|
-
exports.BaseClient = BaseClient;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BaseClient } from './baseClient';
|
|
2
|
-
import { IClientError } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* Type guard for ClientError.
|
|
5
|
-
* @param object - The object to check.
|
|
6
|
-
* @returns True if the object is a ClientError; otherwise, false.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isClientError(object: any): object is IClientError;
|
|
9
|
-
/**
|
|
10
|
-
* Fetches a resource as text.
|
|
11
|
-
* @param req - The request object.
|
|
12
|
-
* @param res - The response object.
|
|
13
|
-
* @param uri - The URI to fetch from.
|
|
14
|
-
* @throws ClientError - If the response is not ok.
|
|
15
|
-
* @returns The fetched text.
|
|
16
|
-
*/
|
|
17
|
-
export declare function handleText(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Fetches a resource as JSON.
|
|
20
|
-
* @param req - The request object.
|
|
21
|
-
* @param res - The response object.
|
|
22
|
-
* @param uri - The URI to fetch from.
|
|
23
|
-
* @throws ClientError - If the response is not ok.
|
|
24
|
-
* @returns The fetched JSON data.
|
|
25
|
-
*/
|
|
26
|
-
export declare function handleJson<T>(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<T>;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if a client has access to a resource.
|
|
29
|
-
* @param accessCondition - The condition to check to get access.
|
|
30
|
-
* @throws ClientError - If the condition is true.
|
|
31
|
-
*/
|
|
32
|
-
export declare function handleAccess<TClient extends BaseClient>(this: TClient, accessCondition: boolean): void;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.handleAccess = exports.handleJson = exports.handleText = exports.isClientError = void 0;
|
|
55
|
-
var constants_1 = require("../leaves-client/constants");
|
|
56
|
-
/**
|
|
57
|
-
* Represents a client-side error.
|
|
58
|
-
*/
|
|
59
|
-
var ClientError = /** @class */ (function (_super) {
|
|
60
|
-
__extends(ClientError, _super);
|
|
61
|
-
/**
|
|
62
|
-
* Constructs a ClientError.
|
|
63
|
-
* @param message - The error message.
|
|
64
|
-
* @param client - The BaseClient that generated the error.
|
|
65
|
-
* @param response - The server's response.
|
|
66
|
-
* @param request - The original request.
|
|
67
|
-
* @param uri - The URI to which the request was sent.
|
|
68
|
-
*/
|
|
69
|
-
function ClientError(message, client, response, request, uri) {
|
|
70
|
-
var _this = _super.call(this, message) || this;
|
|
71
|
-
_this.client = client;
|
|
72
|
-
_this.response = response;
|
|
73
|
-
_this.request = request;
|
|
74
|
-
_this.uri = uri;
|
|
75
|
-
return _this;
|
|
76
|
-
}
|
|
77
|
-
return ClientError;
|
|
78
|
-
}(Error));
|
|
79
|
-
/**
|
|
80
|
-
* Type guard for ClientError.
|
|
81
|
-
* @param object - The object to check.
|
|
82
|
-
* @returns True if the object is a ClientError; otherwise, false.
|
|
83
|
-
*/
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
function isClientError(object) {
|
|
86
|
-
return (object instanceof ClientError ||
|
|
87
|
-
('client' in object &&
|
|
88
|
-
'message' in object &&
|
|
89
|
-
'host' in object.client &&
|
|
90
|
-
'isPasswordProtected' in object.client &&
|
|
91
|
-
'subdomain' in object.client &&
|
|
92
|
-
'response' in object &&
|
|
93
|
-
'status' in object.response &&
|
|
94
|
-
!isNaN(object.response.status)));
|
|
95
|
-
}
|
|
96
|
-
exports.isClientError = isClientError;
|
|
97
|
-
/**
|
|
98
|
-
* Fetches a resource as text.
|
|
99
|
-
* @param req - The request object.
|
|
100
|
-
* @param res - The response object.
|
|
101
|
-
* @param uri - The URI to fetch from.
|
|
102
|
-
* @throws ClientError - If the response is not ok.
|
|
103
|
-
* @returns The fetched text.
|
|
104
|
-
*/
|
|
105
|
-
function handleText(req, res, uri) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
var text;
|
|
108
|
-
return __generator(this, function (_a) {
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0: return [4 /*yield*/, res.text()];
|
|
111
|
-
case 1:
|
|
112
|
-
text = _a.sent();
|
|
113
|
-
if (res.ok) {
|
|
114
|
-
return [2 /*return*/, text];
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw new ClientError(text, this, res, req, uri);
|
|
118
|
-
}
|
|
119
|
-
return [2 /*return*/];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
exports.handleText = handleText;
|
|
125
|
-
/**
|
|
126
|
-
* Fetches a resource as JSON.
|
|
127
|
-
* @param req - The request object.
|
|
128
|
-
* @param res - The response object.
|
|
129
|
-
* @param uri - The URI to fetch from.
|
|
130
|
-
* @throws ClientError - If the response is not ok.
|
|
131
|
-
* @returns The fetched JSON data.
|
|
132
|
-
*/
|
|
133
|
-
function handleJson(req, res, uri) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
-
var _a;
|
|
136
|
-
return __generator(this, function (_b) {
|
|
137
|
-
switch (_b.label) {
|
|
138
|
-
case 0:
|
|
139
|
-
if (!res.ok) return [3 /*break*/, 1];
|
|
140
|
-
return [2 /*return*/, res.json()];
|
|
141
|
-
case 1:
|
|
142
|
-
_a = ClientError.bind;
|
|
143
|
-
return [4 /*yield*/, res.text()];
|
|
144
|
-
case 2: throw new (_a.apply(ClientError, [void 0, _b.sent(), this, res, req, uri]))();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
exports.handleJson = handleJson;
|
|
150
|
-
/**
|
|
151
|
-
* Checks if a client has access to a resource.
|
|
152
|
-
* @param accessCondition - The condition to check to get access.
|
|
153
|
-
* @throws ClientError - If the condition is true.
|
|
154
|
-
*/
|
|
155
|
-
function handleAccess(accessCondition) {
|
|
156
|
-
if (!accessCondition) {
|
|
157
|
-
throw new ClientError(constants_1.ACCESS_DENIED, this, constants_1.UNAUTHORIZED);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.handleAccess = handleAccess;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BaseClient } from './baseClient';
|
|
2
|
-
import { isClientError } from './clientError';
|
|
3
|
-
import { IBaseClient, IClientError } from './interfaces';
|
|
4
|
-
import { HttpMethods, QueryType } from './types';
|
|
5
|
-
export { BaseClient, isClientError };
|
|
6
|
-
export type { IBaseClient, IClientError, HttpMethods, QueryType };
|
package/dist/src/client/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isClientError = exports.BaseClient = void 0;
|
|
4
|
-
var baseClient_1 = require("./baseClient");
|
|
5
|
-
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return baseClient_1.BaseClient; } });
|
|
6
|
-
var clientError_1 = require("./clientError");
|
|
7
|
-
Object.defineProperty(exports, "isClientError", { enumerable: true, get: function () { return clientError_1.isClientError; } });
|