Skip to content

Commit 35f982f

Browse files
committed
chore: add listOrganizations to sdk-for-cli
1 parent 490d525 commit 35f982f

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { sdkForProject } = require('../sdks')
2+
const { parse } = require('../parser')
3+
const { showConsoleLink } = require('../utils.js');
4+
5+
/**
6+
* @typedef {Object} OrganizationsListRequestParams
7+
* @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
8+
* @property {string} search Search term to filter your list results. Max length: 256 chars.
9+
* @property {boolean} parseOutput
10+
* @property {libClient | undefined} sdk
11+
*/
12+
13+
/**
14+
* @param {OrganizationsListRequestParams} params
15+
*/
16+
const organizationsList = async ({queries, search, parseOutput = true, sdk = undefined, console}) => {
17+
let client = !sdk ? await sdkForProject() :
18+
sdk;
19+
let apiPath = '/organizations';
20+
let payload = {};
21+
if (typeof queries !== 'undefined') {
22+
payload['queries'] = queries;
23+
}
24+
if (typeof search !== 'undefined') {
25+
payload['search'] = search;
26+
}
27+
28+
let response = undefined;
29+
30+
response = await client.call('get', apiPath, {
31+
'content-type': 'application/json',
32+
}, payload);
33+
34+
if (parseOutput) {
35+
if(console) {
36+
showConsoleLink('organizations', 'list');
37+
} else {
38+
parse(response)
39+
}
40+
}
41+
42+
return response;
43+
44+
}
45+
46+
module.exports = {
47+
organizationsList
48+
}

templates/cli/lib/questions.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const chalk = require("chalk");
22
const Client = require("./client");
33
const { localConfig, globalConfig } = require('./config');
44
const { projectsList } = require('./commands/projects');
5+
const { organizationsList } = require('./commands/organizations');
56
const { teamsList } = require('./commands/teams');
67
const { functionsListRuntimes, functionsListSpecifications, functionsList } = require('./commands/functions');
78
const { accountListMfaFactors } = require("./commands/account");
@@ -152,7 +153,7 @@ const questionsInitProject = [
152153
message: "Choose your organization",
153154
choices: async () => {
154155
let client = await sdkForConsole(true);
155-
const { teams } = await paginate(teamsList, { parseOutput: false, sdk: client }, 100, 'teams');
156+
const { teams } = await paginate(organizationsList, { parseOutput: false, sdk: client }, 100, 'teams');
156157

157158
let choices = teams.map((team, idx) => {
158159
return {

templates/cli/lib/utils.js.twig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ function showConsoleLink(serviceName, action, ...ids) {
8989
case "teams":
9090
url.pathname += getTeamsPath(action, ids);
9191
break;
92+
case "organizations":
93+
url.pathname += getOrganizationsPath(action, ids);
94+
break;
9295
case "users":
9396
url.pathname += getUsersPath(action, ids);
9497
break;
@@ -241,6 +244,16 @@ function getTeamsPath(action, ids) {
241244
return path;
242245
}
243246

247+
function getOrganizationsPath(action, ids) {
248+
let path = `/organization-${ids[0]}`;
249+
250+
if (action === 'list') {
251+
path = '/account/organizations';
252+
}
253+
254+
return path;
255+
}
256+
244257
function getUsersPath(action, ids) {
245258
let path = '/auth';
246259

0 commit comments

Comments
 (0)