appwrite-cli 8.2.0 → 8.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.
@@ -41,7 +41,7 @@ jobs:
41
41
  npm publish
42
42
  fi
43
43
  env:
44
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_NO_ORG }}
45
45
  - uses: fnkr/github-action-ghr@v1
46
46
  env:
47
47
  GHR_PATH: build/
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.2.1
4
+
5
+ * Added `--with-variables` option to the Sites command for adding/updating environment variables
6
+ * Fixed Functions environment variables not being pushed with `--with-variables`
7
+ * Removed `awaitPools` when wiping old variables
8
+
9
+ > **Note:** Storing environment variables in the `vars` attribute of `appwrite.json` is now deprecated due to security risks. Variables are now synced directly from the `.env` file in the root directory of the function’s or site’s folder.
10
+
3
11
  ## 8.2.0
4
12
 
5
13
  * Add `encrypt` attribute support
package/README.md CHANGED
@@ -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
- 8.2.0
32
+ 8.2.1
33
33
  ```
34
34
 
35
35
  ### Install using prebuilt binaries
@@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
60
60
  Once the installation completes, you can verify your install using
61
61
  ```
62
62
  $ appwrite -v
63
- 8.2.0
63
+ 8.2.1
64
64
  ```
65
65
 
66
66
  ## 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/8.2.0/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.0/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.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="8.2.0"
100
+ GITHUB_LATEST_VERSION="8.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
@@ -16,8 +16,8 @@ class Client {
16
16
  'x-sdk-name': 'Command Line',
17
17
  'x-sdk-platform': 'console',
18
18
  'x-sdk-language': 'cli',
19
- 'x-sdk-version': '8.2.0',
20
- 'user-agent' : `AppwriteCLI/8.2.0 (${os.type()} ${os.version()}; ${os.arch()})`,
19
+ 'x-sdk-version': '8.2.1',
20
+ 'user-agent' : `AppwriteCLI/8.2.1 (${os.type()} ${os.version()}; ${os.arch()})`,
21
21
  'X-Appwrite-Response-Format' : '1.7.0',
22
22
  };
23
23
  }
@@ -1,3 +1,6 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { parse: parseDotenv } = require('dotenv');
1
4
  const chalk = require('chalk');
2
5
  const inquirer = require("inquirer");
3
6
  const JSONbig = require("json-bigint")({ storeAsString: false });
@@ -12,7 +15,7 @@ const { proxyCreateFunctionRule, proxyCreateSiteRule, proxyListRules } = require
12
15
  const { consoleVariables } = require('./console');
13
16
  const { sdkForConsole } = require('../sdks')
14
17
  const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
15
- const { sitesGet, sitesCreate, sitesUpdate, sitesCreateDeployment, sitesGetDeployment, sitesCreateVariable } = require('./sites');
18
+ const { sitesGet, sitesCreate, sitesUpdate, sitesCreateDeployment, sitesGetDeployment, sitesCreateVariable, sitesListVariables, sitesDeleteVariable } = require('./sites');
16
19
  const {
17
20
  databasesGet,
18
21
  databasesCreate,
@@ -149,37 +152,6 @@ const awaitPools = {
149
152
  iteration + 1
150
153
  );
151
154
  },
152
- wipeVariables: async (functionId, iteration = 1) => {
153
- if (iteration > pollMaxDebounces) {
154
- return false;
155
- }
156
-
157
- const { total } = await functionsListVariables({
158
- functionId,
159
- queries: ['limit(1)'],
160
- parseOutput: false
161
- });
162
-
163
- if (total === 0) {
164
- return true;
165
- }
166
-
167
- if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
168
- let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
169
- if (steps > 1 && iteration === 1) {
170
- pollMaxDebounces *= steps;
171
-
172
- log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
173
- }
174
- }
175
-
176
- await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
177
-
178
- return await awaitPools.wipeVariables(
179
- functionId,
180
- iteration + 1
181
- );
182
- },
183
155
  deleteAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
184
156
  if (iteration > pollMaxDebounces) {
185
157
  return false;
@@ -1047,7 +1019,7 @@ const pushSettings = async () => {
1047
1019
  }
1048
1020
  }
1049
1021
 
1050
- const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
1022
+ const pushSite = async({ siteId, async, code, withVariables } = { returnOnZero: false }) => {
1051
1023
  process.chdir(localConfig.configDirectoryPath)
1052
1024
 
1053
1025
  const siteIds = [];
@@ -1180,7 +1152,6 @@ const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
1180
1152
  timeout: site.timeout,
1181
1153
  enabled: site.enabled,
1182
1154
  logging: site.logging,
1183
- vars: JSON.stringify(site.vars),
1184
1155
  parseOutput: false
1185
1156
  });
1186
1157
 
@@ -1213,16 +1184,43 @@ const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
1213
1184
  }
1214
1185
  }
1215
1186
 
1216
- updaterRow.update({ status: 'Creating variables' }).replaceSpinner(SPINNER_ARC);
1187
+ if (withVariables) {
1188
+ updaterRow.update({ status: 'Creating variables' }).replaceSpinner(SPINNER_ARC);
1217
1189
 
1218
- await Promise.all((site['vars'] ?? []).map(async variable => {
1219
- await sitesCreateVariable({
1190
+ const { variables } = await paginate(sitesListVariables, {
1220
1191
  siteId: site['$id'],
1221
- key: variable['key'],
1222
- value: variable['value'],
1223
1192
  parseOutput: false
1224
- });
1225
- }));
1193
+ }, 100, 'variables');
1194
+
1195
+ await Promise.all(variables.map(async variable => {
1196
+ await sitesDeleteVariable({
1197
+ siteId: site['$id'],
1198
+ variableId: variable['$id'],
1199
+ parseOutput: false
1200
+ });
1201
+ }));
1202
+
1203
+ const envFileLocation = `${site['path']}/.env`;
1204
+ let envVariables = [];
1205
+ try {
1206
+ if (fs.existsSync(envFileLocation)) {
1207
+ const envObject = parseDotenv(fs.readFileSync(envFileLocation, 'utf8'));
1208
+ envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
1209
+ }
1210
+ } catch (error) {
1211
+ // Handle parsing errors gracefully
1212
+ envVariables = [];
1213
+ }
1214
+ await Promise.all(envVariables.map(async variable => {
1215
+ await sitesCreateVariable({
1216
+ siteId: site['$id'],
1217
+ key: variable.key,
1218
+ value: variable.value,
1219
+ parseOutput: false,
1220
+ secret: false
1221
+ });
1222
+ }));
1223
+ }
1226
1224
 
1227
1225
  if (code === false) {
1228
1226
  successfullyPushed++;
@@ -1475,7 +1473,6 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur
1475
1473
  entrypoint: func.entrypoint,
1476
1474
  commands: func.commands,
1477
1475
  scopes: func.scopes,
1478
- vars: JSON.stringify(func.vars),
1479
1476
  parseOutput: false
1480
1477
  });
1481
1478
 
@@ -1524,19 +1521,25 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur
1524
1521
  });
1525
1522
  }));
1526
1523
 
1527
- let result = await awaitPools.wipeVariables(func['$id']);
1528
- if (!result) {
1529
- updaterRow.fail({ errorMessage: `Variable deletion timed out.` })
1530
- return;
1524
+ const envFileLocation = `${func['path']}/.env`;
1525
+ let envVariables = [];
1526
+ try {
1527
+ if (fs.existsSync(envFileLocation)) {
1528
+ const envObject = parseDotenv(fs.readFileSync(envFileLocation, 'utf8'));
1529
+ envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
1530
+ }
1531
+ } catch (error) {
1532
+ // Handle parsing errors gracefully
1533
+ envVariables = [];
1531
1534
  }
1532
-
1533
- // Deploy local variables
1534
- await Promise.all((func['vars'] ?? []).map(async variable => {
1535
+ await Promise.all(envVariables.map(async variable => {
1535
1536
  await functionsCreateVariable({
1536
1537
  functionId: func['$id'],
1537
- key: variable['key'],
1538
- value: variable['value'],
1539
- parseOutput: false
1538
+ variableId: ID.unique(),
1539
+ key: variable.key,
1540
+ value: variable.value,
1541
+ parseOutput: false,
1542
+ secret: false
1540
1543
  });
1541
1544
  }));
1542
1545
  }
@@ -2065,6 +2068,7 @@ push
2065
2068
  .option(`-f, --site-id <site-id>`, `ID of site to run`)
2066
2069
  .option(`-A, --async`, `Don't wait for sites deployments status`)
2067
2070
  .option("--no-code", "Don't push the site's code")
2071
+ .option("--with-variables", `Push site variables.`)
2068
2072
  .action(actionRunner(pushSite));
2069
2073
 
2070
2074
  push
package/lib/parser.js CHANGED
@@ -122,7 +122,7 @@ const parseError = (err) => {
122
122
  } catch {
123
123
  }
124
124
 
125
- const version = '8.2.0';
125
+ const version = '8.2.1';
126
126
  const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
127
127
  const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;
128
128
 
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": "8.2.0",
5
+ "version": "8.2.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "index.js",
8
8
  "bin": {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3
- "version": "8.2.0",
3
+ "version": "8.2.1",
4
4
  "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
5
5
  "homepage": "https://github.com/appwrite/sdk-for-cli",
6
6
  "license": "BSD-3-Clause",
7
7
  "architecture": {
8
8
  "64bit": {
9
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.0/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-x64.exe",
10
10
  "bin": [
11
11
  [
12
12
  "appwrite-cli-win-x64.exe",
@@ -15,7 +15,7 @@
15
15
  ]
16
16
  },
17
17
  "arm64": {
18
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.0/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",