Skip to content

Commit 16ec150

Browse files
lcaresiaGTFalcaocoderabbitai[bot]
authored
[Components] finerworks #10976 (#18830)
* Added actions * Added actions * Added actions * Added actions * Update components/finerworks/actions/get-product-details/get-product-details.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/finerworks/actions/validate-address/validate-address.mjs --------- Co-authored-by: Guilherme Falcão <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 7502b61 commit 16ec150

File tree

6 files changed

+446
-88
lines changed

6 files changed

+446
-88
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import app from "../../finerworks.app.mjs";
2+
3+
export default {
4+
key: "finerworks-get-prices",
5+
name: "Get Prices",
6+
description: "Get the price of a product. [See the documentation](https://v2.api.finerworks.com/Help/Api/POST-v3-get_prices)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
productSku: {
17+
propDefinition: [
18+
app,
19+
"productSku",
20+
],
21+
},
22+
productQty: {
23+
propDefinition: [
24+
app,
25+
"productQty",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.app.getPrices({
31+
$,
32+
data: {
33+
products: [
34+
{
35+
product_qty: this.productQty,
36+
product_sku: this.productSku,
37+
},
38+
],
39+
},
40+
});
41+
$.export("$summary", `Successfully retrieved ${response.prices.length} ${response.prices.length > 1
42+
? "prices"
43+
: "price"} for product SKU ${this.productSku}`);
44+
return response;
45+
},
46+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import app from "../../finerworks.app.mjs";
2+
3+
export default {
4+
key: "finerworks-get-product-details",
5+
name: "Get Product Details",
6+
description: "Get details of a product. [See the documentation](https://v2.api.finerworks.com/Help/Api/POST-v3-get_product_details)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
productSku: {
17+
propDefinition: [
18+
app,
19+
"productSku",
20+
],
21+
},
22+
productQty: {
23+
propDefinition: [
24+
app,
25+
"productQty",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.app.getProductDetails({
31+
$,
32+
data: {
33+
products: [
34+
{
35+
product_sku: this.productSku,
36+
product_qty: this.productQty,
37+
},
38+
],
39+
},
40+
});
41+
$.export("$summary", `Successfully retrieved details for product SKU ${this.productSku}`);
42+
return response;
43+
},
44+
};
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import app from "../../finerworks.app.mjs";
2+
3+
export default {
4+
key: "finerworks-validate-address",
5+
name: "Validate Address",
6+
description: "Validate an address. [See the documentation](https://v2.api.finerworks.com/Help/Api/POST-v3-validate_recipient_address)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
firstName: {
17+
propDefinition: [
18+
app,
19+
"firstName",
20+
],
21+
},
22+
lastName: {
23+
propDefinition: [
24+
app,
25+
"lastName",
26+
],
27+
},
28+
companyName: {
29+
propDefinition: [
30+
app,
31+
"companyName",
32+
],
33+
},
34+
address: {
35+
propDefinition: [
36+
app,
37+
"address",
38+
],
39+
},
40+
city: {
41+
propDefinition: [
42+
app,
43+
"city",
44+
],
45+
},
46+
stateCode: {
47+
propDefinition: [
48+
app,
49+
"stateCode",
50+
],
51+
},
52+
province: {
53+
propDefinition: [
54+
app,
55+
"province",
56+
],
57+
},
58+
zipPostalCode: {
59+
propDefinition: [
60+
app,
61+
"zipPostalCode",
62+
],
63+
},
64+
countryCode: {
65+
propDefinition: [
66+
app,
67+
"countryCode",
68+
],
69+
},
70+
phone: {
71+
propDefinition: [
72+
app,
73+
"phone",
74+
],
75+
},
76+
email: {
77+
propDefinition: [
78+
app,
79+
"email",
80+
],
81+
},
82+
},
83+
async run({ $ }) {
84+
const response = await this.app.validateAddress({
85+
$,
86+
data: {
87+
recipient: {
88+
first_name: this.firstName,
89+
last_name: this.lastName,
90+
company_name: this.companyName,
91+
address_1: this.address,
92+
city: this.city,
93+
state_code: this.stateCode,
94+
province: this.province,
95+
zip_postal_code: this.zipPostalCode,
96+
country_code: this.countryCode,
97+
phone: this.phone,
98+
email: this.email,
99+
},
100+
},
101+
});
102+
$.export("$summary", "Successfully validated the address: " + response.status.success);
103+
return response;
104+
},
105+
};
Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,149 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "finerworks",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
firstName: {
8+
type: "string",
9+
label: "First Name",
10+
description: "Recipient first name",
11+
},
12+
lastName: {
13+
type: "string",
14+
label: "Last Name",
15+
description: "Recipient last name",
16+
},
17+
companyName: {
18+
type: "string",
19+
label: "Company Name",
20+
description: "Recipient company name",
21+
optional: true,
22+
},
23+
address: {
24+
type: "string",
25+
label: "Address",
26+
description: "Street address for the recipient",
27+
},
28+
city: {
29+
type: "string",
30+
label: "City",
31+
description: "Recipient city",
32+
optional: true,
33+
},
34+
stateCode: {
35+
type: "string",
36+
label: "State Code",
37+
description: "Required if in U.S. A valid USPS recognized 2 digit state code, i.e.: `CA`",
38+
optional: true,
39+
},
40+
province: {
41+
type: "string",
42+
label: "Province",
43+
description: "Province or region name",
44+
optional: true,
45+
},
46+
zipPostalCode: {
47+
type: "string",
48+
label: "ZIP or Postal Code",
49+
description: "ZIP or postal code of the recipient",
50+
},
51+
countryCode: {
52+
type: "string",
53+
label: "Country Code",
54+
description: "Two-letter ISO country code, e.g.: `US`, `CA`, `GB`",
55+
},
56+
phone: {
57+
type: "string",
58+
label: "Phone",
59+
description: "Recipient phone number",
60+
optional: true,
61+
},
62+
email: {
63+
type: "string",
64+
label: "Email",
65+
description: "Recipient email address",
66+
optional: true,
67+
},
68+
productQty: {
69+
type: "integer",
70+
label: "Product Quantity",
71+
description: "Quantity of the product",
72+
},
73+
productSku: {
74+
type: "string",
75+
label: "Product SKU",
76+
description: "SKU identifier of the product",
77+
async options() {
78+
const response = await this.getProducts();
79+
const products = response.products;
80+
return products.map(({
81+
sku, name,
82+
}) => ({
83+
label: name,
84+
value: sku,
85+
}));
86+
},
87+
},
88+
},
589
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
90+
_baseUrl() {
91+
return "https://v2.api.finerworks.com/v3";
92+
},
93+
async _makeRequest(opts = {}) {
94+
const {
95+
$ = this,
96+
path,
97+
headers,
98+
...otherOpts
99+
} = opts;
100+
console.log({
101+
...otherOpts,
102+
url: this._baseUrl() + path,
103+
headers: {
104+
"web_api_key": `${this.$auth.web_api_key}`,
105+
"app_key": `${this.$auth.app_key}`,
106+
...headers,
107+
},
108+
});
109+
return axios($, {
110+
...otherOpts,
111+
url: this._baseUrl() + path,
112+
headers: {
113+
"web_api_key": `${this.$auth.web_api_key}`,
114+
"app_key": `${this.$auth.app_key}`,
115+
...headers,
116+
},
117+
});
118+
},
119+
async validateAddress(args = {}) {
120+
return this._makeRequest({
121+
path: "/validate_recipient_address",
122+
method: "post",
123+
...args,
124+
});
125+
},
126+
async getPrices(args = {}) {
127+
return this._makeRequest({
128+
path: "/get_prices",
129+
method: "post",
130+
...args,
131+
});
132+
},
133+
async getProductDetails(args = {}) {
134+
return this._makeRequest({
135+
path: "/get_product_details",
136+
method: "post",
137+
...args,
138+
});
139+
},
140+
async getProducts(args = {}) {
141+
return this._makeRequest({
142+
path: "/list_virtual_inventory",
143+
method: "post",
144+
data: {},
145+
...args,
146+
});
9147
},
10148
},
11149
};

components/finerworks/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/finerworks",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream FinerWorks Components",
55
"main": "finerworks.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}

0 commit comments

Comments
 (0)