@strivacity/sdk-core 2.0.0 → 2.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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var l=(a,t,e)=>t in a?d(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var n=(a,t,e)=>l(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./State.cjs"),o=require("./errors.cjs");require("./crypto.cjs");require("./base64Url.cjs");require("./date.cjs");class c{constructor(t,e={}){n(this,"sessionId",null);this.sdk=t,this.params=e}async startSession(t){if(t)return this.sessionId=t,this.submitForm();const e=await h.State.create(),s=await this.sdk.getAuthorizationUrl(this.params);s.searchParams.append("sdk","web"),s.searchParams.append("state",e.id),s.searchParams.append("code_challenge",e.codeChallenge),s.searchParams.append("nonce",e.nonce),await this.sdk.storage.set(`sty.${e.id}`,JSON.stringify(e));const r=await this.sdk.httpClient.request(s.toString(),{method:"GET",credentials:"include"}),i=new URL(await r.text());if(i.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!i.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(i.toString(),this.sdk.options.responseMode||"fragment"))}if(i.searchParams.has("error"))throw new Error(`${i.searchParams.get("error")}: ${i.searchParams.get("error_description")}`);if(!i.searchParams.has("session_id"))throw new Error('Failed to start a session: "session_id" is missing');return this.sessionId=i.searchParams.get("session_id"),this.submitForm()}async finalizeSession(t){const e=await this.sdk.httpClient.request(t,{method:"GET",credentials:"include"}),s=new URL(await e.text());if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!s.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(s.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(t,e={}){const s=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${t?`form/${t}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"}),r=await s.json();if(!s.ok&&s.status>=400&&s.status<500){if(s.status!==403&&(r!=null&&r.hostedUrl))throw new o.FallbackError(new URL(r.hostedUrl));if(s.status!==400)throw new Error(`HTTP ${s.status}: ${s.statusText}`)}if(r.finalizeUrl)await this.finalizeSession(r.finalizeUrl);else if(r.hostedUrl&&!r.forms&&!r.messages)throw new o.FallbackError(new URL(r.hostedUrl));return r}}exports.NativeFlowHandler=c;
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=(a,t,e)=>t in a?d(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var n=(a,t,e)=>l(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./State.cjs"),o=require("./errors.cjs");require("./crypto.cjs");require("./base64Url.cjs");require("./date.cjs");class c{constructor(t,e={}){n(this,"sessionId",null);this.sdk=t,this.params=e}async startSession(t){if(t)return this.sessionId=t,this.submitForm();const e=await h.State.create(),s=await this.sdk.getAuthorizationUrl(this.params);s.searchParams.append("sdk","web"),s.searchParams.append("state",e.id),s.searchParams.append("code_challenge",e.codeChallenge),s.searchParams.append("nonce",e.nonce),await this.sdk.storage.set(`sty.${e.id}`,JSON.stringify(e));const r=await this.sdk.httpClient.request(s.toString(),{method:"GET",credentials:"include"}),i=new URL(await r.text());if(i.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!i.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(i.toString(),this.sdk.options.responseMode||"fragment"))}if(i.searchParams.has("error"))throw new Error(`${i.searchParams.get("error")}: ${i.searchParams.get("error_description")}`);if(!i.searchParams.has("session_id"))throw new Error('Failed to start a session: "session_id" is missing');return this.sessionId=i.searchParams.get("session_id"),this.submitForm()}async finalizeSession(t){const e=await this.sdk.httpClient.request(t,{method:"GET",credentials:"include"}),s=new URL(await e.text());if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!s.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(s.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(t,e={}){const s=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${t?`form/${t}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"}),r=await s.json();if(!s.ok&&s.status>=400&&s.status<500){if(s.status!==403&&(r!=null&&r.hostedUrl)&&!r.messages)throw new o.FallbackError(new URL(r.hostedUrl));if(s.status!==400)throw new Error(`HTTP ${s.status}: ${s.statusText}`)}if(r.finalizeUrl)await this.finalizeSession(r.finalizeUrl);else if(r.hostedUrl&&!r.forms&&!r.messages)throw new o.FallbackError(new URL(r.hostedUrl));return r}}exports.NativeFlowHandler=c;
|
|
2
2
|
//# sourceMappingURL=NativeFlowHandler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeFlowHandler.cjs","sources":["../../src/utils/NativeFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\nimport { State } from './State';\nimport { FallbackError } from './errors';\n\nexport class NativeFlowHandler {\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\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\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', '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\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (redirectUri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t\t}\n\t\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tthrow new Error('Invalid redirect URI');\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (redirectUri.searchParams.has('error')) {\n\t\t\tthrow new Error(`${redirectUri.searchParams.get('error')}: ${redirectUri.searchParams.get('error_description')}`);\n\t\t}\n\n\t\tif (!redirectUri.searchParams.has('session_id')) {\n\t\t\tthrow new Error('Failed to start a session: \"session_id\" is missing');\n\t\t}\n\n\t\tthis.sessionId = redirectUri.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\tasync finalizeSession(finalizeUrl: string): Promise<void> {\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, { method: 'GET', credentials: 'include' });\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tthrow new Error('Invalid redirect URI');\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\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\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) {\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\tthrow new Error(`HTTP ${response.status}: ${response.statusText}`);\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\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","sdk","params","__publicField","sessionId","state","State","authorizationUrl","response","redirectUri","finalizeUrl","formId","body","data","FallbackError"],"mappings":"sXAKO,MAAMA,CAAkB,CAQ9B,YAMWC,EAMAC,EAAuB,GAChC,CAfQC,EAAA,iBAA2B,MAQ1B,KAAA,IAAAF,EAMA,KAAA,OAAAC,CAAA,CASX,MAAM,aAAaE,EAA2D,CAC7E,GAAIA,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,EACjDA,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,EACnHE,EAAc,IAAI,IAAI,MAAMD,EAAS,MAAM,EAEjD,GAAIC,EAAY,aAAa,IAAI,MAAM,EAAG,CACzC,GAAI,OAAO,KAAK,IAAI,QAAQ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F,CACC,OAAQ,OACR,QAAS,CAAE,cAAe,UAAU,KAAK,SAAS,GAAI,eAAgB,kBAAA,EACtE,KAAM,KAAK,UAAUC,CAAI,EACzB,YAAa,SAAA,CACd,EAEKC,EAAO,MAAML,EAAS,KAAA,EAE5B,GAAI,CAACA,EAAS,IACTA,EAAS,QAAU,KAAOA,EAAS,OAAS,IAAK,CACpD,GAAIA,EAAS,SAAW,MAAOK,GAAA,MAAAA,EAAM,
|
|
1
|
+
{"version":3,"file":"NativeFlowHandler.cjs","sources":["../../src/utils/NativeFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\nimport { State } from './State';\nimport { FallbackError } from './errors';\n\nexport class NativeFlowHandler {\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\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\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', '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\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (redirectUri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t\t}\n\t\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tthrow new Error('Invalid redirect URI');\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (redirectUri.searchParams.has('error')) {\n\t\t\tthrow new Error(`${redirectUri.searchParams.get('error')}: ${redirectUri.searchParams.get('error_description')}`);\n\t\t}\n\n\t\tif (!redirectUri.searchParams.has('session_id')) {\n\t\t\tthrow new Error('Failed to start a session: \"session_id\" is missing');\n\t\t}\n\n\t\tthis.sessionId = redirectUri.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\tasync finalizeSession(finalizeUrl: string): Promise<void> {\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, { method: 'GET', credentials: 'include' });\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tthrow new Error('Invalid redirect URI');\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\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\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\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\tthrow new Error(`HTTP ${response.status}: ${response.statusText}`);\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\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","sdk","params","__publicField","sessionId","state","State","authorizationUrl","response","redirectUri","finalizeUrl","formId","body","data","FallbackError"],"mappings":"sXAKO,MAAMA,CAAkB,CAQ9B,YAMWC,EAMAC,EAAuB,GAChC,CAfQC,EAAA,iBAA2B,MAQ1B,KAAA,IAAAF,EAMA,KAAA,OAAAC,CAAA,CASX,MAAM,aAAaE,EAA2D,CAC7E,GAAIA,EACH,YAAK,UAAYA,EACV,KAAK,WAAA,EAGb,MAAMC,EAAQ,MAAMC,EAAAA,MAAM,OAAA,EACpBC,EAAmB,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var d=Object.defineProperty;var h=(a,t,e)=>t in a?d(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var n=(a,t,e)=>h(a,typeof t!="symbol"?t+"":t,e);import{State as c}from"./State.mjs";import{FallbackError as o}from"./errors.mjs";import"./crypto.mjs";import"./base64Url.mjs";import"./date.mjs";class u{constructor(t,e={}){n(this,"sessionId",null);this.sdk=t,this.params=e}async startSession(t){if(t)return this.sessionId=t,this.submitForm();const e=await c.create(),s=await this.sdk.getAuthorizationUrl(this.params);s.searchParams.append("sdk","web"),s.searchParams.append("state",e.id),s.searchParams.append("code_challenge",e.codeChallenge),s.searchParams.append("nonce",e.nonce),await this.sdk.storage.set(`sty.${e.id}`,JSON.stringify(e));const i=await this.sdk.httpClient.request(s.toString(),{method:"GET",credentials:"include"}),r=new URL(await i.text());if(r.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!r.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error"))throw new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);if(!r.searchParams.has("session_id"))throw new Error('Failed to start a session: "session_id" is missing');return this.sessionId=r.searchParams.get("session_id"),this.submitForm()}async finalizeSession(t){const e=await this.sdk.httpClient.request(t,{method:"GET",credentials:"include"}),s=new URL(await e.text());if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!s.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(s.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(t,e={}){const s=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${t?`form/${t}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"}),i=await s.json();if(!s.ok&&s.status>=400&&s.status<500){if(s.status!==403&&(i!=null&&i.hostedUrl))throw new o(new URL(i.hostedUrl));if(s.status!==400)throw new Error(`HTTP ${s.status}: ${s.statusText}`)}if(i.finalizeUrl)await this.finalizeSession(i.finalizeUrl);else if(i.hostedUrl&&!i.forms&&!i.messages)throw new o(new URL(i.hostedUrl));return i}}export{u as NativeFlowHandler};
|
|
1
|
+
var d=Object.defineProperty;var h=(a,t,e)=>t in a?d(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var n=(a,t,e)=>h(a,typeof t!="symbol"?t+"":t,e);import{State as c}from"./State.mjs";import{FallbackError as o}from"./errors.mjs";import"./crypto.mjs";import"./base64Url.mjs";import"./date.mjs";class u{constructor(t,e={}){n(this,"sessionId",null);this.sdk=t,this.params=e}async startSession(t){if(t)return this.sessionId=t,this.submitForm();const e=await c.create(),s=await this.sdk.getAuthorizationUrl(this.params);s.searchParams.append("sdk","web"),s.searchParams.append("state",e.id),s.searchParams.append("code_challenge",e.codeChallenge),s.searchParams.append("nonce",e.nonce),await this.sdk.storage.set(`sty.${e.id}`,JSON.stringify(e));const i=await this.sdk.httpClient.request(s.toString(),{method:"GET",credentials:"include"}),r=new URL(await i.text());if(r.searchParams.has("code")){if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!r.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error"))throw new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);if(!r.searchParams.has("session_id"))throw new Error('Failed to start a session: "session_id" is missing');return this.sessionId=r.searchParams.get("session_id"),this.submitForm()}async finalizeSession(t){const e=await this.sdk.httpClient.request(t,{method:"GET",credentials:"include"}),s=new URL(await e.text());if(typeof this.sdk.options.callbackHandler!="function")throw new Error("Callback handler is not defined. Please provide a valid callback handler function in the SDK options.");if(!s.toString().startsWith(this.sdk.options.redirectUri))throw new Error("Invalid redirect URI");await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(s.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(t,e={}){const s=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${t?`form/${t}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"}),i=await s.json();if(!s.ok&&s.status>=400&&s.status<500){if(s.status!==403&&(i!=null&&i.hostedUrl)&&!i.messages)throw new o(new URL(i.hostedUrl));if(s.status!==400)throw new Error(`HTTP ${s.status}: ${s.statusText}`)}if(i.finalizeUrl)await this.finalizeSession(i.finalizeUrl);else if(i.hostedUrl&&!i.forms&&!i.messages)throw new o(new URL(i.hostedUrl));return i}}export{u as NativeFlowHandler};
|
|
2
2
|
//# sourceMappingURL=NativeFlowHandler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeFlowHandler.mjs","sources":["../../src/utils/NativeFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\nimport { State } from './State';\nimport { FallbackError } from './errors';\n\nexport class NativeFlowHandler {\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\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\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', '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\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (redirectUri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t\t}\n\t\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tthrow new Error('Invalid redirect URI');\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (redirectUri.searchParams.has('error')) {\n\t\t\tthrow new Error(`${redirectUri.searchParams.get('error')}: ${redirectUri.searchParams.get('error_description')}`);\n\t\t}\n\n\t\tif (!redirectUri.searchParams.has('session_id')) {\n\t\t\tthrow new Error('Failed to start a session: \"session_id\" is missing');\n\t\t}\n\n\t\tthis.sessionId = redirectUri.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\tasync finalizeSession(finalizeUrl: string): Promise<void> {\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, { method: 'GET', credentials: 'include' });\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tthrow new Error('Invalid redirect URI');\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\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\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) {\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\tthrow new Error(`HTTP ${response.status}: ${response.statusText}`);\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\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","sdk","params","__publicField","sessionId","state","State","authorizationUrl","response","redirectUri","finalizeUrl","formId","body","data","FallbackError"],"mappings":"qTAKO,MAAMA,CAAkB,CAQ9B,YAMWC,EAMAC,EAAuB,GAChC,CAfQC,EAAA,iBAA2B,MAQ1B,KAAA,IAAAF,EAMA,KAAA,OAAAC,CAAA,CASX,MAAM,aAAaE,EAA2D,CAC7E,GAAIA,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,EACjDA,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,EACnHE,EAAc,IAAI,IAAI,MAAMD,EAAS,MAAM,EAEjD,GAAIC,EAAY,aAAa,IAAI,MAAM,EAAG,CACzC,GAAI,OAAO,KAAK,IAAI,QAAQ,iBAAoB,WAC/C,MAAM,IAAI,MAAM,uGAAuG,EAExH,GAAI,CAACA,EAAY,WAAW,WAAW,KAAK,IAAI,QAAQ,WAAW,EAClE,MAAM,IAAI,MAAM,sBAAsB,EAGvC,OAAO,MAAM,KAAK,IAAI,cACpB,MAAM,KAAK,IAAI,QAAQ,gBAAgBA,EAAY,SAAA,EAAY,KAAK,IAAI,QAAQ,cAAgB,UAAU,CAAA,CAC5G,CAGD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AM,
|
|
1
|
+
{"version":3,"file":"NativeFlowHandler.mjs","sources":["../../src/utils/NativeFlowHandler.ts"],"sourcesContent":["import type { NativeParams, LoginFlowState } from '../types';\nimport type { BaseFlow } from '../flows/BaseFlow';\nimport { State } from './State';\nimport { FallbackError } from './errors';\n\nexport class NativeFlowHandler {\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\tasync startSession(sessionId?: string | null): Promise<LoginFlowState | void> {\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', '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\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (redirectUri.searchParams.has('code')) {\n\t\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t\t}\n\t\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\t\tthrow new Error('Invalid redirect URI');\n\t\t\t}\n\n\t\t\treturn await this.sdk.tokenExchange(\n\t\t\t\t(await this.sdk.options.callbackHandler(redirectUri.toString(), this.sdk.options.responseMode || 'fragment')) as Record<string, string>,\n\t\t\t);\n\t\t}\n\n\t\tif (redirectUri.searchParams.has('error')) {\n\t\t\tthrow new Error(`${redirectUri.searchParams.get('error')}: ${redirectUri.searchParams.get('error_description')}`);\n\t\t}\n\n\t\tif (!redirectUri.searchParams.has('session_id')) {\n\t\t\tthrow new Error('Failed to start a session: \"session_id\" is missing');\n\t\t}\n\n\t\tthis.sessionId = redirectUri.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\tasync finalizeSession(finalizeUrl: string): Promise<void> {\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, { method: 'GET', credentials: 'include' });\n\t\tconst redirectUri = new URL(await response.text());\n\n\t\tif (typeof this.sdk.options.callbackHandler !== 'function') {\n\t\t\tthrow new Error('Callback handler is not defined. Please provide a valid callback handler function in the SDK options.');\n\t\t}\n\n\t\tif (!redirectUri.toString().startsWith(this.sdk.options.redirectUri)) {\n\t\t\tthrow new Error('Invalid redirect URI');\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\tasync submitForm(formId?: string, body: Record<string, unknown> = {}): Promise<LoginFlowState> {\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\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\tthrow new Error(`HTTP ${response.status}: ${response.statusText}`);\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\tthrow new FallbackError(new URL(data.hostedUrl));\n\t\t}\n\n\t\treturn data;\n\t}\n}\n"],"names":["NativeFlowHandler","sdk","params","__publicField","sessionId","state","State","authorizationUrl","response","redirectUri","finalizeUrl","formId","body","data","FallbackError"],"mappings":"qTAKO,MAAMA,CAAkB,CAQ9B,YAMWC,EAMAC,EAAuB,GAChC,CAfQC,EAAA,iBAA2B,MAQ1B,KAAA,IAAAF,EAMA,KAAA,OAAAC,CAAA,CASX,MAAM,aAAaE,EAA2D,CAC7E,GAAIA,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,EACjDA,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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