@capgo/cli 4.12.14 → 4.13.2

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/src/key.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs'
2
2
  import { program } from 'commander'
3
- import { writeConfig } from '@capacitor/cli/dist/config'
4
- import * as p from '@clack/prompts'
3
+ import { intro, log, outro } from '@clack/prompts'
4
+ import { writeConfig } from './config'
5
5
  import { createRSA } from './api/crypto'
6
6
  import { baseKey, baseKeyPub, getConfig } from './utils'
7
7
  import { checkLatest } from './api/update'
@@ -14,12 +14,11 @@ interface Options {
14
14
  force?: boolean
15
15
  }
16
16
 
17
- export async function saveKey(options: saveOptions, log = true) {
18
- if (log)
19
- p.intro(`Save keys 🔑`)
17
+ export async function saveKey(options: saveOptions, logg = true) {
18
+ if (logg)
19
+ intro(`Save keys 🔑`)
20
20
 
21
- const config = await getConfig()
22
- const { extConfig } = config.app
21
+ const extConfig = await getConfig()
23
22
 
24
23
  const keyPath = options.key || baseKey
25
24
  // check if publicKey exist
@@ -27,8 +26,8 @@ export async function saveKey(options: saveOptions, log = true) {
27
26
  let privateKey = options.keyData || ''
28
27
 
29
28
  if (!existsSync(keyPath) && !privateKey) {
30
- if (log) {
31
- p.log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
29
+ if (logg) {
30
+ log.error(`Cannot find public key ${keyPath} or as keyData option or in ${extConfig.path}`)
32
31
  program.error('')
33
32
  }
34
33
  else {
@@ -41,43 +40,43 @@ export async function saveKey(options: saveOptions, log = true) {
41
40
  privateKey = keyFile.toString()
42
41
  }
43
42
 
44
- if (extConfig) {
45
- if (!extConfig.plugins) {
46
- extConfig.plugins = {
43
+ if (extConfig?.config) {
44
+ if (!extConfig.config.plugins) {
45
+ extConfig.config.plugins = {
47
46
  extConfig: {},
48
47
  CapacitorUpdater: {},
49
48
  }
50
49
  }
51
- if (!extConfig.plugins.CapacitorUpdater)
52
- extConfig.plugins.CapacitorUpdater = {}
50
+ if (!extConfig.config.plugins.CapacitorUpdater)
51
+ extConfig.config.plugins.CapacitorUpdater = {}
53
52
 
54
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
53
+ extConfig.config.plugins.CapacitorUpdater.privateKey = privateKey
55
54
  // console.log('extConfig', extConfig)
56
- writeConfig(extConfig, config.app.extConfigFilePath)
55
+ await writeConfig(extConfig)
57
56
  }
58
57
  if (log) {
59
- p.log.success(`private key saved into ${config.app.extConfigFilePath} file in local directory`)
60
- p.log.success(`your app will decode the zip archive with this key`)
58
+ log.success(`private key saved into ${extConfig.path} file in local directory`)
59
+ log.success(`your app will decode the zip archive with this key`)
61
60
  }
62
61
  return true
63
62
  }
64
63
  export async function saveKeyCommand(options: saveOptions) {
65
- p.intro(`Save keys 🔑`)
64
+ intro(`Save keys 🔑`)
66
65
  await checkLatest()
67
66
  await saveKey(options)
68
67
  }
69
68
 
70
- export async function createKey(options: Options, log = true) {
69
+ export async function createKey(options: Options, logg = true) {
71
70
  // write in file .capgo the apikey in home directory
72
- if (log)
73
- p.intro(`Create keys 🔑`)
71
+ if (logg)
72
+ intro(`Create keys 🔑`)
74
73
 
75
74
  const { publicKey, privateKey } = createRSA()
76
75
 
77
76
  // check if baseName already exist
78
77
  if (existsSync(baseKeyPub) && !options.force) {
79
- p.log.error('Public Key already exists, use --force to overwrite')
80
- if (log) {
78
+ log.error('Public Key already exists, use --force to overwrite')
79
+ if (logg) {
81
80
  program.error('')
82
81
  }
83
82
  else {
@@ -86,8 +85,8 @@ export async function createKey(options: Options, log = true) {
86
85
  }
87
86
  writeFileSync(baseKeyPub, publicKey)
88
87
  if (existsSync(baseKey) && !options.force) {
89
- p.log.error('Private Key already exists, use --force to overwrite')
90
- if (log) {
88
+ log.error('Private Key already exists, use --force to overwrite')
89
+ if (logg) {
91
90
  program.error('')
92
91
  }
93
92
  else {
@@ -96,36 +95,36 @@ export async function createKey(options: Options, log = true) {
96
95
  }
97
96
  writeFileSync(baseKey, privateKey)
98
97
 
99
- const config = await getConfig()
100
- const { extConfig } = config.app
101
- if (extConfig) {
102
- if (!extConfig.plugins) {
103
- extConfig.plugins = {
98
+ const extConfig = await getConfig()
99
+ if (extConfig?.config) {
100
+ if (!extConfig.config.plugins) {
101
+ extConfig.config.plugins = {
104
102
  extConfig: {},
105
103
  CapacitorUpdater: {},
106
104
  }
107
105
  }
108
106
 
109
- if (!extConfig.plugins.CapacitorUpdater) {
110
- extConfig.plugins.CapacitorUpdater = {}
107
+ if (!extConfig.config.plugins.CapacitorUpdater) {
108
+ extConfig.config.plugins.CapacitorUpdater = {}
111
109
  }
112
110
 
113
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
111
+ const flattenPrivateKey = privateKey.replace(/\\n/g, '\\n')
112
+ extConfig.config.plugins.CapacitorUpdater.privateKey = flattenPrivateKey
114
113
  // console.log('extConfig', extConfig)
115
- writeConfig(extConfig, config.app.extConfigFilePath)
114
+ writeConfig(extConfig)
116
115
  }
117
116
 
118
- if (log) {
119
- p.log.success('Your RSA key has been generated')
120
- p.log.success(`Public key saved in ${baseKeyPub}`)
121
- p.log.success('This key will be use to encrypt your bundle before sending it to Capgo')
122
- p.log.success('Keep it safe')
123
- p.log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
124
- p.log.success(`Private key saved in ${config.app.extConfigFilePath}`)
125
- p.log.success('Your app will be the only one having it')
126
- p.log.success('Only your users can decrypt your update')
127
- p.log.success('Only you can send them an update')
128
- p.outro(`Done ✅`)
117
+ if (logg) {
118
+ log.success('Your RSA key has been generated')
119
+ log.success(`Public key saved in ${baseKeyPub}`)
120
+ log.success('This key will be use to encrypt your bundle before sending it to Capgo')
121
+ log.success('Keep it safe')
122
+ log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
123
+ log.success(`Private key saved in ${extConfig.path}`)
124
+ log.success('Your app will be the only one having it')
125
+ log.success('Only your users can decrypt your update')
126
+ log.success('Only you can send them an update')
127
+ outro(`Done ✅`)
129
128
  }
130
129
  return true
131
130
  }
package/src/login.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { appendFileSync, existsSync, writeFileSync } from 'node:fs'
2
2
  import { homedir } from 'node:os'
3
- import process from 'node:process'
3
+ import { exit } from 'node:process'
4
4
  import { program } from 'commander'
5
- import * as p from '@clack/prompts'
5
+ import { intro, log, outro } from '@clack/prompts'
6
6
  import { createSupabaseClient, useLogSnag, verifyUser } from './utils'
7
7
  import { checkLatest } from './api/update'
8
8
 
@@ -16,11 +16,11 @@ export async function doLoginExists() {
16
16
 
17
17
  export async function login(apikey: string, options: Options, shouldExit = true) {
18
18
  if (shouldExit)
19
- p.intro(`Login to Capgo`)
19
+ intro(`Login to Capgo`)
20
20
 
21
21
  if (!apikey) {
22
22
  if (shouldExit) {
23
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
23
+ log.error('Missing API key, you need to provide a API key to upload your bundle')
24
24
  program.error('')
25
25
  }
26
26
  return false
@@ -33,7 +33,7 @@ export async function login(apikey: string, options: Options, shouldExit = true)
33
33
 
34
34
  if (local) {
35
35
  if (!existsSync('.git')) {
36
- p.log.error('To use local you should be in a git repository')
36
+ log.error('To use local you should be in a git repository')
37
37
  program.error('')
38
38
  }
39
39
  writeFileSync('.capgo', `${apikey}\n`)
@@ -52,15 +52,15 @@ export async function login(apikey: string, options: Options, shouldExit = true)
52
52
  user_id: userId,
53
53
  notify: false,
54
54
  }).catch()
55
- p.log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
55
+ log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
56
56
  }
57
57
  catch (e) {
58
- p.log.error(`Error while saving login`)
59
- process.exit(1)
58
+ log.error(`Error while saving login`)
59
+ exit(1)
60
60
  }
61
61
  if (shouldExit) {
62
- p.outro('Done ✅')
63
- process.exit()
62
+ outro('Done ✅')
63
+ exit()
64
64
  }
65
65
  return true
66
66
  }
@@ -1,11 +1,11 @@
1
- import * as p from '@clack/prompts'
1
+ import { intro, outro } from '@clack/prompts'
2
2
  import { createSupabaseClient, findSavedKey, verifyUser } from '../utils'
3
3
  import type { Options } from '../api/app'
4
4
 
5
5
  export async function getUserId(options: Options) {
6
- p.intro(`Getting user id`)
6
+ intro(`Getting user id`)
7
7
  options.apikey = options.apikey || findSavedKey()
8
8
  const supabase = await createSupabaseClient(options.apikey)
9
9
  const userId = await verifyUser(supabase, options.apikey, ['read'])
10
- p.outro(`Done ✅: ${userId}`)
10
+ outro(`Done ✅: ${userId}`)
11
11
  }