@funnelsgrove/runtime 0.8.0 → 0.9.0
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.
|
@@ -4,6 +4,7 @@ export type FunnelRuntimeConfig = {
|
|
|
4
4
|
schemaVersion: 2;
|
|
5
5
|
funnelId: string;
|
|
6
6
|
projectId: string;
|
|
7
|
+
paymentsApiVersion?: 'v1' | 'v2';
|
|
7
8
|
sessionReplay?: {
|
|
8
9
|
enabled?: unknown;
|
|
9
10
|
sampleRate?: unknown;
|
|
@@ -22,6 +23,7 @@ export type ResolvedFunnelRuntimeConfig = {
|
|
|
22
23
|
sourceDeploymentId: string;
|
|
23
24
|
sourceVersionId: string;
|
|
24
25
|
publishedAt: string;
|
|
26
|
+
paymentsApiVersion?: 'v1' | 'v2';
|
|
25
27
|
sessionReplay?: FunnelSessionReplayConfig;
|
|
26
28
|
defaultOfferSetId?: string | null;
|
|
27
29
|
offerSets: readonly GeneratedOfferSet[];
|
|
@@ -269,6 +269,7 @@ export const resolvePublishedFunnelRuntimeConfig = (published, options = {}) =>
|
|
|
269
269
|
sourceDeploymentId: published.sourceDeploymentId,
|
|
270
270
|
sourceVersionId: published.sourceVersionId,
|
|
271
271
|
publishedAt: published.publishedAt,
|
|
272
|
+
paymentsApiVersion: published.config.paymentsApiVersion === 'v2' ? 'v2' : 'v1',
|
|
272
273
|
sessionReplay: normalizeSessionReplay(published.config.sessionReplay),
|
|
273
274
|
defaultOfferSetId: hasDomainDefault && isRecord(domainDefaults)
|
|
274
275
|
? readString(domainDefaults[hostname])
|
|
@@ -4,6 +4,7 @@ export type FunnelSdkRuntimeConfigOverrides = {
|
|
|
4
4
|
funnelId?: string | null;
|
|
5
5
|
funnelVersionId?: string | null;
|
|
6
6
|
funnelSdkPublishableKey?: string | null;
|
|
7
|
+
paymentsApiVersion?: 'v1' | 'v2' | null;
|
|
7
8
|
};
|
|
8
9
|
export type FunnelSdkJsonObject = Record<string, unknown>;
|
|
9
10
|
export type FunnelSdkBootstrapUserInput = {
|
|
@@ -115,6 +116,7 @@ export type FunnelSdkCreateHostedCheckoutSessionResponse = {
|
|
|
115
116
|
};
|
|
116
117
|
export type FunnelSdkCreateSubscriptionCheckoutInput = {
|
|
117
118
|
planId: string;
|
|
119
|
+
planKey?: string | null;
|
|
118
120
|
offerSetId?: string | null;
|
|
119
121
|
offerSetKey?: string | null;
|
|
120
122
|
amountCents: number;
|
|
@@ -132,6 +134,11 @@ export type FunnelSdkCreateSubscriptionCheckoutInput = {
|
|
|
132
134
|
description?: string | null;
|
|
133
135
|
environment?: FunnelSdkRuntimeMode;
|
|
134
136
|
providerPlanId?: string | null;
|
|
137
|
+
provider?: 'stripe' | null;
|
|
138
|
+
paymentProfileId?: string | null;
|
|
139
|
+
runtimeConfigRevisionId?: string | null;
|
|
140
|
+
anonymousUserId?: string | null;
|
|
141
|
+
idempotencyKey?: string | null;
|
|
135
142
|
runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
|
|
136
143
|
title?: string | null;
|
|
137
144
|
userId?: string | null;
|
|
@@ -20,6 +20,7 @@ const resolveRuntimeConfig = (runtimeConfig) => {
|
|
|
20
20
|
funnelId: (_a = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelId)) !== null && _a !== void 0 ? _a : asTrimmedStringOrNull(FUNNEL_ID),
|
|
21
21
|
funnelVersionId: (_b = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelVersionId)) !== null && _b !== void 0 ? _b : asTrimmedStringOrNull(FUNNEL_VERSION_ID),
|
|
22
22
|
funnelSdkPublishableKey: resolvePreviewPaymentPublishableKey((_c = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey)) !== null && _c !== void 0 ? _c : asTrimmedStringOrNull(FUNNEL_SDK_PUBLISHABLE_KEY)) || null,
|
|
23
|
+
paymentsApiVersion: (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.paymentsApiVersion) === 'v2' ? 'v2' : 'v1',
|
|
23
24
|
});
|
|
24
25
|
};
|
|
25
26
|
const buildApiUrl = (path, runtimeConfig) => {
|
|
@@ -254,6 +255,44 @@ class FunnelSdkService {
|
|
|
254
255
|
});
|
|
255
256
|
}
|
|
256
257
|
async createSubscriptionCheckout(input) {
|
|
258
|
+
const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
|
|
259
|
+
if (paymentsApiVersion === 'v2') {
|
|
260
|
+
const runtimeConfigRevisionId = asTrimmedStringOrNull(input.runtimeConfigRevisionId);
|
|
261
|
+
const offerSetId = asTrimmedStringOrNull(input.offerSetId);
|
|
262
|
+
const paymentProfileId = asTrimmedStringOrNull(input.paymentProfileId);
|
|
263
|
+
const providerPlanId = asTrimmedStringOrNull(input.providerPlanId);
|
|
264
|
+
const planKey = asTrimmedStringOrNull(input.planKey) || asTrimmedStringOrNull(input.planId);
|
|
265
|
+
if (!runtimeConfigRevisionId
|
|
266
|
+
|| !offerSetId
|
|
267
|
+
|| !paymentProfileId
|
|
268
|
+
|| !providerPlanId
|
|
269
|
+
|| !planKey
|
|
270
|
+
|| input.provider !== 'stripe') {
|
|
271
|
+
throw new Error('Published Stripe checkout selection is incomplete');
|
|
272
|
+
}
|
|
273
|
+
return this.postJson('/sdk/public/v2/payments/checkout-sessions', {
|
|
274
|
+
runtimeConfig: input.runtimeConfig,
|
|
275
|
+
body: {
|
|
276
|
+
runtimeConfigRevisionId,
|
|
277
|
+
offerSetId,
|
|
278
|
+
paymentProfileId,
|
|
279
|
+
provider: 'stripe',
|
|
280
|
+
providerPlanId,
|
|
281
|
+
planKey,
|
|
282
|
+
checkoutType: 'subscription',
|
|
283
|
+
uiMode: 'custom',
|
|
284
|
+
couponId: input.couponId,
|
|
285
|
+
analyticsMetadata: input.analyticsMetadata,
|
|
286
|
+
customerEmail: input.customerEmail,
|
|
287
|
+
returnUrl: input.returnUrl,
|
|
288
|
+
userId: input.userId,
|
|
289
|
+
anonymousUserId: input.anonymousUserId,
|
|
290
|
+
idempotencyKey: input.idempotencyKey,
|
|
291
|
+
environment: input.environment,
|
|
292
|
+
},
|
|
293
|
+
errorMessage: 'Unable to create subscription checkout',
|
|
294
|
+
});
|
|
295
|
+
}
|
|
257
296
|
return this.postJson('/sdk/public/payments/subscriptions', {
|
|
258
297
|
runtimeConfig: input.runtimeConfig,
|
|
259
298
|
body: {
|
|
@@ -276,6 +315,8 @@ class FunnelSdkService {
|
|
|
276
315
|
customerEmail: input.customerEmail,
|
|
277
316
|
returnUrl: input.returnUrl,
|
|
278
317
|
user_id: input.userId,
|
|
318
|
+
anonymousUserId: input.anonymousUserId,
|
|
319
|
+
idempotencyKey: input.idempotencyKey,
|
|
279
320
|
environment: input.environment,
|
|
280
321
|
},
|
|
281
322
|
errorMessage: 'Unable to create subscription checkout',
|