pocketbase-react 0.1.26 → 0.1.28
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/dist/pocketbase-react.js +319 -25
- package/dist/pocketbase-react.min.js +4 -4
- package/es/context/Pocketbase.d.ts +2 -2
- package/es/context/Pocketbase.js +1 -1
- package/es/context/auth.d.ts +12 -12
- package/es/context/auth.js +10 -10
- package/es/context/client.d.ts +2 -2
- package/es/context/content.d.ts +7 -7
- package/es/context/content.js +4 -4
- package/es/hooks/useAppContent.d.ts +6 -6
- package/es/hooks/useAuth.d.ts +2 -2
- package/es/hooks/useClientContext.d.ts +1 -1
- package/es/service/Storage.js +3 -3
- package/es/store/reducers/index.d.ts +1 -1
- package/es/store/reducers/records.d.ts +1 -1
- package/es/store/reducers/subscriptions.d.ts +1 -1
- package/es/store/store.d.ts +3 -3
- package/es/store/types/index.d.ts +2 -2
- package/lib/context/Pocketbase.js +1 -1
- package/lib/context/auth.js +10 -10
- package/lib/context/content.js +4 -4
- package/lib/service/Storage.js +3 -3
- package/package.json +3 -3
- package/src/context/Pocketbase.tsx +1 -1
- package/src/context/auth.tsx +18 -15
- package/src/context/client.tsx +1 -1
- package/src/context/content.tsx +15 -5
- package/src/hooks/useAuth.ts +3 -3
- package/src/service/Storage.ts +3 -3
|
@@ -4,8 +4,8 @@ export declare const ADD_RECORDS = "ADD_RECORDS";
|
|
|
4
4
|
export declare const UPDATE_RECORD = "UPDATE_RECORD";
|
|
5
5
|
export declare const DELETE_RECORD = "DELETE_RECORD";
|
|
6
6
|
export declare const DELETE_RECORDS = "DELETE_RECORDS";
|
|
7
|
-
export
|
|
7
|
+
export type RecordTypes = typeof SET_RECORDS | typeof ADD_RECORD | typeof ADD_RECORDS | typeof UPDATE_RECORD | typeof DELETE_RECORD | typeof DELETE_RECORDS;
|
|
8
8
|
export declare const SET_SUBSCRIPTIONS = "SET_SUBSCRIPTIONS";
|
|
9
9
|
export declare const ADD_SUBSCRIPTION = "ADD_SUBSCRIPTION";
|
|
10
10
|
export declare const DELETE_SUBSCRIPTION = "DELETE_SUBSCRIPTION";
|
|
11
|
-
export
|
|
11
|
+
export type SubscriptionsTypes = typeof SET_SUBSCRIPTIONS | typeof ADD_SUBSCRIPTION | typeof DELETE_SUBSCRIPTION;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.PocketbaseContext = exports.Pocketbase = void 0;
|
|
6
6
|
var React = _interopRequireWildcard(require("react"));
|
|
7
|
-
var _pocketbase = _interopRequireDefault(require("
|
|
7
|
+
var _pocketbase = _interopRequireDefault(require("pocketbase"));
|
|
8
8
|
var _reactRedux = require("react-redux");
|
|
9
9
|
var _react2 = require("redux-persist/integration/react");
|
|
10
10
|
var _store = require("../store/store");
|
package/lib/context/auth.js
CHANGED
|
@@ -14,18 +14,18 @@ const AuthProvider = props => {
|
|
|
14
14
|
const [authProviders, setAuthProviders] = React.useState();
|
|
15
15
|
const actions = {
|
|
16
16
|
registerWithEmail: async (email, password) => {
|
|
17
|
-
await (client == null ? void 0 : client.users.create({
|
|
17
|
+
await (client == null ? void 0 : client.collection('users').create({
|
|
18
18
|
email: email,
|
|
19
19
|
password: password,
|
|
20
20
|
passwordConfirm: password
|
|
21
21
|
}));
|
|
22
22
|
},
|
|
23
23
|
signInWithEmail: async (email, password) => {
|
|
24
|
-
await (client == null ? void 0 : client.users.
|
|
24
|
+
await (client == null ? void 0 : client.collection('users').authWithPassword(email, password));
|
|
25
25
|
},
|
|
26
26
|
signInWithProvider: async provider => {
|
|
27
27
|
const authProvider = authProviders == null ? void 0 : authProviders.find(p => p.name === provider);
|
|
28
|
-
const redirectURL = typeof
|
|
28
|
+
const redirectURL = typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
|
|
29
29
|
const url = (authProvider == null ? void 0 : authProvider.authUrl) + redirectURL;
|
|
30
30
|
await _Storage.StorageService.set('provider', JSON.stringify(authProviders));
|
|
31
31
|
await props.openURL(url);
|
|
@@ -39,7 +39,7 @@ const AuthProvider = props => {
|
|
|
39
39
|
const providers = JSON.parse(providersString);
|
|
40
40
|
const authProvider = providers == null ? void 0 : providers.find(p => p.state === state);
|
|
41
41
|
if (authProvider && code) {
|
|
42
|
-
await (client == null ? void 0 : client.users.
|
|
42
|
+
await (client == null ? void 0 : client.collection('users').authWithOAuth2(authProvider.name, code, authProvider.codeVerifier, typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
},
|
|
@@ -47,24 +47,24 @@ const AuthProvider = props => {
|
|
|
47
47
|
client == null ? void 0 : client.authStore.clear();
|
|
48
48
|
},
|
|
49
49
|
sendPasswordResetEmail: async email => {
|
|
50
|
-
await (client == null ? void 0 : client.users.requestPasswordReset(email));
|
|
50
|
+
await (client == null ? void 0 : client.collection('users').requestPasswordReset(email));
|
|
51
51
|
},
|
|
52
52
|
sendEmailVerification: async email => {
|
|
53
|
-
await (client == null ? void 0 : client.users.requestVerification(email));
|
|
53
|
+
await (client == null ? void 0 : client.collection('users').requestVerification(email));
|
|
54
54
|
},
|
|
55
55
|
updateProfile: async (id, record) => {
|
|
56
|
-
await (client == null ? void 0 : client.
|
|
56
|
+
await (client == null ? void 0 : client.collection('profiles').update(id, record));
|
|
57
57
|
},
|
|
58
58
|
updateEmail: async email => {
|
|
59
|
-
await (client == null ? void 0 : client.users.requestEmailChange(email));
|
|
59
|
+
await (client == null ? void 0 : client.collection('users').requestEmailChange(email));
|
|
60
60
|
},
|
|
61
61
|
deleteUser: async id => {
|
|
62
|
-
await (client == null ? void 0 : client.users.delete(id));
|
|
62
|
+
await (client == null ? void 0 : client.collection('users').delete(id));
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
React.useEffect(() => {
|
|
66
66
|
(async () => {
|
|
67
|
-
const methods = await (client == null ? void 0 : client.users.listAuthMethods());
|
|
67
|
+
const methods = await (client == null ? void 0 : client.collection('users').listAuthMethods());
|
|
68
68
|
setAuthProviders(methods == null ? void 0 : methods.authProviders);
|
|
69
69
|
})();
|
|
70
70
|
}, [props.webRedirectUrl, props.mobileRedirectUrl]);
|
package/lib/context/content.js
CHANGED
|
@@ -53,18 +53,18 @@ const ContentProvider = props => {
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
fetch: async collectionName => {
|
|
56
|
-
await (client == null ? void 0 : client.
|
|
56
|
+
await (client == null ? void 0 : client.collection(collectionName).getFullList(200).then(records => {
|
|
57
57
|
dispatch(_actions.recordsAction.setRecords(collectionName, records));
|
|
58
58
|
}).catch(tempErrorHandler));
|
|
59
59
|
},
|
|
60
60
|
create: async (collectionName, record) => {
|
|
61
|
-
return await (client == null ? void 0 : client.
|
|
61
|
+
return await (client == null ? void 0 : client.collection(collectionName).create(record).catch(tempErrorHandler));
|
|
62
62
|
},
|
|
63
63
|
update: async (collectionName, recordId, record) => {
|
|
64
|
-
return await (client == null ? void 0 : client.
|
|
64
|
+
return await (client == null ? void 0 : client.collection(collectionName).update(recordId, record).catch(tempErrorHandler));
|
|
65
65
|
},
|
|
66
66
|
delete: async (collectionName, recordId) => {
|
|
67
|
-
return await (client == null ? void 0 : client.
|
|
67
|
+
return await (client == null ? void 0 : client.collection(collectionName).delete(recordId).catch(tempErrorHandler));
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
(0, React.useEffect)(() => {
|
package/lib/service/Storage.js
CHANGED
|
@@ -6,17 +6,17 @@ exports.StorageService = void 0;
|
|
|
6
6
|
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
7
7
|
class StorageService {
|
|
8
8
|
static async get(key) {
|
|
9
|
-
return typeof
|
|
9
|
+
return typeof document !== 'undefined' ? localStorage.getItem(key) : await _asyncStorage.default.getItem(key);
|
|
10
10
|
}
|
|
11
11
|
static async set(key, value) {
|
|
12
|
-
if (typeof
|
|
12
|
+
if (typeof document !== 'undefined') {
|
|
13
13
|
return localStorage.setItem(key, value);
|
|
14
14
|
} else {
|
|
15
15
|
return await _asyncStorage.default.setItem(key, value);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
static async remove(key) {
|
|
19
|
-
if (typeof
|
|
19
|
+
if (typeof document !== 'undefined') {
|
|
20
20
|
return localStorage.removeItem(key);
|
|
21
21
|
} else {
|
|
22
22
|
return await _asyncStorage.default.removeItem(key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pocketbase-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "Unofficial React SDK (React, React Native, Expo) for interacting with the PocketBase JS SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pocketbase",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"prepublishOnly": "npm run build"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"
|
|
48
|
+
"pocketbase": "0.8.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@babel/cli": "^7.12.1",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@react-native-async-storage/async-storage": "^1.17.10",
|
|
70
70
|
"@reduxjs/toolkit": "^1.8.5",
|
|
71
|
-
"
|
|
71
|
+
"pocketbase": "0.8.1",
|
|
72
72
|
"react-redux": "^8.0.4",
|
|
73
73
|
"redux": "^4.2.0",
|
|
74
74
|
"redux-persist": "^6.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createContext, useEffect } from 'react';
|
|
3
|
-
import PocketBase
|
|
3
|
+
import PocketBase from 'pocketbase';
|
|
4
4
|
import { Provider } from 'react-redux';
|
|
5
5
|
import { PersistGate } from 'redux-persist/integration/react';
|
|
6
6
|
import { store, persistor } from '../store/store';
|
package/src/context/auth.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Collection } from 'pocketbase';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { createContext } from 'react';
|
|
3
4
|
import { useClientContext } from '../hooks/useClientContext';
|
|
@@ -51,19 +52,19 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
51
52
|
|
|
52
53
|
const actions: AuthActions = {
|
|
53
54
|
registerWithEmail: async (email, password) => {
|
|
54
|
-
await client?.users.create({
|
|
55
|
+
await client?.collection('users').create({
|
|
55
56
|
email: email,
|
|
56
57
|
password: password,
|
|
57
58
|
passwordConfirm: password,
|
|
58
59
|
});
|
|
59
60
|
},
|
|
60
61
|
signInWithEmail: async (email: string, password: string) => {
|
|
61
|
-
await client?.users.
|
|
62
|
+
await client?.collection('users').authWithPassword(email, password);
|
|
62
63
|
},
|
|
63
64
|
signInWithProvider: async (provider: string) => {
|
|
64
65
|
const authProvider = authProviders?.find((p) => p.name === provider);
|
|
65
66
|
const redirectURL =
|
|
66
|
-
typeof
|
|
67
|
+
typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
|
|
67
68
|
const url = authProvider?.authUrl + redirectURL;
|
|
68
69
|
await StorageService.set('provider', JSON.stringify(authProviders));
|
|
69
70
|
await props.openURL(url);
|
|
@@ -77,12 +78,14 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
77
78
|
const providers = JSON.parse(providersString) as AuthProviderInfo[];
|
|
78
79
|
const authProvider = providers?.find((p) => p.state === state);
|
|
79
80
|
if (authProvider && code) {
|
|
80
|
-
await client
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
await client
|
|
82
|
+
?.collection('users')
|
|
83
|
+
.authWithOAuth2(
|
|
84
|
+
authProvider.name,
|
|
85
|
+
code,
|
|
86
|
+
authProvider.codeVerifier,
|
|
87
|
+
typeof document !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl
|
|
88
|
+
);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
},
|
|
@@ -90,25 +93,25 @@ export const AuthProvider = (props: AuthProviderProps) => {
|
|
|
90
93
|
client?.authStore.clear();
|
|
91
94
|
},
|
|
92
95
|
sendPasswordResetEmail: async (email: string) => {
|
|
93
|
-
await client?.users.requestPasswordReset(email);
|
|
96
|
+
await client?.collection('users').requestPasswordReset(email);
|
|
94
97
|
},
|
|
95
98
|
sendEmailVerification: async (email: string) => {
|
|
96
|
-
await client?.users.requestVerification(email);
|
|
99
|
+
await client?.collection('users').requestVerification(email);
|
|
97
100
|
},
|
|
98
101
|
updateProfile: async (id: string, record: {}) => {
|
|
99
|
-
await client?.
|
|
102
|
+
await client?.collection('profiles').update(id, record);
|
|
100
103
|
},
|
|
101
104
|
updateEmail: async (email: string) => {
|
|
102
|
-
await client?.users.requestEmailChange(email);
|
|
105
|
+
await client?.collection('users').requestEmailChange(email);
|
|
103
106
|
},
|
|
104
107
|
deleteUser: async (id: string) => {
|
|
105
|
-
await client?.users.delete(id);
|
|
108
|
+
await client?.collection('users').delete(id);
|
|
106
109
|
},
|
|
107
110
|
};
|
|
108
111
|
|
|
109
112
|
React.useEffect(() => {
|
|
110
113
|
(async () => {
|
|
111
|
-
const methods = await client?.users.listAuthMethods();
|
|
114
|
+
const methods = await client?.collection('users').listAuthMethods();
|
|
112
115
|
setAuthProviders(methods?.authProviders);
|
|
113
116
|
})();
|
|
114
117
|
}, [props.webRedirectUrl, props.mobileRedirectUrl]);
|
package/src/context/client.tsx
CHANGED
package/src/context/content.tsx
CHANGED
|
@@ -90,21 +90,31 @@ export const ContentProvider = (props: ContentProviderProps) => {
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
fetch: async (collectionName: string) => {
|
|
93
|
-
await client
|
|
94
|
-
|
|
93
|
+
await client
|
|
94
|
+
?.collection(collectionName)
|
|
95
|
+
.getFullList(200)
|
|
95
96
|
.then((records) => {
|
|
96
97
|
dispatch(recordsAction.setRecords(collectionName, records as Record[]));
|
|
97
98
|
})
|
|
98
99
|
.catch(tempErrorHandler);
|
|
99
100
|
},
|
|
100
101
|
create: async (collectionName: string, record: {}) => {
|
|
101
|
-
return await client
|
|
102
|
+
return await client
|
|
103
|
+
?.collection(collectionName)
|
|
104
|
+
.create(record)
|
|
105
|
+
.catch(tempErrorHandler);
|
|
102
106
|
},
|
|
103
107
|
update: async (collectionName: string, recordId: string, record: {}) => {
|
|
104
|
-
return await client
|
|
108
|
+
return await client
|
|
109
|
+
?.collection(collectionName)
|
|
110
|
+
.update(recordId, record)
|
|
111
|
+
.catch(tempErrorHandler);
|
|
105
112
|
},
|
|
106
113
|
delete: async (collectionName: string, recordId: string) => {
|
|
107
|
-
return await client
|
|
114
|
+
return await client
|
|
115
|
+
?.collection(collectionName)
|
|
116
|
+
.delete(recordId)
|
|
117
|
+
.catch(tempErrorHandler);
|
|
108
118
|
},
|
|
109
119
|
};
|
|
110
120
|
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Admin,
|
|
1
|
+
import { Admin, Record } from 'pocketbase';
|
|
2
2
|
import { useContext, useEffect, useState } from 'react';
|
|
3
3
|
import { AuthActions, AuthContext } from '../context/auth';
|
|
4
4
|
import { StorageService } from '../service/Storage';
|
|
@@ -7,14 +7,14 @@ import { useClientContext } from './useClientContext';
|
|
|
7
7
|
export interface AuthContextInterface {
|
|
8
8
|
actions: AuthActions;
|
|
9
9
|
isSignedIn: boolean | null;
|
|
10
|
-
user:
|
|
10
|
+
user: Record | Admin | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function useAuth(): AuthContextInterface {
|
|
14
14
|
const client = useClientContext();
|
|
15
15
|
const actions = useContext(AuthContext);
|
|
16
16
|
const [isSignedIn, setIsSignedIn] = useState<boolean | null>(null);
|
|
17
|
-
const [user, setUser] = useState<
|
|
17
|
+
const [user, setUser] = useState<Record | Admin | null>(null);
|
|
18
18
|
|
|
19
19
|
function updateAuth() {
|
|
20
20
|
setIsSignedIn(client?.authStore.token !== '');
|
package/src/service/Storage.ts
CHANGED
|
@@ -7,13 +7,13 @@ export class StorageService {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
static async get(key: string): Promise<string | null> {
|
|
10
|
-
return typeof
|
|
10
|
+
return typeof document !== 'undefined'
|
|
11
11
|
? localStorage.getItem(key)
|
|
12
12
|
: await AsyncStorage.getItem(key);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
static async set(key: string, value: string): Promise<void> {
|
|
16
|
-
if (typeof
|
|
16
|
+
if (typeof document !== 'undefined') {
|
|
17
17
|
return localStorage.setItem(key, value);
|
|
18
18
|
} else {
|
|
19
19
|
return await AsyncStorage.setItem(key, value);
|
|
@@ -21,7 +21,7 @@ export class StorageService {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
static async remove(key: string): Promise<void> {
|
|
24
|
-
if (typeof
|
|
24
|
+
if (typeof document !== 'undefined') {
|
|
25
25
|
return localStorage.removeItem(key);
|
|
26
26
|
} else {
|
|
27
27
|
return await AsyncStorage.removeItem(key);
|