@controleonline/ui-common 1.2.71 → 1.2.76

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.
Files changed (150) hide show
  1. package/.github/actions/workers/manager/action.yml +147 -0
  2. package/.github/actions/workers/qa/action.yml +44 -0
  3. package/.github/actions/workers/security/action.yml +44 -0
  4. package/.github/actions/workers/technical-documenter/action.yml +51 -0
  5. package/.github/workflows/manager-worker.yml +168 -0
  6. package/.github/workflows/publish-npm.yml +45 -0
  7. package/.gitmodules +3 -0
  8. package/AGENTS.md +6 -0
  9. package/README.md +14 -0
  10. package/package.json +3 -2
  11. package/src/api/fetch.js +1 -1
  12. package/src/api/index.js +92 -22
  13. package/src/react/components/AddImportModal.js +94 -110
  14. package/src/react/components/BottomNavigationBar.config.js +211 -231
  15. package/src/react/components/CategoryForm.js +52 -35
  16. package/src/react/components/DefaultProvider.native.js +131 -95
  17. package/src/react/components/DefaultProvider.web.js +148 -74
  18. package/src/react/components/NetworkPrinterPreviewModal.js +249 -0
  19. package/src/react/components/NetworkPrinterPreviewModal.styles.js +159 -0
  20. package/src/react/components/RuntimeInfoFooter.js +164 -104
  21. package/src/react/components/RuntimeInfoFooter.styles.js +3 -0
  22. package/src/react/components/UnifiedPaymentBar.js +7 -4
  23. package/src/react/components/UserAvatar.js +160 -0
  24. package/src/react/components/integrations/IntegrationHero/index.js +48 -0
  25. package/src/react/components/integrations/IntegrationHero/styles.js +57 -0
  26. package/src/react/components/integrations/IntegrationTabs/index.js +89 -0
  27. package/src/react/components/integrations/IntegrationTabs/styles.js +44 -0
  28. package/src/react/config/deviceConfigBootstrap.js +5 -3
  29. package/src/react/pages/Connections.js +229 -0
  30. package/src/react/pages/Connections.styles.js +222 -0
  31. package/src/react/pages/DeviceDetailPage.js +2865 -0
  32. package/src/react/pages/DeviceDetailPage.styles.js +308 -0
  33. package/src/react/pages/Devices/currentDevice.js +194 -0
  34. package/src/react/pages/Devices/deviceTypes/DeviceGroupCard.js +257 -0
  35. package/src/react/pages/Devices/deviceTypes/all.js +23 -0
  36. package/src/react/pages/Devices/deviceTypes/device.js +25 -0
  37. package/src/react/pages/Devices/deviceTypes/deviceListHelpers.js +178 -0
  38. package/src/react/pages/Devices/deviceTypes/display.js +26 -0
  39. package/src/react/pages/Devices/deviceTypes/index.js +145 -0
  40. package/src/react/pages/Devices/deviceTypes/ipCamera.js +35 -0
  41. package/src/react/pages/Devices/deviceTypes/pdv.js +88 -0
  42. package/src/react/pages/Devices/deviceTypes/printer.js +37 -0
  43. package/src/react/pages/Devices/deviceTypes/shared.js +453 -0
  44. package/src/react/pages/Devices/deviceTypes/useDeviceNetworkConnectivity.js +145 -0
  45. package/src/react/pages/Devices.js +183 -0
  46. package/src/react/pages/Devices.styles.js +353 -0
  47. package/src/react/pages/Food99IntegrationPage/components/Food99CatalogTab.js +219 -0
  48. package/src/react/pages/Food99IntegrationPage/components/Food99OverviewTab.js +134 -0
  49. package/src/react/pages/Food99IntegrationPage/components/Food99PreviewModal.js +173 -0
  50. package/src/react/pages/Food99IntegrationPage/components/Food99ProductCard.js +1 -0
  51. package/src/react/pages/Food99IntegrationPage/components/Food99QuickWalletModal.js +181 -0
  52. package/src/react/pages/Food99IntegrationPage/components/Food99SettingsTab.js +306 -0
  53. package/src/react/pages/Food99IntegrationPage/components/Food99StoreTab.js +417 -0
  54. package/src/react/pages/Food99IntegrationPage/index.js +1530 -0
  55. package/src/react/pages/Food99IntegrationPage/styles.js +792 -0
  56. package/src/react/pages/Food99IntegrationPage/utils.js +155 -0
  57. package/src/react/pages/Food99IntegrationPage.js +1 -0
  58. package/src/react/pages/Food99IntegrationPage.styles.js +1 -0
  59. package/src/react/pages/GenericLogPage.js +42 -167
  60. package/src/react/pages/IFoodIntegrationPage/components/IFoodCatalogTab.js +8 -0
  61. package/src/react/pages/IFoodIntegrationPage/components/IFoodOperationsTab.js +420 -0
  62. package/src/react/pages/IFoodIntegrationPage/components/IFoodOverviewTab.js +118 -0
  63. package/src/react/pages/IFoodIntegrationPage/components/IFoodPreviewModal.js +103 -0
  64. package/src/react/pages/IFoodIntegrationPage/components/IFoodProductCard.js +1 -0
  65. package/src/react/pages/IFoodIntegrationPage/components/IFoodStoreTab.js +150 -0
  66. package/src/react/pages/IFoodIntegrationPage/index.js +1298 -0
  67. package/src/react/pages/IFoodIntegrationPage/styles.js +764 -0
  68. package/src/react/pages/IFoodIntegrationPage/utils.js +91 -0
  69. package/src/react/pages/IFoodIntegrationPage.js +1 -0
  70. package/src/react/pages/IFoodIntegrationPage.styles.js +1 -0
  71. package/src/react/pages/Imports.js +214 -166
  72. package/src/react/pages/IntegrationConfigPage.js +744 -0
  73. package/src/react/pages/IntegrationConfigPage.styles.js +269 -0
  74. package/src/react/pages/Integrations.js +299 -0
  75. package/src/react/pages/Integrations.styles.js +130 -0
  76. package/src/react/pages/ManagerOrderNotificationsPage.js +642 -0
  77. package/src/react/pages/MarketplaceIntegrationPage/components/MarketplaceProductCard.js +205 -0
  78. package/src/react/pages/MarketplaceIntegrationPage/components/RemoteMarketplaceMenuTab.js +335 -0
  79. package/src/react/pages/MarketplaceIntegrationPage/index.js +60 -0
  80. package/src/react/pages/MarketplaceIntegrationPage/utils.js +137 -0
  81. package/src/react/pages/MercadoLivreIntegrationPage.js +538 -0
  82. package/src/react/pages/PrinterDeviceDetailPage.js +1916 -0
  83. package/src/react/pages/PrinterDeviceDetailPage.styles.js +223 -0
  84. package/src/react/pages/PrinterDeviceFormPage.js +521 -0
  85. package/src/react/pages/PrinterDeviceFormPage.styles.js +159 -0
  86. package/src/react/pages/WhatsAppConnectionPage.js +459 -0
  87. package/src/react/pages/WhatsAppConnectionPage.styles.js +284 -0
  88. package/src/react/pages/integrationsCatalog.js +399 -0
  89. package/src/react/services/Cielo/Cielo.js +193 -193
  90. package/src/react/utils/categoryContexts.js +46 -0
  91. package/src/react/utils/entityDisplay.js +222 -217
  92. package/src/react/utils/fileUrl.js +39 -20
  93. package/src/react/utils/integrationPage.js +16 -0
  94. package/src/react/utils/runtimeFooter.js +40 -22
  95. package/src/react/utils/runtimeLanguage.js +50 -9
  96. package/src/react/utils/runtimeMenu.js +191 -131
  97. package/src/react/utils/runtimeZoom.js +43 -0
  98. package/src/react/utils/shopConfig.js +27 -15
  99. package/src/react/utils/shopFranchises.js +126 -1
  100. package/src/react/utils/storeColumns.js +23 -4
  101. package/src/react/utils/userAvatar.js +104 -0
  102. package/src/store/categories/index.js +48 -20
  103. package/src/store/device_config/index.js +62 -21
  104. package/src/store/entity_log/index.js +22 -1
  105. package/src/store/imports/customActions.js +51 -0
  106. package/src/store/imports/index.js +89 -88
  107. package/src/store/status/index.js +11 -11
  108. package/src/store/themes/index.js +22 -0
  109. package/src/store/timezones/index.js +3 -1
  110. package/src/tests/browser/manager/connections.spec.js +143 -0
  111. package/src/tests/browser/manager/devices-current.spec.js +343 -0
  112. package/src/tests/browser/manager/mercado-livre-integration.spec.js +268 -0
  113. package/src/tests/react/api/deviceHeaders.test.js +114 -0
  114. package/src/tests/react/components/AddImportModal.test.js +166 -0
  115. package/src/tests/react/components/BottomNavigationBar.config.test.js +20 -0
  116. package/src/tests/react/components/UserAvatar.test.js +52 -0
  117. package/src/tests/react/pages/DevicePickerStyles.test.js +47 -0
  118. package/src/tests/react/pages/Devices/deviceListHelpers.test.js +39 -0
  119. package/src/tests/react/pages/DevicesCurrentDevice.test.js +198 -0
  120. package/src/tests/react/pages/connectionsHelpers.test.js +34 -0
  121. package/src/tests/react/pages/mercadoLivreIntegrationPageContract.test.mjs +16 -0
  122. package/src/tests/react/services/Cielo.test.js +190 -190
  123. package/src/tests/react/store/categoriesOrdering.test.js +26 -0
  124. package/src/tests/react/utils/appDomain.test.js +62 -0
  125. package/src/tests/react/utils/entityDisplay.test.js +2 -2
  126. package/src/tests/react/utils/fileUrl.test.js +3 -3
  127. package/src/tests/react/utils/formatter.test.mjs +33 -0
  128. package/src/tests/react/utils/runtimeFooter.test.js +29 -4
  129. package/src/tests/react/utils/runtimeLanguage.test.js +79 -9
  130. package/src/tests/react/utils/runtimeMenu.test.js +198 -134
  131. package/src/tests/react/utils/runtimeZoom.test.js +38 -0
  132. package/src/tests/react/utils/shopConfig.test.js +10 -9
  133. package/src/tests/react/utils/shopFranchises.test.js +43 -0
  134. package/src/tests/react/utils/translate.discovery.test.mjs +170 -0
  135. package/src/tests/react/utils/translate.test.helpers.mjs +152 -0
  136. package/src/tests/react/utils/translate.test.mjs +141 -349
  137. package/src/tests/react/utils/userAvatar.test.js +63 -0
  138. package/src/utils/appDomain.js +15 -4
  139. package/src/utils/formatter.js +104 -16
  140. package/src/utils/integrationConfigs.js +80 -80
  141. package/src/utils/translate.js +222 -438
  142. package/src/utils/translateDiscovery.js +96 -0
  143. package/src/utils/translateNormalize.js +33 -0
  144. package/src/utils/translatePending.js +92 -0
  145. package/src/utils/translateStorage.js +142 -0
  146. package/.github/agents/developer.agent.md +0 -30
  147. package/.github/agents/devops.agent.md +0 -30
  148. package/.github/agents/qa.agent.md +0 -30
  149. package/.github/agents/security.agent.md +0 -30
  150. package/.github/workflows/npmjs.yml +0 -35
@@ -0,0 +1,308 @@
1
+ import { Platform, StyleSheet } from 'react-native';
2
+
3
+ const cardShadow = Platform.select({
4
+ ios: { shadowColor: '#0F172A', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.06, shadowRadius: 12 },
5
+ android: { elevation: 2 },
6
+ web: { boxShadow: '0 4px 12px rgba(15,23,42,0.06)' },
7
+ });
8
+
9
+ const styles = StyleSheet.create({
10
+ container: { flex: 1 },
11
+ scroll: { padding: 16, gap: 14, paddingBottom: 32 },
12
+
13
+ /* Cabeçalho do device */
14
+ deviceHeader: {
15
+ backgroundColor: '#fff',
16
+ borderRadius: 16,
17
+ padding: 14,
18
+ flexDirection: 'row',
19
+ justifyContent: 'space-between',
20
+ alignItems: 'center',
21
+ ...cardShadow,
22
+ },
23
+ deviceHeaderLeft: { flexDirection: 'row', alignItems: 'center', gap: 12, flex: 1, minWidth: 0 },
24
+ deviceIconBox: { width: 42, height: 42, borderRadius: 12, alignItems: 'center', justifyContent: 'center', flexShrink: 0 },
25
+ aliasBlock: { flex: 1, minWidth: 0 },
26
+ aliasRow: { flexDirection: 'row', alignItems: 'center', gap: 6, minWidth: 0 },
27
+ aliasInput: {
28
+ flex: 1,
29
+ fontSize: 15, fontWeight: '700', color: '#0F172A',
30
+ borderBottomWidth: 1.5, borderBottomColor: '#0EA5E9',
31
+ paddingVertical: 2, paddingHorizontal: 0,
32
+ outlineStyle: 'none',
33
+ },
34
+ editAliasBtn: {
35
+ width: 34, height: 34, borderRadius: 8, borderWidth: 1,
36
+ alignItems: 'center', justifyContent: 'center',
37
+ flexShrink: 0,
38
+ },
39
+ deviceAlias: { fontSize: 15, fontWeight: '800', color: '#0F172A', flex: 1 },
40
+ deviceString: { fontSize: 11, color: '#94A3B8', marginTop: 2 },
41
+ deviceHeaderRight: { flexDirection: 'row', alignItems: 'center', gap: 8 },
42
+ toggleBtn: {
43
+ flexDirection: 'row', alignItems: 'center', gap: 5,
44
+ paddingHorizontal: 12, paddingVertical: 8, borderRadius: 10,
45
+ },
46
+ toggleBtnText: { fontSize: 12, fontWeight: '700', color: '#fff' },
47
+
48
+ /* Loading */
49
+ loadingBox: { flexDirection: 'row', gap: 8, alignItems: 'center' },
50
+ loadingText: { fontSize: 12, color: '#64748B', fontWeight: '600' },
51
+
52
+ /* Abas */
53
+ tabsBar: {
54
+ backgroundColor: '#fff',
55
+ borderRadius: 14,
56
+ padding: 6,
57
+ ...cardShadow,
58
+ },
59
+ tabsContent: {
60
+ gap: 6,
61
+ },
62
+ tabButton: {
63
+ minWidth: 126,
64
+ minHeight: 42,
65
+ borderWidth: 1,
66
+ borderRadius: 10,
67
+ paddingHorizontal: 12,
68
+ paddingVertical: 9,
69
+ flexDirection: 'row',
70
+ alignItems: 'center',
71
+ justifyContent: 'center',
72
+ gap: 7,
73
+ },
74
+ tabButtonText: {
75
+ fontSize: 12,
76
+ fontWeight: '800',
77
+ },
78
+
79
+ /* Resumo */
80
+ summaryRow: { flexDirection: 'row', gap: 10 },
81
+ summaryCard: {
82
+ flex: 1, backgroundColor: '#fff', borderRadius: 14,
83
+ padding: 12, ...cardShadow,
84
+ },
85
+ summaryIcon: { marginBottom: 6 },
86
+ summaryLabel: { fontSize: 10, fontWeight: '700', textTransform: 'uppercase', color: '#94A3B8', letterSpacing: 0.3, marginBottom: 4 },
87
+ summaryValue: { fontSize: 16, fontWeight: '800', color: '#0F172A' },
88
+
89
+ /* Seção */
90
+ section: { gap: 10 },
91
+ sectionTitle: {
92
+ fontSize: 13, fontWeight: '800', color: '#334155',
93
+ textTransform: 'uppercase', letterSpacing: 0.4,
94
+ },
95
+ sectionHeaderRow: {
96
+ alignItems: 'center',
97
+ flexDirection: 'row',
98
+ gap: 10,
99
+ justifyContent: 'space-between',
100
+ },
101
+ configCard: {
102
+ backgroundColor: '#fff',
103
+ borderRadius: 14,
104
+ padding: 14,
105
+ gap: 12,
106
+ ...cardShadow,
107
+ },
108
+ sectionTitleRow: {
109
+ alignItems: 'center',
110
+ flexDirection: 'row',
111
+ gap: 8,
112
+ justifyContent: 'space-between',
113
+ },
114
+ configTitle: {
115
+ fontSize: 14,
116
+ fontWeight: '700',
117
+ color: '#0F172A',
118
+ },
119
+ pickerWrap: {
120
+ borderWidth: 1,
121
+ borderColor: '#E2E8F0',
122
+ borderRadius: 12,
123
+ backgroundColor: '#F8FAFC',
124
+ overflow: 'hidden',
125
+ },
126
+ picker: {
127
+ minHeight: 44,
128
+ color: '#0F172A',
129
+ backgroundColor: '#F8FAFC',
130
+ fontSize: 14,
131
+ },
132
+ optionRow: {
133
+ flexDirection: 'row',
134
+ flexWrap: 'wrap',
135
+ gap: 8,
136
+ },
137
+ optionButtonHoverWrap: {
138
+ position: 'relative',
139
+ },
140
+ optionButtonHoverWrapActive: {
141
+ zIndex: 20,
142
+ },
143
+ optionButton: {
144
+ alignItems: 'center',
145
+ alignSelf: 'flex-start',
146
+ backgroundColor: '#F8FAFC',
147
+ borderColor: '#E2E8F0',
148
+ borderRadius: 999,
149
+ borderWidth: 1,
150
+ minHeight: 34,
151
+ paddingHorizontal: 12,
152
+ paddingVertical: 8,
153
+ },
154
+ optionButtonActive: {
155
+ borderColor: '#0EA5E9',
156
+ backgroundColor: '#E0F2FE',
157
+ },
158
+ optionButtonText: {
159
+ color: '#475569',
160
+ fontSize: 12,
161
+ fontWeight: '700',
162
+ },
163
+ optionButtonTextActive: {
164
+ color: '#0369A1',
165
+ },
166
+ optionButtonTooltip: {
167
+ position: 'absolute',
168
+ bottom: '100%',
169
+ left: '50%',
170
+ marginLeft: -130,
171
+ alignItems: 'center',
172
+ paddingBottom: 10,
173
+ zIndex: 30,
174
+ width: 260,
175
+ },
176
+ optionButtonTooltipText: {
177
+ backgroundColor: '#0F172A',
178
+ borderRadius: 12,
179
+ color: '#FFFFFF',
180
+ fontSize: 11,
181
+ fontWeight: '700',
182
+ lineHeight: 15,
183
+ maxWidth: 260,
184
+ paddingHorizontal: 12,
185
+ paddingVertical: 8,
186
+ textAlign: 'center',
187
+ },
188
+ configButton: {
189
+ alignSelf: 'flex-start',
190
+ flexDirection: 'row',
191
+ alignItems: 'center',
192
+ gap: 8,
193
+ borderWidth: 1,
194
+ paddingHorizontal: 14,
195
+ paddingVertical: 10,
196
+ borderRadius: 10,
197
+ },
198
+ configButtonText: {
199
+ fontSize: 13,
200
+ fontWeight: '700',
201
+ },
202
+ toggleRow: {
203
+ borderWidth: 1,
204
+ borderRadius: 12,
205
+ paddingHorizontal: 14,
206
+ paddingVertical: 12,
207
+ flexDirection: 'row',
208
+ justifyContent: 'space-between',
209
+ alignItems: 'center',
210
+ gap: 12,
211
+ },
212
+ toggleRowCopy: {
213
+ flex: 1,
214
+ marginRight: 12,
215
+ },
216
+ toggleRowDisabled: { opacity: 0.6 },
217
+ toggleRowLabel: {
218
+ fontSize: 13,
219
+ fontWeight: '700',
220
+ },
221
+ toggleRowValue: {
222
+ marginTop: 4,
223
+ fontSize: 12,
224
+ },
225
+ textInputWrap: {
226
+ gap: 6,
227
+ },
228
+ textInputLabel: {
229
+ fontSize: 12,
230
+ fontWeight: '700',
231
+ color: '#475569',
232
+ textTransform: 'uppercase',
233
+ letterSpacing: 0.3,
234
+ },
235
+ textInput: {
236
+ minHeight: 46,
237
+ borderWidth: 1,
238
+ borderColor: '#E2E8F0',
239
+ borderRadius: 12,
240
+ backgroundColor: '#fff',
241
+ color: '#0F172A',
242
+ paddingHorizontal: 12,
243
+ paddingVertical: 10,
244
+ outlineStyle: 'none',
245
+ },
246
+
247
+ /* Carteiras / pagamentos */
248
+ walletCard: {
249
+ backgroundColor: '#fff', borderRadius: 14, padding: 14,
250
+ gap: 8, ...cardShadow,
251
+ },
252
+ walletHeader: { flexDirection: 'row', alignItems: 'center', gap: 8 },
253
+ walletName: { flex: 1, fontSize: 14, fontWeight: '700', color: '#0F172A' },
254
+ walletTotal: { fontSize: 15, fontWeight: '800' },
255
+ paymentRow: {
256
+ flexDirection: 'row', alignItems: 'center', gap: 10,
257
+ backgroundColor: '#F8FAFC', borderRadius: 10, paddingHorizontal: 10, paddingVertical: 8,
258
+ },
259
+ paymentIconBox: { width: 26, height: 26, borderRadius: 7, alignItems: 'center', justifyContent: 'center' },
260
+ paymentName: { flex: 1, fontSize: 13, color: '#475569', fontWeight: '600' },
261
+ paymentValue: { fontSize: 14, fontWeight: '800', color: '#0F172A' },
262
+
263
+ /* Tabela de produtos */
264
+ searchRow: {
265
+ flexDirection: 'row', alignItems: 'center', gap: 8,
266
+ backgroundColor: '#fff', borderRadius: 12, paddingHorizontal: 12, paddingVertical: 10,
267
+ ...cardShadow,
268
+ },
269
+ searchInput: { flex: 1, fontSize: 13, color: '#0F172A', paddingVertical: 0 },
270
+ tableContainer: {
271
+ backgroundColor: '#fff', borderRadius: 14, overflow: 'hidden', ...cardShadow,
272
+ },
273
+ tableHeader: {
274
+ flexDirection: 'row', backgroundColor: '#F1F5F9',
275
+ paddingHorizontal: 12, paddingVertical: 8,
276
+ },
277
+ tableHead: { fontSize: 10, fontWeight: '800', color: '#64748B', textTransform: 'uppercase', letterSpacing: 0.3 },
278
+ productRow: { flexDirection: 'row', paddingHorizontal: 12, paddingVertical: 9, alignItems: 'flex-start' },
279
+ productRowAlt: { backgroundColor: '#F8FAFC' },
280
+ productCell: { fontSize: 12, color: '#334155', fontWeight: '500' },
281
+ productName: { fontSize: 12, color: '#334155', fontWeight: '600' },
282
+ productSku: { fontSize: 10, color: '#94A3B8', marginTop: 1 },
283
+ tableFooter: {
284
+ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center',
285
+ paddingHorizontal: 12, paddingVertical: 10,
286
+ borderTopWidth: 1, borderTopColor: '#E2E8F0',
287
+ backgroundColor: '#F8FAFC',
288
+ },
289
+ tableFooterLabel: { fontSize: 12, fontWeight: '700', color: '#64748B', textTransform: 'uppercase' },
290
+ tableFooterValue: { fontSize: 17, fontWeight: '900' },
291
+
292
+ /* Vazio */
293
+ emptyBox: {
294
+ backgroundColor: '#fff', borderRadius: 14, padding: 28,
295
+ alignItems: 'center', ...cardShadow,
296
+ },
297
+ emptyText: { fontSize: 13, color: '#94A3B8', fontWeight: '600', textAlign: 'center' },
298
+ });
299
+
300
+ export default styles;
301
+
302
+ export const inlineStyle_667_12 = {
303
+ flex: 3,
304
+ };
305
+
306
+ export const inlineStyle_1301_61 = {
307
+ marginBottom: 8,
308
+ };
@@ -0,0 +1,194 @@
1
+ import {PDV_DEVICE_TYPE, normalizeDeviceType} from '@controleonline/ui-common/src/react/utils/printerDevices';
2
+ import {
3
+ normalizeDeviceId,
4
+ normalizeEntityId,
5
+ } from '@controleonline/ui-common/src/react/utils/paymentDevices';
6
+
7
+ export const readStoredRuntimeDevice = (storage = globalThis?.localStorage) => {
8
+ if (!storage || typeof storage.getItem !== 'function') {
9
+ return {};
10
+ }
11
+
12
+ try {
13
+ const storedDevice = JSON.parse(storage.getItem('device') || '{}');
14
+ return storedDevice && typeof storedDevice === 'object'
15
+ ? storedDevice
16
+ : {};
17
+ } catch {
18
+ return {};
19
+ }
20
+ };
21
+
22
+ export const getRuntimeDeviceIdentifier = runtimeDevice =>
23
+ normalizeDeviceId(runtimeDevice?.id || runtimeDevice?.device);
24
+
25
+ export const getDeviceConfigIdentifier = deviceConfig =>
26
+ normalizeDeviceId(deviceConfig?.device?.device);
27
+
28
+ export const isCurrentDeviceConfig = ({
29
+ deviceConfig,
30
+ runtimeDeviceIdentifier,
31
+ }) =>
32
+ Boolean(
33
+ runtimeDeviceIdentifier &&
34
+ getDeviceConfigIdentifier(deviceConfig) ===
35
+ normalizeDeviceId(runtimeDeviceIdentifier),
36
+ );
37
+
38
+ export const prioritizeCurrentDeviceConfigs = (
39
+ deviceConfigs = [],
40
+ runtimeDeviceIdentifier = '',
41
+ ) => {
42
+ const current = [];
43
+ const remaining = [];
44
+
45
+ (Array.isArray(deviceConfigs) ? deviceConfigs : []).forEach(deviceConfig => {
46
+ if (isCurrentDeviceConfig({deviceConfig, runtimeDeviceIdentifier})) {
47
+ current.push(deviceConfig);
48
+ return;
49
+ }
50
+
51
+ remaining.push(deviceConfig);
52
+ });
53
+
54
+ return [...current, ...remaining];
55
+ };
56
+
57
+ export const filterDeviceConfigsByTypes = (
58
+ deviceConfigs = [],
59
+ queryTypes = [],
60
+ ) => {
61
+ const normalizedTypes = (Array.isArray(queryTypes) ? queryTypes : [])
62
+ .map(normalizeDeviceType)
63
+ .filter(Boolean);
64
+
65
+ if (normalizedTypes.length === 0) {
66
+ return Array.isArray(deviceConfigs) ? deviceConfigs : [];
67
+ }
68
+
69
+ return (Array.isArray(deviceConfigs) ? deviceConfigs : []).filter(
70
+ deviceConfig =>
71
+ normalizedTypes.includes(normalizeDeviceType(deviceConfig?.type)),
72
+ );
73
+ };
74
+
75
+ export const hasCurrentPdvConfig = (
76
+ deviceConfigs = [],
77
+ runtimeDeviceIdentifier = '',
78
+ ) =>
79
+ (Array.isArray(deviceConfigs) ? deviceConfigs : []).some(
80
+ deviceConfig =>
81
+ isCurrentDeviceConfig({deviceConfig, runtimeDeviceIdentifier}) &&
82
+ normalizeDeviceType(deviceConfig?.type) === PDV_DEVICE_TYPE,
83
+ );
84
+
85
+ export const getDeviceGroupKey = device => {
86
+ const entityId = normalizeEntityId(
87
+ device?.id || device?.['@id'] || device?.entityId || device?.entityIri,
88
+ );
89
+
90
+ if (entityId) {
91
+ return `device:${entityId}`;
92
+ }
93
+
94
+ const identifier = normalizeDeviceId(device?.device || device?.id);
95
+ return identifier ? `identifier:${identifier}` : '';
96
+ };
97
+
98
+ const createRuntimeDevice = runtimeDevice => ({
99
+ id:
100
+ runtimeDevice?.entityId ||
101
+ runtimeDevice?.entityIri ||
102
+ runtimeDevice?.databaseId ||
103
+ null,
104
+ device: getRuntimeDeviceIdentifier(runtimeDevice),
105
+ alias:
106
+ runtimeDevice?.alias ||
107
+ runtimeDevice?.deviceName ||
108
+ runtimeDevice?.modelName ||
109
+ runtimeDevice?.model ||
110
+ 'Este dispositivo',
111
+ metadata: runtimeDevice?.metadata || {},
112
+ });
113
+
114
+ export const groupDeviceConfigs = (
115
+ deviceConfigs = [],
116
+ {includeRuntimeDevice = false, runtimeDevice = {}} = {},
117
+ ) => {
118
+ const groupsByKey = new Map();
119
+
120
+ (Array.isArray(deviceConfigs) ? deviceConfigs : []).forEach(deviceConfig => {
121
+ const device = deviceConfig?.device || {};
122
+ const key =
123
+ getDeviceGroupKey(device) ||
124
+ `config:${normalizeEntityId(deviceConfig?.id || deviceConfig?.['@id'])}`;
125
+
126
+ if (!groupsByKey.has(key)) {
127
+ groupsByKey.set(key, {
128
+ key,
129
+ device,
130
+ deviceConfigs: [],
131
+ });
132
+ }
133
+
134
+ groupsByKey.get(key).deviceConfigs.push(deviceConfig);
135
+ });
136
+
137
+ if (includeRuntimeDevice) {
138
+ const runtimeIdentifier = getRuntimeDeviceIdentifier(runtimeDevice);
139
+ const matchingGroup = [...groupsByKey.values()].find(
140
+ group =>
141
+ normalizeDeviceId(group?.device?.device) === runtimeIdentifier,
142
+ );
143
+
144
+ if (!matchingGroup && runtimeIdentifier) {
145
+ const device = createRuntimeDevice(runtimeDevice);
146
+ const key = getDeviceGroupKey(device) || `identifier:${runtimeIdentifier}`;
147
+ groupsByKey.set(key, {
148
+ key,
149
+ device,
150
+ deviceConfigs: [],
151
+ });
152
+ }
153
+ }
154
+
155
+ return [...groupsByKey.values()];
156
+ };
157
+
158
+ export const isCurrentDeviceGroup = ({
159
+ deviceGroup,
160
+ runtimeDeviceIdentifier,
161
+ }) =>
162
+ Boolean(
163
+ runtimeDeviceIdentifier &&
164
+ normalizeDeviceId(deviceGroup?.device?.device) ===
165
+ normalizeDeviceId(runtimeDeviceIdentifier),
166
+ );
167
+
168
+ export const prioritizeCurrentDeviceGroups = (
169
+ deviceGroups = [],
170
+ runtimeDeviceIdentifier = '',
171
+ ) => {
172
+ const current = [];
173
+ const remaining = [];
174
+
175
+ (Array.isArray(deviceGroups) ? deviceGroups : []).forEach(deviceGroup => {
176
+ if (isCurrentDeviceGroup({deviceGroup, runtimeDeviceIdentifier})) {
177
+ current.push(deviceGroup);
178
+ return;
179
+ }
180
+
181
+ remaining.push(deviceGroup);
182
+ });
183
+
184
+ return [...current, ...remaining];
185
+ };
186
+
187
+ export const findDeviceConfigByType = (deviceGroup, type) => {
188
+ const normalizedType = normalizeDeviceType(type);
189
+
190
+ return (deviceGroup?.deviceConfigs || []).find(
191
+ deviceConfig =>
192
+ normalizeDeviceType(deviceConfig?.type) === normalizedType,
193
+ );
194
+ };