@lifestreamdynamics/vault-sdk 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -40
- package/dist/client.d.ts +66 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +129 -15
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/calendar.d.ts +208 -0
- package/dist/resources/calendar.d.ts.map +1 -0
- package/dist/resources/calendar.js +205 -0
- package/dist/resources/calendar.js.map +1 -0
- package/dist/resources/documents.d.ts +63 -0
- package/dist/resources/documents.d.ts.map +1 -1
- package/dist/resources/documents.js +55 -0
- package/dist/resources/documents.js.map +1 -1
- package/dist/resources/mfa.d.ts +190 -0
- package/dist/resources/mfa.d.ts.map +1 -0
- package/dist/resources/mfa.js +249 -0
- package/dist/resources/mfa.js.map +1 -0
- package/dist/resources/search.d.ts +13 -0
- package/dist/resources/search.d.ts.map +1 -1
- package/dist/resources/search.js +12 -0
- package/dist/resources/search.js.map +1 -1
- package/dist/resources/subscription.d.ts +1 -1
- package/dist/resources/subscription.d.ts.map +1 -1
- package/dist/resources/vaults.d.ts +73 -0
- package/dist/resources/vaults.d.ts.map +1 -1
- package/dist/resources/vaults.js +59 -0
- package/dist/resources/vaults.js.map +1 -1
- package/dist/types/api.d.ts +50 -0
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js +4 -1
- package/dist/types/api.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resources.d.ts +2 -2
- package/dist/types/resources.d.ts.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Official TypeScript SDK for the Lifestream Vault API. Build powerful integrations with your Lifestream Vault account using a modern, type-safe client library.
|
|
4
4
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://www.npmjs.com/package/@lifestreamdynamics/vault-sdk)
|
|
7
7
|
|
|
8
8
|
## 📖 Table of Contents
|
|
9
9
|
|
|
@@ -42,19 +42,19 @@ Official TypeScript SDK for the Lifestream Vault API. Build powerful integration
|
|
|
42
42
|
### NPM (Recommended)
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
npm install @
|
|
45
|
+
npm install @lifestreamdynamics/vault-sdk
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### Yarn
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
yarn add @
|
|
51
|
+
yarn add @lifestreamdynamics/vault-sdk
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
### pnpm
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
pnpm add @
|
|
57
|
+
pnpm add @lifestreamdynamics/vault-sdk
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
### CDN
|
|
@@ -62,24 +62,26 @@ pnpm add @lifestream-vault/sdk
|
|
|
62
62
|
```html
|
|
63
63
|
<!-- ES Module -->
|
|
64
64
|
<script type="module">
|
|
65
|
-
import { LifestreamVaultClient } from 'https://unpkg.com/@
|
|
65
|
+
import { LifestreamVaultClient } from 'https://unpkg.com/@lifestreamdynamics/vault-sdk/dist/index.js';
|
|
66
66
|
</script>
|
|
67
67
|
|
|
68
68
|
<!-- Or via jsDelivr -->
|
|
69
69
|
<script type="module">
|
|
70
|
-
import { LifestreamVaultClient } from 'https://cdn.jsdelivr.net/npm/@
|
|
70
|
+
import { LifestreamVaultClient } from 'https://cdn.jsdelivr.net/npm/@lifestreamdynamics/vault-sdk/+esm';
|
|
71
71
|
</script>
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
## 🚀 Quick Start
|
|
75
75
|
|
|
76
|
+
> **Self-hosting?** Replace `https://vault.lifestreamdynamics.com` with your server's URL, or set the `LSVAULT_API_URL` environment variable.
|
|
77
|
+
|
|
76
78
|
### Basic Usage with API Key
|
|
77
79
|
|
|
78
80
|
```typescript
|
|
79
|
-
import { LifestreamVaultClient } from '@
|
|
81
|
+
import { LifestreamVaultClient } from '@lifestreamdynamics/vault-sdk';
|
|
80
82
|
|
|
81
83
|
const client = new LifestreamVaultClient({
|
|
82
|
-
baseUrl: 'https://vault.
|
|
84
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
83
85
|
apiKey: 'lsv_k_your_api_key_here',
|
|
84
86
|
});
|
|
85
87
|
|
|
@@ -95,10 +97,10 @@ console.log(doc.content);
|
|
|
95
97
|
### Login with Email and Password
|
|
96
98
|
|
|
97
99
|
```typescript
|
|
98
|
-
import { LifestreamVaultClient } from '@
|
|
100
|
+
import { LifestreamVaultClient } from '@lifestreamdynamics/vault-sdk';
|
|
99
101
|
|
|
100
102
|
const { client, tokens } = await LifestreamVaultClient.login(
|
|
101
|
-
'https://vault.
|
|
103
|
+
'https://vault.lifestreamdynamics.com',
|
|
102
104
|
'user@example.com',
|
|
103
105
|
'your-password',
|
|
104
106
|
);
|
|
@@ -111,7 +113,7 @@ const vaults = await client.vaults.list();
|
|
|
111
113
|
|
|
112
114
|
```typescript
|
|
113
115
|
const client = new LifestreamVaultClient({
|
|
114
|
-
baseUrl: 'https://vault.
|
|
116
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
115
117
|
accessToken: 'eyJhbGci...', // Your JWT access token
|
|
116
118
|
refreshToken: 'your_refresh_token', // Optional: enables auto-refresh
|
|
117
119
|
});
|
|
@@ -120,7 +122,7 @@ const client = new LifestreamVaultClient({
|
|
|
120
122
|
### Error Handling
|
|
121
123
|
|
|
122
124
|
```typescript
|
|
123
|
-
import { LifestreamVaultClient, NotFoundError, AuthenticationError } from '@
|
|
125
|
+
import { LifestreamVaultClient, NotFoundError, AuthenticationError } from '@lifestreamdynamics/vault-sdk';
|
|
124
126
|
|
|
125
127
|
try {
|
|
126
128
|
const vault = await client.vaults.get('non-existent-id');
|
|
@@ -145,7 +147,7 @@ Best for server-side integrations, automation scripts, and long-running services
|
|
|
145
147
|
|
|
146
148
|
```typescript
|
|
147
149
|
const client = new LifestreamVaultClient({
|
|
148
|
-
baseUrl: 'https://vault.
|
|
150
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
149
151
|
apiKey: 'lsv_k_your_api_key_here', // Starts with 'lsv_k_'
|
|
150
152
|
});
|
|
151
153
|
```
|
|
@@ -169,7 +171,7 @@ Best for user-facing applications and scenarios requiring user-specific permissi
|
|
|
169
171
|
|
|
170
172
|
```typescript
|
|
171
173
|
const client = new LifestreamVaultClient({
|
|
172
|
-
baseUrl: 'https://vault.
|
|
174
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
173
175
|
accessToken: 'eyJhbGci...', // Your JWT access token
|
|
174
176
|
refreshToken: 'your_refresh_token', // Optional but recommended
|
|
175
177
|
refreshBufferMs: 60000, // Refresh 60s before expiry (default)
|
|
@@ -189,7 +191,7 @@ const client = new LifestreamVaultClient({
|
|
|
189
191
|
**Login Helper:**
|
|
190
192
|
```typescript
|
|
191
193
|
const { client, tokens, refreshToken } = await LifestreamVaultClient.login(
|
|
192
|
-
'https://vault.
|
|
194
|
+
'https://vault.lifestreamdynamics.com',
|
|
193
195
|
'user@example.com',
|
|
194
196
|
'password',
|
|
195
197
|
{
|
|
@@ -232,6 +234,19 @@ const updated = await client.vaults.update('vault-id', {
|
|
|
232
234
|
|
|
233
235
|
// Delete a vault
|
|
234
236
|
await client.vaults.delete('vault-id');
|
|
237
|
+
|
|
238
|
+
// Get the link graph for a vault
|
|
239
|
+
const graph = await client.vaults.getGraph('vault-id');
|
|
240
|
+
console.log(`${graph.nodes.length} documents, ${graph.edges.length} links`);
|
|
241
|
+
|
|
242
|
+
// Get unresolved (broken) links
|
|
243
|
+
const broken = await client.vaults.getUnresolvedLinks('vault-id');
|
|
244
|
+
for (const link of broken) {
|
|
245
|
+
console.log(`Missing: ${link.targetPath}`);
|
|
246
|
+
for (const ref of link.references) {
|
|
247
|
+
console.log(` Referenced by: ${ref.sourcePath}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
235
250
|
```
|
|
236
251
|
|
|
237
252
|
### Documents
|
|
@@ -258,6 +273,19 @@ await client.documents.delete('vault-id', 'path/to/doc.md');
|
|
|
258
273
|
// Get directory tree structure
|
|
259
274
|
const tree = await client.documents.tree('vault-id');
|
|
260
275
|
|
|
276
|
+
// Get forward links from a document
|
|
277
|
+
const links = await client.documents.getLinks('vault-id', 'notes/index.md');
|
|
278
|
+
for (const link of links) {
|
|
279
|
+
console.log(`[[${link.linkText}]] -> ${link.targetPath} (resolved: ${link.isResolved})`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Get backlinks pointing to a document
|
|
283
|
+
const backlinks = await client.documents.getBacklinks('vault-id', 'notes/important.md');
|
|
284
|
+
console.log(`${backlinks.length} documents link to this one`);
|
|
285
|
+
for (const bl of backlinks) {
|
|
286
|
+
console.log(`- ${bl.sourceDocument.path}: [[${bl.linkText}]]`);
|
|
287
|
+
}
|
|
288
|
+
|
|
261
289
|
// List document versions
|
|
262
290
|
const versions = await client.documents.listVersions('vault-id', 'path/to/doc.md');
|
|
263
291
|
|
|
@@ -554,13 +582,68 @@ const health = await client.admin.getHealth();
|
|
|
554
582
|
console.log(health.status); // 'healthy', 'degraded', or 'down'
|
|
555
583
|
```
|
|
556
584
|
|
|
585
|
+
### Calendar
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
// Get aggregated calendar view (free tier)
|
|
589
|
+
const calendar = await client.calendar.getCalendar(vaultId, { month: 2, year: 2026 });
|
|
590
|
+
|
|
591
|
+
// Get activity heatmap for past year (free tier)
|
|
592
|
+
const activity = await client.calendar.getActivity(vaultId);
|
|
593
|
+
|
|
594
|
+
// Get documents by due date (pro tier)
|
|
595
|
+
const due = await client.calendar.getDue(vaultId, { from: '2026-02-01', to: '2026-02-28' });
|
|
596
|
+
|
|
597
|
+
// Get agenda view (pro tier)
|
|
598
|
+
const agenda = await client.calendar.getAgenda(vaultId, { groupBy: 'week' });
|
|
599
|
+
|
|
600
|
+
// Create a calendar event (pro tier)
|
|
601
|
+
const event = await client.calendar.createEvent(vaultId, {
|
|
602
|
+
title: 'Team Review',
|
|
603
|
+
startAt: '2026-02-20T10:00:00Z',
|
|
604
|
+
endAt: '2026-02-20T11:00:00Z',
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// List calendar events (pro tier)
|
|
608
|
+
const events = await client.calendar.listEvents(vaultId);
|
|
609
|
+
|
|
610
|
+
// Update event (pro tier)
|
|
611
|
+
await client.calendar.updateEvent(vaultId, eventId, { title: 'Updated Review' });
|
|
612
|
+
|
|
613
|
+
// Delete event (pro tier)
|
|
614
|
+
await client.calendar.deleteEvent(vaultId, eventId);
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### MFA
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
// Get MFA status
|
|
621
|
+
const status = await client.mfa.getStatus();
|
|
622
|
+
|
|
623
|
+
// Set up TOTP (returns QR code URI)
|
|
624
|
+
const setup = await client.mfa.setupTotp();
|
|
625
|
+
|
|
626
|
+
// Verify and enable TOTP
|
|
627
|
+
await client.mfa.verifyTotp({ token: '123456' });
|
|
628
|
+
|
|
629
|
+
// Register a passkey
|
|
630
|
+
const registration = await client.mfa.startPasskeyRegistration();
|
|
631
|
+
await client.mfa.finishPasskeyRegistration(registration.options);
|
|
632
|
+
|
|
633
|
+
// List passkeys
|
|
634
|
+
const passkeys = await client.mfa.listPasskeys();
|
|
635
|
+
|
|
636
|
+
// Regenerate backup codes
|
|
637
|
+
const codes = await client.mfa.regenerateBackupCodes();
|
|
638
|
+
```
|
|
639
|
+
|
|
557
640
|
## ⚙️ Configuration
|
|
558
641
|
|
|
559
642
|
### ClientOptions
|
|
560
643
|
|
|
561
644
|
| Option | Type | Default | Description |
|
|
562
645
|
|--------|------|---------|-------------|
|
|
563
|
-
| `baseUrl` | `string` |
|
|
646
|
+
| `baseUrl` | `string` | `https://vault.lifestreamdynamics.com` | Base URL of your Lifestream Vault server (optional, defaults to production) |
|
|
564
647
|
| `apiKey` | `string` | - | API key for authentication (starts with `lsv_k_`) |
|
|
565
648
|
| `accessToken` | `string` | - | JWT access token for user authentication |
|
|
566
649
|
| `refreshToken` | `string` | - | JWT refresh token for automatic renewal |
|
|
@@ -575,7 +658,7 @@ console.log(health.status); // 'healthy', 'degraded', or 'down'
|
|
|
575
658
|
|
|
576
659
|
```typescript
|
|
577
660
|
const client = new LifestreamVaultClient({
|
|
578
|
-
baseUrl: 'https://vault.
|
|
661
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
579
662
|
apiKey: 'lsv_k_your_api_key',
|
|
580
663
|
timeout: 60000, // 60 seconds
|
|
581
664
|
enableRequestSigning: true,
|
|
@@ -588,7 +671,7 @@ const client = new LifestreamVaultClient({
|
|
|
588
671
|
|
|
589
672
|
```typescript
|
|
590
673
|
const client = new LifestreamVaultClient({
|
|
591
|
-
baseUrl: 'https://vault.
|
|
674
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
592
675
|
accessToken: 'eyJhbGci...',
|
|
593
676
|
refreshToken: 'refresh_token_here',
|
|
594
677
|
refreshBufferMs: 120000, // Refresh 2 minutes before expiry
|
|
@@ -605,10 +688,10 @@ const client = new LifestreamVaultClient({
|
|
|
605
688
|
### Create a Vault and Upload Documents
|
|
606
689
|
|
|
607
690
|
```typescript
|
|
608
|
-
import { LifestreamVaultClient } from '@
|
|
691
|
+
import { LifestreamVaultClient } from '@lifestreamdynamics/vault-sdk';
|
|
609
692
|
|
|
610
693
|
const client = new LifestreamVaultClient({
|
|
611
|
-
baseUrl: 'https://vault.
|
|
694
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
612
695
|
apiKey: 'lsv_k_your_api_key',
|
|
613
696
|
});
|
|
614
697
|
|
|
@@ -680,12 +763,12 @@ console.log('AI:', response2.message);
|
|
|
680
763
|
### Automated Backup Script
|
|
681
764
|
|
|
682
765
|
```typescript
|
|
683
|
-
import { LifestreamVaultClient } from '@
|
|
766
|
+
import { LifestreamVaultClient } from '@lifestreamdynamics/vault-sdk';
|
|
684
767
|
import fs from 'fs/promises';
|
|
685
768
|
import path from 'path';
|
|
686
769
|
|
|
687
770
|
const client = new LifestreamVaultClient({
|
|
688
|
-
baseUrl: 'https://vault.
|
|
771
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
689
772
|
apiKey: process.env.LSVAULT_API_KEY!,
|
|
690
773
|
});
|
|
691
774
|
|
|
@@ -769,7 +852,7 @@ import {
|
|
|
769
852
|
ConflictError, // Resource conflict (e.g., duplicate slug)
|
|
770
853
|
RateLimitError, // Rate limit exceeded
|
|
771
854
|
NetworkError, // Network or connection error
|
|
772
|
-
} from '@
|
|
855
|
+
} from '@lifestreamdynamics/vault-sdk';
|
|
773
856
|
```
|
|
774
857
|
|
|
775
858
|
### Handling Specific Errors
|
|
@@ -803,7 +886,7 @@ error.context // Additional error context (resource type, ID, etc.)
|
|
|
803
886
|
### Retry Logic Example
|
|
804
887
|
|
|
805
888
|
```typescript
|
|
806
|
-
import { RateLimitError, NetworkError } from '@
|
|
889
|
+
import { RateLimitError, NetworkError } from '@lifestreamdynamics/vault-sdk';
|
|
807
890
|
|
|
808
891
|
async function fetchWithRetry(operation: () => Promise<any>, maxRetries = 3) {
|
|
809
892
|
for (let i = 0; i < maxRetries; i++) {
|
|
@@ -845,7 +928,7 @@ import {
|
|
|
845
928
|
type Team,
|
|
846
929
|
type ApiKey,
|
|
847
930
|
type Subscription,
|
|
848
|
-
} from '@
|
|
931
|
+
} from '@lifestreamdynamics/vault-sdk';
|
|
849
932
|
```
|
|
850
933
|
|
|
851
934
|
### Type Safety
|
|
@@ -868,7 +951,7 @@ doc.document.sizeBytes; // number
|
|
|
868
951
|
### Generic Error Handling
|
|
869
952
|
|
|
870
953
|
```typescript
|
|
871
|
-
import { SDKError } from '@
|
|
954
|
+
import { SDKError } from '@lifestreamdynamics/vault-sdk';
|
|
872
955
|
|
|
873
956
|
try {
|
|
874
957
|
await client.vaults.get('invalid-id');
|
|
@@ -888,7 +971,7 @@ Automatically enabled for API key authentication. Adds signature headers to muta
|
|
|
888
971
|
|
|
889
972
|
```typescript
|
|
890
973
|
const client = new LifestreamVaultClient({
|
|
891
|
-
baseUrl: 'https://vault.
|
|
974
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
892
975
|
apiKey: 'lsv_k_your_api_key',
|
|
893
976
|
enableRequestSigning: true, // Default: true for API keys
|
|
894
977
|
});
|
|
@@ -897,10 +980,34 @@ const client = new LifestreamVaultClient({
|
|
|
897
980
|
await client.documents.put('vault-id', 'doc.md', 'content');
|
|
898
981
|
```
|
|
899
982
|
|
|
983
|
+
**How Request Signing Works:**
|
|
984
|
+
|
|
985
|
+
The SDK automatically signs write operations (PUT, DELETE on documents) using HMAC-SHA256. The signature is computed from a canonical payload that includes:
|
|
986
|
+
|
|
987
|
+
1. **HTTP Method** (uppercase, e.g., `PUT`)
|
|
988
|
+
2. **Request Path** (full pathname including `/api/v1` prefix, e.g., `/api/v1/vaults/{id}/documents/path.md`)
|
|
989
|
+
3. **ISO Timestamp** (must be within 5 minutes of server time)
|
|
990
|
+
4. **Nonce** (16-byte hex string for replay protection)
|
|
991
|
+
5. **Body Hash** (SHA-256 hash of the request body)
|
|
992
|
+
|
|
993
|
+
The payload format is: `METHOD\nPATH\nTIMESTAMP\nNONCE\nBODY_HASH`
|
|
994
|
+
|
|
995
|
+
The HMAC signature is computed using your full API key as the secret, and three headers are attached to the request:
|
|
996
|
+
|
|
997
|
+
- `X-Signature` - The HMAC-SHA256 signature (hex-encoded)
|
|
998
|
+
- `X-Signature-Timestamp` - ISO-8601 timestamp
|
|
999
|
+
- `X-Signature-Nonce` - 16-byte hex nonce (unique per request)
|
|
1000
|
+
|
|
1001
|
+
**Security Features:**
|
|
1002
|
+
|
|
1003
|
+
- **Timestamp validation**: Requests older than 5 minutes are rejected, preventing replay attacks
|
|
1004
|
+
- **Nonce tracking**: Each nonce can only be used once within a 10-minute window (enforced via Redis)
|
|
1005
|
+
- **Constant-time comparison**: Prevents timing attacks during signature verification
|
|
1006
|
+
|
|
900
1007
|
**Manual Signing:**
|
|
901
1008
|
|
|
902
1009
|
```typescript
|
|
903
|
-
import { signRequest } from '@
|
|
1010
|
+
import { signRequest } from '@lifestreamdynamics/vault-sdk';
|
|
904
1011
|
|
|
905
1012
|
const headers = signRequest(
|
|
906
1013
|
'lsv_k_your_api_key',
|
|
@@ -909,9 +1016,9 @@ const headers = signRequest(
|
|
|
909
1016
|
JSON.stringify({ name: 'My Vault' }),
|
|
910
1017
|
);
|
|
911
1018
|
|
|
912
|
-
console.log(headers['
|
|
913
|
-
console.log(headers['
|
|
914
|
-
console.log(headers['
|
|
1019
|
+
console.log(headers['x-signature']); // HMAC signature
|
|
1020
|
+
console.log(headers['x-signature-timestamp']); // ISO timestamp
|
|
1021
|
+
console.log(headers['x-signature-nonce']); // Random nonce
|
|
915
1022
|
```
|
|
916
1023
|
|
|
917
1024
|
### Audit Logging
|
|
@@ -920,7 +1027,7 @@ Enable client-side request logging for compliance and debugging.
|
|
|
920
1027
|
|
|
921
1028
|
```typescript
|
|
922
1029
|
const client = new LifestreamVaultClient({
|
|
923
|
-
baseUrl: 'https://vault.
|
|
1030
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
924
1031
|
apiKey: 'lsv_k_your_api_key',
|
|
925
1032
|
enableAuditLogging: true,
|
|
926
1033
|
auditLogPath: '/var/log/lsvault/audit.log',
|
|
@@ -936,7 +1043,7 @@ await client.vaults.list();
|
|
|
936
1043
|
**Standalone Audit Logger:**
|
|
937
1044
|
|
|
938
1045
|
```typescript
|
|
939
|
-
import { AuditLogger } from '@
|
|
1046
|
+
import { AuditLogger } from '@lifestreamdynamics/vault-sdk';
|
|
940
1047
|
|
|
941
1048
|
const logger = new AuditLogger({ logPath: './custom-audit.log' });
|
|
942
1049
|
|
|
@@ -954,7 +1061,7 @@ logger.log({
|
|
|
954
1061
|
Encrypt vault content client-side before uploading (requires encryption-enabled vault).
|
|
955
1062
|
|
|
956
1063
|
```typescript
|
|
957
|
-
import { generateVaultKey, encryptContent, decryptContent } from '@
|
|
1064
|
+
import { generateVaultKey, encryptContent, decryptContent } from '@lifestreamdynamics/vault-sdk';
|
|
958
1065
|
|
|
959
1066
|
// Generate a vault encryption key (save this securely!)
|
|
960
1067
|
const vaultKey = generateVaultKey();
|
|
@@ -983,7 +1090,7 @@ console.log(decrypted); // Original plaintext
|
|
|
983
1090
|
### Token Management Utilities
|
|
984
1091
|
|
|
985
1092
|
```typescript
|
|
986
|
-
import { decodeJwtPayload, isTokenExpired } from '@
|
|
1093
|
+
import { decodeJwtPayload, isTokenExpired } from '@lifestreamdynamics/vault-sdk';
|
|
987
1094
|
|
|
988
1095
|
const token = 'eyJhbGci...';
|
|
989
1096
|
|
|
@@ -1003,7 +1110,7 @@ Access the underlying `ky` HTTP client for custom requests:
|
|
|
1003
1110
|
|
|
1004
1111
|
```typescript
|
|
1005
1112
|
const client = new LifestreamVaultClient({
|
|
1006
|
-
baseUrl: 'https://vault.
|
|
1113
|
+
baseUrl: 'https://vault.lifestreamdynamics.com',
|
|
1007
1114
|
apiKey: 'lsv_k_your_api_key',
|
|
1008
1115
|
});
|
|
1009
1116
|
|
|
@@ -1012,7 +1119,7 @@ const response = await client.http.get('custom/endpoint').json();
|
|
|
1012
1119
|
|
|
1013
1120
|
// The client is pre-configured with:
|
|
1014
1121
|
// - Authentication headers
|
|
1015
|
-
// - Base URL (https://vault.
|
|
1122
|
+
// - Base URL (https://vault.lifestreamdynamics.com/api/v1)
|
|
1016
1123
|
// - Timeout settings
|
|
1017
1124
|
// - Request signing (if enabled)
|
|
1018
1125
|
```
|
|
@@ -1032,8 +1139,7 @@ For complete API documentation, guides, and examples, visit:
|
|
|
1032
1139
|
|
|
1033
1140
|
## 🔗 Related Packages
|
|
1034
1141
|
|
|
1035
|
-
- **[@
|
|
1036
|
-
- **[@lifestream-vault/shared](https://www.npmjs.com/package/@lifestream-vault/shared)** - Shared types and schemas
|
|
1142
|
+
- **[@lifestreamdynamics/vault-cli](https://www.npmjs.com/package/@lifestreamdynamics/vault-cli)** - Command-line interface for Lifestream Vault
|
|
1037
1143
|
|
|
1038
1144
|
## 🐛 Troubleshooting
|
|
1039
1145
|
|
|
@@ -1105,7 +1211,7 @@ Need help? We're here for you!
|
|
|
1105
1211
|
- **Documentation**: [vault.lifestreamdynamics.com/docs](https://vault.lifestreamdynamics.com/docs)
|
|
1106
1212
|
|
|
1107
1213
|
When reporting issues, please include:
|
|
1108
|
-
- SDK version (`npm list @
|
|
1214
|
+
- SDK version (`npm list @lifestreamdynamics/vault-sdk`)
|
|
1109
1215
|
- Node.js version (`node --version`)
|
|
1110
1216
|
- Error messages and stack traces
|
|
1111
1217
|
- Minimal reproduction code (without sensitive credentials)
|
package/dist/client.d.ts
CHANGED
|
@@ -13,13 +13,18 @@ import { ConnectorsResource } from './resources/connectors.js';
|
|
|
13
13
|
import { AdminResource } from './resources/admin.js';
|
|
14
14
|
import { HooksResource } from './resources/hooks.js';
|
|
15
15
|
import { WebhooksResource } from './resources/webhooks.js';
|
|
16
|
+
import { MfaResource } from './resources/mfa.js';
|
|
17
|
+
import { CalendarResource } from './resources/calendar.js';
|
|
16
18
|
import { TokenManager, type AuthTokens, type OnTokenRefresh } from './lib/token-manager.js';
|
|
19
|
+
import type { MfaMethod } from './types/api.js';
|
|
20
|
+
/** Default API URL used when `baseUrl` is not provided. */
|
|
21
|
+
export declare const DEFAULT_API_URL = "https://vault.lifestreamdynamics.com";
|
|
17
22
|
/**
|
|
18
23
|
* Configuration options for creating a {@link LifestreamVaultClient}.
|
|
19
24
|
*/
|
|
20
25
|
export interface ClientOptions {
|
|
21
|
-
/** Base URL of the Lifestream Vault API server
|
|
22
|
-
baseUrl
|
|
26
|
+
/** Base URL of the Lifestream Vault API server. Defaults to `'https://vault.lifestreamdynamics.com'`. */
|
|
27
|
+
baseUrl?: string;
|
|
23
28
|
/** API key for authentication (prefix `lsv_k_`). Provide either this or `accessToken`. */
|
|
24
29
|
apiKey?: string;
|
|
25
30
|
/** JWT access token for authentication. Provide either this or `apiKey`. */
|
|
@@ -48,12 +53,14 @@ export interface ClientOptions {
|
|
|
48
53
|
* {@link ApiKeysResource | apiKeys}, {@link UserResource | user},
|
|
49
54
|
* {@link SubscriptionResource | subscription}, and {@link TeamsResource | teams}.
|
|
50
55
|
*
|
|
56
|
+
* When `baseUrl` is omitted, it defaults to `'https://vault.lifestreamdynamics.com'`.
|
|
57
|
+
*
|
|
51
58
|
* @example
|
|
52
59
|
* ```typescript
|
|
53
|
-
* import { LifestreamVaultClient } from '@
|
|
60
|
+
* import { LifestreamVaultClient } from '@lifestreamdynamics/vault-sdk';
|
|
54
61
|
*
|
|
62
|
+
* // Uses the default production URL
|
|
55
63
|
* const client = new LifestreamVaultClient({
|
|
56
|
-
* baseUrl: 'https://vault.example.com',
|
|
57
64
|
* apiKey: 'lsv_k_your_api_key',
|
|
58
65
|
* });
|
|
59
66
|
*
|
|
@@ -62,7 +69,7 @@ export interface ClientOptions {
|
|
|
62
69
|
*
|
|
63
70
|
* @example
|
|
64
71
|
* ```typescript
|
|
65
|
-
* // Using a
|
|
72
|
+
* // Using a custom base URL and JWT access token
|
|
66
73
|
* const client = new LifestreamVaultClient({
|
|
67
74
|
* baseUrl: 'https://vault.example.com',
|
|
68
75
|
* accessToken: 'eyJhbGci...',
|
|
@@ -103,17 +110,21 @@ export declare class LifestreamVaultClient {
|
|
|
103
110
|
readonly hooks: HooksResource;
|
|
104
111
|
/** Vault webhook management (outbound HTTP notifications). */
|
|
105
112
|
readonly webhooks: WebhooksResource;
|
|
113
|
+
/** Multi-factor authentication management (TOTP, passkeys, backup codes). */
|
|
114
|
+
readonly mfa: MfaResource;
|
|
115
|
+
/** Calendar, activity, and due date operations. */
|
|
116
|
+
readonly calendar: CalendarResource;
|
|
106
117
|
/** Token manager for JWT auto-refresh (null when using API key auth). */
|
|
107
118
|
readonly tokenManager: TokenManager | null;
|
|
108
119
|
/**
|
|
109
120
|
* Creates a new Lifestream Vault API client.
|
|
110
121
|
*
|
|
111
122
|
* @param options - Client configuration options
|
|
112
|
-
* @param options.baseUrl - Base URL of the API server (trailing slashes are stripped)
|
|
123
|
+
* @param options.baseUrl - Base URL of the API server (trailing slashes are stripped). Defaults to `'https://vault.lifestreamdynamics.com'`.
|
|
113
124
|
* @param options.apiKey - API key for authentication (mutually exclusive with `accessToken`)
|
|
114
125
|
* @param options.accessToken - JWT access token (mutually exclusive with `apiKey`)
|
|
115
126
|
* @param options.timeout - Request timeout in milliseconds (default: 30000)
|
|
116
|
-
* @throws {ValidationError} If
|
|
127
|
+
* @throws {ValidationError} If neither `apiKey` nor `accessToken` is provided
|
|
117
128
|
*
|
|
118
129
|
* @example
|
|
119
130
|
* ```typescript
|
|
@@ -128,13 +139,59 @@ export declare class LifestreamVaultClient {
|
|
|
128
139
|
* Authenticate with email and password to obtain JWT tokens.
|
|
129
140
|
* Returns an authenticated client instance with token management.
|
|
130
141
|
*
|
|
131
|
-
*
|
|
142
|
+
* If the account has MFA enabled, either provide `mfaCode` directly or use
|
|
143
|
+
* the `onMfaRequired` callback to prompt for the code interactively.
|
|
144
|
+
*
|
|
145
|
+
* @param baseUrl - Base URL of the API server. Defaults to `'https://vault.lifestreamdynamics.com'`.
|
|
132
146
|
* @param email - User email address
|
|
133
147
|
* @param password - User password
|
|
134
148
|
* @param options - Additional client options (timeout, refreshBufferMs, onTokenRefresh, etc.)
|
|
149
|
+
* @param mfaOptions - MFA handling options
|
|
150
|
+
* @param mfaOptions.mfaCode - Optional MFA code to provide upfront (TOTP or backup code)
|
|
151
|
+
* @param mfaOptions.onMfaRequired - Optional callback to handle MFA challenges interactively
|
|
135
152
|
* @returns A new authenticated client with the access/refresh tokens used
|
|
153
|
+
* @throws {ValidationError} If MFA is required but no MFA options are provided
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Login with MFA code provided upfront
|
|
158
|
+
* const { client } = await LifestreamVaultClient.login(
|
|
159
|
+
* undefined,
|
|
160
|
+
* 'user@example.com',
|
|
161
|
+
* 'password123',
|
|
162
|
+
* {},
|
|
163
|
+
* { mfaCode: '123456' }
|
|
164
|
+
* );
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Login with interactive MFA prompt
|
|
170
|
+
* const { client } = await LifestreamVaultClient.login(
|
|
171
|
+
* undefined,
|
|
172
|
+
* 'user@example.com',
|
|
173
|
+
* 'password123',
|
|
174
|
+
* {},
|
|
175
|
+
* {
|
|
176
|
+
* onMfaRequired: async (challenge) => {
|
|
177
|
+
* console.log('MFA required. Available methods:', challenge.methods);
|
|
178
|
+
* const code = await promptUserForCode(); // Your input function
|
|
179
|
+
* return { method: 'totp', code };
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* );
|
|
183
|
+
* ```
|
|
136
184
|
*/
|
|
137
|
-
static login(baseUrl: string, email: string, password: string, options?: Omit<ClientOptions, 'baseUrl' | 'apiKey' | 'accessToken' | 'refreshToken'
|
|
185
|
+
static login(baseUrl: string | undefined, email: string, password: string, options?: Omit<ClientOptions, 'baseUrl' | 'apiKey' | 'accessToken' | 'refreshToken'>, mfaOptions?: {
|
|
186
|
+
mfaCode?: string;
|
|
187
|
+
onMfaRequired?: (challenge: {
|
|
188
|
+
methods: MfaMethod[];
|
|
189
|
+
mfaToken: string;
|
|
190
|
+
}) => Promise<{
|
|
191
|
+
method: 'totp' | 'backup_code';
|
|
192
|
+
code: string;
|
|
193
|
+
}>;
|
|
194
|
+
}): Promise<{
|
|
138
195
|
client: LifestreamVaultClient;
|
|
139
196
|
tokens: AuthTokens;
|
|
140
197
|
refreshToken: string | null;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +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,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
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,CA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