@a-cube-io/ereceipts-js-sdk 1.0.3 → 1.0.7
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/README.md +260 -57
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.cjs +2417 -379
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +292 -21
- package/dist/index.d.ts +292 -21
- package/dist/index.js +2253 -37
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +28 -4
- package/dist/auth-D6UEILKY.cjs +0 -56
- package/dist/auth-D6UEILKY.cjs.map +0 -1
- package/dist/auth-RZRIC4PK.js +0 -7
- package/dist/auth-RZRIC4PK.js.map +0 -1
- package/dist/chunk-24ZJ6SNG.cjs +0 -624
- package/dist/chunk-24ZJ6SNG.cjs.map +0 -1
- package/dist/chunk-C3YEL4ED.js +0 -511
- package/dist/chunk-C3YEL4ED.js.map +0 -1
- package/dist/chunk-K65HAAAO.js +0 -44
- package/dist/chunk-K65HAAAO.js.map +0 -1
- package/dist/chunk-NARXAXFL.cjs +0 -215
- package/dist/chunk-NARXAXFL.cjs.map +0 -1
- package/dist/chunk-UBEIMFLN.js +0 -209
- package/dist/chunk-UBEIMFLN.js.map +0 -1
- package/dist/chunk-UVUWF5FV.cjs +0 -3964
- package/dist/chunk-UVUWF5FV.cjs.map +0 -1
- package/dist/chunk-UXVFQRZK.cjs +0 -533
- package/dist/chunk-UXVFQRZK.cjs.map +0 -1
- package/dist/chunk-VDHN3FKS.js +0 -3929
- package/dist/chunk-VDHN3FKS.js.map +0 -1
- package/dist/chunk-XQKCXG4I.cjs +0 -52
- package/dist/chunk-XQKCXG4I.cjs.map +0 -1
- package/dist/chunk-YX3PJ4FC.js +0 -590
- package/dist/chunk-YX3PJ4FC.js.map +0 -1
- package/dist/client-WPBRHPKX.cjs +0 -31
- package/dist/client-WPBRHPKX.cjs.map +0 -1
- package/dist/client-Z2LXQJMF.js +0 -6
- package/dist/client-Z2LXQJMF.js.map +0 -1
- package/dist/queue-D7PJ536B.js +0 -4
- package/dist/queue-D7PJ536B.js.map +0 -1
- package/dist/queue-JHWXWX2B.cjs +0 -13
- package/dist/queue-JHWXWX2B.cjs.map +0 -1
- package/dist/token-3CIX4E64.cjs +0 -13
- package/dist/token-3CIX4E64.cjs.map +0 -1
- package/dist/token-4OAGWTVG.js +0 -4
- package/dist/token-4OAGWTVG.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# A-Cube SDK
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
> **Professional TypeScript SDK for A-Cube e-receipt system integration**
|
|
4
7
|
|
|
5
8
|
[](https://badge.fury.io/js/primeng)
|
|
@@ -31,7 +34,7 @@ A comprehensive, cross-platform SDK for integrating the Italian A-Cube e-receipt
|
|
|
31
34
|
| Section | Description | Links |
|
|
32
35
|
|---------|-------------|-------|
|
|
33
36
|
| **🔧 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) |
|
|
37
|
+
| **📚 Guides** | Step-by-step tutorials | [Getting Started](docs/guides/getting-started.md) • [React Provider](docs/guides/react-provider.md) • [Authentication Flow](docs/guides/auth-flow.md) • [Receipt Management](docs/guides/receipt-management.md) |
|
|
35
38
|
| **💡 Examples** | Code samples | [React Examples](examples/react/) • [React Native Examples](examples/react-native/) • [Advanced Usage](USAGE_EXAMPLE.md) |
|
|
36
39
|
| **🔒 Security** | Token & certificate management | [Secure Storage](#-secure-token-storage) • [mTLS Certificates](docs/security/mtls.md) |
|
|
37
40
|
| **🛠️ Development** | SDK development & contribution | [Building](docs/development/building.md) • [Testing](docs/development/testing.md) • [Contributing](CONTRIBUTING.md) |
|
|
@@ -63,33 +66,85 @@ For **React Web** projects:
|
|
|
63
66
|
|
|
64
67
|
## 🚀 Quick Start
|
|
65
68
|
|
|
66
|
-
### 1
|
|
69
|
+
### Option 1: React Provider (Recommended for React Apps)
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import React from 'react';
|
|
73
|
+
import { EReceiptsProvider, useEReceipts, loginAsMerchant } from '@a-cube-io/ereceipts-js-sdk';
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<EReceiptsProvider
|
|
78
|
+
config={{
|
|
79
|
+
environment: 'sandbox',
|
|
80
|
+
enableLogging: true,
|
|
81
|
+
onInitialized: () => console.log('✅ SDK Ready!'),
|
|
82
|
+
onAuthChange: (isAuth) => console.log('🔐 Auth:', isAuth)
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<AppContent />
|
|
86
|
+
</EReceiptsProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function AppContent() {
|
|
91
|
+
const { isInitialized, isAuthenticated, currentUser } = useEReceipts();
|
|
92
|
+
|
|
93
|
+
const handleLogin = async () => {
|
|
94
|
+
const result = await loginAsMerchant('merchant@example.com', 'password');
|
|
95
|
+
if (result.success) {
|
|
96
|
+
console.log('✅ Logged in!', result.token);
|
|
97
|
+
} else {
|
|
98
|
+
console.error('❌ Login failed:', result.error?.message);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (!isInitialized) return <div>🔄 Loading SDK...</div>;
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div>
|
|
106
|
+
{isAuthenticated ? (
|
|
107
|
+
<p>👋 Welcome, {currentUser?.email}!</p>
|
|
108
|
+
) : (
|
|
109
|
+
<button onClick={handleLogin}>Login</button>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Option 2: Manual Initialization
|
|
67
117
|
|
|
68
118
|
```typescript
|
|
69
|
-
import {
|
|
119
|
+
import { initializeEReceipts } from '@a-cube-io/ereceipts-js-sdk';
|
|
70
120
|
|
|
71
121
|
// Initialize SDK (call once at app startup)
|
|
72
|
-
await
|
|
73
|
-
environment: 'sandbox', //
|
|
122
|
+
await initializeEReceipts({
|
|
123
|
+
environment: 'sandbox', // 'sandbox' | 'production' | 'development'
|
|
74
124
|
enableLogging: true,
|
|
75
125
|
enableRetry: true,
|
|
76
126
|
enableOfflineQueue: true
|
|
77
127
|
});
|
|
78
128
|
```
|
|
79
129
|
|
|
80
|
-
### 2. Authentication
|
|
130
|
+
### 2. Authentication (User-Friendly)
|
|
81
131
|
|
|
82
132
|
```typescript
|
|
83
|
-
import {
|
|
133
|
+
import { loginAsProvider, loginAsMerchant, loginAsCashier } from '@a-cube-io/ereceipts-js-sdk';
|
|
84
134
|
|
|
85
135
|
// Login as Provider (highest privileges)
|
|
86
|
-
const
|
|
136
|
+
const providerResult = await loginAsProvider('provider@company.com', 'password123');
|
|
137
|
+
if (providerResult.success) {
|
|
138
|
+
console.log('✅ Provider logged in:', providerResult.token);
|
|
139
|
+
} else {
|
|
140
|
+
console.error('❌ Login failed:', providerResult.error?.message);
|
|
141
|
+
}
|
|
87
142
|
|
|
88
143
|
// Login as Merchant (business owner)
|
|
89
|
-
const
|
|
144
|
+
const merchantResult = await loginAsMerchant('merchant@restaurant.com', 'password123');
|
|
90
145
|
|
|
91
146
|
// Login as Cashier (operational level)
|
|
92
|
-
const
|
|
147
|
+
const cashierResult = await loginAsCashier('cashier@store.com', 'password123');
|
|
93
148
|
```
|
|
94
149
|
|
|
95
150
|
### 3. Create Your First Receipt
|
|
@@ -114,63 +169,179 @@ const receipt = await createReceipt({
|
|
|
114
169
|
console.log('Receipt created:', receipt.uuid);
|
|
115
170
|
```
|
|
116
171
|
|
|
117
|
-
### 4.
|
|
172
|
+
### 4. Complete App Example
|
|
118
173
|
|
|
119
|
-
```
|
|
120
|
-
import React from 'react';
|
|
121
|
-
import {
|
|
174
|
+
```tsx
|
|
175
|
+
import React, { useState } from 'react';
|
|
176
|
+
import {
|
|
177
|
+
EReceiptsProvider,
|
|
178
|
+
useEReceipts,
|
|
179
|
+
loginAsMerchant,
|
|
180
|
+
logoutUser,
|
|
181
|
+
createReceipt,
|
|
182
|
+
Button,
|
|
183
|
+
FormInput
|
|
184
|
+
} from '@a-cube-io/ereceipts-js-sdk';
|
|
122
185
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
186
|
+
// App with Provider
|
|
187
|
+
function App() {
|
|
188
|
+
return (
|
|
189
|
+
<EReceiptsProvider
|
|
190
|
+
config={{
|
|
191
|
+
environment: 'sandbox',
|
|
192
|
+
enableLogging: true,
|
|
193
|
+
onInitialized: () => console.log('🚀 E-Receipts SDK Ready!'),
|
|
194
|
+
onAuthChange: (isAuth) => console.log('🔐 Auth Status:', isAuth ? 'Logged In' : 'Logged Out')
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
<AppContent />
|
|
198
|
+
</EReceiptsProvider>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Main app content
|
|
203
|
+
function AppContent() {
|
|
204
|
+
const { isInitialized, isLoading, isAuthenticated, currentUser, error } = useEReceipts();
|
|
205
|
+
const [email, setEmail] = useState('');
|
|
206
|
+
const [password, setPassword] = useState('');
|
|
207
|
+
const [loginLoading, setLoginLoading] = useState(false);
|
|
127
208
|
|
|
128
209
|
const handleLogin = async () => {
|
|
129
|
-
|
|
210
|
+
setLoginLoading(true);
|
|
211
|
+
const result = await loginAsMerchant(email, password);
|
|
212
|
+
if (result.success) {
|
|
213
|
+
console.log('✅ Login successful!');
|
|
214
|
+
// Provider automatically updates auth state
|
|
215
|
+
} else {
|
|
216
|
+
alert(`❌ Login failed: ${result.error?.message}`);
|
|
217
|
+
}
|
|
218
|
+
setLoginLoading(false);
|
|
130
219
|
};
|
|
131
220
|
|
|
221
|
+
const handleLogout = async () => {
|
|
222
|
+
const result = await logoutUser();
|
|
223
|
+
if (result.success) {
|
|
224
|
+
console.log('✅ Logged out successfully');
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const handleCreateReceipt = async () => {
|
|
229
|
+
const receipt = await createReceipt({
|
|
230
|
+
items: [{
|
|
231
|
+
description: 'Test Product',
|
|
232
|
+
quantity: '1.00',
|
|
233
|
+
unit_price: '10.00',
|
|
234
|
+
good_or_service: 'B',
|
|
235
|
+
vat_rate_code: '22'
|
|
236
|
+
}],
|
|
237
|
+
cash_payment_amount: '10.00'
|
|
238
|
+
});
|
|
239
|
+
console.log('📄 Receipt created:', receipt.uuid);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// Loading state
|
|
243
|
+
if (isLoading) {
|
|
244
|
+
return <div>🔄 Initializing E-Receipts SDK...</div>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Error state
|
|
248
|
+
if (error) {
|
|
249
|
+
return <div>❌ SDK Error: {error.message}</div>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Not initialized
|
|
253
|
+
if (!isInitialized) {
|
|
254
|
+
return <div>⏳ SDK not ready...</div>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Login screen
|
|
258
|
+
if (!isAuthenticated) {
|
|
259
|
+
return (
|
|
260
|
+
<div style={{ padding: '20px', maxWidth: '400px' }}>
|
|
261
|
+
<h2>🔐 Login to E-Receipts</h2>
|
|
262
|
+
|
|
263
|
+
<FormInput
|
|
264
|
+
label="Email"
|
|
265
|
+
value={email}
|
|
266
|
+
onChangeText={setEmail}
|
|
267
|
+
keyboardType="email-address"
|
|
268
|
+
required
|
|
269
|
+
/>
|
|
270
|
+
|
|
271
|
+
<FormInput
|
|
272
|
+
label="Password"
|
|
273
|
+
value={password}
|
|
274
|
+
onChangeText={setPassword}
|
|
275
|
+
secureTextEntry
|
|
276
|
+
showPasswordToggle
|
|
277
|
+
required
|
|
278
|
+
/>
|
|
279
|
+
|
|
280
|
+
<Button
|
|
281
|
+
title="Login as Merchant"
|
|
282
|
+
onPress={handleLogin}
|
|
283
|
+
loading={loginLoading}
|
|
284
|
+
disabled={!email || !password}
|
|
285
|
+
/>
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Authenticated dashboard
|
|
132
291
|
return (
|
|
133
|
-
<div>
|
|
134
|
-
<
|
|
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
|
-
/>
|
|
292
|
+
<div style={{ padding: '20px' }}>
|
|
293
|
+
<h1>📱 E-Receipts Dashboard</h1>
|
|
150
294
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
295
|
+
<div style={{ marginBottom: '20px', padding: '10px', backgroundColor: '#f0f0f0' }}>
|
|
296
|
+
<p>👋 Welcome, <strong>{currentUser?.email}</strong></p>
|
|
297
|
+
<p>🏷️ Role: <strong>{currentUser?.role}</strong></p>
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap' }}>
|
|
301
|
+
<Button
|
|
302
|
+
title="📄 Create Test Receipt"
|
|
303
|
+
onPress={handleCreateReceipt}
|
|
304
|
+
/>
|
|
305
|
+
|
|
306
|
+
<Button
|
|
307
|
+
title="🚪 Logout"
|
|
308
|
+
onPress={handleLogout}
|
|
309
|
+
variant="secondary"
|
|
310
|
+
/>
|
|
311
|
+
</div>
|
|
159
312
|
</div>
|
|
160
313
|
);
|
|
161
314
|
}
|
|
315
|
+
|
|
316
|
+
export default App;
|
|
162
317
|
```
|
|
163
318
|
|
|
164
319
|
## 📚 API Reference
|
|
165
320
|
|
|
166
|
-
###
|
|
167
|
-
- `
|
|
168
|
-
- `
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
-
|
|
172
|
-
- `
|
|
173
|
-
- `
|
|
321
|
+
### SDK Initialization
|
|
322
|
+
- `initializeEReceipts(config)` - Initialize the E-Receipts SDK
|
|
323
|
+
- `checkSDKStatus()` - Check if SDK is ready to use
|
|
324
|
+
|
|
325
|
+
### React Provider
|
|
326
|
+
- `<EReceiptsProvider>` - React Provider for automatic SDK setup
|
|
327
|
+
- `useEReceipts()` - Hook to access SDK state and methods
|
|
328
|
+
- `withEReceipts(Component)` - Higher-order component wrapper
|
|
329
|
+
|
|
330
|
+
### Authentication (User-Friendly)
|
|
331
|
+
- `loginAsProvider(email, password)` - Provider authentication with error handling
|
|
332
|
+
- `loginAsMerchant(email, password)` - Merchant authentication with error handling
|
|
333
|
+
- `loginAsCashier(email, password)` - Cashier authentication with error handling
|
|
334
|
+
- `logoutUser()` - Logout current user with error handling
|
|
335
|
+
- `checkAuthentication()` - Check if user is authenticated
|
|
336
|
+
- `getCurrentUserInfo()` - Get current user information
|
|
337
|
+
|
|
338
|
+
### Legacy Authentication (Backward Compatibility)
|
|
339
|
+
- `loginProvider(email, password)` - Direct provider authentication
|
|
340
|
+
- `loginMerchant(email, password)` - Direct merchant authentication
|
|
341
|
+
- `loginCashier(email, password)` - Direct cashier authentication
|
|
342
|
+
- `logout()` - Direct logout
|
|
343
|
+
- `isAuthenticated()` - Direct authentication check
|
|
344
|
+
- `getCurrentUser()` - Direct user info retrieval
|
|
174
345
|
|
|
175
346
|
### Receipt Management
|
|
176
347
|
- `createReceipt(data)` - Create new receipt
|
|
@@ -201,7 +372,7 @@ function LoginScreen() {
|
|
|
201
372
|
import { initSDK } from '@a-cube-io/ereceipts-js-sdk';
|
|
202
373
|
|
|
203
374
|
await initSDK({
|
|
204
|
-
environment: 'sandbox', // 'sandbox' | 'production'
|
|
375
|
+
environment: 'sandbox', // 'sandbox' | 'production' | 'development'
|
|
205
376
|
enableLogging: true, // Enable debug logging
|
|
206
377
|
enableRetry: true, // Enable automatic retries
|
|
207
378
|
maxRetries: 3, // Maximum retry attempts
|
|
@@ -211,6 +382,31 @@ await initSDK({
|
|
|
211
382
|
});
|
|
212
383
|
```
|
|
213
384
|
|
|
385
|
+
### API Architecture
|
|
386
|
+
|
|
387
|
+
The SDK automatically handles different API endpoints:
|
|
388
|
+
|
|
389
|
+
| Mode | Purpose | Default Environment | Base URL |
|
|
390
|
+
|------|---------|-------------------|-----------|
|
|
391
|
+
| **API Mode** | E-receipt operations (receipts, POS, merchants) | `sandbox` | `ereceipts-it-sandbox.acubeapi.com` |
|
|
392
|
+
| **Auth Mode** | Authentication endpoints | `sandbox` | `common-sandbox.api.acubeapi.com` |
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
// API mode is used by default for most operations
|
|
396
|
+
import { getAPIClient } from '@a-cube-io/ereceipts-js-sdk';
|
|
397
|
+
|
|
398
|
+
// Auth mode is automatically used for authentication
|
|
399
|
+
import { loginMerchant } from '@a-cube-io/ereceipts-js-sdk';
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Environment Configuration
|
|
403
|
+
|
|
404
|
+
| Environment | API Endpoint | Auth Endpoint | Usage |
|
|
405
|
+
|-------------|-------------|---------------|--------|
|
|
406
|
+
| **`sandbox`** (default) | `ereceipts-it-sandbox.acubeapi.com` | `common-sandbox.api.acubeapi.com` | Development & testing |
|
|
407
|
+
| **`production`** | `ereceipts-it.acubeapi.com` | `common.api.acubeapi.com` | Production deployment |
|
|
408
|
+
| **`development`** | `ereceipts-it.dev.acubeapi.com` | `common-sandbox.api.acubeapi.com` | Local development |
|
|
409
|
+
|
|
214
410
|
### Platform-Specific Configuration
|
|
215
411
|
|
|
216
412
|
#### React Native
|
|
@@ -402,19 +598,26 @@ const receiptData: ReceiptInput = {
|
|
|
402
598
|
|
|
403
599
|
## 🐛 Troubleshooting
|
|
404
600
|
|
|
405
|
-
### React Native Issues
|
|
601
|
+
### React Native/Expo Issues
|
|
602
|
+
|
|
603
|
+
1. **Node.js module imports error (Fixed in v1.0.5+)**:
|
|
604
|
+
```
|
|
605
|
+
The package attempted to import the Node standard library module "url".
|
|
606
|
+
It failed because the native React runtime does not include the Node standard library.
|
|
607
|
+
```
|
|
608
|
+
**Solution**: Update to SDK version 1.0.5 or higher - we've fixed React Native/Expo compatibility by properly externalizing axios and preventing Node.js module bundling.
|
|
406
609
|
|
|
407
|
-
|
|
610
|
+
2. **Keychain errors on iOS**:
|
|
408
611
|
```bash
|
|
409
612
|
cd ios && pod install
|
|
410
613
|
```
|
|
411
614
|
|
|
412
|
-
|
|
615
|
+
3. **AsyncStorage warnings**:
|
|
413
616
|
```bash
|
|
414
617
|
npm install @react-native-async-storage/async-storage
|
|
415
618
|
```
|
|
416
619
|
|
|
417
|
-
|
|
620
|
+
4. **Network detection issues**:
|
|
418
621
|
```bash
|
|
419
622
|
npm install @react-native-community/netinfo
|
|
420
623
|
```
|