@capgo/cli 4.0.11 → 4.0.13

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.
@@ -1,86 +1,87 @@
1
- import { SupabaseClient } from '@supabase/supabase-js';
2
- import { program } from 'commander';
3
- import { Table } from 'console-table-printer';
4
- import * as p from '@clack/prompts';
5
- import { Database } from '../types/supabase.types';
1
+ import type { SupabaseClient } from '@supabase/supabase-js'
2
+ import { program } from 'commander'
3
+ import { Table } from 'console-table-printer'
4
+ import * as p from '@clack/prompts'
5
+ import type { Database } from '../types/supabase.types'
6
+
6
7
  // import { definitions } from '../types/types_supabase';
7
- import { getHumanDate } from '../utils';
8
- import { checkVersionNotUsedInChannel } from './channels';
9
- import { checkVersionNotUsedInDeviceOverride } from './devices_override';
8
+ import { getHumanDate } from '../utils'
9
+ import { checkVersionNotUsedInChannel } from './channels'
10
+ import { checkVersionNotUsedInDeviceOverride } from './devices_override'
10
11
 
11
- export const deleteAppVersion = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
12
+ export async function deleteAppVersion(supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) {
12
13
  const { error: delAppSpecVersionError } = await supabase
13
14
  .from('app_versions')
14
15
  .update({
15
- deleted: true
16
+ deleted: true,
16
17
  })
17
18
  .eq('app_id', appid)
18
19
  .eq('deleted', false)
19
20
  .eq('user_id', userId)
20
- .eq('name', bundle);
21
+ .eq('name', bundle)
21
22
  if (delAppSpecVersionError) {
22
- p.log.error(`App Version ${appid}@${bundle} not found in database`);
23
- program.error('');
23
+ p.log.error(`App Version ${appid}@${bundle} not found in database`)
24
+ program.error('')
24
25
  }
25
26
  }
26
27
 
27
- export const deleteSpecificVersion = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
28
- const versionData = await getVersionData(supabase, appid, userId, bundle);
29
- await checkVersionNotUsedInChannel(supabase, appid, userId, versionData);
30
- await checkVersionNotUsedInDeviceOverride(supabase, appid, versionData);
28
+ export async function deleteSpecificVersion(supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) {
29
+ const versionData = await getVersionData(supabase, appid, userId, bundle)
30
+ await checkVersionNotUsedInChannel(supabase, appid, userId, versionData)
31
+ await checkVersionNotUsedInDeviceOverride(supabase, appid, versionData)
31
32
  // Delete only a specific version in storage
32
- await deleteAppVersion(supabase, appid, userId, bundle);
33
+ await deleteAppVersion(supabase, appid, userId, bundle)
33
34
  }
34
35
 
35
- export const displayBundles = (data: (Database['public']['Tables']['app_versions']['Row'] & { keep?: string })[]) => {
36
+ export function displayBundles(data: (Database['public']['Tables']['app_versions']['Row'] & { keep?: string })[]) {
36
37
  const t = new Table({
37
- title: "Bundles",
38
- charLength: { "": 2, "": 2 },
39
- });
38
+ title: 'Bundles',
39
+ charLength: { '': 2, '': 2 },
40
+ })
40
41
 
41
42
  // add rows with color
42
- data.reverse().forEach(row => {
43
+ data.reverse().forEach((row) => {
43
44
  t.addRow({
44
45
  Version: row.name,
45
46
  Created: getHumanDate(row.created_at),
46
- ...(row.keep != null ? { Keep: row.keep } : {})
47
- });
48
- });
47
+ ...(row.keep != null ? { Keep: row.keep } : {}),
48
+ })
49
+ })
49
50
 
50
- p.log.success(t.render());
51
+ p.log.success(t.render())
51
52
  }
52
53
 
53
- export const getActiveAppVersions = async (supabase: SupabaseClient<Database>, appid: string, userId: string) => {
54
+ export async function getActiveAppVersions(supabase: SupabaseClient<Database>, appid: string, userId: string) {
54
55
  const { data, error: vError } = await supabase
55
56
  .from('app_versions')
56
57
  .select()
57
58
  .eq('app_id', appid)
58
59
  .eq('user_id', userId)
59
60
  .eq('deleted', false)
60
- .order('created_at', { ascending: false });
61
+ .order('created_at', { ascending: false })
61
62
 
62
63
  if (vError) {
63
- p.log.error(`App ${appid} not found in database`);
64
- program.error('');
64
+ p.log.error(`App ${appid} not found in database`)
65
+ program.error('')
65
66
  }
66
- return data;
67
+ return data
67
68
  }
68
69
 
69
- export const getChannelsVersion = async (supabase: SupabaseClient<Database>, appid: string) => {
70
+ export async function getChannelsVersion(supabase: SupabaseClient<Database>, appid: string) {
70
71
  // get all channels versionID
71
72
  const { data: channels, error: channelsError } = await supabase
72
73
  .from('channels')
73
74
  .select('version')
74
75
  .eq('app_id', appid)
75
-
76
+
76
77
  if (channelsError) {
77
- p.log.error(`App ${appid} not found in database`);
78
- program.error('');
78
+ p.log.error(`App ${appid} not found in database`)
79
+ program.error('')
79
80
  }
80
- return channels.map(c => c.version);
81
+ return channels.map(c => c.version)
81
82
  }
82
83
 
83
- export const getVersionData = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
84
+ export async function getVersionData(supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) {
84
85
  const { data: versionData, error: versionIdError } = await supabase
85
86
  .from('app_versions')
86
87
  .select()
@@ -88,10 +89,10 @@ export const getVersionData = async (supabase: SupabaseClient<Database>, appid:
88
89
  .eq('user_id', userId)
89
90
  .eq('name', bundle)
90
91
  .eq('deleted', false)
91
- .single();
92
+ .single()
92
93
  if (!versionData || versionIdError) {
93
- p.log.error(`App Version ${appid}@${bundle} doesn't exist`);
94
- program.error('');
94
+ p.log.error(`App Version ${appid}@${bundle} doesn't exist`)
95
+ program.error('')
95
96
  }
96
- return versionData;
97
+ return versionData
97
98
  }
package/src/app/add.ts CHANGED
@@ -1,72 +1,80 @@
1
- import { randomUUID } from 'node:crypto';
2
- import mime from 'mime';
3
- import { program } from 'commander';
4
- import * as p from '@clack/prompts';
5
- import { existsSync, readFileSync } from 'node:fs';
6
- import { checkLatest } from '../api/update';
7
- import { newIconPath, Options, checkAppExists } from '../api/app';
1
+ import { randomUUID } from 'node:crypto'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import process from 'node:process'
4
+ import mime from 'mime'
5
+ import { program } from 'commander'
6
+ import * as p from '@clack/prompts'
7
+ import { checkLatest } from '../api/update'
8
+ import type { Options } from '../api/app'
9
+ import { checkAppExists, newIconPath } from '../api/app'
8
10
  import {
9
- getConfig, createSupabaseClient,
10
- findSavedKey, useLogSnag, verifyUser, formatError
11
- } from '../utils';
11
+ createSupabaseClient,
12
+ findSavedKey,
13
+ formatError,
14
+ getConfig,
15
+ useLogSnag,
16
+ verifyUser,
17
+ } from '../utils'
12
18
 
13
- export const addApp = async (appId: string, options: Options, throwErr = true) => {
14
- if (throwErr) {
15
- p.intro(`Adding`);
16
- }
17
- await checkLatest();
19
+ export async function addApp(appId: string, options: Options, throwErr = true) {
20
+ if (throwErr)
21
+ p.intro(`Adding`)
22
+
23
+ await checkLatest()
18
24
  options.apikey = options.apikey || findSavedKey()
19
- const config = await getConfig();
25
+ const config = await getConfig()
20
26
  appId = appId || config?.app?.appId
21
27
  const snag = useLogSnag()
22
28
 
23
29
  if (!options.apikey) {
24
- p.log.error(`Missing API key, you need to provide a API key to upload your bundle`);
25
- program.error('');
30
+ p.log.error(`Missing API key, you need to provide a API key to upload your bundle`)
31
+ program.error('')
26
32
  }
27
33
  if (!appId) {
28
- p.log.error("Missing argument, you need to provide a appId, or be in a capacitor project");
29
- program.error('');
34
+ p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
35
+ program.error('')
30
36
  }
31
37
  const supabase = await createSupabaseClient(options.apikey)
32
38
 
33
- const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
39
+ const userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
34
40
  // Check we have app access to this appId
35
- const appExist = await checkAppExists(supabase, appId);
41
+ const appExist = await checkAppExists(supabase, appId)
36
42
  if (throwErr && appExist) {
37
- p.log.error(`App ${appId} already exist`);
38
- program.error('');
39
- } else if (appExist) {
43
+ p.log.error(`App ${appId} already exist`)
44
+ program.error('')
45
+ }
46
+ else if (appExist) {
40
47
  return true
41
48
  }
42
49
 
43
- let { name, icon } = options;
50
+ let { name, icon } = options
44
51
  appId = appId || config?.app?.appId
45
52
  name = name || config?.app?.appName || 'Unknown'
46
- icon = icon || "resources/icon.png" // default path for capacitor app
53
+ icon = icon || 'resources/icon.png' // default path for capacitor app
47
54
  if (!icon || !name) {
48
- p.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project");
49
- program.error('');
55
+ p.log.error('Missing argument, you need to provide a appId and a name, or be in a capacitor project')
56
+ program.error('')
50
57
  }
51
- if (throwErr) {
52
- p.log.info(`Adding ${appId} to Capgo`);
53
- }
54
- let iconBuff;
55
- let iconType;
58
+ if (throwErr)
59
+ p.log.info(`Adding ${appId} to Capgo`)
60
+
61
+ let iconBuff
62
+ let iconType
56
63
 
57
64
  if (icon && existsSync(icon)) {
58
- iconBuff = readFileSync(icon);
59
- const contentType = mime.getType(icon);
60
- iconType = contentType || 'image/png';
61
- p.log.warn(`Found app icon ${icon}`);
65
+ iconBuff = readFileSync(icon)
66
+ const contentType = mime.getType(icon)
67
+ iconType = contentType || 'image/png'
68
+ p.log.warn(`Found app icon ${icon}`)
62
69
  }
63
70
  else if (existsSync(newIconPath)) {
64
- iconBuff = readFileSync(newIconPath);
65
- const contentType = mime.getType(newIconPath);
66
- iconType = contentType || 'image/png';
67
- p.log.warn(`Found app icon ${newIconPath}`);
68
- } else {
69
- p.log.warn(`Cannot find app icon in any of the following locations: ${icon}, ${newIconPath}`);
71
+ iconBuff = readFileSync(newIconPath)
72
+ const contentType = mime.getType(newIconPath)
73
+ iconType = contentType || 'image/png'
74
+ p.log.warn(`Found app icon ${newIconPath}`)
75
+ }
76
+ else {
77
+ p.log.warn(`Cannot find app icon in any of the following locations: ${icon}, ${newIconPath}`)
70
78
  }
71
79
 
72
80
  const fileName = `icon_${randomUUID()}`
@@ -80,8 +88,8 @@ export const addApp = async (appId: string, options: Options, throwErr = true) =
80
88
  contentType: iconType,
81
89
  })
82
90
  if (error) {
83
- p.log.error(`Could not add app ${formatError(error)}`);
84
- program.error('');
91
+ p.log.error(`Could not add app ${formatError(error)}`)
92
+ program.error('')
85
93
  }
86
94
  const { data: signedURLData } = await supabase
87
95
  .storage
@@ -99,8 +107,8 @@ export const addApp = async (appId: string, options: Options, throwErr = true) =
99
107
  app_id: appId,
100
108
  })
101
109
  if (dbError) {
102
- p.log.error(`Could not add app ${formatError(dbError)}`);
103
- program.error('');
110
+ p.log.error(`Could not add app ${formatError(dbError)}`)
111
+ program.error('')
104
112
  }
105
113
  const { error: dbVersionError } = await supabase
106
114
  .from('app_versions')
@@ -116,8 +124,8 @@ export const addApp = async (appId: string, options: Options, throwErr = true) =
116
124
  app_id: appId,
117
125
  }])
118
126
  if (dbVersionError) {
119
- p.log.error(`Could not add app ${formatError(dbVersionError)}`);
120
- program.error('');
127
+ p.log.error(`Could not add app ${formatError(dbVersionError)}`)
128
+ program.error('')
121
129
  }
122
130
  await snag.track({
123
131
  channel: 'app',
@@ -129,14 +137,14 @@ export const addApp = async (appId: string, options: Options, throwErr = true) =
129
137
  },
130
138
  notify: false,
131
139
  }).catch()
132
- p.log.success(`App ${appId} added to Capgo. ${throwErr ? 'You can upload a bundle now' : ''}`);
140
+ p.log.success(`App ${appId} added to Capgo. ${throwErr ? 'You can upload a bundle now' : ''}`)
133
141
  if (throwErr) {
134
- p.outro(`Done ✅`);
142
+ p.outro(`Done ✅`)
135
143
  process.exit()
136
144
  }
137
145
  return true
138
146
  }
139
147
 
140
- export const addCommand = async (apikey: string, options: Options) => {
148
+ export async function addCommand(apikey: string, options: Options) {
141
149
  addApp(apikey, options, true)
142
150
  }