@salesforce/platform-sdk 9.10.2 → 9.10.3

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 CHANGED
@@ -47,6 +47,100 @@ const result = await sdk.graphql?.query<GetAccountsQuery>({
47
47
 
48
48
  The chat, view, lightning, telemetry, and analytics surfaces follow the same pattern — see [Migrating from individual SDK packages](#migrating-from-individual-sdk-packages) for the full set of factories.
49
49
 
50
+ ## Instrumenting a widget
51
+
52
+ `createAnalytics` is the recommended entry point for Mosaic widget tiles and other MCP-embedded UI components. It wires an `o11y` instrumented app, a Proxy-wrapped `ChatSDK` for auto-instrumentation, global error listeners, and an optional upload transport — all from one call.
53
+
54
+ ```ts
55
+ import { createAnalytics, createTelemetryTransport, getChatSDK } from "@salesforce/platform-sdk";
56
+
57
+ const sdk = await getChatSDK();
58
+ const transport = createTelemetryTransport({ sdk });
59
+ const analytics = await createAnalytics({
60
+ appId: "my-mosaic-tile",
61
+ sdk,
62
+ transport,
63
+ });
64
+
65
+ // Pass `analytics.instrumentedSDK` to widget hosts that expect a `ChatSDK` —
66
+ // SDK calls made through it are auto-instrumented.
67
+
68
+ analytics.trackPageView("AccountTile");
69
+ analytics.trackInteraction("account-tile-row", { accountId });
70
+ analytics.trackEvent("record_opened", { recordId });
71
+
72
+ // On widget/app teardown:
73
+ analytics.dispose();
74
+ ```
75
+
76
+ | Method | When to call |
77
+ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
78
+ | `trackPageView(componentRef)` | Widget mounted or navigated to a new component. Consecutive identical calls are deduplicated. |
79
+ | `trackInteraction(elementId, properties?)` | User interacted with a UI element (click, change, submit). |
80
+ | `trackEvent(eventName, properties?)` | Custom business event that isn't an interaction or page view. |
81
+ | `trackError(error, properties?)` | Explicitly report a caught error. Uncaught errors and unhandled promise rejections are captured automatically. |
82
+ | `dispose()` | Removes global error listeners, logs session duration, and flushes the upload buffer. Call once on teardown. |
83
+
84
+ `createAnalytics` is async because it constructs a `ChatSDK` if you don't supply one. To skip the transport (e.g., during local development), omit the `transport` option — events still flow through `o11y` but aren't uploaded.
85
+
86
+ ## Telemetry transport
87
+
88
+ `createTelemetryTransport` buffers `o11y` envelopes and uploads them via the `telemetry/upload` tool exposed by the host `ChatSDK`. Use it directly when you want batching independent of `createAnalytics`.
89
+
90
+ ```ts
91
+ import { createTelemetryTransport, getChatSDK } from "@salesforce/platform-sdk";
92
+
93
+ const transport = createTelemetryTransport({
94
+ sdk: await getChatSDK(),
95
+ flushInterval: 30_000, // ms; default 30s
96
+ maxBufferSize: 65_536, // bytes; default 64 KB
97
+ onError: ({ reason, error, droppedCount }) => {
98
+ console.warn("[telemetry]", reason, { error, droppedCount });
99
+ },
100
+ });
101
+
102
+ transport.enqueue(envelopeBytes);
103
+ transport.dispose(); // flush + cleanup
104
+ ```
105
+
106
+ Behavior:
107
+
108
+ - **Buffering.** Up to `maxBufferSize` bytes. On overflow the oldest entries are evicted and `onError` fires with `reason: "buffer_overflow"` and a `droppedCount`.
109
+ - **Automatic flush.** On `flushInterval`, on `visibilitychange` → hidden, on `pagehide`, and on `dispose()`.
110
+ - **Upload path.** Each flush calls `sdk.callTool({ toolName: "telemetry/upload", params: { inputs: [{ envelopes }] } })`. If the call rejects, `onError` fires with `reason: "tool_call_failed"`.
111
+
112
+ ## Advanced: `registerTelemetryUploader`
113
+
114
+ Use `registerTelemetryUploader` when you already manage your own `o11y` `InstrumentedApp` and don't want `createAnalytics` to create one for you.
115
+
116
+ ```ts
117
+ import {
118
+ registerTelemetryUploader,
119
+ createTelemetryTransport,
120
+ getChatSDK,
121
+ } from "@salesforce/platform-sdk";
122
+ import { registerInstrumentedApp } from "o11y/client";
123
+
124
+ const app = registerInstrumentedApp("my-app", {
125
+ /* o11y options */
126
+ });
127
+ const transport = createTelemetryTransport({ sdk: await getChatSDK() });
128
+
129
+ const uploader = registerTelemetryUploader(app, {
130
+ onEnvelope: (envelope) => transport.enqueue(envelope),
131
+ uploadInterval: 10_000,
132
+ messagesLimit: 10,
133
+ metricsLimit: 10,
134
+ enableClickTrigger: true,
135
+ enableVisibilityTrigger: true,
136
+ });
137
+
138
+ // On teardown:
139
+ await uploader.dispose({ flush: true });
140
+ ```
141
+
142
+ `uploader.flush(reason)` accepts a `FlushReason` of `"manual" | "interval" | "threshold" | "click" | "visibilitychange" | "pagehide" | "dispose"` and is exposed via the `TelemetryUploadContext` passed to `onEnvelope`.
143
+
50
144
  ## Migrating from individual SDK packages
51
145
 
52
146
  This package replaced the seven previously-published per-domain SDK packages. The deprecation shims published as their final 5.x.x versions forwarded every export to `@salesforce/platform-sdk` and have now been removed:
package/dist/index.js CHANGED
@@ -999,7 +999,7 @@ class Ze {
999
999
  })).structuredContent;
1000
1000
  }
1001
1001
  }
1002
- const et = "X-SFDC-Client-Name", tt = "X-SFDC-Client-Version", st = "@salesforce/platform-sdk", rt = "9.10.2", nt = (s) => {
1002
+ const et = "X-SFDC-Client-Name", tt = "X-SFDC-Client-Version", st = "@salesforce/platform-sdk", rt = "9.10.3", nt = (s) => {
1003
1003
  let e = _(et, st, s);
1004
1004
  return e = _(tt, rt, e), w(e);
1005
1005
  }, it = "X-CSRF-Token";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/platform-sdk",
3
- "version": "9.10.2",
3
+ "version": "9.10.3",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",