@temboplus/afloat 0.1.7 → 0.1.8
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/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/src/features/auth/manager.d.ts +1 -0
- package/esm/src/features/auth/manager.d.ts.map +1 -1
- package/esm/src/features/auth/manager.js +17 -8
- package/esm/src/utils/env_detect.d.ts +28 -0
- package/esm/src/utils/env_detect.d.ts.map +1 -0
- package/esm/src/utils/env_detect.js +75 -0
- package/package.json +4 -4
- package/script/_dnt.shims.d.ts +6 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +65 -0
- package/script/src/features/auth/manager.d.ts +1 -0
- package/script/src/features/auth/manager.d.ts.map +1 -1
- package/script/src/features/auth/manager.js +17 -8
- package/script/src/utils/env_detect.d.ts +28 -0
- package/script/src/utils/env_detect.d.ts.map +1 -0
- package/script/src/utils/env_detect.js +105 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
const dntGlobals = {
|
|
4
|
+
Deno,
|
|
5
|
+
};
|
|
6
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
7
|
+
function createMergeProxy(baseObj, extObj) {
|
|
8
|
+
return new Proxy(baseObj, {
|
|
9
|
+
get(_target, prop, _receiver) {
|
|
10
|
+
if (prop in extObj) {
|
|
11
|
+
return extObj[prop];
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return baseObj[prop];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
set(_target, prop, value) {
|
|
18
|
+
if (prop in extObj) {
|
|
19
|
+
delete extObj[prop];
|
|
20
|
+
}
|
|
21
|
+
baseObj[prop] = value;
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
deleteProperty(_target, prop) {
|
|
25
|
+
let success = false;
|
|
26
|
+
if (prop in extObj) {
|
|
27
|
+
delete extObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
if (prop in baseObj) {
|
|
31
|
+
delete baseObj[prop];
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
return success;
|
|
35
|
+
},
|
|
36
|
+
ownKeys(_target) {
|
|
37
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
38
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
39
|
+
const extKeysSet = new Set(extKeys);
|
|
40
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
41
|
+
},
|
|
42
|
+
defineProperty(_target, prop, desc) {
|
|
43
|
+
if (prop in extObj) {
|
|
44
|
+
delete extObj[prop];
|
|
45
|
+
}
|
|
46
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
49
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
50
|
+
if (prop in extObj) {
|
|
51
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
has(_target, prop) {
|
|
58
|
+
return prop in extObj || prop in baseObj;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare class AfloatAuth {
|
|
|
9
9
|
private store;
|
|
10
10
|
/** The token handler implementation */
|
|
11
11
|
private tokenHandler;
|
|
12
|
+
private static _instance;
|
|
12
13
|
/**
|
|
13
14
|
* Private constructor to prevent direct instantiation.
|
|
14
15
|
* @param {AuthStore} store - The auth store implementation to use
|
|
@@ -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;AAW7D;;;GAGG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,OAAO,CAAC,KAAK,CAAY;IAEzB,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAe;IAEnC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IAEnD;;;;OAIG;IACH,OAAO;IAKP;;;;OAIG;WACW,gBAAgB,IAAI,UAAU;IAQ5C;;;;;;OAMG;WACiB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBxE;;;;OAIG;IACH,WAAkB,QAAQ,IAAI,UAAU,CASvC;IAED;;;;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,7 @@ 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
|
-
|
|
6
|
+
import { EnvironmentDetector } from "../../utils/env_detect.js";
|
|
7
7
|
/**
|
|
8
8
|
* Main authentication class that works in both client and server environments.
|
|
9
9
|
* Provides authentication functionality and user management.
|
|
@@ -38,8 +38,8 @@ export class AfloatAuth {
|
|
|
38
38
|
* @returns {AfloatAuth} The singleton instance configured for client-side
|
|
39
39
|
*/
|
|
40
40
|
static initializeClient() {
|
|
41
|
-
_instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance);
|
|
42
|
-
return _instance;
|
|
41
|
+
this._instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance);
|
|
42
|
+
return this._instance;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Creates a new instance of AfloatAuth configured for server-side use.
|
|
@@ -59,8 +59,8 @@ export class AfloatAuth {
|
|
|
59
59
|
const user = await tokenHandler.constructUser();
|
|
60
60
|
store.setUser(user);
|
|
61
61
|
// Create and initialize auth instance
|
|
62
|
-
_instance = new AfloatAuth(store, tokenHandler);
|
|
63
|
-
return _instance;
|
|
62
|
+
this._instance = new AfloatAuth(store, tokenHandler);
|
|
63
|
+
return this._instance;
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
if (error instanceof Error) {
|
|
@@ -75,10 +75,13 @@ export class AfloatAuth {
|
|
|
75
75
|
* @returns {AfloatAuth} The singleton instance
|
|
76
76
|
*/
|
|
77
77
|
static get instance() {
|
|
78
|
-
if (_instance
|
|
79
|
-
|
|
78
|
+
if (!this._instance) {
|
|
79
|
+
if (EnvironmentDetector.isClient()) {
|
|
80
|
+
return this.initializeClient();
|
|
81
|
+
}
|
|
82
|
+
throw new Error("AfloatAuth has not been initialized");
|
|
80
83
|
}
|
|
81
|
-
return _instance;
|
|
84
|
+
return this._instance;
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
87
|
* Gets the authentication repository instance.
|
|
@@ -159,3 +162,9 @@ export class AfloatAuth {
|
|
|
159
162
|
this.tokenHandler.clearToken();
|
|
160
163
|
}
|
|
161
164
|
}
|
|
165
|
+
Object.defineProperty(AfloatAuth, "_instance", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
configurable: true,
|
|
168
|
+
writable: true,
|
|
169
|
+
value: null
|
|
170
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type RuntimeEnvironment = "client" | "server";
|
|
2
|
+
export declare class EnvironmentDetector {
|
|
3
|
+
private static _environment;
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current runtime environment
|
|
6
|
+
* @returns {RuntimeEnvironment}
|
|
7
|
+
* @throws {Error} If environment cannot be definitively determined
|
|
8
|
+
*/
|
|
9
|
+
static detect(): RuntimeEnvironment;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if code is running in client environment
|
|
12
|
+
*/
|
|
13
|
+
static isClient(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if code is running in server environment
|
|
16
|
+
*/
|
|
17
|
+
static isServer(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Explicitly sets the environment (useful for testing)
|
|
20
|
+
* @param {RuntimeEnvironment} env
|
|
21
|
+
*/
|
|
22
|
+
static setEnvironment(env: RuntimeEnvironment): void;
|
|
23
|
+
/**
|
|
24
|
+
* Resets the detected environment (useful for testing)
|
|
25
|
+
*/
|
|
26
|
+
static reset(): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=env_detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env_detect.d.ts","sourceRoot":"","sources":["../../../src/src/utils/env_detect.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,YAAY,CAAmC;IAE9D;;;;OAIG;WACW,MAAM,IAAI,kBAAkB;IAyC1C;;OAEG;WACW,QAAQ,IAAI,OAAO;IAIjC;;OAEG;WACW,QAAQ,IAAI,OAAO;IAIjC;;;OAGG;WACW,cAAc,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI;IAI3D;;OAEG;WACW,KAAK,IAAI,IAAI;CAG5B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
export class EnvironmentDetector {
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current runtime environment
|
|
6
|
+
* @returns {RuntimeEnvironment}
|
|
7
|
+
* @throws {Error} If environment cannot be definitively determined
|
|
8
|
+
*/
|
|
9
|
+
static detect() {
|
|
10
|
+
// If already detected, return cached result
|
|
11
|
+
if (this._environment) {
|
|
12
|
+
return this._environment;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
// Check for Deno specific global
|
|
16
|
+
if (typeof dntShim.Deno !== "undefined") {
|
|
17
|
+
this._environment = "server";
|
|
18
|
+
return this._environment;
|
|
19
|
+
}
|
|
20
|
+
// For non-Deno environments, we can use process
|
|
21
|
+
if (typeof process !== "undefined" &&
|
|
22
|
+
process.versions?.node &&
|
|
23
|
+
!process.versions?.bun) {
|
|
24
|
+
this._environment = "server";
|
|
25
|
+
return this._environment;
|
|
26
|
+
}
|
|
27
|
+
// For client environments, check window
|
|
28
|
+
// This will throw ReferenceError in Deno
|
|
29
|
+
if (typeof dntShim.dntGlobalThis !== "undefined") {
|
|
30
|
+
this._environment = "client";
|
|
31
|
+
return this._environment;
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Unable to determine runtime environment");
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// If we get a ReferenceError for 'window' in Deno, we're in server
|
|
37
|
+
if (error instanceof ReferenceError) {
|
|
38
|
+
this._environment = "server";
|
|
39
|
+
return this._environment;
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if code is running in client environment
|
|
46
|
+
*/
|
|
47
|
+
static isClient() {
|
|
48
|
+
return this.detect() === "client";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if code is running in server environment
|
|
52
|
+
*/
|
|
53
|
+
static isServer() {
|
|
54
|
+
return this.detect() === "server";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Explicitly sets the environment (useful for testing)
|
|
58
|
+
* @param {RuntimeEnvironment} env
|
|
59
|
+
*/
|
|
60
|
+
static setEnvironment(env) {
|
|
61
|
+
this._environment = env;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resets the detected environment (useful for testing)
|
|
65
|
+
*/
|
|
66
|
+
static reset() {
|
|
67
|
+
this._environment = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
Object.defineProperty(EnvironmentDetector, "_environment", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: null
|
|
75
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/afloat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A JavaScript/TypeScript package providing common utilities and logic shared across all Temboplus-Afloat Projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"antd": "^5.22.7",
|
|
29
29
|
"uuid": "^11.0.3",
|
|
30
30
|
"zod": "^3.24.1",
|
|
31
|
-
"zustand": "^5.0.2"
|
|
31
|
+
"zustand": "^5.0.2",
|
|
32
|
+
"@deno/shim-deno": "~0.18.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^20.9.0",
|
|
35
36
|
"picocolors": "^1.0.0",
|
|
36
|
-
"@faker-js/faker": "9.3.0"
|
|
37
|
-
"@deno/shim-deno": "~0.18.0"
|
|
37
|
+
"@faker-js/faker": "9.3.0"
|
|
38
38
|
},
|
|
39
39
|
"_generatedBy": "dnt@dev"
|
|
40
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dntGlobalThis = exports.Deno = void 0;
|
|
4
|
+
const shim_deno_1 = require("@deno/shim-deno");
|
|
5
|
+
var shim_deno_2 = require("@deno/shim-deno");
|
|
6
|
+
Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
|
|
7
|
+
const dntGlobals = {
|
|
8
|
+
Deno: shim_deno_1.Deno,
|
|
9
|
+
};
|
|
10
|
+
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
11
|
+
function createMergeProxy(baseObj, extObj) {
|
|
12
|
+
return new Proxy(baseObj, {
|
|
13
|
+
get(_target, prop, _receiver) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
return extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return baseObj[prop];
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
set(_target, prop, value) {
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
}
|
|
25
|
+
baseObj[prop] = value;
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
deleteProperty(_target, prop) {
|
|
29
|
+
let success = false;
|
|
30
|
+
if (prop in extObj) {
|
|
31
|
+
delete extObj[prop];
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
if (prop in baseObj) {
|
|
35
|
+
delete baseObj[prop];
|
|
36
|
+
success = true;
|
|
37
|
+
}
|
|
38
|
+
return success;
|
|
39
|
+
},
|
|
40
|
+
ownKeys(_target) {
|
|
41
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
42
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
43
|
+
const extKeysSet = new Set(extKeys);
|
|
44
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
45
|
+
},
|
|
46
|
+
defineProperty(_target, prop, desc) {
|
|
47
|
+
if (prop in extObj) {
|
|
48
|
+
delete extObj[prop];
|
|
49
|
+
}
|
|
50
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
54
|
+
if (prop in extObj) {
|
|
55
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
has(_target, prop) {
|
|
62
|
+
return prop in extObj || prop in baseObj;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare class AfloatAuth {
|
|
|
9
9
|
private store;
|
|
10
10
|
/** The token handler implementation */
|
|
11
11
|
private tokenHandler;
|
|
12
|
+
private static _instance;
|
|
12
13
|
/**
|
|
13
14
|
* Private constructor to prevent direct instantiation.
|
|
14
15
|
* @param {AuthStore} store - The auth store implementation to use
|
|
@@ -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;AAW7D;;;GAGG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,OAAO,CAAC,KAAK,CAAY;IAEzB,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAe;IAEnC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IAEnD;;;;OAIG;IACH,OAAO;IAKP;;;;OAIG;WACW,gBAAgB,IAAI,UAAU;IAQ5C;;;;;;OAMG;WACiB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBxE;;;;OAIG;IACH,WAAkB,QAAQ,IAAI,UAAU,CASvC;IAED;;;;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,7 @@ 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
|
-
|
|
9
|
+
const env_detect_js_1 = require("../../utils/env_detect.js");
|
|
10
10
|
/**
|
|
11
11
|
* Main authentication class that works in both client and server environments.
|
|
12
12
|
* Provides authentication functionality and user management.
|
|
@@ -41,8 +41,8 @@ class AfloatAuth {
|
|
|
41
41
|
* @returns {AfloatAuth} The singleton instance configured for client-side
|
|
42
42
|
*/
|
|
43
43
|
static initializeClient() {
|
|
44
|
-
_instance = new AfloatAuth((0, client_store_js_1.createClientStore)(), client_token_handler_js_1.ClientTokenHandler.instance);
|
|
45
|
-
return _instance;
|
|
44
|
+
this._instance = new AfloatAuth((0, client_store_js_1.createClientStore)(), client_token_handler_js_1.ClientTokenHandler.instance);
|
|
45
|
+
return this._instance;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Creates a new instance of AfloatAuth configured for server-side use.
|
|
@@ -62,8 +62,8 @@ class AfloatAuth {
|
|
|
62
62
|
const user = await tokenHandler.constructUser();
|
|
63
63
|
store.setUser(user);
|
|
64
64
|
// Create and initialize auth instance
|
|
65
|
-
_instance = new AfloatAuth(store, tokenHandler);
|
|
66
|
-
return _instance;
|
|
65
|
+
this._instance = new AfloatAuth(store, tokenHandler);
|
|
66
|
+
return this._instance;
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
69
69
|
if (error instanceof Error) {
|
|
@@ -78,10 +78,13 @@ class AfloatAuth {
|
|
|
78
78
|
* @returns {AfloatAuth} The singleton instance
|
|
79
79
|
*/
|
|
80
80
|
static get instance() {
|
|
81
|
-
if (_instance
|
|
82
|
-
|
|
81
|
+
if (!this._instance) {
|
|
82
|
+
if (env_detect_js_1.EnvironmentDetector.isClient()) {
|
|
83
|
+
return this.initializeClient();
|
|
84
|
+
}
|
|
85
|
+
throw new Error("AfloatAuth has not been initialized");
|
|
83
86
|
}
|
|
84
|
-
return _instance;
|
|
87
|
+
return this._instance;
|
|
85
88
|
}
|
|
86
89
|
/**
|
|
87
90
|
* Gets the authentication repository instance.
|
|
@@ -163,3 +166,9 @@ class AfloatAuth {
|
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
exports.AfloatAuth = AfloatAuth;
|
|
169
|
+
Object.defineProperty(AfloatAuth, "_instance", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
configurable: true,
|
|
172
|
+
writable: true,
|
|
173
|
+
value: null
|
|
174
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type RuntimeEnvironment = "client" | "server";
|
|
2
|
+
export declare class EnvironmentDetector {
|
|
3
|
+
private static _environment;
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current runtime environment
|
|
6
|
+
* @returns {RuntimeEnvironment}
|
|
7
|
+
* @throws {Error} If environment cannot be definitively determined
|
|
8
|
+
*/
|
|
9
|
+
static detect(): RuntimeEnvironment;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if code is running in client environment
|
|
12
|
+
*/
|
|
13
|
+
static isClient(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if code is running in server environment
|
|
16
|
+
*/
|
|
17
|
+
static isServer(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Explicitly sets the environment (useful for testing)
|
|
20
|
+
* @param {RuntimeEnvironment} env
|
|
21
|
+
*/
|
|
22
|
+
static setEnvironment(env: RuntimeEnvironment): void;
|
|
23
|
+
/**
|
|
24
|
+
* Resets the detected environment (useful for testing)
|
|
25
|
+
*/
|
|
26
|
+
static reset(): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=env_detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env_detect.d.ts","sourceRoot":"","sources":["../../../src/src/utils/env_detect.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,YAAY,CAAmC;IAE9D;;;;OAIG;WACW,MAAM,IAAI,kBAAkB;IAyC1C;;OAEG;WACW,QAAQ,IAAI,OAAO;IAIjC;;OAEG;WACW,QAAQ,IAAI,OAAO;IAIjC;;;OAGG;WACW,cAAc,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI;IAI3D;;OAEG;WACW,KAAK,IAAI,IAAI;CAG5B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.EnvironmentDetector = void 0;
|
|
30
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
31
|
+
const node_process_1 = __importDefault(require("node:process"));
|
|
32
|
+
class EnvironmentDetector {
|
|
33
|
+
/**
|
|
34
|
+
* Detects the current runtime environment
|
|
35
|
+
* @returns {RuntimeEnvironment}
|
|
36
|
+
* @throws {Error} If environment cannot be definitively determined
|
|
37
|
+
*/
|
|
38
|
+
static detect() {
|
|
39
|
+
// If already detected, return cached result
|
|
40
|
+
if (this._environment) {
|
|
41
|
+
return this._environment;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
// Check for Deno specific global
|
|
45
|
+
if (typeof dntShim.Deno !== "undefined") {
|
|
46
|
+
this._environment = "server";
|
|
47
|
+
return this._environment;
|
|
48
|
+
}
|
|
49
|
+
// For non-Deno environments, we can use process
|
|
50
|
+
if (typeof node_process_1.default !== "undefined" &&
|
|
51
|
+
node_process_1.default.versions?.node &&
|
|
52
|
+
!node_process_1.default.versions?.bun) {
|
|
53
|
+
this._environment = "server";
|
|
54
|
+
return this._environment;
|
|
55
|
+
}
|
|
56
|
+
// For client environments, check window
|
|
57
|
+
// This will throw ReferenceError in Deno
|
|
58
|
+
if (typeof dntShim.dntGlobalThis !== "undefined") {
|
|
59
|
+
this._environment = "client";
|
|
60
|
+
return this._environment;
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Unable to determine runtime environment");
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// If we get a ReferenceError for 'window' in Deno, we're in server
|
|
66
|
+
if (error instanceof ReferenceError) {
|
|
67
|
+
this._environment = "server";
|
|
68
|
+
return this._environment;
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks if code is running in client environment
|
|
75
|
+
*/
|
|
76
|
+
static isClient() {
|
|
77
|
+
return this.detect() === "client";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if code is running in server environment
|
|
81
|
+
*/
|
|
82
|
+
static isServer() {
|
|
83
|
+
return this.detect() === "server";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Explicitly sets the environment (useful for testing)
|
|
87
|
+
* @param {RuntimeEnvironment} env
|
|
88
|
+
*/
|
|
89
|
+
static setEnvironment(env) {
|
|
90
|
+
this._environment = env;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Resets the detected environment (useful for testing)
|
|
94
|
+
*/
|
|
95
|
+
static reset() {
|
|
96
|
+
this._environment = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.EnvironmentDetector = EnvironmentDetector;
|
|
100
|
+
Object.defineProperty(EnvironmentDetector, "_environment", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: null
|
|
105
|
+
});
|