@tern-secure/shared 1.3.0-canary.v20251008165428 → 1.3.0-canary.v20251019190011
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.
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { TernSecureResources,
|
|
1
|
+
import { TernSecureResources, TernSecureStateExtended, TernSecureUser, DecodedIdToken, SignedInSession } from '@tern-secure/types';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
token: any;
|
|
6
|
-
email: string | null;
|
|
7
|
-
user: TernSecureUser;
|
|
8
|
-
} | {
|
|
3
|
+
type NormalizedClaims = DecodedIdToken;
|
|
4
|
+
type DerivedAuthState = {
|
|
9
5
|
userId: string | null | undefined;
|
|
10
|
-
token: Promise<string> | null;
|
|
11
|
-
email: string | null;
|
|
12
6
|
user: TernSecureUser | null | undefined;
|
|
7
|
+
sessionClaims: NormalizedClaims | null | undefined;
|
|
8
|
+
token?: string | null;
|
|
9
|
+
session?: SignedInSession | null;
|
|
13
10
|
};
|
|
11
|
+
declare const deriveAuthState: (ternSecureIsReady: boolean, authState: TernSecureResources, initialState: TernSecureStateExtended | undefined) => DerivedAuthState;
|
|
14
12
|
|
|
15
13
|
export { deriveAuthState };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { TernSecureResources,
|
|
1
|
+
import { TernSecureResources, TernSecureStateExtended, TernSecureUser, DecodedIdToken, SignedInSession } from '@tern-secure/types';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
token: any;
|
|
6
|
-
email: string | null;
|
|
7
|
-
user: TernSecureUser;
|
|
8
|
-
} | {
|
|
3
|
+
type NormalizedClaims = DecodedIdToken;
|
|
4
|
+
type DerivedAuthState = {
|
|
9
5
|
userId: string | null | undefined;
|
|
10
|
-
token: Promise<string> | null;
|
|
11
|
-
email: string | null;
|
|
12
6
|
user: TernSecureUser | null | undefined;
|
|
7
|
+
sessionClaims: NormalizedClaims | null | undefined;
|
|
8
|
+
token?: string | null;
|
|
9
|
+
session?: SignedInSession | null;
|
|
13
10
|
};
|
|
11
|
+
declare const deriveAuthState: (ternSecureIsReady: boolean, authState: TernSecureResources, initialState: TernSecureStateExtended | undefined) => DerivedAuthState;
|
|
14
12
|
|
|
15
13
|
export { deriveAuthState };
|
package/dist/derivedAuthState.js
CHANGED
|
@@ -23,33 +23,51 @@ __export(derivedAuthState_exports, {
|
|
|
23
23
|
deriveAuthState: () => deriveAuthState
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(derivedAuthState_exports);
|
|
26
|
-
var deriveAuthState = (authState, initialState) => {
|
|
27
|
-
if (initialState) {
|
|
28
|
-
return
|
|
26
|
+
var deriveAuthState = (ternSecureIsReady, authState, initialState) => {
|
|
27
|
+
if (!authState.user && initialState) {
|
|
28
|
+
return fromSsrInitialState(initialState);
|
|
29
29
|
}
|
|
30
30
|
return fromClientSideState(authState);
|
|
31
31
|
};
|
|
32
|
-
var
|
|
32
|
+
var fromSsrInitialState = (initialState) => {
|
|
33
33
|
const userId = initialState.userId;
|
|
34
|
+
const sessionClaims = initialState.sessionClaims;
|
|
34
35
|
const token = initialState.token;
|
|
35
|
-
const email = initialState.email;
|
|
36
36
|
const user = initialState.user;
|
|
37
37
|
return {
|
|
38
38
|
userId,
|
|
39
|
+
sessionClaims,
|
|
39
40
|
token,
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
user,
|
|
42
|
+
session: void 0
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
45
|
var fromClientSideState = (authState) => {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const email = authState.user ? authState.user.email : null;
|
|
46
|
+
var _a, _b, _c, _d, _e, _f;
|
|
47
|
+
const userId = authState.user ? authState.user.uid : null;
|
|
48
48
|
const user = authState.user;
|
|
49
|
+
const sessionClaims = ((_a = authState.session) == null ? void 0 : _a.claims) ? {
|
|
50
|
+
uid: userId || authState.session.claims.sub || "",
|
|
51
|
+
sub: authState.session.claims.sub || userId || "",
|
|
52
|
+
email: authState.session.claims.email || ((_b = authState.user) == null ? void 0 : _b.email) || void 0,
|
|
53
|
+
email_verified: authState.session.claims.email_verified || ((_c = authState.user) == null ? void 0 : _c.emailVerified) || false,
|
|
54
|
+
exp: authState.session.claims.exp ? parseInt(authState.session.claims.exp) : 0,
|
|
55
|
+
iat: authState.session.claims.iat ? parseInt(authState.session.claims.iat) : 0,
|
|
56
|
+
auth_time: authState.session.claims.auth_time ? parseInt(authState.session.claims.auth_time) : 0,
|
|
57
|
+
aud: authState.session.claims.aud || "",
|
|
58
|
+
iss: authState.session.claims.iss || "",
|
|
59
|
+
firebase: {
|
|
60
|
+
identities: ((_d = authState.session.claims.firebase) == null ? void 0 : _d.identities) || {},
|
|
61
|
+
sign_in_provider: ((_e = authState.session.claims.firebase) == null ? void 0 : _e.sign_in_provider) || authState.session.signInProvider || "unknown",
|
|
62
|
+
sign_in_second_factor: (_f = authState.session.claims.firebase) == null ? void 0 : _f.sign_in_second_factor
|
|
63
|
+
},
|
|
64
|
+
phone_number: (user == null ? void 0 : user.phoneNumber) || void 0,
|
|
65
|
+
picture: (user == null ? void 0 : user.photoURL) || void 0,
|
|
66
|
+
name: (user == null ? void 0 : user.displayName) || void 0
|
|
67
|
+
} : null;
|
|
49
68
|
return {
|
|
50
69
|
userId,
|
|
51
|
-
|
|
52
|
-
email,
|
|
70
|
+
sessionClaims,
|
|
53
71
|
user
|
|
54
72
|
};
|
|
55
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/derivedAuthState.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/derivedAuthState.ts"],"sourcesContent":["import type {\n DecodedIdToken,\n SignedInSession,\n TernSecureResources,\n TernSecureStateExtended,\n TernSecureUser,\n} from '@tern-secure/types';\n\n\ntype NormalizedClaims = DecodedIdToken;\n\n\ntype DerivedAuthState = {\n userId: string | null | undefined;\n user: TernSecureUser | null | undefined;\n sessionClaims: NormalizedClaims | null | undefined;\n token?: string | null;\n session?: SignedInSession | null;\n};\n\nexport const deriveAuthState = (\n ternSecureIsReady: boolean,\n authState: TernSecureResources,\n initialState: TernSecureStateExtended | undefined,\n): DerivedAuthState => {\n if (!authState.user && initialState) {\n return fromSsrInitialState(initialState);\n }\n return fromClientSideState(authState);\n};\n\nconst fromSsrInitialState = (initialState: TernSecureStateExtended) => {\n const userId = initialState.userId;\n const sessionClaims = initialState.sessionClaims;\n const token = initialState.token;\n const user = initialState.user as TernSecureUser;\n\n return {\n userId,\n sessionClaims,\n token,\n user,\n session: undefined,\n };\n};\n\n\nconst fromClientSideState = (authState: TernSecureResources) => {\n const userId: string | null | undefined = authState.user ? authState.user.uid : null;\n const user = authState.user;\n const sessionClaims: DecodedIdToken | null = authState.session?.claims ? {\n uid: userId || (authState.session.claims.sub as string) || '',\n sub: (authState.session.claims.sub as string) || userId || '',\n email: (authState.session.claims as any).email || authState.user?.email || undefined,\n email_verified: (authState.session.claims as any).email_verified || authState.user?.emailVerified || false,\n exp: authState.session.claims.exp ? parseInt(authState.session.claims.exp) : 0,\n iat: authState.session.claims.iat ? parseInt(authState.session.claims.iat) : 0,\n auth_time: authState.session.claims.auth_time ? parseInt(authState.session.claims.auth_time) : 0,\n aud: (authState.session.claims as any).aud || '',\n iss: (authState.session.claims as any).iss || '',\n firebase: {\n identities: (authState.session.claims.firebase?.identities || {}) as { [key: string]: unknown },\n sign_in_provider: authState.session.claims.firebase?.sign_in_provider || authState.session.signInProvider || 'unknown',\n sign_in_second_factor: authState.session.claims.firebase?.sign_in_second_factor,\n },\n phone_number: user?.phoneNumber || undefined,\n picture: user?.photoURL || undefined,\n name: user?.displayName || undefined,\n } as DecodedIdToken : null;\n\n return {\n userId,\n sessionClaims,\n user,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,IAAM,kBAAkB,CAC7B,mBACA,WACA,iBACqB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UAAU,QAAQ,kBAAkB;AAAA,MAC7G,wBAAuB,eAAU,QAAQ,OAAO,aAAzB,mBAAmC;AAAA,IAC5D;AAAA,IACA,eAAc,6BAAM,gBAAe;AAAA,IACnC,UAAS,6BAAM,aAAY;AAAA,IAC3B,OAAM,6BAAM,gBAAe;AAAA,EAC7B,IAAsB;AAEtB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
// src/derivedAuthState.ts
|
|
2
|
-
var deriveAuthState = (authState, initialState) => {
|
|
3
|
-
if (initialState) {
|
|
4
|
-
return
|
|
2
|
+
var deriveAuthState = (ternSecureIsReady, authState, initialState) => {
|
|
3
|
+
if (!authState.user && initialState) {
|
|
4
|
+
return fromSsrInitialState(initialState);
|
|
5
5
|
}
|
|
6
6
|
return fromClientSideState(authState);
|
|
7
7
|
};
|
|
8
|
-
var
|
|
8
|
+
var fromSsrInitialState = (initialState) => {
|
|
9
9
|
const userId = initialState.userId;
|
|
10
|
+
const sessionClaims = initialState.sessionClaims;
|
|
10
11
|
const token = initialState.token;
|
|
11
|
-
const email = initialState.email;
|
|
12
12
|
const user = initialState.user;
|
|
13
13
|
return {
|
|
14
14
|
userId,
|
|
15
|
+
sessionClaims,
|
|
15
16
|
token,
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
user,
|
|
18
|
+
session: void 0
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
21
|
var fromClientSideState = (authState) => {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const email = authState.user ? authState.user.email : null;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
const userId = authState.user ? authState.user.uid : null;
|
|
24
24
|
const user = authState.user;
|
|
25
|
+
const sessionClaims = ((_a = authState.session) == null ? void 0 : _a.claims) ? {
|
|
26
|
+
uid: userId || authState.session.claims.sub || "",
|
|
27
|
+
sub: authState.session.claims.sub || userId || "",
|
|
28
|
+
email: authState.session.claims.email || ((_b = authState.user) == null ? void 0 : _b.email) || void 0,
|
|
29
|
+
email_verified: authState.session.claims.email_verified || ((_c = authState.user) == null ? void 0 : _c.emailVerified) || false,
|
|
30
|
+
exp: authState.session.claims.exp ? parseInt(authState.session.claims.exp) : 0,
|
|
31
|
+
iat: authState.session.claims.iat ? parseInt(authState.session.claims.iat) : 0,
|
|
32
|
+
auth_time: authState.session.claims.auth_time ? parseInt(authState.session.claims.auth_time) : 0,
|
|
33
|
+
aud: authState.session.claims.aud || "",
|
|
34
|
+
iss: authState.session.claims.iss || "",
|
|
35
|
+
firebase: {
|
|
36
|
+
identities: ((_d = authState.session.claims.firebase) == null ? void 0 : _d.identities) || {},
|
|
37
|
+
sign_in_provider: ((_e = authState.session.claims.firebase) == null ? void 0 : _e.sign_in_provider) || authState.session.signInProvider || "unknown",
|
|
38
|
+
sign_in_second_factor: (_f = authState.session.claims.firebase) == null ? void 0 : _f.sign_in_second_factor
|
|
39
|
+
},
|
|
40
|
+
phone_number: (user == null ? void 0 : user.phoneNumber) || void 0,
|
|
41
|
+
picture: (user == null ? void 0 : user.photoURL) || void 0,
|
|
42
|
+
name: (user == null ? void 0 : user.displayName) || void 0
|
|
43
|
+
} : null;
|
|
25
44
|
return {
|
|
26
45
|
userId,
|
|
27
|
-
|
|
28
|
-
email,
|
|
46
|
+
sessionClaims,
|
|
29
47
|
user
|
|
30
48
|
};
|
|
31
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/derivedAuthState.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/derivedAuthState.ts"],"sourcesContent":["import type {\n DecodedIdToken,\n SignedInSession,\n TernSecureResources,\n TernSecureStateExtended,\n TernSecureUser,\n} from '@tern-secure/types';\n\n\ntype NormalizedClaims = DecodedIdToken;\n\n\ntype DerivedAuthState = {\n userId: string | null | undefined;\n user: TernSecureUser | null | undefined;\n sessionClaims: NormalizedClaims | null | undefined;\n token?: string | null;\n session?: SignedInSession | null;\n};\n\nexport const deriveAuthState = (\n ternSecureIsReady: boolean,\n authState: TernSecureResources,\n initialState: TernSecureStateExtended | undefined,\n): DerivedAuthState => {\n if (!authState.user && initialState) {\n return fromSsrInitialState(initialState);\n }\n return fromClientSideState(authState);\n};\n\nconst fromSsrInitialState = (initialState: TernSecureStateExtended) => {\n const userId = initialState.userId;\n const sessionClaims = initialState.sessionClaims;\n const token = initialState.token;\n const user = initialState.user as TernSecureUser;\n\n return {\n userId,\n sessionClaims,\n token,\n user,\n session: undefined,\n };\n};\n\n\nconst fromClientSideState = (authState: TernSecureResources) => {\n const userId: string | null | undefined = authState.user ? authState.user.uid : null;\n const user = authState.user;\n const sessionClaims: DecodedIdToken | null = authState.session?.claims ? {\n uid: userId || (authState.session.claims.sub as string) || '',\n sub: (authState.session.claims.sub as string) || userId || '',\n email: (authState.session.claims as any).email || authState.user?.email || undefined,\n email_verified: (authState.session.claims as any).email_verified || authState.user?.emailVerified || false,\n exp: authState.session.claims.exp ? parseInt(authState.session.claims.exp) : 0,\n iat: authState.session.claims.iat ? parseInt(authState.session.claims.iat) : 0,\n auth_time: authState.session.claims.auth_time ? parseInt(authState.session.claims.auth_time) : 0,\n aud: (authState.session.claims as any).aud || '',\n iss: (authState.session.claims as any).iss || '',\n firebase: {\n identities: (authState.session.claims.firebase?.identities || {}) as { [key: string]: unknown },\n sign_in_provider: authState.session.claims.firebase?.sign_in_provider || authState.session.signInProvider || 'unknown',\n sign_in_second_factor: authState.session.claims.firebase?.sign_in_second_factor,\n },\n phone_number: user?.phoneNumber || undefined,\n picture: user?.photoURL || undefined,\n name: user?.displayName || undefined,\n } as DecodedIdToken : null;\n\n return {\n userId,\n sessionClaims,\n user,\n };\n};\n"],"mappings":";AAoBO,IAAM,kBAAkB,CAC7B,mBACA,WACA,iBACqB;AACrB,MAAI,CAAC,UAAU,QAAQ,cAAc;AACnC,WAAO,oBAAoB,YAAY;AAAA,EACzC;AACA,SA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IAC5D;AAAA,IACA,eAAc,6BAAM,gBAAe;AAAA,IACnC,UAAS,6BAAM,aAAY;AAAA,IAC3B,OAAM,6BAAM,gBAAe;AAAA,EAC7B,IAAsB;AAEtB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tern-secure/shared",
|
|
3
|
-
"version": "1.3.0-canary.
|
|
3
|
+
"version": "1.3.0-canary.v20251019190011",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TernSecure/auth.git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"js-cookie": "^3.0.5",
|
|
83
83
|
"tslib": "2.4.1",
|
|
84
|
-
"@tern-secure/types": "1.1.0-canary.
|
|
84
|
+
"@tern-secure/types": "1.1.0-canary.v20251019190011"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "^19",
|