Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { LOCALE_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import printful from "../../printful.app.mjs";

export default {
key: "printful-calculate-shipping-rates",
name: "Calculate Shipping Rates",
description: "Fetches available shipping rates for a given destination. [See the documentation](https://developers.printful.com/docs/#tag/Shipping-Rate-API/operation/calculateShippingRates)",
version: "0.0.1",
type: "action",
props: {
printful,
storeId: {
propDefinition: [
printful,
"storeId",
],
},
address1: {
label: "Address 1",
description: "The address 1",
type: "string",
},
city: {
label: "City",
description: "The city",
type: "string",
},
stateCode: {
label: "State Code",
description: "The state code. E.g. `SC`",
type: "string",
},
countryCode: {
label: "Country Code",
description: "The country code. E.g. `BR`",
type: "string",
},
zip: {
label: "ZIP/Postal Code",
description: "The ZIP/postal code. E.g. `89221525`",
type: "string",
},
phone: {
label: "Phone",
description: "The phone number",
type: "string",
optional: true,
},
items: {
type: "string[]",
label: "Items",
description: "A list of items in JSON format. **Example: [{\"variant_id\": \"123456\", \"external_variant_id\": \"123456\", \"quantity\": 123, \"value\": \"12345\" }]**",
},
currency: {
type: "string",
label: "Currency",
description: "3 letter currency code (optional), required if the rates need to be converted to another currency instead of store default currency",
optional: true,
},
locale: {
type: "string",
label: "Locale",
description: "Locale in which shipping rate names will be returned",
options: LOCALE_OPTIONS,
optional: true,
},
},
async run({ $ }) {
const shippingRates = await this.printful.fetchShippingRates({
$,
headers: {
"X-PF-Store-Id": this.storeId,
},
data: {
recipient: {
address1: this.address1,
city: this.city,
state_code: this.stateCode,
country_code: this.countryCode,
zip: this.zip,
phone: this.phone,
},
items: parseObject(this.items),
currency: this.currency,
locale: this.locale,
},
});
$.export("$summary", "Fetched shipping rates successfully");
return shippingRates;
},
};
144 changes: 144 additions & 0 deletions components/printful/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { parseObject } from "../../common/utils.mjs";
import printful from "../../printful.app.mjs";

export default {
name: "Create Order",
version: "0.0.1",
key: "printful-create-order",
description: "Creates a new order in your Printful account. [See the documentaion](https://developers.printful.com/docs/#operation/createOrder)",
type: "action",
props: {
printful,
storeId: {
propDefinition: [
printful,
"storeId",
],
},
externalId: {
label: "External ID",
description: "Order ID from the external system",
type: "string",
optional: true,
},
recipientName: {
label: "Recipient Name",
description: "The recipient full name",
type: "string",
},
recipientCompanyName: {
label: "Recipient Company Name",
description: "The recipient company name",
type: "string",
optional: true,
},
address1: {
label: "Address 1",
description: "The address 1",
type: "string",
},
address2: {
label: "Address 2",
description: "The address 2",
type: "string",
optional: true,
},
city: {
label: "City",
description: "The city",
type: "string",
},
stateCode: {
label: "State Code",
description: "The state code. E.g. `SC`",
type: "string",
},
countryCode: {
label: "Country Code",
description: "The country code. E.g. `BR`",
type: "string",
reloadProps: true,
},
taxNumber: {
label: "Tax Number",
description: "TAX number (`optional`, but in case of Brazil country this field becomes `required` and will be used as CPF/CNPJ number)",
type: "string",
optional: true,
},
zip: {
label: "ZIP/Postal Code",
description: "The ZIP/postal code. E.g. `89221525`",
type: "string",
reloadProps: true,
},
phone: {
label: "Phone",
description: "The phone number",
type: "string",
optional: true,
},
email: {
label: "Email",
description: "The email",
type: "string",
optional: true,
},
giftSubject: {
label: "Gift Subject",
description: "Gift message title",
type: "string",
optional: true,
},
giftMessage: {
label: "Gift Message",
description: "Gift message text",
type: "string",
optional: true,
},
items: {
label: "Items",
description: "Array of items in the order. E.g. `[ { \"id\": 1, \"variant_id\": 2, \"quantity\": 3, \"price\": \"13.60\", \"retail_price\": \"9.90\", \"name\": \"Beauty Poster\", \"product\": { \"product_id\": 301, \"variant_id\": 500, \"name\": \"Red T-Shirt\" }, \"files\": [{\"url\": \"https://file.com/060b204a37f.png\"}] } ]`",
type: "string[]",
},
},
additionalProps(props) {
props.taxNumber.optional = this.countryCode != "BR";
return {};
},
async run({ $ }) {
const response = await this.printful.createOrder({
$,
headers: {
"X-PF-Store-Id": this.storeId,
},
data: {
external_id: this.externalId,
shipping: "STANDARD",
recipient: {
name: this.recipientName,
company: this.recipientCompanyName,
address1: this.address1,
address2: this.address2,
city: this.city,
state_code: this.stateCode,
country_code: this.countryCode,
zip: this.zip,
phone: this.phone,
email: this.email,
tax_number: this.taxNumber,
},
gift: {
subject: this.giftSubject,
message: this.giftMessage,
},
items: parseObject(this.items),
},
});

if (response) {
$.export("$summary", `Successfully created order with id ${response.result.id}`);
}

return response;
},
};
63 changes: 63 additions & 0 deletions components/printful/actions/update-product/update-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { parseObject } from "../../common/utils.mjs";
import printful from "../../printful.app.mjs";

export default {
key: "printful-update-product",
name: "Update Product",
description: "Updates an existing product in your Printful store. [See the documentation](https://developers.printful.com/docs/#tag/Products-API/operation/updateSyncProduct)",
version: "0.0.1",
type: "action",
props: {
printful,
storeId: {
propDefinition: [
printful,
"storeId",
],
},
productId: {
propDefinition: [
printful,
"productId",
({ storeId }) => ({
storeId,
}),
],
},
alert: {

Check warning on line 27 in components/printful/actions/update-product/update-product.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 27 in components/printful/actions/update-product/update-product.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "warning",
content: `Please note that in the request body you only need to specify the fields that need to be changed.
\nFurthermore, if you want to update existing sync variants, then in the sync variants array you must specify the IDs of all existing sync variants.
\nAll omitted existing sync variants will be deleted. All new sync variants without an ID will be created.`,
},
syncProduct: {
type: "object",
label: "Sync Product",
description: "Information about the SyncProduct. **Example: {\"external_id\": \"4235234213\", \"name\": \"T-shirt\", \"thumbnail\": \"http://your-domain.com/path/to/thumbnail.png\", \"is_ignored\": true}**",
optional: true,
},
syncVariants: {
type: "string[]",
label: "Sync Variants",
description: "Information about the Sync Variants. **Example: [{\"external_id\": \"12312414\", \"variant_id\": 3001, \"retail_price\": \"29.99\", \"is_ignored\": true, \"sku\": \"SKU1234\", \"files\": [{ \"type\": \"default\", \"url\": \"​https://www.example.com/files/tshirts/example.png\", \"options\": [{ \"id\": \"template_type\", \"value\": \"native\" }], \"filename\": \"shirt1.png\", \"visible\": true }], \"options\": [{ \"id\": \"embroidery_type\", \"value\": \"flat\" }], \"availability_status\": \"active\" }]**",
optional: true,
},
},
async run({ $ }) {

const response = await this.printful.updateProduct({
$,
headers: {
"X-PF-Store-Id": this.storeId,
},
productId: this.productId,
data: {
sync_product: parseObject(this.syncProduct),
sync_variants: parseObject(this.syncVariants),
},
});
$.export("$summary", `Updated product ${this.productId}`);
return response;
},
};
11 changes: 11 additions & 0 deletions components/printful/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const LIMIT = 100;
export const LOCALE_OPTIONS = [
{
label: "English (US)",
value: "en_US",
},
{
label: "Spanish (Spain)",
value: "es_ES",
},
];
24 changes: 24 additions & 0 deletions components/printful/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
18 changes: 18 additions & 0 deletions components/printful/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/printful",
"version": "0.1.0",
"description": "Pipedream Printful Components",
"main": "printful.app.mjs",
"keywords": [
"pipedream",
"printful"
],
"homepage": "https://pipedream.com/apps/printful",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Loading
Loading