@capgo/cli 4.3.0 → 4.3.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [4.3.3](https://github.com/Cap-go/CLI/compare/v4.3.2...v4.3.3) (2024-04-16)
6
+
7
+ ### [4.3.2](https://github.com/Cap-go/CLI/compare/v4.3.1...v4.3.2) (2024-04-14)
8
+
9
+ ### [4.3.1](https://github.com/Cap-go/CLI/compare/v4.3.0...v4.3.1) (2024-04-14)
10
+
5
11
  ## [4.3.0](https://github.com/Cap-go/CLI/compare/v4.2.12...v4.3.0) (2024-03-31)
6
12
 
7
13
 
package/dist/index.js CHANGED
@@ -91634,7 +91634,7 @@ var {
91634
91634
  // package.json
91635
91635
  var package_default = {
91636
91636
  name: "@capgo/cli",
91637
- version: "4.3.0",
91637
+ version: "4.3.3",
91638
91638
  description: "A CLI to upload to capgo servers",
91639
91639
  main: "dist/index.js",
91640
91640
  bin: {
@@ -92884,16 +92884,16 @@ async function checkKey(supabase, apikey, keymode) {
92884
92884
  program.error("");
92885
92885
  }
92886
92886
  }
92887
- async function isPaying(supabase, userId) {
92888
- const { data } = await supabase.rpc("is_paying", { userid: userId }).single();
92887
+ async function isPayingOrg(supabase, orgId) {
92888
+ const { data } = await supabase.rpc("is_paying_org", { orgid: orgId }).single();
92889
92889
  return data || false;
92890
92890
  }
92891
- async function isTrial(supabase, userId) {
92892
- const { data } = await supabase.rpc("is_trial", { userid: userId }).single();
92891
+ async function isTrialOrg(supabase, orgId) {
92892
+ const { data } = await supabase.rpc("is_trial_org", { orgid: orgId }).single();
92893
92893
  return data || 0;
92894
92894
  }
92895
- async function isAllowedAction(supabase, userId) {
92896
- const { data } = await supabase.rpc("is_allowed_action_user", { userid: userId }).single();
92895
+ async function isAllowedActionOrg(supabase, orgId) {
92896
+ const { data } = await supabase.rpc("is_allowed_action_org", { orgid: orgId }).single();
92897
92897
  return !!data;
92898
92898
  }
92899
92899
  async function isAllowedActionAppIdApiKey(supabase, appId, apikey) {
@@ -92993,9 +92993,9 @@ async function isAllowedAppOrg(supabase, apikey, appId) {
92993
92993
  error: functionError
92994
92994
  };
92995
92995
  }
92996
- async function checkPlanValid(supabase, userId, apikey, appId, warning = true) {
92996
+ async function checkPlanValid(supabase, orgId, apikey, appId, warning = true) {
92997
92997
  const config = await getRemoteConfig();
92998
- const validPlan = await (appId ? isAllowedActionAppIdApiKey(supabase, appId, apikey) : isAllowedAction(supabase, userId));
92998
+ const validPlan = await (appId ? isAllowedActionAppIdApiKey(supabase, appId, apikey) : isAllowedActionOrg(supabase, orgId));
92999
92999
  if (!validPlan) {
93000
93000
  f2.error(`You need to upgrade your plan to continue to use capgo.
93001
93001
  Upgrade here: ${config.hostWeb}/dashboard/settings/plans
@@ -93007,8 +93007,10 @@ async function checkPlanValid(supabase, userId, apikey, appId, warning = true) {
93007
93007
  wait(500);
93008
93008
  program.error("");
93009
93009
  }
93010
- const trialDays = await isTrial(supabase, userId);
93011
- const ispaying = await isPaying(supabase, userId);
93010
+ const [trialDays, ispaying] = await Promise.all([
93011
+ isTrialOrg(supabase, orgId),
93012
+ isPayingOrg(supabase, orgId)
93013
+ ]);
93012
93014
  if (trialDays > 0 && warning && !ispaying)
93013
93015
  f2.warn(`WARNING !!
93014
93016
  Trial expires in ${trialDays} days, upgrade here: ${config.hostWeb}/dashboard/settings/plans
@@ -93119,6 +93121,15 @@ async function verifyUser(supabase, apikey, keymod = ["all"]) {
93119
93121
  }
93120
93122
  return userId;
93121
93123
  }
93124
+ async function getOrganizationId(supabase, appId) {
93125
+ const { data, error } = await supabase.from("apps").select("owner_org").eq("app_id", appId).single();
93126
+ if (!data || error) {
93127
+ f2.error(`Cannot get organization id for app id ${appId}`);
93128
+ formatError(error);
93129
+ program.error("");
93130
+ }
93131
+ return data.owner_org;
93132
+ }
93122
93133
  async function requireUpdateMetadata(supabase, channel2, appId) {
93123
93134
  const { data, error } = await supabase.from("channels").select("disableAutoUpdate").eq("name", channel2).eq("app_id", appId).limit(1);
93124
93135
  if (error) {
@@ -94011,7 +94022,8 @@ async function uploadBundle(appid, options, shouldExit = true) {
94011
94022
  const supabase = await createSupabaseClient(options.apikey);
94012
94023
  const userId = await verifyUser(supabase, options.apikey, ["write", "all", "upload"]);
94013
94024
  const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, 2 /* upload */);
94014
- await checkPlanValid(supabase, userId, options.apikey, appid, true);
94025
+ const orgId = await getOrganizationId(supabase, appid);
94026
+ await checkPlanValid(supabase, orgId, options.apikey, appid, true);
94015
94027
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel2, appid);
94016
94028
  const { data: channelData, error: channelError } = await supabase.from("channels").select("version ( minUpdateVersion, native_packages )").eq("name", channel2).eq("app_id", appid).single();
94017
94029
  let localDependencies = void 0;
@@ -94065,11 +94077,11 @@ async function uploadBundle(appid, options, shouldExit = true) {
94065
94077
  program.error("");
94066
94078
  }
94067
94079
  }
94068
- const { data: isTrial2, error: isTrialsError } = await supabase.rpc("is_trial", { userid: userId }).single();
94069
- if (isTrial2 && isTrial2 > 0 || isTrialsError) {
94080
+ const { data: isTrial, error: isTrialsError } = await supabase.rpc("is_trial_org", { orgid: orgId }).single();
94081
+ if (isTrial && isTrial > 0 || isTrialsError) {
94070
94082
  f2.warn(`WARNING !!
94071
- Trial expires in ${isTrial2} days`);
94072
- f2.warn(`Upgrade here: ${localConfig.hostWeb}/dashboard/settings/plans`);
94083
+ Trial expires in ${isTrial} days`);
94084
+ f2.warn(`Upgrade here: ${localConfig.hostWeb}/dashboard/settings/plans?oid=${orgId}`);
94073
94085
  }
94074
94086
  const { data: appVersion, error: appVersionError } = await supabase.rpc("exist_app_versions", { appid, apikey: options.apikey, name_version: bundle2 }).single();
94075
94087
  if (appVersion || appVersionError) {
@@ -94483,7 +94495,6 @@ async function addApp(appId, options, throwErr = true) {
94483
94495
  }
94484
94496
  const supabase = await createSupabaseClient(options.apikey);
94485
94497
  let userId = await verifyUser(supabase, options.apikey, ["write", "all"]);
94486
- await checkPlanValid(supabase, userId, options.apikey, void 0, false);
94487
94498
  const appExist = await checkAppExists(supabase, appId);
94488
94499
  if (throwErr && appExist) {
94489
94500
  f2.error(`App ${appId} already exist`);
@@ -94491,7 +94502,7 @@ async function addApp(appId, options, throwErr = true) {
94491
94502
  } else if (appExist) {
94492
94503
  return true;
94493
94504
  }
94494
- const { error: orgError, data: allOrganizations } = await supabase.rpc("get_orgs_v4");
94505
+ const { error: orgError, data: allOrganizations } = await supabase.rpc("get_orgs_v5");
94495
94506
  if (orgError) {
94496
94507
  f2.error("Cannot get the list of organizations - exiting");
94497
94508
  f2.error(`Error ${JSON.stringify(orgError)}`);
@@ -94512,6 +94523,7 @@ async function addApp(appId, options, throwErr = true) {
94512
94523
  const organization = allOrganizations.find((org) => org.gid === organizationUid);
94513
94524
  userId = organization.created_by;
94514
94525
  f2.info(`Using the organization "${organization.name}" as the app owner`);
94526
+ await checkPlanValid(supabase, organizationUid, options.apikey, void 0, false);
94515
94527
  let { name, icon } = options;
94516
94528
  appId = appId || config?.app?.appId;
94517
94529
  name = name || config?.app?.appName || "Unknown";
@@ -95173,6 +95185,7 @@ async function setChannel(channel2, appId, options) {
95173
95185
  const supabase = await createSupabaseClient(options.apikey);
95174
95186
  const userId = await verifyUser(supabase, options.apikey, ["write", "all"]);
95175
95187
  await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, 4 /* admin */);
95188
+ const orgId = await getOrganizationId(supabase, appId);
95176
95189
  const { bundle: bundle2, latest, downgrade, upgrade, ios, android, selfAssign, state, disableAutoUpdate } = options;
95177
95190
  if (!channel2) {
95178
95191
  f2.error("Missing argument, you need to provide a channel");
@@ -95187,7 +95200,7 @@ async function setChannel(channel2, appId, options) {
95187
95200
  program.error("");
95188
95201
  }
95189
95202
  try {
95190
- await checkPlanValid(supabase, userId, options.apikey, appId);
95203
+ await checkPlanValid(supabase, orgId, options.apikey, appId);
95191
95204
  const channelPayload = {
95192
95205
  created_by: userId,
95193
95206
  app_id: appId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "4.3.0",
3
+ "version": "4.3.3",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/app/add.ts CHANGED
@@ -39,8 +39,6 @@ export async function addApp(appId: string, options: Options, throwErr = true) {
39
39
 
40
40
  let userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
41
41
 
42
- await checkPlanValid(supabase, userId, options.apikey, undefined, false)
43
-
44
42
  // Check we have app access to this appId
45
43
  const appExist = await checkAppExists(supabase, appId)
46
44
  if (throwErr && appExist) {
@@ -52,7 +50,7 @@ export async function addApp(appId: string, options: Options, throwErr = true) {
52
50
  }
53
51
 
54
52
  const { error: orgError, data: allOrganizations } = await supabase
55
- .rpc('get_orgs_v4')
53
+ .rpc('get_orgs_v5')
56
54
 
57
55
  if (orgError) {
58
56
  p.log.error('Cannot get the list of organizations - exiting')
@@ -82,6 +80,8 @@ export async function addApp(appId: string, options: Options, throwErr = true) {
82
80
 
83
81
  p.log.info(`Using the organization "${organization.name}" as the app owner`)
84
82
 
83
+ await checkPlanValid(supabase, organizationUid, options.apikey, undefined, false)
84
+
85
85
  let { name, icon } = options
86
86
  appId = appId || config?.app?.appId
87
87
  name = name || config?.app?.appName || 'Unknown'
@@ -15,6 +15,7 @@ import {
15
15
  findSavedKey,
16
16
  formatError,
17
17
  getConfig,
18
+ getOrganizationId,
18
19
  useLogSnag,
19
20
  verifyUser,
20
21
  } from '../utils'
@@ -47,7 +48,11 @@ export async function unlinkDevice(channel: string, appId: string, options: Opti
47
48
  }
48
49
  const supabase = await createSupabaseClient(options.apikey)
49
50
 
50
- const userId = await verifyUser(supabase, options.apikey, ['all', 'write'])
51
+ const [userId, orgId] = await Promise.all([
52
+ verifyUser(supabase, options.apikey, ['all', 'write']),
53
+ getOrganizationId(supabase, appId),
54
+ ])
55
+
51
56
  // Check we have app access to this appId
52
57
  await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.write)
53
58
 
@@ -56,7 +61,7 @@ export async function unlinkDevice(channel: string, appId: string, options: Opti
56
61
  program.error('')
57
62
  }
58
63
  try {
59
- await checkPlanValid(supabase, userId, options.apikey, appId)
64
+ await checkPlanValid(supabase, orgId, options.apikey, appId)
60
65
 
61
66
  const versionData = await getVersionData(supabase, appId, bundle)
62
67
  await checkVersionNotUsedInChannel(supabase, appId, versionData)
@@ -32,6 +32,7 @@ import {
32
32
  getConfig,
33
33
  getLocalConfig,
34
34
  getLocalDepenencies,
35
+ getOrganizationId,
35
36
  hasOrganizationPerm,
36
37
  regexSemver,
37
38
  requireUpdateMetadata,
@@ -149,7 +150,10 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
149
150
  // await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
150
151
 
151
152
  const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, OrganizationPerm.upload)
152
- await checkPlanValid(supabase, userId, options.apikey, appid, true)
153
+
154
+ // Now if it does exist we will fetch the org id
155
+ const orgId = await getOrganizationId(supabase, appid)
156
+ await checkPlanValid(supabase, orgId, options.apikey, appid, true)
153
157
 
154
158
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel, appid)
155
159
 
@@ -227,11 +231,12 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
227
231
  }
228
232
 
229
233
  const { data: isTrial, error: isTrialsError } = await supabase
230
- .rpc('is_trial', { userid: userId })
234
+ .rpc('is_trial_org', { orgid: orgId })
231
235
  .single()
232
236
  if ((isTrial && isTrial > 0) || isTrialsError) {
237
+ // TODO: Come back to this to fix for orgs v3
233
238
  p.log.warn(`WARNING !!\nTrial expires in ${isTrial} days`)
234
- p.log.warn(`Upgrade here: ${localConfig.hostWeb}/dashboard/settings/plans`)
239
+ p.log.warn(`Upgrade here: ${localConfig.hostWeb}/dashboard/settings/plans?oid=${orgId}`)
235
240
  }
236
241
 
237
242
  // check if app already exist
@@ -13,6 +13,7 @@ import {
13
13
  findSavedKey,
14
14
  formatError,
15
15
  getConfig,
16
+ getOrganizationId,
16
17
  updateOrCreateChannel,
17
18
  useLogSnag,
18
19
  verifyUser,
@@ -53,6 +54,7 @@ export async function setChannel(channel: string, appId: string, options: Option
53
54
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
54
55
  // Check we have app access to this appId
55
56
  await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.admin)
57
+ const orgId = await getOrganizationId(supabase, appId)
56
58
 
57
59
  const { bundle, latest, downgrade, upgrade, ios, android, selfAssign, state, disableAutoUpdate } = options
58
60
  if (!channel) {
@@ -76,7 +78,7 @@ export async function setChannel(channel: string, appId: string, options: Option
76
78
  program.error('')
77
79
  }
78
80
  try {
79
- await checkPlanValid(supabase, userId, options.apikey, appId)
81
+ await checkPlanValid(supabase, orgId, options.apikey, appId)
80
82
  const channelPayload: Database['public']['Tables']['channels']['Insert'] = {
81
83
  created_by: userId,
82
84
  app_id: appId,