@foxtware/mineral 0.1.7 → 0.1.9

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 (59) hide show
  1. package/.creds.yml.sample +22 -1
  2. package/api/loop/loop.constants.js +7 -0
  3. package/api/loop/loop.utils.js +43 -0
  4. package/api/loop/loopAllowlistItemsGet.js +42 -0
  5. package/api/loop/loopBlocklistItemsGet.js +46 -0
  6. package/api/loop/loopDestinationsGet.js +42 -0
  7. package/api/loop/loopGet.js +143 -0
  8. package/api/loop/loopReturnGet.js +73 -0
  9. package/api/loop/loopReturnsGet.js +46 -0
  10. package/api/peoplevox/peoplevox.sessions.js +87 -0
  11. package/api/peoplevox/peoplevox.utils.js +7 -15
  12. package/api/shopify/shopifyCollectionGet.js +1 -1
  13. package/api/shopify/shopifyTagsAdd.js +1 -1
  14. package/api/shopify/shopifyTagsRemove.js +1 -1
  15. package/api/stripe/_example.js +48 -0
  16. package/api/stripe/stripe.constants.js +5 -0
  17. package/api/stripe/stripe.utils.js +47 -0
  18. package/api/stripe/stripeCardCharge.js +98 -0
  19. package/api/stripe/stripeCardTokenCreate.js +70 -0
  20. package/api/stripe/stripeChargeCapture.js +63 -0
  21. package/api/stripe/stripeChargeCreate.js +70 -0
  22. package/api/stripe/stripeChargeGet.js +51 -0
  23. package/api/stripe/stripeChargesGet.js +52 -0
  24. package/api/stripe/stripeRefundCreate.js +64 -0
  25. package/api/stripe/stripeRefundGet.js +51 -0
  26. package/api/stripe/stripeRefundsGet.js +52 -0
  27. package/api/stripe/stripeTokenGet.js +51 -0
  28. package/api/supabase/supabase.utils.js +52 -0
  29. package/api/supabase/supabaseRowDelete.js +95 -0
  30. package/api/supabase/supabaseRowGet.js +58 -0
  31. package/api/supabase/supabaseRowInsert.js +56 -0
  32. package/api/supabase/supabaseRowUpdate.js +58 -0
  33. package/api/supabase/supabaseRpc.js +61 -0
  34. package/api/supabase/supabaseTableGet.js +44 -0
  35. package/api/supabase/supabaseTableGetAll.js +86 -0
  36. package/api/upstash/upstash.utils.js +36 -0
  37. package/api/upstash/upstashDel.js +46 -0
  38. package/api/upstash/upstashExists.js +46 -0
  39. package/api/upstash/upstashGet.js +46 -0
  40. package/api/upstash/upstashSet.js +64 -0
  41. package/api/utils.js +52 -1
  42. package/api/workable/workable.constants.js +3 -0
  43. package/api/workable/workable.utils.js +46 -0
  44. package/api/workable/workableGet.js +146 -0
  45. package/api/workable/workableJobCandidateCreate.js +87 -0
  46. package/api/workable/workableJobGet.js +52 -0
  47. package/api/workable/workableJobMembersGet.js +52 -0
  48. package/api/workable/workableJobStagesGet.js +52 -0
  49. package/api/workable/workableJobsGet.js +78 -0
  50. package/bin/mineral.js +6 -0
  51. package/hosting/.hosting.yml.sample +9 -11
  52. package/hosting/copyCredsToEnv.js +58 -2
  53. package/hosting/deployFromHostingYml.js +9 -2
  54. package/hosting/generateHosted.js +22 -2
  55. package/hosting/hosting.utils.js +3 -2
  56. package/hosting/hostingPreview.js +160 -0
  57. package/hosting/wrappers.js +1 -1
  58. package/package.json +9 -2
  59. package/server.utils.js +1 -0
package/.creds.yml.sample CHANGED
@@ -26,4 +26,25 @@ linear:
26
26
  API_KEY: _______________________________
27
27
 
28
28
  slack:
29
- BOT_TOKEN: xoxb________________________________
29
+ BOT_TOKEN: xoxb_________________________
30
+
31
+ workable:
32
+ BASE_URL: https://[subdomain].workable.com/spi/v3
33
+ ACCESS_TOKEN: __________________________
34
+
35
+ loop:
36
+ au:
37
+ API_KEY: _____________________________
38
+
39
+ upstash:
40
+ BASE_URL: https://________.upstash.io
41
+ TOKEN: ______________________________
42
+
43
+ supabase:
44
+ project:
45
+ BASE_URL: https://_____.supabase.co
46
+ API_KEY: __________________________
47
+
48
+ stripe:
49
+ API_KEY: sk__________________________
50
+
@@ -0,0 +1,7 @@
1
+ const LOOP_API_BASE_URL = 'https://api.loopreturns.com/api/v1';
2
+ const MAX_PER_PAGE = 750;
3
+
4
+ module.exports = {
5
+ LOOP_API_BASE_URL,
6
+ MAX_PER_PAGE,
7
+ };
@@ -0,0 +1,43 @@
1
+ const { LOOP_API_BASE_URL } = require('../loop/loop.constants');
2
+ const {
3
+ FetchClient,
4
+ Chain,
5
+ appendUrlToBase,
6
+ fetchClientCommonSteps,
7
+ } = require('../utils');
8
+
9
+ // TODO: Allow creds failure (e.g. missing API_KEY → INVALID_CREDS before fetch)
10
+ const addUrlAndAuthHeaders = async (state) => {
11
+ const { requestPayload, context } = state;
12
+ const { creds } = context;
13
+ const { API_KEY } = creds;
14
+
15
+ return {
16
+ requestPayload: {
17
+ ...requestPayload,
18
+ url: appendUrlToBase(LOOP_API_BASE_URL, requestPayload.url),
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ 'X-Authorization': API_KEY,
22
+ ...requestPayload.headers,
23
+ },
24
+ },
25
+ };
26
+ };
27
+
28
+ const loopClientRequestPreparer = new Chain([
29
+ addUrlAndAuthHeaders,
30
+ ]);
31
+
32
+ const loopClientResponseInterpreter = new Chain([
33
+ fetchClientCommonSteps.exitEarlyOnNotOk,
34
+ ]);
35
+
36
+ const loopClient = new FetchClient({
37
+ requestPreparer: loopClientRequestPreparer,
38
+ responseInterpreter: loopClientResponseInterpreter,
39
+ });
40
+
41
+ module.exports = {
42
+ loopClient,
43
+ };
@@ -0,0 +1,42 @@
1
+ const { ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { loopGet } = require('../loop/loopGet');
4
+
5
+ const argsWarden = new ArgsWarden([
6
+ ['credsPayload', credsValidator],
7
+ ]);
8
+
9
+ const loopAllowlistItemsGet = async (
10
+ credsPayload,
11
+ {
12
+ ...getterOptions
13
+ } = {},
14
+ ) => {
15
+
16
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
17
+ if (rejectResponse) {
18
+ return rejectResponse;
19
+ }
20
+
21
+ return loopGet(credsPayload, '/allowlists', {
22
+ resultsKey: 'data',
23
+ ...getterOptions,
24
+ });
25
+ };
26
+
27
+ const funcApiConfig = {
28
+ argsWarden,
29
+ };
30
+
31
+ module.exports = {
32
+ loopAllowlistItemsGet,
33
+ funcApiConfig,
34
+ };
35
+
36
+ /*
37
+ curl -X POST "http://localhost:8000/loopAllowlistItemsGet" \
38
+ -H "Content-Type: application/json" \
39
+ -d '{
40
+ "credsPayload": { "credsPath": "loop.au" }
41
+ }'
42
+ */
@@ -0,0 +1,46 @@
1
+ const { ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { loopGet } = require('../loop/loopGet');
4
+
5
+ const argsWarden = new ArgsWarden([
6
+ ['credsPayload', credsValidator],
7
+ ]);
8
+
9
+ const loopBlocklistItemsGet = async (
10
+ credsPayload,
11
+ {
12
+ ...getterOptions
13
+ } = {},
14
+ ) => {
15
+
16
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
17
+ if (rejectResponse) {
18
+ return rejectResponse;
19
+ }
20
+
21
+ return loopGet(credsPayload, '/blocklists', {
22
+ resultsKey: 'data',
23
+ ...getterOptions,
24
+ });
25
+ };
26
+
27
+ const funcApiConfig = {
28
+ argsWarden,
29
+ };
30
+
31
+ module.exports = {
32
+ loopBlocklistItemsGet,
33
+ funcApiConfig,
34
+ };
35
+
36
+ /*
37
+ curl -X POST "http://localhost:8000/loopBlocklistItemsGet" \
38
+ -H "Content-Type: application/json" \
39
+ -d '{
40
+ "credsPayload": { "credsPath": "loop.au" },
41
+ "options": {
42
+ "limit": 20,
43
+ "perPage": 7
44
+ }
45
+ }'
46
+ */
@@ -0,0 +1,42 @@
1
+ const { ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { loopGet } = require('../loop/loopGet');
4
+
5
+ const argsWarden = new ArgsWarden([
6
+ ['credsPayload', credsValidator],
7
+ ]);
8
+
9
+ const loopDestinationsGet = async (
10
+ credsPayload,
11
+ {
12
+ ...getterOptions
13
+ } = {},
14
+ ) => {
15
+
16
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
17
+ if (rejectResponse) {
18
+ return rejectResponse;
19
+ }
20
+
21
+ return loopGet(credsPayload, '/destinations', {
22
+ resultsKey: 'destinations',
23
+ ...getterOptions,
24
+ });
25
+ };
26
+
27
+ const funcApiConfig = {
28
+ argsWarden,
29
+ };
30
+
31
+ module.exports = {
32
+ loopDestinationsGet,
33
+ funcApiConfig,
34
+ };
35
+
36
+ /*
37
+ curl -X POST "http://localhost:8000/loopDestinationsGet" \
38
+ -H "Content-Type: application/json" \
39
+ -d '{
40
+ "credsPayload": { "credsPath": "loop.au" }
41
+ }'
42
+ */
@@ -0,0 +1,143 @@
1
+ const { credsFromPayload, ArgsWarden, Getter } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { loopClient } = require('../loop/loop.utils');
4
+ const { MAX_PER_PAGE } = require('../loop/loop.constants');
5
+
6
+ const argsWarden = new ArgsWarden([
7
+ ['credsPayload', credsValidator],
8
+ ['url'],
9
+ ]);
10
+
11
+ const loopGetPacket = async (
12
+ creds,
13
+ url,
14
+ {
15
+ params,
16
+ perPage = MAX_PER_PAGE,
17
+ paginate = true,
18
+ } = {},
19
+ ) => {
20
+ return loopClient.fetch({
21
+ url,
22
+ ...(paginate && {
23
+ params: {
24
+ paginate: true,
25
+ pageSize: perPage,
26
+ ...params,
27
+ },
28
+ }),
29
+ context: {
30
+ creds,
31
+ },
32
+ });
33
+ };
34
+
35
+ const loopGetPaginator = async (currentParams, response) => {
36
+ const { args } = currentParams;
37
+
38
+ if (!response?.ok) {
39
+ return [true];
40
+ }
41
+
42
+ const nextPageUrl = response?.data?.nextPageUrl;
43
+ if (!nextPageUrl) {
44
+ return [true];
45
+ }
46
+
47
+ const [creds] = args;
48
+
49
+ return [false, {
50
+ args: [creds, nextPageUrl],
51
+ options: {
52
+ paginate: false,
53
+ },
54
+ }];
55
+ };
56
+
57
+ const loopGet = async (
58
+ returnGetter,
59
+
60
+ credsPayload,
61
+ url,
62
+ {
63
+ params,
64
+ perPage = MAX_PER_PAGE,
65
+ resultsKey,
66
+ ...getterOptions
67
+ } = {},
68
+ ) => {
69
+
70
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
71
+ credsPayload,
72
+ url,
73
+ });
74
+ if (rejectResponse) {
75
+ return rejectResponse;
76
+ }
77
+
78
+ const creds = await credsFromPayload(credsPayload);
79
+
80
+ let firstError = null;
81
+
82
+ const getter = new Getter(
83
+ {
84
+ args: [creds, url],
85
+ options: {
86
+ params,
87
+ perPage,
88
+ },
89
+ },
90
+ {
91
+ func: loopGetPacket,
92
+ digester: (response) => {
93
+ if (!response?.ok) {
94
+ firstError = response;
95
+ return [];
96
+ }
97
+
98
+ if (resultsKey) {
99
+ return response?.data?.[resultsKey] ?? [];
100
+ }
101
+
102
+ return [];
103
+ },
104
+ paginator: loopGetPaginator,
105
+ ...getterOptions,
106
+ },
107
+ );
108
+
109
+ if (returnGetter) {
110
+ return getter;
111
+ }
112
+
113
+ const data = await getter.run({ returnAll: true });
114
+
115
+ if (firstError) {
116
+ return firstError;
117
+ }
118
+
119
+ return data;
120
+ };
121
+
122
+ const funcApiConfig = {
123
+ argsWarden,
124
+ };
125
+
126
+ module.exports = {
127
+ loopGet: (...args) => loopGet(false, ...args),
128
+ loopGetter: (...args) => loopGet(true, ...args),
129
+ funcApiConfig,
130
+ };
131
+
132
+ /*
133
+ curl -X POST "http://localhost:8000/loopGet" \
134
+ -H "Content-Type: application/json" \
135
+ -d '{
136
+ "credsPayload": { "credsPath": "loop.au" },
137
+ "url": "/warehouse/return/list",
138
+ "options": {
139
+ "resultsKey": "returns",
140
+ "limit": 10
141
+ }
142
+ }'
143
+ */
@@ -0,0 +1,73 @@
1
+ // https://docs.loopreturns.com/api-reference/latest/return-data/get-return-details
2
+
3
+ const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { loopClient } = require('../loop/loop.utils');
6
+
7
+ const returnIdentifierValidator = (returnIdentifier) => {
8
+ return objHasAny(returnIdentifier, [
9
+ 'returnId',
10
+ 'orderId',
11
+ 'orderName',
12
+ ]);
13
+ };
14
+
15
+ const argsWarden = new ArgsWarden([
16
+ ['credsPayload', credsValidator],
17
+ ['returnIdentifier', returnIdentifierValidator],
18
+ ]);
19
+
20
+ const loopReturnGet = async (
21
+ credsPayload,
22
+ returnIdentifier,
23
+ options = {},
24
+ ) => {
25
+
26
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
27
+ credsPayload,
28
+ returnIdentifier,
29
+ });
30
+ if (rejectResponse) {
31
+ return rejectResponse;
32
+ }
33
+
34
+ const {
35
+ returnId,
36
+ orderId,
37
+ orderName,
38
+ } = returnIdentifier;
39
+
40
+ const creds = await credsFromPayload(credsPayload);
41
+
42
+ const params = {
43
+ ...returnId && { return_id: returnId },
44
+ ...orderId && { order_id: orderId },
45
+ ...orderName && { order_name: orderName },
46
+ };
47
+
48
+ return loopClient.fetch({
49
+ url: '/warehouse/return/details',
50
+ params,
51
+ context: {
52
+ creds,
53
+ },
54
+ });
55
+ };
56
+
57
+ const funcApiConfig = {
58
+ argsWarden,
59
+ };
60
+
61
+ module.exports = {
62
+ loopReturnGet,
63
+ funcApiConfig,
64
+ };
65
+
66
+ /*
67
+ curl -X POST "http://localhost:8000/loopReturnGet" \
68
+ -H "Content-Type: application/json" \
69
+ -d '{
70
+ "credsPayload": { "credsPath": "loop.au" },
71
+ "returnIdentifier": { "returnId": "85747906" }
72
+ }'
73
+ */
@@ -0,0 +1,46 @@
1
+ const { ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { loopGet } = require('../loop/loopGet');
4
+
5
+ const argsWarden = new ArgsWarden([
6
+ ['credsPayload', credsValidator],
7
+ ]);
8
+
9
+ const loopReturnsGet = async (
10
+ credsPayload,
11
+ {
12
+ ...getterOptions
13
+ } = {},
14
+ ) => {
15
+
16
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
17
+ if (rejectResponse) {
18
+ return rejectResponse;
19
+ }
20
+
21
+ return loopGet(credsPayload, '/warehouse/return/list', {
22
+ resultsKey: 'returns',
23
+ ...getterOptions,
24
+ });
25
+ };
26
+
27
+ const funcApiConfig = {
28
+ argsWarden,
29
+ };
30
+
31
+ module.exports = {
32
+ loopReturnsGet,
33
+ funcApiConfig,
34
+ };
35
+
36
+ /*
37
+ curl -X POST "http://localhost:8000/loopReturnsGet" \
38
+ -H "Content-Type: application/json" \
39
+ -d '{
40
+ "credsPayload": { "credsPath": "loop.au" },
41
+ "options": {
42
+ "limit": 20,
43
+ "perPage": 7
44
+ }
45
+ }'
46
+ */
@@ -0,0 +1,87 @@
1
+ const { HOSTED } = require('../constants');
2
+ const { credsFromPayload } = require('../utils');
3
+ const { peoplevoxAuthGet } = require('./peoplevoxAuthGet');
4
+
5
+ // TODO: Track where auth comes from in order to facilitate retrying
6
+ // TODO: Consider only storing auth when successful request goes through
7
+
8
+ const SESSION_IDS = new Map();
9
+
10
+ const getSessionId = async (credsPayload) => {
11
+ const { CLIENT_ID } = await credsFromPayload(credsPayload);
12
+
13
+ let sessionId = SESSION_IDS.get(CLIENT_ID);
14
+
15
+ if (sessionId) {
16
+ !HOSTED && console.log('Peoplevox auth: from memory');
17
+ return {
18
+ ok: true,
19
+ data: sessionId,
20
+ meta: {
21
+ source: 'memory',
22
+ },
23
+ };
24
+ }
25
+
26
+ const authResponse = await peoplevoxAuthGet(credsPayload);
27
+
28
+ if (!authResponse.ok) {
29
+ return authResponse;
30
+ }
31
+
32
+ const { Detail } = authResponse?.data?.['soap:Envelope']?.['soap:Body']?.['AuthenticateResponse']?.['AuthenticateResult'];
33
+ const [, responseSessionId] = Detail.split(',');
34
+
35
+ SESSION_IDS.set(CLIENT_ID, responseSessionId);
36
+ !HOSTED && console.log('Peoplevox auth: from API');
37
+ return {
38
+ ok: true,
39
+ data: responseSessionId,
40
+ meta: {
41
+ source: 'api',
42
+ },
43
+ };
44
+ };
45
+
46
+ const setSessionId = async (credsPayload, sessionId) => {
47
+ const { CLIENT_ID } = await credsFromPayload(credsPayload);
48
+ SESSION_IDS.set(CLIENT_ID, sessionId);
49
+ };
50
+
51
+ const withPeoplevoxAuth = async (fetchPayload, next) => {
52
+ const { context = {} } = fetchPayload;
53
+ const { credsPayload } = context;
54
+
55
+ const sessionIdResponse = await getSessionId(credsPayload);
56
+
57
+ const {
58
+ ok: sessionIdOk,
59
+ data: sessionId,
60
+ } = sessionIdResponse;
61
+
62
+ if (!sessionIdOk) {
63
+ return sessionIdResponse;
64
+ }
65
+
66
+ const response = await next({
67
+ ...fetchPayload,
68
+ context: {
69
+ ...context,
70
+ sessionId,
71
+ },
72
+ });
73
+
74
+ if (response.ok) {
75
+ await setSessionId(credsPayload, sessionId);
76
+ return response;
77
+ }
78
+
79
+ // TODO: Check if it was an auth error, and try another auth method if so
80
+ return response;
81
+ };
82
+
83
+ module.exports = {
84
+ getSessionId,
85
+ setSessionId,
86
+ withPeoplevoxAuth,
87
+ };
@@ -1,7 +1,7 @@
1
1
  const csvtojson = require('csvtojson');
2
2
  const xml2js = require('xml2js');
3
3
  const { FetchClient, credsFromPayload, appendUrlToBase, logDeep, Chain } = require('../utils');
4
- const { peoplevoxAuthGet } = require('../peoplevox/peoplevoxAuthGet');
4
+ const { withPeoplevoxAuth } = require('../peoplevox/peoplevox.sessions');
5
5
 
6
6
  const xml2jsBuilder = new xml2js.Builder({
7
7
  headless: true,
@@ -48,21 +48,11 @@ const buildSoapEnvelope = ({
48
48
  // TODO: Split into multiple steps, allow mutating context
49
49
  const peoplevoxRequestPreparer = async (requestPayload, context) => {
50
50
  const { headers, body } = requestPayload;
51
- const { credsPayload, action } = context;
52
- let { sessionId: localSessionId } = context;
51
+ const { credsPayload, action, sessionId } = context;
53
52
  const { CLIENT_ID } = await credsFromPayload(credsPayload);
54
53
 
55
- if (!localSessionId) {
56
- const authResponse = await peoplevoxAuthGet(credsPayload);
57
-
58
- if (!authResponse.ok) {
59
- return { ...authResponse, breakChain: true };
60
- }
61
-
62
- const { Detail } = authResponse?.data?.['soap:Envelope']?.['soap:Body']?.['AuthenticateResponse']?.['AuthenticateResult'];
63
- const [, responseSessionId] = Detail.split(',');
64
-
65
- localSessionId = responseSessionId;
54
+ if (!sessionId) {
55
+ throw new Error('PeopleVox sessionId is required');
66
56
  }
67
57
 
68
58
  const baseUrl = `https://ap.peoplevox.net/${ CLIENT_ID }/Resources/IntegrationServicev4.asmx`;
@@ -71,7 +61,7 @@ const peoplevoxRequestPreparer = async (requestPayload, context) => {
71
61
  action,
72
62
  body,
73
63
  clientId: CLIENT_ID,
74
- sessionId: localSessionId,
64
+ sessionId,
75
65
  });
76
66
 
77
67
  logDeep({ envelopeXml });
@@ -186,6 +176,8 @@ const peoplevoxClient = new FetchClient({
186
176
  ]),
187
177
  });
188
178
 
179
+ peoplevoxClient.use(withPeoplevoxAuth);
180
+
189
181
  module.exports = {
190
182
  peoplevoxClient,
191
183
  };
@@ -75,7 +75,7 @@ const shopifyCollectionGet = async (
75
75
  return shopifyGetSingle(
76
76
  credsPayload,
77
77
  'collection',
78
- collectionIdentifier,
78
+ id,
79
79
  {
80
80
  apiVersion,
81
81
  attrs,
@@ -7,7 +7,7 @@ const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
7
7
  const argsWarden = new ArgsWarden([
8
8
  ['credsPayload', credsValidator],
9
9
  ['gid'],
10
- ['tags', Array],
10
+ ['tags', Array.isArray],
11
11
  ]);
12
12
 
13
13
  const defaultAttrs = 'id';
@@ -7,7 +7,7 @@ const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
7
7
  const argsWarden = new ArgsWarden([
8
8
  ['credsPayload', credsValidator],
9
9
  ['gid'],
10
- ['tags', Array],
10
+ ['tags', Array.isArray],
11
11
  ]);
12
12
 
13
13
  const defaultAttrs = 'id';
@@ -0,0 +1,48 @@
1
+ const { credsFromPayload, ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { stripeClient } = require('../stripe/stripe.utils');
4
+
5
+ const argsWarden = new ArgsWarden([
6
+ ['credsPayload', credsValidator],
7
+ ['arg'],
8
+ ]);
9
+
10
+ const FUNC = async (
11
+ credsPayload,
12
+ arg,
13
+ ) => {
14
+
15
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, arg });
16
+ if (rejectResponse) {
17
+ return rejectResponse;
18
+ }
19
+
20
+ const creds = await credsFromPayload(credsPayload);
21
+
22
+ const response = await stripeClient.fetch({
23
+ url: '/things',
24
+ method: 'post',
25
+ body: { arg },
26
+ context: { creds },
27
+ });
28
+
29
+ return response;
30
+ };
31
+
32
+ const funcApiConfig = {
33
+ argsWarden,
34
+ };
35
+
36
+ module.exports = {
37
+ FUNC,
38
+ funcApiConfig,
39
+ };
40
+
41
+ /*
42
+ curl -X POST "http://localhost:8000/FUNC" \
43
+ -H "Content-Type: application/json" \
44
+ -d '{
45
+ "credsPayload": { "credsPath": "stripe" },
46
+ "arg": "1234"
47
+ }'
48
+ */
@@ -0,0 +1,5 @@
1
+ const BASE_URL = 'https://api.stripe.com/v1';
2
+
3
+ module.exports = {
4
+ BASE_URL,
5
+ };