saasco-sdk 0.2.3 → 0.2.4

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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { isValid, parse } from "psl";
3
3
 
4
4
  // package.json
5
- var version = "0.2.3";
5
+ var version = "0.2.4";
6
6
 
7
7
  // src/lib/timezones.ts
8
8
  var timezones = {
@@ -1989,15 +1989,15 @@ function isSocialProofQaMode() {
1989
1989
  }
1990
1990
 
1991
1991
  // src/lib/analytics.ts
1992
- function getSupportChatGlobal() {
1993
- return window.SaascoSupportChat;
1992
+ function getSupportGlobal() {
1993
+ return window.SaascoSupport;
1994
1994
  }
1995
1995
  var isBrowser5 = typeof window !== "undefined";
1996
1996
  var isServer5 = !isBrowser5;
1997
1997
  var PREF = "saasco-sdk";
1998
1998
  var SESSION_DURATION = 1e3 * 60 * 30;
1999
1999
  var USER_DURATION = 1e3 * 60 * 60 * 24 * 365;
2000
- var SUPPORT_CHAT_ATTR_MAP = {
2000
+ var SUPPORT_ATTR_MAP = {
2001
2001
  baseUrl: "data-base-url",
2002
2002
  placeholder: "data-placeholder"
2003
2003
  };
@@ -2168,7 +2168,7 @@ function getUserId() {
2168
2168
  function setUserId(userId) {
2169
2169
  storeData(`user-id`, userId ?? void 0, USER_DURATION);
2170
2170
  }
2171
- function buildSupportChatTraits(properties, envelope) {
2171
+ function buildSupportTraits(properties, envelope) {
2172
2172
  const traits = {};
2173
2173
  const add = (key, value) => {
2174
2174
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
@@ -2338,10 +2338,10 @@ var Saasco = class {
2338
2338
  integrationManager;
2339
2339
  logger;
2340
2340
  // Last identity handed to `identify()`, mirrored into the lazily-loaded
2341
- // support-chat widget so chat conversations attach to a CRM contact. Held
2341
+ // support widget so chat conversations attach to a CRM contact. Held
2342
2342
  // here so an `identify()` that fires before the widget bundle finishes
2343
2343
  // loading is replayed once it does.
2344
- lastSupportChatIdentity = null;
2344
+ lastSupportIdentity = null;
2345
2345
  init() {
2346
2346
  if (this.isInitialized) {
2347
2347
  this.logger.info(
@@ -2365,8 +2365,8 @@ var Saasco = class {
2365
2365
  );
2366
2366
  }
2367
2367
  this.initAutoPageTracking();
2368
- if (this.config.supportChat && this.config.supportChat.enabled !== false) {
2369
- this.injectSupportChat();
2368
+ if (this.config.support && this.config.support.enabled !== false) {
2369
+ this.injectSupport();
2370
2370
  }
2371
2371
  if (this.config.socialProof?.enabled !== false) {
2372
2372
  void this.injectSocialProof();
@@ -2382,19 +2382,19 @@ var Saasco = class {
2382
2382
  this.logger.info("Debug mode activated.");
2383
2383
  }
2384
2384
  /**
2385
- * Enables and injects the support chat widget when it was constructed with
2386
- * `supportChat: { enabled: false }`. Safe to call multiple times.
2385
+ * Enables and injects the support widget when it was constructed with
2386
+ * `support: { enabled: false }`. Safe to call multiple times.
2387
2387
  */
2388
- enableSupportChat() {
2389
- if (!this.config.supportChat) {
2388
+ enableSupport() {
2389
+ if (!this.config.support) {
2390
2390
  this.logger.warn(
2391
- "Support chat is not configured; enableSupportChat() was ignored."
2391
+ "Support is not configured; enableSupport() was ignored."
2392
2392
  );
2393
2393
  return;
2394
2394
  }
2395
- this.config.supportChat.enabled = true;
2396
- this.injectSupportChat();
2397
- this.pushSupportChatIdentity();
2395
+ this.config.support.enabled = true;
2396
+ this.injectSupport();
2397
+ this.pushSupportIdentity();
2398
2398
  }
2399
2399
  /**
2400
2400
  * Enables and injects the social-proof widget (e.g. after constructing with
@@ -2573,13 +2573,13 @@ var Saasco = class {
2573
2573
  reset: userIdChangedToNull
2574
2574
  });
2575
2575
  setUserId(distinctId);
2576
- this.updateSupportChatIdentity({
2576
+ this.updateSupportIdentity({
2577
2577
  distinctId: hasId && distinctId !== null ? distinctId : void 0,
2578
2578
  email: typeof properties?.["email"] === "string" ? properties["email"] : void 0,
2579
2579
  // Forward the full scalar payload (browser/track context + identify traits
2580
2580
  // + session envelope) so the widget can bind them via live context without
2581
2581
  // the host mirroring traits into `setStateSnapshot`.
2582
- traits: buildSupportChatTraits(properties, { anonymousId, sessionId })
2582
+ traits: buildSupportTraits(properties, { anonymousId, sessionId })
2583
2583
  });
2584
2584
  this.integrationManager.setContext({
2585
2585
  distinctId,
@@ -2751,39 +2751,39 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
2751
2751
  return this.integrationManager.getStats();
2752
2752
  }
2753
2753
  /**
2754
- * Lazily injects the support-chat **loader** from the same `/sdk/` origin as
2754
+ * Lazily injects the support **loader** from the same `/sdk/` origin as
2755
2755
  * the analytics bundle, forwarding the shared `projectId` and the widget
2756
2756
  * config as `data-*` attributes. The loader (no React) injects the
2757
2757
  * cross-origin embed iframe. Deferred (`async`) and guarded against
2758
2758
  * double-injection so re-running `init()` is a no-op.
2759
2759
  */
2760
- injectSupportChat() {
2760
+ injectSupport() {
2761
2761
  if (!isBrowser5 || typeof document === "undefined") {
2762
2762
  return;
2763
2763
  }
2764
- const chat = this.config.supportChat;
2764
+ const chat = this.config.support;
2765
2765
  if (!chat) {
2766
2766
  return;
2767
2767
  }
2768
- if (window.__saascoSupportChatInjected || document.querySelector('script[src*="saasco-support-chat-loader.js"]')) {
2768
+ if (window.__saascoSupportInjected || document.querySelector('script[src*="saasco-support-loader.js"]')) {
2769
2769
  return;
2770
2770
  }
2771
2771
  const scriptUrl = resolveLoaderScriptUrl(
2772
- "saasco-support-chat-loader.js",
2772
+ "saasco-support-loader.js",
2773
2773
  chat.scriptUrl
2774
2774
  );
2775
2775
  if (!scriptUrl) {
2776
2776
  this.logger.warn(
2777
- "Support chat is enabled but the loader URL could not be resolved. Pass `supportChat.scriptUrl` pointing at your hosted saasco-support-chat-loader.js (or load the analytics SDK from the CDN)."
2777
+ "Support is enabled but the loader URL could not be resolved. Pass `support.scriptUrl` pointing at your hosted saasco-support-loader.js (or load the analytics SDK from the CDN)."
2778
2778
  );
2779
2779
  return;
2780
2780
  }
2781
- window.__saascoSupportChatInjected = true;
2781
+ window.__saascoSupportInjected = true;
2782
2782
  const script = document.createElement("script");
2783
2783
  script.async = true;
2784
2784
  script.src = normalizeSaascoUrl(scriptUrl);
2785
2785
  script.setAttribute("data-projectId", this.config.projectId);
2786
- for (const [key, attr] of Object.entries(SUPPORT_CHAT_ATTR_MAP)) {
2786
+ for (const [key, attr] of Object.entries(SUPPORT_ATTR_MAP)) {
2787
2787
  const value = chat[key];
2788
2788
  if (value !== void 0) {
2789
2789
  script.setAttribute(
@@ -2793,7 +2793,7 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
2793
2793
  }
2794
2794
  }
2795
2795
  script.addEventListener("load", () => {
2796
- this.pushSupportChatIdentity();
2796
+ this.pushSupportIdentity();
2797
2797
  });
2798
2798
  (document.body ?? document.head ?? document.documentElement).append(script);
2799
2799
  }
@@ -2817,42 +2817,42 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
2817
2817
  });
2818
2818
  }
2819
2819
  /**
2820
- * Records the latest CRM identity and forwards it to the support-chat widget.
2821
- * No-op when support chat isn't enabled.
2820
+ * Records the latest CRM identity and forwards it to the support widget.
2821
+ * No-op when support isn't enabled.
2822
2822
  */
2823
- updateSupportChatIdentity(identity) {
2824
- if (!isBrowser5 || !this.config.supportChat) {
2823
+ updateSupportIdentity(identity) {
2824
+ if (!isBrowser5 || !this.config.support) {
2825
2825
  return;
2826
2826
  }
2827
2827
  const hasTraits = identity.traits && Object.keys(identity.traits).length > 0;
2828
- this.lastSupportChatIdentity = identity.distinctId || identity.email || hasTraits ? identity : null;
2829
- if (this.config.supportChat.enabled === false) {
2828
+ this.lastSupportIdentity = identity.distinctId || identity.email || hasTraits ? identity : null;
2829
+ if (this.config.support.enabled === false) {
2830
2830
  return;
2831
2831
  }
2832
- this.pushSupportChatIdentity();
2832
+ this.pushSupportIdentity();
2833
2833
  }
2834
2834
  /**
2835
- * Pushes the current identity onto `window.SaascoSupportChat.identify`. The
2835
+ * Pushes the current identity onto `window.SaascoSupport.identify`. The
2836
2836
  * widget bundle publishes that global asynchronously, so this short-polls for
2837
2837
  * it (same approach as tool registration); the load handler also calls this,
2838
2838
  * so a fresh page load with a stored distinctId still identifies the chat.
2839
2839
  */
2840
- pushSupportChatIdentity() {
2841
- if (!isBrowser5 || !this.config.supportChat || this.config.supportChat.enabled === false) {
2840
+ pushSupportIdentity() {
2841
+ if (!isBrowser5 || !this.config.support || this.config.support.enabled === false) {
2842
2842
  return;
2843
2843
  }
2844
- const identity = this.lastSupportChatIdentity ?? {
2844
+ const identity = this.lastSupportIdentity ?? {
2845
2845
  distinctId: getUserId() ?? void 0,
2846
2846
  // Anonymous (pre-identify) page load: still forward browser/track context
2847
2847
  // and the session envelope so live context has them from the first turn.
2848
- traits: buildSupportChatTraits(void 0, {
2848
+ traits: buildSupportTraits(void 0, {
2849
2849
  anonymousId: getAnonymousId() ?? void 0,
2850
2850
  sessionId: getSessionId() ?? void 0
2851
2851
  })
2852
2852
  };
2853
2853
  let attempts = 0;
2854
2854
  const tryPush = () => {
2855
- const api = getSupportChatGlobal();
2855
+ const api = getSupportGlobal();
2856
2856
  if (!api) {
2857
2857
  attempts += 1;
2858
2858
  if (attempts > 40) {
@@ -2865,7 +2865,7 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
2865
2865
  api.identify(identity);
2866
2866
  } catch (error) {
2867
2867
  this.logger.warn(
2868
- "Failed to forward identity to the support chat widget:",
2868
+ "Failed to forward identity to the support widget:",
2869
2869
  error
2870
2870
  );
2871
2871
  }
@@ -2964,9 +2964,9 @@ function getLoggerLevel(config) {
2964
2964
  return effectiveDebugVerbose ? 3 /* DEBUG */ : effectiveDebug ? 2 /* INFO */ : 0 /* ERROR */;
2965
2965
  }
2966
2966
 
2967
- // src/lib/tracking/types.ts
2967
+ // ../shared/src/lib/types/browserContext.ts
2968
2968
  import { z } from "zod";
2969
- var browserContextSchema = z.object({
2969
+ var BrowserContextSchema = z.object({
2970
2970
  $href: z.string(),
2971
2971
  $locale: z.string(),
2972
2972
  $location: z.string(),
@@ -2992,9 +2992,9 @@ var browserContextSchema = z.object({
2992
2992
  $utmTerm: z.string().nullable()
2993
2993
  });
2994
2994
  export {
2995
+ BrowserContextSchema,
2995
2996
  IntegrationManager,
2996
2997
  Saasco,
2997
- browserContextSchema,
2998
2998
  createFacebookPixelIntegration,
2999
2999
  createPinterestTagIntegration,
3000
3000
  createTikTokPixelIntegration,