@ketrics/sdk-backend 0.7.0 → 0.8.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/dist/index.d.ts CHANGED
@@ -23,20 +23,20 @@
23
23
  * const file = await volume.get('documents/report.pdf');
24
24
  * return { contentType: file.contentType, size: file.contentLength };
25
25
  * } catch (error) {
26
- * if (error instanceof ketrics.VolumeNotFoundError) {
26
+ * if (error instanceof ketrics.Volume.NotFoundError) {
27
27
  * return { error: `Volume not found: ${error.volumeCode}` };
28
28
  * }
29
29
  * throw error;
30
30
  * }
31
31
  *
32
- * // Use ketrics.DatabaseConnection.connect() for databases
32
+ * // Use ketrics.Database.connect() for databases
33
33
  * try {
34
- * const db = await ketrics.DatabaseConnection.connect('main-db');
34
+ * const db = await ketrics.Database.connect('main-db');
35
35
  * const result = await db.query('SELECT * FROM users');
36
36
  * await db.close();
37
37
  * return { users: result.rows };
38
38
  * } catch (error) {
39
- * if (error instanceof ketrics.DatabaseNotFoundError) {
39
+ * if (error instanceof ketrics.Database.NotFoundError) {
40
40
  * return { error: `Database not found: ${error.databaseCode}` };
41
41
  * }
42
42
  * throw error;
@@ -47,7 +47,7 @@
47
47
  * const apiKey = await ketrics.Secret.get('stripe-api-key');
48
48
  * // Use the API key
49
49
  * } catch (error) {
50
- * if (error instanceof ketrics.SecretNotFoundError) {
50
+ * if (error instanceof ketrics.Secret.NotFoundError) {
51
51
  * return { error: `Secret not found: ${error.secretCode}` };
52
52
  * }
53
53
  * throw error;
@@ -55,51 +55,316 @@
55
55
  * }
56
56
  * ```
57
57
  */
58
- export { TenantContext, ApplicationContext, UserContext, RequestorContext, RuntimeContext, EnvironmentVariables, } from './context';
59
- export { ConsoleLogger } from './console';
60
- export { HttpRequestConfig, HttpResponse, HttpClient } from './http';
61
- export { DatabaseQueryResult, DatabaseExecuteResult, IDatabaseConnection, DatabaseManager, } from './databases';
62
- export { DatabaseError, DatabaseNotFoundError, DatabaseAccessDeniedError, DatabaseConnectionError, DatabaseQueryError, DatabaseTransactionError, isDatabaseError, isDatabaseErrorType, } from './database-errors';
63
- export { ISecret } from './secrets';
64
- export { SecretError, SecretNotFoundError, SecretAccessDeniedError, SecretDecryptionError, isSecretError, isSecretErrorType, } from './secret-errors';
65
- export { ExcelCellValue, ExcelRowValues, ExcelColumnDefinition, AddWorksheetOptions, IExcelCell, IExcelRow, IExcelWorksheet, IExcelWorkbook, ExcelManager, } from './excel';
66
- export { ExcelError, ExcelParseError, ExcelWriteError, isExcelError, isExcelErrorType, } from './excel-errors';
67
- export { PdfPageSize, PdfStandardFont, PdfRgbColor, PdfDrawTextOptions, PdfDrawRectOptions, PdfDrawLineOptions, PdfDrawCircleOptions, PdfDrawImageOptions, PdfEmbeddedImage, PdfEmbeddedFont, IPdfPage, IPdfDocument, PdfManager, } from './pdf';
68
- export { PdfError, PdfParseError, PdfWriteError, isPdfError, isPdfErrorType, } from './pdf-errors';
69
- export { JobStatusValue, RunInBackgroundOptions, RunInBackgroundParams, JobErrorDetails, JobStatus, JobListParams, JobListResult, } from './job';
70
- export { JobError, JobNotFoundError, InvalidFunctionError, CrossAppPermissionError, JobExecutionError, isJobError, isJobErrorType, } from './job-errors';
71
- export { MessagePriorityLevel, MessageChannelConfig, SendMessageParams, SendBulkMessageParams, SendGroupMessageParams, SendMessageResult, SendBulkMessageResult, MessagesManager, } from './messages';
72
- export { MessageError, MessageValidationError, GroupNotFoundError, TenantGrantPermissionDeniedError, isMessageError, isMessageErrorType, } from './messages-errors';
73
- export { PutContent, FileContent, FileMetadata, FileInfo, PutOptions, PutResult, DeleteResult, DeleteError, DeleteByPrefixResult, ListOptions, ListResult, CopyOptions, CopyResult, MoveOptions, MoveResult, DownloadUrlOptions, UploadUrlOptions, PresignedUrl, IVolume, } from './volumes';
74
- export { VolumePermissionValue, VolumeError, VolumeNotFoundError, VolumeAccessDeniedError, VolumePermissionDeniedError, FileNotFoundError, FileAlreadyExistsError, InvalidPathError, FileSizeLimitError, ContentTypeNotAllowedError, isVolumeError, isVolumeErrorType, } from './errors';
75
- import type { TenantContext, ApplicationContext, RequestorContext, RuntimeContext, EnvironmentVariables } from './context';
76
- import type { ConsoleLogger } from './console';
77
- import type { HttpClient } from './http';
78
- import type { IDatabaseConnection } from './databases';
79
- import type { IVolume } from './volumes';
80
- import type { IExcelWorkbook } from './excel';
81
- import type { IPdfDocument, PdfRgbColor } from './pdf';
82
- import type { RunInBackgroundParams, JobStatus, JobListParams, JobListResult } from './job';
83
- import type { MessagesManager } from './messages';
84
- 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';
85
- import { DatabaseError as DatabaseErrorClass, DatabaseNotFoundError as DatabaseNotFoundErrorClass, DatabaseAccessDeniedError as DatabaseAccessDeniedErrorClass, DatabaseConnectionError as DatabaseConnectionErrorClass, DatabaseQueryError as DatabaseQueryErrorClass, DatabaseTransactionError as DatabaseTransactionErrorClass } from './database-errors';
86
- import { SecretError as SecretErrorClass, SecretNotFoundError as SecretNotFoundErrorClass, SecretAccessDeniedError as SecretAccessDeniedErrorClass, SecretDecryptionError as SecretDecryptionErrorClass } from './secret-errors';
87
- import { ExcelError as ExcelErrorClass, ExcelParseError as ExcelParseErrorClass, ExcelWriteError as ExcelWriteErrorClass } from './excel-errors';
88
- import { PdfError as PdfErrorClass, PdfParseError as PdfParseErrorClass, PdfWriteError as PdfWriteErrorClass } from './pdf-errors';
89
- import { JobError as JobErrorClass, JobNotFoundError as JobNotFoundErrorClass, InvalidFunctionError as InvalidFunctionErrorClass, CrossAppPermissionError as CrossAppPermissionErrorClass, JobExecutionError as JobExecutionErrorClass } from './job-errors';
90
- import { MessageError as MessageErrorClass, MessageValidationError as MessageValidationErrorClass, GroupNotFoundError as GroupNotFoundErrorClass, TenantGrantPermissionDeniedError as TenantGrantPermissionDeniedErrorClass } from './messages-errors';
91
- import { isVolumeError, isVolumeErrorType } from './errors';
92
- import { isDatabaseError, isDatabaseErrorType } from './database-errors';
93
- import { isSecretError, isSecretErrorType } from './secret-errors';
94
- import { isExcelError, isExcelErrorType } from './excel-errors';
95
- import { isPdfError, isPdfErrorType } from './pdf-errors';
96
- import { isJobError, isJobErrorType } from './job-errors';
97
- import { isMessageError, isMessageErrorType } from './messages-errors';
58
+ export { TenantContext, ApplicationContext, UserContext, RequestorContext, RuntimeContext, EnvironmentVariables } from "./context";
59
+ export { ConsoleLogger } from "./console";
60
+ export { HttpRequestConfig, HttpResponse, HttpClient } from "./http";
61
+ export { DatabaseQueryResult, DatabaseExecuteResult, IDatabaseConnection, DatabaseManager } from "./databases";
62
+ export { DatabaseError, DatabaseNotFoundError, DatabaseAccessDeniedError, DatabaseConnectionError, DatabaseQueryError, DatabaseTransactionError, isDatabaseError, isDatabaseErrorType, } from "./database-errors";
63
+ export { ISecret } from "./secrets";
64
+ export { SecretError, SecretNotFoundError, SecretAccessDeniedError, SecretDecryptionError, isSecretError, isSecretErrorType } from "./secret-errors";
65
+ export { ExcelCellValue, ExcelRowValues, ExcelColumnDefinition, AddWorksheetOptions, IExcelCell, IExcelRow, IExcelWorksheet, IExcelWorkbook, ExcelManager, } from "./excel";
66
+ export { ExcelError, ExcelParseError, ExcelWriteError, isExcelError, isExcelErrorType } from "./excel-errors";
67
+ export { PdfPageSize, PdfStandardFont, PdfRgbColor, PdfDrawTextOptions, PdfDrawRectOptions, PdfDrawLineOptions, PdfDrawCircleOptions, PdfDrawImageOptions, PdfEmbeddedImage, PdfEmbeddedFont, IPdfPage, IPdfDocument, PdfManager, } from "./pdf";
68
+ export { PdfError, PdfParseError, PdfWriteError, isPdfError, isPdfErrorType } from "./pdf-errors";
69
+ export { JobStatusValue, RunInBackgroundOptions, RunInBackgroundParams, JobErrorDetails, JobStatus, JobListParams, JobListResult } from "./job";
70
+ export { JobError, JobNotFoundError, InvalidFunctionError, CrossAppPermissionError, EltJobExecutionError, isJobError, isJobErrorType, } from "./job-errors";
71
+ export { MessagePriorityLevel, MessageChannelConfig, SendMessageParams, SendBulkMessageParams, SendGroupMessageParams, SendMessageResult, SendBulkMessageResult, MessagesManager, } from "./messages";
72
+ export { MessageError, MessageValidationError, GroupNotFoundError, TenantGrantPermissionDeniedError, isMessageError, isMessageErrorType, } from "./messages-errors";
73
+ export { PutContent, FileContent, FileMetadata, FileInfo, PutOptions, PutResult, DeleteResult, DeleteError, DeleteByPrefixResult, ListOptions, ListResult, CopyOptions, CopyResult, MoveOptions, MoveResult, DownloadUrlOptions, UploadUrlOptions, PresignedUrl, IVolume, } from "./volumes";
74
+ export { VolumePermissionValue, VolumeError, VolumeNotFoundError, VolumeAccessDeniedError, VolumePermissionDeniedError, FileNotFoundError, FileAlreadyExistsError, InvalidPathError, FileSizeLimitError, ContentTypeNotAllowedError, isVolumeError, isVolumeErrorType, } from "./errors";
75
+ import type { TenantContext, ApplicationContext, RequestorContext, RuntimeContext, EnvironmentVariables } from "./context";
76
+ import type { ConsoleLogger } from "./console";
77
+ import type { HttpClient } from "./http";
78
+ import type { IDatabaseConnection } from "./databases";
79
+ import type { IVolume } from "./volumes";
80
+ import type { IExcelWorkbook } from "./excel";
81
+ import type { IPdfDocument, PdfRgbColor } from "./pdf";
82
+ import type { RunInBackgroundParams, JobStatus, JobListParams, JobListResult } from "./job";
83
+ import type { SendMessageParams, SendBulkMessageParams, SendGroupMessageParams, SendMessageResult, SendBulkMessageResult } from "./messages";
84
+ /**
85
+ * Base class for all Volume errors
86
+ */
87
+ export interface VolumeErrorClass extends Error {
88
+ readonly volumeCode: string;
89
+ readonly operation: string;
90
+ readonly timestamp: Date;
91
+ toJSON(): Record<string, unknown>;
92
+ }
93
+ export type AbstractVolumeErrorConstructor = abstract new (...args: any[]) => VolumeErrorClass;
94
+ export type VolumeErrorConstructor = new (...args: any[]) => VolumeErrorClass;
95
+ /**
96
+ * Base class for all Database errors
97
+ */
98
+ export interface DatabaseErrorClass extends Error {
99
+ readonly databaseCode: string;
100
+ readonly operation: string;
101
+ readonly timestamp: Date;
102
+ toJSON(): Record<string, unknown>;
103
+ }
104
+ export type AbstractDatabaseErrorConstructor = abstract new (...args: any[]) => DatabaseErrorClass;
105
+ export type DatabaseErrorConstructor = new (...args: any[]) => DatabaseErrorClass;
106
+ /**
107
+ * Base class for all Secret errors
108
+ */
109
+ export interface SecretErrorClass extends Error {
110
+ readonly secretCode: string;
111
+ readonly operation: string;
112
+ readonly timestamp: Date;
113
+ toJSON(): Record<string, unknown>;
114
+ }
115
+ export type AbstractSecretErrorConstructor = abstract new (...args: any[]) => SecretErrorClass;
116
+ export type SecretErrorConstructor = new (...args: any[]) => SecretErrorClass;
117
+ /**
118
+ * Base class for all Excel errors
119
+ */
120
+ export interface ExcelErrorClass extends Error {
121
+ readonly operation: string;
122
+ readonly timestamp: Date;
123
+ toJSON(): Record<string, unknown>;
124
+ }
125
+ export type AbstractExcelErrorConstructor = abstract new (...args: any[]) => ExcelErrorClass;
126
+ export type ExcelErrorConstructor = new (...args: any[]) => ExcelErrorClass;
127
+ /**
128
+ * Base class for all PDF errors
129
+ */
130
+ export interface PdfErrorClass extends Error {
131
+ readonly operation: string;
132
+ readonly timestamp: Date;
133
+ toJSON(): Record<string, unknown>;
134
+ }
135
+ export type AbstractPdfErrorConstructor = abstract new (...args: any[]) => PdfErrorClass;
136
+ export type PdfErrorConstructor = new (...args: any[]) => PdfErrorClass;
137
+ /**
138
+ * Base class for all Job errors
139
+ */
140
+ export interface JobErrorClass extends Error {
141
+ readonly jobId?: string;
142
+ readonly operation: string;
143
+ readonly timestamp: Date;
144
+ toJSON(): Record<string, unknown>;
145
+ }
146
+ export type AbstractJobErrorConstructor = abstract new (...args: any[]) => JobErrorClass;
147
+ export type JobErrorConstructor = new (...args: any[]) => JobErrorClass;
148
+ /**
149
+ * Base class for all Message errors
150
+ */
151
+ export interface MessageErrorClass extends Error {
152
+ readonly code: string;
153
+ }
154
+ export type MessageErrorConstructor = new (message: string, code?: string) => MessageErrorClass;
155
+ /**
156
+ * Volume Module
157
+ *
158
+ * Groups Volume operations, error classes, and type guards under a single namespace.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * try {
163
+ * const volume = await ketrics.Volume.connect('uploads');
164
+ * const files = await volume.list();
165
+ * } catch (error) {
166
+ * if (error instanceof ketrics.Volume.NotFoundError) {
167
+ * console.log('Volume not found');
168
+ * }
169
+ * }
170
+ * ```
171
+ */
172
+ export interface VolumeModule {
173
+ connect(volumeCode: string): Promise<IVolume>;
174
+ Error: AbstractVolumeErrorConstructor;
175
+ NotFoundError: VolumeErrorConstructor;
176
+ AccessDeniedError: VolumeErrorConstructor;
177
+ PermissionDeniedError: VolumeErrorConstructor;
178
+ FileNotFoundError: VolumeErrorConstructor;
179
+ FileAlreadyExistsError: VolumeErrorConstructor;
180
+ InvalidPathError: VolumeErrorConstructor;
181
+ FileSizeLimitError: VolumeErrorConstructor;
182
+ ContentTypeNotAllowedError: VolumeErrorConstructor;
183
+ isError: (error: unknown) => error is VolumeErrorClass;
184
+ isErrorType: <T extends VolumeErrorClass>(error: unknown, errorClass: new (...args: never[]) => T) => error is T;
185
+ }
186
+ /**
187
+ * Database Module
188
+ *
189
+ * Groups Database operations, error classes, and type guards under a single namespace.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * try {
194
+ * const db = await ketrics.Database.connect('main-db');
195
+ * const result = await db.query('SELECT * FROM users WHERE id = $1', [1]);
196
+ * await db.close();
197
+ * } catch (error) {
198
+ * if (error instanceof ketrics.Database.NotFoundError) {
199
+ * console.log('Database not found');
200
+ * } else if (error instanceof ketrics.Database.QueryError) {
201
+ * console.log('Query failed');
202
+ * }
203
+ * }
204
+ * ```
205
+ */
206
+ export interface DatabaseModule {
207
+ connect(databaseCode: string): Promise<IDatabaseConnection>;
208
+ Error: AbstractDatabaseErrorConstructor;
209
+ NotFoundError: DatabaseErrorConstructor;
210
+ AccessDeniedError: DatabaseErrorConstructor;
211
+ ConnectionError: DatabaseErrorConstructor;
212
+ QueryError: DatabaseErrorConstructor;
213
+ TransactionError: DatabaseErrorConstructor;
214
+ isError: (error: unknown) => error is DatabaseErrorClass;
215
+ isErrorType: <T extends DatabaseErrorClass>(error: unknown, errorClass: new (...args: never[]) => T) => error is T;
216
+ }
217
+ /**
218
+ * Secret Module
219
+ *
220
+ * Groups Secret operations, error classes, and type guards under a single namespace.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * try {
225
+ * const apiKey = await ketrics.Secret.get('stripe-api-key');
226
+ * } catch (error) {
227
+ * if (error instanceof ketrics.Secret.NotFoundError) {
228
+ * console.log('Secret not found');
229
+ * }
230
+ * }
231
+ * ```
232
+ */
233
+ export interface SecretModule {
234
+ get(secretCode: string): Promise<string>;
235
+ exists(secretCode: string): Promise<boolean>;
236
+ Error: AbstractSecretErrorConstructor;
237
+ NotFoundError: SecretErrorConstructor;
238
+ AccessDeniedError: SecretErrorConstructor;
239
+ DecryptionError: SecretErrorConstructor;
240
+ isError: (error: unknown) => error is SecretErrorClass;
241
+ isErrorType: <T extends SecretErrorClass>(error: unknown, errorClass: new (...args: any[]) => T) => error is T;
242
+ }
243
+ /**
244
+ * Excel Module
245
+ *
246
+ * Groups Excel operations, error classes, and type guards under a single namespace.
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * try {
251
+ * const workbook = await ketrics.Excel.read(buffer);
252
+ * const sheet = workbook.getWorksheet('Sheet1');
253
+ * } catch (error) {
254
+ * if (error instanceof ketrics.Excel.ParseError) {
255
+ * console.log('Invalid Excel file');
256
+ * }
257
+ * }
258
+ * ```
259
+ */
260
+ export interface ExcelModule {
261
+ read(buffer: Buffer): Promise<IExcelWorkbook>;
262
+ create(): IExcelWorkbook;
263
+ Error: AbstractExcelErrorConstructor;
264
+ ParseError: ExcelErrorConstructor;
265
+ WriteError: ExcelErrorConstructor;
266
+ isError: (error: unknown) => error is ExcelErrorClass;
267
+ isErrorType: <T extends ExcelErrorClass>(error: unknown, errorClass: new (...args: never[]) => T) => error is T;
268
+ }
269
+ /**
270
+ * PDF Module
271
+ *
272
+ * Groups PDF operations, error classes, and type guards under a single namespace.
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * try {
277
+ * const doc = await ketrics.Pdf.create();
278
+ * const page = doc.addPage('A4');
279
+ * const red = ketrics.Pdf.rgb(1, 0, 0);
280
+ * await page.drawText('Hello!', { x: 50, y: 700, color: red });
281
+ * } catch (error) {
282
+ * if (error instanceof ketrics.Pdf.WriteError) {
283
+ * console.log('PDF write failed');
284
+ * }
285
+ * }
286
+ * ```
287
+ */
288
+ export interface PdfModule {
289
+ read(buffer: Buffer): Promise<IPdfDocument>;
290
+ create(): Promise<IPdfDocument>;
291
+ rgb(r: number, g: number, b: number): PdfRgbColor;
292
+ Error: AbstractPdfErrorConstructor;
293
+ ParseError: PdfErrorConstructor;
294
+ WriteError: PdfErrorConstructor;
295
+ isError: (error: unknown) => error is PdfErrorClass;
296
+ isErrorType: <T extends PdfErrorClass>(error: unknown, errorClass: new (...args: never[]) => T) => error is T;
297
+ }
298
+ /**
299
+ * Job Module (Grouped)
300
+ *
301
+ * Groups Job operations, error classes, and type guards under a single namespace.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * try {
306
+ * const jobId = await ketrics.Job.runInBackground({
307
+ * function: 'processOrder',
308
+ * payload: { orderId: '123' },
309
+ * });
310
+ * const status = await ketrics.Job.getStatus(jobId);
311
+ * } catch (error) {
312
+ * if (error instanceof ketrics.Job.NotFoundError) {
313
+ * console.log('Job not found');
314
+ * }
315
+ * }
316
+ * ```
317
+ */
318
+ export interface JobGroupedModule {
319
+ runInBackground(params: RunInBackgroundParams): Promise<string>;
320
+ getStatus(jobId: string): Promise<JobStatus>;
321
+ list(params?: JobListParams): Promise<JobListResult>;
322
+ Error: AbstractJobErrorConstructor;
323
+ NotFoundError: JobErrorConstructor;
324
+ InvalidFunctionError: JobErrorConstructor;
325
+ CrossAppPermissionError: JobErrorConstructor;
326
+ ExecutionError: JobErrorConstructor;
327
+ isError: (error: unknown) => error is JobErrorClass;
328
+ isErrorType: <T extends JobErrorClass>(error: unknown, errorClass: new (...args: never[]) => T) => error is T;
329
+ }
330
+ /**
331
+ * Messages Module (Grouped)
332
+ *
333
+ * Groups Messages operations, error classes, and type guards under a single namespace.
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * try {
338
+ * const result = await ketrics.Messages.send({
339
+ * userId: 'user-123',
340
+ * type: 'ORDER_SHIPPED',
341
+ * subject: 'Your order has shipped!',
342
+ * body: 'Track your package...',
343
+ * });
344
+ * } catch (error) {
345
+ * if (error instanceof ketrics.Messages.ValidationError) {
346
+ * console.log('Invalid message params');
347
+ * }
348
+ * }
349
+ * ```
350
+ */
351
+ export interface MessagesGroupedModule {
352
+ send(params: SendMessageParams): Promise<SendMessageResult>;
353
+ sendBulk(params: SendBulkMessageParams): Promise<SendBulkMessageResult>;
354
+ sendToGroup(params: SendGroupMessageParams): Promise<SendBulkMessageResult>;
355
+ Error: MessageErrorConstructor;
356
+ ValidationError: MessageErrorConstructor;
357
+ GroupNotFoundError: MessageErrorConstructor;
358
+ PermissionDeniedError: MessageErrorConstructor;
359
+ isError: (error: unknown) => error is MessageErrorClass;
360
+ isErrorType: <T extends MessageErrorClass>(error: unknown, errorClass: new (...args: any[]) => T) => error is T;
361
+ }
98
362
  /**
99
363
  * Ketrics Platform SDK Interface
100
364
  *
101
365
  * The complete SDK interface available as the global `ketrics` object
102
- * in tenant application code.
366
+ * in tenant application code. Each module groups its operations, error
367
+ * classes, and type guards under a single namespace.
103
368
  *
104
369
  * @example
105
370
  * ```typescript
@@ -118,8 +383,8 @@ import { isMessageError, isMessageErrorType } from './messages-errors';
118
383
  * const response = await ketrics.http.get('https://api.example.com/data');
119
384
  * console.log(response.data);
120
385
  *
121
- * // Access databases (new static factory pattern)
122
- * const db = await ketrics.DatabaseConnection.connect('main-db');
386
+ * // Access databases
387
+ * const db = await ketrics.Database.connect('main-db');
123
388
  * const result = await db.query('SELECT * FROM users');
124
389
  * await db.close();
125
390
  *
@@ -154,134 +419,20 @@ export interface KetricsSdkV1 {
154
419
  console: ConsoleLogger;
155
420
  /** HTTP client for external API requests */
156
421
  http: HttpClient;
157
- /** Volume class with static connect() factory method */
158
- Volume: {
159
- connect(volumeCode: string): Promise<IVolume>;
160
- };
161
- /** Base error class for all Volume errors (abstract) */
162
- VolumeError: typeof VolumeErrorClass;
163
- /** Error thrown when volume doesn't exist */
164
- VolumeNotFoundError: typeof VolumeNotFoundErrorClass;
165
- /** Error thrown when application has no access grant */
166
- VolumeAccessDeniedError: typeof VolumeAccessDeniedErrorClass;
167
- /** Error thrown when operation requires missing permission */
168
- VolumePermissionDeniedError: typeof VolumePermissionDeniedErrorClass;
169
- /** Error thrown when file doesn't exist */
170
- FileNotFoundError: typeof FileNotFoundErrorClass;
171
- /** Error thrown when file already exists (with ifNotExists option) */
172
- FileAlreadyExistsError: typeof FileAlreadyExistsErrorClass;
173
- /** Error thrown for invalid path characters or traversal attempts */
174
- InvalidPathError: typeof InvalidPathErrorClass;
175
- /** Error thrown when file exceeds size limit */
176
- FileSizeLimitError: typeof FileSizeLimitErrorClass;
177
- /** Error thrown when content type is not allowed */
178
- ContentTypeNotAllowedError: typeof ContentTypeNotAllowedErrorClass;
179
- /** Type guard to check if error is a VolumeError */
180
- isVolumeError: typeof isVolumeError;
181
- /** Type guard to check if error is a specific VolumeError type */
182
- isVolumeErrorType: typeof isVolumeErrorType;
183
- /** DatabaseConnection class with static connect() factory method */
184
- DatabaseConnection: {
185
- connect(databaseCode: string): Promise<IDatabaseConnection>;
186
- };
187
- /** Base error class for all Database errors (abstract) */
188
- DatabaseError: typeof DatabaseErrorClass;
189
- /** Error thrown when database doesn't exist */
190
- DatabaseNotFoundError: typeof DatabaseNotFoundErrorClass;
191
- /** Error thrown when application has no access grant */
192
- DatabaseAccessDeniedError: typeof DatabaseAccessDeniedErrorClass;
193
- /** Error thrown when connection cannot be established */
194
- DatabaseConnectionError: typeof DatabaseConnectionErrorClass;
195
- /** Error thrown when query execution fails */
196
- DatabaseQueryError: typeof DatabaseQueryErrorClass;
197
- /** Error thrown when transaction fails */
198
- DatabaseTransactionError: typeof DatabaseTransactionErrorClass;
199
- /** Type guard to check if error is a DatabaseError */
200
- isDatabaseError: typeof isDatabaseError;
201
- /** Type guard to check if error is a specific DatabaseError type */
202
- isDatabaseErrorType: typeof isDatabaseErrorType;
203
- /** Secret class with static get() method */
204
- Secret: {
205
- get(secretCode: string): Promise<string>;
206
- exists(secretCode: string): Promise<boolean>;
207
- };
208
- /** Base error class for all Secret errors (abstract) */
209
- SecretError: typeof SecretErrorClass;
210
- /** Error thrown when secret doesn't exist */
211
- SecretNotFoundError: typeof SecretNotFoundErrorClass;
212
- /** Error thrown when application has no access grant */
213
- SecretAccessDeniedError: typeof SecretAccessDeniedErrorClass;
214
- /** Error thrown when decryption fails */
215
- SecretDecryptionError: typeof SecretDecryptionErrorClass;
216
- /** Type guard to check if error is a SecretError */
217
- isSecretError: typeof isSecretError;
218
- /** Type guard to check if error is a specific SecretError type */
219
- isSecretErrorType: typeof isSecretErrorType;
220
- /** Excel class with static read() and create() methods */
221
- Excel: {
222
- read(buffer: Buffer): Promise<IExcelWorkbook>;
223
- create(): IExcelWorkbook;
224
- };
225
- /** Base error class for all Excel errors (abstract) */
226
- ExcelError: typeof ExcelErrorClass;
227
- /** Error thrown when parsing Excel file fails */
228
- ExcelParseError: typeof ExcelParseErrorClass;
229
- /** Error thrown when writing Excel file fails */
230
- ExcelWriteError: typeof ExcelWriteErrorClass;
231
- /** Type guard to check if error is an ExcelError */
232
- isExcelError: typeof isExcelError;
233
- /** Type guard to check if error is a specific ExcelError type */
234
- isExcelErrorType: typeof isExcelErrorType;
235
- /** PDF class with static read() and create() methods */
236
- Pdf: {
237
- read(buffer: Buffer): Promise<IPdfDocument>;
238
- create(): Promise<IPdfDocument>;
239
- rgb(r: number, g: number, b: number): PdfRgbColor;
240
- };
241
- /** Base error class for all PDF errors (abstract) */
242
- PdfError: typeof PdfErrorClass;
243
- /** Error thrown when parsing PDF file fails */
244
- PdfParseError: typeof PdfParseErrorClass;
245
- /** Error thrown when writing PDF file fails */
246
- PdfWriteError: typeof PdfWriteErrorClass;
247
- /** Type guard to check if error is a PdfError */
248
- isPdfError: typeof isPdfError;
249
- /** Type guard to check if error is a specific PdfError type */
250
- isPdfErrorType: typeof isPdfErrorType;
251
- /** Job class with static methods for background job operations */
252
- Job: {
253
- runInBackground(params: RunInBackgroundParams): Promise<string>;
254
- getStatus(jobId: string): Promise<JobStatus>;
255
- list(params?: JobListParams): Promise<JobListResult>;
256
- };
257
- /** Base error class for all job errors */
258
- JobError: typeof JobErrorClass;
259
- /** Thrown when a job is not found */
260
- JobNotFoundError: typeof JobNotFoundErrorClass;
261
- /** Thrown when function name is invalid or missing */
262
- InvalidFunctionError: typeof InvalidFunctionErrorClass;
263
- /** Thrown when cross-app job lacks required permission */
264
- CrossAppPermissionError: typeof CrossAppPermissionErrorClass;
265
- /** Thrown when job execution fails */
266
- JobExecutionError: typeof JobExecutionErrorClass;
267
- /** Type guard to check if error is a JobError */
268
- isJobError: typeof isJobError;
269
- /** Type guard to check if error is a specific JobError type */
270
- isJobErrorType: typeof isJobErrorType;
271
- /** Messages class with static methods for sending messages to users */
272
- Messages: MessagesManager;
273
- /** Base error class for all message errors */
274
- MessageError: typeof MessageErrorClass;
275
- /** Error thrown when message validation fails */
276
- MessageValidationError: typeof MessageValidationErrorClass;
277
- /** Error thrown when group is not found */
278
- GroupNotFoundError: typeof GroupNotFoundErrorClass;
279
- /** Error thrown when TenantGrant permissions are missing */
280
- TenantGrantPermissionDeniedError: typeof TenantGrantPermissionDeniedErrorClass;
281
- /** Type guard to check if error is a MessageError */
282
- isMessageError: typeof isMessageError;
283
- /** Type guard to check if error is a specific MessageError type */
284
- isMessageErrorType: typeof isMessageErrorType;
422
+ /** Volume SDK - S3-backed file storage */
423
+ Volume: VolumeModule;
424
+ /** Database SDK - External SQL database access */
425
+ Database: DatabaseModule;
426
+ /** Secret SDK - Encrypted secret values */
427
+ Secret: SecretModule;
428
+ /** Excel SDK - Excel file reading and writing */
429
+ Excel: ExcelModule;
430
+ /** PDF SDK - PDF file reading, creation, and modification */
431
+ Pdf: PdfModule;
432
+ /** Job SDK - Async background job execution */
433
+ Job: JobGroupedModule;
434
+ /** Messages SDK - Application message delivery */
435
+ Messages: MessagesGroupedModule;
285
436
  }
286
437
  /**
287
438
  * Volume - S3-backed storage for tenant applications
@@ -310,10 +461,10 @@ export interface KetricsSdkV1 {
310
461
  * }
311
462
  *
312
463
  * } catch (error) {
313
- * // Error classes are on the ketrics object
314
- * if (error instanceof ketrics.VolumeNotFoundError) {
464
+ * // Error classes are grouped under the module namespace
465
+ * if (error instanceof ketrics.Volume.NotFoundError) {
315
466
  * console.log('Volume not found');
316
- * } else if (error instanceof ketrics.FileNotFoundError) {
467
+ * } else if (error instanceof ketrics.Volume.FileNotFoundError) {
317
468
  * console.log('File not found:', error.key);
318
469
  * }
319
470
  * }
@@ -337,16 +488,16 @@ export declare class Volume {
337
488
  static connect(volumeCode: string): Promise<IVolume>;
338
489
  }
339
490
  /**
340
- * DatabaseConnection - External database access for tenant applications
491
+ * Database - External database access for tenant applications
341
492
  *
342
- * Access via `ketrics.DatabaseConnection.connect()` to obtain an instance.
493
+ * Access via `ketrics.Database.connect()` to obtain an instance.
343
494
  *
344
495
  * @example
345
496
  * ```typescript
346
497
  * export async function handler() {
347
498
  * try {
348
499
  * // Connect to a database
349
- * const db = await ketrics.DatabaseConnection.connect('main-db');
500
+ * const db = await ketrics.Database.connect('main-db');
350
501
  *
351
502
  * // Query data
352
503
  * const result = await db.query('SELECT * FROM users WHERE id = ?', [1]);
@@ -365,16 +516,16 @@ export declare class Volume {
365
516
  * await db.close();
366
517
  *
367
518
  * } catch (error) {
368
- * if (error instanceof ketrics.DatabaseNotFoundError) {
519
+ * if (error instanceof ketrics.Database.NotFoundError) {
369
520
  * console.log('Database not found');
370
- * } else if (error instanceof ketrics.DatabaseAccessDeniedError) {
521
+ * } else if (error instanceof ketrics.Database.AccessDeniedError) {
371
522
  * console.log('No access to database');
372
523
  * }
373
524
  * }
374
525
  * }
375
526
  * ```
376
527
  */
377
- export declare class DatabaseConnection {
528
+ export declare class Database {
378
529
  private constructor();
379
530
  /** Database code (read-only) */
380
531
  readonly code: string;
@@ -384,10 +535,10 @@ export declare class DatabaseConnection {
384
535
  * Connect to a database by code
385
536
  *
386
537
  * @param databaseCode - Database code (e.g., "main-db", "analytics-db")
387
- * @returns Connected DatabaseConnection instance
388
- * @throws DatabaseNotFoundError if database doesn't exist
389
- * @throws DatabaseAccessDeniedError if application has no access grant
390
- * @throws DatabaseConnectionError if connection cannot be established
538
+ * @returns Connected Database instance
539
+ * @throws Database.NotFoundError if database doesn't exist
540
+ * @throws Database.AccessDeniedError if application has no access grant
541
+ * @throws Database.ConnectionError if connection cannot be established
391
542
  */
392
543
  static connect(databaseCode: string): Promise<IDatabaseConnection>;
393
544
  }
@@ -411,9 +562,9 @@ export declare class DatabaseConnection {
411
562
  * }
412
563
  *
413
564
  * } catch (error) {
414
- * if (error instanceof ketrics.SecretNotFoundError) {
565
+ * if (error instanceof ketrics.Secret.NotFoundError) {
415
566
  * console.log('Secret not found');
416
- * } else if (error instanceof ketrics.SecretAccessDeniedError) {
567
+ * } else if (error instanceof ketrics.Secret.AccessDeniedError) {
417
568
  * console.log('No access to secret');
418
569
  * }
419
570
  * }
@@ -472,9 +623,9 @@ export declare class Secret {
472
623
  * await volume.put('output.xlsx', buffer);
473
624
  *
474
625
  * } catch (error) {
475
- * if (error instanceof ketrics.ExcelParseError) {
626
+ * if (error instanceof ketrics.Excel.ParseError) {
476
627
  * console.log('Failed to parse Excel file');
477
- * } else if (error instanceof ketrics.ExcelWriteError) {
628
+ * } else if (error instanceof ketrics.Excel.WriteError) {
478
629
  * console.log('Failed to write Excel file');
479
630
  * }
480
631
  * }
@@ -529,9 +680,9 @@ export declare class Excel {
529
680
  * await volume.put('output.pdf', buffer);
530
681
  *
531
682
  * } catch (error) {
532
- * if (error instanceof ketrics.PdfParseError) {
683
+ * if (error instanceof ketrics.Pdf.ParseError) {
533
684
  * console.log('Failed to parse PDF file');
534
- * } else if (error instanceof ketrics.PdfWriteError) {
685
+ * } else if (error instanceof ketrics.Pdf.WriteError) {
535
686
  * console.log('Failed to write PDF file');
536
687
  * }
537
688
  * }
@@ -592,11 +743,11 @@ export declare class Pdf {
592
743
  * console.log('Pending jobs:', result.jobs.length);
593
744
  *
594
745
  * } catch (error) {
595
- * if (error instanceof ketrics.JobNotFoundError) {
746
+ * if (error instanceof ketrics.Job.NotFoundError) {
596
747
  * console.log('Job not found');
597
- * } else if (error instanceof ketrics.InvalidFunctionError) {
748
+ * } else if (error instanceof ketrics.Job.InvalidFunctionError) {
598
749
  * console.log('Invalid function name');
599
- * } else if (error instanceof ketrics.CrossAppPermissionError) {
750
+ * } else if (error instanceof ketrics.Job.CrossAppPermissionError) {
600
751
  * console.log('Cross-app permission denied');
601
752
  * }
602
753
  * }
@@ -636,15 +787,13 @@ export declare class Job {
636
787
  * The `ketrics` global object provides:
637
788
  * - Context: tenant, application, requestor, runtime, environment
638
789
  * - Utilities: console, http
639
- * - Volume: Static class for S3 storage
640
- * - DatabaseConnection: Static class for database access
641
- * - Secret: Static class for secret retrieval
642
- * - Excel: Static class for Excel file operations
643
- * - Pdf: Static class for PDF file operations
644
- * - Job: Static class for background job execution
645
- * - Messages: Static class for user messaging
646
- * - Error classes: For instanceof checks
647
- * - Type guards: For error type checking
790
+ * - Volume: S3 storage (connect, errors, type guards)
791
+ * - Database: SQL database access (connect, errors, type guards)
792
+ * - Secret: Encrypted secrets (get, exists, errors, type guards)
793
+ * - Excel: Excel file operations (read, create, errors, type guards)
794
+ * - Pdf: PDF file operations (read, create, rgb, errors, type guards)
795
+ * - Job: Background job execution (runInBackground, getStatus, list, errors, type guards)
796
+ * - Messages: Application messaging (send, sendBulk, sendToGroup, errors, type guards)
648
797
  */
649
798
  declare global {
650
799
  /** Ketrics SDK global object - available in all tenant application code */