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ACvB,QAAQ,eAAiB,eACzB,QAAQ,YAAc,YACtB,QAAQ,kBAAoB,kBAC5B,QAAQ,gBAAkB","file":"/npm/b44-sdk@1.1.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/b44-sdk@1.1.0/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","'use strict';\n\nvar axios = require('axios');\n\n/**\n * Custom error class for B44 SDK\n */\nclass B44Error extends Error {\n    /**\n     * HTTP status code\n     */\n    status;\n    /**\n     * Error code\n     */\n    code;\n    /**\n     * Additional error data\n     */\n    data;\n    /**\n     * Original error that caused this error\n     */\n    originalError;\n    /**\n     * Create a new B44Error\n     * @param message Error message\n     * @param status HTTP status code\n     * @param code Error code\n     * @param data Additional error data\n     * @param originalError Original error that caused this error\n     */\n    constructor(message, status, code, data, originalError) {\n        super(message);\n        this.name = \"B44Error\";\n        this.status = status;\n        this.code = code;\n        this.data = data;\n        this.originalError = originalError;\n    }\n    /**\n     * Convert the error to a JSON object\n     * @returns JSON representation of the error\n     */\n    toJSON() {\n        return {\n            name: this.name,\n            message: this.message,\n            status: this.status,\n            code: this.code,\n            data: this.data,\n        };\n    }\n}\n/**\n * Log an error to the console in development mode\n * @param prefix Prefix for the error message\n * @param error Error to log\n */\nfunction logError(prefix, error) {\n    if (error instanceof B44Error) {\n        if (console.error) {\n            console.error(`${prefix} ${error.status}: ${error.message}`);\n            if (error.data) {\n                try {\n                    console.error(\"Error data:\", JSON.stringify(error.data, null, 2));\n                }\n                catch (e) {\n                    console.error(\"Error data: [Cannot stringify error data]\");\n                }\n            }\n        }\n    }\n    else {\n        if (console.error) {\n            console.error(`${prefix} ${error.message}`);\n        }\n    }\n}\n\n/**\n * Create an HTTP client with the specified configuration\n * @param config Client configuration\n * @returns Configured Axios instance\n */\nfunction createHttpClient(config) {\n    const { baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, } = config;\n    // Create Axios instance with default headers\n    const client = axios.create({\n        baseURL,\n        headers: {\n            \"Content-Type\": \"application/json\",\n            Accept: \"application/json\",\n            ...headers,\n        },\n    });\n    // Set authorization header if token is provided\n    if (token) {\n        client.defaults.headers.common[\"Authorization\"] = `Bearer ${token}`;\n    }\n    // Request interceptor to add origin URL\n    client.interceptors.request.use((config) => {\n        if (typeof window !== \"undefined\") {\n            config.headers.set(\"X-Origin-URL\", window.location.href);\n        }\n        return config;\n    });\n    // Response interceptor to handle errors\n    client.interceptors.response.use(\n    // Success handler - extract data from response\n    (response) => response.data, \n    // Error handler - convert to B44Error\n    (error) => {\n        // Extract error message from response or use default\n        const message = error.response?.data?.message ||\n            error.response?.data?.detail ||\n            error.message;\n        // Create B44Error with additional information\n        const b44Error = new B44Error(message, error.response?.status, error.response?.data?.code, error.response?.data, error);\n        // Log error in development mode\n        if (process.env.NODE_ENV !== \"production\") {\n            logError(\"[B44 SDK Error]\", b44Error);\n        }\n        // Handle authentication errors\n        console.log(requiresAuth, error.response?.status, typeof window !== \"undefined\");\n        if (requiresAuth &&\n            error.response?.status === 403 &&\n            typeof window !== \"undefined\") {\n            console.log(\"Authentication required. Redirecting to login...\");\n            // Redirect to login page after a short delay\n            setTimeout(() => {\n                redirectToLogin(serverUrl, appId);\n            }, 100);\n        }\n        return Promise.reject(b44Error);\n    });\n    return client;\n}\n/**\n * Redirect to the login page\n * @param serverUrl Base server URL\n * @param appId Application ID\n */\nfunction redirectToLogin(serverUrl, appId) {\n    if (typeof window === \"undefined\") {\n        return;\n    }\n    const loginUrl = `${serverUrl}/login?from_url=${encodeURIComponent(window.location.href)}&app_id=${appId}`;\n    window.location.href = loginUrl;\n}\n\n/**\n * Create entity methods for a specific entity type\n * @param client HTTP client\n * @param appId Application ID\n * @param entityName Entity name\n * @returns Entity methods\n */\nfunction createEntityMethods(client, appId, entityName) {\n    const basePath = `/apps/${appId}/entities/${entityName}`;\n    return {\n        /**\n         * List entities with optional sorting, pagination, and field selection\n         * @param sort Optional sorting parameter\n         * @param limit Optional limit for pagination\n         * @param skip Optional skip for pagination\n         * @param fields Optional fields to include\n         */\n        async list(sort, limit, skip, fields) {\n            const params = {};\n            if (sort)\n                params.sort = sort;\n            if (limit)\n                params.limit = limit;\n            if (skip)\n                params.skip = skip;\n            if (fields)\n                params.fields = Array.isArray(fields) ? fields.join(\",\") : fields;\n            return client.get(basePath, { params });\n        },\n        /**\n         * Filter entities by query with optional sorting, pagination, and field selection\n         * @param query Filter query\n         * @param sort Optional sorting parameter\n         * @param limit Optional limit for pagination\n         * @param skip Optional skip for pagination\n         * @param fields Optional fields to include\n         */\n        async filter(query, sort, limit, skip, fields) {\n            const params = {\n                q: JSON.stringify(query),\n            };\n            if (sort)\n                params.sort = sort;\n            if (limit)\n                params.limit = limit;\n            if (skip)\n                params.skip = skip;\n            if (fields)\n                params.fields = Array.isArray(fields) ? fields.join(\",\") : fields;\n            return client.get(basePath, { params });\n        },\n        /**\n         * Get a single entity by ID\n         * @param id Entity ID\n         */\n        get: async (id) => {\n            return client.get(`${basePath}/${id}`);\n        },\n        /**\n         * Create a new entity\n         * @param data Entity data\n         */\n        create: async (data) => {\n            return client.post(basePath, data);\n        },\n        /**\n         * Update an existing entity\n         * @param id Entity ID\n         * @param data Updated entity data\n         */\n        update: async (id, data) => {\n            return client.put(`${basePath}/${id}`, data);\n        },\n        /**\n         * Delete an entity\n         * @param id Entity ID\n         */\n        delete: async (id) => {\n            return client.delete(`${basePath}/${id}`);\n        },\n        /**\n         * Delete multiple entities matching a query\n         * @param query Filter query for entities to delete\n         */\n        deleteMany: async (query) => {\n            return client.delete(basePath, { data: query });\n        },\n        /**\n         * Create multiple entities in a single operation\n         * @param data Array of entity data\n         */\n        bulkCreate: async (data) => {\n            return client.post(`${basePath}/bulk`, data);\n        },\n        /**\n         * Import entities from a file\n         * @param file File containing entity data\n         */\n        async importEntities(file) {\n            const formData = new FormData();\n            formData.append(\"file\", file, file.name);\n            return client.post(`${basePath}/import`, formData, {\n                headers: {\n                    \"Content-Type\": \"multipart/form-data\",\n                },\n            });\n        },\n    };\n}\n\n/**\n * Create the entities module with dynamic entity access\n * @param client HTTP client\n * @param appId Application ID\n * @returns Entities module\n */\nfunction createEntitiesModule(client, appId) {\n    // Use a Proxy to dynamically handle entity access\n    return new Proxy({}, {\n        get(_target, prop) {\n            // Ignore special properties like 'then' and properties starting with '_'\n            if (typeof prop === \"string\" &&\n                prop !== \"then\" &&\n                !prop.startsWith(\"_\")) {\n                // Create entity methods for the requested entity type\n                return createEntityMethods(client, appId, prop);\n            }\n            return undefined;\n        },\n    });\n}\n\n/**\n * Default storage key for the access token\n */\nconst DEFAULT_STORAGE_KEY = \"b44_access_token\";\n/**\n * Default parameter name for the access token in URL\n */\nconst DEFAULT_PARAM_NAME = \"access_token\";\n/**\n * Get the access token from URL parameters or localStorage\n * @param options Token options\n * @returns Access token or null if not found\n */\nfunction getAccessToken(options = {}) {\n    const { storageKey = DEFAULT_STORAGE_KEY, paramName = DEFAULT_PARAM_NAME, saveToStorage = true, removeFromUrl = true, } = options;\n    let token = null;\n    // Try to get token from URL parameters\n    if (typeof window !== \"undefined\" && window.location) {\n        try {\n            const urlParams = new URLSearchParams(window.location.search);\n            token = urlParams.get(paramName);\n            if (token) {\n                // Save token to localStorage if requested\n                if (saveToStorage) {\n                    saveAccessToken(token, { storageKey });\n                }\n                // Remove token from URL if requested\n                if (removeFromUrl) {\n                    urlParams.delete(paramName);\n                    const newUrl = `${window.location.pathname}${urlParams.toString() ? `?${urlParams.toString()}` : \"\"}${window.location.hash}`;\n                    window.history.replaceState({}, document.title, newUrl);\n                }\n                return token;\n            }\n        }\n        catch (error) {\n            console.error(\"Error retrieving token from URL:\", error);\n        }\n    }\n    // Try to get token from localStorage\n    if (typeof window !== \"undefined\" && window.localStorage) {\n        try {\n            token = window.localStorage.getItem(storageKey);\n            return token;\n        }\n        catch (error) {\n            console.error(\"Error retrieving token from localStorage:\", error);\n        }\n    }\n    return null;\n}\n/**\n * Save the access token to localStorage\n * @param token Access token\n * @param options Token options\n * @returns Whether the token was successfully saved\n */\nfunction saveAccessToken(token, options = {}) {\n    const { storageKey = DEFAULT_STORAGE_KEY } = options;\n    if (typeof window === \"undefined\" || !window.localStorage || !token) {\n        return false;\n    }\n    try {\n        window.localStorage.setItem(storageKey, token);\n        return true;\n    }\n    catch (error) {\n        console.error(\"Error saving token to localStorage:\", error);\n        return false;\n    }\n}\n/**\n * Remove the access token from localStorage\n * @param options Token options\n * @returns Whether the token was successfully removed\n */\nfunction removeAccessToken(options = {}) {\n    const { storageKey = DEFAULT_STORAGE_KEY } = options;\n    if (typeof window === \"undefined\" || !window.localStorage) {\n        return false;\n    }\n    try {\n        window.localStorage.removeItem(storageKey);\n        return true;\n    }\n    catch (error) {\n        console.error(\"Error removing token from localStorage:\", error);\n        return false;\n    }\n}\n/**\n * Get the login URL for the specified return URL and configuration\n * @param returnUrl URL to return to after login\n * @param options Login URL options\n * @returns Login URL\n */\nfunction getLoginUrl(returnUrl, options) {\n    const { serverUrl, appId, loginPath = \"/login\" } = options;\n    if (!serverUrl || !appId) {\n        throw new Error(\"serverUrl and appId are required to construct login URL\");\n    }\n    const actualReturnUrl = returnUrl || (typeof window !== \"undefined\" ? window.location.href : \"\");\n    return `${serverUrl}${loginPath}?from_url=${encodeURIComponent(actualReturnUrl)}&app_id=${appId}`;\n}\n\n/**\n * Create the authentication module\n * @param client HTTP client\n * @param appId Application ID\n * @param serverUrl Server URL\n * @returns Authentication module\n */\nfunction createAuthModule(client, appId, serverUrl) {\n    return {\n        /**\n         * Get the current authenticated user\n         * @returns Promise resolving to the user entity\n         */\n        me: async () => {\n            try {\n                return client.get(`/auth/me`);\n            }\n            catch (error) {\n                console.info(\"Error fetching user from /auth/me, falling back to /apps/:appId/entities/User/me\", error.message);\n                return client.get(`/apps/${appId}/entities/User/me`);\n            }\n        },\n        /**\n         * Update the current authenticated user\n         * @param data Updated user data\n         * @returns Promise resolving to the updated user entity\n         */\n        updateMe: async (data) => {\n            return client.put(`/apps/${appId}/entities/User/me`, data);\n        },\n        /**\n         * Redirect to the login page\n         * @param nextUrl Optional URL to redirect to after successful login\n         */\n        login(nextUrl) {\n            if (typeof window === \"undefined\") {\n                throw new Error(\"Login method can only be used in a browser environment\");\n            }\n            console.log(\"redirecting to login page...\");\n            const returnUrl = nextUrl || window.location.href;\n            const loginUrl = getLoginUrl(returnUrl, { serverUrl, appId });\n            window.location.href = loginUrl;\n        },\n        /**\n         * Log out the current user\n         * @param redirectUrl Optional URL to redirect to after logout\n         * @returns Promise that resolves when logout is complete\n         */\n        async logout(redirectUrl) {\n            // Remove the authorization header\n            delete client.defaults.headers.common[\"Authorization\"];\n            // Remove the token from localStorage\n            if (typeof window !== \"undefined\" && window.localStorage) {\n                try {\n                    window.localStorage.removeItem(\"b44_access_token\");\n                }\n                catch (error) {\n                    console.error(\"Failed to remove token from localStorage:\", error);\n                }\n            }\n            // Redirect if a URL is provided\n            if (redirectUrl && typeof window !== \"undefined\") {\n                window.location.href = redirectUrl;\n            }\n            return Promise.resolve();\n        },\n        /**\n         * Set the authentication token\n         * @param token Authentication token\n         * @param saveToStorage Whether to save the token to localStorage\n         */\n        setToken(token, saveToStorage = true) {\n            if (token) {\n                // Set the authorization header\n                client.defaults.headers.common[\"Authorization\"] = `Bearer ${token}`;\n                // Save the token to localStorage if requested\n                if (saveToStorage &&\n                    typeof window !== \"undefined\" &&\n                    window.localStorage) {\n                    try {\n                        window.localStorage.setItem(\"b44_access_token\", token);\n                    }\n                    catch (error) {\n                        console.error(\"Failed to save token to localStorage:\", error);\n                    }\n                }\n            }\n        },\n        /**\n         * Check if the user is authenticated\n         * @returns Promise resolving to authentication status\n         */\n        async isAuthenticated() {\n            try {\n                await this.me();\n                return true;\n            }\n            catch (error) {\n                return false;\n            }\n        },\n    };\n}\n\n/**\n * Create a B44 client instance\n * @param config Client configuration\n * @returns B44 client\n */\nfunction createClient(config) {\n    // Validate required configuration\n    if (!config || !config.appId) {\n        throw new Error(\"appId is required\");\n    }\n    // Extract configuration with defaults\n    const { serverUrl = \"http://localhost:3000\", appId, env = \"prod\", token, apiKey, requiresAuth = false, } = config;\n    // Create HTTP client\n    const httpClient = createHttpClient({\n        baseURL: `${serverUrl}/api`,\n        headers: {\n            api_key: apiKey ?? \"\",\n            \"X-App-Id\": String(appId),\n            \"X-Environment\": env,\n        },\n        token,\n        requiresAuth,\n        appId,\n        serverUrl,\n    });\n    // Create entities module\n    const entities = createEntitiesModule(httpClient, appId);\n    // Create auth module\n    const auth = createAuthModule(httpClient, appId, serverUrl);\n    // Initialize token from storage or URL if in browser environment\n    if (typeof window !== \"undefined\") {\n        const storedToken = token || getAccessToken();\n        if (storedToken) {\n            auth.setToken(storedToken);\n        }\n    }\n    // Auto-check authentication if required\n    if (requiresAuth && typeof window !== \"undefined\") {\n        setTimeout(async () => {\n            try {\n                const isAuthenticated = await auth.isAuthenticated();\n                if (!isAuthenticated) {\n                    auth.login(window.location.href);\n                }\n            }\n            catch (error) {\n                console.error(\"Authentication check failed:\", error);\n                auth.login(window.location.href);\n            }\n        }, 0);\n    }\n    // Create and return the client instance\n    return {\n        entities,\n        auth,\n        setToken(token) {\n            auth.setToken(token);\n        },\n        getConfig() {\n            return {\n                serverUrl,\n                appId,\n                env,\n                requiresAuth,\n            };\n        },\n        integrations: {\n            Core: {},\n            InvokeLLM: {},\n            SendEmail: {},\n            SendSMS: {},\n            UploadFile: {},\n            GenerateImage: {},\n            ExtractDataFromUploadedFile: {},\n        },\n    };\n}\n\nexports.B44Error = B44Error;\nexports.createClient = createClient;\nexports.getAccessToken = getAccessToken;\nexports.getLoginUrl = getLoginUrl;\nexports.removeAccessToken = removeAccessToken;\nexports.saveAccessToken = saveAccessToken;\n\n"]}