@funnelsgrove/runtime 0.1.15 → 0.1.16
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.
|
@@ -274,6 +274,20 @@ export function useFunnelFlowController({ initialStepId, lockToInitialStep = fal
|
|
|
274
274
|
setAttributes((prev) => (Object.assign(Object.assign({}, sessionAttributes), prev)));
|
|
275
275
|
}
|
|
276
276
|
setUser((prev) => (Object.assign(Object.assign({}, prev), { id: sessionUser.id || prev.id, name: sessionUser.name || prev.name, email: sessionUser.email || prev.email, document: sessionUser.document, attributes: sessionAttributes ? Object.assign(Object.assign({}, sessionAttributes), prev.attributes) : prev.attributes })));
|
|
277
|
+
void apiService.pingUserContext(sessionUser.id)
|
|
278
|
+
.then((pingedUser) => {
|
|
279
|
+
if (!pingedUser) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const pingedAttributes = Object.keys(pingedUser.attributes || {}).length > 0
|
|
283
|
+
? pingedUser.attributes
|
|
284
|
+
: null;
|
|
285
|
+
setUser((prev) => (Object.assign(Object.assign({}, prev), { document: pingedUser.document, attributes: pingedAttributes
|
|
286
|
+
? Object.assign(Object.assign({}, prev.attributes), pingedAttributes) : prev.attributes })));
|
|
287
|
+
})
|
|
288
|
+
.catch((error) => {
|
|
289
|
+
logger.error('Failed to ping user context:', error);
|
|
290
|
+
});
|
|
277
291
|
return sessionUser;
|
|
278
292
|
})
|
|
279
293
|
.catch((error) => {
|
|
@@ -84,6 +84,7 @@ declare class ApiService {
|
|
|
84
84
|
urlAttributes?: UrlUserAttributes | null;
|
|
85
85
|
attribution?: FunnelUserAttribution;
|
|
86
86
|
}): Promise<AppUser | null>;
|
|
87
|
+
pingUserContext(userId: string): Promise<AppUser | null>;
|
|
87
88
|
uploadTempPhoto(input: {
|
|
88
89
|
file: File;
|
|
89
90
|
userId?: string;
|
|
@@ -24,6 +24,17 @@ const asNumber = (value) => {
|
|
|
24
24
|
}
|
|
25
25
|
return value;
|
|
26
26
|
};
|
|
27
|
+
const resolveBrowserTimezone = () => {
|
|
28
|
+
if (!canUseDom()) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return asString(Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
27
38
|
const normalizeUserId = (value) => {
|
|
28
39
|
if (!value || typeof value !== 'string') {
|
|
29
40
|
return null;
|
|
@@ -311,6 +322,38 @@ class ApiService {
|
|
|
311
322
|
urlAttributes: input.urlAttributes,
|
|
312
323
|
});
|
|
313
324
|
}
|
|
325
|
+
async pingUserContext(userId) {
|
|
326
|
+
var _a;
|
|
327
|
+
const normalizedUserId = normalizeUserId(userId);
|
|
328
|
+
const publishableKey = getFunnelSdkPublishableKey();
|
|
329
|
+
if (!normalizedUserId || !publishableKey || !FUNNEL_ID || !canUseDom()) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
const response = await fetch('/api/ping', {
|
|
334
|
+
method: 'POST',
|
|
335
|
+
headers: buildSdkHeaders({
|
|
336
|
+
'Content-Type': 'application/json',
|
|
337
|
+
}),
|
|
338
|
+
body: JSON.stringify({
|
|
339
|
+
funnelId: FUNNEL_ID,
|
|
340
|
+
user_id: normalizedUserId,
|
|
341
|
+
timezone: resolveBrowserTimezone() || undefined,
|
|
342
|
+
}),
|
|
343
|
+
});
|
|
344
|
+
if (!response.ok) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
const payload = (await response.json());
|
|
348
|
+
return toAppUser({
|
|
349
|
+
apiUser: payload.user,
|
|
350
|
+
userId: asString((_a = payload.user) === null || _a === void 0 ? void 0 : _a.user_id) || normalizedUserId,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
catch (_b) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
314
357
|
async uploadTempPhoto(input) {
|
|
315
358
|
const userId = persistUserId(input.userId || this.getOrCreateClientUserId(), FUNNEL_ID);
|
|
316
359
|
const publishableKey = getFunnelSdkPublishableKey();
|