Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.6.x #138

Merged
merged 18 commits into from
Aug 27, 2024
Merged

1.6.x #138

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/account/delete-mfa-authenticator.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
appwrite account deleteMfaAuthenticator \
--type totp \
--otp <OTP>
--type totp
2 changes: 1 addition & 1 deletion docs/examples/functions/create-build.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
appwrite functions createBuild \
--functionId <FUNCTION_ID> \
--deploymentId <DEPLOYMENT_ID> \
--buildId <BUILD_ID>

1 change: 1 addition & 0 deletions docs/examples/functions/create-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ appwrite functions createExecution \




2 changes: 2 additions & 0 deletions docs/examples/functions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ appwrite functions create \





3 changes: 3 additions & 0 deletions docs/examples/functions/delete-execution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appwrite functions deleteExecution \
--functionId <FUNCTION_ID> \
--executionId <EXECUTION_ID>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
appwrite functions downloadDeployment \
appwrite functions getDeploymentDownload \
--functionId <FUNCTION_ID> \
--deploymentId <DEPLOYMENT_ID>
2 changes: 2 additions & 0 deletions docs/examples/functions/get-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
appwrite functions getTemplate \
--templateId <TEMPLATE_ID>
1 change: 1 addition & 0 deletions docs/examples/functions/list-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
appwrite functions listSpecifications
5 changes: 5 additions & 0 deletions docs/examples/functions/list-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
appwrite functions listTemplates \




3 changes: 3 additions & 0 deletions docs/examples/functions/update-deployment-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appwrite functions updateDeploymentBuild \
--functionId <FUNCTION_ID> \
--deploymentId <DEPLOYMENT_ID>
2 changes: 2 additions & 0 deletions docs/examples/functions/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ appwrite functions update \





4 changes: 4 additions & 0 deletions docs/examples/projects/create-j-w-t.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appwrite projects createJWT \
--projectId <PROJECT_ID> \
--scopes one two three \

3 changes: 3 additions & 0 deletions docs/examples/projects/update-mock-numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appwrite projects updateMockNumbers \
--projectId <PROJECT_ID> \
--numbers one two three
3 changes: 3 additions & 0 deletions docs/examples/projects/update-session-alerts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appwrite projects updateSessionAlerts \
--projectId <PROJECT_ID> \
--alerts false
4 changes: 4 additions & 0 deletions docs/examples/users/create-j-w-t.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appwrite users createJWT \
--userId <USER_ID> \


4 changes: 4 additions & 0 deletions docs/examples/vcs/get-repository-contents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appwrite vcs getRepositoryContents \
--installationId <INSTALLATION_ID> \
--providerRepositoryId <PROVIDER_REPOSITORY_ID> \

45 changes: 37 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand All @@ -72,5 +101,5 @@ program
.addCommand(vcs)
.addCommand(client)
.parse(process.argv);
process.stdout.columns = oldWidth;

process.stdout.columns = oldWidth;
6 changes: 3 additions & 3 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'"
}


Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ 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 = {
'content-type': '',
'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',
};
}

Expand Down Expand Up @@ -167,7 +168,7 @@ class Client {

body = formData;
} else {
body = JSON.stringify(params);
body = JSONbig.stringify(params);
}

let response = undefined;
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand Down
Loading