@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,110 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - Messages Error Classes
4
+ *
5
+ * Provides error class definitions for the Messages SDK.
6
+ * These classes are used for error handling in tenant applications.
7
+ *
8
+ * Usage in tenant code:
9
+ * ```typescript
10
+ * try {
11
+ * await ketrics.Messages.sendToGroup({
12
+ * groupCode: 'engineering-team',
13
+ * type: 'TEAM_UPDATE',
14
+ * subject: 'Sprint planning',
15
+ * body: '...'
16
+ * });
17
+ * } catch (error) {
18
+ * if (error instanceof ketrics.MessageValidationError) {
19
+ * console.log('Invalid message parameters:', error.message);
20
+ * } else if (error instanceof ketrics.GroupNotFoundError) {
21
+ * console.log('Group not found:', error.message);
22
+ * } else if (error instanceof ketrics.TenantGrantPermissionDeniedError) {
23
+ * console.log('Missing permissions:', error.missingPermissions);
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TenantGrantPermissionDeniedError = exports.GroupNotFoundError = exports.MessageValidationError = exports.MessageError = void 0;
30
+ exports.isMessageError = isMessageError;
31
+ exports.isMessageErrorType = isMessageErrorType;
32
+ // ============================================================================
33
+ // Base Message Error
34
+ // ============================================================================
35
+ /**
36
+ * Base error class for message-related errors
37
+ */
38
+ class MessageError extends Error {
39
+ constructor(message, code) {
40
+ super(message);
41
+ this.name = 'MessageError';
42
+ this.code = code ?? 'MESSAGE_ERROR';
43
+ }
44
+ }
45
+ exports.MessageError = MessageError;
46
+ // ============================================================================
47
+ // Specific Message Errors
48
+ // ============================================================================
49
+ /**
50
+ * Error thrown when message validation fails
51
+ */
52
+ class MessageValidationError extends MessageError {
53
+ constructor(message) {
54
+ super(message, 'VALIDATION_ERROR');
55
+ this.name = 'MessageValidationError';
56
+ }
57
+ }
58
+ exports.MessageValidationError = MessageValidationError;
59
+ /**
60
+ * Error thrown when group is not found
61
+ */
62
+ class GroupNotFoundError extends MessageError {
63
+ constructor(groupCode) {
64
+ super(`Group not found: ${groupCode}`, 'GROUP_NOT_FOUND');
65
+ this.name = 'GroupNotFoundError';
66
+ }
67
+ }
68
+ exports.GroupNotFoundError = GroupNotFoundError;
69
+ /**
70
+ * Error thrown when application IAM-data permission is missing
71
+ *
72
+ * This error is thrown when an application tries to access tenant data
73
+ * (users, groups, group memberships) without having the required
74
+ * IAM-data permissions assigned via its role.
75
+ */
76
+ class TenantGrantPermissionDeniedError extends MessageError {
77
+ constructor(message, code) {
78
+ super(message, code ?? 'PERMISSION_DENIED');
79
+ this.name = 'TenantGrantPermissionDeniedError';
80
+ // Parse missing permissions from message if it follows the standard format
81
+ const match = message.match(/permissions: (.+)/);
82
+ this.missingPermissions = match ? match[1].split(', ') : [];
83
+ }
84
+ /**
85
+ * Factory method to create error with permissions list
86
+ */
87
+ static withPermissions(permissions) {
88
+ return new TenantGrantPermissionDeniedError(`Application is missing required IAM-data permissions: ${permissions.join(', ')}. ` +
89
+ `Assign a role with these permissions to the application.`);
90
+ }
91
+ }
92
+ exports.TenantGrantPermissionDeniedError = TenantGrantPermissionDeniedError;
93
+ // ============================================================================
94
+ // Type Guards
95
+ // ============================================================================
96
+ /**
97
+ * Type guard to check if an error is a MessageError
98
+ */
99
+ function isMessageError(error) {
100
+ return error instanceof MessageError;
101
+ }
102
+ /**
103
+ * Type guard to check if an error is a specific MessageError type
104
+ */
105
+ function isMessageErrorType(error,
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ errorClass) {
108
+ return error instanceof errorClass;
109
+ }
110
+ //# sourceMappingURL=messages-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages-errors.js","sourceRoot":"","sources":["../src/messages-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AA+EH,wCAEC;AAKD,gDAMC;A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AAyD,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACjF,0DAA0D,CAC7D,CAAC;IACJ,CAAC;CACF;AApBD,4EAoBC;AAED,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAChC,KAAc;AACd,8DAA8D;AAC9D,UAAqC;IAErC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Ketrics SDK - Messages Interfaces and Types
3
+ *
4
+ * Provides type definitions for the Messages SDK that allows
5
+ * tenant applications to send messages to users.
6
+ *
7
+ * Usage in tenant code:
8
+ * ```typescript
9
+ * // Send single message
10
+ * const result = await ketrics.Messages.send({
11
+ * userId: 'user-123',
12
+ * type: 'ORDER_SHIPPED',
13
+ * subject: 'Your order has shipped!',
14
+ * body: 'Track your package...',
15
+ * priority: 'HIGH'
16
+ * });
17
+ *
18
+ * // Send to multiple users
19
+ * const bulk = await ketrics.Messages.sendBulk({
20
+ * userIds: ['user-1', 'user-2'],
21
+ * type: 'ANNOUNCEMENT',
22
+ * subject: 'Important update',
23
+ * body: '...'
24
+ * });
25
+ *
26
+ * // Send to a group (requires IAM-data permissions via application role)
27
+ * const group = await ketrics.Messages.sendToGroup({
28
+ * groupCode: 'engineering-team',
29
+ * type: 'TEAM_UPDATE',
30
+ * subject: 'Sprint planning tomorrow',
31
+ * body: '...'
32
+ * });
33
+ * ```
34
+ *
35
+ * Key Distinction:
36
+ * - Messages: Content sent by apps to users, stored in their inbox
37
+ * - Notifications: Alerts (push) that tell users about new messages
38
+ */
39
+ /**
40
+ * Message priority level
41
+ */
42
+ export type MessagePriorityLevel = 'LOW' | 'MEDIUM' | 'HIGH';
43
+ /**
44
+ * Channel configuration for message delivery
45
+ */
46
+ export interface MessageChannelConfig {
47
+ /** Store in user's inbox (always enabled) */
48
+ inbox: boolean;
49
+ /** Send push notification alert */
50
+ push: boolean;
51
+ }
52
+ /**
53
+ * Parameters for Messages.send()
54
+ */
55
+ export interface SendMessageParams {
56
+ /** Recipient user ID */
57
+ userId: string;
58
+ /** Application-defined message type */
59
+ type: string;
60
+ /** Message subject/title (max 200 chars) */
61
+ subject: string;
62
+ /** Message body (max 10,000 chars, markdown supported) */
63
+ body: string;
64
+ /** Priority level (default: MEDIUM) */
65
+ priority?: MessagePriorityLevel;
66
+ /** Optional channel overrides */
67
+ channels?: Partial<MessageChannelConfig>;
68
+ /** Optional action URL for deep linking */
69
+ actionUrl?: string;
70
+ /** Optional custom data for app use */
71
+ data?: Record<string, unknown>;
72
+ /** Optional expiration timestamp (ISO) */
73
+ expiresAt?: string;
74
+ }
75
+ /**
76
+ * Parameters for Messages.sendBulk()
77
+ */
78
+ export interface SendBulkMessageParams {
79
+ /** Array of user IDs to message */
80
+ userIds: string[];
81
+ /** Message content (same for all recipients) */
82
+ type: string;
83
+ subject: string;
84
+ body: string;
85
+ priority?: MessagePriorityLevel;
86
+ channels?: Partial<MessageChannelConfig>;
87
+ actionUrl?: string;
88
+ data?: Record<string, unknown>;
89
+ expiresAt?: string;
90
+ }
91
+ /**
92
+ * Parameters for Messages.sendToGroup()
93
+ */
94
+ export interface SendGroupMessageParams {
95
+ /** Group code to send message to */
96
+ groupCode: string;
97
+ /** Message content (same for all group members) */
98
+ type: string;
99
+ subject: string;
100
+ body: string;
101
+ priority?: MessagePriorityLevel;
102
+ channels?: Partial<MessageChannelConfig>;
103
+ actionUrl?: string;
104
+ data?: Record<string, unknown>;
105
+ expiresAt?: string;
106
+ }
107
+ /**
108
+ * Result of sending a single message
109
+ */
110
+ export interface SendMessageResult {
111
+ messageId: string;
112
+ userId: string;
113
+ status: 'sent' | 'failed';
114
+ error?: string;
115
+ }
116
+ /**
117
+ * Result of sending bulk messages
118
+ */
119
+ export interface SendBulkMessageResult {
120
+ total: number;
121
+ sent: number;
122
+ failed: number;
123
+ results: SendMessageResult[];
124
+ }
125
+ /**
126
+ * Messages SDK module interface
127
+ *
128
+ * Provides methods for sending messages to users in tenant applications.
129
+ */
130
+ export interface MessagesManager {
131
+ /**
132
+ * Send message to a single user
133
+ * No TenantGrant required (userId is explicit)
134
+ *
135
+ * @param params - Message parameters
136
+ * @returns Result with messageId and status
137
+ * @throws MessageValidationError if parameters are invalid
138
+ */
139
+ send(params: SendMessageParams): Promise<SendMessageResult>;
140
+ /**
141
+ * Send message to multiple users
142
+ * No TenantGrant required (userIds are explicit)
143
+ *
144
+ * @param params - Bulk message parameters
145
+ * @returns Results with counts and individual statuses
146
+ * @throws MessageValidationError if parameters are invalid
147
+ */
148
+ sendBulk(params: SendBulkMessageParams): Promise<SendBulkMessageResult>;
149
+ /**
150
+ * Send message to all members of a group
151
+ *
152
+ * Requires IAM-data permissions: iam:GetGroupData + iam:GetMembershipData
153
+ * These permissions must be assigned to the application via its role.
154
+ *
155
+ * @param params - Group message parameters
156
+ * @returns Results with counts and individual statuses
157
+ * @throws MessageValidationError if parameters are invalid
158
+ * @throws GroupNotFoundError if group doesn't exist
159
+ * @throws TenantGrantPermissionDeniedError if IAM-data permissions are missing
160
+ */
161
+ sendToGroup(params: SendGroupMessageParams): Promise<SendBulkMessageResult>;
162
+ }
163
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAMH;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAM7D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,IAAI,EAAE,OAAO,CAAC;CACf;AAMD;;GAEG;AACH,M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C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAMD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE5D;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAExE;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC7E"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - Messages Interfaces and Types
4
+ *
5
+ * Provides type definitions for the Messages SDK that allows
6
+ * tenant applications to send messages to users.
7
+ *
8
+ * Usage in tenant code:
9
+ * ```typescript
10
+ * // Send single message
11
+ * const result = await ketrics.Messages.send({
12
+ * userId: 'user-123',
13
+ * type: 'ORDER_SHIPPED',
14
+ * subject: 'Your order has shipped!',
15
+ * body: 'Track your package...',
16
+ * priority: 'HIGH'
17
+ * });
18
+ *
19
+ * // Send to multiple users
20
+ * const bulk = await ketrics.Messages.sendBulk({
21
+ * userIds: ['user-1', 'user-2'],
22
+ * type: 'ANNOUNCEMENT',
23
+ * subject: 'Important update',
24
+ * body: '...'
25
+ * });
26
+ *
27
+ * // Send to a group (requires IAM-data permissions via application role)
28
+ * const group = await ketrics.Messages.sendToGroup({
29
+ * groupCode: 'engineering-team',
30
+ * type: 'TEAM_UPDATE',
31
+ * subject: 'Sprint planning tomorrow',
32
+ * body: '...'
33
+ * });
34
+ * ```
35
+ *
36
+ * Key Distinction:
37
+ * - Messages: Content sent by apps to users, stored in their inbox
38
+ * - Notifications: Alerts (push) that tell users about new messages
39
+ */
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * PDF SDK Error Classes
3
+ *
4
+ * Error types for PDF operations in tenant applications.
5
+ */
6
+ /**
7
+ * Base error for all PDF operations
8
+ *
9
+ * All PDF-related errors inherit from this class, providing
10
+ * consistent context and structure for error handling.
11
+ */
12
+ export declare abstract class PdfError extends Error {
13
+ /** Operation that caused the error */
14
+ readonly operation: string;
15
+ /** Timestamp when the error occurred */
16
+ readonly timestamp: Date;
17
+ constructor(operation: string, message: string);
18
+ /**
19
+ * Convert error to JSON-serializable object
20
+ */
21
+ toJSON(): Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Error parsing PDF file
25
+ *
26
+ * Thrown when a PDF file cannot be parsed due to invalid format,
27
+ * corrupted data, or unsupported features.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * try {
32
+ * const doc = await ketrics.Pdf.read(buffer);
33
+ * } catch (error) {
34
+ * if (error instanceof ketrics.PdfParseError) {
35
+ * console.log('Failed to parse PDF file:', error.message);
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ export declare class PdfParseError extends PdfError {
41
+ /** The reason for the parse failure */
42
+ readonly reason: string;
43
+ constructor(reason: string);
44
+ toJSON(): Record<string, unknown>;
45
+ }
46
+ /**
47
+ * Error writing PDF file
48
+ *
49
+ * Thrown when a PDF file cannot be written due to invalid data
50
+ * or other write errors.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * try {
55
+ * const buffer = await doc.toBuffer();
56
+ * } catch (error) {
57
+ * if (error instanceof ketrics.PdfWriteError) {
58
+ * console.log('Failed to write PDF file:', error.message);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export declare class PdfWriteError extends PdfError {
64
+ /** The reason for the write failure */
65
+ readonly reason: string;
66
+ constructor(reason: string);
67
+ toJSON(): Record<string, unknown>;
68
+ }
69
+ /**
70
+ * Type guard to check if an error is a PdfError
71
+ */
72
+ export declare function isPdfError(error: unknown): error is PdfError;
73
+ /**
74
+ * Type guard to check if an error is a specific PDF error type
75
+ */
76
+ export declare function isPdfErrorType<T extends PdfError>(error: unknown, errorClass: new (...args: never[]) => T): error is T;
77
+ //# sourceMappingURL=pdf-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-errors.d.ts","sourceRoot":"","sources":["../src/pdf-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;;;GAKG;AACH,8BAAsB,QAAS,SAAQ,KAAK;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEb,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAc9C;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQlC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;IAK1B,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;IAK1B,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAMD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;GAEG;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,127 @@
1
+ "use strict";
2
+ /**
3
+ * PDF SDK Error Classes
4
+ *
5
+ * Error types for PDF operations in tenant applications.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.PdfWriteError = exports.PdfParseError = exports.PdfError = void 0;
9
+ exports.isPdfError = isPdfError;
10
+ exports.isPdfErrorType = isPdfErrorType;
11
+ // ============================================================================
12
+ // Base PDF Error
13
+ // ============================================================================
14
+ /**
15
+ * Base error for all PDF operations
16
+ *
17
+ * All PDF-related errors inherit from this class, providing
18
+ * consistent context and structure for error handling.
19
+ */
20
+ class PdfError extends Error {
21
+ constructor(operation, message) {
22
+ super(message);
23
+ this.name = this.constructor.name;
24
+ this.operation = operation;
25
+ this.timestamp = new Date();
26
+ // Maintain proper stack trace in V8 environments
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ if (Error.captureStackTrace) {
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ Error.captureStackTrace(this, this.constructor);
31
+ }
32
+ }
33
+ /**
34
+ * Convert error to JSON-serializable object
35
+ */
36
+ toJSON() {
37
+ return {
38
+ name: this.name,
39
+ message: this.message,
40
+ operation: this.operation,
41
+ timestamp: this.timestamp.toISOString(),
42
+ };
43
+ }
44
+ }
45
+ exports.PdfError = PdfError;
46
+ // ============================================================================
47
+ // PDF Parse Error
48
+ // ============================================================================
49
+ /**
50
+ * Error parsing PDF file
51
+ *
52
+ * Thrown when a PDF file cannot be parsed due to invalid format,
53
+ * corrupted data, or unsupported features.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * try {
58
+ * const doc = await ketrics.Pdf.read(buffer);
59
+ * } catch (error) {
60
+ * if (error instanceof ketrics.PdfParseError) {
61
+ * console.log('Failed to parse PDF file:', error.message);
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ class PdfParseError extends PdfError {
67
+ constructor(reason) {
68
+ super('read', `Failed to parse PDF file: ${reason}`);
69
+ this.reason = reason;
70
+ }
71
+ toJSON() {
72
+ return {
73
+ ...super.toJSON(),
74
+ reason: this.reason,
75
+ };
76
+ }
77
+ }
78
+ exports.PdfParseError = PdfParseError;
79
+ // ============================================================================
80
+ // PDF Write Error
81
+ // ============================================================================
82
+ /**
83
+ * Error writing PDF file
84
+ *
85
+ * Thrown when a PDF file cannot be written due to invalid data
86
+ * or other write errors.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * try {
91
+ * const buffer = await doc.toBuffer();
92
+ * } catch (error) {
93
+ * if (error instanceof ketrics.PdfWriteError) {
94
+ * console.log('Failed to write PDF file:', error.message);
95
+ * }
96
+ * }
97
+ * ```
98
+ */
99
+ class PdfWriteError extends PdfError {
100
+ constructor(reason) {
101
+ super('write', `Failed to write PDF file: ${reason}`);
102
+ this.reason = reason;
103
+ }
104
+ toJSON() {
105
+ return {
106
+ ...super.toJSON(),
107
+ reason: this.reason,
108
+ };
109
+ }
110
+ }
111
+ exports.PdfWriteError = PdfWriteError;
112
+ // ============================================================================
113
+ // Type Guards
114
+ // ============================================================================
115
+ /**
116
+ * Type guard to check if an error is a PdfError
117
+ */
118
+ function isPdfError(error) {
119
+ return error instanceof PdfError;
120
+ }
121
+ /**
122
+ * Type guard to check if an error is a specific PDF error type
123
+ */
124
+ function isPdfErrorType(error, errorClass) {
125
+ return error instanceof errorClass;
126
+ }
127
+ //# sourceMappingURL=pdf-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-errors.js","sourceRoot":"","sources":["../src/pdf-errors.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAiIH,gCAEC;AAKD,wCAKC;AA3ID,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAsB,QAAS,SAAQ,KAAK;IAO1C,YAAY,SAAiB,EAAE,OAAe;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAE5B,iDAAiD;QACjD,8DAA8D;QAC9D,IAAK,KAAa,CAAC,iBAAiB,EAAE,CAAC;YACrC,8DAA8D;YAC7D,KAAa,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;SACxC,CAAC;IACJ,CAAC;CACF;AAhCD,4BAgCC;AAED,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,aAAc,SAAQ,QAAQ;IAIzC,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,EAAE,6BAA6B,MAAM,EAAE,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