@funnelsgrove/runtime 0.10.0 → 0.11.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.
@@ -0,0 +1,44 @@
1
+ export type PublishedStripeSelectionInput = {
2
+ planId?: string | null;
3
+ planKey?: string | null;
4
+ offerSetId?: string | null;
5
+ paymentProfileId?: string | null;
6
+ provider?: 'stripe' | null;
7
+ providerPlanId?: string | null;
8
+ runtimeConfigRevisionId?: string | null;
9
+ };
10
+ export declare const toV2CheckoutSelection: (input: PublishedStripeSelectionInput) => {
11
+ runtimeConfigRevisionId: string | undefined;
12
+ offerSetId: string | undefined;
13
+ paymentProfileId: string | undefined;
14
+ provider: "stripe" | null | undefined;
15
+ providerPlanId: string | undefined;
16
+ planKey: string | undefined;
17
+ };
18
+ export declare const toV2CheckoutSessionRequest: (input: PublishedStripeSelectionInput & {
19
+ couponId?: string | null;
20
+ analyticsMetadata?: Record<string, unknown> | null;
21
+ customerEmail?: string | null;
22
+ returnUrl: string;
23
+ userId?: string | null;
24
+ anonymousUserId?: string | null;
25
+ idempotencyKey?: string | null;
26
+ environment?: "test" | "live";
27
+ }, checkoutType: "subscription" | "one_time") => {
28
+ checkoutType: "one_time" | "subscription";
29
+ uiMode: string;
30
+ couponId: string | null | undefined;
31
+ analyticsMetadata: Record<string, unknown> | null | undefined;
32
+ customerEmail: string | null | undefined;
33
+ returnUrl: string;
34
+ userId: string | null | undefined;
35
+ anonymousUserId: string | null | undefined;
36
+ idempotencyKey: string | null | undefined;
37
+ environment: "test" | "live" | undefined;
38
+ runtimeConfigRevisionId: string | undefined;
39
+ offerSetId: string | undefined;
40
+ paymentProfileId: string | undefined;
41
+ provider: "stripe" | null | undefined;
42
+ providerPlanId: string | undefined;
43
+ planKey: string | undefined;
44
+ };
@@ -0,0 +1,16 @@
1
+ export const toV2CheckoutSelection = (input) => {
2
+ var _a, _b, _c, _d, _e, _f;
3
+ const selection = {
4
+ runtimeConfigRevisionId: (_a = input.runtimeConfigRevisionId) === null || _a === void 0 ? void 0 : _a.trim(),
5
+ offerSetId: (_b = input.offerSetId) === null || _b === void 0 ? void 0 : _b.trim(),
6
+ paymentProfileId: (_c = input.paymentProfileId) === null || _c === void 0 ? void 0 : _c.trim(),
7
+ provider: input.provider,
8
+ providerPlanId: (_d = input.providerPlanId) === null || _d === void 0 ? void 0 : _d.trim(),
9
+ planKey: ((_e = input.planKey) === null || _e === void 0 ? void 0 : _e.trim()) || ((_f = input.planId) === null || _f === void 0 ? void 0 : _f.trim()),
10
+ };
11
+ if (selection.provider !== 'stripe' || Object.values(selection).some((value) => !value)) {
12
+ throw new Error('Published Stripe checkout selection is incomplete');
13
+ }
14
+ return selection;
15
+ };
16
+ 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 }));
@@ -152,6 +152,12 @@ export type FunnelSdkCreateSubscriptionCheckoutResponse = {
152
152
  };
153
153
  export type FunnelSdkCreateOneTimeCheckoutInput = {
154
154
  planId: string;
155
+ planKey?: string | null;
156
+ paymentProfileId?: string | null;
157
+ provider?: 'stripe' | null;
158
+ runtimeConfigRevisionId?: string | null;
159
+ anonymousUserId?: string | null;
160
+ idempotencyKey?: string | null;
155
161
  offerSetId?: string | null;
156
162
  offerSetKey?: string | null;
157
163
  amountCents: number;
@@ -240,6 +246,11 @@ export type FunnelSdkCreateOneTimePaymentIntentResponse = {
240
246
  };
241
247
  export type FunnelSdkChargeOneClickPaymentInput = {
242
248
  planId: string;
249
+ planKey?: string | null;
250
+ offerSetId?: string | null;
251
+ paymentProfileId?: string | null;
252
+ provider?: 'stripe' | null;
253
+ runtimeConfigRevisionId?: string | null;
243
254
  providerPlanId?: string | null;
244
255
  amountCents: number;
245
256
  analyticsMetadata?: Record<string, unknown> | null;
@@ -1,6 +1,7 @@
1
1
  import { buildMainApiUrl, FUNNEL_ID, FUNNEL_SDK_PUBLISHABLE_KEY, FUNNEL_VERSION_ID, } from './runtime-api.config.js';
2
2
  import { resolvePreviewPaymentPublishableKey } from './public-env.js';
3
3
  import { CURRENT_STEP_CONTRACT_VERSION } from '../steps/step-contract.js';
4
+ import { toV2CheckoutSelection, toV2CheckoutSessionRequest } from './funnel-sdk-payments.functions.js';
4
5
  const trimTrailingSlash = (value) => value.replace(/\/+$/, '');
5
6
  const toNormalizedPath = (path) => (path.startsWith('/') ? path : `/${path}`);
6
7
  const asTrimmedStringOrNull = (value) => {
@@ -263,39 +264,9 @@ class FunnelSdkService {
263
264
  async createSubscriptionCheckout(input) {
264
265
  const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
265
266
  if (paymentsApiVersion === 'v2') {
266
- const runtimeConfigRevisionId = asTrimmedStringOrNull(input.runtimeConfigRevisionId);
267
- const offerSetId = asTrimmedStringOrNull(input.offerSetId);
268
- const paymentProfileId = asTrimmedStringOrNull(input.paymentProfileId);
269
- const providerPlanId = asTrimmedStringOrNull(input.providerPlanId);
270
- const planKey = asTrimmedStringOrNull(input.planKey) || asTrimmedStringOrNull(input.planId);
271
- if (!runtimeConfigRevisionId
272
- || !offerSetId
273
- || !paymentProfileId
274
- || !providerPlanId
275
- || !planKey
276
- || input.provider !== 'stripe') {
277
- throw new Error('Published Stripe checkout selection is incomplete');
278
- }
279
267
  return this.postJson('/sdk/public/v2/payments/checkout-sessions', {
280
268
  runtimeConfig: input.runtimeConfig,
281
- body: {
282
- runtimeConfigRevisionId,
283
- offerSetId,
284
- paymentProfileId,
285
- provider: 'stripe',
286
- providerPlanId,
287
- planKey,
288
- checkoutType: 'subscription',
289
- uiMode: 'custom',
290
- couponId: input.couponId,
291
- analyticsMetadata: input.analyticsMetadata,
292
- customerEmail: input.customerEmail,
293
- returnUrl: input.returnUrl,
294
- userId: input.userId,
295
- anonymousUserId: input.anonymousUserId,
296
- idempotencyKey: input.idempotencyKey,
297
- environment: input.environment,
298
- },
269
+ body: toV2CheckoutSessionRequest(input, 'subscription'),
299
270
  errorMessage: 'Unable to create subscription checkout',
300
271
  });
301
272
  }
@@ -329,6 +300,13 @@ class FunnelSdkService {
329
300
  });
330
301
  }
331
302
  async createOneTimeCheckout(input) {
303
+ if (resolveRuntimeConfig(input.runtimeConfig).paymentsApiVersion === 'v2') {
304
+ return this.postJson('/sdk/public/v2/payments/checkout-sessions', {
305
+ runtimeConfig: input.runtimeConfig,
306
+ body: toV2CheckoutSessionRequest(input, 'one_time'),
307
+ errorMessage: 'Unable to create one-time checkout',
308
+ });
309
+ }
332
310
  return this.postJson('/sdk/public/payments/one-time-checkout', {
333
311
  runtimeConfig: input.runtimeConfig,
334
312
  body: {
@@ -352,32 +330,9 @@ class FunnelSdkService {
352
330
  async updateSubscriptionCheckoutPlan(input) {
353
331
  const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
354
332
  if (paymentsApiVersion === 'v2') {
355
- const runtimeConfigRevisionId = asTrimmedStringOrNull(input.runtimeConfigRevisionId);
356
- const offerSetId = asTrimmedStringOrNull(input.offerSetId);
357
- const paymentProfileId = asTrimmedStringOrNull(input.paymentProfileId);
358
- const providerPlanId = asTrimmedStringOrNull(input.providerPlanId);
359
- const planKey = asTrimmedStringOrNull(input.planKey) || asTrimmedStringOrNull(input.planId);
360
- if (!runtimeConfigRevisionId
361
- || !offerSetId
362
- || !paymentProfileId
363
- || !providerPlanId
364
- || !planKey
365
- || input.provider !== 'stripe') {
366
- throw new Error('Published Stripe checkout selection is incomplete');
367
- }
368
333
  return this.patchJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(input.checkoutSessionId)}`, {
369
334
  runtimeConfig: input.runtimeConfig,
370
- body: {
371
- runtimeConfigRevisionId,
372
- offerSetId,
373
- paymentProfileId,
374
- provider: 'stripe',
375
- providerPlanId,
376
- planKey,
377
- couponId: input.couponId,
378
- analyticsMetadata: input.analyticsMetadata,
379
- environment: input.environment,
380
- },
335
+ body: Object.assign(Object.assign({}, toV2CheckoutSelection(input)), { couponId: input.couponId, analyticsMetadata: input.analyticsMetadata, environment: input.environment }),
381
336
  errorMessage: 'Unable to update subscription checkout',
382
337
  });
383
338
  }
@@ -441,6 +396,18 @@ class FunnelSdkService {
441
396
  });
442
397
  }
443
398
  async chargeOneClickPayment(input) {
399
+ var _a, _b, _c;
400
+ if (resolveRuntimeConfig(input.runtimeConfig).paymentsApiVersion === 'v2') {
401
+ const selection = toV2CheckoutSelection(input);
402
+ 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())) {
403
+ throw new Error('V2 one-click requires checkoutSessionId, userId and idempotencyKey');
404
+ }
405
+ return this.postJson('/sdk/public/v2/payments/one-click', {
406
+ runtimeConfig: input.runtimeConfig,
407
+ body: Object.assign(Object.assign({}, selection), { checkoutSessionId: input.checkoutSessionId, userId: input.userId, idempotencyKey: input.idempotencyKey, analyticsMetadata: input.analyticsMetadata, environment: input.environment }),
408
+ errorMessage: 'Unable to charge one-click payment',
409
+ });
410
+ }
444
411
  return this.postJson('/sdk/public/payments/one-click', {
445
412
  runtimeConfig: input.runtimeConfig,
446
413
  body: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",