@symbo.ls/sdk 3.2.3 → 3.2.7
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 +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var TrackingService_exports = {};
|
|
29
|
+
__export(TrackingService_exports, {
|
|
30
|
+
TrackingService: () => TrackingService
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(TrackingService_exports);
|
|
33
|
+
var import_BaseService = require("./BaseService.js");
|
|
34
|
+
var import_environment = __toESM(require("../config/environment.js"), 1);
|
|
35
|
+
const DEFAULT_MAX_QUEUE_SIZE = 100;
|
|
36
|
+
const isBrowserEnvironment = () => typeof window !== "undefined";
|
|
37
|
+
const DEFAULT_TRACKING_OPTIONS = {
|
|
38
|
+
// Enabled by default unless explicitly disabled via SDK options or runtime config
|
|
39
|
+
enabled: true,
|
|
40
|
+
sessionTracking: true,
|
|
41
|
+
enableTracing: true,
|
|
42
|
+
maxQueueSize: DEFAULT_MAX_QUEUE_SIZE,
|
|
43
|
+
transports: null,
|
|
44
|
+
instrumentations: null,
|
|
45
|
+
instrumentationsFactory: null,
|
|
46
|
+
webInstrumentationOptions: null,
|
|
47
|
+
globalAttributes: {},
|
|
48
|
+
transport: null,
|
|
49
|
+
user: null
|
|
50
|
+
};
|
|
51
|
+
const sanitizeAttributes = (value) => {
|
|
52
|
+
if (!value || typeof value !== "object") {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(JSON.stringify(value));
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.warn("[TrackingService] Failed to sanitize attributes:", error);
|
|
59
|
+
return { ...value };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
class TrackingService extends import_BaseService.BaseService {
|
|
63
|
+
constructor({ context, options } = {}) {
|
|
64
|
+
super({ context, options });
|
|
65
|
+
this._faroClient = null;
|
|
66
|
+
this._queue = [];
|
|
67
|
+
this._initialized = false;
|
|
68
|
+
this._enabled = DEFAULT_TRACKING_OPTIONS.enabled;
|
|
69
|
+
this._runtimeConfig = {};
|
|
70
|
+
this._setupPromise = null;
|
|
71
|
+
this._trackingOptions = {
|
|
72
|
+
...DEFAULT_TRACKING_OPTIONS,
|
|
73
|
+
...(options == null ? void 0 : options.tracking) || {}
|
|
74
|
+
};
|
|
75
|
+
this._globalAttributes = sanitizeAttributes(
|
|
76
|
+
this._trackingOptions.globalAttributes || {}
|
|
77
|
+
);
|
|
78
|
+
this._trackingOptions.globalAttributes = { ...this._globalAttributes };
|
|
79
|
+
}
|
|
80
|
+
async init({ context = {}, options = {} } = {}) {
|
|
81
|
+
var _a;
|
|
82
|
+
this.updateContext(context);
|
|
83
|
+
this._trackingOptions = {
|
|
84
|
+
...DEFAULT_TRACKING_OPTIONS,
|
|
85
|
+
...this._trackingOptions,
|
|
86
|
+
...((_a = this._options) == null ? void 0 : _a.tracking) || {},
|
|
87
|
+
...options.tracking || {}
|
|
88
|
+
};
|
|
89
|
+
this._globalAttributes = sanitizeAttributes(
|
|
90
|
+
this._trackingOptions.globalAttributes || {}
|
|
91
|
+
);
|
|
92
|
+
this._enabled = this._trackingOptions.enabled !== false;
|
|
93
|
+
if (!this._enabled) {
|
|
94
|
+
this._setReady();
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
if (!isBrowserEnvironment()) {
|
|
98
|
+
this._enabled = false;
|
|
99
|
+
this._setReady();
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
this._runtimeConfig = this._buildRuntimeConfig();
|
|
103
|
+
this._trackingOptions.transports = this._runtimeConfig.transports;
|
|
104
|
+
const hasCustomTransports = Array.isArray(this._runtimeConfig.transports) && this._runtimeConfig.transports.length > 0;
|
|
105
|
+
if (!this._runtimeConfig.url && !hasCustomTransports) {
|
|
106
|
+
console.warn("[TrackingService] Grafana Faro URL missing. Tracking will stay disabled.");
|
|
107
|
+
this._enabled = false;
|
|
108
|
+
this._setReady();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
if (this._initialized) {
|
|
112
|
+
this._setReady();
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
if (!this._setupPromise) {
|
|
116
|
+
this._setupPromise = this._loadFaroClient(this._runtimeConfig);
|
|
117
|
+
}
|
|
118
|
+
await this._setupPromise;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
updateContext(context) {
|
|
122
|
+
super.updateContext(context);
|
|
123
|
+
const trackingContext = context == null ? void 0 : context.tracking;
|
|
124
|
+
if (trackingContext) {
|
|
125
|
+
if (Object.hasOwn(trackingContext, "user")) {
|
|
126
|
+
this.setUser(trackingContext.user, { queue: false });
|
|
127
|
+
}
|
|
128
|
+
if (Object.hasOwn(trackingContext, "globalAttributes")) {
|
|
129
|
+
this.setGlobalAttributes(trackingContext.globalAttributes);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
configureTracking(trackingOptions = {}) {
|
|
134
|
+
if (!trackingOptions || typeof trackingOptions !== "object") {
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
this._trackingOptions = {
|
|
138
|
+
...this._trackingOptions,
|
|
139
|
+
...trackingOptions
|
|
140
|
+
};
|
|
141
|
+
if (Object.hasOwn(trackingOptions, "globalAttributes")) {
|
|
142
|
+
this.setGlobalAttributes(trackingOptions.globalAttributes);
|
|
143
|
+
}
|
|
144
|
+
if (Object.hasOwn(trackingOptions, "user")) {
|
|
145
|
+
this.setUser(trackingOptions.user);
|
|
146
|
+
this._trackingOptions.user = trackingOptions.user;
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
configure(trackingOptions = {}) {
|
|
151
|
+
return this.configureTracking(trackingOptions);
|
|
152
|
+
}
|
|
153
|
+
trackEvent(name, attributes, options = {}) {
|
|
154
|
+
if (!name) {
|
|
155
|
+
throw new Error("Event name is required for trackEvent");
|
|
156
|
+
}
|
|
157
|
+
const mergedAttributes = this._mergeAttributes(attributes);
|
|
158
|
+
const eventOptions = options && typeof options === "object" ? options : {};
|
|
159
|
+
const { domain, queue, ...restOptions } = eventOptions;
|
|
160
|
+
const eventDomain = Object.hasOwn(eventOptions, "domain") ? domain : null;
|
|
161
|
+
const invokeTracking = (client) => {
|
|
162
|
+
const api = client == null ? void 0 : client.api;
|
|
163
|
+
if (!(api == null ? void 0 : api.pushEvent)) {
|
|
164
|
+
console.warn("[TrackingService] Faro pushEvent API not available");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
api.pushEvent(name, mergedAttributes, eventDomain, restOptions);
|
|
168
|
+
};
|
|
169
|
+
if (Object.hasOwn(eventOptions, "queue")) {
|
|
170
|
+
this._withClient(invokeTracking, { queue: Boolean(queue) });
|
|
171
|
+
} else {
|
|
172
|
+
this._withClient(invokeTracking);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
trackError(error, options = {}) {
|
|
176
|
+
if (!error) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const err = error instanceof Error ? error : new Error(
|
|
180
|
+
typeof error === "string" ? error : "Unknown error captured by TrackingService"
|
|
181
|
+
);
|
|
182
|
+
const isContextOnly = options && typeof options === "object" && options !== null && !("context" in options || "type" in options || "stackFrames" in options || "skipDedupe" in options || "spanContext" in options || "timestampOverwriteMs" in options || "originalError" in options);
|
|
183
|
+
const normalizedOptions = isContextOnly ? { context: options } : options || {};
|
|
184
|
+
const mergedContext = this._mergeAttributes(normalizedOptions.context);
|
|
185
|
+
const apiOptions = {
|
|
186
|
+
...normalizedOptions,
|
|
187
|
+
...Object.keys(mergedContext).length > 0 ? { context: mergedContext } : {}
|
|
188
|
+
};
|
|
189
|
+
const queueConfigured = Object.hasOwn(apiOptions, "queue");
|
|
190
|
+
const { queue, ...errorOptions } = apiOptions;
|
|
191
|
+
const invokeTracking = (client) => {
|
|
192
|
+
const api = client == null ? void 0 : client.api;
|
|
193
|
+
if (!(api == null ? void 0 : api.pushError)) {
|
|
194
|
+
console.warn("[TrackingService] Faro pushError API not available");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
api.pushError(err, errorOptions);
|
|
198
|
+
};
|
|
199
|
+
if (queueConfigured) {
|
|
200
|
+
this._withClient(invokeTracking, { queue: Boolean(queue) });
|
|
201
|
+
} else {
|
|
202
|
+
this._withClient(invokeTracking);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
captureException(error, options = {}) {
|
|
206
|
+
this.trackError(error, options);
|
|
207
|
+
}
|
|
208
|
+
logMessage(message, level = "info", context = null) {
|
|
209
|
+
if (!message) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const payload = Array.isArray(message) ? message : [message];
|
|
213
|
+
const logContext = this._mergeAttributes(context);
|
|
214
|
+
const severity = level || "info";
|
|
215
|
+
const options = {
|
|
216
|
+
level: severity,
|
|
217
|
+
...Object.keys(logContext).length > 0 ? { context: logContext } : {}
|
|
218
|
+
};
|
|
219
|
+
this._withClient((client) => {
|
|
220
|
+
const api = client == null ? void 0 : client.api;
|
|
221
|
+
if (!(api == null ? void 0 : api.pushLog)) {
|
|
222
|
+
console.warn("[TrackingService] Faro pushLog API not available");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
api.pushLog(payload, options);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
logDebug(message, context) {
|
|
229
|
+
this.logMessage(message, "debug", context);
|
|
230
|
+
}
|
|
231
|
+
logInfo(message, context) {
|
|
232
|
+
this.logMessage(message, "info", context);
|
|
233
|
+
}
|
|
234
|
+
logWarning(message, context) {
|
|
235
|
+
this.logMessage(message, "warn", context);
|
|
236
|
+
}
|
|
237
|
+
logWarn(message, context) {
|
|
238
|
+
this.logWarning(message, context);
|
|
239
|
+
}
|
|
240
|
+
logErrorMessage(message, context) {
|
|
241
|
+
this.logMessage(message, "error", context);
|
|
242
|
+
}
|
|
243
|
+
logError(message, context) {
|
|
244
|
+
this.logErrorMessage(message, context);
|
|
245
|
+
}
|
|
246
|
+
addBreadcrumb(message, attributes) {
|
|
247
|
+
if (!message) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const breadcrumbAttributes = {
|
|
251
|
+
category: "custom",
|
|
252
|
+
...sanitizeAttributes(attributes || {}),
|
|
253
|
+
message
|
|
254
|
+
};
|
|
255
|
+
this.trackEvent("breadcrumb", breadcrumbAttributes);
|
|
256
|
+
}
|
|
257
|
+
trackMeasurement(type, values, options = {}) {
|
|
258
|
+
if (!type) {
|
|
259
|
+
throw new Error("Measurement type is required for trackMeasurement");
|
|
260
|
+
}
|
|
261
|
+
if (values == null) {
|
|
262
|
+
throw new Error("Measurement values are required for trackMeasurement");
|
|
263
|
+
}
|
|
264
|
+
const measurementValues = typeof values === "object" && !Array.isArray(values) ? sanitizeAttributes(values) : { value: Number(values) };
|
|
265
|
+
if (typeof measurementValues.value === "number" && Number.isNaN(measurementValues.value)) {
|
|
266
|
+
throw new Error("Measurement value must be a valid number");
|
|
267
|
+
}
|
|
268
|
+
const measurementOptions = options && typeof options === "object" ? options : {};
|
|
269
|
+
const {
|
|
270
|
+
attributes: measurementAttributesOption,
|
|
271
|
+
context: measurementContextOption,
|
|
272
|
+
queue,
|
|
273
|
+
...transportOptions
|
|
274
|
+
} = measurementOptions;
|
|
275
|
+
const hasGlobalAttributes = Object.keys(this._globalAttributes).length > 0;
|
|
276
|
+
const attributePayload = measurementAttributesOption ? this._mergeAttributes(measurementAttributesOption) : hasGlobalAttributes ? { ...this._globalAttributes } : {};
|
|
277
|
+
const payload = {
|
|
278
|
+
type,
|
|
279
|
+
values: measurementValues,
|
|
280
|
+
...attributePayload && Object.keys(attributePayload).length > 0 ? { attributes: attributePayload } : {}
|
|
281
|
+
};
|
|
282
|
+
const context = measurementContextOption ? this._mergeAttributes(measurementContextOption) : hasGlobalAttributes ? { ...this._globalAttributes } : {};
|
|
283
|
+
const apiOptions = {
|
|
284
|
+
...transportOptions,
|
|
285
|
+
...Object.keys(context).length > 0 ? { context } : {}
|
|
286
|
+
};
|
|
287
|
+
const invokeTracking = (client) => {
|
|
288
|
+
const api = client == null ? void 0 : client.api;
|
|
289
|
+
if (!(api == null ? void 0 : api.pushMeasurement)) {
|
|
290
|
+
console.warn("[TrackingService] Faro pushMeasurement API not available");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
api.pushMeasurement(payload, apiOptions);
|
|
294
|
+
};
|
|
295
|
+
if (Object.hasOwn(measurementOptions, "queue")) {
|
|
296
|
+
this._withClient(invokeTracking, { queue: Boolean(queue) });
|
|
297
|
+
} else {
|
|
298
|
+
this._withClient(invokeTracking);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
trackView(name, attributes) {
|
|
302
|
+
if (!name) {
|
|
303
|
+
throw new Error("View name is required for trackView");
|
|
304
|
+
}
|
|
305
|
+
const viewAttributes = sanitizeAttributes(attributes || {});
|
|
306
|
+
const merged = this._mergeAttributes(viewAttributes);
|
|
307
|
+
this._withClient((client) => {
|
|
308
|
+
const api = client == null ? void 0 : client.api;
|
|
309
|
+
if (!(api == null ? void 0 : api.setView)) {
|
|
310
|
+
console.warn("[TrackingService] Faro setView API not available");
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
api.setView({
|
|
314
|
+
name,
|
|
315
|
+
...merged
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
setUser(user, options = {}) {
|
|
320
|
+
if (user == null) {
|
|
321
|
+
this.clearUser();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (typeof user !== "object") {
|
|
325
|
+
throw new Error("User must be an object");
|
|
326
|
+
}
|
|
327
|
+
const userData = sanitizeAttributes(user);
|
|
328
|
+
const queueConfigured = options && typeof options === "object" && Object.hasOwn(options, "queue");
|
|
329
|
+
const invokeTracking = (client) => {
|
|
330
|
+
const api = client == null ? void 0 : client.api;
|
|
331
|
+
if (!(api == null ? void 0 : api.setUser)) {
|
|
332
|
+
console.warn("[TrackingService] Faro setUser API not available");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
api.setUser(userData);
|
|
336
|
+
};
|
|
337
|
+
if (queueConfigured) {
|
|
338
|
+
this._withClient(invokeTracking, { queue: Boolean(options.queue) });
|
|
339
|
+
} else {
|
|
340
|
+
this._withClient(invokeTracking);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
clearUser() {
|
|
344
|
+
this._withClient((client) => {
|
|
345
|
+
const api = client == null ? void 0 : client.api;
|
|
346
|
+
if (api == null ? void 0 : api.setUser) {
|
|
347
|
+
api.setUser(null);
|
|
348
|
+
} else {
|
|
349
|
+
console.warn("[TrackingService] Faro setUser API not available");
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
setSession(session, options = {}) {
|
|
354
|
+
if (session == null) {
|
|
355
|
+
this.clearSession();
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (typeof session !== "object") {
|
|
359
|
+
throw new Error("Session must be an object");
|
|
360
|
+
}
|
|
361
|
+
const sessionData = sanitizeAttributes(session);
|
|
362
|
+
const queueConfigured = Object.hasOwn(options, "queue");
|
|
363
|
+
const { queue, ...sessionOptions } = options;
|
|
364
|
+
const invokeTracking = (client) => {
|
|
365
|
+
const api = client == null ? void 0 : client.api;
|
|
366
|
+
if (!(api == null ? void 0 : api.setSession)) {
|
|
367
|
+
console.warn("[TrackingService] Faro setSession API not available");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
api.setSession(sessionData, sessionOptions);
|
|
371
|
+
};
|
|
372
|
+
if (queueConfigured) {
|
|
373
|
+
this._withClient(invokeTracking, { queue: Boolean(queue) });
|
|
374
|
+
} else {
|
|
375
|
+
this._withClient(invokeTracking);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
clearSession() {
|
|
379
|
+
this._withClient((client) => {
|
|
380
|
+
const api = client == null ? void 0 : client.api;
|
|
381
|
+
if (api == null ? void 0 : api.setSession) {
|
|
382
|
+
api.setSession(null);
|
|
383
|
+
} else {
|
|
384
|
+
console.warn("[TrackingService] Faro setSession API not available");
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
setGlobalAttributes(attributes) {
|
|
389
|
+
if (attributes == null) {
|
|
390
|
+
this._globalAttributes = {};
|
|
391
|
+
this._trackingOptions.globalAttributes = {};
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (typeof attributes !== "object") {
|
|
395
|
+
throw new Error("Global attributes must be an object");
|
|
396
|
+
}
|
|
397
|
+
const sanitized = sanitizeAttributes(attributes);
|
|
398
|
+
this._globalAttributes = sanitized;
|
|
399
|
+
this._trackingOptions.globalAttributes = sanitized;
|
|
400
|
+
}
|
|
401
|
+
setGlobalAttribute(key, value) {
|
|
402
|
+
if (!key) {
|
|
403
|
+
throw new Error("Global attribute key is required");
|
|
404
|
+
}
|
|
405
|
+
const sanitized = sanitizeAttributes({ [key]: value });
|
|
406
|
+
this._globalAttributes = {
|
|
407
|
+
...this._globalAttributes,
|
|
408
|
+
...sanitized
|
|
409
|
+
};
|
|
410
|
+
this._trackingOptions.globalAttributes = { ...this._globalAttributes };
|
|
411
|
+
}
|
|
412
|
+
removeGlobalAttribute(key) {
|
|
413
|
+
if (!key) {
|
|
414
|
+
throw new Error("Global attribute key is required to remove it");
|
|
415
|
+
}
|
|
416
|
+
if (Object.hasOwn(this._globalAttributes, key)) {
|
|
417
|
+
const rest = { ...this._globalAttributes };
|
|
418
|
+
delete rest[key];
|
|
419
|
+
this._globalAttributes = rest;
|
|
420
|
+
this._trackingOptions.globalAttributes = rest;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
_mergeAttributes(attributes) {
|
|
424
|
+
const hasInput = attributes && typeof attributes === "object";
|
|
425
|
+
const sanitized = hasInput ? sanitizeAttributes(attributes) : {};
|
|
426
|
+
if (!this._globalAttributes || Object.keys(this._globalAttributes).length === 0) {
|
|
427
|
+
return sanitized;
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
...this._globalAttributes,
|
|
431
|
+
...sanitized
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
flushQueue() {
|
|
435
|
+
if (!this._queue.length) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const queue = [...this._queue];
|
|
439
|
+
this._queue.length = 0;
|
|
440
|
+
if (!this._faroClient) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
queue.forEach((callback) => {
|
|
444
|
+
try {
|
|
445
|
+
callback(this._faroClient);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error("[TrackingService] Failed to flush queued tracking call", error);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
getClient() {
|
|
452
|
+
return this._faroClient;
|
|
453
|
+
}
|
|
454
|
+
isEnabled() {
|
|
455
|
+
return this._enabled && Boolean(this._faroClient);
|
|
456
|
+
}
|
|
457
|
+
isInitialized() {
|
|
458
|
+
return this._initialized;
|
|
459
|
+
}
|
|
460
|
+
destroy() {
|
|
461
|
+
var _a;
|
|
462
|
+
this._queue.length = 0;
|
|
463
|
+
if ((_a = this._faroClient) == null ? void 0 : _a.destroy) {
|
|
464
|
+
try {
|
|
465
|
+
this._faroClient.destroy();
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.warn("[TrackingService] Failed to destroy Faro client cleanly", error);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (isBrowserEnvironment() && window.symbols && window.symbols.faro === this._faroClient) {
|
|
471
|
+
delete window.symbols.faro;
|
|
472
|
+
}
|
|
473
|
+
this._faroClient = null;
|
|
474
|
+
this._initialized = false;
|
|
475
|
+
this._setupPromise = null;
|
|
476
|
+
this._setReady(false);
|
|
477
|
+
this._enabled = this._trackingOptions.enabled !== false;
|
|
478
|
+
}
|
|
479
|
+
_buildRuntimeConfig() {
|
|
480
|
+
var _a, _b;
|
|
481
|
+
const contextConfig = ((_a = this._context) == null ? void 0 : _a.tracking) || {};
|
|
482
|
+
const merged = {
|
|
483
|
+
...DEFAULT_TRACKING_OPTIONS,
|
|
484
|
+
...this._trackingOptions,
|
|
485
|
+
...contextConfig
|
|
486
|
+
};
|
|
487
|
+
const transportList = [];
|
|
488
|
+
if (Array.isArray(merged.transports)) {
|
|
489
|
+
transportList.push(...merged.transports.filter(Boolean));
|
|
490
|
+
} else if (merged.transport) {
|
|
491
|
+
transportList.push(merged.transport);
|
|
492
|
+
}
|
|
493
|
+
const configuredUrl = merged.url || contextConfig.url || this._trackingOptions.url;
|
|
494
|
+
let url = configuredUrl;
|
|
495
|
+
if (!url && transportList.length === 0) {
|
|
496
|
+
url = import_environment.default.grafanaUrl;
|
|
497
|
+
}
|
|
498
|
+
const appName = merged.appName || contextConfig.appName || this._trackingOptions.appName || import_environment.default.grafanaAppName || "Symbols Platform";
|
|
499
|
+
const appVersion = merged.appVersion || contextConfig.appVersion || this._trackingOptions.appVersion || ((_b = this._context) == null ? void 0 : _b.appVersion);
|
|
500
|
+
const environmentName = merged.environment || contextConfig.environment || this._trackingOptions.environment || this._resolveEnvironmentName();
|
|
501
|
+
const contextGlobalAttributes = sanitizeAttributes(contextConfig.globalAttributes || {});
|
|
502
|
+
const globalAttributes = sanitizeAttributes({
|
|
503
|
+
...this._globalAttributes,
|
|
504
|
+
...contextGlobalAttributes
|
|
505
|
+
});
|
|
506
|
+
const runtimeConfig = {
|
|
507
|
+
url,
|
|
508
|
+
appName,
|
|
509
|
+
appVersion,
|
|
510
|
+
environment: environmentName,
|
|
511
|
+
globalAttributes,
|
|
512
|
+
sessionTracking: merged.sessionTracking !== false,
|
|
513
|
+
enableTracing: merged.enableTracing !== false,
|
|
514
|
+
user: merged.user,
|
|
515
|
+
maxQueueSize: typeof merged.maxQueueSize === "number" && merged.maxQueueSize > 0 ? merged.maxQueueSize : DEFAULT_MAX_QUEUE_SIZE
|
|
516
|
+
};
|
|
517
|
+
if (typeof merged.isolate === "boolean") {
|
|
518
|
+
runtimeConfig.isolate = merged.isolate;
|
|
519
|
+
}
|
|
520
|
+
if (Array.isArray(merged.instrumentations)) {
|
|
521
|
+
runtimeConfig.instrumentations = merged.instrumentations;
|
|
522
|
+
}
|
|
523
|
+
if (typeof merged.instrumentationsFactory === "function") {
|
|
524
|
+
runtimeConfig.instrumentationsFactory = merged.instrumentationsFactory;
|
|
525
|
+
}
|
|
526
|
+
if (merged.webInstrumentationOptions != null) {
|
|
527
|
+
runtimeConfig.webInstrumentationOptions = merged.webInstrumentationOptions;
|
|
528
|
+
}
|
|
529
|
+
if (transportList.length > 0) {
|
|
530
|
+
runtimeConfig.transports = transportList;
|
|
531
|
+
}
|
|
532
|
+
return runtimeConfig;
|
|
533
|
+
}
|
|
534
|
+
_resolveEnvironmentName() {
|
|
535
|
+
if (import_environment.default.isProduction) {
|
|
536
|
+
return "production";
|
|
537
|
+
}
|
|
538
|
+
if (import_environment.default.isStaging) {
|
|
539
|
+
return "staging";
|
|
540
|
+
}
|
|
541
|
+
if (import_environment.default.isTesting) {
|
|
542
|
+
return "testing";
|
|
543
|
+
}
|
|
544
|
+
if (import_environment.default.isDevelopment) {
|
|
545
|
+
return "development";
|
|
546
|
+
}
|
|
547
|
+
return process.env.SYMBOLS_APP_ENV || process.env.NODE_ENV || "development";
|
|
548
|
+
}
|
|
549
|
+
async _loadFaroClient(runtimeConfig) {
|
|
550
|
+
try {
|
|
551
|
+
const tracingImport = runtimeConfig.enableTracing === false ? Promise.resolve(null) : import("@grafana/faro-web-tracing").catch((error) => {
|
|
552
|
+
console.warn("[TrackingService] Tracing instrumentation failed to load:", error);
|
|
553
|
+
return null;
|
|
554
|
+
});
|
|
555
|
+
const [{ initializeFaro, getWebInstrumentations }, tracingModule] = await Promise.all([
|
|
556
|
+
import("@grafana/faro-web-sdk"),
|
|
557
|
+
tracingImport
|
|
558
|
+
]);
|
|
559
|
+
const TracingInstrumentation = tracingModule == null ? void 0 : tracingModule.TracingInstrumentation;
|
|
560
|
+
const instrumentations = await this._resolveInstrumentations({
|
|
561
|
+
runtimeConfig,
|
|
562
|
+
getWebInstrumentations,
|
|
563
|
+
TracingInstrumentation
|
|
564
|
+
});
|
|
565
|
+
const initializeOptions = {
|
|
566
|
+
app: {
|
|
567
|
+
name: runtimeConfig.appName,
|
|
568
|
+
version: runtimeConfig.appVersion,
|
|
569
|
+
environment: runtimeConfig.environment
|
|
570
|
+
},
|
|
571
|
+
instrumentations,
|
|
572
|
+
globalAttributes: sanitizeAttributes(runtimeConfig.globalAttributes)
|
|
573
|
+
};
|
|
574
|
+
if (runtimeConfig.url) {
|
|
575
|
+
initializeOptions.url = runtimeConfig.url;
|
|
576
|
+
}
|
|
577
|
+
if (Array.isArray(runtimeConfig.transports) && runtimeConfig.transports.length > 0) {
|
|
578
|
+
initializeOptions.transports = runtimeConfig.transports;
|
|
579
|
+
}
|
|
580
|
+
if (runtimeConfig.sessionTracking === false) {
|
|
581
|
+
initializeOptions.sessionTracking = false;
|
|
582
|
+
}
|
|
583
|
+
if (runtimeConfig.isolate === true) {
|
|
584
|
+
initializeOptions.isolate = true;
|
|
585
|
+
}
|
|
586
|
+
this._faroClient = initializeFaro(initializeOptions);
|
|
587
|
+
if (runtimeConfig.user) {
|
|
588
|
+
this.setUser(runtimeConfig.user, { queue: false });
|
|
589
|
+
}
|
|
590
|
+
if (isBrowserEnvironment()) {
|
|
591
|
+
window.symbols ||= {};
|
|
592
|
+
window.symbols.faro = this._faroClient;
|
|
593
|
+
}
|
|
594
|
+
this._initialized = true;
|
|
595
|
+
this._setReady();
|
|
596
|
+
this.flushQueue();
|
|
597
|
+
} catch (error) {
|
|
598
|
+
this._enabled = false;
|
|
599
|
+
this._setError(error);
|
|
600
|
+
this._ready = true;
|
|
601
|
+
console.error("[TrackingService] Failed to initialize Grafana Faro client:", error);
|
|
602
|
+
} finally {
|
|
603
|
+
this._setupPromise = null;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
async _resolveInstrumentations({
|
|
607
|
+
runtimeConfig,
|
|
608
|
+
getWebInstrumentations,
|
|
609
|
+
TracingInstrumentation
|
|
610
|
+
}) {
|
|
611
|
+
if (Array.isArray(runtimeConfig.instrumentations)) {
|
|
612
|
+
return runtimeConfig.instrumentations;
|
|
613
|
+
}
|
|
614
|
+
if (typeof runtimeConfig.instrumentationsFactory === "function") {
|
|
615
|
+
try {
|
|
616
|
+
const instrumentations = await runtimeConfig.instrumentationsFactory({
|
|
617
|
+
runtimeConfig,
|
|
618
|
+
getWebInstrumentations,
|
|
619
|
+
TracingInstrumentation
|
|
620
|
+
});
|
|
621
|
+
if (Array.isArray(instrumentations)) {
|
|
622
|
+
return instrumentations;
|
|
623
|
+
}
|
|
624
|
+
} catch (error) {
|
|
625
|
+
console.warn("[TrackingService] Custom instrumentation factory failed:", error);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const instrumentationOptions = runtimeConfig.webInstrumentationOptions == null ? {} : runtimeConfig.webInstrumentationOptions;
|
|
629
|
+
const defaultInstrumentations = getWebInstrumentations(instrumentationOptions);
|
|
630
|
+
if (runtimeConfig.enableTracing !== false && TracingInstrumentation) {
|
|
631
|
+
try {
|
|
632
|
+
defaultInstrumentations.push(new TracingInstrumentation());
|
|
633
|
+
} catch (error) {
|
|
634
|
+
console.warn("[TrackingService] Failed to instantiate tracing instrumentation:", error);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return defaultInstrumentations;
|
|
638
|
+
}
|
|
639
|
+
_withClient(callback, options = {}) {
|
|
640
|
+
if (!this._enabled) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
if (this._faroClient) {
|
|
644
|
+
try {
|
|
645
|
+
return callback(this._faroClient);
|
|
646
|
+
} catch (error) {
|
|
647
|
+
console.error("[TrackingService] Tracking callback failed:", error);
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (options.queue === false) {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
const queueLimit = this._runtimeConfig.maxQueueSize ?? this._trackingOptions.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE;
|
|
655
|
+
if (this._queue.length >= queueLimit) {
|
|
656
|
+
this._queue.shift();
|
|
657
|
+
}
|
|
658
|
+
this._queue.push(callback);
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
}
|