@a-cube-io/ereceipts-js-sdk 2.0.7 → 2.0.8

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/react.d.ts DELETED
@@ -1,1615 +0,0 @@
1
- import * as React from 'react';
2
- import { AxiosRequestConfig, AxiosInstance } from 'axios';
3
-
4
- /**
5
- * Role and Permission Management System
6
- *
7
- * This module provides type-safe role management with hierarchical permissions
8
- * and context-based authorization for the ACube E-Receipt system.
9
- */
10
- type BaseRole = 'ROLE_SUPPLIER' | 'ROLE_CASHIER' | 'ROLE_MERCHANT';
11
- type RoleContext = 'ereceipts-it.acubeapi.com';
12
- type UserRoles = Partial<Record<RoleContext, BaseRole[]>>;
13
-
14
- /**
15
- * Core SDK types
16
- */
17
-
18
- type Environment = 'production' | 'development' | 'sandbox';
19
- /**
20
- * Certificate management configuration
21
- */
22
- interface CertificateConfig {
23
- storagePrefix?: string;
24
- metadataKey?: string;
25
- }
26
- /**
27
- * SDK Configuration
28
- */
29
- interface SDKConfig {
30
- environment: Environment;
31
- apiUrl?: string;
32
- authUrl?: string;
33
- timeout?: number;
34
- retryAttempts?: number;
35
- debug?: boolean;
36
- customHeaders?: Record<string, string>;
37
- certificateConfig?: CertificateConfig;
38
- }
39
- /**
40
- * Authentication credentials
41
- */
42
- interface AuthCredentials {
43
- email: string;
44
- password: string;
45
- }
46
- /**
47
- * User information
48
- */
49
- interface User {
50
- id: string;
51
- email: string;
52
- username: string;
53
- roles: UserRoles;
54
- fid: string;
55
- pid: string | null;
56
- expiresAt: number;
57
- }
58
- /**
59
- * User provider interface for accessing current user information
60
- */
61
- interface IUserProvider {
62
- getCurrentUser(): Promise<User | null>;
63
- isAuthenticated(): Promise<boolean>;
64
- getAccessToken(): Promise<string | null>;
65
- }
66
- /**
67
- * API Violation structure for validation errors
68
- */
69
- interface APIViolation {
70
- propertyPath: string;
71
- message: string;
72
- }
73
- /**
74
- * SDK Error types
75
- */
76
- type SDKError = 'NETWORK_ERROR' | 'AUTH_ERROR' | 'VALIDATION_ERROR' | 'NOT_FOUND_ERROR' | 'FORBIDDEN_ERROR' | 'UNKNOWN_ERROR' | 'STORAGE_CERTIFICATE_ERROR' | 'CERTIFICATE_MANAGER_NOT_INITIALIZED' | 'SDK_INITIALIZATION_ERROR' | 'API_CLIENT_NOT_INITIALIZED' | 'MTLS_ADAPTER_NOT_AVAILABLE' | 'CERTIFICATE_INFO_ERROR';
77
- /**
78
- * SDK Exception class
79
- */
80
- declare class ACubeSDKError extends Error {
81
- type: SDKError;
82
- originalError?: unknown | undefined;
83
- statusCode?: number | undefined;
84
- violations?: APIViolation[];
85
- constructor(type: SDKError, message: string, originalError?: unknown | undefined, statusCode?: number | undefined, violations?: APIViolation[]);
86
- }
87
-
88
- /**
89
- * SDK Configuration manager
90
- */
91
- declare class ConfigManager {
92
- private config;
93
- constructor(userConfig: SDKConfig);
94
- private mergeConfig;
95
- private getDefaultApiUrl;
96
- private getDefaultAuthUrl;
97
- /**
98
- * Get the current configuration
99
- */
100
- getConfig(): Required<SDKConfig>;
101
- /**
102
- * Get API URL
103
- */
104
- getApiUrl(): string;
105
- /**
106
- * Get Auth URL
107
- */
108
- getAuthUrl(): string;
109
- /**
110
- * Get environment
111
- */
112
- getEnvironment(): Environment;
113
- /**
114
- * Check if debug mode is enabled
115
- */
116
- isDebugEnabled(): boolean;
117
- /**
118
- * Get timeout in milliseconds
119
- */
120
- getTimeout(): number;
121
- /**
122
- * Get retry attempts
123
- */
124
- getRetryAttempts(): number;
125
- /**
126
- * Get custom headers
127
- */
128
- getCustomHeaders(): Record<string, string>;
129
- /**
130
- * Update configuration
131
- */
132
- updateConfig(updates: Partial<SDKConfig>): void;
133
- }
134
-
135
- interface ICachePort {
136
- get<T>(key: string): Promise<CachedItem<T> | null>;
137
- set<T>(key: string, data: T): Promise<void>;
138
- setItem<T>(key: string, item: CachedItem<T>): Promise<void>;
139
- setBatch<T>(items: Array<[string, CachedItem<T>]>): Promise<void>;
140
- invalidate(pattern: string): Promise<void>;
141
- clear(): Promise<void>;
142
- getSize(): Promise<CacheSize>;
143
- cleanup(): Promise<number>;
144
- getKeys(pattern?: string): Promise<string[]>;
145
- }
146
- interface CachedItem<T> {
147
- data: T;
148
- timestamp: number;
149
- compressed?: boolean;
150
- }
151
- interface CacheSize {
152
- entries: number;
153
- bytes: number;
154
- lastCleanup: number;
155
- }
156
-
157
- interface CertificateData {
158
- certificate: string;
159
- privateKey: string;
160
- format: 'PEM' | 'P12';
161
- password?: string;
162
- }
163
- interface MTLSConnectionConfig {
164
- baseUrl: string;
165
- port?: number;
166
- timeout?: number;
167
- validateCertificate?: boolean;
168
- }
169
- interface MTLSRequestConfig {
170
- url: string;
171
- method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
172
- headers?: Record<string, string>;
173
- data?: unknown;
174
- timeout?: number;
175
- responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
176
- }
177
- interface MTLSResponse<T = unknown> {
178
- data: T;
179
- status: number;
180
- statusText: string;
181
- headers: Record<string, string>;
182
- }
183
- interface CertificateInfo {
184
- subject: string;
185
- issuer: string;
186
- validFrom: Date;
187
- validTo: Date;
188
- serialNumber: string;
189
- fingerprint: string;
190
- pemId: string;
191
- cashRegisterUUID: string;
192
- }
193
- interface IMTLSPort {
194
- isMTLSSupported(): Promise<boolean>;
195
- initialize(config: MTLSConnectionConfig): Promise<void>;
196
- configureCertificate(certificateData: CertificateData): Promise<void>;
197
- hasCertificate(): Promise<boolean>;
198
- getCertificateInfo(): Promise<CertificateInfo | null>;
199
- request<T>(config: MTLSRequestConfig): Promise<MTLSResponse<T>>;
200
- testConnection(): Promise<boolean>;
201
- removeCertificate(): Promise<void>;
202
- getBaseUrl(): string | null;
203
- getPlatformInfo(): {
204
- platform: 'react-native' | 'node' | 'web' | 'expo';
205
- mtlsSupported: boolean;
206
- certificateStorage: 'keychain' | 'keystore' | 'filesystem' | 'browser-managed' | 'memory';
207
- fallbackToJWT: boolean;
208
- };
209
- }
210
-
211
- interface INetworkPort {
212
- isOnline(): boolean;
213
- onStatusChange(callback: (online: boolean) => void): () => void;
214
- getNetworkInfo(): Promise<NetworkInfo | null>;
215
- }
216
- interface NetworkInfo {
217
- type: 'wifi' | 'cellular' | 'ethernet' | 'unknown';
218
- effectiveType?: '2g' | '3g' | '4g' | '5g';
219
- downlink?: number;
220
- rtt?: number;
221
- }
222
-
223
- interface IStoragePort {
224
- get(key: string): Promise<string | null>;
225
- set(key: string, value: string): Promise<void>;
226
- remove(key: string): Promise<void>;
227
- clear(): Promise<void>;
228
- getAllKeys(): Promise<string[]>;
229
- multiGet(keys: string[]): Promise<Record<string, string | null>>;
230
- multiSet(items: Record<string, string>): Promise<void>;
231
- multiRemove(keys: string[]): Promise<void>;
232
- }
233
- interface ISecureStoragePort extends IStoragePort {
234
- isAvailable(): Promise<boolean>;
235
- getSecurityLevel(): Promise<string>;
236
- }
237
-
238
- /**
239
- * Platform adapters collection
240
- */
241
- interface PlatformAdapters {
242
- storage: IStoragePort;
243
- secureStorage: ISecureStoragePort;
244
- networkMonitor: INetworkPort;
245
- cache?: ICachePort;
246
- mtls?: IMTLSPort;
247
- }
248
-
249
- /**
250
- * Generated API types from OpenAPI spec
251
- */
252
- interface Page<T> {
253
- members: T[];
254
- total?: number;
255
- page?: number;
256
- size?: number;
257
- pages?: number;
258
- }
259
- interface LdJsonPage<T> {
260
- member: T[];
261
- totalItems?: number;
262
- view?: {
263
- '@id': string;
264
- type?: string;
265
- first?: string;
266
- last?: string;
267
- previous?: string;
268
- next?: string;
269
- };
270
- }
271
- interface CashierCreateInput {
272
- email: string;
273
- password: string;
274
- name: string;
275
- display_name: string;
276
- }
277
- interface CashierOutput {
278
- uuid: string;
279
- merchant_uuid: string;
280
- display_name: string;
281
- email: string;
282
- name: string;
283
- }
284
- interface CashierListParams {
285
- page?: number;
286
- size?: number;
287
- }
288
- type PEMStatus = 'NEW' | 'REGISTERED' | 'ACTIVATED' | 'ONLINE' | 'OFFLINE' | 'DISCARDED';
289
- interface Address {
290
- street_address: string;
291
- street_number: string;
292
- zip_code: string;
293
- city: string;
294
- province: string;
295
- }
296
- type PointOfSaleMf2Type = 'AP' | 'SP' | 'TM' | 'PV';
297
- interface PointOfSaleOutputMf2 {
298
- id: string;
299
- status: PEMStatus;
300
- type: PointOfSaleMf2Type;
301
- }
302
- interface PointOfSaleOutput {
303
- serial_number: string;
304
- status: PEMStatus;
305
- address: Address;
306
- operational_status: string;
307
- }
308
- interface PointOfSaleListParams {
309
- status?: PEMStatus;
310
- page?: number;
311
- size?: number;
312
- }
313
- interface PointOfSaleDetailedOutput {
314
- serial_number: string;
315
- status: PEMStatus;
316
- address: Address;
317
- registration_key?: string;
318
- operational_status: string;
319
- }
320
- interface ActivationRequest {
321
- registration_key: string;
322
- }
323
- interface PEMStatusOfflineRequest {
324
- timestamp: string;
325
- reason: string;
326
- }
327
- interface PointOfSaleUpdateInput {
328
- address?: Address;
329
- }
330
- type ReceiptType = 'sale' | 'return' | 'void';
331
- type GoodOrService = 'goods' | 'service';
332
- type VatRateCode = '4.00' | '5.00' | '10.00' | '22.00' | '2.00' | '6.40' | '7.00' | '7.30' | '7.50' | '7.65' | '7.95' | '8.30' | '8.50' | '8.80' | '9.50' | '12.30' | 'N1' | 'N2' | 'N3' | 'N4' | 'N5' | 'N6';
333
- interface ReceiptItem {
334
- type?: GoodOrService;
335
- quantity: string;
336
- description: string;
337
- unit_price: string;
338
- vat_rate_code?: VatRateCode;
339
- simplified_vat_allocation?: boolean;
340
- discount?: string;
341
- is_down_payment_or_voucher_redemption?: boolean;
342
- complimentary?: boolean;
343
- }
344
- interface ReceiptReturnItem {
345
- id: number;
346
- quantity: string;
347
- }
348
- interface ReceiptInput {
349
- items: ReceiptItem[];
350
- customer_tax_code?: string;
351
- customer_lottery_code?: string;
352
- discount?: string;
353
- invoice_issuing?: boolean;
354
- uncollected_dcr_to_ssn?: boolean;
355
- services_uncollected_amount?: string;
356
- goods_uncollected_amount?: string;
357
- cash_payment_amount?: string;
358
- electronic_payment_amount?: string;
359
- ticket_restaurant_payment_amount?: string;
360
- ticket_restaurant_quantity?: number;
361
- }
362
- interface ReceiptOutput {
363
- uuid: string;
364
- type: ReceiptType;
365
- created_at: string;
366
- total_amount: string;
367
- document_number: string;
368
- document_datetime?: string;
369
- is_returnable: boolean;
370
- is_voidable: boolean;
371
- pdf_url?: string;
372
- parent_receipt_uuid?: string;
373
- }
374
- interface ReceiptDetailsOutput {
375
- uuid: string;
376
- type: ReceiptType;
377
- customer_lottery_code?: string;
378
- created_at: string;
379
- total_amount: string;
380
- document_number?: string;
381
- document_datetime?: string;
382
- vat_number: string;
383
- total_taxable_amount: string;
384
- total_uncollected_amount: string;
385
- deductible_amount: string;
386
- total_vat_amount: string;
387
- total_discount: string;
388
- total_gross_discount: string;
389
- discount: string;
390
- is_returnable: boolean;
391
- is_voidable: boolean;
392
- pdf_url?: string;
393
- parent_receipt_uuid?: string;
394
- items?: ReceiptItem[];
395
- }
396
- interface VoidReceiptInput {
397
- document_number: string;
398
- }
399
- interface ReceiptReturnInput {
400
- items: ReceiptReturnItem[];
401
- document_number: string;
402
- }
403
- interface ReturnableReceiptItem {
404
- id: number;
405
- type?: GoodOrService;
406
- quantity: string;
407
- returned_quantity: string;
408
- description: string;
409
- unit_price: string;
410
- vat_rate_code?: VatRateCode;
411
- }
412
- interface ReceiptReturnOrVoidViaPEMInput {
413
- pos_id?: string;
414
- items: ReceiptItem[];
415
- document_number: string;
416
- document_datetime?: string;
417
- lottery_code?: string;
418
- }
419
- type ReceiptProofType = 'POS' | 'VR' | 'ND';
420
- declare const RECEIPT_READY = "ready";
421
- declare const RECEIPT_SENT = "sent";
422
- type ReceiptStatus = typeof RECEIPT_READY | typeof RECEIPT_SENT;
423
- declare const RECEIPT_SORT_DESCENDING = "descending";
424
- declare const RECEIPT_SORT_ASCENDING = "ascending";
425
- type ReceiptSortOrder = typeof RECEIPT_SORT_DESCENDING | typeof RECEIPT_SORT_ASCENDING;
426
- interface ReceiptListParams {
427
- serial_number: string;
428
- page?: number;
429
- size?: number;
430
- status?: ReceiptStatus;
431
- sort?: ReceiptSortOrder;
432
- document_number?: string;
433
- 'document_datetime[before]'?: string;
434
- 'document_datetime[after]'?: string | null;
435
- }
436
- interface ReceiptReturnOrVoidWithProofInput {
437
- items: ReceiptItem[];
438
- proof: ReceiptProofType;
439
- document_datetime: string;
440
- }
441
- interface CashRegisterCreate {
442
- pem_serial_number: string;
443
- name: string;
444
- }
445
- interface CashRegisterBasicOutput {
446
- uuid: string;
447
- pem_serial_number: string;
448
- name: string;
449
- }
450
- interface CashRegisterDetailedOutput {
451
- uuid: string;
452
- pem_serial_number: string;
453
- name: string;
454
- mtls_certificate: string;
455
- private_key: string;
456
- }
457
- interface CashRegisterListParams {
458
- page?: number;
459
- size?: number;
460
- serial_number?: string;
461
- }
462
- interface MerchantOutput {
463
- uuid: string;
464
- vat_number: string;
465
- fiscal_code?: string | null;
466
- email: string;
467
- business_name?: string | null;
468
- first_name?: string | null;
469
- last_name?: string | null;
470
- address?: Address;
471
- }
472
- interface MerchantsParams {
473
- page?: number;
474
- }
475
- interface MerchantCreateInput {
476
- vat_number: string;
477
- fiscal_code?: string;
478
- business_name?: string | null;
479
- first_name?: string | null;
480
- last_name?: string | null;
481
- email: string;
482
- password: string;
483
- address?: Address;
484
- }
485
- interface MerchantUpdateInput {
486
- business_name?: string | null;
487
- first_name?: string | null;
488
- last_name?: string | null;
489
- address?: Address | null;
490
- }
491
- interface PemCreateInput {
492
- merchant_uuid: string;
493
- address?: Address;
494
- }
495
- interface PemCreateOutput {
496
- serial_number: string;
497
- registration_key: string;
498
- }
499
- interface PemCertificatesOutput {
500
- mtls_certificate: string;
501
- activation_xml_response?: string;
502
- }
503
- interface SupplierOutput {
504
- uuid: string;
505
- fiscal_id: string;
506
- name: string;
507
- address?: Address;
508
- }
509
- interface SuppliersParams {
510
- page?: number;
511
- }
512
- interface SupplierCreateInput {
513
- fiscal_id: string;
514
- name: string;
515
- address?: Address;
516
- }
517
- interface SupplierUpdateInput {
518
- name: string;
519
- address?: Address;
520
- }
521
- interface DailyReportOutput {
522
- uuid: string;
523
- pem_serial_number: string;
524
- date: string;
525
- total_receipts: number;
526
- total_amount: string;
527
- status: 'pending' | 'sent' | 'error';
528
- }
529
- interface DailyReportsParams {
530
- pem_serial_number?: string;
531
- date_from?: string;
532
- date_to?: string;
533
- status?: 'pending' | 'sent' | 'error';
534
- page?: number;
535
- }
536
- interface JournalOutput {
537
- uuid: string;
538
- pem_serial_number: string;
539
- date: string;
540
- sequence_number: number;
541
- total_receipts: number;
542
- total_amount: string;
543
- status: 'open' | 'closed';
544
- }
545
- interface JournalsParams {
546
- pem_serial_number?: string;
547
- status?: 'open' | 'closed';
548
- date_from?: string;
549
- date_to?: string;
550
- page?: number;
551
- }
552
-
553
- /**
554
- * Single certificate data structure - Essential fields only
555
- */
556
- interface StoredCertificate {
557
- certificate: string;
558
- privateKey: string;
559
- format: 'pem' | 'p12' | 'pkcs12';
560
- }
561
- /**
562
- * Certificate storage options - Only format is configurable
563
- */
564
- interface CertificateOptions {
565
- format?: 'pem' | 'p12' | 'pkcs12';
566
- }
567
- /**
568
- * Certificate manager configuration
569
- */
570
- interface CertificateManagerConfig {
571
- storageKey?: string;
572
- }
573
- /**
574
- * Simplified Certificate Manager - Supports only ONE certificate per device
575
- *
576
- * Key behaviors:
577
- * - Installing a new certificate automatically removes the existing one
578
- * - No certificate IDs needed - there's only one
579
- * - Much simpler API and storage
580
- */
581
- declare class CertificateManager {
582
- private storage;
583
- private storageKey;
584
- private isDebugEnabled;
585
- constructor(storage: ISecureStoragePort, config?: CertificateManagerConfig, debugEnabled?: boolean);
586
- /**
587
- * Store a certificate (replaces any existing certificate)
588
- */
589
- storeCertificate(certificate: string, privateKey: string, options?: CertificateOptions): Promise<void>;
590
- /**
591
- * Get the stored certificate (returns null if none exists)
592
- */
593
- getCertificate(): Promise<StoredCertificate | null>;
594
- /**
595
- * Check if a certificate is stored
596
- */
597
- hasCertificate(): Promise<boolean>;
598
- /**
599
- * Remove the stored certificate
600
- */
601
- clearCertificate(): Promise<void>;
602
- /**
603
- * Get certificate information without exposing a private key
604
- */
605
- getCertificateInfo(): Promise<{
606
- format: string;
607
- } | null>;
608
- }
609
-
610
- /**
611
- * Simplified authentication modes
612
- */
613
- type AuthMode = 'jwt' | 'mtls' | 'auto';
614
-
615
- /**
616
- * Simplified cache request configuration
617
- * Cache behavior: Online = always fetch fresh data, Offline = always use cache
618
- */
619
- interface CacheConfig {
620
- /** Whether to use cache for this request (default: true if cache available) */
621
- useCache?: boolean;
622
- }
623
-
624
- /**
625
- * Extended request configuration with simplified cache and mTLS options
626
- */
627
- interface HttpRequestConfig extends AxiosRequestConfig, CacheConfig {
628
- /** Authentication mode for this request */
629
- authMode?: AuthMode;
630
- /** Skip mTLS fallback to JWT */
631
- noFallback?: boolean;
632
- }
633
-
634
- /**
635
- * Simplified HTTP client with mTLS and caching support
636
- */
637
- declare class HttpClient {
638
- private config;
639
- private client;
640
- private mtlsHandler;
641
- private cacheHandler;
642
- private certificateManager;
643
- private mtlsAdapter;
644
- private userProvider;
645
- private _isDebugEnabled;
646
- constructor(config: ConfigManager, certificateManager?: CertificateManager, cache?: ICachePort, networkMonitor?: INetworkPort, mtlsAdapter?: IMTLSPort, userProvider?: IUserProvider);
647
- private createClient;
648
- /**
649
- * Set authorization header
650
- */
651
- setAuthorizationHeader(token: string): void;
652
- /**
653
- * Remove authorization header
654
- */
655
- removeAuthorizationHeader(): void;
656
- /**
657
- * Extract mTLS-compatible config from HttpRequestConfig
658
- */
659
- private extractMTLSConfig;
660
- /**
661
- * Execute request with consistent error handling
662
- * Eliminates duplicate try-catch blocks across all HTTP methods
663
- */
664
- private executeRequest;
665
- /**
666
- * Get current network status
667
- */
668
- getNetworkStatus(): {
669
- isOnline: boolean;
670
- hasMonitor: boolean;
671
- };
672
- /**
673
- * Check if currently online
674
- */
675
- isOnline(): boolean;
676
- /**
677
- * GET request with authentication and caching support
678
- */
679
- get<T>(url: string, config?: HttpRequestConfig): Promise<T>;
680
- /**
681
- * POST request with authentication support
682
- */
683
- post<T>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<T>;
684
- /**
685
- * PUT request with authentication support
686
- */
687
- put<T>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<T>;
688
- /**
689
- * DELETE request with authentication support
690
- */
691
- delete<T>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<T>;
692
- /**
693
- * PATCH request with authentication support
694
- */
695
- patch<T>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<T>;
696
- /**
697
- * Get mTLS status and certificate information
698
- */
699
- getMTLSStatus(): Promise<{
700
- adapterAvailable: boolean;
701
- certificateManagerAvailable: boolean;
702
- isReady: boolean;
703
- hasCertificate: boolean;
704
- certificateInfo: {
705
- format: string;
706
- } | null;
707
- platformInfo: {
708
- platform: "react-native" | "node" | "web" | "expo";
709
- mtlsSupported: boolean;
710
- certificateStorage: "keychain" | "keystore" | "filesystem" | "browser-managed" | "memory";
711
- fallbackToJWT: boolean;
712
- } | null;
713
- diagnosticTest: boolean;
714
- diagnosticTestNote: string;
715
- pendingRequestsCount: number;
716
- }>;
717
- /**
718
- * Store certificate with coordination between certificate manager and mTLS adapter
719
- * This ensures old certificates are properly cleared from both SDK storage and native keychain
720
- */
721
- storeCertificate(certificate: string, privateKey: string, options?: {
722
- format?: 'pem' | 'p12' | 'pkcs12';
723
- }): Promise<void>;
724
- /**
725
- * Clear certificate from both certificate manager and native keychain
726
- */
727
- clearCertificate(): Promise<void>;
728
- /**
729
- * Test mTLS connection
730
- */
731
- testMTLSConnection(): Promise<boolean>;
732
- /**
733
- * Check if mTLS is ready for requests
734
- */
735
- isMTLSReady(): Promise<boolean>;
736
- /**
737
- * Get the mTLS adapter instance (for backward compatibility)
738
- */
739
- getMTLSAdapter(): IMTLSPort | null;
740
- /**
741
- * Get a certificate manager instance
742
- */
743
- getCertificateManager(): CertificateManager | null;
744
- /**
745
- * Get the underlying axios instance for advanced use cases
746
- */
747
- getAxiosInstance(): AxiosInstance;
748
- /**
749
- * Invalidate cache entries
750
- */
751
- invalidateCache(pattern: string): Promise<void>;
752
- get isDebugEnabled(): boolean;
753
- }
754
-
755
- /**
756
- * Cash Registers API manager
757
- */
758
- declare class CashRegistersAPI {
759
- private httpClient;
760
- private debugEnabled;
761
- constructor(httpClient: HttpClient);
762
- /**
763
- * Create a new cash register
764
- */
765
- create(cashRegisterData: CashRegisterCreate): Promise<CashRegisterDetailedOutput>;
766
- /**
767
- * Get all cash registers for the current merchant
768
- */
769
- list(params: CashRegisterListParams): Promise<Page<CashRegisterBasicOutput>>;
770
- /**
771
- * Get a cash register by ID
772
- */
773
- get(id: string): Promise<CashRegisterBasicOutput>;
774
- /**
775
- * Get detailed cash register information
776
- */
777
- getDetailed(id: string): Promise<CashRegisterDetailedOutput>;
778
- /**
779
- * Get certificate status for a cash register
780
- */
781
- getCertificateStatus(cashRegisterId: string): Promise<{
782
- hasCertificate: boolean;
783
- isConfigured: boolean;
784
- canConnect: boolean;
785
- certificateInfo?: {
786
- configuredAt: Date;
787
- source: string;
788
- };
789
- }>;
790
- }
791
-
792
- /**
793
- * Cashiers API manager
794
- */
795
- declare class CashiersAPI {
796
- private httpClient;
797
- constructor(httpClient: HttpClient);
798
- /**
799
- * Read cashiers with pagination
800
- */
801
- list(params?: CashierListParams): Promise<Page<CashierOutput>>;
802
- /**
803
- * Create a new cashier
804
- */
805
- create(cashierData: CashierCreateInput): Promise<CashierOutput>;
806
- /**
807
- * Read currently authenticated cashier's information
808
- */
809
- me(): Promise<CashierOutput>;
810
- /**
811
- * Get a specific cashier by ID
812
- */
813
- get(cashierId: string): Promise<CashierOutput>;
814
- /**
815
- * Delete a cashier
816
- */
817
- delete(cashierId: string): Promise<void>;
818
- }
819
-
820
- /**
821
- * Daily Reports API manager (MF2)
822
- */
823
- declare class DailyReportsAPI {
824
- private httpClient;
825
- constructor(httpClient: HttpClient);
826
- /**
827
- * Retrieve the collection of Daily Report resources
828
- */
829
- list(params?: DailyReportsParams): Promise<DailyReportOutput[]>;
830
- /**
831
- * Retrieve a Daily Report resource by UUID
832
- */
833
- get(uuid: string): Promise<DailyReportOutput>;
834
- /**
835
- * Regenerate/resend a daily report
836
- */
837
- regenerate(uuid: string): Promise<DailyReportOutput>;
838
- }
839
-
840
- /**
841
- * Journals API manager (MF2)
842
- */
843
- declare class JournalsAPI {
844
- private httpClient;
845
- constructor(httpClient: HttpClient);
846
- /**
847
- * Retrieve the collection of Journal resources
848
- */
849
- list(params?: JournalsParams): Promise<JournalOutput[]>;
850
- /**
851
- * Retrieve a Journal resource by UUID
852
- */
853
- get(uuid: string): Promise<JournalOutput>;
854
- }
855
-
856
- /**
857
- * Merchants API manager (MF2)
858
- */
859
- declare class MerchantsAPI {
860
- private httpClient;
861
- constructor(httpClient: HttpClient);
862
- /**
863
- * Retrieve the collection of Merchant resources
864
- */
865
- list(params: MerchantsParams): Promise<MerchantOutput[]>;
866
- /**
867
- * Create a Merchant resource
868
- */
869
- create(merchantData: MerchantCreateInput): Promise<MerchantOutput>;
870
- /**
871
- * Retrieve a Merchant resource by UUID
872
- */
873
- get(uuid: string): Promise<MerchantOutput>;
874
- /**
875
- * Replace the Merchant resource
876
- */
877
- update(uuid: string, merchantData: MerchantUpdateInput): Promise<MerchantOutput>;
878
- /**
879
- * Retrieve Point of Sale resources for a specific merchant by Supplier logged
880
- */
881
- listPointOfSalesBySuppliers(merchantUuid: string, params?: {
882
- page?: number;
883
- }): Promise<LdJsonPage<PointOfSaleOutputMf2>>;
884
- /**
885
- * Retrieve Point of Sale resources for a specific merchant by Merchant logged
886
- */
887
- listPointOfSalesByMerchants(params?: {
888
- page?: number;
889
- }): Promise<LdJsonPage<PointOfSaleOutputMf2>>;
890
- }
891
-
892
- /**
893
- * PEMs API manager (MF2)
894
- */
895
- declare class PemsAPI {
896
- private httpClient;
897
- constructor(httpClient: HttpClient);
898
- /**
899
- * Create a new PEM
900
- */
901
- create(pemData: PemCreateInput): Promise<PemCreateOutput>;
902
- /**
903
- * Get a specific PEM by serial number
904
- */
905
- get(serialNumber: string): Promise<PointOfSaleDetailedOutput>;
906
- /**
907
- * Get mTLS and signing certificates for a PEM
908
- */
909
- getCertificates(serialNumber: string): Promise<PemCertificatesOutput>;
910
- }
911
-
912
- /**
913
- * Point of Sales API manager
914
- */
915
- declare class PointOfSalesAPI {
916
- private httpClient;
917
- constructor(httpClient: HttpClient);
918
- /**
919
- * Retrieve Point of Sales (PEMs)
920
- */
921
- list(params?: PointOfSaleListParams): Promise<Page<PointOfSaleOutput>>;
922
- /**
923
- * Get a specific Point of Sale by serial number
924
- */
925
- get(serialNumber: string): Promise<PointOfSaleDetailedOutput>;
926
- /**
927
- * Update a Point of Sale
928
- */
929
- update(serialNumber: string, updateData: PointOfSaleUpdateInput): Promise<PointOfSaleDetailedOutput>;
930
- /**
931
- * Close a journal
932
- */
933
- close(serial_number: string): Promise<void>;
934
- /**
935
- * Trigger the activation process of a Point of Sale
936
- */
937
- activate(serialNumber: string, activationData: ActivationRequest): Promise<void>;
938
- /**
939
- * Create a new inactivity period
940
- */
941
- createInactivityPeriod(serialNumber: string): Promise<void>;
942
- /**
943
- * Change the state of the Point of Sale to 'offline'
944
- */
945
- setOffline(serialNumber: string, offlineData: PEMStatusOfflineRequest): Promise<void>;
946
- /**
947
- * Retrieve a POS resource by UUID
948
- */
949
- getMf2Pos(serialNumber: string): Promise<PointOfSaleOutputMf2>;
950
- }
951
-
952
- /**
953
- * User role information for authentication routing
954
- */
955
- interface UserContext {
956
- roles: string[];
957
- userId?: string;
958
- merchantId?: string;
959
- }
960
- /**
961
- * Receipts API manager with mTLS and role-based authentication
962
- */
963
- declare class ReceiptsAPI {
964
- private httpClient;
965
- private debugEnabled;
966
- private userContext;
967
- constructor(httpClient: HttpClient);
968
- /**
969
- * Set user context for role-based authentication
970
- */
971
- setUserContext(context: UserContext): void;
972
- /**
973
- * Create request configuration
974
- * Let MTLSHandler determine the best authentication mode based on role/platform/method
975
- */
976
- private createRequestConfig;
977
- /**
978
- * Create a new electronic receipt
979
- * Authentication mode determined by MTLSHandler based on role/platform
980
- */
981
- create(receiptData: ReceiptInput): Promise<ReceiptOutput>;
982
- /**
983
- * Get a list of electronic receipts
984
- * Authentication mode determined by MTLSHandler (typically JWT for GET operations)
985
- */
986
- list(params: ReceiptListParams): Promise<Page<ReceiptOutput>>;
987
- /**
988
- * Get an electronic receipt by UUID
989
- * Authentication mode determined by MTLSHandler based on role/platform
990
- */
991
- get(receiptUuid: string): Promise<ReceiptOutput>;
992
- /**
993
- * Get receipt details (JSON or PDF)
994
- * Authentication mode determined by MTLSHandler
995
- * ✅ PDF downloads now use mTLS with binary response support (expo-mutual-tls v1.0.3+)
996
- */
997
- getDetails(receiptUuid: string, format?: 'json' | 'pdf'): Promise<ReceiptDetailsOutput | string>;
998
- /**
999
- * Void an electronic receipt via same pos
1000
- */
1001
- voidViaSamePos(voidData: VoidReceiptInput): Promise<void>;
1002
- /**
1003
- * Void an electronic receipt via different pos
1004
- */
1005
- voidViaDifferentPos(voidData: ReceiptReturnOrVoidViaPEMInput): Promise<void>;
1006
- /**
1007
- * Void an electronic receipt identified by proof of purchase
1008
- */
1009
- voidWithProof(voidData: ReceiptReturnOrVoidWithProofInput): Promise<void>;
1010
- /**
1011
- * Return an electronic receipt via same pos
1012
- */
1013
- return(returnData: ReceiptReturnInput): Promise<ReceiptOutput>;
1014
- /**
1015
- * get returnable items for a receipt
1016
- */
1017
- getReturnableItems(receiptUuid: string): Promise<ReturnableReceiptItem[]>;
1018
- /**
1019
- * Return items from an electronic receipt via different pos
1020
- */
1021
- returnViaDifferentPos(returnData: ReceiptReturnOrVoidViaPEMInput): Promise<ReceiptOutput>;
1022
- /**
1023
- * Return items from an electronic receipt identified by proof of purchase
1024
- * Authentication mode determined by MTLSHandler
1025
- */
1026
- returnWithProof(returnData: ReceiptReturnOrVoidWithProofInput): Promise<ReceiptOutput>;
1027
- /**
1028
- * Get current authentication status
1029
- */
1030
- getAuthenticationStatus(): Promise<{
1031
- mtlsAvailable: boolean;
1032
- mtlsReady: boolean;
1033
- userContext: UserContext | null;
1034
- recommendedAuthMode: 'auto';
1035
- }>;
1036
- }
1037
-
1038
- /**
1039
- * Suppliers API manager (MF2)
1040
- */
1041
- declare class SuppliersAPI {
1042
- private httpClient;
1043
- constructor(httpClient: HttpClient);
1044
- /**
1045
- * Retrieve the collection of Supplier resources
1046
- */
1047
- list(params: SuppliersParams): Promise<SupplierOutput[]>;
1048
- /**
1049
- * Create a Supplier resource
1050
- */
1051
- create(supplierData: SupplierCreateInput): Promise<SupplierOutput>;
1052
- /**
1053
- * Retrieve a Supplier resource by UUID
1054
- */
1055
- get(uuid: string): Promise<SupplierOutput>;
1056
- /**
1057
- * Replace the Supplier resource
1058
- */
1059
- update(uuid: string, supplierData: SupplierUpdateInput): Promise<SupplierOutput>;
1060
- /**
1061
- * Delete a Supplier resource
1062
- */
1063
- delete(uuid: string): Promise<void>;
1064
- }
1065
-
1066
- /**
1067
- * Main API client that combines all resource managers
1068
- */
1069
- declare class APIClient {
1070
- private httpClient;
1071
- private cache?;
1072
- private networkMonitor?;
1073
- readonly receipts: ReceiptsAPI;
1074
- readonly cashiers: CashiersAPI;
1075
- readonly pointOfSales: PointOfSalesAPI;
1076
- readonly cashRegisters: CashRegistersAPI;
1077
- readonly merchants: MerchantsAPI;
1078
- readonly pems: PemsAPI;
1079
- readonly suppliers: SuppliersAPI;
1080
- readonly dailyReports: DailyReportsAPI;
1081
- readonly journals: JournalsAPI;
1082
- constructor(config: ConfigManager, certificateManager?: CertificateManager, cache?: ICachePort, networkMonitor?: INetworkPort, mtlsAdapter?: IMTLSPort, userProvider?: IUserProvider);
1083
- /**
1084
- * Set an authorization header for all requests
1085
- */
1086
- setAuthorizationHeader(token: string): void;
1087
- /**
1088
- * Remove authorization header
1089
- */
1090
- removeAuthorizationHeader(): void;
1091
- /**
1092
- * Get the underlying HTTP client for advanced use cases
1093
- */
1094
- getHttpClient(): HttpClient;
1095
- /**
1096
- * Get the cache adapter if available
1097
- */
1098
- getCache(): ICachePort | undefined;
1099
- /**
1100
- * Check if the cache is available and enabled
1101
- */
1102
- isCacheEnabled(): boolean;
1103
- /**
1104
- * Get the network monitor if available
1105
- */
1106
- getNetworkMonitor(): INetworkPort | undefined;
1107
- /**
1108
- * Check if network monitoring is enabled
1109
- */
1110
- isNetworkMonitorEnabled(): boolean;
1111
- /**
1112
- * Get current network status
1113
- */
1114
- getNetworkStatus(): {
1115
- isOnline: boolean;
1116
- hasMonitor: boolean;
1117
- };
1118
- /**
1119
- * Check if currently online
1120
- */
1121
- isOnline(): boolean;
1122
- /**
1123
- * Get mTLS adapter if available through HttpClient
1124
- */
1125
- getMTLSAdapter(): IMTLSPort | null;
1126
- /**
1127
- * Check if mTLS is ready
1128
- */
1129
- isMTLSReady(): Promise<boolean>;
1130
- }
1131
-
1132
- /**
1133
- * Offline queue types and interfaces
1134
- */
1135
- type OperationType = 'CREATE' | 'UPDATE' | 'DELETE';
1136
- type ResourceType = 'receipt' | 'cashier' | 'point-of-sale' | 'cash-register' | 'merchant' | 'pem';
1137
- type OperationStatus = 'pending' | 'processing' | 'completed' | 'failed';
1138
- /**
1139
- * Queued operation data structure
1140
- */
1141
- interface QueuedOperation {
1142
- id: string;
1143
- type: OperationType;
1144
- resource: ResourceType;
1145
- endpoint: string;
1146
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
1147
- data?: unknown;
1148
- headers?: Record<string, string>;
1149
- status: OperationStatus;
1150
- createdAt: number;
1151
- updatedAt: number;
1152
- retryCount: number;
1153
- maxRetries: number;
1154
- error?: string;
1155
- priority: number;
1156
- }
1157
- /**
1158
- * Sync result for a single operation
1159
- */
1160
- interface SyncResult {
1161
- operation: QueuedOperation;
1162
- success: boolean;
1163
- error?: string;
1164
- response?: unknown;
1165
- }
1166
- /**
1167
- * Batch sync result
1168
- */
1169
- interface BatchSyncResult {
1170
- totalOperations: number;
1171
- successCount: number;
1172
- failureCount: number;
1173
- results: SyncResult[];
1174
- }
1175
- /**
1176
- * Queue configuration
1177
- */
1178
- interface QueueConfig {
1179
- maxRetries: number;
1180
- retryDelay: number;
1181
- maxRetryDelay: number;
1182
- backoffMultiplier: number;
1183
- maxQueueSize: number;
1184
- batchSize: number;
1185
- syncInterval: number;
1186
- }
1187
- /**
1188
- * Queue events
1189
- */
1190
- interface QueueEvents {
1191
- onOperationAdded?: (operation: QueuedOperation) => void;
1192
- onOperationCompleted?: (result: SyncResult) => void;
1193
- onOperationFailed?: (result: SyncResult) => void;
1194
- onBatchSyncCompleted?: (result: BatchSyncResult) => void;
1195
- onQueueEmpty?: () => void;
1196
- onError?: (error: Error) => void;
1197
- }
1198
-
1199
- /**
1200
- * Operation queue manager for offline functionality
1201
- */
1202
- declare class OperationQueue {
1203
- private storage;
1204
- private config;
1205
- private events;
1206
- private static readonly QUEUE_KEY;
1207
- private queue;
1208
- private isProcessing;
1209
- private syncIntervalId?;
1210
- constructor(storage: IStoragePort, config?: QueueConfig, events?: QueueEvents);
1211
- /**
1212
- * Add an operation to the queue
1213
- */
1214
- addOperation(type: OperationType, resource: ResourceType, endpoint: string, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', data?: unknown, priority?: number): Promise<string>;
1215
- /**
1216
- * Get all pending operations
1217
- */
1218
- getPendingOperations(): QueuedOperation[];
1219
- /**
1220
- * Get operation by ID
1221
- */
1222
- getOperation(id: string): QueuedOperation | undefined;
1223
- /**
1224
- * Remove operation from queue
1225
- */
1226
- removeOperation(id: string): Promise<boolean>;
1227
- /**
1228
- * Update operation status
1229
- */
1230
- updateOperation(id: string, updates: Partial<QueuedOperation>): Promise<boolean>;
1231
- /**
1232
- * Get queue statistics
1233
- */
1234
- getStats(): {
1235
- total: number;
1236
- pending: number;
1237
- processing: number;
1238
- completed: number;
1239
- failed: number;
1240
- };
1241
- /**
1242
- * Clear all operations from queue
1243
- */
1244
- clearQueue(): Promise<void>;
1245
- /**
1246
- * Clear completed operations
1247
- */
1248
- clearCompleted(): Promise<void>;
1249
- /**
1250
- * Clear failed operations
1251
- */
1252
- clearFailed(): Promise<void>;
1253
- /**
1254
- * Retry failed operations
1255
- */
1256
- retryFailed(): Promise<void>;
1257
- /**
1258
- * Get operations for batch processing
1259
- */
1260
- getNextBatch(): QueuedOperation[];
1261
- /**
1262
- * Check if queue is empty (no pending operations)
1263
- */
1264
- isEmpty(): boolean;
1265
- /**
1266
- * Start auto-sync timer
1267
- */
1268
- startAutoSync(): void;
1269
- /**
1270
- * Stop auto-sync timer
1271
- */
1272
- stopAutoSync(): void;
1273
- /**
1274
- * Set processing state
1275
- */
1276
- setProcessing(processing: boolean): void;
1277
- /**
1278
- * Check if currently processing
1279
- */
1280
- isCurrentlyProcessing(): boolean;
1281
- /**
1282
- * Load queue from storage
1283
- */
1284
- private loadQueue;
1285
- /**
1286
- * Save queue to storage
1287
- */
1288
- private saveQueue;
1289
- /**
1290
- * Generate unique ID for operations
1291
- */
1292
- private generateId;
1293
- /**
1294
- * Cleanup resources
1295
- */
1296
- destroy(): void;
1297
- }
1298
-
1299
- /**
1300
- * Enhanced offline manager with optimistic update support
1301
- */
1302
- declare class OfflineManager {
1303
- private queue;
1304
- private syncManager;
1305
- constructor(storage: IStoragePort, httpClient: HttpClient, networkMonitor: INetworkPort, config?: Partial<QueueConfig>, events?: QueueEvents, _cache?: ICachePort);
1306
- /**
1307
- * Queue an operation for offline execution
1308
- */
1309
- queueOperation(type: OperationType, resource: ResourceType, endpoint: string, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', data?: unknown, priority?: number): Promise<string>;
1310
- /**
1311
- * Queue a receipt creation
1312
- */
1313
- queueReceiptCreation(receiptData: unknown, priority?: number): Promise<string>;
1314
- /**
1315
- * Queue a receipt void operation
1316
- */
1317
- queueReceiptVoid(voidData: unknown, priority?: number): Promise<string>;
1318
- /**
1319
- * Queue a receipt return operation
1320
- */
1321
- queueReceiptReturn(returnData: unknown, priority?: number): Promise<string>;
1322
- /**
1323
- * Queue a cashier creation
1324
- */
1325
- queueCashierCreation(cashierData: unknown, priority?: number): Promise<string>;
1326
- /**
1327
- * Check if currently online
1328
- */
1329
- isOnline(): boolean;
1330
- /**
1331
- * Get sync status and queue statistics
1332
- */
1333
- getStatus(): {
1334
- isOnline: boolean;
1335
- isProcessing: boolean;
1336
- queueStats: ReturnType<OperationQueue["getStats"]>;
1337
- };
1338
- /**
1339
- * Get pending operations count
1340
- */
1341
- getPendingCount(): number;
1342
- /**
1343
- * Check if queue is empty
1344
- */
1345
- isEmpty(): boolean;
1346
- /**
1347
- * Manually trigger sync (if online)
1348
- */
1349
- sync(): Promise<BatchSyncResult | null>;
1350
- /**
1351
- * Retry failed operations
1352
- */
1353
- retryFailed(): Promise<void>;
1354
- /**
1355
- * Clear completed operations
1356
- */
1357
- clearCompleted(): Promise<void>;
1358
- /**
1359
- * Clear failed operations
1360
- */
1361
- clearFailed(): Promise<void>;
1362
- /**
1363
- * Clear all operations
1364
- */
1365
- clearAll(): Promise<void>;
1366
- /**
1367
- * Get operation by ID
1368
- */
1369
- getOperation(id: string): QueuedOperation | undefined;
1370
- /**
1371
- * Remove specific operation
1372
- */
1373
- removeOperation(id: string): Promise<boolean>;
1374
- /**
1375
- * Get queue statistics
1376
- */
1377
- getQueueStats(): {
1378
- total: number;
1379
- pending: number;
1380
- processing: number;
1381
- completed: number;
1382
- failed: number;
1383
- };
1384
- /**
1385
- * Start auto-sync (if not already started)
1386
- */
1387
- startAutoSync(): void;
1388
- /**
1389
- * Stop auto-sync
1390
- */
1391
- stopAutoSync(): void;
1392
- /**
1393
- * Create optimistic update (requires cache)
1394
- */
1395
- createOptimisticUpdate<T>(_resource: ResourceType, _operation: OperationType, _endpoint: string, _method: 'POST' | 'PUT' | 'PATCH' | 'DELETE', _data: unknown, _optimisticData: T, _cacheKey: string, _priority?: number): Promise<string | null>;
1396
- /**
1397
- * Enhanced queue receipt creation with optimistic update
1398
- */
1399
- queueReceiptCreationWithOptimistic<T>(receiptData: unknown, optimisticReceipt: T, cacheKey: string, priority?: number): Promise<string | null>;
1400
- /**
1401
- * Enhanced queue receipt void with optimistic update
1402
- */
1403
- queueReceiptVoidWithOptimistic<T>(voidData: unknown, optimisticUpdate: T, cacheKey: string, priority?: number): Promise<string | null>;
1404
- /**
1405
- * Enhanced queue receipt return with optimistic update
1406
- */
1407
- queueReceiptReturnWithOptimistic<T>(returnData: unknown, optimisticReceipt: T, cacheKey: string, priority?: number): Promise<string | null>;
1408
- /**
1409
- * Get optimistic operations (disabled in simplified cache system)
1410
- */
1411
- getOptimisticOperations(): never[];
1412
- /**
1413
- * Get pending optimistic operations count (disabled in simplified cache system)
1414
- */
1415
- getOptimisticPendingCount(): number;
1416
- /**
1417
- * Check if optimistic updates are enabled (disabled in simplified cache system)
1418
- */
1419
- isOptimisticEnabled(): boolean;
1420
- /**
1421
- * Check if resource has pending optimistic updates (disabled in simplified cache system)
1422
- */
1423
- hasPendingOptimisticUpdates(_resource: ResourceType, _resourceId?: string): boolean;
1424
- /**
1425
- * Get the optimistic manager (disabled in simplified cache system)
1426
- */
1427
- getOptimisticManager(): null;
1428
- /**
1429
- * Manually rollback a specific optimistic operation (disabled in simplified cache system)
1430
- */
1431
- rollbackOptimisticOperation(_operationId: string, _reason?: string): Promise<void>;
1432
- /**
1433
- * Manually rollback all pending optimistic operations for a resource (disabled in simplified cache system)
1434
- */
1435
- rollbackOptimisticOperationsByResource(_resource: ResourceType, _resourceId?: string): Promise<void>;
1436
- /**
1437
- * Cleanup resources
1438
- */
1439
- destroy(): void;
1440
- }
1441
-
1442
- /**
1443
- * SDK Events interface
1444
- */
1445
- interface SDKEvents {
1446
- onUserChanged?: (user: User | null) => void;
1447
- onAuthError?: (error: ACubeSDKError) => void;
1448
- onNetworkStatusChanged?: (online: boolean) => void;
1449
- onOfflineOperationAdded?: (operationId: string) => void;
1450
- onOfflineOperationCompleted?: (operationId: string, success: boolean) => void;
1451
- }
1452
- /**
1453
- * Main ACube SDK class
1454
- */
1455
- declare class ACubeSDK {
1456
- private events;
1457
- private config;
1458
- private adapters?;
1459
- private authManager?;
1460
- private offlineManager?;
1461
- private certificateManager?;
1462
- private isInitialized;
1463
- api?: APIClient;
1464
- constructor(config: SDKConfig, customAdapters?: PlatformAdapters, events?: SDKEvents);
1465
- /**
1466
- * Initialize the SDK
1467
- */
1468
- initialize(): Promise<void>;
1469
- /**
1470
- * Login with email and password
1471
- */
1472
- login(credentials: AuthCredentials): Promise<User>;
1473
- /**
1474
- * Logout current user
1475
- */
1476
- logout(): Promise<void>;
1477
- /**
1478
- * Get current user
1479
- */
1480
- getCurrentUser(): Promise<User | null>;
1481
- /**
1482
- * Check if the user is authenticated
1483
- */
1484
- isAuthenticated(): Promise<boolean>;
1485
- /**
1486
- * Get offline manager for manual queue operations
1487
- */
1488
- getOfflineManager(): OfflineManager;
1489
- /**
1490
- * Check if currently online
1491
- */
1492
- isOnline(): boolean;
1493
- /**
1494
- * Get SDK configuration
1495
- */
1496
- getConfig(): SDKConfig;
1497
- /**
1498
- * Update SDK configuration
1499
- */
1500
- updateConfig(updates: Partial<SDKConfig>): void;
1501
- /**
1502
- * Get platform adapters (for advanced use cases)
1503
- */
1504
- getAdapters(): PlatformAdapters | undefined;
1505
- /**
1506
- * Store mTLS certificate (replaces any existing certificate)
1507
- */
1508
- storeCertificate(certificate: string, privateKey: string, options?: {
1509
- name?: string;
1510
- format?: 'pem' | 'p12' | 'pkcs12';
1511
- password?: string;
1512
- }): Promise<void>;
1513
- /**
1514
- * Get mTLS status and configuration info
1515
- */
1516
- getMTLSStatus(): Promise<{
1517
- adapterAvailable: boolean;
1518
- certificateManagerAvailable: boolean;
1519
- isReady: boolean;
1520
- hasCertificate: boolean;
1521
- certificateInfo: {
1522
- format: string;
1523
- } | null;
1524
- platformInfo: {
1525
- platform: "react-native" | "node" | "web" | "expo";
1526
- mtlsSupported: boolean;
1527
- certificateStorage: "keychain" | "keystore" | "filesystem" | "browser-managed" | "memory";
1528
- fallbackToJWT: boolean;
1529
- } | null;
1530
- diagnosticTest: boolean;
1531
- diagnosticTestNote: string;
1532
- pendingRequestsCount: number;
1533
- }>;
1534
- /**
1535
- * Test mTLS connection
1536
- */
1537
- testMTLSConnection(): Promise<boolean>;
1538
- /**
1539
- * Clear the stored certificate
1540
- */
1541
- clearCertificate(): Promise<void>;
1542
- /**
1543
- * Get certificate manager for advanced certificate operations
1544
- */
1545
- getCertificateManager(): CertificateManager | undefined;
1546
- /**
1547
- * Get the stored certificate
1548
- */
1549
- getCertificate(): Promise<StoredCertificate | null>;
1550
- /**
1551
- * Get certificate information (without private key)
1552
- */
1553
- getCertificateInfo(): Promise<{
1554
- format: string;
1555
- } | null>;
1556
- /**
1557
- * Check if certificate is stored
1558
- */
1559
- hasCertificate(): Promise<boolean>;
1560
- /**
1561
- * Get detailed certificate information from stored certificates
1562
- * This method retrieves certificate metadata including subject, issuer,
1563
- * validity dates, fingerprints, key usage, and more from the mTLS adapter.
1564
- *
1565
- * Uses retry-on-failure pattern similar to executeRequestMTLS:
1566
- * - First attempt: Try to get certificate info
1567
- * - If null and certificate exists: Configure certificate and retry once
1568
- * - Maximum 2 attempts to prevent infinite loops
1569
- *
1570
- * @param isRetryAttempt Internal flag to prevent infinite retry loops
1571
- * @returns Promise with detailed certificate information or null if not available
1572
- */
1573
- getCertificatesInfo(isRetryAttempt?: boolean): Promise<CertificateInfo | null>;
1574
- /**
1575
- * Destroy SDK and cleanup resources
1576
- */
1577
- destroy(): void;
1578
- /**
1579
- * Ensure SDK is initialized
1580
- */
1581
- private ensureInitialized;
1582
- }
1583
-
1584
- interface ACubeContextValue {
1585
- sdk: ACubeSDK | null;
1586
- user: User | null;
1587
- isAuthenticated: boolean;
1588
- isLoading: boolean;
1589
- isOnline: boolean;
1590
- error: ACubeSDKError | null;
1591
- pendingOperations: number;
1592
- }
1593
- interface ACubeProviderProps {
1594
- config: SDKConfig;
1595
- children: React.ReactNode;
1596
- onUserChanged?: (user: User | null) => void;
1597
- onAuthError?: (error: ACubeSDKError) => void;
1598
- onNetworkStatusChanged?: (online: boolean) => void;
1599
- }
1600
- declare function ACubeProvider({ config, children, onUserChanged, onAuthError, onNetworkStatusChanged, }: ACubeProviderProps): React.JSX.Element;
1601
- declare function useACube(): ACubeContextValue;
1602
-
1603
- interface UseAuthReturn {
1604
- user: User | null;
1605
- isAuthenticated: boolean;
1606
- isLoading: boolean;
1607
- error: ACubeSDKError | null;
1608
- login: (credentials: AuthCredentials) => Promise<User | null>;
1609
- logout: () => Promise<void>;
1610
- clearError: () => void;
1611
- }
1612
- declare function useAuth(): UseAuthReturn;
1613
-
1614
- export { ACubeProvider, useACube, useAuth };
1615
- export type { ACubeContextValue, ACubeProviderProps, UseAuthReturn };