@capgo/cli 4.2.3 → 5.0.0-alpha.3

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
@@ -21,14 +21,15 @@ export async function saveKey(options: saveOptions, log = true) {
21
21
  const config = await getConfig()
22
22
  const { extConfig } = config.app
23
23
 
24
- const keyPath = options.key || baseKey
24
+ // const keyPath = options.key || baseKey
25
+ const keyPath = options.key || baseKeyPub
25
26
  // check if publicKey exist
26
27
 
27
- let privateKey = options.keyData || ''
28
+ let publicKey = options.keyData || ''
28
29
 
29
- if (!existsSync(keyPath) && !privateKey) {
30
+ if (!existsSync(keyPath) && !publicKey) {
30
31
  if (log) {
31
- p.log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
32
+ p.log.error(`Cannot find a public key at ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
32
33
  program.error('')
33
34
  }
34
35
  else {
@@ -38,7 +39,20 @@ export async function saveKey(options: saveOptions, log = true) {
38
39
  else if (existsSync(keyPath)) {
39
40
  // open with fs publicKey path
40
41
  const keyFile = readFileSync(keyPath)
41
- privateKey = keyFile.toString()
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
+ }
42
56
  }
43
57
 
44
58
  if (extConfig) {
@@ -51,12 +65,16 @@ export async function saveKey(options: saveOptions, log = true) {
51
65
  if (!extConfig.plugins.CapacitorUpdater)
52
66
  extConfig.plugins.CapacitorUpdater = {}
53
67
 
54
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
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
+
55
73
  // console.log('extConfig', extConfig)
56
74
  writeConfig(extConfig, config.app.extConfigFilePath)
57
75
  }
58
76
  if (log) {
59
- p.log.success(`private key saved into ${config.app.extConfigFilePath} file in local directory`)
77
+ p.log.success(`public key saved into ${config.app.extConfigFilePath} file in local directory`)
60
78
  p.log.success(`your app will decode the zip archive with this key`)
61
79
  }
62
80
  return true
@@ -98,6 +116,7 @@ export async function createKey(options: Options, log = true) {
98
116
 
99
117
  const config = await getConfig()
100
118
  const { extConfig } = config.app
119
+
101
120
  if (extConfig) {
102
121
  if (!extConfig.plugins) {
103
122
  extConfig.plugins = {
@@ -105,21 +124,29 @@ export async function createKey(options: Options, log = true) {
105
124
  CapacitorUpdater: {},
106
125
  }
107
126
  }
108
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
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
+
109
136
  // console.log('extConfig', extConfig)
110
137
  writeConfig(extConfig, config.app.extConfigFilePath)
111
138
  }
112
139
 
113
140
  if (log) {
114
141
  p.log.success('Your RSA key has been generated')
115
- p.log.success(`Public key saved in ${baseKeyPub}`)
142
+ p.log.success(`Private key saved in ${baseKey}`)
116
143
  p.log.success('This key will be use to encrypt your bundle before sending it to Capgo')
117
144
  p.log.success('Keep it safe')
118
145
  p.log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
119
- p.log.success(`Private key saved in ${config.app.extConfigFilePath}`)
146
+ p.log.success(`Public key saved in ${config.app.extConfigFilePath}`)
120
147
  p.log.success('Your app will be the only one having it')
121
148
  p.log.success('Only your users can decrypt your update')
122
- p.log.success('Only you can send them an update')
149
+ p.log.success('Only your key can send them an update')
123
150
  p.outro(`Done ✅`)
124
151
  }
125
152
  return true
@@ -648,42 +648,54 @@ export interface Database {
648
648
  global_stats: {
649
649
  Row: {
650
650
  apps: number
651
+ apps_active: number | null
651
652
  created_at: string | null
652
653
  date_id: string
653
654
  need_upgrade: number | null
654
655
  not_paying: number | null
655
656
  onboarded: number | null
656
657
  paying: number | null
658
+ paying_monthly: number | null
659
+ paying_yearly: number | null
657
660
  stars: number
658
661
  trial: number | null
659
662
  updates: number
660
663
  users: number | null
664
+ users_active: number | null
661
665
  }
662
666
  Insert: {
663
667
  apps: number
668
+ apps_active?: number | null
664
669
  created_at?: string | null
665
670
  date_id: string
666
671
  need_upgrade?: number | null
667
672
  not_paying?: number | null
668
673
  onboarded?: number | null
669
674
  paying?: number | null
675
+ paying_monthly?: number | null
676
+ paying_yearly?: number | null
670
677
  stars: number
671
678
  trial?: number | null
672
679
  updates: number
673
680
  users?: number | null
681
+ users_active?: number | null
674
682
  }
675
683
  Update: {
676
684
  apps?: number
685
+ apps_active?: number | null
677
686
  created_at?: string | null
678
687
  date_id?: string
679
688
  need_upgrade?: number | null
680
689
  not_paying?: number | null
681
690
  onboarded?: number | null
682
691
  paying?: number | null
692
+ paying_monthly?: number | null
693
+ paying_yearly?: number | null
683
694
  stars?: number
684
695
  trial?: number | null
685
696
  updates?: number
686
697
  users?: number | null
698
+ users_active?: number | null
687
699
  }
688
700
  Relationships: []
689
701
  }
@@ -1257,6 +1269,12 @@ export interface Database {
1257
1269
  }
1258
1270
  Returns: number
1259
1271
  }
1272
+ count_active_users: {
1273
+ Args: {
1274
+ app_ids: string[]
1275
+ }
1276
+ Returns: number
1277
+ }
1260
1278
  count_all_apps: {
1261
1279
  Args: Record<PropertyKey, never>
1262
1280
  Returns: number
@@ -1382,6 +1400,14 @@ export interface Database {
1382
1400
  }
1383
1401
  Returns: string
1384
1402
  }
1403
+ get_customer_counts: {
1404
+ Args: Record<PropertyKey, never>
1405
+ Returns: {
1406
+ yearly: number
1407
+ monthly: number
1408
+ total: number
1409
+ }[]
1410
+ }
1385
1411
  get_cycle_info:
1386
1412
  | {
1387
1413
  Args: Record<PropertyKey, never>
@@ -1930,35 +1956,37 @@ export interface Database {
1930
1956
  }
1931
1957
  CompositeTypes: {
1932
1958
  match_plan: {
1933
- name: string
1959
+ name: string | null
1934
1960
  }
1935
1961
  orgs_table: {
1936
- id: string
1937
- created_by: string
1938
- created_at: string
1939
- updated_at: string
1940
- logo: string
1941
- name: string
1962
+ id: string | null
1963
+ created_by: string | null
1964
+ created_at: string | null
1965
+ updated_at: string | null
1966
+ logo: string | null
1967
+ name: string | null
1942
1968
  }
1943
1969
  owned_orgs: {
1944
- id: string
1945
- created_by: string
1946
- logo: string
1947
- name: string
1948
- role: string
1970
+ id: string | null
1971
+ created_by: string | null
1972
+ logo: string | null
1973
+ name: string | null
1974
+ role: string | null
1949
1975
  }
1950
1976
  stats_table: {
1951
- mau: number
1952
- bandwidth: number
1953
- storage: number
1977
+ mau: number | null
1978
+ bandwidth: number | null
1979
+ storage: number | null
1954
1980
  }
1955
1981
  }
1956
1982
  }
1957
1983
  }
1958
1984
 
1985
+ type PublicSchema = Database[Extract<keyof Database, 'public'>]
1986
+
1959
1987
  export type Tables<
1960
1988
  PublicTableNameOrOptions extends
1961
- | keyof (Database['public']['Tables'] & Database['public']['Views'])
1989
+ | keyof (PublicSchema['Tables'] & PublicSchema['Views'])
1962
1990
  | { schema: keyof Database },
1963
1991
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
1964
1992
  ? keyof (Database[PublicTableNameOrOptions['schema']]['Tables'] &
@@ -1971,10 +1999,10 @@ export type Tables<
1971
1999
  }
1972
2000
  ? R
1973
2001
  : never
1974
- : PublicTableNameOrOptions extends keyof (Database['public']['Tables'] &
1975
- Database['public']['Views'])
1976
- ? (Database['public']['Tables'] &
1977
- Database['public']['Views'])[PublicTableNameOrOptions] extends {
2002
+ : PublicTableNameOrOptions extends keyof (PublicSchema['Tables'] &
2003
+ PublicSchema['Views'])
2004
+ ? (PublicSchema['Tables'] &
2005
+ PublicSchema['Views'])[PublicTableNameOrOptions] extends {
1978
2006
  Row: infer R
1979
2007
  }
1980
2008
  ? R
@@ -1983,7 +2011,7 @@ export type Tables<
1983
2011
 
1984
2012
  export type TablesInsert<
1985
2013
  PublicTableNameOrOptions extends
1986
- | keyof Database['public']['Tables']
2014
+ | keyof PublicSchema['Tables']
1987
2015
  | { schema: keyof Database },
1988
2016
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
1989
2017
  ? keyof Database[PublicTableNameOrOptions['schema']]['Tables']
@@ -1994,8 +2022,8 @@ export type TablesInsert<
1994
2022
  }
1995
2023
  ? I
1996
2024
  : never
1997
- : PublicTableNameOrOptions extends keyof Database['public']['Tables']
1998
- ? Database['public']['Tables'][PublicTableNameOrOptions] extends {
2025
+ : PublicTableNameOrOptions extends keyof PublicSchema['Tables']
2026
+ ? PublicSchema['Tables'][PublicTableNameOrOptions] extends {
1999
2027
  Insert: infer I
2000
2028
  }
2001
2029
  ? I
@@ -2004,7 +2032,7 @@ export type TablesInsert<
2004
2032
 
2005
2033
  export type TablesUpdate<
2006
2034
  PublicTableNameOrOptions extends
2007
- | keyof Database['public']['Tables']
2035
+ | keyof PublicSchema['Tables']
2008
2036
  | { schema: keyof Database },
2009
2037
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
2010
2038
  ? keyof Database[PublicTableNameOrOptions['schema']]['Tables']
@@ -2015,8 +2043,8 @@ export type TablesUpdate<
2015
2043
  }
2016
2044
  ? U
2017
2045
  : never
2018
- : PublicTableNameOrOptions extends keyof Database['public']['Tables']
2019
- ? Database['public']['Tables'][PublicTableNameOrOptions] extends {
2046
+ : PublicTableNameOrOptions extends keyof PublicSchema['Tables']
2047
+ ? PublicSchema['Tables'][PublicTableNameOrOptions] extends {
2020
2048
  Update: infer U
2021
2049
  }
2022
2050
  ? U
@@ -2025,13 +2053,13 @@ export type TablesUpdate<
2025
2053
 
2026
2054
  export type Enums<
2027
2055
  PublicEnumNameOrOptions extends
2028
- | keyof Database['public']['Enums']
2056
+ | keyof PublicSchema['Enums']
2029
2057
  | { schema: keyof Database },
2030
2058
  EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
2031
2059
  ? keyof Database[PublicEnumNameOrOptions['schema']]['Enums']
2032
2060
  : never = never,
2033
2061
  > = PublicEnumNameOrOptions extends { schema: keyof Database }
2034
2062
  ? Database[PublicEnumNameOrOptions['schema']]['Enums'][EnumName]
2035
- : PublicEnumNameOrOptions extends keyof Database['public']['Enums']
2036
- ? Database['public']['Enums'][PublicEnumNameOrOptions]
2063
+ : PublicEnumNameOrOptions extends keyof PublicSchema['Enums']
2064
+ ? PublicSchema['Enums'][PublicEnumNameOrOptions]
2037
2065
  : never
package/src/utils.ts CHANGED
@@ -378,7 +378,6 @@ interface Config {
378
378
  resetWhenUpdate?: boolean
379
379
  updateUrl?: string
380
380
  statsUrl?: string
381
- privateKey?: string
382
381
  version?: string
383
382
  directUpdate?: boolean
384
383
  periodCheckDelay?: number
@@ -389,6 +388,9 @@ interface Config {
389
388
  localSupaAnon?: string
390
389
  allowModifyUrl?: boolean
391
390
  defaultChannel?: string
391
+ channelUrl?: string
392
+ publicKey?: string
393
+ privateKey?: string
392
394
  }
393
395
  }
394
396
  server: {
@@ -399,6 +401,25 @@ interface Config {
399
401
  }
400
402
  }
401
403
 
404
+ export async function checKOldEncryption() {
405
+ const config = await getConfig()
406
+ const { extConfig } = config.app
407
+ // console.log('localConfig - ', localConfig)
408
+ // console.log('config - ', config)
409
+
410
+ const hasPrivateKeyInConfig = !!extConfig?.plugins?.CapacitorUpdater?.privateKey
411
+ const hasPublicKeyInConfig = !!extConfig?.plugins?.CapacitorUpdater?.publicKey
412
+
413
+ if (hasPrivateKeyInConfig)
414
+ p.log.warning(`You still have privateKey in the capacitor config, this is deprecated, please remove it`)
415
+ p.log.warning(`Encryption with private will be ignored`)
416
+
417
+ if (!hasPublicKeyInConfig) {
418
+ p.log.warning(`publicKey not found in capacitor config, please run npx @capgo/cli key save`)
419
+ program.error('')
420
+ }
421
+ }
422
+
402
423
  export async function updateOrCreateVersion(supabase: SupabaseClient<Database>, update: Database['public']['Tables']['app_versions']['Insert']) {
403
424
  return supabase.from('app_versions')
404
425
  .upsert(update, { onConflict: 'name,app_id' })