@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,143 @@
1
+ import { type KyInstance } from 'ky';
2
+ import { VaultsResource } from './resources/vaults.js';
3
+ import { DocumentsResource } from './resources/documents.js';
4
+ import { SearchResource } from './resources/search.js';
5
+ import { AiResource } from './resources/ai.js';
6
+ import { TeamsResource } from './resources/teams.js';
7
+ import { ApiKeysResource } from './resources/api-keys.js';
8
+ import { UserResource } from './resources/user.js';
9
+ import { SubscriptionResource } from './resources/subscription.js';
10
+ import { SharesResource } from './resources/shares.js';
11
+ import { PublishResource } from './resources/publish.js';
12
+ import { ConnectorsResource } from './resources/connectors.js';
13
+ import { AdminResource } from './resources/admin.js';
14
+ import { HooksResource } from './resources/hooks.js';
15
+ import { WebhooksResource } from './resources/webhooks.js';
16
+ import { TokenManager, type AuthTokens, type OnTokenRefresh } from './lib/token-manager.js';
17
+ /**
18
+ * Configuration options for creating a {@link LifestreamVaultClient}.
19
+ */
20
+ export interface ClientOptions {
21
+ /** Base URL of the Lifestream Vault API server (e.g., `'https://vault.example.com'`). */
22
+ baseUrl: string;
23
+ /** API key for authentication (prefix `lsv_k_`). Provide either this or `accessToken`. */
24
+ apiKey?: string;
25
+ /** JWT access token for authentication. Provide either this or `apiKey`. */
26
+ accessToken?: string;
27
+ /** JWT refresh token for automatic token renewal. Only used with `accessToken`. */
28
+ refreshToken?: string;
29
+ /** Request timeout in milliseconds. Defaults to 30000 (30 seconds). */
30
+ timeout?: number;
31
+ /** Milliseconds before token expiry to trigger proactive refresh. Default: 60000 (1 min). */
32
+ refreshBufferMs?: number;
33
+ /** Called after a successful token refresh with the new tokens. */
34
+ onTokenRefresh?: OnTokenRefresh;
35
+ /** Enable HMAC-SHA256 request signing for sensitive operations. Defaults to true when using API keys, false for JWT. */
36
+ enableRequestSigning?: boolean;
37
+ /** Enable client-side audit logging of requests. Defaults to false. */
38
+ enableAuditLogging?: boolean;
39
+ /** Path to the audit log file. Defaults to `~/.lsvault/audit.log`. */
40
+ auditLogPath?: string;
41
+ }
42
+ /**
43
+ * Main client for the Lifestream Vault API.
44
+ *
45
+ * Provides access to all API resources through typed sub-clients:
46
+ * {@link VaultsResource | vaults}, {@link DocumentsResource | documents},
47
+ * {@link SearchResource | search}, {@link AiResource | ai},
48
+ * {@link ApiKeysResource | apiKeys}, {@link UserResource | user},
49
+ * {@link SubscriptionResource | subscription}, and {@link TeamsResource | teams}.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { LifestreamVaultClient } from '@lifestream-vault/sdk';
54
+ *
55
+ * const client = new LifestreamVaultClient({
56
+ * baseUrl: 'https://vault.example.com',
57
+ * apiKey: 'lsv_k_your_api_key',
58
+ * });
59
+ *
60
+ * const vaults = await client.vaults.list();
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Using a JWT access token instead of an API key
66
+ * const client = new LifestreamVaultClient({
67
+ * baseUrl: 'https://vault.example.com',
68
+ * accessToken: 'eyJhbGci...',
69
+ * timeout: 60_000,
70
+ * });
71
+ * ```
72
+ */
73
+ export declare class LifestreamVaultClient {
74
+ /** The underlying ky HTTP client instance, pre-configured with auth and base URL. */
75
+ readonly http: KyInstance;
76
+ /** The normalized base URL of the API server. */
77
+ readonly baseUrl: string;
78
+ /** Vault management operations. */
79
+ readonly vaults: VaultsResource;
80
+ /** Document CRUD and file operations. */
81
+ readonly documents: DocumentsResource;
82
+ /** Full-text search across vaults. */
83
+ readonly search: SearchResource;
84
+ /** AI chat and document summarization. */
85
+ readonly ai: AiResource;
86
+ /** API key management operations. */
87
+ readonly apiKeys: ApiKeysResource;
88
+ /** User profile and storage information. */
89
+ readonly user: UserResource;
90
+ /** Subscription management and billing. */
91
+ readonly subscription: SubscriptionResource;
92
+ /** Team management, members, invitations, and team vaults. */
93
+ readonly teams: TeamsResource;
94
+ /** Document sharing via token-based links. */
95
+ readonly shares: SharesResource;
96
+ /** Document publishing for public access. */
97
+ readonly publish: PublishResource;
98
+ /** External connector management (e.g., Google Drive sync). */
99
+ readonly connectors: ConnectorsResource;
100
+ /** Admin operations: stats, user management, activity, health. */
101
+ readonly admin: AdminResource;
102
+ /** Vault hook management (internal event handlers). */
103
+ readonly hooks: HooksResource;
104
+ /** Vault webhook management (outbound HTTP notifications). */
105
+ readonly webhooks: WebhooksResource;
106
+ /** Token manager for JWT auto-refresh (null when using API key auth). */
107
+ readonly tokenManager: TokenManager | null;
108
+ /**
109
+ * Creates a new Lifestream Vault API client.
110
+ *
111
+ * @param options - Client configuration options
112
+ * @param options.baseUrl - Base URL of the API server (trailing slashes are stripped)
113
+ * @param options.apiKey - API key for authentication (mutually exclusive with `accessToken`)
114
+ * @param options.accessToken - JWT access token (mutually exclusive with `apiKey`)
115
+ * @param options.timeout - Request timeout in milliseconds (default: 30000)
116
+ * @throws {ValidationError} If `baseUrl` is empty or neither `apiKey` nor `accessToken` is provided
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const client = new LifestreamVaultClient({
121
+ * baseUrl: 'https://vault.example.com',
122
+ * apiKey: 'lsv_k_your_api_key',
123
+ * });
124
+ * ```
125
+ */
126
+ constructor(options: ClientOptions);
127
+ /**
128
+ * Authenticate with email and password to obtain JWT tokens.
129
+ * Returns an authenticated client instance with token management.
130
+ *
131
+ * @param baseUrl - Base URL of the API server
132
+ * @param email - User email address
133
+ * @param password - User password
134
+ * @param options - Additional client options (timeout, refreshBufferMs, onTokenRefresh, etc.)
135
+ * @returns A new authenticated client with the access/refresh tokens used
136
+ */
137
+ static login(baseUrl: string, email: string, password: string, options?: Omit<ClientOptions, 'baseUrl' | 'apiKey' | 'accessToken' | 'refreshToken'>): Promise<{
138
+ client: LifestreamVaultClient;
139
+ tokens: AuthTokens;
140
+ refreshToken: string | null;
141
+ }>;
142
+ }
143
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAA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C5C,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAE3C;;;;;;;;;;;;;;;;;OAiBG;gBACS,OAAO,EAAE,aAAa;IAqKlC;;;;;;;;;OASG;WACU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,cAAc,CAAM,GACvF,OAAO,CAAC;QAAE,MAAM,EAAE,qBAAqB,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAgC/F"}
package/dist/client.js ADDED
@@ -0,0 +1,286 @@
1
+ import ky from 'ky';
2
+ import { VaultsResource } from './resources/vaults.js';
3
+ import { DocumentsResource } from './resources/documents.js';
4
+ import { SearchResource } from './resources/search.js';
5
+ import { AiResource } from './resources/ai.js';
6
+ import { TeamsResource } from './resources/teams.js';
7
+ import { ApiKeysResource } from './resources/api-keys.js';
8
+ import { UserResource } from './resources/user.js';
9
+ import { SubscriptionResource } from './resources/subscription.js';
10
+ import { SharesResource } from './resources/shares.js';
11
+ import { PublishResource } from './resources/publish.js';
12
+ import { ConnectorsResource } from './resources/connectors.js';
13
+ import { AdminResource } from './resources/admin.js';
14
+ import { HooksResource } from './resources/hooks.js';
15
+ import { WebhooksResource } from './resources/webhooks.js';
16
+ import { ValidationError } from './errors.js';
17
+ import { AuditLogger } from './lib/audit-logger.js';
18
+ import { signRequest } from './lib/signature.js';
19
+ import { TokenManager } from './lib/token-manager.js';
20
+ /** Header used to prevent infinite 401 retry loops. */
21
+ const RETRY_HEADER = 'X-Retry-After-Refresh';
22
+ /**
23
+ * Main client for the Lifestream Vault API.
24
+ *
25
+ * Provides access to all API resources through typed sub-clients:
26
+ * {@link VaultsResource | vaults}, {@link DocumentsResource | documents},
27
+ * {@link SearchResource | search}, {@link AiResource | ai},
28
+ * {@link ApiKeysResource | apiKeys}, {@link UserResource | user},
29
+ * {@link SubscriptionResource | subscription}, and {@link TeamsResource | teams}.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { LifestreamVaultClient } from '@lifestream-vault/sdk';
34
+ *
35
+ * const client = new LifestreamVaultClient({
36
+ * baseUrl: 'https://vault.example.com',
37
+ * apiKey: 'lsv_k_your_api_key',
38
+ * });
39
+ *
40
+ * const vaults = await client.vaults.list();
41
+ * ```
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Using a JWT access token instead of an API key
46
+ * const client = new LifestreamVaultClient({
47
+ * baseUrl: 'https://vault.example.com',
48
+ * accessToken: 'eyJhbGci...',
49
+ * timeout: 60_000,
50
+ * });
51
+ * ```
52
+ */
53
+ export class LifestreamVaultClient {
54
+ /** The underlying ky HTTP client instance, pre-configured with auth and base URL. */
55
+ http;
56
+ /** The normalized base URL of the API server. */
57
+ baseUrl;
58
+ /** Vault management operations. */
59
+ vaults;
60
+ /** Document CRUD and file operations. */
61
+ documents;
62
+ /** Full-text search across vaults. */
63
+ search;
64
+ /** AI chat and document summarization. */
65
+ ai;
66
+ /** API key management operations. */
67
+ apiKeys;
68
+ /** User profile and storage information. */
69
+ user;
70
+ /** Subscription management and billing. */
71
+ subscription;
72
+ /** Team management, members, invitations, and team vaults. */
73
+ teams;
74
+ /** Document sharing via token-based links. */
75
+ shares;
76
+ /** Document publishing for public access. */
77
+ publish;
78
+ /** External connector management (e.g., Google Drive sync). */
79
+ connectors;
80
+ /** Admin operations: stats, user management, activity, health. */
81
+ admin;
82
+ /** Vault hook management (internal event handlers). */
83
+ hooks;
84
+ /** Vault webhook management (outbound HTTP notifications). */
85
+ webhooks;
86
+ /** Token manager for JWT auto-refresh (null when using API key auth). */
87
+ tokenManager;
88
+ /**
89
+ * Creates a new Lifestream Vault API client.
90
+ *
91
+ * @param options - Client configuration options
92
+ * @param options.baseUrl - Base URL of the API server (trailing slashes are stripped)
93
+ * @param options.apiKey - API key for authentication (mutually exclusive with `accessToken`)
94
+ * @param options.accessToken - JWT access token (mutually exclusive with `apiKey`)
95
+ * @param options.timeout - Request timeout in milliseconds (default: 30000)
96
+ * @throws {ValidationError} If `baseUrl` is empty or neither `apiKey` nor `accessToken` is provided
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const client = new LifestreamVaultClient({
101
+ * baseUrl: 'https://vault.example.com',
102
+ * apiKey: 'lsv_k_your_api_key',
103
+ * });
104
+ * ```
105
+ */
106
+ constructor(options) {
107
+ if (!options.baseUrl) {
108
+ throw new ValidationError('baseUrl is required');
109
+ }
110
+ if (!options.apiKey && !options.accessToken) {
111
+ throw new ValidationError('Either apiKey or accessToken is required');
112
+ }
113
+ this.baseUrl = options.baseUrl.replace(/\/$/, '');
114
+ const prefixUrl = `${this.baseUrl}/api/v1`;
115
+ const timeout = options.timeout || 30_000;
116
+ // Determine whether to enable request signing
117
+ const shouldSign = options.enableRequestSigning ?? !!options.apiKey;
118
+ const beforeRequestHooks = [];
119
+ const afterResponseHooks = [];
120
+ // Request signing hook -- adds HMAC signature headers to mutating requests
121
+ if (shouldSign && options.apiKey) {
122
+ const apiKeyForSigning = options.apiKey;
123
+ beforeRequestHooks.push(async (request) => {
124
+ const url = new URL(request.url);
125
+ const method = request.method.toUpperCase();
126
+ // Only sign mutating operations
127
+ if (!['PUT', 'POST', 'DELETE', 'PATCH'].includes(method)) {
128
+ return;
129
+ }
130
+ // Read body for signing (clone to avoid consuming the stream)
131
+ let body = '';
132
+ if (request.body) {
133
+ const cloned = request.clone();
134
+ body = await cloned.text();
135
+ }
136
+ const sigHeaders = signRequest(apiKeyForSigning, method, url.pathname, body);
137
+ for (const [key, value] of Object.entries(sigHeaders)) {
138
+ request.headers.set(key, value);
139
+ }
140
+ });
141
+ }
142
+ // Audit logging hooks
143
+ if (options.enableAuditLogging) {
144
+ const auditLogger = new AuditLogger({ logPath: options.auditLogPath });
145
+ const requestTimings = new WeakMap();
146
+ beforeRequestHooks.push((request) => {
147
+ requestTimings.set(request, Date.now());
148
+ });
149
+ afterResponseHooks.push((request, _options, response) => {
150
+ const startTime = requestTimings.get(request);
151
+ const durationMs = startTime ? Date.now() - startTime : 0;
152
+ const url = new URL(request.url);
153
+ try {
154
+ auditLogger.log({
155
+ timestamp: new Date().toISOString(),
156
+ method: request.method,
157
+ path: url.pathname,
158
+ status: response.status,
159
+ durationMs,
160
+ });
161
+ }
162
+ catch {
163
+ // Audit logging is best-effort; never break requests
164
+ }
165
+ });
166
+ }
167
+ if (options.apiKey) {
168
+ // API key auth: static Authorization header, no token management
169
+ this.tokenManager = null;
170
+ this.http = ky.create({
171
+ prefixUrl,
172
+ timeout,
173
+ headers: {
174
+ 'Authorization': `Bearer ${options.apiKey}`,
175
+ },
176
+ hooks: {
177
+ beforeRequest: beforeRequestHooks,
178
+ afterResponse: afterResponseHooks,
179
+ },
180
+ });
181
+ }
182
+ else {
183
+ // JWT auth: set up token manager with optional auto-refresh
184
+ const tokenManager = new TokenManager(options.accessToken, options.refreshToken ?? null, {
185
+ refreshBufferMs: options.refreshBufferMs,
186
+ onTokenRefresh: options.onTokenRefresh,
187
+ });
188
+ this.tokenManager = tokenManager;
189
+ // Base ky instance without auth hooks (used for refresh requests to avoid recursion)
190
+ const baseHttp = ky.create({ prefixUrl, timeout });
191
+ // JWT beforeRequest: proactive refresh + set Authorization header
192
+ beforeRequestHooks.push(async (request) => {
193
+ if (tokenManager.needsRefresh() && tokenManager.getRefreshToken()) {
194
+ try {
195
+ await tokenManager.refresh(baseHttp);
196
+ }
197
+ catch {
198
+ // Refresh failed; proceed with current token, let 401 handler deal with it
199
+ }
200
+ }
201
+ request.headers.set('Authorization', `Bearer ${tokenManager.getAccessToken()}`);
202
+ });
203
+ // JWT afterResponse: reactive 401 retry
204
+ afterResponseHooks.push(async (request, _options, response) => {
205
+ if (response.status === 401
206
+ && !request.headers.get(RETRY_HEADER)
207
+ && tokenManager.getRefreshToken()) {
208
+ try {
209
+ const newToken = await tokenManager.refresh(baseHttp);
210
+ const retryRequest = new Request(request, {
211
+ headers: new Headers(request.headers),
212
+ });
213
+ retryRequest.headers.set('Authorization', `Bearer ${newToken}`);
214
+ retryRequest.headers.set(RETRY_HEADER, '1');
215
+ return ky(retryRequest);
216
+ }
217
+ catch {
218
+ // Refresh failed; return original 401
219
+ return response;
220
+ }
221
+ }
222
+ return response;
223
+ });
224
+ this.http = ky.create({
225
+ prefixUrl,
226
+ timeout,
227
+ hooks: {
228
+ beforeRequest: beforeRequestHooks,
229
+ afterResponse: afterResponseHooks,
230
+ },
231
+ });
232
+ }
233
+ this.vaults = new VaultsResource(this.http);
234
+ this.documents = new DocumentsResource(this.http);
235
+ this.search = new SearchResource(this.http);
236
+ this.ai = new AiResource(this.http);
237
+ this.apiKeys = new ApiKeysResource(this.http);
238
+ this.user = new UserResource(this.http);
239
+ this.subscription = new SubscriptionResource(this.http);
240
+ this.teams = new TeamsResource(this.http);
241
+ this.shares = new SharesResource(this.http);
242
+ this.publish = new PublishResource(this.http);
243
+ this.connectors = new ConnectorsResource(this.http);
244
+ this.admin = new AdminResource(this.http);
245
+ this.hooks = new HooksResource(this.http);
246
+ this.webhooks = new WebhooksResource(this.http);
247
+ }
248
+ /**
249
+ * Authenticate with email and password to obtain JWT tokens.
250
+ * Returns an authenticated client instance with token management.
251
+ *
252
+ * @param baseUrl - Base URL of the API server
253
+ * @param email - User email address
254
+ * @param password - User password
255
+ * @param options - Additional client options (timeout, refreshBufferMs, onTokenRefresh, etc.)
256
+ * @returns A new authenticated client with the access/refresh tokens used
257
+ */
258
+ static async login(baseUrl, email, password, options = {}) {
259
+ const normalizedUrl = baseUrl.replace(/\/$/, '');
260
+ const http = ky.create({
261
+ prefixUrl: `${normalizedUrl}/api/v1`,
262
+ timeout: options.timeout || 30_000,
263
+ });
264
+ const response = await http.post('auth/login', {
265
+ json: { email, password },
266
+ });
267
+ const tokens = await response.json();
268
+ // Extract refresh token from Set-Cookie header if present
269
+ const setCookie = response.headers.get('set-cookie');
270
+ let refreshToken = null;
271
+ if (setCookie) {
272
+ const match = setCookie.match(/lsv_refresh=([^;]+)/);
273
+ if (match) {
274
+ refreshToken = match[1];
275
+ }
276
+ }
277
+ const client = new LifestreamVaultClient({
278
+ ...options,
279
+ baseUrl: normalizedUrl,
280
+ accessToken: tokens.accessToken,
281
+ refreshToken: refreshToken ?? undefined,
282
+ });
283
+ return { client, tokens, refreshToken };
284
+ }
285
+ }
286
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,IAAI,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAA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IACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,OAAe,EACf,KAAa,EACb,QAAgB,EAChB,UAAsF,EAAE;QAExF,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC;YACrB,SAAS,EAAE,GAAG,aAAa,SAAS;YACpC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;SACnC,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YAC7C,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;SAC1B,CAAC,CAAC;QAEH,MAAM,MAAM,GAAe,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEjD,0DAA0D;QAC1D,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACrD,IAAI,YAAY,GAAkB,IAAI,CAAC;QACvC,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACrD,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC;YACvC,GAAG,OAAO;YACV,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,YAAY,EAAE,YAAY,IAAI,SAAS;SACxC,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ export declare class SDKError extends Error {
2
+ statusCode?: number | undefined;
3
+ constructor(message: string, statusCode?: number | undefined);
4
+ }
5
+ export declare class ValidationError extends SDKError {
6
+ details?: unknown | undefined;
7
+ constructor(message: string, details?: unknown | undefined);
8
+ }
9
+ export declare class AuthenticationError extends SDKError {
10
+ constructor(message?: string);
11
+ }
12
+ export declare class AuthorizationError extends SDKError {
13
+ constructor(message?: string);
14
+ }
15
+ export declare class NotFoundError extends SDKError {
16
+ constructor(resource: string, identifier: string);
17
+ }
18
+ export declare class ConflictError extends SDKError {
19
+ constructor(message: string);
20
+ }
21
+ export declare class RateLimitError extends SDKError {
22
+ constructor(message?: string);
23
+ }
24
+ export declare class NetworkError extends SDKError {
25
+ cause?: Error;
26
+ constructor(message: string, cause?: Error);
27
+ }
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IAGxB,UAAU,CAAC,EAAE,MAAM;gBAD1B,OAAO,EAAE,MAAM,EACR,UAAU,CAAC,EAAE,MAAM,YAAA;CAM7B;AAED,qBAAa,eAAgB,SAAQ,QAAQ;IAGlC,OAAO,CAAC,EAAE,OAAO;gBADxB,OAAO,EAAE,MAAM,EACR,OAAO,CAAC,EAAE,OAAO,YAAA;CAI3B;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,GAAE,MAAkC;CAGxD;AAED,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,OAAO,GAAE,MAA4B;CAGlD;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAGjD;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,GAAE,MAA8B;CAGpD;AAED,qBAAa,YAAa,SAAQ,QAAQ;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C"}
package/dist/errors.js ADDED
@@ -0,0 +1,49 @@
1
+ export class SDKError extends Error {
2
+ statusCode;
3
+ constructor(message, statusCode) {
4
+ super(message);
5
+ this.statusCode = statusCode;
6
+ this.name = this.constructor.name;
7
+ Error.captureStackTrace?.(this, this.constructor);
8
+ }
9
+ }
10
+ export class ValidationError extends SDKError {
11
+ details;
12
+ constructor(message, details) {
13
+ super(message, 400);
14
+ this.details = details;
15
+ }
16
+ }
17
+ export class AuthenticationError extends SDKError {
18
+ constructor(message = 'Authentication required') {
19
+ super(message, 401);
20
+ }
21
+ }
22
+ export class AuthorizationError extends SDKError {
23
+ constructor(message = 'Permission denied') {
24
+ super(message, 403);
25
+ }
26
+ }
27
+ export class NotFoundError extends SDKError {
28
+ constructor(resource, identifier) {
29
+ super(`${resource} not found: ${identifier}`, 404);
30
+ }
31
+ }
32
+ export class ConflictError extends SDKError {
33
+ constructor(message) {
34
+ super(message, 409);
35
+ }
36
+ }
37
+ export class RateLimitError extends SDKError {
38
+ constructor(message = 'Rate limit exceeded') {
39
+ super(message, 429);
40
+ }
41
+ }
42
+ export class NetworkError extends SDKError {
43
+ cause;
44
+ constructor(message, cause) {
45
+ super(message);
46
+ this.cause = cause;
47
+ }
48
+ }
49
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGxB;IAFT,YACE,OAAe,EACR,UAAmB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,eAAU,GAAV,UAAU,CAAS;QAG1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAGlC;IAFT,YACE,OAAe,EACR,OAAiB;QAExB,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAFb,YAAO,GAAP,OAAO,CAAU;IAG1B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,UAAkB,yBAAyB;QACrD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,QAAQ;IAC9C,YAAY,UAAkB,mBAAmB;QAC/C,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,QAAQ;IACzC,YAAY,QAAgB,EAAE,UAAkB;QAC9C,KAAK,CAAC,GAAG,QAAQ,eAAe,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,QAAQ;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAC1C,YAAY,UAAkB,qBAAqB;QACjD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,QAAQ;IAC/B,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convert a caught error into the appropriate typed SDK error.
3
+ * @param error The caught error (typically from ky)
4
+ * @param resource Human-readable resource name for 404 messages
5
+ * @param identifier Resource identifier for 404 messages
6
+ */
7
+ export declare function handleError(error: unknown, resource?: string, identifier?: string): Promise<never>;
8
+ //# sourceMappingURL=handle-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.d.ts","sourceRoot":"","sources":["../src/handle-error.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,GAAE,MAAmB,EAC7B,UAAU,GAAE,MAAW,GACtB,OAAO,CAAC,KAAK,CAAC,CAuBhB"}
@@ -0,0 +1,35 @@
1
+ import { HTTPError } from 'ky';
2
+ import { SDKError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, RateLimitError, NetworkError, } from './errors.js';
3
+ /**
4
+ * Convert a caught error into the appropriate typed SDK error.
5
+ * @param error The caught error (typically from ky)
6
+ * @param resource Human-readable resource name for 404 messages
7
+ * @param identifier Resource identifier for 404 messages
8
+ */
9
+ export async function handleError(error, resource = 'Resource', identifier = '') {
10
+ if (error instanceof HTTPError) {
11
+ const status = error.response.status;
12
+ const body = await error.response
13
+ .json()
14
+ .catch(() => ({ message: error.message }));
15
+ const msg = body.message ?? 'Request failed';
16
+ if (status === 400)
17
+ throw new ValidationError(msg, body.details);
18
+ if (status === 401)
19
+ throw new AuthenticationError(msg);
20
+ if (status === 403)
21
+ throw new AuthorizationError(msg);
22
+ if (status === 404)
23
+ throw new NotFoundError(resource, identifier);
24
+ if (status === 409)
25
+ throw new ConflictError(msg);
26
+ if (status === 429)
27
+ throw new RateLimitError(msg);
28
+ throw new SDKError(msg, status);
29
+ }
30
+ if (error instanceof Error) {
31
+ throw new NetworkError('Network request failed', error);
32
+ }
33
+ throw new NetworkError('Network request failed');
34
+ }
35
+ //# sourceMappingURL=handle-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../src/handle-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EACL,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAA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AAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,32 @@
1
+ export { LifestreamVaultClient, type ClientOptions } from './client.js';
2
+ export { VaultsResource } from './resources/vaults.js';
3
+ export { DocumentsResource } from './resources/documents.js';
4
+ export { SearchResource } from './resources/search.js';
5
+ export { AiResource } from './resources/ai.js';
6
+ export { ApiKeysResource } from './resources/api-keys.js';
7
+ export type { ApiKey, ApiKeyWithSecret, CreateApiKeyParams, UpdateApiKeyParams } from './resources/api-keys.js';
8
+ export { UserResource } from './resources/user.js';
9
+ export type { User, VaultStorage, StorageUsage } from './resources/user.js';
10
+ export { SubscriptionResource } from './resources/subscription.js';
11
+ export type { Subscription, Plan, CheckoutSession, PortalSession, Invoice } from './resources/subscription.js';
12
+ export { TeamsResource } from './resources/teams.js';
13
+ export type { Team, TeamMember, TeamInvitation, CreateTeamParams, UpdateTeamParams } from './resources/teams.js';
14
+ export { SharesResource } from './resources/shares.js';
15
+ export type { ShareLink, CreateShareLinkParams, CreateShareLinkResponse } from './resources/shares.js';
16
+ export { PublishResource } from './resources/publish.js';
17
+ export type { PublishedDocument, PublishedDocumentWithMeta, PublishDocumentParams, UpdatePublishParams } from './resources/publish.js';
18
+ export { ConnectorsResource } from './resources/connectors.js';
19
+ export type { Connector, ConnectorSyncLog, CreateConnectorParams, UpdateConnectorParams, TestConnectionResult, TriggerSyncResult, ConnectorProvider, SyncDirection, ConnectorStatus, } from './resources/connectors.js';
20
+ export { HooksResource } from './resources/hooks.js';
21
+ export type { Hook, HookExecution, CreateHookParams, UpdateHookParams } from './resources/hooks.js';
22
+ export { WebhooksResource } from './resources/webhooks.js';
23
+ export type { Webhook, WebhookWithSecret, WebhookDelivery, CreateWebhookParams, UpdateWebhookParams } from './resources/webhooks.js';
24
+ export { AdminResource } from './resources/admin.js';
25
+ export type { SystemStats, TimeseriesDataPoint, TimeseriesResponse, AdminUser, AdminUserListResponse, AdminUserDetail, AdminUserListParams, AdminUpdateUserParams, ActivityEntry, SubscriptionSummary, SystemHealth, } from './resources/admin.js';
26
+ export { signRequest, buildSignaturePayload, signPayload, generateNonce, SIGNATURE_HEADER, SIGNATURE_TIMESTAMP_HEADER, SIGNATURE_NONCE_HEADER, MAX_TIMESTAMP_AGE_MS, } from './lib/signature.js';
27
+ export { AuditLogger, type AuditEntry, type AuditLoggerOptions } from './lib/audit-logger.js';
28
+ export { generateVaultKey, encrypt as encryptContent, decrypt as decryptContent, isEncryptedEnvelope, type EncryptedEnvelope, } from './lib/encryption.js';
29
+ export { TokenManager, decodeJwtPayload, isTokenExpired, type AuthTokens, type JwtPayload, type OnTokenRefresh, type TokenManagerOptions, } from './lib/token-manager.js';
30
+ export { SDKError, ValidationError, AuthenticationError, AuthorizationError, NotFoundError, ConflictError, RateLimitError, NetworkError, } from './errors.js';
31
+ export type { PaginatedResponse, ApiErrorResponse, MessageResponse, Vault, Document, DocumentWithContent, DocumentListItem, SearchResult, SearchResponse, AiChatSession, AiChatMessage, } from './types/index.js';
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAChH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,E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