@ketrics/sdk-backend 0.2.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 +329 -0
- package/dist/console.d.ts +34 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +9 -0
- package/dist/console.js.map +1 -0
- package/dist/context.d.ts +65 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/database-errors.d.ts +197 -0
- package/dist/database-errors.d.ts.map +1 -0
- package/dist/database-errors.js +258 -0
- package/dist/database-errors.js.map +1 -0
- package/dist/databases.d.ts +165 -0
- package/dist/databases.d.ts.map +1 -0
- package/dist/databases.js +31 -0
- package/dist/databases.js.map +1 -0
- package/dist/errors.d.ts +244 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +316 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +57 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +9 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +377 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/secret-errors.d.ts +128 -0
- package/dist/secret-errors.d.ts.map +1 -0
- package/dist/secret-errors.js +172 -0
- package/dist/secret-errors.js.map +1 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +27 -0
- package/dist/secrets.js.map +1 -0
- package/dist/volumes.d.ts +276 -0
- package/dist/volumes.d.ts.map +1 -0
- package/dist/volumes.js +9 -0
- package/dist/volumes.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ketrics SDK - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* TypeScript type definitions for building tenant applications
|
|
5
|
+
* on the Ketrics platform.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Import types only if needed for type annotations
|
|
12
|
+
* import type { FileContent, IVolume, IDatabaseConnection } from '@ketrics/sdk';
|
|
13
|
+
*
|
|
14
|
+
* export async function handler() {
|
|
15
|
+
* // Access the global ketrics object (auto-typed)
|
|
16
|
+
* console.log(ketrics.tenant.name);
|
|
17
|
+
* console.log(ketrics.user.email);
|
|
18
|
+
*
|
|
19
|
+
* // Use ketrics.Volume.connect() for S3 storage
|
|
20
|
+
* try {
|
|
21
|
+
* const volume = await ketrics.Volume.connect('uploads');
|
|
22
|
+
* const file = await volume.get('documents/report.pdf');
|
|
23
|
+
* return { contentType: file.contentType, size: file.contentLength };
|
|
24
|
+
* } catch (error) {
|
|
25
|
+
* if (error instanceof ketrics.VolumeNotFoundError) {
|
|
26
|
+
* return { error: `Volume not found: ${error.volumeCode}` };
|
|
27
|
+
* }
|
|
28
|
+
* throw error;
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Use ketrics.DatabaseConnection.connect() for databases
|
|
32
|
+
* try {
|
|
33
|
+
* const db = await ketrics.DatabaseConnection.connect('main-db');
|
|
34
|
+
* const result = await db.query('SELECT * FROM users');
|
|
35
|
+
* await db.close();
|
|
36
|
+
* return { users: result.rows };
|
|
37
|
+
* } catch (error) {
|
|
38
|
+
* if (error instanceof ketrics.DatabaseNotFoundError) {
|
|
39
|
+
* return { error: `Database not found: ${error.databaseCode}` };
|
|
40
|
+
* }
|
|
41
|
+
* throw error;
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* // Use ketrics.Secret.get() for secrets
|
|
45
|
+
* try {
|
|
46
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
47
|
+
* // Use the API key
|
|
48
|
+
* } catch (error) {
|
|
49
|
+
* if (error instanceof ketrics.SecretNotFoundError) {
|
|
50
|
+
* return { error: `Secret not found: ${error.secretCode}` };
|
|
51
|
+
* }
|
|
52
|
+
* throw error;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export { TenantContext, ApplicationContext, UserContext, EnvironmentContext, } from './context';
|
|
58
|
+
export { ConsoleLogger } from './console';
|
|
59
|
+
export { HttpRequestConfig, HttpResponse, HttpClient } from './http';
|
|
60
|
+
export { DatabaseQueryResult, DatabaseExecuteResult, IDatabaseConnection, DatabaseManager, } from './databases';
|
|
61
|
+
export { DatabaseError, DatabaseNotFoundError, DatabaseAccessDeniedError, DatabaseConnectionError, DatabaseQueryError, DatabaseTransactionError, isDatabaseError, isDatabaseErrorType, } from './database-errors';
|
|
62
|
+
export { ISecret } from './secrets';
|
|
63
|
+
export { SecretError, SecretNotFoundError, SecretAccessDeniedError, SecretDecryptionError, isSecretError, isSecretErrorType, } from './secret-errors';
|
|
64
|
+
export { PutContent, FileContent, FileMetadata, FileInfo, PutOptions, PutResult, DeleteResult, DeleteError, DeleteByPrefixResult, ListOptions, ListResult, CopyOptions, CopyResult, MoveOptions, MoveResult, DownloadUrlOptions, UploadUrlOptions, PresignedUrl, IVolume, } from './volumes';
|
|
65
|
+
export { VolumePermissionValue, VolumeError, VolumeNotFoundError, VolumeAccessDeniedError, VolumePermissionDeniedError, FileNotFoundError, FileAlreadyExistsError, InvalidPathError, FileSizeLimitError, ContentTypeNotAllowedError, isVolumeError, isVolumeErrorType, } from './errors';
|
|
66
|
+
import type { TenantContext, ApplicationContext, UserContext, EnvironmentContext } from './context';
|
|
67
|
+
import type { ConsoleLogger } from './console';
|
|
68
|
+
import type { HttpClient } from './http';
|
|
69
|
+
import type { IDatabaseConnection } from './databases';
|
|
70
|
+
import type { IVolume } from './volumes';
|
|
71
|
+
import { VolumeError as VolumeErrorClass, VolumeNotFoundError as VolumeNotFoundErrorClass, VolumeAccessDeniedError as VolumeAccessDeniedErrorClass, VolumePermissionDeniedError as VolumePermissionDeniedErrorClass, FileNotFoundError as FileNotFoundErrorClass, FileAlreadyExistsError as FileAlreadyExistsErrorClass, InvalidPathError as InvalidPathErrorClass, FileSizeLimitError as FileSizeLimitErrorClass, ContentTypeNotAllowedError as ContentTypeNotAllowedErrorClass } from './errors';
|
|
72
|
+
import { DatabaseError as DatabaseErrorClass, DatabaseNotFoundError as DatabaseNotFoundErrorClass, DatabaseAccessDeniedError as DatabaseAccessDeniedErrorClass, DatabaseConnectionError as DatabaseConnectionErrorClass, DatabaseQueryError as DatabaseQueryErrorClass, DatabaseTransactionError as DatabaseTransactionErrorClass } from './database-errors';
|
|
73
|
+
import { SecretError as SecretErrorClass, SecretNotFoundError as SecretNotFoundErrorClass, SecretAccessDeniedError as SecretAccessDeniedErrorClass, SecretDecryptionError as SecretDecryptionErrorClass } from './secret-errors';
|
|
74
|
+
/**
|
|
75
|
+
* Ketrics Platform SDK Interface
|
|
76
|
+
*
|
|
77
|
+
* The complete SDK interface available as the global `ketrics` object
|
|
78
|
+
* in tenant application code.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Access tenant context
|
|
83
|
+
* console.log(ketrics.tenant.name);
|
|
84
|
+
* console.log(ketrics.application.code);
|
|
85
|
+
* console.log(ketrics.user.email);
|
|
86
|
+
* console.log(ketrics.env.region);
|
|
87
|
+
*
|
|
88
|
+
* // Use console logging (forwarded to CloudWatch)
|
|
89
|
+
* ketrics.console.log('Processing request...');
|
|
90
|
+
* ketrics.console.error('Something went wrong');
|
|
91
|
+
*
|
|
92
|
+
* // Make HTTP requests
|
|
93
|
+
* const response = await ketrics.http.get('https://api.example.com/data');
|
|
94
|
+
* console.log(response.data);
|
|
95
|
+
*
|
|
96
|
+
* // Access databases (new static factory pattern)
|
|
97
|
+
* const db = await ketrics.DatabaseConnection.connect('main-db');
|
|
98
|
+
* const result = await db.query('SELECT * FROM users');
|
|
99
|
+
* await db.close();
|
|
100
|
+
*
|
|
101
|
+
* // Access secrets
|
|
102
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
103
|
+
*
|
|
104
|
+
* // Access volumes
|
|
105
|
+
* const volume = await ketrics.Volume.connect('uploads');
|
|
106
|
+
* const file = await volume.get('document.pdf');
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export interface KetricsSdkV1 {
|
|
110
|
+
/** Current tenant information */
|
|
111
|
+
tenant: TenantContext;
|
|
112
|
+
/** Current application information */
|
|
113
|
+
application: ApplicationContext;
|
|
114
|
+
/** Current user information */
|
|
115
|
+
user: UserContext;
|
|
116
|
+
/** Runtime environment information */
|
|
117
|
+
env: EnvironmentContext;
|
|
118
|
+
/** Console logging (forwarded to CloudWatch) */
|
|
119
|
+
console: ConsoleLogger;
|
|
120
|
+
/** HTTP client for external API requests */
|
|
121
|
+
http: HttpClient;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Volume - S3-backed storage for tenant applications
|
|
125
|
+
*
|
|
126
|
+
* Access via `ketrics.Volume.connect()` to obtain an instance.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* export async function handler() {
|
|
131
|
+
* try {
|
|
132
|
+
* // Connect to a volume via ketrics object
|
|
133
|
+
* const volume = await ketrics.Volume.connect('uploads');
|
|
134
|
+
*
|
|
135
|
+
* // Read a file
|
|
136
|
+
* const file = await volume.get('documents/report.pdf');
|
|
137
|
+
* console.log(file.contentType, file.contentLength);
|
|
138
|
+
*
|
|
139
|
+
* // Write a file
|
|
140
|
+
* const result = await volume.put('output/data.json', JSON.stringify(data));
|
|
141
|
+
* console.log('Uploaded:', result.key, result.etag);
|
|
142
|
+
*
|
|
143
|
+
* // List files
|
|
144
|
+
* const list = await volume.list({ prefix: 'documents/' });
|
|
145
|
+
* for (const file of list.files) {
|
|
146
|
+
* console.log(file.key, file.size);
|
|
147
|
+
* }
|
|
148
|
+
*
|
|
149
|
+
* } catch (error) {
|
|
150
|
+
* // Error classes are on the ketrics object
|
|
151
|
+
* if (error instanceof ketrics.VolumeNotFoundError) {
|
|
152
|
+
* console.log('Volume not found');
|
|
153
|
+
* } else if (error instanceof ketrics.FileNotFoundError) {
|
|
154
|
+
* console.log('File not found:', error.key);
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare class Volume {
|
|
161
|
+
private constructor();
|
|
162
|
+
/** Volume code (read-only) */
|
|
163
|
+
readonly code: string;
|
|
164
|
+
/** Granted permissions (read-only) */
|
|
165
|
+
readonly permissions: ReadonlySet<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Connect to a volume by code
|
|
168
|
+
*
|
|
169
|
+
* @param volumeCode - Volume code (e.g., "uploads", "documents")
|
|
170
|
+
* @returns Connected Volume instance
|
|
171
|
+
* @throws VolumeNotFoundError if volume doesn't exist
|
|
172
|
+
* @throws VolumeAccessDeniedError if application has no access grant
|
|
173
|
+
*/
|
|
174
|
+
static connect(volumeCode: string): Promise<IVolume>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* DatabaseConnection - External database access for tenant applications
|
|
178
|
+
*
|
|
179
|
+
* Access via `ketrics.DatabaseConnection.connect()` to obtain an instance.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* export async function handler() {
|
|
184
|
+
* try {
|
|
185
|
+
* // Connect to a database
|
|
186
|
+
* const db = await ketrics.DatabaseConnection.connect('main-db');
|
|
187
|
+
*
|
|
188
|
+
* // Query data
|
|
189
|
+
* const result = await db.query('SELECT * FROM users WHERE id = ?', [1]);
|
|
190
|
+
* console.log(result.rows);
|
|
191
|
+
*
|
|
192
|
+
* // Execute statement
|
|
193
|
+
* await db.execute('INSERT INTO users (name, email) VALUES (?, ?)', ['John', 'john@example.com']);
|
|
194
|
+
*
|
|
195
|
+
* // Transaction
|
|
196
|
+
* await db.transaction(async (tx) => {
|
|
197
|
+
* await tx.execute('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 1]);
|
|
198
|
+
* await tx.execute('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 2]);
|
|
199
|
+
* });
|
|
200
|
+
*
|
|
201
|
+
* // Close connection
|
|
202
|
+
* await db.close();
|
|
203
|
+
*
|
|
204
|
+
* } catch (error) {
|
|
205
|
+
* if (error instanceof ketrics.DatabaseNotFoundError) {
|
|
206
|
+
* console.log('Database not found');
|
|
207
|
+
* } else if (error instanceof ketrics.DatabaseAccessDeniedError) {
|
|
208
|
+
* console.log('No access to database');
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export declare class DatabaseConnection {
|
|
215
|
+
private constructor();
|
|
216
|
+
/** Database code (read-only) */
|
|
217
|
+
readonly code: string;
|
|
218
|
+
/** Granted permissions (read-only) */
|
|
219
|
+
readonly permissions: ReadonlySet<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Connect to a database by code
|
|
222
|
+
*
|
|
223
|
+
* @param databaseCode - Database code (e.g., "main-db", "analytics-db")
|
|
224
|
+
* @returns Connected DatabaseConnection instance
|
|
225
|
+
* @throws DatabaseNotFoundError if database doesn't exist
|
|
226
|
+
* @throws DatabaseAccessDeniedError if application has no access grant
|
|
227
|
+
* @throws DatabaseConnectionError if connection cannot be established
|
|
228
|
+
*/
|
|
229
|
+
static connect(databaseCode: string): Promise<IDatabaseConnection>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Secret - Encrypted secret values for tenant applications
|
|
233
|
+
*
|
|
234
|
+
* Access via `ketrics.Secret.get()` to retrieve secret values.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* export async function handler() {
|
|
239
|
+
* try {
|
|
240
|
+
* // Get a secret value
|
|
241
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
242
|
+
* console.log('API Key retrieved');
|
|
243
|
+
*
|
|
244
|
+
* // Check if a secret exists
|
|
245
|
+
* if (await ketrics.Secret.exists('optional-api-key')) {
|
|
246
|
+
* const key = await ketrics.Secret.get('optional-api-key');
|
|
247
|
+
* // Use the key
|
|
248
|
+
* }
|
|
249
|
+
*
|
|
250
|
+
* } catch (error) {
|
|
251
|
+
* if (error instanceof ketrics.SecretNotFoundError) {
|
|
252
|
+
* console.log('Secret not found');
|
|
253
|
+
* } else if (error instanceof ketrics.SecretAccessDeniedError) {
|
|
254
|
+
* console.log('No access to secret');
|
|
255
|
+
* }
|
|
256
|
+
* }
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export declare class Secret {
|
|
261
|
+
private constructor();
|
|
262
|
+
/**
|
|
263
|
+
* Get a secret value by code
|
|
264
|
+
*
|
|
265
|
+
* @param secretCode - Secret code (e.g., "api-key", "db-password")
|
|
266
|
+
* @returns The decrypted secret value
|
|
267
|
+
* @throws SecretNotFoundError if secret doesn't exist
|
|
268
|
+
* @throws SecretAccessDeniedError if application has no access grant
|
|
269
|
+
* @throws SecretDecryptionError if decryption fails
|
|
270
|
+
*/
|
|
271
|
+
static get(secretCode: string): Promise<string>;
|
|
272
|
+
/**
|
|
273
|
+
* Check if a secret exists and is accessible
|
|
274
|
+
*
|
|
275
|
+
* @param secretCode - Secret code to check
|
|
276
|
+
* @returns True if secret exists and is accessible
|
|
277
|
+
*/
|
|
278
|
+
static exists(secretCode: string): Promise<boolean>;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Global declaration for the Ketrics VM sandbox.
|
|
282
|
+
*
|
|
283
|
+
* The `ketrics` global object provides:
|
|
284
|
+
* - Context: tenant, application, user, env
|
|
285
|
+
* - Utilities: console, http
|
|
286
|
+
* - Volume: Static class for S3 storage
|
|
287
|
+
* - DatabaseConnection: Static class for database access
|
|
288
|
+
* - Secret: Static class for secret retrieval
|
|
289
|
+
* - Error classes: For instanceof checks
|
|
290
|
+
*/
|
|
291
|
+
declare global {
|
|
292
|
+
/** Ketrics SDK global object - available in all tenant application code */
|
|
293
|
+
const ketrics: KetricsSdkV1 & {
|
|
294
|
+
/**
|
|
295
|
+
* Volume class for S3-backed storage
|
|
296
|
+
*
|
|
297
|
+
* Use `ketrics.Volume.connect()` to get a connected volume instance.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const volume = await ketrics.Volume.connect('uploads');
|
|
302
|
+
* const file = await volume.get('document.pdf');
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
Volume: {
|
|
306
|
+
connect(volumeCode: string): Promise<IVolume>;
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* DatabaseConnection class for external database access
|
|
310
|
+
*
|
|
311
|
+
* Use `ketrics.DatabaseConnection.connect()` to get a connected database instance.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const db = await ketrics.DatabaseConnection.connect('main-db');
|
|
316
|
+
* const result = await db.query('SELECT * FROM users');
|
|
317
|
+
* await db.close();
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
DatabaseConnection: {
|
|
321
|
+
connect(databaseCode: string): Promise<IDatabaseConnection>;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Secret class for encrypted secret retrieval
|
|
325
|
+
*
|
|
326
|
+
* Use `ketrics.Secret.get()` to retrieve a secret value.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
Secret: {
|
|
334
|
+
get(secretCode: string): Promise<string>;
|
|
335
|
+
exists(secretCode: string): Promise<boolean>;
|
|
336
|
+
};
|
|
337
|
+
/** Base class for all volume errors */
|
|
338
|
+
VolumeError: typeof VolumeErrorClass;
|
|
339
|
+
/** Thrown when a volume does not exist */
|
|
340
|
+
VolumeNotFoundError: typeof VolumeNotFoundErrorClass;
|
|
341
|
+
/** Thrown when application has no access grant to volume */
|
|
342
|
+
VolumeAccessDeniedError: typeof VolumeAccessDeniedErrorClass;
|
|
343
|
+
/** Thrown when operation requires a permission not granted */
|
|
344
|
+
VolumePermissionDeniedError: typeof VolumePermissionDeniedErrorClass;
|
|
345
|
+
/** Thrown when a file does not exist */
|
|
346
|
+
FileNotFoundError: typeof FileNotFoundErrorClass;
|
|
347
|
+
/** Thrown when file already exists (with ifNotExists option) */
|
|
348
|
+
FileAlreadyExistsError: typeof FileAlreadyExistsErrorClass;
|
|
349
|
+
/** Thrown when file path is invalid */
|
|
350
|
+
InvalidPathError: typeof InvalidPathErrorClass;
|
|
351
|
+
/** Thrown when file exceeds size limit */
|
|
352
|
+
FileSizeLimitError: typeof FileSizeLimitErrorClass;
|
|
353
|
+
/** Thrown when content type is not allowed */
|
|
354
|
+
ContentTypeNotAllowedError: typeof ContentTypeNotAllowedErrorClass;
|
|
355
|
+
/** Base class for all database errors */
|
|
356
|
+
DatabaseError: typeof DatabaseErrorClass;
|
|
357
|
+
/** Thrown when a database does not exist */
|
|
358
|
+
DatabaseNotFoundError: typeof DatabaseNotFoundErrorClass;
|
|
359
|
+
/** Thrown when application has no access grant to database */
|
|
360
|
+
DatabaseAccessDeniedError: typeof DatabaseAccessDeniedErrorClass;
|
|
361
|
+
/** Thrown when database connection cannot be established */
|
|
362
|
+
DatabaseConnectionError: typeof DatabaseConnectionErrorClass;
|
|
363
|
+
/** Thrown when a database query fails */
|
|
364
|
+
DatabaseQueryError: typeof DatabaseQueryErrorClass;
|
|
365
|
+
/** Thrown when a database transaction fails */
|
|
366
|
+
DatabaseTransactionError: typeof DatabaseTransactionErrorClass;
|
|
367
|
+
/** Base class for all secret errors */
|
|
368
|
+
SecretError: typeof SecretErrorClass;
|
|
369
|
+
/** Thrown when a secret does not exist */
|
|
370
|
+
SecretNotFoundError: typeof SecretNotFoundErrorClass;
|
|
371
|
+
/** Thrown when application has no access grant to secret */
|
|
372
|
+
SecretAccessDeniedError: typeof SecretAccessDeniedErrorClass;
|
|
373
|
+
/** Thrown when secret decryption fails */
|
|
374
|
+
SecretDecryptionError: typeof SecretDecryptionErrorClass;
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAMH,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAMnB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAM1C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAMrE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAEL,UAAU,EAEV,WAAW,EACX,YAAY,EACZ,QAAQ,EAER,UAAU,EACV,SAAS,EAET,YAAY,EACZ,WAAW,EACX,oBAAoB,EAEpB,WAAW,EACX,UAAU,EAEV,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EAEV,kBAAkB,EAClB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;QACzC,4CAA4C;QAC5C,qBAAqB,EAAE,OAAO,0BAA0B,CAAC;QACzD,8DAA8D;QAC9D,yBAAyB,EAAE,OAAO,8BAA8B,CAAC;QACjE,4DAA4D;QAC5D,uBAAuB,EAAE,OAAO,4BAA4B,CAAC;QAC7D,yCAAyC;QACzC,kBAAkB,EAAE,OAAO,uBAAuB,CAAC;QACnD,+CAA+C;QAC/C,wBAAwB,EAAE,OAAO,6BAA6B,CAAC;QAM/D,uCAAuC;QACvC,WAAW,EAAE,OAAO,gBAAgB,CAAC;QACrC,0CAA0C;QAC1C,mBAAmB,EAAE,OAAO,wBAAwB,CAAC;QACrD,4DAA4D;QAC5D,uBAAuB,EAAE,OAAO,4BAA4B,CAAC;QAC7D,0CAA0C;QAC1C,qBAAqB,EAAE,OAAO,0BAA0B,CAAC;KAC1D,CAAC;CACH"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ketrics SDK - Type Definitions
|
|
4
|
+
*
|
|
5
|
+
* TypeScript type definitions for building tenant applications
|
|
6
|
+
* on the Ketrics platform.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Import types only if needed for type annotations
|
|
13
|
+
* import type { FileContent, IVolume, IDatabaseConnection } from '@ketrics/sdk';
|
|
14
|
+
*
|
|
15
|
+
* export async function handler() {
|
|
16
|
+
* // Access the global ketrics object (auto-typed)
|
|
17
|
+
* console.log(ketrics.tenant.name);
|
|
18
|
+
* console.log(ketrics.user.email);
|
|
19
|
+
*
|
|
20
|
+
* // Use ketrics.Volume.connect() for S3 storage
|
|
21
|
+
* try {
|
|
22
|
+
* const volume = await ketrics.Volume.connect('uploads');
|
|
23
|
+
* const file = await volume.get('documents/report.pdf');
|
|
24
|
+
* return { contentType: file.contentType, size: file.contentLength };
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* if (error instanceof ketrics.VolumeNotFoundError) {
|
|
27
|
+
* return { error: `Volume not found: ${error.volumeCode}` };
|
|
28
|
+
* }
|
|
29
|
+
* throw error;
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Use ketrics.DatabaseConnection.connect() for databases
|
|
33
|
+
* try {
|
|
34
|
+
* const db = await ketrics.DatabaseConnection.connect('main-db');
|
|
35
|
+
* const result = await db.query('SELECT * FROM users');
|
|
36
|
+
* await db.close();
|
|
37
|
+
* return { users: result.rows };
|
|
38
|
+
* } catch (error) {
|
|
39
|
+
* if (error instanceof ketrics.DatabaseNotFoundError) {
|
|
40
|
+
* return { error: `Database not found: ${error.databaseCode}` };
|
|
41
|
+
* }
|
|
42
|
+
* throw error;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // Use ketrics.Secret.get() for secrets
|
|
46
|
+
* try {
|
|
47
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
48
|
+
* // Use the API key
|
|
49
|
+
* } catch (error) {
|
|
50
|
+
* if (error instanceof ketrics.SecretNotFoundError) {
|
|
51
|
+
* return { error: `Secret not found: ${error.secretCode}` };
|
|
52
|
+
* }
|
|
53
|
+
* throw error;
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.isVolumeErrorType = exports.isVolumeError = exports.ContentTypeNotAllowedError = exports.FileSizeLimitError = exports.InvalidPathError = exports.FileAlreadyExistsError = exports.FileNotFoundError = exports.VolumePermissionDeniedError = exports.VolumeAccessDeniedError = exports.VolumeNotFoundError = exports.VolumeError = exports.isSecretErrorType = exports.isSecretError = exports.SecretDecryptionError = exports.SecretAccessDeniedError = exports.SecretNotFoundError = exports.SecretError = exports.isDatabaseErrorType = exports.isDatabaseError = exports.DatabaseTransactionError = exports.DatabaseQueryError = exports.DatabaseConnectionError = exports.DatabaseAccessDeniedError = exports.DatabaseNotFoundError = exports.DatabaseError = void 0;
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// Database Error Exports
|
|
62
|
+
// ============================================================================
|
|
63
|
+
var database_errors_1 = require("./database-errors");
|
|
64
|
+
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return database_errors_1.DatabaseError; } });
|
|
65
|
+
Object.defineProperty(exports, "DatabaseNotFoundError", { enumerable: true, get: function () { return database_errors_1.DatabaseNotFoundError; } });
|
|
66
|
+
Object.defineProperty(exports, "DatabaseAccessDeniedError", { enumerable: true, get: function () { return database_errors_1.DatabaseAccessDeniedError; } });
|
|
67
|
+
Object.defineProperty(exports, "DatabaseConnectionError", { enumerable: true, get: function () { return database_errors_1.DatabaseConnectionError; } });
|
|
68
|
+
Object.defineProperty(exports, "DatabaseQueryError", { enumerable: true, get: function () { return database_errors_1.DatabaseQueryError; } });
|
|
69
|
+
Object.defineProperty(exports, "DatabaseTransactionError", { enumerable: true, get: function () { return database_errors_1.DatabaseTransactionError; } });
|
|
70
|
+
Object.defineProperty(exports, "isDatabaseError", { enumerable: true, get: function () { return database_errors_1.isDatabaseError; } });
|
|
71
|
+
Object.defineProperty(exports, "isDatabaseErrorType", { enumerable: true, get: function () { return database_errors_1.isDatabaseErrorType; } });
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Secret Error Exports
|
|
74
|
+
// ============================================================================
|
|
75
|
+
var secret_errors_1 = require("./secret-errors");
|
|
76
|
+
Object.defineProperty(exports, "SecretError", { enumerable: true, get: function () { return secret_errors_1.SecretError; } });
|
|
77
|
+
Object.defineProperty(exports, "SecretNotFoundError", { enumerable: true, get: function () { return secret_errors_1.SecretNotFoundError; } });
|
|
78
|
+
Object.defineProperty(exports, "SecretAccessDeniedError", { enumerable: true, get: function () { return secret_errors_1.SecretAccessDeniedError; } });
|
|
79
|
+
Object.defineProperty(exports, "SecretDecryptionError", { enumerable: true, get: function () { return secret_errors_1.SecretDecryptionError; } });
|
|
80
|
+
Object.defineProperty(exports, "isSecretError", { enumerable: true, get: function () { return secret_errors_1.isSecretError; } });
|
|
81
|
+
Object.defineProperty(exports, "isSecretErrorType", { enumerable: true, get: function () { return secret_errors_1.isSecretErrorType; } });
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Volume Error Exports
|
|
84
|
+
// ============================================================================
|
|
85
|
+
var errors_1 = require("./errors");
|
|
86
|
+
// Error classes
|
|
87
|
+
Object.defineProperty(exports, "VolumeError", { enumerable: true, get: function () { return errors_1.VolumeError; } });
|
|
88
|
+
Object.defineProperty(exports, "VolumeNotFoundError", { enumerable: true, get: function () { return errors_1.VolumeNotFoundError; } });
|
|
89
|
+
Object.defineProperty(exports, "VolumeAccessDeniedError", { enumerable: true, get: function () { return errors_1.VolumeAccessDeniedError; } });
|
|
90
|
+
Object.defineProperty(exports, "VolumePermissionDeniedError", { enumerable: true, get: function () { return errors_1.VolumePermissionDeniedError; } });
|
|
91
|
+
Object.defineProperty(exports, "FileNotFoundError", { enumerable: true, get: function () { return errors_1.FileNotFoundError; } });
|
|
92
|
+
Object.defineProperty(exports, "FileAlreadyExistsError", { enumerable: true, get: function () { return errors_1.FileAlreadyExistsError; } });
|
|
93
|
+
Object.defineProperty(exports, "InvalidPathError", { enumerable: true, get: function () { return errors_1.InvalidPathError; } });
|
|
94
|
+
Object.defineProperty(exports, "FileSizeLimitError", { enumerable: true, get: function () { return errors_1.FileSizeLimitError; } });
|
|
95
|
+
Object.defineProperty(exports, "ContentTypeNotAllowedError", { enumerable: true, get: function () { return errors_1.ContentTypeNotAllowedError; } });
|
|
96
|
+
// Type guards
|
|
97
|
+
Object.defineProperty(exports, "isVolumeError", { enumerable: true, get: function () { return errors_1.isVolumeError; } });
|
|
98
|
+
Object.defineProperty(exports, "isVolumeErrorType", { enumerable: true, get: function () { return errors_1.isVolumeErrorType; } });
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;;;AAoCH,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E,qDAS2B;AARzB,gHAAA,aAAa,OAAA;AACb,wHAAA,qBAAqB,OAAA;AACrB,4HAAA,yBAAyB,OAAA;AACzB,0HAAA,uBAAuB,OAAA;AACvB,qHAAA,kBAAkB,OAAA;AAClB,2HAAA,wBAAwB,OAAA;AACxB,kHAAA,eAAe,OAAA;AACf,sHAAA,mBAAmB,OAAA;AASrB,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E,iDAOyB;AANvB,4GAAA,WAAW,OAAA;AACX,oHAAA,mBAAmB,OAAA;AACnB,wHAAA,uBAAuB,OAAA;AACvB,sHAAA,qBAAqB,OAAA;AACrB,8GAAA,aAAa,OAAA;AACb,kHAAA,iBAAiB,OAAA;AAqCnB,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E,mCAgBkB;AAbhB,gBAAgB;AAChB,qGAAA,WAAW,OAAA;AACX,6GAAA,mBAAmB,OAAA;AACnB,iHAAA,uBAAuB,OAAA;AACvB,qHAAA,2BAA2B,OAAA;AAC3B,2GAAA,iBAAiB,OAAA;AACjB,gHAAA,sBAAsB,OAAA;AACtB,0GAAA,gBAAgB,OAAA;AAChB,4GAAA,kBAAkB,OAAA;AAClB,oHAAA,0BAA0B,OAAA;AAC1B,cAAc;AACd,uGAAA,aAAa,OAAA;AACb,2GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ketrics SDK - Secret Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Provides typed errors for secret operations in tenant applications.
|
|
5
|
+
*
|
|
6
|
+
* Error Hierarchy:
|
|
7
|
+
* - SecretError (base)
|
|
8
|
+
* - SecretNotFoundError
|
|
9
|
+
* - SecretAccessDeniedError
|
|
10
|
+
* - SecretDecryptionError
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Base error class for all Secret errors
|
|
14
|
+
*
|
|
15
|
+
* All Secret errors extend this class and include:
|
|
16
|
+
* - secretCode: The secret code that caused the error
|
|
17
|
+
* - operation: The operation that failed
|
|
18
|
+
* - timestamp: When the error occurred
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class SecretError extends Error {
|
|
21
|
+
/** Secret code that caused the error */
|
|
22
|
+
readonly secretCode: string;
|
|
23
|
+
/** Operation that failed */
|
|
24
|
+
readonly operation: string;
|
|
25
|
+
/** When the error occurred */
|
|
26
|
+
readonly timestamp: Date;
|
|
27
|
+
constructor(message: string, secretCode: string, operation: string);
|
|
28
|
+
/**
|
|
29
|
+
* Serialize error for logging
|
|
30
|
+
*/
|
|
31
|
+
toJSON(): Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when a secret is not found
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* try {
|
|
39
|
+
* const secret = await ketrics.Secret.get('unknown-secret');
|
|
40
|
+
* } catch (error) {
|
|
41
|
+
* if (error instanceof ketrics.SecretNotFoundError) {
|
|
42
|
+
* console.log(`Secret '${error.secretCode}' not found`);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class SecretNotFoundError extends SecretError {
|
|
48
|
+
constructor(secretCode: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error thrown when application does not have access to a secret
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* try {
|
|
56
|
+
* const secret = await ketrics.Secret.get('restricted-secret');
|
|
57
|
+
* } catch (error) {
|
|
58
|
+
* if (error instanceof ketrics.SecretAccessDeniedError) {
|
|
59
|
+
* console.log(`No access to secret '${error.secretCode}'`);
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class SecretAccessDeniedError extends SecretError {
|
|
65
|
+
constructor(secretCode: string);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Error thrown when secret decryption fails
|
|
69
|
+
*
|
|
70
|
+
* This typically indicates a KMS key issue or corrupted data.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* try {
|
|
75
|
+
* const secret = await ketrics.Secret.get('encrypted-secret');
|
|
76
|
+
* } catch (error) {
|
|
77
|
+
* if (error instanceof ketrics.SecretDecryptionError) {
|
|
78
|
+
* console.log(`Failed to decrypt secret: ${error.reason}`);
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare class SecretDecryptionError extends SecretError {
|
|
84
|
+
/** Reason for decryption failure */
|
|
85
|
+
readonly reason: string;
|
|
86
|
+
constructor(secretCode: string, reason: string);
|
|
87
|
+
toJSON(): Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Type guard to check if an error is a SecretError
|
|
91
|
+
*
|
|
92
|
+
* @param error - The error to check
|
|
93
|
+
* @returns True if the error is a SecretError
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* try {
|
|
98
|
+
* const secret = await ketrics.Secret.get('my-secret');
|
|
99
|
+
* } catch (error) {
|
|
100
|
+
* if (isSecretError(error)) {
|
|
101
|
+
* console.log(`Secret error: ${error.secretCode}`);
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function isSecretError(error: unknown): error is SecretError;
|
|
107
|
+
/**
|
|
108
|
+
* Type guard to check if an error is a specific SecretError type
|
|
109
|
+
*
|
|
110
|
+
* @param error - The error to check
|
|
111
|
+
* @param errorClass - The error class to check against
|
|
112
|
+
* @returns True if the error is an instance of the specified class
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* try {
|
|
117
|
+
* const secret = await ketrics.Secret.get('my-secret');
|
|
118
|
+
* } catch (error) {
|
|
119
|
+
* if (isSecretErrorType(error, SecretNotFoundError)) {
|
|
120
|
+
* console.log('Secret not found');
|
|
121
|
+
* } else if (isSecretErrorType(error, SecretAccessDeniedError)) {
|
|
122
|
+
* console.log('Access denied');
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function isSecretErrorType<T extends SecretError>(error: unknown, errorClass: new (...args: never[]) => T): error is T;
|
|
128
|
+
//# sourceMappingURL=secret-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-errors.d.ts","sourceRoot":"","sources":["../src/secret-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;;;;;;GAOG;AACH,8BAAsB,WAAY,SAAQ,KAAK;IAC7C,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,8BAA8B;IAC9B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAalE;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAMD;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,UAAU,EAAE,MAAM;CAO/B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC1C,UAAU,EAAE,MAAM;CAO/B;AAED;;;;;;;;;;;;;;;GAe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