@capgo/cli 3.14.55 → 3.14.57

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "3.14.55",
3
+ "version": "3.14.57",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/api/app.ts CHANGED
@@ -2,7 +2,7 @@ import { SupabaseClient } from '@supabase/supabase-js';
2
2
  import * as p from '@clack/prompts';
3
3
  import { program } from 'commander';
4
4
  import { Database } from 'types/supabase.types';
5
- import { isAllowedApp, OptionsBase } from '../utils';
5
+ import { isAllowedApp, isAllowedAppOrg, OptionsBase, OrganizationPerm } from '../utils';
6
6
 
7
7
  export const checkAppExists = async (supabase: SupabaseClient<Database>, appid: string) => {
8
8
  const { data: app } = await supabase
@@ -30,6 +30,46 @@ export const checkAppExistsAndHasPermissionErr = async (supabase: SupabaseClient
30
30
  }
31
31
  }
32
32
 
33
+ export const checkAppExistsAndHasPermissionOrgErr = async (
34
+ supabase: SupabaseClient<Database>,
35
+ apikey: string,
36
+ appid: string,
37
+ requiredPermission: OrganizationPerm
38
+ ) => {
39
+ const permissions = await isAllowedAppOrg(supabase, apikey, appid)
40
+ if (!permissions.okay) {
41
+ // eslint-disable-next-line default-case
42
+ switch (permissions.error) {
43
+ case 'INVALID_APIKEY': {
44
+ p.log.error('Invalid apikey, such apikey does not exists!')
45
+ program.error('');
46
+ break
47
+ }
48
+ case 'NO_APP': {
49
+ p.log.error(`App ${appid} does not exist`);
50
+ program.error('');
51
+ break
52
+ }
53
+ case 'NO_ORG': {
54
+ p.log.error('Could not find organization, please contact support to resolve this!')
55
+ program.error('')
56
+ break
57
+ }
58
+ }
59
+ }
60
+
61
+ const remotePermNumber = permissions.data as number
62
+ const requiredPermNumber = requiredPermission as number
63
+
64
+ if (requiredPermNumber > remotePermNumber) {
65
+ // eslint-disable-next-line max-len
66
+ p.log.error(`Insuficcent permissions for app ${appid}. Current permission: ${OrganizationPerm[permissions.data]}, required for this action: ${OrganizationPerm[requiredPermission]}.`)
67
+ program.error('')
68
+ }
69
+
70
+ return permissions.data
71
+ }
72
+
33
73
  export interface Options extends OptionsBase {
34
74
  name?: string;
35
75
  icon?: string;
@@ -87,12 +87,12 @@ export const displayChannels = (data: (Database['public']['Tables']['channels'][
87
87
  p.log.success(t.render());
88
88
  }
89
89
 
90
- export const getActiveChannels = async (supabase: SupabaseClient<Database>, appid: string, userId: string) => {
90
+ export const getActiveChannels = async (supabase: SupabaseClient<Database>, appid: string) => {
91
91
  const { data, error: vError } = await supabase
92
92
  .from('channels')
93
93
  .select()
94
94
  .eq('app_id', appid)
95
- .eq('created_by', userId)
95
+ // .eq('created_by', userId)
96
96
  .order('created_at', { ascending: false });
97
97
 
98
98
  if (vError) {
package/src/app/list.ts CHANGED
@@ -24,11 +24,11 @@ const displayApp = (data: Database['public']['Tables']['apps']['Row'][]) => {
24
24
  p.log.success(t.render());
25
25
  }
26
26
 
27
- export const getActiveApps = async (supabase: SupabaseClient<Database>, userId: string) => {
27
+ export const getActiveApps = async (supabase: SupabaseClient<Database>) => {
28
28
  const { data, error: vError } = await supabase
29
29
  .from('apps')
30
30
  .select()
31
- .eq('user_id', userId)
31
+ // .eq('user_id', userId)
32
32
  .order('created_at', { ascending: false });
33
33
 
34
34
  if (vError) {
@@ -46,12 +46,12 @@ export const listApp = async (options: OptionsBase) => {
46
46
 
47
47
  const supabase = await createSupabaseClient(options.apikey)
48
48
 
49
- const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'read', 'upload']);
49
+ await verifyUser(supabase, options.apikey, ['write', 'all', 'read', 'upload']);
50
50
 
51
51
  p.log.info(`Getting active bundle in Capgo`);
52
52
 
53
53
  // Get all active app versions we might possibly be able to cleanup
54
- const allApps = await getActiveApps(supabase, userId);
54
+ const allApps = await getActiveApps(supabase);
55
55
 
56
56
  p.log.info(`Active app in Capgo: ${allApps?.length}`);
57
57
 
@@ -7,7 +7,7 @@ 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 { checkAppExistsAndHasPermissionErr } from "../api/app";
10
+ import { checkAppExistsAndHasPermissionOrgErr } from "../api/app";
11
11
  import { encryptSource } from '../api/crypto';
12
12
  import {
13
13
  OptionsBase,
@@ -15,8 +15,11 @@ import {
15
15
  uploadUrl,
16
16
  updateOrCreateChannel, updateOrCreateVersion,
17
17
  formatError, findSavedKey, checkPlanValid,
18
- useLogSnag, verifyUser, regexSemver, baseKeyPub, convertAppName, getLocalConfig, checkCompatibility, requireUpdateMetadata,
19
- getLocalDepenencies
18
+ useLogSnag, regexSemver, baseKeyPub, convertAppName, getLocalConfig, checkCompatibility, requireUpdateMetadata,
19
+ getLocalDepenencies,
20
+ verifyUser,
21
+ OrganizationPerm,
22
+ hasOrganizationPerm
20
23
  } from '../utils';
21
24
  import { checkIndexPosition, searchInDirectory } from './check';
22
25
 
@@ -99,7 +102,9 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
99
102
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'upload']);
100
103
  await checkPlanValid(supabase, userId, false)
101
104
  // Check we have app access to this appId
102
- await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
105
+ // await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
106
+
107
+ const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, OrganizationPerm.upload)
103
108
 
104
109
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel)
105
110
 
@@ -334,7 +339,8 @@ It will be also visible in your dashboard\n`);
334
339
  const { data: versionId } = await supabase
335
340
  .rpc('get_app_versions', { apikey: options.apikey, name_version: bundle, appid })
336
341
  .single()
337
- if (versionId) {
342
+
343
+ if (versionId && hasOrganizationPerm(permissions, OrganizationPerm.write)) {
338
344
  const { error: dbError3, data } = await updateOrCreateChannel(supabase, {
339
345
  name: channel,
340
346
  app_id: appid,
@@ -356,9 +362,11 @@ It will be also visible in your dashboard\n`);
356
362
  if(options.bundleUrl) {
357
363
  p.log.info(`Bundle url: ${bundleUrl}`);
358
364
  }
359
- } else {
365
+ } else if (!versionId) {
360
366
  p.log.warn('Cannot set bundle with upload key, use key with more rights for that');
361
367
  program.error('');
368
+ } else if (!hasOrganizationPerm(permissions, OrganizationPerm.write)) {
369
+ p.log.warn('Cannot set channel as a upload organization member')
362
370
  }
363
371
  await snag.track({
364
372
  channel: 'app',
@@ -27,7 +27,7 @@ export const listChannels = async (appId: string, options: OptionsBase) => {
27
27
  p.log.info(`Querying available channels in Capgo`);
28
28
 
29
29
  // Get all active app versions we might possibly be able to cleanup
30
- const allVersions = await getActiveChannels(supabase, appId, userId);
30
+ const allVersions = await getActiveChannels(supabase, appId);
31
31
 
32
32
  p.log.info(`Active channels in Capgo: ${allVersions?.length}`);
33
33