@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 +17 -673
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +81 -1258
- package/dist/index.esm.js +41 -624
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.js +41 -624
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1869,27 +1869,6 @@ function clearObject(input) {
|
|
|
1869
1869
|
}
|
|
1870
1870
|
return input;
|
|
1871
1871
|
}
|
|
1872
|
-
function clearObjectShallow(obj) {
|
|
1873
|
-
if (!obj || typeof obj !== 'object') {
|
|
1874
|
-
return {};
|
|
1875
|
-
}
|
|
1876
|
-
const cleaned = {};
|
|
1877
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1878
|
-
if (value !== null && value !== undefined && value !== '') {
|
|
1879
|
-
cleaned[key] = value;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
return cleaned;
|
|
1883
|
-
}
|
|
1884
|
-
function isEmpty(value) {
|
|
1885
|
-
return value === null || value === undefined || value === '';
|
|
1886
|
-
}
|
|
1887
|
-
function hasNonEmptyValues(obj) {
|
|
1888
|
-
if (!obj || typeof obj !== 'object') {
|
|
1889
|
-
return false;
|
|
1890
|
-
}
|
|
1891
|
-
return Object.values(obj).some((value) => !isEmpty(value));
|
|
1892
|
-
}
|
|
1893
1872
|
|
|
1894
1873
|
/**
|
|
1895
1874
|
* Platform detection utilities
|
|
@@ -2446,7 +2425,7 @@ class ConfigManager {
|
|
|
2446
2425
|
}
|
|
2447
2426
|
}
|
|
2448
2427
|
|
|
2449
|
-
// Enum options arrays
|
|
2428
|
+
// Enum options arrays (used by consumers for dropdowns and form validation)
|
|
2450
2429
|
const VAT_RATE_CODE_OPTIONS = [
|
|
2451
2430
|
'4.00',
|
|
2452
2431
|
'5.00',
|
|
@@ -2473,103 +2452,10 @@ const VAT_RATE_CODE_OPTIONS = [
|
|
|
2473
2452
|
];
|
|
2474
2453
|
const GOOD_OR_SERVICE_OPTIONS = ['goods', 'service'];
|
|
2475
2454
|
const RECEIPT_PROOF_TYPE_OPTIONS = ['POS', 'VR', 'ND'];
|
|
2476
|
-
// Enum
|
|
2455
|
+
// Enum schemas (used by consumers as building blocks for their own form schemas)
|
|
2477
2456
|
const VatRateCodeSchema = z.enum(VAT_RATE_CODE_OPTIONS);
|
|
2478
2457
|
const GoodOrServiceSchema = z.enum(GOOD_OR_SERVICE_OPTIONS);
|
|
2479
2458
|
const ReceiptProofTypeSchema = z.enum(RECEIPT_PROOF_TYPE_OPTIONS);
|
|
2480
|
-
// Receipt Item Schema
|
|
2481
|
-
const ReceiptItemSchema = z.object({
|
|
2482
|
-
type: GoodOrServiceSchema.optional(),
|
|
2483
|
-
quantity: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2484
|
-
description: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2485
|
-
unit_price: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2486
|
-
vat_rate_code: VatRateCodeSchema.optional(),
|
|
2487
|
-
simplified_vat_allocation: z.boolean().optional(),
|
|
2488
|
-
discount: z.string().nullable().optional(),
|
|
2489
|
-
is_down_payment_or_voucher_redemption: z.boolean().optional(),
|
|
2490
|
-
complimentary: z.boolean().optional(),
|
|
2491
|
-
});
|
|
2492
|
-
// Main Receipt Input Schema
|
|
2493
|
-
const ReceiptInputSchema = z
|
|
2494
|
-
.object({
|
|
2495
|
-
items: z.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
|
|
2496
|
-
customer_tax_code: z.string().optional(),
|
|
2497
|
-
customer_lottery_code: z.string().optional(),
|
|
2498
|
-
discount: z.string().nullable().optional(),
|
|
2499
|
-
invoice_issuing: z.boolean().optional(),
|
|
2500
|
-
uncollected_dcr_to_ssn: z.boolean().optional(),
|
|
2501
|
-
services_uncollected_amount: z.string().nullable().optional(),
|
|
2502
|
-
goods_uncollected_amount: z.string().nullable().optional(),
|
|
2503
|
-
cash_payment_amount: z.string().nullable().optional(),
|
|
2504
|
-
electronic_payment_amount: z.string().nullable().optional(),
|
|
2505
|
-
ticket_restaurant_payment_amount: z.string().nullable().optional(),
|
|
2506
|
-
ticket_restaurant_quantity: z.number().optional(),
|
|
2507
|
-
})
|
|
2508
|
-
.refine((data) => {
|
|
2509
|
-
// At least one payment method should be provided
|
|
2510
|
-
const hasCashPayment = data.cash_payment_amount && parseFloat(data.cash_payment_amount) > 0;
|
|
2511
|
-
const hasElectronicPayment = data.electronic_payment_amount && parseFloat(data.electronic_payment_amount) > 0;
|
|
2512
|
-
const hasTicketPayment = data.ticket_restaurant_payment_amount &&
|
|
2513
|
-
parseFloat(data.ticket_restaurant_payment_amount) > 0;
|
|
2514
|
-
return hasCashPayment || hasElectronicPayment || hasTicketPayment;
|
|
2515
|
-
}, {
|
|
2516
|
-
error: 'At least one payment method is required',
|
|
2517
|
-
path: ['payment_methods'],
|
|
2518
|
-
})
|
|
2519
|
-
.refine((data) => {
|
|
2520
|
-
// only one between customer_tax_code and customer_lottery_code can be provided
|
|
2521
|
-
return !data.customer_tax_code || !data.customer_lottery_code;
|
|
2522
|
-
}, {
|
|
2523
|
-
error: 'Only one between customer_tax_code and customer_lottery_code can be provided',
|
|
2524
|
-
path: ['customer_tax_code', 'customer_lottery_code'],
|
|
2525
|
-
});
|
|
2526
|
-
// Receipt Return or Void via PEM Schema
|
|
2527
|
-
const ReceiptReturnOrVoidViaPEMInputSchema = z.object({
|
|
2528
|
-
device_id: z.string().optional(),
|
|
2529
|
-
items: z.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
|
|
2530
|
-
document_number: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2531
|
-
document_datetime: z.string().optional(),
|
|
2532
|
-
lottery_code: z.string().optional(),
|
|
2533
|
-
});
|
|
2534
|
-
// Receipt Return or Void with Proof Schema
|
|
2535
|
-
const ReceiptReturnOrVoidWithProofInputSchema = z.object({
|
|
2536
|
-
items: z.array(ReceiptItemSchema).min(1, { error: 'arrayMin1' }),
|
|
2537
|
-
proof: ReceiptProofTypeSchema,
|
|
2538
|
-
document_datetime: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2539
|
-
});
|
|
2540
|
-
// Void Receipt Schema
|
|
2541
|
-
const VoidReceiptInputSchema = z.object({
|
|
2542
|
-
document_number: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2543
|
-
});
|
|
2544
|
-
const ReceiptReturnItemSchema = z
|
|
2545
|
-
.array(z.object({
|
|
2546
|
-
id: z.number(),
|
|
2547
|
-
quantity: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2548
|
-
}))
|
|
2549
|
-
.min(1, { error: 'arrayMin1' });
|
|
2550
|
-
// Receipt Return Schema
|
|
2551
|
-
const ReceiptReturnInputSchema = z.object({
|
|
2552
|
-
items: z.array(ReceiptReturnItemSchema).min(1, { error: 'arrayMin1' }),
|
|
2553
|
-
document_number: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2554
|
-
});
|
|
2555
|
-
|
|
2556
|
-
// Cashier Create Input Schema (MF1)
|
|
2557
|
-
const CashierCreateInputSchema = z.object({
|
|
2558
|
-
email: z
|
|
2559
|
-
.string()
|
|
2560
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2561
|
-
.max(255, { error: 'emailMaxLength' })
|
|
2562
|
-
.email({ error: 'invalidEmail' }),
|
|
2563
|
-
password: z
|
|
2564
|
-
.string()
|
|
2565
|
-
.min(8, { error: 'passwordMinLength' })
|
|
2566
|
-
.max(40, { error: 'passwordMaxLength' }),
|
|
2567
|
-
name: z.string().min(1, { error: 'fieldIsRequired' }).max(255, { error: 'nameMaxLength' }),
|
|
2568
|
-
display_name: z
|
|
2569
|
-
.string()
|
|
2570
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2571
|
-
.max(255, { error: 'displayNameMaxLength' }),
|
|
2572
|
-
});
|
|
2573
2459
|
|
|
2574
2460
|
// Enum options arrays
|
|
2575
2461
|
const PEM_STATUS_OPTIONS = [
|
|
@@ -2580,312 +2466,12 @@ const PEM_STATUS_OPTIONS = [
|
|
|
2580
2466
|
'OFFLINE',
|
|
2581
2467
|
'DISCARDED',
|
|
2582
2468
|
];
|
|
2583
|
-
// Address Schema (reusable)
|
|
2584
|
-
const AddressSchema = z.object({
|
|
2585
|
-
street_address: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2586
|
-
street_number: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2587
|
-
zip_code: z
|
|
2588
|
-
.string()
|
|
2589
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2590
|
-
.regex(/^\d{5}$/, { error: 'invalidZipCode' }),
|
|
2591
|
-
city: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2592
|
-
province: z
|
|
2593
|
-
.string()
|
|
2594
|
-
.min(2, { error: 'provinceMinLength' })
|
|
2595
|
-
.max(2, { error: 'provinceMaxLength' })
|
|
2596
|
-
.toUpperCase(),
|
|
2597
|
-
});
|
|
2598
|
-
// PEM Status Schema
|
|
2599
|
-
const PEMStatusSchema = z.enum(PEM_STATUS_OPTIONS);
|
|
2600
|
-
// Activation Request Schema
|
|
2601
|
-
const ActivationRequestSchema = z.object({
|
|
2602
|
-
registration_key: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2603
|
-
});
|
|
2604
|
-
// PEM Status Offline Request Schema
|
|
2605
|
-
const PEMStatusOfflineRequestSchema = z.object({
|
|
2606
|
-
timestamp: z
|
|
2607
|
-
.string()
|
|
2608
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2609
|
-
.refine((val) => !isNaN(Date.parse(val)), {
|
|
2610
|
-
error: 'invalidDateFormat',
|
|
2611
|
-
}),
|
|
2612
|
-
reason: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2613
|
-
});
|
|
2614
|
-
|
|
2615
|
-
// Cash Register Create Schema
|
|
2616
|
-
const CashRegisterCreateSchema = z.object({
|
|
2617
|
-
pem_serial_number: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2618
|
-
name: z.string().min(1, { error: 'fieldIsRequired' }).max(100, { error: 'nameMaxLength' }),
|
|
2619
|
-
});
|
|
2620
|
-
|
|
2621
|
-
// VAT number validation regex (Partita IVA - 11 digits)
|
|
2622
|
-
const VAT_NUMBER_REGEX = /^\d{11}$/;
|
|
2623
|
-
// Fiscal code validation regex (Codice Fiscale - 11 digits only for merchants)
|
|
2624
|
-
const FISCAL_CODE_REGEX = /^\d{11}$/;
|
|
2625
|
-
// Password validation regex (from OpenAPI spec)
|
|
2626
|
-
const PASSWORD_REGEX = /^((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{10,}).*)$/;
|
|
2627
|
-
// Merchant Create Input Schema
|
|
2628
|
-
const MerchantCreateInputSchema = z
|
|
2629
|
-
.object({
|
|
2630
|
-
vat_number: z
|
|
2631
|
-
.string()
|
|
2632
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2633
|
-
.regex(VAT_NUMBER_REGEX, { error: 'invalidVatNumber' }),
|
|
2634
|
-
fiscal_code: z.string().regex(FISCAL_CODE_REGEX, { error: 'invalidFiscalCode' }).optional(),
|
|
2635
|
-
business_name: z.string().max(200, { error: 'businessNameMaxLength' }).optional().nullable(),
|
|
2636
|
-
first_name: z.string().max(100, { error: 'firstNameMaxLength' }).optional().nullable(),
|
|
2637
|
-
last_name: z.string().max(100, { error: 'lastNameMaxLength' }).optional().nullable(),
|
|
2638
|
-
email: z.string().min(1, { error: 'fieldIsRequired' }).email({ error: 'invalidEmail' }),
|
|
2639
|
-
password: z
|
|
2640
|
-
.string()
|
|
2641
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2642
|
-
.regex(PASSWORD_REGEX, { error: 'passwordComplexity' }),
|
|
2643
|
-
address: AddressSchema.optional(),
|
|
2644
|
-
})
|
|
2645
|
-
.refine((data) => {
|
|
2646
|
-
const hasBusinessName = data.business_name && data.business_name.trim() !== '';
|
|
2647
|
-
const hasPersonalNames = (data.first_name && data.first_name.trim() !== '') ||
|
|
2648
|
-
(data.last_name && data.last_name.trim() !== '');
|
|
2649
|
-
// If business name is set, first/last name must not be provided
|
|
2650
|
-
if (hasBusinessName && hasPersonalNames) {
|
|
2651
|
-
return false;
|
|
2652
|
-
}
|
|
2653
|
-
// At least one naming method must be provided
|
|
2654
|
-
if (!hasBusinessName && !hasPersonalNames) {
|
|
2655
|
-
return false;
|
|
2656
|
-
}
|
|
2657
|
-
return true;
|
|
2658
|
-
}, {
|
|
2659
|
-
error: 'businessNameOrPersonalNamesRequired',
|
|
2660
|
-
path: ['business_name'],
|
|
2661
|
-
});
|
|
2662
|
-
// Merchant Update Input Schema
|
|
2663
|
-
const MerchantUpdateInputSchema = z.object({
|
|
2664
|
-
business_name: z.string().max(200, { error: 'businessNameMaxLength' }).optional().nullable(),
|
|
2665
|
-
first_name: z.string().max(100, { error: 'firstNameMaxLength' }).optional().nullable(),
|
|
2666
|
-
last_name: z.string().max(100, { error: 'lastNameMaxLength' }).optional().nullable(),
|
|
2667
|
-
address: AddressSchema.optional().nullable(),
|
|
2668
|
-
});
|
|
2669
2469
|
|
|
2670
2470
|
// Enum options arrays
|
|
2671
2471
|
const PEM_TYPE_OPTIONS = ['AP', 'SP', 'TM', 'PV'];
|
|
2672
|
-
// PEM Data Schema
|
|
2673
|
-
const PemDataSchema = z.object({
|
|
2674
|
-
version: z.string().min(1, { error: 'fieldIsRequired' }),
|
|
2675
|
-
type: z.enum(PEM_TYPE_OPTIONS, {
|
|
2676
|
-
error: 'invalidPemType',
|
|
2677
|
-
}),
|
|
2678
|
-
});
|
|
2679
|
-
// PEM Create Input Schema
|
|
2680
|
-
const PemCreateInputSchema = z.object({
|
|
2681
|
-
merchant_uuid: z.string().min(1, { error: 'fieldIsRequired' }).uuid({ error: 'invalidUuid' }),
|
|
2682
|
-
address: AddressSchema.optional(),
|
|
2683
|
-
/* external_pem_data: PemDataSchema.optional(), */
|
|
2684
|
-
});
|
|
2685
|
-
|
|
2686
|
-
// Italian Fiscal ID validation regex (Codice Fiscale for individuals or Partita IVA for companies)
|
|
2687
|
-
const FISCAL_ID_REGEX = /^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST][0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{3}[A-Z]|[0-9]{11})$/;
|
|
2688
|
-
// Supplier Create Input Schema
|
|
2689
|
-
const SupplierCreateInputSchema = z.object({
|
|
2690
|
-
fiscal_id: z
|
|
2691
|
-
.string()
|
|
2692
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2693
|
-
.regex(FISCAL_ID_REGEX, { error: 'invalidFiscalId' })
|
|
2694
|
-
.toUpperCase(),
|
|
2695
|
-
name: z.string().min(1, { error: 'fieldIsRequired' }).max(200, { error: 'nameMaxLength' }),
|
|
2696
|
-
address: AddressSchema.optional(),
|
|
2697
|
-
});
|
|
2698
|
-
// Supplier Update Input Schema
|
|
2699
|
-
const SupplierUpdateInputSchema = z.object({
|
|
2700
|
-
name: z.string().min(1, { error: 'fieldIsRequired' }).max(200, { error: 'nameMaxLength' }),
|
|
2701
|
-
address: AddressSchema.optional(),
|
|
2702
|
-
});
|
|
2703
2472
|
|
|
2704
|
-
//
|
|
2705
|
-
const JournalCloseInputSchema = z.object({
|
|
2706
|
-
closing_timestamp: z
|
|
2707
|
-
.string()
|
|
2708
|
-
.min(1, { error: 'fieldIsRequired' })
|
|
2709
|
-
.refine((val) => !isNaN(Date.parse(val)), {
|
|
2710
|
-
error: 'invalidDateFormat',
|
|
2711
|
-
}),
|
|
2712
|
-
reason: z.string().max(255, { error: 'reasonMaxLength' }).optional(),
|
|
2713
|
-
});
|
|
2714
|
-
|
|
2715
|
-
// Daily Report Status Options
|
|
2473
|
+
// Enum options arrays
|
|
2716
2474
|
const DAILY_REPORT_STATUS_OPTIONS = ['pending', 'sent', 'error'];
|
|
2717
|
-
// Daily Report Status Schema
|
|
2718
|
-
const DailyReportStatusSchema = z.enum(DAILY_REPORT_STATUS_OPTIONS, {
|
|
2719
|
-
error: 'invalidDailyReportStatus',
|
|
2720
|
-
});
|
|
2721
|
-
// Daily Reports List Parameters Schema
|
|
2722
|
-
const DailyReportsParamsSchema = z.object({
|
|
2723
|
-
pem_serial_number: z.string().min(1, { error: 'fieldIsRequired' }).optional(),
|
|
2724
|
-
date_from: z
|
|
2725
|
-
.string()
|
|
2726
|
-
.refine((val) => !isNaN(Date.parse(val)), {
|
|
2727
|
-
error: 'invalidDateFormat',
|
|
2728
|
-
})
|
|
2729
|
-
.optional(),
|
|
2730
|
-
date_to: z
|
|
2731
|
-
.string()
|
|
2732
|
-
.refine((val) => !isNaN(Date.parse(val)), {
|
|
2733
|
-
error: 'invalidDateFormat',
|
|
2734
|
-
})
|
|
2735
|
-
.optional(),
|
|
2736
|
-
status: DailyReportStatusSchema.optional(),
|
|
2737
|
-
page: z.number().min(1, { error: 'pageMinValue' }).optional(),
|
|
2738
|
-
});
|
|
2739
|
-
|
|
2740
|
-
const NotificationScopeSchema = z.object({
|
|
2741
|
-
type: z.literal('global'),
|
|
2742
|
-
});
|
|
2743
|
-
const PemStatusSchema = z.enum(['ONLINE', 'OFFLINE']);
|
|
2744
|
-
const NotificationDataBlockAtSchema = z.object({
|
|
2745
|
-
block_at: z.string(),
|
|
2746
|
-
});
|
|
2747
|
-
const NotificationDataPemStatusSchema = z.object({
|
|
2748
|
-
from: PemStatusSchema,
|
|
2749
|
-
to: PemStatusSchema,
|
|
2750
|
-
});
|
|
2751
|
-
const NotificationBaseSchema = z.object({
|
|
2752
|
-
uuid: z.string().uuid({ error: 'invalidUuid' }),
|
|
2753
|
-
scope: NotificationScopeSchema,
|
|
2754
|
-
source: z.enum(['system', 'Italian Tax Authority']),
|
|
2755
|
-
level: z.enum(['info', 'warning', 'error', 'critical']),
|
|
2756
|
-
created_at: z.string(),
|
|
2757
|
-
});
|
|
2758
|
-
const NotificationMf2UnreachableSchema = NotificationBaseSchema.extend({
|
|
2759
|
-
type: z.literal('INTERNAL_COMMUNICATION_FAILURE'),
|
|
2760
|
-
code: z.literal('SYS-W-01'),
|
|
2761
|
-
data: NotificationDataBlockAtSchema,
|
|
2762
|
-
});
|
|
2763
|
-
const NotificationPemsBlockedSchema = NotificationBaseSchema.extend({
|
|
2764
|
-
type: z.literal('PEM_STATUS_CHANGED'),
|
|
2765
|
-
code: z.literal('SYS-C-01'),
|
|
2766
|
-
data: NotificationDataPemStatusSchema,
|
|
2767
|
-
});
|
|
2768
|
-
const NotificationPemBackOnlineSchema = NotificationBaseSchema.extend({
|
|
2769
|
-
type: z.literal('PEM_STATUS_CHANGED'),
|
|
2770
|
-
code: z.literal('SYS-I-01'),
|
|
2771
|
-
data: NotificationDataPemStatusSchema,
|
|
2772
|
-
});
|
|
2773
|
-
const NotificationSchema = z.discriminatedUnion('code', [
|
|
2774
|
-
NotificationMf2UnreachableSchema,
|
|
2775
|
-
NotificationPemsBlockedSchema,
|
|
2776
|
-
NotificationPemBackOnlineSchema,
|
|
2777
|
-
]);
|
|
2778
|
-
const NotificationListResponseSchema = z.object({
|
|
2779
|
-
members: z.array(NotificationSchema),
|
|
2780
|
-
});
|
|
2781
|
-
|
|
2782
|
-
const TelemetryMerchantSchema = z.object({
|
|
2783
|
-
vat_number: z.string(),
|
|
2784
|
-
fiscal_code: z.string().nullable(),
|
|
2785
|
-
business_name: z.string(),
|
|
2786
|
-
});
|
|
2787
|
-
const TelemetrySupplierSchema = z.object({
|
|
2788
|
-
vat_number: z.string(),
|
|
2789
|
-
fiscal_code: z.string().nullable(),
|
|
2790
|
-
business_name: z.string(),
|
|
2791
|
-
});
|
|
2792
|
-
const TelemetrySoftwareVersionSchema = z.object({
|
|
2793
|
-
version: z.string(),
|
|
2794
|
-
swid: z.string(),
|
|
2795
|
-
installed_at: z.string(),
|
|
2796
|
-
status: z.enum(['active', 'inactive', 'archived']),
|
|
2797
|
-
});
|
|
2798
|
-
const TelemetrySoftwareSchema = z.object({
|
|
2799
|
-
code: z.string(),
|
|
2800
|
-
name: z.string(),
|
|
2801
|
-
approval_reference: z.string(),
|
|
2802
|
-
version_info: TelemetrySoftwareVersionSchema,
|
|
2803
|
-
});
|
|
2804
|
-
const PendingReceiptsSchema = z.object({
|
|
2805
|
-
count: z.number().int().nonnegative(),
|
|
2806
|
-
total_amount: z.string(),
|
|
2807
|
-
});
|
|
2808
|
-
const TransmissionSchema = z.object({
|
|
2809
|
-
attempted_at: z.string(),
|
|
2810
|
-
outcome: z.enum(['success', 'failed', 'pending']),
|
|
2811
|
-
});
|
|
2812
|
-
const MessageSchema = z.object({
|
|
2813
|
-
received_at: z.string(),
|
|
2814
|
-
content: z.string(),
|
|
2815
|
-
});
|
|
2816
|
-
const LotterySecretRequestSchema = z.object({
|
|
2817
|
-
requested_at: z.string(),
|
|
2818
|
-
outcome: z.enum(['success', 'failed', 'pending']),
|
|
2819
|
-
});
|
|
2820
|
-
const LotterySchema = z.object({
|
|
2821
|
-
last_transmission: TransmissionSchema,
|
|
2822
|
-
secret_request: LotterySecretRequestSchema,
|
|
2823
|
-
});
|
|
2824
|
-
const TelemetrySchema = z.object({
|
|
2825
|
-
pem_id: z.string(),
|
|
2826
|
-
pem_status: z.enum(['ONLINE', 'OFFLINE', 'ERROR']),
|
|
2827
|
-
pem_status_changed_at: z.string(),
|
|
2828
|
-
merchant: TelemetryMerchantSchema,
|
|
2829
|
-
supplier: TelemetrySupplierSchema,
|
|
2830
|
-
software: TelemetrySoftwareSchema,
|
|
2831
|
-
last_communication_at: z.string(),
|
|
2832
|
-
pending_receipts: PendingReceiptsSchema,
|
|
2833
|
-
last_receipt_transmission: TransmissionSchema,
|
|
2834
|
-
last_message_from_mf2: MessageSchema,
|
|
2835
|
-
ade_corrispettivi_transmission: TransmissionSchema,
|
|
2836
|
-
last_message_from_ade: MessageSchema,
|
|
2837
|
-
lottery: LotterySchema,
|
|
2838
|
-
});
|
|
2839
|
-
|
|
2840
|
-
// Receipt schemas and types
|
|
2841
|
-
// Common validation utilities
|
|
2842
|
-
const ValidationMessages = {
|
|
2843
|
-
fieldIsRequired: 'This field is required',
|
|
2844
|
-
arrayMin1: 'At least one item is required',
|
|
2845
|
-
paymentMethodRequired: 'At least one payment method is required',
|
|
2846
|
-
invalidEmail: 'Please enter a valid email address',
|
|
2847
|
-
passwordMinLength: 'Password must be at least 8 characters long',
|
|
2848
|
-
passwordComplexity: 'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
|
|
2849
|
-
invalidZipCode: 'Please enter a valid 5-digit zip code',
|
|
2850
|
-
provinceMinLength: 'Province code must be 2 characters',
|
|
2851
|
-
provinceMaxLength: 'Province code must be 2 characters',
|
|
2852
|
-
invalidDateFormat: 'Please enter a valid date',
|
|
2853
|
-
nameMaxLength: 'Name is too long',
|
|
2854
|
-
invalidFiscalId: 'Please enter a valid Italian fiscal ID (Codice Fiscale or Partita IVA)',
|
|
2855
|
-
invalidVatNumber: 'Please enter a valid VAT number (11 digits)',
|
|
2856
|
-
invalidFiscalCode: 'Please enter a valid fiscal code (11 digits)',
|
|
2857
|
-
businessNameMaxLength: 'Business name is too long (max 200 characters)',
|
|
2858
|
-
businessNameOrPersonalNamesRequired: 'Please provide either a business name or first/last name, but not both',
|
|
2859
|
-
firstNameMaxLength: 'First name is too long (max 100 characters)',
|
|
2860
|
-
lastNameMaxLength: 'Last name is too long (max 100 characters)',
|
|
2861
|
-
invalidUuid: 'Please enter a valid UUID',
|
|
2862
|
-
invalidPemType: 'PEM type must be one of: AP, SP, TM, PV',
|
|
2863
|
-
reasonMaxLength: 'Reason is too long (max 255 characters)',
|
|
2864
|
-
pageMinValue: 'Page number must be at least 1',
|
|
2865
|
-
invalidDailyReportStatus: 'Daily report status must be one of: pending, sent, error',
|
|
2866
|
-
displayNameMaxLength: 'Display name is too long (max 255 characters)',
|
|
2867
|
-
};
|
|
2868
|
-
// Validation helper functions
|
|
2869
|
-
const validateInput = (schema, data) => {
|
|
2870
|
-
const result = schema.safeParse(data);
|
|
2871
|
-
if (!result.success) {
|
|
2872
|
-
const errors = result.error.issues.map((error) => ({
|
|
2873
|
-
field: error.path.join('.'),
|
|
2874
|
-
message: error.message,
|
|
2875
|
-
code: error.code,
|
|
2876
|
-
}));
|
|
2877
|
-
return {
|
|
2878
|
-
success: false,
|
|
2879
|
-
errors,
|
|
2880
|
-
data: null,
|
|
2881
|
-
};
|
|
2882
|
-
}
|
|
2883
|
-
return {
|
|
2884
|
-
success: true,
|
|
2885
|
-
errors: [],
|
|
2886
|
-
data: result.data,
|
|
2887
|
-
};
|
|
2888
|
-
};
|
|
2889
2475
|
|
|
2890
2476
|
class ACubeSDKError extends Error {
|
|
2891
2477
|
constructor(type, message, originalError, statusCode, violations) {
|
|
@@ -2924,6 +2510,14 @@ class AuthStrategy {
|
|
|
2924
2510
|
if (userRole === 'SUPPLIER') {
|
|
2925
2511
|
return { mode: 'jwt', usePort444: false };
|
|
2926
2512
|
}
|
|
2513
|
+
if (url.includes('/download-data')) {
|
|
2514
|
+
if (platform === 'mobile') {
|
|
2515
|
+
return { mode: 'mtls', usePort444: true };
|
|
2516
|
+
}
|
|
2517
|
+
else {
|
|
2518
|
+
return { mode: 'jwt', usePort444: true };
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2927
2521
|
if (userRole === 'CASHIER') {
|
|
2928
2522
|
if (!isReceiptEndpoint) {
|
|
2929
2523
|
return { mode: 'jwt', usePort444: false };
|
|
@@ -3260,11 +2854,6 @@ class MtlsAuthHandler {
|
|
|
3260
2854
|
}
|
|
3261
2855
|
}
|
|
3262
2856
|
|
|
3263
|
-
/**
|
|
3264
|
-
* Mixin that adds multiGet, multiSet, multiRemove to any storage adapter
|
|
3265
|
-
* Eliminates duplicate code across Node, Web, and React Native adapters
|
|
3266
|
-
*/
|
|
3267
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3268
2857
|
/**
|
|
3269
2858
|
* Abstract base class for standard storage adapters
|
|
3270
2859
|
* Implements multi-operations, subclasses implement core operations
|
|
@@ -4038,7 +3627,7 @@ function loadNetworkMonitor(platform) {
|
|
|
4038
3627
|
}
|
|
4039
3628
|
}
|
|
4040
3629
|
|
|
4041
|
-
var MTLSErrorType
|
|
3630
|
+
var MTLSErrorType;
|
|
4042
3631
|
(function (MTLSErrorType) {
|
|
4043
3632
|
MTLSErrorType["NOT_SUPPORTED"] = "MTLS_NOT_SUPPORTED";
|
|
4044
3633
|
MTLSErrorType["CERTIFICATE_NOT_FOUND"] = "MTLS_CERTIFICATE_NOT_FOUND";
|
|
@@ -4047,7 +3636,7 @@ var MTLSErrorType$1;
|
|
|
4047
3636
|
MTLSErrorType["CONNECTION_FAILED"] = "MTLS_CONNECTION_FAILED";
|
|
4048
3637
|
MTLSErrorType["AUTHENTICATION_FAILED"] = "MTLS_AUTHENTICATION_FAILED";
|
|
4049
3638
|
MTLSErrorType["CONFIGURATION_ERROR"] = "MTLS_CONFIGURATION_ERROR";
|
|
4050
|
-
})(MTLSErrorType
|
|
3639
|
+
})(MTLSErrorType || (MTLSErrorType = {}));
|
|
4051
3640
|
class MTLSError extends Error {
|
|
4052
3641
|
constructor(type, message, originalError, statusCode) {
|
|
4053
3642
|
super(message);
|
|
@@ -4136,7 +3725,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4136
3725
|
}
|
|
4137
3726
|
async initialize(config) {
|
|
4138
3727
|
if (!this.expoMTLS) {
|
|
4139
|
-
throw new MTLSError(MTLSErrorType
|
|
3728
|
+
throw new MTLSError(MTLSErrorType.NOT_SUPPORTED, 'Expo mTLS module not available');
|
|
4140
3729
|
}
|
|
4141
3730
|
this.config = config;
|
|
4142
3731
|
log$5.debug('Initialized with config:', {
|
|
@@ -4148,10 +3737,10 @@ class ReactNativeMTLSAdapter {
|
|
|
4148
3737
|
}
|
|
4149
3738
|
async configureCertificate(certificateData) {
|
|
4150
3739
|
if (!this.expoMTLS) {
|
|
4151
|
-
throw new MTLSError(MTLSErrorType
|
|
3740
|
+
throw new MTLSError(MTLSErrorType.NOT_SUPPORTED, 'Expo mTLS module not available');
|
|
4152
3741
|
}
|
|
4153
3742
|
if (!this.config) {
|
|
4154
|
-
throw new MTLSError(MTLSErrorType
|
|
3743
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, 'Adapter not initialized. Call initialize() first.');
|
|
4155
3744
|
}
|
|
4156
3745
|
log$5.debug('Configuring certificate:', {
|
|
4157
3746
|
format: certificateData.format,
|
|
@@ -4163,7 +3752,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4163
3752
|
if (certificateData.format === 'PEM') {
|
|
4164
3753
|
// Validate PEM format
|
|
4165
3754
|
if (!CertificateValidator.validatePEMFormat(certificateData.certificate, certificateData.privateKey)) {
|
|
4166
|
-
throw new MTLSError(MTLSErrorType
|
|
3755
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, 'Invalid PEM certificate format');
|
|
4167
3756
|
}
|
|
4168
3757
|
// Step 1: Configure PEM services (optional parameters for keychain services)
|
|
4169
3758
|
const configResult = await this.expoMTLS.configurePEM('client-cert-service', // certService
|
|
@@ -4172,19 +3761,19 @@ class ReactNativeMTLSAdapter {
|
|
|
4172
3761
|
);
|
|
4173
3762
|
log$5.debug('PEM services configured:', configResult);
|
|
4174
3763
|
if (!configResult.success) {
|
|
4175
|
-
throw new MTLSError(MTLSErrorType
|
|
3764
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, `PEM configuration failed: ${configResult.state}`);
|
|
4176
3765
|
}
|
|
4177
3766
|
// Step 2: Store the actual PEM certificate and private key
|
|
4178
3767
|
const storeResult = await this.expoMTLS.storePEM(certificateData.certificate, certificateData.privateKey, certificateData.password // passphrase (optional)
|
|
4179
3768
|
);
|
|
4180
3769
|
log$5.debug('PEM certificate store result:', storeResult);
|
|
4181
3770
|
if (!storeResult) {
|
|
4182
|
-
throw new MTLSError(MTLSErrorType
|
|
3771
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, 'Failed to store PEM certificate');
|
|
4183
3772
|
}
|
|
4184
3773
|
}
|
|
4185
3774
|
else if (certificateData.format === 'P12') {
|
|
4186
3775
|
if (!certificateData.password) {
|
|
4187
|
-
throw new MTLSError(MTLSErrorType
|
|
3776
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, 'P12 certificate requires password');
|
|
4188
3777
|
}
|
|
4189
3778
|
// Step 1: Configure P12 keychain service
|
|
4190
3779
|
const configResult = await this.expoMTLS.configureP12('client-p12-service', // keychainService
|
|
@@ -4192,18 +3781,18 @@ class ReactNativeMTLSAdapter {
|
|
|
4192
3781
|
);
|
|
4193
3782
|
log$5.debug('P12 service configured:', configResult);
|
|
4194
3783
|
if (!configResult.success) {
|
|
4195
|
-
throw new MTLSError(MTLSErrorType
|
|
3784
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, `P12 configuration failed: ${configResult.state}`);
|
|
4196
3785
|
}
|
|
4197
3786
|
// Step 2: Store the P12 certificate data
|
|
4198
3787
|
const storeResult = await this.expoMTLS.storeP12(certificateData.certificate, // P12 data in certificate field
|
|
4199
3788
|
certificateData.password);
|
|
4200
3789
|
log$5.debug('P12 certificate store result:', storeResult);
|
|
4201
3790
|
if (!storeResult) {
|
|
4202
|
-
throw new MTLSError(MTLSErrorType
|
|
3791
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, 'Failed to store P12 certificate');
|
|
4203
3792
|
}
|
|
4204
3793
|
}
|
|
4205
3794
|
else {
|
|
4206
|
-
throw new MTLSError(MTLSErrorType
|
|
3795
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, `Unsupported certificate format: ${certificateData.format}`);
|
|
4207
3796
|
}
|
|
4208
3797
|
this.isConfigured = true;
|
|
4209
3798
|
}
|
|
@@ -4212,7 +3801,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4212
3801
|
throw error;
|
|
4213
3802
|
}
|
|
4214
3803
|
log$5.error('Certificate configuration failed:', error);
|
|
4215
|
-
throw new MTLSError(MTLSErrorType
|
|
3804
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, 'Failed to configure certificate', error);
|
|
4216
3805
|
}
|
|
4217
3806
|
}
|
|
4218
3807
|
async hasCertificate() {
|
|
@@ -4290,7 +3879,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4290
3879
|
let result;
|
|
4291
3880
|
if (certificateData.format === 'P12') {
|
|
4292
3881
|
if (!certificateData.password) {
|
|
4293
|
-
throw new MTLSError(MTLSErrorType
|
|
3882
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, 'P12 certificate requires password for parsing');
|
|
4294
3883
|
}
|
|
4295
3884
|
result = await this.expoMTLS.parseCertificateP12(certificateData.certificate, certificateData.password);
|
|
4296
3885
|
}
|
|
@@ -4298,7 +3887,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4298
3887
|
result = await this.expoMTLS.parseCertificatePEM(certificateData.certificate);
|
|
4299
3888
|
}
|
|
4300
3889
|
else {
|
|
4301
|
-
throw new MTLSError(MTLSErrorType
|
|
3890
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, `Unsupported certificate format: ${certificateData.format}`);
|
|
4302
3891
|
}
|
|
4303
3892
|
log$5.debug('Certificate parsed successfully:', {
|
|
4304
3893
|
certificateCount: result.certificates.length,
|
|
@@ -4311,16 +3900,16 @@ class ReactNativeMTLSAdapter {
|
|
|
4311
3900
|
if (error instanceof MTLSError) {
|
|
4312
3901
|
throw error;
|
|
4313
3902
|
}
|
|
4314
|
-
throw new MTLSError(MTLSErrorType
|
|
3903
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_INVALID, 'Failed to parse certificate data', error);
|
|
4315
3904
|
}
|
|
4316
3905
|
}
|
|
4317
3906
|
async request(requestConfig) {
|
|
4318
3907
|
if (!this.expoMTLS) {
|
|
4319
|
-
throw new MTLSError(MTLSErrorType
|
|
3908
|
+
throw new MTLSError(MTLSErrorType.NOT_SUPPORTED, 'Expo mTLS module not available');
|
|
4320
3909
|
}
|
|
4321
3910
|
const hasCert = await this.hasCertificate();
|
|
4322
3911
|
if (!hasCert) {
|
|
4323
|
-
throw new MTLSError(MTLSErrorType
|
|
3912
|
+
throw new MTLSError(MTLSErrorType.CERTIFICATE_NOT_FOUND, 'No certificate configured');
|
|
4324
3913
|
}
|
|
4325
3914
|
log$5.debug('Making mTLS request:', {
|
|
4326
3915
|
method: requestConfig.method || 'GET',
|
|
@@ -4341,7 +3930,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4341
3930
|
});
|
|
4342
3931
|
log$5.debug('mTLS request successful:', response);
|
|
4343
3932
|
if (!response.success) {
|
|
4344
|
-
throw new MTLSError(MTLSErrorType
|
|
3933
|
+
throw new MTLSError(MTLSErrorType.CONNECTION_FAILED, `mTLS request failed: ${response.statusMessage} (${response.statusCode})`, undefined, response.statusCode);
|
|
4345
3934
|
}
|
|
4346
3935
|
let data = response.body;
|
|
4347
3936
|
// only parse if responseType is 'json' or if Content-Type header indicates JSON
|
|
@@ -4369,7 +3958,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4369
3958
|
}
|
|
4370
3959
|
catch (error) {
|
|
4371
3960
|
log$5.error('mTLS request failed:', error);
|
|
4372
|
-
throw new MTLSError(MTLSErrorType
|
|
3961
|
+
throw new MTLSError(MTLSErrorType.CONNECTION_FAILED, 'mTLS request failed', error);
|
|
4373
3962
|
}
|
|
4374
3963
|
}
|
|
4375
3964
|
/**
|
|
@@ -4422,7 +4011,7 @@ class ReactNativeMTLSAdapter {
|
|
|
4422
4011
|
}
|
|
4423
4012
|
catch (error) {
|
|
4424
4013
|
log$5.error('Failed to remove certificate:', error);
|
|
4425
|
-
throw new MTLSError(MTLSErrorType
|
|
4014
|
+
throw new MTLSError(MTLSErrorType.CONFIGURATION_ERROR, 'Failed to remove certificate', error);
|
|
4426
4015
|
}
|
|
4427
4016
|
}
|
|
4428
4017
|
/**
|
|
@@ -4512,7 +4101,7 @@ class WebMTLSAdapter {
|
|
|
4512
4101
|
'Configure server-side proxy for certificate handling',
|
|
4513
4102
|
],
|
|
4514
4103
|
});
|
|
4515
|
-
throw new MTLSError(MTLSErrorType
|
|
4104
|
+
throw new MTLSError(MTLSErrorType.NOT_SUPPORTED, 'mTLS client certificate configuration is not supported in web browsers. ' +
|
|
4516
4105
|
'Web browsers manage client certificates through the browser certificate store. ' +
|
|
4517
4106
|
'Please use JWT authentication or import certificates manually into your browser.');
|
|
4518
4107
|
}
|
|
@@ -4536,7 +4125,7 @@ class WebMTLSAdapter {
|
|
|
4536
4125
|
'Rely on browser-managed certificates (if configured by user)',
|
|
4537
4126
|
],
|
|
4538
4127
|
});
|
|
4539
|
-
throw new MTLSError(MTLSErrorType
|
|
4128
|
+
throw new MTLSError(MTLSErrorType.NOT_SUPPORTED, 'mTLS requests are not supported in web browsers via JavaScript. ' +
|
|
4540
4129
|
'Use standard HTTP client with JWT authentication, or ensure client certificates ' +
|
|
4541
4130
|
'are properly configured in the browser certificate store.');
|
|
4542
4131
|
}
|
|
@@ -5358,6 +4947,12 @@ class PemRepositoryImpl {
|
|
|
5358
4947
|
const response = await this.http.get(`/mf2/pems/${serialNumber}/certificates`);
|
|
5359
4948
|
return PemMapper.fromCertificatesApiOutput(response.data);
|
|
5360
4949
|
}
|
|
4950
|
+
async downloadData(serialNumber) {
|
|
4951
|
+
const response = await this.http.get(`/mf1/pems/${serialNumber}/download-data`, {
|
|
4952
|
+
responseType: 'arraybuffer',
|
|
4953
|
+
});
|
|
4954
|
+
return response.data;
|
|
4955
|
+
}
|
|
5361
4956
|
}
|
|
5362
4957
|
|
|
5363
4958
|
class DailyReportMapper {
|
|
@@ -7161,183 +6756,5 @@ const RECEIPT_SENT = 'sent';
|
|
|
7161
6756
|
const RECEIPT_SORT_DESCENDING = 'descending';
|
|
7162
6757
|
const RECEIPT_SORT_ASCENDING = 'ascending';
|
|
7163
6758
|
|
|
7164
|
-
|
|
7165
|
-
if (axios.isAxiosError(error)) {
|
|
7166
|
-
const response = error.response;
|
|
7167
|
-
if (!response) {
|
|
7168
|
-
return new ACubeSDKError('NETWORK_ERROR', 'Network error occurred', error);
|
|
7169
|
-
}
|
|
7170
|
-
const status = response.status;
|
|
7171
|
-
const data = response.data;
|
|
7172
|
-
const violations = data?.violations;
|
|
7173
|
-
let message = 'Unknown error occurred';
|
|
7174
|
-
if (data?.detail) {
|
|
7175
|
-
message = data.detail;
|
|
7176
|
-
}
|
|
7177
|
-
else if (data?.title) {
|
|
7178
|
-
message = data.title;
|
|
7179
|
-
}
|
|
7180
|
-
else if (error.message) {
|
|
7181
|
-
message = error.message;
|
|
7182
|
-
}
|
|
7183
|
-
switch (status) {
|
|
7184
|
-
case 400:
|
|
7185
|
-
return new ACubeSDKError('VALIDATION_ERROR', message, error, status, violations);
|
|
7186
|
-
case 401:
|
|
7187
|
-
return new ACubeSDKError('AUTH_ERROR', message, error, status, violations);
|
|
7188
|
-
case 403:
|
|
7189
|
-
return new ACubeSDKError('FORBIDDEN_ERROR', message, error, status, violations);
|
|
7190
|
-
case 404:
|
|
7191
|
-
return new ACubeSDKError('NOT_FOUND_ERROR', message, error, status, violations);
|
|
7192
|
-
case 422:
|
|
7193
|
-
return new ACubeSDKError('VALIDATION_ERROR', message, error, status, violations);
|
|
7194
|
-
default:
|
|
7195
|
-
return new ACubeSDKError('UNKNOWN_ERROR', message, error, status, violations);
|
|
7196
|
-
}
|
|
7197
|
-
}
|
|
7198
|
-
return new ACubeSDKError('UNKNOWN_ERROR', 'Unknown error occurred', error);
|
|
7199
|
-
}
|
|
7200
|
-
|
|
7201
|
-
var ErrorCategory;
|
|
7202
|
-
(function (ErrorCategory) {
|
|
7203
|
-
ErrorCategory["SERVER_ERROR"] = "SERVER_ERROR";
|
|
7204
|
-
ErrorCategory["CLIENT_ERROR"] = "CLIENT_ERROR";
|
|
7205
|
-
ErrorCategory["AUTH_ERROR"] = "AUTH_ERROR";
|
|
7206
|
-
ErrorCategory["CERTIFICATE_ERROR"] = "CERTIFICATE_ERROR";
|
|
7207
|
-
ErrorCategory["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
7208
|
-
ErrorCategory["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
7209
|
-
})(ErrorCategory || (ErrorCategory = {}));
|
|
7210
|
-
function extractStatusCode(error) {
|
|
7211
|
-
if (error instanceof MTLSError && error.statusCode) {
|
|
7212
|
-
return error.statusCode;
|
|
7213
|
-
}
|
|
7214
|
-
const errorObj = error;
|
|
7215
|
-
if (errorObj?.response?.status) {
|
|
7216
|
-
return errorObj.response.status;
|
|
7217
|
-
}
|
|
7218
|
-
if (typeof errorObj?.statusCode === 'number') {
|
|
7219
|
-
return errorObj.statusCode;
|
|
7220
|
-
}
|
|
7221
|
-
return undefined;
|
|
7222
|
-
}
|
|
7223
|
-
function classifyError(error) {
|
|
7224
|
-
const statusCode = extractStatusCode(error);
|
|
7225
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7226
|
-
if (statusCode && statusCode >= 500 && statusCode < 600) {
|
|
7227
|
-
return {
|
|
7228
|
-
category: ErrorCategory.SERVER_ERROR,
|
|
7229
|
-
statusCode,
|
|
7230
|
-
message: errorMessage,
|
|
7231
|
-
shouldRetry: false,
|
|
7232
|
-
userMessage: `Server error (${statusCode}): The server encountered an error.`,
|
|
7233
|
-
};
|
|
7234
|
-
}
|
|
7235
|
-
if (statusCode === 401 || statusCode === 403) {
|
|
7236
|
-
return {
|
|
7237
|
-
category: ErrorCategory.AUTH_ERROR,
|
|
7238
|
-
statusCode,
|
|
7239
|
-
message: errorMessage,
|
|
7240
|
-
shouldRetry: false,
|
|
7241
|
-
userMessage: `Authentication error (${statusCode}): Invalid credentials or insufficient permissions.`,
|
|
7242
|
-
};
|
|
7243
|
-
}
|
|
7244
|
-
if (statusCode && statusCode >= 400 && statusCode < 500) {
|
|
7245
|
-
return {
|
|
7246
|
-
category: ErrorCategory.CLIENT_ERROR,
|
|
7247
|
-
statusCode,
|
|
7248
|
-
message: errorMessage,
|
|
7249
|
-
shouldRetry: false,
|
|
7250
|
-
userMessage: `Request error (${statusCode}): ${errorMessage}`,
|
|
7251
|
-
};
|
|
7252
|
-
}
|
|
7253
|
-
if (error instanceof MTLSError) {
|
|
7254
|
-
return {
|
|
7255
|
-
category: ErrorCategory.CERTIFICATE_ERROR,
|
|
7256
|
-
statusCode,
|
|
7257
|
-
message: errorMessage,
|
|
7258
|
-
shouldRetry: true,
|
|
7259
|
-
userMessage: 'Certificate error: Unable to establish secure connection.',
|
|
7260
|
-
};
|
|
7261
|
-
}
|
|
7262
|
-
if (!statusCode &&
|
|
7263
|
-
(errorMessage.toLowerCase().includes('network') ||
|
|
7264
|
-
errorMessage.toLowerCase().includes('timeout') ||
|
|
7265
|
-
errorMessage.toLowerCase().includes('connection'))) {
|
|
7266
|
-
return {
|
|
7267
|
-
category: ErrorCategory.NETWORK_ERROR,
|
|
7268
|
-
message: errorMessage,
|
|
7269
|
-
shouldRetry: true,
|
|
7270
|
-
userMessage: 'Network error: Unable to connect to server.',
|
|
7271
|
-
};
|
|
7272
|
-
}
|
|
7273
|
-
return {
|
|
7274
|
-
category: ErrorCategory.UNKNOWN_ERROR,
|
|
7275
|
-
statusCode,
|
|
7276
|
-
message: errorMessage,
|
|
7277
|
-
shouldRetry: false,
|
|
7278
|
-
userMessage: `Unexpected error: ${errorMessage}`,
|
|
7279
|
-
};
|
|
7280
|
-
}
|
|
7281
|
-
function shouldReconfigureCertificate(error) {
|
|
7282
|
-
const classification = classifyError(error);
|
|
7283
|
-
return classification.category === ErrorCategory.CERTIFICATE_ERROR;
|
|
7284
|
-
}
|
|
7285
|
-
function shouldRetryRequest(error, isRetryAttempt) {
|
|
7286
|
-
if (isRetryAttempt) {
|
|
7287
|
-
return false;
|
|
7288
|
-
}
|
|
7289
|
-
const classification = classifyError(error);
|
|
7290
|
-
return classification.shouldRetry;
|
|
7291
|
-
}
|
|
7292
|
-
function getUserFriendlyMessage(error) {
|
|
7293
|
-
const classification = classifyError(error);
|
|
7294
|
-
return classification.userMessage;
|
|
7295
|
-
}
|
|
7296
|
-
|
|
7297
|
-
var MTLSErrorType;
|
|
7298
|
-
(function (MTLSErrorType) {
|
|
7299
|
-
MTLSErrorType["NOT_SUPPORTED"] = "MTLS_NOT_SUPPORTED";
|
|
7300
|
-
MTLSErrorType["CERTIFICATE_NOT_FOUND"] = "MTLS_CERTIFICATE_NOT_FOUND";
|
|
7301
|
-
MTLSErrorType["CERTIFICATE_EXPIRED"] = "MTLS_CERTIFICATE_EXPIRED";
|
|
7302
|
-
MTLSErrorType["CERTIFICATE_INVALID"] = "MTLS_CERTIFICATE_INVALID";
|
|
7303
|
-
MTLSErrorType["CONNECTION_FAILED"] = "MTLS_CONNECTION_FAILED";
|
|
7304
|
-
MTLSErrorType["AUTHENTICATION_FAILED"] = "MTLS_AUTHENTICATION_FAILED";
|
|
7305
|
-
MTLSErrorType["CONFIGURATION_ERROR"] = "MTLS_CONFIGURATION_ERROR";
|
|
7306
|
-
})(MTLSErrorType || (MTLSErrorType = {}));
|
|
7307
|
-
class PlatformDetector {
|
|
7308
|
-
static detectPlatform() {
|
|
7309
|
-
if ((typeof global !== 'undefined' && global.__expo) ||
|
|
7310
|
-
(typeof navigator !== 'undefined' &&
|
|
7311
|
-
navigator.product === 'ReactNative')) {
|
|
7312
|
-
return 'react-native';
|
|
7313
|
-
}
|
|
7314
|
-
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
7315
|
-
return 'node';
|
|
7316
|
-
}
|
|
7317
|
-
return 'web';
|
|
7318
|
-
}
|
|
7319
|
-
static isReactNative() {
|
|
7320
|
-
return this.detectPlatform() === 'react-native';
|
|
7321
|
-
}
|
|
7322
|
-
static isNode() {
|
|
7323
|
-
return this.detectPlatform() === 'node';
|
|
7324
|
-
}
|
|
7325
|
-
static isWeb() {
|
|
7326
|
-
return this.detectPlatform() === 'web';
|
|
7327
|
-
}
|
|
7328
|
-
static getPlatformDetails() {
|
|
7329
|
-
const platform = this.detectPlatform();
|
|
7330
|
-
return {
|
|
7331
|
-
platform,
|
|
7332
|
-
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown',
|
|
7333
|
-
nodeVersion: typeof process !== 'undefined' ? process.version : undefined,
|
|
7334
|
-
isExpo: typeof global !== 'undefined' && !!global.__expo,
|
|
7335
|
-
hasWindow: typeof window !== 'undefined',
|
|
7336
|
-
hasDocument: typeof document !== 'undefined',
|
|
7337
|
-
hasProcess: typeof process !== 'undefined',
|
|
7338
|
-
};
|
|
7339
|
-
}
|
|
7340
|
-
}
|
|
7341
|
-
|
|
7342
|
-
export { ACubeSDK, ACubeSDKError, ActivationRequestSchema, AddressMapper, AddressSchema, AppStateService, AuthStrategy, AuthenticationService, AxiosHttpAdapter, CashRegisterCreateSchema, CashRegisterMapper, CashRegisterRepositoryImpl, CashierCreateInputSchema, CashierMapper, CashierRepositoryImpl, CertificateService, CertificateValidator, ConfigManager, DAILY_REPORT_STATUS_OPTIONS, DIContainer, DI_TOKENS, DailyReportMapper, DailyReportRepositoryImpl, DailyReportStatusSchema, DailyReportsParamsSchema, EXEMPT_VAT_CODES, ErrorCategory, GOOD_OR_SERVICE_OPTIONS, GoodOrServiceSchema, JournalCloseInputSchema, JournalMapper, JournalRepositoryImpl, JwtAuthHandler, LotterySchema, LotterySecretRequestSchema, MTLSError, MTLSErrorType$1 as MTLSErrorType, MerchantCreateInputSchema, MerchantMapper, MerchantRepositoryImpl, MerchantUpdateInputSchema, MessageSchema, MtlsAuthHandler, NOTIFICATION_CODES, NOTIFICATION_LEVELS, NOTIFICATION_SCOPES, NOTIFICATION_SOURCES, NOTIFICATION_TYPES, NotificationDataBlockAtSchema, NotificationDataPemStatusSchema, NotificationListResponseSchema, NotificationMapper, NotificationMf2UnreachableSchema, NotificationPemBackOnlineSchema, NotificationPemsBlockedSchema, NotificationRepositoryImpl, NotificationSchema, NotificationScopeSchema, NotificationService, PEMStatusOfflineRequestSchema, PEMStatusSchema, PEM_STATUS_OPTIONS, PEM_TYPE_OPTIONS, PemCreateInputSchema, PemDataSchema, PemMapper, PemRepositoryImpl, PemStatusSchema, PendingReceiptsSchema, PlatformDetector, PointOfSaleMapper, PointOfSaleRepositoryImpl, RECEIPT_PROOF_TYPE_OPTIONS, RECEIPT_READY, RECEIPT_SENT, RECEIPT_SORT_ASCENDING, RECEIPT_SORT_DESCENDING, ReceiptInputSchema, ReceiptItemSchema, ReceiptMapper, ReceiptProofTypeSchema, ReceiptRepositoryImpl, ReceiptReturnInputSchema, ReceiptReturnItemSchema, ReceiptReturnOrVoidViaPEMInputSchema, ReceiptReturnOrVoidWithProofInputSchema, SDKFactory, SDKManager, STANDARD_VAT_RATES, SupplierCreateInputSchema, SupplierMapper, SupplierRepositoryImpl, SupplierUpdateInputSchema, TelemetryMapper, TelemetryMerchantSchema, TelemetryRepositoryImpl, TelemetrySchema, TelemetryService, TelemetrySoftwareSchema, TelemetrySoftwareVersionSchema, TelemetrySupplierSchema, TransmissionSchema, VAT_RATE_CODES, VAT_RATE_CODE_OPTIONS, ValidationMessages, VatRateCodeSchema, VoidReceiptInputSchema, classifyError, clearObject, clearObjectShallow, createACubeMTLSConfig, createACubeSDK, createPrefixedLogger, createACubeSDK as default, detectPlatform, extractRoles, formatDecimal, getUserFriendlyMessage, hasAnyRole, hasNonEmptyValues, hasRole, isEmpty, isTokenExpired, loadPlatformAdapters, logger, parseJwt, shouldReconfigureCertificate, shouldRetryRequest, transformError, validateInput };
|
|
6759
|
+
export { ACubeSDK, ACubeSDKError, AddressMapper, AppStateService, AuthenticationService, CashRegisterMapper, CashierMapper, CertificateService, CertificateValidator, ConfigManager, DAILY_REPORT_STATUS_OPTIONS, DailyReportMapper, EXEMPT_VAT_CODES, GOOD_OR_SERVICE_OPTIONS, GoodOrServiceSchema, JournalMapper, MTLSError, MTLSErrorType, MerchantMapper, NOTIFICATION_CODES, NOTIFICATION_LEVELS, NOTIFICATION_SCOPES, NOTIFICATION_SOURCES, NOTIFICATION_TYPES, NotificationMapper, NotificationService, PEM_STATUS_OPTIONS, PEM_TYPE_OPTIONS, PemMapper, PointOfSaleMapper, RECEIPT_PROOF_TYPE_OPTIONS, RECEIPT_READY, RECEIPT_SENT, RECEIPT_SORT_ASCENDING, RECEIPT_SORT_DESCENDING, ReceiptMapper, ReceiptProofTypeSchema, SDKManager, STANDARD_VAT_RATES, SupplierMapper, TelemetryMapper, TelemetryService, VAT_RATE_CODES, VAT_RATE_CODE_OPTIONS, VatRateCodeSchema, createACubeMTLSConfig, createACubeSDK, createPrefixedLogger, createACubeSDK as default, extractRoles, hasAnyRole, hasRole, isTokenExpired, loadPlatformAdapters, logger, parseJwt };
|
|
7343
6760
|
//# sourceMappingURL=index.esm.js.map
|