@capgo/cli 3.14.21 → 3.14.23

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.
@@ -139,35 +139,41 @@ export interface Database {
139
139
  Row: {
140
140
  app_id: string
141
141
  bandwidth: number
142
- created_at: string | null
143
- downloads: number
142
+ date: string | null
144
143
  fails: number
144
+ get: number
145
145
  id: string
146
+ install: number
146
147
  mau: number
147
- mode: Database["public"]["Enums"]["usage_mode"]
148
- storage: number
148
+ storage_added: number
149
+ storage_deleted: number
150
+ uninstall: number
149
151
  }
150
152
  Insert: {
151
153
  app_id: string
152
154
  bandwidth?: number
153
- created_at?: string | null
154
- downloads?: number
155
+ date?: string | null
155
156
  fails?: number
157
+ get?: number
156
158
  id?: string
159
+ install?: number
157
160
  mau?: number
158
- mode?: Database["public"]["Enums"]["usage_mode"]
159
- storage?: number
161
+ storage_added?: number
162
+ storage_deleted?: number
163
+ uninstall?: number
160
164
  }
161
165
  Update: {
162
166
  app_id?: string
163
167
  bandwidth?: number
164
- created_at?: string | null
165
- downloads?: number
168
+ date?: string | null
166
169
  fails?: number
170
+ get?: number
167
171
  id?: string
172
+ install?: number
168
173
  mau?: number
169
- mode?: Database["public"]["Enums"]["usage_mode"]
170
- storage?: number
174
+ storage_added?: number
175
+ storage_deleted?: number
176
+ uninstall?: number
171
177
  }
172
178
  Relationships: []
173
179
  }
@@ -182,6 +188,7 @@ export interface Database {
182
188
  id: number
183
189
  minUpdateVersion: string | null
184
190
  name: string
191
+ native_packages: Json[] | null
185
192
  session_key: string | null
186
193
  storage_provider: string
187
194
  updated_at: string | null
@@ -197,6 +204,7 @@ export interface Database {
197
204
  id?: number
198
205
  minUpdateVersion?: string | null
199
206
  name: string
207
+ native_packages?: Json[] | null
200
208
  session_key?: string | null
201
209
  storage_provider?: string
202
210
  updated_at?: string | null
@@ -212,6 +220,7 @@ export interface Database {
212
220
  id?: number
213
221
  minUpdateVersion?: string | null
214
222
  name?: string
223
+ native_packages?: Json[] | null
215
224
  session_key?: string | null
216
225
  storage_provider?: string
217
226
  updated_at?: string | null
@@ -379,12 +388,6 @@ export interface Database {
379
388
  columns: ["created_by"]
380
389
  referencedRelation: "users"
381
390
  referencedColumns: ["id"]
382
- },
383
- {
384
- foreignKeyName: "channel_devices_device_id_fkey"
385
- columns: ["device_id"]
386
- referencedRelation: "devices"
387
- referencedColumns: ["device_id"]
388
391
  }
389
392
  ]
390
393
  }
@@ -561,49 +564,43 @@ export interface Database {
561
564
  devices: {
562
565
  Row: {
563
566
  app_id: string
564
- created_at: string | null
567
+ created_at: string
565
568
  custom_id: string
566
- date_id: string | null
567
569
  device_id: string
568
570
  is_emulator: boolean | null
569
571
  is_prod: boolean | null
570
- last_mau: string | null
571
572
  os_version: string | null
572
573
  platform: Database["public"]["Enums"]["platform_os"] | null
573
574
  plugin_version: string
574
- updated_at: string | null
575
+ updated_at: string
575
576
  version: number
576
577
  version_build: string | null
577
578
  }
578
579
  Insert: {
579
580
  app_id: string
580
- created_at?: string | null
581
+ created_at: string
581
582
  custom_id?: string
582
- date_id?: string | null
583
583
  device_id: string
584
584
  is_emulator?: boolean | null
585
585
  is_prod?: boolean | null
586
- last_mau?: string | null
587
586
  os_version?: string | null
588
587
  platform?: Database["public"]["Enums"]["platform_os"] | null
589
588
  plugin_version?: string
590
- updated_at?: string | null
589
+ updated_at: string
591
590
  version: number
592
591
  version_build?: string | null
593
592
  }
594
593
  Update: {
595
594
  app_id?: string
596
- created_at?: string | null
595
+ created_at?: string
597
596
  custom_id?: string
598
- date_id?: string | null
599
597
  device_id?: string
600
598
  is_emulator?: boolean | null
601
599
  is_prod?: boolean | null
602
- last_mau?: string | null
603
600
  os_version?: string | null
604
601
  platform?: Database["public"]["Enums"]["platform_os"] | null
605
602
  plugin_version?: string
606
- updated_at?: string | null
603
+ updated_at?: string
607
604
  version?: number
608
605
  version_build?: string | null
609
606
  }
@@ -647,12 +644,6 @@ export interface Database {
647
644
  referencedRelation: "users"
648
645
  referencedColumns: ["id"]
649
646
  },
650
- {
651
- foreignKeyName: "devices_override_device_id_fkey"
652
- columns: ["device_id"]
653
- referencedRelation: "devices"
654
- referencedColumns: ["device_id"]
655
- },
656
647
  {
657
648
  foreignKeyName: "devices_override_version_fkey"
658
649
  columns: ["version"]
@@ -916,7 +907,7 @@ export interface Database {
916
907
  Row: {
917
908
  action: string
918
909
  app_id: string
919
- created_at: string | null
910
+ created_at: string
920
911
  device_id: string
921
912
  platform: Database["public"]["Enums"]["platform_os"]
922
913
  version: number
@@ -925,7 +916,7 @@ export interface Database {
925
916
  Insert: {
926
917
  action: string
927
918
  app_id: string
928
- created_at?: string | null
919
+ created_at: string
929
920
  device_id: string
930
921
  platform: Database["public"]["Enums"]["platform_os"]
931
922
  version: number
@@ -934,7 +925,7 @@ export interface Database {
934
925
  Update: {
935
926
  action?: string
936
927
  app_id?: string
937
- created_at?: string | null
928
+ created_at?: string
938
929
  device_id?: string
939
930
  platform?: Database["public"]["Enums"]["platform_os"]
940
931
  version?: number
@@ -1252,6 +1243,13 @@ export interface Database {
1252
1243
  Args: Record<PropertyKey, never>
1253
1244
  Returns: number
1254
1245
  }
1246
+ create_partitions: {
1247
+ Args: {
1248
+ start_date: string
1249
+ num_years: number
1250
+ }
1251
+ Returns: undefined
1252
+ }
1255
1253
  delete_user: {
1256
1254
  Args: Record<PropertyKey, never>
1257
1255
  Returns: undefined
@@ -1414,6 +1412,16 @@ export interface Database {
1414
1412
  Returns: Database["public"]["CompositeTypes"]["stats_table"]
1415
1413
  }
1416
1414
  get_plan_usage_percent:
1415
+ | {
1416
+ Args: {
1417
+ userid: string
1418
+ }
1419
+ Returns: number
1420
+ }
1421
+ | {
1422
+ Args: Record<PropertyKey, never>
1423
+ Returns: number
1424
+ }
1417
1425
  | {
1418
1426
  Args: {
1419
1427
  dateid: string
@@ -1451,9 +1459,7 @@ export interface Database {
1451
1459
  }
1452
1460
  get_total_stats_v3:
1453
1461
  | {
1454
- Args: {
1455
- userid: string
1456
- }
1462
+ Args: Record<PropertyKey, never>
1457
1463
  Returns: {
1458
1464
  mau: number
1459
1465
  bandwidth: number
@@ -1461,7 +1467,9 @@ export interface Database {
1461
1467
  }[]
1462
1468
  }
1463
1469
  | {
1464
- Args: Record<PropertyKey, never>
1470
+ Args: {
1471
+ userid: string
1472
+ }
1465
1473
  Returns: {
1466
1474
  mau: number
1467
1475
  bandwidth: number
@@ -1469,6 +1477,12 @@ export interface Database {
1469
1477
  }[]
1470
1478
  }
1471
1479
  get_total_storage_size:
1480
+ | {
1481
+ Args: {
1482
+ app_id: string
1483
+ }
1484
+ Returns: number
1485
+ }
1472
1486
  | {
1473
1487
  Args: Record<PropertyKey, never>
1474
1488
  Returns: number
@@ -1545,12 +1559,20 @@ export interface Database {
1545
1559
  }
1546
1560
  Returns: boolean
1547
1561
  }
1548
- is_allowed_action: {
1549
- Args: {
1550
- apikey: string
1551
- }
1552
- Returns: boolean
1553
- }
1562
+ is_allowed_action:
1563
+ | {
1564
+ Args: {
1565
+ apikey: string
1566
+ appid: string
1567
+ }
1568
+ Returns: boolean
1569
+ }
1570
+ | {
1571
+ Args: {
1572
+ apikey: string
1573
+ }
1574
+ Returns: boolean
1575
+ }
1554
1576
  is_allowed_action_user:
1555
1577
  | {
1556
1578
  Args: Record<PropertyKey, never>
@@ -1640,16 +1662,16 @@ export interface Database {
1640
1662
  Returns: boolean
1641
1663
  }
1642
1664
  is_good_plan_v4:
1643
- | {
1644
- Args: Record<PropertyKey, never>
1645
- Returns: number
1646
- }
1647
1665
  | {
1648
1666
  Args: {
1649
1667
  userid: string
1650
1668
  }
1651
1669
  Returns: boolean
1652
1670
  }
1671
+ | {
1672
+ Args: Record<PropertyKey, never>
1673
+ Returns: boolean
1674
+ }
1653
1675
  is_in_channel:
1654
1676
  | {
1655
1677
  Args: {
@@ -1709,6 +1731,17 @@ export interface Database {
1709
1731
  }
1710
1732
  Returns: boolean
1711
1733
  }
1734
+ is_paying_and_good_plan:
1735
+ | {
1736
+ Args: Record<PropertyKey, never>
1737
+ Returns: boolean
1738
+ }
1739
+ | {
1740
+ Args: {
1741
+ userid: string
1742
+ }
1743
+ Returns: boolean
1744
+ }
1712
1745
  is_trial:
1713
1746
  | {
1714
1747
  Args: Record<PropertyKey, never>
package/src/utils.ts CHANGED
@@ -8,7 +8,6 @@ import prettyjson from 'prettyjson';
8
8
  import { LogSnag } from 'logsnag';
9
9
  import * as p from '@clack/prompts';
10
10
  import { Database } from 'types/supabase.types';
11
- import { CapacitorConfig } from '@capacitor/cli';
12
11
  import axios from 'axios';
13
12
 
14
13
  export const baseKey = '.capgo_key';
@@ -19,12 +18,17 @@ export const defaultHostWeb = 'https://web.capgo.app'
19
18
  // eslint-disable-next-line max-len
20
19
  export const regexSemver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
21
20
 
21
+ export interface OptionsBase {
22
+ apikey: string;
23
+ }
24
+
22
25
  export const getConfig = async () => {
23
26
  let config: Config;
24
27
  try {
25
28
  config = await loadConfig();
26
29
  } catch (err) {
27
- program.error("No capacitor config file found, run `cap init` first");
30
+ p.log.error('No capacitor config file found, run `cap init` first');
31
+ program.error('')
28
32
  }
29
33
  return config;
30
34
  }
@@ -72,7 +76,8 @@ export const getRemoteConfig = async () => {
72
76
  export const createSupabaseClient = async (apikey: string) => {
73
77
  const config = await getRemoteConfig()
74
78
  if (!config.supaHost || !config.supaKey) {
75
- program.error('Cannot connect to server please try again later');
79
+ p.log.error('Cannot connect to server please try again later');
80
+ program.error('');
76
81
  }
77
82
  return createClient<Database>(config.supaHost, config.supaKey, {
78
83
  auth: {
@@ -88,53 +93,57 @@ export const createSupabaseClient = async (apikey: string) => {
88
93
 
89
94
  export const checkKey = async (supabase: SupabaseClient<Database>, apikey: string,
90
95
  keymode: Database['public']['Enums']['key_mode'][]) => {
91
- const { data: apiAccess, error: apiAccessError } = await supabase
96
+ const { data: apiAccess} = await supabase
92
97
  .rpc('is_allowed_capgkey', { apikey, keymode })
93
98
  .single()
94
99
 
95
- if (!apiAccess || apiAccessError) {
96
- program.error(`Invalid API key or insufficient permissions ${formatError(apiAccessError)}`);
100
+ if (!apiAccess) {
101
+ p.log.error(`Invalid API key or insufficient permissions.`);
102
+ // create a string from keymode array with comma and space and "or" for the last one
103
+ const keymodeStr = keymode.map((k, i) => {
104
+ if (i === keymode.length - 1) {
105
+ return `or ${k}`
106
+ }
107
+ return `${k}, `
108
+ }).join('')
109
+ p.log.error(`Your key should be: ${keymodeStr} mode.`);
110
+ program.error('')
97
111
  }
98
112
  }
99
113
 
100
114
  export const isGoodPlan = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
101
- const { data, error } = await supabase
115
+ const { data } = await supabase
102
116
  .rpc('is_good_plan_v3', { userid: userId })
103
117
  .single()
104
- if (error) {
105
- throw error
106
- }
107
118
  return data || false
108
119
  }
109
120
 
110
121
  export const isPaying = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
111
- const { data, error } = await supabase
122
+ const { data } = await supabase
112
123
  .rpc('is_paying', { userid: userId })
113
124
  .single()
114
- if (error) {
115
- throw error
116
- }
117
125
  return data || false
118
126
  }
119
127
 
120
128
  export const isTrial = async (supabase: SupabaseClient<Database>, userId: string): Promise<number> => {
121
- const { data, error } = await supabase
129
+ const { data } = await supabase
122
130
  .rpc('is_trial', { userid: userId })
123
131
  .single()
124
- if (error) {
125
- throw error
126
- }
127
132
  return data || 0
128
133
  }
129
134
 
130
135
  export const isAllowedAction = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
131
- const { data, error } = await supabase
136
+ const { data } = await supabase
132
137
  .rpc('is_allowed_action_user', { userid: userId })
133
138
  .single()
134
- if (error) {
135
- throw error
136
- }
137
- return data
139
+ return !!data
140
+ }
141
+
142
+ export const isAllowedApp = async (supabase: SupabaseClient<Database>, apikey: string, appId: string): Promise<boolean> => {
143
+ const { data } = await supabase
144
+ .rpc('is_allowed_action', { apikey, appid: appId })
145
+ .single()
146
+ return !!data
138
147
  }
139
148
 
140
149
  export const checkPlanValid = async (supabase: SupabaseClient<Database>, userId: string, warning = true) => {
@@ -173,8 +182,10 @@ export const findSavedKey = (quiet = false) => {
173
182
  p.log.info(`Use local apy key ${keyPath}`)
174
183
  key = readFileSync(keyPath, 'utf8').trim();
175
184
  }
176
- if (!key)
177
- program.error('Key not found, please login first');
185
+ if (!key) {
186
+ p.log.error(`Cannot find API key in local folder or global, please login first with npx @capacitor/cli login`);
187
+ program.error('')
188
+ }
178
189
  return key
179
190
  }
180
191
 
@@ -341,6 +352,7 @@ export const useLogSnag = (): LogSnag => {
341
352
  }
342
353
 
343
354
  export const convertAppName = (appName: string) => appName.replace(/\./g, '--')
355
+
344
356
  export const verifyUser = async (supabase: SupabaseClient<Database>, apikey: string,
345
357
  keymod: Database['public']['Enums']['key_mode'][] = ['all']) => {
346
358
  await checkKey(supabase, apikey, keymod);
@@ -352,7 +364,8 @@ export const verifyUser = async (supabase: SupabaseClient<Database>, apikey: str
352
364
  const userId = (dataUser || '').toString();
353
365
 
354
366
  if (!userId || userIdError) {
355
- program.error(`Cannot verify user ${formatError(userIdError)}`);
367
+ p.log.error(`Cannot auth user with apikey`);
368
+ program.error('')
356
369
  }
357
370
  return userId;
358
371
  }
@@ -1,15 +0,0 @@
1
- import { SupabaseClient } from '@supabase/supabase-js';
2
- import { program } from 'commander';
3
- import { Database } from 'types/supabase.types';
4
- import { formatError } from '../utils';
5
-
6
- export const deleteFromStorage = async (supabase: SupabaseClient<Database>,
7
- userId: string, appid: string, versionData: Database['public']['Tables']['app_versions']['Row'], bundle: string) => {
8
- const { error: delError } = await supabase
9
- .storage
10
- .from('apps')
11
- .remove([`${userId}/${appid}/versions/${versionData.bucket_id} `]);
12
- if (delError) {
13
- program.error(`Something went wrong when trying to delete ${appid} @${bundle} ${formatError(delError)} `);
14
- }
15
- }
package/src/api/utils.ts DELETED
@@ -1,4 +0,0 @@
1
-
2
- export interface OptionsBase {
3
- apikey: string;
4
- }