@strivacity/sdk-core 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/flows/BaseFlow.cjs +1 -1
- package/dist/flows/BaseFlow.cjs.map +1 -1
- package/dist/flows/BaseFlow.d.ts +14 -6
- package/dist/flows/BaseFlow.mjs +1 -1
- package/dist/flows/BaseFlow.mjs.map +1 -1
- package/dist/flows/NativeFlow.cjs +1 -1
- package/dist/flows/NativeFlow.cjs.map +1 -1
- package/dist/flows/NativeFlow.d.ts +6 -2
- package/dist/flows/NativeFlow.mjs +1 -1
- package/dist/flows/NativeFlow.mjs.map +1 -1
- package/dist/flows/PopupFlow.cjs +1 -1
- package/dist/flows/PopupFlow.cjs.map +1 -1
- package/dist/flows/PopupFlow.d.ts +8 -2
- package/dist/flows/PopupFlow.mjs +1 -1
- package/dist/flows/PopupFlow.mjs.map +1 -1
- package/dist/flows/RedirectFlow.cjs +1 -1
- package/dist/flows/RedirectFlow.cjs.map +1 -1
- package/dist/flows/RedirectFlow.d.ts +8 -2
- package/dist/flows/RedirectFlow.mjs +1 -1
- package/dist/flows/RedirectFlow.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/storages/LocalStorage.cjs +1 -1
- package/dist/storages/LocalStorage.cjs.map +1 -1
- package/dist/storages/LocalStorage.mjs +1 -1
- package/dist/storages/LocalStorage.mjs.map +1 -1
- package/dist/storages/SessionStorage.cjs +1 -1
- package/dist/storages/SessionStorage.cjs.map +1 -1
- package/dist/storages/SessionStorage.mjs +1 -1
- package/dist/storages/SessionStorage.mjs.map +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +28 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/HttpClient.cjs +1 -1
- package/dist/utils/HttpClient.cjs.map +1 -1
- package/dist/utils/HttpClient.d.ts +1 -1
- package/dist/utils/HttpClient.mjs +1 -1
- package/dist/utils/HttpClient.mjs.map +1 -1
- package/dist/utils/Logging.cjs +2 -0
- package/dist/utils/Logging.cjs.map +1 -0
- package/dist/utils/Logging.d.ts +8 -0
- package/dist/utils/Logging.mjs +2 -0
- package/dist/utils/Logging.mjs.map +1 -0
- package/dist/utils/Metadata.cjs +1 -1
- package/dist/utils/Metadata.cjs.map +1 -1
- package/dist/utils/Metadata.mjs +1 -1
- package/dist/utils/Metadata.mjs.map +1 -1
- package/dist/utils/NativeFlowHandler.cjs +1 -1
- package/dist/utils/NativeFlowHandler.cjs.map +1 -1
- package/dist/utils/NativeFlowHandler.d.ts +7 -0
- package/dist/utils/NativeFlowHandler.mjs +1 -1
- package/dist/utils/NativeFlowHandler.mjs.map +1 -1
- package/dist/utils/Session.cjs +1 -1
- package/dist/utils/Session.cjs.map +1 -1
- package/dist/utils/Session.mjs +1 -1
- package/dist/utils/Session.mjs.map +1 -1
- package/dist/utils/State.cjs +1 -1
- package/dist/utils/State.cjs.map +1 -1
- package/dist/utils/State.mjs +1 -1
- package/dist/utils/State.mjs.map +1 -1
- package/dist/utils/base64Url.cjs.map +1 -1
- package/dist/utils/base64Url.mjs.map +1 -1
- package/dist/utils/credentials.cjs +1 -1
- package/dist/utils/credentials.cjs.map +1 -1
- package/dist/utils/credentials.mjs +1 -1
- package/dist/utils/credentials.mjs.map +1 -1
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/handlers.cjs +1 -1
- package/dist/utils/handlers.cjs.map +1 -1
- package/dist/utils/handlers.mjs +1 -1
- package/dist/utils/handlers.mjs.map +1 -1
- package/dist/utils/object.cjs.map +1 -1
- package/dist/utils/object.mjs.map +1 -1
- package/package.json +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Metadata.mjs","sources":["../../src/utils/Metadata.ts"],"sourcesContent":["import type { BaseFlow } from '../flows/BaseFlow';\nimport type { MetadataOptions } from '../types';\n\n/**\n * Class responsible for fetching and handling metadata for authentication endpoints.\n */\nexport class Metadata {\n\t/**\n\t * Holds the metadata options once fetched, or null if not yet fetched.\n\t * @protected\n\t */\n\tprotected data: MetadataOptions | null = null;\n\n\t/**\n\t * Retrieves the issuer metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the issuer string.\n\t */\n\tget issuer(): Promise<string> {\n\t\treturn this.getMetadataProperty('issuer');\n\t}\n\n\t/**\n\t * Retrieves the authorization endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the authorization endpoint URL.\n\t */\n\tget authorizationEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('authorization_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the token endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the token endpoint URL.\n\t */\n\tget tokenEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('token_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the user info endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the user info endpoint URL.\n\t */\n\tget userinfoEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('userinfo_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the end session endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the end session endpoint URL.\n\t */\n\tget endSessionEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('end_session_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the revocation endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the revocation endpoint URL.\n\t */\n\tget revocationEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('revocation_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the JWKS URI metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the JWKS URI.\n\t */\n\tget jwksUri(): Promise<string> {\n\t\treturn this.getMetadataProperty('jwks_uri');\n\t}\n\n\t/**\n\t * Creates an instance of the Metadata class.\n\t *\n\t * @param {string} metadataUrl The URL to fetch metadata from.\n\t */\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\n\t\t/**\n\t\t * The URL to fetch metadata from.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tprotected metadataUrl: string,\n\t) {}\n\n\t/**\n\t * Fetches and updates the metadata from the specified URL.\n\t *\n\t * @returns {Promise<void>} A promise that resolves once the metadata is fetched.\n\t */\n\tasync fetchMetadata(): Promise<void> {\n\t\tconst response = await this.sdk.httpClient.request<MetadataOptions>(this.metadataUrl, { method: 'GET' });\n\t\tthis.data = await response.json();\n\t}\n\n\t/**\n\t * Retrieves a specific metadata property.\n\t *\n\t * @template K The key of the metadata property.\n\t * @param {K} key The metadata property key to retrieve.\n\t * @returns {Promise<MetadataOptions[K]>} A promise that resolves to the value of the specified metadata property.\n\t */\n\tasync getMetadataProperty<K extends keyof MetadataOptions>(key: K): Promise<MetadataOptions[K]> {\n\t\tif (this.data?.[key]) {\n\t\t\treturn Promise.resolve(this.data[key]);\n\t\t}\n\n\t\tawait this.fetchMetadata();\n\n\t\treturn Promise.resolve((this.data as MetadataOptions)[key]);\n\t}\n}\n"],"names":["Metadata","sdk","metadataUrl","
|
|
1
|
+
{"version":3,"file":"Metadata.mjs","sources":["../../src/utils/Metadata.ts"],"sourcesContent":["import type { BaseFlow } from '../flows/BaseFlow';\nimport type { MetadataOptions } from '../types';\n\n/**\n * Class responsible for fetching and handling metadata for authentication endpoints.\n */\nexport class Metadata {\n\t/**\n\t * Holds the metadata options once fetched, or null if not yet fetched.\n\t * @protected\n\t */\n\tprotected data: MetadataOptions | null = null;\n\n\t/**\n\t * Retrieves the issuer metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the issuer string.\n\t */\n\tget issuer(): Promise<string> {\n\t\treturn this.getMetadataProperty('issuer');\n\t}\n\n\t/**\n\t * Retrieves the authorization endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the authorization endpoint URL.\n\t */\n\tget authorizationEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('authorization_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the token endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the token endpoint URL.\n\t */\n\tget tokenEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('token_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the user info endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the user info endpoint URL.\n\t */\n\tget userinfoEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('userinfo_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the end session endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the end session endpoint URL.\n\t */\n\tget endSessionEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('end_session_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the revocation endpoint metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the revocation endpoint URL.\n\t */\n\tget revocationEndpoint(): Promise<string> {\n\t\treturn this.getMetadataProperty('revocation_endpoint');\n\t}\n\n\t/**\n\t * Retrieves the JWKS URI metadata.\n\t *\n\t * @returns {Promise<string>} A promise that resolves to the JWKS URI.\n\t */\n\tget jwksUri(): Promise<string> {\n\t\treturn this.getMetadataProperty('jwks_uri');\n\t}\n\n\t/**\n\t * Creates an instance of the Metadata class.\n\t *\n\t * @param {string} metadataUrl The URL to fetch metadata from.\n\t */\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\n\t\t/**\n\t\t * The URL to fetch metadata from.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tprotected metadataUrl: string,\n\t) {}\n\n\t/**\n\t * Fetches and updates the metadata from the specified URL.\n\t *\n\t * @returns {Promise<void>} A promise that resolves once the metadata is fetched.\n\t */\n\tasync fetchMetadata(): Promise<void> {\n\t\ttry {\n\t\t\tconst response = await this.sdk.httpClient.request<MetadataOptions>(this.metadataUrl, { method: 'GET' });\n\t\t\tthis.data = await response.json();\n\t\t} catch (error) {\n\t\t\tthis.sdk.logging?.error('Failed to fetch metadata', error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a specific metadata property.\n\t *\n\t * @template K The key of the metadata property.\n\t * @param {K} key The metadata property key to retrieve.\n\t * @returns {Promise<MetadataOptions[K]>} A promise that resolves to the value of the specified metadata property.\n\t */\n\tasync getMetadataProperty<K extends keyof MetadataOptions>(key: K): Promise<MetadataOptions[K]> {\n\t\tif (this.data?.[key]) {\n\t\t\treturn Promise.resolve(this.data[key]);\n\t\t}\n\n\t\tawait this.fetchMetadata();\n\n\t\treturn Promise.resolve((this.data as MetadataOptions)[key]);\n\t}\n}\n"],"names":["Metadata","sdk","metadataUrl","response","error","key"],"mappings":"AAMO,MAAMA,CAAS,CA2ErB,YAMWC,EAOAC,EACT,CARS,KAAA,IAAAD,EAOA,KAAA,YAAAC,CACR,CApFO,KAA+B,KAOzC,IAAI,QAA0B,CAC7B,OAAO,KAAK,oBAAoB,QAAQ,CACzC,CAOA,IAAI,uBAAyC,CAC5C,OAAO,KAAK,oBAAoB,wBAAwB,CACzD,CAOA,IAAI,eAAiC,CACpC,OAAO,KAAK,oBAAoB,gBAAgB,CACjD,CAOA,IAAI,kBAAoC,CACvC,OAAO,KAAK,oBAAoB,mBAAmB,CACpD,CAOA,IAAI,oBAAsC,CACzC,OAAO,KAAK,oBAAoB,sBAAsB,CACvD,CAOA,IAAI,oBAAsC,CACzC,OAAO,KAAK,oBAAoB,qBAAqB,CACtD,CAOA,IAAI,SAA2B,CAC9B,OAAO,KAAK,oBAAoB,UAAU,CAC3C,CA4BA,MAAM,eAA+B,CACpC,GAAI,CACH,MAAMC,EAAW,MAAM,KAAK,IAAI,WAAW,QAAyB,KAAK,YAAa,CAAE,OAAQ,KAAA,CAAO,EACvG,KAAK,KAAO,MAAMA,EAAS,KAAA,CAC5B,OAASC,EAAO,CACf,WAAK,IAAI,SAAS,MAAM,2BAA4BA,CAAK,EACnDA,CACP,CACD,CASA,MAAM,oBAAqDC,EAAqC,CAC/F,OAAI,KAAK,OAAOA,CAAG,EACX,QAAQ,QAAQ,KAAK,KAAKA,CAAG,CAAC,GAGtC,MAAM,KAAK,cAAA,EAEJ,QAAQ,QAAS,KAAK,KAAyBA,CAAG,CAAC,EAC3D,CACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./State.cjs"),n=require("./errors.cjs");require("./crypto.cjs");require("./base64Url.cjs");require("./date.cjs");class d{constructor(e,i={}){this.sdk=e,this.params=i}sessionId=null;async startSession(e){if(this.sdk.logging&&(this.sdk.logging.xEventId=void 0,this.sdk.logging.info("Starting login flow session")),e)return this.sessionId=e,this.submitForm();const i=await a.State.create(),r=await this.sdk.getAuthorizationUrl(this.params);r.searchParams.append("sdk",this.params.sdk||"web"),r.searchParams.append("state",i.id),r.searchParams.append("code_challenge",i.codeChallenge),r.searchParams.append("nonce",i.nonce),await this.sdk.storage.set(`sty.${i.id}`,JSON.stringify(i));const s=await this.sdk.httpClient.request(r.toString(),{method:"GET",credentials:"include"});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 o=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",o),o}if(!t.toString().startsWith(this.sdk.options.redirectUri)){const o=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",o),o}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(t.toString(),this.sdk.options.responseMode||"fragment"))}if(t.searchParams.has("error")){const o=new Error(`${t.searchParams.get("error")}: ${t.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",o),o}if(!t.searchParams.has("session_id")){const o=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",o),o}return this.sessionId=t.searchParams.get("session_id"),this.submitForm()}async finalizeSession(e){this.sdk.logging?.debug("Finalizing login flow session");const i=await this.sdk.httpClient.request(e,{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`},credentials:"include"}),r=new URL(await i.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(e,i={}){e&&this.sdk.logging?.debug(`Submitting form: ${e}`);const r=await this.sdk.httpClient.request(new URL(`/flow/api/v1/${e?`form/${e}`:"init"}`,this.sdk.options.issuer).toString(),{method:"POST",headers:{Authorization:`Bearer ${this.sessionId}`,"Content-Type":"application/json"},body:JSON.stringify(i),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.FallbackError(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.FallbackError(new URL(s.hostedUrl));s.screen&&this.sdk.logging?.info(`Rendering screen: ${s.screen}`)}return s}}exports.NativeFlowHandler=d;
|
|
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', 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\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":"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"}
|
|
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\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\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: string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, {\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","sdk","params","sessionId","state","State","authorizationUrl","response","uri","error","finalizeUrl","redirectUri","formId","body","data","FallbackError"],"mappings":"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"}
|
|
@@ -37,18 +37,25 @@ export declare class NativeFlowHandler {
|
|
|
37
37
|
*
|
|
38
38
|
* @param {string} [sessionId] - The session ID to start the session with. If not provided, a new session will be created.
|
|
39
39
|
* @returns {Promise<LoginFlowState | void>}
|
|
40
|
+
*
|
|
41
|
+
* @throws {Error} Throws an error if callback handler is not defined, redirect URI is invalid, authorization error occurs, or session ID is missing.
|
|
40
42
|
*/
|
|
41
43
|
startSession(sessionId?: string | null): Promise<LoginFlowState | void>;
|
|
42
44
|
/**
|
|
43
45
|
* Finalizes the session using the provided [finalizeUrl].
|
|
44
46
|
*
|
|
45
47
|
* @param {string} finalizeUrl The URL to finalize the session.
|
|
48
|
+
*
|
|
49
|
+
* @throws {Error} Throws an error if callback handler is not defined or redirect URI is invalid.
|
|
46
50
|
*/
|
|
47
51
|
finalizeSession(finalizeUrl: string): Promise<void>;
|
|
48
52
|
/**
|
|
49
53
|
* Submits a form with the provided [formId] and [data].
|
|
50
54
|
*
|
|
51
55
|
* @returns {Promise<LoginFlowState>}
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} Throws an error if form submission fails.
|
|
58
|
+
* @throws {FallbackError} Throws a fallback error if response indicates fallback is needed.
|
|
52
59
|
*/
|
|
53
60
|
submitForm(formId?: string, body?: Record<string, unknown>): Promise<LoginFlowState>;
|
|
54
61
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{State as a}from"./State.mjs";import{FallbackError as n}from"./errors.mjs";import"./crypto.mjs";import"./base64Url.mjs";import"./date.mjs";class k{constructor(i,e={}){this.sdk=i,this.params=e}sessionId=null;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 e=await a.create(),t=await this.sdk.getAuthorizationUrl(this.params);t.searchParams.append("sdk",this.params.sdk||"web"),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 s=await this.sdk.httpClient.request(t.toString(),{method:"GET",credentials:"include"});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 o=new Error("Missing option: callbackHandler");throw this.sdk.logging?.error("Required option missing",o),o}if(!r.toString().startsWith(this.sdk.options.redirectUri)){const o=new Error("Invalid redirect URI");throw this.sdk.logging?.error("Invalid redirect URI",o),o}return await this.sdk.tokenExchange(await this.sdk.options.callbackHandler(r.toString(),this.sdk.options.responseMode||"fragment"))}if(r.searchParams.has("error")){const o=new Error(`${r.searchParams.get("error")}: ${r.searchParams.get("error_description")}`);throw this.sdk.logging?.error("Authorization error",o),o}if(!r.searchParams.has("session_id")){const o=new Error('"session_id" is missing from the response');throw this.sdk.logging?.error("Failed to start a session",o),o}return this.sessionId=r.searchParams.get("session_id"),this.submitForm()}async finalizeSession(i){this.sdk.logging?.debug("Finalizing login flow session");const e=await this.sdk.httpClient.request(i,{method:"GET",headers:{Authorization:`Bearer ${this.sessionId}`},credentials:"include"}),t=new URL(await e.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(!t.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(t.toString(),this.sdk.options.responseMode||"fragment"))}async submitForm(i,e={}){i&&this.sdk.logging?.debug(`Submitting form: ${i}`);const t=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"},body:JSON.stringify(e),credentials:"include"}),s=await t.json();if(!t.ok&&t.status>=400&&t.status<500){if(t.status!==403&&s?.hostedUrl&&!s.messages)throw this.sdk.logging?.warn(`Triggering fallback due to: Received HTTP ${t.status} without messages`),new n(new URL(s.hostedUrl));if(t.status!==400){const r=new Error(`HTTP ${t.status}: ${t.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 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/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', 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\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":"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"}
|
|
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\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\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: string): Promise<void> {\n\t\tthis.sdk.logging?.debug('Finalizing login flow session');\n\n\t\tconst response = await this.sdk.httpClient.request(finalizeUrl, {\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","sdk","params","sessionId","state","State","authorizationUrl","response","uri","error","finalizeUrl","redirectUri","formId","body","data","FallbackError"],"mappings":"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"}
|
package/dist/utils/Session.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./date.cjs");class r{state=null;code=null;error=null;error_description=null;id_token=null;access_token=null;refresh_token=null;token_type="bearer";scope=null;expires_at=null;claims=null;get expires_in(){return this.expires_at?this.expires_at-l.timestamp():0}set expires_in(e){e!==null&&!isNaN(e)&&(this.expires_at=Math.floor(e)+l.timestamp())}static load(e){if(!e)return null;let t=new r;try{Object.assign(t,JSON.parse(e))}catch{t=null}return t}}exports.Session=r;
|
|
2
2
|
//# sourceMappingURL=Session.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.cjs","sources":["../../src/utils/Session.ts"],"sourcesContent":["import type { IdTokenClaims } from '../types';\nimport { timestamp } from './date';\n\n/**\n * Class representing a user's authentication session, storing tokens and related information.\n */\nexport class Session {\n\t/**\n\t * The state parameter used in the authentication request.\n\t * @type {string | null}\n\t */\n\tstate: string | null = null;\n\n\t/**\n\t * The authorization code returned by the authorization server.\n\t * @type {string | null}\n\t */\n\tcode: string | null = null;\n\n\t/**\n\t * The error returned during the authentication process, if any.\n\t * @type {string | null}\n\t */\n\terror: string | null = null;\n\n\t/**\n\t * A description of the error returned during authentication.\n\t * @type {string | null}\n\t */\n\terror_description: string | null = null;\n\n\t/**\n\t * The ID token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\tid_token: string | null = null;\n\n\t/**\n\t * The access token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\taccess_token: string | null = null;\n\n\t/**\n\t * The refresh token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\trefresh_token: string | null = null;\n\n\t/**\n\t * The type of token issued, defaulting to 'bearer'.\n\t * @type {string}\n\t */\n\ttoken_type = 'bearer';\n\n\t/**\n\t * The scope of the issued token.\n\t * @type {string | null}\n\t */\n\tscope: string | null = null;\n\n\t/**\n\t * The expiration timestamp of the access token, represented in seconds since the epoch.\n\t * @type {number | null}\n\t */\n\texpires_at: number | null = null;\n\n\t/**\n\t * The claims associated with the ID token.\n\t * @type {IdTokenClaims | null}\n\t */\n\tclaims: IdTokenClaims | null = null;\n\n\t/**\n\t * Returns the number of seconds until the access token expires.\n\t * If `expires_at` is not set, returns 0.\n\t *\n\t * @returns {number} The number of seconds until the token expires.\n\t */\n\tget expires_in(): number {\n\t\tif (!this.expires_at) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn this.expires_at - timestamp();\n\t}\n\n\t/**\n\t * Sets the expiration time based on a duration in seconds.\n\t * This also updates the `expires_at` timestamp.\n\t *\n\t * @param {number | null} value The number of seconds until the token expires.\n\t */\n\tset expires_in(value: number | null) {\n\t\tif (value !== null && !isNaN(value)) {\n\t\t\tthis.expires_at = Math.floor(value) + timestamp();\n\t\t}\n\t}\n\n\t/**\n\t * Loads a serialized session from a JSON string.\n\t *\n\t * @param {string | null} serializedSession The JSON string representing a session.\n\t * @returns {Session | null} A new session instance populated with the data from the string, or null if parsing fails.\n\t */\n\tstatic load(serializedSession: string | null): Session | null {\n\t\tif (!serializedSession) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlet session: Session | null = new Session();\n\n\t\ttry {\n\t\t\tObject.assign(session, JSON.parse(serializedSession));\n\t\t} catch {\n\t\t\tsession = null;\n\t\t}\n\n\t\treturn session;\n\t}\n}\n"],"names":["Session","
|
|
1
|
+
{"version":3,"file":"Session.cjs","sources":["../../src/utils/Session.ts"],"sourcesContent":["import type { IdTokenClaims } from '../types';\nimport { timestamp } from './date';\n\n/**\n * Class representing a user's authentication session, storing tokens and related information.\n */\nexport class Session {\n\t/**\n\t * The state parameter used in the authentication request.\n\t * @type {string | null}\n\t */\n\tstate: string | null = null;\n\n\t/**\n\t * The authorization code returned by the authorization server.\n\t * @type {string | null}\n\t */\n\tcode: string | null = null;\n\n\t/**\n\t * The error returned during the authentication process, if any.\n\t * @type {string | null}\n\t */\n\terror: string | null = null;\n\n\t/**\n\t * A description of the error returned during authentication.\n\t * @type {string | null}\n\t */\n\terror_description: string | null = null;\n\n\t/**\n\t * The ID token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\tid_token: string | null = null;\n\n\t/**\n\t * The access token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\taccess_token: string | null = null;\n\n\t/**\n\t * The refresh token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\trefresh_token: string | null = null;\n\n\t/**\n\t * The type of token issued, defaulting to 'bearer'.\n\t * @type {string}\n\t */\n\ttoken_type = 'bearer';\n\n\t/**\n\t * The scope of the issued token.\n\t * @type {string | null}\n\t */\n\tscope: string | null = null;\n\n\t/**\n\t * The expiration timestamp of the access token, represented in seconds since the epoch.\n\t * @type {number | null}\n\t */\n\texpires_at: number | null = null;\n\n\t/**\n\t * The claims associated with the ID token.\n\t * @type {IdTokenClaims | null}\n\t */\n\tclaims: IdTokenClaims | null = null;\n\n\t/**\n\t * Returns the number of seconds until the access token expires.\n\t * If `expires_at` is not set, returns 0.\n\t *\n\t * @returns {number} The number of seconds until the token expires.\n\t */\n\tget expires_in(): number {\n\t\tif (!this.expires_at) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn this.expires_at - timestamp();\n\t}\n\n\t/**\n\t * Sets the expiration time based on a duration in seconds.\n\t * This also updates the `expires_at` timestamp.\n\t *\n\t * @param {number | null} value The number of seconds until the token expires.\n\t */\n\tset expires_in(value: number | null) {\n\t\tif (value !== null && !isNaN(value)) {\n\t\t\tthis.expires_at = Math.floor(value) + timestamp();\n\t\t}\n\t}\n\n\t/**\n\t * Loads a serialized session from a JSON string.\n\t *\n\t * @param {string | null} serializedSession The JSON string representing a session.\n\t * @returns {Session | null} A new session instance populated with the data from the string, or null if parsing fails.\n\t */\n\tstatic load(serializedSession: string | null): Session | null {\n\t\tif (!serializedSession) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlet session: Session | null = new Session();\n\n\t\ttry {\n\t\t\tObject.assign(session, JSON.parse(serializedSession));\n\t\t} catch {\n\t\t\tsession = null;\n\t\t}\n\n\t\treturn session;\n\t}\n}\n"],"names":["Session","timestamp","value","serializedSession","session"],"mappings":"8GAMO,MAAMA,CAAQ,CAKpB,MAAuB,KAMvB,KAAsB,KAMtB,MAAuB,KAMvB,kBAAmC,KAMnC,SAA0B,KAM1B,aAA8B,KAM9B,cAA+B,KAM/B,WAAa,SAMb,MAAuB,KAMvB,WAA4B,KAM5B,OAA+B,KAQ/B,IAAI,YAAqB,CACxB,OAAK,KAAK,WAIH,KAAK,WAAaC,YAAA,EAHjB,CAIT,CAQA,IAAI,WAAWC,EAAsB,CAChCA,IAAU,MAAQ,CAAC,MAAMA,CAAK,IACjC,KAAK,WAAa,KAAK,MAAMA,CAAK,EAAID,EAAAA,UAAA,EAExC,CAQA,OAAO,KAAKE,EAAkD,CAC7D,GAAI,CAACA,EACJ,OAAO,KAGR,IAAIC,EAA0B,IAAIJ,EAElC,GAAI,CACH,OAAO,OAAOI,EAAS,KAAK,MAAMD,CAAiB,CAAC,CACrD,MAAQ,CACPC,EAAU,IACX,CAEA,OAAOA,CACR,CACD"}
|
package/dist/utils/Session.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{timestamp as r}from"./date.mjs";class l{state=null;code=null;error=null;error_description=null;id_token=null;access_token=null;refresh_token=null;token_type="bearer";scope=null;expires_at=null;claims=null;get expires_in(){return this.expires_at?this.expires_at-r():0}set expires_in(e){e!==null&&!isNaN(e)&&(this.expires_at=Math.floor(e)+r())}static load(e){if(!e)return null;let t=new l;try{Object.assign(t,JSON.parse(e))}catch{t=null}return t}}export{l as Session};
|
|
2
2
|
//# sourceMappingURL=Session.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.mjs","sources":["../../src/utils/Session.ts"],"sourcesContent":["import type { IdTokenClaims } from '../types';\nimport { timestamp } from './date';\n\n/**\n * Class representing a user's authentication session, storing tokens and related information.\n */\nexport class Session {\n\t/**\n\t * The state parameter used in the authentication request.\n\t * @type {string | null}\n\t */\n\tstate: string | null = null;\n\n\t/**\n\t * The authorization code returned by the authorization server.\n\t * @type {string | null}\n\t */\n\tcode: string | null = null;\n\n\t/**\n\t * The error returned during the authentication process, if any.\n\t * @type {string | null}\n\t */\n\terror: string | null = null;\n\n\t/**\n\t * A description of the error returned during authentication.\n\t * @type {string | null}\n\t */\n\terror_description: string | null = null;\n\n\t/**\n\t * The ID token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\tid_token: string | null = null;\n\n\t/**\n\t * The access token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\taccess_token: string | null = null;\n\n\t/**\n\t * The refresh token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\trefresh_token: string | null = null;\n\n\t/**\n\t * The type of token issued, defaulting to 'bearer'.\n\t * @type {string}\n\t */\n\ttoken_type = 'bearer';\n\n\t/**\n\t * The scope of the issued token.\n\t * @type {string | null}\n\t */\n\tscope: string | null = null;\n\n\t/**\n\t * The expiration timestamp of the access token, represented in seconds since the epoch.\n\t * @type {number | null}\n\t */\n\texpires_at: number | null = null;\n\n\t/**\n\t * The claims associated with the ID token.\n\t * @type {IdTokenClaims | null}\n\t */\n\tclaims: IdTokenClaims | null = null;\n\n\t/**\n\t * Returns the number of seconds until the access token expires.\n\t * If `expires_at` is not set, returns 0.\n\t *\n\t * @returns {number} The number of seconds until the token expires.\n\t */\n\tget expires_in(): number {\n\t\tif (!this.expires_at) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn this.expires_at - timestamp();\n\t}\n\n\t/**\n\t * Sets the expiration time based on a duration in seconds.\n\t * This also updates the `expires_at` timestamp.\n\t *\n\t * @param {number | null} value The number of seconds until the token expires.\n\t */\n\tset expires_in(value: number | null) {\n\t\tif (value !== null && !isNaN(value)) {\n\t\t\tthis.expires_at = Math.floor(value) + timestamp();\n\t\t}\n\t}\n\n\t/**\n\t * Loads a serialized session from a JSON string.\n\t *\n\t * @param {string | null} serializedSession The JSON string representing a session.\n\t * @returns {Session | null} A new session instance populated with the data from the string, or null if parsing fails.\n\t */\n\tstatic load(serializedSession: string | null): Session | null {\n\t\tif (!serializedSession) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlet session: Session | null = new Session();\n\n\t\ttry {\n\t\t\tObject.assign(session, JSON.parse(serializedSession));\n\t\t} catch {\n\t\t\tsession = null;\n\t\t}\n\n\t\treturn session;\n\t}\n}\n"],"names":["Session","
|
|
1
|
+
{"version":3,"file":"Session.mjs","sources":["../../src/utils/Session.ts"],"sourcesContent":["import type { IdTokenClaims } from '../types';\nimport { timestamp } from './date';\n\n/**\n * Class representing a user's authentication session, storing tokens and related information.\n */\nexport class Session {\n\t/**\n\t * The state parameter used in the authentication request.\n\t * @type {string | null}\n\t */\n\tstate: string | null = null;\n\n\t/**\n\t * The authorization code returned by the authorization server.\n\t * @type {string | null}\n\t */\n\tcode: string | null = null;\n\n\t/**\n\t * The error returned during the authentication process, if any.\n\t * @type {string | null}\n\t */\n\terror: string | null = null;\n\n\t/**\n\t * A description of the error returned during authentication.\n\t * @type {string | null}\n\t */\n\terror_description: string | null = null;\n\n\t/**\n\t * The ID token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\tid_token: string | null = null;\n\n\t/**\n\t * The access token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\taccess_token: string | null = null;\n\n\t/**\n\t * The refresh token issued by the authorization server.\n\t * @type {string | null}\n\t */\n\trefresh_token: string | null = null;\n\n\t/**\n\t * The type of token issued, defaulting to 'bearer'.\n\t * @type {string}\n\t */\n\ttoken_type = 'bearer';\n\n\t/**\n\t * The scope of the issued token.\n\t * @type {string | null}\n\t */\n\tscope: string | null = null;\n\n\t/**\n\t * The expiration timestamp of the access token, represented in seconds since the epoch.\n\t * @type {number | null}\n\t */\n\texpires_at: number | null = null;\n\n\t/**\n\t * The claims associated with the ID token.\n\t * @type {IdTokenClaims | null}\n\t */\n\tclaims: IdTokenClaims | null = null;\n\n\t/**\n\t * Returns the number of seconds until the access token expires.\n\t * If `expires_at` is not set, returns 0.\n\t *\n\t * @returns {number} The number of seconds until the token expires.\n\t */\n\tget expires_in(): number {\n\t\tif (!this.expires_at) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn this.expires_at - timestamp();\n\t}\n\n\t/**\n\t * Sets the expiration time based on a duration in seconds.\n\t * This also updates the `expires_at` timestamp.\n\t *\n\t * @param {number | null} value The number of seconds until the token expires.\n\t */\n\tset expires_in(value: number | null) {\n\t\tif (value !== null && !isNaN(value)) {\n\t\t\tthis.expires_at = Math.floor(value) + timestamp();\n\t\t}\n\t}\n\n\t/**\n\t * Loads a serialized session from a JSON string.\n\t *\n\t * @param {string | null} serializedSession The JSON string representing a session.\n\t * @returns {Session | null} A new session instance populated with the data from the string, or null if parsing fails.\n\t */\n\tstatic load(serializedSession: string | null): Session | null {\n\t\tif (!serializedSession) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlet session: Session | null = new Session();\n\n\t\ttry {\n\t\t\tObject.assign(session, JSON.parse(serializedSession));\n\t\t} catch {\n\t\t\tsession = null;\n\t\t}\n\n\t\treturn session;\n\t}\n}\n"],"names":["Session","timestamp","value","serializedSession","session"],"mappings":"uCAMO,MAAMA,CAAQ,CAKpB,MAAuB,KAMvB,KAAsB,KAMtB,MAAuB,KAMvB,kBAAmC,KAMnC,SAA0B,KAM1B,aAA8B,KAM9B,cAA+B,KAM/B,WAAa,SAMb,MAAuB,KAMvB,WAA4B,KAM5B,OAA+B,KAQ/B,IAAI,YAAqB,CACxB,OAAK,KAAK,WAIH,KAAK,WAAaC,EAAA,EAHjB,CAIT,CAQA,IAAI,WAAWC,EAAsB,CAChCA,IAAU,MAAQ,CAAC,MAAMA,CAAK,IACjC,KAAK,WAAa,KAAK,MAAMA,CAAK,EAAID,EAAA,EAExC,CAQA,OAAO,KAAKE,EAAkD,CAC7D,GAAI,CAACA,EACJ,OAAO,KAGR,IAAIC,EAA0B,IAAIJ,EAElC,GAAI,CACH,OAAO,OAAOI,EAAS,KAAK,MAAMD,CAAiB,CAAC,CACrD,MAAQ,CACPC,EAAU,IACX,CAEA,OAAOA,CACR,CACD"}
|
package/dist/utils/State.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./crypto.cjs"),c=require("./date.cjs");require("./base64Url.cjs");class a{id;createdAt;codeVerifier;codeChallenge;nonce;static async create(){const e=new a;return e.id=n.Crypto.generateState(),e.createdAt=c.timestamp(),e.codeVerifier=n.Crypto.generateCodeVerifier(),e.codeChallenge=await n.Crypto.generateCodeChallenge(e.codeVerifier),e.nonce=n.Crypto.generateNonce(),e}static fromSerializedData(e){const t=new a,r=JSON.parse(e);return t.id=r.id,t.createdAt=r.createdAt,t.codeVerifier=r.codeVerifier,t.codeChallenge=r.codeChallenge,t.nonce=r.nonce,t}}exports.State=a;
|
|
2
2
|
//# sourceMappingURL=State.cjs.map
|
package/dist/utils/State.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.cjs","sources":["../../src/utils/State.ts"],"sourcesContent":["import { Crypto } from './crypto';\nimport { timestamp } from './date';\n\n/**\n * Class representing an OAuth state, including code verifier and nonce for PKCE flows.\n */\nexport class State {\n\t/**\n\t * The unique identifier for the state.\n\t * @type {string}\n\t */\n\tid!: string;\n\n\t/**\n\t * The timestamp when the state was created, represented in seconds since the epoch.\n\t * @type {number}\n\t */\n\tcreatedAt!: number;\n\n\t/**\n\t * The code verifier used in the PKCE (Proof Key for Code Exchange) flow.\n\t * @type {string}\n\t */\n\tcodeVerifier!: string;\n\n\t/**\n\t * The code challenge derived from the code verifier for the PKCE flow.\n\t * @type {string}\n\t */\n\tcodeChallenge!: string;\n\n\t/**\n\t * The nonce value used to associate a client session with an ID token for replay protection.\n\t * @type {string}\n\t */\n\tnonce!: string;\n\n\t/**\n\t * Creates a new instance of `State` with generated values for PKCE and nonce.\n\t *\n\t * @returns {Promise<State>} A promise that resolves to a new `State` instance.\n\t */\n\tstatic async create(): Promise<State> {\n\t\tconst instance = new State();\n\n\t\tinstance.id = Crypto.generateState();\n\t\tinstance.createdAt = timestamp();\n\t\tinstance.codeVerifier = Crypto.generateCodeVerifier();\n\t\tinstance.codeChallenge = await Crypto.generateCodeChallenge(instance.codeVerifier);\n\t\tinstance.nonce = Crypto.generateNonce();\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Deserializes a `State` instance from a JSON string.\n\t *\n\t * @param {string} serializedData The serialized state data as a JSON string.\n\t * @returns {State} A new `State` instance populated with the deserialized data.\n\t */\n\tstatic fromSerializedData(serializedData: string): State {\n\t\tconst instance = new State();\n\t\tconst data = JSON.parse(serializedData);\n\n\t\tinstance.id = data.id;\n\t\tinstance.createdAt = data.createdAt;\n\t\tinstance.codeVerifier = data.codeVerifier;\n\t\tinstance.codeChallenge = data.codeChallenge;\n\t\tinstance.nonce = data.nonce;\n\n\t\treturn instance;\n\t}\n}\n"],"names":["State","
|
|
1
|
+
{"version":3,"file":"State.cjs","sources":["../../src/utils/State.ts"],"sourcesContent":["import { Crypto } from './crypto';\nimport { timestamp } from './date';\n\n/**\n * Class representing an OAuth state, including code verifier and nonce for PKCE flows.\n */\nexport class State {\n\t/**\n\t * The unique identifier for the state.\n\t * @type {string}\n\t */\n\tid!: string;\n\n\t/**\n\t * The timestamp when the state was created, represented in seconds since the epoch.\n\t * @type {number}\n\t */\n\tcreatedAt!: number;\n\n\t/**\n\t * The code verifier used in the PKCE (Proof Key for Code Exchange) flow.\n\t * @type {string}\n\t */\n\tcodeVerifier!: string;\n\n\t/**\n\t * The code challenge derived from the code verifier for the PKCE flow.\n\t * @type {string}\n\t */\n\tcodeChallenge!: string;\n\n\t/**\n\t * The nonce value used to associate a client session with an ID token for replay protection.\n\t * @type {string}\n\t */\n\tnonce!: string;\n\n\t/**\n\t * Creates a new instance of `State` with generated values for PKCE and nonce.\n\t *\n\t * @returns {Promise<State>} A promise that resolves to a new `State` instance.\n\t */\n\tstatic async create(): Promise<State> {\n\t\tconst instance = new State();\n\n\t\tinstance.id = Crypto.generateState();\n\t\tinstance.createdAt = timestamp();\n\t\tinstance.codeVerifier = Crypto.generateCodeVerifier();\n\t\tinstance.codeChallenge = await Crypto.generateCodeChallenge(instance.codeVerifier);\n\t\tinstance.nonce = Crypto.generateNonce();\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Deserializes a `State` instance from a JSON string.\n\t *\n\t * @param {string} serializedData The serialized state data as a JSON string.\n\t * @returns {State} A new `State` instance populated with the deserialized data.\n\t */\n\tstatic fromSerializedData(serializedData: string): State {\n\t\tconst instance = new State();\n\t\tconst data = JSON.parse(serializedData);\n\n\t\tinstance.id = data.id;\n\t\tinstance.createdAt = data.createdAt;\n\t\tinstance.codeVerifier = data.codeVerifier;\n\t\tinstance.codeChallenge = data.codeChallenge;\n\t\tinstance.nonce = data.nonce;\n\n\t\treturn instance;\n\t}\n}\n"],"names":["State","instance","Crypto","timestamp","serializedData","data"],"mappings":"mKAMO,MAAMA,CAAM,CAKlB,GAMA,UAMA,aAMA,cAMA,MAOA,aAAa,QAAyB,CACrC,MAAMC,EAAW,IAAID,EAErB,OAAAC,EAAS,GAAKC,EAAAA,OAAO,cAAA,EACrBD,EAAS,UAAYE,YAAA,EACrBF,EAAS,aAAeC,EAAAA,OAAO,qBAAA,EAC/BD,EAAS,cAAgB,MAAMC,EAAAA,OAAO,sBAAsBD,EAAS,YAAY,EACjFA,EAAS,MAAQC,EAAAA,OAAO,cAAA,EAEjBD,CACR,CAQA,OAAO,mBAAmBG,EAA+B,CACxD,MAAMH,EAAW,IAAID,EACfK,EAAO,KAAK,MAAMD,CAAc,EAEtC,OAAAH,EAAS,GAAKI,EAAK,GACnBJ,EAAS,UAAYI,EAAK,UAC1BJ,EAAS,aAAeI,EAAK,aAC7BJ,EAAS,cAAgBI,EAAK,cAC9BJ,EAAS,MAAQI,EAAK,MAEfJ,CACR,CACD"}
|
package/dist/utils/State.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{Crypto as n}from"./crypto.mjs";import{timestamp as c}from"./date.mjs";import"./base64Url.mjs";class a{id;createdAt;codeVerifier;codeChallenge;nonce;static async create(){const e=new a;return e.id=n.generateState(),e.createdAt=c(),e.codeVerifier=n.generateCodeVerifier(),e.codeChallenge=await n.generateCodeChallenge(e.codeVerifier),e.nonce=n.generateNonce(),e}static fromSerializedData(e){const r=new a,t=JSON.parse(e);return r.id=t.id,r.createdAt=t.createdAt,r.codeVerifier=t.codeVerifier,r.codeChallenge=t.codeChallenge,r.nonce=t.nonce,r}}export{a as State};
|
|
2
2
|
//# sourceMappingURL=State.mjs.map
|
package/dist/utils/State.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.mjs","sources":["../../src/utils/State.ts"],"sourcesContent":["import { Crypto } from './crypto';\nimport { timestamp } from './date';\n\n/**\n * Class representing an OAuth state, including code verifier and nonce for PKCE flows.\n */\nexport class State {\n\t/**\n\t * The unique identifier for the state.\n\t * @type {string}\n\t */\n\tid!: string;\n\n\t/**\n\t * The timestamp when the state was created, represented in seconds since the epoch.\n\t * @type {number}\n\t */\n\tcreatedAt!: number;\n\n\t/**\n\t * The code verifier used in the PKCE (Proof Key for Code Exchange) flow.\n\t * @type {string}\n\t */\n\tcodeVerifier!: string;\n\n\t/**\n\t * The code challenge derived from the code verifier for the PKCE flow.\n\t * @type {string}\n\t */\n\tcodeChallenge!: string;\n\n\t/**\n\t * The nonce value used to associate a client session with an ID token for replay protection.\n\t * @type {string}\n\t */\n\tnonce!: string;\n\n\t/**\n\t * Creates a new instance of `State` with generated values for PKCE and nonce.\n\t *\n\t * @returns {Promise<State>} A promise that resolves to a new `State` instance.\n\t */\n\tstatic async create(): Promise<State> {\n\t\tconst instance = new State();\n\n\t\tinstance.id = Crypto.generateState();\n\t\tinstance.createdAt = timestamp();\n\t\tinstance.codeVerifier = Crypto.generateCodeVerifier();\n\t\tinstance.codeChallenge = await Crypto.generateCodeChallenge(instance.codeVerifier);\n\t\tinstance.nonce = Crypto.generateNonce();\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Deserializes a `State` instance from a JSON string.\n\t *\n\t * @param {string} serializedData The serialized state data as a JSON string.\n\t * @returns {State} A new `State` instance populated with the deserialized data.\n\t */\n\tstatic fromSerializedData(serializedData: string): State {\n\t\tconst instance = new State();\n\t\tconst data = JSON.parse(serializedData);\n\n\t\tinstance.id = data.id;\n\t\tinstance.createdAt = data.createdAt;\n\t\tinstance.codeVerifier = data.codeVerifier;\n\t\tinstance.codeChallenge = data.codeChallenge;\n\t\tinstance.nonce = data.nonce;\n\n\t\treturn instance;\n\t}\n}\n"],"names":["State","
|
|
1
|
+
{"version":3,"file":"State.mjs","sources":["../../src/utils/State.ts"],"sourcesContent":["import { Crypto } from './crypto';\nimport { timestamp } from './date';\n\n/**\n * Class representing an OAuth state, including code verifier and nonce for PKCE flows.\n */\nexport class State {\n\t/**\n\t * The unique identifier for the state.\n\t * @type {string}\n\t */\n\tid!: string;\n\n\t/**\n\t * The timestamp when the state was created, represented in seconds since the epoch.\n\t * @type {number}\n\t */\n\tcreatedAt!: number;\n\n\t/**\n\t * The code verifier used in the PKCE (Proof Key for Code Exchange) flow.\n\t * @type {string}\n\t */\n\tcodeVerifier!: string;\n\n\t/**\n\t * The code challenge derived from the code verifier for the PKCE flow.\n\t * @type {string}\n\t */\n\tcodeChallenge!: string;\n\n\t/**\n\t * The nonce value used to associate a client session with an ID token for replay protection.\n\t * @type {string}\n\t */\n\tnonce!: string;\n\n\t/**\n\t * Creates a new instance of `State` with generated values for PKCE and nonce.\n\t *\n\t * @returns {Promise<State>} A promise that resolves to a new `State` instance.\n\t */\n\tstatic async create(): Promise<State> {\n\t\tconst instance = new State();\n\n\t\tinstance.id = Crypto.generateState();\n\t\tinstance.createdAt = timestamp();\n\t\tinstance.codeVerifier = Crypto.generateCodeVerifier();\n\t\tinstance.codeChallenge = await Crypto.generateCodeChallenge(instance.codeVerifier);\n\t\tinstance.nonce = Crypto.generateNonce();\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Deserializes a `State` instance from a JSON string.\n\t *\n\t * @param {string} serializedData The serialized state data as a JSON string.\n\t * @returns {State} A new `State` instance populated with the deserialized data.\n\t */\n\tstatic fromSerializedData(serializedData: string): State {\n\t\tconst instance = new State();\n\t\tconst data = JSON.parse(serializedData);\n\n\t\tinstance.id = data.id;\n\t\tinstance.createdAt = data.createdAt;\n\t\tinstance.codeVerifier = data.codeVerifier;\n\t\tinstance.codeChallenge = data.codeChallenge;\n\t\tinstance.nonce = data.nonce;\n\n\t\treturn instance;\n\t}\n}\n"],"names":["State","instance","Crypto","timestamp","serializedData","data"],"mappings":"qGAMO,MAAMA,CAAM,CAKlB,GAMA,UAMA,aAMA,cAMA,MAOA,aAAa,QAAyB,CACrC,MAAMC,EAAW,IAAID,EAErB,OAAAC,EAAS,GAAKC,EAAO,cAAA,EACrBD,EAAS,UAAYE,EAAA,EACrBF,EAAS,aAAeC,EAAO,qBAAA,EAC/BD,EAAS,cAAgB,MAAMC,EAAO,sBAAsBD,EAAS,YAAY,EACjFA,EAAS,MAAQC,EAAO,cAAA,EAEjBD,CACR,CAQA,OAAO,mBAAmBG,EAA+B,CACxD,MAAMH,EAAW,IAAID,EACfK,EAAO,KAAK,MAAMD,CAAc,EAEtC,OAAAH,EAAS,GAAKI,EAAK,GACnBJ,EAAS,UAAYI,EAAK,UAC1BJ,EAAS,aAAeI,EAAK,aAC7BJ,EAAS,cAAgBI,EAAK,cAC9BJ,EAAS,MAAQI,EAAK,MAEfJ,CACR,CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64Url.cjs","sources":["../../src/utils/base64Url.ts"],"sourcesContent":["/**\n * Encodes a buffer or string into a Base64 URL-safe string.\n *\n * @param {string | null | BufferSource | ArrayBuffer} buffer The buffer or string to encode.\n * @returns {string} The Base64 URL-encoded string.\n */\nfunction encode(buffer: string | null | BufferSource | ArrayBuffer): string {\n\tif (typeof buffer === 'string') {\n\t\treturn buffer;\n\t}\n\n\tconst str = String.fromCharCode.apply(null, [...new Uint8Array(buffer as ArrayBuffer)]);\n\n\treturn btoa(str).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\n\n/**\n * Decodes a Base64 URL-safe string into an ArrayBuffer.\n *\n * @param {string | BufferSource} base64Url The Base64 URL-safe string or BufferSource to decode.\n * @returns {ArrayBuffer} The decoded ArrayBuffer.\n */\nfunction decode(base64Url: string | BufferSource): ArrayBuffer {\n\tif (typeof base64Url !== 'string') {\n\t\treturn base64Url as ArrayBuffer;\n\t}\n\n\tconst base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/').replace(/\\s/g, '');\n\tconst binStr = atob(base64);\n\tconst binary = new Uint8Array(binStr.length);\n\n\tfor (let i = 0; i < binStr.length; i++) {\n\t\tbinary[i] = binStr.charCodeAt(i);\n\t}\n\n\treturn binary.buffer;\n}\n\n/**\n * Decodes a Base64 URL-safe string into a UTF-8 string.\n *\n * @param {string} base64Url The Base64 URL-safe string to decode.\n * @returns {string} The decoded Unicode string.\n */\nfunction decodeUnicode(base64Url: string): string {\n\treturn decodeURIComponent(\n\t\tatob(base64Url).replace(/(.)/g, (m, p) => {\n\t\t\tlet code = (p as string).charCodeAt(0).toString(16).toUpperCase();\n\t\t\tif (code.length < 2) {\n\t\t\t\tcode = '0' + code;\n\t\t\t}\n\t\t\treturn '%' + code;\n\t\t}),\n\t);\n}\n\nexport const Base64Url = {\n\tencode,\n\tdecode,\n\tdecodeUnicode,\n};\n"],"names":["encode","buffer","str","decode","base64Url","base64","binStr","binary","i","decodeUnicode","m","p","code","Base64Url"],"mappings":"gFAMA,SAASA,EAAOC,EAA4D,CAC3E,GAAI,OAAOA,GAAW,SACrB,OAAOA,EAGR,MAAMC,EAAM,OAAO,aAAa,MAAM,KAAM,CAAC,GAAG,IAAI,WAAWD,CAAqB,CAAC,CAAC,EAEtF,OAAO,KAAKC,CAAG,EAAE,QAAQ,KAAM,EAAE,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,CAC1E,CAQA,SAASC,EAAOC,EAA+C,CAC9D,GAAI,OAAOA,GAAc,SACxB,OAAOA,EAGR,MAAMC,EAASD,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAAE,QAAQ,MAAO,EAAE,EAC1EE,EAAS,KAAKD,CAAM,EACpBE,EAAS,IAAI,WAAWD,EAAO,MAAM,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAClCD,EAAOC,CAAC,EAAIF,EAAO,WAAWE,CAAC,EAGhC,OAAOD,EAAO,MACf,CAQA,SAASE,EAAcL,EAA2B,CACjD,OAAO,mBACN,KAAKA,CAAS,EAAE,QAAQ,OAAQ,CAACM,EAAGC,IAAM,CACzC,IAAIC,EAAQD,EAAa,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAA,EACpD,OAAIC,EAAK,OAAS,IACjBA,EAAO,IAAMA,GAEP,IAAMA,
|
|
1
|
+
{"version":3,"file":"base64Url.cjs","sources":["../../src/utils/base64Url.ts"],"sourcesContent":["/**\n * Encodes a buffer or string into a Base64 URL-safe string.\n *\n * @param {string | null | BufferSource | ArrayBuffer} buffer The buffer or string to encode.\n * @returns {string} The Base64 URL-encoded string.\n */\nfunction encode(buffer: string | null | BufferSource | ArrayBuffer): string {\n\tif (typeof buffer === 'string') {\n\t\treturn buffer;\n\t}\n\n\tconst str = String.fromCharCode.apply(null, [...new Uint8Array(buffer as ArrayBuffer)]);\n\n\treturn btoa(str).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\n\n/**\n * Decodes a Base64 URL-safe string into an ArrayBuffer.\n *\n * @param {string | BufferSource} base64Url The Base64 URL-safe string or BufferSource to decode.\n * @returns {ArrayBuffer} The decoded ArrayBuffer.\n */\nfunction decode(base64Url: string | BufferSource): ArrayBuffer {\n\tif (typeof base64Url !== 'string') {\n\t\treturn base64Url as ArrayBuffer;\n\t}\n\n\tconst base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/').replace(/\\s/g, '');\n\tconst binStr = atob(base64);\n\tconst binary = new Uint8Array(binStr.length);\n\n\tfor (let i = 0; i < binStr.length; i++) {\n\t\tbinary[i] = binStr.charCodeAt(i);\n\t}\n\n\treturn binary.buffer;\n}\n\n/**\n * Decodes a Base64 URL-safe string into a UTF-8 string.\n *\n * @param {string} base64Url The Base64 URL-safe string to decode.\n * @returns {string} The decoded Unicode string.\n */\nfunction decodeUnicode(base64Url: string): string {\n\treturn decodeURIComponent(\n\t\tatob(base64Url).replace(/(.)/g, (m, p) => {\n\t\t\tlet code = (p as string).charCodeAt(0).toString(16).toUpperCase();\n\t\t\tif (code.length < 2) {\n\t\t\t\tcode = '0' + code;\n\t\t\t}\n\t\t\treturn '%' + code;\n\t\t}),\n\t);\n}\n\nexport const Base64Url = {\n\tencode,\n\tdecode,\n\tdecodeUnicode,\n};\n"],"names":["encode","buffer","str","decode","base64Url","base64","binStr","binary","i","decodeUnicode","m","p","code","Base64Url"],"mappings":"gFAMA,SAASA,EAAOC,EAA4D,CAC3E,GAAI,OAAOA,GAAW,SACrB,OAAOA,EAGR,MAAMC,EAAM,OAAO,aAAa,MAAM,KAAM,CAAC,GAAG,IAAI,WAAWD,CAAqB,CAAC,CAAC,EAEtF,OAAO,KAAKC,CAAG,EAAE,QAAQ,KAAM,EAAE,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,CAC1E,CAQA,SAASC,EAAOC,EAA+C,CAC9D,GAAI,OAAOA,GAAc,SACxB,OAAOA,EAGR,MAAMC,EAASD,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAAE,QAAQ,MAAO,EAAE,EAC1EE,EAAS,KAAKD,CAAM,EACpBE,EAAS,IAAI,WAAWD,EAAO,MAAM,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAClCD,EAAOC,CAAC,EAAIF,EAAO,WAAWE,CAAC,EAGhC,OAAOD,EAAO,MACf,CAQA,SAASE,EAAcL,EAA2B,CACjD,OAAO,mBACN,KAAKA,CAAS,EAAE,QAAQ,OAAQ,CAACM,EAAGC,IAAM,CACzC,IAAIC,EAAQD,EAAa,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAA,EACpD,OAAIC,EAAK,OAAS,IACjBA,EAAO,IAAMA,GAEP,IAAMA,CACd,CAAC,CAAA,CAEH,CAEO,MAAMC,EAAY,CACxB,OAAAb,EACA,OAAAG,EACA,cAAAM,CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64Url.mjs","sources":["../../src/utils/base64Url.ts"],"sourcesContent":["/**\n * Encodes a buffer or string into a Base64 URL-safe string.\n *\n * @param {string | null | BufferSource | ArrayBuffer} buffer The buffer or string to encode.\n * @returns {string} The Base64 URL-encoded string.\n */\nfunction encode(buffer: string | null | BufferSource | ArrayBuffer): string {\n\tif (typeof buffer === 'string') {\n\t\treturn buffer;\n\t}\n\n\tconst str = String.fromCharCode.apply(null, [...new Uint8Array(buffer as ArrayBuffer)]);\n\n\treturn btoa(str).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\n\n/**\n * Decodes a Base64 URL-safe string into an ArrayBuffer.\n *\n * @param {string | BufferSource} base64Url The Base64 URL-safe string or BufferSource to decode.\n * @returns {ArrayBuffer} The decoded ArrayBuffer.\n */\nfunction decode(base64Url: string | BufferSource): ArrayBuffer {\n\tif (typeof base64Url !== 'string') {\n\t\treturn base64Url as ArrayBuffer;\n\t}\n\n\tconst base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/').replace(/\\s/g, '');\n\tconst binStr = atob(base64);\n\tconst binary = new Uint8Array(binStr.length);\n\n\tfor (let i = 0; i < binStr.length; i++) {\n\t\tbinary[i] = binStr.charCodeAt(i);\n\t}\n\n\treturn binary.buffer;\n}\n\n/**\n * Decodes a Base64 URL-safe string into a UTF-8 string.\n *\n * @param {string} base64Url The Base64 URL-safe string to decode.\n * @returns {string} The decoded Unicode string.\n */\nfunction decodeUnicode(base64Url: string): string {\n\treturn decodeURIComponent(\n\t\tatob(base64Url).replace(/(.)/g, (m, p) => {\n\t\t\tlet code = (p as string).charCodeAt(0).toString(16).toUpperCase();\n\t\t\tif (code.length < 2) {\n\t\t\t\tcode = '0' + code;\n\t\t\t}\n\t\t\treturn '%' + code;\n\t\t}),\n\t);\n}\n\nexport const Base64Url = {\n\tencode,\n\tdecode,\n\tdecodeUnicode,\n};\n"],"names":["encode","buffer","str","decode","base64Url","base64","binStr","binary","i","decodeUnicode","m","p","code","Base64Url"],"mappings":"AAMA,SAASA,EAAOC,EAA4D,CAC3E,GAAI,OAAOA,GAAW,SACrB,OAAOA,EAGR,MAAMC,EAAM,OAAO,aAAa,MAAM,KAAM,CAAC,GAAG,IAAI,WAAWD,CAAqB,CAAC,CAAC,EAEtF,OAAO,KAAKC,CAAG,EAAE,QAAQ,KAAM,EAAE,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,CAC1E,CAQA,SAASC,EAAOC,EAA+C,CAC9D,GAAI,OAAOA,GAAc,SACxB,OAAOA,EAGR,MAAMC,EAASD,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAAE,QAAQ,MAAO,EAAE,EAC1EE,EAAS,KAAKD,CAAM,EACpBE,EAAS,IAAI,WAAWD,EAAO,MAAM,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAClCD,EAAOC,CAAC,EAAIF,EAAO,WAAWE,CAAC,EAGhC,OAAOD,EAAO,MACf,CAQA,SAASE,EAAcL,EAA2B,CACjD,OAAO,mBACN,KAAKA,CAAS,EAAE,QAAQ,OAAQ,CAACM,EAAGC,IAAM,CACzC,IAAIC,EAAQD,EAAa,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAA,EACpD,OAAIC,EAAK,OAAS,IACjBA,EAAO,IAAMA,GAEP,IAAMA,
|
|
1
|
+
{"version":3,"file":"base64Url.mjs","sources":["../../src/utils/base64Url.ts"],"sourcesContent":["/**\n * Encodes a buffer or string into a Base64 URL-safe string.\n *\n * @param {string | null | BufferSource | ArrayBuffer} buffer The buffer or string to encode.\n * @returns {string} The Base64 URL-encoded string.\n */\nfunction encode(buffer: string | null | BufferSource | ArrayBuffer): string {\n\tif (typeof buffer === 'string') {\n\t\treturn buffer;\n\t}\n\n\tconst str = String.fromCharCode.apply(null, [...new Uint8Array(buffer as ArrayBuffer)]);\n\n\treturn btoa(str).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\n\n/**\n * Decodes a Base64 URL-safe string into an ArrayBuffer.\n *\n * @param {string | BufferSource} base64Url The Base64 URL-safe string or BufferSource to decode.\n * @returns {ArrayBuffer} The decoded ArrayBuffer.\n */\nfunction decode(base64Url: string | BufferSource): ArrayBuffer {\n\tif (typeof base64Url !== 'string') {\n\t\treturn base64Url as ArrayBuffer;\n\t}\n\n\tconst base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/').replace(/\\s/g, '');\n\tconst binStr = atob(base64);\n\tconst binary = new Uint8Array(binStr.length);\n\n\tfor (let i = 0; i < binStr.length; i++) {\n\t\tbinary[i] = binStr.charCodeAt(i);\n\t}\n\n\treturn binary.buffer;\n}\n\n/**\n * Decodes a Base64 URL-safe string into a UTF-8 string.\n *\n * @param {string} base64Url The Base64 URL-safe string to decode.\n * @returns {string} The decoded Unicode string.\n */\nfunction decodeUnicode(base64Url: string): string {\n\treturn decodeURIComponent(\n\t\tatob(base64Url).replace(/(.)/g, (m, p) => {\n\t\t\tlet code = (p as string).charCodeAt(0).toString(16).toUpperCase();\n\t\t\tif (code.length < 2) {\n\t\t\t\tcode = '0' + code;\n\t\t\t}\n\t\t\treturn '%' + code;\n\t\t}),\n\t);\n}\n\nexport const Base64Url = {\n\tencode,\n\tdecode,\n\tdecodeUnicode,\n};\n"],"names":["encode","buffer","str","decode","base64Url","base64","binStr","binary","i","decodeUnicode","m","p","code","Base64Url"],"mappings":"AAMA,SAASA,EAAOC,EAA4D,CAC3E,GAAI,OAAOA,GAAW,SACrB,OAAOA,EAGR,MAAMC,EAAM,OAAO,aAAa,MAAM,KAAM,CAAC,GAAG,IAAI,WAAWD,CAAqB,CAAC,CAAC,EAEtF,OAAO,KAAKC,CAAG,EAAE,QAAQ,KAAM,EAAE,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,CAC1E,CAQA,SAASC,EAAOC,EAA+C,CAC9D,GAAI,OAAOA,GAAc,SACxB,OAAOA,EAGR,MAAMC,EAASD,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAAE,QAAQ,MAAO,EAAE,EAC1EE,EAAS,KAAKD,CAAM,EACpBE,EAAS,IAAI,WAAWD,EAAO,MAAM,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAClCD,EAAOC,CAAC,EAAIF,EAAO,WAAWE,CAAC,EAGhC,OAAOD,EAAO,MACf,CAQA,SAASE,EAAcL,EAA2B,CACjD,OAAO,mBACN,KAAKA,CAAS,EAAE,QAAQ,OAAQ,CAACM,EAAGC,IAAM,CACzC,IAAIC,EAAQD,EAAa,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAA,EACpD,OAAIC,EAAK,OAAS,IACjBA,EAAO,IAAMA,GAEP,IAAMA,CACd,CAAC,CAAA,CAEH,CAEO,MAAMC,EAAY,CACxB,OAAAb,EACA,OAAAG,EACA,cAAAM,CACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./base64Url.cjs");async function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./base64Url.cjs");async function l(e){e.challenge=r.Base64Url.decode(e.challenge),e.user.id=r.Base64Url.decode(e.user.id),e.excludeCredentials&&(e.excludeCredentials=e.excludeCredentials.map(a=>(a.id=r.Base64Url.decode(a.id),a)));const n=new AbortController,t=await navigator.credentials.create({publicKey:e,signal:n.signal});return t.type!=="public-key"?Promise.reject(new Error("Not a public key")):{id:t.id,rawId:r.Base64Url.encode(t.rawId),type:t.type,authenticatorAttachment:t.authenticatorAttachment,response:{clientDataJSON:r.Base64Url.encode(t.response.clientDataJSON),attestationObject:r.Base64Url.encode(t.response.attestationObject),transports:t.response.getTransports?t.response.getTransports():[]}}}async function o(e,n=!1){e.challenge=r.Base64Url.decode(e.challenge),e.allowCredentials&&(e.allowCredentials=e.allowCredentials?.map(s=>(s.id=r.Base64Url.decode(s.id),s)));const t=new AbortController,a=await navigator.credentials.get({publicKey:e,signal:t.signal,mediation:n?"conditional":"optional"});return a.type!=="public-key"?Promise.reject(new Error("Not a public key")):{id:a.id,rawId:r.Base64Url.encode(a.rawId),type:a.type,response:{clientDataJSON:r.Base64Url.encode(a.response.clientDataJSON),authenticatorData:r.Base64Url.encode(a.response.authenticatorData),signature:r.Base64Url.encode(a.response.signature),userHandle:r.Base64Url.encode(a.response.userHandle)}}}exports.createCredential=l;exports.getCredential=o;
|
|
2
2
|
//# sourceMappingURL=credentials.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.cjs","sources":["../../src/utils/credentials.ts"],"sourcesContent":["import type { AssertionCredentialData, AssertionPublicKeyCredential, AttestationCredentialData, AttestationPublicKeyCredential } from '../types';\nimport { Base64Url } from './base64Url';\n\nexport async function createCredential(credentialOptions: PublicKeyCredentialCreationOptions): Promise<AttestationCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\tcredentialOptions.user.id = Base64Url.decode(credentialOptions.user.id);\n\n\tif (credentialOptions.excludeCredentials) {\n\t\tcredentialOptions.excludeCredentials = credentialOptions.excludeCredentials.map((excludeCredential: PublicKeyCredentialDescriptor) => {\n\t\t\texcludeCredential.id = Base64Url.decode(excludeCredential.id);\n\t\t\treturn excludeCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.create({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t})) as AttestationPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tauthenticatorAttachment: credential.authenticatorAttachment,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tattestationObject: Base64Url.encode(credential.response.attestationObject),\n\t\t\ttransports: credential.response.getTransports ? credential.response.getTransports() : [],\n\t\t},\n\t};\n}\n\nexport async function getCredential(credentialOptions: PublicKeyCredentialRequestOptions, conditional = false): Promise<AssertionCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\n\tif (credentialOptions.allowCredentials) {\n\t\tcredentialOptions.allowCredentials = credentialOptions.allowCredentials?.map((allowCredential: PublicKeyCredentialDescriptor) => {\n\t\t\tallowCredential.id = Base64Url.decode(allowCredential.id);\n\t\t\treturn allowCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.get({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t\tmediation: conditional ? 'conditional' : 'optional',\n\t})) as AssertionPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tauthenticatorData: Base64Url.encode(credential.response.authenticatorData),\n\t\t\tsignature: Base64Url.encode(credential.response.signature),\n\t\t\tuserHandle: Base64Url.encode(credential.response.userHandle),\n\t\t},\n\t};\n}\n"],"names":["createCredential","credentialOptions","Base64Url","excludeCredential","credentialsController","credential","getCredential","conditional","
|
|
1
|
+
{"version":3,"file":"credentials.cjs","sources":["../../src/utils/credentials.ts"],"sourcesContent":["import type { AssertionCredentialData, AssertionPublicKeyCredential, AttestationCredentialData, AttestationPublicKeyCredential } from '../types';\nimport { Base64Url } from './base64Url';\n\nexport async function createCredential(credentialOptions: PublicKeyCredentialCreationOptions): Promise<AttestationCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\tcredentialOptions.user.id = Base64Url.decode(credentialOptions.user.id);\n\n\tif (credentialOptions.excludeCredentials) {\n\t\tcredentialOptions.excludeCredentials = credentialOptions.excludeCredentials.map((excludeCredential: PublicKeyCredentialDescriptor) => {\n\t\t\texcludeCredential.id = Base64Url.decode(excludeCredential.id);\n\t\t\treturn excludeCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.create({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t})) as AttestationPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tauthenticatorAttachment: credential.authenticatorAttachment,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tattestationObject: Base64Url.encode(credential.response.attestationObject),\n\t\t\ttransports: credential.response.getTransports ? credential.response.getTransports() : [],\n\t\t},\n\t};\n}\n\nexport async function getCredential(credentialOptions: PublicKeyCredentialRequestOptions, conditional = false): Promise<AssertionCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\n\tif (credentialOptions.allowCredentials) {\n\t\tcredentialOptions.allowCredentials = credentialOptions.allowCredentials?.map((allowCredential: PublicKeyCredentialDescriptor) => {\n\t\t\tallowCredential.id = Base64Url.decode(allowCredential.id);\n\t\t\treturn allowCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.get({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t\tmediation: conditional ? 'conditional' : 'optional',\n\t})) as AssertionPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tauthenticatorData: Base64Url.encode(credential.response.authenticatorData),\n\t\t\tsignature: Base64Url.encode(credential.response.signature),\n\t\t\tuserHandle: Base64Url.encode(credential.response.userHandle),\n\t\t},\n\t};\n}\n"],"names":["createCredential","credentialOptions","Base64Url","excludeCredential","credentialsController","credential","getCredential","conditional","allowCredential"],"mappings":"mHAGA,eAAsBA,EAAiBC,EAA2F,CACjIA,EAAkB,UAAYC,EAAAA,UAAU,OAAOD,EAAkB,SAAS,EAC1EA,EAAkB,KAAK,GAAKC,EAAAA,UAAU,OAAOD,EAAkB,KAAK,EAAE,EAElEA,EAAkB,qBACrBA,EAAkB,mBAAqBA,EAAkB,mBAAmB,IAAKE,IAChFA,EAAkB,GAAKD,EAAAA,UAAU,OAAOC,EAAkB,EAAE,EACrDA,EACP,GAGF,MAAMC,EAAwB,IAAI,gBAC5BC,EAAc,MAAM,UAAU,YAAY,OAAO,CACtD,UAAWJ,EACX,OAAQG,EAAsB,MAAA,CAC9B,EAED,OAAIC,EAAW,OAAS,aAChB,QAAQ,OAAO,IAAI,MAAM,kBAAkB,CAAC,EAG7C,CACN,GAAIA,EAAW,GACf,MAAOH,EAAAA,UAAU,OAAOG,EAAW,KAAK,EACxC,KAAMA,EAAW,KACjB,wBAAyBA,EAAW,wBACpC,SAAU,CACT,eAAgBH,EAAAA,UAAU,OAAOG,EAAW,SAAS,cAAc,EACnE,kBAAmBH,EAAAA,UAAU,OAAOG,EAAW,SAAS,iBAAiB,EACzE,WAAYA,EAAW,SAAS,cAAgBA,EAAW,SAAS,gBAAkB,CAAA,CAAC,CACxF,CAEF,CAEA,eAAsBC,EAAcL,EAAsDM,EAAc,GAAyC,CAChJN,EAAkB,UAAYC,EAAAA,UAAU,OAAOD,EAAkB,SAAS,EAEtEA,EAAkB,mBACrBA,EAAkB,iBAAmBA,EAAkB,kBAAkB,IAAKO,IAC7EA,EAAgB,GAAKN,EAAAA,UAAU,OAAOM,EAAgB,EAAE,EACjDA,EACP,GAGF,MAAMJ,EAAwB,IAAI,gBAC5BC,EAAc,MAAM,UAAU,YAAY,IAAI,CACnD,UAAWJ,EACX,OAAQG,EAAsB,OAC9B,UAAWG,EAAc,cAAgB,UAAA,CACzC,EAED,OAAIF,EAAW,OAAS,aAChB,QAAQ,OAAO,IAAI,MAAM,kBAAkB,CAAC,EAG7C,CACN,GAAIA,EAAW,GACf,MAAOH,EAAAA,UAAU,OAAOG,EAAW,KAAK,EACxC,KAAMA,EAAW,KACjB,SAAU,CACT,eAAgBH,EAAAA,UAAU,OAAOG,EAAW,SAAS,cAAc,EACnE,kBAAmBH,EAAAA,UAAU,OAAOG,EAAW,SAAS,iBAAiB,EACzE,UAAWH,EAAAA,UAAU,OAAOG,EAAW,SAAS,SAAS,EACzD,WAAYH,EAAAA,UAAU,OAAOG,EAAW,SAAS,UAAU,CAAA,CAC5D,CAEF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Base64Url as t}from"./base64Url.mjs";async function
|
|
1
|
+
import{Base64Url as t}from"./base64Url.mjs";async function c(e){e.challenge=t.decode(e.challenge),e.user.id=t.decode(e.user.id),e.excludeCredentials&&(e.excludeCredentials=e.excludeCredentials.map(r=>(r.id=t.decode(r.id),r)));const n=new AbortController,a=await navigator.credentials.create({publicKey:e,signal:n.signal});return a.type!=="public-key"?Promise.reject(new Error("Not a public key")):{id:a.id,rawId:t.encode(a.rawId),type:a.type,authenticatorAttachment:a.authenticatorAttachment,response:{clientDataJSON:t.encode(a.response.clientDataJSON),attestationObject:t.encode(a.response.attestationObject),transports:a.response.getTransports?a.response.getTransports():[]}}}async function l(e,n=!1){e.challenge=t.decode(e.challenge),e.allowCredentials&&(e.allowCredentials=e.allowCredentials?.map(o=>(o.id=t.decode(o.id),o)));const a=new AbortController,r=await navigator.credentials.get({publicKey:e,signal:a.signal,mediation:n?"conditional":"optional"});return r.type!=="public-key"?Promise.reject(new Error("Not a public key")):{id:r.id,rawId:t.encode(r.rawId),type:r.type,response:{clientDataJSON:t.encode(r.response.clientDataJSON),authenticatorData:t.encode(r.response.authenticatorData),signature:t.encode(r.response.signature),userHandle:t.encode(r.response.userHandle)}}}export{c as createCredential,l as getCredential};
|
|
2
2
|
//# sourceMappingURL=credentials.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.mjs","sources":["../../src/utils/credentials.ts"],"sourcesContent":["import type { AssertionCredentialData, AssertionPublicKeyCredential, AttestationCredentialData, AttestationPublicKeyCredential } from '../types';\nimport { Base64Url } from './base64Url';\n\nexport async function createCredential(credentialOptions: PublicKeyCredentialCreationOptions): Promise<AttestationCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\tcredentialOptions.user.id = Base64Url.decode(credentialOptions.user.id);\n\n\tif (credentialOptions.excludeCredentials) {\n\t\tcredentialOptions.excludeCredentials = credentialOptions.excludeCredentials.map((excludeCredential: PublicKeyCredentialDescriptor) => {\n\t\t\texcludeCredential.id = Base64Url.decode(excludeCredential.id);\n\t\t\treturn excludeCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.create({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t})) as AttestationPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tauthenticatorAttachment: credential.authenticatorAttachment,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tattestationObject: Base64Url.encode(credential.response.attestationObject),\n\t\t\ttransports: credential.response.getTransports ? credential.response.getTransports() : [],\n\t\t},\n\t};\n}\n\nexport async function getCredential(credentialOptions: PublicKeyCredentialRequestOptions, conditional = false): Promise<AssertionCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\n\tif (credentialOptions.allowCredentials) {\n\t\tcredentialOptions.allowCredentials = credentialOptions.allowCredentials?.map((allowCredential: PublicKeyCredentialDescriptor) => {\n\t\t\tallowCredential.id = Base64Url.decode(allowCredential.id);\n\t\t\treturn allowCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.get({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t\tmediation: conditional ? 'conditional' : 'optional',\n\t})) as AssertionPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tauthenticatorData: Base64Url.encode(credential.response.authenticatorData),\n\t\t\tsignature: Base64Url.encode(credential.response.signature),\n\t\t\tuserHandle: Base64Url.encode(credential.response.userHandle),\n\t\t},\n\t};\n}\n"],"names":["createCredential","credentialOptions","Base64Url","excludeCredential","credentialsController","credential","getCredential","conditional","
|
|
1
|
+
{"version":3,"file":"credentials.mjs","sources":["../../src/utils/credentials.ts"],"sourcesContent":["import type { AssertionCredentialData, AssertionPublicKeyCredential, AttestationCredentialData, AttestationPublicKeyCredential } from '../types';\nimport { Base64Url } from './base64Url';\n\nexport async function createCredential(credentialOptions: PublicKeyCredentialCreationOptions): Promise<AttestationCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\tcredentialOptions.user.id = Base64Url.decode(credentialOptions.user.id);\n\n\tif (credentialOptions.excludeCredentials) {\n\t\tcredentialOptions.excludeCredentials = credentialOptions.excludeCredentials.map((excludeCredential: PublicKeyCredentialDescriptor) => {\n\t\t\texcludeCredential.id = Base64Url.decode(excludeCredential.id);\n\t\t\treturn excludeCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.create({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t})) as AttestationPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tauthenticatorAttachment: credential.authenticatorAttachment,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tattestationObject: Base64Url.encode(credential.response.attestationObject),\n\t\t\ttransports: credential.response.getTransports ? credential.response.getTransports() : [],\n\t\t},\n\t};\n}\n\nexport async function getCredential(credentialOptions: PublicKeyCredentialRequestOptions, conditional = false): Promise<AssertionCredentialData> {\n\tcredentialOptions.challenge = Base64Url.decode(credentialOptions.challenge);\n\n\tif (credentialOptions.allowCredentials) {\n\t\tcredentialOptions.allowCredentials = credentialOptions.allowCredentials?.map((allowCredential: PublicKeyCredentialDescriptor) => {\n\t\t\tallowCredential.id = Base64Url.decode(allowCredential.id);\n\t\t\treturn allowCredential;\n\t\t});\n\t}\n\n\tconst credentialsController = new AbortController();\n\tconst credential = (await navigator.credentials.get({\n\t\tpublicKey: credentialOptions,\n\t\tsignal: credentialsController.signal,\n\t\tmediation: conditional ? 'conditional' : 'optional',\n\t})) as AssertionPublicKeyCredential;\n\n\tif (credential.type !== 'public-key') {\n\t\treturn Promise.reject(new Error('Not a public key'));\n\t}\n\n\treturn {\n\t\tid: credential.id,\n\t\trawId: Base64Url.encode(credential.rawId),\n\t\ttype: credential.type,\n\t\tresponse: {\n\t\t\tclientDataJSON: Base64Url.encode(credential.response.clientDataJSON),\n\t\t\tauthenticatorData: Base64Url.encode(credential.response.authenticatorData),\n\t\t\tsignature: Base64Url.encode(credential.response.signature),\n\t\t\tuserHandle: Base64Url.encode(credential.response.userHandle),\n\t\t},\n\t};\n}\n"],"names":["createCredential","credentialOptions","Base64Url","excludeCredential","credentialsController","credential","getCredential","conditional","allowCredential"],"mappings":"4CAGA,eAAsBA,EAAiBC,EAA2F,CACjIA,EAAkB,UAAYC,EAAU,OAAOD,EAAkB,SAAS,EAC1EA,EAAkB,KAAK,GAAKC,EAAU,OAAOD,EAAkB,KAAK,EAAE,EAElEA,EAAkB,qBACrBA,EAAkB,mBAAqBA,EAAkB,mBAAmB,IAAKE,IAChFA,EAAkB,GAAKD,EAAU,OAAOC,EAAkB,EAAE,EACrDA,EACP,GAGF,MAAMC,EAAwB,IAAI,gBAC5BC,EAAc,MAAM,UAAU,YAAY,OAAO,CACtD,UAAWJ,EACX,OAAQG,EAAsB,MAAA,CAC9B,EAED,OAAIC,EAAW,OAAS,aAChB,QAAQ,OAAO,IAAI,MAAM,kBAAkB,CAAC,EAG7C,CACN,GAAIA,EAAW,GACf,MAAOH,EAAU,OAAOG,EAAW,KAAK,EACxC,KAAMA,EAAW,KACjB,wBAAyBA,EAAW,wBACpC,SAAU,CACT,eAAgBH,EAAU,OAAOG,EAAW,SAAS,cAAc,EACnE,kBAAmBH,EAAU,OAAOG,EAAW,SAAS,iBAAiB,EACzE,WAAYA,EAAW,SAAS,cAAgBA,EAAW,SAAS,gBAAkB,CAAA,CAAC,CACxF,CAEF,CAEA,eAAsBC,EAAcL,EAAsDM,EAAc,GAAyC,CAChJN,EAAkB,UAAYC,EAAU,OAAOD,EAAkB,SAAS,EAEtEA,EAAkB,mBACrBA,EAAkB,iBAAmBA,EAAkB,kBAAkB,IAAKO,IAC7EA,EAAgB,GAAKN,EAAU,OAAOM,EAAgB,EAAE,EACjDA,EACP,GAGF,MAAMJ,EAAwB,IAAI,gBAC5BC,EAAc,MAAM,UAAU,YAAY,IAAI,CACnD,UAAWJ,EACX,OAAQG,EAAsB,OAC9B,UAAWG,EAAc,cAAgB,UAAA,CACzC,EAED,OAAIF,EAAW,OAAS,aAChB,QAAQ,OAAO,IAAI,MAAM,kBAAkB,CAAC,EAG7C,CACN,GAAIA,EAAW,GACf,MAAOH,EAAU,OAAOG,EAAW,KAAK,EACxC,KAAMA,EAAW,KACjB,SAAU,CACT,eAAgBH,EAAU,OAAOG,EAAW,SAAS,cAAc,EACnE,kBAAmBH,EAAU,OAAOG,EAAW,SAAS,iBAAiB,EACzE,UAAWH,EAAU,OAAOG,EAAW,SAAS,SAAS,EACzD,WAAYH,EAAU,OAAOG,EAAW,SAAS,UAAU,CAAA,CAC5D,CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["export class FallbackError extends Error {\n\tconstructor(public url: URL) {\n\t\tsuper('Fallback occurred');\n\t\tthis.name = 'FallbackError';\n\t}\n}\n"],"names":["FallbackError","url"],"mappings":"gFAAO,MAAMA,UAAsB,KAAM,CACxC,YAAmBC,EAAU,CAC5B,MAAM,mBAAmB,EADP,KAAA,IAAAA,EAElB,KAAK,KAAO,
|
|
1
|
+
{"version":3,"file":"errors.cjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["export class FallbackError extends Error {\n\tconstructor(public url: URL) {\n\t\tsuper('Fallback occurred');\n\t\tthis.name = 'FallbackError';\n\t}\n}\n"],"names":["FallbackError","url"],"mappings":"gFAAO,MAAMA,UAAsB,KAAM,CACxC,YAAmBC,EAAU,CAC5B,MAAM,mBAAmB,EADP,KAAA,IAAAA,EAElB,KAAK,KAAO,eACb,CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["export class FallbackError extends Error {\n\tconstructor(public url: URL) {\n\t\tsuper('Fallback occurred');\n\t\tthis.name = 'FallbackError';\n\t}\n}\n"],"names":["FallbackError","url"],"mappings":"AAAO,MAAMA,UAAsB,KAAM,CACxC,YAAmBC,EAAU,CAC5B,MAAM,mBAAmB,EADP,KAAA,IAAAA,EAElB,KAAK,KAAO,
|
|
1
|
+
{"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["export class FallbackError extends Error {\n\tconstructor(public url: URL) {\n\t\tsuper('Fallback occurred');\n\t\tthis.name = 'FallbackError';\n\t}\n}\n"],"names":["FallbackError","url"],"mappings":"AAAO,MAAMA,UAAsB,KAAM,CACxC,YAAmBC,EAAU,CAC5B,MAAM,mBAAmB,EADP,KAAA,IAAAA,EAElB,KAAK,KAAO,eACb,CACD"}
|
package/dist/utils/handlers.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let n=null;async function p(a,r){const e=r?.targetWindow==="top"?window.top:window.self,t=r?.locationMethod||"assign";return e&&e.location[t](a),new Promise(o=>o())}function h(a=globalThis.window?.location.href,r){const e=new URL(a)[r==="query"?"search":"hash"].slice(1);return Promise.resolve(Object.fromEntries(new URLSearchParams(e)))}async function u(a,r){const e=new Set,t=()=>{n&&(n.closed||n.close(),n=null);for(const i of e)i();e.clear()};n&&t();const o={location:!1,toolbar:!1,height:640,...r?.popupWindowFeatures};if(o.width===void 0&&(o.width=[800,720,600,480].find(i=>i<=window.outerWidth/1.618)??360),o.left=Math.max(0,Math.round(window.screenX+(window.outerWidth-o.width)/2)),o.height!==void 0&&(o.top=Math.max(0,Math.round(window.screenY+(window.outerHeight-o.height)/2))),n=window.open(void 0,r?.popupWindowTarget||"_blank",Object.entries(o).filter(([,i])=>i!==null).map(([i,l])=>`${i}=${typeof l!="boolean"?l:l?"yes":"no"}`).join(",")),!n)throw new Error("Popup window blocked");n.focus(),n.location.replace(a);const w=await new Promise((i,l)=>{const d=s=>{s.origin===window.location.origin&&s.source===n&&s.data&&i(s.data)},c=setInterval(()=>{n?.closed&&(clearInterval(c),l(Error("Popup closed by user")))},500);window.addEventListener("message",d),e.add(()=>window.removeEventListener("message",d)),e.add(()=>clearInterval(c))});return t(),w}function f(a,r){const e={};return r==="fragment"?new URLSearchParams(globalThis.window?.location.hash.replace("#","?")).forEach((t,o)=>e[o]=t):new URLSearchParams(globalThis.window?.location.search).forEach((t,o)=>e[o]=t),globalThis.window?.opener?.postMessage(e,"*"),new Promise(()=>{})}exports.popupCallbackHandler=f;exports.popupUrlHandler=u;exports.redirectCallbackHandler=h;exports.redirectUrlHandler=p;
|
|
2
2
|
//# sourceMappingURL=handlers.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.cjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(url: string, params?: PopupParams): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new Error('Popup window blocked');\n\t}\n\n\tpopupWindow.focus();\n\tpopupWindow.location.replace(url);\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif (event.origin === window.location.origin && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(Error('Popup closed by user'));\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","
|
|
1
|
+
{"version":3,"file":"handlers.cjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(url: string, params?: PopupParams): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new Error('Popup window blocked');\n\t}\n\n\tpopupWindow.focus();\n\tpopupWindow.location.replace(url);\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif (event.origin === window.location.origin && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(Error('Popup closed by user'));\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","responseMode","data","popupUrlHandler","disposables","closeWindow","dispose","popupWindowFeatures","width","value","key","reject","listener","event","timer","popupCallbackHandler","_url","args"],"mappings":"gFAEA,IAAIA,EAAkC,KAStC,eAAeC,EAAmBC,EAAaC,EAAwC,CACtF,MAAMC,EAAeD,GAAQ,eAAiB,MAAQ,OAAO,IAAM,OAAO,KACpEE,EAASF,GAAQ,gBAAkB,SAEzC,OAAIC,GACHA,EAAa,SAASC,CAAM,EAAEH,CAAG,EAI3B,IAAI,QAASI,GAAYA,GAAS,CAC1C,CASA,SAASC,EAAwBL,EAAc,WAAW,QAAQ,SAAS,KAAMM,EAA8D,CAC9I,MAAMC,EAAO,IAAI,IAAIP,CAAG,EAAEM,IAAiB,QAAU,SAAW,MAAM,EAAE,MAAM,CAAC,EAE/E,OAAO,QAAQ,QAAQ,OAAO,YAAY,IAAI,gBAAgBC,CAAI,CAAC,CAAC,CACrE,CAUA,eAAeC,EAAgBR,EAAaC,EAAuD,CAClG,MAAMQ,MAAkB,IAClBC,EAAc,IAAY,CAC3BZ,IACEA,EAAY,QAChBA,EAAY,MAAA,EAGbA,EAAc,MAGf,UAAWa,KAAWF,EACrBE,EAAA,EAGDF,EAAY,MAAA,CACb,EAEIX,GACHY,EAAA,EAGD,MAAME,EAA2C,CAChD,SAAU,GACV,QAAS,GACT,OAAQ,IACR,GAAGX,GAAQ,mBAAA,EAsBZ,GAnBIW,EAAoB,QAAU,SACjCA,EAAoB,MAAQ,CAAC,IAAK,IAAK,IAAK,GAAG,EAAE,KAAMC,GAAUA,GAAS,OAAO,WAAa,KAAK,GAAK,KAGzGD,EAAoB,KAAO,KAAK,IAAI,EAAG,KAAK,MAAM,OAAO,SAAW,OAAO,WAAaA,EAAoB,OAAS,CAAC,CAAC,EAEnHA,EAAoB,SAAW,SAClCA,EAAoB,IAAM,KAAK,IAAI,EAAG,KAAK,MAAM,OAAO,SAAW,OAAO,YAAcA,EAAoB,QAAU,CAAC,CAAC,GAGzHd,EAAc,OAAO,KACpB,OACAG,GAAQ,mBAAqB,SAC7B,OAAO,QAAQW,CAAmB,EAChC,OAAO,CAAC,CAAA,CAAGE,CAAK,IAAMA,IAAU,IAAI,EACpC,IAAI,CAAC,CAACC,EAAKD,CAAK,IAAM,GAAGC,CAAG,IAAI,OAAOD,GAAU,UAAaA,EAAmBA,EAAQ,MAAQ,IAAI,EAAE,EACvG,KAAK,GAAG,CAAA,EAGP,CAAChB,EACJ,MAAM,IAAI,MAAM,sBAAsB,EAGvCA,EAAY,MAAA,EACZA,EAAY,SAAS,QAAQE,CAAG,EAEhC,MAAMO,EAAO,MAAM,IAAI,QAAgC,CAACH,EAASY,IAAW,CAC3E,MAAMC,EAAYC,GAAgD,CAC7DA,EAAM,SAAW,OAAO,SAAS,QAAUA,EAAM,SAAWpB,GAAeoB,EAAM,MACpFd,EAAQc,EAAM,IAAI,CAEpB,EAEMC,EAAQ,YAAY,IAAM,CAC3BrB,GAAa,SAChB,cAAcqB,CAAK,EACnBH,EAAO,MAAM,sBAAsB,CAAC,EAEtC,EAAG,GAAG,EAEN,OAAO,iBAAiB,UAAWC,CAAQ,EAC3CR,EAAY,IAAI,IAAM,OAAO,oBAAoB,UAAWQ,CAAQ,CAAC,EACrER,EAAY,IAAI,IAAM,cAAcU,CAAK,CAAC,CAC3C,CAAC,EAED,OAAAT,EAAA,EAEOH,CACR,CAQA,SAASa,EAAqBC,EAAef,EAA4C,CACxF,MAAMgB,EAA+B,CAAA,EAErC,OAAIhB,IAAiB,WACpB,IAAI,gBAAgB,WAAW,QAAQ,SAAS,KAAK,QAAQ,IAAK,GAAG,CAAC,EAAE,QAAQ,CAACQ,EAAOC,IAASO,EAAKP,CAAG,EAAID,CAAM,EAEnH,IAAI,gBAAgB,WAAW,QAAQ,SAAS,MAAM,EAAE,QAAQ,CAACA,EAAOC,IAASO,EAAKP,CAAG,EAAID,CAAM,EAGpG,WAAW,QAAQ,QAAQ,YAAYQ,EAAM,GAAG,EAGzC,IAAI,QAAQ,IAAA,EAAe,CACnC"}
|
package/dist/utils/handlers.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let
|
|
1
|
+
let n=null;async function h(a,i){const e=i?.targetWindow==="top"?window.top:window.self,r=i?.locationMethod||"assign";return e&&e.location[r](a),new Promise(o=>o())}function p(a=globalThis.window?.location.href,i){const e=new URL(a)[i==="query"?"search":"hash"].slice(1);return Promise.resolve(Object.fromEntries(new URLSearchParams(e)))}async function f(a,i){const e=new Set,r=()=>{n&&(n.closed||n.close(),n=null);for(const t of e)t();e.clear()};n&&r();const o={location:!1,toolbar:!1,height:640,...i?.popupWindowFeatures};if(o.width===void 0&&(o.width=[800,720,600,480].find(t=>t<=window.outerWidth/1.618)??360),o.left=Math.max(0,Math.round(window.screenX+(window.outerWidth-o.width)/2)),o.height!==void 0&&(o.top=Math.max(0,Math.round(window.screenY+(window.outerHeight-o.height)/2))),n=window.open(void 0,i?.popupWindowTarget||"_blank",Object.entries(o).filter(([,t])=>t!==null).map(([t,s])=>`${t}=${typeof s!="boolean"?s:s?"yes":"no"}`).join(",")),!n)throw new Error("Popup window blocked");n.focus(),n.location.replace(a);const w=await new Promise((t,s)=>{const l=d=>{d.origin===window.location.origin&&d.source===n&&d.data&&t(d.data)},c=setInterval(()=>{n?.closed&&(clearInterval(c),s(Error("Popup closed by user")))},500);window.addEventListener("message",l),e.add(()=>window.removeEventListener("message",l)),e.add(()=>clearInterval(c))});return r(),w}function u(a,i){const e={};return i==="fragment"?new URLSearchParams(globalThis.window?.location.hash.replace("#","?")).forEach((r,o)=>e[o]=r):new URLSearchParams(globalThis.window?.location.search).forEach((r,o)=>e[o]=r),globalThis.window?.opener?.postMessage(e,"*"),new Promise(()=>{})}export{u as popupCallbackHandler,f as popupUrlHandler,p as redirectCallbackHandler,h as redirectUrlHandler};
|
|
2
2
|
//# sourceMappingURL=handlers.mjs.map
|