@a-cube-io/ereceipts-js-sdk 1.0.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/LICENSE +41 -0
- package/README.md +444 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/auth-D6UEILKY.cjs +56 -0
- package/dist/auth-D6UEILKY.cjs.map +1 -0
- package/dist/auth-RZRIC4PK.js +7 -0
- package/dist/auth-RZRIC4PK.js.map +1 -0
- package/dist/chunk-24ZJ6SNG.cjs +624 -0
- package/dist/chunk-24ZJ6SNG.cjs.map +1 -0
- package/dist/chunk-C3YEL4ED.js +511 -0
- package/dist/chunk-C3YEL4ED.js.map +1 -0
- package/dist/chunk-K65HAAAO.js +44 -0
- package/dist/chunk-K65HAAAO.js.map +1 -0
- package/dist/chunk-NARXAXFL.cjs +215 -0
- package/dist/chunk-NARXAXFL.cjs.map +1 -0
- package/dist/chunk-UBEIMFLN.js +209 -0
- package/dist/chunk-UBEIMFLN.js.map +1 -0
- package/dist/chunk-UVUWF5FV.cjs +3964 -0
- package/dist/chunk-UVUWF5FV.cjs.map +1 -0
- package/dist/chunk-UXVFQRZK.cjs +533 -0
- package/dist/chunk-UXVFQRZK.cjs.map +1 -0
- package/dist/chunk-VDHN3FKS.js +3929 -0
- package/dist/chunk-VDHN3FKS.js.map +1 -0
- package/dist/chunk-XQKCXG4I.cjs +52 -0
- package/dist/chunk-XQKCXG4I.cjs.map +1 -0
- package/dist/chunk-YX3PJ4FC.js +590 -0
- package/dist/chunk-YX3PJ4FC.js.map +1 -0
- package/dist/client-WPBRHPKX.cjs +31 -0
- package/dist/client-WPBRHPKX.cjs.map +1 -0
- package/dist/client-Z2LXQJMF.js +6 -0
- package/dist/client-Z2LXQJMF.js.map +1 -0
- package/dist/index.cjs +1326 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +960 -0
- package/dist/index.d.ts +960 -0
- package/dist/index.js +1065 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/queue-D7PJ536B.js +4 -0
- package/dist/queue-D7PJ536B.js.map +1 -0
- package/dist/queue-JHWXWX2B.cjs +13 -0
- package/dist/queue-JHWXWX2B.cjs.map +1 -0
- package/dist/token-3CIX4E64.cjs +13 -0
- package/dist/token-3CIX4E64.cjs.map +1 -0
- package/dist/token-4OAGWTVG.js +4 -0
- package/dist/token-4OAGWTVG.js.map +1 -0
- package/openapi.yaml +2732 -0
- package/package.json +115 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 A-Cube Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.MIT License
|
|
22
|
+
|
|
23
|
+
Copyright (c) 2025 A-Cube S.r.l.
|
|
24
|
+
|
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
+
of this software and associated documentation files (the Software), to deal
|
|
27
|
+
in the Software without restriction, including without limitation the rights
|
|
28
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
30
|
+
furnished to do so, subject to the following conditions:
|
|
31
|
+
|
|
32
|
+
The above copyright notice and this permission notice shall be included in all
|
|
33
|
+
copies or substantial portions of the Software.
|
|
34
|
+
|
|
35
|
+
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# A-Cube SDK
|
|
2
|
+
|
|
3
|
+
> **Professional TypeScript SDK for A-Cube e-receipt system integration**
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/a-cube-io/ereceipts-js-sdk)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://reactnative.dev/)
|
|
8
|
+
[](https://webpack.js.org/guides/tree-shaking/)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
A comprehensive, cross-platform SDK for integrating the Italian A-Cube e-receipt system into React, React Native, and PWA applications. Built with TypeScript for type safety and modern development practices.
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- 🚀 **Cross-Platform**: Works seamlessly on React, React Native, and PWA
|
|
16
|
+
- 📱 **No Expo Required**: Pure React Native compatibility
|
|
17
|
+
- 🔒 **Secure Authentication**: JWT tokens with secure storage (Keychain/localStorage)
|
|
18
|
+
- 📄 **Complete E-Receipt Management**: Create, void, return receipts
|
|
19
|
+
- 🏪 **Multi-Role Support**: Provider, Merchant, and Cashier roles
|
|
20
|
+
- 🌐 **Offline Support**: Request queuing with automatic retry
|
|
21
|
+
- 🎯 **Tree Shakeable**: Import only what you need
|
|
22
|
+
- 📚 **Full TypeScript**: Complete type definitions and IntelliSense
|
|
23
|
+
- 🔧 **Modern Build**: ESM/CJS dual package with tsup
|
|
24
|
+
- ⚡ **Performance Optimized**: Minimal bundle size impact
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 📖 Documentation
|
|
28
|
+
|
|
29
|
+
### 📂 Navigation
|
|
30
|
+
|
|
31
|
+
| Section | Description | Links |
|
|
32
|
+
|---------|-------------|-------|
|
|
33
|
+
| **🔧 API Reference** | Core SDK functionality | [Authentication](docs/api/auth.md) • [Receipts](docs/api/receipts.md) • [Merchants](docs/api/merchants.md) |
|
|
34
|
+
| **📚 Guides** | Step-by-step tutorials | [Getting Started](docs/guides/getting-started.md) • [Authentication Flow](docs/guides/auth-flow.md) • [Receipt Management](docs/guides/receipt-management.md) |
|
|
35
|
+
| **💡 Examples** | Code samples | [React Examples](examples/react/) • [React Native Examples](examples/react-native/) • [Advanced Usage](USAGE_EXAMPLE.md) |
|
|
36
|
+
| **🔒 Security** | Token & certificate management | [Secure Storage](#-secure-token-storage) • [mTLS Certificates](docs/security/mtls.md) |
|
|
37
|
+
| **🛠️ Development** | SDK development & contribution | [Building](docs/development/building.md) • [Testing](docs/development/testing.md) • [Contributing](CONTRIBUTING.md) |
|
|
38
|
+
|
|
39
|
+
- [📋 Full API Documentation](docs/README.md)
|
|
40
|
+
- [🚀 Quick Start Examples](USAGE_EXAMPLE.md)
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install a-cube-io/ereceipts-js-sdk
|
|
46
|
+
# or
|
|
47
|
+
yarn add a-cube-io/ereceipts-js-sdk
|
|
48
|
+
# or
|
|
49
|
+
pnpm add a-cube-io/ereceipts-js-sdk
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Peer Dependencies
|
|
53
|
+
|
|
54
|
+
For **React Native** projects:
|
|
55
|
+
```bash
|
|
56
|
+
npm install @react-native-async-storage/async-storage react-native-keychain @react-native-community/netinfo
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For **React Web** projects:
|
|
60
|
+
```bash
|
|
61
|
+
# No additional dependencies required
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 🚀 Quick Start
|
|
65
|
+
|
|
66
|
+
### 1. Initialize the SDK
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { initSDK } from 'a-cube-io/ereceipts-js-sdk';
|
|
70
|
+
|
|
71
|
+
// Initialize SDK (call once at app startup)
|
|
72
|
+
await initSDK({
|
|
73
|
+
environment: 'sandbox', // or 'production'
|
|
74
|
+
enableLogging: true,
|
|
75
|
+
enableRetry: true,
|
|
76
|
+
enableOfflineQueue: true
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2. Authentication
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { loginProvider, loginMerchant, loginCashier } from 'a-cube-io/ereceipts-js-sdk';
|
|
84
|
+
|
|
85
|
+
// Login as Provider (highest privileges)
|
|
86
|
+
const providerToken = await loginProvider('provider@company.com', 'password123');
|
|
87
|
+
|
|
88
|
+
// Login as Merchant (business owner)
|
|
89
|
+
const merchantToken = await loginMerchant('merchant@restaurant.com', 'password123');
|
|
90
|
+
|
|
91
|
+
// Login as Cashier (operational level)
|
|
92
|
+
const cashierToken = await loginCashier('cashier@store.com', 'password123');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Create Your First Receipt
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { createReceipt } from 'a-cube-io/ereceipts-js-sdk';
|
|
99
|
+
|
|
100
|
+
const receipt = await createReceipt({
|
|
101
|
+
items: [
|
|
102
|
+
{
|
|
103
|
+
description: 'Caffè Espresso',
|
|
104
|
+
quantity: '2.00',
|
|
105
|
+
unit_price: '1.50',
|
|
106
|
+
good_or_service: 'B', // 'B' for goods, 'S' for services
|
|
107
|
+
vat_rate_code: '22'
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
cash_payment_amount: '3.00',
|
|
111
|
+
electronic_payment_amount: '0.00'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log('Receipt created:', receipt.uuid);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 4. Using React Components
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import React from 'react';
|
|
121
|
+
import { Button, FormInput, useAuth } from 'a-cube-io/ereceipts-js-sdk';
|
|
122
|
+
|
|
123
|
+
function LoginScreen() {
|
|
124
|
+
const { loginAsMerchant, isLoading, error } = useAuth();
|
|
125
|
+
const [email, setEmail] = React.useState('');
|
|
126
|
+
const [password, setPassword] = React.useState('');
|
|
127
|
+
|
|
128
|
+
const handleLogin = async () => {
|
|
129
|
+
await loginAsMerchant(email, password);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div>
|
|
134
|
+
<FormInput
|
|
135
|
+
label="Email"
|
|
136
|
+
value={email}
|
|
137
|
+
onChangeText={setEmail}
|
|
138
|
+
keyboardType="email-address"
|
|
139
|
+
required
|
|
140
|
+
/>
|
|
141
|
+
|
|
142
|
+
<FormInput
|
|
143
|
+
label="Password"
|
|
144
|
+
value={password}
|
|
145
|
+
onChangeText={setPassword}
|
|
146
|
+
secureTextEntry
|
|
147
|
+
showPasswordToggle
|
|
148
|
+
required
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
{error && <div style={{ color: 'red' }}>{error}</div>}
|
|
152
|
+
|
|
153
|
+
<Button
|
|
154
|
+
title="Login"
|
|
155
|
+
onPress={handleLogin}
|
|
156
|
+
loading={isLoading}
|
|
157
|
+
disabled={!email || !password}
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 📚 API Reference
|
|
165
|
+
|
|
166
|
+
### Authentication
|
|
167
|
+
- `initSDK(config)` - Initialize the SDK
|
|
168
|
+
- `loginProvider(email, password)` - Provider authentication
|
|
169
|
+
- `loginMerchant(email, password)` - Merchant authentication
|
|
170
|
+
- `loginCashier(email, password)` - Cashier authentication
|
|
171
|
+
- `logout()` - Logout current user
|
|
172
|
+
- `isAuthenticated()` - Check authentication status
|
|
173
|
+
- `getCurrentUser()` - Get current user info
|
|
174
|
+
|
|
175
|
+
### Receipt Management
|
|
176
|
+
- `createReceipt(data)` - Create new receipt
|
|
177
|
+
- `getReceipts(page?, size?)` - List receipts
|
|
178
|
+
- `getReceiptById(uuid)` - Get specific receipt
|
|
179
|
+
- `voidReceipt(data)` - Void/cancel receipt
|
|
180
|
+
- `returnReceiptItems(data)` - Process returns/refunds
|
|
181
|
+
|
|
182
|
+
### Merchant Management
|
|
183
|
+
- `createMerchant(data)` - Create merchant (Provider only)
|
|
184
|
+
- `getMerchants(page?)` - List merchants
|
|
185
|
+
- `updateMerchant(uuid, data)` - Update merchant info
|
|
186
|
+
|
|
187
|
+
### React Hooks
|
|
188
|
+
- `useAuth()` - Authentication state and actions
|
|
189
|
+
- `useRetryQueue()` - Offline queue management
|
|
190
|
+
- `useProviderFlow()` - Provider-specific operations
|
|
191
|
+
|
|
192
|
+
### UI Components
|
|
193
|
+
- `<Button />` - Cross-platform button component
|
|
194
|
+
- `<FormInput />` - Cross-platform input component
|
|
195
|
+
|
|
196
|
+
## 🛠️ Configuration
|
|
197
|
+
|
|
198
|
+
### Environment Setup
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { initSDK } from 'a-cube-io/ereceipts-js-sdk';
|
|
202
|
+
|
|
203
|
+
await initSDK({
|
|
204
|
+
environment: 'sandbox', // 'sandbox' | 'production'
|
|
205
|
+
enableLogging: true, // Enable debug logging
|
|
206
|
+
enableRetry: true, // Enable automatic retries
|
|
207
|
+
maxRetries: 3, // Maximum retry attempts
|
|
208
|
+
retryDelay: 1000, // Base retry delay (ms)
|
|
209
|
+
enableOfflineQueue: true, // Enable offline request queuing
|
|
210
|
+
timeout: 30000 // Request timeout (ms)
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Platform-Specific Configuration
|
|
215
|
+
|
|
216
|
+
#### React Native
|
|
217
|
+
```typescript
|
|
218
|
+
// No additional configuration needed
|
|
219
|
+
// The SDK automatically detects React Native environment
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### React Web
|
|
223
|
+
```typescript
|
|
224
|
+
// Works out of the box with Create React App, Vite, Next.js, etc.
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## 🔧 Advanced Usage
|
|
228
|
+
|
|
229
|
+
### 🔒 Secure Token Storage
|
|
230
|
+
|
|
231
|
+
The SDK includes an advanced cross-platform token storage system with automatic fallbacks and configurable encryption:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { SecureTokenStorage } from 'a-cube-io/ereceipts-js-sdk';
|
|
235
|
+
|
|
236
|
+
// Configure secure storage (call once at app startup)
|
|
237
|
+
SecureTokenStorage.configure({
|
|
238
|
+
encryptionKeyId: 'my-app-key-v1', // For future encryption
|
|
239
|
+
storeNamespace: 'my-app-secure-store' // Custom IndexedDB namespace
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Basic token management
|
|
243
|
+
await SecureTokenStorage.storeToken(authToken);
|
|
244
|
+
const token = await SecureTokenStorage.getToken();
|
|
245
|
+
const isValid = await SecureTokenStorage.isTokenValid();
|
|
246
|
+
|
|
247
|
+
// Advanced features
|
|
248
|
+
const health = await SecureTokenStorage.checkStorageHealth();
|
|
249
|
+
const stats = await SecureTokenStorage.getStorageStats();
|
|
250
|
+
const expiryInfo = await SecureTokenStorage.getTokenExpiryInfo();
|
|
251
|
+
|
|
252
|
+
// User info management
|
|
253
|
+
await SecureTokenStorage.storeUserInfo(jwtToken);
|
|
254
|
+
const userEmail = await SecureTokenStorage.getUserEmail();
|
|
255
|
+
const userRole = await SecureTokenStorage.getUserRole();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### Platform-Specific Storage:
|
|
259
|
+
|
|
260
|
+
| Platform | Primary Storage | Fallback | Features |
|
|
261
|
+
|----------|----------------|----------|----------|
|
|
262
|
+
| **Web** | IndexedDB | localStorage | Custom namespace, Safari incognito support |
|
|
263
|
+
| **React Native** | Keychain | AsyncStorage | Biometric protection, encrypted storage |
|
|
264
|
+
| **PWA** | IndexedDB | localStorage | Offline persistence, sync capabilities |
|
|
265
|
+
|
|
266
|
+
#### Storage Health Monitoring:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
// Monitor storage health in production
|
|
270
|
+
const healthCheck = await SecureTokenStorage.checkStorageHealth();
|
|
271
|
+
if (!healthCheck.isHealthy) {
|
|
272
|
+
console.warn('Storage issues:', healthCheck.issues);
|
|
273
|
+
// Handle fallback scenarios
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Get detailed statistics
|
|
277
|
+
const stats = await SecureTokenStorage.getStorageStats();
|
|
278
|
+
console.log(`Token expires in: ${stats.tokenExpiryInfo.expiresInMs}ms`);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Certificate Management
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { CertificateStorage } from 'a-cube-io/ereceipts-js-sdk';
|
|
285
|
+
|
|
286
|
+
// mTLS certificate management for cash registers
|
|
287
|
+
await CertificateStorage.storeMTLSCertificate(uuid, certificate);
|
|
288
|
+
const cert = await CertificateStorage.getMTLSCertificate(uuid);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Offline Support
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { useRetryQueue } from 'a-cube-io/ereceipts-js-sdk';
|
|
295
|
+
|
|
296
|
+
function OfflineIndicator() {
|
|
297
|
+
const { stats, isConnected, processQueue } = useRetryQueue();
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<div>
|
|
301
|
+
<p>Status: {isConnected ? 'Online' : 'Offline'}</p>
|
|
302
|
+
<p>Queued requests: {stats.total}</p>
|
|
303
|
+
{stats.total > 0 && (
|
|
304
|
+
<button onClick={processQueue}>Retry Queued Requests</button>
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Validation Utilities
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import {
|
|
315
|
+
validateEmail,
|
|
316
|
+
validatePassword,
|
|
317
|
+
validateFiscalId,
|
|
318
|
+
validateReceiptItem
|
|
319
|
+
} from 'a-cube-io/ereceipts-js-sdk';
|
|
320
|
+
|
|
321
|
+
// Validate user input
|
|
322
|
+
const emailValidation = validateEmail('user@example.com');
|
|
323
|
+
if (!emailValidation.isValid) {
|
|
324
|
+
console.error(emailValidation.errors);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Validate Italian fiscal ID
|
|
328
|
+
const fiscalValidation = validateFiscalId('12345678901');
|
|
329
|
+
|
|
330
|
+
// Validate receipt items
|
|
331
|
+
const itemValidation = validateReceiptItem({
|
|
332
|
+
description: 'Product',
|
|
333
|
+
quantity: '1.00',
|
|
334
|
+
unit_price: '10.00'
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## 🏗️ Project Structure
|
|
339
|
+
|
|
340
|
+
When using the SDK in your project:
|
|
341
|
+
|
|
342
|
+
```
|
|
343
|
+
your-app/
|
|
344
|
+
├── src/
|
|
345
|
+
│ ├── services/
|
|
346
|
+
│ │ └── acube.ts # SDK initialization
|
|
347
|
+
│ ├── components/
|
|
348
|
+
│ │ ├── LoginScreen.tsx # Authentication
|
|
349
|
+
│ │ └── ReceiptCreator.tsx # Receipt management
|
|
350
|
+
│ └── App.tsx # Main app
|
|
351
|
+
└── package.json
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 🤝 TypeScript Support
|
|
355
|
+
|
|
356
|
+
The SDK is built with TypeScript and provides complete type definitions:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import type {
|
|
360
|
+
ReceiptInput,
|
|
361
|
+
ReceiptOutput,
|
|
362
|
+
MerchantCreateInput,
|
|
363
|
+
AuthToken,
|
|
364
|
+
ValidationResult
|
|
365
|
+
} from 'a-cube-io/ereceipts-js-sdk';
|
|
366
|
+
|
|
367
|
+
// Full IntelliSense and type checking
|
|
368
|
+
const receiptData: ReceiptInput = {
|
|
369
|
+
items: [/* typed items */],
|
|
370
|
+
cash_payment_amount: '10.00'
|
|
371
|
+
};
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## 📱 Platform Compatibility
|
|
375
|
+
|
|
376
|
+
| Feature | React Web | React Native | PWA |
|
|
377
|
+
|---------|-----------|--------------|-----|
|
|
378
|
+
| Authentication | ✅ | ✅ | ✅ |
|
|
379
|
+
| Receipt Management | ✅ | ✅ | ✅ |
|
|
380
|
+
| Offline Support | ✅ | ✅ | ✅ |
|
|
381
|
+
| Secure Storage | IndexedDB + localStorage | Keychain + AsyncStorage | IndexedDB + localStorage |
|
|
382
|
+
| Push Notifications | ❌ | ✅ | ✅ |
|
|
383
|
+
| File System Access | ❌ | ✅ | Limited |
|
|
384
|
+
|
|
385
|
+
## 🔐 Security
|
|
386
|
+
|
|
387
|
+
- **🔒 Advanced Token Storage**:
|
|
388
|
+
- **Web**: IndexedDB with custom namespace + localStorage fallback
|
|
389
|
+
- **React Native**: Keychain (biometric) + AsyncStorage fallback
|
|
390
|
+
- **Configurable**: Custom encryption keys and namespaces
|
|
391
|
+
- **Monitoring**: Health checks and automatic fallback detection
|
|
392
|
+
|
|
393
|
+
- **🔄 Automatic Token Management**:
|
|
394
|
+
- Token expiry detection and refresh
|
|
395
|
+
- JWT payload parsing and validation
|
|
396
|
+
- User info extraction and secure storage
|
|
397
|
+
|
|
398
|
+
- **🔐 mTLS Support**: End-to-end encryption for cash register communication
|
|
399
|
+
- **✅ Input Validation**: Client-side validation for all inputs
|
|
400
|
+
- **🌐 HTTPS Only**: All API communication over HTTPS
|
|
401
|
+
- **🛡️ Fallback Strategies**: Graceful degradation when secure storage fails
|
|
402
|
+
|
|
403
|
+
## 🐛 Troubleshooting
|
|
404
|
+
|
|
405
|
+
### React Native Issues
|
|
406
|
+
|
|
407
|
+
1. **Keychain errors on iOS**:
|
|
408
|
+
```bash
|
|
409
|
+
cd ios && pod install
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
2. **AsyncStorage warnings**:
|
|
413
|
+
```bash
|
|
414
|
+
npm install @react-native-async-storage/async-storage
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
3. **Network detection issues**:
|
|
418
|
+
```bash
|
|
419
|
+
npm install @react-native-community/netinfo
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Web Issues
|
|
423
|
+
|
|
424
|
+
1. **Module resolution errors**: Ensure your bundler supports ESM/CJS dual packages
|
|
425
|
+
2. **TypeScript errors**: Update to TypeScript 4.0+
|
|
426
|
+
|
|
427
|
+
## 📄 License
|
|
428
|
+
|
|
429
|
+
MIT © A-Cube Team
|
|
430
|
+
|
|
431
|
+
## 🤝 Contributing
|
|
432
|
+
|
|
433
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
434
|
+
|
|
435
|
+
## 📞 Support
|
|
436
|
+
|
|
437
|
+
- 📧 Email: support@acube.it
|
|
438
|
+
- 📖 Documentation: [Full API Documentation](https://docs.acube.it)
|
|
439
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/acube/a-cube-io/ereceipts-js-sdk/issues)
|
|
440
|
+
- 💬 Discussions: [GitHub Discussions](https://github.com/acube/a-cube-io/ereceipts-js-sdk/discussions)
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
**Made with ❤️ by the A-Cube Team**
|