@capgo/cli 5.0.0-alpha.7 → 5.0.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/README.md +197 -41
- package/dist/index.js +329 -95820
- package/dist/package.json +83 -0
- package/package.json +48 -62
- package/.eslintignore +0 -4
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/build.yml +0 -46
- package/.github/workflows/bump_version.yml +0 -56
- package/.github/workflows/test.yml +0 -30
- package/.prettierignore +0 -6
- package/.vscode/launch.json +0 -23
- package/.vscode/settings.json +0 -5
- package/.vscode/tasks.json +0 -42
- package/CHANGELOG.md +0 -2861
- package/build.mjs +0 -23
- package/bun.lockb +0 -0
- package/capacitor.config.ts +0 -33
- package/crypto_explained.png +0 -0
- package/eslint.config.js +0 -3
- package/renovate.json +0 -23
- package/src/api/app.ts +0 -75
- package/src/api/channels.ts +0 -140
- package/src/api/crypto.ts +0 -121
- package/src/api/devices_override.ts +0 -41
- package/src/api/update.ts +0 -12
- package/src/api/versions.ts +0 -101
- package/src/app/add.ts +0 -191
- package/src/app/debug.ts +0 -220
- package/src/app/delete.ts +0 -106
- package/src/app/info.ts +0 -87
- package/src/app/list.ts +0 -67
- package/src/app/set.ts +0 -94
- package/src/bundle/check.ts +0 -42
- package/src/bundle/cleanup.ts +0 -127
- package/src/bundle/compatibility.ts +0 -70
- package/src/bundle/decrypt.ts +0 -65
- package/src/bundle/delete.ts +0 -53
- package/src/bundle/encrypt.ts +0 -69
- package/src/bundle/list.ts +0 -43
- package/src/bundle/unlink.ts +0 -86
- package/src/bundle/upload.ts +0 -516
- package/src/bundle/zip.ts +0 -139
- package/src/channel/add.ts +0 -73
- package/src/channel/currentBundle.ts +0 -72
- package/src/channel/delete.ts +0 -51
- package/src/channel/list.ts +0 -49
- package/src/channel/set.ts +0 -174
- package/src/index.ts +0 -290
- package/src/init.ts +0 -301
- package/src/key.ts +0 -158
- package/src/login.ts +0 -66
- package/src/types/capacitor__cli.d.ts +0 -6
- package/src/types/supabase.types.ts +0 -2471
- package/src/utils.ts +0 -738
- package/test/chunk_convert.ts +0 -28
- package/test/data.ts +0 -18769
- package/test/test_headers_rls.ts +0 -24
- package/test/test_semver.ts +0 -13
- package/tsconfig.json +0 -39
package/src/app/add.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto'
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import mime from 'mime'
|
|
5
|
-
import { program } from 'commander'
|
|
6
|
-
import * as p from '@clack/prompts'
|
|
7
|
-
import { checkLatest } from '../api/update'
|
|
8
|
-
import type { Options } from '../api/app'
|
|
9
|
-
import { checkAppExists, newIconPath } from '../api/app'
|
|
10
|
-
import {
|
|
11
|
-
checkPlanValid,
|
|
12
|
-
createSupabaseClient,
|
|
13
|
-
findSavedKey,
|
|
14
|
-
formatError,
|
|
15
|
-
getConfig,
|
|
16
|
-
useLogSnag,
|
|
17
|
-
verifyUser,
|
|
18
|
-
} from '../utils'
|
|
19
|
-
|
|
20
|
-
export async function addApp(appId: string, options: Options, throwErr = true) {
|
|
21
|
-
if (throwErr)
|
|
22
|
-
p.intro(`Adding`)
|
|
23
|
-
|
|
24
|
-
await checkLatest()
|
|
25
|
-
options.apikey = options.apikey || findSavedKey()
|
|
26
|
-
const config = await getConfig()
|
|
27
|
-
appId = appId || config?.app?.appId
|
|
28
|
-
const snag = useLogSnag()
|
|
29
|
-
|
|
30
|
-
if (!options.apikey) {
|
|
31
|
-
p.log.error(`Missing API key, you need to provide a API key to upload your bundle`)
|
|
32
|
-
program.error('')
|
|
33
|
-
}
|
|
34
|
-
if (!appId) {
|
|
35
|
-
p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
36
|
-
program.error('')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (appId.includes('--')) {
|
|
40
|
-
p.log.error('The app id includes illegal symbols. You cannot use "--" in the app id')
|
|
41
|
-
program.error('')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const supabase = await createSupabaseClient(options.apikey)
|
|
45
|
-
|
|
46
|
-
let userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
|
|
47
|
-
|
|
48
|
-
// Check we have app access to this appId
|
|
49
|
-
const appExist = await checkAppExists(supabase, appId)
|
|
50
|
-
if (throwErr && appExist) {
|
|
51
|
-
p.log.error(`App ${appId} already exist`)
|
|
52
|
-
program.error('')
|
|
53
|
-
}
|
|
54
|
-
else if (appExist) {
|
|
55
|
-
return true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const { error: orgError, data: allOrganizations } = await supabase
|
|
59
|
-
.rpc('get_orgs_v5')
|
|
60
|
-
|
|
61
|
-
if (orgError) {
|
|
62
|
-
p.log.error('Cannot get the list of organizations - exiting')
|
|
63
|
-
p.log.error(`Error ${JSON.stringify(orgError)}`)
|
|
64
|
-
program.error('')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const adminOrgs = allOrganizations.filter(org => org.role === 'admin' || org.role === 'super_admin')
|
|
68
|
-
|
|
69
|
-
const organizationUidRaw = (adminOrgs.length > 1)
|
|
70
|
-
? await p.select({
|
|
71
|
-
message: 'Please pick the organization that you want to insert to',
|
|
72
|
-
options: adminOrgs.map((org) => {
|
|
73
|
-
return { value: org.gid, label: org.name }
|
|
74
|
-
}),
|
|
75
|
-
})
|
|
76
|
-
: adminOrgs[0].gid
|
|
77
|
-
|
|
78
|
-
if (p.isCancel(organizationUidRaw)) {
|
|
79
|
-
p.log.error('Canceled organization selection, exiting')
|
|
80
|
-
program.error('')
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const organizationUid = organizationUidRaw as string
|
|
84
|
-
const organization = allOrganizations.find(org => org.gid === organizationUid)!
|
|
85
|
-
userId = organization.created_by
|
|
86
|
-
|
|
87
|
-
p.log.info(`Using the organization "${organization.name}" as the app owner`)
|
|
88
|
-
|
|
89
|
-
await checkPlanValid(supabase, organizationUid, options.apikey, undefined, false)
|
|
90
|
-
|
|
91
|
-
let { name, icon } = options
|
|
92
|
-
appId = appId || config?.app?.appId
|
|
93
|
-
name = name || config?.app?.appName || 'Unknown'
|
|
94
|
-
icon = icon || 'resources/icon.png' // default path for capacitor app
|
|
95
|
-
if (!icon || !name) {
|
|
96
|
-
p.log.error('Missing argument, you need to provide a appId and a name, or be in a capacitor project')
|
|
97
|
-
program.error('')
|
|
98
|
-
}
|
|
99
|
-
if (throwErr)
|
|
100
|
-
p.log.info(`Adding ${appId} to Capgo`)
|
|
101
|
-
|
|
102
|
-
let iconBuff
|
|
103
|
-
let iconType
|
|
104
|
-
|
|
105
|
-
if (icon && existsSync(icon)) {
|
|
106
|
-
iconBuff = readFileSync(icon)
|
|
107
|
-
const contentType = mime.getType(icon)
|
|
108
|
-
iconType = contentType || 'image/png'
|
|
109
|
-
p.log.warn(`Found app icon ${icon}`)
|
|
110
|
-
}
|
|
111
|
-
else if (existsSync(newIconPath)) {
|
|
112
|
-
iconBuff = readFileSync(newIconPath)
|
|
113
|
-
const contentType = mime.getType(newIconPath)
|
|
114
|
-
iconType = contentType || 'image/png'
|
|
115
|
-
p.log.warn(`Found app icon ${newIconPath}`)
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
p.log.warn(`Cannot find app icon in any of the following locations: ${icon}, ${newIconPath}`)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const fileName = `icon_${randomUUID()}`
|
|
122
|
-
let signedURL = 'https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png'
|
|
123
|
-
|
|
124
|
-
// upload image if available
|
|
125
|
-
if (iconBuff && iconType) {
|
|
126
|
-
const { error } = await supabase.storage
|
|
127
|
-
.from(`images/${userId}/${appId}`)
|
|
128
|
-
.upload(fileName, iconBuff, {
|
|
129
|
-
contentType: iconType,
|
|
130
|
-
})
|
|
131
|
-
if (error) {
|
|
132
|
-
p.log.error(`Could not add app ${formatError(error)}`)
|
|
133
|
-
program.error('')
|
|
134
|
-
}
|
|
135
|
-
const { data: signedURLData } = await supabase
|
|
136
|
-
.storage
|
|
137
|
-
.from(`images/${userId}/${appId}`)
|
|
138
|
-
.getPublicUrl(fileName)
|
|
139
|
-
signedURL = signedURLData?.publicUrl || signedURL
|
|
140
|
-
}
|
|
141
|
-
// add app to db
|
|
142
|
-
const { error: dbError } = await supabase
|
|
143
|
-
.from('apps')
|
|
144
|
-
.insert({
|
|
145
|
-
icon_url: signedURL,
|
|
146
|
-
owner_org: organizationUid,
|
|
147
|
-
name,
|
|
148
|
-
app_id: appId,
|
|
149
|
-
})
|
|
150
|
-
if (dbError) {
|
|
151
|
-
p.log.error(`Could not add app ${formatError(dbError)}`)
|
|
152
|
-
program.error('')
|
|
153
|
-
}
|
|
154
|
-
const { error: dbVersionError } = await supabase
|
|
155
|
-
.from('app_versions')
|
|
156
|
-
.insert([{
|
|
157
|
-
owner_org: organizationUid,
|
|
158
|
-
deleted: true,
|
|
159
|
-
name: 'unknown',
|
|
160
|
-
app_id: appId,
|
|
161
|
-
}, {
|
|
162
|
-
owner_org: organizationUid,
|
|
163
|
-
deleted: true,
|
|
164
|
-
name: 'builtin',
|
|
165
|
-
app_id: appId,
|
|
166
|
-
}])
|
|
167
|
-
if (dbVersionError) {
|
|
168
|
-
p.log.error(`Could not add app ${formatError(dbVersionError)}`)
|
|
169
|
-
program.error('')
|
|
170
|
-
}
|
|
171
|
-
await snag.track({
|
|
172
|
-
channel: 'app',
|
|
173
|
-
event: 'App Added',
|
|
174
|
-
icon: '🎉',
|
|
175
|
-
user_id: userId,
|
|
176
|
-
tags: {
|
|
177
|
-
'app-id': appId,
|
|
178
|
-
},
|
|
179
|
-
notify: false,
|
|
180
|
-
}).catch()
|
|
181
|
-
p.log.success(`App ${appId} added to Capgo. ${throwErr ? 'You can upload a bundle now' : ''}`)
|
|
182
|
-
if (throwErr) {
|
|
183
|
-
p.outro(`Done ✅`)
|
|
184
|
-
process.exit()
|
|
185
|
-
}
|
|
186
|
-
return true
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export async function addCommand(apikey: string, options: Options) {
|
|
190
|
-
addApp(apikey, options, true)
|
|
191
|
-
}
|
package/src/app/debug.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import * as p from '@clack/prompts'
|
|
3
|
-
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
4
|
-
import { program } from 'commander'
|
|
5
|
-
import type LogSnag from 'logsnag'
|
|
6
|
-
import type { Database } from '../types/supabase.types'
|
|
7
|
-
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
|
|
8
|
-
import { checkLatest } from '../api/update'
|
|
9
|
-
import { OrganizationPerm, convertAppName, createSupabaseClient, findSavedKey, formatError, getConfig, getLocalConfig, useLogSnag, verifyUser } from '../utils'
|
|
10
|
-
|
|
11
|
-
function wait(ms: number) {
|
|
12
|
-
return new Promise((resolve) => {
|
|
13
|
-
setTimeout(resolve, ms)
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface OptionsBaseDebug {
|
|
18
|
-
apikey: string
|
|
19
|
-
device?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function markSnag(channel: string, userId: string, snag: LogSnag, event: string, icon = '✅') {
|
|
23
|
-
await snag.track({
|
|
24
|
-
channel,
|
|
25
|
-
event,
|
|
26
|
-
icon,
|
|
27
|
-
user_id: userId,
|
|
28
|
-
notify: false,
|
|
29
|
-
}).catch()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function cancelCommand(channel: string, command: boolean | symbol, userId: string, snag: LogSnag) {
|
|
33
|
-
if (p.isCancel(command)) {
|
|
34
|
-
await markSnag(channel, userId, snag, 'canceled', '🤷')
|
|
35
|
-
process.exit()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface Order {
|
|
40
|
-
key: string
|
|
41
|
-
sortable?: 'asc' | 'desc'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface QueryStats {
|
|
45
|
-
appId: string
|
|
46
|
-
devicesId?: string[]
|
|
47
|
-
search?: string
|
|
48
|
-
order?: Order[]
|
|
49
|
-
rangeStart?: number
|
|
50
|
-
rangeEnd?: number
|
|
51
|
-
after?: string
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function getStats(supabase: SupabaseClient<Database>, query: QueryStats): Promise<Database['public']['Tables']['stats']['Row'] | null> {
|
|
55
|
-
try {
|
|
56
|
-
const pathStats = 'private/stats'
|
|
57
|
-
const res = await supabase.functions.invoke(pathStats, { body: JSON.stringify(query) })
|
|
58
|
-
const listData = res.data.data as Database['public']['Tables']['stats']['Row'][]
|
|
59
|
-
if (listData?.length > 0)
|
|
60
|
-
return listData[0]
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
p.log.error(`Cannot get stats ${formatError(error)}`)
|
|
64
|
-
}
|
|
65
|
-
return null
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function waitLog(channel: string, supabase: SupabaseClient<Database>, appId: string, snag: LogSnag, userId: string, deviceId?: string) {
|
|
69
|
-
let loop = true
|
|
70
|
-
let now = new Date().toISOString()
|
|
71
|
-
const appIdUrl = convertAppName(appId)
|
|
72
|
-
const config = await getLocalConfig()
|
|
73
|
-
const baseUrl = `${config.hostWeb}/app/p/${appIdUrl}`
|
|
74
|
-
await markSnag(channel, userId, snag, 'Use waitlog')
|
|
75
|
-
const query: QueryStats = {
|
|
76
|
-
appId,
|
|
77
|
-
devicesId: deviceId ? [deviceId] : undefined,
|
|
78
|
-
order: [{
|
|
79
|
-
key: 'created_at',
|
|
80
|
-
sortable: 'desc',
|
|
81
|
-
}],
|
|
82
|
-
rangeStart: 0,
|
|
83
|
-
rangeEnd: 1,
|
|
84
|
-
after: now,
|
|
85
|
-
}
|
|
86
|
-
while (loop) {
|
|
87
|
-
const data = await getStats(supabase, query)
|
|
88
|
-
// console.log('data', data)
|
|
89
|
-
if (data) {
|
|
90
|
-
p.log.info(`Log from Device: ${data.device_id}`)
|
|
91
|
-
if (data.action === 'get') {
|
|
92
|
-
p.log.info('Update Sent your your device, wait until event download complete')
|
|
93
|
-
await markSnag(channel, userId, snag, 'done')
|
|
94
|
-
}
|
|
95
|
-
else if (data.action.startsWith('download_')) {
|
|
96
|
-
const action = data.action.split('_')[1]
|
|
97
|
-
if (action === 'complete') {
|
|
98
|
-
p.log.info('Your bundle has been downloaded on your device, background the app now and open it again to see the update')
|
|
99
|
-
await markSnag(channel, userId, snag, 'downloaded')
|
|
100
|
-
}
|
|
101
|
-
else if (action === 'fail') {
|
|
102
|
-
p.log.error('Your bundle has failed to download on your device.')
|
|
103
|
-
p.log.error('Please check if you have network connection and try again')
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
p.log.info(`Your bundle is downloading ${action}% ...`)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (data.action === 'set') {
|
|
110
|
-
p.log.info('Your bundle has been set on your device ❤️')
|
|
111
|
-
loop = false
|
|
112
|
-
await markSnag(channel, userId, snag, 'set')
|
|
113
|
-
return Promise.resolve(data)
|
|
114
|
-
}
|
|
115
|
-
else if (data.action === 'NoChannelOrOverride') {
|
|
116
|
-
p.log.error(`No default channel or override (channel/device) found, please create it here ${baseUrl}`)
|
|
117
|
-
}
|
|
118
|
-
else if (data.action === 'needPlanUpgrade') {
|
|
119
|
-
p.log.error('Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans')
|
|
120
|
-
}
|
|
121
|
-
else if (data.action === 'missingBundle') {
|
|
122
|
-
p.log.error('Your bundle is missing, please check how you build your app ')
|
|
123
|
-
}
|
|
124
|
-
else if (data.action === 'noNew') {
|
|
125
|
-
p.log.error(`Your version in ${data.platform} is the same as your version uploaded, change it to see the update`)
|
|
126
|
-
}
|
|
127
|
-
else if (data.action === 'disablePlatformIos') {
|
|
128
|
-
p.log.error(`iOS is disabled in the default channel and your device is an iOS device ${baseUrl}`)
|
|
129
|
-
}
|
|
130
|
-
else if (data.action === 'disablePlatformAndroid') {
|
|
131
|
-
p.log.error(`Android is disabled in the default channel and your device is an Android device ${baseUrl}`)
|
|
132
|
-
}
|
|
133
|
-
else if (data.action === 'disableAutoUpdateToMajor') {
|
|
134
|
-
p.log.error('Auto update to major version is disabled in the default channel.')
|
|
135
|
-
p.log.error('Set your app to the same major version as the default channel')
|
|
136
|
-
}
|
|
137
|
-
else if (data.action === 'disableAutoUpdateUnderNative') {
|
|
138
|
-
p.log.error('Auto update under native version is disabled in the default channel.')
|
|
139
|
-
p.log.error('Set your app to the same native version as the default channel.')
|
|
140
|
-
}
|
|
141
|
-
else if (data.action === 'disableDevBuild') {
|
|
142
|
-
p.log.error(`Dev build is disabled in the default channel. ${baseUrl}`)
|
|
143
|
-
p.log.error('Set your channel to allow it if you wanna test your app')
|
|
144
|
-
}
|
|
145
|
-
else if (data.action === 'disableEmulator') {
|
|
146
|
-
p.log.error(`Emulator is disabled in the default channel. ${baseUrl}`)
|
|
147
|
-
p.log.error('Set your channel to allow it if you wanna test your app')
|
|
148
|
-
}
|
|
149
|
-
else if (data.action === 'cannotGetBundle') {
|
|
150
|
-
p.log.error(`We cannot get your bundle from the default channel. ${baseUrl}`)
|
|
151
|
-
p.log.error('Are you sure your default channel has a bundle set?')
|
|
152
|
-
}
|
|
153
|
-
else if (data.action === 'set_fail') {
|
|
154
|
-
p.log.error(`Your bundle seems to be corrupted, try to download from ${baseUrl} to identify the issue`)
|
|
155
|
-
}
|
|
156
|
-
else if (data.action === 'reset') {
|
|
157
|
-
p.log.error('Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?')
|
|
158
|
-
}
|
|
159
|
-
else if (data.action === 'update_fail') {
|
|
160
|
-
p.log.error('Your bundle has been installed but failed to call notifyAppReady')
|
|
161
|
-
p.log.error('Please check if you have network connection and try again')
|
|
162
|
-
}
|
|
163
|
-
else if (data.action === 'checksum_fail') {
|
|
164
|
-
p.log.error('Your bundle has failed to validate checksum, please check your code and send it again to Capgo')
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
p.log.error(`Log from Capgo ${data.action}`)
|
|
168
|
-
}
|
|
169
|
-
now = new Date().toISOString()
|
|
170
|
-
query.after = now
|
|
171
|
-
}
|
|
172
|
-
await wait(1000)
|
|
173
|
-
}
|
|
174
|
-
return Promise.resolve()
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export async function debugApp(appId: string, options: OptionsBaseDebug) {
|
|
178
|
-
p.intro(`Debug Live update in Capgo`)
|
|
179
|
-
|
|
180
|
-
await checkLatest()
|
|
181
|
-
options.apikey = options.apikey || findSavedKey()
|
|
182
|
-
const config = await getConfig()
|
|
183
|
-
|
|
184
|
-
appId = appId || config?.app?.appId
|
|
185
|
-
const deviceId = options.device
|
|
186
|
-
if (!options.apikey) {
|
|
187
|
-
p.log.error(`Missing API key, you need to provide an API key to delete your app`)
|
|
188
|
-
program.error('')
|
|
189
|
-
}
|
|
190
|
-
if (!appId) {
|
|
191
|
-
p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
192
|
-
program.error('')
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const supabase = await createSupabaseClient(options.apikey)
|
|
196
|
-
const snag = useLogSnag()
|
|
197
|
-
|
|
198
|
-
const userId = await verifyUser(supabase, options.apikey)
|
|
199
|
-
|
|
200
|
-
p.log.info(`Getting active bundle in Capgo`)
|
|
201
|
-
|
|
202
|
-
// Check we have app access to this appId
|
|
203
|
-
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.admin)
|
|
204
|
-
|
|
205
|
-
const doRun = await p.confirm({ message: `Automatic check if update working in device ?` })
|
|
206
|
-
await cancelCommand('debug', doRun, userId, snag)
|
|
207
|
-
if (doRun) {
|
|
208
|
-
p.log.info(`Wait logs sent to Capgo from ${appId} device, Put the app in background and open it again.`)
|
|
209
|
-
p.log.info('Waiting...')
|
|
210
|
-
await waitLog('debug', supabase, appId, snag, userId, deviceId)
|
|
211
|
-
p.outro(`Done ✅`)
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
// const appIdUrl = convertAppName(appId)
|
|
215
|
-
// p.log.info(`Check logs in https://web.capgo.app/app/p/${appIdUrl}/logs to see if update works.`)
|
|
216
|
-
p.outro(`Canceled ❌`)
|
|
217
|
-
}
|
|
218
|
-
p.outro(`Done ✅`)
|
|
219
|
-
process.exit()
|
|
220
|
-
}
|
package/src/app/delete.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import { program } from 'commander'
|
|
3
|
-
import * as p from '@clack/prompts'
|
|
4
|
-
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
|
|
5
|
-
import type { OptionsBase } from '../utils'
|
|
6
|
-
import { OrganizationPerm, createSupabaseClient, findSavedKey, formatError, getConfig, useLogSnag, verifyUser } from '../utils'
|
|
7
|
-
|
|
8
|
-
export async function deleteApp(appId: string, options: OptionsBase) {
|
|
9
|
-
p.intro(`Deleting`)
|
|
10
|
-
options.apikey = options.apikey || findSavedKey()
|
|
11
|
-
const config = await getConfig()
|
|
12
|
-
appId = appId || config?.app?.appId
|
|
13
|
-
const snag = useLogSnag()
|
|
14
|
-
|
|
15
|
-
if (!options.apikey) {
|
|
16
|
-
p.log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
17
|
-
program.error('')
|
|
18
|
-
}
|
|
19
|
-
if (!appId) {
|
|
20
|
-
p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
21
|
-
program.error('')
|
|
22
|
-
}
|
|
23
|
-
const supabase = await createSupabaseClient(options.apikey)
|
|
24
|
-
|
|
25
|
-
const userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
|
|
26
|
-
// Check we have app access to this appId
|
|
27
|
-
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.super_admin)
|
|
28
|
-
|
|
29
|
-
const { data: appOwnerRaw, error: appOwnerError } = await supabase.from('apps')
|
|
30
|
-
.select(`owner_org ( created_by )`)
|
|
31
|
-
.eq('app_id', appId)
|
|
32
|
-
.single()
|
|
33
|
-
|
|
34
|
-
const appOwner = appOwnerRaw as { owner_org: { created_by: string } } | null
|
|
35
|
-
|
|
36
|
-
if (!appOwnerError && (appOwner?.owner_org.created_by ?? '') !== userId) {
|
|
37
|
-
// We are dealing with a member user that is not the owner
|
|
38
|
-
// Deleting the app is not recomended at this stage
|
|
39
|
-
|
|
40
|
-
p.log.warn('Deleting the app is not recomended for users that are not the organization owner')
|
|
41
|
-
p.log.warn('You are invited as a super_admin but your are not the owner')
|
|
42
|
-
p.log.warn('It\'s strongly recomended that you do not continue!')
|
|
43
|
-
|
|
44
|
-
const shouldContinue = await p.select({
|
|
45
|
-
message: 'Do you want to continue?',
|
|
46
|
-
options: [
|
|
47
|
-
{
|
|
48
|
-
label: 'Yes',
|
|
49
|
-
value: 'yes',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
label: 'No',
|
|
53
|
-
value: 'no',
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
if (p.isCancel(shouldContinue) || shouldContinue === 'no') {
|
|
59
|
-
p.log.error('Canceled deleting the app, exiting')
|
|
60
|
-
program.error('')
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (appOwnerError) {
|
|
64
|
-
p.log.warn(`Cannot get the app owner ${formatError(appOwnerError)}`)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const { error } = await supabase
|
|
68
|
-
.storage
|
|
69
|
-
.from(`images/${userId}`)
|
|
70
|
-
.remove([appId])
|
|
71
|
-
if (error)
|
|
72
|
-
p.log.error('Could not delete app logo')
|
|
73
|
-
|
|
74
|
-
const { error: delError } = await supabase
|
|
75
|
-
.storage
|
|
76
|
-
.from(`apps/${appId}/${userId}`)
|
|
77
|
-
.remove(['versions'])
|
|
78
|
-
if (delError)
|
|
79
|
-
p.log.error('Could not delete app version')
|
|
80
|
-
// We should not care too much, most is in r2 anyways :/
|
|
81
|
-
// program.error('')
|
|
82
|
-
|
|
83
|
-
const { error: dbError } = await supabase
|
|
84
|
-
.from('apps')
|
|
85
|
-
.delete()
|
|
86
|
-
.eq('app_id', appId)
|
|
87
|
-
.eq('user_id', userId)
|
|
88
|
-
|
|
89
|
-
if (dbError) {
|
|
90
|
-
p.log.error('Could not delete app')
|
|
91
|
-
program.error('')
|
|
92
|
-
}
|
|
93
|
-
await snag.track({
|
|
94
|
-
channel: 'app',
|
|
95
|
-
event: 'App Deleted',
|
|
96
|
-
icon: '🗑️',
|
|
97
|
-
user_id: userId,
|
|
98
|
-
tags: {
|
|
99
|
-
'app-id': appId,
|
|
100
|
-
},
|
|
101
|
-
notify: false,
|
|
102
|
-
}).catch()
|
|
103
|
-
p.log.success(`App deleted in Capgo`)
|
|
104
|
-
p.outro('Done ✅')
|
|
105
|
-
process.exit()
|
|
106
|
-
}
|
package/src/app/info.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import os from 'node:os'
|
|
4
|
-
import process from 'node:process'
|
|
5
|
-
import getLatest from 'get-latest-version'
|
|
6
|
-
import Spinnies from '@trufflesuite/spinnies'
|
|
7
|
-
import * as p from '@clack/prompts'
|
|
8
|
-
import pack from '../../package.json'
|
|
9
|
-
|
|
10
|
-
async function getLatestDependencies(installedDependencies: { [key: string]: string }) {
|
|
11
|
-
const latestDependencies: { [key: string]: string } = {}
|
|
12
|
-
const all = []
|
|
13
|
-
for (const dependency in installedDependencies) {
|
|
14
|
-
if (Object.prototype.hasOwnProperty.call(installedDependencies, dependency)) {
|
|
15
|
-
// get in npm the last version of the dependency
|
|
16
|
-
all.push(getLatest(dependency))
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
await Promise.all(all)
|
|
20
|
-
.then((values) => {
|
|
21
|
-
const keys = Object.keys(installedDependencies)
|
|
22
|
-
for (let i = 0; i < values.length; i += 1) {
|
|
23
|
-
const v = values[i]
|
|
24
|
-
if (v)
|
|
25
|
-
latestDependencies[keys[i]] = v
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
return latestDependencies
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function readPackageJson() {
|
|
32
|
-
const packageJson = readFileSync(join(process.cwd(), 'package.json'))
|
|
33
|
-
return JSON.parse(packageJson as any)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function getInstalledDependencies() {
|
|
37
|
-
const { dependencies } = await readPackageJson()
|
|
38
|
-
const installedDependencies: { [key: string]: string } = {
|
|
39
|
-
'@capgo/cli': pack.version,
|
|
40
|
-
}
|
|
41
|
-
for (const dependency in dependencies) {
|
|
42
|
-
if (Object.prototype.hasOwnProperty.call(dependencies, dependency) && dependency.startsWith('@capgo/')) {
|
|
43
|
-
// remove ^ or ~ from version
|
|
44
|
-
const version = dependencies[dependency].replace('^', '').replace('~', '')
|
|
45
|
-
installedDependencies[dependency] = version
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return installedDependencies
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function getInfo() {
|
|
52
|
-
p.log.info(' 💊 Capgo Doctor 💊\n')
|
|
53
|
-
p.log.info(` OS: ${os.platform()} ${os.version()}\n`)
|
|
54
|
-
p.log.info(` Node: ${process.version}\n`)
|
|
55
|
-
p.log.info(' Installed Dependencies:\n')
|
|
56
|
-
const installedDependencies = await getInstalledDependencies()
|
|
57
|
-
if (Object.keys(installedDependencies).length === 0) {
|
|
58
|
-
// display in red color in shell with console log
|
|
59
|
-
p.log.warning('\x1B[31m%s\x1B[0m 🚨 No dependencies found')
|
|
60
|
-
process.exit(1)
|
|
61
|
-
}
|
|
62
|
-
for (const dependency in installedDependencies) {
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(installedDependencies, dependency)) {
|
|
64
|
-
const installedVersion = (installedDependencies as any)[dependency]
|
|
65
|
-
p.log.info(` ${dependency}: ${installedVersion}`)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
p.log.info('\n')
|
|
69
|
-
const spinnies = new Spinnies()
|
|
70
|
-
spinnies.add('loading', { text: ' Loading latest dependencies' })
|
|
71
|
-
const latestDependencies = await getLatestDependencies(installedDependencies)
|
|
72
|
-
spinnies.succeed('loading', { text: ' Latest Dependencies:' })
|
|
73
|
-
for (const dependency in latestDependencies) {
|
|
74
|
-
if (Object.prototype.hasOwnProperty.call(latestDependencies, dependency)) {
|
|
75
|
-
const latestVersion = (latestDependencies as any)[dependency]
|
|
76
|
-
p.log.info(` ${dependency}: ${latestVersion}`)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (JSON.stringify(installedDependencies) !== JSON.stringify(latestDependencies)) {
|
|
80
|
-
// display in red color in shell with console log
|
|
81
|
-
p.log.warn('\x1B[31m🚨 Some dependencies are not up to date\x1B[0m')
|
|
82
|
-
process.exit(1)
|
|
83
|
-
}
|
|
84
|
-
// display in green color in shell with console log
|
|
85
|
-
p.log.success('\x1B[32m✅ All dependencies are up to date\x1B[0m')
|
|
86
|
-
process.exit()
|
|
87
|
-
}
|
package/src/app/list.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import { program } from 'commander'
|
|
3
|
-
import { Table } from 'console-table-printer'
|
|
4
|
-
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
5
|
-
import * as p from '@clack/prompts'
|
|
6
|
-
import type { Database } from '../types/supabase.types'
|
|
7
|
-
import type { OptionsBase } from '../utils'
|
|
8
|
-
import { createSupabaseClient, findSavedKey, getHumanDate, verifyUser } from '../utils'
|
|
9
|
-
import { checkLatest } from '../api/update'
|
|
10
|
-
|
|
11
|
-
function displayApp(data: Database['public']['Tables']['apps']['Row'][]) {
|
|
12
|
-
if (!data.length) {
|
|
13
|
-
p.log.error('No apps found')
|
|
14
|
-
process.exit(1)
|
|
15
|
-
}
|
|
16
|
-
const t = new Table({
|
|
17
|
-
title: 'Apps',
|
|
18
|
-
charLength: { '❌': 2, '✅': 2 },
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
// add rows with color
|
|
22
|
-
data.reverse().forEach((row) => {
|
|
23
|
-
t.addRow({
|
|
24
|
-
Name: row.name,
|
|
25
|
-
id: row.app_id,
|
|
26
|
-
Created: getHumanDate(row.created_at),
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
p.log.success(t.render())
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function getActiveApps(supabase: SupabaseClient<Database>) {
|
|
34
|
-
const { data, error: vError } = await supabase
|
|
35
|
-
.from('apps')
|
|
36
|
-
.select()
|
|
37
|
-
// .eq('user_id', userId)
|
|
38
|
-
.order('created_at', { ascending: false })
|
|
39
|
-
|
|
40
|
-
if (vError) {
|
|
41
|
-
p.log.error('Apps not found')
|
|
42
|
-
program.error('')
|
|
43
|
-
}
|
|
44
|
-
return data
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function listApp(options: OptionsBase) {
|
|
48
|
-
p.intro(`List apps in Capgo`)
|
|
49
|
-
|
|
50
|
-
await checkLatest()
|
|
51
|
-
options.apikey = options.apikey || findSavedKey()
|
|
52
|
-
|
|
53
|
-
const supabase = await createSupabaseClient(options.apikey)
|
|
54
|
-
|
|
55
|
-
await verifyUser(supabase, options.apikey, ['write', 'all', 'read', 'upload'])
|
|
56
|
-
|
|
57
|
-
p.log.info(`Getting active bundle in Capgo`)
|
|
58
|
-
|
|
59
|
-
// Get all active app versions we might possibly be able to cleanup
|
|
60
|
-
const allApps = await getActiveApps(supabase)
|
|
61
|
-
|
|
62
|
-
p.log.info(`Active app in Capgo: ${allApps?.length}`)
|
|
63
|
-
|
|
64
|
-
displayApp(allApps)
|
|
65
|
-
p.outro(`Done ✅`)
|
|
66
|
-
process.exit()
|
|
67
|
-
}
|