shipflow 0.3.0 → 0.3.2
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/dist/carriers/aramex/adapter.d.ts.map +1 -1
- package/dist/carriers/aramex/index.js +12 -11
- package/dist/carriers/aramex/index.js.map +4 -4
- package/dist/carriers/aramex/mappers.d.ts +13 -5
- package/dist/carriers/aramex/mappers.d.ts.map +1 -1
- package/dist/carriers/aymakan/adapter.d.ts +12 -2
- package/dist/carriers/aymakan/adapter.d.ts.map +1 -1
- package/dist/carriers/aymakan/index.js +56 -31
- package/dist/carriers/aymakan/index.js.map +4 -4
- package/dist/carriers/aymakan/mappers.d.ts +2 -0
- package/dist/carriers/aymakan/mappers.d.ts.map +1 -1
- package/dist/carriers/aymakan/types.d.ts +1 -1
- package/dist/carriers/aymakan/types.d.ts.map +1 -1
- package/dist/carriers/smsaexpress/adapter.d.ts +24 -3
- package/dist/carriers/smsaexpress/adapter.d.ts.map +1 -1
- package/dist/carriers/smsaexpress/index.js +94 -24
- package/dist/carriers/smsaexpress/index.js.map +5 -5
- package/dist/carriers/smsaexpress/mappers.d.ts +12 -3
- package/dist/carriers/smsaexpress/mappers.d.ts.map +1 -1
- package/dist/carriers/smsaexpress/services.d.ts +3 -1
- package/dist/carriers/smsaexpress/services.d.ts.map +1 -1
- package/dist/core/http.d.ts +8 -0
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/retry.d.ts +8 -3
- package/dist/core/retry.d.ts.map +1 -1
- package/dist/{index-qnxj8bct.js → index-8cpdcbsf.js} +32 -6
- package/dist/{index-qnxj8bct.js.map → index-8cpdcbsf.js.map} +5 -5
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -16,14 +16,35 @@ export declare class SMSAExpressAdapter extends BaseCarrierAdapter {
|
|
|
16
16
|
private http;
|
|
17
17
|
constructor(config: SMSAExpressConfig);
|
|
18
18
|
protected getBaseUrl(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure the input carries a `reference` so the OrderNumber the shipment is
|
|
21
|
+
* booked under is the exact value surfaced back on `Shipment.reference` (which
|
|
22
|
+
* the caller needs for {@link trackByReference}). When no reference is
|
|
23
|
+
* supplied we generate one here via the shared {@link generateOrderNumber} and
|
|
24
|
+
* pass this prepared input to BOTH the request mapper and the response mapper,
|
|
25
|
+
* so the request OrderNumber and the response reference always agree (otherwise
|
|
26
|
+
* each would call `Date.now()` independently and disagree).
|
|
27
|
+
*/
|
|
28
|
+
private withOrderNumber;
|
|
19
29
|
protected executeCreateShipment(input: CreateShipmentInput): Promise<Shipment>;
|
|
20
30
|
private createC2BShipment;
|
|
21
31
|
/**
|
|
22
32
|
* Cancel a reverse-pickup (C2B) shipment.
|
|
23
33
|
*
|
|
24
|
-
* **Important:** SMSA only supports cancellation for C2B/reverse-pickup
|
|
25
|
-
*
|
|
26
|
-
*
|
|
34
|
+
* **Important:** SMSA only supports cancellation for C2B/reverse-pickup
|
|
35
|
+
* shipments, via the C2B endpoint. B2C shipments cannot be cancelled through
|
|
36
|
+
* the SMSA API: the endpoint responds without a cancellation confirmation,
|
|
37
|
+
* which is surfaced as an {@link APIError} (with `code: "CANCELLATION_UNCONFIRMED"`)
|
|
38
|
+
* rather than a misleading `false`. That `code` lets callers distinguish this
|
|
39
|
+
* "carrier did not confirm" case from a genuine request failure (network/4xx/5xx)
|
|
40
|
+
* and fall back accordingly. Consistent with the other adapters, this method
|
|
41
|
+
* either returns `true` or throws.
|
|
42
|
+
*
|
|
43
|
+
* Success is detected with a negation-aware check: a cancel token must be
|
|
44
|
+
* present AND no negation token may be. A bare `includes("cancelled")` would
|
|
45
|
+
* wrongly succeed on negatives like "Shipment cannot be cancelled",
|
|
46
|
+
* "not cancelled" or "cancellation failed". Note "already cancelled" carries
|
|
47
|
+
* no negation token, so it correctly reports success (idempotent cancel).
|
|
27
48
|
*/
|
|
28
49
|
cancelShipment(trackingNumber: string): Promise<boolean>;
|
|
29
50
|
track(trackingNumber: string): Promise<TrackingResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/adapter.ts"],"names":[],"mappings":"AACA;;;GAGG;AAIH,OAAO,KAAK,EACV,aAAa,EACb,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/adapter.ts"],"names":[],"mappings":"AACA;;;GAGG;AAIH,OAAO,KAAK,EACV,aAAa,EACb,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAa7C,OAAO,KAAK,EAGV,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EAEtB,wBAAwB,EAEzB,MAAM,SAAS,CAAC;AAQjB,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,WAAW,EAAE;QACX,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,qBAAa,kBAAmB,SAAQ,kBAAkB;IACxD,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,QAAQ,CAAC,kBAAkB,WASzB;IAEF,OAAO,CAAC,IAAI,CAAa;gBAEb,MAAM,EAAE,iBAAiB;IAWrC,SAAS,CAAC,UAAU,IAAI,MAAM;IAU9B;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;cAOP,qBAAqB,CACnC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,QAAQ,CAAC;YAmBN,iBAAiB;IAY/B;;;;;;;;;;;;;;;;;OAiBG;IACG,cAAc,CAA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EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,aAAa,CAAC;KACxB,GACA,YAAY,EAAE;CAGlB"}
|
|
@@ -2,9 +2,10 @@ import {
|
|
|
2
2
|
APIError,
|
|
3
3
|
BaseCarrierAdapter,
|
|
4
4
|
HttpClient,
|
|
5
|
+
RateLimitError,
|
|
5
6
|
ValidationError,
|
|
6
7
|
WebhookVerificationError
|
|
7
|
-
} from "../../index-
|
|
8
|
+
} from "../../index-8cpdcbsf.js";
|
|
8
9
|
|
|
9
10
|
// src/carriers/smsaexpress/services.ts
|
|
10
11
|
var SMSAService = {
|
|
@@ -37,7 +38,13 @@ var SMSAStatusCodes = {
|
|
|
37
38
|
|
|
38
39
|
// src/carriers/smsaexpress/mappers.ts
|
|
39
40
|
function mapSMSAStatus(scanType) {
|
|
40
|
-
return SMSAStatusCodes[scanType] ?? "
|
|
41
|
+
return SMSAStatusCodes[scanType] ?? "unknown";
|
|
42
|
+
}
|
|
43
|
+
function scanDate(scan) {
|
|
44
|
+
return new Date(scan.ScanTimeZone ? `${scan.ScanDateTime}${scan.ScanTimeZone}` : scan.ScanDateTime);
|
|
45
|
+
}
|
|
46
|
+
function scanTimestampMs(scan) {
|
|
47
|
+
return scanDate(scan).getTime();
|
|
41
48
|
}
|
|
42
49
|
function deriveStatusFromScans(scans, isDelivered) {
|
|
43
50
|
if (isDelivered) {
|
|
@@ -47,7 +54,7 @@ function deriveStatusFromScans(scans, isDelivered) {
|
|
|
47
54
|
if (safeScans.length === 0) {
|
|
48
55
|
return { status: "unknown", statusLabel: "Unknown" };
|
|
49
56
|
}
|
|
50
|
-
const sorted = [...safeScans].sort((a, b) =>
|
|
57
|
+
const sorted = [...safeScans].sort((a, b) => scanTimestampMs(b) - scanTimestampMs(a));
|
|
51
58
|
const latest = sorted[0];
|
|
52
59
|
return {
|
|
53
60
|
status: mapSMSAStatus(latest.ScanType),
|
|
@@ -57,10 +64,19 @@ function deriveStatusFromScans(scans, isDelivered) {
|
|
|
57
64
|
function roundWeight(weight) {
|
|
58
65
|
return Math.round(weight * 1000) / 1000;
|
|
59
66
|
}
|
|
67
|
+
function sanitizePhone(phone) {
|
|
68
|
+
return phone.replace(/\D/g, "");
|
|
69
|
+
}
|
|
70
|
+
function generateOrderNumber() {
|
|
71
|
+
return `ORD-${Date.now()}`;
|
|
72
|
+
}
|
|
73
|
+
function smsaShipDate() {
|
|
74
|
+
return new Date(Date.now() + 3 * 60 * 60 * 1000).toISOString().slice(0, 19);
|
|
75
|
+
}
|
|
60
76
|
function mapAddress(addr, opts) {
|
|
61
77
|
const result = {
|
|
62
78
|
ContactName: addr.name,
|
|
63
|
-
ContactPhoneNumber: addr.phone,
|
|
79
|
+
ContactPhoneNumber: sanitizePhone(addr.phone),
|
|
64
80
|
Country: addr.countryCode,
|
|
65
81
|
City: addr.city,
|
|
66
82
|
AddressLine1: addr.line1,
|
|
@@ -88,12 +104,12 @@ function mapCreateB2CRequest(input) {
|
|
|
88
104
|
return {
|
|
89
105
|
ConsigneeAddress: consigneeAddress,
|
|
90
106
|
ShipperAddress: mapAddress(input.shipper),
|
|
91
|
-
OrderNumber: input.reference ??
|
|
107
|
+
OrderNumber: input.reference ?? generateOrderNumber(),
|
|
92
108
|
CODAmount: input.cod?.enabled ? input.cod.amount : 0,
|
|
93
109
|
DeclaredValue: input.declaredValue?.amount ?? 0,
|
|
94
110
|
ContentDescription: input.parcels[0]?.description ?? "Shipment contents",
|
|
95
111
|
Parcels: totalPieces,
|
|
96
|
-
ShipDate:
|
|
112
|
+
ShipDate: smsaShipDate(),
|
|
97
113
|
ShipmentCurrency: (input.cod?.enabled ? input.cod.currency : undefined) ?? input.declaredValue?.currency ?? input.cod?.currency ?? "SAR",
|
|
98
114
|
Weight: roundWeight(totalWeight),
|
|
99
115
|
WeightUnit: "KG",
|
|
@@ -110,11 +126,11 @@ function mapCreateC2BRequest(input) {
|
|
|
110
126
|
return {
|
|
111
127
|
PickupAddress: mapAddress(input.consignee, { includeShortCode: true }),
|
|
112
128
|
ReturnToAddress: mapAddress(input.shipper),
|
|
113
|
-
OrderNumber: input.reference ??
|
|
129
|
+
OrderNumber: input.reference ?? generateOrderNumber(),
|
|
114
130
|
DeclaredValue: input.declaredValue?.amount ?? 0.1,
|
|
115
131
|
ContentDescription: input.parcels[0]?.description ?? "Return shipment contents",
|
|
116
132
|
Parcels: totalPieces,
|
|
117
|
-
ShipDate:
|
|
133
|
+
ShipDate: smsaShipDate(),
|
|
118
134
|
ShipmentCurrency: (input.cod?.enabled ? input.cod.currency : undefined) ?? input.declaredValue?.currency ?? input.cod?.currency ?? "SAR",
|
|
119
135
|
Weight: roundWeight(totalWeight),
|
|
120
136
|
WeightUnit: "KG",
|
|
@@ -202,11 +218,11 @@ function mapCreate2WayRequest(input) {
|
|
|
202
218
|
return {
|
|
203
219
|
ConsigneeAddress: consigneeAddress,
|
|
204
220
|
ShipperAddress: mapAddress(input.shipper),
|
|
205
|
-
OrderNumber: input.reference ??
|
|
221
|
+
OrderNumber: input.reference ?? generateOrderNumber(),
|
|
206
222
|
DeclaredValue: input.declaredValue?.amount ?? 0,
|
|
207
223
|
ContentDescription: input.parcels[0]?.description ?? "Shipment contents",
|
|
208
224
|
Parcels: totalPieces,
|
|
209
|
-
ShipDate:
|
|
225
|
+
ShipDate: smsaShipDate(),
|
|
210
226
|
ShipmentCurrency: input.declaredValue?.currency ?? "SAR",
|
|
211
227
|
Weight: roundWeight(totalWeight),
|
|
212
228
|
WeightUnit: "KG",
|
|
@@ -251,9 +267,9 @@ function verifyWebhookAuth(options) {
|
|
|
251
267
|
function mapWebhookShipmentToEvent(shipment) {
|
|
252
268
|
const scans = shipment.Scans ?? [];
|
|
253
269
|
const { status, statusLabel } = deriveStatusFromScans(scans, shipment.isDelivered);
|
|
254
|
-
const sorted = [...scans].sort((a, b) =>
|
|
270
|
+
const sorted = [...scans].sort((a, b) => scanTimestampMs(b) - scanTimestampMs(a));
|
|
255
271
|
const latestScan = sorted[0];
|
|
256
|
-
const timestamp = latestScan ?
|
|
272
|
+
const timestamp = latestScan ? scanDate(latestScan) : new Date;
|
|
257
273
|
return {
|
|
258
274
|
carrier: "smsaexpress",
|
|
259
275
|
eventType: "status_update",
|
|
@@ -266,6 +282,28 @@ function mapWebhookShipmentToEvent(shipment) {
|
|
|
266
282
|
raw: shipment
|
|
267
283
|
};
|
|
268
284
|
}
|
|
285
|
+
function mapWebhookShipmentToEvents(shipment) {
|
|
286
|
+
const scans = shipment.Scans ?? [];
|
|
287
|
+
if (scans.length === 0) {
|
|
288
|
+
return [mapWebhookShipmentToEvent(shipment)];
|
|
289
|
+
}
|
|
290
|
+
const sorted = [...scans].sort((a, b) => scanTimestampMs(a) - scanTimestampMs(b));
|
|
291
|
+
return sorted.map((scan, index) => {
|
|
292
|
+
const isLatest = index === sorted.length - 1;
|
|
293
|
+
const status = isLatest && shipment.isDelivered ? "delivered" : mapSMSAStatus(scan.ScanType);
|
|
294
|
+
return {
|
|
295
|
+
carrier: "smsaexpress",
|
|
296
|
+
eventType: "status_update",
|
|
297
|
+
trackingNumber: shipment.AWB,
|
|
298
|
+
reference: shipment.Reference || undefined,
|
|
299
|
+
status,
|
|
300
|
+
statusCode: scan.ScanType,
|
|
301
|
+
statusLabel: scan.ScanDescription,
|
|
302
|
+
timestamp: scanDate(scan),
|
|
303
|
+
raw: shipment
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
}
|
|
269
307
|
function validateWebhookPayload(payload) {
|
|
270
308
|
if (!Array.isArray(payload)) {
|
|
271
309
|
throw new ValidationError("Invalid SMSA webhook payload: expected an array of shipments", { raw: payload });
|
|
@@ -276,8 +314,8 @@ function validateWebhookPayload(payload) {
|
|
|
276
314
|
});
|
|
277
315
|
}
|
|
278
316
|
for (const item of payload) {
|
|
279
|
-
if (!item || typeof item !== "object" || !("AWB" in item)
|
|
280
|
-
throw new ValidationError("Invalid SMSA webhook payload: shipment missing required
|
|
317
|
+
if (!item || typeof item !== "object" || !("AWB" in item)) {
|
|
318
|
+
throw new ValidationError("Invalid SMSA webhook payload: shipment missing required field (AWB)", { raw: item });
|
|
281
319
|
}
|
|
282
320
|
}
|
|
283
321
|
return payload;
|
|
@@ -290,7 +328,7 @@ function parseSMSAWebhook(payload, options) {
|
|
|
290
328
|
function parseSMSAWebhookBatch(payload, options) {
|
|
291
329
|
verifyWebhookAuth(options);
|
|
292
330
|
const shipments = validateWebhookPayload(payload);
|
|
293
|
-
return shipments.
|
|
331
|
+
return shipments.flatMap(mapWebhookShipmentToEvents);
|
|
294
332
|
}
|
|
295
333
|
|
|
296
334
|
// src/carriers/smsaexpress/adapter.ts
|
|
@@ -324,14 +362,21 @@ class SMSAExpressAdapter extends BaseCarrierAdapter {
|
|
|
324
362
|
getBaseUrl() {
|
|
325
363
|
return this.config.mode === "production" ? SMSA_PRODUCTION_URL : SMSA_SANDBOX_URL;
|
|
326
364
|
}
|
|
365
|
+
withOrderNumber(input) {
|
|
366
|
+
if (input.reference) {
|
|
367
|
+
return input;
|
|
368
|
+
}
|
|
369
|
+
return { ...input, reference: generateOrderNumber() };
|
|
370
|
+
}
|
|
327
371
|
async executeCreateShipment(input) {
|
|
328
|
-
const
|
|
372
|
+
const prepared = this.withOrderNumber(input);
|
|
373
|
+
const isC2B = prepared.serviceType !== undefined && C2B_SERVICE_CODES.has(prepared.serviceType.trim().toUpperCase());
|
|
329
374
|
if (isC2B) {
|
|
330
|
-
return this.createC2BShipment(
|
|
375
|
+
return this.createC2BShipment(prepared);
|
|
331
376
|
}
|
|
332
|
-
const request = mapCreateB2CRequest(
|
|
377
|
+
const request = mapCreateB2CRequest(prepared);
|
|
333
378
|
const response = await this.http.post("/api/shipment/b2c/new", request);
|
|
334
|
-
return mapShipmentResponse(response,
|
|
379
|
+
return mapShipmentResponse(response, prepared);
|
|
335
380
|
}
|
|
336
381
|
async createC2BShipment(input) {
|
|
337
382
|
const request = mapCreateC2BRequest(input);
|
|
@@ -340,7 +385,19 @@ class SMSAExpressAdapter extends BaseCarrierAdapter {
|
|
|
340
385
|
}
|
|
341
386
|
async cancelShipment(trackingNumber) {
|
|
342
387
|
const response = await this.http.post(`/api/c2b/cancel/${encodeURIComponent(trackingNumber)}`);
|
|
343
|
-
|
|
388
|
+
if (typeof response !== "string") {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
const hasCancelToken = /cancel/i.test(response);
|
|
392
|
+
const hasNegation = /\b(?:not|can\s?not|can'?t|cant|unable|fail(?:ed|ure)?|invalid|reject(?:ed)?|error)\b/i.test(response);
|
|
393
|
+
if (hasCancelToken && !hasNegation) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
throw new APIError(response.trim() || "SMSA did not confirm cancellation", {
|
|
397
|
+
carrier: "smsaexpress",
|
|
398
|
+
code: "CANCELLATION_UNCONFIRMED",
|
|
399
|
+
raw: response
|
|
400
|
+
});
|
|
344
401
|
}
|
|
345
402
|
async track(trackingNumber) {
|
|
346
403
|
const response = await this.http.get(`/api/track/single/${encodeURIComponent(trackingNumber)}`);
|
|
@@ -367,7 +424,7 @@ class SMSAExpressAdapter extends BaseCarrierAdapter {
|
|
|
367
424
|
return `data:application/pdf;base64,${waybill.awbFile}`;
|
|
368
425
|
}
|
|
369
426
|
} catch (error) {
|
|
370
|
-
if (!(error instanceof APIError) || error
|
|
427
|
+
if (!(error instanceof APIError) || error instanceof RateLimitError || error.statusCode !== undefined && error.statusCode >= 500) {
|
|
371
428
|
throw error;
|
|
372
429
|
}
|
|
373
430
|
}
|
|
@@ -379,16 +436,29 @@ class SMSAExpressAdapter extends BaseCarrierAdapter {
|
|
|
379
436
|
}
|
|
380
437
|
async getCities(countryCode = "SA") {
|
|
381
438
|
const response = await this.http.get(`/api/lookup/cities/${encodeURIComponent(countryCode)}`);
|
|
439
|
+
if (!Array.isArray(response)) {
|
|
440
|
+
throw new APIError("SMSA cities lookup returned an unexpected shape", {
|
|
441
|
+
carrier: "smsaexpress",
|
|
442
|
+
raw: response
|
|
443
|
+
});
|
|
444
|
+
}
|
|
382
445
|
return response.map(mapCity);
|
|
383
446
|
}
|
|
384
447
|
async getDropoffLocations() {
|
|
385
448
|
const response = await this.http.get("/api/lookup/smsaoffices");
|
|
449
|
+
if (!Array.isArray(response)) {
|
|
450
|
+
throw new APIError("SMSA offices lookup returned an unexpected shape", {
|
|
451
|
+
carrier: "smsaexpress",
|
|
452
|
+
raw: response
|
|
453
|
+
});
|
|
454
|
+
}
|
|
386
455
|
return response.map(mapOffice);
|
|
387
456
|
}
|
|
388
457
|
async create2WayShipment(input) {
|
|
389
|
-
const
|
|
458
|
+
const prepared = this.withOrderNumber(input);
|
|
459
|
+
const request = mapCreate2WayRequest(prepared);
|
|
390
460
|
const response = await this.http.post("/api/TwoWayShipment/new", request);
|
|
391
|
-
return mapShipmentResponse(response,
|
|
461
|
+
return mapShipmentResponse(response, prepared);
|
|
392
462
|
}
|
|
393
463
|
async sendInvoice(request) {
|
|
394
464
|
return this.http.post("/api/invoice", request);
|
|
@@ -415,4 +485,4 @@ export {
|
|
|
415
485
|
SMSAExpressAdapter
|
|
416
486
|
};
|
|
417
487
|
|
|
418
|
-
//# debugId=
|
|
488
|
+
//# debugId=AF4035876BEB4A1F64756E2164756E21
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/carriers/smsaexpress/services.ts", "../src/carriers/smsaexpress/mappers.ts", "../src/carriers/smsaexpress/adapter.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// file: src/carriers/smsaexpress/services.ts\n/**\n * SMSA Express Service Type Codes\n * Use these constants for type-safe service selection.\n */\n\nexport const SMSAService = {\n /** E-commerce delivery */\n ECOMMERCE_DELIVERY: \"EDDL\",\n /** Express delivery */\n EXPRESS_DELIVERY: \"EDEL\",\n /** C2B / Reverse pickup */\n C2B_REVERSE: \"EDCR\",\n} as const;\n\nexport type SMSAServiceType = (typeof SMSAService)[keyof typeof SMSAService];\n\n/**\n * SMSA Express Scan Type Codes → Unified ShipmentStatus mapping.\n *\n * Based on /api/track/statuslookup response.\n * Scan types not explicitly listed default to \"
|
|
6
|
-
"// file: src/carriers/smsaexpress/mappers.ts\n/**\n * SMSA Express Data Mappers\n * Transform between unified ShipFlow types and SMSA Express API formats.\n */\n\nimport {\n APIError,\n ValidationError,\n WebhookVerificationError,\n} from \"../../core/errors\";\nimport type {\n City,\n CreateShipmentInput,\n Location,\n Shipment,\n ShipmentStatus,\n TrackingEvent,\n TrackingResult,\n WebhookConfig,\n WebhookEvent,\n} from \"../../core/types\";\nimport { SMSAStatusCodes } from \"./services\";\nimport type {\n SMSACityLookupItem,\n SMSACreate2WayShipmentRequest,\n SMSACreateB2CShipmentRequest,\n SMSACreateC2BShipmentRequest,\n SMSAOfficeLookupItem,\n SMSAShipmentAddress,\n SMSAShipmentResponse,\n SMSATrackingResponse,\n SMSATrackingScan,\n SMSAWebhookShipment,\n} from \"./types\";\n\n// ============================================================================\n// STATUS MAPPING\n// ============================================================================\n\nexport function mapSMSAStatus(scanType: string): ShipmentStatus {\n return (SMSAStatusCodes[scanType] as ShipmentStatus) ?? \"in_transit\";\n}\n\n/**\n * Derive the current shipment status from tracking scans.\n * Defensively sorts by ScanDateTime descending before taking the latest.\n */\nfunction deriveStatusFromScans(\n scans: SMSATrackingScan[] | undefined,\n isDelivered?: boolean,\n): { status: ShipmentStatus; statusLabel: string } {\n if (isDelivered) {\n return { status: \"delivered\", statusLabel: \"Delivered\" };\n }\n // Records may omit Scans entirely (freshly-booked AWB, partial bulk record).\n const safeScans = scans ?? [];\n if (safeScans.length === 0) {\n return { status: \"unknown\", statusLabel: \"Unknown\" };\n }\n const sorted = [...safeScans].sort(\n (a, b) =>\n new Date(b.ScanDateTime).getTime() -\n new Date(a.ScanDateTime).getTime(),\n );\n const latest = sorted[0]!;\n return {\n status: mapSMSAStatus(latest.ScanType),\n statusLabel: latest.ScanDescription,\n };\n}\n\n// ============================================================================\n// REQUEST MAPPERS\n// ============================================================================\n\n/**\n * Round a weight to 3 decimal places to avoid float-arithmetic noise\n * (e.g. 0.1 + 0.2 = 0.30000000000000004) leaking into the API payload.\n */\nfunction roundWeight(weight: number): number {\n return Math.round(weight * 1000) / 1000;\n}\n\nfunction mapAddress(\n addr: CreateShipmentInput[\"shipper\"] | CreateShipmentInput[\"consignee\"],\n opts?: { includeShortCode?: boolean },\n): SMSAShipmentAddress {\n const result: SMSAShipmentAddress = {\n ContactName: addr.name,\n ContactPhoneNumber: addr.phone,\n Country: addr.countryCode,\n City: addr.city,\n AddressLine1: addr.line1,\n AddressLine2: addr.line2,\n District: addr.neighbourhood ?? addr.state,\n PostalCode: addr.postalCode,\n };\n\n if (addr.coordinates) {\n result.Coordinates = `${addr.coordinates.latitude},${addr.coordinates.longitude}`;\n }\n\n // ShortCode is valid only on the consignee address per the SMSA spec.\n if (opts?.includeShortCode && addr.nationalAddress?.shortCode) {\n result.ShortCode = addr.nationalAddress.shortCode;\n }\n\n return result;\n}\n\nexport function mapCreateB2CRequest(\n input: CreateShipmentInput,\n): SMSACreateB2CShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n const consigneeAddress = mapAddress(input.consignee, {\n includeShortCode: true,\n });\n if (input.options?.metadata?.consigneeId) {\n consigneeAddress.ConsigneeID = input.options.metadata.consigneeId as string;\n }\n\n return {\n ConsigneeAddress: consigneeAddress,\n ShipperAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? `ORD-${Date.now()}`,\n CODAmount: input.cod?.enabled ? input.cod.amount : 0,\n DeclaredValue: input.declaredValue?.amount ?? 0,\n ContentDescription: input.parcels[0]?.description ?? \"Shipment contents\",\n Parcels: totalPieces,\n ShipDate: new Date().toISOString().slice(0, 19),\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n ShipmentCurrency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n ServiceCode: input.serviceType,\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n VatPaid: (input.options?.metadata?.vatPaid as boolean) ?? true,\n DutyPaid: (input.options?.metadata?.dutyPaid as boolean) ?? false,\n };\n}\n\n/**\n * Map to C2B (reverse pickup) request.\n * In C2B flow, the consignee is the pickup point (customer returning),\n * and the shipper is the return-to address (merchant warehouse).\n */\nexport function mapCreateC2BRequest(\n input: CreateShipmentInput,\n): SMSACreateC2BShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n return {\n PickupAddress: mapAddress(input.consignee, { includeShortCode: true }),\n ReturnToAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? `ORD-${Date.now()}`,\n DeclaredValue: input.declaredValue?.amount ?? 0.1,\n ContentDescription:\n input.parcels[0]?.description ?? \"Return shipment contents\",\n Parcels: totalPieces,\n ShipDate: new Date().toISOString().slice(0, 19),\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n ShipmentCurrency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n ServiceCode: input.serviceType ?? \"EDCR\",\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n };\n}\n\n// ============================================================================\n// RESPONSE MAPPERS\n// ============================================================================\n\nexport function mapShipmentResponse(\n data: SMSAShipmentResponse,\n input: CreateShipmentInput,\n): Shipment {\n const firstWaybill = data.waybills?.[0];\n const trackingNumber = firstWaybill?.awb ?? data.sawb;\n\n if (!trackingNumber) {\n throw new APIError(\"No tracking number in shipment response\", {\n carrier: \"smsaexpress\",\n raw: data,\n });\n }\n\n return {\n carrier: \"smsaexpress\",\n trackingNumber,\n reference: input.reference,\n status: \"created\",\n statusLabel: \"Created\",\n codAmount: input.cod?.enabled ? input.cod.amount : undefined,\n declaredValue: input.declaredValue?.amount,\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n currency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n returnLabel: firstWaybill?.returnBarcode\n ? `data:application/pdf;base64,${firstWaybill.returnBarcode}`\n : undefined,\n // Guard a missing createDate so we never build `new Date(\"undefined+03:00\")`\n // (Invalid Date). Append the SMSA timezone (+03:00) only to bare timestamps.\n createdAt: data.createDate\n ? new Date(\n /[Z]$|[+-]\\d{2}(:\\d{2})?$/.test(data.createDate)\n ? data.createDate\n : `${data.createDate}+03:00`,\n )\n : new Date(),\n raw: data,\n };\n}\n\nexport function mapTrackingEvent(scan: SMSATrackingScan): TrackingEvent {\n return {\n timestamp: new Date(\n scan.ScanTimeZone\n ? `${scan.ScanDateTime}${scan.ScanTimeZone}`\n : scan.ScanDateTime,\n ),\n statusCode: scan.ScanType,\n status: mapSMSAStatus(scan.ScanType),\n description: scan.ScanDescription,\n location: scan.City,\n };\n}\n\nexport function mapTrackingResult(data: SMSATrackingResponse): TrackingResult {\n // Real API records (freshly-booked AWB, partial bulk record) may omit Scans\n // entirely; default to [] so a scan-less record yields \"unknown\" instead of\n // throwing (and failing the whole trackMultiple batch).\n const scans = data.Scans ?? [];\n const { status, statusLabel } = deriveStatusFromScans(scans, data.isDelivered);\n\n const deliveredScan = scans.find((s) => s.ScanType === \"DL\");\n const deliveredTimestamp = deliveredScan\n ? new Date(\n deliveredScan.ScanTimeZone\n ? `${deliveredScan.ScanDateTime}${deliveredScan.ScanTimeZone}`\n : deliveredScan.ScanDateTime,\n )\n : undefined;\n\n return {\n trackingNumber: data.AWB,\n carrier: \"smsaexpress\",\n reference: data.Reference || undefined,\n status,\n statusLabel,\n events: scans.map(mapTrackingEvent),\n deliveryDate: deliveredTimestamp,\n codAmount: data.CODAmount > 0 ? data.CODAmount : undefined,\n pieces: data.Pieces,\n raw: data,\n };\n}\n\nexport function mapCity(city: SMSACityLookupItem): City {\n return {\n nameEn: city.cityName,\n code: city.cityCode,\n };\n}\n\nexport function mapOffice(office: SMSAOfficeLookupItem): Location {\n const [lat, lng] = (office.coordinates || \"\")\n .split(\",\")\n .map((s) => parseFloat(s.trim()));\n\n return {\n id: office.code,\n name: office.address,\n nameAr: office.addressAR,\n city: office.cityName,\n latitude: Number.isNaN(lat) ? undefined : lat,\n longitude: Number.isNaN(lng) ? undefined : lng,\n };\n}\n\nexport function mapCreate2WayRequest(\n input: CreateShipmentInput,\n): SMSACreate2WayShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n const consigneeAddress = mapAddress(input.consignee, {\n includeShortCode: true,\n });\n if (input.options?.metadata?.consigneeId) {\n consigneeAddress.ConsigneeID = input.options.metadata.consigneeId as string;\n }\n\n return {\n ConsigneeAddress: consigneeAddress,\n ShipperAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? `ORD-${Date.now()}`,\n DeclaredValue: input.declaredValue?.amount ?? 0,\n ContentDescription: input.parcels[0]?.description ?? \"Shipment contents\",\n Parcels: totalPieces,\n ShipDate: new Date().toISOString().slice(0, 19),\n ShipmentCurrency: input.declaredValue?.currency ?? \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n VatPaid: (input.options?.metadata?.vatPaid as boolean) ?? true,\n DutyPaid: (input.options?.metadata?.dutyPaid as boolean) ?? false,\n };\n}\n\n// ============================================================================\n// WEBHOOK MAPPERS\n// ============================================================================\n\n/**\n * Timing-safe string comparison to prevent timing attacks on auth tokens.\n */\nfunction timingSafeEqual(a: string, b: string): boolean {\n const encoder = new TextEncoder();\n const bufA = encoder.encode(a);\n const bufB = encoder.encode(b);\n if (bufA.byteLength !== bufB.byteLength) return false;\n let mismatch = 0;\n for (let i = 0; i < bufA.byteLength; i++) {\n mismatch |= bufA[i]! ^ bufB[i]!;\n }\n return mismatch === 0;\n}\n\nfunction verifyWebhookAuth(options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n}): void {\n const { headers = {}, queryParams = {}, config } = options ?? {};\n\n // Verify auth via header (case-insensitive lookup, timing-safe comparison)\n if (config?.authHeader && config?.authValue) {\n const lowerKey = config.authHeader.toLowerCase();\n const headerValue = Object.entries(headers).find(\n ([k]) => k.toLowerCase() === lowerKey,\n )?.[1];\n if (!headerValue || !timingSafeEqual(headerValue, config.authValue)) {\n throw new WebhookVerificationError(\"Invalid webhook auth header\", {\n carrier: \"smsaexpress\",\n });\n }\n }\n\n // Verify auth via query param (SMSA uses API key as query param, timing-safe)\n if (config?.authQueryParam && config?.authQueryValue) {\n const paramValue = queryParams[config.authQueryParam];\n if (!paramValue || !timingSafeEqual(paramValue, config.authQueryValue)) {\n throw new WebhookVerificationError(\"Invalid webhook auth query param\", {\n carrier: \"smsaexpress\",\n });\n }\n }\n}\n\nfunction mapWebhookShipmentToEvent(\n shipment: SMSAWebhookShipment,\n): WebhookEvent {\n // A webhook record may arrive without Scans; default to [] so a scan-less\n // shipment yields \"unknown\" instead of throwing.\n const scans = shipment.Scans ?? [];\n const { status, statusLabel } = deriveStatusFromScans(\n scans,\n shipment.isDelivered,\n );\n\n // Sort scans descending to get the latest one for timestamp/statusCode\n const sorted = [...scans].sort(\n (a, b) =>\n new Date(b.ScanDateTime).getTime() -\n new Date(a.ScanDateTime).getTime(),\n );\n const latestScan = sorted[0];\n const timestamp = latestScan\n ? new Date(\n latestScan.ScanTimeZone\n ? `${latestScan.ScanDateTime}${latestScan.ScanTimeZone}`\n : latestScan.ScanDateTime,\n )\n : new Date();\n\n return {\n carrier: \"smsaexpress\",\n eventType: \"status_update\",\n trackingNumber: shipment.AWB,\n reference: shipment.Reference || undefined,\n status,\n statusCode: latestScan?.ScanType ?? \"unknown\",\n statusLabel,\n timestamp,\n raw: shipment,\n };\n}\n\nfunction validateWebhookPayload(payload: unknown): SMSAWebhookShipment[] {\n if (!Array.isArray(payload)) {\n throw new ValidationError(\n \"Invalid SMSA webhook payload: expected an array of shipments\",\n { raw: payload },\n );\n }\n\n if (payload.length === 0) {\n throw new ValidationError(\"Invalid SMSA webhook payload: empty array\", {\n raw: payload,\n });\n }\n\n for (const item of payload) {\n if (\n !item ||\n typeof item !== \"object\" ||\n !(\"AWB\" in item) ||\n !(\"Scans\" in item)\n ) {\n throw new ValidationError(\n \"Invalid SMSA webhook payload: shipment missing required fields (AWB, Scans)\",\n { raw: item },\n );\n }\n }\n\n return payload as SMSAWebhookShipment[];\n}\n\n/**\n * Parse an SMSA webhook payload and return a single WebhookEvent\n * for the first shipment in the batch.\n *\n * SMSA sends webhooks as an array of shipments. This function returns\n * only the first item — use `parseSMSAWebhookBatch()` for full batch parsing.\n */\nexport function parseSMSAWebhook(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n): WebhookEvent {\n verifyWebhookAuth(options);\n const shipments = validateWebhookPayload(payload);\n return mapWebhookShipmentToEvent(shipments[0]!);\n}\n\n/**\n * Parse an SMSA webhook payload and return a WebhookEvent for every\n * shipment in the batch.\n *\n * SMSA sends webhook payloads as an array of shipments, each with\n * their own tracking scans.\n */\nexport function parseSMSAWebhookBatch(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n): WebhookEvent[] {\n verifyWebhookAuth(options);\n const shipments = validateWebhookPayload(payload);\n return shipments.map(mapWebhookShipmentToEvent);\n}\n",
|
|
7
|
-
"// file: src/carriers/smsaexpress/adapter.ts\n/**\n * SMSA Express Carrier Adapter\n * Full implementation of the CarrierAdapter interface for SMSA Express API.\n */\n\nimport { APIError } from \"../../core/errors\";\nimport { HttpClient } from \"../../core/http\";\nimport type {\n CarrierConfig,\n City,\n CreateShipmentInput,\n Location,\n Shipment,\n TrackingResult,\n WebhookConfig,\n WebhookEvent,\n} from \"../../core/types\";\nimport { BaseCarrierAdapter } from \"../base\";\nimport {\n mapCity,\n mapCreate2WayRequest,\n mapCreateB2CRequest,\n mapCreateC2BRequest,\n mapOffice,\n mapShipmentResponse,\n mapTrackingResult,\n parseSMSAWebhook,\n parseSMSAWebhookBatch,\n} from \"./mappers\";\nimport type {\n SMSACityLookupItem,\n SMSAOfficeLookupItem,\n SMSAPushIdDetailsRequest,\n SMSAPushIdDetailsResponse,\n SMSASendInvoiceRequest,\n SMSAShipmentResponse,\n SMSAShortAddressResponse,\n SMSATrackingResponse,\n} from \"./types\";\n\nconst SMSA_SANDBOX_URL = \"https://ecomapis-sandbox.azurewebsites.net\";\nconst SMSA_PRODUCTION_URL = \"https://ecomapis.smsaexpress.com\";\n\n/** Reverse-pickup / C2B service codes */\nconst C2B_SERVICE_CODES = new Set([\"EDCR\"]);\n\nexport interface SMSAExpressConfig extends CarrierConfig {\n credentials: {\n apiKey: string;\n };\n}\n\nexport class SMSAExpressAdapter extends BaseCarrierAdapter {\n readonly name = \"smsaexpress\";\n readonly supportedCountries = [\n \"SA\",\n \"AE\",\n \"BH\",\n \"EG\",\n \"KW\",\n \"OM\",\n \"QA\",\n \"JO\",\n ];\n\n private http: HttpClient;\n\n constructor(config: SMSAExpressConfig) {\n super(config);\n this.http = new HttpClient({\n baseUrl: this.getBaseUrl(),\n carrier: \"smsaexpress\",\n headers: {\n apikey: config.credentials.apiKey,\n },\n });\n }\n\n protected getBaseUrl(): string {\n return this.config.mode === \"production\"\n ? SMSA_PRODUCTION_URL\n : SMSA_SANDBOX_URL;\n }\n\n // =========================================================================\n // SHIPPING\n // =========================================================================\n\n protected async executeCreateShipment(\n input: CreateShipmentInput,\n ): Promise<Shipment> {\n const isC2B =\n input.serviceType !== undefined &&\n C2B_SERVICE_CODES.has(input.serviceType);\n\n if (isC2B) {\n return this.createC2BShipment(input);\n }\n\n const request = mapCreateB2CRequest(input);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/shipment/b2c/new\",\n request,\n );\n\n return mapShipmentResponse(response, input);\n }\n\n private async createC2BShipment(\n input: CreateShipmentInput,\n ): Promise<Shipment> {\n const request = mapCreateC2BRequest(input);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/c2b/new\",\n request,\n );\n\n return mapShipmentResponse(response, input);\n }\n\n /**\n * Cancel a reverse-pickup (C2B) shipment.\n *\n * **Important:** SMSA only supports cancellation for C2B/reverse-pickup shipments.\n * Calling this on a B2C shipment will result in an API error or return `false`.\n * B2C shipments cannot be cancelled via the SMSA API.\n */\n async cancelShipment(trackingNumber: string): Promise<boolean> {\n const response = await this.http.post<string>(\n `/api/c2b/cancel/${encodeURIComponent(trackingNumber)}`,\n );\n // API returns a plain-text message on success (e.g. \"Shipment Cancelled\n // Successfully!\"); inspect it for confirmation. A non-string (JSON) success\n // response is treated as success.\n return typeof response === \"string\"\n ? response.toLowerCase().includes(\"cancelled\")\n : true;\n }\n\n // =========================================================================\n // TRACKING\n // =========================================================================\n\n async track(trackingNumber: string): Promise<TrackingResult> {\n const response = await this.http.get<SMSATrackingResponse>(\n `/api/track/single/${encodeURIComponent(trackingNumber)}`,\n );\n\n return mapTrackingResult(response);\n }\n\n async trackMultiple(trackingNumbers: string[]): Promise<TrackingResult[]> {\n const response = await this.http.post<SMSATrackingResponse[]>(\n \"/api/track/bulk/\",\n trackingNumbers,\n { retry: true },\n );\n\n return response.map(mapTrackingResult);\n }\n\n async trackByReference(reference: string): Promise<TrackingResult> {\n const response = await this.http.get<SMSATrackingResponse>(\n `/api/track/reference/${encodeURIComponent(reference)}`,\n );\n\n return mapTrackingResult(response);\n }\n\n // =========================================================================\n // LABELS\n // =========================================================================\n\n async getLabel(\n trackingNumber: string,\n _format?: \"PDF\" | \"ZPL\" | \"PNG\",\n ): Promise<string> {\n // SMSA returns the waybill file (base64 PDF) as part of the shipment query.\n // Try B2C first (most common), then C2B as fallback.\n const encoded = encodeURIComponent(trackingNumber);\n\n for (const path of [\n `/api/shipment/b2c/query/${encoded}`,\n `/api/c2b/query/${encoded}`,\n ]) {\n try {\n const response = await this.http.get<SMSAShipmentResponse>(path);\n const waybill = response.waybills?.[0];\n if (waybill?.awbFile) {\n return `data:application/pdf;base64,${waybill.awbFile}`;\n }\n } catch (error) {\n // Only swallow 4xx API errors (shipment type mismatch / not found).\n // Re-throw auth, network, server, and unexpected errors immediately.\n if (\n !(error instanceof APIError) ||\n error.statusCode === 401 ||\n (error.statusCode !== undefined && error.statusCode >= 500)\n ) {\n throw error;\n }\n }\n }\n\n throw new APIError(\"No label found for shipment\", {\n carrier: \"smsaexpress\",\n raw: { trackingNumber },\n });\n }\n\n // =========================================================================\n // CITIES & LOCATIONS\n // =========================================================================\n\n async getCities(countryCode = \"SA\"): Promise<City[]> {\n const response = await this.http.get<SMSACityLookupItem[]>(\n `/api/lookup/cities/${encodeURIComponent(countryCode)}`,\n );\n\n return response.map(mapCity);\n }\n\n async getDropoffLocations(): Promise<Location[]> {\n const response = await this.http.get<SMSAOfficeLookupItem[]>(\n \"/api/lookup/smsaoffices\",\n );\n\n return response.map(mapOffice);\n }\n\n // =========================================================================\n // 2-WAY SHIPMENT\n // =========================================================================\n\n async create2WayShipment(input: CreateShipmentInput): Promise<Shipment> {\n const request = mapCreate2WayRequest(input);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/TwoWayShipment/new\",\n request,\n );\n\n return mapShipmentResponse(response, input);\n }\n\n // =========================================================================\n // INVOICE & ID OPERATIONS (SMSA-specific)\n // =========================================================================\n\n async sendInvoice(request: SMSASendInvoiceRequest): Promise<string> {\n return this.http.post<string>(\"/api/invoice\", request);\n }\n\n async validateShortAddress(\n shortCode: string,\n ): Promise<SMSAShortAddressResponse> {\n return this.http.get<SMSAShortAddressResponse>(\n `/api/Lookup/FullAddressByShortCode/${encodeURIComponent(shortCode)}`,\n );\n }\n\n async pushIdDetails(\n request: SMSAPushIdDetailsRequest,\n ): Promise<SMSAPushIdDetailsResponse> {\n return this.http.post<SMSAPushIdDetailsResponse>(\n \"/api/shipment/identity-details\",\n request,\n );\n }\n\n // =========================================================================\n // WEBHOOKS\n // =========================================================================\n\n parseWebhook(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n ): WebhookEvent {\n return parseSMSAWebhook(payload, options);\n }\n\n /**\n * Parse a batch SMSA webhook payload into multiple events.\n *\n * SMSA sends webhook payloads as an array of shipments, each with their own\n * tracking scans. This method returns a WebhookEvent for every shipment\n * in the payload.\n */\n parseWebhookBatch(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n ): WebhookEvent[] {\n return parseSMSAWebhookBatch(payload, options);\n }\n}\n"
|
|
5
|
+
"// file: src/carriers/smsaexpress/services.ts\n/**\n * SMSA Express Service Type Codes\n * Use these constants for type-safe service selection.\n */\n\nexport const SMSAService = {\n /** E-commerce delivery */\n ECOMMERCE_DELIVERY: \"EDDL\",\n /** Express delivery */\n EXPRESS_DELIVERY: \"EDEL\",\n /** C2B / Reverse pickup */\n C2B_REVERSE: \"EDCR\",\n} as const;\n\nexport type SMSAServiceType = (typeof SMSAService)[keyof typeof SMSAService];\n\n/**\n * SMSA Express Scan Type Codes → Unified ShipmentStatus mapping.\n *\n * Based on /api/track/statuslookup response.\n * Scan types not explicitly listed default to \"unknown\" (see mapSMSAStatus)\n * so operators can detect unmapped codes instead of silently treating them\n * as in-transit.\n */\nexport const SMSAStatusCodes: Record<string, string> = {\n // Delivery\n DL: \"delivered\",\n\n // Out for delivery\n OD: \"out_for_delivery\",\n\n // Arrived at facility\n AF: \"at_warehouse\",\n\n // Hub / sorting\n HOP: \"in_transit\",\n HOR: \"in_transit\",\n HOT: \"in_transit\",\n\n // Picked up / collected\n PU: \"picked_up\",\n PKD: \"picked_up\",\n\n // Customs\n CR: \"in_transit\",\n CH: \"in_transit\",\n\n // Exceptions\n DE: \"exception\",\n DMG: \"exception\",\n MISS: \"exception\",\n\n // Cancelled / returned\n CAN: \"cancelled\",\n RTO: \"returned\",\n RTN: \"returned\",\n\n // Processing\n CC: \"at_warehouse\",\n PP: \"pending\",\n\n // Created / booked\n BK: \"created\",\n NEW: \"created\",\n};\n",
|
|
6
|
+
"// file: src/carriers/smsaexpress/mappers.ts\n/**\n * SMSA Express Data Mappers\n * Transform between unified ShipFlow types and SMSA Express API formats.\n */\n\nimport {\n APIError,\n ValidationError,\n WebhookVerificationError,\n} from \"../../core/errors\";\nimport type {\n City,\n CreateShipmentInput,\n Location,\n Shipment,\n ShipmentStatus,\n TrackingEvent,\n TrackingResult,\n WebhookConfig,\n WebhookEvent,\n} from \"../../core/types\";\nimport { SMSAStatusCodes } from \"./services\";\nimport type {\n SMSACityLookupItem,\n SMSACreate2WayShipmentRequest,\n SMSACreateB2CShipmentRequest,\n SMSACreateC2BShipmentRequest,\n SMSAOfficeLookupItem,\n SMSAShipmentAddress,\n SMSAShipmentResponse,\n SMSATrackingResponse,\n SMSATrackingScan,\n SMSAWebhookShipment,\n} from \"./types\";\n\n// ============================================================================\n// STATUS MAPPING\n// ============================================================================\n\nexport function mapSMSAStatus(scanType: string): ShipmentStatus {\n return (SMSAStatusCodes[scanType] as ShipmentStatus) ?? \"unknown\";\n}\n\n/**\n * Resolve a scan's Date, applying its ScanTimeZone offset when present\n * (consistent with mapTrackingEvent / mapShipmentResponse timestamp handling).\n */\nfunction scanDate(scan: SMSATrackingScan): Date {\n return new Date(\n scan.ScanTimeZone\n ? `${scan.ScanDateTime}${scan.ScanTimeZone}`\n : scan.ScanDateTime,\n );\n}\n\nfunction scanTimestampMs(scan: SMSATrackingScan): number {\n return scanDate(scan).getTime();\n}\n\n/**\n * Derive the current shipment status from tracking scans.\n * Defensively sorts by (zone-adjusted) ScanDateTime descending before taking\n * the latest.\n */\nfunction deriveStatusFromScans(\n scans: SMSATrackingScan[] | undefined,\n isDelivered?: boolean,\n): { status: ShipmentStatus; statusLabel: string } {\n if (isDelivered) {\n return { status: \"delivered\", statusLabel: \"Delivered\" };\n }\n // Records may omit Scans entirely (freshly-booked AWB, partial bulk record).\n const safeScans = scans ?? [];\n if (safeScans.length === 0) {\n return { status: \"unknown\", statusLabel: \"Unknown\" };\n }\n const sorted = [...safeScans].sort(\n (a, b) => scanTimestampMs(b) - scanTimestampMs(a),\n );\n const latest = sorted[0]!;\n return {\n status: mapSMSAStatus(latest.ScanType),\n statusLabel: latest.ScanDescription,\n };\n}\n\n// ============================================================================\n// REQUEST MAPPERS\n// ============================================================================\n\n/**\n * Round a weight to 3 decimal places to avoid float-arithmetic noise\n * (e.g. 0.1 + 0.2 = 0.30000000000000004) leaking into the API payload.\n */\nfunction roundWeight(weight: number): number {\n return Math.round(weight * 1000) / 1000;\n}\n\n/** Strip non-digit characters from phone numbers (SMSA requires digits only). */\nfunction sanitizePhone(phone: string): string {\n return phone.replace(/\\D/g, \"\");\n}\n\n/**\n * Generate a fallback OrderNumber when the caller supplies no reference. Single\n * source of the `ORD-<epoch-ms>` format — the adapter uses it to fix a reference\n * on the input so the booked OrderNumber is surfaced back on the Shipment, and\n * the request mappers reference it as their type-required default.\n */\nexport function generateOrderNumber(): string {\n return `ORD-${Date.now()}`;\n}\n\n/**\n * Format the ShipDate as the Saudi (UTC+3) wall-clock, with no zone suffix.\n *\n * SMSA treats a bare (zone-less) timestamp as Saudi local time (UTC+3) — its\n * own responses come back bare and the response mapper appends `+03:00` to them.\n * Sending `new Date().toISOString().slice(0, 19)` (zero-offset UTC wall-clock)\n * therefore lands a day early between ~21:00–24:00 Saudi time, so shift by +3h\n * before formatting.\n */\nfunction smsaShipDate(): string {\n return new Date(Date.now() + 3 * 60 * 60 * 1000)\n .toISOString()\n .slice(0, 19);\n}\n\nfunction mapAddress(\n addr: CreateShipmentInput[\"shipper\"] | CreateShipmentInput[\"consignee\"],\n opts?: { includeShortCode?: boolean },\n): SMSAShipmentAddress {\n const result: SMSAShipmentAddress = {\n ContactName: addr.name,\n ContactPhoneNumber: sanitizePhone(addr.phone),\n Country: addr.countryCode,\n City: addr.city,\n AddressLine1: addr.line1,\n AddressLine2: addr.line2,\n District: addr.neighbourhood ?? addr.state,\n PostalCode: addr.postalCode,\n };\n\n if (addr.coordinates) {\n result.Coordinates = `${addr.coordinates.latitude},${addr.coordinates.longitude}`;\n }\n\n // ShortCode is valid only on the consignee address per the SMSA spec.\n if (opts?.includeShortCode && addr.nationalAddress?.shortCode) {\n result.ShortCode = addr.nationalAddress.shortCode;\n }\n\n return result;\n}\n\nexport function mapCreateB2CRequest(\n input: CreateShipmentInput,\n): SMSACreateB2CShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n const consigneeAddress = mapAddress(input.consignee, {\n includeShortCode: true,\n });\n if (input.options?.metadata?.consigneeId) {\n consigneeAddress.ConsigneeID = input.options.metadata.consigneeId as string;\n }\n\n return {\n ConsigneeAddress: consigneeAddress,\n ShipperAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? generateOrderNumber(),\n CODAmount: input.cod?.enabled ? input.cod.amount : 0,\n DeclaredValue: input.declaredValue?.amount ?? 0,\n ContentDescription: input.parcels[0]?.description ?? \"Shipment contents\",\n Parcels: totalPieces,\n // SMSA reads bare timestamps as Saudi local time (UTC+3), so send the\n // UTC+3 wall-clock rather than zero-offset UTC.\n ShipDate: smsaShipDate(),\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n ShipmentCurrency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n ServiceCode: input.serviceType,\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n VatPaid: (input.options?.metadata?.vatPaid as boolean) ?? true,\n DutyPaid: (input.options?.metadata?.dutyPaid as boolean) ?? false,\n };\n}\n\n/**\n * Map to C2B (reverse pickup) request.\n * In C2B flow, the consignee is the pickup point (customer returning),\n * and the shipper is the return-to address (merchant warehouse).\n */\nexport function mapCreateC2BRequest(\n input: CreateShipmentInput,\n): SMSACreateC2BShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n return {\n PickupAddress: mapAddress(input.consignee, { includeShortCode: true }),\n ReturnToAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? generateOrderNumber(),\n DeclaredValue: input.declaredValue?.amount ?? 0.1,\n ContentDescription:\n input.parcels[0]?.description ?? \"Return shipment contents\",\n Parcels: totalPieces,\n // SMSA reads bare timestamps as Saudi local time (UTC+3), so send the\n // UTC+3 wall-clock rather than zero-offset UTC.\n ShipDate: smsaShipDate(),\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n ShipmentCurrency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n ServiceCode: input.serviceType ?? \"EDCR\",\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n };\n}\n\n// ============================================================================\n// RESPONSE MAPPERS\n// ============================================================================\n\nexport function mapShipmentResponse(\n data: SMSAShipmentResponse,\n input: CreateShipmentInput,\n): Shipment {\n const firstWaybill = data.waybills?.[0];\n const trackingNumber = firstWaybill?.awb ?? data.sawb;\n\n if (!trackingNumber) {\n throw new APIError(\"No tracking number in shipment response\", {\n carrier: \"smsaexpress\",\n raw: data,\n });\n }\n\n return {\n carrier: \"smsaexpress\",\n trackingNumber,\n reference: input.reference,\n status: \"created\",\n statusLabel: \"Created\",\n codAmount: input.cod?.enabled ? input.cod.amount : undefined,\n declaredValue: input.declaredValue?.amount,\n // When COD is enabled, its currency is the amount physically collected\n // and must win over the declared-value currency.\n currency:\n (input.cod?.enabled ? input.cod.currency : undefined) ??\n input.declaredValue?.currency ??\n input.cod?.currency ??\n \"SAR\",\n returnLabel: firstWaybill?.returnBarcode\n ? `data:application/pdf;base64,${firstWaybill.returnBarcode}`\n : undefined,\n // Guard a missing createDate so we never build `new Date(\"undefined+03:00\")`\n // (Invalid Date). Append the SMSA timezone (+03:00) only to bare timestamps.\n createdAt: data.createDate\n ? new Date(\n /[Z]$|[+-]\\d{2}(:\\d{2})?$/.test(data.createDate)\n ? data.createDate\n : `${data.createDate}+03:00`,\n )\n : new Date(),\n raw: data,\n };\n}\n\nexport function mapTrackingEvent(scan: SMSATrackingScan): TrackingEvent {\n return {\n timestamp: new Date(\n scan.ScanTimeZone\n ? `${scan.ScanDateTime}${scan.ScanTimeZone}`\n : scan.ScanDateTime,\n ),\n statusCode: scan.ScanType,\n status: mapSMSAStatus(scan.ScanType),\n description: scan.ScanDescription,\n location: scan.City,\n };\n}\n\nexport function mapTrackingResult(data: SMSATrackingResponse): TrackingResult {\n // Real API records (freshly-booked AWB, partial bulk record) may omit Scans\n // entirely; default to [] so a scan-less record yields \"unknown\" instead of\n // throwing (and failing the whole trackMultiple batch).\n const scans = data.Scans ?? [];\n const { status, statusLabel } = deriveStatusFromScans(scans, data.isDelivered);\n\n const deliveredScan = scans.find((s) => s.ScanType === \"DL\");\n const deliveredTimestamp = deliveredScan\n ? new Date(\n deliveredScan.ScanTimeZone\n ? `${deliveredScan.ScanDateTime}${deliveredScan.ScanTimeZone}`\n : deliveredScan.ScanDateTime,\n )\n : undefined;\n\n return {\n trackingNumber: data.AWB,\n carrier: \"smsaexpress\",\n reference: data.Reference || undefined,\n status,\n statusLabel,\n events: scans.map(mapTrackingEvent),\n deliveryDate: deliveredTimestamp,\n codAmount: data.CODAmount > 0 ? data.CODAmount : undefined,\n pieces: data.Pieces,\n raw: data,\n };\n}\n\nexport function mapCity(city: SMSACityLookupItem): City {\n return {\n nameEn: city.cityName,\n code: city.cityCode,\n };\n}\n\nexport function mapOffice(office: SMSAOfficeLookupItem): Location {\n const [lat, lng] = (office.coordinates || \"\")\n .split(\",\")\n .map((s) => parseFloat(s.trim()));\n\n return {\n id: office.code,\n name: office.address,\n nameAr: office.addressAR,\n city: office.cityName,\n latitude: Number.isNaN(lat) ? undefined : lat,\n longitude: Number.isNaN(lng) ? undefined : lng,\n };\n}\n\nexport function mapCreate2WayRequest(\n input: CreateShipmentInput,\n): SMSACreate2WayShipmentRequest {\n const totalPieces = input.parcels.reduce((sum, p) => sum + p.pieces, 0);\n const totalWeight = input.parcels.reduce(\n (sum, p) =>\n sum +\n (p.weight.unit === \"lb\" ? p.weight.value * 0.453592 : p.weight.value),\n 0,\n );\n\n const consigneeAddress = mapAddress(input.consignee, {\n includeShortCode: true,\n });\n if (input.options?.metadata?.consigneeId) {\n consigneeAddress.ConsigneeID = input.options.metadata.consigneeId as string;\n }\n\n return {\n ConsigneeAddress: consigneeAddress,\n ShipperAddress: mapAddress(input.shipper),\n OrderNumber: input.reference ?? generateOrderNumber(),\n DeclaredValue: input.declaredValue?.amount ?? 0,\n ContentDescription: input.parcels[0]?.description ?? \"Shipment contents\",\n Parcels: totalPieces,\n // SMSA reads bare timestamps as Saudi local time (UTC+3), so send the\n // UTC+3 wall-clock rather than zero-offset UTC.\n ShipDate: smsaShipDate(),\n ShipmentCurrency: input.declaredValue?.currency ?? \"SAR\",\n Weight: roundWeight(totalWeight),\n WeightUnit: \"KG\",\n WaybillType: input.labelFormat === \"ZPL\" ? \"ZPL\" : \"PDF\",\n SMSARetailID: (input.options?.metadata?.smsaRetailId as string) ?? \"0\",\n VatPaid: (input.options?.metadata?.vatPaid as boolean) ?? true,\n DutyPaid: (input.options?.metadata?.dutyPaid as boolean) ?? false,\n };\n}\n\n// ============================================================================\n// WEBHOOK MAPPERS\n// ============================================================================\n\n/**\n * Timing-safe string comparison to prevent timing attacks on auth tokens.\n */\nfunction timingSafeEqual(a: string, b: string): boolean {\n const encoder = new TextEncoder();\n const bufA = encoder.encode(a);\n const bufB = encoder.encode(b);\n if (bufA.byteLength !== bufB.byteLength) return false;\n let mismatch = 0;\n for (let i = 0; i < bufA.byteLength; i++) {\n mismatch |= bufA[i]! ^ bufB[i]!;\n }\n return mismatch === 0;\n}\n\nfunction verifyWebhookAuth(options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n}): void {\n const { headers = {}, queryParams = {}, config } = options ?? {};\n\n // Verify auth via header (case-insensitive lookup, timing-safe comparison)\n if (config?.authHeader && config?.authValue) {\n const lowerKey = config.authHeader.toLowerCase();\n const headerValue = Object.entries(headers).find(\n ([k]) => k.toLowerCase() === lowerKey,\n )?.[1];\n if (!headerValue || !timingSafeEqual(headerValue, config.authValue)) {\n throw new WebhookVerificationError(\"Invalid webhook auth header\", {\n carrier: \"smsaexpress\",\n });\n }\n }\n\n // Verify auth via query param (SMSA uses API key as query param, timing-safe)\n if (config?.authQueryParam && config?.authQueryValue) {\n const paramValue = queryParams[config.authQueryParam];\n if (!paramValue || !timingSafeEqual(paramValue, config.authQueryValue)) {\n throw new WebhookVerificationError(\"Invalid webhook auth query param\", {\n carrier: \"smsaexpress\",\n });\n }\n }\n}\n\nfunction mapWebhookShipmentToEvent(\n shipment: SMSAWebhookShipment,\n): WebhookEvent {\n // A webhook record may arrive without Scans; default to [] so a scan-less\n // shipment yields \"unknown\" instead of throwing.\n const scans = shipment.Scans ?? [];\n const { status, statusLabel } = deriveStatusFromScans(\n scans,\n shipment.isDelivered,\n );\n\n // Sort scans descending (zone-adjusted) to get the latest one for\n // timestamp/statusCode.\n const sorted = [...scans].sort(\n (a, b) => scanTimestampMs(b) - scanTimestampMs(a),\n );\n const latestScan = sorted[0];\n const timestamp = latestScan ? scanDate(latestScan) : new Date();\n\n return {\n carrier: \"smsaexpress\",\n eventType: \"status_update\",\n trackingNumber: shipment.AWB,\n reference: shipment.Reference || undefined,\n status,\n statusCode: latestScan?.ScanType ?? \"unknown\",\n statusLabel,\n timestamp,\n raw: shipment,\n };\n}\n\n/**\n * Map a webhook shipment to one WebhookEvent PER scan, in chronological\n * (oldest → newest) order.\n *\n * SMSA can report several new scans for the same shipment in a single\n * webhook call (e.g. AF, OD, DL all at once). Collapsing that into only the\n * latest scan silently drops intermediate transitions/history, so this\n * expands every scan into its own event.\n */\nfunction mapWebhookShipmentToEvents(\n shipment: SMSAWebhookShipment,\n): WebhookEvent[] {\n const scans = shipment.Scans ?? [];\n\n if (scans.length === 0) {\n // No scans to expand — fall back to the single derived (possibly\n // \"unknown\"/isDelivered-driven) event.\n return [mapWebhookShipmentToEvent(shipment)];\n }\n\n const sorted = [...scans].sort(\n (a, b) => scanTimestampMs(a) - scanTimestampMs(b),\n );\n\n return sorted.map((scan, index) => {\n // Only the chronologically-last scan can be elevated to \"delivered\" by\n // the isDelivered flag; earlier scans reflect their own scan type.\n const isLatest = index === sorted.length - 1;\n const status: ShipmentStatus =\n isLatest && shipment.isDelivered\n ? \"delivered\"\n : mapSMSAStatus(scan.ScanType);\n\n return {\n carrier: \"smsaexpress\",\n eventType: \"status_update\",\n trackingNumber: shipment.AWB,\n reference: shipment.Reference || undefined,\n status,\n statusCode: scan.ScanType,\n statusLabel: scan.ScanDescription,\n timestamp: scanDate(scan),\n raw: shipment,\n };\n });\n}\n\nfunction validateWebhookPayload(payload: unknown): SMSAWebhookShipment[] {\n if (!Array.isArray(payload)) {\n throw new ValidationError(\n \"Invalid SMSA webhook payload: expected an array of shipments\",\n { raw: payload },\n );\n }\n\n if (payload.length === 0) {\n throw new ValidationError(\"Invalid SMSA webhook payload: empty array\", {\n raw: payload,\n });\n }\n\n for (const item of payload) {\n // Only AWB is truly required (it becomes the event's trackingNumber). Scans\n // may be absent on a freshly-booked record — every mapper defends with\n // `Scans ?? []` and yields an \"unknown\" status — so requiring it here would\n // wrongly reject valid scan-less webhooks.\n if (!item || typeof item !== \"object\" || !(\"AWB\" in item)) {\n throw new ValidationError(\n \"Invalid SMSA webhook payload: shipment missing required field (AWB)\",\n { raw: item },\n );\n }\n }\n\n return payload as SMSAWebhookShipment[];\n}\n\n/**\n * Parse an SMSA webhook payload and return a single WebhookEvent\n * for the first shipment in the batch.\n *\n * SMSA sends webhooks as an array of shipments. This function returns\n * only the first item — use `parseSMSAWebhookBatch()` for full batch parsing.\n */\nexport function parseSMSAWebhook(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n): WebhookEvent {\n verifyWebhookAuth(options);\n const shipments = validateWebhookPayload(payload);\n return mapWebhookShipmentToEvent(shipments[0]!);\n}\n\n/**\n * Parse an SMSA webhook payload and return a WebhookEvent for every\n * scan of every shipment in the batch (in chronological order per shipment).\n *\n * SMSA sends webhook payloads as an array of shipments, each with their own\n * tracking scans, and a single call can carry multiple new scans for the\n * same shipment (e.g. AF, OD, DL together) — each becomes its own event so\n * no intermediate transition/history is dropped.\n */\nexport function parseSMSAWebhookBatch(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n): WebhookEvent[] {\n verifyWebhookAuth(options);\n const shipments = validateWebhookPayload(payload);\n return shipments.flatMap(mapWebhookShipmentToEvents);\n}\n",
|
|
7
|
+
"// file: src/carriers/smsaexpress/adapter.ts\n/**\n * SMSA Express Carrier Adapter\n * Full implementation of the CarrierAdapter interface for SMSA Express API.\n */\n\nimport { APIError, RateLimitError } from \"../../core/errors\";\nimport { HttpClient } from \"../../core/http\";\nimport type {\n CarrierConfig,\n City,\n CreateShipmentInput,\n Location,\n Shipment,\n TrackingResult,\n WebhookConfig,\n WebhookEvent,\n} from \"../../core/types\";\nimport { BaseCarrierAdapter } from \"../base\";\nimport {\n generateOrderNumber,\n mapCity,\n mapCreate2WayRequest,\n mapCreateB2CRequest,\n mapCreateC2BRequest,\n mapOffice,\n mapShipmentResponse,\n mapTrackingResult,\n parseSMSAWebhook,\n parseSMSAWebhookBatch,\n} from \"./mappers\";\nimport type {\n SMSACityLookupItem,\n SMSAOfficeLookupItem,\n SMSAPushIdDetailsRequest,\n SMSAPushIdDetailsResponse,\n SMSASendInvoiceRequest,\n SMSAShipmentResponse,\n SMSAShortAddressResponse,\n SMSATrackingResponse,\n} from \"./types\";\n\nconst SMSA_SANDBOX_URL = \"https://ecomapis-sandbox.azurewebsites.net\";\nconst SMSA_PRODUCTION_URL = \"https://ecomapis.smsaexpress.com\";\n\n/** Reverse-pickup / C2B service codes */\nconst C2B_SERVICE_CODES = new Set([\"EDCR\"]);\n\nexport interface SMSAExpressConfig extends CarrierConfig {\n credentials: {\n apiKey: string;\n };\n}\n\nexport class SMSAExpressAdapter extends BaseCarrierAdapter {\n readonly name = \"smsaexpress\";\n readonly supportedCountries = [\n \"SA\",\n \"AE\",\n \"BH\",\n \"EG\",\n \"KW\",\n \"OM\",\n \"QA\",\n \"JO\",\n ];\n\n private http: HttpClient;\n\n constructor(config: SMSAExpressConfig) {\n super(config);\n this.http = new HttpClient({\n baseUrl: this.getBaseUrl(),\n carrier: \"smsaexpress\",\n headers: {\n apikey: config.credentials.apiKey,\n },\n });\n }\n\n protected getBaseUrl(): string {\n return this.config.mode === \"production\"\n ? SMSA_PRODUCTION_URL\n : SMSA_SANDBOX_URL;\n }\n\n // =========================================================================\n // SHIPPING\n // =========================================================================\n\n /**\n * Ensure the input carries a `reference` so the OrderNumber the shipment is\n * booked under is the exact value surfaced back on `Shipment.reference` (which\n * the caller needs for {@link trackByReference}). When no reference is\n * supplied we generate one here via the shared {@link generateOrderNumber} and\n * pass this prepared input to BOTH the request mapper and the response mapper,\n * so the request OrderNumber and the response reference always agree (otherwise\n * each would call `Date.now()` independently and disagree).\n */\n private withOrderNumber(input: CreateShipmentInput): CreateShipmentInput {\n if (input.reference) {\n return input;\n }\n return { ...input, reference: generateOrderNumber() };\n }\n\n protected async executeCreateShipment(\n input: CreateShipmentInput,\n ): Promise<Shipment> {\n const prepared = this.withOrderNumber(input);\n const isC2B =\n prepared.serviceType !== undefined &&\n C2B_SERVICE_CODES.has(prepared.serviceType.trim().toUpperCase());\n\n if (isC2B) {\n return this.createC2BShipment(prepared);\n }\n\n const request = mapCreateB2CRequest(prepared);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/shipment/b2c/new\",\n request,\n );\n\n return mapShipmentResponse(response, prepared);\n }\n\n private async createC2BShipment(\n input: CreateShipmentInput,\n ): Promise<Shipment> {\n const request = mapCreateC2BRequest(input);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/c2b/new\",\n request,\n );\n\n return mapShipmentResponse(response, input);\n }\n\n /**\n * Cancel a reverse-pickup (C2B) shipment.\n *\n * **Important:** SMSA only supports cancellation for C2B/reverse-pickup\n * shipments, via the C2B endpoint. B2C shipments cannot be cancelled through\n * the SMSA API: the endpoint responds without a cancellation confirmation,\n * which is surfaced as an {@link APIError} (with `code: \"CANCELLATION_UNCONFIRMED\"`)\n * rather than a misleading `false`. That `code` lets callers distinguish this\n * \"carrier did not confirm\" case from a genuine request failure (network/4xx/5xx)\n * and fall back accordingly. Consistent with the other adapters, this method\n * either returns `true` or throws.\n *\n * Success is detected with a negation-aware check: a cancel token must be\n * present AND no negation token may be. A bare `includes(\"cancelled\")` would\n * wrongly succeed on negatives like \"Shipment cannot be cancelled\",\n * \"not cancelled\" or \"cancellation failed\". Note \"already cancelled\" carries\n * no negation token, so it correctly reports success (idempotent cancel).\n */\n async cancelShipment(trackingNumber: string): Promise<boolean> {\n const response = await this.http.post<string>(\n `/api/c2b/cancel/${encodeURIComponent(trackingNumber)}`,\n );\n // A non-string (JSON) success response is treated as success.\n if (typeof response !== \"string\") {\n return true;\n }\n // Success messages contain a cancel token (e.g. \"Shipment Cancelled\n // Successfully!\"), but so do negative ones (\"Shipment cannot be cancelled\",\n // \"cancellation failed\"). Treat as success only when a cancel token is\n // present AND no negation token is — so \"already cancelled\" (idempotent\n // success) still passes while \"not cancelled\" does not. Anything else means\n // the carrier did NOT cancel — most commonly because this is a B2C shipment,\n // which the SMSA API cannot cancel.\n const hasCancelToken = /cancel/i.test(response);\n const hasNegation =\n /\\b(?:not|can\\s?not|can'?t|cant|unable|fail(?:ed|ure)?|invalid|reject(?:ed)?|error)\\b/i.test(\n response,\n );\n if (hasCancelToken && !hasNegation) {\n return true;\n }\n // Distinguish \"carrier responded but did not confirm cancellation\" from a\n // genuine request failure (network/4xx/5xx, which throws separately via\n // HttpClient) so callers can tell \"unconfirmed\" apart from \"failed\" and\n // fall back accordingly (e.g. B2C shipments cannot be cancelled via the\n // SMSA API at all).\n throw new APIError(\n response.trim() || \"SMSA did not confirm cancellation\",\n {\n carrier: \"smsaexpress\",\n code: \"CANCELLATION_UNCONFIRMED\",\n raw: response,\n },\n );\n }\n\n // =========================================================================\n // TRACKING\n // =========================================================================\n\n async track(trackingNumber: string): Promise<TrackingResult> {\n const response = await this.http.get<SMSATrackingResponse>(\n `/api/track/single/${encodeURIComponent(trackingNumber)}`,\n );\n\n return mapTrackingResult(response);\n }\n\n async trackMultiple(trackingNumbers: string[]): Promise<TrackingResult[]> {\n const response = await this.http.post<SMSATrackingResponse[]>(\n \"/api/track/bulk/\",\n trackingNumbers,\n { retry: true },\n );\n\n return response.map(mapTrackingResult);\n }\n\n async trackByReference(reference: string): Promise<TrackingResult> {\n const response = await this.http.get<SMSATrackingResponse>(\n `/api/track/reference/${encodeURIComponent(reference)}`,\n );\n\n return mapTrackingResult(response);\n }\n\n // =========================================================================\n // LABELS\n // =========================================================================\n\n async getLabel(\n trackingNumber: string,\n _format?: \"PDF\" | \"ZPL\" | \"PNG\",\n ): Promise<string> {\n // SMSA returns the waybill file (base64 PDF) as part of the shipment query.\n // Try B2C first (most common), then C2B as fallback.\n const encoded = encodeURIComponent(trackingNumber);\n\n for (const path of [\n `/api/shipment/b2c/query/${encoded}`,\n `/api/c2b/query/${encoded}`,\n ]) {\n try {\n const response = await this.http.get<SMSAShipmentResponse>(path);\n const waybill = response.waybills?.[0];\n if (waybill?.awbFile) {\n return `data:application/pdf;base64,${waybill.awbFile}`;\n }\n } catch (error) {\n // Only swallow genuine 4xx (non-429) API errors (shipment type mismatch\n // / not found) so we can try the next path. Re-throw everything else:\n // - non-APIError → auth (AuthenticationError) and network (NetworkError)\n // are not APIErrors, so this clause re-throws them;\n // - RateLimitError → a 429 that must propagate, not masquerade as\n // \"No label found\" (it extends APIError, so guard it explicitly);\n // - 5xx server errors.\n if (\n !(error instanceof APIError) ||\n error instanceof RateLimitError ||\n (error.statusCode !== undefined && error.statusCode >= 500)\n ) {\n throw error;\n }\n }\n }\n\n throw new APIError(\"No label found for shipment\", {\n carrier: \"smsaexpress\",\n raw: { trackingNumber },\n });\n }\n\n // =========================================================================\n // CITIES & LOCATIONS\n // =========================================================================\n\n async getCities(countryCode = \"SA\"): Promise<City[]> {\n const response = await this.http.get<SMSACityLookupItem[]>(\n `/api/lookup/cities/${encodeURIComponent(countryCode)}`,\n );\n\n // Guard the shape before mapping: a non-array (e.g. an error object at\n // HTTP 200) would otherwise throw an opaque \"response.map is not a function\"\n // far from the cause.\n if (!Array.isArray(response)) {\n throw new APIError(\"SMSA cities lookup returned an unexpected shape\", {\n carrier: \"smsaexpress\",\n raw: response,\n });\n }\n\n return response.map(mapCity);\n }\n\n async getDropoffLocations(): Promise<Location[]> {\n const response = await this.http.get<SMSAOfficeLookupItem[]>(\n \"/api/lookup/smsaoffices\",\n );\n\n if (!Array.isArray(response)) {\n throw new APIError(\"SMSA offices lookup returned an unexpected shape\", {\n carrier: \"smsaexpress\",\n raw: response,\n });\n }\n\n return response.map(mapOffice);\n }\n\n // =========================================================================\n // 2-WAY SHIPMENT\n // =========================================================================\n\n async create2WayShipment(input: CreateShipmentInput): Promise<Shipment> {\n const prepared = this.withOrderNumber(input);\n const request = mapCreate2WayRequest(prepared);\n const response = await this.http.post<SMSAShipmentResponse>(\n \"/api/TwoWayShipment/new\",\n request,\n );\n\n return mapShipmentResponse(response, prepared);\n }\n\n // =========================================================================\n // INVOICE & ID OPERATIONS (SMSA-specific)\n // =========================================================================\n\n async sendInvoice(request: SMSASendInvoiceRequest): Promise<string> {\n return this.http.post<string>(\"/api/invoice\", request);\n }\n\n async validateShortAddress(\n shortCode: string,\n ): Promise<SMSAShortAddressResponse> {\n return this.http.get<SMSAShortAddressResponse>(\n `/api/Lookup/FullAddressByShortCode/${encodeURIComponent(shortCode)}`,\n );\n }\n\n async pushIdDetails(\n request: SMSAPushIdDetailsRequest,\n ): Promise<SMSAPushIdDetailsResponse> {\n return this.http.post<SMSAPushIdDetailsResponse>(\n \"/api/shipment/identity-details\",\n request,\n );\n }\n\n // =========================================================================\n // WEBHOOKS\n // =========================================================================\n\n parseWebhook(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n ): WebhookEvent {\n return parseSMSAWebhook(payload, options);\n }\n\n /**\n * Parse a batch SMSA webhook payload into multiple events.\n *\n * SMSA sends webhook payloads as an array of shipments, each with their own\n * tracking scans. This method returns a WebhookEvent for every shipment\n * in the payload.\n */\n parseWebhookBatch(\n payload: unknown,\n options?: {\n headers?: Record<string, string>;\n queryParams?: Record<string, string>;\n config?: WebhookConfig;\n },\n ): WebhookEvent[] {\n return parseSMSAWebhookBatch(payload, options);\n }\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";;;;;;;;;AAMO,IAAM,cAAc;AAAA,EAEzB,oBAAoB;AAAA,EAEpB,kBAAkB;AAAA,EAElB,aAAa;AACf;AAUO,IAAM,kBAA0C;AAAA,EAErD,IAAI;AAAA,EAGJ,IAAI;AAAA,EAGJ,IAAI;AAAA,EAGJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EAGL,IAAI;AAAA,EACJ,KAAK;AAAA,EAGL,IAAI;AAAA,EACJ,IAAI;AAAA,EAGJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EAGN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EAGL,IAAI;AAAA,EACJ,IAAI;AAAA,EAGJ,IAAI;AAAA,EACJ,KAAK;AACP;;;ACvBO,SAAS,aAAa,CAAC,UAAkC;AAAA,EAC9D,OAAQ,gBAAgB,aAAgC;AAAA;AAO1D,SAAS,qBAAqB,CAC5B,OACA,aACiD;AAAA,EACjD,IAAI,aAAa;AAAA,IACf,OAAO,EAAE,QAAQ,aAAa,aAAa,YAAY;AAAA,EACzD;AAAA,EAEA,MAAM,YAAY,SAAS,CAAC;AAAA,EAC5B,IAAI,UAAU,WAAW,GAAG;AAAA,IAC1B,OAAO,EAAE,QAAQ,WAAW,aAAa,UAAU;AAAA,EACrD;AAAA,EACA,MAAM,SAAS,CAAC,GAAG,SAAS,EAAE,KAC5B,CAAC,GAAG,MACF,IAAI,KAAK,EAAE,YAAY,EAAE,QAAQ,IACjC,IAAI,KAAK,EAAE,YAAY,EAAE,QAAQ,CACrC;AAAA,EACA,MAAM,SAAS,OAAO;AAAA,EACtB,OAAO;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B,SAAS,OAAO;AAAA;AAAA,EAU1C,iBAAiB,CACf,SACA,SAKgB;AAAA,IAChB,OAAO,sBAAsB,SAAS,OAAO;AAAA;AAEjD;",
|
|
10
|
+
"debugId": "AF4035876BEB4A1F64756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
import type { City, CreateShipmentInput, Location, Shipment, ShipmentStatus, TrackingEvent, TrackingResult, WebhookConfig, WebhookEvent } from "../../core/types.js";
|
|
6
6
|
import type { SMSACityLookupItem, SMSACreate2WayShipmentRequest, SMSACreateB2CShipmentRequest, SMSACreateC2BShipmentRequest, SMSAOfficeLookupItem, SMSAShipmentResponse, SMSATrackingResponse, SMSATrackingScan } from "./types.js";
|
|
7
7
|
export declare function mapSMSAStatus(scanType: string): ShipmentStatus;
|
|
8
|
+
/**
|
|
9
|
+
* Generate a fallback OrderNumber when the caller supplies no reference. Single
|
|
10
|
+
* source of the `ORD-<epoch-ms>` format — the adapter uses it to fix a reference
|
|
11
|
+
* on the input so the booked OrderNumber is surfaced back on the Shipment, and
|
|
12
|
+
* the request mappers reference it as their type-required default.
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateOrderNumber(): string;
|
|
8
15
|
export declare function mapCreateB2CRequest(input: CreateShipmentInput): SMSACreateB2CShipmentRequest;
|
|
9
16
|
/**
|
|
10
17
|
* Map to C2B (reverse pickup) request.
|
|
@@ -32,10 +39,12 @@ export declare function parseSMSAWebhook(payload: unknown, options?: {
|
|
|
32
39
|
}): WebhookEvent;
|
|
33
40
|
/**
|
|
34
41
|
* Parse an SMSA webhook payload and return a WebhookEvent for every
|
|
35
|
-
* shipment in the batch.
|
|
42
|
+
* scan of every shipment in the batch (in chronological order per shipment).
|
|
36
43
|
*
|
|
37
|
-
* SMSA sends webhook payloads as an array of shipments, each with
|
|
38
|
-
*
|
|
44
|
+
* SMSA sends webhook payloads as an array of shipments, each with their own
|
|
45
|
+
* tracking scans, and a single call can carry multiple new scans for the
|
|
46
|
+
* same shipment (e.g. AF, OD, DL together) — each becomes its own event so
|
|
47
|
+
* no intermediate transition/history is dropped.
|
|
39
48
|
*/
|
|
40
49
|
export declare function parseSMSAWebhookBatch(payload: unknown, options?: {
|
|
41
50
|
headers?: Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/mappers.ts"],"names":[],"mappings":"AACA;;;GAGG;AAOH,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,kBAAkB,EAClB,6BAA6B,EAC7B,4BAA4B,EAC5B,4BAA4B,EAC5B,oBAAoB,EAEpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAMjB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAE9D;
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/mappers.ts"],"names":[],"mappings":"AACA;;;GAGG;AAOH,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,kBAAkB,EAClB,6BAA6B,EAC7B,4BAA4B,EAC5B,4BAA4B,EAC5B,oBAAoB,EAEpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAMjB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAE9D;AA8DD;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;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|
15
15
|
* SMSA Express Scan Type Codes → Unified ShipmentStatus mapping.
|
|
16
16
|
*
|
|
17
17
|
* Based on /api/track/statuslookup response.
|
|
18
|
-
* Scan types not explicitly listed default to "
|
|
18
|
+
* Scan types not explicitly listed default to "unknown" (see mapSMSAStatus)
|
|
19
|
+
* so operators can detect unmapped codes instead of silently treating them
|
|
20
|
+
* as in-transit.
|
|
19
21
|
*/
|
|
20
22
|
export declare const SMSAStatusCodes: Record<string, string>;
|
|
21
23
|
//# sourceMappingURL=services.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/services.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,eAAO,MAAM,WAAW;IACtB,0BAA0B;;IAE1B,uBAAuB;;IAEvB,2BAA2B;;CAEnB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE7E
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/carriers/smsaexpress/services.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,eAAO,MAAM,WAAW;IACtB,0BAA0B;;IAE1B,uBAAuB;;IAEvB,2BAA2B;;CAEnB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwClD,CAAC"}
|
package/dist/core/http.d.ts
CHANGED
|
@@ -79,6 +79,14 @@ export declare class HttpClient {
|
|
|
79
79
|
private isRetryable;
|
|
80
80
|
private executeRequest;
|
|
81
81
|
private handleHttpError;
|
|
82
|
+
/** Cap on sanitized non-JSON error bodies (e.g. HTML gateway/proxy pages). */
|
|
83
|
+
private static readonly MAX_ERROR_TEXT_LENGTH;
|
|
84
|
+
/**
|
|
85
|
+
* Strip markup and cap the length of a raw (non-JSON) error body so a
|
|
86
|
+
* carrier's HTML gateway/proxy error page doesn't get dumped verbatim into
|
|
87
|
+
* the thrown error's message.
|
|
88
|
+
*/
|
|
89
|
+
private sanitizeErrorText;
|
|
82
90
|
private extractErrorMessage;
|
|
83
91
|
private extractValidationErrors;
|
|
84
92
|
/** Create GET request */
|
package/dist/core/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;GAYG;AAWH,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAA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