@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.
- package/LICENSE +21 -0
- package/README.md +1121 -0
- package/dist/client.d.ts +143 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +286 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle-error.d.ts +8 -0
- package/dist/handle-error.d.ts.map +1 -0
- package/dist/handle-error.js +35 -0
- package/dist/handle-error.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audit-logger.d.ts +29 -0
- package/dist/lib/audit-logger.d.ts.map +1 -0
- package/dist/lib/audit-logger.js +99 -0
- package/dist/lib/audit-logger.js.map +1 -0
- package/dist/lib/encryption.d.ts +34 -0
- package/dist/lib/encryption.d.ts.map +1 -0
- package/dist/lib/encryption.js +87 -0
- package/dist/lib/encryption.js.map +1 -0
- package/dist/lib/signature.d.ts +47 -0
- package/dist/lib/signature.d.ts.map +1 -0
- package/dist/lib/signature.js +71 -0
- package/dist/lib/signature.js.map +1 -0
- package/dist/lib/token-manager.d.ts +80 -0
- package/dist/lib/token-manager.d.ts.map +1 -0
- package/dist/lib/token-manager.js +116 -0
- package/dist/lib/token-manager.js.map +1 -0
- package/dist/resources/admin.d.ts +280 -0
- package/dist/resources/admin.d.ts.map +1 -0
- package/dist/resources/admin.js +236 -0
- package/dist/resources/admin.js.map +1 -0
- package/dist/resources/ai.d.ts +184 -0
- package/dist/resources/ai.d.ts.map +1 -0
- package/dist/resources/ai.js +179 -0
- package/dist/resources/ai.js.map +1 -0
- package/dist/resources/api-keys.d.ts +172 -0
- package/dist/resources/api-keys.d.ts.map +1 -0
- package/dist/resources/api-keys.js +166 -0
- package/dist/resources/api-keys.js.map +1 -0
- package/dist/resources/connectors.d.ts +263 -0
- package/dist/resources/connectors.d.ts.map +1 -0
- package/dist/resources/connectors.js +226 -0
- package/dist/resources/connectors.js.map +1 -0
- package/dist/resources/documents.d.ts +334 -0
- package/dist/resources/documents.d.ts.map +1 -0
- package/dist/resources/documents.js +377 -0
- package/dist/resources/documents.js.map +1 -0
- package/dist/resources/hooks.d.ts +195 -0
- package/dist/resources/hooks.d.ts.map +1 -0
- package/dist/resources/hooks.js +166 -0
- package/dist/resources/hooks.js.map +1 -0
- package/dist/resources/publish.d.ts +165 -0
- package/dist/resources/publish.d.ts.map +1 -0
- package/dist/resources/publish.js +150 -0
- package/dist/resources/publish.js.map +1 -0
- package/dist/resources/search.d.ts +94 -0
- package/dist/resources/search.d.ts.map +1 -0
- package/dist/resources/search.js +76 -0
- package/dist/resources/search.js.map +1 -0
- package/dist/resources/shares.d.ts +130 -0
- package/dist/resources/shares.d.ts.map +1 -0
- package/dist/resources/shares.js +115 -0
- package/dist/resources/shares.js.map +1 -0
- package/dist/resources/subscription.d.ts +172 -0
- package/dist/resources/subscription.d.ts.map +1 -0
- package/dist/resources/subscription.js +166 -0
- package/dist/resources/subscription.js.map +1 -0
- package/dist/resources/teams.d.ts +356 -0
- package/dist/resources/teams.d.ts.map +1 -0
- package/dist/resources/teams.js +395 -0
- package/dist/resources/teams.js.map +1 -0
- package/dist/resources/user.d.ts +92 -0
- package/dist/resources/user.d.ts.map +1 -0
- package/dist/resources/user.js +64 -0
- package/dist/resources/user.js.map +1 -0
- package/dist/resources/vaults.d.ts +144 -0
- package/dist/resources/vaults.d.ts.map +1 -0
- package/dist/resources/vaults.js +158 -0
- package/dist/resources/vaults.js.map +1 -0
- package/dist/resources/webhooks.d.ts +187 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +171 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/types/api.d.ts +17 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/resources.d.ts +5 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +2 -0
- package/dist/types/resources.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { handleError } from '../handle-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource for managing vault hooks.
|
|
4
|
+
*
|
|
5
|
+
* Hooks are internal event handlers that run automatically when document
|
|
6
|
+
* events occur within a vault. They can perform actions such as auto-tagging,
|
|
7
|
+
* template application, and other automated workflows.
|
|
8
|
+
*
|
|
9
|
+
* Requires a **pro** or higher subscription tier.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const hooks = await client.hooks.list('vault-123');
|
|
14
|
+
* const hook = await client.hooks.create('vault-123', {
|
|
15
|
+
* name: 'Auto-tag on create',
|
|
16
|
+
* triggerEvent: 'document.create',
|
|
17
|
+
* actionType: 'auto-tag',
|
|
18
|
+
* actionConfig: { tags: ['new'] },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class HooksResource {
|
|
23
|
+
http;
|
|
24
|
+
constructor(http) {
|
|
25
|
+
this.http = http;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Lists all hooks for a vault.
|
|
29
|
+
*
|
|
30
|
+
* @param vaultId - The vault to list hooks for
|
|
31
|
+
* @returns Array of hook objects
|
|
32
|
+
* @throws {AuthenticationError} If not authenticated
|
|
33
|
+
* @throws {AuthorizationError} If the user lacks access to the vault
|
|
34
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const hooks = await client.hooks.list('vault-123');
|
|
39
|
+
* for (const hook of hooks) {
|
|
40
|
+
* console.log(hook.name, hook.triggerEvent, hook.isActive);
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
async list(vaultId) {
|
|
45
|
+
try {
|
|
46
|
+
const data = await this.http.get(`vaults/${vaultId}/hooks`).json();
|
|
47
|
+
return data.hooks;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw await handleError(error, 'Hooks', vaultId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new hook in a vault.
|
|
55
|
+
*
|
|
56
|
+
* @param vaultId - The vault to create the hook in
|
|
57
|
+
* @param params - Hook creation parameters
|
|
58
|
+
* @returns The created hook object
|
|
59
|
+
* @throws {ValidationError} If parameters are invalid
|
|
60
|
+
* @throws {AuthenticationError} If not authenticated
|
|
61
|
+
* @throws {AuthorizationError} If the user lacks access to the vault
|
|
62
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const hook = await client.hooks.create('vault-123', {
|
|
67
|
+
* name: 'Auto-tag new docs',
|
|
68
|
+
* triggerEvent: 'document.create',
|
|
69
|
+
* actionType: 'auto-tag',
|
|
70
|
+
* actionConfig: { tags: ['new'] },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async create(vaultId, params) {
|
|
75
|
+
try {
|
|
76
|
+
return await this.http.post(`vaults/${vaultId}/hooks`, { json: params }).json();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw await handleError(error, 'Hook', params.name);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Updates an existing hook.
|
|
84
|
+
*
|
|
85
|
+
* Only the provided fields are modified; omitted fields remain unchanged.
|
|
86
|
+
*
|
|
87
|
+
* @param vaultId - The vault the hook belongs to
|
|
88
|
+
* @param hookId - The hook to update
|
|
89
|
+
* @param params - Fields to update
|
|
90
|
+
* @returns The updated hook object
|
|
91
|
+
* @throws {ValidationError} If parameters are invalid
|
|
92
|
+
* @throws {NotFoundError} If the hook does not exist in the vault
|
|
93
|
+
* @throws {AuthenticationError} If not authenticated
|
|
94
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const updated = await client.hooks.update('vault-123', 'hook-456', {
|
|
99
|
+
* name: 'Renamed Hook',
|
|
100
|
+
* isActive: false,
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
async update(vaultId, hookId, params) {
|
|
105
|
+
try {
|
|
106
|
+
return await this.http.put(`vaults/${vaultId}/hooks/${hookId}`, { json: params }).json();
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw await handleError(error, 'Hook', hookId);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Deletes a hook permanently.
|
|
114
|
+
*
|
|
115
|
+
* @param vaultId - The vault the hook belongs to
|
|
116
|
+
* @param hookId - The hook to delete
|
|
117
|
+
* @throws {NotFoundError} If the hook does not exist in the vault
|
|
118
|
+
* @throws {AuthenticationError} If not authenticated
|
|
119
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* await client.hooks.delete('vault-123', 'hook-456');
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
async delete(vaultId, hookId) {
|
|
127
|
+
try {
|
|
128
|
+
await this.http.delete(`vaults/${vaultId}/hooks/${hookId}`);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw await handleError(error, 'Hook', hookId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Lists recent executions for a hook.
|
|
136
|
+
*
|
|
137
|
+
* Returns up to 50 most recent execution log entries, ordered by most recent first.
|
|
138
|
+
*
|
|
139
|
+
* @param vaultId - The vault the hook belongs to
|
|
140
|
+
* @param hookId - The hook to get executions for
|
|
141
|
+
* @returns Array of hook execution log entries
|
|
142
|
+
* @throws {NotFoundError} If the hook does not exist in the vault
|
|
143
|
+
* @throws {AuthenticationError} If not authenticated
|
|
144
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const executions = await client.hooks.listExecutions('vault-123', 'hook-456');
|
|
149
|
+
* for (const exec of executions) {
|
|
150
|
+
* console.log(exec.status, exec.durationMs, exec.createdAt);
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async listExecutions(vaultId, hookId) {
|
|
155
|
+
try {
|
|
156
|
+
const data = await this.http
|
|
157
|
+
.get(`vaults/${vaultId}/hooks/${hookId}/executions`)
|
|
158
|
+
.json();
|
|
159
|
+
return data.executions;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw await handleError(error, 'Hook', hookId);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/resources/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA4EjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,IAAI,CAAC,OAAe;QACxB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,OAAO,QAAQ,CAAC,CAAC,IAAI,EAAqB,CAAC;YACtF,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,MAAwB;QACpD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,OAAO,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAQ,CAAC;QACxF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,MAAc,EAAE,MAAwB;QACpE,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,OAAO,UAAU,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAQ,CAAC;QACjG,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,MAAc;QAC1C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,OAAO,UAAU,MAAM,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,MAAc;QAClD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI;iBACzB,GAAG,CAAC,UAAU,OAAO,UAAU,MAAM,aAAa,CAAC;iBACnD,IAAI,EAAmC,CAAC;YAC3C,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { KyInstance } from 'ky';
|
|
2
|
+
/** A published document with SEO metadata. */
|
|
3
|
+
export interface PublishedDocument {
|
|
4
|
+
/** Unique published document identifier. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** ID of the source document. */
|
|
7
|
+
documentId: string;
|
|
8
|
+
/** ID of the vault containing the document. */
|
|
9
|
+
vaultId: string;
|
|
10
|
+
/** ID of the user who published the document. */
|
|
11
|
+
publishedBy: string;
|
|
12
|
+
/** URL-friendly slug for the published page. */
|
|
13
|
+
slug: string;
|
|
14
|
+
/** SEO title for the published page, or `null` if not set. */
|
|
15
|
+
seoTitle: string | null;
|
|
16
|
+
/** SEO description for the published page, or `null` if not set. */
|
|
17
|
+
seoDescription: string | null;
|
|
18
|
+
/** Open Graph image URL, or `null` if not set. */
|
|
19
|
+
ogImage: string | null;
|
|
20
|
+
/** Whether the document is currently published. */
|
|
21
|
+
isPublished: boolean;
|
|
22
|
+
/** ISO 8601 timestamp when the document was first published. */
|
|
23
|
+
publishedAt: string;
|
|
24
|
+
/** ISO 8601 timestamp of the last update to publish settings. */
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
}
|
|
27
|
+
/** A published document with additional document metadata (returned by `listMine`). */
|
|
28
|
+
export interface PublishedDocumentWithMeta extends PublishedDocument {
|
|
29
|
+
/** File path of the source document. */
|
|
30
|
+
documentPath: string;
|
|
31
|
+
/** Title of the source document, or `null` if not set. */
|
|
32
|
+
documentTitle: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** Parameters for publishing a document. */
|
|
35
|
+
export interface PublishDocumentParams {
|
|
36
|
+
/** URL-friendly slug (lowercase alphanumeric with hyphens). */
|
|
37
|
+
slug: string;
|
|
38
|
+
/** Optional SEO title (max 200 chars). */
|
|
39
|
+
seoTitle?: string;
|
|
40
|
+
/** Optional SEO description (max 500 chars). */
|
|
41
|
+
seoDescription?: string;
|
|
42
|
+
/** Optional Open Graph image URL. */
|
|
43
|
+
ogImage?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Parameters for updating a published document. */
|
|
46
|
+
export interface UpdatePublishParams {
|
|
47
|
+
/** New slug (required for updates). */
|
|
48
|
+
slug: string;
|
|
49
|
+
/** Updated SEO title, or `null` to clear. */
|
|
50
|
+
seoTitle?: string | null;
|
|
51
|
+
/** Updated SEO description, or `null` to clear. */
|
|
52
|
+
seoDescription?: string | null;
|
|
53
|
+
/** Updated Open Graph image URL, or `null` to clear. */
|
|
54
|
+
ogImage?: string | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resource for managing document publishing.
|
|
58
|
+
*
|
|
59
|
+
* Published documents are publicly accessible at `/:profileSlug/:docSlug`
|
|
60
|
+
* with optional SEO metadata. Requires a `pro` or higher subscription tier
|
|
61
|
+
* with the `publishing` feature enabled.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const published = await client.publish.create('vault-id', 'blog/first-post.md', {
|
|
66
|
+
* slug: 'my-first-post',
|
|
67
|
+
* seoTitle: 'My First Post',
|
|
68
|
+
* seoDescription: 'An introduction to my vault.',
|
|
69
|
+
* });
|
|
70
|
+
* console.log(`Published at: /${published.publishedBy}/${published.slug}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare class PublishResource {
|
|
74
|
+
private http;
|
|
75
|
+
constructor(http: KyInstance);
|
|
76
|
+
/**
|
|
77
|
+
* Lists all published documents for the authenticated user.
|
|
78
|
+
*
|
|
79
|
+
* Returns documents across all vaults, including document path and title
|
|
80
|
+
* metadata. Does not require vault-level access.
|
|
81
|
+
*
|
|
82
|
+
* @param vaultId - A vault ID (required by the route but not filtered on)
|
|
83
|
+
* @returns Array of published document objects with source document metadata
|
|
84
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
85
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const docs = await client.publish.listMine('any-vault-id');
|
|
90
|
+
* for (const doc of docs) {
|
|
91
|
+
* console.log(`${doc.slug} -> ${doc.documentPath} (published: ${doc.isPublished})`);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
listMine(vaultId: string): Promise<PublishedDocumentWithMeta[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Publishes a document, making it publicly accessible.
|
|
98
|
+
*
|
|
99
|
+
* If the document is already published, this updates its publish settings
|
|
100
|
+
* (acts as an upsert).
|
|
101
|
+
*
|
|
102
|
+
* @param vaultId - The vault ID containing the document
|
|
103
|
+
* @param documentPath - File path of the document to publish
|
|
104
|
+
* @param params - Publish parameters including slug and optional SEO metadata
|
|
105
|
+
* @returns The published document metadata
|
|
106
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
107
|
+
* @throws {ConflictError} If the slug is already in use
|
|
108
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
109
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
110
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
111
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const pub = await client.publish.create('vault-id', 'blog/post.md', {
|
|
116
|
+
* slug: 'my-post',
|
|
117
|
+
* seoTitle: 'My Blog Post',
|
|
118
|
+
* });
|
|
119
|
+
* console.log(`Published: ${pub.slug}`);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
create(vaultId: string, documentPath: string, params: PublishDocumentParams): Promise<PublishedDocument>;
|
|
123
|
+
/**
|
|
124
|
+
* Updates the publish settings of an already-published document.
|
|
125
|
+
*
|
|
126
|
+
* @param vaultId - The vault ID containing the document
|
|
127
|
+
* @param documentPath - File path of the published document
|
|
128
|
+
* @param params - Updated publish parameters (slug is required)
|
|
129
|
+
* @returns The updated published document metadata
|
|
130
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
131
|
+
* @throws {ConflictError} If the new slug is already in use
|
|
132
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
133
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
134
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
135
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const updated = await client.publish.update('vault-id', 'blog/post.md', {
|
|
140
|
+
* slug: 'updated-slug',
|
|
141
|
+
* seoDescription: 'Updated description for SEO.',
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
update(vaultId: string, documentPath: string, params: UpdatePublishParams): Promise<PublishedDocument>;
|
|
146
|
+
/**
|
|
147
|
+
* Unpublishes a document, removing it from public access.
|
|
148
|
+
*
|
|
149
|
+
* The document itself is not deleted; only the published state is changed.
|
|
150
|
+
*
|
|
151
|
+
* @param vaultId - The vault ID containing the document
|
|
152
|
+
* @param documentPath - File path of the document to unpublish
|
|
153
|
+
* @throws {NotFoundError} If the published document does not exist
|
|
154
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
155
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
156
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* await client.publish.delete('vault-id', 'blog/post.md');
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
delete(vaultId: string, documentPath: string): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/resources/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,oEAAoE;IACpE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,kDAAkD;IAClD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mDAAmD;IACnD,WAAW,EAAE,OAAO,CAAC;IACrB,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uFAAuF;AACvF,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,4CAA4C;AAC5C,MAAM,WAAW,qBAAqB;IACpC,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC;;;;;;;;;;;;;;;;;;OAkBG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAWrE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,MAAM,CACV,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,iBAAiB,CAAC;IAW7B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,MAAM,CACV,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IAW7B;;;;;;;;;;;;;;;;OAgBG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOnE"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { handleError } from '../handle-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource for managing document publishing.
|
|
4
|
+
*
|
|
5
|
+
* Published documents are publicly accessible at `/:profileSlug/:docSlug`
|
|
6
|
+
* with optional SEO metadata. Requires a `pro` or higher subscription tier
|
|
7
|
+
* with the `publishing` feature enabled.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const published = await client.publish.create('vault-id', 'blog/first-post.md', {
|
|
12
|
+
* slug: 'my-first-post',
|
|
13
|
+
* seoTitle: 'My First Post',
|
|
14
|
+
* seoDescription: 'An introduction to my vault.',
|
|
15
|
+
* });
|
|
16
|
+
* console.log(`Published at: /${published.publishedBy}/${published.slug}`);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class PublishResource {
|
|
20
|
+
http;
|
|
21
|
+
constructor(http) {
|
|
22
|
+
this.http = http;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lists all published documents for the authenticated user.
|
|
26
|
+
*
|
|
27
|
+
* Returns documents across all vaults, including document path and title
|
|
28
|
+
* metadata. Does not require vault-level access.
|
|
29
|
+
*
|
|
30
|
+
* @param vaultId - A vault ID (required by the route but not filtered on)
|
|
31
|
+
* @returns Array of published document objects with source document metadata
|
|
32
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
33
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const docs = await client.publish.listMine('any-vault-id');
|
|
38
|
+
* for (const doc of docs) {
|
|
39
|
+
* console.log(`${doc.slug} -> ${doc.documentPath} (published: ${doc.isPublished})`);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async listMine(vaultId) {
|
|
44
|
+
try {
|
|
45
|
+
const data = await this.http
|
|
46
|
+
.get(`vaults/${vaultId}/publish/my`)
|
|
47
|
+
.json();
|
|
48
|
+
return data.publishedDocs;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw await handleError(error, 'Published Documents', '');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Publishes a document, making it publicly accessible.
|
|
56
|
+
*
|
|
57
|
+
* If the document is already published, this updates its publish settings
|
|
58
|
+
* (acts as an upsert).
|
|
59
|
+
*
|
|
60
|
+
* @param vaultId - The vault ID containing the document
|
|
61
|
+
* @param documentPath - File path of the document to publish
|
|
62
|
+
* @param params - Publish parameters including slug and optional SEO metadata
|
|
63
|
+
* @returns The published document metadata
|
|
64
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
65
|
+
* @throws {ConflictError} If the slug is already in use
|
|
66
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
67
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
68
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
69
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const pub = await client.publish.create('vault-id', 'blog/post.md', {
|
|
74
|
+
* slug: 'my-post',
|
|
75
|
+
* seoTitle: 'My Blog Post',
|
|
76
|
+
* });
|
|
77
|
+
* console.log(`Published: ${pub.slug}`);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
async create(vaultId, documentPath, params) {
|
|
81
|
+
try {
|
|
82
|
+
const data = await this.http
|
|
83
|
+
.post(`vaults/${vaultId}/publish/document/${documentPath}`, { json: params })
|
|
84
|
+
.json();
|
|
85
|
+
return data.publishedDoc;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw await handleError(error, 'Published Document', documentPath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Updates the publish settings of an already-published document.
|
|
93
|
+
*
|
|
94
|
+
* @param vaultId - The vault ID containing the document
|
|
95
|
+
* @param documentPath - File path of the published document
|
|
96
|
+
* @param params - Updated publish parameters (slug is required)
|
|
97
|
+
* @returns The updated published document metadata
|
|
98
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
99
|
+
* @throws {ConflictError} If the new slug is already in use
|
|
100
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
101
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
102
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
103
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const updated = await client.publish.update('vault-id', 'blog/post.md', {
|
|
108
|
+
* slug: 'updated-slug',
|
|
109
|
+
* seoDescription: 'Updated description for SEO.',
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async update(vaultId, documentPath, params) {
|
|
114
|
+
try {
|
|
115
|
+
const data = await this.http
|
|
116
|
+
.put(`vaults/${vaultId}/publish/document/${documentPath}`, { json: params })
|
|
117
|
+
.json();
|
|
118
|
+
return data.publishedDoc;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw await handleError(error, 'Published Document', documentPath);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Unpublishes a document, removing it from public access.
|
|
126
|
+
*
|
|
127
|
+
* The document itself is not deleted; only the published state is changed.
|
|
128
|
+
*
|
|
129
|
+
* @param vaultId - The vault ID containing the document
|
|
130
|
+
* @param documentPath - File path of the document to unpublish
|
|
131
|
+
* @throws {NotFoundError} If the published document does not exist
|
|
132
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
133
|
+
* @throws {AuthorizationError} If the user's subscription does not include publishing
|
|
134
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await client.publish.delete('vault-id', 'blog/post.md');
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
async delete(vaultId, documentPath) {
|
|
142
|
+
try {
|
|
143
|
+
await this.http.delete(`vaults/${vaultId}/publish/document/${documentPath}`);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
throw await handleError(error, 'Published Document', documentPath);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/resources/publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA4DjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,eAAe;IACN;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI;iBACzB,GAAG,CAAC,UAAU,OAAO,aAAa,CAAC;iBACnC,IAAI,EAAkD,CAAC;YAC1D,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,KAAK,CAAC,MAAM,CACV,OAAe,EACf,YAAoB,EACpB,MAA6B;QAE7B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI;iBACzB,IAAI,CAAC,UAAU,OAAO,qBAAqB,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iBAC5E,IAAI,EAAuC,CAAC;YAC/C,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,MAAM,CACV,OAAe,EACf,YAAoB,EACpB,MAA2B;QAE3B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI;iBACzB,GAAG,CAAC,UAAU,OAAO,qBAAqB,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iBAC3E,IAAI,EAAuC,CAAC;YAC/C,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,YAAoB;QAChD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,OAAO,qBAAqB,YAAY,EAAE,CAAC,CAAC;QAC/E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { KyInstance } from 'ky';
|
|
2
|
+
/** A single search result with matched document details. */
|
|
3
|
+
export interface SearchResult {
|
|
4
|
+
/** Unique identifier of the matched document. */
|
|
5
|
+
documentId: string;
|
|
6
|
+
/** ID of the vault containing the document. */
|
|
7
|
+
vaultId: string;
|
|
8
|
+
/** Name of the vault containing the document. */
|
|
9
|
+
vaultName: string;
|
|
10
|
+
/** File path of the matched document. */
|
|
11
|
+
path: string;
|
|
12
|
+
/** Document title, if available. */
|
|
13
|
+
title: string | null;
|
|
14
|
+
/** Text snippet with highlighted matches. */
|
|
15
|
+
snippet: string;
|
|
16
|
+
/** Tags on the matched document. */
|
|
17
|
+
tags: string[];
|
|
18
|
+
/** Relevance rank (higher is more relevant). */
|
|
19
|
+
rank: number;
|
|
20
|
+
/** ISO 8601 timestamp of the last file modification. */
|
|
21
|
+
fileModifiedAt: string;
|
|
22
|
+
}
|
|
23
|
+
/** Response from a full-text search query. */
|
|
24
|
+
export interface SearchResponse {
|
|
25
|
+
/** Array of matching documents. */
|
|
26
|
+
results: SearchResult[];
|
|
27
|
+
/** Total number of matching documents (for pagination). */
|
|
28
|
+
total: number;
|
|
29
|
+
/** The original query string. */
|
|
30
|
+
query: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resource for full-text search across vaults.
|
|
34
|
+
*
|
|
35
|
+
* Uses PostgreSQL `websearch_to_tsquery` syntax for queries, supporting
|
|
36
|
+
* natural language search, quoted phrases, and boolean operators.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const results = await client.search.search({ q: 'meeting notes' });
|
|
41
|
+
* for (const result of results.results) {
|
|
42
|
+
* console.log(result.title, result.snippet);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class SearchResource {
|
|
47
|
+
private http;
|
|
48
|
+
constructor(http: KyInstance);
|
|
49
|
+
/**
|
|
50
|
+
* Searches for documents matching a full-text query.
|
|
51
|
+
*
|
|
52
|
+
* Supports PostgreSQL `websearch_to_tsquery` syntax: plain words for
|
|
53
|
+
* natural language matching, `"quoted phrases"` for exact matches,
|
|
54
|
+
* `OR` for alternatives, and `-word` for exclusion.
|
|
55
|
+
*
|
|
56
|
+
* @param params - Search parameters
|
|
57
|
+
* @param params.q - Search query string (required)
|
|
58
|
+
* @param params.vault - Optional vault ID to restrict search to a single vault
|
|
59
|
+
* @param params.tags - Optional comma-separated tag filter (e.g., `'work,urgent'`)
|
|
60
|
+
* @param params.limit - Maximum number of results to return
|
|
61
|
+
* @param params.offset - Number of results to skip (for pagination)
|
|
62
|
+
* @returns Search response with matching documents, total count, and the original query
|
|
63
|
+
* @throws {ValidationError} If the query string is empty
|
|
64
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
65
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Simple search
|
|
70
|
+
* const results = await client.search.search({ q: 'project ideas' });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Filtered and paginated search
|
|
76
|
+
* const results = await client.search.search({
|
|
77
|
+
* q: '"quarterly review"',
|
|
78
|
+
* vault: 'vault-uuid',
|
|
79
|
+
* tags: 'work,reports',
|
|
80
|
+
* limit: 10,
|
|
81
|
+
* offset: 20,
|
|
82
|
+
* });
|
|
83
|
+
* console.log(`Showing ${results.results.length} of ${results.total}`);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
search(params: {
|
|
87
|
+
q: string;
|
|
88
|
+
vault?: string;
|
|
89
|
+
tags?: string;
|
|
90
|
+
limit?: number;
|
|
91
|
+
offset?: number;
|
|
92
|
+
}): Promise<SearchResponse>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/resources/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACG,MAAM,CAAC,MAAM,EAAE;QACnB,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,cAAc,CAAC;CAY5B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { handleError } from '../handle-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource for full-text search across vaults.
|
|
4
|
+
*
|
|
5
|
+
* Uses PostgreSQL `websearch_to_tsquery` syntax for queries, supporting
|
|
6
|
+
* natural language search, quoted phrases, and boolean operators.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const results = await client.search.search({ q: 'meeting notes' });
|
|
11
|
+
* for (const result of results.results) {
|
|
12
|
+
* console.log(result.title, result.snippet);
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class SearchResource {
|
|
17
|
+
http;
|
|
18
|
+
constructor(http) {
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Searches for documents matching a full-text query.
|
|
23
|
+
*
|
|
24
|
+
* Supports PostgreSQL `websearch_to_tsquery` syntax: plain words for
|
|
25
|
+
* natural language matching, `"quoted phrases"` for exact matches,
|
|
26
|
+
* `OR` for alternatives, and `-word` for exclusion.
|
|
27
|
+
*
|
|
28
|
+
* @param params - Search parameters
|
|
29
|
+
* @param params.q - Search query string (required)
|
|
30
|
+
* @param params.vault - Optional vault ID to restrict search to a single vault
|
|
31
|
+
* @param params.tags - Optional comma-separated tag filter (e.g., `'work,urgent'`)
|
|
32
|
+
* @param params.limit - Maximum number of results to return
|
|
33
|
+
* @param params.offset - Number of results to skip (for pagination)
|
|
34
|
+
* @returns Search response with matching documents, total count, and the original query
|
|
35
|
+
* @throws {ValidationError} If the query string is empty
|
|
36
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
37
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Simple search
|
|
42
|
+
* const results = await client.search.search({ q: 'project ideas' });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Filtered and paginated search
|
|
48
|
+
* const results = await client.search.search({
|
|
49
|
+
* q: '"quarterly review"',
|
|
50
|
+
* vault: 'vault-uuid',
|
|
51
|
+
* tags: 'work,reports',
|
|
52
|
+
* limit: 10,
|
|
53
|
+
* offset: 20,
|
|
54
|
+
* });
|
|
55
|
+
* console.log(`Showing ${results.results.length} of ${results.total}`);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async search(params) {
|
|
59
|
+
try {
|
|
60
|
+
const searchParams = { q: params.q };
|
|
61
|
+
if (params.vault)
|
|
62
|
+
searchParams.vault = params.vault;
|
|
63
|
+
if (params.tags)
|
|
64
|
+
searchParams.tags = params.tags;
|
|
65
|
+
if (params.limit !== undefined)
|
|
66
|
+
searchParams.limit = params.limit;
|
|
67
|
+
if (params.offset !== undefined)
|
|
68
|
+
searchParams.offset = params.offset;
|
|
69
|
+
return await this.http.get('search', { searchParams }).json();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw await handleError(error, 'Search', params.q);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/resources/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAkCjD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,KAAK,CAAC,MAAM,CAAC,MAMZ;QACC,IAAI,CAAC;YACH,MAAM,YAAY,GAAoC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;YACtE,IAAI,MAAM,CAAC,KAAK;gBAAE,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACpD,IAAI,MAAM,CAAC,IAAI;gBAAE,YAAY,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACjD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;gBAAE,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YAClE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;gBAAE,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACrE,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,IAAI,EAAkB,CAAC;QAChF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF"}
|