@basictech/react 0.7.0-beta.3 → 0.7.0-beta.4

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @basictech/react@0.6.0-beta.0 build
3
+ > @basictech/react@0.7.0-beta.3 build
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: src/index.ts
@@ -11,13 +11,13 @@
11
11
  CLI Cleaning output folder
12
12
  CJS Build start
13
13
  ESM Build start
14
- ESM dist/index.mjs 26.88 KB
15
- ESM dist/index.mjs.map 60.43 KB
16
- ESM ⚡️ Build success in 15ms
17
- CJS dist/index.js 29.13 KB
18
- CJS dist/index.js.map 60.46 KB
19
- CJS ⚡️ Build success in 15ms
14
+ CJS dist/index.js 41.20 KB
15
+ CJS dist/index.js.map 82.45 KB
16
+ CJS ⚡️ Build success in 17ms
17
+ ESM dist/index.mjs 39.45 KB
18
+ ESM dist/index.mjs.map 82.44 KB
19
+ ESM ⚡️ Build success in 18ms
20
20
  DTS Build start
21
- DTS ⚡️ Build success in 854ms
22
- DTS dist/index.d.ts 1008.00 B
23
- DTS dist/index.d.mts 1008.00 B
21
+ DTS ⚡️ Build success in 905ms
22
+ DTS dist/index.d.ts 1.76 KB
23
+ DTS dist/index.d.mts 1.76 KB
package/changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 1.3.4
2
2
 
3
+ ## 0.7.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: provider props
8
+
3
9
  ## 0.7.0-beta.3
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -7,7 +7,24 @@ interface BasicStorage {
7
7
  set(key: string, value: string): Promise<void>;
8
8
  remove(key: string): Promise<void>;
9
9
  }
10
+ declare class LocalStorageAdapter implements BasicStorage {
11
+ get(key: string): Promise<string | null>;
12
+ set(key: string, value: string): Promise<void>;
13
+ remove(key: string): Promise<void>;
14
+ }
10
15
 
16
+ type AuthConfig = {
17
+ scopes?: string | string[];
18
+ server_url?: string;
19
+ };
20
+ type BasicProviderProps = {
21
+ children: React.ReactNode;
22
+ project_id?: string;
23
+ schema?: any;
24
+ debug?: boolean;
25
+ storage?: BasicStorage;
26
+ auth?: AuthConfig;
27
+ };
11
28
  declare enum DBStatus {
12
29
  LOADING = "LOADING",
13
30
  OFFLINE = "OFFLINE",
@@ -25,13 +42,7 @@ type User = {
25
42
  };
26
43
  fullName?: string;
27
44
  };
28
- declare function BasicProvider({ children, project_id, schema, debug, storage }: {
29
- children: React.ReactNode;
30
- project_id?: string;
31
- schema?: any;
32
- debug?: boolean;
33
- storage?: BasicStorage;
34
- }): react_jsx_runtime.JSX.Element;
45
+ declare function BasicProvider({ children, project_id, schema, debug, storage, auth }: BasicProviderProps): react_jsx_runtime.JSX.Element;
35
46
  declare function useBasic(): {
36
47
  unicorn: string;
37
48
  isAuthReady: boolean;
@@ -49,4 +60,4 @@ declare function useBasic(): {
49
60
  dbStatus: DBStatus;
50
61
  };
51
62
 
52
- export { BasicProvider, useBasic };
63
+ export { AuthConfig, BasicProvider, BasicProviderProps, BasicStorage, LocalStorageAdapter, useBasic };
package/dist/index.d.ts CHANGED
@@ -7,7 +7,24 @@ interface BasicStorage {
7
7
  set(key: string, value: string): Promise<void>;
8
8
  remove(key: string): Promise<void>;
9
9
  }
10
+ declare class LocalStorageAdapter implements BasicStorage {
11
+ get(key: string): Promise<string | null>;
12
+ set(key: string, value: string): Promise<void>;
13
+ remove(key: string): Promise<void>;
14
+ }
10
15
 
16
+ type AuthConfig = {
17
+ scopes?: string | string[];
18
+ server_url?: string;
19
+ };
20
+ type BasicProviderProps = {
21
+ children: React.ReactNode;
22
+ project_id?: string;
23
+ schema?: any;
24
+ debug?: boolean;
25
+ storage?: BasicStorage;
26
+ auth?: AuthConfig;
27
+ };
11
28
  declare enum DBStatus {
12
29
  LOADING = "LOADING",
13
30
  OFFLINE = "OFFLINE",
@@ -25,13 +42,7 @@ type User = {
25
42
  };
26
43
  fullName?: string;
27
44
  };
28
- declare function BasicProvider({ children, project_id, schema, debug, storage }: {
29
- children: React.ReactNode;
30
- project_id?: string;
31
- schema?: any;
32
- debug?: boolean;
33
- storage?: BasicStorage;
34
- }): react_jsx_runtime.JSX.Element;
45
+ declare function BasicProvider({ children, project_id, schema, debug, storage, auth }: BasicProviderProps): react_jsx_runtime.JSX.Element;
35
46
  declare function useBasic(): {
36
47
  unicorn: string;
37
48
  isAuthReady: boolean;
@@ -49,4 +60,4 @@ declare function useBasic(): {
49
60
  dbStatus: DBStatus;
50
61
  };
51
62
 
52
- export { BasicProvider, useBasic };
63
+ export { AuthConfig, BasicProvider, BasicProviderProps, BasicStorage, LocalStorageAdapter, useBasic };
package/dist/index.js CHANGED
@@ -279,7 +279,7 @@ var BasicSync = class extends import_dexie2.Dexie {
279
279
  };
280
280
 
281
281
  // package.json
282
- var version = "0.7.0-beta.2";
282
+ var version = "0.7.0-beta.3";
283
283
 
284
284
  // src/updater/versionUpdater.ts
285
285
  var VersionUpdater = class {
@@ -422,6 +422,7 @@ var STORAGE_KEYS = {
422
422
  REFRESH_TOKEN: "basic_refresh_token",
423
423
  USER_INFO: "basic_user_info",
424
424
  AUTH_STATE: "basic_auth_state",
425
+ REDIRECT_URI: "basic_redirect_uri",
425
426
  DEBUG: "basic_debug"
426
427
  };
427
428
  function getCookie(name) {
@@ -619,6 +620,10 @@ async function validateAndCheckSchema(schema) {
619
620
 
620
621
  // src/AuthContext.tsx
621
622
  var import_jsx_runtime = require("react/jsx-runtime");
623
+ var DEFAULT_AUTH_CONFIG = {
624
+ scopes: "profile email app:admin",
625
+ server_url: "https://api.basic.tech"
626
+ };
622
627
  var BasicContext = (0, import_react.createContext)({
623
628
  unicorn: "\u{1F984}",
624
629
  isAuthReady: false,
@@ -639,7 +644,8 @@ function BasicProvider({
639
644
  project_id,
640
645
  schema,
641
646
  debug = false,
642
- storage
647
+ storage,
648
+ auth
643
649
  }) {
644
650
  const [isAuthReady, setIsAuthReady] = (0, import_react.useState)(false);
645
651
  const [isSignedIn, setIsSignedIn] = (0, import_react.useState)(false);
@@ -653,6 +659,11 @@ function BasicProvider({
653
659
  const [pendingRefresh, setPendingRefresh] = (0, import_react.useState)(false);
654
660
  const syncRef = (0, import_react.useRef)(null);
655
661
  const storageAdapter = storage || new LocalStorageAdapter();
662
+ const authConfig = {
663
+ scopes: auth?.scopes || DEFAULT_AUTH_CONFIG.scopes,
664
+ server_url: auth?.server_url || DEFAULT_AUTH_CONFIG.server_url
665
+ };
666
+ const scopesString = Array.isArray(authConfig.scopes) ? authConfig.scopes.join(" ") : authConfig.scopes;
656
667
  const isDevMode = () => isDevelopment(debug);
657
668
  const cleanOAuthParams = () => cleanOAuthParamsFromUrl();
658
669
  (0, import_react.useEffect)(() => {
@@ -820,7 +831,7 @@ function BasicProvider({
820
831
  (0, import_react.useEffect)(() => {
821
832
  async function fetchUser(acc_token) {
822
833
  console.info("fetching user");
823
- const user2 = await fetch("https://api.basic.tech/auth/userInfo", {
834
+ const user2 = await fetch(`${authConfig.server_url}/auth/userInfo`, {
824
835
  method: "GET",
825
836
  headers: {
826
837
  "Authorization": `Bearer ${acc_token}`
@@ -884,13 +895,15 @@ function BasicProvider({
884
895
  if (!redirectUrl || !redirectUrl.startsWith("http://") && !redirectUrl.startsWith("https://")) {
885
896
  throw new Error("Invalid redirect URI provided");
886
897
  }
887
- let baseUrl = "https://api.basic.tech/auth/authorize";
898
+ await storageAdapter.set(STORAGE_KEYS.REDIRECT_URI, redirectUrl);
899
+ log("Stored redirect_uri for token exchange:", redirectUrl);
900
+ let baseUrl = `${authConfig.server_url}/auth/authorize`;
888
901
  baseUrl += `?client_id=${project_id}`;
889
902
  baseUrl += `&redirect_uri=${encodeURIComponent(redirectUrl)}`;
890
903
  baseUrl += `&response_type=code`;
891
- baseUrl += `&scope=profile`;
904
+ baseUrl += `&scope=${encodeURIComponent(scopesString)}`;
892
905
  baseUrl += `&state=${randomState}`;
893
- log("Generated sign-in link successfully");
906
+ log("Generated sign-in link successfully with scopes:", scopesString);
894
907
  return baseUrl;
895
908
  } catch (error2) {
896
909
  log("Error generating sign-in link:", error2);
@@ -963,6 +976,7 @@ function BasicProvider({
963
976
  await storageAdapter.remove(STORAGE_KEYS.AUTH_STATE);
964
977
  await storageAdapter.remove(STORAGE_KEYS.REFRESH_TOKEN);
965
978
  await storageAdapter.remove(STORAGE_KEYS.USER_INFO);
979
+ await storageAdapter.remove(STORAGE_KEYS.REDIRECT_URI);
966
980
  if (syncRef.current) {
967
981
  (async () => {
968
982
  try {
@@ -1033,14 +1047,33 @@ function BasicProvider({
1033
1047
  setPendingRefresh(true);
1034
1048
  throw new Error("Network offline - refresh will be retried when online");
1035
1049
  }
1036
- const requestBody = isRefreshToken ? {
1037
- grant_type: "refresh_token",
1038
- refresh_token: codeOrRefreshToken
1039
- } : {
1040
- grant_type: "authorization_code",
1041
- code: codeOrRefreshToken
1042
- };
1043
- const token2 = await fetch("https://api.basic.tech/auth/token", {
1050
+ let requestBody;
1051
+ if (isRefreshToken) {
1052
+ requestBody = {
1053
+ grant_type: "refresh_token",
1054
+ refresh_token: codeOrRefreshToken
1055
+ };
1056
+ if (project_id) {
1057
+ requestBody.client_id = project_id;
1058
+ }
1059
+ } else {
1060
+ requestBody = {
1061
+ grant_type: "authorization_code",
1062
+ code: codeOrRefreshToken
1063
+ };
1064
+ const storedRedirectUri = await storageAdapter.get(STORAGE_KEYS.REDIRECT_URI);
1065
+ if (storedRedirectUri) {
1066
+ requestBody.redirect_uri = storedRedirectUri;
1067
+ log("Including redirect_uri in token exchange:", storedRedirectUri);
1068
+ } else {
1069
+ log("Warning: No redirect_uri found in storage for token exchange");
1070
+ }
1071
+ if (project_id) {
1072
+ requestBody.client_id = project_id;
1073
+ }
1074
+ }
1075
+ log("Token exchange request body:", { ...requestBody, refresh_token: isRefreshToken ? "[REDACTED]" : void 0, code: !isRefreshToken ? "[REDACTED]" : void 0 });
1076
+ const token2 = await fetch(`${authConfig.server_url}/auth/token`, {
1044
1077
  method: "POST",
1045
1078
  headers: {
1046
1079
  "Content-Type": "application/json"
@@ -1062,6 +1095,7 @@ function BasicProvider({
1062
1095
  }
1063
1096
  await storageAdapter.remove(STORAGE_KEYS.REFRESH_TOKEN);
1064
1097
  await storageAdapter.remove(STORAGE_KEYS.USER_INFO);
1098
+ await storageAdapter.remove(STORAGE_KEYS.REDIRECT_URI);
1065
1099
  clearCookie("basic_token");
1066
1100
  clearCookie("basic_access_token");
1067
1101
  setUser({});
@@ -1076,6 +1110,10 @@ function BasicProvider({
1076
1110
  await storageAdapter.set(STORAGE_KEYS.REFRESH_TOKEN, token2.refresh_token);
1077
1111
  log("Updated refresh token in storage");
1078
1112
  }
1113
+ if (!isRefreshToken) {
1114
+ await storageAdapter.remove(STORAGE_KEYS.REDIRECT_URI);
1115
+ log("Cleaned up redirect_uri from storage after successful exchange");
1116
+ }
1079
1117
  setCookie("basic_access_token", token2.access_token, { httpOnly: false });
1080
1118
  log("Updated access token in cookie");
1081
1119
  }
@@ -1085,6 +1123,7 @@ function BasicProvider({
1085
1123
  if (!error2.message.includes("offline") && !error2.message.includes("Network")) {
1086
1124
  await storageAdapter.remove(STORAGE_KEYS.REFRESH_TOKEN);
1087
1125
  await storageAdapter.remove(STORAGE_KEYS.USER_INFO);
1126
+ await storageAdapter.remove(STORAGE_KEYS.REDIRECT_URI);
1088
1127
  clearCookie("basic_token");
1089
1128
  clearCookie("basic_access_token");
1090
1129
  setUser({});