Registry / devops / zhi-gitlab-middleware

zhi-gitlab-middleware

JSON →
library0.12.4jsnpmunverified

zhi-gitlab-middleware is a middleware library for GitLab API, version 0.12.4. It provides a simple way to interact with GitLab's API through middleware patterns, allowing you to add custom logic before or after API calls. The library is built in TypeScript and ships with type definitions. It has no external dependencies, making it lightweight and easy to integrate into any Node.js project. Compared to other GitLab API clients, it focuses on middleware composition rather than a full-featured client, giving developers fine-grained control over API interactions. Release cadence is irregular.

npm install zhi-gitlab-middleware
INSTALL
IMPORT
SIG · ZHI-GITLAB-MIDDLEW
Z
zhi-gitlab-middleware
devopsjavascriptv0.12.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GitLabMiddleware
import { GitLabMiddleware } from 'zhi-gitlab-middleware'
const GitLabMiddleware = require('zhi-gitlab-middleware')
ESM-only library; CommonJS require will not work.
createMiddleware
import { createMiddleware } from 'zhi-gitlab-middleware'
import createMiddleware from 'zhi-gitlab-middleware'
createMiddleware is a named export, not default.
GitLabClient
import type { GitLabClient } from 'zhi-gitlab-middleware'
import { GitLabClient } from 'zhi-gitlab-middleware'
GitLabClient is a TypeScript type, use `import type` at compile time.

Initializes GitLabMiddleware with token, adds logging middleware via createMiddleware, and fetches current user.

import { GitLabMiddleware, createMiddleware } from 'zhi-gitlab-middleware' // Create a middleware instance const middleware = new GitLabMiddleware({ baseUrl: 'https://gitlab.com', token: process.env.GITLAB_TOKEN ?? '' }) // Define a custom middleware const logger = createMiddleware(async (req, next) => { console.log('Requesting:', req.url) const res = await next(req) console.log('Response status:', res.status) return res }) // Use the middleware const client = middleware.use(logger).getClient() // Example: get current user async function main() { const user = await client.users.current() console.log('User:', user.name) } main()
Debug
Known issues
breakingVersion 0.12.x changed the middleware API; `use` now expects a function instead of an object.
fix
Update middleware to use the new function signature: `middleware.use((req, next) => ...)`
affects: >=0.12.0 <0.12.4
deprecatedThe `GitLabMiddleware` constructor option `host` is deprecated; use `baseUrl` instead.
fix
Replace `host` with `baseUrl` in the constructor options.
affects: >=0.10.0
gotchaThe library does not handle token refresh automatically; expired tokens cause 401 errors.
fix
Implement custom middleware to check response status and refresh token if needed.
affects: all
gotchaTypeScript types are exported under `@types/zhi-gitlab-middleware`; do not use `@types/zhi-gitlab-middleware` as it may mismatch version.
fix
Ensure types are imported directly from the package: `import { GitLabClient } from 'zhi-gitlab-middleware'`
affects: all
Errors
Common errors & fixes
Cannot find module 'zhi-gitlab-middleware' or its corresponding type declarations.
Missing dependency or TypeScript not resolving types.
fix
Run `npm install zhi-gitlab-middleware` and ensure `tsconfig.json` includes `"moduleResolution": "node"`
TypeError: middleware.use is not a function
Using outdated API where `use` was a method on the client object, not the middleware instance.
fix
Ensure you are calling `use` on the `GitLabMiddleware` instance: `const middleware = new GitLabMiddleware(...); middleware.use(...)`
Property 'current' does not exist on type 'Users'
GitLab API version mismatch; `current` endpoint may be named differently in older versions.
fix
Check GitLab API docs; use `users.me()` instead of `users.current()` for GitLab API v4.
Upgrade
Version history
0.12.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
21
Resources
zhi-gitlab-middleware — npm install zhi-gitlab-middleware · libregistry