@foxtware/mineral 0.1.9 → 0.1.11

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 (159) hide show
  1. package/.creds.yml.sample +27 -6
  2. package/AGENTS.md +6 -1
  3. package/README.md +1 -1
  4. package/api/bleckmann/.gitkeep +0 -0
  5. package/api/bleckmann/bleckmann.constants.js +8 -0
  6. package/api/bleckmann/bleckmann.utils.js +32 -0
  7. package/api/bleckmann/bleckmannAsnGet.js +52 -0
  8. package/api/bleckmann/bleckmannAsnsGet.js +65 -0
  9. package/api/constants.js +2 -1
  10. package/api/github/github.constants.js +11 -0
  11. package/api/github/github.utils.js +65 -0
  12. package/api/github/githubGet.js +144 -0
  13. package/api/github/githubIssueCreate.js +71 -0
  14. package/api/github/githubIssueGet.js +65 -0
  15. package/api/github/githubIssueUpdate.js +71 -0
  16. package/api/github/githubIssuesGet.js +74 -0
  17. package/api/github/githubPullRequestCreate.js +74 -0
  18. package/api/github/githubPullRequestGet.js +65 -0
  19. package/api/github/githubPullRequestMerge.js +77 -0
  20. package/api/github/githubPullRequestUpdate.js +72 -0
  21. package/api/github/githubPullRequestsGet.js +74 -0
  22. package/api/github/githubRepoCreate.js +80 -0
  23. package/api/github/githubRepoDelete.js +60 -0
  24. package/api/github/githubRepoGet.js +61 -0
  25. package/api/github/githubRepoUpdate.js +68 -0
  26. package/api/github/githubReposGet.js +69 -0
  27. package/api/github/githubUserGet.js +64 -0
  28. package/api/linear/linear.utils.js +9 -14
  29. package/api/linear/linearIssuesGet.js +9 -9
  30. package/api/logiwa/logiwa.utils.js +27 -25
  31. package/api/logiwa/logiwaInventoriesGet.js +5 -3
  32. package/api/logiwa/logiwaOrderGet.js +4 -2
  33. package/api/logiwa/logiwaOrdersGet.js +5 -3
  34. package/api/logiwa/logiwaProductGet.js +4 -2
  35. package/api/logiwa/logiwaProductsGet.js +5 -3
  36. package/api/logiwa/logiwaReportGetAvailableToPromise.js +5 -3
  37. package/api/logiwa/logiwaReportGetInventoryCalculation.js +5 -3
  38. package/api/logiwa/logiwaReportGetInventorySnapshot.js +5 -3
  39. package/api/logiwa/logiwaReportGetTotalInventory.js +5 -3
  40. package/api/logiwa/logiwaWebhookStatusGet.js +4 -2
  41. package/api/logiwa/logiwaWebhookSubscribe.js +8 -6
  42. package/api/logiwa/logiwaWebhookUnsubscribe.js +4 -2
  43. package/api/logiwa/logiwaWebhooksGet.js +4 -2
  44. package/api/loop/loop.utils.js +9 -15
  45. package/api/loop/loopGet.js +20 -24
  46. package/api/loop/loopReturnGet.js +6 -6
  47. package/api/peoplevox/peoplevox.constants.js +1 -1
  48. package/api/peoplevox/peoplevox.sessions.js +0 -33
  49. package/api/peoplevox/peoplevox.utils.js +63 -19
  50. package/api/peoplevox/peoplevoxGetSingle.js +7 -5
  51. package/api/peoplevox/peoplevoxOrderEdit.js +7 -5
  52. package/api/peoplevox/peoplevoxReportGet.js +11 -9
  53. package/api/pipelineSteps.js +49 -0
  54. package/api/shopify/shopify.utils.js +93 -22
  55. package/api/shopify/shopifyBulkMutationDo.js +211 -0
  56. package/api/shopify/shopifyBulkOperationGet.js +86 -0
  57. package/api/shopify/shopifyBulkOperationRunMutation.js +83 -0
  58. package/api/shopify/shopifyBulkOperationRunQuery.js +70 -0
  59. package/api/shopify/shopifyBulkQueryDo.js +127 -0
  60. package/api/shopify/shopifyCheckoutAndAccountsConfigurationUpdate.js +79 -0
  61. package/api/shopify/shopifyCollectionGet.js +6 -6
  62. package/api/shopify/shopifyCustomerGet.js +6 -6
  63. package/api/shopify/shopifyGet.js +18 -13
  64. package/api/shopify/shopifyGetSingle.js +9 -9
  65. package/api/shopify/shopifyMutationDo.js +6 -6
  66. package/api/shopify/shopifyOrdersGet.js +11 -11
  67. package/api/shopify/shopifyStagedUploadCreate.js +96 -0
  68. package/api/shopify/shopifyTagsAddBulk.js +77 -0
  69. package/api/slack/slack.utils.js +10 -19
  70. package/api/slack/slackMessagePost.js +11 -11
  71. package/api/starshipit/starshipit.constants.js +8 -0
  72. package/api/starshipit/starshipit.utils.js +71 -0
  73. package/api/starshipit/starshipitAddressCreate.js +77 -0
  74. package/api/starshipit/starshipitAddressDelete.js +55 -0
  75. package/api/starshipit/starshipitAddressUpdate.js +69 -0
  76. package/api/starshipit/starshipitAddressesGet.js +52 -0
  77. package/api/starshipit/starshipitGet.js +146 -0
  78. package/api/starshipit/starshipitOrderDelete.js +102 -0
  79. package/api/starshipit/starshipitOrderGet.js +74 -0
  80. package/api/starshipit/starshipitOrderUpdate.js +109 -0
  81. package/api/starshipit/starshipitOrdersListShipped.js +64 -0
  82. package/api/starshipit/starshipitProductAdd.js +100 -0
  83. package/api/starshipit/starshipitProductsDelete.js +57 -0
  84. package/api/starshipit/starshipitProductsGet.js +49 -0
  85. package/api/starshipit/starshipitTrackingGet.js +69 -0
  86. package/api/stripe/_example.js +7 -7
  87. package/api/stripe/stripe.utils.js +9 -14
  88. package/api/stripe/stripeCardTokenCreate.js +11 -11
  89. package/api/stripe/stripeChargeCapture.js +11 -11
  90. package/api/stripe/stripeChargeCreate.js +11 -11
  91. package/api/stripe/stripeChargeGet.js +5 -5
  92. package/api/stripe/stripeChargesGet.js +6 -6
  93. package/api/stripe/stripeRefundCreate.js +10 -10
  94. package/api/stripe/stripeRefundGet.js +5 -5
  95. package/api/stripe/stripeRefundsGet.js +6 -6
  96. package/api/stripe/stripeTokenGet.js +5 -5
  97. package/api/stylearcade/stylearcade.constants.js +5 -0
  98. package/api/stylearcade/stylearcade.utils.js +40 -0
  99. package/api/stylearcade/stylearcadeDataGet.js +62 -0
  100. package/api/stylearcade/stylearcadeGet.js +133 -0
  101. package/api/stylearcade/stylearcadeMetadataGet.js +47 -0
  102. package/api/threeclicks/threeclicks.constants.js +8 -0
  103. package/api/threeclicks/threeclicks.utils.js +119 -0
  104. package/api/threeclicks/threeclicksCollectionsGet.js +40 -0
  105. package/api/threeclicks/threeclicksGet.js +138 -0
  106. package/api/threeclicks/threeclicksKeycodeCreate.js +55 -0
  107. package/api/threeclicks/threeclicksKeycodeGet.js +47 -0
  108. package/api/threeclicks/threeclicksPurchaseOrderCreate.js +34 -0
  109. package/api/threeclicks/threeclicksPurchaseOrderCreateBulk.js +34 -0
  110. package/api/threeclicks/threeclicksPurchaseOrderGet.js +33 -0
  111. package/api/threeclicks/threeclicksPurchaseOrderQuantitiesGet.js +33 -0
  112. package/api/threeclicks/threeclicksPurchaseOrderQuantityCreate.js +34 -0
  113. package/api/threeclicks/threeclicksPurchaseOrderQuantityCreateBulk.js +34 -0
  114. package/api/threeclicks/threeclicksPurchaseOrderQuantityUpdate.js +46 -0
  115. package/api/threeclicks/threeclicksPurchaseOrderQuantityUpdateBulk.js +46 -0
  116. package/api/threeclicks/threeclicksPurchaseOrderUpdate.js +35 -0
  117. package/api/threeclicks/threeclicksPurchaseOrdersGet.js +30 -0
  118. package/api/threeclicks/threeclicksShipmentCreate.js +34 -0
  119. package/api/threeclicks/threeclicksShipmentGet.js +33 -0
  120. package/api/threeclicks/threeclicksShipmentOrderAdd.js +38 -0
  121. package/api/threeclicks/threeclicksShipmentOrderQuantityCreate.js +35 -0
  122. package/api/threeclicks/threeclicksShipmentQuantityUpdate.js +35 -0
  123. package/api/threeclicks/threeclicksShipmentStatusUpdate.js +45 -0
  124. package/api/threeclicks/threeclicksShipmentsGet.js +52 -0
  125. package/api/threeclicks/threeclicksSignatureCalculate.js +73 -0
  126. package/api/threeclicks/threeclicksStyleCodesGet.js +46 -0
  127. package/api/threeclicks/threeclicksStyleColourCreate.js +47 -0
  128. package/api/threeclicks/threeclicksStyleColourDelete.js +34 -0
  129. package/api/threeclicks/threeclicksStyleCreate.js +44 -0
  130. package/api/threeclicks/threeclicksStyleDelete.js +33 -0
  131. package/api/threeclicks/threeclicksStyleGet.js +43 -0
  132. package/api/threeclicks/threeclicksStylePriceUpdate.js +70 -0
  133. package/api/threeclicks/threeclicksStyleUpdate.js +47 -0
  134. package/api/threeclicks/threeclicksStylesGet.js +45 -0
  135. package/api/utils.js +85 -117
  136. package/api/validators.js +1 -1
  137. package/api/workable/workable.utils.js +8 -13
  138. package/api/workable/workableGet.js +16 -11
  139. package/api/workable/workableJobCandidateCreate.js +10 -10
  140. package/api/workable/workableJobGet.js +5 -5
  141. package/api/workable/workableJobMembersGet.js +5 -5
  142. package/api/workable/workableJobStagesGet.js +5 -5
  143. package/api/yotpo/yotpo.utils.js +17 -22
  144. package/api/yotpo/yotpoCampaignsGet.js +6 -6
  145. package/api/yotpo/yotpoCustomerActionRecord.js +7 -7
  146. package/api/yotpo/yotpoCustomerAnniversaryGet.js +7 -7
  147. package/api/yotpo/yotpoCustomerAnniversarySet.js +7 -7
  148. package/api/yotpo/yotpoCustomerBirthdaySet.js +7 -7
  149. package/api/yotpo/yotpoCustomerGet.js +6 -6
  150. package/api/yotpo/yotpoCustomerPointsAdjust.js +7 -7
  151. package/api/yotpo/yotpoCustomerUpsert.js +7 -7
  152. package/api/yotpo/yotpoCustomersRecentGet.js +6 -6
  153. package/api/yotpo/yotpoRedemptionCreate.js +7 -7
  154. package/api/yotpo/yotpoRedemptionOptionsGet.js +6 -6
  155. package/api/yotpo/yotpoVipTiersGet.js +5 -5
  156. package/api/youtube/youtube.constants.js +5 -0
  157. package/api/youtube/youtube.utils.js +77 -0
  158. package/api/youtube/youtubeChannelVideosGet.js +25 -70
  159. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ // https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user
2
+
3
+ const { ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { githubGet } = require('../github/githubGet');
6
+ const { MAX_PER_PAGE } = require('../github/github.constants');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ]);
11
+
12
+ const githubReposGet = async (
13
+ credsPayload,
14
+ {
15
+ org,
16
+ type,
17
+ sort,
18
+ direction,
19
+ perPage,
20
+ ...getterOptions
21
+ } = {},
22
+ ) => {
23
+
24
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
25
+ if (rejectResponse) {
26
+ return rejectResponse;
27
+ }
28
+
29
+ const url = org ? `/orgs/${ org }/repos` : '/user/repos';
30
+
31
+ const params = {
32
+ ...type && { type },
33
+ ...sort && { sort },
34
+ ...direction && { direction },
35
+ };
36
+
37
+ return githubGet(credsPayload, url, {
38
+ params,
39
+ perPage: perPage ?? MAX_PER_PAGE,
40
+ ...getterOptions,
41
+ });
42
+ };
43
+
44
+ const funcApiConfig = {
45
+ argsWarden,
46
+ };
47
+
48
+ module.exports = {
49
+ githubReposGet,
50
+ funcApiConfig,
51
+ };
52
+
53
+ /*
54
+ curl -X POST "http://localhost:8000/githubReposGet" \
55
+ -H "Content-Type: application/json" \
56
+ -d '{
57
+ "credsPayload": { "credsPath": "github" }
58
+ }'
59
+
60
+ curl -X POST "http://localhost:8000/githubReposGet" \
61
+ -H "Content-Type: application/json" \
62
+ -d '{
63
+ "credsPayload": { "credsPath": "github" },
64
+ "options": {
65
+ "org": "GorgonFreeman",
66
+ "limit": 10
67
+ }
68
+ }'
69
+ */
@@ -0,0 +1,64 @@
1
+ // https://docs.github.com/en/rest/users/users#get-the-authenticated-user
2
+ // https://docs.github.com/en/rest/users/users#get-a-user
3
+
4
+ const { ArgsWarden } = require('../utils');
5
+ const { credsValidator } = require('../validators');
6
+ const { githubClient } = require('../github/github.utils');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ]);
11
+
12
+ const githubUserGet = async (
13
+ credsPayload,
14
+ {
15
+ username,
16
+ params,
17
+ apiVersion,
18
+ } = {},
19
+ ) => {
20
+
21
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
22
+ if (rejectResponse) {
23
+ return rejectResponse;
24
+ }
25
+
26
+ const url = username ? `/users/${ username }` : '/user';
27
+
28
+ return githubClient.fetch({
29
+ requestPayload: {
30
+ url,
31
+ params,
32
+ },
33
+ context: {
34
+ credsPayload,
35
+ apiVersion,
36
+ },
37
+ });
38
+ };
39
+
40
+ const funcApiConfig = {
41
+ argsWarden,
42
+ };
43
+
44
+ module.exports = {
45
+ githubUserGet,
46
+ funcApiConfig,
47
+ };
48
+
49
+ /*
50
+ curl -X POST "http://localhost:8000/githubUserGet" \
51
+ -H "Content-Type: application/json" \
52
+ -d '{
53
+ "credsPayload": { "credsPath": "github" }
54
+ }'
55
+
56
+ curl -X POST "http://localhost:8000/githubUserGet" \
57
+ -H "Content-Type: application/json" \
58
+ -d '{
59
+ "credsPayload": { "credsPath": "github" },
60
+ "options": {
61
+ "username": "GorgonFreeman"
62
+ }
63
+ }'
64
+ */
@@ -1,11 +1,11 @@
1
1
  const { LINEAR_GRAPHQL_URL } = require('../linear/linear.constants');
2
+ const { resolveCreds } = require('../pipelineSteps');
2
3
  const {
3
4
  FetchClient,
4
- Chain,
5
5
  fetchClientCommonSteps,
6
6
  } = require('../utils');
7
7
 
8
- const addUrlAndAuthHeaders = async (state) => {
8
+ const useAuthHeaders = async (state) => {
9
9
  const { requestPayload, context } = state;
10
10
  const { creds } = context;
11
11
  const { API_KEY } = creds;
@@ -16,7 +16,6 @@ const addUrlAndAuthHeaders = async (state) => {
16
16
  url: requestPayload.url || LINEAR_GRAPHQL_URL,
17
17
  method: requestPayload.method || 'post',
18
18
  headers: {
19
- 'Content-Type': 'application/json',
20
19
  Authorization: API_KEY,
21
20
  ...requestPayload.headers,
22
21
  },
@@ -24,18 +23,14 @@ const addUrlAndAuthHeaders = async (state) => {
24
23
  };
25
24
  };
26
25
 
27
- const linearClientRequestPreparer = new Chain([
28
- addUrlAndAuthHeaders,
29
- ]);
30
-
31
- const linearClientResponseInterpreter = new Chain([
32
- fetchClientCommonSteps.exitEarlyOnNotOk,
33
- fetchClientCommonSteps.exitEarlyOnGraphqlErrors,
34
- ]);
35
-
36
26
  const linearClient = new FetchClient({
37
- requestPreparer: linearClientRequestPreparer,
38
- responseInterpreter: linearClientResponseInterpreter,
27
+ pipeline: [
28
+ resolveCreds,
29
+ useAuthHeaders,
30
+ 'fetch',
31
+ fetchClientCommonSteps.exitEarlyOnNotOk,
32
+ fetchClientCommonSteps.exitEarlyOnGraphqlErrors,
33
+ ],
39
34
  });
40
35
 
41
36
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  // https://linear.app/developers/graphql
2
2
 
3
- const { credsFromPayload, ArgsWarden } = require('../utils');
3
+ const { ArgsWarden } = require('../utils');
4
4
  const { credsValidator } = require('../validators');
5
5
  const { linearClient } = require('../linear/linear.utils');
6
6
 
@@ -24,15 +24,14 @@ const linearIssuesGet = async (
24
24
  return rejectResponse;
25
25
  }
26
26
 
27
- const creds = await credsFromPayload(credsPayload);
28
-
29
27
  const filter = teamId
30
28
  ? { team: { id: { eq: teamId } } }
31
29
  : undefined;
32
30
 
33
31
  const response = await linearClient.fetch({
34
- body: {
35
- query: `
32
+ requestPayload: {
33
+ body: {
34
+ query: `
36
35
  query IssuesGet($first: Int!, $filter: IssueFilter) {
37
36
  issues(first: $first, filter: $filter) {
38
37
  nodes {
@@ -58,12 +57,13 @@ const linearIssuesGet = async (
58
57
  }
59
58
  }
60
59
  `,
61
- variables: {
62
- first,
63
- ...(filter && { filter }),
60
+ variables: {
61
+ first,
62
+ ...(filter && { filter }),
63
+ },
64
64
  },
65
65
  },
66
- context: { creds },
66
+ context: { credsPayload },
67
67
  inspect,
68
68
  });
69
69
 
@@ -1,31 +1,37 @@
1
1
  const { DEFAULT_API_VERSION } = require('../logiwa/logiwa.constants');
2
2
  const { logiwaAuthGet } = require('../logiwa/logiwaAuthGet');
3
+ const { resolveCreds } = require('../pipelineSteps');
3
4
  const {
4
5
  FetchClient,
5
- Chain,
6
6
  appendUrlToBase,
7
- credsFromPayload,
8
7
  fetchClientCommonSteps,
9
8
  } = require('../utils');
10
9
 
11
- const addUrlAndAuthHeaders = async (state) => {
10
+ const useUrlAndAuthHeaders = async (state) => {
12
11
  const { requestPayload, context } = state;
13
- const { credsPayload, apiVersion = DEFAULT_API_VERSION } = context;
14
-
15
- const creds = context.creds ?? await credsFromPayload(credsPayload);
16
- const authResponse = await logiwaAuthGet(credsPayload);
17
- const { data } = authResponse;
18
- const { token } = data;
19
-
20
- // TODO: Handle failed auth
21
-
12
+ const {
13
+ apiVersion = DEFAULT_API_VERSION,
14
+ creds,
15
+ } = context;
16
+
17
+ const authResponse = await logiwaAuthGet(
18
+ { credsObject: creds },
19
+ { apiVersion },
20
+ );
21
+
22
+ if (!authResponse?.ok) {
23
+ return {
24
+ breakChain: true,
25
+ response: authResponse,
26
+ };
27
+ }
28
+
29
+ const { token } = authResponse.data;
22
30
  const { BASE_URL } = creds;
23
31
 
24
32
  return {
25
- context: {
26
- creds,
27
- },
28
33
  requestPayload: {
34
+ ...requestPayload,
29
35
  url: appendUrlToBase(`${ BASE_URL }/${ apiVersion }`, requestPayload.url),
30
36
  headers: {
31
37
  Authorization: `Bearer ${ token }`,
@@ -35,17 +41,13 @@ const addUrlAndAuthHeaders = async (state) => {
35
41
  };
36
42
  };
37
43
 
38
- const logiwaClientRequestPreparer = new Chain([
39
- addUrlAndAuthHeaders,
40
- ]);
41
-
42
- const logiwaClientResponseInterpreter = new Chain([
43
- fetchClientCommonSteps.exitEarlyOnNotOk,
44
- ]);
45
-
46
44
  const logiwaClient = new FetchClient({
47
- requestPreparer: logiwaClientRequestPreparer,
48
- responseInterpreter: logiwaClientResponseInterpreter,
45
+ pipeline: [
46
+ resolveCreds,
47
+ useUrlAndAuthHeaders,
48
+ 'fetch',
49
+ fetchClientCommonSteps.exitEarlyOnNotOk,
50
+ ],
49
51
  });
50
52
 
51
53
  module.exports = {
@@ -39,9 +39,11 @@ const logiwaInventoriesGet = async (
39
39
  };
40
40
 
41
41
  return logiwaClient.fetch({
42
- method: 'get',
43
- url: `/Inventory/list/i/${ page }/s/${ perPage }`,
44
- params,
42
+ requestPayload: {
43
+ method: 'get',
44
+ url: `/Inventory/list/i/${ page }/s/${ perPage }`,
45
+ params,
46
+ },
45
47
  context: {
46
48
  credsPayload,
47
49
  apiVersion,
@@ -26,8 +26,10 @@ const logiwaOrderGet = async (
26
26
  }
27
27
 
28
28
  return logiwaClient.fetch({
29
- method: 'get',
30
- url: `/ShipmentOrder/${ orderId }`,
29
+ requestPayload: {
30
+ method: 'get',
31
+ url: `/ShipmentOrder/${ orderId }`,
32
+ },
31
33
  context: {
32
34
  credsPayload,
33
35
  apiVersion,
@@ -57,9 +57,11 @@ const logiwaOrdersGet = async (
57
57
  };
58
58
 
59
59
  return logiwaClient.fetch({
60
- method: 'get',
61
- url: `/ShipmentOrder/list/i/${ page }/s/${ perPage }`,
62
- params,
60
+ requestPayload: {
61
+ method: 'get',
62
+ url: `/ShipmentOrder/list/i/${ page }/s/${ perPage }`,
63
+ params,
64
+ },
63
65
  context: {
64
66
  credsPayload,
65
67
  apiVersion,
@@ -26,8 +26,10 @@ const logiwaProductGet = async (
26
26
  }
27
27
 
28
28
  return logiwaClient.fetch({
29
- method: 'get',
30
- url: `/Product/detail/${ productId }`,
29
+ requestPayload: {
30
+ method: 'get',
31
+ url: `/Product/detail/${ productId }`,
32
+ },
31
33
  context: {
32
34
  credsPayload,
33
35
  apiVersion,
@@ -45,9 +45,11 @@ const logiwaProductsGet = async (
45
45
  };
46
46
 
47
47
  return logiwaClient.fetch({
48
- method: 'get',
49
- url: `/Product/list/i/${ page }/s/${ perPage }`,
50
- params,
48
+ requestPayload: {
49
+ method: 'get',
50
+ url: `/Product/list/i/${ page }/s/${ perPage }`,
51
+ params,
52
+ },
51
53
  context: {
52
54
  credsPayload,
53
55
  apiVersion,
@@ -100,9 +100,11 @@ const logiwaReportGetAvailableToPromiseSingle = async (
100
100
  }
101
101
 
102
102
  return logiwaClient.fetch({
103
- method: 'get',
104
- url: `/Report/AvailableToPromise/i/${ page }/s/${ perPage }`,
105
- params,
103
+ requestPayload: {
104
+ method: 'get',
105
+ url: `/Report/AvailableToPromise/i/${ page }/s/${ perPage }`,
106
+ params,
107
+ },
106
108
  context: {
107
109
  credsPayload,
108
110
  apiVersion,
@@ -33,9 +33,11 @@ const logiwaReportGetInventoryCalculation = async (
33
33
  };
34
34
 
35
35
  return logiwaClient.fetch({
36
- method: 'get',
37
- url: `/Report/InventoryCalculation/i/${ page }/s/${ perPage }`,
38
- params,
36
+ requestPayload: {
37
+ method: 'get',
38
+ url: `/Report/InventoryCalculation/i/${ page }/s/${ perPage }`,
39
+ params,
40
+ },
39
41
  context: {
40
42
  credsPayload,
41
43
  apiVersion,
@@ -37,9 +37,11 @@ const logiwaReportGetInventorySnapshot = async (
37
37
  };
38
38
 
39
39
  return logiwaClient.fetch({
40
- method: 'get',
41
- url: `/Report/InventorySnapshot/i/${ page }/s/${ perPage }`,
42
- params,
40
+ requestPayload: {
41
+ method: 'get',
42
+ url: `/Report/InventorySnapshot/i/${ page }/s/${ perPage }`,
43
+ params,
44
+ },
43
45
  context: {
44
46
  credsPayload,
45
47
  apiVersion,
@@ -43,9 +43,11 @@ const logiwaReportGetTotalInventory = async (
43
43
  };
44
44
 
45
45
  return logiwaClient.fetch({
46
- method: 'get',
47
- url: `/Report/TotalInventory/i/${ page }/s/${ perPage }`,
48
- params,
46
+ requestPayload: {
47
+ method: 'get',
48
+ url: `/Report/TotalInventory/i/${ page }/s/${ perPage }`,
49
+ params,
50
+ },
49
51
  context: {
50
52
  credsPayload,
51
53
  apiVersion,
@@ -26,8 +26,10 @@ const logiwaWebhookStatusGet = async (
26
26
  }
27
27
 
28
28
  return logiwaClient.fetch({
29
- method: 'get',
30
- url: `/Webhook/status/${ subscriptionId }`,
29
+ requestPayload: {
30
+ method: 'get',
31
+ url: `/Webhook/status/${ subscriptionId }`,
32
+ },
31
33
  context: {
32
34
  credsPayload,
33
35
  apiVersion,
@@ -30,12 +30,14 @@ const logiwaWebhookSubscribe = async (
30
30
  }
31
31
 
32
32
  return logiwaClient.fetch({
33
- method: 'post',
34
- url: '/Webhook/create',
35
- body: {
36
- topic,
37
- address: url,
38
- ...(clientIdentifier ? { clientIdentifier } : { ignoreClient: true }),
33
+ requestPayload: {
34
+ method: 'post',
35
+ url: '/Webhook/create',
36
+ body: {
37
+ topic,
38
+ address: url,
39
+ ...(clientIdentifier ? { clientIdentifier } : { ignoreClient: true }),
40
+ },
39
41
  },
40
42
  context: {
41
43
  credsPayload,
@@ -26,8 +26,10 @@ const logiwaWebhookUnsubscribe = async (
26
26
  }
27
27
 
28
28
  return logiwaClient.fetch({
29
- method: 'delete',
30
- url: `/Webhook/unsubscribe/${ subscriptionId }`,
29
+ requestPayload: {
30
+ method: 'delete',
31
+ url: `/Webhook/unsubscribe/${ subscriptionId }`,
32
+ },
31
33
  context: {
32
34
  credsPayload,
33
35
  apiVersion,
@@ -21,8 +21,10 @@ const logiwaWebhooksGet = async (
21
21
  }
22
22
 
23
23
  return logiwaClient.fetch({
24
- method: 'get',
25
- url: '/Webhook/list',
24
+ requestPayload: {
25
+ method: 'get',
26
+ url: '/Webhook/list',
27
+ },
26
28
  context: {
27
29
  credsPayload,
28
30
  apiVersion,
@@ -1,13 +1,12 @@
1
1
  const { LOOP_API_BASE_URL } = require('../loop/loop.constants');
2
+ const { resolveCreds, useBaseUrl } = require('../pipelineSteps');
2
3
  const {
3
4
  FetchClient,
4
- Chain,
5
- appendUrlToBase,
6
5
  fetchClientCommonSteps,
7
6
  } = require('../utils');
8
7
 
9
8
  // TODO: Allow creds failure (e.g. missing API_KEY → INVALID_CREDS before fetch)
10
- const addUrlAndAuthHeaders = async (state) => {
9
+ const useAuthHeaders = async (state) => {
11
10
  const { requestPayload, context } = state;
12
11
  const { creds } = context;
13
12
  const { API_KEY } = creds;
@@ -15,9 +14,7 @@ const addUrlAndAuthHeaders = async (state) => {
15
14
  return {
16
15
  requestPayload: {
17
16
  ...requestPayload,
18
- url: appendUrlToBase(LOOP_API_BASE_URL, requestPayload.url),
19
17
  headers: {
20
- 'Content-Type': 'application/json',
21
18
  'X-Authorization': API_KEY,
22
19
  ...requestPayload.headers,
23
20
  },
@@ -25,17 +22,14 @@ const addUrlAndAuthHeaders = async (state) => {
25
22
  };
26
23
  };
27
24
 
28
- const loopClientRequestPreparer = new Chain([
29
- addUrlAndAuthHeaders,
30
- ]);
31
-
32
- const loopClientResponseInterpreter = new Chain([
33
- fetchClientCommonSteps.exitEarlyOnNotOk,
34
- ]);
35
-
36
25
  const loopClient = new FetchClient({
37
- requestPreparer: loopClientRequestPreparer,
38
- responseInterpreter: loopClientResponseInterpreter,
26
+ pipeline: [
27
+ resolveCreds,
28
+ useBaseUrl(LOOP_API_BASE_URL),
29
+ useAuthHeaders,
30
+ 'fetch',
31
+ fetchClientCommonSteps.exitEarlyOnNotOk,
32
+ ],
39
33
  });
40
34
 
41
35
  module.exports = {
@@ -1,4 +1,4 @@
1
- const { credsFromPayload, ArgsWarden, Getter } = require('../utils');
1
+ const { ArgsWarden, Getter } = require('../utils');
2
2
  const { credsValidator } = require('../validators');
3
3
  const { loopClient } = require('../loop/loop.utils');
4
4
  const { MAX_PER_PAGE } = require('../loop/loop.constants');
@@ -9,7 +9,7 @@ const argsWarden = new ArgsWarden([
9
9
  ]);
10
10
 
11
11
  const loopGetPacket = async (
12
- creds,
12
+ credsPayload,
13
13
  url,
14
14
  {
15
15
  params,
@@ -18,16 +18,18 @@ const loopGetPacket = async (
18
18
  } = {},
19
19
  ) => {
20
20
  return loopClient.fetch({
21
- url,
22
- ...(paginate && {
23
- params: {
24
- paginate: true,
25
- pageSize: perPage,
26
- ...params,
27
- },
28
- }),
21
+ requestPayload: {
22
+ url,
23
+ ...(paginate && {
24
+ params: {
25
+ paginate: true,
26
+ pageSize: perPage,
27
+ ...params,
28
+ },
29
+ }),
30
+ },
29
31
  context: {
30
- creds,
32
+ credsPayload,
31
33
  },
32
34
  });
33
35
  };
@@ -44,10 +46,10 @@ const loopGetPaginator = async (currentParams, response) => {
44
46
  return [true];
45
47
  }
46
48
 
47
- const [creds] = args;
49
+ const [credsPayload] = args;
48
50
 
49
51
  return [false, {
50
- args: [creds, nextPageUrl],
52
+ args: [credsPayload, nextPageUrl],
51
53
  options: {
52
54
  paginate: false,
53
55
  },
@@ -75,13 +77,9 @@ const loopGet = async (
75
77
  return rejectResponse;
76
78
  }
77
79
 
78
- const creds = await credsFromPayload(credsPayload);
79
-
80
- let firstError = null;
81
-
82
80
  const getter = new Getter(
83
81
  {
84
- args: [creds, url],
82
+ args: [credsPayload, url],
85
83
  options: {
86
84
  params,
87
85
  perPage,
@@ -91,7 +89,6 @@ const loopGet = async (
91
89
  func: loopGetPacket,
92
90
  digester: (response) => {
93
91
  if (!response?.ok) {
94
- firstError = response;
95
92
  return [];
96
93
  }
97
94
 
@@ -112,11 +109,10 @@ const loopGet = async (
112
109
 
113
110
  const data = await getter.run({ returnAll: true });
114
111
 
115
- if (firstError) {
116
- return firstError;
117
- }
118
-
119
- return data;
112
+ return {
113
+ ok: true,
114
+ data,
115
+ };
120
116
  };
121
117
 
122
118
  const funcApiConfig = {
@@ -1,6 +1,6 @@
1
1
  // https://docs.loopreturns.com/api-reference/latest/return-data/get-return-details
2
2
 
3
- const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
3
+ const { objHasAny, ArgsWarden } = require('../utils');
4
4
  const { credsValidator } = require('../validators');
5
5
  const { loopClient } = require('../loop/loop.utils');
6
6
 
@@ -37,8 +37,6 @@ const loopReturnGet = async (
37
37
  orderName,
38
38
  } = returnIdentifier;
39
39
 
40
- const creds = await credsFromPayload(credsPayload);
41
-
42
40
  const params = {
43
41
  ...returnId && { return_id: returnId },
44
42
  ...orderId && { order_id: orderId },
@@ -46,10 +44,12 @@ const loopReturnGet = async (
46
44
  };
47
45
 
48
46
  return loopClient.fetch({
49
- url: '/warehouse/return/details',
50
- params,
47
+ requestPayload: {
48
+ url: '/warehouse/return/details',
49
+ params,
50
+ },
51
51
  context: {
52
- creds,
52
+ credsPayload,
53
53
  },
54
54
  });
55
55
  };