diff --git a/components/fedex/actions/create-shipment/create-shipment.mjs b/components/fedex/actions/create-shipment/create-shipment.mjs new file mode 100644 index 0000000000000..f71011a2412db --- /dev/null +++ b/components/fedex/actions/create-shipment/create-shipment.mjs @@ -0,0 +1,223 @@ +import fedex from "../../fedex.app.mjs"; + +export default { + key: "fedex-create-shipment", + name: "Create Shipment", + description: "Create a new shipment. [See the documentation](https://developer.fedex.com/api/en-us/catalog/ship/docs.html#operation/Create%20Shipment)", + version: "0.0.1", + type: "action", + props: { + fedex, + accountNumber: { + propDefinition: [ + fedex, + "accountNumber", + ], + }, + shipperStreetLines: { + propDefinition: [ + fedex, + "shipperStreetLines", + ], + }, + shipperCity: { + propDefinition: [ + fedex, + "shipperCity", + ], + }, + shipperStateOrProvinceCode: { + propDefinition: [ + fedex, + "shipperStateOrProvinceCode", + ], + }, + shipperPostalCode: { + propDefinition: [ + fedex, + "shipperPostalCode", + ], + }, + shipperCountryCode: { + propDefinition: [ + fedex, + "shipperCountryCode", + ], + }, + shipperContactName: { + propDefinition: [ + fedex, + "shipperContactName", + ], + }, + shipperPhoneNumber: { + propDefinition: [ + fedex, + "shipperPhoneNumber", + ], + }, + recipientStreetLines: { + propDefinition: [ + fedex, + "recipientStreetLines", + ], + }, + recipientCity: { + propDefinition: [ + fedex, + "recipientCity", + ], + }, + recipientStateOrProvinceCode: { + propDefinition: [ + fedex, + "recipientStateOrProvinceCode", + ], + }, + recipientPostalCode: { + propDefinition: [ + fedex, + "recipientPostalCode", + ], + }, + recipientCountryCode: { + propDefinition: [ + fedex, + "recipientCountryCode", + ], + }, + recipientContactName: { + propDefinition: [ + fedex, + "recipientContactName", + ], + }, + recipientPhoneNumber: { + propDefinition: [ + fedex, + "recipientPhoneNumber", + ], + }, + pickupType: { + propDefinition: [ + fedex, + "pickupType", + ], + }, + serviceType: { + propDefinition: [ + fedex, + "serviceType", + ], + }, + packagingType: { + propDefinition: [ + fedex, + "packagingType", + ], + }, + totalWeight: { + propDefinition: [ + fedex, + "totalWeight", + ], + }, + paymentType: { + propDefinition: [ + fedex, + "paymentType", + ], + }, + labelFormatType: { + propDefinition: [ + fedex, + "labelFormatType", + ], + }, + labelStockType: { + propDefinition: [ + fedex, + "labelStockType", + ], + }, + imageType: { + propDefinition: [ + fedex, + "imageType", + ], + }, + weightUnit: { + propDefinition: [ + fedex, + "weightUnit", + ], + }, + weights: { + propDefinition: [ + fedex, + "weights", + ], + }, + }, + async run({ $ }) { + const response = await this.fedex.createShipment({ + $, + data: { + accountNumber: { + value: this.accountNumber, + }, + labelResponseOptions: "URL_ONLY", + requestedShipment: { + shipper: { + address: { + streetLines: this.shipperStreetLines, + city: this.shipperCity, + stateOrProvinceCode: this.shipperStateOrProvinceCode, + postalCode: this.shipperPostalCode, + countryCode: this.shipperCountryCode, + }, + contact: { + personName: this.shipperContactName, + phoneNumber: this.shipperPhoneNumber, + }, + }, + recipients: [ + { + address: { + streetLines: this.recipientStreetLines, + city: this.recipientCity, + stateOrProvinceCode: this.recipientStateOrProvinceCode, + postalCode: this.recipientPostalCode, + countryCode: this.recipientCountryCode, + }, + contact: { + personName: this.recipientContactName, + phoneNumber: this.recipientPhoneNumber, + }, + }, + ], + pickupType: this.pickupType, + serviceType: this.serviceType, + packagingType: this.packagingType, + totalWeight: +this.totalWeight, + shippingChargesPayment: { + paymentType: this.paymentType, + }, + labelSpecification: { + labelFormatType: this.labelFormatType, + labelStockType: this.labelStockType, + imageType: this.imageType, + }, + requestedPackageLineItems: this.weights.map((weight) => ({ + weight: { + units: this.weightUnit, + value: +weight, + }, + })), + }, + }, + }); + $.export("$summary", "Shipment created successfully"); + return response; + }, +}; diff --git a/components/fedex/actions/validate-shipment/validate-shipment.mjs b/components/fedex/actions/validate-shipment/validate-shipment.mjs new file mode 100644 index 0000000000000..ad3279129db96 --- /dev/null +++ b/components/fedex/actions/validate-shipment/validate-shipment.mjs @@ -0,0 +1,219 @@ +import fedex from "../../fedex.app.mjs"; + +export default { + key: "fedex-validate-shipment", + name: "Validate Shipment", + description: "Validate a shipment. [See the documentation](https://developer.fedex.com/api/en-us/catalog/ship/docs.html#operation/ShipmentPackageValidate)", + version: "0.0.1", + type: "action", + props: { + fedex, + accountNumber: { + propDefinition: [ + fedex, + "accountNumber", + ], + }, + shipperStreetLines: { + propDefinition: [ + fedex, + "shipperStreetLines", + ], + }, + shipperCity: { + propDefinition: [ + fedex, + "shipperCity", + ], + }, + shipperStateOrProvinceCode: { + propDefinition: [ + fedex, + "shipperStateOrProvinceCode", + ], + }, + shipperPostalCode: { + propDefinition: [ + fedex, + "shipperPostalCode", + ], + }, + shipperCountryCode: { + propDefinition: [ + fedex, + "shipperCountryCode", + ], + }, + shipperContactName: { + propDefinition: [ + fedex, + "shipperContactName", + ], + }, + shipperPhoneNumber: { + propDefinition: [ + fedex, + "shipperPhoneNumber", + ], + }, + recipientStreetLines: { + propDefinition: [ + fedex, + "recipientStreetLines", + ], + }, + recipientCity: { + propDefinition: [ + fedex, + "recipientCity", + ], + }, + recipientStateOrProvinceCode: { + propDefinition: [ + fedex, + "recipientStateOrProvinceCode", + ], + }, + recipientPostalCode: { + propDefinition: [ + fedex, + "recipientPostalCode", + ], + }, + recipientCountryCode: { + propDefinition: [ + fedex, + "recipientCountryCode", + ], + }, + recipientContactName: { + propDefinition: [ + fedex, + "recipientContactName", + ], + }, + recipientPhoneNumber: { + propDefinition: [ + fedex, + "recipientPhoneNumber", + ], + }, + pickupType: { + propDefinition: [ + fedex, + "pickupType", + ], + }, + serviceType: { + propDefinition: [ + fedex, + "serviceType", + ], + }, + packagingType: { + propDefinition: [ + fedex, + "packagingType", + ], + }, + totalWeight: { + propDefinition: [ + fedex, + "totalWeight", + ], + }, + paymentType: { + propDefinition: [ + fedex, + "paymentType", + ], + }, + labelFormatType: { + propDefinition: [ + fedex, + "labelFormatType", + ], + }, + labelStockType: { + propDefinition: [ + fedex, + "labelStockType", + ], + }, + imageType: { + propDefinition: [ + fedex, + "imageType", + ], + }, + weightUnit: { + propDefinition: [ + fedex, + "weightUnit", + ], + }, + weights: { + propDefinition: [ + fedex, + "weights", + ], + }, + }, + async run({ $ }) { + const response = await this.fedex.validateShipment({ + $, + data: { + requestedShipment: { + shipper: { + address: { + streetLines: this.shipperStreetLines, + city: this.shipperCity, + stateOrProvinceCode: this.shipperStateOrProvinceCode, + postalCode: this.shipperPostalCode, + countryCode: this.shipperCountryCode, + }, + contact: { + personName: this.shipperContactName, + phoneNumber: this.shipperPhoneNumber, + }, + }, + recipients: [ + { + address: { + streetLines: this.recipientStreetLines, + city: this.recipientCity, + stateOrProvinceCode: this.recipientStateOrProvinceCode, + postalCode: this.recipientPostalCode, + countryCode: this.recipientCountryCode, + }, + contact: { + personName: this.recipientContactName, + phoneNumber: this.recipientPhoneNumber, + }, + }, + ], + pickupType: this.pickupType, + serviceType: this.serviceType, + packagingType: this.packagingType, + totalWeight: +this.totalWeight, + shippingChargesPayment: { + paymentType: this.paymentType, + }, + labelSpecification: { + labelFormatType: this.labelFormatType, + labelStockType: this.labelStockType, + imageType: this.imageType, + }, + requestedPackageLineItems: this.weights.map((weight) => ({ + weight: { + units: this.weightUnit, + value: +weight, + }, + })), + }, + }, + }); + $.export("$summary", "Shipment validated successfully"); + return response; + }, +}; diff --git a/components/fedex/fedex.app.mjs b/components/fedex/fedex.app.mjs index 9e882a7078da7..60ec87724706f 100644 --- a/components/fedex/fedex.app.mjs +++ b/components/fedex/fedex.app.mjs @@ -1,11 +1,212 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "fedex", - propDefinitions: {}, + propDefinitions: { + accountNumber: { + type: "string", + label: "Account Number", + description: "The account number associated with the shipment", + }, + shipperStreetLines: { + type: "string[]", + label: "Shipper Street Lines", + description: "Combination of number, street name, etc. At least one line is required for a valid physical address. Empty lines should not be included. Max Length is 35. Example: [1550 Union Blvd,Suite 302]", + }, + shipperCity: { + type: "string", + label: "Shipper City", + description: "The name of city, town of the recipient.Max length is 35. Example: Beverly Hills", + }, + shipperStateOrProvinceCode: { + type: "string", + label: "Shipper State Or Province Code", + description: "It is used to identify the principal subdivisions (e.g., provinces or states) of countries. The Format and presence of this field may vary depending on the country. Note: For specific countries, such as the United States and Canada, and Puerto Rico, there is a two-character state, province, codes limit . Example: TX", + optional: true, + }, + shipperPostalCode: { + type: "string", + label: "Shipper Postal Code", + description: "This is the postal code. Note: This is Optional for non [postal-aware countries](https://developer.fedex.com/api/en-us/guides/api-reference.html#postalawarecountries). Maximum length is 10. Example: 65247", + optional: true, + }, + shipperCountryCode: { + type: "string", + label: "Shipper Country Code", + description: "Is a capitalized two-character alpha code representing the country of the address. Example: US", + }, + shipperContactName: { + type: "string", + label: "Shipper Contact Name", + description: "Contact name, e.g. for customer support. Maximum length is 35. Example: John Doe", + }, + shipperPhoneNumber: { + type: "string", + label: "Shipper Phone Number", + description: "Contact phone number, e.g. for customer support. Maximum length is 10. Example: 15014321111", + }, + recipientStreetLines: { + type: "string[]", + label: "Recipient Street Lines", + description: "Combination of number, street name, etc. At least one line is required for a valid physical address. Empty lines should not be included. Max Length is 35. Example: [1550 Union Blvd,Suite 302]", + }, + recipientCity: { + type: "string", + label: "Recipient City", + description: "The name of city, town of the recipient.Max length is 35. Example: Beverly Hills", + }, + recipientStateOrProvinceCode: { + type: "string", + label: "Recipient State Or Province Code", + description: "It is used to identify the principal subdivisions (e.g., provinces or states) of countries. The Format and presence of this field may vary depending on the country. Note: For specific countries, such as the United States and Canada, and Puerto Rico, there is a two-character state, province, codes limit . Example: TX", + optional: true, + }, + recipientPostalCode: { + type: "string", + label: "Recipient Postal Code", + description: "This is the postal code. Note: This is Optional for non [postal-aware countries](https://developer.fedex.com/api/en-us/guides/api-reference.html#postalawarecountries). Maximum length is 10. Example: 65247", + optional: true, + }, + recipientCountryCode: { + type: "string", + label: "Recipient Country Code", + description: "Is a capitalized two-character alpha code representing the country of the address. Example: US", + }, + recipientContactName: { + type: "string", + label: "Recipient Contact Name", + description: "Contact name, e.g. for customer support. Maximum length is 35. Example: John Doe", + }, + recipientPhoneNumber: { + type: "string", + label: "Recipient Phone Number", + description: "Contact phone number, e.g. for customer support. Maximum length is 10. Example: 15014321111", + }, + pickupType: { + type: "string", + label: "Pickup Type", + description: "Indicates if shipment is being dropped off at a FedEx location or being picked up by FedEx or if it's a regularly scheduled pickup for this shipment.", + options: [ + "CONTACT_FEDEX_TO_SCHEDULE", + "DROPOFF_AT_FEDEX_LOCATION", + "USE_SCHEDULED_PICKUP", + ], + }, + serviceType: { + type: "string", + label: "Service Type", + description: "Indicate the FedEx [service type](https://developer.fedex.com/api/en-us/guides/api-reference.html#servicetypes) used for this shipment", + }, + packagingType: { + type: "string", + label: "Packaging Type", + description: "Specify the [packaging type](https://developer.fedex.com/api/en-us/guides/api-reference.html#packagetypes) used", + }, + totalWeight: { + type: "string", + label: "Total Weight", + description: "Indicate the shipment total weight in pounds", + }, + paymentType: { + type: "string", + label: "Payment Type", + description: "Indicates who and how the shipment will be paid for", + options: [ + "SENDER", + "RECIPIENT", + "THIRD_PARTY", + "COLLECT", + ], + }, + labelFormatType: { + type: "string", + label: "Label Format Type", + description: "Specifies the label Format Type", + options: [ + "COMMON2D", + "LABEL_DATA_ONLY", + ], + }, + labelStockType: { + type: "string", + label: "Label Stock Type", + description: "Label stock type used to create labels", + options: [ + "PAPER_4X6", + "STOCK_4X675", + "PAPER_4X675", + "PAPER_4X8", + "PAPER_4X9", + "PAPER_7X475", + "PAPER_85X11_BOTTOM_HALF_LABEL", + "PAPER_85X11_TOP_HALF_LABEL", + "PAPER_LETTER", + "STOCK_4X675_LEADING_DOC_TAB", + "STOCK_4X8", + "STOCK_4X9_LEADING_DOC_TAB", + "STOCK_4X6", + "STOCK_4X675_TRAILING_DOC_TAB", + "STOCK_4X9_TRAILING_DOC_TAB", + "STOCK_4X9", + "STOCK_4X85_TRAILING_DOC_TAB", + "STOCK_4X105_TRAILING_DOC_TAB", + ], + }, + imageType: { + type: "string", + label: "Image Type", + description: "Specifies the image type of this shipping document", + options: [ + "ZPLII", + "EPL2", + "PDF", + "PNG", + ], + }, + weightUnit: { + type: "string", + label: "Weight Unit", + description: "Specifies the package weight unit type", + options: [ + "LB", + "KG", + ], + }, + weights: { + type: "string[]", + label: "Weights", + description: "An array of weight values for each of the requested pieces of the shipment", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return this.$auth.server_type; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + ...opts, + }); + }, + createShipment(opts = {}) { + return this._makeRequest({ + path: "/ship/v1/shipments", + method: "POST", + ...opts, + }); + }, + validateShipment(opts = {}) { + return this._makeRequest({ + path: "/ship/v1/shipments/packages/validate", + method: "POST", + ...opts, + }); }, }, }; diff --git a/components/fedex/package.json b/components/fedex/package.json index 7cdc62da02c63..058aa2bac5dd5 100644 --- a/components/fedex/package.json +++ b/components/fedex/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/fedex", - "version": "0.0.4", + "version": "0.1.0", "description": "Pipedream FedEx Components", "main": "fedex.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81354f113b0cf..e932f114686a5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4812,7 +4812,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/fedex: {} + components/fedex: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/feedbin: dependencies: