@shopickup/adapters-mpl 0.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.
Files changed (50) hide show
  1. package/README.md +43 -0
  2. package/dist/capabilities/auth.d.ts +39 -0
  3. package/dist/capabilities/auth.d.ts.map +1 -0
  4. package/dist/capabilities/auth.js +130 -0
  5. package/dist/capabilities/close.d.ts +8 -0
  6. package/dist/capabilities/close.d.ts.map +1 -0
  7. package/dist/capabilities/close.js +70 -0
  8. package/dist/capabilities/get-shipment-details.d.ts +63 -0
  9. package/dist/capabilities/get-shipment-details.d.ts.map +1 -0
  10. package/dist/capabilities/get-shipment-details.js +97 -0
  11. package/dist/capabilities/index.d.ts +10 -0
  12. package/dist/capabilities/index.d.ts.map +1 -0
  13. package/dist/capabilities/index.js +9 -0
  14. package/dist/capabilities/label.d.ts +33 -0
  15. package/dist/capabilities/label.d.ts.map +1 -0
  16. package/dist/capabilities/label.js +328 -0
  17. package/dist/capabilities/parcels.d.ts +33 -0
  18. package/dist/capabilities/parcels.d.ts.map +1 -0
  19. package/dist/capabilities/parcels.js +284 -0
  20. package/dist/capabilities/pickup-points.d.ts +41 -0
  21. package/dist/capabilities/pickup-points.d.ts.map +1 -0
  22. package/dist/capabilities/pickup-points.js +294 -0
  23. package/dist/capabilities/track.d.ts +72 -0
  24. package/dist/capabilities/track.d.ts.map +1 -0
  25. package/dist/capabilities/track.js +331 -0
  26. package/dist/index.d.ts +83 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +142 -0
  29. package/dist/mappers/label.d.ts +67 -0
  30. package/dist/mappers/label.d.ts.map +1 -0
  31. package/dist/mappers/label.js +83 -0
  32. package/dist/mappers/shipment.d.ts +110 -0
  33. package/dist/mappers/shipment.d.ts.map +1 -0
  34. package/dist/mappers/shipment.js +258 -0
  35. package/dist/mappers/tracking.d.ts +60 -0
  36. package/dist/mappers/tracking.d.ts.map +1 -0
  37. package/dist/mappers/tracking.js +187 -0
  38. package/dist/utils/httpUtils.d.ts +36 -0
  39. package/dist/utils/httpUtils.d.ts.map +1 -0
  40. package/dist/utils/httpUtils.js +76 -0
  41. package/dist/utils/oauthFallback.d.ts +47 -0
  42. package/dist/utils/oauthFallback.d.ts.map +1 -0
  43. package/dist/utils/oauthFallback.js +250 -0
  44. package/dist/utils/resolveBaseUrl.d.ts +75 -0
  45. package/dist/utils/resolveBaseUrl.d.ts.map +1 -0
  46. package/dist/utils/resolveBaseUrl.js +65 -0
  47. package/dist/validation.d.ts +1890 -0
  48. package/dist/validation.d.ts.map +1 -0
  49. package/dist/validation.js +726 -0
  50. package/package.json +69 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Label mapping utilities for MPL adapter
3
+ *
4
+ * Handles conversion from canonical label requests to MPL API query parameters
5
+ * and normalization of API responses back to canonical format.
6
+ *
7
+ * The MPL label endpoint uses GET with query parameters:
8
+ * GET /shipments/label?trackingNumbers=X&trackingNumbers=Y&labelType=A5&labelFormat=PDF&orderBy=SENDING&singleFile=true
9
+ *
10
+ * Response is JSON array of LabelQueryResult objects with base64-encoded label data.
11
+ */
12
+ /**
13
+ * Build query parameters from canonical label request
14
+ *
15
+ * Transforms CreateLabelsMPLRequest into query parameters suitable for
16
+ * the MPL GET /shipments/label endpoint.
17
+ *
18
+ * @param req - Canonical label request
19
+ * @returns Query parameters object
20
+ */
21
+ export function buildLabelQueryParams(req) {
22
+ return {
23
+ trackingNumbers: req.parcelCarrierIds,
24
+ // prefer canonical `size` (options.size) then carrier override under options.mpl.labelType
25
+ labelType: (req.options.size ?? req.options.mpl.labelType),
26
+ labelFormat: req.options.mpl.labelFormat,
27
+ orderBy: req.options.mpl.orderBy,
28
+ singleFile: req.options.mpl.singleFile,
29
+ };
30
+ }
31
+ /**
32
+ * Serialize query parameters to URL search params string
33
+ *
34
+ * Handles array parameters (trackingNumbers) as multiple query params:
35
+ * ?trackingNumbers=X&trackingNumbers=Y&trackingNumbers=Z&labelType=A5&labelFormat=PDF
36
+ *
37
+ * @param params - Query parameters
38
+ * @returns URLSearchParams string (without leading ?)
39
+ */
40
+ export function serializeQueryParams(params) {
41
+ const searchParams = new URLSearchParams();
42
+ // Add tracking numbers as array (multiple params with same name)
43
+ params.trackingNumbers.forEach(tn => {
44
+ searchParams.append('trackingNumbers', tn);
45
+ });
46
+ // Add optional parameters if present
47
+ if (params.labelType) {
48
+ searchParams.set('labelType', params.labelType);
49
+ }
50
+ if (params.labelFormat) {
51
+ searchParams.set('labelFormat', params.labelFormat);
52
+ }
53
+ if (params.orderBy) {
54
+ searchParams.set('orderBy', params.orderBy);
55
+ }
56
+ if (params.singleFile !== undefined) {
57
+ searchParams.set('singleFile', String(params.singleFile));
58
+ }
59
+ return searchParams.toString();
60
+ }
61
+ /**
62
+ * Build complete query string for logging/debugging
63
+ *
64
+ * Shows the actual query string that will be sent to the API
65
+ *
66
+ * @param params - Query parameters
67
+ * @returns Complete query string with leading ?
68
+ */
69
+ export function buildQueryString(params) {
70
+ const serialized = serializeQueryParams(params);
71
+ return serialized ? `?${serialized}` : '';
72
+ }
73
+ /**
74
+ * Get default values for optional label parameters
75
+ *
76
+ * These match MPL server defaults for when parameters are not specified
77
+ */
78
+ export const LABEL_DEFAULTS = {
79
+ labelType: 'A5',
80
+ labelFormat: 'PDF',
81
+ orderBy: undefined,
82
+ singleFile: false,
83
+ };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * MPL Adapter: Shipment Mappers
3
+ * Converts canonical Parcel objects to/from MPL ShipmentCreateRequest format
4
+ *
5
+ * Key mapping strategies:
6
+ * 1. Canonical Parcel -> MPL ShipmentCreateRequest (one parcel = one item in shipment)
7
+ * 2. Handles delivery modes: HOME (HA) vs PICKUP_POINT (PM/PP/CS)
8
+ * 3. Maps canonical service levels to MPL basic service codes
9
+ * 4. Translates COD/insurance to MPL extra services
10
+ */
11
+ import type { Parcel, Contact as CoreContact, Address as CoreAddress, Delivery } from '@shopickup/core';
12
+ import type { ShipmentCreateRequest, Item, Service, Recipient, Sender, Contact as MPLContact, Address as MPLAddress, BasicServiceCode, DeliveryMode, LabelType } from '../validation.js';
13
+ /**
14
+ * Maps canonical service level to MPL basic service code
15
+ *
16
+ * Defaults to A_175_UZL (standard domestic service)
17
+ * Can be overridden by parcel.carrierServiceCode if provided
18
+ */
19
+ export declare function mapServiceLevel(service: string, carrierServiceCode?: string, isInternational?: boolean): BasicServiceCode;
20
+ /**
21
+ * Maps delivery type to MPL delivery mode
22
+ *
23
+ * Canonical Delivery is discriminated union:
24
+ * - HomeDelivery: { method: 'HOME'; address }
25
+ * - PickupPointDelivery: { method: 'PICKUP_POINT'; pickupPoint }
26
+ */
27
+ export declare function mapDeliveryMode(delivery: Delivery): DeliveryMode;
28
+ /**
29
+ * Maps canonical Contact to MPL Contact format
30
+ */
31
+ export declare function mapContact(contact: CoreContact): MPLContact;
32
+ /**
33
+ * Maps canonical Address to MPL Address format
34
+ *
35
+ * MPL requires:
36
+ * - postCode: 4 characters
37
+ * - city: 2-35 chars
38
+ * - address: 3-60 chars (street + house number)
39
+ */
40
+ export declare function mapAddress(address: CoreAddress): MPLAddress;
41
+ /**
42
+ * Maps canonical Delivery to MPL DeliveryAddress
43
+ * If PICKUP_POINT, includes pickup point information
44
+ */
45
+ export declare function mapDeliveryAddress(delivery: Delivery): MPLAddress;
46
+ /**
47
+ * Maps canonical Recipient to MPL Recipient format
48
+ */
49
+ export declare function mapRecipient(recipient: {
50
+ contact: CoreContact;
51
+ delivery: Delivery;
52
+ }): Recipient;
53
+ /**
54
+ * Maps canonical Parcel shipper to MPL Sender format
55
+ *
56
+ * IMPORTANT: Sender requires:
57
+ * - agreement (8-character contract number)
58
+ * - contact, address
59
+ *
60
+ * The integration should provide agreement number via parcel metadata or credentials
61
+ */
62
+ export declare function mapSender(shipper: {
63
+ contact: CoreContact;
64
+ address: CoreAddress;
65
+ }, agreementCode: string, bankAccountNumber: string): Sender;
66
+ /**
67
+ * Maps canonical Parcel to MPL Service configuration
68
+ * Handles COD, insurance, delivery mode, service level
69
+ */
70
+ export declare function mapService(parcel: Parcel, isInternational?: boolean): Service;
71
+ /**
72
+ * Maps canonical Parcel package to MPL Item format
73
+ *
74
+ * A parcel contains one item (package) in MPL terms
75
+ */
76
+ export declare function mapItem(parcel: Parcel): Item;
77
+ /**
78
+ * Main mapper: canonical Parcel -> MPL ShipmentCreateRequest
79
+ *
80
+ * Usage:
81
+ * ```
82
+ * const mplShipment = mapParcelToMPLShipment(
83
+ * canonicalParcel,
84
+ * sender,
85
+ * agreementNumber,
86
+ * labelType
87
+ * );
88
+ * ```
89
+ *
90
+ * @param parcel - Canonical Parcel domain object
91
+ * @param shipper - Shipper contact and address from parcel
92
+ * @param agreementCode - 8-character MPL agreement/contract number
93
+ * @param labelType - Optional label format (A5, A4, etc.)
94
+ * @param developerName - System name making the API call (default: "shopickup-mpl")
95
+ * @returns MPL ShipmentCreateRequest ready for POST /shipments
96
+ */
97
+ export declare function mapParcelToMPLShipment(parcel: Parcel, shipper: {
98
+ contact: CoreContact;
99
+ address: CoreAddress;
100
+ }, agreementCode: string, bankAccountNumber: string, labelType?: LabelType, developerName?: string): ShipmentCreateRequest;
101
+ /**
102
+ * Batch mapper: Convert multiple parcels to multiple ShipmentCreateRequests
103
+ *
104
+ * Useful for preparing shipment array for batch POST
105
+ */
106
+ export declare function mapParcelsToMPLShipments(parcels: Parcel[], shipper: {
107
+ contact: CoreContact;
108
+ address: CoreAddress;
109
+ }, agreementCode: string, bankAccountNumber: string, labelType?: LabelType, developerName?: string): ShipmentCreateRequest[];
110
+ //# sourceMappingURL=shipment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shipment.d.ts","sourceRoot":"","sources":["../../src/mappers/shipment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,IAAI,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACxG,O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AO,EAAE;IACP,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB,EACD,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,SAAS,CAAC,EAAE,SAAS,EACrB,aAAa,GAAE,MAAwB,GACtC,qBAAqB,CAUvB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IACP,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB,EACD,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,SAAS,CAAC,EAAE,SAAS,EACrB,aAAa,CAAC,EAAE,MAAM,GACrB,qBAAqB,EAAE,CAWzB"}
@@ -0,0 +1,258 @@
1
+ /**
2
+ * MPL Adapter: Shipment Mappers
3
+ * Converts canonical Parcel objects to/from MPL ShipmentCreateRequest format
4
+ *
5
+ * Key mapping strategies:
6
+ * 1. Canonical Parcel -> MPL ShipmentCreateRequest (one parcel = one item in shipment)
7
+ * 2. Handles delivery modes: HOME (HA) vs PICKUP_POINT (PM/PP/CS)
8
+ * 3. Maps canonical service levels to MPL basic service codes
9
+ * 4. Translates COD/insurance to MPL extra services
10
+ */
11
+ /**
12
+ * Maps canonical service level to MPL basic service code
13
+ *
14
+ * Defaults to A_175_UZL (standard domestic service)
15
+ * Can be overridden by parcel.carrierServiceCode if provided
16
+ */
17
+ export function mapServiceLevel(service, carrierServiceCode, isInternational = false) {
18
+ // If integrator explicitly provided a carrier service code, use it
19
+ if (carrierServiceCode) {
20
+ // Validate it's a real MPL service code
21
+ const validCodes = [
22
+ 'A_175_UZL',
23
+ 'A_177_MPC',
24
+ 'A_176_NET',
25
+ 'A_176_NKP',
26
+ 'A_122_ECS',
27
+ 'A_121_CSG',
28
+ 'A_13_EMS',
29
+ 'A_123_EUP',
30
+ 'A_123_HAR',
31
+ 'A_123_HAI',
32
+ 'A_125_HAR',
33
+ 'A_125_HAI',
34
+ ];
35
+ if (validCodes.includes(carrierServiceCode)) {
36
+ return carrierServiceCode;
37
+ }
38
+ }
39
+ // Map canonical service levels to MPL codes
40
+ if (isInternational) {
41
+ switch (service) {
42
+ case 'standard':
43
+ return 'A_123_EUP'; // Europe standard
44
+ case 'express':
45
+ return 'A_13_EMS'; // Express Mail Service
46
+ default:
47
+ return 'A_123_EUP';
48
+ }
49
+ }
50
+ // Domestic services
51
+ switch (service) {
52
+ case 'express':
53
+ return 'A_121_CSG'; // Csomag (parcel) - faster
54
+ case 'economy':
55
+ return 'A_175_UZL'; // Standard - cheapest
56
+ case 'overnight':
57
+ return 'A_121_CSG'; // Use fastest available
58
+ case 'standard':
59
+ default:
60
+ return 'A_175_UZL'; // Default standard domestic
61
+ }
62
+ }
63
+ /**
64
+ * Maps delivery type to MPL delivery mode
65
+ *
66
+ * Canonical Delivery is discriminated union:
67
+ * - HomeDelivery: { method: 'HOME'; address }
68
+ * - PickupPointDelivery: { method: 'PICKUP_POINT'; pickupPoint }
69
+ */
70
+ export function mapDeliveryMode(delivery) {
71
+ switch (delivery.method) {
72
+ case 'HOME':
73
+ return 'HA'; // Házhozszállítás (Home Delivery)
74
+ case 'PICKUP_POINT':
75
+ // Parcel locker (Csomagautomata) by default for pickup points
76
+ // Integrator can override via metadata if needed
77
+ return 'CS'; // Csomagautomata
78
+ default:
79
+ return 'HA'; // Default to home
80
+ }
81
+ }
82
+ /**
83
+ * Maps canonical Contact to MPL Contact format
84
+ */
85
+ export function mapContact(contact) {
86
+ return {
87
+ name: contact.name,
88
+ phone: contact.phone,
89
+ email: contact.email,
90
+ };
91
+ }
92
+ /**
93
+ * Maps canonical Address to MPL Address format
94
+ *
95
+ * MPL requires:
96
+ * - postCode: 4 characters
97
+ * - city: 2-35 chars
98
+ * - address: 3-60 chars (street + house number)
99
+ */
100
+ export function mapAddress(address) {
101
+ return {
102
+ postCode: address.postalCode.slice(0, 4).padEnd(4, '0'), // Normalize to 4 digits
103
+ city: address.city.slice(0, 35),
104
+ address: address.street.slice(0, 60),
105
+ };
106
+ }
107
+ /**
108
+ * Maps canonical Delivery to MPL DeliveryAddress
109
+ * If PICKUP_POINT, includes pickup point information
110
+ */
111
+ export function mapDeliveryAddress(delivery) {
112
+ if (delivery.method === 'HOME') {
113
+ return mapAddress(delivery.address);
114
+ }
115
+ else {
116
+ // PICKUP_POINT - use pickup point address if available, otherwise use fallback
117
+ const pickupAddr = delivery.pickupPoint.address;
118
+ if (pickupAddr) {
119
+ return mapAddress(pickupAddr);
120
+ }
121
+ // Fallback - this shouldn't happen but be defensive
122
+ throw new Error('PickupPointDelivery missing address information');
123
+ }
124
+ }
125
+ /**
126
+ * Maps canonical Recipient to MPL Recipient format
127
+ */
128
+ export function mapRecipient(recipient) {
129
+ return {
130
+ contact: mapContact(recipient.contact),
131
+ address: mapDeliveryAddress(recipient.delivery),
132
+ };
133
+ }
134
+ /**
135
+ * Maps canonical Parcel shipper to MPL Sender format
136
+ *
137
+ * IMPORTANT: Sender requires:
138
+ * - agreement (8-character contract number)
139
+ * - contact, address
140
+ *
141
+ * The integration should provide agreement number via parcel metadata or credentials
142
+ */
143
+ export function mapSender(shipper, agreementCode, bankAccountNumber) {
144
+ return {
145
+ agreement: agreementCode,
146
+ accountNo: bankAccountNumber,
147
+ contact: mapContact(shipper.contact),
148
+ address: mapAddress(shipper.address),
149
+ };
150
+ }
151
+ /**
152
+ * Maps canonical Parcel to MPL Service configuration
153
+ * Handles COD, insurance, delivery mode, service level
154
+ */
155
+ export function mapService(parcel, isInternational = false) {
156
+ const service = {
157
+ basic: mapServiceLevel(parcel.service, parcel.carrierServiceCode, isInternational),
158
+ deliveryMode: mapDeliveryMode(parcel.recipient.delivery),
159
+ };
160
+ // Handle cash on delivery
161
+ if (parcel.cod?.amount) {
162
+ service.cod = parcel.cod.amount.amount;
163
+ if (parcel.cod.amount.currency && parcel.cod.amount.currency !== 'HUF') {
164
+ service.codCurrency = parcel.cod.amount.currency;
165
+ }
166
+ }
167
+ // Handle declared value / insurance
168
+ if (parcel.declaredValue?.amount) {
169
+ service.value = Math.round(parcel.declaredValue.amount);
170
+ // If we have value, add K_ENY (value insurance) extra service
171
+ service.extra = service.extra || [];
172
+ if (!service.extra.includes('K_ENY')) {
173
+ service.extra.push('K_ENY');
174
+ }
175
+ }
176
+ else if (parcel.insurance?.amount) {
177
+ service.value = Math.round(parcel.insurance.amount.amount);
178
+ service.extra = service.extra || [];
179
+ if (!service.extra.includes('K_ENY')) {
180
+ service.extra.push('K_ENY');
181
+ }
182
+ }
183
+ return service;
184
+ }
185
+ /**
186
+ * Maps canonical Parcel package to MPL Item format
187
+ *
188
+ * A parcel contains one item (package) in MPL terms
189
+ */
190
+ export function mapItem(parcel) {
191
+ const item = {
192
+ services: mapService(parcel),
193
+ };
194
+ // Add weight if available
195
+ if (parcel.package?.weightGrams) {
196
+ item.weight = {
197
+ value: parcel.package.weightGrams,
198
+ unit: 'g',
199
+ };
200
+ }
201
+ // Add custom data from references if available
202
+ if (parcel.references?.orderId) {
203
+ item.customData1 = parcel.references.orderId.slice(0, 40);
204
+ }
205
+ if (parcel.references?.customerReference) {
206
+ item.customData2 = parcel.references.customerReference.slice(0, 40);
207
+ }
208
+ // Handle special handling requirements
209
+ if (parcel.handling?.fragile || parcel.handling?.perishables) {
210
+ if (!item.services.extra) {
211
+ item.services.extra = [];
212
+ }
213
+ // Add bulky handling if needed for fragile items
214
+ if (!item.services.extra.includes('K_TER')) {
215
+ item.services.extra.push('K_TER');
216
+ }
217
+ }
218
+ return item;
219
+ }
220
+ /**
221
+ * Main mapper: canonical Parcel -> MPL ShipmentCreateRequest
222
+ *
223
+ * Usage:
224
+ * ```
225
+ * const mplShipment = mapParcelToMPLShipment(
226
+ * canonicalParcel,
227
+ * sender,
228
+ * agreementNumber,
229
+ * labelType
230
+ * );
231
+ * ```
232
+ *
233
+ * @param parcel - Canonical Parcel domain object
234
+ * @param shipper - Shipper contact and address from parcel
235
+ * @param agreementCode - 8-character MPL agreement/contract number
236
+ * @param labelType - Optional label format (A5, A4, etc.)
237
+ * @param developerName - System name making the API call (default: "shopickup-mpl")
238
+ * @returns MPL ShipmentCreateRequest ready for POST /shipments
239
+ */
240
+ export function mapParcelToMPLShipment(parcel, shipper, agreementCode, bankAccountNumber, labelType, developerName = 'shopickup-mpl') {
241
+ return {
242
+ developer: developerName,
243
+ sender: mapSender(shipper, agreementCode, bankAccountNumber),
244
+ recipient: mapRecipient(parcel.recipient),
245
+ webshopId: parcel.id, // Use parcel ID as unique identifier within request
246
+ orderId: parcel.references?.orderId,
247
+ labelType: labelType || 'A5', // Default to A5
248
+ item: [mapItem(parcel)],
249
+ };
250
+ }
251
+ /**
252
+ * Batch mapper: Convert multiple parcels to multiple ShipmentCreateRequests
253
+ *
254
+ * Useful for preparing shipment array for batch POST
255
+ */
256
+ export function mapParcelsToMPLShipments(parcels, shipper, agreementCode, bankAccountNumber, labelType, developerName) {
257
+ return parcels.map((parcel, idx) => mapParcelToMPLShipment(parcel, shipper, agreementCode, bankAccountNumber, labelType, developerName));
258
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * MPL Tracking Mapper
3
+ * Converts MPL C-code tracking records to canonical TrackingUpdate format
4
+ */
5
+ import type { TrackingUpdate } from '@shopickup/core';
6
+ /**
7
+ * MPL C-Code Tracking Record Interface
8
+ * Represents a single tracking record with C0-C63 fields from MPL API
9
+ */
10
+ export interface MPLTrackingRecord {
11
+ c0?: string;
12
+ c1?: string;
13
+ c2?: string;
14
+ c4?: string;
15
+ c5?: string;
16
+ c6?: string;
17
+ c8?: string;
18
+ c9?: string;
19
+ c10?: string;
20
+ c11?: string;
21
+ c12?: string;
22
+ c13?: string;
23
+ c38?: string;
24
+ c39?: string;
25
+ c41?: string;
26
+ c42?: string;
27
+ c43?: string;
28
+ c49?: string;
29
+ c53?: string;
30
+ c55?: string;
31
+ c56?: string;
32
+ c57?: string;
33
+ c59?: string;
34
+ c60?: string;
35
+ c61?: string;
36
+ c63?: string;
37
+ [key: string]: any;
38
+ }
39
+ /**
40
+ * Convert MPL C-code tracking record to canonical TrackingUpdate
41
+ *
42
+ * @param record - MPL tracking record with C-codes
43
+ * @param includeFinancialData - If true, include weight/size/value (Registered endpoint)
44
+ * @returns Canonical TrackingUpdate
45
+ */
46
+ export declare function mapMPLTrackingToCanonical(record: MPLTrackingRecord, includeFinancialData?: boolean): TrackingUpdate;
47
+ /**
48
+ * Build multiple events from complete tracking history
49
+ * Used when state='all' is requested
50
+ *
51
+ * Note: MPL API appears to return multiple records in trackAndTrace array
52
+ * when state='all'. Each record represents an event in the history.
53
+ */
54
+ export declare function mapMPLTrackingHistoryToCanonical(records: MPLTrackingRecord[], includeFinancialData?: boolean): TrackingUpdate;
55
+ /**
56
+ * Determine if record has financial data (Registered vs Guest)
57
+ * Registered includes C5 (weight), Guest excludes it
58
+ */
59
+ export declare function isRegisteredRecord(record: MPLTrackingRecord): boolean;
60
+ //# sourceMappingURL=tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../../src/mappers/tracking.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,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