@hackmd/api 2.7.0-beta.20261120073810.060eeab → 2.7.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 +11 -125
- package/dist/index.cjs +73 -430
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -148
- package/dist/index.js +73 -426
- package/dist/index.js.map +1 -1
- package/dist/type.d.ts +128 -69
- package/package.json +5 -20
- package/dist/generated/client/client.gen.d.ts +0 -2
- package/dist/generated/client/index.d.ts +0 -10
- package/dist/generated/client/types.gen.d.ts +0 -87
- package/dist/generated/client/utils.gen.d.ts +0 -14
- package/dist/generated/client.gen.d.ts +0 -12
- package/dist/generated/core/auth.gen.d.ts +0 -25
- package/dist/generated/core/bodySerializer.gen.d.ts +0 -25
- package/dist/generated/core/params.gen.d.ts +0 -43
- package/dist/generated/core/pathSerializer.gen.d.ts +0 -33
- package/dist/generated/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/generated/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/generated/core/types.gen.d.ts +0 -83
- package/dist/generated/core/utils.gen.d.ts +0 -19
- package/dist/generated/index.d.ts +0 -2
- package/dist/generated/operationRegistry.gen.d.ts +0 -1323
- package/dist/generated/sdk.gen.d.ts +0 -274
- package/dist/generated/types.gen.d.ts +0 -2962
- package/dist/raw.cjs +0 -132
- package/dist/raw.cjs.map +0 -1
- package/dist/raw.d.ts +0 -15
- package/dist/raw.js +0 -69
- package/dist/raw.js.map +0 -1
- package/dist/sdk.gen-0nBaZJhE.js +0 -1286
- package/dist/sdk.gen-0nBaZJhE.js.map +0 -1
- package/dist/sdk.gen-COYJyg7W.cjs +0 -1349
- package/dist/sdk.gen-COYJyg7W.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -87,13 +87,10 @@ const client = new HackMDAPI('YOUR_ACCESS_TOKEN', 'https://api.hackmd.io/v1', {
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
The client will automatically retry requests that fail with:
|
|
90
|
-
|
|
91
90
|
- 5xx server errors
|
|
92
91
|
- 429 Too Many Requests errors
|
|
93
92
|
- Network errors
|
|
94
93
|
|
|
95
|
-
POST, PATCH, and trash restore operations are never retried automatically.
|
|
96
|
-
|
|
97
94
|
### Response Data Handling
|
|
98
95
|
|
|
99
96
|
By default, the client automatically unwraps the response data from the Axios response object. You can control this behavior using the `unwrapData` option:
|
|
@@ -106,32 +103,18 @@ const response = await client.getMe({ unwrapData: false })
|
|
|
106
103
|
const data = await client.getMe({ unwrapData: true })
|
|
107
104
|
```
|
|
108
105
|
|
|
109
|
-
`createNote` and `createTeamNote` also include `status` and optional `etag` in the unwrapped result. For `status === 207`, the note was created but folder placement failed; use `result.note` and `result.error` rather than retrying creation.
|
|
110
|
-
|
|
111
106
|
### ETag Support
|
|
112
107
|
|
|
113
|
-
The client can
|
|
114
|
-
generates the ETag and decides whether to return 304; the client does not cache
|
|
115
|
-
the note body for you:
|
|
108
|
+
The client supports ETag-based caching for note retrieval. You can pass an ETag to check if the content has changed:
|
|
116
109
|
|
|
117
110
|
```javascript
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
unwrapData: false,
|
|
122
|
-
})
|
|
123
|
-
// 304 has no body; keep first.data. Otherwise, use response.data.
|
|
124
|
-
const note = response.status === 304 ? first.data : response.data
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Team notes work the same way through the existing client:
|
|
111
|
+
// First request
|
|
112
|
+
const note = await client.getNote('note-id')
|
|
113
|
+
const etag = note.etag
|
|
128
114
|
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
etag: teamFirst.etag,
|
|
133
|
-
})
|
|
134
|
-
const teamNote = teamResponse.status === 304 ? teamFirst : teamResponse
|
|
115
|
+
// Subsequent request with ETag
|
|
116
|
+
const updatedNote = await client.getNote('note-id', { etag })
|
|
117
|
+
// If the note hasn't changed, the response will have status 304
|
|
135
118
|
```
|
|
136
119
|
|
|
137
120
|
### Image Upload
|
|
@@ -151,117 +134,20 @@ const uploadedFromNode = await client.uploadNoteImage('note-id', image, {
|
|
|
151
134
|
console.log(uploadedFromNode.data.link)
|
|
152
135
|
```
|
|
153
136
|
|
|
154
|
-
### Webhooks
|
|
155
|
-
|
|
156
|
-
Manage personal or team webhooks through the same `API` client. Save the secret
|
|
157
|
-
returned by `createWebhook` when you create a webhook; later reads do not return it.
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
const webhook = await client.createWebhook({
|
|
161
|
-
scope: { type: 'workspace' },
|
|
162
|
-
url: 'https://example.com/webhook',
|
|
163
|
-
})
|
|
164
|
-
console.log(webhook.secret)
|
|
165
|
-
|
|
166
|
-
const teamWebhooks = await client.listTeamWebhooks('team-path')
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
`listWebhookDeliveries('hook-id', { page: 1, limit: 20 })` returns delivery data
|
|
170
|
-
and pagination metadata. `exportWebhookDeliveries('hook-id')` returns
|
|
171
|
-
newline-delimited JSON as a string; parse the lines yourself if needed.
|
|
172
|
-
|
|
173
|
-
### Trash
|
|
174
|
-
|
|
175
|
-
Use `listTrash()` or `listTeamTrash('team-path')` to find deleted notes.
|
|
176
|
-
`restoreNote('note-id')` restores one note; `batchRestore({ noteIds })` reports
|
|
177
|
-
success or failure for each note. Pass `{ unwrapData: false }` to inspect the
|
|
178
|
-
batch HTTP status (200 or 207).
|
|
179
|
-
|
|
180
|
-
### Versions
|
|
181
|
-
|
|
182
|
-
`listVersions('note-id', { named_only: true, page: 1, limit: 20 })` lists saved
|
|
183
|
-
versions. Use `getVersion('note-id', versionId)` for content, or
|
|
184
|
-
`compareVersions('note-id', { base: 'version:<id>', target: 'note_content' })`
|
|
185
|
-
to compare it with the live note. `createVersion` and `updateVersion` accept the
|
|
186
|
-
corresponding OpenAPI request bodies.
|
|
187
|
-
|
|
188
|
-
### Comments
|
|
189
|
-
|
|
190
|
-
Use `listNoteComments('note-id', { page: 1, limit: 20, threadStatus: 'open' })`
|
|
191
|
-
to browse comments. `getNoteComment('note-id', commentId)` reads one comment;
|
|
192
|
-
`resolveNoteComment` and `unresolveNoteComment` return the updated comment and
|
|
193
|
-
any affected thread.
|
|
194
|
-
|
|
195
|
-
### Generated Raw API
|
|
196
|
-
|
|
197
|
-
The `@hackmd/api/raw` entry point exposes every OpenAPI operation as a generated,
|
|
198
|
-
one-to-one function. Create a client to share authentication and the API endpoint:
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
import { createClient, getNote } from '@hackmd/api/raw'
|
|
202
|
-
|
|
203
|
-
const client = createClient({
|
|
204
|
-
auth: 'YOUR_ACCESS_TOKEN',
|
|
205
|
-
baseURL: 'https://api.hackmd.io/v1',
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
const response = await getNote({
|
|
209
|
-
client,
|
|
210
|
-
path: { noteId: 'NOTE_ID' },
|
|
211
|
-
throwOnError: true,
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
console.log(response.data.content)
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
The package root retains the existing `API` class. Files under
|
|
218
|
-
`src/generated` are generated from the vendored OpenAPI document and must not
|
|
219
|
-
be edited manually.
|
|
220
|
-
|
|
221
|
-
On `API`, `listNotes`, `listFolders`, `listTeamNotes`, `listTeamFolders`, and
|
|
222
|
-
`listTeams` match the OpenAPI operation names. Existing `getNoteList`,
|
|
223
|
-
`getFolderList`, `getTeamNotes`, `getTeamFolderList`, and `getTeams` remain
|
|
224
|
-
compatible aliases.
|
|
225
|
-
|
|
226
137
|
## API
|
|
227
138
|
|
|
228
|
-
|
|
229
|
-
`API` class and every raw operation and DTO. To explore autocomplete
|
|
230
|
-
without a real token, open the type-only example:
|
|
231
|
-
|
|
232
|
-
[](https://stackblitz.com/fork/github/hackmdio/api-client/tree/master/nodejs?file=tests/types/playground.mts)
|
|
233
|
-
|
|
234
|
-
The Pages site is deployed from `master` only.
|
|
235
|
-
|
|
236
|
-
Run `pnpm docs:dev` from `nodejs` and open `http://127.0.0.1:3000` to preview
|
|
237
|
-
the reference locally. It builds the HTML once before serving; rerun the
|
|
238
|
-
command after changing source or docs. The output in `.docs-dist` is not
|
|
239
|
-
committed.
|
|
240
|
-
|
|
241
|
-
## Regenerating the raw client
|
|
242
|
-
|
|
243
|
-
Generation requires Node.js 22.18 or newer.
|
|
244
|
-
|
|
245
|
-
```bash
|
|
246
|
-
pnpm spec:pull
|
|
247
|
-
pnpm codegen
|
|
248
|
-
pnpm check:generated
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
The OpenAPI document is committed at `spec/hackmd-openapi.json`, and generated
|
|
252
|
-
sources are committed under `src/generated` so package builds remain offline and
|
|
253
|
-
deterministic.
|
|
139
|
+
See the [code](./src/index.ts) and [typings](./src/type.ts). The API client is written in TypeScript, so you can get auto-completion and type checking in any TypeScript Language Server powered editor or IDE.
|
|
254
140
|
|
|
255
141
|
## E2E tests (live API)
|
|
256
142
|
|
|
257
143
|
Integration tests call a real HackMD API (staging or production). They are **not** run by `pnpm test` or the default CI job.
|
|
258
144
|
|
|
259
|
-
|
|
145
|
+
**Requirements**
|
|
260
146
|
|
|
261
147
|
- `HACKMD_ACCESS_TOKEN` — a valid personal access token for the environment you target.
|
|
262
148
|
- Optional: `HACKMD_API_ENDPOINT` — defaults to `https://api.hackmd.io/v1`. For staging, use `https://api-stage.hackmd.io/v1`.
|
|
263
149
|
|
|
264
|
-
|
|
150
|
+
**Read-only (default e2e)**
|
|
265
151
|
|
|
266
152
|
```bash
|
|
267
153
|
cd nodejs
|
|
@@ -270,7 +156,7 @@ export HACKMD_API_ENDPOINT=https://api-stage.hackmd.io/v1 # optional
|
|
|
270
156
|
pnpm test:e2e
|
|
271
157
|
```
|
|
272
158
|
|
|
273
|
-
|
|
159
|
+
**With CRUD / mutations**
|
|
274
160
|
|
|
275
161
|
Set `HACKMD_E2E_MUTATIONS=1` to run write tests against your account:
|
|
276
162
|
|