Skip to content

Commit

Permalink
chore: add listOrganizations to sdk-for-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiragAgg5k committed Feb 24, 2025
1 parent 490d525 commit 35f982f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
48 changes: 48 additions & 0 deletions templates/cli/lib/commands/organizations.js.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { sdkForProject } = require('../sdks')
const { parse } = require('../parser')
const { showConsoleLink } = require('../utils.js');

/**
* @typedef {Object} OrganizationsListRequestParams
* @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan
* @property {string} search Search term to filter your list results. Max length: 256 chars.
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
*/

/**
* @param {OrganizationsListRequestParams} params
*/
const organizationsList = async ({queries, search, parseOutput = true, sdk = undefined, console}) => {
let client = !sdk ? await sdkForProject() :
sdk;
let apiPath = '/organizations';
let payload = {};
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
if (typeof search !== 'undefined') {
payload['search'] = search;
}

let response = undefined;

response = await client.call('get', apiPath, {
'content-type': 'application/json',
}, payload);

if (parseOutput) {
if(console) {
showConsoleLink('organizations', 'list');
} else {
parse(response)
}
}

return response;

}

module.exports = {
organizationsList
}
3 changes: 2 additions & 1 deletion templates/cli/lib/questions.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const chalk = require("chalk");
const Client = require("./client");
const { localConfig, globalConfig } = require('./config');
const { projectsList } = require('./commands/projects');
const { organizationsList } = require('./commands/organizations');
const { teamsList } = require('./commands/teams');
const { functionsListRuntimes, functionsListSpecifications, functionsList } = require('./commands/functions');
const { accountListMfaFactors } = require("./commands/account");
Expand Down Expand Up @@ -152,7 +153,7 @@ const questionsInitProject = [
message: "Choose your organization",
choices: async () => {
let client = await sdkForConsole(true);
const { teams } = await paginate(teamsList, { parseOutput: false, sdk: client }, 100, 'teams');
const { teams } = await paginate(organizationsList, { parseOutput: false, sdk: client }, 100, 'teams');

let choices = teams.map((team, idx) => {
return {
Expand Down
13 changes: 13 additions & 0 deletions templates/cli/lib/utils.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function showConsoleLink(serviceName, action, ...ids) {
case "teams":
url.pathname += getTeamsPath(action, ids);
break;
case "organizations":
url.pathname += getOrganizationsPath(action, ids);
break;
case "users":
url.pathname += getUsersPath(action, ids);
break;
Expand Down Expand Up @@ -241,6 +244,16 @@ function getTeamsPath(action, ids) {
return path;
}

function getOrganizationsPath(action, ids) {
let path = `/organization-${ids[0]}`;

if (action === 'list') {
path = '/account/organizations';
}

return path;
}

function getUsersPath(action, ids) {
let path = '/auth';

Expand Down

0 comments on commit 35f982f

Please sign in to comment.