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.fixUpdate 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.fixReplace `host` with `baseUrl` in the constructor options.
affects: >=0.10.0
gotchaThe library does not handle token refresh automatically; expired tokens cause 401 errors.fixImplement 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.fixEnsure 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.
fixRun `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.
fixEnsure 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.
fixCheck GitLab API docs; use `users.me()` instead of `users.current()` for GitLab API v4.
Audit
Dependencies
No dependency data recorded yet.