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AC3F,QAAS,CACL,cAAe,UAAU,KAAK,WAGtC,GAAI,EAAI,QAAU,KAAO,EAAI,OAAS,IAAK,CAEvC,YADoB,EAAI,MAE5B,CACA,aAAa,EAAI,MACrB,CAMA,kBAAM,CAAa,GACf,MAAM,QAAY,MAAM,GAAG,KAAK,mCAAmC,IAAe,CAC9E,QAAS,CACL,cAAe,UAAU,KAAK,WAGtC,GAAI,EAAI,QAAU,KAAO,EAAI,OAAS,IAAK,CAEvC,YADoB,EAAI,MAE5B,CACA,aAAa,EAAI,MACrB,EAEJ,QAAQ,OAAS","file":"/npm/@cobaltio/cobalt-js@9.2.0-beta.3/cobalt.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@cobaltio/cobalt-js@9.2.0-beta.3/cobalt.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n/**\n * Cobalt Frontend SDK\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Cobalt = exports.AuthStatus = exports.AuthType = void 0;\nvar AuthType;\n(function (AuthType) {\n    AuthType[\"OAuth2\"] = \"oauth2\";\n    AuthType[\"KeyBased\"] = \"keybased\";\n})(AuthType || (exports.AuthType = AuthType = {}));\nvar AuthStatus;\n(function (AuthStatus) {\n    AuthStatus[\"Active\"] = \"active\";\n    AuthStatus[\"Expired\"] = \"expired\";\n})(AuthStatus || (exports.AuthStatus = AuthStatus = {}));\nclass Cobalt {\n    /**\n     * Cobalt Frontend SDK\n     * @param {Object} options The options to configure the Cobalt SDK.\n     * @param {String} [options.token] The session token.\n     * @param {String} [options.baseUrl=https://api.gocobalt.io] The base URL of the Cobalt API.\n     */\n    constructor(options = {}) {\n        this.baseUrl = options.baseUrl\n            ? /^https?:\\/\\//.test(options.baseUrl)\n                ? options.baseUrl\n                : \"https://\" + options.baseUrl\n            : \"https://api.gocobalt.io\";\n        this.token = options.token || \"\";\n    }\n    /**\n     * Returns the org & customer details for the associated token.\n     * @private\n     * @returns {Promise<unknown>}\n     */\n    async getAccountDetails() {\n        const res = await fetch(`${this.baseUrl}/api/v3/org/basics`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data;\n    }\n    /**\n     * Returns the org & customer details for the associated token.\n     * @private\n     * @returns {Promise<unknown>}\n     */\n    async updateAccount(payload) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/linked-account`, {\n            method: \"PUT\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n            },\n            body: JSON.stringify({\n                ...payload,\n            }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data;\n    }\n    /**\n     * Returns the application details for the specified application, provided\n     * the application is enabled in Cobalt. If no application is specified,\n     * it returns all the enabled applications.\n     * @param {String} [slug] The application slug.\n     * @returns {Promise<Application | Application[]>} The application details.\n     */\n    async getApp(slug) {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/application${slug ? `/${slug}` : \"\"}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data;\n    }\n    /**\n     * Returns all the enabled apps.\n     * @returns {Promise<Application[]>} The list of applications.\n     */\n    async getApps() {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/application`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data;\n    }\n    /**\n     * Returns the auth configs for the specified application.\n     * @param {String} slug The application slug.\n     * @returns {Promise<AuthConfig[]>} The auth configs.\n     */\n    async getAuthConfigs(slug) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/slug/${slug}/auth-config`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data.docs || [];\n    }\n    /**\n     * Returns the auth URL that users can use to authenticate themselves to the\n     * specified application.\n     * @private\n     * @param {OAuthParams} params The OAuth parameters.\n     * @returns {Promise<String>} The auth URL where users can authenticate themselves.\n     */\n    async getOAuthUrl({ slug, authConfig, payload, }) {\n        const queryParams = new URLSearchParams();\n        if (authConfig)\n            queryParams.append(\"auth_config_id\", authConfig);\n        if (typeof payload === \"object\") {\n            for (const [key, value] of Object.entries(payload)) {\n                queryParams.append(key, value);\n            }\n        }\n        const res = await fetch(`${this.baseUrl}/api/v1/${slug}/integrate?${queryParams.toString()}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data.auth_url;\n    }\n    /**\n     * Handle OAuth for the specified application.\n     * @private\n     * @param {OAuthParams} params The OAuth parameters.\n     * @returns {Promise<Boolean>} Whether the user authenticated.\n     */\n    async oauth({ slug, authConfig, payload, }) {\n        return new Promise((resolve, reject) => {\n            this.getOAuthUrl({ slug, authConfig, payload })\n                .then(oauthUrl => {\n                const connectWindow = window.open(oauthUrl);\n                // keep checking connection status\n                const interval = setInterval(() => {\n                    this.getApp(slug)\n                        .then(app => {\n                        const oauthAccounts = app.connected_accounts?.filter(a => a.auth_type === AuthType.OAuth2 && a.status === AuthStatus.Active);\n                        if (app && oauthAccounts?.some(a => authConfig ? a.auth_config_id === authConfig : true)) {\n                            // close auth window\n                            connectWindow && connectWindow.close();\n                            // clear interval\n                            clearInterval(interval);\n                            // resovle status\n                            resolve(true);\n                        }\n                        else {\n                            // user closed oauth window without authenticating\n                            if (connectWindow && connectWindow.closed) {\n                                // clear interval\n                                clearInterval(interval);\n                                // resolve status\n                                resolve(false);\n                            }\n                        }\n                    })\n                        .catch(e => {\n                        console.error(e);\n                        // connectWindow?.close();\n                        clearInterval(interval);\n                        reject(e);\n                    });\n                }, 3e3);\n            })\n                .catch(reject);\n        });\n    }\n    /**\n     * Save auth data for the specified keybased application.\n     * @param {KeyBasedParams} params The key based parameters.\n     * @returns {Promise<Boolean>} Whether the auth data was saved successfully.\n     */\n    async keybased({ slug, authConfig, payload, }) {\n        const res = await fetch(`${this.baseUrl}/api/v2/app/${slug}/save?auth_config_id=${authConfig}`, {\n            method: \"POST\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n            },\n            body: JSON.stringify({\n                ...payload,\n            }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data.success;\n    }\n    /**\n     * Connects the specified application using the provided authentication type and optional auth data.\n     * @param params - The parameters for connecting the application.\n     * @param params.slug - The application slug.\n     * @param params.authConfig - The identifier of the auth config.\n     * @param params.type - The authentication type to use. If not provided, it defaults to `keybased` if payload is provided, otherwise `oauth2`.\n     * @param params.payload - key-value pairs of authentication data required for the specified auth type.\n     * @returns A promise that resolves to true if the connection was successful, otherwise false.\n     * @throws Throws an error if the authentication type is invalid or the connection fails.\n     */\n    async connect({ slug, authConfig, type, payload, }) {\n        switch (type) {\n            case AuthType.OAuth2:\n                return this.oauth({ slug, authConfig, payload });\n            case AuthType.KeyBased:\n                return this.keybased({ slug, authConfig, payload });\n            default:\n                if (payload)\n                    return this.keybased({ slug, authConfig, payload });\n                return this.oauth({ slug, authConfig });\n        }\n    }\n    /**\n     * Disconnect the specified application and remove any associated data from Cobalt.\n     * @param {String} slug The application slug.\n     * @param {AuthType} [type] The authentication type to use. If not provided, it'll remove all the connected accounts.\n     * @param {String} [authConfig] The identifier of the auth config.\n     * @returns {Promise<unknown>}\n     */\n    async disconnect(slug, type, authConfig) {\n        const queryParams = new URLSearchParams();\n        if (type)\n            queryParams.append(\"auth_type\", type);\n        if (authConfig)\n            queryParams.append(\"auth_config_id\", authConfig);\n        const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${slug}?${queryParams.toString()}`, {\n            method: \"DELETE\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the specified config, or creates one if it doesn't exist.\n     * @param {ConfigPayload} payload The payload object for config.\n     * @returns {Promise<Config>} The specified config.\n     */\n    async config(payload) {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/config`, {\n            method: \"POST\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n            },\n            body: JSON.stringify({\n                ...payload,\n                labels: payload.labels || [],\n            }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the configs created for the specified application.\n     * @param {String} slug The application slug.\n     * @returns {Promise<{ config_id: string; }[]>} The configs created for the specified application.\n     */\n    async getConfigs(slug) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/slug/${slug}/configs`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the specified config.\n     * @param {String} slug The application slug.\n     * @param {String} [configId] The unique ID of the config.\n     * @returns {Promise<Config>} The specified config.\n     */\n    async getConfig(slug, configId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : \"\"}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Update the specified config.\n     * @param {UpdateConfigPayload} payload The update payload.\n     * @returns {Promise<Config>} The specified config.\n     */\n    async updateConfig(payload) {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/config`, {\n            method: \"PUT\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n            },\n            body: JSON.stringify(payload),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Delete the specified config.\n     * @param {String} slug The application slug.\n     * @param {String} [configId] The unique ID of the config.\n     * @returns {Promise<unknown>}\n     */\n    async deleteConfig(slug, configId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : \"\"}`, {\n            method: \"DELETE\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the specified field of the config.\n     * @param {String} slug The application slug.\n     * @param {String} fieldId The unique ID of the field.\n     * @param {String} [workflowId] The unique ID of the workflow.\n     * @returns {Promise<Field>} The specified config field.\n     */\n    async getConfigField(slug, fieldId, workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : \"\"}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                slug,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Update the specified config field value.\n     * @param {String} slug The application slug.\n     * @param {String} fieldId The unique ID of the field.\n     * @param {String | Number | Boolean | null} value The new value for the field.\n     * @param {String} [workflowId] The unique ID of the workflow.\n     * @returns {Promise<Field>} The updated config field.\n     */\n    async updateConfigField(slug, fieldId, value, workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : \"\"}`, {\n            method: \"PUT\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n                slug,\n            },\n            body: JSON.stringify({ value }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Delete the specified config field value.\n     * @param {String} slug The application slug.\n     * @param {String} fieldId The unique ID of the field.\n     * @param {String} [workflowId] The unique ID of the workflow.\n     * @returns {Promise<unknown>}\n     */\n    async deleteConfigField(slug, fieldId, workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : \"\"}`, {\n            method: \"DELETE\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                slug,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the options for the specified field.\n     * @param {String} lhs The selected value of the lhs field.\n     * @param {String} slug The application slug.\n     * @param {String} fieldId The unique ID of the field.\n     * @param {String} [workflowId] The unique ID of the workflow, if this is a workflow field.\n     * @returns {Promise<RuleOptions>} The specified rule field's options.\n     */\n    async getFieldOptions(lhs, slug, fieldId, workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/config/rule-engine/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : \"\"}`, {\n            method: \"POST\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n                slug,\n            },\n            body: JSON.stringify({\n                rule_column: { lhs },\n            }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the private workflows for the specified application.\n     * @param {Object} params\n     * @param {String} [params.slug]\n     * @param {Number} [params.page]\n     * @param {Number} [params.limit]\n     * @returns\n     */\n    async getWorkflows(params) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/workflow?page=${params?.page || 1}&limit=${params?.limit || 100}${params?.slug ? `&slug=${params.slug}` : \"\"}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Create a public workflow for the linked account.\n     * @param {Object} params\n     * @param {String} params.name The workflow name.\n     * @param {String} [params.description] The workflow description.\n     * @param {String} [params.slug] The application slug in which this workflow should be created.\n     * If slug isn't set, the workflow will be created in the organization's default application.\n     * @returns {Promise<PublicWorkflow>} The created public workflow.\n     */\n    async createWorkflow(params) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/workflow`, {\n            method: \"POST\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n            },\n            body: JSON.stringify({\n                name: params.name,\n                description: params.description,\n                slug: params.slug,\n            }),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        const data = await res.json();\n        return data?.workflow ?? data;\n    }\n    /**\n     * Delete the specified public workflow.\n     * @param {String} workflowId The workflow ID.\n     * @returns {Promise<unknown>}\n     */\n    async deleteWorkflow(workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${workflowId}`, {\n            method: \"DELETE\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the execution payload for the specified public workflow.\n     * @param {String} workflowId The workflow ID.\n     * @returns {Promise<WorkflowPayloadResponse>} The workflow payload response.\n     */\n    async getWorkflowPayload(workflowId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/request-structure/${workflowId}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Execute the specified public workflow.\n     * @param {ExecuteWorkflowPayload} options The execution payload.\n     * @param {String} options.worklfow The workflow id or alias.\n     * @param {String} [options.slug] The application's slug this workflow belongs to. Slug is required if you're using workflow alias.\n     * @param {Record<string, any>} [options.payload] The execution payload.\n     * @returns {Promise<unknown>}\n     */\n    async executeWorkflow(options) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${options?.worklfow}/execute`, {\n            method: \"POST\",\n            headers: {\n                authorization: `Bearer ${this.token}`,\n                \"content-type\": \"application/json\",\n                slug: options?.slug || \"\",\n                sync_execution: options?.sync_execution ? \"true\" : \"false\",\n            },\n            body: JSON.stringify(options?.payload),\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the workflow execution logs for the linked account.\n     * @param {Object} [params]\n     * @param {Number} [params.page]\n     * @param {Number} [params.limit]\n     * @returns {Promise<PaginatedResponse<Execution>>} The paginated workflow execution logs.\n     */\n    async getExecutions({ page = 1, limit = 10 } = {}) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/execution?page=${page}&limit=${limit}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n    /**\n     * Returns the specified workflow execution log.\n     * @param {String} executionId The execution ID.\n     * @returns {Promise<Execution>} The specified execution log.\n     */\n    async getExecution(executionId) {\n        const res = await fetch(`${this.baseUrl}/api/v2/public/execution/${executionId}`, {\n            headers: {\n                authorization: `Bearer ${this.token}`,\n            },\n        });\n        if (res.status >= 400 && res.status < 600) {\n            const error = await res.json();\n            throw error;\n        }\n        return await res.json();\n    }\n}\nexports.Cobalt = Cobalt;\n"]}