@uipath/insights-sdk 1.196.0 → 1.197.0-preview.59
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/dist/index.browser.js +88 -0
- package/dist/index.js +16603 -25756
- package/package.json +6 -3
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// ../common/dist/catch-error.js
|
|
2
|
+
function isPromiseLike(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
4
|
+
}
|
|
5
|
+
function catchError(fnOrPromise) {
|
|
6
|
+
if (isPromiseLike(fnOrPromise)) {
|
|
7
|
+
return settlePromiseLike(fnOrPromise);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const result = fnOrPromise();
|
|
11
|
+
if (isPromiseLike(result)) {
|
|
12
|
+
return settlePromiseLike(result);
|
|
13
|
+
}
|
|
14
|
+
return [undefined, result];
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return [
|
|
17
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
18
|
+
undefined
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function settlePromiseLike(thenable) {
|
|
23
|
+
return Promise.resolve(thenable).then((data) => [undefined, data]).catch((error) => [
|
|
24
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
25
|
+
undefined
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/client.ts
|
|
30
|
+
function buildInsightsUrl(config, path) {
|
|
31
|
+
return `${config.baseUrl}/${config.organizationId}/${config.tenantName}/insightsrtm_/api/v1.0/InsightsJobs${path}`;
|
|
32
|
+
}
|
|
33
|
+
function buildHeaders(config) {
|
|
34
|
+
return {
|
|
35
|
+
Authorization: `Bearer ${config.authToken}`,
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Accept: "application/json",
|
|
38
|
+
"X-UiPath-Internal-AccountName": config.accountName,
|
|
39
|
+
"X-UiPath-Internal-TenantName": config.tenantName
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function insightsPost(config, path, body) {
|
|
43
|
+
const url = buildInsightsUrl(config, path);
|
|
44
|
+
const headers = buildHeaders(config);
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers,
|
|
48
|
+
body: body ? JSON.stringify(body) : undefined
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const errorText = await response.text();
|
|
52
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
53
|
+
}
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
if (!text)
|
|
56
|
+
throw new Error("API returned an empty response body");
|
|
57
|
+
const [parseErr, parsed] = catchError(() => JSON.parse(text));
|
|
58
|
+
if (parseErr) {
|
|
59
|
+
throw new Error(`Failed to parse API response body: ${parseErr.message}`);
|
|
60
|
+
}
|
|
61
|
+
return parsed;
|
|
62
|
+
}
|
|
63
|
+
// src/client-factory.ts
|
|
64
|
+
import { getAuthContext } from "@uipath/auth";
|
|
65
|
+
async function createInsightsConfig(tenantOverride) {
|
|
66
|
+
const ctx = await getAuthContext({
|
|
67
|
+
tenant: tenantOverride,
|
|
68
|
+
ensureTokenValidityMinutes: 10,
|
|
69
|
+
requireOrganizationId: true,
|
|
70
|
+
requireOrganizationName: true,
|
|
71
|
+
requireTenantId: true,
|
|
72
|
+
requireTenantName: true
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
baseUrl: ctx.baseUrl,
|
|
76
|
+
organizationId: ctx.organizationId,
|
|
77
|
+
tenantId: ctx.tenantId,
|
|
78
|
+
authToken: ctx.accessToken,
|
|
79
|
+
accountName: ctx.organizationName,
|
|
80
|
+
tenantName: ctx.tenantName
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
insightsPost,
|
|
85
|
+
createInsightsConfig
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//# debugId=FD8E3A18FF1018EC64756E2164756E21
|