@foxtware/mineral 0.1.28 → 0.1.29

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 (63) hide show
  1. package/.creds.yml.sample +14 -2
  2. package/AGENTS.md +7 -0
  3. package/_build_scripts/createNewFunction.js +26 -3
  4. package/api/dropbox/docs.md +7 -0
  5. package/api/dropbox/dropbox.constants.js +10 -0
  6. package/api/dropbox/dropbox.utils.js +67 -0
  7. package/api/dropbox/dropboxAccountGet.js +64 -0
  8. package/api/dropbox/dropboxFileCopy.js +67 -0
  9. package/api/dropbox/dropboxFileDelete.js +89 -0
  10. package/api/dropbox/dropboxFileDownload.js +139 -0
  11. package/api/dropbox/dropboxFileMetadataGet.js +100 -0
  12. package/api/dropbox/dropboxFileMove.js +67 -0
  13. package/api/dropbox/dropboxFileUpload.js +129 -0
  14. package/api/dropbox/dropboxFolderCreate.js +68 -0
  15. package/api/dropbox/dropboxFolderList.js +66 -0
  16. package/api/dropbox/dropboxGet.js +158 -0
  17. package/api/dropbox/dropboxSearch.js +161 -0
  18. package/api/dropbox/dropboxSharedLinkCreate.js +68 -0
  19. package/api/dropbox/dropboxSpaceUsageGet.js +55 -0
  20. package/api/dropbox/dropboxTemporaryLinkGet.js +75 -0
  21. package/api/google/docs.md +1 -0
  22. package/api/google/google.constants.js +1 -0
  23. package/api/google/google.utils.js +21 -0
  24. package/api/google/googleanalyticsMetadataGet.js +62 -0
  25. package/api/google/googleanalyticsRealtimeReportRun.js +103 -0
  26. package/api/google/googleanalyticsReportRun.js +114 -0
  27. package/api/shopify/shopify.utils.js +53 -4
  28. package/api/shopify/shopifyMetaobjectCreate.js +13 -6
  29. package/api/shopify/shopifyMetaobjectDelete.js +90 -0
  30. package/api/shopify/shopifyMetaobjectGet.js +80 -0
  31. package/api/shopify/shopifyMetaobjectUpdate.js +108 -0
  32. package/api/shopify/shopifyStorefrontSearch.js +158 -0
  33. package/api/spotify/docs.md +8 -0
  34. package/api/spotify/spotify.constants.js +12 -0
  35. package/api/spotify/spotify.utils.js +106 -0
  36. package/api/spotify/spotifyAlbumGet.js +76 -0
  37. package/api/spotify/spotifyAlbumTracksGet.js +49 -0
  38. package/api/spotify/spotifyArtistAlbumsGet.js +55 -0
  39. package/api/spotify/spotifyArtistGet.js +71 -0
  40. package/api/spotify/spotifyArtistTopTracksGet.js +56 -0
  41. package/api/spotify/spotifyGet.js +171 -0
  42. package/api/spotify/spotifyMeGet.js +48 -0
  43. package/api/spotify/spotifyPlayerCurrentlyPlayingGet.js +62 -0
  44. package/api/spotify/spotifyPlayerDevicesGet.js +51 -0
  45. package/api/spotify/spotifyPlayerGet.js +63 -0
  46. package/api/spotify/spotifyPlayerNext.js +55 -0
  47. package/api/spotify/spotifyPlayerPause.js +55 -0
  48. package/api/spotify/spotifyPlayerPlay.js +70 -0
  49. package/api/spotify/spotifyPlayerPrevious.js +55 -0
  50. package/api/spotify/spotifyPlaylistCreate.js +63 -0
  51. package/api/spotify/spotifyPlaylistGet.js +91 -0
  52. package/api/spotify/spotifyPlaylistItemsAdd.js +61 -0
  53. package/api/spotify/spotifyPlaylistItemsGet.js +58 -0
  54. package/api/spotify/spotifyPlaylistItemsRemove.js +67 -0
  55. package/api/spotify/spotifyPlaylistUpdate.js +64 -0
  56. package/api/spotify/spotifyPlaylistsGet.js +47 -0
  57. package/api/spotify/spotifySavedTracksGet.js +46 -0
  58. package/api/spotify/spotifySavedTracksRemove.js +59 -0
  59. package/api/spotify/spotifySavedTracksSave.js +59 -0
  60. package/api/spotify/spotifySearch.js +174 -0
  61. package/api/spotify/spotifyTrackGet.js +76 -0
  62. package/package.json +1 -1
  63. package/server.js +3 -1
@@ -0,0 +1,55 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#users-get_space_usage
2
+
3
+ const { ArgsWarden, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ]);
10
+
11
+ const dropboxSpaceUsageGet = async (
12
+ credsPayload,
13
+ {
14
+ fetchClient = dropboxClient,
15
+ } = {},
16
+ ) => {
17
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
18
+ credsPayload,
19
+ });
20
+ if (rejectResponse) {
21
+ return rejectResponse;
22
+ }
23
+
24
+ const response = await fetchClient.fetch({
25
+ context: { credsPayload },
26
+ requestPayload: {
27
+ method: 'post',
28
+ url: '/users/get_space_usage',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ },
32
+ body: 'null',
33
+ },
34
+ });
35
+
36
+ const { ok, data, error } = response;
37
+ if (!ok) {
38
+ logDeep({ error });
39
+ return { ok: false, error };
40
+ }
41
+
42
+ return {
43
+ ok: true,
44
+ data,
45
+ };
46
+ };
47
+
48
+ const funcApiConfig = {
49
+ argsWarden,
50
+ };
51
+
52
+ module.exports = {
53
+ dropboxSpaceUsageGet,
54
+ funcApiConfig,
55
+ };
@@ -0,0 +1,75 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link
2
+
3
+ const { ArgsWarden, actionSingleOrMultiple, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['path'],
10
+ ]);
11
+
12
+ const dropboxTemporaryLinkGetSingle = async (
13
+ credsPayload,
14
+ path,
15
+ {
16
+ fetchClient = dropboxClient,
17
+ } = {},
18
+ ) => {
19
+ const response = await fetchClient.fetch({
20
+ context: { credsPayload },
21
+ requestPayload: {
22
+ method: 'post',
23
+ url: '/files/get_temporary_link',
24
+ body: { path },
25
+ },
26
+ });
27
+
28
+ const { ok, data, error } = response;
29
+ if (!ok) {
30
+ logDeep({ error });
31
+ return { ok: false, error };
32
+ }
33
+
34
+ return {
35
+ ok: true,
36
+ data,
37
+ };
38
+ };
39
+
40
+ const dropboxTemporaryLinkGet = async (
41
+ credsPayload,
42
+ path,
43
+ {
44
+ queueRunOptions,
45
+ fetchClient,
46
+ } = {},
47
+ ) => {
48
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
49
+ credsPayload,
50
+ path,
51
+ });
52
+ if (rejectResponse) {
53
+ return rejectResponse;
54
+ }
55
+
56
+ return actionSingleOrMultiple(
57
+ path,
58
+ dropboxTemporaryLinkGetSingle,
59
+ (pathItem) => ({
60
+ args: [credsPayload, pathItem, { fetchClient }],
61
+ }),
62
+ {
63
+ ...(queueRunOptions ? { queueRunOptions } : {}),
64
+ },
65
+ );
66
+ };
67
+
68
+ const funcApiConfig = {
69
+ argsWarden,
70
+ };
71
+
72
+ module.exports = {
73
+ dropboxTemporaryLinkGet,
74
+ funcApiConfig,
75
+ };
@@ -5,3 +5,4 @@ Service account auth via `SERVICE_ACCOUNT_JSON` on the `google` creds path. Uses
5
5
  - [Sheets API](https://developers.google.com/workspace/sheets/api/reference/rest)
6
6
  - [Drive API](https://developers.google.com/workspace/drive/api/reference/rest/v3)
7
7
  - [Calendar API](https://developers.google.com/workspace/calendar/api/v3/reference)
8
+ - [Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1/rest)
@@ -2,6 +2,7 @@ const GOOGLE_SCOPES = {
2
2
  sheets: ['https://www.googleapis.com/auth/spreadsheets'],
3
3
  drive: ['https://www.googleapis.com/auth/drive'],
4
4
  calendar: ['https://www.googleapis.com/auth/calendar'],
5
+ analytics: ['https://www.googleapis.com/auth/analytics'],
5
6
  };
6
7
 
7
8
  module.exports = {
@@ -108,6 +108,26 @@ const getGoogleCalendar = async (
108
108
  };
109
109
  };
110
110
 
111
+ const getGoogleAnalyticsData = async (
112
+ credsPayload,
113
+ {
114
+ subject,
115
+ } = {},
116
+ ) => {
117
+ const { auth, error } = await getGoogleAuth(credsPayload, {
118
+ scopes: GOOGLE_SCOPES.analytics,
119
+ subject,
120
+ });
121
+
122
+ if (error) {
123
+ return { error };
124
+ }
125
+
126
+ return {
127
+ client: google.analyticsdata({ version: 'v1beta', auth }),
128
+ };
129
+ };
130
+
111
131
  const googleApiCall = async (promiseFn) => {
112
132
  try {
113
133
  const response = await promiseFn();
@@ -132,6 +152,7 @@ module.exports = {
132
152
  getGoogleSheets,
133
153
  getGoogleDrive,
134
154
  getGoogleCalendar,
155
+ getGoogleAnalyticsData,
135
156
  googleApiCall,
136
157
  invalidCredsResponse,
137
158
  };
@@ -0,0 +1,62 @@
1
+ // https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
2
+
3
+ const { ArgsWarden, objHasAny } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { getGoogleAnalyticsData, googleApiCall } = require('../google/google.utils');
6
+
7
+ const propertyIdentifierValidator = (propertyIdentifier) => {
8
+ return objHasAny(propertyIdentifier, ['propertyId', 'property']);
9
+ };
10
+
11
+ const argsWarden = new ArgsWarden([
12
+ ['credsPayload', credsValidator],
13
+ ['propertyIdentifier', propertyIdentifierValidator],
14
+ ]);
15
+
16
+ const googleanalyticsMetadataGet = async (
17
+ credsPayload,
18
+ propertyIdentifier,
19
+ {
20
+ subject,
21
+ } = {},
22
+ ) => {
23
+
24
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
25
+ credsPayload,
26
+ propertyIdentifier,
27
+ });
28
+ if (rejectResponse) {
29
+ return rejectResponse;
30
+ }
31
+
32
+ const { propertyId, property } = propertyIdentifier;
33
+ const propertyName = property ?? `properties/${ propertyId }`;
34
+
35
+ const { client, error } = await getGoogleAnalyticsData(credsPayload, { subject });
36
+
37
+ if (error) {
38
+ return error;
39
+ }
40
+
41
+ return googleApiCall(() => client.properties.getMetadata({
42
+ name: `${ propertyName }/metadata`,
43
+ }));
44
+ };
45
+
46
+ const funcApiConfig = {
47
+ argsWarden,
48
+ };
49
+
50
+ module.exports = {
51
+ googleanalyticsMetadataGet,
52
+ funcApiConfig,
53
+ };
54
+
55
+ /*
56
+ curl -X POST "http://localhost:8000/googleanalyticsMetadataGet" \
57
+ -H "Content-Type: application/json" \
58
+ -d '{
59
+ "credsPayload": { "credsPath": "google" },
60
+ "propertyIdentifier": { "propertyId": "402247571" }
61
+ }'
62
+ */
@@ -0,0 +1,103 @@
1
+ // https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runRealtimeReport
2
+
3
+ const { ArgsWarden, objHasAny } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { getGoogleAnalyticsData, googleApiCall } = require('../google/google.utils');
6
+
7
+ const propertyIdentifierValidator = (propertyIdentifier) => {
8
+ return objHasAny(propertyIdentifier, ['propertyId', 'property']);
9
+ };
10
+
11
+ const argsWarden = new ArgsWarden([
12
+ ['credsPayload', credsValidator],
13
+ ['propertyIdentifier', propertyIdentifierValidator],
14
+ ]);
15
+
16
+ const formatDimensions = (dimensions) => {
17
+ if (!dimensions) {
18
+ return undefined;
19
+ }
20
+ return dimensions.map((dim) => (typeof dim === 'string' ? { name: dim } : dim));
21
+ };
22
+
23
+ const formatMetrics = (metrics) => {
24
+ if (!metrics) {
25
+ return undefined;
26
+ }
27
+ return metrics.map((metric) => (typeof metric === 'string' ? { name: metric } : metric));
28
+ };
29
+
30
+ const googleanalyticsRealtimeReportRun = async (
31
+ credsPayload,
32
+ propertyIdentifier,
33
+ {
34
+ subject,
35
+ dimensions,
36
+ metrics,
37
+ dimensionFilter,
38
+ metricFilter,
39
+ limit,
40
+ metricAggregations,
41
+ orderBys,
42
+ returnPropertyQuota,
43
+ minuteRanges,
44
+ } = {},
45
+ ) => {
46
+
47
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
48
+ credsPayload,
49
+ propertyIdentifier,
50
+ });
51
+ if (rejectResponse) {
52
+ return rejectResponse;
53
+ }
54
+
55
+ const { propertyId, property } = propertyIdentifier;
56
+ const propertyName = property ?? `properties/${ propertyId }`;
57
+
58
+ const { client, error } = await getGoogleAnalyticsData(credsPayload, { subject });
59
+
60
+ if (error) {
61
+ return error;
62
+ }
63
+
64
+ const formattedDimensions = formatDimensions(dimensions);
65
+ const formattedMetrics = formatMetrics(metrics);
66
+
67
+ return googleApiCall(() => client.properties.runRealtimeReport({
68
+ property: propertyName,
69
+ requestBody: {
70
+ ...formattedDimensions && { dimensions: formattedDimensions },
71
+ ...formattedMetrics && { metrics: formattedMetrics },
72
+ ...dimensionFilter && { dimensionFilter },
73
+ ...metricFilter && { metricFilter },
74
+ ...limit !== undefined && { limit },
75
+ ...metricAggregations && { metricAggregations },
76
+ ...orderBys && { orderBys },
77
+ ...returnPropertyQuota !== undefined && { returnPropertyQuota },
78
+ ...minuteRanges && { minuteRanges },
79
+ },
80
+ }));
81
+ };
82
+
83
+ const funcApiConfig = {
84
+ argsWarden,
85
+ };
86
+
87
+ module.exports = {
88
+ googleanalyticsRealtimeReportRun,
89
+ funcApiConfig,
90
+ };
91
+
92
+ /*
93
+ curl -X POST "http://localhost:8000/googleanalyticsRealtimeReportRun" \
94
+ -H "Content-Type: application/json" \
95
+ -d '{
96
+ "credsPayload": { "credsPath": "google" },
97
+ "propertyIdentifier": { "propertyId": "402247571" },
98
+ "options": {
99
+ "dimensions": ["country"],
100
+ "metrics": ["activeUsers"]
101
+ }
102
+ }'
103
+ */
@@ -0,0 +1,114 @@
1
+ // https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
2
+
3
+ const { ArgsWarden, objHasAny } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { getGoogleAnalyticsData, googleApiCall } = require('../google/google.utils');
6
+
7
+ const propertyIdentifierValidator = (propertyIdentifier) => {
8
+ return objHasAny(propertyIdentifier, ['propertyId', 'property']);
9
+ };
10
+
11
+ const argsWarden = new ArgsWarden([
12
+ ['credsPayload', credsValidator],
13
+ ['propertyIdentifier', propertyIdentifierValidator],
14
+ ]);
15
+
16
+ const formatDimensions = (dimensions) => {
17
+ if (!dimensions) {
18
+ return undefined;
19
+ }
20
+ return dimensions.map((dim) => (typeof dim === 'string' ? { name: dim } : dim));
21
+ };
22
+
23
+ const formatMetrics = (metrics) => {
24
+ if (!metrics) {
25
+ return undefined;
26
+ }
27
+ return metrics.map((metric) => (typeof metric === 'string' ? { name: metric } : metric));
28
+ };
29
+
30
+ const googleanalyticsReportRun = async (
31
+ credsPayload,
32
+ propertyIdentifier,
33
+ {
34
+ subject,
35
+ dateRanges,
36
+ dimensions,
37
+ metrics,
38
+ dimensionFilter,
39
+ metricFilter,
40
+ offset,
41
+ limit,
42
+ metricAggregations,
43
+ orderBys,
44
+ currencyCode,
45
+ cohortSpec,
46
+ keepEmptyRows,
47
+ returnPropertyQuota,
48
+ comparisons,
49
+ } = {},
50
+ ) => {
51
+
52
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
53
+ credsPayload,
54
+ propertyIdentifier,
55
+ });
56
+ if (rejectResponse) {
57
+ return rejectResponse;
58
+ }
59
+
60
+ const { propertyId, property } = propertyIdentifier;
61
+ const propertyName = property ?? `properties/${ propertyId }`;
62
+
63
+ const { client, error } = await getGoogleAnalyticsData(credsPayload, { subject });
64
+
65
+ if (error) {
66
+ return error;
67
+ }
68
+
69
+ const formattedDimensions = formatDimensions(dimensions);
70
+ const formattedMetrics = formatMetrics(metrics);
71
+
72
+ return googleApiCall(() => client.properties.runReport({
73
+ property: propertyName,
74
+ requestBody: {
75
+ ...dateRanges && { dateRanges },
76
+ ...formattedDimensions && { dimensions: formattedDimensions },
77
+ ...formattedMetrics && { metrics: formattedMetrics },
78
+ ...dimensionFilter && { dimensionFilter },
79
+ ...metricFilter && { metricFilter },
80
+ ...offset !== undefined && { offset },
81
+ ...limit !== undefined && { limit },
82
+ ...metricAggregations && { metricAggregations },
83
+ ...orderBys && { orderBys },
84
+ ...currencyCode && { currencyCode },
85
+ ...cohortSpec && { cohortSpec },
86
+ ...keepEmptyRows !== undefined && { keepEmptyRows },
87
+ ...returnPropertyQuota !== undefined && { returnPropertyQuota },
88
+ ...comparisons && { comparisons },
89
+ },
90
+ }));
91
+ };
92
+
93
+ const funcApiConfig = {
94
+ argsWarden,
95
+ };
96
+
97
+ module.exports = {
98
+ googleanalyticsReportRun,
99
+ funcApiConfig,
100
+ };
101
+
102
+ /*
103
+ curl -X POST "http://localhost:8000/googleanalyticsReportRun" \
104
+ -H "Content-Type: application/json" \
105
+ -d '{
106
+ "credsPayload": { "credsPath": "google" },
107
+ "propertyIdentifier": { "propertyId": "402247571" },
108
+ "options": {
109
+ "dateRanges": [{ "startDate": "30daysAgo", "endDate": "today" }],
110
+ "dimensions": ["date"],
111
+ "metrics": ["activeUsers", "sessions"]
112
+ }
113
+ }'
114
+ */
@@ -76,6 +76,31 @@ const useUrlAndAuthHeaders = async (state) => {
76
76
  };
77
77
  };
78
78
 
79
+ const useStorefrontUrlAndAuthHeaders = async (state) => {
80
+ const { requestPayload, context } = state;
81
+ const {
82
+ apiVersion = DEFAULT_API_VERSION,
83
+ creds,
84
+ } = context;
85
+ const {
86
+ STORE_HANDLE,
87
+ STOREFRONT_API_KEY,
88
+ } = creds;
89
+
90
+ const baseUrl = `https://${ STORE_HANDLE }.myshopify.com/api/${ apiVersion }/graphql.json`;
91
+
92
+ return {
93
+ requestPayload: {
94
+ ...requestPayload,
95
+ url: appendUrlToBase(baseUrl, requestPayload.url),
96
+ headers: {
97
+ 'X-Shopify-Storefront-Access-Token': STOREFRONT_API_KEY,
98
+ ...requestPayload.headers,
99
+ },
100
+ },
101
+ };
102
+ };
103
+
79
104
  const movePageInfoToMeta = async (state) => {
80
105
  const { response, context } = state;
81
106
  const { resultPath } = context ?? {};
@@ -86,15 +111,23 @@ const movePageInfoToMeta = async (state) => {
86
111
 
87
112
  const connection = objectDigNodeAtPath(response.data, pathAsArray(resultPath));
88
113
 
89
- if (!connection?.pageInfo) {
114
+ if (!connection || typeof connection !== 'object') {
115
+ return {};
116
+ }
117
+
118
+ const meta = {
119
+ ...connection.pageInfo ? { pageInfo: connection.pageInfo } : {},
120
+ ...connection.totalCount !== undefined ? { totalCount: connection.totalCount } : {},
121
+ ...connection.productFilters !== undefined ? { productFilters: connection.productFilters } : {},
122
+ };
123
+
124
+ if (!Object.keys(meta).length) {
90
125
  return {};
91
126
  }
92
127
 
93
128
  return {
94
129
  response: {
95
- meta: {
96
- pageInfo: connection.pageInfo,
97
- },
130
+ meta,
98
131
  },
99
132
  };
100
133
  };
@@ -188,7 +221,23 @@ const shopifyClient = new FetchClient({
188
221
  ],
189
222
  });
190
223
 
224
+ const shopifyStorefrontClient = new FetchClient({
225
+ pipeline: [
226
+ resolveCreds,
227
+ useStorefrontUrlAndAuthHeaders,
228
+ 'fetch',
229
+ movePageInfoToMeta,
230
+ fetchClientCommonSteps.stripEdgesAndNodes,
231
+ fetchClientCommonSteps.collapseDataWithOneValue,
232
+ fetchClientCommonSteps.exitEarlyOnNotOk,
233
+ fetchClientCommonSteps.exitEarlyOnGraphqlErrors,
234
+ fetchClientCommonSteps.digToPath,
235
+ handleMutationUserErrors,
236
+ ],
237
+ });
238
+
191
239
  module.exports = {
192
240
  parseShopifyJsonl,
193
241
  shopifyClient,
242
+ shopifyStorefrontClient,
194
243
  };
@@ -11,7 +11,7 @@ const argsWarden = new ArgsWarden([
11
11
  ['metaobjectInput', metaobjectInputValidator],
12
12
  ]);
13
13
 
14
- const defaultReturnMetaobjectAttrs = 'id handle type updatedAt';
14
+ const defaultReturnMetaobjectAttrs = 'id handle type updatedAt capabilities { publishable { status } }';
15
15
 
16
16
  const shopifyMetaobjectCreate = async (
17
17
  credsPayload,
@@ -59,13 +59,20 @@ module.exports = {
59
59
  curl -X POST "http://localhost:8000/shopifyMetaobjectCreate" \
60
60
  -H "Content-Type: application/json" \
61
61
  -d '{
62
- "credsPayload": { "credsPath": "shopify.white-fox-us-dev-radial" },
62
+ "credsPayload": { "credsPath": "shopify.au" },
63
63
  "metaobjectInput": {
64
- "type": "your_metaobject_type",
65
- "handle": "optional-unique-handle",
64
+ "type": "catalog_filter_blacklist",
65
+ "handle": "collection-blacklist-example",
66
+ "capabilities": {
67
+ "publishable": {
68
+ "status": "ACTIVE"
69
+ }
70
+ },
66
71
  "fields": [
67
- { "key": "title", "value": "Example" },
68
- { "key": "body", "value": "Some content" }
72
+ { "key": "internal_name", "value": "Blacklist Category > \"Example\"" },
73
+ { "key": "source_filter", "value": "Category" },
74
+ { "key": "values", "value": "[\"Example\"]" },
75
+ { "key": "enabled", "value": "true" }
69
76
  ]
70
77
  }
71
78
  }'
@@ -0,0 +1,90 @@
1
+ // https://shopify.dev/docs/api/admin-graphql/latest/mutations/metaobjectDelete
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { actionSingleOrMultiple, ArgsWarden } = require('../utils');
5
+ const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['metaobjectId'],
10
+ ]);
11
+
12
+ const shopifyMetaobjectDeleteSingle = async (
13
+ credsPayload,
14
+ metaobjectId,
15
+ {
16
+ apiVersion,
17
+ returnSchema = 'deletedId',
18
+ } = {},
19
+ ) => {
20
+
21
+ return shopifyMutationDo(
22
+ credsPayload,
23
+ 'metaobjectDelete',
24
+ {
25
+ mutationVariables: {
26
+ id: {
27
+ type: 'ID!',
28
+ value: `gid://shopify/Metaobject/${ metaobjectId }`,
29
+ },
30
+ },
31
+ returnSchema,
32
+ apiVersion,
33
+ },
34
+ );
35
+ };
36
+
37
+ const shopifyMetaobjectDelete = async (
38
+ credsPayload,
39
+ metaobjectId,
40
+ {
41
+ queueRunOptions,
42
+ apiVersion,
43
+ returnSchema = 'deletedId',
44
+ } = {},
45
+ ) => {
46
+
47
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
48
+ credsPayload,
49
+ metaobjectId,
50
+ });
51
+ if (rejectResponse) {
52
+ return rejectResponse;
53
+ }
54
+
55
+ return actionSingleOrMultiple(
56
+ metaobjectId,
57
+ shopifyMetaobjectDeleteSingle,
58
+ (metaobjectIdItem) => ({
59
+ args: [credsPayload, metaobjectIdItem, { apiVersion, returnSchema }],
60
+ }),
61
+ {
62
+ ...(queueRunOptions ? { queueRunOptions } : {}),
63
+ },
64
+ );
65
+ };
66
+
67
+ const funcApiConfig = {
68
+ argsWarden,
69
+ };
70
+
71
+ module.exports = {
72
+ shopifyMetaobjectDelete,
73
+ funcApiConfig,
74
+ };
75
+
76
+ /*
77
+ curl -X POST "http://localhost:8000/shopifyMetaobjectDelete" \
78
+ -H "Content-Type: application/json" \
79
+ -d '{
80
+ "credsPayload": { "credsPath": "shopify.au" },
81
+ "metaobjectId": "215094820924"
82
+ }'
83
+
84
+ curl -X POST "http://localhost:8000/shopifyMetaobjectDelete" \
85
+ -H "Content-Type: application/json" \
86
+ -d '{
87
+ "credsPayload": { "credsPath": "shopify.au" },
88
+ "metaobjectId": ["215094820924", "215094820925"]
89
+ }'
90
+ */