@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,72 +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 jwtClient_exports = {};
|
|
20
|
-
__export(jwtClient_exports, {
|
|
21
|
-
createClientFromJwt: () => createClientFromJwt,
|
|
22
|
-
updateClient: () => updateClient
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(jwtClient_exports);
|
|
25
|
-
var import_jwt = require("../utils/jwt");
|
|
26
|
-
const createClientFromJwt = (jwtToken) => {
|
|
27
|
-
if (!jwtToken) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const { decoded } = (0, import_jwt.decode)(jwtToken);
|
|
31
|
-
console.log("[TernAuth] Loaded user from JWT:", decoded);
|
|
32
|
-
return decoded;
|
|
33
|
-
};
|
|
34
|
-
const updateClient = (user, options) => {
|
|
35
|
-
try {
|
|
36
|
-
if (options.onUserUpdate) {
|
|
37
|
-
options.onUserUpdate(user);
|
|
38
|
-
}
|
|
39
|
-
if (user && options.onSessionUpdate) {
|
|
40
|
-
user.getIdTokenResult().then((tokenResult) => {
|
|
41
|
-
const session = {
|
|
42
|
-
status: "active",
|
|
43
|
-
token: tokenResult.token,
|
|
44
|
-
claims: tokenResult.claims,
|
|
45
|
-
issuedAtTime: tokenResult.issuedAtTime,
|
|
46
|
-
expirationTime: tokenResult.expirationTime,
|
|
47
|
-
authTime: tokenResult.authTime,
|
|
48
|
-
signInProvider: tokenResult.signInProvider || "unknown",
|
|
49
|
-
signInSecondFactor: tokenResult.signInSecondFactor
|
|
50
|
-
};
|
|
51
|
-
if (options.onSessionUpdate) {
|
|
52
|
-
options.onSessionUpdate(session);
|
|
53
|
-
}
|
|
54
|
-
}).catch((error) => {
|
|
55
|
-
console.error("[TernAuth] Error getting token result for session:", error);
|
|
56
|
-
if (options.onSessionUpdate) {
|
|
57
|
-
options.onSessionUpdate(null);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
} else if (options.onSessionUpdate) {
|
|
61
|
-
options.onSessionUpdate(null);
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error("[TernAuth] Error updating client:", error);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
-
0 && (module.exports = {
|
|
69
|
-
createClientFromJwt,
|
|
70
|
-
updateClient
|
|
71
|
-
});
|
|
72
|
-
//# sourceMappingURL=jwtClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/instance/jwtClient.ts"],"sourcesContent":["import type { DecodedIdToken, SignedInSession, TernSecureUser } from '@tern-secure/types';\n\nimport type { AuthCookieManager } from '../auth/AuthCookieManager';\nimport { decode } from '../utils/jwt';\n\n/**\n * Utility functions for loading user from JWT cookie and updating client state\n * This addresses the issue where user is undefined when client loads on page refresh\n */\n\nexport interface ClientUpdateOptions {\n authCookieManager: AuthCookieManager;\n onUserUpdate?: (user: TernSecureUser | null) => void;\n onSessionUpdate?: (session: SignedInSession | null) => void;\n}\n\n/**\n * Creates Firebase user from stored JWT token (ID token)\n * Since the token is already a Firebase ID token, we validate it and wait for auth state\n */\nconst createClientFromJwt = (jwtToken: string | null): DecodedIdToken | null => {\n if (!jwtToken) {\n return null;\n }\n\n const { decoded } = decode(jwtToken);\n\n console.log('[TernAuth] Loaded user from JWT:', decoded);\n\n return decoded;\n};\n\n/**\n * Updates client user state and triggers callbacks\n */\nconst updateClient = (\n user: TernSecureUser | null,\n options: Pick<ClientUpdateOptions, 'onUserUpdate' | 'onSessionUpdate'>,\n): void => {\n try {\n // Update user\n if (options.onUserUpdate) {\n options.onUserUpdate(user);\n }\n\n // Update session if user exists\n if (user && options.onSessionUpdate) {\n user\n .getIdTokenResult()\n .then(tokenResult => {\n const session: SignedInSession = {\n status: 'active',\n token: tokenResult.token,\n claims: tokenResult.claims,\n issuedAtTime: tokenResult.issuedAtTime,\n expirationTime: tokenResult.expirationTime,\n authTime: tokenResult.authTime,\n signInProvider: tokenResult.signInProvider || 'unknown',\n signInSecondFactor: tokenResult.signInSecondFactor,\n };\n if (options.onSessionUpdate) {\n options.onSessionUpdate(session);\n }\n })\n .catch(error => {\n console.error('[TernAuth] Error getting token result for session:', error);\n if (options.onSessionUpdate) {\n options.onSessionUpdate(null);\n }\n });\n } else if (options.onSessionUpdate) {\n options.onSessionUpdate(null);\n }\n } catch (error) {\n console.error('[TernAuth] Error updating client:', error);\n }\n};\n\nexport { createClientFromJwt, updateClient };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAuB;AAiBvB,MAAM,sBAAsB,CAAC,aAAmD;AAC9E,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,QAAQ,QAAI,mBAAO,QAAQ;AAEnC,UAAQ,IAAI,oCAAoC,OAAO;AAEvD,SAAO;AACT;AAKA,MAAM,eAAe,CACnB,MACA,YACS;AACT,MAAI;AAEF,QAAI,QAAQ,cAAc;AACxB,cAAQ,aAAa,IAAI;AAAA,IAC3B;AAGA,QAAI,QAAQ,QAAQ,iBAAiB;AACnC,WACG,iBAAiB,EACjB,KAAK,iBAAe;AACnB,cAAM,UAA2B;AAAA,UAC/B,QAAQ;AAAA,UACR,OAAO,YAAY;AAAA,UACnB,QAAQ,YAAY;AAAA,UACpB,cAAc,YAAY;AAAA,UAC1B,gBAAgB,YAAY;AAAA,UAC5B,UAAU,YAAY;AAAA,UACtB,gBAAgB,YAAY,kBAAkB;AAAA,UAC9C,oBAAoB,YAAY;AAAA,QAClC;AACA,YAAI,QAAQ,iBAAiB;AAC3B,kBAAQ,gBAAgB,OAAO;AAAA,QACjC;AAAA,MACF,CAAC,EACA,MAAM,WAAS;AACd,gBAAQ,MAAM,sDAAsD,KAAK;AACzE,YAAI,QAAQ,iBAAiB;AAC3B,kBAAQ,gBAAgB,IAAI;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACL,WAAW,QAAQ,iBAAiB;AAClC,cAAQ,gBAAgB,IAAI;AAAA,IAC9B;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,qCAAqC,KAAK;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -1,137 +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 Base_exports = {};
|
|
20
|
-
__export(Base_exports, {
|
|
21
|
-
TernSecureBase: () => TernSecureBase
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(Base_exports);
|
|
24
|
-
var import_browser = require("@tern-secure/shared/browser");
|
|
25
|
-
var import_Error = require("./Error");
|
|
26
|
-
class TernSecureBase {
|
|
27
|
-
static ternsecure;
|
|
28
|
-
static get apiClient() {
|
|
29
|
-
return TernSecureBase.ternsecure.getApiClient();
|
|
30
|
-
}
|
|
31
|
-
static get authCookieManager() {
|
|
32
|
-
return this.ternsecure.authCookieManager();
|
|
33
|
-
}
|
|
34
|
-
get authCookieManager() {
|
|
35
|
-
return TernSecureBase.authCookieManager;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Core method to fetch data from API endpoints using coreApiClient
|
|
39
|
-
* This method handles the complete request lifecycle including error handling
|
|
40
|
-
*/
|
|
41
|
-
static async fetchFromCoreApi(requestInit) {
|
|
42
|
-
var _a;
|
|
43
|
-
let apiResponse;
|
|
44
|
-
try {
|
|
45
|
-
apiResponse = await TernSecureBase.apiClient.request(requestInit, { timeoutMs: 1e4 });
|
|
46
|
-
} catch (error) {
|
|
47
|
-
if (this.shouldRethrowofflineNetworkError()) {
|
|
48
|
-
throw new import_Error.TernSecureRuntimeError((error == null ? void 0 : error.message) || String(error), {
|
|
49
|
-
code: "OFFLINE_NETWORK_ERROR"
|
|
50
|
-
});
|
|
51
|
-
} else if (!(0, import_browser.isValidBrowserOnline)()) {
|
|
52
|
-
console.warn(error);
|
|
53
|
-
return null;
|
|
54
|
-
} else {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const { payload, status, statusText, headers } = apiResponse;
|
|
59
|
-
if (headers) {
|
|
60
|
-
const country = headers.get("x-country");
|
|
61
|
-
this.ternsecure.__internal_setCountry(country ? country.toLowerCase() : null);
|
|
62
|
-
}
|
|
63
|
-
if (status >= 200 && status <= 299) {
|
|
64
|
-
return payload;
|
|
65
|
-
}
|
|
66
|
-
if (status >= 400) {
|
|
67
|
-
const errors = payload == null ? void 0 : payload.errors;
|
|
68
|
-
const message = (_a = errors == null ? void 0 : errors[0]) == null ? void 0 : _a.message;
|
|
69
|
-
const apiResponseOptions = {
|
|
70
|
-
data: errors,
|
|
71
|
-
status
|
|
72
|
-
};
|
|
73
|
-
if (status === 429 && headers) {
|
|
74
|
-
const retryAfter = headers.get("retry-After");
|
|
75
|
-
if (retryAfter) {
|
|
76
|
-
const value = parseInt(retryAfter, 10);
|
|
77
|
-
if (!isNaN(value)) {
|
|
78
|
-
apiResponseOptions.retryAfter = value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
throw new import_Error.TernSecureAPIResponseError(message || statusText, apiResponseOptions);
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Convenience method for making POST requests
|
|
88
|
-
*/
|
|
89
|
-
static async basePost(params) {
|
|
90
|
-
return this.fetchFromCoreApi({ ...params, method: "POST" });
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Instance method to fetch data from API endpoints
|
|
94
|
-
*/
|
|
95
|
-
async fetchFromCoreApi(requestInit) {
|
|
96
|
-
return TernSecureBase.fetchFromCoreApi(requestInit);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Instance method for making POST requests
|
|
100
|
-
*/
|
|
101
|
-
async basePost(params) {
|
|
102
|
-
return TernSecureBase.basePost(params);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Instance method to make GET requests
|
|
106
|
-
* This is a convenience method that sets the HTTP method to GET
|
|
107
|
-
*/
|
|
108
|
-
async baseGet(params) {
|
|
109
|
-
return this.fetchFromCoreApi({ ...params, method: "GET" });
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Protected instance method for making POST requests with specific path and body
|
|
113
|
-
* This is designed to be used by child classes like SignIn
|
|
114
|
-
*/
|
|
115
|
-
async _post(params) {
|
|
116
|
-
return this.basePost({
|
|
117
|
-
path: params.path,
|
|
118
|
-
body: params.body
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
static async makeApiRequest(requestInit) {
|
|
122
|
-
return this.fetchFromCoreApi(requestInit);
|
|
123
|
-
}
|
|
124
|
-
async makeApiRequest(requestInit) {
|
|
125
|
-
return this.fetchFromCoreApi(requestInit);
|
|
126
|
-
}
|
|
127
|
-
static shouldRethrowofflineNetworkError() {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
const experimental = (_b = (_a = TernSecureBase.ternsecure) == null ? void 0 : _a._internal_getOption) == null ? void 0 : _b.call(_a, "experimental");
|
|
130
|
-
return (experimental == null ? void 0 : experimental.rethrowOfflineNetworkErrors) || false;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
-
0 && (module.exports = {
|
|
135
|
-
TernSecureBase
|
|
136
|
-
});
|
|
137
|
-
//# sourceMappingURL=Base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resources/Base.ts"],"sourcesContent":["import { isValidBrowserOnline } from '@tern-secure/shared/browser';\nimport type { TernSecureApiErrorJSON } from '@tern-secure/types';\n\nimport type { ApiRequestInit, ApiResponse, ApiResponseJSON } from '../instance/coreApiClient';\n//import { coreApiClient} from '../instance/coreApiClient';\nimport { TernSecureAPIResponseError, TernSecureRuntimeError } from './Error';\nimport type { AuthCookieManager, TernSecureAuth } from './internal';\n\nexport type HTTPMethod =\n | 'CONNECT'\n | 'DELETE'\n | 'GET'\n | 'HEAD'\n | 'OPTIONS'\n | 'PATCH'\n | 'POST'\n | 'PUT'\n | 'TRACE';\n\nexport type PostMutateParams = {\n action?: string | undefined;\n body?: any;\n method?: HTTPMethod | undefined;\n path?: string;\n search?: ConstructorParameters<typeof URLSearchParams>[0];\n};\n\nexport abstract class TernSecureBase {\n static ternsecure: TernSecureAuth;\n\n static get apiClient() {\n return TernSecureBase.ternsecure.getApiClient();\n }\n\n static get authCookieManager(): AuthCookieManager | undefined {\n return this.ternsecure.authCookieManager();\n }\n protected get authCookieManager(): AuthCookieManager | undefined {\n return TernSecureBase.authCookieManager;\n }\n\n /**\n * Core method to fetch data from API endpoints using coreApiClient\n * This method handles the complete request lifecycle including error handling\n */\n protected static async fetchFromCoreApi<J>(\n requestInit: ApiRequestInit,\n ): Promise<ApiResponseJSON<J> | null> {\n let apiResponse: ApiResponse<J>;\n try {\n apiResponse = await TernSecureBase.apiClient.request<J>(requestInit, { timeoutMs: 10000 });\n } catch (error) {\n if (this.shouldRethrowofflineNetworkError()) {\n throw new TernSecureRuntimeError((error as Error)?.message || String(error), {\n code: 'OFFLINE_NETWORK_ERROR',\n });\n } else if (!isValidBrowserOnline()) {\n console.warn(error);\n return null;\n } else {\n throw error;\n }\n }\n\n const { payload, status, statusText, headers } = apiResponse;\n\n if (headers) {\n const country = headers.get('x-country');\n this.ternsecure.__internal_setCountry(country ? country.toLowerCase() : null);\n }\n\n if (status >= 200 && status <= 299) {\n return payload;\n }\n\n if (status >= 400) {\n const errors = payload?.errors as TernSecureApiErrorJSON[];\n const message = errors?.[0]?.message;\n\n const apiResponseOptions: ConstructorParameters<typeof TernSecureAPIResponseError>[1] = {\n data: errors,\n status,\n };\n if (status === 429 && headers) {\n const retryAfter = headers.get('retry-After');\n if (retryAfter) {\n const value = parseInt(retryAfter, 10);\n if (!isNaN(value)) {\n apiResponseOptions.retryAfter = value;\n }\n }\n }\n\n throw new TernSecureAPIResponseError(message || statusText, apiResponseOptions);\n }\n\n return null;\n }\n\n /**\n * Convenience method for making POST requests\n */\n static async basePost(params: PostMutateParams): Promise<ApiResponseJSON<any> | null> {\n return this.fetchFromCoreApi({ ...params, method: 'POST' });\n }\n\n /**\n * Instance method to fetch data from API endpoints\n */\n protected async fetchFromCoreApi(\n requestInit: ApiRequestInit,\n ): Promise<ApiResponseJSON<any> | null> {\n return TernSecureBase.fetchFromCoreApi(requestInit);\n }\n\n /**\n * Instance method for making POST requests\n */\n protected async basePost(params: PostMutateParams): Promise<ApiResponseJSON<any> | null> {\n return TernSecureBase.basePost(params);\n }\n\n /**\n * Instance method to make GET requests\n * This is a convenience method that sets the HTTP method to GET\n */\n protected async baseGet(params: Omit<PostMutateParams, 'method'>): Promise<ApiResponseJSON<any> | null> {\n return this.fetchFromCoreApi({ ...params, method: 'GET' });\n }\n\n /**\n * Protected instance method for making POST requests with specific path and body\n * This is designed to be used by child classes like SignIn\n */\n protected async _post(params: PostMutateParams): Promise<ApiResponseJSON<any> | null> {\n return this.basePost({\n path: params.path,\n body: params.body,\n });\n }\n\n static async makeApiRequest(requestInit: ApiRequestInit): Promise<ApiResponseJSON<any> | null> {\n return this.fetchFromCoreApi(requestInit);\n }\n\n protected async makeApiRequest(\n requestInit: ApiRequestInit,\n ): Promise<ApiResponseJSON<any> | null> {\n return this.fetchFromCoreApi(requestInit);\n }\n\n private static shouldRethrowofflineNetworkError(): boolean {\n const experimental = TernSecureBase.ternsecure?._internal_getOption?.('experimental');\n return experimental?.rethrowOfflineNetworkErrors || false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAqC;AAKrC,mBAAmE;AAsB5D,MAAe,eAAe;AAAA,EACnC,OAAO;AAAA,EAEP,WAAW,YAAY;AACrB,WAAO,eAAe,WAAW,aAAa;AAAA,EAChD;AAAA,EAEA,WAAW,oBAAmD;AAC5D,WAAO,KAAK,WAAW,kBAAkB;AAAA,EAC3C;AAAA,EACA,IAAc,oBAAmD;AAC/D,WAAO,eAAe;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAuB,iBACrB,aACoC;AA/CxC;AAgDI,QAAI;AACJ,QAAI;AACF,oBAAc,MAAM,eAAe,UAAU,QAAW,aAAa,EAAE,WAAW,IAAM,CAAC;AAAA,IAC3F,SAAS,OAAO;AACd,UAAI,KAAK,iCAAiC,GAAG;AAC3C,cAAM,IAAI,qCAAwB,+BAAiB,YAAW,OAAO,KAAK,GAAG;AAAA,UAC3E,MAAM;AAAA,QACR,CAAC;AAAA,MACH,WAAW,KAAC,qCAAqB,GAAG;AAClC,gBAAQ,KAAK,KAAK;AAClB,eAAO;AAAA,MACT,OAAO;AACL,cAAM;AAAA,MACR;AAAA,IACF;AAEA,UAAM,EAAE,SAAS,QAAQ,YAAY,QAAQ,IAAI;AAEjD,QAAI,SAAS;AACX,YAAM,UAAU,QAAQ,IAAI,WAAW;AACvC,WAAK,WAAW,sBAAsB,UAAU,QAAQ,YAAY,IAAI,IAAI;AAAA,IAC9E;AAEA,QAAI,UAAU,OAAO,UAAU,KAAK;AAClC,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,KAAK;AACjB,YAAM,SAAS,mCAAS;AACxB,YAAM,WAAU,sCAAS,OAAT,mBAAa;AAE7B,YAAM,qBAAkF;AAAA,QACtF,MAAM;AAAA,QACN;AAAA,MACF;AACA,UAAI,WAAW,OAAO,SAAS;AAC7B,cAAM,aAAa,QAAQ,IAAI,aAAa;AAC5C,YAAI,YAAY;AACd,gBAAM,QAAQ,SAAS,YAAY,EAAE;AACrC,cAAI,CAAC,MAAM,KAAK,GAAG;AACjB,+BAAmB,aAAa;AAAA,UAClC;AAAA,QACF;AAAA,MACF;AAEA,YAAM,IAAI,wCAA2B,WAAW,YAAY,kBAAkB;AAAA,IAChF;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,SAAS,QAAgE;AACpF,WAAO,KAAK,iBAAiB,EAAE,GAAG,QAAQ,QAAQ,OAAO,CAAC;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,iBACd,aACsC;AACtC,WAAO,eAAe,iBAAiB,WAAW;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,SAAS,QAAgE;AACvF,WAAO,eAAe,SAAS,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,QAAQ,QAAgF;AACtG,WAAO,KAAK,iBAAiB,EAAE,GAAG,QAAQ,QAAQ,MAAM,CAAC;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,MAAM,QAAgE;AACpF,WAAO,KAAK,SAAS;AAAA,MACnB,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,IACf,CAAC;AAAA,EACH;AAAA,EAEA,aAAa,eAAe,aAAmE;AAC7F,WAAO,KAAK,iBAAiB,WAAW;AAAA,EAC1C;AAAA,EAEA,MAAgB,eACd,aACsC;AACtC,WAAO,KAAK,iBAAiB,WAAW;AAAA,EAC1C;AAAA,EAEA,OAAe,mCAA4C;AAvJ7D;AAwJI,UAAM,gBAAe,0BAAe,eAAf,mBAA2B,wBAA3B,4BAAiD;AACtE,YAAO,6CAAc,gCAA+B;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -1,31 +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 Error_exports = {};
|
|
20
|
-
__export(Error_exports, {
|
|
21
|
-
TernSecureAPIResponseError: () => import_errors_api.TernSecureAPIResponseError,
|
|
22
|
-
TernSecureRuntimeError: () => import_errors_api.TernSecureRuntimeError
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(Error_exports);
|
|
25
|
-
var import_errors_api = require("@tern-secure/shared/errors-api");
|
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
28
|
-
TernSecureAPIResponseError,
|
|
29
|
-
TernSecureRuntimeError
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=Error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resources/Error.ts"],"sourcesContent":["export {\n TernSecureAPIResponseError,\n TernSecureRuntimeError,\n} from \"@tern-secure/shared/errors-api\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAGO;","names":[]}
|
|
@@ -1,105 +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 Session_exports = {};
|
|
20
|
-
__export(Session_exports, {
|
|
21
|
-
Session: () => Session
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(Session_exports);
|
|
24
|
-
var import_events = require("../instance/events");
|
|
25
|
-
var import_Base = require("./Base");
|
|
26
|
-
class Session extends import_Base.TernSecureBase {
|
|
27
|
-
pathRoot = "/sessions/createsession";
|
|
28
|
-
status;
|
|
29
|
-
token;
|
|
30
|
-
claims;
|
|
31
|
-
authTime;
|
|
32
|
-
expirationTime;
|
|
33
|
-
issuedAtTime;
|
|
34
|
-
signInProvider;
|
|
35
|
-
signInSecondFactor;
|
|
36
|
-
user;
|
|
37
|
-
constructor(sessionData) {
|
|
38
|
-
super();
|
|
39
|
-
this.initializeFromSessionData(sessionData);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Initialize session from existing session data
|
|
43
|
-
*/
|
|
44
|
-
initializeFromSessionData(sessionData) {
|
|
45
|
-
this.status = sessionData.status || "pending";
|
|
46
|
-
this.token = sessionData.token || "";
|
|
47
|
-
this.claims = sessionData.claims || {};
|
|
48
|
-
this.authTime = sessionData.authTime || "";
|
|
49
|
-
this.expirationTime = sessionData.expirationTime || "";
|
|
50
|
-
this.issuedAtTime = sessionData.issuedAtTime || "";
|
|
51
|
-
this.signInProvider = sessionData.signInProvider || null;
|
|
52
|
-
this.signInSecondFactor = sessionData.signInSecondFactor || null;
|
|
53
|
-
this.user = sessionData.user;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Create custom token from current session for server-side sync
|
|
57
|
-
* This calls the backend API to create a custom token from the current ID token
|
|
58
|
-
*/
|
|
59
|
-
createSession = (idToken, csrfToken) => {
|
|
60
|
-
return this._post({
|
|
61
|
-
path: this.pathRoot,
|
|
62
|
-
body: {
|
|
63
|
-
idToken,
|
|
64
|
-
csrfToken
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* FIXED: Now properly returns the custom token string instead of the full API response
|
|
70
|
-
* This method correctly extracts the token from the API response structure
|
|
71
|
-
*/
|
|
72
|
-
getIdAndRefreshToken = async (idToken, csrfToken) => {
|
|
73
|
-
await this.createSession(idToken, csrfToken);
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* NEW: create method that calls API to create session
|
|
77
|
-
* API handles everything, no return value needed
|
|
78
|
-
* This method works with the existing sessionData passed to constructor
|
|
79
|
-
*/
|
|
80
|
-
create = async (csrfToken) => {
|
|
81
|
-
await this.createSession(this.token, csrfToken);
|
|
82
|
-
import_events.eventBus.emit(import_events.events.SessionChanged, null);
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Convert session to plain object for serialization
|
|
86
|
-
*/
|
|
87
|
-
toJSON() {
|
|
88
|
-
return {
|
|
89
|
-
status: this.status,
|
|
90
|
-
token: this.token,
|
|
91
|
-
claims: this.claims,
|
|
92
|
-
authTime: this.authTime,
|
|
93
|
-
expirationTime: this.expirationTime,
|
|
94
|
-
issuedAtTime: this.issuedAtTime,
|
|
95
|
-
signInProvider: this.signInProvider,
|
|
96
|
-
signInSecondFactor: this.signInSecondFactor,
|
|
97
|
-
user: this.user
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
-
0 && (module.exports = {
|
|
103
|
-
Session
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=Session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resources/Session.ts"],"sourcesContent":["import type {\n IdTokenResult,\n SessionJson,\n SessionResource,\n SessionStatus,\n TernSecureUser,\n} from '@tern-secure/types';\n\nimport { eventBus, events } from '../instance/events';\nimport { TernSecureBase } from './Base';\n\n/**\n * Enhanced Session class that handles custom token authentication for client-server sync.\n *\n * Key Features:\n * - Manages custom tokens for server-side verification\n * - Uses TernSecureUser object directly (no Firebase Auth instance needed)\n * - Provides seamless client-server session synchronization\n * - Works with in-memory persistence by using custom tokens to restore auth state\n */\nexport class Session extends TernSecureBase implements SessionResource {\n pathRoot = '/sessions/createsession';\n\n status!: SessionStatus;\n token!: string;\n claims!: IdTokenResult['claims'];\n authTime!: string;\n expirationTime!: string;\n issuedAtTime!: string;\n signInProvider!: string | null;\n signInSecondFactor!: string | null;\n user?: TernSecureUser;\n\n constructor(sessionData: Partial<SessionResource>) {\n super();\n this.initializeFromSessionData(sessionData);\n }\n\n /**\n * Initialize session from existing session data\n */\n private initializeFromSessionData(sessionData: Partial<SessionResource>): void {\n this.status = sessionData.status || 'pending';\n this.token = sessionData.token || '';\n this.claims = sessionData.claims || {};\n this.authTime = sessionData.authTime || '';\n this.expirationTime = sessionData.expirationTime || '';\n this.issuedAtTime = sessionData.issuedAtTime || '';\n this.signInProvider = sessionData.signInProvider || null;\n this.signInSecondFactor = sessionData.signInSecondFactor || null;\n this.user = sessionData.user;\n }\n\n /**\n * Create custom token from current session for server-side sync\n * This calls the backend API to create a custom token from the current ID token\n */\n private createSession = (idToken: string, csrfToken: string) => {\n return this._post({\n path: this.pathRoot,\n body: {\n idToken,\n csrfToken,\n },\n });\n };\n\n\n /**\n * FIXED: Now properly returns the custom token string instead of the full API response\n * This method correctly extracts the token from the API response structure\n */\n getIdAndRefreshToken = async (idToken: string, csrfToken: string): Promise<void> => {\n await this.createSession(idToken, csrfToken);\n };\n\n /**\n * NEW: create method that calls API to create session\n * API handles everything, no return value needed\n * This method works with the existing sessionData passed to constructor\n */\n create = async (csrfToken: string): Promise<void> => {\n await this.createSession(this.token, csrfToken);\n eventBus.emit(events.SessionChanged, null);\n };\n\n /**\n * Convert session to plain object for serialization\n */\n toJSON(): SessionJson {\n return {\n status: this.status,\n token: this.token,\n claims: this.claims,\n authTime: this.authTime,\n expirationTime: this.expirationTime,\n issuedAtTime: this.issuedAtTime,\n signInProvider: this.signInProvider,\n signInSecondFactor: this.signInSecondFactor,\n user: this.user,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,oBAAiC;AACjC,kBAA+B;AAWxB,MAAM,gBAAgB,2BAA0C;AAAA,EACrE,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,aAAuC;AACjD,UAAM;AACN,SAAK,0BAA0B,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKQ,0BAA0B,aAA6C;AAC7E,SAAK,SAAS,YAAY,UAAU;AACpC,SAAK,QAAQ,YAAY,SAAS;AAClC,SAAK,SAAS,YAAY,UAAU,CAAC;AACrC,SAAK,WAAW,YAAY,YAAY;AACxC,SAAK,iBAAiB,YAAY,kBAAkB;AACpD,SAAK,eAAe,YAAY,gBAAgB;AAChD,SAAK,iBAAiB,YAAY,kBAAkB;AACpD,SAAK,qBAAqB,YAAY,sBAAsB;AAC5D,SAAK,OAAO,YAAY;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,gBAAgB,CAAC,SAAiB,cAAsB;AAC9D,WAAO,KAAK,MAAM;AAAA,MAChB,MAAM,KAAK;AAAA,MACX,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,uBAAuB,OAAO,SAAiB,cAAqC;AAClF,UAAM,KAAK,cAAc,SAAS,SAAS;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,OAAO,cAAqC;AACnD,UAAM,KAAK,cAAc,KAAK,OAAO,SAAS;AAC9C,2BAAS,KAAK,qBAAO,gBAAgB,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKA,SAAsB;AACpB,WAAO;AAAA,MACL,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,QAAQ,KAAK;AAAA,MACb,UAAU,KAAK;AAAA,MACf,gBAAgB,KAAK;AAAA,MACrB,cAAc,KAAK;AAAA,MACnB,gBAAgB,KAAK;AAAA,MACrB,oBAAoB,KAAK;AAAA,MACzB,MAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,256 +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 SignIn_exports = {};
|
|
20
|
-
__export(SignIn_exports, {
|
|
21
|
-
SignIn: () => SignIn
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(SignIn_exports);
|
|
24
|
-
var import_errors = require("@tern-secure/shared/errors");
|
|
25
|
-
var import_auth = require("firebase/auth");
|
|
26
|
-
var import_Base = require("./Base");
|
|
27
|
-
class SignIn extends import_Base.TernSecureBase {
|
|
28
|
-
pathRoot = "/sessions/createsession";
|
|
29
|
-
status = null;
|
|
30
|
-
auth;
|
|
31
|
-
csrfToken;
|
|
32
|
-
_currentUser = null;
|
|
33
|
-
constructor(auth, csrfToken) {
|
|
34
|
-
super();
|
|
35
|
-
this.auth = auth;
|
|
36
|
-
this.csrfToken = csrfToken;
|
|
37
|
-
}
|
|
38
|
-
signInWithCredential = async (credential) => {
|
|
39
|
-
const idToken = await credential.user.getIdToken();
|
|
40
|
-
const params = {
|
|
41
|
-
idToken,
|
|
42
|
-
csrfToken: this.csrfToken
|
|
43
|
-
};
|
|
44
|
-
return this._post({
|
|
45
|
-
path: this.pathRoot,
|
|
46
|
-
body: params
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
withEmailAndPassword = async (params) => {
|
|
50
|
-
try {
|
|
51
|
-
const { email, password } = params;
|
|
52
|
-
const { user, providerId, operationType } = await (0, import_auth.signInWithEmailAndPassword)(
|
|
53
|
-
this.auth,
|
|
54
|
-
email,
|
|
55
|
-
password
|
|
56
|
-
);
|
|
57
|
-
return {
|
|
58
|
-
status: "success",
|
|
59
|
-
user,
|
|
60
|
-
providerId,
|
|
61
|
-
operationType,
|
|
62
|
-
message: "Authentication successful",
|
|
63
|
-
error: !user.emailVerified ? "REQUIRES_VERIFICATION" : "AUTHENTICATED"
|
|
64
|
-
};
|
|
65
|
-
} catch (error) {
|
|
66
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
67
|
-
return {
|
|
68
|
-
status: "error",
|
|
69
|
-
message: authError.message,
|
|
70
|
-
error: authError.code
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
withCredential = async (params) => {
|
|
75
|
-
try {
|
|
76
|
-
const { email, password } = params;
|
|
77
|
-
const userCredential = await (0, import_auth.signInWithEmailAndPassword)(this.auth, email, password);
|
|
78
|
-
await this.signInWithCredential(userCredential);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
81
|
-
console.error(authError);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
withSocialProvider = async (provider, options = {}) => {
|
|
85
|
-
try {
|
|
86
|
-
const { mode = "popup" } = options;
|
|
87
|
-
if (mode === "redirect") {
|
|
88
|
-
const redirectResult = await this.authRedirectResult();
|
|
89
|
-
if (redirectResult) {
|
|
90
|
-
return redirectResult;
|
|
91
|
-
}
|
|
92
|
-
return await this._signInWithRedirect(provider, options);
|
|
93
|
-
} else {
|
|
94
|
-
return await this._signInWithPopUp(provider, options);
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
return {
|
|
98
|
-
status: "error",
|
|
99
|
-
message: error.message || `Sign in with ${provider} failed`,
|
|
100
|
-
error
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
completeMfaSignIn = async (_mfaToken, _mfaContext) => {
|
|
105
|
-
throw new Error("Method not implemented.");
|
|
106
|
-
};
|
|
107
|
-
sendPasswordResetEmail = async (email) => {
|
|
108
|
-
console.log(`Sending password reset email to ${email}`);
|
|
109
|
-
};
|
|
110
|
-
resendEmailVerification = async () => {
|
|
111
|
-
const user = this._currentUser;
|
|
112
|
-
if (!user) {
|
|
113
|
-
throw new Error("No user is currently signed in");
|
|
114
|
-
}
|
|
115
|
-
await user.reload();
|
|
116
|
-
if (user.emailVerified) {
|
|
117
|
-
return {
|
|
118
|
-
isVerified: true
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const actionCodeSettings = {
|
|
122
|
-
url: "/sign-in",
|
|
123
|
-
// TODO: Make this configurable
|
|
124
|
-
handleCodeInApp: true
|
|
125
|
-
};
|
|
126
|
-
await (0, import_auth.sendEmailVerification)(user, actionCodeSettings);
|
|
127
|
-
return {
|
|
128
|
-
isVerified: false
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
getProviderConfig(providerName) {
|
|
132
|
-
switch (providerName.toLowerCase()) {
|
|
133
|
-
case "google": {
|
|
134
|
-
const googleProvider = new import_auth.GoogleAuthProvider();
|
|
135
|
-
return { provider: googleProvider };
|
|
136
|
-
}
|
|
137
|
-
case "apple": {
|
|
138
|
-
const appleProvider = new import_auth.OAuthProvider("apple.com");
|
|
139
|
-
return { provider: appleProvider };
|
|
140
|
-
}
|
|
141
|
-
case "microsoft": {
|
|
142
|
-
const microsoftProvider = new import_auth.OAuthProvider("microsoft.com");
|
|
143
|
-
return { provider: microsoftProvider };
|
|
144
|
-
}
|
|
145
|
-
case "github": {
|
|
146
|
-
const githubProvider = new import_auth.OAuthProvider("github.com");
|
|
147
|
-
return { provider: githubProvider };
|
|
148
|
-
}
|
|
149
|
-
case "twitter": {
|
|
150
|
-
const twitterProvider = new import_auth.OAuthProvider("twitter.com");
|
|
151
|
-
return { provider: twitterProvider };
|
|
152
|
-
}
|
|
153
|
-
case "facebook": {
|
|
154
|
-
const facebookProvider = new import_auth.OAuthProvider("facebook.com");
|
|
155
|
-
return { provider: facebookProvider };
|
|
156
|
-
}
|
|
157
|
-
default:
|
|
158
|
-
throw new Error(`Unsupported provider: ${providerName}`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async authRedirectResult() {
|
|
162
|
-
try {
|
|
163
|
-
const result = await (0, import_auth.getRedirectResult)(this.auth);
|
|
164
|
-
if (result) {
|
|
165
|
-
const { user, providerId, operationType } = result;
|
|
166
|
-
return {
|
|
167
|
-
status: "success",
|
|
168
|
-
user,
|
|
169
|
-
providerId,
|
|
170
|
-
operationType
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return null;
|
|
174
|
-
} catch (error) {
|
|
175
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
176
|
-
return {
|
|
177
|
-
status: "error",
|
|
178
|
-
message: authError.message,
|
|
179
|
-
error: authError.code
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Sets custom OAuth parameters on the provider if provided by consumer
|
|
185
|
-
* @param provider - Firebase auth provider instance
|
|
186
|
-
* @param customParameters - Consumer-provided OAuth parameters
|
|
187
|
-
*/
|
|
188
|
-
setProviderCustomParameters(provider, customParameters) {
|
|
189
|
-
if (!customParameters || Object.keys(customParameters).length === 0) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
provider.setCustomParameters(customParameters);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Adds OAuth scopes to the provider if provided by consumer
|
|
196
|
-
* Handles provider-specific scope setting logic
|
|
197
|
-
* @param provider - Firebase auth provider instance
|
|
198
|
-
* @param scopes - Array of OAuth scopes to request
|
|
199
|
-
*/
|
|
200
|
-
setProviderScopes(provider, scopes) {
|
|
201
|
-
if (!scopes || scopes.length === 0) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (provider instanceof import_auth.GoogleAuthProvider) {
|
|
205
|
-
scopes.forEach((scope) => {
|
|
206
|
-
provider.addScope(scope);
|
|
207
|
-
});
|
|
208
|
-
} else if (provider instanceof import_auth.OAuthProvider) {
|
|
209
|
-
provider.addScope(scopes.join(" "));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Configures OAuth provider with consumer-provided options
|
|
214
|
-
* @param provider - Firebase auth provider instance
|
|
215
|
-
* @param options - Consumer options containing custom parameters and scopes
|
|
216
|
-
*/
|
|
217
|
-
configureProvider(provider, options) {
|
|
218
|
-
this.setProviderCustomParameters(provider, options.customParameters);
|
|
219
|
-
this.setProviderScopes(provider, options.scopes);
|
|
220
|
-
}
|
|
221
|
-
executeAuthMethod = async (authMethod, providerName, options = {}) => {
|
|
222
|
-
try {
|
|
223
|
-
const config = this.getProviderConfig(providerName);
|
|
224
|
-
this.configureProvider(config.provider, options);
|
|
225
|
-
const { user, providerId, operationType } = await authMethod(this.auth, config.provider);
|
|
226
|
-
return {
|
|
227
|
-
status: "success",
|
|
228
|
-
message: "Authentication successful",
|
|
229
|
-
user,
|
|
230
|
-
providerId,
|
|
231
|
-
operationType
|
|
232
|
-
};
|
|
233
|
-
} catch (error) {
|
|
234
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
235
|
-
return {
|
|
236
|
-
status: "error",
|
|
237
|
-
message: authError.message,
|
|
238
|
-
error: authError.code
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
async _signInWithRedirect(providerName, options = {}) {
|
|
243
|
-
return this.executeAuthMethod(import_auth.signInWithRedirect, providerName, options);
|
|
244
|
-
}
|
|
245
|
-
async _signInWithPopUp(providerName, options = {}) {
|
|
246
|
-
return this.executeAuthMethod(import_auth.signInWithPopup, providerName, options);
|
|
247
|
-
}
|
|
248
|
-
async checkRedirectResult() {
|
|
249
|
-
return this.authRedirectResult();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
253
|
-
0 && (module.exports = {
|
|
254
|
-
SignIn
|
|
255
|
-
});
|
|
256
|
-
//# sourceMappingURL=SignIn.js.map
|