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.
@@ -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 declare type RecordTypes = typeof SET_RECORDS | typeof ADD_RECORD | typeof ADD_RECORDS | typeof UPDATE_RECORD | typeof DELETE_RECORD | typeof DELETE_RECORDS;
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 declare type SubscriptionsTypes = typeof SET_SUBSCRIPTIONS | typeof ADD_SUBSCRIPTION | typeof DELETE_SUBSCRIPTION;
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("@tobicrain/pocketbase"));
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");
@@ -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.authViaEmail(email, password));
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 window !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
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.authViaOAuth2(authProvider.name, code, authProvider.codeVerifier, typeof window !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl));
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.records.update('profiles', id, record));
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]);
@@ -53,18 +53,18 @@ const ContentProvider = props => {
53
53
  }
54
54
  },
55
55
  fetch: async collectionName => {
56
- await (client == null ? void 0 : client.records.getFullList(collectionName, 200).then(records => {
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.records.create(collectionName, record).catch(tempErrorHandler));
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.records.update(collectionName, recordId, record).catch(tempErrorHandler));
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.records.delete(collectionName, recordId).catch(tempErrorHandler));
67
+ return await (client == null ? void 0 : client.collection(collectionName).delete(recordId).catch(tempErrorHandler));
68
68
  }
69
69
  };
70
70
  (0, React.useEffect)(() => {
@@ -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 window !== 'undefined' ? localStorage.getItem(key) : await _asyncStorage.default.getItem(key);
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 window !== 'undefined') {
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 window !== 'undefined') {
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.26",
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
- "@tobicrain/pocketbase": "^0.7.3"
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
- "@tobicrain/pocketbase": "^0.7.3",
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, { Admin, BaseAuthStore, LocalAuthStore, User } from '@tobicrain/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';
@@ -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.authViaEmail(email, password);
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 window !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl;
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?.users.authViaOAuth2(
81
- authProvider.name,
82
- code,
83
- authProvider.codeVerifier,
84
- typeof window !== 'undefined' ? props.webRedirectUrl : props.mobileRedirectUrl
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?.records.update('profiles', id, record);
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]);
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { createContext } from 'react';
3
- import PocketBase from '@tobicrain/pocketbase';
3
+ import PocketBase from 'pocketbase';
4
4
 
5
5
  export const ClientContext = createContext<PocketBase | null>(null);
6
6
 
@@ -90,21 +90,31 @@ export const ContentProvider = (props: ContentProviderProps) => {
90
90
  }
91
91
  },
92
92
  fetch: async (collectionName: string) => {
93
- await client?.records
94
- .getFullList(collectionName, 200)
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?.records.create(collectionName, record).catch(tempErrorHandler);
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?.records.update(collectionName, recordId, record).catch(tempErrorHandler);
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?.records.delete(collectionName, recordId).catch(tempErrorHandler);
114
+ return await client
115
+ ?.collection(collectionName)
116
+ .delete(recordId)
117
+ .catch(tempErrorHandler);
108
118
  },
109
119
  };
110
120
 
@@ -1,4 +1,4 @@
1
- import { Admin, User } from '@tobicrain/pocketbase';
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: User | Admin | null;
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<User | Admin | null>(null);
17
+ const [user, setUser] = useState<Record | Admin | null>(null);
18
18
 
19
19
  function updateAuth() {
20
20
  setIsSignedIn(client?.authStore.token !== '');
@@ -7,13 +7,13 @@ export class StorageService {
7
7
  };
8
8
 
9
9
  static async get(key: string): Promise<string | null> {
10
- return typeof window !== 'undefined'
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 window !== 'undefined') {
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 window !== 'undefined') {
24
+ if (typeof document !== 'undefined') {
25
25
  return localStorage.removeItem(key);
26
26
  } else {
27
27
  return await AsyncStorage.removeItem(key);