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/dist/esm/sdk.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import
|
|
3
|
-
import { Platform } from 'react-native';
|
|
4
|
-
import fs from 'react-native-fs';
|
|
1
|
+
import * as Device from 'expo-device';
|
|
2
|
+
import * as FileSystem from 'expo-file-system';
|
|
5
3
|
|
|
6
4
|
/******************************************************************************
|
|
7
5
|
Copyright (c) Microsoft Corporation.
|
|
@@ -158,7 +156,7 @@ class Client {
|
|
|
158
156
|
// @ts-ignore
|
|
159
157
|
this.realtime.socket = new WebSocket(url, undefined, {
|
|
160
158
|
headers: {
|
|
161
|
-
Origin: `appwrite-${
|
|
159
|
+
Origin: `appwrite-${Device.osName}://${this.config.platform}`
|
|
162
160
|
}
|
|
163
161
|
});
|
|
164
162
|
this.realtime.socket.addEventListener('message', this.realtime.onMessage);
|
|
@@ -347,7 +345,7 @@ class Client {
|
|
|
347
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
348
346
|
method = method.toUpperCase();
|
|
349
347
|
headers = Object.assign({}, this.headers, headers);
|
|
350
|
-
headers.Origin = `appwrite-${
|
|
348
|
+
headers.Origin = `appwrite-${Device.osName}://${this.config.platform}`;
|
|
351
349
|
let options = {
|
|
352
350
|
method,
|
|
353
351
|
headers,
|
|
@@ -1056,31 +1054,7 @@ class Account extends Service {
|
|
|
1056
1054
|
* @returns {void|string}
|
|
1057
1055
|
*/
|
|
1058
1056
|
createOAuth2Session(provider, success, failure, scopes) {
|
|
1059
|
-
|
|
1060
|
-
throw new AppwriteException('Missing required parameter: "provider"');
|
|
1061
|
-
}
|
|
1062
|
-
const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
|
|
1063
|
-
const payload = {};
|
|
1064
|
-
if (typeof success !== 'undefined') {
|
|
1065
|
-
payload['success'] = success;
|
|
1066
|
-
}
|
|
1067
|
-
if (typeof failure !== 'undefined') {
|
|
1068
|
-
payload['failure'] = failure;
|
|
1069
|
-
}
|
|
1070
|
-
if (typeof scopes !== 'undefined') {
|
|
1071
|
-
payload['scopes'] = scopes;
|
|
1072
|
-
}
|
|
1073
|
-
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
1074
|
-
payload['project'] = this.client.config.project;
|
|
1075
|
-
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
1076
|
-
uri.searchParams.append(key, value);
|
|
1077
|
-
}
|
|
1078
|
-
if (typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.location)) {
|
|
1079
|
-
window.location.href = uri.toString();
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
return uri;
|
|
1083
|
-
}
|
|
1057
|
+
throw new AppwriteException('Not yet supported');
|
|
1084
1058
|
}
|
|
1085
1059
|
/**
|
|
1086
1060
|
* Create phone session
|
|
@@ -2255,7 +2229,7 @@ class Storage extends Service {
|
|
|
2255
2229
|
*
|
|
2256
2230
|
* @param {string} bucketId
|
|
2257
2231
|
* @param {string} fileId
|
|
2258
|
-
* @param {
|
|
2232
|
+
* @param {{name: string, type: string, size: number, uri: string}} file
|
|
2259
2233
|
* @param {string[]} permissions
|
|
2260
2234
|
* @throws {AppwriteException}
|
|
2261
2235
|
* @returns {Promise}
|
|
@@ -2308,7 +2282,11 @@ class Storage extends Service {
|
|
|
2308
2282
|
if (response && response.$id) {
|
|
2309
2283
|
apiHeaders['x-appwrite-id'] = response.$id;
|
|
2310
2284
|
}
|
|
2311
|
-
let chunk = yield
|
|
2285
|
+
let chunk = yield FileSystem.readAsStringAsync(file.uri, {
|
|
2286
|
+
encoding: FileSystem.EncodingType.Base64,
|
|
2287
|
+
position: offset,
|
|
2288
|
+
length: Service.CHUNK_SIZE
|
|
2289
|
+
});
|
|
2312
2290
|
payload['file'] = { uri: `data:${file.type};base64,${chunk}`, name: file.name, type: file.type };
|
|
2313
2291
|
response = yield this.client.call('post', uri, apiHeaders, payload);
|
|
2314
2292
|
if (onProgress) {
|