Skip to content

Commit 0193d17

Browse files
authored
New Components - printful (#15436)
* printful init * [Components] printful #15140 Sources - New Order (Instant) - New Product Added (Instant) - New Order Status Updated (Instant) Actions - Create Order - Calculate Shipping Rates - Update Product * pnpm update * some adjusts
1 parent 4e6a586 commit 0193d17

File tree

15 files changed

+1058
-4
lines changed

15 files changed

+1058
-4
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { LOCALE_OPTIONS } from "../../common/constants.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import printful from "../../printful.app.mjs";
4+
5+
export default {
6+
key: "printful-calculate-shipping-rates",
7+
name: "Calculate Shipping Rates",
8+
description: "Fetches available shipping rates for a given destination. [See the documentation](https://developers.printful.com/docs/#tag/Shipping-Rate-API/operation/calculateShippingRates)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
printful,
13+
storeId: {
14+
propDefinition: [
15+
printful,
16+
"storeId",
17+
],
18+
},
19+
address1: {
20+
label: "Address 1",
21+
description: "The address 1",
22+
type: "string",
23+
},
24+
city: {
25+
label: "City",
26+
description: "The city",
27+
type: "string",
28+
},
29+
stateCode: {
30+
label: "State Code",
31+
description: "The state code. E.g. `SC`",
32+
type: "string",
33+
},
34+
countryCode: {
35+
label: "Country Code",
36+
description: "The country code. E.g. `BR`",
37+
type: "string",
38+
},
39+
zip: {
40+
label: "ZIP/Postal Code",
41+
description: "The ZIP/postal code. E.g. `89221525`",
42+
type: "string",
43+
},
44+
phone: {
45+
label: "Phone",
46+
description: "The phone number",
47+
type: "string",
48+
optional: true,
49+
},
50+
items: {
51+
type: "string[]",
52+
label: "Items",
53+
description: "A list of items in JSON format. **Example: [{\"variant_id\": \"123456\", \"external_variant_id\": \"123456\", \"quantity\": 123, \"value\": \"12345\" }]**",
54+
},
55+
currency: {
56+
type: "string",
57+
label: "Currency",
58+
description: "3 letter currency code (optional), required if the rates need to be converted to another currency instead of store default currency",
59+
optional: true,
60+
},
61+
locale: {
62+
type: "string",
63+
label: "Locale",
64+
description: "Locale in which shipping rate names will be returned",
65+
options: LOCALE_OPTIONS,
66+
optional: true,
67+
},
68+
},
69+
async run({ $ }) {
70+
const shippingRates = await this.printful.fetchShippingRates({
71+
$,
72+
headers: {
73+
"X-PF-Store-Id": this.storeId,
74+
},
75+
data: {
76+
recipient: {
77+
address1: this.address1,
78+
city: this.city,
79+
state_code: this.stateCode,
80+
country_code: this.countryCode,
81+
zip: this.zip,
82+
phone: this.phone,
83+
},
84+
items: parseObject(this.items),
85+
currency: this.currency,
86+
locale: this.locale,
87+
},
88+
});
89+
$.export("$summary", "Fetched shipping rates successfully");
90+
return shippingRates;
91+
},
92+
};
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import printful from "../../printful.app.mjs";
3+
4+
export default {
5+
name: "Create Order",
6+
version: "0.0.1",
7+
key: "printful-create-order",
8+
description: "Creates a new order in your Printful account. [See the documentaion](https://developers.printful.com/docs/#operation/createOrder)",
9+
type: "action",
10+
props: {
11+
printful,
12+
storeId: {
13+
propDefinition: [
14+
printful,
15+
"storeId",
16+
],
17+
},
18+
externalId: {
19+
label: "External ID",
20+
description: "Order ID from the external system",
21+
type: "string",
22+
optional: true,
23+
},
24+
recipientName: {
25+
label: "Recipient Name",
26+
description: "The recipient full name",
27+
type: "string",
28+
},
29+
recipientCompanyName: {
30+
label: "Recipient Company Name",
31+
description: "The recipient company name",
32+
type: "string",
33+
optional: true,
34+
},
35+
address1: {
36+
label: "Address 1",
37+
description: "The address 1",
38+
type: "string",
39+
},
40+
address2: {
41+
label: "Address 2",
42+
description: "The address 2",
43+
type: "string",
44+
optional: true,
45+
},
46+
city: {
47+
label: "City",
48+
description: "The city",
49+
type: "string",
50+
},
51+
stateCode: {
52+
label: "State Code",
53+
description: "The state code. E.g. `SC`",
54+
type: "string",
55+
},
56+
countryCode: {
57+
label: "Country Code",
58+
description: "The country code. E.g. `BR`",
59+
type: "string",
60+
reloadProps: true,
61+
},
62+
taxNumber: {
63+
label: "Tax Number",
64+
description: "TAX number (`optional`, but in case of Brazil country this field becomes `required` and will be used as CPF/CNPJ number)",
65+
type: "string",
66+
optional: true,
67+
},
68+
zip: {
69+
label: "ZIP/Postal Code",
70+
description: "The ZIP/postal code. E.g. `89221525`",
71+
type: "string",
72+
reloadProps: true,
73+
},
74+
phone: {
75+
label: "Phone",
76+
description: "The phone number",
77+
type: "string",
78+
optional: true,
79+
},
80+
email: {
81+
label: "Email",
82+
description: "The email",
83+
type: "string",
84+
optional: true,
85+
},
86+
giftSubject: {
87+
label: "Gift Subject",
88+
description: "Gift message title",
89+
type: "string",
90+
optional: true,
91+
},
92+
giftMessage: {
93+
label: "Gift Message",
94+
description: "Gift message text",
95+
type: "string",
96+
optional: true,
97+
},
98+
items: {
99+
label: "Items",
100+
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\"}] } ]`",
101+
type: "string[]",
102+
},
103+
},
104+
additionalProps(props) {
105+
props.taxNumber.optional = this.countryCode != "BR";
106+
return {};
107+
},
108+
async run({ $ }) {
109+
const response = await this.printful.createOrder({
110+
$,
111+
headers: {
112+
"X-PF-Store-Id": this.storeId,
113+
},
114+
data: {
115+
external_id: this.externalId,
116+
shipping: "STANDARD",
117+
recipient: {
118+
name: this.recipientName,
119+
company: this.recipientCompanyName,
120+
address1: this.address1,
121+
address2: this.address2,
122+
city: this.city,
123+
state_code: this.stateCode,
124+
country_code: this.countryCode,
125+
zip: this.zip,
126+
phone: this.phone,
127+
email: this.email,
128+
tax_number: this.taxNumber,
129+
},
130+
gift: {
131+
subject: this.giftSubject,
132+
message: this.giftMessage,
133+
},
134+
items: parseObject(this.items),
135+
},
136+
});
137+
138+
if (response) {
139+
$.export("$summary", `Successfully created order with id ${response.result.id}`);
140+
}
141+
142+
return response;
143+
},
144+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import printful from "../../printful.app.mjs";
3+
4+
export default {
5+
key: "printful-update-product",
6+
name: "Update Product",
7+
description: "Updates an existing product in your Printful store. [See the documentation](https://developers.printful.com/docs/#tag/Products-API/operation/updateSyncProduct)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
printful,
12+
storeId: {
13+
propDefinition: [
14+
printful,
15+
"storeId",
16+
],
17+
},
18+
productId: {
19+
propDefinition: [
20+
printful,
21+
"productId",
22+
({ storeId }) => ({
23+
storeId,
24+
}),
25+
],
26+
},
27+
alert: {
28+
type: "alert",
29+
alertType: "warning",
30+
content: `Please note that in the request body you only need to specify the fields that need to be changed.
31+
\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.
32+
\nAll omitted existing sync variants will be deleted. All new sync variants without an ID will be created.`,
33+
},
34+
syncProduct: {
35+
type: "object",
36+
label: "Sync Product",
37+
description: "Information about the SyncProduct. **Example: {\"external_id\": \"4235234213\", \"name\": \"T-shirt\", \"thumbnail\": \"http://your-domain.com/path/to/thumbnail.png\", \"is_ignored\": true}**",
38+
optional: true,
39+
},
40+
syncVariants: {
41+
type: "string[]",
42+
label: "Sync Variants",
43+
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\" }]**",
44+
optional: true,
45+
},
46+
},
47+
async run({ $ }) {
48+
49+
const response = await this.printful.updateProduct({
50+
$,
51+
headers: {
52+
"X-PF-Store-Id": this.storeId,
53+
},
54+
productId: this.productId,
55+
data: {
56+
sync_product: parseObject(this.syncProduct),
57+
sync_variants: parseObject(this.syncVariants),
58+
},
59+
});
60+
$.export("$summary", `Updated product ${this.productId}`);
61+
return response;
62+
},
63+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const LIMIT = 100;
2+
export const LOCALE_OPTIONS = [
3+
{
4+
label: "English (US)",
5+
value: "en_US",
6+
},
7+
{
8+
label: "Spanish (Spain)",
9+
value: "es_ES",
10+
},
11+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/printful/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/printful",
3+
"version": "0.1.0",
4+
"description": "Pipedream Printful Components",
5+
"main": "printful.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"printful"
9+
],
10+
"homepage": "https://pipedream.com/apps/printful",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)