Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ Appwrite playground is a simple way to explore the Appwrite API & Web SDK. Use t

![Appwrite Playground](preview.png)

## Appwrite Install
If you have never setup Appwrite locally before there are a few steps.

- You must have [Docker](https://docs.docker.com/engine/install/) installed.
- Run docker compose command from the [Appwrite Installation Docs](https://appwrite.io/docs/installation).
- Reference the [Appwrite 101 - YouTube Playlist](https://youtu.be/aO4mw8smXkI)
- If you are running a remote Appwrite instance change `http://localhost/v1` in the [configuration](https://github.com/appwrite/playground-for-web/blob/fcd5aa02976f6787d14720a4e920402fafa6175b/public/index.html#L205) to your Appwrite url.

### Initial Setup

Execute the below steps if you would like to automatically setup the project.

- Create project in [console](http://localhost/console/home) with key `playground` and Name `Playground`
- [Generate API Key](http://localhost/console/keys?project=playground)
- In `./helpers/setup.js` update the `setKey` method with your new value
- Run command `node ./helpers/setup.js`
## Get Started
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Get Started
## Get Started


The **public/index.html** file in this repository contains **all** the playground examples and source code.
Expand Down
85 changes: 58 additions & 27 deletions helpers/setup.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
const sdk = require('node-appwrite');
const config = {
project: '5d8fa6deefd05',
endpoint: 'https://localhost/v1',
key: '1589eb89e0c0153892c68867ea44137581a7a91390668ab1966a9c3a30a4d9ace58de90b3eaf61c0eae3f35e886b3d01cc8a674caf630c25a4428021ba0697cca5047b42bafb6710911e88fb1553d2833a221a94d2dc6fb55b7e500bc7873c4f09aab939e47aa959d55a972beacec8f7b86852b6842f4ca606908dea9d1cc7df',
};
const sdk = require("node-appwrite");

// Init SDK
const client = new sdk.Client();

const database = new sdk.Database(client);
const databases = new sdk.Databases(client);
const storage = new sdk.Storage(client);

client
.setSelfSigned(true)
.setProject(config.project)
.setKey(config.key)
// .setJWT('jwt') // set this to authenticate using JWT
.setEndpoint(config.endpoint)
;

const collectionName = 'tasks';
const read = ['role:all'];
const write = ['role:all'];

const promise = database.createCollection(collectionName, read, write);

promise.then(function(response) {
console.log('success');
database.createBooleanAttribute(response.$id, 'completed', true, false, false);
database.createStringAttribute(response.$id, 'text', 255, true, '', false);
}, function(error) {
console.log('error', error.type, error.message);
});
.setSelfSigned(true)
.setProject("playground")
// Update this key
.setKey(
"beb1e9fdeece6048ffa707a8cf19f3f645bce784def5135f3f8f5c91e382570ac26df1180105ba50068df79a20687fbc5b2af525fe2962550f42840175656444584cc84e97ec4b5ae57e342b912949c98224bac9d64ba6f3531ba33da707a07e0b0adb4155b95fbd32918aafba87338ab4c131f76d786cff4406c2af6bba9ef4"
)
.setEndpoint("https://localhost/v1");

(async function () {
try {
await databases.create("playground-db", "Playground Database");
console.log("successfully created database");

await databases.createCollection(
"playground-db",
"playground-collection",
"Playground Collection",
[
sdk.Permission.create("any"),
sdk.Permission.read("any"),
sdk.Permission.update("any"),
sdk.Permission.delete("any"),
]
);
console.log("successfully created collection");

await databases.createBooleanAttribute(
"playground-db",
"playground-collection",
"completed",
true
);
console.log("successfully created completed attribute");

await databases.createStringAttribute(
"playground-db",
"playground-collection",
"text",
255,
true,
"",
false
);
console.log("successfully created text attribute");

await storage.createBucket("playground-bucket", "Playground Bucket", [
sdk.Permission.create("any"),
sdk.Permission.read("any"),
sdk.Permission.update("any"),
sdk.Permission.delete("any"),
]);
console.log("successfully created playground-bucket");
} catch (error) {
console.log("error", error.type, error.message);
}
})();
50 changes: 26 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"homepage": "https://github.com/appwrite/playground-for-js#readme",
"dependencies": {
"appwrite": "^8.0.1",
"appwrite": "^10.1.0",
"express": "^4.18.1",
"node-appwrite": "5.1.0"
"node-appwrite": "^8.1.0"
}
}
21 changes: 12 additions & 9 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ <h2 class="mb-5">Locale</h2>
<!-- Include Appwrite Web SDK before trying to create a new instance -->

<!-- Fetch the latest sdk or use an existing one -->
<script src="https://cdn.jsdelivr.net/npm/appwrite@9.0.1"></script>
<script src="https://cdn.jsdelivr.net/npm/appwrite@10.1.0"></script>

<script>

Expand All @@ -204,7 +204,7 @@ <h2 class="mb-5">Locale</h2>

client
.setEndpoint("http://localhost/v1") // Set your own appwrite server endpoint here, if not sure, you can get this value from your project settings page.
.setProject("test"); // Your Appwrite Project UID, you can get it from your project settings page.
.setProject("playground"); // Your Appwrite Project UID, you can get it from your project settings page.

// Prepare all services we are going to use
const account = new Appwrite.Account(client);
Expand All @@ -224,8 +224,8 @@ <h2 class="mb-5">Locale</h2>

client.subscribe("files", function(response) {
const entry = document.createElement("li");
const image = storage.getFilePreview('testbucket', response.payload.$id, 250);
const url = storage.getFileView('testbucket', response.payload.$id, 250);
const image = storage.getFilePreview('playground-bucket', response.payload.$id, 250);
const url = storage.getFileView('playground-bucket', response.payload.$id, 250);
entry.classList.add('list-group-item');
entry.innerHTML = `<a href="${url}" target=_blank><b>Events</b>: ${response.events}<br><img src="${image}" /></a>`;
realtimeElement.prepend(entry);
Expand Down Expand Up @@ -275,7 +275,7 @@ <h2 class="mb-5">Locale</h2>
}

function getSessions() {
let promise = account.getSessions();
let promise = account.listSessions();

promise.then(
function (response) {
Expand All @@ -293,7 +293,7 @@ <h2 class="mb-5">Locale</h2>
}

function getLogs() {
let promise = account.getLogs();
let promise = account.listLogs();

promise.then(
function (response) {
Expand All @@ -311,6 +311,7 @@ <h2 class="mb-5">Locale</h2>
}

function register(event) {
event.preventDefault();
account
.create(
"unique()",
Expand Down Expand Up @@ -352,6 +353,7 @@ <h2 class="mb-5">Locale</h2>
}

function login(event) {
event.preventDefault();
account
.createEmailSession(
event.target.elements["login-email"].value, // Email
Expand Down Expand Up @@ -516,18 +518,19 @@ <h2 class="mb-5">Locale</h2>
}

function createFile() {
let promise = storage.createFile('testbucket', 'unique()', document.getElementById('uploader').files[0]);
let promise = storage.createFile('playground-bucket', 'unique()', document.getElementById('uploader').files[0]);

promise.then(function (response) {
console.log(response); // Success
alert("File uploaded successfully");
}, function (error) {
console.log(error); // Failure
alert("File failed to upload");
});
}

function listFiles() {
let promise = storage.listFiles('testbucket');
let promise = storage.listFiles('playground-bucket');

promise.then(function (response) {
var ul = document.getElementById("list");
Expand All @@ -548,7 +551,7 @@ <h2 class="mb-5">Locale</h2>
}

function getFile(file_id) {
let promise = storage.getFile('testbucket', file_id);
let promise = storage.getFile('playground-bucket', file_id);

promise.then(function (response) {
alert(JSON.stringify(response, undefined, 2));
Expand Down
22 changes: 13 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const sdk = require('node-appwrite');
const sdk = require("node-appwrite");

const client = new sdk.Client();

client
.setEndpoint('http://localhost/v1') // Your API Endpoint
.setProject('62387717329626ff1d5a') // Your project ID
.setKey('000615ffba60ade50ebabc4f13360f4b78a87b40d6f64e2d3eb3d7b248ed70495f8e6918327c12338d96e1f5a745360db915b7ec71e4e0694cf3c3bc4f9a33a78a183d651f64e75ba1f2f3b920a7fec5b04cb706ddbe962d6922a9631e855198e9d042c8205efcc45a19640e0f55b543570da692fe5bea94381632f161b10913') // Your secret API key
;
.setEndpoint("http://localhost/v1") // Your API Endpoint
.setProject("playground") // Your project ID
.setKey(
"beb1e9fdeece6048ffa707a8cf19f3f645bce784def5135f3f8f5c91e382570ac26df1180105ba50068df79a20687fbc5b2af525fe2962550f42840175656444584cc84e97ec4b5ae57e342b912949c98224bac9d64ba6f3531ba33da707a07e0b0adb4155b95fbd32918aafba87338ab4c131f76d786cff4406c2af6bba9ef4"
); // Your secret API key

let users = new sdk.Users(client);

let promise = users.get('623b66a849afa34b5d4e');
let promise = users.get("6334bfa0202f3a501716");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this ID hardcoded, what are we testing here? and why did this required an update?


promise.then(function (response) {
promise.then(
function (response) {
console.log(response);
}, function (error) {
},
function (error) {
console.log(error);
});
}
);