@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,193 @@
|
|
|
1
|
+
import {Platform} from 'react-native';
|
|
2
|
+
import {buildScreenMetrics} from '@controleonline/ui-common/src/react/utils/screenMetrics';
|
|
3
|
+
|
|
4
|
+
const APP_TYPE_DEVICE_MAP = {
|
|
5
|
+
POS: 'PDV',
|
|
6
|
+
PPC: 'DISPLAY',
|
|
7
|
+
DISPLAY: 'DISPLAY',
|
|
8
|
+
KDS: 'KDS',
|
|
9
|
+
PRINT: 'PRINT',
|
|
10
|
+
PRINTER: 'PRINT',
|
|
11
|
+
TOTEM: 'DISPLAY',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const WEB_DEVICE_INSTANCE_STORAGE_KEY = 'web-device-instance-id';
|
|
15
|
+
|
|
16
|
+
const safeTrim = value => String(value || '').trim();
|
|
17
|
+
const isPlainObject = value =>
|
|
18
|
+
!!value && typeof value === 'object' && !Array.isArray(value);
|
|
19
|
+
const normalizeWebUserId = userId => safeTrim(userId).replace(/^web-/, '');
|
|
20
|
+
|
|
21
|
+
const resolveStoredWebUserId = () => {
|
|
22
|
+
if (typeof localStorage === 'undefined') {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const sessionData = JSON.parse(localStorage.getItem('session') || '{}');
|
|
28
|
+
return normalizeWebUserId(sessionData?.id || '');
|
|
29
|
+
} catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const safeStringify = value => {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.stringify(value || {});
|
|
37
|
+
} catch {
|
|
38
|
+
return '{}';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createWebDeviceInstanceId = () => {
|
|
43
|
+
const normalizedUserId = resolveStoredWebUserId();
|
|
44
|
+
if (!normalizedUserId) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `web-${normalizedUserId}`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const getOrCreateWebDeviceInstanceId = () => {
|
|
52
|
+
const nextId = createWebDeviceInstanceId();
|
|
53
|
+
if (!nextId) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof localStorage === 'undefined') {
|
|
58
|
+
return nextId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
localStorage.setItem(WEB_DEVICE_INSTANCE_STORAGE_KEY, nextId);
|
|
63
|
+
return nextId;
|
|
64
|
+
} catch {
|
|
65
|
+
return nextId;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const isWebRuntimeDevice = deviceInfo =>
|
|
70
|
+
deviceInfo?.deviceType === 'web' ||
|
|
71
|
+
deviceInfo?.systemName === 'web' ||
|
|
72
|
+
String(deviceInfo?.id || '').startsWith('web-');
|
|
73
|
+
|
|
74
|
+
export const resolveOperationalDeviceType = ({appType, deviceInfo}) => {
|
|
75
|
+
const normalizedAppType = safeTrim(appType).toUpperCase();
|
|
76
|
+
if (APP_TYPE_DEVICE_MAP[normalizedAppType]) {
|
|
77
|
+
return APP_TYPE_DEVICE_MAP[normalizedAppType];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (normalizedAppType) {
|
|
81
|
+
return normalizedAppType;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (safeTrim(deviceInfo?.type)) {
|
|
85
|
+
return safeTrim(deviceInfo.type).toUpperCase();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (isWebRuntimeDevice(deviceInfo)) {
|
|
89
|
+
return 'WEB';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return 'DEVICE';
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const buildDeviceAlias = ({deviceInfo, appType}) => {
|
|
96
|
+
const resolvedType = resolveOperationalDeviceType({appType, deviceInfo});
|
|
97
|
+
return (
|
|
98
|
+
safeTrim(deviceInfo?.alias) ||
|
|
99
|
+
safeTrim(deviceInfo?.appName) ||
|
|
100
|
+
safeTrim(deviceInfo?.model) ||
|
|
101
|
+
safeTrim(deviceInfo?.manufacturer) ||
|
|
102
|
+
safeTrim(deviceInfo?.id) ||
|
|
103
|
+
resolvedType
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const buildDeviceMetadata = ({deviceInfo, appType}) => {
|
|
108
|
+
const screen = buildScreenMetrics();
|
|
109
|
+
const existingMetadata = isPlainObject(deviceInfo?.metadata)
|
|
110
|
+
? deviceInfo.metadata
|
|
111
|
+
: {};
|
|
112
|
+
const navigatorData =
|
|
113
|
+
typeof navigator !== 'undefined'
|
|
114
|
+
? {
|
|
115
|
+
userAgent: navigator.userAgent || null,
|
|
116
|
+
language: navigator.language || null,
|
|
117
|
+
}
|
|
118
|
+
: {};
|
|
119
|
+
const publicIp = safeTrim(deviceInfo?.externalIp) || null;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
runtime: Platform.OS,
|
|
123
|
+
appType: safeTrim(appType).toUpperCase() || null,
|
|
124
|
+
app: {
|
|
125
|
+
name: safeTrim(deviceInfo?.appName) || null,
|
|
126
|
+
version: safeTrim(deviceInfo?.appVersion) || null,
|
|
127
|
+
buildNumber: safeTrim(deviceInfo?.buildNumber) || null,
|
|
128
|
+
},
|
|
129
|
+
screen: {
|
|
130
|
+
deviceResolution: screen?.deviceResolution || null,
|
|
131
|
+
actualSize: screen?.actualSize || null,
|
|
132
|
+
windosSize: screen?.windosSize || null,
|
|
133
|
+
},
|
|
134
|
+
network: {
|
|
135
|
+
publicIp,
|
|
136
|
+
},
|
|
137
|
+
system: {
|
|
138
|
+
name: safeTrim(deviceInfo?.systemName) || null,
|
|
139
|
+
version: safeTrim(deviceInfo?.systemVersion) || null,
|
|
140
|
+
manufacturer: safeTrim(deviceInfo?.manufacturer) || null,
|
|
141
|
+
model: safeTrim(deviceInfo?.model) || null,
|
|
142
|
+
hardwareType: safeTrim(deviceInfo?.deviceType) || null,
|
|
143
|
+
isEmulator:
|
|
144
|
+
deviceInfo?.isEmulator === undefined ? null : !!deviceInfo.isEmulator,
|
|
145
|
+
batteryLevel:
|
|
146
|
+
deviceInfo?.batteryLevel === undefined ||
|
|
147
|
+
deviceInfo?.batteryLevel === null
|
|
148
|
+
? null
|
|
149
|
+
: Number(deviceInfo.batteryLevel),
|
|
150
|
+
},
|
|
151
|
+
browser: navigatorData,
|
|
152
|
+
...Object.fromEntries(
|
|
153
|
+
Object.entries(existingMetadata).filter(([key]) =>
|
|
154
|
+
!['runtime', 'appType', 'app', 'screen', 'network', 'system', 'browser'].includes(key),
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const buildLocalRuntimeDevice = ({deviceInfo, appType}) => {
|
|
161
|
+
const metadata = buildDeviceMetadata({deviceInfo, appType});
|
|
162
|
+
return {
|
|
163
|
+
...deviceInfo,
|
|
164
|
+
type: resolveOperationalDeviceType({appType, deviceInfo}),
|
|
165
|
+
metadata,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const buildDeviceRegistrationPayload = ({
|
|
170
|
+
deviceInfo,
|
|
171
|
+
appType,
|
|
172
|
+
existingDevice = null,
|
|
173
|
+
}) => {
|
|
174
|
+
const localDevice = buildLocalRuntimeDevice({deviceInfo, appType});
|
|
175
|
+
return {
|
|
176
|
+
id: existingDevice?.id,
|
|
177
|
+
device: localDevice.id,
|
|
178
|
+
alias: existingDevice?.alias || buildDeviceAlias({deviceInfo: localDevice, appType}),
|
|
179
|
+
metadata: localDevice.metadata,
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const hasDeviceRecordChanges = ({existingDevice, nextDevice}) => {
|
|
184
|
+
if (!existingDevice) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
safeTrim(existingDevice.device) !== safeTrim(nextDevice.device) ||
|
|
190
|
+
safeTrim(existingDevice.alias) !== safeTrim(nextDevice.alias) ||
|
|
191
|
+
safeStringify(existingDevice.metadata) !== safeStringify(nextDevice.metadata)
|
|
192
|
+
);
|
|
193
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
const pickFirstText = (...values) => {
|
|
2
|
+
for (const value of values) {
|
|
3
|
+
const normalized = normalizeText(value);
|
|
4
|
+
if (normalized) {
|
|
5
|
+
return normalized;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return '';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const normalizeText = value => {
|
|
13
|
+
if (value === null || value === undefined) return '';
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
typeof value === 'string' ||
|
|
17
|
+
typeof value === 'number' ||
|
|
18
|
+
typeof value === 'bigint' ||
|
|
19
|
+
typeof value === 'boolean'
|
|
20
|
+
) {
|
|
21
|
+
return String(value).trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
for (const item of value) {
|
|
26
|
+
const normalized = normalizeText(item);
|
|
27
|
+
if (normalized) return normalized;
|
|
28
|
+
}
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof value === 'object') {
|
|
33
|
+
const street = String(
|
|
34
|
+
value?.street_name ||
|
|
35
|
+
value?.streetName ||
|
|
36
|
+
value?.street ||
|
|
37
|
+
value?.logradouro ||
|
|
38
|
+
'',
|
|
39
|
+
).trim();
|
|
40
|
+
const number = String(
|
|
41
|
+
value?.street_number ||
|
|
42
|
+
value?.streetNumber ||
|
|
43
|
+
value?.number ||
|
|
44
|
+
value?.house_number ||
|
|
45
|
+
'',
|
|
46
|
+
).trim();
|
|
47
|
+
const streetLine = [street, number].filter(Boolean).join(', ');
|
|
48
|
+
|
|
49
|
+
const candidates = [
|
|
50
|
+
value?.display,
|
|
51
|
+
value?.formattedAddress,
|
|
52
|
+
value?.formatted_address,
|
|
53
|
+
value?.formatted,
|
|
54
|
+
value?.address,
|
|
55
|
+
value?.poi_address,
|
|
56
|
+
value?.value,
|
|
57
|
+
value?.description,
|
|
58
|
+
streetLine,
|
|
59
|
+
value?.district,
|
|
60
|
+
value?.city,
|
|
61
|
+
value?.name,
|
|
62
|
+
value?.reference,
|
|
63
|
+
value?.complement,
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
for (const candidate of candidates) {
|
|
67
|
+
const normalized = normalizeText(candidate);
|
|
68
|
+
if (normalized) return normalized;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return '';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const formatHumanLabel = value => {
|
|
76
|
+
const normalized = normalizeText(value)
|
|
77
|
+
.replace(/[_-]+/g, ' ')
|
|
78
|
+
.replace(/\s+/g, ' ')
|
|
79
|
+
.trim();
|
|
80
|
+
|
|
81
|
+
if (!normalized) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return normalized.replace(
|
|
86
|
+
/(^|[\s([{'"“”‘’])(\p{L})/gu,
|
|
87
|
+
(match, prefix, char) => `${prefix}${char.toLocaleUpperCase('pt-BR')}`,
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const uppercaseText = (value, locale = 'pt-BR') => {
|
|
92
|
+
if (value === null || value === undefined) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const normalized = String(value);
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
return normalized.toLocaleUpperCase(locale);
|
|
100
|
+
} catch {
|
|
101
|
+
return normalized.toUpperCase();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const formatDisplayUppercase = (value, locale = 'pt-BR') => {
|
|
106
|
+
const normalized = normalizeText(value);
|
|
107
|
+
|
|
108
|
+
if (!normalized) {
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return uppercaseText(normalized, locale);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const formatPhoneDisplay = phoneEntry => {
|
|
116
|
+
if (!phoneEntry) return '';
|
|
117
|
+
|
|
118
|
+
if (typeof phoneEntry === 'string' || typeof phoneEntry === 'number') {
|
|
119
|
+
return normalizeText(phoneEntry);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const ddi = normalizeText(phoneEntry?.ddi);
|
|
123
|
+
const ddd = normalizeText(phoneEntry?.ddd);
|
|
124
|
+
const phone = normalizeText(phoneEntry?.phone);
|
|
125
|
+
|
|
126
|
+
if (!phone) return '';
|
|
127
|
+
|
|
128
|
+
return [ddi ? `+${ddi}` : '', ddd ? `(${ddd})` : '', phone]
|
|
129
|
+
.filter(Boolean)
|
|
130
|
+
.join(' ')
|
|
131
|
+
.trim();
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const resolveAddressDisplayParts = address => {
|
|
135
|
+
const streetName = normalizeText(address?.street?.street);
|
|
136
|
+
const streetNumber = normalizeText(address?.number);
|
|
137
|
+
const nickname = normalizeText(address?.nickname);
|
|
138
|
+
const complement = normalizeText(address?.complement);
|
|
139
|
+
const district = normalizeText(address?.street?.district?.district);
|
|
140
|
+
const city = normalizeText(address?.street?.district?.city?.city);
|
|
141
|
+
const state = normalizeText(
|
|
142
|
+
address?.street?.district?.city?.state?.uf ||
|
|
143
|
+
address?.street?.district?.city?.state?.state,
|
|
144
|
+
);
|
|
145
|
+
const postalCode = normalizeText(address?.street?.cep?.cep);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
primary: pickFirstText(
|
|
149
|
+
[streetName, streetNumber].filter(Boolean).join(', '),
|
|
150
|
+
streetName,
|
|
151
|
+
nickname,
|
|
152
|
+
),
|
|
153
|
+
secondary: [district, [city, state].filter(Boolean).join(' / ')].filter(Boolean).join(' • '),
|
|
154
|
+
streetLine: [streetName, streetNumber].filter(Boolean).join(', '),
|
|
155
|
+
district,
|
|
156
|
+
cityStateLine: [city, state].filter(Boolean).join(' / '),
|
|
157
|
+
postalCode,
|
|
158
|
+
complement,
|
|
159
|
+
nickname,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const buildAddressOptionSummary = address => {
|
|
164
|
+
const addressParts = resolveAddressDisplayParts(address);
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
primary: pickFirstText(
|
|
168
|
+
addressParts.primary,
|
|
169
|
+
addressParts.streetLine,
|
|
170
|
+
addressParts.nickname,
|
|
171
|
+
),
|
|
172
|
+
secondary: pickFirstText(
|
|
173
|
+
addressParts.secondary,
|
|
174
|
+
addressParts.postalCode,
|
|
175
|
+
addressParts.complement,
|
|
176
|
+
),
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export const buildCustomerSearchMeta = customer => {
|
|
181
|
+
const phone = pickFirstText(
|
|
182
|
+
Array.isArray(customer?.phone)
|
|
183
|
+
? customer.phone.map(formatPhoneDisplay).find(Boolean)
|
|
184
|
+
: formatPhoneDisplay(customer?.phone),
|
|
185
|
+
);
|
|
186
|
+
const email = pickFirstText(
|
|
187
|
+
Array.isArray(customer?.email)
|
|
188
|
+
? customer.email.map(item => normalizeText(item?.email)).find(Boolean)
|
|
189
|
+
: normalizeText(customer?.email?.email || customer?.email),
|
|
190
|
+
);
|
|
191
|
+
const document = pickFirstText(
|
|
192
|
+
Array.isArray(customer?.document)
|
|
193
|
+
? customer.document.map(item => normalizeText(item?.document)).find(Boolean)
|
|
194
|
+
: normalizeText(customer?.document?.document || customer?.document),
|
|
195
|
+
);
|
|
196
|
+
const address = pickFirstText(
|
|
197
|
+
Array.isArray(customer?.address)
|
|
198
|
+
? customer.address
|
|
199
|
+
.map(item => {
|
|
200
|
+
const summary = buildAddressOptionSummary(item);
|
|
201
|
+
|
|
202
|
+
return pickFirstText(
|
|
203
|
+
item?.search_for,
|
|
204
|
+
summary.primary,
|
|
205
|
+
summary.secondary,
|
|
206
|
+
);
|
|
207
|
+
})
|
|
208
|
+
.find(Boolean)
|
|
209
|
+
: '',
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return [phone, email, document, address].filter(Boolean).join(' • ');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const normalizePostalCodeInput = value =>
|
|
216
|
+
String(value ?? '')
|
|
217
|
+
.replace(/\D+/g, '')
|
|
218
|
+
.slice(0, 8);
|
|
219
|
+
|
|
220
|
+
export const createEmptyAddressForm = (overrides = {}) => ({
|
|
221
|
+
nickname: '',
|
|
222
|
+
cep: '',
|
|
223
|
+
street: '',
|
|
224
|
+
number: '',
|
|
225
|
+
district: '',
|
|
226
|
+
city: '',
|
|
227
|
+
state: '',
|
|
228
|
+
country: 'Brasil',
|
|
229
|
+
complement: '',
|
|
230
|
+
...overrides,
|
|
231
|
+
});
|