prostgles-client 4.0.276 → 4.0.277
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/getAuthHandler.d.ts +3 -1
- package/dist/getAuthHandler.d.ts.map +1 -1
- package/dist/getAuthHandler.js +14 -10
- package/dist/hooks/useProstglesClient.d.ts +4 -5
- package/dist/hooks/useProstglesClient.d.ts.map +1 -1
- package/dist/hooks/useProstglesClient.js +11 -5
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/dist/prostgles.d.ts +8 -0
- package/dist/prostgles.d.ts.map +1 -1
- package/dist/prostgles.js +2 -2
- package/package.json +1 -1
package/dist/getAuthHandler.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ type Args = {
|
|
|
3
3
|
socket: any;
|
|
4
4
|
authData: AuthSocketSchema | undefined;
|
|
5
5
|
onReload: VoidFunction | undefined;
|
|
6
|
+
endpoint: string | undefined;
|
|
7
|
+
project: string | undefined;
|
|
6
8
|
};
|
|
7
9
|
type WithProviderLogin = Partial<Record<IdentityProvider, VoidFunction>>;
|
|
8
10
|
type ClientAuthSuccess<T> = T & {
|
|
@@ -32,7 +34,7 @@ type AuthStateLoggedIn<U extends UserLike = UserLike> = LoginSignupOptions & {
|
|
|
32
34
|
logout: () => Promise<any>;
|
|
33
35
|
};
|
|
34
36
|
export type AuthHandler<U extends UserLike = UserLike> = AuthStateLoggedOut | AuthStateLoggedIn<U>;
|
|
35
|
-
export declare const getAuthHandler: ({ authData: authConfig, socket, onReload }: Args) => AuthHandler;
|
|
37
|
+
export declare const getAuthHandler: ({ authData: authConfig, socket, onReload, endpoint, project, }: Args) => AuthHandler;
|
|
36
38
|
export declare const authRequest: <T extends (import("prostgles-types").CommonAuthFailure & {
|
|
37
39
|
/**
|
|
38
40
|
* This is a client-only property that is obtained from server redirect response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthHandler.d.ts","sourceRoot":"","sources":["../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;;OAEG;;;IAFH;;OAEG;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;UAoJG,MAAM,QACN,MAAM,WACH,KAAK,GAAG,MAAM,eAgCxB,CAAC"}
|
package/dist/getAuthHandler.js
CHANGED
|
@@ -3,8 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.authRequest = exports.getAuthHandler = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const prostgles_1 = require("./prostgles");
|
|
6
|
-
const getAuthHandler = ({ authData: authConfig, socket, onReload }) => {
|
|
6
|
+
const getAuthHandler = ({ authData: authConfig, socket, onReload, endpoint, project, }) => {
|
|
7
7
|
var _a;
|
|
8
|
+
const urlWithEndpointAndSearch = (route) => {
|
|
9
|
+
const { search } = window.location;
|
|
10
|
+
let url = route + search;
|
|
11
|
+
if (project)
|
|
12
|
+
url = `/${project}${route}`;
|
|
13
|
+
if (endpoint)
|
|
14
|
+
url = `${endpoint}${url}`;
|
|
15
|
+
return url;
|
|
16
|
+
};
|
|
8
17
|
if ((authConfig === null || authConfig === void 0 ? void 0 : authConfig.pathGuard) && prostgles_1.isClientSide) {
|
|
9
18
|
const doReload = (res) => {
|
|
10
19
|
if (res === null || res === void 0 ? void 0 : res.shouldReload) {
|
|
@@ -48,18 +57,17 @@ const getAuthHandler = ({ authData: authConfig, socket, onReload }) => {
|
|
|
48
57
|
loginSignupOptions.login =
|
|
49
58
|
login &&
|
|
50
59
|
(async (params) => {
|
|
51
|
-
return (0, exports.authRequest)(
|
|
60
|
+
return (0, exports.authRequest)(urlWithEndpointAndSearch(login.loginRoute), params);
|
|
52
61
|
});
|
|
53
62
|
loginSignupOptions.signupWithEmailAndPassword =
|
|
54
63
|
signupWithEmailAndPassword &&
|
|
55
64
|
((params) => {
|
|
56
|
-
return (0, exports.authRequest)(
|
|
65
|
+
return (0, exports.authRequest)(urlWithEndpointAndSearch(signupWithEmailAndPassword.url), params);
|
|
57
66
|
});
|
|
58
67
|
loginSignupOptions.confirmEmail =
|
|
59
68
|
signupWithEmailAndPassword &&
|
|
60
69
|
((data) => {
|
|
61
|
-
|
|
62
|
-
return (0, exports.authRequest)(signupWithEmailAndPassword.emailConfirmationRoute, data);
|
|
70
|
+
return (0, exports.authRequest)(urlWithEndpointAndSearch(signupWithEmailAndPassword.emailConfirmationRoute), data);
|
|
63
71
|
});
|
|
64
72
|
}
|
|
65
73
|
if (!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.user)) {
|
|
@@ -77,16 +85,12 @@ const getAuthHandler = ({ authData: authConfig, socket, onReload }) => {
|
|
|
77
85
|
const { logoutRoute } = (_a = authConfig.login) !== null && _a !== void 0 ? _a : {};
|
|
78
86
|
if (!logoutRoute)
|
|
79
87
|
throw new Error("Unexpected");
|
|
80
|
-
return (0, exports.authRequest)(
|
|
88
|
+
return (0, exports.authRequest)(urlWithEndpointAndSearch(logoutRoute), {}, "POST");
|
|
81
89
|
},
|
|
82
90
|
...loginSignupOptions,
|
|
83
91
|
};
|
|
84
92
|
};
|
|
85
93
|
exports.getAuthHandler = getAuthHandler;
|
|
86
|
-
const addSearchInCaseItHasReturnUrl = (url) => {
|
|
87
|
-
const { search } = window.location;
|
|
88
|
-
return url + search;
|
|
89
|
-
};
|
|
90
94
|
const authRequest = async (path, data, method) => {
|
|
91
95
|
const rawResponse = await fetch(path, {
|
|
92
96
|
method: method !== null && method !== void 0 ? method : "POST",
|
|
@@ -11,13 +11,12 @@ export type OnReadyParams<DBSchema, U extends UserLike = UserLike> = {
|
|
|
11
11
|
isReconnect: boolean;
|
|
12
12
|
socket: Socket;
|
|
13
13
|
};
|
|
14
|
-
type SocketPathOrOptions =
|
|
15
|
-
uri?: string;
|
|
16
|
-
});
|
|
14
|
+
type SocketPathOrOptions = Partial<ManagerOptions & SocketOptions>;
|
|
17
15
|
export type UseProstglesClientProps = Omit<InitOptions<DBSchema>, "onReady" | "socket"> & {
|
|
18
16
|
/**
|
|
19
|
-
*
|
|
17
|
+
* Websocket API token
|
|
20
18
|
*/
|
|
19
|
+
token?: string;
|
|
21
20
|
socketOptions?: SocketPathOrOptions;
|
|
22
21
|
skip?: boolean;
|
|
23
22
|
};
|
|
@@ -34,6 +33,6 @@ export type ProstglesClientState<PGC> = {
|
|
|
34
33
|
hasError: true;
|
|
35
34
|
error: unknown;
|
|
36
35
|
};
|
|
37
|
-
export declare const useProstglesClient: <DBSchema_1, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<OnReadyParams<DBSchema_1, U>>;
|
|
36
|
+
export declare const useProstglesClient: <DBSchema_1, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, endpoint, project, token, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<OnReadyParams<DBSchema_1, U>>;
|
|
38
37
|
export {};
|
|
39
38
|
//# sourceMappingURL=useProstglesClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAa,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAMjF,eAAO,MAAM,KAAK,gEAQjB,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI;IACnE,GAAG,EAAE,eAAe,CAAC,QAAQ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F;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AACF,MAAM,MAAM,oBAAoB,CAAC,GAAG,IAChC;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GAC5D,CAAC;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,GAAG,CAAC,GACjE;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD,eAAO,MAAM,kBAAkB,oIAO5B,uBAAuB,uDAmEzB,CAAC"}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.useProstglesClient = exports.getIO = void 0;
|
|
8
|
-
const prostgles_types_1 = require("prostgles-types");
|
|
9
8
|
const SyncedTable_1 = require("../SyncedTable/SyncedTable");
|
|
10
9
|
const prostgles_1 = require("../prostgles");
|
|
11
10
|
const reactImports_1 = require("./reactImports");
|
|
@@ -23,7 +22,7 @@ const getIO = (throwError = false) => {
|
|
|
23
22
|
return {};
|
|
24
23
|
};
|
|
25
24
|
exports.getIO = getIO;
|
|
26
|
-
const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, ...initOpts } = {}) => {
|
|
25
|
+
const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint, project, token, ...initOpts } = {}) => {
|
|
27
26
|
const { useRef, useState } = (0, reactImports_1.getReact)(true);
|
|
28
27
|
const [onReadyArgs, setOnReadyArgs] = useState({
|
|
29
28
|
isLoading: true,
|
|
@@ -31,18 +30,25 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, ...initO
|
|
|
31
30
|
const getIsMounted = (0, useIsMounted_1.useIsMounted)();
|
|
32
31
|
const socketRef = useRef();
|
|
33
32
|
(0, useAsyncEffectQueue_1.useAsyncEffectQueue)(async () => {
|
|
34
|
-
var _a;
|
|
33
|
+
var _a, _b;
|
|
35
34
|
if (skip)
|
|
36
35
|
return undefined;
|
|
37
36
|
(_a = socketRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
38
37
|
const io = (0, exports.getIO)();
|
|
39
38
|
const socketOptions = typeof socketPathOrOptions === "string" ? { path: socketPathOrOptions } : socketPathOrOptions;
|
|
40
39
|
const opts = {
|
|
40
|
+
...socketOptions,
|
|
41
41
|
reconnectionDelay: 1000,
|
|
42
42
|
reconnection: true,
|
|
43
|
-
...(0, prostgles_types_1.omitKeys)(socketOptions !== null && socketOptions !== void 0 ? socketOptions : {}, ["uri"]),
|
|
44
43
|
};
|
|
45
|
-
|
|
44
|
+
if (project) {
|
|
45
|
+
opts.path = `/ws-api-db/${project}`;
|
|
46
|
+
}
|
|
47
|
+
if (token) {
|
|
48
|
+
(_b = opts.query) !== null && _b !== void 0 ? _b : (opts.query = {});
|
|
49
|
+
opts.query.sid_token = token;
|
|
50
|
+
}
|
|
51
|
+
const socket = endpoint ? io(endpoint, opts) : io(opts);
|
|
46
52
|
socketRef.current = socket;
|
|
47
53
|
await (0, prostgles_1.prostgles)({
|
|
48
54
|
socket,
|