@foxtware/mineral 1.0.5 → 1.0.7

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.
Files changed (87) hide show
  1. package/.creds.yml.sample +1 -0
  2. package/_build_scripts/createNewFunction.js +23 -41
  3. package/api/UTILS.md +1 -1
  4. package/api/bleckmann/bleckmannPickticketGet.js +4 -2
  5. package/api/github/githubActionsSecretCreateOrUpdate.js +139 -0
  6. package/api/github/githubActionsSecretPublicKeyGet.js +59 -0
  7. package/api/google/googlecalendarEventCreate.js +2 -0
  8. package/api/linear/linearTeamGet.js +6 -3
  9. package/api/shopify/shopify.constants.js +25 -0
  10. package/api/shopify/shopify.utils.js +41 -6
  11. package/api/shopify/shopifyInventoryQuantitiesSet.js +164 -0
  12. package/api/shopify/shopifyMutationDo.js +12 -6
  13. package/api/shopify/shopifyShopGet.js +68 -0
  14. package/api/shopify/shopifyStorefrontArticleGet.js +86 -0
  15. package/api/shopify/shopifyStorefrontArticlesGet.js +67 -0
  16. package/api/shopify/shopifyStorefrontBlogGet.js +110 -0
  17. package/api/shopify/shopifyStorefrontBlogsGet.js +66 -0
  18. package/api/shopify/shopifyStorefrontCartAttributesUpdate.js +87 -0
  19. package/api/shopify/shopifyStorefrontCartBuyerIdentityUpdate.js +87 -0
  20. package/api/shopify/shopifyStorefrontCartCreate.js +83 -0
  21. package/api/shopify/shopifyStorefrontCartDeliveryAddressesAdd.js +87 -0
  22. package/api/shopify/shopifyStorefrontCartDeliveryAddressesRemove.js +87 -0
  23. package/api/shopify/shopifyStorefrontCartDeliveryAddressesReplace.js +87 -0
  24. package/api/shopify/shopifyStorefrontCartDeliveryAddressesUpdate.js +87 -0
  25. package/api/shopify/shopifyStorefrontCartDiscountCodesUpdate.js +87 -0
  26. package/api/shopify/shopifyStorefrontCartGet.js +100 -0
  27. package/api/shopify/shopifyStorefrontCartGiftCardCodesAdd.js +87 -0
  28. package/api/shopify/shopifyStorefrontCartGiftCardCodesRemove.js +87 -0
  29. package/api/shopify/shopifyStorefrontCartGiftCardCodesUpdate.js +87 -0
  30. package/api/shopify/shopifyStorefrontCartLinesAdd.js +87 -0
  31. package/api/shopify/shopifyStorefrontCartLinesRemove.js +87 -0
  32. package/api/shopify/shopifyStorefrontCartLinesUpdate.js +87 -0
  33. package/api/shopify/shopifyStorefrontCartMetafieldDelete.js +69 -0
  34. package/api/shopify/shopifyStorefrontCartMetafieldsSet.js +80 -0
  35. package/api/shopify/shopifyStorefrontCartNoteUpdate.js +87 -0
  36. package/api/shopify/shopifyStorefrontCartSelectedDeliveryOptionsUpdate.js +87 -0
  37. package/api/shopify/shopifyStorefrontCollectionGet.js +92 -0
  38. package/api/shopify/shopifyStorefrontCollectionsGet.js +66 -0
  39. package/api/shopify/shopifyStorefrontCustomerAccessTokenCreate.js +75 -0
  40. package/api/shopify/shopifyStorefrontCustomerAccessTokenCreateWithMultipass.js +72 -0
  41. package/api/shopify/shopifyStorefrontCustomerAccessTokenDelete.js +67 -0
  42. package/api/shopify/shopifyStorefrontCustomerAccessTokenRenew.js +72 -0
  43. package/api/shopify/shopifyStorefrontCustomerActivate.js +98 -0
  44. package/api/shopify/shopifyStorefrontCustomerActivateByUrl.js +91 -0
  45. package/api/shopify/shopifyStorefrontCustomerAddressCreate.js +94 -0
  46. package/api/shopify/shopifyStorefrontCustomerAddressDelete.js +78 -0
  47. package/api/shopify/shopifyStorefrontCustomerAddressUpdate.js +101 -0
  48. package/api/shopify/shopifyStorefrontCustomerCreate.js +79 -0
  49. package/api/shopify/shopifyStorefrontCustomerDefaultAddressUpdate.js +89 -0
  50. package/api/shopify/shopifyStorefrontCustomerGet.js +92 -0
  51. package/api/shopify/shopifyStorefrontCustomerRecover.js +64 -0
  52. package/api/shopify/shopifyStorefrontCustomerReset.js +98 -0
  53. package/api/shopify/shopifyStorefrontCustomerResetByUrl.js +91 -0
  54. package/api/shopify/shopifyStorefrontCustomerUpdate.js +93 -0
  55. package/api/shopify/shopifyStorefrontGet.js +233 -0
  56. package/api/shopify/shopifyStorefrontLocalizationGet.js +98 -0
  57. package/api/shopify/shopifyStorefrontLocationsGet.js +70 -0
  58. package/api/shopify/shopifyStorefrontMenuGet.js +93 -0
  59. package/api/shopify/shopifyStorefrontMetaobjectGet.js +126 -0
  60. package/api/shopify/shopifyStorefrontMetaobjectsGet.js +73 -0
  61. package/api/shopify/shopifyStorefrontMutationDo.js +103 -0
  62. package/api/shopify/shopifyStorefrontNodeGet.js +90 -0
  63. package/api/shopify/shopifyStorefrontNodesGet.js +86 -0
  64. package/api/shopify/shopifyStorefrontPageGet.js +93 -0
  65. package/api/shopify/shopifyStorefrontPagesGet.js +66 -0
  66. package/api/shopify/shopifyStorefrontPaymentSettingsGet.js +79 -0
  67. package/api/shopify/shopifyStorefrontPredictiveSearch.js +138 -0
  68. package/api/shopify/shopifyStorefrontProductGet.js +94 -0
  69. package/api/shopify/shopifyStorefrontProductRecommendationsGet.js +112 -0
  70. package/api/shopify/shopifyStorefrontProductTagsGet.js +80 -0
  71. package/api/shopify/shopifyStorefrontProductTypesGet.js +80 -0
  72. package/api/shopify/shopifyStorefrontProductsGet.js +76 -0
  73. package/api/shopify/shopifyStorefrontPublicApiVersionsGet.js +75 -0
  74. package/api/shopify/shopifyStorefrontSearch.js +8 -2
  75. package/api/shopify/shopifyStorefrontShopGet.js +81 -0
  76. package/api/shopify/shopifyStorefrontShopPayPaymentRequestSessionCreate.js +91 -0
  77. package/api/shopify/shopifyStorefrontShopPayPaymentRequestSessionSubmit.js +95 -0
  78. package/api/shopify/shopifyStorefrontSitemapGet.js +98 -0
  79. package/api/shopify/shopifyStorefrontUrlRedirectsGet.js +67 -0
  80. package/api/slack/docs.md +4 -0
  81. package/api/slack/slack.utils.js +36 -2
  82. package/api/slack/slackMessagePost.js +11 -3
  83. package/api/slack/slackMessagesSearch.js +81 -0
  84. package/api/utils.js +44 -8
  85. package/hosting/deployFromHostingYml.js +9 -21
  86. package/package.json +3 -1
  87. package/server.utils.js +24 -15
@@ -0,0 +1,91 @@
1
+ // https://shopify.dev/docs/api/storefront/latest/mutations/customerResetByUrl
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden } = require('../utils');
5
+ const { shopifyStorefrontMutationDo } = require('./shopifyStorefrontMutationDo');
6
+
7
+ const defaultReturnCustomerAttrs = `
8
+ id
9
+ email
10
+ firstName
11
+ lastName
12
+ displayName
13
+ phone
14
+ `.trim();
15
+
16
+ const defaultReturnAccessTokenAttrs = `
17
+ accessToken
18
+ expiresAt
19
+ `.trim();
20
+
21
+ const argsWarden = new ArgsWarden([
22
+ ['credsPayload', credsValidator],
23
+ ['resetUrl'],
24
+ ['password'],
25
+ ]);
26
+
27
+ const shopifyStorefrontCustomerResetByUrl = async (
28
+ credsPayload,
29
+ resetUrl,
30
+ password,
31
+ {
32
+ apiVersion,
33
+ returnCustomerAttrs = defaultReturnCustomerAttrs,
34
+ returnAccessTokenAttrs = defaultReturnAccessTokenAttrs,
35
+ inContext,
36
+ fetchClient,
37
+ } = {},
38
+ ) => {
39
+
40
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
41
+ credsPayload,
42
+ resetUrl,
43
+ password,
44
+ });
45
+ if (rejectResponse) {
46
+ return rejectResponse;
47
+ }
48
+
49
+ return shopifyStorefrontMutationDo(
50
+ credsPayload,
51
+ 'customerResetByUrl',
52
+ {
53
+ mutationVariables: {
54
+ resetUrl: {
55
+ type: 'URL!',
56
+ value: resetUrl,
57
+ },
58
+ password: {
59
+ type: 'String!',
60
+ value: password,
61
+ },
62
+ },
63
+ returnSchema: `
64
+ customer { ${ returnCustomerAttrs } }
65
+ customerAccessToken { ${ returnAccessTokenAttrs } }
66
+ `.trim(),
67
+ apiVersion,
68
+ inContext,
69
+ ...fetchClient ? { fetchClient } : {},
70
+ },
71
+ );
72
+ };
73
+
74
+ const funcApiConfig = {
75
+ argsWarden,
76
+ };
77
+
78
+ module.exports = {
79
+ shopifyStorefrontCustomerResetByUrl,
80
+ funcApiConfig,
81
+ };
82
+
83
+ /*
84
+ curl -X POST "http://localhost:8000/shopifyStorefrontCustomerResetByUrl" \
85
+ -H "Content-Type: application/json" \
86
+ -d '{
87
+ "credsPayload": { "credsPath": "shopify.au" },
88
+ "resetUrl": "https://example.com/account/reset/xxx/yyy",
89
+ "password": "NewSecurePass123"
90
+ }'
91
+ */
@@ -0,0 +1,93 @@
1
+ // https://shopify.dev/docs/api/storefront/latest/mutations/customerUpdate
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden } = require('../utils');
5
+ const { shopifyStorefrontMutationDo } = require('./shopifyStorefrontMutationDo');
6
+
7
+ const defaultReturnCustomerAttrs = `
8
+ id
9
+ email
10
+ firstName
11
+ lastName
12
+ displayName
13
+ phone
14
+ `.trim();
15
+
16
+ const defaultReturnAccessTokenAttrs = `
17
+ accessToken
18
+ expiresAt
19
+ `.trim();
20
+
21
+ const argsWarden = new ArgsWarden([
22
+ ['credsPayload', credsValidator],
23
+ ['customerAccessToken'],
24
+ ['customer'],
25
+ ]);
26
+
27
+ const shopifyStorefrontCustomerUpdate = async (
28
+ credsPayload,
29
+ customerAccessToken,
30
+ customer,
31
+ {
32
+ apiVersion,
33
+ returnCustomerAttrs = defaultReturnCustomerAttrs,
34
+ returnAccessTokenAttrs = defaultReturnAccessTokenAttrs,
35
+ inContext,
36
+ fetchClient,
37
+ } = {},
38
+ ) => {
39
+
40
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
41
+ credsPayload,
42
+ customerAccessToken,
43
+ customer,
44
+ });
45
+ if (rejectResponse) {
46
+ return rejectResponse;
47
+ }
48
+
49
+ return shopifyStorefrontMutationDo(
50
+ credsPayload,
51
+ 'customerUpdate',
52
+ {
53
+ mutationVariables: {
54
+ customerAccessToken: {
55
+ type: 'String!',
56
+ value: customerAccessToken,
57
+ },
58
+ customer: {
59
+ type: 'CustomerUpdateInput!',
60
+ value: customer,
61
+ },
62
+ },
63
+ returnSchema: `
64
+ customer { ${ returnCustomerAttrs } }
65
+ customerAccessToken { ${ returnAccessTokenAttrs } }
66
+ `.trim(),
67
+ apiVersion,
68
+ inContext,
69
+ ...fetchClient ? { fetchClient } : {},
70
+ },
71
+ );
72
+ };
73
+
74
+ const funcApiConfig = {
75
+ argsWarden,
76
+ };
77
+
78
+ module.exports = {
79
+ shopifyStorefrontCustomerUpdate,
80
+ funcApiConfig,
81
+ };
82
+
83
+ /*
84
+ curl -X POST "http://localhost:8000/shopifyStorefrontCustomerUpdate" \
85
+ -H "Content-Type: application/json" \
86
+ -d '{
87
+ "credsPayload": { "credsPath": "shopify.au" },
88
+ "customerAccessToken": "shcat_xxx",
89
+ "customer": {
90
+ "firstName": "Jane"
91
+ }
92
+ }'
93
+ */
@@ -0,0 +1,233 @@
1
+ const { Getter, capitaliseString, ArgsWarden, getWithLocalCachedFile } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const {
4
+ shopifyStorefrontClient,
5
+ buildInContextDirective,
6
+ } = require('./shopify.utils');
7
+ const { MAX_PER_PAGE } = require('./shopify.constants');
8
+
9
+ const argsWarden = new ArgsWarden([
10
+ ['credsPayload', credsValidator],
11
+ ['resource'],
12
+ ]);
13
+
14
+ const shopifyStorefrontGetPacket = async (
15
+ credsPayload,
16
+ resource,
17
+ resources,
18
+ attrs,
19
+ {
20
+ apiVersion,
21
+ perPage = MAX_PER_PAGE,
22
+ cursor,
23
+ queries,
24
+ reverse,
25
+ sortKey,
26
+ type,
27
+ inContext,
28
+ sortKeyType,
29
+ fetchClient = shopifyStorefrontClient,
30
+ } = {},
31
+ ) => {
32
+
33
+ const Resource = capitaliseString(resource);
34
+ const Resources = capitaliseString(resources);
35
+ const resolvedSortKeyType = sortKeyType || `${ Resource }SortKeys`;
36
+
37
+ const queryTypeDeclaration = [
38
+ '$first: Int!',
39
+ '$cursor: String',
40
+ ...queries ? ['$query: String'] : [],
41
+ ...reverse !== undefined ? ['$reverse: Boolean'] : [],
42
+ ...sortKey ? [`$sortKey: ${ resolvedSortKeyType }`] : [],
43
+ ...type ? ['$type: String!'] : [],
44
+ ].join('\n');
45
+
46
+ const queryVariableDeclaration = [
47
+ 'first: $first',
48
+ 'after: $cursor',
49
+ ...queries ? ['query: $query'] : [],
50
+ ...reverse !== undefined ? ['reverse: $reverse'] : [],
51
+ ...sortKey ? ['sortKey: $sortKey'] : [],
52
+ ...type ? ['type: $type'] : [],
53
+ ].join('\n');
54
+
55
+ const variables = {
56
+ first: perPage,
57
+ cursor,
58
+ ...reverse !== undefined && { reverse },
59
+ ...queries && { query: queries.join(' AND ') },
60
+ ...sortKey && { sortKey },
61
+ ...type && { type },
62
+ };
63
+
64
+ const inContextDirective = buildInContextDirective(inContext);
65
+
66
+ return fetchClient.fetch({
67
+ requestPayload: {
68
+ method: 'post',
69
+ body: {
70
+ query: `
71
+ query StorefrontGet${ Resources } (
72
+ ${ queryTypeDeclaration }
73
+ )${ inContextDirective } {
74
+ ${ resources }(
75
+ ${ queryVariableDeclaration }
76
+ ) {
77
+ edges {
78
+ node {
79
+ ${ attrs }
80
+ }
81
+ }
82
+ pageInfo {
83
+ hasNextPage
84
+ endCursor
85
+ }
86
+ }
87
+ }
88
+ `,
89
+ variables,
90
+ },
91
+ },
92
+ context: {
93
+ credsPayload,
94
+ apiVersion,
95
+ resultPath: `data.${ resources }`,
96
+ },
97
+ });
98
+ };
99
+
100
+ const shopifyStorefrontGetPaginator = async (currentParams, response) => {
101
+ const { args, options } = currentParams;
102
+ const { ok, meta } = response;
103
+ const { pageInfo } = meta || {};
104
+ const { hasNextPage, endCursor } = pageInfo || {};
105
+
106
+ if (!ok) {
107
+ return [true];
108
+ }
109
+
110
+ if (!hasNextPage) {
111
+ return [true];
112
+ }
113
+
114
+ return [false, {
115
+ args,
116
+ options: {
117
+ ...options,
118
+ cursor: endCursor,
119
+ },
120
+ }];
121
+ };
122
+
123
+ const shopifyStorefrontGetDigester = (response) => {
124
+ const { ok, data } = response;
125
+
126
+ if (!ok) {
127
+ return null;
128
+ }
129
+
130
+ return data;
131
+ };
132
+
133
+ const shopifyStorefrontGet = async (
134
+ returnGetter,
135
+
136
+ credsPayload,
137
+ resource,
138
+ {
139
+ apiVersion,
140
+ perPage = MAX_PER_PAGE,
141
+ cursor,
142
+ attrs = 'id',
143
+ queries,
144
+ reverse,
145
+ sortKey,
146
+ type,
147
+ inContext,
148
+ sortKeyType,
149
+ resources = `${ resource }s`,
150
+ useLocalCachedFile,
151
+ fetchClient = shopifyStorefrontClient,
152
+ ...getterOptions
153
+ } = {},
154
+ ) => {
155
+
156
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
157
+ credsPayload,
158
+ resource,
159
+ });
160
+ if (rejectResponse) {
161
+ return rejectResponse;
162
+ }
163
+
164
+ const getter = new Getter(
165
+ {
166
+ args: [
167
+ credsPayload,
168
+ resource,
169
+ resources,
170
+ attrs,
171
+ ],
172
+ options: {
173
+ apiVersion,
174
+ perPage,
175
+ cursor,
176
+ queries,
177
+ reverse,
178
+ sortKey,
179
+ type,
180
+ inContext,
181
+ sortKeyType,
182
+ fetchClient,
183
+ },
184
+ },
185
+ {
186
+ func: shopifyStorefrontGetPacket,
187
+ digester: shopifyStorefrontGetDigester,
188
+ paginator: shopifyStorefrontGetPaginator,
189
+ ...getterOptions,
190
+ },
191
+ );
192
+
193
+ if (returnGetter) {
194
+ return getter;
195
+ }
196
+
197
+ return getWithLocalCachedFile(
198
+ useLocalCachedFile,
199
+ async () => {
200
+ const data = await getter.run({ returnAll: true });
201
+
202
+ return {
203
+ ok: true,
204
+ data,
205
+ };
206
+ },
207
+ );
208
+ };
209
+
210
+ const funcApiConfig = {
211
+ argsWarden,
212
+ };
213
+
214
+ module.exports = {
215
+ shopifyStorefrontGet: (...args) => shopifyStorefrontGet(false, ...args),
216
+ shopifyStorefrontGetter: (...args) => shopifyStorefrontGet(true, ...args),
217
+ shopifyStorefrontGetPaginator,
218
+ shopifyStorefrontGetDigester,
219
+ funcApiConfig,
220
+ };
221
+
222
+ /*
223
+ curl -X POST "http://localhost:8000/shopifyStorefrontGet" \
224
+ -H "Content-Type: application/json" \
225
+ -d '{
226
+ "credsPayload": { "credsPath": "shopify.au" },
227
+ "resource": "product",
228
+ "options": {
229
+ "limit": 5,
230
+ "attrs": "id handle title"
231
+ }
232
+ }'
233
+ */
@@ -0,0 +1,98 @@
1
+ // https://shopify.dev/docs/api/storefront/latest/queries/localization
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden } = require('../utils');
5
+ const {
6
+ shopifyStorefrontClient,
7
+ buildInContextDirective,
8
+ } = require('./shopify.utils');
9
+
10
+ const defaultAttrs = `
11
+ availableCountries {
12
+ isoCode
13
+ name
14
+ currency { isoCode symbol }
15
+ }
16
+ availableLanguages {
17
+ isoCode
18
+ name
19
+ endonymName
20
+ }
21
+ country {
22
+ isoCode
23
+ name
24
+ currency { isoCode symbol }
25
+ }
26
+ language {
27
+ isoCode
28
+ name
29
+ }
30
+ market {
31
+ id
32
+ handle
33
+ }
34
+ `.trim();
35
+
36
+ const argsWarden = new ArgsWarden([
37
+ ['credsPayload', credsValidator],
38
+ ]);
39
+
40
+ const shopifyStorefrontLocalizationGet = async (
41
+ credsPayload,
42
+ {
43
+ apiVersion,
44
+ attrs = defaultAttrs,
45
+ inContext,
46
+ fetchClient = shopifyStorefrontClient,
47
+ } = {},
48
+ ) => {
49
+
50
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
51
+ credsPayload,
52
+ });
53
+ if (rejectResponse) {
54
+ return rejectResponse;
55
+ }
56
+
57
+ const inContextDirective = buildInContextDirective(inContext);
58
+
59
+ return fetchClient.fetch({
60
+ requestPayload: {
61
+ method: 'post',
62
+ body: {
63
+ query: `
64
+ query StorefrontLocalization${ inContextDirective } {
65
+ localization {
66
+ ${ attrs }
67
+ }
68
+ }
69
+ `,
70
+ },
71
+ },
72
+ context: {
73
+ credsPayload,
74
+ apiVersion,
75
+ resultPath: 'data.localization',
76
+ },
77
+ });
78
+ };
79
+
80
+ const funcApiConfig = {
81
+ argsWarden,
82
+ };
83
+
84
+ module.exports = {
85
+ shopifyStorefrontLocalizationGet,
86
+ funcApiConfig,
87
+ };
88
+
89
+ /*
90
+ curl -X POST "http://localhost:8000/shopifyStorefrontLocalizationGet" \
91
+ -H "Content-Type: application/json" \
92
+ -d '{
93
+ "credsPayload": { "credsPath": "shopify.au" },
94
+ "options": {
95
+ "inContext": { "country": "AU", "language": "EN" }
96
+ }
97
+ }'
98
+ */
@@ -0,0 +1,70 @@
1
+ // https://shopify.dev/docs/api/storefront/latest/queries/locations
2
+
3
+ const { ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { shopifyStorefrontGet, shopifyStorefrontGetter } = require('./shopifyStorefrontGet');
6
+
7
+ const defaultAttrs = `
8
+ id
9
+ name
10
+ address {
11
+ address1
12
+ city
13
+ country
14
+ }
15
+ `.trim();
16
+
17
+ const argsWarden = new ArgsWarden([
18
+ ['credsPayload', credsValidator],
19
+ ]);
20
+
21
+ const shopifyStorefrontLocationsGetInner = async (
22
+ returnGetter,
23
+ credsPayload,
24
+ {
25
+ attrs = defaultAttrs,
26
+ ...getterOptions
27
+ } = {},
28
+ ) => {
29
+
30
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
31
+ credsPayload,
32
+ });
33
+ if (rejectResponse) {
34
+ return rejectResponse;
35
+ }
36
+
37
+ const getterArgs = [
38
+ credsPayload,
39
+ 'location',
40
+ {
41
+ attrs,
42
+ ...getterOptions,
43
+ },
44
+ ];
45
+
46
+ return returnGetter
47
+ ? shopifyStorefrontGetter(...getterArgs)
48
+ : shopifyStorefrontGet(...getterArgs);
49
+ };
50
+
51
+ const funcApiConfig = {
52
+ argsWarden,
53
+ };
54
+
55
+ module.exports = {
56
+ shopifyStorefrontLocationsGet: (...args) => shopifyStorefrontLocationsGetInner(false, ...args),
57
+ shopifyStorefrontLocationsGetter: (...args) => shopifyStorefrontLocationsGetInner(true, ...args),
58
+ funcApiConfig,
59
+ };
60
+
61
+ /*
62
+ curl -X POST "http://localhost:8000/shopifyStorefrontLocationsGet" \
63
+ -H "Content-Type: application/json" \
64
+ -d '{
65
+ "credsPayload": { "credsPath": "shopify.au" },
66
+ "options": {
67
+ "limit": 10
68
+ }
69
+ }'
70
+ */
@@ -0,0 +1,93 @@
1
+ // https://shopify.dev/docs/api/storefront/latest/queries/menu
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden } = require('../utils');
5
+ const {
6
+ shopifyStorefrontClient,
7
+ buildInContextDirective,
8
+ } = require('./shopify.utils');
9
+
10
+ const defaultAttrs = `
11
+ id
12
+ handle
13
+ title
14
+ itemsCount
15
+ items {
16
+ id
17
+ title
18
+ url
19
+ type
20
+ items {
21
+ id
22
+ title
23
+ url
24
+ type
25
+ }
26
+ }
27
+ `.trim();
28
+
29
+ const argsWarden = new ArgsWarden([
30
+ ['credsPayload', credsValidator],
31
+ ['handle'],
32
+ ]);
33
+
34
+ const shopifyStorefrontMenuGet = async (
35
+ credsPayload,
36
+ handle,
37
+ {
38
+ apiVersion,
39
+ attrs = defaultAttrs,
40
+ inContext,
41
+ fetchClient = shopifyStorefrontClient,
42
+ } = {},
43
+ ) => {
44
+
45
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
46
+ credsPayload,
47
+ handle,
48
+ });
49
+ if (rejectResponse) {
50
+ return rejectResponse;
51
+ }
52
+
53
+ const inContextDirective = buildInContextDirective(inContext);
54
+
55
+ return fetchClient.fetch({
56
+ requestPayload: {
57
+ method: 'post',
58
+ body: {
59
+ query: `
60
+ query StorefrontMenu ($handle: String!)${ inContextDirective } {
61
+ menu(handle: $handle) {
62
+ ${ attrs }
63
+ }
64
+ }
65
+ `,
66
+ variables: { handle },
67
+ },
68
+ },
69
+ context: {
70
+ credsPayload,
71
+ apiVersion,
72
+ resultPath: 'data.menu',
73
+ },
74
+ });
75
+ };
76
+
77
+ const funcApiConfig = {
78
+ argsWarden,
79
+ };
80
+
81
+ module.exports = {
82
+ shopifyStorefrontMenuGet,
83
+ funcApiConfig,
84
+ };
85
+
86
+ /*
87
+ curl -X POST "http://localhost:8000/shopifyStorefrontMenuGet" \
88
+ -H "Content-Type: application/json" \
89
+ -d '{
90
+ "credsPayload": { "credsPath": "shopify.au" },
91
+ "handle": "main-menu"
92
+ }'
93
+ */