@cesar-richard/git-connector-sdk 1.21.0 → 1.22.0
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 +169 -14
- package/dist/index.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,45 +1,200 @@
|
|
|
1
1
|
# @cesar-richard/git-connector-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@cesar-richard/git-connector-sdk)
|
|
4
|
+
[](https://github.com/cesar-richard-ei/git-connector/blob/main/LICENSE)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
TypeScript SDK for [**git-connector**](https://github.com/cesar-richard-ei/git-connector) — a server that aggregates GitHub + GitLab activity (PRs, MRs, issues, commits, comments, reviews, CI runs) and exposes a unified, ticket-correlated read API.
|
|
7
|
+
|
|
8
|
+
This SDK is a thin, fully-typed wrapper around the server's `/v1/*` HTTP API, generated from its OpenAPI spec via [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/).
|
|
9
|
+
|
|
10
|
+
> **Version policy:** the SDK version always tracks the git-connector server release it was generated against. Pinning the same major+minor as your server is recommended.
|
|
11
|
+
|
|
12
|
+
---
|
|
6
13
|
|
|
7
14
|
## Install
|
|
8
15
|
|
|
9
16
|
```bash
|
|
10
17
|
npm install @cesar-richard/git-connector-sdk
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @cesar-richard/git-connector-sdk
|
|
20
|
+
# or
|
|
21
|
+
bun add @cesar-richard/git-connector-sdk
|
|
11
22
|
```
|
|
12
23
|
|
|
13
|
-
##
|
|
24
|
+
## Quick start
|
|
14
25
|
|
|
15
26
|
```ts
|
|
16
27
|
import { createGitConnectorClient } from "@cesar-richard/git-connector-sdk";
|
|
17
28
|
|
|
18
29
|
const client = createGitConnectorClient({
|
|
19
30
|
baseUrl: "https://git-connector.example.com",
|
|
20
|
-
token: process.env.GIT_CONNECTOR_TOKEN!,
|
|
31
|
+
token: process.env.GIT_CONNECTOR_TOKEN!, // gck_…
|
|
21
32
|
});
|
|
22
33
|
|
|
23
34
|
const { data, error } = await client.GET("/v1/work-items", {
|
|
24
35
|
params: { query: { state: "open", iteration: "current" } },
|
|
25
36
|
});
|
|
26
37
|
|
|
27
|
-
if (error) throw new Error(`
|
|
28
|
-
|
|
38
|
+
if (error) throw new Error(`git-connector error: ${JSON.stringify(error)}`);
|
|
39
|
+
|
|
40
|
+
for (const item of data.items) {
|
|
41
|
+
console.log(`${item.source}/${item.projectKey}#${item.number} — ${item.title}`);
|
|
42
|
+
for (const pr of item.linkedActivities) {
|
|
43
|
+
console.log(` ↳ ${pr.type.toUpperCase()} ${pr.url} (${pr.state})`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The client is fully typed: request params, query strings, and response bodies are all derived from the server's OpenAPI schema. Hover any field in your editor to see its shape.
|
|
49
|
+
|
|
50
|
+
## Authentication
|
|
51
|
+
|
|
52
|
+
The SDK sends `Authorization: Bearer <token>` on every request. Mint a token from the git-connector control UI or via:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
curl -X POST https://git-connector.example.com/admin/api-keys \
|
|
56
|
+
-H "Content-Type: application/json" \
|
|
57
|
+
-d '{"name":"my-integration"}'
|
|
58
|
+
# → { "token": "gck_…", "id": 12, "name": "my-integration", "createdAt": "…" }
|
|
29
59
|
```
|
|
30
60
|
|
|
31
|
-
|
|
61
|
+
Tokens with the `gck_` prefix are immutable once minted; revoke and reissue via the same endpoint.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## API surface
|
|
66
|
+
|
|
67
|
+
The `/v1/*` API exposes three resources:
|
|
68
|
+
|
|
69
|
+
### `GET /v1/work-items` — list aggregated work items
|
|
70
|
+
|
|
71
|
+
Issues from GitHub + GitLab, with linked PRs/MRs resolved server-side via ticket-reference correlation. Filter by `state`, `iteration` (id or `"current"`), `assignee`, `label`, `source`.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const { data } = await client.GET("/v1/work-items", {
|
|
75
|
+
params: {
|
|
76
|
+
query: {
|
|
77
|
+
state: "open",
|
|
78
|
+
iteration: "current",
|
|
79
|
+
assignee: "alice",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
// data: { items: WorkItem[]; total: number; limit: number }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Each `WorkItem` includes its `linkedActivities` (PRs/MRs with full enrichment: reviews summary, unresolved threads, volume, status history, reviewRequestedAt, mergedAt).
|
|
87
|
+
|
|
88
|
+
### `GET /v1/work-items/{source}/{projectKey}/{number}` — detail
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const { data } = await client.GET(
|
|
92
|
+
"/v1/work-items/{source}/{projectKey}/{number}",
|
|
93
|
+
{ params: { path: { source: "gitlab", projectKey: "acme/ops", number: 42 } } },
|
|
94
|
+
);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `GET /v1/iterations` — list iterations
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const { data } = await client.GET("/v1/iterations");
|
|
101
|
+
// data: IterationWithCount[] — each carries workItemCount across all linked WorkItems
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### `GET /v1/events` — unified activity stream
|
|
105
|
+
|
|
106
|
+
Daily-bucketed (Paris-TZ) chronological event stream. Mixes commits, comments, reviews, state-transitions, and CI runs across both providers. Cursor-paginated.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const { data } = await client.GET("/v1/events", {
|
|
110
|
+
params: {
|
|
111
|
+
query: {
|
|
112
|
+
from: "2026-05-01",
|
|
113
|
+
to: "2026-05-17",
|
|
114
|
+
type: "ci-run,review", // CSV
|
|
115
|
+
user: "alice",
|
|
116
|
+
limit: "200",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
// data: { events: GitEvent[]; total: number; nextCursor: string | null }
|
|
121
|
+
|
|
122
|
+
// Paginate:
|
|
123
|
+
if (data.nextCursor) {
|
|
124
|
+
const { data: next } = await client.GET("/v1/events", {
|
|
125
|
+
params: { query: { from: "2026-05-01", to: "2026-05-17", cursor: data.nextCursor } },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Event types in the stream:
|
|
131
|
+
|
|
132
|
+
| `type` | Source | `parentActivityId` | Notable `meta` keys |
|
|
133
|
+
|--------|--------|--------------------|---------------------|
|
|
134
|
+
| `commit` | Default branch | null | `fullMessage` |
|
|
135
|
+
| `comment` | Issue/PR/MR notes | resolves to PR/MR/issue | `body` |
|
|
136
|
+
| `review` | GH PR review / GL MR approval | resolves to PR/MR | `state`, `reviewer` |
|
|
137
|
+
| `state-transition` | Derived from activity state diff | resolves to PR/MR/issue | `from`, `to` |
|
|
138
|
+
| `ci-run` | GH Actions job / GL pipeline job | resolves to PR/MR via head SHA | `runId`, `jobName`, `conclusion`, `durationSec`, `sha`, `branch` |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Schema as a separate import
|
|
143
|
+
|
|
144
|
+
If you need the raw OpenAPI types without the client (e.g. for codegen or for non-`openapi-fetch` consumers), import directly:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import type { components } from "@cesar-richard/git-connector-sdk/schema";
|
|
148
|
+
|
|
149
|
+
type WorkItem = components["schemas"]["WorkItem"];
|
|
150
|
+
type GitEvent = components["schemas"]["GitEvent"];
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The full OpenAPI document is also published in the package — see [`openapi.json`](https://github.com/cesar-richard-ei/git-connector/blob/main/packages/sdk/openapi.json) for the contract.
|
|
154
|
+
|
|
155
|
+
## Error handling
|
|
156
|
+
|
|
157
|
+
`openapi-fetch` never throws on HTTP-level errors — it returns `{ data, error, response }`. Always check `error` before using `data`:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const { data, error, response } = await client.GET("/v1/work-items");
|
|
161
|
+
if (error) {
|
|
162
|
+
if (response.status === 401) throw new Error("Missing/invalid gck_ token");
|
|
163
|
+
if (response.status === 403) throw new Error("Token revoked");
|
|
164
|
+
throw new Error(`git-connector ${response.status}: ${JSON.stringify(error)}`);
|
|
165
|
+
}
|
|
166
|
+
// data is non-null and fully typed from here
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Network errors (DNS, timeout, connection refused) reject the promise as usual.
|
|
170
|
+
|
|
171
|
+
## Custom fetch
|
|
172
|
+
|
|
173
|
+
Pass your own `fetch` implementation to wire up retries, telemetry, or a non-global fetch (e.g. inside Cloudflare Workers):
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { fetch as undiciFetch } from "undici";
|
|
177
|
+
|
|
178
|
+
const client = createGitConnectorClient({
|
|
179
|
+
baseUrl: "https://git-connector.example.com",
|
|
180
|
+
token: process.env.GIT_CONNECTOR_TOKEN!,
|
|
181
|
+
fetch: undiciFetch,
|
|
182
|
+
});
|
|
183
|
+
```
|
|
32
184
|
|
|
33
|
-
|
|
185
|
+
## Compatibility
|
|
34
186
|
|
|
35
|
-
|
|
187
|
+
- Node ≥ 18 (uses global `fetch`).
|
|
188
|
+
- Bun ≥ 1.0.
|
|
189
|
+
- Modern browsers (no Node-only APIs).
|
|
190
|
+
- ESM only.
|
|
36
191
|
|
|
37
|
-
|
|
38
|
-
- `GET /v1/work-items/{source}/{projectKey}/{number}` — detail
|
|
39
|
-
- `GET /v1/iterations` — list iterations with work-item counts
|
|
192
|
+
## Related
|
|
40
193
|
|
|
41
|
-
|
|
194
|
+
- **Server / control UI:** [git-connector](https://github.com/cesar-richard-ei/git-connector)
|
|
195
|
+
- **OpenAPI spec:** ships with this package as [`openapi.json`](https://github.com/cesar-richard-ei/git-connector/blob/main/packages/sdk/openapi.json) — generated server-side, the SDK types derive from it via `openapi-typescript`.
|
|
196
|
+
- **Releases:** SDK and server release in lockstep via semantic-release on every merge to `main`.
|
|
42
197
|
|
|
43
198
|
## License
|
|
44
199
|
|
|
45
|
-
MIT
|
|
200
|
+
[MIT](https://github.com/cesar-richard-ei/git-connector/blob/main/LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import createClient from "openapi-fetch";
|
|
2
2
|
export function createGitConnectorClient(opts) {
|
|
3
|
+
if (!opts.baseUrl) {
|
|
4
|
+
throw new Error("createGitConnectorClient: baseUrl is required");
|
|
5
|
+
}
|
|
6
|
+
if (!opts.token) {
|
|
7
|
+
throw new Error("createGitConnectorClient: token is required (mint via POST /admin/api-keys)");
|
|
8
|
+
}
|
|
3
9
|
const client = createClient({
|
|
4
10
|
baseUrl: opts.baseUrl.replace(/\/$/, ""),
|
|
5
11
|
fetch: opts.fetch,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cesar-richard/git-connector-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "TypeScript SDK for the git-connector v1 API (work items + iterations aggregated from GitHub/GitLab). Version published on npm tracks server releases.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|