@capgo/cli 2.3.2 → 2.3.6
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/CHANGELOG.md +28 -0
- package/dist/index.js +1 -1
- package/package.json +5 -4
- package/src/api/app.ts +2 -1
- package/src/api/channels.ts +11 -6
- package/src/api/devices_override.ts +11 -7
- package/src/api/versions.ts +6 -5
- package/src/bin/add.ts +7 -7
- package/src/bin/cleanup.ts +11 -7
- package/src/bin/delete.ts +6 -5
- package/src/bin/set.ts +4 -3
- package/src/bin/upload.ts +13 -5
- package/src/bin/utils.ts +38 -21
- package/src/types/supabase.types.ts +1031 -0
- package/test/test_headers_rls.ts +4 -2
- package/src/types/types_supabase.ts +0 -4607
package/src/bin/upload.ts
CHANGED
|
@@ -7,7 +7,9 @@ import { checksum as getChecksum } from '@tomasklaen/checksum';
|
|
|
7
7
|
import { encryptSource } from '../api/crypto';
|
|
8
8
|
import {
|
|
9
9
|
host, hostWeb, getConfig, createSupabaseClient,
|
|
10
|
-
updateOrCreateChannel, updateOrCreateVersion,
|
|
10
|
+
updateOrCreateChannel, updateOrCreateVersion,
|
|
11
|
+
formatError, findSavedKey, checkPlanValid,
|
|
12
|
+
useLogSnag, verifyUser, regexSemver, baseKeyPub, convertAppName
|
|
11
13
|
} from './utils';
|
|
12
14
|
|
|
13
15
|
interface Options {
|
|
@@ -63,6 +65,7 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
63
65
|
// checking if user has access rights before uploading
|
|
64
66
|
const { data: versionExist, error: versionExistError } = await supabase
|
|
65
67
|
.rpc('exist_app_versions', { apikey, name_version: bundle, appid })
|
|
68
|
+
.single()
|
|
66
69
|
|
|
67
70
|
if (versionExist || versionExistError) {
|
|
68
71
|
multibar.stop()
|
|
@@ -70,7 +73,7 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
70
73
|
}
|
|
71
74
|
b1.increment();
|
|
72
75
|
const { data: isTrial, error: isTrialsError } = await supabase
|
|
73
|
-
.rpc
|
|
76
|
+
.rpc('is_trial', { userid: userId })
|
|
74
77
|
.single()
|
|
75
78
|
if (isTrial && isTrial > 0 || isTrialsError) {
|
|
76
79
|
multibar.log(`WARNING !!\nTrial expires in ${isTrial} days, upgrade here: ${hostWeb}/dashboard/settings/plans\n`);
|
|
@@ -78,7 +81,9 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
78
81
|
b1.increment();
|
|
79
82
|
|
|
80
83
|
const { data: app, error: appError } = await supabase
|
|
81
|
-
.rpc
|
|
84
|
+
.rpc('exist_app', { appid, apikey })
|
|
85
|
+
.single()
|
|
86
|
+
|
|
82
87
|
if (!app || appError) {
|
|
83
88
|
multibar.stop()
|
|
84
89
|
program.error(`Cannot find app ${appid} in your account \n${formatError(appError)}`)
|
|
@@ -86,7 +91,9 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
86
91
|
b1.increment();
|
|
87
92
|
// check if app already exist
|
|
88
93
|
const { data: appVersion, error: appVersionError } = await supabase
|
|
89
|
-
.rpc
|
|
94
|
+
.rpc('exist_app_versions', { appid, apikey, name_version: bundle })
|
|
95
|
+
.single()
|
|
96
|
+
|
|
90
97
|
if (appVersion || appVersionError) {
|
|
91
98
|
program.error(`Version already exists ${formatError(appVersionError)}`)
|
|
92
99
|
}
|
|
@@ -108,6 +115,7 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
108
115
|
// open with fs publicKey path
|
|
109
116
|
const keyFile = readFileSync(publicKey)
|
|
110
117
|
// encrypt
|
|
118
|
+
console.log('Encrypting your bundle')
|
|
111
119
|
const res = encryptSource(zipped, keyFile.toString())
|
|
112
120
|
sessionKey = res.ivSessionKey
|
|
113
121
|
zipped = res.encryptedData
|
|
@@ -171,7 +179,7 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
171
179
|
multibar.log('Cannot set bundle with upload key, use key with more rights for that\n');
|
|
172
180
|
}
|
|
173
181
|
multibar.stop()
|
|
174
|
-
const appidWeb = appid
|
|
182
|
+
const appidWeb = convertAppName(appid)
|
|
175
183
|
console.log("App uploaded to server")
|
|
176
184
|
console.log(`Try it in mobile app: ${host}/app_mobile`)
|
|
177
185
|
console.log(`Or set the channel ${channel} as public here: ${hostWeb}/app/package/${appidWeb}`)
|
package/src/bin/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import prettyjson from 'prettyjson';
|
|
|
5
5
|
import { existsSync, readFileSync } from 'fs';
|
|
6
6
|
import { homedir } from 'os';
|
|
7
7
|
import { LogSnag } from 'logsnag';
|
|
8
|
-
import {
|
|
8
|
+
import { Database } from 'types/supabase.types';
|
|
9
9
|
|
|
10
10
|
export const baseKey = '.capgo_key';
|
|
11
11
|
export const baseKeyPub = `${baseKey}.pub`;
|
|
@@ -23,9 +23,11 @@ export const supaAnon = process.env.SUPA_DB === 'production'
|
|
|
23
23
|
: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImF1Y3N5YnZuaGF2b2dkbXp3dGN3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTQ1Mzk1MDYsImV4cCI6MTk3MDExNTUwNn0.HyuZmo_EjF5fgZQU3g37bdNardK1CLHgxXmYqtr59bo'
|
|
24
24
|
/* eslint-enable */
|
|
25
25
|
|
|
26
|
-
export const createSupabaseClient = (apikey: string) => createClient(hostSupa, supaAnon, {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export const createSupabaseClient = (apikey: string) => createClient<Database>(hostSupa, supaAnon, {
|
|
27
|
+
global: {
|
|
28
|
+
headers: {
|
|
29
|
+
capgkey: apikey,
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
})
|
|
31
33
|
// eslint-disable-next-line max-len
|
|
@@ -34,6 +36,7 @@ export const regexSemver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[
|
|
|
34
36
|
export const checkKey = async (supabase: SupabaseClient, apikey: string, keymode: string[]) => {
|
|
35
37
|
const { data: apiAccess, error: apiAccessError } = await supabase
|
|
36
38
|
.rpc('is_allowed_capgkey', { apikey, keymode })
|
|
39
|
+
.single()
|
|
37
40
|
|
|
38
41
|
if (!apiAccess || apiAccessError) {
|
|
39
42
|
program.error(`Invalid API key or insufficient permissions ${formatError(apiAccessError)}`);
|
|
@@ -42,7 +45,7 @@ export const checkKey = async (supabase: SupabaseClient, apikey: string, keymode
|
|
|
42
45
|
|
|
43
46
|
export const isGoodPlan = async (supabase: SupabaseClient, userId: string): Promise<boolean> => {
|
|
44
47
|
const { data, error } = await supabase
|
|
45
|
-
.rpc
|
|
48
|
+
.rpc('is_good_plan_v2', { userid: userId })
|
|
46
49
|
.single()
|
|
47
50
|
if (error) {
|
|
48
51
|
throw error
|
|
@@ -52,7 +55,7 @@ export const isGoodPlan = async (supabase: SupabaseClient, userId: string): Prom
|
|
|
52
55
|
|
|
53
56
|
export const isPaying = async (supabase: SupabaseClient, userId: string): Promise<boolean> => {
|
|
54
57
|
const { data, error } = await supabase
|
|
55
|
-
.rpc
|
|
58
|
+
.rpc('is_paying', { userid: userId })
|
|
56
59
|
.single()
|
|
57
60
|
if (error) {
|
|
58
61
|
throw error
|
|
@@ -62,7 +65,7 @@ export const isPaying = async (supabase: SupabaseClient, userId: string): Promis
|
|
|
62
65
|
|
|
63
66
|
export const isTrial = async (supabase: SupabaseClient, userId: string): Promise<number> => {
|
|
64
67
|
const { data, error } = await supabase
|
|
65
|
-
.rpc
|
|
68
|
+
.rpc('is_trial', { userid: userId })
|
|
66
69
|
.single()
|
|
67
70
|
if (error) {
|
|
68
71
|
throw error
|
|
@@ -72,7 +75,7 @@ export const isTrial = async (supabase: SupabaseClient, userId: string): Promise
|
|
|
72
75
|
|
|
73
76
|
export const isAllowedAction = async (supabase: SupabaseClient, userId: string): Promise<boolean> => {
|
|
74
77
|
const { data, error } = await supabase
|
|
75
|
-
.rpc
|
|
78
|
+
.rpc('is_allowed_action_user', { userid: userId })
|
|
76
79
|
.single()
|
|
77
80
|
if (error) {
|
|
78
81
|
throw error
|
|
@@ -133,47 +136,59 @@ export const getConfig = async () => {
|
|
|
133
136
|
return config;
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
export const updateOrCreateVersion = async (supabase: SupabaseClient,
|
|
139
|
+
export const updateOrCreateVersion = async (supabase: SupabaseClient,
|
|
140
|
+
update: Partial<Database['public']['Tables']['app_versions']['Row']>, apikey: string) => {
|
|
137
141
|
// console.log('updateOrCreateVersion', update, apikey)
|
|
138
142
|
const { data, error } = await supabase
|
|
139
|
-
.rpc
|
|
143
|
+
.rpc('exist_app_versions', { appid: update.app_id, name_version: update.name, apikey })
|
|
144
|
+
.single()
|
|
145
|
+
|
|
140
146
|
if (data && !error) {
|
|
141
147
|
update.deleted = false
|
|
142
148
|
return supabase
|
|
143
|
-
.from
|
|
149
|
+
.from('app_versions')
|
|
144
150
|
.update(update)
|
|
145
151
|
.eq('app_id', update.app_id)
|
|
146
152
|
.eq('name', update.name)
|
|
153
|
+
.single()
|
|
147
154
|
}
|
|
148
155
|
// console.log('create Version', data, error)
|
|
149
156
|
|
|
150
157
|
return supabase
|
|
151
|
-
.from
|
|
158
|
+
.from('app_versions')
|
|
152
159
|
.insert(update)
|
|
153
|
-
|
|
160
|
+
.select()
|
|
161
|
+
.single()
|
|
154
162
|
}
|
|
155
163
|
|
|
156
|
-
export const updateOrCreateChannel = async (supabase: SupabaseClient,
|
|
164
|
+
export const updateOrCreateChannel = async (supabase: SupabaseClient,
|
|
165
|
+
update: Partial<Database['public']['Tables']['channels']['Row']>, apikey: string) => {
|
|
157
166
|
// console.log('updateOrCreateChannel', update)
|
|
158
167
|
if (!update.app_id || !update.name || !update.created_by) {
|
|
159
168
|
console.error('missing app_id, name, or created_by')
|
|
160
169
|
return Promise.reject(new Error('missing app_id, name, or created_by'))
|
|
161
170
|
}
|
|
162
171
|
const { data, error } = await supabase
|
|
163
|
-
.rpc
|
|
172
|
+
.rpc('exist_channel', { appid: update.app_id, name_channel: update.name, apikey })
|
|
173
|
+
.single()
|
|
174
|
+
|
|
164
175
|
if (data && !error) {
|
|
165
176
|
return supabase
|
|
166
|
-
.from
|
|
167
|
-
.update(update
|
|
177
|
+
.from('channels')
|
|
178
|
+
.update(update)
|
|
168
179
|
.eq('app_id', update.app_id)
|
|
169
180
|
.eq('name', update.name)
|
|
170
181
|
.eq('created_by', update.created_by)
|
|
182
|
+
.single()
|
|
183
|
+
|
|
171
184
|
}
|
|
172
185
|
// console.log('create Channel', data, error)
|
|
173
186
|
|
|
174
187
|
return supabase
|
|
175
|
-
.from
|
|
176
|
-
.insert(update
|
|
188
|
+
.from('channels')
|
|
189
|
+
.insert(update)
|
|
190
|
+
.select()
|
|
191
|
+
.single()
|
|
177
192
|
}
|
|
178
193
|
|
|
179
194
|
export const useLogSnag = (): LogSnag => {
|
|
@@ -184,11 +199,13 @@ export const useLogSnag = (): LogSnag => {
|
|
|
184
199
|
return logsnag
|
|
185
200
|
}
|
|
186
201
|
|
|
202
|
+
export const convertAppName = (appName: string) => appName.replace(/\./g, '--')
|
|
187
203
|
export const verifyUser = async (supabase: SupabaseClient, apikey: string, keymod: string[] = ['all']) => {
|
|
188
204
|
await checkKey(supabase, apikey, keymod);
|
|
189
205
|
|
|
190
206
|
const { data: dataUser, error: userIdError } = await supabase
|
|
191
|
-
.rpc
|
|
207
|
+
.rpc('get_user_id', { apikey })
|
|
208
|
+
.single();
|
|
192
209
|
|
|
193
210
|
const userId = dataUser ? dataUser.toString() : '';
|
|
194
211
|
|
|
@@ -198,7 +215,7 @@ export const verifyUser = async (supabase: SupabaseClient, apikey: string, keymo
|
|
|
198
215
|
return userId;
|
|
199
216
|
}
|
|
200
217
|
|
|
201
|
-
export const getHumanDate = (row:
|
|
218
|
+
export const getHumanDate = (row: Database['public']['Tables']['app_versions']['Row']) => {
|
|
202
219
|
const date = new Date(row.created_at || '');
|
|
203
220
|
return date.toLocaleString();
|
|
204
221
|
}
|