@opexa/portal-components 0.1.65 → 0.1.69

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.
Files changed (49) hide show
  1. package/dist/client/hooks/useSessionQuery.js +11 -1
  2. package/dist/client/hooks/useSignInMutation.d.ts +1 -0
  3. package/dist/client/hooks/useSignInMutation.js +1 -1
  4. package/dist/components/KYC/KYCReminder.lazy.js +1 -1
  5. package/dist/components/PortalProvider/SessionWatcher.js +45 -2
  6. package/dist/components/SignIn/SignIn.lazy.d.ts +2 -1
  7. package/dist/constants/StorageKey.d.ts +1 -0
  8. package/dist/constants/StorageKey.js +1 -0
  9. package/dist/handlers/deleteSession.d.ts +1 -1
  10. package/dist/handlers/deleteSession.js +6 -2
  11. package/dist/handlers/getSession.js +29 -4
  12. package/dist/handlers/index.d.ts +2 -2
  13. package/dist/handlers/postSession.js +20 -3
  14. package/dist/schemas/forgotPasswordSchema.d.ts +4 -4
  15. package/dist/services/auth.d.ts +4 -3
  16. package/dist/services/auth.js +26 -6
  17. package/dist/ui/AlertDialog/AlertDialog.d.ts +55 -55
  18. package/dist/ui/AlertDialog/alertDialog.recipe.d.ts +5 -5
  19. package/dist/ui/Badge/Badge.d.ts +12 -12
  20. package/dist/ui/Badge/badge.anatomy.d.ts +1 -1
  21. package/dist/ui/Badge/badge.recipe.d.ts +3 -3
  22. package/dist/ui/Carousel/Carousel.d.ts +99 -99
  23. package/dist/ui/Carousel/carousel.recipe.d.ts +11 -11
  24. package/dist/ui/Checkbox/Checkbox.d.ts +23 -23
  25. package/dist/ui/Checkbox/checkbox.recipe.d.ts +3 -3
  26. package/dist/ui/Clipboard/Clipboard.d.ts +18 -18
  27. package/dist/ui/Clipboard/clipboard.recipe.d.ts +3 -3
  28. package/dist/ui/Combobox/Combobox.d.ts +42 -42
  29. package/dist/ui/Combobox/combobox.recipe.d.ts +3 -3
  30. package/dist/ui/DatePicker/DatePicker.d.ts +72 -72
  31. package/dist/ui/DatePicker/datePicker.recipe.d.ts +3 -3
  32. package/dist/ui/Dialog/Dialog.d.ts +33 -33
  33. package/dist/ui/Dialog/dialog.recipe.d.ts +3 -3
  34. package/dist/ui/Drawer/Drawer.d.ts +33 -33
  35. package/dist/ui/Drawer/drawer.recipe.d.ts +3 -3
  36. package/dist/ui/Field/Field.d.ts +21 -21
  37. package/dist/ui/Field/field.recipe.d.ts +3 -3
  38. package/dist/ui/Menu/Menu.d.ts +144 -144
  39. package/dist/ui/Menu/menu.recipe.d.ts +8 -8
  40. package/dist/ui/Popover/Popover.d.ts +55 -55
  41. package/dist/ui/Popover/popover.recipe.d.ts +5 -5
  42. package/dist/ui/SegmentGroup/SegmentGroup.d.ts +18 -18
  43. package/dist/ui/SegmentGroup/segmentGroup.recipe.d.ts +3 -3
  44. package/dist/ui/Select/Select.d.ts +45 -45
  45. package/dist/ui/Select/select.recipe.d.ts +3 -3
  46. package/dist/ui/Table/Table.d.ts +21 -21
  47. package/dist/ui/Table/table.anatomy.d.ts +1 -1
  48. package/dist/ui/Table/table.recipe.d.ts +3 -3
  49. package/package.json +2 -1
@@ -1,6 +1,8 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
+ import { FINGERPRINT_HEADER_KEY } from '../../constants/index.js';
2
3
  import { getSessionQueryKey } from '../../utils/queryKeys.js';
3
4
  import { getSession } from '../services/getSession.js';
5
+ import { getFingerprint } from './useSignInMutation.js';
4
6
  export const useSessionQuery = (config) => {
5
7
  return useQuery({
6
8
  gcTime: 1000 * 2,
@@ -8,7 +10,15 @@ export const useSessionQuery = (config) => {
8
10
  ...config,
9
11
  queryKey: getSessionQueryKey(),
10
12
  queryFn: async ({ signal }) => {
11
- return await getSession({ signal });
13
+ const fingerprint = await getFingerprint();
14
+ return await getSession({
15
+ signal,
16
+ headers: {
17
+ ...(fingerprint && {
18
+ [FINGERPRINT_HEADER_KEY]: fingerprint,
19
+ }),
20
+ },
21
+ });
12
22
  },
13
23
  });
14
24
  };
@@ -8,3 +8,4 @@ export interface UseSignInMutationOptions extends MutationConfig<Authenticator |
8
8
  version?: ApiVersion;
9
9
  }
10
10
  export declare const useSignInMutation: (options?: UseSignInMutationOptions) => UseMutationResult<Authenticator | null, Error, SignInInput>;
11
+ export declare function getFingerprint(): Promise<string | null>;
@@ -88,7 +88,7 @@ async function pollSignIn(signInOnce) {
88
88
  return result.authenticator;
89
89
  }
90
90
  let thumbmark_instance;
91
- async function getFingerprint() {
91
+ export async function getFingerprint() {
92
92
  if (typeof window === 'undefined')
93
93
  return null;
94
94
  if (!thumbmark_instance) {
@@ -11,7 +11,6 @@ import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
11
11
  import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
12
12
  import { useSignOutMutation } from '../../client/hooks/useSignOutMutation.js';
13
13
  import { getSession } from '../../client/services/getSession.js';
14
- import { clearLocalStorageOnLogout } from '../../utils/clear-local-storage-on-logout.js';
15
14
  import { FileCheck02Icon } from '../../icons/FileCheck02Icon.js';
16
15
  import { XIcon } from '../../icons/XIcon.js';
17
16
  import pagcorLogo from '../../images/pagcor.png';
@@ -20,6 +19,7 @@ import { unregisterFCMDevice } from '../../services/trigger.js';
20
19
  import { Button } from '../../ui/Button/index.js';
21
20
  import { Dialog } from '../../ui/Dialog/index.js';
22
21
  import { Portal } from '../../ui/Portal/index.js';
22
+ import { clearLocalStorageOnLogout } from '../../utils/clear-local-storage-on-logout.js';
23
23
  import { getQueryClient } from '../../utils/getQueryClient.js';
24
24
  import { getSessionQueryKey } from '../../utils/queryKeys.js';
25
25
  export function KYCReminder({ enablePendingKycReminder = false, ...props }) {
@@ -1,5 +1,7 @@
1
1
  'use client';
2
+ import { App } from '@capacitor/app';
2
3
  import { useRouter } from 'next/navigation';
4
+ import { useEffect, useRef } from 'react';
3
5
  import { useTimeout } from 'usehooks-ts';
4
6
  import { useShallow } from 'zustand/shallow';
5
7
  import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
@@ -7,13 +9,54 @@ import { useSessionHealthQuery } from '../../client/hooks/useSessionHealthQuery.
7
9
  import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
8
10
  import { useSignOutMutation } from '../../client/hooks/useSignOutMutation.js';
9
11
  import { toaster } from '../../client/utils/toaster.js';
12
+ const SESSION_WATCH_INTERVAL = 30_000;
10
13
  export function SessionWatcher() {
11
14
  const router = useRouter();
12
15
  const sessionQuery = useSessionQuery();
16
+ const isAuthenticated = sessionQuery.data?.status === 'authenticated';
17
+ const isAuthenticatedRef = useRef(isAuthenticated);
18
+ isAuthenticatedRef.current = isAuthenticated;
13
19
  const sessionHealthQuery = useSessionHealthQuery({
14
- enabled: sessionQuery.data?.status === 'authenticated',
15
- refetchInterval: 1000 * 5,
20
+ enabled: false,
16
21
  });
22
+ const refetchSessionHealthRef = useRef(sessionHealthQuery.refetch);
23
+ refetchSessionHealthRef.current = sessionHealthQuery.refetch;
24
+ useEffect(() => {
25
+ let counter = 0;
26
+ let timeout = null;
27
+ let isForeground = true;
28
+ let stopped = false;
29
+ const listener = App.addListener('appStateChange', ({ isActive }) => {
30
+ isForeground = isActive;
31
+ });
32
+ const assignTimeout = () => {
33
+ const duration = counter <= 0 ? SESSION_WATCH_INTERVAL * 1.5 : SESSION_WATCH_INTERVAL;
34
+ return setTimeout(async () => {
35
+ if (isForeground && isAuthenticatedRef.current) {
36
+ try {
37
+ await refetchSessionHealthRef.current();
38
+ }
39
+ catch {
40
+ // A failed check must not stop future session checks.
41
+ }
42
+ if (stopped) {
43
+ return;
44
+ }
45
+ }
46
+ counter += 1;
47
+ timeout = assignTimeout();
48
+ }, duration);
49
+ };
50
+ timeout = assignTimeout();
51
+ return () => {
52
+ stopped = true;
53
+ if (timeout) {
54
+ clearTimeout(timeout);
55
+ timeout = null;
56
+ }
57
+ void listener.then((handle) => handle.remove()).catch(() => undefined);
58
+ };
59
+ }, []);
17
60
  const { gameLaunch, reset } = useGlobalStore(useShallow((ctx) => ({
18
61
  gameLaunch: ctx.gameLaunch,
19
62
  reset: ctx.reset,
@@ -29,7 +29,8 @@ export interface SignInProps extends UseSignInProps {
29
29
  /**
30
30
  * Selects which auth session endpoint the sign-in flow targets.
31
31
  * - `default` (default): `${AUTH_ENDPOINT}/sessions`
32
- * - `Inplay`: `${AUTH_ENDPOINT}/v3/inplay/sessions`
32
+ * - `Inplay`: `${AUTH_ENDPOINT}/v3/inplay/sessions`, or `/v4/inplay/sessions`
33
+ * when `version` is `4`
33
34
  */
34
35
  versionSession?: VersionSession;
35
36
  /**
@@ -1,3 +1,4 @@
1
+ export declare const AUTH_CONFIG_COOKIE_NAME: string;
1
2
  export declare const ACCESS_TOKEN_COOKIE_NAME: string;
2
3
  export declare const REFRESH_TOKEN_COOKIE_NAME: string;
3
4
  export declare const DOMAIN_COOKIE_NAME: string;
@@ -1,3 +1,4 @@
1
+ export const AUTH_CONFIG_COOKIE_NAME = 'WebPortalAuthConfig';
1
2
  export const ACCESS_TOKEN_COOKIE_NAME = 'WebPortalAuthAccessToken';
2
3
  export const REFRESH_TOKEN_COOKIE_NAME = 'WebPortalAuthRefreshToken';
3
4
  export const DOMAIN_COOKIE_NAME = 'WebPortalDomain';
@@ -1,4 +1,4 @@
1
- import { NextResponse, type NextRequest } from 'next/server';
1
+ import { type NextRequest, NextResponse } from 'next/server';
2
2
  export declare function deleteSession(request: NextRequest): Promise<NextResponse<{
3
3
  ok: true;
4
4
  data?: never;
@@ -1,14 +1,18 @@
1
1
  import { NextResponse } from 'next/server';
2
- import { ACCESS_TOKEN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
2
+ import { ACCESS_TOKEN_COOKIE_NAME, AUTH_CONFIG_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
3
3
  import { destroySession } from '../services/auth.js';
4
4
  export async function deleteSession(request) {
5
5
  const accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
6
+ const authConfig = JSON.parse(request.cookies.get(AUTH_CONFIG_COOKIE_NAME)?.value ?? '{}');
7
+ const authApiBaseUrl = authConfig.apiBaseUrl;
8
+ console.log('[DESTROY SESSION]');
9
+ console.log({ authApiBaseUrl });
6
10
  if (accessToken) {
7
11
  await destroySession({
8
12
  headers: {
9
13
  Authorization: `Bearer ${accessToken}`,
10
14
  },
11
- });
15
+ }, authApiBaseUrl);
12
16
  }
13
17
  const response = NextResponse.json({
14
18
  ok: true,
@@ -1,11 +1,21 @@
1
- import { addMinutes } from 'date-fns';
1
+ import { addDays, addMinutes, subMinutes } from 'date-fns';
2
2
  import { NextResponse } from 'next/server';
3
- import { ACCESS_TOKEN_COOKIE_NAME, BTAG_COOKIE_NAME, DOMAIN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
3
+ import { ACCESS_TOKEN_COOKIE_NAME, AUTH_CONFIG_COOKIE_NAME, BTAG_COOKIE_NAME, DOMAIN_COOKIE_NAME, FINGERPRINT_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
4
4
  import { refreshSession } from '../services/auth.js';
5
5
  export async function getSession(request) {
6
6
  const accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
7
+ const authConfig = JSON.parse(request.cookies.get(AUTH_CONFIG_COOKIE_NAME)?.value ?? '{}');
8
+ const authVersion = authConfig.version;
9
+ const authApiBaseUrl = authConfig.apiBaseUrl;
10
+ const fingerprint = request.headers.get(FINGERPRINT_HEADER_KEY);
11
+ console.log('[GET SESSION]');
12
+ console.log({
13
+ authVersion,
14
+ authApiBaseUrl,
15
+ fingerprint,
16
+ });
7
17
  let isAccessTokenValid = true;
8
- if (accessToken) {
18
+ if (accessToken && authVersion !== 4) {
9
19
  try {
10
20
  const payload = accessToken.split('.')[1];
11
21
  const decoded = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
@@ -17,6 +27,9 @@ export async function getSession(request) {
17
27
  isAccessTokenValid = false;
18
28
  }
19
29
  }
30
+ if (authVersion === 4 && !accessToken) {
31
+ isAccessTokenValid = false;
32
+ }
20
33
  const refreshToken = request.cookies.get(REFRESH_TOKEN_COOKIE_NAME)?.value;
21
34
  const domain = request.cookies.get(DOMAIN_COOKIE_NAME)?.value;
22
35
  const btag = request.cookies.get(BTAG_COOKIE_NAME)?.value;
@@ -31,6 +44,7 @@ export async function getSession(request) {
31
44
  });
32
45
  response.cookies.delete(ACCESS_TOKEN_COOKIE_NAME);
33
46
  response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
47
+ response.cookies.delete(AUTH_CONFIG_COOKIE_NAME);
34
48
  return response;
35
49
  }
36
50
  if (!accessToken || !isAccessTokenValid) {
@@ -45,8 +59,11 @@ export async function getSession(request) {
45
59
  ...(ipAddress && {
46
60
  'X-Forwarded-For': ipAddress,
47
61
  }),
62
+ ...(fingerprint && {
63
+ [FINGERPRINT_HEADER_KEY]: fingerprint,
64
+ }),
48
65
  },
49
- });
66
+ }, authVersion, authApiBaseUrl);
50
67
  const response = NextResponse.json({
51
68
  ok: true,
52
69
  data: {
@@ -60,6 +77,13 @@ export async function getSession(request) {
60
77
  httpOnly: true,
61
78
  sameSite: 'strict',
62
79
  });
80
+ if (authVersion === 4) {
81
+ response.cookies.set(REFRESH_TOKEN_COOKIE_NAME, data.refreshToken, {
82
+ expires: subMinutes(addDays(new Date(), 15), 2),
83
+ httpOnly: true,
84
+ sameSite: 'strict',
85
+ });
86
+ }
63
87
  return response;
64
88
  }
65
89
  catch {
@@ -72,6 +96,7 @@ export async function getSession(request) {
72
96
  },
73
97
  });
74
98
  response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
99
+ response.cookies.delete(AUTH_CONFIG_COOKIE_NAME);
75
100
  return response;
76
101
  }
77
102
  }
@@ -18,14 +18,14 @@ export declare const GET: (req: NextRequest, { params }: Context) => Promise<Nex
18
18
  __error?: unknown;
19
19
  } | {
20
20
  ok: true;
21
- data: Record<string, unknown>;
21
+ data: import("../types").Session;
22
22
  }> | NextResponse<{
23
23
  ok: false;
24
24
  message: string;
25
25
  __error?: unknown;
26
26
  } | {
27
27
  ok: true;
28
- data: import("../types").Session;
28
+ data: Record<string, unknown>;
29
29
  }>>;
30
30
  export declare const DELETE: (req: NextRequest, { params }: Context) => Promise<NextResponse<{
31
31
  ok: true;
@@ -1,7 +1,7 @@
1
1
  import { addDays, addMinutes, subMinutes } from 'date-fns';
2
2
  import { NextResponse } from 'next/server';
3
3
  import { z } from 'zod';
4
- import { ACCESS_TOKEN_COOKIE_NAME, API_VERSION_HEADER_KEY, AUTH_API_BASE_URL_HEADER_KEY, DOMAIN_HEADER_KEY, FINGERPRINT_HEADER_KEY, GOOGLE_FRAUD_DEFENSE_HEADER_KEY, PLATFORM_WEB_HEADER_KEY, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, SESSION_VERSION_HEADER_KEY, } from '../constants/index.js';
4
+ import { ACCESS_TOKEN_COOKIE_NAME, API_VERSION_HEADER_KEY, AUTH_API_BASE_URL_HEADER_KEY, AUTH_CONFIG_COOKIE_NAME, DOMAIN_HEADER_KEY, FINGERPRINT_HEADER_KEY, GOOGLE_FRAUD_DEFENSE_HEADER_KEY, PLATFORM_WEB_HEADER_KEY, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, SESSION_VERSION_HEADER_KEY, } from '../constants/index.js';
5
5
  import { createSession, } from '../services/auth.js';
6
6
  const CreateSessionDefinition = z.union([
7
7
  z.object({
@@ -47,6 +47,14 @@ export async function postSession(request) {
47
47
  const authApiBaseUrl = request.headers.get(AUTH_API_BASE_URL_HEADER_KEY);
48
48
  const version = request.headers.get(API_VERSION_HEADER_KEY) === '4' ? 4 : 1;
49
49
  const isWeb = request.headers.get(PLATFORM_WEB_HEADER_KEY) === 'true';
50
+ console.log('[CREATE SESSION]');
51
+ console.log({
52
+ versionSession,
53
+ version,
54
+ authApiBaseUrl,
55
+ fingerprint,
56
+ isWeb,
57
+ });
50
58
  try {
51
59
  const googleFraudDefense = request.headers.get(GOOGLE_FRAUD_DEFENSE_HEADER_KEY);
52
60
  const recaptchaToken = googleFraudDefense ?? recaptcha;
@@ -79,12 +87,21 @@ export async function postSession(request) {
79
87
  }
80
88
  const response = NextResponse.json({ ok: true, data: null }, { status: 201 });
81
89
  response.cookies.set(ACCESS_TOKEN_COOKIE_NAME, res.accessToken, {
82
- expires: addMinutes(new Date(), 9),
90
+ expires: addMinutes(new Date(), version === 4 ? 4 : 9),
83
91
  httpOnly: true,
84
92
  sameSite: 'strict',
85
93
  });
94
+ const _15d = subMinutes(addDays(new Date(), version === 4 ? 15 : 1), 2);
86
95
  response.cookies.set(REFRESH_TOKEN_COOKIE_NAME, res.refreshToken, {
87
- expires: subMinutes(addDays(new Date(), 30), 1),
96
+ expires: _15d,
97
+ httpOnly: true,
98
+ sameSite: 'strict',
99
+ });
100
+ response.cookies.set(AUTH_CONFIG_COOKIE_NAME, JSON.stringify({
101
+ version,
102
+ authApiBaseUrl,
103
+ }), {
104
+ expires: _15d,
88
105
  httpOnly: true,
89
106
  sameSite: 'strict',
90
107
  });
@@ -8,24 +8,24 @@ export declare const createForgotPasswordSchema: (mobileNumberParser: MobileNumb
8
8
  mobileNumber: z.ZodEffects<z.ZodString, string, string>;
9
9
  verificationCode: z.ZodEffects<z.ZodString, string, string>;
10
10
  }, "strip", z.ZodTypeAny, {
11
- verificationCode: string;
12
11
  password: string;
13
12
  mobileNumber: string;
13
+ verificationCode: string;
14
14
  confirmPassword: string;
15
15
  }, {
16
- verificationCode: string;
17
16
  password: string;
18
17
  mobileNumber: string;
18
+ verificationCode: string;
19
19
  confirmPassword: string;
20
20
  }>, {
21
- verificationCode: string;
22
21
  password: string;
23
22
  mobileNumber: string;
23
+ verificationCode: string;
24
24
  confirmPassword: string;
25
25
  }, {
26
- verificationCode: string;
27
26
  password: string;
28
27
  mobileNumber: string;
28
+ verificationCode: string;
29
29
  confirmPassword: string;
30
30
  }>;
31
31
  export type ForgotPasswordSchema = z.infer<ReturnType<typeof createForgotPasswordSchema>>;
@@ -25,7 +25,8 @@ export type CreateSessionInput = CreateSessionInput__UsernameAndPassword | Creat
25
25
  /**
26
26
  * Controls which auth endpoint is used to create a session.
27
27
  * - `default` -> `${AUTH_ENDPOINT}/sessions` (or `/v3`/`/v4/sessions`, see `ApiVersion`)
28
- * - `Inplay` -> `${AUTH_ENDPOINT}/v3/inplay/sessions` (no v4 variant exists)
28
+ * - `Inplay` -> `${AUTH_ENDPOINT}/v3/inplay/sessions`, or `/v4/inplay/sessions`
29
+ * when `version` is `4` (any other version falls back to `v3`)
29
30
  */
30
31
  export type VersionSession = 'default' | 'Inplay';
31
32
  /**
@@ -80,8 +81,8 @@ export type AuthenticateInput = AuthenticateInput__SecurityQuestion;
80
81
  export declare function authenticate(input: AuthenticateInput, options?: HttpRequestOptions): Promise<AuthenticateMutation>;
81
82
  export interface RefreshSessionMutation extends Omit<CreateSessionTwoFactorAuthDisabledMutation, 'authenticator'> {
82
83
  }
83
- export declare function refreshSession(options?: HttpRequestOptions): Promise<RefreshSessionMutation>;
84
- export declare function destroySession(options?: HttpRequestOptions): Promise<void>;
84
+ export declare function refreshSession(options?: HttpRequestOptions, version?: ApiVersion, authApiBaseUrl?: string | null): Promise<RefreshSessionMutation>;
85
+ export declare function destroySession(options?: HttpRequestOptions, authApiBaseUrl?: string | null): Promise<void>;
85
86
  export declare function getSessionHealth(options?: HttpRequestOptions): Promise<boolean>;
86
87
  export interface SendVerificationCodeInput {
87
88
  strict?: boolean;
@@ -3,7 +3,7 @@ import { httpRequest } from './httpRequest.js';
3
3
  import { sha256 } from './sha256.js';
4
4
  function getSessionEndpoint(versionSession, version) {
5
5
  if (versionSession === 'Inplay')
6
- return '/v3/inplay/sessions';
6
+ return `/v${version === 4 ? 4 : 3}/inplay/sessions`;
7
7
  return version !== 1 ? `/v${version}/sessions` : '/sessions';
8
8
  }
9
9
  export async function createSession(input, options, versionSession = 'default', version = 1, authApiBaseUrl) {
@@ -50,7 +50,6 @@ export async function createSession(input, options, versionSession = 'default',
50
50
  const queryParam = version === 4 && isWeb ? '?type=web' : '';
51
51
  const path = getSessionEndpoint(effectiveVersionSession, version);
52
52
  const baseUrl = authApiBaseUrl || AUTH_ENDPOINT;
53
- console.log({ x: baseUrl });
54
53
  try {
55
54
  // v1 against the default endpoint returns the payload flat; every
56
55
  // other combination (Inplay, or version 3/4) wraps it in `{ data: { ... } }`.
@@ -143,14 +142,25 @@ export async function authenticate(input, options) {
143
142
  }
144
143
  throw new Error("Invalid input 'type'");
145
144
  }
146
- export async function refreshSession(options) {
145
+ export async function refreshSession(options, version = 1, authApiBaseUrl) {
146
+ let url = '';
147
+ url = authApiBaseUrl || AUTH_ENDPOINT;
148
+ url =
149
+ version !== 1
150
+ ? `${url}/v${version}/session/refresh`
151
+ : `${url}/session:refresh`;
152
+ console.log('[REFRESH SESSION]');
153
+ console.log({ url });
147
154
  try {
148
- return await httpRequest.json(`${AUTH_ENDPOINT}/session:refresh`, {
155
+ return await httpRequest.json(url, {
149
156
  ...options,
150
157
  method: 'POST',
151
158
  });
152
159
  }
153
160
  catch (e) {
161
+ console.log('[REFRESH SESSION]');
162
+ console.log('Failed to refresh session');
163
+ console.log(e);
154
164
  if (e instanceof Error) {
155
165
  throw e;
156
166
  }
@@ -163,9 +173,14 @@ export async function refreshSession(options) {
163
173
  }
164
174
  }
165
175
  }
166
- export async function destroySession(options) {
176
+ export async function destroySession(options, authApiBaseUrl) {
177
+ let url = '';
178
+ url = authApiBaseUrl || AUTH_ENDPOINT;
179
+ url = `${url}/session`;
180
+ console.log('[DESTROY SESSION]');
181
+ console.log({ url });
167
182
  try {
168
- await httpRequest(`${AUTH_ENDPOINT}/session`, {
183
+ await httpRequest(url, {
169
184
  ...options,
170
185
  method: 'DELETE',
171
186
  });
@@ -177,9 +192,14 @@ export async function destroySession(options) {
177
192
  export async function getSessionHealth(options) {
178
193
  try {
179
194
  const res = await fetch(`${AUTH_ENDPOINT}/session`, options);
195
+ if (!res.ok) {
196
+ console.log('[SESSION]');
197
+ console.log("'/session' failed");
198
+ }
180
199
  return res.ok;
181
200
  }
182
201
  catch {
202
+ console.log("unknown error in '/session'");
183
203
  /* Network errors should not be logged out */
184
204
  return true;
185
205
  }