├── .changeset ├── README.md └── config.json ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github ├── auto_assign.yml └── workflows │ └── node.js.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierrc.js ├── .vscode ├── extensions.json └── settings.json ├── LICENSE ├── OWNERS ├── README.md ├── README_en.md ├── babel.config.js ├── netlify.toml ├── package.json ├── packages ├── admin-api │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── babel.config.js │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── AdminApiClient.ts │ │ ├── AuthorizedClient.ts │ │ ├── __tests__ │ │ │ └── AuthorizedClient.test.ts │ │ ├── clients │ │ │ ├── ActuatorClient.ts │ │ │ ├── AttachmentClient.ts │ │ │ ├── BackupClient.ts │ │ │ ├── CategoryClient.ts │ │ │ ├── CommentClient.ts │ │ │ ├── InstallationClient.ts │ │ │ ├── JournalClient.ts │ │ │ ├── JournalCommentClient.ts │ │ │ ├── LinkClient.ts │ │ │ ├── LogClient.ts │ │ │ ├── MailClient.ts │ │ │ ├── MenuClient.ts │ │ │ ├── MigrationClient.ts │ │ │ ├── OptionClient.ts │ │ │ ├── PhotoClient.ts │ │ │ ├── PostClient.ts │ │ │ ├── PostCommentClient.ts │ │ │ ├── SheetClient.ts │ │ │ ├── SheetCommentClient.ts │ │ │ ├── StaticStorageClient.ts │ │ │ ├── StatisticClient.ts │ │ │ ├── TagClient.ts │ │ │ ├── ThemeClient.ts │ │ │ ├── UserClient.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── types │ │ │ └── index.ts │ │ └── url.ts │ └── tsconfig.json ├── content-api │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── babel.config.js │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── ContentApiClient.ts │ │ ├── clients │ │ │ ├── ArchiveClient.ts │ │ │ ├── CategoryClient.ts │ │ │ ├── CommentClient.ts │ │ │ ├── JournalClient.ts │ │ │ ├── LinkClient.ts │ │ │ ├── MenuClient.ts │ │ │ ├── OptionClient.ts │ │ │ ├── PhotoClient.ts │ │ │ ├── PostClient.ts │ │ │ ├── SheetClient.ts │ │ │ ├── StatisticClient.ts │ │ │ ├── TagClient.ts │ │ │ ├── ThemeClient.ts │ │ │ ├── UserClient.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── types │ │ │ └── index.ts │ │ └── url.ts │ └── tsconfig.json ├── logger │ ├── .gitignore │ ├── CHANGELOG.md │ ├── babel.config.js │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── __tests__ │ │ │ ├── debug.test.ts │ │ │ ├── logger.test.ts │ │ │ └── setup.ts │ │ ├── index.browser.ts │ │ ├── index.ts │ │ ├── logger │ │ │ ├── debug.ts │ │ │ └── index.ts │ │ ├── platform │ │ │ ├── browser.ts │ │ │ ├── index.ts │ │ │ └── node.ts │ │ └── types │ │ │ └── index.ts │ └── tsconfig.json ├── markdown-renderer │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── markdown.ts │ │ └── mermaid │ │ │ ├── index.js │ │ │ ├── index.license │ │ │ ├── murmurhash3_gc.js │ │ │ └── murmurhash3_gc.license │ ├── tsconfig.json │ └── vite.config.ts ├── rest-api-client │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── babel.config.js │ ├── index.mjs │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── HaloRequestConfigBuilder.ts │ │ ├── HaloResponseHandler.ts │ │ ├── HaloRestAPIClient.ts │ │ ├── __tests__ │ │ │ ├── HaloRequestConfigBuilder.test.ts │ │ │ ├── HaloResponseHandler.test.ts │ │ │ └── setup.ts │ │ ├── error │ │ │ └── HaloRestAPIError.ts │ │ ├── http │ │ │ ├── AxiosClient.ts │ │ │ ├── InterceptorManager.ts │ │ │ ├── MockClient.ts │ │ │ └── index.ts │ │ ├── index.browser.ts │ │ ├── index.ts │ │ ├── logger.ts │ │ ├── platform │ │ │ ├── UnsupportedPlatformError.ts │ │ │ ├── browser.ts │ │ │ ├── index.ts │ │ │ └── node.ts │ │ └── types │ │ │ ├── CredentialsInterface.ts │ │ │ ├── HttpClientInterface.ts │ │ │ ├── auth.ts │ │ │ └── index.ts │ ├── tsconfig.json │ └── types │ │ └── global │ │ └── index.d.ts └── tracker │ ├── index.js │ ├── package.json │ ├── public │ └── halo-tracker.js │ └── rollup.tracker.config.js ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── tsconfig.base.json └── tsconfig.json /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "linked": [["@halo-dev/*"]], 6 | "access": "public", 7 | "baseBranch": "master", 8 | "updateInternalDependencies": "patch", 9 | "ignore": [] 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = false 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | **/lib/* 2 | **/node_modules/* 3 | example 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], 5 | env: { 6 | browser: true, 7 | node: true, 8 | }, 9 | rules: { 10 | '@typescript-eslint/no-explicit-any': ['off'], 11 | '@typescript-eslint/no-non-null-assertion': 'off', 12 | '@typescript-eslint/ban-ts-comment': 'off', 13 | }, 14 | } 15 | -------------------------------------------------------------------------------- /.github/auto_assign.yml: -------------------------------------------------------------------------------- 1 | # Set to true to add reviewers to pull requests 2 | addReviewers: true 3 | 4 | # Set to true to add assignees to pull requests 5 | addAssignees: true 6 | 7 | # A list of reviewers to be added to pull requests (GitHub user name) 8 | reviewers: 9 | - ruibaby 10 | - JohnNiang 11 | - guqing 12 | - LIlGG 13 | 14 | # A list of keywords to be skipped the process that add reviewers if pull requests include it 15 | skipKeywords: 16 | - wip 17 | 18 | # A number of reviewers added to the pull request 19 | # Set 0 to add all the reviewers (default: 0) 20 | numberOfReviewers: 0 21 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [master] 9 | pull_request: 10 | branches: [master] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [14.x, 16.x] 19 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Install pnpm 25 | uses: pnpm/action-setup@v2.0.1 26 | with: 27 | version: 7.1.6 28 | 29 | - name: Use Node.js ${{ matrix.node-version }} 30 | uses: actions/setup-node@v2 31 | with: 32 | node-version: ${{ matrix.node-version }} 33 | cache: 'pnpm' 34 | 35 | - run: pnpm install 36 | - run: pnpm lint 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node template 2 | dist/ 3 | tsconfig.tsbuildinfo 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | .tsbuildinfo 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # nyc test coverage 25 | .nyc_output 26 | 27 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 28 | .grunt 29 | 30 | # Bower dependency directory (https://bower.io/) 31 | bower_components 32 | 33 | # node-waf configuration 34 | .lock-wscript 35 | 36 | # Compiled binary addons (https://nodejs.org/api/addons.html) 37 | build/Release 38 | 39 | # Dependency directories 40 | node_modules/ 41 | jspm_packages/ 42 | 43 | # Typescript v1 declaration files 44 | typings/ 45 | 46 | # Optional npm cache directory 47 | .npm 48 | 49 | # Optional eslint cache 50 | .eslintcache 51 | 52 | # Optional REPL history 53 | .node_repl_history 54 | 55 | # Output of 'npm pack' 56 | *.tgz 57 | 58 | # Yarn Integrity file 59 | .yarn-integrity 60 | 61 | # IDE 62 | .idea/* 63 | *.iml 64 | *.sublime-* 65 | 66 | # OSX 67 | .DS_Store 68 | 69 | docs 70 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | pnpm lint --fix 5 | 6 | git add . 7 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 120, 3 | semi: false, 4 | trailingComma: 'all', 5 | singleQuote: true, 6 | }; 7 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "oderwat.indent-rainbow", 4 | "esbenp.prettier-vscode", 5 | "editorconfig.editorconfig", 6 | "VisualStudioExptTeam.vscodeintellicode" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.quickSuggestions": { 3 | "strings": true 4 | }, 5 | "[javascript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "vetur.format.defaultFormatter.html": "js-beautify-html", 9 | "vetur.format.defaultFormatterOptions": { 10 | "js-beautify-html": { 11 | "wrap_attributes": "force-expand-multiline" 12 | }, 13 | "prettyhtml": { 14 | "printWidth": 100, 15 | "singleQuote": false, 16 | "wrapAttributes": false, 17 | "sortAttributes": false 18 | } 19 | }, 20 | "[vue]": { 21 | "editor.defaultFormatter": "esbenp.prettier-vscode" 22 | }, 23 | "[json]": { 24 | "editor.defaultFormatter": "esbenp.prettier-vscode" 25 | }, 26 | "[jsonc]": { 27 | "editor.defaultFormatter": "esbenp.prettier-vscode" 28 | }, 29 | "[typescript]": { 30 | "editor.defaultFormatter": "esbenp.prettier-vscode" 31 | }, 32 | "editor.suggestSelection": "first", 33 | "[html]": { 34 | "editor.defaultFormatter": "esbenp.prettier-vscode" 35 | }, 36 | "editor.formatOnSave": true, 37 | "[javascriptreact]": { 38 | "editor.defaultFormatter": "esbenp.prettier-vscode" 39 | }, 40 | "[typescriptreact]": { 41 | "editor.defaultFormatter": "esbenp.prettier-vscode" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Halo Dev 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. 22 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | reviewers: 2 | - ruibaby 3 | - guqing 4 | - JohnNiang 5 | - lan-yonghui 6 | - wangzhen-fit2cloud 7 | 8 | approvers: 9 | - ruibaby 10 | - guqing 11 | - JohnNiang 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Halo logo 4 | 5 |

6 |

Halo SDK

7 | 8 |

9 | 10 | Project Build 11 | 12 | 13 | npm 14 | 15 | 16 | npm 17 | 18 | 19 | npm version 20 | 21 |

22 |

一个与 Halo api 交互的工具集

23 | 24 | [English Document](./README_en.md) 25 | 26 | ## 特性 27 | 28 | - 封装认证以简化开发. 29 | - 异常处理 30 | - 使用 Halo rest api 更方便 31 | - 使用 `TypeScript` 编写,更明确的参数和返回值类型,更好的代码提示 32 | 33 | ## 管理后台 API 库 34 | 35 | ### 安装 36 | 37 | 使用 `npm` 方式安装示例如下: 38 | 39 | ```shell 40 | npm install @halo-dev/admin-api --save 41 | ``` 42 | 43 | ### 使用示例 44 | 45 | 以下是一个获取后台文章列表的简单示例: 46 | 47 | ```javascript 48 | import { AdminApiClient, HaloRestAPIClient } from "@halo-dev/admin-api"; 49 | //halo http 请求客户端. 50 | const haloRestApiClient = new HaloRestAPIClient({ 51 | baseUrl: process.env.HALO_BASE_URL, 52 | auth: { adminToken: "halo admin token" }, 53 | }); 54 | // 通过 haloRestApiCLient 创建 adminApiClient。 55 | const haloAdminClient = new AdminApiClient(haloRestApiClient); 56 | // 获取文章列表 57 | haloAdminClient.post.list().then((res) => { 58 | console.log(res); 59 | }); 60 | ``` 61 | 62 | 关于如何通过用户名和密码进行自动认证,这里提供了一个示例 [example](https://github.com/halo-dev/js-sdk/tree/master/example) 63 | 64 | 由于 `@halo-dev/admin-api` 依赖 `@halo-dev/rest-api-client`,而其是基于 `axios` 进行 `http` 通信的,因此如果你有需要的话,可以使用 [axios](https://axios-http.com/docs/intro), 的拦截器对 `halo api` 的请求与响应进行一些处理。 65 | 66 | ```javascript 67 | import axios from "axios"; 68 | 69 | // Add a request interceptor 70 | axios.interceptors.request.use( 71 | function (config) { 72 | // Do something before request is sent 73 | return config; 74 | }, 75 | function (error) { 76 | // Do something with request error 77 | return Promise.reject(error); 78 | } 79 | ); 80 | 81 | // Add a response interceptor 82 | axios.interceptors.response.use( 83 | function (response) { 84 | // Any status code that lie within the range of 2xx cause this function to trigger 85 | // Do something with response data 86 | return response; 87 | }, 88 | function (error) { 89 | // Any status codes that falls outside the range of 2xx cause this function to trigger 90 | // Do something with response error 91 | return Promise.reject(error); 92 | } 93 | ); 94 | ``` 95 | 96 | `@halo-dev/content-api` 也可以这样使用拦截器。 97 | 98 | ## 前台 API 库 99 | 100 | 使用 `npm` 安装示例如下: 101 | 102 | ```shell 103 | npm install @halo-dev/content-api --save 104 | ``` 105 | 106 | ### 使用示例 107 | 108 | 同样我们使用一个获取博客前台文章列表的示例如下: 109 | 110 | ```javascript 111 | import { ContentApiClient, HaloRestAPIClient } from "@halo-dev/content-api"; 112 | // 创建 halo http 请求客户端 113 | const haloRestApiClient = new HaloRestAPIClient({ 114 | baseUrl: process.env.HALO_BASE_URL, 115 | auth: { apiToken: process.env.HALO_API_TOKEN }, 116 | }); 117 | // 通过 http 客户端创建 halo 前台 api 客户端 118 | const haloContentClient = new ContentApiClient(haloRestApiClient); 119 | // 获取文章列表 120 | haloContentClient.post.list().then((res) => { 121 | console.log(res); 122 | }); 123 | ``` 124 | 125 | ## Halo Rest API Http 通信库 126 | 127 | ### 安装 128 | 129 | 你可以使用 `npm` 安装它,示例如下: 130 | 131 | ```shell 132 | npm install @halo-dev/rest-api-client 133 | ``` 134 | 135 | 使用 `require` 或 `import` 导入 136 | 137 | ```javascript 138 | // CommonJS 139 | const { HaloRestAPIClient } = require("@halo-dev/rest-api-client"); 140 | // ES modules 141 | import { HaloRestAPIClient } from "@halo-dev/rest-api-client"; 142 | ``` 143 | 144 | ### 使用示例 145 | 146 | ```javascript 147 | const client = new HaloRestAPIClient({ 148 | baseUrl: "https://example.halo.run", 149 | // Use password authentication 150 | auth: { 151 | username: process.env.HALO_USERNAME, 152 | password: process.env.HALO_PASSWORD, 153 | }, 154 | }); 155 | ``` 156 | 157 | `auth` 参数为认证方式,支持以下几种认证方式,示例如下: 158 | 159 | 1. 使用 API token 认证,它适用于 halo 博客前台 api 认证 160 | 161 | ```javascript 162 | auth: { 163 | apiToken: process.env.HALO_API_TOKEN; 164 | } 165 | ``` 166 | 167 | 2. 使用 Admin token 认证,它适用于 halo 后台管理 api 认证 168 | 169 | ```javascript 170 | auth: { 171 | adminToken: process.env.HALO_ADMIN_TOKEN; 172 | } 173 | ``` 174 | 175 | 3. 使用自定义请求头认证方式 176 | 177 | ```javascript 178 | auth: { 179 | type: "customizeAuth", 180 | authHeader: "Admin-Authorization", 181 | getToken () { 182 | return localStorage.getItem ("Access_Token") 183 | } 184 | } 185 | ``` 186 | 187 | 4. 使用 OAuth2 Bearer token 的认证方式,最终会在请求头添加 `Authorization: bearer some-token` 188 | 189 | ```javascript 190 | auth: { 191 | oAuthToken: process.env.HALO_OAUTH_TOKEN; 192 | } 193 | ``` 194 | 195 | **Basic 认证** 196 | 197 | 会在请求头添加例如 `Authorization: Basic dXNlci1jbGllbi1zZWNyZXQtODg4OA==` 这样的 pair 198 | 199 | ```javascript 200 | const client = new HaloRestAPIClient({ 201 | baseUrl: "https://example.halo.run", 202 | // Use basic authentication 203 | basicAuth: { username: "user", password: "password" }, 204 | }); 205 | ``` 206 | 207 | 另外还支持通过提供一个 `TokenProvider` 来接管 `halo` 的认证,这样不需要在考虑如何实现登录和 `token` 过期怎么续期的逻辑,示例如下: 208 | 209 | ```javascript 210 | import { 211 | HaloRestAPIClient, 212 | LocalStorageTokenStore, 213 | // FileTokenStore, 214 | // TokenStore, 215 | DefaultTokenProvider, 216 | } from "@halo-dev/rest-clint-api"; 217 | 218 | // Use LocalStorageTokenStore to persistence AccessToken to localStorage (in browser only) 219 | //you can use FileTokenStore if in the Node environment. 220 | // If there is no suitable Token store implemention, you can implement your own token storage strategy through the TokenStore interface. 221 | const localStorageTokenStore = new LocalStorageTokenStore(); 222 | 223 | //halo api base url. 224 | const baseUrl = process.env.VUE_APP_BASE_URL; 225 | 226 | const haloRestApiClient = new HaloRestAPIClient({ 227 | baseUrl: baseUrl, 228 | }); 229 | 230 | const buildTokenProvider = (credentials) => { 231 | return new DefaultTokenProvider( 232 | { 233 | ...credentials, 234 | }, 235 | baseUrl, 236 | localStorageTokenStore 237 | ); 238 | }; 239 | 240 | const tokenProvider = buildTokenProvider({ 241 | username: "your halo username", 242 | password: "your password", 243 | }); 244 | haloRestApiClient.setTokenProvider(tokenProvider); 245 | //now you can use haloRestApiClient to build your api client 246 | ``` 247 | 248 | 完整的例子可以点 [这里](https://github.com/halo-dev/js-sdk/tree/master/example) 249 | 250 | ### 发送 Http 请求 251 | 252 | ```javascript 253 | const haloRestApiClient = new HaloRestAPIClient({ 254 | baseUrl: "https://example.halo.run", 255 | basicAuth: { username: "user", password: "password" }, 256 | }); 257 | //build http client to perform http request 258 | const client = haloRestApiClient.buildHttpClient(); 259 | 260 | //api parameters 261 | const parameters = {}; 262 | //http get 263 | client.get("https://example.halo.run", parameters); 264 | //http post 265 | client.post("https://example.halo.run", parameters); 266 | ``` 267 | 268 | ## Logger 日志库 269 | 270 | ### 安装 271 | 272 | 使用 `npm` 安装示例如下: 273 | 274 | ```shell 275 | npm install @halo-dev/logger --save 276 | ``` 277 | 278 | ### 主要概念 279 | 280 | `@halo-dev/logger` 包支持按从最详细到最不详细的顺序指定的以下日志级别: 281 | 282 | - debug 283 | - info 284 | - warning 285 | - error 286 | 287 | 当以编程方式或通过 `HALO_LOG_LEVEL` 环境变量设置日志级别时,使用小于或等于您选择的日志级别时写入的任何日志都将被显示。 288 | 289 | 例如,将日志级别设置为 `warning` 将导致所有日志级别为 `warning` 或 `error` 的日志被显示。 290 | 291 | ### 使用示例 292 | 293 | #### 示例 1 - 基本使用 294 | 295 | ```javascript 296 | import * as Logger from "@halo-dev/logger"; 297 | Logger.setLogLevel ("info"); 298 | 299 | //operations will now emit info, warning, and error logs 300 | 301 | //create a namespaced logger 302 | const logger = Logger.createClientLogger ("posts"); 303 | const client = new AdminApiClient (/* params */); 304 | client.post.list () 305 | .then (res => { 306 | /* write an info log */ 307 | logger.info ("Successfully acquired a list of articles", res); 308 | }) 309 | .catch (e => { /* do work */ }); 310 | }); 311 | ``` 312 | 313 | #### 示例 2 - 覆盖原先日志输出方式 314 | 315 | ```javascript 316 | import { HaloLogger, setLogLevel } from "@halo-dev/logger"; 317 | 318 | setLogLevel("warning"); 319 | 320 | //override logging to output to console.log (default location is stderr) 321 | HaloLogger.log = (...args) => { 322 | console.log(...args); 323 | }; 324 | HaloLogger.log("hello world!"); 325 | ``` 326 | 327 | ## License 328 | 329 | [MIT license](./LICENSE) 330 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/env', '@babel/typescript'], 3 | } 4 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build.environment] 2 | NODE_VERSION = "14" 3 | NPM_FLAGS = "--version" 4 | 5 | [build] 6 | publish = "docs" 7 | command = "npx pnpm install --store=node_modules/.pnpm-store && npx pnpm build && npx pnpm build:docs" 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@halo-dev/js-sdk", 3 | "version": "0.0.0", 4 | "description": "Packages for Halo JavaScript SDK.", 5 | "private": true, 6 | "scripts": { 7 | "test": "pnpm --filter './packages/**' run test", 8 | "dev": "pnpm --filter './packages/**' run dev --parallel", 9 | "build": "pnpm --filter './packages/**' run build", 10 | "build:docs": "typedoc --excludeExternals --readme README.md --entryPoints packages/admin-api/src packages/content-api/src packages/logger/src packages/rest-api-client/src", 11 | "lint": "eslint .", 12 | "cleanup": "rimraf node_modules docs packages/**/lib packages/**/node_modules", 13 | "changeset": "changeset", 14 | "release": "changeset publish" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/halo-dev/js-sdk.git" 19 | }, 20 | "keywords": [ 21 | "halo", 22 | "halo-sdk" 23 | ], 24 | "maintainers": [ 25 | { 26 | "name": "guqing", 27 | "email": "1484563614@qq.com", 28 | "url": "https://github.com/guqing" 29 | }, 30 | { 31 | "name": "ryanwang", 32 | "email": "i@ryanc.cc", 33 | "url": "https://github.com/ruibaby" 34 | } 35 | ], 36 | "author": "@halo-dev", 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/halo-dev/js-sdk/issues" 40 | }, 41 | "homepage": "https://github.com/halo-dev/js-sdk#readme", 42 | "workspaces": [ 43 | "packages/*" 44 | ], 45 | "devDependencies": { 46 | "@babel/core": "^7.18.2", 47 | "@babel/preset-env": "^7.18.2", 48 | "@babel/preset-typescript": "^7.17.12", 49 | "@changesets/cli": "^2.22.0", 50 | "@types/jest": "^26.0.24", 51 | "@types/node": "^17.0.35", 52 | "@typescript-eslint/eslint-plugin": "^5.26.0", 53 | "@typescript-eslint/parser": "^5.26.0", 54 | "eslint": "^8.16.0", 55 | "eslint-config-prettier": "^8.5.0", 56 | "eslint-plugin-prettier": "^4.0.0", 57 | "husky": "^7.0.4", 58 | "jest": "^26.6.3", 59 | "lint-staged": "^12.4.2", 60 | "prettier": "^2.6.2", 61 | "rimraf": "^3.0.2", 62 | "ts-jest": "^26.5.6", 63 | "typedoc": "^0.22.15", 64 | "typedoc-plugin-missing-exports": "^0.22.6", 65 | "typescript": "^4.7.2" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/admin-api/.gitignore: -------------------------------------------------------------------------------- 1 | tsconfig.tsbuildinfo 2 | lib 3 | pnpm-workspace.yaml 4 | -------------------------------------------------------------------------------- /packages/admin-api/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @halo-dev/admin-api 2 | 3 | ## 1.1.0 4 | 5 | ### Minor Changes 6 | 7 | - - add an API of updating links in batch #40 @gungnir479 8 | 9 | ### Patch Changes 10 | 11 | - Updated dependencies 12 | - @halo-dev/rest-api-client@1.1.0 13 | 14 | ## 1.0.0 15 | 16 | ### Patch Changes 17 | 18 | - @halo-dev/rest-api-client@1.0.0 19 | -------------------------------------------------------------------------------- /packages/admin-api/README.md: -------------------------------------------------------------------------------- 1 |

Admin API Client

2 | 3 |

4 | 5 | npm version 6 | 7 | 8 | npm 9 | 10 | 11 | node-current 12 | 13 | 14 | NPM 15 | 16 |

17 | 18 |

JavaScript SDK for Halo's Admin API,implemented with TypeScript,encapsulating parameter types and return value types to make the use of API more brief.

19 | 20 | ## Installation 21 | 22 | ```shell 23 | npm install @halo-dev/admin-api --save 24 | ``` 25 | 26 | ## Usage 27 | 28 | Here is a simple code for obtaining a list of posts. 29 | 30 | ```javascript 31 | import { AdminApiClient, HaloRestAPIClient } from '@halo-dev/admin-api' 32 | 33 | // http request tool for halo rest api. 34 | const haloRestApiClient = new HaloRestAPIClient({ 35 | baseUrl: process.env.HALO_BASE_URL, 36 | }) 37 | 38 | // create adminApiClient by haloRestApiCLient. 39 | const haloAdminClient = new AdminApiClient(haloRestApiClient) 40 | 41 | // obtaining a list of articles. 42 | haloAdminClient.post.list().then((res) => { 43 | console.log(res) 44 | }) 45 | ``` 46 | 47 | You can also view the complete implementation of the halo-admin project: [@halo-dev/halo-admin](https://github.com/halo-dev/halo-admin). 48 | 49 | ### License 50 | 51 | [MIT license](../../LICENSE) 52 | -------------------------------------------------------------------------------- /packages/admin-api/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'], 3 | } 4 | -------------------------------------------------------------------------------- /packages/admin-api/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | clearMocks: true, 4 | rootDir: 'src', 5 | testPathIgnorePatterns: ['node_modules', '/__tests__/setup.ts'], 6 | testEnvironment: 'node', 7 | } 8 | -------------------------------------------------------------------------------- /packages/admin-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@halo-dev/admin-api", 3 | "version": "1.1.0", 4 | "description": "Halo admin api client.", 5 | "main": "lib/index.js", 6 | "module": "./lib/index.js", 7 | "types": "lib/index.d.ts", 8 | "engines": { 9 | "node": ">=12" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "private": false, 15 | "scripts": { 16 | "dev": "tsc --build --force --watch", 17 | "build": "tsc --build --force", 18 | "test": "jest --rootDir src" 19 | }, 20 | "files": [ 21 | "lib" 22 | ], 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/halo-dev/js-sdk.git", 26 | "directory": "packages/admin-api" 27 | }, 28 | "keywords": [ 29 | "halo", 30 | "halo-sdk", 31 | "halo-admin", 32 | "halo-admin-api" 33 | ], 34 | "maintainers": [ 35 | { 36 | "name": "guqing", 37 | "email": "1484563614@qq.com", 38 | "url": "https://github.com/guqing" 39 | }, 40 | { 41 | "name": "ryanwang", 42 | "email": "i@ryanc.cc", 43 | "url": "https://github.com/ruibaby" 44 | } 45 | ], 46 | "author": "@halo-dev", 47 | "license": "MIT", 48 | "bugs": { 49 | "url": "https://github.com/halo-dev/js-sdk/issues" 50 | }, 51 | "homepage": "https://github.com/halo-dev/js-sdk/tree/master/packages/admin-api#readme", 52 | "dependencies": { 53 | "@halo-dev/rest-api-client": "workspace:*", 54 | "tslib": "^2.4.0" 55 | }, 56 | "exports": { 57 | ".": { 58 | "import": "./lib/index.js", 59 | "require": "./lib/index.js" 60 | }, 61 | "./package.json": "./package.json" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/admin-api/src/AdminApiClient.ts: -------------------------------------------------------------------------------- 1 | import { HaloRestAPIClient, HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from './url' 3 | import { AccessToken, Environment, LoginPreCheck, Response } from './types' 4 | import { 5 | ActuatorClient, 6 | AttachmentClient, 7 | BackupClient, 8 | CategoryClient, 9 | CommentClient, 10 | InstallationClient, 11 | JournalClient, 12 | JournalCommentClient, 13 | LinkClient, 14 | LogClient, 15 | MailClient, 16 | MenuClient, 17 | MigrationClient, 18 | OptionClient, 19 | PhotoClient, 20 | PostClient, 21 | PostCommentClient, 22 | SheetClient, 23 | SheetCommentClient, 24 | StaticStorageClient, 25 | StatisticClient, 26 | TagClient, 27 | ThemeClient, 28 | UserClient, 29 | } from './clients' 30 | 31 | export class AdminApiClient { 32 | private readonly client: HttpClient 33 | private readonly _attachment: AttachmentClient 34 | private readonly _backup: BackupClient 35 | private readonly _category: CategoryClient 36 | private readonly _installation: InstallationClient 37 | private readonly _journalComment: JournalCommentClient 38 | private readonly _journal: JournalClient 39 | private readonly _link: LinkClient 40 | private readonly _log: LogClient 41 | private readonly _mail: MailClient 42 | private readonly _menu: MenuClient 43 | private readonly _migration: MigrationClient 44 | private readonly _option: OptionClient 45 | private readonly _photo: PhotoClient 46 | private readonly _postComment: PostCommentClient 47 | private readonly _post: PostClient 48 | private readonly _sheetComment: SheetCommentClient 49 | private readonly _sheet: SheetClient 50 | private readonly _statistic: StatisticClient 51 | private readonly _tag: TagClient 52 | private readonly _theme: ThemeClient 53 | private readonly _user: UserClient 54 | private readonly _staticStorage: StaticStorageClient 55 | private readonly _comment: CommentClient 56 | private readonly _actuator: ActuatorClient 57 | 58 | constructor(client: HaloRestAPIClient) { 59 | this.client = client.buildHttpClient() 60 | this._attachment = new AttachmentClient(this.client) 61 | this._backup = new BackupClient(this.client) 62 | this._category = new CategoryClient(this.client) 63 | this._installation = new InstallationClient(this.client) 64 | this._journalComment = new JournalCommentClient(this.client) 65 | this._journal = new JournalClient(this.client) 66 | this._link = new LinkClient(this.client) 67 | this._log = new LogClient(this.client) 68 | this._mail = new MailClient(this.client) 69 | this._menu = new MenuClient(this.client) 70 | this._migration = new MigrationClient(this.client) 71 | this._option = new OptionClient(this.client) 72 | this._photo = new PhotoClient(this.client) 73 | this._postComment = new PostCommentClient(this.client) 74 | this._post = new PostClient(this.client) 75 | this._sheetComment = new SheetCommentClient(this.client) 76 | this._sheet = new SheetClient(this.client) 77 | this._statistic = new StatisticClient(this.client) 78 | this._tag = new TagClient(this.client) 79 | this._theme = new ThemeClient(this.client) 80 | this._user = new UserClient(this.client) 81 | this._staticStorage = new StaticStorageClient(this.client) 82 | this._comment = new CommentClient(this.client) 83 | this._actuator = new ActuatorClient(this.client) 84 | } 85 | 86 | public get attachment() { 87 | return this._attachment 88 | } 89 | 90 | public get backup() { 91 | return this._backup 92 | } 93 | 94 | public get category() { 95 | return this._category 96 | } 97 | 98 | public get installation() { 99 | return this._installation 100 | } 101 | 102 | public get journalComment() { 103 | return this._journalComment 104 | } 105 | 106 | public get journal() { 107 | return this._journal 108 | } 109 | 110 | public get link() { 111 | return this._link 112 | } 113 | 114 | public get log() { 115 | return this._log 116 | } 117 | 118 | public get mail() { 119 | return this._mail 120 | } 121 | 122 | public get menu() { 123 | return this._menu 124 | } 125 | 126 | public get migration() { 127 | return this._migration 128 | } 129 | 130 | public get option() { 131 | return this._option 132 | } 133 | 134 | public get photo() { 135 | return this._photo 136 | } 137 | 138 | public get postComment() { 139 | return this._postComment 140 | } 141 | 142 | public get post() { 143 | return this._post 144 | } 145 | 146 | public get sheetComment() { 147 | return this._sheetComment 148 | } 149 | 150 | public get sheet() { 151 | return this._sheet 152 | } 153 | 154 | public get statistic() { 155 | return this._statistic 156 | } 157 | 158 | public get tag() { 159 | return this._tag 160 | } 161 | 162 | public get theme() { 163 | return this._theme 164 | } 165 | 166 | public get user() { 167 | return this._user 168 | } 169 | 170 | public get staticStorage() { 171 | return this._staticStorage 172 | } 173 | 174 | public get comment() { 175 | return this._comment 176 | } 177 | 178 | public get actuator() { 179 | return this._actuator 180 | } 181 | 182 | public getEnvironment(): Promise> { 183 | const path = buildPath({ 184 | endpointName: 'environments', 185 | }) 186 | return this.client.get(path, {}) 187 | } 188 | 189 | public getLogFile(lines: number): Promise> { 190 | const path = buildPath({ 191 | endpointName: 'halo/logfile', 192 | }) 193 | return this.client.get(path, { lines }) 194 | } 195 | 196 | public isInstalled(): Promise> { 197 | const path = buildPath({ 198 | endpointName: 'is_installed', 199 | }) 200 | return this.client.get(path, {}) 201 | } 202 | 203 | public logout(): Promise> { 204 | const path = buildPath({ 205 | endpointName: 'logout', 206 | }) 207 | return this.client.post(path, {}) 208 | } 209 | 210 | public sendResetPasswordCode(params: { 211 | username: string 212 | email: string 213 | code?: string 214 | password?: string 215 | }): Promise { 216 | const path = buildPath({ 217 | endpointName: 'password/code', 218 | }) 219 | return this.client.post(path, params) 220 | } 221 | 222 | public resetPassword(params: { username: string; email: string; code?: string; password?: string }): Promise { 223 | const path = buildPath({ 224 | endpointName: 'password/reset', 225 | }) 226 | return this.client.put(path, params) 227 | } 228 | 229 | public refreshToken(refreshToken: string): Promise> { 230 | const path = buildPath({ 231 | endpointName: `refresh/${refreshToken}`, 232 | }) 233 | return this.client.post(path, {}) 234 | } 235 | 236 | public needMFACode(params: { username: string; password: string }): Promise> { 237 | const path = buildPath({ 238 | endpointName: 'login/precheck', 239 | }) 240 | return this.client.post(path, { ...params }) 241 | } 242 | 243 | public login(params: { username: string; password: string; authcode: boolean }): Promise> { 244 | const path = buildPath({ 245 | endpointName: 'login', 246 | }) 247 | return this.client.post(path, { ...params }) 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /packages/admin-api/src/AuthorizedClient.ts: -------------------------------------------------------------------------------- 1 | import { buildPath } from './url' 2 | import { AccessToken, LoginPreCheck, Response } from './types' 3 | import { DefaultHttpClient, HaloRequestConfigBuilder, HaloResponseHandler } from '@halo-dev/rest-api-client' 4 | 5 | export class AuthorizedClient { 6 | private client: DefaultHttpClient 7 | 8 | constructor(baseUrl: string) { 9 | const requestConfigBuilder = new HaloRequestConfigBuilder({ 10 | baseUrl: baseUrl, 11 | }) 12 | const responseHandler = new HaloResponseHandler() 13 | this.client = new DefaultHttpClient({ 14 | responseHandler, 15 | requestConfigBuilder, 16 | }) 17 | } 18 | 19 | public isInstalled(): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'is_installed', 22 | }) 23 | return this.client.get(path, {}) 24 | } 25 | 26 | public sendResetPasswordCode(params: { 27 | username: string 28 | email: string 29 | code?: string 30 | password?: string 31 | }): Promise { 32 | const path = buildPath({ 33 | endpointName: 'password/code', 34 | }) 35 | return this.client.post(path, params) 36 | } 37 | 38 | public resetPassword(params: { username: string; email: string; code?: string; password?: string }): Promise { 39 | const path = buildPath({ 40 | endpointName: 'password/reset', 41 | }) 42 | return this.client.post(path, params) 43 | } 44 | 45 | public refreshToken(refreshToken: string): Promise> { 46 | const path = buildPath({ 47 | endpointName: `refresh/${refreshToken}`, 48 | }) 49 | return this.client.post(path, {}) 50 | } 51 | 52 | public login(params: { username: string; password: string; authcode: boolean }): Promise> { 53 | const path = buildPath({ 54 | endpointName: 'login', 55 | }) 56 | return this.client.post(path, { ...params }) 57 | } 58 | 59 | public needMFACode(params: { username: string; password: string }): Promise> { 60 | const path = buildPath({ 61 | endpointName: 'login/precheck', 62 | }) 63 | return this.client.post(path, { ...params }) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /packages/admin-api/src/__tests__/AuthorizedClient.test.ts: -------------------------------------------------------------------------------- 1 | import { AuthorizedClient } from '../AuthorizedClient' 2 | 3 | describe('Halo AuthorizedClient test', () => { 4 | it('base test', async () => { 5 | const authorizedClient = new AuthorizedClient('http://localhost:8090') 6 | 7 | const data = await authorizedClient.isInstalled() 8 | console.log('authorizedClient test response:', data) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/ActuatorClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { Response } from '../types' 3 | import { buildPath } from '../url' 4 | 5 | export class ActuatorClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public getLogfile(): Promise> { 13 | const path = buildPath({ 14 | endpointName: 'actuator/logfile', 15 | }) 16 | return this.client.get(path, {}) 17 | } 18 | 19 | public getEnv(): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'actuator/env', 22 | }) 23 | return this.client.get(path, {}) 24 | } 25 | 26 | public getSystemCpuCount(): Promise> { 27 | const path = buildPath({ 28 | endpointName: 'actuator/metrics/system.cpu.count', 29 | }) 30 | return this.client.get(path, {}) 31 | } 32 | 33 | public getSystemCpuUsage(): Promise> { 34 | const path = buildPath({ 35 | endpointName: 'actuator/metrics/system.cpu.usage', 36 | }) 37 | return this.client.get(path, {}) 38 | } 39 | 40 | public getProcessUptime(): Promise> { 41 | const path = buildPath({ 42 | endpointName: 'actuator/metrics/process.uptime', 43 | }) 44 | return this.client.get(path, {}) 45 | } 46 | 47 | public getProcessStartTime(): Promise> { 48 | const path = buildPath({ 49 | endpointName: 'actuator/metrics/process.start.time', 50 | }) 51 | return this.client.get(path, {}) 52 | } 53 | 54 | public getProcessCpuUsage(): Promise> { 55 | const path = buildPath({ 56 | endpointName: 'actuator/metrics/process.cpu.usage', 57 | }) 58 | return this.client.get(path, {}) 59 | } 60 | 61 | public getJvmMemoryMax(): Promise> { 62 | const path = buildPath({ 63 | endpointName: 'actuator/metrics/jvm.memory.max', 64 | }) 65 | return this.client.get(path, {}) 66 | } 67 | 68 | public getJvmMemoryCommitted(): Promise> { 69 | const path = buildPath({ 70 | endpointName: 'actuator/metrics/jvm.memory.committed', 71 | }) 72 | return this.client.get(path, {}) 73 | } 74 | 75 | public getJvmMemoryUsed(): Promise> { 76 | const path = buildPath({ 77 | endpointName: 'actuator/metrics/jvm.memory.used', 78 | }) 79 | return this.client.get(path, {}) 80 | } 81 | 82 | public getJvmGcPause(): Promise> { 83 | const path = buildPath({ 84 | endpointName: 'actuator/metrics/jvm.gc.pause', 85 | }) 86 | return this.client.get(path, {}) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/AttachmentClient.ts: -------------------------------------------------------------------------------- 1 | import { FormData, HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Attachment, AttachmentQuery, Page, Response, UploadOptions } from '../types' 4 | 5 | export class AttachmentClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | /** 13 | * Gets attachment detail by id. 14 | * 15 | * @param attachmentId attachment id 16 | * @returns Returns attachment detail response. 17 | */ 18 | public get(attachmentId: number): Promise> { 19 | const path = buildPath({ 20 | endpointName: `attachments/${attachmentId}`, 21 | }) 22 | return this.client.get(path, {}) 23 | } 24 | 25 | /** 26 | * Page query attachment list. 27 | * 28 | * @param params attachment query parameter 29 | * @returns Returns attachment page response. 30 | */ 31 | public list(params: AttachmentQuery): Promise>> { 32 | const path = buildPath({ 33 | endpointName: 'attachments', 34 | }) 35 | return this.client.get(path, { ...params }) 36 | } 37 | 38 | /** 39 | * Batch delete attachment permanently by attachment ids. 40 | * 41 | * @param attachmentIds a collection of attachment id 42 | * @returns Returns attachments of deleted 43 | */ 44 | public deleteInBatch(attachmentIds: Array): Promise>> { 45 | const path = buildPath({ 46 | endpointName: 'attachments', 47 | }) 48 | return this.client.delete(path, attachmentIds) 49 | } 50 | 51 | /** 52 | * Delete attachment permanently by attachment id. 53 | * 54 | * @param attachmentId attachment id 55 | * @returns Returns attachment detail of deleted 56 | */ 57 | public delete(attachmentId: number): Promise>> { 58 | const path = buildPath({ 59 | endpointName: `attachments/${attachmentId}`, 60 | }) 61 | return this.client.delete(path, {}) 62 | } 63 | 64 | /** 65 | * Update attachment name by id. 66 | * 67 | * @param attachmentId attachment id 68 | * @param name a new attachment name 69 | * @returns Returns an updated attachment response. 70 | */ 71 | public update(attachmentId: number, name: string): Promise> { 72 | const path = buildPath({ 73 | endpointName: `attachments/${attachmentId}`, 74 | }) 75 | return this.client.put(path, { name }) 76 | } 77 | 78 | /** 79 | * List all of attachment media types. 80 | * 81 | * @returns Returns attachment media types response. 82 | */ 83 | public listMediaTypes(): Promise>> { 84 | const path = buildPath({ 85 | endpointName: 'attachments/media_types', 86 | }) 87 | return this.client.get(path, {}) 88 | } 89 | 90 | /** 91 | * List all of attachment types. 92 | * 93 | * @returns Returns a response of attachment types. 94 | */ 95 | public listTypes(): Promise>> { 96 | const path = buildPath({ 97 | endpointName: 'attachments/types', 98 | }) 99 | return this.client.get(path, {}) 100 | } 101 | 102 | /** 103 | * Upload a single attachment file. 104 | * 105 | * @param data attachment file object. 106 | * @param options other upload options. 107 | * @returns Returns a response of uploaded attachment 108 | */ 109 | public upload(data: unknown, options?: UploadOptions): Promise> { 110 | const path = buildPath({ 111 | endpointName: 'attachments/upload', 112 | }) 113 | const formData = new FormData() 114 | formData.append('file', data) 115 | return this.client.post(path, formData, { ...options }) 116 | } 117 | 118 | /** 119 | * Batch upload attachments. 120 | * 121 | * @param data attachment file object. 122 | * @param options other upload options. 123 | * @returns Returns a response of uploaded attachments. 124 | */ 125 | public uploadInBatch(data: Array, options?: UploadOptions): Promise>> { 126 | const path = buildPath({ 127 | endpointName: 'attachments/uploads', 128 | }) 129 | const formData = new FormData() 130 | data.forEach((fileStream) => { 131 | formData.append('files', fileStream) 132 | }) 133 | return this.client.post(path, formData, { ...options }) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/BackupClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Backup, BasePostDetail, Response, UploadOptions } from '../types' 4 | 5 | export class BackupClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public getWorkdirBackup(filename: string): Promise> { 13 | const path = buildPath({ 14 | endpointName: `backups/work-dir/fetch?filename=${filename}`, 15 | }) 16 | 17 | return this.client.get(path, {}) 18 | } 19 | 20 | public getDataBackup(filename: string): Promise> { 21 | const path = buildPath({ 22 | endpointName: `backups/data/fetch?filename=${filename}`, 23 | }) 24 | 25 | return this.client.get(path, {}) 26 | } 27 | 28 | public getMarkdownBackup(filename: string): Promise> { 29 | const path = buildPath({ 30 | endpointName: `backups/markdown/fetch?filename=${filename}`, 31 | }) 32 | 33 | return this.client.get(path, {}) 34 | } 35 | 36 | public backupWorkdir(options: Array): Promise> { 37 | const path = buildPath({ 38 | endpointName: 'backups/work-dir', 39 | }) 40 | return this.client.post(path, options) 41 | } 42 | 43 | public getWorkdirBackupOptions(): Promise>> { 44 | const path = buildPath({ 45 | endpointName: 'backups/work-dir/options', 46 | }) 47 | return this.client.get(path, {}) 48 | } 49 | 50 | public listWorkdirBackups(): Promise>> { 51 | const path = buildPath({ 52 | endpointName: 'backups/work-dir', 53 | }) 54 | return this.client.get(path, {}) 55 | } 56 | 57 | public deleteWorkdirBackup(filename: string): Promise> { 58 | const path = buildPath({ 59 | endpointName: `backups/work-dir`, 60 | }) 61 | return this.client.delete(path, { filename }) 62 | } 63 | 64 | public backupData(): Promise> { 65 | const path = buildPath({ 66 | endpointName: 'backups/data', 67 | }) 68 | return this.client.post(path, {}) 69 | } 70 | 71 | public listDataBackups(): Promise>> { 72 | const path = buildPath({ 73 | endpointName: 'backups/data', 74 | }) 75 | return this.client.get(path, {}) 76 | } 77 | 78 | public deleteDataBackup(filename: string): Promise> { 79 | const path = buildPath({ 80 | endpointName: `backups/data`, 81 | }) 82 | return this.client.delete(path, { filename }) 83 | } 84 | 85 | public backupMarkdown(params: { needFrontMatter: boolean }): Promise> { 86 | const path = buildPath({ 87 | endpointName: 'backups/markdown/export', 88 | }) 89 | return this.client.post(path, params) 90 | } 91 | 92 | public listMarkdownBackups(): Promise>> { 93 | const path = buildPath({ 94 | endpointName: 'backups/markdown/export', 95 | }) 96 | return this.client.get(path, {}) 97 | } 98 | 99 | public deleteMarkdownBackup(filename: string): Promise> { 100 | const path = buildPath({ 101 | endpointName: `backups/markdown/export`, 102 | }) 103 | return this.client.delete(path, { filename }) 104 | } 105 | 106 | public importMarkdown(data: any, options: UploadOptions): Promise> { 107 | const path = buildPath({ 108 | endpointName: 'backups/markdown/import', 109 | }) 110 | const formData = new FormData() 111 | formData.append('file', data) 112 | return this.client.post(path, formData, { ...options }) 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/CategoryClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Category, CategoryParam, CategoryTree, Response } from '../types' 4 | 5 | export class CategoryClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | /** 13 | * Lists all categories. 14 | * 15 | * @param params parameter for queries 16 | * @returns A response of all categories. 17 | */ 18 | public list(params: { sort?: Array; more?: boolean }): Promise>> { 19 | const path = buildPath({ 20 | endpointName: 'categories', 21 | }) 22 | return this.client.get(path, { ...params }) 23 | } 24 | 25 | /** 26 | * List all categories as tree. 27 | * 28 | * @param sort sort option for queries, value is category field 29 | * @returns A response of all categories. 30 | */ 31 | public listAsTree(sort: Array): Promise>> { 32 | const path = buildPath({ 33 | endpointName: 'categories/tree_view', 34 | }) 35 | return this.client.get(path, { sort }) 36 | } 37 | 38 | /** 39 | * Gets category detail by id. 40 | * 41 | * @param categoryId category id 42 | * @returns A response of category detail. 43 | */ 44 | public get(categoryId: number): Promise> { 45 | const path = buildPath({ 46 | endpointName: `categories/${categoryId}`, 47 | }) 48 | return this.client.get(path, {}) 49 | } 50 | 51 | /** 52 | * Creates a category. 53 | * 54 | * @param params category parameter to create 55 | * @returns A response of created category. 56 | */ 57 | public create(params: CategoryParam): Promise> { 58 | const path = buildPath({ 59 | endpointName: 'categories', 60 | }) 61 | return this.client.post(path, { ...params }) 62 | } 63 | 64 | /** 65 | * Updates category by id 66 | * 67 | * @param categoryId category id 68 | * @param params category update parameter 69 | * @returns A response of updated category. 70 | */ 71 | public update(categoryId: number, params: CategoryParam): Promise> { 72 | const path = buildPath({ 73 | endpointName: `categories/${categoryId}`, 74 | }) 75 | return this.client.put(path, { ...params }) 76 | } 77 | 78 | /** 79 | * Updates category in batch 80 | * 81 | * @param params 82 | */ 83 | public updateInBatch(params: Array): Promise>> { 84 | const path = buildPath({ 85 | endpointName: 'categories/batch', 86 | }) 87 | return this.client.put(path, [...params]) 88 | } 89 | 90 | /** 91 | * Deletes a category by id. 92 | * 93 | * @param categoryId category id 94 | */ 95 | public async delete(categoryId: number): Promise { 96 | const path = buildPath({ 97 | endpointName: `categories/${categoryId}`, 98 | }) 99 | await this.client.delete(path, {}) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/CommentClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { 3 | BaseComment, 4 | BaseCommentParam, 5 | CommentQuery, 6 | CommentStatus, 7 | Page, 8 | PostCommentWithPost, 9 | Response, 10 | } from '../types' 11 | import { buildPath } from '../url' 12 | 13 | type commentTargets = 'posts' | 'sheets' | 'journals' 14 | 15 | export class CommentClient { 16 | private client: HttpClient 17 | 18 | constructor(client: HttpClient) { 19 | this.client = client 20 | } 21 | 22 | public list(target: commentTargets, params: CommentQuery): Promise>> { 23 | const path = buildPath({ 24 | endpointName: `${target}/comments`, 25 | }) 26 | return this.client.get(path, params) 27 | } 28 | 29 | public latest( 30 | target: commentTargets, 31 | top: number, 32 | status: CommentStatus, 33 | ): Promise>> { 34 | const path = buildPath({ 35 | endpointName: `${target}/comments/latest`, 36 | }) 37 | return this.client.get(path, { top, status }) 38 | } 39 | 40 | public listAsView( 41 | target: commentTargets, 42 | targetId: number, 43 | params: { page: number; sort?: Array }, 44 | ): Promise>> { 45 | const path = buildPath({ 46 | endpointName: `${target}/comments/${targetId}/list_view`, 47 | }) 48 | return this.client.get(path, params) 49 | } 50 | 51 | public listAsTreeView( 52 | target: commentTargets, 53 | targetId: number, 54 | params: { 55 | sort?: Array 56 | page?: number 57 | }, 58 | ): Promise>> { 59 | const path = buildPath({ 60 | endpointName: `${target}/comments/${targetId}/tree_view`, 61 | }) 62 | return this.client.get(path, params) 63 | } 64 | 65 | public get(target: commentTargets, commentId: number): Promise> { 66 | const path = buildPath({ 67 | endpointName: `${target}/comments/${commentId}`, 68 | }) 69 | return this.client.get(path, {}) 70 | } 71 | 72 | public create(target: commentTargets, params: BaseCommentParam): Promise> { 73 | const path = buildPath({ 74 | endpointName: `${target}/comments`, 75 | }) 76 | return this.client.post(path, params) 77 | } 78 | 79 | public update(target: commentTargets, commentId: number, params: BaseCommentParam): Promise> { 80 | const path = buildPath({ 81 | endpointName: `${target}/comments/${commentId}`, 82 | }) 83 | return this.client.get(path, params) 84 | } 85 | 86 | public updateStatusById( 87 | target: commentTargets, 88 | commentId: number, 89 | status: CommentStatus, 90 | ): Promise> { 91 | const path = buildPath({ 92 | endpointName: `${target}/comments/${commentId}/status/${status}`, 93 | }) 94 | return this.client.put(path, {}) 95 | } 96 | 97 | public updateStatusInBatch( 98 | target: commentTargets, 99 | commentIds: Array, 100 | status: CommentStatus, 101 | ): Promise>> { 102 | const path = buildPath({ 103 | endpointName: `${target}/comments/status/${status}`, 104 | }) 105 | return this.client.put(path, commentIds) 106 | } 107 | 108 | public delete(target: commentTargets, commentId: number): Promise> { 109 | const path = buildPath({ 110 | endpointName: `${target}/comments/${commentId}`, 111 | }) 112 | return this.client.delete(path, {}) 113 | } 114 | 115 | public deleteInBatch(target: commentTargets, postCommentIds: Array): Promise>> { 116 | const path = buildPath({ 117 | endpointName: `${target}/comments`, 118 | }) 119 | return this.client.delete(path, postCommentIds) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/InstallationClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { InstallParam, Response } from '../types' 4 | 5 | export class InstallationClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | /** 13 | * Initializes the blog. 14 | * 15 | * @param params installation parameter 16 | * @returns A response of installation status message. 17 | */ 18 | public install(params: InstallParam): Promise> { 19 | const path = buildPath({ 20 | endpointName: 'installations', 21 | }) 22 | return this.client.post(path, { ...params }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/JournalClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Journal, JournalParam, JournalQuery, JournalWithCmtCount, Page, Response } from '../types' 4 | 5 | export class JournalClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | /** 13 | * Lists journals. 14 | * 15 | * @param params parameter for queries 16 | * @returns A page response of journals. 17 | */ 18 | public list(params: JournalQuery): Promise>> { 19 | const path = buildPath({ 20 | endpointName: 'journals', 21 | }) 22 | return this.client.get(path, { ...params }) 23 | } 24 | 25 | /** 26 | * Gets latest journals. 27 | * 28 | * @param top top option for queries 29 | * @returns A response of lastes journals. 30 | */ 31 | public latest(top: number): Promise>> { 32 | const path = buildPath({ 33 | endpointName: 'journals/latest', 34 | }) 35 | return this.client.get(path, { top }) 36 | } 37 | 38 | /** 39 | * Creates a journal. 40 | * 41 | * @param params parameter for creates 42 | * @returns A response of created journal. 43 | */ 44 | public create(params: JournalParam): Promise> { 45 | const path = buildPath({ 46 | endpointName: 'journals', 47 | }) 48 | return this.client.post(path, { ...params }) 49 | } 50 | 51 | /** 52 | * Updates a journal by id. 53 | * 54 | * @param journalId journal id 55 | * @param params parameter for updates 56 | * @returns A response of updated journal. 57 | */ 58 | public update(journalId: number, params: JournalParam): Promise> { 59 | const path = buildPath({ 60 | endpointName: `journals/${journalId}`, 61 | }) 62 | return this.client.put(path, { ...params }) 63 | } 64 | 65 | /** 66 | * Deletes a journal by id. 67 | * @param journalId journal id 68 | */ 69 | public async delete(journalId: number): Promise { 70 | const path = buildPath({ 71 | endpointName: `journals/${journalId}`, 72 | }) 73 | await this.client.delete(path, {}) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/JournalCommentClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { 4 | BaseComment, 5 | BaseCommentParam, 6 | CommentStatus, 7 | JournalCommentQuery, 8 | JournalCommentWithJournal, 9 | Page, 10 | Response, 11 | } from '../types' 12 | 13 | export class JournalCommentClient { 14 | private client: HttpClient 15 | 16 | constructor(client: HttpClient) { 17 | this.client = client 18 | } 19 | 20 | /** 21 | * Lists journal comments. 22 | * 23 | * @param params parameter for queries 24 | * @returns A page response of journals. 25 | */ 26 | public async list(params: JournalCommentQuery): Promise>> { 27 | const path = buildPath({ 28 | endpointName: 'journals/comments', 29 | }) 30 | return this.client.get(path, { ...params }) 31 | } 32 | 33 | /** 34 | * Creates a journal comment. 35 | * 36 | * @param params comment parameter for creates 37 | * @returns A response of created journal comment. 38 | */ 39 | public create(params: BaseCommentParam): Promise> { 40 | const path = buildPath({ 41 | endpointName: 'journals/comments', 42 | }) 43 | return this.client.post(path, { ...params }) 44 | } 45 | 46 | /** 47 | * Deletes a journal comment by id. 48 | * 49 | * @param commentId journal comment id. 50 | * @returns A response of deleted journal comment. 51 | */ 52 | public delete(commentId: number): Promise> { 53 | const path = buildPath({ 54 | endpointName: `journals/comments/${commentId}`, 55 | }) 56 | return this.client.delete(path, {}) 57 | } 58 | 59 | /** 60 | * Updates journal comment status by id. 61 | * 62 | * @param commentId journal comment id 63 | * @param status comment status 64 | * @returns A response of updated journal comment. 65 | */ 66 | public update(commentId: number, status: CommentStatus): Promise> { 67 | const path = buildPath({ 68 | endpointName: `journals/comments/${commentId}/status/${status}`, 69 | }) 70 | return this.client.put(path, {}) 71 | } 72 | 73 | /** 74 | * Lists comment with list view. 75 | * 76 | * @param params parameter for queries 77 | * @returns A page response of journal comments. 78 | */ 79 | public listAsView(params: { 80 | journalId: number 81 | sort?: Array 82 | page?: number 83 | }): Promise>> { 84 | const path = buildPath({ 85 | endpointName: `journals/comments/${params.journalId}/list_view`, 86 | }) 87 | return this.client.get(path, { ...params }) 88 | } 89 | 90 | /** 91 | * Lists comment with tree view. 92 | * 93 | * @param params parameter for queries 94 | * @returns A page response of journal comments tree. 95 | */ 96 | public listAsTree(params: { 97 | journalId: number 98 | sort?: Array 99 | page?: number 100 | }): Promise>> { 101 | const path = buildPath({ 102 | endpointName: `journals/comments/${params.journalId}/tree_view`, 103 | }) 104 | return this.client.get(path, { ...params }) 105 | } 106 | 107 | /** 108 | * Lists latest journal comments. 109 | * 110 | * @param params parameter for queries 111 | * @returns A response of latest journal comments. 112 | */ 113 | public latest(params: { top?: number; status?: CommentStatus }): Promise>> { 114 | const path = buildPath({ 115 | endpointName: 'journals/comments/latest', 116 | }) 117 | return this.client.get(path, { ...params }) 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/LinkClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Link, Response } from '../types' 4 | 5 | export class LinkClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public list(sort?: Array): Promise>> { 13 | const path = buildPath({ 14 | endpointName: 'links', 15 | }) 16 | return this.client.get(path, { sort }) 17 | } 18 | 19 | public create(params: Link): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'links', 22 | }) 23 | return this.client.post(path, { ...params }) 24 | } 25 | 26 | public get(id: number): Promise> { 27 | const path = buildPath({ 28 | endpointName: `links/${id}`, 29 | }) 30 | return this.client.get(path, {}) 31 | } 32 | 33 | public update(linkId: number, params: Link): Promise> { 34 | const path = buildPath({ 35 | endpointName: `links/${linkId}`, 36 | }) 37 | return this.client.put(path, { ...params }) 38 | } 39 | 40 | public updateInBatch(params: Array): Promise>> { 41 | const path = buildPath({ 42 | endpointName: 'links/batch', 43 | }) 44 | return this.client.put(path, [...params]) 45 | } 46 | 47 | public async delete(id: number): Promise { 48 | const path = buildPath({ 49 | endpointName: `links/${id}`, 50 | }) 51 | await this.client.delete(path, {}) 52 | } 53 | 54 | public listTeams(): Promise>> { 55 | const path = buildPath({ 56 | endpointName: 'links/teams', 57 | }) 58 | return this.client.get(path, {}) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/LogClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Log, Page, Response } from '../types' 4 | 5 | export class LogClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | /** 13 | * List action logs by params. 14 | * 15 | * @param params 16 | */ 17 | public list(params: { page: number; size: number; sort?: Array }): Promise>> { 18 | const path = buildPath({ 19 | endpointName: 'logs', 20 | }) 21 | return this.client.get(path, { ...params }) 22 | } 23 | 24 | /** 25 | * Clear action logs 26 | */ 27 | public async clear(): Promise { 28 | const path = buildPath({ 29 | endpointName: 'logs/clear', 30 | }) 31 | await this.client.get(path, {}) 32 | } 33 | 34 | /** 35 | * Get latest action logs 36 | * 37 | * @param top the number of logs to get 38 | */ 39 | public latest(top: number): Promise>> { 40 | const path = buildPath({ 41 | endpointName: 'logs/latest', 42 | }) 43 | return this.client.get(path, { top }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/MailClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Response } from '../types' 4 | 5 | export class MailClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public testSmtpService(params: { content: string; subject: string; to: string }): Promise> { 13 | const path = buildPath({ 14 | endpointName: 'mails/test', 15 | }) 16 | return this.client.post(path, { ...params }) 17 | } 18 | 19 | public testConnect(): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'mails/test/connection', 22 | }) 23 | return this.client.post(path, {}) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/MenuClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Menu, Response } from '../types' 4 | 5 | export class MenuClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public list(): Promise>> { 13 | const path = buildPath({ 14 | endpointName: 'menus', 15 | }) 16 | return this.client.get(path, {}) 17 | } 18 | 19 | public create(params: Menu): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'menus', 22 | }) 23 | return this.client.post(path, { ...params }) 24 | } 25 | 26 | public createInBatch(params: Array): Promise>> { 27 | const path = buildPath({ 28 | endpointName: 'menus/batch', 29 | }) 30 | return this.client.post(path, [...params]) 31 | } 32 | 33 | public get(menuId: number): Promise> { 34 | const path = buildPath({ 35 | endpointName: `menus/${menuId}`, 36 | }) 37 | return this.client.post(path, {}) 38 | } 39 | 40 | public update(menuId: number, params: Menu): Promise> { 41 | const path = buildPath({ 42 | endpointName: `menus/${menuId}`, 43 | }) 44 | return this.client.put(path, { ...params }) 45 | } 46 | 47 | public updateInBatch(params: Array): Promise>> { 48 | const path = buildPath({ 49 | endpointName: 'menus/batch', 50 | }) 51 | return this.client.put(path, [...params]) 52 | } 53 | 54 | public async delete(menuId: number): Promise { 55 | const path = buildPath({ 56 | endpointName: `menus/${menuId}`, 57 | }) 58 | await this.client.delete(path, {}) 59 | } 60 | 61 | public async deleteInBatch(menuIds: Array): Promise { 62 | const path = buildPath({ 63 | endpointName: 'menus/batch', 64 | }) 65 | await this.client.delete(path, [...menuIds]) 66 | } 67 | 68 | public listTreeViewByTeam(team: string, sort?: Array): Promise>> { 69 | const path = buildPath({ 70 | endpointName: 'menus/team/tree_view', 71 | }) 72 | return this.client.get(path, { team, sort }) 73 | } 74 | 75 | public listTeams(): Promise>> { 76 | const path = buildPath({ 77 | endpointName: 'menus/teams', 78 | }) 79 | return this.client.get(path, {}) 80 | } 81 | 82 | public listTreeView(sort?: Array): Promise>> { 83 | const path = buildPath({ 84 | endpointName: 'menus/tree_view', 85 | }) 86 | return this.client.get(path, { sort }) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/MigrationClient.ts: -------------------------------------------------------------------------------- 1 | import { FormData, HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { UploadOptions } from '../types' 4 | 5 | export class MigrationClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public async migrate(data: unknown, options: UploadOptions): Promise { 13 | const path = buildPath({ 14 | endpointName: 'migrations/halo', 15 | }) 16 | const formData = new FormData() 17 | formData.append('file', data) 18 | await this.client.post(path, formData, { ...options }) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/admin-api/src/clients/OptionClient.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@halo-dev/rest-api-client' 2 | import { buildPath } from '../url' 3 | import { Option, OptionQuery, Response } from '../types' 4 | 5 | export class OptionClient { 6 | private client: HttpClient 7 | 8 | constructor(client: HttpClient) { 9 | this.client = client 10 | } 11 | 12 | public list(): Promise>> { 13 | const path = buildPath({ 14 | endpointName: 'options', 15 | }) 16 | return this.client.get(path, {}) 17 | } 18 | 19 | public create(params: Option): Promise> { 20 | const path = buildPath({ 21 | endpointName: 'options', 22 | }) 23 | return this.client.post(path, { ...params }) 24 | } 25 | 26 | public get(id: number): Promise> { 27 | const path = buildPath({ 28 | endpointName: `options/${id}`, 29 | }) 30 | return this.client.get(path, {}) 31 | } 32 | 33 | public update(optionId: number, params: Option): Promise> { 34 | const path = buildPath({ 35 | endpointName: `options/${optionId}`, 36 | }) 37 | return this.client.put(path, { ...params }) 38 | } 39 | 40 | public async delete(optionId: number): Promise { 41 | const path = buildPath({ 42 | endpointName: `options/${optionId}`, 43 | }) 44 | await this.client.delete(path, {}) 45 | } 46 | 47 | public listAsView(params: OptionQuery): Promise>> { 48 | const path = buildPath({ 49 | endpointName: 'options/list_view', 50 | }) 51 | return this.client.get(path, { ...params }) 52 | } 53 | 54 | public listAsMapView(): Promise>> { 55 | const path = buildPath({ 56 | endpointName: 'options/map_view', 57 | }) 58 | return this.client.get(path, {}) 59 | } 60 | 61 | public listAsMapViewByKeys(params: Array): Promise>> { 62 | const path = buildPath({ 63 | endpointName: 'options/map_view/keys', 64 | }) 65 | return this.client.post(path, params) 66 | } 67 | 68 | public async saveMapView(params: any): Promise { 69 | const path = buildPath({ 70 | endpointName: 'options/map_view/saving', 71 | }) 72 | await this.client.post(path, { ...params }) 73 | } 74 | 75 | public async save(params: Array