kodzero-front-sdk-alfa 0.0.5 → 0.0.6
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/README.md +6 -6
- package/dist/auth/base.d.ts +3 -3
- package/dist/auth/base.js +3 -3
- package/dist/auth/email.d.ts +4 -4
- package/dist/auth/email.js +6 -6
- package/dist/auth/index.js +3 -3
- package/package.json +1 -1
- package/src/auth/base.ts +3 -3
- package/src/auth/email.ts +11 -11
- package/src/auth/index.ts +3 -3
package/README.md
CHANGED
|
@@ -18,14 +18,14 @@ const kodzero = new Kodzero({
|
|
|
18
18
|
host: 'https://api.your-backend.com'
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
const
|
|
21
|
+
// New user registration
|
|
22
|
+
const registerResult = await kodzero.auth.register({
|
|
23
23
|
email: 'user@example.com',
|
|
24
24
|
password: 'secure_password'
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
const
|
|
27
|
+
// Login
|
|
28
|
+
const loginResult = await kodzero.auth.login({
|
|
29
29
|
email: 'user@example.com',
|
|
30
30
|
password: 'secure_password'
|
|
31
31
|
});
|
|
@@ -36,8 +36,8 @@ const verified = await kodzero.auth.verify();
|
|
|
36
36
|
// Refresh the token
|
|
37
37
|
const refreshed = await kodzero.auth.refresh();
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
await kodzero.auth.
|
|
39
|
+
// Logout
|
|
40
|
+
await kodzero.auth.logout();
|
|
41
41
|
|
|
42
42
|
// Manually set tokens (useful for persisting sessions)
|
|
43
43
|
kodzero.auth.setTokens('access_token', 'refresh_token');
|
package/dist/auth/base.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ declare class KodzeroAuthBase {
|
|
|
7
7
|
tokensManager: TokensManagerClass;
|
|
8
8
|
constructor(options: AuthOptions, api: typeof FluidFetch, tokensManager: TokensManagerClass);
|
|
9
9
|
_handleApiError(response: Response): Promise<void>;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
login: (...args: any[]) => Promise<any> | void;
|
|
11
|
+
register: (...args: any[]) => Promise<any> | void;
|
|
12
12
|
refresh: (...args: any[]) => Promise<any> | void;
|
|
13
|
-
|
|
13
|
+
logout: (...args: any[]) => Promise<any> | void;
|
|
14
14
|
verify: (...args: any[]) => Promise<any> | void;
|
|
15
15
|
}
|
|
16
16
|
export default KodzeroAuthBase;
|
package/dist/auth/base.js
CHANGED
|
@@ -13,10 +13,10 @@ class KodzeroAuthBase {
|
|
|
13
13
|
_handleApiError(response) {
|
|
14
14
|
return validateApiResponse(response);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
login = (...args) => { };
|
|
17
|
+
register = (...args) => { };
|
|
18
18
|
refresh = (...args) => { };
|
|
19
|
-
|
|
19
|
+
logout = (...args) => { };
|
|
20
20
|
verify = (...args) => { };
|
|
21
21
|
}
|
|
22
22
|
export default KodzeroAuthBase;
|
package/dist/auth/email.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import FluidFetch from "fluid-fetch";
|
|
|
2
2
|
import { AuthOptions } from "./index.js";
|
|
3
3
|
import KodzeroAuthBase from "./base.js";
|
|
4
4
|
import TokensManagerClass from "./tokens.js";
|
|
5
|
-
interface
|
|
5
|
+
interface KodzeroAuthEmailLogin {
|
|
6
6
|
email: string;
|
|
7
7
|
password: string;
|
|
8
8
|
}
|
|
@@ -11,13 +11,13 @@ declare class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
11
11
|
collection: "auth/password";
|
|
12
12
|
constructor(options: AuthOptions, api: typeof FluidFetch, tokensManager: TokensManagerClass);
|
|
13
13
|
_setTokens: (access: string, refresh?: string) => void;
|
|
14
|
-
|
|
14
|
+
login: (input: KodzeroAuthEmailLogin) => Promise<{
|
|
15
15
|
access: string;
|
|
16
16
|
refresh: string;
|
|
17
17
|
}>;
|
|
18
|
-
|
|
18
|
+
register: (userData: Record<string, string>) => Promise<Record<string, any>>;
|
|
19
19
|
verify: () => Promise<any>;
|
|
20
20
|
refresh: () => Promise<any>;
|
|
21
|
-
|
|
21
|
+
logout: () => Promise<any>;
|
|
22
22
|
}
|
|
23
23
|
export default KodzeroAuthEmail;
|
package/dist/auth/email.js
CHANGED
|
@@ -13,8 +13,8 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
13
13
|
if (refresh)
|
|
14
14
|
this.tokensManager.setRefresh(refresh);
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
const url = buildURL(this.host, this.collection + '/
|
|
16
|
+
login = async (input) => {
|
|
17
|
+
const url = buildURL(this.host, this.collection + '/login');
|
|
18
18
|
const response = await this.api.post(url, input)
|
|
19
19
|
.headers({ 'Content-Type': 'application/json' });
|
|
20
20
|
await this._handleApiError(response);
|
|
@@ -24,8 +24,8 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
24
24
|
}
|
|
25
25
|
return json.tokens;
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
const url = buildURL(this.host, this.collection + '/
|
|
27
|
+
register = async (userData) => {
|
|
28
|
+
const url = buildURL(this.host, this.collection + '/register');
|
|
29
29
|
const response = await this.api.post(url, userData)
|
|
30
30
|
.headers({ 'Content-Type': 'application/json' });
|
|
31
31
|
await this._handleApiError(response);
|
|
@@ -58,8 +58,8 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
58
58
|
}
|
|
59
59
|
return json.ok ? true : false;
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
const url = buildURL(this.host, this.collection + '/
|
|
61
|
+
logout = async () => {
|
|
62
|
+
const url = buildURL(this.host, this.collection + '/logout');
|
|
63
63
|
const response = await this.api.post(url, {})
|
|
64
64
|
.headers({ 'Content-Type': 'application/json' });
|
|
65
65
|
await this._handleApiError(response);
|
package/dist/auth/index.js
CHANGED
|
@@ -7,9 +7,9 @@ class KodzeroAuth extends KodzeroAuthBase {
|
|
|
7
7
|
constructor(options, api, tokensManager) {
|
|
8
8
|
super(options, api, tokensManager);
|
|
9
9
|
this.email = new KodzeroAuthEmail(options, api, tokensManager);
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
10
|
+
this.login = this.email.login;
|
|
11
|
+
this.register = this.email.register;
|
|
12
|
+
this.logout = this.email.logout;
|
|
13
13
|
this.verify = this.email.verify;
|
|
14
14
|
this.refresh = this.email.refresh;
|
|
15
15
|
this.setTokens = (access, refresh) => {
|
package/package.json
CHANGED
package/src/auth/base.ts
CHANGED
|
@@ -29,10 +29,10 @@ class KodzeroAuthBase {
|
|
|
29
29
|
* Base auth methods.
|
|
30
30
|
* These will be overridden by specific strategies (e.g. email, social, etc.)
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
login = (...args: any[]): Promise<any> | void => {}
|
|
33
|
+
register = (...args: any[]): Promise<any> | void => {}
|
|
34
34
|
refresh = (...args: any[]): Promise<any> | void => {}
|
|
35
|
-
|
|
35
|
+
logout = (...args: any[]): Promise<any> | void => {}
|
|
36
36
|
verify = (...args: any[]): Promise<any> | void => {}
|
|
37
37
|
}
|
|
38
38
|
|
package/src/auth/email.ts
CHANGED
|
@@ -4,7 +4,7 @@ import buildURL from "../utils/buildURL.js"
|
|
|
4
4
|
import KodzeroAuthBase from "./base.js"
|
|
5
5
|
import TokensManagerClass from "./tokens.js"
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface KodzeroAuthEmailLogin {
|
|
8
8
|
email: string
|
|
9
9
|
password: string
|
|
10
10
|
}
|
|
@@ -30,11 +30,11 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Login with email and password. On success, sets tokens in TokensManager automatically
|
|
34
34
|
*/
|
|
35
|
-
|
|
36
|
-
const url = buildURL(this.host, this.collection + '/
|
|
37
|
-
|
|
35
|
+
login = async (input: KodzeroAuthEmailLogin): Promise<{access: string, refresh: string}> => {
|
|
36
|
+
const url = buildURL(this.host, this.collection + '/login')
|
|
37
|
+
|
|
38
38
|
const response = await this.api.post(url, input)
|
|
39
39
|
.headers({ 'Content-Type': 'application/json' });
|
|
40
40
|
|
|
@@ -49,10 +49,10 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Register with email and password. On success, sets tokens in TokensManager automatically
|
|
53
53
|
*/
|
|
54
|
-
|
|
55
|
-
const url = buildURL(this.host, this.collection + '/
|
|
54
|
+
register = async (userData: Record<string, string>): Promise<Record<string, any>> => {
|
|
55
|
+
const url = buildURL(this.host, this.collection + '/register')
|
|
56
56
|
const response = await this.api.post(url, userData)
|
|
57
57
|
.headers({ 'Content-Type': 'application/json' });
|
|
58
58
|
|
|
@@ -102,11 +102,11 @@ class KodzeroAuthEmail extends KodzeroAuthBase {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Logout the user
|
|
106
106
|
* If success, clears tokens in TokensManager automatically
|
|
107
107
|
*/
|
|
108
|
-
|
|
109
|
-
const url = buildURL(this.host, this.collection + '/
|
|
108
|
+
logout = async (): Promise<any> => {
|
|
109
|
+
const url = buildURL(this.host, this.collection + '/logout')
|
|
110
110
|
const response = await this.api.post(url, {})
|
|
111
111
|
.headers({ 'Content-Type': 'application/json' });
|
|
112
112
|
|
package/src/auth/index.ts
CHANGED
|
@@ -19,9 +19,9 @@ class KodzeroAuth extends KodzeroAuthBase {
|
|
|
19
19
|
this.email = new KodzeroAuthEmail(options, api, tokensManager)
|
|
20
20
|
|
|
21
21
|
// Default methods set to email strategy methods
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
22
|
+
this.login = this.email.login
|
|
23
|
+
this.register = this.email.register
|
|
24
|
+
this.logout = this.email.logout
|
|
25
25
|
this.verify = this.email.verify
|
|
26
26
|
this.refresh = this.email.refresh
|
|
27
27
|
|