@fecommunity/reactpress-toolkit 1.0.0-beta.2 → 1.0.0-beta.3
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/README.md +221 -6
- package/dist/api/Article.d.ts +43 -28
- package/dist/api/Article.js +42 -31
- package/dist/api/Auth.d.ts +12 -7
- package/dist/api/Auth.js +12 -10
- package/dist/api/Category.d.ts +19 -12
- package/dist/api/Category.js +18 -15
- package/dist/api/Comment.d.ts +22 -14
- package/dist/api/Comment.js +21 -17
- package/dist/api/File.d.ts +16 -10
- package/dist/api/File.js +15 -13
- package/dist/{HttpClient.d.ts → api/HttpClient.d.ts} +2 -2
- package/dist/{HttpClient.js → api/HttpClient.js} +4 -2
- package/dist/api/Knowledge.d.ts +28 -18
- package/dist/api/Knowledge.js +27 -22
- package/dist/api/Page.d.ts +22 -14
- package/dist/api/Page.js +21 -17
- package/dist/api/Search.d.ts +12 -7
- package/dist/api/Search.js +12 -10
- package/dist/api/Setting.d.ts +10 -6
- package/dist/api/Setting.js +9 -9
- package/dist/api/Smtp.d.ts +13 -8
- package/dist/api/Smtp.js +12 -11
- package/dist/api/Tag.d.ts +22 -14
- package/dist/api/Tag.js +21 -17
- package/dist/api/User.d.ts +17 -10
- package/dist/api/User.js +16 -16
- package/dist/api/View.d.ts +19 -12
- package/dist/api/View.js +18 -15
- package/dist/api/index.d.ts +13 -18
- package/dist/api/index.js +28 -40
- package/dist/api/instance.d.ts +47 -0
- package/dist/api/instance.js +71 -0
- package/dist/config/env.d.ts +1 -0
- package/dist/config/env.js +93 -0
- package/dist/config/global.d.ts +34 -0
- package/dist/config/global.js +382 -0
- package/dist/config/i18n.d.ts +5 -0
- package/dist/config/i18n.js +47 -0
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.js +30 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +21 -18
- package/dist/locales/en.json +97 -0
- package/dist/locales/zh.json +97 -0
- package/dist/types/index.d.ts +245 -1
- package/dist/types/index.js +10 -17
- package/dist/utils/index.d.ts +33 -2
- package/dist/utils/index.js +57 -18
- package/package.json +12 -5
- package/dist/Article.d.ts +0 -121
- package/dist/Article.js +0 -189
- package/dist/Auth.d.ts +0 -30
- package/dist/Auth.js +0 -59
- package/dist/Category.d.ts +0 -49
- package/dist/Category.js +0 -85
- package/dist/Comment.d.ts +0 -58
- package/dist/Comment.js +0 -98
- package/dist/File.d.ts +0 -40
- package/dist/File.js +0 -72
- package/dist/Knowledge.d.ts +0 -76
- package/dist/Knowledge.js +0 -124
- package/dist/Page.d.ts +0 -58
- package/dist/Page.js +0 -98
- package/dist/Search.d.ts +0 -30
- package/dist/Search.js +0 -59
- package/dist/Setting.d.ts +0 -22
- package/dist/Setting.js +0 -46
- package/dist/Smtp.d.ts +0 -31
- package/dist/Smtp.js +0 -59
- package/dist/Tag.d.ts +0 -58
- package/dist/Tag.js +0 -98
- package/dist/User.d.ts +0 -41
- package/dist/User.js +0 -73
- package/dist/View.d.ts +0 -49
- package/dist/View.js +0 -85
- package/dist/api/Admin.d.ts +0 -14
- package/dist/api/Admin.js +0 -32
- package/dist/api/All.d.ts +0 -14
- package/dist/api/All.js +0 -32
- package/dist/api/ApiInstance.d.ts +0 -39
- package/dist/api/ApiInstance.js +0 -46
- package/dist/api/Archives.d.ts +0 -14
- package/dist/api/Archives.js +0 -32
- package/dist/api/ArticleRoute.d.ts +0 -201
- package/dist/api/ArticleRoute.js +0 -12
- package/dist/api/AuthRoute.d.ts +0 -44
- package/dist/api/AuthRoute.js +0 -12
- package/dist/api/Book.d.ts +0 -15
- package/dist/api/Book.js +0 -33
- package/dist/api/CategoryRoute.d.ts +0 -79
- package/dist/api/CategoryRoute.js +0 -12
- package/dist/api/Chapter.d.ts +0 -15
- package/dist/api/Chapter.js +0 -33
- package/dist/api/CommentRoute.d.ts +0 -95
- package/dist/api/CommentRoute.js +0 -12
- package/dist/api/FileRoute.d.ts +0 -63
- package/dist/api/FileRoute.js +0 -12
- package/dist/api/Get.d.ts +0 -14
- package/dist/api/Get.js +0 -32
- package/dist/api/Github.d.ts +0 -14
- package/dist/api/Github.js +0 -32
- package/dist/api/Host.d.ts +0 -14
- package/dist/api/Host.js +0 -32
- package/dist/api/Id.d.ts +0 -284
- package/dist/api/Id.js +0 -422
- package/dist/api/KnowledgeRoute.d.ts +0 -125
- package/dist/api/KnowledgeRoute.js +0 -12
- package/dist/api/Login.d.ts +0 -14
- package/dist/api/Login.js +0 -32
- package/dist/api/PageRoute.d.ts +0 -95
- package/dist/api/PageRoute.js +0 -12
- package/dist/api/Password.d.ts +0 -15
- package/dist/api/Password.js +0 -33
- package/dist/api/Recommend.d.ts +0 -14
- package/dist/api/Recommend.js +0 -32
- package/dist/api/Register.d.ts +0 -15
- package/dist/api/Register.js +0 -33
- package/dist/api/SearchRoute.d.ts +0 -46
- package/dist/api/SearchRoute.js +0 -12
- package/dist/api/SettingRoute.d.ts +0 -31
- package/dist/api/SettingRoute.js +0 -12
- package/dist/api/SmtpRoute.d.ts +0 -47
- package/dist/api/SmtpRoute.js +0 -12
- package/dist/api/TagRoute.d.ts +0 -95
- package/dist/api/TagRoute.js +0 -12
- package/dist/api/Update.d.ts +0 -15
- package/dist/api/Update.js +0 -33
- package/dist/api/Upload.d.ts +0 -15
- package/dist/api/Upload.js +0 -33
- package/dist/api/Url.d.ts +0 -14
- package/dist/api/Url.js +0 -32
- package/dist/api/UserRoute.d.ts +0 -60
- package/dist/api/UserRoute.js +0 -12
- package/dist/api/ViewRoute.d.ts +0 -77
- package/dist/api/ViewRoute.js +0 -12
- package/dist/api/api-instance.d.ts +0 -39
- package/dist/api/api-instance.js +0 -46
- package/dist/api/http-client.d.ts +0 -41
- package/dist/api/http-client.js +0 -94
- package/dist/api/httpClient.d.ts +0 -42
- package/dist/api/httpClient.js +0 -95
- package/dist/data-contracts.d.ts +0 -245
- package/dist/data-contracts.js +0 -12
- package/dist/types/data-contracts.d.ts +0 -177
- package/dist/types/data-contracts.js +0 -12
- package/dist/utils/common.d.ts +0 -21
- package/dist/utils/common.js +0 -52
- package/dist/utils/http.d.ts +0 -3
- package/dist/utils/http.js +0 -45
package/dist/api/ViewRoute.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { IView } from '../types/data-contracts';
|
|
2
|
-
export declare namespace View {
|
|
3
|
-
/**
|
|
4
|
-
* No description
|
|
5
|
-
* @tags View
|
|
6
|
-
* @name create
|
|
7
|
-
* @request POST:/view
|
|
8
|
-
* @response `200` `(IView)[]` 访问记录添加成功
|
|
9
|
-
*/
|
|
10
|
-
namespace create {
|
|
11
|
-
type RequestParams = {};
|
|
12
|
-
type RequestQuery = {};
|
|
13
|
-
type RequestBody = never;
|
|
14
|
-
type RequestHeaders = {};
|
|
15
|
-
type ResponseBody = IView[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* No description
|
|
19
|
-
* @tags View
|
|
20
|
-
* @name findAll
|
|
21
|
-
* @request GET:/view
|
|
22
|
-
* @response `200` `void`
|
|
23
|
-
*/
|
|
24
|
-
namespace findAll {
|
|
25
|
-
type RequestParams = {};
|
|
26
|
-
type RequestQuery = {};
|
|
27
|
-
type RequestBody = never;
|
|
28
|
-
type RequestHeaders = {};
|
|
29
|
-
type ResponseBody = void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* No description
|
|
33
|
-
* @tags View
|
|
34
|
-
* @name findByUrl
|
|
35
|
-
* @request GET:/view/url
|
|
36
|
-
* @response `200` `void`
|
|
37
|
-
*/
|
|
38
|
-
namespace findByUrl {
|
|
39
|
-
type RequestParams = {};
|
|
40
|
-
type RequestQuery = {};
|
|
41
|
-
type RequestBody = never;
|
|
42
|
-
type RequestHeaders = {};
|
|
43
|
-
type ResponseBody = void;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* No description
|
|
47
|
-
* @tags View
|
|
48
|
-
* @name findById
|
|
49
|
-
* @request GET:/view/{id}
|
|
50
|
-
* @response `200` `void`
|
|
51
|
-
*/
|
|
52
|
-
namespace findById {
|
|
53
|
-
type RequestParams = {
|
|
54
|
-
id: string;
|
|
55
|
-
};
|
|
56
|
-
type RequestQuery = {};
|
|
57
|
-
type RequestBody = never;
|
|
58
|
-
type RequestHeaders = {};
|
|
59
|
-
type ResponseBody = void;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* No description
|
|
63
|
-
* @tags View
|
|
64
|
-
* @name deleteById
|
|
65
|
-
* @request DELETE:/view/{id}
|
|
66
|
-
* @response `200` `void`
|
|
67
|
-
*/
|
|
68
|
-
namespace deleteById {
|
|
69
|
-
type RequestParams = {
|
|
70
|
-
id: string;
|
|
71
|
-
};
|
|
72
|
-
type RequestQuery = {};
|
|
73
|
-
type RequestBody = never;
|
|
74
|
-
type RequestHeaders = {};
|
|
75
|
-
type ResponseBody = void;
|
|
76
|
-
}
|
|
77
|
-
}
|
package/dist/api/ViewRoute.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/*
|
|
5
|
-
* ---------------------------------------------------------------
|
|
6
|
-
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
-
* ## ##
|
|
8
|
-
* ## AUTHOR: acacode ##
|
|
9
|
-
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
-
* ---------------------------------------------------------------
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { HttpClientConfig } from './httpClient';
|
|
2
|
-
import { Article } from './Article';
|
|
3
|
-
import { Auth } from './Auth';
|
|
4
|
-
import { Category } from './Category';
|
|
5
|
-
import { Comment } from './Comment';
|
|
6
|
-
import { File } from './File';
|
|
7
|
-
import { Knowledge } from './Knowledge';
|
|
8
|
-
import { Page } from './Page';
|
|
9
|
-
import { Search } from './Search';
|
|
10
|
-
import { Setting } from './Setting';
|
|
11
|
-
import { Smtp } from './Smtp';
|
|
12
|
-
import { Tag } from './Tag';
|
|
13
|
-
import { User } from './User';
|
|
14
|
-
import { View } from './View';
|
|
15
|
-
export interface ApiConfig<SecurityDataType = unknown> extends HttpClientConfig<SecurityDataType> {
|
|
16
|
-
}
|
|
17
|
-
export interface ApiInstance<SecurityDataType = unknown> {
|
|
18
|
-
article: Article<SecurityDataType>;
|
|
19
|
-
auth: Auth<SecurityDataType>;
|
|
20
|
-
category: Category<SecurityDataType>;
|
|
21
|
-
comment: Comment<SecurityDataType>;
|
|
22
|
-
file: File<SecurityDataType>;
|
|
23
|
-
knowledge: Knowledge<SecurityDataType>;
|
|
24
|
-
page: Page<SecurityDataType>;
|
|
25
|
-
search: Search<SecurityDataType>;
|
|
26
|
-
setting: Setting<SecurityDataType>;
|
|
27
|
-
smtp: Smtp<SecurityDataType>;
|
|
28
|
-
tag: Tag<SecurityDataType>;
|
|
29
|
-
user: User<SecurityDataType>;
|
|
30
|
-
view: View<SecurityDataType>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 创建 API 实例
|
|
34
|
-
* @param config API 配置
|
|
35
|
-
* @returns API 实例对象
|
|
36
|
-
*/
|
|
37
|
-
export declare function createApiInstance<SecurityDataType = unknown>(config?: ApiConfig<SecurityDataType>): ApiInstance<SecurityDataType>;
|
|
38
|
-
export declare const api: ApiInstance<unknown>;
|
|
39
|
-
export default api;
|
package/dist/api/api-instance.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// API 实例化文件
|
|
3
|
-
// 自动生成,请勿手动修改
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.api = exports.createApiInstance = void 0;
|
|
6
|
-
const httpClient_1 = require("./httpClient");
|
|
7
|
-
const Article_1 = require("./Article");
|
|
8
|
-
const Auth_1 = require("./Auth");
|
|
9
|
-
const Category_1 = require("./Category");
|
|
10
|
-
const Comment_1 = require("./Comment");
|
|
11
|
-
const File_1 = require("./File");
|
|
12
|
-
const Knowledge_1 = require("./Knowledge");
|
|
13
|
-
const Page_1 = require("./Page");
|
|
14
|
-
const Search_1 = require("./Search");
|
|
15
|
-
const Setting_1 = require("./Setting");
|
|
16
|
-
const Smtp_1 = require("./Smtp");
|
|
17
|
-
const Tag_1 = require("./Tag");
|
|
18
|
-
const User_1 = require("./User");
|
|
19
|
-
const View_1 = require("./View");
|
|
20
|
-
/**
|
|
21
|
-
* 创建 API 实例
|
|
22
|
-
* @param config API 配置
|
|
23
|
-
* @returns API 实例对象
|
|
24
|
-
*/
|
|
25
|
-
function createApiInstance(config = {}) {
|
|
26
|
-
const httpClient = new httpClient_1.HttpClient(config);
|
|
27
|
-
return {
|
|
28
|
-
article: new Article_1.Article(config),
|
|
29
|
-
auth: new Auth_1.Auth(config),
|
|
30
|
-
category: new Category_1.Category(config),
|
|
31
|
-
comment: new Comment_1.Comment(config),
|
|
32
|
-
file: new File_1.File(config),
|
|
33
|
-
knowledge: new Knowledge_1.Knowledge(config),
|
|
34
|
-
page: new Page_1.Page(config),
|
|
35
|
-
search: new Search_1.Search(config),
|
|
36
|
-
setting: new Setting_1.Setting(config),
|
|
37
|
-
smtp: new Smtp_1.Smtp(config),
|
|
38
|
-
tag: new Tag_1.Tag(config),
|
|
39
|
-
user: new User_1.User(config),
|
|
40
|
-
view: new View_1.View(config),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createApiInstance = createApiInstance;
|
|
44
|
-
// 默认 API 实例
|
|
45
|
-
exports.api = createApiInstance();
|
|
46
|
-
exports.default = exports.api;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
|
|
2
|
-
export declare type QueryParamsType = Record<string | number, any>;
|
|
3
|
-
export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
|
|
4
|
-
/** set parameter to `true` for call `securityWorker` for this request */
|
|
5
|
-
secure?: boolean;
|
|
6
|
-
/** request path */
|
|
7
|
-
path: string;
|
|
8
|
-
/** content type of request body */
|
|
9
|
-
type?: ContentType;
|
|
10
|
-
/** query params */
|
|
11
|
-
query?: QueryParamsType;
|
|
12
|
-
/** format of response (i.e. response.json() -> format: "json") */
|
|
13
|
-
format?: ResponseType;
|
|
14
|
-
/** request body */
|
|
15
|
-
body?: unknown;
|
|
16
|
-
}
|
|
17
|
-
export declare type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
|
|
18
|
-
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
|
|
19
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
20
|
-
secure?: boolean;
|
|
21
|
-
format?: ResponseType;
|
|
22
|
-
}
|
|
23
|
-
export declare enum ContentType {
|
|
24
|
-
Json = "application/json",
|
|
25
|
-
FormData = "multipart/form-data",
|
|
26
|
-
UrlEncoded = "application/x-www-form-urlencoded",
|
|
27
|
-
Text = "text/plain"
|
|
28
|
-
}
|
|
29
|
-
export declare class HttpClient<SecurityDataType = unknown> {
|
|
30
|
-
instance: AxiosInstance;
|
|
31
|
-
private securityData;
|
|
32
|
-
private securityWorker?;
|
|
33
|
-
private secure?;
|
|
34
|
-
private format?;
|
|
35
|
-
constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
|
|
36
|
-
setSecurityData: (data: SecurityDataType | null) => void;
|
|
37
|
-
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
|
|
38
|
-
protected stringifyFormItem(formItem: unknown): string;
|
|
39
|
-
protected createFormData(input: Record<string, unknown>): FormData;
|
|
40
|
-
request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any, {}>>;
|
|
41
|
-
}
|
package/dist/api/http-client.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/*
|
|
5
|
-
* ---------------------------------------------------------------
|
|
6
|
-
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
-
* ## ##
|
|
8
|
-
* ## AUTHOR: acacode ##
|
|
9
|
-
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
-
* ---------------------------------------------------------------
|
|
11
|
-
*/
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.HttpClient = exports.ContentType = void 0;
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
var ContentType;
|
|
19
|
-
(function (ContentType) {
|
|
20
|
-
ContentType["Json"] = "application/json";
|
|
21
|
-
ContentType["FormData"] = "multipart/form-data";
|
|
22
|
-
ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
|
|
23
|
-
ContentType["Text"] = "text/plain";
|
|
24
|
-
})(ContentType = exports.ContentType || (exports.ContentType = {}));
|
|
25
|
-
class HttpClient {
|
|
26
|
-
constructor({ securityWorker, secure, format, ...axiosConfig } = {}) {
|
|
27
|
-
this.securityData = null;
|
|
28
|
-
this.setSecurityData = (data) => {
|
|
29
|
-
this.securityData = data;
|
|
30
|
-
};
|
|
31
|
-
this.request = async ({ secure, path, type, query, format, body, ...params }) => {
|
|
32
|
-
const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
|
|
33
|
-
this.securityWorker &&
|
|
34
|
-
(await this.securityWorker(this.securityData))) ||
|
|
35
|
-
{};
|
|
36
|
-
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
37
|
-
const responseFormat = format || this.format || undefined;
|
|
38
|
-
if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
|
|
39
|
-
body = this.createFormData(body);
|
|
40
|
-
}
|
|
41
|
-
if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
|
|
42
|
-
body = JSON.stringify(body);
|
|
43
|
-
}
|
|
44
|
-
return this.instance.request({
|
|
45
|
-
...requestParams,
|
|
46
|
-
headers: {
|
|
47
|
-
...(requestParams.headers || {}),
|
|
48
|
-
...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
|
|
49
|
-
},
|
|
50
|
-
params: query,
|
|
51
|
-
responseType: responseFormat,
|
|
52
|
-
data: body,
|
|
53
|
-
url: path,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
this.instance = axios_1.default.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || 'http://localhost:3002' });
|
|
57
|
-
this.secure = secure;
|
|
58
|
-
this.format = format;
|
|
59
|
-
this.securityWorker = securityWorker;
|
|
60
|
-
}
|
|
61
|
-
mergeRequestParams(params1, params2) {
|
|
62
|
-
const method = params1.method || (params2 && params2.method);
|
|
63
|
-
return {
|
|
64
|
-
...this.instance.defaults,
|
|
65
|
-
...params1,
|
|
66
|
-
...(params2 || {}),
|
|
67
|
-
headers: {
|
|
68
|
-
...((method && this.instance.defaults.headers[method.toLowerCase()]) || {}),
|
|
69
|
-
...(params1.headers || {}),
|
|
70
|
-
...((params2 && params2.headers) || {}),
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
stringifyFormItem(formItem) {
|
|
75
|
-
if (typeof formItem === 'object' && formItem !== null) {
|
|
76
|
-
return JSON.stringify(formItem);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return `${formItem}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
createFormData(input) {
|
|
83
|
-
return Object.keys(input || {}).reduce((formData, key) => {
|
|
84
|
-
const property = input[key];
|
|
85
|
-
const propertyContent = property instanceof Array ? property : [property];
|
|
86
|
-
for (const formItem of propertyContent) {
|
|
87
|
-
const isFileType = formItem instanceof Blob || formItem instanceof File;
|
|
88
|
-
formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
|
|
89
|
-
}
|
|
90
|
-
return formData;
|
|
91
|
-
}, new FormData());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.HttpClient = HttpClient;
|
package/dist/api/httpClient.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
|
|
2
|
-
export declare type QueryParamsType = Record<string | number, any>;
|
|
3
|
-
export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
|
|
4
|
-
/** set parameter to `true` for call `securityWorker` for this request */
|
|
5
|
-
secure?: boolean;
|
|
6
|
-
/** request path */
|
|
7
|
-
path: string;
|
|
8
|
-
/** content type of request body */
|
|
9
|
-
type?: ContentType;
|
|
10
|
-
/** query params */
|
|
11
|
-
query?: QueryParamsType;
|
|
12
|
-
/** format of response (i.e. response.json() -> format: "json") */
|
|
13
|
-
format?: ResponseType;
|
|
14
|
-
/** request body */
|
|
15
|
-
body?: unknown;
|
|
16
|
-
}
|
|
17
|
-
export declare type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
|
|
18
|
-
export interface HttpClientConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
|
|
19
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
20
|
-
secure?: boolean;
|
|
21
|
-
format?: ResponseType;
|
|
22
|
-
}
|
|
23
|
-
export declare enum ContentType {
|
|
24
|
-
Json = "application/json",
|
|
25
|
-
FormData = "multipart/form-data",
|
|
26
|
-
UrlEncoded = "application/x-www-form-urlencoded",
|
|
27
|
-
Text = "text/plain"
|
|
28
|
-
}
|
|
29
|
-
export declare class HttpClient<SecurityDataType = unknown> {
|
|
30
|
-
instance: AxiosInstance;
|
|
31
|
-
private securityData;
|
|
32
|
-
securityWorker?: HttpClientConfig<SecurityDataType>['securityWorker'];
|
|
33
|
-
private secure?;
|
|
34
|
-
private format?;
|
|
35
|
-
constructor({ securityWorker, secure, format, ...axiosConfig }?: HttpClientConfig<SecurityDataType>);
|
|
36
|
-
setSecurityData: (data: SecurityDataType | null) => void;
|
|
37
|
-
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
|
|
38
|
-
protected stringifyFormItem(formItem: unknown): string;
|
|
39
|
-
protected createFormData(input: Record<string, unknown>): FormData;
|
|
40
|
-
request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any, {}>>;
|
|
41
|
-
}
|
|
42
|
-
export default HttpClient;
|
package/dist/api/httpClient.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/*
|
|
5
|
-
* ---------------------------------------------------------------
|
|
6
|
-
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
-
* ## ##
|
|
8
|
-
* ## AUTHOR: acacode ##
|
|
9
|
-
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
-
* ---------------------------------------------------------------
|
|
11
|
-
*/
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.HttpClient = exports.ContentType = void 0;
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
var ContentType;
|
|
19
|
-
(function (ContentType) {
|
|
20
|
-
ContentType["Json"] = "application/json";
|
|
21
|
-
ContentType["FormData"] = "multipart/form-data";
|
|
22
|
-
ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
|
|
23
|
-
ContentType["Text"] = "text/plain";
|
|
24
|
-
})(ContentType = exports.ContentType || (exports.ContentType = {}));
|
|
25
|
-
class HttpClient {
|
|
26
|
-
constructor({ securityWorker, secure, format, ...axiosConfig } = {}) {
|
|
27
|
-
this.securityData = null;
|
|
28
|
-
this.setSecurityData = (data) => {
|
|
29
|
-
this.securityData = data;
|
|
30
|
-
};
|
|
31
|
-
this.request = async ({ secure, path, type, query, format, body, ...params }) => {
|
|
32
|
-
const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
|
|
33
|
-
this.securityWorker &&
|
|
34
|
-
(await this.securityWorker(this.securityData))) ||
|
|
35
|
-
{};
|
|
36
|
-
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
37
|
-
const responseFormat = format || this.format || undefined;
|
|
38
|
-
if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
|
|
39
|
-
body = this.createFormData(body);
|
|
40
|
-
}
|
|
41
|
-
if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
|
|
42
|
-
body = JSON.stringify(body);
|
|
43
|
-
}
|
|
44
|
-
return this.instance.request({
|
|
45
|
-
...requestParams,
|
|
46
|
-
headers: {
|
|
47
|
-
...(requestParams.headers || {}),
|
|
48
|
-
...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
|
|
49
|
-
},
|
|
50
|
-
params: query,
|
|
51
|
-
responseType: responseFormat,
|
|
52
|
-
data: body,
|
|
53
|
-
url: path,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
this.instance = axios_1.default.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || 'http://localhost:3002' });
|
|
57
|
-
this.secure = secure;
|
|
58
|
-
this.format = format;
|
|
59
|
-
this.securityWorker = securityWorker;
|
|
60
|
-
}
|
|
61
|
-
mergeRequestParams(params1, params2) {
|
|
62
|
-
const method = params1.method || (params2 && params2.method);
|
|
63
|
-
return {
|
|
64
|
-
...this.instance.defaults,
|
|
65
|
-
...params1,
|
|
66
|
-
...(params2 || {}),
|
|
67
|
-
headers: {
|
|
68
|
-
...((method && this.instance.defaults.headers[method.toLowerCase()]) || {}),
|
|
69
|
-
...(params1.headers || {}),
|
|
70
|
-
...((params2 && params2.headers) || {}),
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
stringifyFormItem(formItem) {
|
|
75
|
-
if (typeof formItem === 'object' && formItem !== null) {
|
|
76
|
-
return JSON.stringify(formItem);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return `${formItem}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
createFormData(input) {
|
|
83
|
-
return Object.keys(input || {}).reduce((formData, key) => {
|
|
84
|
-
const property = input[key];
|
|
85
|
-
const propertyContent = property instanceof Array ? property : [property];
|
|
86
|
-
for (const formItem of propertyContent) {
|
|
87
|
-
const isFileType = formItem instanceof Blob || formItem instanceof File;
|
|
88
|
-
formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
|
|
89
|
-
}
|
|
90
|
-
return formData;
|
|
91
|
-
}, new FormData());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.HttpClient = HttpClient;
|
|
95
|
-
exports.default = HttpClient;
|