@capgo/cli 3.14.21 → 3.14.22

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/api/app.ts CHANGED
@@ -1,21 +1,32 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
+ import * as p from '@clack/prompts';
2
3
  import { program } from 'commander';
3
4
  import { Database } from 'types/supabase.types';
4
- import { OptionsBase } from './utils';
5
+ import { isAllowedApp, OptionsBase } from '../utils';
5
6
 
6
- export const checkAppExistsAndHasPermission = async (supabase: SupabaseClient<Database>, appid: string,
7
- shouldExist = true) => {
8
- const { data: app, error: dbError0 } = await supabase
7
+ export const checkAppExists = async (supabase: SupabaseClient<Database>, appid: string) => {
8
+ const { data: app } = await supabase
9
9
  .rpc('exist_app_v2', { appid })
10
10
  .single();
11
- return app !== shouldExist || dbError0;
11
+ return !!app;
12
12
  }
13
13
 
14
- export const checkAppExistsAndHasPermissionErr = async (supabase: SupabaseClient<Database>, appid: string,
14
+ export const checkAppExistsAndHasPermissionErr = async (supabase: SupabaseClient<Database>, apikey: string, appid: string,
15
15
  shouldExist = true) => {
16
- const res = await checkAppExistsAndHasPermission(supabase, appid, shouldExist);
17
- if (res) {
18
- program.error(`App ${appid} does not exist or you don't have permission to access it`);
16
+ const res = await checkAppExists(supabase, appid);
17
+ const perm = await isAllowedApp(supabase, apikey, appid);
18
+
19
+ if (res && !shouldExist) {
20
+ p.log.error(`App ${appid} already exist`);
21
+ program.error('');
22
+ }
23
+ if (!res && shouldExist) {
24
+ p.log.error(`App ${appid} does not exist`);
25
+ program.error('');
26
+ }
27
+ if (res && !perm) {
28
+ p.log.error(`App ${appid} exist and you don't have permission to access it`);
29
+ program.error('');
19
30
  }
20
31
  }
21
32
 
@@ -13,8 +13,10 @@ export const checkVersionNotUsedInChannel = async (supabase: SupabaseClient<Data
13
13
  .eq('app_id', appid)
14
14
  .eq('created_by', userId)
15
15
  .eq('version', versionData.id)
16
- if (errorChannel)
17
- program.error(`Cannot check Version ${appid}@${versionData.name} ${formatError(errorChannel)}`);
16
+ if (errorChannel) {
17
+ p.log.error(`Cannot check Version ${appid}@${versionData.name}`);
18
+ program.error('');
19
+ }
18
20
  if (channelFound && channelFound.length > 0) {
19
21
  p.intro(`❌ Version ${appid}@${versionData.name} is used in ${channelFound.length} channel`)
20
22
  if (await p.confirm({ message: 'unlink it?' })) {
@@ -36,7 +38,8 @@ export const checkVersionNotUsedInChannel = async (supabase: SupabaseClient<Data
36
38
  }
37
39
  }
38
40
  else {
39
- program.error(`unlink it first`);
41
+ p.log.error(`Unlink it first`);
42
+ program.error('');
40
43
  }
41
44
  p.outro(`Version unlinked from ${channelFound.length} channel`)
42
45
  }
@@ -93,7 +96,8 @@ export const getActiveChannels = async (supabase: SupabaseClient<Database>, appi
93
96
  .order('created_at', { ascending: false });
94
97
 
95
98
  if (vError) {
96
- program.error(`App ${appid} not found in database ${formatError(vError)} `);
99
+ p.log.error(`App ${appid} not found in database`);
100
+ program.error('');
97
101
  }
98
102
  return data;
99
- }
103
+ }
@@ -12,8 +12,10 @@ export const checkVersionNotUsedInDeviceOverride = async (supabase: SupabaseClie
12
12
  .select()
13
13
  .eq('app_id', appid)
14
14
  .eq('version', versionData.id)
15
- if (errorDevice)
16
- program.error(`Cannot check Device override ${appid}@${versionData.name} ${formatError(errorDevice)}`);
15
+ if (errorDevice) {
16
+ p.log.error(`Cannot check Device override ${appid}@${versionData.name}`);
17
+ program.error('');
18
+ }
17
19
  if (deviceFound && deviceFound.length > 0) {
18
20
  p.intro(`❌ Version ${appid}@${versionData.name} is used in ${deviceFound.length} device override`)
19
21
  if (await p.confirm({ message: 'unlink it?' })) {
@@ -33,7 +35,8 @@ export const checkVersionNotUsedInDeviceOverride = async (supabase: SupabaseClie
33
35
  }
34
36
  }
35
37
  else {
36
- program.error(`unlink it first`);
38
+ p.log.error(`Unlink it first`);
39
+ program.error('');
37
40
  }
38
41
  }
39
- }
42
+ }
@@ -7,7 +7,6 @@ import { Database } from 'types/supabase.types';
7
7
  import { formatError, getHumanDate } from '../utils';
8
8
  import { checkVersionNotUsedInChannel } from './channels';
9
9
  import { checkVersionNotUsedInDeviceOverride } from './devices_override';
10
- import { deleteFromStorage } from './storage';
11
10
 
12
11
  export const deleteAppVersion = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
13
12
  const { error: delAppSpecVersionError } = await supabase
@@ -20,7 +19,8 @@ export const deleteAppVersion = async (supabase: SupabaseClient<Database>, appid
20
19
  .eq('user_id', userId)
21
20
  .eq('name', bundle);
22
21
  if (delAppSpecVersionError) {
23
- program.error(`App Version ${appid}@${bundle} not found in database '${formatError(delAppSpecVersionError)}'`);
22
+ p.log.error(`App Version ${appid}@${bundle} not found in database`);
23
+ program.error('');
24
24
  }
25
25
  }
26
26
 
@@ -29,8 +29,6 @@ export const deleteSpecificVersion = async (supabase: SupabaseClient<Database>,
29
29
  await checkVersionNotUsedInChannel(supabase, appid, userId, versionData);
30
30
  await checkVersionNotUsedInDeviceOverride(supabase, appid, versionData);
31
31
  // Delete only a specific version in storage
32
- await deleteFromStorage(supabase, userId, appid, versionData, bundle);
33
-
34
32
  await deleteAppVersion(supabase, appid, userId, bundle);
35
33
  }
36
34
 
@@ -62,7 +60,8 @@ export const getActiveAppVersions = async (supabase: SupabaseClient<Database>, a
62
60
  .order('created_at', { ascending: false });
63
61
 
64
62
  if (vError) {
65
- program.error(`App ${appid} not found in database ${formatError(vError)} `);
63
+ p.log.error(`App ${appid} not found in database`);
64
+ program.error('');
66
65
  }
67
66
  return data;
68
67
  }
@@ -75,7 +74,8 @@ export const getChannelsVersion = async (supabase: SupabaseClient<Database>, app
75
74
  .eq('app_id', appid)
76
75
 
77
76
  if (channelsError) {
78
- program.error(`App ${appid} not found in database ${formatError(channelsError)} `);
77
+ p.log.error(`App ${appid} not found in database`);
78
+ program.error('');
79
79
  }
80
80
  return channels.map(c => c.version);
81
81
  }
@@ -90,7 +90,8 @@ export const getVersionData = async (supabase: SupabaseClient<Database>, appid:
90
90
  .eq('deleted', false)
91
91
  .single();
92
92
  if (!versionData || versionIdError) {
93
- program.error(`App Version ${appid}@${bundle} doesn't exist ${formatError(versionIdError)}`);
93
+ p.log.error(`App Version ${appid}@${bundle} doesn't exist`);
94
+ program.error('');
94
95
  }
95
96
  return versionData;
96
97
  }
package/src/app/add.ts CHANGED
@@ -4,14 +4,14 @@ import { program } from 'commander';
4
4
  import * as p from '@clack/prompts';
5
5
  import { existsSync, readFileSync } from 'fs-extra';
6
6
  import { checkLatest } from '../api/update';
7
- import { checkAppExistsAndHasPermissionErr, checkAppExistsAndHasPermission, newIconPath, Options } from '../api/app';
7
+ import { newIconPath, Options, checkAppExists } from '../api/app';
8
8
  import {
9
9
  getConfig, createSupabaseClient,
10
10
  findSavedKey, useLogSnag, verifyUser, formatError
11
11
  } from '../utils';
12
12
 
13
- export const addApp = async (appId: string, options: Options, shouldExit = true) => {
14
- if (shouldExit) {
13
+ export const addApp = async (appId: string, options: Options, throwErr = true) => {
14
+ if (throwErr) {
15
15
  p.intro(`Adding`);
16
16
  }
17
17
  await checkLatest();
@@ -32,13 +32,12 @@ export const addApp = async (appId: string, options: Options, shouldExit = true)
32
32
 
33
33
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
34
34
  // Check we have app access to this appId
35
- if (shouldExit) {
36
- await checkAppExistsAndHasPermissionErr(supabase, appId, false);
37
- } else {
38
- const res = await checkAppExistsAndHasPermission(supabase, appId, false);
39
- if (res) {
40
- return false
41
- }
35
+ const appExist = await checkAppExists(supabase, appId);
36
+ if (throwErr && appExist) {
37
+ p.log.error(`App ${appId} already exist`);
38
+ program.error('');
39
+ } else if (appExist) {
40
+ return true
42
41
  }
43
42
 
44
43
  let { name, icon } = options;
@@ -49,7 +48,7 @@ export const addApp = async (appId: string, options: Options, shouldExit = true)
49
48
  p.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project");
50
49
  program.error('');
51
50
  }
52
- if (shouldExit) {
51
+ if (throwErr) {
53
52
  p.log.info(`Adding ${appId} to Capgo`);
54
53
  }
55
54
  let iconBuff;
@@ -130,8 +129,8 @@ export const addApp = async (appId: string, options: Options, shouldExit = true)
130
129
  },
131
130
  notify: false,
132
131
  }).catch()
133
- p.log.success(`App ${appId} added to Capgo. ${shouldExit ? 'You can upload a bundle now' : ''}`);
134
- if (shouldExit) {
132
+ p.log.success(`App ${appId} added to Capgo. ${throwErr ? 'You can upload a bundle now' : ''}`);
133
+ if (throwErr) {
135
134
  p.outro(`Done ✅`);
136
135
  process.exit()
137
136
  }
package/src/app/debug.ts CHANGED
@@ -164,7 +164,7 @@ export const debugApp = async (appId: string, options: OptionsBaseDebug) => {
164
164
  p.log.info(`Getting active bundle in Capgo`);
165
165
 
166
166
  // Check we have app access to this appId
167
- await checkAppExistsAndHasPermissionErr(supabase, appId);
167
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
168
168
 
169
169
  const doRun = await p.confirm({ message: `Automatic check if update working in device ?` });
170
170
  await cancelCommand('debug', doRun, userId, snag);
package/src/app/delete.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { program } from "commander";
2
2
  import * as p from '@clack/prompts';
3
- import { OptionsBase } from "../api/utils";
4
3
  import { checkAppExistsAndHasPermissionErr } from '../api/app';
5
- import { createSupabaseClient, findSavedKey, formatError, getConfig, useLogSnag, verifyUser } from "../utils";
4
+ import { createSupabaseClient, findSavedKey, formatError, getConfig, useLogSnag, verifyUser, OptionsBase } from "../utils";
6
5
 
7
6
  export const deleteApp = async (appId: string, options: OptionsBase) => {
8
7
  p.intro(`Deleting`);
@@ -12,30 +11,33 @@ export const deleteApp = async (appId: string, options: OptionsBase) => {
12
11
  const snag = useLogSnag()
13
12
 
14
13
  if (!options.apikey) {
15
- program.error("Missing API key, you need to provide a API key to upload your bundle");
14
+ p.log.error('Missing API key, you need to provide a API key to upload your bundle');
15
+ program.error('');
16
16
  }
17
17
  if (!appId) {
18
- program.error("Missing argument, you need to provide a appId, or be in a capacitor project");
18
+ p.log.error('Missing argument, you need to provide a appId, or be in a capacitor project');
19
+ program.error('');
19
20
  }
20
21
  const supabase = await createSupabaseClient(options.apikey)
21
22
 
22
23
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
23
24
  // Check we have app access to this appId
24
- await checkAppExistsAndHasPermissionErr(supabase, appId);
25
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
25
26
 
26
27
  const { error } = await supabase
27
28
  .storage
28
29
  .from(`images/${userId}`)
29
30
  .remove([appId])
30
31
  if (error) {
31
- program.error(`Could not add app ${formatError(error)}`);
32
+ p.log.error('Could not delete app logo');
32
33
  }
33
34
  const { error: delError } = await supabase
34
35
  .storage
35
36
  .from(`apps/${appId}/${userId}`)
36
37
  .remove(['versions'])
37
38
  if (delError) {
38
- program.error(`Could not delete app version ${formatError(delError)}`);
39
+ p.log.error('Could not delete app version');
40
+ program.error('');
39
41
  }
40
42
 
41
43
  const { error: dbError } = await supabase
@@ -45,7 +47,8 @@ export const deleteApp = async (appId: string, options: OptionsBase) => {
45
47
  .eq('user_id', userId)
46
48
 
47
49
  if (dbError) {
48
- program.error(`Could not delete app ${formatError(dbError)}`);
50
+ p.log.error('Could not delete app');
51
+ program.error('');
49
52
  }
50
53
  await snag.track({
51
54
  channel: 'app',
package/src/app/list.ts CHANGED
@@ -3,8 +3,7 @@ import { Table } from 'console-table-printer';
3
3
  import { SupabaseClient } from '@supabase/supabase-js';
4
4
  import * as p from '@clack/prompts';
5
5
  import { Database } from 'types/supabase.types';
6
- import { OptionsBase } from '../api/utils';
7
- import { createSupabaseClient, findSavedKey, formatError, getHumanDate, verifyUser } from '../utils';
6
+ import { OptionsBase, createSupabaseClient, findSavedKey, formatError, getHumanDate, verifyUser } from '../utils';
8
7
  import { checkLatest } from '../api/update';
9
8
 
10
9
  const displayApp = (data: Database['public']['Tables']['apps']['Row'][]) => {
@@ -32,7 +31,8 @@ export const getActiveApps = async (supabase: SupabaseClient<Database>, userId:
32
31
  .order('created_at', { ascending: false });
33
32
 
34
33
  if (vError) {
35
- program.error(`Apps not found in database ${formatError(vError)} `);
34
+ p.log.error('Apps not found');
35
+ program.error('');
36
36
  }
37
37
  return data;
38
38
  }
package/src/app/set.ts CHANGED
@@ -24,7 +24,7 @@ export const setApp = async (appId: string, options: Options) => {
24
24
 
25
25
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
26
26
  // Check we have app access to this appId
27
- await checkAppExistsAndHasPermissionErr(supabase, appId);
27
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
28
28
 
29
29
  const { name, icon, retention } = options;
30
30
 
@@ -4,8 +4,7 @@ import * as p from '@clack/prompts';
4
4
  import promptSync from 'prompt-sync';
5
5
  import { SupabaseClient } from '@supabase/supabase-js';
6
6
  import { Database } from 'types/supabase.types';
7
- import { OptionsBase } from '../api/utils';
8
- import { createSupabaseClient, findSavedKey, getConfig, getHumanDate, verifyUser } from '../utils';
7
+ import { OptionsBase, createSupabaseClient, findSavedKey, getConfig, getHumanDate, verifyUser } from '../utils';
9
8
  import { deleteSpecificVersion, displayBundles, getActiveAppVersions, getChannelsVersion } from '../api/versions';
10
9
  import { checkAppExistsAndHasPermissionErr } from '../api/app';
11
10
  import { checkLatest } from '../api/update';
@@ -52,17 +51,19 @@ export const cleanupBundle = async (appid: string, options: Options) => {
52
51
  const config = await getConfig();
53
52
  appid = appid || config?.app?.appId
54
53
  if (!apikey) {
55
- program.error('Missing API key, you need to provide an API key to delete your app');
54
+ p.log.error('Missing API key, you need to provide an API key to delete your app');
55
+ program.error('');
56
56
  }
57
57
  if (!appid) {
58
- program.error('Missing argument, you need to provide a appid, or be in a capacitor project');
58
+ p.log.error('Missing argument, you need to provide a appid, or be in a capacitor project');
59
+ program.error('');
59
60
  }
60
61
  const supabase = await createSupabaseClient(apikey)
61
62
 
62
63
  const userId = await verifyUser(supabase, apikey);
63
64
 
64
65
  // Check we have app access to this appId
65
- await checkAppExistsAndHasPermissionErr(supabase, appid);
66
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
66
67
  p.log.info(`Querying all available versions in Capgo`);
67
68
 
68
69
  // Get all active app versions we might possibly be able to cleanup
@@ -16,14 +16,16 @@ export const decryptZip = async (zipPath: string, ivsessionKey: string, options:
16
16
  // write in file .capgo the apikey in home directory
17
17
 
18
18
  if (!existsSync(zipPath)) {
19
- program.error(`Zip not found at the path ${zipPath}`);
19
+ p.log.error(`Zip not found at the path ${zipPath}`);
20
+ program.error('');
20
21
  }
21
22
 
22
23
  const config = await getConfig();
23
24
  const { extConfig } = config.app;
24
25
 
25
26
  if (!options.key && !existsSync(baseKey) && !extConfig.plugins?.CapacitorUpdater?.privateKey) {
26
- program.error(`Private Key not found at the path ${baseKey} or in ${config.app.extConfigFilePath}`);
27
+ p.log.error(`Private Key not found at the path ${baseKey} or in ${config.app.extConfigFilePath}`);
28
+ program.error('');
27
29
  }
28
30
  const keyPath = options.key || baseKey
29
31
  // check if publicKey exist
@@ -31,7 +33,8 @@ export const decryptZip = async (zipPath: string, ivsessionKey: string, options:
31
33
  let privateKey = extConfig?.plugins?.CapacitorUpdater?.privateKey
32
34
 
33
35
  if (!existsSync(keyPath) && !privateKey) {
34
- program.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
36
+ p.log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`);
37
+ program.error('');
35
38
  } else if (existsSync(keyPath)) {
36
39
  // open with fs publicKey path
37
40
  const keyFile = readFileSync(keyPath)
@@ -1,8 +1,7 @@
1
1
  import { program } from 'commander';
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from '../api/app';
4
- import { OptionsBase } from '../api/utils';
5
- import { createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils';
4
+ import { OptionsBase, createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils';
6
5
  import { deleteSpecificVersion } from '../api/versions';
7
6
 
8
7
  interface Options extends OptionsBase {
@@ -27,7 +26,7 @@ export const deleteBundle = async (bundleId: string, appId: string, options: Opt
27
26
 
28
27
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
29
28
  // Check we have app access to this appId
30
- await checkAppExistsAndHasPermissionErr(supabase, appId);
29
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
31
30
 
32
31
  const apikey = options.apikey || findSavedKey()
33
32
 
@@ -1,9 +1,8 @@
1
1
  import { program } from 'commander';
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from '../api/app';
4
- import { OptionsBase } from '../api/utils';
5
4
  import { getActiveAppVersions, displayBundles } from '../api/versions';
6
- import { createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils';
5
+ import { OptionsBase, createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils';
7
6
  import { checkLatest } from '../api/update';
8
7
 
9
8
  export const listBundle = async (appId: string, options: OptionsBase) => {
@@ -29,7 +28,7 @@ export const listBundle = async (appId: string, options: OptionsBase) => {
29
28
  p.log.info(`Querying available versions of: ${appId} in Capgo`);
30
29
 
31
30
  // Check we have app access to this appId
32
- await checkAppExistsAndHasPermissionErr(supabase, appId);
31
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
33
32
 
34
33
  // Get all active app versions we might possibly be able to cleanup
35
34
  const allVersions = await getActiveAppVersions(supabase, appId, userId);
@@ -3,9 +3,9 @@ import * as p from '@clack/prompts';
3
3
  import { getVersionData } from 'api/versions';
4
4
  import { checkVersionNotUsedInDeviceOverride } from '../api/devices_override';
5
5
  import { checkVersionNotUsedInChannel } from '../api/channels';
6
- import { OptionsBase } from '../api/utils';
7
6
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
8
7
  import {
8
+ OptionsBase,
9
9
  getConfig, createSupabaseClient,
10
10
  formatError, findSavedKey, checkPlanValid, useLogSnag, verifyUser
11
11
  } from '../utils';
@@ -40,7 +40,7 @@ export const unlinkDevice = async (channel: string, appId: string, options: Opti
40
40
 
41
41
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
42
42
  // Check we have app access to this appId
43
- await checkAppExistsAndHasPermissionErr(supabase, appId);
43
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
44
44
 
45
45
  if (!channel) {
46
46
  p.log.error("Missing argument, you need to provide a channel");
@@ -7,10 +7,10 @@ import { checksum as getChecksum } from '@tomasklaen/checksum';
7
7
  import ciDetect from 'ci-info';
8
8
  import axios from "axios";
9
9
  import { checkLatest } from '../api/update';
10
- import { OptionsBase } from '../api/utils';
11
10
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
12
11
  import { encryptSource } from '../api/crypto';
13
12
  import {
13
+ OptionsBase,
14
14
  getConfig, createSupabaseClient,
15
15
  uploadUrl,
16
16
  updateOrCreateChannel, updateOrCreateVersion,
@@ -95,7 +95,7 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
95
95
  const userId = await verifyUser(supabase, apikey, ['write', 'all', 'upload']);
96
96
  await checkPlanValid(supabase, userId, false)
97
97
  // Check we have app access to this appId
98
- await checkAppExistsAndHasPermissionErr(supabase, appid);
98
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
99
99
 
100
100
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel)
101
101
  if (updateMetadataRequired && !minUpdateVersion) {
package/src/bundle/zip.ts CHANGED
@@ -5,8 +5,8 @@ import { program } from 'commander';
5
5
  import * as p from '@clack/prompts';
6
6
  import { checksum as getChecksum } from '@tomasklaen/checksum';
7
7
  import { checkLatest } from '../api/update';
8
- import { OptionsBase } from '../api/utils';
9
8
  import {
9
+ OptionsBase,
10
10
  getConfig,
11
11
  useLogSnag,
12
12
  regexSemver,
@@ -2,8 +2,7 @@ import { program } from "commander";
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
4
4
  import { createChannel, findUnknownVersion } from "../api/channels";
5
- import { OptionsBase } from "../api/utils";
6
- import { findSavedKey, getConfig, useLogSnag, createSupabaseClient, verifyUser } from "../utils";
5
+ import { OptionsBase, findSavedKey, getConfig, useLogSnag, createSupabaseClient, verifyUser } from "../utils";
7
6
 
8
7
  interface Options extends OptionsBase {
9
8
  default?: boolean;
@@ -28,7 +27,7 @@ export const addChannel = async (channelId: string, appId: string, options: Opti
28
27
 
29
28
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
30
29
  // Check we have app access to this appId
31
- await checkAppExistsAndHasPermissionErr(supabase, appId);
30
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
32
31
 
33
32
  p.log.info(`Creating channel ${appId}#${channelId} to Capgo`);
34
33
  try {
@@ -1,8 +1,7 @@
1
1
  import { program } from "commander";
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
4
- import { OptionsBase } from "../api/utils";
5
- import { createSupabaseClient, findSavedKey, getConfig, verifyUser } from "../utils";
4
+ import { OptionsBase, createSupabaseClient, findSavedKey, getConfig, verifyUser } from "../utils";
6
5
 
7
6
 
8
7
  interface Options extends OptionsBase {
@@ -39,7 +38,7 @@ export const currentBundle = async (channel: string, appId: string, options: Opt
39
38
 
40
39
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'read']);
41
40
  // Check we have app access to this appId
42
- await checkAppExistsAndHasPermissionErr(supabase, appId);
41
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
43
42
 
44
43
  if (!channel) {
45
44
  p.log.error(`Please provide a channel to get the bundle from.`);
@@ -2,8 +2,7 @@ import { program } from "commander";
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
4
4
  import { delChannel } from "../api/channels";
5
- import { OptionsBase } from "../api/utils";
6
- import { findSavedKey, getConfig, useLogSnag, createSupabaseClient, verifyUser } from "../utils";
5
+ import { OptionsBase, findSavedKey, getConfig, useLogSnag, createSupabaseClient, verifyUser } from "../utils";
7
6
 
8
7
  export const deleteChannel = async (channelId: string, appId: string, options: OptionsBase) => {
9
8
  p.intro(`Delete channel`);
@@ -24,7 +23,7 @@ export const deleteChannel = async (channelId: string, appId: string, options: O
24
23
 
25
24
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
26
25
  // Check we have app access to this appId
27
- await checkAppExistsAndHasPermissionErr(supabase, appId);
26
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
28
27
 
29
28
  p.log.info(`Deleting channel ${appId}#${channelId} from Capgo`);
30
29
  try {
@@ -2,8 +2,7 @@ import { program } from 'commander';
2
2
  import * as p from '@clack/prompts';
3
3
  import { checkAppExistsAndHasPermissionErr } from '../api/app';
4
4
  import { getActiveChannels, displayChannels } from '../api/channels';
5
- import { OptionsBase } from '../api/utils';
6
- import { findSavedKey, getConfig, createSupabaseClient, verifyUser, useLogSnag } from '../utils';
5
+ import { OptionsBase, findSavedKey, getConfig, createSupabaseClient, verifyUser, useLogSnag } from '../utils';
7
6
 
8
7
  export const listChannels = async (appId: string, options: OptionsBase) => {
9
8
  p.intro(`List channels`);
@@ -23,13 +22,10 @@ export const listChannels = async (appId: string, options: OptionsBase) => {
23
22
 
24
23
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'read', 'upload']);
25
24
  // Check we have app access to this appId
26
- await checkAppExistsAndHasPermissionErr(supabase, appId);
25
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
27
26
 
28
27
  p.log.info(`Querying available channels in Capgo`);
29
28
 
30
- // Check we have app access to this appId
31
- await checkAppExistsAndHasPermissionErr(supabase, appId);
32
-
33
29
  // Get all active app versions we might possibly be able to cleanup
34
30
  const allVersions = await getActiveChannels(supabase, appId, userId);
35
31
 
@@ -1,9 +1,9 @@
1
1
  import { program } from 'commander';
2
2
  import * as p from '@clack/prompts';
3
3
  import { Database } from 'types/supabase.types';
4
- import { OptionsBase } from '../api/utils';
5
4
  import { checkAppExistsAndHasPermissionErr } from "../api/app";
6
5
  import {
6
+ OptionsBase,
7
7
  getConfig, createSupabaseClient, updateOrCreateChannel,
8
8
  formatError, findSavedKey, checkPlanValid, useLogSnag, verifyUser
9
9
  } from '../utils';
@@ -42,7 +42,7 @@ export const setChannel = async (channel: string, appId: string, options: Option
42
42
 
43
43
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all']);
44
44
  // Check we have app access to this appId
45
- await checkAppExistsAndHasPermissionErr(supabase, appId);
45
+ await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appId);
46
46
 
47
47
  const { bundle, latest, downgrade, upgrade, ios, android, selfAssign, state, disableAutoUpdate } = options;
48
48
  if (!channel) {
@@ -67,8 +67,6 @@ export const setChannel = async (channel: string, appId: string, options: Option
67
67
  }
68
68
  try {
69
69
  await checkPlanValid(supabase, userId)
70
- // Check we have app access to this appId
71
- await checkAppExistsAndHasPermissionErr(supabase, appId);
72
70
  const channelPayload: Database['public']['Tables']['channels']['Insert'] = {
73
71
  created_by: userId,
74
72
  app_id: appId,
package/src/login.ts CHANGED
@@ -16,7 +16,8 @@ export const login = async (apikey: string, options: Options, shouldExit = true)
16
16
  }
17
17
  if (!apikey) {
18
18
  if (shouldExit) {
19
- program.error("Missing API key, you need to provide a API key to upload your bundle");
19
+ p.log.error('Missing API key, you need to provide a API key to upload your bundle');
20
+ program.error('');
20
21
  }
21
22
  return false
22
23
  }