@salesforce/platform-sdk 13.0.0 → 13.1.0
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/README.md +34 -0
- package/dist/analytics/analytics.d.ts.map +1 -1
- package/dist/analytics/index.d.ts +1 -1
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics/index.js +1 -1
- package/dist/analytics/pdp.d.ts +46 -0
- package/dist/analytics/pdp.d.ts.map +1 -0
- package/dist/analytics/schemas.d.ts +1 -0
- package/dist/analytics/schemas.d.ts.map +1 -1
- package/dist/analytics/types.d.ts +60 -0
- package/dist/analytics/types.d.ts.map +1 -1
- package/dist/analytics-CqPkAIdv.js +195 -0
- package/dist/data/index.js +172 -175
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/pdp_event-DNU_h--P.js +8 -0
- package/package.json +3 -3
- package/dist/analytics-BqVdGxvp.js +0 -150
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ analytics.dispose();
|
|
|
102
102
|
| `trackPageView(componentRef)` | Widget mounted or navigated to a new component. Consecutive identical calls are deduplicated. |
|
|
103
103
|
| `trackInteraction(elementId, properties?)` | User interacted with a UI element (click, change, submit). |
|
|
104
104
|
| `trackEvent(eventName, properties?)` | Custom business event that isn't an interaction or page view. |
|
|
105
|
+
| `trackProductUsage(eventName, options?)` | Count feature usage in PDP (Huron). Needs a PFT Id; see [Counting product usage](#counting-product-usage-pdp). |
|
|
105
106
|
| `trackError(error, properties?)` | Explicitly report a caught error. Uncaught errors and unhandled promise rejections are captured automatically. |
|
|
106
107
|
| `dispose()` | Removes global error listeners, logs session duration, and flushes the upload buffer. Call once on teardown. |
|
|
107
108
|
|
|
@@ -143,6 +144,39 @@ const analytics = await createAnalytics({
|
|
|
143
144
|
|
|
144
145
|
Only PF Ids (KeyPrefix `aJC`, 15 or 18 chars) are accepted; PFE Ids (`aJD`) and malformed values are ignored, and the analytics instance simply carries no PFT attribution. Use `validatePftId` if you want to gate the value yourself before passing it in.
|
|
145
146
|
|
|
147
|
+
### Counting product usage (PDP)
|
|
148
|
+
|
|
149
|
+
`trackProductUsage` sends an `sf.pdp.PdpEvent` that Core records in PDP, so you can query it in Huron (`pdp_productusage`). These events do not land in Splunk.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// Count each widget once per analytics instance (the denominator).
|
|
153
|
+
analytics.trackProductUsage("hxlWidget.rendered", { componentId: "record-summary", once: true });
|
|
154
|
+
|
|
155
|
+
// Count every click.
|
|
156
|
+
analytics.trackProductUsage("hxlWidgetButton.clicked", {
|
|
157
|
+
componentId: "record-summary",
|
|
158
|
+
channel: "OpenAI",
|
|
159
|
+
subType: "button",
|
|
160
|
+
contextName: "action",
|
|
161
|
+
contextValue: "send-message",
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- The event is sent only when a PFT Id is set (via `pftId` or `setPftId`). PDP rejects events without one, so the call is a no-op otherwise.
|
|
166
|
+
- `eventName` must be `<object>.<action>`: both parts in lower camelCase (`hxlWidget.rendered`, `hxlWidget.buttonClicked`). Other names are dropped with a `console.debug` note.
|
|
167
|
+
- `once: true` sends a given `eventName` + `componentId` pair at most once per PFT Id for the life of the analytics instance. Use it for "rendered" and "interacted" counts.
|
|
168
|
+
- Optional fields, copied to the PDP row when they are strings (other values are dropped):
|
|
169
|
+
- `componentId`: the component that sent the event.
|
|
170
|
+
- `channel`: the surface, for example `OpenAI` or `Slack`.
|
|
171
|
+
- `subType`: a finer kind of event, for example `button`.
|
|
172
|
+
- `contextName` and `contextValue`: one extra detail.
|
|
173
|
+
- `eventVolume`: a count, when one event stands for several actions. Only whole numbers from 0 to 2,147,483,647 are sent.
|
|
174
|
+
- Use fixed names in every field. Never put button labels, URLs or record Ids in them.
|
|
175
|
+
- `productFeatureId` is filled in for you. Core fills in the org, user and session.
|
|
176
|
+
- To group events by widget session in Huron, use `clientSessionId`. Core sets `sessionId` from the server session, which is `GuestSession` for calls made through an MCP server.
|
|
177
|
+
|
|
178
|
+
The SDK bundles its own `sf.pdp.PdpEvent` descriptor, so consumers don't need to upgrade `o11y_schema`.
|
|
179
|
+
|
|
146
180
|
### Pages whose CSP blocks `'unsafe-eval'`
|
|
147
181
|
|
|
148
182
|
`o11y` encodes telemetry with protobufjs, which generates code at runtime. On a page whose Content Security Policy omits `'unsafe-eval'` from `script-src`, that encode throws an `EvalError` and no envelope reaches the transport. Set `useEvalFreeEncoder: true` to let `o11y` fall back to an eval-free encoder:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/analytics/analytics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/analytics/analytics.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAwC,MAAM,SAAS,CAAC;AAEjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAK7E"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* For full license text, see the LICENSE.txt file
|
|
5
5
|
*/
|
|
6
6
|
export { createAnalytics } from './analytics';
|
|
7
|
-
export type { Analytics, AnalyticsOptions } from './types';
|
|
7
|
+
export type { Analytics, AnalyticsOptions, ProductUsageOptions } from './types';
|
|
8
8
|
export { PFT_META_KEY, validatePftId } from './pft';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAOhF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/analytics/index.js
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validates a PDP event name at the SDK boundary.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Rejection never throws. The function logs a debug message with
|
|
11
|
+
* `console.debug` the first time it sees a given invalid name on the page,
|
|
12
|
+
* for up to 20 distinct names, and truncates long names. It drops later
|
|
13
|
+
* occurrences without further logging.
|
|
14
|
+
*
|
|
15
|
+
* @param name - The candidate event name, in any input shape, including non-strings.
|
|
16
|
+
* @returns `true` when the name follows the `<object>.<action>` rule.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* validatePdpEventName("hxlWidget.rendered"); // → true
|
|
20
|
+
* validatePdpEventName("hxlWidgetButton.clicked"); // → true
|
|
21
|
+
* validatePdpEventName("hxlWidget.buttonClicked"); // → true
|
|
22
|
+
* validatePdpEventName("HxlWidget.rendered"); // → false (object not lower camelCase)
|
|
23
|
+
* validatePdpEventName("hxlWidget.ButtonClicked"); // → false (action not lower camelCase)
|
|
24
|
+
* validatePdpEventName("hxl.widget.rendered"); // → false (more than one dot)
|
|
25
|
+
*/
|
|
26
|
+
export declare function validatePdpEventName(name: unknown): name is string;
|
|
27
|
+
/**
|
|
28
|
+
* Checks that a value fits the PDP `eventVolume` field.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* The field is an `int32` in `sf.pdp.PdpEvent`, and Core reads it only when it
|
|
32
|
+
* arrives as an integer. Negative counts have no meaning, so they fail too.
|
|
33
|
+
*
|
|
34
|
+
* @param value - The candidate count, in any input shape.
|
|
35
|
+
* @returns `true` for a whole number from 0 to 2,147,483,647.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isEventVolume(value: unknown): value is number;
|
|
38
|
+
/**
|
|
39
|
+
* Logs a one-time `console.debug` when a caller passes an `eventVolume` that
|
|
40
|
+
* {@link isEventVolume} rejects, so the dropped count isn't silent.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* The value itself isn't printed, in case it holds customer data.
|
|
44
|
+
*/
|
|
45
|
+
export declare function warnInvalidEventVolume(value: unknown): void;
|
|
46
|
+
//# sourceMappingURL=pdp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdp.d.ts","sourceRoot":"","sources":["../../src/analytics/pdp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+CH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAclE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAO3D"}
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
* For full license text, see the LICENSE.txt file
|
|
5
5
|
*/
|
|
6
6
|
export { customEventSchema, interactionSchema, pageViewSchema, sessionSchema, errorContextSchema, analyticsContextSchema, } from 'o11y_schema/sf_mcpanalytics';
|
|
7
|
+
export { pdpEventSchema } from 'o11y_schema/sf_pdp';
|
|
7
8
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/analytics/schemas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/analytics/schemas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -106,6 +106,47 @@ export interface AnalyticsOptions {
|
|
|
106
106
|
*/
|
|
107
107
|
useEvalFreeEncoder?: boolean;
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The options for {@link Analytics.trackProductUsage}.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* Every field is optional. The SDK sets `productFeatureId` and `sessionId`
|
|
114
|
+
* itself, and Core fills in the org, user and session from the request. Never put
|
|
115
|
+
* button labels, URLs, or record Ids in any field, because they can contain
|
|
116
|
+
* customer data.
|
|
117
|
+
*/
|
|
118
|
+
export interface ProductUsageOptions {
|
|
119
|
+
/** The component that sent the event, for example `record-detail-lists`. */
|
|
120
|
+
componentId?: string;
|
|
121
|
+
/** The name of one extra detail about the event, for example `host`. */
|
|
122
|
+
contextName?: string;
|
|
123
|
+
/** The value of the extra detail, for example `ChatGPT`. */
|
|
124
|
+
contextValue?: string;
|
|
125
|
+
/** The surface the event came from, for example `OpenAI` or `Slack`. */
|
|
126
|
+
channel?: string;
|
|
127
|
+
/** A finer kind of event, for example `button` for an interaction. */
|
|
128
|
+
subType?: string;
|
|
129
|
+
/**
|
|
130
|
+
* How many times the action happened, when one event counts several.
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* Must be a whole number from 0 to 2,147,483,647. The SDK leaves the field
|
|
134
|
+
* off for any other value, and PDP then counts the event once.
|
|
135
|
+
*/
|
|
136
|
+
eventVolume?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Sends the event at most once for the life of this Analytics instance.
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* The SDK keys repeats on the current PFT Id, `eventName` and `componentId`,
|
|
142
|
+
* so a widget that switches PFT Id with `setPftId()` sends the event once
|
|
143
|
+
* for each PFT Id. Use this option for events such as `hxlWidget.rendered`
|
|
144
|
+
* that must count once per widget, even when the widget re-renders.
|
|
145
|
+
*
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
once?: boolean;
|
|
149
|
+
}
|
|
109
150
|
/**
|
|
110
151
|
* The Analytics instance that `createAnalytics()` returns.
|
|
111
152
|
*/
|
|
@@ -122,6 +163,25 @@ export interface Analytics {
|
|
|
122
163
|
trackError: (error: Error | string, properties?: Record<string, unknown>) => void;
|
|
123
164
|
/** Logs a component load or page view. */
|
|
124
165
|
trackPageView: (componentRef: string) => void;
|
|
166
|
+
/**
|
|
167
|
+
* Logs a Product Data Platform (PDP) product-usage event, attributed to
|
|
168
|
+
* the current PFT Id.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* The event is an `sf.pdp.PdpEvent` that travels in the same upload as
|
|
172
|
+
* other analytics events. Core records it in PDP, so it counts toward
|
|
173
|
+
* product-feature usage. `trackEvent` events never reach PDP.
|
|
174
|
+
*
|
|
175
|
+
* The SDK drops the event silently when:
|
|
176
|
+
* - No valid PFT Id is set, because PDP rejects events without one.
|
|
177
|
+
* - `eventName` breaks the PDP `<object>.<action>` naming rule.
|
|
178
|
+
* - `options.once` is set and the event was already sent.
|
|
179
|
+
* - The instance is disposed.
|
|
180
|
+
*
|
|
181
|
+
* @param eventName - The PDP event name, for example `hxlWidgetButton.clicked`.
|
|
182
|
+
* @param options - Optional event details. See {@link ProductUsageOptions}.
|
|
183
|
+
*/
|
|
184
|
+
trackProductUsage: (eventName: string, options?: ProductUsageOptions) => void;
|
|
125
185
|
/**
|
|
126
186
|
* Sets the Product Feature Taxonomy (PFT) Id for attribution of later
|
|
127
187
|
* analytics events.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analytics/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,MAAM;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,SAAS,CAAC;CACvE;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OA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,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACpF,gCAAgC;IAChC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClF,0CAA0C;IAC1C,aAAa,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;;;;;;;;;;;;;;;;OAiBG;IACH,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC9E;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,wEAAwE;IACxE,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { registerInstrumentedApp as L } from "o11y/client";
|
|
2
|
+
import { g as M, S as z } from "./surface-DyglgPiz.js";
|
|
3
|
+
import { w as K } from "./sdk-promise-D0sy7OW1.js";
|
|
4
|
+
import { getChatSDK as O } from "./chat/index.js";
|
|
5
|
+
import { r as R } from "./TelemetryUploader-mZWIhtRG.js";
|
|
6
|
+
import { p as j } from "./pdp_event-DNU_h--P.js";
|
|
7
|
+
import { analyticsContextSchema as J, sessionSchema as W, pageViewSchema as Z, errorContextSchema as q, interactionSchema as U, customEventSchema as X } from "o11y_schema/sf_mcpanalytics";
|
|
8
|
+
function H(e) {
|
|
9
|
+
const n = (r, f, g, o, i) => {
|
|
10
|
+
e.error(i ?? r);
|
|
11
|
+
}, c = (r) => {
|
|
12
|
+
e.error(r.reason);
|
|
13
|
+
};
|
|
14
|
+
return window.addEventListener("error", n), window.addEventListener("unhandledrejection", c), () => {
|
|
15
|
+
window.removeEventListener("error", n), window.removeEventListener("unhandledrejection", c);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const w = /* @__PURE__ */ new Set(), Y = 20, T = 64;
|
|
19
|
+
let x = !1;
|
|
20
|
+
const B = /^[a-z][a-zA-Z0-9]*\.[a-z][a-zA-Z0-9]*$/;
|
|
21
|
+
function G(e) {
|
|
22
|
+
if (typeof e != "string") return !1;
|
|
23
|
+
if (B.test(e)) return !0;
|
|
24
|
+
if (!w.has(e) && w.size < Y) {
|
|
25
|
+
w.add(e);
|
|
26
|
+
const n = e.length > T ? `${e.slice(0, T)}…` : e;
|
|
27
|
+
console.debug(
|
|
28
|
+
`[platform-sdk:analytics] Ignoring invalid PDP event name "${n}". Expected "<object>.<action>", for example "hxlWidgetButton.clicked".`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return !1;
|
|
32
|
+
}
|
|
33
|
+
function Q(e) {
|
|
34
|
+
return Number.isInteger(e) && e >= 0 && e <= 2147483647;
|
|
35
|
+
}
|
|
36
|
+
function ee(e) {
|
|
37
|
+
x || (x = !0, console.debug(
|
|
38
|
+
`[platform-sdk:analytics] Ignoring invalid PDP eventVolume of type ${typeof e}. Expected a whole number from 0 to 2,147,483,647; the event counts once.`
|
|
39
|
+
));
|
|
40
|
+
}
|
|
41
|
+
const te = "aJC", pe = "sfdc.pftId", _ = /* @__PURE__ */ new Set(), ne = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
|
|
42
|
+
function k(e) {
|
|
43
|
+
return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (N(e, "Expected a 15- or 18-character Salesforce ID"), !1) : ne.test(e) ? !0 : (N(e, `Expected a Product Feature Id (prefix "${te}", base62).`), !1);
|
|
44
|
+
}
|
|
45
|
+
function N(e, n) {
|
|
46
|
+
_.has(e) || (_.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${n}`));
|
|
47
|
+
}
|
|
48
|
+
function v(e) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
const re = {
|
|
52
|
+
callTool: {
|
|
53
|
+
isAsync: !0,
|
|
54
|
+
extractTags: (e) => ({ toolName: e[0]?.toolName ?? "unknown" })
|
|
55
|
+
},
|
|
56
|
+
setWidgetState: {
|
|
57
|
+
isAsync: !1,
|
|
58
|
+
extractTags: v
|
|
59
|
+
},
|
|
60
|
+
sendMessageToHost: {
|
|
61
|
+
isAsync: !0,
|
|
62
|
+
extractTags: v
|
|
63
|
+
},
|
|
64
|
+
openLink: {
|
|
65
|
+
isAsync: !0,
|
|
66
|
+
extractTags: v
|
|
67
|
+
},
|
|
68
|
+
readResource: {
|
|
69
|
+
isAsync: !0,
|
|
70
|
+
extractTags: (e) => {
|
|
71
|
+
const c = e[0]?.uri ?? "", r = c.indexOf("://");
|
|
72
|
+
return { scheme: r > 0 ? c.slice(0, r).toLowerCase() : "unknown" };
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
setDisplayMode: {
|
|
76
|
+
isAsync: !0,
|
|
77
|
+
extractTags: (e) => ({ mode: e[0] ?? "unknown" })
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function oe(e, n, c) {
|
|
81
|
+
return new Proxy(e, {
|
|
82
|
+
get(r, f, g) {
|
|
83
|
+
const o = Reflect.get(r, f, g), i = re[f];
|
|
84
|
+
return !i || typeof o != "function" ? o : (...l) => {
|
|
85
|
+
const s = { ...c(), ...i.extractTags(l) }, d = `sdk.${String(f)}`;
|
|
86
|
+
return i.isAsync ? n.activityAsync(d, async () => {
|
|
87
|
+
try {
|
|
88
|
+
const p = await o.apply(r, l);
|
|
89
|
+
return n.incrementCounter(d, 1, !1, s), p;
|
|
90
|
+
} catch (p) {
|
|
91
|
+
throw n.incrementCounter(d, 1, !0, s), p;
|
|
92
|
+
}
|
|
93
|
+
}) : (n.incrementCounter(d, 1, !1, s), o.apply(r, l));
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function ge(e) {
|
|
99
|
+
return K(se(e), "createAnalytics");
|
|
100
|
+
}
|
|
101
|
+
async function se(e) {
|
|
102
|
+
const { appId: n, clientSessionId: c } = e;
|
|
103
|
+
let r;
|
|
104
|
+
try {
|
|
105
|
+
r = await M();
|
|
106
|
+
} catch {
|
|
107
|
+
r = z.WebApp;
|
|
108
|
+
}
|
|
109
|
+
const f = Date.now(), g = e.sdk ?? await O();
|
|
110
|
+
let o = null;
|
|
111
|
+
e.pftId !== void 0 && k(e.pftId) && (o = e.pftId);
|
|
112
|
+
const i = () => o !== null ? { pftId: o } : {}, l = L("mcp-widget", {
|
|
113
|
+
appPayloadProvider: {
|
|
114
|
+
getPayload: () => ({
|
|
115
|
+
schema: J,
|
|
116
|
+
payload: {
|
|
117
|
+
appId: n,
|
|
118
|
+
surface: r,
|
|
119
|
+
...i()
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
},
|
|
123
|
+
clientSessionId: c
|
|
124
|
+
}), s = l, d = oe(g, s, () => ({
|
|
125
|
+
surface: r,
|
|
126
|
+
...i()
|
|
127
|
+
})), p = H(s);
|
|
128
|
+
let h;
|
|
129
|
+
e.transport && (h = R(l, {
|
|
130
|
+
onEnvelope: (t) => {
|
|
131
|
+
e.transport.enqueue(t);
|
|
132
|
+
},
|
|
133
|
+
useEvalFreeEncoder: e.useEvalFreeEncoder
|
|
134
|
+
}));
|
|
135
|
+
let P, u = !1;
|
|
136
|
+
const I = /* @__PURE__ */ new Set();
|
|
137
|
+
return {
|
|
138
|
+
instrumentedSDK: d,
|
|
139
|
+
app: l,
|
|
140
|
+
trackEvent(t, a) {
|
|
141
|
+
u || s.log(X, {
|
|
142
|
+
eventName: t,
|
|
143
|
+
properties: a ? JSON.stringify(a) : ""
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
trackInteraction(t, a) {
|
|
147
|
+
u || s.log(U, {
|
|
148
|
+
elementId: t,
|
|
149
|
+
properties: a ? JSON.stringify(a) : ""
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
trackError(t, a) {
|
|
153
|
+
u || s.error(t, q, {
|
|
154
|
+
properties: a ? JSON.stringify(a) : ""
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
trackPageView(t) {
|
|
158
|
+
u || t !== P && (P = t, s.log(Z, { componentRef: t }));
|
|
159
|
+
},
|
|
160
|
+
trackProductUsage(t, a) {
|
|
161
|
+
if (u || !G(t) || o === null) return;
|
|
162
|
+
const { componentId: A, contextName: C, contextValue: D, channel: V, subType: $, eventVolume: m, once: F } = a ?? {}, y = F ? `${o}\0${t}\0${A ?? ""}` : null;
|
|
163
|
+
if (y !== null && I.has(y)) return;
|
|
164
|
+
const E = {};
|
|
165
|
+
for (const [b, S] of Object.entries({
|
|
166
|
+
componentId: A,
|
|
167
|
+
contextName: C,
|
|
168
|
+
contextValue: D,
|
|
169
|
+
channel: V,
|
|
170
|
+
subType: $
|
|
171
|
+
}))
|
|
172
|
+
typeof S == "string" && (E[b] = S);
|
|
173
|
+
Q(m) ? E.eventVolume = m : m !== void 0 && ee(m), s.log(j, {
|
|
174
|
+
...E,
|
|
175
|
+
eventName: t,
|
|
176
|
+
productFeatureId: o,
|
|
177
|
+
sessionId: l.getClientSessionId()
|
|
178
|
+
}), y !== null && I.add(y);
|
|
179
|
+
},
|
|
180
|
+
setPftId(t) {
|
|
181
|
+
u || k(t) && (o = t);
|
|
182
|
+
},
|
|
183
|
+
dispose() {
|
|
184
|
+
if (u) return;
|
|
185
|
+
u = !0, p();
|
|
186
|
+
const t = Date.now() - f;
|
|
187
|
+
s.log(W, { durationMs: t }), h?.dispose();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export {
|
|
192
|
+
pe as P,
|
|
193
|
+
ge as c,
|
|
194
|
+
k as v
|
|
195
|
+
};
|