appwrite-cli 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Appwrite Command Line SDK
2
2
 
3
3
  ![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square)
4
- ![Version](https://img.shields.io/badge/api%20version-0.13.0-blue.svg?style=flat-square)
4
+ ![Version](https://img.shields.io/badge/api%20version-0.14.0-blue.svg?style=flat-square)
5
5
  [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
6
6
  [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
7
7
  [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
8
8
 
9
- **This SDK is compatible with Appwrite server version 0.13.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
9
+ **This SDK is compatible with Appwrite server version 0.14.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
10
10
 
11
11
  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)
12
12
 
@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
29
29
 
30
30
  ```sh
31
31
  $ appwrite -v
32
- 0.16.0
32
+ 0.17.0
33
33
  ```
34
34
 
35
35
  ### Install using prebuilt binaries
@@ -58,7 +58,7 @@ $ iwr -useb https://appwrite.io/cli/install.ps1 | iex
58
58
  Once the installation completes, you can verify your install using
59
59
  ```
60
60
  $ appwrite -v
61
- 0.16.0
61
+ 0.17.0
62
62
  ```
63
63
 
64
64
  ## Getting Started
@@ -0,0 +1 @@
1
+ appwrite account updateStatus
@@ -0,0 +1,4 @@
1
+ appwrite teams listLogs \
2
+ --teamId [TEAM_ID] \
3
+
4
+
@@ -0,0 +1,2 @@
1
+ appwrite users getMemberships \
2
+ --userId [USER_ID]
package/install.ps1 CHANGED
@@ -13,14 +13,17 @@
13
13
  # You can use "View source" of this page to see the full script.
14
14
 
15
15
  # REPO
16
- $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.16.0/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.16.0/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.17.0/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.17.0/appwrite-cli-win-arm64.exe"
18
+
19
+ $APPWRITE_BINARY_NAME = "appwrite.exe"
18
20
 
19
21
  # Appwrite download directory
20
- $APPWRITE_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath "appwrite.exe"
22
+ $APPWRITE_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath $APPWRITE_BINARY_NAME
21
23
 
22
24
  # Appwrite CLI location
23
25
  $APPWRITE_INSTALL_DIR = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Appwrite"
26
+ $APPWRITE_INSTALL_PATH = Join-Path -Path "$APPWRITE_INSTALL_DIR" -ChildPath "$APPWRITE_BINARY_NAME"
24
27
 
25
28
  $USER_PATH_ENV_VAR = [Environment]::GetEnvironmentVariable("PATH", "User")
26
29
 
@@ -58,9 +61,9 @@ function DownloadBinary {
58
61
  } else {
59
62
  Invoke-WebRequest -Uri $GITHUB_x64_URL -OutFile $APPWRITE_DOWNLOAD_DIR
60
63
  }
61
-
62
64
 
63
- Move-Item $APPWRITE_DOWNLOAD_DIR $APPWRITE_INSTALL_DIR
65
+ New-Item -ItemType Directory -Path $APPWRITE_INSTALL_DIR
66
+ Move-Item $APPWRITE_DOWNLOAD_DIR $APPWRITE_INSTALL_PATH
64
67
  }
65
68
 
66
69
 
@@ -71,6 +74,7 @@ function Install {
71
74
  Write-Host "Skipping to add Appwrite to User Path."
72
75
  } else {
73
76
  [System.Environment]::SetEnvironmentVariable("PATH", $USER_PATH_ENV_VAR + ";$APPWRITE_INSTALL_DIR", "User")
77
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
74
78
  }
75
79
  }
76
80
 
package/install.sh CHANGED
@@ -97,7 +97,7 @@ printSuccess() {
97
97
  downloadBinary() {
98
98
  echo "[2/4] Downloading executable for $OS ($ARCH) ..."
99
99
 
100
- GITHUB_LATEST_VERSION="0.16.0"
100
+ GITHUB_LATEST_VERSION="0.17.0"
101
101
  GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102
102
  GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103
103
 
package/lib/client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const os = require('os');
2
2
  const axios = require("axios");
3
+ const JSONbig = require("json-bigint")({ storeAsString: false });
3
4
  const FormData = require("form-data");
4
5
  const AppwriteException = require("./exception.js");
5
6
  const { globalConfig } = require("./config.js");
@@ -11,9 +12,9 @@ class Client {
11
12
  this.endpoint = 'https://HOSTNAME/v1';
12
13
  this.headers = {
13
14
  'content-type': '',
14
- 'x-sdk-version': 'appwrite:cli:0.16.0',
15
- 'User-Agent' : `AppwriteCLI/0.16.0 (${os.type()} ${os.version()}; ${os.arch()})`,
16
- 'X-Appwrite-Response-Format' : '0.13.0',
15
+ 'x-sdk-version': 'appwrite:cli:0.17.0',
16
+ 'User-Agent' : `AppwriteCLI/0.17.0 (${os.type()} ${os.version()}; ${os.arch()})`,
17
+ 'X-Appwrite-Response-Format' : '0.14.0',
17
18
  };
18
19
  }
19
20
 
@@ -180,11 +181,9 @@ class Client {
180
181
  params: method.toUpperCase() === "GET" ? params : {},
181
182
  headers: headers,
182
183
  data:
183
- method.toUpperCase() === "GET" ||
184
- contentType.startsWith("multipart/form-data")
185
- ? formData
186
- : params,
184
+ method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? formData : params,
187
185
  json: contentType.startsWith("application/json"),
186
+ transformRequest: method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? undefined : (data) => JSONbig.stringify(data),
188
187
  responseType: responseType,
189
188
  };
190
189
  try {
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -65,23 +68,6 @@ const accountCreate = async ({ userId, email, password, name, parseOutput = true
65
68
  return response;
66
69
  }
67
70
 
68
- const accountDelete = async ({ parseOutput = true, sdk = undefined}) => {
69
-
70
- let client = !sdk ? await sdkForProject() : sdk;
71
- let path = '/account';
72
- let payload = {};
73
- let response = undefined;
74
- response = await client.call('delete', path, {
75
- 'content-type': 'application/json',
76
- }, payload);
77
-
78
- if (parseOutput) {
79
- parse(response)
80
- success()
81
- }
82
- return response;
83
- }
84
-
85
71
  const accountUpdateEmail = async ({ email, password, parseOutput = true, sdk = undefined}) => {
86
72
  /* @param {string} email */
87
73
  /* @param {string} password */
@@ -546,6 +532,23 @@ const accountDeleteSession = async ({ sessionId, parseOutput = true, sdk = undef
546
532
  return response;
547
533
  }
548
534
 
535
+ const accountUpdateStatus = async ({ parseOutput = true, sdk = undefined}) => {
536
+
537
+ let client = !sdk ? await sdkForProject() : sdk;
538
+ let path = '/account/status';
539
+ let payload = {};
540
+ let response = undefined;
541
+ response = await client.call('patch', path, {
542
+ 'content-type': 'application/json',
543
+ }, payload);
544
+
545
+ if (parseOutput) {
546
+ parse(response)
547
+ success()
548
+ }
549
+ return response;
550
+ }
551
+
549
552
  const accountCreateVerification = async ({ url, parseOutput = true, sdk = undefined}) => {
550
553
  /* @param {string} url */
551
554
 
@@ -614,11 +617,6 @@ account
614
617
  .option(`--name <name>`, `User name. Max length: 128 chars.`)
615
618
  .action(actionRunner(accountCreate))
616
619
 
617
- account
618
- .command(`delete`)
619
- .description(`Delete a currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. This is done to avoid deleted accounts being overtaken by new users with the same email address. Any user-related resources like documents or storage files should be deleted separately.`)
620
- .action(actionRunner(accountDelete))
621
-
622
620
  account
623
621
  .command(`updateEmail`)
624
622
  .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. `)
@@ -646,7 +644,7 @@ account
646
644
 
647
645
  account
648
646
  .command(`updatePassword`)
649
- .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 and Team Invites, oldPassword is optional.`)
647
+ .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.`)
650
648
  .requiredOption(`--password <password>`, `New user password. Must be at least 8 chars.`)
651
649
  .option(`--oldPassword <oldPassword>`, `Current user password. Must be at least 8 chars.`)
652
650
  .action(actionRunner(accountUpdatePassword))
@@ -718,10 +716,10 @@ account
718
716
  account
719
717
  .command(`createOAuth2Session`)
720
718
  .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.. `)
721
- .requiredOption(`--provider <provider>`, `OAuth2 Provider. Currently, supported providers are: amazon, apple, bitbucket, bitly, box, discord, dropbox, facebook, github, gitlab, google, linkedin, microsoft, notion, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, vk, yahoo, yammer, yandex, wordpress, stripe.`)
719
+ .requiredOption(`--provider <provider>`, `OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, bitbucket, bitly, box, discord, dropbox, facebook, github, gitlab, google, linkedin, microsoft, notion, okta, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, zoom, yahoo, yammer, yandex, wordpress, stripe.`)
722
720
  .option(`--success <success>`, `URL to redirect back to your app after a successful login attempt. 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.`)
723
721
  .option(`--failure <failure>`, `URL to redirect back to your app after a failed login attempt. 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.`)
724
- .option(`--scopes <scopes...>`, `A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.`)
722
+ .option(`--scopes <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 128 characters long.`)
725
723
  .action(actionRunner(accountCreateOAuth2Session))
726
724
 
727
725
  account
@@ -732,7 +730,7 @@ account
732
730
 
733
731
  account
734
732
  .command(`updateSession`)
735
- .description(``)
733
+ .description(`Access tokens have limited lifespan and expire to mitigate security risks. If session was created using an OAuth provider, this route can be used to "refresh" the access token.`)
736
734
  .requiredOption(`--sessionId <sessionId>`, `Session ID. Use the string 'current' to update the current device session.`)
737
735
  .action(actionRunner(accountUpdateSession))
738
736
 
@@ -742,6 +740,11 @@ account
742
740
  .requiredOption(`--sessionId <sessionId>`, `Session ID. Use the string 'current' to delete the current device session.`)
743
741
  .action(actionRunner(accountDeleteSession))
744
742
 
743
+ account
744
+ .command(`updateStatus`)
745
+ .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.`)
746
+ .action(actionRunner(accountUpdateStatus))
747
+
745
748
  account
746
749
  .command(`createVerification`)
747
750
  .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](/docs/client/account#accountUpdateVerification). 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. `)
@@ -760,7 +763,6 @@ module.exports = {
760
763
  account,
761
764
  accountGet,
762
765
  accountCreate,
763
- accountDelete,
764
766
  accountUpdateEmail,
765
767
  accountCreateJWT,
766
768
  accountGetLogs,
@@ -780,6 +782,7 @@ module.exports = {
780
782
  accountGetSession,
781
783
  accountUpdateSession,
782
784
  accountDeleteSession,
785
+ accountUpdateStatus,
783
786
  accountCreateVerification,
784
787
  accountUpdateVerification
785
788
  };
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -271,7 +274,7 @@ const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true,
271
274
 
272
275
  avatars
273
276
  .command(`getBrowser`)
274
- .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 /account/sessions endpoint. Use width, height and quality arguments to change the output settings.`)
277
+ .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](/docs/client/account#accountGetSessions) 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.`)
275
278
  .requiredOption(`--code <code>`, `Browser Code.`)
276
279
  .option(`--width <width>`, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
277
280
  .option(`--height <height>`, `Image height. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
@@ -281,7 +284,7 @@ avatars
281
284
 
282
285
  avatars
283
286
  .command(`getCreditCard`)
284
- .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.`)
287
+ .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. `)
285
288
  .requiredOption(`--code <code>`, `Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.`)
286
289
  .option(`--width <width>`, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
287
290
  .option(`--height <height>`, `Image height. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
@@ -298,7 +301,7 @@ avatars
298
301
 
299
302
  avatars
300
303
  .command(`getFlag`)
301
- .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.`)
304
+ .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. 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. `)
302
305
  .requiredOption(`--code <code>`, `Country Code. ISO Alpha-2 country code format.`)
303
306
  .option(`--width <width>`, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
304
307
  .option(`--height <height>`, `Image height. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
@@ -308,16 +311,16 @@ avatars
308
311
 
309
312
  avatars
310
313
  .command(`getImage`)
311
- .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.`)
314
+ .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. `)
312
315
  .requiredOption(`--url <url>`, `Image URL which you want to crop.`)
313
- .option(`--width <width>`, `Resize preview image width, Pass an integer between 0 to 2000.`, parseInteger)
314
- .option(`--height <height>`, `Resize preview image height, Pass an integer between 0 to 2000.`, parseInteger)
316
+ .option(`--width <width>`, `Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400.`, parseInteger)
317
+ .option(`--height <height>`, `Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400.`, parseInteger)
315
318
  .requiredOption(`--destination <path>`, `output file path.`)
316
319
  .action(actionRunner(avatarsGetImage))
317
320
 
318
321
  avatars
319
322
  .command(`getInitials`)
320
- .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.`)
323
+ .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. `)
321
324
  .option(`--name <name>`, `Full Name. When empty, current user name or email will be used. Max length: 128 chars.`)
322
325
  .option(`--width <width>`, `Image width. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
323
326
  .option(`--height <height>`, `Image height. Pass an integer between 0 to 2000. Defaults to 100.`, parseInteger)
@@ -328,9 +331,9 @@ avatars
328
331
 
329
332
  avatars
330
333
  .command(`getQR`)
331
- .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.`)
334
+ .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. `)
332
335
  .requiredOption(`--text <text>`, `Plain text to be converted to QR code image.`)
333
- .option(`--size <size>`, `QR code size. Pass an integer between 0 to 1000. Defaults to 400.`, parseInteger)
336
+ .option(`--size <size>`, `QR code size. Pass an integer between 1 to 1000. Defaults to 400.`, parseInteger)
334
337
  .option(`--margin <margin>`, `Margin from edge. Pass an integer between 0 to 10. Defaults to 1.`, parseInteger)
335
338
  .option(`--download <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.`, parseBool)
336
339
  .requiredOption(`--destination <path>`, `output file path.`)
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -962,7 +965,7 @@ database
962
965
  .description(`Create a new Collection.`)
963
966
  .requiredOption(`--collectionId <collectionId>`, `Unique Id. Choose your own unique ID or pass the string "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.`)
964
967
  .requiredOption(`--name <name>`, `Collection name. Max length: 128 chars.`)
965
- .requiredOption(`--permission <permission>`, `Permissions type model to use for reading documents in this collection. You can use collection-level permission set once on the collection using the 'read' and 'write' params, or you can set document-level permission where each document read and write params will decide who has access to read and write to each document individually. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
968
+ .requiredOption(`--permission <permission>`, `Specifies the permissions model used in this collection, which accepts either 'collection' or 'document'. For 'collection' level permission, the permissions specified in read and write params are applied to all documents in the collection. For 'document' level permissions, read and write permissions are specified in each document. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
966
969
  .requiredOption(`--read <read...>`, `An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
967
970
  .requiredOption(`--write <write...>`, `An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
968
971
  .action(actionRunner(databaseCreateCollection))
@@ -1021,7 +1024,7 @@ database
1021
1024
  .description(``)
1022
1025
  .requiredOption(`--collectionId <collectionId>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).`)
1023
1026
  .requiredOption(`--key <key>`, `Attribute Key.`)
1024
- .requiredOption(`--elements <elements...>`, `Array of elements in enumerated type. Uses length of longest element to determine size.`)
1027
+ .requiredOption(`--elements <elements...>`, `Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 1024 characters long.`)
1025
1028
  .requiredOption(`--required <required>`, `Is attribute required?`, parseBool)
1026
1029
  .option(`--xdefault <xdefault>`, `Default value for attribute when not provided. Cannot be set when attribute is required.`)
1027
1030
  .option(`--array <array>`, `Is attribute an array?`, parseBool)
@@ -1100,13 +1103,13 @@ database
1100
1103
  .command(`listDocuments`)
1101
1104
  .description(`Get a list of all the user documents. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's documents. [Learn more about different API modes](/docs/admin).`)
1102
1105
  .requiredOption(`--collectionId <collectionId>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).`)
1103
- .option(`--queries <queries...>`, `Array of query strings.`)
1106
+ .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/database#querying-documents). Maximum of 100 queries are allowed, each 128 characters long.`)
1104
1107
  .option(`--limit <limit>`, `Maximum number of documents to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.`, parseInteger)
1105
1108
  .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
1106
1109
  .option(`--cursor <cursor>`, `ID of the document used as the starting point for the query, excluding the document itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination)`)
1107
1110
  .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor.`)
1108
- .option(`--orderAttributes <orderAttributes...>`, `Array of attributes used to sort results.`)
1109
- .option(`--orderTypes <orderTypes...>`, `Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order.`)
1111
+ .option(`--orderAttributes <orderAttributes...>`, `Array of attributes used to sort results. Maximum of 100 order attributes are allowed, each 128 characters long.`)
1112
+ .option(`--orderTypes <orderTypes...>`, `Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order. Maximum of 100 order types are allowed.`)
1110
1113
  .action(actionRunner(databaseListDocuments))
1111
1114
 
1112
1115
  database
@@ -1131,14 +1134,14 @@ database
1131
1134
  .description(`Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.`)
1132
1135
  .requiredOption(`--collectionId <collectionId>`, `Collection ID.`)
1133
1136
  .requiredOption(`--documentId <documentId>`, `Document ID.`)
1134
- .requiredOption(`--data <data>`, `Document data as JSON object.`)
1137
+ .requiredOption(`--data <data>`, `Document data as JSON object. Include only attribute and value pairs to be updated.`)
1135
1138
  .option(`--read <read...>`, `An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
1136
1139
  .option(`--write <write...>`, `An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
1137
1140
  .action(actionRunner(databaseUpdateDocument))
1138
1141
 
1139
1142
  database
1140
1143
  .command(`deleteDocument`)
1141
- .description(`Delete a document by its unique ID. This endpoint deletes only the parent documents, its attributes and relations to other documents. Child documents **will not** be deleted.`)
1144
+ .description(`Delete a document by its unique ID.`)
1142
1145
  .requiredOption(`--collectionId <collectionId>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).`)
1143
1146
  .requiredOption(`--documentId <documentId>`, `Document ID.`)
1144
1147
  .action(actionRunner(databaseDeleteDocument))
@@ -1164,8 +1167,8 @@ database
1164
1167
  .requiredOption(`--collectionId <collectionId>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).`)
1165
1168
  .requiredOption(`--key <key>`, `Index Key.`)
1166
1169
  .requiredOption(`--type <type>`, `Index type.`)
1167
- .requiredOption(`--attributes <attributes...>`, `Array of attributes to index.`)
1168
- .option(`--orders <orders...>`, `Array of index orders.`)
1170
+ .requiredOption(`--attributes <attributes...>`, `Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long.`)
1171
+ .option(`--orders <orders...>`, `Array of index orders. Maximum of 100 orders are allowed.`)
1169
1172
  .action(actionRunner(databaseCreateIndex))
1170
1173
 
1171
1174
  database
@@ -1,4 +1,5 @@
1
1
  const inquirer = require("inquirer");
2
+ const JSONbig = require("json-bigint")({ storeAsString: false });
2
3
  const { Command } = require("commander");
3
4
  const { localConfig } = require("../config");
4
5
  const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections } = require("../questions");
@@ -167,7 +168,7 @@ const deployFunction = async () => {
167
168
  functionId: func['$id'],
168
169
  name: func.name,
169
170
  execute: func.execute,
170
- vars: response.vars,
171
+ vars: JSON.stringify(response.vars),
171
172
  events: func.events,
172
173
  schedule: func.schedule,
173
174
  timeout: func.timeout,
@@ -181,7 +182,7 @@ const deployFunction = async () => {
181
182
  name: func.name,
182
183
  runtime: func.runtime,
183
184
  execute: func.execute,
184
- vars: func.vars,
185
+ vars: JSON.stringify(func.vars),
185
186
  events: func.events,
186
187
  schedule: func.schedule,
187
188
  timeout: func.timeout,
@@ -319,7 +320,7 @@ const createAttribute = async (collectionId, attribute) => {
319
320
  const deployCollection = async () => {
320
321
  let response = {};
321
322
  let answers = await inquirer.prompt(questionsDeployCollections[0])
322
- let collections = answers.collections
323
+ let collections = answers.collections.map((collection) => JSONbig.parse(collection));
323
324
 
324
325
  for (let collection of collections) {
325
326
  log(`Deploying collection ${collection.name} ( ${collection['$id']} )`)
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -277,13 +280,27 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
277
280
  if (!fs.lstatSync(folderPath).isDirectory())
278
281
  throw new Error('The path is not a directory.');
279
282
 
283
+ const ignorer = ignore();
284
+
285
+ const func = localConfig.getFunction(functionId);
286
+
287
+ if(func.ignore) {
288
+ ignorer.add(func.ignore);
289
+ log('Ignoring files using configuration from appwrite.json');
290
+ } else if(fs.existsSync(pathLib.join(code, '.gitignore'))) {
291
+ ignorer.add(fs.readFileSync(pathLib.join(code, '.gitignore')).toString());
292
+ log('Ignoring files in .gitignore');
293
+ }
294
+
295
+ const files = getAllFiles(code).map((file) => pathLib.relative(code, file)).filter((file) => !ignorer.ignores(file));
296
+
280
297
  await tar
281
298
  .create({
282
299
  gzip: true,
283
300
  sync: true,
284
301
  cwd: folderPath,
285
302
  file: 'code.tar.gz'
286
- }, ['./'])
303
+ }, files);
287
304
  let archivePath = fs.realpathSync('code.tar.gz')
288
305
  if (typeof archivePath !== 'undefined') {
289
306
  payload['code'] = archivePath;
@@ -568,10 +585,10 @@ functions
568
585
  .description(`Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.`)
569
586
  .requiredOption(`--functionId <functionId>`, `Function ID. Choose your own unique ID or pass the string "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.`)
570
587
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
571
- .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
588
+ .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.`)
572
589
  .requiredOption(`--runtime <runtime>`, `Execution runtime.`)
573
590
  .option(`--vars <vars>`, `Key-value JSON object that will be passed to the function as environment variables.`)
574
- .option(`--events <events...>`, `Events list.`)
591
+ .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
575
592
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
576
593
  .option(`--timeout <timeout>`, `Function maximum execution time in seconds.`, parseInteger)
577
594
  .action(actionRunner(functionsCreate))
@@ -592,9 +609,9 @@ functions
592
609
  .description(`Update function by its unique ID.`)
593
610
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
594
611
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
595
- .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.`)
612
+ .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.`)
596
613
  .option(`--vars <vars>`, `Key-value JSON object that will be passed to the function as environment variables.`)
597
- .option(`--events <events...>`, `Events list.`)
614
+ .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
598
615
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
599
616
  .option(`--timeout <timeout>`, `Maximum execution time in seconds.`, parseInteger)
600
617
  .action(actionRunner(functionsUpdate))
@@ -1,5 +1,6 @@
1
1
  const inquirer = require("inquirer");
2
2
  const { Command } = require("commander");
3
+ const Client = require("../client");
3
4
  const { sdkForConsole } = require("../sdks");
4
5
  const { globalConfig, localConfig } = require("../config");
5
6
  const { actionRunner, success, parseBool, commandDescriptions, log, parse } = require("../parser");
@@ -65,13 +66,19 @@ const client = new Command("client")
65
66
  if (endpoint !== undefined) {
66
67
  try {
67
68
  let url = new URL(endpoint);
68
- if (url.protocol === "http:" || url.protocol === "https:") {
69
- globalConfig.setEndpoint(endpoint);
70
- } else {
69
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
71
70
  throw new Error();
72
71
  }
72
+
73
+ let client = new Client().setEndpoint(endpoint);
74
+ let response = await client.call('GET', '/health/version');
75
+ if(!response.version) {
76
+ throw new Error();
77
+ }
78
+
79
+ globalConfig.setEndpoint(endpoint);
73
80
  } catch (_) {
74
- throw new Error("Invalid endpoint");
81
+ throw new Error("Invalid endpoint or your Appwrite server is not running as expected.");
75
82
  }
76
83
  }
77
84
 
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -128,23 +131,6 @@ const healthGetQueueLogs = async ({ parseOutput = true, sdk = undefined}) => {
128
131
  return response;
129
132
  }
130
133
 
131
- const healthGetQueueUsage = async ({ parseOutput = true, sdk = undefined}) => {
132
-
133
- let client = !sdk ? await sdkForProject() : sdk;
134
- let path = '/health/queue/usage';
135
- let payload = {};
136
- let response = undefined;
137
- response = await client.call('get', path, {
138
- 'content-type': 'application/json',
139
- }, payload);
140
-
141
- if (parseOutput) {
142
- parse(response)
143
- success()
144
- }
145
- return response;
146
- }
147
-
148
134
  const healthGetQueueWebhooks = async ({ parseOutput = true, sdk = undefined}) => {
149
135
 
150
136
  let client = !sdk ? await sdkForProject() : sdk;
@@ -232,11 +218,6 @@ health
232
218
  .description(`Get the number of logs that are waiting to be processed in the Appwrite internal queue server.`)
233
219
  .action(actionRunner(healthGetQueueLogs))
234
220
 
235
- health
236
- .command(`getQueueUsage`)
237
- .description(`Get the number of usage stats that are waiting to be processed in the Appwrite internal queue server.`)
238
- .action(actionRunner(healthGetQueueUsage))
239
-
240
221
  health
241
222
  .command(`getQueueWebhooks`)
242
223
  .description(`Get the number of webhooks that are waiting to be processed in the Appwrite internal queue server.`)
@@ -262,7 +243,6 @@ module.exports = {
262
243
  healthGetQueueCertificates,
263
244
  healthGetQueueFunctions,
264
245
  healthGetQueueLogs,
265
- healthGetQueueUsage,
266
246
  healthGetQueueWebhooks,
267
247
  healthGetStorageLocal,
268
248
  healthGetTime
@@ -99,6 +99,7 @@ const initFunction = async () => {
99
99
  runtime: response.runtime,
100
100
  path: `functions/${answers.name}`,
101
101
  entrypoint: answers.runtime.entrypoint || '',
102
+ ignore: answers.runtime.ignore || null,
102
103
  execute: response.execute,
103
104
  events: response.events,
104
105
  schedule: response.schedule,
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -1018,7 +1021,7 @@ projects
1018
1021
  .description(``)
1019
1022
  .requiredOption(`--projectId <projectId>`, `Project unique ID.`)
1020
1023
  .requiredOption(`--name <name>`, `Key name. Max length: 128 chars.`)
1021
- .requiredOption(`--scopes <scopes...>`, `Key scopes list.`)
1024
+ .requiredOption(`--scopes <scopes...>`, `Key scopes list. Maximum of 100 scopes are allowed.`)
1022
1025
  .action(actionRunner(projectsCreateKey))
1023
1026
 
1024
1027
  projects
@@ -1034,7 +1037,7 @@ projects
1034
1037
  .requiredOption(`--projectId <projectId>`, `Project unique ID.`)
1035
1038
  .requiredOption(`--keyId <keyId>`, `Key unique ID.`)
1036
1039
  .requiredOption(`--name <name>`, `Key name. Max length: 128 chars.`)
1037
- .requiredOption(`--scopes <scopes...>`, `Key scopes list`)
1040
+ .requiredOption(`--scopes <scopes...>`, `Key scopes list. Maximum of 100 events are allowed.`)
1038
1041
  .action(actionRunner(projectsUpdateKey))
1039
1042
 
1040
1043
  projects
@@ -1121,7 +1124,7 @@ projects
1121
1124
  .description(``)
1122
1125
  .requiredOption(`--projectId <projectId>`, `Project unique ID.`)
1123
1126
  .requiredOption(`--name <name>`, `Webhook name. Max length: 128 chars.`)
1124
- .requiredOption(`--events <events...>`, `Events list.`)
1127
+ .requiredOption(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
1125
1128
  .requiredOption(`--url <url>`, `Webhook URL.`)
1126
1129
  .requiredOption(`--security <security>`, `Certificate verification, false for disabled or true for enabled.`, parseBool)
1127
1130
  .option(`--httpUser <httpUser>`, `Webhook HTTP user. Max length: 256 chars.`)
@@ -1141,7 +1144,7 @@ projects
1141
1144
  .requiredOption(`--projectId <projectId>`, `Project unique ID.`)
1142
1145
  .requiredOption(`--webhookId <webhookId>`, `Webhook unique ID.`)
1143
1146
  .requiredOption(`--name <name>`, `Webhook name. Max length: 128 chars.`)
1144
- .requiredOption(`--events <events...>`, `Events list.`)
1147
+ .requiredOption(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
1145
1148
  .requiredOption(`--url <url>`, `Webhook URL.`)
1146
1149
  .requiredOption(`--security <security>`, `Certificate verification, false for disabled or true for enabled.`, parseBool)
1147
1150
  .option(`--httpUser <httpUser>`, `Webhook HTTP user. Max length: 256 chars.`)
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -620,7 +623,7 @@ storage
620
623
  .option(`--write <write...>`, `An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.`)
621
624
  .option(`--enabled <enabled>`, `Is bucket enabled?`, parseBool)
622
625
  .option(`--maximumFileSize <maximumFileSize>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB. For self-hosted setups you can change the max limit by changing the '_APP_STORAGE_LIMIT' environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)`, parseInteger)
623
- .option(`--allowedFileExtensions <allowedFileExtensions...>`, `Allowed file extensions`)
626
+ .option(`--allowedFileExtensions <allowedFileExtensions...>`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`)
624
627
  .option(`--encryption <encryption>`, `Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled`, parseBool)
625
628
  .option(`--antivirus <antivirus>`, `Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled`, parseBool)
626
629
  .action(actionRunner(storageCreateBucket))
@@ -641,7 +644,7 @@ storage
641
644
  .option(`--write <write...>`, `An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.`)
642
645
  .option(`--enabled <enabled>`, `Is bucket enabled?`, parseBool)
643
646
  .option(`--maximumFileSize <maximumFileSize>`, `Maximum file size allowed in bytes. Maximum allowed value is 30MB. For self hosted version you can change the limit by changing _APP_STORAGE_LIMIT environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)`, parseInteger)
644
- .option(`--allowedFileExtensions <allowedFileExtensions...>`, `Allowed file extensions`)
647
+ .option(`--allowedFileExtensions <allowedFileExtensions...>`, `Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.`)
645
648
  .option(`--encryption <encryption>`, `Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled`, parseBool)
646
649
  .option(`--antivirus <antivirus>`, `Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled`, parseBool)
647
650
  .action(actionRunner(storageUpdateBucket))
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -147,6 +150,34 @@ const teamsDelete = async ({ teamId, parseOutput = true, sdk = undefined}) => {
147
150
  return response;
148
151
  }
149
152
 
153
+ const teamsListLogs = async ({ teamId, limit, offset, parseOutput = true, sdk = undefined}) => {
154
+ /* @param {string} teamId */
155
+ /* @param {number} limit */
156
+ /* @param {number} offset */
157
+
158
+ let client = !sdk ? await sdkForProject() : sdk;
159
+ let path = '/teams/{teamId}/logs'.replace('{teamId}', teamId);
160
+ let payload = {};
161
+
162
+ /** Query Params */
163
+ if (typeof limit !== 'undefined') {
164
+ payload['limit'] = limit;
165
+ }
166
+ if (typeof offset !== 'undefined') {
167
+ payload['offset'] = offset;
168
+ }
169
+ let response = undefined;
170
+ response = await client.call('get', path, {
171
+ 'content-type': 'application/json',
172
+ }, payload);
173
+
174
+ if (parseOutput) {
175
+ parse(response)
176
+ success()
177
+ }
178
+ return response;
179
+ }
180
+
150
181
  const teamsGetMemberships = async ({ teamId, search, limit, offset, cursor, cursorDirection, orderType, parseOutput = true, sdk = undefined}) => {
151
182
  /* @param {string} teamId */
152
183
  /* @param {string} search */
@@ -343,7 +374,7 @@ teams
343
374
  .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.`)
344
375
  .requiredOption(`--teamId <teamId>`, `Team ID. Choose your own unique ID or pass the string "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.`)
345
376
  .requiredOption(`--name <name>`, `Team name. Max length: 128 chars.`)
346
- .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](/docs/permissions). Max length for each role is 32 chars.`)
377
+ .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](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.`)
347
378
  .action(actionRunner(teamsCreate))
348
379
 
349
380
  teams
@@ -365,6 +396,14 @@ teams
365
396
  .requiredOption(`--teamId <teamId>`, `Team ID.`)
366
397
  .action(actionRunner(teamsDelete))
367
398
 
399
+ teams
400
+ .command(`listLogs`)
401
+ .description(`Get the team activity logs list by its unique ID.`)
402
+ .requiredOption(`--teamId <teamId>`, `Team ID.`)
403
+ .option(`--limit <limit>`, `Maximum number of logs to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.`, parseInteger)
404
+ .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
405
+ .action(actionRunner(teamsListLogs))
406
+
368
407
  teams
369
408
  .command(`getMemberships`)
370
409
  .description(`Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint.`)
@@ -382,7 +421,7 @@ teams
382
421
  .description(`Invite a new member to join your team. If initiated from the client SDK, an email with a link to join the team will be sent to the member's email address and an account will be created for them should they not be signed up already. If initiated from server-side SDKs, the new member will automatically be added to the team. Use the 'url' parameter to redirect the user from the invitation email back to your app. When the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) 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) the only valid redirect URL's are the once from domains you have set when adding your platforms in the console interface.`)
383
422
  .requiredOption(`--teamId <teamId>`, `Team ID.`)
384
423
  .requiredOption(`--email <email>`, `Email of the new team member.`)
385
- .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](/docs/permissions). Max length for each role is 32 chars.`)
424
+ .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](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.`)
386
425
  .requiredOption(`--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.`)
387
426
  .option(`--name <name>`, `Name of the new team member. Max length: 128 chars.`)
388
427
  .action(actionRunner(teamsCreateMembership))
@@ -399,7 +438,7 @@ teams
399
438
  .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](/docs/permissions).`)
400
439
  .requiredOption(`--teamId <teamId>`, `Team ID.`)
401
440
  .requiredOption(`--membershipId <membershipId>`, `Membership ID.`)
402
- .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). Max length for each role is 32 chars.`)
441
+ .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.`)
403
442
  .action(actionRunner(teamsUpdateMembershipRoles))
404
443
 
405
444
  teams
@@ -426,6 +465,7 @@ module.exports = {
426
465
  teamsGet,
427
466
  teamsUpdate,
428
467
  teamsDelete,
468
+ teamsListLogs,
429
469
  teamsGetMemberships,
430
470
  teamsCreateMembership,
431
471
  teamsGetMembership,
@@ -1,7 +1,10 @@
1
1
  const fs = require('fs');
2
+ const pathLib = require('path');
2
3
  const tar = require("tar");
4
+ const ignore = require("ignore");
3
5
  const { promisify } = require('util');
4
6
  const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
5
8
  const { Command } = require('commander');
6
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
7
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -207,6 +210,24 @@ const usersGetLogs = async ({ userId, limit, offset, parseOutput = true, sdk = u
207
210
  return response;
208
211
  }
209
212
 
213
+ const usersGetMemberships = async ({ userId, parseOutput = true, sdk = undefined}) => {
214
+ /* @param {string} userId */
215
+
216
+ let client = !sdk ? await sdkForProject() : sdk;
217
+ let path = '/users/{userId}/memberships'.replace('{userId}', userId);
218
+ let payload = {};
219
+ let response = undefined;
220
+ response = await client.call('get', path, {
221
+ 'content-type': 'application/json',
222
+ }, payload);
223
+
224
+ if (parseOutput) {
225
+ parse(response)
226
+ success()
227
+ }
228
+ return response;
229
+ }
230
+
210
231
  const usersUpdateName = async ({ userId, name, parseOutput = true, sdk = undefined}) => {
211
232
  /* @param {string} userId */
212
233
  /* @param {string} name */
@@ -441,7 +462,7 @@ users
441
462
 
442
463
  users
443
464
  .command(`delete`)
444
- .description(`Delete a user by its unique ID.`)
465
+ .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](/docs/server/users#usersUpdateStatus) endpoint instead.`)
445
466
  .requiredOption(`--userId <userId>`, `User ID.`)
446
467
  .action(actionRunner(usersDelete))
447
468
 
@@ -460,6 +481,12 @@ users
460
481
  .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
461
482
  .action(actionRunner(usersGetLogs))
462
483
 
484
+ users
485
+ .command(`getMemberships`)
486
+ .description(`Get the user membership list by its unique ID.`)
487
+ .requiredOption(`--userId <userId>`, `User ID.`)
488
+ .action(actionRunner(usersGetMemberships))
489
+
463
490
  users
464
491
  .command(`updateName`)
465
492
  .description(`Update the user name by its unique ID.`)
@@ -508,7 +535,7 @@ users
508
535
 
509
536
  users
510
537
  .command(`updateStatus`)
511
- .description(`Update the user status by its unique ID.`)
538
+ .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.`)
512
539
  .requiredOption(`--userId <userId>`, `User ID.`)
513
540
  .requiredOption(`--status <status>`, `User Status. To activate the user pass 'true' and to block the user pass 'false'.`, parseBool)
514
541
  .action(actionRunner(usersUpdateStatus))
@@ -530,6 +557,7 @@ module.exports = {
530
557
  usersDelete,
531
558
  usersUpdateEmail,
532
559
  usersGetLogs,
560
+ usersGetMemberships,
533
561
  usersUpdateName,
534
562
  usersUpdatePassword,
535
563
  usersGetPrefs,
package/lib/config.js CHANGED
@@ -2,6 +2,7 @@ const os = require('os');
2
2
  const fs = require("fs");
3
3
  const _path = require("path");
4
4
  const process = require("process");
5
+ const JSONbig = require("json-bigint")({ storeAsString: false });
5
6
 
6
7
  class Config {
7
8
  constructor(path) {
@@ -11,7 +12,8 @@ class Config {
11
12
 
12
13
  read() {
13
14
  try {
14
- this.data = require(this.path);
15
+ const file = fs.readFileSync(this.path).toString();
16
+ this.data = JSONbig.parse(file);
15
17
  } catch (e) {
16
18
  // console.log(`${this.path} not found. Empty data`);
17
19
  this.data = {};
@@ -23,7 +25,7 @@ class Config {
23
25
  if (!fs.existsSync(dir)){
24
26
  fs.mkdirSync(dir, { recursive: true });
25
27
  }
26
- fs.writeFileSync(this.path, JSON.stringify(this.data, null, 4));
28
+ fs.writeFileSync(this.path, JSONbig.stringify(this.data, null, 4));
27
29
  }
28
30
 
29
31
  get(key) {
@@ -46,7 +48,7 @@ class Config {
46
48
  }
47
49
 
48
50
  has(key) {
49
- return this.data.hasOwnProperty(key);
51
+ return this.data[key] !== undefined;
50
52
  }
51
53
 
52
54
  keys() {
@@ -58,7 +60,7 @@ class Config {
58
60
  }
59
61
 
60
62
  toString() {
61
- return JSON.stringify(this.data, null, 4);
63
+ return JSONbig.stringify(this.data, null, 4);
62
64
  }
63
65
  }
64
66
 
package/lib/questions.js CHANGED
@@ -1,6 +1,39 @@
1
1
  const { localConfig } = require('./config');
2
2
  const { projectsList } = require('./commands/projects');
3
3
  const { functionsListRuntimes } = require('./commands/functions');
4
+ const JSONbig = require("json-bigint")({ storeAsString: false });
5
+
6
+ const getIgnores = (runtime) => {
7
+ const languge = runtime.split('-')[0];
8
+
9
+ switch (languge) {
10
+ case 'cpp':
11
+ return ['build', 'CMakeFiles', 'CMakeCaches.txt'];
12
+ case 'dart':
13
+ return ['.packages', '.dart_tool'];
14
+ case 'deno':
15
+ return [];
16
+ case 'dotnet':
17
+ return ['bin', 'obj', '.nuget'];
18
+ case 'java':
19
+ case 'kotlin':
20
+ return ['build'];
21
+ case 'node':
22
+ return ['node_modules', '.npm'];
23
+ case 'php':
24
+ return ['vendor'];
25
+ case 'python':
26
+ return ['__pypackages__'];
27
+ case 'ruby':
28
+ return ['vendor'];
29
+ case 'rust':
30
+ return ['target', 'debug', '*.rs.bk', '*.pdb'];
31
+ case 'swift':
32
+ return ['.build', '.swiftpm'];
33
+ }
34
+
35
+ return undefined;
36
+ };
4
37
 
5
38
  const getEntrypoint = (runtime) => {
6
39
  const languge = runtime.split('-')[0];
@@ -117,7 +150,7 @@ const questionsInitFunction = [
117
150
  let choices = runtimes.map((runtime, idx) => {
118
151
  return {
119
152
  name: `${runtime.name} (${runtime['$id']})`,
120
- value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id'])}
153
+ value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id']), ignore: getIgnores(runtime['$id'])},
121
154
  }
122
155
  })
123
156
  return choices;
@@ -185,7 +218,7 @@ const questionsDeployCollections = [
185
218
  let choices = collections.map((collection, idx) => {
186
219
  return {
187
220
  name: `${collection.name} (${collection['$id']})`,
188
- value: collection
221
+ value: JSONbig.stringify(collection)
189
222
  }
190
223
  })
191
224
  return choices;
package/lib/sdks.js CHANGED
@@ -7,7 +7,23 @@ const questionGetEndpoint = [
7
7
  type: "input",
8
8
  name: "endpoint",
9
9
  message: "Enter the endpoint of your Appwrite server",
10
- default: "http://localhost/v1"
10
+ default: "http://localhost/v1",
11
+ async validate(value) {
12
+ if (!value) {
13
+ return "Please enter a valid endpoint.";
14
+ }
15
+ let client = new Client().setEndpoint(value);
16
+ try {
17
+ let response = await client.call('get', '/health/version');
18
+ if (response.version) {
19
+ return true;
20
+ } else {
21
+ throw new Error();
22
+ }
23
+ } catch (error) {
24
+ return "Invalid endpoint or your Appwrite server is not running as expected.";
25
+ }
26
+ }
11
27
  }
12
28
  ]
13
29
 
package/lib/utils.js ADDED
@@ -0,0 +1,19 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ function getAllFiles(folder) {
5
+ const files = [];
6
+ for(const pathDir of fs.readdirSync(folder)) {
7
+ const pathAbsolute = path.join(folder, pathDir);
8
+ if (fs.statSync(pathAbsolute).isDirectory()) {
9
+ files.push(...getAllFiles(pathAbsolute));
10
+ } else {
11
+ files.push(pathAbsolute);
12
+ }
13
+ }
14
+ return files;
15
+ }
16
+
17
+ module.exports = {
18
+ getAllFiles
19
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "appwrite-cli",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "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",
5
- "version": "0.16.0",
5
+ "version": "0.17.0",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "index.js",
8
8
  "bin": {
@@ -22,13 +22,15 @@
22
22
  "windows-arm64": "pkg -t node16-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
23
23
  },
24
24
  "dependencies": {
25
- "axios": "^0.26.1",
25
+ "axios": "^0.27.2",
26
26
  "chalk": "4.1.2",
27
- "cli-table3": "^0.6.1",
28
- "commander": "^9.0.0",
27
+ "cli-table3": "^0.6.2",
28
+ "commander": "^9.2.0",
29
29
  "form-data": "^4.0.0",
30
- "inquirer": "^8.2.1",
31
- "tar": "^6.1.11"
30
+ "json-bigint": "^1.0.0",
31
+ "inquirer": "^8.2.4",
32
+ "tar": "^6.1.11",
33
+ "ignore": "^5.2.0"
32
34
  },
33
35
  "devDependencies": {
34
36
  "pkg": "5.5.1"
@@ -1 +0,0 @@
1
- appwrite account delete
@@ -1 +0,0 @@
1
- appwrite health getQueueUsage