diff --git a/README.md b/README.md index c9568fb..f3c09bd 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.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.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) @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -5.0.5 +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 -5.0.5 +6.0.0 ``` ## 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/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..8b83c0e 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -19,3 +19,5 @@ 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/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 \ --deploymentId 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 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/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/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..7ac63e0 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -15,3 +15,5 @@ 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..fa7067f 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, deploy } = require("./lib/commands/push"); const { account } = require("./lib/commands/account"); const { avatars } = require("./lib/commands/avatars"); const { assistant } = require("./lib/commands/assistant"); @@ -32,25 +35,51 @@ 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({ helpWidth: process.stdout.columns || 80, - sortSubcommands: true + sortSubcommands: true, }) - .version(version, "-v, --version") - .option("--verbose", "Show complete error log") - .option("--json", "Output in JSON format") + .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 a list of ids for a given 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(pull) + .addCommand(push) .addCommand(deploy) + .addCommand(run) .addCommand(logout) .addCommand(account) .addCommand(avatars) @@ -72,5 +101,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..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/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/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" @@ -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..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="5.0.5" + 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" @@ -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..6bff12f 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 = { @@ -15,9 +16,9 @@ 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-Appwrite-Response-Format' : '1.5.0', + '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', }; } @@ -167,7 +168,7 @@ class Client { body = formData; } else { - body = JSON.stringify(params); + body = JSONbig.stringify(params); } let response = undefined; @@ -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); } @@ -210,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/account.js b/lib/commands/account.js index d6f07c6..4c45f43 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') @@ -35,12 +35,13 @@ 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 }) /** * @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,15 @@ const accountGet = async ({ parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('account', 'get'); + } else { + parse(response) + } } - + return response; + } /** @@ -73,6 +79,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 +87,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') { @@ -105,14 +113,15 @@ const accountCreate = async ({ userId, email, password, name, parseOutput = true if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountDeleteRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -120,8 +129,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 = {}; @@ -133,16 +143,17 @@ const accountDelete = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +161,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') { @@ -169,15 +181,16 @@ const accountUpdateEmail = async ({ email, password, parseOutput = true, sdk = u if (parseOutput) { 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 +198,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') { @@ -201,15 +215,16 @@ const accountListIdentities = async ({ queries, parseOutput = true, sdk = undefi if (parseOutput) { 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 +232,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 = {}; @@ -230,14 +246,15 @@ const accountDeleteIdentity = async ({ identityId, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountCreateJWTRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -245,9 +262,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; @@ -258,15 +276,16 @@ const accountCreateJWT = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +293,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') { @@ -290,15 +310,16 @@ const accountListLogs = async ({ queries, parseOutput = true, sdk = undefined}) if (parseOutput) { 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 +327,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') { @@ -322,15 +344,16 @@ const accountUpdateMFA = async ({ mfa, parseOutput = true, sdk = undefined}) => if (parseOutput) { 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 +361,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 = {}; @@ -351,16 +375,17 @@ const accountCreateMfaAuthenticator = async ({ type, parseOutput = true, sdk = u if (parseOutput) { 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 +393,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') { @@ -384,16 +410,16 @@ const accountUpdateMfaAuthenticator = async ({ type, otp, parseOutput = true, sd if (parseOutput) { 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,13 +427,11 @@ 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,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; @@ -417,15 +441,16 @@ const accountDeleteMfaAuthenticator = async ({ type, otp, parseOutput = true, sd if (parseOutput) { 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 +458,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') { @@ -449,16 +475,17 @@ const accountCreateMfaChallenge = async ({ factor, parseOutput = true, sdk = und if (parseOutput) { 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 +493,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') { @@ -485,14 +513,15 @@ const accountUpdateMfaChallenge = async ({ challengeId, otp, parseOutput = true, if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountListMfaFactorsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -500,8 +529,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 = {}; @@ -513,14 +543,15 @@ const accountListMfaFactors = async ({ parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountGetMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -528,8 +559,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 = {}; @@ -541,14 +573,15 @@ const accountGetMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefined} if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountCreateMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -556,8 +589,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 = {}; @@ -569,14 +603,15 @@ const accountCreateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountUpdateMfaRecoveryCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -584,8 +619,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 = {}; @@ -597,15 +633,16 @@ const accountUpdateMfaRecoveryCodes = async ({ parseOutput = true, sdk = undefin if (parseOutput) { 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 +650,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') { @@ -629,16 +667,17 @@ const accountUpdateName = async ({ name, parseOutput = true, sdk = undefined}) = if (parseOutput) { 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 +685,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') { @@ -665,16 +705,17 @@ const accountUpdatePassword = async ({ password, oldPassword, parseOutput = true if (parseOutput) { 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 +723,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') { @@ -701,14 +743,15 @@ const accountUpdatePhone = async ({ phone, password, parseOutput = true, sdk = u if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountGetPrefsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -716,8 +759,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 = {}; @@ -729,15 +773,16 @@ const accountGetPrefs = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +790,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') { @@ -761,16 +807,17 @@ const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined}) if (parseOutput) { 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 +825,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') { @@ -797,10 +845,10 @@ const accountCreateRecovery = async ({ email, url, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -808,6 +856,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 +864,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') { @@ -837,14 +887,15 @@ const accountUpdateRecovery = async ({ userId, secret, password, parseOutput = t if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountListSessionsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -852,8 +903,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 +916,20 @@ const accountListSessions = async ({ parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('account', 'listSessions'); + } else { + parse(response) + } } - + return response; + } /** * @typedef {Object} AccountDeleteSessionsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -880,8 +937,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 = {}; @@ -893,14 +951,15 @@ const accountDeleteSessions = async ({ parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountCreateAnonymousSessionRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -908,8 +967,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 = {}; @@ -921,16 +981,17 @@ const accountCreateAnonymousSession = async ({ parseOutput = true, sdk = undefin if (parseOutput) { 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 +999,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') { @@ -957,16 +1019,17 @@ const accountCreateEmailPasswordSession = async ({ email, password, parseOutput if (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 +1037,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') { @@ -993,10 +1057,10 @@ const accountUpdateMagicURLSession = async ({ userId, secret, parseOutput = true if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1005,6 +1069,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 +1077,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') { @@ -1034,16 +1100,17 @@ const accountCreateOAuth2Session = async ({ provider, success, failure, scopes, if (parseOutput) { 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 +1118,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') { @@ -1070,16 +1138,17 @@ const accountUpdatePhoneSession = async ({ userId, secret, parseOutput = true, s if (parseOutput) { 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 +1156,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') { @@ -1106,15 +1176,16 @@ const accountCreateSession = async ({ userId, secret, parseOutput = true, sdk = if (parseOutput) { 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 +1193,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 = {}; @@ -1135,15 +1207,16 @@ const accountGetSession = async ({ sessionId, parseOutput = true, sdk = undefine if (parseOutput) { 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 +1224,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 = {}; @@ -1164,15 +1238,16 @@ const accountUpdateSession = async ({ sessionId, parseOutput = true, sdk = undef if (parseOutput) { 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 +1255,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 = {}; @@ -1193,14 +1269,15 @@ const accountDeleteSession = async ({ sessionId, parseOutput = true, sdk = undef if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountUpdateStatusRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1208,8 +1285,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 = {}; @@ -1221,10 +1299,10 @@ const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1232,6 +1310,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 +1318,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') { @@ -1261,16 +1341,17 @@ const accountCreatePushTarget = async ({ targetId, identifier, providerId, parse if (parseOutput) { 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 +1359,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') { @@ -1294,15 +1376,16 @@ const accountUpdatePushTarget = async ({ targetId, identifier, parseOutput = tru if (parseOutput) { 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 +1393,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 = {}; @@ -1323,10 +1407,10 @@ const accountDeletePushTarget = async ({ targetId, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1334,6 +1418,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 +1426,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') { @@ -1363,10 +1449,10 @@ const accountCreateEmailToken = async ({ userId, email, phrase, parseOutput = tr if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1375,6 +1461,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 +1469,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') { @@ -1407,10 +1495,10 @@ const accountCreateMagicURLToken = async ({ userId, email, url, phrase, parseOut if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1419,6 +1507,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 +1515,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') { @@ -1448,16 +1538,17 @@ const accountCreateOAuth2Token = async ({ provider, success, failure, scopes, pa if (parseOutput) { 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 +1556,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') { @@ -1484,15 +1576,16 @@ const accountCreatePhoneToken = async ({ userId, phone, parseOutput = true, sdk if (parseOutput) { 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 +1593,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') { @@ -1516,16 +1610,17 @@ const accountCreateVerification = async ({ url, parseOutput = true, sdk = undefi if (parseOutput) { 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 +1628,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') { @@ -1552,14 +1648,15 @@ const accountUpdateVerification = async ({ userId, secret, parseOutput = true, s if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} AccountCreatePhoneVerificationRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1567,8 +1664,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 = {}; @@ -1580,16 +1678,17 @@ const accountCreatePhoneVerification = async ({ parseOutput = true, sdk = undefi if (parseOutput) { 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 +1696,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') { @@ -1616,21 +1716,22 @@ const accountUpdatePhoneVerification = async ({ userId, secret, parseOutput = tr if (parseOutput) { 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 .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.`) @@ -1642,171 +1743,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`) - .description(`Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method. add `) + .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.`) - .requiredOption(`--otp `, `Valid verification token.`) .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.`) @@ -1815,82 +1916,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.`) @@ -1899,34 +2000,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)) @@ -1980,4 +2081,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..16a17ec 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') @@ -35,13 +35,14 @@ 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 }) /** * @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') { @@ -65,10 +67,10 @@ const assistantChat = async ({ prompt, parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } assistant @@ -80,4 +82,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..0468eb8 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') @@ -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 }) @@ -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,17 @@ 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 +100,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 +109,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 +123,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 +136,23 @@ 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 +161,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 +182,17 @@ 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 +201,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 +210,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 +224,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 +237,17 @@ 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 +255,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 +264,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 +278,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 +291,17 @@ 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 +310,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 +319,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 +336,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 +349,17 @@ 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 +368,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 +377,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 +394,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,18 +407,21 @@ 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 - .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) @@ -382,7 +431,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) @@ -392,14 +441,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) @@ -409,8 +458,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) @@ -418,7 +467,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) @@ -428,7 +477,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) @@ -446,4 +495,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..180c38a 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') @@ -35,12 +35,13 @@ 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 }) /** * @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 = {}; @@ -61,10 +63,10 @@ const consoleVariables = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } console @@ -75,4 +77,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..66b49e6 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') @@ -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 }) @@ -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,15 @@ const databasesList = async ({ queries, search, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'list'); + } else { + parse(response) + } } - + return response; + } /** @@ -80,6 +86,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 +94,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') { @@ -109,15 +117,16 @@ const databasesCreate = async ({ databaseId, name, enabled, parseOutput = true, if (parseOutput) { 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 +134,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') { @@ -141,15 +151,16 @@ const databasesGetUsage = async ({ range, parseOutput = true, sdk = undefined}) if (parseOutput) { 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 +168,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 +181,15 @@ const databasesGet = async ({ databaseId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'get', databaseId); + } else { + parse(response) + } } - + return response; + } /** @@ -181,6 +197,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 +205,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') { @@ -207,15 +225,16 @@ const databasesUpdate = async ({ databaseId, name, enabled, parseOutput = true, if (parseOutput) { 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 +242,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 = {}; @@ -236,10 +256,10 @@ const databasesDelete = async ({ databaseId, parseOutput = true, sdk = undefined if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -247,6 +267,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 +275,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 +294,15 @@ const databasesListCollections = async ({ databaseId, queries, search, parseOutp }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listCollections', databaseId); + } else { + parse(response) + } } - + return response; + } /** @@ -287,6 +313,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 +321,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') { @@ -323,16 +351,17 @@ const databasesCreateCollection = async ({ databaseId, collectionId, name, permi if (parseOutput) { 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 +369,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 +382,15 @@ const databasesGetCollection = async ({ databaseId, collectionId, parseOutput = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getCollection', databaseId, collectionId); + } else { + parse(response) + } } - + return response; + } /** @@ -367,6 +401,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 +409,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') { @@ -400,16 +436,17 @@ const databasesUpdateCollection = async ({ databaseId, collectionId, name, permi if (parseOutput) { 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 +454,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 = {}; @@ -430,10 +468,10 @@ const databasesDeleteCollection = async ({ databaseId, collectionId, parseOutput if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -441,6 +479,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 +487,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 +503,15 @@ const databasesListAttributes = async ({ databaseId, collectionId, queries, pars }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listAttributes', databaseId, collectionId); + } else { + parse(response) + } } - + return response; + } /** @@ -478,6 +522,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 +530,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') { @@ -510,10 +556,10 @@ const databasesCreateBooleanAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -523,6 +569,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 +577,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') { @@ -549,10 +597,10 @@ const databasesUpdateBooleanAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -563,6 +611,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 +619,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') { @@ -595,10 +645,10 @@ const databasesCreateDatetimeAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -608,6 +658,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 +666,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') { @@ -634,10 +686,10 @@ const databasesUpdateDatetimeAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -648,6 +700,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 +708,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') { @@ -680,10 +734,10 @@ const databasesCreateEmailAttribute = async ({ databaseId, collectionId, key, re if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -693,6 +747,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 +755,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') { @@ -719,10 +775,10 @@ const databasesUpdateEmailAttribute = async ({ databaseId, collectionId, key, re if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -734,6 +790,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 +798,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') { @@ -770,10 +828,10 @@ const databasesCreateEnumAttribute = async ({ databaseId, collectionId, key, ele if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -784,6 +842,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 +850,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; @@ -814,10 +874,10 @@ const databasesUpdateEnumAttribute = async ({ databaseId, collectionId, key, ele if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -830,6 +890,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 +898,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') { @@ -868,10 +930,10 @@ const databasesCreateFloatAttribute = async ({ databaseId, collectionId, key, re if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -883,6 +945,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 +953,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') { @@ -915,10 +979,10 @@ const databasesUpdateFloatAttribute = async ({ databaseId, collectionId, key, re if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -931,6 +995,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 +1003,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') { @@ -969,10 +1035,10 @@ const databasesCreateIntegerAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -984,6 +1050,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 +1058,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') { @@ -1016,10 +1084,10 @@ const databasesUpdateIntegerAttribute = async ({ databaseId, collectionId, key, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1030,6 +1098,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 +1106,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') { @@ -1062,10 +1132,10 @@ const databasesCreateIpAttribute = async ({ databaseId, collectionId, key, requi if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1075,6 +1145,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 +1153,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') { @@ -1101,10 +1173,10 @@ const databasesUpdateIpAttribute = async ({ databaseId, collectionId, key, requi if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1117,6 +1189,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 +1197,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') { @@ -1155,10 +1229,10 @@ const databasesCreateRelationshipAttribute = async ({ databaseId, collectionId, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1171,6 +1245,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 +1253,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') { @@ -1209,10 +1285,10 @@ const databasesCreateStringAttribute = async ({ databaseId, collectionId, key, s if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1222,6 +1298,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 +1306,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') { @@ -1248,10 +1326,10 @@ const databasesUpdateStringAttribute = async ({ databaseId, collectionId, key, r if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1262,6 +1340,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 +1348,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') { @@ -1294,10 +1374,10 @@ const databasesCreateUrlAttribute = async ({ databaseId, collectionId, key, requ if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1307,6 +1387,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 +1395,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') { @@ -1333,10 +1415,10 @@ const databasesUpdateUrlAttribute = async ({ databaseId, collectionId, key, requ if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1344,6 +1426,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 +1434,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 = {}; @@ -1364,10 +1448,10 @@ const databasesGetAttribute = async ({ databaseId, collectionId, key, parseOutpu if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1375,6 +1459,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 +1467,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 = {}; @@ -1395,10 +1481,10 @@ const databasesDeleteAttribute = async ({ databaseId, collectionId, key, parseOu if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1407,6 +1493,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 +1501,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') { @@ -1430,10 +1518,10 @@ const databasesUpdateRelationshipAttribute = async ({ databaseId, collectionId, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1441,6 +1529,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 +1537,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 +1553,15 @@ const databasesListDocuments = async ({ databaseId, collectionId, queries, parse }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listDocuments', databaseId, collectionId); + } else { + parse(response) + } } - + return response; + } /** @@ -1477,6 +1571,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 +1579,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') { @@ -1507,10 +1603,10 @@ const databasesCreateDocument = async ({ databaseId, collectionId, documentId, d if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1519,6 +1615,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 +1623,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 +1639,15 @@ const databasesGetDocument = async ({ databaseId, collectionId, documentId, quer }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getDocument', databaseId, collectionId, documentId); + } else { + parse(response) + } } - + return response; + } /** @@ -1555,6 +1657,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 +1665,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') { @@ -1582,10 +1686,10 @@ const databasesUpdateDocument = async ({ databaseId, collectionId, documentId, d if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1593,6 +1697,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 +1705,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 = {}; @@ -1613,10 +1719,10 @@ const databasesDeleteDocument = async ({ databaseId, collectionId, documentId, p if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1625,6 +1731,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 +1739,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') { @@ -1648,10 +1756,10 @@ const databasesListDocumentLogs = async ({ databaseId, collectionId, documentId, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1659,6 +1767,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 +1775,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 +1791,15 @@ const databasesListIndexes = async ({ databaseId, collectionId, queries, parseOu }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'listIndexes', databaseId, collectionId); + } else { + parse(response) + } } - + return response; + } /** @@ -1696,6 +1810,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 +1818,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') { @@ -1730,10 +1846,10 @@ const databasesCreateIndex = async ({ databaseId, collectionId, key, type, attri if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1741,6 +1857,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 +1865,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 = {}; @@ -1761,10 +1879,10 @@ const databasesGetIndex = async ({ databaseId, collectionId, key, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1772,6 +1890,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 +1898,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 = {}; @@ -1792,10 +1912,10 @@ const databasesDeleteIndex = async ({ databaseId, collectionId, key, parseOutput if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1803,6 +1923,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 +1931,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') { @@ -1826,10 +1948,10 @@ const databasesListCollectionLogs = async ({ databaseId, collectionId, queries, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1837,6 +1959,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 +1967,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') { @@ -1860,16 +1984,17 @@ const databasesGetCollectionUsage = async ({ databaseId, collectionId, range, pa if (parseOutput) { 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 +2002,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') { @@ -1893,16 +2019,17 @@ const databasesListLogs = async ({ databaseId, queries, parseOutput = true, sdk if (parseOutput) { 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 +2037,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 +2053,15 @@ const databasesGetDatabaseUsage = async ({ databaseId, range, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('databases', 'getDatabaseUsage', databaseId); + } else { + parse(response) + } } - + return response; + } databases @@ -1937,18 +2069,19 @@ 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 .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)) @@ -1956,13 +2089,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)) @@ -1970,66 +2104,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) @@ -2037,20 +2174,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.`) @@ -2058,20 +2195,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.`) @@ -2079,20 +2216,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) @@ -2101,10 +2238,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) @@ -2112,10 +2249,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) @@ -2125,10 +2262,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) @@ -2137,10 +2274,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) @@ -2150,10 +2287,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) @@ -2162,10 +2299,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.`) @@ -2173,33 +2310,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) @@ -2209,20 +2346,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.`) @@ -2230,107 +2367,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.`) @@ -2338,49 +2478,50 @@ 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)) module.exports = { @@ -2433,4 +2574,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..a5b9a7f 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') @@ -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 }) @@ -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,15 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'list'); + } else { + parse(response) + } } - + return response; + } /** @@ -88,6 +94,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. @@ -96,7 +103,9 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi * @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 {string} specification Runtime specification for the function and builds. + * @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,templateVersion,specification,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; } @@ -167,8 +181,11 @@ const functionsCreate = async ({ functionId, name, runtime, execute, events, sch if (typeof templateRootDirectory !== 'undefined') { payload['templateRootDirectory'] = templateRootDirectory; } - if (typeof templateBranch !== 'undefined') { - payload['templateBranch'] = templateBranch; + if (typeof templateVersion !== 'undefined') { + payload['templateVersion'] = templateVersion; + } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; } let response = undefined; @@ -179,14 +196,15 @@ const functionsCreate = async ({ functionId, name, runtime, execute, events, sch if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} FunctionsListRuntimesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -194,8 +212,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 = {}; @@ -207,15 +226,135 @@ const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + + return response; + +} + +/** + * @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. + * @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; + } /** * @typedef {Object} FunctionsGetUsageRequestParams * @property {FunctionUsageRange} range Date range. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -223,8 +362,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') { @@ -239,15 +379,16 @@ const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) if (parseOutput) { 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 +396,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 +409,15 @@ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'get', functionId); + } else { + parse(response) + } } - + return response; + } /** @@ -287,11 +433,14 @@ 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 {string} specification Runtime specification for the function and builds. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -299,8 +448,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,specification,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 +485,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; } @@ -350,6 +504,9 @@ const functionsUpdate = async ({ functionId, name, runtime, execute, events, sch if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; + } let response = undefined; @@ -359,15 +516,16 @@ const functionsUpdate = async ({ functionId, name, runtime, execute, events, sch if (parseOutput) { 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 +533,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 = {}; @@ -388,17 +547,18 @@ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined if (parseOutput) { parse(response) - success() } - + return response; + } /** * @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 * @property {libClient | undefined} sdk */ @@ -406,8 +566,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 +585,15 @@ const functionsListDeployments = async ({ functionId, queries, search, parseOutp }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'listDeployments', functionId); + } else { + parse(response) + } } - + return response; + } /** @@ -438,6 +603,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 +612,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,30 +627,32 @@ 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)); + 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; @@ -502,7 +671,7 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin } const size = code.size; - + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -529,7 +698,7 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin } let uploadableChunkTrimmed; - + if(currentPosition + 1 >= client.CHUNK_SIZE) { uploadableChunkTrimmed = uploadableChunk; } else { @@ -582,11 +751,10 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin await uploadChunk(true); } - fs.unlinkSync(filePath); - + await fs.unlink(filePath,()=>{}); + if (parseOutput) { parse(response) - success() } return response; @@ -596,6 +764,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 +772,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 +785,22 @@ const functionsGetDeployment = async ({ functionId, deploymentId, parseOutput = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'getDeployment', functionId, deploymentId); + } else { + parse(response) + } } - + 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 +808,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 = {}; @@ -646,16 +822,17 @@ const functionsUpdateDeployment = async ({ functionId, deploymentId, parseOutput if (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 +840,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 = {}; @@ -676,10 +854,10 @@ const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -687,6 +865,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 +873,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; @@ -707,32 +890,68 @@ const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOu if (parseOutput) { parse(response) - success() } - + return response; + } /** - * @typedef {Object} FunctionsDownloadDeploymentRequestParams + * @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) + } + + return response; + +} + +/** + * @typedef {Object} FunctionsGetDeploymentDownloadRequestParams + * @property {string} functionId Function ID. + * @property {string} deploymentId Deployment ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk * @property {string} destination */ /** - * @param {FunctionsDownloadDeploymentRequestParams} params + * @param {FunctionsGetDeploymentDownloadRequestParams} params */ -const functionsDownloadDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined, destination}) => { - let client = !sdk ? await sdkForProject() : sdk; +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); 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 +959,29 @@ 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() + if(console) { + showConsoleLink('functions', 'getDeploymentDownload', functionId, deploymentId); + } else { + parse(response) + } } - + 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 +989,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 +1008,15 @@ const functionsListExecutions = async ({ functionId, queries, search, parseOutpu }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'listExecutions', functionId); + } else { + parse(response) + } } - + return response; + } /** @@ -795,6 +1027,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 with precision in minutes. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -802,8 +1036,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 +1056,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; @@ -830,16 +1068,17 @@ const functionsCreateExecution = async ({ functionId, body, async, xpath, method if (parseOutput) { 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 +1086,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 +1098,55 @@ const functionsGetExecution = async ({ functionId, executionId, parseOutput = tr 'content-type': 'application/json', }, payload); + if (parseOutput) { + if(console) { + showConsoleLink('functions', 'getExecution', functionId, executionId); + } else { + parse(response) + } + } + + 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 +1154,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 +1170,21 @@ const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('functions', 'getFunctionUsage', functionId); + } else { + parse(response) + } } - + return response; + } /** * @typedef {Object} FunctionsListVariablesRequestParams * @property {string} functionId Function unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -909,8 +1192,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 = {}; @@ -922,10 +1206,10 @@ const functionsListVariables = async ({ functionId, parseOutput = true, sdk = un if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -933,6 +1217,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 +1225,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') { @@ -959,16 +1245,17 @@ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = t if (parseOutput) { 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 +1263,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 = {}; @@ -989,10 +1277,10 @@ const functionsGetVariable = async ({ functionId, variableId, parseOutput = true if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1001,6 +1289,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 +1297,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') { @@ -1027,16 +1317,17 @@ const functionsUpdateVariable = async ({ functionId, variableId, key, value, par if (parseOutput) { 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 +1335,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 = {}; @@ -1057,10 +1349,10 @@ const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = t if (parseOutput) { parse(response) - success() } - + return response; + } functions @@ -1068,12 +1360,13 @@ 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 .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.`) @@ -1084,24 +1377,49 @@ 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(`--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(`--scopes [scopes...]`, `List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed.`) + .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-version `, `Version (tag) for the repo linked to the function template.`) + .option(`--specification `, `Runtime specification for the function and builds.`) .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(`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.`) + .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 the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.`, parseInteger) + .option(`--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.`) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsGetTemplate)) + +functions + .command(`get-usage`) .description(``) .option(`--range `, `Date range.`) .action(actionRunner(functionsGetUsage)) @@ -1109,13 +1427,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.`) @@ -1126,31 +1445,34 @@ 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(`--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(`--scopes [scopes...]`, `List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed.`) + .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.`) + .option(`--specification `, `Runtime specification for the function and builds.`) .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.`) - .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`) + .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, type, size`) .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.`) @@ -1158,110 +1480,130 @@ 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`) - .description(`Create a new build for an Appwrite Function deployment. This endpoint can be used to retry a failed build.`) - .requiredOption(`--functionId `, `Function ID.`) - .requiredOption(`--deploymentId `, `Deployment ID.`) - .requiredOption(`--buildId `, `Build unique ID.`) + .command(`create-build`) + .description(``) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) + .option(`--build-id `, `Build unique ID.`) .action(actionRunner(functionsCreateBuild)) functions - .command(`downloadDeployment`) + .command(`update-deployment-build`) + .description(``) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--deployment-id `, `Deployment ID.`) + .action(actionRunner(functionsUpdateDeploymentBuild)) + +functions + .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(`--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)) + .option(`--console`, `Get the resource console url`) + .action(actionRunner(functionsGetDeploymentDownload)) 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.`) - .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`) + .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(`--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 - .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(`getFunctionUsage`) + .command(`delete-execution`) + .description(`Delete a function execution by its unique ID. `) + .requiredOption(`--function-id `, `Function ID.`) + .requiredOption(`--execution-id `, `Execution ID.`) + .action(actionRunner(functionsDeleteExecution)) + +functions + .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 = { @@ -1269,6 +1611,9 @@ module.exports = { functionsList, functionsCreate, functionsListRuntimes, + functionsListSpecifications, + functionsListTemplates, + functionsGetTemplate, functionsGetUsage, functionsGet, functionsUpdate, @@ -1279,14 +1624,16 @@ module.exports = { functionsUpdateDeployment, functionsDeleteDeployment, functionsCreateBuild, - functionsDownloadDeployment, + functionsUpdateDeploymentBuild, + functionsGetDeploymentDownload, 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..407dd58 100644 --- a/lib/commands/generic.js +++ b/lib/commands/generic.js @@ -3,20 +3,57 @@ 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 { 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 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(); + + const configEndpoint = endpoint ?? globalConfig.getEndpoint() ?? 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; + + 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 +63,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("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'"); + return; + } + + let client = await sdkForConsole(false); + let account; try { @@ -33,43 +121,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 +172,52 @@ 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 === '' || !sessions.length) { + log('No active sessions found.'); + return; + } + if (sessions.length === 1) { + await deleteSession(current); + success("Logging out"); + + 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("Logging out"); })); const client = new Command("client") @@ -87,12 +225,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, --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, --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") .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 +249,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 +264,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 +285,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() + success("Setting client") })); +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..c3c6c0c 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') @@ -35,13 +35,14 @@ 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 }) /** * @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') { @@ -66,15 +68,16 @@ const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +85,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') { @@ -99,10 +103,10 @@ const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } graphql @@ -121,4 +125,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..99f6896 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') @@ -35,12 +35,13 @@ 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 }) /** * @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 = {}; @@ -61,14 +63,15 @@ const healthGet = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetAntivirusRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -76,8 +79,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 = {}; @@ -89,14 +93,15 @@ const healthGetAntivirus = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetCacheRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -104,8 +109,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 = {}; @@ -117,15 +123,16 @@ const healthGetCache = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetCertificateRequestParams * @property {string} domain string + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -133,8 +140,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') { @@ -149,14 +157,15 @@ const healthGetCertificate = async ({ domain, parseOutput = true, sdk = undefine if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetDBRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -164,8 +173,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 = {}; @@ -177,14 +187,15 @@ const healthGetDB = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetPubSubRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -192,8 +203,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 = {}; @@ -205,14 +217,15 @@ const healthGetPubSub = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetQueueRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -220,8 +233,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 = {}; @@ -233,15 +247,16 @@ const healthGetQueue = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +264,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') { @@ -265,15 +281,16 @@ const healthGetQueueBuilds = async ({ threshold, parseOutput = true, sdk = undef if (parseOutput) { 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 +298,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') { @@ -297,16 +315,17 @@ const healthGetQueueCertificates = async ({ threshold, parseOutput = true, sdk = if (parseOutput) { 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 +333,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') { @@ -333,15 +353,16 @@ const healthGetQueueDatabases = async ({ name, threshold, parseOutput = true, sd if (parseOutput) { 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 +370,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') { @@ -365,16 +387,17 @@ const healthGetQueueDeletes = async ({ threshold, parseOutput = true, sdk = unde if (parseOutput) { 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 +405,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') { @@ -398,15 +422,16 @@ const healthGetFailedJobs = async ({ name, threshold, parseOutput = true, sdk = if (parseOutput) { 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 +439,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') { @@ -430,15 +456,16 @@ const healthGetQueueFunctions = async ({ threshold, parseOutput = true, sdk = un if (parseOutput) { 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 +473,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') { @@ -462,15 +490,16 @@ const healthGetQueueLogs = async ({ threshold, parseOutput = true, sdk = undefin if (parseOutput) { 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 +507,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') { @@ -494,15 +524,16 @@ const healthGetQueueMails = async ({ threshold, parseOutput = true, sdk = undefi if (parseOutput) { 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 +541,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') { @@ -526,15 +558,16 @@ const healthGetQueueMessaging = async ({ threshold, parseOutput = true, sdk = un if (parseOutput) { 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 +575,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') { @@ -558,15 +592,16 @@ const healthGetQueueMigrations = async ({ threshold, parseOutput = true, sdk = u if (parseOutput) { 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 +609,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') { @@ -590,15 +626,16 @@ const healthGetQueueUsage = async ({ threshold, parseOutput = true, sdk = undefi if (parseOutput) { 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 +643,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') { @@ -622,15 +660,16 @@ const healthGetQueueUsageDump = async ({ threshold, parseOutput = true, sdk = un if (parseOutput) { 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 +677,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') { @@ -654,14 +694,15 @@ const healthGetQueueWebhooks = async ({ threshold, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetStorageRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -669,8 +710,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 = {}; @@ -682,14 +724,15 @@ const healthGetStorage = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetStorageLocalRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -697,8 +740,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 = {}; @@ -710,14 +754,15 @@ const healthGetStorageLocal = async ({ parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} HealthGetTimeRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -725,8 +770,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 = {}; @@ -738,10 +784,10 @@ const healthGetTime = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } health @@ -750,128 +796,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)) @@ -900,4 +946,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..b9147e1 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,58 +3,199 @@ 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 { pullResources } = require("./pull"); +const ID = require("../id"); +const { localConfig, globalConfig } = require("../config"); +const { + questionsCreateFunction, + questionsCreateFunctionSelectTemplate, + questionsCreateBucket, + questionsCreateMessagingTopic, + questionsCreateCollection, + questionsInitProject, + questionsInitProjectAutopull, + questionsInitResources, + questionsCreateTeam +} = require("../questions"); +const { cliConfig, success, log, hint, 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 teamId = response['$id']; + 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; + } + } + } + + 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(); + + success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`); + + if(answers.start === 'existing') { + 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."); + } + } + + 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 () => { + 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("Initialing bucket"); + 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("Initialing team"); + 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("Initialing collection"); + 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("Initialing topic"); + log("Next you can use 'appwrite push topic' to deploy the changes."); +}; + const initFunction = async () => { + process.chdir(localConfig.configDirectoryPath) + // 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 +204,35 @@ const initFunction = async () => { }); } - const functionDir = path.join(functionFolder, answers.name); + const functionId = answers.id === 'unique()' ? ID.unique() : answers.id; + 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(`( ${answers.name} ) 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) { - 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}` + let selected = { template: 'starter' }; + + const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase(); - 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 + 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 ${answers.runtime.id}`; + 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,19 @@ const initFunction = async () => { } } - fs.rmSync(path.join(functionDir, ".git"), { recursive: true }); + 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)); + 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 +284,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', functionName, 'README.md'); const readmeFile = fs.readFileSync(readmePath).toString(); const newReadmeFile = readmeFile.split('\n'); newReadmeFile[0] = `# ${answers.name}`; @@ -142,125 +296,68 @@ 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: ["any"], + events: [], + scopes: ["users.read"], + 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/${functionName}`, }; localConfig.addFunction(data); - success(); -} - -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(); + success("Initialing function"); + log("Next you can use 'appwrite run function' to develop a function locally. To deploy the function, use 'appwrite push function'"); } -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("--organization-id ", "Appwrite organization ID") + .option("--project-id ", "Appwrite project ID") + .option("--project-name ", "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..a23dafa 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') @@ -35,12 +35,13 @@ 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 }) /** * @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 = {}; @@ -61,14 +63,15 @@ const localeGet = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListCodesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -76,8 +79,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 = {}; @@ -89,14 +93,15 @@ const localeListCodes = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListContinentsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -104,8 +109,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 = {}; @@ -117,14 +123,15 @@ const localeListContinents = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -132,8 +139,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 = {}; @@ -145,14 +153,15 @@ const localeListCountries = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesEURequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -160,8 +169,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 = {}; @@ -173,14 +183,15 @@ const localeListCountriesEU = async ({ parseOutput = true, sdk = undefined}) => if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListCountriesPhonesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -188,8 +199,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 = {}; @@ -201,14 +213,15 @@ const localeListCountriesPhones = async ({ parseOutput = true, sdk = undefined}) if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListCurrenciesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -216,8 +229,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 = {}; @@ -229,14 +243,15 @@ const localeListCurrencies = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} LocaleListLanguagesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -244,8 +259,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 = {}; @@ -257,10 +273,10 @@ const localeListLanguages = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { parse(response) - success() } - + return response; + } locale @@ -269,37 +285,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)) @@ -313,4 +329,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..0004554 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') @@ -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 }) @@ -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,15 @@ const messagingListMessages = async ({ queries, search, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listMessages'); + } else { + parse(response) + } } - + return response; + } /** @@ -89,6 +95,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 +103,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') { @@ -151,10 +159,10 @@ const messagingCreateEmail = async ({ messageId, subject, content, topics, users if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -171,6 +179,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 +187,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; @@ -230,10 +240,10 @@ const messagingUpdateEmail = async ({ messageId, topics, users, targets, subject if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -254,6 +264,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 +272,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') { @@ -325,10 +337,10 @@ const messagingCreatePush = async ({ messageId, title, body, topics, users, targ if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -349,6 +361,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 +369,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; @@ -417,10 +431,10 @@ const messagingUpdatePush = async ({ messageId, topics, users, targets, title, b if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -432,6 +446,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 +454,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') { @@ -476,10 +492,10 @@ const messagingCreateSms = async ({ messageId, content, topics, users, targets, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -491,6 +507,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 +515,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; @@ -532,15 +550,16 @@ const messagingUpdateSms = async ({ messageId, topics, users, targets, content, if (parseOutput) { 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 +567,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 +580,21 @@ const messagingGetMessage = async ({ messageId, parseOutput = true, sdk = undefi }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getMessage', messageId); + } else { + parse(response) + } } - + return response; + } /** * @typedef {Object} MessagingDeleteRequestParams * @property {string} messageId Message ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -577,8 +602,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 = {}; @@ -590,16 +616,17 @@ const messagingDelete = async ({ messageId, parseOutput = true, sdk = undefined} if (parseOutput) { 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 +634,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 +650,22 @@ const messagingListMessageLogs = async ({ messageId, queries, parseOutput = true }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listMessageLogs', messageId); + } else { + parse(response) + } } - + 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 +673,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') { @@ -656,16 +690,17 @@ const messagingListTargets = async ({ messageId, queries, parseOutput = true, sd if (parseOutput) { 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 +708,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 +727,15 @@ const messagingListProviders = async ({ queries, search, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listProviders'); + } else { + parse(response) + } } - + return response; + } /** @@ -708,6 +748,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 +756,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') { @@ -752,10 +794,10 @@ const messagingCreateApnsProvider = async ({ providerId, name, authKey, authKeyI if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -768,6 +810,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 +818,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') { @@ -809,10 +853,10 @@ const messagingUpdateApnsProvider = async ({ providerId, name, enabled, authKey, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -821,6 +865,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 +873,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') { @@ -853,10 +899,10 @@ const messagingCreateFcmProvider = async ({ providerId, name, serviceAccountJSON if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -865,6 +911,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 +919,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') { @@ -894,10 +942,10 @@ const messagingUpdateFcmProvider = async ({ providerId, name, enabled, serviceAc if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -912,6 +960,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 +968,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') { @@ -962,10 +1012,10 @@ const messagingCreateMailgunProvider = async ({ providerId, name, apiKey, domain if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -980,6 +1030,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 +1038,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') { @@ -1027,10 +1079,10 @@ const messagingUpdateMailgunProvider = async ({ providerId, name, apiKey, domain if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1041,6 +1093,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 +1101,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') { @@ -1079,10 +1133,10 @@ const messagingCreateMsg91Provider = async ({ providerId, name, templateId, send if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1093,6 +1147,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 +1155,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') { @@ -1128,10 +1184,10 @@ const messagingUpdateMsg91Provider = async ({ providerId, name, enabled, templat if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1144,6 +1200,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 +1208,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') { @@ -1188,10 +1246,10 @@ const messagingCreateSendgridProvider = async ({ providerId, name, apiKey, fromN if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1204,6 +1262,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 +1270,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') { @@ -1245,10 +1305,10 @@ const messagingUpdateSendgridProvider = async ({ providerId, name, enabled, apiK if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1267,6 +1327,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 +1335,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') { @@ -1329,10 +1391,10 @@ const messagingCreateSmtpProvider = async ({ providerId, name, host, port, usern if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1351,6 +1413,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 +1421,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') { @@ -1410,10 +1474,10 @@ const messagingUpdateSmtpProvider = async ({ providerId, name, host, port, usern if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1424,6 +1488,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 +1496,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') { @@ -1462,10 +1528,10 @@ const messagingCreateTelesignProvider = async ({ providerId, name, from, custome if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1476,6 +1542,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 +1550,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') { @@ -1511,10 +1579,10 @@ const messagingUpdateTelesignProvider = async ({ providerId, name, enabled, cust if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1525,6 +1593,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 +1601,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') { @@ -1563,10 +1633,10 @@ const messagingCreateTextmagicProvider = async ({ providerId, name, from, userna if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1577,6 +1647,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 +1655,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') { @@ -1612,10 +1684,10 @@ const messagingUpdateTextmagicProvider = async ({ providerId, name, enabled, use if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1626,6 +1698,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 +1706,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') { @@ -1664,10 +1738,10 @@ const messagingCreateTwilioProvider = async ({ providerId, name, from, accountSi if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1678,6 +1752,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 +1760,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') { @@ -1713,10 +1789,10 @@ const messagingUpdateTwilioProvider = async ({ providerId, name, enabled, accoun if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1727,6 +1803,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 +1811,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') { @@ -1765,10 +1843,10 @@ const messagingCreateVonageProvider = async ({ providerId, name, from, apiKey, a if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1779,6 +1857,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 +1865,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') { @@ -1814,15 +1894,16 @@ const messagingUpdateVonageProvider = async ({ providerId, name, enabled, apiKey if (parseOutput) { 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 +1911,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 +1924,21 @@ const messagingGetProvider = async ({ providerId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getProvider', providerId); + } else { + parse(response) + } } - + return response; + } /** * @typedef {Object} MessagingDeleteProviderRequestParams * @property {string} providerId Provider ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -1859,8 +1946,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 = {}; @@ -1872,16 +1960,17 @@ const messagingDeleteProvider = async ({ providerId, parseOutput = true, sdk = u if (parseOutput) { 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 +1978,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') { @@ -1905,16 +1995,17 @@ const messagingListProviderLogs = async ({ providerId, queries, parseOutput = tr if (parseOutput) { 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 +2013,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') { @@ -1938,16 +2030,17 @@ const messagingListSubscriberLogs = async ({ subscriberId, queries, parseOutput if (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 +2048,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 +2067,15 @@ const messagingListTopics = async ({ queries, search, parseOutput = true, sdk = }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listTopics'); + } else { + parse(response) + } } - + return response; + } /** @@ -1985,6 +2083,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 +2091,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') { @@ -2015,15 +2115,16 @@ const messagingCreateTopic = async ({ topicId, name, subscribe, parseOutput = tr if (parseOutput) { 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 +2132,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 +2145,15 @@ const messagingGetTopic = async ({ topicId, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'getTopic', topicId); + } else { + parse(response) + } } - + return response; + } /** @@ -2055,6 +2161,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 +2169,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') { @@ -2082,15 +2190,16 @@ const messagingUpdateTopic = async ({ topicId, name, subscribe, parseOutput = tr if (parseOutput) { 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 +2207,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 = {}; @@ -2111,16 +2221,17 @@ const messagingDeleteTopic = async ({ topicId, parseOutput = true, sdk = undefin if (parseOutput) { 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 +2239,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') { @@ -2144,10 +2256,10 @@ const messagingListTopicLogs = async ({ topicId, queries, parseOutput = true, sd if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -2155,6 +2267,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 +2275,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 +2294,15 @@ const messagingListSubscribers = async ({ topicId, queries, search, parseOutput }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('messaging', 'listSubscribers', topicId); + } else { + parse(response) + } } - + return response; + } /** @@ -2192,6 +2310,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 +2318,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') { @@ -2218,16 +2338,17 @@ const messagingCreateSubscriber = async ({ topicId, subscriberId, targetId, pars if (parseOutput) { 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 +2356,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 = {}; @@ -2248,16 +2370,17 @@ const messagingGetSubscriber = async ({ topicId, subscriberId, parseOutput = tru if (parseOutput) { 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 +2388,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 = {}; @@ -2278,23 +2402,24 @@ const messagingDeleteSubscriber = async ({ topicId, subscriberId, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } 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.`) + .option(`--console`, `Get the resource console url`) .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.`) @@ -2305,13 +2430,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.`) @@ -2321,14 +2446,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.`) @@ -2343,13 +2468,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.`) @@ -2364,410 +2489,417 @@ 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.`) + .option(`--console`, `Get the resource console url`) .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.`) + .option(`--console`, `Get the resource console url`) .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 = { @@ -2818,4 +2950,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..043cad4 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') @@ -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 }) @@ -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') { @@ -69,10 +71,10 @@ const migrationsList = async ({ queries, search, parseOutput = true, sdk = undef if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -81,6 +83,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 +91,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; @@ -114,10 +118,10 @@ const migrationsCreateAppwriteMigration = async ({ resources, endpoint, projectI if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -126,6 +130,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 +138,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') { @@ -158,16 +164,17 @@ const migrationsGetAppwriteReport = async ({ resources, endpoint, projectID, key if (parseOutput) { 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 +182,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; @@ -195,14 +203,15 @@ const migrationsCreateFirebaseMigration = async ({ resources, serviceAccount, pa if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} MigrationsDeleteFirebaseAuthRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -210,8 +219,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 = {}; @@ -223,16 +233,17 @@ const migrationsDeleteFirebaseAuth = async ({ parseOutput = true, sdk = undefine if (parseOutput) { 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 +251,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; @@ -260,14 +272,15 @@ const migrationsCreateFirebaseOAuthMigration = async ({ resources, projectId, pa if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} MigrationsListFirebaseProjectsRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -275,8 +288,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 = {}; @@ -288,16 +302,17 @@ const migrationsListFirebaseProjects = async ({ parseOutput = true, sdk = undefi if (parseOutput) { 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 +320,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') { @@ -324,16 +340,17 @@ const migrationsGetFirebaseReport = async ({ resources, serviceAccount, parseOut if (parseOutput) { 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 +358,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') { @@ -360,10 +378,10 @@ const migrationsGetFirebaseReportOAuth = async ({ resources, projectId, parseOut if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -376,6 +394,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 +402,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; @@ -421,10 +441,10 @@ const migrationsCreateNHostMigration = async ({ resources, subdomain, region, ad if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -437,6 +457,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 +465,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') { @@ -481,10 +503,10 @@ const migrationsGetNHostReport = async ({ resources, subdomain, region, adminSec if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -496,6 +518,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 +526,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; @@ -538,10 +562,10 @@ const migrationsCreateSupabaseMigration = async ({ resources, endpoint, apiKey, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -553,6 +577,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 +585,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') { @@ -594,15 +620,16 @@ const migrationsGetSupabaseReport = async ({ resources, endpoint, apiKey, databa if (parseOutput) { 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 +637,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 = {}; @@ -623,15 +651,16 @@ const migrationsGet = async ({ migrationId, parseOutput = true, sdk = undefined} if (parseOutput) { 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 +668,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 = {}; @@ -652,15 +682,16 @@ const migrationsRetry = async ({ migrationId, parseOutput = true, sdk = undefine if (parseOutput) { 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 +699,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 = {}; @@ -681,10 +713,10 @@ const migrationsDelete = async ({ migrationId, parseOutput = true, sdk = undefin if (parseOutput) { parse(response) - success() } - + return response; + } migrations @@ -695,68 +727,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`) @@ -764,12 +796,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.`) @@ -777,24 +809,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) @@ -803,19 +835,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 = { @@ -836,4 +868,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..1630ee5 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') @@ -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 }) @@ -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') { @@ -73,14 +75,15 @@ const projectGetUsage = async ({ startDate, endDate, period, parseOutput = true, if (parseOutput) { parse(response) - success() } - + return response; + } /** * @typedef {Object} ProjectListVariablesRequestParams + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -88,8 +91,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 = {}; @@ -101,16 +105,17 @@ const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +123,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') { @@ -137,15 +143,16 @@ const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = und if (parseOutput) { 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 +160,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 = {}; @@ -166,10 +174,10 @@ const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefi if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -177,6 +185,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 +193,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') { @@ -203,15 +213,16 @@ const projectUpdateVariable = async ({ variableId, key, value, parseOutput = tru if (parseOutput) { 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 +230,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 = {}; @@ -232,50 +244,50 @@ const projectDeleteVariable = async ({ variableId, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } 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 = { @@ -286,4 +298,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..243f762 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') @@ -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 }) @@ -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,15 @@ const projectsList = async ({ queries, search, parseOutput = true, sdk = undefin }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'list'); + } else { + parse(response) + } } - + return response; + } /** @@ -90,6 +96,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 +104,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') { @@ -149,15 +157,16 @@ const projectsCreate = async ({ projectId, name, teamId, region, description, lo if (parseOutput) { 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 +174,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 +187,15 @@ const projectsGet = async ({ projectId, parseOutput = true, sdk = undefined}) => }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'get', projectId); + } else { + parse(response) + } } - + return response; + } /** @@ -197,6 +211,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 +219,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') { @@ -247,15 +263,16 @@ const projectsUpdate = async ({ projectId, name, description, logo, url, legalNa if (parseOutput) { 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 +280,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 = {}; @@ -276,10 +294,10 @@ const projectsDelete = async ({ projectId, parseOutput = true, sdk = undefined}) if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -287,6 +305,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 +313,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') { @@ -313,16 +333,17 @@ const projectsUpdateApiStatus = async ({ projectId, api, status, parseOutput = t if (parseOutput) { 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 +351,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') { @@ -346,16 +368,17 @@ const projectsUpdateApiStatusAll = async ({ projectId, status, parseOutput = tru if (parseOutput) { 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 +386,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') { @@ -379,16 +403,17 @@ const projectsUpdateAuthDuration = async ({ projectId, duration, parseOutput = t if (parseOutput) { 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 +421,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') { @@ -412,16 +438,17 @@ const projectsUpdateAuthLimit = async ({ projectId, limit, parseOutput = true, s if (parseOutput) { 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 +456,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') { @@ -445,16 +473,53 @@ const projectsUpdateAuthSessionsLimit = async ({ projectId, limit, parseOutput = if (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) + } + + 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 +527,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') { @@ -478,16 +544,17 @@ const projectsUpdateAuthPasswordDictionary = async ({ projectId, enabled, parseO if (parseOutput) { 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 +562,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') { @@ -511,16 +579,17 @@ const projectsUpdateAuthPasswordHistory = async ({ projectId, limit, parseOutput if (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 +597,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') { @@ -544,10 +614,45 @@ const projectsUpdatePersonalDataCheck = async ({ projectId, enabled, parseOutput if (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) + } + + return response; + } /** @@ -555,6 +660,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 +668,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') { @@ -578,15 +685,56 @@ const projectsUpdateAuthStatus = async ({ projectId, method, status, parseOutput if (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) + } + return response; + } /** * @typedef {Object} ProjectsListKeysRequestParams * @property {string} projectId Project unique ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -594,8 +742,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 +755,15 @@ const projectsListKeys = async ({ projectId, parseOutput = true, sdk = undefined }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listKeys', projectId); + } else { + parse(response) + } } - + return response; + } /** @@ -619,6 +772,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 +780,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') { @@ -649,16 +804,17 @@ const projectsCreateKey = async ({ projectId, name, scopes, expire, parseOutput if (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 +822,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 +835,15 @@ 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) + } } - + return response; + } /** @@ -692,6 +853,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 +861,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') { @@ -722,16 +885,17 @@ const projectsUpdateKey = async ({ projectId, keyId, name, scopes, expire, parse if (parseOutput) { 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 +903,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 = {}; @@ -752,10 +917,10 @@ const projectsDeleteKey = async ({ projectId, keyId, parseOutput = true, sdk = u if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -765,6 +930,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 +938,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') { @@ -797,15 +964,16 @@ const projectsUpdateOAuth2 = async ({ projectId, provider, appId, secret, enable if (parseOutput) { 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 +981,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 +994,15 @@ const projectsListPlatforms = async ({ projectId, parseOutput = true, sdk = unde }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listPlatforms', projectId); + } else { + parse(response) + } } - + return response; + } /** @@ -840,6 +1013,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 +1021,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') { @@ -875,16 +1050,17 @@ const projectsCreatePlatform = async ({ projectId, type, name, key, store, hostn if (parseOutput) { 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 +1068,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 +1081,15 @@ const projectsGetPlatform = async ({ projectId, platformId, parseOutput = true, }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'getPlatform', projectId, platformId); + } else { + parse(response) + } } - + return response; + } /** @@ -919,6 +1100,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 +1108,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') { @@ -951,16 +1134,17 @@ const projectsUpdatePlatform = async ({ projectId, platformId, name, key, store, if (parseOutput) { 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 +1152,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 = {}; @@ -981,10 +1166,10 @@ const projectsDeletePlatform = async ({ projectId, platformId, parseOutput = tru if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -992,6 +1177,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 +1185,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') { @@ -1018,16 +1205,17 @@ const projectsUpdateServiceStatus = async ({ projectId, service, status, parseOu if (parseOutput) { 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 +1223,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') { @@ -1051,10 +1240,10 @@ const projectsUpdateServiceStatusAll = async ({ projectId, status, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1069,6 +1258,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 +1266,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') { @@ -1116,10 +1307,10 @@ const projectsUpdateSmtp = async ({ projectId, enabled, senderName, senderEmail, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1134,6 +1325,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 +1333,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; @@ -1182,16 +1375,17 @@ const projectsCreateSmtpTest = async ({ projectId, emails, senderName, senderEma if (parseOutput) { 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 +1393,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') { @@ -1215,10 +1410,10 @@ const projectsUpdateTeam = async ({ projectId, teamId, parseOutput = true, sdk = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1226,6 +1421,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 +1429,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 = {}; @@ -1246,10 +1443,10 @@ const projectsGetEmailTemplate = async ({ projectId, type, locale, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1262,6 +1459,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 +1467,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') { @@ -1297,10 +1496,10 @@ const projectsUpdateEmailTemplate = async ({ projectId, type, locale, subject, m if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1308,6 +1507,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 +1515,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 = {}; @@ -1328,10 +1529,10 @@ const projectsDeleteEmailTemplate = async ({ projectId, type, locale, parseOutpu if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1339,6 +1540,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 +1548,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 = {}; @@ -1359,10 +1562,10 @@ const projectsGetSmsTemplate = async ({ projectId, type, locale, parseOutput = t if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1371,6 +1574,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 +1582,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') { @@ -1394,10 +1599,10 @@ const projectsUpdateSmsTemplate = async ({ projectId, type, locale, message, par if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1405,6 +1610,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 +1618,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 = {}; @@ -1425,15 +1632,16 @@ const projectsDeleteSmsTemplate = async ({ projectId, type, locale, parseOutput if (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 +1649,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 +1662,15 @@ const projectsListWebhooks = async ({ projectId, parseOutput = true, sdk = undef }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'listWebhooks', projectId); + } else { + parse(response) + } } - + return response; + } /** @@ -1470,6 +1683,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 +1691,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') { @@ -1512,16 +1727,17 @@ const projectsCreateWebhook = async ({ projectId, name, events, url, security, e if (parseOutput) { 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 +1745,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 +1758,15 @@ const projectsGetWebhook = async ({ projectId, webhookId, parseOutput = true, sd }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('projects', 'getWebhook', projectId, webhookId); + } else { + parse(response) + } } - + return response; + } /** @@ -1559,6 +1780,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 +1788,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') { @@ -1601,16 +1824,17 @@ const projectsUpdateWebhook = async ({ projectId, webhookId, name, events, url, if (parseOutput) { 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 +1842,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 = {}; @@ -1631,16 +1856,17 @@ const projectsDeleteWebhook = async ({ projectId, webhookId, parseOutput = true, if (parseOutput) { 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 +1874,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 = {}; @@ -1661,10 +1888,10 @@ const projectsUpdateWebhookSignature = async ({ projectId, webhookId, parseOutpu if (parseOutput) { parse(response) - success() } - + return response; + } projects @@ -1672,178 +1899,205 @@ 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>`, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(projectsList)) 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(`updateAuthPasswordDictionary`) + .command(`update-mock-numbers`) + .description(``) + .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(`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(`updateAuthStatus`) + .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(`update-auth-status`) + .description(``) + .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(`listKeys`) + .command(`create-jwt`) + .description(``) + .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(`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.`) @@ -1852,17 +2106,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.`) @@ -1870,35 +2125,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`) @@ -1907,14 +2162,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`) @@ -1922,118 +2177,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 = { @@ -2048,10 +2305,13 @@ module.exports = { projectsUpdateAuthDuration, projectsUpdateAuthLimit, projectsUpdateAuthSessionsLimit, + projectsUpdateMockNumbers, projectsUpdateAuthPasswordDictionary, projectsUpdateAuthPasswordHistory, projectsUpdatePersonalDataCheck, + projectsUpdateSessionAlerts, projectsUpdateAuthStatus, + projectsCreateJWT, projectsListKeys, projectsCreateKey, projectsGetKey, @@ -2080,4 +2340,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..beffbda 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') @@ -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 }) @@ -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') { @@ -69,10 +71,10 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -80,6 +82,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 +90,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') { @@ -109,15 +113,16 @@ const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = if (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 +130,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 = {}; @@ -138,15 +144,16 @@ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +161,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 = {}; @@ -167,15 +175,16 @@ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) = if (parseOutput) { 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 +192,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 = {}; @@ -196,43 +206,43 @@ const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = u if (parseOutput) { parse(response) - success() } - + return response; + } 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 = { @@ -242,4 +252,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..40c07a7 --- /dev/null +++ b/lib/commands/pull.js @@ -0,0 +1,351 @@ +const fs = require("fs"); +const chalk = require('chalk'); +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, functionsGetDeploymentDownload, functionsListDeployments } = require("./functions"); +const { databasesGet, databasesListCollections, databasesList } = require("./databases"); +const { storageListBuckets } = require("./storage"); +const { localConfig } = require("../config"); +const { paginate } = require("../paginate"); +const { questionsPullCollection, questionsPullFunctions, questionsPullFunctionsCode, questionsPullResources } = require("../questions"); +const { cliConfig, success, log, warn, actionRunner, commandDescriptions } = require("../parser"); + +const pullResources = async () => { + const actions = { + settings: pullSettings, + functions: pullFunctions, + collections: pullCollection, + buckets: pullBucket, + teams: pullTeam, + messages: pullMessagingTopic + } + + if (cliConfig.all) { + for (let action of Object.values(actions)) { + cliConfig.all = true; + await action({ returnOnZero: true }); + } + } else { + const answers = await inquirer.prompt(questionsPullResources[0]); + + const action = actions[answers.resource]; + if (action !== undefined) { + await action({ returnOnZero: true }); + } + } +}; + +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(`Successfully pulled ${chalk.bold('all')} project settings.`); + } catch (e) { + throw e; + } +} + +const pullFunctions = async ({ code, withVariables }) => { + process.chdir(localConfig.configDirectoryPath) + + 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; + + 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.name}`; + } + const holdingVars = func['vars']; + // We don't save var in to the config + delete func['vars']; + localConfig.addFunction(func); + + if (!fs.existsSync(func['path'])) { + fs.mkdirSync(func['path'], { recursive: true }); + } + + if (code === false) { + warn("Source code download skipped."); + 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']; + } + + } 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, holdingVars.map(r => `${r.key}=${r.value}\n`).join('')) + } + } + + 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) { + 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 + }); + + total++; + log(`Pulling all collections from ${chalk.bold(database['name'])} database ...`); + + localConfig.addDatabase(database); + + const { collections } = await paginate(databasesListCollections, { + databaseId, + parseOutput: false + }, 100, 'collections'); + + for (const collection of collections) { + localConfig.addCollection({ + ...collection, + '$createdAt': undefined, + '$updatedAt': undefined + }); + } + } + + success(`Successfully pulled ${chalk.bold(total)} collections.`); +} + +const pullBucket = async () => { + log("Fetching buckets ..."); + let total = 0; + + 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; + } + + const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets'); + + 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 () => { + log("Fetching teams ..."); + let total = 0; + + 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; + } + + 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 () => { + 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; + } + + const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics'); + + for (const topic of topics) { + total++; + log(`Pulling topic ${chalk.bold(topic['name'])} ...`); + localConfig.addMessagingTopic(topic); + } + + success(`Successfully pulled ${chalk.bold(total)} topics.`); +} + +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("settings") + .description("Pull your Appwrite project name, services and auth settings") + .action(actionRunner(pullSettings)); + +pull + .command("function") + .alias("functions") + .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)) + +pull + .command("collection") + .alias("collections") + .description("Pull your Appwrite collections") + .action(actionRunner(pullCollection)) + +pull + .command("bucket") + .alias("buckets") + .description("Pull your Appwrite buckets") + .action(actionRunner(pullBucket)) + +pull + .command("team") + .alias("teams") + .description("Pull your Appwrite teams") + .action(actionRunner(pullTeam)) + +pull + .command("topic") + .alias("topics") + .description("Pull your Appwrite messaging topics") + .action(actionRunner(pullMessagingTopic)) + +module.exports = { + pull, + pullResources +}; diff --git a/lib/commands/push.js b/lib/commands/push.js new file mode 100644 index 0000000..e1fd35b --- /dev/null +++ b/lib/commands/push.js @@ -0,0 +1,1732 @@ +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, KeysCollection } = require("../config"); +const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner'); +const { paginate } = require('../paginate'); +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'); +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, + databasesDeleteIndex, + databasesListAttributes, + databasesListIndexes, + databasesUpdateCollection +} = require("./databases"); +const { + storageGetBucket, storageUpdateBucket, storageCreateBucket +} = require("./storage"); +const { + messagingGetTopic, messagingUpdateTopic, messagingCreateTopic +} = require("./messaging"); +const { + teamsGet, + teamsUpdateName, + teamsCreate +} = require("./teams"); +const { + projectsGet, + projectsUpdate, + projectsUpdateServiceStatus, + projectsUpdateAuthStatus, + projectsUpdateAuthDuration, + projectsUpdateAuthLimit, + projectsUpdateAuthSessionsLimit, + projectsUpdateAuthPasswordDictionary, + projectsUpdateAuthPasswordHistory, + projectsUpdatePersonalDataCheck, + projectsUpdateSessionAlerts, + projectsUpdateMockNumbers, +} = require("./projects"); +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 = POLL_DEFAULT_VALUE; + +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; + } + + 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') + } + } + + 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; + } + + 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') + } + } + + 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; + } + + 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') + } + } + + 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; + } + + 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') + } + } + + 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; + } + + 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') + } + } + + 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 + ); + }, + 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; + } + + 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') + } + } + + 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 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 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 ...'); + const changes = []; + + await Promise.all(resource.map(async (localResource) => { + try { + 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 (isEmpty(value) && isEmpty(localResource[key])) { + continue; + } + + 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 ((await getConfirmation()) === true) { + 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': + 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 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: attribute.min, + max: attribute.max, + xdefault: attribute.default, + array: attribute.array, + parseOutput: false + }) + case 'double': + return databasesUpdateFloatAttribute({ + 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 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, 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'], + collectionId: collection['$id'], + key: attribute.key, + parseOutput: 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'; + 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 + * 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 (!KeysAttributes.has(key)) { + continue; + } + + if (changeableKeys.includes(key)) { + if (!recraeting) { + reason += compareAttribute(remote[key], local[key], reason, key) + } + continue; + } + + if (!recraeting) { + continue; + } + + reason += compareAttribute(remote[key], local[key], reason, 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 isn\'t present on the remote server' : 'Field isn\'t present on the appwrite.json file', + action: isAdding ? chalk.green('adding') : chalk.red('deleting') + }; + +}; + +/** + * Filter deleted and recreated attributes, + * return list of attributes to create + * @returns {Promise<*|*[]>} + */ +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)); + 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 && !isIndex) { + log(`Attribute deletion will cause ${chalk.red('loss of data')}`); + } + if (conflicts.length > 0 && !isIndex) { + log(`Attribute recreation will cause ${chalk.red('loss of data')}`); + } + + if ((await getConfirmation()) !== true) { + return changedAttributes; + } + } + + if (conflicts.length > 0) { + changedAttributes = conflicts.map((change) => change.attribute); + 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))); + } + + const deletingAttributes = deleting.map((change) => change.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) { + 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 = { + settings: pushSettings, + 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 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 ((await getConfirmation()) !== true) { + success(`Successfully pushed 0 project settings.`); + return; + } + } + } catch (e) { + } + + try { + log("Pushing project settings ..."); + + const projectId = localConfig.getProject().projectId; + const projectName = localConfig.getProject().projectName; + const settings = localConfig.getProject().projectSettings ?? {}; + + if (projectName) { + log("Applying project name ..."); + await projectsUpdate({ + projectId, + name: projectName, + parseOutput: false + }); + } + + if (settings.services) { + log("Applying 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("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 }); + 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) { + log("Applying auth methods statuses ..."); + + for (let [method, status] of Object.entries(settings.auth.methods)) { + await projectsUpdateAuthStatus({ + projectId, + method, + status, + parseOutput: false + }); + } + } + } + + success(`Successfully pushed ${chalk.bold('all')} project settings.`); + } catch (e) { + throw e; + } +} + +const pushFunction = async ({ functionId, async, code, withVariables } = { returnOnZero: false }) => { + process.chdir(localConfig.configDirectoryPath) + + const functionIds = []; + + if (functionId) { + functionIds.push(functionId); + } else if (cliConfig.all) { + checkDeployConditions(localConfig); + const functions = localConfig.getFunctions(); + functionIds.push(...functions.map((func) => { + return func.$id; + })); + } + + if (functionIds.length <= 0) { + const answers = await inquirer.prompt(questionsPushFunctions[0]); + 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) => { + 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} is missing an entrypoint.`); + const answers = await inquirer.prompt(questionsGetEntrypoint) + func.entrypoint = answers.entrypoint; + localConfig.addFunction(func); + } + } + + if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions', ['vars']))) { + return; + } + + log('Pushing functions ...'); + + Spinner.start(false); + let successfullyPushed = 0; + let successfullyDeployed = 0; + const failedDeployments = []; + const errors = []; + + await Promise.all(functions.map(async (func) => { + let response = {}; + + 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, + scopes: func.scopes, + vars: JSON.stringify(response.vars), + parseOutput: false + }); + } catch (e) { + + if (Number(e.code) === 404) { + functionExists = false; + } else { + errors.push(e); + 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, + 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 + }); + + 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++; + updaterRow.update({ status: 'Pushed' }); + updaterRow.stopSpinner(); + return; + } + + 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) { + errors.push(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) { + 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 * 1.5)); + } + } catch (e) { + errors.push(e); + updaterRow.fail({ errorMessage: e.message ?? 'Unknown error occurred. Please try again' }) + } + } + + updaterRow.stopSpinner(); + })); + + Spinner.stop(); + + failedDeployments.forEach((failed) => { + const { name, deployment, $id } = failed; + 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) { + error('No functions were pushed.'); + } else if (successfullyDeployed !== successfullyPushed) { + warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} functions`) + } else { + success(`Successfully pushed ${successfullyPushed} functions.`); + } + } else { + success(`Successfully pushed ${successfullyPushed} functions.`); + } + + if (cliConfig.verbose) { + errors.forEach(e => { + console.error(e); + }) + } +} + +const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false }) => { + const collections = []; + + if (attempts) { + pollMaxDebounces = attempts; + } + + if (cliConfig.all) { + checkDeployConditions(localConfig); + collections.push(...localConfig.getCollections()); + } else { + 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']))); + + // 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, + }); + } + })); + + + if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) { + return; + } + // 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; + } + } + })) + 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) && (Array.isArray(indexes) && indexes.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(indexes, collection); + } catch (e) { + throw e; + } + numberOfCollections++; + success(`Successfully pushed ${collection.name} ( ${collection['$id']} )`); + } + + success(`Successfully pushed ${numberOfCollections} collections`); +} + +const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let bucketIds = []; + const configBuckets = localConfig.getBuckets(); + + if (cliConfig.all) { + checkDeployConditions(localConfig); + bucketIds.push(...configBuckets.map((b) => b.$id)); + } + + if (bucketIds.length === 0) { + const answers = await inquirer.prompt(questionsPushBuckets[0]) + 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 = []; + + for (const bucketId of bucketIds) { + const idBuckets = configBuckets.filter((b) => b.$id === bucketId); + buckets.push(...idBuckets); + } + + if (!(await approveChanges(buckets, storageGetBucket, KeysStorage, 'bucketId', 'buckets'))) { + return; + } + + log('Pushing buckets ...'); + + for (let bucket of buckets) { + log(`Pushing bucket ${chalk.bold(bucket['name'])} ...`); + + try { + response = await storageGetBucket({ + bucketId: bucket['$id'], + parseOutput: false, + }) + + 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 + }); + } 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 + }) + } else { + throw e; + } + } + } + + success(`Successfully pushed ${buckets.length} buckets.`); +} + +const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let teamIds = []; + const configTeams = localConfig.getTeams(); + + if (cliConfig.all) { + checkDeployConditions(localConfig); + teamIds.push(...configTeams.map((t) => t.$id)); + } + + if (teamIds.length === 0) { + const answers = await inquirer.prompt(questionsPushTeams[0]) + 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 = []; + + for (const teamId of teamIds) { + const idTeams = configTeams.filter((t) => t.$id === teamId); + teams.push(...idTeams); + } + + if (!(await approveChanges(teams, teamsGet, KeysTeams, 'teamId', 'teams'))) { + return; + } + + + log('Pushing teams ...'); + + for (let team of teams) { + log(`Pushing team ${chalk.bold(team['name'])} ...`); + + try { + response = await teamsGet({ + teamId: team['$id'], + parseOutput: false, + }) + + await teamsUpdateName({ + teamId: team['$id'], + name: team.name, + parseOutput: false + }); + } 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 + }) + } else { + throw e; + } + } + } + + success(`Successfully pushed ${teams.length} teams.`); +} + +const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => { + let response = {}; + + let topicsIds = []; + const configTopics = localConfig.getMessagingTopics(); + + if (cliConfig.all) { + checkDeployConditions(localConfig); + topicsIds.push(...configTopics.map((b) => b.$id)); + } + + if (topicsIds.length === 0) { + const answers = await inquirer.prompt(questionsPushMessagingTopics[0]) + 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 = []; + + for (const topicId of topicsIds) { + const idTopic = configTopics.filter((b) => b.$id === topicId); + topics.push(...idTopic); + } + + if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) { + return; + } + + log('Pushing topics ...'); + + for (let topic of topics) { + log(`Pushing topic ${chalk.bold(topic['name'])} ...`); + + try { + response = await messagingGetTopic({ + topicId: topic['$id'], + parseOutput: false + }) + log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`); + + await messagingUpdateTopic({ + topicId: topic['$id'], + name: topic.name, + subscribe: topic.subscribe, + parseOutput: false + }); + } 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; + } + } + } + + success(`Successfully pushed ${topics.length} topics.`); +} + +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("settings") + .description("Push project name, services and auth settings") + .action(actionRunner(pushSettings)); + +push + .command("function") + .alias("functions") + .description("Push functions in the current directory.") + .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 + .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 + .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)); + +const deploy = new Command("deploy") + .description('Removed. Use appwrite push instead') + .action(actionRunner(async () => { + warn("appwrite deploy has been removed. Please use 'appwrite push' instead"); + })); + +module.exports = { + push, + deploy +} diff --git a/lib/commands/run.js b/lib/commands/run.js new file mode 100644 index 0000000..fea72c3 --- /dev/null +++ b/lib/commands/run.js @@ -0,0 +1,330 @@ +const Tail = require('tail').Tail; +const { parse: parseDotenv } = require('dotenv'); +const chalk = require('chalk'); +const ignore = require("ignore"); +const tar = require("tar"); +const fs = require("fs"); +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 { questionsRunFunctions } = require("../questions"); +const { actionRunner, success, log, warn, error, hint, commandDescriptions, drawTable } = require("../parser"); +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, withVariables, reload, 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, + scopes: func.scopes ?? [] + }; + + drawTable([settings]); + 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(func.$id); + + process.on('SIGINT', async () => { + log('Cleaning up ...'); + await dockerCleanup(func.$id); + success("Local function successfully stopped."); + 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 userVariables = {}; + const allVariables = {}; + + if(withVariables) { + try { + const { variables: remoteVariables } = await paginate(functionsListVariables, { + functionId: func['$id'], + parseOutput: false + }, 100, 'variables'); + + remoteVariables.forEach((v) => { + allVariables[v.key] = v.value; + userVariables[v.key] = v.value; + }); + } catch(err) { + warn("Remote variables not fetched. Production environment variables will not be available. 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) => { + allVariables[key] = env[key]; + userVariables[key] = env[key]; + }); + } + + 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 ?? []); + } 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 ?? ''; + headers['x-appwrite-trigger'] = 'http'; + headers['x-appwrite-event'] = ''; + headers['x-appwrite-user-id'] = userId ?? ''; + headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? ''; + allVariables['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) { + process.stdout.write(chalk.white(`${data}\n`)); + }); + new Tail(errorsPath).on("line", function(data) { + process.stdout.write(chalk.white(`${data}\n`)); + }); + + if(reload) { + 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: (xpath) => { + const relativePath = path.relative(functionPath, xpath); + + if(!relativePath) { + return false; + } + return ignorer.ignores(relativePath); + } + }).on('all', async (_event, filePath) => { + Queue.push(filePath); + }); + } + + Queue.events.on('reload', async ({ files }) => { + Queue.lock(); + + try { + await dockerStop(func.$id); + + const dependencyFile = files.find((filePath) => tool.dependencyFiles.includes(filePath)); + if(tool.isCompiled || dependencyFile) { + log(`Rebuilding the function due to file changes ...`); + await dockerBuild(func, allVariables); + + if(!Queue.isEmpty()) { + Queue.unlock(); + return; + } + + await dockerStart(func, allVariables, port); + } else { + log('Hot-swapping function.. Files with change are ' + files.join(', ')); + + 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({ + keep: true, + gzip: true, + sync: true, + cwd: hotSwapPath, + file: buildPath + }); + + const ignorer = ignore(); + 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)); + 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 + }, ['.']); + + await dockerStart(func, allVariables, port); + } + } catch(err) { + console.error(err); + } finally { + Queue.unlock(); + } + }); + + Queue.lock(); + + log('Building function using Docker ...'); + await dockerBuild(func, allVariables); + + if(!Queue.isEmpty()) { + Queue.unlock(); + return; + } + + log('Starting function using Docker ...'); + hint('Function automatically restarts when you edit your code.'); + await dockerStart(func, allVariables, port); + + 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(`--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(`--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)); + +module.exports = { + run +} diff --git a/lib/commands/storage.js b/lib/commands/storage.js index 2358c98..16c2f74 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') @@ -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 }) @@ -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,15 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'listBuckets'); + } else { + parse(response) + } } - + return response; + } /** @@ -87,6 +93,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 +101,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') { @@ -139,15 +147,16 @@ const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity, if (parseOutput) { 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 +164,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 +177,15 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'getBucket', bucketId); + } else { + parse(response) + } } - + return response; + } /** @@ -186,6 +200,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 +208,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') { @@ -235,15 +251,16 @@ const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity, if (parseOutput) { 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 +268,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 = {}; @@ -264,10 +282,10 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -275,6 +293,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 +301,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 +320,24 @@ const storageListFiles = async ({ bucketId, queries, search, parseOutput = true, }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'listFiles', bucketId); + } else { + parse(response) + } } - + 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 +346,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 +368,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut } const size = file.size; - + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -377,7 +403,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut } let uploadableChunkTrimmed; - + if(currentPosition + 1 >= client.CHUNK_SIZE) { uploadableChunkTrimmed = uploadableChunk; } else { @@ -430,10 +456,9 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut await uploadChunk(true); } - + if (parseOutput) { parse(response) - success() } return response; @@ -443,6 +468,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 +476,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 +489,15 @@ 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) + } } - + return response; + } /** @@ -475,6 +506,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 +514,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') { @@ -502,16 +535,17 @@ const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOut if (parseOutput) { 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 +553,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 = {}; @@ -532,16 +567,17 @@ const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = u if (parseOutput) { 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 +586,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 +604,17 @@ 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 +632,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 +641,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 +679,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 +692,24 @@ 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 +718,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 +736,23 @@ 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 +760,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') { @@ -719,16 +777,17 @@ const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => if (parseOutput) { 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 +795,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,122 +811,130 @@ const storageGetBucketUsage = async ({ bucketId, range, parseOutput = true, sdk }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('storage', 'getBucketUsage', bucketId); + } else { + parse(response) + } } - + return response; + } 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.`) + .option(`--console`, `Get the resource console url`) .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(`--file <file>`, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/storage#file-input).`) + .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.`) @@ -875,24 +943,25 @@ 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)) module.exports = { @@ -912,4 +981,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..dda741a 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') @@ -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 }) @@ -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,15 @@ const teamsList = async ({ queries, search, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('teams', 'list'); + } else { + parse(response) + } } - + return response; + } /** @@ -80,6 +86,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 +94,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') { @@ -110,15 +118,16 @@ const teamsCreate = async ({ teamId, name, roles, parseOutput = true, sdk = unde if (parseOutput) { 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 +135,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 +148,22 @@ const teamsGet = async ({ teamId, parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('teams', 'get', teamId); + } else { + parse(response) + } } - + 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 +171,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') { @@ -172,15 +188,16 @@ const teamsUpdateName = async ({ teamId, name, parseOutput = true, sdk = undefin if (parseOutput) { 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 +205,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 = {}; @@ -201,16 +219,17 @@ const teamsDelete = async ({ teamId, parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +237,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') { @@ -234,10 +254,10 @@ const teamsListLogs = async ({ teamId, queries, parseOutput = true, sdk = undefi if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -245,6 +265,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 +273,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') { @@ -271,10 +293,10 @@ const teamsListMemberships = async ({ teamId, queries, search, parseOutput = tru if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -284,8 +306,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 +316,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') { @@ -325,16 +349,17 @@ const teamsCreateMembership = async ({ teamId, roles, email, userId, phone, url, if (parseOutput) { 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 +367,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 = {}; @@ -355,10 +381,10 @@ const teamsGetMembership = async ({ teamId, membershipId, parseOutput = true, sd if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -366,6 +392,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 +400,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; @@ -390,16 +418,17 @@ const teamsUpdateMembership = async ({ teamId, membershipId, roles, parseOutput if (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 +436,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 = {}; @@ -420,10 +450,10 @@ const teamsDeleteMembership = async ({ teamId, membershipId, parseOutput = true, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -432,6 +462,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 +470,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') { @@ -458,15 +490,16 @@ const teamsUpdateMembershipStatus = async ({ teamId, membershipId, userId, secre if (parseOutput) { 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 +507,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 = {}; @@ -487,16 +521,17 @@ const teamsGetPrefs = async ({ teamId, parseOutput = true, sdk = undefined}) => if (parseOutput) { 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 +539,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') { @@ -520,10 +556,10 @@ const teamsUpdatePrefs = async ({ teamId, prefs, parseOutput = true, sdk = undef if (parseOutput) { parse(response) - success() } - + return response; + } teams @@ -531,12 +567,13 @@ 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>`, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(teamsList)) 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)) @@ -544,90 +581,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. 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>`, `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)) @@ -647,4 +685,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..1de7a59 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') @@ -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 }) @@ -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,15 @@ const usersList = async ({ queries, search, parseOutput = true, sdk = undefined} }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'list'); + } else { + parse(response) + } } - + return response; + } /** @@ -82,6 +88,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 +96,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') { @@ -117,10 +125,10 @@ const usersCreate = async ({ userId, email, phone, password, name, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -129,6 +137,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 +145,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') { @@ -161,10 +171,10 @@ const usersCreateArgon2User = async ({ userId, email, password, name, parseOutpu if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -173,6 +183,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 +191,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') { @@ -205,16 +217,17 @@ const usersCreateBcryptUser = async ({ userId, email, password, name, parseOutpu if (parseOutput) { 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 +235,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') { @@ -241,15 +255,16 @@ const usersListIdentities = async ({ queries, search, parseOutput = true, sdk = if (parseOutput) { 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 +272,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 = {}; @@ -270,10 +286,10 @@ const usersDeleteIdentity = async ({ identityId, parseOutput = true, sdk = undef if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -282,6 +298,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 +306,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') { @@ -314,10 +332,10 @@ const usersCreateMD5User = async ({ userId, email, password, name, parseOutput = if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -326,6 +344,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 +352,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') { @@ -358,10 +378,10 @@ const usersCreatePHPassUser = async ({ userId, email, password, name, parseOutpu if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -375,6 +395,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 +403,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') { @@ -422,10 +444,10 @@ const usersCreateScryptUser = async ({ userId, email, password, passwordSalt, pa if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -437,6 +459,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 +467,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') { @@ -478,10 +502,10 @@ const usersCreateScryptModifiedUser = async ({ userId, email, password, password if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -491,6 +515,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 +523,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') { @@ -526,15 +552,16 @@ const usersCreateSHAUser = async ({ userId, email, password, passwordVersion, na if (parseOutput) { 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 +569,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') { @@ -558,15 +586,16 @@ const usersGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +603,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 +616,21 @@ const usersGet = async ({ userId, parseOutput = true, sdk = undefined}) => { }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'get', userId); + } else { + parse(response) + } } - + return response; + } /** * @typedef {Object} UsersDeleteRequestParams * @property {string} userId User ID. + * @property {boolean} overrideForCli * @property {boolean} parseOutput * @property {libClient | undefined} sdk */ @@ -603,8 +638,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 = {}; @@ -616,16 +652,17 @@ const usersDelete = async ({ userId, parseOutput = true, sdk = undefined}) => { if (parseOutput) { 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 +670,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') { @@ -649,16 +687,56 @@ const usersUpdateEmail = async ({ userId, email, parseOutput = true, sdk = undef if (parseOutput) { 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) + } + + 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 +744,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; @@ -683,16 +762,17 @@ const usersUpdateLabels = async ({ userId, labels, parseOutput = true, sdk = und if (parseOutput) { 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 +780,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') { @@ -716,15 +797,16 @@ const usersListLogs = async ({ userId, queries, parseOutput = true, sdk = undefi if (parseOutput) { 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 +814,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 = {}; @@ -745,16 +828,17 @@ const usersListMemberships = async ({ userId, parseOutput = true, sdk = undefine if (parseOutput) { 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 +846,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') { @@ -778,16 +863,17 @@ const usersUpdateMfa = async ({ userId, mfa, parseOutput = true, sdk = undefined if (parseOutput) { 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 +881,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 = {}; @@ -808,15 +895,16 @@ const usersDeleteMfaAuthenticator = async ({ userId, type, parseOutput = true, s if (parseOutput) { 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 +912,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 = {}; @@ -837,15 +926,16 @@ const usersListMfaFactors = async ({ userId, parseOutput = true, sdk = undefined if (parseOutput) { 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 +943,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 = {}; @@ -866,15 +957,16 @@ const usersGetMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = unde if (parseOutput) { 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 +974,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 = {}; @@ -895,15 +988,16 @@ const usersUpdateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u if (parseOutput) { 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 +1005,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 = {}; @@ -924,16 +1019,17 @@ const usersCreateMfaRecoveryCodes = async ({ userId, parseOutput = true, sdk = u if (parseOutput) { 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 +1037,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') { @@ -957,16 +1054,17 @@ const usersUpdateName = async ({ userId, name, parseOutput = true, sdk = undefin if (parseOutput) { 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 +1072,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') { @@ -990,16 +1089,17 @@ const usersUpdatePassword = async ({ userId, password, parseOutput = true, sdk = if (parseOutput) { 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 +1107,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') { @@ -1023,15 +1124,16 @@ const usersUpdatePhone = async ({ userId, number, parseOutput = true, sdk = unde if (parseOutput) { 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 +1141,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 = {}; @@ -1052,16 +1155,17 @@ const usersGetPrefs = async ({ userId, parseOutput = true, sdk = undefined}) => if (parseOutput) { 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 +1173,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') { @@ -1085,15 +1190,16 @@ const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undef if (parseOutput) { 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 +1207,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 +1220,21 @@ const usersListSessions = async ({ userId, parseOutput = true, sdk = undefined}) }, payload); if (parseOutput) { - parse(response) - success() + if(console) { + showConsoleLink('users', 'listSessions', userId); + } else { + parse(response) + } } - + 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 +1242,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 = {}; @@ -1143,15 +1256,16 @@ const usersCreateSession = async ({ userId, parseOutput = true, sdk = undefined} if (parseOutput) { 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 +1273,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 = {}; @@ -1172,16 +1287,17 @@ const usersDeleteSessions = async ({ userId, parseOutput = true, sdk = undefined if (parseOutput) { 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 +1305,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 = {}; @@ -1202,16 +1319,17 @@ const usersDeleteSession = async ({ userId, sessionId, parseOutput = true, sdk = if (parseOutput) { 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 +1337,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') { @@ -1235,16 +1354,17 @@ const usersUpdateStatus = async ({ userId, status, parseOutput = true, sdk = und if (parseOutput) { 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 +1372,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') { @@ -1268,10 +1389,10 @@ const usersListTargets = async ({ userId, queries, parseOutput = true, sdk = und if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1282,6 +1403,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 +1411,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') { @@ -1317,16 +1440,17 @@ const usersCreateTarget = async ({ userId, targetId, providerType, identifier, p if (parseOutput) { 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 +1458,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 = {}; @@ -1347,10 +1472,10 @@ const usersGetTarget = async ({ userId, targetId, parseOutput = true, sdk = unde if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1360,6 +1485,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 +1493,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') { @@ -1389,16 +1516,17 @@ const usersUpdateTarget = async ({ userId, targetId, identifier, providerId, nam if (parseOutput) { 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 +1534,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 = {}; @@ -1419,10 +1548,10 @@ const usersDeleteTarget = async ({ userId, targetId, parseOutput = true, sdk = u if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -1430,6 +1559,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 +1567,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') { @@ -1456,16 +1587,17 @@ const usersCreateToken = async ({ userId, length, expire, parseOutput = true, sd if (parseOutput) { 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 +1605,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') { @@ -1489,16 +1622,17 @@ const usersUpdateEmailVerification = async ({ userId, emailVerification, parseOu if (parseOutput) { 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 +1640,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') { @@ -1522,10 +1657,10 @@ const usersUpdatePhoneVerification = async ({ userId, phoneVerification, parseOu if (parseOutput) { parse(response) - success() } - + return response; + } users @@ -1533,12 +1668,13 @@ 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>`, `Search term to filter your list results. Max length: 256 chars.`) + .option(`--console`, `Get the resource console url`) .action(actionRunner(usersList)) 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.`) @@ -1546,92 +1682,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)) @@ -1639,208 +1775,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(`updateLabels`) + .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(`--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(`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 = { @@ -1860,6 +2006,7 @@ module.exports = { usersGet, usersDelete, usersUpdateEmail, + usersCreateJWT, usersUpdateLabels, usersListLogs, usersListMemberships, @@ -1887,4 +2034,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..a903cae 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') @@ -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 }) @@ -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') { @@ -66,10 +68,10 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true, if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -77,6 +79,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 +87,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') { @@ -103,16 +107,17 @@ const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput if (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 +125,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 = {}; @@ -133,16 +139,17 @@ const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOut if (parseOutput) { 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 +157,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 = {}; @@ -163,10 +171,46 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, if (parseOutput) { 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) + } + + return response; + } /** @@ -174,6 +218,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 +226,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') { @@ -197,10 +243,10 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository if (parseOutput) { parse(response) - success() } - + return response; + } /** @@ -208,6 +254,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 +262,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') { @@ -231,16 +279,17 @@ const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, prov if (parseOutput) { 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 +297,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') { @@ -267,15 +317,16 @@ const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = if (parseOutput) { 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 +334,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 = {}; @@ -296,15 +348,16 @@ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = un if (parseOutput) { 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 +365,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 = {}; @@ -325,74 +379,82 @@ const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = if (parseOutput) { parse(response) - success() } - + return response; + } 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(`createRepositoryDetection`) + .command(`get-repository-contents`) + .description(``) + .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(`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 = { @@ -401,9 +463,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..19190d7 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,6 +4,64 @@ const _path = require("path"); const process = require("process"); const JSONbig = require("json-bigint")({ storeAsString: false }); +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"]); +const KeysTopics = new Set(["$id", "name", "subscribe"]); +const KeysTeams = new Set(["$id", "name"]); +const KeysAttributes = 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", + // Indexes + "attributes", + "orders" +]); +const KeyIndexes = new Set(["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.has(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; @@ -65,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() { @@ -94,6 +168,10 @@ class Local extends Config { } addFunction(props) { + props = whitelistKeys(props, KeysFunction, { + vars: KeysVars + }); + if (!this.has("functions")) { this.set("functions", []); } @@ -101,21 +179,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 +187,9 @@ class Local extends Config { return; } } + + functions.push(props); + this.set("functions", functions); } getCollections() { @@ -149,6 +215,11 @@ class Local extends Config { } addCollection(props) { + props = whitelistKeys(props, KeysCollection, { + attributes: KeysAttributes, + indexes: KeyIndexes + }); + if (!this.has("collections")) { this.set("collections", []); } @@ -188,6 +259,8 @@ class Local extends Config { } addBucket(props) { + props = whitelistKeys(props, KeysStorage); + if (!this.has("buckets")) { this.set("buckets", []); } @@ -204,6 +277,47 @@ 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) { + props = whitelistKeys(props, KeysTopics); + + 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 []; @@ -227,6 +341,8 @@ class Local extends Config { } addDatabase(props) { + props = whitelistKeys(props, KeysDatabase); + if (!this.has("databases")) { this.set("databases", []); } @@ -266,6 +382,7 @@ class Local extends Config { } addTeam(props) { + props = whitelistKeys(props, KeysTeams); if (!this.has("teams")) { this.set("teams", []); } @@ -283,26 +400,77 @@ 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('settings') }; } - 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; + } + + this.set('settings', this.createSettingsObject(projectSettings)); + } + + createSettingsObject(projectSettings) { + return { + 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, + sessionAlerts: projectSettings.authSessionAlerts, + mockNumbers: projectSettings.authMockNumbers + }, + } + }; } } 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 +478,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,63 +490,152 @@ 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(); + } } } module.exports = { localConfig: new Local(), globalConfig: new Global(), + KeysAttributes, + KeysFunction, + KeysTopics, + KeysStorage, + KeysTeams, + KeysCollection, + whitelistKeys }; diff --git a/lib/emulation/docker.js b/lib/emulation/docker.js new file mode 100644 index 0000000..41e39f5 --- /dev/null +++ b/lib/emulation/docker.js @@ -0,0 +1,264 @@ +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, 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], { + stdio: 'pipe', + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } + }); + + await new Promise((res) => { stopProcess.on('close', res) }); +} + +async function dockerPull(func) { + const runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); + const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; + + log('Verifying Docker image ...'); + + const pullProcess = childProcess.spawn('docker', ['pull', imageName], { + stdio: 'pipe', + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } + }); + + await new Promise((res) => { pullProcess.on('close', res) }); +} + +async function dockerBuild(func, variables) { + 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 = 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`); + 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, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } + }); + + buildProcess.stdout.on('data', (data) => { + process.stdout.write(chalk.blackBright(`${data}\n`)); + }); + + buildProcess.stderr.on('data', (data) => { + 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(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)) { + fs.mkdirSync(copyDir, { recursive: true }); + } + + const copyProcess = childProcess.spawn('docker', ['cp', `${id}:/mnt/code/code.tar.gz`, copyPath], { + stdio: 'pipe', + pwd: functionDir, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } + }); + + await new Promise((res) => { copyProcess.on('close', res) }); + + await dockerStop(id); + + const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + 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 runtimeChunks = func.runtime.split("-"); + const runtimeVersion = runtimeChunks.pop(); + const runtimeName = runtimeChunks.join("-"); + const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; + + const tool = systemTools[runtimeName]; + + const id = func.$id; + + const params = [ 'run' ]; + params.push('--rm'); + params.push('--name', id); + params.push('-p', `${port}:3000`); + 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}"`); + + const startProcess = childProcess.spawn('docker', params, { + stdio: 'pipe', + pwd: functionDir, + env: { + ...process.env, + DOCKER_CLI_HINTS: 'false' + } + }); + + startProcess.stdout.on('data', (data) => { + process.stdout.write(chalk.blackBright(data)); + }); + + startProcess.stderr.on('data', (data) => { + 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.`); +} + +async function dockerCleanup(functionId) { + await dockerStop(functionId); + + 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 }); + } + + const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + if (fs.existsSync(tempPath)) { + fs.rmSync(tempPath, { force: true }); + } +} + +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, + dockerStart, + dockerCleanup, + dockerStop, +} diff --git a/lib/emulation/utils.js b/lib/emulation/utils.js new file mode 100644 index 0000000..f32a6b9 --- /dev/null +++ b/lib/emulation/utils.js @@ -0,0 +1,186 @@ +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'; + +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', + 'go': 'Go', +}; + +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" ] + }, + 'go': { + isCompiled: true, + startCommand: "src/function/server", + dependencyFiles: [ ] + }, +}; + +const JwtManager = { + userJwt: null, + functionJwt: null, + + timerWarn: null, + timerError: null, + + async setup(userId = null, projectScopes = []) { + 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, + scopes: projectScopes, + 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; + }, + isEmpty() { + return this.files.length === 0 + }, + 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..1d511e5 100644 --- a/lib/paginate.js +++ b/lib/paginate.js @@ -1,4 +1,4 @@ -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; @@ -10,6 +10,7 @@ const paginate = async (action, args = {}, limit = 100, wrapper = '') => { const response = await action({ ...args, queries: [ + ...queries, JSON.stringify({ method: 'limit', values: [limit] }), JSON.stringify({ method: 'offset', values: [offset] }) ] @@ -48,4 +49,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..6b53ec7 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) => { @@ -82,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]); } @@ -110,17 +107,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 = '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}`; + + const stack = '```\n' + err.stack + '\n```'; - error(err.message); + 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('\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); + } - 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) => { @@ -138,15 +178,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"; @@ -155,37 +203,42 @@ 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.`, - "deploy": `The deploy command provides a convenient wrapper for deploying your functions and collections.`, - "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.`, - "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-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.`, - "console" : `The console command allows gives you access to the APIs used by the Appwrite console.`, + "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 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}`), } module.exports = { + drawTable, parse, actionRunner, parseInteger, parseBool, log, + warn, + hint, success, error, commandDescriptions, - cliConfig -} \ No newline at end of file + cliConfig, + drawTable +} diff --git a/lib/questions.js b/lib/questions.js index 7f26b13..6f72adb 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']; @@ -38,11 +46,11 @@ const getIgnores = (runtime) => { return ['.build', '.swiftpm']; } - return undefined; + return []; }; 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'; @@ -71,13 +80,15 @@ const getEntrypoint = (runtime) => { return 'src/Main.java'; case 'kotlin': return 'src/Main.kt'; + case 'go': + return 'main.go'; } return undefined; }; const getInstallCommand = (runtime) => { - const languge = runtime.split('-')[0]; + const languge = runtime.split("-").slice(0, -1).join("-"); switch (languge) { case 'dart': @@ -91,6 +102,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 +125,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 +133,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] }), + JSON.stringify({ method: 'orderDesc', attribute: '$id' }) + ] + + const { projects } = await paginate(projectsList, { parseOutput: false }, 100, 'projects', queries); + + let choices = projects.map((project) => { return { name: `${project.name} (${project['$id']})`, - value: { - name: project.name, - id: project['$id'] - } + value: project['$id'] } }) @@ -184,11 +207,65 @@ const questionsInitProject = [ } return choices; + }, + 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: `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' } + ] + } +] + +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 questionsPullFunctionsCode = [ + { + type: "confirm", + name: "override", + message: "Do you want to pull source code of the latest deployment?" + }, +]; + +const questionsCreateFunction = [ { type: "input", name: "name", @@ -215,22 +292,158 @@ 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']) }, } }) return choices; + }, + } +]; + +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 questionsInitCollection = [ +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 +465,16 @@ const questionsInitCollection = [ ]; const questionsLogin = [ + { + type: "list", + name: "method", + message: "What you like to do?", + choices: [ + { name: 'Login to an account', value: 'login' }, + { name: 'Switch to an account', value: 'select' } + ], + when: () => globalConfig.getSessions().length >= 2 + }, { type: "input", name: "email", @@ -262,6 +485,7 @@ const questionsLogin = [ } return true; }, + when: (answers) => answers.method !== 'select' }, { type: "password", @@ -273,21 +497,131 @@ 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: `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' } + ] + } +]; + +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), + when: () => localConfig.getFunctions().length > 0, choices: () => { let functions = localConfig.getFunctions(); checkDeployConditions(localConfig) - if (functions.length === 0) { - throw new Error("No functions found in the current directory."); - } let choices = functions.map((func, idx) => { return { name: `${func.name} (${func.$id})`, @@ -297,25 +631,19 @@ const questionsDeployFunctions = [ 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 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), + 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. Run `appwrite init collection` to fetch all your collections."); - } return collections.map(collection => { return { name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`, @@ -323,25 +651,36 @@ const questionsDeployCollections = [ } }); } - }, + } +]; + +const questionPushChanges = [ { 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: `Are you sure you want to apply these changes? (YES/NO)` + } +]; + +const questionPushChangesConfirmation = [ + { + type: "input", + name: "changes", + message: `Please type 'YES' or 'NO':` + } +]; -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), + 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. Run `appwrite init bucket` to fetch all your buckets."); - } + return buckets.map(bucket => { return { name: `${bucket.name} (${bucket['$id']})`, @@ -349,12 +688,27 @@ const questionsDeployBuckets = [ } }); } - }, + } +] + +const questionsPushMessagingTopics = [ { - 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.' - }, + 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(); + + return topics.map(topic => { + return { + name: `${topic.name} (${topic['$id']})`, + value: topic.$id + } + }); + } + } ] const questionsGetEntrypoint = [ @@ -372,17 +726,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), + 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. Run `appwrite init team` to fetch all your teams."); - } + return teams.map(team => { return { name: `${team.name} (${team['$id']})`, @@ -391,43 +745,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 +797,55 @@ 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. 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, + questionsInitProjectAutopull, + questionsCreateFunction, + questionsCreateFunctionSelectTemplate, + questionsCreateBucket, + questionsCreateCollection, + questionsCreateMessagingTopic, + questionsPullFunctions, + questionsPullFunctionsCode, questionsLogin, - questionsInitFunction, - questionsInitCollection, - questionsDeployFunctions, - questionsDeployCollections, - questionsDeployBuckets, - questionsDeployTeams, + questionsPullResources, + questionsLogout, + questionsPullCollection, + questionsPushResources, + questionsPushFunctions, + questionsPushCollections, + questionsPushBuckets, + questionsPushMessagingTopics, + questionsPushTeams, questionsGetEntrypoint, questionsListFactors, - questionsMfaChallenge + questionsMfaChallenge, + questionsRunFunctions, + questionGetEndpoint, + questionsInitResources, + questionsCreateTeam, + questionPushChanges, + questionPushChangesConfirmation }; diff --git a/lib/sdks.js b/lib/sdks.js index fe8afb8..9208e8f 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 project` to initialize the current directory with an Appwrite project."); } diff --git a/lib/spinner.js b/lib/spinner.js new file mode 100644 index 0000000..bcc7e6b --- /dev/null +++ b/lib/spinner.js @@ -0,0 +1,104 @@ +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, + linewrap: 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..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": "5.0.5", + "version": "6.0.0", "license": "BSD-3-Clause", "main": "index.js", "bin": { @@ -24,13 +24,18 @@ "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", + "dotenv": "^16.4.5" }, "devDependencies": { "pkg": "5.8.1" diff --git a/scoop/appwrite.json b/scoop/appwrite.json index 1289e25..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": "5.0.5", + "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/5.0.5/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/5.0.5/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",