@strivacity/sdk-core 3.0.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.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/flows/EmbeddedFlow.cjs +1 -1
- package/dist/flows/EmbeddedFlow.cjs.map +1 -1
- package/dist/flows/EmbeddedFlow.d.ts +1 -0
- package/dist/flows/EmbeddedFlow.mjs +1 -1
- package/dist/flows/EmbeddedFlow.mjs.map +1 -1
- package/dist/flows/NativeFlow.cjs +1 -1
- package/dist/flows/NativeFlow.cjs.map +1 -1
- package/dist/flows/NativeFlow.mjs +1 -1
- package/dist/flows/NativeFlow.mjs.map +1 -1
- package/dist/handlers/BaseFlowHandler.cjs +1 -1
- package/dist/handlers/BaseFlowHandler.cjs.map +1 -1
- package/dist/handlers/BaseFlowHandler.d.ts +8 -0
- package/dist/handlers/BaseFlowHandler.mjs +1 -1
- package/dist/handlers/BaseFlowHandler.mjs.map +1 -1
- package/dist/handlers/EmbeddedFlowHandler.cjs +1 -1
- package/dist/handlers/EmbeddedFlowHandler.cjs.map +1 -1
- package/dist/handlers/EmbeddedFlowHandler.mjs +1 -1
- package/dist/handlers/EmbeddedFlowHandler.mjs.map +1 -1
- package/dist/handlers/NativeFlowHandler.cjs +1 -1
- package/dist/handlers/NativeFlowHandler.cjs.map +1 -1
- package/dist/handlers/NativeFlowHandler.mjs +1 -1
- package/dist/handlers/NativeFlowHandler.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 3.0.1 (2026-04-20)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- handle language parameter from response body url correctly ([e42294b](https://github.com/Strivacity/sdk-js/commit/e42294b))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated testing to 3.0.1
|
|
10
|
+
|
|
1
11
|
# 3.0.0 (2026-04-09)
|
|
2
12
|
|
|
3
13
|
### 🚀 Features
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ In `native` mode, `login()` returns a `NativeFlowHandler` instance that drives t
|
|
|
84
84
|
|
|
85
85
|
#### Login page example
|
|
86
86
|
|
|
87
|
-
The login page extracts `session_id` from the URL on load and passes
|
|
87
|
+
The login page extracts `session_id` and optionally `language` from the URL on load and passes them to `startSession()` to resume an existing flow or start a new one. When a `language` parameter is present it overrides `uiLocales` to display the authentication UI in the specified language:
|
|
88
88
|
|
|
89
89
|
```js
|
|
90
90
|
import { initFlow } from '@strivacity/sdk-core';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../utils/handlers.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../utils/handlers.cjs"),g=require("../handlers/EmbeddedFlowHandler.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 p extends u.BaseFlow{constructor(r,e,s,i){r.urlHandler||(r.urlHandler=c.redirectUrlHandler),r.callbackHandler||(r.callbackHandler=c.redirectCallbackHandler),super(r,e,s,i),globalThis.sty||(globalThis.sty={}),globalThis.sty.oidcService=this}login(r={}){return this.dispatchEvent("loginInitiated",[]),new g.EmbeddedFlowHandler(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 s=await this.httpClient.request(`${this.options.issuer}/provider/flow/entry?${e.searchParams.toString()}`,{headers:{"Accept-Language":"*"}});if(!s.ok){if(s.status===400){const o=await s.json();let n="Entry request failed with status 400";typeof o=="object"&&(o.error?n=`${o.error}: ${o.error_description}`:o.errorKey&&(n=o.errorKey));const d=new Error(n);throw this.logging?.error("Entry request error",d),d}const t=new Error(`Entry request failed with status ${s.status}`);throw this.logging?.error("Entry request error",t),t}let i;try{i=new URL(await s.text())}catch{i=new URL(s.url)}const a=i.searchParams.get("short_app_id"),l=i.searchParams.get("session_id"),h=i.searchParams.get("language")||navigator.language;if(!a){const t=new Error('"short_app_id" is missing from the response');throw this.logging?.error("Entry response error",t),t}if(!l){const t=new Error('"session_id" is missing from the response');throw this.logging?.error("Entry response error",t),t}return{session_id:l,short_app_id:a,language:h}}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.EmbeddedFlow=p;
|
|
2
2
|
//# sourceMappingURL=EmbeddedFlow.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddedFlow.cjs","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);\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":"yeAKO,MAAMA,UAAqBC,EAAAA,QAAuC,CACxE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,EAAAA,oBAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,EAAAA,yBAG3B,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,EAAAA,oBAAoB,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,
|
|
1
|
+
{"version":3,"file":"EmbeddedFlow.cjs","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":"yeAKO,MAAMA,UAAqBC,EAAAA,QAAuC,CACxE,YAAYC,EAAqBC,EAAqBC,EAA2BC,EAAsB,CACjGH,EAAQ,aACZA,EAAQ,WAAaI,EAAAA,oBAEjBJ,EAAQ,kBACZA,EAAQ,gBAAkBK,EAAAA,yBAG3B,MAAML,EAASC,EAASC,EAAYC,CAAO,EAEtC,WAAW,MACf,WAAW,IAAM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AI,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"}
|
|
@@ -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
|
|
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 '../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);\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":"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,
|
|
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"),
|
|
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 '../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);\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":"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,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,
|
|
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,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{redirectUrlHandler as
|
|
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 '../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);\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":"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,
|
|
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 '../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,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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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
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
2
|
//# sourceMappingURL=BaseFlowHandler.cjs.map
|
|
@@ -1 +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\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\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,
|
|
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"}
|
|
@@ -19,6 +19,14 @@ export declare abstract class BaseFlowHandler {
|
|
|
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.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class o{constructor(s
|
|
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
2
|
//# sourceMappingURL=BaseFlowHandler.mjs.map
|
|
@@ -1 +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\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\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,
|
|
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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./BaseFlowHandler.cjs"),
|
|
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
2
|
//# sourceMappingURL=EmbeddedFlowHandler.cjs.map
|
|
@@ -1 +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(), {
|
|
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":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D,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BaseFlowHandler as o}from"./BaseFlowHandler.mjs";import{State as
|
|
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
2
|
//# sourceMappingURL=EmbeddedFlowHandler.mjs.map
|
|
@@ -1 +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(), {
|
|
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"],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AAiC,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
2
|
//# sourceMappingURL=NativeFlowHandler.cjs.map
|
|
@@ -1 +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(), { method: 'GET', credentials: 'include' });\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\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}` },\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' },\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":"wRAKO,MAAMA,UAA0BC,EAAAA,eAAgB,CAStD,MAAM,aAAaC,EAA2D,CAM7E,GALI,KAAK,IAAI,UACZ,KAAK,IAAI,QAAQ,SAAW,OAC5B,KAAK,IAAI,QAAQ,KAAK,6BAA6B,GAGhDA,EACH,YAAK,UAAYA,EACV,KAAK,WAAA,EAGb,MAAMC,EAAQ,MAAMC,EAAAA,MAAM,OAAA,EACpBC,EAAmB,MAAM,KAAK,IAAI,oBAAoB,KAAK,MAAM,EAEvEA,EAAiB,aAAa,OAAO,MAAO,KAAK,OAAO,KAAO,KAAK,EACpEA,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,SAAA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O,GAAM,WAAa,CAACA,EAAK,SACvD,WAAK,IAAI,SAAS,KAAK,6CAA6CP,EAAS,MAAM,mBAAmB,EAChG,IAAIQ,EAAAA,cAAc,IAAI,IAAID,EAAK,SAAS,CAAC,EAGhD,GAAIP,EAAS,SAAW,IAAK,CAC5B,MAAMC,EAAQ,IAAI,MAAM,QAAQD,EAAS,MAAM,KAAKA,EAAS,UAAU,EAAE,EACzE,WAAK,IAAI,SAAS,MAAM,wBAAyBC,CAAK,EAChDA,CACP,CACD,CAGD,GAAIM,EAAK,YACR,MAAM,KAAK,gBAAgBA,EAAK,WAAW,MAC5C,IAAWA,EAAK,WAAa,CAACA,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"}
|
|
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","redirectUri","formId","body","data","FallbackError"],"mappings":"wRAKO,MAAMA,UAA0BC,EAAAA,eAAgB,CAStD,MAAM,aAAaC,EAA2D,CAM7E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IAAID,EAAK,SAAS,CAAC,EACrCA,EAAK,QACf,KAAK,IAAI,SAAS,KAAK,qBAAqBA,EAAK,MAAM,EAAE,EAG1D,OAAOA,CACR,CACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BaseFlowHandler as a}from"./BaseFlowHandler.mjs";import{State as
|
|
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
2
|
//# sourceMappingURL=NativeFlowHandler.mjs.map
|
|
@@ -1 +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(), { method: 'GET', credentials: 'include' });\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\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}` },\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' },\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,MAAM,aAAaC,EAA2D,CAM7E,GALI,KAAK,IAAI,UACZ,KAAK,IAAI,QAAQ,SAAW,OAC5B,KAAK,IAAI,QAAQ,KAAK,6BAA6B,GAGhDA,EACH,YAAK,UAAYA,EACV,KAAK,WAAA,EAGb,MAAMC,EAAQ,MAAMC,EAAM,OAAA,EACpBC,EAAmB,MAAM,KAAK,IAAI,oBAAoB,KAAK,MAAM,EAEvEA,EAAiB,aAAa,OAAO,MAAO,KAAK,OAAO,KAAO,KAAK,EACpEA,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,SAAA,EAAY,CAAE,OAAQ,MAAO,YAAa,UAAW,EAEzH,GAAI,CAACC,EAAS,GAAI,CACjB,MAAMC,EAAQ,IAAI,MAAM,4CAA4CD,EAAS,MAAM,EAAE,EACrF,WAAK,IAAI,SAAS,MAAM,8BAA+BC,CAAK,EACtDA,CACP,CAEA,IAAIC,EAEJ,GAAI,CACHA,EAAM,IAAI,IAAI,MAAMF,EAAS,MAAM,CACpC,MAAQ,CACPE,EAAM,IAAI,IAAIF,EAAS,GAAG,CA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CAGD,GAAIM,EAAK,YACR,MAAM,KAAK,gBAAgBA,EAAK,WAAW,MAC5C,IAAWA,EAAK,WAAa,CAACA,EAAK,OAAS,CAACA,EAAK,SACjD,WAAK,IAAI,SAAS,KAAK,8DAA8D,EAC/E,IAAIC,EAAc,IAAI,IAAID,EAAK,SAAS,CAAC,EACrCA,EAAK,QACf,KAAK,IAAI,SAAS,KAAK,qBAAqBA,EAAK,MAAM,EAAE,EAG1D,OAAOA,CACR,CACD"}
|
|
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,MAAM,aAAaC,EAA2D,CAM7E,GALI,KAAK,IAAI,UACZ,KAAK,IAAI,QAAQ,SAAW,OAC5B,KAAK,IAAI,QAAQ,KAAK,6BAA6B,GAGhDA,EACH,YAAK,UAAYA,EACV,KAAK,WAAA,EAGb,MAAMC,EAAQ,MAAMC,EAAM,OAAA,EACpBC,EAAmB,MAAM,KAAK,IAAI,oBAAoB,KAAK,MAAM,EAEvEA,EAAiB,aAAa,OAAO,MAAO,KAAK,OAAO,KAAO,KAAK,EACpEA,EAAiB,aAAa,OAAO,QAASF,EAAM,EAAE,EACt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