|
| 1 | +import ups from "../../ups.app.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "ups-create-shipment", |
| 6 | + name: "Create Shipment", |
| 7 | + description: "Create a new shipment. [See the documentation](https://developer.ups.com/tag/Shipping?loc=en_US#operation/Shipment)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + annotations: { |
| 11 | + destructiveHint: false, |
| 12 | + openWorldHint: true, |
| 13 | + readOnlyHint: false, |
| 14 | + }, |
| 15 | + props: { |
| 16 | + ups, |
| 17 | + shipperName: { |
| 18 | + type: "string", |
| 19 | + label: "Shipper Name", |
| 20 | + description: "The name of the shipper", |
| 21 | + }, |
| 22 | + shipperNumber: { |
| 23 | + type: "string", |
| 24 | + label: "Shipper Number", |
| 25 | + description: "Shipper's six digit alphanumeric account number", |
| 26 | + }, |
| 27 | + shipperAddressLine: { |
| 28 | + type: "string", |
| 29 | + label: "Shipper Address Line", |
| 30 | + description: "The address line of the shipper", |
| 31 | + }, |
| 32 | + shipperCity: { |
| 33 | + type: "string", |
| 34 | + label: "Shipper City", |
| 35 | + description: "The city of the shipper", |
| 36 | + }, |
| 37 | + shipperStateProvinceCode: { |
| 38 | + type: "string", |
| 39 | + label: "Shipper State Province Code", |
| 40 | + description: "The state province code of the shipper", |
| 41 | + }, |
| 42 | + shipperPostalCode: { |
| 43 | + type: "string", |
| 44 | + label: "Shipper Postal Code", |
| 45 | + description: "The postal code of the shipper", |
| 46 | + }, |
| 47 | + shipperCountryCode: { |
| 48 | + type: "string", |
| 49 | + label: "Shipper Country Code", |
| 50 | + description: "The country code of the shipper", |
| 51 | + }, |
| 52 | + shipToName: { |
| 53 | + type: "string", |
| 54 | + label: "Ship To Name", |
| 55 | + description: "The name of the ship to", |
| 56 | + }, |
| 57 | + shipToAddressLine: { |
| 58 | + type: "string", |
| 59 | + label: "Ship To Address Line", |
| 60 | + description: "The address line of the ship to", |
| 61 | + }, |
| 62 | + shipToCity: { |
| 63 | + type: "string", |
| 64 | + label: "Ship To City", |
| 65 | + description: "The city of the ship to", |
| 66 | + }, |
| 67 | + shipToStateProvinceCode: { |
| 68 | + type: "string", |
| 69 | + label: "Ship To State Province Code", |
| 70 | + description: "The state province code of the ship to", |
| 71 | + }, |
| 72 | + shipToPostalCode: { |
| 73 | + type: "string", |
| 74 | + label: "Ship To Postal Code", |
| 75 | + description: "The postal code of the ship to", |
| 76 | + }, |
| 77 | + shipToCountryCode: { |
| 78 | + type: "string", |
| 79 | + label: "Ship To Country Code", |
| 80 | + description: "The country code of the ship to", |
| 81 | + }, |
| 82 | + serviceCode: { |
| 83 | + type: "string", |
| 84 | + label: "Service Code", |
| 85 | + description: "The code of the service", |
| 86 | + options: constants.SERVICE_CODES, |
| 87 | + }, |
| 88 | + packagingCode: { |
| 89 | + type: "string", |
| 90 | + label: "Packaging Code", |
| 91 | + description: "The code of the packaging", |
| 92 | + options: constants.PACKAGING_CODES, |
| 93 | + }, |
| 94 | + weightUnit: { |
| 95 | + type: "string", |
| 96 | + label: "Weight Unit", |
| 97 | + description: "The unit of weight for the package", |
| 98 | + options: [ |
| 99 | + "LBS", |
| 100 | + "KGS", |
| 101 | + "OZS", |
| 102 | + ], |
| 103 | + }, |
| 104 | + packageWeight: { |
| 105 | + type: "string", |
| 106 | + label: "Package Weight", |
| 107 | + description: "The weight of the package", |
| 108 | + }, |
| 109 | + }, |
| 110 | + async run({ $ }) { |
| 111 | + const response = await this.ups.createShipment({ |
| 112 | + $, |
| 113 | + data: { |
| 114 | + ShipmentRequest: { |
| 115 | + Request: { |
| 116 | + RequestOption: "nonvalidate", |
| 117 | + }, |
| 118 | + Shipment: { |
| 119 | + Shipper: { |
| 120 | + Name: this.shipperName, |
| 121 | + ShipperNumber: this.shipperNumber, |
| 122 | + Address: { |
| 123 | + AddressLine: this.shipperAddressLine, |
| 124 | + City: this.shipperCity, |
| 125 | + StateProvinceCode: this.shipperStateProvinceCode, |
| 126 | + PostalCode: this.shipperPostalCode, |
| 127 | + CountryCode: this.shipperCountryCode, |
| 128 | + }, |
| 129 | + }, |
| 130 | + ShipTo: { |
| 131 | + Name: this.shipToName, |
| 132 | + Address: { |
| 133 | + AddressLine: this.shipToAddressLine, |
| 134 | + City: this.shipToCity, |
| 135 | + StateProvinceCode: this.shipToStateProvinceCode, |
| 136 | + PostalCode: this.shipToPostalCode, |
| 137 | + CountryCode: this.shipToCountryCode, |
| 138 | + }, |
| 139 | + }, |
| 140 | + PaymentInformation: { |
| 141 | + ShipmentCharge: [ |
| 142 | + { |
| 143 | + Type: "01", // Transportation Charge |
| 144 | + BillShipper: { |
| 145 | + AccountNumber: this.shipperNumber, |
| 146 | + }, |
| 147 | + }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + Service: { |
| 151 | + Code: this.serviceCode, |
| 152 | + }, |
| 153 | + Package: [ |
| 154 | + { |
| 155 | + Packaging: { |
| 156 | + Code: this.packagingCode, |
| 157 | + }, |
| 158 | + PackageWeight: { |
| 159 | + UnitOfMeasurement: { |
| 160 | + Code: this.weightUnit, |
| 161 | + }, |
| 162 | + Weight: this.packageWeight, |
| 163 | + }, |
| 164 | + }, |
| 165 | + ], |
| 166 | + }, |
| 167 | + }, |
| 168 | + }, |
| 169 | + }); |
| 170 | + $.export("$summary", "Shipment created successfully"); |
| 171 | + return response; |
| 172 | + }, |
| 173 | +}; |
0 commit comments