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,aAAA,CAAAA,MAAA,CAAA,QAAA,EAAA,IAAA,kBACEA,MAAA,CAAA,aAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,EAAG,EAAA,qBAAA;AAAA,MACH,QAAS,EAAA,mBAAA;AAAA,MACT,uBAAyB,EAAA;AAAA,QACvB,MAAQ,EAAA;AAAA;AACV;AAAA,GAEF,kBAAAA,MAAA,CAAA,aAAA,CAAC,MAAO,EAAA,EAAA,EAAA,EAAG,kBAAmB,EAAA,GAAA,EAAK,MAAQ,EAAA,QAAA,EAAS,kBAAmB,EAAA,CAAA,EACtE,QACH,CAAA;AAEJ","file":"index.mjs","sourcesContent":["import \"./global\";\nimport { generateUserIdentitySignature } from \"./utils/signing\";\n\nconst CDN_URL = \"https://cdn.userjot.com/sdk/v1/uj.js\";\n\nexport type InitOptions = {};\n\nexport type IdentifyOptions = {\n  id: string;\n  email: string;\n  firstName?: string;\n  lastName?: string;\n  avatar?: string;\n};\n\nexport interface IUserJot {\n  /**\n   * Initializes the widget.\n   * @param projectId - The project id.\n   * @param options - The options for the widget.\n   */\n  init(projectId: string, options?: InitOptions): void;\n\n  /**\n   * Sets the user id.\n   * @param options - The options for the user.\n   */\n  identify(options: IdentifyOptions | null): void;\n\n  /**\n   * Sets a property for the user.\n   * @param key - The key of the property.\n   * @param value - The value of the property.\n   */\n  setProperty(key: string, value: string | number | boolean | null): void;\n\n  /**\n   * Destroys the widget.\n   */\n  destroy(): void;\n}\n\nexport { CDN_URL, generateUserIdentitySignature };\n","import \"@userjot/core\";\n\n/**\n * A higher-order function that ensures a given function is only called on the client-side.\n * Throws an error if called on the server.\n * @param fn The function to be wrapped.\n * @returns The wrapped function.\n */\nconst ensureClientSide = <T extends (...args: any[]) => any>(fn: T) => {\n  if (typeof window === \"undefined\") {\n    console.warn(\"UserJot client functions cannot be used on the server.\");\n    return (() => {}) as T;\n  }\n  if (typeof window.uj === \"undefined\") {\n    console.warn(\"UserJot library is not available on the window object.\");\n    return (() => {}) as T;\n  }\n  return fn;\n};\n\nconst identify: (typeof window)[\"uj\"][\"identify\"] = ensureClientSide(\n  (options) => {\n    window.uj.identify(options);\n  }\n);\n\n/**\n * A React hook that provides access to UserJot client functions.\n * @returns An object containing UserJot client functions.\n */\nexport const useUserJot = () => {\n  return {\n    identify,\n  };\n};\n","import React, { PropsWithChildren } from \"react\";\nimport { CDN_URL, InitOptions } from \"@userjot/core\";\nimport Script from \"next/script\";\n\ninterface IUserJotProviderProps {\n  /** Your UserJot Project ID */\n  projectId: string;\n  /** The URL for the UserJot SDK. Defaults to the UserJot CDN. */\n  sdkUrl?: string;\n  /** The options for the UserJot SDK. These are defined in `@userjot/core`. */\n  options?: InitOptions;\n}\n\n/**\n * `UserJotProvider` is a React component that initializes the UserJot SDK.\n * It should wrap the root of your application or the part of your application\n * where you want to use UserJot.\n *\n * It includes the UserJot SDK script and initializes it with your Project ID\n * and any specified options.\n *\n * @param {PropsWithChildren<IUserJotProviderProps>} props - The props for the component.\n * @param {string} props.projectId - Your UserJot Project ID. This is required.\n * @param {React.ReactNode} props.children - The child components to render.\n * @param {string} [props.sdkUrl] - The URL for the UserJot SDK. Defaults to the UserJot CDN.\n * @param {InitOptions} [props.options] - The options for the UserJot SDK. These are defined in `@userjot/core`.\n * @returns {JSX.Element} - The provider component wrapping the children and UserJot SDK scripts.\n */\nexport const UserJotProvider: React.FC<\n  PropsWithChildren<IUserJotProviderProps>\n> = ({ projectId, children, sdkUrl = CDN_URL, options }) => {\n  if (!projectId) {\n    console.warn(\n      \"UserJotProvider: `projectId` prop is missing. UserJot SDK will not be configured.\"\n    );\n    return <>{children}</>;\n  }\n\n  const serializedOptions = JSON.stringify(options);\n  const inlineInitializationScript = `\n    const options = ${serializedOptions};\n    window.$ujq = window.$ujq || [];\n    window.uj = window.uj || new Proxy({}, {\n      get: function(_target, prop) {\n        return function(...args) {\n          window.$ujq.push([String(prop), ...args]);\n        };\n      }\n    });\n    window.uj.init('${projectId}', ${serializedOptions});\n  `;\n\n  return (\n    <>\n      <Script\n        id=\"userjot-init-config\"\n        strategy=\"beforeInteractive\"\n        dangerouslySetInnerHTML={{\n          __html: inlineInitializationScript,\n        }}\n      />\n      <Script id=\"userjot-sdk-main\" src={sdkUrl} strategy=\"afterInteractive\" />\n      {children}\n    </>\n  );\n};\n"]}