@lifestreamdynamics/vault-sdk 1.0.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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1121 -0
  3. package/dist/client.d.ts +143 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +286 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/errors.d.ts +28 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +49 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/handle-error.d.ts +8 -0
  12. package/dist/handle-error.d.ts.map +1 -0
  13. package/dist/handle-error.js +35 -0
  14. package/dist/handle-error.js.map +1 -0
  15. package/dist/index.d.ts +32 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +26 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lib/audit-logger.d.ts +29 -0
  20. package/dist/lib/audit-logger.d.ts.map +1 -0
  21. package/dist/lib/audit-logger.js +99 -0
  22. package/dist/lib/audit-logger.js.map +1 -0
  23. package/dist/lib/encryption.d.ts +34 -0
  24. package/dist/lib/encryption.d.ts.map +1 -0
  25. package/dist/lib/encryption.js +87 -0
  26. package/dist/lib/encryption.js.map +1 -0
  27. package/dist/lib/signature.d.ts +47 -0
  28. package/dist/lib/signature.d.ts.map +1 -0
  29. package/dist/lib/signature.js +71 -0
  30. package/dist/lib/signature.js.map +1 -0
  31. package/dist/lib/token-manager.d.ts +80 -0
  32. package/dist/lib/token-manager.d.ts.map +1 -0
  33. package/dist/lib/token-manager.js +116 -0
  34. package/dist/lib/token-manager.js.map +1 -0
  35. package/dist/resources/admin.d.ts +280 -0
  36. package/dist/resources/admin.d.ts.map +1 -0
  37. package/dist/resources/admin.js +236 -0
  38. package/dist/resources/admin.js.map +1 -0
  39. package/dist/resources/ai.d.ts +184 -0
  40. package/dist/resources/ai.d.ts.map +1 -0
  41. package/dist/resources/ai.js +179 -0
  42. package/dist/resources/ai.js.map +1 -0
  43. package/dist/resources/api-keys.d.ts +172 -0
  44. package/dist/resources/api-keys.d.ts.map +1 -0
  45. package/dist/resources/api-keys.js +166 -0
  46. package/dist/resources/api-keys.js.map +1 -0
  47. package/dist/resources/connectors.d.ts +263 -0
  48. package/dist/resources/connectors.d.ts.map +1 -0
  49. package/dist/resources/connectors.js +226 -0
  50. package/dist/resources/connectors.js.map +1 -0
  51. package/dist/resources/documents.d.ts +334 -0
  52. package/dist/resources/documents.d.ts.map +1 -0
  53. package/dist/resources/documents.js +377 -0
  54. package/dist/resources/documents.js.map +1 -0
  55. package/dist/resources/hooks.d.ts +195 -0
  56. package/dist/resources/hooks.d.ts.map +1 -0
  57. package/dist/resources/hooks.js +166 -0
  58. package/dist/resources/hooks.js.map +1 -0
  59. package/dist/resources/publish.d.ts +165 -0
  60. package/dist/resources/publish.d.ts.map +1 -0
  61. package/dist/resources/publish.js +150 -0
  62. package/dist/resources/publish.js.map +1 -0
  63. package/dist/resources/search.d.ts +94 -0
  64. package/dist/resources/search.d.ts.map +1 -0
  65. package/dist/resources/search.js +76 -0
  66. package/dist/resources/search.js.map +1 -0
  67. package/dist/resources/shares.d.ts +130 -0
  68. package/dist/resources/shares.d.ts.map +1 -0
  69. package/dist/resources/shares.js +115 -0
  70. package/dist/resources/shares.js.map +1 -0
  71. package/dist/resources/subscription.d.ts +172 -0
  72. package/dist/resources/subscription.d.ts.map +1 -0
  73. package/dist/resources/subscription.js +166 -0
  74. package/dist/resources/subscription.js.map +1 -0
  75. package/dist/resources/teams.d.ts +356 -0
  76. package/dist/resources/teams.d.ts.map +1 -0
  77. package/dist/resources/teams.js +395 -0
  78. package/dist/resources/teams.js.map +1 -0
  79. package/dist/resources/user.d.ts +92 -0
  80. package/dist/resources/user.d.ts.map +1 -0
  81. package/dist/resources/user.js +64 -0
  82. package/dist/resources/user.js.map +1 -0
  83. package/dist/resources/vaults.d.ts +144 -0
  84. package/dist/resources/vaults.d.ts.map +1 -0
  85. package/dist/resources/vaults.js +158 -0
  86. package/dist/resources/vaults.js.map +1 -0
  87. package/dist/resources/webhooks.d.ts +187 -0
  88. package/dist/resources/webhooks.d.ts.map +1 -0
  89. package/dist/resources/webhooks.js +171 -0
  90. package/dist/resources/webhooks.js.map +1 -0
  91. package/dist/types/api.d.ts +17 -0
  92. package/dist/types/api.d.ts.map +1 -0
  93. package/dist/types/api.js +2 -0
  94. package/dist/types/api.js.map +1 -0
  95. package/dist/types/index.d.ts +3 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/types/index.js +2 -0
  98. package/dist/types/index.js.map +1 -0
  99. package/dist/types/resources.d.ts +5 -0
  100. package/dist/types/resources.d.ts.map +1 -0
  101. package/dist/types/resources.js +2 -0
  102. package/dist/types/resources.js.map +1 -0
  103. package/package.json +58 -0
@@ -0,0 +1,377 @@
1
+ import { handleError } from '../handle-error.js';
2
+ import { encrypt, decrypt } from '../lib/encryption.js';
3
+ /**
4
+ * Resource for managing documents within vaults.
5
+ *
6
+ * Documents are Markdown files stored in vaults. Each document has a file
7
+ * path relative to the vault root and must end with `.md`. The API supports
8
+ * CRUD operations as well as move and copy.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const docs = await client.documents.list('vault-uuid');
13
+ * const doc = await client.documents.get('vault-uuid', 'notes/todo.md');
14
+ * console.log(doc.content);
15
+ * ```
16
+ */
17
+ export class DocumentsResource {
18
+ http;
19
+ constructor(http) {
20
+ this.http = http;
21
+ }
22
+ /**
23
+ * Lists documents in a vault, optionally filtered by directory.
24
+ *
25
+ * @param vaultId - The vault ID to list documents from
26
+ * @param dirPath - Optional directory path to filter results (e.g., `'notes/'`)
27
+ * @returns Array of document summary objects
28
+ * @throws {NotFoundError} If the vault does not exist
29
+ * @throws {AuthenticationError} If the request is not authenticated
30
+ * @throws {NetworkError} If the request fails due to network issues
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // List all documents
35
+ * const docs = await client.documents.list('vault-uuid');
36
+ *
37
+ * // List documents in a subdirectory
38
+ * const notes = await client.documents.list('vault-uuid', 'notes/');
39
+ * ```
40
+ */
41
+ async list(vaultId, dirPath) {
42
+ try {
43
+ const searchParams = {};
44
+ if (dirPath)
45
+ searchParams.dir = dirPath;
46
+ const data = await this.http.get(`vaults/${vaultId}/documents`, { searchParams }).json();
47
+ return data.documents;
48
+ }
49
+ catch (error) {
50
+ throw await handleError(error, 'Documents', vaultId);
51
+ }
52
+ }
53
+ /**
54
+ * Retrieves a document's metadata and full Markdown content.
55
+ *
56
+ * @param vaultId - The vault ID containing the document
57
+ * @param docPath - File path relative to vault root (e.g., `'notes/todo.md'`)
58
+ * @returns The document metadata and raw Markdown content
59
+ * @throws {NotFoundError} If the vault or document does not exist
60
+ * @throws {AuthenticationError} If the request is not authenticated
61
+ * @throws {NetworkError} If the request fails due to network issues
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const { document, content } = await client.documents.get(
66
+ * 'vault-uuid',
67
+ * 'notes/todo.md'
68
+ * );
69
+ * console.log(document.title, content);
70
+ * ```
71
+ */
72
+ async get(vaultId, docPath) {
73
+ try {
74
+ return await this.http.get(`vaults/${vaultId}/documents/${docPath}`).json();
75
+ }
76
+ catch (error) {
77
+ throw await handleError(error, 'Document', docPath);
78
+ }
79
+ }
80
+ /**
81
+ * Creates or updates a document (upsert).
82
+ *
83
+ * If a document already exists at the given path, it is updated only when
84
+ * the content has changed (compared by SHA-256 hash). Intermediate folders
85
+ * are created automatically.
86
+ *
87
+ * @param vaultId - The vault ID to write the document into
88
+ * @param docPath - File path relative to vault root (must end with `.md`)
89
+ * @param content - Raw Markdown content to write
90
+ * @returns The created or updated document metadata
91
+ * @throws {NotFoundError} If the vault does not exist
92
+ * @throws {ValidationError} If the path is invalid or content exceeds size limits
93
+ * @throws {AuthenticationError} If the request is not authenticated
94
+ * @throws {NetworkError} If the request fails due to network issues
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Create a new document
99
+ * const doc = await client.documents.put(
100
+ * 'vault-uuid',
101
+ * 'notes/hello.md',
102
+ * '# Hello World\n\nThis is my first note.'
103
+ * );
104
+ * ```
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // Update an existing document
109
+ * const { content } = await client.documents.get('vault-uuid', 'notes/hello.md');
110
+ * await client.documents.put(
111
+ * 'vault-uuid',
112
+ * 'notes/hello.md',
113
+ * content + '\n\nAppended text.'
114
+ * );
115
+ * ```
116
+ */
117
+ async put(vaultId, docPath, content) {
118
+ try {
119
+ return await this.http.put(`vaults/${vaultId}/documents/${docPath}`, {
120
+ json: { content },
121
+ }).json();
122
+ }
123
+ catch (error) {
124
+ throw await handleError(error, 'Document', docPath);
125
+ }
126
+ }
127
+ /**
128
+ * Permanently deletes a document from a vault.
129
+ *
130
+ * Removes the document from both the filesystem and the database.
131
+ * This action is irreversible.
132
+ *
133
+ * @param vaultId - The vault ID containing the document
134
+ * @param docPath - File path of the document to delete
135
+ * @throws {NotFoundError} If the vault or document does not exist
136
+ * @throws {AuthenticationError} If the request is not authenticated
137
+ * @throws {NetworkError} If the request fails due to network issues
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * await client.documents.delete('vault-uuid', 'notes/old-note.md');
142
+ * ```
143
+ */
144
+ async delete(vaultId, docPath) {
145
+ try {
146
+ await this.http.delete(`vaults/${vaultId}/documents/${docPath}`);
147
+ }
148
+ catch (error) {
149
+ throw await handleError(error, 'Document', docPath);
150
+ }
151
+ }
152
+ /**
153
+ * Moves (renames) a document to a new path within the same vault.
154
+ *
155
+ * @param vaultId - The vault ID containing the document
156
+ * @param sourcePath - Current file path of the document
157
+ * @param destination - New file path for the document (must end with `.md`)
158
+ * @param overwrite - If `true`, overwrite any existing document at the destination. Defaults to `false`.
159
+ * @returns Object with a confirmation message and the source/destination paths
160
+ * @throws {NotFoundError} If the vault or source document does not exist
161
+ * @throws {ConflictError} If a document exists at the destination and `overwrite` is `false`
162
+ * @throws {ValidationError} If the destination path is invalid
163
+ * @throws {AuthenticationError} If the request is not authenticated
164
+ * @throws {NetworkError} If the request fails due to network issues
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * const result = await client.documents.move(
169
+ * 'vault-uuid',
170
+ * 'drafts/note.md',
171
+ * 'published/note.md'
172
+ * );
173
+ * console.log(result.destination); // 'published/note.md'
174
+ * ```
175
+ *
176
+ * @see {@link DocumentsResource.copy} to duplicate a document instead
177
+ */
178
+ async move(vaultId, sourcePath, destination, overwrite) {
179
+ try {
180
+ return await this.http.post(`vaults/${vaultId}/documents/${sourcePath}/move`, {
181
+ json: { destination, overwrite },
182
+ }).json();
183
+ }
184
+ catch (error) {
185
+ throw await handleError(error, 'Document', sourcePath);
186
+ }
187
+ }
188
+ /**
189
+ * Copies a document to a new path within the same vault.
190
+ *
191
+ * The original document is preserved. A new document is created at the
192
+ * destination path with the same content.
193
+ *
194
+ * @param vaultId - The vault ID containing the document
195
+ * @param sourcePath - File path of the document to copy
196
+ * @param destination - File path for the new copy (must end with `.md`)
197
+ * @param overwrite - If `true`, overwrite any existing document at the destination. Defaults to `false`.
198
+ * @returns Object with a confirmation message and the source/destination paths
199
+ * @throws {NotFoundError} If the vault or source document does not exist
200
+ * @throws {ConflictError} If a document exists at the destination and `overwrite` is `false`
201
+ * @throws {ValidationError} If the destination path is invalid
202
+ * @throws {AuthenticationError} If the request is not authenticated
203
+ * @throws {NetworkError} If the request fails due to network issues
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const result = await client.documents.copy(
208
+ * 'vault-uuid',
209
+ * 'templates/meeting.md',
210
+ * 'notes/2024-01-15-meeting.md'
211
+ * );
212
+ * ```
213
+ *
214
+ * @see {@link DocumentsResource.move} to relocate a document instead
215
+ */
216
+ async copy(vaultId, sourcePath, destination, overwrite) {
217
+ try {
218
+ return await this.http.post(`vaults/${vaultId}/documents/${sourcePath}/copy`, {
219
+ json: { destination, overwrite },
220
+ }).json();
221
+ }
222
+ catch (error) {
223
+ throw await handleError(error, 'Document', sourcePath);
224
+ }
225
+ }
226
+ /**
227
+ * Creates or updates a document with client-side encryption.
228
+ *
229
+ * The content is encrypted locally using AES-256-GCM before being sent to
230
+ * the server. The server stores only the ciphertext and cannot read the
231
+ * plaintext content. Search indexing, AI features, and hooks are disabled
232
+ * for encrypted documents.
233
+ *
234
+ * @param vaultId - The vault ID to write the document into
235
+ * @param docPath - File path relative to vault root (must end with `.md`)
236
+ * @param content - Raw Markdown content to encrypt and write
237
+ * @param keyHex - The 256-bit vault encryption key as a hex string
238
+ * @returns The created or updated document metadata
239
+ * @throws {Error} If the key is invalid
240
+ */
241
+ async putEncrypted(vaultId, docPath, content, keyHex) {
242
+ try {
243
+ const encryptedContent = encrypt(content, keyHex);
244
+ return await this.http.put(`vaults/${vaultId}/documents/${docPath}`, {
245
+ json: { content: encryptedContent, encrypted: true, encryptionAlgorithm: 'aes-256-gcm' },
246
+ }).json();
247
+ }
248
+ catch (error) {
249
+ throw await handleError(error, 'Document', docPath);
250
+ }
251
+ }
252
+ /**
253
+ * Retrieves an encrypted document and decrypts it client-side.
254
+ *
255
+ * @param vaultId - The vault ID containing the document
256
+ * @param docPath - File path relative to vault root
257
+ * @param keyHex - The 256-bit vault encryption key as a hex string
258
+ * @returns The document metadata and decrypted plaintext content
259
+ * @throws {Error} If the key is invalid or decryption fails
260
+ */
261
+ async getEncrypted(vaultId, docPath, keyHex) {
262
+ try {
263
+ const result = await this.http.get(`vaults/${vaultId}/documents/${docPath}`).json();
264
+ if (result.document.encrypted) {
265
+ result.content = decrypt(result.content, keyHex);
266
+ }
267
+ return result;
268
+ }
269
+ catch (error) {
270
+ throw await handleError(error, 'Document', docPath);
271
+ }
272
+ }
273
+ /**
274
+ * Lists version history for a document.
275
+ *
276
+ * @param vaultId - The vault ID containing the document
277
+ * @param docPath - File path relative to vault root
278
+ * @returns Array of version metadata objects (newest first)
279
+ */
280
+ async listVersions(vaultId, docPath) {
281
+ try {
282
+ const data = await this.http.get(`vaults/${vaultId}/documents/${docPath}/versions`).json();
283
+ return data.versions;
284
+ }
285
+ catch (error) {
286
+ throw await handleError(error, 'Document', docPath);
287
+ }
288
+ }
289
+ /**
290
+ * Retrieves a specific version's content.
291
+ *
292
+ * @param vaultId - The vault ID containing the document
293
+ * @param docPath - File path relative to vault root
294
+ * @param versionNum - The version number to retrieve
295
+ * @returns The version metadata and content
296
+ */
297
+ async getVersion(vaultId, docPath, versionNum) {
298
+ try {
299
+ const data = await this.http.get(`vaults/${vaultId}/documents/${docPath}/versions/${versionNum}`).json();
300
+ return data.version;
301
+ }
302
+ catch (error) {
303
+ throw await handleError(error, 'Document', docPath);
304
+ }
305
+ }
306
+ /**
307
+ * Computes a diff between two versions of a document.
308
+ *
309
+ * @param vaultId - The vault ID containing the document
310
+ * @param docPath - File path relative to vault root
311
+ * @param from - Source version number
312
+ * @param to - Target version number
313
+ * @returns The diff with line-level changes
314
+ */
315
+ async diffVersions(vaultId, docPath, from, to) {
316
+ try {
317
+ return await this.http.post(`vaults/${vaultId}/documents/${docPath}/versions/diff`, {
318
+ json: { from, to },
319
+ }).json();
320
+ }
321
+ catch (error) {
322
+ throw await handleError(error, 'Document', docPath);
323
+ }
324
+ }
325
+ /**
326
+ * Restores a document to a previous version.
327
+ *
328
+ * @param vaultId - The vault ID containing the document
329
+ * @param docPath - File path relative to vault root
330
+ * @param versionNum - The version number to restore
331
+ * @returns The updated document metadata
332
+ */
333
+ async restoreVersion(vaultId, docPath, versionNum) {
334
+ try {
335
+ const data = await this.http.post(`vaults/${vaultId}/documents/${docPath}/versions/${versionNum}/restore`).json();
336
+ return data.document;
337
+ }
338
+ catch (error) {
339
+ throw await handleError(error, 'Document', docPath);
340
+ }
341
+ }
342
+ /**
343
+ * Pins a version to prevent it from being pruned.
344
+ *
345
+ * @param vaultId - The vault ID containing the document
346
+ * @param docPath - File path relative to vault root
347
+ * @param versionNum - The version number to pin
348
+ * @returns The updated version metadata
349
+ */
350
+ async pinVersion(vaultId, docPath, versionNum) {
351
+ try {
352
+ const data = await this.http.post(`vaults/${vaultId}/documents/${docPath}/versions/${versionNum}/pin`).json();
353
+ return data.version;
354
+ }
355
+ catch (error) {
356
+ throw await handleError(error, 'Document', docPath);
357
+ }
358
+ }
359
+ /**
360
+ * Unpins a version, allowing it to be pruned.
361
+ *
362
+ * @param vaultId - The vault ID containing the document
363
+ * @param docPath - File path relative to vault root
364
+ * @param versionNum - The version number to unpin
365
+ * @returns The updated version metadata
366
+ */
367
+ async unpinVersion(vaultId, docPath, versionNum) {
368
+ try {
369
+ const data = await this.http.post(`vaults/${vaultId}/documents/${docPath}/versions/${versionNum}/unpin`).json();
370
+ return data.version;
371
+ }
372
+ catch (error) {
373
+ throw await handleError(error, 'Document', docPath);
374
+ }
375
+ }
376
+ }
377
+ //# sourceMappingURL=documents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/resources/documents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAkFxD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,OAAgB;QAC1C,IAAI,CAAC;YACH,MAAM,YAAY,GAA2B,EAAE,CAAC;YAChD,IAAI,OAAO;gBAAE,YAAY,CAAC,GAAG,GAAG,OAAO,CAAC;YACxC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,OAAO,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,IAAI,EAAqC,CAAC;YAC5H,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAA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AC,UAAU,OAAO,cAAc,OAAO,aAAa,UAAU,MAAM,CAAC,CAAC,IAAI,EAAgC,CAAC;YAC5I,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,OAAe,EAAE,UAAkB;QACrE,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,OAAO,cAAc,OAAO,aAAa,UAAU,QAAQ,CAAC,CAAC,IAAI,EAAgC,CAAC;YAC9I,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,195 @@
1
+ import type { KyInstance } from 'ky';
2
+ /** A hook object returned by the API. */
3
+ export interface Hook {
4
+ /** Unique hook identifier. */
5
+ id: string;
6
+ /** Vault this hook belongs to. */
7
+ vaultId: string;
8
+ /** Human-readable name for the hook. */
9
+ name: string;
10
+ /** Event that triggers the hook (e.g., `'document.create'`, `'document.update'`, `'document.delete'`). */
11
+ triggerEvent: string;
12
+ /** Optional filter for narrowing which events trigger the hook. */
13
+ triggerFilter: Record<string, unknown> | null;
14
+ /** The type of action to perform (e.g., `'auto-tag'`, `'template'`). */
15
+ actionType: string;
16
+ /** Configuration object for the action. */
17
+ actionConfig: Record<string, unknown>;
18
+ /** Whether the hook is currently active. */
19
+ isActive: boolean;
20
+ /** ISO 8601 creation timestamp. */
21
+ createdAt: string;
22
+ /** ISO 8601 last-updated timestamp. */
23
+ updatedAt: string;
24
+ }
25
+ /** A hook execution log entry. */
26
+ export interface HookExecution {
27
+ /** Unique execution identifier. */
28
+ id: string;
29
+ /** Hook that was executed. */
30
+ hookId: string;
31
+ /** Vault event that triggered the execution. */
32
+ eventId: string;
33
+ /** Execution status (e.g., `'success'`, `'error'`). */
34
+ status: string;
35
+ /** Duration of execution in milliseconds, or `null` if not recorded. */
36
+ durationMs: number | null;
37
+ /** Result data from the execution, or `null`. */
38
+ result: unknown;
39
+ /** Error message if the execution failed, or `null`. */
40
+ error: string | null;
41
+ /** ISO 8601 timestamp of when the execution occurred. */
42
+ createdAt: string;
43
+ }
44
+ /** Parameters for creating a new hook. */
45
+ export interface CreateHookParams {
46
+ /** Human-readable name for the hook. */
47
+ name: string;
48
+ /** Event that triggers the hook. */
49
+ triggerEvent: string;
50
+ /** Optional filter for narrowing trigger events. */
51
+ triggerFilter?: Record<string, unknown> | null;
52
+ /** The type of action to perform. */
53
+ actionType: string;
54
+ /** Configuration for the action. */
55
+ actionConfig: Record<string, unknown>;
56
+ }
57
+ /** Parameters for updating an existing hook. */
58
+ export interface UpdateHookParams {
59
+ /** New name for the hook. */
60
+ name?: string;
61
+ /** Whether the hook should be active. */
62
+ isActive?: boolean;
63
+ /** New trigger event. */
64
+ triggerEvent?: string;
65
+ /** New trigger filter. */
66
+ triggerFilter?: Record<string, unknown> | null;
67
+ /** New action type. */
68
+ actionType?: string;
69
+ /** New action configuration. */
70
+ actionConfig?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Resource for managing vault hooks.
74
+ *
75
+ * Hooks are internal event handlers that run automatically when document
76
+ * events occur within a vault. They can perform actions such as auto-tagging,
77
+ * template application, and other automated workflows.
78
+ *
79
+ * Requires a **pro** or higher subscription tier.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const hooks = await client.hooks.list('vault-123');
84
+ * const hook = await client.hooks.create('vault-123', {
85
+ * name: 'Auto-tag on create',
86
+ * triggerEvent: 'document.create',
87
+ * actionType: 'auto-tag',
88
+ * actionConfig: { tags: ['new'] },
89
+ * });
90
+ * ```
91
+ */
92
+ export declare class HooksResource {
93
+ private http;
94
+ constructor(http: KyInstance);
95
+ /**
96
+ * Lists all hooks for a vault.
97
+ *
98
+ * @param vaultId - The vault to list hooks for
99
+ * @returns Array of hook objects
100
+ * @throws {AuthenticationError} If not authenticated
101
+ * @throws {AuthorizationError} If the user lacks access to the vault
102
+ * @throws {NetworkError} If the request fails due to network issues
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const hooks = await client.hooks.list('vault-123');
107
+ * for (const hook of hooks) {
108
+ * console.log(hook.name, hook.triggerEvent, hook.isActive);
109
+ * }
110
+ * ```
111
+ */
112
+ list(vaultId: string): Promise<Hook[]>;
113
+ /**
114
+ * Creates a new hook in a vault.
115
+ *
116
+ * @param vaultId - The vault to create the hook in
117
+ * @param params - Hook creation parameters
118
+ * @returns The created hook object
119
+ * @throws {ValidationError} If parameters are invalid
120
+ * @throws {AuthenticationError} If not authenticated
121
+ * @throws {AuthorizationError} If the user lacks access to the vault
122
+ * @throws {NetworkError} If the request fails due to network issues
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const hook = await client.hooks.create('vault-123', {
127
+ * name: 'Auto-tag new docs',
128
+ * triggerEvent: 'document.create',
129
+ * actionType: 'auto-tag',
130
+ * actionConfig: { tags: ['new'] },
131
+ * });
132
+ * ```
133
+ */
134
+ create(vaultId: string, params: CreateHookParams): Promise<Hook>;
135
+ /**
136
+ * Updates an existing hook.
137
+ *
138
+ * Only the provided fields are modified; omitted fields remain unchanged.
139
+ *
140
+ * @param vaultId - The vault the hook belongs to
141
+ * @param hookId - The hook to update
142
+ * @param params - Fields to update
143
+ * @returns The updated hook object
144
+ * @throws {ValidationError} If parameters are invalid
145
+ * @throws {NotFoundError} If the hook does not exist in the vault
146
+ * @throws {AuthenticationError} If not authenticated
147
+ * @throws {NetworkError} If the request fails due to network issues
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const updated = await client.hooks.update('vault-123', 'hook-456', {
152
+ * name: 'Renamed Hook',
153
+ * isActive: false,
154
+ * });
155
+ * ```
156
+ */
157
+ update(vaultId: string, hookId: string, params: UpdateHookParams): Promise<Hook>;
158
+ /**
159
+ * Deletes a hook permanently.
160
+ *
161
+ * @param vaultId - The vault the hook belongs to
162
+ * @param hookId - The hook to delete
163
+ * @throws {NotFoundError} If the hook does not exist in the vault
164
+ * @throws {AuthenticationError} If not authenticated
165
+ * @throws {NetworkError} If the request fails due to network issues
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * await client.hooks.delete('vault-123', 'hook-456');
170
+ * ```
171
+ */
172
+ delete(vaultId: string, hookId: string): Promise<void>;
173
+ /**
174
+ * Lists recent executions for a hook.
175
+ *
176
+ * Returns up to 50 most recent execution log entries, ordered by most recent first.
177
+ *
178
+ * @param vaultId - The vault the hook belongs to
179
+ * @param hookId - The hook to get executions for
180
+ * @returns Array of hook execution log entries
181
+ * @throws {NotFoundError} If the hook does not exist in the vault
182
+ * @throws {AuthenticationError} If not authenticated
183
+ * @throws {NetworkError} If the request fails due to network issues
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const executions = await client.hooks.listExecutions('vault-123', 'hook-456');
188
+ * for (const exec of executions) {
189
+ * console.log(exec.status, exec.durationMs, exec.createdAt);
190
+ * }
191
+ * ```
192
+ */
193
+ listExecutions(vaultId: string, hookId: string): Promise<HookExecution[]>;
194
+ }
195
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/resources/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,yCAAyC;AACzC,MAAM,WAAW,IAAI;IACnB,8BAA8B;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,0GAA0G;IAC1G,YAAY,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