Skip to content

Commit

Permalink
feat: support custom fetch client for gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 30, 2024
1 parent 143cf45 commit 6172bb1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
6 changes: 6 additions & 0 deletions libs/zhi-fetch-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# zhi-fetch-middleware

## 0.10.0

### Minor Changes

- feat: support custom fetch client for gitlab

## 0.9.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/zhi-fetch-middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zhi-fetch-middleware",
"version": "0.9.1",
"version": "0.10.0",
"type": "module",
"description": "an intermediate tier prepared for fetch requests",
"main": "./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions libs/zhi-fetch-middleware/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CommonFetchClient from "./lib/commonFetchClient"
import { ICommonFetchClient } from "./lib/types"

export { CommonFetchClient }
export { type ICommonFetchClient }
3 changes: 2 additions & 1 deletion libs/zhi-fetch-middleware/src/lib/commonFetchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import { JsonUtil, StrUtil } from "zhi-common"
import { fetchNode } from "./impl/nodeFetch"
import { fetchChrome } from "./impl/chromeFetch"
import { fetchMiddleware } from "./impl/middlewareFetch"
import { ICommonFetchClient } from "./types"

class CommonFetchClient {
class CommonFetchClient implements ICommonFetchClient {
private readonly appInstance: any

private readonly logger: any
Expand Down
33 changes: 33 additions & 0 deletions libs/zhi-fetch-middleware/src/lib/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

/**
* 通用的 Fetch 接口
*/
interface ICommonFetchClient {
fetchCall(endpointUrl: string, fetchOptions: RequestInit, forceProxy?: boolean): Promise<any>
}

export {ICommonFetchClient}
11 changes: 11 additions & 0 deletions libs/zhi-gitlab-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# zhi-gitlab-middleware

## 0.8.0

### Minor Changes

- feat: support custom fetch client for gitlab

### Patch Changes

- Updated dependencies
- zhi-fetch-middleware@0.10.0

## 0.7.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/zhi-gitlab-middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zhi-gitlab-middleware",
"version": "0.7.1",
"version": "0.8.0",
"type": "module",
"description": "a middleware for gitlab api ",
"main": "./dist/index.js",
Expand Down
8 changes: 5 additions & 3 deletions libs/zhi-gitlab-middleware/src/lib/commonGitlabClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

import { simpleLogger } from "zhi-lib-base"
import { CommonFetchClient } from "zhi-fetch-middleware"
import { CommonFetchClient, ICommonFetchClient } from "zhi-fetch-middleware"

/**
* 通用的Gitlab客户端
Expand All @@ -38,7 +38,7 @@ class CommonGitlabClient {
private readonly commitMessage: string
private readonly authorEmail: string
private readonly authorName: string
private readonly commonFetchClient: CommonFetchClient
private readonly commonFetchClient: ICommonFetchClient

/**
* 初始化 Gitlab API
Expand All @@ -52,6 +52,7 @@ class CommonGitlabClient {
* @param commitMessage - 提交信息
* @param authorEmail - 邮箱
* @param authorName - 提交人
* @param commonFetchClient - 请求客户端
* @param middlewareUrl - 代理地址
* @param isDev - 是否调试模式
*/
Expand All @@ -65,6 +66,7 @@ class CommonGitlabClient {
commitMessage: string,
authorEmail: string,
authorName: string,
commonFetchClient?: ICommonFetchClient,
middlewareUrl?: string,
isDev?: boolean
) {
Expand All @@ -76,7 +78,7 @@ class CommonGitlabClient {
this.commitMessage = commitMessage
this.authorEmail = authorEmail
this.authorName = authorName
this.commonFetchClient = new CommonFetchClient(appInstance, host, middlewareUrl, isDev)
this.commonFetchClient = commonFetchClient ?? new CommonFetchClient(appInstance, host, middlewareUrl, isDev)
}

/**
Expand Down

0 comments on commit 6172bb1

Please sign in to comment.