@capgo/cli 4.0.12 → 4.0.14

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