pdf-oxide-fips 0.3.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +25 -0
  3. package/README.md +218 -0
  4. package/lib/builders/annotation-builder.d.ts +198 -0
  5. package/lib/builders/annotation-builder.js +317 -0
  6. package/lib/builders/conversion-options-builder.d.ts +106 -0
  7. package/lib/builders/conversion-options-builder.js +214 -0
  8. package/lib/builders/document-builder.d.ts +381 -0
  9. package/lib/builders/document-builder.js +770 -0
  10. package/lib/builders/index.d.ts +13 -0
  11. package/lib/builders/index.js +13 -0
  12. package/lib/builders/metadata-builder.d.ts +201 -0
  13. package/lib/builders/metadata-builder.js +285 -0
  14. package/lib/builders/pdf-builder.d.ts +216 -0
  15. package/lib/builders/pdf-builder.js +350 -0
  16. package/lib/builders/search-options-builder.d.ts +73 -0
  17. package/lib/builders/search-options-builder.js +129 -0
  18. package/lib/builders/streaming-table.d.ts +64 -0
  19. package/lib/builders/streaming-table.js +140 -0
  20. package/lib/document-editor-manager.d.ts +139 -0
  21. package/lib/document-editor-manager.js +256 -0
  22. package/lib/document-editor.d.ts +124 -0
  23. package/lib/document-editor.js +318 -0
  24. package/lib/errors.d.ts +382 -0
  25. package/lib/errors.js +1115 -0
  26. package/lib/form-field-manager.d.ts +299 -0
  27. package/lib/form-field-manager.js +568 -0
  28. package/lib/hybrid-ml-manager.d.ts +142 -0
  29. package/lib/hybrid-ml-manager.js +208 -0
  30. package/lib/index.d.ts +205 -0
  31. package/lib/index.js +693 -0
  32. package/lib/managers/accessibility-manager.d.ts +148 -0
  33. package/lib/managers/accessibility-manager.js +234 -0
  34. package/lib/managers/annotation-manager.d.ts +219 -0
  35. package/lib/managers/annotation-manager.js +359 -0
  36. package/lib/managers/barcode-manager.d.ts +82 -0
  37. package/lib/managers/barcode-manager.js +263 -0
  38. package/lib/managers/batch-manager.d.ts +185 -0
  39. package/lib/managers/batch-manager.js +385 -0
  40. package/lib/managers/cache-manager.d.ts +181 -0
  41. package/lib/managers/cache-manager.js +384 -0
  42. package/lib/managers/compliance-manager.d.ts +103 -0
  43. package/lib/managers/compliance-manager.js +453 -0
  44. package/lib/managers/content-manager.d.ts +120 -0
  45. package/lib/managers/content-manager.js +294 -0
  46. package/lib/managers/document-utility-manager.d.ts +369 -0
  47. package/lib/managers/document-utility-manager.js +730 -0
  48. package/lib/managers/dom-pdf-creator.d.ts +104 -0
  49. package/lib/managers/dom-pdf-creator.js +299 -0
  50. package/lib/managers/editing-manager.d.ts +248 -0
  51. package/lib/managers/editing-manager.js +387 -0
  52. package/lib/managers/enterprise-manager.d.ts +192 -0
  53. package/lib/managers/enterprise-manager.js +307 -0
  54. package/lib/managers/extended-managers.d.ts +122 -0
  55. package/lib/managers/extended-managers.js +664 -0
  56. package/lib/managers/extraction-manager.d.ts +246 -0
  57. package/lib/managers/extraction-manager.js +482 -0
  58. package/lib/managers/final-utilities.d.ts +127 -0
  59. package/lib/managers/final-utilities.js +657 -0
  60. package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
  61. package/lib/managers/hybrid-ml-advanced.js +722 -0
  62. package/lib/managers/index.d.ts +64 -0
  63. package/lib/managers/index.js +69 -0
  64. package/lib/managers/layer-manager.d.ts +203 -0
  65. package/lib/managers/layer-manager.js +401 -0
  66. package/lib/managers/metadata-manager.d.ts +148 -0
  67. package/lib/managers/metadata-manager.js +280 -0
  68. package/lib/managers/ocr-manager.d.ts +194 -0
  69. package/lib/managers/ocr-manager.js +582 -0
  70. package/lib/managers/optimization-manager.d.ts +102 -0
  71. package/lib/managers/optimization-manager.js +213 -0
  72. package/lib/managers/outline-manager.d.ts +101 -0
  73. package/lib/managers/outline-manager.js +169 -0
  74. package/lib/managers/page-manager.d.ts +142 -0
  75. package/lib/managers/page-manager.js +235 -0
  76. package/lib/managers/pattern-detection.d.ts +169 -0
  77. package/lib/managers/pattern-detection.js +322 -0
  78. package/lib/managers/rendering-manager.d.ts +353 -0
  79. package/lib/managers/rendering-manager.js +679 -0
  80. package/lib/managers/search-manager.d.ts +235 -0
  81. package/lib/managers/search-manager.js +329 -0
  82. package/lib/managers/security-manager.d.ts +161 -0
  83. package/lib/managers/security-manager.js +292 -0
  84. package/lib/managers/signature-manager.d.ts +738 -0
  85. package/lib/managers/signature-manager.js +1509 -0
  86. package/lib/managers/streams.d.ts +262 -0
  87. package/lib/managers/streams.js +477 -0
  88. package/lib/managers/xfa-manager.d.ts +227 -0
  89. package/lib/managers/xfa-manager.js +539 -0
  90. package/lib/native-loader.d.ts +7 -0
  91. package/lib/native-loader.js +62 -0
  92. package/lib/native.d.ts +16 -0
  93. package/lib/native.js +69 -0
  94. package/lib/pdf-creator-manager.d.ts +200 -0
  95. package/lib/pdf-creator-manager.js +381 -0
  96. package/lib/properties.d.ts +79 -0
  97. package/lib/properties.js +454 -0
  98. package/lib/result-accessors-manager.d.ts +346 -0
  99. package/lib/result-accessors-manager.js +706 -0
  100. package/lib/thumbnail-manager.d.ts +121 -0
  101. package/lib/thumbnail-manager.js +205 -0
  102. package/lib/timestamp.d.ts +54 -0
  103. package/lib/timestamp.js +115 -0
  104. package/lib/tsa-client.d.ts +44 -0
  105. package/lib/tsa-client.js +67 -0
  106. package/lib/types/common.d.ts +189 -0
  107. package/lib/types/common.js +17 -0
  108. package/lib/types/document-types.d.ts +352 -0
  109. package/lib/types/document-types.js +82 -0
  110. package/lib/types/index.d.ts +5 -0
  111. package/lib/types/index.js +5 -0
  112. package/lib/types/manager-types.d.ts +179 -0
  113. package/lib/types/manager-types.js +100 -0
  114. package/lib/types/native-bindings.d.ts +439 -0
  115. package/lib/types/native-bindings.js +7 -0
  116. package/lib/workers/index.d.ts +6 -0
  117. package/lib/workers/index.js +5 -0
  118. package/lib/workers/pool.d.ts +64 -0
  119. package/lib/workers/pool.js +192 -0
  120. package/lib/workers/worker.d.ts +5 -0
  121. package/lib/workers/worker.js +99 -0
  122. package/package.json +79 -0
  123. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  124. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  125. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  126. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  127. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
@@ -0,0 +1,382 @@
1
+ /**
2
+ * Unified Error Handling for PDF Oxide
3
+ *
4
+ * Provides comprehensive exception hierarchy consistent across all language bindings.
5
+ * Uses 4-digit error codes organized by category (1000-9999).
6
+ *
7
+ * Error Code System:
8
+ * - 1000-1999: Parse errors
9
+ * - 2000-2999: I/O errors
10
+ * - 3000-3999: Encryption errors
11
+ * - 4000-4999: State errors
12
+ * - 5000-5999: Unsupported feature errors
13
+ * - 6000-6999: Validation errors
14
+ * - 7000-7999: Rendering errors
15
+ * - 8000-8999: Search errors
16
+ * - 9000-9999: Other errors (compliance, OCR, etc.)
17
+ */
18
+ import type { PdfErrorDetails } from './types/common';
19
+ /**
20
+ * Error categories for classification and handling
21
+ */
22
+ export declare enum ErrorCategory {
23
+ VALIDATION = "validation",
24
+ IO = "io",
25
+ ENCRYPTION = "encryption",
26
+ PARSING = "parsing",
27
+ RENDERING = "rendering",
28
+ SEARCH = "search",
29
+ PERMISSION = "permission",
30
+ RESOURCE = "resource",
31
+ STATE = "state",
32
+ UNSUPPORTED = "unsupported",
33
+ COMPLIANCE = "compliance",
34
+ OCR = "ocr",
35
+ SIGNATURE = "signature",
36
+ REDACTION = "redaction",
37
+ UNKNOWN = "unknown"
38
+ }
39
+ /**
40
+ * Error severity levels for prioritization and monitoring
41
+ */
42
+ export declare enum ErrorSeverity {
43
+ LOW = "low",
44
+ MEDIUM = "medium",
45
+ HIGH = "high",
46
+ CRITICAL = "critical"
47
+ }
48
+ /**
49
+ * Recovery information for error handling
50
+ */
51
+ export interface ErrorRecovery {
52
+ canRetry: boolean;
53
+ retryAfterMs?: number;
54
+ suggestions: string[];
55
+ alternativeApproach?: string;
56
+ }
57
+ /**
58
+ * Base class for all PDF Oxide errors.
59
+ *
60
+ * @class PdfException
61
+ * @extends {Error}
62
+ * @property {string} code - 4-digit error code (XXXX format)
63
+ * @property {string} message - Human-readable error message
64
+ * @property {PdfErrorDetails} details - Additional context information
65
+ *
66
+ * @example
67
+ * try {
68
+ * // PDF operation
69
+ * } catch (err) {
70
+ * if (err instanceof PdfException) {
71
+ * console.log(`[${err.code}] ${err.message}`);
72
+ * console.log('Context:', err.details);
73
+ * }
74
+ * }
75
+ */
76
+ export declare class PdfException extends Error {
77
+ readonly code: string;
78
+ readonly message: string;
79
+ readonly details: PdfErrorDetails;
80
+ readonly category: ErrorCategory;
81
+ readonly severity: ErrorSeverity;
82
+ readonly recovery: ErrorRecovery;
83
+ /**
84
+ * Creates a new PdfException.
85
+ *
86
+ * @param code - 4-digit error code
87
+ * @param message - Human-readable error message
88
+ * @param category - Error category for classification
89
+ * @param severity - Error severity level
90
+ * @param details - Additional context information
91
+ * @param recovery - Recovery information
92
+ */
93
+ constructor(code: string, message: string, category?: ErrorCategory, severity?: ErrorSeverity, details?: PdfErrorDetails, recovery?: Partial<ErrorRecovery>);
94
+ /**
95
+ * Adds operational context to this exception for better diagnostics.
96
+ *
97
+ * @param operation - Name of the operation that failed
98
+ * @param context - Additional context key-value pairs
99
+ * @returns This exception for method chaining
100
+ *
101
+ * @example
102
+ * throw new FileNotFound('Not found')
103
+ * .withContext('openFile', { path: '/tmp/doc.pdf' });
104
+ */
105
+ withContext(operation: string, context?: Record<string, any>): this;
106
+ /**
107
+ * Get a comprehensive error message with all details
108
+ * @returns Formatted error message with context and suggestions
109
+ */
110
+ getFullMessage(): string;
111
+ /**
112
+ * Convert error to JSON for logging/monitoring
113
+ * @returns JSON representation of the error
114
+ */
115
+ toJSON(): {
116
+ name: string;
117
+ code: string;
118
+ message: string;
119
+ category: ErrorCategory;
120
+ severity: ErrorSeverity;
121
+ details: PdfErrorDetails;
122
+ recovery: ErrorRecovery;
123
+ stack: string | undefined;
124
+ };
125
+ }
126
+ export declare class ParseException extends PdfException {
127
+ constructor(message: string, details?: PdfErrorDetails);
128
+ }
129
+ export declare class InvalidStructure extends PdfException {
130
+ constructor(message: string, details?: PdfErrorDetails);
131
+ }
132
+ export declare class CorruptedData extends PdfException {
133
+ constructor(message: string, details?: PdfErrorDetails);
134
+ }
135
+ export declare class UnsupportedVersion extends PdfException {
136
+ constructor(message: string, details?: PdfErrorDetails);
137
+ }
138
+ export declare class IoException extends PdfException {
139
+ constructor(message: string, details?: PdfErrorDetails);
140
+ }
141
+ export declare class FileNotFound extends PdfException {
142
+ constructor(message: string, details?: PdfErrorDetails);
143
+ }
144
+ export declare class PermissionDenied extends PdfException {
145
+ constructor(message: string, details?: PdfErrorDetails);
146
+ }
147
+ export declare class DiskFull extends PdfException {
148
+ constructor(message: string, details?: PdfErrorDetails);
149
+ }
150
+ export declare class NetworkError extends PdfException {
151
+ constructor(message: string, details?: PdfErrorDetails);
152
+ }
153
+ export declare class EncryptionException extends PdfException {
154
+ constructor(message: string, details?: PdfErrorDetails);
155
+ }
156
+ export declare class InvalidPassword extends PdfException {
157
+ constructor(message: string, details?: PdfErrorDetails);
158
+ }
159
+ export declare class DecryptionFailed extends PdfException {
160
+ constructor(message: string, details?: PdfErrorDetails);
161
+ }
162
+ export declare class UnsupportedAlgorithm extends PdfException {
163
+ constructor(message: string, details?: PdfErrorDetails);
164
+ }
165
+ export declare class InvalidStateException extends PdfException {
166
+ constructor(message: string, details?: PdfErrorDetails);
167
+ }
168
+ export declare class DocumentClosed extends PdfException {
169
+ constructor(message: string, details?: PdfErrorDetails);
170
+ }
171
+ export declare class OperationNotAllowed extends PdfException {
172
+ constructor(message: string, details?: PdfErrorDetails);
173
+ }
174
+ export declare class InvalidOperation extends PdfException {
175
+ constructor(message: string, details?: PdfErrorDetails);
176
+ }
177
+ export declare class UnsupportedFeatureException extends PdfException {
178
+ constructor(message: string, details?: PdfErrorDetails);
179
+ }
180
+ export declare class FeatureNotImplemented extends PdfException {
181
+ constructor(message: string, details?: PdfErrorDetails);
182
+ }
183
+ export declare class FormatNotSupported extends PdfException {
184
+ constructor(message: string, details?: PdfErrorDetails);
185
+ }
186
+ export declare class EncodingNotSupported extends PdfException {
187
+ constructor(message: string, details?: PdfErrorDetails);
188
+ }
189
+ export declare class ValidationException extends PdfException {
190
+ constructor(message: string, details?: PdfErrorDetails);
191
+ }
192
+ export declare class InvalidParameter extends PdfException {
193
+ constructor(message: string, details?: PdfErrorDetails);
194
+ }
195
+ export declare class InvalidValue extends PdfException {
196
+ constructor(message: string, details?: PdfErrorDetails);
197
+ }
198
+ export declare class MissingRequired extends PdfException {
199
+ constructor(message: string, details?: PdfErrorDetails);
200
+ }
201
+ export declare class TypeMismatch extends PdfException {
202
+ constructor(message: string, details?: PdfErrorDetails);
203
+ }
204
+ export declare class RenderingException extends PdfException {
205
+ constructor(message: string, details?: PdfErrorDetails);
206
+ }
207
+ export declare class RenderFailed extends PdfException {
208
+ constructor(message: string, details?: PdfErrorDetails);
209
+ }
210
+ export declare class UnsupportedRenderFormat extends PdfException {
211
+ constructor(message: string, details?: PdfErrorDetails);
212
+ }
213
+ export declare class InsufficientMemory extends PdfException {
214
+ constructor(message: string, details?: PdfErrorDetails);
215
+ }
216
+ export declare class SearchException extends PdfException {
217
+ constructor(message: string, details?: PdfErrorDetails);
218
+ }
219
+ export declare class SearchFailed extends PdfException {
220
+ constructor(message: string, details?: PdfErrorDetails);
221
+ }
222
+ export declare class InvalidPattern extends PdfException {
223
+ constructor(message: string, details?: PdfErrorDetails);
224
+ }
225
+ export declare class IndexCorrupted extends PdfException {
226
+ constructor(message: string, details?: PdfErrorDetails);
227
+ }
228
+ export declare class SignatureException extends PdfException {
229
+ constructor(message: string, details?: PdfErrorDetails);
230
+ }
231
+ export declare class CertificateLoadFailed extends PdfException {
232
+ constructor(message: string, details?: PdfErrorDetails);
233
+ }
234
+ export declare class SigningFailed extends PdfException {
235
+ constructor(message: string, details?: PdfErrorDetails);
236
+ }
237
+ export declare class RedactionException extends PdfException {
238
+ constructor(message: string, details?: PdfErrorDetails);
239
+ }
240
+ export declare class AccessibilityException extends PdfException {
241
+ constructor(message: string, details?: PdfErrorDetails);
242
+ }
243
+ export declare class OptimizationException extends PdfException {
244
+ constructor(message: string, details?: PdfErrorDetails);
245
+ }
246
+ export declare class ComplianceException extends PdfException {
247
+ constructor(message: string, details?: PdfErrorDetails);
248
+ }
249
+ export declare class InvalidCompliance extends PdfException {
250
+ constructor(message: string, details?: PdfErrorDetails);
251
+ }
252
+ export declare class ValidationFailed extends PdfException {
253
+ constructor(message: string, details?: PdfErrorDetails);
254
+ }
255
+ export declare class OcrException extends PdfException {
256
+ constructor(message: string, details?: PdfErrorDetails);
257
+ }
258
+ export declare class RecognitionFailed extends PdfException {
259
+ constructor(message: string, details?: PdfErrorDetails);
260
+ }
261
+ export declare class LanguageNotSupported extends PdfException {
262
+ constructor(message: string, details?: PdfErrorDetails);
263
+ }
264
+ export declare class ImageProcessingFailed extends PdfException {
265
+ constructor(message: string, details?: PdfErrorDetails);
266
+ }
267
+ export declare class UnknownError extends PdfException {
268
+ constructor(message: string, details?: PdfErrorDetails);
269
+ }
270
+ export declare class InternalError extends PdfException {
271
+ constructor(message: string, details?: PdfErrorDetails);
272
+ }
273
+ /**
274
+ * Maps Rust error type names to JavaScript exception types.
275
+ */
276
+ export declare const ERROR_MAP: Record<string, new (message: string, details?: PdfErrorDetails) => PdfException>;
277
+ /**
278
+ * Maps a Rust error type to a JavaScript exception.
279
+ *
280
+ * @param rustErrorType - Rust error type name
281
+ * @param message - Error message
282
+ * @param details - Additional context
283
+ * @returns Appropriate error instance
284
+ *
285
+ * @example
286
+ * try {
287
+ * // Native call
288
+ * } catch (err) {
289
+ * const jsErr = mapError('FileNotFound', 'File does not exist', { path: '/tmp/doc.pdf' });
290
+ * throw jsErr;
291
+ * }
292
+ */
293
+ export declare function mapError(rustErrorType: string, message: string, details?: PdfErrorDetails): PdfException;
294
+ /**
295
+ * Maps a numeric FFI error code from the Rust layer to a JavaScript exception.
296
+ *
297
+ * FFI Error Codes:
298
+ * - 0: Success (no error)
299
+ * - 1: I/O error
300
+ * - 2: Parse error
301
+ * - 3: Encryption error
302
+ * - 4: Invalid state error
303
+ * - 5: Rendering unsupported
304
+ * - 6: OCR unsupported
305
+ * - 7: Invalid argument
306
+ * - 8: Signature error
307
+ * - 100: Internal/generic error
308
+ *
309
+ * @param errorCode - Numeric FFI error code from native layer
310
+ * @param message - Optional error message override
311
+ * @returns Appropriate error instance
312
+ *
313
+ * @example
314
+ * const errorCode = nativeCall();
315
+ * if (errorCode !== 0) {
316
+ * throw mapFfiErrorCode(errorCode, 'Operation failed');
317
+ * }
318
+ */
319
+ export declare function mapFfiErrorCode(errorCode: number, message?: string): PdfException;
320
+ /**
321
+ * Creates an error with optional context.
322
+ *
323
+ * @param code - 4-digit error code
324
+ * @param message - Error message
325
+ * @param options - Configuration options
326
+ * @returns Created exception
327
+ *
328
+ * @example
329
+ * const err = createError('7100', 'Rendering failed', {
330
+ * operation: 'renderPage',
331
+ * context: { page: 0, format: 'png' }
332
+ * });
333
+ */
334
+ export declare function createError(code: string, message: string, options?: {
335
+ operation?: string;
336
+ context?: Record<string, any>;
337
+ }): PdfException;
338
+ /**
339
+ * Maps native error to appropriate PDF exception.
340
+ *
341
+ * @param error - The error to wrap
342
+ * @returns Wrapped exception
343
+ *
344
+ * @example
345
+ * try {
346
+ * // Native call
347
+ * } catch (err) {
348
+ * const wrapped = wrapError(err);
349
+ * console.log(wrapped.code); // e.g., "2100"
350
+ * }
351
+ */
352
+ export declare function wrapError(error: unknown): PdfException;
353
+ /**
354
+ * Function signature for methods to be wrapped
355
+ */
356
+ type MethodFunction = (...args: any[]) => any;
357
+ type AsyncMethodFunction = (...args: any[]) => Promise<any>;
358
+ /**
359
+ * Creates a method wrapper that catches native errors and converts them.
360
+ *
361
+ * @param fn - The method to wrap
362
+ * @param thisArg - The context (this) to bind
363
+ * @returns Wrapped function with error conversion
364
+ *
365
+ * @example
366
+ * const wrapped = wrapMethod(nativeMethod, this);
367
+ * const result = wrapped(arg1, arg2); // Throws PdfException on error
368
+ */
369
+ export declare function wrapMethod<T extends MethodFunction>(fn: T, thisArg?: any): T;
370
+ /**
371
+ * Creates an async method wrapper that catches native errors.
372
+ *
373
+ * @param fn - The async method to wrap
374
+ * @param thisArg - The context (this) to bind
375
+ * @returns Wrapped async function with error conversion
376
+ *
377
+ * @example
378
+ * const wrapped = wrapAsyncMethod(nativeAsyncMethod, this);
379
+ * const result = await wrapped(arg1, arg2); // Throws PdfException on error
380
+ */
381
+ export declare function wrapAsyncMethod<T extends AsyncMethodFunction>(fn: T, thisArg?: any): T;
382
+ export {};