@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.
- package/README.md +272 -224
- package/dist/account-sdk.d.ts +18 -0
- package/dist/account.d.ts +134 -3
- package/dist/globals.d.ts +0 -4
- package/dist/identity.d.ts +39 -83
- package/dist/index.d.ts +2 -1
- package/dist/index.js +286 -338
- package/dist/index.js.map +1 -1
- package/dist/monetization.d.ts +6 -25
- package/dist/sdk-error.d.ts +2 -0
- package/dist/types/account.d.ts +33 -3
- package/dist/types/common.d.ts +7 -1
- package/dist/types/identity.d.ts +0 -18
- package/dist/types/login.d.ts +16 -11
- package/dist/types/monetization.d.ts +6 -1
- package/dist/types/session.d.ts +28 -3
- package/dist/version.d.ts +1 -1
- package/package.json +1 -4
- package/src/account-sdk.ts +18 -0
- package/src/account.ts +154 -15
- package/src/globals.ts +0 -4
- package/src/identity.ts +125 -273
- package/src/index.ts +2 -2
- package/src/monetization.ts +15 -51
- package/src/sdk-error.ts +2 -0
- package/src/types/account.ts +36 -13
- package/src/types/common.ts +7 -1
- package/src/types/identity.ts +0 -29
- package/src/types/login.ts +16 -11
- package/src/types/monetization.ts +6 -1
- package/src/types/session.ts +28 -3
- package/src/version.ts +1 -1
- package/dist/global-registry.d.ts +0 -23
- package/dist/types/monetization-guards.d.ts +0 -2
- package/dist/types/session-guards.d.ts +0 -36
- package/src/global-registry.ts +0 -39
- package/src/types/monetization-guards.ts +0 -35
- package/src/types/session-guards.ts +0 -89
|
@@ -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
|
-
}
|