@shipengine/elements 0.6.21 → 0.6.23
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/hooks/use-address-preference.d.ts +1 -1
- package/index.cjs +69 -29
- package/index.js +69 -29
- package/package.json +8 -6
|
@@ -20,7 +20,7 @@ export declare const useAddressPreference: () => {
|
|
|
20
20
|
}[];
|
|
21
21
|
alternativeSource: "originalAddress" | "matchedAddress";
|
|
22
22
|
isModified: boolean;
|
|
23
|
-
toggle: () => SE.Address;
|
|
24
23
|
selectionSource: "originalAddress" | "matchedAddress";
|
|
24
|
+
toggle: () => SE.Address;
|
|
25
25
|
};
|
|
26
26
|
};
|
package/index.cjs
CHANGED
|
@@ -20138,11 +20138,12 @@ const useAddressPreference = () => {
|
|
|
20138
20138
|
}) => {
|
|
20139
20139
|
const {
|
|
20140
20140
|
matchedAddress,
|
|
20141
|
-
originalAddress
|
|
20141
|
+
originalAddress,
|
|
20142
|
+
status
|
|
20142
20143
|
} = validation; // If the address is domestic, we always default to the matchedAddress if it exists.
|
|
20143
20144
|
// If the address is international, we always default to the original due to issues with SE-API's validation
|
|
20144
20145
|
|
|
20145
|
-
const selectionSource = elementsCore.isDomesticAddress(originalAddress) ? matchedAddress ? "matchedAddress" : "originalAddress" : "originalAddress";
|
|
20146
|
+
const selectionSource = elementsCore.isDomesticAddress(originalAddress) && status !== "error" ? matchedAddress ? "matchedAddress" : "originalAddress" : "originalAddress";
|
|
20146
20147
|
const alternativeSource = selectionSource === "matchedAddress" ? "originalAddress" : "matchedAddress";
|
|
20147
20148
|
const newAddressPreference = Object.assign(Object.assign(Object.assign({}, validation), _.isEqual(originalAddress, matchedAddress) ? {
|
|
20148
20149
|
// An exact match in SE-API will *sometimes* return a matchedAddress exactly mirroring the originalAddress,
|
|
@@ -20263,34 +20264,73 @@ const SalesOrder = ({
|
|
|
20263
20264
|
const pendingShipment = shipments.data.find(s => s.shipmentStatus === "pending");
|
|
20264
20265
|
|
|
20265
20266
|
if (currentSalesOrder && !pendingShipment) {
|
|
20266
|
-
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0];
|
|
20267
|
-
|
|
20268
|
-
|
|
20269
|
-
//
|
|
20270
|
-
|
|
20271
|
-
|
|
20272
|
-
weight
|
|
20273
|
-
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
|
|
20289
|
-
|
|
20290
|
-
|
|
20291
|
-
|
|
20267
|
+
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0];
|
|
20268
|
+
|
|
20269
|
+
try {
|
|
20270
|
+
// We don't have a shipment yet; create one.
|
|
20271
|
+
const result = yield createShipment.trigger(Object.assign({
|
|
20272
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20273
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20274
|
+
packages: [{
|
|
20275
|
+
weight: {
|
|
20276
|
+
value: 0,
|
|
20277
|
+
unit: "pound"
|
|
20278
|
+
}
|
|
20279
|
+
}],
|
|
20280
|
+
validateAddress: "validate_and_clean",
|
|
20281
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20282
|
+
}, elementsCore.getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20283
|
+
customs: elementsCore.getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20284
|
+
}));
|
|
20285
|
+
|
|
20286
|
+
if (!result) {
|
|
20287
|
+
logger.error("createShipment returned an undefined result");
|
|
20288
|
+
} else if (!result.addressValidation) {
|
|
20289
|
+
logger.error("createShipment returned an undefined addressValidation");
|
|
20290
|
+
} else {
|
|
20291
|
+
yield shipments.mutate();
|
|
20292
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20293
|
+
validation: result.addressValidation,
|
|
20294
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20295
|
+
});
|
|
20296
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20297
|
+
}
|
|
20298
|
+
} catch (error) {
|
|
20299
|
+
// Shipment creation failed most likely due to validate_and_clean failing create and update
|
|
20300
|
+
// validate and create the shipment the old fashioned way.
|
|
20301
|
+
logger.warn("createShipment failed to create a shipment, trying plan b", error.message);
|
|
20302
|
+
const result = yield validateAddresses.trigger({
|
|
20303
|
+
addresses: [currentSalesOrder.shipTo]
|
|
20292
20304
|
});
|
|
20293
|
-
|
|
20305
|
+
const addressValidation = result === null || result === void 0 ? void 0 : result[0];
|
|
20306
|
+
|
|
20307
|
+
if (addressValidation) {
|
|
20308
|
+
try {
|
|
20309
|
+
yield createShipment.trigger(Object.assign({
|
|
20310
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20311
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20312
|
+
packages: [{
|
|
20313
|
+
weight: {
|
|
20314
|
+
value: 0,
|
|
20315
|
+
unit: "pound"
|
|
20316
|
+
}
|
|
20317
|
+
}],
|
|
20318
|
+
shipTo: addressValidation.originalAddress,
|
|
20319
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20320
|
+
}, elementsCore.getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20321
|
+
customs: elementsCore.getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20322
|
+
}));
|
|
20323
|
+
yield shipments.mutate();
|
|
20324
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20325
|
+
validation: addressValidation,
|
|
20326
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20327
|
+
});
|
|
20328
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20329
|
+
} catch (error) {
|
|
20330
|
+
logger.error("createShipment failed to create a shipment", error.message);
|
|
20331
|
+
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20332
|
+
}
|
|
20333
|
+
}
|
|
20294
20334
|
}
|
|
20295
20335
|
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20296
20336
|
// We have a preexisting shipment; validate the address
|
package/index.js
CHANGED
|
@@ -20134,11 +20134,12 @@ const useAddressPreference = () => {
|
|
|
20134
20134
|
}) => {
|
|
20135
20135
|
const {
|
|
20136
20136
|
matchedAddress,
|
|
20137
|
-
originalAddress
|
|
20137
|
+
originalAddress,
|
|
20138
|
+
status
|
|
20138
20139
|
} = validation; // If the address is domestic, we always default to the matchedAddress if it exists.
|
|
20139
20140
|
// If the address is international, we always default to the original due to issues with SE-API's validation
|
|
20140
20141
|
|
|
20141
|
-
const selectionSource = isDomesticAddress(originalAddress) ? matchedAddress ? "matchedAddress" : "originalAddress" : "originalAddress";
|
|
20142
|
+
const selectionSource = isDomesticAddress(originalAddress) && status !== "error" ? matchedAddress ? "matchedAddress" : "originalAddress" : "originalAddress";
|
|
20142
20143
|
const alternativeSource = selectionSource === "matchedAddress" ? "originalAddress" : "matchedAddress";
|
|
20143
20144
|
const newAddressPreference = Object.assign(Object.assign(Object.assign({}, validation), _.isEqual(originalAddress, matchedAddress) ? {
|
|
20144
20145
|
// An exact match in SE-API will *sometimes* return a matchedAddress exactly mirroring the originalAddress,
|
|
@@ -20259,34 +20260,73 @@ const SalesOrder = ({
|
|
|
20259
20260
|
const pendingShipment = shipments.data.find(s => s.shipmentStatus === "pending");
|
|
20260
20261
|
|
|
20261
20262
|
if (currentSalesOrder && !pendingShipment) {
|
|
20262
|
-
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0];
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
//
|
|
20266
|
-
|
|
20267
|
-
|
|
20268
|
-
weight
|
|
20269
|
-
|
|
20270
|
-
|
|
20271
|
-
|
|
20272
|
-
|
|
20273
|
-
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20263
|
+
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0];
|
|
20264
|
+
|
|
20265
|
+
try {
|
|
20266
|
+
// We don't have a shipment yet; create one.
|
|
20267
|
+
const result = yield createShipment.trigger(Object.assign({
|
|
20268
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20269
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20270
|
+
packages: [{
|
|
20271
|
+
weight: {
|
|
20272
|
+
value: 0,
|
|
20273
|
+
unit: "pound"
|
|
20274
|
+
}
|
|
20275
|
+
}],
|
|
20276
|
+
validateAddress: "validate_and_clean",
|
|
20277
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20278
|
+
}, getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20279
|
+
customs: getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20280
|
+
}));
|
|
20281
|
+
|
|
20282
|
+
if (!result) {
|
|
20283
|
+
logger.error("createShipment returned an undefined result");
|
|
20284
|
+
} else if (!result.addressValidation) {
|
|
20285
|
+
logger.error("createShipment returned an undefined addressValidation");
|
|
20286
|
+
} else {
|
|
20287
|
+
yield shipments.mutate();
|
|
20288
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20289
|
+
validation: result.addressValidation,
|
|
20290
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20291
|
+
});
|
|
20292
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20293
|
+
}
|
|
20294
|
+
} catch (error) {
|
|
20295
|
+
// Shipment creation failed most likely due to validate_and_clean failing create and update
|
|
20296
|
+
// validate and create the shipment the old fashioned way.
|
|
20297
|
+
logger.warn("createShipment failed to create a shipment, trying plan b", error.message);
|
|
20298
|
+
const result = yield validateAddresses.trigger({
|
|
20299
|
+
addresses: [currentSalesOrder.shipTo]
|
|
20288
20300
|
});
|
|
20289
|
-
|
|
20301
|
+
const addressValidation = result === null || result === void 0 ? void 0 : result[0];
|
|
20302
|
+
|
|
20303
|
+
if (addressValidation) {
|
|
20304
|
+
try {
|
|
20305
|
+
yield createShipment.trigger(Object.assign({
|
|
20306
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20307
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20308
|
+
packages: [{
|
|
20309
|
+
weight: {
|
|
20310
|
+
value: 0,
|
|
20311
|
+
unit: "pound"
|
|
20312
|
+
}
|
|
20313
|
+
}],
|
|
20314
|
+
shipTo: addressValidation.originalAddress,
|
|
20315
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20316
|
+
}, getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20317
|
+
customs: getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20318
|
+
}));
|
|
20319
|
+
yield shipments.mutate();
|
|
20320
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20321
|
+
validation: addressValidation,
|
|
20322
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20323
|
+
});
|
|
20324
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20325
|
+
} catch (error) {
|
|
20326
|
+
logger.error("createShipment failed to create a shipment", error.message);
|
|
20327
|
+
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20328
|
+
}
|
|
20329
|
+
}
|
|
20290
20330
|
}
|
|
20291
20331
|
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20292
20332
|
// We have a preexisting shipment; validate the address
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipengine/elements",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.23",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@packlink/giger": "*"
|
|
6
|
+
},
|
|
4
7
|
"module": "./index.js",
|
|
5
8
|
"main": "./index.cjs",
|
|
6
9
|
"type": "module",
|
|
7
10
|
"types": "./index.d.ts",
|
|
8
11
|
"dependencies": {
|
|
9
12
|
"react": "^18.2.0",
|
|
10
|
-
"@shipengine/elements-core": "0.6.
|
|
13
|
+
"@shipengine/elements-core": "0.6.23",
|
|
11
14
|
"react-i18next": "^11.18.4",
|
|
12
15
|
"i18next": "^21.9.1",
|
|
13
16
|
"i18next-http-backend": "^1.4.1",
|
|
14
17
|
"i18next-browser-languagedetector": "^6.1.4",
|
|
15
|
-
"@shipengine/types": "0.6.
|
|
16
|
-
"@shipengine/elements-ui": "0.6.
|
|
17
|
-
}
|
|
18
|
-
"peerDependencies": {}
|
|
18
|
+
"@shipengine/types": "0.6.23",
|
|
19
|
+
"@shipengine/elements-ui": "0.6.23"
|
|
20
|
+
}
|
|
19
21
|
}
|