@funnelsgrove/runtime 0.1.14 → 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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -21,6 +21,11 @@
21
21
  "types": "./dist/services/project-env.d.ts",
22
22
  "import": "./dist/services/project-env.js",
23
23
  "default": "./dist/services/project-env.js"
24
+ },
25
+ "./services/public-env": {
26
+ "types": "./dist/services/public-env.d.ts",
27
+ "import": "./dist/services/public-env.js",
28
+ "default": "./dist/services/public-env.js"
24
29
  }
25
30
  },
26
31
  "files": [