@capgo/cli 0.8.6 → 0.11.0
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/.cz.toml +1 -1
- package/.eslintignore +1 -0
- package/.eslintrc +0 -1
- package/CHANGELOG.md +39 -0
- package/dist/index.js +1 -1
- package/package.json +6 -3
- package/src/bin/add.ts +89 -35
- package/src/bin/delete.ts +132 -31
- package/src/bin/index.ts +9 -1
- package/src/bin/login.ts +23 -0
- package/src/bin/set.ts +58 -31
- package/src/bin/types.d.ts +6 -0
- package/src/bin/types_supabase.ts +2867 -0
- package/src/bin/upload.ts +112 -146
- package/src/bin/utils.ts +100 -5
- package/test/test_headers_rls.ts +26 -0
- package/tsconfig.json +4 -1
package/src/bin/set.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import prettyjson from 'prettyjson';
|
|
4
1
|
import { program } from 'commander';
|
|
5
|
-
import { host } from './utils';
|
|
2
|
+
import { getConfig, createSupabaseClient, updateOrCreateChannel, host, formatError, findSavedKey } from './utils';
|
|
3
|
+
import { definitions } from './types_supabase';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
5
|
+
interface Options {
|
|
6
|
+
apikey: string;
|
|
7
|
+
version: string;
|
|
8
|
+
state: string;
|
|
9
|
+
channel?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const setChannel = async (appid: string, options: Options) => {
|
|
13
|
+
let { version } = options;
|
|
14
|
+
const { state, channel = 'dev' } = options;
|
|
15
|
+
const apikey = options.apikey || findSavedKey()
|
|
16
|
+
const config = await getConfig();
|
|
16
17
|
appid = appid || config?.app?.appId
|
|
18
|
+
version = version || config?.app?.package?.version
|
|
17
19
|
let parsedState
|
|
18
20
|
if (state === 'public' || state === 'private')
|
|
19
21
|
parsedState = state === 'public'
|
|
@@ -32,25 +34,50 @@ export const setChannel = async (appid, options) => {
|
|
|
32
34
|
console.log(`Set${channel} to @${state} in ${appid}`);
|
|
33
35
|
}
|
|
34
36
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
const supabase = createSupabaseClient(apikey)
|
|
38
|
+
const { data: apiAccess, error: apiAccessError } = await supabase
|
|
39
|
+
.rpc('is_allowed_capgkey', { apikey, keymode: ['write', 'all'], app_id: appid })
|
|
40
|
+
|
|
41
|
+
if (!apiAccess || apiAccessError) {
|
|
42
|
+
program.error("Invalid API key or insufisant rights");
|
|
43
|
+
}
|
|
44
|
+
const { data: dataUser, error: userIdError } = await supabase
|
|
45
|
+
.rpc<string>('get_user_id', { apikey })
|
|
46
|
+
|
|
47
|
+
const userId = dataUser ? dataUser.toString() : '';
|
|
48
|
+
|
|
49
|
+
if (!userId || userIdError) {
|
|
50
|
+
program.error('Cannot verify user')
|
|
51
|
+
}
|
|
52
|
+
const channelPayload: Partial<definitions['channels']> = {
|
|
53
|
+
created_by: userId,
|
|
54
|
+
app_id: appid,
|
|
55
|
+
name: channel,
|
|
56
|
+
}
|
|
57
|
+
if (version) {
|
|
58
|
+
const { data, error: vError } = await supabase
|
|
59
|
+
.from<definitions['app_versions']>('app_versions')
|
|
60
|
+
.select()
|
|
61
|
+
.eq('app_id', appid)
|
|
62
|
+
.eq('name', version)
|
|
63
|
+
.eq('user_id', userId)
|
|
64
|
+
.eq('deleted', false)
|
|
65
|
+
if (vError || !data || !data.length)
|
|
66
|
+
program.error(`Cannot find version ${version}`);
|
|
67
|
+
channelPayload.version = data[0].id
|
|
68
|
+
}
|
|
69
|
+
if (parsedState !== undefined)
|
|
70
|
+
channelPayload.public = parsedState
|
|
71
|
+
try {
|
|
72
|
+
const { error: dbError } = await updateOrCreateChannel(supabase, channelPayload, apikey)
|
|
73
|
+
if (dbError)
|
|
74
|
+
program.error(`Cannot set channel ${formatError(dbError)}`);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
program.error(`Cannot set channel ${formatError(e)}`);
|
|
78
|
+
}
|
|
49
79
|
} catch (err) {
|
|
50
|
-
program.error(`
|
|
51
|
-
}
|
|
52
|
-
if (!res || res.status !== 200) {
|
|
53
|
-
program.error(`Server Error \n${prettyjson.render(res.data)}`);
|
|
80
|
+
program.error(`Unknow error ${formatError(err)}`);
|
|
54
81
|
}
|
|
55
82
|
if (version) {
|
|
56
83
|
console.log(`Done ✅`);
|