@salesforce/metadata-core-sdk 1.8.0 → 1.9.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 +61 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.d.ts +34 -0
- package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.d.ts.map +1 -0
- package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.js +64 -0
- package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.js.map +1 -0
- package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts +5 -0
- package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts.map +1 -1
- package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js +6 -1
- package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js.map +1 -1
- package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.d.ts +7 -1
- package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.d.ts.map +1 -1
- package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.js +6 -1
- package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.js.map +1 -1
- package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.d.ts.map +1 -1
- package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js +129 -18
- package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js.map +1 -1
- package/dist/sdk/utils/HostCommunicationUtils.d.ts +13 -0
- package/dist/sdk/utils/HostCommunicationUtils.d.ts.map +1 -1
- package/dist/sdk/utils/HostCommunicationUtils.js +48 -19
- package/dist/sdk/utils/HostCommunicationUtils.js.map +1 -1
- package/dist/sdk/utils/telemetry/telemetryBuffer.d.ts +54 -0
- package/dist/sdk/utils/telemetry/telemetryBuffer.d.ts.map +1 -0
- package/dist/sdk/utils/telemetry/telemetryBuffer.js +163 -0
- package/dist/sdk/utils/telemetry/telemetryBuffer.js.map +1 -0
- package/dist/sdk/utils/telemetry/telemetryEvents.d.ts +60 -0
- package/dist/sdk/utils/telemetry/telemetryEvents.d.ts.map +1 -0
- package/dist/sdk/utils/telemetry/telemetryEvents.js +243 -0
- package/dist/sdk/utils/telemetry/telemetryEvents.js.map +1 -0
- package/dist/sdk/utils/telemetry/telemetryRelay.d.ts +63 -0
- package/dist/sdk/utils/telemetry/telemetryRelay.d.ts.map +1 -0
- package/dist/sdk/utils/telemetry/telemetryRelay.js +64 -0
- package/dist/sdk/utils/telemetry/telemetryRelay.js.map +1 -0
- package/dist/sdk/webviewMessageTypes.d.ts +8 -0
- package/dist/sdk/webviewMessageTypes.d.ts.map +1 -1
- package/dist/sdk/webviewMessageTypes.js +8 -0
- package/dist/sdk/webviewMessageTypes.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryBuffer.js","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryBuffer.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAGzB,MAAM,sBAAsB,CAAC;AAgB9B,SAAS,SAAS,CAAC,IAAY,EAAE,UAAkC;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;SAClC,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7C,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACtC,CAAC;AAED,sFAAsF;AACtF,MAA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AC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,EAClD,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CACvD,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Schema and strict validator for the iframe -> host TELEMETRY_EVENT message.
|
|
9
|
+
*
|
|
10
|
+
* The payload mirrors `ITelemetry.sendEvent(name, properties, measurements)` so a
|
|
11
|
+
* host can forward a validated event without reshaping it. Every property value
|
|
12
|
+
* comes from a closed list and every measurement is a bounded integer, so a
|
|
13
|
+
* payload can never carry free-form text (prompt text, api names, paths, ids).
|
|
14
|
+
*
|
|
15
|
+
* Node-safe on purpose: no React, no CSS, no `window`. This module is exported
|
|
16
|
+
* from the React-free main barrel and is imported by hosts.
|
|
17
|
+
*/
|
|
18
|
+
export declare const TELEMETRY_SCHEMA_VERSION = 1;
|
|
19
|
+
export declare const TELEMETRY_EVENT_NAMES: readonly ["vibeEdit.selectMode", "vibeEdit.selection", "vibeEdit.promptAbandoned"];
|
|
20
|
+
export type TelemetryEventName = (typeof TELEMETRY_EVENT_NAMES)[number];
|
|
21
|
+
export declare const SELECT_MODE_ACTIONS: readonly ["enter", "exit"];
|
|
22
|
+
export type SelectModeAction = (typeof SELECT_MODE_ACTIONS)[number];
|
|
23
|
+
export declare const SELECTION_ACTIONS: readonly ["add", "remove"];
|
|
24
|
+
export type SelectionAction = (typeof SELECTION_ACTIONS)[number];
|
|
25
|
+
/**
|
|
26
|
+
* `SelectableNode.type` values emitted by the first-party plugins, plus the
|
|
27
|
+
* `'other'` fallback. Anything outside this list is bucketed to `'other'` by
|
|
28
|
+
* `toElementTypeBucket` (iframe side) and by `parseTelemetryEvent` (host side),
|
|
29
|
+
* so a third-party plugin's custom type, or a type added after this host shipped,
|
|
30
|
+
* is counted but never named.
|
|
31
|
+
*
|
|
32
|
+
* Keep in step with the plugins repo: Flow emits its `FlowNodeKind`, Permission
|
|
33
|
+
* set emits its named-access section keys, Agent emits the types below. Every
|
|
34
|
+
* entry adds up to two buckets per flush (add and remove), so the default of
|
|
35
|
+
* `TelemetryRateLimiter` must stay above `2 * SELECTION_ELEMENT_TYPES.length`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const SELECTION_ELEMENT_TYPES: readonly ["agent", "start-agent", "subagent", "topic", "system-instructions", "reasoning", "reasoning-action", "action", "action-target", "action-input", "action-output", "messages", "description", "heading", "step", "detail", "start", "screen", "apexAction", "apexPluginCall", "emailAction", "externalCallout", "routeWork", "addScreenPop", "addSkillRequirement", "checkAvailability", "setScreenProperty", "assignment", "addPromptInstructions", "decision", "loop", "recordCreate", "recordLookup", "recordUpdate", "recordDelete", "recordRollback", "subflow", "wait", "collectionProcessor", "collectionSort", "transform", "customError", "stage", "interactiveStep", "managedContentStep", "permissionset", "objectPermission", "fieldPermission", "recordTypeVisibility", "tabSetting", "apexClassAccesses", "pageAccesses", "flowAccesses", "agentAccesses", "customPermissions", "customMetadataTypeAccesses", "customSettingAccesses", "externalDataSourceAccesses", "externalCredentialPrincipalAccesses", "servicePresenceStatusAccesses", "emailRoutingAddressAccesses", "genComputingSummaryDefAccesses", "userPermissions", "applicationVisibilities", "object", "field", "region", "block", "dataProvider", "other"];
|
|
38
|
+
export type SelectionElementType = (typeof SELECTION_ELEMENT_TYPES)[number];
|
|
39
|
+
export declare const BOOLEAN_STRINGS: readonly ["true", "false"];
|
|
40
|
+
/** Upper bound for every count measurement. */
|
|
41
|
+
export declare const MAX_TELEMETRY_COUNT = 10000;
|
|
42
|
+
export interface TelemetryEventPayload {
|
|
43
|
+
schemaVersion: typeof TELEMETRY_SCHEMA_VERSION;
|
|
44
|
+
name: TelemetryEventName;
|
|
45
|
+
properties: Record<string, string>;
|
|
46
|
+
measurements: Record<string, number>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Strict host-side check of an iframe TELEMETRY_EVENT payload. Returns a fresh,
|
|
50
|
+
* validated copy, or null. Nothing is coerced except a string `elementType`
|
|
51
|
+
* outside the closed list, which becomes `'other'` (the schema's `fallbacks`), so
|
|
52
|
+
* the copy still only holds closed-list values. Any other deviation from the
|
|
53
|
+
* schema (unknown name, extra or missing key, out-of-list value, non-string
|
|
54
|
+
* value, non-integer or out-of-range measurement) is rejected. Never throws, even
|
|
55
|
+
* on hostile input (proxies, throwing getters).
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseTelemetryEvent(value: unknown): TelemetryEventPayload | null;
|
|
58
|
+
/** Emitter side: map any element type to a closed bucket (unknown -> 'other'). */
|
|
59
|
+
export declare function toElementTypeBucket(type: string): SelectionElementType;
|
|
60
|
+
//# sourceMappingURL=telemetryEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryEvents.d.ts","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryEvents.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,eAAO,MAAM,qBAAqB,oFAIxB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,mBAAmB,4BAA6B,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,iBAAiB,4BAA6B,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,krCA6E1B,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,eAAO,MAAM,eAAe,4BAA6B,CAAC;AAE1D,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,OAAO,wBAAwB,CAAC;IAC/C,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAwED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,GAAG,IAAI,CAgEhF;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAItE"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Schema and strict validator for the iframe -> host TELEMETRY_EVENT message.
|
|
9
|
+
*
|
|
10
|
+
* The payload mirrors `ITelemetry.sendEvent(name, properties, measurements)` so a
|
|
11
|
+
* host can forward a validated event without reshaping it. Every property value
|
|
12
|
+
* comes from a closed list and every measurement is a bounded integer, so a
|
|
13
|
+
* payload can never carry free-form text (prompt text, api names, paths, ids).
|
|
14
|
+
*
|
|
15
|
+
* Node-safe on purpose: no React, no CSS, no `window`. This module is exported
|
|
16
|
+
* from the React-free main barrel and is imported by hosts.
|
|
17
|
+
*/
|
|
18
|
+
export const TELEMETRY_SCHEMA_VERSION = 1;
|
|
19
|
+
export const TELEMETRY_EVENT_NAMES = [
|
|
20
|
+
'vibeEdit.selectMode',
|
|
21
|
+
'vibeEdit.selection',
|
|
22
|
+
'vibeEdit.promptAbandoned',
|
|
23
|
+
];
|
|
24
|
+
export const SELECT_MODE_ACTIONS = ['enter', 'exit'];
|
|
25
|
+
export const SELECTION_ACTIONS = ['add', 'remove'];
|
|
26
|
+
/**
|
|
27
|
+
* `SelectableNode.type` values emitted by the first-party plugins, plus the
|
|
28
|
+
* `'other'` fallback. Anything outside this list is bucketed to `'other'` by
|
|
29
|
+
* `toElementTypeBucket` (iframe side) and by `parseTelemetryEvent` (host side),
|
|
30
|
+
* so a third-party plugin's custom type, or a type added after this host shipped,
|
|
31
|
+
* is counted but never named.
|
|
32
|
+
*
|
|
33
|
+
* Keep in step with the plugins repo: Flow emits its `FlowNodeKind`, Permission
|
|
34
|
+
* set emits its named-access section keys, Agent emits the types below. Every
|
|
35
|
+
* entry adds up to two buckets per flush (add and remove), so the default of
|
|
36
|
+
* `TelemetryRateLimiter` must stay above `2 * SELECTION_ELEMENT_TYPES.length`.
|
|
37
|
+
*/
|
|
38
|
+
export const SELECTION_ELEMENT_TYPES = [
|
|
39
|
+
// Agent
|
|
40
|
+
'agent',
|
|
41
|
+
'start-agent',
|
|
42
|
+
'subagent',
|
|
43
|
+
'topic',
|
|
44
|
+
'system-instructions',
|
|
45
|
+
'reasoning',
|
|
46
|
+
'reasoning-action',
|
|
47
|
+
'action',
|
|
48
|
+
'action-target',
|
|
49
|
+
'action-input',
|
|
50
|
+
'action-output',
|
|
51
|
+
'messages',
|
|
52
|
+
'description',
|
|
53
|
+
'heading',
|
|
54
|
+
// Flow (rows and stage steps, then FlowNodeKind minus the non-selectable end/group)
|
|
55
|
+
'step',
|
|
56
|
+
'detail',
|
|
57
|
+
'start',
|
|
58
|
+
'screen',
|
|
59
|
+
'apexAction',
|
|
60
|
+
'apexPluginCall',
|
|
61
|
+
'emailAction',
|
|
62
|
+
'externalCallout',
|
|
63
|
+
'routeWork',
|
|
64
|
+
'addScreenPop',
|
|
65
|
+
'addSkillRequirement',
|
|
66
|
+
'checkAvailability',
|
|
67
|
+
'setScreenProperty',
|
|
68
|
+
'assignment',
|
|
69
|
+
'addPromptInstructions',
|
|
70
|
+
'decision',
|
|
71
|
+
'loop',
|
|
72
|
+
'recordCreate',
|
|
73
|
+
'recordLookup',
|
|
74
|
+
'recordUpdate',
|
|
75
|
+
'recordDelete',
|
|
76
|
+
'recordRollback',
|
|
77
|
+
'subflow',
|
|
78
|
+
'wait',
|
|
79
|
+
'collectionProcessor',
|
|
80
|
+
'collectionSort',
|
|
81
|
+
'transform',
|
|
82
|
+
'customError',
|
|
83
|
+
'stage',
|
|
84
|
+
'interactiveStep',
|
|
85
|
+
'managedContentStep',
|
|
86
|
+
// Permission set
|
|
87
|
+
'permissionset',
|
|
88
|
+
'objectPermission',
|
|
89
|
+
'fieldPermission',
|
|
90
|
+
'recordTypeVisibility',
|
|
91
|
+
'tabSetting',
|
|
92
|
+
'apexClassAccesses',
|
|
93
|
+
'pageAccesses',
|
|
94
|
+
'flowAccesses',
|
|
95
|
+
'agentAccesses',
|
|
96
|
+
'customPermissions',
|
|
97
|
+
'customMetadataTypeAccesses',
|
|
98
|
+
'customSettingAccesses',
|
|
99
|
+
'externalDataSourceAccesses',
|
|
100
|
+
'externalCredentialPrincipalAccesses',
|
|
101
|
+
'servicePresenceStatusAccesses',
|
|
102
|
+
'emailRoutingAddressAccesses',
|
|
103
|
+
'genComputingSummaryDefAccesses',
|
|
104
|
+
'userPermissions',
|
|
105
|
+
'applicationVisibilities',
|
|
106
|
+
// Schema
|
|
107
|
+
'object',
|
|
108
|
+
'field',
|
|
109
|
+
// Flexipage
|
|
110
|
+
'region',
|
|
111
|
+
'block',
|
|
112
|
+
'dataProvider',
|
|
113
|
+
// Fallback
|
|
114
|
+
'other',
|
|
115
|
+
];
|
|
116
|
+
export const BOOLEAN_STRINGS = ['true', 'false'];
|
|
117
|
+
/** Upper bound for every count measurement. */
|
|
118
|
+
export const MAX_TELEMETRY_COUNT = 10000;
|
|
119
|
+
/** One table drives both the emitters' type buckets and the host validator. */
|
|
120
|
+
const SCHEMA = {
|
|
121
|
+
'vibeEdit.selectMode': {
|
|
122
|
+
properties: { action: SELECT_MODE_ACTIONS },
|
|
123
|
+
measurements: {},
|
|
124
|
+
},
|
|
125
|
+
'vibeEdit.selection': {
|
|
126
|
+
properties: { action: SELECTION_ACTIONS, elementType: SELECTION_ELEMENT_TYPES },
|
|
127
|
+
measurements: { count: { min: 1, max: MAX_TELEMETRY_COUNT } },
|
|
128
|
+
fallbacks: { elementType: 'other' },
|
|
129
|
+
},
|
|
130
|
+
'vibeEdit.promptAbandoned': {
|
|
131
|
+
properties: { hadText: BOOLEAN_STRINGS },
|
|
132
|
+
measurements: { attachmentCount: { min: 0, max: MAX_TELEMETRY_COUNT } },
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
const EVENT_NAME_SET = new Set(TELEMETRY_EVENT_NAMES);
|
|
136
|
+
const ELEMENT_TYPE_SET = new Set(SELECTION_ELEMENT_TYPES);
|
|
137
|
+
const TOP_LEVEL_KEYS = ['schemaVersion', 'name', 'properties', 'measurements'];
|
|
138
|
+
function isPlainObject(value) {
|
|
139
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const prototype = Reflect.getPrototypeOf(value);
|
|
143
|
+
return prototype === Object.prototype || prototype === null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Snapshot of an object's own data properties, or null unless its keys are
|
|
147
|
+
* exactly `allowed`. Accessor properties and symbol keys are rejected, so the
|
|
148
|
+
* validated values cannot change between the check and the use.
|
|
149
|
+
*/
|
|
150
|
+
function snapshotExactKeys(value, allowed) {
|
|
151
|
+
const keys = Reflect.ownKeys(value);
|
|
152
|
+
if (keys.length !== allowed.length) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const snapshot = {};
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
if (typeof key !== 'string' || !allowed.includes(key)) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
|
|
161
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
snapshot[key] = descriptor.value;
|
|
165
|
+
}
|
|
166
|
+
return snapshot;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Strict host-side check of an iframe TELEMETRY_EVENT payload. Returns a fresh,
|
|
170
|
+
* validated copy, or null. Nothing is coerced except a string `elementType`
|
|
171
|
+
* outside the closed list, which becomes `'other'` (the schema's `fallbacks`), so
|
|
172
|
+
* the copy still only holds closed-list values. Any other deviation from the
|
|
173
|
+
* schema (unknown name, extra or missing key, out-of-list value, non-string
|
|
174
|
+
* value, non-integer or out-of-range measurement) is rejected. Never throws, even
|
|
175
|
+
* on hostile input (proxies, throwing getters).
|
|
176
|
+
*/
|
|
177
|
+
export function parseTelemetryEvent(value) {
|
|
178
|
+
try {
|
|
179
|
+
if (!isPlainObject(value)) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const top = snapshotExactKeys(value, TOP_LEVEL_KEYS);
|
|
183
|
+
if (!top || top.schemaVersion !== TELEMETRY_SCHEMA_VERSION) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const name = top.name;
|
|
187
|
+
if (typeof name !== 'string' || !EVENT_NAME_SET.has(name)) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const schema = SCHEMA[name];
|
|
191
|
+
if (!isPlainObject(top.properties) || !isPlainObject(top.measurements)) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const properties = snapshotExactKeys(top.properties, Object.keys(schema.properties));
|
|
195
|
+
const measurements = snapshotExactKeys(top.measurements, Object.keys(schema.measurements));
|
|
196
|
+
if (!properties || !measurements) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const cleanProperties = {};
|
|
200
|
+
for (const [key, allowedValues] of Object.entries(schema.properties)) {
|
|
201
|
+
const propertyValue = properties[key];
|
|
202
|
+
if (typeof propertyValue !== 'string') {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (allowedValues.includes(propertyValue)) {
|
|
206
|
+
cleanProperties[key] = propertyValue;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const fallback = schema.fallbacks?.[key];
|
|
210
|
+
if (fallback === undefined) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
cleanProperties[key] = fallback;
|
|
214
|
+
}
|
|
215
|
+
const cleanMeasurements = {};
|
|
216
|
+
for (const [key, range] of Object.entries(schema.measurements)) {
|
|
217
|
+
const measurementValue = measurements[key];
|
|
218
|
+
if (typeof measurementValue !== 'number' ||
|
|
219
|
+
!Number.isInteger(measurementValue) ||
|
|
220
|
+
measurementValue < range.min ||
|
|
221
|
+
measurementValue > range.max) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
cleanMeasurements[key] = measurementValue;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
schemaVersion: TELEMETRY_SCHEMA_VERSION,
|
|
228
|
+
name: name,
|
|
229
|
+
properties: cleanProperties,
|
|
230
|
+
measurements: cleanMeasurements,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Emitter side: map any element type to a closed bucket (unknown -> 'other'). */
|
|
238
|
+
export function toElementTypeBucket(type) {
|
|
239
|
+
return typeof type === 'string' && ELEMENT_TYPE_SET.has(type)
|
|
240
|
+
? type
|
|
241
|
+
: 'other';
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=telemetryEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryEvents.js","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryEvents.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,qBAAqB;IACrB,oBAAoB;IACpB,0BAA0B;CAClB,CAAC;AAGX,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAC;AAG9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;AAG5D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,QAAQ;IACR,OAAO;IACP,aAAa;IACb,UAAU;IACV,OAAO;IACP,qBAAqB;IACrB,WAAW;IACX,kBAAkB;IAClB,QAAQ;IACR,eAAe;IACf,cAAc;IACd,eAAe;IACf,UAAU;IACV,aAAa;IACb,SAAS;IACT,oFAAoF;IACpF,MAAM;IACN,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,gBAAgB;IAChB,aAAa;IACb,iBAAiB;IACjB,WAAW;IACX,cAAc;IACd,qBAAqB;IACrB,mBAAmB;IACnB,mBAAmB;IACnB,YAAY;IACZ,uBAAuB;IACvB,UAAU;IACV,MAAM;IACN,cAAc;IACd,cAAc;IACd,cAAc;IACd,cAAc;IACd,gBAAgB;IAChB,SAAS;IACT,MAAM;IACN,qBAAqB;IACrB,gBAAgB;IAChB,WAAW;IACX,aAAa;IACb,OAAO;IACP,iBAAiB;IACjB,oBAAoB;IACpB,iBAAiB;IACjB,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,sB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;AACd,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Host-side relay for the iframe TELEMETRY_EVENT message.
|
|
9
|
+
*
|
|
10
|
+
* The iframe is host-agnostic: it emits the same events whether it runs in VS
|
|
11
|
+
* Code, Builder Central or any other embedder. Each host turns those events into
|
|
12
|
+
* analytics by passing the received payload to `relayTelemetryEvent` with its own
|
|
13
|
+
* `ITelemetry`-shaped sink, so the rules (rate limit, strict validation, host
|
|
14
|
+
* attribution that the iframe cannot override) live here in tested code instead of
|
|
15
|
+
* being re-implemented per host.
|
|
16
|
+
*
|
|
17
|
+
* Node-safe and free of `window`, so any host runtime can import it.
|
|
18
|
+
*/
|
|
19
|
+
import type { ITelemetry } from '../../abstractions/services/ITelemetry.js';
|
|
20
|
+
/** The part of `ITelemetry` the relay needs. */
|
|
21
|
+
export type TelemetrySink = Pick<ITelemetry, 'sendEvent'>;
|
|
22
|
+
export type RelayResult = 'forwarded' | 'invalid' | 'rate_limited';
|
|
23
|
+
/**
|
|
24
|
+
* Sliding-window rate limiter. A host creates one per render target (VS Code) or
|
|
25
|
+
* per iframe (browser hosts) so a misbehaving page cannot flood the sink.
|
|
26
|
+
*
|
|
27
|
+
* The default of 300 per minute leaves room for the worst-case selection flush,
|
|
28
|
+
* which emits one bucket per (add/remove, element type) pair, plus the
|
|
29
|
+
* select-mode and abandon events around it. A single iframe renders one plugin,
|
|
30
|
+
* so a real flush is well below the worst case; the headroom covers a few flushes
|
|
31
|
+
* inside one window (leaving select mode, page hide, the 20 second timer).
|
|
32
|
+
*/
|
|
33
|
+
export declare class TelemetryRateLimiter {
|
|
34
|
+
private readonly maxEvents;
|
|
35
|
+
private readonly windowMs;
|
|
36
|
+
private readonly now;
|
|
37
|
+
private readonly timestamps;
|
|
38
|
+
constructor(maxEvents?: number, windowMs?: number, now?: () => number);
|
|
39
|
+
/** Returns false once the budget for the current window is spent. */
|
|
40
|
+
tryAcquire(): boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface RelayTelemetryOptions {
|
|
43
|
+
/** Where validated events go, typically the host's `ITelemetry`. */
|
|
44
|
+
sink: TelemetrySink;
|
|
45
|
+
/**
|
|
46
|
+
* Properties the host derives from its own state (for example `pluginId`).
|
|
47
|
+
* Spread last, so a host value always wins over anything from the iframe.
|
|
48
|
+
*/
|
|
49
|
+
hostProperties: Record<string, string>;
|
|
50
|
+
/** Rate limit applied before the payload is parsed. Hosts should pass one. */
|
|
51
|
+
limiter?: TelemetryRateLimiter;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates an iframe TELEMETRY_EVENT payload and forwards it to the host's sink.
|
|
55
|
+
*
|
|
56
|
+
* Order: rate limit, then `parseTelemetryEvent`, then
|
|
57
|
+
* `sink.sendEvent(name, { ...properties, ...hostProperties }, measurements)`.
|
|
58
|
+
* Never throws: a sink that throws is swallowed and reported as `'invalid'`. The
|
|
59
|
+
* relay does not log; the caller decides what to log from the result. Never echo
|
|
60
|
+
* anything back to the iframe.
|
|
61
|
+
*/
|
|
62
|
+
export declare function relayTelemetryEvent(payload: unknown, options: RelayTelemetryOptions): RelayResult;
|
|
63
|
+
//# sourceMappingURL=telemetryRelay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryRelay.d.ts","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryRelay.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AAG5E,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,cAAc,CAAC;AAEnE;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAI7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;gBAGxB,SAAS,GAAE,MAAY,EACvB,QAAQ,GAAE,MAAe,EACzB,GAAG,GAAE,MAAM,MAAiB;IAG/C,qEAAqE;IACrE,UAAU,IAAI,OAAO;CAYtB;AAED,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,IAAI,EAAE,aAAa,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,8EAA8E;IAC9E,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,qBAAqB,GAAG,WAAW,CAkBjG"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
**/
|
|
7
|
+
import { parseTelemetryEvent } from './telemetryEvents.js';
|
|
8
|
+
/**
|
|
9
|
+
* Sliding-window rate limiter. A host creates one per render target (VS Code) or
|
|
10
|
+
* per iframe (browser hosts) so a misbehaving page cannot flood the sink.
|
|
11
|
+
*
|
|
12
|
+
* The default of 300 per minute leaves room for the worst-case selection flush,
|
|
13
|
+
* which emits one bucket per (add/remove, element type) pair, plus the
|
|
14
|
+
* select-mode and abandon events around it. A single iframe renders one plugin,
|
|
15
|
+
* so a real flush is well below the worst case; the headroom covers a few flushes
|
|
16
|
+
* inside one window (leaving select mode, page hide, the 20 second timer).
|
|
17
|
+
*/
|
|
18
|
+
export class TelemetryRateLimiter {
|
|
19
|
+
constructor(maxEvents = 300, windowMs = 60000, now = Date.now) {
|
|
20
|
+
this.maxEvents = maxEvents;
|
|
21
|
+
this.windowMs = windowMs;
|
|
22
|
+
this.now = now;
|
|
23
|
+
this.timestamps = [];
|
|
24
|
+
}
|
|
25
|
+
/** Returns false once the budget for the current window is spent. */
|
|
26
|
+
tryAcquire() {
|
|
27
|
+
const now = this.now();
|
|
28
|
+
const windowStart = now - this.windowMs;
|
|
29
|
+
while (this.timestamps.length > 0 && this.timestamps[0] <= windowStart) {
|
|
30
|
+
this.timestamps.shift();
|
|
31
|
+
}
|
|
32
|
+
if (this.timestamps.length >= this.maxEvents) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
this.timestamps.push(now);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validates an iframe TELEMETRY_EVENT payload and forwards it to the host's sink.
|
|
41
|
+
*
|
|
42
|
+
* Order: rate limit, then `parseTelemetryEvent`, then
|
|
43
|
+
* `sink.sendEvent(name, { ...properties, ...hostProperties }, measurements)`.
|
|
44
|
+
* Never throws: a sink that throws is swallowed and reported as `'invalid'`. The
|
|
45
|
+
* relay does not log; the caller decides what to log from the result. Never echo
|
|
46
|
+
* anything back to the iframe.
|
|
47
|
+
*/
|
|
48
|
+
export function relayTelemetryEvent(payload, options) {
|
|
49
|
+
try {
|
|
50
|
+
if (options.limiter && !options.limiter.tryAcquire()) {
|
|
51
|
+
return 'rate_limited';
|
|
52
|
+
}
|
|
53
|
+
const event = parseTelemetryEvent(payload);
|
|
54
|
+
if (!event) {
|
|
55
|
+
return 'invalid';
|
|
56
|
+
}
|
|
57
|
+
options.sink.sendEvent(event.name, { ...event.properties, ...options.hostProperties }, event.measurements);
|
|
58
|
+
return 'forwarded';
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return 'invalid';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=telemetryRelay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryRelay.js","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryRelay.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAgBJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAO3D;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IAG/B,YACmB,YAAoB,GAAG,EACvB,WAAmB,KAAM,EACzB,MAAoB,IAAI,CAAC,GAAG;QAF5B,cAAS,GAAT,SAAS,CAAc;QACvB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,QAAG,GAAH,GAAG,CAAyB;QAL9B,eAAU,GAAa,EAAE,CAAC;IAMxC,CAAC;IAEJ,qEAAqE;IACrE,UAAU;QACR,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;YACvE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAcD;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,OAA8B;IAClF,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;YACrD,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,MAAM,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,SAAS,CACpB,KAAK,CAAC,IAAI,EACV,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,EAClD,KAAK,CAAC,YAAY,CACnB,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -35,6 +35,14 @@ export declare const WebviewMessageType: {
|
|
|
35
35
|
readonly SUBMIT_EDIT: "SUBMIT_EDIT";
|
|
36
36
|
/** Host reports the outcome of a correlated VS Code edit submission. */
|
|
37
37
|
readonly SUBMIT_EDIT_RESULT: "SUBMIT_EDIT_RESULT";
|
|
38
|
+
/**
|
|
39
|
+
* Plugin reports an anonymous, aggregate usage event to the host (payload:
|
|
40
|
+
* TelemetryEventPayload, see utils/telemetry). Fire-and-forget: the host never
|
|
41
|
+
* replies. The host MUST validate the payload (relayTelemetryEvent /
|
|
42
|
+
* parseTelemetryEvent) and add its own attribution such as `pluginId`; the
|
|
43
|
+
* plugin never sends one.
|
|
44
|
+
*/
|
|
45
|
+
readonly TELEMETRY_EVENT: "TELEMETRY_EVENT";
|
|
38
46
|
};
|
|
39
47
|
export type WebviewMessageTypeValue = (typeof WebviewMessageType)[keyof typeof WebviewMessageType];
|
|
40
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webviewMessageTypes.d.ts","sourceRoot":"","sources":["../../src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cAAc,GAAG,MAAM,CAAC;IACjC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,aAAqD,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -30,6 +30,14 @@ export const WebviewMessageType = {
|
|
|
30
30
|
SUBMIT_EDIT: 'SUBMIT_EDIT',
|
|
31
31
|
/** Host reports the outcome of a correlated VS Code edit submission. */
|
|
32
32
|
SUBMIT_EDIT_RESULT: 'SUBMIT_EDIT_RESULT',
|
|
33
|
+
/**
|
|
34
|
+
* Plugin reports an anonymous, aggregate usage event to the host (payload:
|
|
35
|
+
* TelemetryEventPayload, see utils/telemetry). Fire-and-forget: the host never
|
|
36
|
+
* replies. The host MUST validate the payload (relayTelemetryEvent /
|
|
37
|
+
* parseTelemetryEvent) and add its own attribution such as `pluginId`; the
|
|
38
|
+
* plugin never sends one.
|
|
39
|
+
*/
|
|
40
|
+
TELEMETRY_EVENT: 'TELEMETRY_EVENT',
|
|
33
41
|
};
|
|
34
42
|
/** Set of all valid message types for whitelist validation */
|
|
35
43
|
export const VALID_MESSAGE_TYPES = new Set(Object.values(WebviewMessageType));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webviewMessageTypes.js","sourceRoot":"","sources":["../../src/sdk/webviewMessageTypes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