@tern-secure/auth 1.1.0-canary.v20251108045933 → 1.1.0-canary.v20251125170702
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/492_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/687_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/68_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/framework_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/signin_ternsecure_f36de9_1.1.0-canary.v20251125170702.css +2 -0
- package/dist/signin_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/signup_ternsecure_f36de9_1.1.0-canary.v20251125170702.css +2 -0
- package/dist/signup_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/ternsecure.browser.js +30 -0
- package/dist/ternsecure.css +2 -0
- package/dist/ternsecure.js +17 -0
- package/dist/ternsecure.mjs +17 -0
- package/dist/types/auth/AuthCookieManager.d.ts +0 -1
- package/dist/types/auth/cookies/authTime_cookie.d.ts +0 -1
- package/dist/types/index.browser.d.ts +1 -0
- package/dist/types/index.d.ts +3 -10
- package/dist/types/instance/c_coreApiClient.d.ts +2 -2
- package/dist/types/instance/constants.d.ts +3 -0
- package/dist/types/instance/coreApiClient.d.ts +0 -1
- package/dist/types/instance/events.d.ts +0 -1
- package/dist/types/instance/{TernAuth.d.ts → ternsecure.d.ts} +31 -7
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/resources/Base.d.ts +16 -3
- package/dist/types/resources/Error.d.ts +0 -1
- package/dist/types/resources/Session.d.ts +2 -2
- package/dist/types/resources/SignIn.d.ts +27 -10
- package/dist/types/resources/SignUp.d.ts +12 -10
- package/dist/types/resources/internal.d.ts +1 -2
- package/dist/types/ui/Renderer.d.ts +26 -0
- package/dist/types/ui/common/ProviderInitialIcon.d.ts +6 -0
- package/dist/types/ui/common/VerificationCodeCard.d.ts +12 -0
- package/dist/types/ui/common/VerificationLinkCard.d.ts +7 -0
- package/dist/types/ui/common/constants.d.ts +8 -0
- package/dist/types/ui/common/index.d.ts +3 -0
- package/dist/types/ui/components/sign-in/ResetPassword.d.ts +1 -0
- package/dist/types/ui/components/sign-in/ResetPasswordSuccess.d.ts +1 -0
- package/dist/types/ui/components/sign-in/SignIn.d.ts +4 -0
- package/dist/types/ui/components/sign-in/SignInEmailLinkCard.d.ts +2 -0
- package/dist/types/ui/components/sign-in/SignInFactorOne.d.ts +1 -0
- package/dist/types/ui/components/sign-in/SignInFactorOneCodeForm.d.ts +7 -0
- package/dist/types/ui/components/sign-in/SignInFactorOnePasswordCard.d.ts +6 -0
- package/dist/types/ui/components/sign-in/SignInFactorOnePhoneCodeCard.d.ts +7 -0
- package/dist/types/ui/components/sign-in/SignInPassword.d.ts +8 -0
- package/dist/types/ui/components/sign-in/SignInSocialButtons.d.ts +1 -0
- package/dist/types/ui/components/sign-in/SignInStart.d.ts +7 -0
- package/dist/types/ui/components/sign-in/SignInVerifyEmail.d.ts +1 -0
- package/dist/types/ui/components/sign-in/index.d.ts +4 -0
- package/dist/types/ui/components/sign-up/SignUp.d.ts +8 -0
- package/dist/types/ui/components/sign-up/SignUpEmailLinkCard.d.ts +2 -0
- package/dist/types/ui/components/sign-up/SignUpSocialButtons.d.ts +1 -0
- package/dist/types/ui/components/sign-up/SignUpStart.d.ts +1 -0
- package/dist/types/ui/components/sign-up/SignUpVerifyEmail.d.ts +1 -0
- package/dist/types/ui/components/sign-up/index.d.ts +2 -0
- package/dist/types/ui/components/sign-up/util.d.ts +14 -0
- package/dist/types/ui/components/user-button/index.d.ts +1 -0
- package/dist/types/ui/components/user-button/userButton.d.ts +1 -0
- package/dist/types/ui/ctx/TernAuthContext.d.ts +4 -0
- package/dist/types/ui/ctx/TernAuthUIComponentCtx.d.ts +8 -0
- package/dist/types/ui/ctx/TernSecureContextWrapper.d.ts +8 -0
- package/dist/types/ui/ctx/TernSecureOptions.d.ts +10 -0
- package/dist/types/ui/ctx/components/SignIn.d.ts +21 -0
- package/dist/types/ui/ctx/components/SignUp.d.ts +14 -0
- package/dist/types/ui/ctx/components/UserButton.d.ts +10 -0
- package/dist/types/ui/ctx/components/index.d.ts +3 -0
- package/dist/types/ui/ctx/index.d.ts +4 -0
- package/dist/types/ui/ctx/utils.d.ts +3 -0
- package/dist/types/ui/customize/FieldControl.d.ts +15 -0
- package/dist/types/ui/customize/FieldLabelControl.d.ts +11 -0
- package/dist/types/ui/customize/Form.d.ts +36 -0
- package/dist/types/ui/elements/CodeControl.d.ts +47 -0
- package/dist/types/ui/elements/ErrorCard.d.ts +10 -0
- package/dist/types/ui/elements/LoadingCard.d.ts +1 -0
- package/dist/types/ui/elements/RouterLink.d.ts +42 -0
- package/dist/types/ui/elements/SocialButtons.d.ts +6 -0
- package/dist/types/ui/elements/TimerButton.d.ts +9 -0
- package/dist/types/ui/elements/alert.d.ts +8 -0
- package/dist/types/ui/elements/avatar.d.ts +6 -0
- package/dist/types/ui/elements/button.d.ts +10 -0
- package/dist/types/ui/elements/card.d.ts +9 -0
- package/dist/types/ui/elements/ctx/CardStateCtx.d.ts +26 -0
- package/dist/types/ui/elements/ctx/index.d.ts +1 -0
- package/dist/types/ui/elements/field.d.ts +24 -0
- package/dist/types/ui/elements/index.d.ts +16 -0
- package/dist/types/ui/elements/input.d.ts +3 -0
- package/dist/types/ui/elements/label.d.ts +4 -0
- package/dist/types/ui/elements/separator.d.ts +4 -0
- package/dist/types/ui/hooks/index.d.ts +6 -0
- package/dist/types/ui/hooks/useEmailLink.d.ts +11 -0
- package/dist/types/ui/hooks/useFetch.d.ts +44 -0
- package/dist/types/ui/hooks/useLoadingStatus.d.ts +14 -0
- package/dist/types/ui/hooks/useNavigateToFlowStart.d.ts +3 -0
- package/dist/types/ui/hooks/useSafeState.d.ts +9 -0
- package/dist/types/ui/hooks/useWindowEventListener.d.ts +3 -0
- package/dist/types/ui/icons/index.d.ts +13 -0
- package/dist/types/ui/lazyLoading/common.d.ts +2 -0
- package/dist/types/ui/lazyLoading/components.d.ts +11 -0
- package/dist/types/ui/lazyLoading/providersCtx.d.ts +26 -0
- package/dist/types/ui/portal/index.d.ts +12 -0
- package/dist/types/ui/router/BaseRouter.d.ts +21 -0
- package/dist/types/ui/router/HashRouter.d.ts +8 -0
- package/dist/types/ui/router/PathRouter.d.ts +8 -0
- package/dist/types/ui/router/Route.d.ts +19 -0
- package/dist/types/ui/router/RouterCtx.d.ts +32 -0
- package/dist/types/ui/router/Switch.d.ts +4 -0
- package/dist/types/ui/router/index.d.ts +7 -0
- package/dist/types/ui/router/newPaths.d.ts +1 -0
- package/dist/types/ui/router/pathToRegexp.d.ts +127 -0
- package/dist/types/ui/types.d.ts +18 -0
- package/dist/types/ui/utils/form.d.ts +19 -0
- package/dist/types/ui/utils/index.d.ts +1 -0
- package/dist/types/ui/utils/sleep.d.ts +1 -0
- package/dist/types/utils/construct.d.ts +3 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/normalizeRoutingOptions.d.ts +6 -0
- package/dist/types/utils/path.d.ts +0 -1
- package/dist/types/utils/querystring.d.ts +0 -1
- package/dist/types/utils/redirectUrls.d.ts +4 -9
- package/dist/types/utils/windowNavigate.d.ts +0 -1
- package/dist/ui-common_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/userbutton_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/dist/vendors_ternsecure_f36de9_1.1.0-canary.v20251125170702.js +1 -0
- package/package.json +63 -24
- package/dist/cjs/auth/AuthCookieManager.js +0 -113
- package/dist/cjs/auth/AuthCookieManager.js.map +0 -1
- package/dist/cjs/auth/cookies/authTime_cookie.js +0 -62
- package/dist/cjs/auth/cookies/authTime_cookie.js.map +0 -1
- package/dist/cjs/auth/request.js +0 -159
- package/dist/cjs/auth/request.js.map +0 -1
- package/dist/cjs/global.d.js +0 -2
- package/dist/cjs/global.d.js.map +0 -1
- package/dist/cjs/index.js +0 -47
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/instance/TernAuth.js +0 -524
- package/dist/cjs/instance/TernAuth.js.map +0 -1
- package/dist/cjs/instance/TernAuthServer.js +0 -95
- package/dist/cjs/instance/TernAuthServer.js.map +0 -1
- package/dist/cjs/instance/c_coreApiClient.js +0 -264
- package/dist/cjs/instance/c_coreApiClient.js.map +0 -1
- package/dist/cjs/instance/coreApiClient.js +0 -255
- package/dist/cjs/instance/coreApiClient.js.map +0 -1
- package/dist/cjs/instance/events.js +0 -39
- package/dist/cjs/instance/events.js.map +0 -1
- package/dist/cjs/instance/jwtClient.js +0 -72
- package/dist/cjs/instance/jwtClient.js.map +0 -1
- package/dist/cjs/resources/Base.js +0 -137
- package/dist/cjs/resources/Base.js.map +0 -1
- package/dist/cjs/resources/Error.js +0 -31
- package/dist/cjs/resources/Error.js.map +0 -1
- package/dist/cjs/resources/Session.js +0 -105
- package/dist/cjs/resources/Session.js.map +0 -1
- package/dist/cjs/resources/SignIn.js +0 -256
- package/dist/cjs/resources/SignIn.js.map +0 -1
- package/dist/cjs/resources/SignUp.js +0 -72
- package/dist/cjs/resources/SignUp.js.map +0 -1
- package/dist/cjs/resources/Token.js +0 -32
- package/dist/cjs/resources/Token.js.map +0 -1
- package/dist/cjs/resources/UserData.js +0 -43
- package/dist/cjs/resources/UserData.js.map +0 -1
- package/dist/cjs/resources/cookie.js +0 -154
- package/dist/cjs/resources/cookie.js.map +0 -1
- package/dist/cjs/resources/index.js +0 -23
- package/dist/cjs/resources/index.js.map +0 -1
- package/dist/cjs/resources/internal.js +0 -35
- package/dist/cjs/resources/internal.js.map +0 -1
- package/dist/cjs/utils/construct.js +0 -253
- package/dist/cjs/utils/construct.js.map +0 -1
- package/dist/cjs/utils/index.js +0 -29
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/jwt.js +0 -46
- package/dist/cjs/utils/jwt.js.map +0 -1
- package/dist/cjs/utils/mapDecode.js +0 -33
- package/dist/cjs/utils/mapDecode.js.map +0 -1
- package/dist/cjs/utils/path.js +0 -33
- package/dist/cjs/utils/path.js.map +0 -1
- package/dist/cjs/utils/querystring.js +0 -70
- package/dist/cjs/utils/querystring.js.map +0 -1
- package/dist/cjs/utils/redirectUrls.js +0 -156
- package/dist/cjs/utils/redirectUrls.js.map +0 -1
- package/dist/cjs/utils/windowNavigate.js +0 -45
- package/dist/cjs/utils/windowNavigate.js.map +0 -1
- package/dist/esm/auth/AuthCookieManager.js +0 -89
- package/dist/esm/auth/AuthCookieManager.js.map +0 -1
- package/dist/esm/auth/cookies/authTime_cookie.js +0 -38
- package/dist/esm/auth/cookies/authTime_cookie.js.map +0 -1
- package/dist/esm/auth/request.js +0 -134
- package/dist/esm/auth/request.js.map +0 -1
- package/dist/esm/global.d.js +0 -1
- package/dist/esm/global.d.js.map +0 -1
- package/dist/esm/index.js +0 -16
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/instance/TernAuth.js +0 -510
- package/dist/esm/instance/TernAuth.js.map +0 -1
- package/dist/esm/instance/TernAuthServer.js +0 -73
- package/dist/esm/instance/TernAuthServer.js.map +0 -1
- package/dist/esm/instance/c_coreApiClient.js +0 -236
- package/dist/esm/instance/c_coreApiClient.js.map +0 -1
- package/dist/esm/instance/coreApiClient.js +0 -226
- package/dist/esm/instance/coreApiClient.js.map +0 -1
- package/dist/esm/instance/events.js +0 -14
- package/dist/esm/instance/events.js.map +0 -1
- package/dist/esm/instance/jwtClient.js +0 -47
- package/dist/esm/instance/jwtClient.js.map +0 -1
- package/dist/esm/resources/Base.js +0 -113
- package/dist/esm/resources/Base.js.map +0 -1
- package/dist/esm/resources/Error.js +0 -9
- package/dist/esm/resources/Error.js.map +0 -1
- package/dist/esm/resources/Session.js +0 -81
- package/dist/esm/resources/Session.js.map +0 -1
- package/dist/esm/resources/SignIn.js +0 -240
- package/dist/esm/resources/SignIn.js.map +0 -1
- package/dist/esm/resources/SignUp.js +0 -48
- package/dist/esm/resources/SignUp.js.map +0 -1
- package/dist/esm/resources/Token.js +0 -8
- package/dist/esm/resources/Token.js.map +0 -1
- package/dist/esm/resources/UserData.js +0 -19
- package/dist/esm/resources/UserData.js.map +0 -1
- package/dist/esm/resources/cookie.js +0 -130
- package/dist/esm/resources/cookie.js.map +0 -1
- package/dist/esm/resources/index.js +0 -2
- package/dist/esm/resources/index.js.map +0 -1
- package/dist/esm/resources/internal.js +0 -8
- package/dist/esm/resources/internal.js.map +0 -1
- package/dist/esm/utils/construct.js +0 -215
- package/dist/esm/utils/construct.js.map +0 -1
- package/dist/esm/utils/index.js +0 -5
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/esm/utils/jwt.js +0 -22
- package/dist/esm/utils/jwt.js.map +0 -1
- package/dist/esm/utils/mapDecode.js +0 -9
- package/dist/esm/utils/mapDecode.js.map +0 -1
- package/dist/esm/utils/path.js +0 -9
- package/dist/esm/utils/path.js.map +0 -1
- package/dist/esm/utils/querystring.js +0 -45
- package/dist/esm/utils/querystring.js.map +0 -1
- package/dist/esm/utils/redirectUrls.js +0 -132
- package/dist/esm/utils/redirectUrls.js.map +0 -1
- package/dist/esm/utils/windowNavigate.js +0 -19
- package/dist/esm/utils/windowNavigate.js.map +0 -1
- package/dist/types/auth/AuthCookieManager.d.ts.map +0 -1
- package/dist/types/auth/cookies/authTime_cookie.d.ts.map +0 -1
- package/dist/types/auth/request.d.ts +0 -49
- package/dist/types/auth/request.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/instance/TernAuth.d.ts.map +0 -1
- package/dist/types/instance/TernAuthServer.d.ts +0 -32
- package/dist/types/instance/TernAuthServer.d.ts.map +0 -1
- package/dist/types/instance/c_coreApiClient.d.ts.map +0 -1
- package/dist/types/instance/coreApiClient.d.ts.map +0 -1
- package/dist/types/instance/events.d.ts.map +0 -1
- package/dist/types/instance/jwtClient.d.ts +0 -22
- package/dist/types/instance/jwtClient.d.ts.map +0 -1
- package/dist/types/resources/Base.d.ts.map +0 -1
- package/dist/types/resources/Error.d.ts.map +0 -1
- package/dist/types/resources/Session.d.ts.map +0 -1
- package/dist/types/resources/SignIn.d.ts.map +0 -1
- package/dist/types/resources/SignUp.d.ts.map +0 -1
- package/dist/types/resources/Token.d.ts +0 -5
- package/dist/types/resources/Token.d.ts.map +0 -1
- package/dist/types/resources/UserData.d.ts +0 -8
- package/dist/types/resources/UserData.d.ts.map +0 -1
- package/dist/types/resources/cookie.d.ts +0 -24
- package/dist/types/resources/cookie.d.ts.map +0 -1
- package/dist/types/resources/index.d.ts +0 -2
- package/dist/types/resources/index.d.ts.map +0 -1
- package/dist/types/resources/internal.d.ts.map +0 -1
- package/dist/types/utils/construct.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/jwt.d.ts +0 -12
- package/dist/types/utils/jwt.d.ts.map +0 -1
- package/dist/types/utils/mapDecode.d.ts +0 -4
- package/dist/types/utils/mapDecode.d.ts.map +0 -1
- package/dist/types/utils/path.d.ts.map +0 -1
- package/dist/types/utils/querystring.d.ts.map +0 -1
- package/dist/types/utils/redirectUrls.d.ts.map +0 -1
- package/dist/types/utils/windowNavigate.d.ts.map +0 -1
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var TernAuth_exports = {};
|
|
20
|
-
__export(TernAuth_exports, {
|
|
21
|
-
TernSecureAuth: () => TernSecureAuth,
|
|
22
|
-
inBrowser: () => inBrowser
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(TernAuth_exports);
|
|
25
|
-
var import_errors = require("@tern-secure/shared/errors");
|
|
26
|
-
var import_ternStatusEvent = require("@tern-secure/shared/ternStatusEvent");
|
|
27
|
-
var import_url = require("@tern-secure/shared/url");
|
|
28
|
-
var import_utils = require("@tern-secure/shared/utils");
|
|
29
|
-
var import_app = require("firebase/app");
|
|
30
|
-
var import_auth = require("firebase/auth");
|
|
31
|
-
var import_installations = require("firebase/installations");
|
|
32
|
-
var import_internal = require("../resources/internal");
|
|
33
|
-
var import_utils2 = require("../utils/");
|
|
34
|
-
var import_redirectUrls = require("../utils/redirectUrls");
|
|
35
|
-
var import_c_coreApiClient = require("./c_coreApiClient");
|
|
36
|
-
var import_events = require("./events");
|
|
37
|
-
function inBrowser() {
|
|
38
|
-
return typeof window !== "undefined";
|
|
39
|
-
}
|
|
40
|
-
class TernSecureAuth {
|
|
41
|
-
static version = "1.1.0-canary.v20251108045933";
|
|
42
|
-
static sdkMetadata = {
|
|
43
|
-
name: "@tern-secure/auth",
|
|
44
|
-
version: "1.1.0-canary.v20251108045933",
|
|
45
|
-
environment: process.env.NODE_ENV || "production"
|
|
46
|
-
};
|
|
47
|
-
static instance = null;
|
|
48
|
-
_currentUser = null;
|
|
49
|
-
signedInSession = null;
|
|
50
|
-
firebaseClientApp;
|
|
51
|
-
authStateUnsubscribe = null;
|
|
52
|
-
auth;
|
|
53
|
-
csrfToken;
|
|
54
|
-
isLoading = false;
|
|
55
|
-
error = null;
|
|
56
|
-
user = null;
|
|
57
|
-
__internal_country;
|
|
58
|
-
#domain;
|
|
59
|
-
#apiClient;
|
|
60
|
-
#apiUrl;
|
|
61
|
-
#instanceType;
|
|
62
|
-
#status = "loading";
|
|
63
|
-
#listeners = [];
|
|
64
|
-
#options = {};
|
|
65
|
-
#authCookieManager;
|
|
66
|
-
#publicEventBus = (0, import_ternStatusEvent.createTernAuthEventBus)();
|
|
67
|
-
signIn;
|
|
68
|
-
signUp;
|
|
69
|
-
session;
|
|
70
|
-
get isReady() {
|
|
71
|
-
return this.status === "ready";
|
|
72
|
-
}
|
|
73
|
-
get status() {
|
|
74
|
-
return this.#status;
|
|
75
|
-
}
|
|
76
|
-
get version() {
|
|
77
|
-
return TernSecureAuth.version;
|
|
78
|
-
}
|
|
79
|
-
set sdkMetadata(metadata) {
|
|
80
|
-
TernSecureAuth.sdkMetadata = metadata;
|
|
81
|
-
}
|
|
82
|
-
get sdkMetadata() {
|
|
83
|
-
return TernSecureAuth.sdkMetadata;
|
|
84
|
-
}
|
|
85
|
-
get requiresVerification() {
|
|
86
|
-
return this.#options.requiresVerification ?? true;
|
|
87
|
-
}
|
|
88
|
-
get apiUrl() {
|
|
89
|
-
return this.#apiUrl;
|
|
90
|
-
}
|
|
91
|
-
get domain() {
|
|
92
|
-
if (inBrowser()) {
|
|
93
|
-
const strippedDomainString = (0, import_url.stripScheme)(
|
|
94
|
-
(0, import_utils.handleValueOrFn)(this.#domain, new URL(window.location.href))
|
|
95
|
-
);
|
|
96
|
-
if (this.#instanceType === "production") {
|
|
97
|
-
return strippedDomainString;
|
|
98
|
-
}
|
|
99
|
-
return strippedDomainString;
|
|
100
|
-
}
|
|
101
|
-
return "";
|
|
102
|
-
}
|
|
103
|
-
get instanceType() {
|
|
104
|
-
return this.#instanceType;
|
|
105
|
-
}
|
|
106
|
-
constructor(options) {
|
|
107
|
-
var _a;
|
|
108
|
-
this.#domain = (_a = options == null ? void 0 : options.ternSecureConfig) == null ? void 0 : _a.authDomain;
|
|
109
|
-
this.#apiUrl = (options == null ? void 0 : options.apiUrl) || "";
|
|
110
|
-
this.#instanceType = process.env.NODE_ENV || "production";
|
|
111
|
-
this.#apiClient = (0, import_c_coreApiClient.createCoreApiClient)({
|
|
112
|
-
domain: this.#domain,
|
|
113
|
-
apiUrl: options == null ? void 0 : options.apiUrl,
|
|
114
|
-
instanceType: this.instanceType
|
|
115
|
-
});
|
|
116
|
-
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "loading");
|
|
117
|
-
import_internal.TernSecureBase.ternsecure = this;
|
|
118
|
-
}
|
|
119
|
-
getApiClient = () => this.#apiClient;
|
|
120
|
-
setLoading(isLoading) {
|
|
121
|
-
this.isLoading = isLoading;
|
|
122
|
-
}
|
|
123
|
-
authCookieManager() {
|
|
124
|
-
return this.#authCookieManager;
|
|
125
|
-
}
|
|
126
|
-
_internal_getOption(key) {
|
|
127
|
-
return this.#options[key];
|
|
128
|
-
}
|
|
129
|
-
_internal_getAllOptions() {
|
|
130
|
-
return Object.freeze({ ...this.#options });
|
|
131
|
-
}
|
|
132
|
-
static getOrCreateInstance(options) {
|
|
133
|
-
if (!this.instance) {
|
|
134
|
-
this.instance = new TernSecureAuth(options);
|
|
135
|
-
}
|
|
136
|
-
return this.instance;
|
|
137
|
-
}
|
|
138
|
-
static clearInstance() {
|
|
139
|
-
if (TernSecureAuth.instance) {
|
|
140
|
-
if (TernSecureAuth.instance.authStateUnsubscribe) {
|
|
141
|
-
TernSecureAuth.instance.authStateUnsubscribe();
|
|
142
|
-
TernSecureAuth.instance.authStateUnsubscribe = null;
|
|
143
|
-
}
|
|
144
|
-
TernSecureAuth.instance = null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
static initialize(options) {
|
|
148
|
-
const instance = this.getOrCreateInstance(options);
|
|
149
|
-
instance.#initialize(options);
|
|
150
|
-
return instance;
|
|
151
|
-
}
|
|
152
|
-
initialize = async (options) => {
|
|
153
|
-
void this.#initialize(options || {});
|
|
154
|
-
};
|
|
155
|
-
static create(options) {
|
|
156
|
-
const instance = this.getOrCreateInstance();
|
|
157
|
-
void instance.initialize(options);
|
|
158
|
-
return instance;
|
|
159
|
-
}
|
|
160
|
-
#initialize = (options) => {
|
|
161
|
-
this.#options = this.#initOptions(options);
|
|
162
|
-
try {
|
|
163
|
-
if (!this.#options.ternSecureConfig) {
|
|
164
|
-
throw new Error("TernSecureConfig is required to initialize TernSecureAuth");
|
|
165
|
-
}
|
|
166
|
-
if (!this.#options.apiUrl) {
|
|
167
|
-
throw new Error("apiUrl is required to initialize TernSecureAuth");
|
|
168
|
-
}
|
|
169
|
-
this.initializeFirebaseApp(this.#options.ternSecureConfig, {
|
|
170
|
-
appName: this.#options.appName,
|
|
171
|
-
tenantId: this.#options.tenantId
|
|
172
|
-
});
|
|
173
|
-
const isBrowserCookiePersistence = this.#options.persistence === "browserCookie";
|
|
174
|
-
if (!isBrowserCookiePersistence) {
|
|
175
|
-
this.authStateUnsubscribe = this.initAuthStateListener();
|
|
176
|
-
}
|
|
177
|
-
this.#authCookieManager = new import_internal.AuthCookieManager();
|
|
178
|
-
this.csrfToken = this.#authCookieManager.getCSRFToken();
|
|
179
|
-
this.signIn = new import_internal.SignIn(this.auth, this.csrfToken);
|
|
180
|
-
this.signUp = new import_internal.SignUp(this.auth);
|
|
181
|
-
import_events.eventBus.on(import_events.events.SessionChanged, () => {
|
|
182
|
-
this.#setCreatedActiveSession(this.user || null);
|
|
183
|
-
this.#emit();
|
|
184
|
-
});
|
|
185
|
-
this.#setStatus("ready");
|
|
186
|
-
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "ready");
|
|
187
|
-
} catch (error) {
|
|
188
|
-
this.error = error;
|
|
189
|
-
this.#setStatus("error");
|
|
190
|
-
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "error");
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
initializeFirebaseApp(config, options) {
|
|
195
|
-
const appName = (options == null ? void 0 : options.appName) || "[DEFAULT]";
|
|
196
|
-
this.firebaseClientApp = (0, import_app.getApps)().length === 0 ? (0, import_app.initializeApp)(config, appName) : (0, import_app.getApps)()[0];
|
|
197
|
-
const persistence = this.#setPersistence();
|
|
198
|
-
const auth = (0, import_auth.initializeAuth)(this.firebaseClientApp, {
|
|
199
|
-
persistence,
|
|
200
|
-
popupRedirectResolver: import_auth.browserPopupRedirectResolver
|
|
201
|
-
});
|
|
202
|
-
this.auth = auth;
|
|
203
|
-
if (options == null ? void 0 : options.tenantId) {
|
|
204
|
-
this.auth.tenantId = options.tenantId;
|
|
205
|
-
}
|
|
206
|
-
this.#configureEmulator();
|
|
207
|
-
(0, import_installations.getInstallations)(this.firebaseClientApp);
|
|
208
|
-
}
|
|
209
|
-
signOut = async (options) => {
|
|
210
|
-
const redirectUrl = (options == null ? void 0 : options.redirectUrl) || this.#constructAfterSignOutUrl();
|
|
211
|
-
if (options == null ? void 0 : options.onBeforeSignOut) {
|
|
212
|
-
await options.onBeforeSignOut();
|
|
213
|
-
}
|
|
214
|
-
await this.auth.signOut();
|
|
215
|
-
if (options == null ? void 0 : options.onAfterSignOut) {
|
|
216
|
-
await options.onAfterSignOut();
|
|
217
|
-
}
|
|
218
|
-
await this.navigate(redirectUrl);
|
|
219
|
-
import_events.eventBus.emit(import_events.events.UserSignOut, null);
|
|
220
|
-
import_events.eventBus.emit(import_events.events.TokenUpdate, { token: null });
|
|
221
|
-
this.#emit();
|
|
222
|
-
};
|
|
223
|
-
get currentSession() {
|
|
224
|
-
return this.signedInSession;
|
|
225
|
-
}
|
|
226
|
-
initAuthListener() {
|
|
227
|
-
(async () => {
|
|
228
|
-
await this.auth.authStateReady();
|
|
229
|
-
const user = this.auth.currentUser;
|
|
230
|
-
this._currentUser = user;
|
|
231
|
-
this.user = user;
|
|
232
|
-
await this.updateCurrentSession();
|
|
233
|
-
this.#emit();
|
|
234
|
-
})();
|
|
235
|
-
return () => {
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
initAuthStateListener() {
|
|
239
|
-
return (0, import_auth.onAuthStateChanged)(this.auth, async (user) => {
|
|
240
|
-
await this.auth.authStateReady();
|
|
241
|
-
this._currentUser = user;
|
|
242
|
-
this.user = user;
|
|
243
|
-
await this.updateCurrentSession();
|
|
244
|
-
this.#emit();
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
_onIdTokenChanged() {
|
|
248
|
-
return (0, import_auth.onIdTokenChanged)(this.auth, async (user) => {
|
|
249
|
-
await this.auth.authStateReady();
|
|
250
|
-
this._currentUser = user;
|
|
251
|
-
this.user = user;
|
|
252
|
-
await this.updateCurrentSession();
|
|
253
|
-
this.#emit();
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
async getIdToken() {
|
|
257
|
-
await this.auth.authStateReady();
|
|
258
|
-
if (!this.auth.currentUser) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
return (0, import_auth.getIdToken)(this.auth.currentUser);
|
|
262
|
-
}
|
|
263
|
-
onAuthStateChanged(callback) {
|
|
264
|
-
return (0, import_auth.onAuthStateChanged)(this.auth, callback);
|
|
265
|
-
}
|
|
266
|
-
onIdTokenChanged(callback) {
|
|
267
|
-
return (0, import_auth.onIdTokenChanged)(this.auth, callback);
|
|
268
|
-
}
|
|
269
|
-
async updateCurrentSession() {
|
|
270
|
-
if (!this._currentUser) {
|
|
271
|
-
this.signedInSession = null;
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
const res = await this._currentUser.getIdTokenResult();
|
|
276
|
-
this.signedInSession = {
|
|
277
|
-
status: "active",
|
|
278
|
-
token: res.token,
|
|
279
|
-
claims: res.claims,
|
|
280
|
-
issuedAtTime: res.issuedAtTime,
|
|
281
|
-
expirationTime: res.expirationTime,
|
|
282
|
-
authTime: res.authTime,
|
|
283
|
-
signInProvider: res.signInProvider || "unknown",
|
|
284
|
-
signInSecondFactor: res.signInSecondFactor
|
|
285
|
-
};
|
|
286
|
-
} catch (error) {
|
|
287
|
-
console.error("[TernSecureAuth] Error updating session:", error);
|
|
288
|
-
this.signedInSession = null;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
checkRedirectResult = async () => {
|
|
292
|
-
try {
|
|
293
|
-
const result = await (0, import_auth.getRedirectResult)(this.auth);
|
|
294
|
-
if (result) {
|
|
295
|
-
return {
|
|
296
|
-
status: "success",
|
|
297
|
-
user: result.user
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
return null;
|
|
301
|
-
} catch (error) {
|
|
302
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
303
|
-
return {
|
|
304
|
-
status: "error",
|
|
305
|
-
message: authError.message,
|
|
306
|
-
error: authError.code
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
getRedirectResult = async () => {
|
|
311
|
-
return this.checkRedirectResult();
|
|
312
|
-
};
|
|
313
|
-
addListener = (listener) => {
|
|
314
|
-
this.#listeners.push(listener);
|
|
315
|
-
if (this._currentUser) {
|
|
316
|
-
listener({
|
|
317
|
-
user: this._currentUser,
|
|
318
|
-
session: this.signedInSession
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
const unsubscribe = () => {
|
|
322
|
-
this.#listeners = this.#listeners.filter((l) => l !== listener);
|
|
323
|
-
};
|
|
324
|
-
return unsubscribe;
|
|
325
|
-
};
|
|
326
|
-
on = (...args) => {
|
|
327
|
-
this.#publicEventBus.on(...args);
|
|
328
|
-
};
|
|
329
|
-
off = (...args) => {
|
|
330
|
-
this.#publicEventBus.off(...args);
|
|
331
|
-
};
|
|
332
|
-
createActiveSession = async ({
|
|
333
|
-
session,
|
|
334
|
-
redirectUrl
|
|
335
|
-
}) => {
|
|
336
|
-
try {
|
|
337
|
-
if (!session) {
|
|
338
|
-
throw new Error("No session provided to createActiveSession");
|
|
339
|
-
}
|
|
340
|
-
const sessionResult = await session.getIdTokenResult();
|
|
341
|
-
const sessionData = new import_internal.Session(sessionResult);
|
|
342
|
-
await sessionData.create(this.csrfToken || "");
|
|
343
|
-
if (redirectUrl) {
|
|
344
|
-
await this.navigate(this.constructUrlWithAuthRedirect(redirectUrl));
|
|
345
|
-
}
|
|
346
|
-
this.#setCreatedActiveSession(session);
|
|
347
|
-
this.#emit();
|
|
348
|
-
} catch (error) {
|
|
349
|
-
console.error("[TernSecureAuth] Error creating active session:", error);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
navigate = async (to, options) => {
|
|
353
|
-
if (!to || !inBrowser()) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
let toURL = new URL(to, window.location.href);
|
|
357
|
-
if (!this.#allowedRedirectProtocols.includes(toURL.protocol)) {
|
|
358
|
-
console.warn(
|
|
359
|
-
`TernSecureAuth: "${toURL.protocol}" is not a valid protocol. Redirecting to "/" instead. If you think this is a mistake, please open an issue.`
|
|
360
|
-
);
|
|
361
|
-
toURL = new URL("/", window.location.href);
|
|
362
|
-
}
|
|
363
|
-
const customNavigate = (options == null ? void 0 : options.replace) && this.#options.routerReplace ? this.#options.routerReplace : this.#options.routerPush;
|
|
364
|
-
if (toURL.origin !== "null" && toURL.origin !== window.location.origin || !customNavigate) {
|
|
365
|
-
(0, import_utils2.windowNavigate)(toURL);
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const metadata = {
|
|
369
|
-
...(options == null ? void 0 : options.metadata) ? { __internal_metadata: options == null ? void 0 : options.metadata } : {},
|
|
370
|
-
windowNavigate: import_utils2.windowNavigate
|
|
371
|
-
};
|
|
372
|
-
return await customNavigate((0, import_utils2.stripOrigin)(toURL), metadata);
|
|
373
|
-
};
|
|
374
|
-
constructUrlWithAuthRedirect = (to) => {
|
|
375
|
-
if (this.#instanceType === "production") {
|
|
376
|
-
return to;
|
|
377
|
-
}
|
|
378
|
-
const baseUrl = window.location.origin;
|
|
379
|
-
const url = new URL(to, baseUrl);
|
|
380
|
-
if (url.origin === window.location.origin) {
|
|
381
|
-
return url.href;
|
|
382
|
-
}
|
|
383
|
-
return url.toString();
|
|
384
|
-
};
|
|
385
|
-
#buildUrl = (key, options) => {
|
|
386
|
-
if (!key || !this.isReady) {
|
|
387
|
-
return "";
|
|
388
|
-
}
|
|
389
|
-
const baseUrlConfig = key === "signInUrl" ? this.#options.signInUrl : this.#options.signUpUrl;
|
|
390
|
-
const defaultPagePath = key === "signInUrl" ? "/sign-in" : "/sign-up";
|
|
391
|
-
const base = baseUrlConfig || defaultPagePath;
|
|
392
|
-
const redirectUrls = new import_redirectUrls.RedirectUrls(this.#options, options).toSearchParams();
|
|
393
|
-
const constructedUrl = (0, import_utils2.buildURL)(
|
|
394
|
-
{
|
|
395
|
-
base,
|
|
396
|
-
hashSearchParams: [redirectUrls]
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
stringify: true,
|
|
400
|
-
skipOrigin: false
|
|
401
|
-
}
|
|
402
|
-
);
|
|
403
|
-
return this.constructUrlWithAuthRedirect(constructedUrl);
|
|
404
|
-
};
|
|
405
|
-
#constructAfterSignInUrl = () => {
|
|
406
|
-
return this.constructUrlWithAuthRedirect(new import_redirectUrls.RedirectUrls(this.#options).getAfterSignInUrl());
|
|
407
|
-
};
|
|
408
|
-
#constructAfterSignOutUrl = () => {
|
|
409
|
-
if (!this.#options.afterSignOutUrl) {
|
|
410
|
-
return "/";
|
|
411
|
-
}
|
|
412
|
-
return this.constructUrlWithAuthRedirect(this.#options.afterSignOutUrl);
|
|
413
|
-
};
|
|
414
|
-
redirectToSignIn = async (options) => {
|
|
415
|
-
if (inBrowser()) {
|
|
416
|
-
return this.navigate(this.constructSignInUrl(options));
|
|
417
|
-
}
|
|
418
|
-
return;
|
|
419
|
-
};
|
|
420
|
-
redirectToSignUp = async (options) => {
|
|
421
|
-
if (inBrowser()) {
|
|
422
|
-
return this.navigate(this.constructSignUpUrl());
|
|
423
|
-
}
|
|
424
|
-
return;
|
|
425
|
-
};
|
|
426
|
-
redirectAfterSignIn = async () => {
|
|
427
|
-
if (inBrowser()) {
|
|
428
|
-
return this.navigate(this.#constructAfterSignInUrl());
|
|
429
|
-
}
|
|
430
|
-
return;
|
|
431
|
-
};
|
|
432
|
-
redirectAfterSignUp = () => {
|
|
433
|
-
throw new Error("redirectAfterSignUp is not implemented yet");
|
|
434
|
-
};
|
|
435
|
-
constructSignInUrl = (options) => {
|
|
436
|
-
return this.#buildUrl("signInUrl", {
|
|
437
|
-
...options,
|
|
438
|
-
signInForceRedirectUrl: (options == null ? void 0 : options.signInForceRedirectUrl) || window.location.href
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
constructSignUpUrl = (options) => {
|
|
442
|
-
return this.#buildUrl("signUpUrl", {
|
|
443
|
-
...options,
|
|
444
|
-
signUpForceRedirectUrl: (options == null ? void 0 : options.signUpForceRedirectUrl) || window.location.href
|
|
445
|
-
});
|
|
446
|
-
};
|
|
447
|
-
get #allowedRedirectProtocols() {
|
|
448
|
-
let allowedProtocols = import_utils2.ALLOWED_PROTOCOLS;
|
|
449
|
-
if (this.#options.allowedRedirectProtocols) {
|
|
450
|
-
allowedProtocols = allowedProtocols.concat(this.#options.allowedRedirectProtocols);
|
|
451
|
-
}
|
|
452
|
-
return allowedProtocols;
|
|
453
|
-
}
|
|
454
|
-
__internal_setCountry = (country) => {
|
|
455
|
-
if (!this.__internal_country) {
|
|
456
|
-
this.__internal_country = country;
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
#initOptions = (options) => {
|
|
460
|
-
return {
|
|
461
|
-
...options
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
#emit = () => {
|
|
465
|
-
for (const listener of this.#listeners) {
|
|
466
|
-
listener({
|
|
467
|
-
user: this.user,
|
|
468
|
-
session: this.signedInSession
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
#setStatus(newStatus) {
|
|
473
|
-
if (this.#status !== newStatus) {
|
|
474
|
-
this.#status = newStatus;
|
|
475
|
-
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, this.#status);
|
|
476
|
-
if (newStatus === "ready") {
|
|
477
|
-
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "ready");
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
#setCreatedActiveSession = (session) => {
|
|
482
|
-
this.user = session;
|
|
483
|
-
this._currentUser = session;
|
|
484
|
-
};
|
|
485
|
-
#setPersistence = () => {
|
|
486
|
-
const persistenceType = this.#options.persistence;
|
|
487
|
-
switch (persistenceType) {
|
|
488
|
-
case "browserCookie":
|
|
489
|
-
return import_auth.inMemoryPersistence;
|
|
490
|
-
case "session":
|
|
491
|
-
return import_auth.browserSessionPersistence;
|
|
492
|
-
case "local":
|
|
493
|
-
return import_auth.browserLocalPersistence;
|
|
494
|
-
case "none":
|
|
495
|
-
default:
|
|
496
|
-
return import_auth.inMemoryPersistence;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
#emulatorHost = () => {
|
|
500
|
-
if (typeof process === "undefined") return void 0;
|
|
501
|
-
return process.env.FIREBASE_AUTH_EMULATOR_HOST;
|
|
502
|
-
};
|
|
503
|
-
#configureEmulator = () => {
|
|
504
|
-
const host = this.#emulatorHost();
|
|
505
|
-
const isDev = this.#instanceType === "development";
|
|
506
|
-
const shouldUseEmulator = isDev && !!host;
|
|
507
|
-
if (!shouldUseEmulator || !host) {
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
const emulatorUrl = host.startsWith("http") ? host : `http://${host}`;
|
|
511
|
-
try {
|
|
512
|
-
(0, import_auth.connectAuthEmulator)(this.auth, emulatorUrl, { disableWarnings: false });
|
|
513
|
-
console.warn(`[TernSecure] Firebase Auth Emulator connected at ${emulatorUrl}`);
|
|
514
|
-
} catch (error) {
|
|
515
|
-
console.error("[TernSecure] Error connecting to Firebase Auth Emulator:", error);
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
520
|
-
0 && (module.exports = {
|
|
521
|
-
TernSecureAuth,
|
|
522
|
-
inBrowser
|
|
523
|
-
});
|
|
524
|
-
//# sourceMappingURL=TernAuth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/instance/TernAuth.ts"],"sourcesContent":["import { handleFirebaseAuthError } from '@tern-secure/shared/errors';\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { stripScheme } from '@tern-secure/shared/url';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n CreateActiveSession,\n DomainOrProxyUrl,\n InstanceType,\n ListenerCallback,\n NavigateOptions,\n RedirectOptions,\n SessionResource,\n SignedInSession,\n SignInRedirectOptions,\n SignInResource,\n SignInResponse,\n SignOut,\n SignOutOptions,\n SignUpRedirectOptions,\n SignUpResource,\n TernAuthSDK,\n TernSecureAuth as TernSecureAuthInterface,\n TernSecureAuthOptions,\n TernSecureAuthStatus,\n TernSecureConfig,\n TernSecureResources,\n TernSecureUser,\n UnsubscribeCallback,\n} from '@tern-secure/types';\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApps, initializeApp } from 'firebase/app';\nimport type { Auth, Auth as TernAuth } from 'firebase/auth';\nimport {\n browserLocalPersistence,\n browserPopupRedirectResolver,\n browserSessionPersistence,\n connectAuthEmulator,\n getIdToken,\n getRedirectResult,\n initializeAuth,\n inMemoryPersistence,\n onAuthStateChanged,\n onIdTokenChanged,\n} from 'firebase/auth';\nimport { getInstallations } from 'firebase/installations';\n\nimport { AuthCookieManager, Session, SignIn, SignUp, TernSecureBase } from '../resources/internal';\nimport { ALLOWED_PROTOCOLS, buildURL, stripOrigin, windowNavigate } from '../utils/';\nimport { RedirectUrls } from '../utils/redirectUrls';\nimport { type ApiClient, createCoreApiClient } from './c_coreApiClient';\nimport { eventBus, events } from './events';\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport { TernAuth };\n\n/**\n * Firebase implementation of the TernSecureAuth interface\n */\nexport class TernSecureAuth implements TernSecureAuthInterface {\n public static version: string = PACKAGE_VERSION;\n public static sdkMetadata: TernAuthSDK = {\n name: PACKAGE_NAME,\n version: PACKAGE_VERSION,\n environment: process.env.NODE_ENV || 'production',\n };\n private static instance: TernSecureAuth | null = null;\n private _currentUser: TernSecureUser | null = null;\n private signedInSession: SignedInSession | null = null;\n private firebaseClientApp: FirebaseApp | undefined;\n private authStateUnsubscribe: (() => void) | null = null;\n private auth!: Auth;\n private csrfToken: string | undefined;\n public isLoading = false;\n public error: Error | null = null;\n public user: TernSecureUser | null | undefined = null;\n public __internal_country?: string | null;\n #domain: DomainOrProxyUrl['domain'];\n #apiClient: ApiClient;\n #apiUrl: string;\n #instanceType?: InstanceType;\n #status: TernSecureAuthInterface['status'] = 'loading';\n #listeners: Array<(emission: TernSecureResources) => void> = [];\n #options: TernSecureAuthOptions = {};\n #authCookieManager?: AuthCookieManager;\n #publicEventBus = createTernAuthEventBus();\n\n signIn!: SignInResource | null | undefined;\n signUp!: SignUpResource | null | undefined;\n session!: SessionResource | null | undefined;\n\n get isReady(): boolean {\n return this.status === 'ready';\n }\n\n get status(): TernSecureAuthInterface['status'] {\n return this.#status;\n }\n\n get version(): string {\n return TernSecureAuth.version;\n }\n\n set sdkMetadata(metadata: TernAuthSDK) {\n TernSecureAuth.sdkMetadata = metadata;\n }\n\n get sdkMetadata(): TernAuthSDK {\n return TernSecureAuth.sdkMetadata;\n }\n\n get requiresVerification(): boolean {\n return this.#options.requiresVerification ?? true;\n }\n\n get apiUrl(): string {\n return this.#apiUrl;\n }\n\n get domain(): string {\n if (inBrowser()) {\n const strippedDomainString = stripScheme(\n handleValueOrFn(this.#domain, new URL(window.location.href)),\n );\n if (this.#instanceType === 'production') {\n return strippedDomainString;\n }\n return strippedDomainString;\n }\n return '';\n }\n\n get instanceType() {\n return this.#instanceType;\n }\n\n public constructor(options?: TernSecureAuthOptions) {\n this.#domain = options?.ternSecureConfig?.authDomain;\n this.#apiUrl = options?.apiUrl || '';\n this.#instanceType = (process.env.NODE_ENV as InstanceType) || 'production';\n\n this.#apiClient = createCoreApiClient({\n domain: this.#domain,\n apiUrl: options?.apiUrl,\n instanceType: this.instanceType as InstanceType,\n });\n\n this.#publicEventBus.emit(ternEvents.Status, 'loading');\n TernSecureBase.ternsecure = this;\n }\n\n public getApiClient = (): ApiClient => this.#apiClient;\n\n public setLoading(isLoading: boolean): void {\n this.isLoading = isLoading;\n }\n\n public authCookieManager(): AuthCookieManager | undefined {\n return this.#authCookieManager;\n }\n\n public _internal_getOption<K extends keyof TernSecureAuthOptions>(\n key: K,\n ): TernSecureAuthOptions[K] {\n return this.#options[key];\n }\n\n public _internal_getAllOptions(): Readonly<TernSecureAuthOptions> {\n return Object.freeze({ ...this.#options });\n }\n\n static getOrCreateInstance(options?: TernSecureAuthOptions): TernSecureAuth {\n if (!this.instance) {\n this.instance = new TernSecureAuth(options);\n }\n return this.instance;\n }\n\n static clearInstance() {\n if (TernSecureAuth.instance) {\n if (TernSecureAuth.instance.authStateUnsubscribe) {\n TernSecureAuth.instance.authStateUnsubscribe();\n TernSecureAuth.instance.authStateUnsubscribe = null;\n }\n TernSecureAuth.instance = null;\n }\n }\n\n public static initialize(options: TernSecureAuthOptions): TernSecureAuth {\n const instance = this.getOrCreateInstance(options);\n instance.#initialize(options);\n return instance;\n }\n\n initialize = async (options?: TernSecureAuthOptions): Promise<void> => {\n void this.#initialize(options || {});\n };\n\n public static create(options: TernSecureAuthOptions): TernSecureAuth {\n const instance = this.getOrCreateInstance();\n void instance.initialize(options);\n return instance;\n }\n\n #initialize = (options: TernSecureAuthOptions): void => {\n this.#options = this.#initOptions(options);\n\n try {\n if (!this.#options.ternSecureConfig) {\n throw new Error('TernSecureConfig is required to initialize TernSecureAuth');\n }\n\n if (!this.#options.apiUrl) {\n throw new Error('apiUrl is required to initialize TernSecureAuth');\n }\n\n this.initializeFirebaseApp(this.#options.ternSecureConfig, {\n appName: this.#options.appName,\n tenantId: this.#options.tenantId,\n });\n\n const isBrowserCookiePersistence = this.#options.persistence === 'browserCookie';\n\n if (!isBrowserCookiePersistence) {\n this.authStateUnsubscribe = this.initAuthStateListener();\n }\n\n this.#authCookieManager = new AuthCookieManager();\n this.csrfToken = this.#authCookieManager.getCSRFToken();\n\n this.signIn = new SignIn(this.auth, this.csrfToken);\n this.signUp = new SignUp(this.auth);\n\n eventBus.on(events.SessionChanged, () => {\n this.#setCreatedActiveSession(this.user || null);\n this.#emit();\n });\n\n this.#setStatus('ready');\n this.#publicEventBus.emit(ternEvents.Status, 'ready');\n\n //return this;\n } catch (error) {\n this.error = error as Error;\n this.#setStatus('error');\n this.#publicEventBus.emit(ternEvents.Status, 'error');\n throw error;\n }\n };\n\n private initializeFirebaseApp(\n config: TernSecureConfig,\n options?: { appName?: string; tenantId?: string },\n ): void {\n const appName = options?.appName || '[DEFAULT]';\n this.firebaseClientApp = getApps().length === 0 ? initializeApp(config, appName) : getApps()[0];\n\n const persistence = this.#setPersistence();\n const auth = initializeAuth(this.firebaseClientApp, {\n persistence,\n popupRedirectResolver: browserPopupRedirectResolver,\n });\n\n this.auth = auth;\n\n if (options?.tenantId) {\n this.auth.tenantId = options.tenantId;\n }\n\n this.#configureEmulator();\n\n getInstallations(this.firebaseClientApp);\n }\n\n public signOut: SignOut = async (options?: SignOutOptions) => {\n const redirectUrl = options?.redirectUrl || this.#constructAfterSignOutUrl();\n if (options?.onBeforeSignOut) {\n await options.onBeforeSignOut();\n }\n\n await this.auth.signOut();\n\n if (options?.onAfterSignOut) {\n await options.onAfterSignOut();\n }\n\n await this.navigate(redirectUrl);\n\n eventBus.emit(events.UserSignOut, null);\n eventBus.emit(events.TokenUpdate, { token: null });\n this.#emit();\n };\n\n get currentSession(): SignedInSession | null {\n return this.signedInSession;\n }\n\n private initAuthListener(): () => void {\n (async () => {\n await this.auth.authStateReady();\n const user = this.auth.currentUser as TernSecureUser | null;\n this._currentUser = user;\n this.user = user;\n await this.updateCurrentSession();\n this.#emit();\n })();\n\n // Return a no-op unsubscribe function since we're not setting up a listener\n return () => {\n // No-op: nothing to unsubscribe from\n };\n }\n\n private initAuthStateListener(): () => void {\n return onAuthStateChanged(this.auth, async (user: TernSecureUser | null) => {\n await this.auth.authStateReady();\n this._currentUser = user;\n this.user = user;\n await this.updateCurrentSession();\n\n this.#emit();\n });\n }\n\n private _onIdTokenChanged(): () => void {\n return onIdTokenChanged(this.auth, async (user: TernSecureUser | null) => {\n await this.auth.authStateReady();\n this._currentUser = user;\n this.user = user;\n await this.updateCurrentSession();\n\n this.#emit();\n });\n }\n\n private async getIdToken(): Promise<string | null> {\n await this.auth.authStateReady();\n if (!this.auth.currentUser) {\n return null;\n }\n return getIdToken(this.auth.currentUser);\n }\n\n public onAuthStateChanged(callback: (cb: any) => void): () => void {\n return onAuthStateChanged(this.auth, callback);\n }\n\n public onIdTokenChanged(callback: (cb: any) => void): () => void {\n return onIdTokenChanged(this.auth, callback);\n }\n\n private async updateCurrentSession(): Promise<void> {\n if (!this._currentUser) {\n this.signedInSession = null;\n return;\n }\n\n try {\n const res = await this._currentUser.getIdTokenResult();\n this.signedInSession = {\n status: 'active',\n token: res.token,\n claims: res.claims,\n issuedAtTime: res.issuedAtTime,\n expirationTime: res.expirationTime,\n authTime: res.authTime,\n signInProvider: res.signInProvider || 'unknown',\n signInSecondFactor: res.signInSecondFactor,\n };\n } catch (error) {\n console.error('[TernSecureAuth] Error updating session:', error);\n this.signedInSession = null;\n }\n }\n\n private checkRedirectResult = async (): Promise<SignInResponse | null> => {\n try {\n const result = await getRedirectResult(this.auth);\n if (result) {\n return {\n status: 'success',\n user: result.user as TernSecureUser,\n };\n }\n return null;\n } catch (error) {\n const authError = handleFirebaseAuthError(error);\n return {\n status: 'error',\n message: authError.message,\n error: authError.code,\n };\n }\n };\n\n public getRedirectResult = async (): Promise<any> => {\n return this.checkRedirectResult();\n };\n\n public addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n this.#listeners.push(listener);\n if (this._currentUser) {\n listener({\n user: this._currentUser,\n session: this.signedInSession,\n });\n }\n\n const unsubscribe = () => {\n this.#listeners = this.#listeners.filter(l => l !== listener);\n };\n return unsubscribe;\n };\n\n public on: TernSecureAuthInterface['on'] = (...args) => {\n this.#publicEventBus.on(...args);\n };\n\n public off: TernSecureAuthInterface['off'] = (...args) => {\n this.#publicEventBus.off(...args);\n };\n\n public createActiveSession: CreateActiveSession = async ({\n session,\n redirectUrl,\n }): Promise<void> => {\n try {\n if (!session) {\n throw new Error('No session provided to createActiveSession');\n }\n const sessionResult = await session.getIdTokenResult();\n const sessionData = new Session(sessionResult);\n await sessionData.create(this.csrfToken || '');\n\n if (redirectUrl) {\n await this.navigate(this.constructUrlWithAuthRedirect(redirectUrl));\n }\n\n this.#setCreatedActiveSession(session);\n this.#emit();\n } catch (error) {\n console.error('[TernSecureAuth] Error creating active session:', error);\n }\n };\n\n public navigate = async (to: string | undefined, options?: NavigateOptions): Promise<unknown> => {\n if (!to || !inBrowser()) {\n return;\n }\n\n let toURL = new URL(to, window.location.href);\n\n if (!this.#allowedRedirectProtocols.includes(toURL.protocol)) {\n console.warn(\n `TernSecureAuth: \"${toURL.protocol}\" is not a valid protocol. Redirecting to \"/\" instead. If you think this is a mistake, please open an issue.`,\n );\n toURL = new URL('/', window.location.href);\n }\n\n const customNavigate =\n options?.replace && this.#options.routerReplace\n ? this.#options.routerReplace\n : this.#options.routerPush;\n\n if ((toURL.origin !== 'null' && toURL.origin !== window.location.origin) || !customNavigate) {\n windowNavigate(toURL);\n return;\n }\n\n const metadata = {\n ...(options?.metadata ? { __internal_metadata: options?.metadata } : {}),\n windowNavigate,\n };\n\n // React router only wants the path, search or hash portion.\n return await customNavigate(stripOrigin(toURL), metadata);\n };\n\n public constructUrlWithAuthRedirect = (to: string): string => {\n if (this.#instanceType === 'production') {\n return to;\n }\n const baseUrl = window.location.origin;\n const url = new URL(to, baseUrl);\n\n if (url.origin === window.location.origin) {\n return url.href;\n }\n\n return url.toString();\n };\n\n #buildUrl = (key: 'signInUrl' | 'signUpUrl', options: RedirectOptions): string => {\n if (!key || !this.isReady) {\n return '';\n }\n\n const baseUrlConfig = key === 'signInUrl' ? this.#options.signInUrl : this.#options.signUpUrl;\n const defaultPagePath = key === 'signInUrl' ? '/sign-in' : '/sign-up';\n const base = baseUrlConfig || defaultPagePath;\n\n const redirectUrls = new RedirectUrls(this.#options, options).toSearchParams();\n const constructedUrl = buildURL(\n {\n base,\n hashSearchParams: [redirectUrls],\n },\n {\n stringify: true,\n skipOrigin: false,\n },\n );\n return this.constructUrlWithAuthRedirect(constructedUrl);\n };\n\n #constructAfterSignInUrl = (): string => {\n return this.constructUrlWithAuthRedirect(new RedirectUrls(this.#options).getAfterSignInUrl());\n };\n\n #constructAfterSignOutUrl = (): string => {\n if (!this.#options.afterSignOutUrl) {\n return '/';\n }\n return this.constructUrlWithAuthRedirect(this.#options.afterSignOutUrl);\n };\n\n public redirectToSignIn = async (options?: SignInRedirectOptions): Promise<unknown> => {\n if (inBrowser()) {\n return this.navigate(this.constructSignInUrl(options));\n }\n return;\n };\n\n public redirectToSignUp = async (options?: SignUpRedirectOptions): Promise<unknown> => {\n if (inBrowser()) {\n return this.navigate(this.constructSignUpUrl());\n }\n return;\n };\n\n public redirectAfterSignIn = async (): Promise<unknown> => {\n if (inBrowser()) {\n return this.navigate(this.#constructAfterSignInUrl());\n }\n return;\n };\n\n redirectAfterSignUp = (): void => {\n throw new Error('redirectAfterSignUp is not implemented yet');\n };\n\n public constructSignInUrl = (options?: SignInRedirectOptions): string => {\n return this.#buildUrl('signInUrl', {\n ...options,\n signInForceRedirectUrl: options?.signInForceRedirectUrl || window.location.href,\n });\n };\n\n public constructSignUpUrl = (options?: SignUpRedirectOptions): string => {\n return this.#buildUrl('signUpUrl', {\n ...options,\n signUpForceRedirectUrl: options?.signUpForceRedirectUrl || window.location.href,\n });\n };\n\n get #allowedRedirectProtocols() {\n let allowedProtocols = ALLOWED_PROTOCOLS;\n\n if (this.#options.allowedRedirectProtocols) {\n allowedProtocols = allowedProtocols.concat(this.#options.allowedRedirectProtocols);\n }\n\n return allowedProtocols;\n }\n\n __internal_setCountry = (country: string | null) => {\n if (!this.__internal_country) {\n this.__internal_country = country;\n }\n };\n\n #initOptions = (options: TernSecureAuthOptions): TernSecureAuthOptions => {\n return {\n ...options,\n };\n };\n\n #emit = (): void => {\n for (const listener of this.#listeners) {\n listener({\n user: this.user,\n session: this.signedInSession,\n });\n }\n };\n\n #setStatus(newStatus: TernSecureAuthStatus): void {\n if (this.#status !== newStatus) {\n this.#status = newStatus;\n this.#publicEventBus.emit(ternEvents.Status, this.#status);\n\n if (newStatus === 'ready') {\n this.#publicEventBus.emit(ternEvents.Status, 'ready');\n }\n }\n }\n\n #setCreatedActiveSession = (session: TernSecureUser | null) => {\n this.user = session;\n this._currentUser = session;\n };\n\n #setPersistence = () => {\n const persistenceType = this.#options.persistence;\n\n switch (persistenceType) {\n case 'browserCookie':\n return inMemoryPersistence;\n case 'session':\n return browserSessionPersistence;\n case 'local':\n return browserLocalPersistence;\n case 'none':\n default:\n return inMemoryPersistence;\n }\n };\n\n #emulatorHost = (): string | undefined => {\n if (typeof process === 'undefined') return undefined;\n return process.env.FIREBASE_AUTH_EMULATOR_HOST;\n };\n\n #configureEmulator = (): void => {\n const host = this.#emulatorHost();\n const isDev = this.#instanceType === 'development';\n const shouldUseEmulator = isDev && !!host;\n if (!shouldUseEmulator || !host) {\n return;\n }\n\n const emulatorUrl = host.startsWith('http') ? host : `http://${host}`;\n\n try {\n //(this.auth as unknown as any)._canInitEmulator = true;\n connectAuthEmulator(this.auth, emulatorUrl, { disableWarnings: false });\n console.warn(`[TernSecure] Firebase Auth Emulator connected at ${emulatorUrl}`);\n } catch (error) {\n console.error('[TernSecure] Error connecting to Firebase Auth Emulator:', error);\n }\n };\n}\n"],"mappings":";;;;;;;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AAA,EAEA,gBAAgB,MAA0B;AACxC,QAAI,OAAO,YAAY,YAAa,QAAO;AAC3C,WAAO,QAAQ,IAAI;AAAA,EACrB;AAAA,EAEA,qBAAqB,MAAY;AAC/B,UAAM,OAAO,KAAK,cAAc;AAChC,UAAM,QAAQ,KAAK,kBAAkB;AACrC,UAAM,oBAAoB,SAAS,CAAC,CAAC;AACrC,QAAI,CAAC,qBAAqB,CAAC,MAAM;AAC/B;AAAA,IACF;AAEA,UAAM,cAAc,KAAK,WAAW,MAAM,IAAI,OAAO,UAAU,IAAI;AAEnE,QAAI;AAEF,2CAAoB,KAAK,MAAM,aAAa,EAAE,iBAAiB,MAAM,CAAC;AACtE,cAAQ,KAAK,oDAAoD,WAAW,EAAE;AAAA,IAChF,SAAS,OAAO;AACd,cAAQ,MAAM,4DAA4D,KAAK;AAAA,IACjF;AAAA,EACF;AACF;","names":["import_utils"]}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var TernAuthServer_exports = {};
|
|
20
|
-
__export(TernAuthServer_exports, {
|
|
21
|
-
TernServerAuth: () => TernServerAuth
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(TernAuthServer_exports);
|
|
24
|
-
var import_app = require("firebase/app");
|
|
25
|
-
var import_auth = require("firebase/auth");
|
|
26
|
-
class TernServerAuth {
|
|
27
|
-
static instance = null;
|
|
28
|
-
auth;
|
|
29
|
-
#options = {};
|
|
30
|
-
constructor() {
|
|
31
|
-
}
|
|
32
|
-
static getInstance() {
|
|
33
|
-
if (!this.instance) {
|
|
34
|
-
this.instance = new TernServerAuth();
|
|
35
|
-
}
|
|
36
|
-
return this.instance;
|
|
37
|
-
}
|
|
38
|
-
static initialize(options) {
|
|
39
|
-
const instance = this.getInstance();
|
|
40
|
-
instance.#initialize(options);
|
|
41
|
-
return instance;
|
|
42
|
-
}
|
|
43
|
-
#initialize(options) {
|
|
44
|
-
this.#options = this.#initOptions(options);
|
|
45
|
-
}
|
|
46
|
-
static clearInstance() {
|
|
47
|
-
this.instance = null;
|
|
48
|
-
}
|
|
49
|
-
getAuthIdToken = async () => {
|
|
50
|
-
await this.auth.authStateReady();
|
|
51
|
-
if (!this.auth.currentUser) return;
|
|
52
|
-
return await (0, import_auth.getIdToken)(this.auth.currentUser);
|
|
53
|
-
};
|
|
54
|
-
getAuthenticatedAppFromHeaders = async (headers) => {
|
|
55
|
-
const authHeader = headers.get("Authorization");
|
|
56
|
-
const idToken = authHeader == null ? void 0 : authHeader.split("Bearer ")[1];
|
|
57
|
-
let appSettings = {};
|
|
58
|
-
appSettings = {
|
|
59
|
-
releaseOnDeref: headers
|
|
60
|
-
};
|
|
61
|
-
if (idToken && idToken.trim()) {
|
|
62
|
-
appSettings.authIdToken = idToken;
|
|
63
|
-
}
|
|
64
|
-
return this.getServerApp(appSettings);
|
|
65
|
-
};
|
|
66
|
-
getServerApp = async (appSettings) => {
|
|
67
|
-
const firebaseServerConfig = this.#options.firebaseServerConfig;
|
|
68
|
-
if (!firebaseServerConfig) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
"Firebase server configuration is required to initialize the server app"
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
const firebaseServerApp = (0, import_app.initializeServerApp)(
|
|
74
|
-
firebaseServerConfig,
|
|
75
|
-
appSettings || {}
|
|
76
|
-
);
|
|
77
|
-
this.auth = (0, import_auth.getAuth)(firebaseServerApp);
|
|
78
|
-
await this.auth.authStateReady();
|
|
79
|
-
return {
|
|
80
|
-
firebaseServerApp,
|
|
81
|
-
currentUser: this.auth.currentUser,
|
|
82
|
-
auth: this.auth
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
#initOptions = (options) => {
|
|
86
|
-
return {
|
|
87
|
-
...options
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
TernServerAuth
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=TernAuthServer.js.map
|