@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.
- package/.turbo/turbo-build.log +10 -10
- package/changelog.md +6 -0
- package/dist/index.d.mts +19 -8
- package/dist/index.d.ts +19 -8
- package/dist/index.js +53 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthContext.tsx +10 -8
- package/src/index.ts +3 -7
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @basictech/react@0.
|
|
3
|
+
> @basictech/react@0.7.0-beta.3 build
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
[34mCLI[39m Cleaning output folder
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
13
|
[34mESM[39m Build start
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m41.20 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m82.45 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 17ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m39.45 KB[39m
|
|
18
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m82.44 KB[39m
|
|
19
|
+
[32mESM[39m ⚡️ Build success in 18ms
|
|
20
20
|
[34mDTS[39m Build start
|
|
21
|
-
[32mDTS[39m ⚡️ Build success in
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
23
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
21
|
+
[32mDTS[39m ⚡️ Build success in 905ms
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.76 KB[39m
|
|
23
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m1.76 KB[39m
|
package/changelog.md
CHANGED
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.
|
|
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(
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
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({});
|