@capgo/cli 5.0.0-alpha.7 → 7.0.1
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/README.md +197 -41
- package/dist/index.js +335 -95820
- package/dist/package.json +83 -0
- package/package.json +48 -62
- package/.eslintignore +0 -4
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/build.yml +0 -46
- package/.github/workflows/bump_version.yml +0 -56
- package/.github/workflows/test.yml +0 -30
- package/.prettierignore +0 -6
- package/.vscode/launch.json +0 -23
- package/.vscode/settings.json +0 -5
- package/.vscode/tasks.json +0 -42
- package/CHANGELOG.md +0 -2861
- package/build.mjs +0 -23
- package/bun.lockb +0 -0
- package/capacitor.config.ts +0 -33
- package/crypto_explained.png +0 -0
- package/eslint.config.js +0 -3
- package/renovate.json +0 -23
- package/src/api/app.ts +0 -75
- package/src/api/channels.ts +0 -140
- package/src/api/crypto.ts +0 -121
- package/src/api/devices_override.ts +0 -41
- package/src/api/update.ts +0 -12
- package/src/api/versions.ts +0 -101
- package/src/app/add.ts +0 -191
- package/src/app/debug.ts +0 -220
- package/src/app/delete.ts +0 -106
- package/src/app/info.ts +0 -87
- package/src/app/list.ts +0 -67
- package/src/app/set.ts +0 -94
- package/src/bundle/check.ts +0 -42
- package/src/bundle/cleanup.ts +0 -127
- package/src/bundle/compatibility.ts +0 -70
- package/src/bundle/decrypt.ts +0 -65
- package/src/bundle/delete.ts +0 -53
- package/src/bundle/encrypt.ts +0 -69
- package/src/bundle/list.ts +0 -43
- package/src/bundle/unlink.ts +0 -86
- package/src/bundle/upload.ts +0 -516
- package/src/bundle/zip.ts +0 -139
- package/src/channel/add.ts +0 -73
- package/src/channel/currentBundle.ts +0 -72
- package/src/channel/delete.ts +0 -51
- package/src/channel/list.ts +0 -49
- package/src/channel/set.ts +0 -174
- package/src/index.ts +0 -290
- package/src/init.ts +0 -301
- package/src/key.ts +0 -158
- package/src/login.ts +0 -66
- package/src/types/capacitor__cli.d.ts +0 -6
- package/src/types/supabase.types.ts +0 -2471
- package/src/utils.ts +0 -738
- package/test/chunk_convert.ts +0 -28
- package/test/data.ts +0 -18769
- package/test/test_headers_rls.ts +0 -24
- package/test/test_semver.ts +0 -13
- package/tsconfig.json +0 -39
package/src/key.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
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
|
-
const keyPath = options.key || baseKeyPub
|
|
26
|
-
// check if publicKey exist
|
|
27
|
-
|
|
28
|
-
let publicKey = options.keyData || ''
|
|
29
|
-
|
|
30
|
-
if (!existsSync(keyPath) && !publicKey) {
|
|
31
|
-
if (log) {
|
|
32
|
-
p.log.error(`Cannot find a public key at ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
|
|
33
|
-
program.error('')
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (existsSync(keyPath)) {
|
|
40
|
-
// open with fs publicKey path
|
|
41
|
-
const keyFile = readFileSync(keyPath)
|
|
42
|
-
publicKey = keyFile.toString()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// let's doublecheck and make sure the key we are saving is the right type based on the decryption strategy
|
|
46
|
-
if (publicKey) {
|
|
47
|
-
if (!publicKey.startsWith('-----BEGIN RSA PUBLIC KEY-----')) {
|
|
48
|
-
if (log) {
|
|
49
|
-
p.log.error(`the public key provided is not a valid RSA Public key`)
|
|
50
|
-
program.error('')
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return false
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (extConfig) {
|
|
59
|
-
if (!extConfig.plugins) {
|
|
60
|
-
extConfig.plugins = {
|
|
61
|
-
extConfig: {},
|
|
62
|
-
CapacitorUpdater: {},
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (!extConfig.plugins.CapacitorUpdater)
|
|
66
|
-
extConfig.plugins.CapacitorUpdater = {}
|
|
67
|
-
|
|
68
|
-
// TODO: this might be a breaking change if user has other code looking at the specific value in the config file
|
|
69
|
-
if (extConfig.plugins.CapacitorUpdater.privateKey)
|
|
70
|
-
delete extConfig.plugins.CapacitorUpdater.privateKey
|
|
71
|
-
extConfig.plugins.CapacitorUpdater.publicKey = publicKey
|
|
72
|
-
|
|
73
|
-
// console.log('extConfig', extConfig)
|
|
74
|
-
writeConfig(extConfig, config.app.extConfigFilePath)
|
|
75
|
-
}
|
|
76
|
-
if (log) {
|
|
77
|
-
p.log.success(`public key saved into ${config.app.extConfigFilePath} file in local directory`)
|
|
78
|
-
p.log.success(`your app will decode the zip archive with this key`)
|
|
79
|
-
}
|
|
80
|
-
return true
|
|
81
|
-
}
|
|
82
|
-
export async function saveKeyCommand(options: saveOptions) {
|
|
83
|
-
p.intro(`Save keys 🔑`)
|
|
84
|
-
await checkLatest()
|
|
85
|
-
await saveKey(options)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function createKey(options: Options, log = true) {
|
|
89
|
-
// write in file .capgo the apikey in home directory
|
|
90
|
-
if (log)
|
|
91
|
-
p.intro(`Create keys 🔑`)
|
|
92
|
-
|
|
93
|
-
const { publicKey, privateKey } = createRSA()
|
|
94
|
-
|
|
95
|
-
// check if baseName already exist
|
|
96
|
-
if (existsSync(baseKeyPub) && !options.force) {
|
|
97
|
-
if (log) {
|
|
98
|
-
p.log.error('Public Key already exists, use --force to overwrite')
|
|
99
|
-
program.error('')
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
return false
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
writeFileSync(baseKeyPub, publicKey)
|
|
106
|
-
if (existsSync(baseKey) && !options.force) {
|
|
107
|
-
if (log) {
|
|
108
|
-
p.log.error('Private Key already exists, use --force to overwrite')
|
|
109
|
-
program.error('')
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
return false
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
writeFileSync(baseKey, privateKey)
|
|
116
|
-
|
|
117
|
-
const config = await getConfig()
|
|
118
|
-
const { extConfig } = config.app
|
|
119
|
-
|
|
120
|
-
if (extConfig) {
|
|
121
|
-
if (!extConfig.plugins) {
|
|
122
|
-
extConfig.plugins = {
|
|
123
|
-
extConfig: {},
|
|
124
|
-
CapacitorUpdater: {},
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!extConfig.plugins.CapacitorUpdater)
|
|
129
|
-
extConfig.plugins.CapacitorUpdater = {}
|
|
130
|
-
|
|
131
|
-
// TODO: this might be a breaking change if user has other code looking at the specific value in the config file
|
|
132
|
-
if (extConfig.plugins.CapacitorUpdater.privateKey)
|
|
133
|
-
delete extConfig.plugins.CapacitorUpdater.privateKey
|
|
134
|
-
extConfig.plugins.CapacitorUpdater.publicKey = publicKey
|
|
135
|
-
|
|
136
|
-
// console.log('extConfig', extConfig)
|
|
137
|
-
writeConfig(extConfig, config.app.extConfigFilePath)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (log) {
|
|
141
|
-
p.log.success('Your RSA key has been generated')
|
|
142
|
-
p.log.success(`Private key saved in ${baseKey}`)
|
|
143
|
-
p.log.success('This key will be use to encrypt your bundle before sending it to Capgo')
|
|
144
|
-
p.log.success('Keep it safe')
|
|
145
|
-
p.log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
|
|
146
|
-
p.log.success(`Public key saved in ${config.app.extConfigFilePath}`)
|
|
147
|
-
p.log.success('Your app will be the only one having it')
|
|
148
|
-
p.log.success('Only your users can decrypt your update')
|
|
149
|
-
p.log.success('Only your key can send them an update')
|
|
150
|
-
p.outro(`Done ✅`)
|
|
151
|
-
}
|
|
152
|
-
return true
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export async function createKeyCommand(options: Options) {
|
|
156
|
-
await checkLatest()
|
|
157
|
-
await createKey(options)
|
|
158
|
-
}
|
package/src/login.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
|
|
13
|
-
export async function login(apikey: string, options: Options, shouldExit = true) {
|
|
14
|
-
if (shouldExit)
|
|
15
|
-
p.intro(`Login to Capgo`)
|
|
16
|
-
|
|
17
|
-
if (!apikey) {
|
|
18
|
-
if (shouldExit) {
|
|
19
|
-
p.log.error('Missing API key, you need to provide a API key to upload your bundle')
|
|
20
|
-
program.error('')
|
|
21
|
-
}
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
24
|
-
await checkLatest()
|
|
25
|
-
// write in file .capgo the apikey in home directory
|
|
26
|
-
try {
|
|
27
|
-
const { local } = options
|
|
28
|
-
const snag = useLogSnag()
|
|
29
|
-
|
|
30
|
-
if (local) {
|
|
31
|
-
if (!existsSync('.git')) {
|
|
32
|
-
p.log.error('To use local you should be in a git repository')
|
|
33
|
-
program.error('')
|
|
34
|
-
}
|
|
35
|
-
writeFileSync('.capgo', `${apikey}\n`)
|
|
36
|
-
appendFileSync('.gitignore', '.capgo\n')
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const userHomeDir = homedir()
|
|
40
|
-
writeFileSync(`${userHomeDir}/.capgo`, `${apikey}\n`)
|
|
41
|
-
}
|
|
42
|
-
const supabase = await createSupabaseClient(apikey)
|
|
43
|
-
const userId = await verifyUser(supabase, apikey, ['write', 'all', 'upload'])
|
|
44
|
-
await snag.track({
|
|
45
|
-
channel: 'user-login',
|
|
46
|
-
event: 'User CLI login',
|
|
47
|
-
icon: '✅',
|
|
48
|
-
user_id: userId,
|
|
49
|
-
notify: false,
|
|
50
|
-
}).catch()
|
|
51
|
-
p.log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
p.log.error(`Error while saving login`)
|
|
55
|
-
process.exit(1)
|
|
56
|
-
}
|
|
57
|
-
if (shouldExit) {
|
|
58
|
-
p.outro('Done ✅')
|
|
59
|
-
process.exit()
|
|
60
|
-
}
|
|
61
|
-
return true
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function loginCommand(apikey: string, options: Options) {
|
|
65
|
-
login(apikey, options, true)
|
|
66
|
-
}
|