@apiclient.xyz/gitlab 2.0.2 → 2.0.3

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@apiclient.xyz/gitlab',
6
- version: '2.0.2',
6
+ version: '2.0.3',
7
7
  description: 'A TypeScript client for the GitLab API, providing easy access to projects, groups, CI/CD variables, and pipelines.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx1QkFBdUI7SUFDN0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLG9IQUFvSDtDQUNsSSxDQUFBIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apiclient.xyz/gitlab",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "private": false,
5
5
  "description": "A TypeScript client for the GitLab API, providing easy access to projects, groups, CI/CD variables, and pipelines.",
6
6
  "main": "dist_ts/index.js",
package/readme.md CHANGED
@@ -4,25 +4,291 @@ A TypeScript client for the GitLab API, providing easy access to projects, group
4
4
 
5
5
  ## Install
6
6
 
7
- ```sh
7
+ ```bash
8
8
  npm install @apiclient.xyz/gitlab
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
+ All examples below use ESM imports and async/await.
14
+
15
+ ### Creating a Client
16
+
13
17
  ```typescript
14
18
  import { GitLabClient } from '@apiclient.xyz/gitlab';
15
19
 
16
- const client = new GitLabClient('https://gitlab.com', 'your-private-token');
20
+ const client = new GitLabClient('https://gitlab.example.com', 'your-private-token');
21
+ ```
22
+
23
+ The constructor accepts the base URL of your GitLab instance and a personal access token (or project/group token) used for authentication via the `PRIVATE-TOKEN` header.
24
+
25
+ ### Testing the Connection
17
26
 
18
- // Test connection
27
+ ```typescript
19
28
  const result = await client.testConnection();
20
29
 
21
- // List projects
30
+ if (result.ok) {
31
+ console.log('Connected successfully.');
32
+ } else {
33
+ console.error('Connection failed:', result.error);
34
+ }
35
+ ```
36
+
37
+ ### Listing Projects
38
+
39
+ Retrieve projects you are a member of, ordered by most recently updated.
40
+
41
+ ```typescript
42
+ // First page, default 50 per page
22
43
  const projects = await client.getProjects();
23
44
 
24
- // Manage CI/CD variables
25
- await client.createProjectVariable(123, 'SECRET_KEY', 'secret-value');
45
+ // Search with pagination
46
+ const filtered = await client.getProjects({
47
+ search: 'my-service',
48
+ page: 1,
49
+ perPage: 20,
50
+ });
51
+
52
+ for (const project of filtered) {
53
+ console.log(`${project.id} - ${project.path_with_namespace}`);
54
+ }
55
+ ```
56
+
57
+ ### Listing Groups
58
+
59
+ ```typescript
60
+ const groups = await client.getGroups();
61
+
62
+ // Search groups by name
63
+ const matchingGroups = await client.getGroups({ search: 'platform' });
64
+
65
+ for (const group of matchingGroups) {
66
+ console.log(`${group.id} - ${group.full_path}`);
67
+ }
68
+ ```
69
+
70
+ ### Managing Project Variables
71
+
72
+ ```typescript
73
+ const projectId = 42;
74
+
75
+ // List all variables
76
+ const vars = await client.getProjectVariables(projectId);
77
+
78
+ // Create a variable
79
+ await client.createProjectVariable(projectId, 'DATABASE_URL', 'postgres://...', {
80
+ protected: true,
81
+ masked: true,
82
+ environment_scope: 'production',
83
+ });
84
+
85
+ // Update a variable
86
+ await client.updateProjectVariable(projectId, 'DATABASE_URL', 'postgres://new-host/...', {
87
+ protected: true,
88
+ });
89
+
90
+ // Delete a variable
91
+ await client.deleteProjectVariable(projectId, 'DATABASE_URL');
92
+ ```
93
+
94
+ ### Managing Group Variables
95
+
96
+ The group variable API mirrors the project variable API.
97
+
98
+ ```typescript
99
+ const groupId = 7;
100
+
101
+ // List all variables
102
+ const groupVars = await client.getGroupVariables(groupId);
103
+
104
+ // Create a variable
105
+ await client.createGroupVariable(groupId, 'NPM_TOKEN', 'tok-xxx', {
106
+ protected: false,
107
+ masked: true,
108
+ environment_scope: '*',
109
+ });
110
+
111
+ // Update a variable
112
+ await client.updateGroupVariable(groupId, 'NPM_TOKEN', 'tok-yyy', {
113
+ masked: true,
114
+ });
115
+
116
+ // Delete a variable
117
+ await client.deleteGroupVariable(groupId, 'NPM_TOKEN');
118
+ ```
119
+
120
+ ### Working with Pipelines
121
+
122
+ ```typescript
123
+ const projectId = 42;
124
+
125
+ // List recent pipelines
126
+ const pipelines = await client.getPipelines(projectId, { page: 1, perPage: 10 });
127
+
128
+ for (const pipeline of pipelines) {
129
+ console.log(`Pipeline #${pipeline.id} [${pipeline.status}] on ${pipeline.ref}`);
130
+ }
131
+
132
+ // Get jobs for a specific pipeline
133
+ const jobs = await client.getPipelineJobs(projectId, pipelines[0].id);
134
+ for (const job of jobs) {
135
+ console.log(` Job "${job.name}" (${job.stage}): ${job.status}`);
136
+ }
137
+
138
+ // Read the raw log output of a job
139
+ const log = await client.getJobLog(projectId, jobs[0].id);
140
+ console.log(log);
141
+
142
+ // Retry a failed pipeline
143
+ await client.retryPipeline(projectId, pipelines[0].id);
144
+
145
+ // Cancel a running pipeline
146
+ await client.cancelPipeline(projectId, pipelines[0].id);
147
+ ```
148
+
149
+ ## API Reference
150
+
151
+ ### `GitLabClient`
152
+
153
+ | Method | Signature | Returns | Description |
154
+ |---|---|---|---|
155
+ | `constructor` | `(baseUrl: string, token: string)` | `GitLabClient` | Create a new client instance. |
156
+ | `testConnection` | `()` | `Promise<ITestConnectionResult>` | Verify the token and connectivity. |
157
+ | `getProjects` | `(opts?: IListOptions)` | `Promise<IGitLabProject[]>` | List projects you are a member of. |
158
+ | `getGroups` | `(opts?: IListOptions)` | `Promise<IGitLabGroup[]>` | List accessible groups. |
159
+ | `getProjectVariables` | `(projectId: number \| string)` | `Promise<IGitLabVariable[]>` | List all CI/CD variables for a project. |
160
+ | `createProjectVariable` | `(projectId: number \| string, key: string, value: string, opts?: IVariableOptions)` | `Promise<IGitLabVariable>` | Create a CI/CD variable on a project. |
161
+ | `updateProjectVariable` | `(projectId: number \| string, key: string, value: string, opts?: IVariableOptions)` | `Promise<IGitLabVariable>` | Update an existing project variable. |
162
+ | `deleteProjectVariable` | `(projectId: number \| string, key: string)` | `Promise<void>` | Delete a project variable. |
163
+ | `getGroupVariables` | `(groupId: number \| string)` | `Promise<IGitLabVariable[]>` | List all CI/CD variables for a group. |
164
+ | `createGroupVariable` | `(groupId: number \| string, key: string, value: string, opts?: IVariableOptions)` | `Promise<IGitLabVariable>` | Create a CI/CD variable on a group. |
165
+ | `updateGroupVariable` | `(groupId: number \| string, key: string, value: string, opts?: IVariableOptions)` | `Promise<IGitLabVariable>` | Update an existing group variable. |
166
+ | `deleteGroupVariable` | `(groupId: number \| string, key: string)` | `Promise<void>` | Delete a group variable. |
167
+ | `getPipelines` | `(projectId: number \| string, opts?: IListOptions)` | `Promise<IGitLabPipeline[]>` | List pipelines for a project, newest first. |
168
+ | `getPipelineJobs` | `(projectId: number \| string, pipelineId: number)` | `Promise<IGitLabJob[]>` | Get all jobs for a pipeline. |
169
+ | `getJobLog` | `(projectId: number \| string, jobId: number)` | `Promise<string>` | Retrieve the raw trace/log of a job. |
170
+ | `retryPipeline` | `(projectId: number \| string, pipelineId: number)` | `Promise<void>` | Retry all failed jobs in a pipeline. |
171
+ | `cancelPipeline` | `(projectId: number \| string, pipelineId: number)` | `Promise<void>` | Cancel a running pipeline. |
172
+
173
+ ## Types
174
+
175
+ ### `IListOptions`
176
+
177
+ Pagination and search options used by `getProjects`, `getGroups`, and `getPipelines`.
178
+
179
+ ```typescript
180
+ interface IListOptions {
181
+ search?: string; // Filter results by keyword
182
+ page?: number; // Page number (default: 1)
183
+ perPage?: number; // Items per page (default: 50 for projects/groups, 30 for pipelines)
184
+ }
185
+ ```
186
+
187
+ ### `IVariableOptions`
188
+
189
+ Options when creating or updating CI/CD variables.
190
+
191
+ ```typescript
192
+ interface IVariableOptions {
193
+ protected?: boolean; // Only expose to protected branches/tags (default: false)
194
+ masked?: boolean; // Mask the value in job logs (default: false)
195
+ environment_scope?: string; // Environment scope (default: '*' for all environments)
196
+ }
197
+ ```
198
+
199
+ ### `ITestConnectionResult`
200
+
201
+ ```typescript
202
+ interface ITestConnectionResult {
203
+ ok: boolean;
204
+ error?: string; // Present when ok is false
205
+ }
206
+ ```
207
+
208
+ ### `IGitLabProject`
209
+
210
+ ```typescript
211
+ interface IGitLabProject {
212
+ id: number;
213
+ name: string;
214
+ path_with_namespace: string;
215
+ description: string;
216
+ default_branch: string;
217
+ web_url: string;
218
+ visibility: string;
219
+ topics: string[];
220
+ last_activity_at: string;
221
+ }
222
+ ```
223
+
224
+ ### `IGitLabGroup`
225
+
226
+ ```typescript
227
+ interface IGitLabGroup {
228
+ id: number;
229
+ name: string;
230
+ full_path: string;
231
+ description: string;
232
+ web_url: string;
233
+ visibility: string;
234
+ }
235
+ ```
236
+
237
+ ### `IGitLabVariable`
238
+
239
+ ```typescript
240
+ interface IGitLabVariable {
241
+ key: string;
242
+ value: string;
243
+ variable_type: string;
244
+ protected: boolean;
245
+ masked: boolean;
246
+ environment_scope: string;
247
+ }
248
+ ```
249
+
250
+ ### `IGitLabPipeline`
251
+
252
+ ```typescript
253
+ interface IGitLabPipeline {
254
+ id: number;
255
+ project_id: number;
256
+ status: string;
257
+ ref: string;
258
+ sha: string;
259
+ web_url: string;
260
+ duration: number;
261
+ created_at: string;
262
+ source: string;
263
+ }
264
+ ```
265
+
266
+ ### `IGitLabJob`
267
+
268
+ ```typescript
269
+ interface IGitLabJob {
270
+ id: number;
271
+ name: string;
272
+ stage: string;
273
+ status: string;
274
+ duration: number;
275
+ }
276
+ ```
277
+
278
+ ### `IGitLabUser`
279
+
280
+ Returned internally by `testConnection` to verify credentials.
281
+
282
+ ```typescript
283
+ interface IGitLabUser {
284
+ id: number;
285
+ username: string;
286
+ name: string;
287
+ email: string;
288
+ avatar_url: string;
289
+ web_url: string;
290
+ state: string;
291
+ }
26
292
  ```
27
293
 
28
294
  ## License
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@apiclient.xyz/gitlab',
6
- version: '2.0.2',
6
+ version: '2.0.3',
7
7
  description: 'A TypeScript client for the GitLab API, providing easy access to projects, groups, CI/CD variables, and pipelines.'
8
8
  }