@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,14 @@
|
|
|
1
|
+
export default class Config {
|
|
2
|
+
getConfig(key) {
|
|
3
|
+
let storedUser = this.getAllConfig();
|
|
4
|
+
return storedUser ? storedUser[key] : {};
|
|
5
|
+
}
|
|
6
|
+
getAllConfig() {
|
|
7
|
+
return JSON.parse(localStorage.getItem("config")) || {};
|
|
8
|
+
}
|
|
9
|
+
setConfig(key, data) {
|
|
10
|
+
let storedUser = this.getAllConfig();
|
|
11
|
+
storedUser[key] = data;
|
|
12
|
+
localStorage.setItem("config", JSON.stringify(storedUser));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
export default class Formatter {
|
|
2
|
+
|
|
3
|
+
/* ================= UTIL ================= */
|
|
4
|
+
|
|
5
|
+
static onlyNumbers(value) {
|
|
6
|
+
return String(value || '').replace(/\D/g, '');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* ================= DOCUMENTOS ================= */
|
|
10
|
+
|
|
11
|
+
static formatDocument(value) {
|
|
12
|
+
|
|
13
|
+
const numbers = Formatter.onlyNumbers(value);
|
|
14
|
+
|
|
15
|
+
if (numbers.length === 11)
|
|
16
|
+
return Formatter.maskCPF(numbers);
|
|
17
|
+
|
|
18
|
+
if (numbers.length === 14)
|
|
19
|
+
return Formatter.maskCNPJ(numbers);
|
|
20
|
+
|
|
21
|
+
return value || '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static formatBRDocument(value) {
|
|
25
|
+
return Formatter.maskBRDocument(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* ================= MÁSCARAS DIGITAÇÃO ================= */
|
|
29
|
+
|
|
30
|
+
static maskCPF(value) {
|
|
31
|
+
|
|
32
|
+
value = Formatter.onlyNumbers(value).slice(0, 11);
|
|
33
|
+
|
|
34
|
+
return value
|
|
35
|
+
.replace(/^(\d{3})(\d)/, '$1.$2')
|
|
36
|
+
.replace(/^(\d{3})\.(\d{3})(\d)/, '$1.$2.$3')
|
|
37
|
+
.replace(/\.(\d{3})(\d)/, '.$1-$2');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static maskCNPJ(value) {
|
|
41
|
+
|
|
42
|
+
value = Formatter.onlyNumbers(value).slice(0, 14);
|
|
43
|
+
|
|
44
|
+
return value
|
|
45
|
+
.replace(/^(\d{2})(\d)/, '$1.$2')
|
|
46
|
+
.replace(/^(\d{2})\.(\d{3})(\d)/, '$1.$2.$3')
|
|
47
|
+
.replace(/\.(\d{3})(\d)/, '.$1/$2')
|
|
48
|
+
.replace(/(\d{4})(\d)/, '$1-$2');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static maskBRDocument(value) {
|
|
52
|
+
|
|
53
|
+
const numbers = Formatter.onlyNumbers(value);
|
|
54
|
+
|
|
55
|
+
if (numbers.length <= 11)
|
|
56
|
+
return Formatter.maskCPF(numbers);
|
|
57
|
+
|
|
58
|
+
return Formatter.maskCNPJ(numbers);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* ================= TELEFONE ================= */
|
|
62
|
+
|
|
63
|
+
static maskPhoneBR(value) {
|
|
64
|
+
|
|
65
|
+
value = Formatter.onlyNumbers(value).slice(0, 11);
|
|
66
|
+
|
|
67
|
+
// if (value.length <= 2)
|
|
68
|
+
// return `(${value}`;
|
|
69
|
+
|
|
70
|
+
// if (value.length <= 6)
|
|
71
|
+
// return value.replace(/(\d{2})(\d+)/, '($1) $2');
|
|
72
|
+
|
|
73
|
+
if (value.length <= 8)
|
|
74
|
+
return value.replace(/(\d{4})(\d+)/, '$1-$2');
|
|
75
|
+
|
|
76
|
+
if (value.length <= 9)
|
|
77
|
+
return value.replace(/(\d{1})(\d{4})(\d+)/, '$1 $2-$3');
|
|
78
|
+
|
|
79
|
+
if (value.length <= 10)
|
|
80
|
+
return value.replace(/(\d{2})(\d{4})(\d+)/, '($1) $2-$3');
|
|
81
|
+
|
|
82
|
+
return value.replace(/(\d{2})(\d{1})(\d{4})(\d+)/, '($1) $2 $3-$4');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static formatBRPhone(value) {
|
|
86
|
+
|
|
87
|
+
const numbers = Formatter.onlyNumbers(value);
|
|
88
|
+
|
|
89
|
+
if (numbers.length === 10)
|
|
90
|
+
return numbers.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3');
|
|
91
|
+
|
|
92
|
+
if (numbers.length === 11)
|
|
93
|
+
return numbers.replace(/(\d{2})(\d{1})(\d{4})(\d{4})/, '($1) $2 $3-$4');
|
|
94
|
+
|
|
95
|
+
return value || '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static formatPhone(value) {
|
|
99
|
+
return Formatter.maskPhoneBR(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ================= VALIDAÇÕES ================= */
|
|
103
|
+
|
|
104
|
+
static validateEmail(email) {
|
|
105
|
+
if (!email) return false;
|
|
106
|
+
return /\S+@\S+\.\S+/.test(email);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static validateCPF(cpf) {
|
|
110
|
+
|
|
111
|
+
cpf = Formatter.onlyNumbers(cpf);
|
|
112
|
+
|
|
113
|
+
if (cpf.length !== 11) return false;
|
|
114
|
+
if (/^(\d)\1+$/.test(cpf)) return false;
|
|
115
|
+
|
|
116
|
+
let sum = 0;
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < 9; i++)
|
|
119
|
+
sum += cpf[i] * (10 - i);
|
|
120
|
+
|
|
121
|
+
let rev = 11 - (sum % 11);
|
|
122
|
+
if (rev >= 10) rev = 0;
|
|
123
|
+
|
|
124
|
+
if (rev != cpf[9]) return false;
|
|
125
|
+
|
|
126
|
+
sum = 0;
|
|
127
|
+
|
|
128
|
+
for (let i = 0; i < 10; i++)
|
|
129
|
+
sum += cpf[i] * (11 - i);
|
|
130
|
+
|
|
131
|
+
rev = 11 - (sum % 11);
|
|
132
|
+
if (rev >= 10) rev = 0;
|
|
133
|
+
|
|
134
|
+
return rev == cpf[10];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static validateCNPJ(cnpj) {
|
|
138
|
+
|
|
139
|
+
cnpj = Formatter.onlyNumbers(cnpj);
|
|
140
|
+
|
|
141
|
+
if (cnpj.length !== 14) return false;
|
|
142
|
+
if (/^(\d)\1+$/.test(cnpj)) return false;
|
|
143
|
+
|
|
144
|
+
let length = cnpj.length - 2;
|
|
145
|
+
let numbers = cnpj.substring(0, length);
|
|
146
|
+
let digits = cnpj.substring(length);
|
|
147
|
+
|
|
148
|
+
let sum = 0;
|
|
149
|
+
let pos = length - 7;
|
|
150
|
+
|
|
151
|
+
for (let i = length; i >= 1; i--) {
|
|
152
|
+
|
|
153
|
+
sum += numbers[length - i] * pos--;
|
|
154
|
+
|
|
155
|
+
if (pos < 2)
|
|
156
|
+
pos = 9;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let result = sum % 11 < 2 ? 0 : 11 - sum % 11;
|
|
160
|
+
|
|
161
|
+
if (result != digits[0])
|
|
162
|
+
return false;
|
|
163
|
+
|
|
164
|
+
length = length + 1;
|
|
165
|
+
numbers = cnpj.substring(0, length);
|
|
166
|
+
|
|
167
|
+
sum = 0;
|
|
168
|
+
pos = length - 7;
|
|
169
|
+
|
|
170
|
+
for (let i = length; i >= 1; i--) {
|
|
171
|
+
|
|
172
|
+
sum += numbers[length - i] * pos--;
|
|
173
|
+
|
|
174
|
+
if (pos < 2)
|
|
175
|
+
pos = 9;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
result = sum % 11 < 2 ? 0 : 11 - sum % 11;
|
|
179
|
+
|
|
180
|
+
return result == digits[1];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* ================= DATAS ================= */
|
|
184
|
+
|
|
185
|
+
static formatDateToBR(dateInput) {
|
|
186
|
+
|
|
187
|
+
if (!dateInput) return '';
|
|
188
|
+
|
|
189
|
+
const dateOnly = String(dateInput).split(' ')[0];
|
|
190
|
+
const parts = dateOnly.split(/[-/]/);
|
|
191
|
+
|
|
192
|
+
if (parts.length !== 3)
|
|
193
|
+
return dateInput;
|
|
194
|
+
|
|
195
|
+
const [part1, part2, part3] = parts;
|
|
196
|
+
|
|
197
|
+
let day, month, year;
|
|
198
|
+
|
|
199
|
+
if (part1.length === 4) {
|
|
200
|
+
|
|
201
|
+
year = part1;
|
|
202
|
+
month = part2;
|
|
203
|
+
day = part3;
|
|
204
|
+
|
|
205
|
+
} else if (part3.length === 4) {
|
|
206
|
+
|
|
207
|
+
day = part1;
|
|
208
|
+
month = part2;
|
|
209
|
+
year = part3;
|
|
210
|
+
|
|
211
|
+
} else {
|
|
212
|
+
return dateInput;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (day > 31 || month > 12 || day < 1 || month < 1)
|
|
216
|
+
return dateInput;
|
|
217
|
+
|
|
218
|
+
return `${String(day).padStart(2, '0')}/${String(month).padStart(2, '0')}/${year}`;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static validateBRDate(value) {
|
|
222
|
+
|
|
223
|
+
if (!value) return true;
|
|
224
|
+
|
|
225
|
+
const normalizedValue = value.replace(/[-/]/g, '/');
|
|
226
|
+
|
|
227
|
+
const regex = /^\d{2}\/\d{2}\/\d{4}$/;
|
|
228
|
+
|
|
229
|
+
if (!regex.test(normalizedValue))
|
|
230
|
+
return 'Data inválida. Formato esperado: DD/MM/YYYY';
|
|
231
|
+
|
|
232
|
+
const [day, month, year] = normalizedValue.split('/').map(Number);
|
|
233
|
+
|
|
234
|
+
const date = new Date(year, month - 1, day);
|
|
235
|
+
|
|
236
|
+
if (
|
|
237
|
+
date.getFullYear() !== year ||
|
|
238
|
+
date.getMonth() + 1 !== month ||
|
|
239
|
+
date.getDate() !== day
|
|
240
|
+
)
|
|
241
|
+
return 'Data inválida';
|
|
242
|
+
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/* ================= CEP ================= */
|
|
247
|
+
|
|
248
|
+
static formatCEP(value) {
|
|
249
|
+
|
|
250
|
+
if (!value) return '';
|
|
251
|
+
|
|
252
|
+
value = Formatter.onlyNumbers(value);
|
|
253
|
+
|
|
254
|
+
if (value.length === 7)
|
|
255
|
+
value = `0${value}`;
|
|
256
|
+
|
|
257
|
+
return value.replace(/(\d{5})(\d{3})/, '$1-$2');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* ================= NUMÉRICOS ================= */
|
|
261
|
+
|
|
262
|
+
static formatFloat(value) {
|
|
263
|
+
|
|
264
|
+
const formatedValue = String(value || 0)
|
|
265
|
+
.replace(/[^0-9.,]/g, '')
|
|
266
|
+
.replace('.', '')
|
|
267
|
+
.replace(',', '.');
|
|
268
|
+
|
|
269
|
+
return parseFloat(formatedValue) || 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
static formatMoney(value, currency = 'R$', locale = 'pt-BR') {
|
|
273
|
+
|
|
274
|
+
if (!value && value !== 0)
|
|
275
|
+
return `${currency} 0,00`;
|
|
276
|
+
|
|
277
|
+
const numericValue =
|
|
278
|
+
typeof value === 'string'
|
|
279
|
+
? parseFloat(value.replace('.', '').replace(',', '.')) || 0
|
|
280
|
+
: value;
|
|
281
|
+
|
|
282
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
283
|
+
minimumFractionDigits: 2,
|
|
284
|
+
maximumFractionDigits: 2,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
return `${currency} ${formatter.format(numericValue)}`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
static formatInteger(value, locale = 'pt-BR') {
|
|
291
|
+
|
|
292
|
+
const numericValue = Number(value || 0);
|
|
293
|
+
|
|
294
|
+
return new Intl.NumberFormat(locale, {
|
|
295
|
+
maximumFractionDigits: 0,
|
|
296
|
+
}).format(Number.isFinite(numericValue) ? numericValue : 0);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
static formatDecimal(value, locale = 'pt-BR', maximumFractionDigits = 1) {
|
|
300
|
+
|
|
301
|
+
const numericValue = Number(value || 0);
|
|
302
|
+
|
|
303
|
+
return new Intl.NumberFormat(locale, {
|
|
304
|
+
maximumFractionDigits,
|
|
305
|
+
}).format(Number.isFinite(numericValue) ? numericValue : 0);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
static formatPercent(value, locale = 'pt-BR', maximumFractionDigits = 1) {
|
|
309
|
+
|
|
310
|
+
return `${Formatter.formatDecimal(value, locale, maximumFractionDigits)}%`;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
static formatSignedInteger(value, locale = 'pt-BR') {
|
|
314
|
+
|
|
315
|
+
const numericValue = Number(value || 0);
|
|
316
|
+
|
|
317
|
+
if (numericValue > 0)
|
|
318
|
+
return `+${Formatter.formatInteger(numericValue, locale)}`;
|
|
319
|
+
|
|
320
|
+
if (numericValue < 0)
|
|
321
|
+
return `-${Formatter.formatInteger(Math.abs(numericValue), locale)}`;
|
|
322
|
+
|
|
323
|
+
return '0';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
static formatSignedPercent(value, locale = 'pt-BR', maximumFractionDigits = 1) {
|
|
327
|
+
|
|
328
|
+
const numericValue = Number(value || 0);
|
|
329
|
+
|
|
330
|
+
if (numericValue > 0)
|
|
331
|
+
return `+${Formatter.formatPercent(numericValue, locale, maximumFractionDigits)}`;
|
|
332
|
+
|
|
333
|
+
if (numericValue < 0)
|
|
334
|
+
return `-${Formatter.formatPercent(Math.abs(numericValue), locale, maximumFractionDigits)}`;
|
|
335
|
+
|
|
336
|
+
return '0%';
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static formatDateShort(value) {
|
|
340
|
+
|
|
341
|
+
if (!value) return '';
|
|
342
|
+
|
|
343
|
+
const date = new Date(value);
|
|
344
|
+
|
|
345
|
+
if (isNaN(date.getTime()))
|
|
346
|
+
return '';
|
|
347
|
+
|
|
348
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
349
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
350
|
+
|
|
351
|
+
return `${day}/${month}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/* ================= DATAS AUX ================= */
|
|
355
|
+
|
|
356
|
+
static buildAmericanDate(dateString) {
|
|
357
|
+
|
|
358
|
+
if (!dateString) return null;
|
|
359
|
+
|
|
360
|
+
const normalizedDate = dateString.replaceAll('/', '-');
|
|
361
|
+
|
|
362
|
+
const [day, month, year] = normalizedDate.split('-').map(Number);
|
|
363
|
+
|
|
364
|
+
const date = new Date(year, month - 1, day);
|
|
365
|
+
|
|
366
|
+
if (isNaN(date.getTime()))
|
|
367
|
+
return null;
|
|
368
|
+
|
|
369
|
+
const yyyy = date.getFullYear();
|
|
370
|
+
const mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
371
|
+
const dd = String(date.getDate()).padStart(2, '0');
|
|
372
|
+
|
|
373
|
+
return `${yyyy}-${mm}-${dd}`;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
static getCurrentDate() {
|
|
377
|
+
|
|
378
|
+
const today = new Date();
|
|
379
|
+
|
|
380
|
+
const year = today.getFullYear();
|
|
381
|
+
const month = String(today.getMonth() + 1).padStart(2, '0');
|
|
382
|
+
const day = String(today.getDate()).padStart(2, '0');
|
|
383
|
+
|
|
384
|
+
return `${year}-${month}-${day}`;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
static formatDateYmdTodmY(value, withTime = false) {
|
|
388
|
+
|
|
389
|
+
if (!value) return '';
|
|
390
|
+
|
|
391
|
+
const date = new Date(value);
|
|
392
|
+
|
|
393
|
+
if (isNaN(date.getTime()))
|
|
394
|
+
return value;
|
|
395
|
+
|
|
396
|
+
const clientTimeZoneOffset = new Date().getTimezoneOffset();
|
|
397
|
+
|
|
398
|
+
const timeZoneDiffMinutes = clientTimeZoneOffset - date.getTimezoneOffset();
|
|
399
|
+
|
|
400
|
+
date.setMinutes(date.getMinutes() + timeZoneDiffMinutes);
|
|
401
|
+
|
|
402
|
+
const options = {
|
|
403
|
+
year: 'numeric',
|
|
404
|
+
month: '2-digit',
|
|
405
|
+
day: '2-digit',
|
|
406
|
+
hour12: false,
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
if (withTime) {
|
|
410
|
+
|
|
411
|
+
options.hour = '2-digit';
|
|
412
|
+
options.minute = '2-digit';
|
|
413
|
+
options.second = '2-digit';
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return date.toLocaleString('pt-BR', options);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const CIELO_CONFIG_KEY = 'CIELO';
|
|
2
|
+
export const NEW_RELIC_CONFIG_KEY = 'NEW_RELIC';
|
|
3
|
+
export const SPOTIFY_CONFIG_KEY = 'SPOTIFY';
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_CIELO_CONFIG = {
|
|
6
|
+
ACCESS_TOKEN: '',
|
|
7
|
+
CLIENT_ID: '',
|
|
8
|
+
EMAIL: '',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_NEW_RELIC_CONFIG = {
|
|
12
|
+
LICENSE_KEY: '',
|
|
13
|
+
APPLICATION_ID: '',
|
|
14
|
+
ACCOUNT_ID: '',
|
|
15
|
+
TRUST_KEY: '',
|
|
16
|
+
BEACON: 'bam.nr-data.net',
|
|
17
|
+
ERROR_BEACON: 'bam.nr-data.net',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_SPOTIFY_CONFIG = {
|
|
21
|
+
CLIENT_ID: '',
|
|
22
|
+
CLIENT_SECRET: '',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const isConfigMap = value =>
|
|
26
|
+
value && typeof value === 'object' && !Array.isArray(value);
|
|
27
|
+
|
|
28
|
+
const parseJsonValue = (value, fallback) => {
|
|
29
|
+
if (value === null || value === undefined || value === '') {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof value === 'string') {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(value);
|
|
36
|
+
} catch {
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const normalizeTextValue = value => String(value || '').trim();
|
|
45
|
+
|
|
46
|
+
export const resolveIntegrationConfig = (configs, configKey, defaults) => {
|
|
47
|
+
if (!isConfigMap(defaults)) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rawConfig = isConfigMap(configs)
|
|
52
|
+
? parseJsonValue(configs[configKey], {})
|
|
53
|
+
: {};
|
|
54
|
+
const source = isConfigMap(rawConfig) ? rawConfig : {};
|
|
55
|
+
|
|
56
|
+
return Object.keys(defaults).reduce((accumulator, fieldKey) => {
|
|
57
|
+
accumulator[fieldKey] = normalizeTextValue(
|
|
58
|
+
source[fieldKey] !== undefined ? source[fieldKey] : defaults[fieldKey],
|
|
59
|
+
);
|
|
60
|
+
return accumulator;
|
|
61
|
+
}, {});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const resolveCieloConfig = configs =>
|
|
65
|
+
resolveIntegrationConfig(configs, CIELO_CONFIG_KEY, DEFAULT_CIELO_CONFIG);
|
|
66
|
+
|
|
67
|
+
export const resolveNewRelicConfig = configs =>
|
|
68
|
+
resolveIntegrationConfig(
|
|
69
|
+
configs,
|
|
70
|
+
NEW_RELIC_CONFIG_KEY,
|
|
71
|
+
DEFAULT_NEW_RELIC_CONFIG,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export const resolveSpotifyConfig = configs =>
|
|
75
|
+
resolveIntegrationConfig(
|
|
76
|
+
configs,
|
|
77
|
+
SPOTIFY_CONFIG_KEY,
|
|
78
|
+
DEFAULT_SPOTIFY_CONFIG,
|
|
79
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function copyObject(obj) {
|
|
2
|
+
if (obj === null || !(obj instanceof Object)) {
|
|
3
|
+
return obj;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
const newArray = obj.map((item) => copyObject(item));
|
|
8
|
+
return newArray;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (obj instanceof Function) {
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const newObj = {};
|
|
16
|
+
for (const key in obj) {
|
|
17
|
+
if (obj.hasOwnProperty(key)) {
|
|
18
|
+
newObj[key] = copyObject(obj[key]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return newObj || {};
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const OAUTH_GOOGLE_CLIENT_ID_CONFIG_KEY = 'OAUTH_GOOGLE_CLIENT_ID';
|
|
2
|
+
|
|
3
|
+
const normalizeConfigTextValue = value => {
|
|
4
|
+
if (value === null || value === undefined) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (typeof value === 'string') {
|
|
9
|
+
const trimmedValue = value.trim();
|
|
10
|
+
|
|
11
|
+
if (!trimmedValue) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const parsedValue = JSON.parse(trimmedValue);
|
|
17
|
+
if (typeof parsedValue === 'string') {
|
|
18
|
+
return parsedValue.trim();
|
|
19
|
+
}
|
|
20
|
+
} catch {}
|
|
21
|
+
|
|
22
|
+
return trimmedValue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return String(value).trim();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isConfigMap = value =>
|
|
29
|
+
value && typeof value === 'object' && !Array.isArray(value);
|
|
30
|
+
|
|
31
|
+
export const resolveGoogleOauthClientId = configs => {
|
|
32
|
+
if (!isConfigMap(configs)) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return normalizeConfigTextValue(
|
|
37
|
+
configs[OAUTH_GOOGLE_CLIENT_ID_CONFIG_KEY],
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const resolveCompanyGoogleOauthClientId = company =>
|
|
42
|
+
resolveGoogleOauthClientId(company?.configs);
|