react-native-appwrite 0.9.0 → 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.
@@ -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);
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.9.0",
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,13 +108,14 @@ 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.9.0',
118
+ 'x-sdk-version': '0.9.1',
118
119
  'X-Appwrite-Response-Format': '1.7.0',
119
120
  };
120
121
 
@@ -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,
@@ -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.
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.
@@ -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.