@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/CHANGELOG.md +36 -0
- package/build.mjs +3 -5
- package/bun.lockb +0 -0
- package/dist/index.js +183 -92196
- package/package.json +20 -22
- 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 +12 -12
- package/src/bundle/list.ts +11 -12
- package/src/bundle/unlink.ts +15 -13
- package/src/bundle/upload.ts +65 -64
- 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/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/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 {
|
|
4
|
-
import
|
|
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,
|
|
18
|
-
if (
|
|
19
|
-
|
|
17
|
+
export async function saveKey(options: saveOptions, logg = true) {
|
|
18
|
+
if (logg)
|
|
19
|
+
intro(`Save keys 🔑`)
|
|
20
20
|
|
|
21
|
-
const
|
|
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 (
|
|
31
|
-
|
|
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
|
|
55
|
+
await writeConfig(extConfig)
|
|
57
56
|
}
|
|
58
57
|
if (log) {
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
+
intro(`Save keys 🔑`)
|
|
66
65
|
await checkLatest()
|
|
67
66
|
await saveKey(options)
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
export async function createKey(options: Options,
|
|
69
|
+
export async function createKey(options: Options, logg = true) {
|
|
71
70
|
// write in file .capgo the apikey in home directory
|
|
72
|
-
if (
|
|
73
|
-
|
|
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
|
-
|
|
80
|
-
if (
|
|
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
|
-
|
|
90
|
-
if (
|
|
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
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
111
|
+
const flattenPrivateKey = privateKey.replace(/\\n/g, '\\n')
|
|
112
|
+
extConfig.config.plugins.CapacitorUpdater.privateKey = flattenPrivateKey
|
|
114
113
|
// console.log('extConfig', extConfig)
|
|
115
|
-
writeConfig(extConfig
|
|
114
|
+
writeConfig(extConfig)
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
3
|
+
import { exit } from 'node:process'
|
|
4
4
|
import { program } from 'commander'
|
|
5
|
-
import
|
|
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
|
-
|
|
19
|
+
intro(`Login to Capgo`)
|
|
20
20
|
|
|
21
21
|
if (!apikey) {
|
|
22
22
|
if (shouldExit) {
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
+
log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
|
|
56
56
|
}
|
|
57
57
|
catch (e) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
log.error(`Error while saving login`)
|
|
59
|
+
exit(1)
|
|
60
60
|
}
|
|
61
61
|
if (shouldExit) {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
outro('Done ✅')
|
|
63
|
+
exit()
|
|
64
64
|
}
|
|
65
65
|
return true
|
|
66
66
|
}
|
package/src/user/account.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
10
|
+
outro(`Done ✅: ${userId}`)
|
|
11
11
|
}
|