prostgles-client 4.0.141 → 4.0.142
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/Auth.d.ts +20 -19
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +47 -34
- package/dist/index.js +2 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/index.no-sync.js +2 -1
- package/dist/index.no-sync.js.LICENSE.txt +9 -0
- package/lib/Auth.ts +71 -43
- package/lib/SyncedTable/SyncedTable.ts +1 -1
- package/package.json +2 -2
- package/tests/package-lock.json +2 -2
package/dist/Auth.d.ts
CHANGED
|
@@ -4,30 +4,30 @@ type Args = {
|
|
|
4
4
|
authData: AuthSocketSchema | undefined;
|
|
5
5
|
onReload: VoidFunction | undefined;
|
|
6
6
|
};
|
|
7
|
+
type WithProviderLogin = Partial<Record<IdentityProvider, VoidFunction>>;
|
|
8
|
+
type EmailAuth = {
|
|
9
|
+
withPassword?: (params: {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
remember_me?: boolean;
|
|
13
|
+
totp_token?: string;
|
|
14
|
+
totp_recovery_code?: string;
|
|
15
|
+
}) => Promise<any>;
|
|
16
|
+
withMagicLink?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
withPassword?: undefined;
|
|
19
|
+
withMagicLink?: (params: {
|
|
20
|
+
username: string;
|
|
21
|
+
}) => Promise<any>;
|
|
22
|
+
};
|
|
7
23
|
type AuthStateLoggedOut = {
|
|
8
24
|
isLoggedin: false;
|
|
9
25
|
user?: undefined;
|
|
10
26
|
prefferedLogin: string;
|
|
11
27
|
login?: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}) => Promise<any>;
|
|
16
|
-
withMagicLink?: (params: {
|
|
17
|
-
email: string;
|
|
18
|
-
}) => Promise<any>;
|
|
19
|
-
withProvider?: (provider: IdentityProvider) => void;
|
|
20
|
-
};
|
|
21
|
-
register?: {
|
|
22
|
-
withPassword: (params: {
|
|
23
|
-
email: string;
|
|
24
|
-
password: string;
|
|
25
|
-
}) => Promise<any>;
|
|
26
|
-
} | {
|
|
27
|
-
magicLink: (params: {
|
|
28
|
-
email: string;
|
|
29
|
-
}) => Promise<any>;
|
|
30
|
-
};
|
|
28
|
+
withProvider?: WithProviderLogin;
|
|
29
|
+
} & EmailAuth;
|
|
30
|
+
register?: EmailAuth;
|
|
31
31
|
};
|
|
32
32
|
type AuthStateLoggedIn = {
|
|
33
33
|
isLoggedin: true;
|
|
@@ -37,5 +37,6 @@ type AuthStateLoggedIn = {
|
|
|
37
37
|
};
|
|
38
38
|
export type AuthHandler = AuthStateLoggedOut | AuthStateLoggedIn;
|
|
39
39
|
export declare const setupAuth: ({ authData: authConfig, socket, onReload }: Args) => AuthHandler;
|
|
40
|
+
export declare const POST: (path: string, data: object) => Promise<Response>;
|
|
40
41
|
export {};
|
|
41
42
|
//# sourceMappingURL=Auth.d.ts.map
|
package/dist/Auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../lib/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA0D,KAAK,gBAAgB,EAAY,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../lib/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA0D,KAAK,gBAAgB,EAAY,KAAK,gBAAgB,EAA+B,MAAM,iBAAiB,CAAC;AAG9L,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;CACpC,CAAA;AAED,KAAK,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzE,K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
exports.POST = exports.setupAuth = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const prostgles_1 = require("./prostgles");
|
|
6
6
|
const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
7
|
-
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
socket.emit(channel, params, (err, res) => {
|
|
10
|
-
if (err)
|
|
11
|
-
reject(err);
|
|
12
|
-
else
|
|
13
|
-
resolve(res);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
if (!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.user)) {
|
|
18
|
-
return {
|
|
19
|
-
isLoggedin: false,
|
|
20
|
-
user: undefined,
|
|
21
|
-
prefferedLogin: "",
|
|
22
|
-
login: {
|
|
23
|
-
withEmailAndPassword: (params) => emit(prostgles_types_1.CHANNELS.LOGIN, { type: "withPassword", params }),
|
|
24
|
-
withMagicLink: (params) => emit(prostgles_types_1.CHANNELS.LOGIN, { type: "magicLink", params }),
|
|
25
|
-
withProvider: (provider) => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const url = (_b = (_a = authConfig === null || authConfig === void 0 ? void 0 : authConfig.providers) === null || _a === void 0 ? void 0 : _a[provider]) === null || _b === void 0 ? void 0 : _b.url;
|
|
28
|
-
if (!url)
|
|
29
|
-
throw new Error(`Provider ${provider} not enabled`);
|
|
30
|
-
window.location.assign(url);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
register: (authConfig === null || authConfig === void 0 ? void 0 : authConfig.register) ? {
|
|
34
|
-
[authConfig.register]: (params) => emit(prostgles_types_1.CHANNELS.REGISTER, { type: authConfig.register, params })
|
|
35
|
-
} : undefined
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (authConfig.pathGuard && prostgles_1.hasWnd) {
|
|
7
|
+
if ((authConfig === null || authConfig === void 0 ? void 0 : authConfig.pathGuard) && prostgles_1.hasWnd) {
|
|
39
8
|
const doReload = (res) => {
|
|
40
9
|
if (res === null || res === void 0 ? void 0 : res.shouldReload) {
|
|
41
10
|
if (onReload)
|
|
@@ -53,11 +22,55 @@ const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
|
53
22
|
doReload(res);
|
|
54
23
|
});
|
|
55
24
|
}
|
|
25
|
+
if (!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.user)) {
|
|
26
|
+
const { login, providers, register } = authConfig !== null && authConfig !== void 0 ? authConfig : {};
|
|
27
|
+
const withProvider = (0, prostgles_types_1.isEmpty)(providers) ? undefined : providers && Object.entries(providers).reduce((acc, [provider, { url }]) => {
|
|
28
|
+
acc[provider] = () => {
|
|
29
|
+
window.location.assign(url);
|
|
30
|
+
};
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
return {
|
|
34
|
+
isLoggedin: false,
|
|
35
|
+
user: undefined,
|
|
36
|
+
prefferedLogin: "",
|
|
37
|
+
login: (login || providers) && {
|
|
38
|
+
withProvider,
|
|
39
|
+
...(login && {
|
|
40
|
+
[login.type]: async (params) => {
|
|
41
|
+
return (0, exports.POST)(login.url, params);
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
register: (register === null || register === void 0 ? void 0 : register.type) ? {
|
|
46
|
+
[register.type]: (params) => {
|
|
47
|
+
(0, exports.POST)(register.url, params);
|
|
48
|
+
}
|
|
49
|
+
} : undefined
|
|
50
|
+
};
|
|
51
|
+
}
|
|
56
52
|
return {
|
|
57
53
|
isLoggedin: true,
|
|
58
54
|
user: authConfig.user,
|
|
59
|
-
logout: () =>
|
|
55
|
+
logout: () => {
|
|
56
|
+
},
|
|
60
57
|
prefferedLogin: "",
|
|
61
58
|
};
|
|
62
59
|
};
|
|
63
60
|
exports.setupAuth = setupAuth;
|
|
61
|
+
const POST = async (path, data) => {
|
|
62
|
+
const rawResponse = await fetch(path, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Accept": "application/json",
|
|
66
|
+
"Content-Type": "application/json"
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(data)
|
|
69
|
+
});
|
|
70
|
+
if (!rawResponse.ok) {
|
|
71
|
+
const error = await rawResponse.json().catch(() => rawResponse.text()).catch(() => rawResponse.statusText);
|
|
72
|
+
throw new Error(error);
|
|
73
|
+
}
|
|
74
|
+
return rawResponse;
|
|
75
|
+
};
|
|
76
|
+
exports.POST = POST;
|