@foxtware/mineral 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.creds.yml.sample +16 -7
- package/AGENTS.md +4 -0
- package/_build_scripts/createNewFunction.js +10 -5
- package/_build_scripts/publish.js +15 -1
- package/api/backblaze/backblaze.constants.js +11 -0
- package/api/backblaze/backblaze.utils.js +322 -0
- package/api/backblaze/backblazeBucketsGet.js +68 -0
- package/api/backblaze/backblazeFileDelete.js +62 -0
- package/api/backblaze/backblazeFileHide.js +62 -0
- package/api/backblaze/backblazeFileUpload.js +142 -0
- package/api/backblaze/backblazeFilesGet.js +85 -0
- package/api/backblaze/backblazeGet.js +139 -0
- package/api/backblaze/docs.md +6 -0
- package/api/etsy/etsyListingUpdate.js +1 -1
- package/api/gorgias/gorgias.constants.js +8 -0
- package/api/gorgias/gorgias.utils.js +46 -0
- package/api/gorgias/gorgiasAccountGet.js +51 -0
- package/api/gorgias/gorgiasCustomerGet.js +70 -0
- package/api/gorgias/gorgiasCustomersGet.js +56 -0
- package/api/gorgias/gorgiasGet.js +150 -0
- package/api/gorgias/gorgiasGetSingle.js +26 -0
- package/api/gorgias/gorgiasMessagesGet.js +56 -0
- package/api/gorgias/gorgiasTagsGet.js +52 -0
- package/api/gorgias/gorgiasTicketCreate.js +66 -0
- package/api/gorgias/gorgiasTicketGet.js +70 -0
- package/api/gorgias/gorgiasTicketMessageCreate.js +65 -0
- package/api/gorgias/gorgiasTicketMessagesGet.js +66 -0
- package/api/gorgias/gorgiasTicketUpdate.js +62 -0
- package/api/gorgias/gorgiasTicketsGet.js +58 -0
- package/api/gorgias/gorgiasUsersGet.js +52 -0
- package/api/gorgias/gorgiasViewItemsGet.js +57 -0
- package/api/gorgias/gorgiasViewsGet.js +72 -0
- package/api/linear/docs.md +6 -0
- package/api/linear/linear.constants.js +3 -0
- package/api/linear/linear.utils.js +59 -0
- package/api/linear/linearAttachmentCreate.js +77 -0
- package/api/linear/linearAttachmentDelete.js +68 -0
- package/api/linear/linearCommentCreate.js +77 -0
- package/api/linear/linearCommentDelete.js +68 -0
- package/api/linear/linearCommentGet.js +77 -0
- package/api/linear/linearCommentUpdate.js +87 -0
- package/api/linear/linearCommentsGet.js +70 -0
- package/api/linear/linearCyclesGet.js +67 -0
- package/api/linear/linearGet.js +218 -0
- package/api/linear/linearIssueAddLabel.js +77 -0
- package/api/linear/linearIssueArchive.js +74 -0
- package/api/linear/linearIssueCreate.js +94 -0
- package/api/linear/linearIssueDelete.js +74 -0
- package/api/linear/linearIssueGet.js +87 -0
- package/api/linear/linearIssueLabelCreate.js +81 -0
- package/api/linear/linearIssueLabelsGet.js +66 -0
- package/api/linear/linearIssueRemoveLabel.js +77 -0
- package/api/linear/linearIssueUpdate.js +96 -0
- package/api/linear/linearIssuesGet.js +39 -63
- package/api/linear/linearOrganizationGet.js +64 -0
- package/api/linear/linearProjectCreate.js +92 -0
- package/api/linear/linearProjectGet.js +74 -0
- package/api/linear/linearProjectUpdate.js +80 -0
- package/api/linear/linearProjectsGet.js +71 -0
- package/api/linear/linearTeamGet.js +71 -0
- package/api/linear/linearTeamsGet.js +66 -0
- package/api/linear/linearUserGet.js +72 -0
- package/api/linear/linearUsersGet.js +71 -0
- package/api/linear/linearViewerGet.js +65 -0
- package/api/linear/linearWebhookCreate.js +77 -0
- package/api/linear/linearWebhookDelete.js +68 -0
- package/api/linear/linearWebhooksGet.js +67 -0
- package/api/linear/linearWorkflowStatesGet.js +73 -0
- package/api/peoplevox/peoplevox.utils.js +25 -0
- package/api/pipe17/pipe17.utils.js +7 -20
- package/api/pipe17/pipe17ArrivalGet.js +1 -1
- package/api/pipe17/pipe17FulfillmentGet.js +1 -1
- package/api/pipe17/pipe17InventoryItemGet.js +1 -1
- package/api/pipe17/pipe17JobGet.js +11 -24
- package/api/pipe17/pipe17LocationGet.js +1 -1
- package/api/pipe17/pipe17OrderGet.js +1 -1
- package/api/pipe17/pipe17ProductGet.js +1 -1
- package/api/pipe17/pipe17PurchaseGet.js +1 -1
- package/api/pipe17/pipe17ReceiptGet.js +1 -1
- package/api/pipe17/pipe17ReturnGet.js +1 -1
- package/api/shopify/shopifyFileCreate.js +107 -0
- package/api/shopify/shopifyFulfillmentCreate.js +180 -0
- package/api/shopify/shopifyFulfillmentTrackingInfoUpdate.js +92 -0
- package/api/shopify/shopifyMetafieldDefinitionCreate.js +2 -0
- package/api/shopify/shopifyMetafieldDefinitionGet.js +108 -0
- package/api/shopify/shopifyMetafieldDefinitionPropagate.js +93 -86
- package/api/shopify/shopifyOrderFulfill.js +322 -0
- package/api/shopify/shopifyThemeFileGet.js +112 -0
- package/api/shopify/shopifyThemeFilePropagate.js +410 -0
- package/api/shopify/shopifyThemeFilesUpsert.js +88 -0
- package/api/starshipit/starshipit.utils.js +29 -3
- package/api/starshipit/starshipitOrderGet.js +2 -10
- package/api/starshipit/starshipitOrdersGet.js +96 -0
- package/api/utils.js +96 -5
- package/package.json +1 -1
- package/server.utils.js +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/fulfillmentCreate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { actionSingleOrMultiple, everyIfArray, ArgsWarden, valueProvided } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const fulfillmentInputValidator = (fulfillmentInput) => {
|
|
8
|
+
const { lineItemsByFulfillmentOrder } = fulfillmentInput || {};
|
|
9
|
+
if (!Array.isArray(lineItemsByFulfillmentOrder) || lineItemsByFulfillmentOrder.length === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return lineItemsByFulfillmentOrder.every((item) => {
|
|
14
|
+
if (!item?.fulfillmentOrderId) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (item.fulfillmentOrderLineItems) {
|
|
19
|
+
return item.fulfillmentOrderLineItems.every((lineItem) => {
|
|
20
|
+
return lineItem?.id && valueProvided(lineItem?.quantity);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const argsWarden = new ArgsWarden([
|
|
29
|
+
['credsPayload', credsValidator],
|
|
30
|
+
['fulfillmentInput', (i) => everyIfArray(fulfillmentInputValidator, i)],
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const defaultReturnFulfillmentAttrs = `
|
|
34
|
+
id
|
|
35
|
+
status
|
|
36
|
+
trackingInfo {
|
|
37
|
+
number
|
|
38
|
+
company
|
|
39
|
+
url
|
|
40
|
+
}
|
|
41
|
+
`.trim();
|
|
42
|
+
|
|
43
|
+
const shopifyFulfillmentCreateSingle = async (
|
|
44
|
+
credsPayload,
|
|
45
|
+
fulfillmentInput,
|
|
46
|
+
{
|
|
47
|
+
apiVersion,
|
|
48
|
+
message,
|
|
49
|
+
returnFulfillmentAttrs = defaultReturnFulfillmentAttrs,
|
|
50
|
+
} = {},
|
|
51
|
+
) => {
|
|
52
|
+
|
|
53
|
+
return shopifyMutationDo(
|
|
54
|
+
credsPayload,
|
|
55
|
+
'fulfillmentCreate',
|
|
56
|
+
{
|
|
57
|
+
mutationVariables: {
|
|
58
|
+
fulfillment: {
|
|
59
|
+
type: 'FulfillmentInput!',
|
|
60
|
+
value: fulfillmentInput,
|
|
61
|
+
},
|
|
62
|
+
...(valueProvided(message) && {
|
|
63
|
+
message: {
|
|
64
|
+
type: 'String',
|
|
65
|
+
value: message,
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
returnSchema: `
|
|
70
|
+
fulfillment { ${ returnFulfillmentAttrs } }
|
|
71
|
+
`.trim(),
|
|
72
|
+
apiVersion,
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const shopifyFulfillmentCreate = async (
|
|
78
|
+
credsPayload,
|
|
79
|
+
fulfillmentInput,
|
|
80
|
+
{
|
|
81
|
+
queueRunOptions,
|
|
82
|
+
apiVersion,
|
|
83
|
+
message,
|
|
84
|
+
returnFulfillmentAttrs = defaultReturnFulfillmentAttrs,
|
|
85
|
+
} = {},
|
|
86
|
+
) => {
|
|
87
|
+
|
|
88
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
89
|
+
credsPayload,
|
|
90
|
+
fulfillmentInput,
|
|
91
|
+
});
|
|
92
|
+
if (rejectResponse) {
|
|
93
|
+
return rejectResponse;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return actionSingleOrMultiple(
|
|
97
|
+
fulfillmentInput,
|
|
98
|
+
shopifyFulfillmentCreateSingle,
|
|
99
|
+
(fulfillmentInputItem) => ({
|
|
100
|
+
args: [
|
|
101
|
+
credsPayload,
|
|
102
|
+
fulfillmentInputItem,
|
|
103
|
+
{ apiVersion, message, returnFulfillmentAttrs },
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
{
|
|
107
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const funcApiConfig = {
|
|
113
|
+
argsWarden,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
module.exports = {
|
|
117
|
+
shopifyFulfillmentCreate,
|
|
118
|
+
funcApiConfig,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
curl -X POST "http://localhost:8000/shopifyFulfillmentCreate" \
|
|
123
|
+
-H "Content-Type: application/json" \
|
|
124
|
+
-d '{
|
|
125
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
126
|
+
"fulfillmentInput": {
|
|
127
|
+
"lineItemsByFulfillmentOrder": [
|
|
128
|
+
{
|
|
129
|
+
"fulfillmentOrderId": "gid://shopify/FulfillmentOrder/1234567890"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
"notifyCustomer": true,
|
|
133
|
+
"trackingInfo": {
|
|
134
|
+
"number": "1234567890",
|
|
135
|
+
"company": "Australia Post",
|
|
136
|
+
"url": "https://auspost.com.au/mypost/track/details/1234567890"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}'
|
|
140
|
+
|
|
141
|
+
curl -X POST "http://localhost:8000/shopifyFulfillmentCreate" \
|
|
142
|
+
-H "Content-Type: application/json" \
|
|
143
|
+
-d '{
|
|
144
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
145
|
+
"fulfillmentInput": [
|
|
146
|
+
{
|
|
147
|
+
"lineItemsByFulfillmentOrder": [
|
|
148
|
+
{
|
|
149
|
+
"fulfillmentOrderId": "gid://shopify/FulfillmentOrder/1234567890"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"notifyCustomer": true,
|
|
153
|
+
"trackingInfo": {
|
|
154
|
+
"number": "1234567890",
|
|
155
|
+
"company": "Australia Post"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"lineItemsByFulfillmentOrder": [
|
|
160
|
+
{
|
|
161
|
+
"fulfillmentOrderId": "gid://shopify/FulfillmentOrder/0987654321",
|
|
162
|
+
"fulfillmentOrderLineItems": [
|
|
163
|
+
{
|
|
164
|
+
"id": "gid://shopify/FulfillmentOrderLineItem/9876543210",
|
|
165
|
+
"quantity": 1
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"notifyCustomer": false,
|
|
171
|
+
"originAddress": {
|
|
172
|
+
"countryCode": "AU"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"options": {
|
|
177
|
+
"message": "Partial fulfillment"
|
|
178
|
+
}
|
|
179
|
+
}'
|
|
180
|
+
*/
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/fulfillmentTrackingInfoUpdate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const defaultReturnSchema = `
|
|
8
|
+
fulfillment {
|
|
9
|
+
id
|
|
10
|
+
status
|
|
11
|
+
trackingInfo {
|
|
12
|
+
company
|
|
13
|
+
number
|
|
14
|
+
url
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const argsWarden = new ArgsWarden([
|
|
20
|
+
['credsPayload', credsValidator],
|
|
21
|
+
['fulfillmentId'],
|
|
22
|
+
['trackingInfoPayload'],
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const shopifyFulfillmentTrackingInfoUpdate = async (
|
|
26
|
+
credsPayload,
|
|
27
|
+
fulfillmentId,
|
|
28
|
+
trackingInfoPayload,
|
|
29
|
+
{
|
|
30
|
+
apiVersion,
|
|
31
|
+
returnSchema = defaultReturnSchema,
|
|
32
|
+
notifyCustomer = false,
|
|
33
|
+
} = {},
|
|
34
|
+
) => {
|
|
35
|
+
|
|
36
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
37
|
+
credsPayload,
|
|
38
|
+
fulfillmentId,
|
|
39
|
+
trackingInfoPayload,
|
|
40
|
+
});
|
|
41
|
+
if (rejectResponse) {
|
|
42
|
+
return rejectResponse;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return shopifyMutationDo(
|
|
46
|
+
credsPayload,
|
|
47
|
+
'fulfillmentTrackingInfoUpdate',
|
|
48
|
+
{
|
|
49
|
+
mutationVariables: {
|
|
50
|
+
fulfillmentId: {
|
|
51
|
+
type: 'ID!',
|
|
52
|
+
value: `gid://shopify/Fulfillment/${ fulfillmentId }`,
|
|
53
|
+
},
|
|
54
|
+
trackingInfoInput: {
|
|
55
|
+
type: 'FulfillmentTrackingInput!',
|
|
56
|
+
value: trackingInfoPayload,
|
|
57
|
+
},
|
|
58
|
+
...notifyCustomer && {
|
|
59
|
+
notifyCustomer: {
|
|
60
|
+
type: 'Boolean',
|
|
61
|
+
value: notifyCustomer,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
returnSchema,
|
|
66
|
+
apiVersion,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const funcApiConfig = {
|
|
72
|
+
argsWarden,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
shopifyFulfillmentTrackingInfoUpdate,
|
|
77
|
+
funcApiConfig,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
curl -X POST "http://localhost:8000/shopifyFulfillmentTrackingInfoUpdate" \
|
|
82
|
+
-H "Content-Type: application/json" \
|
|
83
|
+
-d '{
|
|
84
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
85
|
+
"fulfillmentId": "104188477512",
|
|
86
|
+
"trackingInfoPayload": {
|
|
87
|
+
"company": "FastEx",
|
|
88
|
+
"number": "123456789",
|
|
89
|
+
"url": "https://track.example.com/123456789"
|
|
90
|
+
}
|
|
91
|
+
}'
|
|
92
|
+
*/
|
|
@@ -39,6 +39,7 @@ const shopifyMetafieldDefinitionCreate = async (
|
|
|
39
39
|
pin,
|
|
40
40
|
useAsCollectionCondition,
|
|
41
41
|
validations,
|
|
42
|
+
capabilities,
|
|
42
43
|
returnSchema = defaultReturnSchema,
|
|
43
44
|
} = {},
|
|
44
45
|
) => {
|
|
@@ -73,6 +74,7 @@ const shopifyMetafieldDefinitionCreate = async (
|
|
|
73
74
|
...(pin && { pin }),
|
|
74
75
|
...(useAsCollectionCondition && { useAsCollectionCondition }),
|
|
75
76
|
...(validations && { validations }),
|
|
77
|
+
...(capabilities && { capabilities }),
|
|
76
78
|
},
|
|
77
79
|
},
|
|
78
80
|
},
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/metafieldDefinition
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden, objHasAny } = require('../utils');
|
|
5
|
+
const { shopifyClient } = require('./shopify.utils');
|
|
6
|
+
|
|
7
|
+
const metafieldDefinitionIdentifierValidator = (metafieldDefinitionIdentifier) => {
|
|
8
|
+
return objHasAny(metafieldDefinitionIdentifier, [
|
|
9
|
+
'ownerType',
|
|
10
|
+
'namespace',
|
|
11
|
+
'key',
|
|
12
|
+
]);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const argsWarden = new ArgsWarden([
|
|
16
|
+
['credsPayload', credsValidator],
|
|
17
|
+
['metafieldDefinitionIdentifier', metafieldDefinitionIdentifierValidator],
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const defaultAttrs = `
|
|
21
|
+
name
|
|
22
|
+
namespace
|
|
23
|
+
key
|
|
24
|
+
description
|
|
25
|
+
ownerType
|
|
26
|
+
pinnedPosition
|
|
27
|
+
type {
|
|
28
|
+
name
|
|
29
|
+
}
|
|
30
|
+
validations {
|
|
31
|
+
name
|
|
32
|
+
value
|
|
33
|
+
}
|
|
34
|
+
capabilities {
|
|
35
|
+
adminFilterable {
|
|
36
|
+
enabled
|
|
37
|
+
}
|
|
38
|
+
smartCollectionCondition {
|
|
39
|
+
enabled
|
|
40
|
+
}
|
|
41
|
+
uniqueValues {
|
|
42
|
+
enabled
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`.trim();
|
|
46
|
+
|
|
47
|
+
const shopifyMetafieldDefinitionGet = async (
|
|
48
|
+
credsPayload,
|
|
49
|
+
metafieldDefinitionIdentifier,
|
|
50
|
+
{
|
|
51
|
+
apiVersion,
|
|
52
|
+
attrs = defaultAttrs,
|
|
53
|
+
} = {},
|
|
54
|
+
) => {
|
|
55
|
+
|
|
56
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
57
|
+
credsPayload,
|
|
58
|
+
metafieldDefinitionIdentifier,
|
|
59
|
+
});
|
|
60
|
+
if (rejectResponse) {
|
|
61
|
+
return rejectResponse;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return shopifyClient.fetch({
|
|
65
|
+
requestPayload: {
|
|
66
|
+
method: 'post',
|
|
67
|
+
body: {
|
|
68
|
+
query: `
|
|
69
|
+
query GetMetafieldDefinition($identifier: MetafieldDefinitionIdentifierInput!) {
|
|
70
|
+
metafieldDefinition(identifier: $identifier) {
|
|
71
|
+
${ attrs }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
variables: {
|
|
76
|
+
identifier: metafieldDefinitionIdentifier,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
context: {
|
|
81
|
+
credsPayload,
|
|
82
|
+
apiVersion,
|
|
83
|
+
resultPath: 'data.metafieldDefinition',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const funcApiConfig = {
|
|
89
|
+
argsWarden,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
shopifyMetafieldDefinitionGet,
|
|
94
|
+
funcApiConfig,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
curl -X POST "http://localhost:8000/shopifyMetafieldDefinitionGet" \
|
|
99
|
+
-H "Content-Type: application/json" \
|
|
100
|
+
-d '{
|
|
101
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
102
|
+
"metafieldDefinitionIdentifier": {
|
|
103
|
+
"ownerType": "PRODUCT",
|
|
104
|
+
"namespace": "custom",
|
|
105
|
+
"key": "outfit_builder_image"
|
|
106
|
+
}
|
|
107
|
+
}'
|
|
108
|
+
*/
|
|
@@ -2,36 +2,9 @@
|
|
|
2
2
|
// https://shopify.dev/docs/api/admin-graphql/latest/queries/metafieldDefinition
|
|
3
3
|
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
|
-
const { ArgsWarden,
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
const sourceMetafieldDefinitionAttrs = `
|
|
10
|
-
name
|
|
11
|
-
namespace
|
|
12
|
-
key
|
|
13
|
-
description
|
|
14
|
-
ownerType
|
|
15
|
-
pinnedPosition
|
|
16
|
-
type {
|
|
17
|
-
name
|
|
18
|
-
}
|
|
19
|
-
validations {
|
|
20
|
-
name
|
|
21
|
-
value
|
|
22
|
-
}
|
|
23
|
-
capabilities {
|
|
24
|
-
adminFilterable {
|
|
25
|
-
enabled
|
|
26
|
-
}
|
|
27
|
-
smartCollectionCondition {
|
|
28
|
-
enabled
|
|
29
|
-
}
|
|
30
|
-
uniqueValues {
|
|
31
|
-
enabled
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`.trim();
|
|
5
|
+
const { ArgsWarden, actionSingleOrMultiple, everyIfArray, objHasAny } = require('../utils');
|
|
6
|
+
const { shopifyMetafieldDefinitionGet } = require('./shopifyMetafieldDefinitionGet');
|
|
7
|
+
const { shopifyMetafieldDefinitionCreate } = require('./shopifyMetafieldDefinitionCreate');
|
|
35
8
|
|
|
36
9
|
const defaultReturnCreatedDefinitionAttrs = 'id name namespace key ownerType type { name }';
|
|
37
10
|
|
|
@@ -45,8 +18,8 @@ const metafieldDefinitionIdentifierValidator = (metafieldDefinitionIdentifier) =
|
|
|
45
18
|
|
|
46
19
|
const argsWarden = new ArgsWarden([
|
|
47
20
|
['fromStoreCredsPayload', credsValidator],
|
|
48
|
-
['toStoreCredsPayload', credsValidator],
|
|
49
|
-
['metafieldDefinitionIdentifier', metafieldDefinitionIdentifierValidator],
|
|
21
|
+
['toStoreCredsPayload', (i) => everyIfArray(credsValidator, i)],
|
|
22
|
+
['metafieldDefinitionIdentifier', (i) => everyIfArray(metafieldDefinitionIdentifierValidator, i)],
|
|
50
23
|
]);
|
|
51
24
|
|
|
52
25
|
const metafieldDefinitionInputFromDefinition = (sourceDefinition) => {
|
|
@@ -96,38 +69,7 @@ const metafieldDefinitionInputFromDefinition = (sourceDefinition) => {
|
|
|
96
69
|
return definitionInput;
|
|
97
70
|
};
|
|
98
71
|
|
|
99
|
-
const
|
|
100
|
-
fromStoreCredsPayload,
|
|
101
|
-
metafieldDefinitionIdentifier,
|
|
102
|
-
{
|
|
103
|
-
apiVersion,
|
|
104
|
-
} = {},
|
|
105
|
-
) => {
|
|
106
|
-
const creds = await credsFromPayload(fromStoreCredsPayload);
|
|
107
|
-
|
|
108
|
-
return shopifyClient.fetch({
|
|
109
|
-
method: 'post',
|
|
110
|
-
body: {
|
|
111
|
-
query: `
|
|
112
|
-
query GetMetafieldDefinition($identifier: MetafieldDefinitionIdentifierInput!) {
|
|
113
|
-
metafieldDefinition(identifier: $identifier) {
|
|
114
|
-
${ sourceMetafieldDefinitionAttrs }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
`,
|
|
118
|
-
variables: {
|
|
119
|
-
identifier: metafieldDefinitionIdentifier,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
context: {
|
|
123
|
-
creds,
|
|
124
|
-
apiVersion,
|
|
125
|
-
resultPath: 'data.metafieldDefinition',
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const shopifyMetafieldDefinitionPropagate = async (
|
|
72
|
+
const shopifyMetafieldDefinitionPropagateSingle = async (
|
|
131
73
|
fromStoreCredsPayload,
|
|
132
74
|
toStoreCredsPayload,
|
|
133
75
|
metafieldDefinitionIdentifier,
|
|
@@ -137,16 +79,7 @@ const shopifyMetafieldDefinitionPropagate = async (
|
|
|
137
79
|
} = {},
|
|
138
80
|
) => {
|
|
139
81
|
|
|
140
|
-
const
|
|
141
|
-
fromStoreCredsPayload,
|
|
142
|
-
toStoreCredsPayload,
|
|
143
|
-
metafieldDefinitionIdentifier,
|
|
144
|
-
});
|
|
145
|
-
if (rejectResponse) {
|
|
146
|
-
return rejectResponse;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const sourceResponse = await fetchSourceMetafieldDefinition(
|
|
82
|
+
const sourceResponse = await shopifyMetafieldDefinitionGet(
|
|
150
83
|
fromStoreCredsPayload,
|
|
151
84
|
metafieldDefinitionIdentifier,
|
|
152
85
|
{ apiVersion },
|
|
@@ -167,22 +100,96 @@ const shopifyMetafieldDefinitionPropagate = async (
|
|
|
167
100
|
};
|
|
168
101
|
}
|
|
169
102
|
|
|
103
|
+
const existingResponse = await shopifyMetafieldDefinitionGet(
|
|
104
|
+
toStoreCredsPayload,
|
|
105
|
+
metafieldDefinitionIdentifier,
|
|
106
|
+
{
|
|
107
|
+
apiVersion,
|
|
108
|
+
attrs: returnCreatedDefinitionAttrs,
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (!existingResponse.ok) {
|
|
113
|
+
return existingResponse;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (existingResponse.data) {
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
data: existingResponse.data,
|
|
120
|
+
meta: {
|
|
121
|
+
alreadyExisted: true,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
170
126
|
const definitionInput = metafieldDefinitionInputFromDefinition(sourceResponse.data);
|
|
171
127
|
|
|
172
|
-
|
|
128
|
+
const {
|
|
129
|
+
ownerType,
|
|
130
|
+
namespace,
|
|
131
|
+
key,
|
|
132
|
+
name,
|
|
133
|
+
type,
|
|
134
|
+
description,
|
|
135
|
+
pin,
|
|
136
|
+
validations,
|
|
137
|
+
capabilities,
|
|
138
|
+
} = definitionInput;
|
|
139
|
+
|
|
140
|
+
return shopifyMetafieldDefinitionCreate(
|
|
173
141
|
toStoreCredsPayload,
|
|
174
|
-
|
|
142
|
+
ownerType,
|
|
143
|
+
namespace,
|
|
144
|
+
key,
|
|
145
|
+
name,
|
|
146
|
+
type,
|
|
175
147
|
{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
},
|
|
148
|
+
apiVersion,
|
|
149
|
+
...(description && { description }),
|
|
150
|
+
...(pin != null && { pin }),
|
|
151
|
+
...(validations && { validations }),
|
|
152
|
+
...(capabilities && { capabilities }),
|
|
182
153
|
returnSchema: `
|
|
183
154
|
createdDefinition { ${ returnCreatedDefinitionAttrs } }
|
|
184
155
|
`.trim(),
|
|
185
|
-
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const shopifyMetafieldDefinitionPropagate = async (
|
|
161
|
+
fromStoreCredsPayload,
|
|
162
|
+
toStoreCredsPayload,
|
|
163
|
+
metafieldDefinitionIdentifier,
|
|
164
|
+
{
|
|
165
|
+
queueRunOptions,
|
|
166
|
+
apiVersion,
|
|
167
|
+
returnCreatedDefinitionAttrs = defaultReturnCreatedDefinitionAttrs,
|
|
168
|
+
} = {},
|
|
169
|
+
) => {
|
|
170
|
+
|
|
171
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
172
|
+
fromStoreCredsPayload,
|
|
173
|
+
toStoreCredsPayload,
|
|
174
|
+
metafieldDefinitionIdentifier,
|
|
175
|
+
});
|
|
176
|
+
if (rejectResponse) {
|
|
177
|
+
return rejectResponse;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return actionSingleOrMultiple(
|
|
181
|
+
[toStoreCredsPayload, metafieldDefinitionIdentifier],
|
|
182
|
+
shopifyMetafieldDefinitionPropagateSingle,
|
|
183
|
+
(toStoreCredsPayloadItem, metafieldDefinitionIdentifierItem) => ({
|
|
184
|
+
args: [
|
|
185
|
+
fromStoreCredsPayload,
|
|
186
|
+
toStoreCredsPayloadItem,
|
|
187
|
+
metafieldDefinitionIdentifierItem,
|
|
188
|
+
{ apiVersion, returnCreatedDefinitionAttrs },
|
|
189
|
+
],
|
|
190
|
+
}),
|
|
191
|
+
{
|
|
192
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
186
193
|
},
|
|
187
194
|
);
|
|
188
195
|
};
|
|
@@ -201,11 +208,11 @@ curl -X POST "http://localhost:8000/shopifyMetafieldDefinitionPropagate" \
|
|
|
201
208
|
-H "Content-Type: application/json" \
|
|
202
209
|
-d '{
|
|
203
210
|
"fromStoreCredsPayload": { "credsPath": "shopify.au" },
|
|
204
|
-
"toStoreCredsPayload": { "credsPath": "shopify.us" },
|
|
211
|
+
"toStoreCredsPayload": [{ "credsPath": "shopify.us" }, { "credsPath": "shopify.uk" }],
|
|
205
212
|
"metafieldDefinitionIdentifier": {
|
|
206
213
|
"ownerType": "PRODUCT",
|
|
207
|
-
"namespace": "
|
|
208
|
-
"key": "
|
|
214
|
+
"namespace": "merch",
|
|
215
|
+
"key": "associations"
|
|
209
216
|
}
|
|
210
217
|
}'
|
|
211
218
|
*/
|