@controleonline/ui-common 1.2.132 → 1.2.134
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/.release/rc-manifest.json +5 -6
- package/package.json +2 -4
- package/src/react/components/LinkedOrderProductsTab.js +4 -11
- package/src/react/pages/WhatsAppConnectionPage.js +51 -0
- package/src/react/pages/WhatsAppProviderForm.js +38 -0
- package/src/react/pages/whatsAppEmbeddedSignup.js +133 -0
- package/src/react/utils/commercialDocumentOrders.js +20 -13
- package/src/store/connections/customActions.js +35 -0
- package/src/react/utils/documentFileContent.js +0 -55
- package/src/react/utils/linkedOrderPayload.js +0 -43
- package/src/tests/react/utils/documentFileContent.test.js +0 -28
- package/src/tests/react/utils/linkedOrderPayload.test.js +0 -46
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.131",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
6
|
-
"baseTag": "v1.2.131",
|
|
4
|
+
"branch": "rc/1.2.131-rc.1",
|
|
5
|
+
"baseMaster": "3aeaced0835b88b82621be16259985080203eee1",
|
|
7
6
|
"tasks": [
|
|
8
|
-
|
|
7
|
+
159
|
|
9
8
|
],
|
|
10
9
|
"frozen": true,
|
|
11
10
|
"repositories": {
|
|
12
|
-
"ControleOnline/ui-common": "
|
|
11
|
+
"ControleOnline/ui-common": "96efe92a8b5fd573c7688b21713f75fe7a0b57c2"
|
|
13
12
|
}
|
|
14
13
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@controleonline/ui-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.134",
|
|
4
4
|
"author": "ControleOnline",
|
|
5
5
|
"description": "ControleOnline Common Quasar UI Component",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/react/index.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary
|
|
9
|
+
"test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary",
|
|
10
10
|
"test:receita-federal": "node --test src/tests/react/pages/receitaFederalIntegrationContract.test.mjs",
|
|
11
11
|
"test:imports-status": "mkdir -p node_modules/@controleonline && rm -rf node_modules/@controleonline/ui-common && ln -s ../.. node_modules/@controleonline/ui-common && node --test src/tests/react/utils/importStatus.test.js",
|
|
12
12
|
"test:cash-register-summary": "node --test src/tests/react/utils/cashRegisterSummary.test.js",
|
|
13
|
-
"test:linked-order-payload": "node --test src/tests/react/utils/linkedOrderPayload.test.js",
|
|
14
|
-
"test:document-file-content": "node --test src/tests/react/utils/documentFileContent.test.js",
|
|
15
13
|
"test:runtime-language": "node --test src/tests/react/utils/runtimeLanguage.test.js",
|
|
16
14
|
"test:runtime-footer": "node --test src/tests/react/utils/runtimeFooter.test.js src/tests/react/utils/runtimeFooterText.test.js",
|
|
17
15
|
"test:invoice-presentation": "node --test src/tests/react/utils/invoicePresentation.test.mjs",
|
|
@@ -62,8 +62,6 @@ const LinkedOrderProductsTab = ({
|
|
|
62
62
|
emptyTitle = 'Nenhum produto adicionado.',
|
|
63
63
|
emptySubtitle = 'Você pode vincular produtos a este documento quando precisar.',
|
|
64
64
|
searchPlaceholder = 'Buscar produto para adicionar...',
|
|
65
|
-
// Called after products change so the parent can regenerate/reload the document.
|
|
66
|
-
onProductsChanged,
|
|
67
65
|
}) => {
|
|
68
66
|
const peopleStore = useStore('people');
|
|
69
67
|
const { currentCompany } = peopleStore.getters;
|
|
@@ -84,9 +82,6 @@ const LinkedOrderProductsTab = ({
|
|
|
84
82
|
);
|
|
85
83
|
|
|
86
84
|
const canEditProducts = !!canEdit && !!contract?.['@id'] && (!order || isOpenCommercialOrder(order));
|
|
87
|
-
// The backend only accepts products linked to the contract model category
|
|
88
|
-
// (ProposalProductCategoryGuard), so the search must use the same filter.
|
|
89
|
-
const modelCategoryId = normalizeEntityId(contract?.contractModel?.category);
|
|
90
85
|
|
|
91
86
|
const loadLinkedOrderProducts = useCallback(async () => {
|
|
92
87
|
if (!contract?.['@id']) {
|
|
@@ -133,7 +128,6 @@ const LinkedOrderProductsTab = ({
|
|
|
133
128
|
const results = await searchCompanyProducts({
|
|
134
129
|
companyId: currentCompany.id,
|
|
135
130
|
query: trimmedQuery,
|
|
136
|
-
categoryId: modelCategoryId,
|
|
137
131
|
});
|
|
138
132
|
|
|
139
133
|
if (!cancelled) {
|
|
@@ -154,7 +148,7 @@ const LinkedOrderProductsTab = ({
|
|
|
154
148
|
cancelled = true;
|
|
155
149
|
clearTimeout(timeoutId);
|
|
156
150
|
};
|
|
157
|
-
}, [canEditProducts, currentCompany?.id,
|
|
151
|
+
}, [canEditProducts, currentCompany?.id, searchQuery]);
|
|
158
152
|
|
|
159
153
|
const ensureCurrentOrder = useCallback(async () => {
|
|
160
154
|
if (order) {
|
|
@@ -167,6 +161,7 @@ const LinkedOrderProductsTab = ({
|
|
|
167
161
|
client: contract?.client,
|
|
168
162
|
payer: contract?.client,
|
|
169
163
|
app: 'CRM',
|
|
164
|
+
orderType: 'sale',
|
|
170
165
|
});
|
|
171
166
|
|
|
172
167
|
setOrder(createdOrder);
|
|
@@ -193,13 +188,12 @@ const LinkedOrderProductsTab = ({
|
|
|
193
188
|
setSearchQuery('');
|
|
194
189
|
setSearchResults([]);
|
|
195
190
|
await loadLinkedOrderProducts();
|
|
196
|
-
await onProductsChanged?.();
|
|
197
191
|
} catch (error) {
|
|
198
192
|
showError?.(formatApiError(error));
|
|
199
193
|
} finally {
|
|
200
194
|
setAddingProductId(null);
|
|
201
195
|
}
|
|
202
|
-
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts,
|
|
196
|
+
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, showError]);
|
|
203
197
|
|
|
204
198
|
const handleChangeQuantity = useCallback(async (orderProduct, nextQuantity) => {
|
|
205
199
|
if (updatingOrderProductId) {
|
|
@@ -223,13 +217,12 @@ const LinkedOrderProductsTab = ({
|
|
|
223
217
|
}
|
|
224
218
|
|
|
225
219
|
await loadLinkedOrderProducts();
|
|
226
|
-
await onProductsChanged?.();
|
|
227
220
|
} catch (error) {
|
|
228
221
|
showError?.(formatApiError(error));
|
|
229
222
|
} finally {
|
|
230
223
|
setUpdatingOrderProductId(null);
|
|
231
224
|
}
|
|
232
|
-
}, [loadLinkedOrderProducts,
|
|
225
|
+
}, [loadLinkedOrderProducts, showError, updatingOrderProductId]);
|
|
233
226
|
|
|
234
227
|
const visibleSearchResults = useMemo(() => {
|
|
235
228
|
const existingProductIds = new Set(
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
buildOfficialProviderConfig,
|
|
21
21
|
} from './whatsAppConnectionHelpers';
|
|
22
22
|
import WhatsAppProviderForm from './WhatsAppProviderForm';
|
|
23
|
+
import { isEmbeddedSignupSupported, launchEmbeddedSignup } from './whatsAppEmbeddedSignup';
|
|
23
24
|
import {
|
|
24
25
|
resolveThemePalette,
|
|
25
26
|
withOpacity,
|
|
@@ -77,6 +78,7 @@ export default function WhatsAppConnectionPage() {
|
|
|
77
78
|
const [qrValue, setQrValue] = useState('');
|
|
78
79
|
const [connectionStatus, setConnectionStatus] = useState('');
|
|
79
80
|
const [lastRequestedPhone, setLastRequestedPhone] = useState('');
|
|
81
|
+
const [embeddedSignupConfig, setEmbeddedSignupConfig] = useState(null);
|
|
80
82
|
|
|
81
83
|
const pollingRef = useRef(null);
|
|
82
84
|
const providerId = currentCompany?.id;
|
|
@@ -207,6 +209,53 @@ export default function WhatsAppConnectionPage() {
|
|
|
207
209
|
}
|
|
208
210
|
}, [accessToken, phoneNumberId, apiVersion, connectionType, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
|
|
209
211
|
|
|
212
|
+
// Meta Embedded Signup only runs in the browser (Facebook JS SDK popup).
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (Platform.OS !== 'web' || !isEmbeddedSignupSupported()) return;
|
|
215
|
+
let active = true;
|
|
216
|
+
Promise.resolve(connectionsActions.getWhatsappEmbeddedSignupConfig())
|
|
217
|
+
.then(config => {
|
|
218
|
+
if (active && config?.app_id && config?.config_id) setEmbeddedSignupConfig(config);
|
|
219
|
+
})
|
|
220
|
+
.catch(() => {});
|
|
221
|
+
return () => {
|
|
222
|
+
active = false;
|
|
223
|
+
};
|
|
224
|
+
}, [connectionsActions]);
|
|
225
|
+
|
|
226
|
+
const handleEmbeddedSignup = useCallback(async coexistence => {
|
|
227
|
+
if (!embeddedSignupConfig) return;
|
|
228
|
+
setSubmitting(true);
|
|
229
|
+
try {
|
|
230
|
+
const session = await launchEmbeddedSignup({
|
|
231
|
+
appId: embeddedSignupConfig.app_id,
|
|
232
|
+
configId: embeddedSignupConfig.config_id,
|
|
233
|
+
graphVersion: embeddedSignupConfig.graph_version,
|
|
234
|
+
coexistence,
|
|
235
|
+
});
|
|
236
|
+
const response = await connectionsActions.completeWhatsappEmbeddedSignup({
|
|
237
|
+
...session,
|
|
238
|
+
coexistence,
|
|
239
|
+
type: connectionType,
|
|
240
|
+
people: peopleIri,
|
|
241
|
+
});
|
|
242
|
+
showSuccess(
|
|
243
|
+
coexistence
|
|
244
|
+
? 'Numero conectado. Ele continua no app do celular e agora tambem recebe pela API.'
|
|
245
|
+
: 'Numero conectado a API oficial do WhatsApp.',
|
|
246
|
+
);
|
|
247
|
+
setConnectionStatus('CONNECTED');
|
|
248
|
+
setQrValue('');
|
|
249
|
+
await loadConnections();
|
|
250
|
+
return response;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
showError(formatApiError(error));
|
|
253
|
+
return null;
|
|
254
|
+
} finally {
|
|
255
|
+
setSubmitting(false);
|
|
256
|
+
}
|
|
257
|
+
}, [embeddedSignupConfig, connectionsActions, connectionType, peopleIri, loadConnections, showError, showSuccess]);
|
|
258
|
+
|
|
210
259
|
const handlePrimaryAction = useCallback(async () => {
|
|
211
260
|
if (providerMode === PROVIDER_OFFICIAL) {
|
|
212
261
|
return saveOfficialConnection();
|
|
@@ -366,6 +415,8 @@ export default function WhatsAppConnectionPage() {
|
|
|
366
415
|
setApiVersion={setApiVersion}
|
|
367
416
|
submitting={submitting}
|
|
368
417
|
onPrimaryAction={() => handlePrimaryAction()}
|
|
418
|
+
embeddedSignupAvailable={!!embeddedSignupConfig}
|
|
419
|
+
onEmbeddedSignup={handleEmbeddedSignup}
|
|
369
420
|
/>
|
|
370
421
|
|
|
371
422
|
<View style={{ flexDirection: 'row', gap: 8, marginTop: 8 }}>
|
|
@@ -17,6 +17,8 @@ export default function WhatsAppProviderForm({
|
|
|
17
17
|
setApiVersion,
|
|
18
18
|
submitting,
|
|
19
19
|
onPrimaryAction,
|
|
20
|
+
embeddedSignupAvailable,
|
|
21
|
+
onEmbeddedSignup,
|
|
20
22
|
}) {
|
|
21
23
|
return (
|
|
22
24
|
<>
|
|
@@ -50,6 +52,42 @@ export default function WhatsAppProviderForm({
|
|
|
50
52
|
</TouchableOpacity>
|
|
51
53
|
</View>
|
|
52
54
|
|
|
55
|
+
{providerMode === PROVIDER_OFFICIAL && embeddedSignupAvailable ? (
|
|
56
|
+
<View style={{ marginBottom: 12 }}>
|
|
57
|
+
<Text style={styles.inputLabel}>Conectar pelo Facebook</Text>
|
|
58
|
+
{[
|
|
59
|
+
[true, 'Numero do app WhatsApp Business', 'smartphone', 'Continua no celular; autorize pelo QR Code no app.'],
|
|
60
|
+
[false, 'Numero novo', 'plus-circle', 'O Meta verifica o numero por SMS ou ligacao.'],
|
|
61
|
+
].map(([coexistence, label, icon, hint]) => (
|
|
62
|
+
<TouchableOpacity
|
|
63
|
+
key={label}
|
|
64
|
+
activeOpacity={0.9}
|
|
65
|
+
disabled={submitting}
|
|
66
|
+
onPress={() => onEmbeddedSignup(coexistence)}
|
|
67
|
+
style={{
|
|
68
|
+
flexDirection: 'row',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
gap: 10,
|
|
71
|
+
borderWidth: 1,
|
|
72
|
+
borderColor: withOpacity('#1877F2', 0.35),
|
|
73
|
+
backgroundColor: withOpacity('#1877F2', 0.06),
|
|
74
|
+
borderRadius: 12,
|
|
75
|
+
padding: 12,
|
|
76
|
+
marginTop: 8,
|
|
77
|
+
opacity: submitting ? 0.6 : 1,
|
|
78
|
+
}}>
|
|
79
|
+
<Icon name={icon} size={18} color="#1877F2" />
|
|
80
|
+
<View style={{ flex: 1 }}>
|
|
81
|
+
<Text style={{ color: '#0F172A', fontWeight: '600' }}>{label}</Text>
|
|
82
|
+
<Text style={{ color: '#64748B', fontSize: 12 }}>{hint}</Text>
|
|
83
|
+
</View>
|
|
84
|
+
<Icon name="chevron-right" size={18} color="#1877F2" />
|
|
85
|
+
</TouchableOpacity>
|
|
86
|
+
))}
|
|
87
|
+
<Text style={[styles.inputLabel, { marginTop: 16 }]}>Ou informe manualmente</Text>
|
|
88
|
+
</View>
|
|
89
|
+
) : null}
|
|
90
|
+
|
|
53
91
|
{providerMode === PROVIDER_OFFICIAL ? (
|
|
54
92
|
<View style={{ marginBottom: 12 }}>
|
|
55
93
|
<Text style={styles.inputLabel}>Access token (Meta)</Text>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Meta WhatsApp Embedded Signup (web only): opens the Facebook login popup with the
|
|
2
|
+
// Embedded Signup configuration and resolves with the code + WABA / phone number ids.
|
|
3
|
+
// The code is exchanged for the token by the API (POST /whatsapp/embedded-signup).
|
|
4
|
+
|
|
5
|
+
const SDK_ID = 'facebook-jssdk';
|
|
6
|
+
const SIGNUP_EVENT = 'WA_EMBEDDED_SIGNUP';
|
|
7
|
+
|
|
8
|
+
let sdkPromise = null;
|
|
9
|
+
|
|
10
|
+
// Only messages posted by the Facebook popup itself (exact host or a facebook.com subdomain).
|
|
11
|
+
const isFacebookOrigin = origin => {
|
|
12
|
+
try {
|
|
13
|
+
const { protocol, hostname } = new URL(origin);
|
|
14
|
+
return protocol === 'https:' && (hostname === 'facebook.com' || hostname.endsWith('.facebook.com'));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isEmbeddedSignupSupported = () =>
|
|
21
|
+
typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
22
|
+
|
|
23
|
+
const loadFacebookSdk = ({ appId, graphVersion }) => {
|
|
24
|
+
if (window.FB) {
|
|
25
|
+
window.FB.init({ appId, autoLogAppEvents: true, xfbml: false, version: graphVersion });
|
|
26
|
+
return Promise.resolve(window.FB);
|
|
27
|
+
}
|
|
28
|
+
if (sdkPromise) return sdkPromise;
|
|
29
|
+
|
|
30
|
+
sdkPromise = new Promise((resolve, reject) => {
|
|
31
|
+
window.fbAsyncInit = () => {
|
|
32
|
+
window.FB.init({ appId, autoLogAppEvents: true, xfbml: false, version: graphVersion });
|
|
33
|
+
resolve(window.FB);
|
|
34
|
+
};
|
|
35
|
+
const script = document.createElement('script');
|
|
36
|
+
script.id = SDK_ID;
|
|
37
|
+
script.async = true;
|
|
38
|
+
script.defer = true;
|
|
39
|
+
script.crossOrigin = 'anonymous';
|
|
40
|
+
script.src = 'https://connect.facebook.net/pt_BR/sdk.js';
|
|
41
|
+
script.onerror = () => {
|
|
42
|
+
sdkPromise = null;
|
|
43
|
+
reject(new Error('Nao foi possivel carregar o SDK do Facebook.'));
|
|
44
|
+
};
|
|
45
|
+
document.body.appendChild(script);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return sdkPromise;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {{appId: string, configId: string, graphVersion: string, coexistence: boolean}} options
|
|
53
|
+
* @returns {Promise<{code: string, wabaId: string, phoneNumberId: string}>}
|
|
54
|
+
*/
|
|
55
|
+
export const launchEmbeddedSignup = async ({ appId, configId, graphVersion, coexistence }) => {
|
|
56
|
+
if (!appId || !configId) {
|
|
57
|
+
throw new Error('Cadastro incorporado do Meta nao configurado na API.');
|
|
58
|
+
}
|
|
59
|
+
const FB = await loadFacebookSdk({ appId, graphVersion });
|
|
60
|
+
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const session = {};
|
|
63
|
+
let code = '';
|
|
64
|
+
let settled = false;
|
|
65
|
+
|
|
66
|
+
const finish = (error, value) => {
|
|
67
|
+
if (settled) return;
|
|
68
|
+
settled = true;
|
|
69
|
+
window.removeEventListener('message', onMessage);
|
|
70
|
+
if (error) reject(error);
|
|
71
|
+
else resolve(value);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const tryResolve = () => {
|
|
75
|
+
if (code && session.wabaId && session.phoneNumberId) {
|
|
76
|
+
finish(null, { code, ...session });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Meta posts the selected WABA / number from the popup; the login callback brings the code.
|
|
81
|
+
const onMessage = event => {
|
|
82
|
+
if (!isFacebookOrigin(event.origin)) return;
|
|
83
|
+
let data = event.data;
|
|
84
|
+
try {
|
|
85
|
+
data = typeof data === 'string' ? JSON.parse(data) : data;
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (data?.type !== SIGNUP_EVENT) return;
|
|
90
|
+
|
|
91
|
+
if (String(data.event || '').startsWith('FINISH')) {
|
|
92
|
+
session.wabaId = String(data.data?.waba_id || '');
|
|
93
|
+
session.phoneNumberId = String(data.data?.phone_number_id || '');
|
|
94
|
+
tryResolve();
|
|
95
|
+
} else if (data.event === 'CANCEL') {
|
|
96
|
+
const step = data.data?.current_step ? ` (etapa ${data.data.current_step})` : '';
|
|
97
|
+
finish(new Error(data.data?.error_message || `Conexao cancelada no Facebook${step}.`));
|
|
98
|
+
} else if (data.event === 'ERROR') {
|
|
99
|
+
finish(new Error(data.data?.error_message || 'O Facebook retornou um erro.'));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
window.addEventListener('message', onMessage);
|
|
103
|
+
|
|
104
|
+
const extras = { setup: {}, sessionInfoVersion: '3' };
|
|
105
|
+
if (coexistence) {
|
|
106
|
+
extras.featureType = 'whatsapp_business_app_onboarding';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// FB.login requires a plain (non-async) callback.
|
|
110
|
+
FB.login(
|
|
111
|
+
response => {
|
|
112
|
+
code = response?.authResponse?.code || '';
|
|
113
|
+
if (!code) {
|
|
114
|
+
finish(new Error('Login no Facebook nao concluido.'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
tryResolve();
|
|
118
|
+
// The session message may arrive a little after the callback.
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
if (!settled) {
|
|
121
|
+
finish(new Error('O Facebook nao informou a conta e o numero do WhatsApp. Tente novamente.'));
|
|
122
|
+
}
|
|
123
|
+
}, 15000);
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
config_id: configId,
|
|
127
|
+
response_type: 'code',
|
|
128
|
+
override_default_response_type: true,
|
|
129
|
+
extras,
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { api } from '@controleonline/ui-common/src/api';
|
|
2
|
-
import {
|
|
3
|
-
LINKED_ORDER_TYPE,
|
|
4
|
-
buildLinkedOrderPayload,
|
|
5
|
-
} from '@controleonline/ui-common/src/react/utils/linkedOrderPayload';
|
|
6
2
|
|
|
7
3
|
const normalizeStatusKey = value => String(value || '').trim().toLowerCase();
|
|
8
4
|
|
|
@@ -162,19 +158,30 @@ export const createLinkedOrder = async ({
|
|
|
162
158
|
client,
|
|
163
159
|
payer,
|
|
164
160
|
app = 'CRM',
|
|
165
|
-
orderType =
|
|
161
|
+
orderType = 'sale',
|
|
166
162
|
fallbackStatusId = null,
|
|
167
163
|
}) => {
|
|
168
164
|
const status = await resolveOpenOrderStatusIri(fallbackStatusId);
|
|
169
|
-
const payload =
|
|
165
|
+
const payload = {
|
|
170
166
|
app,
|
|
171
167
|
orderType,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
contract: toEntityIri(contractRef, 'contracts'),
|
|
169
|
+
provider: toEntityIri(provider, 'people'),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (status) {
|
|
173
|
+
payload.status = status;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const clientIri = toEntityIri(client, 'people');
|
|
177
|
+
if (clientIri) {
|
|
178
|
+
payload.client = clientIri;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const payerIri = toEntityIri(payer || client, 'people');
|
|
182
|
+
if (payerIri) {
|
|
183
|
+
payload.payer = payerIri;
|
|
184
|
+
}
|
|
178
185
|
|
|
179
186
|
return api.fetch('orders', {
|
|
180
187
|
method: 'POST',
|
|
@@ -188,7 +195,7 @@ export const ensureLinkedOrder = async ({
|
|
|
188
195
|
client,
|
|
189
196
|
payer,
|
|
190
197
|
app = 'CRM',
|
|
191
|
-
orderType =
|
|
198
|
+
orderType = 'sale',
|
|
192
199
|
fallbackStatusId = null,
|
|
193
200
|
}) => {
|
|
194
201
|
const existingOrder = await fetchLinkedOrder(contractRef);
|
|
@@ -109,3 +109,38 @@ export const saveEmailConnection = ({ commit }, params = {}) => {
|
|
|
109
109
|
commit(types.SET_ISLOADING, false);
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Meta Embedded Signup: public data to open the Facebook popup (app id + configuration id).
|
|
115
|
+
*/
|
|
116
|
+
export const getWhatsappEmbeddedSignupConfig = () =>
|
|
117
|
+
api.fetch('/whatsapp/embedded-signup/config', { method: 'GET' });
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Meta Embedded Signup: the API exchanges the code for the token, subscribes the webhook
|
|
121
|
+
* and creates/updates the whatsapp_official connection of the company.
|
|
122
|
+
*/
|
|
123
|
+
export const completeWhatsappEmbeddedSignup = ({ commit }, params = {}) => {
|
|
124
|
+
commit(types.SET_ISLOADING, true);
|
|
125
|
+
|
|
126
|
+
return api
|
|
127
|
+
.fetch('/whatsapp/embedded-signup', {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: {
|
|
130
|
+
people: params.people,
|
|
131
|
+
code: params.code,
|
|
132
|
+
waba_id: params.wabaId,
|
|
133
|
+
phone_number_id: params.phoneNumberId,
|
|
134
|
+
coexistence: !!params.coexistence,
|
|
135
|
+
type: params.type || null,
|
|
136
|
+
connection: params.connection || null,
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
.catch(e => {
|
|
140
|
+
commit(types.SET_ERROR, e.message);
|
|
141
|
+
throw e;
|
|
142
|
+
})
|
|
143
|
+
.finally(() => {
|
|
144
|
+
commit(types.SET_ISLOADING, false);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// File.content comes base64 encoded from the API (File::getContent()). Contract
|
|
2
|
-
// and proposal documents are HTML generated from Twig models, while signed
|
|
3
|
-
// documents may be PDFs. Decode before deciding how to render.
|
|
4
|
-
|
|
5
|
-
const BASE64_PATTERN = /^[A-Za-z0-9+/=\r\n]+$/;
|
|
6
|
-
|
|
7
|
-
const decodeBase64Utf8 = value => {
|
|
8
|
-
const binary =
|
|
9
|
-
typeof globalThis.atob === 'function'
|
|
10
|
-
? globalThis.atob(value)
|
|
11
|
-
: typeof Buffer !== 'undefined'
|
|
12
|
-
? Buffer.from(value, 'base64').toString('binary')
|
|
13
|
-
: null;
|
|
14
|
-
if (binary === null) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const percentEncoded = Array.from(binary)
|
|
19
|
-
.map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`)
|
|
20
|
-
.join('');
|
|
21
|
-
return decodeURIComponent(percentEncoded);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const looksLikeHtml = value => String(value || '').trim().startsWith('<');
|
|
25
|
-
|
|
26
|
-
const resolveDocumentFileContent = content => {
|
|
27
|
-
const raw = String(content || '');
|
|
28
|
-
if (!raw.trim()) {
|
|
29
|
-
return { kind: 'empty', content: '' };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (looksLikeHtml(raw)) {
|
|
33
|
-
return { kind: 'html', content: raw };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const compact = raw.trim();
|
|
37
|
-
if (BASE64_PATTERN.test(compact)) {
|
|
38
|
-
try {
|
|
39
|
-
const decoded = decodeBase64Utf8(compact.replace(/[\r\n]/g, ''));
|
|
40
|
-
if (decoded !== null && looksLikeHtml(decoded)) {
|
|
41
|
-
return { kind: 'html', content: decoded };
|
|
42
|
-
}
|
|
43
|
-
} catch {
|
|
44
|
-
// Not UTF-8 text: binary payload such as a PDF.
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { kind: 'pdf', content: compact };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return { kind: 'text', content: raw };
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
module.exports = {
|
|
54
|
-
resolveDocumentFileContent,
|
|
55
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Orders linked to proposals/contracts are commercial drafts: the backend only
|
|
2
|
-
// accepts add/remove of products while the order is a `cart`
|
|
3
|
-
// (api-platform-orders OrderProductServiceHelpers::isMutableCartOrder) and never
|
|
4
|
-
// lets a `sale` go back to `cart`. They must start as `cart` and be promoted to
|
|
5
|
-
// `sale` (PUT /orders/{id} with orderType=sale) only when the deal is confirmed.
|
|
6
|
-
const LINKED_ORDER_TYPE = 'cart';
|
|
7
|
-
|
|
8
|
-
const buildLinkedOrderPayload = ({
|
|
9
|
-
app = 'CRM',
|
|
10
|
-
orderType = LINKED_ORDER_TYPE,
|
|
11
|
-
contractIri = null,
|
|
12
|
-
providerIri = null,
|
|
13
|
-
statusIri = null,
|
|
14
|
-
clientIri = null,
|
|
15
|
-
payerIri = null,
|
|
16
|
-
} = {}) => {
|
|
17
|
-
const payload = {
|
|
18
|
-
app,
|
|
19
|
-
orderType: orderType || LINKED_ORDER_TYPE,
|
|
20
|
-
contract: contractIri,
|
|
21
|
-
provider: providerIri,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (statusIri) {
|
|
25
|
-
payload.status = statusIri;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (clientIri) {
|
|
29
|
-
payload.client = clientIri;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const resolvedPayerIri = payerIri || clientIri;
|
|
33
|
-
if (resolvedPayerIri) {
|
|
34
|
-
payload.payer = resolvedPayerIri;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return payload;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
LINKED_ORDER_TYPE,
|
|
42
|
-
buildLinkedOrderPayload,
|
|
43
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const { resolveDocumentFileContent } = require('../../../react/utils/documentFileContent');
|
|
4
|
-
|
|
5
|
-
const toBase64 = text => Buffer.from(text, 'utf8').toString('base64');
|
|
6
|
-
|
|
7
|
-
test('decodes base64 HTML documents returned by the files API', () => {
|
|
8
|
-
const html = '<h1>Proposta</h1><p>Codex — R$ 260,00 (ação)</p>';
|
|
9
|
-
assert.deepEqual(resolveDocumentFileContent(toBase64(html)), { kind: 'html', content: html });
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('keeps plain HTML as is', () => {
|
|
13
|
-
assert.deepEqual(resolveDocumentFileContent(' <p>ok</p>'), { kind: 'html', content: ' <p>ok</p>' });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('treats non-HTML base64 payloads as PDF', () => {
|
|
17
|
-
const pdf = Buffer.from([0x25, 0x50, 0x44, 0x46, 0x2d, 0xff, 0xfe, 0x00]).toString('base64');
|
|
18
|
-
assert.deepEqual(resolveDocumentFileContent(pdf), { kind: 'pdf', content: pdf });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('empty and plain text contents', () => {
|
|
22
|
-
assert.deepEqual(resolveDocumentFileContent(''), { kind: 'empty', content: '' });
|
|
23
|
-
assert.deepEqual(resolveDocumentFileContent(null), { kind: 'empty', content: '' });
|
|
24
|
-
assert.deepEqual(resolveDocumentFileContent('Contrato simples, sem HTML.'), {
|
|
25
|
-
kind: 'text',
|
|
26
|
-
content: 'Contrato simples, sem HTML.',
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const {
|
|
4
|
-
LINKED_ORDER_TYPE,
|
|
5
|
-
buildLinkedOrderPayload,
|
|
6
|
-
} = require('../../../react/utils/linkedOrderPayload');
|
|
7
|
-
|
|
8
|
-
test('linked commercial orders start as cart so products can be edited', () => {
|
|
9
|
-
assert.equal(LINKED_ORDER_TYPE, 'cart');
|
|
10
|
-
const payload = buildLinkedOrderPayload({
|
|
11
|
-
contractIri: '/contracts/27',
|
|
12
|
-
providerIri: '/people/1',
|
|
13
|
-
statusIri: '/statuses/119',
|
|
14
|
-
clientIri: '/people/105792',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
assert.deepEqual(payload, {
|
|
18
|
-
app: 'CRM',
|
|
19
|
-
orderType: 'cart',
|
|
20
|
-
contract: '/contracts/27',
|
|
21
|
-
provider: '/people/1',
|
|
22
|
-
status: '/statuses/119',
|
|
23
|
-
client: '/people/105792',
|
|
24
|
-
payer: '/people/105792',
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('empty orderType falls back to cart instead of being sent blank', () => {
|
|
29
|
-
assert.equal(buildLinkedOrderPayload({orderType: ''}).orderType, 'cart');
|
|
30
|
-
assert.equal(buildLinkedOrderPayload({orderType: null}).orderType, 'cart');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('explicit payer wins over client and optional refs are omitted', () => {
|
|
34
|
-
const payload = buildLinkedOrderPayload({
|
|
35
|
-
contractIri: '/contracts/1',
|
|
36
|
-
providerIri: '/people/1',
|
|
37
|
-
clientIri: '/people/2',
|
|
38
|
-
payerIri: '/people/3',
|
|
39
|
-
});
|
|
40
|
-
assert.equal(payload.payer, '/people/3');
|
|
41
|
-
assert.equal('status' in payload, false);
|
|
42
|
-
|
|
43
|
-
const withoutParties = buildLinkedOrderPayload({contractIri: '/contracts/1'});
|
|
44
|
-
assert.equal('client' in withoutParties, false);
|
|
45
|
-
assert.equal('payer' in withoutParties, false);
|
|
46
|
-
});
|