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ified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@nangohq/frontend@0.70.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n * Copyright (c) 2025 Nango, all rights reserved.\n */\nimport { AuthorizationModal, computeLayout, windowFeaturesToString } from './authModal.js';\nimport { ConnectUI } from './connectUI.js';\nexport * from './connectUI.js';\nconst prodHost = 'https://api.nango.dev';\nconst debugLogPrefix = 'NANGO DEBUG LOG: ';\nexport class AuthError extends Error {\n    type;\n    constructor(message, type) {\n        super(message);\n        this.type = type;\n    }\n}\nexport default class Nango {\n    hostBaseUrl;\n    websocketsBaseUrl;\n    publicKey;\n    connectSessionToken;\n    debug = false;\n    width = 500;\n    height = 600;\n    tm = null;\n    // Do not rename, part of the public api\n    win = null;\n    constructor(config = {}) {\n        config.host = config.host || prodHost; // Default to Nango Cloud.\n        config.websocketsPath = config.websocketsPath || '/'; // Default to root path.\n        this.debug = config.debug || false;\n        if (this.debug) {\n            console.log(debugLogPrefix, `Debug mode is enabled.`);\n            console.log(debugLogPrefix, `Using host: ${config.host}.`);\n        }\n        if (config.width) {\n            this.width = config.width;\n        }\n        if (config.height) {\n            this.height = config.height;\n        }\n        this.hostBaseUrl = config.host.replace(/\\/+$/, ''); // Remove trailing slash.\n        this.publicKey = config.publicKey;\n        this.connectSessionToken = config.connectSessionToken;\n        try {\n            const baseUrl = new URL(this.hostBaseUrl);\n            // Build the websockets url based on the host url.\n            // The websockets path is considered relative to the baseUrl, and with the protocol updated\n            const websocketUrl = new URL(config.websocketsPath, baseUrl);\n            this.websocketsBaseUrl = websocketUrl.toString().replace('https://', 'wss://').replace('http://', 'ws://');\n        }\n        catch {\n            throw new AuthError('Invalid URL provided for the Nango host.', 'invalid_host_url');\n        }\n    }\n    async create(providerConfigKey, connectionIdOrConnectionConfig, moreConnectionConfig) {\n        this.ensureCredentials();\n        let connectionId = null;\n        let connectionConfig = moreConnectionConfig;\n        if (typeof connectionIdOrConnectionConfig === 'string') {\n            connectionId = connectionIdOrConnectionConfig;\n        }\n        else {\n            connectionConfig = connectionIdOrConnectionConfig;\n        }\n        const url = this.hostBaseUrl + `/auth/unauthenticated/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`;\n        const res = await this.triggerAuth({\n            authUrl: url\n        });\n        return res;\n    }\n    auth(providerConfigKey, connectionIdOrOptions, moreOptions) {\n        this.ensureCredentials();\n        let connectionId = null;\n        let options = moreOptions;\n        if (typeof connectionIdOrOptions === 'string') {\n            connectionId = connectionIdOrOptions;\n        }\n        else {\n            options = {\n                ...options,\n                ...connectionIdOrOptions\n            };\n        }\n        // -----------\n        // Non popup auth\n        // -----------\n        if (options &&\n            (('installation' in options && options.installation === 'outbound') ||\n                ('credentials' in options &&\n                    (('token_id' in options.credentials && 'token_secret' in options.credentials) ||\n                        !('oauth_client_id_override' in options.credentials) ||\n                        !('oauth_client_secret_override' in options.credentials)) &&\n                    Object.keys(options.credentials).length > 0))) {\n            const credentials = options.credentials;\n            if (!credentials) {\n                throw new AuthError('Credentials are required for custom auth', 'missing_credentials');\n            }\n            const { credentials: _, ...connectionConfig } = options;\n            return this.customAuth(providerConfigKey, connectionId, this.convertCredentialsToConfig(credentials), connectionConfig, options.installation);\n        }\n        // -----------\n        // Auth with popup (e.g: OAuth)\n        // -----------\n        // /!\\ /!\\ /!\\ /!\\\n        //\n        // Some popup blocker are more sensitive than others\n        // e.g: safari is blocking any popup opened in a different function or in async mode so it has to be opened here before everything else\n        //\n        const modal = window.open('', '_blank', windowFeaturesToString(computeLayout({ expectedWidth: this.width, expectedHeight: this.height })));\n        return new Promise((resolve, reject) => {\n            const successHandler = (authSuccess) => {\n                resolve(authSuccess);\n            };\n            const errorHandler = (errorType, errorDesc) => {\n                reject(new AuthError(errorDesc, errorType));\n                return;\n            };\n            // Clear state if the modal is already opened\n            if (this.win) {\n                this.clear();\n            }\n            if (!modal || modal.closed || typeof modal.closed == 'undefined') {\n                errorHandler('blocked_by_browser', 'Modal blocked by browser');\n                return;\n            }\n            let url;\n            try {\n                url = new URL(`${this.hostBaseUrl}/oauth/connect/${providerConfigKey}${this.toQueryString(connectionId, options)}`);\n            }\n            catch {\n                errorHandler('invalid_host_url', 'Invalid URL provided for the Nango host.');\n                return;\n            }\n            this.win = new AuthorizationModal({ baseUrl: url, debug: this.debug, webSocketUrl: this.websocketsBaseUrl, successHandler, errorHandler });\n            this.win.setModal(modal);\n            this.tm = setInterval(() => {\n                if (!this.win || !this.win.modal) {\n                    return;\n                }\n                if (!this.win.modal.closed) {\n                    return;\n                }\n                if (this.win.isProcessingMessage) {\n                    // Modal is still processing a web socket message from the server\n                    // We ignore the window being closed for now\n                    return;\n                }\n                if (options?.detectClosedAuthWindow) {\n                    // Unfortunately some third party are blocking us from accessing the popup\n                    // So we can't reliably close the popup and websocket connection\n                    clearInterval(this.tm);\n                    this.win.close();\n                    this.win = null;\n                    reject(new AuthError('The authorization window was closed before the authorization flow was completed', 'window_closed'));\n                }\n            }, 500);\n        }).finally(() => {\n            this.clear();\n        });\n    }\n    reconnect(providerConfigKey, options) {\n        if (!this.connectSessionToken) {\n            throw new AuthError('Reconnect requires a session token', 'missing_connect_session_token');\n        }\n        return this.auth(providerConfigKey, options);\n    }\n    /**\n     * Clear state of the frontend SDK\n     * Delays closing the popup so the callback page can postMessage to conect ui\n     * and the opener can process the message before the popup is destroyed.\n     */\n    clear() {\n        if (this.tm) {\n            clearInterval(this.tm);\n        }\n        if (this.win) {\n            const windowRef = this.win;\n            this.win = null;\n            setTimeout(() => {\n                try {\n                    windowRef.close();\n                }\n                catch {\n                    // ignore\n                }\n            }, 500);\n        }\n    }\n    /**\n     * Open managed Connect UI\n     */\n    openConnectUI(params) {\n        const connect = new ConnectUI({ sessionToken: this.connectSessionToken, ...params });\n        connect.open();\n        return connect;\n    }\n    /**\n     * Converts the provided credentials to a Connection configuration object\n     * @param credentials - The credentials to convert\n     * @returns The connection configuration object\n     */\n    convertCredentialsToConfig(credentials) {\n        const params = {};\n        if ('type' in credentials && 'username' in credentials && 'password' in credentials && credentials.type === 'SIGNATURE') {\n            const signatureCredentials = {\n                type: credentials.type,\n                username: credentials.username,\n                password: credentials.password\n            };\n            return { params: signatureCredentials };\n        }\n        if ('username' in credentials) {\n            params['username'] = credentials.username || '';\n        }\n        if ('password' in credentials) {\n            params['password'] = credentials.password || '';\n        }\n        if ('apiKey' in credentials) {\n            params['apiKey'] = credentials.apiKey || '';\n        }\n        if (\n        // for backwards compatibility with the old JWT credentials (ghost-admin)\n        'privateKey' in credentials ||\n            ('type' in credentials && credentials.type === 'JWT')) {\n            const { privateKey, ...rest } = credentials;\n            const params = { ...rest };\n            if (privateKey && typeof privateKey === 'object' && 'id' in privateKey && 'secret' in privateKey) {\n                params['privateKey'] = privateKey;\n            }\n            return { params: credentials };\n        }\n        if ('privateKeyId' in credentials && 'issuerId' in credentials && 'privateKey' in credentials) {\n            const appStoreCredentials = {\n                params: {\n                    privateKeyId: credentials['privateKeyId'],\n                    issuerId: credentials['issuerId'],\n                    privateKey: credentials['privateKey']\n                }\n            };\n            if ('scope' in credentials && (typeof credentials['scope'] === 'string' || Array.isArray(credentials['scope']))) {\n                appStoreCredentials.params['scope'] = credentials['scope'];\n            }\n            return appStoreCredentials;\n        }\n        if ('client_id' in credentials && ('client_secret' in credentials || 'client_private_key' in credentials)) {\n            const oauth2CCCredentials = {\n                client_id: credentials.client_id,\n                client_secret: credentials.client_secret,\n                client_certificate: credentials.client_certificate,\n                client_private_key: credentials.client_private_key\n            };\n            return { params: oauth2CCCredentials };\n        }\n        if ('token_id' in credentials && 'token_secret' in credentials) {\n            const tbaCredentials = {\n                token_id: credentials.token_id,\n                token_secret: credentials.token_secret\n            };\n            if ('oauth_client_id_override' in credentials) {\n                tbaCredentials['oauth_client_id_override'] = credentials.oauth_client_id_override;\n            }\n            if ('oauth_client_secret_override' in credentials) {\n                tbaCredentials['oauth_client_secret_override'] = credentials.oauth_client_secret_override;\n            }\n            return { params: tbaCredentials };\n        }\n        if ('username' in credentials && 'password' in credentials && 'organization_id' in credentials && 'dev_key' in credentials) {\n            const BillCredentials = {\n                username: credentials.username,\n                password: credentials.password,\n                organization_id: credentials.organization_id,\n                dev_key: credentials.dev_key\n            };\n            return { params: BillCredentials };\n        }\n        if ('type' in credentials && credentials.type === 'TWO_STEP') {\n            const twoStepCredentials = { ...credentials };\n            return { params: twoStepCredentials };\n        }\n        return { params };\n    }\n    async triggerAuth({ authUrl, credentials, assertionOption }) {\n        const body = {};\n        if (credentials) {\n            Object.assign(body, credentials);\n        }\n        if (assertionOption && Object.keys(assertionOption).length > 0) {\n            body['assertionOption'] = assertionOption;\n        }\n        const res = await fetch(authUrl, {\n            method: 'POST',\n            headers: {\n                'Content-Type': 'application/json'\n            },\n            ...(Object.keys(body).length > 0 ? { body: JSON.stringify(body) } : {})\n        });\n        if (!res.ok) {\n            const errorResponse = await res.json();\n            throw new AuthError(errorResponse.error.message, errorResponse.error.code);\n        }\n        return res.json();\n    }\n    /**\n     * Performs authorization based on the provided credentials i.e api, basic, appstore and oauth2\n     * @param providerConfigKey - The key identifying the provider configuration on Nango\n     * @param connectionId - The ID of the connection for which to create the custom Authorization\n     * @param connectionConfigWithCredentials - The connection configuration containing the credentials\n     * @param connectionConfig - Optional. Additional connection configuration\n     * @returns A promise that resolves with the authorization result\n     */\n    async customAuth(providerConfigKey, connectionId, connectionConfigWithCredentials, connectionConfig, installation) {\n        const { params: credentials } = connectionConfigWithCredentials;\n        if (!credentials) {\n            throw new AuthError('You must specify credentials.', 'missing_credentials');\n        }\n        if ('type' in credentials && credentials['type'] === 'TWO_STEP') {\n            const assertionOption = connectionConfig?.assertionOption;\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/two-step/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials,\n                ...(assertionOption ? { assertionOption } : {})\n            });\n        }\n        if ('type' in credentials && credentials['type'] === 'SIGNATURE' && 'username' in credentials && 'password' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/signature/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('username' in credentials && 'password' in credentials && 'organization_id' in credentials && 'dev_key' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/bill/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('apiKey' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/api-auth/api-key/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('username' in credentials || 'password' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/api-auth/basic/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('privateKey' in credentials || ('type' in credentials && credentials['type'] === 'JWT')) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/jwt/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('privateKeyId' in credentials && 'issuerId' in credentials && 'privateKey' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/app-store-auth/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('token_id' in credentials && 'token_secret' in credentials) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/tba/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if ('client_id' in credentials && ('client_secret' in credentials || 'client_private_key' in credentials)) {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/oauth2/auth/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`,\n                credentials: credentials\n            });\n        }\n        if (installation === 'outbound') {\n            return await this.triggerAuth({\n                authUrl: this.hostBaseUrl + `/auth/oauth-outbound/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig)}`\n            });\n        }\n        return Promise.reject(new Error('Something went wrong with the authorization'));\n    }\n    /**\n     * Converts the connection ID and configuration parameters into a query string\n     * @param connectionId - The ID of the connection for which to generate a query string\n     * @param connectionConfig - Optional. Additional configuration for the connection\n     * @returns The generated query string\n     */\n    toQueryString(connectionId, connectionConfig) {\n        const query = [];\n        if (connectionId) {\n            query.push(`connection_id=${connectionId}`);\n        }\n        if (this.publicKey) {\n            query.push(`public_key=${this.publicKey}`);\n        }\n        if (this.connectSessionToken) {\n            query.push(`connect_session_token=${this.connectSessionToken}`);\n        }\n        if (connectionConfig) {\n            for (const param in connectionConfig.params) {\n                const val = connectionConfig.params[param];\n                if (typeof val === 'string') {\n                    query.push(`params[${encodeURIComponent(param)}]=${encodeURIComponent(val)}`);\n                }\n            }\n            if (connectionConfig.hmac) {\n                query.push(`hmac=${connectionConfig.hmac}`);\n            }\n            if (connectionConfig.user_scope) {\n                query.push(`user_scope=${connectionConfig.user_scope.join(',')}`);\n            }\n            if (connectionConfig.credentials) {\n                const credentials = connectionConfig.credentials;\n                if ('oauth_client_id_override' in credentials) {\n                    query.push(`credentials[oauth_client_id_override]=${encodeURIComponent(credentials.oauth_client_id_override)}`);\n                }\n                if ('oauth_client_secret_override' in credentials) {\n                    query.push(`credentials[oauth_client_secret_override]=${encodeURIComponent(credentials.oauth_client_secret_override)}`);\n                }\n                if ('oauth_refresh_token_override' in credentials) {\n                    query.push(`credentials[oauth_refresh_token_override]=${encodeURIComponent(credentials.oauth_refresh_token_override)}`);\n                }\n                if ('token_id' in credentials) {\n                    query.push(`token_id=${encodeURIComponent(credentials.token_id)}`);\n                }\n                if ('token_secret' in credentials) {\n                    query.push(`token_secret=${encodeURIComponent(credentials.token_secret)}`);\n                }\n            }\n            for (const param in connectionConfig.authorization_params) {\n                const val = connectionConfig.authorization_params[param];\n                if (typeof val === 'string') {\n                    query.push(`authorization_params[${param}]=${val}`);\n                }\n                else if (val === undefined) {\n                    query.push(`authorization_params[${param}]=undefined`);\n                }\n            }\n        }\n        return query.length === 0 ? '' : '?' + query.join('&');\n    }\n    /**\n     * Check that we have one valid credential\n     * It's not done in the constructor because if you only use Nango Connect it's not relevant to throw an error\n     */\n    ensureCredentials() {\n        if (!this.publicKey && !this.connectSessionToken) {\n            throw new AuthError('You must specify a public key OR a connect session token (cf. documentation).', 'missing_auth_token');\n        }\n    }\n}\n"]}