Skip to content

Commit ca4ef6d

Browse files
Merge pull request #74 from appwrite/dev
fix: for appwrite 1.4.x
2 parents 1b03080 + 02ce252 commit ca4ef6d

File tree

7 files changed

+95
-43
lines changed

7 files changed

+95
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Appwrite Web SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.4.0-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.4.2-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![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";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@12.0.0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@13.0.0"></script>
3737
```
3838

3939

docs/examples/teams/create-membership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ client
99
.setProject('5df5acd0d48c2') // Your project ID
1010
;
1111

12-
const promise = teams.createMembership('[TEAM_ID]', [], 'https://example.com');
12+
const promise = teams.createMembership('[TEAM_ID]', []);
1313

1414
promise.then(function (response) {
1515
console.log(response); // Success

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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": "12.0.0",
5+
"version": "13.0.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Client {
102102
'x-sdk-name': 'Web',
103103
'x-sdk-platform': 'client',
104104
'x-sdk-language': 'web',
105-
'x-sdk-version': '12.0.0',
105+
'x-sdk-version': '13.0.0',
106106
'X-Appwrite-Response-Format': '1.4.0',
107107
};
108108

src/role.ts

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,100 @@
1+
/**
2+
* Helper class to generate role strings for `Permission`.
3+
*/
14
export class Role {
5+
6+
/**
7+
* Grants access to anyone.
8+
*
9+
* This includes authenticated and unauthenticated users.
10+
*
11+
* @returns {string}
12+
*/
213
public static any(): string {
314
return 'any'
415
}
516

17+
/**
18+
* Grants access to a specific user by user ID.
19+
*
20+
* You can optionally pass verified or unverified for
21+
* `status` to target specific types of users.
22+
*
23+
* @param {string} id
24+
* @param {string} status
25+
* @returns {string}
26+
*/
627
public static user(id: string, status: string = ''): string {
7-
if(status === '') {
28+
if (status === '') {
829
return `user:${id}`
930
}
1031
return `user:${id}/${status}`
1132
}
12-
33+
34+
/**
35+
* Grants access to any authenticated or anonymous user.
36+
*
37+
* You can optionally pass verified or unverified for
38+
* `status` to target specific types of users.
39+
*
40+
* @param {string} status
41+
* @returns {string}
42+
*/
1343
public static users(status: string = ''): string {
14-
if(status === '') {
44+
if (status === '') {
1545
return 'users'
1646
}
1747
return `users/${status}`
1848
}
19-
49+
50+
/**
51+
* Grants access to any guest user without a session.
52+
*
53+
* Authenticated users don't have access to this role.
54+
*
55+
* @returns {string}
56+
*/
2057
public static guests(): string {
2158
return 'guests'
2259
}
23-
60+
61+
/**
62+
* Grants access to a team by team ID.
63+
*
64+
* You can optionally pass a role for `role` to target
65+
* team members with the specified role.
66+
*
67+
* @param {string} id
68+
* @param {string} role
69+
* @returns {string}
70+
*/
2471
public static team(id: string, role: string = ''): string {
25-
if(role === '') {
72+
if (role === '') {
2673
return `team:${id}`
2774
}
2875
return `team:${id}/${role}`
2976
}
3077

78+
/**
79+
* Grants access to a specific member of a team.
80+
*
81+
* When the member is removed from the team, they will
82+
* no longer have access.
83+
*
84+
* @param {string} id
85+
* @returns {string}
86+
*/
3187
public static member(id: string): string {
3288
return `member:${id}`
3389
}
90+
91+
/**
92+
* Grants access to a user with the specified label.
93+
*
94+
* @param {string} name
95+
* @returns {string}
96+
*/
97+
public static label(name: string): string {
98+
return `label:${name}`
99+
}
34100
}

src/services/storage.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,57 +111,47 @@ export class Storage extends Service {
111111

112112
if (size <= Service.CHUNK_SIZE) {
113113
return await this.client.call('post', uri, {
114-
115114
'content-type': 'multipart/form-data',
116115
}, payload);
117116
}
118-
let id = undefined;
119-
let response = undefined;
120117

121-
const headers: { [header: string]: string } = {
118+
const apiHeaders: { [header: string]: string } = {
122119
'content-type': 'multipart/form-data',
123120
}
124121

125-
let counter = 0;
126-
const totalCounters = Math.ceil(size / Service.CHUNK_SIZE);
122+
let offset = 0;
123+
let response = undefined;
127124
if(fileId != 'unique()') {
128125
try {
129-
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), headers);
130-
counter = response.chunksUploaded;
126+
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
127+
offset = response.chunksUploaded * Service.CHUNK_SIZE;
131128
} catch(e) {
132129
}
133130
}
134131

135-
for (counter; counter < totalCounters; counter++) {
136-
const start = (counter * Service.CHUNK_SIZE);
137-
const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size);
138-
139-
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size
132+
while (offset < size) {
133+
let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
140134

141-
if (id) {
142-
headers['x-appwrite-id'] = id;
135+
apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
136+
if (response && response.$id) {
137+
apiHeaders['x-appwrite-id'] = response.$id;
143138
}
144139

145-
const stream = file.slice(start, end + 1);
146-
payload['file'] = new File([stream], file.name);
147-
148-
response = await this.client.call('post', uri, headers, payload);
149-
150-
if (!id) {
151-
id = response['$id'];
152-
}
140+
const chunk = file.slice(offset, end + 1);
141+
payload['file'] = new File([chunk], file.name);
142+
response = await this.client.call('post', uri, apiHeaders, payload);
153143

154144
if (onProgress) {
155145
onProgress({
156146
$id: response.$id,
157-
progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100,
158-
sizeUploaded: end,
147+
progress: (offset / size) * 100,
148+
sizeUploaded: offset,
159149
chunksTotal: response.chunksTotal,
160150
chunksUploaded: response.chunksUploaded
161151
});
162152
}
153+
offset += Service.CHUNK_SIZE;
163154
}
164-
165155
return response;
166156
}
167157

src/services/teams.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ export class Teams extends Service {
222222
*
223223
* @param {string} teamId
224224
* @param {string[]} roles
225-
* @param {string} url
226225
* @param {string} email
227226
* @param {string} userId
228227
* @param {string} phone
228+
* @param {string} url
229229
* @param {string} name
230230
* @throws {AppwriteException}
231231
* @returns {Promise}
232232
*/
233-
async createMembership(teamId: string, roles: string[], url: string, email?: string, userId?: string, phone?: string, name?: string): Promise<Models.Membership> {
233+
async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise<Models.Membership> {
234234
if (typeof teamId === 'undefined') {
235235
throw new AppwriteException('Missing required parameter: "teamId"');
236236
}
@@ -239,10 +239,6 @@ export class Teams extends Service {
239239
throw new AppwriteException('Missing required parameter: "roles"');
240240
}
241241

242-
if (typeof url === 'undefined') {
243-
throw new AppwriteException('Missing required parameter: "url"');
244-
}
245-
246242
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
247243
const payload: Payload = {};
248244

0 commit comments

Comments
 (0)