@funnelsgrove/runtime 0.9.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.
@@ -175,6 +175,7 @@ export type FunnelSdkCreateOneTimeCheckoutResponse = {
175
175
  export type FunnelSdkUpdateSubscriptionCheckoutPlanInput = {
176
176
  checkoutSessionId: string;
177
177
  planId: string;
178
+ planKey?: string | null;
178
179
  offerSetId?: string | null;
179
180
  offerSetKey?: string | null;
180
181
  amountCents: number;
@@ -191,6 +192,9 @@ export type FunnelSdkUpdateSubscriptionCheckoutPlanInput = {
191
192
  description?: string | null;
192
193
  environment?: FunnelSdkRuntimeMode;
193
194
  providerPlanId?: string | null;
195
+ provider?: 'stripe' | null;
196
+ paymentProfileId?: string | null;
197
+ runtimeConfigRevisionId?: string | null;
194
198
  runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
195
199
  title?: string | null;
196
200
  userId?: string | null;
@@ -274,7 +278,9 @@ export type FunnelSdkListSubscriptionsInput = {
274
278
  };
275
279
  declare class FunnelSdkService {
276
280
  private getJson;
281
+ private writeJson;
277
282
  private postJson;
283
+ private patchJson;
278
284
  bootstrapUser<ResponsePayload = FunnelSdkJsonObject>(input?: FunnelSdkBootstrapUserInput): Promise<ResponsePayload>;
279
285
  captureEmail(input: FunnelSdkCaptureEmailInput): Promise<FunnelSdkCaptureEmailResponse>;
280
286
  getCurrentUser<ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkGetCurrentUserInput): Promise<ResponsePayload>;
@@ -84,10 +84,10 @@ class FunnelSdkService {
84
84
  }
85
85
  return (await response.json());
86
86
  }
87
- async postJson(path, input) {
87
+ async writeJson(method, path, input) {
88
88
  var _a;
89
89
  const response = await fetch(buildApiUrl(path, input.runtimeConfig), {
90
- method: 'POST',
90
+ method,
91
91
  headers: buildHeaders(input.runtimeConfig, {
92
92
  'Content-Type': 'application/json',
93
93
  }),
@@ -102,6 +102,12 @@ class FunnelSdkService {
102
102
  }
103
103
  return (await response.json());
104
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
+ }
105
111
  async bootstrapUser(input = {}) {
106
112
  return this.postJson('/sdk/public/users/bootstrap', {
107
113
  runtimeConfig: input.runtimeConfig,
@@ -344,6 +350,37 @@ class FunnelSdkService {
344
350
  });
345
351
  }
346
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
+ }
347
384
  return this.postJson('/sdk/public/payments/subscriptions/update-plan', {
348
385
  runtimeConfig: input.runtimeConfig,
349
386
  body: {
@@ -367,6 +404,14 @@ class FunnelSdkService {
367
404
  });
368
405
  }
369
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
+ }
370
415
  return this.postJson('/sdk/public/payments/subscriptions/checkout-session-status', {
371
416
  runtimeConfig: input.runtimeConfig,
372
417
  body: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.9.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",