Skip to content

Commit 08b3ac4

Browse files
committed
Added actions
1 parent 88e141a commit 08b3ac4

File tree

6 files changed

+341
-23
lines changed

6 files changed

+341
-23
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
{
34+
product_qty: this.productQty,
35+
product_sku: this.productSku,
36+
},
37+
],
38+
});
39+
$.export("$summary", "Successfully sent the request");
40+
return response;
41+
},
42+
};
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 sent the request to get details of the specified product");
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 sent the request. Validation success: " + response.status.success);
103+
return response;
104+
},
105+
};
Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,140 @@
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+
return axios($, {
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+
},
110+
async validateAddress(args = {}) {
111+
return this._makeRequest({
112+
path: "/validate_recipient_address",
113+
method: "post",
114+
...args,
115+
});
116+
},
117+
async getPrices(args = {}) {
118+
return this._makeRequest({
119+
path: "/get_prices",
120+
method: "post",
121+
...args,
122+
});
123+
},
124+
async getProductDetails(args = {}) {
125+
return this._makeRequest({
126+
path: "/get_product_details",
127+
method: "post",
128+
...args,
129+
});
130+
},
131+
async getProducts(args = {}) {
132+
return this._makeRequest({
133+
path: "/list_virtual_inventory",
134+
method: "post",
135+
data: {},
136+
...args,
137+
});
9138
},
10139
},
11140
};

components/finerworks/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)