@a-cube-io/ereceipts-js-sdk 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1892,27 +1892,6 @@ function clearObject(input) {
1892
1892
  }
1893
1893
  return input;
1894
1894
  }
1895
- function clearObjectShallow(obj) {
1896
- if (!obj || typeof obj !== 'object') {
1897
- return {};
1898
- }
1899
- const cleaned = {};
1900
- for (const [key, value] of Object.entries(obj)) {
1901
- if (value !== null && value !== undefined && value !== '') {
1902
- cleaned[key] = value;
1903
- }
1904
- }
1905
- return cleaned;
1906
- }
1907
- function isEmpty(value) {
1908
- return value === null || value === undefined || value === '';
1909
- }
1910
- function hasNonEmptyValues(obj) {
1911
- if (!obj || typeof obj !== 'object') {
1912
- return false;
1913
- }
1914
- return Object.values(obj).some((value) => !isEmpty(value));
1915
- }
1916
1895
 
1917
1896
  /**
1918
1897
  * Platform detection utilities
@@ -2469,7 +2448,7 @@ class ConfigManager {
2469
2448
  }
2470
2449
  }
2471
2450
 
2472
- // Enum options arrays
2451
+ // Enum options arrays (used by consumers for dropdowns and form validation)
2473
2452
  const VAT_RATE_CODE_OPTIONS = [
2474
2453
  '4.00',
2475
2454
  '5.00',
@@ -2496,103 +2475,10 @@ const VAT_RATE_CODE_OPTIONS = [
2496
2475
  ];
2497
2476
  const GOOD_OR_SERVICE_OPTIONS = ['goods', 'service'];
2498
2477
  const RECEIPT_PROOF_TYPE_OPTIONS = ['POS', 'VR', 'ND'];
2499
- // Enum types for receipt validation
2478
+ // Enum schemas (used by consumers as building blocks for their own form schemas)
2500
2479
  const VatRateCodeSchema = z__namespace.enum(VAT_RATE_CODE_OPTIONS);
2501
2480
  const GoodOrServiceSchema = z__namespace.enum(GOOD_OR_SERVICE_OPTIONS);
2502
2481
  const ReceiptProofTypeSchema = z__namespace.enum(RECEIPT_PROOF_TYPE_OPTIONS);
2503
- // Receipt Item Schema
2504
- const ReceiptItemSchema = z__namespace.object({
2505
- type: GoodOrServiceSchema.optional(),
2506
- quantity: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2507
- description: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2508
- unit_price: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2509
- vat_rate_code: VatRateCodeSchema.optional(),
2510
- simplified_vat_allocation: z__namespace.boolean().optional(),
2511
- discount: z__namespace.string().nullable().optional(),
2512
- is_down_payment_or_voucher_redemption: z__namespace.boolean().optional(),
2513
- complimentary: z__namespace.boolean().optional(),
2514
- });
2515
- // Main Receipt Input Schema
2516
- const ReceiptInputSchema = z__namespace
2517
- .object({
2518
- items: z__namespace.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
2519
- customer_tax_code: z__namespace.string().optional(),
2520
- customer_lottery_code: z__namespace.string().optional(),
2521
- discount: z__namespace.string().nullable().optional(),
2522
- invoice_issuing: z__namespace.boolean().optional(),
2523
- uncollected_dcr_to_ssn: z__namespace.boolean().optional(),
2524
- services_uncollected_amount: z__namespace.string().nullable().optional(),
2525
- goods_uncollected_amount: z__namespace.string().nullable().optional(),
2526
- cash_payment_amount: z__namespace.string().nullable().optional(),
2527
- electronic_payment_amount: z__namespace.string().nullable().optional(),
2528
- ticket_restaurant_payment_amount: z__namespace.string().nullable().optional(),
2529
- ticket_restaurant_quantity: z__namespace.number().optional(),
2530
- })
2531
- .refine((data) => {
2532
- // At least one payment method should be provided
2533
- const hasCashPayment = data.cash_payment_amount && parseFloat(data.cash_payment_amount) > 0;
2534
- const hasElectronicPayment = data.electronic_payment_amount && parseFloat(data.electronic_payment_amount) > 0;
2535
- const hasTicketPayment = data.ticket_restaurant_payment_amount &&
2536
- parseFloat(data.ticket_restaurant_payment_amount) > 0;
2537
- return hasCashPayment || hasElectronicPayment || hasTicketPayment;
2538
- }, {
2539
- error: 'At least one payment method is required',
2540
- path: ['payment_methods'],
2541
- })
2542
- .refine((data) => {
2543
- // only one between customer_tax_code and customer_lottery_code can be provided
2544
- return !data.customer_tax_code || !data.customer_lottery_code;
2545
- }, {
2546
- error: 'Only one between customer_tax_code and customer_lottery_code can be provided',
2547
- path: ['customer_tax_code', 'customer_lottery_code'],
2548
- });
2549
- // Receipt Return or Void via PEM Schema
2550
- const ReceiptReturnOrVoidViaPEMInputSchema = z__namespace.object({
2551
- device_id: z__namespace.string().optional(),
2552
- items: z__namespace.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
2553
- document_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2554
- document_datetime: z__namespace.string().optional(),
2555
- lottery_code: z__namespace.string().optional(),
2556
- });
2557
- // Receipt Return or Void with Proof Schema
2558
- const ReceiptReturnOrVoidWithProofInputSchema = z__namespace.object({
2559
- items: z__namespace.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
2560
- proof: ReceiptProofTypeSchema,
2561
- document_datetime: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2562
- });
2563
- // Void Receipt Schema
2564
- const VoidReceiptInputSchema = z__namespace.object({
2565
- document_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2566
- });
2567
- const ReceiptReturnItemSchema = z__namespace
2568
- .array(z__namespace.object({
2569
- id: z__namespace.number(),
2570
- quantity: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2571
- }))
2572
- .min(1, { error: 'arrayMin1' });
2573
- // Receipt Return Schema
2574
- const ReceiptReturnInputSchema = z__namespace.object({
2575
- items: z__namespace.array(ReceiptReturnItemSchema).min(1, { error: 'arrayMin1' }),
2576
- document_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2577
- });
2578
-
2579
- // Cashier Create Input Schema (MF1)
2580
- const CashierCreateInputSchema = z__namespace.object({
2581
- email: z__namespace
2582
- .string()
2583
- .min(1, { error: 'fieldIsRequired' })
2584
- .max(255, { error: 'emailMaxLength' })
2585
- .email({ error: 'invalidEmail' }),
2586
- password: z__namespace
2587
- .string()
2588
- .min(8, { error: 'passwordMinLength' })
2589
- .max(40, { error: 'passwordMaxLength' }),
2590
- name: z__namespace.string().min(1, { error: 'fieldIsRequired' }).max(255, { error: 'nameMaxLength' }),
2591
- display_name: z__namespace
2592
- .string()
2593
- .min(1, { error: 'fieldIsRequired' })
2594
- .max(255, { error: 'displayNameMaxLength' }),
2595
- });
2596
2482
 
2597
2483
  // Enum options arrays
2598
2484
  const PEM_STATUS_OPTIONS = [
@@ -2603,312 +2489,12 @@ const PEM_STATUS_OPTIONS = [
2603
2489
  'OFFLINE',
2604
2490
  'DISCARDED',
2605
2491
  ];
2606
- // Address Schema (reusable)
2607
- const AddressSchema = z__namespace.object({
2608
- street_address: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2609
- street_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2610
- zip_code: z__namespace
2611
- .string()
2612
- .min(1, { error: 'fieldIsRequired' })
2613
- .regex(/^\d{5}$/, { error: 'invalidZipCode' }),
2614
- city: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2615
- province: z__namespace
2616
- .string()
2617
- .min(2, { error: 'provinceMinLength' })
2618
- .max(2, { error: 'provinceMaxLength' })
2619
- .toUpperCase(),
2620
- });
2621
- // PEM Status Schema
2622
- const PEMStatusSchema = z__namespace.enum(PEM_STATUS_OPTIONS);
2623
- // Activation Request Schema
2624
- const ActivationRequestSchema = z__namespace.object({
2625
- registration_key: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2626
- });
2627
- // PEM Status Offline Request Schema
2628
- const PEMStatusOfflineRequestSchema = z__namespace.object({
2629
- timestamp: z__namespace
2630
- .string()
2631
- .min(1, { error: 'fieldIsRequired' })
2632
- .refine((val) => !isNaN(Date.parse(val)), {
2633
- error: 'invalidDateFormat',
2634
- }),
2635
- reason: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2636
- });
2637
-
2638
- // Cash Register Create Schema
2639
- const CashRegisterCreateSchema = z__namespace.object({
2640
- pem_serial_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2641
- name: z__namespace.string().min(1, { error: 'fieldIsRequired' }).max(100, { error: 'nameMaxLength' }),
2642
- });
2643
-
2644
- // VAT number validation regex (Partita IVA - 11 digits)
2645
- const VAT_NUMBER_REGEX = /^\d{11}$/;
2646
- // Fiscal code validation regex (Codice Fiscale - 11 digits only for merchants)
2647
- const FISCAL_CODE_REGEX = /^\d{11}$/;
2648
- // Password validation regex (from OpenAPI spec)
2649
- const PASSWORD_REGEX = /^((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{10,}).*)$/;
2650
- // Merchant Create Input Schema
2651
- const MerchantCreateInputSchema = z__namespace
2652
- .object({
2653
- vat_number: z__namespace
2654
- .string()
2655
- .min(1, { error: 'fieldIsRequired' })
2656
- .regex(VAT_NUMBER_REGEX, { error: 'invalidVatNumber' }),
2657
- fiscal_code: z__namespace.string().regex(FISCAL_CODE_REGEX, { error: 'invalidFiscalCode' }).optional(),
2658
- business_name: z__namespace.string().max(200, { error: 'businessNameMaxLength' }).optional().nullable(),
2659
- first_name: z__namespace.string().max(100, { error: 'firstNameMaxLength' }).optional().nullable(),
2660
- last_name: z__namespace.string().max(100, { error: 'lastNameMaxLength' }).optional().nullable(),
2661
- email: z__namespace.string().min(1, { error: 'fieldIsRequired' }).email({ error: 'invalidEmail' }),
2662
- password: z__namespace
2663
- .string()
2664
- .min(1, { error: 'fieldIsRequired' })
2665
- .regex(PASSWORD_REGEX, { error: 'passwordComplexity' }),
2666
- address: AddressSchema.optional(),
2667
- })
2668
- .refine((data) => {
2669
- const hasBusinessName = data.business_name && data.business_name.trim() !== '';
2670
- const hasPersonalNames = (data.first_name && data.first_name.trim() !== '') ||
2671
- (data.last_name && data.last_name.trim() !== '');
2672
- // If business name is set, first/last name must not be provided
2673
- if (hasBusinessName && hasPersonalNames) {
2674
- return false;
2675
- }
2676
- // At least one naming method must be provided
2677
- if (!hasBusinessName && !hasPersonalNames) {
2678
- return false;
2679
- }
2680
- return true;
2681
- }, {
2682
- error: 'businessNameOrPersonalNamesRequired',
2683
- path: ['business_name'],
2684
- });
2685
- // Merchant Update Input Schema
2686
- const MerchantUpdateInputSchema = z__namespace.object({
2687
- business_name: z__namespace.string().max(200, { error: 'businessNameMaxLength' }).optional().nullable(),
2688
- first_name: z__namespace.string().max(100, { error: 'firstNameMaxLength' }).optional().nullable(),
2689
- last_name: z__namespace.string().max(100, { error: 'lastNameMaxLength' }).optional().nullable(),
2690
- address: AddressSchema.optional().nullable(),
2691
- });
2692
2492
 
2693
2493
  // Enum options arrays
2694
2494
  const PEM_TYPE_OPTIONS = ['AP', 'SP', 'TM', 'PV'];
2695
- // PEM Data Schema
2696
- const PemDataSchema = z__namespace.object({
2697
- version: z__namespace.string().min(1, { error: 'fieldIsRequired' }),
2698
- type: z__namespace.enum(PEM_TYPE_OPTIONS, {
2699
- error: 'invalidPemType',
2700
- }),
2701
- });
2702
- // PEM Create Input Schema
2703
- const PemCreateInputSchema = z__namespace.object({
2704
- merchant_uuid: z__namespace.string().min(1, { error: 'fieldIsRequired' }).uuid({ error: 'invalidUuid' }),
2705
- address: AddressSchema.optional(),
2706
- /* external_pem_data: PemDataSchema.optional(), */
2707
- });
2708
-
2709
- // Italian Fiscal ID validation regex (Codice Fiscale for individuals or Partita IVA for companies)
2710
- const FISCAL_ID_REGEX = /^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST][0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{3}[A-Z]|[0-9]{11})$/;
2711
- // Supplier Create Input Schema
2712
- const SupplierCreateInputSchema = z__namespace.object({
2713
- fiscal_id: z__namespace
2714
- .string()
2715
- .min(1, { error: 'fieldIsRequired' })
2716
- .regex(FISCAL_ID_REGEX, { error: 'invalidFiscalId' })
2717
- .toUpperCase(),
2718
- name: z__namespace.string().min(1, { error: 'fieldIsRequired' }).max(200, { error: 'nameMaxLength' }),
2719
- address: AddressSchema.optional(),
2720
- });
2721
- // Supplier Update Input Schema
2722
- const SupplierUpdateInputSchema = z__namespace.object({
2723
- name: z__namespace.string().min(1, { error: 'fieldIsRequired' }).max(200, { error: 'nameMaxLength' }),
2724
- address: AddressSchema.optional(),
2725
- });
2726
-
2727
- // Journal Close Input Schema
2728
- const JournalCloseInputSchema = z__namespace.object({
2729
- closing_timestamp: z__namespace
2730
- .string()
2731
- .min(1, { error: 'fieldIsRequired' })
2732
- .refine((val) => !isNaN(Date.parse(val)), {
2733
- error: 'invalidDateFormat',
2734
- }),
2735
- reason: z__namespace.string().max(255, { error: 'reasonMaxLength' }).optional(),
2736
- });
2737
2495
 
2738
- // Daily Report Status Options
2496
+ // Enum options arrays
2739
2497
  const DAILY_REPORT_STATUS_OPTIONS = ['pending', 'sent', 'error'];
2740
- // Daily Report Status Schema
2741
- const DailyReportStatusSchema = z__namespace.enum(DAILY_REPORT_STATUS_OPTIONS, {
2742
- error: 'invalidDailyReportStatus',
2743
- });
2744
- // Daily Reports List Parameters Schema
2745
- const DailyReportsParamsSchema = z__namespace.object({
2746
- pem_serial_number: z__namespace.string().min(1, { error: 'fieldIsRequired' }).optional(),
2747
- date_from: z__namespace
2748
- .string()
2749
- .refine((val) => !isNaN(Date.parse(val)), {
2750
- error: 'invalidDateFormat',
2751
- })
2752
- .optional(),
2753
- date_to: z__namespace
2754
- .string()
2755
- .refine((val) => !isNaN(Date.parse(val)), {
2756
- error: 'invalidDateFormat',
2757
- })
2758
- .optional(),
2759
- status: DailyReportStatusSchema.optional(),
2760
- page: z__namespace.number().min(1, { error: 'pageMinValue' }).optional(),
2761
- });
2762
-
2763
- const NotificationScopeSchema = z__namespace.object({
2764
- type: z__namespace.literal('global'),
2765
- });
2766
- const PemStatusSchema = z__namespace.enum(['ONLINE', 'OFFLINE']);
2767
- const NotificationDataBlockAtSchema = z__namespace.object({
2768
- block_at: z__namespace.string(),
2769
- });
2770
- const NotificationDataPemStatusSchema = z__namespace.object({
2771
- from: PemStatusSchema,
2772
- to: PemStatusSchema,
2773
- });
2774
- const NotificationBaseSchema = z__namespace.object({
2775
- uuid: z__namespace.string().uuid({ error: 'invalidUuid' }),
2776
- scope: NotificationScopeSchema,
2777
- source: z__namespace.enum(['system', 'Italian Tax Authority']),
2778
- level: z__namespace.enum(['info', 'warning', 'error', 'critical']),
2779
- created_at: z__namespace.string(),
2780
- });
2781
- const NotificationMf2UnreachableSchema = NotificationBaseSchema.extend({
2782
- type: z__namespace.literal('INTERNAL_COMMUNICATION_FAILURE'),
2783
- code: z__namespace.literal('SYS-W-01'),
2784
- data: NotificationDataBlockAtSchema,
2785
- });
2786
- const NotificationPemsBlockedSchema = NotificationBaseSchema.extend({
2787
- type: z__namespace.literal('PEM_STATUS_CHANGED'),
2788
- code: z__namespace.literal('SYS-C-01'),
2789
- data: NotificationDataPemStatusSchema,
2790
- });
2791
- const NotificationPemBackOnlineSchema = NotificationBaseSchema.extend({
2792
- type: z__namespace.literal('PEM_STATUS_CHANGED'),
2793
- code: z__namespace.literal('SYS-I-01'),
2794
- data: NotificationDataPemStatusSchema,
2795
- });
2796
- const NotificationSchema = z__namespace.discriminatedUnion('code', [
2797
- NotificationMf2UnreachableSchema,
2798
- NotificationPemsBlockedSchema,
2799
- NotificationPemBackOnlineSchema,
2800
- ]);
2801
- const NotificationListResponseSchema = z__namespace.object({
2802
- members: z__namespace.array(NotificationSchema),
2803
- });
2804
-
2805
- const TelemetryMerchantSchema = z__namespace.object({
2806
- vat_number: z__namespace.string(),
2807
- fiscal_code: z__namespace.string().nullable(),
2808
- business_name: z__namespace.string(),
2809
- });
2810
- const TelemetrySupplierSchema = z__namespace.object({
2811
- vat_number: z__namespace.string(),
2812
- fiscal_code: z__namespace.string().nullable(),
2813
- business_name: z__namespace.string(),
2814
- });
2815
- const TelemetrySoftwareVersionSchema = z__namespace.object({
2816
- version: z__namespace.string(),
2817
- swid: z__namespace.string(),
2818
- installed_at: z__namespace.string(),
2819
- status: z__namespace.enum(['active', 'inactive', 'archived']),
2820
- });
2821
- const TelemetrySoftwareSchema = z__namespace.object({
2822
- code: z__namespace.string(),
2823
- name: z__namespace.string(),
2824
- approval_reference: z__namespace.string(),
2825
- version_info: TelemetrySoftwareVersionSchema,
2826
- });
2827
- const PendingReceiptsSchema = z__namespace.object({
2828
- count: z__namespace.number().int().nonnegative(),
2829
- total_amount: z__namespace.string(),
2830
- });
2831
- const TransmissionSchema = z__namespace.object({
2832
- attempted_at: z__namespace.string(),
2833
- outcome: z__namespace.enum(['success', 'failed', 'pending']),
2834
- });
2835
- const MessageSchema = z__namespace.object({
2836
- received_at: z__namespace.string(),
2837
- content: z__namespace.string(),
2838
- });
2839
- const LotterySecretRequestSchema = z__namespace.object({
2840
- requested_at: z__namespace.string(),
2841
- outcome: z__namespace.enum(['success', 'failed', 'pending']),
2842
- });
2843
- const LotterySchema = z__namespace.object({
2844
- last_transmission: TransmissionSchema,
2845
- secret_request: LotterySecretRequestSchema,
2846
- });
2847
- const TelemetrySchema = z__namespace.object({
2848
- pem_id: z__namespace.string(),
2849
- pem_status: z__namespace.enum(['ONLINE', 'OFFLINE', 'ERROR']),
2850
- pem_status_changed_at: z__namespace.string(),
2851
- merchant: TelemetryMerchantSchema,
2852
- supplier: TelemetrySupplierSchema,
2853
- software: TelemetrySoftwareSchema,
2854
- last_communication_at: z__namespace.string(),
2855
- pending_receipts: PendingReceiptsSchema,
2856
- last_receipt_transmission: TransmissionSchema,
2857
- last_message_from_mf2: MessageSchema,
2858
- ade_corrispettivi_transmission: TransmissionSchema,
2859
- last_message_from_ade: MessageSchema,
2860
- lottery: LotterySchema,
2861
- });
2862
-
2863
- // Receipt schemas and types
2864
- // Common validation utilities
2865
- const ValidationMessages = {
2866
- fieldIsRequired: 'This field is required',
2867
- arrayMin1: 'At least one item is required',
2868
- paymentMethodRequired: 'At least one payment method is required',
2869
- invalidEmail: 'Please enter a valid email address',
2870
- passwordMinLength: 'Password must be at least 8 characters long',
2871
- passwordComplexity: 'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
2872
- invalidZipCode: 'Please enter a valid 5-digit zip code',
2873
- provinceMinLength: 'Province code must be 2 characters',
2874
- provinceMaxLength: 'Province code must be 2 characters',
2875
- invalidDateFormat: 'Please enter a valid date',
2876
- nameMaxLength: 'Name is too long',
2877
- invalidFiscalId: 'Please enter a valid Italian fiscal ID (Codice Fiscale or Partita IVA)',
2878
- invalidVatNumber: 'Please enter a valid VAT number (11 digits)',
2879
- invalidFiscalCode: 'Please enter a valid fiscal code (11 digits)',
2880
- businessNameMaxLength: 'Business name is too long (max 200 characters)',
2881
- businessNameOrPersonalNamesRequired: 'Please provide either a business name or first/last name, but not both',
2882
- firstNameMaxLength: 'First name is too long (max 100 characters)',
2883
- lastNameMaxLength: 'Last name is too long (max 100 characters)',
2884
- invalidUuid: 'Please enter a valid UUID',
2885
- invalidPemType: 'PEM type must be one of: AP, SP, TM, PV',
2886
- reasonMaxLength: 'Reason is too long (max 255 characters)',
2887
- pageMinValue: 'Page number must be at least 1',
2888
- invalidDailyReportStatus: 'Daily report status must be one of: pending, sent, error',
2889
- displayNameMaxLength: 'Display name is too long (max 255 characters)',
2890
- };
2891
- // Validation helper functions
2892
- const validateInput = (schema, data) => {
2893
- const result = schema.safeParse(data);
2894
- if (!result.success) {
2895
- const errors = result.error.issues.map((error) => ({
2896
- field: error.path.join('.'),
2897
- message: error.message,
2898
- code: error.code,
2899
- }));
2900
- return {
2901
- success: false,
2902
- errors,
2903
- data: null,
2904
- };
2905
- }
2906
- return {
2907
- success: true,
2908
- errors: [],
2909
- data: result.data,
2910
- };
2911
- };
2912
2498
 
2913
2499
  class ACubeSDKError extends Error {
2914
2500
  constructor(type, message, originalError, statusCode, violations) {
@@ -2947,6 +2533,14 @@ class AuthStrategy {
2947
2533
  if (userRole === 'SUPPLIER') {
2948
2534
  return { mode: 'jwt', usePort444: false };
2949
2535
  }
2536
+ if (url.includes('/download-data')) {
2537
+ if (platform === 'mobile') {
2538
+ return { mode: 'mtls', usePort444: true };
2539
+ }
2540
+ else {
2541
+ return { mode: 'jwt', usePort444: true };
2542
+ }
2543
+ }
2950
2544
  if (userRole === 'CASHIER') {
2951
2545
  if (!isReceiptEndpoint) {
2952
2546
  return { mode: 'jwt', usePort444: false };
@@ -3283,11 +2877,6 @@ class MtlsAuthHandler {
3283
2877
  }
3284
2878
  }
3285
2879
 
3286
- /**
3287
- * Mixin that adds multiGet, multiSet, multiRemove to any storage adapter
3288
- * Eliminates duplicate code across Node, Web, and React Native adapters
3289
- */
3290
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3291
2880
  /**
3292
2881
  * Abstract base class for standard storage adapters
3293
2882
  * Implements multi-operations, subclasses implement core operations
@@ -5381,6 +4970,12 @@ class PemRepositoryImpl {
5381
4970
  const response = await this.http.get(`/mf2/pems/${serialNumber}/certificates`);
5382
4971
  return PemMapper.fromCertificatesApiOutput(response.data);
5383
4972
  }
4973
+ async downloadData(serialNumber) {
4974
+ const response = await this.http.get(`/mf1/pems/${serialNumber}/download-data`, {
4975
+ responseType: 'arraybuffer',
4976
+ });
4977
+ return response.data;
4978
+ }
5384
4979
  }
5385
4980
 
5386
4981
  class DailyReportMapper {
@@ -7184,310 +6779,59 @@ const RECEIPT_SENT = 'sent';
7184
6779
  const RECEIPT_SORT_DESCENDING = 'descending';
7185
6780
  const RECEIPT_SORT_ASCENDING = 'ascending';
7186
6781
 
7187
- function transformError(error) {
7188
- if (axios.isAxiosError(error)) {
7189
- const response = error.response;
7190
- if (!response) {
7191
- return new ACubeSDKError('NETWORK_ERROR', 'Network error occurred', error);
7192
- }
7193
- const status = response.status;
7194
- const data = response.data;
7195
- const violations = data?.violations;
7196
- let message = 'Unknown error occurred';
7197
- if (data?.detail) {
7198
- message = data.detail;
7199
- }
7200
- else if (data?.title) {
7201
- message = data.title;
7202
- }
7203
- else if (error.message) {
7204
- message = error.message;
7205
- }
7206
- switch (status) {
7207
- case 400:
7208
- return new ACubeSDKError('VALIDATION_ERROR', message, error, status, violations);
7209
- case 401:
7210
- return new ACubeSDKError('AUTH_ERROR', message, error, status, violations);
7211
- case 403:
7212
- return new ACubeSDKError('FORBIDDEN_ERROR', message, error, status, violations);
7213
- case 404:
7214
- return new ACubeSDKError('NOT_FOUND_ERROR', message, error, status, violations);
7215
- case 422:
7216
- return new ACubeSDKError('VALIDATION_ERROR', message, error, status, violations);
7217
- default:
7218
- return new ACubeSDKError('UNKNOWN_ERROR', message, error, status, violations);
7219
- }
7220
- }
7221
- return new ACubeSDKError('UNKNOWN_ERROR', 'Unknown error occurred', error);
7222
- }
7223
-
7224
- exports.ErrorCategory = void 0;
7225
- (function (ErrorCategory) {
7226
- ErrorCategory["SERVER_ERROR"] = "SERVER_ERROR";
7227
- ErrorCategory["CLIENT_ERROR"] = "CLIENT_ERROR";
7228
- ErrorCategory["AUTH_ERROR"] = "AUTH_ERROR";
7229
- ErrorCategory["CERTIFICATE_ERROR"] = "CERTIFICATE_ERROR";
7230
- ErrorCategory["NETWORK_ERROR"] = "NETWORK_ERROR";
7231
- ErrorCategory["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
7232
- })(exports.ErrorCategory || (exports.ErrorCategory = {}));
7233
- function extractStatusCode(error) {
7234
- if (error instanceof MTLSError && error.statusCode) {
7235
- return error.statusCode;
7236
- }
7237
- const errorObj = error;
7238
- if (errorObj?.response?.status) {
7239
- return errorObj.response.status;
7240
- }
7241
- if (typeof errorObj?.statusCode === 'number') {
7242
- return errorObj.statusCode;
7243
- }
7244
- return undefined;
7245
- }
7246
- function classifyError(error) {
7247
- const statusCode = extractStatusCode(error);
7248
- const errorMessage = error instanceof Error ? error.message : String(error);
7249
- if (statusCode && statusCode >= 500 && statusCode < 600) {
7250
- return {
7251
- category: exports.ErrorCategory.SERVER_ERROR,
7252
- statusCode,
7253
- message: errorMessage,
7254
- shouldRetry: false,
7255
- userMessage: `Server error (${statusCode}): The server encountered an error.`,
7256
- };
7257
- }
7258
- if (statusCode === 401 || statusCode === 403) {
7259
- return {
7260
- category: exports.ErrorCategory.AUTH_ERROR,
7261
- statusCode,
7262
- message: errorMessage,
7263
- shouldRetry: false,
7264
- userMessage: `Authentication error (${statusCode}): Invalid credentials or insufficient permissions.`,
7265
- };
7266
- }
7267
- if (statusCode && statusCode >= 400 && statusCode < 500) {
7268
- return {
7269
- category: exports.ErrorCategory.CLIENT_ERROR,
7270
- statusCode,
7271
- message: errorMessage,
7272
- shouldRetry: false,
7273
- userMessage: `Request error (${statusCode}): ${errorMessage}`,
7274
- };
7275
- }
7276
- if (error instanceof MTLSError) {
7277
- return {
7278
- category: exports.ErrorCategory.CERTIFICATE_ERROR,
7279
- statusCode,
7280
- message: errorMessage,
7281
- shouldRetry: true,
7282
- userMessage: 'Certificate error: Unable to establish secure connection.',
7283
- };
7284
- }
7285
- if (!statusCode &&
7286
- (errorMessage.toLowerCase().includes('network') ||
7287
- errorMessage.toLowerCase().includes('timeout') ||
7288
- errorMessage.toLowerCase().includes('connection'))) {
7289
- return {
7290
- category: exports.ErrorCategory.NETWORK_ERROR,
7291
- message: errorMessage,
7292
- shouldRetry: true,
7293
- userMessage: 'Network error: Unable to connect to server.',
7294
- };
7295
- }
7296
- return {
7297
- category: exports.ErrorCategory.UNKNOWN_ERROR,
7298
- statusCode,
7299
- message: errorMessage,
7300
- shouldRetry: false,
7301
- userMessage: `Unexpected error: ${errorMessage}`,
7302
- };
7303
- }
7304
- function shouldReconfigureCertificate(error) {
7305
- const classification = classifyError(error);
7306
- return classification.category === exports.ErrorCategory.CERTIFICATE_ERROR;
7307
- }
7308
- function shouldRetryRequest(error, isRetryAttempt) {
7309
- if (isRetryAttempt) {
7310
- return false;
7311
- }
7312
- const classification = classifyError(error);
7313
- return classification.shouldRetry;
7314
- }
7315
- function getUserFriendlyMessage(error) {
7316
- const classification = classifyError(error);
7317
- return classification.userMessage;
7318
- }
7319
-
7320
- var MTLSErrorType;
7321
- (function (MTLSErrorType) {
7322
- MTLSErrorType["NOT_SUPPORTED"] = "MTLS_NOT_SUPPORTED";
7323
- MTLSErrorType["CERTIFICATE_NOT_FOUND"] = "MTLS_CERTIFICATE_NOT_FOUND";
7324
- MTLSErrorType["CERTIFICATE_EXPIRED"] = "MTLS_CERTIFICATE_EXPIRED";
7325
- MTLSErrorType["CERTIFICATE_INVALID"] = "MTLS_CERTIFICATE_INVALID";
7326
- MTLSErrorType["CONNECTION_FAILED"] = "MTLS_CONNECTION_FAILED";
7327
- MTLSErrorType["AUTHENTICATION_FAILED"] = "MTLS_AUTHENTICATION_FAILED";
7328
- MTLSErrorType["CONFIGURATION_ERROR"] = "MTLS_CONFIGURATION_ERROR";
7329
- })(MTLSErrorType || (MTLSErrorType = {}));
7330
- class PlatformDetector {
7331
- static detectPlatform() {
7332
- if ((typeof global !== 'undefined' && global.__expo) ||
7333
- (typeof navigator !== 'undefined' &&
7334
- navigator.product === 'ReactNative')) {
7335
- return 'react-native';
7336
- }
7337
- if (typeof process !== 'undefined' && process.versions?.node) {
7338
- return 'node';
7339
- }
7340
- return 'web';
7341
- }
7342
- static isReactNative() {
7343
- return this.detectPlatform() === 'react-native';
7344
- }
7345
- static isNode() {
7346
- return this.detectPlatform() === 'node';
7347
- }
7348
- static isWeb() {
7349
- return this.detectPlatform() === 'web';
7350
- }
7351
- static getPlatformDetails() {
7352
- const platform = this.detectPlatform();
7353
- return {
7354
- platform,
7355
- userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown',
7356
- nodeVersion: typeof process !== 'undefined' ? process.version : undefined,
7357
- isExpo: typeof global !== 'undefined' && !!global.__expo,
7358
- hasWindow: typeof window !== 'undefined',
7359
- hasDocument: typeof document !== 'undefined',
7360
- hasProcess: typeof process !== 'undefined',
7361
- };
7362
- }
7363
- }
7364
-
7365
6782
  exports.ACubeSDK = ACubeSDK;
7366
6783
  exports.ACubeSDKError = ACubeSDKError;
7367
- exports.ActivationRequestSchema = ActivationRequestSchema;
7368
6784
  exports.AddressMapper = AddressMapper;
7369
- exports.AddressSchema = AddressSchema;
7370
6785
  exports.AppStateService = AppStateService;
7371
- exports.AuthStrategy = AuthStrategy;
7372
6786
  exports.AuthenticationService = AuthenticationService;
7373
- exports.AxiosHttpAdapter = AxiosHttpAdapter;
7374
- exports.CashRegisterCreateSchema = CashRegisterCreateSchema;
7375
6787
  exports.CashRegisterMapper = CashRegisterMapper;
7376
- exports.CashRegisterRepositoryImpl = CashRegisterRepositoryImpl;
7377
- exports.CashierCreateInputSchema = CashierCreateInputSchema;
7378
6788
  exports.CashierMapper = CashierMapper;
7379
- exports.CashierRepositoryImpl = CashierRepositoryImpl;
7380
6789
  exports.CertificateService = CertificateService;
7381
6790
  exports.CertificateValidator = CertificateValidator;
7382
6791
  exports.ConfigManager = ConfigManager;
7383
6792
  exports.DAILY_REPORT_STATUS_OPTIONS = DAILY_REPORT_STATUS_OPTIONS;
7384
- exports.DIContainer = DIContainer;
7385
- exports.DI_TOKENS = DI_TOKENS;
7386
6793
  exports.DailyReportMapper = DailyReportMapper;
7387
- exports.DailyReportRepositoryImpl = DailyReportRepositoryImpl;
7388
- exports.DailyReportStatusSchema = DailyReportStatusSchema;
7389
- exports.DailyReportsParamsSchema = DailyReportsParamsSchema;
7390
6794
  exports.EXEMPT_VAT_CODES = EXEMPT_VAT_CODES;
7391
6795
  exports.GOOD_OR_SERVICE_OPTIONS = GOOD_OR_SERVICE_OPTIONS;
7392
6796
  exports.GoodOrServiceSchema = GoodOrServiceSchema;
7393
- exports.JournalCloseInputSchema = JournalCloseInputSchema;
7394
6797
  exports.JournalMapper = JournalMapper;
7395
- exports.JournalRepositoryImpl = JournalRepositoryImpl;
7396
- exports.JwtAuthHandler = JwtAuthHandler;
7397
- exports.LotterySchema = LotterySchema;
7398
- exports.LotterySecretRequestSchema = LotterySecretRequestSchema;
7399
6798
  exports.MTLSError = MTLSError;
7400
- exports.MerchantCreateInputSchema = MerchantCreateInputSchema;
7401
6799
  exports.MerchantMapper = MerchantMapper;
7402
- exports.MerchantRepositoryImpl = MerchantRepositoryImpl;
7403
- exports.MerchantUpdateInputSchema = MerchantUpdateInputSchema;
7404
- exports.MessageSchema = MessageSchema;
7405
- exports.MtlsAuthHandler = MtlsAuthHandler;
7406
6800
  exports.NOTIFICATION_CODES = NOTIFICATION_CODES;
7407
6801
  exports.NOTIFICATION_LEVELS = NOTIFICATION_LEVELS;
7408
6802
  exports.NOTIFICATION_SCOPES = NOTIFICATION_SCOPES;
7409
6803
  exports.NOTIFICATION_SOURCES = NOTIFICATION_SOURCES;
7410
6804
  exports.NOTIFICATION_TYPES = NOTIFICATION_TYPES;
7411
- exports.NotificationDataBlockAtSchema = NotificationDataBlockAtSchema;
7412
- exports.NotificationDataPemStatusSchema = NotificationDataPemStatusSchema;
7413
- exports.NotificationListResponseSchema = NotificationListResponseSchema;
7414
6805
  exports.NotificationMapper = NotificationMapper;
7415
- exports.NotificationMf2UnreachableSchema = NotificationMf2UnreachableSchema;
7416
- exports.NotificationPemBackOnlineSchema = NotificationPemBackOnlineSchema;
7417
- exports.NotificationPemsBlockedSchema = NotificationPemsBlockedSchema;
7418
- exports.NotificationRepositoryImpl = NotificationRepositoryImpl;
7419
- exports.NotificationSchema = NotificationSchema;
7420
- exports.NotificationScopeSchema = NotificationScopeSchema;
7421
6806
  exports.NotificationService = NotificationService;
7422
- exports.PEMStatusOfflineRequestSchema = PEMStatusOfflineRequestSchema;
7423
- exports.PEMStatusSchema = PEMStatusSchema;
7424
6807
  exports.PEM_STATUS_OPTIONS = PEM_STATUS_OPTIONS;
7425
6808
  exports.PEM_TYPE_OPTIONS = PEM_TYPE_OPTIONS;
7426
- exports.PemCreateInputSchema = PemCreateInputSchema;
7427
- exports.PemDataSchema = PemDataSchema;
7428
6809
  exports.PemMapper = PemMapper;
7429
- exports.PemRepositoryImpl = PemRepositoryImpl;
7430
- exports.PemStatusSchema = PemStatusSchema;
7431
- exports.PendingReceiptsSchema = PendingReceiptsSchema;
7432
- exports.PlatformDetector = PlatformDetector;
7433
6810
  exports.PointOfSaleMapper = PointOfSaleMapper;
7434
- exports.PointOfSaleRepositoryImpl = PointOfSaleRepositoryImpl;
7435
6811
  exports.RECEIPT_PROOF_TYPE_OPTIONS = RECEIPT_PROOF_TYPE_OPTIONS;
7436
6812
  exports.RECEIPT_READY = RECEIPT_READY;
7437
6813
  exports.RECEIPT_SENT = RECEIPT_SENT;
7438
6814
  exports.RECEIPT_SORT_ASCENDING = RECEIPT_SORT_ASCENDING;
7439
6815
  exports.RECEIPT_SORT_DESCENDING = RECEIPT_SORT_DESCENDING;
7440
- exports.ReceiptInputSchema = ReceiptInputSchema;
7441
- exports.ReceiptItemSchema = ReceiptItemSchema;
7442
6816
  exports.ReceiptMapper = ReceiptMapper;
7443
6817
  exports.ReceiptProofTypeSchema = ReceiptProofTypeSchema;
7444
- exports.ReceiptRepositoryImpl = ReceiptRepositoryImpl;
7445
- exports.ReceiptReturnInputSchema = ReceiptReturnInputSchema;
7446
- exports.ReceiptReturnItemSchema = ReceiptReturnItemSchema;
7447
- exports.ReceiptReturnOrVoidViaPEMInputSchema = ReceiptReturnOrVoidViaPEMInputSchema;
7448
- exports.ReceiptReturnOrVoidWithProofInputSchema = ReceiptReturnOrVoidWithProofInputSchema;
7449
- exports.SDKFactory = SDKFactory;
7450
6818
  exports.SDKManager = SDKManager;
7451
6819
  exports.STANDARD_VAT_RATES = STANDARD_VAT_RATES;
7452
- exports.SupplierCreateInputSchema = SupplierCreateInputSchema;
7453
6820
  exports.SupplierMapper = SupplierMapper;
7454
- exports.SupplierRepositoryImpl = SupplierRepositoryImpl;
7455
- exports.SupplierUpdateInputSchema = SupplierUpdateInputSchema;
7456
6821
  exports.TelemetryMapper = TelemetryMapper;
7457
- exports.TelemetryMerchantSchema = TelemetryMerchantSchema;
7458
- exports.TelemetryRepositoryImpl = TelemetryRepositoryImpl;
7459
- exports.TelemetrySchema = TelemetrySchema;
7460
6822
  exports.TelemetryService = TelemetryService;
7461
- exports.TelemetrySoftwareSchema = TelemetrySoftwareSchema;
7462
- exports.TelemetrySoftwareVersionSchema = TelemetrySoftwareVersionSchema;
7463
- exports.TelemetrySupplierSchema = TelemetrySupplierSchema;
7464
- exports.TransmissionSchema = TransmissionSchema;
7465
6823
  exports.VAT_RATE_CODES = VAT_RATE_CODES;
7466
6824
  exports.VAT_RATE_CODE_OPTIONS = VAT_RATE_CODE_OPTIONS;
7467
- exports.ValidationMessages = ValidationMessages;
7468
6825
  exports.VatRateCodeSchema = VatRateCodeSchema;
7469
- exports.VoidReceiptInputSchema = VoidReceiptInputSchema;
7470
- exports.classifyError = classifyError;
7471
- exports.clearObject = clearObject;
7472
- exports.clearObjectShallow = clearObjectShallow;
7473
6826
  exports.createACubeMTLSConfig = createACubeMTLSConfig;
7474
6827
  exports.createACubeSDK = createACubeSDK;
7475
6828
  exports.createPrefixedLogger = createPrefixedLogger;
7476
6829
  exports.default = createACubeSDK;
7477
- exports.detectPlatform = detectPlatform;
7478
6830
  exports.extractRoles = extractRoles;
7479
- exports.formatDecimal = formatDecimal;
7480
- exports.getUserFriendlyMessage = getUserFriendlyMessage;
7481
6831
  exports.hasAnyRole = hasAnyRole;
7482
- exports.hasNonEmptyValues = hasNonEmptyValues;
7483
6832
  exports.hasRole = hasRole;
7484
- exports.isEmpty = isEmpty;
7485
6833
  exports.isTokenExpired = isTokenExpired;
7486
6834
  exports.loadPlatformAdapters = loadPlatformAdapters;
7487
6835
  exports.logger = logger;
7488
6836
  exports.parseJwt = parseJwt;
7489
- exports.shouldReconfigureCertificate = shouldReconfigureCertificate;
7490
- exports.shouldRetryRequest = shouldRetryRequest;
7491
- exports.transformError = transformError;
7492
- exports.validateInput = validateInput;
7493
6837
  //# sourceMappingURL=index.cjs.js.map