@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,130 @@
1
+ import type { KyInstance } from 'ky';
2
+ /** A share link for a document. */
3
+ export interface ShareLink {
4
+ /** Unique share link identifier. */
5
+ id: string;
6
+ /** ID of the shared document. */
7
+ documentId: string;
8
+ /** ID of the vault containing the document. */
9
+ vaultId: string;
10
+ /** ID of the user who created the share link. */
11
+ createdBy: string;
12
+ /** First 8 characters of the share token (for identification). */
13
+ tokenPrefix: string;
14
+ /** Permission level granted by this link. */
15
+ permission: 'view' | 'edit';
16
+ /** ISO 8601 expiration timestamp, or `null` if the link never expires. */
17
+ expiresAt: string | null;
18
+ /** Maximum number of views allowed, or `null` for unlimited. */
19
+ maxViews: number | null;
20
+ /** Number of times the link has been viewed. */
21
+ viewCount: number;
22
+ /** Whether the share link is currently active. */
23
+ isActive: boolean;
24
+ /** ISO 8601 creation timestamp. */
25
+ createdAt: string;
26
+ }
27
+ /** Parameters for creating a new share link. */
28
+ export interface CreateShareLinkParams {
29
+ /** Permission level: `'view'` (default) or `'edit'`. */
30
+ permission?: 'view' | 'edit';
31
+ /** Optional password to protect the share link (min 4, max 128 chars). */
32
+ password?: string;
33
+ /** Optional ISO 8601 expiration date. */
34
+ expiresAt?: string;
35
+ /** Optional maximum number of views before the link expires. */
36
+ maxViews?: number;
37
+ }
38
+ /** Response from creating a share link, including the full token (shown only once). */
39
+ export interface CreateShareLinkResponse {
40
+ /** The created share link metadata. */
41
+ shareLink: ShareLink;
42
+ /** The full share token. Only returned at creation time; cannot be retrieved later. */
43
+ fullToken: string;
44
+ }
45
+ /**
46
+ * Resource for managing document share links.
47
+ *
48
+ * Share links provide token-based access to documents with optional password
49
+ * protection, expiration dates, and view limits. Links can grant either
50
+ * read-only (`view`) or read-write (`edit`) access.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Create a view-only share link that expires in 7 days
55
+ * const result = await client.shares.create('vault-id', 'notes/meeting.md', {
56
+ * permission: 'view',
57
+ * expiresAt: new Date(Date.now() + 7 * 86400000).toISOString(),
58
+ * });
59
+ * console.log('Share URL token:', result.fullToken);
60
+ * ```
61
+ */
62
+ export declare class SharesResource {
63
+ private http;
64
+ constructor(http: KyInstance);
65
+ /**
66
+ * Lists all share links for a specific document.
67
+ *
68
+ * @param vaultId - The vault ID containing the document
69
+ * @param documentPath - File path of the document (e.g., `'notes/meeting.md'`)
70
+ * @returns Array of share link objects for the document
71
+ * @throws {NotFoundError} If the vault or document does not exist
72
+ * @throws {AuthenticationError} If the request is not authenticated
73
+ * @throws {NetworkError} If the request fails due to network issues
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const links = await client.shares.list('vault-id', 'notes/meeting.md');
78
+ * for (const link of links) {
79
+ * console.log(`${link.tokenPrefix}... (${link.permission}, views: ${link.viewCount})`);
80
+ * }
81
+ * ```
82
+ */
83
+ list(vaultId: string, documentPath: string): Promise<ShareLink[]>;
84
+ /**
85
+ * Creates a new share link for a document.
86
+ *
87
+ * The `fullToken` in the response is only returned at creation time and
88
+ * cannot be retrieved later. Store it securely or share it immediately.
89
+ *
90
+ * @param vaultId - The vault ID containing the document
91
+ * @param documentPath - File path of the document to share
92
+ * @param params - Optional share link parameters (permission, password, expiry, max views)
93
+ * @returns The created share link and its full token
94
+ * @throws {NotFoundError} If the vault or document does not exist
95
+ * @throws {AuthenticationError} If the request is not authenticated
96
+ * @throws {ValidationError} If the parameters are invalid
97
+ * @throws {NetworkError} If the request fails due to network issues
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Create a password-protected link with a view limit
102
+ * const result = await client.shares.create('vault-id', 'notes/secret.md', {
103
+ * permission: 'view',
104
+ * password: 'secure-password',
105
+ * maxViews: 10,
106
+ * });
107
+ * console.log('Token:', result.fullToken);
108
+ * ```
109
+ */
110
+ create(vaultId: string, documentPath: string, params?: CreateShareLinkParams): Promise<CreateShareLinkResponse>;
111
+ /**
112
+ * Revokes (deactivates) a share link.
113
+ *
114
+ * Once revoked, the share link can no longer be used to access the document.
115
+ * This action is irreversible.
116
+ *
117
+ * @param vaultId - The vault ID containing the shared document
118
+ * @param shareId - The unique identifier of the share link to revoke
119
+ * @throws {NotFoundError} If the share link does not exist
120
+ * @throws {AuthenticationError} If the request is not authenticated
121
+ * @throws {NetworkError} If the request fails due to network issues
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * await client.shares.revoke('vault-id', 'share-link-id');
126
+ * ```
127
+ */
128
+ revoke(vaultId: string, shareId: string): Promise<void>;
129
+ }
130
+ //# sourceMappingURL=shares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shares.d.ts","sourceRoot":"","sources":["../../src/resources/shares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,mCAAmC;AACnC,MAAM,WAAW,SAAS;IACxB,oCAAoC;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,WAAW,EAAE,MAAM,CAAC;IACpB,6C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+1,115 @@
1
+ import { handleError } from '../handle-error.js';
2
+ /**
3
+ * Resource for managing document share links.
4
+ *
5
+ * Share links provide token-based access to documents with optional password
6
+ * protection, expiration dates, and view limits. Links can grant either
7
+ * read-only (`view`) or read-write (`edit`) access.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Create a view-only share link that expires in 7 days
12
+ * const result = await client.shares.create('vault-id', 'notes/meeting.md', {
13
+ * permission: 'view',
14
+ * expiresAt: new Date(Date.now() + 7 * 86400000).toISOString(),
15
+ * });
16
+ * console.log('Share URL token:', result.fullToken);
17
+ * ```
18
+ */
19
+ export class SharesResource {
20
+ http;
21
+ constructor(http) {
22
+ this.http = http;
23
+ }
24
+ /**
25
+ * Lists all share links for a specific document.
26
+ *
27
+ * @param vaultId - The vault ID containing the document
28
+ * @param documentPath - File path of the document (e.g., `'notes/meeting.md'`)
29
+ * @returns Array of share link objects for the document
30
+ * @throws {NotFoundError} If the vault or document does not exist
31
+ * @throws {AuthenticationError} If the request is not authenticated
32
+ * @throws {NetworkError} If the request fails due to network issues
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const links = await client.shares.list('vault-id', 'notes/meeting.md');
37
+ * for (const link of links) {
38
+ * console.log(`${link.tokenPrefix}... (${link.permission}, views: ${link.viewCount})`);
39
+ * }
40
+ * ```
41
+ */
42
+ async list(vaultId, documentPath) {
43
+ try {
44
+ const data = await this.http
45
+ .get(`vaults/${vaultId}/shares/document/${documentPath}`)
46
+ .json();
47
+ return data.shareLinks;
48
+ }
49
+ catch (error) {
50
+ throw await handleError(error, 'Share Links', documentPath);
51
+ }
52
+ }
53
+ /**
54
+ * Creates a new share link for a document.
55
+ *
56
+ * The `fullToken` in the response is only returned at creation time and
57
+ * cannot be retrieved later. Store it securely or share it immediately.
58
+ *
59
+ * @param vaultId - The vault ID containing the document
60
+ * @param documentPath - File path of the document to share
61
+ * @param params - Optional share link parameters (permission, password, expiry, max views)
62
+ * @returns The created share link and its full token
63
+ * @throws {NotFoundError} If the vault or document does not exist
64
+ * @throws {AuthenticationError} If the request is not authenticated
65
+ * @throws {ValidationError} If the parameters are invalid
66
+ * @throws {NetworkError} If the request fails due to network issues
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Create a password-protected link with a view limit
71
+ * const result = await client.shares.create('vault-id', 'notes/secret.md', {
72
+ * permission: 'view',
73
+ * password: 'secure-password',
74
+ * maxViews: 10,
75
+ * });
76
+ * console.log('Token:', result.fullToken);
77
+ * ```
78
+ */
79
+ async create(vaultId, documentPath, params = {}) {
80
+ try {
81
+ return await this.http
82
+ .post(`vaults/${vaultId}/shares/document/${documentPath}`, { json: params })
83
+ .json();
84
+ }
85
+ catch (error) {
86
+ throw await handleError(error, 'Share Link', documentPath);
87
+ }
88
+ }
89
+ /**
90
+ * Revokes (deactivates) a share link.
91
+ *
92
+ * Once revoked, the share link can no longer be used to access the document.
93
+ * This action is irreversible.
94
+ *
95
+ * @param vaultId - The vault ID containing the shared document
96
+ * @param shareId - The unique identifier of the share link to revoke
97
+ * @throws {NotFoundError} If the share link does not exist
98
+ * @throws {AuthenticationError} If the request is not authenticated
99
+ * @throws {NetworkError} If the request fails due to network issues
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * await client.shares.revoke('vault-id', 'share-link-id');
104
+ * ```
105
+ */
106
+ async revoke(vaultId, shareId) {
107
+ try {
108
+ await this.http.delete(`vaults/${vaultId}/shares/${shareId}`);
109
+ }
110
+ catch (error) {
111
+ throw await handleError(error, 'Share Link', shareId);
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=shares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shares.js","sourceRoot":"","sources":["../../src/resources/shares.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgDjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAA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subscription {
4
+ /** Subscription tier, plan details, and status. */
5
+ subscription: {
6
+ tier: string;
7
+ expiresAt: string | null;
8
+ isActive: boolean;
9
+ };
10
+ /** Current resource usage counts. */
11
+ usage: {
12
+ vaultCount: number;
13
+ totalStorageBytes: number;
14
+ apiCallsToday: number;
15
+ aiTokens: number;
16
+ hookExecutions: number;
17
+ webhookDeliveries: number;
18
+ };
19
+ }
20
+ /** A subscription plan definition. */
21
+ export interface Plan {
22
+ /** Plan tier identifier. */
23
+ tier: string;
24
+ /** Human-readable plan name. */
25
+ name: string;
26
+ /** Plan resource limits. */
27
+ limits: Record<string, number>;
28
+ /** Plan feature flags. */
29
+ features: Record<string, boolean>;
30
+ }
31
+ /** A checkout session for upgrading subscription. */
32
+ export interface CheckoutSession {
33
+ /** URL to redirect the user to for payment. */
34
+ url: string;
35
+ /** Unique session identifier. */
36
+ sessionId: string;
37
+ }
38
+ /** A billing portal session. */
39
+ export interface PortalSession {
40
+ /** URL to redirect the user to for billing management. */
41
+ url: string;
42
+ }
43
+ /** An invoice record. */
44
+ export interface Invoice {
45
+ /** Unique invoice identifier. */
46
+ id: string;
47
+ /** Invoice amount in smallest currency unit. */
48
+ amount: number;
49
+ /** ISO 4217 currency code. */
50
+ currency: string;
51
+ /** Invoice status (e.g., `paid`, `open`, `void`). */
52
+ status: string;
53
+ /** ISO 8601 creation timestamp. */
54
+ createdAt: string;
55
+ /** ISO 8601 payment timestamp, or `null` if unpaid. */
56
+ paidAt: string | null;
57
+ /** URL to view the invoice, or `null`. */
58
+ invoiceUrl: string | null;
59
+ }
60
+ /**
61
+ * Resource for managing subscriptions and billing.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const sub = await client.subscription.get();
66
+ * console.log(`Plan: ${sub.subscription.tier}`);
67
+ *
68
+ * const plans = await client.subscription.listPlans();
69
+ * plans.forEach(p => console.log(p.name));
70
+ * ```
71
+ */
72
+ export declare class SubscriptionResource {
73
+ private http;
74
+ constructor(http: KyInstance);
75
+ /**
76
+ * Retrieves the current user's subscription details and usage.
77
+ *
78
+ * @returns Subscription object with usage breakdown
79
+ * @throws {AuthenticationError} If not authenticated
80
+ * @throws {NetworkError} If the request fails due to network issues
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const sub = await client.subscription.get();
85
+ * console.log(`Plan: ${sub.subscription.tier}, Active: ${sub.subscription.isActive}`);
86
+ * console.log(`Vaults: ${sub.usage.vaultCount}`);
87
+ * ```
88
+ */
89
+ get(): Promise<Subscription>;
90
+ /**
91
+ * Lists all available subscription plans.
92
+ *
93
+ * @returns Array of available plans
94
+ * @throws {AuthenticationError} If not authenticated
95
+ * @throws {NetworkError} If the request fails due to network issues
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const plans = await client.subscription.listPlans();
100
+ * plans.forEach(p => console.log(`${p.name}: ${JSON.stringify(p.limits)}`));
101
+ * ```
102
+ */
103
+ listPlans(): Promise<Plan[]>;
104
+ /**
105
+ * Creates a checkout session for upgrading to a paid plan.
106
+ *
107
+ * @param tier - Subscription tier to upgrade to (`pro` or `business`)
108
+ * @param returnUrl - URL to redirect after checkout completes
109
+ * @returns Checkout session with redirect URL
110
+ * @throws {AuthenticationError} If not authenticated
111
+ * @throws {ValidationError} If the tier is invalid or not an upgrade
112
+ * @throws {NetworkError} If the request fails due to network issues
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const session = await client.subscription.createCheckoutSession(
117
+ * 'pro',
118
+ * 'https://app.example.com/subscription/success'
119
+ * );
120
+ * console.log('Redirect to:', session.url);
121
+ * ```
122
+ */
123
+ createCheckoutSession(tier: string, returnUrl: string): Promise<CheckoutSession>;
124
+ /**
125
+ * Cancels the current subscription.
126
+ *
127
+ * @param reason - Optional cancellation reason
128
+ * @throws {AuthenticationError} If not authenticated
129
+ * @throws {ValidationError} If no active subscription exists
130
+ * @throws {NetworkError} If the request fails due to network issues
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * await client.subscription.cancel('Switching to self-hosted');
135
+ * ```
136
+ */
137
+ cancel(reason?: string): Promise<void>;
138
+ /**
139
+ * Creates a billing portal session for managing payment methods and invoices.
140
+ *
141
+ * @param returnUrl - URL to redirect after the portal session ends
142
+ * @returns Portal session with redirect URL
143
+ * @throws {AuthenticationError} If not authenticated
144
+ * @throws {NetworkError} If the request fails due to network issues
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const portal = await client.subscription.createPortalSession(
149
+ * 'https://app.example.com/settings/billing'
150
+ * );
151
+ * console.log('Redirect to:', portal.url);
152
+ * ```
153
+ */
154
+ createPortalSession(returnUrl: string): Promise<PortalSession>;
155
+ /**
156
+ * Lists all invoices for the current user.
157
+ *
158
+ * @returns Array of invoice records
159
+ * @throws {AuthenticationError} If not authenticated
160
+ * @throws {NetworkError} If the request fails due to network issues
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const invoices = await client.subscription.listInvoices();
165
+ * invoices.forEach(inv => {
166
+ * console.log(`${inv.createdAt}: ${inv.amount} ${inv.currency} - ${inv.status}`);
167
+ * });
168
+ * ```
169
+ */
170
+ listInvoices(): Promise<Invoice[]>;
171
+ }
172
+ //# sourceMappingURL=subscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/resources/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,qCAAqC;IACrC,KAAK,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,C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,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAUtF;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5C;;;;;;;;;;;;;;;OAeG;IACG,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAUpE;;;;;;;;;;;;;;OAcG;IACG,YAAY,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAQzC"}
@@ -0,0 +1,166 @@
1
+ import { handleError } from '../handle-error.js';
2
+ /**
3
+ * Resource for managing subscriptions and billing.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const sub = await client.subscription.get();
8
+ * console.log(`Plan: ${sub.subscription.tier}`);
9
+ *
10
+ * const plans = await client.subscription.listPlans();
11
+ * plans.forEach(p => console.log(p.name));
12
+ * ```
13
+ */
14
+ export class SubscriptionResource {
15
+ http;
16
+ constructor(http) {
17
+ this.http = http;
18
+ }
19
+ /**
20
+ * Retrieves the current user's subscription details and usage.
21
+ *
22
+ * @returns Subscription object with usage breakdown
23
+ * @throws {AuthenticationError} If not authenticated
24
+ * @throws {NetworkError} If the request fails due to network issues
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const sub = await client.subscription.get();
29
+ * console.log(`Plan: ${sub.subscription.tier}, Active: ${sub.subscription.isActive}`);
30
+ * console.log(`Vaults: ${sub.usage.vaultCount}`);
31
+ * ```
32
+ */
33
+ async get() {
34
+ try {
35
+ return await this.http.get('subscription').json();
36
+ }
37
+ catch (error) {
38
+ throw await handleError(error, 'Subscription', '');
39
+ }
40
+ }
41
+ /**
42
+ * Lists all available subscription plans.
43
+ *
44
+ * @returns Array of available plans
45
+ * @throws {AuthenticationError} If not authenticated
46
+ * @throws {NetworkError} If the request fails due to network issues
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const plans = await client.subscription.listPlans();
51
+ * plans.forEach(p => console.log(`${p.name}: ${JSON.stringify(p.limits)}`));
52
+ * ```
53
+ */
54
+ async listPlans() {
55
+ try {
56
+ const data = await this.http.get('subscription/plans').json();
57
+ return data.plans;
58
+ }
59
+ catch (error) {
60
+ throw await handleError(error, 'Plans', '');
61
+ }
62
+ }
63
+ /**
64
+ * Creates a checkout session for upgrading to a paid plan.
65
+ *
66
+ * @param tier - Subscription tier to upgrade to (`pro` or `business`)
67
+ * @param returnUrl - URL to redirect after checkout completes
68
+ * @returns Checkout session with redirect URL
69
+ * @throws {AuthenticationError} If not authenticated
70
+ * @throws {ValidationError} If the tier is invalid or not an upgrade
71
+ * @throws {NetworkError} If the request fails due to network issues
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const session = await client.subscription.createCheckoutSession(
76
+ * 'pro',
77
+ * 'https://app.example.com/subscription/success'
78
+ * );
79
+ * console.log('Redirect to:', session.url);
80
+ * ```
81
+ */
82
+ async createCheckoutSession(tier, returnUrl) {
83
+ try {
84
+ return await this.http.post('subscription/checkout', {
85
+ json: { tier, returnUrl },
86
+ }).json();
87
+ }
88
+ catch (error) {
89
+ throw await handleError(error, 'Checkout', '');
90
+ }
91
+ }
92
+ /**
93
+ * Cancels the current subscription.
94
+ *
95
+ * @param reason - Optional cancellation reason
96
+ * @throws {AuthenticationError} If not authenticated
97
+ * @throws {ValidationError} If no active subscription exists
98
+ * @throws {NetworkError} If the request fails due to network issues
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * await client.subscription.cancel('Switching to self-hosted');
103
+ * ```
104
+ */
105
+ async cancel(reason) {
106
+ try {
107
+ await this.http.post('subscription/cancel', {
108
+ json: { reason },
109
+ }).json();
110
+ }
111
+ catch (error) {
112
+ throw await handleError(error, 'Subscription', '');
113
+ }
114
+ }
115
+ /**
116
+ * Creates a billing portal session for managing payment methods and invoices.
117
+ *
118
+ * @param returnUrl - URL to redirect after the portal session ends
119
+ * @returns Portal session with redirect URL
120
+ * @throws {AuthenticationError} If not authenticated
121
+ * @throws {NetworkError} If the request fails due to network issues
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const portal = await client.subscription.createPortalSession(
126
+ * 'https://app.example.com/settings/billing'
127
+ * );
128
+ * console.log('Redirect to:', portal.url);
129
+ * ```
130
+ */
131
+ async createPortalSession(returnUrl) {
132
+ try {
133
+ return await this.http.post('subscription/portal', {
134
+ json: { returnUrl },
135
+ }).json();
136
+ }
137
+ catch (error) {
138
+ throw await handleError(error, 'Portal', '');
139
+ }
140
+ }
141
+ /**
142
+ * Lists all invoices for the current user.
143
+ *
144
+ * @returns Array of invoice records
145
+ * @throws {AuthenticationError} If not authenticated
146
+ * @throws {NetworkError} If the request fails due to network issues
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const invoices = await client.subscription.listInvoices();
151
+ * invoices.forEach(inv => {
152
+ * console.log(`${inv.createdAt}: ${inv.amount} ${inv.currency} - ${inv.status}`);
153
+ * });
154
+ * ```
155
+ */
156
+ async listInvoices() {
157
+ try {
158
+ const data = await this.http.get('subscription/invoices').json();
159
+ return data.invoices;
160
+ }
161
+ catch (error) {
162
+ throw await handleError(error, 'Invoices', '');
163
+ }
164
+ }
165
+ }
166
+ //# sourceMappingURL=subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/resources/subscription.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAiEjD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,oBAAoB;IACX;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,GAAG;QACP,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,EAAgB,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAA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