@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
@@ -0,0 +1,47 @@
1
+ const { BASE_URL } = require('../stripe/stripe.constants');
2
+ const {
3
+ FetchClient,
4
+ Chain,
5
+ appendUrlToBase,
6
+ fetchClientCommonSteps,
7
+ } = require('../utils');
8
+
9
+ const addUrlAndAuthHeaders = async (state) => {
10
+ const { requestPayload, context } = state;
11
+ const { creds } = context;
12
+ const { API_KEY } = creds;
13
+
14
+ const body = requestPayload.body
15
+ ? new URLSearchParams(requestPayload.body).toString()
16
+ : undefined;
17
+
18
+ return {
19
+ requestPayload: {
20
+ ...requestPayload,
21
+ url: appendUrlToBase(BASE_URL, requestPayload.url),
22
+ headers: {
23
+ 'Content-Type': 'application/x-www-form-urlencoded',
24
+ Authorization: `Bearer ${ API_KEY }`,
25
+ ...requestPayload.headers,
26
+ },
27
+ ...(body && { body }),
28
+ },
29
+ };
30
+ };
31
+
32
+ const stripeClientRequestPreparer = new Chain([
33
+ addUrlAndAuthHeaders,
34
+ ]);
35
+
36
+ const stripeClientResponseInterpreter = new Chain([
37
+ fetchClientCommonSteps.exitEarlyOnNotOk,
38
+ ]);
39
+
40
+ const stripeClient = new FetchClient({
41
+ requestPreparer: stripeClientRequestPreparer,
42
+ responseInterpreter: stripeClientResponseInterpreter,
43
+ });
44
+
45
+ module.exports = {
46
+ stripeClient,
47
+ };
@@ -0,0 +1,98 @@
1
+ const { ArgsWarden } = require('../utils');
2
+ const { credsValidator } = require('../validators');
3
+ const { stripeCardTokenCreate } = require('../stripe/stripeCardTokenCreate');
4
+ const { stripeChargeCreate } = require('../stripe/stripeChargeCreate');
5
+
6
+ const argsWarden = new ArgsWarden([
7
+ ['credsPayload', credsValidator],
8
+ ['cardNumber'],
9
+ ['expiryMonth'],
10
+ ['expiryYear'],
11
+ ['cvc'],
12
+ ['amountCents'],
13
+ ['currency'],
14
+ ['description'],
15
+ ]);
16
+
17
+ const stripeCardCharge = async (
18
+ credsPayload,
19
+ cardNumber,
20
+ expiryMonth,
21
+ expiryYear,
22
+ cvc,
23
+ amountCents,
24
+ currency,
25
+ description,
26
+ ) => {
27
+
28
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
29
+ credsPayload,
30
+ cardNumber,
31
+ expiryMonth,
32
+ expiryYear,
33
+ cvc,
34
+ amountCents,
35
+ currency,
36
+ description,
37
+ });
38
+ if (rejectResponse) {
39
+ return rejectResponse;
40
+ }
41
+
42
+ const cardTokenResponse = await stripeCardTokenCreate(
43
+ credsPayload,
44
+ cardNumber,
45
+ expiryMonth,
46
+ expiryYear,
47
+ cvc,
48
+ );
49
+
50
+ if (!cardTokenResponse?.ok) {
51
+ return cardTokenResponse;
52
+ }
53
+
54
+ const cardToken = cardTokenResponse?.data?.id;
55
+
56
+ if (!cardToken) {
57
+ return {
58
+ ok: false,
59
+ error: {
60
+ message: 'Failed to create card token',
61
+ },
62
+ };
63
+ }
64
+
65
+ const chargeResponse = await stripeChargeCreate(
66
+ credsPayload,
67
+ amountCents,
68
+ currency,
69
+ cardToken,
70
+ description,
71
+ );
72
+
73
+ return chargeResponse;
74
+ };
75
+
76
+ const funcApiConfig = {
77
+ argsWarden,
78
+ };
79
+
80
+ module.exports = {
81
+ stripeCardCharge,
82
+ funcApiConfig,
83
+ };
84
+
85
+ /*
86
+ curl -X POST "http://localhost:8000/stripeCardCharge" \
87
+ -H "Content-Type: application/json" \
88
+ -d '{
89
+ "credsPayload": { "credsPath": "stripe" },
90
+ "cardNumber": "4242424242424242",
91
+ "expiryMonth": "01",
92
+ "expiryYear": "2026",
93
+ "cvc": "123",
94
+ "currency": "AUD",
95
+ "description": "Transaction helper",
96
+ "amountCents": "50"
97
+ }'
98
+ */
@@ -0,0 +1,70 @@
1
+ // https://docs.stripe.com/api/tokens/create_card
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['cardNumber'],
10
+ ['expiryMonth'],
11
+ ['expiryYear'],
12
+ ['cvc'],
13
+ ]);
14
+
15
+ const stripeCardTokenCreate = async (
16
+ credsPayload,
17
+ cardNumber,
18
+ expiryMonth,
19
+ expiryYear,
20
+ cvc,
21
+ ) => {
22
+
23
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
24
+ credsPayload,
25
+ cardNumber,
26
+ expiryMonth,
27
+ expiryYear,
28
+ cvc,
29
+ });
30
+ if (rejectResponse) {
31
+ return rejectResponse;
32
+ }
33
+
34
+ const creds = await credsFromPayload(credsPayload);
35
+
36
+ const response = await stripeClient.fetch({
37
+ url: '/tokens',
38
+ method: 'post',
39
+ body: {
40
+ 'card[number]': cardNumber,
41
+ 'card[exp_month]': expiryMonth,
42
+ 'card[exp_year]': expiryYear,
43
+ 'card[cvc]': cvc,
44
+ },
45
+ context: { creds },
46
+ });
47
+
48
+ return response;
49
+ };
50
+
51
+ const funcApiConfig = {
52
+ argsWarden,
53
+ };
54
+
55
+ module.exports = {
56
+ stripeCardTokenCreate,
57
+ funcApiConfig,
58
+ };
59
+
60
+ /*
61
+ curl -X POST "http://localhost:8000/stripeCardTokenCreate" \
62
+ -H "Content-Type: application/json" \
63
+ -d '{
64
+ "credsPayload": { "credsPath": "stripe" },
65
+ "cardNumber": "4242424242424242",
66
+ "expiryMonth": "01",
67
+ "expiryYear": "2030",
68
+ "cvc": "123"
69
+ }'
70
+ */
@@ -0,0 +1,63 @@
1
+ // https://docs.stripe.com/api/charges/capture
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['chargeId'],
10
+ ]);
11
+
12
+ const stripeChargeCapture = async (
13
+ credsPayload,
14
+ chargeId,
15
+ {
16
+ amountCents,
17
+ } = {},
18
+ ) => {
19
+
20
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
21
+ credsPayload,
22
+ chargeId,
23
+ });
24
+ if (rejectResponse) {
25
+ return rejectResponse;
26
+ }
27
+
28
+ const creds = await credsFromPayload(credsPayload);
29
+
30
+ const response = await stripeClient.fetch({
31
+ url: `/charges/${ chargeId }/capture`,
32
+ method: 'post',
33
+ ...(amountCents && {
34
+ body: {
35
+ amount: amountCents,
36
+ },
37
+ }),
38
+ context: { creds },
39
+ });
40
+
41
+ return response;
42
+ };
43
+
44
+ const funcApiConfig = {
45
+ argsWarden,
46
+ };
47
+
48
+ module.exports = {
49
+ stripeChargeCapture,
50
+ funcApiConfig,
51
+ };
52
+
53
+ /*
54
+ curl -X POST "http://localhost:8000/stripeChargeCapture" \
55
+ -H "Content-Type: application/json" \
56
+ -d '{
57
+ "credsPayload": { "credsPath": "stripe" },
58
+ "chargeId": "ch_123",
59
+ "options": {
60
+ "amountCents": "100"
61
+ }
62
+ }'
63
+ */
@@ -0,0 +1,70 @@
1
+ // https://docs.stripe.com/api/charges/create
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['amountCents'],
10
+ ['currency'],
11
+ ['source'],
12
+ ['description'],
13
+ ]);
14
+
15
+ const stripeChargeCreate = async (
16
+ credsPayload,
17
+ amountCents,
18
+ currency,
19
+ source,
20
+ description,
21
+ ) => {
22
+
23
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
24
+ credsPayload,
25
+ amountCents,
26
+ currency,
27
+ source,
28
+ description,
29
+ });
30
+ if (rejectResponse) {
31
+ return rejectResponse;
32
+ }
33
+
34
+ const creds = await credsFromPayload(credsPayload);
35
+
36
+ const response = await stripeClient.fetch({
37
+ url: '/charges',
38
+ method: 'post',
39
+ body: {
40
+ amount: amountCents,
41
+ currency,
42
+ source,
43
+ description,
44
+ },
45
+ context: { creds },
46
+ });
47
+
48
+ return response;
49
+ };
50
+
51
+ const funcApiConfig = {
52
+ argsWarden,
53
+ };
54
+
55
+ module.exports = {
56
+ stripeChargeCreate,
57
+ funcApiConfig,
58
+ };
59
+
60
+ /*
61
+ curl -X POST "http://localhost:8000/stripeChargeCreate" \
62
+ -H "Content-Type: application/json" \
63
+ -d '{
64
+ "credsPayload": { "credsPath": "stripe" },
65
+ "amountCents": "100",
66
+ "currency": "AUD",
67
+ "source": "tok_visa",
68
+ "description": "small charge"
69
+ }'
70
+ */
@@ -0,0 +1,51 @@
1
+ // https://docs.stripe.com/api/charges/retrieve
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['chargeId'],
10
+ ]);
11
+
12
+ const stripeChargeGet = async (
13
+ credsPayload,
14
+ chargeId,
15
+ ) => {
16
+
17
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
18
+ credsPayload,
19
+ chargeId,
20
+ });
21
+ if (rejectResponse) {
22
+ return rejectResponse;
23
+ }
24
+
25
+ const creds = await credsFromPayload(credsPayload);
26
+
27
+ const response = await stripeClient.fetch({
28
+ url: `/charges/${ chargeId }`,
29
+ context: { creds },
30
+ });
31
+
32
+ return response;
33
+ };
34
+
35
+ const funcApiConfig = {
36
+ argsWarden,
37
+ };
38
+
39
+ module.exports = {
40
+ stripeChargeGet,
41
+ funcApiConfig,
42
+ };
43
+
44
+ /*
45
+ curl -X POST "http://localhost:8000/stripeChargeGet" \
46
+ -H "Content-Type: application/json" \
47
+ -d '{
48
+ "credsPayload": { "credsPath": "stripe" },
49
+ "chargeId": "ch_123"
50
+ }'
51
+ */
@@ -0,0 +1,52 @@
1
+ // https://docs.stripe.com/api/charges/list
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ]);
10
+
11
+ const stripeChargesGet = async (
12
+ credsPayload,
13
+ {
14
+ params,
15
+ } = {},
16
+ ) => {
17
+
18
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
19
+ if (rejectResponse) {
20
+ return rejectResponse;
21
+ }
22
+
23
+ const creds = await credsFromPayload(credsPayload);
24
+
25
+ const response = await stripeClient.fetch({
26
+ url: '/charges',
27
+ params,
28
+ context: { creds },
29
+ });
30
+
31
+ return response;
32
+ };
33
+
34
+ const funcApiConfig = {
35
+ argsWarden,
36
+ };
37
+
38
+ module.exports = {
39
+ stripeChargesGet,
40
+ funcApiConfig,
41
+ };
42
+
43
+ /*
44
+ curl -X POST "http://localhost:8000/stripeChargesGet" \
45
+ -H "Content-Type: application/json" \
46
+ -d '{
47
+ "credsPayload": { "credsPath": "stripe" },
48
+ "options": {
49
+ "params": { "limit": 10 }
50
+ }
51
+ }'
52
+ */
@@ -0,0 +1,64 @@
1
+ // https://docs.stripe.com/api/refunds/create
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['chargeId'],
10
+ ]);
11
+
12
+ const stripeRefundCreate = async (
13
+ credsPayload,
14
+ chargeId,
15
+ {
16
+ amountCents,
17
+ reason,
18
+ } = {},
19
+ ) => {
20
+
21
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
22
+ credsPayload,
23
+ chargeId,
24
+ });
25
+ if (rejectResponse) {
26
+ return rejectResponse;
27
+ }
28
+
29
+ const creds = await credsFromPayload(credsPayload);
30
+
31
+ const response = await stripeClient.fetch({
32
+ url: '/refunds',
33
+ method: 'post',
34
+ body: {
35
+ charge: chargeId,
36
+ ...amountCents && { amount: amountCents },
37
+ ...reason && { reason },
38
+ },
39
+ context: { creds },
40
+ });
41
+
42
+ return response;
43
+ };
44
+
45
+ const funcApiConfig = {
46
+ argsWarden,
47
+ };
48
+
49
+ module.exports = {
50
+ stripeRefundCreate,
51
+ funcApiConfig,
52
+ };
53
+
54
+ /*
55
+ curl -X POST "http://localhost:8000/stripeRefundCreate" \
56
+ -H "Content-Type: application/json" \
57
+ -d '{
58
+ "credsPayload": { "credsPath": "stripe" },
59
+ "chargeId": "ch_123",
60
+ "options": {
61
+ "amountCents": "100"
62
+ }
63
+ }'
64
+ */
@@ -0,0 +1,51 @@
1
+ // https://docs.stripe.com/api/refunds/retrieve
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['refundId'],
10
+ ]);
11
+
12
+ const stripeRefundGet = async (
13
+ credsPayload,
14
+ refundId,
15
+ ) => {
16
+
17
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
18
+ credsPayload,
19
+ refundId,
20
+ });
21
+ if (rejectResponse) {
22
+ return rejectResponse;
23
+ }
24
+
25
+ const creds = await credsFromPayload(credsPayload);
26
+
27
+ const response = await stripeClient.fetch({
28
+ url: `/refunds/${ refundId }`,
29
+ context: { creds },
30
+ });
31
+
32
+ return response;
33
+ };
34
+
35
+ const funcApiConfig = {
36
+ argsWarden,
37
+ };
38
+
39
+ module.exports = {
40
+ stripeRefundGet,
41
+ funcApiConfig,
42
+ };
43
+
44
+ /*
45
+ curl -X POST "http://localhost:8000/stripeRefundGet" \
46
+ -H "Content-Type: application/json" \
47
+ -d '{
48
+ "credsPayload": { "credsPath": "stripe" },
49
+ "refundId": "re_123"
50
+ }'
51
+ */
@@ -0,0 +1,52 @@
1
+ // https://docs.stripe.com/api/refunds/list
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ]);
10
+
11
+ const stripeRefundsGet = async (
12
+ credsPayload,
13
+ {
14
+ params,
15
+ } = {},
16
+ ) => {
17
+
18
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
19
+ if (rejectResponse) {
20
+ return rejectResponse;
21
+ }
22
+
23
+ const creds = await credsFromPayload(credsPayload);
24
+
25
+ const response = await stripeClient.fetch({
26
+ url: '/refunds',
27
+ params,
28
+ context: { creds },
29
+ });
30
+
31
+ return response;
32
+ };
33
+
34
+ const funcApiConfig = {
35
+ argsWarden,
36
+ };
37
+
38
+ module.exports = {
39
+ stripeRefundsGet,
40
+ funcApiConfig,
41
+ };
42
+
43
+ /*
44
+ curl -X POST "http://localhost:8000/stripeRefundsGet" \
45
+ -H "Content-Type: application/json" \
46
+ -d '{
47
+ "credsPayload": { "credsPath": "stripe" },
48
+ "options": {
49
+ "params": { "charge": "ch_123" }
50
+ }
51
+ }'
52
+ */
@@ -0,0 +1,51 @@
1
+ // https://docs.stripe.com/api/tokens/retrieve
2
+
3
+ const { credsFromPayload, ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { stripeClient } = require('../stripe/stripe.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['tokenId'],
10
+ ]);
11
+
12
+ const stripeTokenGet = async (
13
+ credsPayload,
14
+ tokenId,
15
+ ) => {
16
+
17
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
18
+ credsPayload,
19
+ tokenId,
20
+ });
21
+ if (rejectResponse) {
22
+ return rejectResponse;
23
+ }
24
+
25
+ const creds = await credsFromPayload(credsPayload);
26
+
27
+ const response = await stripeClient.fetch({
28
+ url: `/tokens/${ tokenId }`,
29
+ context: { creds },
30
+ });
31
+
32
+ return response;
33
+ };
34
+
35
+ const funcApiConfig = {
36
+ argsWarden,
37
+ };
38
+
39
+ module.exports = {
40
+ stripeTokenGet,
41
+ funcApiConfig,
42
+ };
43
+
44
+ /*
45
+ curl -X POST "http://localhost:8000/stripeTokenGet" \
46
+ -H "Content-Type: application/json" \
47
+ -d '{
48
+ "credsPayload": { "credsPath": "stripe" },
49
+ "tokenId": "tok_123"
50
+ }'
51
+ */