shoal-web-sdk 1.0.95 → 1.0.96

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, DeletePaymentMethodData, DeletePaymentMethodError, DeletePaymentMethodResponse, GetCustomerData, GetInvoicesData, GetPlansData, M2mCreateCustomerData, M2mCreateCustomerError, M2mGetCustomerData, M2mUpdatePlanData, M2mUpdatePlanError, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodError, UpdateDefaultPaymentMethodResponse, UpdatePlanData, UpdatePlanError } from '../types.gen';
3
+ import type { CreateSetupIntentData, CreateSetupIntentError, CreateSetupIntentResponse, CreateSubscriptionData, CreateSubscriptionError, DeletePaymentMethodData, DeletePaymentMethodError, DeletePaymentMethodResponse, GetCustomerData, GetInvoicesData, GetPlansData, 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;
@@ -68,6 +68,13 @@ export declare const getPlansOptions: (options?: Options<GetPlansData>) => impor
68
68
  * Returns a list of available pricing plans.
69
69
  */
70
70
  export declare const updatePlanMutation: (options?: Partial<Options<UpdatePlanData>>) => UseMutationOptions<unknown, UpdatePlanError, Options<UpdatePlanData>>;
71
+ /**
72
+ * Starts a new subscription for a customer who no longer has one.
73
+ *
74
+ * Resubscribes an account whose subscription was cancelled — for example when a trial ended without a payment method. Reuses the existing Stripe customer, requires a saved payment method, and never grants a trial period.
75
+ *
76
+ */
77
+ export declare const createSubscriptionMutation: (options?: Partial<Options<CreateSubscriptionData>>) => UseMutationOptions<unknown, CreateSubscriptionError, Options<CreateSubscriptionData>>;
71
78
  /**
72
79
  * Creates a Stripe SetupIntent.
73
80
  *
@@ -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, deletePaymentMethod, getCustomer, getInvoices, getPlans, m2mCreateCustomer, m2mGetCustomer, m2mUpdatePlan, updateDefaultPaymentMethod, updatePlan } from '../sdk.gen';
4
+ import { createSetupIntent, createSubscription, deletePaymentMethod, getCustomer, getInvoices, getPlans, 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) {
@@ -78,6 +78,25 @@ export const updatePlanMutation = (options) => {
78
78
  };
79
79
  return mutationOptions;
80
80
  };
81
+ /**
82
+ * Starts a new subscription for a customer who no longer has one.
83
+ *
84
+ * Resubscribes an account whose subscription was cancelled — for example when a trial ended without a payment method. Reuses the existing Stripe customer, requires a saved payment method, and never grants a trial period.
85
+ *
86
+ */
87
+ export const createSubscriptionMutation = (options) => {
88
+ const mutationOptions = {
89
+ mutationFn: async (fnOptions) => {
90
+ const { data } = await createSubscription({
91
+ ...options,
92
+ ...fnOptions,
93
+ throwOnError: true
94
+ });
95
+ return data;
96
+ }
97
+ };
98
+ return mutationOptions;
99
+ };
81
100
  /**
82
101
  * Creates a Stripe SetupIntent.
83
102
  *
@@ -1,5 +1,5 @@
1
1
  import type { Client, Options as Options2, TDataShape } from './client';
2
- import type { CreateSetupIntentData, CreateSetupIntentErrors, CreateSetupIntentResponses, DeletePaymentMethodData, DeletePaymentMethodErrors, DeletePaymentMethodResponses, GetCustomerData, GetCustomerErrors, GetCustomerResponses, GetInvoicesData, GetInvoicesErrors, GetInvoicesResponses, GetPlansData, GetPlansErrors, GetPlansResponses, M2mCreateCustomerData, M2mCreateCustomerErrors, M2mCreateCustomerResponses, M2mGetCustomerData, M2mGetCustomerErrors, M2mGetCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanErrors, M2mUpdatePlanResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodErrors, UpdateDefaultPaymentMethodResponses, UpdatePlanData, UpdatePlanErrors, UpdatePlanResponses } from './types.gen';
2
+ import type { CreateSetupIntentData, CreateSetupIntentErrors, CreateSetupIntentResponses, CreateSubscriptionData, CreateSubscriptionErrors, CreateSubscriptionResponses, DeletePaymentMethodData, DeletePaymentMethodErrors, DeletePaymentMethodResponses, GetCustomerData, GetCustomerErrors, GetCustomerResponses, GetInvoicesData, GetInvoicesErrors, GetInvoicesResponses, GetPlansData, GetPlansErrors, GetPlansResponses, 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
@@ -25,6 +25,13 @@ export declare const getPlans: <ThrowOnError extends boolean = false>(options?:
25
25
  * Returns a list of available pricing plans.
26
26
  */
27
27
  export declare const updatePlan: <ThrowOnError extends boolean = false>(options: Options<UpdatePlanData, ThrowOnError>) => import("./client").RequestResult<UpdatePlanResponses, UpdatePlanErrors, ThrowOnError, "fields">;
28
+ /**
29
+ * Starts a new subscription for a customer who no longer has one.
30
+ *
31
+ * Resubscribes an account whose subscription was cancelled — for example when a trial ended without a payment method. Reuses the existing Stripe customer, requires a saved payment method, and never grants a trial period.
32
+ *
33
+ */
34
+ export declare const createSubscription: <ThrowOnError extends boolean = false>(options: Options<CreateSubscriptionData, ThrowOnError>) => import("./client").RequestResult<CreateSubscriptionResponses, CreateSubscriptionErrors, ThrowOnError, "fields">;
28
35
  /**
29
36
  * Creates a Stripe SetupIntent.
30
37
  *
@@ -49,6 +49,28 @@ export const updatePlan = (options) => {
49
49
  }
50
50
  });
51
51
  };
52
+ /**
53
+ * Starts a new subscription for a customer who no longer has one.
54
+ *
55
+ * Resubscribes an account whose subscription was cancelled — for example when a trial ended without a payment method. Reuses the existing Stripe customer, requires a saved payment method, and never grants a trial period.
56
+ *
57
+ */
58
+ export const createSubscription = (options) => {
59
+ return (options.client ?? client).post({
60
+ security: [
61
+ {
62
+ scheme: 'bearer',
63
+ type: 'http'
64
+ }
65
+ ],
66
+ url: '/api/v1/subscription/{org}',
67
+ ...options,
68
+ headers: {
69
+ 'Content-Type': 'application/json',
70
+ ...options.headers
71
+ }
72
+ });
73
+ };
52
74
  /**
53
75
  * Creates a Stripe SetupIntent.
54
76
  *
@@ -91,6 +91,10 @@ export type CreateCustomerRequest = {
91
91
  plan: string;
92
92
  billingInterval: BillingInterval;
93
93
  };
94
+ export type CreateSubscriptionRequest = {
95
+ plan: string;
96
+ billingInterval: BillingInterval;
97
+ };
94
98
  export type SetupIntentResponse = {
95
99
  readonly clientSecret: string;
96
100
  };
@@ -139,7 +143,7 @@ export type CustomerStatus = 'incomplete' | 'incomplete_expired' | 'trialing' |
139
143
  export type CustomerResponse = {
140
144
  id: string;
141
145
  status: CustomerStatus;
142
- currentPlan: CustomerPlanResponse;
146
+ currentPlan?: CustomerPlanResponse;
143
147
  pendingPlan?: CustomerPlanResponse;
144
148
  readonly currentPeriodEnd: number;
145
149
  readonly scheduledChangeAt?: number;
@@ -200,7 +204,7 @@ export type CustomerPlanResponseWritable = {
200
204
  export type CustomerResponseWritable = {
201
205
  id: string;
202
206
  status: CustomerStatus;
203
- currentPlan: CustomerPlanResponseWritable;
207
+ currentPlan?: CustomerPlanResponseWritable;
204
208
  };
205
209
  /**
206
210
  * Stripe payment method.
@@ -299,6 +303,50 @@ export type UpdatePlanResponses = {
299
303
  */
300
304
  202: unknown;
301
305
  };
306
+ export type CreateSubscriptionData = {
307
+ body: CreateSubscriptionRequest;
308
+ path: {
309
+ /**
310
+ * Kinde organisation id.
311
+ */
312
+ org: string;
313
+ };
314
+ query?: never;
315
+ url: '/api/v1/subscription/{org}';
316
+ };
317
+ export type CreateSubscriptionErrors = {
318
+ /**
319
+ * Invalid request body
320
+ */
321
+ 400: _Error;
322
+ /**
323
+ * Unauthorised user
324
+ */
325
+ 401: _Error;
326
+ /**
327
+ * Account not found
328
+ */
329
+ 404: _Error;
330
+ /**
331
+ * The account already has an in-force subscription
332
+ */
333
+ 409: _Error;
334
+ /**
335
+ * The subscription cannot be created
336
+ */
337
+ 422: _Error;
338
+ /**
339
+ * Internal error
340
+ */
341
+ 500: _Error;
342
+ };
343
+ export type CreateSubscriptionError = CreateSubscriptionErrors[keyof CreateSubscriptionErrors];
344
+ export type CreateSubscriptionResponses = {
345
+ /**
346
+ * The subscription was created
347
+ */
348
+ 201: unknown;
349
+ };
302
350
  export type CreateSetupIntentData = {
303
351
  body?: never;
304
352
  path: {
@@ -422,6 +422,13 @@ export declare const zCreateCustomerRequest: z.ZodObject<{
422
422
  annual: "annual";
423
423
  }>;
424
424
  }, z.core.$strip>;
425
+ export declare const zCreateSubscriptionRequest: z.ZodObject<{
426
+ plan: z.ZodString;
427
+ billingInterval: z.ZodEnum<{
428
+ monthly: "monthly";
429
+ annual: "annual";
430
+ }>;
431
+ }, z.core.$strip>;
425
432
  export declare const zSetupIntentResponse: z.ZodObject<{
426
433
  clientSecret: z.ZodReadonly<z.ZodString>;
427
434
  }, z.core.$strip>;
@@ -581,7 +588,7 @@ export declare const zCustomerResponse: z.ZodObject<{
581
588
  unpaid: "unpaid";
582
589
  onboarding: "onboarding";
583
590
  }>;
584
- currentPlan: z.ZodObject<{
591
+ currentPlan: z.ZodOptional<z.ZodObject<{
585
592
  key: z.ZodReadonly<z.ZodString>;
586
593
  displayName: z.ZodReadonly<z.ZodString>;
587
594
  displayDescription: z.ZodOptional<z.ZodReadonly<z.ZodString>>;
@@ -673,7 +680,7 @@ export declare const zCustomerResponse: z.ZodObject<{
673
680
  }>;
674
681
  }, z.core.$strip>>>]>>;
675
682
  }, z.core.$strip>>;
676
- }, z.core.$strip>;
683
+ }, z.core.$strip>>;
677
684
  pendingPlan: z.ZodOptional<z.ZodObject<{
678
685
  key: z.ZodReadonly<z.ZodString>;
679
686
  displayName: z.ZodReadonly<z.ZodString>;
@@ -922,12 +929,12 @@ export declare const zCustomerResponseWritable: z.ZodObject<{
922
929
  unpaid: "unpaid";
923
930
  onboarding: "onboarding";
924
931
  }>;
925
- currentPlan: z.ZodObject<{
932
+ currentPlan: z.ZodOptional<z.ZodObject<{
926
933
  interval: z.ZodOptional<z.ZodEnum<{
927
934
  monthly: "monthly";
928
935
  annual: "annual";
929
936
  }>>;
930
- }, z.core.$strip>;
937
+ }, z.core.$strip>>;
931
938
  }, z.core.$strip>;
932
939
  /**
933
940
  * Stripe payment method.
@@ -960,7 +967,7 @@ export declare const zGetCustomerResponse: z.ZodObject<{
960
967
  unpaid: "unpaid";
961
968
  onboarding: "onboarding";
962
969
  }>;
963
- currentPlan: z.ZodObject<{
970
+ currentPlan: z.ZodOptional<z.ZodObject<{
964
971
  key: z.ZodReadonly<z.ZodString>;
965
972
  displayName: z.ZodReadonly<z.ZodString>;
966
973
  displayDescription: z.ZodOptional<z.ZodReadonly<z.ZodString>>;
@@ -1052,7 +1059,7 @@ export declare const zGetCustomerResponse: z.ZodObject<{
1052
1059
  }>;
1053
1060
  }, z.core.$strip>>>]>>;
1054
1061
  }, z.core.$strip>>;
1055
- }, z.core.$strip>;
1062
+ }, z.core.$strip>>;
1056
1063
  pendingPlan: z.ZodOptional<z.ZodObject<{
1057
1064
  key: z.ZodReadonly<z.ZodString>;
1058
1065
  displayName: z.ZodReadonly<z.ZodString>;
@@ -1305,6 +1312,19 @@ export declare const zUpdatePlanData: z.ZodObject<{
1305
1312
  }, z.core.$strip>;
1306
1313
  query: z.ZodOptional<z.ZodNever>;
1307
1314
  }, z.core.$strip>;
1315
+ export declare const zCreateSubscriptionData: z.ZodObject<{
1316
+ body: z.ZodObject<{
1317
+ plan: z.ZodString;
1318
+ billingInterval: z.ZodEnum<{
1319
+ monthly: "monthly";
1320
+ annual: "annual";
1321
+ }>;
1322
+ }, z.core.$strip>;
1323
+ path: z.ZodObject<{
1324
+ org: z.ZodString;
1325
+ }, z.core.$strip>;
1326
+ query: z.ZodOptional<z.ZodNever>;
1327
+ }, z.core.$strip>;
1308
1328
  export declare const zCreateSetupIntentData: z.ZodObject<{
1309
1329
  body: z.ZodOptional<z.ZodNever>;
1310
1330
  path: z.ZodObject<{
@@ -1395,7 +1415,7 @@ export declare const zM2mGetCustomerResponse: z.ZodObject<{
1395
1415
  unpaid: "unpaid";
1396
1416
  onboarding: "onboarding";
1397
1417
  }>;
1398
- currentPlan: z.ZodObject<{
1418
+ currentPlan: z.ZodOptional<z.ZodObject<{
1399
1419
  key: z.ZodReadonly<z.ZodString>;
1400
1420
  displayName: z.ZodReadonly<z.ZodString>;
1401
1421
  displayDescription: z.ZodOptional<z.ZodReadonly<z.ZodString>>;
@@ -1487,7 +1507,7 @@ export declare const zM2mGetCustomerResponse: z.ZodObject<{
1487
1507
  }>;
1488
1508
  }, z.core.$strip>>>]>>;
1489
1509
  }, z.core.$strip>>;
1490
- }, z.core.$strip>;
1510
+ }, z.core.$strip>>;
1491
1511
  pendingPlan: z.ZodOptional<z.ZodObject<{
1492
1512
  key: z.ZodReadonly<z.ZodString>;
1493
1513
  displayName: z.ZodReadonly<z.ZodString>;
@@ -113,6 +113,10 @@ export const zCreateCustomerRequest = z.object({
113
113
  plan: z.string(),
114
114
  billingInterval: zBillingInterval
115
115
  });
116
+ export const zCreateSubscriptionRequest = z.object({
117
+ plan: z.string(),
118
+ billingInterval: zBillingInterval
119
+ });
116
120
  export const zSetupIntentResponse = z.object({
117
121
  clientSecret: z.string().readonly()
118
122
  });
@@ -171,7 +175,7 @@ export const zCustomerStatus = z.enum([
171
175
  export const zCustomerResponse = z.object({
172
176
  id: z.uuid(),
173
177
  status: zCustomerStatus,
174
- currentPlan: zCustomerPlanResponse,
178
+ currentPlan: z.optional(zCustomerPlanResponse),
175
179
  pendingPlan: z.optional(zCustomerPlanResponse),
176
180
  currentPeriodEnd: z.int().readonly(),
177
181
  scheduledChangeAt: z.optional(z.int().readonly()),
@@ -236,7 +240,7 @@ export const zCustomerPlanResponseWritable = z.object({
236
240
  export const zCustomerResponseWritable = z.object({
237
241
  id: z.uuid(),
238
242
  status: zCustomerStatus,
239
- currentPlan: zCustomerPlanResponseWritable
243
+ currentPlan: z.optional(zCustomerPlanResponseWritable)
240
244
  });
241
245
  /**
242
246
  * Stripe payment method.
@@ -273,6 +277,13 @@ export const zUpdatePlanData = z.object({
273
277
  }),
274
278
  query: z.optional(z.never())
275
279
  });
280
+ export const zCreateSubscriptionData = z.object({
281
+ body: zCreateSubscriptionRequest,
282
+ path: z.object({
283
+ org: z.string()
284
+ }),
285
+ query: z.optional(z.never())
286
+ });
276
287
  export const zCreateSetupIntentData = z.object({
277
288
  body: z.optional(z.never()),
278
289
  path: z.object({
@@ -1,6 +1,6 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { GetSuccessResponse } from "../util";
3
- import { GetCustomerData, GetPlansData, UpdatePlanData, UpdatePlanResponses, CreateSetupIntentData, CreateSetupIntentResponses, DeletePaymentMethodData, DeletePaymentMethodResponses, UpdateDefaultPaymentMethodData, UpdateDefaultPaymentMethodResponses, GetInvoicesData, M2mGetCustomerData, M2mCreateCustomerData, M2mCreateCustomerResponses, M2mUpdatePlanData, M2mUpdatePlanResponses } from "../../sdk/billing/types.gen";
3
+ import { GetCustomerData, GetPlansData, UpdatePlanData, UpdatePlanResponses, 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
  }) => {
@@ -423,6 +423,14 @@ export declare const useUpdatePlan: (config?: {
423
423
  data: unknown;
424
424
  headers: Record<string, string>;
425
425
  }, unknown, Omit<UpdatePlanData, "url">, unknown>;
426
+ export declare const useCreateSubscription: (config?: {
427
+ onSuccess?: (data: GetSuccessResponse<CreateSubscriptionResponses>, headers: Record<string, string>) => void;
428
+ onError?: Parameters<typeof useMutation>["0"]["onError"];
429
+ retry?: boolean;
430
+ }) => import("@tanstack/react-query").UseMutationResult<{
431
+ data: unknown;
432
+ headers: Record<string, string>;
433
+ }, unknown, Omit<CreateSubscriptionData, "url">, unknown>;
426
434
  export declare const useCreateSetupIntent: (config?: {
427
435
  onSuccess?: (data: GetSuccessResponse<CreateSetupIntentResponses>, headers: Record<string, string>) => void;
428
436
  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, getPlans, updatePlan, createSetupIntent, deletePaymentMethod, updateDefaultPaymentMethod, getInvoices, m2mGetCustomer, m2mCreateCustomer, m2mUpdatePlan } from "../../sdk/billing/sdk.gen";
5
+ import { getCustomer, getPlans, updatePlan, 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 };
@@ -66,6 +66,25 @@ export const useUpdatePlan = (config) => {
66
66
  retry: config?.retry
67
67
  });
68
68
  };
69
+ export const useCreateSubscription = (config) => {
70
+ const token = useToken();
71
+ const queryClient = useQueryClient();
72
+ const opts = { throwOnError: true, url: "/api/v1/subscription/{org}" };
73
+ const funcer = async (options) => {
74
+ const auth = isPromise(token) ? (await token) || "" : token || "";
75
+ const res = await createSubscription({ ...opts, ...options, auth });
76
+ return { data: res.data, headers: headersToObject(res.response.headers) };
77
+ };
78
+ return useMutation({
79
+ mutationFn: funcer,
80
+ onSuccess: (res, options, c, ctx) => {
81
+ queryClient.invalidateQueries({ queryKey: ["api", "v1", "subscription", options?.path?.org] });
82
+ config?.onSuccess && config.onSuccess(res.data, res.headers);
83
+ },
84
+ onError: config?.onError,
85
+ retry: config?.retry
86
+ });
87
+ };
69
88
  export const useCreateSetupIntent = (config) => {
70
89
  const token = useToken();
71
90
  const queryClient = useQueryClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoal-web-sdk",
3
- "version": "1.0.95",
3
+ "version": "1.0.96",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build-hooks": "npx tsx tanstack-codegen/generator.ts",