cargos-sdk 0.1.3 → 0.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/README.md +45 -11
- package/dist/cargos-sdk.cjs +8268 -4
- package/dist/cargos-sdk.d.ts +1 -0
- package/dist/cargos-sdk.d.ts.map +1 -1
- package/dist/cargos-sdk.js +8268 -4
- package/dist/tables.d.ts +36 -0
- package/dist/tables.d.ts.map +1 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -28,7 +28,8 @@ The system verifies driver eligibility and checks for security concerns in real-
|
|
|
28
28
|
- ✅ Contract validation before submission
|
|
29
29
|
- ✅ Batch processing (automatic chunking for 100+ contracts)
|
|
30
30
|
- ✅ Check contracts before sending
|
|
31
|
-
- ✅
|
|
31
|
+
- ✅ Bundled static coding tables with lookup helpers
|
|
32
|
+
- ✅ Runtime table download methods for fresh snapshots
|
|
32
33
|
- ✅ Comprehensive error handling
|
|
33
34
|
|
|
34
35
|
## Installation
|
|
@@ -45,6 +46,32 @@ Or import directly:
|
|
|
45
46
|
import { CargosClient, RentalContract, PaymentType } from './cargos-sdk';
|
|
46
47
|
```
|
|
47
48
|
|
|
49
|
+
## Bundled Reference Tables
|
|
50
|
+
|
|
51
|
+
Reference tables are bundled in the SDK and can be used without authentication:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { LOCATIONS, getLocationCode, lookupLocation } from 'cargos-sdk';
|
|
55
|
+
|
|
56
|
+
const romeCode = getLocationCode('ROMA'); // 412058091
|
|
57
|
+
const cityName = lookupLocation(412058091); // "ROMA"
|
|
58
|
+
const italyCode = LOCATIONS['ITALIA']; // 100000100
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Table snapshot metadata is published in [`TABLES_LAST_UPDATED.md`](./TABLES_LAST_UPDATED.md). If the snapshot looks stale, please open an issue.
|
|
62
|
+
|
|
63
|
+
To regenerate the bundled snapshot after replacing CSV exports in `scripts/tables-csv/`:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm run generate:tables
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To download the latest CSVs from CARGOS first:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm run download:tables
|
|
73
|
+
```
|
|
74
|
+
|
|
48
75
|
## Quick Start
|
|
49
76
|
|
|
50
77
|
```typescript
|
|
@@ -199,7 +226,7 @@ Available tables:
|
|
|
199
226
|
|
|
200
227
|
### getAllTables()
|
|
201
228
|
|
|
202
|
-
Download all coding tables at once:
|
|
229
|
+
Download all coding tables at once (useful when you need a fresh runtime snapshot):
|
|
203
230
|
|
|
204
231
|
```typescript
|
|
205
232
|
const tables = await client.getAllTables();
|
|
@@ -263,13 +290,13 @@ interface Location {
|
|
|
263
290
|
```
|
|
264
291
|
|
|
265
292
|
Common location codes:
|
|
266
|
-
-
|
|
267
|
-
-
|
|
268
|
-
-
|
|
269
|
-
-
|
|
270
|
-
-
|
|
293
|
+
- ROMA: 412058091
|
|
294
|
+
- MILANO: 403015146
|
|
295
|
+
- NAPOLI: 415063049
|
|
296
|
+
- TORINO: 401001272
|
|
297
|
+
- FIRENZE: 409048017
|
|
271
298
|
|
|
272
|
-
|
|
299
|
+
Use bundled `LOCATIONS` for offline lookups, or `getAllTables()` if you need a fresh runtime export.
|
|
273
300
|
|
|
274
301
|
### Driver
|
|
275
302
|
|
|
@@ -371,7 +398,7 @@ Checks:
|
|
|
371
398
|
1. **Prepare** contract data from your rental management system
|
|
372
399
|
2. **Validate** with `isValidContractData()`
|
|
373
400
|
3. **Check** with `checkContracts()` (optional but recommended)
|
|
374
|
-
4. **
|
|
401
|
+
4. **Use bundled tables** (`LOCATIONS`, `getLocationCode()`, etc.) for local lookups
|
|
375
402
|
5. **Send** with `sendContracts()` or `batchSendContracts()`
|
|
376
403
|
6. **Store** transaction IDs for audit trail
|
|
377
404
|
|
|
@@ -529,7 +556,8 @@ All communication with Cargos service is over HTTPS (TLS 1.2+).
|
|
|
529
556
|
|
|
530
557
|
### "Invalid location code" Error
|
|
531
558
|
|
|
532
|
-
-
|
|
559
|
+
- Check bundled `LOCATIONS` first for valid codes
|
|
560
|
+
- If needed, refresh from API with `getAllTables()`
|
|
533
561
|
- Location codes reference specific police jurisdictions
|
|
534
562
|
- Use exact numeric code from the table
|
|
535
563
|
|
|
@@ -550,6 +578,7 @@ All communication with Cargos service is over HTTPS (TLS 1.2+).
|
|
|
550
578
|
See `cargos-example.ts` for:
|
|
551
579
|
- Basic single contract submission
|
|
552
580
|
- Batch processing (100+ contracts)
|
|
581
|
+
- Bundled table lookups
|
|
553
582
|
- Downloading and parsing tables
|
|
554
583
|
- Secondary driver handling
|
|
555
584
|
- Error handling patterns
|
|
@@ -580,6 +609,11 @@ function isValidContractData(contract: RentalContract): string[];
|
|
|
580
609
|
|
|
581
610
|
// Parse table CSV (# separated, UTF-8)
|
|
582
611
|
function parseTableCSV(data: Buffer): Map<string, string>;
|
|
612
|
+
|
|
613
|
+
// Bundled table lookups
|
|
614
|
+
function getLocationCode(locationName: string): number | undefined;
|
|
615
|
+
function lookupLocation(code: number): string | undefined;
|
|
616
|
+
const TABLES_LAST_UPDATED_AT: string;
|
|
583
617
|
```
|
|
584
618
|
|
|
585
619
|
## Technical Details
|
|
@@ -639,7 +673,7 @@ This SDK implements the technical specifications from:
|
|
|
639
673
|
For issues or questions:
|
|
640
674
|
|
|
641
675
|
1. Check `checkContracts()` output for validation details
|
|
642
|
-
2.
|
|
676
|
+
2. Check [`TABLES_LAST_UPDATED.md`](./TABLES_LAST_UPDATED.md) and open an issue if an update is needed
|
|
643
677
|
3. Review CARGOS documentation: https://cargos.poliziadistato.it
|
|
644
678
|
4. Contact your provincial Questura
|
|
645
679
|
|