Skip to content

Commit 193d171

Browse files
committed
Merge branch 'master' of https://github.com/appwrite/sdk-generator into feat-kmp-sdk
2 parents 94f4042 + df18067 commit 193d171

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

src/SDK/Language/CLI.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ public function getFiles(): array
270270
'scope' => 'default',
271271
'destination' => 'lib/commands/generic.js',
272272
'template' => 'cli/lib/commands/generic.js.twig',
273+
],
274+
[
275+
'scope' => 'default',
276+
'destination' => 'lib/commands/organizations.js',
277+
'template' => 'cli/lib/commands/organizations.js.twig',
273278
]
274279
];
275280
}
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: 5 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,10 @@ 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 hostname = new URL(client.endpoint).hostname;
157+
const { teams } = hostname.endsWith('appwrite.io')
158+
? await paginate(organizationsList, { parseOutput: false, sdk: client }, 100, 'teams')
159+
: await paginate(teamsList, { parseOutput: false, sdk: client }, 100, 'teams');
156160

157161
let choices = teams.map((team, idx) => {
158162
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

templates/dart/lib/src/client_mixin.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class ClientMixin {
6262
(request as http.Request).body = jsonEncode(params);
6363
}
6464

65+
headers['User-Agent'] = Uri.encodeFull(headers['User-Agent'] ?? '');
66+
headers['X-Forwarded-User-Agent'] = Uri.encodeFull(headers['X-Forwarded-User-Agent'] ?? '');
67+
6568
request.headers.addAll(headers);
6669
return request;
6770
}

templates/flutter/lib/src/client_mixin.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class ClientMixin {
6262
(request as http.Request).body = jsonEncode(params);
6363
}
6464

65+
headers['User-Agent'] = Uri.encodeFull(headers['User-Agent'] ?? '');
66+
headers['X-Forwarded-User-Agent'] = Uri.encodeFull(headers['X-Forwarded-User-Agent'] ?? '');
67+
6568
request.headers.addAll(headers);
6669
return request;
6770
}

0 commit comments

Comments
 (0)