@controleonline/ui-common 1.2.70
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/.github/agents/developer.agent.md +30 -0
- package/.github/agents/devops.agent.md +30 -0
- package/.github/agents/qa.agent.md +30 -0
- package/.github/agents/security.agent.md +30 -0
- package/.github/workflows/npmjs.yml +35 -0
- package/.github/workflows/pull-request-checks.yml +19 -0
- package/.scrutinizer.yml +24 -0
- package/FUNDING.yml +1 -0
- package/package.json +28 -0
- package/src/api/fetch.js +74 -0
- package/src/api/index.js +155 -0
- package/src/api/localDB.js +131 -0
- package/src/api/queue.js +66 -0
- package/src/react/assets/tap.mp3 +0 -0
- package/src/react/components/AddImportModal.js +157 -0
- package/src/react/components/AddImportModal.styles.js +81 -0
- package/src/react/components/BackgroundRuntimeBridge.js +219 -0
- package/src/react/components/BottomNavigationBar.config.js +238 -0
- package/src/react/components/BottomNavigationBar.js +120 -0
- package/src/react/components/BottomNavigationBar.styles.js +110 -0
- package/src/react/components/CategoryForm.js +572 -0
- package/src/react/components/CategoryForm.styles.js +334 -0
- package/src/react/components/ConfirmModal.js +24 -0
- package/src/react/components/ConfirmModal.styles.js +43 -0
- package/src/react/components/ContextHelpButton.js +69 -0
- package/src/react/components/ContextHelpButton.styles.js +62 -0
- package/src/react/components/DefaultProvider.native.js +848 -0
- package/src/react/components/DefaultProvider.styles.js +21 -0
- package/src/react/components/DefaultProvider.web.js +909 -0
- package/src/react/components/DeliveryPushBridge.native.js +314 -0
- package/src/react/components/DeliveryPushBridge.web.js +5 -0
- package/src/react/components/DeviceAlertSoundService.js +499 -0
- package/src/react/components/EntityLogContent.js +909 -0
- package/src/react/components/EntityLogContent.styles.js +400 -0
- package/src/react/components/EventBus.js +12 -0
- package/src/react/components/KioskModeBridge.js +65 -0
- package/src/react/components/LauncherModeBridge.js +47 -0
- package/src/react/components/LinkedOrderProductsTab.js +388 -0
- package/src/react/components/LinkedOrderProductsTab.styles.js +180 -0
- package/src/react/components/ManagerPushBridge.native.js +345 -0
- package/src/react/components/MessageService.js +314 -0
- package/src/react/components/Paywall/Google.js +89 -0
- package/src/react/components/PrintService.js +778 -0
- package/src/react/components/ProductCatalogCacheService.js +45 -0
- package/src/react/components/RemoteCheckoutService.js +292 -0
- package/src/react/components/RuntimeBottomNavigationBar.js +151 -0
- package/src/react/components/RuntimeInfoFooter.js +214 -0
- package/src/react/components/RuntimeInfoFooter.styles.js +56 -0
- package/src/react/components/SystemErrorToast.js +29 -0
- package/src/react/components/SystemErrorToast.styles.js +38 -0
- package/src/react/components/TouchFeedbackProvider.js +65 -0
- package/src/react/components/UnifiedPaymentBar.js +155 -0
- package/src/react/components/UnifiedPaymentBar.styles.js +174 -0
- package/src/react/components/WebsocketListener.native.js +487 -0
- package/src/react/components/WebsocketListener.web.js +102 -0
- package/src/react/components/inputs/IdInput.js +49 -0
- package/src/react/components/inputs/IdInput.styles.js +26 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.js +74 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.styles.js +34 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.js +115 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.styles.js +39 -0
- package/src/react/components/lists/CategoriesList.js +56 -0
- package/src/react/components/lists/PaymentTypeList.js +55 -0
- package/src/react/components/lists/ReceiverList.js +56 -0
- package/src/react/components/lists/SelectList.styles.js +18 -0
- package/src/react/components/lists/StatusList.js +55 -0
- package/src/react/components/lists/WalletList.js +54 -0
- package/src/react/components/radio/Spotify.js +144 -0
- package/src/react/components/radio/Spotify.styles.js +32 -0
- package/src/react/components/radio/YouTube.js +82 -0
- package/src/react/components/radio/YouTube.styles.js +16 -0
- package/src/react/components/toastConfig.js +16 -0
- package/src/react/config/deviceConfigBootstrap.js +571 -0
- package/src/react/index.js +4 -0
- package/src/react/localStorage.js +30 -0
- package/src/react/pages/EntityLogPage.js +124 -0
- package/src/react/pages/EntityLogPage.styles.js +17 -0
- package/src/react/pages/GenericLogPage.js +760 -0
- package/src/react/pages/GenericLogPage.styles.js +401 -0
- package/src/react/pages/Imports.js +361 -0
- package/src/react/pages/Imports.styles.js +223 -0
- package/src/react/pages/SettingsPage/PaymentTypesByWalletTab.js +462 -0
- package/src/react/pages/SettingsPage/index.js +1171 -0
- package/src/react/pages/SettingsPage/index.styles.js +122 -0
- package/src/react/print/jobs.js +147 -0
- package/src/react/print/providers/local.js +53 -0
- package/src/react/print/providers/remote.js +81 -0
- package/src/react/print/selection.js +296 -0
- package/src/react/print/usePrintButtonController.js +474 -0
- package/src/react/router/routes.js +42 -0
- package/src/react/services/NetworkPrinterService.native.js +391 -0
- package/src/react/services/NetworkPrinterService.web.js +15 -0
- package/src/react/stores/index.js +128 -0
- package/src/react/stores/storeErrorBridge.js +36 -0
- package/src/react/utils/backgroundRuntimeRegistration.js +69 -0
- package/src/react/utils/cashPayment.js +87 -0
- package/src/react/utils/commercialDocumentOrders.js +269 -0
- package/src/react/utils/dateRangeFilter.js +264 -0
- package/src/react/utils/deviceRuntime.js +193 -0
- package/src/react/utils/entityDisplay.js +231 -0
- package/src/react/utils/entityLog.js +649 -0
- package/src/react/utils/fileUrl.js +102 -0
- package/src/react/utils/frontendDebugLog.js +45 -0
- package/src/react/utils/googleMapsConfig.js +49 -0
- package/src/react/utils/importStatus.js +100 -0
- package/src/react/utils/invoiceDueDateMessages.js +14 -0
- package/src/react/utils/invoicePresentation.js +46 -0
- package/src/react/utils/logSettings.js +143 -0
- package/src/react/utils/maintenanceSettings.js +53 -0
- package/src/react/utils/managerOrderNotifications.js +523 -0
- package/src/react/utils/mapNavigation.js +76 -0
- package/src/react/utils/menuCatalogConfig.js +8 -0
- package/src/react/utils/menuCatalogDownload.js +157 -0
- package/src/react/utils/networkCameraDevices.js +175 -0
- package/src/react/utils/networkDeviceProfiles.js +135 -0
- package/src/react/utils/normalizedCatalogDownload.js +157 -0
- package/src/react/utils/notificationNavigation.js +94 -0
- package/src/react/utils/notificationSound.js +42 -0
- package/src/react/utils/paymentDevices.js +397 -0
- package/src/react/utils/paymentGatewayExecution.js +91 -0
- package/src/react/utils/paymentOptions.js +88 -0
- package/src/react/utils/peopleDisplay.js +39 -0
- package/src/react/utils/printerDevices.js +465 -0
- package/src/react/utils/remotePayment.js +61 -0
- package/src/react/utils/runtimeFooter.js +475 -0
- package/src/react/utils/runtimeLanguage.js +50 -0
- package/src/react/utils/runtimeMenu.js +224 -0
- package/src/react/utils/screenMetrics.js +30 -0
- package/src/react/utils/shopConfig.js +294 -0
- package/src/react/utils/shopFranchises.js +114 -0
- package/src/react/utils/socketRuntimePipeline.js +454 -0
- package/src/react/utils/spoolAckTracker.js +77 -0
- package/src/react/utils/storeColumns.js +427 -0
- package/src/react/utils/systemErrorChannel.js +109 -0
- package/src/react/utils/systemErrorMessage.js +67 -0
- package/src/react/utils/toastPresentation.js +53 -0
- package/src/react/utils/websocketSharedRuntime.js +826 -0
- package/src/store/acl/getters.js +4 -0
- package/src/store/acl/index.js +19 -0
- package/src/store/acl/mutation_types.js +4 -0
- package/src/store/acl/mutations.js +17 -0
- package/src/store/address/city.js +22 -0
- package/src/store/categories/category_file/index.js +25 -0
- package/src/store/categories/index.js +93 -0
- package/src/store/configs/customActions.js +131 -0
- package/src/store/configs/index.js +25 -0
- package/src/store/connections/customActions.js +26 -0
- package/src/store/connections/index.js +124 -0
- package/src/store/device/index.js +22 -0
- package/src/store/device_config/customActions.js +190 -0
- package/src/store/device_config/index.js +28 -0
- package/src/store/entity_log/customActions.js +63 -0
- package/src/store/entity_log/index.js +25 -0
- package/src/store/extra/data.js +85 -0
- package/src/store/extra/fields.js +88 -0
- package/src/store/file/actions.js +27 -0
- package/src/store/file/index.js +24 -0
- package/src/store/imports/index.js +88 -0
- package/src/store/print/customActions.js +251 -0
- package/src/store/print/index.js +28 -0
- package/src/store/printer/customActions.js +54 -0
- package/src/store/printer/index.js +26 -0
- package/src/store/runtime_debug/customActions.js +71 -0
- package/src/store/runtime_debug/index.js +30 -0
- package/src/store/status/index.js +65 -0
- package/src/store/timezones/index.js +43 -0
- package/src/store/websocket/customActions.js +24 -0
- package/src/store/websocket/index.js +28 -0
- package/src/tests/react/components/LauncherModeBridge.test.js +93 -0
- package/src/tests/react/config/deviceConfigBootstrap.test.js +337 -0
- package/src/tests/react/print/localPrintProvider.test.js +45 -0
- package/src/tests/react/utils/backgroundRuntimeRegistration.test.js +123 -0
- package/src/tests/react/utils/cashPayment.test.js +41 -0
- package/src/tests/react/utils/dateRangeFilter.test.mjs +29 -0
- package/src/tests/react/utils/entityDisplay.test.js +18 -0
- package/src/tests/react/utils/googleMapsConfig.test.js +32 -0
- package/src/tests/react/utils/importStatus.test.js +85 -0
- package/src/tests/react/utils/invoicePresentation.test.mjs +40 -0
- package/src/tests/react/utils/managerOrderNotifications.test.js +127 -0
- package/src/tests/react/utils/mapNavigation.test.js +58 -0
- package/src/tests/react/utils/notificationNavigation.test.js +39 -0
- package/src/tests/react/utils/notificationSound.test.js +27 -0
- package/src/tests/react/utils/paymentDevices.test.js +88 -0
- package/src/tests/react/utils/runtimeFooter.test.js +429 -0
- package/src/tests/react/utils/runtimeLanguage.test.js +80 -0
- package/src/tests/react/utils/runtimeMenu.test.js +174 -0
- package/src/tests/react/utils/shopFranchises.test.js +82 -0
- package/src/tests/react/utils/socketRuntimePipeline.test.js +124 -0
- package/src/tests/react/utils/spoolAckTracker.test.js +40 -0
- package/src/tests/react/utils/storeErrorBridge.test.js +66 -0
- package/src/tests/react/utils/systemErrorChannel.test.js +58 -0
- package/src/tests/react/utils/systemErrorMessage.test.js +59 -0
- package/src/tests/react/utils/toastPresentation.test.js +75 -0
- package/src/tests/react/utils/translate.test.mjs +396 -0
- package/src/tests/react/utils/websocketSharedRuntime.test.js +245 -0
- package/src/utils/apiEntryPoint.js +31 -0
- package/src/utils/appDomain.js +50 -0
- package/src/utils/config.js +14 -0
- package/src/utils/formatter.js +419 -0
- package/src/utils/integrationConfigs.js +79 -0
- package/src/utils/methods.js +23 -0
- package/src/utils/oauth.js +42 -0
- package/src/utils/translate.js +620 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const normalizeText = value => String(value || '').trim();
|
|
2
|
+
|
|
3
|
+
const normalizeEntityId = value => String(value || '').replace(/\D/g, '');
|
|
4
|
+
|
|
5
|
+
export const getPeopleDisplayName = person => {
|
|
6
|
+
if (!person || typeof person !== 'object') {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const companyLabel = normalizeText(
|
|
11
|
+
person?.alias ||
|
|
12
|
+
person?.fantasy_name ||
|
|
13
|
+
person?.nickname,
|
|
14
|
+
);
|
|
15
|
+
const responsibleLabel = normalizeText(
|
|
16
|
+
person?.name ||
|
|
17
|
+
person?.realname,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (companyLabel && responsibleLabel && companyLabel !== responsibleLabel) {
|
|
21
|
+
return `${companyLabel} - ${responsibleLabel}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return responsibleLabel || companyLabel;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const buildOwnedClientsParams = ({
|
|
28
|
+
currentCompanyId,
|
|
29
|
+
}) => {
|
|
30
|
+
const ownerId = normalizeEntityId(currentCompanyId);
|
|
31
|
+
if (!ownerId) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
'link.company': `/people/${ownerId}`,
|
|
37
|
+
'link.linkType': 'client',
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import {parseConfigsObject} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap';
|
|
2
|
+
import {
|
|
3
|
+
filterDeviceConfigsByCompany,
|
|
4
|
+
isPdvPrinterEnabled,
|
|
5
|
+
normalizeDeviceId,
|
|
6
|
+
} from '@controleonline/ui-common/src/react/utils/paymentDevices';
|
|
7
|
+
|
|
8
|
+
export const PRINT_DEVICE_TYPE = 'PRINT';
|
|
9
|
+
export const PRINTER_DEVICE_TYPE = 'PRINTER';
|
|
10
|
+
export const IP_CAMERA_DEVICE_TYPE = 'IP_CAMERA';
|
|
11
|
+
export const DISPLAY_DEVICE_TYPE = 'DISPLAY';
|
|
12
|
+
export const PDV_DEVICE_TYPE = 'PDV';
|
|
13
|
+
|
|
14
|
+
export const NETWORK_PRINTER_MANAGER_DEVICE_CONFIG_KEY =
|
|
15
|
+
'print-network-manager-device';
|
|
16
|
+
export const NETWORK_PRINTER_PORT_CONFIG_KEY = 'print-network-port';
|
|
17
|
+
export const NETWORK_PRINTER_COLUMNS_CONFIG_KEY = 'print-network-columns';
|
|
18
|
+
export const NETWORK_PRINTER_TRANSPORT_CONFIG_KEY =
|
|
19
|
+
'print-network-transport';
|
|
20
|
+
export const NETWORK_PRINTER_CODE_PAGE_CONFIG_KEY = 'print-network-code-page';
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_NETWORK_PRINTER_PORT = '9100';
|
|
23
|
+
export const DEFAULT_NETWORK_PRINTER_COLUMNS = '48';
|
|
24
|
+
export const DEFAULT_NETWORK_PRINTER_TRANSPORT = 'tcp-raw';
|
|
25
|
+
export const DEFAULT_NETWORK_PRINTER_CODE_PAGE = 'cp850';
|
|
26
|
+
export const DEFAULT_NETWORK_PRINTER_MANUFACTURER = 'Bematech';
|
|
27
|
+
export const DEFAULT_NETWORK_PRINTER_MODEL = 'MP-2800 TH';
|
|
28
|
+
|
|
29
|
+
const safeTrim = value => String(value || '').trim();
|
|
30
|
+
|
|
31
|
+
const parseMetadataObject = metadata => {
|
|
32
|
+
if (!metadata) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof metadata === 'string') {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(metadata);
|
|
39
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
40
|
+
} catch {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return typeof metadata === 'object' ? {...metadata} : {};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const normalizePositiveIntegerString = (value, fallback) => {
|
|
49
|
+
const normalized = safeTrim(value).replace(/\D+/g, '');
|
|
50
|
+
if (!normalized) {
|
|
51
|
+
return fallback;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const numericValue = Number(normalized);
|
|
55
|
+
return Number.isFinite(numericValue) && numericValue > 0
|
|
56
|
+
? String(numericValue)
|
|
57
|
+
: fallback;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const normalizeDeviceType = value => safeTrim(value).toUpperCase();
|
|
61
|
+
export const getDeviceConfigType = deviceConfig =>
|
|
62
|
+
normalizeDeviceType(deviceConfig?.type || deviceConfig?.device?.type);
|
|
63
|
+
export const buildDeviceConfigIri = deviceConfig => {
|
|
64
|
+
const directIri = safeTrim(deviceConfig?.['@id']);
|
|
65
|
+
if (directIri) {
|
|
66
|
+
return directIri;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const configId = safeTrim(deviceConfig?.id);
|
|
70
|
+
return configId ? `/device_configs/${configId}` : '';
|
|
71
|
+
};
|
|
72
|
+
export const getPrinterOptionValue = printer =>
|
|
73
|
+
safeTrim(printer?.configIri) ||
|
|
74
|
+
safeTrim(printer?.selectionValue) ||
|
|
75
|
+
safeTrim(printer?.device);
|
|
76
|
+
export const findPrinterOptionByValue = (printerOptions = [], value = '') => {
|
|
77
|
+
const normalizedValue = safeTrim(value);
|
|
78
|
+
if (!normalizedValue) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const options = Array.isArray(printerOptions) ? printerOptions : [];
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
options.find(option => getPrinterOptionValue(option) === normalizedValue) ||
|
|
86
|
+
options.find(option => normalizeDeviceId(option?.device) === normalizedValue) ||
|
|
87
|
+
null
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const isNetworkPrinterDeviceType = type =>
|
|
92
|
+
[PRINT_DEVICE_TYPE, PRINTER_DEVICE_TYPE].includes(normalizeDeviceType(type));
|
|
93
|
+
|
|
94
|
+
export const isManagedNetworkDeviceType = type =>
|
|
95
|
+
[PRINT_DEVICE_TYPE, PRINTER_DEVICE_TYPE, IP_CAMERA_DEVICE_TYPE].includes(
|
|
96
|
+
normalizeDeviceType(type),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const isPrintCapableDeviceType = type =>
|
|
100
|
+
[PRINT_DEVICE_TYPE, PRINTER_DEVICE_TYPE, PDV_DEVICE_TYPE].includes(
|
|
101
|
+
normalizeDeviceType(type),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
export const isPrintCapableDeviceConfig = deviceConfig => {
|
|
105
|
+
const deviceType = getDeviceConfigType(deviceConfig);
|
|
106
|
+
|
|
107
|
+
if (!isPrintCapableDeviceType(deviceType)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (normalizeDeviceType(deviceType) !== PDV_DEVICE_TYPE) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return isPdvPrinterEnabled(deviceConfig);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const isPrinterDeviceType = isNetworkPrinterDeviceType;
|
|
119
|
+
|
|
120
|
+
export const getDeviceTypeLabel = type => {
|
|
121
|
+
const normalizedType = normalizeDeviceType(type);
|
|
122
|
+
|
|
123
|
+
if (isPrinterDeviceType(normalizedType)) {
|
|
124
|
+
return 'Impressora';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (normalizedType === IP_CAMERA_DEVICE_TYPE) {
|
|
128
|
+
return 'Camera IP';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return normalizedType || 'DEVICE';
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const getPrinterLabel = printer =>
|
|
135
|
+
safeTrim(printer?.alias) ||
|
|
136
|
+
safeTrim(printer?.name) ||
|
|
137
|
+
safeTrim(printer?.device) ||
|
|
138
|
+
'Impressora sem nome';
|
|
139
|
+
|
|
140
|
+
export const normalizePrinterHost = value => safeTrim(value);
|
|
141
|
+
export const normalizePrinterPort = value =>
|
|
142
|
+
normalizePositiveIntegerString(value, DEFAULT_NETWORK_PRINTER_PORT);
|
|
143
|
+
export const normalizePrinterColumns = value =>
|
|
144
|
+
normalizePositiveIntegerString(value, DEFAULT_NETWORK_PRINTER_COLUMNS);
|
|
145
|
+
|
|
146
|
+
export const getPrinterHost = printer => {
|
|
147
|
+
const parsedMetadata = getPrinterMetadata(printer?.metadata);
|
|
148
|
+
return (
|
|
149
|
+
normalizePrinterHost(printer?.device) ||
|
|
150
|
+
normalizePrinterHost(parsedMetadata?.printer?.host)
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const getPrinterMetadata = metadata => parseMetadataObject(metadata);
|
|
155
|
+
|
|
156
|
+
export const getPrinterMetadataField = (metadata, field) => {
|
|
157
|
+
const parsedMetadata = getPrinterMetadata(metadata);
|
|
158
|
+
const printerField = safeTrim(parsedMetadata?.printer?.[field]);
|
|
159
|
+
if (printerField) {
|
|
160
|
+
return printerField;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (field === 'manufacturer') {
|
|
164
|
+
return safeTrim(parsedMetadata?.system?.manufacturer);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (field === 'model') {
|
|
168
|
+
return safeTrim(parsedMetadata?.system?.model);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (field === 'version') {
|
|
172
|
+
return safeTrim(parsedMetadata?.system?.version);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return '';
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const buildNetworkPrinterMetadata = ({
|
|
179
|
+
existingMetadata = {},
|
|
180
|
+
host,
|
|
181
|
+
manufacturer,
|
|
182
|
+
model,
|
|
183
|
+
version,
|
|
184
|
+
transport = DEFAULT_NETWORK_PRINTER_TRANSPORT,
|
|
185
|
+
}) => {
|
|
186
|
+
const parsedMetadata = getPrinterMetadata(existingMetadata);
|
|
187
|
+
const normalizedManufacturer =
|
|
188
|
+
safeTrim(manufacturer) ||
|
|
189
|
+
getPrinterMetadataField(parsedMetadata, 'manufacturer') ||
|
|
190
|
+
null;
|
|
191
|
+
const normalizedModel =
|
|
192
|
+
safeTrim(model) ||
|
|
193
|
+
getPrinterMetadataField(parsedMetadata, 'model') ||
|
|
194
|
+
null;
|
|
195
|
+
const normalizedVersion =
|
|
196
|
+
safeTrim(version) ||
|
|
197
|
+
getPrinterMetadataField(parsedMetadata, 'version') ||
|
|
198
|
+
null;
|
|
199
|
+
const normalizedHost =
|
|
200
|
+
normalizePrinterHost(host) ||
|
|
201
|
+
safeTrim(parsedMetadata?.printer?.host) ||
|
|
202
|
+
null;
|
|
203
|
+
const normalizedTransport =
|
|
204
|
+
safeTrim(transport) ||
|
|
205
|
+
safeTrim(parsedMetadata?.printer?.transport) ||
|
|
206
|
+
DEFAULT_NETWORK_PRINTER_TRANSPORT;
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
...parsedMetadata,
|
|
210
|
+
runtime: safeTrim(parsedMetadata?.runtime) || 'network',
|
|
211
|
+
printer: {
|
|
212
|
+
...(parsedMetadata?.printer || {}),
|
|
213
|
+
host: normalizedHost,
|
|
214
|
+
manufacturer: normalizedManufacturer,
|
|
215
|
+
model: normalizedModel,
|
|
216
|
+
version: normalizedVersion,
|
|
217
|
+
transport: normalizedTransport,
|
|
218
|
+
},
|
|
219
|
+
system: {
|
|
220
|
+
...(parsedMetadata?.system || {}),
|
|
221
|
+
name: safeTrim(parsedMetadata?.system?.name) || 'network-printer',
|
|
222
|
+
version: normalizedVersion,
|
|
223
|
+
manufacturer: normalizedManufacturer,
|
|
224
|
+
model: normalizedModel,
|
|
225
|
+
hardwareType: 'printer',
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const getPrinterManagerDeviceOptions = ({
|
|
231
|
+
deviceConfigs = [],
|
|
232
|
+
companyId,
|
|
233
|
+
excludeDeviceId = null,
|
|
234
|
+
}) =>
|
|
235
|
+
filterDeviceConfigsByCompany(deviceConfigs, companyId)
|
|
236
|
+
.filter(deviceConfig => {
|
|
237
|
+
const deviceId = normalizeDeviceId(deviceConfig?.device?.device);
|
|
238
|
+
const deviceType = getDeviceConfigType(deviceConfig);
|
|
239
|
+
return (
|
|
240
|
+
deviceId &&
|
|
241
|
+
deviceId !== normalizeDeviceId(excludeDeviceId) &&
|
|
242
|
+
[PDV_DEVICE_TYPE, DISPLAY_DEVICE_TYPE].includes(deviceType)
|
|
243
|
+
);
|
|
244
|
+
})
|
|
245
|
+
.map(deviceConfig => {
|
|
246
|
+
const deviceId = normalizeDeviceId(deviceConfig?.device?.device);
|
|
247
|
+
const deviceType = getDeviceConfigType(deviceConfig);
|
|
248
|
+
const alias =
|
|
249
|
+
safeTrim(deviceConfig?.device?.alias) ||
|
|
250
|
+
deviceId ||
|
|
251
|
+
`Device #${deviceConfig?.id || '--'}`;
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
alias,
|
|
255
|
+
deviceId,
|
|
256
|
+
deviceType,
|
|
257
|
+
label: `${alias} (${deviceType})`,
|
|
258
|
+
};
|
|
259
|
+
})
|
|
260
|
+
.sort((left, right) => left.label.localeCompare(right.label));
|
|
261
|
+
|
|
262
|
+
export const getPrinterOptions = ({
|
|
263
|
+
printers = [],
|
|
264
|
+
deviceConfigs = [],
|
|
265
|
+
companyId = null,
|
|
266
|
+
}) => {
|
|
267
|
+
const printerMap = new Map();
|
|
268
|
+
|
|
269
|
+
const assignPrinter = (mapKey, printer, currentValue = {}) => {
|
|
270
|
+
const deviceId = normalizeDeviceId(printer?.device || printer?.deviceId);
|
|
271
|
+
if (!deviceId) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const nextMetadata = getPrinterMetadata(printer?.metadata);
|
|
276
|
+
const currentConfigs = parseConfigsObject(currentValue?.configs);
|
|
277
|
+
const nextConfigs = parseConfigsObject(printer?.configs);
|
|
278
|
+
|
|
279
|
+
printerMap.set(mapKey, {
|
|
280
|
+
...currentValue,
|
|
281
|
+
...printer,
|
|
282
|
+
device: deviceId,
|
|
283
|
+
alias:
|
|
284
|
+
safeTrim(printer?.alias) ||
|
|
285
|
+
safeTrim(currentValue?.alias) ||
|
|
286
|
+
safeTrim(printer?.name) ||
|
|
287
|
+
safeTrim(currentValue?.name) ||
|
|
288
|
+
deviceId,
|
|
289
|
+
type:
|
|
290
|
+
normalizeDeviceType(printer?.type || printer?.deviceType) ||
|
|
291
|
+
normalizeDeviceType(currentValue?.type || currentValue?.deviceType),
|
|
292
|
+
configId: safeTrim(printer?.configId || currentValue?.configId),
|
|
293
|
+
configIri: safeTrim(printer?.configIri || currentValue?.configIri),
|
|
294
|
+
config: printer?.config || currentValue?.config,
|
|
295
|
+
metadata:
|
|
296
|
+
Object.keys(nextMetadata).length > 0
|
|
297
|
+
? nextMetadata
|
|
298
|
+
: getPrinterMetadata(currentValue?.metadata),
|
|
299
|
+
configs:
|
|
300
|
+
Object.keys(nextConfigs).length > 0 ? nextConfigs : currentConfigs,
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
filterDeviceConfigsByCompany(deviceConfigs, companyId)
|
|
305
|
+
.filter(isPrintCapableDeviceConfig)
|
|
306
|
+
.forEach(deviceConfig => {
|
|
307
|
+
const deviceId = normalizeDeviceId(
|
|
308
|
+
deviceConfig?.device?.device || deviceConfig?.device?.id,
|
|
309
|
+
);
|
|
310
|
+
const configIri = buildDeviceConfigIri(deviceConfig);
|
|
311
|
+
const mapKey =
|
|
312
|
+
configIri ||
|
|
313
|
+
`${deviceId}::${getDeviceConfigType(deviceConfig) || 'DEVICE'}`;
|
|
314
|
+
|
|
315
|
+
assignPrinter(mapKey, {
|
|
316
|
+
...(deviceConfig?.device || {}),
|
|
317
|
+
type: getDeviceConfigType(deviceConfig),
|
|
318
|
+
configId: safeTrim(deviceConfig?.id),
|
|
319
|
+
configIri,
|
|
320
|
+
config: deviceConfig,
|
|
321
|
+
configs: parseConfigsObject(deviceConfig?.configs),
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
(Array.isArray(printers) ? printers : []).forEach(printer => {
|
|
326
|
+
const deviceId = normalizeDeviceId(printer?.device || printer?.deviceId);
|
|
327
|
+
if (!deviceId) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const matchingEntries = Array.from(printerMap.entries()).filter(
|
|
332
|
+
([, option]) => normalizeDeviceId(option?.device) === deviceId,
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
if (matchingEntries.length > 0) {
|
|
336
|
+
matchingEntries.forEach(([mapKey, currentValue]) => {
|
|
337
|
+
assignPrinter(mapKey, printer, currentValue);
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const fallbackType = normalizeDeviceType(printer?.type || printer?.deviceType);
|
|
343
|
+
const fallbackKey = fallbackType ? `${deviceId}::${fallbackType}` : deviceId;
|
|
344
|
+
assignPrinter(fallbackKey, printer, printerMap.get(fallbackKey) || {});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return Array.from(printerMap.values()).sort((left, right) =>
|
|
348
|
+
`${getPrinterLabel(left)} ${getDeviceTypeLabel(left?.type)}`.localeCompare(
|
|
349
|
+
`${getPrinterLabel(right)} ${getDeviceTypeLabel(right?.type)}`,
|
|
350
|
+
),
|
|
351
|
+
);
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
export const getManagedPrinterDevices = ({
|
|
355
|
+
deviceConfigs = [],
|
|
356
|
+
companyId = null,
|
|
357
|
+
managerDeviceId = null,
|
|
358
|
+
}) => {
|
|
359
|
+
const scopedDeviceConfigs = filterDeviceConfigsByCompany(
|
|
360
|
+
deviceConfigs,
|
|
361
|
+
companyId,
|
|
362
|
+
);
|
|
363
|
+
const normalizedManagerDeviceId = normalizeDeviceId(managerDeviceId);
|
|
364
|
+
const managedPrinterMap = new Map();
|
|
365
|
+
|
|
366
|
+
const assignManagedPrinter = printer => {
|
|
367
|
+
const printerDeviceId = normalizeDeviceId(printer?.device);
|
|
368
|
+
const printerOptionValue =
|
|
369
|
+
getPrinterOptionValue(printer) ||
|
|
370
|
+
(printerDeviceId
|
|
371
|
+
? `${printerDeviceId}::${normalizeDeviceType(printer?.type) || 'DEVICE'}`
|
|
372
|
+
: '');
|
|
373
|
+
|
|
374
|
+
if (!printerDeviceId || !printerOptionValue) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
managedPrinterMap.set(printerOptionValue, {
|
|
379
|
+
...(managedPrinterMap.get(printerOptionValue) || {}),
|
|
380
|
+
...printer,
|
|
381
|
+
device: printerDeviceId,
|
|
382
|
+
configs: parseConfigsObject(printer?.configs),
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
scopedDeviceConfigs
|
|
387
|
+
.filter(deviceConfig => {
|
|
388
|
+
if (!isPrinterDeviceType(getDeviceConfigType(deviceConfig))) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const configs = parseConfigsObject(deviceConfig?.configs);
|
|
393
|
+
return (
|
|
394
|
+
normalizeDeviceId(configs?.[NETWORK_PRINTER_MANAGER_DEVICE_CONFIG_KEY]) ===
|
|
395
|
+
normalizedManagerDeviceId
|
|
396
|
+
);
|
|
397
|
+
})
|
|
398
|
+
.forEach(deviceConfig => {
|
|
399
|
+
assignManagedPrinter({
|
|
400
|
+
...(deviceConfig?.device || {}),
|
|
401
|
+
type: getDeviceConfigType(deviceConfig),
|
|
402
|
+
configId: safeTrim(deviceConfig?.id),
|
|
403
|
+
configIri: buildDeviceConfigIri(deviceConfig),
|
|
404
|
+
config: deviceConfig,
|
|
405
|
+
configs: parseConfigsObject(deviceConfig?.configs),
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
scopedDeviceConfigs
|
|
410
|
+
.filter(
|
|
411
|
+
deviceConfig =>
|
|
412
|
+
getDeviceConfigType(deviceConfig) === DISPLAY_DEVICE_TYPE &&
|
|
413
|
+
normalizeDeviceId(deviceConfig?.device?.device) === normalizedManagerDeviceId,
|
|
414
|
+
)
|
|
415
|
+
.forEach(displayDeviceConfig => {
|
|
416
|
+
const displayConfigs = parseConfigsObject(displayDeviceConfig?.configs);
|
|
417
|
+
const attachedPrinterReference = normalizeDeviceId(displayConfigs?.printer);
|
|
418
|
+
|
|
419
|
+
if (!attachedPrinterReference) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const printerDeviceConfig = scopedDeviceConfigs.find(
|
|
424
|
+
deviceConfig =>
|
|
425
|
+
buildDeviceConfigIri(deviceConfig) === attachedPrinterReference &&
|
|
426
|
+
isPrinterDeviceType(getDeviceConfigType(deviceConfig)),
|
|
427
|
+
) || scopedDeviceConfigs.find(
|
|
428
|
+
deviceConfig =>
|
|
429
|
+
normalizeDeviceId(deviceConfig?.device?.device) ===
|
|
430
|
+
attachedPrinterReference &&
|
|
431
|
+
isPrinterDeviceType(getDeviceConfigType(deviceConfig)),
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
if (!printerDeviceConfig) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const printerConfigs = parseConfigsObject(printerDeviceConfig?.configs);
|
|
439
|
+
const explicitManagerDeviceId = normalizeDeviceId(
|
|
440
|
+
printerConfigs?.[NETWORK_PRINTER_MANAGER_DEVICE_CONFIG_KEY],
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
// When the printer already names a specific manager device, only that
|
|
444
|
+
// device should consume the spool to avoid duplicated prints.
|
|
445
|
+
if (
|
|
446
|
+
explicitManagerDeviceId &&
|
|
447
|
+
explicitManagerDeviceId !== normalizedManagerDeviceId
|
|
448
|
+
) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
assignManagedPrinter({
|
|
453
|
+
...(printerDeviceConfig?.device || {}),
|
|
454
|
+
type: getDeviceConfigType(printerDeviceConfig),
|
|
455
|
+
configId: safeTrim(printerDeviceConfig?.id),
|
|
456
|
+
configIri: buildDeviceConfigIri(printerDeviceConfig),
|
|
457
|
+
config: printerDeviceConfig,
|
|
458
|
+
configs: parseConfigsObject(printerDeviceConfig?.configs),
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
return Array.from(managedPrinterMap.values()).sort((left, right) =>
|
|
463
|
+
getPrinterLabel(left).localeCompare(getPrinterLabel(right)),
|
|
464
|
+
);
|
|
465
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {getPaymentOptionId, getPaymentOptionLabel} from './paymentOptions';
|
|
2
|
+
|
|
3
|
+
export const REMOTE_PAYMENT_MESSAGE_STORE = 'invoice';
|
|
4
|
+
export const REMOTE_PAYMENT_REQUEST_ACTION = 'pay';
|
|
5
|
+
export const REMOTE_PAYMENT_RESULT_ACTION = 'pay-result';
|
|
6
|
+
|
|
7
|
+
const normalizeText = value => String(value || '').trim();
|
|
8
|
+
|
|
9
|
+
const normalizeOrderId = value => normalizeText(value).replace(/\D/g, '');
|
|
10
|
+
|
|
11
|
+
export const normalizeRemotePaymentRequestKey = value => normalizeText(value);
|
|
12
|
+
|
|
13
|
+
export const buildRemotePaymentRequestKey = ({
|
|
14
|
+
orderId,
|
|
15
|
+
payment,
|
|
16
|
+
targetDeviceId,
|
|
17
|
+
}) =>
|
|
18
|
+
[
|
|
19
|
+
normalizeOrderId(orderId) || 'order',
|
|
20
|
+
normalizeText(targetDeviceId) || 'device',
|
|
21
|
+
getPaymentOptionId(payment) || 'payment',
|
|
22
|
+
Date.now().toString(),
|
|
23
|
+
].join(':');
|
|
24
|
+
|
|
25
|
+
export const isRemotePaymentRequestMessage = message =>
|
|
26
|
+
normalizeText(message?.action).toLowerCase() ===
|
|
27
|
+
REMOTE_PAYMENT_REQUEST_ACTION;
|
|
28
|
+
|
|
29
|
+
export const isRemotePaymentResultMessage = message =>
|
|
30
|
+
normalizeText(message?.action).toLowerCase() ===
|
|
31
|
+
REMOTE_PAYMENT_RESULT_ACTION;
|
|
32
|
+
|
|
33
|
+
export const buildRemotePaymentResultMessage = ({
|
|
34
|
+
destinationDeviceId,
|
|
35
|
+
error = '',
|
|
36
|
+
invoice = null,
|
|
37
|
+
orderId,
|
|
38
|
+
paidAmount = 0,
|
|
39
|
+
payment = null,
|
|
40
|
+
requestKey,
|
|
41
|
+
status = 'error',
|
|
42
|
+
targetDeviceId,
|
|
43
|
+
targetDeviceLabel = '',
|
|
44
|
+
targetGateway = '',
|
|
45
|
+
total = 0,
|
|
46
|
+
}) => ({
|
|
47
|
+
destination: normalizeText(destinationDeviceId),
|
|
48
|
+
store: REMOTE_PAYMENT_MESSAGE_STORE,
|
|
49
|
+
action: REMOTE_PAYMENT_RESULT_ACTION,
|
|
50
|
+
requestKey: normalizeRemotePaymentRequestKey(requestKey),
|
|
51
|
+
status: normalizeText(status).toLowerCase() === 'success' ? 'success' : 'error',
|
|
52
|
+
order: normalizeOrderId(orderId),
|
|
53
|
+
total: Number(total || 0),
|
|
54
|
+
paidAmount: Number(paidAmount || 0),
|
|
55
|
+
paymentLabel: getPaymentOptionLabel(payment),
|
|
56
|
+
targetDeviceId: normalizeText(targetDeviceId),
|
|
57
|
+
targetDeviceLabel: normalizeText(targetDeviceLabel),
|
|
58
|
+
targetGateway: normalizeText(targetGateway),
|
|
59
|
+
...(invoice ? {invoice} : {}),
|
|
60
|
+
...(error ? {error: normalizeText(error)} : {}),
|
|
61
|
+
});
|