autumn-js 0.0.3 → 0.0.5

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Autumn.js
1
+ # Autumn JS Library
2
2
 
3
- Autumn.js is a comprehensive JavaScript/TypeScript library for interacting with the Autumn pricing platform. This package provides both a server-side SDK for the Autumn API and a Next.js integration package for seamless client-side implementation.
3
+ autumn-js is a comprehensive JavaScript/TypeScript library for interacting with the Autumn pricing platform. This package provides both a server-side SDK for the Autumn API and a Next.js integration package for seamless client-side implementation.
4
4
 
5
5
  ## Features
6
6
 
@@ -42,9 +42,9 @@ await autumn.customers.create({
42
42
  })
43
43
 
44
44
  // Other available operations
45
- await autumn.products.list()
46
- await autumn.prices.create(...)
47
- await autumn.subscriptions.create(...)
45
+ await autumn.attach(...)
46
+ await autumn.entitled(...)
47
+ await autumn.event(...)
48
48
  ```
49
49
 
50
50
  ### Next.js Integration
@@ -53,7 +53,7 @@ For Next.js applications, Autumn.js provides a dedicated integration with helpfu
53
53
 
54
54
  1. First, wrap your application with the `AutumnProvider` in your root layout:
55
55
 
56
- ```typescript
56
+ ```jsx
57
57
  // app/layout.tsx
58
58
  import { AutumnProvider } from 'autumn-js/next'
59
59
 
@@ -76,7 +76,7 @@ export default function RootLayout({
76
76
 
77
77
  2. Then use the `useAutumn` hook in your components:
78
78
 
79
- ```typescript
79
+ ```jsx
80
80
  import { useAutumn } from 'autumn-js/next'
81
81
 
82
82
  export default function BillingPage() {
@@ -4,7 +4,10 @@ import { createContext, useContext } from "react";
4
4
  const AutumnContext = createContext({
5
5
  encryptedCustomerId: "",
6
6
  customerData: {},
7
- authProvider: "better-auth"
7
+ authProvider: "better-auth",
8
+ customer: null,
9
+ setCustomer: () => {
10
+ }
8
11
  });
9
12
  const useAutumnContext = () => {
10
13
  const context = useContext(AutumnContext);
@@ -4,7 +4,10 @@ import { createContext, useContext } from "react";
4
4
  const AutumnContext = createContext({
5
5
  encryptedCustomerId: "",
6
6
  customerData: {},
7
- authProvider: "better-auth"
7
+ authProvider: "better-auth",
8
+ customer: null,
9
+ setCustomer: () => {
10
+ }
8
11
  });
9
12
  const useAutumnContext = () => {
10
13
  const context = useContext(AutumnContext);
@@ -1,9 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { AutumnContextParams } from './types.mjs';
3
- import './cusTypes-BUiIMwvu.mjs';
2
+ import { C as CustomerData } from './cusTypes-BUiIMwvu.mjs';
4
3
 
5
- interface AutumnProviderProps extends AutumnContextParams {
4
+ interface AutumnProviderProps {
6
5
  children?: React.ReactNode;
6
+ encryptedCustomerId?: string;
7
+ customerData?: CustomerData;
7
8
  }
8
9
  declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps) => react_jsx_runtime.JSX.Element;
9
10
 
@@ -1,9 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { AutumnContextParams } from './types.js';
3
- import './cusTypes-BUiIMwvu.js';
2
+ import { C as CustomerData } from './cusTypes-BUiIMwvu.js';
4
3
 
5
- interface AutumnProviderProps extends AutumnContextParams {
4
+ interface AutumnProviderProps {
6
5
  children?: React.ReactNode;
6
+ encryptedCustomerId?: string;
7
+ customerData?: CustomerData;
7
8
  }
8
9
  declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps) => react_jsx_runtime.JSX.Element;
9
10
 
@@ -2,17 +2,21 @@
2
2
 
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { AutumnContext } from "./AutumnContext";
5
+ import { useState } from "react";
5
6
  const AutumnClientProvider = ({
6
7
  children,
7
8
  encryptedCustomerId,
8
9
  customerData
9
10
  }) => {
11
+ let [customer, setCustomer] = useState(null);
10
12
  return /* @__PURE__ */ jsx(
11
13
  AutumnContext.Provider,
12
14
  {
13
15
  value: {
14
16
  encryptedCustomerId,
15
- customerData
17
+ customerData,
18
+ customer,
19
+ setCustomer
16
20
  },
17
21
  children
18
22
  }
@@ -2,17 +2,21 @@
2
2
 
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { AutumnContext } from "./AutumnContext";
5
+ import { useState } from "react";
5
6
  const AutumnClientProvider = ({
6
7
  children,
7
8
  encryptedCustomerId,
8
9
  customerData
9
10
  }) => {
11
+ let [customer, setCustomer] = useState(null);
10
12
  return /* @__PURE__ */ jsx(
11
13
  AutumnContext.Provider,
12
14
  {
13
15
  value: {
14
16
  encryptedCustomerId,
15
- customerData
17
+ customerData,
18
+ customer,
19
+ setCustomer
16
20
  },
17
21
  children
18
22
  }
@@ -8,6 +8,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
8
8
  customer: Customer | null;
9
9
  loading: boolean;
10
10
  error: AutumnError | null;
11
+ refetch: () => Promise<void>;
11
12
  attach: ({ productId }: {
12
13
  productId: string;
13
14
  }) => Promise<any>;
@@ -8,6 +8,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
8
8
  customer: Customer | null;
9
9
  loading: boolean;
10
10
  error: AutumnError | null;
11
+ refetch: () => Promise<void>;
11
12
  attach: ({ productId }: {
12
13
  productId: string;
13
14
  }) => Promise<any>;
@@ -13,7 +13,8 @@ const useAutumn = (options) => {
13
13
  const {
14
14
  customer,
15
15
  isLoading: loading,
16
- error
16
+ error,
17
+ refetch
17
18
  } = useCustomer({
18
19
  autoCreate: options?.autoCreate
19
20
  });
@@ -77,6 +78,7 @@ const useAutumn = (options) => {
77
78
  customer,
78
79
  loading,
79
80
  error,
81
+ refetch,
80
82
  attach,
81
83
  sendEvent,
82
84
  entitled,
@@ -13,7 +13,8 @@ const useAutumn = (options) => {
13
13
  const {
14
14
  customer,
15
15
  isLoading: loading,
16
- error
16
+ error,
17
+ refetch
17
18
  } = useCustomer({
18
19
  autoCreate: options?.autoCreate
19
20
  });
@@ -77,6 +78,7 @@ const useAutumn = (options) => {
77
78
  customer,
78
79
  loading,
79
80
  error,
81
+ refetch,
80
82
  attach,
81
83
  sendEvent,
82
84
  entitled,
@@ -9,6 +9,7 @@ declare const useCustomer: ({ autoCreate }: UseCustomerProps) => {
9
9
  customer: Customer | null;
10
10
  error: AutumnError | null;
11
11
  isLoading: boolean;
12
+ refetch: () => Promise<void>;
12
13
  };
13
14
 
14
15
  export { type UseCustomerProps, useCustomer };
@@ -9,6 +9,7 @@ declare const useCustomer: ({ autoCreate }: UseCustomerProps) => {
9
9
  customer: Customer | null;
10
10
  error: AutumnError | null;
11
11
  isLoading: boolean;
12
+ refetch: () => Promise<void>;
12
13
  };
13
14
 
14
15
  export { type UseCustomerProps, useCustomer };
@@ -4,8 +4,7 @@ import { useEffect, useState } from "react";
4
4
  import { useAutumnContext } from "../AutumnContext";
5
5
  import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
6
6
  const useCustomer = ({ autoCreate = true }) => {
7
- const { encryptedCustomerId, customerData } = useAutumnContext();
8
- const [customer, setCustomer] = useState(null);
7
+ const { encryptedCustomerId, customerData, customer, setCustomer } = useAutumnContext();
9
8
  const [error, setError] = useState(null);
10
9
  const [isLoading, setIsLoading] = useState(false);
11
10
  const fetchCustomer = async () => {
@@ -37,10 +36,13 @@ const useCustomer = ({ autoCreate = true }) => {
37
36
  }
38
37
  setIsLoading(false);
39
38
  };
39
+ const refetch = async () => {
40
+ await fetchCustomer();
41
+ };
40
42
  useEffect(() => {
41
43
  fetchCustomer();
42
44
  }, [encryptedCustomerId]);
43
- return { customer, error, isLoading };
45
+ return { customer, error, isLoading, refetch };
44
46
  };
45
47
  export {
46
48
  useCustomer
@@ -4,8 +4,7 @@ import { useEffect, useState } from "react";
4
4
  import { useAutumnContext } from "../AutumnContext";
5
5
  import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
6
6
  const useCustomer = ({ autoCreate = true }) => {
7
- const { encryptedCustomerId, customerData } = useAutumnContext();
8
- const [customer, setCustomer] = useState(null);
7
+ const { encryptedCustomerId, customerData, customer, setCustomer } = useAutumnContext();
9
8
  const [error, setError] = useState(null);
10
9
  const [isLoading, setIsLoading] = useState(false);
11
10
  const fetchCustomer = async () => {
@@ -37,10 +36,13 @@ const useCustomer = ({ autoCreate = true }) => {
37
36
  }
38
37
  setIsLoading(false);
39
38
  };
39
+ const refetch = async () => {
40
+ await fetchCustomer();
41
+ };
40
42
  useEffect(() => {
41
43
  fetchCustomer();
42
44
  }, [encryptedCustomerId]);
43
- return { customer, error, isLoading };
45
+ return { customer, error, isLoading, refetch };
44
46
  };
45
47
  export {
46
48
  useCustomer
@@ -1,9 +1,11 @@
1
- import { C as CustomerData } from './cusTypes-BUiIMwvu.mjs';
1
+ import { C as CustomerData, a as Customer } from './cusTypes-BUiIMwvu.mjs';
2
2
 
3
3
  interface AutumnContextParams {
4
4
  encryptedCustomerId?: string;
5
5
  customerData?: CustomerData;
6
6
  authProvider?: "clerk" | "better-auth";
7
+ customer: Customer | null;
8
+ setCustomer: (customer: Customer | null) => void;
7
9
  }
8
10
  interface AutumnProviderProps extends AutumnContextParams {
9
11
  children?: React.ReactNode;
@@ -1,9 +1,11 @@
1
- import { C as CustomerData } from './cusTypes-BUiIMwvu.js';
1
+ import { C as CustomerData, a as Customer } from './cusTypes-BUiIMwvu.js';
2
2
 
3
3
  interface AutumnContextParams {
4
4
  encryptedCustomerId?: string;
5
5
  customerData?: CustomerData;
6
6
  authProvider?: "clerk" | "better-auth";
7
+ customer: Customer | null;
8
+ setCustomer: (customer: Customer | null) => void;
7
9
  }
8
10
  interface AutumnProviderProps extends AutumnContextParams {
9
11
  children?: React.ReactNode;
@@ -75,6 +75,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
75
75
  customer: Customer | null;
76
76
  loading: boolean;
77
77
  error: AutumnError | null;
78
+ refetch: () => Promise<void>;
78
79
  attach: ({ productId }: {
79
80
  productId: string;
80
81
  }) => Promise<any>;
@@ -96,19 +97,24 @@ declare const useCustomer: ({ autoCreate }: UseCustomerProps) => {
96
97
  customer: Customer | null;
97
98
  error: AutumnError | null;
98
99
  isLoading: boolean;
100
+ refetch: () => Promise<void>;
99
101
  };
100
102
 
101
103
  interface AutumnContextParams {
102
104
  encryptedCustomerId?: string;
103
105
  customerData?: CustomerData;
104
106
  authProvider?: "clerk" | "better-auth";
107
+ customer: Customer | null;
108
+ setCustomer: (customer: Customer | null) => void;
105
109
  }
106
110
 
107
111
  declare const AutumnContext: react.Context<AutumnContextParams>;
108
112
  declare const useAutumnContext: () => AutumnContextParams;
109
113
 
110
- interface AutumnProviderProps$1 extends AutumnContextParams {
114
+ interface AutumnProviderProps$1 {
111
115
  children?: React.ReactNode;
116
+ encryptedCustomerId?: string;
117
+ customerData?: CustomerData;
112
118
  }
113
119
  declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps$1) => react_jsx_runtime.JSX.Element;
114
120
 
@@ -75,6 +75,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
75
75
  customer: Customer | null;
76
76
  loading: boolean;
77
77
  error: AutumnError | null;
78
+ refetch: () => Promise<void>;
78
79
  attach: ({ productId }: {
79
80
  productId: string;
80
81
  }) => Promise<any>;
@@ -96,19 +97,24 @@ declare const useCustomer: ({ autoCreate }: UseCustomerProps) => {
96
97
  customer: Customer | null;
97
98
  error: AutumnError | null;
98
99
  isLoading: boolean;
100
+ refetch: () => Promise<void>;
99
101
  };
100
102
 
101
103
  interface AutumnContextParams {
102
104
  encryptedCustomerId?: string;
103
105
  customerData?: CustomerData;
104
106
  authProvider?: "clerk" | "better-auth";
107
+ customer: Customer | null;
108
+ setCustomer: (customer: Customer | null) => void;
105
109
  }
106
110
 
107
111
  declare const AutumnContext: react.Context<AutumnContextParams>;
108
112
  declare const useAutumnContext: () => AutumnContextParams;
109
113
 
110
- interface AutumnProviderProps$1 extends AutumnContextParams {
114
+ interface AutumnProviderProps$1 {
111
115
  children?: React.ReactNode;
116
+ encryptedCustomerId?: string;
117
+ customerData?: CustomerData;
112
118
  }
113
119
  declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps$1) => react_jsx_runtime.JSX.Element;
114
120
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "autumn-js",
3
3
  "description": "Autumn JS Library",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
package/publish.sh CHANGED
@@ -6,6 +6,8 @@ cp ../README.md ./
6
6
  # Copy LICENSE.md from ../ to ./
7
7
  cp ../LICENSE.md ./
8
8
 
9
+ npm run build
10
+
9
11
  npm version patch
10
12
 
11
13
  npm publish