myio-js-library 0.1.53 → 0.1.55
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.cjs +88 -0
- package/dist/index.d.cts +68 -1
- package/dist/index.js +85 -0
- package/dist/myio-js-library.umd.js +85 -0
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -592,6 +592,9 @@ __export(index_exports, {
|
|
|
592
592
|
determineInterval: () => determineInterval,
|
|
593
593
|
exportToCSV: () => exportToCSV,
|
|
594
594
|
exportToCSVAll: () => exportToCSVAll,
|
|
595
|
+
extractMyIOCredentials: () => extractMyIOCredentials,
|
|
596
|
+
fetchThingsboardCustomerAttrsFromStorage: () => fetchThingsboardCustomerAttrsFromStorage,
|
|
597
|
+
fetchThingsboardCustomerServerScopeAttrs: () => fetchThingsboardCustomerServerScopeAttrs,
|
|
595
598
|
findValue: () => findValue,
|
|
596
599
|
fmtPerc: () => fmtPerc,
|
|
597
600
|
fmtPercLegacy: () => fmtPerc2,
|
|
@@ -1503,6 +1506,88 @@ function getAuthCacheStats() {
|
|
|
1503
1506
|
};
|
|
1504
1507
|
}
|
|
1505
1508
|
|
|
1509
|
+
// src/thingsboard/api/fetchThingsboardCustomerServerScopeAttrs.ts
|
|
1510
|
+
async function fetchThingsboardCustomerServerScopeAttrs(config) {
|
|
1511
|
+
const { customerId, tbToken, baseUrl = "" } = config;
|
|
1512
|
+
if (!customerId || !tbToken) {
|
|
1513
|
+
throw new Error("customerId and tbToken are required");
|
|
1514
|
+
}
|
|
1515
|
+
const url = `${baseUrl}/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
|
|
1516
|
+
try {
|
|
1517
|
+
const response = await fetch(url, {
|
|
1518
|
+
method: "GET",
|
|
1519
|
+
headers: {
|
|
1520
|
+
"Content-Type": "application/json",
|
|
1521
|
+
"X-Authorization": `Bearer ${tbToken}`
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
if (!response.ok) {
|
|
1525
|
+
console.warn(`[ThingsBoard Customer Attrs] HTTP ${response.status} ${response.statusText}`);
|
|
1526
|
+
if (response.status === 404 || response.status === 403) {
|
|
1527
|
+
return {};
|
|
1528
|
+
}
|
|
1529
|
+
throw new Error(`ThingsBoard API error: HTTP ${response.status} ${response.statusText}`);
|
|
1530
|
+
}
|
|
1531
|
+
const payload = await response.json();
|
|
1532
|
+
return processAttributesResponse(payload);
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
console.error("[ThingsBoard Customer Attrs] Error fetching attributes:", error);
|
|
1535
|
+
if (error instanceof Error) {
|
|
1536
|
+
throw new Error(`Failed to fetch customer attributes: ${error.message}`);
|
|
1537
|
+
}
|
|
1538
|
+
throw new Error("Failed to fetch customer attributes: Unknown error");
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
function processAttributesResponse(payload) {
|
|
1542
|
+
const attributesMap = {};
|
|
1543
|
+
if (!payload) {
|
|
1544
|
+
return attributesMap;
|
|
1545
|
+
}
|
|
1546
|
+
if (Array.isArray(payload)) {
|
|
1547
|
+
for (const item of payload) {
|
|
1548
|
+
if (item && typeof item === "object" && item.key !== void 0) {
|
|
1549
|
+
attributesMap[item.key] = item.value;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return attributesMap;
|
|
1553
|
+
}
|
|
1554
|
+
if (typeof payload === "object") {
|
|
1555
|
+
for (const key of Object.keys(payload)) {
|
|
1556
|
+
const value = payload[key];
|
|
1557
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
1558
|
+
const firstItem = value[0];
|
|
1559
|
+
attributesMap[key] = firstItem?.value ?? firstItem;
|
|
1560
|
+
} else {
|
|
1561
|
+
attributesMap[key] = value;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return attributesMap;
|
|
1565
|
+
}
|
|
1566
|
+
console.warn("[ThingsBoard Customer Attrs] Unexpected payload format:", typeof payload);
|
|
1567
|
+
return attributesMap;
|
|
1568
|
+
}
|
|
1569
|
+
async function fetchThingsboardCustomerAttrsFromStorage(customerId, tbToken, baseUrl) {
|
|
1570
|
+
return fetchThingsboardCustomerServerScopeAttrs({
|
|
1571
|
+
customerId,
|
|
1572
|
+
tbToken,
|
|
1573
|
+
baseUrl
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
function extractMyIOCredentials(attributes) {
|
|
1577
|
+
if (!attributes || typeof attributes !== "object") {
|
|
1578
|
+
return {
|
|
1579
|
+
clientId: "",
|
|
1580
|
+
clientSecret: "",
|
|
1581
|
+
ingestionId: ""
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
return {
|
|
1585
|
+
clientId: attributes.client_id || attributes.clientId || "",
|
|
1586
|
+
clientSecret: attributes.client_secret || attributes.clientSecret || "",
|
|
1587
|
+
ingestionId: attributes.ingestionId || attributes.ingestion_id || ""
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1506
1591
|
// src/utils/deviceType.js
|
|
1507
1592
|
function normalize(str) {
|
|
1508
1593
|
if (typeof str !== "string") return "";
|
|
@@ -10199,6 +10284,9 @@ async function openDemandModal(params) {
|
|
|
10199
10284
|
determineInterval,
|
|
10200
10285
|
exportToCSV,
|
|
10201
10286
|
exportToCSVAll,
|
|
10287
|
+
extractMyIOCredentials,
|
|
10288
|
+
fetchThingsboardCustomerAttrsFromStorage,
|
|
10289
|
+
fetchThingsboardCustomerServerScopeAttrs,
|
|
10202
10290
|
findValue,
|
|
10203
10291
|
fmtPerc,
|
|
10204
10292
|
fmtPercLegacy,
|
package/dist/index.d.cts
CHANGED
|
@@ -408,6 +408,73 @@ declare function getAuthCacheStats(): {
|
|
|
408
408
|
cacheKeys: string[];
|
|
409
409
|
};
|
|
410
410
|
|
|
411
|
+
/**
|
|
412
|
+
* ThingsBoard Customer Server Scope Attributes Fetcher
|
|
413
|
+
*
|
|
414
|
+
* Utility function to fetch customer server scope attributes from ThingsBoard API.
|
|
415
|
+
* Handles both array and object response formats with proper error handling.
|
|
416
|
+
*/
|
|
417
|
+
/**
|
|
418
|
+
* Configuration parameters for fetching customer attributes
|
|
419
|
+
*/
|
|
420
|
+
interface ThingsboardCustomerAttrsConfig {
|
|
421
|
+
customerId: string;
|
|
422
|
+
tbToken: string;
|
|
423
|
+
baseUrl?: string;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Fetch customer server scope attributes from ThingsBoard API
|
|
427
|
+
*
|
|
428
|
+
* @param config Configuration object with customerId and tbToken
|
|
429
|
+
* @returns Promise resolving to attributes map
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* const attrs = await fetchThingsboardCustomerServerScopeAttrs({
|
|
434
|
+
* customerId: 'customer-uuid',
|
|
435
|
+
* tbToken: 'jwt-token-from-localStorage'
|
|
436
|
+
* });
|
|
437
|
+
*
|
|
438
|
+
* console.log(attrs.client_id, attrs.client_secret, attrs.ingestionId);
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
declare function fetchThingsboardCustomerServerScopeAttrs(config: ThingsboardCustomerAttrsConfig): Promise<Record<string, any>>;
|
|
442
|
+
/**
|
|
443
|
+
* Fetch customer attributes with token parameter
|
|
444
|
+
* Convenience function for ThingsBoard widget contexts
|
|
445
|
+
*
|
|
446
|
+
* @param customerId Customer UUID
|
|
447
|
+
* @param tbToken JWT token for authentication
|
|
448
|
+
* @param baseUrl Optional base URL for ThingsBoard API
|
|
449
|
+
* @returns Promise resolving to attributes map
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* const tbToken = localStorage.getItem('jwt_token');
|
|
454
|
+
* const attrs = await fetchThingsboardCustomerAttrsFromStorage('customer-uuid', tbToken);
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
declare function fetchThingsboardCustomerAttrsFromStorage(customerId: string, tbToken: string, baseUrl?: string): Promise<Record<string, any>>;
|
|
458
|
+
/**
|
|
459
|
+
* Extract common credentials from attributes map
|
|
460
|
+
* Helper function to get standard MyIO credentials
|
|
461
|
+
*
|
|
462
|
+
* @param attributes Attributes map from fetchThingsboardCustomerServerScopeAttrs
|
|
463
|
+
* @returns Extracted credentials with fallbacks
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const attrs = await fetchThingsboardCustomerServerScopeAttrs(config);
|
|
468
|
+
* const creds = extractMyIOCredentials(attrs);
|
|
469
|
+
* console.log(creds.clientId, creds.clientSecret, creds.ingestionId);
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
declare function extractMyIOCredentials(attributes: Record<string, any> | null | undefined): {
|
|
473
|
+
clientId: string;
|
|
474
|
+
clientSecret: string;
|
|
475
|
+
ingestionId: string;
|
|
476
|
+
};
|
|
477
|
+
|
|
411
478
|
/**
|
|
412
479
|
* Detects the device type based on the given name and context.
|
|
413
480
|
* Uses the specified detection context to identify device types.
|
|
@@ -1187,4 +1254,4 @@ interface DemandModalInstance {
|
|
|
1187
1254
|
*/
|
|
1188
1255
|
declare function openDemandModal(params: DemandModalParams): Promise<DemandModalInstance>;
|
|
1189
1256
|
|
|
1190
|
-
export { type CreateDateRangePickerOptions, type CreateInputDateRangePickerInsideDIVParams, type DateRangeControl, type DateRangeInputController, type DateRangeResult, type DemandModalInstance, type DemandModalParams, type DemandModalPdfConfig, type DemandModalStyles, type MyIOAuthConfig, type MyIOAuthInstance, MyIOChartModal, MyIODraggableCard, MyIOSelectionStore, MyIOSelectionStoreClass, type OpenDashboardPopupSettingsParams, type PersistResult, type SettingsError, type SettingsEvent, type StoreRow, type TbScope, type TelemetryFetcher, type TimedValue, type WaterRow, addDetectionContext, addNamespace, averageByDay, buildListItemsThingsboardByUniqueDatasource, buildMyioIngestionAuth, buildWaterReportCSV, buildWaterStoresCSV, calcDeltaPercent, classify, classifyWaterLabel, classifyWaterLabels, clearAllAuthCaches, createDateRangePicker, createInputDateRangePickerInsideDIV, decodePayload, decodePayloadBase64Xor, detectDeviceType, determineInterval, exportToCSV, exportToCSVAll, findValue, fmtPerc$1 as fmtPerc, fmtPerc as fmtPercLegacy, formatAllInSameUnit, formatAllInSameWaterUnit, formatDateForInput, formatDateToYMD, formatDateWithTimezoneOffset, formatEnergy, formatNumberReadable, formatTankHeadFromCm, formatWaterByGroup, formatWaterVolumeM3, getAuthCacheStats, getAvailableContexts, getDateRangeArray, getSaoPauloISOString, getSaoPauloISOStringFixed, getValueByDatakey, getValueByDatakeyLegacy, getWaterCategories, groupByDay, isWaterCategory, normalizeRecipients, numbers, openDashboardPopup, openDashboardPopupAllReport, openDashboardPopupEnergy, openDashboardPopupReport, openDashboardPopupSettings, openDemandModal, parseInputDateToDate, renderCardCompenteHeadOffice, renderCardComponent$1 as renderCardComponent, renderCardComponent as renderCardComponentEnhanced, renderCardComponentLegacy, renderCardComponentV2, strings, timeWindowFromInputYMD, toCSV, toFixedSafe };
|
|
1257
|
+
export { type CreateDateRangePickerOptions, type CreateInputDateRangePickerInsideDIVParams, type DateRangeControl, type DateRangeInputController, type DateRangeResult, type DemandModalInstance, type DemandModalParams, type DemandModalPdfConfig, type DemandModalStyles, type MyIOAuthConfig, type MyIOAuthInstance, MyIOChartModal, MyIODraggableCard, MyIOSelectionStore, MyIOSelectionStoreClass, type OpenDashboardPopupSettingsParams, type PersistResult, type SettingsError, type SettingsEvent, type StoreRow, type TbScope, type TelemetryFetcher, type ThingsboardCustomerAttrsConfig, type TimedValue, type WaterRow, addDetectionContext, addNamespace, averageByDay, buildListItemsThingsboardByUniqueDatasource, buildMyioIngestionAuth, buildWaterReportCSV, buildWaterStoresCSV, calcDeltaPercent, classify, classifyWaterLabel, classifyWaterLabels, clearAllAuthCaches, createDateRangePicker, createInputDateRangePickerInsideDIV, decodePayload, decodePayloadBase64Xor, detectDeviceType, determineInterval, exportToCSV, exportToCSVAll, extractMyIOCredentials, fetchThingsboardCustomerAttrsFromStorage, fetchThingsboardCustomerServerScopeAttrs, findValue, fmtPerc$1 as fmtPerc, fmtPerc as fmtPercLegacy, formatAllInSameUnit, formatAllInSameWaterUnit, formatDateForInput, formatDateToYMD, formatDateWithTimezoneOffset, formatEnergy, formatNumberReadable, formatTankHeadFromCm, formatWaterByGroup, formatWaterVolumeM3, getAuthCacheStats, getAvailableContexts, getDateRangeArray, getSaoPauloISOString, getSaoPauloISOStringFixed, getValueByDatakey, getValueByDatakeyLegacy, getWaterCategories, groupByDay, isWaterCategory, normalizeRecipients, numbers, openDashboardPopup, openDashboardPopupAllReport, openDashboardPopupEnergy, openDashboardPopupReport, openDashboardPopupSettings, openDemandModal, parseInputDateToDate, renderCardCompenteHeadOffice, renderCardComponent$1 as renderCardComponent, renderCardComponent as renderCardComponentEnhanced, renderCardComponentLegacy, renderCardComponentV2, strings, timeWindowFromInputYMD, toCSV, toFixedSafe };
|
package/dist/index.js
CHANGED
|
@@ -1432,6 +1432,88 @@ function getAuthCacheStats() {
|
|
|
1432
1432
|
};
|
|
1433
1433
|
}
|
|
1434
1434
|
|
|
1435
|
+
// src/thingsboard/api/fetchThingsboardCustomerServerScopeAttrs.ts
|
|
1436
|
+
async function fetchThingsboardCustomerServerScopeAttrs(config) {
|
|
1437
|
+
const { customerId, tbToken, baseUrl = "" } = config;
|
|
1438
|
+
if (!customerId || !tbToken) {
|
|
1439
|
+
throw new Error("customerId and tbToken are required");
|
|
1440
|
+
}
|
|
1441
|
+
const url = `${baseUrl}/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
|
|
1442
|
+
try {
|
|
1443
|
+
const response = await fetch(url, {
|
|
1444
|
+
method: "GET",
|
|
1445
|
+
headers: {
|
|
1446
|
+
"Content-Type": "application/json",
|
|
1447
|
+
"X-Authorization": `Bearer ${tbToken}`
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
if (!response.ok) {
|
|
1451
|
+
console.warn(`[ThingsBoard Customer Attrs] HTTP ${response.status} ${response.statusText}`);
|
|
1452
|
+
if (response.status === 404 || response.status === 403) {
|
|
1453
|
+
return {};
|
|
1454
|
+
}
|
|
1455
|
+
throw new Error(`ThingsBoard API error: HTTP ${response.status} ${response.statusText}`);
|
|
1456
|
+
}
|
|
1457
|
+
const payload = await response.json();
|
|
1458
|
+
return processAttributesResponse(payload);
|
|
1459
|
+
} catch (error) {
|
|
1460
|
+
console.error("[ThingsBoard Customer Attrs] Error fetching attributes:", error);
|
|
1461
|
+
if (error instanceof Error) {
|
|
1462
|
+
throw new Error(`Failed to fetch customer attributes: ${error.message}`);
|
|
1463
|
+
}
|
|
1464
|
+
throw new Error("Failed to fetch customer attributes: Unknown error");
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
function processAttributesResponse(payload) {
|
|
1468
|
+
const attributesMap = {};
|
|
1469
|
+
if (!payload) {
|
|
1470
|
+
return attributesMap;
|
|
1471
|
+
}
|
|
1472
|
+
if (Array.isArray(payload)) {
|
|
1473
|
+
for (const item of payload) {
|
|
1474
|
+
if (item && typeof item === "object" && item.key !== void 0) {
|
|
1475
|
+
attributesMap[item.key] = item.value;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return attributesMap;
|
|
1479
|
+
}
|
|
1480
|
+
if (typeof payload === "object") {
|
|
1481
|
+
for (const key of Object.keys(payload)) {
|
|
1482
|
+
const value = payload[key];
|
|
1483
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
1484
|
+
const firstItem = value[0];
|
|
1485
|
+
attributesMap[key] = firstItem?.value ?? firstItem;
|
|
1486
|
+
} else {
|
|
1487
|
+
attributesMap[key] = value;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return attributesMap;
|
|
1491
|
+
}
|
|
1492
|
+
console.warn("[ThingsBoard Customer Attrs] Unexpected payload format:", typeof payload);
|
|
1493
|
+
return attributesMap;
|
|
1494
|
+
}
|
|
1495
|
+
async function fetchThingsboardCustomerAttrsFromStorage(customerId, tbToken, baseUrl) {
|
|
1496
|
+
return fetchThingsboardCustomerServerScopeAttrs({
|
|
1497
|
+
customerId,
|
|
1498
|
+
tbToken,
|
|
1499
|
+
baseUrl
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
function extractMyIOCredentials(attributes) {
|
|
1503
|
+
if (!attributes || typeof attributes !== "object") {
|
|
1504
|
+
return {
|
|
1505
|
+
clientId: "",
|
|
1506
|
+
clientSecret: "",
|
|
1507
|
+
ingestionId: ""
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
return {
|
|
1511
|
+
clientId: attributes.client_id || attributes.clientId || "",
|
|
1512
|
+
clientSecret: attributes.client_secret || attributes.clientSecret || "",
|
|
1513
|
+
ingestionId: attributes.ingestionId || attributes.ingestion_id || ""
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1435
1517
|
// src/utils/deviceType.js
|
|
1436
1518
|
function normalize(str) {
|
|
1437
1519
|
if (typeof str !== "string") return "";
|
|
@@ -10127,6 +10209,9 @@ export {
|
|
|
10127
10209
|
determineInterval,
|
|
10128
10210
|
exportToCSV,
|
|
10129
10211
|
exportToCSVAll,
|
|
10212
|
+
extractMyIOCredentials,
|
|
10213
|
+
fetchThingsboardCustomerAttrsFromStorage,
|
|
10214
|
+
fetchThingsboardCustomerServerScopeAttrs,
|
|
10130
10215
|
findValue,
|
|
10131
10216
|
fmtPerc,
|
|
10132
10217
|
fmtPerc2 as fmtPercLegacy,
|
|
@@ -1438,6 +1438,88 @@
|
|
|
1438
1438
|
};
|
|
1439
1439
|
}
|
|
1440
1440
|
|
|
1441
|
+
// src/thingsboard/api/fetchThingsboardCustomerServerScopeAttrs.ts
|
|
1442
|
+
async function fetchThingsboardCustomerServerScopeAttrs(config) {
|
|
1443
|
+
const { customerId, tbToken, baseUrl = "" } = config;
|
|
1444
|
+
if (!customerId || !tbToken) {
|
|
1445
|
+
throw new Error("customerId and tbToken are required");
|
|
1446
|
+
}
|
|
1447
|
+
const url = `${baseUrl}/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
|
|
1448
|
+
try {
|
|
1449
|
+
const response = await fetch(url, {
|
|
1450
|
+
method: "GET",
|
|
1451
|
+
headers: {
|
|
1452
|
+
"Content-Type": "application/json",
|
|
1453
|
+
"X-Authorization": `Bearer ${tbToken}`
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
if (!response.ok) {
|
|
1457
|
+
console.warn(`[ThingsBoard Customer Attrs] HTTP ${response.status} ${response.statusText}`);
|
|
1458
|
+
if (response.status === 404 || response.status === 403) {
|
|
1459
|
+
return {};
|
|
1460
|
+
}
|
|
1461
|
+
throw new Error(`ThingsBoard API error: HTTP ${response.status} ${response.statusText}`);
|
|
1462
|
+
}
|
|
1463
|
+
const payload = await response.json();
|
|
1464
|
+
return processAttributesResponse(payload);
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
console.error("[ThingsBoard Customer Attrs] Error fetching attributes:", error);
|
|
1467
|
+
if (error instanceof Error) {
|
|
1468
|
+
throw new Error(`Failed to fetch customer attributes: ${error.message}`);
|
|
1469
|
+
}
|
|
1470
|
+
throw new Error("Failed to fetch customer attributes: Unknown error");
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
function processAttributesResponse(payload) {
|
|
1474
|
+
const attributesMap = {};
|
|
1475
|
+
if (!payload) {
|
|
1476
|
+
return attributesMap;
|
|
1477
|
+
}
|
|
1478
|
+
if (Array.isArray(payload)) {
|
|
1479
|
+
for (const item of payload) {
|
|
1480
|
+
if (item && typeof item === "object" && item.key !== void 0) {
|
|
1481
|
+
attributesMap[item.key] = item.value;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return attributesMap;
|
|
1485
|
+
}
|
|
1486
|
+
if (typeof payload === "object") {
|
|
1487
|
+
for (const key of Object.keys(payload)) {
|
|
1488
|
+
const value = payload[key];
|
|
1489
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
1490
|
+
const firstItem = value[0];
|
|
1491
|
+
attributesMap[key] = firstItem?.value ?? firstItem;
|
|
1492
|
+
} else {
|
|
1493
|
+
attributesMap[key] = value;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return attributesMap;
|
|
1497
|
+
}
|
|
1498
|
+
console.warn("[ThingsBoard Customer Attrs] Unexpected payload format:", typeof payload);
|
|
1499
|
+
return attributesMap;
|
|
1500
|
+
}
|
|
1501
|
+
async function fetchThingsboardCustomerAttrsFromStorage(customerId, tbToken, baseUrl) {
|
|
1502
|
+
return fetchThingsboardCustomerServerScopeAttrs({
|
|
1503
|
+
customerId,
|
|
1504
|
+
tbToken,
|
|
1505
|
+
baseUrl
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
function extractMyIOCredentials(attributes) {
|
|
1509
|
+
if (!attributes || typeof attributes !== "object") {
|
|
1510
|
+
return {
|
|
1511
|
+
clientId: "",
|
|
1512
|
+
clientSecret: "",
|
|
1513
|
+
ingestionId: ""
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
return {
|
|
1517
|
+
clientId: attributes.client_id || attributes.clientId || "",
|
|
1518
|
+
clientSecret: attributes.client_secret || attributes.clientSecret || "",
|
|
1519
|
+
ingestionId: attributes.ingestionId || attributes.ingestion_id || ""
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1441
1523
|
// src/utils/deviceType.js
|
|
1442
1524
|
function normalize(str) {
|
|
1443
1525
|
if (typeof str !== "string") return "";
|
|
@@ -10116,6 +10198,9 @@
|
|
|
10116
10198
|
exports.determineInterval = determineInterval;
|
|
10117
10199
|
exports.exportToCSV = exportToCSV;
|
|
10118
10200
|
exports.exportToCSVAll = exportToCSVAll;
|
|
10201
|
+
exports.extractMyIOCredentials = extractMyIOCredentials;
|
|
10202
|
+
exports.fetchThingsboardCustomerAttrsFromStorage = fetchThingsboardCustomerAttrsFromStorage;
|
|
10203
|
+
exports.fetchThingsboardCustomerServerScopeAttrs = fetchThingsboardCustomerServerScopeAttrs;
|
|
10119
10204
|
exports.findValue = findValue;
|
|
10120
10205
|
exports.fmtPerc = fmtPerc;
|
|
10121
10206
|
exports.fmtPercLegacy = fmtPerc2;
|