@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.
- package/.creds.yml.sample +22 -1
- package/api/loop/loop.constants.js +7 -0
- package/api/loop/loop.utils.js +43 -0
- package/api/loop/loopAllowlistItemsGet.js +42 -0
- package/api/loop/loopBlocklistItemsGet.js +46 -0
- package/api/loop/loopDestinationsGet.js +42 -0
- package/api/loop/loopGet.js +143 -0
- package/api/loop/loopReturnGet.js +73 -0
- package/api/loop/loopReturnsGet.js +46 -0
- package/api/peoplevox/peoplevox.sessions.js +87 -0
- package/api/peoplevox/peoplevox.utils.js +7 -15
- package/api/shopify/shopifyCollectionGet.js +1 -1
- package/api/shopify/shopifyTagsAdd.js +1 -1
- package/api/shopify/shopifyTagsRemove.js +1 -1
- package/api/stripe/_example.js +48 -0
- package/api/stripe/stripe.constants.js +5 -0
- package/api/stripe/stripe.utils.js +47 -0
- package/api/stripe/stripeCardCharge.js +98 -0
- package/api/stripe/stripeCardTokenCreate.js +70 -0
- package/api/stripe/stripeChargeCapture.js +63 -0
- package/api/stripe/stripeChargeCreate.js +70 -0
- package/api/stripe/stripeChargeGet.js +51 -0
- package/api/stripe/stripeChargesGet.js +52 -0
- package/api/stripe/stripeRefundCreate.js +64 -0
- package/api/stripe/stripeRefundGet.js +51 -0
- package/api/stripe/stripeRefundsGet.js +52 -0
- package/api/stripe/stripeTokenGet.js +51 -0
- package/api/supabase/supabase.utils.js +52 -0
- package/api/supabase/supabaseRowDelete.js +95 -0
- package/api/supabase/supabaseRowGet.js +58 -0
- package/api/supabase/supabaseRowInsert.js +56 -0
- package/api/supabase/supabaseRowUpdate.js +58 -0
- package/api/supabase/supabaseRpc.js +61 -0
- package/api/supabase/supabaseTableGet.js +44 -0
- package/api/supabase/supabaseTableGetAll.js +86 -0
- package/api/upstash/upstash.utils.js +36 -0
- package/api/upstash/upstashDel.js +46 -0
- package/api/upstash/upstashExists.js +46 -0
- package/api/upstash/upstashGet.js +46 -0
- package/api/upstash/upstashSet.js +64 -0
- package/api/utils.js +52 -1
- package/api/workable/workable.constants.js +3 -0
- package/api/workable/workable.utils.js +46 -0
- package/api/workable/workableGet.js +146 -0
- package/api/workable/workableJobCandidateCreate.js +87 -0
- package/api/workable/workableJobGet.js +52 -0
- package/api/workable/workableJobMembersGet.js +52 -0
- package/api/workable/workableJobStagesGet.js +52 -0
- package/api/workable/workableJobsGet.js +78 -0
- package/bin/mineral.js +6 -0
- package/hosting/.hosting.yml.sample +9 -11
- package/hosting/copyCredsToEnv.js +58 -2
- package/hosting/deployFromHostingYml.js +9 -2
- package/hosting/generateHosted.js +22 -2
- package/hosting/hosting.utils.js +3 -2
- package/hosting/hostingPreview.js +160 -0
- package/hosting/wrappers.js +1 -1
- package/package.json +9 -2
- package/server.utils.js +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { createClient } = require('@supabase/supabase-js');
|
|
2
|
+
const { HOSTED } = require('../constants');
|
|
3
|
+
const { credsFromPayload } = require('../utils');
|
|
4
|
+
|
|
5
|
+
const SUPABASE_INSTANCES = new Map();
|
|
6
|
+
|
|
7
|
+
const getSupabaseCacheKey = (credsPayload) => JSON.stringify(credsPayload);
|
|
8
|
+
|
|
9
|
+
const getSupabaseClient = async (credsPayload) => {
|
|
10
|
+
const key = getSupabaseCacheKey(credsPayload);
|
|
11
|
+
|
|
12
|
+
if (SUPABASE_INSTANCES.has(key)) {
|
|
13
|
+
return SUPABASE_INSTANCES.get(key);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const creds = await credsFromPayload(credsPayload);
|
|
17
|
+
const {
|
|
18
|
+
BASE_URL,
|
|
19
|
+
API_KEY,
|
|
20
|
+
} = creds;
|
|
21
|
+
|
|
22
|
+
if (!BASE_URL || !API_KEY) {
|
|
23
|
+
throw new Error('Missing Supabase creds');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const client = createClient(BASE_URL, API_KEY);
|
|
27
|
+
SUPABASE_INSTANCES.set(key, client);
|
|
28
|
+
return client;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const supabaseInterpreter = (response) => {
|
|
32
|
+
const { data, error } = response;
|
|
33
|
+
|
|
34
|
+
if (error) {
|
|
35
|
+
return {
|
|
36
|
+
ok: false,
|
|
37
|
+
error: {
|
|
38
|
+
details: error,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
data,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
getSupabaseClient,
|
|
51
|
+
supabaseInterpreter,
|
|
52
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const { HOSTED } = require('../constants');
|
|
2
|
+
const { ArgsWarden } = require('../utils');
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
5
|
+
|
|
6
|
+
const argsWarden = new ArgsWarden([
|
|
7
|
+
['credsPayload', credsValidator],
|
|
8
|
+
['tableName'],
|
|
9
|
+
['deleteConfig'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const supabaseRowDelete = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
tableName,
|
|
15
|
+
deleteConfig,
|
|
16
|
+
) => {
|
|
17
|
+
|
|
18
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
19
|
+
credsPayload,
|
|
20
|
+
tableName,
|
|
21
|
+
deleteConfig,
|
|
22
|
+
});
|
|
23
|
+
if (rejectResponse) {
|
|
24
|
+
return rejectResponse;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!deleteConfig || typeof deleteConfig !== 'object') {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
error: {
|
|
31
|
+
message: 'deleteConfig must be an object with either { field, value } or { conditions }',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const client = await getSupabaseClient(credsPayload);
|
|
37
|
+
let queryResponse;
|
|
38
|
+
|
|
39
|
+
if (deleteConfig.conditions) {
|
|
40
|
+
if (typeof deleteConfig.conditions !== 'object') {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: {
|
|
44
|
+
message: 'conditions must be an object with field-value pairs',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
!HOSTED && console.log('Deleting row with conditions:', deleteConfig.conditions);
|
|
50
|
+
|
|
51
|
+
let query = client.from(tableName).delete();
|
|
52
|
+
|
|
53
|
+
Object.entries(deleteConfig.conditions).forEach(([field, value]) => {
|
|
54
|
+
query = query.eq(field, value);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
queryResponse = await query.select();
|
|
58
|
+
} else if (deleteConfig.field && deleteConfig.value !== undefined) {
|
|
59
|
+
!HOSTED && console.log(`Deleting row where ${ deleteConfig.field } = ${ deleteConfig.value }`);
|
|
60
|
+
|
|
61
|
+
queryResponse = await client
|
|
62
|
+
.from(tableName)
|
|
63
|
+
.delete()
|
|
64
|
+
.eq(deleteConfig.field, deleteConfig.value)
|
|
65
|
+
.select();
|
|
66
|
+
} else {
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
error: {
|
|
70
|
+
message: 'deleteConfig must have either { field, value } or { conditions }',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return supabaseInterpreter(queryResponse);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const funcApiConfig = {
|
|
79
|
+
argsWarden,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = {
|
|
83
|
+
supabaseRowDelete,
|
|
84
|
+
funcApiConfig,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
curl -X POST "http://localhost:8000/supabaseRowDelete" \
|
|
89
|
+
-H "Content-Type: application/json" \
|
|
90
|
+
-d '{
|
|
91
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
92
|
+
"tableName": "powerups",
|
|
93
|
+
"deleteConfig": { "field": "name", "value": "fire_flower" }
|
|
94
|
+
}'
|
|
95
|
+
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['tableName'],
|
|
8
|
+
['rowField'],
|
|
9
|
+
['rowValue'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const supabaseRowGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
tableName,
|
|
15
|
+
rowField,
|
|
16
|
+
rowValue,
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
tableName,
|
|
22
|
+
rowField,
|
|
23
|
+
rowValue,
|
|
24
|
+
});
|
|
25
|
+
if (rejectResponse) {
|
|
26
|
+
return rejectResponse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const client = await getSupabaseClient(credsPayload);
|
|
30
|
+
const response = await client
|
|
31
|
+
.from(tableName)
|
|
32
|
+
.select('*')
|
|
33
|
+
.eq(rowField, rowValue)
|
|
34
|
+
.single()
|
|
35
|
+
;
|
|
36
|
+
|
|
37
|
+
return supabaseInterpreter(response);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const funcApiConfig = {
|
|
41
|
+
argsWarden,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
supabaseRowGet,
|
|
46
|
+
funcApiConfig,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
curl -X POST "http://localhost:8000/supabaseRowGet" \
|
|
51
|
+
-H "Content-Type: application/json" \
|
|
52
|
+
-d '{
|
|
53
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
54
|
+
"tableName": "powerups",
|
|
55
|
+
"rowField": "name",
|
|
56
|
+
"rowValue": "star"
|
|
57
|
+
}'
|
|
58
|
+
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['tableName'],
|
|
8
|
+
['rowObject'],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const supabaseRowInsert = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
tableName,
|
|
14
|
+
rowObject,
|
|
15
|
+
) => {
|
|
16
|
+
|
|
17
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
18
|
+
credsPayload,
|
|
19
|
+
tableName,
|
|
20
|
+
rowObject,
|
|
21
|
+
});
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const client = await getSupabaseClient(credsPayload);
|
|
27
|
+
const response = await client
|
|
28
|
+
.from(tableName)
|
|
29
|
+
.insert(rowObject)
|
|
30
|
+
.select()
|
|
31
|
+
;
|
|
32
|
+
|
|
33
|
+
return supabaseInterpreter(response);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const funcApiConfig = {
|
|
37
|
+
argsWarden,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
supabaseRowInsert,
|
|
42
|
+
funcApiConfig,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
curl -X POST "http://localhost:8000/supabaseRowInsert" \
|
|
47
|
+
-H "Content-Type: application/json" \
|
|
48
|
+
-d '{
|
|
49
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
50
|
+
"tableName": "powerups",
|
|
51
|
+
"rowObject": [
|
|
52
|
+
{ "name": "mushroom", "effect": "grow", "duration_seconds": null },
|
|
53
|
+
{ "name": "star", "effect": "invincible", "duration_seconds": 10 }
|
|
54
|
+
]
|
|
55
|
+
}'
|
|
56
|
+
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['tableName'],
|
|
8
|
+
['match'],
|
|
9
|
+
['updatePayload'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const supabaseRowUpdate = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
tableName,
|
|
15
|
+
match,
|
|
16
|
+
updatePayload,
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
tableName,
|
|
22
|
+
match,
|
|
23
|
+
updatePayload,
|
|
24
|
+
});
|
|
25
|
+
if (rejectResponse) {
|
|
26
|
+
return rejectResponse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const client = await getSupabaseClient(credsPayload);
|
|
30
|
+
const response = await client
|
|
31
|
+
.from(tableName)
|
|
32
|
+
.update(updatePayload)
|
|
33
|
+
.match(match)
|
|
34
|
+
.select()
|
|
35
|
+
;
|
|
36
|
+
|
|
37
|
+
return supabaseInterpreter(response);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const funcApiConfig = {
|
|
41
|
+
argsWarden,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
supabaseRowUpdate,
|
|
46
|
+
funcApiConfig,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
curl -X POST "http://localhost:8000/supabaseRowUpdate" \
|
|
51
|
+
-H "Content-Type: application/json" \
|
|
52
|
+
-d '{
|
|
53
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
54
|
+
"tableName": "powerups",
|
|
55
|
+
"match": { "name": "star" },
|
|
56
|
+
"updatePayload": { "duration_seconds": 12 }
|
|
57
|
+
}'
|
|
58
|
+
*/
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// https://supabase.com/docs/reference/javascript/rpc
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['rpcName'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const supabaseRpc = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
rpcName,
|
|
15
|
+
{
|
|
16
|
+
rpcArgs,
|
|
17
|
+
rpcOptions,
|
|
18
|
+
useMaybeSingle = false,
|
|
19
|
+
} = {},
|
|
20
|
+
) => {
|
|
21
|
+
|
|
22
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
23
|
+
credsPayload,
|
|
24
|
+
rpcName,
|
|
25
|
+
});
|
|
26
|
+
if (rejectResponse) {
|
|
27
|
+
return rejectResponse;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const client = await getSupabaseClient(credsPayload);
|
|
31
|
+
let query = client.rpc(rpcName, rpcArgs, rpcOptions);
|
|
32
|
+
|
|
33
|
+
if (useMaybeSingle) {
|
|
34
|
+
query = query.maybeSingle();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const response = await query;
|
|
38
|
+
return supabaseInterpreter(response);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
supabaseRpc,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
curl -X POST "http://localhost:8000/supabaseRpc" \
|
|
52
|
+
-H "Content-Type: application/json" \
|
|
53
|
+
-d '{
|
|
54
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
55
|
+
"rpcName": "grant_powerup",
|
|
56
|
+
"options": {
|
|
57
|
+
"rpcArgs": { "player": "mario", "powerup": "1up_mushroom" },
|
|
58
|
+
"useMaybeSingle": true
|
|
59
|
+
}
|
|
60
|
+
}'
|
|
61
|
+
*/
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getSupabaseClient, supabaseInterpreter } = require('../supabase/supabase.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['tableName'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const supabaseTableGet = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
tableName,
|
|
13
|
+
) => {
|
|
14
|
+
|
|
15
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
16
|
+
credsPayload,
|
|
17
|
+
tableName,
|
|
18
|
+
});
|
|
19
|
+
if (rejectResponse) {
|
|
20
|
+
return rejectResponse;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const client = await getSupabaseClient(credsPayload);
|
|
24
|
+
const response = await client.from(tableName).select('*');
|
|
25
|
+
return supabaseInterpreter(response);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const funcApiConfig = {
|
|
29
|
+
argsWarden,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
supabaseTableGet,
|
|
34
|
+
funcApiConfig,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
curl -X POST "http://localhost:8000/supabaseTableGet" \
|
|
39
|
+
-H "Content-Type: application/json" \
|
|
40
|
+
-d '{
|
|
41
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
42
|
+
"tableName": "powerups"
|
|
43
|
+
}'
|
|
44
|
+
*/
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const { HOSTED } = require('../constants');
|
|
2
|
+
const { ArgsWarden } = require('../utils');
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { getSupabaseClient } = require('../supabase/supabase.utils');
|
|
5
|
+
|
|
6
|
+
const argsWarden = new ArgsWarden([
|
|
7
|
+
['credsPayload', credsValidator],
|
|
8
|
+
['tableName'],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const supabaseTableGetAll = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
tableName,
|
|
14
|
+
{
|
|
15
|
+
orderBy = 'id',
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
tableName,
|
|
22
|
+
});
|
|
23
|
+
if (rejectResponse) {
|
|
24
|
+
return rejectResponse;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const client = await getSupabaseClient(credsPayload);
|
|
28
|
+
|
|
29
|
+
const rowsCountResponse = await client.from(tableName).select('*', { count: 'exact', head: true });
|
|
30
|
+
const { count: rowsCount } = rowsCountResponse;
|
|
31
|
+
|
|
32
|
+
const PAGE_SIZE = 1000;
|
|
33
|
+
let rowsFetched = 0;
|
|
34
|
+
let rows = [];
|
|
35
|
+
|
|
36
|
+
while (rowsFetched < rowsCount) {
|
|
37
|
+
const pageRowsResponse = await client
|
|
38
|
+
.from(tableName)
|
|
39
|
+
.select('*')
|
|
40
|
+
.order(orderBy)
|
|
41
|
+
.range(rowsFetched, (rowsFetched + PAGE_SIZE) - 1)
|
|
42
|
+
;
|
|
43
|
+
const { data, error } = pageRowsResponse;
|
|
44
|
+
|
|
45
|
+
if (error) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
error: {
|
|
49
|
+
message: error.message,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!data) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
rows.push(...data);
|
|
59
|
+
rowsFetched += PAGE_SIZE;
|
|
60
|
+
!HOSTED && console.log(`${ rows.length } / ${ rowsCount }`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
ok: true,
|
|
65
|
+
data: rows,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const funcApiConfig = {
|
|
70
|
+
argsWarden,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
supabaseTableGetAll,
|
|
75
|
+
funcApiConfig,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
curl -X POST "http://localhost:8000/supabaseTableGetAll" \
|
|
80
|
+
-H "Content-Type: application/json" \
|
|
81
|
+
-d '{
|
|
82
|
+
"credsPayload": { "credsPath": "supabase.mushroom_kingdom" },
|
|
83
|
+
"tableName": "powerups",
|
|
84
|
+
"options": { "orderBy": "name" }
|
|
85
|
+
}'
|
|
86
|
+
*/
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { Redis } = require('@upstash/redis');
|
|
2
|
+
const { credsFromPayload } = require('../utils');
|
|
3
|
+
|
|
4
|
+
const UPSTASH_INSTANCES = new Map();
|
|
5
|
+
|
|
6
|
+
const getRedisCacheKey = (credsPayload) => JSON.stringify(credsPayload);
|
|
7
|
+
|
|
8
|
+
const getRedisInstance = async (credsPayload) => {
|
|
9
|
+
const key = getRedisCacheKey(credsPayload);
|
|
10
|
+
|
|
11
|
+
if (UPSTASH_INSTANCES.has(key)) {
|
|
12
|
+
return UPSTASH_INSTANCES.get(key);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const creds = await credsFromPayload(credsPayload);
|
|
16
|
+
const {
|
|
17
|
+
BASE_URL,
|
|
18
|
+
TOKEN,
|
|
19
|
+
} = creds;
|
|
20
|
+
|
|
21
|
+
if (!BASE_URL || !TOKEN) {
|
|
22
|
+
throw new Error('Missing Upstash creds');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const redis = new Redis({
|
|
26
|
+
url: BASE_URL,
|
|
27
|
+
token: TOKEN,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
UPSTASH_INSTANCES.set(key, redis);
|
|
31
|
+
return redis;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
getRedisInstance,
|
|
36
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getRedisInstance } = require('../upstash/upstash.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['key'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const upstashDel = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
key,
|
|
13
|
+
) => {
|
|
14
|
+
|
|
15
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, key });
|
|
16
|
+
if (rejectResponse) {
|
|
17
|
+
return rejectResponse;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const redis = await getRedisInstance(credsPayload);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const result = await redis.del(key);
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
data: result,
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('upstashDel error', error);
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
error: {
|
|
33
|
+
message: error.message,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const funcApiConfig = {
|
|
40
|
+
argsWarden,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
upstashDel,
|
|
45
|
+
funcApiConfig,
|
|
46
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getRedisInstance } = require('../upstash/upstash.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['key'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const upstashExists = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
key,
|
|
13
|
+
) => {
|
|
14
|
+
|
|
15
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, key });
|
|
16
|
+
if (rejectResponse) {
|
|
17
|
+
return rejectResponse;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const redis = await getRedisInstance(credsPayload);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const result = await redis.exists(key);
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
data: result === 1,
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('upstashExists error', error);
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
error: {
|
|
33
|
+
message: error.message,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const funcApiConfig = {
|
|
40
|
+
argsWarden,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
upstashExists,
|
|
45
|
+
funcApiConfig,
|
|
46
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { getRedisInstance } = require('../upstash/upstash.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['key'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const upstashGet = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
key,
|
|
13
|
+
) => {
|
|
14
|
+
|
|
15
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, key });
|
|
16
|
+
if (rejectResponse) {
|
|
17
|
+
return rejectResponse;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const redis = await getRedisInstance(credsPayload);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const result = await redis.get(key);
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
data: result,
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('upstashGet error', error);
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
error: {
|
|
33
|
+
message: error.message,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const funcApiConfig = {
|
|
40
|
+
argsWarden,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
upstashGet,
|
|
45
|
+
funcApiConfig,
|
|
46
|
+
};
|