@formbricks/js
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -128,3 +128,3 @@ import { z } from 'zod'; | ||
userId: z.string(), | ||
attributes: z.record(z.string()), | ||
attributes: z.record(z.union([z.string(), z.number()])), | ||
}); | ||
@@ -154,2 +154,4 @@ | ||
declare const ZResponseInput = z.object({ | ||
createdAt: z.coerce.date().optional(), | ||
updatedAt: z.coerce.date().optional(), | ||
environmentId: z.string().cuid2(), | ||
@@ -156,0 +158,0 @@ surveyId: z.string().cuid2(), |
@@ -1,70 +0,5 @@ | ||
import { w as wrapThrowsAsync } from "./errorHandlers-N7AebTum.js"; | ||
async function loadFormbricksAppSDK(apiHost) { | ||
if (!window.formbricks) { | ||
const res = await fetch(`${apiHost}/api/packages/app`); | ||
if (!res.ok) { | ||
return { ok: false, error: new Error("Failed to load Formbricks App SDK") }; | ||
} | ||
const sdkScript = await res.text(); | ||
const scriptTag = document.createElement("script"); | ||
scriptTag.innerHTML = sdkScript; | ||
document.head.appendChild(scriptTag); | ||
const getFormbricks = async () => new Promise((resolve, reject) => { | ||
const checkInterval = setInterval(() => { | ||
if (window.formbricks) { | ||
clearInterval(checkInterval); | ||
resolve(); | ||
} | ||
}, 100); | ||
setTimeout(() => { | ||
clearInterval(checkInterval); | ||
reject(new Error("Formbricks App SDK loading timed out")); | ||
}, 1e4); | ||
}); | ||
try { | ||
await getFormbricks(); | ||
return { ok: true, data: void 0 }; | ||
} catch (error) { | ||
return { | ||
ok: false, | ||
error: new Error(error.message ?? "Failed to load Formbricks App SDK") | ||
}; | ||
} | ||
} | ||
return { ok: true, data: void 0 }; | ||
} | ||
import { l as loadFormbricksToProxy } from "./loadFormbricks-BzaImH2L.js"; | ||
const formbricksProxyHandler = { | ||
get(_target, prop, _receiver) { | ||
return async (...args) => { | ||
if (!window.formbricks) { | ||
if (prop !== "init") { | ||
console.error( | ||
"🧱 Formbricks - Global error: You need to call formbricks.init before calling any other method" | ||
); | ||
return; | ||
} | ||
if (!args[0]) { | ||
console.error("🧱 Formbricks - Global error: You need to pass the apiHost as the first argument"); | ||
return; | ||
} | ||
const { apiHost } = args[0]; | ||
const loadSDKResult = await wrapThrowsAsync(loadFormbricksAppSDK)(apiHost); | ||
if (!loadSDKResult.ok) { | ||
console.error(`🧱 Formbricks - Global error: ${loadSDKResult.error.message}`); | ||
return; | ||
} | ||
} | ||
if (window.formbricks && typeof window.formbricks[prop] !== "function") { | ||
console.error( | ||
`🧱 Formbricks - Global error: Formbricks App SDK does not support method ${String(prop)}` | ||
); | ||
return; | ||
} | ||
try { | ||
return window.formbricks[prop](...args); | ||
} catch (error) { | ||
console.error(`Something went wrong: ${error}`); | ||
return; | ||
} | ||
}; | ||
return (...args) => loadFormbricksToProxy(prop, "app", ...args); | ||
} | ||
@@ -71,0 +6,0 @@ }; |
@@ -10,4 +10,4 @@ import z from 'zod'; | ||
declare const formbricksApp: TFormbricksWebsite; | ||
export default formbricksApp; | ||
declare const formbricksWebsite: TFormbricksWebsite; | ||
export default formbricksWebsite; | ||
@@ -14,0 +14,0 @@ declare type TFormbricksWebsite = typeof formbricks; |
@@ -1,76 +0,11 @@ | ||
import { w as wrapThrowsAsync } from "./errorHandlers-N7AebTum.js"; | ||
async function loadFormbricksWebsiteSDK(apiHost) { | ||
if (!window.formbricks) { | ||
const res = await fetch(`${apiHost}/api/packages/website`); | ||
if (!res.ok) { | ||
return { ok: false, error: new Error("Failed to load Formbricks Website SDK") }; | ||
} | ||
const sdkScript = await res.text(); | ||
const scriptTag = document.createElement("script"); | ||
scriptTag.innerHTML = sdkScript; | ||
document.head.appendChild(scriptTag); | ||
const getFormbricks = async () => new Promise((resolve, reject) => { | ||
const checkInterval = setInterval(() => { | ||
if (window.formbricks) { | ||
clearInterval(checkInterval); | ||
resolve(); | ||
} | ||
}, 100); | ||
setTimeout(() => { | ||
clearInterval(checkInterval); | ||
reject(new Error("Formbricks Website SDK loading timed out")); | ||
}, 1e4); | ||
}); | ||
try { | ||
await getFormbricks(); | ||
return { ok: true, data: void 0 }; | ||
} catch (error) { | ||
return { | ||
ok: false, | ||
error: new Error(error.message ?? "Failed to load Formbricks Website SDK") | ||
}; | ||
} | ||
} | ||
return { ok: true, data: void 0 }; | ||
} | ||
import { l as loadFormbricksToProxy } from "./loadFormbricks-BzaImH2L.js"; | ||
const formbricksProxyHandler = { | ||
get(_target, prop, _receiver) { | ||
return async (...args) => { | ||
if (!window.formbricks) { | ||
if (prop !== "init") { | ||
console.error( | ||
"🧱 Formbricks - Global error: You need to call formbricks.init before calling any other method" | ||
); | ||
return; | ||
} | ||
if (!args[0]) { | ||
console.error("🧱 Formbricks - Global error: You need to pass the apiHost as the first argument"); | ||
return; | ||
} | ||
const { apiHost } = args[0]; | ||
const loadSDKResult = await wrapThrowsAsync(loadFormbricksWebsiteSDK)(apiHost); | ||
if (!loadSDKResult.ok) { | ||
console.error(`🧱 Formbricks - Global error: ${loadSDKResult.error.message}`); | ||
return; | ||
} | ||
} | ||
if (window.formbricks && typeof window.formbricks[prop] !== "function") { | ||
console.error( | ||
`🧱 Formbricks - Global error: Formbricks Website SDK does not support method ${String(prop)}` | ||
); | ||
return; | ||
} | ||
try { | ||
return window.formbricks[prop](...args); | ||
} catch (error) { | ||
console.error(`🧱 Formbricks - Global error: Something went wrong: ${error}`); | ||
return; | ||
} | ||
}; | ||
return (...args) => loadFormbricksToProxy(prop, "website", ...args); | ||
} | ||
}; | ||
const formbricksApp = new Proxy({}, formbricksProxyHandler); | ||
const formbricksWebsite = new Proxy({}, formbricksProxyHandler); | ||
export { | ||
formbricksApp as default | ||
formbricksWebsite as default | ||
}; | ||
//# sourceMappingURL=website.js.map |
{ | ||
"name": "@formbricks/js", | ||
"license": "MIT", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Formbricks-js allows you to connect your app to Formbricks, display surveys and trigger events.", | ||
@@ -35,8 +35,8 @@ "homepage": "https://formbricks.com", | ||
"devDependencies": { | ||
"terser": "^5.30.4", | ||
"vite": "^5.2.10", | ||
"vite-plugin-dts": "^3.9.0", | ||
"@formbricks/js-core": "1.0.0", | ||
"terser": "^5.31.0", | ||
"vite": "^5.2.11", | ||
"vite-plugin-dts": "^3.9.1", | ||
"@formbricks/tsconfig": "1.0.0", | ||
"eslint-config-formbricks": "1.0.0", | ||
"@formbricks/tsconfig": "1.0.0" | ||
"@formbricks/js-core": "1.0.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "scripts": { |
@@ -18,3 +18,3 @@ # Formbricks Browser JS Library | ||
```bash | ||
npm install -s @formbricks/js | ||
npm install @formbricks/js | ||
``` | ||
@@ -21,0 +21,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
2
46668
374