react-native-appwrite 0.1.0 → 0.2.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/README.md +24 -32
- package/dist/cjs/sdk.js +31 -36
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +11 -33
- package/dist/esm/sdk.js.map +1 -1
- package/package.json +5 -10
- package/rollup.config.js +0 -10
- package/src/client.ts +3 -5
- package/src/services/account.ts +1 -31
- package/src/services/storage.ts +8 -4
- package/dist/iife/sdk.js +0 -3126
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
|
+
"version": "0.2.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "dist/cjs/sdk.js",
|
|
8
8
|
"exports": {
|
|
@@ -30,18 +30,13 @@
|
|
|
30
30
|
"rollup": "2.75.4",
|
|
31
31
|
"serve-handler": "6.1.0",
|
|
32
32
|
"tslib": "2.4.0",
|
|
33
|
-
"react-native-fs": "^2.20.0",
|
|
34
33
|
"typescript": "4.7.2"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
36
|
+
"expo-file-system": "16.0.8",
|
|
37
|
+
"expo-device": "5.9.3"
|
|
39
38
|
},
|
|
40
39
|
"peerDependencies": {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"react-native-url-polyfill": "^2.0.0"
|
|
44
|
-
},
|
|
45
|
-
"jsdelivr": "dist/iife/sdk.js",
|
|
46
|
-
"unpkg": "dist/iife/sdk.js"
|
|
40
|
+
"expo": "*"
|
|
41
|
+
}
|
|
47
42
|
}
|
package/rollup.config.js
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import 'isomorphic-form-data';
|
|
2
|
-
import { fetch } from 'cross-fetch';
|
|
3
|
-
import { Platform } from 'react-native';
|
|
4
1
|
import { Models } from './models';
|
|
5
2
|
import { Service } from './service';
|
|
3
|
+
import * as Device from 'expo-device';
|
|
6
4
|
|
|
7
5
|
type Payload = {
|
|
8
6
|
[key: string]: any;
|
|
@@ -251,7 +249,7 @@ class Client {
|
|
|
251
249
|
// @ts-ignore
|
|
252
250
|
this.realtime.socket = new WebSocket(url, undefined, {
|
|
253
251
|
headers: {
|
|
254
|
-
Origin: `appwrite-${
|
|
252
|
+
Origin: `appwrite-${Device.osName}://${this.config.platform}`
|
|
255
253
|
}
|
|
256
254
|
});
|
|
257
255
|
this.realtime.socket.addEventListener('message', this.realtime.onMessage);
|
|
@@ -369,7 +367,7 @@ class Client {
|
|
|
369
367
|
method = method.toUpperCase();
|
|
370
368
|
|
|
371
369
|
headers = Object.assign({}, this.headers, headers);
|
|
372
|
-
headers.Origin = `appwrite-${
|
|
370
|
+
headers.Origin = `appwrite-${Device.osName}://${this.config.platform}`;
|
|
373
371
|
let options: RequestInit = {
|
|
374
372
|
method,
|
|
375
373
|
headers,
|
package/src/services/account.ts
CHANGED
|
@@ -706,37 +706,7 @@ export class Account extends Service {
|
|
|
706
706
|
* @returns {void|string}
|
|
707
707
|
*/
|
|
708
708
|
createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL {
|
|
709
|
-
|
|
710
|
-
throw new AppwriteException('Missing required parameter: "provider"');
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
|
|
714
|
-
const payload: Payload = {};
|
|
715
|
-
|
|
716
|
-
if (typeof success !== 'undefined') {
|
|
717
|
-
payload['success'] = success;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
if (typeof failure !== 'undefined') {
|
|
721
|
-
payload['failure'] = failure;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
if (typeof scopes !== 'undefined') {
|
|
725
|
-
payload['scopes'] = scopes;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
729
|
-
payload['project'] = this.client.config.project;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
733
|
-
uri.searchParams.append(key, value);
|
|
734
|
-
}
|
|
735
|
-
if (typeof window !== 'undefined' && window?.location) {
|
|
736
|
-
window.location.href = uri.toString();
|
|
737
|
-
} else {
|
|
738
|
-
return uri;
|
|
739
|
-
}
|
|
709
|
+
throw new AppwriteException('Not yet supported');
|
|
740
710
|
}
|
|
741
711
|
|
|
742
712
|
/**
|
package/src/services/storage.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Service } from '../service';
|
|
|
2
2
|
import { AppwriteException, Client } from '../client';
|
|
3
3
|
import type { Models } from '../models';
|
|
4
4
|
import type { UploadProgress, Payload } from '../client';
|
|
5
|
-
import
|
|
5
|
+
import * as FileSystem from 'expo-file-system';
|
|
6
6
|
|
|
7
7
|
export class Storage extends Service {
|
|
8
8
|
|
|
@@ -69,12 +69,12 @@ export class Storage extends Service {
|
|
|
69
69
|
*
|
|
70
70
|
* @param {string} bucketId
|
|
71
71
|
* @param {string} fileId
|
|
72
|
-
* @param {
|
|
72
|
+
* @param {{name: string, type: string, size: number, uri: string}} file
|
|
73
73
|
* @param {string[]} permissions
|
|
74
74
|
* @throws {AppwriteException}
|
|
75
75
|
* @returns {Promise}
|
|
76
76
|
*/
|
|
77
|
-
async createFile(bucketId: string, fileId: string, file:
|
|
77
|
+
async createFile(bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise<Models.File> {
|
|
78
78
|
if (typeof bucketId === 'undefined') {
|
|
79
79
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
80
80
|
}
|
|
@@ -134,7 +134,11 @@ export class Storage extends Service {
|
|
|
134
134
|
apiHeaders['x-appwrite-id'] = response.$id;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
let chunk = await
|
|
137
|
+
let chunk = await FileSystem.readAsStringAsync(file.uri, {
|
|
138
|
+
encoding: FileSystem.EncodingType.Base64,
|
|
139
|
+
position: offset,
|
|
140
|
+
length: Service.CHUNK_SIZE
|
|
141
|
+
});
|
|
138
142
|
|
|
139
143
|
payload['file'] = {uri: `data:${file.type};base64,${chunk}`, name: file.name, type: file.type};
|
|
140
144
|
response = await this.client.call('post', uri, apiHeaders, payload);
|