@capgo/cli 4.13.7 → 4.13.9
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/FUNDING.yml +1 -0
- package/.github/workflows/build.yml +46 -0
- package/.github/workflows/bump_version.yml +56 -0
- package/.github/workflows/test.yml +30 -0
- package/.prettierignore +6 -0
- package/.vscode/launch.json +23 -0
- package/.vscode/settings.json +46 -0
- package/.vscode/tasks.json +42 -0
- package/CHANGELOG.md +2739 -0
- package/build.mjs +23 -0
- package/bun.lockb +0 -0
- package/capacitor.config.ts +33 -0
- package/crypto_explained.png +0 -0
- package/dist/index.js +114692 -205
- package/eslint.config.js +10 -0
- package/package.json +33 -32
- package/renovate.json +23 -0
- package/src/api/app.ts +55 -0
- package/src/api/channels.ts +140 -0
- package/src/api/crypto.ts +116 -0
- package/src/api/devices_override.ts +41 -0
- package/src/api/update.ts +13 -0
- package/src/api/versions.ts +101 -0
- package/src/app/add.ts +158 -0
- package/src/app/debug.ts +222 -0
- package/src/app/delete.ts +106 -0
- package/src/app/info.ts +90 -0
- package/src/app/list.ts +67 -0
- package/src/app/set.ts +94 -0
- package/src/bundle/check.ts +42 -0
- package/src/bundle/cleanup.ts +127 -0
- package/src/bundle/compatibility.ts +70 -0
- package/src/bundle/decrypt.ts +54 -0
- package/src/bundle/delete.ts +53 -0
- package/src/bundle/encrypt.ts +60 -0
- package/src/bundle/list.ts +43 -0
- package/src/bundle/unlink.ts +86 -0
- package/src/bundle/upload.ts +532 -0
- package/src/bundle/zip.ts +139 -0
- package/src/channel/add.ts +74 -0
- package/src/channel/currentBundle.ts +72 -0
- package/src/channel/delete.ts +52 -0
- package/src/channel/list.ts +49 -0
- package/src/channel/set.ts +178 -0
- package/src/index.ts +307 -0
- package/src/init.ts +342 -0
- package/src/key.ts +131 -0
- package/src/login.ts +70 -0
- package/src/types/capacitor__cli.d.ts +6 -0
- package/src/types/supabase.types.ts +2193 -0
- package/src/user/account.ts +11 -0
- package/src/utils.ts +956 -0
- package/test/chunk_convert.ts +28 -0
- package/test/data.ts +18769 -0
- package/test/test_headers_rls.ts +24 -0
- package/test/test_semver.ts +13 -0
- package/tsconfig.json +39 -0
package/src/key.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { program } from 'commander'
|
|
3
|
+
import { writeConfig } from '@capacitor/cli/dist/config'
|
|
4
|
+
import * as p from '@clack/prompts'
|
|
5
|
+
import { createRSA } from './api/crypto'
|
|
6
|
+
import { baseKey, baseKeyPub, getConfig } from './utils'
|
|
7
|
+
import { checkLatest } from './api/update'
|
|
8
|
+
|
|
9
|
+
interface saveOptions {
|
|
10
|
+
key?: string
|
|
11
|
+
keyData?: string
|
|
12
|
+
}
|
|
13
|
+
interface Options {
|
|
14
|
+
force?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function saveKey(options: saveOptions, log = true) {
|
|
18
|
+
if (log)
|
|
19
|
+
p.intro(`Save keys 🔑`)
|
|
20
|
+
|
|
21
|
+
const config = await getConfig()
|
|
22
|
+
const { extConfig } = config.app
|
|
23
|
+
|
|
24
|
+
const keyPath = options.key || baseKey
|
|
25
|
+
// check if publicKey exist
|
|
26
|
+
|
|
27
|
+
let privateKey = options.keyData || ''
|
|
28
|
+
|
|
29
|
+
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}`)
|
|
32
|
+
program.error('')
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (existsSync(keyPath)) {
|
|
39
|
+
// open with fs publicKey path
|
|
40
|
+
const keyFile = readFileSync(keyPath)
|
|
41
|
+
privateKey = keyFile.toString()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (extConfig) {
|
|
45
|
+
if (!extConfig.plugins) {
|
|
46
|
+
extConfig.plugins = {
|
|
47
|
+
extConfig: {},
|
|
48
|
+
CapacitorUpdater: {},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!extConfig.plugins.CapacitorUpdater)
|
|
52
|
+
extConfig.plugins.CapacitorUpdater = {}
|
|
53
|
+
|
|
54
|
+
extConfig.plugins.CapacitorUpdater.privateKey = privateKey
|
|
55
|
+
// console.log('extConfig', extConfig)
|
|
56
|
+
writeConfig(extConfig, config.app.extConfigFilePath)
|
|
57
|
+
}
|
|
58
|
+
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`)
|
|
61
|
+
}
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
export async function saveKeyCommand(options: saveOptions) {
|
|
65
|
+
p.intro(`Save keys 🔑`)
|
|
66
|
+
await checkLatest()
|
|
67
|
+
await saveKey(options)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function createKey(options: Options, log = true) {
|
|
71
|
+
// write in file .capgo the apikey in home directory
|
|
72
|
+
if (log)
|
|
73
|
+
p.intro(`Create keys 🔑`)
|
|
74
|
+
|
|
75
|
+
const { publicKey, privateKey } = createRSA()
|
|
76
|
+
|
|
77
|
+
// check if baseName already exist
|
|
78
|
+
if (existsSync(baseKeyPub) && !options.force) {
|
|
79
|
+
if (log) {
|
|
80
|
+
p.log.error('Public Key already exists, use --force to overwrite')
|
|
81
|
+
program.error('')
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
writeFileSync(baseKeyPub, publicKey)
|
|
88
|
+
if (existsSync(baseKey) && !options.force) {
|
|
89
|
+
if (log) {
|
|
90
|
+
p.log.error('Private Key already exists, use --force to overwrite')
|
|
91
|
+
program.error('')
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
writeFileSync(baseKey, privateKey)
|
|
98
|
+
|
|
99
|
+
const config = await getConfig()
|
|
100
|
+
const { extConfig } = config.app
|
|
101
|
+
if (extConfig) {
|
|
102
|
+
if (!extConfig.plugins) {
|
|
103
|
+
extConfig.plugins = {
|
|
104
|
+
extConfig: {},
|
|
105
|
+
CapacitorUpdater: {},
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
extConfig.plugins.CapacitorUpdater.privateKey = privateKey
|
|
109
|
+
// console.log('extConfig', extConfig)
|
|
110
|
+
writeConfig(extConfig, config.app.extConfigFilePath)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (log) {
|
|
114
|
+
p.log.success('Your RSA key has been generated')
|
|
115
|
+
p.log.success(`Public key saved in ${baseKeyPub}`)
|
|
116
|
+
p.log.success('This key will be use to encrypt your bundle before sending it to Capgo')
|
|
117
|
+
p.log.success('Keep it safe')
|
|
118
|
+
p.log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
|
|
119
|
+
p.log.success(`Private key saved in ${config.app.extConfigFilePath}`)
|
|
120
|
+
p.log.success('Your app will be the only one having it')
|
|
121
|
+
p.log.success('Only your users can decrypt your update')
|
|
122
|
+
p.log.success('Only you can send them an update')
|
|
123
|
+
p.outro(`Done ✅`)
|
|
124
|
+
}
|
|
125
|
+
return true
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function createKeyCommand(options: Options) {
|
|
129
|
+
await checkLatest()
|
|
130
|
+
await createKey(options)
|
|
131
|
+
}
|
package/src/login.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
import { program } from 'commander'
|
|
5
|
+
import * as p from '@clack/prompts'
|
|
6
|
+
import { createSupabaseClient, useLogSnag, verifyUser } from './utils'
|
|
7
|
+
import { checkLatest } from './api/update'
|
|
8
|
+
|
|
9
|
+
interface Options {
|
|
10
|
+
local: boolean
|
|
11
|
+
}
|
|
12
|
+
export async function doLoginExists() {
|
|
13
|
+
const userHomeDir = homedir()
|
|
14
|
+
return existsSync(`${userHomeDir}/.capgo`) || existsSync('.capgo')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function login(apikey: string, options: Options, shouldExit = true) {
|
|
18
|
+
if (shouldExit)
|
|
19
|
+
p.intro(`Login to Capgo`)
|
|
20
|
+
|
|
21
|
+
if (!apikey) {
|
|
22
|
+
if (shouldExit) {
|
|
23
|
+
p.log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
24
|
+
program.error('')
|
|
25
|
+
}
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
await checkLatest()
|
|
29
|
+
// write in file .capgo the apikey in home directory
|
|
30
|
+
try {
|
|
31
|
+
const { local } = options
|
|
32
|
+
const snag = useLogSnag()
|
|
33
|
+
|
|
34
|
+
if (local) {
|
|
35
|
+
if (!existsSync('.git')) {
|
|
36
|
+
p.log.error('To use local you should be in a git repository')
|
|
37
|
+
program.error('')
|
|
38
|
+
}
|
|
39
|
+
writeFileSync('.capgo', `${apikey}\n`)
|
|
40
|
+
appendFileSync('.gitignore', '.capgo\n')
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const userHomeDir = homedir()
|
|
44
|
+
writeFileSync(`${userHomeDir}/.capgo`, `${apikey}\n`)
|
|
45
|
+
}
|
|
46
|
+
const supabase = await createSupabaseClient(apikey)
|
|
47
|
+
const userId = await verifyUser(supabase, apikey, ['write', 'all', 'upload'])
|
|
48
|
+
await snag.track({
|
|
49
|
+
channel: 'user-login',
|
|
50
|
+
event: 'User CLI login',
|
|
51
|
+
icon: '✅',
|
|
52
|
+
user_id: userId,
|
|
53
|
+
notify: false,
|
|
54
|
+
}).catch()
|
|
55
|
+
p.log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
p.log.error(`Error while saving login`)
|
|
59
|
+
process.exit(1)
|
|
60
|
+
}
|
|
61
|
+
if (shouldExit) {
|
|
62
|
+
p.outro('Done ✅')
|
|
63
|
+
process.exit()
|
|
64
|
+
}
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function loginCommand(apikey: string, options: Options) {
|
|
69
|
+
login(apikey, options, true)
|
|
70
|
+
}
|