@schibsted/account-sdk-browser 6.0.0-alpha.4 → 6.0.0-alpha.6

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,89 +0,0 @@
1
- /* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
- * See LICENSE.md in the project root.
3
- */
4
-
5
- import { isObject, isStr } from '../validate.js';
6
- import type {
7
- ConnectedSessionResponse,
8
- ConnectedSessionWithUserIdResponse,
9
- SessionFailureResponse,
10
- SessionResponse,
11
- SessionSuccessResponse,
12
- UnrecognizedSessionResponse,
13
- } from './session.js';
14
-
15
- type SessionObjectResponse =
16
- | SessionSuccessResponse
17
- | SessionFailureResponse
18
- | UnrecognizedSessionResponse;
19
-
20
- type RedirectSessionPayload = {
21
- redirectURL: string;
22
- };
23
-
24
- export type NormalizedSessionPayload = SessionObjectResponse | RedirectSessionPayload;
25
-
26
- export function isSessionSuccessResponse(value: unknown): value is SessionSuccessResponse {
27
- return isObject(value) && typeof value.result === 'boolean';
28
- }
29
-
30
- export function isConnectedSessionResponse(value: unknown): value is ConnectedSessionResponse {
31
- return isSessionSuccessResponse(value) && value.result === true;
32
- }
33
-
34
- export function isSessionFailureResponse(value: unknown): value is SessionFailureResponse {
35
- return isObject(value) && Boolean(value.error);
36
- }
37
-
38
- export function isRedirectSessionPayload(value: unknown): value is RedirectSessionPayload {
39
- return isObject(value) && Object.keys(value).length === 1 && isStr(value.redirectURL);
40
- }
41
-
42
- export function isConnectedSessionWithUserIdResponse(
43
- value: SessionResponse,
44
- ): value is ConnectedSessionWithUserIdResponse {
45
- return (
46
- isConnectedSessionResponse(value) &&
47
- (typeof value.userId === 'number' || typeof value.userId === 'string')
48
- );
49
- }
50
-
51
- /**
52
- * Converts an unknown Session Service `hasSession` payload into one of the shapes the SDK knows how
53
- * to handle.
54
- *
55
- * This function is intentionally tolerant because `hasSession()` historically resolved unknown
56
- * object payloads instead of rejecting them. The SDK relies on that behavior for backwards
57
- * compatibility with clients that check the raw response themselves.
58
- *
59
- * The normal cases are:
60
- * - regular success payloads with a boolean `result`;
61
- * - failure payloads wrapped as `{ error, response? }`;
62
- * - Safari/session-refresh redirect payloads shaped as `{ redirectURL }`.
63
- *
64
- * Any other object is preserved as an unrecognized response so callers can still receive it.
65
- * Non-object values are normalized to `{}`, matching the old "empty response" fallback used by
66
- * `hasSession()` and cached-session reads.
67
- *
68
- * This is used both for network responses parsed by `RESTClient` and for values restored from the
69
- * session cache, so the rest of the Identity flow can switch on typed guards instead of repeatedly
70
- * re-validating unknown data.
71
- *
72
- * @internal
73
- */
74
- export function normalizeSessionResponse(value: unknown): NormalizedSessionPayload {
75
- if (isRedirectSessionPayload(value)) {
76
- return value;
77
- }
78
- if (isSessionFailureResponse(value)) {
79
- return value;
80
- }
81
- if (isSessionSuccessResponse(value)) {
82
- return value;
83
- }
84
- if (isObject(value)) {
85
- return value;
86
- }
87
-
88
- return {};
89
- }