diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b6408d4 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1 +APPWRITE_PROJECT=my-project +APPWRITE_KEY=secret-key \ No newline at end of file diff --git a/.gitignore b/.gitignore index b8fc5cc..bacb897 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .idea **.DS_Store +.env \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6fdb7c7..b39b30c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "BSD-3-Clause", "dependencies": { "chalk": "^4.1.0", - "node-appwrite": "14.0.0" + "dotenv": "^16.4.5", + "node-appwrite": "^15.0.0-rc1" } }, "node_modules/ansi-styles": { @@ -58,6 +59,18 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -67,11 +80,13 @@ } }, "node_modules/node-appwrite": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-14.0.0.tgz", - "integrity": "sha512-pPynEAmhep1rNHpv2UqsZfM7FbtDX7y+nRRZS/IP5CMDznMu8PBqzFD2WbbQIvVCv3MEDRY5xpXbPfyxbysCPQ==", + "version": "15.0.0-rc1", + "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-15.0.0-rc1.tgz", + "integrity": "sha512-WLkAhLyE4ohvuXR6caBwt9wjs+abv75N9zmtxBnIC1y7Xr9+gIfVVnG6dwUeb4sbzf0TloRXjTQB4bSVoM3q9Q==", + "license": "BSD-3-Clause", "dependencies": { - "node-fetch-native-with-agent": "1.7.2" + "node-fetch-native-with-agent": "1.7.2", + "parse-multipart-data": "^1.5.0" } }, "node_modules/node-fetch-native-with-agent": { @@ -79,6 +94,12 @@ "resolved": "https://registry.npmjs.org/node-fetch-native-with-agent/-/node-fetch-native-with-agent-1.7.2.tgz", "integrity": "sha512-5MaOOCuJEvcckoz7/tjdx1M6OusOY6Xc5f459IaruGStWnKzlI1qpNgaAwmn4LmFYcsSlj+jBMk84wmmRxfk5g==" }, + "node_modules/parse-multipart-data": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/parse-multipart-data/-/parse-multipart-data-1.5.0.tgz", + "integrity": "sha512-ck5zaMF0ydjGfejNMnlo5YU2oJ+pT+80Jb1y4ybanT27j+zbVP/jkYmCrUGsEln0Ox/hZmuvgy8Ra7AxbXP2Mw==", + "license": "MIT" + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -122,17 +143,23 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==" + }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "node-appwrite": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-14.0.0.tgz", - "integrity": "sha512-pPynEAmhep1rNHpv2UqsZfM7FbtDX7y+nRRZS/IP5CMDznMu8PBqzFD2WbbQIvVCv3MEDRY5xpXbPfyxbysCPQ==", + "version": "15.0.0-rc1", + "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-15.0.0-rc1.tgz", + "integrity": "sha512-WLkAhLyE4ohvuXR6caBwt9wjs+abv75N9zmtxBnIC1y7Xr9+gIfVVnG6dwUeb4sbzf0TloRXjTQB4bSVoM3q9Q==", "requires": { - "node-fetch-native-with-agent": "1.7.2" + "node-fetch-native-with-agent": "1.7.2", + "parse-multipart-data": "^1.5.0" } }, "node-fetch-native-with-agent": { @@ -140,6 +167,11 @@ "resolved": "https://registry.npmjs.org/node-fetch-native-with-agent/-/node-fetch-native-with-agent-1.7.2.tgz", "integrity": "sha512-5MaOOCuJEvcckoz7/tjdx1M6OusOY6Xc5f459IaruGStWnKzlI1qpNgaAwmn4LmFYcsSlj+jBMk84wmmRxfk5g==" }, + "parse-multipart-data": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/parse-multipart-data/-/parse-multipart-data-1.5.0.tgz", + "integrity": "sha512-ck5zaMF0ydjGfejNMnlo5YU2oJ+pT+80Jb1y4ybanT27j+zbVP/jkYmCrUGsEln0Ox/hZmuvgy8Ra7AxbXP2Mw==" + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index b0027da..9d5f7f8 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "chalk": "^4.1.0", - "node-appwrite": "14.0.0" + "dotenv": "^16.4.5", + "node-appwrite": "^15.0.0-rc1" } } diff --git a/src/app.js b/src/app.js index 3726040..ee2fbfa 100644 --- a/src/app.js +++ b/src/app.js @@ -1,15 +1,30 @@ -const { Client, Databases, Functions, Account, Users, Storage, Query, Permission, Role, ID } = require('node-appwrite'); -const chalk = require('chalk'); -const fs = require('fs'); -const path = require('path'); -const { InputFile } = require('node-appwrite/file') +require("dotenv").config(); + +const { + Client, + Databases, + Functions, + Account, + Users, + Storage, + Query, + Permission, + Payload, + Role, + ID, + Runtime, + ExecutionMethod, +} = require("node-appwrite"); +const chalk = require("chalk"); +const fs = require("fs"); +const path = require("path"); // Config const client = new Client() - .setEndpoint('YOUR_ENDPOINT') // Replace with your endpoint - .setProject('YOUR_PROJECT_ID') // Replace with your project ID - .setKey('YOUR_API_KEY'); // Replace with your API Key - //.setJWT('jwt'); // Use this to authenticate with JWT generated from Client SDK + .setEndpoint(process.env.APPWRITE_ENDPOINT) + .setProject(process.env.APPWRITE_PROJECT) + .setKey(process.env.APPWRITE_KEY) + .setSelfSigned(true); const databases = new Databases(client); const functions = new Functions(client); @@ -28,546 +43,539 @@ let executionId; // List of API Definitions const createDatabase = async () => { - console.log(chalk.greenBright('Running Create Database API')); + console.log(chalk.greenBright("Running Create Database API")); - const response = await databases.create(ID.unique(), "Default"); + const response = await databases.create(ID.unique(), "Default"); - databaseId = response.$id; + databaseId = response.$id; - console.log(response); -} + console.log(response); +}; const listDatabases = async () => { - console.log(chalk.greenBright("Running List Databases API")); + console.log(chalk.greenBright("Running List Databases API")); - const response = await databases.list(); + const response = await databases.list(); - console.log(response); -} + console.log(response); +}; const getDatabase = async () => { - console.log(chalk.greenBright("Running Get Database API")); + console.log(chalk.greenBright("Running Get Database API")); - const response = await databases.get(databaseId); + const response = await databases.get(databaseId); - console.log(response); -} + console.log(response); +}; const updateDatabase = async () => { - console.log(chalk.greenBright('Running Update Database API')); + console.log(chalk.greenBright("Running Update Database API")); - const response = await databases.update( - databaseId, - "Updated Database" - ); + const response = await databases.update(databaseId, "Updated Database"); - console.log(response); -} + console.log(response); +}; const deleteDatabase = async () => { - console.log(chalk.greenBright("Running Delete Database API")); + console.log(chalk.greenBright("Running Delete Database API")); - const response = await databases.delete(databaseId); + const response = await databases.delete(databaseId); - console.log(response); -} + console.log(response); +}; const createCollection = async () => { - console.log(chalk.greenBright('Running Create Collection API')); - - const response = await databases.createCollection( - databaseId, // ID of the collection - ID.unique(), // Collection ID - "Collection", // Collection Name - [ - Permission.read(Role.any()), - Permission.create(Role.users()), - Permission.update(Role.users()), - Permission.delete(Role.users()), - ] - ); - - collectionId = response.$id; - console.log(response); - - const nameAttributeResponse = await databases.createStringAttribute( - databaseId, - collectionId, - 'name', - 255, - false, - "Empty Name", - false - ); - console.log(nameAttributeResponse); - - const yearAttributeResponse = await databases.createIntegerAttribute( - databaseId, - collectionId, - 'release_year', - false, - 0, 5000, - 1970, - false - ); - console.log(yearAttributeResponse); - - console.log("Waiting a little to ensure attributes are created ..."); - await new Promise((resolve) => setTimeout(resolve, 2000)); - - const yearIndexResponse = await databases.createIndex( - databaseId, - collectionId, - 'key_release_year_asc', - 'key', - ['release_year'], - ['ASC'], - ); - console.log(yearIndexResponse); - - console.log("Waiting a little to ensure index is created ..."); - await new Promise((resolve) => setTimeout(resolve, 2000)); -} + console.log(chalk.greenBright("Running Create Collection API")); + + const response = await databases.createCollection( + databaseId, // ID of the collection + ID.unique(), // Collection ID + "Collection", // Collection Name + [ + Permission.read(Role.any()), + Permission.create(Role.users()), + Permission.update(Role.users()), + Permission.delete(Role.users()), + ] + ); + + collectionId = response.$id; + console.log(response); + + const nameAttributeResponse = await databases.createStringAttribute( + databaseId, + collectionId, + "name", + 255, + false, + "Empty Name", + false + ); + console.log(nameAttributeResponse); + + const yearAttributeResponse = await databases.createIntegerAttribute( + databaseId, + collectionId, + "release_year", + false, + 0, + 5000, + 1970, + false + ); + console.log(yearAttributeResponse); + + console.log("Waiting a little to ensure attributes are created ..."); + await new Promise((resolve) => setTimeout(resolve, 2000)); + + const yearIndexResponse = await databases.createIndex( + databaseId, + collectionId, + "key_release_year_asc", + "key", + ["release_year"], + ["ASC"] + ); + console.log(yearIndexResponse); + + console.log("Waiting a little to ensure index is created ..."); + await new Promise((resolve) => setTimeout(resolve, 2000)); +}; const listCollections = async () => { - console.log(chalk.greenBright('Running List Collections API')); + console.log(chalk.greenBright("Running List Collections API")); - const response = await databases.listCollections(databaseId); + const response = await databases.listCollections(databaseId); - console.log(response); -} + console.log(response); +}; const getCollection = async () => { - console.log(chalk.greenBright("Running Get Collection API")); + console.log(chalk.greenBright("Running Get Collection API")); - const response = await databases.getCollection(databaseId, collectionId); + const response = await databases.getCollection(databaseId, collectionId); - console.log(response); -} + console.log(response); +}; const updateCollection = async () => { - console.log(chalk.greenBright("Running Update Collection API")); + console.log(chalk.greenBright("Running Update Collection API")); - const response = await databases.updateCollection( - databaseId, - collectionId, - "Updated Collection" - ); + const response = await databases.updateCollection( + databaseId, + collectionId, + "Updated Collection" + ); - console.log(response); -} + console.log(response); +}; const deleteCollection = async () => { - console.log(chalk.greenBright("Running Delete Collection API")); + console.log(chalk.greenBright("Running Delete Collection API")); - const response = await databases.deleteCollection(databaseId, collectionId); + const response = await databases.deleteCollection(databaseId, collectionId); - console.log(response); -} + console.log(response); +}; const listAttributes = async () => { - console.log(chalk.greenBright('Running List Attributes API')); + console.log(chalk.greenBright("Running List Attributes API")); - const response = await databases.listAttributes(databaseId, collectionId); + const response = await databases.listAttributes(databaseId, collectionId); - console.log(response); -} + console.log(response); +}; const createDocument = async () => { - console.log(chalk.greenBright('Running Add Document API')); - - const response = await databases.createDocument( - databaseId, - collectionId, - ID.unique(), - { - name: 'Spider Man', - release_year: 1920 - }, - [ - Permission.read(Role.any()), - Permission.update(Role.users()), - Permission.delete(Role.users()), - ] - ); - documentId = response.$id; - - console.log(response); -} + console.log(chalk.greenBright("Running Add Document API")); + + const response = await databases.createDocument( + databaseId, + collectionId, + ID.unique(), + { + name: "Spider Man", + release_year: 1920, + }, + [ + Permission.read(Role.any()), + Permission.update(Role.users()), + Permission.delete(Role.users()), + ] + ); + documentId = response.$id; + + console.log(response); +}; const listDocuments = async () => { - console.log(chalk.greenBright('Running List Documents API')); + console.log(chalk.greenBright("Running List Documents API")); - const response = await databases.listDocuments( - databaseId, - collectionId, - [ - Query.equal('release_year', 1920), - ] - ); + const response = await databases.listDocuments(databaseId, collectionId, [ + Query.equal("release_year", 1920), + ]); - console.log(response); -} + console.log(response); +}; const getDocument = async () => { - console.log(chalk.greenBright("Running Get Document API")); + console.log(chalk.greenBright("Running Get Document API")); - const response = await databases.getDocument( - databaseId, - collectionId, - documentId - ); + const response = await databases.getDocument( + databaseId, + collectionId, + documentId + ); - console.log(response); -} + console.log(response); +}; const updateDocument = async () => { - console.log(chalk.greenBright("Running Update Document API")); + console.log(chalk.greenBright("Running Update Document API")); - const response = await databases.updateDocument( - databaseId, - collectionId, - documentId, - { - release_year: 2005 - } - ); + const response = await databases.updateDocument( + databaseId, + collectionId, + documentId, + { + release_year: 2005, + } + ); - console.log(response); -} + console.log(response); +}; const deleteDocument = async () => { - console.log(chalk.greenBright("Running Delete Document API")); + console.log(chalk.greenBright("Running Delete Document API")); - const response = await databases.deleteDocument( - databaseId, - collectionId, - documentId - ); + const response = await databases.deleteDocument( + databaseId, + collectionId, + documentId + ); - console.log(response); -} + console.log(response); +}; const createBucket = async () => { - console.log(chalk.greenBright("Running Create Bucket API")); - - const response = await storage.createBucket( - ID.unique(), - "All Files", - [ - Permission.read(Role.any()), - Permission.create(Role.users()), - Permission.update(Role.users()), - Permission.delete(Role.users()), - ] - ); - bucketId = response.$id; - - console.log(response); -} + console.log(chalk.greenBright("Running Create Bucket API")); + + const response = await storage.createBucket(ID.unique(), "All Files", [ + Permission.read(Role.any()), + Permission.create(Role.users()), + Permission.update(Role.users()), + Permission.delete(Role.users()), + ]); + bucketId = response.$id; + + console.log(response); +}; const listBuckets = async () => { - console.log(chalk.greenBright("Running List Buckets API")); + console.log(chalk.greenBright("Running List Buckets API")); - const response = await storage.listBuckets(); + const response = await storage.listBuckets(); - console.log(response); -} + console.log(response); +}; const getBucket = async () => { - console.log(chalk.greenBright("Running Get Bucket API")); + console.log(chalk.greenBright("Running Get Bucket API")); - const response = await storage.getBucket(bucketId); + const response = await storage.getBucket(bucketId); - console.log(response); -} + console.log(response); +}; const updateBucket = async () => { - console.log(chalk.greenBright("Running Update Bucket API")); + console.log(chalk.greenBright("Running Update Bucket API")); - const response = await storage.updateBucket( - bucketId, - "Updated Bucket" - ); + const response = await storage.updateBucket(bucketId, "Updated Bucket"); - console.log(response); -} + console.log(response); +}; const deleteBucket = async () => { - console.log(chalk.greenBright("Running Delete Bucket API")); + console.log(chalk.greenBright("Running Delete Bucket API")); - const response = await storage.deleteBucket(bucketId); + const response = await storage.deleteBucket(bucketId); - console.log(response); -} + console.log(response); +}; const uploadFile = async () => { - console.log(chalk.greenBright('Running Upload File API')); - - const response = await storage.createFile( - bucketId, - ID.unique(), - InputFile.fromPath("./resources/nature.jpg", "nature.jpg"), - [ - Permission.read(Role.any()), - Permission.update(Role.users()), - Permission.delete(Role.users()), - ] - ); - fileId = response.$id; - - console.log(response); -} + console.log(chalk.greenBright("Running Upload File API")); + + const response = await storage.createFile( + bucketId, + ID.unique(), + Payload.fromBinary(fs.readFileSync("./resources/nature.jpg"), "nature.jpg"), + [ + Permission.read(Role.any()), + Permission.update(Role.users()), + Permission.delete(Role.users()), + ] + ); + fileId = response.$id; + + console.log(response); +}; const listFiles = async () => { - console.log(chalk.greenBright("Running List Files API")); + console.log(chalk.greenBright("Running List Files API")); - const response = await storage.listFiles(bucketId); + const response = await storage.listFiles(bucketId); - console.log(response); -} + console.log(response); +}; const getFile = async () => { - console.log(chalk.greenBright("Running Get File API")); + console.log(chalk.greenBright("Running Get File API")); - const response = await storage.getFile(bucketId, fileId); + const response = await storage.getFile(bucketId, fileId); - console.log(response); -} + console.log(response); +}; const updateFile = async () => { - console.log(chalk.greenBright("Running Update File API")); - - const response = await storage.updateFile( - bucketId, - fileId, - "abc", - [ - Permission.read(Role.any()), - Permission.update(Role.any()), - Permission.delete(Role.any()), - ] - ); - - console.log(response); -} + console.log(chalk.greenBright("Running Update File API")); + + const response = await storage.updateFile(bucketId, fileId, "abc", [ + Permission.read(Role.any()), + Permission.update(Role.any()), + Permission.delete(Role.any()), + ]); + + console.log(response); +}; const deleteFile = async () => { - console.log(chalk.greenBright("Running Delete File API")); + console.log(chalk.greenBright("Running Delete File API")); - const response = await storage.deleteFile(bucketId, fileId); + const response = await storage.deleteFile(bucketId, fileId); - console.log(response); -} + console.log(response); +}; const createUser = async () => { - console.log(chalk.greenBright('Running Create User API')); + console.log(chalk.greenBright("Running Create User API")); - const response = await users.create( - ID.unique(), - new Date().getTime() + '@example.com', - null, - 'user@123', - 'Some User' - ); - userId = response.$id; + const response = await users.create( + ID.unique(), + new Date().getTime() + "@example.com", + undefined, + "user@123", + "Some User" + ); + userId = response.$id; - console.log(response); -} + console.log(response); +}; const listUsers = async () => { - console.log(chalk.greenBright('Running List Users API')); + console.log(chalk.greenBright("Running List Users API")); - const response = await users.list(); + const response = await users.list(); - console.log(response); -} + console.log(response); +}; const getUser = async () => { - console.log(chalk.greenBright('Running Get User API')); + console.log(chalk.greenBright("Running Get User API")); - const response = await users.get(userId); + const response = await users.get(userId); - console.log(response); -} + console.log(response); +}; const getAccount = async () => { - console.log(chalk.greenBright('Running List Users API')); + console.log(chalk.greenBright("Running List Users API")); - const response = await account.get(); + const response = await account.get(); - console.log(response); -} + console.log(response); +}; const updateUserName = async () => { - console.log(chalk.greenBright('Running Update User Name API')); + console.log(chalk.greenBright("Running Update User Name API")); - const response = await users.updateName(userId, 'Updated Name'); + const response = await users.updateName(userId, "Updated Name"); - console.log(response); -} + console.log(response); +}; const deleteUser = async () => { - console.log(chalk.greenBright('Running Delete User API')); + console.log(chalk.greenBright("Running Delete User API")); - const response = await users.delete(userId); + const response = await users.delete(userId); - console.log(response); -} + console.log(response); +}; const createFunction = async () => { - console.log(chalk.greenBright('Running Create Function API')); - - const response = await functions.create( - ID.unique(), - "Node Hello World", - "node-16.0", - [Role.any()], - [], - '', - 15, - true, - true, - "index.js", - '' - ); - - functionId = response.$id; - - console.log(response); -} + console.log(chalk.greenBright("Running Create Function API")); + + const response = await functions.create( + ID.unique(), + "Node Hello World", + Runtime.Node180, + [Role.any()], + [], + "", + 15, + true, + true, + "index.js", + "" + ); + + functionId = response.$id; + + console.log(response); +}; const listFunctions = async () => { - console.log(chalk.greenBright('Running List Functions API')); + console.log(chalk.greenBright("Running List Functions API")); - let response = await functions.list(); + let response = await functions.list(); - console.log(response); -} + console.log(response); +}; const getFunction = async () => { - console.log(chalk.greenBright('Running Get Function API')); + console.log(chalk.greenBright("Running Get Function API")); - let response = await functions.get(functionId); + let response = await functions.get(functionId); - console.log(response); -} + console.log(response); +}; const uploadDeployment = async () => { - console.log(chalk.greenBright('Running Upload Deployment API')); + console.log(chalk.greenBright("Running Upload Deployment API")); - let response = await functions.createDeployment( - functionId, - InputFile.fromPath("./resources/code.tar.gz", "code.tar.gz"), - true, - "index.js" - ); + let response = await functions.createDeployment( + functionId, + Payload.fromBinary( + fs.readFileSync("./resources/code.tar.gz"), + "code.tar.gz" + ), + true, + "index.js" + ); - console.log(response); + console.log(response); - console.log("Waiting a little to ensure deployment has built ..."); - await new Promise((resolve) => setTimeout(resolve, 3000)); -} + console.log("Waiting a little to ensure deployment has built ..."); + await new Promise((resolve) => setTimeout(resolve, 3000)); +}; const listDeployments = async () => { - console.log(chalk.greenBright('Running List Deployments API')); + console.log(chalk.greenBright("Running List Deployments API")); - let response = await functions.listDeployments(functionId); + let response = await functions.listDeployments(functionId); - console.log(response); -} + console.log(response); +}; const executeSync = async () => { - console.log(chalk.greenBright('Running Execute Function API (sync)')); + console.log(chalk.greenBright("Running Execute Function API (sync)")); - let response = await functions.createExecution(functionId, "", false, "/", "GET", {}); + let response = await functions.createExecution( + functionId, + undefined, + // @ts-ignore + false, + "/", + ExecutionMethod.GET, + {} + ); - // sleep for 3 seconds - console.log("Waiting a little to ensure execution is finished ..."); - await new Promise((resolve) => setTimeout(resolve, 3000)); + // sleep for 3 seconds + console.log("Waiting a little to ensure execution is finished ..."); + await new Promise((resolve) => setTimeout(resolve, 3000)); - console.log(response); -} + console.log(response); +}; const executeAsync = async () => { - console.log(chalk.greenBright('Running Execute Function API (async)')); + console.log(chalk.greenBright("Running Execute Function API (async)")); - let response = await functions.createExecution(functionId, '', true); + let response = await functions.createExecution(functionId, undefined, true); - executionId = response.$id; + executionId = response.$id; - console.log(response); + console.log(response); - console.log("Waiting a little to ensure execution is finished ..."); - await new Promise((resolve) => setTimeout(resolve, 2000)); + console.log("Waiting a little to ensure execution is finished ..."); + await new Promise((resolve) => setTimeout(resolve, 2000)); - let asyncResponse = await functions.getExecution(functionId, executionId); + let asyncResponse = await functions.getExecution(functionId, executionId); - console.log(asyncResponse); -} + console.log(asyncResponse); +}; const deleteFunction = async () => { - console.log(chalk.greenBright('Running Delete function API')); + console.log(chalk.greenBright("Running Delete function API")); - const response = await functions.delete(functionId); + const response = await functions.delete(functionId); - console.log(response); -} + console.log(response); +}; const runAllTasks = async () => { - await createDatabase(); - await listDatabases(); - await getDatabase(); - await updateDatabase(); - - await createCollection(); - await listCollections(); - await getCollection(); - await updateCollection(); - await listAttributes(); - - await createDocument(); - await listDocuments(); - await getDocument(); - await updateDocument(); - - await deleteDocument(); - await deleteCollection(); - await deleteDatabase(); - - await createBucket(); - await listBuckets(); - await getBucket(); - await updateBucket(); - - await uploadFile(); - await listFiles(); - await getFile(); - await updateFile(); - - await deleteFile(); - await deleteBucket(); - - // await getAccount() // works only with JWT - await createUser(); - await listUsers(); - await getUser(); - await updateUserName(); - await deleteUser(); - - await createFunction(); - await listFunctions(); - await uploadDeployment(); - await listDeployments(); - await executeSync(); - await executeAsync(); - await deleteFunction(); -} + await createDatabase(); + await listDatabases(); + await getDatabase(); + await updateDatabase(); + + await createCollection(); + await listCollections(); + await getCollection(); + await updateCollection(); + await listAttributes(); + + await createDocument(); + await listDocuments(); + await getDocument(); + await updateDocument(); + + await deleteDocument(); + await deleteCollection(); + await deleteDatabase(); + + await createBucket(); + await listBuckets(); + await getBucket(); + await updateBucket(); + + await uploadFile(); + await listFiles(); + await getFile(); + await updateFile(); + + await deleteFile(); + await deleteBucket(); + + // await getAccount() // works only with JWT + await createUser(); + await listUsers(); + await getUser(); + await updateUserName(); + await deleteUser(); + + await createFunction(); + await listFunctions(); + await uploadDeployment(); + await listDeployments(); + await executeSync(); + await executeAsync(); + await deleteFunction(); +}; runAllTasks() - .then(() => { - console.log(chalk.green.bold('Successfully ran playground!')) - }) - .catch(err => { - console.error(err) - }) + .then(() => { + console.log(chalk.green.bold("Successfully ran playground!")); + }) + .catch((err) => { + console.error(err); + });