@uipath/insights-sdk 1.199.0 → 1.200.0-preview.117

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.
@@ -26,6 +26,422 @@ function settlePromiseLike(thenable) {
26
26
  ]);
27
27
  }
28
28
 
29
+ // src/errors.ts
30
+ class InsightsHttpError extends Error {
31
+ status;
32
+ method;
33
+ endpoint;
34
+ bodyKind;
35
+ requestId;
36
+ retryAfterSeconds;
37
+ constructor(init) {
38
+ super(`Insights request failed with HTTP ${init.status} for ${init.endpoint}`);
39
+ this.name = "InsightsHttpError";
40
+ this.status = init.status;
41
+ this.method = init.method;
42
+ this.endpoint = init.endpoint;
43
+ this.bodyKind = init.bodyKind;
44
+ this.requestId = init.requestId;
45
+ this.retryAfterSeconds = init.retryAfterSeconds;
46
+ }
47
+ }
48
+
49
+ class InsightsNetworkError extends Error {
50
+ endpoint;
51
+ constructor(endpoint, cause) {
52
+ super(`Insights request failed before a response was received for ${endpoint}`, { cause });
53
+ this.name = "InsightsNetworkError";
54
+ this.endpoint = endpoint;
55
+ }
56
+ }
57
+
58
+ class InsightsProtocolError extends Error {
59
+ endpoint;
60
+ constructor(endpoint, reason) {
61
+ super(`Insights returned a malformed success response for ${endpoint}: ${reason}`);
62
+ this.name = "InsightsProtocolError";
63
+ this.endpoint = endpoint;
64
+ }
65
+ }
66
+
67
+ // ../common/src/singleton.ts
68
+ var PREFIX = "@uipath/common/";
69
+ var _g = globalThis;
70
+ function singleton(ctorOrName) {
71
+ const name = typeof ctorOrName === "string" ? ctorOrName : ctorOrName.name;
72
+ const key = Symbol.for(PREFIX + name);
73
+ return {
74
+ get(fallback) {
75
+ return _g[key] ?? fallback;
76
+ },
77
+ set(value) {
78
+ _g[key] = value;
79
+ },
80
+ clear() {
81
+ delete _g[key];
82
+ },
83
+ getOrInit(factory, guard) {
84
+ const existing = _g[key];
85
+ if (existing != null && typeof existing === "object") {
86
+ if (!guard || guard(existing)) {
87
+ return existing;
88
+ }
89
+ }
90
+ const instance = factory();
91
+ _g[key] = instance;
92
+ return instance;
93
+ }
94
+ };
95
+ }
96
+
97
+ // ../common/src/telemetry/global-telemetry-properties.ts
98
+ var telemetryPropsSlot = singleton("TelemetryDefaultProps");
99
+
100
+ // ../common/src/sdk-user-agent.ts
101
+ var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
102
+ function splitUserAgentTokens(value) {
103
+ return value?.trim().split(/\s+/).filter(Boolean) ?? [];
104
+ }
105
+ function appendUserAgentToken(value, userAgent) {
106
+ const tokens = splitUserAgentTokens(value);
107
+ const seen = new Set(tokens);
108
+ for (const token of splitUserAgentTokens(userAgent)) {
109
+ if (!seen.has(token)) {
110
+ tokens.push(token);
111
+ seen.add(token);
112
+ }
113
+ }
114
+ return tokens.join(" ");
115
+ }
116
+ function getEffectiveUserAgent(userAgent) {
117
+ return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
118
+ }
119
+ function getSdkUserAgentToken(pkg) {
120
+ const packageName = pkg.name.replace(/^@uipath\//, "");
121
+ return getEffectiveUserAgent(`${packageName}/${pkg.version}`);
122
+ }
123
+ // package.json
124
+ var package_default = {
125
+ name: "@uipath/insights-sdk",
126
+ license: "MIT",
127
+ version: "1.200.0-preview.117",
128
+ description: "SDK for the UiPath Insights API — jobs, failures, and performance metrics.",
129
+ repository: {
130
+ type: "git",
131
+ url: "https://github.com/UiPath/cli.git",
132
+ directory: "packages/insights-sdk"
133
+ },
134
+ publishConfig: {
135
+ registry: "https://npm.pkg.github.com/@uipath"
136
+ },
137
+ keywords: [
138
+ "uipath",
139
+ "insights",
140
+ "sdk"
141
+ ],
142
+ type: "module",
143
+ main: "./dist/index.js",
144
+ types: "./dist/src/index.d.ts",
145
+ exports: {
146
+ ".": {
147
+ browser: {
148
+ types: "./dist/src/index.browser.d.ts",
149
+ default: "./dist/index.browser.js"
150
+ },
151
+ default: {
152
+ types: "./dist/src/index.d.ts",
153
+ default: "./dist/index.js"
154
+ }
155
+ }
156
+ },
157
+ files: [
158
+ "dist"
159
+ ],
160
+ scripts: {
161
+ build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && bun build ./src/index.browser.ts --outdir dist --format esm --target browser --external @uipath/auth --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
162
+ lint: "biome check .",
163
+ "lint:fix": "biome check --write .",
164
+ test: "vitest run",
165
+ "test:coverage": "vitest run --coverage",
166
+ typecheck: "tsc --noEmit"
167
+ },
168
+ devDependencies: {
169
+ "@uipath/auth": "workspace:*",
170
+ "@uipath/common": "workspace:*",
171
+ "@types/node": "^25.5.2",
172
+ typescript: "^7.0.2"
173
+ }
174
+ };
175
+
176
+ // src/user-agent.ts
177
+ function buildInsightsUserAgent() {
178
+ return getSdkUserAgentToken(package_default);
179
+ }
180
+
181
+ // src/transport.ts
182
+ var SERVICE_ROOTS = {
183
+ rtm: "insightsrtm_",
184
+ portal: "insights_/api"
185
+ };
186
+ var INSIGHTS_ROUTES = {
187
+ alertDefinitionsList: {
188
+ service: "rtm",
189
+ method: "POST",
190
+ template: "AlertDefinitions/getDefinitions/{tenantId}/{accountName}/{tenantName}"
191
+ },
192
+ alertDefinitionsListAgentic: {
193
+ service: "rtm",
194
+ method: "GET",
195
+ template: "AlertDefinitions/agentic/{tenantId}/{processKey}"
196
+ },
197
+ alertDefinitionsGet: {
198
+ service: "rtm",
199
+ method: "GET",
200
+ template: "AlertDefinitions/{tenantId}/{alertDefinitionId}"
201
+ },
202
+ alertDefinitionsCreate: {
203
+ service: "rtm",
204
+ method: "POST",
205
+ template: "AlertDefinitions/{tenantId}/{accountName}/{tenantName}"
206
+ },
207
+ alertDefinitionsUpdate: {
208
+ service: "rtm",
209
+ method: "PUT",
210
+ template: "AlertDefinitions/{tenantId}/{alertDefinitionId}/{accountName}/{tenantName}"
211
+ },
212
+ alertDefinitionsSnooze: {
213
+ service: "rtm",
214
+ method: "PUT",
215
+ template: "AlertDefinitions/{tenantId}/{alertDefinitionId}/{accountName}/{tenantName}/snooze?isSnoozed={isSnoozed}"
216
+ },
217
+ alertDefinitionsDelete: {
218
+ service: "rtm",
219
+ method: "DELETE",
220
+ template: "AlertDefinitions/{tenantId}/{alertDefinitionId}",
221
+ allowsEmptyResponse: true
222
+ },
223
+ alertDefinitionsCheckEntitlement: {
224
+ service: "rtm",
225
+ method: "GET",
226
+ template: "AlertDefinitions/checkEntitlement/{tenantId}"
227
+ },
228
+ alertHistoryDetails: {
229
+ service: "rtm",
230
+ method: "POST",
231
+ template: "AlertHistory/details"
232
+ },
233
+ alertHistoryMetrics: {
234
+ service: "rtm",
235
+ method: "POST",
236
+ template: "AlertHistory/metrics"
237
+ },
238
+ defaultDeliveryGet: {
239
+ service: "rtm",
240
+ method: "GET",
241
+ template: "DefaultDelivery/{tenantId}/{alertDeliveryId}"
242
+ },
243
+ filtersAllFolders: {
244
+ service: "rtm",
245
+ method: "POST",
246
+ template: "Filters/allFolders/{accountName}/{tenantName}"
247
+ },
248
+ filtersAllProcesses: {
249
+ service: "rtm",
250
+ method: "POST",
251
+ template: "Filters/allProcesses/{accountName}/{tenantName}"
252
+ },
253
+ filtersAllQueues: {
254
+ service: "rtm",
255
+ method: "POST",
256
+ template: "Filters/allQueues/{accountName}/{tenantName}"
257
+ },
258
+ filtersAllMachines: {
259
+ service: "rtm",
260
+ method: "POST",
261
+ template: "Filters/allMachines"
262
+ },
263
+ usersList: { service: "portal", method: "GET", template: "User" },
264
+ usersGet: { service: "portal", method: "GET", template: "User/{userId}" },
265
+ rolesList: { service: "portal", method: "GET", template: "Role" },
266
+ rolesGet: { service: "portal", method: "GET", template: "Role/{roleId}" },
267
+ groupsList: { service: "portal", method: "GET", template: "Group" },
268
+ groupsGet: {
269
+ service: "portal",
270
+ method: "GET",
271
+ template: "Group/{groupId}"
272
+ },
273
+ authorizationCheckAccess: {
274
+ service: "portal",
275
+ method: "POST",
276
+ template: "Authorization/tenant/insights"
277
+ }
278
+ };
279
+ function insightsRouteTemplate(routeKey) {
280
+ return INSIGHTS_ROUTES[routeKey].template;
281
+ }
282
+ var SESSION_PARAM_NAMES = new Set(["tenantId", "accountName", "tenantName"]);
283
+ function sessionPathParams(config) {
284
+ return {
285
+ tenantId: config.tenantId,
286
+ accountName: config.accountName,
287
+ tenantName: config.tenantName
288
+ };
289
+ }
290
+ function encodePathSegment(routeKey, name, value) {
291
+ if (value.trim() === "" || value === "." || value === "..") {
292
+ throw new Error(`Insights route "${routeKey}" has an invalid value for "{${name}}".`);
293
+ }
294
+ return encodeURIComponent(value);
295
+ }
296
+ function buildRoutePath(routeKey, template, config, pathParams) {
297
+ for (const name of Object.keys(pathParams)) {
298
+ if (SESSION_PARAM_NAMES.has(name)) {
299
+ throw new Error(`Insights route segment "{${name}}" is session-derived and cannot be overridden.`);
300
+ }
301
+ if (!template.includes(`{${name}}`)) {
302
+ throw new Error(`Insights route "${routeKey}" has no "{${name}}" segment.`);
303
+ }
304
+ }
305
+ const values = {
306
+ ...sessionPathParams(config),
307
+ ...pathParams
308
+ };
309
+ return template.replace(/\{([A-Za-z]+)\}/g, (_, name) => {
310
+ const value = values[name];
311
+ if (value === undefined) {
312
+ throw new Error(`Insights route "${routeKey}" is missing a value for "{${name}}".`);
313
+ }
314
+ return encodePathSegment(routeKey, name, value);
315
+ });
316
+ }
317
+ function buildServiceHeaders(config, service, hasBody) {
318
+ const headers = {
319
+ Authorization: `Bearer ${config.authToken}`,
320
+ Accept: "application/json"
321
+ };
322
+ if (hasBody) {
323
+ headers["Content-Type"] = "application/json";
324
+ }
325
+ if (service === "rtm") {
326
+ headers["X-UiPath-Internal-AccountName"] = config.accountName;
327
+ headers["X-UiPath-Internal-TenantName"] = config.tenantName;
328
+ } else {
329
+ headers["X-UiPath-Internal-AccountId"] = config.organizationId;
330
+ headers["X-UiPath-Internal-TenantId"] = config.tenantId;
331
+ }
332
+ const userAgent = buildInsightsUserAgent();
333
+ if (userAgent) {
334
+ headers["User-Agent"] = userAgent;
335
+ }
336
+ return headers;
337
+ }
338
+ function classifyErrorBody(text) {
339
+ if (!text.trim()) {
340
+ return "absent";
341
+ }
342
+ const head = text.trimStart().toLowerCase();
343
+ if (head.startsWith("<!doctype") || head.startsWith("<html")) {
344
+ return "html";
345
+ }
346
+ const [parseError] = catchError(() => JSON.parse(text));
347
+ if (!parseError) {
348
+ return "json";
349
+ }
350
+ return head.startsWith("{") || head.startsWith("[") ? "invalid-json" : "text";
351
+ }
352
+ function parseRetryAfterSeconds(header) {
353
+ if (header === null) {
354
+ return;
355
+ }
356
+ const seconds = Number.parseInt(header, 10);
357
+ return Number.isNaN(seconds) || seconds < 0 ? undefined : seconds;
358
+ }
359
+ async function requestInsightsRoute(config, routeKey, request = {}) {
360
+ const route = INSIGHTS_ROUTES[routeKey];
361
+ if (!route) {
362
+ throw new Error(`Unsupported Insights route "${routeKey}".`);
363
+ }
364
+ const path = buildRoutePath(routeKey, route.template, config, request.pathParams ?? {});
365
+ const url = `${config.baseUrl}/${encodePathSegment(routeKey, "organizationId", config.organizationId)}/${encodePathSegment(routeKey, "tenantName", config.tenantName)}/${SERVICE_ROOTS[route.service]}/${path}`;
366
+ const hasBody = request.body !== undefined;
367
+ const [fetchError, response] = await catchError(fetch(url, {
368
+ method: route.method,
369
+ headers: buildServiceHeaders(config, route.service, hasBody),
370
+ body: hasBody ? JSON.stringify(request.body) : undefined
371
+ }));
372
+ if (fetchError) {
373
+ throw new InsightsNetworkError(route.template, fetchError);
374
+ }
375
+ const [readError, text] = await catchError(response.text());
376
+ if (readError) {
377
+ throw new InsightsNetworkError(route.template, readError);
378
+ }
379
+ if (!response.ok) {
380
+ throw new InsightsHttpError({
381
+ status: response.status,
382
+ method: route.method,
383
+ endpoint: route.template,
384
+ bodyKind: classifyErrorBody(text),
385
+ requestId: response.headers.get("x-request-id") ?? undefined,
386
+ retryAfterSeconds: parseRetryAfterSeconds(response.headers.get("retry-after"))
387
+ });
388
+ }
389
+ if (!text.trim()) {
390
+ if (route.allowsEmptyResponse) {
391
+ return;
392
+ }
393
+ throw new InsightsProtocolError(route.template, "empty response body");
394
+ }
395
+ const [parseError, parsed] = catchError(() => JSON.parse(text));
396
+ if (parseError) {
397
+ throw new InsightsProtocolError(route.template, "response body is not valid JSON");
398
+ }
399
+ return parsed;
400
+ }
401
+
402
+ // src/alerts.ts
403
+ async function listAlertDefinitions(config, request) {
404
+ return requestInsightsRoute(config, "alertDefinitionsList", {
405
+ body: request ?? {}
406
+ });
407
+ }
408
+ async function listAgenticAlertDefinitions(config, processKey) {
409
+ return requestInsightsRoute(config, "alertDefinitionsListAgentic", {
410
+ pathParams: { processKey }
411
+ });
412
+ }
413
+ async function getAlertDefinition(config, alertDefinitionId) {
414
+ return requestInsightsRoute(config, "alertDefinitionsGet", {
415
+ pathParams: { alertDefinitionId }
416
+ });
417
+ }
418
+ async function deleteAlertDefinition(config, alertDefinitionId) {
419
+ return requestInsightsRoute(config, "alertDefinitionsDelete", {
420
+ pathParams: { alertDefinitionId }
421
+ });
422
+ }
423
+ async function checkAlertEntitlement(config) {
424
+ return requestInsightsRoute(config, "alertDefinitionsCheckEntitlement");
425
+ }
426
+ function withSessionTenantId(config, request) {
427
+ const base = typeof request === "object" && request !== null && !Array.isArray(request) ? request : {};
428
+ return { ...base, tenantId: config.tenantId };
429
+ }
430
+ async function listAlertHistoryDetails(config, request) {
431
+ return requestInsightsRoute(config, "alertHistoryDetails", {
432
+ body: withSessionTenantId(config, request)
433
+ });
434
+ }
435
+ async function getAlertHistoryMetrics(config, request) {
436
+ return requestInsightsRoute(config, "alertHistoryMetrics", {
437
+ body: withSessionTenantId(config, request)
438
+ });
439
+ }
440
+ async function getDefaultDelivery(config, alertDeliveryId) {
441
+ return requestInsightsRoute(config, "defaultDeliveryGet", {
442
+ pathParams: { alertDeliveryId }
443
+ });
444
+ }
29
445
  // src/client.ts
30
446
  function buildInsightsUrl(config, path) {
31
447
  return `${config.baseUrl}/${config.organizationId}/${config.tenantName}/insightsrtm_/api/v1.0/InsightsJobs${path}`;
@@ -80,9 +496,128 @@ async function createInsightsConfig(tenantOverride) {
80
496
  tenantName: ctx.tenantName
81
497
  };
82
498
  }
499
+ // src/types.ts
500
+ function isStringArrayOrNullish(value) {
501
+ if (value === undefined || value === null) {
502
+ return true;
503
+ }
504
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string");
505
+ }
506
+ function hasStringArrayFields(value, fields) {
507
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
508
+ return false;
509
+ }
510
+ const record = value;
511
+ if (!fields.every((field) => isStringArrayOrNullish(record[field]))) {
512
+ return false;
513
+ }
514
+ return Object.keys(record).length === 0 || fields.some((field) => (field in record));
515
+ }
516
+ function isFolderFiltersResponse(value) {
517
+ return hasStringArrayFields(value, [
518
+ "folderKeys",
519
+ "folderNames"
520
+ ]);
521
+ }
522
+ function isProcessFiltersResponse(value) {
523
+ return hasStringArrayFields(value, [
524
+ "processNames",
525
+ "folderKeys",
526
+ "processKeys",
527
+ "processVersions",
528
+ "projectKeys"
529
+ ]);
530
+ }
531
+ function isQueueFiltersResponse(value) {
532
+ return hasStringArrayFields(value, [
533
+ "queueNames",
534
+ "folderKeys"
535
+ ]);
536
+ }
537
+ function isMachineFiltersResponse(value) {
538
+ return hasStringArrayFields(value, [
539
+ "filterOptions",
540
+ "filtersExtraOptions"
541
+ ]);
542
+ }
543
+
544
+ // src/filters.ts
545
+ async function listFilters(config, routeKey, guard, contractName) {
546
+ const parsed = await requestInsightsRoute(config, routeKey, {
547
+ body: { tenantId: config.tenantId }
548
+ });
549
+ if (!guard(parsed)) {
550
+ throw new InsightsProtocolError(insightsRouteTemplate(routeKey), `body does not match the ${contractName} contract`);
551
+ }
552
+ return parsed;
553
+ }
554
+ async function listFolderFilters(config) {
555
+ return listFilters(config, "filtersAllFolders", isFolderFiltersResponse, "folder filters");
556
+ }
557
+ async function listProcessFilters(config) {
558
+ return listFilters(config, "filtersAllProcesses", isProcessFiltersResponse, "process filters");
559
+ }
560
+ async function listQueueFilters(config) {
561
+ return listFilters(config, "filtersAllQueues", isQueueFiltersResponse, "queue filters");
562
+ }
563
+ async function listMachineFilters(config) {
564
+ return listFilters(config, "filtersAllMachines", isMachineFiltersResponse, "machine filters");
565
+ }
566
+ // src/rbac.ts
567
+ async function listUsers(config) {
568
+ return requestInsightsRoute(config, "usersList");
569
+ }
570
+ async function getUser(config, userId) {
571
+ return requestInsightsRoute(config, "usersGet", {
572
+ pathParams: { userId }
573
+ });
574
+ }
575
+ async function listRoles(config) {
576
+ return requestInsightsRoute(config, "rolesList");
577
+ }
578
+ async function getRole(config, roleId) {
579
+ return requestInsightsRoute(config, "rolesGet", {
580
+ pathParams: { roleId }
581
+ });
582
+ }
583
+ async function listGroups(config) {
584
+ return requestInsightsRoute(config, "groupsList");
585
+ }
586
+ async function getGroup(config, groupId) {
587
+ return requestInsightsRoute(config, "groupsGet", {
588
+ pathParams: { groupId }
589
+ });
590
+ }
591
+ async function checkInsightsAccess(config, request) {
592
+ return requestInsightsRoute(config, "authorizationCheckAccess", {
593
+ body: request
594
+ });
595
+ }
83
596
  export {
597
+ listUsers,
598
+ listRoles,
599
+ listQueueFilters,
600
+ listProcessFilters,
601
+ listMachineFilters,
602
+ listGroups,
603
+ listFolderFilters,
604
+ listAlertHistoryDetails,
605
+ listAlertDefinitions,
606
+ listAgenticAlertDefinitions,
84
607
  insightsPost,
85
- createInsightsConfig
608
+ getUser,
609
+ getRole,
610
+ getGroup,
611
+ getDefaultDelivery,
612
+ getAlertHistoryMetrics,
613
+ getAlertDefinition,
614
+ deleteAlertDefinition,
615
+ createInsightsConfig,
616
+ checkInsightsAccess,
617
+ checkAlertEntitlement,
618
+ InsightsProtocolError,
619
+ InsightsNetworkError,
620
+ InsightsHttpError
86
621
  };
87
622
 
88
- //# debugId=D4177847864883E864756E2164756E21
623
+ //# debugId=98D65697D55F700864756E2164756E21