@funnelsgrove/runtime 0.1.15 → 0.1.17
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) => {
|
|
@@ -50,6 +50,7 @@ export type ManageSubscriptionsResponse = {
|
|
|
50
50
|
currency?: string | null;
|
|
51
51
|
billingInterval?: string | null;
|
|
52
52
|
billingIntervalCount?: number | null;
|
|
53
|
+
discountCouponIds?: string[];
|
|
53
54
|
environment: 'test' | 'live';
|
|
54
55
|
}>;
|
|
55
56
|
eventsCount: number;
|
|
@@ -84,6 +85,7 @@ declare class ApiService {
|
|
|
84
85
|
urlAttributes?: UrlUserAttributes | null;
|
|
85
86
|
attribution?: FunnelUserAttribution;
|
|
86
87
|
}): Promise<AppUser | null>;
|
|
88
|
+
pingUserContext(userId: string): Promise<AppUser | null>;
|
|
87
89
|
uploadTempPhoto(input: {
|
|
88
90
|
file: File;
|
|
89
91
|
userId?: string;
|
|
@@ -101,7 +103,8 @@ declare class ApiService {
|
|
|
101
103
|
getManageSubscriptions(): Promise<ManageSubscriptionsResponse>;
|
|
102
104
|
updateSubscription(input: {
|
|
103
105
|
subscriptionId: string;
|
|
104
|
-
action: 'cancel' | 'renew';
|
|
106
|
+
action: 'cancel' | 'renew' | 'apply-discount';
|
|
107
|
+
couponId?: string | null;
|
|
105
108
|
}): Promise<ManageSubscriptionsResponse>;
|
|
106
109
|
}
|
|
107
110
|
export declare const apiService: ApiService;
|
|
@@ -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();
|
|
@@ -438,6 +481,7 @@ class ApiService {
|
|
|
438
481
|
return (await response.json());
|
|
439
482
|
}
|
|
440
483
|
async updateSubscription(input) {
|
|
484
|
+
var _a;
|
|
441
485
|
const userId = this.getSubscriptionManagementUserId();
|
|
442
486
|
const stripeCustomerId = this.getSubscriptionManagementStripeCustomerId();
|
|
443
487
|
const response = await fetch(buildMainApiUrl(`/sdk/public/subscriptions/${encodeURIComponent(input.subscriptionId)}/${input.action}`), {
|
|
@@ -449,6 +493,7 @@ class ApiService {
|
|
|
449
493
|
user_id: userId || undefined,
|
|
450
494
|
stripe_customer_id: stripeCustomerId || undefined,
|
|
451
495
|
funnelId: FUNNEL_ID || undefined,
|
|
496
|
+
coupon_id: ((_a = input.couponId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
452
497
|
}),
|
|
453
498
|
});
|
|
454
499
|
if (!response.ok) {
|