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.cjs +46 -46
- package/dist/index.d.cts +32 -23
- package/dist/index.d.ts +32 -23
- package/dist/index.js +45 -45
- package/dist/{support-chat.cjs → support.cjs} +2334 -1425
- package/dist/{support-chat.d.cts → support.d.cts} +20 -21
- package/dist/{support-chat.d.ts → support.d.ts} +20 -21
- package/dist/{support-chat.js → support.js} +2308 -1399
- package/package.json +14 -9
package/dist/index.cjs
CHANGED
|
@@ -20,9 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
BrowserContextSchema: () => BrowserContextSchema,
|
|
23
24
|
IntegrationManager: () => IntegrationManager,
|
|
24
25
|
Saasco: () => Saasco,
|
|
25
|
-
browserContextSchema: () => browserContextSchema,
|
|
26
26
|
createFacebookPixelIntegration: () => createFacebookPixelIntegration,
|
|
27
27
|
createPinterestTagIntegration: () => createPinterestTagIntegration,
|
|
28
28
|
createTikTokPixelIntegration: () => createTikTokPixelIntegration,
|
|
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var import_psl = require("psl");
|
|
39
39
|
|
|
40
40
|
// package.json
|
|
41
|
-
var version = "0.2.
|
|
41
|
+
var version = "0.2.4";
|
|
42
42
|
|
|
43
43
|
// src/lib/timezones.ts
|
|
44
44
|
var timezones = {
|
|
@@ -2025,15 +2025,15 @@ function isSocialProofQaMode() {
|
|
|
2025
2025
|
}
|
|
2026
2026
|
|
|
2027
2027
|
// src/lib/analytics.ts
|
|
2028
|
-
function
|
|
2029
|
-
return window.
|
|
2028
|
+
function getSupportGlobal() {
|
|
2029
|
+
return window.SaascoSupport;
|
|
2030
2030
|
}
|
|
2031
2031
|
var isBrowser5 = typeof window !== "undefined";
|
|
2032
2032
|
var isServer5 = !isBrowser5;
|
|
2033
2033
|
var PREF = "saasco-sdk";
|
|
2034
2034
|
var SESSION_DURATION = 1e3 * 60 * 30;
|
|
2035
2035
|
var USER_DURATION = 1e3 * 60 * 60 * 24 * 365;
|
|
2036
|
-
var
|
|
2036
|
+
var SUPPORT_ATTR_MAP = {
|
|
2037
2037
|
baseUrl: "data-base-url",
|
|
2038
2038
|
placeholder: "data-placeholder"
|
|
2039
2039
|
};
|
|
@@ -2204,7 +2204,7 @@ function getUserId() {
|
|
|
2204
2204
|
function setUserId(userId) {
|
|
2205
2205
|
storeData(`user-id`, userId ?? void 0, USER_DURATION);
|
|
2206
2206
|
}
|
|
2207
|
-
function
|
|
2207
|
+
function buildSupportTraits(properties, envelope) {
|
|
2208
2208
|
const traits = {};
|
|
2209
2209
|
const add = (key, value) => {
|
|
2210
2210
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
@@ -2374,10 +2374,10 @@ var Saasco = class {
|
|
|
2374
2374
|
integrationManager;
|
|
2375
2375
|
logger;
|
|
2376
2376
|
// Last identity handed to `identify()`, mirrored into the lazily-loaded
|
|
2377
|
-
// support
|
|
2377
|
+
// support widget so chat conversations attach to a CRM contact. Held
|
|
2378
2378
|
// here so an `identify()` that fires before the widget bundle finishes
|
|
2379
2379
|
// loading is replayed once it does.
|
|
2380
|
-
|
|
2380
|
+
lastSupportIdentity = null;
|
|
2381
2381
|
init() {
|
|
2382
2382
|
if (this.isInitialized) {
|
|
2383
2383
|
this.logger.info(
|
|
@@ -2401,8 +2401,8 @@ var Saasco = class {
|
|
|
2401
2401
|
);
|
|
2402
2402
|
}
|
|
2403
2403
|
this.initAutoPageTracking();
|
|
2404
|
-
if (this.config.
|
|
2405
|
-
this.
|
|
2404
|
+
if (this.config.support && this.config.support.enabled !== false) {
|
|
2405
|
+
this.injectSupport();
|
|
2406
2406
|
}
|
|
2407
2407
|
if (this.config.socialProof?.enabled !== false) {
|
|
2408
2408
|
void this.injectSocialProof();
|
|
@@ -2418,19 +2418,19 @@ var Saasco = class {
|
|
|
2418
2418
|
this.logger.info("Debug mode activated.");
|
|
2419
2419
|
}
|
|
2420
2420
|
/**
|
|
2421
|
-
* Enables and injects the support
|
|
2422
|
-
* `
|
|
2421
|
+
* Enables and injects the support widget when it was constructed with
|
|
2422
|
+
* `support: { enabled: false }`. Safe to call multiple times.
|
|
2423
2423
|
*/
|
|
2424
|
-
|
|
2425
|
-
if (!this.config.
|
|
2424
|
+
enableSupport() {
|
|
2425
|
+
if (!this.config.support) {
|
|
2426
2426
|
this.logger.warn(
|
|
2427
|
-
"Support
|
|
2427
|
+
"Support is not configured; enableSupport() was ignored."
|
|
2428
2428
|
);
|
|
2429
2429
|
return;
|
|
2430
2430
|
}
|
|
2431
|
-
this.config.
|
|
2432
|
-
this.
|
|
2433
|
-
this.
|
|
2431
|
+
this.config.support.enabled = true;
|
|
2432
|
+
this.injectSupport();
|
|
2433
|
+
this.pushSupportIdentity();
|
|
2434
2434
|
}
|
|
2435
2435
|
/**
|
|
2436
2436
|
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
@@ -2609,13 +2609,13 @@ var Saasco = class {
|
|
|
2609
2609
|
reset: userIdChangedToNull
|
|
2610
2610
|
});
|
|
2611
2611
|
setUserId(distinctId);
|
|
2612
|
-
this.
|
|
2612
|
+
this.updateSupportIdentity({
|
|
2613
2613
|
distinctId: hasId && distinctId !== null ? distinctId : void 0,
|
|
2614
2614
|
email: typeof properties?.["email"] === "string" ? properties["email"] : void 0,
|
|
2615
2615
|
// Forward the full scalar payload (browser/track context + identify traits
|
|
2616
2616
|
// + session envelope) so the widget can bind them via live context without
|
|
2617
2617
|
// the host mirroring traits into `setStateSnapshot`.
|
|
2618
|
-
traits:
|
|
2618
|
+
traits: buildSupportTraits(properties, { anonymousId, sessionId })
|
|
2619
2619
|
});
|
|
2620
2620
|
this.integrationManager.setContext({
|
|
2621
2621
|
distinctId,
|
|
@@ -2787,39 +2787,39 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2787
2787
|
return this.integrationManager.getStats();
|
|
2788
2788
|
}
|
|
2789
2789
|
/**
|
|
2790
|
-
* Lazily injects the support
|
|
2790
|
+
* Lazily injects the support **loader** from the same `/sdk/` origin as
|
|
2791
2791
|
* the analytics bundle, forwarding the shared `projectId` and the widget
|
|
2792
2792
|
* config as `data-*` attributes. The loader (no React) injects the
|
|
2793
2793
|
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
2794
2794
|
* double-injection so re-running `init()` is a no-op.
|
|
2795
2795
|
*/
|
|
2796
|
-
|
|
2796
|
+
injectSupport() {
|
|
2797
2797
|
if (!isBrowser5 || typeof document === "undefined") {
|
|
2798
2798
|
return;
|
|
2799
2799
|
}
|
|
2800
|
-
const chat = this.config.
|
|
2800
|
+
const chat = this.config.support;
|
|
2801
2801
|
if (!chat) {
|
|
2802
2802
|
return;
|
|
2803
2803
|
}
|
|
2804
|
-
if (window.
|
|
2804
|
+
if (window.__saascoSupportInjected || document.querySelector('script[src*="saasco-support-loader.js"]')) {
|
|
2805
2805
|
return;
|
|
2806
2806
|
}
|
|
2807
2807
|
const scriptUrl = resolveLoaderScriptUrl(
|
|
2808
|
-
"saasco-support-
|
|
2808
|
+
"saasco-support-loader.js",
|
|
2809
2809
|
chat.scriptUrl
|
|
2810
2810
|
);
|
|
2811
2811
|
if (!scriptUrl) {
|
|
2812
2812
|
this.logger.warn(
|
|
2813
|
-
"Support
|
|
2813
|
+
"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)."
|
|
2814
2814
|
);
|
|
2815
2815
|
return;
|
|
2816
2816
|
}
|
|
2817
|
-
window.
|
|
2817
|
+
window.__saascoSupportInjected = true;
|
|
2818
2818
|
const script = document.createElement("script");
|
|
2819
2819
|
script.async = true;
|
|
2820
2820
|
script.src = normalizeSaascoUrl(scriptUrl);
|
|
2821
2821
|
script.setAttribute("data-projectId", this.config.projectId);
|
|
2822
|
-
for (const [key, attr] of Object.entries(
|
|
2822
|
+
for (const [key, attr] of Object.entries(SUPPORT_ATTR_MAP)) {
|
|
2823
2823
|
const value = chat[key];
|
|
2824
2824
|
if (value !== void 0) {
|
|
2825
2825
|
script.setAttribute(
|
|
@@ -2829,7 +2829,7 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2829
2829
|
}
|
|
2830
2830
|
}
|
|
2831
2831
|
script.addEventListener("load", () => {
|
|
2832
|
-
this.
|
|
2832
|
+
this.pushSupportIdentity();
|
|
2833
2833
|
});
|
|
2834
2834
|
(document.body ?? document.head ?? document.documentElement).append(script);
|
|
2835
2835
|
}
|
|
@@ -2853,42 +2853,42 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2853
2853
|
});
|
|
2854
2854
|
}
|
|
2855
2855
|
/**
|
|
2856
|
-
* Records the latest CRM identity and forwards it to the support
|
|
2857
|
-
* No-op when support
|
|
2856
|
+
* Records the latest CRM identity and forwards it to the support widget.
|
|
2857
|
+
* No-op when support isn't enabled.
|
|
2858
2858
|
*/
|
|
2859
|
-
|
|
2860
|
-
if (!isBrowser5 || !this.config.
|
|
2859
|
+
updateSupportIdentity(identity) {
|
|
2860
|
+
if (!isBrowser5 || !this.config.support) {
|
|
2861
2861
|
return;
|
|
2862
2862
|
}
|
|
2863
2863
|
const hasTraits = identity.traits && Object.keys(identity.traits).length > 0;
|
|
2864
|
-
this.
|
|
2865
|
-
if (this.config.
|
|
2864
|
+
this.lastSupportIdentity = identity.distinctId || identity.email || hasTraits ? identity : null;
|
|
2865
|
+
if (this.config.support.enabled === false) {
|
|
2866
2866
|
return;
|
|
2867
2867
|
}
|
|
2868
|
-
this.
|
|
2868
|
+
this.pushSupportIdentity();
|
|
2869
2869
|
}
|
|
2870
2870
|
/**
|
|
2871
|
-
* Pushes the current identity onto `window.
|
|
2871
|
+
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
2872
2872
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
2873
2873
|
* it (same approach as tool registration); the load handler also calls this,
|
|
2874
2874
|
* so a fresh page load with a stored distinctId still identifies the chat.
|
|
2875
2875
|
*/
|
|
2876
|
-
|
|
2877
|
-
if (!isBrowser5 || !this.config.
|
|
2876
|
+
pushSupportIdentity() {
|
|
2877
|
+
if (!isBrowser5 || !this.config.support || this.config.support.enabled === false) {
|
|
2878
2878
|
return;
|
|
2879
2879
|
}
|
|
2880
|
-
const identity = this.
|
|
2880
|
+
const identity = this.lastSupportIdentity ?? {
|
|
2881
2881
|
distinctId: getUserId() ?? void 0,
|
|
2882
2882
|
// Anonymous (pre-identify) page load: still forward browser/track context
|
|
2883
2883
|
// and the session envelope so live context has them from the first turn.
|
|
2884
|
-
traits:
|
|
2884
|
+
traits: buildSupportTraits(void 0, {
|
|
2885
2885
|
anonymousId: getAnonymousId() ?? void 0,
|
|
2886
2886
|
sessionId: getSessionId() ?? void 0
|
|
2887
2887
|
})
|
|
2888
2888
|
};
|
|
2889
2889
|
let attempts = 0;
|
|
2890
2890
|
const tryPush = () => {
|
|
2891
|
-
const api =
|
|
2891
|
+
const api = getSupportGlobal();
|
|
2892
2892
|
if (!api) {
|
|
2893
2893
|
attempts += 1;
|
|
2894
2894
|
if (attempts > 40) {
|
|
@@ -2901,7 +2901,7 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2901
2901
|
api.identify(identity);
|
|
2902
2902
|
} catch (error) {
|
|
2903
2903
|
this.logger.warn(
|
|
2904
|
-
"Failed to forward identity to the support
|
|
2904
|
+
"Failed to forward identity to the support widget:",
|
|
2905
2905
|
error
|
|
2906
2906
|
);
|
|
2907
2907
|
}
|
|
@@ -3000,9 +3000,9 @@ function getLoggerLevel(config) {
|
|
|
3000
3000
|
return effectiveDebugVerbose ? 3 /* DEBUG */ : effectiveDebug ? 2 /* INFO */ : 0 /* ERROR */;
|
|
3001
3001
|
}
|
|
3002
3002
|
|
|
3003
|
-
// src/lib/
|
|
3003
|
+
// ../shared/src/lib/types/browserContext.ts
|
|
3004
3004
|
var import_zod = require("zod");
|
|
3005
|
-
var
|
|
3005
|
+
var BrowserContextSchema = import_zod.z.object({
|
|
3006
3006
|
$href: import_zod.z.string(),
|
|
3007
3007
|
$locale: import_zod.z.string(),
|
|
3008
3008
|
$location: import_zod.z.string(),
|
|
@@ -3029,9 +3029,9 @@ var browserContextSchema = import_zod.z.object({
|
|
|
3029
3029
|
});
|
|
3030
3030
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3031
3031
|
0 && (module.exports = {
|
|
3032
|
+
BrowserContextSchema,
|
|
3032
3033
|
IntegrationManager,
|
|
3033
3034
|
Saasco,
|
|
3034
|
-
browserContextSchema,
|
|
3035
3035
|
createFacebookPixelIntegration,
|
|
3036
3036
|
createPinterestTagIntegration,
|
|
3037
3037
|
createTikTokPixelIntegration,
|
package/dist/index.d.cts
CHANGED
|
@@ -259,8 +259,8 @@ declare global {
|
|
|
259
259
|
saascoAutoPageTrackingActive?: boolean;
|
|
260
260
|
saasco: Saasco;
|
|
261
261
|
saascoLastIdentifyKey?: string;
|
|
262
|
-
/** Set once the lazy-loaded support
|
|
263
|
-
|
|
262
|
+
/** Set once the lazy-loaded support script has been injected. */
|
|
263
|
+
__saascoSupportInjected?: boolean;
|
|
264
264
|
/** Set once the lazy-loaded social-proof loader script has been injected. */
|
|
265
265
|
__saascoSocialProofInjected?: boolean;
|
|
266
266
|
}
|
|
@@ -287,25 +287,25 @@ type DoRequestResponse = {
|
|
|
287
287
|
};
|
|
288
288
|
type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
|
|
289
289
|
/**
|
|
290
|
-
* Opt-in config for the support
|
|
290
|
+
* Opt-in config for the support widget, set on the `Saasco` constructor.
|
|
291
291
|
* The widget is a cross-origin iframe loaded by a lean host-page loader
|
|
292
|
-
* (`saasco-support-
|
|
292
|
+
* (`saasco-support-loader.js`); no React ships in this analytics entry,
|
|
293
293
|
* which stays React-free by lazily injecting the loader rather than importing
|
|
294
294
|
* it. Providing this object opts in; pass `enabled: false` to keep it off (e.g.
|
|
295
295
|
* behind your own runtime flag). The projectId is shared from the analytics
|
|
296
296
|
* config — you never declare it twice.
|
|
297
297
|
*/
|
|
298
|
-
type
|
|
299
|
-
/** Defaults to `true` when the `
|
|
298
|
+
type SupportInit = {
|
|
299
|
+
/** Defaults to `true` when the `support` object is provided. */
|
|
300
300
|
enabled?: boolean;
|
|
301
|
-
/** Origin of the saasco app hosting the support
|
|
301
|
+
/** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
|
|
302
302
|
baseUrl?: string;
|
|
303
303
|
/** Input placeholder for the chat composer. */
|
|
304
304
|
placeholder?: string;
|
|
305
305
|
/**
|
|
306
306
|
* URL the loader is loaded from. Accepts either the analytics
|
|
307
307
|
* `saasco-sdk.js` URL (the loader URL is derived from it) or the
|
|
308
|
-
* `saasco-support-
|
|
308
|
+
* `saasco-support-loader.js` URL directly. Defaults to deriving from the
|
|
309
309
|
* loaded analytics `<script>` tag, so CDN installs can omit it.
|
|
310
310
|
*/
|
|
311
311
|
scriptUrl?: string;
|
|
@@ -356,7 +356,7 @@ declare class Saasco {
|
|
|
356
356
|
private isInitialized;
|
|
357
357
|
private integrationManager;
|
|
358
358
|
private logger;
|
|
359
|
-
private
|
|
359
|
+
private lastSupportIdentity;
|
|
360
360
|
/**
|
|
361
361
|
* Creates an instance of the Saasco SDK.
|
|
362
362
|
* @param config Configuration options.
|
|
@@ -381,17 +381,17 @@ declare class Saasco {
|
|
|
381
381
|
debug?: boolean;
|
|
382
382
|
debugVerbose?: boolean;
|
|
383
383
|
integrations?: IntegrationsConfig;
|
|
384
|
-
|
|
384
|
+
support?: SupportInit;
|
|
385
385
|
socialProof?: SocialProofInit;
|
|
386
386
|
});
|
|
387
387
|
init(): void;
|
|
388
388
|
disableDebug(): void;
|
|
389
389
|
enableDebug(): void;
|
|
390
390
|
/**
|
|
391
|
-
* Enables and injects the support
|
|
392
|
-
* `
|
|
391
|
+
* Enables and injects the support widget when it was constructed with
|
|
392
|
+
* `support: { enabled: false }`. Safe to call multiple times.
|
|
393
393
|
*/
|
|
394
|
-
|
|
394
|
+
enableSupport(): void;
|
|
395
395
|
/**
|
|
396
396
|
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
397
397
|
* `socialProof: { enabled: false }`, or when no `socialProof` block was
|
|
@@ -465,33 +465,42 @@ declare class Saasco {
|
|
|
465
465
|
readyCount: number;
|
|
466
466
|
};
|
|
467
467
|
/**
|
|
468
|
-
* Lazily injects the support
|
|
468
|
+
* Lazily injects the support **loader** from the same `/sdk/` origin as
|
|
469
469
|
* the analytics bundle, forwarding the shared `projectId` and the widget
|
|
470
470
|
* config as `data-*` attributes. The loader (no React) injects the
|
|
471
471
|
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
472
472
|
* double-injection so re-running `init()` is a no-op.
|
|
473
473
|
*/
|
|
474
|
-
private
|
|
474
|
+
private injectSupport;
|
|
475
475
|
/**
|
|
476
476
|
* Lazily injects the social-proof loader (server-gated). See
|
|
477
477
|
* {@link injectSocialProofLoader}.
|
|
478
478
|
*/
|
|
479
479
|
private injectSocialProof;
|
|
480
480
|
/**
|
|
481
|
-
* Records the latest CRM identity and forwards it to the support
|
|
482
|
-
* No-op when support
|
|
481
|
+
* Records the latest CRM identity and forwards it to the support widget.
|
|
482
|
+
* No-op when support isn't enabled.
|
|
483
483
|
*/
|
|
484
|
-
private
|
|
484
|
+
private updateSupportIdentity;
|
|
485
485
|
/**
|
|
486
|
-
* Pushes the current identity onto `window.
|
|
486
|
+
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
487
487
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
488
488
|
* it (same approach as tool registration); the load handler also calls this,
|
|
489
489
|
* so a fresh page load with a stored distinctId still identifies the chat.
|
|
490
490
|
*/
|
|
491
|
-
private
|
|
491
|
+
private pushSupportIdentity;
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
-
|
|
494
|
+
/**
|
|
495
|
+
* Browser-collected context attached to track payloads by `getBrowserContext()`.
|
|
496
|
+
*
|
|
497
|
+
* Defined here rather than in `libs/analytics/sdk` because server and worker
|
|
498
|
+
* code validates it too. The SDK re-exports it, so `saasco-sdk`'s public API is
|
|
499
|
+
* unchanged — but a shared module importing the SDK barrel would drag the whole
|
|
500
|
+
* DOM-dependent bundle into every consumer's program, including the Cloudflare
|
|
501
|
+
* Worker, which has no DOM lib.
|
|
502
|
+
*/
|
|
503
|
+
declare const BrowserContextSchema: z.ZodObject<{
|
|
495
504
|
$href: z.ZodString;
|
|
496
505
|
$locale: z.ZodString;
|
|
497
506
|
$location: z.ZodString;
|
|
@@ -516,11 +525,11 @@ declare const browserContextSchema: z.ZodObject<{
|
|
|
516
525
|
$utmSourcePlatform: z.ZodNullable<z.ZodString>;
|
|
517
526
|
$utmTerm: z.ZodNullable<z.ZodString>;
|
|
518
527
|
}, z.core.$strip>;
|
|
519
|
-
type BrowserContext = z.infer<typeof
|
|
528
|
+
type BrowserContext = z.infer<typeof BrowserContextSchema>;
|
|
520
529
|
type SuperContext = Record<string, unknown>;
|
|
521
530
|
|
|
522
531
|
declare function getBrowserContext(): BrowserContext;
|
|
523
532
|
|
|
524
533
|
declare const timezones: Record<string, string>;
|
|
525
534
|
|
|
526
|
-
export { type AnalyticsContext, type BrowserContext, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type
|
|
535
|
+
export { type AnalyticsContext, type BrowserContext, BrowserContextSchema, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };
|
package/dist/index.d.ts
CHANGED
|
@@ -259,8 +259,8 @@ declare global {
|
|
|
259
259
|
saascoAutoPageTrackingActive?: boolean;
|
|
260
260
|
saasco: Saasco;
|
|
261
261
|
saascoLastIdentifyKey?: string;
|
|
262
|
-
/** Set once the lazy-loaded support
|
|
263
|
-
|
|
262
|
+
/** Set once the lazy-loaded support script has been injected. */
|
|
263
|
+
__saascoSupportInjected?: boolean;
|
|
264
264
|
/** Set once the lazy-loaded social-proof loader script has been injected. */
|
|
265
265
|
__saascoSocialProofInjected?: boolean;
|
|
266
266
|
}
|
|
@@ -287,25 +287,25 @@ type DoRequestResponse = {
|
|
|
287
287
|
};
|
|
288
288
|
type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
|
|
289
289
|
/**
|
|
290
|
-
* Opt-in config for the support
|
|
290
|
+
* Opt-in config for the support widget, set on the `Saasco` constructor.
|
|
291
291
|
* The widget is a cross-origin iframe loaded by a lean host-page loader
|
|
292
|
-
* (`saasco-support-
|
|
292
|
+
* (`saasco-support-loader.js`); no React ships in this analytics entry,
|
|
293
293
|
* which stays React-free by lazily injecting the loader rather than importing
|
|
294
294
|
* it. Providing this object opts in; pass `enabled: false` to keep it off (e.g.
|
|
295
295
|
* behind your own runtime flag). The projectId is shared from the analytics
|
|
296
296
|
* config — you never declare it twice.
|
|
297
297
|
*/
|
|
298
|
-
type
|
|
299
|
-
/** Defaults to `true` when the `
|
|
298
|
+
type SupportInit = {
|
|
299
|
+
/** Defaults to `true` when the `support` object is provided. */
|
|
300
300
|
enabled?: boolean;
|
|
301
|
-
/** Origin of the saasco app hosting the support
|
|
301
|
+
/** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
|
|
302
302
|
baseUrl?: string;
|
|
303
303
|
/** Input placeholder for the chat composer. */
|
|
304
304
|
placeholder?: string;
|
|
305
305
|
/**
|
|
306
306
|
* URL the loader is loaded from. Accepts either the analytics
|
|
307
307
|
* `saasco-sdk.js` URL (the loader URL is derived from it) or the
|
|
308
|
-
* `saasco-support-
|
|
308
|
+
* `saasco-support-loader.js` URL directly. Defaults to deriving from the
|
|
309
309
|
* loaded analytics `<script>` tag, so CDN installs can omit it.
|
|
310
310
|
*/
|
|
311
311
|
scriptUrl?: string;
|
|
@@ -356,7 +356,7 @@ declare class Saasco {
|
|
|
356
356
|
private isInitialized;
|
|
357
357
|
private integrationManager;
|
|
358
358
|
private logger;
|
|
359
|
-
private
|
|
359
|
+
private lastSupportIdentity;
|
|
360
360
|
/**
|
|
361
361
|
* Creates an instance of the Saasco SDK.
|
|
362
362
|
* @param config Configuration options.
|
|
@@ -381,17 +381,17 @@ declare class Saasco {
|
|
|
381
381
|
debug?: boolean;
|
|
382
382
|
debugVerbose?: boolean;
|
|
383
383
|
integrations?: IntegrationsConfig;
|
|
384
|
-
|
|
384
|
+
support?: SupportInit;
|
|
385
385
|
socialProof?: SocialProofInit;
|
|
386
386
|
});
|
|
387
387
|
init(): void;
|
|
388
388
|
disableDebug(): void;
|
|
389
389
|
enableDebug(): void;
|
|
390
390
|
/**
|
|
391
|
-
* Enables and injects the support
|
|
392
|
-
* `
|
|
391
|
+
* Enables and injects the support widget when it was constructed with
|
|
392
|
+
* `support: { enabled: false }`. Safe to call multiple times.
|
|
393
393
|
*/
|
|
394
|
-
|
|
394
|
+
enableSupport(): void;
|
|
395
395
|
/**
|
|
396
396
|
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
397
397
|
* `socialProof: { enabled: false }`, or when no `socialProof` block was
|
|
@@ -465,33 +465,42 @@ declare class Saasco {
|
|
|
465
465
|
readyCount: number;
|
|
466
466
|
};
|
|
467
467
|
/**
|
|
468
|
-
* Lazily injects the support
|
|
468
|
+
* Lazily injects the support **loader** from the same `/sdk/` origin as
|
|
469
469
|
* the analytics bundle, forwarding the shared `projectId` and the widget
|
|
470
470
|
* config as `data-*` attributes. The loader (no React) injects the
|
|
471
471
|
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
472
472
|
* double-injection so re-running `init()` is a no-op.
|
|
473
473
|
*/
|
|
474
|
-
private
|
|
474
|
+
private injectSupport;
|
|
475
475
|
/**
|
|
476
476
|
* Lazily injects the social-proof loader (server-gated). See
|
|
477
477
|
* {@link injectSocialProofLoader}.
|
|
478
478
|
*/
|
|
479
479
|
private injectSocialProof;
|
|
480
480
|
/**
|
|
481
|
-
* Records the latest CRM identity and forwards it to the support
|
|
482
|
-
* No-op when support
|
|
481
|
+
* Records the latest CRM identity and forwards it to the support widget.
|
|
482
|
+
* No-op when support isn't enabled.
|
|
483
483
|
*/
|
|
484
|
-
private
|
|
484
|
+
private updateSupportIdentity;
|
|
485
485
|
/**
|
|
486
|
-
* Pushes the current identity onto `window.
|
|
486
|
+
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
487
487
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
488
488
|
* it (same approach as tool registration); the load handler also calls this,
|
|
489
489
|
* so a fresh page load with a stored distinctId still identifies the chat.
|
|
490
490
|
*/
|
|
491
|
-
private
|
|
491
|
+
private pushSupportIdentity;
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
-
|
|
494
|
+
/**
|
|
495
|
+
* Browser-collected context attached to track payloads by `getBrowserContext()`.
|
|
496
|
+
*
|
|
497
|
+
* Defined here rather than in `libs/analytics/sdk` because server and worker
|
|
498
|
+
* code validates it too. The SDK re-exports it, so `saasco-sdk`'s public API is
|
|
499
|
+
* unchanged — but a shared module importing the SDK barrel would drag the whole
|
|
500
|
+
* DOM-dependent bundle into every consumer's program, including the Cloudflare
|
|
501
|
+
* Worker, which has no DOM lib.
|
|
502
|
+
*/
|
|
503
|
+
declare const BrowserContextSchema: z.ZodObject<{
|
|
495
504
|
$href: z.ZodString;
|
|
496
505
|
$locale: z.ZodString;
|
|
497
506
|
$location: z.ZodString;
|
|
@@ -516,11 +525,11 @@ declare const browserContextSchema: z.ZodObject<{
|
|
|
516
525
|
$utmSourcePlatform: z.ZodNullable<z.ZodString>;
|
|
517
526
|
$utmTerm: z.ZodNullable<z.ZodString>;
|
|
518
527
|
}, z.core.$strip>;
|
|
519
|
-
type BrowserContext = z.infer<typeof
|
|
528
|
+
type BrowserContext = z.infer<typeof BrowserContextSchema>;
|
|
520
529
|
type SuperContext = Record<string, unknown>;
|
|
521
530
|
|
|
522
531
|
declare function getBrowserContext(): BrowserContext;
|
|
523
532
|
|
|
524
533
|
declare const timezones: Record<string, string>;
|
|
525
534
|
|
|
526
|
-
export { type AnalyticsContext, type BrowserContext, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type
|
|
535
|
+
export { type AnalyticsContext, type BrowserContext, BrowserContextSchema, type EventEnvelope, type EventType, type FacebookEventMapping, type FacebookPixelConfig, type FacebookPixelIntegrationConfig, type Integration, type IntegrationConfigBase, type IntegrationEnvironment, IntegrationManager, type IntegrationState, type IntegrationStatus, type IntegrationsConfig, type ManagerConfig, type PinterestEventMapping, type PinterestTagConfig, type PinterestTagIntegrationConfig, Saasco, type SocialProofInit, type StandardFacebookEvent, type StandardPinterestEvent, type StandardTikTokEvent, type SuperContext, type SupportInit, type TikTokEventMapping, type TikTokPixelConfig, type TikTokPixelIntegrationConfig, createFacebookPixelIntegration, createPinterestTagIntegration, createTikTokPixelIntegration, getBrowserContext, standardFacebookEvents, standardPinterestEvents, standardTikTokEvents, timezones };
|