@greatapps/common 1.1.204 → 1.1.205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,20 +7,21 @@ const V4_WHITELABEL_ID = 367568;
7
7
  const CRISP_WEBSITE_ID = "3339a3ec-b4c6-4aac-8b86-45668fb7655c";
8
8
  const CRISP_SCRIPT_URL = "https://client.crisp.chat/l.js";
9
9
  const CRISP_LOAD_DELAY = 800;
10
- function openCrispHelpdesk() {
11
- if (typeof window !== "undefined" && window.$crisp) {
12
- window.$crisp.push(["do", "helpdesk:search"]);
10
+ function safeCrispPush(args) {
11
+ try {
12
+ const $crisp = window?.$crisp;
13
+ if ($crisp) $crisp.push(args);
14
+ } catch {
13
15
  }
14
16
  }
17
+ function openCrispHelpdesk() {
18
+ safeCrispPush(["do", "helpdesk:search"]);
19
+ }
15
20
  function hideCrisp() {
16
- if (typeof window !== "undefined" && window.$crisp) {
17
- window.$crisp.push(["do", "chat:hide"]);
18
- }
21
+ safeCrispPush(["do", "chat:hide"]);
19
22
  }
20
23
  function showCrisp() {
21
- if (typeof window !== "undefined" && window.$crisp) {
22
- window.$crisp.push(["do", "chat:show"]);
23
- }
24
+ safeCrispPush(["do", "chat:show"]);
24
25
  }
25
26
  function CrispEmbed() {
26
27
  const { user, account } = useAuth();
@@ -31,41 +32,50 @@ function CrispEmbed() {
31
32
  const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
32
33
  useEffect(() => {
33
34
  if (!user || scriptLoadedRef.current) return;
34
- const win = window;
35
- win.$crisp = [];
36
- win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
37
- win.$crisp.push(["config", "container:index", [100]]);
38
- const timeout = setTimeout(() => {
39
- if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
40
- const s = document.createElement("script");
41
- s.src = CRISP_SCRIPT_URL;
42
- s.async = true;
43
- document.head.appendChild(s);
44
- scriptLoadedRef.current = true;
45
- }, CRISP_LOAD_DELAY);
46
- return () => clearTimeout(timeout);
35
+ try {
36
+ const win = window;
37
+ win.$crisp = [];
38
+ win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
39
+ win.$crisp.push(["config", "container:index", [100]]);
40
+ const timeout = setTimeout(() => {
41
+ try {
42
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
43
+ const s = document.createElement("script");
44
+ s.src = CRISP_SCRIPT_URL;
45
+ s.async = true;
46
+ document.head.appendChild(s);
47
+ scriptLoadedRef.current = true;
48
+ } catch {
49
+ }
50
+ }, CRISP_LOAD_DELAY);
51
+ return () => clearTimeout(timeout);
52
+ } catch {
53
+ }
47
54
  }, [user]);
48
55
  useEffect(() => {
49
- const $crisp = window.$crisp;
50
- if (!user || !$crisp) return;
51
- if (user.email) $crisp.push(["set", "user:email", user.email]);
52
- const fullName = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
53
- if (fullName) $crisp.push(["set", "user:nickname", fullName]);
54
- if (account?.name) $crisp.push(["set", "user:company", account.name]);
55
- const phone = `${user.ddi ?? ""}${user.phone ?? ""}`.trim();
56
- if (phone) $crisp.push(["set", "user:phone", phone]);
57
- if (user.photo && user.photo.startsWith("http")) {
58
- $crisp.push(["set", "user:avatar", user.photo]);
59
- }
60
- if (isV4) {
61
- $crisp.push(["set", "session:segments", [["company_v4"]]]);
62
- $crisp.push(["set", "session:data", [[["Company", "V4"]]]]);
63
- } else {
64
- const planName = subscription?.plan_name ?? "";
65
- if (planName) $crisp.push(["set", "session:segments", [[`plano_${planName}`]]]);
66
- if (user.profile) $crisp.push(["set", "session:segments", [[`usuario_${user.profile}`]]]);
67
- if (planName) $crisp.push(["set", "session:data", [[["Plano", planName]]]]);
68
- if (user.profile) $crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
56
+ try {
57
+ const $crisp = window?.$crisp;
58
+ if (!user || !$crisp) return;
59
+ if (user.email) $crisp.push(["set", "user:email", user.email]);
60
+ const fullName = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
61
+ if (fullName) $crisp.push(["set", "user:nickname", fullName]);
62
+ if (account?.name) $crisp.push(["set", "user:company", account.name]);
63
+ const phone = `${user.ddi ?? ""}${user.phone ?? ""}`.trim();
64
+ if (phone) $crisp.push(["set", "user:phone", phone]);
65
+ if (user.photo && user.photo.startsWith("http")) {
66
+ $crisp.push(["set", "user:avatar", user.photo]);
67
+ }
68
+ if (isV4) {
69
+ $crisp.push(["set", "session:segments", [["company_v4"]]]);
70
+ $crisp.push(["set", "session:data", [[["Company", "V4"]]]]);
71
+ } else {
72
+ const planName = subscription?.plan_name ?? "";
73
+ if (planName) $crisp.push(["set", "session:segments", [[`plano_${planName}`]]]);
74
+ if (user.profile) $crisp.push(["set", "session:segments", [[`usuario_${user.profile}`]]]);
75
+ if (planName) $crisp.push(["set", "session:data", [[["Plano", planName]]]]);
76
+ if (user.profile) $crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
77
+ }
78
+ } catch {
69
79
  }
70
80
  }, [user, account, isV4, subscription?.plan_name]);
71
81
  return null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/embeds/CrispEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';\nconst CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';\nconst CRISP_LOAD_DELAY = 800;\n\nexport function openCrispHelpdesk() {\n if (typeof window !== 'undefined' && (window as any).$crisp) {\n (window as any).$crisp.push(['do', 'helpdesk:search']);\n }\n}\n\nexport function hideCrisp() {\n if (typeof window !== 'undefined' && (window as any).$crisp) {\n (window as any).$crisp.push(['do', 'chat:hide']);\n }\n}\n\nexport function showCrisp() {\n if (typeof window !== 'undefined' && (window as any).$crisp) {\n (window as any).$crisp.push(['do', 'chat:show']);\n }\n}\n\nexport function CrispEmbed() {\n const { user, account } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const scriptLoadedRef = useRef(false);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n // Load Crisp script (once, with 800ms delay)\n useEffect(() => {\n if (!user || scriptLoadedRef.current) return;\n\n const win = window as any;\n win.$crisp = [];\n win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n win.$crisp.push(['config', 'container:index', [100]]);\n\n const timeout = setTimeout(() => {\n if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) return;\n const s = document.createElement('script');\n s.src = CRISP_SCRIPT_URL;\n s.async = true;\n document.head.appendChild(s);\n scriptLoadedRef.current = true;\n }, CRISP_LOAD_DELAY);\n\n return () => clearTimeout(timeout);\n }, [user]);\n\n // Identify user\n useEffect(() => {\n const $crisp = (window as any).$crisp;\n if (!user || !$crisp) return;\n\n if (user.email) $crisp.push(['set', 'user:email', user.email]);\n\n const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n if (fullName) $crisp.push(['set', 'user:nickname', fullName]);\n\n if (account?.name) $crisp.push(['set', 'user:company', account.name]);\n\n const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();\n if (phone) $crisp.push(['set', 'user:phone', phone]);\n\n if (user.photo && user.photo.startsWith('http')) {\n $crisp.push(['set', 'user:avatar', user.photo]);\n }\n\n if (isV4) {\n $crisp.push(['set', 'session:segments', [['company_v4']]]);\n $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);\n } else {\n const planName = subscription?.plan_name ?? '';\n if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);\n if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);\n if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);\n if (user.profile) $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);\n }\n }, [user, account, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAElB,SAAS,oBAAoB;AAClC,MAAI,OAAO,WAAW,eAAgB,OAAe,QAAQ;AAC3D,IAAC,OAAe,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAAA,EACvD;AACF;AAEO,SAAS,YAAY;AAC1B,MAAI,OAAO,WAAW,eAAgB,OAAe,QAAQ;AAC3D,IAAC,OAAe,OAAO,KAAK,CAAC,MAAM,WAAW,CAAC;AAAA,EACjD;AACF;AAEO,SAAS,YAAY;AAC1B,MAAI,OAAO,WAAW,eAAgB,OAAe,QAAQ;AAC3D,IAAC,OAAe,OAAO,KAAK,CAAC,MAAM,WAAW,CAAC;AAAA,EACjD;AACF;AAEO,SAAS,aAAa;AAC3B,QAAM,EAAE,MAAM,QAAQ,IAAI,QAAQ;AAClC,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,EAAE,MAAM,iBAAiB,IAAI,sBAAsB;AACzD,QAAM,kBAAkB,OAAO,KAAK;AAEpC,QAAM,eAAe,kBAAkB,OAAO,CAAC,KAAK;AACpD,QAAM,OAAO,YAAY,OAAO;AAGhC,YAAU,MAAM;AACd,QAAI,CAAC,QAAQ,gBAAgB,QAAS;AAEtC,UAAM,MAAM;AACZ,QAAI,SAAS,CAAC;AACd,QAAI,mBAAmB;AACvB,QAAI,OAAO,KAAK,CAAC,UAAU,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAEpD,UAAM,UAAU,WAAW,MAAM;AAC/B,UAAI,SAAS,cAAc,eAAe,gBAAgB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AAO,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC;AACxF,UAAI,SAAU,QAAO,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC1E,UAAI,KAAK,QAAS,QAAO,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAAA,IACtF;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,MAAM,cAAc,SAAS,CAAC;AAEjD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/embeds/CrispEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';\nconst CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';\nconst CRISP_LOAD_DELAY = 800;\n\nfunction safeCrispPush(args: any[]) {\n try {\n const $crisp = (window as any)?.$crisp;\n if ($crisp) $crisp.push(args);\n } catch {}\n}\n\nexport function openCrispHelpdesk() {\n safeCrispPush(['do', 'helpdesk:search']);\n}\n\nexport function hideCrisp() {\n safeCrispPush(['do', 'chat:hide']);\n}\n\nexport function showCrisp() {\n safeCrispPush(['do', 'chat:show']);\n}\n\nexport function CrispEmbed() {\n const { user, account } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const scriptLoadedRef = useRef(false);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n // Load Crisp script (once, with 800ms delay)\n useEffect(() => {\n if (!user || scriptLoadedRef.current) return;\n\n try {\n const win = window as any;\n win.$crisp = [];\n win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n win.$crisp.push(['config', 'container:index', [100]]);\n\n const timeout = setTimeout(() => {\n try {\n if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) return;\n const s = document.createElement('script');\n s.src = CRISP_SCRIPT_URL;\n s.async = true;\n document.head.appendChild(s);\n scriptLoadedRef.current = true;\n } catch {}\n }, CRISP_LOAD_DELAY);\n\n return () => clearTimeout(timeout);\n } catch {}\n }, [user]);\n\n // Identify user\n useEffect(() => {\n try {\n const $crisp = (window as any)?.$crisp;\n if (!user || !$crisp) return;\n\n if (user.email) $crisp.push(['set', 'user:email', user.email]);\n\n const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n if (fullName) $crisp.push(['set', 'user:nickname', fullName]);\n\n if (account?.name) $crisp.push(['set', 'user:company', account.name]);\n\n const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();\n if (phone) $crisp.push(['set', 'user:phone', phone]);\n\n if (user.photo && user.photo.startsWith('http')) {\n $crisp.push(['set', 'user:avatar', user.photo]);\n }\n\n if (isV4) {\n $crisp.push(['set', 'session:segments', [['company_v4']]]);\n $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);\n } else {\n const planName = subscription?.plan_name ?? '';\n if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);\n if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);\n if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);\n if (user.profile) $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);\n }\n } catch {}\n }, [user, account, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;A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AAC,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAAA,MACtF;AAAA,IACF,QAAQ;AAAA,IAAC;AAAA,EACX,GAAG,CAAC,MAAM,SAAS,MAAM,cAAc,SAAS,CAAC;AAEjD,SAAO;AACT;","names":[]}
@@ -12,39 +12,45 @@ const WIDGETS = [
12
12
  { key: "720c0912-e6a4-495c-835e-3ff1f59d6dfc" }
13
13
  ];
14
14
  function initFrillLoader() {
15
- const win = window;
16
- if (win.Frill) return;
17
- let counter = 0;
18
- const queue = {};
19
- win.Frill = function(action, params) {
20
- let instance;
21
- const id = counter++;
22
- const promise = new Promise((resolve, reject) => {
23
- queue[id] = {
24
- params: [action, params],
25
- resolve: (f) => {
26
- instance = f;
27
- resolve(f);
28
- },
29
- reject
15
+ try {
16
+ const win = window;
17
+ if (win.Frill) return;
18
+ let counter = 0;
19
+ const queue = {};
20
+ win.Frill = function(action, params) {
21
+ let instance;
22
+ const id = counter++;
23
+ const promise = new Promise((resolve, reject) => {
24
+ queue[id] = {
25
+ params: [action, params],
26
+ resolve: (f) => {
27
+ instance = f;
28
+ resolve(f);
29
+ },
30
+ reject
31
+ };
32
+ });
33
+ promise.destroy = () => {
34
+ delete queue[id];
35
+ instance?.destroy();
30
36
  };
31
- });
32
- promise.destroy = () => {
33
- delete queue[id];
34
- instance?.destroy();
37
+ return promise;
35
38
  };
36
- return promise;
37
- };
38
- win.Frill.q = queue;
39
+ win.Frill.q = queue;
40
+ } catch {
41
+ }
39
42
  }
40
43
  function loadFrillScript() {
41
- if (document.querySelector(`script[src="${FRILL_SCRIPT_URL}"]`)) return;
42
- const anchor = document.getElementsByTagName("script")[0];
43
- const script = document.createElement("script");
44
- script.type = "text/javascript";
45
- script.async = true;
46
- script.src = FRILL_SCRIPT_URL;
47
- anchor?.parentNode?.insertBefore(script, anchor);
44
+ try {
45
+ if (document.querySelector(`script[src="${FRILL_SCRIPT_URL}"]`)) return;
46
+ const anchor = document.getElementsByTagName("script")[0];
47
+ const script = document.createElement("script");
48
+ script.type = "text/javascript";
49
+ script.async = true;
50
+ script.src = FRILL_SCRIPT_URL;
51
+ anchor?.parentNode?.insertBefore(script, anchor);
52
+ } catch {
53
+ }
48
54
  }
49
55
  function FrillEmbed() {
50
56
  const { user } = useAuth();
@@ -55,36 +61,42 @@ function FrillEmbed() {
55
61
  const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
56
62
  useEffect(() => {
57
63
  if (!user) return;
58
- initFrillLoader();
59
- if (document.readyState === "complete" || document.readyState === "interactive") {
60
- loadFrillScript();
61
- } else {
62
- document.addEventListener("DOMContentLoaded", loadFrillScript);
63
- }
64
- const userData = {
65
- id: String(user.id ?? "")
66
- };
67
- if (user.email) userData.email = user.email;
68
- if (user.name || user.last_name) {
69
- userData.name = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
70
- }
71
- userData.attributes = isV4 ? { company: "V4" } : { profile: user.profile ?? "", plan: subscription?.plan_name ?? "" };
72
- const config = { key: FRILL_KEY, user: userData };
73
- if (!isV4) {
74
- config.surveys = SURVEYS;
75
- config.widgets = WIDGETS;
64
+ try {
65
+ initFrillLoader();
66
+ if (document.readyState === "complete" || document.readyState === "interactive") {
67
+ loadFrillScript();
68
+ } else {
69
+ document.addEventListener("DOMContentLoaded", loadFrillScript);
70
+ }
71
+ const userData = {
72
+ id: String(user.id ?? "")
73
+ };
74
+ if (user.email) userData.email = user.email;
75
+ if (user.name || user.last_name) {
76
+ userData.name = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
77
+ }
78
+ userData.attributes = isV4 ? { company: "V4" } : { profile: user.profile ?? "", plan: subscription?.plan_name ?? "" };
79
+ const config = { key: FRILL_KEY, user: userData };
80
+ if (!isV4) {
81
+ config.surveys = SURVEYS;
82
+ config.widgets = WIDGETS;
83
+ }
84
+ const win = window;
85
+ const containerPromise = win.Frill("container", config);
86
+ win.Frill("identify", userData);
87
+ containerPromise.then((widget) => {
88
+ containerRef.current = widget;
89
+ }).catch(() => {
90
+ });
91
+ } catch {
76
92
  }
77
- const win = window;
78
- const containerPromise = win.Frill("container", config);
79
- win.Frill("identify", userData);
80
- containerPromise.then((widget) => {
81
- containerRef.current = widget;
82
- }).catch(() => {
83
- });
84
93
  return () => {
85
- containerRef.current?.destroy();
86
- containerRef.current = null;
87
- document.removeEventListener("DOMContentLoaded", loadFrillScript);
94
+ try {
95
+ containerRef.current?.destroy();
96
+ containerRef.current = null;
97
+ document.removeEventListener("DOMContentLoaded", loadFrillScript);
98
+ } catch {
99
+ }
88
100
  };
89
101
  }, [user, isV4, subscription?.plan_name]);
90
102
  return null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/embeds/FrillEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst FRILL_SCRIPT_URL = 'https://widget.frill.co/v2/container.js';\nconst FRILL_KEY = '2f77f232-a120-438e-8ef6-01912ffd1b99';\n\nconst SURVEYS = [{ key: '7f59dbf6-b665-458a-80e2-778de47efe1c' }];\nconst WIDGETS = [\n { key: '4a5ba13b-1150-49fe-aa15-f9a2da0ba909' },\n { key: '720c0912-e6a4-495c-835e-3ff1f59d6dfc' },\n];\n\nfunction initFrillLoader() {\n const win = window as any;\n if (win.Frill) return;\n\n let counter = 0;\n const queue: Record<number, any> = {};\n\n win.Frill = function (action: string, params: any) {\n let instance: any;\n const id = counter++;\n const promise: any = new Promise((resolve, reject) => {\n queue[id] = {\n params: [action, params],\n resolve: (f: any) => {\n instance = f;\n resolve(f);\n },\n reject,\n };\n });\n promise.destroy = () => {\n delete queue[id];\n instance?.destroy();\n };\n return promise;\n };\n win.Frill.q = queue;\n}\n\nfunction loadFrillScript() {\n if (document.querySelector(`script[src=\"${FRILL_SCRIPT_URL}\"]`)) return;\n const anchor = document.getElementsByTagName('script')[0];\n const script = document.createElement('script');\n script.type = 'text/javascript';\n script.async = true;\n script.src = FRILL_SCRIPT_URL;\n anchor?.parentNode?.insertBefore(script, anchor);\n}\n\nexport function FrillEmbed() {\n const { user } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const containerRef = useRef<any>(null);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n useEffect(() => {\n if (!user) return;\n\n initFrillLoader();\n\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n loadFrillScript();\n } else {\n document.addEventListener('DOMContentLoaded', loadFrillScript);\n }\n\n const userData: Record<string, any> = {\n id: String(user.id ?? ''),\n };\n if (user.email) userData.email = user.email;\n if (user.name || user.last_name) {\n userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n }\n userData.attributes = isV4\n ? { company: 'V4' }\n : { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };\n\n const config: Record<string, any> = { key: FRILL_KEY, user: userData };\n if (!isV4) {\n config.surveys = SURVEYS;\n config.widgets = WIDGETS;\n }\n\n const win = window as any;\n const containerPromise = win.Frill('container', config);\n win.Frill('identify', userData);\n\n containerPromise.then((widget: any) => {\n containerRef.current = widget;\n }).catch(() => {});\n\n return () => {\n containerRef.current?.destroy();\n containerRef.current = null;\n document.removeEventListener('DOMContentLoaded', loadFrillScript);\n };\n }, [user, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAElB,MAAM,UAAU,CAAC,EAAE,KAAK,uCAAuC,CAAC;AAChE,MAAM,UAAU;AAAA,EACd,EAAE,KAAK,uCAAuC;AAAA,EAC9C,EAAE,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D;AAEA,UAAM,WAAgC;AAAA,MACpC,IAAI,OAAO,KAAK,MAAM,EAAE;AAAA,IAC1B;AACA,QAAI,KAAK,MAAO,UAAS,QAAQ,KAAK;AACtC,QAAI,KAAK,QAAQ,KAAK,WAAW;AAC/B,eAAS,OAAO,GAAG,KAAK,QAAQ,EAAE,IAAI,KAAK,aAAa,EAAE,GAAG,KAAK;AAAA,IACpE;AACA,aAAS,aAAa,OAClB,EAAE,SAAS,KAAK,IAChB,EAAE,SAAS,KAAK,WAAW,IAAI,MAAM,cAAc,aAAa,GAAG;AAEvE,UAAM,SAA8B,EAAE,KAAK,WAAW,MAAM,SAAS;AACrE,QAAI,CAAC,MAAM;AACT,aAAO,UAAU;AACjB,aAAO,UAAU;AAAA,IACnB;AAEA,UAAM,MAAM;AACZ,UAAM,mBAAmB,IAAI,MAAM,aAAa,MAAM;AACtD,QAAI,MAAM,YAAY,QAAQ;AAE9B,qBAAiB,KAAK,CAAC,WAAgB;AACrC,mBAAa,UAAU;AAAA,IACzB,CAAC,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAEjB,WAAO,MAAM;AACX,mBAAa,SAAS,QAAQ;AAC9B,mBAAa,UAAU;AACvB,eAAS,oBAAoB,oBAAoB,eAAe;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,cAAc,SAAS,CAAC;AAExC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/embeds/FrillEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst FRILL_SCRIPT_URL = 'https://widget.frill.co/v2/container.js';\nconst FRILL_KEY = '2f77f232-a120-438e-8ef6-01912ffd1b99';\n\nconst SURVEYS = [{ key: '7f59dbf6-b665-458a-80e2-778de47efe1c' }];\nconst WIDGETS = [\n { key: '4a5ba13b-1150-49fe-aa15-f9a2da0ba909' },\n { key: '720c0912-e6a4-495c-835e-3ff1f59d6dfc' },\n];\n\nfunction initFrillLoader() {\n try {\n const win = window as any;\n if (win.Frill) return;\n\n let counter = 0;\n const queue: Record<number, any> = {};\n\n win.Frill = function (action: string, params: any) {\n let instance: any;\n const id = counter++;\n const promise: any = new Promise((resolve, reject) => {\n queue[id] = {\n params: [action, params],\n resolve: (f: any) => {\n instance = f;\n resolve(f);\n },\n reject,\n };\n });\n promise.destroy = () => {\n delete queue[id];\n instance?.destroy();\n };\n return promise;\n };\n win.Frill.q = queue;\n } catch {}\n}\n\nfunction loadFrillScript() {\n try {\n if (document.querySelector(`script[src=\"${FRILL_SCRIPT_URL}\"]`)) return;\n const anchor = document.getElementsByTagName('script')[0];\n const script = document.createElement('script');\n script.type = 'text/javascript';\n script.async = true;\n script.src = FRILL_SCRIPT_URL;\n anchor?.parentNode?.insertBefore(script, anchor);\n } catch {}\n}\n\nexport function FrillEmbed() {\n const { user } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const containerRef = useRef<any>(null);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n useEffect(() => {\n if (!user) return;\n\n try {\n initFrillLoader();\n\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n loadFrillScript();\n } else {\n document.addEventListener('DOMContentLoaded', loadFrillScript);\n }\n\n const userData: Record<string, any> = {\n id: String(user.id ?? ''),\n };\n if (user.email) userData.email = user.email;\n if (user.name || user.last_name) {\n userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n }\n userData.attributes = isV4\n ? { company: 'V4' }\n : { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };\n\n const config: Record<string, any> = { key: FRILL_KEY, user: userData };\n if (!isV4) {\n config.surveys = SURVEYS;\n config.widgets = WIDGETS;\n }\n\n const win = window as any;\n const containerPromise = win.Frill('container', config);\n win.Frill('identify', userData);\n\n containerPromise.then((widget: any) => {\n containerRef.current = widget;\n }).catch(() => {});\n } catch {}\n\n return () => {\n try {\n containerRef.current?.destroy();\n containerRef.current = null;\n document.removeEventListener('DOMContentLoaded', loadFrillScript);\n } catch {}\n };\n }, [user, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAElB,MAAM,UAAU,CAAC,EAAE,KAAK,uCAAuC,CAAC;AAChE,MAAM,UAAU;AAAA,EACd,EAAE,KAAK,uCAAuC;AAAA,EAC9C,EAAE,KAAK,uCAAuC;AAChD;AAEA,SAAS,kBAAkB;AACzB,MAAI;AACF,UAAM,MAAM;AACZ,QAAI,IAAI,MAAO;AAEf,QAAI,UAAU;AACd,UAAM,QAA6B,CAAC;AAEpC,QAAI,QAAQ,SAAU,QAAgB,QAAa;AACjD,UAAI;AACJ,YAAM,KAAK;AACX,YAAM,UAAe,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpD,cAAM,EAAE,IAAI;AAAA,UACV,QAAQ,CAAC,QAAQ,MAAM;AAAA,UACvB,SAAS,CAAC,MAAW;AACnB,uBAAW;AACX,oBAAQ,CAAC;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AACD,cAAQ,UAAU,MAAM;AACtB,eAAO,MAAM,EAAE;AACf,kBAAU,QAAQ;AAAA,MACpB;AACA,aAAO;AAAA,IACT;AACA,QAAI,MAAM,IAAI;AAAA,EAChB,QAAQ;AAAA,EAAC;AACX;AAEA,SAAS,kBAAkB;AACzB,MAAI;AACF,QAAI,SAAS,cAAc,eAAe,gBAAgB,IAAI,EAAG;AACjE,UAAM,SAAS,SAAS,qBAAqB,QAAQ,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UAAU;AAAA,MACzB,CAAC,EAAE,MAAM,MAAM;AAAA,MAAC,CAAC;AAAA,IACnB,QAAQ;AAAA,IAAC;AAET,WAAO,MAAM;AACX,UAAI;AACF,qBAAa,SAAS,QAAQ;AAC9B,qBAAa,UAAU;AACvB,iBAAS,oBAAoB,oBAAoB,eAAe;AAAA,MAClE,QAAQ;AAAA,MAAC;AAAA,IACX;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,cAAc,SAAS,CAAC;AAExC,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.204",
3
+ "version": "1.1.205",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -11,22 +11,23 @@ const CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';
11
11
  const CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';
12
12
  const CRISP_LOAD_DELAY = 800;
13
13
 
14
+ function safeCrispPush(args: any[]) {
15
+ try {
16
+ const $crisp = (window as any)?.$crisp;
17
+ if ($crisp) $crisp.push(args);
18
+ } catch {}
19
+ }
20
+
14
21
  export function openCrispHelpdesk() {
15
- if (typeof window !== 'undefined' && (window as any).$crisp) {
16
- (window as any).$crisp.push(['do', 'helpdesk:search']);
17
- }
22
+ safeCrispPush(['do', 'helpdesk:search']);
18
23
  }
19
24
 
20
25
  export function hideCrisp() {
21
- if (typeof window !== 'undefined' && (window as any).$crisp) {
22
- (window as any).$crisp.push(['do', 'chat:hide']);
23
- }
26
+ safeCrispPush(['do', 'chat:hide']);
24
27
  }
25
28
 
26
29
  export function showCrisp() {
27
- if (typeof window !== 'undefined' && (window as any).$crisp) {
28
- (window as any).$crisp.push(['do', 'chat:show']);
29
- }
30
+ safeCrispPush(['do', 'chat:show']);
30
31
  }
31
32
 
32
33
  export function CrispEmbed() {
@@ -42,52 +43,58 @@ export function CrispEmbed() {
42
43
  useEffect(() => {
43
44
  if (!user || scriptLoadedRef.current) return;
44
45
 
45
- const win = window as any;
46
- win.$crisp = [];
47
- win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
48
- win.$crisp.push(['config', 'container:index', [100]]);
49
-
50
- const timeout = setTimeout(() => {
51
- if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
52
- const s = document.createElement('script');
53
- s.src = CRISP_SCRIPT_URL;
54
- s.async = true;
55
- document.head.appendChild(s);
56
- scriptLoadedRef.current = true;
57
- }, CRISP_LOAD_DELAY);
58
-
59
- return () => clearTimeout(timeout);
46
+ try {
47
+ const win = window as any;
48
+ win.$crisp = [];
49
+ win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
50
+ win.$crisp.push(['config', 'container:index', [100]]);
51
+
52
+ const timeout = setTimeout(() => {
53
+ try {
54
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
55
+ const s = document.createElement('script');
56
+ s.src = CRISP_SCRIPT_URL;
57
+ s.async = true;
58
+ document.head.appendChild(s);
59
+ scriptLoadedRef.current = true;
60
+ } catch {}
61
+ }, CRISP_LOAD_DELAY);
62
+
63
+ return () => clearTimeout(timeout);
64
+ } catch {}
60
65
  }, [user]);
61
66
 
62
67
  // Identify user
63
68
  useEffect(() => {
64
- const $crisp = (window as any).$crisp;
65
- if (!user || !$crisp) return;
66
-
67
- if (user.email) $crisp.push(['set', 'user:email', user.email]);
68
-
69
- const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
70
- if (fullName) $crisp.push(['set', 'user:nickname', fullName]);
71
-
72
- if (account?.name) $crisp.push(['set', 'user:company', account.name]);
73
-
74
- const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();
75
- if (phone) $crisp.push(['set', 'user:phone', phone]);
76
-
77
- if (user.photo && user.photo.startsWith('http')) {
78
- $crisp.push(['set', 'user:avatar', user.photo]);
79
- }
80
-
81
- if (isV4) {
82
- $crisp.push(['set', 'session:segments', [['company_v4']]]);
83
- $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);
84
- } else {
85
- const planName = subscription?.plan_name ?? '';
86
- if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);
87
- if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);
88
- if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
89
- if (user.profile) $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
90
- }
69
+ try {
70
+ const $crisp = (window as any)?.$crisp;
71
+ if (!user || !$crisp) return;
72
+
73
+ if (user.email) $crisp.push(['set', 'user:email', user.email]);
74
+
75
+ const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
76
+ if (fullName) $crisp.push(['set', 'user:nickname', fullName]);
77
+
78
+ if (account?.name) $crisp.push(['set', 'user:company', account.name]);
79
+
80
+ const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();
81
+ if (phone) $crisp.push(['set', 'user:phone', phone]);
82
+
83
+ if (user.photo && user.photo.startsWith('http')) {
84
+ $crisp.push(['set', 'user:avatar', user.photo]);
85
+ }
86
+
87
+ if (isV4) {
88
+ $crisp.push(['set', 'session:segments', [['company_v4']]]);
89
+ $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);
90
+ } else {
91
+ const planName = subscription?.plan_name ?? '';
92
+ if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);
93
+ if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);
94
+ if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
95
+ if (user.profile) $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
96
+ }
97
+ } catch {}
91
98
  }, [user, account, isV4, subscription?.plan_name]);
92
99
 
93
100
  return null;
@@ -17,42 +17,46 @@ const WIDGETS = [
17
17
  ];
18
18
 
19
19
  function initFrillLoader() {
20
- const win = window as any;
21
- if (win.Frill) return;
22
-
23
- let counter = 0;
24
- const queue: Record<number, any> = {};
25
-
26
- win.Frill = function (action: string, params: any) {
27
- let instance: any;
28
- const id = counter++;
29
- const promise: any = new Promise((resolve, reject) => {
30
- queue[id] = {
31
- params: [action, params],
32
- resolve: (f: any) => {
33
- instance = f;
34
- resolve(f);
35
- },
36
- reject,
20
+ try {
21
+ const win = window as any;
22
+ if (win.Frill) return;
23
+
24
+ let counter = 0;
25
+ const queue: Record<number, any> = {};
26
+
27
+ win.Frill = function (action: string, params: any) {
28
+ let instance: any;
29
+ const id = counter++;
30
+ const promise: any = new Promise((resolve, reject) => {
31
+ queue[id] = {
32
+ params: [action, params],
33
+ resolve: (f: any) => {
34
+ instance = f;
35
+ resolve(f);
36
+ },
37
+ reject,
38
+ };
39
+ });
40
+ promise.destroy = () => {
41
+ delete queue[id];
42
+ instance?.destroy();
37
43
  };
38
- });
39
- promise.destroy = () => {
40
- delete queue[id];
41
- instance?.destroy();
44
+ return promise;
42
45
  };
43
- return promise;
44
- };
45
- win.Frill.q = queue;
46
+ win.Frill.q = queue;
47
+ } catch {}
46
48
  }
47
49
 
48
50
  function loadFrillScript() {
49
- if (document.querySelector(`script[src="${FRILL_SCRIPT_URL}"]`)) return;
50
- const anchor = document.getElementsByTagName('script')[0];
51
- const script = document.createElement('script');
52
- script.type = 'text/javascript';
53
- script.async = true;
54
- script.src = FRILL_SCRIPT_URL;
55
- anchor?.parentNode?.insertBefore(script, anchor);
51
+ try {
52
+ if (document.querySelector(`script[src="${FRILL_SCRIPT_URL}"]`)) return;
53
+ const anchor = document.getElementsByTagName('script')[0];
54
+ const script = document.createElement('script');
55
+ script.type = 'text/javascript';
56
+ script.async = true;
57
+ script.src = FRILL_SCRIPT_URL;
58
+ anchor?.parentNode?.insertBefore(script, anchor);
59
+ } catch {}
56
60
  }
57
61
 
58
62
  export function FrillEmbed() {
@@ -67,43 +71,47 @@ export function FrillEmbed() {
67
71
  useEffect(() => {
68
72
  if (!user) return;
69
73
 
70
- initFrillLoader();
71
-
72
- if (document.readyState === 'complete' || document.readyState === 'interactive') {
73
- loadFrillScript();
74
- } else {
75
- document.addEventListener('DOMContentLoaded', loadFrillScript);
76
- }
77
-
78
- const userData: Record<string, any> = {
79
- id: String(user.id ?? ''),
80
- };
81
- if (user.email) userData.email = user.email;
82
- if (user.name || user.last_name) {
83
- userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
84
- }
85
- userData.attributes = isV4
86
- ? { company: 'V4' }
87
- : { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };
88
-
89
- const config: Record<string, any> = { key: FRILL_KEY, user: userData };
90
- if (!isV4) {
91
- config.surveys = SURVEYS;
92
- config.widgets = WIDGETS;
93
- }
74
+ try {
75
+ initFrillLoader();
94
76
 
95
- const win = window as any;
96
- const containerPromise = win.Frill('container', config);
97
- win.Frill('identify', userData);
77
+ if (document.readyState === 'complete' || document.readyState === 'interactive') {
78
+ loadFrillScript();
79
+ } else {
80
+ document.addEventListener('DOMContentLoaded', loadFrillScript);
81
+ }
98
82
 
99
- containerPromise.then((widget: any) => {
100
- containerRef.current = widget;
101
- }).catch(() => {});
83
+ const userData: Record<string, any> = {
84
+ id: String(user.id ?? ''),
85
+ };
86
+ if (user.email) userData.email = user.email;
87
+ if (user.name || user.last_name) {
88
+ userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
89
+ }
90
+ userData.attributes = isV4
91
+ ? { company: 'V4' }
92
+ : { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };
93
+
94
+ const config: Record<string, any> = { key: FRILL_KEY, user: userData };
95
+ if (!isV4) {
96
+ config.surveys = SURVEYS;
97
+ config.widgets = WIDGETS;
98
+ }
99
+
100
+ const win = window as any;
101
+ const containerPromise = win.Frill('container', config);
102
+ win.Frill('identify', userData);
103
+
104
+ containerPromise.then((widget: any) => {
105
+ containerRef.current = widget;
106
+ }).catch(() => {});
107
+ } catch {}
102
108
 
103
109
  return () => {
104
- containerRef.current?.destroy();
105
- containerRef.current = null;
106
- document.removeEventListener('DOMContentLoaded', loadFrillScript);
110
+ try {
111
+ containerRef.current?.destroy();
112
+ containerRef.current = null;
113
+ document.removeEventListener('DOMContentLoaded', loadFrillScript);
114
+ } catch {}
107
115
  };
108
116
  }, [user, isV4, subscription?.plan_name]);
109
117