From 13312b5463dd8dd136cb2f319f570186cae86b3d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 3 Jul 2024 17:12:48 +0200 Subject: [PATCH 01/18] feat: 1.6.x preview --- README.md | 4 +- docs/examples/functions/create-build.md | 2 +- docs/examples/functions/create-execution.md | 1 + docs/examples/functions/create.md | 1 + docs/examples/functions/delete-execution.md | 3 + .../functions/update-deployment-build.md | 3 + docs/examples/functions/update.md | 1 + docs/examples/projects/create-j-w-t.md | 4 + docs/examples/projects/update-mock-numbers.md | 3 + .../projects/update-session-alerts.md | 3 + docs/examples/users/create-j-w-t.md | 4 + docs/examples/vcs/get-repository-contents.md | 4 + index.js | 41 +- install.ps1 | 2 +- install.sh | 2 +- lib/client.js | 16 +- lib/commands/account.js | 458 +++-- lib/commands/assistant.js | 13 +- lib/commands/avatars.js | 172 +- lib/commands/console.js | 13 +- lib/commands/databases.js | 517 ++++-- lib/commands/deploy.js | 940 ---------- lib/commands/functions.js | 410 +++-- lib/commands/generic.js | 260 ++- lib/commands/graphql.js | 22 +- lib/commands/health.js | 211 ++- lib/commands/init.js | 405 +++-- lib/commands/locale.js | 76 +- lib/commands/messaging.js | 490 ++++-- lib/commands/migrations.js | 148 +- lib/commands/project.js | 58 +- lib/commands/projects.js | 593 +++++-- lib/commands/proxy.js | 49 +- lib/commands/pull.js | 231 +++ lib/commands/push.js | 1518 +++++++++++++++++ lib/commands/run.js | 282 +++ lib/commands/storage.js | 236 ++- lib/commands/teams.js | 152 +- lib/commands/users.js | 458 +++-- lib/commands/vcs.js | 131 +- lib/config.js | 208 ++- lib/emulation/docker.js | 187 ++ lib/emulation/utils.js | 177 ++ lib/id.js | 30 + lib/paginate.js | 3 +- lib/parser.js | 81 +- lib/questions.js | 532 +++++- lib/sdks.js | 2 +- lib/spinner.js | 103 ++ lib/utils.js | 246 ++- lib/validations.js | 17 + package.json | 6 +- 52 files changed, 6984 insertions(+), 2545 deletions(-) create mode 100644 docs/examples/functions/delete-execution.md create mode 100644 docs/examples/functions/update-deployment-build.md create mode 100644 docs/examples/projects/create-j-w-t.md create mode 100644 docs/examples/projects/update-mock-numbers.md create mode 100644 docs/examples/projects/update-session-alerts.md create mode 100644 docs/examples/users/create-j-w-t.md create mode 100644 docs/examples/vcs/get-repository-contents.md delete mode 100644 lib/commands/deploy.js create mode 100644 lib/commands/pull.js create mode 100644 lib/commands/push.js create mode 100644 lib/commands/run.js create mode 100644 lib/emulation/docker.js create mode 100644 lib/emulation/utils.js create mode 100644 lib/id.js create mode 100644 lib/spinner.js create mode 100644 lib/validations.js diff --git a/README.md b/README.md index c9568fb..883bc89 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite Command Line SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.5.6-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.7-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.5.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** +**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/functions/create-build.md b/docs/examples/functions/create-build.md index 98d087b..5a99f7a 100644 --- a/docs/examples/functions/create-build.md +++ b/docs/examples/functions/create-build.md @@ -1,4 +1,4 @@ appwrite functions createBuild \ --functionId \ --deploymentId \ - --buildId + diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 1efb701..febe88c 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -5,3 +5,4 @@ appwrite functions createExecution \ + diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index cfc3c9c..c75658e 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -19,3 +19,4 @@ appwrite functions create \ + diff --git a/docs/examples/functions/delete-execution.md b/docs/examples/functions/delete-execution.md new file mode 100644 index 0000000..2926b5a --- /dev/null +++ b/docs/examples/functions/delete-execution.md @@ -0,0 +1,3 @@ +appwrite functions deleteExecution \ + --functionId \ + --executionId diff --git a/docs/examples/functions/update-deployment-build.md b/docs/examples/functions/update-deployment-build.md new file mode 100644 index 0000000..ddaf1e5 --- /dev/null +++ b/docs/examples/functions/update-deployment-build.md @@ -0,0 +1,3 @@ +appwrite functions updateDeploymentBuild \ + --functionId \ + --deploymentId diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 6f42584..8bad859 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -15,3 +15,4 @@ appwrite functions update \ + diff --git a/docs/examples/projects/create-j-w-t.md b/docs/examples/projects/create-j-w-t.md new file mode 100644 index 0000000..d703d36 --- /dev/null +++ b/docs/examples/projects/create-j-w-t.md @@ -0,0 +1,4 @@ +appwrite projects createJWT \ + --projectId \ + --scopes one two three \ + diff --git a/docs/examples/projects/update-mock-numbers.md b/docs/examples/projects/update-mock-numbers.md new file mode 100644 index 0000000..733cc16 --- /dev/null +++ b/docs/examples/projects/update-mock-numbers.md @@ -0,0 +1,3 @@ +appwrite projects updateMockNumbers \ + --projectId \ + --numbers one two three diff --git a/docs/examples/projects/update-session-alerts.md b/docs/examples/projects/update-session-alerts.md new file mode 100644 index 0000000..bd23b74 --- /dev/null +++ b/docs/examples/projects/update-session-alerts.md @@ -0,0 +1,3 @@ +appwrite projects updateSessionAlerts \ + --projectId \ + --alerts false diff --git a/docs/examples/users/create-j-w-t.md b/docs/examples/users/create-j-w-t.md new file mode 100644 index 0000000..220086b --- /dev/null +++ b/docs/examples/users/create-j-w-t.md @@ -0,0 +1,4 @@ +appwrite users createJWT \ + --userId \ + + diff --git a/docs/examples/vcs/get-repository-contents.md b/docs/examples/vcs/get-repository-contents.md new file mode 100644 index 0000000..7d378d7 --- /dev/null +++ b/docs/examples/vcs/get-repository-contents.md @@ -0,0 +1,4 @@ +appwrite vcs getRepositoryContents \ + --installationId \ + --providerRepositoryId \ + diff --git a/index.js b/index.js index 630b9b1..a1db573 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,12 @@ const chalk = require("chalk"); const { version } = require("./package.json"); const { commandDescriptions, cliConfig } = require("./lib/parser"); const { client } = require("./lib/commands/generic"); -const { login, logout } = require("./lib/commands/generic"); +const inquirer = require("inquirer"); +const { login, logout, whoami, migrate, register } = require("./lib/commands/generic"); const { init } = require("./lib/commands/init"); -const { deploy } = require("./lib/commands/deploy"); +const { pull } = require("./lib/commands/pull"); +const { run } = require("./lib/commands/run"); +const { push } = require("./lib/commands/push"); const { account } = require("./lib/commands/account"); const { avatars } = require("./lib/commands/avatars"); const { assistant } = require("./lib/commands/assistant"); @@ -32,6 +35,8 @@ const { teams } = require("./lib/commands/teams"); const { users } = require("./lib/commands/users"); const { vcs } = require("./lib/commands/vcs"); +inquirer.registerPrompt('search-list', require('inquirer-search-list')); + program .description(commandDescriptions['main']) .configureHelp({ @@ -39,18 +44,40 @@ program sortSubcommands: true }) .version(version, "-v, --version") - .option("--verbose", "Show complete error log") - .option("--json", "Output in JSON format") + .option("-V, --verbose", "Show complete error log") + .option("-j, --json", "Output in JSON format") + .hook('preAction', migrate) + .option("-f,--force", "Flag to confirm all warnings") + .option("-a,--all", "Flag to push all resources") + .option("--id [id...]", "Flag to pass list of ids for a giving action") + .option("--report", "Enable reporting in case of CLI errors") .on("option:json", () => { cliConfig.json = true; }) .on("option:verbose", () => { cliConfig.verbose = true; }) + .on("option:report", function() { + cliConfig.report = true; + cliConfig.reportData = { data: this }; + }) + .on("option:force", () => { + cliConfig.force = true; + }) + .on("option:all", () => { + cliConfig.all = true; + }) + .on("option:id", function() { + cliConfig.ids = this.opts().id; + }) .showSuggestionAfterError() + .addCommand(whoami) + .addCommand(register) .addCommand(login) .addCommand(init) - .addCommand(deploy) + .addCommand(pull) + .addCommand(push) + .addCommand(run) .addCommand(logout) .addCommand(account) .addCommand(avatars) @@ -72,5 +99,5 @@ program .addCommand(vcs) .addCommand(client) .parse(process.argv); - -process.stdout.columns = oldWidth; \ No newline at end of file + +process.stdout.columns = oldWidth; diff --git a/install.ps1 b/install.ps1 index 0c9310b..14ad4a8 100644 --- a/install.ps1 +++ b/install.ps1 @@ -85,8 +85,8 @@ function CleanUp { function InstallCompleted { Write-Host "[4/4] Finishing Installation ... " cleanup - Write-Host "🤘 May the force be with you." Write-Host "To get started with Appwrite CLI, please visit https://appwrite.io/docs/command-line" + Write-Host "As first step, you can login to your Appwrite account using 'appwrite login'" } diff --git a/install.sh b/install.sh index 70f8948..b870292 100644 --- a/install.sh +++ b/install.sh @@ -145,8 +145,8 @@ cleanup() { installCompleted() { echo "[4/4] Wrapping up installation ... " cleanup - printf "🤘 May the force be with you. \n" echo "🚀 To get started with Appwrite CLI, please visit https://appwrite.io/docs/command-line" + echo "As first step, you can login to your Appwrite account using 'appwrite login'" } # Installation Starts here diff --git a/lib/client.js b/lib/client.js index 1fd7c26..81e827f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -4,10 +4,11 @@ const { fetch, FormData, Agent } = require("undici"); const JSONbig = require("json-bigint")({ storeAsString: false }); const AppwriteException = require("./exception.js"); const { globalConfig } = require("./config.js"); +const chalk = require("chalk"); class Client { CHUNK_SIZE = 5*1024*1024; // 5MB - + constructor() { this.endpoint = 'https://cloud.appwrite.io/v1'; this.headers = { @@ -182,6 +183,11 @@ class Client { }, }), }); + + const warnings = response.headers.get('x-appwrite-warning'); + if (warnings) { + warnings.split(';').forEach((warning) => console.warn(warning)); + } } catch (error) { throw new AppwriteException(error.message); } @@ -194,6 +200,14 @@ class Client { } catch (error) { throw new AppwriteException(text, response.status, "", text); } + + if (path !== '/account' && json.code === 401 && json.type === 'user_more_factors_required') { + console.log(`${chalk.cyan.bold("ℹ Info")} ${chalk.cyan("Unusable account found, removing...")}`); + + const current = globalConfig.getCurrentSession(); + globalConfig.setCurrentSession(''); + globalConfig.removeSession(current); + } throw new AppwriteException(json.message, json.code, json.type, json); } diff --git a/lib/commands/account.js b/lib/commands/account.js index d6f07c6..1de3c98 100644 --- a/lib/commands/account.js +++ b/lib/commands/account.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -41,6 +41,7 @@ const account = new Command("account").description(commandDescriptions['account' /** * @typedef {Object} AccountGetRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -48,8 +49,9 @@ const account = new Command("account").description(commandDescriptions['account' /** * @param {AccountGetRequestParams} params */ -const accountGet = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountGet = async ({parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account'; let payload = {}; @@ -60,11 +62,16 @@ const accountGet = async ({ parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('account', 'get'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -73,6 +80,7 @@ const accountGet = async ({ parseOutput = true, sdk = undefined}) => { * @property {string} email User email. * @property {string} password New user password. Must be between 8 and 256 chars. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -80,8 +88,9 @@ const accountGet = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountCreateRequestParams} params */ -const accountCreate = async ({ userId, email, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreate = async ({userId,email,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account'; let payload = {}; if (typeof userId !== 'undefined') { @@ -107,12 +116,14 @@ const accountCreate = async ({ userId, email, password, name, parseOutput = true parse(response) success() } - + return response; + } /** * @typedef {Object} AccountDeleteRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -120,8 +131,9 @@ const accountCreate = async ({ userId, email, password, name, parseOutput = true /** * @param {AccountDeleteRequestParams} params */ -const accountDelete = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDelete = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account'; let payload = {}; @@ -135,14 +147,16 @@ const accountDelete = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateEmailRequestParams * @property {string} email User email. * @property {string} password User password. Must be at least 8 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -150,8 +164,9 @@ const accountDelete = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountUpdateEmailRequestParams} params */ -const accountUpdateEmail = async ({ email, password, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateEmail = async ({email,password,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/email'; let payload = {}; if (typeof email !== 'undefined') { @@ -171,13 +186,15 @@ const accountUpdateEmail = async ({ email, password, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} AccountListIdentitiesRequestParams * @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: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -185,8 +202,9 @@ const accountUpdateEmail = async ({ email, password, parseOutput = true, sdk = u /** * @param {AccountListIdentitiesRequestParams} params */ -const accountListIdentities = async ({ queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountListIdentities = async ({queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/identities'; let payload = {}; if (typeof queries !== 'undefined') { @@ -203,13 +221,15 @@ const accountListIdentities = async ({ queries, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} AccountDeleteIdentityRequestParams * @property {string} identityId Identity ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -217,8 +237,9 @@ const accountListIdentities = async ({ queries, parseOutput = true, sdk = undefi /** * @param {AccountDeleteIdentityRequestParams} params */ -const accountDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDeleteIdentity = async ({identityId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId); let payload = {}; @@ -232,12 +253,14 @@ const accountDeleteIdentity = async ({ identityId, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateJWTRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -245,9 +268,10 @@ const accountDeleteIdentity = async ({ identityId, parseOutput = true, sdk = und /** * @param {AccountCreateJWTRequestParams} params */ -const accountCreateJWT = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; - let apiPath = '/account/jwt'; +const accountCreateJWT = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/account/jwts'; let payload = {}; let response = undefined; @@ -260,13 +284,15 @@ const accountCreateJWT = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} AccountListLogsRequestParams * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -274,8 +300,9 @@ const accountCreateJWT = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountListLogsRequestParams} params */ -const accountListLogs = async ({ queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountListLogs = async ({queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/logs'; let payload = {}; if (typeof queries !== 'undefined') { @@ -292,13 +319,15 @@ const accountListLogs = async ({ queries, parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateMFARequestParams * @property {boolean} mfa Enable or disable MFA. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -306,8 +335,9 @@ const accountListLogs = async ({ queries, parseOutput = true, sdk = undefined}) /** * @param {AccountUpdateMFARequestParams} params */ -const accountUpdateMFA = async ({ mfa, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateMFA = async ({mfa,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa'; let payload = {}; if (typeof mfa !== 'undefined') { @@ -324,13 +354,15 @@ const accountUpdateMFA = async ({ mfa, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateMfaAuthenticatorRequestParams * @property {AuthenticatorType} type Type of authenticator. Must be 'totp' + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -338,8 +370,9 @@ const accountUpdateMFA = async ({ mfa, parseOutput = true, sdk = undefined}) => /** * @param {AccountCreateMfaAuthenticatorRequestParams} params */ -const accountCreateMfaAuthenticator = async ({ type, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateMfaAuthenticator = async ({type,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); let payload = {}; @@ -353,14 +386,16 @@ const accountCreateMfaAuthenticator = async ({ type, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateMfaAuthenticatorRequestParams * @property {AuthenticatorType} type Type of authenticator. * @property {string} otp Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -368,8 +403,9 @@ const accountCreateMfaAuthenticator = async ({ type, parseOutput = true, sdk = u /** * @param {AccountUpdateMfaAuthenticatorRequestParams} params */ -const accountUpdateMfaAuthenticator = async ({ type, otp, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateMfaAuthenticator = async ({type,otp,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); let payload = {}; if (typeof otp !== 'undefined') { @@ -386,14 +422,16 @@ const accountUpdateMfaAuthenticator = async ({ type, otp, parseOutput = true, sd parse(response) success() } - + return response; + } /** * @typedef {Object} AccountDeleteMfaAuthenticatorRequestParams * @property {AuthenticatorType} type Type of authenticator. * @property {string} otp Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -401,8 +439,9 @@ const accountUpdateMfaAuthenticator = async ({ type, otp, parseOutput = true, sd /** * @param {AccountDeleteMfaAuthenticatorRequestParams} params */ -const accountDeleteMfaAuthenticator = async ({ type, otp, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDeleteMfaAuthenticator = async ({type,otp,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); let payload = {}; if (typeof otp !== 'undefined') { @@ -419,13 +458,15 @@ const accountDeleteMfaAuthenticator = async ({ type, otp, parseOutput = true, sd parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateMfaChallengeRequestParams * @property {AuthenticationFactor} factor Factor used for verification. Must be one of following: 'email', 'phone', 'totp', 'recoveryCode'. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -433,8 +474,9 @@ const accountDeleteMfaAuthenticator = async ({ type, otp, parseOutput = true, sd /** * @param {AccountCreateMfaChallengeRequestParams} params */ -const accountCreateMfaChallenge = async ({ factor, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateMfaChallenge = async ({factor,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/challenge'; let payload = {}; if (typeof factor !== 'undefined') { @@ -451,14 +493,16 @@ const accountCreateMfaChallenge = async ({ factor, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateMfaChallengeRequestParams * @property {string} challengeId ID of the challenge. * @property {string} otp Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -466,8 +510,9 @@ const accountCreateMfaChallenge = async ({ factor, parseOutput = true, sdk = und /** * @param {AccountUpdateMfaChallengeRequestParams} params */ -const accountUpdateMfaChallenge = async ({ challengeId, otp, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateMfaChallenge = async ({challengeId,otp,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/challenge'; let payload = {}; if (typeof challengeId !== 'undefined') { @@ -487,12 +532,14 @@ const accountUpdateMfaChallenge = async ({ challengeId, otp, parseOutput = true, parse(response) success() } - + return response; + } /** * @typedef {Object} AccountListMfaFactorsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -500,8 +547,9 @@ const accountUpdateMfaChallenge = async ({ challengeId, otp, parseOutput = true, /** * @param {AccountListMfaFactorsRequestParams} params */ -const accountListMfaFactors = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountListMfaFactors = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/factors'; let payload = {}; @@ -515,12 +563,14 @@ const accountListMfaFactors = async ({ parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} AccountGetMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -528,8 +578,9 @@ const accountListMfaFactors = async ({ parseOutput = true, sdk = undefined}) => /** * @param {AccountGetMfaRecoveryCodesRequestParams} params */ -const accountGetMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountGetMfaRecoveryCodes = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/recovery-codes'; let payload = {}; @@ -543,12 +594,14 @@ const accountGetMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined} parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -556,8 +609,9 @@ const accountGetMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined} /** * @param {AccountCreateMfaRecoveryCodesRequestParams} params */ -const accountCreateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateMfaRecoveryCodes = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/recovery-codes'; let payload = {}; @@ -571,12 +625,14 @@ const accountCreateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -584,8 +640,9 @@ const accountCreateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin /** * @param {AccountUpdateMfaRecoveryCodesRequestParams} params */ -const accountUpdateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateMfaRecoveryCodes = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/mfa/recovery-codes'; let payload = {}; @@ -599,13 +656,15 @@ const accountUpdateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateNameRequestParams * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -613,8 +672,9 @@ const accountUpdateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin /** * @param {AccountUpdateNameRequestParams} params */ -const accountUpdateName = async ({ name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateName = async ({name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/name'; let payload = {}; if (typeof name !== 'undefined') { @@ -631,14 +691,16 @@ const accountUpdateName = async ({ name, parseOutput = true, sdk = undefined}) = parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePasswordRequestParams * @property {string} password New user password. Must be at least 8 chars. * @property {string} oldPassword Current user password. Must be at least 8 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -646,8 +708,9 @@ const accountUpdateName = async ({ name, parseOutput = true, sdk = undefined}) = /** * @param {AccountUpdatePasswordRequestParams} params */ -const accountUpdatePassword = async ({ password, oldPassword, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePassword = async ({password,oldPassword,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/password'; let payload = {}; if (typeof password !== 'undefined') { @@ -667,14 +730,16 @@ const accountUpdatePassword = async ({ password, oldPassword, parseOutput = true parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePhoneRequestParams * @property {string} phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. * @property {string} password User password. Must be at least 8 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -682,8 +747,9 @@ const accountUpdatePassword = async ({ password, oldPassword, parseOutput = true /** * @param {AccountUpdatePhoneRequestParams} params */ -const accountUpdatePhone = async ({ phone, password, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePhone = async ({phone,password,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/phone'; let payload = {}; if (typeof phone !== 'undefined') { @@ -703,12 +769,14 @@ const accountUpdatePhone = async ({ phone, password, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} AccountGetPrefsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -716,8 +784,9 @@ const accountUpdatePhone = async ({ phone, password, parseOutput = true, sdk = u /** * @param {AccountGetPrefsRequestParams} params */ -const accountGetPrefs = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountGetPrefs = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/prefs'; let payload = {}; @@ -731,13 +800,15 @@ const accountGetPrefs = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePrefsRequestParams * @property {object} prefs Prefs key-value JSON object. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -745,8 +816,9 @@ const accountGetPrefs = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountUpdatePrefsRequestParams} params */ -const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePrefs = async ({prefs,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/prefs'; let payload = {}; if (typeof prefs !== 'undefined') { @@ -763,14 +835,16 @@ const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateRecoveryRequestParams * @property {string} email User email. * @property {string} url URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -778,8 +852,9 @@ const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined}) /** * @param {AccountCreateRecoveryRequestParams} params */ -const accountCreateRecovery = async ({ email, url, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateRecovery = async ({email,url,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/recovery'; let payload = {}; if (typeof email !== 'undefined') { @@ -799,8 +874,9 @@ const accountCreateRecovery = async ({ email, url, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** @@ -808,6 +884,7 @@ const accountCreateRecovery = async ({ email, url, parseOutput = true, sdk = und * @property {string} userId User ID. * @property {string} secret Valid reset token. * @property {string} password New user password. Must be between 8 and 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -815,8 +892,9 @@ const accountCreateRecovery = async ({ email, url, parseOutput = true, sdk = und /** * @param {AccountUpdateRecoveryRequestParams} params */ -const accountUpdateRecovery = async ({ userId, secret, password, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateRecovery = async ({userId,secret,password,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/recovery'; let payload = {}; if (typeof userId !== 'undefined') { @@ -839,12 +917,14 @@ const accountUpdateRecovery = async ({ userId, secret, password, parseOutput = t parse(response) success() } - + return response; + } /** * @typedef {Object} AccountListSessionsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -852,8 +932,9 @@ const accountUpdateRecovery = async ({ userId, secret, password, parseOutput = t /** * @param {AccountListSessionsRequestParams} params */ -const accountListSessions = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountListSessions = async ({parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions'; let payload = {}; @@ -864,15 +945,21 @@ const accountListSessions = async ({ parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('account', 'listSessions'); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} AccountDeleteSessionsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -880,8 +967,9 @@ const accountListSessions = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountDeleteSessionsRequestParams} params */ -const accountDeleteSessions = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDeleteSessions = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions'; let payload = {}; @@ -895,12 +983,14 @@ const accountDeleteSessions = async ({ parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateAnonymousSessionRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -908,8 +998,9 @@ const accountDeleteSessions = async ({ parseOutput = true, sdk = undefined}) => /** * @param {AccountCreateAnonymousSessionRequestParams} params */ -const accountCreateAnonymousSession = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateAnonymousSession = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/anonymous'; let payload = {}; @@ -923,14 +1014,16 @@ const accountCreateAnonymousSession = async ({ parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateEmailPasswordSessionRequestParams * @property {string} email User email. * @property {string} password User password. Must be at least 8 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -938,8 +1031,9 @@ const accountCreateAnonymousSession = async ({ parseOutput = true, sdk = undefin /** * @param {AccountCreateEmailPasswordSessionRequestParams} params */ -const accountCreateEmailPasswordSession = async ({ email, password, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateEmailPasswordSession = async ({email,password,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/email'; let payload = {}; if (typeof email !== 'undefined') { @@ -959,14 +1053,16 @@ const accountCreateEmailPasswordSession = async ({ email, password, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateMagicURLSessionRequestParams * @property {string} userId User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} secret Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -974,8 +1070,9 @@ const accountCreateEmailPasswordSession = async ({ email, password, parseOutput /** * @param {AccountUpdateMagicURLSessionRequestParams} params */ -const accountUpdateMagicURLSession = async ({ userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateMagicURLSession = async ({userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/magic-url'; let payload = {}; if (typeof userId !== 'undefined') { @@ -995,8 +1092,9 @@ const accountUpdateMagicURLSession = async ({ userId, secret, parseOutput = true parse(response) success() } - + return response; + } /** @@ -1005,6 +1103,7 @@ const accountUpdateMagicURLSession = async ({ userId, secret, parseOutput = true * @property {string} success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {string} failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {string[]} scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1012,8 +1111,9 @@ const accountUpdateMagicURLSession = async ({ userId, secret, parseOutput = true /** * @param {AccountCreateOAuth2SessionRequestParams} params */ -const accountCreateOAuth2Session = async ({ provider, success, failure, scopes, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateOAuth2Session = async ({provider,success,failure,scopes,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider); let payload = {}; if (typeof success !== 'undefined') { @@ -1036,14 +1136,16 @@ const accountCreateOAuth2Session = async ({ provider, success, failure, scopes, parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePhoneSessionRequestParams * @property {string} userId User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} secret Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1051,8 +1153,9 @@ const accountCreateOAuth2Session = async ({ provider, success, failure, scopes, /** * @param {AccountUpdatePhoneSessionRequestParams} params */ -const accountUpdatePhoneSession = async ({ userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePhoneSession = async ({userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/phone'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1072,14 +1175,16 @@ const accountUpdatePhoneSession = async ({ userId, secret, parseOutput = true, s parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateSessionRequestParams * @property {string} userId User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} secret Secret of a token generated by login methods. For example, the 'createMagicURLToken' or 'createPhoneToken' methods. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1087,8 +1192,9 @@ const accountUpdatePhoneSession = async ({ userId, secret, parseOutput = true, s /** * @param {AccountCreateSessionRequestParams} params */ -const accountCreateSession = async ({ userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateSession = async ({userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/token'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1108,13 +1214,15 @@ const accountCreateSession = async ({ userId, secret, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} AccountGetSessionRequestParams * @property {string} sessionId Session ID. Use the string 'current' to get the current device session. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1122,8 +1230,9 @@ const accountCreateSession = async ({ userId, secret, parseOutput = true, sdk = /** * @param {AccountGetSessionRequestParams} params */ -const accountGetSession = async ({ sessionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountGetSession = async ({sessionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); let payload = {}; @@ -1137,13 +1246,15 @@ const accountGetSession = async ({ sessionId, parseOutput = true, sdk = undefine parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateSessionRequestParams * @property {string} sessionId Session ID. Use the string 'current' to update the current device session. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1151,8 +1262,9 @@ const accountGetSession = async ({ sessionId, parseOutput = true, sdk = undefine /** * @param {AccountUpdateSessionRequestParams} params */ -const accountUpdateSession = async ({ sessionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateSession = async ({sessionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); let payload = {}; @@ -1166,13 +1278,15 @@ const accountUpdateSession = async ({ sessionId, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** * @typedef {Object} AccountDeleteSessionRequestParams * @property {string} sessionId Session ID. Use the string 'current' to delete the current device session. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1180,8 +1294,9 @@ const accountUpdateSession = async ({ sessionId, parseOutput = true, sdk = undef /** * @param {AccountDeleteSessionRequestParams} params */ -const accountDeleteSession = async ({ sessionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDeleteSession = async ({sessionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); let payload = {}; @@ -1195,12 +1310,14 @@ const accountDeleteSession = async ({ sessionId, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateStatusRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1208,8 +1325,9 @@ const accountDeleteSession = async ({ sessionId, parseOutput = true, sdk = undef /** * @param {AccountUpdateStatusRequestParams} params */ -const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateStatus = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/status'; let payload = {}; @@ -1223,8 +1341,9 @@ const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** @@ -1232,6 +1351,7 @@ const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => { * @property {string} targetId Target ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} identifier The target identifier (token, email, phone etc.) * @property {string} providerId Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1239,8 +1359,9 @@ const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {AccountCreatePushTargetRequestParams} params */ -const accountCreatePushTarget = async ({ targetId, identifier, providerId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreatePushTarget = async ({targetId,identifier,providerId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/targets/push'; let payload = {}; if (typeof targetId !== 'undefined') { @@ -1263,14 +1384,16 @@ const accountCreatePushTarget = async ({ targetId, identifier, providerId, parse parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePushTargetRequestParams * @property {string} targetId Target ID. * @property {string} identifier The target identifier (token, email, phone etc.) + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1278,8 +1401,9 @@ const accountCreatePushTarget = async ({ targetId, identifier, providerId, parse /** * @param {AccountUpdatePushTargetRequestParams} params */ -const accountUpdatePushTarget = async ({ targetId, identifier, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePushTarget = async ({targetId,identifier,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); let payload = {}; if (typeof identifier !== 'undefined') { @@ -1296,13 +1420,15 @@ const accountUpdatePushTarget = async ({ targetId, identifier, parseOutput = tru parse(response) success() } - + return response; + } /** * @typedef {Object} AccountDeletePushTargetRequestParams * @property {string} targetId Target ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1310,8 +1436,9 @@ const accountUpdatePushTarget = async ({ targetId, identifier, parseOutput = tru /** * @param {AccountDeletePushTargetRequestParams} params */ -const accountDeletePushTarget = async ({ targetId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountDeletePushTarget = async ({targetId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); let payload = {}; @@ -1325,8 +1452,9 @@ const accountDeletePushTarget = async ({ targetId, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** @@ -1334,6 +1462,7 @@ const accountDeletePushTarget = async ({ targetId, parseOutput = true, sdk = und * @property {string} userId User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} email User email. * @property {boolean} phrase Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1341,8 +1470,9 @@ const accountDeletePushTarget = async ({ targetId, parseOutput = true, sdk = und /** * @param {AccountCreateEmailTokenRequestParams} params */ -const accountCreateEmailToken = async ({ userId, email, phrase, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateEmailToken = async ({userId,email,phrase,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/tokens/email'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1365,8 +1495,9 @@ const accountCreateEmailToken = async ({ userId, email, phrase, parseOutput = tr parse(response) success() } - + return response; + } /** @@ -1375,6 +1506,7 @@ const accountCreateEmailToken = async ({ userId, email, phrase, parseOutput = tr * @property {string} email User email. * @property {string} url URL to redirect the user back to your app from the magic URL login. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {boolean} phrase Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1382,8 +1514,9 @@ const accountCreateEmailToken = async ({ userId, email, phrase, parseOutput = tr /** * @param {AccountCreateMagicURLTokenRequestParams} params */ -const accountCreateMagicURLToken = async ({ userId, email, url, phrase, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateMagicURLToken = async ({userId,email,url,phrase,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/tokens/magic-url'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1409,8 +1542,9 @@ const accountCreateMagicURLToken = async ({ userId, email, url, phrase, parseOut parse(response) success() } - + return response; + } /** @@ -1419,6 +1553,7 @@ const accountCreateMagicURLToken = async ({ userId, email, url, phrase, parseOut * @property {string} success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {string} failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {string[]} scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1426,8 +1561,9 @@ const accountCreateMagicURLToken = async ({ userId, email, url, phrase, parseOut /** * @param {AccountCreateOAuth2TokenRequestParams} params */ -const accountCreateOAuth2Token = async ({ provider, success, failure, scopes, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateOAuth2Token = async ({provider,success,failure,scopes,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider); let payload = {}; if (typeof success !== 'undefined') { @@ -1450,14 +1586,16 @@ const accountCreateOAuth2Token = async ({ provider, success, failure, scopes, pa parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreatePhoneTokenRequestParams * @property {string} userId Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1465,8 +1603,9 @@ const accountCreateOAuth2Token = async ({ provider, success, failure, scopes, pa /** * @param {AccountCreatePhoneTokenRequestParams} params */ -const accountCreatePhoneToken = async ({ userId, phone, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreatePhoneToken = async ({userId,phone,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/tokens/phone'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1486,13 +1625,15 @@ const accountCreatePhoneToken = async ({ userId, phone, parseOutput = true, sdk parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreateVerificationRequestParams * @property {string} url URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1500,8 +1641,9 @@ const accountCreatePhoneToken = async ({ userId, phone, parseOutput = true, sdk /** * @param {AccountCreateVerificationRequestParams} params */ -const accountCreateVerification = async ({ url, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreateVerification = async ({url,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/verification'; let payload = {}; if (typeof url !== 'undefined') { @@ -1518,14 +1660,16 @@ const accountCreateVerification = async ({ url, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdateVerificationRequestParams * @property {string} userId User ID. * @property {string} secret Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1533,8 +1677,9 @@ const accountCreateVerification = async ({ url, parseOutput = true, sdk = undefi /** * @param {AccountUpdateVerificationRequestParams} params */ -const accountUpdateVerification = async ({ userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdateVerification = async ({userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/verification'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1554,12 +1699,14 @@ const accountUpdateVerification = async ({ userId, secret, parseOutput = true, s parse(response) success() } - + return response; + } /** * @typedef {Object} AccountCreatePhoneVerificationRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1567,8 +1714,9 @@ const accountUpdateVerification = async ({ userId, secret, parseOutput = true, s /** * @param {AccountCreatePhoneVerificationRequestParams} params */ -const accountCreatePhoneVerification = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountCreatePhoneVerification = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/verification/phone'; let payload = {}; @@ -1582,14 +1730,16 @@ const accountCreatePhoneVerification = async ({ parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} AccountUpdatePhoneVerificationRequestParams * @property {string} userId User ID. * @property {string} secret Valid verification token. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1597,8 +1747,9 @@ const accountCreatePhoneVerification = async ({ parseOutput = true, sdk = undefi /** * @param {AccountUpdatePhoneVerificationRequestParams} params */ -const accountUpdatePhoneVerification = async ({ userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const accountUpdatePhoneVerification = async ({userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/account/verification/phone'; let payload = {}; if (typeof userId !== 'undefined') { @@ -1618,13 +1769,15 @@ const accountUpdatePhoneVerification = async ({ userId, secret, parseOutput = tr parse(response) success() } - + return response; + } account .command(`get`) .description(`Get the currently logged in user.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(accountGet)) account @@ -1685,7 +1838,7 @@ account account .command(`updateMfaAuthenticator`) - .description(`Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method. add `) + .description(`Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.`) .requiredOption(`--type `, `Type of authenticator.`) .requiredOption(`--otp `, `Valid verification token.`) .action(actionRunner(accountUpdateMfaAuthenticator)) @@ -1779,6 +1932,7 @@ account account .command(`listSessions`) .description(`Get the list of active sessions across different devices for the currently logged in user.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(accountListSessions)) account @@ -1980,4 +2134,4 @@ module.exports = { accountUpdateVerification, accountCreatePhoneVerification, accountUpdatePhoneVerification -}; \ No newline at end of file +}; diff --git a/lib/commands/assistant.js b/lib/commands/assistant.js index 1d2300e..3a1da8a 100644 --- a/lib/commands/assistant.js +++ b/lib/commands/assistant.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -42,6 +42,7 @@ const assistant = new Command("assistant").description(commandDescriptions['assi /** * @typedef {Object} AssistantChatRequestParams * @property {string} prompt Prompt. A string containing questions asked to the AI assistant. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -49,8 +50,9 @@ const assistant = new Command("assistant").description(commandDescriptions['assi /** * @param {AssistantChatRequestParams} params */ -const assistantChat = async ({ prompt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const assistantChat = async ({prompt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/console/assistant'; let payload = {}; if (typeof prompt !== 'undefined') { @@ -67,8 +69,9 @@ const assistantChat = async ({ prompt, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } assistant @@ -80,4 +83,4 @@ assistant module.exports = { assistant, assistantChat -}; \ No newline at end of file +}; diff --git a/lib/commands/avatars.js b/lib/commands/avatars.js index c40d77c..4d423d6 100644 --- a/lib/commands/avatars.js +++ b/lib/commands/avatars.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -45,6 +45,7 @@ const avatars = new Command("avatars").description(commandDescriptions['avatars' * @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -53,8 +54,9 @@ const avatars = new Command("avatars").description(commandDescriptions['avatars' /** * @param {AvatarsGetBrowserRequestParams} params */ -const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetBrowser = async ({code,width,height,quality,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/browsers/{code}'.replace('{code}', code); let payload = {}; if (typeof width !== 'undefined') { @@ -66,10 +68,12 @@ const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = t if (typeof quality !== 'undefined') { payload['quality'] = quality; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -77,14 +81,18 @@ const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = t 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -93,6 +101,7 @@ const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = t * @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -101,8 +110,9 @@ const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = t /** * @param {AvatarsGetCreditCardRequestParams} params */ -const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetCreditCard = async ({code,width,height,quality,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code); let payload = {}; if (typeof width !== 'undefined') { @@ -114,10 +124,12 @@ const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput if (typeof quality !== 'undefined') { payload['quality'] = quality; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -125,19 +137,24 @@ const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** * @typedef {Object} AvatarsGetFaviconRequestParams * @property {string} url Website URL which you want to fetch the favicon from. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -146,17 +163,20 @@ const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput /** * @param {AvatarsGetFaviconRequestParams} params */ -const avatarsGetFavicon = async ({ url, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetFavicon = async ({url,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/favicon'; let payload = {}; if (typeof url !== 'undefined') { payload['url'] = url; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -164,14 +184,18 @@ const avatarsGetFavicon = async ({ url, parseOutput = true, sdk = undefined, des 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -180,6 +204,7 @@ const avatarsGetFavicon = async ({ url, parseOutput = true, sdk = undefined, des * @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -188,8 +213,9 @@ const avatarsGetFavicon = async ({ url, parseOutput = true, sdk = undefined, des /** * @param {AvatarsGetFlagRequestParams} params */ -const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetFlag = async ({code,width,height,quality,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/flags/{code}'.replace('{code}', code); let payload = {}; if (typeof width !== 'undefined') { @@ -201,10 +227,12 @@ const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true if (typeof quality !== 'undefined') { payload['quality'] = quality; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -212,14 +240,18 @@ const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -227,6 +259,7 @@ const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true * @property {string} url Image URL which you want to crop. * @property {number} width Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400. * @property {number} height Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -235,8 +268,9 @@ const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true /** * @param {AvatarsGetImageRequestParams} params */ -const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetImage = async ({url,width,height,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/image'; let payload = {}; if (typeof url !== 'undefined') { @@ -248,10 +282,12 @@ const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = u if (typeof height !== 'undefined') { payload['height'] = height; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -259,14 +295,18 @@ const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = u 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -275,6 +315,7 @@ const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = u * @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100. * @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100. * @property {string} background Changes background color. By default a random color will be picked and stay will persistent to the given name. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -283,8 +324,9 @@ const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = u /** * @param {AvatarsGetInitialsRequestParams} params */ -const avatarsGetInitials = async ({ name, width, height, background, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetInitials = async ({name,width,height,background,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/initials'; let payload = {}; if (typeof name !== 'undefined') { @@ -299,10 +341,12 @@ const avatarsGetInitials = async ({ name, width, height, background, parseOutput if (typeof background !== 'undefined') { payload['background'] = background; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -310,14 +354,18 @@ const avatarsGetInitials = async ({ name, width, height, background, parseOutput 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -326,6 +374,7 @@ const avatarsGetInitials = async ({ name, width, height, background, parseOutput * @property {number} size QR code size. Pass an integer between 1 to 1000. Defaults to 400. * @property {number} margin Margin from edge. Pass an integer between 0 to 10. Defaults to 1. * @property {boolean} download Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -334,8 +383,9 @@ const avatarsGetInitials = async ({ name, width, height, background, parseOutput /** * @param {AvatarsGetQRRequestParams} params */ -const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const avatarsGetQR = async ({text,size,margin,download,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/avatars/qr'; let payload = {}; if (typeof text !== 'undefined') { @@ -350,10 +400,12 @@ const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true, if (typeof download !== 'undefined') { payload['download'] = download; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -361,14 +413,18 @@ const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true, 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } avatars @@ -446,4 +502,4 @@ module.exports = { avatarsGetImage, avatarsGetInitials, avatarsGetQR -}; \ No newline at end of file +}; diff --git a/lib/commands/console.js b/lib/commands/console.js index 7c894ff..ef46397 100644 --- a/lib/commands/console.js +++ b/lib/commands/console.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -41,6 +41,7 @@ const console = new Command("console").description(commandDescriptions['console' /** * @typedef {Object} ConsoleVariablesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -48,8 +49,9 @@ const console = new Command("console").description(commandDescriptions['console' /** * @param {ConsoleVariablesRequestParams} params */ -const consoleVariables = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const consoleVariables = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/console/variables'; let payload = {}; @@ -63,8 +65,9 @@ const consoleVariables = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } console @@ -75,4 +78,4 @@ console module.exports = { console, consoleVariables -}; \ No newline at end of file +}; diff --git a/lib/commands/databases.js b/lib/commands/databases.js index 80aa3b4..d2b989b 100644 --- a/lib/commands/databases.js +++ b/lib/commands/databases.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const databases = new Command("databases").description(commandDescriptions['data * @typedef {Object} DatabasesListRequestParams * @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 * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const databases = new Command("databases").description(commandDescriptions['data /** * @param {DatabasesListRequestParams} params */ -const databasesList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const databasesList = async ({ queries, search, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'list'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -80,6 +87,7 @@ const databasesList = async ({ queries, search, parseOutput = true, sdk = undefi * @property {string} databaseId Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} name Database name. Max length: 128 chars. * @property {boolean} enabled Is the database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -87,8 +95,9 @@ const databasesList = async ({ queries, search, parseOutput = true, sdk = undefi /** * @param {DatabasesCreateRequestParams} params */ -const databasesCreate = async ({ databaseId, name, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreate = async ({databaseId,name,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases'; let payload = {}; if (typeof databaseId !== 'undefined') { @@ -111,13 +120,15 @@ const databasesCreate = async ({ databaseId, name, enabled, parseOutput = true, parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesGetUsageRequestParams * @property {DatabaseUsageRange} range 'Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -125,8 +136,9 @@ const databasesCreate = async ({ databaseId, name, enabled, parseOutput = true, /** * @param {DatabasesGetUsageRequestParams} params */ -const databasesGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetUsage = async ({range,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/usage'; let payload = {}; if (typeof range !== 'undefined') { @@ -143,13 +155,15 @@ const databasesGetUsage = async ({ range, parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesGetRequestParams * @property {string} databaseId Database ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -157,8 +171,9 @@ const databasesGetUsage = async ({ range, parseOutput = true, sdk = undefined}) /** * @param {DatabasesGetRequestParams} params */ -const databasesGet = async ({ databaseId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGet = async ({databaseId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}'.replace('{databaseId}', databaseId); let payload = {}; @@ -169,11 +184,16 @@ const databasesGet = async ({ databaseId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'get', databaseId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -181,6 +201,7 @@ const databasesGet = async ({ databaseId, parseOutput = true, sdk = undefined}) * @property {string} databaseId Database ID. * @property {string} name Database name. Max length: 128 chars. * @property {boolean} enabled Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -188,8 +209,9 @@ const databasesGet = async ({ databaseId, parseOutput = true, sdk = undefined}) /** * @param {DatabasesUpdateRequestParams} params */ -const databasesUpdate = async ({ databaseId, name, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdate = async ({databaseId,name,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}'.replace('{databaseId}', databaseId); let payload = {}; if (typeof name !== 'undefined') { @@ -209,13 +231,15 @@ const databasesUpdate = async ({ databaseId, name, enabled, parseOutput = true, parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesDeleteRequestParams * @property {string} databaseId Database ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -223,8 +247,9 @@ const databasesUpdate = async ({ databaseId, name, enabled, parseOutput = true, /** * @param {DatabasesDeleteRequestParams} params */ -const databasesDelete = async ({ databaseId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesDelete = async ({databaseId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}'.replace('{databaseId}', databaseId); let payload = {}; @@ -238,8 +263,9 @@ const databasesDelete = async ({ databaseId, parseOutput = true, sdk = undefined parse(response) success() } - + return response; + } /** @@ -247,6 +273,7 @@ const databasesDelete = async ({ databaseId, parseOutput = true, sdk = undefined * @property {string} databaseId Database ID. * @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, enabled, documentSecurity * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -254,8 +281,9 @@ const databasesDelete = async ({ databaseId, parseOutput = true, sdk = undefined /** * @param {DatabasesListCollectionsRequestParams} params */ -const databasesListCollections = async ({ databaseId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListCollections = async ({databaseId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections'.replace('{databaseId}', databaseId); let payload = {}; if (typeof queries !== 'undefined') { @@ -272,11 +300,16 @@ const databasesListCollections = async ({ databaseId, queries, search, parseOutp }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listCollections', databaseId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -287,6 +320,7 @@ const databasesListCollections = async ({ databaseId, queries, search, parseOutp * @property {string[]} permissions An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). * @property {boolean} documentSecurity Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions). * @property {boolean} enabled Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -294,8 +328,9 @@ const databasesListCollections = async ({ databaseId, queries, search, parseOutp /** * @param {DatabasesCreateCollectionRequestParams} params */ -const databasesCreateCollection = async ({ databaseId, collectionId, name, permissions, documentSecurity, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateCollection = async ({databaseId,collectionId,name,permissions,documentSecurity,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections'.replace('{databaseId}', databaseId); let payload = {}; if (typeof collectionId !== 'undefined') { @@ -325,14 +360,16 @@ const databasesCreateCollection = async ({ databaseId, collectionId, name, permi parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesGetCollectionRequestParams * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -340,8 +377,9 @@ const databasesCreateCollection = async ({ databaseId, collectionId, name, permi /** * @param {DatabasesGetCollectionRequestParams} params */ -const databasesGetCollection = async ({ databaseId, collectionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetCollection = async ({databaseId,collectionId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; @@ -352,11 +390,16 @@ const databasesGetCollection = async ({ databaseId, collectionId, parseOutput = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getCollection', databaseId, collectionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -367,6 +410,7 @@ const databasesGetCollection = async ({ databaseId, collectionId, parseOutput = * @property {string[]} permissions An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). * @property {boolean} documentSecurity Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions). * @property {boolean} enabled Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -374,8 +418,9 @@ const databasesGetCollection = async ({ databaseId, collectionId, parseOutput = /** * @param {DatabasesUpdateCollectionRequestParams} params */ -const databasesUpdateCollection = async ({ databaseId, collectionId, name, permissions, documentSecurity, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateCollection = async ({databaseId,collectionId,name,permissions,documentSecurity,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof name !== 'undefined') { @@ -402,14 +447,16 @@ const databasesUpdateCollection = async ({ databaseId, collectionId, name, permi parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesDeleteCollectionRequestParams * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -417,8 +464,9 @@ const databasesUpdateCollection = async ({ databaseId, collectionId, name, permi /** * @param {DatabasesDeleteCollectionRequestParams} params */ -const databasesDeleteCollection = async ({ databaseId, collectionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesDeleteCollection = async ({databaseId,collectionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; @@ -432,8 +480,9 @@ const databasesDeleteCollection = async ({ databaseId, collectionId, parseOutput parse(response) success() } - + return response; + } /** @@ -441,6 +490,7 @@ const databasesDeleteCollection = async ({ databaseId, collectionId, parseOutput * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @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: key, type, size, required, array, status, error + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -448,8 +498,9 @@ const databasesDeleteCollection = async ({ databaseId, collectionId, parseOutput /** * @param {DatabasesListAttributesRequestParams} params */ -const databasesListAttributes = async ({ databaseId, collectionId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListAttributes = async ({databaseId,collectionId,queries,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -463,11 +514,16 @@ const databasesListAttributes = async ({ databaseId, collectionId, queries, pars }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listAttributes', databaseId, collectionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -478,6 +534,7 @@ const databasesListAttributes = async ({ databaseId, collectionId, queries, pars * @property {boolean} required Is attribute required? * @property {boolean} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -485,8 +542,9 @@ const databasesListAttributes = async ({ databaseId, collectionId, queries, pars /** * @param {DatabasesCreateBooleanAttributeRequestParams} params */ -const databasesCreateBooleanAttribute = async ({ databaseId, collectionId, key, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateBooleanAttribute = async ({databaseId,collectionId,key,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -512,8 +570,9 @@ const databasesCreateBooleanAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -523,6 +582,7 @@ const databasesCreateBooleanAttribute = async ({ databaseId, collectionId, key, * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {boolean} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -530,8 +590,9 @@ const databasesCreateBooleanAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesUpdateBooleanAttributeRequestParams} params */ -const databasesUpdateBooleanAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateBooleanAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -551,8 +612,9 @@ const databasesUpdateBooleanAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -563,6 +625,7 @@ const databasesUpdateBooleanAttribute = async ({ databaseId, collectionId, key, * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for the attribute in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -570,8 +633,9 @@ const databasesUpdateBooleanAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesCreateDatetimeAttributeRequestParams} params */ -const databasesCreateDatetimeAttribute = async ({ databaseId, collectionId, key, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateDatetimeAttribute = async ({databaseId,collectionId,key,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -597,8 +661,9 @@ const databasesCreateDatetimeAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -608,6 +673,7 @@ const databasesCreateDatetimeAttribute = async ({ databaseId, collectionId, key, * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -615,8 +681,9 @@ const databasesCreateDatetimeAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesUpdateDatetimeAttributeRequestParams} params */ -const databasesUpdateDatetimeAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateDatetimeAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -636,8 +703,9 @@ const databasesUpdateDatetimeAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -648,6 +716,7 @@ const databasesUpdateDatetimeAttribute = async ({ databaseId, collectionId, key, * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -655,8 +724,9 @@ const databasesUpdateDatetimeAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesCreateEmailAttributeRequestParams} params */ -const databasesCreateEmailAttribute = async ({ databaseId, collectionId, key, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateEmailAttribute = async ({databaseId,collectionId,key,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -682,8 +752,9 @@ const databasesCreateEmailAttribute = async ({ databaseId, collectionId, key, re parse(response) success() } - + return response; + } /** @@ -693,6 +764,7 @@ const databasesCreateEmailAttribute = async ({ databaseId, collectionId, key, re * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -700,8 +772,9 @@ const databasesCreateEmailAttribute = async ({ databaseId, collectionId, key, re /** * @param {DatabasesUpdateEmailAttributeRequestParams} params */ -const databasesUpdateEmailAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateEmailAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -721,8 +794,9 @@ const databasesUpdateEmailAttribute = async ({ databaseId, collectionId, key, re parse(response) success() } - + return response; + } /** @@ -734,6 +808,7 @@ const databasesUpdateEmailAttribute = async ({ databaseId, collectionId, key, re * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -741,8 +816,9 @@ const databasesUpdateEmailAttribute = async ({ databaseId, collectionId, key, re /** * @param {DatabasesCreateEnumAttributeRequestParams} params */ -const databasesCreateEnumAttribute = async ({ databaseId, collectionId, key, elements, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateEnumAttribute = async ({databaseId,collectionId,key,elements,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -772,8 +848,9 @@ const databasesCreateEnumAttribute = async ({ databaseId, collectionId, key, ele parse(response) success() } - + return response; + } /** @@ -784,6 +861,7 @@ const databasesCreateEnumAttribute = async ({ databaseId, collectionId, key, ele * @property {string[]} elements Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 255 characters long. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -791,8 +869,9 @@ const databasesCreateEnumAttribute = async ({ databaseId, collectionId, key, ele /** * @param {DatabasesUpdateEnumAttributeRequestParams} params */ -const databasesUpdateEnumAttribute = async ({ databaseId, collectionId, key, elements, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateEnumAttribute = async ({databaseId,collectionId,key,elements,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; elements = elements === true ? [] : elements; @@ -816,8 +895,9 @@ const databasesUpdateEnumAttribute = async ({ databaseId, collectionId, key, ele parse(response) success() } - + return response; + } /** @@ -830,6 +910,7 @@ const databasesUpdateEnumAttribute = async ({ databaseId, collectionId, key, ele * @property {number} max Maximum value to enforce on new documents * @property {number} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -837,8 +918,9 @@ const databasesUpdateEnumAttribute = async ({ databaseId, collectionId, key, ele /** * @param {DatabasesCreateFloatAttributeRequestParams} params */ -const databasesCreateFloatAttribute = async ({ databaseId, collectionId, key, required, min, max, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateFloatAttribute = async ({databaseId,collectionId,key,required,min,max,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -870,8 +952,9 @@ const databasesCreateFloatAttribute = async ({ databaseId, collectionId, key, re parse(response) success() } - + return response; + } /** @@ -883,6 +966,7 @@ const databasesCreateFloatAttribute = async ({ databaseId, collectionId, key, re * @property {number} min Minimum value to enforce on new documents * @property {number} max Maximum value to enforce on new documents * @property {number} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -890,8 +974,9 @@ const databasesCreateFloatAttribute = async ({ databaseId, collectionId, key, re /** * @param {DatabasesUpdateFloatAttributeRequestParams} params */ -const databasesUpdateFloatAttribute = async ({ databaseId, collectionId, key, required, min, max, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateFloatAttribute = async ({databaseId,collectionId,key,required,min,max,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -917,8 +1002,9 @@ const databasesUpdateFloatAttribute = async ({ databaseId, collectionId, key, re parse(response) success() } - + return response; + } /** @@ -931,6 +1017,7 @@ const databasesUpdateFloatAttribute = async ({ databaseId, collectionId, key, re * @property {number} max Maximum value to enforce on new documents * @property {number} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -938,8 +1025,9 @@ const databasesUpdateFloatAttribute = async ({ databaseId, collectionId, key, re /** * @param {DatabasesCreateIntegerAttributeRequestParams} params */ -const databasesCreateIntegerAttribute = async ({ databaseId, collectionId, key, required, min, max, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateIntegerAttribute = async ({databaseId,collectionId,key,required,min,max,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -971,8 +1059,9 @@ const databasesCreateIntegerAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -984,6 +1073,7 @@ const databasesCreateIntegerAttribute = async ({ databaseId, collectionId, key, * @property {number} min Minimum value to enforce on new documents * @property {number} max Maximum value to enforce on new documents * @property {number} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -991,8 +1081,9 @@ const databasesCreateIntegerAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesUpdateIntegerAttributeRequestParams} params */ -const databasesUpdateIntegerAttribute = async ({ databaseId, collectionId, key, required, min, max, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateIntegerAttribute = async ({databaseId,collectionId,key,required,min,max,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -1018,8 +1109,9 @@ const databasesUpdateIntegerAttribute = async ({ databaseId, collectionId, key, parse(response) success() } - + return response; + } /** @@ -1030,6 +1122,7 @@ const databasesUpdateIntegerAttribute = async ({ databaseId, collectionId, key, * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1037,8 +1130,9 @@ const databasesUpdateIntegerAttribute = async ({ databaseId, collectionId, key, /** * @param {DatabasesCreateIpAttributeRequestParams} params */ -const databasesCreateIpAttribute = async ({ databaseId, collectionId, key, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateIpAttribute = async ({databaseId,collectionId,key,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -1064,8 +1158,9 @@ const databasesCreateIpAttribute = async ({ databaseId, collectionId, key, requi parse(response) success() } - + return response; + } /** @@ -1075,6 +1170,7 @@ const databasesCreateIpAttribute = async ({ databaseId, collectionId, key, requi * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1082,8 +1178,9 @@ const databasesCreateIpAttribute = async ({ databaseId, collectionId, key, requi /** * @param {DatabasesUpdateIpAttributeRequestParams} params */ -const databasesUpdateIpAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateIpAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -1103,8 +1200,9 @@ const databasesUpdateIpAttribute = async ({ databaseId, collectionId, key, requi parse(response) success() } - + return response; + } /** @@ -1117,6 +1215,7 @@ const databasesUpdateIpAttribute = async ({ databaseId, collectionId, key, requi * @property {string} key Attribute Key. * @property {string} twoWayKey Two Way Attribute Key. * @property {RelationMutate} onDelete Constraints option + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1124,8 +1223,9 @@ const databasesUpdateIpAttribute = async ({ databaseId, collectionId, key, requi /** * @param {DatabasesCreateRelationshipAttributeRequestParams} params */ -const databasesCreateRelationshipAttribute = async ({ databaseId, collectionId, relatedCollectionId, type, twoWay, key, twoWayKey, onDelete, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateRelationshipAttribute = async ({databaseId,collectionId,relatedCollectionId,type,twoWay,key,twoWayKey,onDelete,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof relatedCollectionId !== 'undefined') { @@ -1157,8 +1257,9 @@ const databasesCreateRelationshipAttribute = async ({ databaseId, collectionId, parse(response) success() } - + return response; + } /** @@ -1171,6 +1272,7 @@ const databasesCreateRelationshipAttribute = async ({ databaseId, collectionId, * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? * @property {boolean} encrypt Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1178,8 +1280,9 @@ const databasesCreateRelationshipAttribute = async ({ databaseId, collectionId, /** * @param {DatabasesCreateStringAttributeRequestParams} params */ -const databasesCreateStringAttribute = async ({ databaseId, collectionId, key, size, required, xdefault, array, encrypt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateStringAttribute = async ({databaseId,collectionId,key,size,required,xdefault,array,encrypt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -1211,8 +1314,9 @@ const databasesCreateStringAttribute = async ({ databaseId, collectionId, key, s parse(response) success() } - + return response; + } /** @@ -1222,6 +1326,7 @@ const databasesCreateStringAttribute = async ({ databaseId, collectionId, key, s * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1229,8 +1334,9 @@ const databasesCreateStringAttribute = async ({ databaseId, collectionId, key, s /** * @param {DatabasesUpdateStringAttributeRequestParams} params */ -const databasesUpdateStringAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateStringAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -1250,8 +1356,9 @@ const databasesUpdateStringAttribute = async ({ databaseId, collectionId, key, r parse(response) success() } - + return response; + } /** @@ -1262,6 +1369,7 @@ const databasesUpdateStringAttribute = async ({ databaseId, collectionId, key, r * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. * @property {boolean} array Is attribute an array? + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1269,8 +1377,9 @@ const databasesUpdateStringAttribute = async ({ databaseId, collectionId, key, r /** * @param {DatabasesCreateUrlAttributeRequestParams} params */ -const databasesCreateUrlAttribute = async ({ databaseId, collectionId, key, required, xdefault, array, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateUrlAttribute = async ({databaseId,collectionId,key,required,xdefault,array,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -1296,8 +1405,9 @@ const databasesCreateUrlAttribute = async ({ databaseId, collectionId, key, requ parse(response) success() } - + return response; + } /** @@ -1307,6 +1417,7 @@ const databasesCreateUrlAttribute = async ({ databaseId, collectionId, key, requ * @property {string} key Attribute Key. * @property {boolean} required Is attribute required? * @property {string} xdefault Default value for attribute when not provided. Cannot be set when attribute is required. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1314,8 +1425,9 @@ const databasesCreateUrlAttribute = async ({ databaseId, collectionId, key, requ /** * @param {DatabasesUpdateUrlAttributeRequestParams} params */ -const databasesUpdateUrlAttribute = async ({ databaseId, collectionId, key, required, xdefault, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateUrlAttribute = async ({databaseId,collectionId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof required !== 'undefined') { @@ -1335,8 +1447,9 @@ const databasesUpdateUrlAttribute = async ({ databaseId, collectionId, key, requ parse(response) success() } - + return response; + } /** @@ -1344,6 +1457,7 @@ const databasesUpdateUrlAttribute = async ({ databaseId, collectionId, key, requ * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} key Attribute Key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1351,8 +1465,9 @@ const databasesUpdateUrlAttribute = async ({ databaseId, collectionId, key, requ /** * @param {DatabasesGetAttributeRequestParams} params */ -const databasesGetAttribute = async ({ databaseId, collectionId, key, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetAttribute = async ({databaseId,collectionId,key,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; @@ -1366,8 +1481,9 @@ const databasesGetAttribute = async ({ databaseId, collectionId, key, parseOutpu parse(response) success() } - + return response; + } /** @@ -1375,6 +1491,7 @@ const databasesGetAttribute = async ({ databaseId, collectionId, key, parseOutpu * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} key Attribute Key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1382,8 +1499,9 @@ const databasesGetAttribute = async ({ databaseId, collectionId, key, parseOutpu /** * @param {DatabasesDeleteAttributeRequestParams} params */ -const databasesDeleteAttribute = async ({ databaseId, collectionId, key, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesDeleteAttribute = async ({databaseId,collectionId,key,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; @@ -1397,8 +1515,9 @@ const databasesDeleteAttribute = async ({ databaseId, collectionId, key, parseOu parse(response) success() } - + return response; + } /** @@ -1407,6 +1526,7 @@ const databasesDeleteAttribute = async ({ databaseId, collectionId, key, parseOu * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} key Attribute Key. * @property {RelationMutate} onDelete Constraints option + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1414,8 +1534,9 @@ const databasesDeleteAttribute = async ({ databaseId, collectionId, key, parseOu /** * @param {DatabasesUpdateRelationshipAttributeRequestParams} params */ -const databasesUpdateRelationshipAttribute = async ({ databaseId, collectionId, key, onDelete, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateRelationshipAttribute = async ({databaseId,collectionId,key,onDelete,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; if (typeof onDelete !== 'undefined') { @@ -1432,8 +1553,9 @@ const databasesUpdateRelationshipAttribute = async ({ databaseId, collectionId, parse(response) success() } - + return response; + } /** @@ -1441,6 +1563,7 @@ const databasesUpdateRelationshipAttribute = async ({ databaseId, collectionId, * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @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. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1448,8 +1571,9 @@ const databasesUpdateRelationshipAttribute = async ({ databaseId, collectionId, /** * @param {DatabasesListDocumentsRequestParams} params */ -const databasesListDocuments = async ({ databaseId, collectionId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListDocuments = async ({databaseId,collectionId,queries,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1463,11 +1587,16 @@ const databasesListDocuments = async ({ databaseId, collectionId, queries, parse }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listDocuments', databaseId, collectionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1477,6 +1606,7 @@ const databasesListDocuments = async ({ databaseId, collectionId, queries, parse * @property {string} documentId Document ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {object} data Document data as JSON object. * @property {string[]} permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1484,8 +1614,9 @@ const databasesListDocuments = async ({ databaseId, collectionId, queries, parse /** * @param {DatabasesCreateDocumentRequestParams} params */ -const databasesCreateDocument = async ({ databaseId, collectionId, documentId, data, permissions, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateDocument = async ({databaseId,collectionId,documentId,data,permissions,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof documentId !== 'undefined') { @@ -1509,8 +1640,9 @@ const databasesCreateDocument = async ({ databaseId, collectionId, documentId, d parse(response) success() } - + return response; + } /** @@ -1519,6 +1651,7 @@ const databasesCreateDocument = async ({ databaseId, collectionId, documentId, d * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} documentId Document ID. * @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. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1526,8 +1659,9 @@ const databasesCreateDocument = async ({ databaseId, collectionId, documentId, d /** * @param {DatabasesGetDocumentRequestParams} params */ -const databasesGetDocument = async ({ databaseId, collectionId, documentId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetDocument = async ({databaseId,collectionId,documentId,queries,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1541,11 +1675,16 @@ const databasesGetDocument = async ({ databaseId, collectionId, documentId, quer }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getDocument', databaseId, collectionId, documentId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1555,6 +1694,7 @@ const databasesGetDocument = async ({ databaseId, collectionId, documentId, quer * @property {string} documentId Document ID. * @property {object} data Document data as JSON object. Include only attribute and value pairs to be updated. * @property {string[]} permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1562,8 +1702,9 @@ const databasesGetDocument = async ({ databaseId, collectionId, documentId, quer /** * @param {DatabasesUpdateDocumentRequestParams} params */ -const databasesUpdateDocument = async ({ databaseId, collectionId, documentId, data, permissions, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesUpdateDocument = async ({databaseId,collectionId,documentId,data,permissions,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); let payload = {}; if (typeof data !== 'undefined') { @@ -1584,8 +1725,9 @@ const databasesUpdateDocument = async ({ databaseId, collectionId, documentId, d parse(response) success() } - + return response; + } /** @@ -1593,6 +1735,7 @@ const databasesUpdateDocument = async ({ databaseId, collectionId, documentId, d * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} documentId Document ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1600,8 +1743,9 @@ const databasesUpdateDocument = async ({ databaseId, collectionId, documentId, d /** * @param {DatabasesDeleteDocumentRequestParams} params */ -const databasesDeleteDocument = async ({ databaseId, collectionId, documentId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesDeleteDocument = async ({databaseId,collectionId,documentId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); let payload = {}; @@ -1615,8 +1759,9 @@ const databasesDeleteDocument = async ({ databaseId, collectionId, documentId, p parse(response) success() } - + return response; + } /** @@ -1625,6 +1770,7 @@ const databasesDeleteDocument = async ({ databaseId, collectionId, documentId, p * @property {string} collectionId Collection ID. * @property {string} documentId Document ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1632,8 +1778,9 @@ const databasesDeleteDocument = async ({ databaseId, collectionId, documentId, p /** * @param {DatabasesListDocumentLogsRequestParams} params */ -const databasesListDocumentLogs = async ({ databaseId, collectionId, documentId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListDocumentLogs = async ({databaseId,collectionId,documentId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/logs'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1650,8 +1797,9 @@ const databasesListDocumentLogs = async ({ databaseId, collectionId, documentId, parse(response) success() } - + return response; + } /** @@ -1659,6 +1807,7 @@ const databasesListDocumentLogs = async ({ databaseId, collectionId, documentId, * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @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: key, type, status, attributes, error + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1666,8 +1815,9 @@ const databasesListDocumentLogs = async ({ databaseId, collectionId, documentId, /** * @param {DatabasesListIndexesRequestParams} params */ -const databasesListIndexes = async ({ databaseId, collectionId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListIndexes = async ({databaseId,collectionId,queries,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1681,11 +1831,16 @@ const databasesListIndexes = async ({ databaseId, collectionId, queries, parseOu }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listIndexes', databaseId, collectionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1696,6 +1851,7 @@ const databasesListIndexes = async ({ databaseId, collectionId, queries, parseOu * @property {IndexType} type Index type. * @property {string[]} attributes Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long. * @property {string[]} orders Array of index orders. Maximum of 100 orders are allowed. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1703,8 +1859,9 @@ const databasesListIndexes = async ({ databaseId, collectionId, queries, parseOu /** * @param {DatabasesCreateIndexRequestParams} params */ -const databasesCreateIndex = async ({ databaseId, collectionId, key, type, attributes, orders, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesCreateIndex = async ({databaseId,collectionId,key,type,attributes,orders,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof key !== 'undefined') { @@ -1732,8 +1889,9 @@ const databasesCreateIndex = async ({ databaseId, collectionId, key, type, attri parse(response) success() } - + return response; + } /** @@ -1741,6 +1899,7 @@ const databasesCreateIndex = async ({ databaseId, collectionId, key, type, attri * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} key Index Key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1748,8 +1907,9 @@ const databasesCreateIndex = async ({ databaseId, collectionId, key, type, attri /** * @param {DatabasesGetIndexRequestParams} params */ -const databasesGetIndex = async ({ databaseId, collectionId, key, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetIndex = async ({databaseId,collectionId,key,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; @@ -1763,8 +1923,9 @@ const databasesGetIndex = async ({ databaseId, collectionId, key, parseOutput = parse(response) success() } - + return response; + } /** @@ -1772,6 +1933,7 @@ const databasesGetIndex = async ({ databaseId, collectionId, key, parseOutput = * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @property {string} key Index Key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1779,8 +1941,9 @@ const databasesGetIndex = async ({ databaseId, collectionId, key, parseOutput = /** * @param {DatabasesDeleteIndexRequestParams} params */ -const databasesDeleteIndex = async ({ databaseId, collectionId, key, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesDeleteIndex = async ({databaseId,collectionId,key,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); let payload = {}; @@ -1794,8 +1957,9 @@ const databasesDeleteIndex = async ({ databaseId, collectionId, key, parseOutput parse(response) success() } - + return response; + } /** @@ -1803,6 +1967,7 @@ const databasesDeleteIndex = async ({ databaseId, collectionId, key, parseOutput * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1810,8 +1975,9 @@ const databasesDeleteIndex = async ({ databaseId, collectionId, key, parseOutput /** * @param {DatabasesListCollectionLogsRequestParams} params */ -const databasesListCollectionLogs = async ({ databaseId, collectionId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListCollectionLogs = async ({databaseId,collectionId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/logs'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1828,8 +1994,9 @@ const databasesListCollectionLogs = async ({ databaseId, collectionId, queries, parse(response) success() } - + return response; + } /** @@ -1837,6 +2004,7 @@ const databasesListCollectionLogs = async ({ databaseId, collectionId, queries, * @property {string} databaseId Database ID. * @property {string} collectionId Collection ID. * @property {DatabaseUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1844,8 +2012,9 @@ const databasesListCollectionLogs = async ({ databaseId, collectionId, queries, /** * @param {DatabasesGetCollectionUsageRequestParams} params */ -const databasesGetCollectionUsage = async ({ databaseId, collectionId, range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetCollectionUsage = async ({databaseId,collectionId,range,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/collections/{collectionId}/usage'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; if (typeof range !== 'undefined') { @@ -1862,14 +2031,16 @@ const databasesGetCollectionUsage = async ({ databaseId, collectionId, range, pa parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesListLogsRequestParams * @property {string} databaseId Database ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1877,8 +2048,9 @@ const databasesGetCollectionUsage = async ({ databaseId, collectionId, range, pa /** * @param {DatabasesListLogsRequestParams} params */ -const databasesListLogs = async ({ databaseId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesListLogs = async ({databaseId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/logs'.replace('{databaseId}', databaseId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1895,14 +2067,16 @@ const databasesListLogs = async ({ databaseId, queries, parseOutput = true, sdk parse(response) success() } - + return response; + } /** * @typedef {Object} DatabasesGetDatabaseUsageRequestParams * @property {string} databaseId Database ID. * @property {DatabaseUsageRange} range 'Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1910,8 +2084,9 @@ const databasesListLogs = async ({ databaseId, queries, parseOutput = true, sdk /** * @param {DatabasesGetDatabaseUsageRequestParams} params */ -const databasesGetDatabaseUsage = async ({ databaseId, range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const databasesGetDatabaseUsage = async ({databaseId,range,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/databases/{databaseId}/usage'.replace('{databaseId}', databaseId); let payload = {}; if (typeof range !== 'undefined') { @@ -1925,11 +2100,16 @@ const databasesGetDatabaseUsage = async ({ databaseId, range, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getDatabaseUsage', databaseId); + } else { + parse(response) + success() + } } - + return response; + } databases @@ -1937,6 +2117,7 @@ databases .description(`Get a list of all databases from the current Appwrite project. You can use the search parameter to filter your results.`) .option(`--queries [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`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesList)) databases @@ -1957,6 +2138,7 @@ databases .command(`get`) .description(`Get a database by its unique ID. This endpoint response returns a JSON object with the database metadata.`) .requiredOption(`--databaseId `, `Database ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGet)) databases @@ -1979,6 +2161,7 @@ databases .requiredOption(`--databaseId `, `Database ID.`) .option(`--queries [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, enabled, documentSecurity`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListCollections)) databases @@ -1997,6 +2180,7 @@ databases .description(`Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.`) .requiredOption(`--databaseId `, `Database ID.`) .requiredOption(`--collectionId `, `Collection ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetCollection)) databases @@ -2023,6 +2207,7 @@ databases .requiredOption(`--databaseId `, `Database ID.`) .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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: key, type, size, required, array, status, error`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListAttributes)) databases @@ -2270,6 +2455,7 @@ databases .requiredOption(`--databaseId `, `Database ID.`) .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListDocuments)) databases @@ -2289,6 +2475,7 @@ databases .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--documentId `, `Document ID.`) .option(`--queries [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.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetDocument)) databases @@ -2324,6 +2511,7 @@ databases .requiredOption(`--databaseId `, `Database ID.`) .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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: key, type, status, attributes, error`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListIndexes)) databases @@ -2381,6 +2569,7 @@ databases .description(``) .requiredOption(`--databaseId `, `Database ID.`) .option(`--range `, `'Date range.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetDatabaseUsage)) module.exports = { @@ -2433,4 +2622,4 @@ module.exports = { databasesGetCollectionUsage, databasesListLogs, databasesGetDatabaseUsage -}; \ No newline at end of file +}; diff --git a/lib/commands/deploy.js b/lib/commands/deploy.js deleted file mode 100644 index 3ae7a17..0000000 --- a/lib/commands/deploy.js +++ /dev/null @@ -1,940 +0,0 @@ -const inquirer = require("inquirer"); -const JSONbig = require("json-bigint")({ storeAsString: false }); -const { Command } = require("commander"); -const { localConfig } = require("../config"); -const { paginate } = require('../paginate'); -const { questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions"); -const { actionRunner, success, log, error, commandDescriptions } = require("../parser"); -const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); -const { - databasesGet, - databasesCreate, - databasesUpdate, - databasesCreateBooleanAttribute, - databasesGetCollection, - databasesCreateCollection, - databasesCreateStringAttribute, - databasesCreateIntegerAttribute, - databasesCreateFloatAttribute, - databasesCreateEmailAttribute, - databasesCreateDatetimeAttribute, - databasesCreateIndex, - databasesCreateUrlAttribute, - databasesCreateIpAttribute, - databasesCreateEnumAttribute, - databasesCreateRelationshipAttribute, - databasesDeleteAttribute, - databasesListAttributes, - databasesListIndexes, - databasesDeleteIndex, - databasesUpdateCollection -} = require("./databases"); -const { - storageGetBucket, storageUpdateBucket, storageCreateBucket -} = require("./storage"); -const { - teamsGet, - teamsUpdateName, - teamsCreate -} = require("./teams"); -const { checkDeployConditions } = require('../utils'); - -const STEP_SIZE = 100; // Resources -const POOL_DEBOUNCE = 2000; // Milliseconds - -let poolMaxDebounces = 30; - -const awaitPools = { - wipeAttributes: async (databaseId, collectionId, iteration = 1) => { - if (iteration > poolMaxDebounces) { - return false; - } - - const { total } = await databasesListAttributes({ - databaseId, - collectionId, - queries: [JSON.stringify({ method: 'limit', values: [1] })], - parseOutput: false - }); - - if (total === 0) { - return true; - } - - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - poolMaxDebounces *= steps; - - log('Found a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes') - } - - await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE)); - - return await awaitPools.wipeAttributes( - databaseId, - collectionId, - iteration + 1 - ); - }, - wipeIndexes: async (databaseId, collectionId, iteration = 1) => { - if (iteration > poolMaxDebounces) { - return false; - } - - const { total } = await databasesListIndexes({ - databaseId, - collectionId, - queries: [JSON.stringify({ method: 'limit', values: [1] })], - parseOutput: false - }); - - if (total === 0) { - return true; - } - - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - poolMaxDebounces *= steps; - - log('Found a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes') - } - - await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE)); - - return await awaitPools.wipeIndexes( - databaseId, - collectionId, - iteration + 1 - ); - }, - wipeVariables: async (functionId, iteration = 1) => { - if (iteration > poolMaxDebounces) { - return false; - } - - const { total } = await functionsListVariables({ - functionId, - queries: ['limit(1)'], - parseOutput: false - }); - - if (total === 0) { - return true; - } - - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - poolMaxDebounces *= steps; - - log('Found a large number of variables, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes') - } - - await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE)); - - return await awaitPools.wipeVariables( - functionId, - iteration + 1 - ); - }, - expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => { - if (iteration > poolMaxDebounces) { - return false; - } - - let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - poolMaxDebounces *= steps; - - log('Creating a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes') - } - - const { attributes } = await paginate(databasesListAttributes, { - databaseId, - collectionId, - parseOutput: false - }, 100, 'attributes'); - - const ready = attributes - .filter(attribute => { - if (attributeKeys.includes(attribute.key)) { - if (['stuck', 'failed'].includes(attribute.status)) { - throw new Error(`Attribute '${attribute.key}' failed!`); - } - - return attribute.status === 'available'; - } - - return false; - }) - .map(attribute => attribute.key); - - if (ready.length === attributeKeys.length) { - return true; - } - - await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE)); - - return await awaitPools.expectAttributes( - databaseId, - collectionId, - attributeKeys, - iteration + 1 - ); - }, - expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => { - if (iteration > poolMaxDebounces) { - return false; - } - - let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - poolMaxDebounces *= steps; - - log('Creating a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes') - } - - const { indexes } = await paginate(databasesListIndexes, { - databaseId, - collectionId, - parseOutput: false - }, 100, 'indexes'); - - const ready = indexes - .filter((index) => { - if (indexKeys.includes(index.key)) { - if (['stuck', 'failed'].includes(index.status)) { - throw new Error(`Index '${index.key}' failed!`); - } - - return index.status === 'available'; - } - - return false; - }) - .map(index => index.key); - - if (ready.length >= indexKeys.length) { - return true; - } - - await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE)); - - return await awaitPools.expectIndexes( - databaseId, - collectionId, - indexKeys, - iteration + 1 - ); - }, -} - -const deploy = new Command("deploy") - .description(commandDescriptions['deploy']) - .configureHelp({ - helpWidth: process.stdout.columns || 80 - }) - .action(actionRunner(async (_options, command) => { - command.help() - })); - -const deployFunction = async ({ functionId, all, yes } = {}) => { - let response = {}; - - const functionIds = []; - - if (functionId) { - functionIds.push(functionId); - } else if (all) { - const functions = localConfig.getFunctions(); - checkDeployConditions(localConfig); - if (functions.length === 0) { - throw new Error("No functions found in the current directory."); - } - functionIds.push(...functions.map((func, idx) => { - return func.$id; - })); - } - - if (functionIds.length <= 0) { - const answers = await inquirer.prompt(questionsDeployFunctions[0]); - functionIds.push(...answers.functions); - } - - let functions = functionIds.map((id) => { - const functions = localConfig.getFunctions(); - const func = functions.find((f) => f.$id === id); - - if (!func) { - throw new Error("Function '" + id + "' not found.") - } - - return func; - }); - - for (let func of functions) { - log(`Deploying function ${func.name} ( ${func['$id']} )`) - - try { - response = await functionsGet({ - functionId: func['$id'], - parseOutput: false, - }); - - if (response.runtime !== func.runtime) { - throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`); - } - - response = await functionsUpdate({ - functionId: func['$id'], - name: func.name, - execute: func.execute, - events: func.events, - schedule: func.schedule, - timeout: func.timeout, - enabled: func.enabled, - logging: func.logging, - entrypoint: func.entrypoint, - commands: func.commands, - vars: JSON.stringify(response.vars), - parseOutput: false - }); - } catch (e) { - if (e.code == 404) { - log(`Function ${func.name} ( ${func['$id']} ) does not exist in the project. Creating ... `); - response = await functionsCreate({ - functionId: func.$id || 'unique()', - name: func.name, - runtime: func.runtime, - execute: func.execute, - events: func.events, - schedule: func.schedule, - timeout: func.timeout, - enabled: func.enabled, - logging: func.logging, - entrypoint: func.entrypoint, - commands: func.commands, - vars: JSON.stringify(func.vars), - parseOutput: false - }); - - localConfig.updateFunction(func['$id'], { - "$id": response['$id'], - }); - - func["$id"] = response['$id']; - log(`Function ${func.name} created.`); - } else { - throw e; - } - } - - if (func.variables) { - // Delete existing variables - - const { total } = await functionsListVariables({ - functionId: func['$id'], - queries: [JSON.stringify({ method: 'limit', values: [1] })], - parseOutput: false - }); - - let deployVariables = yes; - - if (total === 0) { - deployVariables = true; - } else if (total > 0 && !yes) { - const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1]) - deployVariables = variableAnswers.override.toLowerCase() === "yes"; - } - - if (!deployVariables) { - log(`Skipping variables for ${func.name} ( ${func['$id']} )`); - } else { - log(`Deploying variables for ${func.name} ( ${func['$id']} )`); - - const { variables } = await paginate(functionsListVariables, { - functionId: func['$id'], - parseOutput: false - }, 100, 'variables'); - - await Promise.all(variables.map(async variable => { - await functionsDeleteVariable({ - functionId: func['$id'], - variableId: variable['$id'], - parseOutput: false - }); - })); - - let result = await awaitPools.wipeVariables(func['$id']); - if (!result) { - throw new Error("Variable deletion timed out."); - } - - // Deploy local variables - await Promise.all(Object.keys(func.variables).map(async localVariableKey => { - await functionsCreateVariable({ - functionId: func['$id'], - key: localVariableKey, - value: func.variables[localVariableKey], - parseOutput: false - }); - })); - } - } - - // Create tag - if (!func.entrypoint) { - const answers = await inquirer.prompt(questionsGetEntrypoint) - func.entrypoint = answers.entrypoint; - localConfig.updateFunction(func['$id'], func); - } - - try { - response = await functionsCreateDeployment({ - functionId: func['$id'], - entrypoint: func.entrypoint, - commands: func.commands, - code: func.path, - activate: true, - parseOutput: false - }) - - success(`Deployed ${func.name} ( ${func['$id']} )`); - - } catch (e) { - switch (e.code) { - case 'ENOENT': - error(`Function ${func.name} ( ${func['$id']} ) not found in the current directory. Skipping ...`); - break; - default: - throw e; - } - } - } - - success(`Deployed ${functions.length} functions`); -} - -const createAttribute = async (databaseId, collectionId, attribute) => { - switch (attribute.type) { - case 'string': - switch (attribute.format) { - case 'email': - return await databasesCreateEmailAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'url': - return await databasesCreateUrlAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'ip': - return await databasesCreateIpAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'enum': - return await databasesCreateEnumAttribute({ - databaseId, - collectionId, - key: attribute.key, - elements: attribute.elements, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - default: - return await databasesCreateStringAttribute({ - databaseId, - collectionId, - key: attribute.key, - size: attribute.size, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - - } - case 'integer': - return await databasesCreateIntegerAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - min: attribute.min, - max: attribute.max, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'double': - return databasesCreateFloatAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - min: attribute.min, - max: attribute.max, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'boolean': - return databasesCreateBooleanAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'datetime': - return databasesCreateDatetimeAttribute({ - databaseId, - collectionId, - key: attribute.key, - required: attribute.required, - xdefault: attribute.default, - array: attribute.array, - parseOutput: false - }) - case 'relationship': - return databasesCreateRelationshipAttribute({ - databaseId, - collectionId, - relatedCollectionId: attribute.relatedCollection, - type: attribute.relationType, - twoWay: attribute.twoWay, - key: attribute.key, - twoWayKey: attribute.twoWayKey, - onDelete: attribute.onDelete, - parseOutput: false - }) - } -} - -const deployCollection = async ({ all, yes } = {}) => { - let response = {}; - - const collections = []; - - if (all) { - checkDeployConditions(localConfig); - if (localConfig.getCollections().length === 0) { - throw new Error("No collections found in the current directory. Run `appwrite init collection` to fetch all your collections."); - } - collections.push(...localConfig.getCollections()); - } else { - const answers = await inquirer.prompt(questionsDeployCollections[0]) - const configCollections = new Map(); - localConfig.getCollections().forEach((c) => { - configCollections.set(`${c['databaseId']}|${c['$id']}`, c); - }); - answers.collections.forEach((a) => { - const collection = configCollections.get(a); - collections.push(collection); - }) - } - - for (let collection of collections) { - log(`Deploying collection ${collection.name} ( ${collection['databaseId']} - ${collection['$id']} )`) - - let databaseId; - - const localDatabase = localConfig.getDatabase(collection.databaseId); - - try { - const database = await databasesGet({ - databaseId: collection.databaseId, - parseOutput: false, - }); - - databaseId = database.$id; - - if (database.name !== (localDatabase.name ?? collection.databaseId)) { - await databasesUpdate({ - databaseId: collection.databaseId, - name: localDatabase.name ?? collection.databaseId, - parseOutput: false - }) - - success(`Updated ${localDatabase.name} ( ${collection.databaseId} )`); - } - } catch (err) { - log(`Database ${collection.databaseId} not found. Creating it now...`); - - const database = await databasesCreate({ - databaseId: collection.databaseId, - name: localDatabase.name ?? collection.databaseId, - parseOutput: false, - }); - - databaseId = database.$id; - } - - try { - response = await databasesGetCollection({ - databaseId, - collectionId: collection['$id'], - parseOutput: false, - }) - - log(`Collection ${collection.name} ( ${collection['$id']} ) already exists.`); - - if (!yes) { - const answers = await inquirer.prompt(questionsDeployCollections[1]) - if (answers.override.toLowerCase() !== "yes") { - log(`Received "${answers.override}". Skipping ${collection.name} ( ${collection['$id']} )`); - continue; - } - } - - log(`Deleting indexes and attributes ... `); - - const { indexes } = await paginate(databasesListIndexes, { - databaseId, - collectionId: collection['$id'], - parseOutput: false - }, 100, 'indexes'); - - await Promise.all(indexes.map(async index => { - await databasesDeleteIndex({ - databaseId, - collectionId: collection['$id'], - key: index.key, - parseOutput: false - }); - })); - - let result = await awaitPools.wipeIndexes(databaseId, collection['$id']); - if (!result) { - throw new Error("Index deletion timed out."); - } - - const { attributes } = await paginate(databasesListAttributes, { - databaseId, - collectionId: collection['$id'], - parseOutput: false - }, 100, 'attributes'); - - await Promise.all(attributes.map(async attribute => { - await databasesDeleteAttribute({ - databaseId, - collectionId: collection['$id'], - key: attribute.key, - parseOutput: false - }); - })); - - const deleteAttributesPoolStatus = await awaitPools.wipeAttributes(databaseId, collection['$id']); - if (!deleteAttributesPoolStatus) { - throw new Error("Attribute deletion timed out."); - } - - await databasesUpdateCollection({ - databaseId, - collectionId: collection['$id'], - name: collection.name, - documentSecurity: collection.documentSecurity, - permissions: collection['$permissions'], - enabled: collection.enabled, - parseOutput: false - }) - } catch (e) { - if (e.code == 404) { - log(`Collection ${collection.name} does not exist in the project. Creating ... `); - response = await databasesCreateCollection({ - databaseId, - collectionId: collection['$id'], - name: collection.name, - documentSecurity: collection.documentSecurity, - permissions: collection['$permissions'], - parseOutput: false - }) - - } else { - throw e; - } - } - - // Create all non-relationship attributes first - const attributes = collection.attributes.filter(attribute => attribute.type !== 'relationship'); - - await Promise.all(attributes.map(attribute => { - return createAttribute(databaseId, collection['$id'], attribute); - })); - - let result = await awaitPools.expectAttributes( - databaseId, - collection['$id'], - attributes.map(attribute => attribute.key) - ); - - if (!result) { - throw new Error("Attribute creation timed out."); - } - - success(`Created ${attributes.length} non-relationship attributes`); - - log(`Creating indexes ...`) - - await Promise.all(collection.indexes.map(async index => { - await databasesCreateIndex({ - databaseId, - collectionId: collection['$id'], - key: index.key, - type: index.type, - attributes: index.attributes, - orders: index.orders, - parseOutput: false - }); - })); - - result = await awaitPools.expectIndexes( - databaseId, - collection['$id'], - collection.indexes.map(attribute => attribute.key) - ); - - if (!result) { - throw new Error("Index creation timed out."); - } - - success(`Created ${collection.indexes.length} indexes`); - - success(`Deployed ${collection.name} ( ${collection['$id']} )`); - } - - // Create the relationship attributes - for (let collection of collections) { - const relationships = collection.attributes.filter(attribute => - attribute.type === 'relationship' && attribute.side === 'parent' - ); - - if (relationships.length === 0) { - continue; - } - - log(`Deploying relationships for collection ${collection.name} ( ${collection['$id']} )`); - - await Promise.all(relationships.map(attribute => { - return createAttribute(collection['databaseId'], collection['$id'], attribute); - })); - - let result = await awaitPools.expectAttributes( - collection['databaseId'], - collection['$id'], - relationships.map(attribute => attribute.key) - ); - - if (!result) { - throw new Error("Attribute creation timed out."); - } - - success(`Created ${relationships.length} relationship attributes`); - } -} - -const deployBucket = async ({ all, yes } = {}) => { - let response = {}; - - let bucketIds = []; - const configBuckets = localConfig.getBuckets(); - - if (all) { - checkDeployConditions(localConfig); - bucketIds.push(...configBuckets.map((b) => b.$id)); - } - - if (bucketIds.length === 0) { - const answers = await inquirer.prompt(questionsDeployBuckets[0]) - bucketIds.push(...answers.buckets); - } - - let buckets = []; - - for (const bucketId of bucketIds) { - const idBuckets = configBuckets.filter((b) => b.$id === bucketId); - buckets.push(...idBuckets); - } - - for (let bucket of buckets) { - log(`Deploying bucket ${bucket.name} ( ${bucket['$id']} )`) - - try { - response = await storageGetBucket({ - bucketId: bucket['$id'], - parseOutput: false, - }) - log(`Bucket ${bucket.name} ( ${bucket['$id']} ) already exists.`); - - if (!yes) { - const answers = await inquirer.prompt(questionsDeployBuckets[1]) - if (answers.override.toLowerCase() !== "yes") { - log(`Received "${answers.override}". Skipping ${bucket.name} ( ${bucket['$id']} )`); - continue; - } - } - - log(`Updating bucket ...`) - - await storageUpdateBucket({ - bucketId: bucket['$id'], - name: bucket.name, - permissions: bucket['$permissions'], - fileSecurity: bucket.fileSecurity, - enabled: bucket.enabled, - maximumFileSize: bucket.maximumFileSize, - allowedFileExtensions: bucket.allowedFileExtensions, - compression: bucket.compression, - encryption: bucket.encryption, - antivirus: bucket.antivirus, - compression: bucket.compression, - parseOutput: false - }); - - success(`Deployed ${bucket.name} ( ${bucket['$id']} )`); - } catch (e) { - if (e.code == 404) { - log(`Bucket ${bucket.name} does not exist in the project. Creating ... `); - - response = await storageCreateBucket({ - bucketId: bucket['$id'], - name: bucket.name, - permissions: bucket['$permissions'], - fileSecurity: bucket.fileSecurity, - enabled: bucket.enabled, - maximumFileSize: bucket.maximumFileSize, - allowedFileExtensions: bucket.allowedFileExtensions, - compression: bucket.compression, - encryption: bucket.encryption, - antivirus: bucket.antivirus, - parseOutput: false - }) - - success(`Deployed ${bucket.name} ( ${bucket['$id']} )`); - } else { - throw e; - } - } - } -} - -const deployTeam = async ({ all, yes } = {}) => { - let response = {}; - - let teamIds = []; - const configTeams = localConfig.getTeams(); - - if (all) { - checkDeployConditions(localConfig); - teamIds.push(...configTeams.map((t) => t.$id)); - } - - if (teamIds.length === 0) { - const answers = await inquirer.prompt(questionsDeployTeams[0]) - teamIds.push(...answers.teams); - } - - let teams = []; - - for (const teamId of teamIds) { - const idTeams = configTeams.filter((t) => t.$id === teamId); - teams.push(...idTeams); - } - - for (let team of teams) { - log(`Deploying team ${team.name} ( ${team['$id']} )`) - - try { - response = await teamsGet({ - teamId: team['$id'], - parseOutput: false, - }) - log(`Team ${team.name} ( ${team['$id']} ) already exists.`); - - if (!yes) { - const answers = await inquirer.prompt(questionsDeployTeams[1]) - if (answers.override.toLowerCase() !== "yes") { - log(`Received "${answers.override}". Skipping ${team.name} ( ${team['$id']} )`); - continue; - } - } - - log(`Updating team ...`) - - await teamsUpdateName({ - teamId: team['$id'], - name: team.name, - parseOutput: false - }); - - success(`Deployed ${team.name} ( ${team['$id']} )`); - } catch (e) { - if (e.code == 404) { - log(`Team ${team.name} does not exist in the project. Creating ... `); - - response = await teamsCreate({ - teamId: team['$id'], - name: team.name, - parseOutput: false - }) - - success(`Deployed ${team.name} ( ${team['$id']} )`); - } else { - throw e; - } - } - } -} - -deploy - .command("function") - .description("Deploy functions in the current directory.") - .option(`--functionId `, `Function ID`) - .option(`--all`, `Flag to deploy all functions`) - .option(`--yes`, `Flag to confirm all warnings`) - .action(actionRunner(deployFunction)); - -deploy - .command("collection") - .description("Deploy collections in the current project.") - .option(`--all`, `Flag to deploy all collections`) - .option(`--yes`, `Flag to confirm all warnings`) - .action(actionRunner(deployCollection)); - -deploy - .command("bucket") - .description("Deploy buckets in the current project.") - .option(`--all`, `Flag to deploy all buckets`) - .option(`--yes`, `Flag to confirm all warnings`) - .action(actionRunner(deployBucket)); - -deploy - .command("team") - .description("Deploy teams in the current project.") - .option(`--all`, `Flag to deploy all teams`) - .option(`--yes`, `Flag to confirm all warnings`) - .action(actionRunner(deployTeam)); - -module.exports = { - deploy -} diff --git a/lib/commands/functions.js b/lib/commands/functions.js index 360c7a9..f169303 100644 --- a/lib/commands/functions.js +++ b/lib/commands/functions.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const functions = new Command("functions").description(commandDescriptions['func * @typedef {Object} FunctionsListRequestParams * @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, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout, entrypoint, commands, installationId * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const functions = new Command("functions").description(commandDescriptions['func /** * @param {FunctionsListRequestParams} params */ -const functionsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'list'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -88,6 +95,7 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi * @property {boolean} logging Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. * @property {string} entrypoint Entrypoint File. This path is relative to the "providerRootDirectory". * @property {string} commands Build Commands. + * @property {string[]} scopes List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed. * @property {string} installationId Appwrite Installation ID for VCS (Version Control System) deployment. * @property {string} providerRepositoryId Repository ID of the repo linked to the function. * @property {string} providerBranch Production branch for the repo linked to the function. @@ -97,6 +105,7 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi * @property {string} templateOwner The name of the owner of the template. * @property {string} templateRootDirectory Path to function code in the template repo. * @property {string} templateBranch Production branch for the repo linked to the function template. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -104,8 +113,9 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi /** * @param {FunctionsCreateRequestParams} params */ -const functionsCreate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, logging, entrypoint, commands, installationId, providerRepositoryId, providerBranch, providerSilentMode, providerRootDirectory, templateRepository, templateOwner, templateRootDirectory, templateBranch, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsCreate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,templateRepository,templateOwner,templateRootDirectory,templateBranch,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions'; let payload = {}; if (typeof functionId !== 'undefined') { @@ -143,6 +153,10 @@ const functionsCreate = async ({ functionId, name, runtime, execute, events, sch if (typeof commands !== 'undefined') { payload['commands'] = commands; } + scopes = scopes === true ? [] : scopes; + if (typeof scopes !== 'undefined') { + payload['scopes'] = scopes; + } if (typeof installationId !== 'undefined') { payload['installationId'] = installationId; } @@ -181,12 +195,14 @@ const functionsCreate = async ({ functionId, name, runtime, execute, events, sch parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsListRuntimesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -194,8 +210,9 @@ const functionsCreate = async ({ functionId, name, runtime, execute, events, sch /** * @param {FunctionsListRuntimesRequestParams} params */ -const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsListRuntimes = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/runtimes'; let payload = {}; @@ -209,13 +226,15 @@ const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsGetUsageRequestParams * @property {FunctionUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -223,8 +242,9 @@ const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => /** * @param {FunctionsGetUsageRequestParams} params */ -const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGetUsage = async ({range,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/usage'; let payload = {}; if (typeof range !== 'undefined') { @@ -241,13 +261,15 @@ const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsGetRequestParams * @property {string} functionId Function ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -255,8 +277,9 @@ const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) /** * @param {FunctionsGetRequestParams} params */ -const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGet = async ({functionId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); let payload = {}; @@ -267,11 +290,16 @@ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'get', functionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -287,11 +315,13 @@ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) * @property {boolean} logging Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. * @property {string} entrypoint Entrypoint File. This path is relative to the "providerRootDirectory". * @property {string} commands Build Commands. + * @property {string[]} scopes List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed. * @property {string} installationId Appwrite Installation ID for VCS (Version Controle System) deployment. * @property {string} providerRepositoryId Repository ID of the repo linked to the function * @property {string} providerBranch Production branch for the repo linked to the function * @property {boolean} providerSilentMode Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @property {string} providerRootDirectory Path to function code in the linked repo. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -299,8 +329,9 @@ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) /** * @param {FunctionsUpdateRequestParams} params */ -const functionsUpdate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, logging, entrypoint, commands, installationId, providerRepositoryId, providerBranch, providerSilentMode, providerRootDirectory, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsUpdate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); let payload = {}; if (typeof name !== 'undefined') { @@ -335,6 +366,10 @@ const functionsUpdate = async ({ functionId, name, runtime, execute, events, sch if (typeof commands !== 'undefined') { payload['commands'] = commands; } + scopes = scopes === true ? [] : scopes; + if (typeof scopes !== 'undefined') { + payload['scopes'] = scopes; + } if (typeof installationId !== 'undefined') { payload['installationId'] = installationId; } @@ -361,13 +396,15 @@ const functionsUpdate = async ({ functionId, name, runtime, execute, events, sch parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsDeleteRequestParams * @property {string} functionId Function ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -375,8 +412,9 @@ const functionsUpdate = async ({ functionId, name, runtime, execute, events, sch /** * @param {FunctionsDeleteRequestParams} params */ -const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsDelete = async ({functionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); let payload = {}; @@ -390,8 +428,9 @@ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined parse(response) success() } - + return response; + } /** @@ -399,6 +438,7 @@ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined * @property {string} functionId Function ID. * @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: size, buildId, activate, entrypoint, commands * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -406,8 +446,9 @@ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined /** * @param {FunctionsListDeploymentsRequestParams} params */ -const functionsListDeployments = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsListDeployments = async ({functionId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments'.replace('{functionId}', functionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -424,11 +465,16 @@ const functionsListDeployments = async ({ functionId, queries, search, parseOutp }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'listDeployments', functionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -438,6 +484,7 @@ const functionsListDeployments = async ({ functionId, queries, search, parseOutp * @property {boolean} activate Automatically activate the deployment when it is finished building. * @property {string} entrypoint Entrypoint File. * @property {string} commands Build Commands. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {CallableFunction} onProgress @@ -446,8 +493,9 @@ const functionsListDeployments = async ({ functionId, queries, search, parseOutp /** * @param {FunctionsCreateDeploymentRequestParams} params */ -const functionsCreateDeployment = async ({ functionId, code, activate, entrypoint, commands, parseOutput = true, sdk = undefined, onProgress = () => {}}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsCreateDeployment = async ({functionId,code,activate,entrypoint,commands,parseOutput = true, overrideForCli = false, sdk = undefined,onProgress = () => {}}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments'.replace('{functionId}', functionId); let payload = {}; if (typeof entrypoint !== 'undefined') { @@ -460,19 +508,19 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin if (!fs.lstatSync(folderPath).isDirectory()) { throw new Error('The path is not a directory.'); } - + const ignorer = ignore(); const func = localConfig.getFunction(functionId); + ignorer.add('.appwrite'); + if (func.ignore) { ignorer.add(func.ignore); - log('Ignoring files using configuration from appwrite.json'); } else if (fs.existsSync(pathLib.join(code, '.gitignore'))) { ignorer.add(fs.readFileSync(pathLib.join(code, '.gitignore')).toString()); - log('Ignoring files in .gitignore'); } - + const files = getAllFiles(code).map((file) => pathLib.relative(code, file)).filter((file) => !ignorer.ignores(file)); await tar @@ -502,7 +550,7 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin } const size = code.size; - + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -529,7 +577,7 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin } let uploadableChunkTrimmed; - + if(currentPosition + 1 >= client.CHUNK_SIZE) { uploadableChunkTrimmed = uploadableChunk; } else { @@ -582,8 +630,8 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin await uploadChunk(true); } - fs.unlinkSync(filePath); - + await fs.unlink(filePath,()=>{}); + if (parseOutput) { parse(response) success() @@ -596,6 +644,7 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin * @typedef {Object} FunctionsGetDeploymentRequestParams * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -603,8 +652,9 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin /** * @param {FunctionsGetDeploymentRequestParams} params */ -const functionsGetDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGetDeployment = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); let payload = {}; @@ -615,17 +665,23 @@ const functionsGetDeployment = async ({ functionId, deploymentId, parseOutput = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'getDeployment', functionId, deploymentId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} FunctionsUpdateDeploymentRequestParams * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -633,8 +689,9 @@ const functionsGetDeployment = async ({ functionId, deploymentId, parseOutput = /** * @param {FunctionsUpdateDeploymentRequestParams} params */ -const functionsUpdateDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsUpdateDeployment = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); let payload = {}; @@ -648,14 +705,16 @@ const functionsUpdateDeployment = async ({ functionId, deploymentId, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsDeleteDeploymentRequestParams * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -663,8 +722,9 @@ const functionsUpdateDeployment = async ({ functionId, deploymentId, parseOutput /** * @param {FunctionsDeleteDeploymentRequestParams} params */ -const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsDeleteDeployment = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); let payload = {}; @@ -678,8 +738,9 @@ const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput parse(response) success() } - + return response; + } /** @@ -687,6 +748,7 @@ const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. * @property {string} buildId Build unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -694,10 +756,14 @@ const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput /** * @param {FunctionsCreateBuildRequestParams} params */ -const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; - let apiPath = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId); +const functionsCreateBuild = async ({functionId,deploymentId,buildId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); let payload = {}; + if (typeof buildId !== 'undefined') { + payload['buildId'] = buildId; + } let response = undefined; @@ -709,14 +775,49 @@ const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOu parse(response) success() } - + + return response; + +} + +/** + * @typedef {Object} FunctionsUpdateDeploymentBuildRequestParams + * @property {string} functionId Function ID. + * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {FunctionsUpdateDeploymentBuildRequestParams} params + */ +const functionsUpdateDeploymentBuild = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); + let payload = {}; + + let response = undefined; + + response = await client.call('patch', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + return response; + } /** * @typedef {Object} FunctionsDownloadDeploymentRequestParams * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -725,14 +826,17 @@ const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOu /** * @param {FunctionsDownloadDeploymentRequestParams} params */ -const functionsDownloadDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsDownloadDeployment = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); let payload = {}; - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -740,21 +844,26 @@ const functionsDownloadDeployment = async ({ functionId, deploymentId, parseOutp 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsListExecutionsRequestParams * @property {string} functionId Function ID. - * @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: trigger, status, responseStatusCode, duration + * @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: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -762,8 +871,9 @@ const functionsDownloadDeployment = async ({ functionId, deploymentId, parseOutp /** * @param {FunctionsListExecutionsRequestParams} params */ -const functionsListExecutions = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsListExecutions = async ({functionId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); let payload = {}; if (typeof queries !== 'undefined') { @@ -780,11 +890,16 @@ const functionsListExecutions = async ({ functionId, queries, search, parseOutpu }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'listExecutions', functionId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -795,6 +910,8 @@ const functionsListExecutions = async ({ functionId, queries, search, parseOutpu * @property {string} xpath HTTP path of execution. Path can include query params. Default value is / * @property {ExecutionMethod} method HTTP method of execution. Default value is GET. * @property {object} headers HTTP headers of execution. Defaults to empty. + * @property {string} scheduledAt Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -802,8 +919,9 @@ const functionsListExecutions = async ({ functionId, queries, search, parseOutpu /** * @param {FunctionsCreateExecutionRequestParams} params */ -const functionsCreateExecution = async ({ functionId, body, async, xpath, method, headers, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsCreateExecution = async ({functionId,body,async,xpath,method,headers,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); let payload = {}; if (typeof body !== 'undefined') { @@ -821,6 +939,9 @@ const functionsCreateExecution = async ({ functionId, body, async, xpath, method if (typeof headers !== 'undefined') { payload['headers'] = JSON.parse(headers); } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } let response = undefined; @@ -832,14 +953,16 @@ const functionsCreateExecution = async ({ functionId, body, async, xpath, method parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsGetExecutionRequestParams * @property {string} functionId Function ID. * @property {string} executionId Execution ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -847,8 +970,9 @@ const functionsCreateExecution = async ({ functionId, body, async, xpath, method /** * @param {FunctionsGetExecutionRequestParams} params */ -const functionsGetExecution = async ({ functionId, executionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGetExecution = async ({functionId,executionId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); let payload = {}; @@ -858,18 +982,57 @@ const functionsGetExecution = async ({ functionId, executionId, parseOutput = tr 'content-type': 'application/json', }, payload); + if (parseOutput) { + if(console) { + showConsoleLink('functions', 'getExecution', functionId, executionId); + } else { + parse(response) + success() + } + } + + return response; + +} + +/** + * @typedef {Object} FunctionsDeleteExecutionRequestParams + * @property {string} functionId Function ID. + * @property {string} executionId Execution ID. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {FunctionsDeleteExecutionRequestParams} params + */ +const functionsDeleteExecution = async ({functionId,executionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); + let payload = {}; + + let response = undefined; + + response = await client.call('delete', apiPath, { + 'content-type': 'application/json', + }, payload); + if (parseOutput) { parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsGetFunctionUsageRequestParams * @property {string} functionId Function ID. * @property {FunctionUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -877,8 +1040,9 @@ const functionsGetExecution = async ({ functionId, executionId, parseOutput = tr /** * @param {FunctionsGetFunctionUsageRequestParams} params */ -const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGetFunctionUsage = async ({functionId,range,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/usage'.replace('{functionId}', functionId); let payload = {}; if (typeof range !== 'undefined') { @@ -892,16 +1056,22 @@ const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'getFunctionUsage', functionId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} FunctionsListVariablesRequestParams * @property {string} functionId Function unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -909,8 +1079,9 @@ const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true /** * @param {FunctionsListVariablesRequestParams} params */ -const functionsListVariables = async ({ functionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsListVariables = async ({functionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/variables'.replace('{functionId}', functionId); let payload = {}; @@ -924,8 +1095,9 @@ const functionsListVariables = async ({ functionId, parseOutput = true, sdk = un parse(response) success() } - + return response; + } /** @@ -933,6 +1105,7 @@ const functionsListVariables = async ({ functionId, parseOutput = true, sdk = un * @property {string} functionId Function unique ID. * @property {string} key Variable key. Max length: 255 chars. * @property {string} value Variable value. Max length: 8192 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -940,8 +1113,9 @@ const functionsListVariables = async ({ functionId, parseOutput = true, sdk = un /** * @param {FunctionsCreateVariableRequestParams} params */ -const functionsCreateVariable = async ({ functionId, key, value, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsCreateVariable = async ({functionId,key,value,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/variables'.replace('{functionId}', functionId); let payload = {}; if (typeof key !== 'undefined') { @@ -961,14 +1135,16 @@ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = t parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsGetVariableRequestParams * @property {string} functionId Function unique ID. * @property {string} variableId Variable unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -976,8 +1152,9 @@ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = t /** * @param {FunctionsGetVariableRequestParams} params */ -const functionsGetVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsGetVariable = async ({functionId,variableId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); let payload = {}; @@ -991,8 +1168,9 @@ const functionsGetVariable = async ({ functionId, variableId, parseOutput = true parse(response) success() } - + return response; + } /** @@ -1001,6 +1179,7 @@ const functionsGetVariable = async ({ functionId, variableId, parseOutput = true * @property {string} variableId Variable unique ID. * @property {string} key Variable key. Max length: 255 chars. * @property {string} value Variable value. Max length: 8192 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1008,8 +1187,9 @@ const functionsGetVariable = async ({ functionId, variableId, parseOutput = true /** * @param {FunctionsUpdateVariableRequestParams} params */ -const functionsUpdateVariable = async ({ functionId, variableId, key, value, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsUpdateVariable = async ({functionId,variableId,key,value,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); let payload = {}; if (typeof key !== 'undefined') { @@ -1029,14 +1209,16 @@ const functionsUpdateVariable = async ({ functionId, variableId, key, value, par parse(response) success() } - + return response; + } /** * @typedef {Object} FunctionsDeleteVariableRequestParams * @property {string} functionId Function unique ID. * @property {string} variableId Variable unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1044,8 +1226,9 @@ const functionsUpdateVariable = async ({ functionId, variableId, key, value, par /** * @param {FunctionsDeleteVariableRequestParams} params */ -const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const functionsDeleteVariable = async ({functionId,variableId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); let payload = {}; @@ -1059,8 +1242,9 @@ const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = t parse(response) success() } - + return response; + } functions @@ -1068,6 +1252,7 @@ functions .description(`Get a list of all the project's functions. You can use the query params to filter your results.`) .option(`--queries [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, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout, entrypoint, commands, installationId`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsList)) functions @@ -1084,6 +1269,7 @@ functions .option(`--logging `, `Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project.`, parseBool) .option(`--entrypoint `, `Entrypoint File. This path is relative to the "providerRootDirectory".`) .option(`--commands `, `Build Commands.`) + .option(`--scopes [scopes...]`, `List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed.`) .option(`--installationId `, `Appwrite Installation ID for VCS (Version Control System) deployment.`) .option(`--providerRepositoryId `, `Repository ID of the repo linked to the function.`) .option(`--providerBranch `, `Production branch for the repo linked to the function.`) @@ -1110,6 +1296,7 @@ functions .command(`get`) .description(`Get a function by its unique ID.`) .requiredOption(`--functionId `, `Function ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGet)) functions @@ -1126,6 +1313,7 @@ functions .option(`--logging `, `Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project.`, parseBool) .option(`--entrypoint `, `Entrypoint File. This path is relative to the "providerRootDirectory".`) .option(`--commands `, `Build Commands.`) + .option(`--scopes [scopes...]`, `List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed.`) .option(`--installationId `, `Appwrite Installation ID for VCS (Version Controle System) deployment.`) .option(`--providerRepositoryId `, `Repository ID of the repo linked to the function`) .option(`--providerBranch `, `Production branch for the repo linked to the function`) @@ -1145,6 +1333,7 @@ functions .requiredOption(`--functionId `, `Function ID.`) .option(`--queries [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: size, buildId, activate, entrypoint, commands`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsListDeployments)) functions @@ -1162,6 +1351,7 @@ functions .description(`Get a code deployment by its unique ID.`) .requiredOption(`--functionId `, `Function ID.`) .requiredOption(`--deploymentId `, `Deployment ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetDeployment)) functions @@ -1180,12 +1370,19 @@ functions functions .command(`createBuild`) - .description(`Create a new build for an Appwrite Function deployment. This endpoint can be used to retry a failed build.`) + .description(``) .requiredOption(`--functionId `, `Function ID.`) .requiredOption(`--deploymentId `, `Deployment ID.`) - .requiredOption(`--buildId `, `Build unique ID.`) + .option(`--buildId `, `Build unique ID.`) .action(actionRunner(functionsCreateBuild)) +functions + .command(`updateDeploymentBuild`) + .description(``) + .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--deploymentId `, `Deployment ID.`) + .action(actionRunner(functionsUpdateDeploymentBuild)) + functions .command(`downloadDeployment`) .description(`Get a Deployment's contents by its unique ID. This endpoint supports range requests for partial or streaming file download.`) @@ -1198,8 +1395,9 @@ functions .command(`listExecutions`) .description(`Get a list of all the current user function execution logs. You can use the query params to filter your results.`) .requiredOption(`--functionId `, `Function ID.`) - .option(`--queries [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: trigger, status, responseStatusCode, duration`) + .option(`--queries [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: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsListExecutions)) functions @@ -1211,6 +1409,7 @@ functions .option(`--xpath `, `HTTP path of execution. Path can include query params. Default value is /`) .option(`--method `, `HTTP method of execution. Default value is GET.`) .option(`--headers `, `HTTP headers of execution. Defaults to empty.`) + .option(`--scheduledAt `, `Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(functionsCreateExecution)) functions @@ -1218,13 +1417,22 @@ functions .description(`Get a function execution log by its unique ID.`) .requiredOption(`--functionId `, `Function ID.`) .requiredOption(`--executionId `, `Execution ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetExecution)) +functions + .command(`deleteExecution`) + .description(`Delete a function execution by its unique ID. `) + .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--executionId `, `Execution ID.`) + .action(actionRunner(functionsDeleteExecution)) + functions .command(`getFunctionUsage`) .description(``) .requiredOption(`--functionId `, `Function ID.`) .option(`--range `, `Date range.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetFunctionUsage)) functions @@ -1279,14 +1487,16 @@ module.exports = { functionsUpdateDeployment, functionsDeleteDeployment, functionsCreateBuild, + functionsUpdateDeploymentBuild, functionsDownloadDeployment, functionsListExecutions, functionsCreateExecution, functionsGetExecution, + functionsDeleteExecution, functionsGetFunctionUsage, functionsListVariables, functionsCreateVariable, functionsGetVariable, functionsUpdateVariable, functionsDeleteVariable -}; \ No newline at end of file +}; diff --git a/lib/commands/generic.js b/lib/commands/generic.js index b29b2b6..c6b1a4c 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -3,20 +3,44 @@ const { Command } = require("commander"); const Client = require("../client"); const { sdkForConsole } = require("../sdks"); const { globalConfig, localConfig } = require("../config"); -const { actionRunner, success, parseBool, commandDescriptions, log, parse } = require("../parser"); -const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions"); -const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); +const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable, cliConfig } = require("../parser"); +const ID = require("../id"); +const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions"); +const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); -const login = new Command("login") - .description(commandDescriptions['login']) - .configureHelp({ - helpWidth: process.stdout.columns || 80 - }) - .action(actionRunner(async () => { - const answers = await inquirer.prompt(questionsLogin) +const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1'; - let client = await sdkForConsole(false); +const loginCommand = async ({ email, password, endpoint, mfa, code }) => { + const oldCurrent = globalConfig.getCurrentSession(); + let configEndpoint = endpoint ?? DEFAULT_ENDPOINT; + + const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin); + + if (answers.method === 'select') { + const accountId = answers.accountId; + + if (!globalConfig.getSessionIds().includes(accountId)) { + throw Error('Session ID not found'); + } + + globalConfig.setCurrentSession(accountId); + success(`Current account is ${accountId}`); + + return; + } + + const id = ID.unique(); + + globalConfig.addSession(id, {}); + globalConfig.setCurrentSession(id); + globalConfig.setEndpoint(configEndpoint); + globalConfig.setEmail(answers.email); + let client = await sdkForConsole(false); + + let account; + + try { await accountCreateEmailPasswordSession({ email: answers.email, password: answers.password, @@ -26,6 +50,57 @@ const login = new Command("login") client.setCookie(globalConfig.getCookie()); + account = await accountGet({ + sdk: client, + parseOutput: false + }); + } catch (error) { + if (error.response === 'user_more_factors_required') { + const { factor } = mfa ? { factor: mfa } : await inquirer.prompt(questionsListFactors); + + const challenge = await accountCreateMfaChallenge({ + factor, + parseOutput: false, + sdk: client + }); + + const { otp } = code ? { otp: code } : await inquirer.prompt(questionsMfaChallenge); + + await accountUpdateMfaChallenge({ + challengeId: challenge.$id, + otp, + parseOutput: false, + sdk: client + }); + + account = await accountGet({ + sdk: client, + parseOutput: false + }); + } else { + globalConfig.removeSession(id); + globalConfig.setCurrentSession(oldCurrent); + if(endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials'){ + log('Use the --endpoint option for self-hosted instances') + } + throw error; + } + } + + success("Signed in as user with ID: " + account.$id); + log("Next you can create or link to your project using 'appwrite init project'"); +}; + +const whoami = new Command("whoami") + .description(commandDescriptions['whoami']) + .action(actionRunner(async () => { + if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { + error("No user is signed in. To sign in, run: appwrite login "); + return; + } + + let client = await sdkForConsole(false); + let account; try { @@ -33,43 +108,49 @@ const login = new Command("login") sdk: client, parseOutput: false }); - } catch(error) { - if (error.response === 'user_more_factors_required') { - const { factor } = await inquirer.prompt(questionsListFactors); - - const challenge = await accountCreateMfaChallenge({ - factor, - parseOutput: false, - sdk: client - }); - - const { otp } = await inquirer.prompt(questionsMfaChallenge); - - await accountUpdateMfaChallenge({ - challengeId: challenge.$id, - otp, - parseOutput: false, - sdk: client - }); - - account = await accountGet({ - sdk: client, - parseOutput: false - }); - } else { - throw error; + } catch (error) { + error("No user is signed in. To sign in, run: appwrite login"); + return; + } + + const data = [ + { + 'ID': account.$id, + 'Name': account.name, + 'Email': account.email, + 'MFA enabled': account.mfa ? 'Yes' : 'No', + 'Endpoint': globalConfig.getEndpoint() } + ]; + + if(cliConfig.json) { + console.log(data); + return; } - success("Signed in as user with ID: " + account.$id); + drawTable(data) })); -const logout = new Command("logout") - .description(commandDescriptions['logout']) +const register = new Command("register") + .description(commandDescriptions['register']) + .action(actionRunner(async () => { + log('Visit https://cloud.appwrite.io/register to create an account') + })); + +const login = new Command("login") + .description(commandDescriptions['login']) + .option(`--email [email]`, `User email`) + .option(`--password [password]`, `User password`) + .option(`--endpoint [endpoint]`, `Appwrite endpoint for self hosted instances`) + .option(`--mfa [factor]`, `Multi-factor authentication login factor: totp, email, phone or recoveryCode`) + .option(`--code [code]`, `Multi-factor code`) .configureHelp({ helpWidth: process.stdout.columns || 80 }) - .action(actionRunner(async () => { + .action(actionRunner(loginCommand)); + +const deleteSession = async (accountId) => { + try { let client = await sdkForConsole(); await accountDeleteSession({ @@ -78,8 +159,51 @@ const logout = new Command("logout") sdk: client }) - globalConfig.setCookie(""); - success() + globalConfig.removeSession(accountId); + } catch (e) { + error('Unable to log out, removing locally saved session information') + } + globalConfig.removeSession(accountId); +} + +const logout = new Command("logout") + .description(commandDescriptions['logout']) + .configureHelp({ + helpWidth: process.stdout.columns || 80 + }) + .action(actionRunner(async () => { + const sessions = globalConfig.getSessions(); + const current = globalConfig.getCurrentSession(); + + if (current === '') { + return; + } + if (sessions.length === 1) { + await deleteSession(current); + success(); + + return; + } + + const answers = await inquirer.prompt(questionsLogout); + + if (answers.accounts) { + for (let accountId of answers.accounts) { + globalConfig.setCurrentSession(accountId); + await deleteSession(accountId); + } + } + + const remainingSessions = globalConfig.getSessions(); + + if (remainingSessions .length > 0 && remainingSessions .filter(session => session.id === current).length !== 1) { + const accountId = remainingSessions [0].id; + globalConfig.setCurrentSession(accountId); + + success(`Current account is ${accountId}`); + } + + success(); })); const client = new Command("client") @@ -87,12 +211,12 @@ const client = new Command("client") .configureHelp({ helpWidth: process.stdout.columns || 80 }) - .option("--selfSigned ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) - .option("--endpoint ", "Set your Appwrite server endpoint") - .option("--projectId ", "Set your Appwrite project ID") - .option("--key ", "Set your Appwrite server's API key") - .option("--debug", "Print CLI debug information") - .option("--reset", "Reset the CLI configuration") + .option("-ss, --selfSigned ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) + .option("-e, --endpoint ", "Set your Appwrite server endpoint") + .option("-p, --projectId ", "Set your Appwrite project ID") + .option("-k, --key ", "Set your Appwrite server's API key") + .option("-d, --debug", "Print CLI debug information") + .option("-r, --reset", "Reset the CLI configuration") .action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }, command) => { if (selfSigned == undefined && endpoint == undefined && projectId == undefined && key == undefined && debug == undefined && reset == undefined) { command.help() @@ -111,6 +235,7 @@ const client = new Command("client") if (endpoint !== undefined) { try { + const id = ID.unique(); let url = new URL(endpoint); if (url.protocol !== "http:" && url.protocol !== "https:") { throw new Error(); @@ -125,7 +250,8 @@ const client = new Command("client") if (!response.version) { throw new Error(); } - + globalConfig.setCurrentSession(id); + globalConfig.addSession(id, {}); globalConfig.setEndpoint(endpoint); } catch (_) { throw new Error("Invalid endpoint or your Appwrite server is not running as expected."); @@ -145,18 +271,44 @@ const client = new Command("client") } if (reset !== undefined) { - globalConfig.setEndpoint(""); - globalConfig.setKey(""); - globalConfig.setCookie(""); - globalConfig.setSelfSigned(""); - localConfig.setProject("", ""); + const sessions = globalConfig.getSessions(); + + for (let accountId of sessions.map(session => session.id)) { + globalConfig.setCurrentSession(accountId); + await deleteSession(accountId); + } } success() })); +const migrate = async () => { + if (!globalConfig.has('endpoint') || !globalConfig.has('cookie')) { + return; + } + + const endpoint = globalConfig.get('endpoint'); + const cookie = globalConfig.get('cookie'); + + const id = ID.unique(); + const data = { + endpoint, + cookie, + email: 'legacy' + }; + + globalConfig.addSession(id, data); + globalConfig.setCurrentSession(id); + globalConfig.delete('endpoint'); + globalConfig.delete('cookie'); + +} module.exports = { + loginCommand, + whoami, + register, login, logout, + migrate, client }; diff --git a/lib/commands/graphql.js b/lib/commands/graphql.js index 2d4c360..8c6a90b 100644 --- a/lib/commands/graphql.js +++ b/lib/commands/graphql.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -42,6 +42,7 @@ const graphql = new Command("graphql").description(commandDescriptions['graphql' /** * @typedef {Object} GraphqlQueryRequestParams * @property {object} query The query or queries to execute. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -49,8 +50,9 @@ const graphql = new Command("graphql").description(commandDescriptions['graphql' /** * @param {GraphqlQueryRequestParams} params */ -const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const graphqlQuery = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/graphql'; let payload = {}; if (typeof query !== 'undefined') { @@ -68,13 +70,15 @@ const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} GraphqlMutationRequestParams * @property {object} query The query or queries to execute. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -82,8 +86,9 @@ const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => { /** * @param {GraphqlMutationRequestParams} params */ -const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const graphqlMutation = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/graphql/mutation'; let payload = {}; if (typeof query !== 'undefined') { @@ -101,8 +106,9 @@ const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } graphql @@ -121,4 +127,4 @@ module.exports = { graphql, graphqlQuery, graphqlMutation -}; \ No newline at end of file +}; diff --git a/lib/commands/health.js b/lib/commands/health.js index e0f6d08..9f028ee 100644 --- a/lib/commands/health.js +++ b/lib/commands/health.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -41,6 +41,7 @@ const health = new Command("health").description(commandDescriptions['health']). /** * @typedef {Object} HealthGetRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -48,8 +49,9 @@ const health = new Command("health").description(commandDescriptions['health']). /** * @param {HealthGetRequestParams} params */ -const healthGet = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGet = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health'; let payload = {}; @@ -63,12 +65,14 @@ const healthGet = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetAntivirusRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -76,8 +80,9 @@ const healthGet = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetAntivirusRequestParams} params */ -const healthGetAntivirus = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetAntivirus = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/anti-virus'; let payload = {}; @@ -91,12 +96,14 @@ const healthGetAntivirus = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetCacheRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -104,8 +111,9 @@ const healthGetAntivirus = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetCacheRequestParams} params */ -const healthGetCache = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetCache = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/cache'; let payload = {}; @@ -119,13 +127,15 @@ const healthGetCache = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetCertificateRequestParams * @property {string} domain string + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -133,8 +143,9 @@ const healthGetCache = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetCertificateRequestParams} params */ -const healthGetCertificate = async ({ domain, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetCertificate = async ({domain,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/certificate'; let payload = {}; if (typeof domain !== 'undefined') { @@ -151,12 +162,14 @@ const healthGetCertificate = async ({ domain, parseOutput = true, sdk = undefine parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetDBRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -164,8 +177,9 @@ const healthGetCertificate = async ({ domain, parseOutput = true, sdk = undefine /** * @param {HealthGetDBRequestParams} params */ -const healthGetDB = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetDB = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/db'; let payload = {}; @@ -179,12 +193,14 @@ const healthGetDB = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetPubSubRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -192,8 +208,9 @@ const healthGetDB = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetPubSubRequestParams} params */ -const healthGetPubSub = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetPubSub = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/pubsub'; let payload = {}; @@ -207,12 +224,14 @@ const healthGetPubSub = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -220,8 +239,9 @@ const healthGetPubSub = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetQueueRequestParams} params */ -const healthGetQueue = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueue = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue'; let payload = {}; @@ -235,13 +255,15 @@ const healthGetQueue = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueBuildsRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -249,8 +271,9 @@ const healthGetQueue = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetQueueBuildsRequestParams} params */ -const healthGetQueueBuilds = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueBuilds = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/builds'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -267,13 +290,15 @@ const healthGetQueueBuilds = async ({ threshold, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueCertificatesRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -281,8 +306,9 @@ const healthGetQueueBuilds = async ({ threshold, parseOutput = true, sdk = undef /** * @param {HealthGetQueueCertificatesRequestParams} params */ -const healthGetQueueCertificates = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueCertificates = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/certificates'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -299,14 +325,16 @@ const healthGetQueueCertificates = async ({ threshold, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueDatabasesRequestParams * @property {string} name Queue name for which to check the queue size * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -314,8 +342,9 @@ const healthGetQueueCertificates = async ({ threshold, parseOutput = true, sdk = /** * @param {HealthGetQueueDatabasesRequestParams} params */ -const healthGetQueueDatabases = async ({ name, threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueDatabases = async ({name,threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/databases'; let payload = {}; if (typeof name !== 'undefined') { @@ -335,13 +364,15 @@ const healthGetQueueDatabases = async ({ name, threshold, parseOutput = true, sd parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueDeletesRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -349,8 +380,9 @@ const healthGetQueueDatabases = async ({ name, threshold, parseOutput = true, sd /** * @param {HealthGetQueueDeletesRequestParams} params */ -const healthGetQueueDeletes = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueDeletes = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/deletes'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -367,14 +399,16 @@ const healthGetQueueDeletes = async ({ threshold, parseOutput = true, sdk = unde parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetFailedJobsRequestParams * @property {Name} name The name of the queue * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -382,8 +416,9 @@ const healthGetQueueDeletes = async ({ threshold, parseOutput = true, sdk = unde /** * @param {HealthGetFailedJobsRequestParams} params */ -const healthGetFailedJobs = async ({ name, threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetFailedJobs = async ({name,threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/failed/{name}'.replace('{name}', name); let payload = {}; if (typeof threshold !== 'undefined') { @@ -400,13 +435,15 @@ const healthGetFailedJobs = async ({ name, threshold, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueFunctionsRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -414,8 +451,9 @@ const healthGetFailedJobs = async ({ name, threshold, parseOutput = true, sdk = /** * @param {HealthGetQueueFunctionsRequestParams} params */ -const healthGetQueueFunctions = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueFunctions = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/functions'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -432,13 +470,15 @@ const healthGetQueueFunctions = async ({ threshold, parseOutput = true, sdk = un parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueLogsRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -446,8 +486,9 @@ const healthGetQueueFunctions = async ({ threshold, parseOutput = true, sdk = un /** * @param {HealthGetQueueLogsRequestParams} params */ -const healthGetQueueLogs = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueLogs = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/logs'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -464,13 +505,15 @@ const healthGetQueueLogs = async ({ threshold, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueMailsRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -478,8 +521,9 @@ const healthGetQueueLogs = async ({ threshold, parseOutput = true, sdk = undefin /** * @param {HealthGetQueueMailsRequestParams} params */ -const healthGetQueueMails = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueMails = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/mails'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -496,13 +540,15 @@ const healthGetQueueMails = async ({ threshold, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueMessagingRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -510,8 +556,9 @@ const healthGetQueueMails = async ({ threshold, parseOutput = true, sdk = undefi /** * @param {HealthGetQueueMessagingRequestParams} params */ -const healthGetQueueMessaging = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueMessaging = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/messaging'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -528,13 +575,15 @@ const healthGetQueueMessaging = async ({ threshold, parseOutput = true, sdk = un parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueMigrationsRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -542,8 +591,9 @@ const healthGetQueueMessaging = async ({ threshold, parseOutput = true, sdk = un /** * @param {HealthGetQueueMigrationsRequestParams} params */ -const healthGetQueueMigrations = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueMigrations = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/migrations'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -560,13 +610,15 @@ const healthGetQueueMigrations = async ({ threshold, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueUsageRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -574,8 +626,9 @@ const healthGetQueueMigrations = async ({ threshold, parseOutput = true, sdk = u /** * @param {HealthGetQueueUsageRequestParams} params */ -const healthGetQueueUsage = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueUsage = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/usage'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -592,13 +645,15 @@ const healthGetQueueUsage = async ({ threshold, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueUsageDumpRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -606,8 +661,9 @@ const healthGetQueueUsage = async ({ threshold, parseOutput = true, sdk = undefi /** * @param {HealthGetQueueUsageDumpRequestParams} params */ -const healthGetQueueUsageDump = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueUsageDump = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/usage-dump'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -624,13 +680,15 @@ const healthGetQueueUsageDump = async ({ threshold, parseOutput = true, sdk = un parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetQueueWebhooksRequestParams * @property {number} threshold Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -638,8 +696,9 @@ const healthGetQueueUsageDump = async ({ threshold, parseOutput = true, sdk = un /** * @param {HealthGetQueueWebhooksRequestParams} params */ -const healthGetQueueWebhooks = async ({ threshold, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetQueueWebhooks = async ({threshold,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/queue/webhooks'; let payload = {}; if (typeof threshold !== 'undefined') { @@ -656,12 +715,14 @@ const healthGetQueueWebhooks = async ({ threshold, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetStorageRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -669,8 +730,9 @@ const healthGetQueueWebhooks = async ({ threshold, parseOutput = true, sdk = und /** * @param {HealthGetStorageRequestParams} params */ -const healthGetStorage = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetStorage = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/storage'; let payload = {}; @@ -684,12 +746,14 @@ const healthGetStorage = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetStorageLocalRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -697,8 +761,9 @@ const healthGetStorage = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {HealthGetStorageLocalRequestParams} params */ -const healthGetStorageLocal = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetStorageLocal = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/storage/local'; let payload = {}; @@ -712,12 +777,14 @@ const healthGetStorageLocal = async ({ parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} HealthGetTimeRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -725,8 +792,9 @@ const healthGetStorageLocal = async ({ parseOutput = true, sdk = undefined}) => /** * @param {HealthGetTimeRequestParams} params */ -const healthGetTime = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const healthGetTime = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/health/time'; let payload = {}; @@ -740,8 +808,9 @@ const healthGetTime = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } health @@ -900,4 +969,4 @@ module.exports = { healthGetStorage, healthGetStorageLocal, healthGetTime -}; \ No newline at end of file +}; diff --git a/lib/commands/init.js b/lib/commands/init.js index 706ed97..ebd74e8 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,58 +3,188 @@ const path = require("path"); const childProcess = require('child_process'); const { Command } = require("commander"); const inquirer = require("inquirer"); -const { teamsCreate, teamsList } = require("./teams"); -const { projectsCreate } = require("./projects"); +const { fetch } = require("undici"); +const { projectsCreate, projectsGet } = require("./projects"); +const { storageCreateBucket } = require("./storage"); +const { messagingCreateTopic } = require("./messaging"); const { functionsCreate } = require("./functions"); -const { databasesGet, databasesListCollections, databasesList } = require("./databases"); -const { storageListBuckets } = require("./storage"); +const { databasesCreateCollection } = require("./databases"); +const ID = require("../id"); +const { localConfig, globalConfig } = require("../config"); +const { + questionsCreateFunction, + questionsCreateFunctionSelectTemplate, + questionsCreateBucket, + questionsCreateMessagingTopic, + questionsCreateCollection, + questionsInitProject, + questionsInitResources, + questionsCreateTeam +} = require("../questions"); +const { success, log, error, actionRunner, commandDescriptions } = require("../parser"); +const { accountGet } = require("./account"); const { sdkForConsole } = require("../sdks"); -const { localConfig } = require("../config"); -const { paginate } = require("../paginate"); -const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions"); -const { success, log, actionRunner, commandDescriptions } = require("../parser"); -const init = new Command("init") - .description(commandDescriptions['init']) - .configureHelp({ - helpWidth: process.stdout.columns || 80 - }) - .action(actionRunner(async (_options, command) => { - command.help(); - })); - -const initProject = async () => { - let response = {} - const answers = await inquirer.prompt(questionsInitProject) - if (!answers.project) process.exit(1) - - let sdk = await sdkForConsole(); - if (answers.start === "new") { - response = await teamsCreate({ - teamId: 'unique()', - name: answers.project, - sdk, - parseOutput: false - }) +const initResources = async () => { + const actions = { + function: initFunction, + collection: initCollection, + bucket: initBucket, + team: initTeam, + message: initTopic + } + + const answers = await inquirer.prompt(questionsInitResources[0]); + + const action = actions[answers.resource]; + if (action !== undefined) { + await action({ returnOnZero: true }); + } +}; + +const initProject = async ({ organizationId, projectId, projectName } = {}) => { + let response = {}; + + try { + if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { + throw ''; + } + const client = await sdkForConsole(); + + await accountGet({ + parseOutput: false, + sdk: client + }); + } catch (e) { + error('Error Session not found. Please run `appwrite login` to create a session'); + process.exit(1); + } + + let answers = {}; + + if (!organizationId && !projectId && !projectName) { + answers = await inquirer.prompt(questionsInitProject) + if (answers.override === false) { + process.exit(1) + } + } else { + answers.start = 'existing'; + answers.project = {}; + answers.organization = {}; + + answers.organization = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization; + answers.project.name = projectName ?? (await inquirer.prompt(questionsInitProject[3])).project; + answers.project = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id; + + try { + await projectsGet({ projectId, parseOutput: false }); + } catch (e) { + if (e.code === 404) { + answers.start = 'new'; + answers.id = answers.project; + answers.project = answers.project.name; + } else { + throw e; + } + } + } - let teamId = response['$id']; + if (answers.start === 'new') { response = await projectsCreate({ projectId: answers.id, name: answers.project, - teamId, + teamId: answers.organization, parseOutput: false }) - localConfig.setProject(response['$id'], response.name); + localConfig.setProject(response['$id']); } else { - localConfig.setProject(answers.project.id, answers.project.name); + localConfig.setProject(answers.project); + } + + success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`); + + log("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwite push' to synchronize your project.") + + if(answers.start === 'existing') { + log("Since you connected to an existing project, we highly recommend to run 'appwrite pull all' to synchronize all of your existing resources."); } - success(); } +const initBucket = async () => { + const answers = await inquirer.prompt(questionsCreateBucket) + + localConfig.addBucket({ + $id: answers.id === 'unique()' ? ID.unique() : answers.id, + name: answers.bucket, + fileSecurity: answers.fileSecurity.toLowerCase() === 'yes', + enabled: true, + }); + success(); + log("Next you can use 'appwrite push bucket' to deploy the changes."); +}; + +const initTeam = async () => { + const answers = await inquirer.prompt(questionsCreateTeam) + + localConfig.addTeam({ + $id: answers.id === 'unique()' ? ID.unique() : answers.id, + name: answers.bucket, + }); + + success(); + log("Next you can use 'appwrite push team' to deploy the changes."); +}; + +const initCollection = async () => { + const answers = await inquirer.prompt(questionsCreateCollection) + const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing'; + + if (!newDatabase) { + answers.databaseId = answers.database; + answers.databaseName = localConfig.getDatabase(answers.database).name; + } + + const databaseId = answers.databaseId === 'unique()' ? ID.unique() : answers.databaseId; + + if (newDatabase || !localConfig.getDatabase(answers.databaseId)) { + localConfig.addDatabase({ + $id: databaseId, + name: answers.databaseName, + enabled: true + }); + } + + localConfig.addCollection({ + $id: answers.id === 'unique()' ? ID.unique() : answers.id, + databaseId: databaseId, + name: answers.collection, + documentSecurity: answers.documentSecurity.toLowerCase() === 'yes', + attributes: [], + indexes: [], + enabled: true, + }); + + success(); + log("Next you can use 'appwrite push collection' to deploy the changes."); +}; + +const initTopic = async () => { + const answers = await inquirer.prompt(questionsCreateMessagingTopic) + + localConfig.addMessagingTopic({ + $id: answers.id === 'unique()' ? ID.unique() : answers.id, + name: answers.topic, + + }); + + success(); + log("Next you can use 'appwrite push topic' to deploy the changes."); +}; + const initFunction = async () => { // TODO: Add CI/CD support (ID, name, runtime) - const answers = await inquirer.prompt(questionsInitFunction) + const answers = await inquirer.prompt(questionsCreateFunction) const functionFolder = path.join(process.cwd(), 'functions'); if (!fs.existsSync(functionFolder)) { @@ -63,34 +193,46 @@ const initFunction = async () => { }); } - const functionDir = path.join(functionFolder, answers.name); + const functionId = answers.id === 'unique()' ? ID.unique() : answers.id; + const functionDir = path.join(functionFolder, functionId); + const templatesDir = path.join(functionFolder, `${functionId}-templates`); + const runtimeDir = path.join(templatesDir, answers.runtime.name); if (fs.existsSync(functionDir)) { - throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`); + throw new Error(`( ${functionId} ) already exists in the current directory. Please choose another name.`); } if (!answers.runtime.entrypoint) { - log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`); + log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first push the function.`); } if (!answers.runtime.commands) { - log(`Installation command for this runtime not found. You will be asked to configure the install command when you first deploy the function.`); + log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`); } - let response = await functionsCreate({ - functionId: answers.id, - name: answers.name, - runtime: answers.runtime.id, - entrypoint: answers.runtime.entrypoint || '', - commands: answers.runtime.commands || '', - parseOutput: false - }) fs.mkdirSync(functionDir, "777"); + fs.mkdirSync(templatesDir, "777"); + const repo = "https://github.com/appwrite/templates"; + const api = `https://api.github.com/repos/appwrite/templates/contents/${answers.runtime.name}` + const templates = ['starter']; + let selected = undefined; + + try { + const res = await fetch(api); + templates.push(...(await res.json()).map((template) => template.name)); - let gitInitCommands = "git clone -b v3 --single-branch --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched + selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates)) + } catch { + // Not a problem will go with directory pulling + log('Loading templates...'); + } + + const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase(); - let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`; + let gitInitCommands = `git clone --single-branch --depth 1 --sparse ${repo} .`; // depth prevents fetching older commits reducing the amount fetched + + let gitPullCommands = `git sparse-checkout add ${sparse}`; /* Force use CMD as powershell does not support && */ if (process.platform === 'win32') { @@ -100,8 +242,8 @@ const initFunction = async () => { /* Execute the child process but do not print any std output */ try { - childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir }); - childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir }); + childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: templatesDir }); + childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: templatesDir }); } catch (error) { /* Specialised errors with recommended actions to take */ if (error.message.includes('error: unknown option')) { @@ -113,7 +255,18 @@ const initFunction = async () => { } } - fs.rmSync(path.join(functionDir, ".git"), { recursive: true }); + fs.rmSync(path.join(templatesDir, ".git"), { recursive: true }); + if (!selected) { + templates.push(...fs.readdirSync(runtimeDir, { withFileTypes: true }) + .filter(item => item.isDirectory() && item.name !== 'starter') + .map(dirent => dirent.name)); + selected = { template: 'starter' }; + + if (templates.length > 1) { + selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates)) + } + } + const copyRecursiveSync = (src, dest) => { let exists = fs.existsSync(src); let stats = exists && fs.statSync(src); @@ -130,11 +283,11 @@ const initFunction = async () => { fs.copyFileSync(src, dest); } }; - copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir); + copyRecursiveSync(path.join(runtimeDir, selected.template), functionDir); - fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true }); + fs.rmSync(templatesDir, { recursive: true, force: true }); - const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md'); + const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md'); const readmeFile = fs.readFileSync(readmePath).toString(); const newReadmeFile = readmeFile.split('\n'); newReadmeFile[0] = `# ${answers.name}`; @@ -142,125 +295,67 @@ const initFunction = async () => { fs.writeFileSync(readmePath, newReadmeFile.join('\n')); let data = { - $id: response['$id'], - name: response.name, - runtime: response.runtime, - execute: response.execute, - events: response.events, - schedule: response.schedule, - timeout: response.timeout, - enabled: response.enabled, - logging: response.logging, - entrypoint: response.entrypoint, - commands: response.commands, + $id: functionId, + name: answers.name, + runtime: answers.runtime.id, + execute: [], + events: [], + schedule: "", + timeout: 15, + enabled: true, + logging: true, + entrypoint: answers.runtime.entrypoint || '', + commands: answers.runtime.commands || '', ignore: answers.runtime.ignore || null, - path: `functions/${answers.name}`, + path: `functions/${functionId}`, }; localConfig.addFunction(data); success(); + log("Next you can use 'appwrite run function' to develop a function locally. To deploy the function, use 'appwrite push function'"); } -const initCollection = async ({ all, databaseId } = {}) => { - const databaseIds = []; - - if (databaseId) { - databaseIds.push(databaseId); - } else if (all) { - let allDatabases = await databasesList({ - parseOutput: false - }) - - databaseIds.push(...allDatabases.databases.map((d) => d.$id)); - } - - if (databaseIds.length <= 0) { - let answers = await inquirer.prompt(questionsInitCollection) - if (!answers.databases) process.exit(1) - databaseIds.push(...answers.databases); - } - - for (const databaseId of databaseIds) { - const database = await databasesGet({ - databaseId, - parseOutput: false - }); - - localConfig.addDatabase(database); - - const { collections, total } = await paginate(databasesListCollections, { - databaseId, - parseOutput: false - }, 100, 'collections'); - - log(`Found ${total} collections`); - - collections.forEach(async collection => { - log(`Fetching ${collection.name} ...`); - localConfig.addCollection({ - ...collection, - '$createdAt': undefined, - '$updatedAt': undefined, - }); - }); - } - - success(); -} - -const initBucket = async () => { - const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); - - log(`Found ${buckets.length} buckets`); - - buckets.forEach(async bucket => { - log(`Fetching ${bucket.name} ...`); - localConfig.addBucket(bucket); - }); - - success(); -} - -const initTeam = async () => { - const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams'); - - log(`Found ${teams.length} teams`); - - teams.forEach(async team => { - log(`Fetching ${team.name} ...`); - const { total, $updatedAt, $createdAt, prefs, ...rest } = team; - localConfig.addTeam(rest); - }); - - success(); -} +const init = new Command("init") + .description(commandDescriptions['init']) + .action(actionRunner(initResources)); init .command("project") - .description("Initialise your Appwrite project") + .description("Init a new Appwrite project") + .option("--organizationId ", "Appwrite organization ID") + .option("--projectId ", "Appwrite project ID") + .option("--projectName ", "Appwrite project ID") .action(actionRunner(initProject)); init .command("function") - .description("Initialise your Appwrite cloud function") - .action(actionRunner(initFunction)) - -init - .command("collection") - .description("Initialise your Appwrite collections") - .option(`--databaseId `, `Database ID`) - .option(`--all`, `Flag to initialize all databases`) - .action(actionRunner(initCollection)) + .alias("functions") + .description("Init a new Appwrite function") + .action(actionRunner(initFunction)); init .command("bucket") - .description("Initialise your Appwrite buckets") - .action(actionRunner(initBucket)) + .alias("buckets") + .description("Init a new Appwrite bucket") + .action(actionRunner(initBucket)); init .command("team") - .description("Initialise your Appwrite teams") - .action(actionRunner(initTeam)) + .alias("teams") + .description("Init a new Appwrite team") + .action(actionRunner(initTeam)); + +init + .command("collection") + .alias("collections") + .description("Init a new Appwrite collection") + .action(actionRunner(initCollection)); + +init + .command("topic") + .alias("topics") + .description("Init a new Appwrite topic") + .action(actionRunner(initTopic)); module.exports = { init, diff --git a/lib/commands/locale.js b/lib/commands/locale.js index 50a9421..ef02bf9 100644 --- a/lib/commands/locale.js +++ b/lib/commands/locale.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -41,6 +41,7 @@ const locale = new Command("locale").description(commandDescriptions['locale']). /** * @typedef {Object} LocaleGetRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -48,8 +49,9 @@ const locale = new Command("locale").description(commandDescriptions['locale']). /** * @param {LocaleGetRequestParams} params */ -const localeGet = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeGet = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale'; let payload = {}; @@ -63,12 +65,14 @@ const localeGet = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -76,8 +80,9 @@ const localeGet = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {LocaleListCodesRequestParams} params */ -const localeListCodes = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListCodes = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/codes'; let payload = {}; @@ -91,12 +96,14 @@ const localeListCodes = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListContinentsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -104,8 +111,9 @@ const localeListCodes = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {LocaleListContinentsRequestParams} params */ -const localeListContinents = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListContinents = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/continents'; let payload = {}; @@ -119,12 +127,14 @@ const localeListContinents = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -132,8 +142,9 @@ const localeListContinents = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {LocaleListCountriesRequestParams} params */ -const localeListCountries = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListCountries = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/countries'; let payload = {}; @@ -147,12 +158,14 @@ const localeListCountries = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesEURequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -160,8 +173,9 @@ const localeListCountries = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {LocaleListCountriesEURequestParams} params */ -const localeListCountriesEU = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListCountriesEU = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/countries/eu'; let payload = {}; @@ -175,12 +189,14 @@ const localeListCountriesEU = async ({ parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesPhonesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -188,8 +204,9 @@ const localeListCountriesEU = async ({ parseOutput = true, sdk = undefined}) => /** * @param {LocaleListCountriesPhonesRequestParams} params */ -const localeListCountriesPhones = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListCountriesPhones = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/countries/phones'; let payload = {}; @@ -203,12 +220,14 @@ const localeListCountriesPhones = async ({ parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListCurrenciesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -216,8 +235,9 @@ const localeListCountriesPhones = async ({ parseOutput = true, sdk = undefined}) /** * @param {LocaleListCurrenciesRequestParams} params */ -const localeListCurrencies = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListCurrencies = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/currencies'; let payload = {}; @@ -231,12 +251,14 @@ const localeListCurrencies = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} LocaleListLanguagesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -244,8 +266,9 @@ const localeListCurrencies = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {LocaleListLanguagesRequestParams} params */ -const localeListLanguages = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const localeListLanguages = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/locale/languages'; let payload = {}; @@ -259,8 +282,9 @@ const localeListLanguages = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } locale @@ -313,4 +337,4 @@ module.exports = { localeListCountriesPhones, localeListCurrencies, localeListLanguages -}; \ No newline at end of file +}; diff --git a/lib/commands/messaging.js b/lib/commands/messaging.js index f61ac9e..4093463 100644 --- a/lib/commands/messaging.js +++ b/lib/commands/messaging.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const messaging = new Command("messaging").description(commandDescriptions['mess * @typedef {Object} MessagingListMessagesRequestParams * @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: scheduledAt, deliveredAt, deliveredTotal, status, description, providerType * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const messaging = new Command("messaging").description(commandDescriptions['mess /** * @param {MessagingListMessagesRequestParams} params */ -const messagingListMessages = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListMessages = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const messagingListMessages = async ({ queries, search, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listMessages'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -89,6 +96,7 @@ const messagingListMessages = async ({ queries, search, parseOutput = true, sdk * @property {boolean} draft Is message a draft * @property {boolean} html Is content of type HTML * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -96,8 +104,9 @@ const messagingListMessages = async ({ queries, search, parseOutput = true, sdk /** * @param {MessagingCreateEmailRequestParams} params */ -const messagingCreateEmail = async ({ messageId, subject, content, topics, users, targets, cc, bcc, attachments, draft, html, scheduledAt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateEmail = async ({messageId,subject,content,topics,users,targets,cc,bcc,attachments,draft,html,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/email'; let payload = {}; if (typeof messageId !== 'undefined') { @@ -153,8 +162,9 @@ const messagingCreateEmail = async ({ messageId, subject, content, topics, users parse(response) success() } - + return response; + } /** @@ -171,6 +181,7 @@ const messagingCreateEmail = async ({ messageId, subject, content, topics, users * @property {string[]} bcc Array of target IDs to be added as BCC. * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. * @property {string[]} attachments Array of compound ID strings of bucket IDs and file IDs to be attached to the email. They should be formatted as <BUCKET_ID>:<FILE_ID>. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -178,8 +189,9 @@ const messagingCreateEmail = async ({ messageId, subject, content, topics, users /** * @param {MessagingUpdateEmailRequestParams} params */ -const messagingUpdateEmail = async ({ messageId, topics, users, targets, subject, content, draft, html, cc, bcc, scheduledAt, attachments, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateEmail = async ({messageId,topics,users,targets,subject,content,draft,html,cc,bcc,scheduledAt,attachments,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/email/{messageId}'.replace('{messageId}', messageId); let payload = {}; topics = topics === true ? [] : topics; @@ -232,8 +244,9 @@ const messagingUpdateEmail = async ({ messageId, topics, users, targets, subject parse(response) success() } - + return response; + } /** @@ -254,6 +267,7 @@ const messagingUpdateEmail = async ({ messageId, topics, users, targets, subject * @property {string} badge Badge for push notification. Available only for IOS Platform. * @property {boolean} draft Is message a draft * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -261,8 +275,9 @@ const messagingUpdateEmail = async ({ messageId, topics, users, targets, subject /** * @param {MessagingCreatePushRequestParams} params */ -const messagingCreatePush = async ({ messageId, title, body, topics, users, targets, data, action, image, icon, sound, color, tag, badge, draft, scheduledAt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreatePush = async ({messageId,title,body,topics,users,targets,data,action,image,icon,sound,color,tag,badge,draft,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/push'; let payload = {}; if (typeof messageId !== 'undefined') { @@ -327,8 +342,9 @@ const messagingCreatePush = async ({ messageId, title, body, topics, users, targ parse(response) success() } - + return response; + } /** @@ -349,6 +365,7 @@ const messagingCreatePush = async ({ messageId, title, body, topics, users, targ * @property {number} badge Badge for push notification. Available only for iOS platforms. * @property {boolean} draft Is message a draft * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -356,8 +373,9 @@ const messagingCreatePush = async ({ messageId, title, body, topics, users, targ /** * @param {MessagingUpdatePushRequestParams} params */ -const messagingUpdatePush = async ({ messageId, topics, users, targets, title, body, data, action, image, icon, sound, color, tag, badge, draft, scheduledAt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdatePush = async ({messageId,topics,users,targets,title,body,data,action,image,icon,sound,color,tag,badge,draft,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/push/{messageId}'.replace('{messageId}', messageId); let payload = {}; topics = topics === true ? [] : topics; @@ -419,8 +437,9 @@ const messagingUpdatePush = async ({ messageId, topics, users, targets, title, b parse(response) success() } - + return response; + } /** @@ -432,6 +451,7 @@ const messagingUpdatePush = async ({ messageId, topics, users, targets, title, b * @property {string[]} targets List of Targets IDs. * @property {boolean} draft Is message a draft * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -439,8 +459,9 @@ const messagingUpdatePush = async ({ messageId, topics, users, targets, title, b /** * @param {MessagingCreateSmsRequestParams} params */ -const messagingCreateSms = async ({ messageId, content, topics, users, targets, draft, scheduledAt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateSms = async ({messageId,content,topics,users,targets,draft,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/sms'; let payload = {}; if (typeof messageId !== 'undefined') { @@ -478,8 +499,9 @@ const messagingCreateSms = async ({ messageId, content, topics, users, targets, parse(response) success() } - + return response; + } /** @@ -491,6 +513,7 @@ const messagingCreateSms = async ({ messageId, content, topics, users, targets, * @property {string} content Email Content. * @property {boolean} draft Is message a draft * @property {string} scheduledAt Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -498,8 +521,9 @@ const messagingCreateSms = async ({ messageId, content, topics, users, targets, /** * @param {MessagingUpdateSmsRequestParams} params */ -const messagingUpdateSms = async ({ messageId, topics, users, targets, content, draft, scheduledAt, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateSms = async ({messageId,topics,users,targets,content,draft,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/sms/{messageId}'.replace('{messageId}', messageId); let payload = {}; topics = topics === true ? [] : topics; @@ -534,13 +558,15 @@ const messagingUpdateSms = async ({ messageId, topics, users, targets, content, parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingGetMessageRequestParams * @property {string} messageId Message ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -548,8 +574,9 @@ const messagingUpdateSms = async ({ messageId, topics, users, targets, content, /** * @param {MessagingGetMessageRequestParams} params */ -const messagingGetMessage = async ({ messageId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingGetMessage = async ({messageId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/{messageId}'.replace('{messageId}', messageId); let payload = {}; @@ -560,16 +587,22 @@ const messagingGetMessage = async ({ messageId, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getMessage', messageId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} MessagingDeleteRequestParams * @property {string} messageId Message ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -577,8 +610,9 @@ const messagingGetMessage = async ({ messageId, parseOutput = true, sdk = undefi /** * @param {MessagingDeleteRequestParams} params */ -const messagingDelete = async ({ messageId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingDelete = async ({messageId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/{messageId}'.replace('{messageId}', messageId); let payload = {}; @@ -592,14 +626,16 @@ const messagingDelete = async ({ messageId, parseOutput = true, sdk = undefined} parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListMessageLogsRequestParams * @property {string} messageId Message ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -607,8 +643,9 @@ const messagingDelete = async ({ messageId, parseOutput = true, sdk = undefined} /** * @param {MessagingListMessageLogsRequestParams} params */ -const messagingListMessageLogs = async ({ messageId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListMessageLogs = async ({messageId,queries,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/{messageId}/logs'.replace('{messageId}', messageId); let payload = {}; if (typeof queries !== 'undefined') { @@ -622,17 +659,23 @@ const messagingListMessageLogs = async ({ messageId, queries, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listMessageLogs', messageId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} MessagingListTargetsRequestParams * @property {string} messageId Message ID. * @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: userId, providerId, identifier, providerType + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -640,8 +683,9 @@ const messagingListMessageLogs = async ({ messageId, queries, parseOutput = true /** * @param {MessagingListTargetsRequestParams} params */ -const messagingListTargets = async ({ messageId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListTargets = async ({messageId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/messages/{messageId}/targets'.replace('{messageId}', messageId); let payload = {}; if (typeof queries !== 'undefined') { @@ -658,14 +702,16 @@ const messagingListTargets = async ({ messageId, queries, parseOutput = true, sd parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListProvidersRequestParams * @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, provider, type, enabled * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -673,8 +719,9 @@ const messagingListTargets = async ({ messageId, queries, parseOutput = true, sd /** * @param {MessagingListProvidersRequestParams} params */ -const messagingListProviders = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListProviders = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers'; let payload = {}; if (typeof queries !== 'undefined') { @@ -691,11 +738,16 @@ const messagingListProviders = async ({ queries, search, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listProviders'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -708,6 +760,7 @@ const messagingListProviders = async ({ queries, search, parseOutput = true, sdk * @property {string} bundleId APNS bundle ID. * @property {boolean} sandbox Use APNS sandbox environment. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -715,8 +768,9 @@ const messagingListProviders = async ({ queries, search, parseOutput = true, sdk /** * @param {MessagingCreateApnsProviderRequestParams} params */ -const messagingCreateApnsProvider = async ({ providerId, name, authKey, authKeyId, teamId, bundleId, sandbox, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateApnsProvider = async ({providerId,name,authKey,authKeyId,teamId,bundleId,sandbox,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/apns'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -754,8 +808,9 @@ const messagingCreateApnsProvider = async ({ providerId, name, authKey, authKeyI parse(response) success() } - + return response; + } /** @@ -768,6 +823,7 @@ const messagingCreateApnsProvider = async ({ providerId, name, authKey, authKeyI * @property {string} teamId APNS team ID. * @property {string} bundleId APNS bundle ID. * @property {boolean} sandbox Use APNS sandbox environment. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -775,8 +831,9 @@ const messagingCreateApnsProvider = async ({ providerId, name, authKey, authKeyI /** * @param {MessagingUpdateApnsProviderRequestParams} params */ -const messagingUpdateApnsProvider = async ({ providerId, name, enabled, authKey, authKeyId, teamId, bundleId, sandbox, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateApnsProvider = async ({providerId,name,enabled,authKey,authKeyId,teamId,bundleId,sandbox,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/apns/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -811,8 +868,9 @@ const messagingUpdateApnsProvider = async ({ providerId, name, enabled, authKey, parse(response) success() } - + return response; + } /** @@ -821,6 +879,7 @@ const messagingUpdateApnsProvider = async ({ providerId, name, enabled, authKey, * @property {string} name Provider name. * @property {object} serviceAccountJSON FCM service account JSON. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -828,8 +887,9 @@ const messagingUpdateApnsProvider = async ({ providerId, name, enabled, authKey, /** * @param {MessagingCreateFcmProviderRequestParams} params */ -const messagingCreateFcmProvider = async ({ providerId, name, serviceAccountJSON, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateFcmProvider = async ({providerId,name,serviceAccountJSON,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/fcm'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -855,8 +915,9 @@ const messagingCreateFcmProvider = async ({ providerId, name, serviceAccountJSON parse(response) success() } - + return response; + } /** @@ -865,6 +926,7 @@ const messagingCreateFcmProvider = async ({ providerId, name, serviceAccountJSON * @property {string} name Provider name. * @property {boolean} enabled Set as enabled. * @property {object} serviceAccountJSON FCM service account JSON. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -872,8 +934,9 @@ const messagingCreateFcmProvider = async ({ providerId, name, serviceAccountJSON /** * @param {MessagingUpdateFcmProviderRequestParams} params */ -const messagingUpdateFcmProvider = async ({ providerId, name, enabled, serviceAccountJSON, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateFcmProvider = async ({providerId,name,enabled,serviceAccountJSON,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/fcm/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -896,8 +959,9 @@ const messagingUpdateFcmProvider = async ({ providerId, name, enabled, serviceAc parse(response) success() } - + return response; + } /** @@ -912,6 +976,7 @@ const messagingUpdateFcmProvider = async ({ providerId, name, enabled, serviceAc * @property {string} replyToName Name set in the reply to field for the mail. Default value is sender name. Reply to name must have reply to email as well. * @property {string} replyToEmail Email set in the reply to field for the mail. Default value is sender email. Reply to email must have reply to name as well. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -919,8 +984,9 @@ const messagingUpdateFcmProvider = async ({ providerId, name, enabled, serviceAc /** * @param {MessagingCreateMailgunProviderRequestParams} params */ -const messagingCreateMailgunProvider = async ({ providerId, name, apiKey, domain, isEuRegion, fromName, fromEmail, replyToName, replyToEmail, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateMailgunProvider = async ({providerId,name,apiKey,domain,isEuRegion,fromName,fromEmail,replyToName,replyToEmail,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/mailgun'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -964,8 +1030,9 @@ const messagingCreateMailgunProvider = async ({ providerId, name, apiKey, domain parse(response) success() } - + return response; + } /** @@ -980,6 +1047,7 @@ const messagingCreateMailgunProvider = async ({ providerId, name, apiKey, domain * @property {string} fromEmail Sender email address. * @property {string} replyToName Name set in the reply to field for the mail. Default value is sender name. * @property {string} replyToEmail Email set in the reply to field for the mail. Default value is sender email. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -987,8 +1055,9 @@ const messagingCreateMailgunProvider = async ({ providerId, name, apiKey, domain /** * @param {MessagingUpdateMailgunProviderRequestParams} params */ -const messagingUpdateMailgunProvider = async ({ providerId, name, apiKey, domain, isEuRegion, enabled, fromName, fromEmail, replyToName, replyToEmail, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateMailgunProvider = async ({providerId,name,apiKey,domain,isEuRegion,enabled,fromName,fromEmail,replyToName,replyToEmail,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/mailgun/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1029,8 +1098,9 @@ const messagingUpdateMailgunProvider = async ({ providerId, name, apiKey, domain parse(response) success() } - + return response; + } /** @@ -1041,6 +1111,7 @@ const messagingUpdateMailgunProvider = async ({ providerId, name, apiKey, domain * @property {string} senderId Msg91 sender ID. * @property {string} authKey Msg91 auth key. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1048,8 +1119,9 @@ const messagingUpdateMailgunProvider = async ({ providerId, name, apiKey, domain /** * @param {MessagingCreateMsg91ProviderRequestParams} params */ -const messagingCreateMsg91Provider = async ({ providerId, name, templateId, senderId, authKey, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateMsg91Provider = async ({providerId,name,templateId,senderId,authKey,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/msg91'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1081,8 +1153,9 @@ const messagingCreateMsg91Provider = async ({ providerId, name, templateId, send parse(response) success() } - + return response; + } /** @@ -1093,6 +1166,7 @@ const messagingCreateMsg91Provider = async ({ providerId, name, templateId, send * @property {string} templateId Msg91 template ID. * @property {string} senderId Msg91 sender ID. * @property {string} authKey Msg91 auth key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1100,8 +1174,9 @@ const messagingCreateMsg91Provider = async ({ providerId, name, templateId, send /** * @param {MessagingUpdateMsg91ProviderRequestParams} params */ -const messagingUpdateMsg91Provider = async ({ providerId, name, enabled, templateId, senderId, authKey, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateMsg91Provider = async ({providerId,name,enabled,templateId,senderId,authKey,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/msg91/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1130,8 +1205,9 @@ const messagingUpdateMsg91Provider = async ({ providerId, name, enabled, templat parse(response) success() } - + return response; + } /** @@ -1144,6 +1220,7 @@ const messagingUpdateMsg91Provider = async ({ providerId, name, enabled, templat * @property {string} replyToName Name set in the reply to field for the mail. Default value is sender name. * @property {string} replyToEmail Email set in the reply to field for the mail. Default value is sender email. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1151,8 +1228,9 @@ const messagingUpdateMsg91Provider = async ({ providerId, name, enabled, templat /** * @param {MessagingCreateSendgridProviderRequestParams} params */ -const messagingCreateSendgridProvider = async ({ providerId, name, apiKey, fromName, fromEmail, replyToName, replyToEmail, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateSendgridProvider = async ({providerId,name,apiKey,fromName,fromEmail,replyToName,replyToEmail,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/sendgrid'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1190,8 +1268,9 @@ const messagingCreateSendgridProvider = async ({ providerId, name, apiKey, fromN parse(response) success() } - + return response; + } /** @@ -1204,6 +1283,7 @@ const messagingCreateSendgridProvider = async ({ providerId, name, apiKey, fromN * @property {string} fromEmail Sender email address. * @property {string} replyToName Name set in the Reply To field for the mail. Default value is Sender Name. * @property {string} replyToEmail Email set in the Reply To field for the mail. Default value is Sender Email. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1211,8 +1291,9 @@ const messagingCreateSendgridProvider = async ({ providerId, name, apiKey, fromN /** * @param {MessagingUpdateSendgridProviderRequestParams} params */ -const messagingUpdateSendgridProvider = async ({ providerId, name, enabled, apiKey, fromName, fromEmail, replyToName, replyToEmail, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateSendgridProvider = async ({providerId,name,enabled,apiKey,fromName,fromEmail,replyToName,replyToEmail,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/sendgrid/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1247,8 +1328,9 @@ const messagingUpdateSendgridProvider = async ({ providerId, name, enabled, apiK parse(response) success() } - + return response; + } /** @@ -1267,6 +1349,7 @@ const messagingUpdateSendgridProvider = async ({ providerId, name, enabled, apiK * @property {string} replyToName Name set in the reply to field for the mail. Default value is sender name. * @property {string} replyToEmail Email set in the reply to field for the mail. Default value is sender email. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1274,8 +1357,9 @@ const messagingUpdateSendgridProvider = async ({ providerId, name, enabled, apiK /** * @param {MessagingCreateSmtpProviderRequestParams} params */ -const messagingCreateSmtpProvider = async ({ providerId, name, host, port, username, password, encryption, autoTLS, mailer, fromName, fromEmail, replyToName, replyToEmail, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateSmtpProvider = async ({providerId,name,host,port,username,password,encryption,autoTLS,mailer,fromName,fromEmail,replyToName,replyToEmail,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/smtp'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1331,8 +1415,9 @@ const messagingCreateSmtpProvider = async ({ providerId, name, host, port, usern parse(response) success() } - + return response; + } /** @@ -1351,6 +1436,7 @@ const messagingCreateSmtpProvider = async ({ providerId, name, host, port, usern * @property {string} replyToName Name set in the Reply To field for the mail. Default value is Sender Name. * @property {string} replyToEmail Email set in the Reply To field for the mail. Default value is Sender Email. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1358,8 +1444,9 @@ const messagingCreateSmtpProvider = async ({ providerId, name, host, port, usern /** * @param {MessagingUpdateSmtpProviderRequestParams} params */ -const messagingUpdateSmtpProvider = async ({ providerId, name, host, port, username, password, encryption, autoTLS, mailer, fromName, fromEmail, replyToName, replyToEmail, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateSmtpProvider = async ({providerId,name,host,port,username,password,encryption,autoTLS,mailer,fromName,fromEmail,replyToName,replyToEmail,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/smtp/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1412,8 +1499,9 @@ const messagingUpdateSmtpProvider = async ({ providerId, name, host, port, usern parse(response) success() } - + return response; + } /** @@ -1424,6 +1512,7 @@ const messagingUpdateSmtpProvider = async ({ providerId, name, host, port, usern * @property {string} customerId Telesign customer ID. * @property {string} apiKey Telesign API key. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1431,8 +1520,9 @@ const messagingUpdateSmtpProvider = async ({ providerId, name, host, port, usern /** * @param {MessagingCreateTelesignProviderRequestParams} params */ -const messagingCreateTelesignProvider = async ({ providerId, name, from, customerId, apiKey, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateTelesignProvider = async ({providerId,name,from,customerId,apiKey,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/telesign'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1464,8 +1554,9 @@ const messagingCreateTelesignProvider = async ({ providerId, name, from, custome parse(response) success() } - + return response; + } /** @@ -1476,6 +1567,7 @@ const messagingCreateTelesignProvider = async ({ providerId, name, from, custome * @property {string} customerId Telesign customer ID. * @property {string} apiKey Telesign API key. * @property {string} from Sender number. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1483,8 +1575,9 @@ const messagingCreateTelesignProvider = async ({ providerId, name, from, custome /** * @param {MessagingUpdateTelesignProviderRequestParams} params */ -const messagingUpdateTelesignProvider = async ({ providerId, name, enabled, customerId, apiKey, from, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateTelesignProvider = async ({providerId,name,enabled,customerId,apiKey,from,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/telesign/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1513,8 +1606,9 @@ const messagingUpdateTelesignProvider = async ({ providerId, name, enabled, cust parse(response) success() } - + return response; + } /** @@ -1525,6 +1619,7 @@ const messagingUpdateTelesignProvider = async ({ providerId, name, enabled, cust * @property {string} username Textmagic username. * @property {string} apiKey Textmagic apiKey. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1532,8 +1627,9 @@ const messagingUpdateTelesignProvider = async ({ providerId, name, enabled, cust /** * @param {MessagingCreateTextmagicProviderRequestParams} params */ -const messagingCreateTextmagicProvider = async ({ providerId, name, from, username, apiKey, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateTextmagicProvider = async ({providerId,name,from,username,apiKey,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/textmagic'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1565,8 +1661,9 @@ const messagingCreateTextmagicProvider = async ({ providerId, name, from, userna parse(response) success() } - + return response; + } /** @@ -1577,6 +1674,7 @@ const messagingCreateTextmagicProvider = async ({ providerId, name, from, userna * @property {string} username Textmagic username. * @property {string} apiKey Textmagic apiKey. * @property {string} from Sender number. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1584,8 +1682,9 @@ const messagingCreateTextmagicProvider = async ({ providerId, name, from, userna /** * @param {MessagingUpdateTextmagicProviderRequestParams} params */ -const messagingUpdateTextmagicProvider = async ({ providerId, name, enabled, username, apiKey, from, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateTextmagicProvider = async ({providerId,name,enabled,username,apiKey,from,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/textmagic/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1614,8 +1713,9 @@ const messagingUpdateTextmagicProvider = async ({ providerId, name, enabled, use parse(response) success() } - + return response; + } /** @@ -1626,6 +1726,7 @@ const messagingUpdateTextmagicProvider = async ({ providerId, name, enabled, use * @property {string} accountSid Twilio account secret ID. * @property {string} authToken Twilio authentication token. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1633,8 +1734,9 @@ const messagingUpdateTextmagicProvider = async ({ providerId, name, enabled, use /** * @param {MessagingCreateTwilioProviderRequestParams} params */ -const messagingCreateTwilioProvider = async ({ providerId, name, from, accountSid, authToken, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateTwilioProvider = async ({providerId,name,from,accountSid,authToken,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/twilio'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1666,8 +1768,9 @@ const messagingCreateTwilioProvider = async ({ providerId, name, from, accountSi parse(response) success() } - + return response; + } /** @@ -1678,6 +1781,7 @@ const messagingCreateTwilioProvider = async ({ providerId, name, from, accountSi * @property {string} accountSid Twilio account secret ID. * @property {string} authToken Twilio authentication token. * @property {string} from Sender number. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1685,8 +1789,9 @@ const messagingCreateTwilioProvider = async ({ providerId, name, from, accountSi /** * @param {MessagingUpdateTwilioProviderRequestParams} params */ -const messagingUpdateTwilioProvider = async ({ providerId, name, enabled, accountSid, authToken, from, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateTwilioProvider = async ({providerId,name,enabled,accountSid,authToken,from,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/twilio/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1715,8 +1820,9 @@ const messagingUpdateTwilioProvider = async ({ providerId, name, enabled, accoun parse(response) success() } - + return response; + } /** @@ -1727,6 +1833,7 @@ const messagingUpdateTwilioProvider = async ({ providerId, name, enabled, accoun * @property {string} apiKey Vonage API key. * @property {string} apiSecret Vonage API secret. * @property {boolean} enabled Set as enabled. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1734,8 +1841,9 @@ const messagingUpdateTwilioProvider = async ({ providerId, name, enabled, accoun /** * @param {MessagingCreateVonageProviderRequestParams} params */ -const messagingCreateVonageProvider = async ({ providerId, name, from, apiKey, apiSecret, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateVonageProvider = async ({providerId,name,from,apiKey,apiSecret,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/vonage'; let payload = {}; if (typeof providerId !== 'undefined') { @@ -1767,8 +1875,9 @@ const messagingCreateVonageProvider = async ({ providerId, name, from, apiKey, a parse(response) success() } - + return response; + } /** @@ -1779,6 +1888,7 @@ const messagingCreateVonageProvider = async ({ providerId, name, from, apiKey, a * @property {string} apiKey Vonage API key. * @property {string} apiSecret Vonage API secret. * @property {string} from Sender number. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1786,8 +1896,9 @@ const messagingCreateVonageProvider = async ({ providerId, name, from, apiKey, a /** * @param {MessagingUpdateVonageProviderRequestParams} params */ -const messagingUpdateVonageProvider = async ({ providerId, name, enabled, apiKey, apiSecret, from, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateVonageProvider = async ({providerId,name,enabled,apiKey,apiSecret,from,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/vonage/{providerId}'.replace('{providerId}', providerId); let payload = {}; if (typeof name !== 'undefined') { @@ -1816,13 +1927,15 @@ const messagingUpdateVonageProvider = async ({ providerId, name, enabled, apiKey parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingGetProviderRequestParams * @property {string} providerId Provider ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1830,8 +1943,9 @@ const messagingUpdateVonageProvider = async ({ providerId, name, enabled, apiKey /** * @param {MessagingGetProviderRequestParams} params */ -const messagingGetProvider = async ({ providerId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingGetProvider = async ({providerId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/{providerId}'.replace('{providerId}', providerId); let payload = {}; @@ -1842,16 +1956,22 @@ const messagingGetProvider = async ({ providerId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getProvider', providerId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} MessagingDeleteProviderRequestParams * @property {string} providerId Provider ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1859,8 +1979,9 @@ const messagingGetProvider = async ({ providerId, parseOutput = true, sdk = unde /** * @param {MessagingDeleteProviderRequestParams} params */ -const messagingDeleteProvider = async ({ providerId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingDeleteProvider = async ({providerId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/{providerId}'.replace('{providerId}', providerId); let payload = {}; @@ -1874,14 +1995,16 @@ const messagingDeleteProvider = async ({ providerId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListProviderLogsRequestParams * @property {string} providerId Provider ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1889,8 +2012,9 @@ const messagingDeleteProvider = async ({ providerId, parseOutput = true, sdk = u /** * @param {MessagingListProviderLogsRequestParams} params */ -const messagingListProviderLogs = async ({ providerId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListProviderLogs = async ({providerId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/providers/{providerId}/logs'.replace('{providerId}', providerId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1907,14 +2031,16 @@ const messagingListProviderLogs = async ({ providerId, queries, parseOutput = tr parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListSubscriberLogsRequestParams * @property {string} subscriberId Subscriber ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1922,8 +2048,9 @@ const messagingListProviderLogs = async ({ providerId, queries, parseOutput = tr /** * @param {MessagingListSubscriberLogsRequestParams} params */ -const messagingListSubscriberLogs = async ({ subscriberId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListSubscriberLogs = async ({subscriberId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/subscribers/{subscriberId}/logs'.replace('{subscriberId}', subscriberId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1940,14 +2067,16 @@ const messagingListSubscriberLogs = async ({ subscriberId, queries, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListTopicsRequestParams * @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, description, emailTotal, smsTotal, pushTotal * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1955,8 +2084,9 @@ const messagingListSubscriberLogs = async ({ subscriberId, queries, parseOutput /** * @param {MessagingListTopicsRequestParams} params */ -const messagingListTopics = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListTopics = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics'; let payload = {}; if (typeof queries !== 'undefined') { @@ -1973,11 +2103,16 @@ const messagingListTopics = async ({ queries, search, parseOutput = true, sdk = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listTopics'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1985,6 +2120,7 @@ const messagingListTopics = async ({ queries, search, parseOutput = true, sdk = * @property {string} topicId Topic ID. Choose a custom Topic ID or a new Topic ID. * @property {string} name Topic Name. * @property {string[]} subscribe An array of role strings with subscribe permission. By default all users are granted with any subscribe permission. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1992,8 +2128,9 @@ const messagingListTopics = async ({ queries, search, parseOutput = true, sdk = /** * @param {MessagingCreateTopicRequestParams} params */ -const messagingCreateTopic = async ({ topicId, name, subscribe, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateTopic = async ({topicId,name,subscribe,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics'; let payload = {}; if (typeof topicId !== 'undefined') { @@ -2017,13 +2154,15 @@ const messagingCreateTopic = async ({ topicId, name, subscribe, parseOutput = tr parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingGetTopicRequestParams * @property {string} topicId Topic ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2031,8 +2170,9 @@ const messagingCreateTopic = async ({ topicId, name, subscribe, parseOutput = tr /** * @param {MessagingGetTopicRequestParams} params */ -const messagingGetTopic = async ({ topicId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingGetTopic = async ({topicId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); let payload = {}; @@ -2043,11 +2183,16 @@ const messagingGetTopic = async ({ topicId, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getTopic', topicId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -2055,6 +2200,7 @@ const messagingGetTopic = async ({ topicId, parseOutput = true, sdk = undefined} * @property {string} topicId Topic ID. * @property {string} name Topic Name. * @property {string[]} subscribe An array of role strings with subscribe permission. By default all users are granted with any subscribe permission. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2062,8 +2208,9 @@ const messagingGetTopic = async ({ topicId, parseOutput = true, sdk = undefined} /** * @param {MessagingUpdateTopicRequestParams} params */ -const messagingUpdateTopic = async ({ topicId, name, subscribe, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingUpdateTopic = async ({topicId,name,subscribe,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); let payload = {}; if (typeof name !== 'undefined') { @@ -2084,13 +2231,15 @@ const messagingUpdateTopic = async ({ topicId, name, subscribe, parseOutput = tr parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingDeleteTopicRequestParams * @property {string} topicId Topic ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2098,8 +2247,9 @@ const messagingUpdateTopic = async ({ topicId, name, subscribe, parseOutput = tr /** * @param {MessagingDeleteTopicRequestParams} params */ -const messagingDeleteTopic = async ({ topicId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingDeleteTopic = async ({topicId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); let payload = {}; @@ -2113,14 +2263,16 @@ const messagingDeleteTopic = async ({ topicId, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingListTopicLogsRequestParams * @property {string} topicId Topic ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2128,8 +2280,9 @@ const messagingDeleteTopic = async ({ topicId, parseOutput = true, sdk = undefin /** * @param {MessagingListTopicLogsRequestParams} params */ -const messagingListTopicLogs = async ({ topicId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListTopicLogs = async ({topicId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}/logs'.replace('{topicId}', topicId); let payload = {}; if (typeof queries !== 'undefined') { @@ -2146,8 +2299,9 @@ const messagingListTopicLogs = async ({ topicId, queries, parseOutput = true, sd parse(response) success() } - + return response; + } /** @@ -2155,6 +2309,7 @@ const messagingListTopicLogs = async ({ topicId, queries, parseOutput = true, sd * @property {string} topicId Topic ID. The topic ID subscribed to. * @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, provider, type, enabled * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2162,8 +2317,9 @@ const messagingListTopicLogs = async ({ topicId, queries, parseOutput = true, sd /** * @param {MessagingListSubscribersRequestParams} params */ -const messagingListSubscribers = async ({ topicId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingListSubscribers = async ({topicId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); let payload = {}; if (typeof queries !== 'undefined') { @@ -2180,11 +2336,16 @@ const messagingListSubscribers = async ({ topicId, queries, search, parseOutput }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listSubscribers', topicId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -2192,6 +2353,7 @@ const messagingListSubscribers = async ({ topicId, queries, search, parseOutput * @property {string} topicId Topic ID. The topic ID to subscribe to. * @property {string} subscriberId Subscriber ID. Choose a custom Subscriber ID or a new Subscriber ID. * @property {string} targetId Target ID. The target ID to link to the specified Topic ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2199,8 +2361,9 @@ const messagingListSubscribers = async ({ topicId, queries, search, parseOutput /** * @param {MessagingCreateSubscriberRequestParams} params */ -const messagingCreateSubscriber = async ({ topicId, subscriberId, targetId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingCreateSubscriber = async ({topicId,subscriberId,targetId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); let payload = {}; if (typeof subscriberId !== 'undefined') { @@ -2220,14 +2383,16 @@ const messagingCreateSubscriber = async ({ topicId, subscriberId, targetId, pars parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingGetSubscriberRequestParams * @property {string} topicId Topic ID. The topic ID subscribed to. * @property {string} subscriberId Subscriber ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2235,8 +2400,9 @@ const messagingCreateSubscriber = async ({ topicId, subscriberId, targetId, pars /** * @param {MessagingGetSubscriberRequestParams} params */ -const messagingGetSubscriber = async ({ topicId, subscriberId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingGetSubscriber = async ({topicId,subscriberId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); let payload = {}; @@ -2250,14 +2416,16 @@ const messagingGetSubscriber = async ({ topicId, subscriberId, parseOutput = tru parse(response) success() } - + return response; + } /** * @typedef {Object} MessagingDeleteSubscriberRequestParams * @property {string} topicId Topic ID. The topic ID subscribed to. * @property {string} subscriberId Subscriber ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -2265,8 +2433,9 @@ const messagingGetSubscriber = async ({ topicId, subscriberId, parseOutput = tru /** * @param {MessagingDeleteSubscriberRequestParams} params */ -const messagingDeleteSubscriber = async ({ topicId, subscriberId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const messagingDeleteSubscriber = async ({topicId,subscriberId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); let payload = {}; @@ -2280,8 +2449,9 @@ const messagingDeleteSubscriber = async ({ topicId, subscriberId, parseOutput = parse(response) success() } - + return response; + } messaging @@ -2289,6 +2459,7 @@ messaging .description(`Get a list of all messages from the current Appwrite project.`) .option(`--queries [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: scheduledAt, deliveredAt, deliveredTotal, status, description, providerType`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListMessages)) messaging @@ -2395,6 +2566,7 @@ messaging .command(`getMessage`) .description(`Get a message by its unique ID. `) .requiredOption(`--messageId `, `Message ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetMessage)) messaging @@ -2408,6 +2580,7 @@ messaging .description(`Get the message activity logs listed by its unique ID.`) .requiredOption(`--messageId `, `Message ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListMessageLogs)) messaging @@ -2422,6 +2595,7 @@ messaging .description(`Get a list of all providers from the current Appwrite project.`) .option(`--queries [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, provider, type, enabled`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListProviders)) messaging @@ -2676,6 +2850,7 @@ messaging .command(`getProvider`) .description(`Get a provider by its unique ID. `) .requiredOption(`--providerId `, `Provider ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetProvider)) messaging @@ -2703,6 +2878,7 @@ messaging .description(`Get a list of all topics from the current Appwrite project.`) .option(`--queries [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, description, emailTotal, smsTotal, pushTotal`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListTopics)) messaging @@ -2717,6 +2893,7 @@ messaging .command(`getTopic`) .description(`Get a topic by its unique ID. `) .requiredOption(`--topicId `, `Topic ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetTopic)) messaging @@ -2746,6 +2923,7 @@ messaging .requiredOption(`--topicId `, `Topic ID. The topic ID subscribed to.`) .option(`--queries [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, provider, type, enabled`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListSubscribers)) messaging @@ -2818,4 +2996,4 @@ module.exports = { messagingCreateSubscriber, messagingGetSubscriber, messagingDeleteSubscriber -}; \ No newline at end of file +}; diff --git a/lib/commands/migrations.js b/lib/commands/migrations.js index 2ddb16c..02e5db3 100644 --- a/lib/commands/migrations.js +++ b/lib/commands/migrations.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const migrations = new Command("migrations").description(commandDescriptions['mi * @typedef {Object} MigrationsListRequestParams * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: status, stage, source, resources, statusCounters, resourceData, errors * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const migrations = new Command("migrations").description(commandDescriptions['mi /** * @param {MigrationsListRequestParams} params */ -const migrationsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations'; let payload = {}; if (typeof queries !== 'undefined') { @@ -71,8 +73,9 @@ const migrationsList = async ({ queries, search, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** @@ -81,6 +84,7 @@ const migrationsList = async ({ queries, search, parseOutput = true, sdk = undef * @property {string} endpoint Source's Appwrite Endpoint * @property {string} projectId Source's Project ID * @property {string} apiKey Source's API Key + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -88,8 +92,9 @@ const migrationsList = async ({ queries, search, parseOutput = true, sdk = undef /** * @param {MigrationsCreateAppwriteMigrationRequestParams} params */ -const migrationsCreateAppwriteMigration = async ({ resources, endpoint, projectId, apiKey, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsCreateAppwriteMigration = async ({resources,endpoint,projectId,apiKey,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/appwrite'; let payload = {}; resources = resources === true ? [] : resources; @@ -116,8 +121,9 @@ const migrationsCreateAppwriteMigration = async ({ resources, endpoint, projectI parse(response) success() } - + return response; + } /** @@ -126,6 +132,7 @@ const migrationsCreateAppwriteMigration = async ({ resources, endpoint, projectI * @property {string} endpoint Source's Appwrite Endpoint * @property {string} projectID Source's Project ID * @property {string} key Source's API Key + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -133,8 +140,9 @@ const migrationsCreateAppwriteMigration = async ({ resources, endpoint, projectI /** * @param {MigrationsGetAppwriteReportRequestParams} params */ -const migrationsGetAppwriteReport = async ({ resources, endpoint, projectID, key, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGetAppwriteReport = async ({resources,endpoint,projectID,key,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/appwrite/report'; let payload = {}; if (typeof resources !== 'undefined') { @@ -160,14 +168,16 @@ const migrationsGetAppwriteReport = async ({ resources, endpoint, projectID, key parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsCreateFirebaseMigrationRequestParams * @property {string[]} resources List of resources to migrate * @property {string} serviceAccount JSON of the Firebase service account credentials + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -175,8 +185,9 @@ const migrationsGetAppwriteReport = async ({ resources, endpoint, projectID, key /** * @param {MigrationsCreateFirebaseMigrationRequestParams} params */ -const migrationsCreateFirebaseMigration = async ({ resources, serviceAccount, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsCreateFirebaseMigration = async ({resources,serviceAccount,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase'; let payload = {}; resources = resources === true ? [] : resources; @@ -197,12 +208,14 @@ const migrationsCreateFirebaseMigration = async ({ resources, serviceAccount, pa parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsDeleteFirebaseAuthRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -210,8 +223,9 @@ const migrationsCreateFirebaseMigration = async ({ resources, serviceAccount, pa /** * @param {MigrationsDeleteFirebaseAuthRequestParams} params */ -const migrationsDeleteFirebaseAuth = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsDeleteFirebaseAuth = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase/deauthorize'; let payload = {}; @@ -225,14 +239,16 @@ const migrationsDeleteFirebaseAuth = async ({ parseOutput = true, sdk = undefine parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsCreateFirebaseOAuthMigrationRequestParams * @property {string[]} resources List of resources to migrate * @property {string} projectId Project ID of the Firebase Project + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -240,8 +256,9 @@ const migrationsDeleteFirebaseAuth = async ({ parseOutput = true, sdk = undefine /** * @param {MigrationsCreateFirebaseOAuthMigrationRequestParams} params */ -const migrationsCreateFirebaseOAuthMigration = async ({ resources, projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsCreateFirebaseOAuthMigration = async ({resources,projectId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase/oauth'; let payload = {}; resources = resources === true ? [] : resources; @@ -262,12 +279,14 @@ const migrationsCreateFirebaseOAuthMigration = async ({ resources, projectId, pa parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsListFirebaseProjectsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -275,8 +294,9 @@ const migrationsCreateFirebaseOAuthMigration = async ({ resources, projectId, pa /** * @param {MigrationsListFirebaseProjectsRequestParams} params */ -const migrationsListFirebaseProjects = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsListFirebaseProjects = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase/projects'; let payload = {}; @@ -290,14 +310,16 @@ const migrationsListFirebaseProjects = async ({ parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsGetFirebaseReportRequestParams * @property {string[]} resources List of resources to migrate * @property {string} serviceAccount JSON of the Firebase service account credentials + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -305,8 +327,9 @@ const migrationsListFirebaseProjects = async ({ parseOutput = true, sdk = undefi /** * @param {MigrationsGetFirebaseReportRequestParams} params */ -const migrationsGetFirebaseReport = async ({ resources, serviceAccount, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGetFirebaseReport = async ({resources,serviceAccount,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase/report'; let payload = {}; if (typeof resources !== 'undefined') { @@ -326,14 +349,16 @@ const migrationsGetFirebaseReport = async ({ resources, serviceAccount, parseOut parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsGetFirebaseReportOAuthRequestParams * @property {string[]} resources List of resources to migrate * @property {string} projectId Project ID + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -341,8 +366,9 @@ const migrationsGetFirebaseReport = async ({ resources, serviceAccount, parseOut /** * @param {MigrationsGetFirebaseReportOAuthRequestParams} params */ -const migrationsGetFirebaseReportOAuth = async ({ resources, projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGetFirebaseReportOAuth = async ({resources,projectId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/firebase/report/oauth'; let payload = {}; if (typeof resources !== 'undefined') { @@ -362,8 +388,9 @@ const migrationsGetFirebaseReportOAuth = async ({ resources, projectId, parseOut parse(response) success() } - + return response; + } /** @@ -376,6 +403,7 @@ const migrationsGetFirebaseReportOAuth = async ({ resources, projectId, parseOut * @property {string} username Source's Database Username * @property {string} password Source's Database Password * @property {number} port Source's Database Port + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -383,8 +411,9 @@ const migrationsGetFirebaseReportOAuth = async ({ resources, projectId, parseOut /** * @param {MigrationsCreateNHostMigrationRequestParams} params */ -const migrationsCreateNHostMigration = async ({ resources, subdomain, region, adminSecret, database, username, password, port, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsCreateNHostMigration = async ({resources,subdomain,region,adminSecret,database,username,password,port,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/nhost'; let payload = {}; resources = resources === true ? [] : resources; @@ -423,8 +452,9 @@ const migrationsCreateNHostMigration = async ({ resources, subdomain, region, ad parse(response) success() } - + return response; + } /** @@ -437,6 +467,7 @@ const migrationsCreateNHostMigration = async ({ resources, subdomain, region, ad * @property {string} username Source's Database Username. * @property {string} password Source's Database Password. * @property {number} port Source's Database Port. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -444,8 +475,9 @@ const migrationsCreateNHostMigration = async ({ resources, subdomain, region, ad /** * @param {MigrationsGetNHostReportRequestParams} params */ -const migrationsGetNHostReport = async ({ resources, subdomain, region, adminSecret, database, username, password, port, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGetNHostReport = async ({resources,subdomain,region,adminSecret,database,username,password,port,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/nhost/report'; let payload = {}; if (typeof resources !== 'undefined') { @@ -483,8 +515,9 @@ const migrationsGetNHostReport = async ({ resources, subdomain, region, adminSec parse(response) success() } - + return response; + } /** @@ -496,6 +529,7 @@ const migrationsGetNHostReport = async ({ resources, subdomain, region, adminSec * @property {string} username Source's Database Username * @property {string} password Source's Database Password * @property {number} port Source's Database Port + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -503,8 +537,9 @@ const migrationsGetNHostReport = async ({ resources, subdomain, region, adminSec /** * @param {MigrationsCreateSupabaseMigrationRequestParams} params */ -const migrationsCreateSupabaseMigration = async ({ resources, endpoint, apiKey, databaseHost, username, password, port, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsCreateSupabaseMigration = async ({resources,endpoint,apiKey,databaseHost,username,password,port,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/supabase'; let payload = {}; resources = resources === true ? [] : resources; @@ -540,8 +575,9 @@ const migrationsCreateSupabaseMigration = async ({ resources, endpoint, apiKey, parse(response) success() } - + return response; + } /** @@ -553,6 +589,7 @@ const migrationsCreateSupabaseMigration = async ({ resources, endpoint, apiKey, * @property {string} username Source's Database Username. * @property {string} password Source's Database Password. * @property {number} port Source's Database Port. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -560,8 +597,9 @@ const migrationsCreateSupabaseMigration = async ({ resources, endpoint, apiKey, /** * @param {MigrationsGetSupabaseReportRequestParams} params */ -const migrationsGetSupabaseReport = async ({ resources, endpoint, apiKey, databaseHost, username, password, port, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGetSupabaseReport = async ({resources,endpoint,apiKey,databaseHost,username,password,port,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/supabase/report'; let payload = {}; if (typeof resources !== 'undefined') { @@ -596,13 +634,15 @@ const migrationsGetSupabaseReport = async ({ resources, endpoint, apiKey, databa parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsGetRequestParams * @property {string} migrationId Migration unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -610,8 +650,9 @@ const migrationsGetSupabaseReport = async ({ resources, endpoint, apiKey, databa /** * @param {MigrationsGetRequestParams} params */ -const migrationsGet = async ({ migrationId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsGet = async ({migrationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/{migrationId}'.replace('{migrationId}', migrationId); let payload = {}; @@ -625,13 +666,15 @@ const migrationsGet = async ({ migrationId, parseOutput = true, sdk = undefined} parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsRetryRequestParams * @property {string} migrationId Migration unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -639,8 +682,9 @@ const migrationsGet = async ({ migrationId, parseOutput = true, sdk = undefined} /** * @param {MigrationsRetryRequestParams} params */ -const migrationsRetry = async ({ migrationId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsRetry = async ({migrationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/{migrationId}'.replace('{migrationId}', migrationId); let payload = {}; @@ -654,13 +698,15 @@ const migrationsRetry = async ({ migrationId, parseOutput = true, sdk = undefine parse(response) success() } - + return response; + } /** * @typedef {Object} MigrationsDeleteRequestParams * @property {string} migrationId Migration ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -668,8 +714,9 @@ const migrationsRetry = async ({ migrationId, parseOutput = true, sdk = undefine /** * @param {MigrationsDeleteRequestParams} params */ -const migrationsDelete = async ({ migrationId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const migrationsDelete = async ({migrationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/migrations/{migrationId}'.replace('{migrationId}', migrationId); let payload = {}; @@ -683,8 +730,9 @@ const migrationsDelete = async ({ migrationId, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } migrations @@ -836,4 +884,4 @@ module.exports = { migrationsGet, migrationsRetry, migrationsDelete -}; \ No newline at end of file +}; diff --git a/lib/commands/project.js b/lib/commands/project.js index 126827c..1251a64 100644 --- a/lib/commands/project.js +++ b/lib/commands/project.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -44,6 +44,7 @@ const project = new Command("project").description(commandDescriptions['project' * @property {string} startDate Starting date for the usage * @property {string} endDate End date for the usage * @property {ProjectUsageRange} period Period used + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -51,8 +52,9 @@ const project = new Command("project").description(commandDescriptions['project' /** * @param {ProjectGetUsageRequestParams} params */ -const projectGetUsage = async ({ startDate, endDate, period, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectGetUsage = async ({startDate,endDate,period,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/usage'; let payload = {}; if (typeof startDate !== 'undefined') { @@ -75,12 +77,14 @@ const projectGetUsage = async ({ startDate, endDate, period, parseOutput = true, parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectListVariablesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -88,8 +92,9 @@ const projectGetUsage = async ({ startDate, endDate, period, parseOutput = true, /** * @param {ProjectListVariablesRequestParams} params */ -const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectListVariables = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/variables'; let payload = {}; @@ -103,14 +108,16 @@ const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectCreateVariableRequestParams * @property {string} key Variable key. Max length: 255 chars. * @property {string} value Variable value. Max length: 8192 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -118,8 +125,9 @@ const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => { /** * @param {ProjectCreateVariableRequestParams} params */ -const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectCreateVariable = async ({key,value,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/variables'; let payload = {}; if (typeof key !== 'undefined') { @@ -139,13 +147,15 @@ const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectGetVariableRequestParams * @property {string} variableId Variable unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -153,8 +163,9 @@ const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = und /** * @param {ProjectGetVariableRequestParams} params */ -const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectGetVariable = async ({variableId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); let payload = {}; @@ -168,8 +179,9 @@ const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** @@ -177,6 +189,7 @@ const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefi * @property {string} variableId Variable unique ID. * @property {string} key Variable key. Max length: 255 chars. * @property {string} value Variable value. Max length: 8192 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -184,8 +197,9 @@ const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefi /** * @param {ProjectUpdateVariableRequestParams} params */ -const projectUpdateVariable = async ({ variableId, key, value, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectUpdateVariable = async ({variableId,key,value,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); let payload = {}; if (typeof key !== 'undefined') { @@ -205,13 +219,15 @@ const projectUpdateVariable = async ({ variableId, key, value, parseOutput = tru parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectDeleteVariableRequestParams * @property {string} variableId Variable unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -219,8 +235,9 @@ const projectUpdateVariable = async ({ variableId, key, value, parseOutput = tru /** * @param {ProjectDeleteVariableRequestParams} params */ -const projectDeleteVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const projectDeleteVariable = async ({variableId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); let payload = {}; @@ -234,8 +251,9 @@ const projectDeleteVariable = async ({ variableId, parseOutput = true, sdk = und parse(response) success() } - + return response; + } project @@ -286,4 +304,4 @@ module.exports = { projectGetVariable, projectUpdateVariable, projectDeleteVariable -}; \ No newline at end of file +}; diff --git a/lib/commands/projects.js b/lib/commands/projects.js index e613579..5b5c153 100644 --- a/lib/commands/projects.js +++ b/lib/commands/projects.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const projects = new Command("projects").description(commandDescriptions['projec * @typedef {Object} ProjectsListRequestParams * @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, teamId * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const projects = new Command("projects").description(commandDescriptions['projec /** * @param {ProjectsListRequestParams} params */ -const projectsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const projectsList = async ({ queries, search, parseOutput = true, sdk = undefin }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'list'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -90,6 +97,7 @@ const projectsList = async ({ queries, search, parseOutput = true, sdk = undefin * @property {string} legalCity Project legal City. Max length: 256 chars. * @property {string} legalAddress Project legal Address. Max length: 256 chars. * @property {string} legalTaxId Project legal Tax ID. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -97,8 +105,9 @@ const projectsList = async ({ queries, search, parseOutput = true, sdk = undefin /** * @param {ProjectsCreateRequestParams} params */ -const projectsCreate = async ({ projectId, name, teamId, region, description, logo, url, legalName, legalCountry, legalState, legalCity, legalAddress, legalTaxId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsCreate = async ({projectId,name,teamId,region,description,logo,url,legalName,legalCountry,legalState,legalCity,legalAddress,legalTaxId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects'; let payload = {}; if (typeof projectId !== 'undefined') { @@ -151,13 +160,15 @@ const projectsCreate = async ({ projectId, name, teamId, region, description, lo parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsGetRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -165,8 +176,9 @@ const projectsCreate = async ({ projectId, name, teamId, region, description, lo /** * @param {ProjectsGetRequestParams} params */ -const projectsGet = async ({ projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGet = async ({projectId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}'.replace('{projectId}', projectId); let payload = {}; @@ -177,11 +189,16 @@ const projectsGet = async ({ projectId, parseOutput = true, sdk = undefined}) => }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'get', projectId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -197,6 +214,7 @@ const projectsGet = async ({ projectId, parseOutput = true, sdk = undefined}) => * @property {string} legalCity Project legal city. Max length: 256 chars. * @property {string} legalAddress Project legal address. Max length: 256 chars. * @property {string} legalTaxId Project legal tax ID. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -204,8 +222,9 @@ const projectsGet = async ({ projectId, parseOutput = true, sdk = undefined}) => /** * @param {ProjectsUpdateRequestParams} params */ -const projectsUpdate = async ({ projectId, name, description, logo, url, legalName, legalCountry, legalState, legalCity, legalAddress, legalTaxId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdate = async ({projectId,name,description,logo,url,legalName,legalCountry,legalState,legalCity,legalAddress,legalTaxId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}'.replace('{projectId}', projectId); let payload = {}; if (typeof name !== 'undefined') { @@ -249,13 +268,15 @@ const projectsUpdate = async ({ projectId, name, description, logo, url, legalNa parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsDeleteRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -263,8 +284,9 @@ const projectsUpdate = async ({ projectId, name, description, logo, url, legalNa /** * @param {ProjectsDeleteRequestParams} params */ -const projectsDelete = async ({ projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDelete = async ({projectId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}'.replace('{projectId}', projectId); let payload = {}; @@ -278,8 +300,9 @@ const projectsDelete = async ({ projectId, parseOutput = true, sdk = undefined}) parse(response) success() } - + return response; + } /** @@ -287,6 +310,7 @@ const projectsDelete = async ({ projectId, parseOutput = true, sdk = undefined}) * @property {string} projectId Project unique ID. * @property {Api} api API name. * @property {boolean} status API status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -294,8 +318,9 @@ const projectsDelete = async ({ projectId, parseOutput = true, sdk = undefined}) /** * @param {ProjectsUpdateApiStatusRequestParams} params */ -const projectsUpdateApiStatus = async ({ projectId, api, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateApiStatus = async ({projectId,api,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/api'.replace('{projectId}', projectId); let payload = {}; if (typeof api !== 'undefined') { @@ -315,14 +340,16 @@ const projectsUpdateApiStatus = async ({ projectId, api, status, parseOutput = t parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateApiStatusAllRequestParams * @property {string} projectId Project unique ID. * @property {boolean} status API status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -330,8 +357,9 @@ const projectsUpdateApiStatus = async ({ projectId, api, status, parseOutput = t /** * @param {ProjectsUpdateApiStatusAllRequestParams} params */ -const projectsUpdateApiStatusAll = async ({ projectId, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateApiStatusAll = async ({projectId,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/api/all'.replace('{projectId}', projectId); let payload = {}; if (typeof status !== 'undefined') { @@ -348,14 +376,16 @@ const projectsUpdateApiStatusAll = async ({ projectId, status, parseOutput = tru parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateAuthDurationRequestParams * @property {string} projectId Project unique ID. * @property {number} duration Project session length in seconds. Max length: 31536000 seconds. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -363,8 +393,9 @@ const projectsUpdateApiStatusAll = async ({ projectId, status, parseOutput = tru /** * @param {ProjectsUpdateAuthDurationRequestParams} params */ -const projectsUpdateAuthDuration = async ({ projectId, duration, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthDuration = async ({projectId,duration,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/duration'.replace('{projectId}', projectId); let payload = {}; if (typeof duration !== 'undefined') { @@ -381,14 +412,16 @@ const projectsUpdateAuthDuration = async ({ projectId, duration, parseOutput = t parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateAuthLimitRequestParams * @property {string} projectId Project unique ID. * @property {number} limit Set the max number of users allowed in this project. Use 0 for unlimited. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -396,8 +429,9 @@ const projectsUpdateAuthDuration = async ({ projectId, duration, parseOutput = t /** * @param {ProjectsUpdateAuthLimitRequestParams} params */ -const projectsUpdateAuthLimit = async ({ projectId, limit, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthLimit = async ({projectId,limit,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/limit'.replace('{projectId}', projectId); let payload = {}; if (typeof limit !== 'undefined') { @@ -414,14 +448,16 @@ const projectsUpdateAuthLimit = async ({ projectId, limit, parseOutput = true, s parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateAuthSessionsLimitRequestParams * @property {string} projectId Project unique ID. * @property {number} limit Set the max number of users allowed in this project. Value allowed is between 1-100. Default is 10 + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -429,8 +465,9 @@ const projectsUpdateAuthLimit = async ({ projectId, limit, parseOutput = true, s /** * @param {ProjectsUpdateAuthSessionsLimitRequestParams} params */ -const projectsUpdateAuthSessionsLimit = async ({ projectId, limit, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthSessionsLimit = async ({projectId,limit,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/max-sessions'.replace('{projectId}', projectId); let payload = {}; if (typeof limit !== 'undefined') { @@ -447,14 +484,53 @@ const projectsUpdateAuthSessionsLimit = async ({ projectId, limit, parseOutput = parse(response) success() } - + + return response; + +} + +/** + * @typedef {Object} ProjectsUpdateMockNumbersRequestParams + * @property {string} projectId Project unique ID. + * @property {object[]} numbers An array of mock numbers and their corresponding verification codes (OTPs). Each number should be a valid E.164 formatted phone number. Maximum of 10 numbers are allowed. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {ProjectsUpdateMockNumbersRequestParams} params + */ +const projectsUpdateMockNumbers = async ({projectId,numbers,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; + let apiPath = '/projects/{projectId}/auth/mock-numbers'.replace('{projectId}', projectId); + let payload = {}; + numbers = numbers === true ? [] : numbers; + if (typeof numbers !== 'undefined') { + payload['numbers'] = numbers; + } + + let response = undefined; + + response = await client.call('patch', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + return response; + } /** * @typedef {Object} ProjectsUpdateAuthPasswordDictionaryRequestParams * @property {string} projectId Project unique ID. * @property {boolean} enabled Set whether or not to enable checking user's password against most commonly used passwords. Default is false. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -462,8 +538,9 @@ const projectsUpdateAuthSessionsLimit = async ({ projectId, limit, parseOutput = /** * @param {ProjectsUpdateAuthPasswordDictionaryRequestParams} params */ -const projectsUpdateAuthPasswordDictionary = async ({ projectId, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthPasswordDictionary = async ({projectId,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/password-dictionary'.replace('{projectId}', projectId); let payload = {}; if (typeof enabled !== 'undefined') { @@ -480,14 +557,16 @@ const projectsUpdateAuthPasswordDictionary = async ({ projectId, enabled, parseO parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateAuthPasswordHistoryRequestParams * @property {string} projectId Project unique ID. * @property {number} limit Set the max number of passwords to store in user history. User can't choose a new password that is already stored in the password history list. Max number of passwords allowed in history is20. Default value is 0 + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -495,8 +574,9 @@ const projectsUpdateAuthPasswordDictionary = async ({ projectId, enabled, parseO /** * @param {ProjectsUpdateAuthPasswordHistoryRequestParams} params */ -const projectsUpdateAuthPasswordHistory = async ({ projectId, limit, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthPasswordHistory = async ({projectId,limit,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/password-history'.replace('{projectId}', projectId); let payload = {}; if (typeof limit !== 'undefined') { @@ -513,14 +593,16 @@ const projectsUpdateAuthPasswordHistory = async ({ projectId, limit, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdatePersonalDataCheckRequestParams * @property {string} projectId Project unique ID. * @property {boolean} enabled Set whether or not to check a password for similarity with personal data. Default is false. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -528,8 +610,9 @@ const projectsUpdateAuthPasswordHistory = async ({ projectId, limit, parseOutput /** * @param {ProjectsUpdatePersonalDataCheckRequestParams} params */ -const projectsUpdatePersonalDataCheck = async ({ projectId, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdatePersonalDataCheck = async ({projectId,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/personal-data'.replace('{projectId}', projectId); let payload = {}; if (typeof enabled !== 'undefined') { @@ -546,8 +629,45 @@ const projectsUpdatePersonalDataCheck = async ({ projectId, enabled, parseOutput parse(response) success() } - + return response; + +} + +/** + * @typedef {Object} ProjectsUpdateSessionAlertsRequestParams + * @property {string} projectId Project unique ID. + * @property {boolean} alerts Set to true to enable session emails. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {ProjectsUpdateSessionAlertsRequestParams} params + */ +const projectsUpdateSessionAlerts = async ({projectId,alerts,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; + let apiPath = '/projects/{projectId}/auth/session-alerts'.replace('{projectId}', projectId); + let payload = {}; + if (typeof alerts !== 'undefined') { + payload['alerts'] = alerts; + } + + let response = undefined; + + response = await client.call('patch', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + + return response; + } /** @@ -555,6 +675,7 @@ const projectsUpdatePersonalDataCheck = async ({ projectId, enabled, parseOutput * @property {string} projectId Project unique ID. * @property {AuthMethod} method Auth Method. Possible values: email-password,magic-url,email-otp,anonymous,invites,jwt,phone * @property {boolean} status Set the status of this auth method. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -562,8 +683,9 @@ const projectsUpdatePersonalDataCheck = async ({ projectId, enabled, parseOutput /** * @param {ProjectsUpdateAuthStatusRequestParams} params */ -const projectsUpdateAuthStatus = async ({ projectId, method, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateAuthStatus = async ({projectId,method,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/auth/{method}'.replace('{projectId}', projectId).replace('{method}', method); let payload = {}; if (typeof status !== 'undefined') { @@ -580,13 +702,56 @@ const projectsUpdateAuthStatus = async ({ projectId, method, status, parseOutput parse(response) success() } - + + return response; + +} + +/** + * @typedef {Object} ProjectsCreateJWTRequestParams + * @property {string} projectId Project unique ID. + * @property {string[]} scopes List of scopes allowed for JWT key. Maximum of 100 scopes are allowed. + * @property {number} duration Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {ProjectsCreateJWTRequestParams} params + */ +const projectsCreateJWT = async ({projectId,scopes,duration,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; + let apiPath = '/projects/{projectId}/jwts'.replace('{projectId}', projectId); + let payload = {}; + scopes = scopes === true ? [] : scopes; + if (typeof scopes !== 'undefined') { + payload['scopes'] = scopes; + } + if (typeof duration !== 'undefined') { + payload['duration'] = duration; + } + + let response = undefined; + + response = await client.call('post', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + return response; + } /** * @typedef {Object} ProjectsListKeysRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -594,8 +759,9 @@ const projectsUpdateAuthStatus = async ({ projectId, method, status, parseOutput /** * @param {ProjectsListKeysRequestParams} params */ -const projectsListKeys = async ({ projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsListKeys = async ({projectId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/keys'.replace('{projectId}', projectId); let payload = {}; @@ -606,11 +772,16 @@ const projectsListKeys = async ({ projectId, parseOutput = true, sdk = undefined }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listKeys', projectId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -619,6 +790,7 @@ const projectsListKeys = async ({ projectId, parseOutput = true, sdk = undefined * @property {string} name Key name. Max length: 128 chars. * @property {string[]} scopes Key scopes list. Maximum of 100 scopes are allowed. * @property {string} expire Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -626,8 +798,9 @@ const projectsListKeys = async ({ projectId, parseOutput = true, sdk = undefined /** * @param {ProjectsCreateKeyRequestParams} params */ -const projectsCreateKey = async ({ projectId, name, scopes, expire, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsCreateKey = async ({projectId,name,scopes,expire,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/keys'.replace('{projectId}', projectId); let payload = {}; if (typeof name !== 'undefined') { @@ -651,14 +824,16 @@ const projectsCreateKey = async ({ projectId, name, scopes, expire, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsGetKeyRequestParams * @property {string} projectId Project unique ID. * @property {string} keyId Key unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -666,8 +841,9 @@ const projectsCreateKey = async ({ projectId, name, scopes, expire, parseOutput /** * @param {ProjectsGetKeyRequestParams} params */ -const projectsGetKey = async ({ projectId, keyId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGetKey = async ({projectId,keyId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/keys/{keyId}'.replace('{projectId}', projectId).replace('{keyId}', keyId); let payload = {}; @@ -678,11 +854,16 @@ const projectsGetKey = async ({ projectId, keyId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'getKey', projectId, keyId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -692,6 +873,7 @@ const projectsGetKey = async ({ projectId, keyId, parseOutput = true, sdk = unde * @property {string} name Key name. Max length: 128 chars. * @property {string[]} scopes Key scopes list. Maximum of 100 events are allowed. * @property {string} expire Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -699,8 +881,9 @@ const projectsGetKey = async ({ projectId, keyId, parseOutput = true, sdk = unde /** * @param {ProjectsUpdateKeyRequestParams} params */ -const projectsUpdateKey = async ({ projectId, keyId, name, scopes, expire, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateKey = async ({projectId,keyId,name,scopes,expire,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/keys/{keyId}'.replace('{projectId}', projectId).replace('{keyId}', keyId); let payload = {}; if (typeof name !== 'undefined') { @@ -724,14 +907,16 @@ const projectsUpdateKey = async ({ projectId, keyId, name, scopes, expire, parse parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsDeleteKeyRequestParams * @property {string} projectId Project unique ID. * @property {string} keyId Key unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -739,8 +924,9 @@ const projectsUpdateKey = async ({ projectId, keyId, name, scopes, expire, parse /** * @param {ProjectsDeleteKeyRequestParams} params */ -const projectsDeleteKey = async ({ projectId, keyId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDeleteKey = async ({projectId,keyId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/keys/{keyId}'.replace('{projectId}', projectId).replace('{keyId}', keyId); let payload = {}; @@ -754,8 +940,9 @@ const projectsDeleteKey = async ({ projectId, keyId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** @@ -765,6 +952,7 @@ const projectsDeleteKey = async ({ projectId, keyId, parseOutput = true, sdk = u * @property {string} appId Provider app ID. Max length: 256 chars. * @property {string} secret Provider secret key. Max length: 512 chars. * @property {boolean} enabled Provider status. Set to 'false' to disable new session creation. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -772,8 +960,9 @@ const projectsDeleteKey = async ({ projectId, keyId, parseOutput = true, sdk = u /** * @param {ProjectsUpdateOAuth2RequestParams} params */ -const projectsUpdateOAuth2 = async ({ projectId, provider, appId, secret, enabled, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateOAuth2 = async ({projectId,provider,appId,secret,enabled,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/oauth2'.replace('{projectId}', projectId); let payload = {}; if (typeof provider !== 'undefined') { @@ -799,13 +988,15 @@ const projectsUpdateOAuth2 = async ({ projectId, provider, appId, secret, enable parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsListPlatformsRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -813,8 +1004,9 @@ const projectsUpdateOAuth2 = async ({ projectId, provider, appId, secret, enable /** * @param {ProjectsListPlatformsRequestParams} params */ -const projectsListPlatforms = async ({ projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsListPlatforms = async ({projectId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/platforms'.replace('{projectId}', projectId); let payload = {}; @@ -825,11 +1017,16 @@ const projectsListPlatforms = async ({ projectId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listPlatforms', projectId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -840,6 +1037,7 @@ const projectsListPlatforms = async ({ projectId, parseOutput = true, sdk = unde * @property {string} key Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars. * @property {string} store App store or Google Play store ID. Max length: 256 chars. * @property {string} hostname Platform client hostname. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -847,8 +1045,9 @@ const projectsListPlatforms = async ({ projectId, parseOutput = true, sdk = unde /** * @param {ProjectsCreatePlatformRequestParams} params */ -const projectsCreatePlatform = async ({ projectId, type, name, key, store, hostname, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsCreatePlatform = async ({projectId,type,name,key,store,hostname,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/platforms'.replace('{projectId}', projectId); let payload = {}; if (typeof type !== 'undefined') { @@ -877,14 +1076,16 @@ const projectsCreatePlatform = async ({ projectId, type, name, key, store, hostn parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsGetPlatformRequestParams * @property {string} projectId Project unique ID. * @property {string} platformId Platform unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -892,8 +1093,9 @@ const projectsCreatePlatform = async ({ projectId, type, name, key, store, hostn /** * @param {ProjectsGetPlatformRequestParams} params */ -const projectsGetPlatform = async ({ projectId, platformId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGetPlatform = async ({projectId,platformId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/platforms/{platformId}'.replace('{projectId}', projectId).replace('{platformId}', platformId); let payload = {}; @@ -904,11 +1106,16 @@ const projectsGetPlatform = async ({ projectId, platformId, parseOutput = true, }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'getPlatform', projectId, platformId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -919,6 +1126,7 @@ const projectsGetPlatform = async ({ projectId, platformId, parseOutput = true, * @property {string} key Package name for android or bundle ID for iOS. Max length: 256 chars. * @property {string} store App store or Google Play store ID. Max length: 256 chars. * @property {string} hostname Platform client URL. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -926,8 +1134,9 @@ const projectsGetPlatform = async ({ projectId, platformId, parseOutput = true, /** * @param {ProjectsUpdatePlatformRequestParams} params */ -const projectsUpdatePlatform = async ({ projectId, platformId, name, key, store, hostname, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdatePlatform = async ({projectId,platformId,name,key,store,hostname,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/platforms/{platformId}'.replace('{projectId}', projectId).replace('{platformId}', platformId); let payload = {}; if (typeof name !== 'undefined') { @@ -953,14 +1162,16 @@ const projectsUpdatePlatform = async ({ projectId, platformId, name, key, store, parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsDeletePlatformRequestParams * @property {string} projectId Project unique ID. * @property {string} platformId Platform unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -968,8 +1179,9 @@ const projectsUpdatePlatform = async ({ projectId, platformId, name, key, store, /** * @param {ProjectsDeletePlatformRequestParams} params */ -const projectsDeletePlatform = async ({ projectId, platformId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDeletePlatform = async ({projectId,platformId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/platforms/{platformId}'.replace('{projectId}', projectId).replace('{platformId}', platformId); let payload = {}; @@ -983,8 +1195,9 @@ const projectsDeletePlatform = async ({ projectId, platformId, parseOutput = tru parse(response) success() } - + return response; + } /** @@ -992,6 +1205,7 @@ const projectsDeletePlatform = async ({ projectId, platformId, parseOutput = tru * @property {string} projectId Project unique ID. * @property {ApiService} service Service name. * @property {boolean} status Service status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -999,8 +1213,9 @@ const projectsDeletePlatform = async ({ projectId, platformId, parseOutput = tru /** * @param {ProjectsUpdateServiceStatusRequestParams} params */ -const projectsUpdateServiceStatus = async ({ projectId, service, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateServiceStatus = async ({projectId,service,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/service'.replace('{projectId}', projectId); let payload = {}; if (typeof service !== 'undefined') { @@ -1020,14 +1235,16 @@ const projectsUpdateServiceStatus = async ({ projectId, service, status, parseOu parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateServiceStatusAllRequestParams * @property {string} projectId Project unique ID. * @property {boolean} status Service status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1035,8 +1252,9 @@ const projectsUpdateServiceStatus = async ({ projectId, service, status, parseOu /** * @param {ProjectsUpdateServiceStatusAllRequestParams} params */ -const projectsUpdateServiceStatusAll = async ({ projectId, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateServiceStatusAll = async ({projectId,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/service/all'.replace('{projectId}', projectId); let payload = {}; if (typeof status !== 'undefined') { @@ -1053,8 +1271,9 @@ const projectsUpdateServiceStatusAll = async ({ projectId, status, parseOutput = parse(response) success() } - + return response; + } /** @@ -1069,6 +1288,7 @@ const projectsUpdateServiceStatusAll = async ({ projectId, status, parseOutput = * @property {string} username SMTP server username * @property {string} password SMTP server password * @property {SMTPSecure} secure Does SMTP server use secure connection + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1076,8 +1296,9 @@ const projectsUpdateServiceStatusAll = async ({ projectId, status, parseOutput = /** * @param {ProjectsUpdateSmtpRequestParams} params */ -const projectsUpdateSmtp = async ({ projectId, enabled, senderName, senderEmail, replyTo, host, port, username, password, secure, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateSmtp = async ({projectId,enabled,senderName,senderEmail,replyTo,host,port,username,password,secure,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/smtp'.replace('{projectId}', projectId); let payload = {}; if (typeof enabled !== 'undefined') { @@ -1118,8 +1339,9 @@ const projectsUpdateSmtp = async ({ projectId, enabled, senderName, senderEmail, parse(response) success() } - + return response; + } /** @@ -1134,6 +1356,7 @@ const projectsUpdateSmtp = async ({ projectId, enabled, senderName, senderEmail, * @property {string} username SMTP server username * @property {string} password SMTP server password * @property {SMTPSecure} secure Does SMTP server use secure connection + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1141,8 +1364,9 @@ const projectsUpdateSmtp = async ({ projectId, enabled, senderName, senderEmail, /** * @param {ProjectsCreateSmtpTestRequestParams} params */ -const projectsCreateSmtpTest = async ({ projectId, emails, senderName, senderEmail, host, replyTo, port, username, password, secure, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsCreateSmtpTest = async ({projectId,emails,senderName,senderEmail,host,replyTo,port,username,password,secure,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/smtp/tests'.replace('{projectId}', projectId); let payload = {}; emails = emails === true ? [] : emails; @@ -1184,14 +1408,16 @@ const projectsCreateSmtpTest = async ({ projectId, emails, senderName, senderEma parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateTeamRequestParams * @property {string} projectId Project unique ID. * @property {string} teamId Team ID of the team to transfer project to. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1199,8 +1425,9 @@ const projectsCreateSmtpTest = async ({ projectId, emails, senderName, senderEma /** * @param {ProjectsUpdateTeamRequestParams} params */ -const projectsUpdateTeam = async ({ projectId, teamId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateTeam = async ({projectId,teamId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/team'.replace('{projectId}', projectId); let payload = {}; if (typeof teamId !== 'undefined') { @@ -1217,8 +1444,9 @@ const projectsUpdateTeam = async ({ projectId, teamId, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** @@ -1226,6 +1454,7 @@ const projectsUpdateTeam = async ({ projectId, teamId, parseOutput = true, sdk = * @property {string} projectId Project unique ID. * @property {EmailTemplateType} type Template type * @property {EmailTemplateLocale} locale Template locale + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1233,8 +1462,9 @@ const projectsUpdateTeam = async ({ projectId, teamId, parseOutput = true, sdk = /** * @param {ProjectsGetEmailTemplateRequestParams} params */ -const projectsGetEmailTemplate = async ({ projectId, type, locale, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGetEmailTemplate = async ({projectId,type,locale,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/email/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; @@ -1248,8 +1478,9 @@ const projectsGetEmailTemplate = async ({ projectId, type, locale, parseOutput = parse(response) success() } - + return response; + } /** @@ -1262,6 +1493,7 @@ const projectsGetEmailTemplate = async ({ projectId, type, locale, parseOutput = * @property {string} senderName Name of the email sender * @property {string} senderEmail Email of the sender * @property {string} replyTo Reply to email + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1269,8 +1501,9 @@ const projectsGetEmailTemplate = async ({ projectId, type, locale, parseOutput = /** * @param {ProjectsUpdateEmailTemplateRequestParams} params */ -const projectsUpdateEmailTemplate = async ({ projectId, type, locale, subject, message, senderName, senderEmail, replyTo, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateEmailTemplate = async ({projectId,type,locale,subject,message,senderName,senderEmail,replyTo,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/email/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; if (typeof subject !== 'undefined') { @@ -1299,8 +1532,9 @@ const projectsUpdateEmailTemplate = async ({ projectId, type, locale, subject, m parse(response) success() } - + return response; + } /** @@ -1308,6 +1542,7 @@ const projectsUpdateEmailTemplate = async ({ projectId, type, locale, subject, m * @property {string} projectId Project unique ID. * @property {EmailTemplateType} type Template type * @property {EmailTemplateLocale} locale Template locale + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1315,8 +1550,9 @@ const projectsUpdateEmailTemplate = async ({ projectId, type, locale, subject, m /** * @param {ProjectsDeleteEmailTemplateRequestParams} params */ -const projectsDeleteEmailTemplate = async ({ projectId, type, locale, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDeleteEmailTemplate = async ({projectId,type,locale,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/email/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; @@ -1330,8 +1566,9 @@ const projectsDeleteEmailTemplate = async ({ projectId, type, locale, parseOutpu parse(response) success() } - + return response; + } /** @@ -1339,6 +1576,7 @@ const projectsDeleteEmailTemplate = async ({ projectId, type, locale, parseOutpu * @property {string} projectId Project unique ID. * @property {SmsTemplateType} type Template type * @property {SmsTemplateLocale} locale Template locale + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1346,8 +1584,9 @@ const projectsDeleteEmailTemplate = async ({ projectId, type, locale, parseOutpu /** * @param {ProjectsGetSmsTemplateRequestParams} params */ -const projectsGetSmsTemplate = async ({ projectId, type, locale, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGetSmsTemplate = async ({projectId,type,locale,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/sms/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; @@ -1361,8 +1600,9 @@ const projectsGetSmsTemplate = async ({ projectId, type, locale, parseOutput = t parse(response) success() } - + return response; + } /** @@ -1371,6 +1611,7 @@ const projectsGetSmsTemplate = async ({ projectId, type, locale, parseOutput = t * @property {SmsTemplateType} type Template type * @property {SmsTemplateLocale} locale Template locale * @property {string} message Template message + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1378,8 +1619,9 @@ const projectsGetSmsTemplate = async ({ projectId, type, locale, parseOutput = t /** * @param {ProjectsUpdateSmsTemplateRequestParams} params */ -const projectsUpdateSmsTemplate = async ({ projectId, type, locale, message, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateSmsTemplate = async ({projectId,type,locale,message,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/sms/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; if (typeof message !== 'undefined') { @@ -1396,8 +1638,9 @@ const projectsUpdateSmsTemplate = async ({ projectId, type, locale, message, par parse(response) success() } - + return response; + } /** @@ -1405,6 +1648,7 @@ const projectsUpdateSmsTemplate = async ({ projectId, type, locale, message, par * @property {string} projectId Project unique ID. * @property {SmsTemplateType} type Template type * @property {SmsTemplateLocale} locale Template locale + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1412,8 +1656,9 @@ const projectsUpdateSmsTemplate = async ({ projectId, type, locale, message, par /** * @param {ProjectsDeleteSmsTemplateRequestParams} params */ -const projectsDeleteSmsTemplate = async ({ projectId, type, locale, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDeleteSmsTemplate = async ({projectId,type,locale,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/templates/sms/{type}/{locale}'.replace('{projectId}', projectId).replace('{type}', type).replace('{locale}', locale); let payload = {}; @@ -1427,13 +1672,15 @@ const projectsDeleteSmsTemplate = async ({ projectId, type, locale, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsListWebhooksRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1441,8 +1688,9 @@ const projectsDeleteSmsTemplate = async ({ projectId, type, locale, parseOutput /** * @param {ProjectsListWebhooksRequestParams} params */ -const projectsListWebhooks = async ({ projectId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsListWebhooks = async ({projectId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks'.replace('{projectId}', projectId); let payload = {}; @@ -1453,11 +1701,16 @@ const projectsListWebhooks = async ({ projectId, parseOutput = true, sdk = undef }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listWebhooks', projectId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1470,6 +1723,7 @@ const projectsListWebhooks = async ({ projectId, parseOutput = true, sdk = undef * @property {boolean} enabled Enable or disable a webhook. * @property {string} httpUser Webhook HTTP user. Max length: 256 chars. * @property {string} httpPass Webhook HTTP password. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1477,8 +1731,9 @@ const projectsListWebhooks = async ({ projectId, parseOutput = true, sdk = undef /** * @param {ProjectsCreateWebhookRequestParams} params */ -const projectsCreateWebhook = async ({ projectId, name, events, url, security, enabled, httpUser, httpPass, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsCreateWebhook = async ({projectId,name,events,url,security,enabled,httpUser,httpPass,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks'.replace('{projectId}', projectId); let payload = {}; if (typeof name !== 'undefined') { @@ -1514,14 +1769,16 @@ const projectsCreateWebhook = async ({ projectId, name, events, url, security, e parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsGetWebhookRequestParams * @property {string} projectId Project unique ID. * @property {string} webhookId Webhook unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1529,8 +1786,9 @@ const projectsCreateWebhook = async ({ projectId, name, events, url, security, e /** * @param {ProjectsGetWebhookRequestParams} params */ -const projectsGetWebhook = async ({ projectId, webhookId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsGetWebhook = async ({projectId,webhookId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks/{webhookId}'.replace('{projectId}', projectId).replace('{webhookId}', webhookId); let payload = {}; @@ -1541,11 +1799,16 @@ const projectsGetWebhook = async ({ projectId, webhookId, parseOutput = true, sd }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'getWebhook', projectId, webhookId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -1559,6 +1822,7 @@ const projectsGetWebhook = async ({ projectId, webhookId, parseOutput = true, sd * @property {boolean} enabled Enable or disable a webhook. * @property {string} httpUser Webhook HTTP user. Max length: 256 chars. * @property {string} httpPass Webhook HTTP password. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1566,8 +1830,9 @@ const projectsGetWebhook = async ({ projectId, webhookId, parseOutput = true, sd /** * @param {ProjectsUpdateWebhookRequestParams} params */ -const projectsUpdateWebhook = async ({ projectId, webhookId, name, events, url, security, enabled, httpUser, httpPass, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateWebhook = async ({projectId,webhookId,name,events,url,security,enabled,httpUser,httpPass,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks/{webhookId}'.replace('{projectId}', projectId).replace('{webhookId}', webhookId); let payload = {}; if (typeof name !== 'undefined') { @@ -1603,14 +1868,16 @@ const projectsUpdateWebhook = async ({ projectId, webhookId, name, events, url, parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsDeleteWebhookRequestParams * @property {string} projectId Project unique ID. * @property {string} webhookId Webhook unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1618,8 +1885,9 @@ const projectsUpdateWebhook = async ({ projectId, webhookId, name, events, url, /** * @param {ProjectsDeleteWebhookRequestParams} params */ -const projectsDeleteWebhook = async ({ projectId, webhookId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsDeleteWebhook = async ({projectId,webhookId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks/{webhookId}'.replace('{projectId}', projectId).replace('{webhookId}', webhookId); let payload = {}; @@ -1633,14 +1901,16 @@ const projectsDeleteWebhook = async ({ projectId, webhookId, parseOutput = true, parse(response) success() } - + return response; + } /** * @typedef {Object} ProjectsUpdateWebhookSignatureRequestParams * @property {string} projectId Project unique ID. * @property {string} webhookId Webhook unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1648,8 +1918,9 @@ const projectsDeleteWebhook = async ({ projectId, webhookId, parseOutput = true, /** * @param {ProjectsUpdateWebhookSignatureRequestParams} params */ -const projectsUpdateWebhookSignature = async ({ projectId, webhookId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForConsole() : sdk; +const projectsUpdateWebhookSignature = async ({projectId,webhookId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForConsole() : + sdk; let apiPath = '/projects/{projectId}/webhooks/{webhookId}/signature'.replace('{projectId}', projectId).replace('{webhookId}', webhookId); let payload = {}; @@ -1663,8 +1934,9 @@ const projectsUpdateWebhookSignature = async ({ projectId, webhookId, parseOutpu parse(response) success() } - + return response; + } projects @@ -1672,6 +1944,7 @@ projects .description(``) .option(`--queries [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, teamId`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsList)) projects @@ -1696,6 +1969,7 @@ projects .command(`get`) .description(``) .requiredOption(`--projectId `, `Project unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGet)) projects @@ -1756,6 +2030,13 @@ projects .requiredOption(`--limit `, `Set the max number of users allowed in this project. Value allowed is between 1-100. Default is 10`, parseInteger) .action(actionRunner(projectsUpdateAuthSessionsLimit)) +projects + .command(`updateMockNumbers`) + .description(``) + .requiredOption(`--projectId `, `Project unique ID.`) + .requiredOption(`--numbers [numbers...]`, `An array of mock numbers and their corresponding verification codes (OTPs). Each number should be a valid E.164 formatted phone number. Maximum of 10 numbers are allowed.`) + .action(actionRunner(projectsUpdateMockNumbers)) + projects .command(`updateAuthPasswordDictionary`) .description(``) @@ -1777,6 +2058,13 @@ projects .requiredOption(`--enabled `, `Set whether or not to check a password for similarity with personal data. Default is false.`, parseBool) .action(actionRunner(projectsUpdatePersonalDataCheck)) +projects + .command(`updateSessionAlerts`) + .description(``) + .requiredOption(`--projectId `, `Project unique ID.`) + .requiredOption(`--alerts `, `Set to true to enable session emails.`, parseBool) + .action(actionRunner(projectsUpdateSessionAlerts)) + projects .command(`updateAuthStatus`) .description(``) @@ -1785,10 +2073,19 @@ projects .requiredOption(`--status `, `Set the status of this auth method.`, parseBool) .action(actionRunner(projectsUpdateAuthStatus)) +projects + .command(`createJWT`) + .description(``) + .requiredOption(`--projectId `, `Project unique ID.`) + .requiredOption(`--scopes [scopes...]`, `List of scopes allowed for JWT key. Maximum of 100 scopes are allowed.`) + .option(`--duration `, `Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.`, parseInteger) + .action(actionRunner(projectsCreateJWT)) + projects .command(`listKeys`) .description(``) .requiredOption(`--projectId `, `Project unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListKeys)) projects @@ -1805,6 +2102,7 @@ projects .description(``) .requiredOption(`--projectId `, `Project unique ID.`) .requiredOption(`--keyId `, `Key unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetKey)) projects @@ -1838,6 +2136,7 @@ projects .command(`listPlatforms`) .description(``) .requiredOption(`--projectId `, `Project unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListPlatforms)) projects @@ -1856,6 +2155,7 @@ projects .description(``) .requiredOption(`--projectId `, `Project unique ID.`) .requiredOption(`--platformId `, `Platform unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetPlatform)) projects @@ -1986,6 +2286,7 @@ projects .command(`listWebhooks`) .description(``) .requiredOption(`--projectId `, `Project unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListWebhooks)) projects @@ -2006,6 +2307,7 @@ projects .description(``) .requiredOption(`--projectId `, `Project unique ID.`) .requiredOption(`--webhookId `, `Webhook unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetWebhook)) projects @@ -2048,10 +2350,13 @@ module.exports = { projectsUpdateAuthDuration, projectsUpdateAuthLimit, projectsUpdateAuthSessionsLimit, + projectsUpdateMockNumbers, projectsUpdateAuthPasswordDictionary, projectsUpdateAuthPasswordHistory, projectsUpdatePersonalDataCheck, + projectsUpdateSessionAlerts, projectsUpdateAuthStatus, + projectsCreateJWT, projectsListKeys, projectsCreateKey, projectsGetKey, @@ -2080,4 +2385,4 @@ module.exports = { projectsUpdateWebhook, projectsDeleteWebhook, projectsUpdateWebhookSignature -}; \ No newline at end of file +}; diff --git a/lib/commands/proxy.js b/lib/commands/proxy.js index ed11a14..0c6eb08 100644 --- a/lib/commands/proxy.js +++ b/lib/commands/proxy.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const proxy = new Command("proxy").description(commandDescriptions['proxy']).con * @typedef {Object} ProxyListRulesRequestParams * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: domain, resourceType, resourceId, url * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const proxy = new Command("proxy").description(commandDescriptions['proxy']).con /** * @param {ProxyListRulesRequestParams} params */ -const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const proxyListRules = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/proxy/rules'; let payload = {}; if (typeof queries !== 'undefined') { @@ -71,8 +73,9 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** @@ -80,6 +83,7 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef * @property {string} domain Domain name. * @property {ResourceType} resourceType Action definition for the rule. Possible values are "api", "function" * @property {string} resourceId ID of resource for the action type. If resourceType is "api", leave empty. If resourceType is "function", provide ID of the function. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -87,8 +91,9 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef /** * @param {ProxyCreateRuleRequestParams} params */ -const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const proxyCreateRule = async ({domain,resourceType,resourceId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/proxy/rules'; let payload = {}; if (typeof domain !== 'undefined') { @@ -111,13 +116,15 @@ const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = parse(response) success() } - + return response; + } /** * @typedef {Object} ProxyGetRuleRequestParams * @property {string} ruleId Rule ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -125,8 +132,9 @@ const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = /** * @param {ProxyGetRuleRequestParams} params */ -const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const proxyGetRule = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId); let payload = {}; @@ -140,13 +148,15 @@ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} ProxyDeleteRuleRequestParams * @property {string} ruleId Rule ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -154,8 +164,9 @@ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => { /** * @param {ProxyDeleteRuleRequestParams} params */ -const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const proxyDeleteRule = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId); let payload = {}; @@ -169,13 +180,15 @@ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) = parse(response) success() } - + return response; + } /** * @typedef {Object} ProxyUpdateRuleVerificationRequestParams * @property {string} ruleId Rule ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -183,8 +196,9 @@ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) = /** * @param {ProxyUpdateRuleVerificationRequestParams} params */ -const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const proxyUpdateRuleVerification = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/proxy/rules/{ruleId}/verification'.replace('{ruleId}', ruleId); let payload = {}; @@ -198,8 +212,9 @@ const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } proxy @@ -242,4 +257,4 @@ module.exports = { proxyGetRule, proxyDeleteRule, proxyUpdateRuleVerification -}; \ No newline at end of file +}; diff --git a/lib/commands/pull.js b/lib/commands/pull.js new file mode 100644 index 0000000..cea0331 --- /dev/null +++ b/lib/commands/pull.js @@ -0,0 +1,231 @@ +const fs = require("fs"); +const tar = require("tar"); +const { Command } = require("commander"); +const inquirer = require("inquirer"); +const { messagingListTopics } = require("./messaging"); +const { teamsList } = require("./teams"); +const { projectsGet } = require("./projects"); +const { functionsList, functionsDownloadDeployment } = require("./functions"); +const { databasesGet, databasesListCollections, databasesList } = require("./databases"); +const { storageListBuckets } = require("./storage"); +const { localConfig } = require("../config"); +const { paginate } = require("../paginate"); +const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions"); +const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser"); + +const pullResources = async () => { + const actions = { + project: pullProject, + functions: pullFunctions, + collections: pullCollection, + buckets: pullBucket, + teams: pullTeam, + messages: pullMessagingTopic + } + + if (cliConfig.all) { + for (let action of Object.values(actions)) { + await action(); + } + } else { + const answers = await inquirer.prompt(questionsPullResources[0]); + + const action = actions[answers.resource]; + if (action !== undefined) { + await action({ returnOnZero: true }); + } + } +}; + +const pullProject = async () => { + try { + let response = await projectsGet({ + parseOutput: false, + projectId: localConfig.getProject().projectId + + }) + + localConfig.setProject(response.$id, response.name, response); + + success(); + } catch (e) { + throw e; + } +} + +const pullFunctions = async () => { + const localFunctions = localConfig.getFunctions(); + + const functions = cliConfig.all + ? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions + : (await inquirer.prompt(questionsPullFunctions)).functions; + + log(`Pulling ${functions.length} functions`); + + for (let func of functions) { + const functionExistLocally = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']) !== undefined; + + if (functionExistLocally) { + localConfig.updateFunction(func['$id'], func); + } else { + func['path'] = `functions/${func['$id']}`; + localConfig.addFunction(func); + localFunctions.push(func); + } + + const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']); + + if (localFunction['deployment'] === '') { + continue + } + + const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` + + await functionsDownloadDeployment({ + functionId: func['$id'], + deploymentId: func['deployment'], + destination: compressedFileName, + overrideForCli: true, + parseOutput: false + }) + + if (!fs.existsSync(localFunction['path'])) { + fs.mkdirSync(localFunction['path'], { recursive: true }); + } + + tar.extract({ + sync: true, + cwd: localFunction['path'], + file: compressedFileName, + strict: false, + }); + + fs.rmSync(compressedFileName); + success(`Pulled ${func['name']} code and settings`) + } +} + +const pullCollection = async () => { + let databases = cliConfig.ids; + + if (databases.length === 0) { + if (cliConfig.all) { + databases = (await paginate(databasesList, { parseOutput: false }, 100, 'databases')).databases.map(database => database.$id); + } else { + databases = (await inquirer.prompt(questionsPullCollection)).databases; + } + } + + for (const databaseId of databases) { + const database = await databasesGet({ + databaseId, + parseOutput: false + }); + + localConfig.addDatabase(database); + + const { collections, total } = await paginate(databasesListCollections, { + databaseId, + parseOutput: false + }, 100, 'collections'); + + log(`Found ${total} collections`); + + collections.map(async collection => { + log(`Fetching ${collection.name} ...`); + localConfig.addCollection({ + ...collection, + '$createdAt': undefined, + '$updatedAt': undefined + }); + }); + } + + success(); +} + +const pullBucket = async () => { + const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); + + log(`Found ${buckets.length} buckets`); + + buckets.forEach(bucket => localConfig.addBucket(bucket)); + + success(); +} + +const pullTeam = async () => { + const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams'); + + log(`Found ${teams.length} teams`); + + teams.forEach(team => { + const { total, $updatedAt, $createdAt, prefs, ...rest } = team; + localConfig.addTeam(rest); + }); + + success(); +} + +const pullMessagingTopic = async () => { + const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics'); + + log(`Found ${topics.length} topics`); + + topics.forEach(topic => { + localConfig.addMessagingTopic(topic); + }); + + success(); +} + +const pull = new Command("pull") + .description(commandDescriptions['pull']) + .action(actionRunner(pullResources)); + +pull + .command("all") + .description("Pull all resource.") + .action(actionRunner(() => { + cliConfig.all = true; + return pullResources(); + })); + +pull + .command("project") + .description("Pull your Appwrite project name, services and auth settings") + .action(actionRunner(pullProject)); + +pull + .command("function") + .alias("functions") + .description("Pulling your Appwrite cloud function") + .action(actionRunner(pullFunctions)) + +pull + .command("collection") + .alias("collections") + .description("Pulling your Appwrite collections") + .action(actionRunner(pullCollection)) + +pull + .command("bucket") + .alias("buckets") + .description("Pulling your Appwrite buckets") + .action(actionRunner(pullBucket)) + +pull + .command("team") + .alias("teams") + .description("Pulling your Appwrite teams") + .action(actionRunner(pullTeam)) + +pull + .command("topic") + .alias("topics") + .description("Initialise your Appwrite messaging topics") + .action(actionRunner(pullMessagingTopic)) + +module.exports = { + pull, +}; diff --git a/lib/commands/push.js b/lib/commands/push.js new file mode 100644 index 0000000..1349b73 --- /dev/null +++ b/lib/commands/push.js @@ -0,0 +1,1518 @@ +const chalk = require('chalk'); +const inquirer = require("inquirer"); +const JSONbig = require("json-bigint")({ storeAsString: false }); +const { Command } = require("commander"); +const { localConfig, globalConfig } = require("../config"); +const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner'); +const { paginate } = require('../paginate'); +const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); +const { cliConfig, actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser"); +const { proxyListRules } = require('./proxy'); +const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); +const { + databasesGet, + databasesCreate, + databasesUpdate, + databasesCreateBooleanAttribute, + databasesGetCollection, + databasesCreateCollection, + databasesCreateStringAttribute, + databasesCreateIntegerAttribute, + databasesCreateFloatAttribute, + databasesCreateEmailAttribute, + databasesCreateDatetimeAttribute, + databasesCreateIndex, + databasesCreateUrlAttribute, + databasesCreateIpAttribute, + databasesCreateEnumAttribute, + databasesUpdateBooleanAttribute, + databasesUpdateStringAttribute, + databasesUpdateIntegerAttribute, + databasesUpdateFloatAttribute, + databasesUpdateEmailAttribute, + databasesUpdateDatetimeAttribute, + databasesUpdateUrlAttribute, + databasesUpdateIpAttribute, + databasesUpdateEnumAttribute, + databasesUpdateRelationshipAttribute, + databasesCreateRelationshipAttribute, + databasesDeleteAttribute, + databasesListAttributes, + databasesListIndexes, + databasesUpdateCollection +} = require("./databases"); +const { + storageGetBucket, storageUpdateBucket, storageCreateBucket +} = require("./storage"); +const { + messagingGetTopic, messagingUpdateTopic, messagingCreateTopic +} = require("./messaging"); +const { + teamsGet, + teamsUpdateName, + teamsCreate +} = require("./teams"); +const { + projectsUpdate, + projectsUpdateServiceStatus, + projectsUpdateAuthStatus, + projectsUpdateAuthDuration, + projectsUpdateAuthLimit, + projectsUpdateAuthSessionsLimit, + projectsUpdateAuthPasswordDictionary, + projectsUpdateAuthPasswordHistory, + projectsUpdatePersonalDataCheck, +} = require("./projects"); +const { checkDeployConditions } = require('../utils'); + +const STEP_SIZE = 100; // Resources +const POLL_DEBOUNCE = 2000; // Milliseconds +const POLL_MAX_DEBOUNCE = 30; // Times + +let pollMaxDebounces = 30; + +const changeableKeys = ['status', 'required', 'xdefault', 'elements', 'min', 'max', 'default', 'error']; + +const awaitPools = { + wipeAttributes: async (databaseId, collectionId, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + const { total } = await databasesListAttributes({ + databaseId, + collectionId, + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + + if (total === 0) { + return true; + } + + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.wipeAttributes( + databaseId, + collectionId, + iteration + 1 + ); + }, + wipeIndexes: async (databaseId, collectionId, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + const { total } = await databasesListIndexes({ + databaseId, + collectionId, + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + + if (total === 0) { + return true; + } + + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.wipeIndexes( + databaseId, + collectionId, + iteration + 1 + ); + }, + wipeVariables: async (functionId, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + const { total } = await functionsListVariables({ + functionId, + queries: ['limit(1)'], + parseOutput: false + }); + + if (total === 0) { + return true; + } + + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.wipeVariables( + functionId, + iteration + 1 + ); + }, + deleteAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + const { attributes } = await paginate(databasesListAttributes, { + databaseId, + collectionId, + parseOutput: false + }, 100, 'attributes'); + + const ready = attributeKeys.filter(attribute => attributes.includes(attribute.key)); + + if (ready.length === 0) { + return true; + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.expectAttributes( + databaseId, + collectionId, + attributeKeys, + iteration + 1 + ); + }, + expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + const { attributes } = await paginate(databasesListAttributes, { + databaseId, + collectionId, + parseOutput: false + }, 100, 'attributes'); + + const ready = attributes + .filter(attribute => { + if (attributeKeys.includes(attribute.key)) { + if (['stuck', 'failed'].includes(attribute.status)) { + throw new Error(`Attribute '${attribute.key}' failed!`); + } + + return attribute.status === 'available'; + } + + return false; + }) + .map(attribute => attribute.key); + + if (ready.length === attributeKeys.length) { + return true; + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.expectAttributes( + databaseId, + collectionId, + attributeKeys, + iteration + 1 + ); + }, + expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + + const { indexes } = await paginate(databasesListIndexes, { + databaseId, + collectionId, + parseOutput: false + }, 100, 'indexes'); + + const ready = indexes + .filter((index) => { + if (indexKeys.includes(index.key)) { + if (['stuck', 'failed'].includes(index.status)) { + throw new Error(`Index '${index.key}' failed!`); + } + + return index.status === 'available'; + } + + return false; + }) + .map(index => index.key); + + if (ready.length >= indexKeys.length) { + return true; + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.expectIndexes( + databaseId, + collectionId, + indexKeys, + iteration + 1 + ); + }, +} + +const createAttribute = async (databaseId, collectionId, attribute) => { + switch (attribute.type) { + case 'string': + switch (attribute.format) { + case 'email': + return await databasesCreateEmailAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'url': + return await databasesCreateUrlAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'ip': + return await databasesCreateIpAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'enum': + return await databasesCreateEnumAttribute({ + databaseId, + collectionId, + key: attribute.key, + elements: attribute.elements, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + default: + return await databasesCreateStringAttribute({ + databaseId, + collectionId, + key: attribute.key, + size: attribute.size, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + + } + case 'integer': + return await databasesCreateIntegerAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + min: parseInt(attribute.min.toString()), + max: parseInt(attribute.max.toString()), + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'double': + return databasesCreateFloatAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + min: parseFloat(attribute.min.toString()), + max: parseFloat(attribute.max.toString()), + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'boolean': + return databasesCreateBooleanAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'datetime': + return databasesCreateDatetimeAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'relationship': + return databasesCreateRelationshipAttribute({ + databaseId, + collectionId, + relatedCollectionId: attribute.relatedCollection, + type: attribute.relationType, + twoWay: attribute.twoWay, + key: attribute.key, + twoWayKey: attribute.twoWayKey, + onDelete: attribute.onDelete, + parseOutput: false + }) + } +} + +const updateAttribute = async (databaseId, collectionId, attribute) => { + switch (attribute.type) { + case 'string': + switch (attribute.format) { + case 'email': + return await databasesUpdateEmailAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'url': + return await databasesUpdateUrlAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'ip': + return await databasesUpdateIpAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'enum': + return await databasesUpdateEnumAttribute({ + databaseId, + collectionId, + key: attribute.key, + elements: attribute.elements, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + default: + return await databasesUpdateStringAttribute({ + databaseId, + collectionId, + key: attribute.key, + size: attribute.size, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + + } + case 'integer': + return await databasesUpdateIntegerAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + min: parseInt(attribute.min.toString()), + max: parseInt(attribute.max.toString()), + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'double': + return databasesUpdateFloatAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + min: parseFloat(attribute.min.toString()), + max: parseFloat(attribute.max.toString()), + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'boolean': + return databasesUpdateBooleanAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'datetime': + return databasesUpdateDatetimeAttribute({ + databaseId, + collectionId, + key: attribute.key, + required: attribute.required, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'relationship': + return databasesUpdateRelationshipAttribute({ + databaseId, + collectionId, + relatedCollectionId: attribute.relatedCollection, + type: attribute.relationType, + twoWay: attribute.twoWay, + key: attribute.key, + twoWayKey: attribute.twoWayKey, + onDelete: attribute.onDelete, + parseOutput: false + }) + } +} +const deleteAttribute = async (collection, attribute) => { + log(`Deleting attribute ${attribute.key} of ${collection.name} ( ${collection['$id']} )`); + + await databasesDeleteAttribute({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + key: attribute.key, + parseOutput: false + }); +} + + +/** + * Check if attribute non-changeable fields has been changed + * If so return the differences as an object. + * @param remote + * @param local + * @param collection + * @param recraeting when true will check only non-changeable keys + * @returns {undefined|{reason: string, action: *, attribute, key: string}} + */ +const checkAttributeChanges = (remote, local, collection, recraeting = true) => { + if (local === undefined) { + return undefined; + } + + const keyName = `${chalk.yellow(local.key)} in ${collection.name} (${collection['$id']})`; + const action = chalk.cyan(recraeting ? 'recreating' : 'changing'); + let reason = ''; + let attribute = remote; + + for (let key of Object.keys(remote)) { + if (changeableKeys.includes(key)) { + if (!recraeting) { + if (remote[key] !== local[key]) { + const bol = reason === '' ? '' : '\n'; + reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; + attribute = local; + } + } + continue; + } + + if (!recraeting) { + continue; + } + + if (remote[key] !== local[key]) { + const bol = reason === '' ? '' : '\n'; + reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; + } + } + + return reason === '' ? undefined : { key: keyName, attribute, reason, action }; +} + +/** + * Check if attributes contain the given attribute + * @param attribute + * @param attributes + * @returns {*} + */ +const attributesContains = (attribute, attributes) => attributes.find((attr) => attr.key === attribute.key); +const generateChangesObject = (attribute, collection, isAdding) => { + return { + key: `${chalk.yellow(attribute.key)} in ${collection.name} (${collection['$id']})`, + attribute: attribute, + reason: isAdding ? 'Field doesn\'t exist on the remote server' : 'Field doesn\'t exist in appwrite.json file', + action: isAdding ? chalk.green('adding') : chalk.red('deleting') + }; + +}; + +/** + * Filter deleted and recreated attributes, + * return list of attributes to create + * @param remoteAttributes + * @param localAttributes + * @param collection + * @returns {Promise<*|*[]>} + */ +const attributesToCreate = async (remoteAttributes, localAttributes, collection) => { + + const deleting = remoteAttributes.filter((attribute) => !attributesContains(attribute, localAttributes)).map((attr) => generateChangesObject(attr, collection, false)); + const adding = localAttributes.filter((attribute) => !attributesContains(attribute, remoteAttributes)).map((attr) => generateChangesObject(attr, collection, true)); + const conflicts = remoteAttributes.map((attribute) => checkAttributeChanges(attribute, attributesContains(attribute, localAttributes), collection)).filter(attribute => attribute !== undefined); + const changes = remoteAttributes.map((attribute) => checkAttributeChanges(attribute, attributesContains(attribute, localAttributes), collection, false)) + .filter(attribute => attribute !== undefined) + .filter(attribute => conflicts.filter(attr => attribute.key === attr.key).length !== 1); + + let changedAttributes = []; + const changing = [...deleting, ...adding, ...conflicts, ...changes] + if (changing.length === 0) { + return changedAttributes; + } + + log(!cliConfig.force ? 'There are pending changes in your collection deployment' : 'List of applied changes'); + + drawTable(changing.map((change) => { + return { Key: change.key, Action: change.action, Reason: change.reason, }; + })); + + if (!cliConfig.force) { + if (deleting.length > 0) { + log(`Attribute deletion will cause ${chalk.red('loss of data')}`); + } + if (conflicts.length > 0) { + log(`Attribute recreation will cause ${chalk.red('loss of data')}`); + } + + const answers = await inquirer.prompt(questionsPushCollections[1]); + + if (answers.changes.toLowerCase() !== 'yes') { + return changedAttributes; + } + } + + if (conflicts.length > 0) { + changedAttributes = conflicts.map((change) => change.attribute); + await Promise.all(changedAttributes.map((changed) => deleteAttribute(collection, changed))); + remoteAttributes = remoteAttributes.filter((attribute) => !attributesContains(attribute, changedAttributes)) + } + + if (changes.length > 0) { + changedAttributes = changes.map((change) => change.attribute); + await Promise.all(changedAttributes.map((changed) => updateAttribute(collection['databaseId'],collection['$id'], changed))); + } + + const deletingAttributes = deleting.map((change) => change.attribute); + await Promise.all(deletingAttributes.map((attribute) => deleteAttribute(collection, attribute))); + const attributeKeys = [...remoteAttributes.map(attribute => attribute.key), ...deletingAttributes.map(attribute => attribute.key)] + + if (attributeKeys.length) { + const deleteAttributesPoolStatus = await awaitPools.deleteAttributes(collection['databaseId'], collection['$id'], attributeKeys); + + if (!deleteAttributesPoolStatus) { + throw new Error("Attribute deletion timed out."); + } + } + + return localAttributes.filter((attribute) => !attributesContains(attribute, remoteAttributes)); +} +const createIndexes = async (indexes, collection) => { + log(`Creating indexes ...`) + + for (let index of indexes) { + await databasesCreateIndex({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + key: index.key, + type: index.type, + attributes: index.attributes, + orders: index.orders, + parseOutput: false + }); + } + + const result = await awaitPools.expectIndexes( + collection['databaseId'], + collection['$id'], + indexes.map(index => index.key) + ); + + if (!result) { + throw new Error("Index creation timed out."); + } + + success(`Created ${indexes.length} indexes`); +} +const createAttributes = async (attributes, collection) => { + for (let attribute of attributes) { + if (attribute.side !== 'child') { + await createAttribute(collection['databaseId'], collection['$id'], attribute); + } + } + + const result = await awaitPools.expectAttributes( + collection['databaseId'], + collection['$id'], + collection.attributes.map(attribute => attribute.key) + ); + + if (!result) { + throw new Error(`Attribute creation timed out.`); + } + + success(`Created ${attributes.length} attributes`); +} + +const pushResources = async () => { + const actions = { + project: pushProject, + functions: pushFunction, + collections: pushCollection, + buckets: pushBucket, + teams: pushTeam, + messages: pushMessagingTopic + } + + if (cliConfig.all) { + for (let action of Object.values(actions)) { + await action({ returnOnZero: true }); + } + } else { + const answers = await inquirer.prompt(questionsPushResources[0]); + + const action = actions[answers.resource]; + if (action !== undefined) { + await action({ returnOnZero: true }); + } + } +}; + +const pushProject = async () => { + try { + const projectId = localConfig.getProject().projectId; + const projectName = localConfig.getProject().projectName; + const settings = localConfig.getProject().projectSettings ?? {}; + + log(`Updating project ${projectId}`); + + if (projectName) { + await projectsUpdate({ + projectId, + name: projectName, + parseOutput: false + }); + } + + if (settings.services) { + log('Updating service statuses'); + for (let [service, status] of Object.entries(settings.services)) { + await projectsUpdateServiceStatus({ + projectId, + service, + status, + parseOutput: false + }); + } + } + + if (settings.auth) { + if (settings.auth.security) { + log('Updating auth security settings'); + await projectsUpdateAuthDuration({ projectId, duration: settings.auth.security.duration, parseOutput: false }); + await projectsUpdateAuthLimit({ projectId, limit: settings.auth.security.limit, parseOutput: false }); + await projectsUpdateAuthSessionsLimit({ projectId, limit: settings.auth.security.sessionsLimit, parseOutput: false }); + await projectsUpdateAuthPasswordDictionary({ projectId, enabled: settings.auth.security.passwordDictionary, parseOutput: false }); + await projectsUpdateAuthPasswordHistory({ projectId, limit: settings.auth.security.passwordHistory, parseOutput: false }); + await projectsUpdatePersonalDataCheck({ projectId, enabled: settings.auth.security.personalDataCheck, parseOutput: false }); + } + + if (settings.auth.methods) { + log('Updating auth login methods'); + + for (let [method, status] of Object.entries(settings.auth.methods)) { + await projectsUpdateAuthStatus({ + projectId, + method, + status, + parseOutput: false + }); + } + } + } + + success("Project configuration updated."); + } catch (e) { + throw e; + } +} + +const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + const functionIds = []; + + if (functionId) { + functionIds.push(functionId); + } else if (cliConfig.all) { + checkDeployConditions(localConfig); + const functions = localConfig.getFunctions(); + if (functions.length === 0) { + if (returnOnZero) { + log('No functions found, skipping'); + return; + } + throw new Error("No functions found in the current directory. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + } + functionIds.push(...functions.map((func) => { + return func.$id; + })); + } + + if (functionIds.length <= 0) { + const answers = await inquirer.prompt(questionsPushFunctions[0]); + functionIds.push(...answers.functions); + } + + let functions = functionIds.map((id) => { + const functions = localConfig.getFunctions(); + const func = functions.find((f) => f.$id === id); + + if (!func) { + throw new Error("Function '" + id + "' not found.") + } + + return func; + }); + + log('Validating functions'); + // Validation is done BEFORE pushing so the deployment process can be run in async with progress update + for (let func of functions) { + + if (!func.entrypoint) { + log(`Function ${func.name} does not have an endpoint`); + const answers = await inquirer.prompt(questionsGetEntrypoint) + func.entrypoint = answers.entrypoint; + localConfig.updateFunction(func['$id'], func); + } + + if (func.variables) { + func.pushVariables = cliConfig.force; + + try { + const { total } = await functionsListVariables({ + functionId: func['$id'], + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + + if (total === 0) { + func.pushVariables = true; + } else if (total > 0 && !func.pushVariables) { + log(`The function ${func.name} has remote variables setup`); + const variableAnswers = await inquirer.prompt(questionsPushFunctions[1]) + func.pushVariables = variableAnswers.override.toLowerCase() === "yes"; + } + } catch (e) { + if (e.code != 404) { + throw e.message; + } + } + } + } + + + log('All functions are validated'); + log('Pushing functions\n'); + + Spinner.start(false); + let successfullyPushed = 0; + let successfullyDeployed = 0; + const failedDeployments = []; + + await Promise.all(functions.map(async (func) => { + const ignore = func.ignore ? 'appwrite.json' : '.gitignore'; + let functionExists = false; + let deploymentCreated = false; + + const updaterRow = new Spinner({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` }); + + updaterRow.update({ status: 'Getting' }).startSpinner(SPINNER_DOTS); + + try { + response = await functionsGet({ + functionId: func['$id'], + parseOutput: false, + }); + functionExists = true; + if (response.runtime !== func.runtime) { + updaterRow.fail({ errorMessage: `Runtime mismatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json` }) + return; + } + + updaterRow.update({ status: 'Updating' }).replaceSpinner(SPINNER_ARC); + + response = await functionsUpdate({ + functionId: func['$id'], + name: func.name, + execute: func.execute, + events: func.events, + schedule: func.schedule, + timeout: func.timeout, + enabled: func.enabled, + logging: func.logging, + entrypoint: func.entrypoint, + commands: func.commands, + providerRepositoryId: func.providerRepositoryId ?? "", + installationId: func.installationId ?? '', + providerBranch: func.providerBranch ?? '', + providerRootDirectory: func.providerRootDirectory ?? '', + providerSilentMode: func.providerSilentMode ?? false, + vars: JSON.stringify(response.vars), + parseOutput: false + }); + } catch (e) { + + if (Number(e.code) === 404) { + functionExists = false; + } else { + updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' }); + return; + } + } + + if (!functionExists) { + updaterRow.update({ status: 'Creating' }).replaceSpinner(SPINNER_DOTS); + + try { + response = await functionsCreate({ + functionId: func.$id || 'unique()', + name: func.name, + runtime: func.runtime, + execute: func.execute, + events: func.events, + schedule: func.schedule, + timeout: func.timeout, + enabled: func.enabled, + logging: func.logging, + entrypoint: func.entrypoint, + commands: func.commands, + vars: JSON.stringify(func.vars), + parseOutput: false + }); + + localConfig.updateFunction(func['$id'], { + "$id": response['$id'], + }); + func["$id"] = response['$id']; + updaterRow.update({ status: 'Created' }); + } catch (e) { + updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' }); + return; + } + } + + if (func.variables) { + if (!func.pushVariables) { + updaterRow.update({ end: 'Skipping variables' }); + } else { + updaterRow.update({ end: 'Pushing variables' }); + + const { variables } = await paginate(functionsListVariables, { + functionId: func['$id'], + parseOutput: false + }, 100, 'variables'); + + await Promise.all(variables.map(async variable => { + await functionsDeleteVariable({ + functionId: func['$id'], + variableId: variable['$id'], + parseOutput: false + }); + })); + + let result = await awaitPools.wipeVariables(func['$id']); + if (!result) { + updaterRow.fail({ errorMessage: 'Variable deletion timed out' }) + return; + } + + // Push local variables + await Promise.all(Object.keys(func.variables).map(async localVariableKey => { + await functionsCreateVariable({ + functionId: func['$id'], + key: localVariableKey, + value: func.variables[localVariableKey], + parseOutput: false + }); + })); + } + } + + try { + updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC); + response = await functionsCreateDeployment({ + functionId: func['$id'], + entrypoint: func.entrypoint, + commands: func.commands, + code: func.path, + activate: true, + parseOutput: false + }) + + updaterRow.update({ status: 'Pushed' }); + deploymentCreated = true; + successfullyPushed++; + } catch (e) { + switch (e.code) { + case 'ENOENT': + updaterRow.fail({ errorMessage: 'Not found in the current directory. Skipping...' }) + break; + default: + updaterRow.fail({ errorMessage: e.message ?? 'An unknown error occurred. Please try again.' }) + } + } + + if (deploymentCreated && !async) { + try { + const deploymentId = response['$id']; + updaterRow.update({ status: 'Deploying', end: 'Checking deployment status...' }) + let pollChecks = 0; + + while (true) { + if (pollChecks >= POLL_MAX_DEBOUNCE) { + updaterRow.update({ end: 'Deployment is taking too long. Please check the console for more details.' }) + break; + } + + response = await functionsGetDeployment({ + functionId: func['$id'], + deploymentId: deploymentId, + parseOutput: false + }); + + + const status = response['status']; + if (status === 'ready') { + successfullyDeployed++; + + let url = ''; + const res = await proxyListRules({ + parseOutput: false, + queries: [ + JSON.stringify({ method: 'limit', values: [1] }), + JSON.stringify({ method: 'equal', "attribute": "resourceType", "values": ["function"] }), + JSON.stringify({ method: 'equal', "attribute": "resourceId", "values": [func['$id']] }) + ], + }); + + if (Number(res.total) === 1) { + url = res.rules[0].domain; + } + + updaterRow.update({ status: 'Deployed', end: url }); + + break; + } else if (status === 'failed') { + failedDeployments.push({ name: func['name'], $id: func['$id'], deployment: response['$id'] }); + updaterRow.fail({ errorMessage: `Failed to deploy` }); + + break; + } else { + updaterRow.update({ status: 'Deploying', end: `Current status: ${status}` }) + } + + pollChecks++; + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + } + } catch (e) { + updaterRow.fail({ errorMessage: e.message ?? 'Unknown error occurred. Please try again' }) + } + } + + updaterRow.stopSpinner(); + })); + + Spinner.stop(); + console.log('\n'); + + failedDeployments.forEach((failed) => { + const { name, deployment, $id } = failed; + const failUrl = `${globalConfig.getEndpoint().replace('/v1', '')}/console/project-${localConfig.getProject().projectId}/functions/function-${$id}/deployment-${deployment}`; + + error(`Deployment of ${name} has failed. Check at ${failUrl} for more details\n`); + }) + + let message = chalk.green(`Pushed and deployed ${successfullyPushed} functions`); + + if (!async) { + if (successfullyDeployed < successfullyPushed) { + message = `${chalk.green(`Pushed and deployed ${successfullyPushed} functions.`)} ${chalk.red(`${successfullyPushed - successfullyDeployed} failed to deploy`)}`; + } else { + if (successfullyPushed === 0) { + message = chalk.red(`Error pushing ${functions.length} functions`) + } + } + } + log(message); +} + +const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { + const collections = []; + + if (cliConfig.all) { + checkDeployConditions(localConfig); + if (localConfig.getCollections().length === 0) { + if (returnOnZero) { + log('No collections found, skipping'); + return; + } + + throw new Error("No collections found in the current directory. Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); + } + collections.push(...localConfig.getCollections()); + } else { + const answers = await inquirer.prompt(questionsPushCollections[0]) + const configCollections = new Map(); + localConfig.getCollections().forEach((c) => { + configCollections.set(`${c['databaseId']}|${c['$id']}`, c); + }); + answers.collections.forEach((a) => { + const collection = configCollections.get(a); + collections.push(collection); + }) + } + const databases = Array.from(new Set(collections.map(collection => collection['databaseId']))); + log('Checking for databases and collection changes'); + + // Parallel db actions + await Promise.all(databases.map(async (databaseId) => { + const localDatabase = localConfig.getDatabase(databaseId); + + try { + const database = await databasesGet({ + databaseId: databaseId, + parseOutput: false, + }); + + if (database.name !== (localDatabase.name ?? databaseId)) { + await databasesUpdate({ + databaseId: databaseId, + name: localDatabase.name ?? databaseId, + parseOutput: false + }) + + success(`Updated ${localDatabase.name} ( ${databaseId} ) name`); + } + } catch (err) { + log(`Database ${databaseId} not found. Creating it now...`); + + await databasesCreate({ + databaseId: databaseId, + name: localDatabase.name ?? databaseId, + parseOutput: false, + }); + } + })); + + // Parallel collection actions + await Promise.all(collections.map(async (collection) => { + try { + const remoteCollection = await databasesGetCollection({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + parseOutput: false, + }); + + if (remoteCollection.name !== collection.name) { + await databasesUpdateCollection({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + name: collection.name, + name: collection.name, + parseOutput: false + }) + + success(`Updated ${collection.name} ( ${collection['$id']} ) name`); + } + collection.remoteVersion = remoteCollection; + + collection.isExisted = true; + } catch + (e) { + if (Number(e.code) === 404) { + log(`Collection ${collection.name} does not exist in the project. Creating ... `); + await databasesCreateCollection({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + name: collection.name, + documentSecurity: collection.documentSecurity, + permissions: collection['$permissions'], + parseOutput: false + }) + } else { + throw e; + } + } + })) + + // Serialize attribute actions + for (let collection of collections) { + let attributes = collection.attributes; + + if (collection.isExisted) { + attributes = await attributesToCreate(collection.remoteVersion.attributes, collection.attributes, collection); + + if (Array.isArray(attributes) && attributes.length <= 0) { + continue; + } + } + + log(`Pushing collection ${collection.name} ( ${collection['databaseId']} - ${collection['$id']} ) attributes`) + + try { + await createAttributes(attributes, collection) + } catch (e) { + throw e; + } + + try { + await createIndexes(collection.indexes, collection); + } catch (e) { + throw e; + } + + success(`Pushed ${collection.name} ( ${collection['$id']} )`); + } +} + +const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let bucketIds = []; + const configBuckets = localConfig.getBuckets(); + + if (cliConfig.all) { + checkDeployConditions(localConfig); + if (configBuckets.length === 0) { + if (returnOnZero) { + log('No buckets found, skipping'); + return; + } + throw new Error("No buckets found in the current directory. Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); + } + bucketIds.push(...configBuckets.map((b) => b.$id)); + } + + if (bucketIds.length === 0) { + const answers = await inquirer.prompt(questionsPushBuckets[0]) + bucketIds.push(...answers.buckets); + } + + let buckets = []; + + for (const bucketId of bucketIds) { + const idBuckets = configBuckets.filter((b) => b.$id === bucketId); + buckets.push(...idBuckets); + } + + for (let bucket of buckets) { + log(`Pushing bucket ${bucket.name} ( ${bucket['$id']} )`) + + try { + response = await storageGetBucket({ + bucketId: bucket['$id'], + parseOutput: false, + }) + + log(`Updating bucket ...`) + + await storageUpdateBucket({ + bucketId: bucket['$id'], + name: bucket.name, + permissions: bucket['$permissions'], + fileSecurity: bucket.fileSecurity, + enabled: bucket.enabled, + maximumFileSize: bucket.maximumFileSize, + allowedFileExtensions: bucket.allowedFileExtensions, + encryption: bucket.encryption, + antivirus: bucket.antivirus, + compression: bucket.compression, + parseOutput: false + }); + + success(`Pushed ${bucket.name} ( ${bucket['$id']} )`); + } catch (e) { + if (Number(e.code) === 404) { + log(`Bucket ${bucket.name} does not exist in the project. Creating ... `); + + response = await storageCreateBucket({ + bucketId: bucket['$id'], + name: bucket.name, + permissions: bucket['$permissions'], + fileSecurity: bucket.fileSecurity, + enabled: bucket.enabled, + maximumFileSize: bucket.maximumFileSize, + allowedFileExtensions: bucket.allowedFileExtensions, + compression: bucket.compression, + encryption: bucket.encryption, + antivirus: bucket.antivirus, + parseOutput: false + }) + + success(`Pushed ${bucket.name} ( ${bucket['$id']} )`); + } else { + throw e; + } + } + } +} + +const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let teamIds = []; + const configTeams = localConfig.getTeams(); + + if (cliConfig.all) { + checkDeployConditions(localConfig); + if (configTeams.length === 0) { + if (returnOnZero) { + log('No teams found, skipping'); + return; + } + throw new Error("No teams found in the current directory. Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); + } + teamIds.push(...configTeams.map((t) => t.$id)); + } + + if (teamIds.length === 0) { + const answers = await inquirer.prompt(questionsPushTeams[0]) + teamIds.push(...answers.teams); + } + + let teams = []; + + for (const teamId of teamIds) { + const idTeams = configTeams.filter((t) => t.$id === teamId); + teams.push(...idTeams); + } + + for (let team of teams) { + log(`Pushing team ${team.name} ( ${team['$id']} )`) + + try { + response = await teamsGet({ + teamId: team['$id'], + parseOutput: false, + }) + + log(`Updating team ...`) + + await teamsUpdateName({ + teamId: team['$id'], + name: team.name, + parseOutput: false + }); + + success(`Pushed ${team.name} ( ${team['$id']} )`); + } catch (e) { + if (Number(e.code) === 404) { + log(`Team ${team.name} does not exist in the project. Creating ... `); + + response = await teamsCreate({ + teamId: team['$id'], + name: team.name, + parseOutput: false + }) + + success(`Pushed ${team.name} ( ${team['$id']} )`); + } else { + throw e; + } + } + } +} + +const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let topicsIds = []; + const configTopics = localConfig.getMessagingTopics(); + let overrideExisting = cliConfig.force; + + if (cliConfig.all) { + checkDeployConditions(localConfig); + if (configTopics.length === 0) { + if (returnOnZero) { + log('No topics found, skipping'); + return; + } + throw new Error("No topics found in the current directory. Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); + } + topicsIds.push(...configTopics.map((b) => b.$id)); + } + + if (topicsIds.length === 0) { + const answers = await inquirer.prompt(questionsPushMessagingTopics[0]) + topicsIds.push(...answers.topics); + } + + let topics = []; + + for (const topicId of topicsIds) { + const idTopic = configTopics.filter((b) => b.$id === topicId); + topics.push(...idTopic); + } + + if (!cliConfig.force) { + const answers = await inquirer.prompt(questionsPushMessagingTopics[1]) + if (answers.override.toLowerCase() === "yes") { + overrideExisting = true; + } + } + + for (let topic of topics) { + log(`Pushing topic ${topic.name} ( ${topic['$id']} )`) + + try { + response = await messagingGetTopic({ + topicId: topic['$id'], + parseOutput: false + }) + log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`); + + if (!overrideExisting) { + log(`Skipping ${topic.name} ( ${topic['$id']} )`); + continue; + } + + log(`Updating Topic ...`) + + await messagingUpdateTopic({ + topicId: topic['$id'], + name: topic.name, + subscribe: topic.subscribe, + parseOutput: false + }); + + success(`Pushed ${topic.name} ( ${topic['$id']} )`); + } catch (e) { + if (Number(e.code) === 404) { + log(`Topic ${topic.name} does not exist in the project. Creating ... `); + + response = await messagingCreateTopic({ + topicId: topic['$id'], + name: topic.name, + subscribe: topic.subscribe, + parseOutput: false + }) + + success(`Created ${topic.name} ( ${topic['$id']} )`); + } else { + throw e; + } + } + } +} + +const push = new Command("push") + .description(commandDescriptions['push']) + .action(actionRunner(pushResources)); + +push + .command("all") + .description("Push all resource.") + .action(actionRunner(() => { + cliConfig.all = true; + return pushResources(); + })); + +push + .command("project") + .description("Push project name, services and auth settings") + .action(actionRunner(pushProject)); + +push + .command("function") + .alias("functions") + .description("Push functions in the current directory.") + .option(`-f, --functionId `, `Function ID`) + .option(`-A, --async`, `Don't wait for functions deployments status`) + .action(actionRunner(pushFunction)); + +push + .command("collection") + .alias("collections") + .description("Push collections in the current project.") + .action(actionRunner(pushCollection)); + +push + .command("bucket") + .alias("buckets") + .description("Push buckets in the current project.") + .action(actionRunner(pushBucket)); + +push + .command("team") + .alias("teams") + .description("Push teams in the current project.") + .action(actionRunner(pushTeam)); + +push + .command("topic") + .alias("topics") + .description("Push messaging topics in the current project.") + .action(actionRunner(pushMessagingTopic)); + +module.exports = { + push +} diff --git a/lib/commands/run.js b/lib/commands/run.js new file mode 100644 index 0000000..5d05e21 --- /dev/null +++ b/lib/commands/run.js @@ -0,0 +1,282 @@ +const Tail = require('tail').Tail; +const EventEmitter = require('node:events'); +const ignore = require("ignore"); +const tar = require("tar"); +const fs = require("fs"); +const ID = require("../id"); +const childProcess = require('child_process'); +const chokidar = require('chokidar'); +const inquirer = require("inquirer"); +const path = require("path"); +const { Command } = require("commander"); +const { localConfig, globalConfig } = require("../config"); +const { paginate } = require('../paginate'); +const { functionsListVariables } = require('./functions'); +const { usersGet, usersCreateJWT } = require('./users'); +const { projectsCreateJWT } = require('./projects'); +const { questionsRunFunctions } = require("../questions"); +const { actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser"); +const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils'); +const { openRuntimesVersion, runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils'); +const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull, dockerStopActive } = require('../emulation/docker'); + +const runFunction = async ({ port, functionId, noVariables, noReload, userId } = {}) => { + // Selection + if(!functionId) { + const answers = await inquirer.prompt(questionsRunFunctions[0]); + functionId = answers.function; + } + + const functions = localConfig.getFunctions(); + const func = functions.find((f) => f.$id === functionId); + if (!func) { + throw new Error("Function '" + functionId + "' not found.") + } + + const runtimeName = func.runtime.split("-").slice(0, -1).join("-"); + const tool = systemTools[runtimeName]; + + // Configuration: Port + if(port) { + port = +port; + } + + if(isNaN(port)) { + port = null; + } + + if(port) { + const taken = await isPortTaken(port); + + if(taken) { + error(`Port ${port} is already in use by another process.`); + return; + } + } + + if(!port) { + let portFound = false; + port = 3000; + while(port < 3100) { + const taken = await isPortTaken(port); + if(!taken) { + portFound = true; + break; + } + + port++; + } + + if(!portFound) { + error('Could not find an available port. Please select a port with `appwrite run --port YOUR_PORT` command.'); + return; + } + } + + // Configuration: Engine + if(!systemHasCommand('docker')) { + return error("Docker Engine is required for local development. Please install Docker using: https://docs.docker.com/engine/install/"); + } + + // Settings + const settings = { + runtime: func.runtime, + entrypoint: func.entrypoint, + path: func.path, + commands: func.commands, + }; + + log("Local function configuration:"); + drawTable([settings]); + log('If you wish to change your local settings, update the appwrite.json file and rerun the `appwrite run` command.'); + + await dockerCleanup(); + + process.on('SIGINT', async () => { + log('Cleaning up ...'); + await dockerCleanup(); + success(); + process.exit(); + }); + + const logsPath = path.join(process.cwd(), func.path, '.appwrite/logs.txt'); + const errorsPath = path.join(process.cwd(), func.path, '.appwrite/errors.txt'); + + if(!fs.existsSync(path.dirname(logsPath))) { + fs.mkdirSync(path.dirname(logsPath), { recursive: true }); + } + + if (!fs.existsSync(logsPath)) { + fs.writeFileSync(logsPath, ''); + } + + if (!fs.existsSync(errorsPath)) { + fs.writeFileSync(errorsPath, ''); + } + + const variables = {}; + if(!noVariables) { + if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { + error("No user is signed in. To sign in, run: appwrite login. Function will run locally, but will not have your function's environment variables set."); + } else { + try { + const { variables: remoteVariables } = await paginate(functionsListVariables, { + functionId: func['$id'], + parseOutput: false + }, 100, 'variables'); + + remoteVariables.forEach((v) => { + variables[v.key] = v.value; + }); + } catch(err) { + log("Could not fetch remote variables: " + err.message); + log("Function will run locally, but will not have your function's environment variables set."); + } + } + } + + variables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint'); + variables['APPWRITE_FUNCTION_ID'] = func.$id; + variables['APPWRITE_FUNCTION_NAME'] = func.name; + variables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant + variables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId; + variables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? ''; + variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime; + + await JwtManager.setup(userId); + + const headers = {}; + headers['x-appwrite-key'] = JwtManager.functionJwt ?? ''; + headers['x-appwrite-trigger'] = 'http'; + headers['x-appwrite-event'] = ''; + headers['x-appwrite-user-id'] = userId ?? ''; + headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? ''; + variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers); + + await dockerPull(func); + await dockerBuild(func, variables); + await dockerStart(func, variables, port); + + new Tail(logsPath).on("line", function(data) { + console.log(data); + }); + new Tail(errorsPath).on("line", function(data) { + console.log(data); + }); + + if(!noReload) { + chokidar.watch('.', { + cwd: path.join(process.cwd(), func.path), + ignoreInitial: true, + ignored: [ ...(func.ignore ?? []), 'code.tar.gz', '.appwrite', '.appwrite/', '.appwrite/*', '.appwrite/**', '.appwrite/*.*', '.appwrite/**/*.*' ] + }).on('all', async (_event, filePath) => { + Queue.push(filePath); + }); + } + + Queue.events.on('reload', async ({ files }) => { + Queue.lock(); + + log('Live-reloading due to file changes: '); + for(const file of files) { + log(`- ${file}`); + } + + try { + log('Stopping the function ...'); + + await dockerStopActive(); + + const dependencyFile = files.find((filePath) => tool.dependencyFiles.includes(filePath)); + if(tool.isCompiled || dependencyFile) { + log(`Rebuilding the function due to cange in ${dependencyFile} ...`); + await dockerBuild(func, variables); + await dockerStart(func, variables, port); + } else { + log('Hot-swapping function files ...'); + + const functionPath = path.join(process.cwd(), func.path); + const hotSwapPath = path.join(functionPath, '.appwrite/hot-swap'); + const buildPath = path.join(functionPath, '.appwrite/build.tar.gz'); + + // Prepare temp folder + if (!fs.existsSync(hotSwapPath)) { + fs.mkdirSync(hotSwapPath, { recursive: true }); + } else { + fs.rmSync(hotSwapPath, { recursive: true, force: true }); + fs.mkdirSync(hotSwapPath, { recursive: true }); + } + + await tar + .extract({ + gzip: true, + sync: true, + cwd: hotSwapPath, + file: buildPath + }); + + const ignorer = ignore(); + ignorer.add('.appwrite'); + if (func.ignore) { + ignorer.add(func.ignore); + } + + const filesToCopy = getAllFiles(functionPath).map((file) => path.relative(functionPath, file)).filter((file) => !ignorer.ignores(file)); + for(const f of filesToCopy) { + const filePath = path.join(hotSwapPath, f); + if (fs.existsSync(filePath)) { + fs.rmSync(filePath, { force: true }); + } + + const fileDir = path.dirname(filePath); + if (!fs.existsSync(fileDir)) { + fs.mkdirSync(fileDir, { recursive: true }); + } + + const sourcePath = path.join(functionPath, f); + fs.copyFileSync(sourcePath, filePath); + } + + await tar + .create({ + gzip: true, + sync: true, + cwd: hotSwapPath, + file: buildPath + }, ['.']); + + fs.rmSync(hotSwapPath, { recursive: true, force: true }); + + await dockerStart(func, variables, port); + } + } catch(err) { + console.error(err); + } finally { + Queue.unlock(); + } + }); +} + +const run = new Command("run") + .description(commandDescriptions['run']) + .configureHelp({ + helpWidth: process.stdout.columns || 80 + }) + .action(actionRunner(async (_options, command) => { + command.help(); + })); + +run + .command("function") + .alias("functions") + .description("Run functions in the current directory.") + .option(`--functionId `, `Function ID`) + .option(`--port `, `Local port`) + .option(`--userId `, `ID of user to impersonate`) + .option(`--noVariables`, `Prevent pulling variables from function settings`) + .option(`--noReload`, `Prevent live reloading of server when changes are made to function files`) + .action(actionRunner(runFunction)); + +module.exports = { + run +} diff --git a/lib/commands/storage.js b/lib/commands/storage.js index 2358c98..4dca398 100644 --- a/lib/commands/storage.js +++ b/lib/commands/storage.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const storage = new Command("storage").description(commandDescriptions['storage' * @typedef {Object} StorageListBucketsRequestParams * @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: enabled, name, fileSecurity, maximumFileSize, encryption, antivirus * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const storage = new Command("storage").description(commandDescriptions['storage' /** * @param {StorageListBucketsRequestParams} params */ -const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageListBuckets = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'listBuckets'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -87,6 +94,7 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u * @property {Compression} compression Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled * @property {boolean} encryption Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled * @property {boolean} antivirus Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -94,8 +102,9 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u /** * @param {StorageCreateBucketRequestParams} params */ -const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageCreateBucket = async ({bucketId,name,permissions,fileSecurity,enabled,maximumFileSize,allowedFileExtensions,compression,encryption,antivirus,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets'; let payload = {}; if (typeof bucketId !== 'undefined') { @@ -141,13 +150,15 @@ const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity, parse(response) success() } - + return response; + } /** * @typedef {Object} StorageGetBucketRequestParams * @property {string} bucketId Bucket unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -155,8 +166,9 @@ const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity, /** * @param {StorageGetBucketRequestParams} params */ -const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetBucket = async ({bucketId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); let payload = {}; @@ -167,11 +179,16 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'getBucket', bucketId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -186,6 +203,7 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined} * @property {Compression} compression Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled * @property {boolean} encryption Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled * @property {boolean} antivirus Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -193,8 +211,9 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined} /** * @param {StorageUpdateBucketRequestParams} params */ -const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageUpdateBucket = async ({bucketId,name,permissions,fileSecurity,enabled,maximumFileSize,allowedFileExtensions,compression,encryption,antivirus,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); let payload = {}; if (typeof name !== 'undefined') { @@ -237,13 +256,15 @@ const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity, parse(response) success() } - + return response; + } /** * @typedef {Object} StorageDeleteBucketRequestParams * @property {string} bucketId Bucket unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -251,8 +272,9 @@ const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity, /** * @param {StorageDeleteBucketRequestParams} params */ -const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageDeleteBucket = async ({bucketId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); let payload = {}; @@ -266,8 +288,9 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** @@ -275,6 +298,7 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @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, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -282,8 +306,9 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin /** * @param {StorageListFilesRequestParams} params */ -const storageListFiles = async ({ bucketId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageListFiles = async ({bucketId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); let payload = {}; if (typeof queries !== 'undefined') { @@ -300,19 +325,25 @@ const storageListFiles = async ({ bucketId, queries, search, parseOutput = true, }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'listFiles', bucketId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} StorageCreateFileRequestParams * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @property {string} fileId File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. - * @property {string} file Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/storage#file-input). + * @property {string} file Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/products/storage/upload-download#input-file). * @property {string[]} permissions An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {CallableFunction} onProgress @@ -321,8 +352,9 @@ const storageListFiles = async ({ bucketId, queries, search, parseOutput = true, /** * @param {StorageCreateFileRequestParams} params */ -const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOutput = true, sdk = undefined, onProgress = () => {}}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageCreateFile = async ({bucketId,fileId,file,permissions,parseOutput = true, overrideForCli = false, sdk = undefined,onProgress = () => {}}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); let payload = {}; if (typeof fileId !== 'undefined') { @@ -342,7 +374,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut } const size = file.size; - + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -377,7 +409,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut } let uploadableChunkTrimmed; - + if(currentPosition + 1 >= client.CHUNK_SIZE) { uploadableChunkTrimmed = uploadableChunk; } else { @@ -430,7 +462,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut await uploadChunk(true); } - + if (parseOutput) { parse(response) success() @@ -443,6 +475,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut * @typedef {Object} StorageGetFileRequestParams * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @property {string} fileId File ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -450,8 +483,9 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut /** * @param {StorageGetFileRequestParams} params */ -const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetFile = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; @@ -462,11 +496,16 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'getFile', bucketId, fileId); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -475,6 +514,7 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde * @property {string} fileId File unique ID. * @property {string} name Name of the file * @property {string[]} permissions An array of permission string. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -482,8 +522,9 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde /** * @param {StorageUpdateFileRequestParams} params */ -const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageUpdateFile = async ({bucketId,fileId,name,permissions,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; if (typeof name !== 'undefined') { @@ -504,14 +545,16 @@ const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOut parse(response) success() } - + return response; + } /** * @typedef {Object} StorageDeleteFileRequestParams * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @property {string} fileId File ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -519,8 +562,9 @@ const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOut /** * @param {StorageDeleteFileRequestParams} params */ -const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageDeleteFile = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; @@ -534,14 +578,16 @@ const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} StorageGetFileDownloadRequestParams * @property {string} bucketId Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @property {string} fileId File ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -550,14 +596,17 @@ const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = u /** * @param {StorageGetFileDownloadRequestParams} params */ -const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetFileDownload = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -565,14 +614,18 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** @@ -590,6 +643,7 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd * @property {number} rotation Preview image rotation in degrees. Pass an integer between -360 and 360. * @property {string} background Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix. * @property {ImageFormat} output Output format type (jpeg, jpg, png, gif and webp). + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -598,8 +652,9 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd /** * @param {StorageGetFilePreviewRequestParams} params */ -const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetFilePreview = async ({bucketId,fileId,width,height,gravity,quality,borderWidth,borderColor,borderRadius,opacity,rotation,background,output,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; if (typeof width !== 'undefined') { @@ -635,10 +690,12 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity, if (typeof output !== 'undefined') { payload['output'] = output; } - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -646,20 +703,25 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity, 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** * @typedef {Object} StorageGetFileViewRequestParams * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @property {string} fileId File ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination @@ -668,14 +730,17 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity, /** * @param {StorageGetFileViewRequestParams} params */ -const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetFileView = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); let payload = {}; - payload['project'] = localConfig.getProject().projectId - payload['key'] = globalConfig.getKey(); - const queryParams = new URLSearchParams(payload); - apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + if (!overrideForCli) { + payload['project'] = localConfig.getProject().projectId + payload['key'] = globalConfig.getKey(); + const queryParams = new URLSearchParams(payload); + apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`; + } let response = undefined; @@ -683,19 +748,24 @@ const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk = 'content-type': 'application/json', }, payload, 'arraybuffer'); - fs.writeFileSync(destination, response); + if (overrideForCli) { + response = Buffer.from(response); + } + fs.writeFileSync(destination, response); if (parseOutput) { parse(response) success() } - + return response; + } /** * @typedef {Object} StorageGetUsageRequestParams * @property {StorageUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -703,8 +773,9 @@ const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk = /** * @param {StorageGetUsageRequestParams} params */ -const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetUsage = async ({range,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/usage'; let payload = {}; if (typeof range !== 'undefined') { @@ -721,14 +792,16 @@ const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} StorageGetBucketUsageRequestParams * @property {string} bucketId Bucket ID. * @property {StorageUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -736,8 +809,9 @@ const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => /** * @param {StorageGetBucketUsageRequestParams} params */ -const storageGetBucketUsage = async ({ bucketId, range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const storageGetBucketUsage = async ({bucketId,range,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/storage/{bucketId}/usage'.replace('{bucketId}', bucketId); let payload = {}; if (typeof range !== 'undefined') { @@ -751,11 +825,16 @@ const storageGetBucketUsage = async ({ bucketId, range, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'getBucketUsage', bucketId); + } else { + parse(response) + success() + } } - + return response; + } storage @@ -763,6 +842,7 @@ storage .description(`Get a list of all the storage buckets. You can use the query params to filter your results.`) .option(`--queries [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: enabled, name, fileSecurity, maximumFileSize, encryption, antivirus`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(storageListBuckets)) storage @@ -784,6 +864,7 @@ storage .command(`getBucket`) .description(`Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.`) .requiredOption(`--bucketId `, `Bucket unique ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetBucket)) storage @@ -813,6 +894,7 @@ storage .requiredOption(`--bucketId `, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) .option(`--queries [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, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(storageListFiles)) storage @@ -820,7 +902,7 @@ storage .description(`Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console. Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of '5MB'. The 'content-range' header values should always be in bytes. When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in 'x-appwrite-id' header to allow the server to know that the partial upload is for the existing file and not for a new one. If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally. `) .requiredOption(`--bucketId `, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) .requiredOption(`--fileId `, `File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) - .requiredOption(`--file `, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/storage#file-input).`) + .requiredOption(`--file `, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/products/storage/upload-download#input-file).`) .option(`--permissions [permissions...]`, `An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`) .action(actionRunner(storageCreateFile)) @@ -829,6 +911,7 @@ storage .description(`Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.`) .requiredOption(`--bucketId `, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) .requiredOption(`--fileId `, `File ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetFile)) storage @@ -893,6 +976,7 @@ storage .description(``) .requiredOption(`--bucketId `, `Bucket ID.`) .option(`--range `, `Date range.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetBucketUsage)) module.exports = { @@ -912,4 +996,4 @@ module.exports = { storageGetFileView, storageGetUsage, storageGetBucketUsage -}; \ No newline at end of file +}; diff --git a/lib/commands/teams.js b/lib/commands/teams.js index 37261de..39f1848 100644 --- a/lib/commands/teams.js +++ b/lib/commands/teams.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const teams = new Command("teams").description(commandDescriptions['teams']).con * @typedef {Object} TeamsListRequestParams * @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} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const teams = new Command("teams").description(commandDescriptions['teams']).con /** * @param {TeamsListRequestParams} params */ -const teamsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const teamsList = async ({ queries, search, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('teams', 'list'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -80,6 +87,7 @@ const teamsList = async ({ queries, search, parseOutput = true, sdk = undefined} * @property {string} teamId Team ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @property {string} name Team name. Max length: 128 chars. * @property {string[]} roles Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -87,8 +95,9 @@ const teamsList = async ({ queries, search, parseOutput = true, sdk = undefined} /** * @param {TeamsCreateRequestParams} params */ -const teamsCreate = async ({ teamId, name, roles, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsCreate = async ({teamId,name,roles,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams'; let payload = {}; if (typeof teamId !== 'undefined') { @@ -112,13 +121,15 @@ const teamsCreate = async ({ teamId, name, roles, parseOutput = true, sdk = unde parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsGetRequestParams * @property {string} teamId Team ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -126,8 +137,9 @@ const teamsCreate = async ({ teamId, name, roles, parseOutput = true, sdk = unde /** * @param {TeamsGetRequestParams} params */ -const teamsGet = async ({ teamId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsGet = async ({teamId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); let payload = {}; @@ -138,17 +150,23 @@ const teamsGet = async ({ teamId, parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('teams', 'get', teamId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} TeamsUpdateNameRequestParams * @property {string} teamId Team ID. * @property {string} name New team name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -156,8 +174,9 @@ const teamsGet = async ({ teamId, parseOutput = true, sdk = undefined}) => { /** * @param {TeamsUpdateNameRequestParams} params */ -const teamsUpdateName = async ({ teamId, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsUpdateName = async ({teamId,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); let payload = {}; if (typeof name !== 'undefined') { @@ -174,13 +193,15 @@ const teamsUpdateName = async ({ teamId, name, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsDeleteRequestParams * @property {string} teamId Team ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -188,8 +209,9 @@ const teamsUpdateName = async ({ teamId, name, parseOutput = true, sdk = undefin /** * @param {TeamsDeleteRequestParams} params */ -const teamsDelete = async ({ teamId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsDelete = async ({teamId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); let payload = {}; @@ -203,14 +225,16 @@ const teamsDelete = async ({ teamId, parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsListLogsRequestParams * @property {string} teamId Team ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -218,8 +242,9 @@ const teamsDelete = async ({ teamId, parseOutput = true, sdk = undefined}) => { /** * @param {TeamsListLogsRequestParams} params */ -const teamsListLogs = async ({ teamId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsListLogs = async ({teamId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/logs'.replace('{teamId}', teamId); let payload = {}; if (typeof queries !== 'undefined') { @@ -236,8 +261,9 @@ const teamsListLogs = async ({ teamId, queries, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** @@ -245,6 +271,7 @@ const teamsListLogs = async ({ teamId, queries, parseOutput = true, sdk = undefi * @property {string} teamId Team ID. * @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: userId, teamId, invited, joined, confirm * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -252,8 +279,9 @@ const teamsListLogs = async ({ teamId, queries, parseOutput = true, sdk = undefi /** * @param {TeamsListMembershipsRequestParams} params */ -const teamsListMemberships = async ({ teamId, queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsListMemberships = async ({teamId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); let payload = {}; if (typeof queries !== 'undefined') { @@ -273,8 +301,9 @@ const teamsListMemberships = async ({ teamId, queries, search, parseOutput = tru parse(response) success() } - + return response; + } /** @@ -284,8 +313,9 @@ const teamsListMemberships = async ({ teamId, queries, search, parseOutput = tru * @property {string} email Email of the new team member. * @property {string} userId ID of the user to be added to a team. * @property {string} phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. - * @property {string} url URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. + * @property {string} url URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @property {string} name Name of the new team member. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -293,8 +323,9 @@ const teamsListMemberships = async ({ teamId, queries, search, parseOutput = tru /** * @param {TeamsCreateMembershipRequestParams} params */ -const teamsCreateMembership = async ({ teamId, roles, email, userId, phone, url, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsCreateMembership = async ({teamId,roles,email,userId,phone,url,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); let payload = {}; if (typeof email !== 'undefined') { @@ -327,14 +358,16 @@ const teamsCreateMembership = async ({ teamId, roles, email, userId, phone, url, parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsGetMembershipRequestParams * @property {string} teamId Team ID. * @property {string} membershipId Membership ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -342,8 +375,9 @@ const teamsCreateMembership = async ({ teamId, roles, email, userId, phone, url, /** * @param {TeamsGetMembershipRequestParams} params */ -const teamsGetMembership = async ({ teamId, membershipId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsGetMembership = async ({teamId,membershipId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); let payload = {}; @@ -357,8 +391,9 @@ const teamsGetMembership = async ({ teamId, membershipId, parseOutput = true, sd parse(response) success() } - + return response; + } /** @@ -366,6 +401,7 @@ const teamsGetMembership = async ({ teamId, membershipId, parseOutput = true, sd * @property {string} teamId Team ID. * @property {string} membershipId Membership ID. * @property {string[]} roles An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -373,8 +409,9 @@ const teamsGetMembership = async ({ teamId, membershipId, parseOutput = true, sd /** * @param {TeamsUpdateMembershipRequestParams} params */ -const teamsUpdateMembership = async ({ teamId, membershipId, roles, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsUpdateMembership = async ({teamId,membershipId,roles,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); let payload = {}; roles = roles === true ? [] : roles; @@ -392,14 +429,16 @@ const teamsUpdateMembership = async ({ teamId, membershipId, roles, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsDeleteMembershipRequestParams * @property {string} teamId Team ID. * @property {string} membershipId Membership ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -407,8 +446,9 @@ const teamsUpdateMembership = async ({ teamId, membershipId, roles, parseOutput /** * @param {TeamsDeleteMembershipRequestParams} params */ -const teamsDeleteMembership = async ({ teamId, membershipId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsDeleteMembership = async ({teamId,membershipId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); let payload = {}; @@ -422,8 +462,9 @@ const teamsDeleteMembership = async ({ teamId, membershipId, parseOutput = true, parse(response) success() } - + return response; + } /** @@ -432,6 +473,7 @@ const teamsDeleteMembership = async ({ teamId, membershipId, parseOutput = true, * @property {string} membershipId Membership ID. * @property {string} userId User ID. * @property {string} secret Secret key. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -439,8 +481,9 @@ const teamsDeleteMembership = async ({ teamId, membershipId, parseOutput = true, /** * @param {TeamsUpdateMembershipStatusRequestParams} params */ -const teamsUpdateMembershipStatus = async ({ teamId, membershipId, userId, secret, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsUpdateMembershipStatus = async ({teamId,membershipId,userId,secret,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); let payload = {}; if (typeof userId !== 'undefined') { @@ -460,13 +503,15 @@ const teamsUpdateMembershipStatus = async ({ teamId, membershipId, userId, secre parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsGetPrefsRequestParams * @property {string} teamId Team ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -474,8 +519,9 @@ const teamsUpdateMembershipStatus = async ({ teamId, membershipId, userId, secre /** * @param {TeamsGetPrefsRequestParams} params */ -const teamsGetPrefs = async ({ teamId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsGetPrefs = async ({teamId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); let payload = {}; @@ -489,14 +535,16 @@ const teamsGetPrefs = async ({ teamId, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} TeamsUpdatePrefsRequestParams * @property {string} teamId Team ID. * @property {object} prefs Prefs key-value JSON object. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -504,8 +552,9 @@ const teamsGetPrefs = async ({ teamId, parseOutput = true, sdk = undefined}) => /** * @param {TeamsUpdatePrefsRequestParams} params */ -const teamsUpdatePrefs = async ({ teamId, prefs, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const teamsUpdatePrefs = async ({teamId,prefs,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); let payload = {}; if (typeof prefs !== 'undefined') { @@ -522,8 +571,9 @@ const teamsUpdatePrefs = async ({ teamId, prefs, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } teams @@ -531,6 +581,7 @@ teams .description(`Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results.`) .option(`--queries [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`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(teamsList)) teams @@ -545,6 +596,7 @@ teams .command(`get`) .description(`Get a team by its ID. All team members have read access for this resource.`) .requiredOption(`--teamId `, `Team ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(teamsGet)) teams @@ -583,7 +635,7 @@ teams .option(`--email `, `Email of the new team member.`) .option(`--userId `, `ID of the user to be added to a team.`) .option(`--phone `, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) - .option(`--url `, `URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) + .option(`--url `, `URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) .option(`--name `, `Name of the new team member. Max length: 128 chars.`) .action(actionRunner(teamsCreateMembership)) @@ -647,4 +699,4 @@ module.exports = { teamsUpdateMembershipStatus, teamsGetPrefs, teamsUpdatePrefs -}; \ No newline at end of file +}; diff --git a/lib/commands/users.js b/lib/commands/users.js index d412d27..42f4ea3 100644 --- a/lib/commands/users.js +++ b/lib/commands/users.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const users = new Command("users").description(commandDescriptions['users']).con * @typedef {Object} UsersListRequestParams * @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, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const users = new Command("users").description(commandDescriptions['users']).con /** * @param {UsersListRequestParams} params */ -const usersList = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersList = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users'; let payload = {}; if (typeof queries !== 'undefined') { @@ -68,11 +70,16 @@ const usersList = async ({ queries, search, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'list'); + } else { + parse(response) + success() + } } - + return response; + } /** @@ -82,6 +89,7 @@ const usersList = async ({ queries, search, parseOutput = true, sdk = undefined} * @property {string} phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. * @property {string} password Plain text user password. Must be at least 8 chars. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -89,8 +97,9 @@ const usersList = async ({ queries, search, parseOutput = true, sdk = undefined} /** * @param {UsersCreateRequestParams} params */ -const usersCreate = async ({ userId, email, phone, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreate = async ({userId,email,phone,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users'; let payload = {}; if (typeof userId !== 'undefined') { @@ -119,8 +128,9 @@ const usersCreate = async ({ userId, email, phone, password, name, parseOutput = parse(response) success() } - + return response; + } /** @@ -129,6 +139,7 @@ const usersCreate = async ({ userId, email, phone, password, name, parseOutput = * @property {string} email User email. * @property {string} password User password hashed using Argon2. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -136,8 +147,9 @@ const usersCreate = async ({ userId, email, phone, password, name, parseOutput = /** * @param {UsersCreateArgon2UserRequestParams} params */ -const usersCreateArgon2User = async ({ userId, email, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateArgon2User = async ({userId,email,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/argon2'; let payload = {}; if (typeof userId !== 'undefined') { @@ -163,8 +175,9 @@ const usersCreateArgon2User = async ({ userId, email, password, name, parseOutpu parse(response) success() } - + return response; + } /** @@ -173,6 +186,7 @@ const usersCreateArgon2User = async ({ userId, email, password, name, parseOutpu * @property {string} email User email. * @property {string} password User password hashed using Bcrypt. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -180,8 +194,9 @@ const usersCreateArgon2User = async ({ userId, email, password, name, parseOutpu /** * @param {UsersCreateBcryptUserRequestParams} params */ -const usersCreateBcryptUser = async ({ userId, email, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateBcryptUser = async ({userId,email,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/bcrypt'; let payload = {}; if (typeof userId !== 'undefined') { @@ -207,14 +222,16 @@ const usersCreateBcryptUser = async ({ userId, email, password, name, parseOutpu parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListIdentitiesRequestParams * @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: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -222,8 +239,9 @@ const usersCreateBcryptUser = async ({ userId, email, password, name, parseOutpu /** * @param {UsersListIdentitiesRequestParams} params */ -const usersListIdentities = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListIdentities = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/identities'; let payload = {}; if (typeof queries !== 'undefined') { @@ -243,13 +261,15 @@ const usersListIdentities = async ({ queries, search, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} UsersDeleteIdentityRequestParams * @property {string} identityId Identity ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -257,8 +277,9 @@ const usersListIdentities = async ({ queries, search, parseOutput = true, sdk = /** * @param {UsersDeleteIdentityRequestParams} params */ -const usersDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDeleteIdentity = async ({identityId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/identities/{identityId}'.replace('{identityId}', identityId); let payload = {}; @@ -272,8 +293,9 @@ const usersDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** @@ -282,6 +304,7 @@ const usersDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undef * @property {string} email User email. * @property {string} password User password hashed using MD5. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -289,8 +312,9 @@ const usersDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undef /** * @param {UsersCreateMD5UserRequestParams} params */ -const usersCreateMD5User = async ({ userId, email, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateMD5User = async ({userId,email,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/md5'; let payload = {}; if (typeof userId !== 'undefined') { @@ -316,8 +340,9 @@ const usersCreateMD5User = async ({ userId, email, password, name, parseOutput = parse(response) success() } - + return response; + } /** @@ -326,6 +351,7 @@ const usersCreateMD5User = async ({ userId, email, password, name, parseOutput = * @property {string} email User email. * @property {string} password User password hashed using PHPass. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -333,8 +359,9 @@ const usersCreateMD5User = async ({ userId, email, password, name, parseOutput = /** * @param {UsersCreatePHPassUserRequestParams} params */ -const usersCreatePHPassUser = async ({ userId, email, password, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreatePHPassUser = async ({userId,email,password,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/phpass'; let payload = {}; if (typeof userId !== 'undefined') { @@ -360,8 +387,9 @@ const usersCreatePHPassUser = async ({ userId, email, password, name, parseOutpu parse(response) success() } - + return response; + } /** @@ -375,6 +403,7 @@ const usersCreatePHPassUser = async ({ userId, email, password, name, parseOutpu * @property {number} passwordParallel Optional parallelization cost used to hash password. * @property {number} passwordLength Optional hash length used to hash password. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -382,8 +411,9 @@ const usersCreatePHPassUser = async ({ userId, email, password, name, parseOutpu /** * @param {UsersCreateScryptUserRequestParams} params */ -const usersCreateScryptUser = async ({ userId, email, password, passwordSalt, passwordCpu, passwordMemory, passwordParallel, passwordLength, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateScryptUser = async ({userId,email,password,passwordSalt,passwordCpu,passwordMemory,passwordParallel,passwordLength,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/scrypt'; let payload = {}; if (typeof userId !== 'undefined') { @@ -424,8 +454,9 @@ const usersCreateScryptUser = async ({ userId, email, password, passwordSalt, pa parse(response) success() } - + return response; + } /** @@ -437,6 +468,7 @@ const usersCreateScryptUser = async ({ userId, email, password, passwordSalt, pa * @property {string} passwordSaltSeparator Salt separator used to hash password. * @property {string} passwordSignerKey Signer key used to hash password. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -444,8 +476,9 @@ const usersCreateScryptUser = async ({ userId, email, password, passwordSalt, pa /** * @param {UsersCreateScryptModifiedUserRequestParams} params */ -const usersCreateScryptModifiedUser = async ({ userId, email, password, passwordSalt, passwordSaltSeparator, passwordSignerKey, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateScryptModifiedUser = async ({userId,email,password,passwordSalt,passwordSaltSeparator,passwordSignerKey,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/scrypt-modified'; let payload = {}; if (typeof userId !== 'undefined') { @@ -480,8 +513,9 @@ const usersCreateScryptModifiedUser = async ({ userId, email, password, password parse(response) success() } - + return response; + } /** @@ -491,6 +525,7 @@ const usersCreateScryptModifiedUser = async ({ userId, email, password, password * @property {string} password User password hashed using SHA. * @property {PasswordHash} passwordVersion Optional SHA version used to hash password. Allowed values are: 'sha1', 'sha224', 'sha256', 'sha384', 'sha512/224', 'sha512/256', 'sha512', 'sha3-224', 'sha3-256', 'sha3-384', 'sha3-512' * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -498,8 +533,9 @@ const usersCreateScryptModifiedUser = async ({ userId, email, password, password /** * @param {UsersCreateSHAUserRequestParams} params */ -const usersCreateSHAUser = async ({ userId, email, password, passwordVersion, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateSHAUser = async ({userId,email,password,passwordVersion,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/sha'; let payload = {}; if (typeof userId !== 'undefined') { @@ -528,13 +564,15 @@ const usersCreateSHAUser = async ({ userId, email, password, passwordVersion, na parse(response) success() } - + return response; + } /** * @typedef {Object} UsersGetUsageRequestParams * @property {UserUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -542,8 +580,9 @@ const usersCreateSHAUser = async ({ userId, email, password, passwordVersion, na /** * @param {UsersGetUsageRequestParams} params */ -const usersGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersGetUsage = async ({range,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/usage'; let payload = {}; if (typeof range !== 'undefined') { @@ -560,13 +599,15 @@ const usersGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} UsersGetRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -574,8 +615,9 @@ const usersGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { /** * @param {UsersGetRequestParams} params */ -const usersGet = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersGet = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}'.replace('{userId}', userId); let payload = {}; @@ -586,16 +628,22 @@ const usersGet = async ({ userId, parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'get', userId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} UsersDeleteRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -603,8 +651,9 @@ const usersGet = async ({ userId, parseOutput = true, sdk = undefined}) => { /** * @param {UsersDeleteRequestParams} params */ -const usersDelete = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDelete = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}'.replace('{userId}', userId); let payload = {}; @@ -618,14 +667,16 @@ const usersDelete = async ({ userId, parseOutput = true, sdk = undefined}) => { parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateEmailRequestParams * @property {string} userId User ID. * @property {string} email User email. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -633,8 +684,9 @@ const usersDelete = async ({ userId, parseOutput = true, sdk = undefined}) => { /** * @param {UsersUpdateEmailRequestParams} params */ -const usersUpdateEmail = async ({ userId, email, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateEmail = async ({userId,email,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/email'.replace('{userId}', userId); let payload = {}; if (typeof email !== 'undefined') { @@ -651,14 +703,56 @@ const usersUpdateEmail = async ({ userId, email, parseOutput = true, sdk = undef parse(response) success() } - + + return response; + +} + +/** + * @typedef {Object} UsersCreateJWTRequestParams + * @property {string} userId User ID. + * @property {string} sessionId Session ID. Use the string 'recent' to use the most recent session. Defaults to the most recent session. + * @property {number} duration Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {UsersCreateJWTRequestParams} params + */ +const usersCreateJWT = async ({userId,sessionId,duration,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/users/{userId}/jwts'.replace('{userId}', userId); + let payload = {}; + if (typeof sessionId !== 'undefined') { + payload['sessionId'] = sessionId; + } + if (typeof duration !== 'undefined') { + payload['duration'] = duration; + } + + let response = undefined; + + response = await client.call('post', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + return response; + } /** * @typedef {Object} UsersUpdateLabelsRequestParams * @property {string} userId User ID. * @property {string[]} labels Array of user labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -666,8 +760,9 @@ const usersUpdateEmail = async ({ userId, email, parseOutput = true, sdk = undef /** * @param {UsersUpdateLabelsRequestParams} params */ -const usersUpdateLabels = async ({ userId, labels, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateLabels = async ({userId,labels,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/labels'.replace('{userId}', userId); let payload = {}; labels = labels === true ? [] : labels; @@ -685,14 +780,16 @@ const usersUpdateLabels = async ({ userId, labels, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListLogsRequestParams * @property {string} userId User ID. * @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). Only supported methods are limit and offset + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -700,8 +797,9 @@ const usersUpdateLabels = async ({ userId, labels, parseOutput = true, sdk = und /** * @param {UsersListLogsRequestParams} params */ -const usersListLogs = async ({ userId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListLogs = async ({userId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/logs'.replace('{userId}', userId); let payload = {}; if (typeof queries !== 'undefined') { @@ -718,13 +816,15 @@ const usersListLogs = async ({ userId, queries, parseOutput = true, sdk = undefi parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListMembershipsRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -732,8 +832,9 @@ const usersListLogs = async ({ userId, queries, parseOutput = true, sdk = undefi /** * @param {UsersListMembershipsRequestParams} params */ -const usersListMemberships = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListMemberships = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/memberships'.replace('{userId}', userId); let payload = {}; @@ -747,14 +848,16 @@ const usersListMemberships = async ({ userId, parseOutput = true, sdk = undefine parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateMfaRequestParams * @property {string} userId User ID. * @property {boolean} mfa Enable or disable MFA. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -762,8 +865,9 @@ const usersListMemberships = async ({ userId, parseOutput = true, sdk = undefine /** * @param {UsersUpdateMfaRequestParams} params */ -const usersUpdateMfa = async ({ userId, mfa, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateMfa = async ({userId,mfa,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa'.replace('{userId}', userId); let payload = {}; if (typeof mfa !== 'undefined') { @@ -780,14 +884,16 @@ const usersUpdateMfa = async ({ userId, mfa, parseOutput = true, sdk = undefined parse(response) success() } - + return response; + } /** * @typedef {Object} UsersDeleteMfaAuthenticatorRequestParams * @property {string} userId User ID. * @property {AuthenticatorType} type Type of authenticator. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -795,8 +901,9 @@ const usersUpdateMfa = async ({ userId, mfa, parseOutput = true, sdk = undefined /** * @param {UsersDeleteMfaAuthenticatorRequestParams} params */ -const usersDeleteMfaAuthenticator = async ({ userId, type, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDeleteMfaAuthenticator = async ({userId,type,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa/authenticators/{type}'.replace('{userId}', userId).replace('{type}', type); let payload = {}; @@ -810,13 +917,15 @@ const usersDeleteMfaAuthenticator = async ({ userId, type, parseOutput = true, s parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListMfaFactorsRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -824,8 +933,9 @@ const usersDeleteMfaAuthenticator = async ({ userId, type, parseOutput = true, s /** * @param {UsersListMfaFactorsRequestParams} params */ -const usersListMfaFactors = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListMfaFactors = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa/factors'.replace('{userId}', userId); let payload = {}; @@ -839,13 +949,15 @@ const usersListMfaFactors = async ({ userId, parseOutput = true, sdk = undefined parse(response) success() } - + return response; + } /** * @typedef {Object} UsersGetMfaRecoveryCodesRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -853,8 +965,9 @@ const usersListMfaFactors = async ({ userId, parseOutput = true, sdk = undefined /** * @param {UsersGetMfaRecoveryCodesRequestParams} params */ -const usersGetMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersGetMfaRecoveryCodes = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); let payload = {}; @@ -868,13 +981,15 @@ const usersGetMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = unde parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateMfaRecoveryCodesRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -882,8 +997,9 @@ const usersGetMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = unde /** * @param {UsersUpdateMfaRecoveryCodesRequestParams} params */ -const usersUpdateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateMfaRecoveryCodes = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); let payload = {}; @@ -897,13 +1013,15 @@ const usersUpdateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} UsersCreateMfaRecoveryCodesRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -911,8 +1029,9 @@ const usersUpdateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u /** * @param {UsersCreateMfaRecoveryCodesRequestParams} params */ -const usersCreateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateMfaRecoveryCodes = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); let payload = {}; @@ -926,14 +1045,16 @@ const usersCreateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateNameRequestParams * @property {string} userId User ID. * @property {string} name User name. Max length: 128 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -941,8 +1062,9 @@ const usersCreateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u /** * @param {UsersUpdateNameRequestParams} params */ -const usersUpdateName = async ({ userId, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateName = async ({userId,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/name'.replace('{userId}', userId); let payload = {}; if (typeof name !== 'undefined') { @@ -959,14 +1081,16 @@ const usersUpdateName = async ({ userId, name, parseOutput = true, sdk = undefin parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdatePasswordRequestParams * @property {string} userId User ID. * @property {string} password New user password. Must be at least 8 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -974,8 +1098,9 @@ const usersUpdateName = async ({ userId, name, parseOutput = true, sdk = undefin /** * @param {UsersUpdatePasswordRequestParams} params */ -const usersUpdatePassword = async ({ userId, password, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdatePassword = async ({userId,password,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/password'.replace('{userId}', userId); let payload = {}; if (typeof password !== 'undefined') { @@ -992,14 +1117,16 @@ const usersUpdatePassword = async ({ userId, password, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdatePhoneRequestParams * @property {string} userId User ID. * @property {string} number User phone number. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1007,8 +1134,9 @@ const usersUpdatePassword = async ({ userId, password, parseOutput = true, sdk = /** * @param {UsersUpdatePhoneRequestParams} params */ -const usersUpdatePhone = async ({ userId, number, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdatePhone = async ({userId,number,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/phone'.replace('{userId}', userId); let payload = {}; if (typeof number !== 'undefined') { @@ -1025,13 +1153,15 @@ const usersUpdatePhone = async ({ userId, number, parseOutput = true, sdk = unde parse(response) success() } - + return response; + } /** * @typedef {Object} UsersGetPrefsRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1039,8 +1169,9 @@ const usersUpdatePhone = async ({ userId, number, parseOutput = true, sdk = unde /** * @param {UsersGetPrefsRequestParams} params */ -const usersGetPrefs = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersGetPrefs = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/prefs'.replace('{userId}', userId); let payload = {}; @@ -1054,14 +1185,16 @@ const usersGetPrefs = async ({ userId, parseOutput = true, sdk = undefined}) => parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdatePrefsRequestParams * @property {string} userId User ID. * @property {object} prefs Prefs key-value JSON object. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1069,8 +1202,9 @@ const usersGetPrefs = async ({ userId, parseOutput = true, sdk = undefined}) => /** * @param {UsersUpdatePrefsRequestParams} params */ -const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdatePrefs = async ({userId,prefs,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/prefs'.replace('{userId}', userId); let payload = {}; if (typeof prefs !== 'undefined') { @@ -1087,13 +1221,15 @@ const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undef parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListSessionsRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1101,8 +1237,9 @@ const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undef /** * @param {UsersListSessionsRequestParams} params */ -const usersListSessions = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListSessions = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); let payload = {}; @@ -1113,16 +1250,22 @@ const usersListSessions = async ({ userId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'listSessions', userId); + } else { + parse(response) + success() + } } - + return response; + } /** * @typedef {Object} UsersCreateSessionRequestParams * @property {string} userId User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1130,8 +1273,9 @@ const usersListSessions = async ({ userId, parseOutput = true, sdk = undefined}) /** * @param {UsersCreateSessionRequestParams} params */ -const usersCreateSession = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateSession = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); let payload = {}; @@ -1145,13 +1289,15 @@ const usersCreateSession = async ({ userId, parseOutput = true, sdk = undefined} parse(response) success() } - + return response; + } /** * @typedef {Object} UsersDeleteSessionsRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1159,8 +1305,9 @@ const usersCreateSession = async ({ userId, parseOutput = true, sdk = undefined} /** * @param {UsersDeleteSessionsRequestParams} params */ -const usersDeleteSessions = async ({ userId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDeleteSessions = async ({userId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); let payload = {}; @@ -1174,14 +1321,16 @@ const usersDeleteSessions = async ({ userId, parseOutput = true, sdk = undefined parse(response) success() } - + return response; + } /** * @typedef {Object} UsersDeleteSessionRequestParams * @property {string} userId User ID. * @property {string} sessionId Session ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1189,8 +1338,9 @@ const usersDeleteSessions = async ({ userId, parseOutput = true, sdk = undefined /** * @param {UsersDeleteSessionRequestParams} params */ -const usersDeleteSession = async ({ userId, sessionId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDeleteSession = async ({userId,sessionId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/sessions/{sessionId}'.replace('{userId}', userId).replace('{sessionId}', sessionId); let payload = {}; @@ -1204,14 +1354,16 @@ const usersDeleteSession = async ({ userId, sessionId, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateStatusRequestParams * @property {string} userId User ID. * @property {boolean} status User Status. To activate the user pass 'true' and to block the user pass 'false'. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1219,8 +1371,9 @@ const usersDeleteSession = async ({ userId, sessionId, parseOutput = true, sdk = /** * @param {UsersUpdateStatusRequestParams} params */ -const usersUpdateStatus = async ({ userId, status, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateStatus = async ({userId,status,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/status'.replace('{userId}', userId); let payload = {}; if (typeof status !== 'undefined') { @@ -1237,14 +1390,16 @@ const usersUpdateStatus = async ({ userId, status, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** * @typedef {Object} UsersListTargetsRequestParams * @property {string} userId User ID. * @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, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1252,8 +1407,9 @@ const usersUpdateStatus = async ({ userId, status, parseOutput = true, sdk = und /** * @param {UsersListTargetsRequestParams} params */ -const usersListTargets = async ({ userId, queries, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersListTargets = async ({userId,queries,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/targets'.replace('{userId}', userId); let payload = {}; if (typeof queries !== 'undefined') { @@ -1270,8 +1426,9 @@ const usersListTargets = async ({ userId, queries, parseOutput = true, sdk = und parse(response) success() } - + return response; + } /** @@ -1282,6 +1439,7 @@ const usersListTargets = async ({ userId, queries, parseOutput = true, sdk = und * @property {string} identifier The target identifier (token, email, phone etc.) * @property {string} providerId Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used. * @property {string} name Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1289,8 +1447,9 @@ const usersListTargets = async ({ userId, queries, parseOutput = true, sdk = und /** * @param {UsersCreateTargetRequestParams} params */ -const usersCreateTarget = async ({ userId, targetId, providerType, identifier, providerId, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateTarget = async ({userId,targetId,providerType,identifier,providerId,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/targets'.replace('{userId}', userId); let payload = {}; if (typeof targetId !== 'undefined') { @@ -1319,14 +1478,16 @@ const usersCreateTarget = async ({ userId, targetId, providerType, identifier, p parse(response) success() } - + return response; + } /** * @typedef {Object} UsersGetTargetRequestParams * @property {string} userId User ID. * @property {string} targetId Target ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1334,8 +1495,9 @@ const usersCreateTarget = async ({ userId, targetId, providerType, identifier, p /** * @param {UsersGetTargetRequestParams} params */ -const usersGetTarget = async ({ userId, targetId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersGetTarget = async ({userId,targetId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); let payload = {}; @@ -1349,8 +1511,9 @@ const usersGetTarget = async ({ userId, targetId, parseOutput = true, sdk = unde parse(response) success() } - + return response; + } /** @@ -1360,6 +1523,7 @@ const usersGetTarget = async ({ userId, targetId, parseOutput = true, sdk = unde * @property {string} identifier The target identifier (token, email, phone etc.) * @property {string} providerId Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used. * @property {string} name Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1367,8 +1531,9 @@ const usersGetTarget = async ({ userId, targetId, parseOutput = true, sdk = unde /** * @param {UsersUpdateTargetRequestParams} params */ -const usersUpdateTarget = async ({ userId, targetId, identifier, providerId, name, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateTarget = async ({userId,targetId,identifier,providerId,name,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); let payload = {}; if (typeof identifier !== 'undefined') { @@ -1391,14 +1556,16 @@ const usersUpdateTarget = async ({ userId, targetId, identifier, providerId, nam parse(response) success() } - + return response; + } /** * @typedef {Object} UsersDeleteTargetRequestParams * @property {string} userId User ID. * @property {string} targetId Target ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1406,8 +1573,9 @@ const usersUpdateTarget = async ({ userId, targetId, identifier, providerId, nam /** * @param {UsersDeleteTargetRequestParams} params */ -const usersDeleteTarget = async ({ userId, targetId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersDeleteTarget = async ({userId,targetId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); let payload = {}; @@ -1421,8 +1589,9 @@ const usersDeleteTarget = async ({ userId, targetId, parseOutput = true, sdk = u parse(response) success() } - + return response; + } /** @@ -1430,6 +1599,7 @@ const usersDeleteTarget = async ({ userId, targetId, parseOutput = true, sdk = u * @property {string} userId User ID. * @property {number} length Token length in characters. The default length is 6 characters * @property {number} expire Token expiration period in seconds. The default expiration is 15 minutes. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1437,8 +1607,9 @@ const usersDeleteTarget = async ({ userId, targetId, parseOutput = true, sdk = u /** * @param {UsersCreateTokenRequestParams} params */ -const usersCreateToken = async ({ userId, length, expire, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersCreateToken = async ({userId,length,expire,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/tokens'.replace('{userId}', userId); let payload = {}; if (typeof length !== 'undefined') { @@ -1458,14 +1629,16 @@ const usersCreateToken = async ({ userId, length, expire, parseOutput = true, sd parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdateEmailVerificationRequestParams * @property {string} userId User ID. * @property {boolean} emailVerification User email verification status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1473,8 +1646,9 @@ const usersCreateToken = async ({ userId, length, expire, parseOutput = true, sd /** * @param {UsersUpdateEmailVerificationRequestParams} params */ -const usersUpdateEmailVerification = async ({ userId, emailVerification, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdateEmailVerification = async ({userId,emailVerification,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/verification'.replace('{userId}', userId); let payload = {}; if (typeof emailVerification !== 'undefined') { @@ -1491,14 +1665,16 @@ const usersUpdateEmailVerification = async ({ userId, emailVerification, parseOu parse(response) success() } - + return response; + } /** * @typedef {Object} UsersUpdatePhoneVerificationRequestParams * @property {string} userId User ID. * @property {boolean} phoneVerification User phone verification status. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1506,8 +1682,9 @@ const usersUpdateEmailVerification = async ({ userId, emailVerification, parseOu /** * @param {UsersUpdatePhoneVerificationRequestParams} params */ -const usersUpdatePhoneVerification = async ({ userId, phoneVerification, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const usersUpdatePhoneVerification = async ({userId,phoneVerification,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/users/{userId}/verification/phone'.replace('{userId}', userId); let payload = {}; if (typeof phoneVerification !== 'undefined') { @@ -1524,8 +1701,9 @@ const usersUpdatePhoneVerification = async ({ userId, phoneVerification, parseOu parse(response) success() } - + return response; + } users @@ -1533,6 +1711,7 @@ users .description(`Get a list of all the project's users. You can use the query params to filter your results.`) .option(`--queries [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, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(usersList)) users @@ -1640,6 +1819,7 @@ users .command(`get`) .description(`Get a user by its unique ID.`) .requiredOption(`--userId `, `User ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(usersGet)) users @@ -1655,6 +1835,14 @@ users .requiredOption(`--email `, `User email.`) .action(actionRunner(usersUpdateEmail)) +users + .command(`createJWT`) + .description(`Use this endpoint to create a JSON Web Token for user by its unique ID. You can use the resulting JWT to authenticate on behalf of the user. The JWT secret will become invalid if the session it uses gets deleted.`) + .requiredOption(`--userId `, `User ID.`) + .option(`--sessionId `, `Session ID. Use the string 'recent' to use the most recent session. Defaults to the most recent session.`) + .option(`--duration `, `Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.`, parseInteger) + .action(actionRunner(usersCreateJWT)) + users .command(`updateLabels`) .description(`Update the user labels by its unique ID. Labels can be used to grant access to resources. While teams are a way for user's to share access to a resource, labels can be defined by the developer to grant access without an invitation. See the [Permissions docs](https://appwrite.io/docs/permissions) for more info.`) @@ -1751,6 +1939,7 @@ users .command(`listSessions`) .description(`Get the user sessions list by its unique ID.`) .requiredOption(`--userId `, `User ID.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(usersListSessions)) users @@ -1860,6 +2049,7 @@ module.exports = { usersGet, usersDelete, usersUpdateEmail, + usersCreateJWT, usersUpdateLabels, usersListLogs, usersListMemberships, @@ -1887,4 +2077,4 @@ module.exports = { usersCreateToken, usersUpdateEmailVerification, usersUpdatePhoneVerification -}; \ No newline at end of file +}; diff --git a/lib/commands/vcs.js b/lib/commands/vcs.js index 65a0d7f..44ae4ce 100644 --- a/lib/commands/vcs.js +++ b/lib/commands/vcs.js @@ -4,7 +4,7 @@ const tar = require("tar"); const ignore = require("ignore"); const { promisify } = require('util'); const libClient = require('../client.js'); -const { getAllFiles } = require('../utils.js'); +const { getAllFiles, showConsoleLink } = require('../utils.js'); const { Command } = require('commander'); const { sdkForProject, sdkForConsole } = require('../sdks') const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser') @@ -43,6 +43,7 @@ const vcs = new Command("vcs").description(commandDescriptions['vcs']).configure * @typedef {Object} VcsListRepositoriesRequestParams * @property {string} installationId Installation Id * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -50,8 +51,9 @@ const vcs = new Command("vcs").description(commandDescriptions['vcs']).configure /** * @param {VcsListRepositoriesRequestParams} params */ -const vcsListRepositories = async ({ installationId, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsListRepositories = async ({installationId,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId); let payload = {}; if (typeof search !== 'undefined') { @@ -68,8 +70,9 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true, parse(response) success() } - + return response; + } /** @@ -77,6 +80,7 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true, * @property {string} installationId Installation Id * @property {string} name Repository name (slug) * @property {boolean} xprivate Mark repository public or private + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -84,8 +88,9 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true, /** * @param {VcsCreateRepositoryRequestParams} params */ -const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsCreateRepository = async ({installationId,name,xprivate,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId); let payload = {}; if (typeof name !== 'undefined') { @@ -105,14 +110,16 @@ const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput parse(response) success() } - + return response; + } /** * @typedef {Object} VcsGetRepositoryRequestParams * @property {string} installationId Installation Id * @property {string} providerRepositoryId Repository Id + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -120,8 +127,9 @@ const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput /** * @param {VcsGetRepositoryRequestParams} params */ -const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsGetRepository = async ({installationId,providerRepositoryId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId); let payload = {}; @@ -135,14 +143,16 @@ const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOut parse(response) success() } - + return response; + } /** * @typedef {Object} VcsListRepositoryBranchesRequestParams * @property {string} installationId Installation Id * @property {string} providerRepositoryId Repository Id + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -150,8 +160,9 @@ const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOut /** * @param {VcsListRepositoryBranchesRequestParams} params */ -const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsListRepositoryBranches = async ({installationId,providerRepositoryId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/branches'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId); let payload = {}; @@ -165,8 +176,46 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, parse(response) success() } - + + return response; + +} + +/** + * @typedef {Object} VcsGetRepositoryContentsRequestParams + * @property {string} installationId Installation Id + * @property {string} providerRepositoryId Repository Id + * @property {string} providerRootDirectory Path to get contents of nested directory + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {VcsGetRepositoryContentsRequestParams} params + */ +const vcsGetRepositoryContents = async ({installationId,providerRepositoryId,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/contents'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId); + let payload = {}; + if (typeof providerRootDirectory !== 'undefined') { + payload['providerRootDirectory'] = providerRootDirectory; + } + + let response = undefined; + + response = await client.call('get', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + success() + } + return response; + } /** @@ -174,6 +223,7 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, * @property {string} installationId Installation Id * @property {string} providerRepositoryId Repository Id * @property {string} providerRootDirectory Path to Root Directory + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -181,8 +231,9 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, /** * @param {VcsCreateRepositoryDetectionRequestParams} params */ -const vcsCreateRepositoryDetection = async ({ installationId, providerRepositoryId, providerRootDirectory, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsCreateRepositoryDetection = async ({installationId,providerRepositoryId,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/detection'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId); let payload = {}; if (typeof providerRootDirectory !== 'undefined') { @@ -199,8 +250,9 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository parse(response) success() } - + return response; + } /** @@ -208,6 +260,7 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository * @property {string} installationId Installation Id * @property {string} repositoryId VCS Repository Id * @property {string} providerPullRequestId GitHub Pull Request Id + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -215,8 +268,9 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository /** * @param {VcsUpdateExternalDeploymentsRequestParams} params */ -const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, providerPullRequestId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsUpdateExternalDeployments = async ({installationId,repositoryId,providerPullRequestId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/github/installations/{installationId}/repositories/{repositoryId}'.replace('{installationId}', installationId).replace('{repositoryId}', repositoryId); let payload = {}; if (typeof providerPullRequestId !== 'undefined') { @@ -233,14 +287,16 @@ const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, prov parse(response) success() } - + return response; + } /** * @typedef {Object} VcsListInstallationsRequestParams * @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: provider, organization * @property {string} search Search term to filter your list results. Max length: 256 chars. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -248,8 +304,9 @@ const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, prov /** * @param {VcsListInstallationsRequestParams} params */ -const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsListInstallations = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/installations'; let payload = {}; if (typeof queries !== 'undefined') { @@ -269,13 +326,15 @@ const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = parse(response) success() } - + return response; + } /** * @typedef {Object} VcsGetInstallationRequestParams * @property {string} installationId Installation Id + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -283,8 +342,9 @@ const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = /** * @param {VcsGetInstallationRequestParams} params */ -const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsGetInstallation = async ({installationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId); let payload = {}; @@ -298,13 +358,15 @@ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = un parse(response) success() } - + return response; + } /** * @typedef {Object} VcsDeleteInstallationRequestParams * @property {string} installationId Installation Id + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -312,8 +374,9 @@ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = un /** * @param {VcsDeleteInstallationRequestParams} params */ -const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => { - let client = !sdk ? await sdkForProject() : sdk; +const vcsDeleteInstallation = async ({installationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => { + let client = !sdk ? await sdkForProject() : + sdk; let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId); let payload = {}; @@ -327,8 +390,9 @@ const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = parse(response) success() } - + return response; + } vcs @@ -360,6 +424,14 @@ vcs .requiredOption(`--providerRepositoryId `, `Repository Id`) .action(actionRunner(vcsListRepositoryBranches)) +vcs + .command(`getRepositoryContents`) + .description(``) + .requiredOption(`--installationId `, `Installation Id`) + .requiredOption(`--providerRepositoryId `, `Repository Id`) + .option(`--providerRootDirectory `, `Path to get contents of nested directory`) + .action(actionRunner(vcsGetRepositoryContents)) + vcs .command(`createRepositoryDetection`) .description(``) @@ -401,9 +473,10 @@ module.exports = { vcsCreateRepository, vcsGetRepository, vcsListRepositoryBranches, + vcsGetRepositoryContents, vcsCreateRepositoryDetection, vcsUpdateExternalDeployments, vcsListInstallations, vcsGetInstallation, vcsDeleteInstallation -}; \ No newline at end of file +}; diff --git a/lib/config.js b/lib/config.js index 2f69a8f..ca66b52 100644 --- a/lib/config.js +++ b/lib/config.js @@ -204,6 +204,45 @@ class Local extends Config { this.set("buckets", buckets); } + getMessagingTopics() { + if (!this.has("topics")) { + return []; + } + return this.get("topics"); + } + + getMessagingTopic($id) { + if (!this.has("topics")) { + return {}; + } + + let topic = this.get("topics"); + for (let i = 0; i < topic.length; i++) { + if (topic[i]['$id'] == $id) { + return topic[i]; + } + } + + return {}; + } + + addMessagingTopic(props) { + if (!this.has("topics")) { + this.set("topics", []); + } + + let topics = this.get("topics"); + for (let i = 0; i < topics.length; i++) { + if (topics[i]['$id'] === props['$id']) { + topics[i] = props; + this.set("topics", topics); + return; + } + } + topics.push(props); + this.set("topics", topics); + } + getDatabases() { if (!this.has("databases")) { return []; @@ -283,26 +322,75 @@ class Local extends Config { } getProject() { - if (!this.has("projectId") || !this.has("projectName")) { + if (!this.has("projectId")) { return {}; } return { projectId: this.get("projectId"), projectName: this.get("projectName"), + projectSettings: this.get('projectSettings') }; } - setProject(projectId, projectName) { + setProject(projectId, projectName = '', projectSettings = undefined) { this.set("projectId", projectId); - this.set("projectName", projectName); + + if (projectName !== '') { + this.set("projectName", projectName); + } + + if (projectSettings === undefined) { + return; + } + + const settings = { + services: { + account: projectSettings.serviceStatusForAccount, + avatars: projectSettings.serviceStatusForAvatars, + databases: projectSettings.serviceStatusForDatabases, + locale: projectSettings.serviceStatusForLocale, + health: projectSettings.serviceStatusForHealth, + storage: projectSettings.serviceStatusForStorage, + teams: projectSettings.serviceStatusForTeams, + users: projectSettings.serviceStatusForUsers, + functions: projectSettings.serviceStatusForFunctions, + graphql: projectSettings.serviceStatusForGraphql, + messaging: projectSettings.serviceStatusForMessaging, + + }, + auth: { + methods: { + jwt: projectSettings.authJWT, + phone: projectSettings.authPhone, + invites: projectSettings.authInvites, + anonymous: projectSettings.authAnonymous, + "email-otp": projectSettings.authEmailOtp, + "magic-url": projectSettings.authUsersAuthMagicURL, + "email-password": projectSettings.authEmailPassword + }, + security: { + duration: projectSettings.authDuration, + limit: projectSettings.authLimit, + sessionsLimit: projectSettings.authSessionsLimit, + passwordHistory: projectSettings.authPasswordHistory, + passwordDictionary: projectSettings.authPasswordDictionary, + personalDataCheck: projectSettings.authPersonalDataCheck + } + } + }; + + this.set('projectSettings', settings) } + } class Global extends Config { static CONFIG_FILE_PATH = ".appwrite/prefs.json"; + static PREFERENCE_CURRENT = "current"; static PREFERENCE_ENDPOINT = "endpoint"; + static PREFERENCE_EMAIL = "email"; static PREFERENCE_SELF_SIGNED = "selfSigned"; static PREFERENCE_COOKIE = "cookie"; static PREFERENCE_PROJECT = "project"; @@ -310,6 +398,8 @@ class Global extends Config { static PREFERENCE_LOCALE = "locale"; static PREFERENCE_MODE = "mode"; + static IGNORE_ATTRIBUTES = [Global.PREFERENCE_CURRENT, Global.PREFERENCE_SELF_SIGNED, Global.PREFERENCE_ENDPOINT, Global.PREFERENCE_COOKIE, Global.PREFERENCE_PROJECT, Global.PREFERENCE_KEY, Global.PREFERENCE_LOCALE, Global.PREFERENCE_MODE]; + static MODE_ADMIN = "admin"; static MODE_DEFAULT = "default"; @@ -320,59 +410,141 @@ class Global extends Config { super(`${homeDir}/${path}`); } + getCurrentSession() { + if (!this.has(Global.PREFERENCE_CURRENT)) { + return ""; + } + return this.get(Global.PREFERENCE_CURRENT); + } + + setCurrentSession(session) { + if (session !== undefined) { + this.set(Global.PREFERENCE_CURRENT, session); + } + } + + getSessionIds() { + return Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key)); + } + + getSessions() { + const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key)) + + return sessions.map((session) => { + + return { + id: session, + endpoint: this.data[session][Global.PREFERENCE_ENDPOINT], + email: this.data[session][Global.PREFERENCE_EMAIL] + } + }) + } + + addSession(session, data) { + this.set(session, data); + } + + removeSession(session) { + this.delete(session); + } + + getEmail() { + if (!this.hasFrom(Global.PREFERENCE_EMAIL)) { + return ""; + } + + return this.getFrom(Global.PREFERENCE_EMAIL); + } + + setEmail(email) { + this.setTo(Global.PREFERENCE_EMAIL, email); + } + getEndpoint() { - if (!this.has(Global.PREFERENCE_ENDPOINT)) { + if (!this.hasFrom(Global.PREFERENCE_ENDPOINT)) { return ""; } - return this.get(Global.PREFERENCE_ENDPOINT); + + return this.getFrom(Global.PREFERENCE_ENDPOINT); } setEndpoint(endpoint) { - this.set(Global.PREFERENCE_ENDPOINT, endpoint); + this.setTo(Global.PREFERENCE_ENDPOINT, endpoint); } getSelfSigned() { - if (!this.has(Global.PREFERENCE_SELF_SIGNED)) { + if (!this.hasFrom(Global.PREFERENCE_SELF_SIGNED)) { return false; } - return this.get(Global.PREFERENCE_SELF_SIGNED); + return this.getFrom(Global.PREFERENCE_SELF_SIGNED); } setSelfSigned(selfSigned) { - this.set(Global.PREFERENCE_SELF_SIGNED, selfSigned); + this.setTo(Global.PREFERENCE_SELF_SIGNED, selfSigned); } getCookie() { - if (!this.has(Global.PREFERENCE_COOKIE)) { + if (!this.hasFrom(Global.PREFERENCE_COOKIE)) { return ""; } - return this.get(Global.PREFERENCE_COOKIE); + return this.getFrom(Global.PREFERENCE_COOKIE); } setCookie(cookie) { - this.set(Global.PREFERENCE_COOKIE, cookie); + this.setTo(Global.PREFERENCE_COOKIE, cookie); } getProject() { - if (!this.has(Global.PREFERENCE_PROJECT)) { + if (!this.hasFrom(Global.PREFERENCE_PROJECT)) { return ""; } - return this.get(Global.PREFERENCE_PROJECT); + return this.getFrom(Global.PREFERENCE_PROJECT); } setProject(project) { - this.set(Global.PREFERENCE_PROJECT, project); + this.setTo(Global.PREFERENCE_PROJECT, project); } getKey() { - if (!this.has(Global.PREFERENCE_KEY)) { + if (!this.hasFrom(Global.PREFERENCE_KEY)) { return ""; } - return this.get(Global.PREFERENCE_KEY); + return this.getFrom(Global.PREFERENCE_KEY); } setKey(key) { - this.set(Global.PREFERENCE_KEY, key); + this.setTo(Global.PREFERENCE_KEY, key); + } + + hasFrom(key) { + const current = this.getCurrentSession(); + + if (current) { + const config = this.get(current); + + return config[key] !== undefined; + } + } + + getFrom(key) { + const current = this.getCurrentSession(); + + if (current) { + const config = this.get(current); + + return config[key]; + } + } + + setTo(key, value) { + const current = this.getCurrentSession(); + + if (current) { + const config = this.get(current); + + config[key] = value; + this.write(); + } } } diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js new file mode 100644 index 0000000..fe50339 --- /dev/null +++ b/lib/emulation/docker.js @@ -0,0 +1,187 @@ +const childProcess = require('child_process'); +const { localConfig } = require("../config"); +const path = require('path'); +const fs = require('fs'); +const { log,success } = require("../parser"); +const { openRuntimesVersion, systemTools } = require("./utils"); +const ID = require("../id"); + +const activeDockerIds = {}; + +async function dockerStop(id) { + delete activeDockerIds[id]; + const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], { + stdio: 'pipe', + }); + + await new Promise((res) => { stopProcess.on('close', res) }); +} + +async function dockerPull(func) { + log('Pulling Docker image of function runtime ...'); + + const runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); + const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; + + const pullProcess = childProcess.spawn('docker', ['pull', imageName], { + stdio: 'pipe', + pwd: path.join(process.cwd(), func.path) + }); + + pullProcess.stderr.on('data', (data) => { + process.stderr.write(`\n${data}$ `); + }); + + await new Promise((res) => { pullProcess.on('close', res) }); +} + +async function dockerBuild(func, variables) { + log('Building function using Docker ...'); + + const runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); + const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; + + const functionDir = path.join(process.cwd(), func.path); + + const id = ID.unique(); + + const params = [ 'run' ]; + params.push('--name', id); + params.push('-v', `${functionDir}/:/mnt/code:rw`); + params.push('-e', 'APPWRITE_ENV=development'); + params.push('-e', 'OPEN_RUNTIMES_ENV=development'); + params.push('-e', 'OPEN_RUNTIMES_SECRET='); + params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`); + + for(const k of Object.keys(variables)) { + params.push('-e', `${k}=${variables[k]}`); + } + + params.push(imageName, 'sh', '-c', `helpers/build.sh "${func.commands}"`); + + const buildProcess = childProcess.spawn('docker', params, { + stdio: 'pipe', + pwd: functionDir + }); + + buildProcess.stdout.on('data', (data) => { + process.stdout.write(`\n${data}`); + }); + + buildProcess.stderr.on('data', (data) => { + process.stderr.write(`\n${data}`); + }); + + await new Promise((res) => { buildProcess.on('close', res) }); + + const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz'); + const copyDir = path.dirname(copyPath); + if (!fs.existsSync(copyDir)) { + fs.mkdirSync(copyDir, { recursive: true }); + } + + const copyProcess = childProcess.spawn('docker', ['cp', `${id}:/mnt/code/code.tar.gz`, copyPath], { + stdio: 'pipe', + pwd: functionDir + }); + + await new Promise((res) => { copyProcess.on('close', res) }); + + const cleanupProcess = childProcess.spawn('docker', ['rm', '--force', id], { + stdio: 'pipe', + pwd: functionDir + }); + + await new Promise((res) => { cleanupProcess.on('close', res) }); + + delete activeDockerIds[id]; + + const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + if (fs.existsSync(tempPath)) { + fs.rmSync(tempPath, { force: true }); + } +} + +async function dockerStart(func, variables, port) { + log('Starting function using Docker ...'); + + log("Permissions, events, CRON and timeouts dont apply when running locally."); + + log('💡 Hint: Function automatically restarts when you edit your code.'); + + success(`Visit http://localhost:${port}/ to execute your function.`); + + + const runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); + const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; + + const tool = systemTools[runtimeName]; + + const functionDir = path.join(process.cwd(), func.path); + + const id = ID.unique(); + + const params = [ 'run' ]; + params.push('--rm'); + params.push('-d'); + params.push('--name', id); + params.push('-p', `${port}:3000`); + params.push('-e', 'APPWRITE_ENV=development'); + params.push('-e', 'OPEN_RUNTIMES_ENV=development'); + params.push('-e', 'OPEN_RUNTIMES_SECRET='); + + for(const k of Object.keys(variables)) { + params.push('-e', `${k}=${variables[k]}`); + } + + params.push('-v', `${functionDir}/.appwrite/logs.txt:/mnt/logs/dev_logs.log:rw`); + params.push('-v', `${functionDir}/.appwrite/errors.txt:/mnt/logs/dev_errors.log:rw`); + params.push('-v', `${functionDir}/.appwrite/build.tar.gz:/mnt/code/code.tar.gz:ro`); + params.push(imageName, 'sh', '-c', `helpers/start.sh "${tool.startCommand}"`); + + childProcess.spawn('docker', params, { + stdio: 'pipe', + pwd: functionDir + }); + + activeDockerIds[id] = true; +} + +async function dockerCleanup() { + await dockerStop(); + + const functions = localConfig.getFunctions(); + for(const func of functions) { + const appwritePath = path.join(process.cwd(), func.path, '.appwrite'); + if (fs.existsSync(appwritePath)) { + fs.rmSync(appwritePath, { recursive: true, force: true }); + } + + const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + if (fs.existsSync(tempPath)) { + fs.rmSync(tempPath, { force: true }); + } + } +} + +async function dockerStopActive() { + const ids = Object.keys(activeDockerIds); + for await (const id of ids) { + await dockerStop(id); + } +} + +module.exports = { + dockerStop, + dockerPull, + dockerBuild, + dockerStart, + dockerCleanup, + dockerStopActive, +} diff --git a/lib/emulation/utils.js b/lib/emulation/utils.js new file mode 100644 index 0000000..d36d5cd --- /dev/null +++ b/lib/emulation/utils.js @@ -0,0 +1,177 @@ +const EventEmitter = require('node:events'); +const { projectsCreateJWT } = require('../commands/projects'); +const { localConfig } = require("../config"); + + +const openRuntimesVersion = 'v3'; + +const runtimeNames = { + 'node': 'Node.js', + 'php': 'PHP', + 'ruby': 'Ruby', + 'python': 'Python', + 'python-ml': 'Python (ML)', + 'deno': 'Deno', + 'dart': 'Dart', + 'dotnet': '.NET', + 'java': 'Java', + 'swift': 'Swift', + 'kotlin': 'Kotlin', + 'bun': 'Bun' +}; + +const systemTools = { + 'node': { + isCompiled: false, + startCommand: "node src/server.js", + dependencyFiles: [ "package.json", "package-lock.json" ] + }, + 'php': { + isCompiled: false, + startCommand: "php src/server.php", + dependencyFiles: [ "composer.json", "composer.lock" ] + }, + 'ruby': { + isCompiled: false, + startCommand: "bundle exec puma -b tcp://0.0.0.0:3000 -e production", + dependencyFiles: [ "Gemfile", "Gemfile.lock" ] + }, + 'python': { + isCompiled: false, + startCommand: "python3 src/server.py", + dependencyFiles: [ "requirements.txt", "requirements.lock" ] + }, + 'python-ml': { + isCompiled: false, + startCommand: "python3 src/server.py", + dependencyFiles: [ "requirements.txt", "requirements.lock" ] + }, + 'deno': { + isCompiled: false, + startCommand: "deno start", + dependencyFiles: [ ] + }, + 'dart': { + isCompiled: true, + startCommand: "src/function/server", + dependencyFiles: [ ] + }, + 'dotnet': { + isCompiled: true, + startCommand: "dotnet src/function/DotNetRuntime.dll", + dependencyFiles: [ ] + }, + 'java': { + isCompiled: true, + startCommand: "java -jar src/function/java-runtime-1.0.0.jar", + dependencyFiles: [ ] + }, + 'swift': { + isCompiled: true, + startCommand: "src/function/Runtime serve --env production --hostname 0.0.0.0 --port 3000", + dependencyFiles: [ ] + }, + 'kotlin': { + isCompiled: true, + startCommand: "java -jar src/function/kotlin-runtime-1.0.0.jar", + dependencyFiles: [ ] + }, + 'bun': { + isCompiled: false, + startCommand: "bun src/server.ts", + dependencyFiles: [ "package.json", "package-lock.json", "bun.lockb" ] + }, +}; + +const JwtManager = { + userJwt: null, + functionJwt: null, + + timerWarn: null, + timerError: null, + + async setup(userId = null) { + if(this.timerWarn) { + clearTimeout(this.timerWarn); + } + + if(this.timerError) { + clearTimeout(this.timerError); + } + + this.timerWarn = setTimeout(() => { + log("Warning: Authorized JWT will expire in 5 minutes. Please stop and re-run the command to refresh tokens for 1 hour."); + }, 1000 * 60 * 55); // 55 mins + + this.timerError = setTimeout(() => { + log("Warning: Authorized JWT just expired. Please stop and re-run the command to obtain new tokens with 1 hour validity."); + log("Some Appwrite API communication is not authorized now.") + }, 1000 * 60 * 60); // 60 mins + + if(userId) { + await usersGet({ + userId, + parseOutput: false + }); + const userResponse = await usersCreateJWT({ + userId, + duration: 60*60, + parseOutput: false + }); + this.userJwt = userResponse.jwt; + } + + const functionResponse = await projectsCreateJWT({ + projectId: localConfig.getProject().projectId, + // TODO: Once we have endpoint for this, use it + scopes: ["sessions.write","users.read","users.write","teams.read","teams.write","databases.read","databases.write","collections.read","collections.write","attributes.read","attributes.write","indexes.read","indexes.write","documents.read","documents.write","files.read","files.write","buckets.read","buckets.write","functions.read","functions.write","execution.read","execution.write","locale.read","avatars.read","health.read","providers.read","providers.write","messages.read","messages.write","topics.read","topics.write","subscribers.read","subscribers.write","targets.read","targets.write","rules.read","rules.write","migrations.read","migrations.write","vcs.read","vcs.write","assistant.read"], + duration: 60*60, + parseOutput: false + }); + this.functionJwt = functionResponse.jwt; + } +}; + +const Queue = { + files: [], + locked: false, + events: new EventEmitter(), + debounce: null, + push(file) { + if(!this.files.includes(file)) { + this.files.push(file); + } + + if(!this.locked) { + this._trigger(); + } + }, + lock() { + this.files = []; + this.locked = true; + }, + unlock() { + this.locked = false; + if(this.files.length > 0) { + this._trigger(); + } + }, + _trigger() { + if(this.debounce) { + return; + } + + this.debounce = setTimeout(() => { + this.events.emit('reload', { files: this.files }); + this.debounce = null; + }, 300); + } +}; + +module.exports = { + openRuntimesVersion, + runtimeNames, + systemTools, + JwtManager, + Queue +} diff --git a/lib/id.js b/lib/id.js new file mode 100644 index 0000000..b628463 --- /dev/null +++ b/lib/id.js @@ -0,0 +1,30 @@ +class ID { + // Generate an hex ID based on timestamp + // Recreated from https://www.php.net/manual/en/function.uniqid.php + static #hexTimestamp() { + const now = new Date(); + const sec = Math.floor(now.getTime() / 1000); + const msec = now.getMilliseconds(); + + // Convert to hexadecimal + const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0'); + return hexTimestamp; + } + + static custom(id) { + return id + } + + static unique(padding = 7) { + // Generate a unique ID with padding to have a longer ID + const baseId = ID.#hexTimestamp(); + let randomPadding = ''; + for (let i = 0; i < padding; i++) { + const randomHexDigit = Math.floor(Math.random() * 16).toString(16); + randomPadding += randomHexDigit; + } + return baseId + randomPadding; + } +} + +module.exports = ID; diff --git a/lib/paginate.js b/lib/paginate.js index 8c57fa7..c78814a 100644 --- a/lib/paginate.js +++ b/lib/paginate.js @@ -5,7 +5,6 @@ const paginate = async (action, args = {}, limit = 100, wrapper = '') => { while (true) { const offset = pageNumber * limit; - // Merge the limit and offset into the args const response = await action({ ...args, @@ -48,4 +47,4 @@ const paginate = async (action, args = {}, limit = 100, wrapper = '') => { module.exports = { paginate -}; \ No newline at end of file +}; diff --git a/lib/parser.js b/lib/parser.js index 717bdd6..8c64db2 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -2,10 +2,18 @@ const chalk = require('chalk'); const commander = require('commander'); const Table = require('cli-table3'); const { description } = require('../package.json'); +const { globalConfig } = require("./config.js"); +const os = require('os'); +const Client = require("./client"); const cliConfig = { - verbose: false, - json: false + verbose: false, + json: false, + force: false, + all: false, + ids: [], + report: false, + reportData: {} }; const parse = (data) => { @@ -110,17 +118,60 @@ const drawJSON = (data) => { } const parseError = (err) => { - if(cliConfig.verbose) { - console.error(err); - } + if (cliConfig.report) { + (async () => { + let appwriteVersion = 'unknown'; + const endpoint = globalConfig.getEndpoint(); + const isCloud = endpoint.includes('cloud.appwrite.io') ? 'Yes' : 'No'; + + try { + const client = new Client().setEndpoint(endpoint); + const res = await client.call('get', '/health/version'); + appwriteVersion = res.version; + } catch { + } + + const version = '5.0.5'; + const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; + const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; + + const stack = '```\n' + err.stack + '\n```'; + + const githubIssueUrl = new URL('https://github.com/appwrite/appwrite/issues/new'); + githubIssueUrl.searchParams.append('labels', 'bug'); + githubIssueUrl.searchParams.append('template', 'bug.yaml'); + githubIssueUrl.searchParams.append('title', `🐛 Bug Report: ${err.message}`); + githubIssueUrl.searchParams.append('actual-behavior', `CLI Error:\n${stack}`); + githubIssueUrl.searchParams.append('steps-to-reproduce', stepsToReproduce); + githubIssueUrl.searchParams.append('environment', yourEnvironment); + + log(`To report this error you can:\n - Create a support ticket in our Discord server https://appwrite.io/discord \n - Create an issue in our Github\n ${githubIssueUrl.href}\n`); - error(err.message); - process.exit(1) + error('\n Stack Trace: \n'); + console.error(err); + process.exit(1); + })() + } else { + if (cliConfig.verbose) { + console.error(err); + } else { + log('For detailed error pass the --verbose or --report flag'); + error(err.message); + } + process.exit(1); + } + } const actionRunner = (fn) => { - return (...args) => fn(...args).catch(parseError); + return (...args) => { + if (cliConfig.all && (Array.isArray(cliConfig.ids) && cliConfig.ids.length !== 0)) { + error(`The '--all' and '--id' flags cannot be used together.`); + process.exit(1); + } + return fn(...args).catch(parseError) + }; } const parseInteger = (value) => { @@ -156,10 +207,12 @@ const commandDescriptions = { "graphql": `The graphql command allows you to query and mutate any resource type on your Appwrite server.`, "avatars": `The avatars command aims to help you complete everyday tasks related to your app image, icons, and avatars.`, "databases": `The databases command allows you to create structured collections of documents, query and filter lists of documents.`, - "deploy": `The deploy command provides a convenient wrapper for deploying your functions and collections.`, + "init": `The init command provides a convenient wrapper for creating and initializing project, functions, collections, buckets, teams and messaging in Appwrite.`, + "push": `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams and messaging.`, + "run": `The run command allows you to run project locally to allow easy development and quick debugging.`, "functions": `The functions command allows you view, create and manage your Cloud Functions.`, "health": `The health command allows you to both validate and monitor your Appwrite server's health.`, - "init": `The init command helps you initialize your Appwrite project, functions and collections`, + "pull": `The pull command helps you pull your Appwrite project, functions, collections, buckets, teams and messaging`, "locale": `The locale command allows you to customize your app based on your users' location.`, "projects": `The projects command allows you to view, create and manage your Appwrite projects.`, "storage": `The storage command allows you to manage your project files.`, @@ -168,6 +221,8 @@ const commandDescriptions = { "client": `The client command allows you to configure your CLI`, "login": `The login command allows you to authenticate and manage a user account.`, "logout": `The logout command allows you to logout of your Appwrite account.`, + "whoami": `The whoami command gives information about the currently logged in user.`, + "register": `Outputs the link to create an Appwrite account..`, "console" : `The console command allows gives you access to the APIs used by the Appwrite console.`, "assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`, "messaging": `The messaging command allows you to send messages.`, @@ -179,6 +234,7 @@ const commandDescriptions = { } module.exports = { + drawTable, parse, actionRunner, parseInteger, @@ -187,5 +243,6 @@ module.exports = { success, error, commandDescriptions, - cliConfig -} \ No newline at end of file + cliConfig, + drawTable +} diff --git a/lib/questions.js b/lib/questions.js index 7f26b13..d003f9d 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -1,15 +1,22 @@ -const { localConfig } = require('./config'); +const chalk = require("chalk"); +const Client = require("./client"); +const { localConfig, globalConfig } = require('./config'); const { projectsList } = require('./commands/projects'); -const { functionsListRuntimes } = require('./commands/functions'); +const { teamsList } = require('./commands/teams'); +const { functionsListRuntimes, functionsList } = require('./commands/functions'); const { accountListMfaFactors } = require("./commands/account"); const { sdkForConsole } = require("./sdks"); - +const { validateRequired } = require("./validations"); +const { paginate } = require('./paginate'); +const { isPortTaken } = require('./utils'); const { databasesList } = require('./commands/databases'); const { checkDeployConditions } = require('./utils'); const JSONbig = require("json-bigint")({ storeAsString: false }); +const whenOverride = (answers) => answers.override === undefined ? true : answers.override; + const getIgnores = (runtime) => { - const languge = runtime.split('-')[0]; + const languge = runtime.split("-").slice(0, -1).join("-"); switch (languge) { case 'cpp': @@ -29,6 +36,7 @@ const getIgnores = (runtime) => { case 'php': return ['vendor']; case 'python': + case 'python-ml': return ['__pypackages__']; case 'ruby': return ['vendor']; @@ -42,7 +50,7 @@ const getIgnores = (runtime) => { }; const getEntrypoint = (runtime) => { - const languge = runtime.split('-')[0]; + const languge = runtime.split("-").slice(0, -1).join("-"); switch (languge) { case 'dart': @@ -56,6 +64,7 @@ const getEntrypoint = (runtime) => { case 'php': return 'src/index.php'; case 'python': + case 'python-ml': return 'src/main.py'; case 'ruby': return 'lib/main.rb'; @@ -77,7 +86,7 @@ const getEntrypoint = (runtime) => { }; const getInstallCommand = (runtime) => { - const languge = runtime.split('-')[0]; + const languge = runtime.split("-").slice(0, -1).join("-"); switch (languge) { case 'dart': @@ -91,6 +100,7 @@ const getInstallCommand = (runtime) => { case 'php': return 'composer install'; case 'python': + case 'python-ml': return 'pip install -r requirements.txt'; case 'ruby': return 'bundle install'; @@ -113,7 +123,7 @@ const questionsInitProject = [ type: "confirm", name: "override", message: - `An Appwrite project ( ${localConfig.getProject()['projectName']} ) is already associated with the current directory. Would you like to override`, + `An Appwrite project ( ${localConfig.getProject()['projectId']} ) is already associated with the current directory. Would you like to override`, when() { return Object.keys(localConfig.getProject()).length !== 0; } @@ -121,61 +131,72 @@ const questionsInitProject = [ { type: "list", name: "start", - when(answers) { - if (answers.override == undefined) { - return true - } - return answers.override; - }, + when: whenOverride, message: "How would you like to start?", choices: [ { - name: "Create a new Appwrite project", - value: "new", + name: "Create new project", + value: "new" }, { - name: "Link this directory to an existing Appwrite project", - value: "existing", - }, - ], + name: "Link directory to an existing project", + value: "existing" + } + ] + }, + { + type: "search-list", + name: "organization", + message: "Choose your organization", + choices: async () => { + let client = await sdkForConsole(true); + const { teams } = await paginate(teamsList, { parseOutput: false, sdk: client }, 100, 'teams'); + + let choices = teams.map((team, idx) => { + return { + name: `${team.name} (${team['$id']})`, + value: team['$id'] + } + }) + + if (choices.length == 0) { + throw new Error(`No organizations found. Please create a new organization at ${globalConfig.getEndpoint().replace('/v1', '/console/onboarding')}`) + } + + return choices; + }, + when: whenOverride }, { type: "input", name: "project", message: "What would you like to name your project?", default: "My Awesome Project", - when(answers) { - return answers.start == "new"; - }, + when: (answer) => answer.start !== 'existing' }, { type: "input", name: "id", message: "What ID would you like to have for your project?", default: "unique()", - when(answers) { - return answers.start == "new"; - }, + when: (answer) => answer.start !== 'existing' }, { - type: "list", + type: "search-list", name: "project", message: "Choose your Appwrite project.", - when(answers) { - return answers.start == "existing"; - }, - choices: async () => { - let response = await projectsList({ - parseOutput: false - }) - let projects = response["projects"] - let choices = projects.map((project, idx) => { + choices: async (answers) => { + const queries = [ + JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization.id] }), + JSON.stringify({ method: 'orderDesc', attribute: 'Id' }) + ] + + const { projects } = await paginate(projectsList, { parseOutput: false, queries, }, 100, 'projects'); + + let choices = projects.map((project) => { return { name: `${project.name} (${project['$id']})`, - value: { - name: project.name, - id: project['$id'] - } + value: project['$id'] } }) @@ -184,11 +205,50 @@ const questionsInitProject = [ } return choices; + }, + when: (answer) => answer.start === 'existing' + } +]; +const questionsPullResources = [ + { + type: "list", + name: "resource", + message: "Which resources would you like to pull?", + choices: [ + { name: 'Project', value: 'project' }, + { name: 'Functions', value: 'functions' }, + { name: 'Collections', value: 'collections' }, + { name: 'Buckets', value: 'buckets' }, + { name: 'Teams', value: 'teams' }, + { name: 'Topics', value: 'messages' } + ] + } +] + +const questionsPullFunctions = [ + { + type: "checkbox", + name: "functions", + message: "Which functions would you like to pull?", + validate: (value) => validateRequired('function', value), + choices: async () => { + const { functions } = await paginate(functionsList, { parseOutput: false }, 100, 'functions'); + + if (functions.length === 0) { + throw "We couldn't find any functions in your Appwrite project"; + } + + return functions.map(func => { + return { + name: `${func.name} (${func.$id})`, + value: func + } + }); } } ]; -const questionsInitFunction = [ +const questionsCreateFunction = [ { type: "input", name: "name", @@ -215,9 +275,10 @@ const questionsInitFunction = [ name: `${runtime.name} (${runtime['$id']})`, value: { id: runtime['$id'], + name: runtime['$id'].split('-')[0], entrypoint: getEntrypoint(runtime['$id']), ignore: getIgnores(runtime['$id']), - commands : getInstallCommand(runtime['$id']) + commands: getInstallCommand(runtime['$id']) }, } }) @@ -226,11 +287,146 @@ const questionsInitFunction = [ } ]; -const questionsInitCollection = [ +const questionsCreateFunctionSelectTemplate = (templates) => { + return [ + { + type: "search-list", + name: "template", + message: "What template would you like to use?", + choices: templates.map((template) => { + const name = `${template[0].toUpperCase()}${template.split('').slice(1).join('')}`.replace(/[-_]/g, ' '); + + return { value: template, name } + }) + } + ]; +}; + + + +const questionsCreateBucket = [ + { + type: "input", + name: "bucket", + message: "What would you like to name your bucket?", + default: "My Awesome Bucket" + }, + { + type: "input", + name: "id", + message: "What ID would you like to have for your bucket?", + default: "unique()" + }, + { + type: "list", + name: "fileSecurity", + message: "Enable File-Security configuring permissions for individual file", + choices: ["No", "Yes"] + } +]; + +const questionsCreateTeam = [ + { + type: "input", + name: "bucket", + message: "What would you like to name your team?", + default: "My Awesome Team" + }, + { + type: "input", + name: "id", + message: "What ID would you like to have for your team?", + default: "unique()" + } +]; + +const questionsCreateCollection = [ + { + type: "list", + name: "method", + message: "What database would you like to use for your collection", + choices: ["New", "Existing"], + when: async () => { + return localConfig.getDatabases().length !== 0; + } + }, + { + type: "search-list", + name: "database", + message: "Choose the collection database", + choices: async () => { + const databases = localConfig.getDatabases(); + + let choices = databases.map((database, idx) => { + return { + name: `${database.name} (${database.$id})`, + value: database.$id + } + }) + + if (choices.length === 0) { + throw new Error("No databases found. Please create one in project console.") + } + + return choices; + }, + when: (answers) => (answers.method ?? '').toLowerCase() === 'existing' + }, + { + type: "input", + name: "databaseName", + message: "What would you like to name your database?", + default: "My Awesome Database", + when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing' + }, + { + type: "input", + name: "databaseId", + message: "What ID would you like to have for your database?", + default: "unique()", + when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing' + }, + { + type: "input", + name: "collection", + message: "What would you like to name your collection?", + default: "My Awesome Collection" + }, + { + type: "input", + name: "id", + message: "What ID would you like to have for your collection?", + default: "unique()" + }, + { + type: "list", + name: "documentSecurity", + message: "Enable Document-Security for configuring permissions for individual documents", + choices: ["No", "Yes"] + } +]; + +const questionsCreateMessagingTopic = [ + { + type: "input", + name: "topic", + message: "What would you like to name your messaging topic?", + default: "My Awesome Topic" + }, + { + type: "input", + name: "id", + message: "What ID would you like to have for your messaging topic?", + default: "unique()" + } +]; + +const questionsPullCollection = [ { type: "checkbox", name: "databases", - message: "From which database would you like to init collections?", + message: "From which database would you like to pull collections?", + validate: (value) => validateRequired('collection', value), choices: async () => { let response = await databasesList({ parseOutput: false @@ -252,6 +448,16 @@ const questionsInitCollection = [ ]; const questionsLogin = [ + { + type: "list", + name: "method", + message: "You're already logged in, what you like to do?", + choices: [ + { name: 'Login to a different account', value: 'login' }, + { name: 'Change to a different existed account', value: 'select' } + ], + when: () => globalConfig.getCurrentSession() !== '' + }, { type: "input", name: "email", @@ -262,6 +468,7 @@ const questionsLogin = [ } return true; }, + when: (answers) => answers.method !== 'select' }, { type: "password", @@ -273,20 +480,132 @@ const questionsLogin = [ return "Please enter your password"; } return true; - } + }, + when: (answers) => answers.method !== 'select' + }, + { + type: "search-list", + name: "accountId", + message: "Select an account to use", + choices() { + const sessions = globalConfig.getSessions(); + const current = globalConfig.getCurrentSession(); + + const data = []; + + const longestEmail = sessions.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length; + + sessions.forEach((session) => { + if (session.email) { + data.push({ + current: current === session.id, + value: session.id, + name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold('current') : ' '.repeat(6)} ${session.endpoint}`, + }); + } + }) + + return data.sort((a, b) => Number(b.current) - Number(a.current)) + }, + when: (answers) => answers.method === 'select' }, ]; +const questionGetEndpoint = [ + { + type: "input", + name: "endpoint", + message: "Enter the endpoint of your Appwrite server", + default: "http://localhost/v1", + async validate(value) { + if (!value) { + return "Please enter a valid endpoint."; + } + let client = new Client().setEndpoint(value); + try { + let response = await client.call('get', '/health/version'); + if (response.version) { + return true; + } else { + throw new Error(); + } + } catch (error) { + return "Invalid endpoint or your Appwrite server is not running as expected."; + } + } + } +]; -const questionsDeployFunctions = [ +const questionsLogout = [ + { + type: "checkbox", + name: "accounts", + message: "Select accounts to logout from", + validate: (value) => validateRequired('account', value), + choices() { + const sessions = globalConfig.getSessions(); + const current = globalConfig.getCurrentSession(); + + const data = []; + + const longestEmail = sessions.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length; + + sessions.forEach((session) => { + if (session.email) { + data.push({ + current: current === session.id, + value: session.id, + name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold('current') : ' '.repeat(6)} ${session.endpoint}`, + }); + } + }) + + return data.sort((a, b) => Number(b.current) - Number(a.current)) + } + } +]; + +const questionsPushResources = [ + { + type: "list", + name: "resource", + message: "Which resources would you like to push?", + choices: [ + { name: 'Project', value: 'project' }, + { name: 'Functions', value: 'functions' }, + { name: 'Collections', value: 'collections' }, + { name: 'Buckets', value: 'buckets' }, + { name: 'Teams', value: 'teams' }, + { name: 'Topics', value: 'messages' } + ] + } +]; + +const questionsInitResources = [ + { + type: "list", + name: "resource", + message: "Which resource would you create?", + choices: [ + { name: 'Function', value: 'function' }, + { name: 'Collection', value: 'collection' }, + { name: 'Bucket', value: 'bucket' }, + { name: 'Team', value: 'team' }, + { name: 'Topic', value: 'message' } + ] + } +]; + +const questionsPushFunctions = [ { type: "checkbox", name: "functions", - message: "Which functions would you like to deploy?", + message: "Which functions would you like to push?", + validate: (value) => validateRequired('function', value), choices: () => { let functions = localConfig.getFunctions(); checkDeployConditions(localConfig) if (functions.length === 0) { - throw new Error("No functions found in the current directory."); + throw new Error("No functions found in the current directory Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); } let choices = functions.map((func, idx) => { return { @@ -304,17 +623,18 @@ const questionsDeployFunctions = [ }, ] -const questionsDeployCollections = [ +const questionsPushCollections = [ { type: "checkbox", name: "collections", - message: "Which collections would you like to deploy?", + message: "Which collections would you like to push?", + validate: (value) => validateRequired('collection', value), choices: () => { let collections = localConfig.getCollections(); checkDeployConditions(localConfig) if (collections.length === 0) { - throw new Error("No collections found in the current directory. Run `appwrite init collection` to fetch all your collections."); + throw new Error("No collections found in the current directory. Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); } return collections.map(collection => { return { @@ -326,21 +646,22 @@ const questionsDeployCollections = [ }, { type: "input", - name: "override", - message: 'Are you sure you want to override this collection? This can lead to loss of data! Type "YES" to confirm.' - }, + name: "changes", + message: `Would you like to apply these changes? Type "YES" to confirm.` + } ] -const questionsDeployBuckets = [ +const questionsPushBuckets = [ { type: "checkbox", name: "buckets", - message: "Which buckets would you like to deploy?", + message: "Which buckets would you like to push?", + validate: (value) => validateRequired('bucket', value), choices: () => { let buckets = localConfig.getBuckets(); checkDeployConditions(localConfig) if (buckets.length === 0) { - throw new Error("No buckets found in the current directory. Run `appwrite init bucket` to fetch all your buckets."); + throw new Error("No buckets found in the current directory. Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); } return buckets.map(bucket => { return { @@ -349,12 +670,32 @@ const questionsDeployBuckets = [ } }); } + } +] + +const questionsPushMessagingTopics = [ + { + type: "checkbox", + name: "topics", + message: "Which messaging topic would you like to push?", + choices: () => { + let topics = localConfig.getMessagingTopics(); + if (topics.length === 0) { + throw new Error("No topics found in the current directory. Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); + } + return topics.map(topic => { + return { + name: `${topic.name} (${topic['$id']})`, + value: topic.$id + } + }); + } }, { type: "input", name: "override", - message: 'Are you sure you want to override this bucket? This can lead to loss of data! Type "YES" to confirm.' - }, + message: 'Would you like to override existing topics? This can lead to loss of data! Type "YES" to confirm.' + } ] const questionsGetEntrypoint = [ @@ -372,16 +713,17 @@ const questionsGetEntrypoint = [ }, ] -const questionsDeployTeams = [ +const questionsPushTeams = [ { type: "checkbox", name: "teams", - message: "Which teams would you like to deploy?", + message: "Which teams would you like to push?", + validate: (value) => validateRequired('team', value), choices: () => { let teams = localConfig.getTeams(); checkDeployConditions(localConfig); if (teams.length === 0) { - throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams."); + throw new Error("No teams found in the current directory. Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); } return teams.map(team => { return { @@ -391,43 +733,38 @@ const questionsDeployTeams = [ }); } }, - { - type: "input", - name: "override", - message: 'Are you sure you want to override this team? This can lead to loss of data! Type "YES" to confirm.' - }, ]; const questionsListFactors = [ { type: "list", name: "factor", - message: "Your account is protected by multiple factors. Which factor would you like to use to authenticate?", + message: "Your account is protected by multi-factor authentication. Please choose one for verification.", choices: async () => { let client = await sdkForConsole(false); const factors = await accountListMfaFactors({ sdk: client, parseOutput: false }); - + const choices = [ { - name: `TOTP (Time-based One-time Password)`, + name: `Authenticator app (Get a code from a third-party authenticator app)`, value: 'totp' }, { - name: `E-mail`, + name: `Email (Get a security code at your Appwrite email address)`, value: 'email' }, { - name: `Phone (SMS)`, + name: `SMS (Get a security code on your Appwrite phone number)`, value: 'phone' }, { - name: `Recovery code`, + name: `Recovery code (Use one of your recovery codes for verification)`, value: 'recoveryCode' } - ].filter((ch) => factors[ch.value] === true); + ].filter((ch) => factors[ch.value] === true); return choices; } @@ -448,16 +785,51 @@ const questionsMfaChallenge = [ } ]; +const questionsRunFunctions = [ + { + type: "list", + name: "function", + message: "Which function would you like to develop locally?", + validate: (value) => validateRequired('function', value), + choices: () => { + let functions = localConfig.getFunctions(); + if (functions.length === 0) { + throw new Error("No functions found in the current directory. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + } + let choices = functions.map((func, idx) => { + return { + name: `${func.name} (${func.$id})`, + value: func.$id + } + }) + return choices; + } + } +]; + module.exports = { questionsInitProject, + questionsCreateFunction, + questionsCreateFunctionSelectTemplate, + questionsCreateBucket, + questionsCreateCollection, + questionsCreateMessagingTopic, + questionsPullFunctions, questionsLogin, - questionsInitFunction, - questionsInitCollection, - questionsDeployFunctions, - questionsDeployCollections, - questionsDeployBuckets, - questionsDeployTeams, + questionsPullResources, + questionsLogout, + questionsPullCollection, + questionsPushResources, + questionsPushFunctions, + questionsPushCollections, + questionsPushBuckets, + questionsPushMessagingTopics, + questionsPushTeams, questionsGetEntrypoint, questionsListFactors, - questionsMfaChallenge + questionsMfaChallenge, + questionsRunFunctions, + questionGetEndpoint, + questionsInitResources, + questionsCreateTeam }; diff --git a/lib/sdks.js b/lib/sdks.js index fe8afb8..48957b4 100644 --- a/lib/sdks.js +++ b/lib/sdks.js @@ -68,7 +68,7 @@ const sdkForProject = async () => { } if (!project) { - throw new Error("Project is not set. Please run `appwrite init project` to initialize the current directory with an Appwrite project."); + throw new Error("Project is not set. Please run `appwrite init` to initialize the current directory with an Appwrite project."); } client diff --git a/lib/spinner.js b/lib/spinner.js new file mode 100644 index 0000000..2f5b3ad --- /dev/null +++ b/lib/spinner.js @@ -0,0 +1,103 @@ +const progress = require('cli-progress'); +const chalk = require('chalk'); + +const SPINNER_ARC = 'arc'; +const SPINNER_DOTS = 'dots'; + +const spinners = { + [SPINNER_ARC]: { + "interval": 100, + "frames": ["◜", "◠", "◝", "◞", "◡", "◟"] + }, + [SPINNER_DOTS]: { + "interval": 80, + "frames": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] + } +} + +class Spinner { + static start(clearOnComplete = true, hideCursor = true) { + Spinner.updatesBar = new progress.MultiBar({ + format: this.#formatter, + hideCursor, + clearOnComplete, + stopOnComplete: true, + noTTYOutput: true + }); + } + + static stop() { + Spinner.updatesBar.stop(); + } + + static #formatter(options, params, payload) { + const status = payload.status.padEnd(12); + const middle = `${payload.resource} (${payload.id})`.padEnd(40); + + let prefix = chalk.cyan(payload.prefix ?? '⧗'); + let start = chalk.cyan(status); + let end = chalk.yellow(payload.end); + + if (status.toLowerCase().trim() === 'pushed') { + start = chalk.greenBright.bold(status); + prefix = chalk.greenBright.bold('✓'); + end = ''; + } else if (status.toLowerCase().trim() === 'deploying') { + start = chalk.cyanBright.bold(status); + } else if (status.toLowerCase().trim() === 'deployed') { + start = chalk.green.bold(status); + prefix = chalk.green.bold('✓'); + } else if (status.toLowerCase().trim() === 'error') { + start = chalk.red.bold(status); + prefix = chalk.red.bold('✗'); + end = chalk.red(payload.errorMessage); + } + + return Spinner.#line(prefix, start, middle, end); + } + + static #line(prefix, start, middle, end, separator = '•') { + return `${prefix} ${start} ${separator} ${middle} ${!end ? '' : separator} ${end}`; + + } + + constructor(payload, total = 100, startValue = 0) { + this.bar = Spinner.updatesBar.create(total, startValue, payload) + } + + update(payload) { + this.bar.update(payload); + return this; + } + + fail(payload) { + this.stopSpinner(); + this.update({ status: 'Error', ...payload }); + } + + startSpinner(name) { + let spinnerFrame = 1; + const spinner = spinners[name] ?? spinners['dots']; + + this.spinnerInterval = setInterval(() => { + if (spinnerFrame === spinner.frames.length) spinnerFrame = 1; + this.bar.update({ prefix: spinner.frames[spinnerFrame++] }); + }, spinner.interval); + } + + stopSpinner() { + clearInterval(this.spinnerInterval); + } + + replaceSpinner(name) { + this.stopSpinner(); + this.startSpinner(name); + } +} + + +module.exports = { + Spinner, + SPINNER_ARC, + SPINNER_DOTS +} diff --git a/lib/utils.js b/lib/utils.js index bc06aaf..a2cf3e3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,9 +1,13 @@ const fs = require("fs"); const path = require("path"); +const net = require("net"); +const childProcess = require('child_process'); +const { localConfig, globalConfig } = require("./config"); +const { success } = require('./parser') function getAllFiles(folder) { const files = []; - for(const pathDir of fs.readdirSync(folder)) { + for (const pathDir of fs.readdirSync(folder)) { const pathAbsolute = path.join(folder, pathDir); if (fs.statSync(pathAbsolute).isDirectory()) { files.push(...getAllFiles(pathAbsolute)); @@ -14,13 +18,247 @@ function getAllFiles(folder) { return files; } +async function isPortTaken(port) { + const taken = await new Promise((res, rej) => { + const tester = net.createServer() + .once('error', function (err) { + if (err.code != 'EADDRINUSE') return rej(err) + res(true) + }) + .once('listening', function() { + tester.once('close', function() { res(false) }) + .close() + }) + .listen(port); + }); + + return taken; +} + +function systemHasCommand(command) { + const isUsingWindows = process.platform == 'win32' + + try { + if(isUsingWindows) { + childProcess.execSync('where ' + command, { stdio: 'pipe' }) + } else { + childProcess.execSync(`[[ $(${command} --version) ]] || { exit 1; } && echo "OK"`, { stdio: 'pipe', shell: '/bin/bash' }); + } + } catch (error) { + console.log(error); + return false; + } + + return true; +} + const checkDeployConditions = (localConfig) => { if (Object.keys(localConfig.data).length === 0) { - throw new Error("No appwrite.json file found in the current directory. This command must be run in the folder holding your appwrite.json file. Please run this command again in the folder containing your appwrite.json file, or run appwrite init project."); + throw new Error("No appwrite.json file found in the current directory. Please run this command again in the folder containing your appwrite.json file, or run 'appwrite init project' to link current directory to an Appwrite project."); + } +} + +function showConsoleLink(serviceName, action, ...ids) { + const projectId = localConfig.getProject().projectId; + + const url = new URL(globalConfig.getEndpoint().replace('/v1', '/console')); + url.pathname += `/project-${projectId}`; + action = action.toLowerCase(); + + switch (serviceName) { + case "account": + url.pathname = url.pathname.replace(`/project-${projectId}`, ''); + url.pathname += getAccountPath(action); + break; + case "databases": + url.pathname += getDatabasePath(action, ids); + break; + case "functions": + url.pathname += getFunctionsPath(action, ids); + break; + case "messaging": + url.pathname += getMessagingPath(action, ids); + break; + case "projects": + url.pathname = url.pathname.replace(`/project-${projectId}`, ''); + url.pathname += getProjectsPath(action, ids); + break; + case "storage": + url.pathname += getBucketsPath(action, ids); + break; + case "teams": + url.pathname += getTeamsPath(action, ids); + break; + case "users": + url.pathname += getUsersPath(action, ids); + break; + default: + return; + } + + + success(url); +} + +function getAccountPath(action) { + let path = '/account'; + + if (action === 'listsessions') { + path += '/sessions'; + } + + return path; +} + +function getDatabasePath(action, ids) { + let path = '/databases'; + + + if (['get', 'listcollections', 'getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes', 'getdatabaseusage'].includes(action)) { + path += `/database-${ids[0]}`; + } + + if (action === 'getdatabaseusage') { + path += `/usage`; + } + + if (['getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes'].includes(action)) { + path += `/collection-${ids[1]}`; + } + + if (action === 'listattributes') { + path += '/attributes'; + } + if (action === 'listindexes') { + path += '/indexes'; + } + if (action === 'getdocument') { + path += `/document-${ids[2]}`; + } + + + return path; +} + +function getFunctionsPath(action, ids) { + let path = '/functions'; + + if (action !== 'list') { + path += `/function-${ids[0]}`; + } + + if (action === 'getdeployment') { + path += `/deployment-${ids[1]}` + } + + if (action === 'getexecution' || action === 'listexecution') { + path += `/executions` + } + if (action === 'getfunctionusage') { + path += `/usage` + } + + return path; +} + +function getMessagingPath(action, ids) { + let path = '/messaging'; + + if (['getmessage', 'listmessagelogs'].includes(action)) { + path += `/message-${ids[0]}`; + } + + if (['listproviders', 'getprovider'].includes(action)) { + path += `/providers`; + } + + if (action === 'getprovider') { + path += `/provider-${ids[0]}`; + } + + if (['listtopics', 'gettopic'].includes(action)) { + path += `/topics`; + } + + if (action === 'gettopic') { + path += `/topic-${ids[0]}`; } + + return path; +} + +function getProjectsPath(action, ids) { + let path = ''; + + if (action !== 'list') { + path += `/project-${ids[0]}`; + } + + if (['listkeys', 'getkey'].includes(action)) { + path += '/overview/keys' + } + + if (['listplatforms', 'getplatform'].includes(action)) { + path += '/overview/platforms' + } + + if (['listwebhooks', 'getwebhook'].includes(action)) { + path += '/settings/webhooks' + } + + if (['getplatform', 'getkey', 'getwebhook'].includes(action)) { + path += `/${ids[1]}`; + } + + return path; +} + +function getBucketsPath(action, ids) { + let path = '/storage'; + + if (action !== 'listbuckets') { + path += `/bucket-${ids[0]}`; + } + + if (action === 'getbucketusage') { + path += `/usage` + } + + if (action === 'getfile') { + path += `/file-${ids[1]}` + } + + return path; +} + +function getTeamsPath(action, ids) { + let path = '/auth/teams'; + + if (action !== 'list') { + path += `/team-${ids[0]}`; + } + + return path; +} + +function getUsersPath(action, ids) { + let path = '/auth'; + + if (action !== 'list') { + path += `/user-${ids[0]}`; + } + + if (action === 'listsessions') { + path += 'sessions'; + } + + return path; } module.exports = { getAllFiles, - checkDeployConditions -}; \ No newline at end of file + isPortTaken, + systemHasCommand, + checkDeployConditions, + showConsoleLink +}; diff --git a/lib/validations.js b/lib/validations.js new file mode 100644 index 0000000..bfae5ba --- /dev/null +++ b/lib/validations.js @@ -0,0 +1,17 @@ +const validateRequired = (resource, value) => { + if (Array.isArray(value)) { + if (value.length <= 0) { + return `Please select at least one ${resource}`; + } + } else { + if (value === undefined || value === null || value === 0 || (typeof value === "string" && value.trim() === '')) { + return `${resource} is required`; + } + } + + return true; +} + +module.exports = { + validateRequired +} diff --git a/package.json b/package.json index 7a87f62..ec468d1 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,17 @@ "dependencies": { "undici": "^5.28.2", "chalk": "4.1.2", + "cli-progress": "^3.12.0", "cli-table3": "^0.6.2", "commander": "^9.2.0", "form-data": "^4.0.0", "json-bigint": "^1.0.0", "inquirer": "^8.2.4", + "inquirer-search-list": "^1.2.6", "tar": "^6.1.11", - "ignore": "^5.2.0" + "ignore": "^5.2.0", + "chokidar": "^3.6.0", + "tail": "^2.2.6" }, "devDependencies": { "pkg": "5.8.1" From 7650f48315dcc93b83177efa2d5f7a3fc26e33be Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 3 Jul 2024 18:35:43 +0200 Subject: [PATCH 02/18] chore: bump version --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 883bc89..eb351d6 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -5.0.5 +6.0.0-rc.1 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -5.0.5 +6.0.0-rc.1 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index 14ad4a8..b33caae 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/5.0.5/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/5.0.5/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index b870292..668926b 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="5.0.5" + GITHUB_LATEST_VERSION="6.0.0-rc.1" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 81e827f..19d06aa 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '5.0.5', - 'user-agent' : `AppwriteCLI/5.0.5 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.1', + 'user-agent' : `AppwriteCLI/6.0.0-rc.1 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } diff --git a/lib/parser.js b/lib/parser.js index 8c64db2..31e6850 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -131,7 +131,7 @@ const parseError = (err) => { } catch { } - const version = '5.0.5'; + const version = '6.0.0-rc.1'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index ec468d1..c293b91 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "5.0.5", + "version": "6.0.0-rc.1", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 1289e25..918f944 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "5.0.5", + "version": "6.0.0-rc.1", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/5.0.5/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/5.0.5/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From c99bde3d4a6d7beebaa029da12428d44f8e40569 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 8 Jul 2024 20:59:45 +0200 Subject: [PATCH 03/18] fix: qa --- README.md | 4 +- index.js | 3 +- install.ps1 | 4 +- install.sh | 2 +- lib/client.js | 4 +- lib/commands/generic.js | 22 ++++- lib/commands/init.js | 41 +++++--- lib/commands/pull.js | 190 ++++++++++++++++++++++++------------- lib/commands/push.js | 205 +++++++++++++--------------------------- lib/commands/run.js | 72 +++++++------- lib/config.js | 72 ++++++++++---- lib/emulation/docker.js | 100 +++++++++++++------- lib/emulation/utils.js | 11 ++- lib/parser.js | 22 +++-- lib/questions.js | 68 +++++++++---- lib/sdks.js | 38 -------- package.json | 2 +- scoop/appwrite.json | 6 +- 18 files changed, 465 insertions(+), 401 deletions(-) diff --git a/README.md b/README.md index eb351d6..0841ddc 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.1 +6.0.0-rc.2 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.1 +6.0.0-rc.2 ``` ## Getting Started diff --git a/index.js b/index.js index a1db573..58b9dcd 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ const { login, logout, whoami, migrate, register } = require("./lib/commands/gen const { init } = require("./lib/commands/init"); const { pull } = require("./lib/commands/pull"); const { run } = require("./lib/commands/run"); -const { push } = require("./lib/commands/push"); +const { push, deploy } = require("./lib/commands/push"); const { account } = require("./lib/commands/account"); const { avatars } = require("./lib/commands/avatars"); const { assistant } = require("./lib/commands/assistant"); @@ -77,6 +77,7 @@ program .addCommand(init) .addCommand(pull) .addCommand(push) + .addCommand(deploy) .addCommand(run) .addCommand(logout) .addCommand(account) diff --git a/install.ps1 b/install.ps1 index b33caae..f6a9445 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 668926b..7d41d28 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.1" + GITHUB_LATEST_VERSION="6.0.0-rc.2" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 19d06aa..050c65e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.1', - 'user-agent' : `AppwriteCLI/6.0.0-rc.1 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.2', + 'user-agent' : `AppwriteCLI/6.0.0-rc.2 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } diff --git a/lib/commands/generic.js b/lib/commands/generic.js index c6b1a4c..bc913fe 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -3,7 +3,7 @@ const { Command } = require("commander"); const Client = require("../client"); const { sdkForConsole } = require("../sdks"); const { globalConfig, localConfig } = require("../config"); -const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable, cliConfig } = require("../parser"); +const { actionRunner, success, parseBool, commandDescriptions, error, parse, hint, log, drawTable, cliConfig } = require("../parser"); const ID = require("../id"); const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions"); const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); @@ -14,8 +14,20 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => { const oldCurrent = globalConfig.getCurrentSession(); let configEndpoint = endpoint ?? DEFAULT_ENDPOINT; + if(globalConfig.getCurrentSession() !== '') { + log('You are currently signed in as ' + globalConfig.getEmail()); + + if(globalConfig.getSessions().length === 1) { + hint('You can sign in and manage multiple accounts with Appwrite CLI'); + } + } + const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin); + if(!answers.method) { + answers.method = 'login'; + } + if (answers.method === 'select') { const accountId = answers.accountId; @@ -87,15 +99,15 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => { } } - success("Signed in as user with ID: " + account.$id); - log("Next you can create or link to your project using 'appwrite init project'"); + success("Successfully signed in as " + account.email); + hint("Next you can create or link to your project using 'appwrite init project'"); }; const whoami = new Command("whoami") .description(commandDescriptions['whoami']) .action(actionRunner(async () => { if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { - error("No user is signed in. To sign in, run: appwrite login "); + error("No user is signed in. To sign in, run 'appwrite login'"); return; } @@ -109,7 +121,7 @@ const whoami = new Command("whoami") parseOutput: false }); } catch (error) { - error("No user is signed in. To sign in, run: appwrite login"); + error("No user is signed in. To sign in, run 'appwrite login'"); return; } diff --git a/lib/commands/init.js b/lib/commands/init.js index ebd74e8..9cbe03b 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -9,6 +9,7 @@ const { storageCreateBucket } = require("./storage"); const { messagingCreateTopic } = require("./messaging"); const { functionsCreate } = require("./functions"); const { databasesCreateCollection } = require("./databases"); +const { pullResources } = require("./pull"); const ID = require("../id"); const { localConfig, globalConfig } = require("../config"); const { @@ -18,10 +19,11 @@ const { questionsCreateMessagingTopic, questionsCreateCollection, questionsInitProject, + questionsInitProjectAutopull, questionsInitResources, questionsCreateTeam } = require("../questions"); -const { success, log, error, actionRunner, commandDescriptions } = require("../parser"); +const { cliConfig, success, log, hint, error, actionRunner, commandDescriptions } = require("../parser"); const { accountGet } = require("./account"); const { sdkForConsole } = require("../sdks"); @@ -56,7 +58,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => { sdk: client }); } catch (e) { - error('Error Session not found. Please run `appwrite login` to create a session'); + error("Error Session not found. Please run 'appwrite login' to create a session"); process.exit(1); } @@ -104,11 +106,17 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => { success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`); - log("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwite push' to synchronize your project.") - if(answers.start === 'existing') { - log("Since you connected to an existing project, we highly recommend to run 'appwrite pull all' to synchronize all of your existing resources."); + answers = await inquirer.prompt(questionsInitProjectAutopull); + if(answers.autopull) { + cliConfig.all = true; + await pullResources(); + } else { + log("You can run 'appwrite pull all' to synchronize all of your existing resources."); + } } + + hint("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwrite push' to synchronize your project.") } const initBucket = async () => { @@ -210,22 +218,24 @@ const initFunction = async () => { log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`); } - fs.mkdirSync(functionDir, "777"); fs.mkdirSync(templatesDir, "777"); const repo = "https://github.com/appwrite/templates"; const api = `https://api.github.com/repos/appwrite/templates/contents/${answers.runtime.name}` - const templates = ['starter']; let selected = undefined; - try { - const res = await fetch(api); - templates.push(...(await res.json()).map((template) => template.name)); - - selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates)) - } catch { - // Not a problem will go with directory pulling - log('Loading templates...'); + if(answers.template === 'starter') { + selected = { template: 'starter' }; + } else { + try { + const res = await fetch(api); + const templates = []; + templates.push(...(await res.json()).map((template) => template.name)); + selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates)); + } catch { + // Not a problem will go with directory pulling + log('Loading templates...'); + } } const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase(); @@ -257,6 +267,7 @@ const initFunction = async () => { fs.rmSync(path.join(templatesDir, ".git"), { recursive: true }); if (!selected) { + const templates = []; templates.push(...fs.readdirSync(runtimeDir, { withFileTypes: true }) .filter(item => item.isDirectory() && item.name !== 'starter') .map(dirent => dirent.name)); diff --git a/lib/commands/pull.js b/lib/commands/pull.js index cea0331..5063e51 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -1,4 +1,5 @@ const fs = require("fs"); +const chalk = require('chalk'); const tar = require("tar"); const { Command } = require("commander"); const inquirer = require("inquirer"); @@ -11,11 +12,11 @@ const { storageListBuckets } = require("./storage"); const { localConfig } = require("../config"); const { paginate } = require("../paginate"); const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions"); -const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser"); +const { cliConfig, success, log, warn, actionRunner, commandDescriptions } = require("../parser"); const pullResources = async () => { const actions = { - project: pullProject, + settings: pullSettings, functions: pullFunctions, collections: pullCollection, buckets: pullBucket, @@ -25,6 +26,7 @@ const pullResources = async () => { if (cliConfig.all) { for (let action of Object.values(actions)) { + cliConfig.all = true; await action(); } } else { @@ -37,75 +39,94 @@ const pullResources = async () => { } }; -const pullProject = async () => { +const pullSettings = async () => { + log("Pulling project settings ..."); + try { let response = await projectsGet({ parseOutput: false, projectId: localConfig.getProject().projectId - - }) + }); localConfig.setProject(response.$id, response.name, response); - success(); + success(`Successfully pulled ${chalk.bold('all')} project settings.`); } catch (e) { throw e; } } const pullFunctions = async () => { - const localFunctions = localConfig.getFunctions(); + log("Fetching functions ..."); + let total = 0; + + const fetchResponse = await functionsList({ + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + if (fetchResponse["functions"].length <= 0) { + log("No functions found."); + success(`Successfully pulled ${chalk.bold(total)} functions.`); + return; + } const functions = cliConfig.all ? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions : (await inquirer.prompt(questionsPullFunctions)).functions; - log(`Pulling ${functions.length} functions`); - for (let func of functions) { - const functionExistLocally = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']) !== undefined; + total++; + log(`Pulling function ${chalk.bold(func['name'])} ...`); - if (functionExistLocally) { - localConfig.updateFunction(func['$id'], func); - } else { - func['path'] = `functions/${func['$id']}`; - localConfig.addFunction(func); - localFunctions.push(func); + const localFunction = localConfig.getFunction(func.$id); + if(!localFunction['path']) { + func['path'] = `functions/${func.$id}`; } - const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']); + localConfig.addFunction(func); - if (localFunction['deployment'] === '') { - continue + if (!fs.existsSync(func['path'])) { + fs.mkdirSync(func['path'], { recursive: true }); } - const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` + if(func['deployment']) { + const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` + await functionsDownloadDeployment({ + functionId: func['$id'], + deploymentId: func['deployment'], + destination: compressedFileName, + overrideForCli: true, + parseOutput: false + }); - await functionsDownloadDeployment({ - functionId: func['$id'], - deploymentId: func['deployment'], - destination: compressedFileName, - overrideForCli: true, - parseOutput: false - }) + tar.extract({ + sync: true, + cwd: func['path'], + file: compressedFileName, + strict: false, + }); - if (!fs.existsSync(localFunction['path'])) { - fs.mkdirSync(localFunction['path'], { recursive: true }); + fs.rmSync(compressedFileName); } - - tar.extract({ - sync: true, - cwd: localFunction['path'], - file: compressedFileName, - strict: false, - }); - - fs.rmSync(compressedFileName); - success(`Pulled ${func['name']} code and settings`) } + + success(`Successfully pulled ${chalk.bold(total)} functions.`); } const pullCollection = async () => { + log("Fetching collections ..."); + let total = 0; + + const fetchResponse = await databasesList({ + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + if (fetchResponse["databases"].length <= 0) { + log("No collections found."); + success(`Successfully pulled ${chalk.bold(total)} collections.`); + return; + } + let databases = cliConfig.ids; if (databases.length === 0) { @@ -122,61 +143,101 @@ const pullCollection = async () => { parseOutput: false }); + total++; + log(`Pulling all collections from ${chalk.bold(database['name'])} database ...`); + localConfig.addDatabase(database); - const { collections, total } = await paginate(databasesListCollections, { + const { collections } = await paginate(databasesListCollections, { databaseId, parseOutput: false }, 100, 'collections'); - log(`Found ${total} collections`); - - collections.map(async collection => { - log(`Fetching ${collection.name} ...`); + for(const collection of collections) { localConfig.addCollection({ ...collection, '$createdAt': undefined, '$updatedAt': undefined }); - }); + } } - success(); + success(`Successfully pulled ${chalk.bold(total)} collections.`); } const pullBucket = async () => { - const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); + log("Fetching buckets ..."); + let total = 0; - log(`Found ${buckets.length} buckets`); + const fetchResponse = await storageListBuckets({ + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + if (fetchResponse["buckets"].length <= 0) { + log("No buckets found."); + success(`Successfully pulled ${chalk.bold(total)} buckets.`); + return; + } - buckets.forEach(bucket => localConfig.addBucket(bucket)); + const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); - success(); + for(const bucket of buckets) { + total++; + log(`Pulling bucket ${chalk.bold(bucket['name'])} ...`); + localConfig.addBucket(bucket); + } + + success(`Successfully pulled ${chalk.bold(total)} buckets.`); } const pullTeam = async () => { - const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams'); - - log(`Found ${teams.length} teams`); + log("Fetching teams ..."); + let total = 0; - teams.forEach(team => { - const { total, $updatedAt, $createdAt, prefs, ...rest } = team; - localConfig.addTeam(rest); + const fetchResponse = await teamsList({ + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false }); + if (fetchResponse["teams"].length <= 0) { + log("No teams found."); + success(`Successfully pulled ${chalk.bold(total)} teams.`); + return; + } - success(); + const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams'); + + for(const team of teams) { + total++; + log(`Pulling team ${chalk.bold(team['name'])} ...`); + localConfig.addTeam(team); + } + + success(`Successfully pulled ${chalk.bold(total)} teams.`); } const pullMessagingTopic = async () => { - const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics'); + log("Fetching topics ..."); + let total = 0; + + const fetchResponse = await messagingListTopics({ + queries: [JSON.stringify({ method: 'limit', values: [1] })], + parseOutput: false + }); + if (fetchResponse["topics"].length <= 0) { + log("No topics found."); + success(`Successfully pulled ${chalk.bold(total)} topics.`); + return; + } - log(`Found ${topics.length} topics`); + const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics'); - topics.forEach(topic => { + for(const topic of topics) { + total++; + log(`Pulling topic ${chalk.bold(topic['name'])} ...`); localConfig.addMessagingTopic(topic); - }); + } - success(); + success(`Successfully pulled ${chalk.bold(total)} topics.`); } const pull = new Command("pull") @@ -192,9 +253,9 @@ pull })); pull - .command("project") + .command("settings") .description("Pull your Appwrite project name, services and auth settings") - .action(actionRunner(pullProject)); + .action(actionRunner(pullSettings)); pull .command("function") @@ -228,4 +289,5 @@ pull module.exports = { pull, + pullResources }; diff --git a/lib/commands/push.js b/lib/commands/push.js index 1349b73..949b299 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -6,7 +6,7 @@ const { localConfig, globalConfig } = require("../config"); const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner'); const { paginate } = require('../paginate'); const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); -const { cliConfig, actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser"); +const { cliConfig, actionRunner, success, warn, log, error, commandDescriptions, drawTable } = require("../parser"); const { proxyListRules } = require('./proxy'); const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); const { @@ -714,7 +714,7 @@ const createAttributes = async (attributes, collection) => { const pushResources = async () => { const actions = { - project: pushProject, + settings: pushSettings, functions: pushFunction, collections: pushCollection, buckets: pushBucket, @@ -736,15 +736,16 @@ const pushResources = async () => { } }; -const pushProject = async () => { +const pushSettings = async () => { try { + log("Pushing project settings ..."); + const projectId = localConfig.getProject().projectId; const projectName = localConfig.getProject().projectName; const settings = localConfig.getProject().projectSettings ?? {}; - log(`Updating project ${projectId}`); - if (projectName) { + log("Applying project name ..."); await projectsUpdate({ projectId, name: projectName, @@ -753,7 +754,7 @@ const pushProject = async () => { } if (settings.services) { - log('Updating service statuses'); + log("Applying service statuses ..."); for (let [service, status] of Object.entries(settings.services)) { await projectsUpdateServiceStatus({ projectId, @@ -766,7 +767,7 @@ const pushProject = async () => { if (settings.auth) { if (settings.auth.security) { - log('Updating auth security settings'); + log("Applying auth security settings ..."); await projectsUpdateAuthDuration({ projectId, duration: settings.auth.security.duration, parseOutput: false }); await projectsUpdateAuthLimit({ projectId, limit: settings.auth.security.limit, parseOutput: false }); await projectsUpdateAuthSessionsLimit({ projectId, limit: settings.auth.security.sessionsLimit, parseOutput: false }); @@ -776,7 +777,7 @@ const pushProject = async () => { } if (settings.auth.methods) { - log('Updating auth login methods'); + log("Applying auth methods statuses ..."); for (let [method, status] of Object.entries(settings.auth.methods)) { await projectsUpdateAuthStatus({ @@ -789,7 +790,7 @@ const pushProject = async () => { } } - success("Project configuration updated."); + success(`Successfully pushed ${chalk.bold('all')} project settings.`); } catch (e) { throw e; } @@ -806,11 +807,9 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero checkDeployConditions(localConfig); const functions = localConfig.getFunctions(); if (functions.length === 0) { - if (returnOnZero) { - log('No functions found, skipping'); - return; - } - throw new Error("No functions found in the current directory. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + log("No functions found."); + hint("Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + return; } functionIds.push(...functions.map((func) => { return func.$id; @@ -833,45 +832,19 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero return func; }); - log('Validating functions'); + log('Validating functions ...'); // Validation is done BEFORE pushing so the deployment process can be run in async with progress update for (let func of functions) { if (!func.entrypoint) { - log(`Function ${func.name} does not have an endpoint`); + log(`Function ${func.name} is missing an entrypoint.`); const answers = await inquirer.prompt(questionsGetEntrypoint) func.entrypoint = answers.entrypoint; - localConfig.updateFunction(func['$id'], func); - } - - if (func.variables) { - func.pushVariables = cliConfig.force; - - try { - const { total } = await functionsListVariables({ - functionId: func['$id'], - queries: [JSON.stringify({ method: 'limit', values: [1] })], - parseOutput: false - }); - - if (total === 0) { - func.pushVariables = true; - } else if (total > 0 && !func.pushVariables) { - log(`The function ${func.name} has remote variables setup`); - const variableAnswers = await inquirer.prompt(questionsPushFunctions[1]) - func.pushVariables = variableAnswers.override.toLowerCase() === "yes"; - } - } catch (e) { - if (e.code != 404) { - throw e.message; - } - } + localConfig.addFunction(func); } } - - log('All functions are validated'); - log('Pushing functions\n'); + log('Pushing functions ...'); Spinner.start(false); let successfullyPushed = 0; @@ -934,7 +907,7 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero try { response = await functionsCreate({ - functionId: func.$id || 'unique()', + functionId: func.$id, name: func.name, runtime: func.runtime, execute: func.execute, @@ -949,10 +922,6 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero parseOutput: false }); - localConfig.updateFunction(func['$id'], { - "$id": response['$id'], - }); - func["$id"] = response['$id']; updaterRow.update({ status: 'Created' }); } catch (e) { updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' }); @@ -960,43 +929,6 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } } - if (func.variables) { - if (!func.pushVariables) { - updaterRow.update({ end: 'Skipping variables' }); - } else { - updaterRow.update({ end: 'Pushing variables' }); - - const { variables } = await paginate(functionsListVariables, { - functionId: func['$id'], - parseOutput: false - }, 100, 'variables'); - - await Promise.all(variables.map(async variable => { - await functionsDeleteVariable({ - functionId: func['$id'], - variableId: variable['$id'], - parseOutput: false - }); - })); - - let result = await awaitPools.wipeVariables(func['$id']); - if (!result) { - updaterRow.fail({ errorMessage: 'Variable deletion timed out' }) - return; - } - - // Push local variables - await Promise.all(Object.keys(func.variables).map(async localVariableKey => { - await functionsCreateVariable({ - functionId: func['$id'], - key: localVariableKey, - value: func.variables[localVariableKey], - parseOutput: false - }); - })); - } - } - try { updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC); response = await functionsCreateDeployment({ @@ -1082,27 +1014,25 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero })); Spinner.stop(); - console.log('\n'); failedDeployments.forEach((failed) => { const { name, deployment, $id } = failed; const failUrl = `${globalConfig.getEndpoint().replace('/v1', '')}/console/project-${localConfig.getProject().projectId}/functions/function-${$id}/deployment-${deployment}`; error(`Deployment of ${name} has failed. Check at ${failUrl} for more details\n`); - }) - - let message = chalk.green(`Pushed and deployed ${successfullyPushed} functions`); + }); if (!async) { - if (successfullyDeployed < successfullyPushed) { - message = `${chalk.green(`Pushed and deployed ${successfullyPushed} functions.`)} ${chalk.red(`${successfullyPushed - successfullyDeployed} failed to deploy`)}`; + if(successfullyPushed === 0) { + error('No functions were pushed.'); + } else if(successfullyDeployed != successfullyPushed) { + warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} functions`) } else { - if (successfullyPushed === 0) { - message = chalk.red(`Error pushing ${functions.length} functions`) - } + success(`Successfully pushed ${successfullyPushed} functions.`); } + } else { + success(`Successfully pushed ${successfullyPushed} functions.`); } - log(message); } const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { @@ -1111,12 +1041,9 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { if (cliConfig.all) { checkDeployConditions(localConfig); if (localConfig.getCollections().length === 0) { - if (returnOnZero) { - log('No collections found, skipping'); - return; - } - - throw new Error("No collections found in the current directory. Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); + log("No collections found."); + hint("Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); + return; } collections.push(...localConfig.getCollections()); } else { @@ -1131,7 +1058,8 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { }) } const databases = Array.from(new Set(collections.map(collection => collection['databaseId']))); - log('Checking for databases and collection changes'); + + log('Checking for changes ...'); // Parallel db actions await Promise.all(databases.map(async (databaseId) => { @@ -1153,7 +1081,7 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { success(`Updated ${localDatabase.name} ( ${databaseId} ) name`); } } catch (err) { - log(`Database ${databaseId} not found. Creating it now...`); + log(`Database ${databaseId} not found. Creating it now ...`); await databasesCreate({ databaseId: databaseId, @@ -1243,11 +1171,9 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { if (cliConfig.all) { checkDeployConditions(localConfig); if (configBuckets.length === 0) { - if (returnOnZero) { - log('No buckets found, skipping'); - return; - } - throw new Error("No buckets found in the current directory. Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); + log("No buckets found."); + hint("Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); + return; } bucketIds.push(...configBuckets.map((b) => b.$id)); } @@ -1264,8 +1190,10 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { buckets.push(...idBuckets); } + log('Pushing buckets ...'); + for (let bucket of buckets) { - log(`Pushing bucket ${bucket.name} ( ${bucket['$id']} )`) + log(`Pushing bucket ${chalk.bold(bucket['name'])} ...`); try { response = await storageGetBucket({ @@ -1273,8 +1201,6 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { parseOutput: false, }) - log(`Updating bucket ...`) - await storageUpdateBucket({ bucketId: bucket['$id'], name: bucket.name, @@ -1288,8 +1214,6 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { compression: bucket.compression, parseOutput: false }); - - success(`Pushed ${bucket.name} ( ${bucket['$id']} )`); } catch (e) { if (Number(e.code) === 404) { log(`Bucket ${bucket.name} does not exist in the project. Creating ... `); @@ -1307,13 +1231,13 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { antivirus: bucket.antivirus, parseOutput: false }) - - success(`Pushed ${bucket.name} ( ${bucket['$id']} )`); } else { throw e; } } } + + success(`Successfully pushed ${buckets.length} buckets.`); } const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { @@ -1325,11 +1249,8 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { if (cliConfig.all) { checkDeployConditions(localConfig); if (configTeams.length === 0) { - if (returnOnZero) { - log('No teams found, skipping'); - return; - } - throw new Error("No teams found in the current directory. Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); + log("No teams found."); + hint("Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); } teamIds.push(...configTeams.map((t) => t.$id)); } @@ -1346,8 +1267,10 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { teams.push(...idTeams); } + log('Pushing teams ...'); + for (let team of teams) { - log(`Pushing team ${team.name} ( ${team['$id']} )`) + log(`Pushing team ${chalk.bold(team['name'])} ...`); try { response = await teamsGet({ @@ -1355,15 +1278,11 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { parseOutput: false, }) - log(`Updating team ...`) - await teamsUpdateName({ teamId: team['$id'], name: team.name, parseOutput: false }); - - success(`Pushed ${team.name} ( ${team['$id']} )`); } catch (e) { if (Number(e.code) === 404) { log(`Team ${team.name} does not exist in the project. Creating ... `); @@ -1373,13 +1292,13 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { name: team.name, parseOutput: false }) - - success(`Pushed ${team.name} ( ${team['$id']} )`); } else { throw e; } } } + + success(`Successfully pushed ${teams.length} teams.`); } const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => { @@ -1392,11 +1311,8 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => if (cliConfig.all) { checkDeployConditions(localConfig); if (configTopics.length === 0) { - if (returnOnZero) { - log('No topics found, skipping'); - return; - } - throw new Error("No topics found in the current directory. Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); + log("No topics found."); + hint("Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); } topicsIds.push(...configTopics.map((b) => b.$id)); } @@ -1420,8 +1336,10 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => } } + log('Pushing topics ...'); + for (let topic of topics) { - log(`Pushing topic ${topic.name} ( ${topic['$id']} )`) + log(`Pushing topic ${chalk.bold(topic['name'])} ...`); try { response = await messagingGetTopic({ @@ -1435,16 +1353,12 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => continue; } - log(`Updating Topic ...`) - await messagingUpdateTopic({ topicId: topic['$id'], name: topic.name, subscribe: topic.subscribe, parseOutput: false }); - - success(`Pushed ${topic.name} ( ${topic['$id']} )`); } catch (e) { if (Number(e.code) === 404) { log(`Topic ${topic.name} does not exist in the project. Creating ... `); @@ -1462,6 +1376,8 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => } } } + + success(`Successfully pushed ${topics.length} topics.`); } const push = new Command("push") @@ -1477,9 +1393,9 @@ push })); push - .command("project") + .command("settings") .description("Push project name, services and auth settings") - .action(actionRunner(pushProject)); + .action(actionRunner(pushSettings)); push .command("function") @@ -1513,6 +1429,13 @@ push .description("Push messaging topics in the current project.") .action(actionRunner(pushMessagingTopic)); +const deploy = new Command("deploy") + .description(commandDescriptions['push']) + .action(actionRunner(async () => { + warn("Did you mean to run 'appwrite push' command?"); + })); + module.exports = { - push + push, + deploy } diff --git a/lib/commands/run.js b/lib/commands/run.js index 5d05e21..425e6d6 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -1,10 +1,8 @@ const Tail = require('tail').Tail; -const EventEmitter = require('node:events'); +const chalk = require('chalk'); const ignore = require("ignore"); const tar = require("tar"); const fs = require("fs"); -const ID = require("../id"); -const childProcess = require('child_process'); const chokidar = require('chokidar'); const inquirer = require("inquirer"); const path = require("path"); @@ -12,13 +10,11 @@ const { Command } = require("commander"); const { localConfig, globalConfig } = require("../config"); const { paginate } = require('../paginate'); const { functionsListVariables } = require('./functions'); -const { usersGet, usersCreateJWT } = require('./users'); -const { projectsCreateJWT } = require('./projects'); const { questionsRunFunctions } = require("../questions"); -const { actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser"); +const { actionRunner, success, log, warn, error, hint, commandDescriptions, drawTable } = require("../parser"); const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils'); -const { openRuntimesVersion, runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils'); -const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull, dockerStopActive } = require('../emulation/docker'); +const { runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils'); +const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull } = require('../emulation/docker'); const runFunction = async ({ port, functionId, noVariables, noReload, userId } = {}) => { // Selection @@ -68,7 +64,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = } if(!portFound) { - error('Could not find an available port. Please select a port with `appwrite run --port YOUR_PORT` command.'); + error("Could not find an available port. Please select a port with 'appwrite run --port YOUR_PORT' command."); return; } } @@ -86,9 +82,9 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = commands: func.commands, }; - log("Local function configuration:"); drawTable([settings]); - log('If you wish to change your local settings, update the appwrite.json file and rerun the `appwrite run` command.'); + log("If you wish to change your local settings, update the appwrite.json file and rerun the 'appwrite run' command."); + hint("Permissions, events, CRON and timeouts dont apply when running locally."); await dockerCleanup(); @@ -116,22 +112,17 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = const variables = {}; if(!noVariables) { - if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { - error("No user is signed in. To sign in, run: appwrite login. Function will run locally, but will not have your function's environment variables set."); - } else { - try { - const { variables: remoteVariables } = await paginate(functionsListVariables, { - functionId: func['$id'], - parseOutput: false - }, 100, 'variables'); - - remoteVariables.forEach((v) => { - variables[v.key] = v.value; - }); - } catch(err) { - log("Could not fetch remote variables: " + err.message); - log("Function will run locally, but will not have your function's environment variables set."); - } + try { + const { variables: remoteVariables } = await paginate(functionsListVariables, { + functionId: func['$id'], + parseOutput: false + }, 100, 'variables'); + + remoteVariables.forEach((v) => { + variables[v.key] = v.value; + }); + } catch(err) { + warn("Remote variables not fetched. Production environment variables will not be avaiable. Reason: " + err.message); } } @@ -143,7 +134,11 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = variables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? ''; variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime; - await JwtManager.setup(userId); + try { + await JwtManager.setup(userId); + } catch(err) { + warn("Dynamic API key not generated. Header x-appwrite-key will not be set. Reason: " + err.message); + } const headers = {}; headers['x-appwrite-key'] = JwtManager.functionJwt ?? ''; @@ -155,13 +150,17 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = await dockerPull(func); await dockerBuild(func, variables); + + log('Starting function using Docker ...'); + hint('Function automatically restarts when you edit your code.'); + await dockerStart(func, variables, port); new Tail(logsPath).on("line", function(data) { - console.log(data); + process.stdout.write(chalk.blackBright(`${data}\n`)); }); new Tail(errorsPath).on("line", function(data) { - console.log(data); + process.stdout.write(chalk.blackBright(`${data}\n`)); }); if(!noReload) { @@ -177,23 +176,16 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = Queue.events.on('reload', async ({ files }) => { Queue.lock(); - log('Live-reloading due to file changes: '); - for(const file of files) { - log(`- ${file}`); - } - try { - log('Stopping the function ...'); - - await dockerStopActive(); + await dockerStop(func.$id); const dependencyFile = files.find((filePath) => tool.dependencyFiles.includes(filePath)); if(tool.isCompiled || dependencyFile) { - log(`Rebuilding the function due to cange in ${dependencyFile} ...`); + log(`Rebuilding the function ...`); await dockerBuild(func, variables); await dockerStart(func, variables, port); } else { - log('Hot-swapping function files ...'); + log('Hot-swapping function.. Files with change are ' + files.join(', ')); const functionPath = path.join(process.cwd(), func.path); const hotSwapPath = path.join(functionPath, '.appwrite/hot-swap'); diff --git a/lib/config.js b/lib/config.js index ca66b52..af4c95d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,6 +4,38 @@ const _path = require("path"); const process = require("process"); const JSONbig = require("json-bigint")({ storeAsString: false }); +const KeysFunction = ["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"]; +const KeysDatabase = ["$id", "name", "enabled"]; +const KeysCollection = ["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]; +const KeysStorage = ["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]; +const KeyTopics = ["$id", "name", "subscribe"]; +const KeyAttributes = ["key", "type", "required", "array", "size", "default"]; +const KeyIndexes = ["key", "type", "status", "attributes", "orders"]; + +function whitelistKeys(value, keys, nestedKeys = []) { + if(Array.isArray(value)) { + const newValue = []; + + for(const item of value) { + newValue.push(whitelistKeys(item, keys, nestedKeys)); + } + + return newValue; + } + + const newValue = {}; + Object.keys(value).forEach((key) => { + if(keys.includes(key)) { + if(nestedKeys[key]) { + newValue[key] = whitelistKeys(value[key], nestedKeys[key]); + } else { + newValue[key] = value[key]; + } + } + }); + return newValue; +} + class Config { constructor(path) { this.path = path; @@ -94,6 +126,8 @@ class Local extends Config { } addFunction(props) { + props = whitelistKeys(props, KeysFunction); + if (!this.has("functions")) { this.set("functions", []); } @@ -101,21 +135,6 @@ class Local extends Config { let functions = this.get("functions"); for (let i = 0; i < functions.length; i++) { if (functions[i]['$id'] == props['$id']) { - return; - } - } - functions.push(props); - this.set("functions", functions); - } - - updateFunction(id, props) { - if (!this.has("functions")) { - return; - } - - let functions = this.get("functions"); - for (let i = 0; i < functions.length; i++) { - if (functions[i]['$id'] == id) { functions[i] = { ...functions[i], ...props @@ -124,6 +143,9 @@ class Local extends Config { return; } } + + functions.push(props); + this.set("functions", functions); } getCollections() { @@ -149,6 +171,11 @@ class Local extends Config { } addCollection(props) { + props = whitelistKeys(props, KeysCollection, { + attributes: KeyAttributes, + indexes: KeyIndexes + }); + if (!this.has("collections")) { this.set("collections", []); } @@ -188,6 +215,8 @@ class Local extends Config { } addBucket(props) { + props = whitelistKeys(props, KeysStorage); + if (!this.has("buckets")) { this.set("buckets", []); } @@ -227,6 +256,8 @@ class Local extends Config { } addMessagingTopic(props) { + props = whitelistKeys(props, KeyTopics); + if (!this.has("topics")) { this.set("topics", []); } @@ -266,6 +297,8 @@ class Local extends Config { } addDatabase(props) { + props = whitelistKeys(props, KeysDatabase); + if (!this.has("databases")) { this.set("databases", []); } @@ -329,7 +362,7 @@ class Local extends Config { return { projectId: this.get("projectId"), projectName: this.get("projectName"), - projectSettings: this.get('projectSettings') + projectSettings: this.get('settings') }; } @@ -357,7 +390,6 @@ class Local extends Config { functions: projectSettings.serviceStatusForFunctions, graphql: projectSettings.serviceStatusForGraphql, messaging: projectSettings.serviceStatusForMessaging, - }, auth: { methods: { @@ -380,7 +412,7 @@ class Local extends Config { } }; - this.set('projectSettings', settings) + this.set('settings', settings) } } @@ -520,7 +552,7 @@ class Global extends Config { const current = this.getCurrentSession(); if (current) { - const config = this.get(current); + const config = this.get(current) ?? {}; return config[key] !== undefined; } @@ -530,7 +562,7 @@ class Global extends Config { const current = this.getCurrentSession(); if (current) { - const config = this.get(current); + const config = this.get(current) ?? {}; return config[key]; } diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index fe50339..2dde55f 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -1,15 +1,12 @@ +const chalk = require('chalk'); const childProcess = require('child_process'); const { localConfig } = require("../config"); const path = require('path'); const fs = require('fs'); -const { log,success } = require("../parser"); +const { log, success, hint } = require("../parser"); const { openRuntimesVersion, systemTools } = require("./utils"); -const ID = require("../id"); - -const activeDockerIds = {}; async function dockerStop(id) { - delete activeDockerIds[id]; const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], { stdio: 'pipe', }); @@ -18,20 +15,42 @@ async function dockerStop(id) { } async function dockerPull(func) { - log('Pulling Docker image of function runtime ...'); - const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; - const pullProcess = childProcess.spawn('docker', ['pull', imageName], { + const checkProcess = childProcess.spawn('docker', ['images', '--format', 'json', imageName], { stdio: 'pipe', pwd: path.join(process.cwd(), func.path) }); - pullProcess.stderr.on('data', (data) => { - process.stderr.write(`\n${data}$ `); + let hasImage = false; + + checkProcess.stdout.on('data', (data) => { + if(data) { + hasImage = false; + } + }); + + checkProcess.stderr.on('data', (data) => { + if(data) { + hasImage = false; + } + }); + + await new Promise((res) => { checkProcess.on('close', res) }); + + if(hasImage) { + return; + } + + log('Pulling Docker image ...'); + hint('This may take a few minutes, but we only need to do this once.'); + + const pullProcess = childProcess.spawn('docker', ['pull', imageName], { + stdio: 'pipe', + pwd: path.join(process.cwd(), func.path) }); await new Promise((res) => { pullProcess.on('close', res) }); @@ -47,7 +66,7 @@ async function dockerBuild(func, variables) { const functionDir = path.join(process.cwd(), func.path); - const id = ID.unique(); + const id = func.$id; const params = [ 'run' ]; params.push('--name', id); @@ -55,6 +74,7 @@ async function dockerBuild(func, variables) { params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); + params.push('-l', 'appwrite-env=dev'); params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`); for(const k of Object.keys(variables)) { @@ -69,11 +89,11 @@ async function dockerBuild(func, variables) { }); buildProcess.stdout.on('data', (data) => { - process.stdout.write(`\n${data}`); + process.stdout.write(chalk.blackBright(`${data}\n`)); }); buildProcess.stderr.on('data', (data) => { - process.stderr.write(`\n${data}`); + process.stderr.write(chalk.blackBright(`${data}\n`)); }); await new Promise((res) => { buildProcess.on('close', res) }); @@ -91,14 +111,7 @@ async function dockerBuild(func, variables) { await new Promise((res) => { copyProcess.on('close', res) }); - const cleanupProcess = childProcess.spawn('docker', ['rm', '--force', id], { - stdio: 'pipe', - pwd: functionDir - }); - - await new Promise((res) => { cleanupProcess.on('close', res) }); - - delete activeDockerIds[id]; + await dockerStop(id); const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { @@ -107,15 +120,6 @@ async function dockerBuild(func, variables) { } async function dockerStart(func, variables, port) { - log('Starting function using Docker ...'); - - log("Permissions, events, CRON and timeouts dont apply when running locally."); - - log('💡 Hint: Function automatically restarts when you edit your code.'); - - success(`Visit http://localhost:${port}/ to execute your function.`); - - const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); @@ -125,13 +129,14 @@ async function dockerStart(func, variables, port) { const functionDir = path.join(process.cwd(), func.path); - const id = ID.unique(); + const id = func.$id; const params = [ 'run' ]; params.push('--rm'); params.push('-d'); params.push('--name', id); params.push('-p', `${port}:3000`); + params.push('-l', 'appwrite-env=dev'); params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); @@ -150,11 +155,11 @@ async function dockerStart(func, variables, port) { pwd: functionDir }); - activeDockerIds[id] = true; + success(`Visit http://localhost:${port}/ to execute your function.`); } async function dockerCleanup() { - await dockerStop(); + await dockerStopActive(); const functions = localConfig.getFunctions(); for(const func of functions) { @@ -171,17 +176,40 @@ async function dockerCleanup() { } async function dockerStopActive() { - const ids = Object.keys(activeDockerIds); - for await (const id of ids) { + const listProcess = childProcess.spawn('docker', ['ps', '-a', '-q', '--filter', 'label=appwrite-env=dev'], { + stdio: 'pipe', + }); + + const ids = []; + function handleOutput(data) { + const list = data.toString().split('\n'); + for(const id of list) { + if(id && !id.includes(' ')) { + ids.push(id); + } + } + } + + listProcess.stdout.on('data', (data) => { + handleOutput(data); + }); + + listProcess.stderr.on('data', (data) => { + handleOutput(data); + }); + + await new Promise((res) => { listProcess.on('close', res) }); + + for(const id of ids) { await dockerStop(id); } } module.exports = { - dockerStop, dockerPull, dockerBuild, dockerStart, dockerCleanup, dockerStopActive, + dockerStop, } diff --git a/lib/emulation/utils.js b/lib/emulation/utils.js index d36d5cd..496aa55 100644 --- a/lib/emulation/utils.js +++ b/lib/emulation/utils.js @@ -2,8 +2,7 @@ const EventEmitter = require('node:events'); const { projectsCreateJWT } = require('../commands/projects'); const { localConfig } = require("../config"); - -const openRuntimesVersion = 'v3'; +const openRuntimesVersion = 'v4'; const runtimeNames = { 'node': 'Node.js', @@ -17,7 +16,8 @@ const runtimeNames = { 'java': 'Java', 'swift': 'Swift', 'kotlin': 'Kotlin', - 'bun': 'Bun' + 'bun': 'Bun', + 'go': 'Go', }; const systemTools = { @@ -81,6 +81,11 @@ const systemTools = { startCommand: "bun src/server.ts", dependencyFiles: [ "package.json", "package-lock.json", "bun.lockb" ] }, + 'go': { + isCompiled: true, + startCommand: "src/function/server", + dependencyFiles: [ ] + }, }; const JwtManager = { diff --git a/lib/parser.js b/lib/parser.js index 31e6850..a8d75b4 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -131,7 +131,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.1'; + const version = '6.0.0-rc.2'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; @@ -189,15 +189,23 @@ const parseBool = (value) => { } const log = (message) => { - console.log(`${chalk.cyan.bold("ℹ Info")} ${chalk.cyan(message ?? "")}`); + console.log(`${chalk.cyan.bold("ℹ Info:")} ${chalk.cyan(message ?? "")}`); +} + +const warn = (message) => { + console.log(`${chalk.yellow.bold("ℹ Warning:")} ${chalk.yellow(message ?? "")}`); +} + +const hint = (message) => { + console.log(`${chalk.cyan.bold("♥ Hint:")} ${chalk.cyan(message ?? "")}`); } const success = (message) => { - console.log(`${chalk.green.bold("✓ Success")} ${chalk.green(message ?? "")}`); + console.log(`${chalk.green.bold("✓ Success:")} ${chalk.green(message ?? "")}`); } const error = (message) => { - console.error(`${chalk.red.bold("✗ Error")} ${chalk.red(message ?? "")}`); + console.error(`${chalk.red.bold("✗ Error:")} ${chalk.red(message ?? "")}`); } const logo = "\n _ _ _ ___ __ _____\n \/_\\ _ __ _ ____ ___ __(_) |_ ___ \/ __\\ \/ \/ \\_ \\\n \/\/_\\\\| '_ \\| '_ \\ \\ \/\\ \/ \/ '__| | __\/ _ \\ \/ \/ \/ \/ \/ \/\\\/\n \/ _ \\ |_) | |_) \\ V V \/| | | | || __\/ \/ \/___\/ \/___\/\\\/ \/_\n \\_\/ \\_\/ .__\/| .__\/ \\_\/\\_\/ |_| |_|\\__\\___| \\____\/\\____\/\\____\/\n |_| |_|\n\n"; @@ -221,8 +229,8 @@ const commandDescriptions = { "client": `The client command allows you to configure your CLI`, "login": `The login command allows you to authenticate and manage a user account.`, "logout": `The logout command allows you to logout of your Appwrite account.`, - "whoami": `The whoami command gives information about the currently logged in user.`, - "register": `Outputs the link to create an Appwrite account..`, + "whoami": `The whoami command gives information about the currently signed in user.`, + "register": `Outputs the link to create an Appwrite account.`, "console" : `The console command allows gives you access to the APIs used by the Appwrite console.`, "assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`, "messaging": `The messaging command allows you to send messages.`, @@ -240,6 +248,8 @@ module.exports = { parseInteger, parseBool, log, + warn, + hint, success, error, commandDescriptions, diff --git a/lib/questions.js b/lib/questions.js index d003f9d..b347469 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -46,7 +46,7 @@ const getIgnores = (runtime) => { return ['.build', '.swiftpm']; } - return undefined; + return []; }; const getEntrypoint = (runtime) => { @@ -80,6 +80,8 @@ const getEntrypoint = (runtime) => { return 'src/Main.java'; case 'kotlin': return 'src/Main.kt'; + case 'go': + return 'main.go'; } return undefined; @@ -209,18 +211,26 @@ const questionsInitProject = [ when: (answer) => answer.start === 'existing' } ]; +const questionsInitProjectAutopull = [ + { + type: "confirm", + name: "autopull", + message: + `Would you like to pull all resources from project you just linked?` + }, +]; const questionsPullResources = [ { type: "list", name: "resource", message: "Which resources would you like to pull?", choices: [ - { name: 'Project', value: 'project' }, - { name: 'Functions', value: 'functions' }, - { name: 'Collections', value: 'collections' }, - { name: 'Buckets', value: 'buckets' }, - { name: 'Teams', value: 'teams' }, - { name: 'Topics', value: 'messages' } + { name: `Settings ${chalk.blackBright(`(Project)`)}`, value: 'settings' }, + { name: `Functions ${chalk.blackBright(`(Deployment)`)}`, value: 'functions' }, + { name: `Collections ${chalk.blackBright(`(Databases)`)}`, value: 'collections' }, + { name: `Buckets ${chalk.blackBright(`(Storage)`)}`, value: 'buckets' }, + { name: `Teams ${chalk.blackBright(`(Auth)`)}`, value: 'teams' }, + { name: `Topics ${chalk.blackBright(`(Messaging)`)}`, value: 'messages' } ] } ] @@ -283,8 +293,23 @@ const questionsCreateFunction = [ } }) return choices; - } - } + }, + }, + { + type: "list", + name: "template", + message: "How would you like to start your function code?", + choices: [ + { + name: `Start from scratch ${chalk.blackBright(`(starter)`)}`, + value: "starter" + }, + { + name: "Pick a template", + value: "custom" + } + ] + }, ]; const questionsCreateFunctionSelectTemplate = (templates) => { @@ -451,12 +476,12 @@ const questionsLogin = [ { type: "list", name: "method", - message: "You're already logged in, what you like to do?", + message: "What you like to do?", choices: [ - { name: 'Login to a different account', value: 'login' }, - { name: 'Change to a different existed account', value: 'select' } + { name: 'Login to an account', value: 'login' }, + { name: 'Switch to an account', value: 'select' } ], - when: () => globalConfig.getCurrentSession() !== '' + when: () => globalConfig.getSessions().length >= 2 }, { type: "input", @@ -570,12 +595,12 @@ const questionsPushResources = [ name: "resource", message: "Which resources would you like to push?", choices: [ - { name: 'Project', value: 'project' }, - { name: 'Functions', value: 'functions' }, - { name: 'Collections', value: 'collections' }, - { name: 'Buckets', value: 'buckets' }, - { name: 'Teams', value: 'teams' }, - { name: 'Topics', value: 'messages' } + { name: `Settings ${chalk.blackBright(`(Project)`)}`, value: 'settings' }, + { name: `Functions ${chalk.blackBright(`(Deployment)`)}`, value: 'functions' }, + { name: `Collections ${chalk.blackBright(`(Databases)`)}`, value: 'collections' }, + { name: `Buckets ${chalk.blackBright(`(Storage)`)}`, value: 'buckets' }, + { name: `Teams ${chalk.blackBright(`(Auth)`)}`, value: 'teams' }, + { name: `Topics ${chalk.blackBright(`(Messaging)`)}`, value: 'messages' } ] } ]; @@ -605,7 +630,7 @@ const questionsPushFunctions = [ let functions = localConfig.getFunctions(); checkDeployConditions(localConfig) if (functions.length === 0) { - throw new Error("No functions found in the current directory Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + throw new Error("No functions found Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); } let choices = functions.map((func, idx) => { return { @@ -794,7 +819,7 @@ const questionsRunFunctions = [ choices: () => { let functions = localConfig.getFunctions(); if (functions.length === 0) { - throw new Error("No functions found in the current directory. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + throw new Error("No functions found. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); } let choices = functions.map((func, idx) => { return { @@ -809,6 +834,7 @@ const questionsRunFunctions = [ module.exports = { questionsInitProject, + questionsInitProjectAutopull, questionsCreateFunction, questionsCreateFunctionSelectTemplate, questionsCreateBucket, diff --git a/lib/sdks.js b/lib/sdks.js index 48957b4..f8cb8fc 100644 --- a/lib/sdks.js +++ b/lib/sdks.js @@ -1,44 +1,12 @@ -const inquirer = require("inquirer"); const Client = require("./client"); const { globalConfig, localConfig } = require("./config"); -const questionGetEndpoint = [ - { - type: "input", - name: "endpoint", - message: "Enter the endpoint of your Appwrite server", - default: "http://localhost/v1", - async validate(value) { - if (!value) { - return "Please enter a valid endpoint."; - } - let client = new Client().setEndpoint(value); - try { - let response = await client.call('get', '/health/version'); - if (response.version) { - return true; - } else { - throw new Error(); - } - } catch (error) { - return "Invalid endpoint or your Appwrite server is not running as expected."; - } - } - } -] - const sdkForConsole = async (requiresAuth = true) => { let client = new Client(); let endpoint = globalConfig.getEndpoint(); let cookie = globalConfig.getCookie() let selfSigned = globalConfig.getSelfSigned() - if (!endpoint) { - const answers = await inquirer.prompt(questionGetEndpoint) - endpoint = answers.endpoint; - globalConfig.setEndpoint(endpoint); - } - if (requiresAuth && cookie === "") { throw new Error("Session not found. Please run `appwrite login` to create a session"); } @@ -61,12 +29,6 @@ const sdkForProject = async () => { let cookie = globalConfig.getCookie() let selfSigned = globalConfig.getSelfSigned() - if (!endpoint) { - const answers = await inquirer.prompt(questionGetEndpoint) - endpoint = answers.endpoint; - globalConfig.setEndpoint(endpoint); - } - if (!project) { throw new Error("Project is not set. Please run `appwrite init` to initialize the current directory with an Appwrite project."); } diff --git a/package.json b/package.json index c293b91..0fe8b81 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.1", + "version": "6.0.0-rc.2", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 918f944..85d84c6 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.1", + "version": "6.0.0-rc.2", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.1/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From 7ebd1b9415ecedf72a0010378c308600dfc26103 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 10 Jul 2024 18:00:08 +0200 Subject: [PATCH 04/18] fix: cli qa --- README.md | 4 +- install.ps1 | 4 +- install.sh | 2 +- lib/client.js | 8 +-- lib/commands/pull.js | 63 +++++++++++------- lib/commands/push.js | 19 +++--- lib/commands/run.js | 42 ++++++++---- lib/config.js | 41 +++++++++--- lib/emulation/docker.js | 138 +++++++++++++++++----------------------- lib/emulation/utils.js | 10 ++- lib/parser.js | 2 +- lib/questions.js | 9 +++ lib/sdks.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +- 15 files changed, 200 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index 0841ddc..d68745b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.2 +6.0.0-rc.3 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.2 +6.0.0-rc.3 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index f6a9445..109a34b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 7d41d28..9079e66 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.2" + GITHUB_LATEST_VERSION="6.0.0-rc.3" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 050c65e..aad186a 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.2', - 'user-agent' : `AppwriteCLI/6.0.0-rc.2 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.3', + 'user-agent' : `AppwriteCLI/6.0.0-rc.3 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } @@ -168,7 +168,7 @@ class Client { body = formData; } else { - body = JSON.stringify(params); + body = JSONbig.stringify(params); } let response = undefined; @@ -224,7 +224,7 @@ class Client { const text = await response.text(); let json = undefined; try { - json = JSON.parse(text); + json = JSONbig.parse(text); } catch (error) { return text; } diff --git a/lib/commands/pull.js b/lib/commands/pull.js index 5063e51..d133f20 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -11,7 +11,7 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat const { storageListBuckets } = require("./storage"); const { localConfig } = require("../config"); const { paginate } = require("../paginate"); -const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions"); +const { questionsPullCollection, questionsPullFunctions, questionsPullFunctionsCode, questionsPullResources } = require("../questions"); const { cliConfig, success, log, warn, actionRunner, commandDescriptions } = require("../parser"); const pullResources = async () => { @@ -56,7 +56,7 @@ const pullSettings = async () => { } } -const pullFunctions = async () => { +const pullFunctions = async ({ code }) => { log("Fetching functions ..."); let total = 0; @@ -74,11 +74,15 @@ const pullFunctions = async () => { ? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions : (await inquirer.prompt(questionsPullFunctions)).functions; + let allowCodePull = cliConfig.force === true ? true : null; + for (let func of functions) { total++; log(`Pulling function ${chalk.bold(func['name'])} ...`); const localFunction = localConfig.getFunction(func.$id); + + func['path'] = localFunction['path']; if(!localFunction['path']) { func['path'] = `functions/${func.$id}`; } @@ -88,28 +92,40 @@ const pullFunctions = async () => { if (!fs.existsSync(func['path'])) { fs.mkdirSync(func['path'], { recursive: true }); } - - if(func['deployment']) { - const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` - await functionsDownloadDeployment({ - functionId: func['$id'], - deploymentId: func['deployment'], - destination: compressedFileName, - overrideForCli: true, - parseOutput: false - }); - - tar.extract({ - sync: true, - cwd: func['path'], - file: compressedFileName, - strict: false, - }); - - fs.rmSync(compressedFileName); - } - } + + if(code === false) { + warn("Source code download skipped."); + } else if(!func['deployment']) { + warn("Source code download skipped because function doesn't have active deployment."); + } else { + if(allowCodePull === null) { + const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode); + allowCodePull = codeAnswer.override; + } + + if(allowCodePull) { + log("Pulling active deployment's code ..."); + + const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` + await functionsDownloadDeployment({ + functionId: func['$id'], + deploymentId: func['deployment'], + destination: compressedFileName, + overrideForCli: true, + parseOutput: false + }); + tar.extract({ + sync: true, + cwd: func['path'], + file: compressedFileName, + strict: false, + }); + + fs.rmSync(compressedFileName); + } + } + success(`Successfully pulled ${chalk.bold(total)} functions.`); } @@ -261,6 +277,7 @@ pull .command("function") .alias("functions") .description("Pulling your Appwrite cloud function") + .option("--no-code", "Don't pull the function's code") .action(actionRunner(pullFunctions)) pull diff --git a/lib/commands/push.js b/lib/commands/push.js index 949b299..d516f8b 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -67,7 +67,7 @@ const { checkDeployConditions } = require('../utils'); const STEP_SIZE = 100; // Resources const POLL_DEBOUNCE = 2000; // Milliseconds -const POLL_MAX_DEBOUNCE = 30; // Times +const POLL_MAX_DEBOUNCE = 1800; // Times of POLL_DEBOUNCE (1 hour) let pollMaxDebounces = 30; @@ -354,8 +354,8 @@ const createAttribute = async (databaseId, collectionId, attribute) => { collectionId, key: attribute.key, required: attribute.required, - min: parseInt(attribute.min.toString()), - max: parseInt(attribute.max.toString()), + min: attribute.min, + max: attribute.max, xdefault: attribute.default, array: attribute.array, parseOutput: false @@ -366,8 +366,8 @@ const createAttribute = async (databaseId, collectionId, attribute) => { collectionId, key: attribute.key, required: attribute.required, - min: parseFloat(attribute.min.toString()), - max: parseFloat(attribute.max.toString()), + min: attribute.min, + max: attribute.max, xdefault: attribute.default, array: attribute.array, parseOutput: false @@ -471,8 +471,8 @@ const updateAttribute = async (databaseId, collectionId, attribute) => { collectionId, key: attribute.key, required: attribute.required, - min: parseInt(attribute.min.toString()), - max: parseInt(attribute.max.toString()), + min: attribute.min, + max: attribute.max, xdefault: attribute.default, array: attribute.array, parseOutput: false @@ -483,8 +483,8 @@ const updateAttribute = async (databaseId, collectionId, attribute) => { collectionId, key: attribute.key, required: attribute.required, - min: parseFloat(attribute.min.toString()), - max: parseFloat(attribute.max.toString()), + min: attribute.min, + max: attribute.max, xdefault: attribute.default, array: attribute.array, parseOutput: false @@ -884,6 +884,7 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero logging: func.logging, entrypoint: func.entrypoint, commands: func.commands, + scopes: func.scopes, providerRepositoryId: func.providerRepositoryId ?? "", installationId: func.installationId ?? '', providerBranch: func.providerBranch ?? '', diff --git a/lib/commands/run.js b/lib/commands/run.js index 425e6d6..0ea914a 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -86,12 +86,12 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = log("If you wish to change your local settings, update the appwrite.json file and rerun the 'appwrite run' command."); hint("Permissions, events, CRON and timeouts dont apply when running locally."); - await dockerCleanup(); + await dockerCleanup(func.$id); process.on('SIGINT', async () => { log('Cleaning up ...'); - await dockerCleanup(); - success(); + await dockerCleanup(func.$id); + success("Local function successfully stopped."); process.exit(); }); @@ -135,7 +135,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime; try { - await JwtManager.setup(userId); + await JwtManager.setup(userId, func.scopes ?? []); } catch(err) { warn("Dynamic API key not generated. Header x-appwrite-key will not be set. Reason: " + err.message); } @@ -149,18 +149,12 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers); await dockerPull(func); - await dockerBuild(func, variables); - - log('Starting function using Docker ...'); - hint('Function automatically restarts when you edit your code.'); - - await dockerStart(func, variables, port); new Tail(logsPath).on("line", function(data) { - process.stdout.write(chalk.blackBright(`${data}\n`)); + process.stdout.write(chalk.white(`${data}\n`)); }); new Tail(errorsPath).on("line", function(data) { - process.stdout.write(chalk.blackBright(`${data}\n`)); + process.stdout.write(chalk.white(`${data}\n`)); }); if(!noReload) { @@ -181,8 +175,14 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = const dependencyFile = files.find((filePath) => tool.dependencyFiles.includes(filePath)); if(tool.isCompiled || dependencyFile) { - log(`Rebuilding the function ...`); + log(`Rebuilding the function due to file changes ...`); await dockerBuild(func, variables); + + if(!Queue.isEmpty()) { + Queue.unlock(); + return; + } + await dockerStart(func, variables, port); } else { log('Hot-swapping function.. Files with change are ' + files.join(', ')); @@ -247,6 +247,22 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = Queue.unlock(); } }); + + Queue.lock(); + + log('Building function using Docker ...'); + await dockerBuild(func, variables); + + if(!Queue.isEmpty()) { + Queue.unlock(); + return; + } + + log('Starting function using Docker ...'); + hint('Function automatically restarts when you edit your code.'); + await dockerStart(func, variables, port); + + Queue.unlock(); } const run = new Command("run") diff --git a/lib/config.js b/lib/config.js index af4c95d..665e983 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,15 +4,36 @@ const _path = require("path"); const process = require("process"); const JSONbig = require("json-bigint")({ storeAsString: false }); -const KeysFunction = ["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"]; -const KeysDatabase = ["$id", "name", "enabled"]; -const KeysCollection = ["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]; -const KeysStorage = ["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]; -const KeyTopics = ["$id", "name", "subscribe"]; -const KeyAttributes = ["key", "type", "required", "array", "size", "default"]; -const KeyIndexes = ["key", "type", "status", "attributes", "orders"]; - -function whitelistKeys(value, keys, nestedKeys = []) { +const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"]); +const KeysDatabase = new Set(["$id", "name", "enabled"]); +const KeysCollection = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]); +const KeysStorage = new Set(["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]); +const KeyTopics = new Set(["$id", "name", "subscribe"]); +const KeyAttributes = new Set([ + "key", + "type", + "required", + "array", + "size", + "default", + // integer and float + "min", + "max", + // email, enum, URL, IP, and datetime + "format", + // enum + "elements", + // relationship + "relatedCollection", + "relationType", + "twoWay", + "twoWayKey", + "onDelete", + "side" +]); +const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]); + +function whitelistKeys(value, keys, nestedKeys = {}) { if(Array.isArray(value)) { const newValue = []; @@ -25,7 +46,7 @@ function whitelistKeys(value, keys, nestedKeys = []) { const newValue = {}; Object.keys(value).forEach((key) => { - if(keys.includes(key)) { + if(keys.has(key)) { if(nestedKeys[key]) { newValue[key] = whitelistKeys(value[key], nestedKeys[key]); } else { diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index 2dde55f..d93f280 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -4,11 +4,15 @@ const { localConfig } = require("../config"); const path = require('path'); const fs = require('fs'); const { log, success, hint } = require("../parser"); -const { openRuntimesVersion, systemTools } = require("./utils"); +const { openRuntimesVersion, systemTools, Queue } = require("./utils"); async function dockerStop(id) { const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], { stdio: 'pipe', + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } }); await new Promise((res) => { stopProcess.on('close', res) }); @@ -20,45 +24,20 @@ async function dockerPull(func) { const runtimeName = runtimeChunks.join("-"); const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; - const checkProcess = childProcess.spawn('docker', ['images', '--format', 'json', imageName], { - stdio: 'pipe', - pwd: path.join(process.cwd(), func.path) - }); - - let hasImage = false; - - checkProcess.stdout.on('data', (data) => { - if(data) { - hasImage = false; - } - }); - - checkProcess.stderr.on('data', (data) => { - if(data) { - hasImage = false; - } - }); - - await new Promise((res) => { checkProcess.on('close', res) }); - - if(hasImage) { - return; - } - - log('Pulling Docker image ...'); - hint('This may take a few minutes, but we only need to do this once.'); + log('Verifying Docker image ...'); const pullProcess = childProcess.spawn('docker', ['pull', imageName], { stdio: 'pipe', - pwd: path.join(process.cwd(), func.path) + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } }); await new Promise((res) => { pullProcess.on('close', res) }); } async function dockerBuild(func, variables) { - log('Building function using Docker ...'); - const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); @@ -74,7 +53,6 @@ async function dockerBuild(func, variables) { params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); - params.push('-l', 'appwrite-env=dev'); params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`); for(const k of Object.keys(variables)) { @@ -85,7 +63,11 @@ async function dockerBuild(func, variables) { const buildProcess = childProcess.spawn('docker', params, { stdio: 'pipe', - pwd: functionDir + pwd: functionDir, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } }); buildProcess.stdout.on('data', (data) => { @@ -96,8 +78,25 @@ async function dockerBuild(func, variables) { process.stderr.write(chalk.blackBright(`${data}\n`)); }); + const killInterval = setInterval(() => { + if(!Queue.isEmpty()) { + log('Cancelling build ...'); + buildProcess.stdout.destroy(); + buildProcess.stdin.destroy(); + buildProcess.stderr.destroy(); + buildProcess.kill("SIGKILL"); + clearInterval(killInterval); + } + }, 100); + await new Promise((res) => { buildProcess.on('close', res) }); + clearInterval(interval); + + if(!Queue.isEmpty()) { + return; + } + const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz'); const copyDir = path.dirname(copyPath); if (!fs.existsSync(copyDir)) { @@ -106,7 +105,11 @@ async function dockerBuild(func, variables) { const copyProcess = childProcess.spawn('docker', ['cp', `${id}:/mnt/code/code.tar.gz`, copyPath], { stdio: 'pipe', - pwd: functionDir + pwd: functionDir, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } }); await new Promise((res) => { copyProcess.on('close', res) }); @@ -133,10 +136,8 @@ async function dockerStart(func, variables, port) { const params = [ 'run' ]; params.push('--rm'); - params.push('-d'); params.push('--name', id); params.push('-p', `${port}:3000`); - params.push('-l', 'appwrite-env=dev'); params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); @@ -150,58 +151,38 @@ async function dockerStart(func, variables, port) { params.push('-v', `${functionDir}/.appwrite/build.tar.gz:/mnt/code/code.tar.gz:ro`); params.push(imageName, 'sh', '-c', `helpers/start.sh "${tool.startCommand}"`); - childProcess.spawn('docker', params, { + const startProcess = childProcess.spawn('docker', params, { stdio: 'pipe', - pwd: functionDir + pwd: functionDir, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } }); - success(`Visit http://localhost:${port}/ to execute your function.`); -} - -async function dockerCleanup() { - await dockerStopActive(); + startProcess.stdout.on('data', (data) => { + process.stdout.write(chalk.blackBright(data)); + }); - const functions = localConfig.getFunctions(); - for(const func of functions) { - const appwritePath = path.join(process.cwd(), func.path, '.appwrite'); - if (fs.existsSync(appwritePath)) { - fs.rmSync(appwritePath, { recursive: true, force: true }); - } + startProcess.stderr.on('data', (data) => { + process.stdout.write(chalk.blackBright(data)); + }); - const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); - if (fs.existsSync(tempPath)) { - fs.rmSync(tempPath, { force: true }); - } - } + success(`Visit http://localhost:${port}/ to execute your function.`); } -async function dockerStopActive() { - const listProcess = childProcess.spawn('docker', ['ps', '-a', '-q', '--filter', 'label=appwrite-env=dev'], { - stdio: 'pipe', - }); +async function dockerCleanup(functionId) { + await dockerStop(functionId); - const ids = []; - function handleOutput(data) { - const list = data.toString().split('\n'); - for(const id of list) { - if(id && !id.includes(' ')) { - ids.push(id); - } - } + const func = localConfig.getFunction(functionId); + const appwritePath = path.join(process.cwd(), func.path, '.appwrite'); + if (fs.existsSync(appwritePath)) { + fs.rmSync(appwritePath, { recursive: true, force: true }); } - listProcess.stdout.on('data', (data) => { - handleOutput(data); - }); - - listProcess.stderr.on('data', (data) => { - handleOutput(data); - }); - - await new Promise((res) => { listProcess.on('close', res) }); - - for(const id of ids) { - await dockerStop(id); + const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + if (fs.existsSync(tempPath)) { + fs.rmSync(tempPath, { force: true }); } } @@ -210,6 +191,5 @@ module.exports = { dockerBuild, dockerStart, dockerCleanup, - dockerStopActive, dockerStop, } diff --git a/lib/emulation/utils.js b/lib/emulation/utils.js index 496aa55..f32a6b9 100644 --- a/lib/emulation/utils.js +++ b/lib/emulation/utils.js @@ -1,6 +1,8 @@ const EventEmitter = require('node:events'); const { projectsCreateJWT } = require('../commands/projects'); const { localConfig } = require("../config"); +const { usersGet, usersCreateJWT } = require("../commands/users"); +const { log } = require("../parser"); const openRuntimesVersion = 'v4'; @@ -95,7 +97,7 @@ const JwtManager = { timerWarn: null, timerError: null, - async setup(userId = null) { + async setup(userId = null, projectScopes = []) { if(this.timerWarn) { clearTimeout(this.timerWarn); } @@ -128,8 +130,7 @@ const JwtManager = { const functionResponse = await projectsCreateJWT({ projectId: localConfig.getProject().projectId, - // TODO: Once we have endpoint for this, use it - scopes: ["sessions.write","users.read","users.write","teams.read","teams.write","databases.read","databases.write","collections.read","collections.write","attributes.read","attributes.write","indexes.read","indexes.write","documents.read","documents.write","files.read","files.write","buckets.read","buckets.write","functions.read","functions.write","execution.read","execution.write","locale.read","avatars.read","health.read","providers.read","providers.write","messages.read","messages.write","topics.read","topics.write","subscribers.read","subscribers.write","targets.read","targets.write","rules.read","rules.write","migrations.read","migrations.write","vcs.read","vcs.write","assistant.read"], + scopes: projectScopes, duration: 60*60, parseOutput: false }); @@ -155,6 +156,9 @@ const Queue = { this.files = []; this.locked = true; }, + isEmpty() { + return this.files.length === 0 + }, unlock() { this.locked = false; if(this.files.length > 0) { diff --git a/lib/parser.js b/lib/parser.js index a8d75b4..fecdf21 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -131,7 +131,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.2'; + const version = '6.0.0-rc.3'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/lib/questions.js b/lib/questions.js index b347469..8798bd5 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -258,6 +258,14 @@ const questionsPullFunctions = [ } ]; +const questionsPullFunctionsCode = [ + { + type: "confirm", + name: "override", + message: "Do you want to pull source code of active deployment?" + }, +]; + const questionsCreateFunction = [ { type: "input", @@ -841,6 +849,7 @@ module.exports = { questionsCreateCollection, questionsCreateMessagingTopic, questionsPullFunctions, + questionsPullFunctionsCode, questionsLogin, questionsPullResources, questionsLogout, diff --git a/lib/sdks.js b/lib/sdks.js index f8cb8fc..9208e8f 100644 --- a/lib/sdks.js +++ b/lib/sdks.js @@ -30,7 +30,7 @@ const sdkForProject = async () => { let selfSigned = globalConfig.getSelfSigned() if (!project) { - throw new Error("Project is not set. Please run `appwrite init` to initialize the current directory with an Appwrite project."); + throw new Error("Project is not set. Please run `appwrite init project` to initialize the current directory with an Appwrite project."); } client diff --git a/package.json b/package.json index 0fe8b81..9b28ba9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.2", + "version": "6.0.0-rc.3", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 85d84c6..4f7d728 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.2", + "version": "6.0.0-rc.3", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.2/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From 90074f7bade62f17f5435e83eedcb99f414ea458 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 17 Jul 2024 15:53:39 +0200 Subject: [PATCH 05/18] chore: rc.4 --- README.md | 4 ++-- docs/examples/account/delete-mfa-authenticator.md | 3 +-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/commands/account.js | 7 +------ lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 9 files changed, 14 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d68745b..047af5e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.3 +6.0.0-rc.4 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.3 +6.0.0-rc.4 ``` ## Getting Started diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index c36e9d5..d466485 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -1,3 +1,2 @@ appwrite account deleteMfaAuthenticator \ - --type totp \ - --otp + --type totp diff --git a/install.ps1 b/install.ps1 index 109a34b..c4117bf 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 9079e66..61ac1c3 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.3" + GITHUB_LATEST_VERSION="6.0.0-rc.4" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index aad186a..f91d767 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.3', - 'user-agent' : `AppwriteCLI/6.0.0-rc.3 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.4', + 'user-agent' : `AppwriteCLI/6.0.0-rc.4 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } diff --git a/lib/commands/account.js b/lib/commands/account.js index 1de3c98..883e8d5 100644 --- a/lib/commands/account.js +++ b/lib/commands/account.js @@ -430,7 +430,6 @@ const accountUpdateMfaAuthenticator = async ({type,otp,parseOutput = true, overr /** * @typedef {Object} AccountDeleteMfaAuthenticatorRequestParams * @property {AuthenticatorType} type Type of authenticator. - * @property {string} otp Valid verification token. * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk @@ -439,14 +438,11 @@ const accountUpdateMfaAuthenticator = async ({type,otp,parseOutput = true, overr /** * @param {AccountDeleteMfaAuthenticatorRequestParams} params */ -const accountDeleteMfaAuthenticator = async ({type,otp,parseOutput = true, overrideForCli = false, sdk = undefined}) => { +const accountDeleteMfaAuthenticator = async ({type,parseOutput = true, overrideForCli = false, sdk = undefined}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); let payload = {}; - if (typeof otp !== 'undefined') { - payload['otp'] = otp; - } let response = undefined; @@ -1847,7 +1843,6 @@ account .command(`deleteMfaAuthenticator`) .description(`Delete an authenticator for a user by ID.`) .requiredOption(`--type `, `Type of authenticator.`) - .requiredOption(`--otp `, `Valid verification token.`) .action(actionRunner(accountDeleteMfaAuthenticator)) account diff --git a/lib/parser.js b/lib/parser.js index fecdf21..a679821 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -131,7 +131,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.3'; + const version = '6.0.0-rc.4'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index 9b28ba9..cc47d7d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.3", + "version": "6.0.0-rc.4", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 4f7d728..138de4b 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.3", + "version": "6.0.0-rc.4", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.3/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From d9a69ee076ab8db67a2701340e7129f9249b0af7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 17 Jul 2024 16:22:21 +0200 Subject: [PATCH 06/18] chore: rc.4 --- lib/commands/pull.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/commands/pull.js b/lib/commands/pull.js index d133f20..d416f8e 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -124,6 +124,7 @@ const pullFunctions = async ({ code }) => { fs.rmSync(compressedFileName); } + } } success(`Successfully pulled ${chalk.bold(total)} functions.`); From 8e18b1e4c28b960db0f93684ba505559da041f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 27 Jul 2024 09:46:16 +0000 Subject: [PATCH 07/18] RC update --- README.md | 8 +- install.ps1 | 4 +- install.sh | 2 +- lib/client.js | 4 +- lib/commands/account.js | 130 ++++++------ lib/commands/avatars.js | 18 +- lib/commands/databases.js | 280 ++++++++++++------------- lib/commands/functions.js | 138 ++++++------- lib/commands/generic.js | 7 +- lib/commands/health.js | 44 ++-- lib/commands/init.js | 7 +- lib/commands/locale.js | 14 +- lib/commands/messaging.js | 320 ++++++++++++++--------------- lib/commands/migrations.js | 56 ++--- lib/commands/project.js | 22 +- lib/commands/projects.js | 244 +++++++++++----------- lib/commands/proxy.js | 20 +- lib/commands/pull.js | 8 +- lib/commands/push.js | 408 ++++++++++++++++++++++++++++--------- lib/commands/run.js | 56 ++++- lib/commands/storage.js | 88 ++++---- lib/commands/teams.js | 58 +++--- lib/commands/users.js | 198 +++++++++--------- lib/commands/vcs.js | 54 ++--- lib/config.js | 32 ++- lib/emulation/docker.js | 83 +++++++- lib/parser.js | 17 +- lib/questions.js | 36 ++-- lib/spinner.js | 1 + package.json | 2 +- scoop/appwrite.json | 6 +- 31 files changed, 1345 insertions(+), 1020 deletions(-) diff --git a/README.md b/README.md index 047af5e..365f8be 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite Command Line SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.5.7-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** +**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.4 +6.0.0-rc.5 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.4 +6.0.0-rc.5 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index c4117bf..dcc1ed2 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 61ac1c3..823437c 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.4" + GITHUB_LATEST_VERSION="6.0.0-rc.5" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index f91d767..f9260d9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.4', - 'user-agent' : `AppwriteCLI/6.0.0-rc.4 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.5', + 'user-agent' : `AppwriteCLI/6.0.0-rc.5 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } diff --git a/lib/commands/account.js b/lib/commands/account.js index 883e8d5..5df93fa 100644 --- a/lib/commands/account.js +++ b/lib/commands/account.js @@ -1779,7 +1779,7 @@ account account .command(`create`) .description(`Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).`) - .requiredOption(`--userId `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email `, `User email.`) .requiredOption(`--password `, `New user password. Must be between 8 and 256 chars.`) .option(`--name `, `User name. Max length: 128 chars.`) @@ -1791,171 +1791,171 @@ account .action(actionRunner(accountDelete)) account - .command(`updateEmail`) + .command(`update-email`) .description(`Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request. This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password. `) .requiredOption(`--email `, `User email.`) .requiredOption(`--password `, `User password. Must be at least 8 chars.`) .action(actionRunner(accountUpdateEmail)) account - .command(`listIdentities`) + .command(`list-identities`) .description(`Get the list of identities for the currently logged in user.`) .option(`--queries [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: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry`) .action(actionRunner(accountListIdentities)) account - .command(`deleteIdentity`) + .command(`delete-identity`) .description(`Delete an identity by its unique ID.`) - .requiredOption(`--identityId `, `Identity ID.`) + .requiredOption(`--identity-id `, `Identity ID.`) .action(actionRunner(accountDeleteIdentity)) account - .command(`createJWT`) + .command(`create-jwt`) .description(`Use this endpoint to create a JSON Web Token. You can use the resulting JWT to authenticate on behalf of the current user when working with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes from its creation and will be invalid if the user will logout in that time frame.`) .action(actionRunner(accountCreateJWT)) account - .command(`listLogs`) + .command(`list-logs`) .description(`Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(accountListLogs)) account - .command(`updateMFA`) + .command(`update-mfa`) .description(`Enable or disable MFA on an account.`) .requiredOption(`--mfa `, `Enable or disable MFA.`, parseBool) .action(actionRunner(accountUpdateMFA)) account - .command(`createMfaAuthenticator`) + .command(`create-mfa-authenticator`) .description(`Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.`) .requiredOption(`--type `, `Type of authenticator. Must be 'totp'`) .action(actionRunner(accountCreateMfaAuthenticator)) account - .command(`updateMfaAuthenticator`) + .command(`update-mfa-authenticator`) .description(`Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.`) .requiredOption(`--type `, `Type of authenticator.`) .requiredOption(`--otp `, `Valid verification token.`) .action(actionRunner(accountUpdateMfaAuthenticator)) account - .command(`deleteMfaAuthenticator`) + .command(`delete-mfa-authenticator`) .description(`Delete an authenticator for a user by ID.`) .requiredOption(`--type `, `Type of authenticator.`) .action(actionRunner(accountDeleteMfaAuthenticator)) account - .command(`createMfaChallenge`) + .command(`create-mfa-challenge`) .description(`Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.`) .requiredOption(`--factor `, `Factor used for verification. Must be one of following: 'email', 'phone', 'totp', 'recoveryCode'.`) .action(actionRunner(accountCreateMfaChallenge)) account - .command(`updateMfaChallenge`) + .command(`update-mfa-challenge`) .description(`Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.`) - .requiredOption(`--challengeId `, `ID of the challenge.`) + .requiredOption(`--challenge-id `, `ID of the challenge.`) .requiredOption(`--otp `, `Valid verification token.`) .action(actionRunner(accountUpdateMfaChallenge)) account - .command(`listMfaFactors`) + .command(`list-mfa-factors`) .description(`List the factors available on the account to be used as a MFA challange.`) .action(actionRunner(accountListMfaFactors)) account - .command(`getMfaRecoveryCodes`) + .command(`get-mfa-recovery-codes`) .description(`Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.`) .action(actionRunner(accountGetMfaRecoveryCodes)) account - .command(`createMfaRecoveryCodes`) + .command(`create-mfa-recovery-codes`) .description(`Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.`) .action(actionRunner(accountCreateMfaRecoveryCodes)) account - .command(`updateMfaRecoveryCodes`) + .command(`update-mfa-recovery-codes`) .description(`Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to regenreate recovery codes.`) .action(actionRunner(accountUpdateMfaRecoveryCodes)) account - .command(`updateName`) + .command(`update-name`) .description(`Update currently logged in user account name.`) .requiredOption(`--name `, `User name. Max length: 128 chars.`) .action(actionRunner(accountUpdateName)) account - .command(`updatePassword`) + .command(`update-password`) .description(`Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.`) .requiredOption(`--password `, `New user password. Must be at least 8 chars.`) - .option(`--oldPassword `, `Current user password. Must be at least 8 chars.`) + .option(`--old-password `, `Current user password. Must be at least 8 chars.`) .action(actionRunner(accountUpdatePassword)) account - .command(`updatePhone`) + .command(`update-phone`) .description(`Update the currently logged in user's phone number. After updating the phone number, the phone verification status will be reset. A confirmation SMS is not sent automatically, however you can use the [POST /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) endpoint to send a confirmation SMS.`) .requiredOption(`--phone `, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .requiredOption(`--password `, `User password. Must be at least 8 chars.`) .action(actionRunner(accountUpdatePhone)) account - .command(`getPrefs`) + .command(`get-prefs`) .description(`Get the preferences as a key-value object for the currently logged in user.`) .action(actionRunner(accountGetPrefs)) account - .command(`updatePrefs`) + .command(`update-prefs`) .description(`Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.`) .requiredOption(`--prefs `, `Prefs key-value JSON object.`) .action(actionRunner(accountUpdatePrefs)) account - .command(`createRecovery`) + .command(`create-recovery`) .description(`Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the [PUT /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour.`) .requiredOption(`--email `, `User email.`) .requiredOption(`--url `, `URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) .action(actionRunner(accountCreateRecovery)) account - .command(`updateRecovery`) + .command(`update-recovery`) .description(`Use this endpoint to complete the user account password reset. Both the **userId** and **secret** arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the [POST /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) endpoint. Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.`) - .requiredOption(`--userId `, `User ID.`) + .requiredOption(`--user-id `, `User ID.`) .requiredOption(`--secret `, `Valid reset token.`) .requiredOption(`--password `, `New user password. Must be between 8 and 256 chars.`) .action(actionRunner(accountUpdateRecovery)) account - .command(`listSessions`) + .command(`list-sessions`) .description(`Get the list of active sessions across different devices for the currently logged in user.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(accountListSessions)) account - .command(`deleteSessions`) + .command(`delete-sessions`) .description(`Delete all sessions from the user account and remove any sessions cookies from the end client.`) .action(actionRunner(accountDeleteSessions)) account - .command(`createAnonymousSession`) + .command(`create-anonymous-session`) .description(`Use this endpoint to allow a new user to register an anonymous account in your project. This route will also create a new session for the user. To allow the new user to convert an anonymous account to a normal account, you need to update its [email and password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) or create an [OAuth2 session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).`) .action(actionRunner(accountCreateAnonymousSession)) account - .command(`createEmailPasswordSession`) + .command(`create-email-password-session`) .description(`Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).`) .requiredOption(`--email `, `User email.`) .requiredOption(`--password `, `User password. Must be at least 8 chars.`) .action(actionRunner(accountCreateEmailPasswordSession)) account - .command(`updateMagicURLSession`) + .command(`update-magic-url-session`) .description(`Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.`) - .requiredOption(`--userId `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--secret `, `Valid verification token.`) .action(actionRunner(accountUpdateMagicURLSession)) account - .command(`createOAuth2Session`) + .command(`create-o-auth-2-session`) .description(`Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed. If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the email received from the OAuth2 provider and attach the new session to the existing user. If no matching user is found - the server will create a new user. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). `) .requiredOption(`--provider `, `OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom.`) .option(`--success `, `URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) @@ -1964,82 +1964,82 @@ account .action(actionRunner(accountCreateOAuth2Session)) account - .command(`updatePhoneSession`) + .command(`update-phone-session`) .description(`Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.`) - .requiredOption(`--userId `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--secret `, `Valid verification token.`) .action(actionRunner(accountUpdatePhoneSession)) account - .command(`createSession`) + .command(`create-session`) .description(`Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.`) - .requiredOption(`--userId `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--secret `, `Secret of a token generated by login methods. For example, the 'createMagicURLToken' or 'createPhoneToken' methods.`) .action(actionRunner(accountCreateSession)) account - .command(`getSession`) + .command(`get-session`) .description(`Use this endpoint to get a logged in user's session using a Session ID. Inputting 'current' will return the current session being used.`) - .requiredOption(`--sessionId `, `Session ID. Use the string 'current' to get the current device session.`) + .requiredOption(`--session-id `, `Session ID. Use the string 'current' to get the current device session.`) .action(actionRunner(accountGetSession)) account - .command(`updateSession`) + .command(`update-session`) .description(`Use this endpoint to extend a session's length. Extending a session is useful when session expiry is short. If the session was created using an OAuth provider, this endpoint refreshes the access token from the provider.`) - .requiredOption(`--sessionId `, `Session ID. Use the string 'current' to update the current device session.`) + .requiredOption(`--session-id `, `Session ID. Use the string 'current' to update the current device session.`) .action(actionRunner(accountUpdateSession)) account - .command(`deleteSession`) + .command(`delete-session`) .description(`Logout the user. Use 'current' as the session ID to logout on this device, use a session ID to logout on another device. If you're looking to logout the user on all devices, use [Delete Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) instead.`) - .requiredOption(`--sessionId `, `Session ID. Use the string 'current' to delete the current device session.`) + .requiredOption(`--session-id `, `Session ID. Use the string 'current' to delete the current device session.`) .action(actionRunner(accountDeleteSession)) account - .command(`updateStatus`) + .command(`update-status`) .description(`Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead.`) .action(actionRunner(accountUpdateStatus)) account - .command(`createPushTarget`) + .command(`create-push-target`) .description(``) - .requiredOption(`--targetId `, `Target ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--target-id `, `Target ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--identifier `, `The target identifier (token, email, phone etc.)`) - .option(`--providerId `, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) + .option(`--provider-id `, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) .action(actionRunner(accountCreatePushTarget)) account - .command(`updatePushTarget`) + .command(`update-push-target`) .description(``) - .requiredOption(`--targetId `, `Target ID.`) + .requiredOption(`--target-id `, `Target ID.`) .requiredOption(`--identifier `, `The target identifier (token, email, phone etc.)`) .action(actionRunner(accountUpdatePushTarget)) account - .command(`deletePushTarget`) + .command(`delete-push-target`) .description(``) - .requiredOption(`--targetId `, `Target ID.`) + .requiredOption(`--target-id `, `Target ID.`) .action(actionRunner(accountDeletePushTarget)) account - .command(`createEmailToken`) + .command(`create-email-token`) .description(`Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).`) - .requiredOption(`--userId `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email `, `User email.`) .option(`--phrase `, `Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow.`, parseBool) .action(actionRunner(accountCreateEmailToken)) account - .command(`createMagicURLToken`) + .command(`create-magic-url-token`) .description(`Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). `) - .requiredOption(`--userId `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email `, `User email.`) .option(`--url `, `URL to redirect the user back to your app from the magic URL login. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) .option(`--phrase `, `Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow.`, parseBool) .action(actionRunner(accountCreateMagicURLToken)) account - .command(`createOAuth2Token`) + .command(`create-o-auth-2-token`) .description(`Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed. If authentication succeeds, 'userId' and 'secret' of a token will be appended to the success URL as query parameters. These can be used to create a new session using the [Create session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).`) .requiredOption(`--provider `, `OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom.`) .option(`--success `, `URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) @@ -2048,34 +2048,34 @@ account .action(actionRunner(accountCreateOAuth2Token)) account - .command(`createPhoneToken`) + .command(`create-phone-token`) .description(`Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).`) - .requiredOption(`--userId `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--phone `, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .action(actionRunner(accountCreatePhoneToken)) account - .command(`createVerification`) + .command(`create-verification`) .description(`Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days. Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. `) .requiredOption(`--url `, `URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) .action(actionRunner(accountCreateVerification)) account - .command(`updateVerification`) + .command(`update-verification`) .description(`Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.`) - .requiredOption(`--userId `, `User ID.`) + .requiredOption(`--user-id `, `User ID.`) .requiredOption(`--secret `, `Valid verification token.`) .action(actionRunner(accountUpdateVerification)) account - .command(`createPhoneVerification`) + .command(`create-phone-verification`) .description(`Use this endpoint to send a verification SMS to the currently logged in user. This endpoint is meant for use after updating a user's phone number using the [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) endpoint. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). The verification code sent to the user's phone number is valid for 15 minutes.`) .action(actionRunner(accountCreatePhoneVerification)) account - .command(`updatePhoneVerification`) + .command(`update-phone-verification`) .description(`Use this endpoint to complete the user phone verification process. Use the **userId** and **secret** that were sent to your user's phone number to verify the user email ownership. If confirmed this route will return a 200 status code.`) - .requiredOption(`--userId `, `User ID.`) + .requiredOption(`--user-id `, `User ID.`) .requiredOption(`--secret `, `Valid verification token.`) .action(actionRunner(accountUpdatePhoneVerification)) diff --git a/lib/commands/avatars.js b/lib/commands/avatars.js index 4d423d6..c0649d8 100644 --- a/lib/commands/avatars.js +++ b/lib/commands/avatars.js @@ -428,7 +428,7 @@ const avatarsGetQR = async ({text,size,margin,download,parseOutput = true, overr } avatars - .command(`getBrowser`) + .command(`get-browser`) .description(`You can use this endpoint to show different browser icons to your users. The code argument receives the browser code as it appears in your user [GET /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) endpoint. Use width, height and quality arguments to change the output settings. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.`) .requiredOption(`--code `, `Browser Code.`) .option(`--width `, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger) @@ -438,7 +438,7 @@ avatars .action(actionRunner(avatarsGetBrowser)) avatars - .command(`getCreditCard`) + .command(`get-credit-card`) .description(`The credit card endpoint will return you the icon of the credit card provider you need. Use width, height and quality arguments to change the output settings. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. `) .requiredOption(`--code `, `Credit Card Code. Possible values: amex, argencard, cabal, cencosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.`) .option(`--width `, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger) @@ -448,14 +448,14 @@ avatars .action(actionRunner(avatarsGetCreditCard)) avatars - .command(`getFavicon`) - .description(`Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL. `) + .command(`get-favicon`) + .description(`Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL. This endpoint does not follow HTTP redirects.`) .requiredOption(`--url `, `Website URL which you want to fetch the favicon from.`) .requiredOption(`--destination `, `output file path.`) .action(actionRunner(avatarsGetFavicon)) avatars - .command(`getFlag`) + .command(`get-flag`) .description(`You can use this endpoint to show different country flags icons to your users. The code argument receives the 2 letter country code. Use width, height and quality arguments to change the output settings. Country codes follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. `) .requiredOption(`--code `, `Country Code. ISO Alpha-2 country code format.`) .option(`--width `, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger) @@ -465,8 +465,8 @@ avatars .action(actionRunner(avatarsGetFlag)) avatars - .command(`getImage`) - .description(`Use this endpoint to fetch a remote image URL and crop it to any image size you want. This endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 400x400px. `) + .command(`get-image`) + .description(`Use this endpoint to fetch a remote image URL and crop it to any image size you want. This endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 400x400px. This endpoint does not follow HTTP redirects.`) .requiredOption(`--url `, `Image URL which you want to crop.`) .option(`--width `, `Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400.`, parseInteger) .option(`--height `, `Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400.`, parseInteger) @@ -474,7 +474,7 @@ avatars .action(actionRunner(avatarsGetImage)) avatars - .command(`getInitials`) + .command(`get-initials`) .description(`Use this endpoint to show your user initials avatar icon on your website or app. By default, this route will try to print your logged-in user name or email initials. You can also overwrite the user name if you pass the 'name' parameter. If no name is given and no user is logged, an empty avatar will be returned. You can use the color and background params to change the avatar colors. By default, a random theme will be selected. The random theme will persist for the user's initials when reloading the same theme will always return for the same initials. When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. `) .option(`--name `, `Full Name. When empty, current user name or email will be used. Max length: 128 chars.`) .option(`--width `, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger) @@ -484,7 +484,7 @@ avatars .action(actionRunner(avatarsGetInitials)) avatars - .command(`getQR`) + .command(`get-qr`) .description(`Converts a given plain text to a QR code image. You can use the query parameters to change the size and style of the resulting image. `) .requiredOption(`--text `, `Plain text to be converted to QR code image.`) .option(`--size `, `QR code size. Pass an integer between 1 to 1000. Defaults to 400.`, parseInteger) diff --git a/lib/commands/databases.js b/lib/commands/databases.js index d2b989b..3174403 100644 --- a/lib/commands/databases.js +++ b/lib/commands/databases.js @@ -2123,13 +2123,13 @@ databases databases .command(`create`) .description(`Create a new Database. `) - .requiredOption(`--databaseId `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--database-id `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name `, `Database name. Max length: 128 chars.`) .option(`--enabled `, `Is the database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.`, parseBool) .action(actionRunner(databasesCreate)) databases - .command(`getUsage`) + .command(`get-usage`) .description(``) .option(`--range `, `'Date range.`) .action(actionRunner(databasesGetUsage)) @@ -2137,14 +2137,14 @@ databases databases .command(`get`) .description(`Get a database by its unique ID. This endpoint response returns a JSON object with the database metadata.`) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGet)) databases .command(`update`) .description(`Update a database by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .requiredOption(`--name `, `Database name. Max length: 128 chars.`) .option(`--enabled `, `Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.`, parseBool) .action(actionRunner(databasesUpdate)) @@ -2152,69 +2152,69 @@ databases databases .command(`delete`) .description(`Delete a database by its unique ID. Only API keys with with databases.write scope can delete a database.`) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .action(actionRunner(databasesDelete)) databases - .command(`listCollections`) + .command(`list-collections`) .description(`Get a list of all collections that belong to the provided databaseId. You can use the search parameter to filter your results.`) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .option(`--queries [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, enabled, documentSecurity`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListCollections)) databases - .command(`createCollection`) + .command(`create-collection`) .description(`Create a new Collection. Before using this route, you should create a new database resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name `, `Collection name. Max length: 128 chars.`) .option(`--permissions [permissions...]`, `An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`) - .option(`--documentSecurity `, `Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) + .option(`--document-security `, `Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) .option(`--enabled `, `Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.`, parseBool) .action(actionRunner(databasesCreateCollection)) databases - .command(`getCollection`) + .command(`get-collection`) .description(`Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetCollection)) databases - .command(`updateCollection`) + .command(`update-collection`) .description(`Update a collection by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) .requiredOption(`--name `, `Collection name. Max length: 128 chars.`) .option(`--permissions [permissions...]`, `An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).`) - .option(`--documentSecurity `, `Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) + .option(`--document-security `, `Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) .option(`--enabled `, `Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.`, parseBool) .action(actionRunner(databasesUpdateCollection)) databases - .command(`deleteCollection`) + .command(`delete-collection`) .description(`Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) .action(actionRunner(databasesDeleteCollection)) databases - .command(`listAttributes`) + .command(`list-attributes`) .description(`List attributes in the collection.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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: key, type, size, required, array, status, error`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListAttributes)) databases - .command(`createBooleanAttribute`) + .command(`create-boolean-attribute`) .description(`Create a boolean attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`, parseBool) @@ -2222,20 +2222,20 @@ databases .action(actionRunner(databasesCreateBooleanAttribute)) databases - .command(`updateBooleanAttribute`) + .command(`update-boolean-attribute`) .description(`Update a boolean attribute. Changing the 'default' value will not update already existing documents.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`, parseBool) .action(actionRunner(databasesUpdateBooleanAttribute)) databases - .command(`createDatetimeAttribute`) + .command(`create-datetime-attribute`) .description(`Create a date time attribute according to the ISO 8601 standard.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for the attribute in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Cannot be set when attribute is required.`) @@ -2243,20 +2243,20 @@ databases .action(actionRunner(databasesCreateDatetimeAttribute)) databases - .command(`updateDatetimeAttribute`) + .command(`update-datetime-attribute`) .description(`Update a date time attribute. Changing the 'default' value will not update already existing documents.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) .action(actionRunner(databasesUpdateDatetimeAttribute)) databases - .command(`createEmailAttribute`) + .command(`create-email-attribute`) .description(`Create an email attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) @@ -2264,20 +2264,20 @@ databases .action(actionRunner(databasesCreateEmailAttribute)) databases - .command(`updateEmailAttribute`) + .command(`update-email-attribute`) .description(`Update an email attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) .action(actionRunner(databasesUpdateEmailAttribute)) databases - .command(`createEnumAttribute`) + .command(`create-enum-attribute`) .description(`Create an enumeration attribute. The 'elements' param acts as a white-list of accepted values for this attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--elements [elements...]`, `Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 255 characters long.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) @@ -2286,10 +2286,10 @@ databases .action(actionRunner(databasesCreateEnumAttribute)) databases - .command(`updateEnumAttribute`) + .command(`update-enum-attribute`) .description(`Update an enum attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--elements [elements...]`, `Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 255 characters long.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) @@ -2297,10 +2297,10 @@ databases .action(actionRunner(databasesUpdateEnumAttribute)) databases - .command(`createFloatAttribute`) + .command(`create-float-attribute`) .description(`Create a float attribute. Optionally, minimum and maximum values can be provided. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--min `, `Minimum value to enforce on new documents`, parseInteger) @@ -2310,10 +2310,10 @@ databases .action(actionRunner(databasesCreateFloatAttribute)) databases - .command(`updateFloatAttribute`) + .command(`update-float-attribute`) .description(`Update a float attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .requiredOption(`--min `, `Minimum value to enforce on new documents`, parseInteger) @@ -2322,10 +2322,10 @@ databases .action(actionRunner(databasesUpdateFloatAttribute)) databases - .command(`createIntegerAttribute`) + .command(`create-integer-attribute`) .description(`Create an integer attribute. Optionally, minimum and maximum values can be provided. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--min `, `Minimum value to enforce on new documents`, parseInteger) @@ -2335,10 +2335,10 @@ databases .action(actionRunner(databasesCreateIntegerAttribute)) databases - .command(`updateIntegerAttribute`) + .command(`update-integer-attribute`) .description(`Update an integer attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .requiredOption(`--min `, `Minimum value to enforce on new documents`, parseInteger) @@ -2347,10 +2347,10 @@ databases .action(actionRunner(databasesUpdateIntegerAttribute)) databases - .command(`createIpAttribute`) + .command(`create-ip-attribute`) .description(`Create IP address attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) @@ -2358,33 +2358,33 @@ databases .action(actionRunner(databasesCreateIpAttribute)) databases - .command(`updateIpAttribute`) + .command(`update-ip-attribute`) .description(`Update an ip attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) .action(actionRunner(databasesUpdateIpAttribute)) databases - .command(`createRelationshipAttribute`) + .command(`create-relationship-attribute`) .description(`Create relationship attribute. [Learn more about relationship attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) - .requiredOption(`--relatedCollectionId `, `Related Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--related-collection-id `, `Related Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--type `, `Relation type`) - .option(`--twoWay `, `Is Two Way?`, parseBool) + .option(`--two-way `, `Is Two Way?`, parseBool) .option(`--key `, `Attribute Key.`) - .option(`--twoWayKey `, `Two Way Attribute Key.`) - .option(`--onDelete `, `Constraints option`) + .option(`--two-way-key `, `Two Way Attribute Key.`) + .option(`--on-delete `, `Constraints option`) .action(actionRunner(databasesCreateRelationshipAttribute)) databases - .command(`createStringAttribute`) + .command(`create-string-attribute`) .description(`Create a string attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--size `, `Attribute size for text attributes, in number of characters.`, parseInteger) .requiredOption(`--required `, `Is attribute required?`, parseBool) @@ -2394,20 +2394,20 @@ databases .action(actionRunner(databasesCreateStringAttribute)) databases - .command(`updateStringAttribute`) + .command(`update-string-attribute`) .description(`Update a string attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) .action(actionRunner(databasesUpdateStringAttribute)) databases - .command(`createUrlAttribute`) + .command(`create-url-attribute`) .description(`Create a URL attribute. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) @@ -2415,110 +2415,110 @@ databases .action(actionRunner(databasesCreateUrlAttribute)) databases - .command(`updateUrlAttribute`) + .command(`update-url-attribute`) .description(`Update an url attribute. Changing the 'default' value will not update already existing documents. `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .requiredOption(`--required `, `Is attribute required?`, parseBool) .option(`--xdefault `, `Default value for attribute when not provided. Cannot be set when attribute is required.`) .action(actionRunner(databasesUpdateUrlAttribute)) databases - .command(`getAttribute`) + .command(`get-attribute`) .description(`Get attribute by ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .action(actionRunner(databasesGetAttribute)) databases - .command(`deleteAttribute`) + .command(`delete-attribute`) .description(`Deletes an attribute.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) .action(actionRunner(databasesDeleteAttribute)) databases - .command(`updateRelationshipAttribute`) + .command(`update-relationship-attribute`) .description(`Update relationship attribute. [Learn more about relationship attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). `) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Attribute Key.`) - .option(`--onDelete `, `Constraints option`) + .option(`--on-delete `, `Constraints option`) .action(actionRunner(databasesUpdateRelationshipAttribute)) databases - .command(`listDocuments`) + .command(`list-documents`) .description(`Get a list of all the user's documents in a given collection. You can use the query params to filter your results.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListDocuments)) databases - .command(`createDocument`) + .command(`create-document`) .description(`Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents.`) - .requiredOption(`--documentId `, `Document ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents.`) + .requiredOption(`--document-id `, `Document ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--data `, `Document data as JSON object.`) .option(`--permissions [permissions...]`, `An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`) .action(actionRunner(databasesCreateDocument)) databases - .command(`getDocument`) + .command(`get-document`) .description(`Get a document by its unique ID. This endpoint response returns a JSON object with the document data.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) - .requiredOption(`--documentId `, `Document ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--document-id `, `Document ID.`) .option(`--queries [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.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetDocument)) databases - .command(`updateDocument`) + .command(`update-document`) .description(`Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) - .requiredOption(`--documentId `, `Document ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) + .requiredOption(`--document-id `, `Document ID.`) .option(`--data `, `Document data as JSON object. Include only attribute and value pairs to be updated.`) .option(`--permissions [permissions...]`, `An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).`) .action(actionRunner(databasesUpdateDocument)) databases - .command(`deleteDocument`) + .command(`delete-document`) .description(`Delete a document by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) - .requiredOption(`--documentId `, `Document ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--document-id `, `Document ID.`) .action(actionRunner(databasesDeleteDocument)) databases - .command(`listDocumentLogs`) + .command(`list-document-logs`) .description(`Get the document activity logs list by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) - .requiredOption(`--documentId `, `Document ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) + .requiredOption(`--document-id `, `Document ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(databasesListDocumentLogs)) databases - .command(`listIndexes`) + .command(`list-indexes`) .description(`List indexes in the collection.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .option(`--queries [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: key, type, status, attributes, error`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesListIndexes)) databases - .command(`createIndex`) + .command(`create-index`) .description(`Creates an index on the attributes listed. Your index should include all the attributes you will query in a single request. Attributes can be 'key', 'fulltext', and 'unique'.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Index Key.`) .requiredOption(`--type `, `Index type.`) .requiredOption(`--attributes [attributes...]`, `Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long.`) @@ -2526,48 +2526,48 @@ databases .action(actionRunner(databasesCreateIndex)) databases - .command(`getIndex`) + .command(`get-index`) .description(`Get index by ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Index Key.`) .action(actionRunner(databasesGetIndex)) databases - .command(`deleteIndex`) + .command(`delete-index`) .description(`Delete an index.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`) .requiredOption(`--key `, `Index Key.`) .action(actionRunner(databasesDeleteIndex)) databases - .command(`listCollectionLogs`) + .command(`list-collection-logs`) .description(`Get the collection activity logs list by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(databasesListCollectionLogs)) databases - .command(`getCollectionUsage`) + .command(`get-collection-usage`) .description(``) - .requiredOption(`--databaseId `, `Database ID.`) - .requiredOption(`--collectionId `, `Collection ID.`) + .requiredOption(`--database-id `, `Database ID.`) + .requiredOption(`--collection-id `, `Collection ID.`) .option(`--range `, `Date range.`) .action(actionRunner(databasesGetCollectionUsage)) databases - .command(`listLogs`) + .command(`list-logs`) .description(`Get the database activity logs list by its unique ID.`) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(databasesListLogs)) databases - .command(`getDatabaseUsage`) + .command(`get-database-usage`) .description(``) - .requiredOption(`--databaseId `, `Database ID.`) + .requiredOption(`--database-id `, `Database ID.`) .option(`--range `, `'Date range.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(databasesGetDatabaseUsage)) diff --git a/lib/commands/functions.js b/lib/commands/functions.js index f169303..7f82da9 100644 --- a/lib/commands/functions.js +++ b/lib/commands/functions.js @@ -1258,7 +1258,7 @@ functions functions .command(`create`) .description(`Create a new function. You can pass a list of [permissions](https://appwrite.io/docs/permissions) to allow different project users or team with access to execute the function using the client API.`) - .requiredOption(`--functionId `, `Function ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--function-id `, `Function ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name `, `Function name. Max length: 128 chars.`) .requiredOption(`--runtime `, `Execution runtime.`) .option(`--execute [execute...]`, `An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.`) @@ -1270,24 +1270,24 @@ functions .option(`--entrypoint `, `Entrypoint File. This path is relative to the "providerRootDirectory".`) .option(`--commands `, `Build Commands.`) .option(`--scopes [scopes...]`, `List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed.`) - .option(`--installationId `, `Appwrite Installation ID for VCS (Version Control System) deployment.`) - .option(`--providerRepositoryId `, `Repository ID of the repo linked to the function.`) - .option(`--providerBranch `, `Production branch for the repo linked to the function.`) - .option(`--providerSilentMode `, `Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.`, parseBool) - .option(`--providerRootDirectory `, `Path to function code in the linked repo.`) - .option(`--templateRepository `, `Repository name of the template.`) - .option(`--templateOwner `, `The name of the owner of the template.`) - .option(`--templateRootDirectory `, `Path to function code in the template repo.`) - .option(`--templateBranch `, `Production branch for the repo linked to the function template.`) + .option(`--installation-id `, `Appwrite Installation ID for VCS (Version Control System) deployment.`) + .option(`--provider-repository-id `, `Repository ID of the repo linked to the function.`) + .option(`--provider-branch `, `Production branch for the repo linked to the function.`) + .option(`--provider-silent-mode `, `Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.`, parseBool) + .option(`--provider-root-directory `, `Path to function code in the linked repo.`) + .option(`--template-repository `, `Repository name of the template.`) + .option(`--template-owner `, `The name of the owner of the template.`) + .option(`--template-root-directory `, `Path to function code in the template repo.`) + .option(`--template-branch `, `Production branch for the repo linked to the function template.`) .action(actionRunner(functionsCreate)) functions - .command(`listRuntimes`) + .command(`list-runtimes`) .description(`Get a list of all runtimes that are currently active on your instance.`) .action(actionRunner(functionsListRuntimes)) functions - .command(`getUsage`) + .command(`get-usage`) .description(``) .option(`--range `, `Date range.`) .action(actionRunner(functionsGetUsage)) @@ -1295,14 +1295,14 @@ functions functions .command(`get`) .description(`Get a function by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGet)) functions .command(`update`) .description(`Update function by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .requiredOption(`--name `, `Function name. Max length: 128 chars.`) .option(`--runtime `, `Execution runtime.`) .option(`--execute [execute...]`, `An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.`) @@ -1314,32 +1314,32 @@ functions .option(`--entrypoint `, `Entrypoint File. This path is relative to the "providerRootDirectory".`) .option(`--commands `, `Build Commands.`) .option(`--scopes [scopes...]`, `List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed.`) - .option(`--installationId `, `Appwrite Installation ID for VCS (Version Controle System) deployment.`) - .option(`--providerRepositoryId `, `Repository ID of the repo linked to the function`) - .option(`--providerBranch `, `Production branch for the repo linked to the function`) - .option(`--providerSilentMode `, `Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.`, parseBool) - .option(`--providerRootDirectory `, `Path to function code in the linked repo.`) + .option(`--installation-id `, `Appwrite Installation ID for VCS (Version Controle System) deployment.`) + .option(`--provider-repository-id `, `Repository ID of the repo linked to the function`) + .option(`--provider-branch `, `Production branch for the repo linked to the function`) + .option(`--provider-silent-mode `, `Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.`, parseBool) + .option(`--provider-root-directory `, `Path to function code in the linked repo.`) .action(actionRunner(functionsUpdate)) functions .command(`delete`) .description(`Delete a function by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .action(actionRunner(functionsDelete)) functions - .command(`listDeployments`) + .command(`list-deployments`) .description(`Get a list of all the project's code deployments. You can use the query params to filter your results.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .option(`--queries [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: size, buildId, activate, entrypoint, commands`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsListDeployments)) functions - .command(`createDeployment`) + .command(`create-deployment`) .description(`Create a new function code deployment. Use this endpoint to upload a new version of your code function. To execute your newly uploaded code, you'll need to update the function's deployment to use your new deployment UID. This endpoint accepts a tar.gz file compressed with your code. Make sure to include any dependencies your code has within the compressed file. You can learn more about code packaging in the [Appwrite Cloud Functions tutorial](https://appwrite.io/docs/functions). Use the "command" param to set the entrypoint used to execute your code.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .requiredOption(`--code `, `Gzip file with your code package. When used with the Appwrite CLI, pass the path to your code directory, and the CLI will automatically package your code. Use a path that is within the current directory.`) .requiredOption(`--activate `, `Automatically activate the deployment when it is finished building.`, parseBool) .option(`--entrypoint `, `Entrypoint File.`) @@ -1347,129 +1347,129 @@ functions .action(actionRunner(functionsCreateDeployment)) functions - .command(`getDeployment`) + .command(`get-deployment`) .description(`Get a code deployment by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetDeployment)) functions - .command(`updateDeployment`) + .command(`update-deployment`) .description(`Update the function code deployment ID using the unique function ID. Use this endpoint to switch the code deployment that should be executed by the execution endpoint.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) .action(actionRunner(functionsUpdateDeployment)) functions - .command(`deleteDeployment`) + .command(`delete-deployment`) .description(`Delete a code deployment by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) .action(actionRunner(functionsDeleteDeployment)) functions - .command(`createBuild`) + .command(`create-build`) .description(``) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) - .option(`--buildId `, `Build unique ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) + .option(`--build-id `, `Build unique ID.`) .action(actionRunner(functionsCreateBuild)) functions - .command(`updateDeploymentBuild`) + .command(`update-deployment-build`) .description(``) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) .action(actionRunner(functionsUpdateDeploymentBuild)) functions - .command(`downloadDeployment`) + .command(`download-deployment`) .description(`Get a Deployment's contents by its unique ID. This endpoint supports range requests for partial or streaming file download.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) .requiredOption(`--destination `, `output file path.`) .action(actionRunner(functionsDownloadDeployment)) functions - .command(`listExecutions`) + .command(`list-executions`) .description(`Get a list of all the current user function execution logs. You can use the query params to filter your results.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .option(`--queries [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: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsListExecutions)) functions - .command(`createExecution`) + .command(`create-execution`) .description(`Trigger a function execution. The returned object will return you the current execution status. You can ping the 'Get Execution' endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.`) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .option(`--body `, `HTTP body of execution. Default value is empty string.`) .option(`--async `, `Execute code in the background. Default value is false.`, parseBool) .option(`--xpath `, `HTTP path of execution. Path can include query params. Default value is /`) .option(`--method `, `HTTP method of execution. Default value is GET.`) .option(`--headers `, `HTTP headers of execution. Defaults to empty.`) - .option(`--scheduledAt `, `Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at `, `Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(functionsCreateExecution)) functions - .command(`getExecution`) + .command(`get-execution`) .description(`Get a function execution log by its unique ID.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--executionId `, `Execution ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--execution-id `, `Execution ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetExecution)) functions - .command(`deleteExecution`) + .command(`delete-execution`) .description(`Delete a function execution by its unique ID. `) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--executionId `, `Execution ID.`) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--execution-id `, `Execution ID.`) .action(actionRunner(functionsDeleteExecution)) functions - .command(`getFunctionUsage`) + .command(`get-function-usage`) .description(``) - .requiredOption(`--functionId `, `Function ID.`) + .requiredOption(`--function-id `, `Function ID.`) .option(`--range `, `Date range.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsGetFunctionUsage)) functions - .command(`listVariables`) + .command(`list-variables`) .description(`Get a list of all variables of a specific function.`) - .requiredOption(`--functionId `, `Function unique ID.`) + .requiredOption(`--function-id `, `Function unique ID.`) .action(actionRunner(functionsListVariables)) functions - .command(`createVariable`) + .command(`create-variable`) .description(`Create a new function environment variable. These variables can be accessed in the function at runtime as environment variables.`) - .requiredOption(`--functionId `, `Function unique ID.`) + .requiredOption(`--function-id `, `Function unique ID.`) .requiredOption(`--key `, `Variable key. Max length: 255 chars.`) .requiredOption(`--value `, `Variable value. Max length: 8192 chars.`) .action(actionRunner(functionsCreateVariable)) functions - .command(`getVariable`) + .command(`get-variable`) .description(`Get a variable by its unique ID.`) - .requiredOption(`--functionId `, `Function unique ID.`) - .requiredOption(`--variableId `, `Variable unique ID.`) + .requiredOption(`--function-id `, `Function unique ID.`) + .requiredOption(`--variable-id `, `Variable unique ID.`) .action(actionRunner(functionsGetVariable)) functions - .command(`updateVariable`) + .command(`update-variable`) .description(`Update variable by its unique ID.`) - .requiredOption(`--functionId `, `Function unique ID.`) - .requiredOption(`--variableId `, `Variable unique ID.`) + .requiredOption(`--function-id `, `Function unique ID.`) + .requiredOption(`--variable-id `, `Variable unique ID.`) .requiredOption(`--key `, `Variable key. Max length: 255 chars.`) .option(`--value `, `Variable value. Max length: 8192 chars.`) .action(actionRunner(functionsUpdateVariable)) functions - .command(`deleteVariable`) + .command(`delete-variable`) .description(`Delete a variable by its unique ID.`) - .requiredOption(`--functionId `, `Function unique ID.`) - .requiredOption(`--variableId `, `Variable unique ID.`) + .requiredOption(`--function-id `, `Function unique ID.`) + .requiredOption(`--variable-id `, `Variable unique ID.`) .action(actionRunner(functionsDeleteVariable)) module.exports = { diff --git a/lib/commands/generic.js b/lib/commands/generic.js index bc913fe..691ff85 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -187,7 +187,8 @@ const logout = new Command("logout") const sessions = globalConfig.getSessions(); const current = globalConfig.getCurrentSession(); - if (current === '') { + if (current === '' || !sessions.length) { + log('No active sessions found.'); return; } if (sessions.length === 1) { @@ -223,9 +224,9 @@ const client = new Command("client") .configureHelp({ helpWidth: process.stdout.columns || 80 }) - .option("-ss, --selfSigned ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) + .option("-ss, --self-signed ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) .option("-e, --endpoint ", "Set your Appwrite server endpoint") - .option("-p, --projectId ", "Set your Appwrite project ID") + .option("-p, --project-id ", "Set your Appwrite project ID") .option("-k, --key ", "Set your Appwrite server's API key") .option("-d, --debug", "Print CLI debug information") .option("-r, --reset", "Reset the CLI configuration") diff --git a/lib/commands/health.js b/lib/commands/health.js index 9f028ee..70a291b 100644 --- a/lib/commands/health.js +++ b/lib/commands/health.js @@ -819,128 +819,128 @@ health .action(actionRunner(healthGet)) health - .command(`getAntivirus`) + .command(`get-antivirus`) .description(`Check the Appwrite Antivirus server is up and connection is successful.`) .action(actionRunner(healthGetAntivirus)) health - .command(`getCache`) + .command(`get-cache`) .description(`Check the Appwrite in-memory cache servers are up and connection is successful.`) .action(actionRunner(healthGetCache)) health - .command(`getCertificate`) + .command(`get-certificate`) .description(`Get the SSL certificate for a domain`) .option(`--domain `, `string`) .action(actionRunner(healthGetCertificate)) health - .command(`getDB`) + .command(`get-db`) .description(`Check the Appwrite database servers are up and connection is successful.`) .action(actionRunner(healthGetDB)) health - .command(`getPubSub`) + .command(`get-pub-sub`) .description(`Check the Appwrite pub-sub servers are up and connection is successful.`) .action(actionRunner(healthGetPubSub)) health - .command(`getQueue`) + .command(`get-queue`) .description(`Check the Appwrite queue messaging servers are up and connection is successful.`) .action(actionRunner(healthGetQueue)) health - .command(`getQueueBuilds`) + .command(`get-queue-builds`) .description(`Get the number of builds that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueBuilds)) health - .command(`getQueueCertificates`) + .command(`get-queue-certificates`) .description(`Get the number of certificates that are waiting to be issued against [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueCertificates)) health - .command(`getQueueDatabases`) + .command(`get-queue-databases`) .description(`Get the number of database changes that are waiting to be processed in the Appwrite internal queue server.`) .option(`--name `, `Queue name for which to check the queue size`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueDatabases)) health - .command(`getQueueDeletes`) + .command(`get-queue-deletes`) .description(`Get the number of background destructive changes that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueDeletes)) health - .command(`getFailedJobs`) + .command(`get-failed-jobs`) .description(`Returns the amount of failed jobs in a given queue. `) .requiredOption(`--name `, `The name of the queue`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetFailedJobs)) health - .command(`getQueueFunctions`) + .command(`get-queue-functions`) .description(`Get the number of function executions that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueFunctions)) health - .command(`getQueueLogs`) + .command(`get-queue-logs`) .description(`Get the number of logs that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueLogs)) health - .command(`getQueueMails`) + .command(`get-queue-mails`) .description(`Get the number of mails that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueMails)) health - .command(`getQueueMessaging`) + .command(`get-queue-messaging`) .description(`Get the number of messages that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueMessaging)) health - .command(`getQueueMigrations`) + .command(`get-queue-migrations`) .description(`Get the number of migrations that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueMigrations)) health - .command(`getQueueUsage`) + .command(`get-queue-usage`) .description(`Get the number of metrics that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueUsage)) health - .command(`getQueueUsageDump`) + .command(`get-queue-usage-dump`) .description(`Get the number of projects containing metrics that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueUsageDump)) health - .command(`getQueueWebhooks`) + .command(`get-queue-webhooks`) .description(`Get the number of webhooks that are waiting to be processed in the Appwrite internal queue server.`) .option(`--threshold `, `Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.`, parseInteger) .action(actionRunner(healthGetQueueWebhooks)) health - .command(`getStorage`) + .command(`get-storage`) .description(`Check the Appwrite storage device is up and connection is successful.`) .action(actionRunner(healthGetStorage)) health - .command(`getStorageLocal`) + .command(`get-storage-local`) .description(`Check the Appwrite local storage device is up and connection is successful.`) .action(actionRunner(healthGetStorageLocal)) health - .command(`getTime`) + .command(`get-time`) .description(`Check the Appwrite server time is synced with Google remote NTP server. We use this technology to smoothly handle leap seconds with no disruptive events. The [Network Time Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is used by hundreds of millions of computers and devices to synchronize their clocks over the Internet. If your computer sets its own clock, it likely uses NTP.`) .action(actionRunner(healthGetTime)) diff --git a/lib/commands/init.js b/lib/commands/init.js index 9cbe03b..69e34c1 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -110,6 +110,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => { answers = await inquirer.prompt(questionsInitProjectAutopull); if(answers.autopull) { cliConfig.all = true; + cliConfig.force = true; await pullResources(); } else { log("You can run 'appwrite pull all' to synchronize all of your existing resources."); @@ -333,9 +334,9 @@ const init = new Command("init") init .command("project") .description("Init a new Appwrite project") - .option("--organizationId ", "Appwrite organization ID") - .option("--projectId ", "Appwrite project ID") - .option("--projectName ", "Appwrite project ID") + .option("--organization-id ", "Appwrite organization ID") + .option("--project-id ", "Appwrite project ID") + .option("--project-name ", "Appwrite project ID") .action(actionRunner(initProject)); init diff --git a/lib/commands/locale.js b/lib/commands/locale.js index ef02bf9..1382b96 100644 --- a/lib/commands/locale.js +++ b/lib/commands/locale.js @@ -293,37 +293,37 @@ locale .action(actionRunner(localeGet)) locale - .command(`listCodes`) + .command(`list-codes`) .description(`List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).`) .action(actionRunner(localeListCodes)) locale - .command(`listContinents`) + .command(`list-continents`) .description(`List of all continents. You can use the locale header to get the data in a supported language.`) .action(actionRunner(localeListContinents)) locale - .command(`listCountries`) + .command(`list-countries`) .description(`List of all countries. You can use the locale header to get the data in a supported language.`) .action(actionRunner(localeListCountries)) locale - .command(`listCountriesEU`) + .command(`list-countries-eu`) .description(`List of all countries that are currently members of the EU. You can use the locale header to get the data in a supported language.`) .action(actionRunner(localeListCountriesEU)) locale - .command(`listCountriesPhones`) + .command(`list-countries-phones`) .description(`List of all countries phone codes. You can use the locale header to get the data in a supported language.`) .action(actionRunner(localeListCountriesPhones)) locale - .command(`listCurrencies`) + .command(`list-currencies`) .description(`List of all currencies, including currency symbol, name, plural, and decimal digits for all major and minor currencies. You can use the locale header to get the data in a supported language.`) .action(actionRunner(localeListCurrencies)) locale - .command(`listLanguages`) + .command(`list-languages`) .description(`List of all languages classified by ISO 639-1 including 2-letter code, name in English, and name in the respective language.`) .action(actionRunner(localeListLanguages)) diff --git a/lib/commands/messaging.js b/lib/commands/messaging.js index 4093463..b775315 100644 --- a/lib/commands/messaging.js +++ b/lib/commands/messaging.js @@ -2455,7 +2455,7 @@ const messagingDeleteSubscriber = async ({topicId,subscriberId,parseOutput = tru } messaging - .command(`listMessages`) + .command(`list-messages`) .description(`Get a list of all messages from the current Appwrite project.`) .option(`--queries [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: scheduledAt, deliveredAt, deliveredTotal, status, description, providerType`) .option(`--search `, `Search term to filter your list results. Max length: 256 chars.`) @@ -2463,9 +2463,9 @@ messaging .action(actionRunner(messagingListMessages)) messaging - .command(`createEmail`) + .command(`create-email`) .description(`Create a new email message.`) - .requiredOption(`--messageId `, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--message-id `, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--subject `, `Email Subject.`) .requiredOption(`--content `, `Email Content.`) .option(`--topics [topics...]`, `List of Topic IDs.`) @@ -2476,13 +2476,13 @@ messaging .option(`--attachments [attachments...]`, `Array of compound ID strings of bucket IDs and file IDs to be attached to the email. They should be formatted as :.`) .option(`--draft `, `Is message a draft`, parseBool) .option(`--html `, `Is content of type HTML`, parseBool) - .option(`--scheduledAt `, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at `, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(messagingCreateEmail)) messaging - .command(`updateEmail`) + .command(`update-email`) .description(`Update an email message by its unique ID. `) - .requiredOption(`--messageId `, `Message ID.`) + .requiredOption(`--message-id `, `Message ID.`) .option(`--topics [topics...]`, `List of Topic IDs.`) .option(`--users [users...]`, `List of User IDs.`) .option(`--targets [targets...]`, `List of Targets IDs.`) @@ -2492,14 +2492,14 @@ messaging .option(`--html `, `Is content of type HTML`, parseBool) .option(`--cc [cc...]`, `Array of target IDs to be added as CC.`) .option(`--bcc [bcc...]`, `Array of target IDs to be added as BCC.`) - .option(`--scheduledAt `, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at `, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .option(`--attachments [attachments...]`, `Array of compound ID strings of bucket IDs and file IDs to be attached to the email. They should be formatted as :.`) .action(actionRunner(messagingUpdateEmail)) messaging - .command(`createPush`) + .command(`create-push`) .description(`Create a new push notification.`) - .requiredOption(`--messageId `, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--message-id `, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--title `, `Title for push notification.`) .requiredOption(`--body <body>`, `Body for push notification.`) .option(`--topics [topics...]`, `List of Topic IDs.`) @@ -2514,13 +2514,13 @@ messaging .option(`--tag <tag>`, `Tag for push notification. Available only for Android Platform.`) .option(`--badge <badge>`, `Badge for push notification. Available only for IOS Platform.`) .option(`--draft <draft>`, `Is message a draft`, parseBool) - .option(`--scheduledAt <scheduledAt>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at <scheduled-at>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(messagingCreatePush)) messaging - .command(`updatePush`) + .command(`update-push`) .description(`Update a push notification by its unique ID. `) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .option(`--topics [topics...]`, `List of Topic IDs.`) .option(`--users [users...]`, `List of User IDs.`) .option(`--targets [targets...]`, `List of Targets IDs.`) @@ -2535,63 +2535,63 @@ messaging .option(`--tag <tag>`, `Tag for push notification. Available only for Android platforms.`) .option(`--badge <badge>`, `Badge for push notification. Available only for iOS platforms.`, parseInteger) .option(`--draft <draft>`, `Is message a draft`, parseBool) - .option(`--scheduledAt <scheduledAt>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at <scheduled-at>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(messagingUpdatePush)) messaging - .command(`createSms`) + .command(`create-sms`) .description(`Create a new SMS message.`) - .requiredOption(`--messageId <messageId>`, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--message-id <message-id>`, `Message ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--content <content>`, `SMS Content.`) .option(`--topics [topics...]`, `List of Topic IDs.`) .option(`--users [users...]`, `List of User IDs.`) .option(`--targets [targets...]`, `List of Targets IDs.`) .option(`--draft <draft>`, `Is message a draft`, parseBool) - .option(`--scheduledAt <scheduledAt>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at <scheduled-at>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(messagingCreateSms)) messaging - .command(`updateSms`) + .command(`update-sms`) .description(`Update an email message by its unique ID. `) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .option(`--topics [topics...]`, `List of Topic IDs.`) .option(`--users [users...]`, `List of User IDs.`) .option(`--targets [targets...]`, `List of Targets IDs.`) .option(`--content <content>`, `Email Content.`) .option(`--draft <draft>`, `Is message a draft`, parseBool) - .option(`--scheduledAt <scheduledAt>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at <scheduled-at>`, `Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) .action(actionRunner(messagingUpdateSms)) messaging - .command(`getMessage`) + .command(`get-message`) .description(`Get a message by its unique ID. `) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetMessage)) messaging .command(`delete`) .description(`Delete a message. If the message is not a draft or scheduled, but has been sent, this will not recall the message.`) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .action(actionRunner(messagingDelete)) messaging - .command(`listMessageLogs`) + .command(`list-message-logs`) .description(`Get the message activity logs listed by its unique ID.`) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListMessageLogs)) messaging - .command(`listTargets`) + .command(`list-targets`) .description(`Get a list of the targets associated with a message.`) - .requiredOption(`--messageId <messageId>`, `Message ID.`) + .requiredOption(`--message-id <message-id>`, `Message ID.`) .option(`--queries [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: userId, providerId, identifier, providerType`) .action(actionRunner(messagingListTargets)) messaging - .command(`listProviders`) + .command(`list-providers`) .description(`Get a list of all providers from the current Appwrite project.`) .option(`--queries [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, provider, type, enabled`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) @@ -2599,282 +2599,282 @@ messaging .action(actionRunner(messagingListProviders)) messaging - .command(`createApnsProvider`) + .command(`create-apns-provider`) .description(`Create a new Apple Push Notification service provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) - .option(`--authKey <authKey>`, `APNS authentication key.`) - .option(`--authKeyId <authKeyId>`, `APNS authentication key ID.`) - .option(`--teamId <teamId>`, `APNS team ID.`) - .option(`--bundleId <bundleId>`, `APNS bundle ID.`) + .option(`--auth-key <auth-key>`, `APNS authentication key.`) + .option(`--auth-key-id <auth-key-id>`, `APNS authentication key ID.`) + .option(`--team-id <team-id>`, `APNS team ID.`) + .option(`--bundle-id <bundle-id>`, `APNS bundle ID.`) .option(`--sandbox <sandbox>`, `Use APNS sandbox environment.`, parseBool) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateApnsProvider)) messaging - .command(`updateApnsProvider`) + .command(`update-apns-provider`) .description(`Update a Apple Push Notification service provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--authKey <authKey>`, `APNS authentication key.`) - .option(`--authKeyId <authKeyId>`, `APNS authentication key ID.`) - .option(`--teamId <teamId>`, `APNS team ID.`) - .option(`--bundleId <bundleId>`, `APNS bundle ID.`) + .option(`--auth-key <auth-key>`, `APNS authentication key.`) + .option(`--auth-key-id <auth-key-id>`, `APNS authentication key ID.`) + .option(`--team-id <team-id>`, `APNS team ID.`) + .option(`--bundle-id <bundle-id>`, `APNS bundle ID.`) .option(`--sandbox <sandbox>`, `Use APNS sandbox environment.`, parseBool) .action(actionRunner(messagingUpdateApnsProvider)) messaging - .command(`createFcmProvider`) + .command(`create-fcm-provider`) .description(`Create a new Firebase Cloud Messaging provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) - .option(`--serviceAccountJSON <serviceAccountJSON>`, `FCM service account JSON.`) + .option(`--service-account-json <service-account-json>`, `FCM service account JSON.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateFcmProvider)) messaging - .command(`updateFcmProvider`) + .command(`update-fcm-provider`) .description(`Update a Firebase Cloud Messaging provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--serviceAccountJSON <serviceAccountJSON>`, `FCM service account JSON.`) + .option(`--service-account-json <service-account-json>`, `FCM service account JSON.`) .action(actionRunner(messagingUpdateFcmProvider)) messaging - .command(`createMailgunProvider`) + .command(`create-mailgun-provider`) .description(`Create a new Mailgun provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) - .option(`--apiKey <apiKey>`, `Mailgun API Key.`) + .option(`--api-key <api-key>`, `Mailgun API Key.`) .option(`--domain <domain>`, `Mailgun Domain.`) - .option(`--isEuRegion <isEuRegion>`, `Set as EU region.`, parseBool) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the reply to field for the mail. Default value is sender name. Reply to name must have reply to email as well.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the reply to field for the mail. Default value is sender email. Reply to email must have reply to name as well.`) + .option(`--is-eu-region <is-eu-region>`, `Set as EU region.`, parseBool) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the reply to field for the mail. Default value is sender name. Reply to name must have reply to email as well.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the reply to field for the mail. Default value is sender email. Reply to email must have reply to name as well.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateMailgunProvider)) messaging - .command(`updateMailgunProvider`) + .command(`update-mailgun-provider`) .description(`Update a Mailgun provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) - .option(`--apiKey <apiKey>`, `Mailgun API Key.`) + .option(`--api-key <api-key>`, `Mailgun API Key.`) .option(`--domain <domain>`, `Mailgun Domain.`) - .option(`--isEuRegion <isEuRegion>`, `Set as EU region.`, parseBool) + .option(`--is-eu-region <is-eu-region>`, `Set as EU region.`, parseBool) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the reply to field for the mail. Default value is sender name.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the reply to field for the mail. Default value is sender email.`) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the reply to field for the mail. Default value is sender name.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the reply to field for the mail. Default value is sender email.`) .action(actionRunner(messagingUpdateMailgunProvider)) messaging - .command(`createMsg91Provider`) + .command(`create-msg-91-provider`) .description(`Create a new MSG91 provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) - .option(`--templateId <templateId>`, `Msg91 template ID`) - .option(`--senderId <senderId>`, `Msg91 sender ID.`) - .option(`--authKey <authKey>`, `Msg91 auth key.`) + .option(`--template-id <template-id>`, `Msg91 template ID`) + .option(`--sender-id <sender-id>`, `Msg91 sender ID.`) + .option(`--auth-key <auth-key>`, `Msg91 auth key.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateMsg91Provider)) messaging - .command(`updateMsg91Provider`) + .command(`update-msg-91-provider`) .description(`Update a MSG91 provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--templateId <templateId>`, `Msg91 template ID.`) - .option(`--senderId <senderId>`, `Msg91 sender ID.`) - .option(`--authKey <authKey>`, `Msg91 auth key.`) + .option(`--template-id <template-id>`, `Msg91 template ID.`) + .option(`--sender-id <sender-id>`, `Msg91 sender ID.`) + .option(`--auth-key <auth-key>`, `Msg91 auth key.`) .action(actionRunner(messagingUpdateMsg91Provider)) messaging - .command(`createSendgridProvider`) + .command(`create-sendgrid-provider`) .description(`Create a new Sendgrid provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) - .option(`--apiKey <apiKey>`, `Sendgrid API key.`) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the reply to field for the mail. Default value is sender name.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the reply to field for the mail. Default value is sender email.`) + .option(`--api-key <api-key>`, `Sendgrid API key.`) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the reply to field for the mail. Default value is sender name.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the reply to field for the mail. Default value is sender email.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateSendgridProvider)) messaging - .command(`updateSendgridProvider`) + .command(`update-sendgrid-provider`) .description(`Update a Sendgrid provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--apiKey <apiKey>`, `Sendgrid API key.`) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the Reply To field for the mail. Default value is Sender Name.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the Reply To field for the mail. Default value is Sender Email.`) + .option(`--api-key <api-key>`, `Sendgrid API key.`) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the Reply To field for the mail. Default value is Sender Name.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the Reply To field for the mail. Default value is Sender Email.`) .action(actionRunner(messagingUpdateSendgridProvider)) messaging - .command(`createSmtpProvider`) + .command(`create-smtp-provider`) .description(`Create a new SMTP provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) .requiredOption(`--host <host>`, `SMTP hosts. Either a single hostname or multiple semicolon-delimited hostnames. You can also specify a different port for each host such as 'smtp1.example.com:25;smtp2.example.com'. You can also specify encryption type, for example: 'tls://smtp1.example.com:587;ssl://smtp2.example.com:465"'. Hosts will be tried in order.`) .option(`--port <port>`, `The default SMTP server port.`, parseInteger) .option(`--username <username>`, `Authentication username.`) .option(`--password <password>`, `Authentication password.`) .option(`--encryption <encryption>`, `Encryption type. Can be omitted, 'ssl', or 'tls'`) - .option(`--autoTLS <autoTLS>`, `Enable SMTP AutoTLS feature.`, parseBool) + .option(`--auto-tls <auto-tls>`, `Enable SMTP AutoTLS feature.`, parseBool) .option(`--mailer <mailer>`, `The value to use for the X-Mailer header.`) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the reply to field for the mail. Default value is sender name.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the reply to field for the mail. Default value is sender email.`) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the reply to field for the mail. Default value is sender name.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the reply to field for the mail. Default value is sender email.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateSmtpProvider)) messaging - .command(`updateSmtpProvider`) + .command(`update-smtp-provider`) .description(`Update a SMTP provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--host <host>`, `SMTP hosts. Either a single hostname or multiple semicolon-delimited hostnames. You can also specify a different port for each host such as 'smtp1.example.com:25;smtp2.example.com'. You can also specify encryption type, for example: 'tls://smtp1.example.com:587;ssl://smtp2.example.com:465"'. Hosts will be tried in order.`) .option(`--port <port>`, `SMTP port.`, parseInteger) .option(`--username <username>`, `Authentication username.`) .option(`--password <password>`, `Authentication password.`) .option(`--encryption <encryption>`, `Encryption type. Can be 'ssl' or 'tls'`) - .option(`--autoTLS <autoTLS>`, `Enable SMTP AutoTLS feature.`, parseBool) + .option(`--auto-tls <auto-tls>`, `Enable SMTP AutoTLS feature.`, parseBool) .option(`--mailer <mailer>`, `The value to use for the X-Mailer header.`) - .option(`--fromName <fromName>`, `Sender Name.`) - .option(`--fromEmail <fromEmail>`, `Sender email address.`) - .option(`--replyToName <replyToName>`, `Name set in the Reply To field for the mail. Default value is Sender Name.`) - .option(`--replyToEmail <replyToEmail>`, `Email set in the Reply To field for the mail. Default value is Sender Email.`) + .option(`--from-name <from-name>`, `Sender Name.`) + .option(`--from-email <from-email>`, `Sender email address.`) + .option(`--reply-to-name <reply-to-name>`, `Name set in the Reply To field for the mail. Default value is Sender Name.`) + .option(`--reply-to-email <reply-to-email>`, `Email set in the Reply To field for the mail. Default value is Sender Email.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingUpdateSmtpProvider)) messaging - .command(`createTelesignProvider`) + .command(`create-telesign-provider`) .description(`Create a new Telesign provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) .option(`--from <from>`, `Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) - .option(`--customerId <customerId>`, `Telesign customer ID.`) - .option(`--apiKey <apiKey>`, `Telesign API key.`) + .option(`--customer-id <customer-id>`, `Telesign customer ID.`) + .option(`--api-key <api-key>`, `Telesign API key.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateTelesignProvider)) messaging - .command(`updateTelesignProvider`) + .command(`update-telesign-provider`) .description(`Update a Telesign provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--customerId <customerId>`, `Telesign customer ID.`) - .option(`--apiKey <apiKey>`, `Telesign API key.`) + .option(`--customer-id <customer-id>`, `Telesign customer ID.`) + .option(`--api-key <api-key>`, `Telesign API key.`) .option(`--from <from>`, `Sender number.`) .action(actionRunner(messagingUpdateTelesignProvider)) messaging - .command(`createTextmagicProvider`) + .command(`create-textmagic-provider`) .description(`Create a new Textmagic provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) .option(`--from <from>`, `Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .option(`--username <username>`, `Textmagic username.`) - .option(`--apiKey <apiKey>`, `Textmagic apiKey.`) + .option(`--api-key <api-key>`, `Textmagic apiKey.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateTextmagicProvider)) messaging - .command(`updateTextmagicProvider`) + .command(`update-textmagic-provider`) .description(`Update a Textmagic provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .option(`--username <username>`, `Textmagic username.`) - .option(`--apiKey <apiKey>`, `Textmagic apiKey.`) + .option(`--api-key <api-key>`, `Textmagic apiKey.`) .option(`--from <from>`, `Sender number.`) .action(actionRunner(messagingUpdateTextmagicProvider)) messaging - .command(`createTwilioProvider`) + .command(`create-twilio-provider`) .description(`Create a new Twilio provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) .option(`--from <from>`, `Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) - .option(`--accountSid <accountSid>`, `Twilio account secret ID.`) - .option(`--authToken <authToken>`, `Twilio authentication token.`) + .option(`--account-sid <account-sid>`, `Twilio account secret ID.`) + .option(`--auth-token <auth-token>`, `Twilio authentication token.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateTwilioProvider)) messaging - .command(`updateTwilioProvider`) + .command(`update-twilio-provider`) .description(`Update a Twilio provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--accountSid <accountSid>`, `Twilio account secret ID.`) - .option(`--authToken <authToken>`, `Twilio authentication token.`) + .option(`--account-sid <account-sid>`, `Twilio account secret ID.`) + .option(`--auth-token <auth-token>`, `Twilio authentication token.`) .option(`--from <from>`, `Sender number.`) .action(actionRunner(messagingUpdateTwilioProvider)) messaging - .command(`createVonageProvider`) + .command(`create-vonage-provider`) .description(`Create a new Vonage provider.`) - .requiredOption(`--providerId <providerId>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Provider name.`) .option(`--from <from>`, `Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) - .option(`--apiKey <apiKey>`, `Vonage API key.`) - .option(`--apiSecret <apiSecret>`, `Vonage API secret.`) + .option(`--api-key <api-key>`, `Vonage API key.`) + .option(`--api-secret <api-secret>`, `Vonage API secret.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) .action(actionRunner(messagingCreateVonageProvider)) messaging - .command(`updateVonageProvider`) + .command(`update-vonage-provider`) .description(`Update a Vonage provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--name <name>`, `Provider name.`) .option(`--enabled <enabled>`, `Set as enabled.`, parseBool) - .option(`--apiKey <apiKey>`, `Vonage API key.`) - .option(`--apiSecret <apiSecret>`, `Vonage API secret.`) + .option(`--api-key <api-key>`, `Vonage API key.`) + .option(`--api-secret <api-secret>`, `Vonage API secret.`) .option(`--from <from>`, `Sender number.`) .action(actionRunner(messagingUpdateVonageProvider)) messaging - .command(`getProvider`) + .command(`get-provider`) .description(`Get a provider by its unique ID. `) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetProvider)) messaging - .command(`deleteProvider`) + .command(`delete-provider`) .description(`Delete a provider by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .action(actionRunner(messagingDeleteProvider)) messaging - .command(`listProviderLogs`) + .command(`list-provider-logs`) .description(`Get the provider activity logs listed by its unique ID.`) - .requiredOption(`--providerId <providerId>`, `Provider ID.`) + .requiredOption(`--provider-id <provider-id>`, `Provider ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(messagingListProviderLogs)) messaging - .command(`listSubscriberLogs`) + .command(`list-subscriber-logs`) .description(`Get the subscriber activity logs listed by its unique ID.`) - .requiredOption(`--subscriberId <subscriberId>`, `Subscriber ID.`) + .requiredOption(`--subscriber-id <subscriber-id>`, `Subscriber ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(messagingListSubscriberLogs)) messaging - .command(`listTopics`) + .command(`list-topics`) .description(`Get a list of all topics from the current Appwrite project.`) .option(`--queries [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, description, emailTotal, smsTotal, pushTotal`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) @@ -2882,70 +2882,70 @@ messaging .action(actionRunner(messagingListTopics)) messaging - .command(`createTopic`) + .command(`create-topic`) .description(`Create a new topic.`) - .requiredOption(`--topicId <topicId>`, `Topic ID. Choose a custom Topic ID or a new Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID. Choose a custom Topic ID or a new Topic ID.`) .requiredOption(`--name <name>`, `Topic Name.`) .option(`--subscribe [subscribe...]`, `An array of role strings with subscribe permission. By default all users are granted with any subscribe permission. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.`) .action(actionRunner(messagingCreateTopic)) messaging - .command(`getTopic`) + .command(`get-topic`) .description(`Get a topic by its unique ID. `) - .requiredOption(`--topicId <topicId>`, `Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingGetTopic)) messaging - .command(`updateTopic`) + .command(`update-topic`) .description(`Update a topic by its unique ID. `) - .requiredOption(`--topicId <topicId>`, `Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID.`) .option(`--name <name>`, `Topic Name.`) .option(`--subscribe [subscribe...]`, `An array of role strings with subscribe permission. By default all users are granted with any subscribe permission. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.`) .action(actionRunner(messagingUpdateTopic)) messaging - .command(`deleteTopic`) + .command(`delete-topic`) .description(`Delete a topic by its unique ID.`) - .requiredOption(`--topicId <topicId>`, `Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID.`) .action(actionRunner(messagingDeleteTopic)) messaging - .command(`listTopicLogs`) + .command(`list-topic-logs`) .description(`Get the topic activity logs listed by its unique ID.`) - .requiredOption(`--topicId <topicId>`, `Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(messagingListTopicLogs)) messaging - .command(`listSubscribers`) + .command(`list-subscribers`) .description(`Get a list of all subscribers from the current Appwrite project.`) - .requiredOption(`--topicId <topicId>`, `Topic ID. The topic ID subscribed to.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID. The topic ID subscribed to.`) .option(`--queries [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, provider, type, enabled`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(messagingListSubscribers)) messaging - .command(`createSubscriber`) + .command(`create-subscriber`) .description(`Create a new subscriber.`) - .requiredOption(`--topicId <topicId>`, `Topic ID. The topic ID to subscribe to.`) - .requiredOption(`--subscriberId <subscriberId>`, `Subscriber ID. Choose a custom Subscriber ID or a new Subscriber ID.`) - .requiredOption(`--targetId <targetId>`, `Target ID. The target ID to link to the specified Topic ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID. The topic ID to subscribe to.`) + .requiredOption(`--subscriber-id <subscriber-id>`, `Subscriber ID. Choose a custom Subscriber ID or a new Subscriber ID.`) + .requiredOption(`--target-id <target-id>`, `Target ID. The target ID to link to the specified Topic ID.`) .action(actionRunner(messagingCreateSubscriber)) messaging - .command(`getSubscriber`) + .command(`get-subscriber`) .description(`Get a subscriber by its unique ID. `) - .requiredOption(`--topicId <topicId>`, `Topic ID. The topic ID subscribed to.`) - .requiredOption(`--subscriberId <subscriberId>`, `Subscriber ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID. The topic ID subscribed to.`) + .requiredOption(`--subscriber-id <subscriber-id>`, `Subscriber ID.`) .action(actionRunner(messagingGetSubscriber)) messaging - .command(`deleteSubscriber`) + .command(`delete-subscriber`) .description(`Delete a subscriber by its unique ID.`) - .requiredOption(`--topicId <topicId>`, `Topic ID. The topic ID subscribed to.`) - .requiredOption(`--subscriberId <subscriberId>`, `Subscriber ID.`) + .requiredOption(`--topic-id <topic-id>`, `Topic ID. The topic ID subscribed to.`) + .requiredOption(`--subscriber-id <subscriber-id>`, `Subscriber ID.`) .action(actionRunner(messagingDeleteSubscriber)) module.exports = { diff --git a/lib/commands/migrations.js b/lib/commands/migrations.js index 02e5db3..3b80874 100644 --- a/lib/commands/migrations.js +++ b/lib/commands/migrations.js @@ -743,68 +743,68 @@ migrations .action(actionRunner(migrationsList)) migrations - .command(`createAppwriteMigration`) + .command(`create-appwrite-migration`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) .requiredOption(`--endpoint <endpoint>`, `Source's Appwrite Endpoint`) - .requiredOption(`--projectId <projectId>`, `Source's Project ID`) - .requiredOption(`--apiKey <apiKey>`, `Source's API Key`) + .requiredOption(`--project-id <project-id>`, `Source's Project ID`) + .requiredOption(`--api-key <api-key>`, `Source's API Key`) .action(actionRunner(migrationsCreateAppwriteMigration)) migrations - .command(`getAppwriteReport`) + .command(`get-appwrite-report`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) .requiredOption(`--endpoint <endpoint>`, `Source's Appwrite Endpoint`) - .requiredOption(`--projectID <projectID>`, `Source's Project ID`) + .requiredOption(`--project-id <project-id>`, `Source's Project ID`) .requiredOption(`--key <key>`, `Source's API Key`) .action(actionRunner(migrationsGetAppwriteReport)) migrations - .command(`createFirebaseMigration`) + .command(`create-firebase-migration`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) - .requiredOption(`--serviceAccount <serviceAccount>`, `JSON of the Firebase service account credentials`) + .requiredOption(`--service-account <service-account>`, `JSON of the Firebase service account credentials`) .action(actionRunner(migrationsCreateFirebaseMigration)) migrations - .command(`deleteFirebaseAuth`) + .command(`delete-firebase-auth`) .description(``) .action(actionRunner(migrationsDeleteFirebaseAuth)) migrations - .command(`createFirebaseOAuthMigration`) + .command(`create-firebase-o-auth-migration`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) - .requiredOption(`--projectId <projectId>`, `Project ID of the Firebase Project`) + .requiredOption(`--project-id <project-id>`, `Project ID of the Firebase Project`) .action(actionRunner(migrationsCreateFirebaseOAuthMigration)) migrations - .command(`listFirebaseProjects`) + .command(`list-firebase-projects`) .description(``) .action(actionRunner(migrationsListFirebaseProjects)) migrations - .command(`getFirebaseReport`) + .command(`get-firebase-report`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) - .requiredOption(`--serviceAccount <serviceAccount>`, `JSON of the Firebase service account credentials`) + .requiredOption(`--service-account <service-account>`, `JSON of the Firebase service account credentials`) .action(actionRunner(migrationsGetFirebaseReport)) migrations - .command(`getFirebaseReportOAuth`) + .command(`get-firebase-report-o-auth`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) - .requiredOption(`--projectId <projectId>`, `Project ID`) + .requiredOption(`--project-id <project-id>`, `Project ID`) .action(actionRunner(migrationsGetFirebaseReportOAuth)) migrations - .command(`createNHostMigration`) + .command(`create-n-host-migration`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) .requiredOption(`--subdomain <subdomain>`, `Source's Subdomain`) .requiredOption(`--region <region>`, `Source's Region`) - .requiredOption(`--adminSecret <adminSecret>`, `Source's Admin Secret`) + .requiredOption(`--admin-secret <admin-secret>`, `Source's Admin Secret`) .requiredOption(`--database <database>`, `Source's Database Name`) .requiredOption(`--username <username>`, `Source's Database Username`) .requiredOption(`--password <password>`, `Source's Database Password`) @@ -812,12 +812,12 @@ migrations .action(actionRunner(migrationsCreateNHostMigration)) migrations - .command(`getNHostReport`) + .command(`get-n-host-report`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate.`) .requiredOption(`--subdomain <subdomain>`, `Source's Subdomain.`) .requiredOption(`--region <region>`, `Source's Region.`) - .requiredOption(`--adminSecret <adminSecret>`, `Source's Admin Secret.`) + .requiredOption(`--admin-secret <admin-secret>`, `Source's Admin Secret.`) .requiredOption(`--database <database>`, `Source's Database Name.`) .requiredOption(`--username <username>`, `Source's Database Username.`) .requiredOption(`--password <password>`, `Source's Database Password.`) @@ -825,24 +825,24 @@ migrations .action(actionRunner(migrationsGetNHostReport)) migrations - .command(`createSupabaseMigration`) + .command(`create-supabase-migration`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) .requiredOption(`--endpoint <endpoint>`, `Source's Supabase Endpoint`) - .requiredOption(`--apiKey <apiKey>`, `Source's API Key`) - .requiredOption(`--databaseHost <databaseHost>`, `Source's Database Host`) + .requiredOption(`--api-key <api-key>`, `Source's API Key`) + .requiredOption(`--database-host <database-host>`, `Source's Database Host`) .requiredOption(`--username <username>`, `Source's Database Username`) .requiredOption(`--password <password>`, `Source's Database Password`) .option(`--port <port>`, `Source's Database Port`, parseInteger) .action(actionRunner(migrationsCreateSupabaseMigration)) migrations - .command(`getSupabaseReport`) + .command(`get-supabase-report`) .description(``) .requiredOption(`--resources [resources...]`, `List of resources to migrate`) .requiredOption(`--endpoint <endpoint>`, `Source's Supabase Endpoint.`) - .requiredOption(`--apiKey <apiKey>`, `Source's API Key.`) - .requiredOption(`--databaseHost <databaseHost>`, `Source's Database Host.`) + .requiredOption(`--api-key <api-key>`, `Source's API Key.`) + .requiredOption(`--database-host <database-host>`, `Source's Database Host.`) .requiredOption(`--username <username>`, `Source's Database Username.`) .requiredOption(`--password <password>`, `Source's Database Password.`) .option(`--port <port>`, `Source's Database Port.`, parseInteger) @@ -851,19 +851,19 @@ migrations migrations .command(`get`) .description(``) - .requiredOption(`--migrationId <migrationId>`, `Migration unique ID.`) + .requiredOption(`--migration-id <migration-id>`, `Migration unique ID.`) .action(actionRunner(migrationsGet)) migrations .command(`retry`) .description(``) - .requiredOption(`--migrationId <migrationId>`, `Migration unique ID.`) + .requiredOption(`--migration-id <migration-id>`, `Migration unique ID.`) .action(actionRunner(migrationsRetry)) migrations .command(`delete`) .description(``) - .requiredOption(`--migrationId <migrationId>`, `Migration ID.`) + .requiredOption(`--migration-id <migration-id>`, `Migration ID.`) .action(actionRunner(migrationsDelete)) module.exports = { diff --git a/lib/commands/project.js b/lib/commands/project.js index 1251a64..c81e2b5 100644 --- a/lib/commands/project.js +++ b/lib/commands/project.js @@ -257,43 +257,43 @@ const projectDeleteVariable = async ({variableId,parseOutput = true, overrideFor } project - .command(`getUsage`) + .command(`get-usage`) .description(``) - .requiredOption(`--startDate <startDate>`, `Starting date for the usage`) - .requiredOption(`--endDate <endDate>`, `End date for the usage`) + .requiredOption(`--start-date <start-date>`, `Starting date for the usage`) + .requiredOption(`--end-date <end-date>`, `End date for the usage`) .option(`--period <period>`, `Period used`) .action(actionRunner(projectGetUsage)) project - .command(`listVariables`) + .command(`list-variables`) .description(`Get a list of all project variables. These variables will be accessible in all Appwrite Functions at runtime.`) .action(actionRunner(projectListVariables)) project - .command(`createVariable`) + .command(`create-variable`) .description(`Create a new project variable. This variable will be accessible in all Appwrite Functions at runtime.`) .requiredOption(`--key <key>`, `Variable key. Max length: 255 chars.`) .requiredOption(`--value <value>`, `Variable value. Max length: 8192 chars.`) .action(actionRunner(projectCreateVariable)) project - .command(`getVariable`) + .command(`get-variable`) .description(`Get a project variable by its unique ID.`) - .requiredOption(`--variableId <variableId>`, `Variable unique ID.`) + .requiredOption(`--variable-id <variable-id>`, `Variable unique ID.`) .action(actionRunner(projectGetVariable)) project - .command(`updateVariable`) + .command(`update-variable`) .description(`Update project variable by its unique ID. This variable will be accessible in all Appwrite Functions at runtime.`) - .requiredOption(`--variableId <variableId>`, `Variable unique ID.`) + .requiredOption(`--variable-id <variable-id>`, `Variable unique ID.`) .requiredOption(`--key <key>`, `Variable key. Max length: 255 chars.`) .option(`--value <value>`, `Variable value. Max length: 8192 chars.`) .action(actionRunner(projectUpdateVariable)) project - .command(`deleteVariable`) + .command(`delete-variable`) .description(`Delete a project variable by its unique ID. `) - .requiredOption(`--variableId <variableId>`, `Variable unique ID.`) + .requiredOption(`--variable-id <variable-id>`, `Variable unique ID.`) .action(actionRunner(projectDeleteVariable)) module.exports = { diff --git a/lib/commands/projects.js b/lib/commands/projects.js index 5b5c153..4623d2e 100644 --- a/lib/commands/projects.js +++ b/lib/commands/projects.js @@ -1950,199 +1950,199 @@ projects projects .command(`create`) .description(``) - .requiredOption(`--projectId <projectId>`, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, and hyphen. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--project-id <project-id>`, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, and hyphen. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Project name. Max length: 128 chars.`) - .requiredOption(`--teamId <teamId>`, `Team unique ID.`) + .requiredOption(`--team-id <team-id>`, `Team unique ID.`) .option(`--region <region>`, `Project Region.`) .option(`--description <description>`, `Project description. Max length: 256 chars.`) .option(`--logo <logo>`, `Project logo.`) .option(`--url <url>`, `Project URL.`) - .option(`--legalName <legalName>`, `Project legal Name. Max length: 256 chars.`) - .option(`--legalCountry <legalCountry>`, `Project legal Country. Max length: 256 chars.`) - .option(`--legalState <legalState>`, `Project legal State. Max length: 256 chars.`) - .option(`--legalCity <legalCity>`, `Project legal City. Max length: 256 chars.`) - .option(`--legalAddress <legalAddress>`, `Project legal Address. Max length: 256 chars.`) - .option(`--legalTaxId <legalTaxId>`, `Project legal Tax ID. Max length: 256 chars.`) + .option(`--legal-name <legal-name>`, `Project legal Name. Max length: 256 chars.`) + .option(`--legal-country <legal-country>`, `Project legal Country. Max length: 256 chars.`) + .option(`--legal-state <legal-state>`, `Project legal State. Max length: 256 chars.`) + .option(`--legal-city <legal-city>`, `Project legal City. Max length: 256 chars.`) + .option(`--legal-address <legal-address>`, `Project legal Address. Max length: 256 chars.`) + .option(`--legal-tax-id <legal-tax-id>`, `Project legal Tax ID. Max length: 256 chars.`) .action(actionRunner(projectsCreate)) projects .command(`get`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGet)) projects .command(`update`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--name <name>`, `Project name. Max length: 128 chars.`) .option(`--description <description>`, `Project description. Max length: 256 chars.`) .option(`--logo <logo>`, `Project logo.`) .option(`--url <url>`, `Project URL.`) - .option(`--legalName <legalName>`, `Project legal name. Max length: 256 chars.`) - .option(`--legalCountry <legalCountry>`, `Project legal country. Max length: 256 chars.`) - .option(`--legalState <legalState>`, `Project legal state. Max length: 256 chars.`) - .option(`--legalCity <legalCity>`, `Project legal city. Max length: 256 chars.`) - .option(`--legalAddress <legalAddress>`, `Project legal address. Max length: 256 chars.`) - .option(`--legalTaxId <legalTaxId>`, `Project legal tax ID. Max length: 256 chars.`) + .option(`--legal-name <legal-name>`, `Project legal name. Max length: 256 chars.`) + .option(`--legal-country <legal-country>`, `Project legal country. Max length: 256 chars.`) + .option(`--legal-state <legal-state>`, `Project legal state. Max length: 256 chars.`) + .option(`--legal-city <legal-city>`, `Project legal city. Max length: 256 chars.`) + .option(`--legal-address <legal-address>`, `Project legal address. Max length: 256 chars.`) + .option(`--legal-tax-id <legal-tax-id>`, `Project legal tax ID. Max length: 256 chars.`) .action(actionRunner(projectsUpdate)) projects .command(`delete`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .action(actionRunner(projectsDelete)) projects - .command(`updateApiStatus`) + .command(`update-api-status`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--api <api>`, `API name.`) .requiredOption(`--status <status>`, `API status.`, parseBool) .action(actionRunner(projectsUpdateApiStatus)) projects - .command(`updateApiStatusAll`) + .command(`update-api-status-all`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--status <status>`, `API status.`, parseBool) .action(actionRunner(projectsUpdateApiStatusAll)) projects - .command(`updateAuthDuration`) + .command(`update-auth-duration`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--duration <duration>`, `Project session length in seconds. Max length: 31536000 seconds.`, parseInteger) .action(actionRunner(projectsUpdateAuthDuration)) projects - .command(`updateAuthLimit`) + .command(`update-auth-limit`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--limit <limit>`, `Set the max number of users allowed in this project. Use 0 for unlimited.`, parseInteger) .action(actionRunner(projectsUpdateAuthLimit)) projects - .command(`updateAuthSessionsLimit`) + .command(`update-auth-sessions-limit`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--limit <limit>`, `Set the max number of users allowed in this project. Value allowed is between 1-100. Default is 10`, parseInteger) .action(actionRunner(projectsUpdateAuthSessionsLimit)) projects - .command(`updateMockNumbers`) + .command(`update-mock-numbers`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--numbers [numbers...]`, `An array of mock numbers and their corresponding verification codes (OTPs). Each number should be a valid E.164 formatted phone number. Maximum of 10 numbers are allowed.`) .action(actionRunner(projectsUpdateMockNumbers)) projects - .command(`updateAuthPasswordDictionary`) + .command(`update-auth-password-dictionary`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--enabled <enabled>`, `Set whether or not to enable checking user's password against most commonly used passwords. Default is false.`, parseBool) .action(actionRunner(projectsUpdateAuthPasswordDictionary)) projects - .command(`updateAuthPasswordHistory`) + .command(`update-auth-password-history`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--limit <limit>`, `Set the max number of passwords to store in user history. User can't choose a new password that is already stored in the password history list. Max number of passwords allowed in history is20. Default value is 0`, parseInteger) .action(actionRunner(projectsUpdateAuthPasswordHistory)) projects - .command(`updatePersonalDataCheck`) + .command(`update-personal-data-check`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--enabled <enabled>`, `Set whether or not to check a password for similarity with personal data. Default is false.`, parseBool) .action(actionRunner(projectsUpdatePersonalDataCheck)) projects - .command(`updateSessionAlerts`) + .command(`update-session-alerts`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--alerts <alerts>`, `Set to true to enable session emails.`, parseBool) .action(actionRunner(projectsUpdateSessionAlerts)) projects - .command(`updateAuthStatus`) + .command(`update-auth-status`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--method <method>`, `Auth Method. Possible values: email-password,magic-url,email-otp,anonymous,invites,jwt,phone`) .requiredOption(`--status <status>`, `Set the status of this auth method.`, parseBool) .action(actionRunner(projectsUpdateAuthStatus)) projects - .command(`createJWT`) + .command(`create-jwt`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--scopes [scopes...]`, `List of scopes allowed for JWT key. Maximum of 100 scopes are allowed.`) .option(`--duration <duration>`, `Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.`, parseInteger) .action(actionRunner(projectsCreateJWT)) projects - .command(`listKeys`) + .command(`list-keys`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListKeys)) projects - .command(`createKey`) + .command(`create-key`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--name <name>`, `Key name. Max length: 128 chars.`) .requiredOption(`--scopes [scopes...]`, `Key scopes list. Maximum of 100 scopes are allowed.`) .option(`--expire <expire>`, `Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.`) .action(actionRunner(projectsCreateKey)) projects - .command(`getKey`) + .command(`get-key`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--keyId <keyId>`, `Key unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--key-id <key-id>`, `Key unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetKey)) projects - .command(`updateKey`) + .command(`update-key`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--keyId <keyId>`, `Key unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--key-id <key-id>`, `Key unique ID.`) .requiredOption(`--name <name>`, `Key name. Max length: 128 chars.`) .requiredOption(`--scopes [scopes...]`, `Key scopes list. Maximum of 100 events are allowed.`) .option(`--expire <expire>`, `Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.`) .action(actionRunner(projectsUpdateKey)) projects - .command(`deleteKey`) + .command(`delete-key`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--keyId <keyId>`, `Key unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--key-id <key-id>`, `Key unique ID.`) .action(actionRunner(projectsDeleteKey)) projects - .command(`updateOAuth2`) + .command(`update-o-auth-2`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--provider <provider>`, `Provider Name`) - .option(`--appId <appId>`, `Provider app ID. Max length: 256 chars.`) + .option(`--app-id <app-id>`, `Provider app ID. Max length: 256 chars.`) .option(`--secret <secret>`, `Provider secret key. Max length: 512 chars.`) .option(`--enabled <enabled>`, `Provider status. Set to 'false' to disable new session creation.`, parseBool) .action(actionRunner(projectsUpdateOAuth2)) projects - .command(`listPlatforms`) + .command(`list-platforms`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListPlatforms)) projects - .command(`createPlatform`) + .command(`create-platform`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Platform type.`) .requiredOption(`--name <name>`, `Platform name. Max length: 128 chars.`) .option(`--key <key>`, `Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.`) @@ -2151,18 +2151,18 @@ projects .action(actionRunner(projectsCreatePlatform)) projects - .command(`getPlatform`) + .command(`get-platform`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--platformId <platformId>`, `Platform unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--platform-id <platform-id>`, `Platform unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetPlatform)) projects - .command(`updatePlatform`) + .command(`update-platform`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--platformId <platformId>`, `Platform unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--platform-id <platform-id>`, `Platform unique ID.`) .requiredOption(`--name <name>`, `Platform name. Max length: 128 chars.`) .option(`--key <key>`, `Package name for android or bundle ID for iOS. Max length: 256 chars.`) .option(`--store <store>`, `App store or Google Play store ID. Max length: 256 chars.`) @@ -2170,35 +2170,35 @@ projects .action(actionRunner(projectsUpdatePlatform)) projects - .command(`deletePlatform`) + .command(`delete-platform`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--platformId <platformId>`, `Platform unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--platform-id <platform-id>`, `Platform unique ID.`) .action(actionRunner(projectsDeletePlatform)) projects - .command(`updateServiceStatus`) + .command(`update-service-status`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--service <service>`, `Service name.`) .requiredOption(`--status <status>`, `Service status.`, parseBool) .action(actionRunner(projectsUpdateServiceStatus)) projects - .command(`updateServiceStatusAll`) + .command(`update-service-status-all`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--status <status>`, `Service status.`, parseBool) .action(actionRunner(projectsUpdateServiceStatusAll)) projects - .command(`updateSmtp`) + .command(`update-smtp`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--enabled <enabled>`, `Enable custom SMTP service`, parseBool) - .option(`--senderName <senderName>`, `Name of the email sender`) - .option(`--senderEmail <senderEmail>`, `Email of the sender`) - .option(`--replyTo <replyTo>`, `Reply to email`) + .option(`--sender-name <sender-name>`, `Name of the email sender`) + .option(`--sender-email <sender-email>`, `Email of the sender`) + .option(`--reply-to <reply-to>`, `Reply to email`) .option(`--host <host>`, `SMTP server host name`) .option(`--port <port>`, `SMTP server port`, parseInteger) .option(`--username <username>`, `SMTP server username`) @@ -2207,14 +2207,14 @@ projects .action(actionRunner(projectsUpdateSmtp)) projects - .command(`createSmtpTest`) + .command(`create-smtp-test`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--emails [emails...]`, `Array of emails to send test email to. Maximum of 10 emails are allowed.`) - .requiredOption(`--senderName <senderName>`, `Name of the email sender`) - .requiredOption(`--senderEmail <senderEmail>`, `Email of the sender`) + .requiredOption(`--sender-name <sender-name>`, `Name of the email sender`) + .requiredOption(`--sender-email <sender-email>`, `Email of the sender`) .requiredOption(`--host <host>`, `SMTP server host name`) - .option(`--replyTo <replyTo>`, `Reply to email`) + .option(`--reply-to <reply-to>`, `Reply to email`) .option(`--port <port>`, `SMTP server port`, parseInteger) .option(`--username <username>`, `SMTP server username`) .option(`--password <password>`, `SMTP server password`) @@ -2222,120 +2222,120 @@ projects .action(actionRunner(projectsCreateSmtpTest)) projects - .command(`updateTeam`) + .command(`update-team`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--teamId <teamId>`, `Team ID of the team to transfer project to.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID of the team to transfer project to.`) .action(actionRunner(projectsUpdateTeam)) projects - .command(`getEmailTemplate`) + .command(`get-email-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .action(actionRunner(projectsGetEmailTemplate)) projects - .command(`updateEmailTemplate`) + .command(`update-email-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .requiredOption(`--subject <subject>`, `Email Subject`) .requiredOption(`--message <message>`, `Template message`) - .option(`--senderName <senderName>`, `Name of the email sender`) - .option(`--senderEmail <senderEmail>`, `Email of the sender`) - .option(`--replyTo <replyTo>`, `Reply to email`) + .option(`--sender-name <sender-name>`, `Name of the email sender`) + .option(`--sender-email <sender-email>`, `Email of the sender`) + .option(`--reply-to <reply-to>`, `Reply to email`) .action(actionRunner(projectsUpdateEmailTemplate)) projects - .command(`deleteEmailTemplate`) + .command(`delete-email-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .action(actionRunner(projectsDeleteEmailTemplate)) projects - .command(`getSmsTemplate`) + .command(`get-sms-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .action(actionRunner(projectsGetSmsTemplate)) projects - .command(`updateSmsTemplate`) + .command(`update-sms-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .requiredOption(`--message <message>`, `Template message`) .action(actionRunner(projectsUpdateSmsTemplate)) projects - .command(`deleteSmsTemplate`) + .command(`delete-sms-template`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--type <type>`, `Template type`) .requiredOption(`--locale <locale>`, `Template locale`) .action(actionRunner(projectsDeleteSmsTemplate)) projects - .command(`listWebhooks`) + .command(`list-webhooks`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsListWebhooks)) projects - .command(`createWebhook`) + .command(`create-webhook`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) .requiredOption(`--name <name>`, `Webhook name. Max length: 128 chars.`) .requiredOption(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`) .requiredOption(`--url <url>`, `Webhook URL.`) .requiredOption(`--security <security>`, `Certificate verification, false for disabled or true for enabled.`, parseBool) .option(`--enabled <enabled>`, `Enable or disable a webhook.`, parseBool) - .option(`--httpUser <httpUser>`, `Webhook HTTP user. Max length: 256 chars.`) - .option(`--httpPass <httpPass>`, `Webhook HTTP password. Max length: 256 chars.`) + .option(`--http-user <http-user>`, `Webhook HTTP user. Max length: 256 chars.`) + .option(`--http-pass <http-pass>`, `Webhook HTTP password. Max length: 256 chars.`) .action(actionRunner(projectsCreateWebhook)) projects - .command(`getWebhook`) + .command(`get-webhook`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--webhookId <webhookId>`, `Webhook unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--webhook-id <webhook-id>`, `Webhook unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsGetWebhook)) projects - .command(`updateWebhook`) + .command(`update-webhook`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--webhookId <webhookId>`, `Webhook unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--webhook-id <webhook-id>`, `Webhook unique ID.`) .requiredOption(`--name <name>`, `Webhook name. Max length: 128 chars.`) .requiredOption(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`) .requiredOption(`--url <url>`, `Webhook URL.`) .requiredOption(`--security <security>`, `Certificate verification, false for disabled or true for enabled.`, parseBool) .option(`--enabled <enabled>`, `Enable or disable a webhook.`, parseBool) - .option(`--httpUser <httpUser>`, `Webhook HTTP user. Max length: 256 chars.`) - .option(`--httpPass <httpPass>`, `Webhook HTTP password. Max length: 256 chars.`) + .option(`--http-user <http-user>`, `Webhook HTTP user. Max length: 256 chars.`) + .option(`--http-pass <http-pass>`, `Webhook HTTP password. Max length: 256 chars.`) .action(actionRunner(projectsUpdateWebhook)) projects - .command(`deleteWebhook`) + .command(`delete-webhook`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--webhookId <webhookId>`, `Webhook unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--webhook-id <webhook-id>`, `Webhook unique ID.`) .action(actionRunner(projectsDeleteWebhook)) projects - .command(`updateWebhookSignature`) + .command(`update-webhook-signature`) .description(``) - .requiredOption(`--projectId <projectId>`, `Project unique ID.`) - .requiredOption(`--webhookId <webhookId>`, `Webhook unique ID.`) + .requiredOption(`--project-id <project-id>`, `Project unique ID.`) + .requiredOption(`--webhook-id <webhook-id>`, `Webhook unique ID.`) .action(actionRunner(projectsUpdateWebhookSignature)) module.exports = { diff --git a/lib/commands/proxy.js b/lib/commands/proxy.js index 0c6eb08..9cc74fa 100644 --- a/lib/commands/proxy.js +++ b/lib/commands/proxy.js @@ -218,36 +218,36 @@ const proxyUpdateRuleVerification = async ({ruleId,parseOutput = true, overrideF } proxy - .command(`listRules`) + .command(`list-rules`) .description(`Get a list of all the proxy rules. You can use the query params to filter your results.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: domain, resourceType, resourceId, url`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .action(actionRunner(proxyListRules)) proxy - .command(`createRule`) + .command(`create-rule`) .description(`Create a new proxy rule.`) .requiredOption(`--domain <domain>`, `Domain name.`) - .requiredOption(`--resourceType <resourceType>`, `Action definition for the rule. Possible values are "api", "function"`) - .option(`--resourceId <resourceId>`, `ID of resource for the action type. If resourceType is "api", leave empty. If resourceType is "function", provide ID of the function.`) + .requiredOption(`--resource-type <resource-type>`, `Action definition for the rule. Possible values are "api", "function"`) + .option(`--resource-id <resource-id>`, `ID of resource for the action type. If resourceType is "api", leave empty. If resourceType is "function", provide ID of the function.`) .action(actionRunner(proxyCreateRule)) proxy - .command(`getRule`) + .command(`get-rule`) .description(`Get a proxy rule by its unique ID.`) - .requiredOption(`--ruleId <ruleId>`, `Rule ID.`) + .requiredOption(`--rule-id <rule-id>`, `Rule ID.`) .action(actionRunner(proxyGetRule)) proxy - .command(`deleteRule`) + .command(`delete-rule`) .description(`Delete a proxy rule by its unique ID.`) - .requiredOption(`--ruleId <ruleId>`, `Rule ID.`) + .requiredOption(`--rule-id <rule-id>`, `Rule ID.`) .action(actionRunner(proxyDeleteRule)) proxy - .command(`updateRuleVerification`) + .command(`update-rule-verification`) .description(``) - .requiredOption(`--ruleId <ruleId>`, `Rule ID.`) + .requiredOption(`--rule-id <rule-id>`, `Rule ID.`) .action(actionRunner(proxyUpdateRuleVerification)) module.exports = { diff --git a/lib/commands/pull.js b/lib/commands/pull.js index d416f8e..a399aee 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -27,7 +27,7 @@ const pullResources = async () => { if (cliConfig.all) { for (let action of Object.values(actions)) { cliConfig.all = true; - await action(); + await action({ returnOnZero: true }); } } else { const answers = await inquirer.prompt(questionsPullResources[0]); @@ -92,7 +92,7 @@ const pullFunctions = async ({ code }) => { if (!fs.existsSync(func['path'])) { fs.mkdirSync(func['path'], { recursive: true }); } - + if(code === false) { warn("Source code download skipped."); } else if(!func['deployment']) { @@ -114,14 +114,14 @@ const pullFunctions = async ({ code }) => { overrideForCli: true, parseOutput: false }); - + tar.extract({ sync: true, cwd: func['path'], file: compressedFileName, strict: false, }); - + fs.rmSync(compressedFileName); } } diff --git a/lib/commands/push.js b/lib/commands/push.js index d516f8b..c0c8bfe 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -2,13 +2,13 @@ const chalk = require('chalk'); const inquirer = require("inquirer"); const JSONbig = require("json-bigint")({ storeAsString: false }); const { Command } = require("commander"); -const { localConfig, globalConfig } = require("../config"); +const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config"); const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner'); const { paginate } = require('../paginate'); -const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); -const { cliConfig, actionRunner, success, warn, log, error, commandDescriptions, drawTable } = require("../parser"); +const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); +const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser"); const { proxyListRules } = require('./proxy'); -const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); +const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); const { databasesGet, databasesCreate, @@ -37,6 +37,7 @@ const { databasesUpdateRelationshipAttribute, databasesCreateRelationshipAttribute, databasesDeleteAttribute, + databasesDeleteIndex, databasesListAttributes, databasesListIndexes, databasesUpdateCollection @@ -53,6 +54,7 @@ const { teamsCreate } = require("./teams"); const { + projectsGet, projectsUpdate, projectsUpdateServiceStatus, projectsUpdateAuthStatus, @@ -68,8 +70,9 @@ const { checkDeployConditions } = require('../utils'); const STEP_SIZE = 100; // Resources const POLL_DEBOUNCE = 2000; // Milliseconds const POLL_MAX_DEBOUNCE = 1800; // Times of POLL_DEBOUNCE (1 hour) +const POLL_DEFAULT_VALUE = 30; -let pollMaxDebounces = 30; +let pollMaxDebounces = POLL_DEFAULT_VALUE; const changeableKeys = ['status', 'required', 'xdefault', 'elements', 'min', 'max', 'default', 'error']; @@ -90,11 +93,13 @@ const awaitPools = { return true; } - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); @@ -121,11 +126,13 @@ const awaitPools = { return true; } - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); @@ -151,11 +158,13 @@ const awaitPools = { return true; } - let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(total / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); @@ -170,11 +179,13 @@ const awaitPools = { return false; } - let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } const { attributes } = await paginate(databasesListAttributes, { @@ -203,11 +214,13 @@ const awaitPools = { return false; } - let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } const { attributes } = await paginate(databasesListAttributes, { @@ -243,16 +256,53 @@ const awaitPools = { iteration + 1 ); }, + deleteIndexes: async (databaseId, collectionId, indexesKeys, iteration = 1) => { + if (iteration > pollMaxDebounces) { + return false; + } + + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; + + log('Found a large number of indexes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } + } + + const { indexes } = await paginate(databasesListIndexes, { + databaseId, + collectionId, + parseOutput: false + }, 100, 'indexes'); + + const ready = indexesKeys.filter(index => indexes.includes(index.key)); + + if (ready.length === 0) { + return true; + } + + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + + return await awaitPools.expectIndexes( + databaseId, + collectionId, + indexesKeys, + iteration + 1 + ); + }, expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => { if (iteration > pollMaxDebounces) { return false; } - let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE)); - if (steps > 1 && iteration === 1) { - pollMaxDebounces *= steps; + if (pollMaxDebounces === POLL_DEFAULT_VALUE) { + let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE)); + if (steps > 1 && iteration === 1) { + pollMaxDebounces *= steps; - log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes') + } } const { indexes } = await paginate(databasesListIndexes, { @@ -290,6 +340,73 @@ const awaitPools = { }, } +const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => { + log('Checking for changes'); + const changes = []; + + await Promise.all(resource.map(async (localResource) => { + try { + const remoteResource = await resourceGetFunction({ + [resourceName]: localResource['$id'], + parseOutput: false, + }); + + for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) { + if (Array.isArray(value) && Array.isArray(localResource[key])) { + if (JSON.stringify(value) !== JSON.stringify(localResource[key])) { + changes.push({ + id: localResource['$id'], + key, + remote: chalk.red(value.join('\n')), + local: chalk.green(localResource[key].join('\n')) + }) + } + } else if (value !== localResource[key]) { + changes.push({ + id: localResource['$id'], + key, + remote: chalk.red(value), + local: chalk.green(localResource[key]) + }) + } + } + } catch (e) { + if (Number(e.code) !== 404) { + throw e; + } + } + })); + + if (changes.length === 0) { + return true; + } + + drawTable(changes); + if (!cliConfig.force) { + const answers = await inquirer.prompt(questionPushChanges); + if (answers.changes.toLowerCase() === 'yes') { + return true; + } + } + + success(`Successfully pushed 0 ${resourcePlural}.`); + return false; +} + +const getObjectChanges = (remote, local, index, what) => { + const changes = []; + + if (remote[index] && local[index]) { + for (let [service, status] of Object.entries(remote[index])) { + if (status !== local[index][service]) { + changes.push({ group: what,setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) }) + } + } + } + + return changes; +} + const createAttribute = async (databaseId, collectionId, attribute) => { switch (attribute.type) { case 'string': @@ -523,8 +640,18 @@ const updateAttribute = async (databaseId, collectionId, attribute) => { }) } } -const deleteAttribute = async (collection, attribute) => { - log(`Deleting attribute ${attribute.key} of ${collection.name} ( ${collection['$id']} )`); +const deleteAttribute = async (collection, attribute, isIndex = false) => { + log(`Deleting ${isIndex ? 'index' : 'attribute'} ${attribute.key} of ${collection.name} ( ${collection['$id']} )`); + + if (isIndex) { + await databasesDeleteIndex({ + databaseId: collection['databaseId'], + collectionId: collection['$id'], + key: attribute.key, + parseOutput: false + }); + return; + } await databasesDeleteAttribute({ databaseId: collection['databaseId'], @@ -555,6 +682,10 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) => let attribute = remote; for (let key of Object.keys(remote)) { + if (!KeysAttributes.has(key)) { + continue; + } + if (changeableKeys.includes(key)) { if (!recraeting) { if (remote[key] !== local[key]) { @@ -570,7 +701,12 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) => continue; } - if (remote[key] !== local[key]) { + if (Array.isArray(remote[key]) && Array.isArray(local[key])) { + if (JSON.stringify(remote[key]) !== JSON.stringify(local[key])) { + const bol = reason === '' ? '' : '\n'; + reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; + } + } else if (remote[key] !== local[key]) { const bol = reason === '' ? '' : '\n'; reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; } @@ -590,7 +726,7 @@ const generateChangesObject = (attribute, collection, isAdding) => { return { key: `${chalk.yellow(attribute.key)} in ${collection.name} (${collection['$id']})`, attribute: attribute, - reason: isAdding ? 'Field doesn\'t exist on the remote server' : 'Field doesn\'t exist in appwrite.json file', + reason: isAdding ? 'Field isn\'t present on the remote server' : 'Field isn\'t present on the appwrite.json file', action: isAdding ? chalk.green('adding') : chalk.red('deleting') }; @@ -599,12 +735,9 @@ const generateChangesObject = (attribute, collection, isAdding) => { /** * Filter deleted and recreated attributes, * return list of attributes to create - * @param remoteAttributes - * @param localAttributes - * @param collection * @returns {Promise<*|*[]>} */ -const attributesToCreate = async (remoteAttributes, localAttributes, collection) => { +const attributesToCreate = async (remoteAttributes, localAttributes, collection, isIndex = false) => { const deleting = remoteAttributes.filter((attribute) => !attributesContains(attribute, localAttributes)).map((attr) => generateChangesObject(attr, collection, false)); const adding = localAttributes.filter((attribute) => !attributesContains(attribute, remoteAttributes)).map((attr) => generateChangesObject(attr, collection, true)); @@ -626,14 +759,14 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection) })); if (!cliConfig.force) { - if (deleting.length > 0) { + if (deleting.length > 0 && !isIndex) { log(`Attribute deletion will cause ${chalk.red('loss of data')}`); } - if (conflicts.length > 0) { + if (conflicts.length > 0 && !isIndex) { log(`Attribute recreation will cause ${chalk.red('loss of data')}`); } - const answers = await inquirer.prompt(questionsPushCollections[1]); + const answers = await inquirer.prompt(questionPushChanges); if (answers.changes.toLowerCase() !== 'yes') { return changedAttributes; @@ -642,17 +775,17 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection) if (conflicts.length > 0) { changedAttributes = conflicts.map((change) => change.attribute); - await Promise.all(changedAttributes.map((changed) => deleteAttribute(collection, changed))); + await Promise.all(changedAttributes.map((changed) => deleteAttribute(collection, changed, isIndex))); remoteAttributes = remoteAttributes.filter((attribute) => !attributesContains(attribute, changedAttributes)) } if (changes.length > 0) { changedAttributes = changes.map((change) => change.attribute); - await Promise.all(changedAttributes.map((changed) => updateAttribute(collection['databaseId'],collection['$id'], changed))); + await Promise.all(changedAttributes.map((changed) => updateAttribute(collection['databaseId'], collection['$id'], changed))); } const deletingAttributes = deleting.map((change) => change.attribute); - await Promise.all(deletingAttributes.map((attribute) => deleteAttribute(collection, attribute))); + await Promise.all(deletingAttributes.map((attribute) => deleteAttribute(collection, attribute, isIndex))); const attributeKeys = [...remoteAttributes.map(attribute => attribute.key), ...deletingAttributes.map(attribute => attribute.key)] if (attributeKeys.length) { @@ -737,6 +870,37 @@ const pushResources = async () => { }; const pushSettings = async () => { + checkDeployConditions(localConfig); + + try { + let response = await projectsGet({ + parseOutput: false, + projectId: localConfig.getProject().projectId + }); + + const remoteSettings = localConfig.createSettingsObject(response ?? {}); + const localSettings = localConfig.getProject().projectSettings ?? {}; + + log('Checking for changes'); + const changes = []; + + changes.push(...(getObjectChanges(remoteSettings, localSettings, 'services', 'Service'))); + changes.push(...(getObjectChanges(remoteSettings['auth'] ?? {}, localSettings['auth'] ?? {}, 'methods', 'Auth method'))); + changes.push(...(getObjectChanges(remoteSettings['auth'] ?? {}, localSettings['auth'] ?? {}, 'security', 'Auth security'))); + + if (changes.length > 0) { + drawTable(changes); + if (!cliConfig.force) { + const answers = await inquirer.prompt(questionPushChanges); + if (answers.changes.toLowerCase() !== 'yes') { + success(`Successfully pushed 0 project settings.`); + return; + } + } + } + } catch (e) { + } + try { log("Pushing project settings ..."); @@ -796,9 +960,7 @@ const pushSettings = async () => { } } -const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero: false }) => { - let response = {}; - +const pushFunction = async ({ functionId, async, code } = { returnOnZero: false }) => { const functionIds = []; if (functionId) { @@ -806,11 +968,6 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } else if (cliConfig.all) { checkDeployConditions(localConfig); const functions = localConfig.getFunctions(); - if (functions.length === 0) { - log("No functions found."); - hint("Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); - return; - } functionIds.push(...functions.map((func) => { return func.$id; })); @@ -818,7 +975,15 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero if (functionIds.length <= 0) { const answers = await inquirer.prompt(questionsPushFunctions[0]); - functionIds.push(...answers.functions); + if (answers.functions) { + functionIds.push(...answers.functions); + } + } + + if (functionIds.length === 0) { + log("No functions found."); + hint("Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); + return; } let functions = functionIds.map((id) => { @@ -844,6 +1009,10 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } } + if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions'))) { + return; + } + log('Pushing functions ...'); Spinner.start(false); @@ -852,6 +1021,8 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero const failedDeployments = []; await Promise.all(functions.map(async (func) => { + let response = {}; + const ignore = func.ignore ? 'appwrite.json' : '.gitignore'; let functionExists = false; let deploymentCreated = false; @@ -859,7 +1030,6 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero const updaterRow = new Spinner({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` }); updaterRow.update({ status: 'Getting' }).startSpinner(SPINNER_DOTS); - try { response = await functionsGet({ functionId: func['$id'], @@ -930,6 +1100,14 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } } + if (code === false) { + successfullyPushed++; + successfullyDeployed++; + updaterRow.update({ status: 'Pushed' }); + updaterRow.stopSpinner(); + return; + } + try { updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC); response = await functionsCreateDeployment({ @@ -961,11 +1139,6 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero let pollChecks = 0; while (true) { - if (pollChecks >= POLL_MAX_DEBOUNCE) { - updaterRow.update({ end: 'Deployment is taking too long. Please check the console for more details.' }) - break; - } - response = await functionsGetDeployment({ functionId: func['$id'], deploymentId: deploymentId, @@ -1004,7 +1177,7 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } pollChecks++; - await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE)); + await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE * 1.5)); } } catch (e) { updaterRow.fail({ errorMessage: e.message ?? 'Unknown error occurred. Please try again' }) @@ -1018,15 +1191,15 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero failedDeployments.forEach((failed) => { const { name, deployment, $id } = failed; - const failUrl = `${globalConfig.getEndpoint().replace('/v1', '')}/console/project-${localConfig.getProject().projectId}/functions/function-${$id}/deployment-${deployment}`; + const failUrl = `${globalConfig.getEndpoint().slice(0, -3)}/console/project-${localConfig.getProject().projectId}/functions/function-${$id}/deployment-${deployment}`; error(`Deployment of ${name} has failed. Check at ${failUrl} for more details\n`); }); if (!async) { - if(successfullyPushed === 0) { + if (successfullyPushed === 0) { error('No functions were pushed.'); - } else if(successfullyDeployed != successfullyPushed) { + } else if (successfullyDeployed !== successfullyPushed) { warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} functions`) } else { success(`Successfully pushed ${successfullyPushed} functions.`); @@ -1036,28 +1209,36 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero } } -const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { +const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false }) => { const collections = []; + if (attempts) { + pollMaxDebounces = attempts; + } + if (cliConfig.all) { checkDeployConditions(localConfig); - if (localConfig.getCollections().length === 0) { - log("No collections found."); - hint("Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); - return; - } collections.push(...localConfig.getCollections()); } else { - const answers = await inquirer.prompt(questionsPushCollections[0]) - const configCollections = new Map(); - localConfig.getCollections().forEach((c) => { - configCollections.set(`${c['databaseId']}|${c['$id']}`, c); - }); - answers.collections.forEach((a) => { - const collection = configCollections.get(a); - collections.push(collection); - }) + const answers = await inquirer.prompt(questionsPushCollections) + if (answers.collections) { + const configCollections = new Map(); + localConfig.getCollections().forEach((c) => { + configCollections.set(`${c['databaseId']}|${c['$id']}`, c); + }); + answers.collections.forEach((a) => { + const collection = configCollections.get(a); + collections.push(collection); + }) + } + } + + if (collections.length === 0) { + log("No collections found."); + hint("Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); + return; } + const databases = Array.from(new Set(collections.map(collection => collection['databaseId']))); log('Checking for changes ...'); @@ -1132,17 +1313,20 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { } } })) - + let numberOfCollections = 0; // Serialize attribute actions for (let collection of collections) { let attributes = collection.attributes; + let indexes = collection.indexes; if (collection.isExisted) { attributes = await attributesToCreate(collection.remoteVersion.attributes, collection.attributes, collection); + indexes = await attributesToCreate(collection.remoteVersion.indexes, collection.indexes, collection, true); - if (Array.isArray(attributes) && attributes.length <= 0) { + if ((Array.isArray(attributes) && attributes.length <= 0) && (Array.isArray(indexes) && indexes.length <= 0)) { continue; } + } log(`Pushing collection ${collection.name} ( ${collection['databaseId']} - ${collection['$id']} ) attributes`) @@ -1154,13 +1338,15 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => { } try { - await createIndexes(collection.indexes, collection); + await createIndexes(indexes, collection); } catch (e) { throw e; } - + numberOfCollections++; success(`Pushed ${collection.name} ( ${collection['$id']} )`); } + + success(`Pushed ${numberOfCollections} collections`); } const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { @@ -1171,17 +1357,20 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { if (cliConfig.all) { checkDeployConditions(localConfig); - if (configBuckets.length === 0) { - log("No buckets found."); - hint("Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); - return; - } bucketIds.push(...configBuckets.map((b) => b.$id)); } if (bucketIds.length === 0) { const answers = await inquirer.prompt(questionsPushBuckets[0]) - bucketIds.push(...answers.buckets); + if (answers.buckets) { + bucketIds.push(...answers.buckets); + } + } + + if (bucketIds.length === 0) { + log("No buckets found."); + hint("Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); + return; } let buckets = []; @@ -1191,6 +1380,10 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { buckets.push(...idBuckets); } + if (!(await approveChanges(buckets, storageGetBucket, KeysStorage, 'bucketId', 'buckets'))) { + return; + } + log('Pushing buckets ...'); for (let bucket of buckets) { @@ -1249,16 +1442,20 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { if (cliConfig.all) { checkDeployConditions(localConfig); - if (configTeams.length === 0) { - log("No teams found."); - hint("Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); - } teamIds.push(...configTeams.map((t) => t.$id)); } if (teamIds.length === 0) { const answers = await inquirer.prompt(questionsPushTeams[0]) - teamIds.push(...answers.teams); + if (answers.teams) { + teamIds.push(...answers.teams); + } + } + + if (teamIds.length === 0) { + log("No teams found."); + hint("Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); + return; } let teams = []; @@ -1268,6 +1465,11 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { teams.push(...idTeams); } + if (!(await approveChanges(teams, teamsGet, KeysTeams, 'teamId', 'teams'))) { + return; + } + + log('Pushing teams ...'); for (let team of teams) { @@ -1311,16 +1513,20 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => if (cliConfig.all) { checkDeployConditions(localConfig); - if (configTopics.length === 0) { - log("No topics found."); - hint("Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); - } topicsIds.push(...configTopics.map((b) => b.$id)); } if (topicsIds.length === 0) { const answers = await inquirer.prompt(questionsPushMessagingTopics[0]) - topicsIds.push(...answers.topics); + if (answers.topics) { + topicsIds.push(...answers.topics); + } + } + + if (topicsIds.length === 0) { + log("No topics found."); + hint("Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); + return; } let topics = []; @@ -1337,6 +1543,10 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => } } + if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) { + return; + } + log('Pushing topics ...'); for (let topic of topics) { @@ -1402,14 +1612,16 @@ push .command("function") .alias("functions") .description("Push functions in the current directory.") - .option(`-f, --functionId <functionId>`, `Function ID`) + .option(`-f, --function-id <function-id>`, `ID of function to run`) .option(`-A, --async`, `Don't wait for functions deployments status`) + .option("--no-code", "Don't push the function's code") .action(actionRunner(pushFunction)); push .command("collection") .alias("collections") .description("Push collections in the current project.") + .option(`-a, --attempts <numberOfAttempts>`, `Max number of attempts before timing out. default: 30.`) .action(actionRunner(pushCollection)); push diff --git a/lib/commands/run.js b/lib/commands/run.js index 0ea914a..a44eb11 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -1,4 +1,5 @@ const Tail = require('tail').Tail; +const { parse: parseDotenv } = require('dotenv'); const chalk = require('chalk'); const ignore = require("ignore"); const tar = require("tar"); @@ -80,6 +81,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = entrypoint: func.entrypoint, path: func.path, commands: func.commands, + scopes: func.scopes ?? [] }; drawTable([settings]); @@ -110,7 +112,9 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = fs.writeFileSync(errorsPath, ''); } + const userVariables = {}; const variables = {}; + if(!noVariables) { try { const { variables: remoteVariables } = await paginate(functionsListVariables, { @@ -120,12 +124,24 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = remoteVariables.forEach((v) => { variables[v.key] = v.value; + userVariables[v.key] = v.value; }); } catch(err) { warn("Remote variables not fetched. Production environment variables will not be avaiable. Reason: " + err.message); } } + const functionPath = path.join(process.cwd(), func.path); + const envPath = path.join(functionPath, '.env'); + if(fs.existsSync(envPath)) { + const env = parseDotenv(fs.readFileSync(envPath).toString() ?? ''); + + Object.keys(env).forEach((key) => { + variables[key] = env[key]; + userVariables[key] = env[key]; + }); + } + variables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint'); variables['APPWRITE_FUNCTION_ID'] = func.$id; variables['APPWRITE_FUNCTION_NAME'] = func.name; @@ -148,6 +164,13 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? ''; variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers); + if(Object.keys(userVariables).length > 0) { + drawTable(Object.keys(userVariables).map((key) => ({ + key, + value: userVariables[key].split("").filter((_, i) => i < 16).map(() => "*").join("") + }))); + } + await dockerPull(func); new Tail(logsPath).on("line", function(data) { @@ -158,10 +181,27 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = }); if(!noReload) { + const ignorer = ignore(); + ignorer.add('.appwrite'); + ignorer.add('code.tar.gz'); + + if (func.ignore) { + ignorer.add(func.ignore); + } else if (fs.existsSync(path.join(functionPath, '.gitignore'))) { + ignorer.add(fs.readFileSync(path.join(functionPath, '.gitignore')).toString()); + } + chokidar.watch('.', { cwd: path.join(process.cwd(), func.path), ignoreInitial: true, - ignored: [ ...(func.ignore ?? []), 'code.tar.gz', '.appwrite', '.appwrite/', '.appwrite/*', '.appwrite/**', '.appwrite/*.*', '.appwrite/**/*.*' ] + ignored: (xpath) => { + const relativePath = path.relative(functionPath, xpath); + + if(!relativePath) { + return false; + } + return ignorer.ignores(relativePath); + } }).on('all', async (_event, filePath) => { Queue.push(filePath); }); @@ -187,7 +227,6 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = } else { log('Hot-swapping function.. Files with change are ' + files.join(', ')); - const functionPath = path.join(process.cwd(), func.path); const hotSwapPath = path.join(functionPath, '.appwrite/hot-swap'); const buildPath = path.join(functionPath, '.appwrite/build.tar.gz'); @@ -201,6 +240,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = await tar .extract({ + keep: true, gzip: true, sync: true, cwd: hotSwapPath, @@ -211,6 +251,8 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = ignorer.add('.appwrite'); if (func.ignore) { ignorer.add(func.ignore); + } else if (fs.existsSync(path.join(functionPath, '.gitignore'))) { + ignorer.add(fs.readFileSync(path.join(functionPath, '.gitignore')).toString()); } const filesToCopy = getAllFiles(functionPath).map((file) => path.relative(functionPath, file)).filter((file) => !ignorer.ignores(file)); @@ -237,8 +279,6 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = file: buildPath }, ['.']); - fs.rmSync(hotSwapPath, { recursive: true, force: true }); - await dockerStart(func, variables, port); } } catch(err) { @@ -278,11 +318,11 @@ run .command("function") .alias("functions") .description("Run functions in the current directory.") - .option(`--functionId <functionId>`, `Function ID`) + .option(`--function-id <function-id>`, `ID of function to run`) .option(`--port <port>`, `Local port`) - .option(`--userId <userId>`, `ID of user to impersonate`) - .option(`--noVariables`, `Prevent pulling variables from function settings`) - .option(`--noReload`, `Prevent live reloading of server when changes are made to function files`) + .option(`--user-id <user-id>`, `ID of user to impersonate`) + .option(`--no-variables`, `Prevent pulling variables from function settings`) + .option(`--no-reload`, `Prevent live reloading of server when changes are made to function files`) .action(actionRunner(runFunction)); module.exports = { diff --git a/lib/commands/storage.js b/lib/commands/storage.js index 4dca398..00102b4 100644 --- a/lib/commands/storage.js +++ b/lib/commands/storage.js @@ -838,7 +838,7 @@ const storageGetBucketUsage = async ({bucketId,range,parseOutput = true, overrid } storage - .command(`listBuckets`) + .command(`list-buckets`) .description(`Get a list of all the storage buckets. You can use the query params to filter your results.`) .option(`--queries [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: enabled, name, fileSecurity, maximumFileSize, encryption, antivirus`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) @@ -846,110 +846,110 @@ storage .action(actionRunner(storageListBuckets)) storage - .command(`createBucket`) + .command(`create-bucket`) .description(`Create a new storage bucket.`) - .requiredOption(`--bucketId <bucketId>`, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--bucket-id <bucket-id>`, `Unique Id. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Bucket name`) .option(`--permissions [permissions...]`, `An array of permission strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`) - .option(`--fileSecurity <fileSecurity>`, `Enables configuring permissions for individual file. A user needs one of file or bucket level permissions to access a file. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) + .option(`--file-security <file-security>`, `Enables configuring permissions for individual file. A user needs one of file or bucket level permissions to access a file. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) .option(`--enabled <enabled>`, `Is bucket enabled? When set to 'disabled', users cannot access the files in this bucket but Server SDKs with and API key can still access the bucket. No files are lost when this is toggled.`, parseBool) - .option(`--maximumFileSize <maximumFileSize>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB.`, parseInteger) - .option(`--allowedFileExtensions [allowedFileExtensions...]`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`) + .option(`--maximum-file-size <maximum-file-size>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB.`, parseInteger) + .option(`--allowed-file-extensions [allowed-file-extensions...]`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`) .option(`--compression <compression>`, `Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled`) .option(`--encryption <encryption>`, `Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled`, parseBool) .option(`--antivirus <antivirus>`, `Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled`, parseBool) .action(actionRunner(storageCreateBucket)) storage - .command(`getBucket`) + .command(`get-bucket`) .description(`Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.`) - .requiredOption(`--bucketId <bucketId>`, `Bucket unique ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Bucket unique ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetBucket)) storage - .command(`updateBucket`) + .command(`update-bucket`) .description(`Update a storage bucket by its unique ID.`) - .requiredOption(`--bucketId <bucketId>`, `Bucket unique ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Bucket unique ID.`) .requiredOption(`--name <name>`, `Bucket name`) .option(`--permissions [permissions...]`, `An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).`) - .option(`--fileSecurity <fileSecurity>`, `Enables configuring permissions for individual file. A user needs one of file or bucket level permissions to access a file. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) + .option(`--file-security <file-security>`, `Enables configuring permissions for individual file. A user needs one of file or bucket level permissions to access a file. [Learn more about permissions](https://appwrite.io/docs/permissions).`, parseBool) .option(`--enabled <enabled>`, `Is bucket enabled? When set to 'disabled', users cannot access the files in this bucket but Server SDKs with and API key can still access the bucket. No files are lost when this is toggled.`, parseBool) - .option(`--maximumFileSize <maximumFileSize>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB.`, parseInteger) - .option(`--allowedFileExtensions [allowedFileExtensions...]`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`) + .option(`--maximum-file-size <maximum-file-size>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB.`, parseInteger) + .option(`--allowed-file-extensions [allowed-file-extensions...]`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`) .option(`--compression <compression>`, `Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled`) .option(`--encryption <encryption>`, `Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled`, parseBool) .option(`--antivirus <antivirus>`, `Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled`, parseBool) .action(actionRunner(storageUpdateBucket)) storage - .command(`deleteBucket`) + .command(`delete-bucket`) .description(`Delete a storage bucket by its unique ID.`) - .requiredOption(`--bucketId <bucketId>`, `Bucket unique ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Bucket unique ID.`) .action(actionRunner(storageDeleteBucket)) storage - .command(`listFiles`) + .command(`list-files`) .description(`Get a list of all the user files. You can use the query params to filter your results.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) .option(`--queries [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, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(storageListFiles)) storage - .command(`createFile`) + .command(`create-file`) .description(`Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console. Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of '5MB'. The 'content-range' header values should always be in bytes. When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in 'x-appwrite-id' header to allow the server to know that the partial upload is for the existing file and not for a new one. If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally. `) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--file <file>`, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/products/storage/upload-download#input-file).`) .option(`--permissions [permissions...]`, `An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`) .action(actionRunner(storageCreateFile)) storage - .command(`getFile`) + .command(`get-file`) .description(`Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetFile)) storage - .command(`updateFile`) + .command(`update-file`) .description(`Update a file by its unique ID. Only users with write permissions have access to update this resource.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File unique ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File unique ID.`) .option(`--name <name>`, `Name of the file`) .option(`--permissions [permissions...]`, `An array of permission string. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).`) .action(actionRunner(storageUpdateFile)) storage - .command(`deleteFile`) + .command(`delete-file`) .description(`Delete a file by its unique ID. Only users with write permissions have access to delete this resource.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID.`) .action(actionRunner(storageDeleteFile)) storage - .command(`getFileDownload`) + .command(`get-file-download`) .description(`Get a file content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID.`) .requiredOption(`--destination <path>`, `output file path.`) .action(actionRunner(storageGetFileDownload)) storage - .command(`getFilePreview`) + .command(`get-file-preview`) .description(`Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID`) .option(`--width <width>`, `Resize preview image width, Pass an integer between 0 to 4000.`, parseInteger) .option(`--height <height>`, `Resize preview image height, Pass an integer between 0 to 4000.`, parseInteger) .option(`--gravity <gravity>`, `Image crop gravity. Can be one of center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right`) .option(`--quality <quality>`, `Preview image quality. Pass an integer between 0 to 100. Defaults to 100.`, parseInteger) - .option(`--borderWidth <borderWidth>`, `Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.`, parseInteger) - .option(`--borderColor <borderColor>`, `Preview image border color. Use a valid HEX color, no # is needed for prefix.`) - .option(`--borderRadius <borderRadius>`, `Preview image border radius in pixels. Pass an integer between 0 to 4000.`, parseInteger) + .option(`--border-width <border-width>`, `Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.`, parseInteger) + .option(`--border-color <border-color>`, `Preview image border color. Use a valid HEX color, no # is needed for prefix.`) + .option(`--border-radius <border-radius>`, `Preview image border radius in pixels. Pass an integer between 0 to 4000.`, parseInteger) .option(`--opacity <opacity>`, `Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.`, parseInteger) .option(`--rotation <rotation>`, `Preview image rotation in degrees. Pass an integer between -360 and 360.`, parseInteger) .option(`--background <background>`, `Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.`) @@ -958,23 +958,23 @@ storage .action(actionRunner(storageGetFilePreview)) storage - .command(`getFileView`) + .command(`get-file-view`) .description(`Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.`) - .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) - .requiredOption(`--fileId <fileId>`, `File ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`) + .requiredOption(`--file-id <file-id>`, `File ID.`) .requiredOption(`--destination <path>`, `output file path.`) .action(actionRunner(storageGetFileView)) storage - .command(`getUsage`) + .command(`get-usage`) .description(``) .option(`--range <range>`, `Date range.`) .action(actionRunner(storageGetUsage)) storage - .command(`getBucketUsage`) + .command(`get-bucket-usage`) .description(``) - .requiredOption(`--bucketId <bucketId>`, `Bucket ID.`) + .requiredOption(`--bucket-id <bucket-id>`, `Bucket ID.`) .option(`--range <range>`, `Date range.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(storageGetBucketUsage)) diff --git a/lib/commands/teams.js b/lib/commands/teams.js index 39f1848..7ca5474 100644 --- a/lib/commands/teams.js +++ b/lib/commands/teams.js @@ -587,7 +587,7 @@ teams teams .command(`create`) .description(`Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team.`) - .requiredOption(`--teamId <teamId>`, `Team ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--team-id <team-id>`, `Team ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--name <name>`, `Team name. Max length: 128 chars.`) .option(`--roles [roles...]`, `Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.`) .action(actionRunner(teamsCreate)) @@ -595,91 +595,91 @@ teams teams .command(`get`) .description(`Get a team by its ID. All team members have read access for this resource.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(teamsGet)) teams - .command(`updateName`) + .command(`update-name`) .description(`Update the team's name by its unique ID.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .requiredOption(`--name <name>`, `New team name. Max length: 128 chars.`) .action(actionRunner(teamsUpdateName)) teams .command(`delete`) .description(`Delete a team using its ID. Only team members with the owner role can delete the team.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .action(actionRunner(teamsDelete)) teams - .command(`listLogs`) + .command(`list-logs`) .description(`Get the team activity logs list by its unique ID.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(teamsListLogs)) teams - .command(`listMemberships`) + .command(`list-memberships`) .description(`Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .option(`--queries [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: userId, teamId, invited, joined, confirm`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .action(actionRunner(teamsListMemberships)) teams - .command(`createMembership`) + .command(`create-membership`) .description(`Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team. You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters. Use the 'url' parameter to redirect the user from the invitation email to your app. After the user is redirected, use the [Update Team Membership Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) endpoint to allow the user to accept the invitation to the team. Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console. `) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .requiredOption(`--roles [roles...]`, `Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.`) .option(`--email <email>`, `Email of the new team member.`) - .option(`--userId <userId>`, `ID of the user to be added to a team.`) + .option(`--user-id <user-id>`, `ID of the user to be added to a team.`) .option(`--phone <phone>`, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .option(`--url <url>`, `URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.`) .option(`--name <name>`, `Name of the new team member. Max length: 128 chars.`) .action(actionRunner(teamsCreateMembership)) teams - .command(`getMembership`) + .command(`get-membership`) .description(`Get a team member by the membership unique id. All team members have read access for this resource.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) - .requiredOption(`--membershipId <membershipId>`, `Membership ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) + .requiredOption(`--membership-id <membership-id>`, `Membership ID.`) .action(actionRunner(teamsGetMembership)) teams - .command(`updateMembership`) + .command(`update-membership`) .description(`Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). `) - .requiredOption(`--teamId <teamId>`, `Team ID.`) - .requiredOption(`--membershipId <membershipId>`, `Membership ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) + .requiredOption(`--membership-id <membership-id>`, `Membership ID.`) .requiredOption(`--roles [roles...]`, `An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.`) .action(actionRunner(teamsUpdateMembership)) teams - .command(`deleteMembership`) + .command(`delete-membership`) .description(`This endpoint allows a user to leave a team or for a team owner to delete the membership of any other team member. You can also use this endpoint to delete a user membership even if it is not accepted.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) - .requiredOption(`--membershipId <membershipId>`, `Membership ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) + .requiredOption(`--membership-id <membership-id>`, `Membership ID.`) .action(actionRunner(teamsDeleteMembership)) teams - .command(`updateMembershipStatus`) + .command(`update-membership-status`) .description(`Use this endpoint to allow a user to accept an invitation to join a team after being redirected back to your app from the invitation email received by the user. If the request is successful, a session for the user is automatically created. `) - .requiredOption(`--teamId <teamId>`, `Team ID.`) - .requiredOption(`--membershipId <membershipId>`, `Membership ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) + .requiredOption(`--membership-id <membership-id>`, `Membership ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--secret <secret>`, `Secret key.`) .action(actionRunner(teamsUpdateMembershipStatus)) teams - .command(`getPrefs`) + .command(`get-prefs`) .description(`Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in [user preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs).`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .action(actionRunner(teamsGetPrefs)) teams - .command(`updatePrefs`) + .command(`update-prefs`) .description(`Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded.`) - .requiredOption(`--teamId <teamId>`, `Team ID.`) + .requiredOption(`--team-id <team-id>`, `Team ID.`) .requiredOption(`--prefs <prefs>`, `Prefs key-value JSON object.`) .action(actionRunner(teamsUpdatePrefs)) diff --git a/lib/commands/users.js b/lib/commands/users.js index 42f4ea3..9d13ed7 100644 --- a/lib/commands/users.js +++ b/lib/commands/users.js @@ -1717,7 +1717,7 @@ users users .command(`create`) .description(`Create a new user.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .option(`--email <email>`, `User email.`) .option(`--phone <phone>`, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .option(`--password <password>`, `Plain text user password. Must be at least 8 chars.`) @@ -1725,92 +1725,92 @@ users .action(actionRunner(usersCreate)) users - .command(`createArgon2User`) + .command(`create-argon-2-user`) .description(`Create a new user. Password provided must be hashed with the [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using Argon2.`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateArgon2User)) users - .command(`createBcryptUser`) + .command(`create-bcrypt-user`) .description(`Create a new user. Password provided must be hashed with the [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using Bcrypt.`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateBcryptUser)) users - .command(`listIdentities`) + .command(`list-identities`) .description(`Get identities for all users.`) .option(`--queries [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: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .action(actionRunner(usersListIdentities)) users - .command(`deleteIdentity`) + .command(`delete-identity`) .description(`Delete an identity by its unique ID.`) - .requiredOption(`--identityId <identityId>`, `Identity ID.`) + .requiredOption(`--identity-id <identity-id>`, `Identity ID.`) .action(actionRunner(usersDeleteIdentity)) users - .command(`createMD5User`) + .command(`create-md-5-user`) .description(`Create a new user. Password provided must be hashed with the [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using MD5.`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateMD5User)) users - .command(`createPHPassUser`) + .command(`create-ph-pass-user`) .description(`Create a new user. Password provided must be hashed with the [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or pass the string 'ID.unique()'to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or pass the string 'ID.unique()'to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using PHPass.`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreatePHPassUser)) users - .command(`createScryptUser`) + .command(`create-scrypt-user`) .description(`Create a new user. Password provided must be hashed with the [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using Scrypt.`) - .requiredOption(`--passwordSalt <passwordSalt>`, `Optional salt used to hash password.`) - .requiredOption(`--passwordCpu <passwordCpu>`, `Optional CPU cost used to hash password.`, parseInteger) - .requiredOption(`--passwordMemory <passwordMemory>`, `Optional memory cost used to hash password.`, parseInteger) - .requiredOption(`--passwordParallel <passwordParallel>`, `Optional parallelization cost used to hash password.`, parseInteger) - .requiredOption(`--passwordLength <passwordLength>`, `Optional hash length used to hash password.`, parseInteger) + .requiredOption(`--password-salt <password-salt>`, `Optional salt used to hash password.`) + .requiredOption(`--password-cpu <password-cpu>`, `Optional CPU cost used to hash password.`, parseInteger) + .requiredOption(`--password-memory <password-memory>`, `Optional memory cost used to hash password.`, parseInteger) + .requiredOption(`--password-parallel <password-parallel>`, `Optional parallelization cost used to hash password.`, parseInteger) + .requiredOption(`--password-length <password-length>`, `Optional hash length used to hash password.`, parseInteger) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateScryptUser)) users - .command(`createScryptModifiedUser`) + .command(`create-scrypt-modified-user`) .description(`Create a new user. Password provided must be hashed with the [Scrypt Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using Scrypt Modified.`) - .requiredOption(`--passwordSalt <passwordSalt>`, `Salt used to hash password.`) - .requiredOption(`--passwordSaltSeparator <passwordSaltSeparator>`, `Salt separator used to hash password.`) - .requiredOption(`--passwordSignerKey <passwordSignerKey>`, `Signer key used to hash password.`) + .requiredOption(`--password-salt <password-salt>`, `Salt used to hash password.`) + .requiredOption(`--password-salt-separator <password-salt-separator>`, `Salt separator used to hash password.`) + .requiredOption(`--password-signer-key <password-signer-key>`, `Signer key used to hash password.`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateScryptModifiedUser)) users - .command(`createSHAUser`) + .command(`create-sha-user`) .description(`Create a new user. Password provided must be hashed with the [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use the [POST /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to create users with a plain text password.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .requiredOption(`--email <email>`, `User email.`) .requiredOption(`--password <password>`, `User password hashed using SHA.`) - .option(`--passwordVersion <passwordVersion>`, `Optional SHA version used to hash password. Allowed values are: 'sha1', 'sha224', 'sha256', 'sha384', 'sha512/224', 'sha512/256', 'sha512', 'sha3-224', 'sha3-256', 'sha3-384', 'sha3-512'`) + .option(`--password-version <password-version>`, `Optional SHA version used to hash password. Allowed values are: 'sha1', 'sha224', 'sha256', 'sha384', 'sha512/224', 'sha512/256', 'sha512', 'sha3-224', 'sha3-256', 'sha3-384', 'sha3-512'`) .option(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersCreateSHAUser)) users - .command(`getUsage`) + .command(`get-usage`) .description(``) .option(`--range <range>`, `Date range.`) .action(actionRunner(usersGetUsage)) @@ -1818,218 +1818,218 @@ users users .command(`get`) .description(`Get a user by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(usersGet)) users .command(`delete`) .description(`Delete a user by its unique ID, thereby releasing it's ID. Since ID is released and can be reused, all user-related resources like documents or storage files should be deleted before user deletion. If you want to keep ID reserved, use the [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) endpoint instead.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersDelete)) users - .command(`updateEmail`) + .command(`update-email`) .description(`Update the user email by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--email <email>`, `User email.`) .action(actionRunner(usersUpdateEmail)) users - .command(`createJWT`) + .command(`create-jwt`) .description(`Use this endpoint to create a JSON Web Token for user by its unique ID. You can use the resulting JWT to authenticate on behalf of the user. The JWT secret will become invalid if the session it uses gets deleted.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .option(`--sessionId <sessionId>`, `Session ID. Use the string 'recent' to use the most recent session. Defaults to the most recent session.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .option(`--session-id <session-id>`, `Session ID. Use the string 'recent' to use the most recent session. Defaults to the most recent session.`) .option(`--duration <duration>`, `Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.`, parseInteger) .action(actionRunner(usersCreateJWT)) users - .command(`updateLabels`) + .command(`update-labels`) .description(`Update the user labels by its unique ID. Labels can be used to grant access to resources. While teams are a way for user's to share access to a resource, labels can be defined by the developer to grant access without an invitation. See the [Permissions docs](https://appwrite.io/docs/permissions) for more info.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--labels [labels...]`, `Array of user labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long.`) .action(actionRunner(usersUpdateLabels)) users - .command(`listLogs`) + .command(`list-logs`) .description(`Get the user activity logs list by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`) .action(actionRunner(usersListLogs)) users - .command(`listMemberships`) + .command(`list-memberships`) .description(`Get the user membership list by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersListMemberships)) users - .command(`updateMfa`) + .command(`update-mfa`) .description(`Enable or disable MFA on a user account.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--mfa <mfa>`, `Enable or disable MFA.`, parseBool) .action(actionRunner(usersUpdateMfa)) users - .command(`deleteMfaAuthenticator`) + .command(`delete-mfa-authenticator`) .description(`Delete an authenticator app.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--type <type>`, `Type of authenticator.`) .action(actionRunner(usersDeleteMfaAuthenticator)) users - .command(`listMfaFactors`) + .command(`list-mfa-factors`) .description(`List the factors available on the account to be used as a MFA challange.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersListMfaFactors)) users - .command(`getMfaRecoveryCodes`) + .command(`get-mfa-recovery-codes`) .description(`Get recovery codes that can be used as backup for MFA flow by User ID. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersGetMfaRecoveryCodes)) users - .command(`updateMfaRecoveryCodes`) + .command(`update-mfa-recovery-codes`) .description(`Regenerate recovery codes that can be used as backup for MFA flow by User ID. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersUpdateMfaRecoveryCodes)) users - .command(`createMfaRecoveryCodes`) + .command(`create-mfa-recovery-codes`) .description(`Generate recovery codes used as backup for MFA flow for User ID. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method by client SDK.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersCreateMfaRecoveryCodes)) users - .command(`updateName`) + .command(`update-name`) .description(`Update the user name by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--name <name>`, `User name. Max length: 128 chars.`) .action(actionRunner(usersUpdateName)) users - .command(`updatePassword`) + .command(`update-password`) .description(`Update the user password by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--password <password>`, `New user password. Must be at least 8 chars.`) .action(actionRunner(usersUpdatePassword)) users - .command(`updatePhone`) + .command(`update-phone`) .description(`Update the user phone by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--number <number>`, `User phone number.`) .action(actionRunner(usersUpdatePhone)) users - .command(`getPrefs`) + .command(`get-prefs`) .description(`Get the user preferences by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersGetPrefs)) users - .command(`updatePrefs`) + .command(`update-prefs`) .description(`Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--prefs <prefs>`, `Prefs key-value JSON object.`) .action(actionRunner(usersUpdatePrefs)) users - .command(`listSessions`) + .command(`list-sessions`) .description(`Get the user sessions list by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(usersListSessions)) users - .command(`createSession`) + .command(`create-session`) .description(`Creates a session for a user. Returns an immediately usable session object. If you want to generate a token for a custom authentication flow, use the [POST /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) endpoint.`) - .requiredOption(`--userId <userId>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--user-id <user-id>`, `User ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) .action(actionRunner(usersCreateSession)) users - .command(`deleteSessions`) + .command(`delete-sessions`) .description(`Delete all user's sessions by using the user's unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .action(actionRunner(usersDeleteSessions)) users - .command(`deleteSession`) + .command(`delete-session`) .description(`Delete a user sessions by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--sessionId <sessionId>`, `Session ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--session-id <session-id>`, `Session ID.`) .action(actionRunner(usersDeleteSession)) users - .command(`updateStatus`) + .command(`update-status`) .description(`Update the user status by its unique ID. Use this endpoint as an alternative to deleting a user if you want to keep user's ID reserved.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .requiredOption(`--status <status>`, `User Status. To activate the user pass 'true' and to block the user pass 'false'.`, parseBool) .action(actionRunner(usersUpdateStatus)) users - .command(`listTargets`) + .command(`list-targets`) .description(`List the messaging targets that are associated with a user.`) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .option(`--queries [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, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels`) .action(actionRunner(usersListTargets)) users - .command(`createTarget`) + .command(`create-target`) .description(`Create a messaging target.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--targetId <targetId>`, `Target ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) - .requiredOption(`--providerType <providerType>`, `The target provider type. Can be one of the following: 'email', 'sms' or 'push'.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--target-id <target-id>`, `Target ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`) + .requiredOption(`--provider-type <provider-type>`, `The target provider type. Can be one of the following: 'email', 'sms' or 'push'.`) .requiredOption(`--identifier <identifier>`, `The target identifier (token, email, phone etc.)`) - .option(`--providerId <providerId>`, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) + .option(`--provider-id <provider-id>`, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) .option(`--name <name>`, `Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23.`) .action(actionRunner(usersCreateTarget)) users - .command(`getTarget`) + .command(`get-target`) .description(`Get a user's push notification target by ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--targetId <targetId>`, `Target ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--target-id <target-id>`, `Target ID.`) .action(actionRunner(usersGetTarget)) users - .command(`updateTarget`) + .command(`update-target`) .description(`Update a messaging target.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--targetId <targetId>`, `Target ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--target-id <target-id>`, `Target ID.`) .option(`--identifier <identifier>`, `The target identifier (token, email, phone etc.)`) - .option(`--providerId <providerId>`, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) + .option(`--provider-id <provider-id>`, `Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.`) .option(`--name <name>`, `Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23.`) .action(actionRunner(usersUpdateTarget)) users - .command(`deleteTarget`) + .command(`delete-target`) .description(`Delete a messaging target.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--targetId <targetId>`, `Target ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--target-id <target-id>`, `Target ID.`) .action(actionRunner(usersDeleteTarget)) users - .command(`createToken`) + .command(`create-token`) .description(`Returns a token with a secret key for creating a session. Use the user ID and secret and submit a request to the [PUT /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. `) - .requiredOption(`--userId <userId>`, `User ID.`) + .requiredOption(`--user-id <user-id>`, `User ID.`) .option(`--length <length>`, `Token length in characters. The default length is 6 characters`, parseInteger) .option(`--expire <expire>`, `Token expiration period in seconds. The default expiration is 15 minutes.`, parseInteger) .action(actionRunner(usersCreateToken)) users - .command(`updateEmailVerification`) + .command(`update-email-verification`) .description(`Update the user email verification status by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--emailVerification <emailVerification>`, `User email verification status.`, parseBool) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--email-verification <email-verification>`, `User email verification status.`, parseBool) .action(actionRunner(usersUpdateEmailVerification)) users - .command(`updatePhoneVerification`) + .command(`update-phone-verification`) .description(`Update the user phone verification status by its unique ID.`) - .requiredOption(`--userId <userId>`, `User ID.`) - .requiredOption(`--phoneVerification <phoneVerification>`, `User phone verification status.`, parseBool) + .requiredOption(`--user-id <user-id>`, `User ID.`) + .requiredOption(`--phone-verification <phone-verification>`, `User phone verification status.`, parseBool) .action(actionRunner(usersUpdatePhoneVerification)) module.exports = { diff --git a/lib/commands/vcs.js b/lib/commands/vcs.js index 44ae4ce..f548870 100644 --- a/lib/commands/vcs.js +++ b/lib/commands/vcs.js @@ -396,75 +396,75 @@ const vcsDeleteInstallation = async ({installationId,parseOutput = true, overrid } vcs - .command(`listRepositories`) + .command(`list-repositories`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .action(actionRunner(vcsListRepositories)) vcs - .command(`createRepository`) + .command(`create-repository`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) .requiredOption(`--name <name>`, `Repository name (slug)`) .requiredOption(`--xprivate <xprivate>`, `Mark repository public or private`, parseBool) .action(actionRunner(vcsCreateRepository)) vcs - .command(`getRepository`) + .command(`get-repository`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) - .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) + .requiredOption(`--provider-repository-id <provider-repository-id>`, `Repository Id`) .action(actionRunner(vcsGetRepository)) vcs - .command(`listRepositoryBranches`) + .command(`list-repository-branches`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) - .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) + .requiredOption(`--provider-repository-id <provider-repository-id>`, `Repository Id`) .action(actionRunner(vcsListRepositoryBranches)) vcs - .command(`getRepositoryContents`) + .command(`get-repository-contents`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) - .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`) - .option(`--providerRootDirectory <providerRootDirectory>`, `Path to get contents of nested directory`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) + .requiredOption(`--provider-repository-id <provider-repository-id>`, `Repository Id`) + .option(`--provider-root-directory <provider-root-directory>`, `Path to get contents of nested directory`) .action(actionRunner(vcsGetRepositoryContents)) vcs - .command(`createRepositoryDetection`) + .command(`create-repository-detection`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) - .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`) - .option(`--providerRootDirectory <providerRootDirectory>`, `Path to Root Directory`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) + .requiredOption(`--provider-repository-id <provider-repository-id>`, `Repository Id`) + .option(`--provider-root-directory <provider-root-directory>`, `Path to Root Directory`) .action(actionRunner(vcsCreateRepositoryDetection)) vcs - .command(`updateExternalDeployments`) + .command(`update-external-deployments`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) - .requiredOption(`--repositoryId <repositoryId>`, `VCS Repository Id`) - .requiredOption(`--providerPullRequestId <providerPullRequestId>`, `GitHub Pull Request Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) + .requiredOption(`--repository-id <repository-id>`, `VCS Repository Id`) + .requiredOption(`--provider-pull-request-id <provider-pull-request-id>`, `GitHub Pull Request Id`) .action(actionRunner(vcsUpdateExternalDeployments)) vcs - .command(`listInstallations`) + .command(`list-installations`) .description(``) .option(`--queries [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: provider, organization`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .action(actionRunner(vcsListInstallations)) vcs - .command(`getInstallation`) + .command(`get-installation`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) .action(actionRunner(vcsGetInstallation)) vcs - .command(`deleteInstallation`) + .command(`delete-installation`) .description(``) - .requiredOption(`--installationId <installationId>`, `Installation Id`) + .requiredOption(`--installation-id <installation-id>`, `Installation Id`) .action(actionRunner(vcsDeleteInstallation)) module.exports = { diff --git a/lib/config.js b/lib/config.js index 665e983..18ed09e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -8,8 +8,9 @@ const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logg const KeysDatabase = new Set(["$id", "name", "enabled"]); const KeysCollection = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]); const KeysStorage = new Set(["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]); -const KeyTopics = new Set(["$id", "name", "subscribe"]); -const KeyAttributes = new Set([ +const KeysTopics = new Set(["$id", "name", "subscribe"]); +const KeysTeams = new Set(["$id", "name"]); +const KeysAttributes = new Set([ "key", "type", "required", @@ -17,7 +18,7 @@ const KeyAttributes = new Set([ "size", "default", // integer and float - "min", + "min", "max", // email, enum, URL, IP, and datetime "format", @@ -29,7 +30,10 @@ const KeyAttributes = new Set([ "twoWay", "twoWayKey", "onDelete", - "side" + "side", + // Indexes + "attributes", + "orders" ]); const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]); @@ -193,7 +197,7 @@ class Local extends Config { addCollection(props) { props = whitelistKeys(props, KeysCollection, { - attributes: KeyAttributes, + attributes: KeysAttributes, indexes: KeyIndexes }); @@ -277,7 +281,7 @@ class Local extends Config { } addMessagingTopic(props) { - props = whitelistKeys(props, KeyTopics); + props = whitelistKeys(props, KeysTopics); if (!this.has("topics")) { this.set("topics", []); @@ -359,6 +363,7 @@ class Local extends Config { } addTeam(props) { + props = whitelistKeys(props, KeysTeams); if (!this.has("teams")) { this.set("teams", []); } @@ -398,7 +403,11 @@ class Local extends Config { return; } - const settings = { + this.set('settings', this.createSettingsObject(settings)); + } + + createSettingsObject(projectSettings) { + return { services: { account: projectSettings.serviceStatusForAccount, avatars: projectSettings.serviceStatusForAvatars, @@ -432,10 +441,7 @@ class Local extends Config { } } }; - - this.set('settings', settings) } - } class Global extends Config { @@ -604,4 +610,10 @@ class Global extends Config { module.exports = { localConfig: new Local(), globalConfig: new Global(), + KeysAttributes, + KeysFunction, + KeysTopics, + KeysStorage, + KeysTeams, + whitelistKeys }; diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index d93f280..b23cc10 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -1,10 +1,14 @@ +const tar = require("tar"); +const ignore = require("ignore"); +const net = require('net'); const chalk = require('chalk'); const childProcess = require('child_process'); const { localConfig } = require("../config"); const path = require('path'); const fs = require('fs'); -const { log, success, hint } = require("../parser"); +const { log, error, success, hint } = require("../parser"); const { openRuntimesVersion, systemTools, Queue } = require("./utils"); +const { getAllFiles } = require("../utils"); async function dockerStop(id) { const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], { @@ -49,7 +53,7 @@ async function dockerBuild(func, variables) { const params = [ 'run' ]; params.push('--name', id); - params.push('-v', `${functionDir}/:/mnt/code:rw`); + params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`); params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); @@ -91,12 +95,11 @@ async function dockerBuild(func, variables) { await new Promise((res) => { buildProcess.on('close', res) }); - clearInterval(interval); - + clearInterval(killInterval); if(!Queue.isEmpty()) { return; } - + const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz'); const copyDir = path.dirname(copyPath); if (!fs.existsSync(copyDir)) { @@ -120,9 +123,39 @@ async function dockerBuild(func, variables) { if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); } + + fs.rmSync(tmpBuildPath, { recursive: true, force: true }); } async function dockerStart(func, variables, port) { + // Pack function files + const functionDir = path.join(process.cwd(), func.path); + + const ignorer = ignore(); + ignorer.add('.appwrite'); + if (func.ignore) { + ignorer.add(func.ignore); + } else if (fs.existsSync(path.join(functionDir, '.gitignore'))) { + ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString()); + } + + const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file)); + const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build'); + if (!fs.existsSync(tmpBuildPath)) { + fs.mkdirSync(tmpBuildPath, { recursive: true }); + } + + for(const f of files) { + const filePath = path.join(tmpBuildPath, f); + const fileDir = path.dirname(filePath); + if (!fs.existsSync(fileDir)) { + fs.mkdirSync(fileDir, { recursive: true }); + } + + const sourcePath = path.join(functionDir, f); + fs.copyFileSync(sourcePath, filePath); + } + const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); @@ -168,6 +201,13 @@ async function dockerStart(func, variables, port) { process.stdout.write(chalk.blackBright(data)); }); + try { + await waitUntilPortOpen(port); + } catch(err) { + error("Failed to start function with error: " + err.message ? err.message : err.toString()); + return; + } + success(`Visit http://localhost:${port}/ to execute your function.`); } @@ -186,6 +226,39 @@ async function dockerCleanup(functionId) { } } +function waitUntilPortOpen(port, iteration = 0) { + return new Promise((resolve, reject) => { + const client = new net.Socket(); + + client.once('connect', () => { + client.removeAllListeners('connect'); + client.removeAllListeners('error'); + client.end(); + client.destroy(); + client.unref(); + + resolve(); + }); + + client.once('error', async (err) => { + client.removeAllListeners('connect'); + client.removeAllListeners('error'); + client.end(); + client.destroy(); + client.unref(); + + if(iteration > 100) { + reject(err); + } else { + await new Promise((res) => setTimeout(res, 100)); + waitUntilPortOpen(port, iteration + 1).then(resolve).catch(reject); + } + }); + + client.connect({port, host: '127.0.0.1'}, function() {}); + }); +} + module.exports = { dockerPull, dockerBuild, diff --git a/lib/parser.js b/lib/parser.js index a679821..e93594e 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -90,20 +90,9 @@ const drawTable = (data) => { if (row[key] === null) { rowValues.push("-"); } else if (Array.isArray(row[key])) { - switch (row[key].length) { - case 1: - if (typeof row[key][0] === 'object') { - rowValues.push(`array(${row[key].length})`); - } else { - rowValues.push(row[key][0]); - } - break; - default: - rowValues.push(`array(${row[key].length})`); - break; - } + rowValues.push(JSON.stringify(row[key])); } else if (typeof row[key] === 'object') { - rowValues.push("object"); + rowValues.push(JSON.stringify(row[key])); } else { rowValues.push(row[key]); } @@ -131,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.4'; + const version = '6.0.0-rc.5'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/lib/questions.js b/lib/questions.js index 8798bd5..d5fdc29 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -247,11 +247,10 @@ const questionsPullFunctions = [ if (functions.length === 0) { throw "We couldn't find any functions in your Appwrite project"; } - return functions.map(func => { return { name: `${func.name} (${func.$id})`, - value: func + value: { ...func } } }); } @@ -634,12 +633,10 @@ const questionsPushFunctions = [ name: "functions", message: "Which functions would you like to push?", validate: (value) => validateRequired('function', value), + when: () => localConfig.getFunctions().length > 0, choices: () => { let functions = localConfig.getFunctions(); checkDeployConditions(localConfig) - if (functions.length === 0) { - throw new Error("No functions found Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one."); - } let choices = functions.map((func, idx) => { return { name: `${func.name} (${func.$id})`, @@ -662,13 +659,11 @@ const questionsPushCollections = [ name: "collections", message: "Which collections would you like to push?", validate: (value) => validateRequired('collection', value), + when: () => localConfig.getCollections().length > 0, choices: () => { let collections = localConfig.getCollections(); checkDeployConditions(localConfig) - if (collections.length === 0) { - throw new Error("No collections found in the current directory. Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one."); - } return collections.map(collection => { return { name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`, @@ -676,13 +671,16 @@ const questionsPushCollections = [ } }); } - }, + } +]; + +const questionPushChanges = [ { type: "input", name: "changes", message: `Would you like to apply these changes? Type "YES" to confirm.` } -] +]; const questionsPushBuckets = [ { @@ -690,12 +688,11 @@ const questionsPushBuckets = [ name: "buckets", message: "Which buckets would you like to push?", validate: (value) => validateRequired('bucket', value), + when: () => localConfig.getBuckets().length > 0, choices: () => { let buckets = localConfig.getBuckets(); checkDeployConditions(localConfig) - if (buckets.length === 0) { - throw new Error("No buckets found in the current directory. Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one."); - } + return buckets.map(bucket => { return { name: `${bucket.name} (${bucket['$id']})`, @@ -711,11 +708,10 @@ const questionsPushMessagingTopics = [ type: "checkbox", name: "topics", message: "Which messaging topic would you like to push?", + when: () => localConfig.getMessagingTopics().length > 0, choices: () => { let topics = localConfig.getMessagingTopics(); - if (topics.length === 0) { - throw new Error("No topics found in the current directory. Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one."); - } + return topics.map(topic => { return { name: `${topic.name} (${topic['$id']})`, @@ -752,12 +748,11 @@ const questionsPushTeams = [ name: "teams", message: "Which teams would you like to push?", validate: (value) => validateRequired('team', value), + when: () => localConfig.getTeams().length > 0, choices: () => { let teams = localConfig.getTeams(); checkDeployConditions(localConfig); - if (teams.length === 0) { - throw new Error("No teams found in the current directory. Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one."); - } + return teams.map(team => { return { name: `${team.name} (${team['$id']})`, @@ -866,5 +861,6 @@ module.exports = { questionsRunFunctions, questionGetEndpoint, questionsInitResources, - questionsCreateTeam + questionsCreateTeam, + questionPushChanges }; diff --git a/lib/spinner.js b/lib/spinner.js index 2f5b3ad..bcc7e6b 100644 --- a/lib/spinner.js +++ b/lib/spinner.js @@ -22,6 +22,7 @@ class Spinner { hideCursor, clearOnComplete, stopOnComplete: true, + linewrap: true, noTTYOutput: true }); } diff --git a/package.json b/package.json index cc47d7d..daac1ad 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.4", + "version": "6.0.0-rc.5", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 138de4b..46f0d71 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.4", + "version": "6.0.0-rc.5", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From a0fbc8b4eb405e22a5cd6f59e6b92e03e6a06067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= <matejbaco2000@gmail.com> Date: Sat, 27 Jul 2024 10:08:51 +0000 Subject: [PATCH 08/18] RC update --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/parser.js | 2 +- package.json | 5 +++-- scoop/appwrite.json | 6 +++--- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 365f8be..76cbd44 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.5 +6.0.0-rc.6 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.5 +6.0.0-rc.6 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index dcc1ed2..4e07dc4 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 823437c..881b4f8 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.5" + GITHUB_LATEST_VERSION="6.0.0-rc.6" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index f9260d9..e5953e9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.5', - 'user-agent' : `AppwriteCLI/6.0.0-rc.5 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.6', + 'user-agent' : `AppwriteCLI/6.0.0-rc.6 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.5.0', }; } diff --git a/lib/parser.js b/lib/parser.js index e93594e..c32fdf6 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.5'; + const version = '6.0.0-rc.6'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index daac1ad..5b6e155 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.5", + "version": "6.0.0-rc.6", "license": "BSD-3-Clause", "main": "index.js", "bin": { @@ -34,7 +34,8 @@ "tar": "^6.1.11", "ignore": "^5.2.0", "chokidar": "^3.6.0", - "tail": "^2.2.6" + "tail": "^2.2.6", + "dotenv": "^16.3.1" }, "devDependencies": { "pkg": "5.8.1" diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 46f0d71..841122f 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.5", + "version": "6.0.0-rc.6", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From 5301b713b6b0b90268606239259e6b50330333be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= <matejbaco2000@gmail.com> Date: Sat, 27 Jul 2024 10:16:16 +0000 Subject: [PATCH 09/18] QA update --- lib/emulation/docker.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index b23cc10..0e4348d 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -156,15 +156,13 @@ async function dockerStart(func, variables, port) { fs.copyFileSync(sourcePath, filePath); } - const runtimeChunks = func.runtime.split("-"); - const runtimeVersion = runtimeChunks.pop(); - const runtimeName = runtimeChunks.join("-"); + const runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; const tool = systemTools[runtimeName]; - const functionDir = path.join(process.cwd(), func.path); - const id = func.$id; const params = [ 'run' ]; From cd5915d6ea662db4caf939eb9c8ddaba9b453ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= <matejbaco2000@gmail.com> Date: Sat, 27 Jul 2024 11:37:44 +0000 Subject: [PATCH 10/18] RC updage --- lib/commands/push.js | 4 ++-- lib/commands/run.js | 30 +++++++++++++------------ lib/emulation/docker.js | 50 ++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/lib/commands/push.js b/lib/commands/push.js index c0c8bfe..ea3dd21 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -341,7 +341,7 @@ const awaitPools = { } const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => { - log('Checking for changes'); + log('Checking for changes ...'); const changes = []; await Promise.all(resource.map(async (localResource) => { @@ -881,7 +881,7 @@ const pushSettings = async () => { const remoteSettings = localConfig.createSettingsObject(response ?? {}); const localSettings = localConfig.getProject().projectSettings ?? {}; - log('Checking for changes'); + log('Checking for changes ...'); const changes = []; changes.push(...(getObjectChanges(remoteSettings, localSettings, 'services', 'Service'))); diff --git a/lib/commands/run.js b/lib/commands/run.js index a44eb11..71baf0c 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -17,7 +17,9 @@ const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils'); const { runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils'); const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull } = require('../emulation/docker'); -const runFunction = async ({ port, functionId, noVariables, noReload, userId } = {}) => { +const runFunction = async ({ port, functionId, variables, reload, userId } = {}) => { + console.log(variables); + console.log(reload); // Selection if(!functionId) { const answers = await inquirer.prompt(questionsRunFunctions[0]); @@ -113,9 +115,9 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = } const userVariables = {}; - const variables = {}; + const allVariables = {}; - if(!noVariables) { + if(variables) { try { const { variables: remoteVariables } = await paginate(functionsListVariables, { functionId: func['$id'], @@ -123,7 +125,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = }, 100, 'variables'); remoteVariables.forEach((v) => { - variables[v.key] = v.value; + allVariables[v.key] = v.value; userVariables[v.key] = v.value; }); } catch(err) { @@ -137,18 +139,18 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = const env = parseDotenv(fs.readFileSync(envPath).toString() ?? ''); Object.keys(env).forEach((key) => { - variables[key] = env[key]; + allVariables[key] = env[key]; userVariables[key] = env[key]; }); } - variables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint'); - variables['APPWRITE_FUNCTION_ID'] = func.$id; - variables['APPWRITE_FUNCTION_NAME'] = func.name; - variables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant - variables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId; - variables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? ''; - variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime; + allVariables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint'); + allVariables['APPWRITE_FUNCTION_ID'] = func.$id; + allVariables['APPWRITE_FUNCTION_NAME'] = func.name; + allVariables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant + allVariables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId; + allVariables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? ''; + allVariables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime; try { await JwtManager.setup(userId, func.scopes ?? []); @@ -162,7 +164,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = headers['x-appwrite-event'] = ''; headers['x-appwrite-user-id'] = userId ?? ''; headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? ''; - variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers); + allVariables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers); if(Object.keys(userVariables).length > 0) { drawTable(Object.keys(userVariables).map((key) => ({ @@ -180,7 +182,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = process.stdout.write(chalk.white(`${data}\n`)); }); - if(!noReload) { + if(reload) { const ignorer = ignore(); ignorer.add('.appwrite'); ignorer.add('code.tar.gz'); diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index 0e4348d..179d905 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -51,6 +51,31 @@ async function dockerBuild(func, variables) { const id = func.$id; + const ignorer = ignore(); + ignorer.add('.appwrite'); + if (func.ignore) { + ignorer.add(func.ignore); + } else if (fs.existsSync(path.join(functionDir, '.gitignore'))) { + ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString()); + } + + const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file)); + const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build'); + if (!fs.existsSync(tmpBuildPath)) { + fs.mkdirSync(tmpBuildPath, { recursive: true }); + } + + for(const f of files) { + const filePath = path.join(tmpBuildPath, f); + const fileDir = path.dirname(filePath); + if (!fs.existsSync(fileDir)) { + fs.mkdirSync(fileDir, { recursive: true }); + } + + const sourcePath = path.join(functionDir, f); + fs.copyFileSync(sourcePath, filePath); + } + const params = [ 'run' ]; params.push('--name', id); params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`); @@ -131,31 +156,6 @@ async function dockerStart(func, variables, port) { // Pack function files const functionDir = path.join(process.cwd(), func.path); - const ignorer = ignore(); - ignorer.add('.appwrite'); - if (func.ignore) { - ignorer.add(func.ignore); - } else if (fs.existsSync(path.join(functionDir, '.gitignore'))) { - ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString()); - } - - const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file)); - const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build'); - if (!fs.existsSync(tmpBuildPath)) { - fs.mkdirSync(tmpBuildPath, { recursive: true }); - } - - for(const f of files) { - const filePath = path.join(tmpBuildPath, f); - const fileDir = path.dirname(filePath); - if (!fs.existsSync(fileDir)) { - fs.mkdirSync(fileDir, { recursive: true }); - } - - const sourcePath = path.join(functionDir, f); - fs.copyFileSync(sourcePath, filePath); - } - const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); From 86506a4c0a93ddcf0982bb635480bea0527d66c4 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Thu, 8 Aug 2024 13:24:51 +0000 Subject: [PATCH 11/18] chore: updates for rc-7 --- README.md | 6 +- ...ployment.md => get-deployment-download.md} | 2 +- docs/examples/functions/get-template.md | 2 + docs/examples/functions/list-templates.md | 5 + index.js | 7 +- install.ps1 | 4 +- install.sh | 2 +- lib/client.js | 6 +- lib/commands/account.js | 50 +---- lib/commands/assistant.js | 3 +- lib/commands/avatars.js | 9 +- lib/commands/console.js | 3 +- lib/commands/databases.js | 50 +---- lib/commands/functions.js | 156 ++++++++++++---- lib/commands/generic.js | 22 +-- lib/commands/graphql.js | 4 +- lib/commands/health.js | 25 +-- lib/commands/init.js | 27 +-- lib/commands/locale.js | 10 +- lib/commands/messaging.js | 48 +---- lib/commands/migrations.js | 18 +- lib/commands/project.js | 8 +- lib/commands/projects.js | 47 +---- lib/commands/proxy.js | 7 +- lib/commands/pull.js | 108 +++++++---- lib/commands/push.js | 173 ++++++++++++------ lib/commands/run.js | 22 +-- lib/commands/storage.js | 17 +- lib/commands/teams.js | 16 +- lib/commands/users.js | 45 +---- lib/commands/vcs.js | 12 +- lib/config.js | 18 +- lib/emulation/docker.js | 4 +- lib/paginate.js | 4 +- lib/parser.js | 27 ++- lib/questions.js | 47 ++--- package.json | 4 +- scoop/appwrite.json | 6 +- 38 files changed, 428 insertions(+), 596 deletions(-) rename docs/examples/functions/{download-deployment.md => get-deployment-download.md} (63%) create mode 100644 docs/examples/functions/get-template.md create mode 100644 docs/examples/functions/list-templates.md diff --git a/README.md b/README.md index 76cbd44..8c1f9d6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** +**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.6 +6.0.0-rc.7 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.6 +6.0.0-rc.7 ``` ## Getting Started diff --git a/docs/examples/functions/download-deployment.md b/docs/examples/functions/get-deployment-download.md similarity index 63% rename from docs/examples/functions/download-deployment.md rename to docs/examples/functions/get-deployment-download.md index aa440b5..2cbb2bd 100644 --- a/docs/examples/functions/download-deployment.md +++ b/docs/examples/functions/get-deployment-download.md @@ -1,3 +1,3 @@ -appwrite functions downloadDeployment \ +appwrite functions getDeploymentDownload \ --functionId <FUNCTION_ID> \ --deploymentId <DEPLOYMENT_ID> diff --git a/docs/examples/functions/get-template.md b/docs/examples/functions/get-template.md new file mode 100644 index 0000000..15c6068 --- /dev/null +++ b/docs/examples/functions/get-template.md @@ -0,0 +1,2 @@ +appwrite functions getTemplate \ + --templateId <TEMPLATE_ID> diff --git a/docs/examples/functions/list-templates.md b/docs/examples/functions/list-templates.md new file mode 100644 index 0000000..b48bab5 --- /dev/null +++ b/docs/examples/functions/list-templates.md @@ -0,0 +1,5 @@ +appwrite functions listTemplates \ + + + + diff --git a/index.js b/index.js index 58b9dcd..fa7067f 100644 --- a/index.js +++ b/index.js @@ -41,15 +41,16 @@ program .description(commandDescriptions['main']) .configureHelp({ helpWidth: process.stdout.columns || 80, - sortSubcommands: true + sortSubcommands: true, }) - .version(version, "-v, --version") + .helpOption('-h, --help', "Display help for command") + .version(version, "-v, --version", "Output the version number") .option("-V, --verbose", "Show complete error log") .option("-j, --json", "Output in JSON format") .hook('preAction', migrate) .option("-f,--force", "Flag to confirm all warnings") .option("-a,--all", "Flag to push all resources") - .option("--id [id...]", "Flag to pass list of ids for a giving action") + .option("--id [id...]", "Flag to pass a list of ids for a given action") .option("--report", "Enable reporting in case of CLI errors") .on("option:json", () => { cliConfig.json = true; diff --git a/install.ps1 b/install.ps1 index 4e07dc4..e251235 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 881b4f8..e6a452b 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.6" + GITHUB_LATEST_VERSION="6.0.0-rc.7" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index e5953e9..87b7329 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,9 +16,9 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.6', - 'user-agent' : `AppwriteCLI/6.0.0-rc.6 (${os.type()} ${os.version()}; ${os.arch()})`, - 'X-Appwrite-Response-Format' : '1.5.0', + 'x-sdk-version': '6.0.0-rc.7', + 'user-agent' : `AppwriteCLI/6.0.0-rc.7 (${os.type()} ${os.version()}; ${os.arch()})`, + 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/commands/account.js b/lib/commands/account.js index 5df93fa..4c45f43 100644 --- a/lib/commands/account.js +++ b/lib/commands/account.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const account = new Command("account").description(commandDescriptions['account']).configureHelp({ +const account = new Command("account").description(commandDescriptions['account'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -66,7 +66,6 @@ const accountGet = async ({parseOutput = true, overrideForCli = false, sdk = und showConsoleLink('account', 'get'); } else { parse(response) - success() } } @@ -114,7 +113,6 @@ const accountCreate = async ({userId,email,password,name,parseOutput = true, ove if (parseOutput) { parse(response) - success() } return response; @@ -145,7 +143,6 @@ const accountDelete = async ({parseOutput = true, overrideForCli = false, sdk = if (parseOutput) { parse(response) - success() } return response; @@ -184,7 +181,6 @@ const accountUpdateEmail = async ({email,password,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -219,7 +215,6 @@ const accountListIdentities = async ({queries,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -251,7 +246,6 @@ const accountDeleteIdentity = async ({identityId,parseOutput = true, overrideFor if (parseOutput) { parse(response) - success() } return response; @@ -282,7 +276,6 @@ const accountCreateJWT = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; @@ -317,7 +310,6 @@ const accountListLogs = async ({queries,parseOutput = true, overrideForCli = fal if (parseOutput) { parse(response) - success() } return response; @@ -352,7 +344,6 @@ const accountUpdateMFA = async ({mfa,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -384,7 +375,6 @@ const accountCreateMfaAuthenticator = async ({type,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -420,7 +410,6 @@ const accountUpdateMfaAuthenticator = async ({type,otp,parseOutput = true, overr if (parseOutput) { parse(response) - success() } return response; @@ -452,7 +441,6 @@ const accountDeleteMfaAuthenticator = async ({type,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -487,7 +475,6 @@ const accountCreateMfaChallenge = async ({factor,parseOutput = true, overrideFor if (parseOutput) { parse(response) - success() } return response; @@ -526,7 +513,6 @@ const accountUpdateMfaChallenge = async ({challengeId,otp,parseOutput = true, ov if (parseOutput) { parse(response) - success() } return response; @@ -557,7 +543,6 @@ const accountListMfaFactors = async ({parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; @@ -588,7 +573,6 @@ const accountGetMfaRecoveryCodes = async ({parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -619,7 +603,6 @@ const accountCreateMfaRecoveryCodes = async ({parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -650,7 +633,6 @@ const accountUpdateMfaRecoveryCodes = async ({parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -685,7 +667,6 @@ const accountUpdateName = async ({name,parseOutput = true, overrideForCli = fals if (parseOutput) { parse(response) - success() } return response; @@ -724,7 +705,6 @@ const accountUpdatePassword = async ({password,oldPassword,parseOutput = true, o if (parseOutput) { parse(response) - success() } return response; @@ -763,7 +743,6 @@ const accountUpdatePhone = async ({phone,password,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -794,7 +773,6 @@ const accountGetPrefs = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; @@ -829,7 +807,6 @@ const accountUpdatePrefs = async ({prefs,parseOutput = true, overrideForCli = fa if (parseOutput) { parse(response) - success() } return response; @@ -868,7 +845,6 @@ const accountCreateRecovery = async ({email,url,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -911,7 +887,6 @@ const accountUpdateRecovery = async ({userId,secret,password,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -945,7 +920,6 @@ const accountListSessions = async ({parseOutput = true, overrideForCli = false, showConsoleLink('account', 'listSessions'); } else { parse(response) - success() } } @@ -977,7 +951,6 @@ const accountDeleteSessions = async ({parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; @@ -1008,7 +981,6 @@ const accountCreateAnonymousSession = async ({parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -1047,7 +1019,6 @@ const accountCreateEmailPasswordSession = async ({email,password,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -1086,7 +1057,6 @@ const accountUpdateMagicURLSession = async ({userId,secret,parseOutput = true, o if (parseOutput) { parse(response) - success() } return response; @@ -1130,7 +1100,6 @@ const accountCreateOAuth2Session = async ({provider,success,failure,scopes,parse if (parseOutput) { parse(response) - success() } return response; @@ -1169,7 +1138,6 @@ const accountUpdatePhoneSession = async ({userId,secret,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -1208,7 +1176,6 @@ const accountCreateSession = async ({userId,secret,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -1240,7 +1207,6 @@ const accountGetSession = async ({sessionId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -1272,7 +1238,6 @@ const accountUpdateSession = async ({sessionId,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -1304,7 +1269,6 @@ const accountDeleteSession = async ({sessionId,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -1335,7 +1299,6 @@ const accountUpdateStatus = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -1378,7 +1341,6 @@ const accountCreatePushTarget = async ({targetId,identifier,providerId,parseOutp if (parseOutput) { parse(response) - success() } return response; @@ -1414,7 +1376,6 @@ const accountUpdatePushTarget = async ({targetId,identifier,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -1446,7 +1407,6 @@ const accountDeletePushTarget = async ({targetId,parseOutput = true, overrideFor if (parseOutput) { parse(response) - success() } return response; @@ -1489,7 +1449,6 @@ const accountCreateEmailToken = async ({userId,email,phrase,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -1536,7 +1495,6 @@ const accountCreateMagicURLToken = async ({userId,email,url,phrase,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -1580,7 +1538,6 @@ const accountCreateOAuth2Token = async ({provider,success,failure,scopes,parseOu if (parseOutput) { parse(response) - success() } return response; @@ -1619,7 +1576,6 @@ const accountCreatePhoneToken = async ({userId,phone,parseOutput = true, overrid if (parseOutput) { parse(response) - success() } return response; @@ -1654,7 +1610,6 @@ const accountCreateVerification = async ({url,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -1693,7 +1648,6 @@ const accountUpdateVerification = async ({userId,secret,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -1724,7 +1678,6 @@ const accountCreatePhoneVerification = async ({parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -1763,7 +1716,6 @@ const accountUpdatePhoneVerification = async ({userId,secret,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/assistant.js b/lib/commands/assistant.js index 3a1da8a..16a17ec 100644 --- a/lib/commands/assistant.js +++ b/lib/commands/assistant.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const assistant = new Command("assistant").description(commandDescriptions['assistant']).configureHelp({ +const assistant = new Command("assistant").description(commandDescriptions['assistant'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -67,7 +67,6 @@ const assistantChat = async ({prompt,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/avatars.js b/lib/commands/avatars.js index c0649d8..0468eb8 100644 --- a/lib/commands/avatars.js +++ b/lib/commands/avatars.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const avatars = new Command("avatars").description(commandDescriptions['avatars']).configureHelp({ +const avatars = new Command("avatars").description(commandDescriptions['avatars'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -88,7 +88,6 @@ const avatarsGetBrowser = async ({code,width,height,quality,parseOutput = true, fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -144,7 +143,6 @@ const avatarsGetCreditCard = async ({code,width,height,quality,parseOutput = tru fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -191,7 +189,6 @@ const avatarsGetFavicon = async ({url,parseOutput = true, overrideForCli = false fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -247,7 +244,6 @@ const avatarsGetFlag = async ({code,width,height,quality,parseOutput = true, ove fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -302,7 +298,6 @@ const avatarsGetImage = async ({url,width,height,parseOutput = true, overrideFor fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -361,7 +356,6 @@ const avatarsGetInitials = async ({name,width,height,background,parseOutput = tr fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -420,7 +414,6 @@ const avatarsGetQR = async ({text,size,margin,download,parseOutput = true, overr fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/console.js b/lib/commands/console.js index ef46397..180c38a 100644 --- a/lib/commands/console.js +++ b/lib/commands/console.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const console = new Command("console").description(commandDescriptions['console']).configureHelp({ +const console = new Command("console").description(commandDescriptions['console'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -63,7 +63,6 @@ const consoleVariables = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/databases.js b/lib/commands/databases.js index 3174403..66b49e6 100644 --- a/lib/commands/databases.js +++ b/lib/commands/databases.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const databases = new Command("databases").description(commandDescriptions['databases']).configureHelp({ +const databases = new Command("databases").description(commandDescriptions['databases'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const databasesList = async ({queries,search,parseOutput = true, overrideForCli showConsoleLink('databases', 'list'); } else { parse(response) - success() } } @@ -118,7 +117,6 @@ const databasesCreate = async ({databaseId,name,enabled,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -153,7 +151,6 @@ const databasesGetUsage = async ({range,parseOutput = true, overrideForCli = fal if (parseOutput) { parse(response) - success() } return response; @@ -188,7 +185,6 @@ const databasesGet = async ({databaseId,parseOutput = true, overrideForCli = fal showConsoleLink('databases', 'get', databaseId); } else { parse(response) - success() } } @@ -229,7 +225,6 @@ const databasesUpdate = async ({databaseId,name,enabled,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -261,7 +256,6 @@ const databasesDelete = async ({databaseId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -304,7 +298,6 @@ const databasesListCollections = async ({databaseId,queries,search,parseOutput = showConsoleLink('databases', 'listCollections', databaseId); } else { parse(response) - success() } } @@ -358,7 +351,6 @@ const databasesCreateCollection = async ({databaseId,collectionId,name,permissio if (parseOutput) { parse(response) - success() } return response; @@ -394,7 +386,6 @@ const databasesGetCollection = async ({databaseId,collectionId,parseOutput = tru showConsoleLink('databases', 'getCollection', databaseId, collectionId); } else { parse(response) - success() } } @@ -445,7 +436,6 @@ const databasesUpdateCollection = async ({databaseId,collectionId,name,permissio if (parseOutput) { parse(response) - success() } return response; @@ -478,7 +468,6 @@ const databasesDeleteCollection = async ({databaseId,collectionId,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -518,7 +507,6 @@ const databasesListAttributes = async ({databaseId,collectionId,queries,parseOut showConsoleLink('databases', 'listAttributes', databaseId, collectionId); } else { parse(response) - success() } } @@ -568,7 +556,6 @@ const databasesCreateBooleanAttribute = async ({databaseId,collectionId,key,requ if (parseOutput) { parse(response) - success() } return response; @@ -610,7 +597,6 @@ const databasesUpdateBooleanAttribute = async ({databaseId,collectionId,key,requ if (parseOutput) { parse(response) - success() } return response; @@ -659,7 +645,6 @@ const databasesCreateDatetimeAttribute = async ({databaseId,collectionId,key,req if (parseOutput) { parse(response) - success() } return response; @@ -701,7 +686,6 @@ const databasesUpdateDatetimeAttribute = async ({databaseId,collectionId,key,req if (parseOutput) { parse(response) - success() } return response; @@ -750,7 +734,6 @@ const databasesCreateEmailAttribute = async ({databaseId,collectionId,key,requir if (parseOutput) { parse(response) - success() } return response; @@ -792,7 +775,6 @@ const databasesUpdateEmailAttribute = async ({databaseId,collectionId,key,requir if (parseOutput) { parse(response) - success() } return response; @@ -846,7 +828,6 @@ const databasesCreateEnumAttribute = async ({databaseId,collectionId,key,element if (parseOutput) { parse(response) - success() } return response; @@ -893,7 +874,6 @@ const databasesUpdateEnumAttribute = async ({databaseId,collectionId,key,element if (parseOutput) { parse(response) - success() } return response; @@ -950,7 +930,6 @@ const databasesCreateFloatAttribute = async ({databaseId,collectionId,key,requir if (parseOutput) { parse(response) - success() } return response; @@ -1000,7 +979,6 @@ const databasesUpdateFloatAttribute = async ({databaseId,collectionId,key,requir if (parseOutput) { parse(response) - success() } return response; @@ -1057,7 +1035,6 @@ const databasesCreateIntegerAttribute = async ({databaseId,collectionId,key,requ if (parseOutput) { parse(response) - success() } return response; @@ -1107,7 +1084,6 @@ const databasesUpdateIntegerAttribute = async ({databaseId,collectionId,key,requ if (parseOutput) { parse(response) - success() } return response; @@ -1156,7 +1132,6 @@ const databasesCreateIpAttribute = async ({databaseId,collectionId,key,required, if (parseOutput) { parse(response) - success() } return response; @@ -1198,7 +1173,6 @@ const databasesUpdateIpAttribute = async ({databaseId,collectionId,key,required, if (parseOutput) { parse(response) - success() } return response; @@ -1255,7 +1229,6 @@ const databasesCreateRelationshipAttribute = async ({databaseId,collectionId,rel if (parseOutput) { parse(response) - success() } return response; @@ -1312,7 +1285,6 @@ const databasesCreateStringAttribute = async ({databaseId,collectionId,key,size, if (parseOutput) { parse(response) - success() } return response; @@ -1354,7 +1326,6 @@ const databasesUpdateStringAttribute = async ({databaseId,collectionId,key,requi if (parseOutput) { parse(response) - success() } return response; @@ -1403,7 +1374,6 @@ const databasesCreateUrlAttribute = async ({databaseId,collectionId,key,required if (parseOutput) { parse(response) - success() } return response; @@ -1445,7 +1415,6 @@ const databasesUpdateUrlAttribute = async ({databaseId,collectionId,key,required if (parseOutput) { parse(response) - success() } return response; @@ -1479,7 +1448,6 @@ const databasesGetAttribute = async ({databaseId,collectionId,key,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -1513,7 +1481,6 @@ const databasesDeleteAttribute = async ({databaseId,collectionId,key,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -1551,7 +1518,6 @@ const databasesUpdateRelationshipAttribute = async ({databaseId,collectionId,key if (parseOutput) { parse(response) - success() } return response; @@ -1591,7 +1557,6 @@ const databasesListDocuments = async ({databaseId,collectionId,queries,parseOutp showConsoleLink('databases', 'listDocuments', databaseId, collectionId); } else { parse(response) - success() } } @@ -1638,7 +1603,6 @@ const databasesCreateDocument = async ({databaseId,collectionId,documentId,data, if (parseOutput) { parse(response) - success() } return response; @@ -1679,7 +1643,6 @@ const databasesGetDocument = async ({databaseId,collectionId,documentId,queries, showConsoleLink('databases', 'getDocument', databaseId, collectionId, documentId); } else { parse(response) - success() } } @@ -1723,7 +1686,6 @@ const databasesUpdateDocument = async ({databaseId,collectionId,documentId,data, if (parseOutput) { parse(response) - success() } return response; @@ -1757,7 +1719,6 @@ const databasesDeleteDocument = async ({databaseId,collectionId,documentId,parse if (parseOutput) { parse(response) - success() } return response; @@ -1795,7 +1756,6 @@ const databasesListDocumentLogs = async ({databaseId,collectionId,documentId,que if (parseOutput) { parse(response) - success() } return response; @@ -1835,7 +1795,6 @@ const databasesListIndexes = async ({databaseId,collectionId,queries,parseOutput showConsoleLink('databases', 'listIndexes', databaseId, collectionId); } else { parse(response) - success() } } @@ -1887,7 +1846,6 @@ const databasesCreateIndex = async ({databaseId,collectionId,key,type,attributes if (parseOutput) { parse(response) - success() } return response; @@ -1921,7 +1879,6 @@ const databasesGetIndex = async ({databaseId,collectionId,key,parseOutput = true if (parseOutput) { parse(response) - success() } return response; @@ -1955,7 +1912,6 @@ const databasesDeleteIndex = async ({databaseId,collectionId,key,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -1992,7 +1948,6 @@ const databasesListCollectionLogs = async ({databaseId,collectionId,queries,pars if (parseOutput) { parse(response) - success() } return response; @@ -2029,7 +1984,6 @@ const databasesGetCollectionUsage = async ({databaseId,collectionId,range,parseO if (parseOutput) { parse(response) - success() } return response; @@ -2065,7 +2019,6 @@ const databasesListLogs = async ({databaseId,queries,parseOutput = true, overrid if (parseOutput) { parse(response) - success() } return response; @@ -2104,7 +2057,6 @@ const databasesGetDatabaseUsage = async ({databaseId,range,parseOutput = true, o showConsoleLink('databases', 'getDatabaseUsage', databaseId); } else { parse(response) - success() } } diff --git a/lib/commands/functions.js b/lib/commands/functions.js index 7f82da9..f44b979 100644 --- a/lib/commands/functions.js +++ b/lib/commands/functions.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const functions = new Command("functions").description(commandDescriptions['functions']).configureHelp({ +const functions = new Command("functions").description(commandDescriptions['functions'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const functionsList = async ({queries,search,parseOutput = true, overrideForCli showConsoleLink('functions', 'list'); } else { parse(response) - success() } } @@ -193,7 +192,6 @@ const functionsCreate = async ({functionId,name,runtime,execute,events,schedule, if (parseOutput) { parse(response) - success() } return response; @@ -224,7 +222,91 @@ const functionsListRuntimes = async ({parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() + } + + return response; + +} + +/** + * @typedef {Object} FunctionsListTemplatesRequestParams + * @property {string[]} runtimes List of runtimes allowed for filtering function templates. Maximum of 100 runtimes are allowed. + * @property {string[]} useCases List of use cases allowed for filtering function templates. Maximum of 100 use cases are allowed. + * @property {number} limit Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000. + * @property {number} offset Offset the list of returned templates. Maximum offset is 5000. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {FunctionsListTemplatesRequestParams} params + */ +const functionsListTemplates = async ({runtimes,useCases,limit,offset,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/templates'; + let payload = {}; + if (typeof runtimes !== 'undefined') { + payload['runtimes'] = runtimes; + } + if (typeof useCases !== 'undefined') { + payload['useCases'] = useCases; + } + if (typeof limit !== 'undefined') { + payload['limit'] = limit; + } + if (typeof offset !== 'undefined') { + payload['offset'] = offset; + } + + let response = undefined; + + response = await client.call('get', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + if(console) { + showConsoleLink('functions', 'listTemplates'); + } else { + parse(response) + } + } + + return response; + +} + +/** + * @typedef {Object} FunctionsGetTemplateRequestParams + * @property {string} templateId Template ID. + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {FunctionsGetTemplateRequestParams} params + */ +const functionsGetTemplate = async ({templateId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/templates/{templateId}'.replace('{templateId}', templateId); + let payload = {}; + + let response = undefined; + + response = await client.call('get', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + if(console) { + showConsoleLink('functions', 'getTemplate', templateId); + } else { + parse(response) + } } return response; @@ -259,7 +341,6 @@ const functionsGetUsage = async ({range,parseOutput = true, overrideForCli = fal if (parseOutput) { parse(response) - success() } return response; @@ -294,7 +375,6 @@ const functionsGet = async ({functionId,parseOutput = true, overrideForCli = fal showConsoleLink('functions', 'get', functionId); } else { parse(response) - success() } } @@ -394,7 +474,6 @@ const functionsUpdate = async ({functionId,name,runtime,execute,events,schedule, if (parseOutput) { parse(response) - success() } return response; @@ -426,7 +505,6 @@ const functionsDelete = async ({functionId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -469,7 +547,6 @@ const functionsListDeployments = async ({functionId,queries,search,parseOutput = showConsoleLink('functions', 'listDeployments', functionId); } else { parse(response) - success() } } @@ -523,15 +600,17 @@ const functionsCreateDeployment = async ({functionId,code,activate,entrypoint,co const files = getAllFiles(code).map((file) => pathLib.relative(code, file)).filter((file) => !ignorer.ignores(file)); + const archiveFileName = `${functionId}-code.tar.gz`; + await tar .create({ gzip: true, sync: true, cwd: folderPath, - file: 'code.tar.gz' + file: archiveFileName }, files); - let archivePath = fs.realpathSync('code.tar.gz') + let archivePath = fs.realpathSync(archiveFileName) if (typeof archivePath !== 'undefined') { payload['code'] = archivePath; code = archivePath; @@ -634,7 +713,6 @@ const functionsCreateDeployment = async ({functionId,code,activate,entrypoint,co if (parseOutput) { parse(response) - success() } return response; @@ -669,7 +747,6 @@ const functionsGetDeployment = async ({functionId,deploymentId,parseOutput = tru showConsoleLink('functions', 'getDeployment', functionId, deploymentId); } else { parse(response) - success() } } @@ -703,7 +780,6 @@ const functionsUpdateDeployment = async ({functionId,deploymentId,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -736,7 +812,6 @@ const functionsDeleteDeployment = async ({functionId,deploymentId,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -773,7 +848,6 @@ const functionsCreateBuild = async ({functionId,deploymentId,buildId,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -806,7 +880,6 @@ const functionsUpdateDeploymentBuild = async ({functionId,deploymentId,parseOutp if (parseOutput) { parse(response) - success() } return response; @@ -814,7 +887,7 @@ const functionsUpdateDeploymentBuild = async ({functionId,deploymentId,parseOutp } /** - * @typedef {Object} FunctionsDownloadDeploymentRequestParams + * @typedef {Object} FunctionsGetDeploymentDownloadRequestParams * @property {string} functionId Function ID. * @property {string} deploymentId Deployment ID. * @property {boolean} overrideForCli @@ -824,9 +897,9 @@ const functionsUpdateDeploymentBuild = async ({functionId,deploymentId,parseOutp */ /** - * @param {FunctionsDownloadDeploymentRequestParams} params + * @param {FunctionsGetDeploymentDownloadRequestParams} params */ -const functionsDownloadDeployment = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => { +const functionsGetDeploymentDownload = async ({functionId,deploymentId,parseOutput = true, overrideForCli = false, sdk = undefined, destination, console}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); @@ -850,8 +923,11 @@ const functionsDownloadDeployment = async ({functionId,deploymentId,parseOutput fs.writeFileSync(destination, response); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'getDeploymentDownload', functionId, deploymentId); + } else { + parse(response) + } } return response; @@ -894,7 +970,6 @@ const functionsListExecutions = async ({functionId,queries,search,parseOutput = showConsoleLink('functions', 'listExecutions', functionId); } else { parse(response) - success() } } @@ -951,7 +1026,6 @@ const functionsCreateExecution = async ({functionId,body,async,xpath,method,head if (parseOutput) { parse(response) - success() } return response; @@ -987,7 +1061,6 @@ const functionsGetExecution = async ({functionId,executionId,parseOutput = true, showConsoleLink('functions', 'getExecution', functionId, executionId); } else { parse(response) - success() } } @@ -1021,7 +1094,6 @@ const functionsDeleteExecution = async ({functionId,executionId,parseOutput = tr if (parseOutput) { parse(response) - success() } return response; @@ -1060,7 +1132,6 @@ const functionsGetFunctionUsage = async ({functionId,range,parseOutput = true, o showConsoleLink('functions', 'getFunctionUsage', functionId); } else { parse(response) - success() } } @@ -1093,7 +1164,6 @@ const functionsListVariables = async ({functionId,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -1133,7 +1203,6 @@ const functionsCreateVariable = async ({functionId,key,value,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -1166,7 +1235,6 @@ const functionsGetVariable = async ({functionId,variableId,parseOutput = true, o if (parseOutput) { parse(response) - success() } return response; @@ -1207,7 +1275,6 @@ const functionsUpdateVariable = async ({functionId,variableId,key,value,parseOut if (parseOutput) { parse(response) - success() } return response; @@ -1240,7 +1307,6 @@ const functionsDeleteVariable = async ({functionId,variableId,parseOutput = true if (parseOutput) { parse(response) - success() } return response; @@ -1286,6 +1352,23 @@ functions .description(`Get a list of all runtimes that are currently active on your instance.`) .action(actionRunner(functionsListRuntimes)) +functions + .command(`list-templates`) + .description(`List available function templates. You can use template details in [createFunction](/docs/references/cloud/server-nodejs/functions#create) method.`) + .option(`--runtimes [runtimes...]`, `List of runtimes allowed for filtering function templates. Maximum of 100 runtimes are allowed.`) + .option(`--use-cases [use-cases...]`, `List of use cases allowed for filtering function templates. Maximum of 100 use cases are allowed.`) + .option(`--limit <limit>`, `Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.`, parseInteger) + .option(`--offset <offset>`, `Offset the list of returned templates. Maximum offset is 5000.`, parseInteger) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsListTemplates)) + +functions + .command(`get-template`) + .description(`Get a function template using ID. You can use template details in [createFunction](/docs/references/cloud/server-nodejs/functions#create) method.`) + .requiredOption(`--template-id <template-id>`, `Template ID.`) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsGetTemplate)) + functions .command(`get-usage`) .description(``) @@ -1384,12 +1467,13 @@ functions .action(actionRunner(functionsUpdateDeploymentBuild)) functions - .command(`download-deployment`) + .command(`get-deployment-download`) .description(`Get a Deployment's contents by its unique ID. This endpoint supports range requests for partial or streaming file download.`) .requiredOption(`--function-id <function-id>`, `Function ID.`) .requiredOption(`--deployment-id <deployment-id>`, `Deployment ID.`) .requiredOption(`--destination <path>`, `output file path.`) - .action(actionRunner(functionsDownloadDeployment)) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsGetDeploymentDownload)) functions .command(`list-executions`) @@ -1477,6 +1561,8 @@ module.exports = { functionsList, functionsCreate, functionsListRuntimes, + functionsListTemplates, + functionsGetTemplate, functionsGetUsage, functionsGet, functionsUpdate, @@ -1488,7 +1574,7 @@ module.exports = { functionsDeleteDeployment, functionsCreateBuild, functionsUpdateDeploymentBuild, - functionsDownloadDeployment, + functionsGetDeploymentDownload, functionsListExecutions, functionsCreateExecution, functionsGetExecution, diff --git a/lib/commands/generic.js b/lib/commands/generic.js index 691ff85..6b6e5df 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -6,7 +6,7 @@ const { globalConfig, localConfig } = require("../config"); const { actionRunner, success, parseBool, commandDescriptions, error, parse, hint, log, drawTable, cliConfig } = require("../parser"); const ID = require("../id"); const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions"); -const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); +const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1'; @@ -14,17 +14,17 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => { const oldCurrent = globalConfig.getCurrentSession(); let configEndpoint = endpoint ?? DEFAULT_ENDPOINT; - if(globalConfig.getCurrentSession() !== '') { + if (globalConfig.getCurrentSession() !== '') { log('You are currently signed in as ' + globalConfig.getEmail()); - if(globalConfig.getSessions().length === 1) { + if (globalConfig.getSessions().length === 1) { hint('You can sign in and manage multiple accounts with Appwrite CLI'); } } const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin); - if(!answers.method) { + if (!answers.method) { answers.method = 'login'; } @@ -92,7 +92,7 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => { } else { globalConfig.removeSession(id); globalConfig.setCurrentSession(oldCurrent); - if(endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials'){ + if (endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials') { log('Use the --endpoint option for self-hosted instances') } throw error; @@ -135,7 +135,7 @@ const whoami = new Command("whoami") } ]; - if(cliConfig.json) { + if (cliConfig.json) { console.log(data); return; } @@ -193,7 +193,7 @@ const logout = new Command("logout") } if (sessions.length === 1) { await deleteSession(current); - success(); + success("Logging out"); return; } @@ -207,16 +207,16 @@ const logout = new Command("logout") } } - const remainingSessions = globalConfig.getSessions(); + const remainingSessions = globalConfig.getSessions(); - if (remainingSessions .length > 0 && remainingSessions .filter(session => session.id === current).length !== 1) { + if (remainingSessions.length > 0 && remainingSessions.filter(session => session.id === current).length !== 1) { const accountId = remainingSessions [0].id; globalConfig.setCurrentSession(accountId); success(`Current account is ${accountId}`); } - success(); + success("Logging out"); })); const client = new Command("client") @@ -292,7 +292,7 @@ const client = new Command("client") } } - success() + success("Setting client") })); const migrate = async () => { diff --git a/lib/commands/graphql.js b/lib/commands/graphql.js index 8c6a90b..c3c6c0c 100644 --- a/lib/commands/graphql.js +++ b/lib/commands/graphql.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const graphql = new Command("graphql").description(commandDescriptions['graphql']).configureHelp({ +const graphql = new Command("graphql").description(commandDescriptions['graphql'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -68,7 +68,6 @@ const graphqlQuery = async ({query,parseOutput = true, overrideForCli = false, s if (parseOutput) { parse(response) - success() } return response; @@ -104,7 +103,6 @@ const graphqlMutation = async ({query,parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/health.js b/lib/commands/health.js index 70a291b..99f6896 100644 --- a/lib/commands/health.js +++ b/lib/commands/health.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const health = new Command("health").description(commandDescriptions['health']).configureHelp({ +const health = new Command("health").description(commandDescriptions['health'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -63,7 +63,6 @@ const healthGet = async ({parseOutput = true, overrideForCli = false, sdk = unde if (parseOutput) { parse(response) - success() } return response; @@ -94,7 +93,6 @@ const healthGetAntivirus = async ({parseOutput = true, overrideForCli = false, s if (parseOutput) { parse(response) - success() } return response; @@ -125,7 +123,6 @@ const healthGetCache = async ({parseOutput = true, overrideForCli = false, sdk = if (parseOutput) { parse(response) - success() } return response; @@ -160,7 +157,6 @@ const healthGetCertificate = async ({domain,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -191,7 +187,6 @@ const healthGetDB = async ({parseOutput = true, overrideForCli = false, sdk = un if (parseOutput) { parse(response) - success() } return response; @@ -222,7 +217,6 @@ const healthGetPubSub = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; @@ -253,7 +247,6 @@ const healthGetQueue = async ({parseOutput = true, overrideForCli = false, sdk = if (parseOutput) { parse(response) - success() } return response; @@ -288,7 +281,6 @@ const healthGetQueueBuilds = async ({threshold,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -323,7 +315,6 @@ const healthGetQueueCertificates = async ({threshold,parseOutput = true, overrid if (parseOutput) { parse(response) - success() } return response; @@ -362,7 +353,6 @@ const healthGetQueueDatabases = async ({name,threshold,parseOutput = true, overr if (parseOutput) { parse(response) - success() } return response; @@ -397,7 +387,6 @@ const healthGetQueueDeletes = async ({threshold,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -433,7 +422,6 @@ const healthGetFailedJobs = async ({name,threshold,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -468,7 +456,6 @@ const healthGetQueueFunctions = async ({threshold,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -503,7 +490,6 @@ const healthGetQueueLogs = async ({threshold,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -538,7 +524,6 @@ const healthGetQueueMails = async ({threshold,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -573,7 +558,6 @@ const healthGetQueueMessaging = async ({threshold,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -608,7 +592,6 @@ const healthGetQueueMigrations = async ({threshold,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -643,7 +626,6 @@ const healthGetQueueUsage = async ({threshold,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -678,7 +660,6 @@ const healthGetQueueUsageDump = async ({threshold,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -713,7 +694,6 @@ const healthGetQueueWebhooks = async ({threshold,parseOutput = true, overrideFor if (parseOutput) { parse(response) - success() } return response; @@ -744,7 +724,6 @@ const healthGetStorage = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; @@ -775,7 +754,6 @@ const healthGetStorageLocal = async ({parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; @@ -806,7 +784,6 @@ const healthGetTime = async ({parseOutput = true, overrideForCli = false, sdk = if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/init.js b/lib/commands/init.js index 69e34c1..4f2b6a3 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -129,7 +129,7 @@ const initBucket = async () => { fileSecurity: answers.fileSecurity.toLowerCase() === 'yes', enabled: true, }); - success(); + success("Initialing bucket"); log("Next you can use 'appwrite push bucket' to deploy the changes."); }; @@ -141,7 +141,7 @@ const initTeam = async () => { name: answers.bucket, }); - success(); + success("Initialing team"); log("Next you can use 'appwrite push team' to deploy the changes."); }; @@ -174,7 +174,7 @@ const initCollection = async () => { enabled: true, }); - success(); + success("Initialing collection"); log("Next you can use 'appwrite push collection' to deploy the changes."); }; @@ -187,7 +187,7 @@ const initTopic = async () => { }); - success(); + success("Initialing topic"); log("Next you can use 'appwrite push topic' to deploy the changes."); }; @@ -223,21 +223,7 @@ const initFunction = async () => { fs.mkdirSync(templatesDir, "777"); const repo = "https://github.com/appwrite/templates"; const api = `https://api.github.com/repos/appwrite/templates/contents/${answers.runtime.name}` - let selected = undefined; - - if(answers.template === 'starter') { - selected = { template: 'starter' }; - } else { - try { - const res = await fetch(api); - const templates = []; - templates.push(...(await res.json()).map((template) => template.name)); - selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates)); - } catch { - // Not a problem will go with directory pulling - log('Loading templates...'); - } - } + let selected = { template: 'starter' }; const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase(); @@ -312,6 +298,7 @@ const initFunction = async () => { runtime: answers.runtime.id, execute: [], events: [], + scopes: [], schedule: "", timeout: 15, enabled: true, @@ -323,7 +310,7 @@ const initFunction = async () => { }; localConfig.addFunction(data); - success(); + success("Initialing function"); log("Next you can use 'appwrite run function' to develop a function locally. To deploy the function, use 'appwrite push function'"); } diff --git a/lib/commands/locale.js b/lib/commands/locale.js index 1382b96..a23dafa 100644 --- a/lib/commands/locale.js +++ b/lib/commands/locale.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const locale = new Command("locale").description(commandDescriptions['locale']).configureHelp({ +const locale = new Command("locale").description(commandDescriptions['locale'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -63,7 +63,6 @@ const localeGet = async ({parseOutput = true, overrideForCli = false, sdk = unde if (parseOutput) { parse(response) - success() } return response; @@ -94,7 +93,6 @@ const localeListCodes = async ({parseOutput = true, overrideForCli = false, sdk if (parseOutput) { parse(response) - success() } return response; @@ -125,7 +123,6 @@ const localeListContinents = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -156,7 +153,6 @@ const localeListCountries = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -187,7 +183,6 @@ const localeListCountriesEU = async ({parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; @@ -218,7 +213,6 @@ const localeListCountriesPhones = async ({parseOutput = true, overrideForCli = f if (parseOutput) { parse(response) - success() } return response; @@ -249,7 +243,6 @@ const localeListCurrencies = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -280,7 +273,6 @@ const localeListLanguages = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/messaging.js b/lib/commands/messaging.js index b775315..0004554 100644 --- a/lib/commands/messaging.js +++ b/lib/commands/messaging.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const messaging = new Command("messaging").description(commandDescriptions['messaging']).configureHelp({ +const messaging = new Command("messaging").description(commandDescriptions['messaging'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const messagingListMessages = async ({queries,search,parseOutput = true, overrid showConsoleLink('messaging', 'listMessages'); } else { parse(response) - success() } } @@ -160,7 +159,6 @@ const messagingCreateEmail = async ({messageId,subject,content,topics,users,targ if (parseOutput) { parse(response) - success() } return response; @@ -242,7 +240,6 @@ const messagingUpdateEmail = async ({messageId,topics,users,targets,subject,cont if (parseOutput) { parse(response) - success() } return response; @@ -340,7 +337,6 @@ const messagingCreatePush = async ({messageId,title,body,topics,users,targets,da if (parseOutput) { parse(response) - success() } return response; @@ -435,7 +431,6 @@ const messagingUpdatePush = async ({messageId,topics,users,targets,title,body,da if (parseOutput) { parse(response) - success() } return response; @@ -497,7 +492,6 @@ const messagingCreateSms = async ({messageId,content,topics,users,targets,draft, if (parseOutput) { parse(response) - success() } return response; @@ -556,7 +550,6 @@ const messagingUpdateSms = async ({messageId,topics,users,targets,content,draft, if (parseOutput) { parse(response) - success() } return response; @@ -591,7 +584,6 @@ const messagingGetMessage = async ({messageId,parseOutput = true, overrideForCli showConsoleLink('messaging', 'getMessage', messageId); } else { parse(response) - success() } } @@ -624,7 +616,6 @@ const messagingDelete = async ({messageId,parseOutput = true, overrideForCli = f if (parseOutput) { parse(response) - success() } return response; @@ -663,7 +654,6 @@ const messagingListMessageLogs = async ({messageId,queries,parseOutput = true, o showConsoleLink('messaging', 'listMessageLogs', messageId); } else { parse(response) - success() } } @@ -700,7 +690,6 @@ const messagingListTargets = async ({messageId,queries,parseOutput = true, overr if (parseOutput) { parse(response) - success() } return response; @@ -742,7 +731,6 @@ const messagingListProviders = async ({queries,search,parseOutput = true, overri showConsoleLink('messaging', 'listProviders'); } else { parse(response) - success() } } @@ -806,7 +794,6 @@ const messagingCreateApnsProvider = async ({providerId,name,authKey,authKeyId,te if (parseOutput) { parse(response) - success() } return response; @@ -866,7 +853,6 @@ const messagingUpdateApnsProvider = async ({providerId,name,enabled,authKey,auth if (parseOutput) { parse(response) - success() } return response; @@ -913,7 +899,6 @@ const messagingCreateFcmProvider = async ({providerId,name,serviceAccountJSON,en if (parseOutput) { parse(response) - success() } return response; @@ -957,7 +942,6 @@ const messagingUpdateFcmProvider = async ({providerId,name,enabled,serviceAccoun if (parseOutput) { parse(response) - success() } return response; @@ -1028,7 +1012,6 @@ const messagingCreateMailgunProvider = async ({providerId,name,apiKey,domain,isE if (parseOutput) { parse(response) - success() } return response; @@ -1096,7 +1079,6 @@ const messagingUpdateMailgunProvider = async ({providerId,name,apiKey,domain,isE if (parseOutput) { parse(response) - success() } return response; @@ -1151,7 +1133,6 @@ const messagingCreateMsg91Provider = async ({providerId,name,templateId,senderId if (parseOutput) { parse(response) - success() } return response; @@ -1203,7 +1184,6 @@ const messagingUpdateMsg91Provider = async ({providerId,name,enabled,templateId, if (parseOutput) { parse(response) - success() } return response; @@ -1266,7 +1246,6 @@ const messagingCreateSendgridProvider = async ({providerId,name,apiKey,fromName, if (parseOutput) { parse(response) - success() } return response; @@ -1326,7 +1305,6 @@ const messagingUpdateSendgridProvider = async ({providerId,name,enabled,apiKey,f if (parseOutput) { parse(response) - success() } return response; @@ -1413,7 +1391,6 @@ const messagingCreateSmtpProvider = async ({providerId,name,host,port,username,p if (parseOutput) { parse(response) - success() } return response; @@ -1497,7 +1474,6 @@ const messagingUpdateSmtpProvider = async ({providerId,name,host,port,username,p if (parseOutput) { parse(response) - success() } return response; @@ -1552,7 +1528,6 @@ const messagingCreateTelesignProvider = async ({providerId,name,from,customerId, if (parseOutput) { parse(response) - success() } return response; @@ -1604,7 +1579,6 @@ const messagingUpdateTelesignProvider = async ({providerId,name,enabled,customer if (parseOutput) { parse(response) - success() } return response; @@ -1659,7 +1633,6 @@ const messagingCreateTextmagicProvider = async ({providerId,name,from,username,a if (parseOutput) { parse(response) - success() } return response; @@ -1711,7 +1684,6 @@ const messagingUpdateTextmagicProvider = async ({providerId,name,enabled,usernam if (parseOutput) { parse(response) - success() } return response; @@ -1766,7 +1738,6 @@ const messagingCreateTwilioProvider = async ({providerId,name,from,accountSid,au if (parseOutput) { parse(response) - success() } return response; @@ -1818,7 +1789,6 @@ const messagingUpdateTwilioProvider = async ({providerId,name,enabled,accountSid if (parseOutput) { parse(response) - success() } return response; @@ -1873,7 +1843,6 @@ const messagingCreateVonageProvider = async ({providerId,name,from,apiKey,apiSec if (parseOutput) { parse(response) - success() } return response; @@ -1925,7 +1894,6 @@ const messagingUpdateVonageProvider = async ({providerId,name,enabled,apiKey,api if (parseOutput) { parse(response) - success() } return response; @@ -1960,7 +1928,6 @@ const messagingGetProvider = async ({providerId,parseOutput = true, overrideForC showConsoleLink('messaging', 'getProvider', providerId); } else { parse(response) - success() } } @@ -1993,7 +1960,6 @@ const messagingDeleteProvider = async ({providerId,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -2029,7 +1995,6 @@ const messagingListProviderLogs = async ({providerId,queries,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -2065,7 +2030,6 @@ const messagingListSubscriberLogs = async ({subscriberId,queries,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -2107,7 +2071,6 @@ const messagingListTopics = async ({queries,search,parseOutput = true, overrideF showConsoleLink('messaging', 'listTopics'); } else { parse(response) - success() } } @@ -2152,7 +2115,6 @@ const messagingCreateTopic = async ({topicId,name,subscribe,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -2187,7 +2149,6 @@ const messagingGetTopic = async ({topicId,parseOutput = true, overrideForCli = f showConsoleLink('messaging', 'getTopic', topicId); } else { parse(response) - success() } } @@ -2229,7 +2190,6 @@ const messagingUpdateTopic = async ({topicId,name,subscribe,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -2261,7 +2221,6 @@ const messagingDeleteTopic = async ({topicId,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -2297,7 +2256,6 @@ const messagingListTopicLogs = async ({topicId,queries,parseOutput = true, overr if (parseOutput) { parse(response) - success() } return response; @@ -2340,7 +2298,6 @@ const messagingListSubscribers = async ({topicId,queries,search,parseOutput = tr showConsoleLink('messaging', 'listSubscribers', topicId); } else { parse(response) - success() } } @@ -2381,7 +2338,6 @@ const messagingCreateSubscriber = async ({topicId,subscriberId,targetId,parseOut if (parseOutput) { parse(response) - success() } return response; @@ -2414,7 +2370,6 @@ const messagingGetSubscriber = async ({topicId,subscriberId,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -2447,7 +2402,6 @@ const messagingDeleteSubscriber = async ({topicId,subscriberId,parseOutput = tru if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/migrations.js b/lib/commands/migrations.js index 3b80874..043cad4 100644 --- a/lib/commands/migrations.js +++ b/lib/commands/migrations.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const migrations = new Command("migrations").description(commandDescriptions['migrations']).configureHelp({ +const migrations = new Command("migrations").description(commandDescriptions['migrations'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -71,7 +71,6 @@ const migrationsList = async ({queries,search,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -119,7 +118,6 @@ const migrationsCreateAppwriteMigration = async ({resources,endpoint,projectId,a if (parseOutput) { parse(response) - success() } return response; @@ -166,7 +164,6 @@ const migrationsGetAppwriteReport = async ({resources,endpoint,projectID,key,par if (parseOutput) { parse(response) - success() } return response; @@ -206,7 +203,6 @@ const migrationsCreateFirebaseMigration = async ({resources,serviceAccount,parse if (parseOutput) { parse(response) - success() } return response; @@ -237,7 +233,6 @@ const migrationsDeleteFirebaseAuth = async ({parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -277,7 +272,6 @@ const migrationsCreateFirebaseOAuthMigration = async ({resources,projectId,parse if (parseOutput) { parse(response) - success() } return response; @@ -308,7 +302,6 @@ const migrationsListFirebaseProjects = async ({parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -347,7 +340,6 @@ const migrationsGetFirebaseReport = async ({resources,serviceAccount,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -386,7 +378,6 @@ const migrationsGetFirebaseReportOAuth = async ({resources,projectId,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -450,7 +441,6 @@ const migrationsCreateNHostMigration = async ({resources,subdomain,region,adminS if (parseOutput) { parse(response) - success() } return response; @@ -513,7 +503,6 @@ const migrationsGetNHostReport = async ({resources,subdomain,region,adminSecret, if (parseOutput) { parse(response) - success() } return response; @@ -573,7 +562,6 @@ const migrationsCreateSupabaseMigration = async ({resources,endpoint,apiKey,data if (parseOutput) { parse(response) - success() } return response; @@ -632,7 +620,6 @@ const migrationsGetSupabaseReport = async ({resources,endpoint,apiKey,databaseHo if (parseOutput) { parse(response) - success() } return response; @@ -664,7 +651,6 @@ const migrationsGet = async ({migrationId,parseOutput = true, overrideForCli = f if (parseOutput) { parse(response) - success() } return response; @@ -696,7 +682,6 @@ const migrationsRetry = async ({migrationId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -728,7 +713,6 @@ const migrationsDelete = async ({migrationId,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/project.js b/lib/commands/project.js index c81e2b5..1630ee5 100644 --- a/lib/commands/project.js +++ b/lib/commands/project.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const project = new Command("project").description(commandDescriptions['project']).configureHelp({ +const project = new Command("project").description(commandDescriptions['project'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -75,7 +75,6 @@ const projectGetUsage = async ({startDate,endDate,period,parseOutput = true, ove if (parseOutput) { parse(response) - success() } return response; @@ -106,7 +105,6 @@ const projectListVariables = async ({parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -145,7 +143,6 @@ const projectCreateVariable = async ({key,value,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -177,7 +174,6 @@ const projectGetVariable = async ({variableId,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -217,7 +213,6 @@ const projectUpdateVariable = async ({variableId,key,value,parseOutput = true, o if (parseOutput) { parse(response) - success() } return response; @@ -249,7 +244,6 @@ const projectDeleteVariable = async ({variableId,parseOutput = true, overrideFor if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/projects.js b/lib/commands/projects.js index 4623d2e..243f762 100644 --- a/lib/commands/projects.js +++ b/lib/commands/projects.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const projects = new Command("projects").description(commandDescriptions['projects']).configureHelp({ +const projects = new Command("projects").description(commandDescriptions['projects'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const projectsList = async ({queries,search,parseOutput = true, overrideForCli = showConsoleLink('projects', 'list'); } else { parse(response) - success() } } @@ -158,7 +157,6 @@ const projectsCreate = async ({projectId,name,teamId,region,description,logo,url if (parseOutput) { parse(response) - success() } return response; @@ -193,7 +191,6 @@ const projectsGet = async ({projectId,parseOutput = true, overrideForCli = false showConsoleLink('projects', 'get', projectId); } else { parse(response) - success() } } @@ -266,7 +263,6 @@ const projectsUpdate = async ({projectId,name,description,logo,url,legalName,leg if (parseOutput) { parse(response) - success() } return response; @@ -298,7 +294,6 @@ const projectsDelete = async ({projectId,parseOutput = true, overrideForCli = fa if (parseOutput) { parse(response) - success() } return response; @@ -338,7 +333,6 @@ const projectsUpdateApiStatus = async ({projectId,api,status,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -374,7 +368,6 @@ const projectsUpdateApiStatusAll = async ({projectId,status,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -410,7 +403,6 @@ const projectsUpdateAuthDuration = async ({projectId,duration,parseOutput = true if (parseOutput) { parse(response) - success() } return response; @@ -446,7 +438,6 @@ const projectsUpdateAuthLimit = async ({projectId,limit,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -482,7 +473,6 @@ const projectsUpdateAuthSessionsLimit = async ({projectId,limit,parseOutput = tr if (parseOutput) { parse(response) - success() } return response; @@ -519,7 +509,6 @@ const projectsUpdateMockNumbers = async ({projectId,numbers,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -555,7 +544,6 @@ const projectsUpdateAuthPasswordDictionary = async ({projectId,enabled,parseOutp if (parseOutput) { parse(response) - success() } return response; @@ -591,7 +579,6 @@ const projectsUpdateAuthPasswordHistory = async ({projectId,limit,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -627,7 +614,6 @@ const projectsUpdatePersonalDataCheck = async ({projectId,enabled,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -663,7 +649,6 @@ const projectsUpdateSessionAlerts = async ({projectId,alerts,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -700,7 +685,6 @@ const projectsUpdateAuthStatus = async ({projectId,method,status,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -741,7 +725,6 @@ const projectsCreateJWT = async ({projectId,scopes,duration,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -776,7 +759,6 @@ const projectsListKeys = async ({projectId,parseOutput = true, overrideForCli = showConsoleLink('projects', 'listKeys', projectId); } else { parse(response) - success() } } @@ -822,7 +804,6 @@ const projectsCreateKey = async ({projectId,name,scopes,expire,parseOutput = tru if (parseOutput) { parse(response) - success() } return response; @@ -858,7 +839,6 @@ const projectsGetKey = async ({projectId,keyId,parseOutput = true, overrideForCl showConsoleLink('projects', 'getKey', projectId, keyId); } else { parse(response) - success() } } @@ -905,7 +885,6 @@ const projectsUpdateKey = async ({projectId,keyId,name,scopes,expire,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -938,7 +917,6 @@ const projectsDeleteKey = async ({projectId,keyId,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -986,7 +964,6 @@ const projectsUpdateOAuth2 = async ({projectId,provider,appId,secret,enabled,par if (parseOutput) { parse(response) - success() } return response; @@ -1021,7 +998,6 @@ const projectsListPlatforms = async ({projectId,parseOutput = true, overrideForC showConsoleLink('projects', 'listPlatforms', projectId); } else { parse(response) - success() } } @@ -1074,7 +1050,6 @@ const projectsCreatePlatform = async ({projectId,type,name,key,store,hostname,pa if (parseOutput) { parse(response) - success() } return response; @@ -1110,7 +1085,6 @@ const projectsGetPlatform = async ({projectId,platformId,parseOutput = true, ove showConsoleLink('projects', 'getPlatform', projectId, platformId); } else { parse(response) - success() } } @@ -1160,7 +1134,6 @@ const projectsUpdatePlatform = async ({projectId,platformId,name,key,store,hostn if (parseOutput) { parse(response) - success() } return response; @@ -1193,7 +1166,6 @@ const projectsDeletePlatform = async ({projectId,platformId,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -1233,7 +1205,6 @@ const projectsUpdateServiceStatus = async ({projectId,service,status,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -1269,7 +1240,6 @@ const projectsUpdateServiceStatusAll = async ({projectId,status,parseOutput = tr if (parseOutput) { parse(response) - success() } return response; @@ -1337,7 +1307,6 @@ const projectsUpdateSmtp = async ({projectId,enabled,senderName,senderEmail,repl if (parseOutput) { parse(response) - success() } return response; @@ -1406,7 +1375,6 @@ const projectsCreateSmtpTest = async ({projectId,emails,senderName,senderEmail,h if (parseOutput) { parse(response) - success() } return response; @@ -1442,7 +1410,6 @@ const projectsUpdateTeam = async ({projectId,teamId,parseOutput = true, override if (parseOutput) { parse(response) - success() } return response; @@ -1476,7 +1443,6 @@ const projectsGetEmailTemplate = async ({projectId,type,locale,parseOutput = tru if (parseOutput) { parse(response) - success() } return response; @@ -1530,7 +1496,6 @@ const projectsUpdateEmailTemplate = async ({projectId,type,locale,subject,messag if (parseOutput) { parse(response) - success() } return response; @@ -1564,7 +1529,6 @@ const projectsDeleteEmailTemplate = async ({projectId,type,locale,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -1598,7 +1562,6 @@ const projectsGetSmsTemplate = async ({projectId,type,locale,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -1636,7 +1599,6 @@ const projectsUpdateSmsTemplate = async ({projectId,type,locale,message,parseOut if (parseOutput) { parse(response) - success() } return response; @@ -1670,7 +1632,6 @@ const projectsDeleteSmsTemplate = async ({projectId,type,locale,parseOutput = tr if (parseOutput) { parse(response) - success() } return response; @@ -1705,7 +1666,6 @@ const projectsListWebhooks = async ({projectId,parseOutput = true, overrideForCl showConsoleLink('projects', 'listWebhooks', projectId); } else { parse(response) - success() } } @@ -1767,7 +1727,6 @@ const projectsCreateWebhook = async ({projectId,name,events,url,security,enabled if (parseOutput) { parse(response) - success() } return response; @@ -1803,7 +1762,6 @@ const projectsGetWebhook = async ({projectId,webhookId,parseOutput = true, overr showConsoleLink('projects', 'getWebhook', projectId, webhookId); } else { parse(response) - success() } } @@ -1866,7 +1824,6 @@ const projectsUpdateWebhook = async ({projectId,webhookId,name,events,url,securi if (parseOutput) { parse(response) - success() } return response; @@ -1899,7 +1856,6 @@ const projectsDeleteWebhook = async ({projectId,webhookId,parseOutput = true, ov if (parseOutput) { parse(response) - success() } return response; @@ -1932,7 +1888,6 @@ const projectsUpdateWebhookSignature = async ({projectId,webhookId,parseOutput = if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/proxy.js b/lib/commands/proxy.js index 9cc74fa..beffbda 100644 --- a/lib/commands/proxy.js +++ b/lib/commands/proxy.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const proxy = new Command("proxy").description(commandDescriptions['proxy']).configureHelp({ +const proxy = new Command("proxy").description(commandDescriptions['proxy'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -71,7 +71,6 @@ const proxyListRules = async ({queries,search,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -114,7 +113,6 @@ const proxyCreateRule = async ({domain,resourceType,resourceId,parseOutput = tru if (parseOutput) { parse(response) - success() } return response; @@ -146,7 +144,6 @@ const proxyGetRule = async ({ruleId,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -178,7 +175,6 @@ const proxyDeleteRule = async ({ruleId,parseOutput = true, overrideForCli = fals if (parseOutput) { parse(response) - success() } return response; @@ -210,7 +206,6 @@ const proxyUpdateRuleVerification = async ({ruleId,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/pull.js b/lib/commands/pull.js index a399aee..ba9d405 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -6,7 +6,7 @@ const inquirer = require("inquirer"); const { messagingListTopics } = require("./messaging"); const { teamsList } = require("./teams"); const { projectsGet } = require("./projects"); -const { functionsList, functionsDownloadDeployment } = require("./functions"); +const { functionsList, functionsGetDeploymentDownload, functionsListDeployments } = require("./functions"); const { databasesGet, databasesListCollections, databasesList } = require("./databases"); const { storageListBuckets } = require("./storage"); const { localConfig } = require("../config"); @@ -56,7 +56,7 @@ const pullSettings = async () => { } } -const pullFunctions = async ({ code }) => { +const pullFunctions = async ({ code, withVariables }) => { log("Fetching functions ..."); let total = 0; @@ -83,47 +83,84 @@ const pullFunctions = async ({ code }) => { const localFunction = localConfig.getFunction(func.$id); func['path'] = localFunction['path']; - if(!localFunction['path']) { + if (!localFunction['path']) { func['path'] = `functions/${func.$id}`; } - + if (!withVariables) { + delete func['vars']; + } localConfig.addFunction(func); if (!fs.existsSync(func['path'])) { fs.mkdirSync(func['path'], { recursive: true }); } - if(code === false) { + if (code === false) { warn("Source code download skipped."); - } else if(!func['deployment']) { - warn("Source code download skipped because function doesn't have active deployment."); - } else { - if(allowCodePull === null) { - const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode); - allowCodePull = codeAnswer.override; + continue; + } + + if (allowCodePull === null) { + const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode); + allowCodePull = codeAnswer.override; + } + + if (!allowCodePull) { + continue; + } + + let deploymentId = null; + + try { + const fetchResponse = await functionsListDeployments({ + functionId: func['$id'], + queries: [ + JSON.stringify({ method: 'limit', values: [1] }), + JSON.stringify({ method: 'orderDesc', values: ['$id'] }) + ], + parseOutput: false + }); + + if (fetchResponse['total'] > 0) { + deploymentId = fetchResponse['deployments'][0]['$id']; } - if(allowCodePull) { - log("Pulling active deployment's code ..."); - - const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` - await functionsDownloadDeployment({ - functionId: func['$id'], - deploymentId: func['deployment'], - destination: compressedFileName, - overrideForCli: true, - parseOutput: false - }); - - tar.extract({ - sync: true, - cwd: func['path'], - file: compressedFileName, - strict: false, - }); - - fs.rmSync(compressedFileName); + } catch { + } + + if (deploymentId === null) { + log("Source code download skipped because function doesn't have any available deployment"); + continue; + } + + log("Pulling latest deployment code ..."); + + const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz` + await functionsGetDeploymentDownload({ + functionId: func['$id'], + deploymentId, + destination: compressedFileName, + overrideForCli: true, + parseOutput: false + }); + + tar.extract({ + sync: true, + cwd: func['path'], + file: compressedFileName, + strict: false, + }); + + fs.rmSync(compressedFileName); + + if (withVariables) { + const envFileLocation = `${func['path']}/.env` + try { + fs.rmSync(envFileLocation); + } catch { } + + fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join('')) } } @@ -170,7 +207,7 @@ const pullCollection = async () => { parseOutput: false }, 100, 'collections'); - for(const collection of collections) { + for (const collection of collections) { localConfig.addCollection({ ...collection, '$createdAt': undefined, @@ -198,7 +235,7 @@ const pullBucket = async () => { const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); - for(const bucket of buckets) { + for (const bucket of buckets) { total++; log(`Pulling bucket ${chalk.bold(bucket['name'])} ...`); localConfig.addBucket(bucket); @@ -223,7 +260,7 @@ const pullTeam = async () => { const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams'); - for(const team of teams) { + for (const team of teams) { total++; log(`Pulling team ${chalk.bold(team['name'])} ...`); localConfig.addTeam(team); @@ -248,7 +285,7 @@ const pullMessagingTopic = async () => { const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics'); - for(const topic of topics) { + for (const topic of topics) { total++; log(`Pulling topic ${chalk.bold(topic['name'])} ...`); localConfig.addMessagingTopic(topic); @@ -279,6 +316,7 @@ pull .alias("functions") .description("Pulling your Appwrite cloud function") .option("--no-code", "Don't pull the function's code") + .option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`) .action(actionRunner(pullFunctions)) pull diff --git a/lib/commands/push.js b/lib/commands/push.js index ea3dd21..d265cfa 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -2,10 +2,10 @@ const chalk = require('chalk'); const inquirer = require("inquirer"); const JSONbig = require("json-bigint")({ storeAsString: false }); const { Command } = require("commander"); -const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config"); +const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection } = require("../config"); const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner'); const { paginate } = require('../paginate'); -const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); +const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions"); const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser"); const { proxyListRules } = require('./proxy'); const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions'); @@ -340,18 +340,56 @@ const awaitPools = { }, } -const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => { +const getConfirmation = async () => { + if (cliConfig.force) { + return true; + } + + async function fixConfirmation() { + const answers = await inquirer.prompt(questionPushChangesConfirmation); + if (answers.changes !== 'YES' && answers.changes !== 'NO') { + return await fixConfirmation(); + } + + return answers.changes; + } + + let answers = await inquirer.prompt(questionPushChanges); + + if (answers.changes !== 'YES' && answers.changes !== 'NO') { + answers.changes = await fixConfirmation(); + } + + if (answers.changes === 'YES') { + return true; + } + + warn('Skipping push action. Changes were not applied.'); + return false; + +}; + +const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = '', secondResourceName = '') => { log('Checking for changes ...'); const changes = []; await Promise.all(resource.map(async (localResource) => { try { - const remoteResource = await resourceGetFunction({ + const options = { [resourceName]: localResource['$id'], parseOutput: false, - }); + }; + + if (secondId !== '' && secondResourceName !== '') { + options[secondResourceName] = localResource[secondId] + } + + const remoteResource = await resourceGetFunction(options); for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) { + if (skipKeys.includes(key)) { + continue; + } if (Array.isArray(value) && Array.isArray(localResource[key])) { if (JSON.stringify(value) !== JSON.stringify(localResource[key])) { changes.push({ @@ -382,11 +420,8 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, } drawTable(changes); - if (!cliConfig.force) { - const answers = await inquirer.prompt(questionPushChanges); - if (answers.changes.toLowerCase() === 'yes') { - return true; - } + if ((await getConfirmation()) === true) { + return true; } success(`Successfully pushed 0 ${resourcePlural}.`); @@ -399,7 +434,7 @@ const getObjectChanges = (remote, local, index, what) => { if (remote[index] && local[index]) { for (let [service, status] of Object.entries(remote[index])) { if (status !== local[index][service]) { - changes.push({ group: what,setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) }) + changes.push({ group: what, setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) }) } } } @@ -661,6 +696,20 @@ const deleteAttribute = async (collection, attribute, isIndex = false) => { }); } +const compareAttribute = (remote, local, reason, key) => { + if (Array.isArray(remote) && Array.isArray(local)) { + if (JSON.stringify(remote) !== JSON.stringify(local)) { + const bol = reason === '' ? '' : '\n'; + reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`; + } + } else if (remote !== local) { + const bol = reason === '' ? '' : '\n'; + reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`; + } + + return reason +} + /** * Check if attribute non-changeable fields has been changed @@ -688,11 +737,7 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) => if (changeableKeys.includes(key)) { if (!recraeting) { - if (remote[key] !== local[key]) { - const bol = reason === '' ? '' : '\n'; - reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; - attribute = local; - } + reason += compareAttribute(remote[key], local[key], reason, key) } continue; } @@ -701,15 +746,7 @@ const checkAttributeChanges = (remote, local, collection, recraeting = true) => continue; } - if (Array.isArray(remote[key]) && Array.isArray(local[key])) { - if (JSON.stringify(remote[key]) !== JSON.stringify(local[key])) { - const bol = reason === '' ? '' : '\n'; - reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; - } - } else if (remote[key] !== local[key]) { - const bol = reason === '' ? '' : '\n'; - reason += `${bol}${key} changed from ${chalk.red(remote[key])} to ${chalk.green(local[key])}`; - } + reason += compareAttribute(remote[key], local[key], reason, key) } return reason === '' ? undefined : { key: keyName, attribute, reason, action }; @@ -766,9 +803,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection, log(`Attribute recreation will cause ${chalk.red('loss of data')}`); } - const answers = await inquirer.prompt(questionPushChanges); - - if (answers.changes.toLowerCase() !== 'yes') { + if ((await getConfirmation()) !== true) { return changedAttributes; } } @@ -890,12 +925,9 @@ const pushSettings = async () => { if (changes.length > 0) { drawTable(changes); - if (!cliConfig.force) { - const answers = await inquirer.prompt(questionPushChanges); - if (answers.changes.toLowerCase() !== 'yes') { - success(`Successfully pushed 0 project settings.`); - return; - } + if ((await getConfirmation()) !== true) { + success(`Successfully pushed 0 project settings.`); + return; } } } catch (e) { @@ -960,7 +992,7 @@ const pushSettings = async () => { } } -const pushFunction = async ({ functionId, async, code } = { returnOnZero: false }) => { +const pushFunction = async ({ functionId, async, code, withVariables } = { returnOnZero: false }) => { const functionIds = []; if (functionId) { @@ -1009,7 +1041,7 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false } } - if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions'))) { + if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions', ['vars']))) { return; } @@ -1019,6 +1051,7 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false let successfullyPushed = 0; let successfullyDeployed = 0; const failedDeployments = []; + const errors = []; await Promise.all(functions.map(async (func) => { let response = {}; @@ -1068,6 +1101,7 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false if (Number(e.code) === 404) { functionExists = false; } else { + errors.push(e); updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' }); return; } @@ -1095,11 +1129,45 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false updaterRow.update({ status: 'Created' }); } catch (e) { + errors.push(e) updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' }); return; } } + if (withVariables) { + updaterRow.update({ status: 'Updating variables' }).replaceSpinner(SPINNER_ARC); + + const { variables } = await paginate(functionsListVariables, { + functionId: func['$id'], + parseOutput: false + }, 100, 'variables'); + + await Promise.all(variables.map(async variable => { + await functionsDeleteVariable({ + functionId: func['$id'], + variableId: variable['$id'], + parseOutput: false + }); + })); + + let result = await awaitPools.wipeVariables(func['$id']); + if (!result) { + updaterRow.fail({ errorMessage: `Variable deletion timed out.` }) + return; + } + + // Deploy local variables + await Promise.all((func['vars'] ?? []).map(async variable => { + await functionsCreateVariable({ + functionId: func['$id'], + key: variable['key'], + value: variable['value'], + parseOutput: false + }); + })); + } + if (code === false) { successfullyPushed++; successfullyDeployed++; @@ -1123,6 +1191,8 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false deploymentCreated = true; successfullyPushed++; } catch (e) { + errors.push(e); + switch (e.code) { case 'ENOENT': updaterRow.fail({ errorMessage: 'Not found in the current directory. Skipping...' }) @@ -1180,6 +1250,7 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE * 1.5)); } } catch (e) { + errors.push(e); updaterRow.fail({ errorMessage: e.message ?? 'Unknown error occurred. Please try again' }) } } @@ -1207,6 +1278,12 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false } else { success(`Successfully pushed ${successfullyPushed} functions.`); } + + if (cliConfig.verbose) { + errors.forEach(e => { + console.error(e); + }) + } } const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false }) => { @@ -1241,8 +1318,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false const databases = Array.from(new Set(collections.map(collection => collection['databaseId']))); - log('Checking for changes ...'); - // Parallel db actions await Promise.all(databases.map(async (databaseId) => { const localDatabase = localConfig.getDatabase(databaseId); @@ -1273,6 +1348,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false } })); + + if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) { + return; + } // Parallel collection actions await Promise.all(collections.map(async (collection) => { try { @@ -1343,10 +1422,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false throw e; } numberOfCollections++; - success(`Pushed ${collection.name} ( ${collection['$id']} )`); + success(`Successfully pushed ${collection.name} ( ${collection['$id']} )`); } - success(`Pushed ${numberOfCollections} collections`); + success(`Successfully pushed ${numberOfCollections} collections`); } const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { @@ -1509,7 +1588,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => let topicsIds = []; const configTopics = localConfig.getMessagingTopics(); - let overrideExisting = cliConfig.force; if (cliConfig.all) { checkDeployConditions(localConfig); @@ -1536,13 +1614,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => topics.push(...idTopic); } - if (!cliConfig.force) { - const answers = await inquirer.prompt(questionsPushMessagingTopics[1]) - if (answers.override.toLowerCase() === "yes") { - overrideExisting = true; - } - } - if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) { return; } @@ -1559,11 +1630,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => }) log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`); - if (!overrideExisting) { - log(`Skipping ${topic.name} ( ${topic['$id']} )`); - continue; - } - await messagingUpdateTopic({ topicId: topic['$id'], name: topic.name, @@ -1615,6 +1681,7 @@ push .option(`-f, --function-id <function-id>`, `ID of function to run`) .option(`-A, --async`, `Don't wait for functions deployments status`) .option("--no-code", "Don't push the function's code") + .option("--with-variables", `Push function variables.`) .action(actionRunner(pushFunction)); push diff --git a/lib/commands/run.js b/lib/commands/run.js index 71baf0c..fea72c3 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -17,9 +17,7 @@ const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils'); const { runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils'); const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull } = require('../emulation/docker'); -const runFunction = async ({ port, functionId, variables, reload, userId } = {}) => { - console.log(variables); - console.log(reload); +const runFunction = async ({ port, functionId, withVariables, reload, userId } = {}) => { // Selection if(!functionId) { const answers = await inquirer.prompt(questionsRunFunctions[0]); @@ -117,7 +115,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) const userVariables = {}; const allVariables = {}; - if(variables) { + if(withVariables) { try { const { variables: remoteVariables } = await paginate(functionsListVariables, { functionId: func['$id'], @@ -129,7 +127,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) userVariables[v.key] = v.value; }); } catch(err) { - warn("Remote variables not fetched. Production environment variables will not be avaiable. Reason: " + err.message); + warn("Remote variables not fetched. Production environment variables will not be available. Reason: " + err.message); } } @@ -186,7 +184,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) const ignorer = ignore(); ignorer.add('.appwrite'); ignorer.add('code.tar.gz'); - + if (func.ignore) { ignorer.add(func.ignore); } else if (fs.existsSync(path.join(functionPath, '.gitignore'))) { @@ -218,14 +216,14 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) const dependencyFile = files.find((filePath) => tool.dependencyFiles.includes(filePath)); if(tool.isCompiled || dependencyFile) { log(`Rebuilding the function due to file changes ...`); - await dockerBuild(func, variables); + await dockerBuild(func, allVariables); if(!Queue.isEmpty()) { Queue.unlock(); return; } - await dockerStart(func, variables, port); + await dockerStart(func, allVariables, port); } else { log('Hot-swapping function.. Files with change are ' + files.join(', ')); @@ -281,7 +279,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) file: buildPath }, ['.']); - await dockerStart(func, variables, port); + await dockerStart(func, allVariables, port); } } catch(err) { console.error(err); @@ -293,7 +291,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) Queue.lock(); log('Building function using Docker ...'); - await dockerBuild(func, variables); + await dockerBuild(func, allVariables); if(!Queue.isEmpty()) { Queue.unlock(); @@ -302,7 +300,7 @@ const runFunction = async ({ port, functionId, variables, reload, userId } = {}) log('Starting function using Docker ...'); hint('Function automatically restarts when you edit your code.'); - await dockerStart(func, variables, port); + await dockerStart(func, allVariables, port); Queue.unlock(); } @@ -323,7 +321,7 @@ run .option(`--function-id <function-id>`, `ID of function to run`) .option(`--port <port>`, `Local port`) .option(`--user-id <user-id>`, `ID of user to impersonate`) - .option(`--no-variables`, `Prevent pulling variables from function settings`) + .option(`--with-variables`, `Run with function variables from function settings`) .option(`--no-reload`, `Prevent live reloading of server when changes are made to function files`) .action(actionRunner(runFunction)); diff --git a/lib/commands/storage.js b/lib/commands/storage.js index 00102b4..16c2f74 100644 --- a/lib/commands/storage.js +++ b/lib/commands/storage.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const storage = new Command("storage").description(commandDescriptions['storage']).configureHelp({ +const storage = new Command("storage").description(commandDescriptions['storage'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const storageListBuckets = async ({queries,search,parseOutput = true, overrideFo showConsoleLink('storage', 'listBuckets'); } else { parse(response) - success() } } @@ -148,7 +147,6 @@ const storageCreateBucket = async ({bucketId,name,permissions,fileSecurity,enabl if (parseOutput) { parse(response) - success() } return response; @@ -183,7 +181,6 @@ const storageGetBucket = async ({bucketId,parseOutput = true, overrideForCli = f showConsoleLink('storage', 'getBucket', bucketId); } else { parse(response) - success() } } @@ -254,7 +251,6 @@ const storageUpdateBucket = async ({bucketId,name,permissions,fileSecurity,enabl if (parseOutput) { parse(response) - success() } return response; @@ -286,7 +282,6 @@ const storageDeleteBucket = async ({bucketId,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -329,7 +324,6 @@ const storageListFiles = async ({bucketId,queries,search,parseOutput = true, ove showConsoleLink('storage', 'listFiles', bucketId); } else { parse(response) - success() } } @@ -465,7 +459,6 @@ const storageCreateFile = async ({bucketId,fileId,file,permissions,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -500,7 +493,6 @@ const storageGetFile = async ({bucketId,fileId,parseOutput = true, overrideForCl showConsoleLink('storage', 'getFile', bucketId, fileId); } else { parse(response) - success() } } @@ -543,7 +535,6 @@ const storageUpdateFile = async ({bucketId,fileId,name,permissions,parseOutput = if (parseOutput) { parse(response) - success() } return response; @@ -576,7 +567,6 @@ const storageDeleteFile = async ({bucketId,fileId,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -621,7 +611,6 @@ const storageGetFileDownload = async ({bucketId,fileId,parseOutput = true, overr fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -710,7 +699,6 @@ const storageGetFilePreview = async ({bucketId,fileId,width,height,gravity,quali fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -755,7 +743,6 @@ const storageGetFileView = async ({bucketId,fileId,parseOutput = true, overrideF fs.writeFileSync(destination, response); if (parseOutput) { parse(response) - success() } return response; @@ -790,7 +777,6 @@ const storageGetUsage = async ({range,parseOutput = true, overrideForCli = false if (parseOutput) { parse(response) - success() } return response; @@ -829,7 +815,6 @@ const storageGetBucketUsage = async ({bucketId,range,parseOutput = true, overrid showConsoleLink('storage', 'getBucketUsage', bucketId); } else { parse(response) - success() } } diff --git a/lib/commands/teams.js b/lib/commands/teams.js index 7ca5474..dda741a 100644 --- a/lib/commands/teams.js +++ b/lib/commands/teams.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const teams = new Command("teams").description(commandDescriptions['teams']).configureHelp({ +const teams = new Command("teams").description(commandDescriptions['teams'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const teamsList = async ({queries,search,parseOutput = true, overrideForCli = fa showConsoleLink('teams', 'list'); } else { parse(response) - success() } } @@ -119,7 +118,6 @@ const teamsCreate = async ({teamId,name,roles,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -154,7 +152,6 @@ const teamsGet = async ({teamId,parseOutput = true, overrideForCli = false, sdk showConsoleLink('teams', 'get', teamId); } else { parse(response) - success() } } @@ -191,7 +188,6 @@ const teamsUpdateName = async ({teamId,name,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -223,7 +219,6 @@ const teamsDelete = async ({teamId,parseOutput = true, overrideForCli = false, s if (parseOutput) { parse(response) - success() } return response; @@ -259,7 +254,6 @@ const teamsListLogs = async ({teamId,queries,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -299,7 +293,6 @@ const teamsListMemberships = async ({teamId,queries,search,parseOutput = true, o if (parseOutput) { parse(response) - success() } return response; @@ -356,7 +349,6 @@ const teamsCreateMembership = async ({teamId,roles,email,userId,phone,url,name,p if (parseOutput) { parse(response) - success() } return response; @@ -389,7 +381,6 @@ const teamsGetMembership = async ({teamId,membershipId,parseOutput = true, overr if (parseOutput) { parse(response) - success() } return response; @@ -427,7 +418,6 @@ const teamsUpdateMembership = async ({teamId,membershipId,roles,parseOutput = tr if (parseOutput) { parse(response) - success() } return response; @@ -460,7 +450,6 @@ const teamsDeleteMembership = async ({teamId,membershipId,parseOutput = true, ov if (parseOutput) { parse(response) - success() } return response; @@ -501,7 +490,6 @@ const teamsUpdateMembershipStatus = async ({teamId,membershipId,userId,secret,pa if (parseOutput) { parse(response) - success() } return response; @@ -533,7 +521,6 @@ const teamsGetPrefs = async ({teamId,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -569,7 +556,6 @@ const teamsUpdatePrefs = async ({teamId,prefs,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/users.js b/lib/commands/users.js index 9d13ed7..1de7a59 100644 --- a/lib/commands/users.js +++ b/lib/commands/users.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const users = new Command("users").description(commandDescriptions['users']).configureHelp({ +const users = new Command("users").description(commandDescriptions['users'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -74,7 +74,6 @@ const usersList = async ({queries,search,parseOutput = true, overrideForCli = fa showConsoleLink('users', 'list'); } else { parse(response) - success() } } @@ -126,7 +125,6 @@ const usersCreate = async ({userId,email,phone,password,name,parseOutput = true, if (parseOutput) { parse(response) - success() } return response; @@ -173,7 +171,6 @@ const usersCreateArgon2User = async ({userId,email,password,name,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -220,7 +217,6 @@ const usersCreateBcryptUser = async ({userId,email,password,name,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -259,7 +255,6 @@ const usersListIdentities = async ({queries,search,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -291,7 +286,6 @@ const usersDeleteIdentity = async ({identityId,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -338,7 +332,6 @@ const usersCreateMD5User = async ({userId,email,password,name,parseOutput = true if (parseOutput) { parse(response) - success() } return response; @@ -385,7 +378,6 @@ const usersCreatePHPassUser = async ({userId,email,password,name,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -452,7 +444,6 @@ const usersCreateScryptUser = async ({userId,email,password,passwordSalt,passwor if (parseOutput) { parse(response) - success() } return response; @@ -511,7 +502,6 @@ const usersCreateScryptModifiedUser = async ({userId,email,password,passwordSalt if (parseOutput) { parse(response) - success() } return response; @@ -562,7 +552,6 @@ const usersCreateSHAUser = async ({userId,email,password,passwordVersion,name,pa if (parseOutput) { parse(response) - success() } return response; @@ -597,7 +586,6 @@ const usersGetUsage = async ({range,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -632,7 +620,6 @@ const usersGet = async ({userId,parseOutput = true, overrideForCli = false, sdk showConsoleLink('users', 'get', userId); } else { parse(response) - success() } } @@ -665,7 +652,6 @@ const usersDelete = async ({userId,parseOutput = true, overrideForCli = false, s if (parseOutput) { parse(response) - success() } return response; @@ -701,7 +687,6 @@ const usersUpdateEmail = async ({userId,email,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -741,7 +726,6 @@ const usersCreateJWT = async ({userId,sessionId,duration,parseOutput = true, ove if (parseOutput) { parse(response) - success() } return response; @@ -778,7 +762,6 @@ const usersUpdateLabels = async ({userId,labels,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -814,7 +797,6 @@ const usersListLogs = async ({userId,queries,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -846,7 +828,6 @@ const usersListMemberships = async ({userId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -882,7 +863,6 @@ const usersUpdateMfa = async ({userId,mfa,parseOutput = true, overrideForCli = f if (parseOutput) { parse(response) - success() } return response; @@ -915,7 +895,6 @@ const usersDeleteMfaAuthenticator = async ({userId,type,parseOutput = true, over if (parseOutput) { parse(response) - success() } return response; @@ -947,7 +926,6 @@ const usersListMfaFactors = async ({userId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -979,7 +957,6 @@ const usersGetMfaRecoveryCodes = async ({userId,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -1011,7 +988,6 @@ const usersUpdateMfaRecoveryCodes = async ({userId,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -1043,7 +1019,6 @@ const usersCreateMfaRecoveryCodes = async ({userId,parseOutput = true, overrideF if (parseOutput) { parse(response) - success() } return response; @@ -1079,7 +1054,6 @@ const usersUpdateName = async ({userId,name,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -1115,7 +1089,6 @@ const usersUpdatePassword = async ({userId,password,parseOutput = true, override if (parseOutput) { parse(response) - success() } return response; @@ -1151,7 +1124,6 @@ const usersUpdatePhone = async ({userId,number,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -1183,7 +1155,6 @@ const usersGetPrefs = async ({userId,parseOutput = true, overrideForCli = false, if (parseOutput) { parse(response) - success() } return response; @@ -1219,7 +1190,6 @@ const usersUpdatePrefs = async ({userId,prefs,parseOutput = true, overrideForCli if (parseOutput) { parse(response) - success() } return response; @@ -1254,7 +1224,6 @@ const usersListSessions = async ({userId,parseOutput = true, overrideForCli = fa showConsoleLink('users', 'listSessions', userId); } else { parse(response) - success() } } @@ -1287,7 +1256,6 @@ const usersCreateSession = async ({userId,parseOutput = true, overrideForCli = f if (parseOutput) { parse(response) - success() } return response; @@ -1319,7 +1287,6 @@ const usersDeleteSessions = async ({userId,parseOutput = true, overrideForCli = if (parseOutput) { parse(response) - success() } return response; @@ -1352,7 +1319,6 @@ const usersDeleteSession = async ({userId,sessionId,parseOutput = true, override if (parseOutput) { parse(response) - success() } return response; @@ -1388,7 +1354,6 @@ const usersUpdateStatus = async ({userId,status,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -1424,7 +1389,6 @@ const usersListTargets = async ({userId,queries,parseOutput = true, overrideForC if (parseOutput) { parse(response) - success() } return response; @@ -1476,7 +1440,6 @@ const usersCreateTarget = async ({userId,targetId,providerType,identifier,provid if (parseOutput) { parse(response) - success() } return response; @@ -1509,7 +1472,6 @@ const usersGetTarget = async ({userId,targetId,parseOutput = true, overrideForCl if (parseOutput) { parse(response) - success() } return response; @@ -1554,7 +1516,6 @@ const usersUpdateTarget = async ({userId,targetId,identifier,providerId,name,par if (parseOutput) { parse(response) - success() } return response; @@ -1587,7 +1548,6 @@ const usersDeleteTarget = async ({userId,targetId,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -1627,7 +1587,6 @@ const usersCreateToken = async ({userId,length,expire,parseOutput = true, overri if (parseOutput) { parse(response) - success() } return response; @@ -1663,7 +1622,6 @@ const usersUpdateEmailVerification = async ({userId,emailVerification,parseOutpu if (parseOutput) { parse(response) - success() } return response; @@ -1699,7 +1657,6 @@ const usersUpdatePhoneVerification = async ({userId,phoneVerification,parseOutpu if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/commands/vcs.js b/lib/commands/vcs.js index f548870..a903cae 100644 --- a/lib/commands/vcs.js +++ b/lib/commands/vcs.js @@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) { }); } -const vcs = new Command("vcs").description(commandDescriptions['vcs']).configureHelp({ +const vcs = new Command("vcs").description(commandDescriptions['vcs'] ?? '').configureHelp({ helpWidth: process.stdout.columns || 80 }) @@ -68,7 +68,6 @@ const vcsListRepositories = async ({installationId,search,parseOutput = true, ov if (parseOutput) { parse(response) - success() } return response; @@ -108,7 +107,6 @@ const vcsCreateRepository = async ({installationId,name,xprivate,parseOutput = t if (parseOutput) { parse(response) - success() } return response; @@ -141,7 +139,6 @@ const vcsGetRepository = async ({installationId,providerRepositoryId,parseOutput if (parseOutput) { parse(response) - success() } return response; @@ -174,7 +171,6 @@ const vcsListRepositoryBranches = async ({installationId,providerRepositoryId,pa if (parseOutput) { parse(response) - success() } return response; @@ -211,7 +207,6 @@ const vcsGetRepositoryContents = async ({installationId,providerRepositoryId,pro if (parseOutput) { parse(response) - success() } return response; @@ -248,7 +243,6 @@ const vcsCreateRepositoryDetection = async ({installationId,providerRepositoryId if (parseOutput) { parse(response) - success() } return response; @@ -285,7 +279,6 @@ const vcsUpdateExternalDeployments = async ({installationId,repositoryId,provide if (parseOutput) { parse(response) - success() } return response; @@ -324,7 +317,6 @@ const vcsListInstallations = async ({queries,search,parseOutput = true, override if (parseOutput) { parse(response) - success() } return response; @@ -356,7 +348,6 @@ const vcsGetInstallation = async ({installationId,parseOutput = true, overrideFo if (parseOutput) { parse(response) - success() } return response; @@ -388,7 +379,6 @@ const vcsDeleteInstallation = async ({installationId,parseOutput = true, overrid if (parseOutput) { parse(response) - success() } return response; diff --git a/lib/config.js b/lib/config.js index 18ed09e..49f70df 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,7 +4,8 @@ const _path = require("path"); const process = require("process"); const JSONbig = require("json-bigint")({ storeAsString: false }); -const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"]); +const KeysVars = new Set(["key", "value"]); +const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands", "vars"]); const KeysDatabase = new Set(["$id", "name", "enabled"]); const KeysCollection = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]); const KeysStorage = new Set(["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]); @@ -38,10 +39,10 @@ const KeysAttributes = new Set([ const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]); function whitelistKeys(value, keys, nestedKeys = {}) { - if(Array.isArray(value)) { + if (Array.isArray(value)) { const newValue = []; - for(const item of value) { + for (const item of value) { newValue.push(whitelistKeys(item, keys, nestedKeys)); } @@ -50,8 +51,8 @@ function whitelistKeys(value, keys, nestedKeys = {}) { const newValue = {}; Object.keys(value).forEach((key) => { - if(keys.has(key)) { - if(nestedKeys[key]) { + if (keys.has(key)) { + if (nestedKeys[key]) { newValue[key] = whitelistKeys(value[key], nestedKeys[key]); } else { newValue[key] = value[key]; @@ -151,7 +152,9 @@ class Local extends Config { } addFunction(props) { - props = whitelistKeys(props, KeysFunction); + props = whitelistKeys(props, KeysFunction, { + vars: KeysVars + }); if (!this.has("functions")) { this.set("functions", []); @@ -403,7 +406,7 @@ class Local extends Config { return; } - this.set('settings', this.createSettingsObject(settings)); + this.set('settings', this.createSettingsObject(projectSettings)); } createSettingsObject(projectSettings) { @@ -615,5 +618,6 @@ module.exports = { KeysTopics, KeysStorage, KeysTeams, + KeysCollection, whitelistKeys }; diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js index 179d905..41e39f5 100644 --- a/lib/emulation/docker.js +++ b/lib/emulation/docker.js @@ -79,7 +79,6 @@ async function dockerBuild(func, variables) { const params = [ 'run' ]; params.push('--name', id); params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`); - params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`); @@ -169,7 +168,6 @@ async function dockerStart(func, variables, port) { params.push('--rm'); params.push('--name', id); params.push('-p', `${port}:3000`); - params.push('-e', 'APPWRITE_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_ENV=development'); params.push('-e', 'OPEN_RUNTIMES_SECRET='); @@ -254,7 +252,7 @@ function waitUntilPortOpen(port, iteration = 0) { }); client.connect({port, host: '127.0.0.1'}, function() {}); - }); + }); } module.exports = { diff --git a/lib/paginate.js b/lib/paginate.js index c78814a..1d511e5 100644 --- a/lib/paginate.js +++ b/lib/paginate.js @@ -1,14 +1,16 @@ -const paginate = async (action, args = {}, limit = 100, wrapper = '') => { +const paginate = async (action, args = {}, limit = 100, wrapper = '', queries = []) => { let pageNumber = 0; let results = []; let total = 0; while (true) { const offset = pageNumber * limit; + // Merge the limit and offset into the args const response = await action({ ...args, queries: [ + ...queries, JSON.stringify({ method: 'limit', values: [limit] }), JSON.stringify({ method: 'offset', values: [offset] }) ] diff --git a/lib/parser.js b/lib/parser.js index c32fdf6..8a459bd 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.6'; + const version = '6.0.0-rc.7'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; @@ -203,29 +203,26 @@ const commandDescriptions = { "account": `The account command allows you to authenticate and manage a user account.`, "graphql": `The graphql command allows you to query and mutate any resource type on your Appwrite server.`, "avatars": `The avatars command aims to help you complete everyday tasks related to your app image, icons, and avatars.`, - "databases": `The databases command allows you to create structured collections of documents, query and filter lists of documents.`, - "init": `The init command provides a convenient wrapper for creating and initializing project, functions, collections, buckets, teams and messaging in Appwrite.`, - "push": `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams and messaging.`, - "run": `The run command allows you to run project locally to allow easy development and quick debugging.`, - "functions": `The functions command allows you view, create and manage your Cloud Functions.`, + "databases": `The databases command allows you to create structured collections of documents and query and filter lists of documents.`, + "init": `The init command provides a convenient wrapper for creating and initializing projects, functions, collections, buckets, teams, and messaging-topics in Appwrite.`, + "push": `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams, and messaging-topics.`, + "run": `The run command allows you to run the project locally to allow easy development and quick debugging.`, + "functions": `The functions command allows you to view, create, and manage your Cloud Functions.`, "health": `The health command allows you to both validate and monitor your Appwrite server's health.`, - "pull": `The pull command helps you pull your Appwrite project, functions, collections, buckets, teams and messaging`, + "pull": `The pull command helps you pull your Appwrite project, functions, collections, buckets, teams, and messaging-topics`, "locale": `The locale command allows you to customize your app based on your users' location.`, - "projects": `The projects command allows you to view, create and manage your Appwrite projects.`, "storage": `The storage command allows you to manage your project files.`, - "teams": `The teams command allows you to group users of your project and to enable them to share read and write access to your project resources`, + "teams": `The teams command allows you to group users of your project to enable them to share read and write access to your project resources.`, "users": `The users command allows you to manage your project users.`, "client": `The client command allows you to configure your CLI`, "login": `The login command allows you to authenticate and manage a user account.`, - "logout": `The logout command allows you to logout of your Appwrite account.`, - "whoami": `The whoami command gives information about the currently signed in user.`, + "logout": `The logout command allows you to log out of your Appwrite account.`, + "whoami": `The whomai command gives information about the currently logged-in user.`, "register": `Outputs the link to create an Appwrite account.`, - "console" : `The console command allows gives you access to the APIs used by the Appwrite console.`, + "console" : `The console command gives you access to the APIs used by the Appwrite Console.`, "assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`, - "messaging": `The messaging command allows you to send messages.`, + "messaging": `The messaging command allows you to manage topics and targets and send messages.`, "migrations": `The migrations command allows you to migrate data between services.`, - "project": `The project command is for overall project administration.`, - "proxy": `The proxy command allows you to configure behavior for your attached domains.`, "vcs": `The vcs command allows you to interact with VCS providers and manage your code repositories.`, "main": chalk.redBright(`${logo}${description}`), } diff --git a/lib/questions.js b/lib/questions.js index d5fdc29..ce5c306 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -189,11 +189,11 @@ const questionsInitProject = [ message: "Choose your Appwrite project.", choices: async (answers) => { const queries = [ - JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization.id] }), - JSON.stringify({ method: 'orderDesc', attribute: 'Id' }) + JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization] }), + JSON.stringify({ method: 'orderDesc', attribute: '$id' }) ] - const { projects } = await paginate(projectsList, { parseOutput: false, queries, }, 100, 'projects'); + const { projects } = await paginate(projectsList, { parseOutput: false }, 100, 'projects', queries); let choices = projects.map((project) => { return { @@ -301,22 +301,7 @@ const questionsCreateFunction = [ }) return choices; }, - }, - { - type: "list", - name: "template", - message: "How would you like to start your function code?", - choices: [ - { - name: `Start from scratch ${chalk.blackBright(`(starter)`)}`, - value: "starter" - }, - { - name: "Pick a template", - value: "custom" - } - ] - }, + } ]; const questionsCreateFunctionSelectTemplate = (templates) => { @@ -646,11 +631,6 @@ const questionsPushFunctions = [ return choices; } }, - { - type: "input", - name: "override", - message: 'Are you sure you want to override this function\'s variables? This can lead to loss of secrets! Type "YES" to confirm.' - }, ] const questionsPushCollections = [ @@ -678,7 +658,15 @@ const questionPushChanges = [ { type: "input", name: "changes", - message: `Would you like to apply these changes? Type "YES" to confirm.` + message: `Are you sure you want to apply these changes? (YES/NO)` + } +]; + +const questionPushChangesConfirmation = [ + { + type: "input", + name: "changes", + message: `Please type 'YES' or 'NO':` } ]; @@ -708,6 +696,7 @@ const questionsPushMessagingTopics = [ type: "checkbox", name: "topics", message: "Which messaging topic would you like to push?", + validate: (value) => validateRequired('topics', value), when: () => localConfig.getMessagingTopics().length > 0, choices: () => { let topics = localConfig.getMessagingTopics(); @@ -719,11 +708,6 @@ const questionsPushMessagingTopics = [ } }); } - }, - { - type: "input", - name: "override", - message: 'Would you like to override existing topics? This can lead to loss of data! Type "YES" to confirm.' } ] @@ -862,5 +846,6 @@ module.exports = { questionGetEndpoint, questionsInitResources, questionsCreateTeam, - questionPushChanges + questionPushChanges, + questionPushChangesConfirmation }; diff --git a/package.json b/package.json index 5b6e155..3ca648f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.6", + "version": "6.0.0-rc.7", "license": "BSD-3-Clause", "main": "index.js", "bin": { @@ -35,7 +35,7 @@ "ignore": "^5.2.0", "chokidar": "^3.6.0", "tail": "^2.2.6", - "dotenv": "^16.3.1" + "dotenv": "^16.4.5" }, "devDependencies": { "pkg": "5.8.1" diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 841122f..79b2b78 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.6", + "version": "6.0.0-rc.7", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.6/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From b4e724d42ea9815b1c6cc7f91b2c58c2bab3ffef Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Sat, 17 Aug 2024 08:49:11 +0000 Subject: [PATCH 12/18] chore: release rc --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/commands/functions.js | 33 +++++++++++---------------------- lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 8 files changed, 23 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 8c1f9d6..1d7c7f5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.7 +6.0.0-rc.8 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.7 +6.0.0-rc.8 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index e251235..53112c9 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index e6a452b..89c37a3 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.7" + GITHUB_LATEST_VERSION="6.0.0-rc.8" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 87b7329..6d0865d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.7', - 'user-agent' : `AppwriteCLI/6.0.0-rc.7 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.8', + 'user-agent' : `AppwriteCLI/6.0.0-rc.8 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/commands/functions.js b/lib/commands/functions.js index f44b979..7ff07b2 100644 --- a/lib/commands/functions.js +++ b/lib/commands/functions.js @@ -103,7 +103,7 @@ const functionsList = async ({queries,search,parseOutput = true, overrideForCli * @property {string} templateRepository Repository name of the template. * @property {string} templateOwner The name of the owner of the template. * @property {string} templateRootDirectory Path to function code in the template repo. - * @property {string} templateBranch Production branch for the repo linked to the function template. + * @property {string} templateVersion Version (tag) for the repo linked to the function template. * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk @@ -112,7 +112,7 @@ const functionsList = async ({queries,search,parseOutput = true, overrideForCli /** * @param {FunctionsCreateRequestParams} params */ -const functionsCreate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,templateRepository,templateOwner,templateRootDirectory,templateBranch,parseOutput = true, overrideForCli = false, sdk = undefined}) => { +const functionsCreate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,templateRepository,templateOwner,templateRootDirectory,templateVersion,parseOutput = true, overrideForCli = false, sdk = undefined}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions'; @@ -180,8 +180,8 @@ const functionsCreate = async ({functionId,name,runtime,execute,events,schedule, if (typeof templateRootDirectory !== 'undefined') { payload['templateRootDirectory'] = templateRootDirectory; } - if (typeof templateBranch !== 'undefined') { - payload['templateBranch'] = templateBranch; + if (typeof templateVersion !== 'undefined') { + payload['templateVersion'] = templateVersion; } let response = undefined; @@ -514,7 +514,7 @@ const functionsDelete = async ({functionId,parseOutput = true, overrideForCli = /** * @typedef {Object} FunctionsListDeploymentsRequestParams * @property {string} functionId Function ID. - * @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: size, buildId, activate, entrypoint, commands + * @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: size, buildId, activate, entrypoint, commands, type, size * @property {string} search Search term to filter your list results. Max length: 256 chars. * @property {boolean} overrideForCli * @property {boolean} parseOutput @@ -985,16 +985,17 @@ const functionsListExecutions = async ({functionId,queries,search,parseOutput = * @property {string} xpath HTTP path of execution. Path can include query params. Default value is / * @property {ExecutionMethod} method HTTP method of execution. Default value is GET. * @property {object} headers HTTP headers of execution. Defaults to empty. - * @property {string} scheduledAt Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + * @property {string} scheduledAt Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future with precision in minutes. * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk + * @property {CallableFunction} onProgress */ /** * @param {FunctionsCreateExecutionRequestParams} params */ -const functionsCreateExecution = async ({functionId,body,async,xpath,method,headers,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { +const functionsCreateExecution = async ({functionId,body,async,xpath,method,headers,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined,onProgress = () => {}}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); @@ -1018,18 +1019,6 @@ const functionsCreateExecution = async ({functionId,body,async,xpath,method,head payload['scheduledAt'] = scheduledAt; } - let response = undefined; - - response = await client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); - - if (parseOutput) { - parse(response) - } - - return response; - } /** @@ -1344,7 +1333,7 @@ functions .option(`--template-repository <template-repository>`, `Repository name of the template.`) .option(`--template-owner <template-owner>`, `The name of the owner of the template.`) .option(`--template-root-directory <template-root-directory>`, `Path to function code in the template repo.`) - .option(`--template-branch <template-branch>`, `Production branch for the repo linked to the function template.`) + .option(`--template-version <template-version>`, `Version (tag) for the repo linked to the function template.`) .action(actionRunner(functionsCreate)) functions @@ -1414,7 +1403,7 @@ functions .command(`list-deployments`) .description(`Get a list of all the project's code deployments. You can use the query params to filter your results.`) .requiredOption(`--function-id <function-id>`, `Function ID.`) - .option(`--queries [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: size, buildId, activate, entrypoint, commands`) + .option(`--queries [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: size, buildId, activate, entrypoint, commands, type, size`) .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`) .option(`--console`, `Get the resource console url`) .action(actionRunner(functionsListDeployments)) @@ -1493,7 +1482,7 @@ functions .option(`--xpath <xpath>`, `HTTP path of execution. Path can include query params. Default value is /`) .option(`--method <method>`, `HTTP method of execution. Default value is GET.`) .option(`--headers <headers>`, `HTTP headers of execution. Defaults to empty.`) - .option(`--scheduled-at <scheduled-at>`, `Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.`) + .option(`--scheduled-at <scheduled-at>`, `Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future with precision in minutes.`) .action(actionRunner(functionsCreateExecution)) functions diff --git a/lib/parser.js b/lib/parser.js index 8a459bd..b14ff0b 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.7'; + const version = '6.0.0-rc.8'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index 3ca648f..48a9982 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.7", + "version": "6.0.0-rc.8", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 79b2b78..f8d93c7 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.7", + "version": "6.0.0-rc.8", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.7/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From 1494f7765f95624cd4ca64d644e2f984f64e5748 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Mon, 19 Aug 2024 09:45:46 +0000 Subject: [PATCH 13/18] chore: update RC version --- lib/commands/init.js | 11 +++++++---- lib/commands/pull.js | 14 ++++++++------ lib/commands/push.js | 21 ++++++++++++++------- lib/config.js | 18 +++++++++++++++++- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index 4f2b6a3..8d291e7 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -192,6 +192,8 @@ const initTopic = async () => { }; const initFunction = async () => { + process.chdir(localConfig.configDirectoryPath) + // TODO: Add CI/CD support (ID, name, runtime) const answers = await inquirer.prompt(questionsCreateFunction) const functionFolder = path.join(process.cwd(), 'functions'); @@ -203,12 +205,13 @@ const initFunction = async () => { } const functionId = answers.id === 'unique()' ? ID.unique() : answers.id; - const functionDir = path.join(functionFolder, functionId); + const functionName = answers.name; + const functionDir = path.join(functionFolder, functionName); const templatesDir = path.join(functionFolder, `${functionId}-templates`); const runtimeDir = path.join(templatesDir, answers.runtime.name); if (fs.existsSync(functionDir)) { - throw new Error(`( ${functionId} ) already exists in the current directory. Please choose another name.`); + throw new Error(`( ${functionName} ) already exists in the current directory. Please choose another name.`); } if (!answers.runtime.entrypoint) { @@ -285,7 +288,7 @@ const initFunction = async () => { fs.rmSync(templatesDir, { recursive: true, force: true }); - const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md'); + const readmePath = path.join(process.cwd(), 'functions', functionName, 'README.md'); const readmeFile = fs.readFileSync(readmePath).toString(); const newReadmeFile = readmeFile.split('\n'); newReadmeFile[0] = `# ${answers.name}`; @@ -306,7 +309,7 @@ const initFunction = async () => { entrypoint: answers.runtime.entrypoint || '', commands: answers.runtime.commands || '', ignore: answers.runtime.ignore || null, - path: `functions/${functionId}`, + path: `functions/${functionName}`, }; localConfig.addFunction(data); diff --git a/lib/commands/pull.js b/lib/commands/pull.js index ba9d405..0c4fc92 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -57,6 +57,8 @@ const pullSettings = async () => { } const pullFunctions = async ({ code, withVariables }) => { + process.chdir(localConfig.configDirectoryPath) + log("Fetching functions ..."); let total = 0; @@ -84,7 +86,7 @@ const pullFunctions = async ({ code, withVariables }) => { func['path'] = localFunction['path']; if (!localFunction['path']) { - func['path'] = `functions/${func.$id}`; + func['path'] = `functions/${func.name}`; } if (!withVariables) { delete func['vars']; @@ -314,7 +316,7 @@ pull pull .command("function") .alias("functions") - .description("Pulling your Appwrite cloud function") + .description("Pull your Appwrite cloud function") .option("--no-code", "Don't pull the function's code") .option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`) .action(actionRunner(pullFunctions)) @@ -322,25 +324,25 @@ pull pull .command("collection") .alias("collections") - .description("Pulling your Appwrite collections") + .description("Pull your Appwrite collections") .action(actionRunner(pullCollection)) pull .command("bucket") .alias("buckets") - .description("Pulling your Appwrite buckets") + .description("Pull your Appwrite buckets") .action(actionRunner(pullBucket)) pull .command("team") .alias("teams") - .description("Pulling your Appwrite teams") + .description("Pull your Appwrite teams") .action(actionRunner(pullTeam)) pull .command("topic") .alias("topics") - .description("Initialise your Appwrite messaging topics") + .description("Pull your Appwrite messaging topics") .action(actionRunner(pullMessagingTopic)) module.exports = { diff --git a/lib/commands/push.js b/lib/commands/push.js index d265cfa..ef3f93a 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -368,6 +368,7 @@ const getConfirmation = async () => { return false; }; +const isEmpty = (value) => (value === null || value === undefined || (typeof value === "string" && value.trim().length === 0) || (Array.isArray(value) && value.length === 0)); const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = '', secondResourceName = '') => { log('Checking for changes ...'); @@ -390,6 +391,11 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, if (skipKeys.includes(key)) { continue; } + + if (isEmpty(value) && isEmpty(localResource[key])) { + continue; + } + if (Array.isArray(value) && Array.isArray(localResource[key])) { if (JSON.stringify(value) !== JSON.stringify(localResource[key])) { changes.push({ @@ -697,6 +703,10 @@ const deleteAttribute = async (collection, attribute, isIndex = false) => { } const compareAttribute = (remote, local, reason, key) => { + if (isEmpty(remote) && isEmpty(local)) { + return reason; + } + if (Array.isArray(remote) && Array.isArray(local)) { if (JSON.stringify(remote) !== JSON.stringify(local)) { const bol = reason === '' ? '' : '\n'; @@ -993,6 +1003,8 @@ const pushSettings = async () => { } const pushFunction = async ({ functionId, async, code, withVariables } = { returnOnZero: false }) => { + process.chdir(localConfig.configDirectoryPath) + const functionIds = []; if (functionId) { @@ -1088,11 +1100,6 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur entrypoint: func.entrypoint, commands: func.commands, scopes: func.scopes, - providerRepositoryId: func.providerRepositoryId ?? "", - installationId: func.installationId ?? '', - providerBranch: func.providerBranch ?? '', - providerRootDirectory: func.providerRootDirectory ?? '', - providerSilentMode: func.providerSilentMode ?? false, vars: JSON.stringify(response.vars), parseOutput: false }); @@ -1710,9 +1717,9 @@ push .action(actionRunner(pushMessagingTopic)); const deploy = new Command("deploy") - .description(commandDescriptions['push']) + .description('Removed. Use appwrite push instead') .action(actionRunner(async () => { - warn("Did you mean to run 'appwrite push' command?"); + warn("appwrite deploy has been removed. Please use 'appwrite push' instead"); })); module.exports = { diff --git a/lib/config.js b/lib/config.js index 49f70df..063ea06 100644 --- a/lib/config.js +++ b/lib/config.js @@ -123,10 +123,26 @@ class Config { class Local extends Config { static CONFIG_FILE_PATH = "appwrite.json"; + configDirectoryPath = "" constructor(path = Local.CONFIG_FILE_PATH) { - let absolutePath = `${process.cwd()}/${path}`; + let currentPath = process.cwd(); + let absolutePath = `${currentPath}/${path}`; + + while (true) { + if (fs.existsSync(`${currentPath}/${path}`)) { + absolutePath = `${currentPath}/${path}`; + break + } else { + const parentDirectory = _path.dirname(currentPath); + if (parentDirectory === currentPath) { // we hit the top directory + break; + } + currentPath = parentDirectory + } + } super(absolutePath); + this.configDirectoryPath =_path.dirname(absolutePath); } getFunctions() { From 8d835d707414e31211707ef96fe7451f64d4ab40 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Tue, 20 Aug 2024 11:02:36 +0000 Subject: [PATCH 14/18] chore: update SDKs to new RC version --- docs/examples/functions/create.md | 1 + .../examples/functions/list-specifications.md | 1 + docs/examples/functions/update.md | 1 + lib/commands/functions.js | 70 +++++++++++++++++-- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 docs/examples/functions/list-specifications.md diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index c75658e..8b83c0e 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -20,3 +20,4 @@ appwrite functions create \ + diff --git a/docs/examples/functions/list-specifications.md b/docs/examples/functions/list-specifications.md new file mode 100644 index 0000000..1d64bc6 --- /dev/null +++ b/docs/examples/functions/list-specifications.md @@ -0,0 +1 @@ +appwrite functions listSpecifications diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 8bad859..7ac63e0 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -16,3 +16,4 @@ appwrite functions update \ + diff --git a/lib/commands/functions.js b/lib/commands/functions.js index 7ff07b2..a5b9a7f 100644 --- a/lib/commands/functions.js +++ b/lib/commands/functions.js @@ -104,6 +104,7 @@ const functionsList = async ({queries,search,parseOutput = true, overrideForCli * @property {string} templateOwner The name of the owner of the template. * @property {string} templateRootDirectory Path to function code in the template repo. * @property {string} templateVersion Version (tag) for the repo linked to the function template. + * @property {string} specification Runtime specification for the function and builds. * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk @@ -112,7 +113,7 @@ const functionsList = async ({queries,search,parseOutput = true, overrideForCli /** * @param {FunctionsCreateRequestParams} params */ -const functionsCreate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,templateRepository,templateOwner,templateRootDirectory,templateVersion,parseOutput = true, overrideForCli = false, sdk = undefined}) => { +const functionsCreate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,templateRepository,templateOwner,templateRootDirectory,templateVersion,specification,parseOutput = true, overrideForCli = false, sdk = undefined}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions'; @@ -183,6 +184,9 @@ const functionsCreate = async ({functionId,name,runtime,execute,events,schedule, if (typeof templateVersion !== 'undefined') { payload['templateVersion'] = templateVersion; } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; + } let response = undefined; @@ -228,6 +232,40 @@ const functionsListRuntimes = async ({parseOutput = true, overrideForCli = false } +/** + * @typedef {Object} FunctionsListSpecificationsRequestParams + * @property {boolean} overrideForCli + * @property {boolean} parseOutput + * @property {libClient | undefined} sdk + */ + +/** + * @param {FunctionsListSpecificationsRequestParams} params + */ +const functionsListSpecifications = async ({parseOutput = true, overrideForCli = false, sdk = undefined, console}) => { + let client = !sdk ? await sdkForProject() : + sdk; + let apiPath = '/functions/specifications'; + let payload = {}; + + let response = undefined; + + response = await client.call('get', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + if(console) { + showConsoleLink('functions', 'listSpecifications'); + } else { + parse(response) + } + } + + return response; + +} + /** * @typedef {Object} FunctionsListTemplatesRequestParams * @property {string[]} runtimes List of runtimes allowed for filtering function templates. Maximum of 100 runtimes are allowed. @@ -401,6 +439,7 @@ const functionsGet = async ({functionId,parseOutput = true, overrideForCli = fal * @property {string} providerBranch Production branch for the repo linked to the function * @property {boolean} providerSilentMode Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @property {string} providerRootDirectory Path to function code in the linked repo. + * @property {string} specification Runtime specification for the function and builds. * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk @@ -409,7 +448,7 @@ const functionsGet = async ({functionId,parseOutput = true, overrideForCli = fal /** * @param {FunctionsUpdateRequestParams} params */ -const functionsUpdate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => { +const functionsUpdate = async ({functionId,name,runtime,execute,events,schedule,timeout,enabled,logging,entrypoint,commands,scopes,installationId,providerRepositoryId,providerBranch,providerSilentMode,providerRootDirectory,specification,parseOutput = true, overrideForCli = false, sdk = undefined}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); @@ -465,6 +504,9 @@ const functionsUpdate = async ({functionId,name,runtime,execute,events,schedule, if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; + } let response = undefined; @@ -989,13 +1031,12 @@ const functionsListExecutions = async ({functionId,queries,search,parseOutput = * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk - * @property {CallableFunction} onProgress */ /** * @param {FunctionsCreateExecutionRequestParams} params */ -const functionsCreateExecution = async ({functionId,body,async,xpath,method,headers,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined,onProgress = () => {}}) => { +const functionsCreateExecution = async ({functionId,body,async,xpath,method,headers,scheduledAt,parseOutput = true, overrideForCli = false, sdk = undefined}) => { let client = !sdk ? await sdkForProject() : sdk; let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); @@ -1019,6 +1060,18 @@ const functionsCreateExecution = async ({functionId,body,async,xpath,method,head payload['scheduledAt'] = scheduledAt; } + let response = undefined; + + response = await client.call('post', apiPath, { + 'content-type': 'application/json', + }, payload); + + if (parseOutput) { + parse(response) + } + + return response; + } /** @@ -1334,6 +1387,7 @@ functions .option(`--template-owner <template-owner>`, `The name of the owner of the template.`) .option(`--template-root-directory <template-root-directory>`, `Path to function code in the template repo.`) .option(`--template-version <template-version>`, `Version (tag) for the repo linked to the function template.`) + .option(`--specification <specification>`, `Runtime specification for the function and builds.`) .action(actionRunner(functionsCreate)) functions @@ -1341,6 +1395,12 @@ functions .description(`Get a list of all runtimes that are currently active on your instance.`) .action(actionRunner(functionsListRuntimes)) +functions + .command(`list-specifications`) + .description(`List allowed function specifications for this instance. `) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsListSpecifications)) + functions .command(`list-templates`) .description(`List available function templates. You can use template details in [createFunction](/docs/references/cloud/server-nodejs/functions#create) method.`) @@ -1391,6 +1451,7 @@ functions .option(`--provider-branch <provider-branch>`, `Production branch for the repo linked to the function`) .option(`--provider-silent-mode <provider-silent-mode>`, `Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.`, parseBool) .option(`--provider-root-directory <provider-root-directory>`, `Path to function code in the linked repo.`) + .option(`--specification <specification>`, `Runtime specification for the function and builds.`) .action(actionRunner(functionsUpdate)) functions @@ -1550,6 +1611,7 @@ module.exports = { functionsList, functionsCreate, functionsListRuntimes, + functionsListSpecifications, functionsListTemplates, functionsGetTemplate, functionsGetUsage, From 2aba229616d56b5113e589fbbadd6b923114aab5 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Fri, 23 Aug 2024 10:49:31 +0000 Subject: [PATCH 15/18] chore: updates for next rc release --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1d7c7f5..530ff28 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.8 +6.0.0-rc.9 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.8 +6.0.0-rc.9 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index 53112c9..d10afd5 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 89c37a3..eba478f 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.8" + GITHUB_LATEST_VERSION="6.0.0-rc.9" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 6d0865d..445af03 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.8', - 'user-agent' : `AppwriteCLI/6.0.0-rc.8 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.9', + 'user-agent' : `AppwriteCLI/6.0.0-rc.9 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/parser.js b/lib/parser.js index b14ff0b..08920d7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.8'; + const version = '6.0.0-rc.9'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index 48a9982..70d0a6d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.8", + "version": "6.0.0-rc.9", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index f8d93c7..3e59707 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.8", + "version": "6.0.0-rc.9", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.8/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From a4d3d2610cecc0b095f14c845f4074676554e116 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Fri, 23 Aug 2024 15:26:18 +0000 Subject: [PATCH 16/18] chore: update SDKs for appwrite 1.6.0 --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/commands/generic.js | 3 ++- lib/commands/init.js | 4 ++-- lib/parser.js | 2 +- lib/questions.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 530ff28..f3c09bd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.9 +6.0.0 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.9 +6.0.0 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index d10afd5..1ecfbf0 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index eba478f..3719a13 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.9" + GITHUB_LATEST_VERSION="6.0.0" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 445af03..6bff12f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.9', - 'user-agent' : `AppwriteCLI/6.0.0-rc.9 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0', + 'user-agent' : `AppwriteCLI/6.0.0 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/commands/generic.js b/lib/commands/generic.js index 6b6e5df..407dd58 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -12,7 +12,8 @@ const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1'; const loginCommand = async ({ email, password, endpoint, mfa, code }) => { const oldCurrent = globalConfig.getCurrentSession(); - let configEndpoint = endpoint ?? DEFAULT_ENDPOINT; + + const configEndpoint = endpoint ?? globalConfig.getEndpoint() ?? DEFAULT_ENDPOINT; if (globalConfig.getCurrentSession() !== '') { log('You are currently signed in as ' + globalConfig.getEmail()); diff --git a/lib/commands/init.js b/lib/commands/init.js index 8d291e7..b9147e1 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -299,9 +299,9 @@ const initFunction = async () => { $id: functionId, name: answers.name, runtime: answers.runtime.id, - execute: [], + execute: ["any"], events: [], - scopes: [], + scopes: ["users.read"], schedule: "", timeout: 15, enabled: true, diff --git a/lib/parser.js b/lib/parser.js index 08920d7..6b53ec7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.9'; + const version = '6.0.0'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/lib/questions.js b/lib/questions.js index ce5c306..6f72adb 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -261,7 +261,7 @@ const questionsPullFunctionsCode = [ { type: "confirm", name: "override", - message: "Do you want to pull source code of active deployment?" + message: "Do you want to pull source code of the latest deployment?" }, ]; diff --git a/package.json b/package.json index 70d0a6d..fadfab4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.9", + "version": "6.0.0", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 3e59707..7fc9b6f 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.9", + "version": "6.0.0", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From 0abc0c63a34f60d64359293afc469d56b76b5149 Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Mon, 26 Aug 2024 16:33:16 +0000 Subject: [PATCH 17/18] chore: update for appwrite 1.6.x --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/commands/push.js | 4 ++++ lib/config.js | 6 ++++-- lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f3c09bd..530ff28 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0 +6.0.0-rc.9 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0 +6.0.0-rc.9 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index 1ecfbf0..d10afd5 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 3719a13..eba478f 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0" + GITHUB_LATEST_VERSION="6.0.0-rc.9" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 6bff12f..445af03 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0', - 'user-agent' : `AppwriteCLI/6.0.0 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0-rc.9', + 'user-agent' : `AppwriteCLI/6.0.0-rc.9 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/commands/push.js b/lib/commands/push.js index ef3f93a..e1fd35b 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -64,6 +64,8 @@ const { projectsUpdateAuthPasswordDictionary, projectsUpdateAuthPasswordHistory, projectsUpdatePersonalDataCheck, + projectsUpdateSessionAlerts, + projectsUpdateMockNumbers, } = require("./projects"); const { checkDeployConditions } = require('../utils'); @@ -980,6 +982,8 @@ const pushSettings = async () => { await projectsUpdateAuthPasswordDictionary({ projectId, enabled: settings.auth.security.passwordDictionary, parseOutput: false }); await projectsUpdateAuthPasswordHistory({ projectId, limit: settings.auth.security.passwordHistory, parseOutput: false }); await projectsUpdatePersonalDataCheck({ projectId, enabled: settings.auth.security.personalDataCheck, parseOutput: false }); + await projectsUpdateSessionAlerts({ projectId, alerts: settings.auth.security.sessionAlerts, parseOutput: false }); + await projectsUpdateMockNumbers({ projectId, numbers: settings.auth.security.mockNumbers, parseOutput: false }); } if (settings.auth.methods) { diff --git a/lib/config.js b/lib/config.js index 063ea06..19190d7 100644 --- a/lib/config.js +++ b/lib/config.js @@ -456,8 +456,10 @@ class Local extends Config { sessionsLimit: projectSettings.authSessionsLimit, passwordHistory: projectSettings.authPasswordHistory, passwordDictionary: projectSettings.authPasswordDictionary, - personalDataCheck: projectSettings.authPersonalDataCheck - } + personalDataCheck: projectSettings.authPersonalDataCheck, + sessionAlerts: projectSettings.authSessionAlerts, + mockNumbers: projectSettings.authMockNumbers + }, } }; } diff --git a/lib/parser.js b/lib/parser.js index 6b53ec7..08920d7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0'; + const version = '6.0.0-rc.9'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index fadfab4..70d0a6d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0", + "version": "6.0.0-rc.9", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 7fc9b6f..3e59707 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0", + "version": "6.0.0-rc.9", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe", From dab99867cefff2f2e9df3e56dd68f57283fa783b Mon Sep 17 00:00:00 2001 From: root <christyjacob4@gmail.com> Date: Tue, 27 Aug 2024 08:53:21 +0000 Subject: [PATCH 18/18] feat: updates for Appwrite 1.6 --- README.md | 4 ++-- install.ps1 | 4 ++-- install.sh | 2 +- lib/client.js | 4 ++-- lib/commands/pull.js | 8 ++++---- lib/parser.js | 2 +- package.json | 2 +- scoop/appwrite.json | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 530ff28..f3c09bd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -6.0.0-rc.9 +6.0.0 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -6.0.0-rc.9 +6.0.0 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index d10afd5..1ecfbf0 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index eba478f..3719a13 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="6.0.0-rc.9" + GITHUB_LATEST_VERSION="6.0.0" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index 445af03..6bff12f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '6.0.0-rc.9', - 'user-agent' : `AppwriteCLI/6.0.0-rc.9 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '6.0.0', + 'user-agent' : `AppwriteCLI/6.0.0 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.6.0', }; } diff --git a/lib/commands/pull.js b/lib/commands/pull.js index 0c4fc92..40c07a7 100644 --- a/lib/commands/pull.js +++ b/lib/commands/pull.js @@ -88,9 +88,9 @@ const pullFunctions = async ({ code, withVariables }) => { if (!localFunction['path']) { func['path'] = `functions/${func.name}`; } - if (!withVariables) { - delete func['vars']; - } + const holdingVars = func['vars']; + // We don't save var in to the config + delete func['vars']; localConfig.addFunction(func); if (!fs.existsSync(func['path'])) { @@ -162,7 +162,7 @@ const pullFunctions = async ({ code, withVariables }) => { } catch { } - fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join('')) + fs.writeFileSync(envFileLocation, holdingVars.map(r => `${r.key}=${r.value}\n`).join('')) } } diff --git a/lib/parser.js b/lib/parser.js index 08920d7..6b53ec7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -120,7 +120,7 @@ const parseError = (err) => { } catch { } - const version = '6.0.0-rc.9'; + const version = '6.0.0'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`; diff --git a/package.json b/package.json index 70d0a6d..fadfab4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "6.0.0-rc.9", + "version": "6.0.0", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 3e59707..7fc9b6f 100644 --- a/scoop/appwrite.json +++ b/scoop/appwrite.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "6.0.0-rc.9", + "version": "6.0.0", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.9/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe",