diff --git a/components/clarifai/clarifai.app.mjs b/components/clarifai/clarifai.app.mjs index 92080776dfcaa..3d5a708bc7c59 100644 --- a/components/clarifai/clarifai.app.mjs +++ b/components/clarifai/clarifai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/cloud_66/cloud_66.app.mjs b/components/cloud_66/cloud_66.app.mjs index d40c866ac3701..cee71d0816d43 100644 --- a/components/cloud_66/cloud_66.app.mjs +++ b/components/cloud_66/cloud_66.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/codefresh/codefresh.app.mjs b/components/codefresh/codefresh.app.mjs index b1ab6322ebfaa..05f22fed15dc6 100644 --- a/components/codefresh/codefresh.app.mjs +++ b/components/codefresh/codefresh.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/coinapi/coinapi.app.mjs b/components/coinapi/coinapi.app.mjs index c345cd0bfd483..6d8f2c096763d 100644 --- a/components/coinapi/coinapi.app.mjs +++ b/components/coinapi/coinapi.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/cometapi/cometapi.app.mjs b/components/cometapi/cometapi.app.mjs index b4887a2014192..d8b1964610914 100644 --- a/components/cometapi/cometapi.app.mjs +++ b/components/cometapi/cometapi.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/copicake/copicake.app.mjs b/components/copicake/copicake.app.mjs index 2f1f2032a15c1..1203c4b1044e1 100644 --- a/components/copicake/copicake.app.mjs +++ b/components/copicake/copicake.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/cronly/cronly.app.mjs b/components/cronly/cronly.app.mjs index 6100b3def7bf1..32cb4f5e4c462 100644 --- a/components/cronly/cronly.app.mjs +++ b/components/cronly/cronly.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/crossmint/crossmint.app.mjs b/components/crossmint/crossmint.app.mjs index b5739f02f4ab4..6ebc3cd601546 100644 --- a/components/crossmint/crossmint.app.mjs +++ b/components/crossmint/crossmint.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/hex/hex.app.mjs b/components/hex/hex.app.mjs index 0468c4d8025a2..ca851c737d608 100644 --- a/components/hex/hex.app.mjs +++ b/components/hex/hex.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/piwik_pro/piwik_pro.app.mjs b/components/piwik_pro/piwik_pro.app.mjs index 2c6c4a51e0f5b..ea2bebcefcc4b 100644 --- a/components/piwik_pro/piwik_pro.app.mjs +++ b/components/piwik_pro/piwik_pro.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/topdesk/topdesk.app.mjs b/components/topdesk/topdesk.app.mjs index c2c4cc0f91c59..c0c7553307b0c 100644 --- a/components/topdesk/topdesk.app.mjs +++ b/components/topdesk/topdesk.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/ups/actions/create-shipment/create-shipment.mjs b/components/ups/actions/create-shipment/create-shipment.mjs new file mode 100644 index 0000000000000..3b5c977191a76 --- /dev/null +++ b/components/ups/actions/create-shipment/create-shipment.mjs @@ -0,0 +1,173 @@ +import ups from "../../ups.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "ups-create-shipment", + name: "Create Shipment", + description: "Create a new shipment. [See the documentation](https://developer.ups.com/tag/Shipping?loc=en_US#operation/Shipment)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + ups, + shipperName: { + type: "string", + label: "Shipper Name", + description: "The name of the shipper", + }, + shipperNumber: { + type: "string", + label: "Shipper Number", + description: "Shipper's six digit alphanumeric account number", + }, + shipperAddressLine: { + type: "string", + label: "Shipper Address Line", + description: "The address line of the shipper", + }, + shipperCity: { + type: "string", + label: "Shipper City", + description: "The city of the shipper", + }, + shipperStateProvinceCode: { + type: "string", + label: "Shipper State Province Code", + description: "The state province code of the shipper", + }, + shipperPostalCode: { + type: "string", + label: "Shipper Postal Code", + description: "The postal code of the shipper", + }, + shipperCountryCode: { + type: "string", + label: "Shipper Country Code", + description: "The country code of the shipper", + }, + shipToName: { + type: "string", + label: "Ship To Name", + description: "The name of the ship to", + }, + shipToAddressLine: { + type: "string", + label: "Ship To Address Line", + description: "The address line of the ship to", + }, + shipToCity: { + type: "string", + label: "Ship To City", + description: "The city of the ship to", + }, + shipToStateProvinceCode: { + type: "string", + label: "Ship To State Province Code", + description: "The state province code of the ship to", + }, + shipToPostalCode: { + type: "string", + label: "Ship To Postal Code", + description: "The postal code of the ship to", + }, + shipToCountryCode: { + type: "string", + label: "Ship To Country Code", + description: "The country code of the ship to", + }, + serviceCode: { + type: "string", + label: "Service Code", + description: "The code of the service", + options: constants.SERVICE_CODES, + }, + packagingCode: { + type: "string", + label: "Packaging Code", + description: "The code of the packaging", + options: constants.PACKAGING_CODES, + }, + weightUnit: { + type: "string", + label: "Weight Unit", + description: "The unit of weight for the package", + options: [ + "LBS", + "KGS", + "OZS", + ], + }, + packageWeight: { + type: "string", + label: "Package Weight", + description: "The weight of the package", + }, + }, + async run({ $ }) { + const response = await this.ups.createShipment({ + $, + data: { + ShipmentRequest: { + Request: { + RequestOption: "nonvalidate", + }, + Shipment: { + Shipper: { + Name: this.shipperName, + ShipperNumber: this.shipperNumber, + Address: { + AddressLine: this.shipperAddressLine, + City: this.shipperCity, + StateProvinceCode: this.shipperStateProvinceCode, + PostalCode: this.shipperPostalCode, + CountryCode: this.shipperCountryCode, + }, + }, + ShipTo: { + Name: this.shipToName, + Address: { + AddressLine: this.shipToAddressLine, + City: this.shipToCity, + StateProvinceCode: this.shipToStateProvinceCode, + PostalCode: this.shipToPostalCode, + CountryCode: this.shipToCountryCode, + }, + }, + PaymentInformation: { + ShipmentCharge: [ + { + Type: "01", // Transportation Charge + BillShipper: { + AccountNumber: this.shipperNumber, + }, + }, + ], + }, + Service: { + Code: this.serviceCode, + }, + Package: [ + { + Packaging: { + Code: this.packagingCode, + }, + PackageWeight: { + UnitOfMeasurement: { + Code: this.weightUnit, + }, + Weight: this.packageWeight, + }, + }, + ], + }, + }, + }, + }); + $.export("$summary", "Shipment created successfully"); + return response; + }, +}; diff --git a/components/ups/actions/get-tracking-info/get-tracking-info.mjs b/components/ups/actions/get-tracking-info/get-tracking-info.mjs new file mode 100644 index 0000000000000..7e4c3e1fc4bd9 --- /dev/null +++ b/components/ups/actions/get-tracking-info/get-tracking-info.mjs @@ -0,0 +1,32 @@ +import ups from "../../ups.app.mjs"; + +export default { + key: "ups-get-tracking-info", + name: "Get Tracking Info", + description: "Get tracking information for a UPS tracking number. [See the documentation](https://developer.ups.com/tag/Tracking?loc=en_US#operation/getSingleTrackResponseUsingGET)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + ups, + trackingNumber: { + propDefinition: [ + ups, + "trackingNumber", + ], + }, + }, + async run({ $ }) { + const response = await this.ups.getTrackingInfo({ + $, + trackingNumber: this.trackingNumber, + }); + + $.export("$summary", `Successfully retrieved tracking information for ${this.trackingNumber}`); + return response; + }, +}; diff --git a/components/ups/actions/recover-label/recover-label.mjs b/components/ups/actions/recover-label/recover-label.mjs new file mode 100644 index 0000000000000..8fd5f4b620118 --- /dev/null +++ b/components/ups/actions/recover-label/recover-label.mjs @@ -0,0 +1,39 @@ +import ups from "../../ups.app.mjs"; + +export default { + key: "ups-recover-label", + name: "Recover Label", + description: "Recover a label. [See the documentation](https://developer.ups.com/tag/Shipping?loc=en_US#operation/LabelRecovery)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + ups, + trackingNumber: { + propDefinition: [ + ups, + "trackingNumber", + ], + }, + }, + async run({ $ }) { + const response = await this.ups.recoverLabel({ + $, + data: { + LabelRecoveryRequest: { + Request: { + SubVersion: "1903", + }, + TrackingNumber: this.trackingNumber, + }, + }, + }); + + $.export("$summary", `Successfully recovered label for shipment with tracking number ${this.trackingNumber}`); + return response; + }, +}; diff --git a/components/ups/actions/void-shipment/void-shipment.mjs b/components/ups/actions/void-shipment/void-shipment.mjs new file mode 100644 index 0000000000000..72789dfc2f811 --- /dev/null +++ b/components/ups/actions/void-shipment/void-shipment.mjs @@ -0,0 +1,32 @@ +import ups from "../../ups.app.mjs"; + +export default { + key: "ups-void-shipment", + name: "Void Shipment", + description: "Void a shipment. [See the documentation](https://developer.ups.com/tag/Shipping?loc=en_US#operation/VoidShipment)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + ups, + trackingNumber: { + propDefinition: [ + ups, + "trackingNumber", + ], + }, + }, + async run({ $ }) { + const response = await this.ups.voidShipment({ + $, + trackingNumber: this.trackingNumber, + }); + + $.export("$summary", `Successfully voided shipment with tracking number ${this.trackingNumber}`); + return response; + }, +}; diff --git a/components/ups/common/constants.mjs b/components/ups/common/constants.mjs new file mode 100644 index 0000000000000..91c0c29b695b2 --- /dev/null +++ b/components/ups/common/constants.mjs @@ -0,0 +1,249 @@ +const VERSION = "v2409"; + +const SERVICE_CODES = [ + { + value: "01", + label: "Next Day Air", + }, + { + value: "02", + label: "2nd Day Air", + }, + { + value: "03", + label: "Ground", + }, + { + value: "07", + label: "Express", + }, + { + value: "08", + label: "Expedited", + }, + { + value: "11", + label: "UPS Standard", + }, + { + value: "12", + label: "3 Day Select", + }, + { + value: "13", + label: "Next Day Air Saver", + }, + { + value: "14", + label: "UPS Next Day Air® Early", + }, + { + value: "17", + label: "UPS Worldwide Economy DDU", + }, + { + value: "54", + label: "Express Plus", + }, + { + value: "59", + label: "2nd Day Air A.M.", + }, + { + value: "65", + label: "UPS Saver", + }, + { + value: "M2", + label: "First Class Mail", + }, + { + value: "M3", + label: "Priority Mail", + }, + { + value: "M4", + label: "Expedited MaiI Innovations", + }, + { + value: "M5", + label: "Priority Mail Innovations", + }, + { + value: "M6", + label: "Economy Mail Innovations", + }, + { + value: "M7", + label: "MaiI Innovations (MI) Returns", + }, + { + value: "70", + label: "UPS Access Point™ Economy", + }, + { + value: "71", + label: "UPS Worldwide Express Freight Midday", + }, + { + value: "72", + label: "UPS Worldwide Economy DDP", + }, + { + value: "74", + label: "UPS Express®12:00", + }, + { + value: "75", + label: "UPS Heavy Goods", + }, + { + value: "82", + label: "UPS Today Standard", + }, + { + value: "83", + label: "UPS Today Dedicated Courier", + }, + { + value: "84", + label: "UPS Today Intercity", + }, + { + value: "85", + label: "UPS Today Express", + }, + { + value: "86", + label: "UPS Today Express Saver", + }, + { + value: "93", + label: "Ground Saver", + }, + { + value: "96", + label: "UPS Worldwide Express Freight.", + }, + { + value: "C6", + label: "Roadie XD AM (Morning delivery)", + }, + { + value: "C7", + label: "Roadie XD PM (Afternoon delivery)", + }, + { + value: "C8", + label: "Roadie XD (Anytime delivery)", + }, + { + value: "T0", + label: "Master", + }, + { + value: "T1", + label: "LTL", + }, +]; + +const PACKAGING_CODES = [ + { + value: "01", + label: "UPS Letter", + }, + { + value: "02", + label: "Customer Supplied Package", + }, + { + value: "03", + label: "Tube", + }, + { + value: "04", + label: "PAK", + }, + { + value: "21", + label: "UPS Express Box", + }, + { + value: "24", + label: "UPS 25KG Box", + }, + { + value: "25", + label: "UPS 10KG Box", + }, + { + value: "30", + label: "Pallet", + }, + { + value: "2a", + label: "Small Express Box", + }, + { + value: "2b", + label: "Medium Express Box", + }, + { + value: "2c", + label: "Large Express Box", + }, + { + value: "56", + label: "Flats", + }, + { + value: "57", + label: "Parcels", + }, + { + value: "58", + label: "BPM", + }, + { + value: "59", + label: "First Class", + }, + { + value: "60", + label: "Priority", + }, + { + value: "61", + label: "Machineables", + }, + { + value: "62", + label: "Irregulars", + }, + { + value: "63", + label: "Parcel Post", + }, + { + value: "64", + label: "BPM Parcel", + }, + { + value: "65", + label: "Media Mail", + }, + { + value: "66", + label: "BPM Flat", + }, + { + value: "67", + label: "Standard Flat", + }, +]; + +export default { + VERSION, + SERVICE_CODES, + PACKAGING_CODES, +}; diff --git a/components/ups/package.json b/components/ups/package.json index c026c0081c0e1..59f2710120e75 100644 --- a/components/ups/package.json +++ b/components/ups/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ups", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream UPS Components", "main": "ups.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/ups/ups.app.mjs b/components/ups/ups.app.mjs index beff489bf6b09..2bf2a019ee2e6 100644 --- a/components/ups/ups.app.mjs +++ b/components/ups/ups.app.mjs @@ -1,11 +1,65 @@ +import { axios } from "@pipedream/platform"; +import { v4 as uuidv4 } from "uuid"; +import constants from "./common/constants.mjs"; +const { VERSION } = constants; + export default { type: "app", app: "ups", - propDefinitions: {}, + propDefinitions: { + trackingNumber: { + type: "string", + label: "Tracking Number", + description: "The tracking number of a shipment. Example: `1Z5338FF0107231059`", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://onlinetools.ups.com/api"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + transactionsrc: "@PipedreamHQ/pipedream v0.1", + transid: uuidv4(), + }, + ...opts, + }); + }, + getTrackingInfo({ + trackingNumber, ...opts + }) { + return this._makeRequest({ + path: `/track/v1/details/${trackingNumber}`, + ...opts, + }); + }, + createShipment(opts = {}) { + return this._makeRequest({ + method: "POST", + path: `/shipments/${VERSION}/ship`, + ...opts, + }); + }, + voidShipment({ + trackingNumber, ...opts + }) { + return this._makeRequest({ + method: "DELETE", + path: `/shipments/${VERSION}/void/cancel/${trackingNumber}`, + ...opts, + }); + }, + recoverLabel(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/labels/v1/recovery", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d037b23951720..aab19a1107096 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15278,7 +15278,11 @@ importers: components/uproc: {} - components/ups: {} + components/ups: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/upstash_redis: dependencies: