@temboplus/afloat 0.1.7 → 0.1.9
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/esm/src/features/auth/manager.d.ts +18 -13
- package/esm/src/features/auth/manager.d.ts.map +1 -1
- package/esm/src/features/auth/manager.js +25 -23
- package/package.json +1 -1
- package/script/src/features/auth/manager.d.ts +18 -13
- package/script/src/features/auth/manager.d.ts.map +1 -1
- package/script/src/features/auth/manager.js +25 -23
|
@@ -9,6 +9,8 @@ export declare class AfloatAuth {
|
|
|
9
9
|
private store;
|
|
10
10
|
/** The token handler implementation */
|
|
11
11
|
private tokenHandler;
|
|
12
|
+
/** client AfloatAuth instance */
|
|
13
|
+
private static _instance;
|
|
12
14
|
/**
|
|
13
15
|
* Private constructor to prevent direct instantiation.
|
|
14
16
|
* @param {AuthStore} store - The auth store implementation to use
|
|
@@ -16,25 +18,28 @@ export declare class AfloatAuth {
|
|
|
16
18
|
*/
|
|
17
19
|
private constructor();
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
* This
|
|
21
|
-
*
|
|
21
|
+
* Gets or creates the client-side singleton instance of AfloatAuth.
|
|
22
|
+
* This getter will automatically initialize the client instance if it hasn't been created yet.
|
|
23
|
+
* For server-side usage, use initializeServer() instead.
|
|
24
|
+
*
|
|
25
|
+
* @returns {AfloatAuth} The client-side singleton instance
|
|
26
|
+
* @example
|
|
27
|
+
* // Client-side usage
|
|
28
|
+
* const auth = AfloatAuth.instance;
|
|
29
|
+
*
|
|
30
|
+
* // Server-side usage (don't use .instance)
|
|
31
|
+
* const serverAuth = await AfloatAuth.initializeServer(token);
|
|
22
32
|
*/
|
|
23
|
-
static
|
|
33
|
+
static get instance(): AfloatAuth;
|
|
24
34
|
/**
|
|
25
|
-
* Creates a new instance of AfloatAuth
|
|
26
|
-
*
|
|
35
|
+
* Creates a new server-side instance of AfloatAuth.
|
|
36
|
+
* Unlike the client-side instance getter, this creates a new instance each time.
|
|
37
|
+
*
|
|
27
38
|
* @param {string} token - Authentication token
|
|
28
|
-
* @returns {Promise<AfloatAuth>} A new
|
|
39
|
+
* @returns {Promise<AfloatAuth>} A new server-side instance
|
|
29
40
|
* @throws {Error} If token is invalid or required data cannot be fetched
|
|
30
41
|
*/
|
|
31
42
|
static initializeServer(token: string): Promise<AfloatAuth>;
|
|
32
|
-
/**
|
|
33
|
-
* Gets the singleton instance of AfloatAuth.
|
|
34
|
-
* @throws {Error} If AfloatAuth hasn't been initialized
|
|
35
|
-
* @returns {AfloatAuth} The singleton instance
|
|
36
|
-
*/
|
|
37
|
-
static get instance(): AfloatAuth;
|
|
38
43
|
/**
|
|
39
44
|
* Gets the authentication repository instance.
|
|
40
45
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAU7D;;;GAGG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,OAAO,CAAC,KAAK,CAAY;IAEzB,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAe;IAEnC,iCAAiC;IACjC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IACnD;;;;OAIG;IACH,OAAO;IAKP;;;;;;;;;;;;OAYG;IACH,WAAkB,QAAQ,IAAI,UAAU,CAKvC;IAED;;;;;;;OAOG;WACiB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAwBxE;;;;OAIG;IACH,OAAO,KAAK,IAAI,GAEf;IAED;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;OAGG;IACH,IAAI,WAAW,IAAI,IAAI,GAAG,SAAS,CAElC;IAED;;;;OAIG;IACH,cAAc,IAAI,IAAI,GAAG,SAAS;IAIlC;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAI1C;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3D;;;;;;OAMG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMvE;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,OAAO,CAAC,cAAc;CAIvB"}
|
|
@@ -3,7 +3,6 @@ import { createClientStore, useClientUser, } from "./storage/client_store.js";
|
|
|
3
3
|
import { ClientTokenHandler } from "./storage/client_token_handler.js";
|
|
4
4
|
import { ServerStore } from "./storage/server_store.js";
|
|
5
5
|
import { ServerTokenHandler } from "./storage/server_token_handler.js";
|
|
6
|
-
let _instance = null;
|
|
7
6
|
/**
|
|
8
7
|
* Main authentication class that works in both client and server environments.
|
|
9
8
|
* Provides authentication functionality and user management.
|
|
@@ -33,19 +32,27 @@ export class AfloatAuth {
|
|
|
33
32
|
this.tokenHandler = tokenHandler;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
37
|
-
* This
|
|
38
|
-
*
|
|
35
|
+
* Gets or creates the client-side singleton instance of AfloatAuth.
|
|
36
|
+
* This getter will automatically initialize the client instance if it hasn't been created yet.
|
|
37
|
+
* For server-side usage, use initializeServer() instead.
|
|
38
|
+
*
|
|
39
|
+
* @returns {AfloatAuth} The client-side singleton instance
|
|
40
|
+
* @example
|
|
41
|
+
* // Client-side usage
|
|
42
|
+
* const auth = AfloatAuth.instance;
|
|
43
|
+
*
|
|
44
|
+
* // Server-side usage (don't use .instance)
|
|
45
|
+
* const serverAuth = await AfloatAuth.initializeServer(token);
|
|
39
46
|
*/
|
|
40
|
-
static
|
|
41
|
-
_instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance);
|
|
42
|
-
return _instance;
|
|
47
|
+
static get instance() {
|
|
48
|
+
return AfloatAuth._instance || (AfloatAuth._instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance));
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
|
-
* Creates a new instance of AfloatAuth
|
|
46
|
-
*
|
|
51
|
+
* Creates a new server-side instance of AfloatAuth.
|
|
52
|
+
* Unlike the client-side instance getter, this creates a new instance each time.
|
|
53
|
+
*
|
|
47
54
|
* @param {string} token - Authentication token
|
|
48
|
-
* @returns {Promise<AfloatAuth>} A new
|
|
55
|
+
* @returns {Promise<AfloatAuth>} A new server-side instance
|
|
49
56
|
* @throws {Error} If token is invalid or required data cannot be fetched
|
|
50
57
|
*/
|
|
51
58
|
static async initializeServer(token) {
|
|
@@ -59,8 +66,7 @@ export class AfloatAuth {
|
|
|
59
66
|
const user = await tokenHandler.constructUser();
|
|
60
67
|
store.setUser(user);
|
|
61
68
|
// Create and initialize auth instance
|
|
62
|
-
|
|
63
|
-
return _instance;
|
|
69
|
+
return new AfloatAuth(store, tokenHandler);
|
|
64
70
|
}
|
|
65
71
|
catch (error) {
|
|
66
72
|
if (error instanceof Error) {
|
|
@@ -69,17 +75,6 @@ export class AfloatAuth {
|
|
|
69
75
|
throw new Error("Failed to initialize server auth");
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Gets the singleton instance of AfloatAuth.
|
|
74
|
-
* @throws {Error} If AfloatAuth hasn't been initialized
|
|
75
|
-
* @returns {AfloatAuth} The singleton instance
|
|
76
|
-
*/
|
|
77
|
-
static get instance() {
|
|
78
|
-
if (_instance === null) {
|
|
79
|
-
throw new Error("AfloatAuth not initialized. Call initializeClient() or initializeServer() first");
|
|
80
|
-
}
|
|
81
|
-
return _instance;
|
|
82
|
-
}
|
|
83
78
|
/**
|
|
84
79
|
* Gets the authentication repository instance.
|
|
85
80
|
* @private
|
|
@@ -159,3 +154,10 @@ export class AfloatAuth {
|
|
|
159
154
|
this.tokenHandler.clearToken();
|
|
160
155
|
}
|
|
161
156
|
}
|
|
157
|
+
/** client AfloatAuth instance */
|
|
158
|
+
Object.defineProperty(AfloatAuth, "_instance", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
configurable: true,
|
|
161
|
+
writable: true,
|
|
162
|
+
value: null
|
|
163
|
+
});
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ export declare class AfloatAuth {
|
|
|
9
9
|
private store;
|
|
10
10
|
/** The token handler implementation */
|
|
11
11
|
private tokenHandler;
|
|
12
|
+
/** client AfloatAuth instance */
|
|
13
|
+
private static _instance;
|
|
12
14
|
/**
|
|
13
15
|
* Private constructor to prevent direct instantiation.
|
|
14
16
|
* @param {AuthStore} store - The auth store implementation to use
|
|
@@ -16,25 +18,28 @@ export declare class AfloatAuth {
|
|
|
16
18
|
*/
|
|
17
19
|
private constructor();
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
* This
|
|
21
|
-
*
|
|
21
|
+
* Gets or creates the client-side singleton instance of AfloatAuth.
|
|
22
|
+
* This getter will automatically initialize the client instance if it hasn't been created yet.
|
|
23
|
+
* For server-side usage, use initializeServer() instead.
|
|
24
|
+
*
|
|
25
|
+
* @returns {AfloatAuth} The client-side singleton instance
|
|
26
|
+
* @example
|
|
27
|
+
* // Client-side usage
|
|
28
|
+
* const auth = AfloatAuth.instance;
|
|
29
|
+
*
|
|
30
|
+
* // Server-side usage (don't use .instance)
|
|
31
|
+
* const serverAuth = await AfloatAuth.initializeServer(token);
|
|
22
32
|
*/
|
|
23
|
-
static
|
|
33
|
+
static get instance(): AfloatAuth;
|
|
24
34
|
/**
|
|
25
|
-
* Creates a new instance of AfloatAuth
|
|
26
|
-
*
|
|
35
|
+
* Creates a new server-side instance of AfloatAuth.
|
|
36
|
+
* Unlike the client-side instance getter, this creates a new instance each time.
|
|
37
|
+
*
|
|
27
38
|
* @param {string} token - Authentication token
|
|
28
|
-
* @returns {Promise<AfloatAuth>} A new
|
|
39
|
+
* @returns {Promise<AfloatAuth>} A new server-side instance
|
|
29
40
|
* @throws {Error} If token is invalid or required data cannot be fetched
|
|
30
41
|
*/
|
|
31
42
|
static initializeServer(token: string): Promise<AfloatAuth>;
|
|
32
|
-
/**
|
|
33
|
-
* Gets the singleton instance of AfloatAuth.
|
|
34
|
-
* @throws {Error} If AfloatAuth hasn't been initialized
|
|
35
|
-
* @returns {AfloatAuth} The singleton instance
|
|
36
|
-
*/
|
|
37
|
-
static get instance(): AfloatAuth;
|
|
38
43
|
/**
|
|
39
44
|
* Gets the authentication repository instance.
|
|
40
45
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAU7D;;;GAGG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,OAAO,CAAC,KAAK,CAAY;IAEzB,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAe;IAEnC,iCAAiC;IACjC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IACnD;;;;OAIG;IACH,OAAO;IAKP;;;;;;;;;;;;OAYG;IACH,WAAkB,QAAQ,IAAI,UAAU,CAKvC;IAED;;;;;;;OAOG;WACiB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAwBxE;;;;OAIG;IACH,OAAO,KAAK,IAAI,GAEf;IAED;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;OAGG;IACH,IAAI,WAAW,IAAI,IAAI,GAAG,SAAS,CAElC;IAED;;;;OAIG;IACH,cAAc,IAAI,IAAI,GAAG,SAAS;IAIlC;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAI1C;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3D;;;;;;OAMG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMvE;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,OAAO,CAAC,cAAc;CAIvB"}
|
|
@@ -6,7 +6,6 @@ const client_store_js_1 = require("./storage/client_store.js");
|
|
|
6
6
|
const client_token_handler_js_1 = require("./storage/client_token_handler.js");
|
|
7
7
|
const server_store_js_1 = require("./storage/server_store.js");
|
|
8
8
|
const server_token_handler_js_1 = require("./storage/server_token_handler.js");
|
|
9
|
-
let _instance = null;
|
|
10
9
|
/**
|
|
11
10
|
* Main authentication class that works in both client and server environments.
|
|
12
11
|
* Provides authentication functionality and user management.
|
|
@@ -36,19 +35,27 @@ class AfloatAuth {
|
|
|
36
35
|
this.tokenHandler = tokenHandler;
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
|
-
*
|
|
40
|
-
* This
|
|
41
|
-
*
|
|
38
|
+
* Gets or creates the client-side singleton instance of AfloatAuth.
|
|
39
|
+
* This getter will automatically initialize the client instance if it hasn't been created yet.
|
|
40
|
+
* For server-side usage, use initializeServer() instead.
|
|
41
|
+
*
|
|
42
|
+
* @returns {AfloatAuth} The client-side singleton instance
|
|
43
|
+
* @example
|
|
44
|
+
* // Client-side usage
|
|
45
|
+
* const auth = AfloatAuth.instance;
|
|
46
|
+
*
|
|
47
|
+
* // Server-side usage (don't use .instance)
|
|
48
|
+
* const serverAuth = await AfloatAuth.initializeServer(token);
|
|
42
49
|
*/
|
|
43
|
-
static
|
|
44
|
-
_instance = new AfloatAuth((0, client_store_js_1.createClientStore)(), client_token_handler_js_1.ClientTokenHandler.instance);
|
|
45
|
-
return _instance;
|
|
50
|
+
static get instance() {
|
|
51
|
+
return AfloatAuth._instance || (AfloatAuth._instance = new AfloatAuth((0, client_store_js_1.createClientStore)(), client_token_handler_js_1.ClientTokenHandler.instance));
|
|
46
52
|
}
|
|
47
53
|
/**
|
|
48
|
-
* Creates a new instance of AfloatAuth
|
|
49
|
-
*
|
|
54
|
+
* Creates a new server-side instance of AfloatAuth.
|
|
55
|
+
* Unlike the client-side instance getter, this creates a new instance each time.
|
|
56
|
+
*
|
|
50
57
|
* @param {string} token - Authentication token
|
|
51
|
-
* @returns {Promise<AfloatAuth>} A new
|
|
58
|
+
* @returns {Promise<AfloatAuth>} A new server-side instance
|
|
52
59
|
* @throws {Error} If token is invalid or required data cannot be fetched
|
|
53
60
|
*/
|
|
54
61
|
static async initializeServer(token) {
|
|
@@ -62,8 +69,7 @@ class AfloatAuth {
|
|
|
62
69
|
const user = await tokenHandler.constructUser();
|
|
63
70
|
store.setUser(user);
|
|
64
71
|
// Create and initialize auth instance
|
|
65
|
-
|
|
66
|
-
return _instance;
|
|
72
|
+
return new AfloatAuth(store, tokenHandler);
|
|
67
73
|
}
|
|
68
74
|
catch (error) {
|
|
69
75
|
if (error instanceof Error) {
|
|
@@ -72,17 +78,6 @@ class AfloatAuth {
|
|
|
72
78
|
throw new Error("Failed to initialize server auth");
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Gets the singleton instance of AfloatAuth.
|
|
77
|
-
* @throws {Error} If AfloatAuth hasn't been initialized
|
|
78
|
-
* @returns {AfloatAuth} The singleton instance
|
|
79
|
-
*/
|
|
80
|
-
static get instance() {
|
|
81
|
-
if (_instance === null) {
|
|
82
|
-
throw new Error("AfloatAuth not initialized. Call initializeClient() or initializeServer() first");
|
|
83
|
-
}
|
|
84
|
-
return _instance;
|
|
85
|
-
}
|
|
86
81
|
/**
|
|
87
82
|
* Gets the authentication repository instance.
|
|
88
83
|
* @private
|
|
@@ -163,3 +158,10 @@ class AfloatAuth {
|
|
|
163
158
|
}
|
|
164
159
|
}
|
|
165
160
|
exports.AfloatAuth = AfloatAuth;
|
|
161
|
+
/** client AfloatAuth instance */
|
|
162
|
+
Object.defineProperty(AfloatAuth, "_instance", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
configurable: true,
|
|
165
|
+
writable: true,
|
|
166
|
+
value: null
|
|
167
|
+
});
|