diff --git a/README.md b/README.md index 86a5b0b..ed95d79 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Web SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.4.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.4.2-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) @@ -33,7 +33,7 @@ import { Client, Account } from "appwrite"; To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services: ```html - + ``` diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index fded560..3e47077 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -9,7 +9,7 @@ client .setProject('5df5acd0d48c2') // Your project ID ; -const promise = teams.createMembership('[TEAM_ID]', [], 'https://example.com'); +const promise = teams.createMembership('[TEAM_ID]', []); promise.then(function (response) { console.log(response); // Success diff --git a/package.json b/package.json index 96a7437..a40c020 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite", "homepage": "https://appwrite.io/support", "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", - "version": "12.0.0", + "version": "13.0.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 72c85f9..4e43261 100644 --- a/src/client.ts +++ b/src/client.ts @@ -102,7 +102,7 @@ class Client { 'x-sdk-name': 'Web', 'x-sdk-platform': 'client', 'x-sdk-language': 'web', - 'x-sdk-version': '12.0.0', + 'x-sdk-version': '13.0.0', 'X-Appwrite-Response-Format': '1.4.0', }; diff --git a/src/role.ts b/src/role.ts index d94e398..79f8c6b 100644 --- a/src/role.ts +++ b/src/role.ts @@ -1,34 +1,100 @@ +/** + * Helper class to generate role strings for `Permission`. + */ export class Role { + + /** + * Grants access to anyone. + * + * This includes authenticated and unauthenticated users. + * + * @returns {string} + */ public static any(): string { return 'any' } + /** + * Grants access to a specific user by user ID. + * + * You can optionally pass verified or unverified for + * `status` to target specific types of users. + * + * @param {string} id + * @param {string} status + * @returns {string} + */ public static user(id: string, status: string = ''): string { - if(status === '') { + if (status === '') { return `user:${id}` } return `user:${id}/${status}` } - + + /** + * Grants access to any authenticated or anonymous user. + * + * You can optionally pass verified or unverified for + * `status` to target specific types of users. + * + * @param {string} status + * @returns {string} + */ public static users(status: string = ''): string { - if(status === '') { + if (status === '') { return 'users' } return `users/${status}` } - + + /** + * Grants access to any guest user without a session. + * + * Authenticated users don't have access to this role. + * + * @returns {string} + */ public static guests(): string { return 'guests' } - + + /** + * Grants access to a team by team ID. + * + * You can optionally pass a role for `role` to target + * team members with the specified role. + * + * @param {string} id + * @param {string} role + * @returns {string} + */ public static team(id: string, role: string = ''): string { - if(role === '') { + if (role === '') { return `team:${id}` } return `team:${id}/${role}` } + /** + * Grants access to a specific member of a team. + * + * When the member is removed from the team, they will + * no longer have access. + * + * @param {string} id + * @returns {string} + */ public static member(id: string): string { return `member:${id}` } + + /** + * Grants access to a user with the specified label. + * + * @param {string} name + * @returns {string} + */ + public static label(name: string): string { + return `label:${name}` + } } \ No newline at end of file diff --git a/src/services/storage.ts b/src/services/storage.ts index 708d65a..b23e851 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -111,57 +111,47 @@ export class Storage extends Service { if (size <= Service.CHUNK_SIZE) { return await this.client.call('post', uri, { - 'content-type': 'multipart/form-data', }, payload); } - let id = undefined; - let response = undefined; - const headers: { [header: string]: string } = { + const apiHeaders: { [header: string]: string } = { 'content-type': 'multipart/form-data', } - let counter = 0; - const totalCounters = Math.ceil(size / Service.CHUNK_SIZE); + let offset = 0; + let response = undefined; if(fileId != 'unique()') { try { - response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), headers); - counter = response.chunksUploaded; + response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders); + offset = response.chunksUploaded * Service.CHUNK_SIZE; } catch(e) { } } - for (counter; counter < totalCounters; counter++) { - const start = (counter * Service.CHUNK_SIZE); - const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size); - - headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size + while (offset < size) { + let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1); - if (id) { - headers['x-appwrite-id'] = id; + apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size; + if (response && response.$id) { + apiHeaders['x-appwrite-id'] = response.$id; } - const stream = file.slice(start, end + 1); - payload['file'] = new File([stream], file.name); - - response = await this.client.call('post', uri, headers, payload); - - if (!id) { - id = response['$id']; - } + const chunk = file.slice(offset, end + 1); + payload['file'] = new File([chunk], file.name); + response = await this.client.call('post', uri, apiHeaders, payload); if (onProgress) { onProgress({ $id: response.$id, - progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100, - sizeUploaded: end, + progress: (offset / size) * 100, + sizeUploaded: offset, chunksTotal: response.chunksTotal, chunksUploaded: response.chunksUploaded }); } + offset += Service.CHUNK_SIZE; } - return response; } diff --git a/src/services/teams.ts b/src/services/teams.ts index a3967c2..3559dca 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -222,15 +222,15 @@ export class Teams extends Service { * * @param {string} teamId * @param {string[]} roles - * @param {string} url * @param {string} email * @param {string} userId * @param {string} phone + * @param {string} url * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - async createMembership(teamId: string, roles: string[], url: string, email?: string, userId?: string, phone?: string, name?: string): Promise { + async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -239,10 +239,6 @@ export class Teams extends Service { throw new AppwriteException('Missing required parameter: "roles"'); } - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); const payload: Payload = {};