Skip to content

Commit c932b1d

Browse files
committed
updates per QA
1 parent 970252e commit c932b1d

File tree

10 files changed

+100
-52
lines changed

10 files changed

+100
-52
lines changed
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import common from "../common/metafield-actions.mjs";
1+
import shopify from "../../shopify.app.mjs";
22
import constants from "../common/constants.mjs";
33

44
export default {
5-
...common,
65
key: "shopify-create-metafield",
76
name: "Create Metafield",
8-
description: "Creates a metafield belonging to a resource. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/mutations/metafieldsSet)",
7+
description: "Creates a metafield belonging to a resource. [See the documentation](https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldDefinitionCreate)",
98
version: "0.0.11",
109
type: "action",
1110
props: {
12-
...common.props,
11+
shopify,
12+
ownerResource: {
13+
type: "string",
14+
label: "Resource Type",
15+
description: "Filter by the resource type on which the metafield is attached to",
16+
options: constants.RESOURCE_TYPES.map((type) => ({
17+
...type,
18+
value: type.value.toUpperCase(),
19+
})),
20+
},
21+
name: {
22+
type: "string",
23+
label: "Name",
24+
description: "The human-readable name for the metafield definition",
25+
},
1326
namespace: {
1427
type: "string",
1528
label: "Namespace",
@@ -25,36 +38,30 @@ export default {
2538
label: "Type",
2639
description: "The type of data that the metafield stores in the `value` field. Refer to the list of [supported types](https://shopify.dev/apps/custom-data/metafields/types).",
2740
options: Object.keys(constants.METAFIELD_TYPES),
28-
reloadProps: true,
2941
},
30-
},
31-
async additionalProps() {
32-
const props = await this.getOwnerIdProp(this.ownerResource);
33-
34-
if (this.type) {
35-
props.value = {
36-
type: "string",
37-
label: "Value",
38-
description: "The data to store in the metafield",
39-
};
40-
}
41-
42-
return props;
42+
pin: {
43+
type: "boolean",
44+
label: "Pin",
45+
description: "Whether to pin the metafield definition",
46+
default: false,
47+
optional: true,
48+
},
4349
},
4450
async run({ $ }) {
4551
const response = await this.shopify.createMetafield({
46-
metafields: {
52+
definition: {
53+
ownerType: this.ownerResource,
54+
name: this.name,
55+
namespace: this.namespace,
4756
key: this.key,
4857
type: this.type,
49-
value: this.value,
50-
namespace: this.namespace,
51-
ownerId: this.ownerId,
58+
pin: this.pin,
5259
},
5360
});
54-
if (response.metafieldsSet.userErrors.length > 0) {
55-
throw new Error(response.metafieldsSet.userErrors[0].message);
61+
if (response.metafieldDefinitionCreate.userErrors.length > 0) {
62+
throw new Error(response.metafieldDefinitionCreate.userErrors[0].message);
5663
}
57-
$.export("$summary", `Created metafield for object with ID ${this.ownerId}`);
64+
$.export("$summary", `Created metafield ${this.name} for object type ${this.type}`);
5865
return response;
5966
},
6067
};

components/shopify/actions/create-product-variant/create-product-variant.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import shopify from "../../shopify.app.mjs";
22
import utils from "../../common/utils.mjs";
3-
import { MAX_LIMIT } from "../../common/constants.mjs";
3+
import {
4+
MAX_LIMIT, WEIGHT_UNITS,
5+
} from "../../common/constants.mjs";
46
import { ConfigurationError } from "@pipedream/platform";
57

68
export default {
@@ -74,12 +76,7 @@ export default {
7476
label: "Weight Unit",
7577
description: "The unit of measurement that applies to the product variant's weight. If you don't specify a value for weight_unit, then the shop's default unit of measurement is applied.",
7678
optional: true,
77-
options: [
78-
"g",
79-
"kg",
80-
"oz",
81-
"lb",
82-
],
79+
options: WEIGHT_UNITS,
8380
},
8481
metafields: {
8582
propDefinition: [
@@ -112,6 +109,10 @@ export default {
112109
throw new ConfigurationError("Must enter LocationId to set the available quantity");
113110
}
114111

112+
if ((this.weightUnit && !this.weight) || (!this.weightUnit && this.weight)) {
113+
throw new ConfigurationError("Must enter both Weight and Weight Unit to set weight");
114+
}
115+
115116
const response = await this.shopify.createProductVariants({
116117
productId: this.productId,
117118
variants: [
@@ -125,7 +126,7 @@ export default {
125126
measurement: (this.weightUnit || this.weight) && {
126127
weight: {
127128
unit: this.weightUnit,
128-
value: this.weight,
129+
value: +this.weight,
129130
},
130131
},
131132
},

components/shopify/actions/get-metaobjects/get-metaobjects.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ export default {
1616
shopify,
1717
"metaobjectType",
1818
],
19+
withLabel: true,
1920
},
2021
},
2122
async run({ $ }) {
2223
const response = await this.shopify.listMetaobjects({
23-
type: this.type,
24+
type: this.type.label,
2425
first: MAX_LIMIT,
2526
});
2627

components/shopify/actions/search-product-variant/search-product-variant.mjs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,20 @@ export default {
110110
});
111111
}
112112

113-
const title = response.productVariants
114-
? response.productVariants.nodes[0].title
115-
: response.productVariant.title;
116-
const id = response.productVariants
117-
? response.productVariants.nodes[0].id
118-
: response.productVariant.id;
119-
$.export("$summary", `Found product variant \`${title}\` with ID \`${id}\``);
113+
const variant = response?.productVariants?.nodes?.length
114+
? response.productVariants.nodes[0]
115+
: response?.productVariant
116+
? response.productVariant
117+
: {};
118+
119+
const title = variant?.title;
120+
const id = variant?.id;
121+
122+
if (title && id) {
123+
$.export("$summary", `Found product variant \`${title}\` with ID \`${id}\``);
124+
} else {
125+
$.export("$summary", "No product variant found");
126+
}
120127
return response;
121128
} catch (err) {
122129
if (!this.createIfNotFound) {

components/shopify/actions/search-products/search-products.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default {
2929
"productId",
3030
],
3131
type: "string[]",
32+
label: "Product IDs",
33+
description: "Select multiple Product IDs or provide Product IDs as a JSON array. For example: `{{ [\"gid://shopify/Product/1\", \"gid://shopify/Product/2\"] }}`",
3234
optional: true,
3335
},
3436
collectionId: {
@@ -61,6 +63,7 @@ export default {
6163
shopify,
6264
"sortKey",
6365
],
66+
description: "The key to sort the results by. Keys `RELEVANCE` and `INVENTORY_TOTAL` not for use with `Collection ID`.",
6467
options: PRODUCT_SORT_KEY,
6568
},
6669
reverse: {
@@ -92,7 +95,7 @@ export default {
9295
const query = queryArray.length
9396
? queryArray.join(" AND ")
9497
: undefined;
95-
98+
console.log(query);
9699
let products = await this.shopify.getPaginated({
97100
resourceFn: this.shopify.listProducts,
98101
resourceKeys: [

components/shopify/actions/update-product-variant/update-product-variant.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import shopify from "../../shopify.app.mjs";
22
import utils from "../../common/utils.mjs";
3-
import { MAX_LIMIT } from "../../common/constants.mjs";
3+
import {
4+
MAX_LIMIT, WEIGHT_UNITS,
5+
} from "../../common/constants.mjs";
6+
import { ConfigurationError } from "@pipedream/platform";
47

58
export default {
69
key: "shopify-update-product-variant",
@@ -70,12 +73,7 @@ export default {
7073
label: "Weight Unit",
7174
description: "The unit of measurement that applies to the product variant's weight. If you don't specify a value for weight_unit, then the shop's default unit of measurement is applied.",
7275
optional: true,
73-
options: [
74-
"g",
75-
"kg",
76-
"oz",
77-
"lb",
78-
],
76+
options: WEIGHT_UNITS,
7977
},
8078
metafields: {
8179
propDefinition: [
@@ -104,6 +102,10 @@ export default {
104102
},
105103
},
106104
async run({ $ }) {
105+
if ((this.weightUnit && !this.weight) || (!this.weightUnit && this.weight)) {
106+
throw new ConfigurationError("Must enter both Weight and Weight Unit to set weight");
107+
}
108+
107109
const response = await this.shopify.updateProductVariant({
108110
productId: this.productId,
109111
variants: [
@@ -118,7 +120,7 @@ export default {
118120
measurement: (this.weightUnit || this.weight) && {
119121
weight: {
120122
unit: this.weightUnit,
121-
value: this.weight,
123+
value: +this.weight,
122124
},
123125
},
124126
},

components/shopify/common/constants.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ const COLLECTION_RULE_RELATIONS = [
5252
"STARTS_WITH",
5353
];
5454

55+
const WEIGHT_UNITS = [
56+
"KILOGRAMS",
57+
"GRAMS",
58+
"POUNDS",
59+
"OUNCES",
60+
];
61+
5562
const INVENTORY_ADJUSTMENT_REASONS = [
5663
{
5764
value: "correction",
@@ -131,5 +138,6 @@ export {
131138
COLLECTION_SORT_KEY,
132139
COLLECTION_RULE_COLUMNS,
133140
COLLECTION_RULE_RELATIONS,
141+
WEIGHT_UNITS,
134142
INVENTORY_ADJUSTMENT_REASONS,
135143
};

components/shopify/common/mutations.mjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const CREATE_PRODUCT = `
173173
}
174174
`;
175175

176-
const CREATE_METAFIELD = `
176+
const SET_METAFIELD = `
177177
mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
178178
metafieldsSet(metafields: $metafields) {
179179
metafields {
@@ -191,6 +191,21 @@ const CREATE_METAFIELD = `
191191
}
192192
`;
193193

194+
const CREATE_METAFIELD = `
195+
mutation CreateMetafieldDefinition($definition: MetafieldDefinitionInput!) {
196+
metafieldDefinitionCreate(definition: $definition) {
197+
createdDefinition {
198+
id
199+
name
200+
}
201+
userErrors {
202+
field
203+
message
204+
}
205+
}
206+
}
207+
`;
208+
194209
const CREATE_METAOBJECT = `
195210
mutation metaobjectCreate($metaobject: MetaobjectCreateInput!) {
196211
metaobjectCreate(metaobject: $metaobject) {
@@ -429,6 +444,7 @@ export default {
429444
CREATE_PAGE,
430445
CREATE_PRODUCT,
431446
CREATE_PRODUCT_VARIANTS,
447+
SET_METAFIELD,
432448
CREATE_METAFIELD,
433449
CREATE_METAOBJECT,
434450
UPDATE_METAFIELD,

components/shopify/shopify.app.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ export default {
427427
createMetafield(variables) {
428428
return this._makeGraphQlRequest(mutations.CREATE_METAFIELD, variables);
429429
},
430+
setMetafield(variables) {
431+
return this._makeGraphQlRequest(mutations.SET_METAFIELD, variables);
432+
},
430433
updateMetafield(variables) {
431434
return this._makeGraphQlRequest(mutations.UPDATE_METAFIELD, variables);
432435
},

components/shopify/sources/collection-updated/collection-updated.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
return "COLLECTIONS_UPDATE";
1616
},
1717
generateMeta(collection) {
18-
const ts = Date.parse(collection.updatedAt);
18+
const ts = Date.parse(collection.updated_at);
1919
return {
2020
id: `${collection.id}${ts}`,
2121
summary: `Collection Updated: ${collection.title}`,

0 commit comments

Comments
 (0)