react-native-appwrite 0.5.0 → 0.7.0

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.
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.5.0",
5
+ "version": "0.7.0",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
package/src/client.ts CHANGED
@@ -11,8 +11,8 @@ type Headers = {
11
11
  }
12
12
 
13
13
  type RealtimeResponse = {
14
- type: 'error' | 'event' | 'connected' | 'response';
15
- data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown>;
14
+ type: 'error' | 'event' | 'connected' | 'response' | 'pong';
15
+ data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown> | undefined;
16
16
  }
17
17
 
18
18
  type RealtimeRequest = {
@@ -49,7 +49,17 @@ type RealtimeRequestAuthenticate = {
49
49
 
50
50
  type Realtime = {
51
51
  socket?: WebSocket;
52
+
53
+ /**
54
+ * Timeout for reconnect operations.
55
+ */
52
56
  timeout?: number;
57
+
58
+ /**
59
+ * Heartbeat interval for the realtime connection.
60
+ */
61
+ heartbeat?: number;
62
+
53
63
  url?: string;
54
64
  lastMessage?: RealtimeResponse;
55
65
  channels: Set<string>;
@@ -63,6 +73,7 @@ type Realtime = {
63
73
  getTimeout: () => number;
64
74
  connect: () => void;
65
75
  createSocket: () => void;
76
+ createHeartbeat: () => void;
66
77
  cleanUp: (channels: string[]) => void;
67
78
  onMessage: (event: MessageEvent) => void;
68
79
  }
@@ -103,7 +114,7 @@ class Client {
103
114
  'x-sdk-name': 'React Native',
104
115
  'x-sdk-platform': 'client',
105
116
  'x-sdk-language': 'reactnative',
106
- 'x-sdk-version': '0.5.0',
117
+ 'x-sdk-version': '0.7.0',
107
118
  'X-Appwrite-Response-Format': '1.6.0',
108
119
  };
109
120
 
@@ -212,6 +223,7 @@ class Client {
212
223
  private realtime: Realtime = {
213
224
  socket: undefined,
214
225
  timeout: undefined,
226
+ heartbeat: undefined,
215
227
  url: '',
216
228
  channels: new Set(),
217
229
  subscriptions: new Map(),
@@ -237,6 +249,17 @@ class Client {
237
249
  return 60_000;
238
250
  }
239
251
  },
252
+ createHeartbeat: () => {
253
+ if (this.realtime.heartbeat) {
254
+ clearTimeout(this.realtime.heartbeat);
255
+ }
256
+
257
+ this.realtime.heartbeat = window?.setInterval(() => {
258
+ this.realtime.socket?.send(JSON.stringify({
259
+ type: 'ping'
260
+ }));
261
+ }, 20_000);
262
+ },
240
263
  createSocket: () => {
241
264
  if (this.realtime.channels.size < 1) {
242
265
  this.realtime.reconnect = false;
@@ -275,6 +298,7 @@ class Client {
275
298
  this.realtime.socket.addEventListener('message', this.realtime.onMessage);
276
299
  this.realtime.socket.addEventListener('open', _event => {
277
300
  this.realtime.reconnectAttempts = 0;
301
+ this.realtime.createHeartbeat();
278
302
  });
279
303
  this.realtime.socket.addEventListener('close', event => {
280
304
  if (
@@ -315,6 +339,8 @@ class Client {
315
339
  })
316
340
  }
317
341
  break;
342
+ case 'pong':
343
+ break; // Handle pong response if needed
318
344
  case 'error':
319
345
  throw message.data;
320
346
  default:
@@ -4,4 +4,6 @@ export enum ImageFormat {
4
4
  Gif = 'gif',
5
5
  Png = 'png',
6
6
  Webp = 'webp',
7
+ Heic = 'heic',
8
+ Avif = 'avif',
7
9
  }
package/src/models.ts CHANGED
@@ -839,11 +839,11 @@ export namespace Models {
839
839
  */
840
840
  userId: string;
841
841
  /**
842
- * User name.
842
+ * User name. Hide this attribute by toggling membership privacy in the Console.
843
843
  */
844
844
  userName: string;
845
845
  /**
846
- * User email address.
846
+ * User email address. Hide this attribute by toggling membership privacy in the Console.
847
847
  */
848
848
  userEmail: string;
849
849
  /**
@@ -867,7 +867,7 @@ export namespace Models {
867
867
  */
868
868
  confirm: boolean;
869
869
  /**
870
- * Multi factor authentication status, true if the user has MFA enabled or false otherwise.
870
+ * Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
871
871
  */
872
872
  mfa: boolean;
873
873
  /**
@@ -1195,5 +1195,9 @@ export namespace Models {
1195
1195
  * The target identifier.
1196
1196
  */
1197
1197
  identifier: string;
1198
+ /**
1199
+ * Is the target expired.
1200
+ */
1201
+ expired: boolean;
1198
1202
  }
1199
1203
  }
@@ -134,7 +134,7 @@ export class Account extends Service {
134
134
  }
135
135
 
136
136
  /**
137
- * List Identities
137
+ * List identities
138
138
  *
139
139
  * Get the list of identities for the currently logged in user.
140
140
  *
@@ -253,7 +253,7 @@ export class Account extends Service {
253
253
  }
254
254
 
255
255
  /**
256
- * Create Authenticator
256
+ * Create authenticator
257
257
  *
258
258
  * Add an authenticator app to be used as an MFA factor. Verify the
259
259
  * authenticator using the [verify
@@ -279,7 +279,7 @@ export class Account extends Service {
279
279
  }
280
280
 
281
281
  /**
282
- * Verify Authenticator
282
+ * Verify authenticator
283
283
  *
284
284
  * Verify an authenticator app after adding it using the [add
285
285
  * authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
@@ -313,7 +313,7 @@ export class Account extends Service {
313
313
  }
314
314
 
315
315
  /**
316
- * Delete Authenticator
316
+ * Delete authenticator
317
317
  *
318
318
  * Delete an authenticator for a user by ID.
319
319
  *
@@ -336,7 +336,7 @@ export class Account extends Service {
336
336
  }
337
337
 
338
338
  /**
339
- * Create MFA Challenge
339
+ * Create MFA challenge
340
340
  *
341
341
  * Begin the process of MFA verification after sign-in. Finish the flow with
342
342
  * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
@@ -365,7 +365,7 @@ export class Account extends Service {
365
365
  }
366
366
 
367
367
  /**
368
- * Create MFA Challenge (confirmation)
368
+ * Create MFA challenge (confirmation)
369
369
  *
370
370
  * Complete the MFA challenge by providing the one-time password. Finish the
371
371
  * process of MFA verification by providing the one-time password. To begin
@@ -378,7 +378,7 @@ export class Account extends Service {
378
378
  * @throws {AppwriteException}
379
379
  * @returns {Promise}
380
380
  */
381
- async updateMfaChallenge(challengeId: string, otp: string): Promise<{}> {
381
+ async updateMfaChallenge(challengeId: string, otp: string): Promise<Models.Session> {
382
382
  if (typeof challengeId === 'undefined') {
383
383
  throw new AppwriteException('Missing required parameter: "challengeId"');
384
384
  }
@@ -405,7 +405,7 @@ export class Account extends Service {
405
405
  }
406
406
 
407
407
  /**
408
- * List Factors
408
+ * List factors
409
409
  *
410
410
  * List the factors available on the account to be used as a MFA challange.
411
411
  *
@@ -423,7 +423,7 @@ export class Account extends Service {
423
423
  }
424
424
 
425
425
  /**
426
- * Get MFA Recovery Codes
426
+ * Get MFA recovery codes
427
427
  *
428
428
  * Get recovery codes that can be used as backup for MFA flow. Before getting
429
429
  * codes, they must be generated using
@@ -444,7 +444,7 @@ export class Account extends Service {
444
444
  }
445
445
 
446
446
  /**
447
- * Create MFA Recovery Codes
447
+ * Create MFA recovery codes
448
448
  *
449
449
  * Generate recovery codes as backup for MFA flow. It's recommended to
450
450
  * generate and show then immediately after user successfully adds their
@@ -466,7 +466,7 @@ export class Account extends Service {
466
466
  }
467
467
 
468
468
  /**
469
- * Regenerate MFA Recovery Codes
469
+ * Regenerate MFA recovery codes
470
470
  *
471
471
  * Regenerate recovery codes that can be used as backup for MFA flow. Before
472
472
  * regenerating codes, they must be first generated using
@@ -1104,6 +1104,11 @@ export class Account extends Service {
1104
1104
  /**
1105
1105
  * Create push target
1106
1106
  *
1107
+ * Use this endpoint to register a device for push notifications. Provide a
1108
+ * target ID (custom or generated using ID.unique()), a device identifier
1109
+ * (usually a device token), and optionally specify which provider should send
1110
+ * notifications to this target. The target is automatically linked to the
1111
+ * current session and includes device information like brand and model.
1107
1112
  *
1108
1113
  * @param {string} targetId
1109
1114
  * @param {string} identifier
@@ -1144,6 +1149,11 @@ export class Account extends Service {
1144
1149
  /**
1145
1150
  * Update push target
1146
1151
  *
1152
+ * Update the currently logged in user's push notification target. You can
1153
+ * modify the target's identifier (device token) and provider ID (token,
1154
+ * email, phone etc.). The target must exist and belong to the current user.
1155
+ * If you change the provider ID, notifications will be sent through the new
1156
+ * messaging provider instead.
1147
1157
  *
1148
1158
  * @param {string} targetId
1149
1159
  * @param {string} identifier
@@ -1175,6 +1185,9 @@ export class Account extends Service {
1175
1185
  /**
1176
1186
  * Delete push target
1177
1187
  *
1188
+ * Delete a push notification target for the currently logged in user. After
1189
+ * deletion, the device will no longer receive push notifications. The target
1190
+ * must exist and belong to the current user.
1178
1191
  *
1179
1192
  * @param {string} targetId
1180
1193
  * @throws {AppwriteException}
@@ -1255,9 +1268,7 @@ export class Account extends Service {
1255
1268
  * [POST
1256
1269
  * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1257
1270
  * endpoint to complete the login process. The link sent to the user's email
1258
- * address is valid for 1 hour. If you are on a mobile device you can leave
1259
- * the URL parameter empty, so that the login completion will be handled by
1260
- * your Appwrite instance by default.
1271
+ * address is valid for 1 hour.
1261
1272
  *
1262
1273
  * A user is limited to 10 active sessions at a time by default. [Learn more
1263
1274
  * about session
@@ -37,7 +37,7 @@ export class Locale extends Service {
37
37
  }
38
38
 
39
39
  /**
40
- * List Locale Codes
40
+ * List locale codes
41
41
  *
42
42
  * List of all locale codes in [ISO
43
43
  * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
@@ -122,12 +122,10 @@ export class Storage extends Service {
122
122
 
123
123
  let offset = 0;
124
124
  let response = undefined;
125
- if(fileId != 'unique()') {
126
- try {
127
- response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
128
- offset = response.chunksUploaded * Service.CHUNK_SIZE;
129
- } catch(e) {
130
- }
125
+ try {
126
+ response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
127
+ offset = response.chunksUploaded * Service.CHUNK_SIZE;
128
+ } catch(e) {
131
129
  }
132
130
 
133
131
  let timestamp = new Date().getTime();
@@ -237,7 +235,7 @@ export class Storage extends Service {
237
235
  }
238
236
 
239
237
  /**
240
- * Delete File
238
+ * Delete file
241
239
  *
242
240
  * Delete a file by its unique ID. Only users with write permissions have
243
241
  * access to delete this resource.
@@ -168,7 +168,8 @@ export class Teams extends Service {
168
168
  * List team memberships
169
169
  *
170
170
  * Use this endpoint to list a team's members using the team's ID. All team
171
- * members have read access to this endpoint.
171
+ * members have read access to this endpoint. Hide sensitive attributes from
172
+ * the response by toggling membership privacy in the Console.
172
173
  *
173
174
  * @param {string} teamId
174
175
  * @param {string[]} queries
@@ -279,7 +280,8 @@ export class Teams extends Service {
279
280
  * Get team membership
280
281
  *
281
282
  * Get a team member by the membership unique id. All team members have read
282
- * access for this resource.
283
+ * access for this resource. Hide sensitive attributes from the response by
284
+ * toggling membership privacy in the Console.
283
285
  *
284
286
  * @param {string} teamId
285
287
  * @param {string} membershipId
@@ -3,5 +3,7 @@ export declare enum ImageFormat {
3
3
  Jpeg = "jpeg",
4
4
  Gif = "gif",
5
5
  Png = "png",
6
- Webp = "webp"
6
+ Webp = "webp",
7
+ Heic = "heic",
8
+ Avif = "avif"
7
9
  }
package/types/models.d.ts CHANGED
@@ -839,11 +839,11 @@ export declare namespace Models {
839
839
  */
840
840
  userId: string;
841
841
  /**
842
- * User name.
842
+ * User name. Hide this attribute by toggling membership privacy in the Console.
843
843
  */
844
844
  userName: string;
845
845
  /**
846
- * User email address.
846
+ * User email address. Hide this attribute by toggling membership privacy in the Console.
847
847
  */
848
848
  userEmail: string;
849
849
  /**
@@ -867,7 +867,7 @@ export declare namespace Models {
867
867
  */
868
868
  confirm: boolean;
869
869
  /**
870
- * Multi factor authentication status, true if the user has MFA enabled or false otherwise.
870
+ * Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
871
871
  */
872
872
  mfa: boolean;
873
873
  /**
@@ -1195,5 +1195,9 @@ export declare namespace Models {
1195
1195
  * The target identifier.
1196
1196
  */
1197
1197
  identifier: string;
1198
+ /**
1199
+ * Is the target expired.
1200
+ */
1201
+ expired: boolean;
1198
1202
  };
1199
1203
  }
@@ -53,7 +53,7 @@ export declare class Account extends Service {
53
53
  */
54
54
  updateEmail<Preferences extends Models.Preferences>(email: string, password: string): Promise<Models.User<Preferences>>;
55
55
  /**
56
- * List Identities
56
+ * List identities
57
57
  *
58
58
  * Get the list of identities for the currently logged in user.
59
59
  *
@@ -107,7 +107,7 @@ export declare class Account extends Service {
107
107
  */
108
108
  updateMFA<Preferences extends Models.Preferences>(mfa: boolean): Promise<Models.User<Preferences>>;
109
109
  /**
110
- * Create Authenticator
110
+ * Create authenticator
111
111
  *
112
112
  * Add an authenticator app to be used as an MFA factor. Verify the
113
113
  * authenticator using the [verify
@@ -120,7 +120,7 @@ export declare class Account extends Service {
120
120
  */
121
121
  createMfaAuthenticator(type: AuthenticatorType): Promise<Models.MfaType>;
122
122
  /**
123
- * Verify Authenticator
123
+ * Verify authenticator
124
124
  *
125
125
  * Verify an authenticator app after adding it using the [add
126
126
  * authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
@@ -133,7 +133,7 @@ export declare class Account extends Service {
133
133
  */
134
134
  updateMfaAuthenticator<Preferences extends Models.Preferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>>;
135
135
  /**
136
- * Delete Authenticator
136
+ * Delete authenticator
137
137
  *
138
138
  * Delete an authenticator for a user by ID.
139
139
  *
@@ -143,7 +143,7 @@ export declare class Account extends Service {
143
143
  */
144
144
  deleteMfaAuthenticator(type: AuthenticatorType): Promise<{}>;
145
145
  /**
146
- * Create MFA Challenge
146
+ * Create MFA challenge
147
147
  *
148
148
  * Begin the process of MFA verification after sign-in. Finish the flow with
149
149
  * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
@@ -155,7 +155,7 @@ export declare class Account extends Service {
155
155
  */
156
156
  createMfaChallenge(factor: AuthenticationFactor): Promise<Models.MfaChallenge>;
157
157
  /**
158
- * Create MFA Challenge (confirmation)
158
+ * Create MFA challenge (confirmation)
159
159
  *
160
160
  * Complete the MFA challenge by providing the one-time password. Finish the
161
161
  * process of MFA verification by providing the one-time password. To begin
@@ -168,9 +168,9 @@ export declare class Account extends Service {
168
168
  * @throws {AppwriteException}
169
169
  * @returns {Promise}
170
170
  */
171
- updateMfaChallenge(challengeId: string, otp: string): Promise<{}>;
171
+ updateMfaChallenge(challengeId: string, otp: string): Promise<Models.Session>;
172
172
  /**
173
- * List Factors
173
+ * List factors
174
174
  *
175
175
  * List the factors available on the account to be used as a MFA challange.
176
176
  *
@@ -179,7 +179,7 @@ export declare class Account extends Service {
179
179
  */
180
180
  listMfaFactors(): Promise<Models.MfaFactors>;
181
181
  /**
182
- * Get MFA Recovery Codes
182
+ * Get MFA recovery codes
183
183
  *
184
184
  * Get recovery codes that can be used as backup for MFA flow. Before getting
185
185
  * codes, they must be generated using
@@ -191,7 +191,7 @@ export declare class Account extends Service {
191
191
  */
192
192
  getMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes>;
193
193
  /**
194
- * Create MFA Recovery Codes
194
+ * Create MFA recovery codes
195
195
  *
196
196
  * Generate recovery codes as backup for MFA flow. It's recommended to
197
197
  * generate and show then immediately after user successfully adds their
@@ -204,7 +204,7 @@ export declare class Account extends Service {
204
204
  */
205
205
  createMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes>;
206
206
  /**
207
- * Regenerate MFA Recovery Codes
207
+ * Regenerate MFA recovery codes
208
208
  *
209
209
  * Regenerate recovery codes that can be used as backup for MFA flow. Before
210
210
  * regenerating codes, they must be first generated using
@@ -482,6 +482,11 @@ export declare class Account extends Service {
482
482
  /**
483
483
  * Create push target
484
484
  *
485
+ * Use this endpoint to register a device for push notifications. Provide a
486
+ * target ID (custom or generated using ID.unique()), a device identifier
487
+ * (usually a device token), and optionally specify which provider should send
488
+ * notifications to this target. The target is automatically linked to the
489
+ * current session and includes device information like brand and model.
485
490
  *
486
491
  * @param {string} targetId
487
492
  * @param {string} identifier
@@ -493,6 +498,11 @@ export declare class Account extends Service {
493
498
  /**
494
499
  * Update push target
495
500
  *
501
+ * Update the currently logged in user's push notification target. You can
502
+ * modify the target's identifier (device token) and provider ID (token,
503
+ * email, phone etc.). The target must exist and belong to the current user.
504
+ * If you change the provider ID, notifications will be sent through the new
505
+ * messaging provider instead.
496
506
  *
497
507
  * @param {string} targetId
498
508
  * @param {string} identifier
@@ -503,6 +513,9 @@ export declare class Account extends Service {
503
513
  /**
504
514
  * Delete push target
505
515
  *
516
+ * Delete a push notification target for the currently logged in user. After
517
+ * deletion, the device will no longer receive push notifications. The target
518
+ * must exist and belong to the current user.
506
519
  *
507
520
  * @param {string} targetId
508
521
  * @throws {AppwriteException}
@@ -541,9 +554,7 @@ export declare class Account extends Service {
541
554
  * [POST
542
555
  * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
543
556
  * endpoint to complete the login process. The link sent to the user's email
544
- * address is valid for 1 hour. If you are on a mobile device you can leave
545
- * the URL parameter empty, so that the login completion will be handled by
546
- * your Appwrite instance by default.
557
+ * address is valid for 1 hour.
547
558
  *
548
559
  * A user is limited to 10 active sessions at a time by default. [Learn more
549
560
  * about session
@@ -18,7 +18,7 @@ export declare class Locale extends Service {
18
18
  */
19
19
  get(): Promise<Models.Locale>;
20
20
  /**
21
- * List Locale Codes
21
+ * List locale codes
22
22
  *
23
23
  * List of all locale codes in [ISO
24
24
  * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
@@ -81,7 +81,7 @@ export declare class Storage extends Service {
81
81
  */
82
82
  updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise<Models.File>;
83
83
  /**
84
- * Delete File
84
+ * Delete file
85
85
  *
86
86
  * Delete a file by its unique ID. Only users with write permissions have
87
87
  * access to delete this resource.
@@ -65,7 +65,8 @@ export declare class Teams extends Service {
65
65
  * List team memberships
66
66
  *
67
67
  * Use this endpoint to list a team's members using the team's ID. All team
68
- * members have read access to this endpoint.
68
+ * members have read access to this endpoint. Hide sensitive attributes from
69
+ * the response by toggling membership privacy in the Console.
69
70
  *
70
71
  * @param {string} teamId
71
72
  * @param {string[]} queries
@@ -114,7 +115,8 @@ export declare class Teams extends Service {
114
115
  * Get team membership
115
116
  *
116
117
  * Get a team member by the membership unique id. All team members have read
117
- * access for this resource.
118
+ * access for this resource. Hide sensitive attributes from the response by
119
+ * toggling membership privacy in the Console.
118
120
  *
119
121
  * @param {string} teamId
120
122
  * @param {string} membershipId