@funnelsgrove/runtime 0.11.2 → 0.11.4

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.
Files changed (129) hide show
  1. package/README.md +51 -0
  2. package/dist/components/ManageSubscriptionScreen.js +7 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/services/api.service.d.ts +28 -104
  6. package/dist/services/api.service.js +24 -519
  7. package/dist/services/checkout-access.service.d.ts +2 -0
  8. package/dist/services/checkout-access.service.js +19 -0
  9. package/dist/services/checkout-identity.service.d.ts +4 -0
  10. package/dist/services/checkout-identity.service.js +28 -0
  11. package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.d.ts +2 -0
  12. package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.js +17 -0
  13. package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.d.ts +2 -0
  14. package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.js +9 -0
  15. package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.d.ts +2 -0
  16. package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.js +21 -0
  17. package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.d.ts +3 -0
  18. package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.js +10 -0
  19. package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.d.ts +2 -0
  20. package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.js +22 -0
  21. package/dist/services/funnel-sdk/checkout/requests.d.ts +127 -0
  22. package/dist/services/funnel-sdk/checkout/requests.js +112 -0
  23. package/dist/services/{funnel-sdk-payments.functions.d.ts → funnel-sdk/checkout/selection.d.ts} +2 -0
  24. package/dist/services/{funnel-sdk-payments.functions.js → funnel-sdk/checkout/selection.js} +1 -1
  25. package/dist/services/funnel-sdk/checkout/types.d.ts +187 -0
  26. package/dist/services/funnel-sdk/checkout/types.js +1 -0
  27. package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.d.ts +2 -0
  28. package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.js +18 -0
  29. package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.d.ts +2 -0
  30. package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.js +25 -0
  31. package/dist/services/funnel-sdk/shared/http.d.ts +21 -0
  32. package/dist/services/funnel-sdk/shared/http.js +65 -0
  33. package/dist/services/funnel-sdk/shared/runtimeConfig.d.ts +17 -0
  34. package/dist/services/funnel-sdk/shared/runtimeConfig.js +42 -0
  35. package/dist/services/funnel-sdk/shared/types.d.ts +9 -0
  36. package/dist/services/funnel-sdk/shared/types.js +1 -0
  37. package/dist/services/funnel-sdk/subscriptions/listSubscriptions.d.ts +3 -0
  38. package/dist/services/funnel-sdk/subscriptions/listSubscriptions.js +17 -0
  39. package/dist/services/funnel-sdk/subscriptions/types.d.ts +24 -0
  40. package/dist/services/funnel-sdk/subscriptions/types.js +1 -0
  41. package/dist/services/funnel-sdk/subscriptions/updateSubscription.d.ts +2 -0
  42. package/dist/services/funnel-sdk/subscriptions/updateSubscription.js +33 -0
  43. package/dist/services/funnel-sdk/subscriptions/validator.d.ts +2 -0
  44. package/dist/services/funnel-sdk/subscriptions/validator.js +15 -0
  45. package/dist/services/funnel-sdk/uploads/preparePhotoUpload.d.ts +4 -0
  46. package/dist/services/funnel-sdk/uploads/preparePhotoUpload.js +19 -0
  47. package/dist/services/funnel-sdk/uploads/types.d.ts +32 -0
  48. package/dist/services/funnel-sdk/uploads/types.js +1 -0
  49. package/dist/services/funnel-sdk/uploads/uploadPhoto.d.ts +7 -0
  50. package/dist/services/funnel-sdk/uploads/uploadPhoto.js +18 -0
  51. package/dist/services/funnel-sdk/uploads/uploadPhotoFile.d.ts +2 -0
  52. package/dist/services/funnel-sdk/uploads/uploadPhotoFile.js +26 -0
  53. package/dist/services/funnel-sdk/users/bootstrapUser.d.ts +3 -0
  54. package/dist/services/funnel-sdk/users/bootstrapUser.js +15 -0
  55. package/dist/services/funnel-sdk/users/captureEmail.d.ts +2 -0
  56. package/dist/services/funnel-sdk/users/captureEmail.js +15 -0
  57. package/dist/services/funnel-sdk/users/claimUserSubscription.d.ts +3 -0
  58. package/dist/services/funnel-sdk/users/claimUserSubscription.js +7 -0
  59. package/dist/services/funnel-sdk/users/getCurrentUser.d.ts +3 -0
  60. package/dist/services/funnel-sdk/users/getCurrentUser.js +13 -0
  61. package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.d.ts +3 -0
  62. package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.js +14 -0
  63. package/dist/services/funnel-sdk/users/types.d.ts +57 -0
  64. package/dist/services/funnel-sdk/users/types.js +1 -0
  65. package/dist/services/funnel-sdk/users/updateFunnelUser.d.ts +3 -0
  66. package/dist/services/funnel-sdk/users/updateFunnelUser.js +18 -0
  67. package/dist/services/funnel-sdk.service.d.ts +26 -319
  68. package/dist/services/funnel-sdk.service.js +38 -456
  69. package/dist/services/session/bootstrap/bootstrapSession.d.ts +8 -0
  70. package/dist/services/session/bootstrap/bootstrapSession.js +25 -0
  71. package/dist/services/session/bootstrap/currentUser.d.ts +1 -0
  72. package/dist/services/session/bootstrap/currentUser.js +37 -0
  73. package/dist/services/session/bootstrap/idempotency.d.ts +9 -0
  74. package/dist/services/session/bootstrap/idempotency.js +97 -0
  75. package/dist/services/session/bootstrap/requests.d.ts +23 -0
  76. package/dist/services/session/bootstrap/requests.js +25 -0
  77. package/dist/services/session/bootstrap/responses.d.ts +3 -0
  78. package/dist/services/session/bootstrap/responses.js +10 -0
  79. package/dist/services/session/bootstrap/types.d.ts +12 -0
  80. package/dist/services/session/bootstrap/types.js +1 -0
  81. package/dist/services/session/emailCapture/captureEmail.d.ts +8 -0
  82. package/dist/services/session/emailCapture/captureEmail.js +13 -0
  83. package/dist/services/session/emailCapture/requests.d.ts +12 -0
  84. package/dist/services/session/emailCapture/requests.js +6 -0
  85. package/dist/services/session/emailCapture/responses.d.ts +3 -0
  86. package/dist/services/session/emailCapture/responses.js +14 -0
  87. package/dist/services/session/emailCapture/types.d.ts +8 -0
  88. package/dist/services/session/emailCapture/types.js +1 -0
  89. package/dist/services/session/emailCapture/validator.d.ts +16 -0
  90. package/dist/services/session/emailCapture/validator.js +37 -0
  91. package/dist/services/session/identity.d.ts +6 -0
  92. package/dist/services/session/identity.js +48 -0
  93. package/dist/services/session/ping/pingUserContext.d.ts +2 -0
  94. package/dist/services/session/ping/pingUserContext.js +10 -0
  95. package/dist/services/session/ping/transport.d.ts +2 -0
  96. package/dist/services/session/ping/transport.js +41 -0
  97. package/dist/services/session/shared/values.d.ts +6 -0
  98. package/dist/services/session/shared/values.js +25 -0
  99. package/dist/services/session/subscriptions/getManageSubscriptions.d.ts +3 -0
  100. package/dist/services/session/subscriptions/getManageSubscriptions.js +8 -0
  101. package/dist/services/session/subscriptions/identity.d.ts +3 -0
  102. package/dist/services/session/subscriptions/identity.js +8 -0
  103. package/dist/services/session/subscriptions/types.d.ts +35 -0
  104. package/dist/services/session/subscriptions/types.js +1 -0
  105. package/dist/services/session/subscriptions/updateSubscription.d.ts +10 -0
  106. package/dist/services/session/subscriptions/updateSubscription.js +7 -0
  107. package/dist/services/session/subscriptions/validator.d.ts +6 -0
  108. package/dist/services/session/subscriptions/validator.js +13 -0
  109. package/dist/services/session/uploads/localPhoto.d.ts +2 -0
  110. package/dist/services/session/uploads/localPhoto.js +10 -0
  111. package/dist/services/session/uploads/requests.d.ts +10 -0
  112. package/dist/services/session/uploads/requests.js +7 -0
  113. package/dist/services/session/uploads/types.d.ts +7 -0
  114. package/dist/services/session/uploads/types.js +1 -0
  115. package/dist/services/session/uploads/uploadTempPhoto.d.ts +6 -0
  116. package/dist/services/session/uploads/uploadTempPhoto.js +13 -0
  117. package/dist/services/session/uploads/validator.d.ts +3 -0
  118. package/dist/services/session/uploads/validator.js +12 -0
  119. package/dist/services/session/users/mappers.d.ts +13 -0
  120. package/dist/services/session/users/mappers.js +33 -0
  121. package/dist/services/session/users/requests.d.ts +15 -0
  122. package/dist/services/session/users/requests.js +8 -0
  123. package/dist/services/session/users/syncUrlUserAttributes.d.ts +10 -0
  124. package/dist/services/session/users/syncUrlUserAttributes.js +21 -0
  125. package/dist/services/session/users/types.d.ts +20 -0
  126. package/dist/services/session/users/types.js +1 -0
  127. package/dist/services/session/users/updateUser.d.ts +6 -0
  128. package/dist/services/session/users/updateUser.js +18 -0
  129. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ import { toV1PaymentIntentRequest } from './requests.js';
2
+ import { postJson } from '../shared/http.js';
3
+ /** @deprecated Use createOneTimeCheckout for one-time paywall checkout. */
4
+ export const createOneTimePaymentIntent = async (input) => {
5
+ return postJson('/sdk/public/payments/intents', {
6
+ runtimeConfig: input.runtimeConfig,
7
+ body: toV1PaymentIntentRequest(input),
8
+ errorMessage: 'Unable to create payment intent',
9
+ });
10
+ };
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkCreateSubscriptionCheckoutInput, FunnelSdkCreateSubscriptionCheckoutResponse } from './types.js';
2
+ export declare const createSubscriptionCheckout: (input: FunnelSdkCreateSubscriptionCheckoutInput) => Promise<FunnelSdkCreateSubscriptionCheckoutResponse>;
@@ -0,0 +1,22 @@
1
+ import { toV1SubscriptionCheckoutRequest } from './requests.js';
2
+ import { postJson } from '../shared/http.js';
3
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
4
+ import { toV2CheckoutSessionRequest } from './selection.js';
5
+ import { retainCheckoutAccessToken } from '../../checkout-access.service.js';
6
+ export const createSubscriptionCheckout = async (input) => {
7
+ const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
8
+ if (paymentsApiVersion === 'v2') {
9
+ const result = await postJson('/sdk/public/v2/payments/checkout-sessions', {
10
+ runtimeConfig: input.runtimeConfig,
11
+ body: toV2CheckoutSessionRequest(input, 'subscription'),
12
+ errorMessage: 'Unable to create subscription checkout',
13
+ });
14
+ retainCheckoutAccessToken(result.checkoutSessionId, result.checkoutAccessToken);
15
+ return result;
16
+ }
17
+ return postJson('/sdk/public/payments/subscriptions', {
18
+ runtimeConfig: input.runtimeConfig,
19
+ body: toV1SubscriptionCheckoutRequest(input),
20
+ errorMessage: 'Unable to create subscription checkout',
21
+ });
22
+ };
@@ -0,0 +1,127 @@
1
+ import type { FunnelSdkCreateHostedCheckoutSessionInput, FunnelSdkCreateSubscriptionCheckoutInput, FunnelSdkCreateOneTimeCheckoutInput, FunnelSdkUpdateSubscriptionCheckoutPlanInput, FunnelSdkVerifySubscriptionCheckoutInput, FunnelSdkCreateOneTimePaymentIntentInput, FunnelSdkChargeOneClickPaymentInput } from './types.js';
2
+ export declare const toV1HostedCheckoutRequest: (input: FunnelSdkCreateHostedCheckoutSessionInput) => {
3
+ offerSetId: string | null | undefined;
4
+ offerSetKey: string | null | undefined;
5
+ planId: string;
6
+ providerPlanId: string | null | undefined;
7
+ title: string | null | undefined;
8
+ description: string | null | undefined;
9
+ amountCents: number;
10
+ billingInterval: string | null | undefined;
11
+ billingIntervalCount: number | null | undefined;
12
+ couponId: string | null | undefined;
13
+ analyticsMetadata: Record<string, unknown> | null | undefined;
14
+ successUrl: string;
15
+ cancelUrl: string;
16
+ customerEmail: string | null | undefined;
17
+ user_id: string | null | undefined;
18
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
19
+ };
20
+ export declare const toV1SubscriptionCheckoutRequest: (input: FunnelSdkCreateSubscriptionCheckoutInput) => {
21
+ offerSetId: string | null | undefined;
22
+ offerSetKey: string | null | undefined;
23
+ planId: string;
24
+ providerPlanId: string | null | undefined;
25
+ title: string | null | undefined;
26
+ description: string | null | undefined;
27
+ amountCents: number;
28
+ billingInterval: string | null | undefined;
29
+ billingIntervalCount: number | null | undefined;
30
+ followUpProviderPlanId: string | null | undefined;
31
+ followUpPlanTitle: string | null | undefined;
32
+ followUpBillingInterval: string | null | undefined;
33
+ followUpBillingIntervalCount: number | null | undefined;
34
+ introIterations: number | null | undefined;
35
+ couponId: string | null | undefined;
36
+ analyticsMetadata: Record<string, unknown> | null | undefined;
37
+ customerEmail: string | null | undefined;
38
+ returnUrl: string;
39
+ user_id: string | null | undefined;
40
+ anonymousUserId: string | null | undefined;
41
+ idempotencyKey: string | null | undefined;
42
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
43
+ };
44
+ export declare const toV1OneTimeCheckoutRequest: (input: FunnelSdkCreateOneTimeCheckoutInput) => {
45
+ offerSetId: string | null | undefined;
46
+ offerSetKey: string | null | undefined;
47
+ planId: string;
48
+ providerPlanId: string | null | undefined;
49
+ title: string | null | undefined;
50
+ description: string | null | undefined;
51
+ amountCents: number;
52
+ couponId: string | null | undefined;
53
+ analyticsMetadata: Record<string, unknown> | null | undefined;
54
+ customerEmail: string | null | undefined;
55
+ returnUrl: string;
56
+ user_id: string | null | undefined;
57
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
58
+ };
59
+ export declare const toV2SubscriptionPlanUpdateRequest: (input: FunnelSdkUpdateSubscriptionCheckoutPlanInput) => {
60
+ checkoutAccessToken: string | null;
61
+ couponId: string | null | undefined;
62
+ analyticsMetadata: Record<string, unknown> | null | undefined;
63
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
64
+ offerSetId: string | undefined;
65
+ paymentProfileId: string | undefined;
66
+ provider: "stripe" | null | undefined;
67
+ providerPlanId: string | undefined;
68
+ planKey: string | undefined;
69
+ runtimeConfigRevisionId: string | undefined;
70
+ };
71
+ export declare const toV1SubscriptionPlanUpdateRequest: (input: FunnelSdkUpdateSubscriptionCheckoutPlanInput) => {
72
+ checkoutSessionId: string;
73
+ offerSetId: string | null | undefined;
74
+ offerSetKey: string | null | undefined;
75
+ planId: string;
76
+ providerPlanId: string | null | undefined;
77
+ title: string | null | undefined;
78
+ description: string | null | undefined;
79
+ amountCents: number;
80
+ billingInterval: string | null | undefined;
81
+ billingIntervalCount: number | null | undefined;
82
+ couponId: string | null | undefined;
83
+ analyticsMetadata: Record<string, unknown> | null | undefined;
84
+ customerEmail: string | null | undefined;
85
+ user_id: string | null | undefined;
86
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
87
+ };
88
+ export declare const toV1SubscriptionCheckoutStatusRequest: (input: FunnelSdkVerifySubscriptionCheckoutInput) => {
89
+ checkoutSessionId: string;
90
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
91
+ };
92
+ export declare const toV1PaymentIntentRequest: (input: FunnelSdkCreateOneTimePaymentIntentInput) => {
93
+ offerSetId: string | null | undefined;
94
+ offerSetKey: string | null | undefined;
95
+ planId: string;
96
+ amountCents: number;
97
+ couponId: string | null | undefined;
98
+ analyticsMetadata: Record<string, unknown> | null | undefined;
99
+ user_id: string | null | undefined;
100
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
101
+ };
102
+ export declare const toV1OneClickPaymentRequest: (input: FunnelSdkChargeOneClickPaymentInput) => {
103
+ planId: string;
104
+ providerPlanId: string | null | undefined;
105
+ amountCents: number;
106
+ currency: string | null | undefined;
107
+ description: string | null | undefined;
108
+ analyticsMetadata: Record<string, unknown> | null | undefined;
109
+ user_id: string | null | undefined;
110
+ stripe_customer_id: string | null | undefined;
111
+ checkoutSessionId: string | null | undefined;
112
+ idempotencyKey: string | null | undefined;
113
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
114
+ };
115
+ export declare const toV2OneClickPaymentRequest: (input: FunnelSdkChargeOneClickPaymentInput) => {
116
+ checkoutSessionId: string;
117
+ userId: string;
118
+ idempotencyKey: string;
119
+ analyticsMetadata: Record<string, unknown> | null | undefined;
120
+ environment: import("../shared/types.js").FunnelSdkRuntimeMode | undefined;
121
+ offerSetId: string | undefined;
122
+ paymentProfileId: string | undefined;
123
+ provider: "stripe" | null | undefined;
124
+ providerPlanId: string | undefined;
125
+ planKey: string | undefined;
126
+ runtimeConfigRevisionId: string | undefined;
127
+ };
@@ -0,0 +1,112 @@
1
+ import { toV2CheckoutSelection } from './selection.js';
2
+ import { getCheckoutAccessToken } from '../../checkout-access.service.js';
3
+ export const toV1HostedCheckoutRequest = (input) => ({
4
+ offerSetId: input.offerSetId,
5
+ offerSetKey: input.offerSetKey,
6
+ planId: input.planId,
7
+ providerPlanId: input.providerPlanId,
8
+ title: input.title,
9
+ description: input.description,
10
+ amountCents: input.amountCents,
11
+ billingInterval: input.billingInterval,
12
+ billingIntervalCount: input.billingIntervalCount,
13
+ couponId: input.couponId,
14
+ analyticsMetadata: input.analyticsMetadata,
15
+ successUrl: input.successUrl,
16
+ cancelUrl: input.cancelUrl,
17
+ customerEmail: input.customerEmail,
18
+ user_id: input.userId,
19
+ environment: input.environment,
20
+ });
21
+ export const toV1SubscriptionCheckoutRequest = (input) => ({
22
+ offerSetId: input.offerSetId,
23
+ offerSetKey: input.offerSetKey,
24
+ planId: input.planId,
25
+ providerPlanId: input.providerPlanId,
26
+ title: input.title,
27
+ description: input.description,
28
+ amountCents: input.amountCents,
29
+ billingInterval: input.billingInterval,
30
+ billingIntervalCount: input.billingIntervalCount,
31
+ followUpProviderPlanId: input.followUpProviderPlanId,
32
+ followUpPlanTitle: input.followUpPlanTitle,
33
+ followUpBillingInterval: input.followUpBillingInterval,
34
+ followUpBillingIntervalCount: input.followUpBillingIntervalCount,
35
+ introIterations: input.introIterations,
36
+ couponId: input.couponId,
37
+ analyticsMetadata: input.analyticsMetadata,
38
+ customerEmail: input.customerEmail,
39
+ returnUrl: input.returnUrl,
40
+ user_id: input.userId,
41
+ anonymousUserId: input.anonymousUserId,
42
+ idempotencyKey: input.idempotencyKey,
43
+ environment: input.environment,
44
+ });
45
+ export const toV1OneTimeCheckoutRequest = (input) => ({
46
+ offerSetId: input.offerSetId,
47
+ offerSetKey: input.offerSetKey,
48
+ planId: input.planId,
49
+ providerPlanId: input.providerPlanId,
50
+ title: input.title,
51
+ description: input.description,
52
+ amountCents: input.amountCents,
53
+ couponId: input.couponId,
54
+ analyticsMetadata: input.analyticsMetadata,
55
+ customerEmail: input.customerEmail,
56
+ returnUrl: input.returnUrl,
57
+ user_id: input.userId,
58
+ environment: input.environment,
59
+ });
60
+ export const toV2SubscriptionPlanUpdateRequest = (input) => (Object.assign(Object.assign({}, toV2CheckoutSelection(input)), { checkoutAccessToken: getCheckoutAccessToken(input.checkoutSessionId), couponId: input.couponId, analyticsMetadata: input.analyticsMetadata, environment: input.environment }));
61
+ export const toV1SubscriptionPlanUpdateRequest = (input) => ({
62
+ checkoutSessionId: input.checkoutSessionId,
63
+ offerSetId: input.offerSetId,
64
+ offerSetKey: input.offerSetKey,
65
+ planId: input.planId,
66
+ providerPlanId: input.providerPlanId,
67
+ title: input.title,
68
+ description: input.description,
69
+ amountCents: input.amountCents,
70
+ billingInterval: input.billingInterval,
71
+ billingIntervalCount: input.billingIntervalCount,
72
+ couponId: input.couponId,
73
+ analyticsMetadata: input.analyticsMetadata,
74
+ customerEmail: input.customerEmail,
75
+ user_id: input.userId,
76
+ environment: input.environment,
77
+ });
78
+ export const toV1SubscriptionCheckoutStatusRequest = (input) => ({
79
+ checkoutSessionId: input.checkoutSessionId,
80
+ environment: input.environment,
81
+ });
82
+ export const toV1PaymentIntentRequest = (input) => ({
83
+ offerSetId: input.offerSetId,
84
+ offerSetKey: input.offerSetKey,
85
+ planId: input.planId,
86
+ amountCents: input.amountCents,
87
+ couponId: input.couponId,
88
+ analyticsMetadata: input.analyticsMetadata,
89
+ user_id: input.userId,
90
+ environment: input.environment,
91
+ });
92
+ export const toV1OneClickPaymentRequest = (input) => ({
93
+ planId: input.planId,
94
+ providerPlanId: input.providerPlanId,
95
+ amountCents: input.amountCents,
96
+ currency: input.currency,
97
+ description: input.description,
98
+ analyticsMetadata: input.analyticsMetadata,
99
+ user_id: input.userId,
100
+ stripe_customer_id: input.stripeCustomerId,
101
+ checkoutSessionId: input.checkoutSessionId,
102
+ idempotencyKey: input.idempotencyKey,
103
+ environment: input.environment,
104
+ });
105
+ export const toV2OneClickPaymentRequest = (input) => {
106
+ var _a, _b, _c;
107
+ const selection = toV2CheckoutSelection(input);
108
+ if (!((_a = input.checkoutSessionId) === null || _a === void 0 ? void 0 : _a.trim()) || !((_b = input.userId) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = input.idempotencyKey) === null || _c === void 0 ? void 0 : _c.trim())) {
109
+ throw new Error('V2 one-click requires checkoutSessionId, userId and idempotencyKey');
110
+ }
111
+ return Object.assign(Object.assign({}, selection), { checkoutSessionId: input.checkoutSessionId, userId: input.userId, idempotencyKey: input.idempotencyKey, analyticsMetadata: input.analyticsMetadata, environment: input.environment });
112
+ };
@@ -22,6 +22,7 @@ export declare const toV2CheckoutSessionRequest: (input: PublishedStripeSelectio
22
22
  returnUrl: string;
23
23
  userId?: string | null;
24
24
  anonymousUserId?: string | null;
25
+ checkoutIdentityToken?: string | null;
25
26
  idempotencyKey?: string | null;
26
27
  environment?: "test" | "live";
27
28
  }, checkoutType: "subscription" | "one_time") => {
@@ -33,6 +34,7 @@ export declare const toV2CheckoutSessionRequest: (input: PublishedStripeSelectio
33
34
  returnUrl: string;
34
35
  userId: string | null | undefined;
35
36
  anonymousUserId: string | null | undefined;
37
+ checkoutIdentityToken: string | null | undefined;
36
38
  idempotencyKey: string | null | undefined;
37
39
  environment: "test" | "live" | undefined;
38
40
  offerSetId: string | undefined;
@@ -14,4 +14,4 @@ export const toV2CheckoutSelection = (input) => {
14
14
  // Retained for older API versions, but not required to identify an offer.
15
15
  runtimeConfigRevisionId: ((_f = input.runtimeConfigRevisionId) === null || _f === void 0 ? void 0 : _f.trim()) || undefined }, selection);
16
16
  };
17
- export const toV2CheckoutSessionRequest = (input, checkoutType) => (Object.assign(Object.assign({}, toV2CheckoutSelection(input)), { checkoutType, uiMode: 'custom', couponId: input.couponId, analyticsMetadata: input.analyticsMetadata, customerEmail: input.customerEmail, returnUrl: input.returnUrl, userId: input.userId, anonymousUserId: input.anonymousUserId, idempotencyKey: input.idempotencyKey, environment: input.environment }));
17
+ export const toV2CheckoutSessionRequest = (input, checkoutType) => (Object.assign(Object.assign({}, toV2CheckoutSelection(input)), { checkoutType, uiMode: 'custom', couponId: input.couponId, analyticsMetadata: input.analyticsMetadata, customerEmail: input.customerEmail, returnUrl: input.returnUrl, userId: input.userId, anonymousUserId: input.anonymousUserId, checkoutIdentityToken: input.checkoutIdentityToken, idempotencyKey: input.idempotencyKey, environment: input.environment }));
@@ -0,0 +1,187 @@
1
+ import type { FunnelSdkRuntimeMode, FunnelSdkRuntimeConfigOverrides } from '../shared/types.js';
2
+ export type FunnelSdkCreateHostedCheckoutSessionInput = {
3
+ planId: string;
4
+ offerSetId?: string | null;
5
+ offerSetKey?: string | null;
6
+ amountCents: number;
7
+ successUrl: string;
8
+ cancelUrl: string;
9
+ analyticsMetadata?: Record<string, unknown> | null;
10
+ billingInterval?: string | null;
11
+ billingIntervalCount?: number | null;
12
+ couponId?: string | null;
13
+ customerEmail?: string | null;
14
+ description?: string | null;
15
+ environment?: FunnelSdkRuntimeMode;
16
+ providerPlanId?: string | null;
17
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
18
+ title?: string | null;
19
+ userId?: string | null;
20
+ };
21
+ export type FunnelSdkCreateHostedCheckoutSessionResponse = {
22
+ sessionId?: string;
23
+ url: string;
24
+ environment?: FunnelSdkRuntimeMode;
25
+ };
26
+ export type FunnelSdkCreateSubscriptionCheckoutInput = {
27
+ planId: string;
28
+ planKey?: string | null;
29
+ offerSetId?: string | null;
30
+ offerSetKey?: string | null;
31
+ amountCents: number;
32
+ returnUrl: string;
33
+ analyticsMetadata?: Record<string, unknown> | null;
34
+ billingInterval?: string | null;
35
+ billingIntervalCount?: number | null;
36
+ followUpProviderPlanId?: string | null;
37
+ followUpPlanTitle?: string | null;
38
+ followUpBillingInterval?: string | null;
39
+ followUpBillingIntervalCount?: number | null;
40
+ introIterations?: number | null;
41
+ couponId?: string | null;
42
+ customerEmail?: string | null;
43
+ description?: string | null;
44
+ environment?: FunnelSdkRuntimeMode;
45
+ providerPlanId?: string | null;
46
+ provider?: 'stripe' | null;
47
+ paymentProfileId?: string | null;
48
+ runtimeConfigRevisionId?: string | null;
49
+ anonymousUserId?: string | null;
50
+ checkoutIdentityToken?: string | null;
51
+ idempotencyKey?: string | null;
52
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
53
+ title?: string | null;
54
+ userId?: string | null;
55
+ };
56
+ export type FunnelSdkCreateSubscriptionCheckoutResponse = {
57
+ clientSecret: string;
58
+ checkoutSessionId?: string;
59
+ checkoutAccessToken?: string;
60
+ subscriptionId?: string;
61
+ stripePublishableKey?: string;
62
+ environment?: FunnelSdkRuntimeMode;
63
+ };
64
+ export type FunnelSdkCreateOneTimeCheckoutInput = {
65
+ planId: string;
66
+ planKey?: string | null;
67
+ paymentProfileId?: string | null;
68
+ provider?: 'stripe' | null;
69
+ runtimeConfigRevisionId?: string | null;
70
+ anonymousUserId?: string | null;
71
+ checkoutIdentityToken?: string | null;
72
+ idempotencyKey?: string | null;
73
+ offerSetId?: string | null;
74
+ offerSetKey?: string | null;
75
+ amountCents: number;
76
+ returnUrl: string;
77
+ analyticsMetadata?: Record<string, unknown> | null;
78
+ couponId?: string | null;
79
+ customerEmail?: string | null;
80
+ description?: string | null;
81
+ environment?: FunnelSdkRuntimeMode;
82
+ providerPlanId?: string | null;
83
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
84
+ title?: string | null;
85
+ userId?: string | null;
86
+ };
87
+ export type FunnelSdkCreateOneTimeCheckoutResponse = {
88
+ clientSecret: string;
89
+ checkoutSessionId?: string;
90
+ checkoutAccessToken?: string;
91
+ stripePublishableKey?: string;
92
+ environment?: FunnelSdkRuntimeMode;
93
+ };
94
+ export type FunnelSdkUpdateSubscriptionCheckoutPlanInput = {
95
+ checkoutSessionId: string;
96
+ planId: string;
97
+ planKey?: string | null;
98
+ offerSetId?: string | null;
99
+ offerSetKey?: string | null;
100
+ amountCents: number;
101
+ analyticsMetadata?: Record<string, unknown> | null;
102
+ billingInterval?: string | null;
103
+ billingIntervalCount?: number | null;
104
+ followUpProviderPlanId?: string | null;
105
+ followUpPlanTitle?: string | null;
106
+ followUpBillingInterval?: string | null;
107
+ followUpBillingIntervalCount?: number | null;
108
+ introIterations?: number | null;
109
+ couponId?: string | null;
110
+ customerEmail?: string | null;
111
+ description?: string | null;
112
+ environment?: FunnelSdkRuntimeMode;
113
+ providerPlanId?: string | null;
114
+ provider?: 'stripe' | null;
115
+ paymentProfileId?: string | null;
116
+ runtimeConfigRevisionId?: string | null;
117
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
118
+ title?: string | null;
119
+ userId?: string | null;
120
+ };
121
+ export type FunnelSdkUpdateSubscriptionCheckoutPlanResponse = {
122
+ checkoutSessionId: string;
123
+ environment?: FunnelSdkRuntimeMode;
124
+ };
125
+ export type FunnelSdkVerifySubscriptionCheckoutInput = {
126
+ checkoutSessionId: string;
127
+ environment?: FunnelSdkRuntimeMode;
128
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
129
+ };
130
+ export type FunnelSdkVerifySubscriptionCheckoutResponse = {
131
+ checkoutSessionId: string;
132
+ paid: boolean;
133
+ paymentStatus?: string | null;
134
+ status?: string | null;
135
+ environment?: FunnelSdkRuntimeMode;
136
+ analyticsMetadata?: Record<string, unknown>;
137
+ };
138
+ /**
139
+ * @deprecated Use FunnelSdkCreateOneTimeCheckoutInput for one-time paywall checkout.
140
+ */
141
+ export type FunnelSdkCreateOneTimePaymentIntentInput = {
142
+ planId: string;
143
+ offerSetId?: string | null;
144
+ offerSetKey?: string | null;
145
+ amountCents: number;
146
+ analyticsMetadata?: Record<string, unknown> | null;
147
+ couponId?: string | null;
148
+ environment?: FunnelSdkRuntimeMode;
149
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
150
+ userId?: string | null;
151
+ };
152
+ /**
153
+ * @deprecated Use FunnelSdkCreateOneTimeCheckoutResponse for one-time paywall checkout.
154
+ */
155
+ export type FunnelSdkCreateOneTimePaymentIntentResponse = {
156
+ clientSecret: string;
157
+ stripePublishableKey?: string;
158
+ environment?: FunnelSdkRuntimeMode;
159
+ };
160
+ export type FunnelSdkChargeOneClickPaymentInput = {
161
+ planId: string;
162
+ planKey?: string | null;
163
+ offerSetId?: string | null;
164
+ paymentProfileId?: string | null;
165
+ provider?: 'stripe' | null;
166
+ runtimeConfigRevisionId?: string | null;
167
+ providerPlanId?: string | null;
168
+ amountCents: number;
169
+ analyticsMetadata?: Record<string, unknown> | null;
170
+ checkoutSessionId?: string | null;
171
+ currency?: string | null;
172
+ description?: string | null;
173
+ environment?: FunnelSdkRuntimeMode;
174
+ idempotencyKey?: string | null;
175
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
176
+ stripeCustomerId?: string | null;
177
+ userId?: string | null;
178
+ };
179
+ export type FunnelSdkChargeOneClickPaymentResponse = {
180
+ paymentIntentId: string;
181
+ status: string;
182
+ amountCents?: number;
183
+ clientSecret?: string;
184
+ currency?: string;
185
+ environment?: FunnelSdkRuntimeMode;
186
+ stripePublishableKey?: string;
187
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkUpdateSubscriptionCheckoutPlanInput, FunnelSdkUpdateSubscriptionCheckoutPlanResponse } from './types.js';
2
+ export declare const updateSubscriptionCheckoutPlan: (input: FunnelSdkUpdateSubscriptionCheckoutPlanInput) => Promise<FunnelSdkUpdateSubscriptionCheckoutPlanResponse>;
@@ -0,0 +1,18 @@
1
+ import { toV2SubscriptionPlanUpdateRequest, toV1SubscriptionPlanUpdateRequest } from './requests.js';
2
+ import { postJson, patchJson } from '../shared/http.js';
3
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
4
+ export const updateSubscriptionCheckoutPlan = async (input) => {
5
+ const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
6
+ if (paymentsApiVersion === 'v2') {
7
+ return patchJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(input.checkoutSessionId)}`, {
8
+ runtimeConfig: input.runtimeConfig,
9
+ body: toV2SubscriptionPlanUpdateRequest(input),
10
+ errorMessage: 'Unable to update subscription checkout',
11
+ });
12
+ }
13
+ return postJson('/sdk/public/payments/subscriptions/update-plan', {
14
+ runtimeConfig: input.runtimeConfig,
15
+ body: toV1SubscriptionPlanUpdateRequest(input),
16
+ errorMessage: 'Unable to update subscription checkout',
17
+ });
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkVerifySubscriptionCheckoutInput, FunnelSdkVerifySubscriptionCheckoutResponse } from './types.js';
2
+ export declare const verifySubscriptionCheckout: (input: FunnelSdkVerifySubscriptionCheckoutInput) => Promise<FunnelSdkVerifySubscriptionCheckoutResponse>;
@@ -0,0 +1,25 @@
1
+ import { toV1SubscriptionCheckoutStatusRequest } from './requests.js';
2
+ import { postJson, getJson } from '../shared/http.js';
3
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
4
+ import { getCheckoutAccessToken } from '../../checkout-access.service.js';
5
+ export const verifySubscriptionCheckout = async (input) => {
6
+ const { funnelId, paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
7
+ if (paymentsApiVersion === 'v2') {
8
+ const checkoutAccessToken = getCheckoutAccessToken(input.checkoutSessionId);
9
+ return getJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(input.checkoutSessionId)}`, {
10
+ runtimeConfig: input.runtimeConfig,
11
+ searchParams: { funnelId },
12
+ headers: Object.assign({}, (checkoutAccessToken
13
+ ? {
14
+ 'x-funnelsgrove-checkout-access-token': checkoutAccessToken,
15
+ }
16
+ : {})),
17
+ errorMessage: 'Unable to verify subscription checkout',
18
+ });
19
+ }
20
+ return postJson('/sdk/public/payments/subscriptions/checkout-session-status', {
21
+ runtimeConfig: input.runtimeConfig,
22
+ body: toV1SubscriptionCheckoutStatusRequest(input),
23
+ errorMessage: 'Unable to verify subscription checkout',
24
+ });
25
+ };
@@ -0,0 +1,21 @@
1
+ import type { FunnelSdkRuntimeConfigOverrides } from './types.js';
2
+ type JsonWriteInput = {
3
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
4
+ body?: Record<string, unknown>;
5
+ errorMessage: string;
6
+ includeRuntimeFields?: boolean;
7
+ includePublishableKey?: boolean;
8
+ };
9
+ export declare const getJson: <ResponsePayload>(path: string, input: {
10
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
11
+ searchParams?: Record<string, string | null | undefined>;
12
+ headers?: Record<string, string>;
13
+ errorMessage: string;
14
+ }) => Promise<ResponsePayload>;
15
+ export declare const postJson: <ResponsePayload>(path: string, input: JsonWriteInput) => Promise<ResponsePayload>;
16
+ export declare const patchJson: <ResponsePayload>(path: string, input: {
17
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
18
+ body?: Record<string, unknown>;
19
+ errorMessage: string;
20
+ }) => Promise<ResponsePayload>;
21
+ export {};
@@ -0,0 +1,65 @@
1
+ import { asTrimmedStringOrNull, removeEmptyFields, buildApiUrl, buildHeaders, withRuntimeFields, } from './runtimeConfig.js';
2
+ const parseErrorMessage = async (response, fallbackMessage) => {
3
+ try {
4
+ const payload = (await response.json());
5
+ const apiError = asTrimmedStringOrNull(payload.error);
6
+ if (apiError) {
7
+ return apiError;
8
+ }
9
+ }
10
+ catch (_a) {
11
+ // ignore JSON parsing errors
12
+ }
13
+ try {
14
+ const text = await response.text();
15
+ if (text.trim()) {
16
+ return text;
17
+ }
18
+ }
19
+ catch (_b) {
20
+ // ignore text parsing errors
21
+ }
22
+ return fallbackMessage;
23
+ };
24
+ const readJsonResponse = async (response, fallbackMessage) => {
25
+ if (!response.ok) {
26
+ throw new Error(await parseErrorMessage(response, fallbackMessage));
27
+ }
28
+ return (await response.json());
29
+ };
30
+ export const getJson = async (path, input) => {
31
+ var _a;
32
+ const url = new URL(buildApiUrl(path, input.runtimeConfig));
33
+ for (const [key, value] of Object.entries((_a = input.searchParams) !== null && _a !== void 0 ? _a : {})) {
34
+ const normalizedValue = asTrimmedStringOrNull(value);
35
+ if (normalizedValue) {
36
+ url.searchParams.set(key, normalizedValue);
37
+ }
38
+ }
39
+ const response = await fetch(url.toString(), {
40
+ method: 'GET',
41
+ headers: buildHeaders(input.runtimeConfig, input.headers),
42
+ });
43
+ return readJsonResponse(response, input.errorMessage);
44
+ };
45
+ const writeJson = async (method, path, input) => {
46
+ var _a;
47
+ const response = await fetch(buildApiUrl(path, input.runtimeConfig), {
48
+ method,
49
+ headers: buildHeaders(input.runtimeConfig, {
50
+ 'Content-Type': 'application/json',
51
+ }),
52
+ body: JSON.stringify(input.includeRuntimeFields === false
53
+ ? removeEmptyFields((_a = input.body) !== null && _a !== void 0 ? _a : {})
54
+ : withRuntimeFields(input.runtimeConfig, input.body, {
55
+ includePublishableKey: input.includePublishableKey,
56
+ })),
57
+ });
58
+ return readJsonResponse(response, input.errorMessage);
59
+ };
60
+ export const postJson = (path, input) => {
61
+ return writeJson('POST', path, input);
62
+ };
63
+ export const patchJson = async (path, input) => {
64
+ return writeJson('PATCH', path, input);
65
+ };
@@ -0,0 +1,17 @@
1
+ import type { FunnelSdkRuntimeConfigOverrides } from './types.js';
2
+ export declare const asTrimmedStringOrNull: (value: unknown) => string | null;
3
+ export declare const removeEmptyFields: (input: Record<string, unknown>) => Record<string, unknown>;
4
+ type ResolvedFunnelSdkRuntimeConfig = {
5
+ apiBaseUrl: string | null;
6
+ funnelId: string | null;
7
+ funnelVersionId: string | null;
8
+ funnelSdkPublishableKey: string | null;
9
+ paymentsApiVersion: 'v1' | 'v2';
10
+ };
11
+ export declare const resolveRuntimeConfig: (runtimeConfig?: FunnelSdkRuntimeConfigOverrides) => ResolvedFunnelSdkRuntimeConfig;
12
+ export declare const buildApiUrl: (path: string, runtimeConfig?: FunnelSdkRuntimeConfigOverrides) => string;
13
+ export declare const buildHeaders: (runtimeConfig?: FunnelSdkRuntimeConfigOverrides, headers?: Record<string, string>) => Record<string, string>;
14
+ export declare const withRuntimeFields: (runtimeConfig?: FunnelSdkRuntimeConfigOverrides, body?: Record<string, unknown>, options?: {
15
+ includePublishableKey?: boolean;
16
+ }) => Record<string, unknown>;
17
+ export {};