@ketrics/sdk-backend 0.3.0 → 0.5.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.
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Ketrics SDK - Job Error Classes
3
+ *
4
+ * Provides typed errors for background job operations in tenant applications.
5
+ *
6
+ * Error Hierarchy:
7
+ * - JobError (base)
8
+ * - JobNotFoundError
9
+ * - InvalidFunctionError
10
+ * - CrossAppPermissionError
11
+ * - JobExecutionError
12
+ */
13
+ /**
14
+ * Base error class for all Job errors
15
+ *
16
+ * All Job errors extend this class and include:
17
+ * - jobId: The job ID that caused the error (if applicable)
18
+ * - operation: The operation that failed
19
+ * - timestamp: When the error occurred
20
+ */
21
+ export declare abstract class JobError extends Error {
22
+ /** Job ID that caused the error (if applicable) */
23
+ readonly jobId?: string;
24
+ /** Operation that failed */
25
+ readonly operation: string;
26
+ /** When the error occurred */
27
+ readonly timestamp: Date;
28
+ constructor(message: string, operation: string, jobId?: string);
29
+ /**
30
+ * Serialize error for logging
31
+ */
32
+ toJSON(): Record<string, unknown>;
33
+ }
34
+ /**
35
+ * Error thrown when a job is not found
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * try {
40
+ * const status = await ketrics.Job.getStatus('invalid-job-id');
41
+ * } catch (error) {
42
+ * if (error instanceof ketrics.JobNotFoundError) {
43
+ * console.log(`Job '${error.jobId}' not found`);
44
+ * }
45
+ * }
46
+ * ```
47
+ */
48
+ export declare class JobNotFoundError extends JobError {
49
+ constructor(jobId: string);
50
+ }
51
+ /**
52
+ * Error thrown when function name is invalid or missing
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * try {
57
+ * await ketrics.Job.runInBackground({ function: '' });
58
+ * } catch (error) {
59
+ * if (error instanceof ketrics.InvalidFunctionError) {
60
+ * console.log(`Invalid function: ${error.functionName}`);
61
+ * }
62
+ * }
63
+ * ```
64
+ */
65
+ export declare class InvalidFunctionError extends JobError {
66
+ /** The invalid function name */
67
+ readonly functionName: string;
68
+ constructor(functionName: string);
69
+ toJSON(): Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Error thrown when cross-app job lacks required permission
73
+ *
74
+ * This error occurs when attempting to create a job in another application
75
+ * without a valid application grant that includes background job permission.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * try {
80
+ * await ketrics.Job.runInBackground({
81
+ * application: 'other-app',
82
+ * function: 'processData',
83
+ * });
84
+ * } catch (error) {
85
+ * if (error instanceof ketrics.CrossAppPermissionError) {
86
+ * console.log(`Cannot create job from '${error.sourceApp}' to '${error.targetApp}'`);
87
+ * }
88
+ * }
89
+ * ```
90
+ */
91
+ export declare class CrossAppPermissionError extends JobError {
92
+ /** Source application code (where the job was created from) */
93
+ readonly sourceApp: string;
94
+ /** Target application code (where the job would run) */
95
+ readonly targetApp: string;
96
+ constructor(sourceApp: string, targetApp: string);
97
+ toJSON(): Record<string, unknown>;
98
+ }
99
+ /**
100
+ * Error thrown when job execution fails
101
+ *
102
+ * This error wraps runtime errors that occur during job execution.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const status = await ketrics.Job.getStatus(jobId);
107
+ * if (status.status === 'failed' && status.error) {
108
+ * console.log(`Job failed with code ${status.error.code}: ${status.error.message}`);
109
+ * }
110
+ * ```
111
+ */
112
+ export declare class JobExecutionError extends JobError {
113
+ /** Error code from job execution */
114
+ readonly errorCode: string;
115
+ constructor(jobId: string, errorCode: string, message: string);
116
+ toJSON(): Record<string, unknown>;
117
+ }
118
+ /**
119
+ * Type guard to check if an error is a JobError
120
+ *
121
+ * @param error - The error to check
122
+ * @returns True if the error is a JobError
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * try {
127
+ * await ketrics.Job.runInBackground({ function: 'myFunc' });
128
+ * } catch (error) {
129
+ * if (isJobError(error)) {
130
+ * console.log(`Job error during ${error.operation}: ${error.message}`);
131
+ * }
132
+ * }
133
+ * ```
134
+ */
135
+ export declare function isJobError(error: unknown): error is JobError;
136
+ /**
137
+ * Type guard to check if an error is a specific JobError type
138
+ *
139
+ * @param error - The error to check
140
+ * @param errorClass - The error class to check against
141
+ * @returns True if the error is an instance of the specified class
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * try {
146
+ * await ketrics.Job.getStatus('invalid-id');
147
+ * } catch (error) {
148
+ * if (isJobErrorType(error, JobNotFoundError)) {
149
+ * console.log('Job not found');
150
+ * } else if (isJobErrorType(error, CrossAppPermissionError)) {
151
+ * console.log('Permission denied');
152
+ * }
153
+ * }
154
+ * ```
155
+ */
156
+ export declare function isJobErrorType<T extends JobError>(error: unknown, errorClass: new (...args: never[]) => T): error is T;
157
+ //# sourceMappingURL=job-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-errors.d.ts","sourceRoot":"","sources":["../src/job-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;;;GAOG;AACH,8BAAsB,QAAS,SAAQ,KAAK;IAC1C,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,8BAA8B;IAC9B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAa9D;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAMD;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;gBAChC,KAAK,EAAE,MAAM;CAO1B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;IAChD,gCAAgC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,YAAY,EAAE,MAAM;IAQhC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,uBAAwB,SAAQ,QAAQ;IACnD,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,wDAAwD;IACxD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAShD,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOlC;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAS7D,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,EAC/C,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,GACtC,KAAK,IAAI,CAAC,CAEZ"}
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - Job Error Classes
4
+ *
5
+ * Provides typed errors for background job operations in tenant applications.
6
+ *
7
+ * Error Hierarchy:
8
+ * - JobError (base)
9
+ * - JobNotFoundError
10
+ * - InvalidFunctionError
11
+ * - CrossAppPermissionError
12
+ * - JobExecutionError
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.JobExecutionError = exports.CrossAppPermissionError = exports.InvalidFunctionError = exports.JobNotFoundError = exports.JobError = void 0;
16
+ exports.isJobError = isJobError;
17
+ exports.isJobErrorType = isJobErrorType;
18
+ // ============================================================================
19
+ // Base Error Class
20
+ // ============================================================================
21
+ /**
22
+ * Base error class for all Job errors
23
+ *
24
+ * All Job errors extend this class and include:
25
+ * - jobId: The job ID that caused the error (if applicable)
26
+ * - operation: The operation that failed
27
+ * - timestamp: When the error occurred
28
+ */
29
+ class JobError extends Error {
30
+ constructor(message, operation, jobId) {
31
+ super(message);
32
+ this.name = this.constructor.name;
33
+ this.operation = operation;
34
+ this.jobId = jobId;
35
+ this.timestamp = new Date();
36
+ // Maintains proper stack trace for where error was thrown
37
+ if (Error.captureStackTrace) {
38
+ Error.captureStackTrace(this, this.constructor);
39
+ }
40
+ }
41
+ /**
42
+ * Serialize error for logging
43
+ */
44
+ toJSON() {
45
+ return {
46
+ name: this.name,
47
+ message: this.message,
48
+ jobId: this.jobId,
49
+ operation: this.operation,
50
+ timestamp: this.timestamp.toISOString(),
51
+ };
52
+ }
53
+ }
54
+ exports.JobError = JobError;
55
+ // ============================================================================
56
+ // Specific Error Classes
57
+ // ============================================================================
58
+ /**
59
+ * Error thrown when a job is not found
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * try {
64
+ * const status = await ketrics.Job.getStatus('invalid-job-id');
65
+ * } catch (error) {
66
+ * if (error instanceof ketrics.JobNotFoundError) {
67
+ * console.log(`Job '${error.jobId}' not found`);
68
+ * }
69
+ * }
70
+ * ```
71
+ */
72
+ class JobNotFoundError extends JobError {
73
+ constructor(jobId) {
74
+ super(`Job '${jobId}' not found. Verify the job ID is correct and the job exists.`, 'getStatus', jobId);
75
+ }
76
+ }
77
+ exports.JobNotFoundError = JobNotFoundError;
78
+ /**
79
+ * Error thrown when function name is invalid or missing
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * try {
84
+ * await ketrics.Job.runInBackground({ function: '' });
85
+ * } catch (error) {
86
+ * if (error instanceof ketrics.InvalidFunctionError) {
87
+ * console.log(`Invalid function: ${error.functionName}`);
88
+ * }
89
+ * }
90
+ * ```
91
+ */
92
+ class InvalidFunctionError extends JobError {
93
+ constructor(functionName) {
94
+ super(`Invalid function name '${functionName}'. Function name must be a non-empty string.`, 'runInBackground');
95
+ this.functionName = functionName;
96
+ }
97
+ toJSON() {
98
+ return {
99
+ ...super.toJSON(),
100
+ functionName: this.functionName,
101
+ };
102
+ }
103
+ }
104
+ exports.InvalidFunctionError = InvalidFunctionError;
105
+ /**
106
+ * Error thrown when cross-app job lacks required permission
107
+ *
108
+ * This error occurs when attempting to create a job in another application
109
+ * without a valid application grant that includes background job permission.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * try {
114
+ * await ketrics.Job.runInBackground({
115
+ * application: 'other-app',
116
+ * function: 'processData',
117
+ * });
118
+ * } catch (error) {
119
+ * if (error instanceof ketrics.CrossAppPermissionError) {
120
+ * console.log(`Cannot create job from '${error.sourceApp}' to '${error.targetApp}'`);
121
+ * }
122
+ * }
123
+ * ```
124
+ */
125
+ class CrossAppPermissionError extends JobError {
126
+ constructor(sourceApp, targetApp) {
127
+ super(`Cross-app job permission denied. Application '${sourceApp}' does not have background job permission for '${targetApp}'.`, 'runInBackground');
128
+ this.sourceApp = sourceApp;
129
+ this.targetApp = targetApp;
130
+ }
131
+ toJSON() {
132
+ return {
133
+ ...super.toJSON(),
134
+ sourceApp: this.sourceApp,
135
+ targetApp: this.targetApp,
136
+ };
137
+ }
138
+ }
139
+ exports.CrossAppPermissionError = CrossAppPermissionError;
140
+ /**
141
+ * Error thrown when job execution fails
142
+ *
143
+ * This error wraps runtime errors that occur during job execution.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const status = await ketrics.Job.getStatus(jobId);
148
+ * if (status.status === 'failed' && status.error) {
149
+ * console.log(`Job failed with code ${status.error.code}: ${status.error.message}`);
150
+ * }
151
+ * ```
152
+ */
153
+ class JobExecutionError extends JobError {
154
+ constructor(jobId, errorCode, message) {
155
+ super(`Job '${jobId}' execution failed: ${message}`, 'execute', jobId);
156
+ this.errorCode = errorCode;
157
+ }
158
+ toJSON() {
159
+ return {
160
+ ...super.toJSON(),
161
+ errorCode: this.errorCode,
162
+ };
163
+ }
164
+ }
165
+ exports.JobExecutionError = JobExecutionError;
166
+ // ============================================================================
167
+ // Type Guards
168
+ // ============================================================================
169
+ /**
170
+ * Type guard to check if an error is a JobError
171
+ *
172
+ * @param error - The error to check
173
+ * @returns True if the error is a JobError
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * try {
178
+ * await ketrics.Job.runInBackground({ function: 'myFunc' });
179
+ * } catch (error) {
180
+ * if (isJobError(error)) {
181
+ * console.log(`Job error during ${error.operation}: ${error.message}`);
182
+ * }
183
+ * }
184
+ * ```
185
+ */
186
+ function isJobError(error) {
187
+ return error instanceof JobError;
188
+ }
189
+ /**
190
+ * Type guard to check if an error is a specific JobError type
191
+ *
192
+ * @param error - The error to check
193
+ * @param errorClass - The error class to check against
194
+ * @returns True if the error is an instance of the specified class
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * try {
199
+ * await ketrics.Job.getStatus('invalid-id');
200
+ * } catch (error) {
201
+ * if (isJobErrorType(error, JobNotFoundError)) {
202
+ * console.log('Job not found');
203
+ * } else if (isJobErrorType(error, CrossAppPermissionError)) {
204
+ * console.log('Permission denied');
205
+ * }
206
+ * }
207
+ * ```
208
+ */
209
+ function isJobErrorType(error, errorClass) {
210
+ return error instanceof errorClass;
211
+ }
212
+ //# sourceMappingURL=job-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-errors.js","sourceRoot":"","sources":["../src/job-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAqNH,gCAEC;AAsBD,wCAKC;AAhPD,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;GAOG;AACH,MAAsB,QAAS,SAAQ,KAAK;IAU1C,YAAY,OAAe,EAAE,SAAiB,EAAE,KAAc;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,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Q,QAAQ;IAOnD,YAAY,SAAiB,EAAE,SAAiB;QAC9C,KAAK,CACH,iDAAiD,SAAS,kDAAkD,SAAS,IAAI,EACzH,iBAAiB,CAClB,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;CACF;AAvBD,0DAuBC;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,iBAAkB,SAAQ,QAAQ;IAI7C,YAAY,KAAa,EAAE,SAAiB,EAAE,OAAe;QAC3D,KAAK,CACH,QAAQ,KAAK,uBAAuB,OAAO,EAAE,EAC7C,SAAS,EACT,KAAK,CACN,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;CACF;AAnBD,8CAmBC;AAED,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc,CAC5B,KAAc,EACd,UAAuC;IAEvC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC"}
package/dist/job.d.ts ADDED
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Ketrics SDK - Job Interfaces and Types
3
+ *
4
+ * Provides type definitions for background job execution
5
+ * in tenant applications.
6
+ *
7
+ * Usage in tenant code:
8
+ * ```typescript
9
+ * // Queue a background job
10
+ * const jobId = await ketrics.Job.runInBackground({
11
+ * function: 'generateReport',
12
+ * payload: { year: 2024 },
13
+ * options: { timeout: 600000 }
14
+ * });
15
+ *
16
+ * // Check job status
17
+ * const status = await ketrics.Job.getStatus(jobId);
18
+ * if (status.status === 'completed') {
19
+ * console.log('Job completed at:', status.completedAt);
20
+ * }
21
+ *
22
+ * // List pending jobs
23
+ * const result = await ketrics.Job.list({ status: 'pending', limit: 10 });
24
+ * for (const job of result.jobs) {
25
+ * console.log(job.jobId, job.functionName);
26
+ * }
27
+ * ```
28
+ */
29
+ /**
30
+ * Job status string literal type
31
+ */
32
+ export type JobStatusValue = 'pending' | 'running' | 'completed' | 'failed';
33
+ /**
34
+ * Options for background job execution
35
+ */
36
+ export interface RunInBackgroundOptions {
37
+ /**
38
+ * Execution timeout in milliseconds
39
+ *
40
+ * @default 300000 (5 minutes)
41
+ * @max 900000 (15 minutes)
42
+ */
43
+ timeout?: number;
44
+ /**
45
+ * Idempotency key to prevent duplicate job creation
46
+ *
47
+ * If a job with the same idempotency key already exists,
48
+ * the existing job ID will be returned instead of creating a new job.
49
+ */
50
+ idempotencyKey?: string;
51
+ }
52
+ /**
53
+ * Parameters for Job.runInBackground()
54
+ */
55
+ export interface RunInBackgroundParams {
56
+ /**
57
+ * Target application code (optional)
58
+ *
59
+ * If specified, creates a cross-app job that executes in another application.
60
+ * Requires a valid application grant with background job permission.
61
+ * If omitted, the job executes in the current application.
62
+ */
63
+ application?: string;
64
+ /**
65
+ * Function name to execute
66
+ *
67
+ * Must be an exported function in the target application.
68
+ */
69
+ function: string;
70
+ /**
71
+ * Payload to pass to the function
72
+ *
73
+ * This object will be passed as the first argument to the function.
74
+ */
75
+ payload?: Record<string, unknown>;
76
+ /**
77
+ * Execution options
78
+ */
79
+ options?: RunInBackgroundOptions;
80
+ }
81
+ /**
82
+ * Job error details
83
+ */
84
+ export interface JobErrorDetails {
85
+ /**
86
+ * Error code
87
+ *
88
+ * Common codes:
89
+ * - 'TIMEOUT': Job exceeded execution timeout
90
+ * - 'RUNTIME_ERROR': Unhandled exception in function
91
+ * - 'FUNCTION_NOT_FOUND': Target function does not exist
92
+ */
93
+ code: string;
94
+ /** Human-readable error message */
95
+ message: string;
96
+ }
97
+ /**
98
+ * Job status returned from getStatus() and list()
99
+ */
100
+ export interface JobStatus {
101
+ /** Job UUID */
102
+ jobId: string;
103
+ /** Application UUID where the job runs */
104
+ applicationId: string;
105
+ /** Application code where the job runs */
106
+ applicationCode: string;
107
+ /** Function name being executed */
108
+ functionName: string;
109
+ /** Current job status */
110
+ status: JobStatusValue;
111
+ /** ISO timestamp when the job was created */
112
+ createdAt: string;
113
+ /** ISO timestamp when the job started execution (optional) */
114
+ startedAt?: string;
115
+ /** ISO timestamp when the job completed (optional) */
116
+ completedAt?: string;
117
+ /** Error details if the job failed (optional) */
118
+ error?: JobErrorDetails;
119
+ }
120
+ /**
121
+ * Parameters for Job.list()
122
+ */
123
+ export interface JobListParams {
124
+ /**
125
+ * Filter by job status
126
+ *
127
+ * If omitted, returns jobs of all statuses.
128
+ */
129
+ status?: JobStatusValue;
130
+ /**
131
+ * Maximum number of results to return
132
+ *
133
+ * @default 20
134
+ * @max 100
135
+ */
136
+ limit?: number;
137
+ /**
138
+ * Pagination cursor from previous response
139
+ *
140
+ * Pass the `cursor` from a previous JobListResult to fetch the next page.
141
+ */
142
+ cursor?: string;
143
+ }
144
+ /**
145
+ * Result from Job.list()
146
+ */
147
+ export interface JobListResult {
148
+ /** Array of job status objects */
149
+ jobs: JobStatus[];
150
+ /**
151
+ * Pagination cursor for fetching the next page
152
+ *
153
+ * If present, more results are available. Pass this value as
154
+ * the `cursor` parameter in the next call to get the next page.
155
+ */
156
+ cursor?: string;
157
+ }
158
+ //# sourceMappingURL=job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;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CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kCAAkC;IAClC,IAAI,EAAE,SAAS,EAAE,CAAC;IAElB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/dist/job.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - Job Interfaces and Types
4
+ *
5
+ * Provides type definitions for background job execution
6
+ * in tenant applications.
7
+ *
8
+ * Usage in tenant code:
9
+ * ```typescript
10
+ * // Queue a background job
11
+ * const jobId = await ketrics.Job.runInBackground({
12
+ * function: 'generateReport',
13
+ * payload: { year: 2024 },
14
+ * options: { timeout: 600000 }
15
+ * });
16
+ *
17
+ * // Check job status
18
+ * const status = await ketrics.Job.getStatus(jobId);
19
+ * if (status.status === 'completed') {
20
+ * console.log('Job completed at:', status.completedAt);
21
+ * }
22
+ *
23
+ * // List pending jobs
24
+ * const result = await ketrics.Job.list({ status: 'pending', limit: 10 });
25
+ * for (const job of result.jobs) {
26
+ * console.log(job.jobId, job.functionName);
27
+ * }
28
+ * ```
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ //# sourceMappingURL=job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job.js","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Ketrics SDK - Messages Error Classes
3
+ *
4
+ * Provides error class definitions for the Messages SDK.
5
+ * These classes are used for error handling in tenant applications.
6
+ *
7
+ * Usage in tenant code:
8
+ * ```typescript
9
+ * try {
10
+ * await ketrics.Messages.sendToGroup({
11
+ * groupCode: 'engineering-team',
12
+ * type: 'TEAM_UPDATE',
13
+ * subject: 'Sprint planning',
14
+ * body: '...'
15
+ * });
16
+ * } catch (error) {
17
+ * if (error instanceof ketrics.MessageValidationError) {
18
+ * console.log('Invalid message parameters:', error.message);
19
+ * } else if (error instanceof ketrics.GroupNotFoundError) {
20
+ * console.log('Group not found:', error.message);
21
+ * } else if (error instanceof ketrics.TenantGrantPermissionDeniedError) {
22
+ * console.log('Missing permissions:', error.missingPermissions);
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ /**
28
+ * Base error class for message-related errors
29
+ */
30
+ export declare class MessageError extends Error {
31
+ readonly code: string;
32
+ constructor(message: string, code?: string);
33
+ }
34
+ /**
35
+ * Error thrown when message validation fails
36
+ */
37
+ export declare class MessageValidationError extends MessageError {
38
+ constructor(message: string);
39
+ }
40
+ /**
41
+ * Error thrown when group is not found
42
+ */
43
+ export declare class GroupNotFoundError extends MessageError {
44
+ constructor(groupCode: string);
45
+ }
46
+ /**
47
+ * Error thrown when application IAM-data permission is missing
48
+ *
49
+ * This error is thrown when an application tries to access tenant data
50
+ * (users, groups, group memberships) without having the required
51
+ * IAM-data permissions assigned via its role.
52
+ */
53
+ export declare class TenantGrantPermissionDeniedError extends MessageError {
54
+ readonly missingPermissions: string[];
55
+ constructor(message: string, code?: string);
56
+ /**
57
+ * Factory method to create error with permissions list
58
+ */
59
+ static withPermissions(permissions: string[]): TenantGrantPermissionDeniedError;
60
+ }
61
+ /**
62
+ * Type guard to check if an error is a MessageError
63
+ */
64
+ export declare function isMessageError(error: unknown): error is MessageError;
65
+ /**
66
+ * Type guard to check if an error is a specific MessageError type
67
+ */
68
+ export declare function isMessageErrorType<T extends MessageError>(error: unknown, errorClass: new (...args: any[]) => T): error is T;
69
+ //# sourceMappingURL=messages-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages-errors.d.ts","sourceRoot":"","sources":["../src/messages-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAMD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,YAAY;gBAC1C,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;gBACtC,SAAS,EAAE,MAAM;CAI9B;AAED;;;;;;GAMG;AACH,qBAAa,gCAAiC,SAAQ,YAAY;IAChE,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAC;gBAEjC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAQ1C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,gCAAgC;CAMhF;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,EACvD,KAAK,EAAE,OAAO,EAEd,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACpC,KAAK,IAAI,CAAC,CAEZ"}