@funnelsgrove/runtime 0.7.31 → 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,16 +4,9 @@ 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
- export type FunnelSdkPaymentPlan = Record<string, unknown>;
9
9
  export type FunnelSdkJsonObject = Record<string, unknown>;
10
- export type FunnelSdkListPaymentPlansResponse = {
11
- funnelId?: string;
12
- environment?: FunnelSdkRuntimeMode;
13
- offerSetId?: string;
14
- offerSetKey?: string;
15
- plans: FunnelSdkPaymentPlan[];
16
- };
17
10
  export type FunnelSdkBootstrapUserInput = {
18
11
  userId?: string | null;
19
12
  idempotencyKey?: string | null;
@@ -123,6 +116,7 @@ export type FunnelSdkCreateHostedCheckoutSessionResponse = {
123
116
  };
124
117
  export type FunnelSdkCreateSubscriptionCheckoutInput = {
125
118
  planId: string;
119
+ planKey?: string | null;
126
120
  offerSetId?: string | null;
127
121
  offerSetKey?: string | null;
128
122
  amountCents: number;
@@ -140,6 +134,11 @@ export type FunnelSdkCreateSubscriptionCheckoutInput = {
140
134
  description?: string | null;
141
135
  environment?: FunnelSdkRuntimeMode;
142
136
  providerPlanId?: string | null;
137
+ provider?: 'stripe' | null;
138
+ paymentProfileId?: string | null;
139
+ runtimeConfigRevisionId?: string | null;
140
+ anonymousUserId?: string | null;
141
+ idempotencyKey?: string | null;
143
142
  runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
144
143
  title?: string | null;
145
144
  userId?: string | null;
@@ -287,12 +286,6 @@ declare class FunnelSdkService {
287
286
  sizeBytes: number;
288
287
  }): Promise<FunnelSdkPreparedPhotoUpload>;
289
288
  uploadPhotoFile(input: FunnelSdkUploadPhotoFileInput): Promise<FunnelSdkUploadedPhoto>;
290
- listPaymentPlans(input?: {
291
- environment?: FunnelSdkRuntimeMode;
292
- offerSetId?: string | null;
293
- offerSetKey?: string | null;
294
- runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
295
- }): Promise<FunnelSdkListPaymentPlansResponse>;
296
289
  createHostedCheckoutSession(input: FunnelSdkCreateHostedCheckoutSessionInput): Promise<FunnelSdkCreateHostedCheckoutSessionResponse>;
297
290
  createSubscriptionCheckout(input: FunnelSdkCreateSubscriptionCheckoutInput): Promise<FunnelSdkCreateSubscriptionCheckoutResponse>;
298
291
  createOneTimeCheckout(input: FunnelSdkCreateOneTimeCheckoutInput): Promise<FunnelSdkCreateOneTimeCheckoutResponse>;
@@ -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) => {
@@ -229,19 +230,6 @@ class FunnelSdkService {
229
230
  uploadedAt: new Date().toISOString(),
230
231
  };
231
232
  }
232
- async listPaymentPlans(input = {}) {
233
- const { funnelId } = resolveRuntimeConfig(input.runtimeConfig);
234
- return this.getJson('/sdk/public/payments/plans', {
235
- runtimeConfig: input.runtimeConfig,
236
- searchParams: {
237
- environment: input.environment,
238
- funnelId,
239
- offerSetId: input.offerSetId,
240
- offerSetKey: input.offerSetKey,
241
- },
242
- errorMessage: 'Unable to load payment plans',
243
- });
244
- }
245
233
  async createHostedCheckoutSession(input) {
246
234
  return this.postJson('/sdk/public/payments/checkout-session', {
247
235
  runtimeConfig: input.runtimeConfig,
@@ -267,6 +255,44 @@ class FunnelSdkService {
267
255
  });
268
256
  }
269
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
+ }
270
296
  return this.postJson('/sdk/public/payments/subscriptions', {
271
297
  runtimeConfig: input.runtimeConfig,
272
298
  body: {
@@ -289,6 +315,8 @@ class FunnelSdkService {
289
315
  customerEmail: input.customerEmail,
290
316
  returnUrl: input.returnUrl,
291
317
  user_id: input.userId,
318
+ anonymousUserId: input.anonymousUserId,
319
+ idempotencyKey: input.idempotencyKey,
292
320
  environment: input.environment,
293
321
  },
294
322
  errorMessage: 'Unable to create subscription checkout',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.7.31",
3
+ "version": "0.9.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",