@nhost/nhost-js 4.2.2 → 4.3.0

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 (76) hide show
  1. package/dist/fetch-2PHmQBIJ.js.map +1 -1
  2. package/dist/fetch-DWXwEnoe.cjs.map +1 -1
  3. package/dist/{middlewareWithAdminSession-DLqDQUbW.js → middlewareWithAdminSession-BeIk-9HO.js} +2 -2
  4. package/dist/middlewareWithAdminSession-BeIk-9HO.js.map +1 -0
  5. package/dist/middlewareWithAdminSession-DDApoLkL.cjs.map +1 -1
  6. package/dist/nhost-js/auth.cjs.map +1 -1
  7. package/dist/nhost-js/auth.js.map +1 -1
  8. package/dist/nhost-js/fetch.cjs.map +1 -1
  9. package/dist/nhost-js/fetch.js +1 -1
  10. package/dist/nhost-js/fetch.js.map +1 -1
  11. package/dist/nhost-js/functions.cjs.map +1 -1
  12. package/dist/nhost-js/functions.js.map +1 -1
  13. package/dist/nhost-js/graphql.cjs.map +1 -1
  14. package/dist/nhost-js/graphql.js.map +1 -1
  15. package/dist/nhost-js/session.cjs.map +1 -1
  16. package/dist/nhost-js/session.js +1 -1
  17. package/dist/nhost-js/session.js.map +1 -1
  18. package/dist/nhost-js/storage.cjs.map +1 -1
  19. package/dist/nhost-js/storage.js.map +1 -1
  20. package/dist/nhost-js.cjs.map +1 -1
  21. package/dist/nhost-js.js +2 -2
  22. package/dist/nhost-js.js.map +1 -1
  23. package/dist/nhost-js.umd.js.map +1 -1
  24. package/dist/refreshSession-Bw715ZmX.cjs.map +1 -1
  25. package/dist/{refreshSession-CG8GIEun.js → refreshSession-WwGlzgtM.js} +2 -5
  26. package/dist/refreshSession-WwGlzgtM.js.map +1 -0
  27. package/dist/src/auth/client.d.ts +28 -28
  28. package/dist/src/auth/client.js +76 -76
  29. package/dist/src/auth/index.d.ts +1 -1
  30. package/dist/src/auth/index.js +1 -1
  31. package/dist/src/fetch/fetch.js +20 -20
  32. package/dist/src/fetch/index.d.ts +7 -7
  33. package/dist/src/fetch/index.js +7 -7
  34. package/dist/src/fetch/middlewareAttachAccessToken.d.ts +2 -2
  35. package/dist/src/fetch/middlewareAttachAccessToken.js +2 -2
  36. package/dist/src/fetch/middlewareSessionRefresh.d.ts +3 -3
  37. package/dist/src/fetch/middlewareSessionRefresh.js +3 -3
  38. package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts +2 -2
  39. package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +8 -8
  40. package/dist/src/fetch/middlewareWithAdminSession.d.ts +1 -1
  41. package/dist/src/fetch/middlewareWithAdminSession.js +5 -5
  42. package/dist/src/fetch/middlewareWithHeaders.d.ts +1 -1
  43. package/dist/src/fetch/middlewareWithRole.d.ts +1 -1
  44. package/dist/src/fetch/middlewareWithRole.js +2 -2
  45. package/dist/src/functions/client.d.ts +1 -1
  46. package/dist/src/functions/client.js +6 -6
  47. package/dist/src/functions/index.d.ts +1 -1
  48. package/dist/src/functions/index.js +1 -1
  49. package/dist/src/graphql/client.d.ts +2 -2
  50. package/dist/src/graphql/client.js +6 -6
  51. package/dist/src/graphql/index.d.ts +1 -1
  52. package/dist/src/graphql/index.js +1 -1
  53. package/dist/src/index.d.ts +1 -1
  54. package/dist/src/index.js +1 -1
  55. package/dist/src/nhost.d.ts +6 -6
  56. package/dist/src/nhost.js +11 -11
  57. package/dist/src/session/index.d.ts +4 -4
  58. package/dist/src/session/index.js +3 -3
  59. package/dist/src/session/refreshSession.d.ts +3 -3
  60. package/dist/src/session/refreshSession.d.ts.map +1 -1
  61. package/dist/src/session/refreshSession.js +5 -7
  62. package/dist/src/session/refreshSession.js.map +1 -1
  63. package/dist/src/session/session.d.ts +2 -2
  64. package/dist/src/session/session.js +15 -15
  65. package/dist/src/session/storage.d.ts +3 -3
  66. package/dist/src/session/storage.js +4 -4
  67. package/dist/src/session/storageBackend.d.ts +2 -2
  68. package/dist/src/session/storageBackend.js +7 -7
  69. package/dist/src/storage/client.d.ts +5 -5
  70. package/dist/src/storage/client.js +44 -44
  71. package/dist/src/storage/index.d.ts +1 -1
  72. package/dist/src/storage/index.js +1 -1
  73. package/dist/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +1 -2
  75. package/dist/middlewareWithAdminSession-DLqDQUbW.js.map +0 -1
  76. package/dist/refreshSession-CG8GIEun.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"refreshSession-Bw715ZmX.cjs","sources":["../src/session/refreshSession.ts"],"sourcesContent":["import type { Client as AuthClient, ErrorResponse } from \"../auth\";\nimport type { FetchResponse } from \"../fetch\";\nimport type { Session } from \"./session\";\nimport type { SessionStorage } from \"./storage\";\n\nclass DummyLock implements Lock {\n async request(\n _name: string,\n _options: { mode: \"exclusive\" | \"shared\" },\n // biome-ignore lint/suspicious/noExplicitAny: any\n callback: () => Promise<any>,\n ) {\n return callback();\n }\n}\n\ninterface Lock {\n request: (\n name: string,\n options: { mode: \"exclusive\" | \"shared\" },\n // biome-ignore lint/suspicious/noExplicitAny: blah\n callback: () => Promise<any>,\n // biome-ignore lint/suspicious/noExplicitAny: blah\n ) => Promise<any>;\n}\n\nconst lock: Lock =\n // biome-ignore lint/complexity/useOptionalChain: this check breaks non-browser environments\n typeof navigator !== \"undefined\" && navigator.locks\n ? navigator.locks\n : new DummyLock();\n\n/**\n * Refreshes the authentication session if needed\n *\n * This function checks if the current session needs to be refreshed based on\n * the access token expiration time. If a refresh is needed, it will attempt to\n * refresh the token using the provided auth client.\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - The number of seconds before the token expiration to refresh the session. If the token is still valid for this duration, it will not be refreshed. Set to 0 to force the refresh.\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n */\nexport const refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n try {\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n try {\n // we retry the refresh token in case of transient error\n // or race conditions\n console.warn(\"error refreshing session, retrying:\", error);\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n const errResponse = error as FetchResponse<ErrorResponse>;\n if (errResponse?.status === 401) {\n // this probably means the refresh token is invalid\n console.error(\"session probably expired\");\n storage.remove();\n }\n return null;\n }\n }\n};\n\n/**\n * Internal implementation of the refresh session logic\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n * @private\n */\nconst _refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n const {\n session,\n needsRefresh,\n }: { session: Session | null; needsRefresh: boolean } = await lock.request(\n \"nhostSessionLock\",\n { mode: \"shared\" },\n async () => {\n return _needsRefresh(storage, marginSeconds);\n },\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n const refreshedSession: Session | null = await lock.request(\n \"nhostSessionLock\",\n { mode: \"exclusive\" },\n async () => {\n const { session, needsRefresh, sessionExpired } = _needsRefresh(\n storage,\n marginSeconds,\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n try {\n const response = await auth.refreshToken({\n refreshToken: session.refreshToken,\n });\n storage.set(response.body);\n\n return response.body;\n } catch (error) {\n if (!sessionExpired) {\n return session;\n }\n\n throw error;\n }\n },\n );\n\n return refreshedSession;\n};\n\n/**\n * Checks if the current session needs to be refreshed based on token expiration\n *\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns An object containing the session, whether it needs refreshing, and whether it has expired\n * @private\n */\nconst _needsRefresh = (storage: SessionStorage, marginSeconds = 60) => {\n const session = storage.get();\n if (!session) {\n return { session: null, needsRefresh: false, sessionExpired: false };\n }\n\n if (!session.decodedToken || !session.decodedToken.exp) {\n // if the session does not have a valid decoded token, treat it as expired\n // as we can't determine its validity\n return { session, needsRefresh: true, sessionExpired: true };\n }\n\n // Force refresh if marginSeconds is 0\n if (marginSeconds === 0) {\n return { session, needsRefresh: true, sessionExpired: false };\n }\n\n const currentTime = Date.now();\n if (session.decodedToken.exp - currentTime > marginSeconds * 1000) {\n return { session, needsRefresh: false, sessionExpired: false };\n }\n\n return {\n session,\n needsRefresh: true,\n sessionExpired: session.decodedToken.exp < currentTime,\n };\n};\n"],"names":["lock","navigator","locks","request","_name","_options","callback","_refreshSession","async","auth","storage","marginSeconds","session","needsRefresh","mode","_needsRefresh","sessionExpired","response","refreshToken","set","body","error","get","decodedToken","exp","currentTime","Date","now","console","warn","errResponse","status","remove"],"mappings":"aA0BA,MAAMA,EAEiB,oBAAdC,WAA6BA,UAAUC,MAC1CD,UAAUC,MACV,IAzBN,MACE,aAAMC,CACJC,EACAC,EAEAC,GAEA,OAAOA,GACT,GAiEIC,EAAkBC,MACtBC,EACAC,EACAC,EAAgB,MAEhB,MAAMC,QACJA,EAAAC,aACAA,SAC4Db,EAAKG,QACjE,mBACA,CAAEW,KAAM,WACRN,SACSO,EAAcL,EAASC,KAIlC,IAAKC,EACH,OAAO,KAGT,IAAKC,EACH,OAAOD,EAqCT,aAlC+CZ,EAAKG,QAClD,mBACA,CAAEW,KAAM,cACRN,UACE,MAAQI,QAAAA,EAASC,aAAAA,EAAAA,eAAcG,GAAmBD,EAChDL,EACAC,GAGF,IAAKC,EACH,OAAO,KAGT,IAAKC,EACH,OAAOD,EAGT,IACE,MAAMK,QAAiBR,EAAKS,aAAa,CACvCA,aAAcN,EAAQM,eAIxB,OAFAR,EAAQS,IAAIF,EAASG,MAEdH,EAASG,IAClB,OAASC,GACP,IAAKL,EACH,OAAOJ,EAGT,MAAMS,CACR,IAIG,EAWHN,EAAgB,CAACL,EAAyBC,EAAgB,MAC9D,MAAMC,EAAUF,EAAQY,MACxB,IAAKV,EACH,MAAO,CAAEA,QAAS,KAAMC,cAAc,EAAOG,gBAAgB,GAG/D,IAAKJ,EAAQW,eAAiBX,EAAQW,aAAaC,IAGjD,MAAO,CAAEZ,UAASC,cAAc,EAAMG,gBAAgB,GAIxD,GAAsB,IAAlBL,EACF,MAAO,CAAEC,UAASC,cAAc,EAAMG,gBAAgB,GAGxD,MAAMS,EAAcC,KAAKC,MACzB,OAAIf,EAAQW,aAAaC,IAAMC,EAA8B,IAAhBd,EACpC,CAAEC,UAASC,cAAc,EAAOG,gBAAgB,GAGlD,CACLJ,UACAC,cAAc,EACdG,eAAgBJ,EAAQW,aAAaC,IAAMC,EAAA,yBAhIjBjB,MAC5BC,EACAC,EACAC,EAAgB,MAEhB,IACE,aAAaJ,EAAgBE,EAAMC,EAASC,EAC9C,OAASU,GACP,IAIE,OADAO,QAAQC,KAAK,sCAAuCR,SACvCd,EAAgBE,EAAMC,EAASC,EAC9C,OAASU,GACP,MAAMS,EAAcT,EAMpB,OAL4B,MAAxBS,GAAaC,SAEfH,QAAQP,MAAM,4BACdX,EAAQsB,UAEH,IACT,CACF"}
1
+ {"version":3,"file":"refreshSession-Bw715ZmX.cjs","sources":["../src/session/refreshSession.ts"],"sourcesContent":["import type { Client as AuthClient, ErrorResponse } from '../auth';\nimport type { FetchResponse } from '../fetch';\nimport type { Session } from './session';\nimport type { SessionStorage } from './storage';\n\nclass DummyLock implements Lock {\n async request(\n _name: string,\n _options: { mode: 'exclusive' | 'shared' },\n // biome-ignore lint/suspicious/noExplicitAny: any\n callback: () => Promise<any>,\n ) {\n return callback();\n }\n}\n\ninterface Lock {\n request: (\n name: string,\n options: { mode: 'exclusive' | 'shared' },\n // biome-ignore lint/suspicious/noExplicitAny: blah\n callback: () => Promise<any>,\n // biome-ignore lint/suspicious/noExplicitAny: blah\n ) => Promise<any>;\n}\n\nconst lock: Lock =\n typeof navigator !== 'undefined' && navigator.locks\n ? navigator.locks\n : new DummyLock();\n\n/**\n * Refreshes the authentication session if needed\n *\n * This function checks if the current session needs to be refreshed based on\n * the access token expiration time. If a refresh is needed, it will attempt to\n * refresh the token using the provided auth client.\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - The number of seconds before the token expiration to refresh the session. If the token is still valid for this duration, it will not be refreshed. Set to 0 to force the refresh.\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n */\nexport const refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n try {\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n try {\n // we retry the refresh token in case of transient error\n // or race conditions\n console.warn('error refreshing session, retrying:', error);\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n const errResponse = error as FetchResponse<ErrorResponse>;\n if (errResponse?.status === 401) {\n // this probably means the refresh token is invalid\n console.error('session probably expired');\n storage.remove();\n }\n return null;\n }\n }\n};\n\n/**\n * Internal implementation of the refresh session logic\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n * @private\n */\nconst _refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n const {\n session,\n needsRefresh,\n }: { session: Session | null; needsRefresh: boolean } = await lock.request(\n 'nhostSessionLock',\n { mode: 'shared' },\n async () => {\n return _needsRefresh(storage, marginSeconds);\n },\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n const refreshedSession: Session | null = await lock.request(\n 'nhostSessionLock',\n { mode: 'exclusive' },\n async () => {\n const { session, needsRefresh, sessionExpired } = _needsRefresh(\n storage,\n marginSeconds,\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n try {\n const response = await auth.refreshToken({\n refreshToken: session.refreshToken,\n });\n storage.set(response.body);\n\n return response.body;\n } catch (error) {\n if (!sessionExpired) {\n return session;\n }\n\n throw error;\n }\n },\n );\n\n return refreshedSession;\n};\n\n/**\n * Checks if the current session needs to be refreshed based on token expiration\n *\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns An object containing the session, whether it needs refreshing, and whether it has expired\n * @private\n */\nconst _needsRefresh = (storage: SessionStorage, marginSeconds = 60) => {\n const session = storage.get();\n if (!session) {\n return { session: null, needsRefresh: false, sessionExpired: false };\n }\n\n if (!session.decodedToken || !session.decodedToken.exp) {\n // if the session does not have a valid decoded token, treat it as expired\n // as we can't determine its validity\n return { session, needsRefresh: true, sessionExpired: true };\n }\n\n // Force refresh if marginSeconds is 0\n if (marginSeconds === 0) {\n return { session, needsRefresh: true, sessionExpired: false };\n }\n\n const currentTime = Date.now();\n if (session.decodedToken.exp - currentTime > marginSeconds * 1000) {\n return { session, needsRefresh: false, sessionExpired: false };\n }\n\n return {\n session,\n needsRefresh: true,\n sessionExpired: session.decodedToken.exp < currentTime,\n };\n};\n"],"names":["lock","navigator","locks","request","_name","_options","callback","_refreshSession","async","auth","storage","marginSeconds","session","needsRefresh","mode","_needsRefresh","sessionExpired","response","refreshToken","set","body","error","get","decodedToken","exp","currentTime","Date","now","console","warn","errResponse","status","remove"],"mappings":"aA0BA,MAAMA,EACiB,oBAAdC,WAA6BA,UAAUC,MAC1CD,UAAUC,MACV,IAxBN,MACE,aAAMC,CACJC,EACAC,EAEAC,GAEA,OAAOA,GACT,GAgEIC,EAAkBC,MACtBC,EACAC,EACAC,EAAgB,MAEhB,MAAMC,QACJA,EAAAC,aACAA,SAC4Db,EAAKG,QACjE,mBACA,CAAEW,KAAM,WACRN,SACSO,EAAcL,EAASC,KAIlC,IAAKC,EACH,OAAO,KAGT,IAAKC,EACH,OAAOD,EAqCT,aAlC+CZ,EAAKG,QAClD,mBACA,CAAEW,KAAM,cACRN,UACE,MAAQI,QAAAA,EAASC,aAAAA,EAAAA,eAAcG,GAAmBD,EAChDL,EACAC,GAGF,IAAKC,EACH,OAAO,KAGT,IAAKC,EACH,OAAOD,EAGT,IACE,MAAMK,QAAiBR,EAAKS,aAAa,CACvCA,aAAcN,EAAQM,eAIxB,OAFAR,EAAQS,IAAIF,EAASG,MAEdH,EAASG,IAClB,OAASC,GACP,IAAKL,EACH,OAAOJ,EAGT,MAAMS,CACR,IAIG,EAWHN,EAAgB,CAACL,EAAyBC,EAAgB,MAC9D,MAAMC,EAAUF,EAAQY,MACxB,IAAKV,EACH,MAAO,CAAEA,QAAS,KAAMC,cAAc,EAAOG,gBAAgB,GAG/D,IAAKJ,EAAQW,eAAiBX,EAAQW,aAAaC,IAGjD,MAAO,CAAEZ,UAASC,cAAc,EAAMG,gBAAgB,GAIxD,GAAsB,IAAlBL,EACF,MAAO,CAAEC,UAASC,cAAc,EAAMG,gBAAgB,GAGxD,MAAMS,EAAcC,KAAKC,MACzB,OAAIf,EAAQW,aAAaC,IAAMC,EAA8B,IAAhBd,EACpC,CAAEC,UAASC,cAAc,EAAOG,gBAAgB,GAGlD,CACLJ,UACAC,cAAc,EACdG,eAAgBJ,EAAQW,aAAaC,IAAMC,EAAA,yBAhIjBjB,MAC5BC,EACAC,EACAC,EAAgB,MAEhB,IACE,aAAaJ,EAAgBE,EAAMC,EAASC,EAC9C,OAASU,GACP,IAIE,OADAO,QAAQC,KAAK,sCAAuCR,SACvCd,EAAgBE,EAAMC,EAASC,EAC9C,OAASU,GACP,MAAMS,EAAcT,EAMpB,OAL4B,MAAxBS,GAAaC,SAEfH,QAAQP,MAAM,4BACdX,EAAQsB,UAEH,IACT,CACF"}
@@ -3,10 +3,7 @@ class DummyLock {
3
3
  return callback();
4
4
  }
5
5
  }
6
- const lock = (
7
- // biome-ignore lint/complexity/useOptionalChain: this check breaks non-browser environments
8
- typeof navigator !== "undefined" && navigator.locks ? navigator.locks : new DummyLock()
9
- );
6
+ const lock = typeof navigator !== "undefined" && navigator.locks ? navigator.locks : new DummyLock();
10
7
  const refreshSession = async (auth, storage, marginSeconds = 60) => {
11
8
  try {
12
9
  return await _refreshSession(auth, storage, marginSeconds);
@@ -95,4 +92,4 @@ const _needsRefresh = (storage, marginSeconds = 60) => {
95
92
  export {
96
93
  refreshSession as r
97
94
  };
98
- //# sourceMappingURL=refreshSession-CG8GIEun.js.map
95
+ //# sourceMappingURL=refreshSession-WwGlzgtM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refreshSession-WwGlzgtM.js","sources":["../src/session/refreshSession.ts"],"sourcesContent":["import type { Client as AuthClient, ErrorResponse } from '../auth';\nimport type { FetchResponse } from '../fetch';\nimport type { Session } from './session';\nimport type { SessionStorage } from './storage';\n\nclass DummyLock implements Lock {\n async request(\n _name: string,\n _options: { mode: 'exclusive' | 'shared' },\n // biome-ignore lint/suspicious/noExplicitAny: any\n callback: () => Promise<any>,\n ) {\n return callback();\n }\n}\n\ninterface Lock {\n request: (\n name: string,\n options: { mode: 'exclusive' | 'shared' },\n // biome-ignore lint/suspicious/noExplicitAny: blah\n callback: () => Promise<any>,\n // biome-ignore lint/suspicious/noExplicitAny: blah\n ) => Promise<any>;\n}\n\nconst lock: Lock =\n typeof navigator !== 'undefined' && navigator.locks\n ? navigator.locks\n : new DummyLock();\n\n/**\n * Refreshes the authentication session if needed\n *\n * This function checks if the current session needs to be refreshed based on\n * the access token expiration time. If a refresh is needed, it will attempt to\n * refresh the token using the provided auth client.\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - The number of seconds before the token expiration to refresh the session. If the token is still valid for this duration, it will not be refreshed. Set to 0 to force the refresh.\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n */\nexport const refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n try {\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n try {\n // we retry the refresh token in case of transient error\n // or race conditions\n console.warn('error refreshing session, retrying:', error);\n return await _refreshSession(auth, storage, marginSeconds);\n } catch (error) {\n const errResponse = error as FetchResponse<ErrorResponse>;\n if (errResponse?.status === 401) {\n // this probably means the refresh token is invalid\n console.error('session probably expired');\n storage.remove();\n }\n return null;\n }\n }\n};\n\n/**\n * Internal implementation of the refresh session logic\n *\n * @param auth - The authentication client to use for token refresh\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns A promise that resolves to the current session (refreshed if needed) or null if no session exists\n * @private\n */\nconst _refreshSession = async (\n auth: AuthClient,\n storage: SessionStorage,\n marginSeconds = 60,\n): Promise<Session | null> => {\n const {\n session,\n needsRefresh,\n }: { session: Session | null; needsRefresh: boolean } = await lock.request(\n 'nhostSessionLock',\n { mode: 'shared' },\n async () => {\n return _needsRefresh(storage, marginSeconds);\n },\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n const refreshedSession: Session | null = await lock.request(\n 'nhostSessionLock',\n { mode: 'exclusive' },\n async () => {\n const { session, needsRefresh, sessionExpired } = _needsRefresh(\n storage,\n marginSeconds,\n );\n\n if (!session) {\n return null; // No session found\n }\n\n if (!needsRefresh) {\n return session; // No need to refresh\n }\n\n try {\n const response = await auth.refreshToken({\n refreshToken: session.refreshToken,\n });\n storage.set(response.body);\n\n return response.body;\n } catch (error) {\n if (!sessionExpired) {\n return session;\n }\n\n throw error;\n }\n },\n );\n\n return refreshedSession;\n};\n\n/**\n * Checks if the current session needs to be refreshed based on token expiration\n *\n * @param storage - The session storage implementation\n * @param marginSeconds - How many seconds before expiration to trigger a refresh\n * @returns An object containing the session, whether it needs refreshing, and whether it has expired\n * @private\n */\nconst _needsRefresh = (storage: SessionStorage, marginSeconds = 60) => {\n const session = storage.get();\n if (!session) {\n return { session: null, needsRefresh: false, sessionExpired: false };\n }\n\n if (!session.decodedToken || !session.decodedToken.exp) {\n // if the session does not have a valid decoded token, treat it as expired\n // as we can't determine its validity\n return { session, needsRefresh: true, sessionExpired: true };\n }\n\n // Force refresh if marginSeconds is 0\n if (marginSeconds === 0) {\n return { session, needsRefresh: true, sessionExpired: false };\n }\n\n const currentTime = Date.now();\n if (session.decodedToken.exp - currentTime > marginSeconds * 1000) {\n return { session, needsRefresh: false, sessionExpired: false };\n }\n\n return {\n session,\n needsRefresh: true,\n sessionExpired: session.decodedToken.exp < currentTime,\n };\n};\n"],"names":["error","session","needsRefresh"],"mappings":"AAKA,MAAM,UAA0B;AAAA,EAC9B,MAAM,QACJ,OACA,UAEA,UACA;AACA,WAAO,SAAA;AAAA,EACT;AACF;AAYA,MAAM,OACJ,OAAO,cAAc,eAAe,UAAU,QAC1C,UAAU,QACV,IAAI,UAAA;AAcH,MAAM,iBAAiB,OAC5B,MACA,SACA,gBAAgB,OACY;AAC5B,MAAI;AACF,WAAO,MAAM,gBAAgB,MAAM,SAAS,aAAa;AAAA,EAC3D,SAAS,OAAO;AACd,QAAI;AAGF,cAAQ,KAAK,uCAAuC,KAAK;AACzD,aAAO,MAAM,gBAAgB,MAAM,SAAS,aAAa;AAAA,IAC3D,SAASA,QAAO;AACd,YAAM,cAAcA;AACpB,UAAI,aAAa,WAAW,KAAK;AAE/B,gBAAQ,MAAM,0BAA0B;AACxC,gBAAQ,OAAA;AAAA,MACV;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAWA,MAAM,kBAAkB,OACtB,MACA,SACA,gBAAgB,OACY;AAC5B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EAAA,IACsD,MAAM,KAAK;AAAA,IACjE;AAAA,IACA,EAAE,MAAM,SAAA;AAAA,IACR,YAAY;AACV,aAAO,cAAc,SAAS,aAAa;AAAA,IAC7C;AAAA,EAAA;AAGF,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmC,MAAM,KAAK;AAAA,IAClD;AAAA,IACA,EAAE,MAAM,YAAA;AAAA,IACR,YAAY;AACV,YAAM,EAAE,SAAAC,UAAS,cAAAC,eAAc,mBAAmB;AAAA,QAChD;AAAA,QACA;AAAA,MAAA;AAGF,UAAI,CAACD,UAAS;AACZ,eAAO;AAAA,MACT;AAEA,UAAI,CAACC,eAAc;AACjB,eAAOD;AAAAA,MACT;AAEA,UAAI;AACF,cAAM,WAAW,MAAM,KAAK,aAAa;AAAA,UACvC,cAAcA,SAAQ;AAAA,QAAA,CACvB;AACD,gBAAQ,IAAI,SAAS,IAAI;AAEzB,eAAO,SAAS;AAAA,MAClB,SAAS,OAAO;AACd,YAAI,CAAC,gBAAgB;AACnB,iBAAOA;AAAAA,QACT;AAEA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGF,SAAO;AACT;AAUA,MAAM,gBAAgB,CAAC,SAAyB,gBAAgB,OAAO;AACrE,QAAM,UAAU,QAAQ,IAAA;AACxB,MAAI,CAAC,SAAS;AACZ,WAAO,EAAE,SAAS,MAAM,cAAc,OAAO,gBAAgB,MAAA;AAAA,EAC/D;AAEA,MAAI,CAAC,QAAQ,gBAAgB,CAAC,QAAQ,aAAa,KAAK;AAGtD,WAAO,EAAE,SAAS,cAAc,MAAM,gBAAgB,KAAA;AAAA,EACxD;AAGA,MAAI,kBAAkB,GAAG;AACvB,WAAO,EAAE,SAAS,cAAc,MAAM,gBAAgB,MAAA;AAAA,EACxD;AAEA,QAAM,cAAc,KAAK,IAAA;AACzB,MAAI,QAAQ,aAAa,MAAM,cAAc,gBAAgB,KAAM;AACjE,WAAO,EAAE,SAAS,cAAc,OAAO,gBAAgB,MAAA;AAAA,EACzD;AAEA,SAAO;AAAA,IACL;AAAA,IACA,cAAc;AAAA,IACd,gBAAgB,QAAQ,aAAa,MAAM;AAAA,EAAA;AAE/C;"}
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * This file is auto-generated. Do not edit manually.
3
3
  */
4
- import type { ChainFunction, FetchResponse } from "../fetch";
4
+ import type { ChainFunction, FetchResponse } from '../fetch';
5
5
  /**
6
6
  * The attestation statement format
7
7
  */
8
- export type AttestationFormat = "packed" | "tpm" | "android-key" | "android-safetynet" | "fido-u2f" | "apple" | "none";
8
+ export type AttestationFormat = 'packed' | 'tpm' | 'android-key' | 'android-safetynet' | 'fido-u2f' | 'apple' | 'none';
9
9
  /**
10
10
  * Map of extension outputs from the client
11
11
  @property appid? (`boolean`) - Application identifier extension output
@@ -52,7 +52,7 @@ export interface AuthenticatorAssertionResponse {
52
52
  /**
53
53
  * The authenticator attachment modality
54
54
  */
55
- export type AuthenticatorAttachment = "platform" | "cross-platform";
55
+ export type AuthenticatorAttachment = 'platform' | 'cross-platform';
56
56
  /**
57
57
  *
58
58
  @property clientDataJSON (`string`) - Base64url-encoded binary data
@@ -124,11 +124,11 @@ export interface AuthenticatorSelection {
124
124
  /**
125
125
  * The authenticator transports that can be used
126
126
  */
127
- export type AuthenticatorTransport = "usb" | "nfc" | "ble" | "smart-card" | "hybrid" | "internal";
127
+ export type AuthenticatorTransport = 'usb' | 'nfc' | 'ble' | 'smart-card' | 'hybrid' | 'internal';
128
128
  /**
129
129
  * The attestation conveyance preference
130
130
  */
131
- export type ConveyancePreference = "none" | "indirect" | "direct" | "enterprise";
131
+ export type ConveyancePreference = 'none' | 'indirect' | 'direct' | 'enterprise';
132
132
  /**
133
133
  *
134
134
  @property expiresAt (`string`) - Expiration date of the PAT
@@ -267,11 +267,11 @@ export interface CredentialPropertiesOutput {
267
267
  /**
268
268
  * The valid credential types
269
269
  */
270
- export type CredentialType = "public-key";
270
+ export type CredentialType = 'public-key';
271
271
  /**
272
272
  * Error code identifying the specific application error
273
273
  */
274
- export type ErrorResponseError = "default-role-must-be-in-allowed-roles" | "disabled-endpoint" | "disabled-user" | "email-already-in-use" | "email-already-verified" | "forbidden-anonymous" | "internal-server-error" | "invalid-email-password" | "invalid-request" | "locale-not-allowed" | "password-too-short" | "password-in-hibp-database" | "redirectTo-not-allowed" | "role-not-allowed" | "signup-disabled" | "unverified-user" | "user-not-anonymous" | "invalid-pat" | "invalid-refresh-token" | "invalid-ticket" | "disabled-mfa-totp" | "no-totp-secret" | "invalid-totp" | "mfa-type-not-found" | "totp-already-active" | "invalid-state" | "oauth-token-echange-failed" | "oauth-profile-fetch-failed" | "oauth-provider-error" | "invalid-otp" | "cannot-send-sms" | "provider-account-already-linked";
274
+ export type ErrorResponseError = 'default-role-must-be-in-allowed-roles' | 'disabled-endpoint' | 'disabled-user' | 'email-already-in-use' | 'email-already-verified' | 'forbidden-anonymous' | 'internal-server-error' | 'invalid-email-password' | 'invalid-request' | 'locale-not-allowed' | 'password-too-short' | 'password-in-hibp-database' | 'redirectTo-not-allowed' | 'role-not-allowed' | 'signup-disabled' | 'unverified-user' | 'user-not-anonymous' | 'invalid-pat' | 'invalid-refresh-token' | 'invalid-ticket' | 'disabled-mfa-totp' | 'no-totp-secret' | 'invalid-totp' | 'mfa-type-not-found' | 'totp-already-active' | 'invalid-state' | 'oauth-token-echange-failed' | 'oauth-profile-fetch-failed' | 'oauth-provider-error' | 'invalid-otp' | 'cannot-send-sms' | 'provider-account-already-linked';
275
275
  /**
276
276
  * Standardized error response
277
277
  @property status (`number`) - HTTP status error code
@@ -298,7 +298,7 @@ export interface ErrorResponse {
298
298
  /**
299
299
  *
300
300
  */
301
- export type IdTokenProvider = "apple" | "google";
301
+ export type IdTokenProvider = 'apple' | 'google';
302
302
  /**
303
303
  * JSON Web Key for JWT verification
304
304
  @property alg (`string`) - Algorithm used with this key
@@ -387,7 +387,7 @@ export interface MFAChallengePayload {
387
387
  /**
388
388
  *
389
389
  */
390
- export type OKResponse = "OK";
390
+ export type OKResponse = 'OK';
391
391
  /**
392
392
  *
393
393
  @property redirectTo? (`string`) -
@@ -486,7 +486,7 @@ export interface PublicKeyCredentialDescriptor {
486
486
  /**
487
487
  * Hints to help guide the user through the experience
488
488
  */
489
- export type PublicKeyCredentialHints = "security-key" | "client-device" | "hybrid";
489
+ export type PublicKeyCredentialHints = 'security-key' | 'client-device' | 'hybrid';
490
490
  /**
491
491
  *
492
492
  @property challenge (`string`) - Base64url-encoded binary data
@@ -617,7 +617,7 @@ export interface RelyingPartyEntity {
617
617
  /**
618
618
  * The resident key requirement
619
619
  */
620
- export type ResidentKeyRequirement = "discouraged" | "preferred" | "required";
620
+ export type ResidentKeyRequirement = 'discouraged' | 'preferred' | 'required';
621
621
  /**
622
622
  * User authentication session containing tokens and user information
623
623
  @property accessToken (`string`) - JWT token for authenticating API requests
@@ -674,10 +674,10 @@ export interface SessionPayload {
674
674
  *
675
675
  @property displayName? (`string`) -
676
676
  * Example - `"John Smith"`
677
- @property locale? (`string`) - A two-characters locale
677
+ @property locale? (`string`) - A two or three characters locale
678
678
  * Example - `"en"`
679
679
  * MinLength - 2
680
- * MaxLength - 2
680
+ * MaxLength - 3
681
681
  @property metadata? (`Record<string, unknown>`) -
682
682
  * Example - `{"firstName":"John","lastName":"Smith"}`*/
683
683
  export interface SignInAnonymousRequest {
@@ -687,10 +687,10 @@ export interface SignInAnonymousRequest {
687
687
  */
688
688
  displayName?: string;
689
689
  /**
690
- * A two-characters locale
690
+ * A two or three characters locale
691
691
  * Example - `"en"`
692
692
  * MinLength - 2
693
- * MaxLength - 2
693
+ * MaxLength - 3
694
694
  */
695
695
  locale?: string;
696
696
  /**
@@ -983,10 +983,10 @@ export interface SignUpEmailPasswordRequest {
983
983
  * Example - `"John Smith"`
984
984
  * Pattern - ^[\p{L}\p{N}\p{S} ,.'-]+$
985
985
  * MaxLength - 32
986
- @property locale? (`string`) - A two-characters locale
986
+ @property locale? (`string`) - A two or three characters locale
987
987
  * Example - `"en"`
988
988
  * MinLength - 2
989
- * MaxLength - 2
989
+ * MaxLength - 3
990
990
  @property metadata? (`Record<string, unknown>`) -
991
991
  * Example - `{"firstName":"John","lastName":"Smith"}`
992
992
  @property redirectTo? (`string`) -
@@ -1011,10 +1011,10 @@ export interface SignUpOptions {
1011
1011
  */
1012
1012
  displayName?: string;
1013
1013
  /**
1014
- * A two-characters locale
1014
+ * A two or three characters locale
1015
1015
  * Example - `"en"`
1016
1016
  * MinLength - 2
1017
- * MaxLength - 2
1017
+ * MaxLength - 3
1018
1018
  */
1019
1019
  locale?: string;
1020
1020
  /**
@@ -1112,7 +1112,7 @@ export type URLEncodedBase64 = string;
1112
1112
  @property locale (`string`) - User's preferred locale (language code)
1113
1113
  * Example - `"en"`
1114
1114
  * MinLength - 2
1115
- * MaxLength - 2
1115
+ * MaxLength - 3
1116
1116
  @property metadata (`Record<string, unknown>`) - Custom metadata associated with the user
1117
1117
  * Example - `{"firstName":"John","lastName":"Smith"}`
1118
1118
  @property phoneNumber? (`string`) - User's phone number
@@ -1170,7 +1170,7 @@ export interface User {
1170
1170
  * User's preferred locale (language code)
1171
1171
  * Example - `"en"`
1172
1172
  * MinLength - 2
1173
- * MaxLength - 2
1173
+ * MaxLength - 3
1174
1174
  */
1175
1175
  locale: string;
1176
1176
  /**
@@ -1201,7 +1201,7 @@ export interface User {
1201
1201
  /**
1202
1202
  * Which sign-in method to use
1203
1203
  */
1204
- export type UserDeanonymizeRequestSignInMethod = "email-password" | "passwordless";
1204
+ export type UserDeanonymizeRequestSignInMethod = 'email-password' | 'passwordless';
1205
1205
  /**
1206
1206
  *
1207
1207
  @property signInMethod (`UserDeanonymizeRequestSignInMethod`) - Which sign-in method to use
@@ -1299,7 +1299,7 @@ export interface UserEntity {
1299
1299
  /**
1300
1300
  * Type of MFA to activate. Use empty string to disable MFA.
1301
1301
  */
1302
- export type UserMfaRequestActiveMfaType = "totp" | "";
1302
+ export type UserMfaRequestActiveMfaType = 'totp' | '';
1303
1303
  /**
1304
1304
  * Request to activate or deactivate multi-factor authentication
1305
1305
  @property code (`string`) - Verification code from the authenticator app when activating MFA
@@ -1361,7 +1361,7 @@ export interface UserPasswordResetRequest {
1361
1361
  /**
1362
1362
  * A requirement for user verification for the operation
1363
1363
  */
1364
- export type UserVerificationRequirement = "required" | "preferred" | "discouraged";
1364
+ export type UserVerificationRequirement = 'required' | 'preferred' | 'discouraged';
1365
1365
  /**
1366
1366
  *
1367
1367
  @property credential (`CredentialCreationResponse`) -
@@ -1408,7 +1408,7 @@ export type RedirectToQuery = string;
1408
1408
  /**
1409
1409
  *
1410
1410
  */
1411
- export type SignInProvider = "apple" | "github" | "google" | "linkedin" | "discord" | "spotify" | "twitch" | "gitlab" | "bitbucket" | "workos" | "azuread" | "entraid" | "strava" | "facebook" | "windowslive" | "twitter";
1411
+ export type SignInProvider = 'apple' | 'github' | 'google' | 'linkedin' | 'discord' | 'spotify' | 'twitch' | 'gitlab' | 'bitbucket' | 'workos' | 'azuread' | 'entraid' | 'strava' | 'facebook' | 'windowslive' | 'twitter';
1412
1412
  /**
1413
1413
  * Ticket
1414
1414
  */
@@ -1416,7 +1416,7 @@ export type TicketQuery = string;
1416
1416
  /**
1417
1417
  * Type of the ticket
1418
1418
  */
1419
- export type TicketTypeQuery = "emailVerify" | "emailConfirmChange" | "signinPasswordless" | "passwordReset";
1419
+ export type TicketTypeQuery = 'emailVerify' | 'emailConfirmChange' | 'signinPasswordless' | 'passwordReset';
1420
1420
  /**
1421
1421
  *
1422
1422
  @property version (`string`) - The version of the authentication service
@@ -1436,7 +1436,7 @@ export interface GetVersionResponse200 {
1436
1436
 
1437
1437
  @property displayName? (string) - Display name for the user
1438
1438
 
1439
- @property locale? (string) - A two-characters locale
1439
+ @property locale? (string) - A two or three characters locale
1440
1440
 
1441
1441
  @property metadata? (Record<string, unknown>) - Additional metadata for the user (JSON encoded string)
1442
1442
 
@@ -1465,7 +1465,7 @@ export interface SignInProviderParams {
1465
1465
  */
1466
1466
  displayName?: string;
1467
1467
  /**
1468
- * A two-characters locale
1468
+ * A two or three characters locale
1469
1469
 
1470
1470
  */
1471
1471
  locale?: string;