autumn-js 0.0.28 → 0.0.30

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.
Files changed (71) hide show
  1. package/dist/next/client/AutumnContext.d.mts +2 -1
  2. package/dist/next/client/AutumnContext.d.ts +2 -1
  3. package/dist/next/client/AutumnContext.js +3 -1
  4. package/dist/next/client/AutumnContext.mjs +3 -1
  5. package/dist/next/client/AutumnProvider.d.mts +1 -1
  6. package/dist/next/client/AutumnProvider.d.ts +1 -1
  7. package/dist/next/client/AutumnProvider.js +4 -1
  8. package/dist/next/client/AutumnProvider.mjs +4 -1
  9. package/dist/next/client/clientUtils.d.mts +2 -1
  10. package/dist/next/client/clientUtils.d.ts +2 -1
  11. package/dist/next/client/{cusTypes-sGWmB2Vf.d.mts → cusTypes-CBQqMlZy.d.mts} +12 -2
  12. package/dist/next/client/{cusTypes-sGWmB2Vf.d.ts → cusTypes-CBQqMlZy.d.ts} +12 -2
  13. package/dist/next/client/entTypes-DHSCGE1o.d.mts +19 -0
  14. package/dist/next/client/entTypes-X4EHXDE5.d.ts +19 -0
  15. package/dist/next/client/hooks/types.d.mts +6 -1
  16. package/dist/next/client/hooks/types.d.ts +6 -1
  17. package/dist/next/client/hooks/useAutumn.d.mts +5 -1
  18. package/dist/next/client/hooks/useAutumn.d.ts +5 -1
  19. package/dist/next/client/hooks/useAutumn.js +1 -0
  20. package/dist/next/client/hooks/useAutumn.mjs +1 -0
  21. package/dist/next/client/hooks/useCustomer.d.mts +5 -1
  22. package/dist/next/client/hooks/useCustomer.d.ts +5 -1
  23. package/dist/next/client/hooks/useCustomer.js +58 -4
  24. package/dist/next/client/hooks/useCustomer.mjs +58 -4
  25. package/dist/next/client/hooks/useEntity.d.mts +12 -0
  26. package/dist/next/client/hooks/useEntity.d.ts +12 -0
  27. package/dist/next/client/hooks/useEntity.js +60 -0
  28. package/dist/next/client/hooks/useEntity.mjs +60 -0
  29. package/dist/next/client/hooks/usePricingTable.d.mts +2 -1
  30. package/dist/next/client/hooks/usePricingTable.d.ts +2 -1
  31. package/dist/next/client/types.d.mts +5 -1
  32. package/dist/next/client/types.d.ts +5 -1
  33. package/dist/next/index.d.mts +50 -2
  34. package/dist/next/index.d.ts +50 -2
  35. package/dist/next/index.js +2 -0
  36. package/dist/next/index.mjs +1 -0
  37. package/dist/next/server/auth/withAuth.d.mts +1 -1
  38. package/dist/next/server/auth/withAuth.d.ts +1 -1
  39. package/dist/next/server/componentActions.d.mts +1 -1
  40. package/dist/next/server/componentActions.d.ts +1 -1
  41. package/dist/next/server/cusActions.d.mts +43 -5
  42. package/dist/next/server/cusActions.d.ts +43 -5
  43. package/dist/next/server/cusActions.js +46 -5
  44. package/dist/next/server/cusActions.mjs +46 -5
  45. package/dist/next/server/{cusTypes-DtlCmw72.d.mts → cusTypes-Cpw_5kXB.d.mts} +16 -2
  46. package/dist/next/server/{cusTypes-DtlCmw72.d.ts → cusTypes-Cpw_5kXB.d.ts} +16 -2
  47. package/dist/next/server/genActions.d.mts +2 -2
  48. package/dist/next/server/genActions.d.ts +2 -2
  49. package/dist/next/server/{genTypes-B8yg2899.d.ts → genTypes-DSJTeaCr.d.ts} +1 -1
  50. package/dist/next/server/{genTypes-CQ_72jZv.d.mts → genTypes-DsrXED76.d.mts} +1 -1
  51. package/dist/sdk/cusTypes-B6L_-8Kz.d.mts +79 -0
  52. package/dist/sdk/cusTypes-BPazw8Ki.d.mts +87 -0
  53. package/dist/sdk/cusTypes-BkqhmnvO.d.mts +88 -0
  54. package/dist/sdk/cusTypes-BxDQNrCc.d.ts +79 -0
  55. package/dist/sdk/cusTypes-CjqnH7C3.d.ts +88 -0
  56. package/dist/sdk/cusTypes-DOUPrslI.d.ts +79 -0
  57. package/dist/sdk/cusTypes-Dqi6Qcj0.d.mts +79 -0
  58. package/dist/sdk/cusTypes-Xg665KFq.d.ts +87 -0
  59. package/dist/sdk/customers.d.mts +1 -1
  60. package/dist/sdk/customers.d.ts +1 -1
  61. package/dist/sdk/entities.d.mts +19 -1
  62. package/dist/sdk/entities.d.ts +19 -1
  63. package/dist/sdk/general.d.mts +1 -1
  64. package/dist/sdk/general.d.ts +1 -1
  65. package/dist/sdk/index.d.mts +8 -6
  66. package/dist/sdk/index.d.ts +8 -6
  67. package/dist/sdk/index.js +34 -4
  68. package/dist/sdk/index.mjs +34 -4
  69. package/dist/utils/encryptUtils.js +34 -4
  70. package/dist/utils/encryptUtils.mjs +34 -4
  71. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { AutumnContextParams } from './types.mjs';
3
- import './cusTypes-sGWmB2Vf.mjs';
3
+ import './cusTypes-CBQqMlZy.mjs';
4
+ import './entTypes-DHSCGE1o.mjs';
4
5
 
5
6
  declare const AutumnContext: react.Context<AutumnContextParams>;
6
7
  declare const useAutumnContext: () => AutumnContextParams;
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { AutumnContextParams } from './types.js';
3
- import './cusTypes-sGWmB2Vf.js';
3
+ import './cusTypes-CBQqMlZy.js';
4
+ import './entTypes-X4EHXDE5.js';
4
5
 
5
6
  declare const AutumnContext: react.Context<AutumnContextParams>;
6
7
  declare const useAutumnContext: () => AutumnContextParams;
@@ -4,7 +4,9 @@ import { createContext, useContext } from "react";
4
4
  const AutumnContext = createContext({
5
5
  encryptedCustomerId: "",
6
6
  customerData: {},
7
- authProvider: "better-auth",
7
+ entity: null,
8
+ setEntity: () => {
9
+ },
8
10
  customer: null,
9
11
  setCustomer: () => {
10
12
  },
@@ -4,7 +4,9 @@ import { createContext, useContext } from "react";
4
4
  const AutumnContext = createContext({
5
5
  encryptedCustomerId: "",
6
6
  customerData: {},
7
- authProvider: "better-auth",
7
+ entity: null,
8
+ setEntity: () => {
9
+ },
8
10
  customer: null,
9
11
  setCustomer: () => {
10
12
  },
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as CustomerData } from './cusTypes-sGWmB2Vf.mjs';
2
+ import { C as CustomerData } from './cusTypes-CBQqMlZy.mjs';
3
3
 
4
4
  interface AutumnProviderProps {
5
5
  children?: React.ReactNode;
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as CustomerData } from './cusTypes-sGWmB2Vf.js';
2
+ import { C as CustomerData } from './cusTypes-CBQqMlZy.js';
3
3
 
4
4
  interface AutumnProviderProps {
5
5
  children?: React.ReactNode;
@@ -39,6 +39,7 @@ const AutumnClientProvider = ({
39
39
  }) => {
40
40
  let [customer, setCustomer] = useState(null);
41
41
  let [pricingTableProducts, setPricingTableProducts] = useState(null);
42
+ const [entity, setEntity] = useState(null);
42
43
  const [
43
44
  prodChangeDialogFound,
44
45
  prodChangeDialogProps,
@@ -72,7 +73,9 @@ const AutumnClientProvider = ({
72
73
  setOpen: setPaywallOpen
73
74
  },
74
75
  pricingTableProducts,
75
- setPricingTableProducts
76
+ setPricingTableProducts,
77
+ entity,
78
+ setEntity
76
79
  },
77
80
  children: [
78
81
  components?.productChangeDialog && /* @__PURE__ */ jsx(
@@ -39,6 +39,7 @@ const AutumnClientProvider = ({
39
39
  }) => {
40
40
  let [customer, setCustomer] = useState(null);
41
41
  let [pricingTableProducts, setPricingTableProducts] = useState(null);
42
+ const [entity, setEntity] = useState(null);
42
43
  const [
43
44
  prodChangeDialogFound,
44
45
  prodChangeDialogProps,
@@ -72,7 +73,9 @@ const AutumnClientProvider = ({
72
73
  setOpen: setPaywallOpen
73
74
  },
74
75
  pricingTableProducts,
75
- setPricingTableProducts
76
+ setPricingTableProducts,
77
+ entity,
78
+ setEntity
76
79
  },
77
80
  children: [
78
81
  components?.productChangeDialog && /* @__PURE__ */ jsx(
@@ -1,5 +1,6 @@
1
1
  import { AutumnClientError, PricingTableProduct } from './types.mjs';
2
- import './cusTypes-sGWmB2Vf.mjs';
2
+ import './cusTypes-CBQqMlZy.mjs';
3
+ import './entTypes-DHSCGE1o.mjs';
3
4
 
4
5
  declare const toClientErrorResponse: (error: any) => {
5
6
  data: null;
@@ -1,5 +1,6 @@
1
1
  import { AutumnClientError, PricingTableProduct } from './types.js';
2
- import './cusTypes-sGWmB2Vf.js';
2
+ import './cusTypes-CBQqMlZy.js';
3
+ import './entTypes-X4EHXDE5.js';
3
4
 
4
5
  declare const toClientErrorResponse: (error: any) => {
5
6
  data: null;
@@ -21,6 +21,7 @@ declare enum ProductStatus {
21
21
  Trialing = "trialing",
22
22
  Scheduled = "scheduled"
23
23
  }
24
+ type CustomerExpandOption = "invoices";
24
25
 
25
26
  interface CustomerFeature {
26
27
  id: string;
@@ -58,13 +59,22 @@ interface Customer {
58
59
  fingerprint: string | null;
59
60
  stripe_id: string | null;
60
61
  env: AppEnv;
61
- products: Record<string, CustomerProduct>;
62
+ products: CustomerProduct[];
62
63
  features: Record<string, CustomerFeature>;
64
+ invoices?: CustomerInvoice[];
63
65
  }
64
66
  interface CustomerData {
65
67
  name?: string;
66
68
  email?: string;
67
69
  fingerprint?: string;
68
70
  }
71
+ interface CustomerInvoice {
72
+ product_ids: string[];
73
+ stripe_id: string;
74
+ status: string;
75
+ total: number;
76
+ currency: string;
77
+ created_at: number;
78
+ }
69
79
 
70
- export type { CustomerData as C, Customer as a };
80
+ export type { CustomerData as C, Customer as a, CustomerExpandOption as b, CustomerProduct as c, CustomerFeature as d, CustomerInvoice as e };
@@ -21,6 +21,7 @@ declare enum ProductStatus {
21
21
  Trialing = "trialing",
22
22
  Scheduled = "scheduled"
23
23
  }
24
+ type CustomerExpandOption = "invoices";
24
25
 
25
26
  interface CustomerFeature {
26
27
  id: string;
@@ -58,13 +59,22 @@ interface Customer {
58
59
  fingerprint: string | null;
59
60
  stripe_id: string | null;
60
61
  env: AppEnv;
61
- products: Record<string, CustomerProduct>;
62
+ products: CustomerProduct[];
62
63
  features: Record<string, CustomerFeature>;
64
+ invoices?: CustomerInvoice[];
63
65
  }
64
66
  interface CustomerData {
65
67
  name?: string;
66
68
  email?: string;
67
69
  fingerprint?: string;
68
70
  }
71
+ interface CustomerInvoice {
72
+ product_ids: string[];
73
+ stripe_id: string;
74
+ status: string;
75
+ total: number;
76
+ currency: string;
77
+ created_at: number;
78
+ }
69
79
 
70
- export type { CustomerData as C, Customer as a };
80
+ export type { CustomerData as C, Customer as a, CustomerExpandOption as b, CustomerProduct as c, CustomerFeature as d, CustomerInvoice as e };
@@ -0,0 +1,19 @@
1
+ import { c as CustomerProduct, d as CustomerFeature, e as CustomerInvoice } from './cusTypes-CBQqMlZy.mjs';
2
+
3
+ type EntityExpandOption = "invoices";
4
+
5
+ interface GetEntityParams {
6
+ expand?: EntityExpandOption[];
7
+ }
8
+ interface Entity {
9
+ id: string;
10
+ name: string;
11
+ customer_id: string;
12
+ created_at: number;
13
+ env: string;
14
+ products: CustomerProduct[];
15
+ features: Record<string, CustomerFeature>;
16
+ invoices?: CustomerInvoice[];
17
+ }
18
+
19
+ export type { Entity as E, GetEntityParams as G };
@@ -0,0 +1,19 @@
1
+ import { c as CustomerProduct, d as CustomerFeature, e as CustomerInvoice } from './cusTypes-CBQqMlZy.js';
2
+
3
+ type EntityExpandOption = "invoices";
4
+
5
+ interface GetEntityParams {
6
+ expand?: EntityExpandOption[];
7
+ }
8
+ interface Entity {
9
+ id: string;
10
+ name: string;
11
+ customer_id: string;
12
+ created_at: number;
13
+ env: string;
14
+ products: CustomerProduct[];
15
+ features: Record<string, CustomerFeature>;
16
+ invoices?: CustomerInvoice[];
17
+ }
18
+
19
+ export type { Entity as E, GetEntityParams as G };
@@ -12,5 +12,10 @@ interface AttachParams {
12
12
  callback?: () => Promise<void>;
13
13
  withPreview?: "formatted" | "raw";
14
14
  }
15
+ interface CreateEntityParams {
16
+ id: string;
17
+ name: string;
18
+ featureId: string;
19
+ }
15
20
 
16
- export type { AttachParams };
21
+ export type { AttachParams, CreateEntityParams };
@@ -12,5 +12,10 @@ interface AttachParams {
12
12
  callback?: () => Promise<void>;
13
13
  withPreview?: "formatted" | "raw";
14
14
  }
15
+ interface CreateEntityParams {
16
+ id: string;
17
+ name: string;
18
+ featureId: string;
19
+ }
15
20
 
16
- export type { AttachParams };
21
+ export type { AttachParams, CreateEntityParams };
@@ -1,5 +1,5 @@
1
1
  import { A as AutumnError } from '../error-CG2LXoa7.mjs';
2
- import { a as Customer } from '../cusTypes-sGWmB2Vf.mjs';
2
+ import { a as Customer } from '../cusTypes-CBQqMlZy.mjs';
3
3
  import { AttachParams } from './types.mjs';
4
4
 
5
5
  declare const useAutumn: () => {
@@ -18,6 +18,10 @@ declare const useAutumn: () => {
18
18
  entityId?: string;
19
19
  value?: number;
20
20
  }) => Promise<any>;
21
+ cancel: ({ productId, entityId, }: {
22
+ productId: string;
23
+ entityId?: string;
24
+ }) => Promise<any>;
21
25
  openBillingPortal: (options?: {
22
26
  returnUrl?: string;
23
27
  }) => Promise<any>;
@@ -1,5 +1,5 @@
1
1
  import { A as AutumnError } from '../error-CG2LXoa7.js';
2
- import { a as Customer } from '../cusTypes-sGWmB2Vf.js';
2
+ import { a as Customer } from '../cusTypes-CBQqMlZy.js';
3
3
  import { AttachParams } from './types.js';
4
4
 
5
5
  declare const useAutumn: () => {
@@ -18,6 +18,10 @@ declare const useAutumn: () => {
18
18
  entityId?: string;
19
19
  value?: number;
20
20
  }) => Promise<any>;
21
+ cancel: ({ productId, entityId, }: {
22
+ productId: string;
23
+ entityId?: string;
24
+ }) => Promise<any>;
21
25
  openBillingPortal: (options?: {
22
26
  returnUrl?: string;
23
27
  }) => Promise<any>;
@@ -274,6 +274,7 @@ const useAutumn = () => {
274
274
  attach,
275
275
  check,
276
276
  track,
277
+ cancel,
277
278
  openBillingPortal,
278
279
  // Deprecated
279
280
  /**
@@ -274,6 +274,7 @@ const useAutumn = () => {
274
274
  attach,
275
275
  check,
276
276
  track,
277
+ cancel,
277
278
  openBillingPortal,
278
279
  // Deprecated
279
280
  /**
@@ -1,7 +1,9 @@
1
1
  import { A as AutumnError } from '../error-CG2LXoa7.mjs';
2
- import { a as Customer } from '../cusTypes-sGWmB2Vf.mjs';
2
+ import { b as CustomerExpandOption, a as Customer } from '../cusTypes-CBQqMlZy.mjs';
3
+ import { CreateEntityParams } from './types.mjs';
3
4
 
4
5
  interface UseCustomerProps {
6
+ expand?: CustomerExpandOption[];
5
7
  autoCreate?: boolean;
6
8
  }
7
9
  declare const useCustomer: (options?: UseCustomerProps) => {
@@ -9,6 +11,8 @@ declare const useCustomer: (options?: UseCustomerProps) => {
9
11
  isLoading: boolean;
10
12
  error: AutumnError | null;
11
13
  refetch: () => Promise<void>;
14
+ createEntity: (params: CreateEntityParams | CreateEntityParams[]) => Promise<any>;
15
+ deleteEntity: (entityId: string) => Promise<any>;
12
16
  };
13
17
 
14
18
  export { type UseCustomerProps, useCustomer };
@@ -1,7 +1,9 @@
1
1
  import { A as AutumnError } from '../error-CG2LXoa7.js';
2
- import { a as Customer } from '../cusTypes-sGWmB2Vf.js';
2
+ import { b as CustomerExpandOption, a as Customer } from '../cusTypes-CBQqMlZy.js';
3
+ import { CreateEntityParams } from './types.js';
3
4
 
4
5
  interface UseCustomerProps {
6
+ expand?: CustomerExpandOption[];
5
7
  autoCreate?: boolean;
6
8
  }
7
9
  declare const useCustomer: (options?: UseCustomerProps) => {
@@ -9,6 +11,8 @@ declare const useCustomer: (options?: UseCustomerProps) => {
9
11
  isLoading: boolean;
10
12
  error: AutumnError | null;
11
13
  refetch: () => Promise<void>;
14
+ createEntity: (params: CreateEntityParams | CreateEntityParams[]) => Promise<any>;
15
+ deleteEntity: (entityId: string) => Promise<any>;
12
16
  };
13
17
 
14
18
  export { type UseCustomerProps, useCustomer };
@@ -2,10 +2,30 @@
2
2
 
3
3
  import { useEffect, useState } from "react";
4
4
  import { useAutumnContext } from "../AutumnContext";
5
- import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
5
+ import {
6
+ getOrCreateCustomer,
7
+ getCustomer,
8
+ createEntityAction,
9
+ deleteEntityAction
10
+ } from "../../server/cusActions";
11
+ import { toClientErrorResponse } from "../clientUtils";
6
12
  const defaultOptions = {
13
+ expand: void 0,
7
14
  autoCreate: true
8
15
  };
16
+ const deleteEntity = async ({
17
+ encryptedCustomerId,
18
+ entityId
19
+ }) => {
20
+ const result = await deleteEntityAction({
21
+ encryptedCustomerId,
22
+ entityId
23
+ });
24
+ if (result.error) {
25
+ return toClientErrorResponse(result.error);
26
+ }
27
+ return result;
28
+ };
9
29
  const useCustomer = (options) => {
10
30
  let finalOptions = defaultOptions;
11
31
  if (options) {
@@ -24,12 +44,20 @@ const useCustomer = (options) => {
24
44
  if (autoCreate) {
25
45
  const result = await getOrCreateCustomer({
26
46
  encryptedCustomerId,
27
- customerData
47
+ customerData,
48
+ params: {
49
+ expand: finalOptions.expand
50
+ }
28
51
  });
29
52
  data = result.data;
30
53
  error2 = result.error;
31
54
  } else {
32
- const result = await getCustomer({ encryptedCustomerId });
55
+ const result = await getCustomer({
56
+ encryptedCustomerId,
57
+ params: {
58
+ expand: finalOptions.expand
59
+ }
60
+ });
33
61
  data = result.data;
34
62
  error2 = result.error;
35
63
  }
@@ -50,10 +78,36 @@ const useCustomer = (options) => {
50
78
  const refetch = async () => {
51
79
  await fetchCustomer();
52
80
  };
81
+ const createEntity = async (params) => {
82
+ let snakeParams = [];
83
+ if (Array.isArray(params)) {
84
+ snakeParams = params.map((param) => ({
85
+ ...param,
86
+ feature_id: param.featureId
87
+ }));
88
+ } else {
89
+ snakeParams = [{ ...params, feature_id: params.featureId }];
90
+ }
91
+ const result = await createEntityAction({
92
+ encryptedCustomerId,
93
+ entity: snakeParams
94
+ });
95
+ if (result.error) {
96
+ return toClientErrorResponse(result.error);
97
+ }
98
+ return result;
99
+ };
53
100
  useEffect(() => {
54
101
  fetchCustomer();
55
102
  }, [encryptedCustomerId]);
56
- return { customer, isLoading, error, refetch };
103
+ return {
104
+ customer,
105
+ isLoading,
106
+ error,
107
+ refetch,
108
+ createEntity,
109
+ deleteEntity: (entityId) => deleteEntity({ encryptedCustomerId, entityId })
110
+ };
57
111
  };
58
112
  export {
59
113
  useCustomer
@@ -2,10 +2,30 @@
2
2
 
3
3
  import { useEffect, useState } from "react";
4
4
  import { useAutumnContext } from "../AutumnContext";
5
- import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
5
+ import {
6
+ getOrCreateCustomer,
7
+ getCustomer,
8
+ createEntityAction,
9
+ deleteEntityAction
10
+ } from "../../server/cusActions";
11
+ import { toClientErrorResponse } from "../clientUtils";
6
12
  const defaultOptions = {
13
+ expand: void 0,
7
14
  autoCreate: true
8
15
  };
16
+ const deleteEntity = async ({
17
+ encryptedCustomerId,
18
+ entityId
19
+ }) => {
20
+ const result = await deleteEntityAction({
21
+ encryptedCustomerId,
22
+ entityId
23
+ });
24
+ if (result.error) {
25
+ return toClientErrorResponse(result.error);
26
+ }
27
+ return result;
28
+ };
9
29
  const useCustomer = (options) => {
10
30
  let finalOptions = defaultOptions;
11
31
  if (options) {
@@ -24,12 +44,20 @@ const useCustomer = (options) => {
24
44
  if (autoCreate) {
25
45
  const result = await getOrCreateCustomer({
26
46
  encryptedCustomerId,
27
- customerData
47
+ customerData,
48
+ params: {
49
+ expand: finalOptions.expand
50
+ }
28
51
  });
29
52
  data = result.data;
30
53
  error2 = result.error;
31
54
  } else {
32
- const result = await getCustomer({ encryptedCustomerId });
55
+ const result = await getCustomer({
56
+ encryptedCustomerId,
57
+ params: {
58
+ expand: finalOptions.expand
59
+ }
60
+ });
33
61
  data = result.data;
34
62
  error2 = result.error;
35
63
  }
@@ -50,10 +78,36 @@ const useCustomer = (options) => {
50
78
  const refetch = async () => {
51
79
  await fetchCustomer();
52
80
  };
81
+ const createEntity = async (params) => {
82
+ let snakeParams = [];
83
+ if (Array.isArray(params)) {
84
+ snakeParams = params.map((param) => ({
85
+ ...param,
86
+ feature_id: param.featureId
87
+ }));
88
+ } else {
89
+ snakeParams = [{ ...params, feature_id: params.featureId }];
90
+ }
91
+ const result = await createEntityAction({
92
+ encryptedCustomerId,
93
+ entity: snakeParams
94
+ });
95
+ if (result.error) {
96
+ return toClientErrorResponse(result.error);
97
+ }
98
+ return result;
99
+ };
53
100
  useEffect(() => {
54
101
  fetchCustomer();
55
102
  }, [encryptedCustomerId]);
56
- return { customer, isLoading, error, refetch };
103
+ return {
104
+ customer,
105
+ isLoading,
106
+ error,
107
+ refetch,
108
+ createEntity,
109
+ deleteEntity: (entityId) => deleteEntity({ encryptedCustomerId, entityId })
110
+ };
57
111
  };
58
112
  export {
59
113
  useCustomer
@@ -0,0 +1,12 @@
1
+ import { A as AutumnError } from '../error-CG2LXoa7.mjs';
2
+ import { G as GetEntityParams, E as Entity } from '../entTypes-DHSCGE1o.mjs';
3
+ import '../cusTypes-CBQqMlZy.mjs';
4
+
5
+ declare const useEntity: (entityId?: string, params?: GetEntityParams) => {
6
+ entity: Entity | null;
7
+ isLoading: boolean;
8
+ error: AutumnError | null;
9
+ refetch: () => Promise<void>;
10
+ };
11
+
12
+ export { useEntity };
@@ -0,0 +1,12 @@
1
+ import { A as AutumnError } from '../error-CG2LXoa7.js';
2
+ import { G as GetEntityParams, E as Entity } from '../entTypes-X4EHXDE5.js';
3
+ import '../cusTypes-CBQqMlZy.js';
4
+
5
+ declare const useEntity: (entityId?: string, params?: GetEntityParams) => {
6
+ entity: Entity | null;
7
+ isLoading: boolean;
8
+ error: AutumnError | null;
9
+ refetch: () => Promise<void>;
10
+ };
11
+
12
+ export { useEntity };
@@ -0,0 +1,60 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useAutumnContext } from "../AutumnContext";
5
+ import { AutumnClientError } from "../types";
6
+ import { getEntityAction } from "../../server/cusActions";
7
+ const useEntity = (entityId, params) => {
8
+ const {
9
+ encryptedCustomerId,
10
+ entityId: contextEntityId,
11
+ entity,
12
+ setEntity
13
+ } = useAutumnContext();
14
+ const finalEntityId = entityId || contextEntityId;
15
+ if (!finalEntityId) {
16
+ throw new AutumnClientError({
17
+ message: `Entity ID required in useEntity hook`,
18
+ code: "ENTITY_ID_REQUIRED"
19
+ });
20
+ }
21
+ const [error, setError] = useState(null);
22
+ const [isLoading, setIsLoading] = useState(true);
23
+ const fetchEntity = async () => {
24
+ setIsLoading(true);
25
+ let returnData = null;
26
+ try {
27
+ let data = null;
28
+ let error2 = null;
29
+ const result = await getEntityAction({
30
+ encryptedCustomerId,
31
+ entityId: finalEntityId,
32
+ params
33
+ });
34
+ data = result.data;
35
+ error2 = result.error;
36
+ if (error2) {
37
+ console.log("(Autumn) Error fetching entity:", error2);
38
+ setError(error2);
39
+ } else {
40
+ setEntity(data);
41
+ }
42
+ returnData = data;
43
+ } catch (error2) {
44
+ console.error("(Autumn) Error fetching entity:", error2);
45
+ setError(error2);
46
+ }
47
+ setIsLoading(false);
48
+ return returnData;
49
+ };
50
+ const refetch = async () => {
51
+ await fetchEntity();
52
+ };
53
+ useEffect(() => {
54
+ fetchEntity();
55
+ }, [encryptedCustomerId, finalEntityId]);
56
+ return { entity, isLoading, error, refetch };
57
+ };
58
+ export {
59
+ useEntity
60
+ };
@@ -0,0 +1,60 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useAutumnContext } from "../AutumnContext";
5
+ import { AutumnClientError } from "../types";
6
+ import { getEntityAction } from "../../server/cusActions";
7
+ const useEntity = (entityId, params) => {
8
+ const {
9
+ encryptedCustomerId,
10
+ entityId: contextEntityId,
11
+ entity,
12
+ setEntity
13
+ } = useAutumnContext();
14
+ const finalEntityId = entityId || contextEntityId;
15
+ if (!finalEntityId) {
16
+ throw new AutumnClientError({
17
+ message: `Entity ID required in useEntity hook`,
18
+ code: "ENTITY_ID_REQUIRED"
19
+ });
20
+ }
21
+ const [error, setError] = useState(null);
22
+ const [isLoading, setIsLoading] = useState(true);
23
+ const fetchEntity = async () => {
24
+ setIsLoading(true);
25
+ let returnData = null;
26
+ try {
27
+ let data = null;
28
+ let error2 = null;
29
+ const result = await getEntityAction({
30
+ encryptedCustomerId,
31
+ entityId: finalEntityId,
32
+ params
33
+ });
34
+ data = result.data;
35
+ error2 = result.error;
36
+ if (error2) {
37
+ console.log("(Autumn) Error fetching entity:", error2);
38
+ setError(error2);
39
+ } else {
40
+ setEntity(data);
41
+ }
42
+ returnData = data;
43
+ } catch (error2) {
44
+ console.error("(Autumn) Error fetching entity:", error2);
45
+ setError(error2);
46
+ }
47
+ setIsLoading(false);
48
+ return returnData;
49
+ };
50
+ const refetch = async () => {
51
+ await fetchEntity();
52
+ };
53
+ useEffect(() => {
54
+ fetchEntity();
55
+ }, [encryptedCustomerId, finalEntityId]);
56
+ return { entity, isLoading, error, refetch };
57
+ };
58
+ export {
59
+ useEntity
60
+ };