@llamaduck/forgejo-ts 11.0.10 → 14.0.2-1

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 CHANGED
@@ -16,141 +16,139 @@ pnpm add @llamaduck/forgejo-ts
16
16
 
17
17
  ## Usage
18
18
 
19
- ### Basic Configuration
19
+ ### Basic Usage
20
+
21
+ Create a client and start making API calls:
20
22
 
21
23
  ```typescript
22
- import { configure, RepositoryService, UserService } from '@llamaduck/forgejo-ts';
24
+ import { createClient, createConfig, getVersion, repoSearch } from '@llamaduck/forgejo-ts';
25
+
26
+ // Create a client
27
+ const client = createClient(createConfig({
28
+ baseUrl: 'https://codeberg.org/api/v1',
29
+ headers: { Authorization: 'token your-api-token' }
30
+ }));
23
31
 
24
- // Configure the client
25
- configure({
26
- baseUrl: 'https://your-forgejo-instance.com/api/v1',
27
- token: 'your-api-token', // Optional: for authenticated requests
28
- });
32
+ // Make API calls - pass the client in options
33
+ const version = await getVersion({ client });
34
+ console.log('Server version:', version.data?.version);
29
35
 
30
- // Now use any service
31
- const repos = await RepositoryService.repoSearch({ q: 'hello' });
32
- console.log(repos);
36
+ const repos = await repoSearch({ query: { q: 'typescript', limit: 10 } }, { client });
37
+ console.log('Found repos:', repos.data);
33
38
  ```
34
39
 
35
- ### Authentication Options
40
+ ### Multiple Clients
41
+
42
+ You can create multiple independent client instances:
36
43
 
37
44
  ```typescript
38
- import { configure } from '@llamaduck/forgejo-ts';
45
+ import { createClient, createConfig, repoSearch } from '@llamaduck/forgejo-ts';
39
46
 
40
- // Token authentication (recommended)
41
- configure({
42
- baseUrl: 'https://your-forgejo-instance.com/api/v1',
43
- token: 'your-personal-access-token',
44
- });
47
+ const clientA = createClient(createConfig({
48
+ baseUrl: 'https://codeberg.org/api/v1',
49
+ headers: { Authorization: 'token token-a' }
50
+ }));
45
51
 
46
- // Basic authentication
47
- configure({
48
- baseUrl: 'https://your-forgejo-instance.com/api/v1',
49
- username: 'your-username',
50
- password: 'your-password',
51
- });
52
- ```
52
+ const clientB = createClient(createConfig({
53
+ baseUrl: 'https://gitea.com/api/v1',
54
+ headers: { Authorization: 'token token-b' }
55
+ }));
53
56
 
54
- ### Direct OpenAPI Configuration
57
+ // Use different clients for different requests
58
+ const reposA = await repoSearch({ query: { q: 'test' } }, { client: clientA });
59
+ const reposB = await repoSearch({ query: { q: 'test' } }, { client: clientB });
60
+ ```
55
61
 
56
- For more control, you can configure the OpenAPI object directly:
62
+ ### Authentication
57
63
 
58
64
  ```typescript
59
- import { OpenAPI } from '@llamaduck/forgejo-ts';
65
+ import { createClient, createConfig } from '@llamaduck/forgejo-ts';
60
66
 
61
- OpenAPI.BASE = 'https://your-forgejo-instance.com/api/v1';
62
- OpenAPI.TOKEN = 'your-api-token';
67
+ // Token authentication (recommended)
68
+ const client = createClient(createConfig({
69
+ baseUrl: 'https://codeberg.org/api/v1',
70
+ headers: { Authorization: 'token your-personal-access-token' }
71
+ }));
63
72
 
64
- // Or use a function for dynamic token retrieval
65
- OpenAPI.TOKEN = async () => {
66
- return getTokenFromSomewhere();
67
- };
73
+ // Basic authentication
74
+ const auth = btoa('username:password');
75
+ const client = createClient(createConfig({
76
+ baseUrl: 'https://codeberg.org/api/v1',
77
+ headers: { Authorization: `Basic ${auth}` }
78
+ }));
68
79
  ```
69
80
 
70
- ### Using Services
81
+ ## API Reference
71
82
 
72
- All API endpoints are organized into services:
83
+ All API functions are exported directly from the package:
73
84
 
74
85
  ```typescript
75
86
  import {
76
- RepositoryService,
77
- UserService,
78
- OrganizationService,
79
- IssueService,
80
- AdminService,
81
- // ... and more
87
+ // Repositories
88
+ repoSearch,
89
+ repoGet,
90
+ userListRepos,
91
+
92
+ // Users
93
+ userGetCurrent,
94
+ userGet,
95
+
96
+ // Issues
97
+ issueSearch,
98
+ issueCreateIssue,
99
+
100
+ // Organizations
101
+ orgGet,
102
+
103
+ // And many more...
82
104
  } from '@llamaduck/forgejo-ts';
83
-
84
- // Get current user
85
- const user = await UserService.userGetCurrent();
86
-
87
- // List repositories
88
- const repos = await RepositoryService.repoSearch({
89
- q: 'typescript',
90
- limit: 10,
91
- });
92
-
93
- // Create an issue
94
- const issue = await IssueService.issueCreateIssue({
95
- owner: 'username',
96
- repo: 'repo-name',
97
- body: {
98
- title: 'Bug report',
99
- body: 'Description of the bug',
100
- },
101
- });
102
105
  ```
103
106
 
104
- ### Error Handling
107
+ Each function accepts:
108
+ 1. **Data/params** - The request data (path params, query params, body)
109
+ 2. **Options** (optional) - Request options including the `client` instance
105
110
 
111
+ Example:
106
112
  ```typescript
107
- import { ApiError, RepositoryService } from '@llamaduck/forgejo-ts';
113
+ // Search repositories
114
+ const repos = await repoSearch(
115
+ { query: { q: 'typescript', limit: 10 } },
116
+ { client }
117
+ );
118
+
119
+ // Get a specific repository
120
+ const repo = await repoGet(
121
+ { path: { owner: 'forgejo', repo: 'forgejo' } },
122
+ { client }
123
+ );
108
124
 
109
- try {
110
- const repo = await RepositoryService.repoGet({
111
- owner: 'user',
112
- repo: 'nonexistent',
113
- });
114
- } catch (error) {
115
- if (error instanceof ApiError) {
116
- console.error('API Error:', error.status, error.message);
117
- console.error('Response body:', error.body);
118
- }
119
- }
125
+ // Create an issue
126
+ const issue = await issueCreateIssue(
127
+ { path: { owner: 'user', repo: 'repo' } },
128
+ { body: { title: 'Bug report', body: 'Description' } },
129
+ { client }
130
+ );
120
131
  ```
121
132
 
122
- ### Canceling Requests
133
+ ### Error Handling
123
134
 
124
135
  ```typescript
125
- import { RepositoryService, CancelError } from '@llamaduck/forgejo-ts';
126
-
127
- const request = RepositoryService.repoSearch({ q: 'test' });
128
-
129
- // Cancel the request
130
- request.cancel();
136
+ import { repoGet } from '@llamaduck/forgejo-ts';
131
137
 
132
138
  try {
133
- await request;
139
+ const repo = await repoGet(
140
+ { path: { owner: 'user', repo: 'nonexistent' } },
141
+ { client }
142
+ );
134
143
  } catch (error) {
135
- if (error instanceof CancelError) {
136
- console.log('Request was canceled');
144
+ if (error.status === 404) {
145
+ console.error('Repository not found');
146
+ } else {
147
+ console.error('API Error:', error);
137
148
  }
138
149
  }
139
150
  ```
140
151
 
141
- ## Available Services
142
-
143
- - `ActivitypubService` - ActivityPub federation endpoints
144
- - `AdminService` - Administration endpoints (requires admin access)
145
- - `IssueService` - Issues and pull requests
146
- - `MiscellaneousService` - Miscellaneous endpoints (version, settings, etc.)
147
- - `NotificationService` - User notifications
148
- - `OrganizationService` - Organizations and teams
149
- - `PackageService` - Package registry
150
- - `RepositoryService` - Repositories, branches, commits, files
151
- - `SettingsService` - Instance settings
152
- - `UserService` - Users, followers, tokens, keys
153
-
154
152
  ## Version Information
155
153
 
156
154
  ```typescript
@@ -189,8 +187,6 @@ FORGEJO_VERSION=14.0.2 npm run generate
189
187
  npm run build
190
188
  ```
191
189
 
192
- The script fetches the Swagger spec directly from Codeberg.
193
-
194
190
  ## Configuration
195
191
 
196
192
  The `config.json` file specifies which major versions to track: