-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New Components - easyship #16818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michelle0927
wants to merge
3
commits into
master
Choose a base branch
from
issue-13239
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Components - easyship #16818
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
222 changes: 222 additions & 0 deletions
222
components/easyship/actions/create-shipment/create-shipment.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
import easyship from "../../easyship.app.mjs"; | ||
|
||
export default { | ||
key: "easyship-create-shipment", | ||
name: "Create Shipment", | ||
description: "Create a new shipment in Easyship. [See the docs](https://developers.easyship.com/reference/shipments_create)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
easyship, | ||
originContactName: { | ||
type: "string", | ||
label: "Origin Name", | ||
description: "The full name of a person at the origin address", | ||
}, | ||
originContactEmail: { | ||
type: "string", | ||
label: "Origin Email", | ||
description: "Email address used to reach the person in `Origin Name`", | ||
}, | ||
originContactPhone: { | ||
type: "string", | ||
label: "Origin Phone Number", | ||
description: "Phone number used to reach the person in `Origin Name` (may or may not be SMS-ready)", | ||
}, | ||
originCompanyName: { | ||
type: "string", | ||
label: "Origin Company Name", | ||
description: "The company or organization at the originaddress", | ||
}, | ||
originLine1: { | ||
type: "string", | ||
label: "Origin Street Address", | ||
description: "Street address of the origin address", | ||
}, | ||
originCity: { | ||
type: "string", | ||
label: "Origin City", | ||
description: "City of the origin address", | ||
}, | ||
originState: { | ||
type: "string", | ||
label: "Origin State", | ||
description: "State, Province, or other top-level administrative region of the origin address", | ||
}, | ||
originPostalCode: { | ||
type: "string", | ||
label: "Origin Postal Code", | ||
description: "Postal code of the origin address", | ||
}, | ||
originCountry: { | ||
type: "string", | ||
label: "Origin Country (Alpha-2 Code)", | ||
description: "ISO 3166-1 alpha-2 code of the origin country", | ||
optional: true, | ||
}, | ||
destinationName: { | ||
type: "string", | ||
label: "Destination Name", | ||
description: "The full name of a person at the destination address.", | ||
}, | ||
destinationEmail: { | ||
type: "string", | ||
label: "Destination Email", | ||
description: "Email address used to reach the person at the destination address.", | ||
}, | ||
destinationPhoneNumber: { | ||
type: "string", | ||
label: "Destination Phone Number", | ||
description: "Phone number used to reach the person at the destination address (may or may not be SMS-ready).", | ||
}, | ||
destinationCompanyName: { | ||
type: "string", | ||
label: "Destination Company Name", | ||
description: "The company or organization at the destination address.", | ||
optional: true, | ||
}, | ||
destinationStreetAddress: { | ||
type: "string", | ||
label: "Destination Street Address", | ||
description: "Street address of the destination address.", | ||
}, | ||
destinationCity: { | ||
type: "string", | ||
label: "Destination City", | ||
description: "City of the destination address.", | ||
}, | ||
destinationState: { | ||
type: "string", | ||
label: "Destination State", | ||
description: "State, Province, or other top-level administrative region of the destination address.", | ||
}, | ||
destinationPostalCode: { | ||
type: "string", | ||
label: "Destination Postal Code", | ||
description: "Postal code of the destination address.", | ||
}, | ||
destinationCountry: { | ||
type: "string", | ||
label: "Destination Country (Alpha-2 Code)", | ||
description: "ISO 3166-1 alpha-2 code of the destination country.", | ||
}, | ||
numberOfParcels: { | ||
type: "integer", | ||
label: "Number of Parcels", | ||
description: "The number of parcels to ship", | ||
reloadProps: true, | ||
}, | ||
}, | ||
async additionalProps() { | ||
const props = {}; | ||
if (this.numberOfParcels > 0) { | ||
for (let i = 1; i <= this.numberOfParcels; i++) { | ||
props[`parcelWeight${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Weight (kg)`, | ||
description: `Item actual weight in kg of parcel ${i}`, | ||
}; | ||
props[`parcelLength${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Length (cm)`, | ||
description: `Length of parcel ${i}`, | ||
}; | ||
props[`parcelWidth${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Width (cm)`, | ||
description: `Width of parcel ${i}`, | ||
}; | ||
props[`parcelHeight${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Height (cm)`, | ||
description: `Height of parcel ${i}`, | ||
}; | ||
props[`parcelDescription${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Description`, | ||
description: `Description of parcel ${i}`, | ||
}; | ||
props[`parcelValue${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Value`, | ||
description: `Value of parcel ${i}`, | ||
}; | ||
props[`parcelCurrency${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Currency`, | ||
description: `Currency of parcel ${i} value`, | ||
}; | ||
props[`parcelCategory${i}`] = { | ||
type: "string", | ||
label: `Parcel ${i} Category`, | ||
description: `Category of parcel ${i}`, | ||
options: await this.getCategoriesOptions(), | ||
}; | ||
} | ||
} | ||
return props; | ||
}, | ||
methods: { | ||
async getCategoriesOptions() { | ||
const categories = await this.easyship.getPaginatedResources({ | ||
fn: this.easyship.listCategories, | ||
resourceKey: "item_categories", | ||
}); | ||
return categories.map((c) => ({ | ||
label: c.name, | ||
value: c.slug, | ||
})); | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const parcelItems = []; | ||
for (let i = 1; i <= this.numberOfParcels; i++) { | ||
parcelItems.push({ | ||
dimensions: { | ||
length: this[`parcelLength${i}`], | ||
width: this[`parcelWidth${i}`], | ||
height: this[`parcelHeight${i}`], | ||
}, | ||
actual_weight: this[`parcelWeight${i}`], | ||
description: this[`parcelDescription${i}`], | ||
declared_customs_value: this[`parcelValue${i}`], | ||
declared_currency: this[`parcelCurrency${i}`] || "USD", | ||
category: this[`parcelCategory${i}`], | ||
}); | ||
} | ||
const response = await this.easyship.createShipment({ | ||
$, | ||
data: { | ||
origin_address: { | ||
contact_name: this.originContactName, | ||
contact_email: this.originContactEmail, | ||
contact_phone: this.originContactPhone, | ||
company_name: this.originCompanyName, | ||
line_1: this.originLine1, | ||
city: this.originCity, | ||
state: this.originState, | ||
postal_code: this.originPostalCode, | ||
country_alpha2: this.originCountry, | ||
}, | ||
destination_address: { | ||
contact_name: this.destinationName, | ||
contact_email: this.destinationEmail, | ||
contact_phone: this.destinationPhoneNumber, | ||
company_name: this.destinationCompanyName, | ||
line_1: this.destinationStreetAddress, | ||
city: this.destinationCity, | ||
state: this.destinationState, | ||
postal_code: this.destinationPostalCode, | ||
country_alpha2: this.destinationCountry, | ||
}, | ||
parcels: [ | ||
{ | ||
items: parcelItems, | ||
}, | ||
], | ||
}, | ||
}); | ||
$.export("$summary", `Created shipment with ID: ${response.shipment.easyship_shipment_id}`); | ||
return response; | ||
}, | ||
}; |
26 changes: 26 additions & 0 deletions
26
components/easyship/actions/find-shipment/find-shipment.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import easyship from "../../easyship.app.mjs"; | ||
|
||
export default { | ||
key: "easyship-find-shipment", | ||
name: "Find Shipment", | ||
description: "Find a shipment by ID. [See the documentation](https://developers.easyship.com/reference/shipments_index)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
easyship, | ||
shipmentId: { | ||
propDefinition: [ | ||
easyship, | ||
"shipmentId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.easyship.getShipment({ | ||
$, | ||
shipmentId: this.shipmentId, | ||
}); | ||
$.export("$summary", `Found shipment with ID: ${this.shipmentId}`); | ||
return response; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "easyship", | ||
propDefinitions: { | ||
shipmentId: { | ||
type: "string", | ||
label: "Shipment ID", | ||
description: "The ID of the shipment to find", | ||
async options({ page }) { | ||
const { shipments } = await this.listShipments({ | ||
params: { | ||
page: page + 1, | ||
per_page: 100, | ||
}, | ||
}); | ||
return shipments.map((shipment) => shipment.easyship_shipment_id ); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_baseUrl() { | ||
return "https://public-api.easyship.com/2023-01"; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: `${this._baseUrl()}${path}`, | ||
headers: { | ||
Authorization: `Bearer ${this.$auth.api_token}`, | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
createWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/webhooks", | ||
method: "POST", | ||
...opts, | ||
}); | ||
}, | ||
activateWebhook({ | ||
webhookId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/webhooks/${webhookId}/activate`, | ||
method: "POST", | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook({ | ||
webhookId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/webhooks/${webhookId}`, | ||
method: "DELETE", | ||
...opts, | ||
}); | ||
}, | ||
getShipment({ | ||
shipmentId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/shipments/${shipmentId}`, | ||
...opts, | ||
}); | ||
}, | ||
listCategories(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/item_categories", | ||
...opts, | ||
}); | ||
}, | ||
listShipments(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/shipments", | ||
...opts, | ||
}); | ||
}, | ||
createShipment(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/shipments", | ||
method: "POST", | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, params, resourceKey, max, | ||
}) { | ||
params = { | ||
...params, | ||
page: 1, | ||
per_page: 100, | ||
}; | ||
let total, count = 0; | ||
do { | ||
const response = await fn({ | ||
params, | ||
}); | ||
const items = response[resourceKey]; | ||
for (const item of items) { | ||
yield item; | ||
if (max && ++count >= max) { | ||
return; | ||
} | ||
} | ||
params.page++; | ||
total = items.length; | ||
} while (total === params.per_page); | ||
}, | ||
async getPaginatedResources(opts = {}) { | ||
const results = []; | ||
for await (const item of this.paginate(opts)) { | ||
results.push(item); | ||
} | ||
return results; | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.