@funnelsgrove/runtime 0.8.0 → 0.10.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;
@@ -168,6 +175,7 @@ export type FunnelSdkCreateOneTimeCheckoutResponse = {
168
175
  export type FunnelSdkUpdateSubscriptionCheckoutPlanInput = {
169
176
  checkoutSessionId: string;
170
177
  planId: string;
178
+ planKey?: string | null;
171
179
  offerSetId?: string | null;
172
180
  offerSetKey?: string | null;
173
181
  amountCents: number;
@@ -184,6 +192,9 @@ export type FunnelSdkUpdateSubscriptionCheckoutPlanInput = {
184
192
  description?: string | null;
185
193
  environment?: FunnelSdkRuntimeMode;
186
194
  providerPlanId?: string | null;
195
+ provider?: 'stripe' | null;
196
+ paymentProfileId?: string | null;
197
+ runtimeConfigRevisionId?: string | null;
187
198
  runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
188
199
  title?: string | null;
189
200
  userId?: string | null;
@@ -267,7 +278,9 @@ export type FunnelSdkListSubscriptionsInput = {
267
278
  };
268
279
  declare class FunnelSdkService {
269
280
  private getJson;
281
+ private writeJson;
270
282
  private postJson;
283
+ private patchJson;
271
284
  bootstrapUser<ResponsePayload = FunnelSdkJsonObject>(input?: FunnelSdkBootstrapUserInput): Promise<ResponsePayload>;
272
285
  captureEmail(input: FunnelSdkCaptureEmailInput): Promise<FunnelSdkCaptureEmailResponse>;
273
286
  getCurrentUser<ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkGetCurrentUserInput): Promise<ResponsePayload>;
@@ -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) => {
@@ -83,10 +84,10 @@ class FunnelSdkService {
83
84
  }
84
85
  return (await response.json());
85
86
  }
86
- async postJson(path, input) {
87
+ async writeJson(method, path, input) {
87
88
  var _a;
88
89
  const response = await fetch(buildApiUrl(path, input.runtimeConfig), {
89
- method: 'POST',
90
+ method,
90
91
  headers: buildHeaders(input.runtimeConfig, {
91
92
  'Content-Type': 'application/json',
92
93
  }),
@@ -101,6 +102,12 @@ class FunnelSdkService {
101
102
  }
102
103
  return (await response.json());
103
104
  }
105
+ postJson(path, input) {
106
+ return this.writeJson('POST', path, input);
107
+ }
108
+ async patchJson(path, input) {
109
+ return this.writeJson('PATCH', path, input);
110
+ }
104
111
  async bootstrapUser(input = {}) {
105
112
  return this.postJson('/sdk/public/users/bootstrap', {
106
113
  runtimeConfig: input.runtimeConfig,
@@ -254,6 +261,44 @@ class FunnelSdkService {
254
261
  });
255
262
  }
256
263
  async createSubscriptionCheckout(input) {
264
+ const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
265
+ 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
+ return this.postJson('/sdk/public/v2/payments/checkout-sessions', {
280
+ 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
+ },
299
+ errorMessage: 'Unable to create subscription checkout',
300
+ });
301
+ }
257
302
  return this.postJson('/sdk/public/payments/subscriptions', {
258
303
  runtimeConfig: input.runtimeConfig,
259
304
  body: {
@@ -276,6 +321,8 @@ class FunnelSdkService {
276
321
  customerEmail: input.customerEmail,
277
322
  returnUrl: input.returnUrl,
278
323
  user_id: input.userId,
324
+ anonymousUserId: input.anonymousUserId,
325
+ idempotencyKey: input.idempotencyKey,
279
326
  environment: input.environment,
280
327
  },
281
328
  errorMessage: 'Unable to create subscription checkout',
@@ -303,6 +350,37 @@ class FunnelSdkService {
303
350
  });
304
351
  }
305
352
  async updateSubscriptionCheckoutPlan(input) {
353
+ const { paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
354
+ 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
+ return this.patchJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(input.checkoutSessionId)}`, {
369
+ 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
+ },
381
+ errorMessage: 'Unable to update subscription checkout',
382
+ });
383
+ }
306
384
  return this.postJson('/sdk/public/payments/subscriptions/update-plan', {
307
385
  runtimeConfig: input.runtimeConfig,
308
386
  body: {
@@ -326,6 +404,14 @@ class FunnelSdkService {
326
404
  });
327
405
  }
328
406
  async verifySubscriptionCheckout(input) {
407
+ const { funnelId, paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
408
+ if (paymentsApiVersion === 'v2') {
409
+ return this.getJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(input.checkoutSessionId)}`, {
410
+ runtimeConfig: input.runtimeConfig,
411
+ searchParams: { funnelId },
412
+ errorMessage: 'Unable to verify subscription checkout',
413
+ });
414
+ }
329
415
  return this.postJson('/sdk/public/payments/subscriptions/checkout-session-status', {
330
416
  runtimeConfig: input.runtimeConfig,
331
417
  body: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",