react-native-appwrite 0.7.4 → 0.9.1

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.
@@ -10,7 +10,7 @@ const result = avatars.getBrowser(
10
10
  Browser.AvantBrowser, // code
11
11
  0, // width (optional)
12
12
  0, // height (optional)
13
- 0 // quality (optional)
13
+ -1 // quality (optional)
14
14
  );
15
15
 
16
16
  console.log(result);
@@ -10,7 +10,7 @@ const result = avatars.getCreditCard(
10
10
  CreditCard.AmericanExpress, // code
11
11
  0, // width (optional)
12
12
  0, // height (optional)
13
- 0 // quality (optional)
13
+ -1 // quality (optional)
14
14
  );
15
15
 
16
16
  console.log(result);
@@ -10,7 +10,7 @@ const result = avatars.getFlag(
10
10
  Flag.Afghanistan, // code
11
11
  0, // width (optional)
12
12
  0, // height (optional)
13
- 0 // quality (optional)
13
+ -1 // quality (optional)
14
14
  );
15
15
 
16
16
  console.log(result);
@@ -2,7 +2,9 @@ import { Client, Databases } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
- .setProject('<YOUR_PROJECT_ID>'); // Your project ID
5
+ .setSession('') // The user session to authenticate with
6
+ .setKey('') //
7
+ .setJWT('<YOUR_JWT>'); // Your secret JSON Web Token
6
8
 
7
9
  const databases = new Databases(client);
8
10
 
@@ -0,0 +1,17 @@
1
+ import { Client, Databases } from "react-native-appwrite";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const databases = new Databases(client);
8
+
9
+ const result = await databases.upsertDocument(
10
+ '<DATABASE_ID>', // databaseId
11
+ '<COLLECTION_ID>', // collectionId
12
+ '<DOCUMENT_ID>', // documentId
13
+ {}, // data
14
+ ["read("any")"] // permissions (optional)
15
+ );
16
+
17
+ console.log(result);
@@ -8,8 +8,7 @@ const functions = new Functions(client);
8
8
 
9
9
  const result = await functions.listExecutions(
10
10
  '<FUNCTION_ID>', // functionId
11
- [], // queries (optional)
12
- '<SEARCH>' // search (optional)
11
+ [] // queries (optional)
13
12
  );
14
13
 
15
14
  console.log(result);
@@ -8,7 +8,8 @@ const storage = new Storage(client);
8
8
 
9
9
  const result = storage.getFileDownload(
10
10
  '<BUCKET_ID>', // bucketId
11
- '<FILE_ID>' // fileId
11
+ '<FILE_ID>', // fileId
12
+ '<TOKEN>' // token (optional)
12
13
  );
13
14
 
14
15
  console.log(result);
@@ -12,14 +12,15 @@ const result = storage.getFilePreview(
12
12
  0, // width (optional)
13
13
  0, // height (optional)
14
14
  ImageGravity.Center, // gravity (optional)
15
- 0, // quality (optional)
15
+ -1, // quality (optional)
16
16
  0, // borderWidth (optional)
17
17
  '', // borderColor (optional)
18
18
  0, // borderRadius (optional)
19
19
  0, // opacity (optional)
20
20
  -360, // rotation (optional)
21
21
  '', // background (optional)
22
- ImageFormat.Jpg // output (optional)
22
+ ImageFormat.Jpg, // output (optional)
23
+ '<TOKEN>' // token (optional)
23
24
  );
24
25
 
25
26
  console.log(result);
@@ -8,7 +8,8 @@ const storage = new Storage(client);
8
8
 
9
9
  const result = storage.getFileView(
10
10
  '<BUCKET_ID>', // bucketId
11
- '<FILE_ID>' // fileId
11
+ '<FILE_ID>', // fileId
12
+ '<TOKEN>' // token (optional)
12
13
  );
13
14
 
14
15
  console.log(result);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-native-appwrite",
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": "0.7.4",
5
+ "version": "0.9.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
package/src/client.ts CHANGED
@@ -108,14 +108,15 @@ class Client {
108
108
  jwt: '',
109
109
  locale: '',
110
110
  session: '',
111
+ devkey: '',
111
112
  platform: '',
112
113
  };
113
114
  headers: Headers = {
114
115
  'x-sdk-name': 'React Native',
115
116
  'x-sdk-platform': 'client',
116
117
  'x-sdk-language': 'reactnative',
117
- 'x-sdk-version': '0.7.4',
118
- 'X-Appwrite-Response-Format': '1.6.0',
118
+ 'x-sdk-version': '0.9.1',
119
+ 'X-Appwrite-Response-Format': '1.7.0',
119
120
  };
120
121
 
121
122
  /**
@@ -226,6 +227,21 @@ class Client {
226
227
  return this;
227
228
  }
228
229
 
230
+ /**
231
+ * Set DevKey
232
+ *
233
+ * Your secret dev API key
234
+ *
235
+ * @param value string
236
+ *
237
+ * @return {this}
238
+ */
239
+ setDevKey(value: string): this {
240
+ this.headers['X-Appwrite-Dev-Key'] = value;
241
+ this.config.devkey = value;
242
+ return this;
243
+ }
244
+
229
245
 
230
246
  private realtime: Realtime = {
231
247
  socket: undefined,
@@ -1,7 +1,6 @@
1
1
  export enum ImageFormat {
2
2
  Jpg = 'jpg',
3
3
  Jpeg = 'jpeg',
4
- Gif = 'gif',
5
4
  Png = 'png',
6
5
  Webp = 'webp',
7
6
  Heic = 'heic',
package/src/models.ts CHANGED
@@ -940,7 +940,7 @@ export namespace Models {
940
940
  */
941
941
  errors: string;
942
942
  /**
943
- * Function execution duration in seconds.
943
+ * Resource(function/site) execution duration in seconds.
944
944
  */
945
945
  duration: number;
946
946
  /**
@@ -132,6 +132,54 @@ export class Databases extends Service {
132
132
  }, payload);
133
133
  }
134
134
 
135
+ /**
136
+ * Create or update a Document. Before using this route, you should create a
137
+ * new collection resource using either a [server
138
+ * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
139
+ * API or directly from your database console.
140
+ *
141
+ * @param {string} databaseId
142
+ * @param {string} collectionId
143
+ * @param {string} documentId
144
+ * @param {object} data
145
+ * @param {string[]} permissions
146
+ * @throws {AppwriteException}
147
+ * @returns {Promise}
148
+ */
149
+ upsertDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise<Document> {
150
+ if (typeof databaseId === 'undefined') {
151
+ throw new AppwriteException('Missing required parameter: "databaseId"');
152
+ }
153
+
154
+ if (typeof collectionId === 'undefined') {
155
+ throw new AppwriteException('Missing required parameter: "collectionId"');
156
+ }
157
+
158
+ if (typeof documentId === 'undefined') {
159
+ throw new AppwriteException('Missing required parameter: "documentId"');
160
+ }
161
+
162
+ if (typeof data === 'undefined') {
163
+ throw new AppwriteException('Missing required parameter: "data"');
164
+ }
165
+
166
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
167
+ const payload: Payload = {};
168
+
169
+ if (typeof data !== 'undefined') {
170
+ payload['data'] = data;
171
+ }
172
+
173
+ if (typeof permissions !== 'undefined') {
174
+ payload['permissions'] = permissions;
175
+ }
176
+
177
+ const uri = new URL(this.client.config.endpoint + apiPath);
178
+ return this.client.call('put', uri, {
179
+ 'content-type': 'application/json',
180
+ }, payload);
181
+ }
182
+
135
183
  /**
136
184
  * Update a document by its unique ID. Using the patch method you can pass
137
185
  * only specific fields that will get updated.
@@ -20,11 +20,10 @@ export class Functions extends Service {
20
20
  *
21
21
  * @param {string} functionId
22
22
  * @param {string[]} queries
23
- * @param {string} search
24
23
  * @throws {AppwriteException}
25
24
  * @returns {Promise}
26
25
  */
27
- listExecutions(functionId: string, queries?: string[], search?: string): Promise<Models.ExecutionList> {
26
+ listExecutions(functionId: string, queries?: string[]): Promise<Models.ExecutionList> {
28
27
  if (typeof functionId === 'undefined') {
29
28
  throw new AppwriteException('Missing required parameter: "functionId"');
30
29
  }
@@ -36,10 +35,6 @@ export class Functions extends Service {
36
35
  payload['queries'] = queries;
37
36
  }
38
37
 
39
- if (typeof search !== 'undefined') {
40
- payload['search'] = search;
41
- }
42
-
43
38
  const uri = new URL(this.client.config.endpoint + apiPath);
44
39
  return this.client.call('get', uri, {
45
40
  }, payload);
@@ -258,10 +258,11 @@ export class Storage extends Service {
258
258
  *
259
259
  * @param {string} bucketId
260
260
  * @param {string} fileId
261
+ * @param {string} token
261
262
  * @throws {AppwriteException}
262
263
  * @returns {URL}
263
264
  */
264
- getFileDownload(bucketId: string, fileId: string): URL {
265
+ getFileDownload(bucketId: string, fileId: string, token?: string): URL {
265
266
  if (typeof bucketId === 'undefined') {
266
267
  throw new AppwriteException('Missing required parameter: "bucketId"');
267
268
  }
@@ -273,6 +274,10 @@ export class Storage extends Service {
273
274
  const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
274
275
  const payload: Payload = {};
275
276
 
277
+ if (typeof token !== 'undefined') {
278
+ payload['token'] = token;
279
+ }
280
+
276
281
  const uri = new URL(this.client.config.endpoint + apiPath);
277
282
  payload['project'] = this.client.config.project;
278
283
 
@@ -303,10 +308,11 @@ export class Storage extends Service {
303
308
  * @param {number} rotation
304
309
  * @param {string} background
305
310
  * @param {ImageFormat} output
311
+ * @param {string} token
306
312
  * @throws {AppwriteException}
307
313
  * @returns {URL}
308
314
  */
309
- getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): URL {
315
+ getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string): URL {
310
316
  if (typeof bucketId === 'undefined') {
311
317
  throw new AppwriteException('Missing required parameter: "bucketId"');
312
318
  }
@@ -362,6 +368,10 @@ export class Storage extends Service {
362
368
  payload['output'] = output;
363
369
  }
364
370
 
371
+ if (typeof token !== 'undefined') {
372
+ payload['token'] = token;
373
+ }
374
+
365
375
  const uri = new URL(this.client.config.endpoint + apiPath);
366
376
  payload['project'] = this.client.config.project;
367
377
 
@@ -379,10 +389,11 @@ export class Storage extends Service {
379
389
  *
380
390
  * @param {string} bucketId
381
391
  * @param {string} fileId
392
+ * @param {string} token
382
393
  * @throws {AppwriteException}
383
394
  * @returns {URL}
384
395
  */
385
- getFileView(bucketId: string, fileId: string): URL {
396
+ getFileView(bucketId: string, fileId: string, token?: string): URL {
386
397
  if (typeof bucketId === 'undefined') {
387
398
  throw new AppwriteException('Missing required parameter: "bucketId"');
388
399
  }
@@ -394,6 +405,10 @@ export class Storage extends Service {
394
405
  const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
395
406
  const payload: Payload = {};
396
407
 
408
+ if (typeof token !== 'undefined') {
409
+ payload['token'] = token;
410
+ }
411
+
397
412
  const uri = new URL(this.client.config.endpoint + apiPath);
398
413
  payload['project'] = this.client.config.project;
399
414
 
package/types/client.d.ts CHANGED
@@ -32,6 +32,7 @@ declare class Client {
32
32
  jwt: string;
33
33
  locale: string;
34
34
  session: string;
35
+ devkey: string;
35
36
  platform: string;
36
37
  };
37
38
  headers: Headers;
@@ -100,6 +101,16 @@ declare class Client {
100
101
  * @return {this}
101
102
  */
102
103
  setSession(value: string): this;
104
+ /**
105
+ * Set DevKey
106
+ *
107
+ * Your secret dev API key
108
+ *
109
+ * @param value string
110
+ *
111
+ * @return {this}
112
+ */
113
+ setDevKey(value: string): this;
103
114
  private realtime;
104
115
  /**
105
116
  * Subscribes to Appwrite events and passes you the payload in realtime.
@@ -1,7 +1,6 @@
1
1
  export declare enum ImageFormat {
2
2
  Jpg = "jpg",
3
3
  Jpeg = "jpeg",
4
- Gif = "gif",
5
4
  Png = "png",
6
5
  Webp = "webp",
7
6
  Heic = "heic",
package/types/models.d.ts CHANGED
@@ -940,7 +940,7 @@ export declare namespace Models {
940
940
  */
941
941
  errors: string;
942
942
  /**
943
- * Function execution duration in seconds.
943
+ * Resource(function/site) execution duration in seconds.
944
944
  */
945
945
  duration: number;
946
946
  /**
@@ -41,6 +41,21 @@ export declare class Databases extends Service {
41
41
  * @returns {Promise}
42
42
  */
43
43
  getDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise<Document>;
44
+ /**
45
+ * Create or update a Document. Before using this route, you should create a
46
+ * new collection resource using either a [server
47
+ * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
48
+ * API or directly from your database console.
49
+ *
50
+ * @param {string} databaseId
51
+ * @param {string} collectionId
52
+ * @param {string} documentId
53
+ * @param {object} data
54
+ * @param {string[]} permissions
55
+ * @throws {AppwriteException}
56
+ * @returns {Promise}
57
+ */
58
+ upsertDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise<Document>;
44
59
  /**
45
60
  * Update a document by its unique ID. Using the patch method you can pass
46
61
  * only specific fields that will get updated.
@@ -10,11 +10,10 @@ export declare class Functions extends Service {
10
10
  *
11
11
  * @param {string} functionId
12
12
  * @param {string[]} queries
13
- * @param {string} search
14
13
  * @throws {AppwriteException}
15
14
  * @returns {Promise}
16
15
  */
17
- listExecutions(functionId: string, queries?: string[], search?: string): Promise<Models.ExecutionList>;
16
+ listExecutions(functionId: string, queries?: string[]): Promise<Models.ExecutionList>;
18
17
  /**
19
18
  * Trigger a function execution. The returned object will return you the
20
19
  * current execution status. You can ping the `Get Execution` endpoint to get
@@ -89,10 +89,11 @@ export declare class Storage extends Service {
89
89
  *
90
90
  * @param {string} bucketId
91
91
  * @param {string} fileId
92
+ * @param {string} token
92
93
  * @throws {AppwriteException}
93
94
  * @returns {URL}
94
95
  */
95
- getFileDownload(bucketId: string, fileId: string): URL;
96
+ getFileDownload(bucketId: string, fileId: string, token?: string): URL;
96
97
  /**
97
98
  * Get a file preview image. Currently, this method supports preview for image
98
99
  * files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
@@ -113,10 +114,11 @@ export declare class Storage extends Service {
113
114
  * @param {number} rotation
114
115
  * @param {string} background
115
116
  * @param {ImageFormat} output
117
+ * @param {string} token
116
118
  * @throws {AppwriteException}
117
119
  * @returns {URL}
118
120
  */
119
- getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): URL;
121
+ getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string): URL;
120
122
  /**
121
123
  * Get a file content by its unique ID. This endpoint is similar to the
122
124
  * download method but returns with no 'Content-Disposition: attachment'
@@ -124,8 +126,9 @@ export declare class Storage extends Service {
124
126
  *
125
127
  * @param {string} bucketId
126
128
  * @param {string} fileId
129
+ * @param {string} token
127
130
  * @throws {AppwriteException}
128
131
  * @returns {URL}
129
132
  */
130
- getFileView(bucketId: string, fileId: string): URL;
133
+ getFileView(bucketId: string, fileId: string, token?: string): URL;
131
134
  }