@funnelsgrove/runtime 0.7.7 → 0.7.8

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.
@@ -5,6 +5,7 @@ import { applyUrlUserAttributesToUser, hasUrlUserProfileAttributes, resolveUrlUs
5
5
  import { getRuntimeMode } from './runtime-mode.service.js';
6
6
  const DEFAULT_USER_ID_STORAGE_KEY = 'funnel:user-id';
7
7
  const DEFAULT_BOOTSTRAP_IDEMPOTENCY_KEY_STORAGE_KEY = 'funnel:bootstrap-idempotency-key';
8
+ const SUBSCRIPTION_MANAGEMENT_LINK_ERROR = 'This subscription management link is invalid or has expired. Please request a new link or contact support.';
8
9
  const canUseDom = () => {
9
10
  return typeof window !== 'undefined';
10
11
  };
@@ -222,14 +223,7 @@ class ApiService {
222
223
  return persistUserId(normalizedUserId, FUNNEL_ID);
223
224
  }
224
225
  getSubscriptionManagementUserId() {
225
- const locationUserId = resolveUrlUserAttributes().userId;
226
- if (locationUserId) {
227
- return persistUserId(locationUserId, FUNNEL_ID);
228
- }
229
- if (this.getSubscriptionManagementStripeCustomerId()) {
230
- return null;
231
- }
232
- return this.getOrCreateClientUserId();
226
+ return resolveUrlUserAttributes().userId;
233
227
  }
234
228
  getSubscriptionManagementStripeCustomerId() {
235
229
  return resolveUrlUserAttributes().stripeCustomerId;
@@ -507,15 +501,28 @@ class ApiService {
507
501
  async getManageSubscriptions() {
508
502
  const userId = this.getSubscriptionManagementUserId();
509
503
  const stripeCustomerId = this.getSubscriptionManagementStripeCustomerId();
510
- return funnelSdkService.listSubscriptions({
504
+ if (!userId && !stripeCustomerId) {
505
+ throw new Error(SUBSCRIPTION_MANAGEMENT_LINK_ERROR);
506
+ }
507
+ const payload = await funnelSdkService.listSubscriptions({
511
508
  userId,
512
509
  stripeCustomerId,
513
510
  funnelId: FUNNEL_ID || undefined,
514
511
  });
512
+ if (!payload.user) {
513
+ throw new Error(SUBSCRIPTION_MANAGEMENT_LINK_ERROR);
514
+ }
515
+ if (userId) {
516
+ persistUserId(payload.user.user_id || userId, FUNNEL_ID);
517
+ }
518
+ return payload;
515
519
  }
516
520
  async updateSubscription(input) {
517
521
  const userId = this.getSubscriptionManagementUserId();
518
522
  const stripeCustomerId = this.getSubscriptionManagementStripeCustomerId();
523
+ if (!userId && !stripeCustomerId) {
524
+ throw new Error(SUBSCRIPTION_MANAGEMENT_LINK_ERROR);
525
+ }
519
526
  return funnelSdkService.updateSubscription({
520
527
  subscriptionId: input.subscriptionId,
521
528
  action: input.action,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",