@salesforce/platform-sdk 11.6.0 → 11.8.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.
@@ -1,4 +1,4 @@
1
- import { A as s, I as A, P as E, c as t, v as I } from "../analytics-CY_NdbkB.js";
1
+ import { A as s, I as A, P as E, c as t, v as I } from "../analytics-CIbrgyL8.js";
2
2
  export {
3
3
  s as AXL_PFT_ID,
4
4
  A as INTERNAL_SESSION_META_KEY,
@@ -6,8 +6,10 @@
6
6
  export interface MethodConfig {
7
7
  /** Whether this method returns a Promise and should use activityAsync */
8
8
  isAsync: boolean;
9
- /** Extract dimensional tags from the method arguments */
10
- extractTags: (args: unknown[], surface: string) => Record<string, string>;
9
+ /** Extract per-call dimensional tags from the method arguments. Static tags
10
+ * (surface, PFT ids) are merged in by the proxy from its getStaticTags
11
+ * provider, so extractTags should return only method-specific keys. */
12
+ extractTags: (args: unknown[]) => Record<string, string>;
11
13
  }
12
14
  export declare const methodConfigs: Record<string, MethodConfig>;
13
15
  //# sourceMappingURL=method-configs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"method-configs.d.ts","sourceRoot":"","sources":["../../src/analytics/method-configs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,yDAAyD;IACzD,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1E;AAMD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAoCtD,CAAC"}
1
+ {"version":3,"file":"method-configs.d.ts","sourceRoot":"","sources":["../../src/analytics/method-configs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB;;2EAEuE;IACvE,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzD;AAMD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAoCtD,CAAC"}
@@ -8,6 +8,10 @@ import { Instrumentation } from './types';
8
8
  * round-trip timing. incrementCounter() records call counts and error rates.
9
9
  * - Sync methods use incrementCounter() only.
10
10
  * - Unconfigured methods pass through unchanged.
11
+ *
12
+ * getStaticTags is re-read on every invocation and merged into the counter
13
+ * tag map so late-bound values (PFT ids, internal-session gate) reach the
14
+ * metric channel without proxy re-creation (W-23257158).
11
15
  */
12
- export declare function createInstrumentedProxy(sdk: ChatSDK, instrumentation: Instrumentation, surface: string): ChatSDK;
16
+ export declare function createInstrumentedProxy(sdk: ChatSDK, instrumentation: Instrumentation, getStaticTags: () => Record<string, string>): ChatSDK;
13
17
  //# sourceMappingURL=proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/analytics/proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,MAAM,GACb,OAAO,CAiCT"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/analytics/proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,OAAO,CAkCT"}
@@ -0,0 +1,159 @@
1
+ import { registerInstrumentedApp as h } from "o11y/client";
2
+ import { g as T, S as x } from "./surface-Dd2tqrPi.js";
3
+ import { w as v } from "./sdk-promise-D0sy7OW1.js";
4
+ import { getChatSDK as _ } from "./chat/index.js";
5
+ import { r as C } from "./TelemetryUploader-DKkdppe9.js";
6
+ import { analyticsContextSchema as k, sessionSchema as F, pageViewSchema as L, errorContextSchema as N, interactionSchema as D, customEventSchema as J } from "o11y_schema/sf_mcpanalytics";
7
+ function K(e) {
8
+ const n = (r, f, p, o, u) => {
9
+ e.error(u ?? r);
10
+ }, a = (r) => {
11
+ e.error(r.reason);
12
+ };
13
+ return window.addEventListener("error", n), window.addEventListener("unhandledrejection", a), () => {
14
+ window.removeEventListener("error", n), window.removeEventListener("unhandledrejection", a);
15
+ };
16
+ }
17
+ const O = "aJC", W = "sfdc.pftId", X = "sfdc.internalSession", M = "aJCEE000000FgYP4A0", I = /* @__PURE__ */ new Set(), R = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
18
+ function S(e) {
19
+ return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (A(e, "Expected a 15- or 18-character Salesforce ID"), !1) : R.test(e) ? !0 : (A(e, `Expected a Product Feature Id (prefix "${O}", base62).`), !1);
20
+ }
21
+ function A(e, n) {
22
+ I.has(e) || (I.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${n}`));
23
+ }
24
+ function g(e) {
25
+ return {};
26
+ }
27
+ const $ = {
28
+ callTool: {
29
+ isAsync: !0,
30
+ extractTags: (e) => ({ toolName: e[0]?.toolName ?? "unknown" })
31
+ },
32
+ setWidgetState: {
33
+ isAsync: !1,
34
+ extractTags: g
35
+ },
36
+ sendMessageToHost: {
37
+ isAsync: !0,
38
+ extractTags: g
39
+ },
40
+ openLink: {
41
+ isAsync: !0,
42
+ extractTags: g
43
+ },
44
+ readResource: {
45
+ isAsync: !0,
46
+ extractTags: (e) => {
47
+ const a = e[0]?.uri ?? "", r = a.indexOf("://");
48
+ return { scheme: r > 0 ? a.slice(0, r).toLowerCase() : "unknown" };
49
+ }
50
+ },
51
+ setDisplayMode: {
52
+ isAsync: !0,
53
+ extractTags: (e) => ({ mode: e[0] ?? "unknown" })
54
+ }
55
+ };
56
+ function V(e, n, a) {
57
+ return new Proxy(e, {
58
+ get(r, f, p) {
59
+ const o = Reflect.get(r, f, p), u = $[f];
60
+ return !u || typeof o != "function" ? o : (...d) => {
61
+ const m = { ...a(), ...u.extractTags(d) }, c = `sdk.${String(f)}`;
62
+ return u.isAsync ? n.activityAsync(c, async () => {
63
+ try {
64
+ const s = await o.apply(r, d);
65
+ return n.incrementCounter(c, 1, !1, m), s;
66
+ } catch (s) {
67
+ throw n.incrementCounter(c, 1, !0, m), s;
68
+ }
69
+ }) : (n.incrementCounter(c, 1, !1, m), o.apply(r, d));
70
+ };
71
+ }
72
+ });
73
+ }
74
+ function Z(e) {
75
+ return v(Y(e), "createAnalytics");
76
+ }
77
+ async function Y(e) {
78
+ const { appId: n, clientSessionId: a } = e;
79
+ let r;
80
+ try {
81
+ r = await T();
82
+ } catch {
83
+ r = x.WebApp;
84
+ }
85
+ const f = Date.now(), p = e.sdk ?? await _();
86
+ let o = null;
87
+ e.pftId !== void 0 && S(e.pftId) && (o = e.pftId);
88
+ const u = e.enforceInternalGate === !0;
89
+ let d = !1;
90
+ const m = () => !u || d ? {
91
+ axlPftId: M,
92
+ ...o !== null ? { pftId: o } : {}
93
+ } : {}, c = h("mcp-widget", {
94
+ appPayloadProvider: {
95
+ getPayload: () => ({
96
+ schema: k,
97
+ payload: {
98
+ appId: n,
99
+ surface: r,
100
+ ...m()
101
+ }
102
+ })
103
+ },
104
+ clientSessionId: a
105
+ }), s = c, E = V(p, s, () => ({
106
+ surface: r,
107
+ ...m()
108
+ })), P = K(s);
109
+ let y;
110
+ e.transport && (y = C(c, {
111
+ onEnvelope: (t) => {
112
+ e.transport.enqueue(t);
113
+ }
114
+ }));
115
+ let w, i = !1;
116
+ return {
117
+ instrumentedSDK: E,
118
+ app: c,
119
+ trackEvent(t, l) {
120
+ i || s.log(J, {
121
+ eventName: t,
122
+ properties: l ? JSON.stringify(l) : ""
123
+ });
124
+ },
125
+ trackInteraction(t, l) {
126
+ i || s.log(D, {
127
+ elementId: t,
128
+ properties: l ? JSON.stringify(l) : ""
129
+ });
130
+ },
131
+ trackError(t, l) {
132
+ i || s.error(t, N, {
133
+ properties: l ? JSON.stringify(l) : ""
134
+ });
135
+ },
136
+ trackPageView(t) {
137
+ i || t !== w && (w = t, s.log(L, { componentRef: t }));
138
+ },
139
+ setPftId(t) {
140
+ i || S(t) && (o = t);
141
+ },
142
+ setInternalSession(t) {
143
+ i || (d = t === !0);
144
+ },
145
+ dispose() {
146
+ if (i) return;
147
+ i = !0, P();
148
+ const t = Date.now() - f;
149
+ s.log(F, { durationMs: t }), y?.dispose();
150
+ }
151
+ };
152
+ }
153
+ export {
154
+ M as A,
155
+ X as I,
156
+ W as P,
157
+ Z as c,
158
+ S as v
159
+ };
@@ -196,7 +196,7 @@ class ie {
196
196
  })).structuredContent;
197
197
  }
198
198
  }
199
- const ce = "X-SFDC-Client-Name", ue = "X-SFDC-Client-Version", he = "@salesforce/platform-sdk", le = "11.6.0", de = (t) => {
199
+ const ce = "X-SFDC-Client-Name", ue = "X-SFDC-Client-Version", he = "@salesforce/platform-sdk", le = "11.8.0", de = (t) => {
200
200
  let e = y(ce, he, t);
201
201
  return e = y(ue, le, e), u(e);
202
202
  }, pe = "X-CSRF-Token";
@@ -3,7 +3,7 @@
3
3
  * All rights reserved.
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
- export { fetchI18nContext, createSalesforceDetector } from './salesforce-detector';
6
+ export { fetchI18nContext, createSalesforceDetector, reloadI18nContext, } from './salesforce-detector';
7
7
  export type { I18nContext } from './salesforce-detector';
8
8
  export { SalesforceBackend } from './salesforce-backend';
9
9
  export type { SalesforceBackendOptions } from './salesforce-backend';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACnF,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,9 +1,9 @@
1
- let l = null;
2
- async function u(n) {
3
- if (l) return l;
4
- if (!n.graphql)
1
+ let o = null;
2
+ async function i(r) {
3
+ if (o) return o;
4
+ if (!r.graphql)
5
5
  throw new Error("Data SDK GraphQL surface unavailable");
6
- const a = await n.graphql.query({
6
+ const a = await r.graphql.query({
7
7
  operationName: "I18nDetect",
8
8
  query: `
9
9
  query I18nDetect {
@@ -26,17 +26,20 @@ async function u(n) {
26
26
  `I18nDetect query failed: ${JSON.stringify(a.errors ?? "no data, no errors")}`
27
27
  );
28
28
  const e = a.data.uiapi.platform.i18n;
29
- return l = e, e;
29
+ return o = e, e;
30
30
  }
31
- function f(n) {
31
+ async function f(r) {
32
+ return o = null, i(r);
33
+ }
34
+ function p(r) {
32
35
  return {
33
36
  type: "languageDetector",
34
37
  detect() {
35
- return l?.lang;
38
+ return o?.lang;
36
39
  }
37
40
  };
38
41
  }
39
- const i = `
42
+ const c = `
40
43
  query Labels($ns: String!, $names: [String!]!, $locale: String) {
41
44
  uiapi {
42
45
  platform {
@@ -50,49 +53,50 @@ const i = `
50
53
  }
51
54
  }
52
55
  `;
53
- function c(n) {
56
+ function u(r) {
54
57
  const a = {};
55
- for (const e of n) {
58
+ for (const e of r) {
56
59
  const t = e.indexOf(":");
57
60
  if (t === -1) continue;
58
- const r = e.slice(0, t), o = e.slice(t + 1);
59
- (a[r] ??= []).push(o);
61
+ const n = e.slice(0, t), l = e.slice(t + 1);
62
+ (a[n] ??= []).push(l);
60
63
  }
61
64
  return a;
62
65
  }
63
- class p {
66
+ class d {
64
67
  type = "backend";
65
68
  static type = "backend";
66
69
  options = { dataSDK: {} };
67
70
  grouped = {};
68
71
  init(a, e) {
69
- this.options = e, this.grouped = c(e.labelManifest ?? []);
72
+ this.options = e, this.grouped = u(e.labelManifest ?? []);
70
73
  }
71
74
  read(a, e, t) {
72
- this.loadLabels(a, e).then((r) => t(null, r)).catch((r) => t(r, !1));
75
+ this.loadLabels(a, e).then((n) => t(null, n)).catch((n) => t(n, !1));
73
76
  }
74
77
  async loadLabels(a, e) {
75
78
  const t = this.grouped[e];
76
79
  if (!t?.length) return {};
77
80
  if (!this.options.dataSDK.graphql)
78
81
  throw new Error("Data SDK GraphQL surface unavailable");
79
- const r = await this.options.dataSDK.graphql.query({
82
+ const n = await this.options.dataSDK.graphql.query({
80
83
  operationName: "Labels",
81
- query: i,
84
+ query: c,
82
85
  variables: { ns: e, names: t, locale: a }
83
86
  });
84
- if (!r.data)
87
+ if (!n.data)
85
88
  throw new Error(
86
- `Labels query failed: ${JSON.stringify(r.errors ?? "no data, no errors")}`
89
+ `Labels query failed: ${JSON.stringify(n.errors ?? "no data, no errors")}`
87
90
  );
88
- const o = {};
89
- for (const s of r.data.uiapi.platform.labels)
90
- s.value != null && (o[s.name] = s.value);
91
- return o;
91
+ const l = {};
92
+ for (const s of n.data.uiapi.platform.labels)
93
+ s.value != null && (l[s.name] = s.value);
94
+ return l;
92
95
  }
93
96
  }
94
97
  export {
95
- p as SalesforceBackend,
96
- f as createSalesforceDetector,
97
- u as fetchI18nContext
98
+ d as SalesforceBackend,
99
+ p as createSalesforceDetector,
100
+ i as fetchI18nContext,
101
+ f as reloadI18nContext
98
102
  };
@@ -17,6 +17,21 @@ export interface I18nContext {
17
17
  timeZone: string;
18
18
  }
19
19
  export declare function fetchI18nContext(dataSDK: DataSDK): Promise<I18nContext>;
20
+ /**
21
+ * Reload the cached i18n context: clear the memoized value and immediately
22
+ * re-query the platform, resolving to the fresh context.
23
+ *
24
+ * The context is fetched once and memoized for the lifetime of the page, so a
25
+ * locale change normally only takes effect on a full page reload. Call this
26
+ * after an in-session locale change: clearing and re-fetching are a single
27
+ * operation, so a caller cannot clear the cache and then forget to refill it.
28
+ *
29
+ * The cache is cleared before the re-query runs, so if the re-query fails the
30
+ * returned promise rejects and the cache is left empty — `detect()` reverts to
31
+ * `undefined` until a later successful fetch. Callers should handle rejection
32
+ * rather than assume a reload always repopulates.
33
+ */
34
+ export declare function reloadI18nContext(dataSDK: DataSDK): Promise<I18nContext>;
20
35
  export declare function createSalesforceDetector(_dataSDK: DataSDK): LanguageDetectorModule;
21
36
  export {};
22
37
  //# sourceMappingURL=salesforce-detector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"salesforce-detector.d.ts","sourceRoot":"","sources":["../../src/i18n/salesforce-detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,UAAU,sBAAsB;IAC/B,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAYD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAkC7E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,GAAG,sBAAsB,CAQlF"}
1
+ {"version":3,"file":"salesforce-detector.d.ts","sourceRoot":"","sources":["../../src/i18n/salesforce-detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,UAAU,sBAAsB;IAC/B,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAYD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAkC7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAG9E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,GAAG,sBAAsB,CAQlF"}
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { createDataSDK as _, gql as h } from "./data/index.js";
7
7
  import { createLightningSDK as I } from "./lightning/index.js";
8
8
  import { c as b } from "./transport-CdXFRgRc.js";
9
9
  import { T as N, r as v } from "./TelemetryUploader-DKkdppe9.js";
10
- import { A as F, I as U, P as Y, c as q, v as z } from "./analytics-CY_NdbkB.js";
10
+ import { A as F, I as U, P as Y, c as q, v as z } from "./analytics-CIbrgyL8.js";
11
11
  export {
12
12
  F as AXL_PFT_ID,
13
13
  U as INTERNAL_SESSION_META_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/platform-sdk",
3
- "version": "11.6.0",
3
+ "version": "11.8.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -115,7 +115,7 @@
115
115
  "@conduit-client/service-pubsub": "3.19.6",
116
116
  "@conduit-client/service-retry": "3.19.6",
117
117
  "@conduit-client/utils": "3.19.6",
118
- "@salesforce/jsonrpc": "^11.6.0",
118
+ "@salesforce/jsonrpc": "^11.8.0",
119
119
  "@salesforce/sf-embedding-bridge": "2.2.4-rc.1"
120
120
  },
121
121
  "peerDependencies": {
@@ -1,157 +0,0 @@
1
- import { registerInstrumentedApp as P } from "o11y/client";
2
- import { g as h, S as T } from "./surface-Dd2tqrPi.js";
3
- import { w as x } from "./sdk-promise-D0sy7OW1.js";
4
- import { getChatSDK as v } from "./chat/index.js";
5
- import { r as _ } from "./TelemetryUploader-DKkdppe9.js";
6
- import { analyticsContextSchema as C, sessionSchema as k, pageViewSchema as L, errorContextSchema as N, interactionSchema as D, customEventSchema as F } from "o11y_schema/sf_mcpanalytics";
7
- function O(e) {
8
- const r = (n, c, p, a, u) => {
9
- e.error(u ?? n);
10
- }, o = (n) => {
11
- e.error(n.reason);
12
- };
13
- return window.addEventListener("error", r), window.addEventListener("unhandledrejection", o), () => {
14
- window.removeEventListener("error", r), window.removeEventListener("unhandledrejection", o);
15
- };
16
- }
17
- const J = "aJC", U = "sfdc.pftId", W = "sfdc.internalSession", K = "aJCEE000000FgYP4A0", w = /* @__PURE__ */ new Set(), M = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
18
- function S(e) {
19
- return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (E(e, "Expected a 15- or 18-character Salesforce ID"), !1) : M.test(e) ? !0 : (E(e, `Expected a Product Feature Id (prefix "${J}", base62).`), !1);
20
- }
21
- function E(e, r) {
22
- w.has(e) || (w.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${r}`));
23
- }
24
- function g(e, r) {
25
- return { surface: r };
26
- }
27
- const R = {
28
- callTool: {
29
- isAsync: !0,
30
- extractTags: (e, r) => ({ toolName: e[0]?.toolName ?? "unknown", surface: r })
31
- },
32
- setWidgetState: {
33
- isAsync: !1,
34
- extractTags: g
35
- },
36
- sendMessageToHost: {
37
- isAsync: !0,
38
- extractTags: g
39
- },
40
- openLink: {
41
- isAsync: !0,
42
- extractTags: g
43
- },
44
- readResource: {
45
- isAsync: !0,
46
- extractTags: (e, r) => {
47
- const n = e[0]?.uri ?? "", c = n.indexOf("://");
48
- return { scheme: c > 0 ? n.slice(0, c).toLowerCase() : "unknown", surface: r };
49
- }
50
- },
51
- setDisplayMode: {
52
- isAsync: !0,
53
- extractTags: (e, r) => ({ mode: e[0] ?? "unknown", surface: r })
54
- }
55
- };
56
- function $(e, r, o) {
57
- return new Proxy(e, {
58
- get(n, c, p) {
59
- const a = Reflect.get(n, c, p), u = R[c];
60
- return !u || typeof a != "function" ? a : (...d) => {
61
- const f = u.extractTags(d, o), s = `sdk.${String(c)}`;
62
- return u.isAsync ? r.activityAsync(s, async () => {
63
- try {
64
- const m = await a.apply(n, d);
65
- return r.incrementCounter(s, 1, !1, f), m;
66
- } catch (m) {
67
- throw r.incrementCounter(s, 1, !0, f), m;
68
- }
69
- }) : (r.incrementCounter(s, 1, !1, f), a.apply(n, d));
70
- };
71
- }
72
- });
73
- }
74
- function X(e) {
75
- return x(V(e), "createAnalytics");
76
- }
77
- async function V(e) {
78
- const { appId: r, clientSessionId: o } = e;
79
- let n;
80
- try {
81
- n = await h();
82
- } catch {
83
- n = T.WebApp;
84
- }
85
- const c = Date.now(), p = e.sdk ?? await v();
86
- let a = null;
87
- e.pftId !== void 0 && S(e.pftId) && (a = e.pftId);
88
- const u = e.enforceInternalGate === !0;
89
- let d = !1;
90
- const f = P("mcp-widget", {
91
- appPayloadProvider: {
92
- getPayload: () => {
93
- const t = !u || d;
94
- return {
95
- schema: C,
96
- payload: {
97
- appId: r,
98
- surface: n,
99
- ...t ? { axlPftId: K } : {},
100
- ...t && a !== null ? { pftId: a } : {}
101
- }
102
- };
103
- }
104
- },
105
- clientSessionId: o
106
- }), s = f, m = $(p, s, n), A = O(s);
107
- let y;
108
- e.transport && (y = _(f, {
109
- onEnvelope: (t) => {
110
- e.transport.enqueue(t);
111
- }
112
- }));
113
- let I, i = !1;
114
- return {
115
- instrumentedSDK: m,
116
- app: f,
117
- trackEvent(t, l) {
118
- i || s.log(F, {
119
- eventName: t,
120
- properties: l ? JSON.stringify(l) : ""
121
- });
122
- },
123
- trackInteraction(t, l) {
124
- i || s.log(D, {
125
- elementId: t,
126
- properties: l ? JSON.stringify(l) : ""
127
- });
128
- },
129
- trackError(t, l) {
130
- i || s.error(t, N, {
131
- properties: l ? JSON.stringify(l) : ""
132
- });
133
- },
134
- trackPageView(t) {
135
- i || t !== I && (I = t, s.log(L, { componentRef: t }));
136
- },
137
- setPftId(t) {
138
- i || S(t) && (a = t);
139
- },
140
- setInternalSession(t) {
141
- i || (d = t === !0);
142
- },
143
- dispose() {
144
- if (i) return;
145
- i = !0, A();
146
- const t = Date.now() - c;
147
- s.log(k, { durationMs: t }), y?.dispose();
148
- }
149
- };
150
- }
151
- export {
152
- K as A,
153
- W as I,
154
- U as P,
155
- X as c,
156
- S as v
157
- };