diff --git a/example.php b/example.php index bcfdc2c5f..a9e158e73 100644 --- a/example.php +++ b/example.php @@ -42,7 +42,7 @@ function getSSLPage($url) { $platform = 'console'; // $platform = 'server'; - $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.5.x/app/config/specs/swagger2-latest-{$platform}.json"); + $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.6.x/app/config/specs/swagger2-latest-{$platform}.json"); if(empty($spec)) { throw new Exception('Failed to fetch spec from Appwrite server'); diff --git a/templates/cli/index.js.twig b/templates/cli/index.js.twig index 39882577f..596d1b864 100644 --- a/templates/cli/index.js.twig +++ b/templates/cli/index.js.twig @@ -12,7 +12,7 @@ const { commandDescriptions, cliConfig } = require("./lib/parser"); const { client } = require("./lib/commands/generic"); const inquirer = require("inquirer"); {% if sdk.test != "true" %} -const { login, logout, whoami, migrate } = require("./lib/commands/generic"); +const { login, logout, whoami, migrate, register } = require("./lib/commands/generic"); const { init } = require("./lib/commands/init"); const { pull } = require("./lib/commands/pull"); const { run } = require("./lib/commands/run"); @@ -62,6 +62,7 @@ program .showSuggestionAfterError() {% if sdk.test != "true" %} .addCommand(whoami) + .addCommand(register) .addCommand(login) .addCommand(init) .addCommand(pull) diff --git a/templates/cli/lib/commands/generic.js.twig b/templates/cli/lib/commands/generic.js.twig index 1a258d664..6d237e3a7 100644 --- a/templates/cli/lib/commands/generic.js.twig +++ b/templates/cli/lib/commands/generic.js.twig @@ -81,6 +81,9 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => { } 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; } } @@ -128,6 +131,12 @@ const whoami = new Command("whoami") drawTable(data) })); +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`) @@ -299,6 +308,7 @@ module.exports = { {% if sdk.test != "true" %} loginCommand, whoami, + register, login, logout, {% endif %} diff --git a/templates/cli/lib/commands/init.js.twig b/templates/cli/lib/commands/init.js.twig index 9b8db081c..f0293da5e 100644 --- a/templates/cli/lib/commands/init.js.twig +++ b/templates/cli/lib/commands/init.js.twig @@ -53,16 +53,16 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => { answers.project = {}; answers.organization = {}; - answers.organization.id = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization; + answers.organization = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization; answers.project.name = projectName ?? (await inquirer.prompt(questionsInitProject[3])).project; - answers.project.id = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id; + 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.id; + answers.id = answers.project; answers.project = answers.project.name; } else { throw e; @@ -74,13 +74,13 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => { response = await projectsCreate({ projectId: answers.id, name: answers.project, - teamId: answers.organization.id, + teamId: answers.organization, parseOutput: false }) localConfig.setProject(response['$id']); } else { - localConfig.setProject(answers.project.id); + localConfig.setProject(answers.project); } success(); @@ -273,6 +273,7 @@ const initFunction = async () => { localConfig.addFunction(data); success(); + log(`* Use 'appwrite dev function' for local development\n${' '.repeat(7)}* Use 'appwrite push functions' to push the function to your {{ spec.title|caseUcfirst }} instance`) } const init = new Command("init") diff --git a/templates/cli/lib/commands/run.js.twig b/templates/cli/lib/commands/run.js.twig index 593bd5a84..e5574396d 100644 --- a/templates/cli/lib/commands/run.js.twig +++ b/templates/cli/lib/commands/run.js.twig @@ -55,7 +55,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = } if(!port) { - let portFound = fale; + let portFound = false; port = 3000; while(port < 3100) { const taken = await isPortTaken(port); @@ -194,7 +194,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = await dockerStart(func, variables, port); } else { log('Hot-swapping function files ...'); - + const functionPath = path.join(process.cwd(), func.path); const hotSwapPath = path.join(functionPath, '.appwrite/hot-swap'); const buildPath = path.join(functionPath, '.appwrite/build.tar.gz'); @@ -226,7 +226,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = const filePath = path.join(hotSwapPath, f); if (fs.existsSync(filePath)) { fs.rmSync(filePath, { force: true }); - } + } const fileDir = path.dirname(filePath); if (!fs.existsSync(fileDir)) { @@ -244,7 +244,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = cwd: hotSwapPath, file: buildPath }, ['.']); - + fs.rmSync(hotSwapPath, { recursive: true, force: true }); await dockerStart(func, variables, port); diff --git a/templates/cli/lib/config.js.twig b/templates/cli/lib/config.js.twig index c454a2558..f4f152a15 100644 --- a/templates/cli/lib/config.js.twig +++ b/templates/cli/lib/config.js.twig @@ -333,13 +333,16 @@ class Local extends Config { }; } - setProject(projectId, projectName = '', projectSettings = {}) { + setProject(projectId, projectName = '', projectSettings = undefined) { this.set("projectId", projectId); if (projectName !== '') { this.set("projectName", projectName); } + if (projectSettings === undefined) { + return; + } const settings = { services: { @@ -414,8 +417,10 @@ class Global extends Config { return this.get(Global.PREFERENCE_CURRENT); } - setCurrentSession(endpoint) { - this.set(Global.PREFERENCE_CURRENT, endpoint); + setCurrentSession(session) { + if (session !== undefined) { + this.set(Global.PREFERENCE_CURRENT, session); + } } getSessionIds() { diff --git a/templates/cli/lib/emulation/docker.js.twig b/templates/cli/lib/emulation/docker.js.twig index 08544ad97..fe5033955 100644 --- a/templates/cli/lib/emulation/docker.js.twig +++ b/templates/cli/lib/emulation/docker.js.twig @@ -1,3 +1,11 @@ +const childProcess = require('child_process'); +const { localConfig } = require("../config"); +const path = require('path'); +const fs = require('fs'); +const { log,success } = require("../parser"); +const { openRuntimesVersion, systemTools } = require("./utils"); +const ID = require("../id"); + const activeDockerIds = {}; async function dockerStop(id) { diff --git a/templates/cli/lib/emulation/utils.js.twig b/templates/cli/lib/emulation/utils.js.twig index eefa096b6..d36d5cda0 100644 --- a/templates/cli/lib/emulation/utils.js.twig +++ b/templates/cli/lib/emulation/utils.js.twig @@ -1,4 +1,7 @@ const EventEmitter = require('node:events'); +const { projectsCreateJWT } = require('../commands/projects'); +const { localConfig } = require("../config"); + const openRuntimesVersion = 'v3'; diff --git a/templates/cli/lib/parser.js.twig b/templates/cli/lib/parser.js.twig index 44451e814..12358131e 100644 --- a/templates/cli/lib/parser.js.twig +++ b/templates/cli/lib/parser.js.twig @@ -222,6 +222,7 @@ const commandDescriptions = { "login": `The login command allows you to authenticate and manage a user account.`, "logout": `The logout command allows you to logout of your {{ spec.title|caseUcfirst }} account.`, "whoami": `The whoami command gives information about the currently logged in user.`, + "register": `Outputs the link to create an {{ spec.title|caseUcfirst }} account..`, "console" : `The console command allows gives you access to the APIs used by the Appwrite console.`, "assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`, "messaging": `The messaging command allows you to send messages.`, diff --git a/templates/cli/lib/questions.js.twig b/templates/cli/lib/questions.js.twig index 17417a3b6..e0afdffbc 100644 --- a/templates/cli/lib/questions.js.twig +++ b/templates/cli/lib/questions.js.twig @@ -155,15 +155,12 @@ const questionsInitProject = [ let choices = teams.map((team, idx) => { return { name: `${team.name} (${team['$id']})`, - value: { - name: team.name, - id: team['$id'] - } + value: team['$id'] } }) if (choices.length == 0) { - throw new Error("No organizations found. Please create a new organization.") + throw new Error(`No organizations found. Please create a new organization at ${globalConfig.getEndpoint().replace('/v1', '/console/onboarding')}`) } return choices; @@ -199,10 +196,7 @@ const questionsInitProject = [ let choices = projects.map((project) => { return { name: `${project.name} (${project['$id']})`, - value: { - name: project.name, - id: project['$id'] - } + value: project['$id'] } }) @@ -781,7 +775,7 @@ const questionsRunFunctions = [ choices: () => { let functions = localConfig.getFunctions(); if (functions.length === 0) { - throw new Error("No functions found in the current directory."); + throw new Error("No functions found in the current directory. Use 'appwrite init function' to create one"); } let choices = functions.map((func, idx) => { return {