appwrite-cli 4.2.0 → 4.2.1

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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors.
1
+ Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
package/README.md CHANGED
@@ -1,7 +1,7 @@
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-1.4.12-blue.svg?style=flat-square)
4
+ ![Version](https://img.shields.io/badge/api%20version-1.4.13-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)
@@ -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
- 4.2.0
32
+ 4.2.1
33
33
  ```
34
34
 
35
35
  ### Install using prebuilt binaries
@@ -63,7 +63,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
63
63
  Once the installation completes, you can verify your install using
64
64
  ```
65
65
  $ appwrite -v
66
- 4.2.0
66
+ 4.2.1
67
67
  ```
68
68
 
69
69
  ## Getting Started
package/install.ps1 CHANGED
@@ -13,8 +13,8 @@
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/4.2.0/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/4.2.0/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/4.2.1/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/4.2.1/appwrite-cli-win-arm64.exe"
18
18
 
19
19
  $APPWRITE_BINARY_NAME = "appwrite.exe"
20
20
 
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="4.2.0"
100
+ GITHUB_LATEST_VERSION="4.2.1"
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,13 +1,12 @@
1
1
  const os = require('os');
2
2
  const https = require("https");
3
- const axios = require("axios");
3
+ const { fetch, FormData, Agent } = require("undici");
4
4
  const JSONbig = require("json-bigint")({ storeAsString: false });
5
- const FormData = require("form-data");
6
5
  const AppwriteException = require("./exception.js");
7
6
  const { globalConfig } = require("./config.js");
8
7
 
9
8
  class Client {
10
- static CHUNK_SIZE = 5*1024*1024; // 5MB
9
+ CHUNK_SIZE = 5*1024*1024; // 5MB
11
10
 
12
11
  constructor() {
13
12
  this.endpoint = 'https://HOSTNAME/v1';
@@ -16,8 +15,8 @@ class Client {
16
15
  'x-sdk-name': 'Command Line',
17
16
  'x-sdk-platform': 'console',
18
17
  'x-sdk-language': 'cli',
19
- 'x-sdk-version': '4.2.0',
20
- 'user-agent' : `AppwriteCLI/4.2.0 (${os.type()} ${os.version()}; ${os.arch()})`,
18
+ 'x-sdk-version': '4.2.1',
19
+ 'user-agent' : `AppwriteCLI/4.2.1 (${os.type()} ${os.version()}; ${os.arch()})`,
21
20
  'X-Appwrite-Response-Format' : '1.4.0',
22
21
  };
23
22
  }
@@ -144,93 +143,81 @@ class Client {
144
143
  return this;
145
144
  }
146
145
 
147
- async call(
148
- method,
149
- path = "",
150
- headers = {},
151
- params = {},
152
- responseType = "json"
153
- ) {
154
- headers = Object.assign({}, this.headers, headers);
146
+ async call(method, path = "", headers = {}, params = {}, responseType = "json") {
147
+ headers = {...this.headers, ...headers};
148
+ const url = new URL(this.endpoint + path);
155
149
 
156
- let contentType = headers["content-type"].toLowerCase();
150
+ let body = undefined;
157
151
 
158
- let formData = null;
152
+ if (method.toUpperCase() === "GET") {
153
+ url.search = new URLSearchParams(Client.flatten(params)).toString();
154
+ } else if (headers["content-type"]?.toLowerCase().startsWith("multipart/form-data")) {
155
+ delete headers["content-type"];
156
+ const formData = new FormData();
159
157
 
160
- if (contentType.startsWith("multipart/form-data")) {
161
- const form = new FormData();
158
+ const flatParams = Client.flatten(params);
162
159
 
163
- let flatParams = Client.flatten(params);
164
-
165
- for (const key in flatParams) {
166
- form.append(key, flatParams[key]);
160
+ for (const [key, value] of Object.entries(flatParams)) {
161
+ if (value && value.type && value.type === "file") {
162
+ formData.append(key, value.file, value.filename);
163
+ } else {
164
+ formData.append(key, value);
165
+ }
167
166
  }
168
167
 
169
- headers = {
170
- ...headers,
171
- ...form.getHeaders(),
172
- };
168
+ body = formData;
169
+ } else {
170
+ body = JSON.stringify(params);
171
+ }
173
172
 
174
- formData = form;
173
+ let response = undefined;
174
+ try {
175
+ response = await fetch(url.toString(), {
176
+ method: method.toUpperCase(),
177
+ headers,
178
+ body,
179
+ dispatcher: new Agent({
180
+ connect: {
181
+ rejectUnauthorized: !this.selfSigned,
182
+ },
183
+ }),
184
+ });
185
+ } catch (error) {
186
+ throw new AppwriteException(error.message);
175
187
  }
176
188
 
177
- let options = {
178
- method: method.toUpperCase(),
179
- url: this.endpoint + path,
180
- params: method.toUpperCase() === "GET" ? params : {},
181
- headers: headers,
182
- data:
183
- method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? formData : params,
184
- json: contentType.startsWith("application/json"),
185
- transformRequest: method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? undefined : (data) => JSONbig.stringify(data),
186
- transformResponse: [ (data) => data ? JSONbig.parse(data) : data ],
187
- responseType: responseType,
188
- };
189
- if (this.selfSigned == true) {
190
- // Allow self signed requests
191
- options.httpsAgent = new https.Agent({ rejectUnauthorized: false });
189
+ if (response.status >= 400) {
190
+ const text = await response.text();
191
+ let json = undefined;
192
+ try {
193
+ json = JSON.parse(text);
194
+ } catch (error) {
195
+ throw new AppwriteException(text, response.status, "", text);
196
+ }
197
+ throw new AppwriteException(json.message, json.code, json.type, json);
192
198
  }
199
+
200
+ if (responseType === "arraybuffer") {
201
+ const data = await response.arrayBuffer();
202
+ return data;
203
+ }
204
+
205
+ const text = await response.text();
206
+ let json = undefined;
193
207
  try {
194
- let response = await axios(options);
195
- if (response.headers["set-cookie"]) {
196
- globalConfig.setCookie(response.headers["set-cookie"][0]);
197
- }
198
- return response.data;
208
+ json = JSON.parse(text);
199
209
  } catch (error) {
200
- if ("response" in error && error.response !== undefined) {
201
- if (error.response && "data" in error.response) {
202
- if (typeof error.response.data === "string") {
203
- throw new AppwriteException(
204
- error.response.data,
205
- error.response.status,
206
- error.response.data
207
- );
208
- } else {
209
- throw new AppwriteException(
210
- error.response.data.message,
211
- error.response.status,
212
- error.response.data
213
- );
214
- }
215
- } else {
216
- throw new AppwriteException(
217
- error.response.statusText,
218
- error.response.status,
219
- error.response.data
220
- );
221
- }
222
- } else {
223
- throw new AppwriteException(error.message);
224
- }
210
+ return text;
225
211
  }
212
+ return json;
226
213
  }
227
214
 
228
- static flatten(data, prefix = "") {
215
+ static flatten(data, prefix = '') {
229
216
  let output = {};
230
217
 
231
218
  for (const key in data) {
232
219
  let value = data[key];
233
- let finalKey = prefix ? prefix + "[" + key + "]" : key;
220
+ let finalKey = prefix ? prefix + '[' + key +']' : key;
234
221
 
235
222
  if (Array.isArray(value)) {
236
223
  output = Object.assign(output, Client.flatten(value, finalKey)); // @todo: handle name collision here if needed
@@ -243,4 +230,4 @@ class Client {
243
230
  }
244
231
  }
245
232
 
246
- module.exports = Client;
233
+ module.exports = Client;