aves-sdk 4.0.1 → 5.0.1
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/CHANGELOG.md +141 -1
- package/README.md +170 -52
- package/dist/CHANGELOG.md +141 -1
- package/dist/index.d.mts +8990 -21231
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AVES SDK
|
|
2
2
|
|
|
3
|
-
Type-safe TypeScript SDK for the AVES XML REST API. Handles XML parsing,
|
|
3
|
+
Type-safe TypeScript SDK for the AVES XML REST API. Handles XML parsing, **Effect Schema** validation, camelCase ↔ PascalCase / `@` attrs, and `@effect/platform` HTTP. Public domain methods return `Result` (they do not throw). Effect apps can also `yield*` domain Tags via Layers / `makeAvesRuntime`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,61 +14,102 @@ pnpm add aves-sdk
|
|
|
14
14
|
bun add aves-sdk
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
`aves-sdk` depends on `effect` and `@effect/platform`.
|
|
18
|
+
|
|
19
|
+
## Quick start (Promise facade)
|
|
18
20
|
|
|
19
21
|
```typescript
|
|
20
|
-
import { AvesClient } from
|
|
22
|
+
import { AvesClient, isAvesError, type Result } from "aves-sdk";
|
|
21
23
|
|
|
22
24
|
const client = new AvesClient({
|
|
23
|
-
baseURL:
|
|
24
|
-
hostID:
|
|
25
|
-
xtoken:
|
|
26
|
-
languageCode:
|
|
25
|
+
baseURL: "https://api.example.com",
|
|
26
|
+
hostID: "000000", // 6 digits
|
|
27
|
+
xtoken: "TOKEN",
|
|
28
|
+
languageCode: "02", // optional: 01=Italian, 02=English
|
|
27
29
|
timeoutMs: 30_000, // optional
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
const result = await client.master.search({
|
|
31
|
-
searchType:
|
|
32
|
-
recordCode:
|
|
32
|
+
const result: Result<unknown> = await client.master.search({
|
|
33
|
+
searchType: "CODE",
|
|
34
|
+
recordCode: "508558",
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
if (result.success) {
|
|
36
38
|
const [record] = result.data;
|
|
37
39
|
console.log(record?.recordCode);
|
|
38
|
-
} else {
|
|
40
|
+
} else if (isAvesError(result.error)) {
|
|
39
41
|
console.error(result.error.kind, result.error.message, result.error.code);
|
|
40
42
|
}
|
|
41
43
|
```
|
|
42
44
|
|
|
45
|
+
`createAvesClient(options, deps?)` returns the same Promise API as a plain object.
|
|
46
|
+
|
|
47
|
+
## Quick start (Effect)
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Effect } from "effect";
|
|
51
|
+
import { AvesMaster, makeAvesRuntime } from "aves-sdk";
|
|
52
|
+
|
|
53
|
+
const runtime = makeAvesRuntime({
|
|
54
|
+
baseURL: "https://api.example.com",
|
|
55
|
+
hostID: "000000",
|
|
56
|
+
xtoken: "TOKEN",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const records = await runtime.runPromise(
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const master = yield* AvesMaster;
|
|
62
|
+
return yield* master.search({
|
|
63
|
+
searchType: "CODE",
|
|
64
|
+
recordCode: "508558",
|
|
65
|
+
});
|
|
66
|
+
}).pipe(
|
|
67
|
+
Effect.catchTag("AvesApiError", (e) =>
|
|
68
|
+
Effect.succeed({ failed: true as const, code: e.code }),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
await runtime.dispose();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Also: `Effect.provide(avesClientLayer(options, deps))` or `AvesClientLive(options)` for the full stack including `AvesConfig` / `AvesHttp`.
|
|
77
|
+
|
|
43
78
|
## Client shape
|
|
44
79
|
|
|
45
|
-
`AvesClient`
|
|
80
|
+
`AvesClient` / `createAvesClient` expose **Promise** domain namespaces only (`master`, `booking`, `packages`). There is no `client.transport` on the Promise facade — use `AvesTransport` with Layers for Effect programs.
|
|
46
81
|
|
|
47
82
|
```typescript
|
|
48
83
|
await client.booking.create(params);
|
|
84
|
+
await client.booking.exportData(params);
|
|
49
85
|
await client.packages.search(params);
|
|
50
|
-
await client.master.search({ searchType:
|
|
86
|
+
await client.master.search({ searchType: "CODE", recordCode: "508558" });
|
|
51
87
|
```
|
|
52
88
|
|
|
53
89
|
Migration from 1.x: insert the appropriate domain namespace (for example,
|
|
54
|
-
`client.search` → `client.master.search`). See the [2.0.0 migration notes](
|
|
90
|
+
`client.search` → `client.master.search`). See the [2.0.0 migration notes](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md#v2.0.0).
|
|
55
91
|
|
|
56
92
|
Migration from 2.x: `master.search` success is a flat array — see the
|
|
57
|
-
[3.0.0 migration notes](
|
|
93
|
+
[3.0.0 migration notes](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md#v3.0.0).
|
|
58
94
|
|
|
59
95
|
Migration from 3.x: domain method names were shortened — see the
|
|
60
|
-
[4.0.0 migration notes](
|
|
96
|
+
[4.0.0 migration notes](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md#v4.0.0).
|
|
97
|
+
|
|
98
|
+
Migration from 4.x: Effect Schema + platform HTTP + tagged errors — see the
|
|
99
|
+
[5.0.0 migration notes](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md#v5.0.0).
|
|
61
100
|
|
|
62
101
|
| Namespace | Methods |
|
|
63
102
|
| --------- | ------- |
|
|
64
103
|
| `master` | `search`, `upsert` |
|
|
65
|
-
| `booking` | `create`, `updateServices`, `updateHeader`, `cancel`, `setStatus`, `setServiceStatus`, `addPayments`, `search` |
|
|
104
|
+
| `booking` | `create`, `updateServices`, `updateHeader`, `cancel`, `setStatus`, `setServiceStatus`, `addPayments`, `search`, `exportData` |
|
|
66
105
|
| `packages` | `search`, `searchServices`, `get`, `commit` |
|
|
67
106
|
|
|
68
107
|
### Constructor
|
|
69
108
|
|
|
70
109
|
```typescript
|
|
71
110
|
new AvesClient(options: AvesClientOptions, deps?: AvesClientDeps)
|
|
111
|
+
// or
|
|
112
|
+
createAvesClient(options, deps?)
|
|
72
113
|
```
|
|
73
114
|
|
|
74
115
|
| Option | Description |
|
|
@@ -77,30 +118,38 @@ new AvesClient(options: AvesClientOptions, deps?: AvesClientDeps)
|
|
|
77
118
|
| `hostID` | 6-digit host id |
|
|
78
119
|
| `xtoken` | Auth token |
|
|
79
120
|
| `languageCode` | Optional 2-digit language code |
|
|
80
|
-
| `timeoutMs` | Optional request timeout (default 30000) |
|
|
121
|
+
| `timeoutMs` | Optional request timeout in milliseconds (default 30000). A numeric string (e.g. from an env var) is accepted; any other non-positive value throws `AvesValidationError` when the client is created |
|
|
81
122
|
|
|
82
|
-
Optional DI (tests / custom
|
|
123
|
+
Optional DI (tests / custom HTTP):
|
|
83
124
|
|
|
84
125
|
```typescript
|
|
85
|
-
import {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
126
|
+
import { HttpClient, HttpClientResponse } from "@effect/platform";
|
|
127
|
+
import { Effect } from "effect";
|
|
128
|
+
import { AvesClient } from "aves-sdk";
|
|
129
|
+
|
|
130
|
+
const httpClient = HttpClient.make((request, url) =>
|
|
131
|
+
Effect.succeed(
|
|
132
|
+
HttpClientResponse.fromWeb(
|
|
133
|
+
request,
|
|
134
|
+
new Response(xmlBody, { status: 200 }),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
);
|
|
90
138
|
|
|
91
|
-
const transport = new AvesTransport(options);
|
|
92
139
|
new AvesClient(options, {
|
|
93
|
-
|
|
94
|
-
|
|
140
|
+
httpClient,
|
|
141
|
+
// or: http, transport, master, booking, packages service overrides
|
|
95
142
|
});
|
|
96
143
|
```
|
|
97
144
|
|
|
98
145
|
### Result type
|
|
99
146
|
|
|
100
|
-
|
|
147
|
+
Promise domain methods return `Result<T, AvesError>` — they do **not** throw. `Result` is exported from `aves-sdk`.
|
|
101
148
|
|
|
102
149
|
```typescript
|
|
103
|
-
type Result
|
|
150
|
+
import type { Result } from "aves-sdk";
|
|
151
|
+
|
|
152
|
+
type Result<T, E = Error> =
|
|
104
153
|
| { success: true; data: T }
|
|
105
154
|
| { success: false; error: E };
|
|
106
155
|
```
|
|
@@ -108,7 +157,7 @@ type Result<T, E> =
|
|
|
108
157
|
## Simple facade names
|
|
109
158
|
|
|
110
159
|
The facade exposes concise aliases for the AVES payload vocabulary. Inbound
|
|
111
|
-
dual keys are owned by
|
|
160
|
+
dual keys are owned by Effect Schema input schemas (`facadeObject` / `coalesceAliases`)
|
|
112
161
|
and coalesced to AVES camelCase before wire encoding. Outbound success payloads
|
|
113
162
|
keep AVES names and add concise compatibility aliases. XML shapes are unchanged.
|
|
114
163
|
|
|
@@ -410,6 +459,7 @@ if (result.success) {
|
|
|
410
459
|
| `setServiceStatus` | Nullify a single service line |
|
|
411
460
|
| `addPayments` | Register payments |
|
|
412
461
|
| `search` | Search practices (`FILE_CODE`, `PAX_NAME`, `PACKAGE_CODE`, `OTHER`) |
|
|
462
|
+
| `exportData` | Read practices back whole, **incl. registered payments and amounts** |
|
|
413
463
|
|
|
414
464
|
### Create
|
|
415
465
|
|
|
@@ -543,6 +593,54 @@ await client.booking.search({
|
|
|
543
593
|
});
|
|
544
594
|
```
|
|
545
595
|
|
|
596
|
+
### Read a practice back (`exportData`)
|
|
597
|
+
|
|
598
|
+
`search` returns the header and booked services. `exportData` is the only AVES
|
|
599
|
+
operation that also returns **registered payments**, per-line amounts and file
|
|
600
|
+
totals — use it to reconcile what was written with `addPayments` / `create`.
|
|
601
|
+
|
|
602
|
+
Every field is an optional filter. With none set AVES exports everything the
|
|
603
|
+
credentials can reach, so pass `limitRange` for anything broader than one
|
|
604
|
+
`bookingFileCode` (`skip` ≥ 0, `take` ≤ 1000 — enforced before sending).
|
|
605
|
+
|
|
606
|
+
```typescript
|
|
607
|
+
const result = await client.booking.exportData({
|
|
608
|
+
bookingFileCode: '14/036654',
|
|
609
|
+
// or filter a window:
|
|
610
|
+
// lastModificationDate: { minDate: '2026-08-01', maxDate: '2026-08-07' },
|
|
611
|
+
// statusLists: ['CONFIRMED'],
|
|
612
|
+
// limitRange: { skip: 0, take: 500 },
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
if (result.success) {
|
|
616
|
+
const file = result.data.bookingFileList?.[0];
|
|
617
|
+
|
|
618
|
+
for (const payment of file?.paymentList ?? []) {
|
|
619
|
+
console.log(payment.paymentDate, payment.amount, payment.paymentType);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
for (const service of file?.bookedServices ?? []) {
|
|
623
|
+
console.log(service.serviceCode, service.amountsDetail?.costWithTax);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
console.log(file?.bookedFileAmounts?.customerDueAmount);
|
|
627
|
+
|
|
628
|
+
// Lookup tables the exported codes resolve against.
|
|
629
|
+
// `territoriality` (IN_UE | OUT_UE | MIXED_UE) drives the VAT regime.
|
|
630
|
+
console.log(result.data.extraInfo?.nationList);
|
|
631
|
+
console.log(result.data.extraInfo?.vatList);
|
|
632
|
+
}
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
`extraInfo.masterDataSet` rows are validated as full master records — the same
|
|
636
|
+
shape `client.master.search` returns. Read responses accept `RecordType:
|
|
637
|
+
'NOT_SET'` via `RecordTypeWire`; the request-side `RecordType` stays strict.
|
|
638
|
+
|
|
639
|
+
Every picklist the spec closes is validated, so an undocumented value fails the
|
|
640
|
+
whole response rather than reaching your code. Two fields are deliberately
|
|
641
|
+
plain strings because AVES documents no values for them: `regimeType` (no list
|
|
642
|
+
given) and `customerPayAt` (absent from the response table entirely).
|
|
643
|
+
|
|
546
644
|
---
|
|
547
645
|
|
|
548
646
|
## Package / Program catalog
|
|
@@ -597,20 +695,29 @@ if (detail.success) console.log(detail.data.pCode, detail.data.serviceList?.[0])
|
|
|
597
695
|
|
|
598
696
|
## Errors
|
|
599
697
|
|
|
698
|
+
`AvesError` is a tagged union: `AvesValidationError` | `AvesApiError` | `AvesUnknownError`.
|
|
699
|
+
Each has `_tag` (for `Effect.catchTag`) and Promise-friendly `kind` (`validation` | `api` | `unknown`).
|
|
700
|
+
|
|
600
701
|
```typescript
|
|
601
|
-
import { AvesClient,
|
|
702
|
+
import { AvesClient, AvesApiError, isAvesError } from "aves-sdk";
|
|
602
703
|
|
|
603
704
|
const result = await client.master.search({
|
|
604
|
-
searchType:
|
|
605
|
-
recordCode:
|
|
705
|
+
searchType: "CODE",
|
|
706
|
+
recordCode: "508558",
|
|
606
707
|
});
|
|
607
708
|
|
|
608
709
|
if (!result.success) {
|
|
609
|
-
|
|
610
|
-
|
|
710
|
+
if (isAvesError(result.error)) {
|
|
711
|
+
console.error(result.error.kind, result.error.message, result.error.code);
|
|
712
|
+
}
|
|
713
|
+
if (result.error instanceof AvesApiError) {
|
|
714
|
+
console.error(result.error._tag, result.error.status);
|
|
715
|
+
}
|
|
611
716
|
}
|
|
612
717
|
```
|
|
613
718
|
|
|
719
|
+
Effect programs recover with `Effect.catchTag("AvesApiError", …)` (also `"AvesValidationError"`, `"AvesUnknownError"`).
|
|
720
|
+
|
|
614
721
|
---
|
|
615
722
|
|
|
616
723
|
## Case transformation & wire shapes
|
|
@@ -626,9 +733,9 @@ You do not handle XML attribute prefixes yourself. Attr vs element is decided by
|
|
|
626
733
|
|
|
627
734
|
One outbound path for all ops:
|
|
628
735
|
|
|
629
|
-
1.
|
|
736
|
+
1. Effect Schema validates camelCase input
|
|
630
737
|
2. `createApiSchema(schema, shape, wrap?)` → `toWireBody` (optional list wrap + `paxAssociated` string[]/empty normalize + `camelToPascalKeys`)
|
|
631
|
-
3. `
|
|
738
|
+
3. Transport `invoke` / `ops.*` adds `RqHeader`, optional `bodyKey` nest, POSTs XML
|
|
632
739
|
|
|
633
740
|
Inbound: `createResponseSchema` / `createFlattenedResponseSchema` / `createListResponseSchema` → camelCase + optional detail spread or typed list RS; `listDetailApiSchema` unwraps wire `*List`/`*Detail` to flat arrays; `coalesceWireAliases` normalizes dialect attrs. Input aliases: `valueFieldSchema`, `coalesceCustomerRecordCode`, `coalesceListHead`. Shared primitives: `LanguageCodeSchema`, `StringishSchema`, `DateRangeSchema`, `StatusOnlyResponseSchema`.
|
|
634
741
|
|
|
@@ -653,18 +760,23 @@ Editing CreateBooking shapes does not affect SearchFile or AvesSearch.
|
|
|
653
760
|
|
|
654
761
|
## Architecture
|
|
655
762
|
|
|
656
|
-
`
|
|
763
|
+
Promise edge: `createAvesClient` / `AvesClient` → `toPromiseFacade` on domain services.
|
|
764
|
+
Effect edge: `makeAvesRuntime` / `avesClientLayer` / `AvesClientLive` → `yield*` Tags.
|
|
657
765
|
|
|
658
766
|
| Module | Role |
|
|
659
767
|
| ------ | ---- |
|
|
660
|
-
| `
|
|
661
|
-
| `
|
|
662
|
-
| `
|
|
663
|
-
| `
|
|
664
|
-
| `client/
|
|
768
|
+
| `src/client.ts` | Promise facade + `makeAvesRuntime` |
|
|
769
|
+
| `src/client/layer.ts` | `avesClientLayer` / `AvesClientLive` composition |
|
|
770
|
+
| `src/client/booking/` | Booking Tag / service / layer |
|
|
771
|
+
| `src/client/master/` | Master-records Tag / service / layer |
|
|
772
|
+
| `src/client/packages/` | Package catalog Tag / service / layer |
|
|
773
|
+
| `src/client/transport/` | `invoke` / `ops` / response reader |
|
|
774
|
+
| `src/client/http/` | XML POST via `@effect/platform` HttpClient |
|
|
775
|
+
| `src/client/config/` | `AvesConfig` |
|
|
776
|
+
| `src/schemas/` | Effect Schema RQ/RS |
|
|
665
777
|
| `src/xml/` | XML root helpers + JSON ↔ XML |
|
|
666
778
|
|
|
667
|
-
Outbound path:
|
|
779
|
+
Outbound path: Schema decode → `createApiSchema` / `toWireBody` → transport → HTTP POST.
|
|
668
780
|
|
|
669
781
|
---
|
|
670
782
|
|
|
@@ -673,24 +785,30 @@ Outbound path: validate → `createApiSchema` / `toWireBody` → `invokeOp` →
|
|
|
673
785
|
Operations are available only through `client.master`, `client.booking`, and
|
|
674
786
|
`client.packages`; flat aliases were removed in 2.0.0. When upgrading from 2.x,
|
|
675
787
|
also update `master.search` consumers for the flat array success payload (3.0.0).
|
|
676
|
-
See the [CHANGELOG migration notes](
|
|
788
|
+
See the [CHANGELOG migration notes](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md).
|
|
677
789
|
|
|
678
790
|
```typescript
|
|
679
791
|
import type {
|
|
680
792
|
AvesClientOptions,
|
|
681
793
|
AvesClientDeps,
|
|
794
|
+
AvesError,
|
|
682
795
|
AvesSearchRQ,
|
|
683
796
|
BookingFileRQ,
|
|
797
|
+
Result,
|
|
684
798
|
SearchMasterRecord,
|
|
685
|
-
} from
|
|
799
|
+
} from "aves-sdk";
|
|
686
800
|
|
|
687
801
|
import {
|
|
688
802
|
AvesClient,
|
|
803
|
+
createAvesClient,
|
|
804
|
+
makeAvesRuntime,
|
|
805
|
+
AvesMaster,
|
|
806
|
+
AvesBooking,
|
|
807
|
+
AvesPackages,
|
|
689
808
|
AvesTransport,
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
AvesError,
|
|
809
|
+
avesClientLayer,
|
|
810
|
+
isAvesError,
|
|
811
|
+
AvesApiError,
|
|
694
812
|
// object enums
|
|
695
813
|
AvesSearchType,
|
|
696
814
|
BookingFileStatus,
|
|
@@ -699,7 +817,7 @@ import {
|
|
|
699
817
|
PaxQtyCriteria,
|
|
700
818
|
PaymentType,
|
|
701
819
|
SearchMasterType,
|
|
702
|
-
} from
|
|
820
|
+
} from "aves-sdk";
|
|
703
821
|
|
|
704
822
|
PaxQtyCriteria.GREATER_OR_EQUAL
|
|
705
823
|
AvesSearchType.PACKAGE
|
|
@@ -713,7 +831,7 @@ MIT
|
|
|
713
831
|
|
|
714
832
|
## Links
|
|
715
833
|
|
|
716
|
-
- [Changelog](
|
|
834
|
+
- [Changelog](https://github.com/simoneguglielmi/aves-sdk/blob/main/CHANGELOG.md)
|
|
717
835
|
- [GitHub Repository](https://github.com/simoneguglielmi/aves-sdk)
|
|
718
836
|
- [NPM Package](https://npmjs.com/package/aves-sdk)
|
|
719
837
|
- [Issue Tracker](https://github.com/simoneguglielmi/aves-sdk/issues)
|