@capgo/cli 4.12.12 → 4.12.14-beta.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/.github/workflows/autofix.yml +25 -0
- package/CHANGELOG.md +9 -0
- package/bun.lockb +0 -0
- package/bunfig.toml +2 -0
- package/dist/index.js +40559 -50832
- package/package.json +22 -24
- package/src/api/app.ts +5 -5
- package/src/api/channels.ts +12 -12
- package/src/api/devices_override.ts +8 -8
- package/src/api/update.ts +2 -2
- package/src/api/versions.ts +10 -9
- package/src/app/add.ts +21 -22
- package/src/app/debug.ts +53 -54
- package/src/app/delete.ts +20 -20
- package/src/app/info.ts +34 -24
- package/src/app/list.ts +11 -11
- package/src/app/set.ts +16 -16
- package/src/bundle/check.ts +10 -10
- package/src/bundle/cleanup.ts +27 -27
- package/src/bundle/compatibility.ts +8 -8
- package/src/bundle/decrypt.ts +8 -8
- package/src/bundle/delete.ts +14 -15
- package/src/bundle/encrypt.ts +13 -13
- package/src/bundle/list.ts +11 -12
- package/src/bundle/unlink.ts +15 -13
- package/src/bundle/upload.ts +93 -86
- package/src/bundle/zip.ts +23 -21
- package/src/channel/add.ts +14 -14
- package/src/channel/currentBundle.ts +13 -13
- package/src/channel/delete.ts +13 -13
- package/src/channel/list.ts +11 -11
- package/src/channel/set.ts +28 -26
- package/src/config/index.ts +156 -0
- package/src/index.ts +6 -3
- package/src/init.ts +22 -22
- package/src/key.ts +45 -46
- package/src/login.ts +10 -10
- package/src/user/account.ts +3 -3
- package/src/utils.ts +119 -150
- package/tsconfig.json +1 -1
- package/vercel-ncc.js +18 -0
package/src/bundle/cleanup.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { exit } from 'node:process'
|
|
2
2
|
import { program } from 'commander'
|
|
3
3
|
import semver from 'semver/preload'
|
|
4
|
-
import * as p from '@clack/prompts'
|
|
5
4
|
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
5
|
+
import { confirm as confirmC, intro, isCancel, log, outro } from '@clack/prompts'
|
|
6
6
|
import type { Database } from '../types/supabase.types'
|
|
7
7
|
import type { OptionsBase } from '../utils'
|
|
8
8
|
import { OrganizationPerm, createSupabaseClient, findSavedKey, getConfig, getHumanDate, verifyUser } from '../utils'
|
|
@@ -20,7 +20,7 @@ interface Options extends OptionsBase {
|
|
|
20
20
|
async function removeVersions(toRemove: Database['public']['Tables']['app_versions']['Row'][], supabase: SupabaseClient<Database>, appid: string) {
|
|
21
21
|
// call deleteSpecificVersion one by one from toRemove sync
|
|
22
22
|
for await (const row of toRemove) {
|
|
23
|
-
|
|
23
|
+
log.warn(`Removing ${row.name} created on ${(getHumanDate(row.created_at))}`)
|
|
24
24
|
await deleteSpecificVersion(supabase, appid, row.name)
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -35,21 +35,21 @@ function getRemovableVersionsInSemverRange(data: Database['public']['Tables']['a
|
|
|
35
35
|
return toRemove
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export async function cleanupBundle(
|
|
39
|
-
|
|
38
|
+
export async function cleanupBundle(appId: string, options: Options) {
|
|
39
|
+
intro(`Cleanup versions in Capgo`)
|
|
40
40
|
await checkLatest()
|
|
41
41
|
options.apikey = options.apikey || findSavedKey()
|
|
42
42
|
const { bundle, keep = 4 } = options
|
|
43
43
|
const force = options.force || false
|
|
44
44
|
|
|
45
|
-
const
|
|
46
|
-
|
|
45
|
+
const extConfig = await getConfig()
|
|
46
|
+
appId = appId || extConfig?.config?.appId
|
|
47
47
|
if (!options.apikey) {
|
|
48
|
-
|
|
48
|
+
log.error('Missing API key, you need to provide an API key to delete your app')
|
|
49
49
|
program.error('')
|
|
50
50
|
}
|
|
51
|
-
if (!
|
|
52
|
-
|
|
51
|
+
if (!appId) {
|
|
52
|
+
log.error('Missing argument, you need to provide a appid, or be in a capacitor project')
|
|
53
53
|
program.error('')
|
|
54
54
|
}
|
|
55
55
|
const supabase = await createSupabaseClient(options.apikey)
|
|
@@ -57,27 +57,27 @@ export async function cleanupBundle(appid: string, options: Options) {
|
|
|
57
57
|
await verifyUser(supabase, options.apikey, ['write', 'all'])
|
|
58
58
|
|
|
59
59
|
// Check we have app access to this appId
|
|
60
|
-
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey,
|
|
61
|
-
|
|
60
|
+
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.write)
|
|
61
|
+
log.info(`Querying all available versions in Capgo`)
|
|
62
62
|
|
|
63
63
|
// Get all active app versions we might possibly be able to cleanup
|
|
64
|
-
let allVersions: (Database['public']['Tables']['app_versions']['Row'] & { keep?: string })[] = await getActiveAppVersions(supabase,
|
|
64
|
+
let allVersions: (Database['public']['Tables']['app_versions']['Row'] & { keep?: string })[] = await getActiveAppVersions(supabase, appId)
|
|
65
65
|
|
|
66
|
-
const versionInUse = await getChannelsVersion(supabase,
|
|
66
|
+
const versionInUse = await getChannelsVersion(supabase, appId)
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
log.info(`Total active versions in Capgo: ${allVersions?.length}`)
|
|
69
69
|
if (allVersions?.length === 0) {
|
|
70
|
-
|
|
70
|
+
log.error('No versions found, aborting cleanup')
|
|
71
71
|
return
|
|
72
72
|
}
|
|
73
73
|
if (bundle) {
|
|
74
74
|
const nextMajor = `${semver.inc(bundle, 'major')}`
|
|
75
|
-
|
|
75
|
+
log.info(`Querying available versions in Capgo between ${bundle} and ${nextMajor}`)
|
|
76
76
|
|
|
77
77
|
// Get all app versions that are in the given range
|
|
78
78
|
allVersions = getRemovableVersionsInSemverRange(allVersions, bundle, nextMajor) as (Database['public']['Tables']['app_versions']['Row'] & { keep: string })[]
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
log.info(`Active versions in Capgo between ${bundle} and ${nextMajor}: ${allVersions?.length}`)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// Slice to keep and remove
|
|
@@ -102,22 +102,22 @@ export async function cleanupBundle(appid: string, options: Options) {
|
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
if (toRemove.length === 0) {
|
|
105
|
-
|
|
105
|
+
log.warn('Nothing to be removed, aborting removal...')
|
|
106
106
|
return
|
|
107
107
|
}
|
|
108
108
|
displayBundles(allVersions)
|
|
109
109
|
// Check user wants to clean that all up
|
|
110
110
|
if (!force) {
|
|
111
|
-
const doDelete = await
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
const doDelete = await confirmC({ message: 'Do you want to continue removing the versions specified?' })
|
|
112
|
+
if (isCancel(doDelete) || !doDelete) {
|
|
113
|
+
log.warn('Not confirmed, aborting removal...')
|
|
114
|
+
exit()
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// Yes, lets clean it up
|
|
119
|
-
|
|
120
|
-
await removeVersions(toRemove, supabase,
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
log.success('You have confirmed removal, removing versions now')
|
|
120
|
+
await removeVersions(toRemove, supabase, appId)
|
|
121
|
+
outro(`Done ✅`)
|
|
122
|
+
exit()
|
|
123
123
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as p from '@clack/prompts'
|
|
2
1
|
import { program } from 'commander'
|
|
3
2
|
import { Table } from 'console-table-printer'
|
|
3
|
+
import { intro, log } from '@clack/prompts'
|
|
4
4
|
import type { OptionsBase } from '../utils'
|
|
5
5
|
import { OrganizationPerm, checkCompatibility, createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils'
|
|
6
6
|
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
|
|
@@ -11,24 +11,24 @@ interface Options extends OptionsBase {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export async function checkCompatibilityCommand(appId: string, options: Options) {
|
|
14
|
-
|
|
14
|
+
intro(`Check compatibility`)
|
|
15
15
|
options.apikey = options.apikey || findSavedKey()
|
|
16
|
-
const
|
|
17
|
-
appId = appId || config?.
|
|
16
|
+
const extConfig = await getConfig()
|
|
17
|
+
appId = appId || extConfig?.config?.appId
|
|
18
18
|
|
|
19
19
|
const { channel } = options
|
|
20
20
|
|
|
21
21
|
if (!channel) {
|
|
22
|
-
|
|
22
|
+
log.error('Missing argument, you need to provide a channel')
|
|
23
23
|
program.error('')
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (!options.apikey) {
|
|
27
|
-
|
|
27
|
+
log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
28
28
|
program.error('')
|
|
29
29
|
}
|
|
30
30
|
if (!appId) {
|
|
31
|
-
|
|
31
|
+
log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
32
32
|
program.error('')
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -66,5 +66,5 @@ export async function checkCompatibilityCommand(appId: string, options: Options)
|
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
log.success(t.render())
|
|
70
70
|
}
|
package/src/bundle/decrypt.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import
|
|
2
|
+
import { exit } from 'node:process'
|
|
3
3
|
import { program } from 'commander'
|
|
4
|
-
import
|
|
4
|
+
import { intro, log, outro } from '@clack/prompts'
|
|
5
5
|
import { decryptSource } from '../api/crypto'
|
|
6
6
|
import { baseKey, getConfig } from '../utils'
|
|
7
7
|
import { checkLatest } from '../api/update'
|
|
@@ -12,12 +12,12 @@ interface Options {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export async function decryptZip(zipPath: string, ivsessionKey: string, options: Options) {
|
|
15
|
-
|
|
15
|
+
intro(`Decrypt zip file`)
|
|
16
16
|
await checkLatest()
|
|
17
17
|
// write in file .capgo the apikey in home directory
|
|
18
18
|
|
|
19
19
|
if (!existsSync(zipPath)) {
|
|
20
|
-
|
|
20
|
+
log.error(`Zip not found at the path ${zipPath}`)
|
|
21
21
|
program.error('')
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ export async function decryptZip(zipPath: string, ivsessionKey: string, options:
|
|
|
25
25
|
const { extConfig } = config.app
|
|
26
26
|
|
|
27
27
|
if (!options.key && !existsSync(baseKey) && !extConfig.plugins?.CapacitorUpdater?.privateKey) {
|
|
28
|
-
|
|
28
|
+
log.error(`Private Key not found at the path ${baseKey} or in ${config.apextConfigFilePath}`)
|
|
29
29
|
program.error('')
|
|
30
30
|
}
|
|
31
31
|
const keyPath = options.key || baseKey
|
|
@@ -34,7 +34,7 @@ export async function decryptZip(zipPath: string, ivsessionKey: string, options:
|
|
|
34
34
|
let privateKey = extConfig?.plugins?.CapacitorUpdater?.privateKey
|
|
35
35
|
|
|
36
36
|
if (!existsSync(keyPath) && !privateKey) {
|
|
37
|
-
|
|
37
|
+
log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.apextConfigFilePath}`)
|
|
38
38
|
program.error('')
|
|
39
39
|
}
|
|
40
40
|
else if (existsSync(keyPath)) {
|
|
@@ -49,6 +49,6 @@ export async function decryptZip(zipPath: string, ivsessionKey: string, options:
|
|
|
49
49
|
const decodedZip = decryptSource(zipFile, ivsessionKey, options.keyData ?? privateKey ?? '')
|
|
50
50
|
// write decodedZip in a file
|
|
51
51
|
writeFileSync(`${zipPath}_decrypted.zip`, decodedZip)
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
outro(`Decrypted zip file at ${zipPath}_decrypted.zip`)
|
|
53
|
+
exit()
|
|
54
54
|
}
|
package/src/bundle/delete.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { exit } from 'node:process'
|
|
2
2
|
import { program } from 'commander'
|
|
3
|
-
import
|
|
3
|
+
import { intro, log, outro } from '@clack/prompts'
|
|
4
4
|
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
|
|
5
5
|
import type { OptionsBase } from '../utils'
|
|
6
6
|
import { OrganizationPerm, createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils'
|
|
@@ -11,17 +11,17 @@ interface Options extends OptionsBase {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export async function deleteBundle(bundleId: string, appId: string, options: Options) {
|
|
14
|
-
|
|
14
|
+
intro(`Delete bundle`)
|
|
15
15
|
options.apikey = options.apikey || findSavedKey()
|
|
16
|
-
const
|
|
17
|
-
appId = appId || config?.
|
|
16
|
+
const extConfig = await getConfig()
|
|
17
|
+
appId = appId || extConfig?.config?.appId
|
|
18
18
|
|
|
19
19
|
if (!options.apikey) {
|
|
20
|
-
|
|
20
|
+
log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
21
21
|
program.error('')
|
|
22
22
|
}
|
|
23
23
|
if (!appId) {
|
|
24
|
-
|
|
24
|
+
log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
25
25
|
program.error('')
|
|
26
26
|
}
|
|
27
27
|
const supabase = await createSupabaseClient(options.apikey)
|
|
@@ -30,24 +30,23 @@ export async function deleteBundle(bundleId: string, appId: string, options: Opt
|
|
|
30
30
|
// Check we have app access to this appId
|
|
31
31
|
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.write)
|
|
32
32
|
|
|
33
|
-
appId = appId || config?.app?.appId
|
|
34
33
|
if (!options.apikey) {
|
|
35
|
-
|
|
34
|
+
log.error('Missing API key, you need to provide an API key to delete your app')
|
|
36
35
|
program.error('')
|
|
37
36
|
}
|
|
38
37
|
if (!bundleId) {
|
|
39
|
-
|
|
38
|
+
log.error('Missing argument, you need to provide a bundleId, or be in a capacitor project')
|
|
40
39
|
program.error('')
|
|
41
40
|
}
|
|
42
41
|
if (!appId) {
|
|
43
|
-
|
|
42
|
+
log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
44
43
|
program.error('')
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
log.info(`Deleting bundle ${appId}@${bundleId} from Capgo`)
|
|
48
47
|
|
|
49
48
|
await deleteSpecificVersion(supabase, appId, bundleId)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
log.success(`Bundle ${appId}@${bundleId} deleted in Capgo`)
|
|
50
|
+
outro(`Done`)
|
|
51
|
+
exit()
|
|
53
52
|
}
|
package/src/bundle/encrypt.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import
|
|
2
|
+
import { exit } from 'node:process'
|
|
3
3
|
import { program } from 'commander'
|
|
4
4
|
import ciDetect from 'ci-info'
|
|
5
|
-
import
|
|
5
|
+
import { intro, log, outro } from '@clack/prompts'
|
|
6
6
|
import { checkLatest } from '../api/update'
|
|
7
7
|
import { encryptSource } from '../api/crypto'
|
|
8
8
|
import { baseKeyPub, getLocalConfig } from '../utils'
|
|
@@ -13,7 +13,7 @@ interface Options {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export async function encryptZip(zipPath: string, options: Options) {
|
|
16
|
-
|
|
16
|
+
intro(`Encryption`)
|
|
17
17
|
|
|
18
18
|
await checkLatest()
|
|
19
19
|
const localConfig = await getLocalConfig()
|
|
@@ -21,7 +21,7 @@ export async function encryptZip(zipPath: string, options: Options) {
|
|
|
21
21
|
// write in file .capgo the apikey in home directory
|
|
22
22
|
|
|
23
23
|
if (!existsSync(zipPath)) {
|
|
24
|
-
|
|
24
|
+
log.error(`Error: Zip not found at the path ${zipPath}`)
|
|
25
25
|
program.error('')
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -31,14 +31,14 @@ export async function encryptZip(zipPath: string, options: Options) {
|
|
|
31
31
|
let publicKey = options.keyData || ''
|
|
32
32
|
|
|
33
33
|
if (!existsSync(keyPath) && !publicKey) {
|
|
34
|
-
|
|
34
|
+
log.warning(`Cannot find public key ${keyPath} or as keyData option`)
|
|
35
35
|
if (ciDetect.isCI) {
|
|
36
|
-
|
|
36
|
+
log.error(`Error: Missing public key`)
|
|
37
37
|
program.error('')
|
|
38
38
|
}
|
|
39
|
-
const res = await
|
|
39
|
+
const res = await confirm({ message: 'Do you want to use our public key ?' })
|
|
40
40
|
if (!res) {
|
|
41
|
-
|
|
41
|
+
log.error(`Error: Missing public key`)
|
|
42
42
|
program.error('')
|
|
43
43
|
}
|
|
44
44
|
publicKey = localConfig.signKey || ''
|
|
@@ -51,10 +51,10 @@ export async function encryptZip(zipPath: string, options: Options) {
|
|
|
51
51
|
|
|
52
52
|
const zipFile = readFileSync(zipPath)
|
|
53
53
|
const encodedZip = encryptSource(zipFile, publicKey)
|
|
54
|
-
|
|
54
|
+
log.success(`ivSessionKey: ${encodedZiivSessionKey}`)
|
|
55
55
|
// write decodedZip in a file
|
|
56
|
-
writeFileSync(`${zipPath}_encrypted.zip`,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
writeFileSync(`${zipPath}_encrypted.zip`, encodedZiencryptedData)
|
|
57
|
+
log.success(`Encrypted zip saved at ${zipPath}_encrypted.zip`)
|
|
58
|
+
outro(`Done ✅`)
|
|
59
|
+
exit()
|
|
60
60
|
}
|
package/src/bundle/list.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { exit } from 'node:process'
|
|
2
2
|
import { program } from 'commander'
|
|
3
|
-
import
|
|
3
|
+
import { intro, log, outro } from '@clack/prompts'
|
|
4
4
|
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
|
|
5
5
|
import { displayBundles, getActiveAppVersions } from '../api/versions'
|
|
6
6
|
import type { OptionsBase } from '../utils'
|
|
@@ -8,18 +8,17 @@ import { OrganizationPerm, createSupabaseClient, findSavedKey, getConfig, verify
|
|
|
8
8
|
import { checkLatest } from '../api/update'
|
|
9
9
|
|
|
10
10
|
export async function listBundle(appId: string, options: OptionsBase) {
|
|
11
|
-
|
|
11
|
+
intro(`List bundles`)
|
|
12
12
|
await checkLatest()
|
|
13
13
|
options.apikey = options.apikey || findSavedKey()
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
appId = appId || config?.app?.appId
|
|
14
|
+
const extConfig = await getConfig()
|
|
15
|
+
appId = appId || extConfig?.config?.appId
|
|
17
16
|
if (!options.apikey) {
|
|
18
|
-
|
|
17
|
+
log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
19
18
|
program.error('')
|
|
20
19
|
}
|
|
21
20
|
if (!appId) {
|
|
22
|
-
|
|
21
|
+
log.error('Missing argument, you need to provide a appid, or be in a capacitor project')
|
|
23
22
|
program.error('')
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -27,7 +26,7 @@ export async function listBundle(appId: string, options: OptionsBase) {
|
|
|
27
26
|
|
|
28
27
|
await verifyUser(supabase, options.apikey, ['write', 'all', 'read', 'upload'])
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
log.info(`Querying available versions of: ${appId} in Capgo`)
|
|
31
30
|
|
|
32
31
|
// Check we have app access to this appId
|
|
33
32
|
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.read)
|
|
@@ -35,9 +34,9 @@ export async function listBundle(appId: string, options: OptionsBase) {
|
|
|
35
34
|
// Get all active app versions we might possibly be able to cleanup
|
|
36
35
|
const allVersions = await getActiveAppVersions(supabase, appId)
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
log.info(`Active versions in Capgo: ${allVersions?.length}`)
|
|
39
38
|
|
|
40
39
|
displayBundles(allVersions)
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
outro(`Done ✅`)
|
|
41
|
+
exit()
|
|
43
42
|
}
|
package/src/bundle/unlink.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { exit } from 'node:process'
|
|
2
2
|
import { program } from 'commander'
|
|
3
|
-
import
|
|
3
|
+
import { intro, log, outro } from '@clack/prompts'
|
|
4
4
|
import { getVersionData } from '../api/versions'
|
|
5
5
|
import { checkVersionNotUsedInDeviceOverride } from '../api/devices_override'
|
|
6
6
|
import { checkVersionNotUsedInChannel } from '../api/channels'
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
formatError,
|
|
17
17
|
getConfig,
|
|
18
18
|
getOrganizationId,
|
|
19
|
+
readPackageJson,
|
|
19
20
|
useLogSnag,
|
|
20
21
|
verifyUser,
|
|
21
22
|
} from '../utils'
|
|
@@ -25,25 +26,26 @@ interface Options extends OptionsBase {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export async function unlinkDevice(channel: string, appId: string, options: Options) {
|
|
28
|
-
|
|
29
|
+
intro(`Unlink bundle ${options.apikey}`)
|
|
29
30
|
options.apikey = options.apikey || findSavedKey()
|
|
30
|
-
const
|
|
31
|
-
appId = appId || config?.
|
|
31
|
+
const extConfig = await getConfig()
|
|
32
|
+
appId = appId || extConfig?.config?.appId
|
|
32
33
|
const snag = useLogSnag()
|
|
33
34
|
let { bundle } = options
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
const pack = await readPackageJson()
|
|
37
|
+
bundle = bundle || pack?.version
|
|
36
38
|
|
|
37
39
|
if (!options.apikey) {
|
|
38
|
-
|
|
40
|
+
log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
39
41
|
program.error('')
|
|
40
42
|
}
|
|
41
43
|
if (!appId) {
|
|
42
|
-
|
|
44
|
+
log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
|
|
43
45
|
program.error('')
|
|
44
46
|
}
|
|
45
47
|
if (!bundle) {
|
|
46
|
-
|
|
48
|
+
log.error('Missing argument, you need to provide a bundle, or be in a capacitor project')
|
|
47
49
|
program.error('')
|
|
48
50
|
}
|
|
49
51
|
const supabase = await createSupabaseClient(options.apikey)
|
|
@@ -57,7 +59,7 @@ export async function unlinkDevice(channel: string, appId: string, options: Opti
|
|
|
57
59
|
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.write)
|
|
58
60
|
|
|
59
61
|
if (!channel) {
|
|
60
|
-
|
|
62
|
+
log.error('Missing argument, you need to provide a channel')
|
|
61
63
|
program.error('')
|
|
62
64
|
}
|
|
63
65
|
try {
|
|
@@ -78,9 +80,9 @@ export async function unlinkDevice(channel: string, appId: string, options: Opti
|
|
|
78
80
|
}).catch()
|
|
79
81
|
}
|
|
80
82
|
catch (err) {
|
|
81
|
-
|
|
83
|
+
log.error(`Unknow error ${formatError(err)}`)
|
|
82
84
|
program.error('')
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
outro('Done ✅')
|
|
87
|
+
exit()
|
|
86
88
|
}
|