Skip to content

Commit 1c31f7a

Browse files
committed
new components
1 parent 391abb1 commit 1c31f7a

File tree

12 files changed

+587
-2
lines changed

12 files changed

+587
-2
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import shopify from "../../shopify_developer_app.app.mjs";
2+
3+
export default {
4+
key: "shopify_developer_app-create-fulfillment",
5+
name: "Create Fulfillment",
6+
description: "Create a fulfillment. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/fulfillmentcreate)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
shopify,
11+
fulfillmentOrderId: {
12+
propDefinition: [
13+
shopify,
14+
"fulfillmentOrderId",
15+
],
16+
},
17+
fulfillmentOrderLineItemIds: {
18+
propDefinition: [
19+
shopify,
20+
"fulfillmentOrderLineItemIds",
21+
(c) => ({
22+
fulfillmentOrderId: c.fulfillmentOrderId,
23+
}),
24+
],
25+
reloadProps: true,
26+
},
27+
notifyCustomer: {
28+
type: "boolean",
29+
label: "Notify Customer",
30+
description: "Whether to notify the customer",
31+
optional: true,
32+
},
33+
message: {
34+
type: "string",
35+
label: "Message",
36+
description: "An optional message for the fulfillment request.",
37+
optional: true,
38+
},
39+
},
40+
async additionalProps() {
41+
const props = {};
42+
if (!this.fulfillmentOrderLineItemIds) {
43+
return props;
44+
}
45+
46+
for (const id of this.fulfillmentOrderLineItemIds) {
47+
props[`quantity_${id}`] = {
48+
type: "integer",
49+
label: `Quantity for Line Item - ${id}`,
50+
description: "The quantity of the line item to fulfill",
51+
};
52+
}
53+
return props;
54+
},
55+
async run({ $ }) {
56+
const fulfillment = await this.shopify.createFulfillment({
57+
fulfillment: {
58+
lineItemsByFulfillmentOrder: [
59+
{
60+
fulfillmentOrderId: this.fulfillmentOrderId,
61+
fulfillmentOrderLineItems: this.fulfillmentOrderLineItemIds.map((id) => ({
62+
id,
63+
quantity: this[`quantity_${id}`],
64+
})),
65+
},
66+
],
67+
notifyCustomer: this.notifyCustomer,
68+
},
69+
message: this.message,
70+
});
71+
if (fulfillment.fulfillmentCreate.userErrors.length > 0) {
72+
throw new Error(fulfillment.fulfillmentCreate.userErrors[0].message);
73+
}
74+
$.export("$summary", `Created fulfillment with ID: ${fulfillment.fulfillmentCreate.fulfillment.id}`);
75+
return fulfillment;
76+
},
77+
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import shopify from "../../shopify_developer_app.app.mjs";
2+
import { MAX_LIMIT } from "@pipedream/shopify/common/constants.mjs";
3+
4+
export default {
5+
key: "shopify-refund-order",
6+
name: "Refund Order",
7+
description: "Refund an order. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/refundcreate)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
shopify,
12+
orderId: {
13+
propDefinition: [
14+
shopify,
15+
"orderId",
16+
],
17+
},
18+
lineItemIds: {
19+
propDefinition: [
20+
shopify,
21+
"lineItemIds",
22+
(c) => ({
23+
orderId: c.orderId,
24+
}),
25+
],
26+
reloadProps: true,
27+
},
28+
},
29+
async additionalProps() {
30+
const props = {};
31+
if (!this.lineItemIds) {
32+
return props;
33+
}
34+
const order = await this.shopify.getOrder({
35+
id: this.orderId,
36+
first: MAX_LIMIT,
37+
});
38+
for (const id of this.lineItemIds) {
39+
const lineItem = order.order.lineItems.edges.find((item) => item.node.id === id);
40+
props[`quantity_${id}`] = {
41+
type: "integer",
42+
label: `Quantity for line item - ${lineItem.node.title}`,
43+
description: "The quantity of the line item to refund",
44+
};
45+
props[`restockType_${id}`] = {
46+
type: "string",
47+
label: `Restock type for line item - ${lineItem.node.title}`,
48+
description: "The restock type for the line item",
49+
options: [
50+
"CANCEL",
51+
"NO_RESTOCK",
52+
"RETURN",
53+
],
54+
default: "RETURN",
55+
};
56+
props[`locationId_${id}`] = {
57+
type: "string",
58+
label: `Location ID for line item - ${lineItem.node.title}`,
59+
description: "The location ID for the line item",
60+
options: async ({ prevContext }) => {
61+
return this.shopify.getPropOptions({
62+
resourceFn: this.shopify.listLocations,
63+
resourceKeys: [
64+
"locations",
65+
],
66+
labelKey: "name",
67+
prevContext,
68+
});
69+
},
70+
};
71+
}
72+
return props;
73+
},
74+
async run({ $ }) {
75+
const response = await this.shopify.refundOrder({
76+
input: {
77+
note: this.note,
78+
orderId: this.orderId,
79+
refundLineItems: this.lineItemIds.map((id) => ({
80+
lineItemId: id,
81+
quantity: this[`quantity_${id}`],
82+
locationId: this[`locationId_${id}`],
83+
restockType: this[`restockType_${id}`],
84+
})),
85+
},
86+
});
87+
88+
if (response.refundCreate.userErrors.length > 0) {
89+
throw new Error(response.refundCreate.userErrors[0].message);
90+
}
91+
$.export("$summary", `Refunded order with ID: ${this.orderId}`);
92+
return response;
93+
},
94+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import shopify from "../../shopify_developer_app.app.mjs";
2+
3+
export default {
4+
key: "shopify_developer_app-search-fulfillment-orders",
5+
name: "Search for Fulfillment Orders",
6+
description: "Search for a fulfillment order or a list of fulfillment orders. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/queries/fulfillmentorders)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
shopify,
11+
query: {
12+
type: "string",
13+
label: "Query",
14+
description: "A filter made up of terms, connectives, modifiers, and comparators. You can apply one or more filters to a query. Learn more about [Shopify API search syntax](https://shopify.dev/api/usage/search-syntax).",
15+
optional: true,
16+
},
17+
max: {
18+
type: "integer",
19+
label: "Max Records",
20+
description: "Optionally limit the maximum number of records to return. Leave blank to retrieve all records.",
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const orders = await this.shopify.getPaginated({
26+
resourceFn: this.shopify.listFulfillmentOrders,
27+
resourceKeys: [
28+
"fulfillmentOrders",
29+
],
30+
variables: {
31+
query: this.query,
32+
},
33+
max: this.max,
34+
});
35+
$.export("$summary", `Found ${orders.length} fulfillment order${orders.length === 1
36+
? ""
37+
: "s"}`);
38+
return orders;
39+
},
40+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import shopify from "../../shopify_developer_app.app.mjs";
2+
3+
export default {
4+
key: "shopify_developer_app-update-fulfillment-tracking-info",
5+
name: "Update Fulfillment Tracking Info",
6+
description: "Update the tracking info for a fulfillment. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/fulfillmenttrackinginfoupdate)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
shopify,
11+
orderId: {
12+
propDefinition: [
13+
shopify,
14+
"orderId",
15+
],
16+
},
17+
fullfillmentId: {
18+
propDefinition: [
19+
shopify,
20+
"fullfillmentId",
21+
(c) => ({
22+
orderId: c.orderId,
23+
}),
24+
],
25+
},
26+
company: {
27+
type: "string",
28+
label: "Company",
29+
description: "The name of the tracking company",
30+
optional: true,
31+
},
32+
number: {
33+
type: "string",
34+
label: "Tracking Number",
35+
description: "The tracking number for the fulfillment",
36+
optional: true,
37+
},
38+
url: {
39+
type: "string",
40+
label: "Tracking URL",
41+
description: "The URL for the tracking information",
42+
optional: true,
43+
},
44+
notifyCustomer: {
45+
type: "boolean",
46+
label: "Notify Customer",
47+
description: "Whether to notify the customer",
48+
optional: true,
49+
},
50+
},
51+
async run({ $ }) {
52+
const response = await this.shopify.updateFulfillmentTrackingInfo({
53+
fulfillmentId: this.fullfillmentId,
54+
trackingInfoInput: {
55+
company: this.company,
56+
number: this.number,
57+
url: this.url,
58+
},
59+
notifyCustomer: this.notifyCustomer,
60+
});
61+
62+
if (response.fulfillmentTrackingInfoUpdate.userErrors.length > 0) {
63+
throw new Error(response.fulfillmentTrackingInfoUpdate.userErrors[0].message);
64+
}
65+
$.export("$summary", `Updated fulfillment tracking info for fulfillment with ID: ${this.fullfillmentId}`);
66+
return response;
67+
},
68+
};

components/shopify_developer_app/common/mutations.mjs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,97 @@ const UPDATE_PRODUCT = `
116116
}
117117
`;
118118

119+
const REFUND_ORDER = `
120+
mutation RefundLineItem($input: RefundInput!) {
121+
refundCreate(input: $input) {
122+
refund {
123+
id
124+
totalRefundedSet {
125+
presentmentMoney {
126+
amount
127+
currencyCode
128+
}
129+
}
130+
order {
131+
id
132+
totalPriceSet {
133+
presentmentMoney {
134+
amount
135+
currencyCode
136+
}
137+
}
138+
}
139+
refundLineItems(first: 10) {
140+
nodes {
141+
id
142+
lineItem {
143+
id
144+
title
145+
quantity
146+
product {
147+
id
148+
title
149+
}
150+
variant {
151+
id
152+
title
153+
price
154+
}
155+
}
156+
}
157+
}
158+
}
159+
userErrors {
160+
field
161+
message
162+
}
163+
}
164+
}
165+
`;
166+
167+
const UPDATE_FULFILLMENT_TRACKING_INFO = `
168+
mutation FulfillmentTrackingInfoUpdate($fulfillmentId: ID!, $trackingInfoInput: FulfillmentTrackingInput!, $notifyCustomer: Boolean) {
169+
fulfillmentTrackingInfoUpdate(fulfillmentId: $fulfillmentId, trackingInfoInput: $trackingInfoInput, notifyCustomer: $notifyCustomer) {
170+
fulfillment {
171+
id
172+
status
173+
trackingInfo {
174+
company
175+
number
176+
url
177+
}
178+
}
179+
userErrors {
180+
field
181+
message
182+
}
183+
}
184+
}
185+
`;
186+
187+
const CREATE_FULFILLMENT = `
188+
mutation fulfillmentCreate($fulfillment: FulfillmentInput!, $message: String) {
189+
fulfillmentCreate(fulfillment: $fulfillment, message: $message) {
190+
fulfillment {
191+
id
192+
name
193+
status
194+
createdAt
195+
}
196+
userErrors {
197+
field
198+
message
199+
}
200+
}
201+
}
202+
`;
203+
119204
export default {
120205
CREATE_ORDER,
121206
CREATE_CUSTOMER,
122207
UPDATE_CUSTOMER,
123208
UPDATE_PRODUCT,
209+
REFUND_ORDER,
210+
UPDATE_FULFILLMENT_TRACKING_INFO,
211+
CREATE_FULFILLMENT,
124212
};

0 commit comments

Comments
 (0)