@foxtware/mineral 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -76,3 +76,17 @@ The decoupled nature of these desires to what the function actually does and the
76
76
  ### AI use
77
77
 
78
78
  Not gonna lie, I have absolutely composed some of these platforms with AI. Some of them may not work, some may not stick closely to the core principles, some may use awkward auth methods - some error payloads are definitely not optimised. However, know that I have hand-coded precursors to this repo, that do largely the same thing, and that any additions benefit (or suffer) from the structure that is laid out in the earlier platforms.
79
+
80
+ ### Function arguments shape
81
+
82
+ - Bound arguments, if they exist, are first
83
+ - Mandatory inputs are passed as separate arguments
84
+ - Optional inputs are passed in one 'options' object on the end, which falls back to `{}` if not supplied
85
+
86
+ This looks like:
87
+ ```
88
+ const attack = (name, damage, accuracy, pp, type, { effects } = {}) => {
89
+ ```
90
+ where 'effects' is optional and the others are mandatory.
91
+
92
+ This documents what options are available, and allows invocations to only supply meaningful inputs.
@@ -1,6 +1,6 @@
1
1
  const { BASE_URL } = require('../bleckmann/bleckmann.constants');
2
2
  const { resolveCreds, useBaseUrl } = require('../pipelineSteps');
3
- const { FetchClient } = require('../utils');
3
+ const { FetchClient, fetchClientCommonSteps } = require('../utils');
4
4
 
5
5
  const useAuthHeaders = async (state) => {
6
6
  const { requestPayload, context } = state;
@@ -24,6 +24,9 @@ const bleckmannClient = new FetchClient({
24
24
  useAuthHeaders,
25
25
  useBaseUrl(BASE_URL),
26
26
  'fetch',
27
+ fetchClientCommonSteps.exitEarlyOnNotOk,
28
+ // Bleckmann wraps payloads in `data` — handlers opt in with context.resultPath
29
+ fetchClientCommonSteps.digToPath,
27
30
  ],
28
31
  });
29
32
 
@@ -42,6 +42,7 @@ const bleckmannAsnsGet = async (
42
42
  },
43
43
  context: {
44
44
  credsPayload,
45
+ resultPath: 'data',
45
46
  },
46
47
  });
47
48
 
@@ -0,0 +1,76 @@
1
+ // https://app.swaggerhub.com/apis-docs/Bleckmann/warehousing/1.5.2#/PICKTICKET/getPickticketForId
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden, objHasAny, oneFromManyInResponse } = require('../utils');
5
+ const { bleckmannClient } = require('../bleckmann/bleckmann.utils');
6
+ const { bleckmannPickticketsGet } = require('../bleckmann/bleckmannPickticketsGet');
7
+
8
+ const pickticketIdentifierValidator = (pickticketIdentifier) => {
9
+ return objHasAny(pickticketIdentifier, ['pickticketId', 'pickticketReference']);
10
+ };
11
+
12
+ const argsWarden = new ArgsWarden([
13
+ ['credsPayload', credsValidator],
14
+ ['pickticketIdentifier', pickticketIdentifierValidator],
15
+ ]);
16
+
17
+ const bleckmannPickticketGet = async (
18
+ credsPayload,
19
+ pickticketIdentifier,
20
+ {
21
+ fetchClient = bleckmannClient,
22
+ } = {},
23
+ ) => {
24
+
25
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
26
+ credsPayload,
27
+ pickticketIdentifier,
28
+ });
29
+ if (rejectResponse) {
30
+ return rejectResponse;
31
+ }
32
+
33
+ const {
34
+ pickticketId,
35
+ pickticketReference,
36
+ } = pickticketIdentifier;
37
+
38
+ if (pickticketId) {
39
+ return fetchClient.fetch({
40
+ requestPayload: {
41
+ url: `/warehousing/picktickets/${ pickticketId }`,
42
+ },
43
+ context: {
44
+ credsPayload,
45
+ },
46
+ });
47
+ }
48
+
49
+ const response = await bleckmannPickticketsGet(
50
+ credsPayload,
51
+ {
52
+ reference: pickticketReference,
53
+ fetchClient,
54
+ },
55
+ );
56
+
57
+ return oneFromManyInResponse(response, 'reference', pickticketReference);
58
+ };
59
+
60
+ const funcApiConfig = {
61
+ argsWarden,
62
+ };
63
+
64
+ module.exports = {
65
+ bleckmannPickticketGet,
66
+ funcApiConfig,
67
+ };
68
+
69
+ /*
70
+ curl -X POST "http://localhost:8000/bleckmannPickticketGet" \
71
+ -H "Content-Type: application/json" \
72
+ -d '{
73
+ "credsPayload": { "credsPath": "bleckmann" },
74
+ "pickticketIdentifier": { "pickticketReference": "1234567890" }
75
+ }'
76
+ */
@@ -0,0 +1,72 @@
1
+ // https://app.swaggerhub.com/apis-docs/Bleckmann/warehousing/1.5.2#/PICKTICKET/getPicktickets
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const { ArgsWarden } = require('../utils');
5
+ const { MAX_PER_PAGE } = require('../bleckmann/bleckmann.constants');
6
+ const { bleckmannClient } = require('../bleckmann/bleckmann.utils');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ]);
11
+
12
+ const bleckmannPickticketsGet = async (
13
+ credsPayload,
14
+ {
15
+ createdFrom,
16
+ createdTo,
17
+ shippedFrom,
18
+ shippedTo,
19
+ // status default is INPROGRESS in the API; use ANY unless provided
20
+ status = 'ANY',
21
+ reference,
22
+ customerReference,
23
+ perPage = MAX_PER_PAGE,
24
+ fetchClient = bleckmannClient,
25
+ } = {},
26
+ ) => {
27
+
28
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
29
+ credsPayload,
30
+ });
31
+ if (rejectResponse) {
32
+ return rejectResponse;
33
+ }
34
+
35
+ return fetchClient.fetch({
36
+ requestPayload: {
37
+ url: '/warehousing/picktickets',
38
+ params: {
39
+ limit: perPage,
40
+ ...(createdFrom && { createdFrom }),
41
+ ...(createdTo && { createdTo }),
42
+ ...(shippedFrom && { shippedFrom }),
43
+ ...(shippedTo && { shippedTo }),
44
+ ...(status && { status }),
45
+ ...(reference && { reference }),
46
+ ...(customerReference && { customerReference }),
47
+ },
48
+ },
49
+ context: {
50
+ credsPayload,
51
+ resultPath: 'data',
52
+ },
53
+ });
54
+ };
55
+
56
+ const funcApiConfig = {
57
+ argsWarden,
58
+ };
59
+
60
+ module.exports = {
61
+ bleckmannPickticketsGet,
62
+ funcApiConfig,
63
+ };
64
+
65
+ /*
66
+ curl -X POST "http://localhost:8000/bleckmannPickticketsGet" \
67
+ -H "Content-Type: application/json" \
68
+ -d '{
69
+ "credsPayload": { "credsPath": "bleckmann" },
70
+ "options": { "perPage": 20 }
71
+ }'
72
+ */
@@ -0,0 +1,81 @@
1
+ // https://linear.app/developers/graphql
2
+
3
+ const { ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { linearClient } = require('../linear/linear.utils');
6
+
7
+ const inputValidator = (input) => Boolean(input?.url);
8
+
9
+ const argsWarden = new ArgsWarden([
10
+ ['credsPayload', credsValidator],
11
+ ['input', inputValidator],
12
+ ]);
13
+
14
+ const linearEntityExternalLinkCreate = async (
15
+ credsPayload,
16
+ input,
17
+ {
18
+ inspect = false,
19
+ fetchClient = linearClient,
20
+ } = {},
21
+ ) => {
22
+
23
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
24
+ credsPayload,
25
+ input,
26
+ });
27
+ if (rejectResponse) {
28
+ return rejectResponse;
29
+ }
30
+
31
+ return fetchClient.fetch({
32
+ requestPayload: {
33
+ body: {
34
+ query: `
35
+ mutation EntityExternalLinkCreate($input: EntityExternalLinkCreateInput!) {
36
+ entityExternalLinkCreate(input: $input) {
37
+ success
38
+ entityExternalLink {
39
+ id
40
+ label
41
+ url
42
+ sortOrder
43
+ createdAt
44
+ }
45
+ }
46
+ }
47
+ `,
48
+ variables: {
49
+ input,
50
+ },
51
+ },
52
+ },
53
+ context: {
54
+ credsPayload,
55
+ resultPath: 'data.entityExternalLinkCreate',
56
+ },
57
+ inspect,
58
+ });
59
+ };
60
+
61
+ const funcApiConfig = {
62
+ argsWarden,
63
+ };
64
+
65
+ module.exports = {
66
+ linearEntityExternalLinkCreate,
67
+ funcApiConfig,
68
+ };
69
+
70
+ /*
71
+ curl -X POST "http://localhost:8000/linearEntityExternalLinkCreate" \
72
+ -H "Content-Type: application/json" \
73
+ -d '{
74
+ "credsPayload": { "credsPath": "linear" },
75
+ "input": {
76
+ "projectId": "64e37bd2-af8c-4142-932a-66441b75311b",
77
+ "url": "https://example.com",
78
+ "label": "Example link"
79
+ }
80
+ }'
81
+ */
@@ -0,0 +1,111 @@
1
+ // https://linear.app/developers/graphql
2
+
3
+ const { ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { linearClient } = require('../linear/linear.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['filename'],
10
+ ['contentType'],
11
+ ['size', (size) => Number.isInteger(size) && size > 0],
12
+ ]);
13
+
14
+ const linearFileUpload = async (
15
+ credsPayload,
16
+ filename,
17
+ contentType,
18
+ size,
19
+ {
20
+ metaData,
21
+ makePublic,
22
+ inspect = false,
23
+ fetchClient = linearClient,
24
+ } = {},
25
+ ) => {
26
+
27
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
28
+ credsPayload,
29
+ filename,
30
+ contentType,
31
+ size,
32
+ });
33
+ if (rejectResponse) {
34
+ return rejectResponse;
35
+ }
36
+
37
+ return fetchClient.fetch({
38
+ requestPayload: {
39
+ body: {
40
+ query: `
41
+ mutation FileUpload(
42
+ $filename: String!
43
+ $contentType: String!
44
+ $size: Int!
45
+ $metaData: JSON
46
+ $makePublic: Boolean
47
+ ) {
48
+ fileUpload(
49
+ filename: $filename
50
+ contentType: $contentType
51
+ size: $size
52
+ metaData: $metaData
53
+ makePublic: $makePublic
54
+ ) {
55
+ success
56
+ uploadFile {
57
+ filename
58
+ contentType
59
+ size
60
+ uploadUrl
61
+ assetUrl
62
+ headers {
63
+ key
64
+ value
65
+ }
66
+ }
67
+ }
68
+ }
69
+ `,
70
+ variables: {
71
+ filename,
72
+ contentType,
73
+ size,
74
+ metaData,
75
+ makePublic,
76
+ },
77
+ },
78
+ },
79
+ context: {
80
+ credsPayload,
81
+ resultPath: 'data.fileUpload',
82
+ },
83
+ inspect,
84
+ });
85
+ };
86
+
87
+ const funcApiConfig = {
88
+ argsWarden,
89
+ };
90
+
91
+ module.exports = {
92
+ linearFileUpload,
93
+ funcApiConfig,
94
+ };
95
+
96
+ /*
97
+ Returns a pre-signed `uploadUrl` to PUT the file to, plus the `headers` that
98
+ the PUT must carry. `assetUrl` is the resulting Linear-hosted URL, suitable
99
+ for linearAttachmentCreate or embedding in comment markdown.
100
+ */
101
+
102
+ /*
103
+ curl -X POST "http://localhost:8000/linearFileUpload" \
104
+ -H "Content-Type: application/json" \
105
+ -d '{
106
+ "credsPayload": { "credsPath": "linear" },
107
+ "filename": "assets.zip",
108
+ "contentType": "application/zip",
109
+ "size": 12345
110
+ }'
111
+ */
@@ -25,9 +25,9 @@ const resolveArrivalId = ({
25
25
  extReferenceId,
26
26
  }) => {
27
27
  return arrivalId
28
- || (extArrivalId ? `ext:${ extArrivalId }` : null)
29
- || (extArrivalApiId ? `api:${ extArrivalApiId }` : null)
30
- || (extReferenceId ? `ref:${ extReferenceId }` : null);
28
+ || (extArrivalId ? `ext:${ encodeURIComponent(extArrivalId) }` : null)
29
+ || (extArrivalApiId ? `api:${ encodeURIComponent(extArrivalApiId) }` : null)
30
+ || (extReferenceId ? `ref:${ encodeURIComponent(extReferenceId) }` : null);
31
31
  };
32
32
 
33
33
  const pipe17ArrivalGet = async (
@@ -52,7 +52,7 @@ const pipe17ArrivalGet = async (
52
52
  '/arrivals',
53
53
  resolveArrivalId(arrivalIdentifier),
54
54
  {
55
- resultPath: 'result.arrival',
55
+ resultPath: 'arrival',
56
56
  inspect,
57
57
  fetchClient,
58
58
  },
@@ -73,6 +73,13 @@ curl -X POST "http://localhost:8000/pipe17ArrivalGet" \
73
73
  -H "Content-Type: application/json" \
74
74
  -d '{
75
75
  "credsPayload": { "credsPath": "pipe17" },
76
- "arrivalIdentifier": { "arrivalId": "d22afa93793be1f1" }
76
+ "arrivalIdentifier": { "arrivalId": "8f146f632e55fd21" }
77
+ }'
78
+
79
+ curl -X POST "http://localhost:8000/pipe17ArrivalGet" \
80
+ -H "Content-Type: application/json" \
81
+ -d '{
82
+ "credsPayload": { "credsPath": "pipe17" },
83
+ "arrivalIdentifier": { "extArrivalId": "US-WF-021" }
77
84
  }'
78
85
  */
@@ -18,7 +18,7 @@ const resolveFulfillmentId = ({
18
18
  extFulfillmentId,
19
19
  }) => {
20
20
  return fulfillmentId
21
- || (extFulfillmentId ? `ext:${ extFulfillmentId }` : null);
21
+ || (extFulfillmentId ? `ext:${ encodeURIComponent(extFulfillmentId) }` : null);
22
22
  };
23
23
 
24
24
  const pipe17FulfillmentGet = async (
@@ -43,7 +43,7 @@ const pipe17FulfillmentGet = async (
43
43
  '/fulfillments',
44
44
  resolveFulfillmentId(fulfillmentIdentifier),
45
45
  {
46
- resultPath: 'result.fulfillment',
46
+ resultPath: 'fulfillment',
47
47
  inspect,
48
48
  fetchClient,
49
49
  },
@@ -64,6 +64,13 @@ curl -X POST "http://localhost:8000/pipe17FulfillmentGet" \
64
64
  -H "Content-Type: application/json" \
65
65
  -d '{
66
66
  "credsPayload": { "credsPath": "pipe17" },
67
- "fulfillmentIdentifier": { "fulfillmentId": "4ce308990d48d54f" }
67
+ "fulfillmentIdentifier": { "fulfillmentId": "171889ac4c86b805" }
68
+ }'
69
+
70
+ curl -X POST "http://localhost:8000/pipe17FulfillmentGet" \
71
+ -H "Content-Type: application/json" \
72
+ -d '{
73
+ "credsPayload": { "credsPath": "pipe17" },
74
+ "fulfillmentIdentifier": { "extFulfillmentId": "bb558b1527b95c99:1Z179A841391432104" }
68
75
  }'
69
76
  */
@@ -31,7 +31,7 @@ const pipe17InventoryItemGet = async (
31
31
  '/inventory',
32
32
  inventoryItemId,
33
33
  {
34
- resultPath: 'result.inventory',
34
+ resultPath: 'inventory',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -48,10 +48,14 @@ module.exports = {
48
48
  };
49
49
 
50
50
  /*
51
- curl -X POST "http://localhost:8000/pipe17InventoryItemGet" \
51
+ NOTE: no working call found. Pipe17 inventory records carry no id of their own — they are
52
+ keyed by sku + locationId — and GET /inventory/{id} returns 404 "No results" for a sku or a
53
+ locationId. Fetch by sku through pipe17InventoryItemsGet instead (one row per location):
54
+
55
+ curl -X POST "http://localhost:8000/pipe17InventoryItemsGet" \
52
56
  -H "Content-Type: application/json" \
53
57
  -d '{
54
58
  "credsPayload": { "credsPath": "pipe17" },
55
- "inventoryItemId": "904e7f5e7a03df4f"
59
+ "options": { "params": { "sku": "EXDAL2449-5-XS" } }
56
60
  }'
57
61
  */
@@ -31,7 +31,7 @@ const pipe17JobGet = async (
31
31
  '/jobs',
32
32
  jobId,
33
33
  {
34
- resultPath: 'result.job',
34
+ resultPath: 'job',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -52,6 +52,6 @@ curl -X POST "http://localhost:8000/pipe17JobGet" \
52
52
  -H "Content-Type: application/json" \
53
53
  -d '{
54
54
  "credsPayload": { "credsPath": "pipe17" },
55
- "jobId": "eb7586ac111d3afb"
55
+ "jobId": "94fc44fdbe6ad3ae"
56
56
  }'
57
57
  */
@@ -50,6 +50,6 @@ curl -X POST "http://localhost:8000/pipe17JobResultsGet" \
50
50
  -H "Content-Type: application/json" \
51
51
  -d '{
52
52
  "credsPayload": { "credsPath": "pipe17" },
53
- "jobId": "eb7586ac111d3afb"
53
+ "jobId": "a25261fefd836d00"
54
54
  }'
55
55
  */
@@ -31,7 +31,7 @@ const pipe17LocationGet = async (
31
31
  '/locations',
32
32
  locationId,
33
33
  {
34
- resultPath: 'result.location',
34
+ resultPath: 'location',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -52,6 +52,6 @@ curl -X POST "http://localhost:8000/pipe17LocationGet" \
52
52
  -H "Content-Type: application/json" \
53
53
  -d '{
54
54
  "credsPayload": { "credsPath": "pipe17" },
55
- "locationId": "6d9c18617ea2d279"
55
+ "locationId": "727db407e94815a6"
56
56
  }'
57
57
  */
@@ -19,8 +19,8 @@ const resolveOrderId = ({
19
19
  extOrderApiId,
20
20
  }) => {
21
21
  return orderId
22
- || (extOrderId ? `ext:${ extOrderId }` : null)
23
- || (extOrderApiId ? `api:${ extOrderApiId }` : null);
22
+ || (extOrderId ? `ext:${ encodeURIComponent(extOrderId) }` : null)
23
+ || (extOrderApiId ? `api:${ encodeURIComponent(extOrderApiId) }` : null);
24
24
  };
25
25
 
26
26
  const pipe17OrderGet = async (
@@ -45,7 +45,7 @@ const pipe17OrderGet = async (
45
45
  '/orders',
46
46
  resolveOrderId(orderIdentifier),
47
47
  {
48
- resultPath: 'result.order',
48
+ resultPath: 'order',
49
49
  inspect,
50
50
  fetchClient,
51
51
  },
@@ -66,6 +66,20 @@ curl -X POST "http://localhost:8000/pipe17OrderGet" \
66
66
  -H "Content-Type: application/json" \
67
67
  -d '{
68
68
  "credsPayload": { "credsPath": "pipe17" },
69
- "orderIdentifier": { "orderId": "dc120f1015760357" }
69
+ "orderIdentifier": { "orderId": "243acd2642101951" }
70
+ }'
71
+
72
+ curl -X POST "http://localhost:8000/pipe17OrderGet" \
73
+ -H "Content-Type: application/json" \
74
+ -d '{
75
+ "credsPayload": { "credsPath": "pipe17" },
76
+ "orderIdentifier": { "extOrderId": "#USA4162713" }
77
+ }'
78
+
79
+ curl -X POST "http://localhost:8000/pipe17OrderGet" \
80
+ -H "Content-Type: application/json" \
81
+ -d '{
82
+ "credsPayload": { "credsPath": "pipe17" },
83
+ "orderIdentifier": { "extOrderApiId": "5820180987964" }
70
84
  }'
71
85
  */
@@ -31,7 +31,7 @@ const pipe17ProductGet = async (
31
31
  '/products',
32
32
  productId,
33
33
  {
34
- resultPath: 'result.product',
34
+ resultPath: 'product',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -52,6 +52,6 @@ curl -X POST "http://localhost:8000/pipe17ProductGet" \
52
52
  -H "Content-Type: application/json" \
53
53
  -d '{
54
54
  "credsPayload": { "credsPath": "pipe17" },
55
- "productId": "149a8a65ad5bca52"
55
+ "productId": "3f91e016e3d433e8"
56
56
  }'
57
57
  */
@@ -31,7 +31,7 @@ const pipe17PurchaseGet = async (
31
31
  '/purchases',
32
32
  purchaseId,
33
33
  {
34
- resultPath: 'result.purchase',
34
+ resultPath: 'purchase',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -52,6 +52,6 @@ curl -X POST "http://localhost:8000/pipe17PurchaseGet" \
52
52
  -H "Content-Type: application/json" \
53
53
  -d '{
54
54
  "credsPayload": { "credsPath": "pipe17" },
55
- "purchaseId": "REPLACE_WITH_PURCHASE_ID"
55
+ "purchaseId": "075e2df5318aa93e"
56
56
  }'
57
57
  */
@@ -31,7 +31,7 @@ const pipe17ReceiptGet = async (
31
31
  '/receipts',
32
32
  receiptId,
33
33
  {
34
- resultPath: 'result.receipt',
34
+ resultPath: 'receipt',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -31,7 +31,7 @@ const pipe17ReturnGet = async (
31
31
  '/returns',
32
32
  returnId,
33
33
  {
34
- resultPath: 'result.return',
34
+ resultPath: 'return',
35
35
  inspect,
36
36
  fetchClient,
37
37
  },
@@ -52,6 +52,6 @@ curl -X POST "http://localhost:8000/pipe17ReturnGet" \
52
52
  -H "Content-Type: application/json" \
53
53
  -d '{
54
54
  "credsPayload": { "credsPath": "pipe17" },
55
- "returnId": "969504fc181f7182"
55
+ "returnId": "b66396c696171143"
56
56
  }'
57
57
  */
@@ -297,6 +297,8 @@ const funcApiConfig = {
297
297
  module.exports = {
298
298
  shopifyGet: (...args) => shopifyGet(false, ...args),
299
299
  shopifyGetter: (...args) => shopifyGet(true, ...args),
300
+ shopifyGetPaginator,
301
+ shopifyGetDigester,
300
302
  funcApiConfig,
301
303
  };
302
304
 
@@ -0,0 +1,166 @@
1
+ // https://shopify.dev/docs/api/admin-graphql/latest/objects/OnlineStoreTheme#connection-files
2
+
3
+ const { ArgsWarden, Getter, ensureArray, getWithLocalCachedFile } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { shopifyClient } = require('./shopify.utils');
6
+ const { shopifyGetPaginator, shopifyGetDigester } = require('./shopifyGet');
7
+ const { MAX_PER_PAGE } = require('./shopify.constants');
8
+
9
+ const defaultAttrs = 'filename';
10
+
11
+ const argsWarden = new ArgsWarden([
12
+ ['credsPayload', credsValidator],
13
+ ['themeId'],
14
+ ]);
15
+
16
+ const shopifyThemeFilesGetPacket = async (
17
+ credsPayload,
18
+ themeId,
19
+ attrs,
20
+ {
21
+ apiVersion,
22
+
23
+ perPage = MAX_PER_PAGE,
24
+ cursor,
25
+ // Supports globs, e.g. templates/page.*
26
+ filenames,
27
+ } = {},
28
+ ) => {
29
+
30
+ return await shopifyClient.fetch({
31
+ requestPayload: {
32
+ method: 'post',
33
+ body: {
34
+ query: `
35
+ query GetThemeFiles (
36
+ $themeId: ID!
37
+ $first: Int!
38
+ $cursor: String
39
+ ${ filenames ? '$filenames: [String!]' : '' }
40
+ ) {
41
+ theme(id: $themeId) {
42
+ files(
43
+ first: $first
44
+ after: $cursor
45
+ ${ filenames ? 'filenames: $filenames' : '' }
46
+ ) {
47
+ nodes {
48
+ ${ attrs }
49
+ }
50
+ pageInfo {
51
+ hasNextPage
52
+ endCursor
53
+ }
54
+ }
55
+ }
56
+ }
57
+ `,
58
+ variables: {
59
+ themeId: `gid://shopify/OnlineStoreTheme/${ themeId }`,
60
+ first: perPage,
61
+ cursor,
62
+ ...filenames && { filenames: ensureArray(filenames) },
63
+ },
64
+ },
65
+ },
66
+ context: {
67
+ credsPayload,
68
+ apiVersion,
69
+ resultPath: 'data.theme.files',
70
+ },
71
+ });
72
+ };
73
+
74
+ const shopifyThemeFilesGet = async (
75
+ returnGetter, // Always bound
76
+
77
+ credsPayload,
78
+ themeId,
79
+ {
80
+ apiVersion,
81
+
82
+ attrs = defaultAttrs,
83
+ perPage = MAX_PER_PAGE,
84
+ cursor,
85
+ filenames,
86
+
87
+ useLocalCachedFile,
88
+ ...getterOptions // e.g. limit
89
+ } = {},
90
+ ) => {
91
+
92
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
93
+ credsPayload,
94
+ themeId,
95
+ });
96
+ if (rejectResponse) {
97
+ return rejectResponse;
98
+ }
99
+
100
+ const getter = new Getter(
101
+ {
102
+ args: [
103
+ credsPayload,
104
+ themeId,
105
+ attrs,
106
+ ],
107
+ options: {
108
+ apiVersion,
109
+ perPage,
110
+ cursor,
111
+ filenames,
112
+ },
113
+ },
114
+ {
115
+ func: shopifyThemeFilesGetPacket,
116
+ digester: shopifyGetDigester,
117
+ paginator: shopifyGetPaginator,
118
+ ...getterOptions,
119
+ },
120
+ );
121
+
122
+ if (returnGetter) {
123
+ return getter;
124
+ }
125
+
126
+ return getWithLocalCachedFile(
127
+ useLocalCachedFile,
128
+ async () => {
129
+ const data = await getter.run({ returnAll: true });
130
+
131
+ return {
132
+ ok: true,
133
+ data,
134
+ };
135
+ },
136
+ );
137
+ };
138
+
139
+ const funcApiConfig = {
140
+ argsWarden,
141
+ };
142
+
143
+ module.exports = {
144
+ shopifyThemeFilesGet: (...args) => shopifyThemeFilesGet(false, ...args),
145
+ shopifyThemeFilesGetter: (...args) => shopifyThemeFilesGet(true, ...args),
146
+ funcApiConfig,
147
+ };
148
+
149
+ /*
150
+ curl -X POST "http://localhost:8000/shopifyThemeFilesGet" \
151
+ -H "Content-Type: application/json" \
152
+ -d '{
153
+ "credsPayload": { "credsPath": "shopify.au" },
154
+ "themeId": "130370109512"
155
+ }'
156
+
157
+ curl -X POST "http://localhost:8000/shopifyThemeFilesGet" \
158
+ -H "Content-Type: application/json" \
159
+ -d '{
160
+ "credsPayload": { "credsPath": "shopify.au" },
161
+ "themeId": "130370109512",
162
+ "options": {
163
+ "filenames": "templates/*"
164
+ }
165
+ }'
166
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxtware/mineral",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "bin": {
5
5
  "mineral": "bin/mineral.js"
6
6
  },