@strivacity/sdk-core 3.0.0-rc.0 → 3.0.1

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 (44) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +384 -79
  3. package/dist/flows/EmbeddedFlow.cjs +1 -1
  4. package/dist/flows/EmbeddedFlow.cjs.map +1 -1
  5. package/dist/flows/EmbeddedFlow.d.ts +2 -1
  6. package/dist/flows/EmbeddedFlow.mjs +1 -1
  7. package/dist/flows/EmbeddedFlow.mjs.map +1 -1
  8. package/dist/flows/NativeFlow.cjs +1 -1
  9. package/dist/flows/NativeFlow.cjs.map +1 -1
  10. package/dist/flows/NativeFlow.d.ts +1 -1
  11. package/dist/flows/NativeFlow.mjs +1 -1
  12. package/dist/flows/NativeFlow.mjs.map +1 -1
  13. package/dist/handlers/BaseFlowHandler.cjs +2 -0
  14. package/dist/handlers/BaseFlowHandler.cjs.map +1 -0
  15. package/dist/{utils/NativeFlowHandler.d.ts → handlers/BaseFlowHandler.d.ts} +11 -12
  16. package/dist/handlers/BaseFlowHandler.mjs +2 -0
  17. package/dist/handlers/BaseFlowHandler.mjs.map +1 -0
  18. package/dist/handlers/EmbeddedFlowHandler.cjs +2 -0
  19. package/dist/handlers/EmbeddedFlowHandler.cjs.map +1 -0
  20. package/dist/{utils → handlers}/EmbeddedFlowHandler.d.ts +3 -35
  21. package/dist/handlers/EmbeddedFlowHandler.mjs +2 -0
  22. package/dist/handlers/EmbeddedFlowHandler.mjs.map +1 -0
  23. package/dist/handlers/NativeFlowHandler.cjs +2 -0
  24. package/dist/handlers/NativeFlowHandler.cjs.map +1 -0
  25. package/dist/handlers/NativeFlowHandler.d.ts +30 -0
  26. package/dist/handlers/NativeFlowHandler.mjs +2 -0
  27. package/dist/handlers/NativeFlowHandler.mjs.map +1 -0
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.ts +5 -2
  31. package/dist/index.mjs +1 -1
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/types.cjs.map +1 -1
  34. package/dist/types.d.ts +48 -56
  35. package/dist/types.mjs.map +1 -1
  36. package/package.json +7 -1
  37. package/dist/utils/EmbeddedFlowHandler.cjs +0 -2
  38. package/dist/utils/EmbeddedFlowHandler.cjs.map +0 -1
  39. package/dist/utils/EmbeddedFlowHandler.mjs +0 -2
  40. package/dist/utils/EmbeddedFlowHandler.mjs.map +0 -1
  41. package/dist/utils/NativeFlowHandler.cjs +0 -2
  42. package/dist/utils/NativeFlowHandler.cjs.map +0 -1
  43. package/dist/utils/NativeFlowHandler.mjs +0 -2
  44. package/dist/utils/NativeFlowHandler.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { SDKOptions, SDKStorage, SDKHttpClient, SDKLogging, ExtraRequestArgs } from '../types';
2
- import { EmbeddedFlowHandler } from '../utils/EmbeddedFlowHandler';
2
+ import { EmbeddedFlowHandler } from '../handlers/EmbeddedFlowHandler';
3
3
  import { BaseFlow } from './BaseFlow';
4
4
  export declare class EmbeddedFlow extends BaseFlow<SDKOptions, ExtraRequestArgs> {
5
5
  constructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging);
@@ -13,6 +13,7 @@ export declare class EmbeddedFlow extends BaseFlow<SDKOptions, ExtraRequestArgs>
13
13
  entry(url?: string): Promise<{
14
14
  session_id: string;
15
15
  short_app_id: string;
16
+ language: string;
16
17
  }>;
17
18
  /**
18
19
  * Handles the callback after login or registration via a redirect.
@@ -1,2 +1,2 @@
1
- import{redirectUrlHandler as d,redirectCallbackHandler as h}from"../utils/handlers.mjs";import{EmbeddedFlowHandler as p}from"../utils/EmbeddedFlowHandler.mjs";import{BaseFlow as g}from"./BaseFlow.mjs";import"../utils/errors.mjs";import"../utils/State.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";import"../utils/jwt.mjs";import"../utils/Metadata.mjs";import"../utils/Session.mjs";class U extends g{constructor(r,e,t,o){r.urlHandler||(r.urlHandler=d),r.callbackHandler||(r.callbackHandler=h),super(r,e,t,o),globalThis.sty||(globalThis.sty={}),globalThis.sty.oidcService=this}login(r={}){return this.dispatchEvent("loginInitiated",[]),new p(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web-embedded"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`);if(!t.ok){if(t.status===400){const i=await t.json();let n="Entry request failed with status 400";typeof i=="object"&&(i.error?n=`${i.error}: ${i.error_description}`:i.errorKey&&(n=i.errorKey));const c=new Error(n);throw this.logging?.error("Entry request error",c),c}const s=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",s),s}let o;try{o=new URL(await t.text())}catch{o=new URL(t.url)}const a=o.searchParams.get("short_app_id"),l=o.searchParams.get("session_id");if(!a){const s=new Error('"short_app_id" is missing from the response');throw this.logging?.error("Entry response error",s),s}if(!l){const s=new Error('"session_id" is missing from the response');throw this.logging?.error("Entry response error",s),s}return{session_id:l,short_app_id:a}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}export{U as EmbeddedFlow};
1
+ import{redirectUrlHandler as h,redirectCallbackHandler as p}from"../utils/handlers.mjs";import{EmbeddedFlowHandler as g}from"../handlers/EmbeddedFlowHandler.mjs";import{BaseFlow as m}from"./BaseFlow.mjs";import"../utils/errors.mjs";import"../handlers/BaseFlowHandler.mjs";import"../utils/State.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";import"../utils/jwt.mjs";import"../utils/Metadata.mjs";import"../utils/Session.mjs";class $ extends m{constructor(r,e,t,o){r.urlHandler||(r.urlHandler=h),r.callbackHandler||(r.callbackHandler=p),super(r,e,t,o),globalThis.sty||(globalThis.sty={}),globalThis.sty.oidcService=this}login(r={}){return this.dispatchEvent("loginInitiated",[]),new g(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web-embedded"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`,{headers:{"Accept-Language":"*"}});if(!t.ok){if(t.status===400){const i=await t.json();let n="Entry request failed with status 400";typeof i=="object"&&(i.error?n=`${i.error}: ${i.error_description}`:i.errorKey&&(n=i.errorKey));const c=new Error(n);throw this.logging?.error("Entry request error",c),c}const s=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",s),s}let o;try{o=new URL(await t.text())}catch{o=new URL(t.url)}const a=o.searchParams.get("short_app_id"),l=o.searchParams.get("session_id"),d=o.searchParams.get("language")||navigator.language;if(!a){const s=new Error('"short_app_id" is missing from the response');throw this.logging?.error("Entry response error",s),s}if(!l){const s=new Error('"session_id" is missing from the response');throw this.logging?.error("Entry response error",s),s}return{session_id:l,short_app_id:a,language:d}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}export{$ as EmbeddedFlow};
2
2
  //# sourceMappingURL=EmbeddedFlow.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EmbeddedFlow.mjs","sources":["../../src/flows/EmbeddedFlow.ts"],"sourcesContent":["import type { SDKOptions, SDKStorage, SDKHttpClient, SDKLogging, ExtraRequestArgs } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { EmbeddedFlowHandler } from '../utils/EmbeddedFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class EmbeddedFlow extends BaseFlow<SDKOptions, ExtraRequestArgs> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\n\t\tif (!globalThis.sty) {\n\t\t\tglobalThis.sty = {};\n\t\t}\n\n\t\t// NOTE: Register the OIDC service instance globally for use in the login component\n\t\tglobalThis.sty.oidcService = this;\n\t}\n\n\t/**\n\t * Initiates the login process via embedded UI.\n\t * @param {ExtraRequestArgs} [params={}] Optional parameters for the login request.\n\t * @returns {EmbeddedFlowHandler} Returns with an embedded login handler.\n\t */\n\toverride login(params: ExtraRequestArgs = {}): EmbeddedFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new EmbeddedFlowHandler(this, params);\n\t}\n\n\toverride register(params: ExtraRequestArgs = {}) {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\toverride async entry(url?: string) {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web-embedded');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst shortAppId = uri.searchParams.get('short_app_id');\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\n\t\tif (!shortAppId) {\n\t\t\tconst error = new Error('\"short_app_id\" is missing from the response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId, short_app_id: shortAppId };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["EmbeddedFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","EmbeddedFlowHandler","url","entryUrl","response","data","message","error","uri","shortAppId","sessionId"],"mappings":"yaAKO,MAAMA,UAAqBC,CAAuC,CACxE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,GAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,GAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,EAEtC,WAAW,MACf,WAAW,IAAM,CAAA,GAIlB,WAAW,IAAI,YAAc,IAC9B,CAOS,MAAMG,EAA2B,GAAyB,CAClE,YAAK,cAAc,iBAAkB,EAAE,EAEhC,IAAIC,EAAoB,KAAMD,CAAM,CAC5C,CAES,SAASA,EAA2B,GAAI,CAChD,OAAAA,EAAO,OAAS,SAET,KAAK,MAAMA,CAAM,CACzB,CAEA,MAAe,MAAME,EAAc,CAC7BA,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAMC,EAAW,IAAI,IAAID,CAAG,EAC5BC,EAAS,aAAa,OAAO,MAAO,cAAc,EAClDA,EAAS,aAAa,OAAO,YAAa,KAAK,QAAQ,QAAQ,EAC/DA,EAAS,aAAa,OAAO,eAAgB,KAAK,QAAQ,WAAW,EAErE,MAAMC,EAAW,MAAM,KAAK,WAAW,QACtC,GAAG,KAAK,QAAQ,MAAM,wBAAwBD,EAAS,aAAa,UAAU,EAAA,EAG/E,GAAI,CAACC,EAAS,GAAI,CACjB,GAAIA,EAAS,SAAW,IAAK,CAC5B,MAAMC,EAAO,MAAMD,EAAS,KAAA,EAC5B,IAAIE,EAAU,uCAEV,OAAOD,GAAS,WACfA,EAAK,MACRC,EAAU,GAAGD,EAAK,KAAK,KAAKA,EAAK,iBAAiB,GACxCA,EAAK,WACfC,EAAUD,EAAK,WAIjB,MAAME,EAAQ,IAAI,MAAMD,CAAO,EAC/B,WAAK,SAAS,MAAM,sBAAuBC,CAAK,EAC1CA,CACP,CAEA,MAAMA,EAAQ,IAAI,MAAM,oCAAoCH,EAAS,MAAM,EAAE,EAC7E,WAAK,SAAS,MAAM,sBAAuBG,CAAK,EAC1CA,CACP,CAEA,IAAIC,EAEJ,GAAI,CACHA,EAAM,IAAI,IAAI,MAAMJ,EAAS,MAAM,CACpC,MAAQ,CACPI,EAAM,IAAI,IAAIJ,EAAS,GAAG,CAC3B,CAEA,MAAMK,EAAaD,EAAI,aAAa,IAAI,cAAc,EAChDE,EAAYF,EAAI,aAAa,IAAI,YAAY,EAEnD,GAAI,CAACC,EAAY,CAChB,MAAMF,EAAQ,IAAI,MAAM,6CAA6C,EACrE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CACA,GAAI,CAACG,EAAW,CACf,MAAMH,EAAQ,IAAI,MAAM,2CAA2C,EACnE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CAEA,MAAO,CAAE,WAAYG,EAAW,aAAcD,CAAA,CAC/C,CASA,MAAM,eAAeP,EAA6B,CACjD,GAAI,OAAO,KAAK,QAAQ,iBAAoB,WAAY,CACvD,MAAMK,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,SAAS,MAAM,0BAA2BA,CAAK,EAC9CA,CACP,CAEKL,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAM,KAAK,cAAe,MAAM,KAAK,QAAQ,gBAAgBA,EAAK,KAAK,QAAQ,cAAgB,UAAU,CAA4B,CACtI,CACD"}
1
+ {"version":3,"file":"EmbeddedFlow.mjs","sources":["../../src/flows/EmbeddedFlow.ts"],"sourcesContent":["import type { SDKOptions, SDKStorage, SDKHttpClient, SDKLogging, ExtraRequestArgs } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { EmbeddedFlowHandler } from '../handlers/EmbeddedFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class EmbeddedFlow extends BaseFlow<SDKOptions, ExtraRequestArgs> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\n\t\tif (!globalThis.sty) {\n\t\t\tglobalThis.sty = {};\n\t\t}\n\n\t\t// NOTE: Register the OIDC service instance globally for use in the login component\n\t\tglobalThis.sty.oidcService = this;\n\t}\n\n\t/**\n\t * Initiates the login process via embedded UI.\n\t * @param {ExtraRequestArgs} [params={}] Optional parameters for the login request.\n\t * @returns {EmbeddedFlowHandler} Returns with an embedded login handler.\n\t */\n\toverride login(params: ExtraRequestArgs = {}): EmbeddedFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new EmbeddedFlowHandler(this, params);\n\t}\n\n\toverride register(params: ExtraRequestArgs = {}) {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\toverride async entry(url?: string) {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web-embedded');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Accept-Language': '*',\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst shortAppId = uri.searchParams.get('short_app_id');\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\t\tconst language = uri.searchParams.get('language') || navigator.language;\n\n\t\tif (!shortAppId) {\n\t\t\tconst error = new Error('\"short_app_id\" is missing from the response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId, short_app_id: shortAppId, language: language };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["EmbeddedFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","EmbeddedFlowHandler","url","entryUrl","response","data","message","error","uri","shortAppId","sessionId","language"],"mappings":"odAKO,MAAMA,UAAqBC,CAAuC,CACxE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,GAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,GAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,EAEtC,WAAW,MACf,WAAW,IAAM,CAAA,GAIlB,WAAW,IAAI,YAAc,IAC9B,CAOS,MAAMG,EAA2B,GAAyB,CAClE,YAAK,cAAc,iBAAkB,EAAE,EAEhC,IAAIC,EAAoB,KAAMD,CAAM,CAC5C,CAES,SAASA,EAA2B,GAAI,CAChD,OAAAA,EAAO,OAAS,SAET,KAAK,MAAMA,CAAM,CACzB,CAEA,MAAe,MAAME,EAAc,CAC7BA,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAMC,EAAW,IAAI,IAAID,CAAG,EAC5BC,EAAS,aAAa,OAAO,MAAO,cAAc,EAClDA,EAAS,aAAa,OAAO,YAAa,KAAK,QAAQ,QAAQ,EAC/DA,EAAS,aAAa,OAAO,eAAgB,KAAK,QAAQ,WAAW,EAErE,MAAMC,EAAW,MAAM,KAAK,WAAW,QACtC,GAAG,KAAK,QAAQ,MAAM,wBAAwBD,EAAS,aAAa,UAAU,GAC9E,CACC,QAAS,CACR,kBAAmB,GAAA,CACpB,CACD,EAGD,GAAI,CAACC,EAAS,GAAI,CACjB,GAAIA,EAAS,SAAW,IAAK,CAC5B,MAAMC,EAAO,MAAMD,EAAS,KAAA,EAC5B,IAAIE,EAAU,uCAEV,OAAOD,GAAS,WACfA,EAAK,MACRC,EAAU,GAAGD,EAAK,KAAK,KAAKA,EAAK,iBAAiB,GACxCA,EAAK,WACfC,EAAUD,EAAK,WAIjB,MAAME,EAAQ,IAAI,MAAMD,CAAO,EAC/B,WAAK,SAAS,MAAM,sBAAuBC,CAAK,EAC1CA,CACP,CAEA,MAAMA,EAAQ,IAAI,MAAM,oCAAoCH,EAAS,MAAM,EAAE,EAC7E,WAAK,SAAS,MAAM,sBAAuBG,CAAK,EAC1CA,CACP,CAEA,IAAIC,EAEJ,GAAI,CACHA,EAAM,IAAI,IAAI,MAAMJ,EAAS,MAAM,CACpC,MAAQ,CACPI,EAAM,IAAI,IAAIJ,EAAS,GAAG,CAC3B,CAEA,MAAMK,EAAaD,EAAI,aAAa,IAAI,cAAc,EAChDE,EAAYF,EAAI,aAAa,IAAI,YAAY,EAC7CG,EAAWH,EAAI,aAAa,IAAI,UAAU,GAAK,UAAU,SAE/D,GAAI,CAACC,EAAY,CAChB,MAAMF,EAAQ,IAAI,MAAM,6CAA6C,EACrE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CACA,GAAI,CAACG,EAAW,CACf,MAAMH,EAAQ,IAAI,MAAM,2CAA2C,EACnE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CAEA,MAAO,CAAE,WAAYG,EAAW,aAAcD,EAAY,SAAAE,CAAA,CAC3D,CASA,MAAM,eAAeT,EAA6B,CACjD,GAAI,OAAO,KAAK,QAAQ,iBAAoB,WAAY,CACvD,MAAMK,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,SAAS,MAAM,0BAA2BA,CAAK,EAC9CA,CACP,CAEKL,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAM,KAAK,cAAe,MAAM,KAAK,QAAQ,gBAAgBA,EAAK,KAAK,QAAQ,cAAgB,UAAU,CAA4B,CACtI,CACD"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../utils/handlers.cjs"),d=require("../utils/NativeFlowHandler.cjs"),h=require("./BaseFlow.cjs");require("../utils/errors.cjs");require("../utils/State.cjs");require("../utils/crypto.cjs");require("../utils/base64Url.cjs");require("../utils/date.cjs");require("../utils/jwt.cjs");require("../utils/Metadata.cjs");require("../utils/Session.cjs");class u extends h.BaseFlow{constructor(r,e,t,s){r.urlHandler||(r.urlHandler=c.redirectUrlHandler),r.callbackHandler||(r.callbackHandler=c.redirectCallbackHandler),super(r,e,t,s)}login(r={}){return this.dispatchEvent("loginInitiated",[]),new d.NativeFlowHandler(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`);if(!t.ok){if(t.status===400){const i=await t.json();let o="Entry request failed with status 400";typeof i=="object"&&(i.error?o=`${i.error}: ${i.error_description}`:i.errorKey&&(o=i.errorKey));const l=new Error(o);throw this.logging?.error("Entry request error",l),l}const n=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",n),n}let s;try{s=new URL(await t.text())}catch{s=new URL(t.url)}const a=s.searchParams.get("session_id");if(!a){const n=new Error("Session ID not found in entry response");throw this.logging?.error("Entry response error",n),n}return{session_id:a}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}exports.NativeFlow=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../utils/handlers.cjs"),h=require("../handlers/NativeFlowHandler.cjs"),u=require("./BaseFlow.cjs");require("../utils/errors.cjs");require("../handlers/BaseFlowHandler.cjs");require("../utils/State.cjs");require("../utils/crypto.cjs");require("../utils/base64Url.cjs");require("../utils/date.cjs");require("../utils/jwt.cjs");require("../utils/Metadata.cjs");require("../utils/Session.cjs");class g extends u.BaseFlow{constructor(r,e,t,i){r.urlHandler||(r.urlHandler=c.redirectUrlHandler),r.callbackHandler||(r.callbackHandler=c.redirectCallbackHandler),super(r,e,t,i)}login(r={}){return this.dispatchEvent("loginInitiated",[]),new h.NativeFlowHandler(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`,{headers:{"Accept-Language":"*"}});if(!t.ok){if(t.status===400){const s=await t.json();let a="Entry request failed with status 400";typeof s=="object"&&(s.error?a=`${s.error}: ${s.error_description}`:s.errorKey&&(a=s.errorKey));const l=new Error(a);throw this.logging?.error("Entry request error",l),l}const n=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",n),n}let i;try{i=new URL(await t.text())}catch{i=new URL(t.url)}const o=i.searchParams.get("session_id"),d=i.searchParams.get("language")||navigator.language;if(!o){const n=new Error("Session ID not found in entry response");throw this.logging?.error("Entry response error",n),n}return{session_id:o,language:d}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}exports.NativeFlow=g;
2
2
  //# sourceMappingURL=NativeFlow.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeFlow.cjs","sources":["../../src/flows/NativeFlow.ts"],"sourcesContent":["import type { SDKOptions, NativeParams, SDKStorage, SDKHttpClient, SDKLogging } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { NativeFlowHandler } from '../utils/NativeFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class NativeFlow extends BaseFlow<SDKOptions, NativeParams> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\t}\n\n\t/**\n\t * Initiates the login process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tlogin(params: NativeParams = {}): NativeFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new NativeFlowHandler(this, params);\n\t}\n\n\t/**\n\t * Initiates the registration process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tregister(params: NativeParams = {}): NativeFlowHandler {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\t/**\n\t * Initiates the entry process via a redirect.\n\t * @param {string} url Optional URL to use for the entry process. If not provided, the current window location will be used.\n\t * @returns {Promise<string>} A promise that resolves to the session ID.\n\t *\n\t * @throws {Error} Throws an error if the entry request fails or session ID is not found.\n\t */\n\tasync entry(url?: string): Promise<Record<string, string>> {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('Session ID not found in entry response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["NativeFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","NativeFlowHandler","url","entryUrl","response","data","message","error","uri","sessionId"],"mappings":"ybAKO,MAAMA,UAAmBC,EAAAA,QAAmC,CAClE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI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MK,EAAYD,EAAI,aAAa,IAAI,YAAY,EAEnD,GAAI,CAACC,EAAW,CACf,MAAMF,EAAQ,IAAI,MAAM,wCAAwC,EAChE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CAEA,MAAO,CAAE,WAAYE,CAAA,CACtB,CASA,MAAM,eAAeP,EAA6B,CACjD,GAAI,OAAO,KAAK,QAAQ,iBAAoB,WAAY,CACvD,MAAMK,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,SAAS,MAAM,0BAA2BA,CAAK,EAC9CA,CACP,CAEKL,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAM,KAAK,cAAe,MAAM,KAAK,QAAQ,gBAAgBA,EAAK,KAAK,QAAQ,cAAgB,UAAU,CAA4B,CACtI,CACD"}
1
+ {"version":3,"file":"NativeFlow.cjs","sources":["../../src/flows/NativeFlow.ts"],"sourcesContent":["import type { SDKOptions, NativeParams, SDKStorage, SDKHttpClient, SDKLogging } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { NativeFlowHandler } from '../handlers/NativeFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class NativeFlow extends BaseFlow<SDKOptions, NativeParams> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\t}\n\n\t/**\n\t * Initiates the login process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tlogin(params: NativeParams = {}): NativeFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new NativeFlowHandler(this, params);\n\t}\n\n\t/**\n\t * Initiates the registration process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tregister(params: NativeParams = {}): NativeFlowHandler {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\t/**\n\t * Initiates the entry process via a redirect.\n\t * @param {string} url Optional URL to use for the entry process. If not provided, the current window location will be used.\n\t * @returns {Promise<string>} A promise that resolves to the session ID.\n\t *\n\t * @throws {Error} Throws an error if the entry request fails or session ID is not found.\n\t */\n\tasync entry(url?: string): Promise<Record<string, string>> {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Accept-Language': '*',\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\t\tconst language = uri.searchParams.get('language') || navigator.language;\n\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('Session ID not found in entry response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId, language: language };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["NativeFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","NativeFlowHandler","url","entryUrl","response","data","message","error","uri","sessionId","language"],"mappings":"ueAKO,MAAMA,UAAmBC,EAAAA,QAAmC,CAClE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,EAAAA,oBAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,EAAAA,yBAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,CAC5C,CAOA,MAAMG,EAAuB,GAAuB,CACnD,YAAK,cAAc,iBAAkB,EAAE,EAEhC,IAAIC,EAAAA,kBAAkB,KAAMD,CAAM,CAC1C,CAOA,SAASA,EAAuB,GAAuB,CACtD,OAAAA,EAAO,OAAS,SAET,KAAK,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AAAC,CAAA,CACjC,CASA,MAAM,eAAeR,EAA6B,CACjD,GAAI,OAAO,KAAK,QAAQ,iBAAoB,WAAY,CACvD,MAAMK,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,SAAS,MAAM,0BAA2BA,CAAK,EAC9CA,CACP,CAEKL,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAM,KAAK,cAAe,MAAM,KAAK,QAAQ,gBAAgBA,EAAK,KAAK,QAAQ,cAAgB,UAAU,CAA4B,CACtI,CACD"}
@@ -1,5 +1,5 @@
1
1
  import { SDKOptions, NativeParams, SDKStorage, SDKHttpClient, SDKLogging } from '../types';
2
- import { NativeFlowHandler } from '../utils/NativeFlowHandler';
2
+ import { NativeFlowHandler } from '../handlers/NativeFlowHandler';
3
3
  import { BaseFlow } from './BaseFlow';
4
4
  export declare class NativeFlow extends BaseFlow<SDKOptions, NativeParams> {
5
5
  constructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging);
@@ -1,2 +1,2 @@
1
- import{redirectUrlHandler as c,redirectCallbackHandler as d}from"../utils/handlers.mjs";import{NativeFlowHandler as h}from"../utils/NativeFlowHandler.mjs";import{BaseFlow as p}from"./BaseFlow.mjs";import"../utils/errors.mjs";import"../utils/State.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";import"../utils/jwt.mjs";import"../utils/Metadata.mjs";import"../utils/Session.mjs";class P extends p{constructor(r,e,t,o){r.urlHandler||(r.urlHandler=c),r.callbackHandler||(r.callbackHandler=d),super(r,e,t,o)}login(r={}){return this.dispatchEvent("loginInitiated",[]),new h(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`);if(!t.ok){if(t.status===400){const i=await t.json();let n="Entry request failed with status 400";typeof i=="object"&&(i.error?n=`${i.error}: ${i.error_description}`:i.errorKey&&(n=i.errorKey));const l=new Error(n);throw this.logging?.error("Entry request error",l),l}const s=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",s),s}let o;try{o=new URL(await t.text())}catch{o=new URL(t.url)}const a=o.searchParams.get("session_id");if(!a){const s=new Error("Session ID not found in entry response");throw this.logging?.error("Entry response error",s),s}return{session_id:a}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}export{P as NativeFlow};
1
+ import{redirectUrlHandler as d,redirectCallbackHandler as h}from"../utils/handlers.mjs";import{NativeFlowHandler as p}from"../handlers/NativeFlowHandler.mjs";import{BaseFlow as g}from"./BaseFlow.mjs";import"../utils/errors.mjs";import"../handlers/BaseFlowHandler.mjs";import"../utils/State.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";import"../utils/jwt.mjs";import"../utils/Metadata.mjs";import"../utils/Session.mjs";class _ extends g{constructor(r,e,t,o){r.urlHandler||(r.urlHandler=d),r.callbackHandler||(r.callbackHandler=h),super(r,e,t,o)}login(r={}){return this.dispatchEvent("loginInitiated",[]),new p(this,r)}register(r={}){return r.prompt="create",this.login(r)}async entry(r){r||(r=globalThis.window?.location.href);const e=new URL(r);e.searchParams.append("sdk","web"),e.searchParams.append("client_id",this.options.clientId),e.searchParams.append("redirect_uri",this.options.redirectUri);const t=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`,{headers:{"Accept-Language":"*"}});if(!t.ok){if(t.status===400){const i=await t.json();let n="Entry request failed with status 400";typeof i=="object"&&(i.error?n=`${i.error}: ${i.error_description}`:i.errorKey&&(n=i.errorKey));const l=new Error(n);throw this.logging?.error("Entry request error",l),l}const s=new Error(`Entry request failed with status ${t.status}`);throw this.logging?.error("Entry request error",s),s}let o;try{o=new URL(await t.text())}catch{o=new URL(t.url)}const a=o.searchParams.get("session_id"),c=o.searchParams.get("language")||navigator.language;if(!a){const s=new Error("Session ID not found in entry response");throw this.logging?.error("Entry response error",s),s}return{session_id:a,language:c}}async handleCallback(r){if(typeof this.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.logging?.error("Required option missing",e),e}r||(r=globalThis.window?.location.href),await this.tokenExchange(await this.options.callbackHandler(r,this.options.responseMode||"fragment"))}}export{_ as NativeFlow};
2
2
  //# sourceMappingURL=NativeFlow.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeFlow.mjs","sources":["../../src/flows/NativeFlow.ts"],"sourcesContent":["import type { SDKOptions, NativeParams, SDKStorage, SDKHttpClient, SDKLogging } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { NativeFlowHandler } from '../utils/NativeFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class NativeFlow extends BaseFlow<SDKOptions, NativeParams> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\t}\n\n\t/**\n\t * Initiates the login process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tlogin(params: NativeParams = {}): NativeFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new NativeFlowHandler(this, params);\n\t}\n\n\t/**\n\t * Initiates the registration process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tregister(params: NativeParams = {}): NativeFlowHandler {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\t/**\n\t * Initiates the entry process via a redirect.\n\t * @param {string} url Optional URL to use for the entry process. If not provided, the current window location will be used.\n\t * @returns {Promise<string>} A promise that resolves to the session ID.\n\t *\n\t * @throws {Error} Throws an error if the entry request fails or session ID is not found.\n\t */\n\tasync entry(url?: string): Promise<Record<string, string>> {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('Session ID not found in entry response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["NativeFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","NativeFlowHandler","url","entryUrl","response","data","message","error","uri","sessionId"],"mappings":"qaAKO,MAAMA,UAAmBC,CAAmC,CAClE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,GAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,GAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,CAC5C,CAOA,MAAMG,EAAuB,GAAuB,CACnD,YAAK,cAAc,iBAAkB,EAAE,EAEhC,IAAIC,EAAkB,KAAMD,CAAM,CAC1C,CAOA,SAASA,EAAuB,GAAuB,CACtD,OAAAA,EAAO,OAAS,SAET,KAAK,MAAMA,CAAM,CACzB,CASA,MAAM,MAAME,EAA+C,CACrDA,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAMC,EAAW,IAAI,IAAID,CAAG,EAC5BC,EAAS,aAAa,OAAO,MAAO,KAAK,EACzCA,EAAS,aAAa,OAAO,YAAa,KAAK,QAAQ,QAAQ,EAC/DA,EAAS,aAA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"version":3,"file":"NativeFlow.mjs","sources":["../../src/flows/NativeFlow.ts"],"sourcesContent":["import type { SDKOptions, NativeParams, SDKStorage, SDKHttpClient, SDKLogging } from '../types';\nimport { redirectUrlHandler, redirectCallbackHandler } from '../utils/handlers';\nimport { NativeFlowHandler } from '../handlers/NativeFlowHandler';\nimport { BaseFlow } from './BaseFlow';\n\nexport class NativeFlow extends BaseFlow<SDKOptions, NativeParams> {\n\tconstructor(options: SDKOptions, storage: SDKStorage, httpClient: SDKHttpClient, logging?: SDKLogging) {\n\t\tif (!options.urlHandler) {\n\t\t\toptions.urlHandler = redirectUrlHandler;\n\t\t}\n\t\tif (!options.callbackHandler) {\n\t\t\toptions.callbackHandler = redirectCallbackHandler;\n\t\t}\n\n\t\tsuper(options, storage, httpClient, logging);\n\t}\n\n\t/**\n\t * Initiates the login process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tlogin(params: NativeParams = {}): NativeFlowHandler {\n\t\tthis.dispatchEvent('loginInitiated', []);\n\n\t\treturn new NativeFlowHandler(this, params);\n\t}\n\n\t/**\n\t * Initiates the registration process via native UI.\n\t * @param {NativeParams} [params={}] Optional parameters for native configuration.\n\t * @returns {NativeFlowHandler} Returns with a native login handler.\n\t */\n\tregister(params: NativeParams = {}): NativeFlowHandler {\n\t\tparams.prompt = 'create';\n\n\t\treturn this.login(params);\n\t}\n\n\t/**\n\t * Initiates the entry process via a redirect.\n\t * @param {string} url Optional URL to use for the entry process. If not provided, the current window location will be used.\n\t * @returns {Promise<string>} A promise that resolves to the session ID.\n\t *\n\t * @throws {Error} Throws an error if the entry request fails or session ID is not found.\n\t */\n\tasync entry(url?: string): Promise<Record<string, string>> {\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tconst entryUrl = new URL(url);\n\t\tentryUrl.searchParams.append('sdk', 'web');\n\t\tentryUrl.searchParams.append('client_id', this.options.clientId);\n\t\tentryUrl.searchParams.append('redirect_uri', this.options.redirectUri);\n\n\t\tconst response = await this.httpClient.request<string | Record<string, string>>(\n\t\t\t`${this.options.issuer}/provider/flow/entry?${entryUrl.searchParams.toString()}`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Accept-Language': '*',\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 400) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tlet message = 'Entry request failed with status 400';\n\n\t\t\t\tif (typeof data === 'object') {\n\t\t\t\t\tif (data.error) {\n\t\t\t\t\t\tmessage = `${data.error}: ${data.error_description}`;\n\t\t\t\t\t} else if (data.errorKey) {\n\t\t\t\t\t\tmessage = data.errorKey;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst error = new Error(message);\n\t\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst error = new Error(`Entry request failed with status ${response.status}`);\n\t\t\tthis.logging?.error('Entry request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tconst sessionId = uri.searchParams.get('session_id');\n\t\tconst language = uri.searchParams.get('language') || navigator.language;\n\n\t\tif (!sessionId) {\n\t\t\tconst error = new Error('Session ID not found in entry response');\n\t\t\tthis.logging?.error('Entry response error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn { session_id: sessionId, language: language };\n\t}\n\n\t/**\n\t * Handles the callback after login or registration via a redirect.\n\t * @param {string} [url] The URL to handle the callback from. Defaults to the current window location.\n\t * @returns {Promise<void>} A promise that resolves when the callback is handled.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined.\n\t */\n\tasync handleCallback(url?: string): Promise<void> {\n\t\tif (typeof this.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!url) {\n\t\t\turl = globalThis.window?.location.href;\n\t\t}\n\n\t\tawait this.tokenExchange((await this.options.callbackHandler(url, this.options.responseMode || 'fragment')) as Record<string, string>);\n\t}\n}\n"],"names":["NativeFlow","BaseFlow","options","storage","httpClient","logging","redirectUrlHandler","redirectCallbackHandler","params","NativeFlowHandler","url","entryUrl","response","data","message","error","uri","sessionId","language"],"mappings":"gdAKO,MAAMA,UAAmBC,CAAmC,CAClE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,GAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,GAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,CAC5C,CAOA,MAAMG,EAAuB,GAAuB,CACnD,YAAK,cAAc,iBAAkB,EAAE,EAEhC,IAAIC,EAAkB,KAAMD,CAAM,CAC1C,CAOA,SAASA,EAAuB,GAAuB,CACtD,OAAAA,EAAO,OAAS,SAET,KAAK,MAAMA,CAAM,CACzB,CASA,MAAM,MAAME,EAA+C,CACrDA,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAMC,EAAW,IAAI,IAAID,CAAG,EAC5BC,EAAS,aAAa,OAAO,MAAO,KAAK,EACzCA,EAAS,aAAa,OAAO,YAAa,KAAK,QAAQ,QAAQ,EAC/DA,EAAS,aAAa,OAAO,eAAgB,KAAK,QAAQ,WAAW,EAErE,MAAMC,EAAW,MAAM,KAAK,WAAW,QACtC,GAAG,KAAK,QAAQ,MAAM,wBAAwBD,EAAS,aAAa,UAAU,GAC9E,CACC,QAAS,CACR,kBAAmB,GAAA,CACpB,CACD,EAGD,GAAI,CAACC,EAAS,GAAI,CACjB,GAAIA,EAAS,SAAW,IAAK,CAC5B,MAAMC,EAAO,MAAMD,EAAS,KAAA,EAC5B,IAAIE,EAAU,uCAEV,OAAOD,GAAS,WACfA,EAAK,MACRC,EAAU,GAAGD,EAAK,KAAK,KAAKA,EAAK,iBAAiB,GACxCA,EAAK,WACfC,EAAUD,EAAK,WAIjB,MAAME,EAAQ,IAAI,MAAMD,CAAO,EAC/B,WAAK,SAAS,MAAM,sBAAuBC,CAAK,EAC1CA,CACP,CAEA,MAAMA,EAAQ,IAAI,MAAM,oCAAoCH,EAAS,MAAM,EAAE,EAC7E,WAAK,SAAS,MAAM,sBAAuBG,CAAK,EAC1CA,CACP,CAEA,IAAIC,EAEJ,GAAI,CACHA,EAAM,IAAI,IAAI,MAAMJ,EAAS,MAAM,CACpC,MAAQ,CACPI,EAAM,IAAI,IAAIJ,EAAS,GAAG,CAC3B,CAEA,MAAMK,EAAYD,EAAI,aAAa,IAAI,YAAY,EAC7CE,EAAWF,EAAI,aAAa,IAAI,UAAU,GAAK,UAAU,SAE/D,GAAI,CAACC,EAAW,CACf,MAAMF,EAAQ,IAAI,MAAM,wCAAwC,EAChE,WAAK,SAAS,MAAM,uBAAwBA,CAAK,EAC3CA,CACP,CAEA,MAAO,CAAE,WAAYE,EAAW,SAAAC,CAAA,CACjC,CASA,MAAM,eAAeR,EAA6B,CACjD,GAAI,OAAO,KAAK,QAAQ,iBAAoB,WAAY,CACvD,MAAMK,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,SAAS,MAAM,0BAA2BA,CAAK,EAC9CA,CACP,CAEKL,IACJA,EAAM,WAAW,QAAQ,SAAS,MAGnC,MAAM,KAAK,cAAe,MAAM,KAAK,QAAQ,gBAAgBA,EAAK,KAAK,QAAQ,cAAgB,UAAU,CAA4B,CACtI,CACD"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class s{constructor(l,e={}){this.sdk=l,this.params=e,this.locale=e.uiLocales?.[0]||navigator.language}sessionId=null;locale}exports.BaseFlowHandler=s;
2
+ //# sourceMappingURL=BaseFlowHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseFlowHandler.cjs","sources":["../../src/handlers/BaseFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\n\nexport abstract class BaseFlowHandler {\n\t/**\n\t * The session ID.\n\t *\n\t * @type {string | null}\n\t */\n\tprotected sessionId: string | null = null;\n\n\t/**\n\t * The locale to use for the authentication flow.\n\t *\n\t * Defaults to the browser's language setting.\n\t *\n\t * @type {string}\n\t */\n\tlocale!: string;\n\n\tconstructor(\n\t\t/**\n\t\t * The SDK instance.\n\t\t *\n\t\t * @type {SDKStorage}\n\t\t */\n\t\tprotected sdk: BaseFlow,\n\t\t/**\n\t\t * Optional parameters for native configuration.\n\t\t *\n\t\t * @type {NativeParams} [options={}]\n\t\t */\n\t\tprotected params: NativeParams = {},\n\t) {\n\t\tthis.locale = params.uiLocales?.[0] || navigator.language;\n\t}\n\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<LoginFlowState | void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tabstract startSession(sessionId?: string | null): Promise<LoginFlowState | void>;\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tabstract finalizeSession(finalizeUrl: URL | string): Promise<void>;\n}\n"],"names":["BaseFlowHandler","sdk","params"],"mappings":"gFAGO,MAAeA,CAAgB,CAiBrC,YAMWC,EAMAC,EAAuB,GAChC,CAPS,KAAA,IAAAD,EAMA,KAAA,OAAAC,EAEV,KAAK,OAASA,EAAO,YAAY,CAAC,GAAK,UAAU,QAClD,CA1BU,UAA2B,KASrC,MAqCD"}
@@ -1,6 +1,6 @@
1
1
  import { NativeParams, LoginFlowState } from '../types';
2
2
  import { BaseFlow } from '../flows/BaseFlow';
3
- export declare class NativeFlowHandler {
3
+ export declare abstract class BaseFlowHandler {
4
4
  /**
5
5
  * The SDK instance.
6
6
  *
@@ -19,6 +19,14 @@ export declare class NativeFlowHandler {
19
19
  * @type {string | null}
20
20
  */
21
21
  protected sessionId: string | null;
22
+ /**
23
+ * The locale to use for the authentication flow.
24
+ *
25
+ * Defaults to the browser's language setting.
26
+ *
27
+ * @type {string}
28
+ */
29
+ locale: string;
22
30
  constructor(
23
31
  /**
24
32
  * The SDK instance.
@@ -40,7 +48,7 @@ export declare class NativeFlowHandler {
40
48
  *
41
49
  * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.
42
50
  */
43
- startSession(sessionId?: string | null): Promise<LoginFlowState | void>;
51
+ abstract startSession(sessionId?: string | null): Promise<LoginFlowState | void>;
44
52
  /**
45
53
  * Finalizes the session using the provided [finalizeUrl].
46
54
  *
@@ -48,14 +56,5 @@ export declare class NativeFlowHandler {
48
56
  *
49
57
  * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.
50
58
  */
51
- finalizeSession(finalizeUrl: URL | string): Promise<void>;
52
- /**
53
- * Submits a form with the provided [formId] and [data].
54
- *
55
- * @returns {Promise<LoginFlowState>}
56
- *
57
- * @throws {Error} Throws an error if form submission fails.
58
- * @throws {FallbackError} Throws a fallback error if response indicates fallback is needed.
59
- */
60
- submitForm(formId?: string, body?: Record<string, unknown>): Promise<LoginFlowState>;
59
+ abstract finalizeSession(finalizeUrl: URL | string): Promise<void>;
61
60
  }
@@ -0,0 +1,2 @@
1
+ class o{constructor(l,s={}){this.sdk=l,this.params=s,this.locale=s.uiLocales?.[0]||navigator.language}sessionId=null;locale}export{o as BaseFlowHandler};
2
+ //# sourceMappingURL=BaseFlowHandler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseFlowHandler.mjs","sources":["../../src/handlers/BaseFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\n\nexport abstract class BaseFlowHandler {\n\t/**\n\t * The session ID.\n\t *\n\t * @type {string | null}\n\t */\n\tprotected sessionId: string | null = null;\n\n\t/**\n\t * The locale to use for the authentication flow.\n\t *\n\t * Defaults to the browser's language setting.\n\t *\n\t * @type {string}\n\t */\n\tlocale!: string;\n\n\tconstructor(\n\t\t/**\n\t\t * The SDK instance.\n\t\t *\n\t\t * @type {SDKStorage}\n\t\t */\n\t\tprotected sdk: BaseFlow,\n\t\t/**\n\t\t * Optional parameters for native configuration.\n\t\t *\n\t\t * @type {NativeParams} [options={}]\n\t\t */\n\t\tprotected params: NativeParams = {},\n\t) {\n\t\tthis.locale = params.uiLocales?.[0] || navigator.language;\n\t}\n\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<LoginFlowState | void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tabstract startSession(sessionId?: string | null): Promise<LoginFlowState | void>;\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tabstract finalizeSession(finalizeUrl: URL | string): Promise<void>;\n}\n"],"names":["BaseFlowHandler","sdk","params"],"mappings":"AAGO,MAAeA,CAAgB,CAiBrC,YAMWC,EAMAC,EAAuB,GAChC,CAPS,KAAA,IAAAD,EAMA,KAAA,OAAAC,EAEV,KAAK,OAASA,EAAO,YAAY,CAAC,GAAK,UAAU,QAClD,CA1BU,UAA2B,KASrC,MAqCD"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./BaseFlowHandler.cjs"),a=require("../utils/State.cjs");require("../utils/crypto.cjs");require("../utils/base64Url.cjs");require("../utils/date.cjs");class n extends o.BaseFlowHandler{shortAppId=null;async startSession(){await this.sdk.waitToInitialize(),this.sdk.logging&&(this.sdk.logging.xEventId=void 0,this.sdk.logging.info("Starting login flow session"));const e=await a.State.create(),t=await this.sdk.getAuthorizationUrl(this.params);t.searchParams.append("sdk","web-embedded"),t.searchParams.append("state",e.id),t.searchParams.append("code_challenge",e.codeChallenge),t.searchParams.append("nonce",e.nonce),await this.sdk.storage.set(`sty.${e.id}`,JSON.stringify(e));const i=await this.sdk.httpClient.request(t.toString(),{method:"GET",credentials:"include",headers:{"Accept-language":"*"}});if(!i.ok){const s=new Error(`Authorization request failed with status ${i.status}`);throw this.sdk.logging?.error("Authorization request error",s),s}let r;try{r=new URL(await i.text())}catch{r=new URL(i.url)}if(r.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function"){const s=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",s),s}if(!r.toString().startsWith(this.sdk.options.redirectUri)){const s=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",s),s}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error")){const s=new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",s),s}if(r.searchParams.has("language")&&(this.locale=r.searchParams.get("language")),this.shortAppId=r.searchParams.get("short_app_id"),this.sessionId=r.searchParams.get("session_id"),!this.shortAppId){const s=new Error('"short_app_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",s),s}if(!this.sessionId){const s=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",s),s}}async finalizeSession(e){this.sdk.logging?.debug("Finalizing login flow session");const t=await this.sdk.httpClient.request(e.toString(),{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`,"Accept-language":"*"},credentials:"include"}),i=new URL(await t.text());if(typeof this.sdk.options.callbackHandler!="function"){const r=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",r),r}if(!i.toString().startsWith(this.sdk.options.redirectUri)){const r=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Finalize session error",r),r}await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(i.toString(),this.sdk.options.responseMode||"fragment"))}}exports.EmbeddedFlowHandler=n;
2
+ //# sourceMappingURL=EmbeddedFlowHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbeddedFlowHandler.cjs","sources":["../../src/handlers/EmbeddedFlowHandler.ts"],"sourcesContent":["import { BaseFlowHandler } from './BaseFlowHandler';\nimport { State } from '../utils/State';\n\n/**\n * Handler for the embedded login flow, managing the session and interactions with the SDK.\n */\nexport class EmbeddedFlowHandler extends BaseFlowHandler {\n\t/**\n\t * The short app ID associated with the session.\n\t *\n\t * @type {string | null}\n\t */\n\tshortAppId: string | null = null;\n\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tasync startSession(): Promise<void> {\n\t\tawait this.sdk.waitToInitialize();\n\n\t\tif (this.sdk.logging) {\n\t\t\tthis.sdk.logging.xEventId = undefined;\n\t\t\tthis.sdk.logging.info('Starting login flow session');\n\t\t}\n\n\t\tconst state = await State.create();\n\t\tconst authorizationUrl = await this.sdk.getAuthorizationUrl(this.params);\n\n\t\tauthorizationUrl.searchParams.append('sdk', 'web-embedded');\n\t\tauthorizationUrl.searchParams.append('state', state.id);\n\t\tauthorizationUrl.searchParams.append('code_challenge', state.codeChallenge);\n\t\tauthorizationUrl.searchParams.append('nonce', state.nonce);\n\n\t\tawait this.sdk.storage.set(`sty.${state.id}`, JSON.stringify(state));\n\n\t\tconst response = await this.sdk.httpClient.request(authorizationUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t\theaders: { 'Accept-language': '*' },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst error = new Error(`Authorization request failed with status ${response.status}`);\n\t\t\tthis.sdk.logging?.error('Authorization request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tif (uri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!uri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\t\tthis.sdk.logging?.error('Invalid redirect URI', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(uri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (uri.searchParams.has('error')) {\n\t\t\tconst error = new Error(`${uri.searchParams.get('error')}: ${uri.searchParams.get('error_description')}`);\n\t\t\tthis.sdk.logging?.error('Authorization error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (uri.searchParams.has('language')) {\n\t\t\tthis.locale = uri.searchParams.get('language')!;\n\t\t}\n\n\t\tthis.shortAppId = uri.searchParams.get('short_app_id');\n\t\tthis.sessionId = uri.searchParams.get('session_id');\n\n\t\tif (!this.shortAppId) {\n\t\t\tconst error = new Error('\"short_app_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\t\tif (!this.sessionId) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tasync finalizeSession(finalizeUrl: URL | string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Accept-language': '*' },\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\tthis.sdk.logging?.error('Finalize session error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tawait this.sdk.tokenExchange(\n\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t);\n\t}\n}\n"],"names":["EmbeddedFlowHandler","BaseFlowHandler","state","State","authorizationUrl","response","error","uri","finalizeUrl","redirectUri"],"mappings":"uPAMO,MAAMA,UAA4BC,EAAAA,eAAgB,CAMxD,WAA4B,KAU5B,MAAM,cAA8B,CACnC,MAAM,KAAK,IAAI,iBAAA,EAEX,KAAK,IAAI,UACZ,KAAK,IAAI,QAAQ,SAAW,OAC5B,KAAK,IAAI,QAAQ,KAAK,6BAA6B,GAGpD,MAAMC,EAAQ,MAAMC,EAAAA,MAAM,OAAA,EACpBC,EAAmB,MAAM,KAAK,IAAI,oBAAoB,KAAK,MAAM,EA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gBG,EAAY,SAAA,EAAY,KAAK,IAAI,QAAQ,cAAgB,UAAU,CAAA,CAE7G,CACD"}
@@ -1,46 +1,14 @@
1
- import { ExtraRequestArgs } from '../types';
2
- import { EmbeddedFlow } from '../flows/EmbeddedFlow';
1
+ import { BaseFlowHandler } from './BaseFlowHandler';
3
2
  /**
4
3
  * Handler for the embedded login flow, managing the session and interactions with the SDK.
5
4
  */
6
- export declare class EmbeddedFlowHandler {
7
- /**
8
- * The SDK instance.
9
- *
10
- * @type {EmbeddedFlow}
11
- */
12
- protected sdk: EmbeddedFlow;
13
- /**
14
- * Optional parameters for native configuration.
15
- *
16
- * @type {NativeParams} [options={}]
17
- */
18
- protected params: ExtraRequestArgs;
5
+ export declare class EmbeddedFlowHandler extends BaseFlowHandler {
19
6
  /**
20
7
  * The short app ID associated with the session.
21
8
  *
22
9
  * @type {string | null}
23
10
  */
24
- shortAppId: string | undefined;
25
- /**
26
- * The session ID.
27
- *
28
- * @type {string | null}
29
- */
30
- sessionId: string | undefined;
31
- constructor(
32
- /**
33
- * The SDK instance.
34
- *
35
- * @type {EmbeddedFlow}
36
- */
37
- sdk: EmbeddedFlow,
38
- /**
39
- * Optional parameters for native configuration.
40
- *
41
- * @type {NativeParams} [options={}]
42
- */
43
- params?: ExtraRequestArgs);
11
+ shortAppId: string | null;
44
12
  /**
45
13
  * Starts a new session.
46
14
  *
@@ -0,0 +1,2 @@
1
+ import{BaseFlowHandler as o}from"./BaseFlowHandler.mjs";import{State as a}from"../utils/State.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";class p extends o{shortAppId=null;async startSession(){await this.sdk.waitToInitialize(),this.sdk.logging&&(this.sdk.logging.xEventId=void 0,this.sdk.logging.info("Starting login flow session"));const t=await a.create(),e=await this.sdk.getAuthorizationUrl(this.params);e.searchParams.append("sdk","web-embedded"),e.searchParams.append("state",t.id),e.searchParams.append("code_challenge",t.codeChallenge),e.searchParams.append("nonce",t.nonce),await this.sdk.storage.set(`sty.${t.id}`,JSON.stringify(t));const i=await this.sdk.httpClient.request(e.toString(),{method:"GET",credentials:"include",headers:{"Accept-language":"*"}});if(!i.ok){const s=new Error(`Authorization request failed with status ${i.status}`);throw this.sdk.logging?.error("Authorization request error",s),s}let r;try{r=new URL(await i.text())}catch{r=new URL(i.url)}if(r.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function"){const s=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",s),s}if(!r.toString().startsWith(this.sdk.options.redirectUri)){const s=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",s),s}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error")){const s=new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",s),s}if(r.searchParams.has("language")&&(this.locale=r.searchParams.get("language")),this.shortAppId=r.searchParams.get("short_app_id"),this.sessionId=r.searchParams.get("session_id"),!this.shortAppId){const s=new Error('"short_app_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",s),s}if(!this.sessionId){const s=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",s),s}}async finalizeSession(t){this.sdk.logging?.debug("Finalizing login flow session");const e=await this.sdk.httpClient.request(t.toString(),{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`,"Accept-language":"*"},credentials:"include"}),i=new URL(await e.text());if(typeof this.sdk.options.callbackHandler!="function"){const r=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",r),r}if(!i.toString().startsWith(this.sdk.options.redirectUri)){const r=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Finalize session error",r),r}await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(i.toString(),this.sdk.options.responseMode||"fragment"))}}export{p as EmbeddedFlowHandler};
2
+ //# sourceMappingURL=EmbeddedFlowHandler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbeddedFlowHandler.mjs","sources":["../../src/handlers/EmbeddedFlowHandler.ts"],"sourcesContent":["import { BaseFlowHandler } from './BaseFlowHandler';\nimport { State } from '../utils/State';\n\n/**\n * Handler for the embedded login flow, managing the session and interactions with the SDK.\n */\nexport class EmbeddedFlowHandler extends BaseFlowHandler {\n\t/**\n\t * The short app ID associated with the session.\n\t *\n\t * @type {string | null}\n\t */\n\tshortAppId: string | null = null;\n\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tasync startSession(): Promise<void> {\n\t\tawait this.sdk.waitToInitialize();\n\n\t\tif (this.sdk.logging) {\n\t\t\tthis.sdk.logging.xEventId = undefined;\n\t\t\tthis.sdk.logging.info('Starting login flow session');\n\t\t}\n\n\t\tconst state = await State.create();\n\t\tconst authorizationUrl = await this.sdk.getAuthorizationUrl(this.params);\n\n\t\tauthorizationUrl.searchParams.append('sdk', 'web-embedded');\n\t\tauthorizationUrl.searchParams.append('state', state.id);\n\t\tauthorizationUrl.searchParams.append('code_challenge', state.codeChallenge);\n\t\tauthorizationUrl.searchParams.append('nonce', state.nonce);\n\n\t\tawait this.sdk.storage.set(`sty.${state.id}`, JSON.stringify(state));\n\n\t\tconst response = await this.sdk.httpClient.request(authorizationUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t\theaders: { 'Accept-language': '*' },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst error = new Error(`Authorization request failed with status ${response.status}`);\n\t\t\tthis.sdk.logging?.error('Authorization request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tif (uri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!uri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\t\tthis.sdk.logging?.error('Invalid redirect URI', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(uri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (uri.searchParams.has('error')) {\n\t\t\tconst error = new Error(`${uri.searchParams.get('error')}: ${uri.searchParams.get('error_description')}`);\n\t\t\tthis.sdk.logging?.error('Authorization error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (uri.searchParams.has('language')) {\n\t\t\tthis.locale = uri.searchParams.get('language')!;\n\t\t}\n\n\t\tthis.shortAppId = uri.searchParams.get('short_app_id');\n\t\tthis.sessionId = uri.searchParams.get('session_id');\n\n\t\tif (!this.shortAppId) {\n\t\t\tconst error = new Error('\"short_app_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\t\tif (!this.sessionId) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tasync finalizeSession(finalizeUrl: URL | string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Accept-language': '*' },\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\tthis.sdk.logging?.error('Finalize session error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tawait this.sdk.tokenExchange(\n\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t);\n\t}\n}\n"],"names":["EmbeddedFlowHandler","BaseFlowHandler","state","State","authorizationUrl","response","error","uri","finalizeUrl","redirectUri"],"mappings":"wLAMO,MAAMA,UAA4BC,CAAgB,CAMxD,WAA4B,KAU5B,MAAM,cAA8B,CACnC,MAAM,KAAK,IAAI,iBAAA,EAEX,KAAK,IAAI,UACZ,KAAK,IAAI,QAAQ,SAAW,OAC5B,KAAK,IAAI,QAAQ,KAAK,6BAA6B,GAGpD,MAAMC,EAAQ,MAAMC,EAAM,OAAA,EACpBC,EAAmB,MAAM,KAAK,IAAI,oBAAoB,KAAK,MAAM,EAEvEA,EAAiB,aAAa,OAAO,MAAO,cAAc,EAC1DA,EAAiB,aAAa,OAAO,QAASF,EAAM,EAAE,EACtDE,EAAiB,aAAa,OAAO,iBAAkBF,EAAM,aAAa,EAC1EE,EAAiB,aAAa,OAAO,QAASF,EAAM,KAAK,EAEzD,MAAM,KAAK,IAAI,QAAQ,IAAI,OAAOA,EAAM,EAAE,GAAI,KAAK,UAAUA,CAAK,CAAC,EAEnE,MAAMG,EAAW,MAAM,KAAK,IAAI,WAAW,QAAQD,EAAiB,WAA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,CAAC,KAAK,WAAY,CACrB,MAAMD,EAAQ,IAAI,MAAM,6CAA6C,EACrE,WAAK,IAAI,SAAS,MAAM,4BAA6BA,CAAK,EACpDA,CACP,CACA,GAAI,CAAC,KAAK,UAAW,CACpB,MAAMA,EAAQ,IAAI,MAAM,2CAA2C,EACnE,WAAK,IAAI,SAAS,MAAM,4BAA6BA,CAAK,EACpDA,CACP,CACD,CASA,MAAM,gBAAgBE,EAA0C,CAC/D,KAAK,IAAI,SAAS,MAAM,+BAA+B,EAEvD,MAAMH,EAAW,MAAM,KAAK,IAAI,WAAW,QAAQG,EAAY,WAAY,CAC1E,OAAQ,MACR,QAAS,CAAE,cAAe,UAAU,KAAK,SAAS,GAAI,kBAAmB,GAAA,EACzE,YAAa,SAAA,CACb,EACKC,EAAc,IAAI,IAAI,MAAMJ,EAAS,MAAM,EAEjD,GAAI,OAAO,KAAK,IAAI,QAAQ,iBAAoB,WAAY,CAC3D,MAAMC,EAAQ,IAAI,MAAM,iCAAiC,EACzD,WAAK,IAAI,SAAS,MAAM,0BAA2BA,CAAK,EAClDA,CACP,CAEA,GAAI,CAACG,EAAY,WAAW,WAAW,KAAK,IAAI,QAAQ,WAAW,EAAG,CACrE,MAAMH,EAAQ,IAAI,MAAM,sBAAsB,EAC9C,WAAK,IAAI,SAAS,MAAM,yBAA0BA,CAAK,EACjDA,CACP,CAEA,MAAM,KAAK,IAAI,cACb,MAAM,KAAK,IAAI,QAAQ,gBAAgBG,EAAY,SAAA,EAAY,KAAK,IAAI,QAAQ,cAAgB,UAAU,CAAA,CAE7G,CACD"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./BaseFlowHandler.cjs"),l=require("../utils/State.cjs"),a=require("../utils/errors.cjs");require("../utils/crypto.cjs");require("../utils/base64Url.cjs");require("../utils/date.cjs");class g extends n.BaseFlowHandler{async startSession(i){if(this.sdk.logging&&(this.sdk.logging.xEventId=void 0,this.sdk.logging.info("Starting login flow session")),i)return this.sessionId=i,this.submitForm();const o=await l.State.create(),e=await this.sdk.getAuthorizationUrl(this.params);e.searchParams.append("sdk",this.params.sdk||"web"),e.searchParams.append("state",o.id),e.searchParams.append("code_challenge",o.codeChallenge),e.searchParams.append("nonce",o.nonce),await this.sdk.storage.set(`sty.${o.id}`,JSON.stringify(o));const s=await this.sdk.httpClient.request(e.toString(),{method:"GET",credentials:"include",headers:{"Accept-language":"*"}});if(!s.ok){const t=new Error(`Authorization request failed with status ${s.status}`);throw this.sdk.logging?.error("Authorization request error",t),t}let r;try{r=new URL(await s.text())}catch{r=new URL(s.url)}if(r.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function"){const t=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",t),t}if(!r.toString().startsWith(this.sdk.options.redirectUri)){const t=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",t),t}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error")){const t=new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",t),t}if(!r.searchParams.has("session_id")){const t=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",t),t}return r.searchParams.has("language")&&(this.locale=r.searchParams.get("language")),this.sessionId=r.searchParams.get("session_id"),this.submitForm()}async finalizeSession(i){this.sdk.logging?.debug("Finalizing login flow session");const o=await this.sdk.httpClient.request(i.toString(),{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`,"Accept-language":"*"},credentials:"include"}),e=new URL(await o.text());if(typeof this.sdk.options.callbackHandler!="function"){const s=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",s),s}if(!e.toString().startsWith(this.sdk.options.redirectUri)){const s=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Finalize session error",s),s}await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(e.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(i,o={}){i&&this.sdk.logging?.debug(`Submitting form: ${i}`);const e=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${i?`form/${i}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json","Accept-language":this.locale},body:JSON.stringify(o),credentials:"include"}),s=await e.json();if(!e.ok&&e.status>=400&&e.status<500){if(e.status!==403&&s?.hostedUrl&&!s.messages)throw this.sdk.logging?.warn(`Triggering fallback due to: Received HTTP ${e.status} without messages`),new a.FallbackError(new URL(s.hostedUrl));if(e.status!==400){const r=new Error(`HTTP ${e.status}: ${e.statusText}`);throw this.sdk.logging?.error("Form submission error",r),r}}if(s.finalizeUrl)await this.finalizeSession(s.finalizeUrl);else{if(s.hostedUrl&&!s.forms&&!s.messages)throw this.sdk.logging?.warn("Triggering fallback due to: No forms or messages in response"),new a.FallbackError(new URL(s.hostedUrl));s.screen&&this.sdk.logging?.info(`Rendering screen: ${s.screen}`)}return s}}exports.NativeFlowHandler=g;
2
+ //# sourceMappingURL=NativeFlowHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeFlowHandler.cjs","sources":["../../src/handlers/NativeFlowHandler.ts"],"sourcesContent":["import type { LoginFlowState } from '../types';\nimport { BaseFlowHandler } from './BaseFlowHandler';\nimport { State } from '../utils/State';\nimport { FallbackError } from '../utils/errors';\n\nexport class NativeFlowHandler extends BaseFlowHandler {\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<LoginFlowState | void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\n\t\tif (this.sdk.logging) {\n\t\t\tthis.sdk.logging.xEventId = undefined;\n\t\t\tthis.sdk.logging.info('Starting login flow session');\n\t\t}\n\n\t\tif (sessionId) {\n\t\t\tthis.sessionId = sessionId;\n\t\t\treturn this.submitForm();\n\t\t}\n\n\t\tconst state = await State.create();\n\t\tconst authorizationUrl = await this.sdk.getAuthorizationUrl(this.params);\n\n\t\tauthorizationUrl.searchParams.append('sdk', this.params.sdk || 'web');\n\t\tauthorizationUrl.searchParams.append('state', state.id);\n\t\tauthorizationUrl.searchParams.append('code_challenge', state.codeChallenge);\n\t\tauthorizationUrl.searchParams.append('nonce', state.nonce);\n\n\t\tawait this.sdk.storage.set(`sty.${state.id}`, JSON.stringify(state));\n\n\t\tconst response = await this.sdk.httpClient.request(authorizationUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t\theaders: { 'Accept-language': '*' },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst error = new Error(`Authorization request failed with status ${response.status}`);\n\t\t\tthis.sdk.logging?.error('Authorization request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tif (uri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!uri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\t\tthis.sdk.logging?.error('Invalid redirect URI', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(uri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (uri.searchParams.has('error')) {\n\t\t\tconst error = new Error(`${uri.searchParams.get('error')}: ${uri.searchParams.get('error_description')}`);\n\t\t\tthis.sdk.logging?.error('Authorization error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!uri.searchParams.has('session_id')) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (uri.searchParams.has('language')) {\n\t\t\tthis.locale = uri.searchParams.get('language')!;\n\t\t}\n\n\t\tthis.sessionId = uri.searchParams.get('session_id');\n\n\t\treturn this.submitForm();\n\t}\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tasync finalizeSession(finalizeUrl: URL | string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Accept-language': '*' },\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\tthis.sdk.logging?.error('Finalize session error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tawait this.sdk.tokenExchange(\n\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t);\n\t}\n\n\t/**\n\t * Submits a form with the provided [formId] and [data].\n\t *\n\t * @returns {Promise<LoginFlowState>}\n\t *\n\t * @throws {Error} Throws an error if form submission fails.\n\t * @throws {FallbackError} Throws a fallback error if response indicates fallback is needed.\n\t */\n\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\n\t\tif (formId) {\n\t\t\tthis.sdk.logging?.debug(`Submitting form: ${formId}`);\n\t\t}\n\n\t\tconst response = await this.sdk.httpClient.request<LoginFlowState>(\n\t\t\tnew URL(`/flow/api/v1/${formId ? `form/${formId}` : 'init'}`, this.sdk.options.issuer).toString(),\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Content-Type': 'application/json', 'Accept-language': this.locale },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tcredentials: 'include',\n\t\t\t},\n\t\t);\n\t\tconst data = await response.json();\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\t\tif (response.status !== 403 && data?.hostedUrl && !data.messages) {\n\t\t\t\t\tthis.sdk.logging?.warn(`Triggering fallback due to: Received HTTP ${response.status} without messages`);\n\t\t\t\t\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t\t\t}\n\n\t\t\t\tif (response.status !== 400) {\n\t\t\t\t\tconst error = new Error(`HTTP ${response.status}: ${response.statusText}`);\n\t\t\t\t\tthis.sdk.logging?.error(`Form submission error`, error);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (data.finalizeUrl) {\n\t\t\tawait this.finalizeSession(data.finalizeUrl);\n\t\t} else if (data.hostedUrl && !data.forms && !data.messages) {\n\t\t\tthis.sdk.logging?.warn(`Triggering fallback due to: No forms or messages in response`);\n\t\t\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t} else if (data.screen) {\n\t\t\tthis.sdk.logging?.info(`Rendering screen: ${data.screen}`);\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","BaseFlowHandler","sessionId","state","State","authorizationUrl","response","error","uri","finalizeUrl","redir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A,EAAK,OAAS,CAACA,EAAK,SACjD,WAAK,IAAI,SAAS,KAAK,8DAA8D,EAC/E,IAAIC,EAAAA,cAAc,IAAI,IAAID,EAAK,SAAS,CAAC,EACrCA,EAAK,QACf,KAAK,IAAI,SAAS,KAAK,qBAAqBA,EAAK,MAAM,EAAE,EAG1D,OAAOA,CACR,CACD"}
@@ -0,0 +1,30 @@
1
+ import { LoginFlowState } from '../types';
2
+ import { BaseFlowHandler } from './BaseFlowHandler';
3
+ export declare class NativeFlowHandler extends BaseFlowHandler {
4
+ /**
5
+ * Starts a new session.
6
+ *
7
+ * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.
8
+ * @returns {Promise<LoginFlowState | void>}
9
+ *
10
+ * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.
11
+ */
12
+ startSession(sessionId?: string | null): Promise<LoginFlowState | void>;
13
+ /**
14
+ * Finalizes the session using the provided [finalizeUrl].
15
+ *
16
+ * @param {string} finalizeUrl The URL to finalize the session.
17
+ *
18
+ * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.
19
+ */
20
+ finalizeSession(finalizeUrl: URL | string): Promise<void>;
21
+ /**
22
+ * Submits a form with the provided [formId] and [data].
23
+ *
24
+ * @returns {Promise<LoginFlowState>}
25
+ *
26
+ * @throws {Error} Throws an error if form submission fails.
27
+ * @throws {FallbackError} Throws a fallback error if response indicates fallback is needed.
28
+ */
29
+ submitForm(formId?: string, body?: Record<string, unknown>): Promise<LoginFlowState>;
30
+ }
@@ -0,0 +1,2 @@
1
+ import{BaseFlowHandler as a}from"./BaseFlowHandler.mjs";import{State as g}from"../utils/State.mjs";import{FallbackError as n}from"../utils/errors.mjs";import"../utils/crypto.mjs";import"../utils/base64Url.mjs";import"../utils/date.mjs";class k extends a{async startSession(i){if(this.sdk.logging&&(this.sdk.logging.xEventId=void 0,this.sdk.logging.info("Starting login flow session")),i)return this.sessionId=i,this.submitForm();const o=await g.create(),r=await this.sdk.getAuthorizationUrl(this.params);r.searchParams.append("sdk",this.params.sdk||"web"),r.searchParams.append("state",o.id),r.searchParams.append("code_challenge",o.codeChallenge),r.searchParams.append("nonce",o.nonce),await this.sdk.storage.set(`sty.${o.id}`,JSON.stringify(o));const s=await this.sdk.httpClient.request(r.toString(),{method:"GET",credentials:"include",headers:{"Accept-language":"*"}});if(!s.ok){const e=new Error(`Authorization request failed with status ${s.status}`);throw this.sdk.logging?.error("Authorization request error",e),e}let t;try{t=new URL(await s.text())}catch{t=new URL(s.url)}if(t.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function"){const e=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",e),e}if(!t.toString().startsWith(this.sdk.options.redirectUri)){const e=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",e),e}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(t.toString(),this.sdk.options.responseMode||"fragment"))}if(t.searchParams.has("error")){const e=new Error(`${t.searchParams.get("error")}: ${t.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",e),e}if(!t.searchParams.has("session_id")){const e=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",e),e}return t.searchParams.has("language")&&(this.locale=t.searchParams.get("language")),this.sessionId=t.searchParams.get("session_id"),this.submitForm()}async finalizeSession(i){this.sdk.logging?.debug("Finalizing login flow session");const o=await this.sdk.httpClient.request(i.toString(),{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`,"Accept-language":"*"},credentials:"include"}),r=new URL(await o.text());if(typeof this.sdk.options.callbackHandler!="function"){const s=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",s),s}if(!r.toString().startsWith(this.sdk.options.redirectUri)){const s=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Finalize session error",s),s}await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(i,o={}){i&&this.sdk.logging?.debug(`Submitting form: ${i}`);const r=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${i?`form/${i}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json","Accept-language":this.locale},body:JSON.stringify(o),credentials:"include"}),s=await r.json();if(!r.ok&&r.status>=400&&r.status<500){if(r.status!==403&&s?.hostedUrl&&!s.messages)throw this.sdk.logging?.warn(`Triggering fallback due to: Received HTTP ${r.status} without messages`),new n(new URL(s.hostedUrl));if(r.status!==400){const t=new Error(`HTTP ${r.status}: ${r.statusText}`);throw this.sdk.logging?.error("Form submission error",t),t}}if(s.finalizeUrl)await this.finalizeSession(s.finalizeUrl);else{if(s.hostedUrl&&!s.forms&&!s.messages)throw this.sdk.logging?.warn("Triggering fallback due to: No forms or messages in response"),new n(new URL(s.hostedUrl));s.screen&&this.sdk.logging?.info(`Rendering screen: ${s.screen}`)}return s}}export{k as NativeFlowHandler};
2
+ //# sourceMappingURL=NativeFlowHandler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeFlowHandler.mjs","sources":["../../src/handlers/NativeFlowHandler.ts"],"sourcesContent":["import type { LoginFlowState } from '../types';\nimport { BaseFlowHandler } from './BaseFlowHandler';\nimport { State } from '../utils/State';\nimport { FallbackError } from '../utils/errors';\n\nexport class NativeFlowHandler extends BaseFlowHandler {\n\t/**\n\t * Starts a new session.\n\t *\n\t * @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.\n\t * @returns {Promise<LoginFlowState | void>}\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.\n\t */\n\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\n\t\tif (this.sdk.logging) {\n\t\t\tthis.sdk.logging.xEventId = undefined;\n\t\t\tthis.sdk.logging.info('Starting login flow session');\n\t\t}\n\n\t\tif (sessionId) {\n\t\t\tthis.sessionId = sessionId;\n\t\t\treturn this.submitForm();\n\t\t}\n\n\t\tconst state = await State.create();\n\t\tconst authorizationUrl = await this.sdk.getAuthorizationUrl(this.params);\n\n\t\tauthorizationUrl.searchParams.append('sdk', this.params.sdk || 'web');\n\t\tauthorizationUrl.searchParams.append('state', state.id);\n\t\tauthorizationUrl.searchParams.append('code_challenge', state.codeChallenge);\n\t\tauthorizationUrl.searchParams.append('nonce', state.nonce);\n\n\t\tawait this.sdk.storage.set(`sty.${state.id}`, JSON.stringify(state));\n\n\t\tconst response = await this.sdk.httpClient.request(authorizationUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\tcredentials: 'include',\n\t\t\theaders: { 'Accept-language': '*' },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst error = new Error(`Authorization request failed with status ${response.status}`);\n\t\t\tthis.sdk.logging?.error('Authorization request error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet uri: URL;\n\n\t\ttry {\n\t\t\turi = new URL(await response.text());\n\t\t} catch {\n\t\t\turi = new URL(response.url);\n\t\t}\n\n\t\tif (uri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!uri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\t\tthis.sdk.logging?.error('Invalid redirect URI', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(uri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (uri.searchParams.has('error')) {\n\t\t\tconst error = new Error(`${uri.searchParams.get('error')}: ${uri.searchParams.get('error_description')}`);\n\t\t\tthis.sdk.logging?.error('Authorization error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!uri.searchParams.has('session_id')) {\n\t\t\tconst error = new Error('\"session_id\" is missing from the response');\n\t\t\tthis.sdk.logging?.error('Failed to start a session', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (uri.searchParams.has('language')) {\n\t\t\tthis.locale = uri.searchParams.get('language')!;\n\t\t}\n\n\t\tthis.sessionId = uri.searchParams.get('session_id');\n\n\t\treturn this.submitForm();\n\t}\n\n\t/**\n\t * Finalizes the session using the provided [finalizeUrl].\n\t *\n\t * @param {string} finalizeUrl The URL to finalize the session.\n\t *\n\t * @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.\n\t */\n\tasync finalizeSession(finalizeUrl: URL | string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl.toString(), {\n\t\t\tmethod: 'GET',\n\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Accept-language': '*' },\n\t\t\tcredentials: 'include',\n\t\t});\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tconst error = new Error('Missing option: callbackHandler');\n\t\t\tthis.sdk.logging?.error('Required option missing', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tconst error = new Error('Invalid redirect URI');\n\t\t\tthis.sdk.logging?.error('Finalize session error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tawait this.sdk.tokenExchange(\n\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t);\n\t}\n\n\t/**\n\t * Submits a form with the provided [formId] and [data].\n\t *\n\t * @returns {Promise<LoginFlowState>}\n\t *\n\t * @throws {Error} Throws an error if form submission fails.\n\t * @throws {FallbackError} Throws a fallback error if response indicates fallback is needed.\n\t */\n\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\n\t\tif (formId) {\n\t\t\tthis.sdk.logging?.debug(`Submitting form: ${formId}`);\n\t\t}\n\n\t\tconst response = await this.sdk.httpClient.request<LoginFlowState>(\n\t\t\tnew URL(`/flow/api/v1/${formId ? `form/${formId}` : 'init'}`, this.sdk.options.issuer).toString(),\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { Authorization: `Bearer ${this.sessionId}`, 'Content-Type': 'application/json', 'Accept-language': this.locale },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tcredentials: 'include',\n\t\t\t},\n\t\t);\n\t\tconst data = await response.json();\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\t\tif (response.status !== 403 && data?.hostedUrl && !data.messages) {\n\t\t\t\t\tthis.sdk.logging?.warn(`Triggering fallback due to: Received HTTP ${response.status} without messages`);\n\t\t\t\t\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t\t\t}\n\n\t\t\t\tif (response.status !== 400) {\n\t\t\t\t\tconst error = new Error(`HTTP ${response.status}: ${response.statusText}`);\n\t\t\t\t\tthis.sdk.logging?.error(`Form submission error`, error);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (data.finalizeUrl) {\n\t\t\tawait this.finalizeSession(data.finalizeUrl);\n\t\t} else if (data.hostedUrl && !data.forms && !data.messages) {\n\t\t\tthis.sdk.logging?.warn(`Triggering fallback due to: No forms or messages in response`);\n\t\t\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t} else if (data.screen) {\n\t\t\tthis.sdk.logging?.info(`Rendering screen: ${data.screen}`);\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","BaseFlowHandler","sessionId","state","State","authorizationUrl","response","error","uri","finalizeUrl","redirectUri","formId","body","data","FallbackError"],"mappings":"4OAKO,MAAMA,UAA0BC,CAAgB,CAStD,MAA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,IAAID,EAAK,SAAS,CAAC,EACrCA,EAAK,QACf,KAAK,IAAI,SAAS,KAAK,qBAAqBA,EAAK,MAAM,EAAE,EAG1D,OAAOA,CACR,CACD"}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./flows/RedirectFlow.cjs"),s=require("./flows/PopupFlow.cjs"),c=require("./flows/NativeFlow.cjs"),a=require("./flows/EmbeddedFlow.cjs"),w=require("./storages/LocalStorage.cjs"),d=require("./utils/HttpClient.cjs"),l=require("./utils/errors.cjs"),i=require("./types.cjs");require("./utils/handlers.cjs");require("./utils/State.cjs");require("./utils/crypto.cjs");require("./utils/base64Url.cjs");require("./utils/date.cjs");require("./flows/BaseFlow.cjs");require("./utils/jwt.cjs");require("./utils/Metadata.cjs");require("./utils/Session.cjs");require("./utils/NativeFlowHandler.cjs");require("./utils/EmbeddedFlowHandler.cjs");function q(e){const u=e.storage||w.LocalStorage,n=e.httpClient||d.HttpClient,o=new u,t=new n;let r;return e.logging&&(r=new e.logging,t.logging=r),e.mode==="popup"?new s.PopupFlow(e,o,t,r):e.mode==="native"?new c.NativeFlow(e,o,t,r):e.mode==="embedded"?new a.EmbeddedFlow(e,o,t,r):new g.RedirectFlow(e,o,t,r)}exports.FallbackError=l.FallbackError;exports.PopupBlockedError=l.PopupBlockedError;exports.PopupClosedError=l.PopupClosedError;exports.SDKHttpClient=i.SDKHttpClient;exports.SDKLogging=i.SDKLogging;exports.SDKStorage=i.SDKStorage;exports.initFlow=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./flows/BaseFlow.cjs"),w=require("./flows/RedirectFlow.cjs"),c=require("./flows/PopupFlow.cjs"),g=require("./flows/NativeFlow.cjs"),a=require("./flows/EmbeddedFlow.cjs"),d=require("./storages/LocalStorage.cjs"),q=require("./utils/HttpClient.cjs"),l=require("./utils/errors.cjs"),u=require("./types.cjs");require("./utils/jwt.cjs");require("./utils/base64Url.cjs");require("./utils/date.cjs");require("./utils/Metadata.cjs");require("./utils/Session.cjs");require("./utils/State.cjs");require("./utils/crypto.cjs");require("./utils/handlers.cjs");require("./handlers/NativeFlowHandler.cjs");require("./handlers/BaseFlowHandler.cjs");require("./handlers/EmbeddedFlowHandler.cjs");function F(e){const i=e.storage||d.LocalStorage,n=e.httpClient||q.HttpClient,o=new i,t=new n;let r;if(e.logging&&(r=new e.logging,t.logging=r),e.mode==="popup")return new c.PopupFlow(e,o,t,r);if(e.mode==="native")return new g.NativeFlow(e,o,t,r);if(e.mode==="embedded")return new a.EmbeddedFlow(e,o,t,r);if(e.mode==="custom"){if(!e.customFlow||!(e.customFlow.prototype instanceof s.BaseFlow))throw new Error("customFlow must extend BaseFlow");return new e.customFlow(e,o,t,r)}else return new w.RedirectFlow(e,o,t,r)}exports.FallbackError=l.FallbackError;exports.PopupBlockedError=l.PopupBlockedError;exports.PopupClosedError=l.PopupClosedError;exports.SDKHttpClient=u.SDKHttpClient;exports.SDKLogging=u.SDKLogging;exports.SDKStorage=u.SDKStorage;exports.initFlow=F;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import type { SDKOptions } from './types';\nimport { RedirectFlow } from './flows/RedirectFlow';\nimport { PopupFlow } from './flows/PopupFlow';\nimport { NativeFlow } from './flows/NativeFlow';\nimport { EmbeddedFlow } from './flows/EmbeddedFlow';\nimport { LocalStorage } from './storages/LocalStorage';\nimport { HttpClient } from './utils/HttpClient';\n\nexport * from './utils/errors';\nexport type * from './types';\nexport { SDKStorage, SDKLogging, SDKHttpClient } from './types';\n\n/**\n * Initializes an authentication flow based on the specified mode.\n *\n * @param {SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }} options - The SDK options, including an optional mode. The default storage class is `LocalStorage`.\n * @returns {PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow} A new instance of either PopupFlow, RedirectFlow, NativeFlow or EmbeddedFlow based on the mode.\n */\nexport function initFlow(options: SDKOptions & { mode: 'popup' }): PopupFlow;\nexport function initFlow(options: SDKOptions & { mode: 'redirect' }): RedirectFlow;\nexport function initFlow(options: SDKOptions & { mode: 'native' }): NativeFlow;\nexport function initFlow(options: SDKOptions & { mode: 'embedded' }): EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow {\n\tconst StorageClass = options.storage || LocalStorage;\n\tconst HttpClientClass = options.httpClient || HttpClient;\n\n\tconst storage = new StorageClass();\n\tconst httpClient = new HttpClientClass();\n\tlet logging;\n\n\tif (options.logging) {\n\t\tlogging = new options.logging();\n\t\thttpClient.logging = logging;\n\t}\n\n\tif (options.mode === 'popup') {\n\t\treturn new PopupFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'native') {\n\t\treturn new NativeFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'embedded') {\n\t\treturn new EmbeddedFlow(options, storage, httpClient, logging);\n\t} else {\n\t\treturn new RedirectFlow(options, storage, httpClient, logging);\n\t}\n}\n"],"names":["initFlow","options","StorageClass","LocalStorage","HttpClientClass","HttpClient","storage","httpClient","logging","PopupFlow","NativeFlow","EmbeddedFlow","RedirectFlow"],"mappings":"qtBAuBO,SAASA,EAASC,EAAqI,CAC7J,MAAMC,EAAeD,EAAQ,SAAWE,EAAAA,aAClCC,EAAkBH,EAAQ,YAAcI,EAAAA,WAExCC,EAAU,IAAIJ,EACdK,EAAa,IAAIH,EACvB,IAAII,EAOJ,OALIP,EAAQ,UACXO,EAAU,IAAIP,EAAQ,QACtBM,EAAW,QAAUC,GAGlBP,EAAQ,OAAS,QACb,IAAIQ,EAAAA,UAAUR,EAASK,EAASC,EAAYC,CAAO,EAChDP,EAAQ,OAAS,SACpB,IAAIS,EAAAA,WAAWT,EAASK,EAASC,EAAYC,CAAO,EACjDP,EAAQ,OAAS,WACpB,IAAIU,EAAAA,aAAaV,EAASK,EAASC,EAAYC,CAAO,EAEtD,IAAII,EAAAA,aAAaX,EAASK,EAASC,EAAYC,CAAO,CAE/D"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import type { SDKOptions } from './types';\nimport { BaseFlow } from './flows/BaseFlow';\nimport { RedirectFlow } from './flows/RedirectFlow';\nimport { PopupFlow } from './flows/PopupFlow';\nimport { NativeFlow } from './flows/NativeFlow';\nimport { EmbeddedFlow } from './flows/EmbeddedFlow';\nimport { LocalStorage } from './storages/LocalStorage';\nimport { HttpClient } from './utils/HttpClient';\n\nexport * from './utils/errors';\nexport type * from './types';\nexport { SDKStorage, SDKLogging, SDKHttpClient } from './types';\n\n/**\n * Initializes an authentication flow based on the specified mode.\n *\n * @param {SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }} options - The SDK options, including an optional mode. The default storage class is `LocalStorage`.\n * @returns {PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow} A new instance of either PopupFlow, RedirectFlow, NativeFlow or EmbeddedFlow based on the mode.\n */\nexport function initFlow(options: SDKOptions & { mode: 'popup' }): PopupFlow;\nexport function initFlow(options: SDKOptions & { mode: 'redirect' }): RedirectFlow;\nexport function initFlow(options: SDKOptions & { mode: 'native' }): NativeFlow;\nexport function initFlow(options: SDKOptions & { mode: 'embedded' }): EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode: 'custom' }): EmbeddedFlow;\nexport function initFlow(\n\toptions: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' | 'custom' },\n): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow | typeof options.customFlow;\nexport function initFlow(\n\toptions: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' | 'custom' },\n): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow | typeof options.customFlow {\n\tconst StorageClass = options.storage || LocalStorage;\n\tconst HttpClientClass = options.httpClient || HttpClient;\n\n\tconst storage = new StorageClass();\n\tconst httpClient = new HttpClientClass();\n\tlet logging;\n\n\tif (options.logging) {\n\t\tlogging = new options.logging();\n\t\thttpClient.logging = logging;\n\t}\n\n\tif (options.mode === 'popup') {\n\t\treturn new PopupFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'native') {\n\t\treturn new NativeFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'embedded') {\n\t\treturn new EmbeddedFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'custom') {\n\t\tif (!options.customFlow || !(options.customFlow.prototype instanceof BaseFlow)) {\n\t\t\tthrow new Error('customFlow must extend BaseFlow');\n\t\t}\n\n\t\treturn new options.customFlow(options, storage, httpClient, logging) as unknown as typeof options.customFlow;\n\t} else {\n\t\treturn new RedirectFlow(options, storage, httpClient, logging);\n\t}\n}\n"],"names":["initFlow","options","StorageClass","LocalStorage","HttpClientClass","HttpClient","storage","httpClient","logging","PopupFlow","NativeFlow","EmbeddedFlow","BaseFlow","RedirectFlow"],"mappings":"uwBA2BO,SAASA,EACfC,EACmF,CACnF,MAAMC,EAAeD,EAAQ,SAAWE,EAAAA,aAClCC,EAAkBH,EAAQ,YAAcI,EAAAA,WAExCC,EAAU,IAAIJ,EACdK,EAAa,IAAIH,EACvB,IAAII,EAOJ,GALIP,EAAQ,UACXO,EAAU,IAAIP,EAAQ,QACtBM,EAAW,QAAUC,GAGlBP,EAAQ,OAAS,QACpB,OAAO,IAAIQ,EAAAA,UAAUR,EAASK,EAASC,EAAYC,CAAO,EAC3D,GAAWP,EAAQ,OAAS,SAC3B,OAAO,IAAIS,EAAAA,WAAWT,EAASK,EAASC,EAAYC,CAAO,EAC5D,GAAWP,EAAQ,OAAS,WAC3B,OAAO,IAAIU,EAAAA,aAAaV,EAASK,EAASC,EAAYC,CAAO,EAC9D,GAAWP,EAAQ,OAAS,SAAU,CACrC,GAAI,CAACA,EAAQ,YAAc,EAAEA,EAAQ,WAAW,qBAAqBW,EAAAA,UACpE,MAAM,IAAI,MAAM,iCAAiC,EAGlD,OAAO,IAAIX,EAAQ,WAAWA,EAASK,EAASC,EAAYC,CAAO,CACpE,KACC,QAAO,IAAIK,EAAAA,aAAaZ,EAASK,EAASC,EAAYC,CAAO,CAE/D"}
package/dist/index.d.ts CHANGED
@@ -25,5 +25,8 @@ export declare function initFlow(options: SDKOptions & {
25
25
  mode: 'embedded';
26
26
  }): EmbeddedFlow;
27
27
  export declare function initFlow(options: SDKOptions & {
28
- mode?: 'popup' | 'redirect' | 'native' | 'embedded';
29
- }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow;
28
+ mode: 'custom';
29
+ }): EmbeddedFlow;
30
+ export declare function initFlow(options: SDKOptions & {
31
+ mode?: 'popup' | 'redirect' | 'native' | 'embedded' | 'custom';
32
+ }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow | typeof options.customFlow;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{RedirectFlow as l}from"./flows/RedirectFlow.mjs";import{PopupFlow as p}from"./flows/PopupFlow.mjs";import{NativeFlow as g}from"./flows/NativeFlow.mjs";import{EmbeddedFlow as n}from"./flows/EmbeddedFlow.mjs";import{LocalStorage as f}from"./storages/LocalStorage.mjs";import{HttpClient as a}from"./utils/HttpClient.mjs";import{FallbackError as N,PopupBlockedError as R,PopupClosedError as j}from"./utils/errors.mjs";import{SDKHttpClient as y,SDKLogging as z,SDKStorage as A}from"./types.mjs";import"./utils/handlers.mjs";import"./utils/State.mjs";import"./utils/crypto.mjs";import"./utils/base64Url.mjs";import"./utils/date.mjs";import"./flows/BaseFlow.mjs";import"./utils/jwt.mjs";import"./utils/Metadata.mjs";import"./utils/Session.mjs";import"./utils/NativeFlowHandler.mjs";import"./utils/EmbeddedFlowHandler.mjs";function v(r){const m=r.storage||f,i=r.httpClient||a,o=new m,t=new i;let e;return r.logging&&(e=new r.logging,t.logging=e),r.mode==="popup"?new p(r,o,t,e):r.mode==="native"?new g(r,o,t,e):r.mode==="embedded"?new n(r,o,t,e):new l(r,o,t,e)}export{N as FallbackError,R as PopupBlockedError,j as PopupClosedError,y as SDKHttpClient,z as SDKLogging,A as SDKStorage,v as initFlow};
1
+ import{BaseFlow as i}from"./flows/BaseFlow.mjs";import{RedirectFlow as p}from"./flows/RedirectFlow.mjs";import{PopupFlow as w}from"./flows/PopupFlow.mjs";import{NativeFlow as g}from"./flows/NativeFlow.mjs";import{EmbeddedFlow as n}from"./flows/EmbeddedFlow.mjs";import{LocalStorage as f}from"./storages/LocalStorage.mjs";import{HttpClient as u}from"./utils/HttpClient.mjs";import{FallbackError as R,PopupBlockedError as j,PopupClosedError as q}from"./utils/errors.mjs";import{SDKHttpClient as A,SDKLogging as G,SDKStorage as I}from"./types.mjs";import"./utils/jwt.mjs";import"./utils/base64Url.mjs";import"./utils/date.mjs";import"./utils/Metadata.mjs";import"./utils/Session.mjs";import"./utils/State.mjs";import"./utils/crypto.mjs";import"./utils/handlers.mjs";import"./handlers/NativeFlowHandler.mjs";import"./handlers/BaseFlowHandler.mjs";import"./handlers/EmbeddedFlowHandler.mjs";function L(r){const m=r.storage||f,l=r.httpClient||u,o=new m,t=new l;let e;if(r.logging&&(e=new r.logging,t.logging=e),r.mode==="popup")return new w(r,o,t,e);if(r.mode==="native")return new g(r,o,t,e);if(r.mode==="embedded")return new n(r,o,t,e);if(r.mode==="custom"){if(!r.customFlow||!(r.customFlow.prototype instanceof i))throw new Error("customFlow must extend BaseFlow");return new r.customFlow(r,o,t,e)}else return new p(r,o,t,e)}export{R as FallbackError,j as PopupBlockedError,q as PopupClosedError,A as SDKHttpClient,G as SDKLogging,I as SDKStorage,L as initFlow};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { SDKOptions } from './types';\nimport { RedirectFlow } from './flows/RedirectFlow';\nimport { PopupFlow } from './flows/PopupFlow';\nimport { NativeFlow } from './flows/NativeFlow';\nimport { EmbeddedFlow } from './flows/EmbeddedFlow';\nimport { LocalStorage } from './storages/LocalStorage';\nimport { HttpClient } from './utils/HttpClient';\n\nexport * from './utils/errors';\nexport type * from './types';\nexport { SDKStorage, SDKLogging, SDKHttpClient } from './types';\n\n/**\n * Initializes an authentication flow based on the specified mode.\n *\n * @param {SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }} options - The SDK options, including an optional mode. The default storage class is `LocalStorage`.\n * @returns {PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow} A new instance of either PopupFlow, RedirectFlow, NativeFlow or EmbeddedFlow based on the mode.\n */\nexport function initFlow(options: SDKOptions & { mode: 'popup' }): PopupFlow;\nexport function initFlow(options: SDKOptions & { mode: 'redirect' }): RedirectFlow;\nexport function initFlow(options: SDKOptions & { mode: 'native' }): NativeFlow;\nexport function initFlow(options: SDKOptions & { mode: 'embedded' }): EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow {\n\tconst StorageClass = options.storage || LocalStorage;\n\tconst HttpClientClass = options.httpClient || HttpClient;\n\n\tconst storage = new StorageClass();\n\tconst httpClient = new HttpClientClass();\n\tlet logging;\n\n\tif (options.logging) {\n\t\tlogging = new options.logging();\n\t\thttpClient.logging = logging;\n\t}\n\n\tif (options.mode === 'popup') {\n\t\treturn new PopupFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'native') {\n\t\treturn new NativeFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'embedded') {\n\t\treturn new EmbeddedFlow(options, storage, httpClient, logging);\n\t} else {\n\t\treturn new RedirectFlow(options, storage, httpClient, logging);\n\t}\n}\n"],"names":["initFlow","options","StorageClass","LocalStorage","HttpClientClass","HttpClient","storage","httpClient","logging","PopupFlow","NativeFlow","EmbeddedFlow","RedirectFlow"],"mappings":"szBAuBO,SAASA,EAASC,EAAqI,CAC7J,MAAMC,EAAeD,EAAQ,SAAWE,EAClCC,EAAkBH,EAAQ,YAAcI,EAExCC,EAAU,IAAIJ,EACdK,EAAa,IAAIH,EACvB,IAAII,EAOJ,OALIP,EAAQ,UACXO,EAAU,IAAIP,EAAQ,QACtBM,EAAW,QAAUC,GAGlBP,EAAQ,OAAS,QACb,IAAIQ,EAAUR,EAASK,EAASC,EAAYC,CAAO,EAChDP,EAAQ,OAAS,SACpB,IAAIS,EAAWT,EAASK,EAASC,EAAYC,CAAO,EACjDP,EAAQ,OAAS,WACpB,IAAIU,EAAaV,EAASK,EAASC,EAAYC,CAAO,EAEtD,IAAII,EAAaX,EAASK,EAASC,EAAYC,CAAO,CAE/D"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { SDKOptions } from './types';\nimport { BaseFlow } from './flows/BaseFlow';\nimport { RedirectFlow } from './flows/RedirectFlow';\nimport { PopupFlow } from './flows/PopupFlow';\nimport { NativeFlow } from './flows/NativeFlow';\nimport { EmbeddedFlow } from './flows/EmbeddedFlow';\nimport { LocalStorage } from './storages/LocalStorage';\nimport { HttpClient } from './utils/HttpClient';\n\nexport * from './utils/errors';\nexport type * from './types';\nexport { SDKStorage, SDKLogging, SDKHttpClient } from './types';\n\n/**\n * Initializes an authentication flow based on the specified mode.\n *\n * @param {SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' }} options - The SDK options, including an optional mode. The default storage class is `LocalStorage`.\n * @returns {PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow} A new instance of either PopupFlow, RedirectFlow, NativeFlow or EmbeddedFlow based on the mode.\n */\nexport function initFlow(options: SDKOptions & { mode: 'popup' }): PopupFlow;\nexport function initFlow(options: SDKOptions & { mode: 'redirect' }): RedirectFlow;\nexport function initFlow(options: SDKOptions & { mode: 'native' }): NativeFlow;\nexport function initFlow(options: SDKOptions & { mode: 'embedded' }): EmbeddedFlow;\nexport function initFlow(options: SDKOptions & { mode: 'custom' }): EmbeddedFlow;\nexport function initFlow(\n\toptions: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' | 'custom' },\n): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow | typeof options.customFlow;\nexport function initFlow(\n\toptions: SDKOptions & { mode?: 'popup' | 'redirect' | 'native' | 'embedded' | 'custom' },\n): PopupFlow | RedirectFlow | NativeFlow | EmbeddedFlow | typeof options.customFlow {\n\tconst StorageClass = options.storage || LocalStorage;\n\tconst HttpClientClass = options.httpClient || HttpClient;\n\n\tconst storage = new StorageClass();\n\tconst httpClient = new HttpClientClass();\n\tlet logging;\n\n\tif (options.logging) {\n\t\tlogging = new options.logging();\n\t\thttpClient.logging = logging;\n\t}\n\n\tif (options.mode === 'popup') {\n\t\treturn new PopupFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'native') {\n\t\treturn new NativeFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'embedded') {\n\t\treturn new EmbeddedFlow(options, storage, httpClient, logging);\n\t} else if (options.mode === 'custom') {\n\t\tif (!options.customFlow || !(options.customFlow.prototype instanceof BaseFlow)) {\n\t\t\tthrow new Error('customFlow must extend BaseFlow');\n\t\t}\n\n\t\treturn new options.customFlow(options, storage, httpClient, logging) as unknown as typeof options.customFlow;\n\t} else {\n\t\treturn new RedirectFlow(options, storage, httpClient, logging);\n\t}\n}\n"],"names":["initFlow","options","StorageClass","LocalStorage","HttpClientClass","HttpClient","storage","httpClient","logging","PopupFlow","NativeFlow","EmbeddedFlow","BaseFlow","RedirectFlow"],"mappings":"s3BA2BO,SAASA,EACfC,EACmF,CACnF,MAAMC,EAAeD,EAAQ,SAAWE,EAClCC,EAAkBH,EAAQ,YAAcI,EAExCC,EAAU,IAAIJ,EACdK,EAAa,IAAIH,EACvB,IAAII,EAOJ,GALIP,EAAQ,UACXO,EAAU,IAAIP,EAAQ,QACtBM,EAAW,QAAUC,GAGlBP,EAAQ,OAAS,QACpB,OAAO,IAAIQ,EAAUR,EAASK,EAASC,EAAYC,CAAO,EAC3D,GAAWP,EAAQ,OAAS,SAC3B,OAAO,IAAIS,EAAWT,EAASK,EAASC,EAAYC,CAAO,EAC5D,GAAWP,EAAQ,OAAS,WAC3B,OAAO,IAAIU,EAAaV,EAASK,EAASC,EAAYC,CAAO,EAC9D,GAAWP,EAAQ,OAAS,SAAU,CACrC,GAAI,CAACA,EAAQ,YAAc,EAAEA,EAAQ,WAAW,qBAAqBW,GACpE,MAAM,IAAI,MAAM,iCAAiC,EAGlD,OAAO,IAAIX,EAAQ,WAAWA,EAASK,EAASC,EAAYC,CAAO,CACpE,KACC,QAAO,IAAIK,EAAaZ,EAASK,EAASC,EAAYC,CAAO,CAE/D"}