@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.
@@ -1,8 +1,8 @@
1
- import process from 'node:process'
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
- p.log.warn(`Removing ${row.name} created on ${(getHumanDate(row.created_at))}`)
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(appid: string, options: Options) {
39
- p.intro(`Cleanup versions in Capgo`)
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 config = await getConfig()
46
- appid = appid || config?.app?.appId
45
+ const extConfig = await getConfig()
46
+ appId = appId || extConfig?.config?.appId
47
47
  if (!options.apikey) {
48
- p.log.error('Missing API key, you need to provide an API key to delete your app')
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 (!appid) {
52
- p.log.error('Missing argument, you need to provide a appid, or be in a capacitor project')
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, appid, OrganizationPerm.write)
61
- p.log.info(`Querying all available versions in Capgo`)
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, appid)
64
+ let allVersions: (Database['public']['Tables']['app_versions']['Row'] & { keep?: string })[] = await getActiveAppVersions(supabase, appId)
65
65
 
66
- const versionInUse = await getChannelsVersion(supabase, appid)
66
+ const versionInUse = await getChannelsVersion(supabase, appId)
67
67
 
68
- p.log.info(`Total active versions in Capgo: ${allVersions?.length}`)
68
+ log.info(`Total active versions in Capgo: ${allVersions?.length}`)
69
69
  if (allVersions?.length === 0) {
70
- p.log.error('No versions found, aborting cleanup')
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
- p.log.info(`Querying available versions in Capgo between ${bundle} and ${nextMajor}`)
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
- p.log.info(`Active versions in Capgo between ${bundle} and ${nextMajor}: ${allVersions?.length}`)
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
- p.log.warn('Nothing to be removed, aborting removal...')
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 p.confirm({ message: 'Do you want to continue removing the versions specified?' })
112
- if (p.isCancel(doDelete) || !doDelete) {
113
- p.log.warn('Not confirmed, aborting removal...')
114
- process.exit()
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
- p.log.success('You have confirmed removal, removing versions now')
120
- await removeVersions(toRemove, supabase, appid)
121
- p.outro(`Done ✅`)
122
- process.exit()
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
- p.intro(`Check compatibility`)
14
+ intro(`Check compatibility`)
15
15
  options.apikey = options.apikey || findSavedKey()
16
- const config = await getConfig()
17
- appId = appId || config?.app?.appId
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
- p.log.error('Missing argument, you need to provide a channel')
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
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
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
- p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
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
- p.log.success(t.render())
69
+ log.success(t.render())
70
70
  }
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs'
2
- import process from 'node:process'
2
+ import { exit } from 'node:process'
3
3
  import { program } from 'commander'
4
- import * as p from '@clack/prompts'
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
- p.intro(`Decrypt zip file`)
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
- p.log.error(`Zip not found at the path ${zipPath}`)
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
- p.log.error(`Private Key not found at the path ${baseKey} or in ${config.app.extConfigFilePath}`)
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
- p.log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
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
- p.outro(`Decrypted zip file at ${zipPath}_decrypted.zip`)
53
- process.exit()
52
+ outro(`Decrypted zip file at ${zipPath}_decrypted.zip`)
53
+ exit()
54
54
  }
@@ -1,6 +1,6 @@
1
- import process from 'node:process'
1
+ import { exit } from 'node:process'
2
2
  import { program } from 'commander'
3
- import * as p from '@clack/prompts'
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
- p.intro(`Delete bundle`)
14
+ intro(`Delete bundle`)
15
15
  options.apikey = options.apikey || findSavedKey()
16
- const config = await getConfig()
17
- appId = appId || config?.app?.appId
16
+ const extConfig = await getConfig()
17
+ appId = appId || extConfig?.config?.appId
18
18
 
19
19
  if (!options.apikey) {
20
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
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
- p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
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
- p.log.error('Missing API key, you need to provide an API key to delete your app')
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
- p.log.error('Missing argument, you need to provide a bundleId, or be in a capacitor project')
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
- p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
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
- p.log.info(`Deleting bundle ${appId}@${bundleId} from Capgo`)
46
+ log.info(`Deleting bundle ${appId}@${bundleId} from Capgo`)
48
47
 
49
48
  await deleteSpecificVersion(supabase, appId, bundleId)
50
- p.log.success(`Bundle ${appId}@${bundleId} deleted in Capgo`)
51
- p.outro(`Done`)
52
- process.exit()
49
+ log.success(`Bundle ${appId}@${bundleId} deleted in Capgo`)
50
+ outro(`Done`)
51
+ exit()
53
52
  }
@@ -1,8 +1,8 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs'
2
- import process from 'node:process'
2
+ import { exit } from 'node:process'
3
3
  import { program } from 'commander'
4
4
  import ciDetect from 'ci-info'
5
- import * as p from '@clack/prompts'
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
- p.intro(`Encryption`)
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
- p.log.error(`Error: Zip not found at the path ${zipPath}`)
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
- p.log.warning(`Cannot find public key ${keyPath} or as keyData option`)
34
+ log.warning(`Cannot find public key ${keyPath} or as keyData option`)
35
35
  if (ciDetect.isCI) {
36
- p.log.error(`Error: Missing public key`)
36
+ log.error(`Error: Missing public key`)
37
37
  program.error('')
38
38
  }
39
- const res = await p.confirm({ message: 'Do you want to use our public key ?' })
39
+ const res = await confirm({ message: 'Do you want to use our public key ?' })
40
40
  if (!res) {
41
- p.log.error(`Error: Missing public key`)
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
- p.log.success(`ivSessionKey: ${encodedZip.ivSessionKey}`)
54
+ log.success(`ivSessionKey: ${encodedZiivSessionKey}`)
55
55
  // write decodedZip in a file
56
- writeFileSync(`${zipPath}_encrypted.zip`, encodedZip.encryptedData)
57
- p.log.success(`Encrypted zip saved at ${zipPath}_encrypted.zip`)
58
- p.outro(`Done ✅`)
59
- process.exit()
56
+ writeFileSync(`${zipPath}_encrypted.zip`, encodedZiencryptedData)
57
+ log.success(`Encrypted zip saved at ${zipPath}_encrypted.zip`)
58
+ outro(`Done ✅`)
59
+ exit()
60
60
  }
@@ -1,6 +1,6 @@
1
- import process from 'node:process'
1
+ import { exit } from 'node:process'
2
2
  import { program } from 'commander'
3
- import * as p from '@clack/prompts'
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
- p.intro(`List bundles`)
11
+ intro(`List bundles`)
12
12
  await checkLatest()
13
13
  options.apikey = options.apikey || findSavedKey()
14
- const config = await getConfig()
15
-
16
- appId = appId || config?.app?.appId
14
+ const extConfig = await getConfig()
15
+ appId = appId || extConfig?.config?.appId
17
16
  if (!options.apikey) {
18
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
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
- p.log.error('Missing argument, you need to provide a appid, or be in a capacitor project')
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
- p.log.info(`Querying available versions of: ${appId} in Capgo`)
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
- p.log.info(`Active versions in Capgo: ${allVersions?.length}`)
37
+ log.info(`Active versions in Capgo: ${allVersions?.length}`)
39
38
 
40
39
  displayBundles(allVersions)
41
- p.outro(`Done ✅`)
42
- process.exit()
40
+ outro(`Done ✅`)
41
+ exit()
43
42
  }
@@ -1,6 +1,6 @@
1
- import process from 'node:process'
1
+ import { exit } from 'node:process'
2
2
  import { program } from 'commander'
3
- import * as p from '@clack/prompts'
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
- p.intro(`Unlink bundle ${options.apikey}`)
29
+ intro(`Unlink bundle ${options.apikey}`)
29
30
  options.apikey = options.apikey || findSavedKey()
30
- const config = await getConfig()
31
- appId = appId || config?.app?.appId
31
+ const extConfig = await getConfig()
32
+ appId = appId || extConfig?.config?.appId
32
33
  const snag = useLogSnag()
33
34
  let { bundle } = options
34
35
 
35
- bundle = bundle || config?.app?.package?.version
36
+ const pack = await readPackageJson()
37
+ bundle = bundle || pack?.version
36
38
 
37
39
  if (!options.apikey) {
38
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
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
- p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
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
- p.log.error('Missing argument, you need to provide a bundle, or be in a capacitor project')
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
- p.log.error('Missing argument, you need to provide a channel')
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
- p.log.error(`Unknow error ${formatError(err)}`)
83
+ log.error(`Unknow error ${formatError(err)}`)
82
84
  program.error('')
83
85
  }
84
- p.outro('Done ✅')
85
- process.exit()
86
+ outro('Done ✅')
87
+ exit()
86
88
  }