@a-cube-io/ereceipts-js-sdk 1.0.3 → 1.0.4

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.
Files changed (32) hide show
  1. package/README.md +246 -53
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{auth-RZRIC4PK.js → auth-4AJ5UPDT.js} +4 -4
  4. package/dist/{auth-RZRIC4PK.js.map → auth-4AJ5UPDT.js.map} +1 -1
  5. package/dist/{auth-D6UEILKY.cjs → auth-PILEVMWR.cjs} +15 -15
  6. package/dist/{auth-D6UEILKY.cjs.map → auth-PILEVMWR.cjs.map} +1 -1
  7. package/dist/{chunk-C3YEL4ED.js → chunk-4RWH43LJ.js} +6 -6
  8. package/dist/chunk-4RWH43LJ.js.map +1 -0
  9. package/dist/{chunk-UVUWF5FV.cjs → chunk-NQC6CVNB.cjs} +59 -7
  10. package/dist/chunk-NQC6CVNB.cjs.map +1 -0
  11. package/dist/{chunk-UXVFQRZK.cjs → chunk-RYQ54ERE.cjs} +10 -10
  12. package/dist/chunk-RYQ54ERE.cjs.map +1 -0
  13. package/dist/{chunk-VDHN3FKS.js → chunk-YE75QGEV.js} +57 -8
  14. package/dist/chunk-YE75QGEV.js.map +1 -0
  15. package/dist/client-H4QJNI4Z.cjs +35 -0
  16. package/dist/{client-WPBRHPKX.cjs.map → client-H4QJNI4Z.cjs.map} +1 -1
  17. package/dist/{client-Z2LXQJMF.js → client-RDKNDDEC.js} +3 -3
  18. package/dist/{client-Z2LXQJMF.js.map → client-RDKNDDEC.js.map} +1 -1
  19. package/dist/index.cjs +353 -136
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +292 -21
  22. package/dist/index.d.ts +292 -21
  23. package/dist/index.js +228 -30
  24. package/dist/index.js.map +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/dist/metafile-esm.json +1 -1
  27. package/package.json +1 -1
  28. package/dist/chunk-C3YEL4ED.js.map +0 -1
  29. package/dist/chunk-UVUWF5FV.cjs.map +0 -1
  30. package/dist/chunk-UXVFQRZK.cjs.map +0 -1
  31. package/dist/chunk-VDHN3FKS.js.map +0 -1
  32. package/dist/client-WPBRHPKX.cjs +0 -31
package/README.md CHANGED
@@ -31,7 +31,7 @@ A comprehensive, cross-platform SDK for integrating the Italian A-Cube e-receipt
31
31
  | Section | Description | Links |
32
32
  |---------|-------------|-------|
33
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) |
34
+ | **📚 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
35
  | **💡 Examples** | Code samples | [React Examples](examples/react/) • [React Native Examples](examples/react-native/) • [Advanced Usage](USAGE_EXAMPLE.md) |
36
36
  | **🔒 Security** | Token & certificate management | [Secure Storage](#-secure-token-storage) • [mTLS Certificates](docs/security/mtls.md) |
37
37
  | **🛠️ Development** | SDK development & contribution | [Building](docs/development/building.md) • [Testing](docs/development/testing.md) • [Contributing](CONTRIBUTING.md) |
@@ -63,33 +63,85 @@ For **React Web** projects:
63
63
 
64
64
  ## 🚀 Quick Start
65
65
 
66
- ### 1. Initialize the SDK
66
+ ### Option 1: React Provider (Recommended for React Apps)
67
+
68
+ ```tsx
69
+ import React from 'react';
70
+ import { EReceiptsProvider, useEReceipts, loginAsMerchant } from '@a-cube-io/ereceipts-js-sdk';
71
+
72
+ function App() {
73
+ return (
74
+ <EReceiptsProvider
75
+ config={{
76
+ environment: 'sandbox',
77
+ enableLogging: true,
78
+ onInitialized: () => console.log('✅ SDK Ready!'),
79
+ onAuthChange: (isAuth) => console.log('🔐 Auth:', isAuth)
80
+ }}
81
+ >
82
+ <AppContent />
83
+ </EReceiptsProvider>
84
+ );
85
+ }
86
+
87
+ function AppContent() {
88
+ const { isInitialized, isAuthenticated, currentUser } = useEReceipts();
89
+
90
+ const handleLogin = async () => {
91
+ const result = await loginAsMerchant('merchant@example.com', 'password');
92
+ if (result.success) {
93
+ console.log('✅ Logged in!', result.token);
94
+ } else {
95
+ console.error('❌ Login failed:', result.error?.message);
96
+ }
97
+ };
98
+
99
+ if (!isInitialized) return <div>🔄 Loading SDK...</div>;
100
+
101
+ return (
102
+ <div>
103
+ {isAuthenticated ? (
104
+ <p>👋 Welcome, {currentUser?.email}!</p>
105
+ ) : (
106
+ <button onClick={handleLogin}>Login</button>
107
+ )}
108
+ </div>
109
+ );
110
+ }
111
+ ```
112
+
113
+ ### Option 2: Manual Initialization
67
114
 
68
115
  ```typescript
69
- import { initSDK } from '@a-cube-io/ereceipts-js-sdk';
116
+ import { initializeEReceipts } from '@a-cube-io/ereceipts-js-sdk';
70
117
 
71
118
  // Initialize SDK (call once at app startup)
72
- await initSDK({
73
- environment: 'sandbox', // or 'production'
119
+ await initializeEReceipts({
120
+ environment: 'sandbox', // 'sandbox' | 'production' | 'development'
74
121
  enableLogging: true,
75
122
  enableRetry: true,
76
123
  enableOfflineQueue: true
77
124
  });
78
125
  ```
79
126
 
80
- ### 2. Authentication
127
+ ### 2. Authentication (User-Friendly)
81
128
 
82
129
  ```typescript
83
- import { loginProvider, loginMerchant, loginCashier } from '@a-cube-io/ereceipts-js-sdk';
130
+ import { loginAsProvider, loginAsMerchant, loginAsCashier } from '@a-cube-io/ereceipts-js-sdk';
84
131
 
85
132
  // Login as Provider (highest privileges)
86
- const providerToken = await loginProvider('provider@company.com', 'password123');
133
+ const providerResult = await loginAsProvider('provider@company.com', 'password123');
134
+ if (providerResult.success) {
135
+ console.log('✅ Provider logged in:', providerResult.token);
136
+ } else {
137
+ console.error('❌ Login failed:', providerResult.error?.message);
138
+ }
87
139
 
88
140
  // Login as Merchant (business owner)
89
- const merchantToken = await loginMerchant('merchant@restaurant.com', 'password123');
141
+ const merchantResult = await loginAsMerchant('merchant@restaurant.com', 'password123');
90
142
 
91
143
  // Login as Cashier (operational level)
92
- const cashierToken = await loginCashier('cashier@store.com', 'password123');
144
+ const cashierResult = await loginAsCashier('cashier@store.com', 'password123');
93
145
  ```
94
146
 
95
147
  ### 3. Create Your First Receipt
@@ -114,63 +166,179 @@ const receipt = await createReceipt({
114
166
  console.log('Receipt created:', receipt.uuid);
115
167
  ```
116
168
 
117
- ### 4. Using React Components
169
+ ### 4. Complete App Example
118
170
 
119
- ```typescript
120
- import React from 'react';
121
- import { Button, FormInput, useAuth } from '@a-cube-io/ereceipts-js-sdk';
171
+ ```tsx
172
+ import React, { useState } from 'react';
173
+ import {
174
+ EReceiptsProvider,
175
+ useEReceipts,
176
+ loginAsMerchant,
177
+ logoutUser,
178
+ createReceipt,
179
+ Button,
180
+ FormInput
181
+ } from '@a-cube-io/ereceipts-js-sdk';
122
182
 
123
- function LoginScreen() {
124
- const { loginAsMerchant, isLoading, error } = useAuth();
125
- const [email, setEmail] = React.useState('');
126
- const [password, setPassword] = React.useState('');
183
+ // App with Provider
184
+ function App() {
185
+ return (
186
+ <EReceiptsProvider
187
+ config={{
188
+ environment: 'sandbox',
189
+ enableLogging: true,
190
+ onInitialized: () => console.log('🚀 E-Receipts SDK Ready!'),
191
+ onAuthChange: (isAuth) => console.log('🔐 Auth Status:', isAuth ? 'Logged In' : 'Logged Out')
192
+ }}
193
+ >
194
+ <AppContent />
195
+ </EReceiptsProvider>
196
+ );
197
+ }
198
+
199
+ // Main app content
200
+ function AppContent() {
201
+ const { isInitialized, isLoading, isAuthenticated, currentUser, error } = useEReceipts();
202
+ const [email, setEmail] = useState('');
203
+ const [password, setPassword] = useState('');
204
+ const [loginLoading, setLoginLoading] = useState(false);
127
205
 
128
206
  const handleLogin = async () => {
129
- await loginAsMerchant(email, password);
207
+ setLoginLoading(true);
208
+ const result = await loginAsMerchant(email, password);
209
+ if (result.success) {
210
+ console.log('✅ Login successful!');
211
+ // Provider automatically updates auth state
212
+ } else {
213
+ alert(`❌ Login failed: ${result.error?.message}`);
214
+ }
215
+ setLoginLoading(false);
130
216
  };
131
217
 
218
+ const handleLogout = async () => {
219
+ const result = await logoutUser();
220
+ if (result.success) {
221
+ console.log('✅ Logged out successfully');
222
+ }
223
+ };
224
+
225
+ const handleCreateReceipt = async () => {
226
+ const receipt = await createReceipt({
227
+ items: [{
228
+ description: 'Test Product',
229
+ quantity: '1.00',
230
+ unit_price: '10.00',
231
+ good_or_service: 'B',
232
+ vat_rate_code: '22'
233
+ }],
234
+ cash_payment_amount: '10.00'
235
+ });
236
+ console.log('📄 Receipt created:', receipt.uuid);
237
+ };
238
+
239
+ // Loading state
240
+ if (isLoading) {
241
+ return <div>🔄 Initializing E-Receipts SDK...</div>;
242
+ }
243
+
244
+ // Error state
245
+ if (error) {
246
+ return <div>❌ SDK Error: {error.message}</div>;
247
+ }
248
+
249
+ // Not initialized
250
+ if (!isInitialized) {
251
+ return <div>⏳ SDK not ready...</div>;
252
+ }
253
+
254
+ // Login screen
255
+ if (!isAuthenticated) {
256
+ return (
257
+ <div style={{ padding: '20px', maxWidth: '400px' }}>
258
+ <h2>🔐 Login to E-Receipts</h2>
259
+
260
+ <FormInput
261
+ label="Email"
262
+ value={email}
263
+ onChangeText={setEmail}
264
+ keyboardType="email-address"
265
+ required
266
+ />
267
+
268
+ <FormInput
269
+ label="Password"
270
+ value={password}
271
+ onChangeText={setPassword}
272
+ secureTextEntry
273
+ showPasswordToggle
274
+ required
275
+ />
276
+
277
+ <Button
278
+ title="Login as Merchant"
279
+ onPress={handleLogin}
280
+ loading={loginLoading}
281
+ disabled={!email || !password}
282
+ />
283
+ </div>
284
+ );
285
+ }
286
+
287
+ // Authenticated dashboard
132
288
  return (
133
- <div>
134
- <FormInput
135
- label="Email"
136
- value={email}
137
- onChangeText={setEmail}
138
- keyboardType="email-address"
139
- required
140
- />
289
+ <div style={{ padding: '20px' }}>
290
+ <h1>📱 E-Receipts Dashboard</h1>
141
291
 
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
- />
292
+ <div style={{ marginBottom: '20px', padding: '10px', backgroundColor: '#f0f0f0' }}>
293
+ <p>👋 Welcome, <strong>{currentUser?.email}</strong></p>
294
+ <p>🏷️ Role: <strong>{currentUser?.role}</strong></p>
295
+ </div>
296
+
297
+ <div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap' }}>
298
+ <Button
299
+ title="📄 Create Test Receipt"
300
+ onPress={handleCreateReceipt}
301
+ />
302
+
303
+ <Button
304
+ title="🚪 Logout"
305
+ onPress={handleLogout}
306
+ variant="secondary"
307
+ />
308
+ </div>
159
309
  </div>
160
310
  );
161
311
  }
312
+
313
+ export default App;
162
314
  ```
163
315
 
164
316
  ## 📚 API Reference
165
317
 
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
318
+ ### SDK Initialization
319
+ - `initializeEReceipts(config)` - Initialize the E-Receipts SDK
320
+ - `checkSDKStatus()` - Check if SDK is ready to use
321
+
322
+ ### React Provider
323
+ - `<EReceiptsProvider>` - React Provider for automatic SDK setup
324
+ - `useEReceipts()` - Hook to access SDK state and methods
325
+ - `withEReceipts(Component)` - Higher-order component wrapper
326
+
327
+ ### Authentication (User-Friendly)
328
+ - `loginAsProvider(email, password)` - Provider authentication with error handling
329
+ - `loginAsMerchant(email, password)` - Merchant authentication with error handling
330
+ - `loginAsCashier(email, password)` - Cashier authentication with error handling
331
+ - `logoutUser()` - Logout current user with error handling
332
+ - `checkAuthentication()` - Check if user is authenticated
333
+ - `getCurrentUserInfo()` - Get current user information
334
+
335
+ ### Legacy Authentication (Backward Compatibility)
336
+ - `loginProvider(email, password)` - Direct provider authentication
337
+ - `loginMerchant(email, password)` - Direct merchant authentication
338
+ - `loginCashier(email, password)` - Direct cashier authentication
339
+ - `logout()` - Direct logout
340
+ - `isAuthenticated()` - Direct authentication check
341
+ - `getCurrentUser()` - Direct user info retrieval
174
342
 
175
343
  ### Receipt Management
176
344
  - `createReceipt(data)` - Create new receipt
@@ -201,7 +369,7 @@ function LoginScreen() {
201
369
  import { initSDK } from '@a-cube-io/ereceipts-js-sdk';
202
370
 
203
371
  await initSDK({
204
- environment: 'sandbox', // 'sandbox' | 'production'
372
+ environment: 'sandbox', // 'sandbox' | 'production' | 'development'
205
373
  enableLogging: true, // Enable debug logging
206
374
  enableRetry: true, // Enable automatic retries
207
375
  maxRetries: 3, // Maximum retry attempts
@@ -211,6 +379,31 @@ await initSDK({
211
379
  });
212
380
  ```
213
381
 
382
+ ### API Architecture
383
+
384
+ The SDK automatically handles different API endpoints:
385
+
386
+ | Mode | Purpose | Default Environment | Base URL |
387
+ |------|---------|-------------------|-----------|
388
+ | **API Mode** | E-receipt operations (receipts, POS, merchants) | `sandbox` | `ereceipts-it-sandbox.acubeapi.com` |
389
+ | **Auth Mode** | Authentication endpoints | `sandbox` | `common-sandbox.api.acubeapi.com` |
390
+
391
+ ```typescript
392
+ // API mode is used by default for most operations
393
+ import { getAPIClient } from '@a-cube-io/ereceipts-js-sdk';
394
+
395
+ // Auth mode is automatically used for authentication
396
+ import { loginMerchant } from '@a-cube-io/ereceipts-js-sdk';
397
+ ```
398
+
399
+ ### Environment Configuration
400
+
401
+ | Environment | API Endpoint | Auth Endpoint | Usage |
402
+ |-------------|-------------|---------------|--------|
403
+ | **`sandbox`** (default) | `ereceipts-it-sandbox.acubeapi.com` | `common-sandbox.api.acubeapi.com` | Development & testing |
404
+ | **`production`** | `ereceipts-it.acubeapi.com` | `common.api.acubeapi.com` | Production deployment |
405
+ | **`development`** | `ereceipts-it.dev.acubeapi.com` | `common-sandbox.api.acubeapi.com` | Local development |
406
+
214
407
  ### Platform-Specific Configuration
215
408
 
216
409
  #### React Native