|
| 1 | +import deftship from "../../deftship.app.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "deftship-create-freight-order", |
| 6 | + name: "Create Freight Order", |
| 7 | + description: "Initializes a new parcel order within Deftship. [See the documentation](https://developer.deftship.com/freight/create-order)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + deftship, |
| 12 | + pickupDate: { |
| 13 | + type: "string", |
| 14 | + label: "Pickup Date", |
| 15 | + description: "Proposed pickup date, in `Y-m-d`", |
| 16 | + }, |
| 17 | + fromOpeningTime: { |
| 18 | + type: "string", |
| 19 | + label: "From Opening Time", |
| 20 | + description: "Opening time of pickup address, in `H:i`", |
| 21 | + }, |
| 22 | + fromClosingTime: { |
| 23 | + type: "string", |
| 24 | + label: "From Closing Time", |
| 25 | + description: "Closing time of pickup address, in `H:i`", |
| 26 | + }, |
| 27 | + fromName: { |
| 28 | + propDefinition: [ |
| 29 | + deftship, |
| 30 | + "fromName", |
| 31 | + ], |
| 32 | + }, |
| 33 | + fromStreet: { |
| 34 | + propDefinition: [ |
| 35 | + deftship, |
| 36 | + "fromStreet", |
| 37 | + ], |
| 38 | + }, |
| 39 | + fromCity: { |
| 40 | + propDefinition: [ |
| 41 | + deftship, |
| 42 | + "fromCity", |
| 43 | + ], |
| 44 | + }, |
| 45 | + fromState: { |
| 46 | + propDefinition: [ |
| 47 | + deftship, |
| 48 | + "fromState", |
| 49 | + ], |
| 50 | + }, |
| 51 | + fromZip: { |
| 52 | + propDefinition: [ |
| 53 | + deftship, |
| 54 | + "fromZip", |
| 55 | + ], |
| 56 | + }, |
| 57 | + fromCountry: { |
| 58 | + propDefinition: [ |
| 59 | + deftship, |
| 60 | + "fromCountry", |
| 61 | + ], |
| 62 | + }, |
| 63 | + fromTelephone: { |
| 64 | + propDefinition: [ |
| 65 | + deftship, |
| 66 | + "fromTelephone", |
| 67 | + ], |
| 68 | + description: "The telephone number of the sender. (must be a number 10-15 digits)", |
| 69 | + }, |
| 70 | + toOpeningTime: { |
| 71 | + type: "string", |
| 72 | + label: "To Opening Time", |
| 73 | + description: "Opening time of delivery address, in `H:i`", |
| 74 | + }, |
| 75 | + toClosingTime: { |
| 76 | + type: "string", |
| 77 | + label: "To Closing Time", |
| 78 | + description: "Closing time of delivery address, in `H:i`", |
| 79 | + }, |
| 80 | + toName: { |
| 81 | + propDefinition: [ |
| 82 | + deftship, |
| 83 | + "toName", |
| 84 | + ], |
| 85 | + }, |
| 86 | + toStreet: { |
| 87 | + propDefinition: [ |
| 88 | + deftship, |
| 89 | + "toStreet", |
| 90 | + ], |
| 91 | + }, |
| 92 | + toCity: { |
| 93 | + propDefinition: [ |
| 94 | + deftship, |
| 95 | + "toCity", |
| 96 | + ], |
| 97 | + }, |
| 98 | + toState: { |
| 99 | + propDefinition: [ |
| 100 | + deftship, |
| 101 | + "toState", |
| 102 | + ], |
| 103 | + }, |
| 104 | + toZip: { |
| 105 | + propDefinition: [ |
| 106 | + deftship, |
| 107 | + "toZip", |
| 108 | + ], |
| 109 | + }, |
| 110 | + toCountry: { |
| 111 | + propDefinition: [ |
| 112 | + deftship, |
| 113 | + "toCountry", |
| 114 | + ], |
| 115 | + }, |
| 116 | + toTelephone: { |
| 117 | + propDefinition: [ |
| 118 | + deftship, |
| 119 | + "fromTelephone", |
| 120 | + ], |
| 121 | + description: "The telephone number of the sender. (must be a number 10-15 digits)", |
| 122 | + }, |
| 123 | + packageType: { |
| 124 | + type: "string", |
| 125 | + label: "Package Type", |
| 126 | + description: "The type of package", |
| 127 | + options: constants.PACKAGE_TYPES, |
| 128 | + }, |
| 129 | + itemCount: { |
| 130 | + propDefinition: [ |
| 131 | + deftship, |
| 132 | + "itemCount", |
| 133 | + ], |
| 134 | + }, |
| 135 | + length: { |
| 136 | + type: "string", |
| 137 | + label: "Length", |
| 138 | + description: "Length (IN)", |
| 139 | + }, |
| 140 | + width: { |
| 141 | + type: "string", |
| 142 | + label: "Width", |
| 143 | + description: "Width (IN)", |
| 144 | + }, |
| 145 | + height: { |
| 146 | + type: "string", |
| 147 | + label: "Height", |
| 148 | + description: "Height (IN)", |
| 149 | + }, |
| 150 | + weight: { |
| 151 | + type: "string", |
| 152 | + label: "Weight", |
| 153 | + description: "Weight (LBS)", |
| 154 | + }, |
| 155 | + description: { |
| 156 | + type: "string", |
| 157 | + label: "Description", |
| 158 | + description: "Description of the item", |
| 159 | + }, |
| 160 | + price: { |
| 161 | + type: "string", |
| 162 | + label: "Price", |
| 163 | + description: "Price (Commodity Value) of the item", |
| 164 | + optional: true, |
| 165 | + }, |
| 166 | + sku: { |
| 167 | + type: "string", |
| 168 | + label: "Sku", |
| 169 | + description: "PO number of the shipment", |
| 170 | + optional: true, |
| 171 | + }, |
| 172 | + additionalFields: { |
| 173 | + propDefinition: [ |
| 174 | + deftship, |
| 175 | + "additionalFields", |
| 176 | + ], |
| 177 | + }, |
| 178 | + }, |
| 179 | + async run({ $ }) { |
| 180 | + const additionalFields = !this.additionalFields |
| 181 | + ? {} |
| 182 | + : typeof this.additionalFields === "string" |
| 183 | + ? JSON.parse(this.additionalFields) |
| 184 | + : this.additionalFields; |
| 185 | + const response = await this.deftship.createFreightOrder({ |
| 186 | + $, |
| 187 | + data: { |
| 188 | + pickup_date: this.pickupDate, |
| 189 | + from_opening_time: this.fromOpeningTime, |
| 190 | + from_closing_time: this.fromClosingTime, |
| 191 | + from_address: { |
| 192 | + name: this.fromName, |
| 193 | + street_1: this.fromStreet, |
| 194 | + city: this.fromCity, |
| 195 | + state: this.fromState, |
| 196 | + zip: this.fromZip, |
| 197 | + country: this.fromCountry, |
| 198 | + telephone: +this.fromTelephone, |
| 199 | + }, |
| 200 | + to_opening_time: this.toOpeningTime, |
| 201 | + to_closing_time: this.toClosingTime, |
| 202 | + to_address: { |
| 203 | + name: this.toName, |
| 204 | + street_1: this.toStreet, |
| 205 | + city: this.toCity, |
| 206 | + state: this.toState, |
| 207 | + zip: this.toZip, |
| 208 | + country: this.toCountry, |
| 209 | + telephone: +this.toTelephone, |
| 210 | + }, |
| 211 | + items: [ |
| 212 | + { |
| 213 | + package_type: this.packageType, |
| 214 | + count: this.itemCount, |
| 215 | + length: +this.length, |
| 216 | + width: +this.width, |
| 217 | + height: +this.height, |
| 218 | + weight: +this.weight, |
| 219 | + description: this.description, |
| 220 | + price: this.price && +this.price, |
| 221 | + sku: this.sku, |
| 222 | + }, |
| 223 | + ], |
| 224 | + ...additionalFields, |
| 225 | + }, |
| 226 | + }); |
| 227 | + $.export("$summary", `New freight order with ID: ${response.data.shipment_order_id}`); |
| 228 | + return response; |
| 229 | + }, |
| 230 | +}; |
0 commit comments