shoal-web-sdk 1.0.113 → 1.0.114

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.
@@ -1,6 +1,6 @@
1
1
  import { type UseMutationOptions } from '@tanstack/react-query';
2
2
  import { type Options } from '../sdk.gen';
3
- import type { CreateSetupIntentData, CreateSetupIntentError, CreateSetupIntentResponse, CreateSubscriptionData, CreateSubscriptionError, DeletePaymentMethodData, DeletePaymentMethodError, DeletePaymentMethodResponse, GetCustomerData, GetInvoicesData, GetPlansData, GetUsageData, M2mCreateCustomerData, M2mCreateCustomerError, M2mGetCustomerData, M2mUpdatePlanData, M2mUpdatePlanError, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodError, UpdateDefaultPaymentMethodResponse, UpdatePlanData, UpdatePlanError } from '../types.gen';
3
+ import type { CancelSubscriptionData, CancelSubscriptionError, CreateSetupIntentData, CreateSetupIntentError, CreateSetupIntentResponse, CreateSubscriptionData, CreateSubscriptionError, DeletePaymentMethodData, DeletePaymentMethodError, DeletePaymentMethodResponse, GetCustomerData, GetInvoicesData, GetPlansData, GetUsageData, M2mCreateCustomerData, M2mCreateCustomerError, M2mGetCustomerData, M2mUpdatePlanData, M2mUpdatePlanError, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodError, UpdateDefaultPaymentMethodResponse, UpdatePlanData, UpdatePlanError } from '../types.gen';
4
4
  export type QueryKey<TOptions extends Options> = [
5
5
  Pick<TOptions, 'baseUrl' | 'body' | 'headers' | 'path' | 'query'> & {
6
6
  _id: string;
@@ -96,6 +96,13 @@ export declare const getPlansOptions: (options?: Options<GetPlansData>) => impor
96
96
  * Returns a list of available pricing plans.
97
97
  */
98
98
  export declare const updatePlanMutation: (options?: Partial<Options<UpdatePlanData>>) => UseMutationOptions<unknown, UpdatePlanError, Options<UpdatePlanData>>;
99
+ /**
100
+ * Cancels the account's subscription at the end of the current billing period.
101
+ *
102
+ * The subscription is resolved from the organisation's Stripe customer, so no subscription id is required. The customer keeps access until the current period ends, at which point the account is downgraded to the solo plan.
103
+ *
104
+ */
105
+ export declare const cancelSubscriptionMutation: (options?: Partial<Options<CancelSubscriptionData>>) => UseMutationOptions<unknown, CancelSubscriptionError, Options<CancelSubscriptionData>>;
99
106
  /**
100
107
  * Starts a new subscription for a customer who no longer has one.
101
108
  *
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated by @hey-api/openapi-ts
2
2
  import { queryOptions } from '@tanstack/react-query';
3
3
  import { client } from '../client.gen';
4
- import { createSetupIntent, createSubscription, deletePaymentMethod, getCustomer, getInvoices, getPlans, getUsage, m2mCreateCustomer, m2mGetCustomer, m2mUpdatePlan, updateDefaultPaymentMethod, updatePlan } from '../sdk.gen';
4
+ import { cancelSubscription, createSetupIntent, createSubscription, deletePaymentMethod, getCustomer, getInvoices, getPlans, getUsage, m2mCreateCustomer, m2mGetCustomer, m2mUpdatePlan, updateDefaultPaymentMethod, updatePlan } from '../sdk.gen';
5
5
  const createQueryKey = (id, options, infinite, tags) => {
6
6
  const params = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl };
7
7
  if (infinite) {
@@ -96,6 +96,25 @@ export const updatePlanMutation = (options) => {
96
96
  };
97
97
  return mutationOptions;
98
98
  };
99
+ /**
100
+ * Cancels the account's subscription at the end of the current billing period.
101
+ *
102
+ * The subscription is resolved from the organisation's Stripe customer, so no subscription id is required. The customer keeps access until the current period ends, at which point the account is downgraded to the solo plan.
103
+ *
104
+ */
105
+ export const cancelSubscriptionMutation = (options) => {
106
+ const mutationOptions = {
107
+ mutationFn: async (fnOptions) => {
108
+ const { data } = await cancelSubscription({
109
+ ...options,
110
+ ...fnOptions,
111
+ throwOnError: true
112
+ });
113
+ return data;
114
+ }
115
+ };
116
+ return mutationOptions;
117
+ };
99
118
  /**
100
119
  * Starts a new subscription for a customer who no longer has one.
101
120
  *
@@ -1,5 +1,5 @@
1
1
  import type { Client, Options as Options2, TDataShape } from './client';
2
- import type { CreateSetupIntentData, CreateSetupIntentErrors, CreateSetupIntentResponses, CreateSubscriptionData, CreateSubscriptionErrors, CreateSubscriptionResponses, DeletePaymentMethodData, DeletePaymentMethodErrors, DeletePaymentMethodResponses, GetCustomerData, GetCustomerErrors, GetCustomerResponses, GetInvoicesData, GetInvoicesErrors, GetInvoicesResponses, GetPlansData, GetPlansErrors, GetPlansResponses, GetUsageData, GetUsageErrors, GetUsageResponses, M2mCreateCustomerData, M2mCreateCustomerErrors, M2mCreateCustomerResponses, M2mGetCustomerData, M2mGetCustomerErrors, M2mGetCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanErrors, M2mUpdatePlanResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodErrors, UpdateDefaultPaymentMethodResponses, UpdatePlanData, UpdatePlanErrors, UpdatePlanResponses } from './types.gen';
2
+ import type { CancelSubscriptionData, CancelSubscriptionErrors, CancelSubscriptionResponses, CreateSetupIntentData, CreateSetupIntentErrors, CreateSetupIntentResponses, CreateSubscriptionData, CreateSubscriptionErrors, CreateSubscriptionResponses, DeletePaymentMethodData, DeletePaymentMethodErrors, DeletePaymentMethodResponses, GetCustomerData, GetCustomerErrors, GetCustomerResponses, GetInvoicesData, GetInvoicesErrors, GetInvoicesResponses, GetPlansData, GetPlansErrors, GetPlansResponses, GetUsageData, GetUsageErrors, GetUsageResponses, M2mCreateCustomerData, M2mCreateCustomerErrors, M2mCreateCustomerResponses, M2mGetCustomerData, M2mGetCustomerErrors, M2mGetCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanErrors, M2mUpdatePlanResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodErrors, UpdateDefaultPaymentMethodResponses, UpdatePlanData, UpdatePlanErrors, UpdatePlanResponses } from './types.gen';
3
3
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
4
4
  /**
5
5
  * You can provide a client instance returned by `createClient()` instead of
@@ -29,6 +29,13 @@ export declare const getPlans: <ThrowOnError extends boolean = false>(options?:
29
29
  * Returns a list of available pricing plans.
30
30
  */
31
31
  export declare const updatePlan: <ThrowOnError extends boolean = false>(options: Options<UpdatePlanData, ThrowOnError>) => import("./client").RequestResult<UpdatePlanResponses, UpdatePlanErrors, ThrowOnError, "fields">;
32
+ /**
33
+ * Cancels the account's subscription at the end of the current billing period.
34
+ *
35
+ * The subscription is resolved from the organisation's Stripe customer, so no subscription id is required. The customer keeps access until the current period ends, at which point the account is downgraded to the solo plan.
36
+ *
37
+ */
38
+ export declare const cancelSubscription: <ThrowOnError extends boolean = false>(options: Options<CancelSubscriptionData, ThrowOnError>) => import("./client").RequestResult<CancelSubscriptionResponses, CancelSubscriptionErrors, ThrowOnError, "fields">;
32
39
  /**
33
40
  * Starts a new subscription for a customer who no longer has one.
34
41
  *
@@ -64,6 +64,24 @@ export const updatePlan = (options) => {
64
64
  }
65
65
  });
66
66
  };
67
+ /**
68
+ * Cancels the account's subscription at the end of the current billing period.
69
+ *
70
+ * The subscription is resolved from the organisation's Stripe customer, so no subscription id is required. The customer keeps access until the current period ends, at which point the account is downgraded to the solo plan.
71
+ *
72
+ */
73
+ export const cancelSubscription = (options) => {
74
+ return (options.client ?? client).delete({
75
+ security: [
76
+ {
77
+ scheme: 'bearer',
78
+ type: 'http'
79
+ }
80
+ ],
81
+ url: '/api/v1/subscription/{org}',
82
+ ...options
83
+ });
84
+ };
67
85
  /**
68
86
  * Starts a new subscription for a customer who no longer has one.
69
87
  *
@@ -384,6 +384,46 @@ export type UpdatePlanResponses = {
384
384
  */
385
385
  202: unknown;
386
386
  };
387
+ export type CancelSubscriptionData = {
388
+ body?: never;
389
+ path: {
390
+ /**
391
+ * Kinde organisation id.
392
+ */
393
+ org: string;
394
+ };
395
+ query?: never;
396
+ url: '/api/v1/subscription/{org}';
397
+ };
398
+ export type CancelSubscriptionErrors = {
399
+ /**
400
+ * Unauthorised user
401
+ */
402
+ 401: _Error;
403
+ /**
404
+ * Account not found, or the account has no in-force subscription
405
+ */
406
+ 404: _Error;
407
+ /**
408
+ * The subscription is already scheduled to cancel, or the account has no Stripe customer yet
409
+ */
410
+ 409: _Error;
411
+ /**
412
+ * The subscription cannot be cancelled
413
+ */
414
+ 422: _Error;
415
+ /**
416
+ * Internal error
417
+ */
418
+ 500: _Error;
419
+ };
420
+ export type CancelSubscriptionError = CancelSubscriptionErrors[keyof CancelSubscriptionErrors];
421
+ export type CancelSubscriptionResponses = {
422
+ /**
423
+ * The subscription is scheduled to cancel at the end of the period
424
+ */
425
+ 202: unknown;
426
+ };
387
427
  export type CreateSubscriptionData = {
388
428
  body: CreateSubscriptionRequest;
389
429
  path: {
@@ -6522,6 +6522,13 @@ export declare const zUpdatePlanData: z.ZodObject<{
6522
6522
  }, z.core.$strip>;
6523
6523
  query: z.ZodOptional<z.ZodNever>;
6524
6524
  }, z.core.$strip>;
6525
+ export declare const zCancelSubscriptionData: z.ZodObject<{
6526
+ body: z.ZodOptional<z.ZodNever>;
6527
+ path: z.ZodObject<{
6528
+ org: z.ZodString;
6529
+ }, z.core.$strip>;
6530
+ query: z.ZodOptional<z.ZodNever>;
6531
+ }, z.core.$strip>;
6525
6532
  export declare const zCreateSubscriptionData: z.ZodObject<{
6526
6533
  body: z.ZodObject<{
6527
6534
  plan: z.ZodString;
@@ -326,6 +326,13 @@ export const zUpdatePlanData = z.object({
326
326
  }),
327
327
  query: z.optional(z.never())
328
328
  });
329
+ export const zCancelSubscriptionData = z.object({
330
+ body: z.optional(z.never()),
331
+ path: z.object({
332
+ org: z.string()
333
+ }),
334
+ query: z.optional(z.never())
335
+ });
329
336
  export const zCreateSubscriptionData = z.object({
330
337
  body: zCreateSubscriptionRequest,
331
338
  path: z.object({
@@ -1,6 +1,6 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { GetSuccessResponse } from "../util";
3
- import { GetCustomerData, GetUsageData, GetPlansData, UpdatePlanData, UpdatePlanResponses, CreateSubscriptionData, CreateSubscriptionResponses, CreateSetupIntentData, CreateSetupIntentResponses, DeletePaymentMethodData, DeletePaymentMethodResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodResponses, GetInvoicesData, M2mGetCustomerData, M2mCreateCustomerData, M2mCreateCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanResponses } from "../../sdk/billing/types.gen";
3
+ import { GetCustomerData, GetUsageData, GetPlansData, UpdatePlanData, UpdatePlanResponses, CancelSubscriptionData, CancelSubscriptionResponses, CreateSubscriptionData, CreateSubscriptionResponses, CreateSetupIntentData, CreateSetupIntentResponses, DeletePaymentMethodData, DeletePaymentMethodResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodResponses, GetInvoicesData, M2mGetCustomerData, M2mCreateCustomerData, M2mCreateCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanResponses } from "../../sdk/billing/types.gen";
4
4
  export declare const useGetCustomer: (options: Omit<GetCustomerData, "url"> & {
5
5
  enabled?: boolean;
6
6
  }) => {
@@ -630,6 +630,14 @@ export declare const useUpdatePlan: (config?: {
630
630
  data: unknown;
631
631
  headers: Record<string, string>;
632
632
  }, unknown, Omit<UpdatePlanData, "url">, unknown>;
633
+ export declare const useCancelSubscription: (config?: {
634
+ onSuccess?: (data: GetSuccessResponse<CancelSubscriptionResponses>, headers: Record<string, string>) => void;
635
+ onError?: Parameters<typeof useMutation>["0"]["onError"];
636
+ retry?: boolean;
637
+ }) => import("@tanstack/react-query").UseMutationResult<{
638
+ data: unknown;
639
+ headers: Record<string, string>;
640
+ }, unknown, Omit<CancelSubscriptionData, "url">, unknown>;
633
641
  export declare const useCreateSubscription: (config?: {
634
642
  onSuccess?: (data: GetSuccessResponse<CreateSubscriptionResponses>, headers: Record<string, string>) => void;
635
643
  onError?: Parameters<typeof useMutation>["0"]["onError"];
@@ -2,7 +2,7 @@
2
2
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
3
  import { isPromise, headersToObject } from "../util";
4
4
  import { useToken } from "../../provider/token-provider";
5
- import { getCustomer, getUsage, getPlans, updatePlan, createSubscription, createSetupIntent, deletePaymentMethod, updateDefaultPaymentMethod, getInvoices, m2mGetCustomer, m2mCreateCustomer, m2mUpdatePlan } from "../../sdk/billing/sdk.gen";
5
+ import { getCustomer, getUsage, getPlans, updatePlan, cancelSubscription, createSubscription, createSetupIntent, deletePaymentMethod, updateDefaultPaymentMethod, getInvoices, m2mGetCustomer, m2mCreateCustomer, m2mUpdatePlan } from "../../sdk/billing/sdk.gen";
6
6
  export const useGetCustomer = (options) => {
7
7
  const token = useToken();
8
8
  let { enabled, ...rest } = options || { enabled: true };
@@ -88,6 +88,25 @@ export const useUpdatePlan = (config) => {
88
88
  retry: config?.retry
89
89
  });
90
90
  };
91
+ export const useCancelSubscription = (config) => {
92
+ const token = useToken();
93
+ const queryClient = useQueryClient();
94
+ const opts = { throwOnError: true, url: "/api/v1/subscription/{org}" };
95
+ const funcer = async (options) => {
96
+ const auth = isPromise(token) ? (await token) || "" : token || "";
97
+ const res = await cancelSubscription({ ...opts, ...options, auth });
98
+ return { data: res.data, headers: headersToObject(res.response.headers) };
99
+ };
100
+ return useMutation({
101
+ mutationFn: funcer,
102
+ onSuccess: (res, options, c, ctx) => {
103
+ queryClient.invalidateQueries({ queryKey: ["api", "v1", "subscription", options?.path?.org] });
104
+ config?.onSuccess && config.onSuccess(res.data, res.headers);
105
+ },
106
+ onError: config?.onError,
107
+ retry: config?.retry
108
+ });
109
+ };
91
110
  export const useCreateSubscription = (config) => {
92
111
  const token = useToken();
93
112
  const queryClient = useQueryClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoal-web-sdk",
3
- "version": "1.0.113",
3
+ "version": "1.0.114",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build-hooks": "npx tsx tanstack-codegen/generator.ts",