appwrite-cli 10.2.1 → 10.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.2.2
4
+
5
+ * Fix `logout` command showing duplicate sessions
6
+ * Fix `logout` command showing a blank email even when logged out
7
+ * Add syncing of `tablesDB` resource during `push tables` command
8
+
3
9
  ## 10.2.1
4
10
 
5
11
  * Add transaction support for Databases and TablesDB
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
- 10.2.1
32
+ 10.2.2
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
- 10.2.1
63
+ 10.2.2
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/10.2.1/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.1/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/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="10.2.1"
100
+ GITHUB_LATEST_VERSION="10.2.2"
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': '10.2.1',
20
- 'user-agent' : `AppwriteCLI/10.2.1 (${os.type()} ${os.version()}; ${os.arch()})`,
19
+ 'x-sdk-version': '10.2.2',
20
+ 'user-agent' : `AppwriteCLI/10.2.2 (${os.type()} ${os.version()}; ${os.arch()})`,
21
21
  'X-Appwrite-Response-Format' : '1.8.0',
22
22
  };
23
23
  }
@@ -171,12 +171,11 @@ const deleteSession = async (accountId) => {
171
171
  parseOutput: false,
172
172
  sdk: client
173
173
  })
174
-
175
- globalConfig.removeSession(accountId);
176
174
  } catch (e) {
177
175
  error('Unable to log out, removing locally saved session information')
176
+ } finally {
177
+ globalConfig.removeSession(accountId);
178
178
  }
179
- globalConfig.removeSession(accountId);
180
179
  }
181
180
 
182
181
  const logout = new Command("logout")
@@ -194,6 +193,7 @@ const logout = new Command("logout")
194
193
  }
195
194
  if (sessions.length === 1) {
196
195
  await deleteSession(current);
196
+ globalConfig.setCurrentSession('');
197
197
  success("Logging out");
198
198
 
199
199
  return;
@@ -215,6 +215,8 @@ const logout = new Command("logout")
215
215
  globalConfig.setCurrentSession(accountId);
216
216
 
217
217
  success(`Current account is ${accountId}`);
218
+ } else if (remainingSessions.length === 0) {
219
+ globalConfig.setCurrentSession('');
218
220
  }
219
221
 
220
222
  success("Logging out");
@@ -55,7 +55,10 @@ const {
55
55
  tablesDBUpdate,
56
56
  tablesDBCreateTable,
57
57
  tablesDBGetTable,
58
- tablesDBUpdateTable
58
+ tablesDBUpdateTable,
59
+ tablesDBList,
60
+ tablesDBDelete,
61
+ tablesDBListTables
59
62
  } = require("./tables-db");
60
63
  const {
61
64
  storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -1700,6 +1703,147 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur
1700
1703
  }
1701
1704
  }
1702
1705
 
1706
+ const checkAndApplyTablesDBChanges = async () => {
1707
+ log('Checking for tablesDB changes ...');
1708
+
1709
+ const localTablesDBs = localConfig.getTablesDBs();
1710
+ const { databases: remoteTablesDBs } = await paginate(tablesDBList, { parseOutput: false }, 100, 'databases');
1711
+
1712
+ if (localTablesDBs.length === 0 && remoteTablesDBs.length === 0) {
1713
+ return { applied: false, resyncNeeded: false };
1714
+ }
1715
+
1716
+ const changes = [];
1717
+ const toCreate = [];
1718
+ const toUpdate = [];
1719
+ const toDelete = [];
1720
+
1721
+ // Check for deletions - remote DBs that aren't in local config
1722
+ for (const remoteDB of remoteTablesDBs) {
1723
+ const localDB = localTablesDBs.find(db => db.$id === remoteDB.$id);
1724
+ if (!localDB) {
1725
+ toDelete.push(remoteDB);
1726
+ changes.push({
1727
+ id: remoteDB.$id,
1728
+ key: 'Database',
1729
+ remote: chalk.red(`${remoteDB.name} (${remoteDB.$id})`),
1730
+ local: chalk.green('(deleted locally)')
1731
+ });
1732
+ }
1733
+ }
1734
+
1735
+ // Check for additions and updates
1736
+ for (const localDB of localTablesDBs) {
1737
+ const remoteDB = remoteTablesDBs.find(db => db.$id === localDB.$id);
1738
+
1739
+ if (!remoteDB) {
1740
+ toCreate.push(localDB);
1741
+ changes.push({
1742
+ id: localDB.$id,
1743
+ key: 'Database',
1744
+ remote: chalk.red('(does not exist)'),
1745
+ local: chalk.green(`${localDB.name} (${localDB.$id})`)
1746
+ });
1747
+ } else {
1748
+ let hasChanges = false;
1749
+
1750
+ if (remoteDB.name !== localDB.name) {
1751
+ hasChanges = true;
1752
+ changes.push({
1753
+ id: localDB.$id,
1754
+ key: 'Name',
1755
+ remote: chalk.red(remoteDB.name),
1756
+ local: chalk.green(localDB.name)
1757
+ });
1758
+ }
1759
+
1760
+ if (remoteDB.enabled !== localDB.enabled) {
1761
+ hasChanges = true;
1762
+ changes.push({
1763
+ id: localDB.$id,
1764
+ key: 'Enabled?',
1765
+ remote: chalk.red(remoteDB.enabled),
1766
+ local: chalk.green(localDB.enabled)
1767
+ });
1768
+ }
1769
+
1770
+ if (hasChanges) {
1771
+ toUpdate.push(localDB);
1772
+ }
1773
+ }
1774
+ }
1775
+
1776
+ if (changes.length === 0) {
1777
+ return { applied: false, resyncNeeded: false };
1778
+ }
1779
+
1780
+ log('Found changes in tablesDB resources:');
1781
+ drawTable(changes);
1782
+
1783
+ if (toDelete.length > 0) {
1784
+ console.log(`${chalk.red('-------------------------------------------------------------------')}`);
1785
+ console.log(`${chalk.red('| WARNING: Database deletion will also delete all related tables |')}`);
1786
+ console.log(`${chalk.red('-------------------------------------------------------------------')}`);
1787
+ }
1788
+
1789
+ if ((await getConfirmation()) !== true) {
1790
+ return { applied: false, resyncNeeded: false };
1791
+ }
1792
+
1793
+ // Apply deletions first
1794
+ let needsResync = false;
1795
+ for (const db of toDelete) {
1796
+ try {
1797
+ log(`Deleting database ${db.name} ( ${db.$id} ) ...`);
1798
+ await tablesDBDelete({
1799
+ databaseId: db.$id,
1800
+ parseOutput: false
1801
+ });
1802
+ success(`Deleted ${db.name} ( ${db.$id} )`);
1803
+ needsResync = true;
1804
+ } catch (e) {
1805
+ error(`Failed to delete database ${db.name} ( ${db.$id} ): ${e.message}`);
1806
+ throw new Error(`Database sync failed during deletion of ${db.$id}. Some changes may have been applied.`);
1807
+ }
1808
+ }
1809
+
1810
+ // Apply creations
1811
+ for (const db of toCreate) {
1812
+ try {
1813
+ log(`Creating database ${db.name} ( ${db.$id} ) ...`);
1814
+ await tablesDBCreate({
1815
+ databaseId: db.$id,
1816
+ name: db.name,
1817
+ enabled: db.enabled,
1818
+ parseOutput: false
1819
+ });
1820
+ success(`Created ${db.name} ( ${db.$id} )`);
1821
+ } catch (e) {
1822
+ error(`Failed to create database ${db.name} ( ${db.$id} ): ${e.message}`);
1823
+ throw new Error(`Database sync failed during creation of ${db.$id}. Some changes may have been applied.`);
1824
+ }
1825
+ }
1826
+
1827
+ // Apply updates
1828
+ for (const db of toUpdate) {
1829
+ try {
1830
+ log(`Updating database ${db.name} ( ${db.$id} ) ...`);
1831
+ await tablesDBUpdate({
1832
+ databaseId: db.$id,
1833
+ name: db.name,
1834
+ enabled: db.enabled,
1835
+ parseOutput: false
1836
+ });
1837
+ success(`Updated ${db.name} ( ${db.$id} )`);
1838
+ } catch (e) {
1839
+ error(`Failed to update database ${db.name} ( ${db.$id} ): ${e.message}`);
1840
+ throw new Error(`Database sync failed during update of ${db.$id}. Some changes may have been applied.`);
1841
+ }
1842
+ }
1843
+
1844
+ return { applied: true, resyncNeeded: needsResync };
1845
+ };
1846
+
1703
1847
  const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) => {
1704
1848
  const tables = [];
1705
1849
 
@@ -1707,6 +1851,25 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1707
1851
  pollMaxDebounces = attempts;
1708
1852
  }
1709
1853
 
1854
+ const { applied: tablesDBApplied, resyncNeeded } = await checkAndApplyTablesDBChanges();
1855
+ if (resyncNeeded) {
1856
+ log('Resyncing configuration due to tablesDB deletions ...');
1857
+
1858
+ const remoteTablesDBs = (await paginate(tablesDBList, { parseOutput: false }, 100, 'databases')).databases;
1859
+ const localTablesDBs = localConfig.getTablesDBs();
1860
+
1861
+ const remoteDatabaseIds = new Set(remoteTablesDBs.map(db => db.$id));
1862
+ const localTables = localConfig.getTables();
1863
+ const validTables = localTables.filter(table => remoteDatabaseIds.has(table.databaseId));
1864
+
1865
+ localConfig.set('tables', validTables);
1866
+
1867
+ const validTablesDBs = localTablesDBs.filter(db => remoteDatabaseIds.has(db.$id));
1868
+ localConfig.set('tablesDB', validTablesDBs);
1869
+
1870
+ success('Configuration resynced successfully.');
1871
+ }
1872
+
1710
1873
  if (cliConfig.all) {
1711
1874
  checkDeployConditions(localConfig);
1712
1875
  tables.push(...localConfig.getTables());
@@ -1730,39 +1893,6 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1730
1893
  return;
1731
1894
  }
1732
1895
 
1733
- const databases = Array.from(new Set(tables.map(table => table['databaseId'])));
1734
-
1735
- // Parallel tablesDB actions
1736
- await Promise.all(databases.map(async (databaseId) => {
1737
- const localDatabase = localConfig.getTablesDB(databaseId);
1738
-
1739
- try {
1740
- const database = await tablesDBGet({
1741
- databaseId: databaseId,
1742
- parseOutput: false,
1743
- });
1744
-
1745
- if (database.name !== (localDatabase.name ?? databaseId)) {
1746
- await tablesDBUpdate({
1747
- databaseId: databaseId,
1748
- name: localDatabase.name ?? databaseId,
1749
- parseOutput: false
1750
- })
1751
-
1752
- success(`Updated ${localDatabase.name} ( ${databaseId} ) name`);
1753
- }
1754
- } catch (err) {
1755
- log(`Database ${databaseId} not found. Creating it now ...`);
1756
-
1757
- await tablesDBCreate({
1758
- databaseId: databaseId,
1759
- name: localDatabase.name ?? databaseId,
1760
- parseOutput: false,
1761
- });
1762
- }
1763
- }));
1764
-
1765
-
1766
1896
  if (!(await approveChanges(tables, tablesDBGetTable, KeysTable, 'tableId', 'tables', ['columns', 'indexes'], 'databaseId', 'databaseId'))) {
1767
1897
  return;
1768
1898
  }
package/lib/config.js CHANGED
@@ -681,15 +681,25 @@ class Global extends Config {
681
681
 
682
682
  getSessions() {
683
683
  const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
684
+ const current = this.getCurrentSession();
684
685
 
685
- return sessions.map((session) => {
686
-
687
- return {
688
- id: session,
689
- endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
690
- email: this.data[session][Global.PREFERENCE_EMAIL]
686
+ const sessionMap = new Map();
687
+
688
+ sessions.forEach((sessionId) => {
689
+ const email = this.data[sessionId][Global.PREFERENCE_EMAIL];
690
+ const endpoint = this.data[sessionId][Global.PREFERENCE_ENDPOINT];
691
+ const key = `${email}|${endpoint}`;
692
+
693
+ if (sessionId === current || !sessionMap.has(key)) {
694
+ sessionMap.set(key, {
695
+ id: sessionId,
696
+ endpoint: this.data[sessionId][Global.PREFERENCE_ENDPOINT],
697
+ email: this.data[sessionId][Global.PREFERENCE_EMAIL]
698
+ });
691
699
  }
692
- })
700
+ });
701
+
702
+ return Array.from(sessionMap.values());
693
703
  }
694
704
 
695
705
  addSession(session, data) {
package/lib/parser.js CHANGED
@@ -122,7 +122,7 @@ const parseError = (err) => {
122
122
  } catch {
123
123
  }
124
124
 
125
- const version = '10.2.1';
125
+ const version = '10.2.2';
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": "10.2.1",
5
+ "version": "10.2.2",
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": "10.2.1",
3
+ "version": "10.2.2",
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/10.2.1/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/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/10.2.1/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",