@ada-support/embed2 1.12.2 → 1.12.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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StartOptions } from "@ada-support/embed-types";
|
|
2
|
+
export type HostTelemetrySurface = "mobile" | "browser";
|
|
3
|
+
export type HostTelemetryPlatform = "ios" | "android" | "react_native" | "web" | "unknown";
|
|
4
|
+
export type HostTelemetryWebSdkOrigin = "legacy" | "messaging";
|
|
5
|
+
export interface HostTelemetryContext {
|
|
6
|
+
surface: HostTelemetrySurface;
|
|
7
|
+
hostPlatform: HostTelemetryPlatform;
|
|
8
|
+
webSdkOrigin: HostTelemetryWebSdkOrigin;
|
|
9
|
+
mobilePackage?: string;
|
|
10
|
+
sdkVariant?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const HOST_TELEMETRY_QUERY_PARAM = "ada_host_telemetry";
|
|
13
|
+
type StartOptionsWithHostTelemetry = StartOptions & {
|
|
14
|
+
hostTelemetry?: unknown;
|
|
15
|
+
};
|
|
16
|
+
export declare function resolveHostTelemetryFromStartOptions(adaSettings: StartOptionsWithHostTelemetry, options?: {
|
|
17
|
+
pathname?: string;
|
|
18
|
+
}): HostTelemetryContext;
|
|
19
|
+
export declare function serializeHostTelemetry(hostTelemetry: HostTelemetryContext): string;
|
|
20
|
+
export declare function shouldPropagateHostTelemetry(hostTelemetry: HostTelemetryContext): boolean;
|
|
21
|
+
export declare function toMonitoringContext(hostTelemetry: HostTelemetryContext): Record<string, string>;
|
|
22
|
+
export {};
|
package/dist/npm-entry/index.js
CHANGED
|
@@ -15919,7 +15919,7 @@ const client = new BrowserClient({
|
|
|
15919
15919
|
return event;
|
|
15920
15920
|
},
|
|
15921
15921
|
environment: "production",
|
|
15922
|
-
release: "1.12.
|
|
15922
|
+
release: "1.12.4-1c18649",
|
|
15923
15923
|
sampleRate: 0.25,
|
|
15924
15924
|
autoSessionTracking: false,
|
|
15925
15925
|
// Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
|
|
@@ -16502,7 +16502,7 @@ function getEmbedURL(_ref) {
|
|
|
16502
16502
|
} else {
|
|
16503
16503
|
host = `http://${handle}.localhost:9001`;
|
|
16504
16504
|
}
|
|
16505
|
-
return `${host}/embed/${frameName}/${"
|
|
16505
|
+
return `${host}/embed/${frameName}/${"1c18649"}/index.html`;
|
|
16506
16506
|
}
|
|
16507
16507
|
function constructQueryString(query) {
|
|
16508
16508
|
return Object.keys(query).map(key => {
|
|
@@ -17656,6 +17656,13 @@ function logger_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { v
|
|
|
17656
17656
|
const DEFAULT_LOG_SAMPLE_RATE = 0.01;
|
|
17657
17657
|
const DD_BASE_URL = "https://browser-http-intake.logs.datadoghq.com/v1/input/";
|
|
17658
17658
|
const DD_TOKEN = "pubfe23baedd2ea322bebb5ed2020fa2fa1";
|
|
17659
|
+
let globalLogContext = {};
|
|
17660
|
+
function setGlobalLogContext(context) {
|
|
17661
|
+
globalLogContext = logger_objectSpread({}, context);
|
|
17662
|
+
}
|
|
17663
|
+
function clearGlobalLogContext() {
|
|
17664
|
+
globalLogContext = {};
|
|
17665
|
+
}
|
|
17659
17666
|
|
|
17660
17667
|
// We need memoization to ensure consistency of logs
|
|
17661
17668
|
const shouldLog = lodash_memoize_default()(sampleRate => {
|
|
@@ -17675,17 +17682,17 @@ async function log(message, extra, options) {
|
|
|
17675
17682
|
await httpRequest({
|
|
17676
17683
|
url: `${DD_BASE_URL}${DD_TOKEN}?ddsource=browser&ddtags=version:1.5.0,env:${"production"}`,
|
|
17677
17684
|
method: "POST",
|
|
17678
|
-
body: JSON.stringify(logger_objectSpread(logger_objectSpread({
|
|
17685
|
+
body: JSON.stringify(logger_objectSpread(logger_objectSpread(logger_objectSpread({
|
|
17679
17686
|
message
|
|
17680
|
-
}, extra), {}, {
|
|
17687
|
+
}, extra), globalLogContext), {}, {
|
|
17681
17688
|
level: (options === null || options === void 0 ? void 0 : options.level) || "info",
|
|
17682
17689
|
sampleRate: (options === null || options === void 0 ? void 0 : options.sampleRate) || DEFAULT_LOG_SAMPLE_RATE,
|
|
17683
17690
|
service: "embed",
|
|
17684
17691
|
env: "production",
|
|
17685
17692
|
embedVersion: 2,
|
|
17686
|
-
version: "1.12.
|
|
17693
|
+
version: "1.12.4",
|
|
17687
17694
|
isNpm: true,
|
|
17688
|
-
commitHash: "
|
|
17695
|
+
commitHash: "1c18649"
|
|
17689
17696
|
}))
|
|
17690
17697
|
});
|
|
17691
17698
|
}
|
|
@@ -19072,6 +19079,134 @@ class LightboxOverlay extends preact_module_d {
|
|
|
19072
19079
|
const ANIMATION_DELAY = 50;
|
|
19073
19080
|
const CHAT_FRAME_TIMEOUT_EVENT_MS = 5000;
|
|
19074
19081
|
const CHAT_FALLBACK_DELAY_MS = 10000;
|
|
19082
|
+
;// CONCATENATED MODULE: ./src/common/helpers/host-telemetry.ts
|
|
19083
|
+
|
|
19084
|
+
function host_telemetry_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19085
|
+
function host_telemetry_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? host_telemetry_ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : host_telemetry_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19086
|
+
const HOST_TELEMETRY_QUERY_PARAM = "ada_host_telemetry";
|
|
19087
|
+
const TRUSTED_MOBILE_SDK_PATH = "/mobile-sdk-webview/";
|
|
19088
|
+
const MAX_TELEMETRY_TAG_LENGTH = 100;
|
|
19089
|
+
const TELEMETRY_TAG_VALUE_PATTERN = /^[a-z0-9_-]+$/;
|
|
19090
|
+
|
|
19091
|
+
// Private mobile-sdk handshake used only on the trusted /mobile-sdk-webview/ page.
|
|
19092
|
+
|
|
19093
|
+
// Keep this normalization logic in sync with
|
|
19094
|
+
// chat/src/shared/services/host-telemetry.ts. Both sides normalize across the
|
|
19095
|
+
// embed/chat iframe boundary on purpose.
|
|
19096
|
+
function asRecord(value) {
|
|
19097
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
19098
|
+
}
|
|
19099
|
+
function normalizeSurface(value) {
|
|
19100
|
+
if (value === "mobile" || value === "browser") {
|
|
19101
|
+
return value;
|
|
19102
|
+
}
|
|
19103
|
+
return undefined;
|
|
19104
|
+
}
|
|
19105
|
+
function normalizeHostPlatform(value) {
|
|
19106
|
+
if (typeof value !== "string") {
|
|
19107
|
+
return undefined;
|
|
19108
|
+
}
|
|
19109
|
+
switch (value.trim().toLowerCase()) {
|
|
19110
|
+
case "ios":
|
|
19111
|
+
return "ios";
|
|
19112
|
+
case "android":
|
|
19113
|
+
return "android";
|
|
19114
|
+
case "react_native":
|
|
19115
|
+
case "reactnative":
|
|
19116
|
+
return "react_native";
|
|
19117
|
+
case "web":
|
|
19118
|
+
return "web";
|
|
19119
|
+
case "unknown":
|
|
19120
|
+
return "unknown";
|
|
19121
|
+
default:
|
|
19122
|
+
return undefined;
|
|
19123
|
+
}
|
|
19124
|
+
}
|
|
19125
|
+
function normalizeOrigin(value) {
|
|
19126
|
+
if (value === "legacy" || value === "messaging") {
|
|
19127
|
+
return value;
|
|
19128
|
+
}
|
|
19129
|
+
return undefined;
|
|
19130
|
+
}
|
|
19131
|
+
function normalizeTelemetryTagValue(value) {
|
|
19132
|
+
if (typeof value !== "string") {
|
|
19133
|
+
return undefined;
|
|
19134
|
+
}
|
|
19135
|
+
const normalizedValue = value.trim().toLowerCase();
|
|
19136
|
+
if (!normalizedValue || normalizedValue.length > MAX_TELEMETRY_TAG_LENGTH || !TELEMETRY_TAG_VALUE_PATTERN.test(normalizedValue)) {
|
|
19137
|
+
return undefined;
|
|
19138
|
+
}
|
|
19139
|
+
return normalizedValue;
|
|
19140
|
+
}
|
|
19141
|
+
function deriveSdkVariant(mobilePackage, webSdkOrigin) {
|
|
19142
|
+
if (!mobilePackage || !webSdkOrigin) {
|
|
19143
|
+
return undefined;
|
|
19144
|
+
}
|
|
19145
|
+
return `${mobilePackage}-${webSdkOrigin}`;
|
|
19146
|
+
}
|
|
19147
|
+
function normalizeHostTelemetry(value) {
|
|
19148
|
+
const record = asRecord(value);
|
|
19149
|
+
if (!record) {
|
|
19150
|
+
return undefined;
|
|
19151
|
+
}
|
|
19152
|
+
const surface = normalizeSurface(record.surface);
|
|
19153
|
+
const hostPlatform = normalizeHostPlatform(record.hostPlatform);
|
|
19154
|
+
const webSdkOrigin = normalizeOrigin(record.webSdkOrigin);
|
|
19155
|
+
const mobilePackage = normalizeTelemetryTagValue(record.mobilePackage);
|
|
19156
|
+
if (!surface || !hostPlatform || !webSdkOrigin) {
|
|
19157
|
+
return undefined;
|
|
19158
|
+
}
|
|
19159
|
+
const sdkVariant = normalizeTelemetryTagValue(record.sdkVariant) ?? deriveSdkVariant(mobilePackage, webSdkOrigin);
|
|
19160
|
+
return host_telemetry_objectSpread(host_telemetry_objectSpread({
|
|
19161
|
+
surface,
|
|
19162
|
+
hostPlatform,
|
|
19163
|
+
webSdkOrigin
|
|
19164
|
+
}, mobilePackage ? {
|
|
19165
|
+
mobilePackage
|
|
19166
|
+
} : {}), sdkVariant ? {
|
|
19167
|
+
sdkVariant
|
|
19168
|
+
} : {});
|
|
19169
|
+
}
|
|
19170
|
+
function isTrustedMobileSdkHostPage() {
|
|
19171
|
+
let pathname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.pathname;
|
|
19172
|
+
return pathname === TRUSTED_MOBILE_SDK_PATH || pathname === TRUSTED_MOBILE_SDK_PATH.slice(0, -1);
|
|
19173
|
+
}
|
|
19174
|
+
function resolveHostTelemetryFromStartOptions(adaSettings) {
|
|
19175
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19176
|
+
const trustedMobileSdkHostPage = isTrustedMobileSdkHostPage(options.pathname);
|
|
19177
|
+
const explicit = trustedMobileSdkHostPage ? normalizeHostTelemetry(adaSettings.hostTelemetry) : undefined;
|
|
19178
|
+
const webSdkOrigin = (explicit === null || explicit === void 0 ? void 0 : explicit.webSdkOrigin) ?? "legacy";
|
|
19179
|
+
const hostPlatform = (explicit === null || explicit === void 0 ? void 0 : explicit.hostPlatform) ?? (trustedMobileSdkHostPage ? "unknown" : "web");
|
|
19180
|
+
const surface = (explicit === null || explicit === void 0 ? void 0 : explicit.surface) ?? (trustedMobileSdkHostPage ? "mobile" : "browser");
|
|
19181
|
+
const mobilePackage = explicit === null || explicit === void 0 ? void 0 : explicit.mobilePackage;
|
|
19182
|
+
const sdkVariant = explicit === null || explicit === void 0 ? void 0 : explicit.sdkVariant;
|
|
19183
|
+
return host_telemetry_objectSpread(host_telemetry_objectSpread({
|
|
19184
|
+
surface,
|
|
19185
|
+
hostPlatform,
|
|
19186
|
+
webSdkOrigin
|
|
19187
|
+
}, mobilePackage ? {
|
|
19188
|
+
mobilePackage
|
|
19189
|
+
} : {}), sdkVariant ? {
|
|
19190
|
+
sdkVariant
|
|
19191
|
+
} : {});
|
|
19192
|
+
}
|
|
19193
|
+
function serializeHostTelemetry(hostTelemetry) {
|
|
19194
|
+
return JSON.stringify(hostTelemetry);
|
|
19195
|
+
}
|
|
19196
|
+
function shouldPropagateHostTelemetry(hostTelemetry) {
|
|
19197
|
+
return hostTelemetry.surface !== "browser" || hostTelemetry.hostPlatform !== "web" || hostTelemetry.webSdkOrigin !== "legacy" || Boolean(hostTelemetry.mobilePackage) || Boolean(hostTelemetry.sdkVariant);
|
|
19198
|
+
}
|
|
19199
|
+
function toMonitoringContext(hostTelemetry) {
|
|
19200
|
+
return host_telemetry_objectSpread(host_telemetry_objectSpread({
|
|
19201
|
+
surface: hostTelemetry.surface,
|
|
19202
|
+
host_platform: hostTelemetry.hostPlatform,
|
|
19203
|
+
web_sdk_origin: hostTelemetry.webSdkOrigin
|
|
19204
|
+
}, hostTelemetry.mobilePackage ? {
|
|
19205
|
+
mobile_package: hostTelemetry.mobilePackage
|
|
19206
|
+
} : {}), hostTelemetry.sdkVariant ? {
|
|
19207
|
+
sdk_variant: hostTelemetry.sdkVariant
|
|
19208
|
+
} : {});
|
|
19209
|
+
}
|
|
19075
19210
|
;// CONCATENATED MODULE: ./src/common/helpers/is-mobile.ts
|
|
19076
19211
|
const isMobile = /(iPhone)|(iPod)|(android)|(webOS)/i.exec(navigator.userAgent) !== null;
|
|
19077
19212
|
;// CONCATENATED MODULE: ./src/client/components/ChatFrame/chatFrameEvents/chatterEvent/index.ts
|
|
@@ -19242,6 +19377,7 @@ function getFallbackDataURI() {
|
|
|
19242
19377
|
|
|
19243
19378
|
|
|
19244
19379
|
|
|
19380
|
+
|
|
19245
19381
|
|
|
19246
19382
|
class ChatFrame extends preact_module_d {
|
|
19247
19383
|
constructor() {
|
|
@@ -19292,7 +19428,7 @@ class ChatFrame extends preact_module_d {
|
|
|
19292
19428
|
log("Chat frame mount", {
|
|
19293
19429
|
handle,
|
|
19294
19430
|
chatUrl: this.url,
|
|
19295
|
-
embedVersion: "
|
|
19431
|
+
embedVersion: "1c18649".slice(0, 7),
|
|
19296
19432
|
embedSettings: adaSettings
|
|
19297
19433
|
});
|
|
19298
19434
|
|
|
@@ -19380,7 +19516,7 @@ class ChatFrame extends preact_module_d {
|
|
|
19380
19516
|
const hostPageUrlParams = new URL(window.location.href).searchParams;
|
|
19381
19517
|
const smsToken = hostPageUrlParams.get("adaSMSToken");
|
|
19382
19518
|
const queryParams = {
|
|
19383
|
-
embedVersion: "
|
|
19519
|
+
embedVersion: "1c18649".slice(0, 7),
|
|
19384
19520
|
greeting,
|
|
19385
19521
|
language,
|
|
19386
19522
|
skipGreeting,
|
|
@@ -19390,6 +19526,10 @@ class ChatFrame extends preact_module_d {
|
|
|
19390
19526
|
test_user: testMode ? 1 : null,
|
|
19391
19527
|
align: getAlignment(adaSettings)
|
|
19392
19528
|
};
|
|
19529
|
+
const hostTelemetry = resolveHostTelemetryFromStartOptions(adaSettings);
|
|
19530
|
+
if (shouldPropagateHostTelemetry(hostTelemetry)) {
|
|
19531
|
+
queryParams[HOST_TELEMETRY_QUERY_PARAM] = serializeHostTelemetry(hostTelemetry);
|
|
19532
|
+
}
|
|
19393
19533
|
if (smsToken) {
|
|
19394
19534
|
queryParams.adaSMSToken = smsToken;
|
|
19395
19535
|
}
|
|
@@ -21688,6 +21828,7 @@ function createEmbed(adaSettings) {
|
|
|
21688
21828
|
|
|
21689
21829
|
|
|
21690
21830
|
|
|
21831
|
+
|
|
21691
21832
|
const EMBED_NOT_INITIALIZED_ERROR = new AdaEmbedError("Actions cannot be called until Embed has been instantiated. Try running `adaEmbed.start({...})`.");
|
|
21692
21833
|
|
|
21693
21834
|
/**
|
|
@@ -21713,17 +21854,24 @@ function createEmbedInterface() {
|
|
|
21713
21854
|
if (embed) {
|
|
21714
21855
|
throw new AdaEmbedError("Ada Embed has already been started.");
|
|
21715
21856
|
}
|
|
21716
|
-
|
|
21717
|
-
|
|
21718
|
-
|
|
21857
|
+
setGlobalLogContext(toMonitoringContext(resolveHostTelemetryFromStartOptions(adaSettings)));
|
|
21858
|
+
try {
|
|
21859
|
+
embed = createEmbed(adaSettings);
|
|
21860
|
+
if (window.adaEmbedLoadedCallback) {
|
|
21861
|
+
window.adaEmbedLoadedCallback();
|
|
21862
|
+
}
|
|
21863
|
+
log("Embed start", {
|
|
21864
|
+
handle: adaSettings.handle,
|
|
21865
|
+
embedSettings: adaSettings,
|
|
21866
|
+
hostPage: window.location.href,
|
|
21867
|
+
adaScriptURL: (scriptElement => scriptElement ? scriptElement.src : null)(document.getElementById("__ada"))
|
|
21868
|
+
});
|
|
21869
|
+
await embed.initialized;
|
|
21870
|
+
} catch (error) {
|
|
21871
|
+
embed = null;
|
|
21872
|
+
clearGlobalLogContext();
|
|
21873
|
+
throw error;
|
|
21719
21874
|
}
|
|
21720
|
-
log("Embed start", {
|
|
21721
|
-
handle: adaSettings.handle,
|
|
21722
|
-
embedSettings: adaSettings,
|
|
21723
|
-
hostPage: window.location.href,
|
|
21724
|
-
adaScriptURL: (scriptElement => scriptElement ? scriptElement.src : null)(document.getElementById("__ada"))
|
|
21725
|
-
});
|
|
21726
|
-
return embed.initialized;
|
|
21727
21875
|
},
|
|
21728
21876
|
stop: async () => {
|
|
21729
21877
|
if (!embed) {
|
|
@@ -21731,7 +21879,11 @@ function createEmbedInterface() {
|
|
|
21731
21879
|
}
|
|
21732
21880
|
const stopPromise = embed.stop();
|
|
21733
21881
|
embed = null;
|
|
21734
|
-
|
|
21882
|
+
try {
|
|
21883
|
+
await stopPromise;
|
|
21884
|
+
} finally {
|
|
21885
|
+
clearGlobalLogContext();
|
|
21886
|
+
}
|
|
21735
21887
|
},
|
|
21736
21888
|
toggle,
|
|
21737
21889
|
deleteHistory: async () => {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const DEFAULT_LOG_SAMPLE_RATE = 0.01;
|
|
2
|
+
export declare function setGlobalLogContext(context: Record<string, unknown>): void;
|
|
3
|
+
export declare function clearGlobalLogContext(): void;
|
|
2
4
|
export declare const shouldLog: ((sampleRate?: number) => boolean) & import("lodash").MemoizedFunction;
|
|
3
5
|
/**
|
|
4
6
|
* Sends log to Datadog
|