autumn-js 0.0.9 → 0.0.11

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
@@ -95,9 +95,9 @@ export default function BillingPage() {
95
95
  The `useAutumn` hook exports several useful functions:
96
96
 
97
97
  - `attach({ productId })`: Opens a checkout URL automatically when called to attach a product to the customer
98
- - `openBillingPortal()`: Opens Stripe's billing portal for the current customer to manage their subscription and billing settings
99
98
  - `entitled({ featureId })`: Checks if the customer is entitled to use a specific feature
100
- - `sendEvent({ featureId, value })`: Records usage for a particular feature
99
+ - `event({ featureId, value })`: Records usage for a particular feature
100
+ - `openBillingPortal()`: Opens Stripe's billing portal for the current customer to manage their subscription and billing settings
101
101
 
102
102
 
103
103
  <br/>
@@ -117,18 +117,30 @@ Better Auth Example:
117
117
  </AutumnProvider>
118
118
  ```
119
119
 
120
+ Supabase Example:
121
+ ```jsx
122
+ <AutumnProvider
123
+ authPlugin={{
124
+ provider: "supabase",
125
+ }}
126
+ >
127
+ {children}
128
+ </AutumnProvider>
129
+ ```
130
+
120
131
  Clerk Example:
121
132
  ```jsx
122
133
  <AutumnProvider
123
134
  authPlugin={{
124
- provider: "clerk",
125
- useOrg: true, // Set to true if organizations are your customers
135
+ provider: "clerk",
136
+ useOrg: true,
126
137
  }}
127
138
  >
128
139
  {children}
129
140
  </AutumnProvider>
130
141
  ```
131
142
 
143
+
132
144
  ## API Reference
133
145
 
134
146
  For detailed API documentation, visit [docs.useautumn.com](https://docs.useautumn.com)
@@ -12,7 +12,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
12
12
  attach: ({ productId }: {
13
13
  productId: string;
14
14
  }) => Promise<any>;
15
- sendEvent: ({ featureId, value, }: {
15
+ event: ({ featureId, value, }: {
16
16
  featureId: string;
17
17
  value?: number;
18
18
  }) => Promise<any>;
@@ -12,7 +12,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
12
12
  attach: ({ productId }: {
13
13
  productId: string;
14
14
  }) => Promise<any>;
15
- sendEvent: ({ featureId, value, }: {
15
+ event: ({ featureId, value, }: {
16
16
  featureId: string;
17
17
  value?: number;
18
18
  }) => Promise<any>;
@@ -42,7 +42,7 @@ const useAutumn = (options) => {
42
42
  }
43
43
  return data;
44
44
  };
45
- const sendEvent = async ({
45
+ const event = async ({
46
46
  featureId,
47
47
  value
48
48
  }) => {
@@ -80,7 +80,7 @@ const useAutumn = (options) => {
80
80
  error,
81
81
  refetch,
82
82
  attach,
83
- sendEvent,
83
+ event,
84
84
  entitled,
85
85
  openBillingPortal
86
86
  };
@@ -42,7 +42,7 @@ const useAutumn = (options) => {
42
42
  }
43
43
  return data;
44
44
  };
45
- const sendEvent = async ({
45
+ const event = async ({
46
46
  featureId,
47
47
  value
48
48
  }) => {
@@ -80,7 +80,7 @@ const useAutumn = (options) => {
80
80
  error,
81
81
  refetch,
82
82
  attach,
83
- sendEvent,
83
+ event,
84
84
  entitled,
85
85
  openBillingPortal
86
86
  };
@@ -79,7 +79,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
79
79
  attach: ({ productId }: {
80
80
  productId: string;
81
81
  }) => Promise<any>;
82
- sendEvent: ({ featureId, value, }: {
82
+ event: ({ featureId, value, }: {
83
83
  featureId: string;
84
84
  value?: number;
85
85
  }) => Promise<any>;
@@ -79,7 +79,7 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
79
79
  attach: ({ productId }: {
80
80
  productId: string;
81
81
  }) => Promise<any>;
82
- sendEvent: ({ featureId, value, }: {
82
+ event: ({ featureId, value, }: {
83
83
  featureId: string;
84
84
  value?: number;
85
85
  }) => Promise<any>;
@@ -16,6 +16,9 @@ declare const handleClerk: ({ options, withCustomerData, }: {
16
16
  name: string;
17
17
  email: string | null | undefined;
18
18
  };
19
+ } | {
20
+ customerId: string;
21
+ customerData?: undefined;
19
22
  } | {
20
23
  customerId: string;
21
24
  customerData: {
@@ -39,6 +42,21 @@ declare const handleAuthProvider: ({ authPlugin, withCustomerData, }: {
39
42
  name: any;
40
43
  email: any;
41
44
  };
45
+ } | null> | Promise<{
46
+ customerId: string;
47
+ customerData: {
48
+ name: string;
49
+ email: string | null | undefined;
50
+ };
51
+ } | {
52
+ customerId: string;
53
+ customerData?: undefined;
54
+ } | {
55
+ customerId: string;
56
+ customerData: {
57
+ name: string | null;
58
+ email: string | undefined;
59
+ };
42
60
  } | null>;
43
61
 
44
62
  export { handleAuthProvider, handleBetterAuth, handleClerk, handleSupabase };
@@ -16,6 +16,9 @@ declare const handleClerk: ({ options, withCustomerData, }: {
16
16
  name: string;
17
17
  email: string | null | undefined;
18
18
  };
19
+ } | {
20
+ customerId: string;
21
+ customerData?: undefined;
19
22
  } | {
20
23
  customerId: string;
21
24
  customerData: {
@@ -39,6 +42,21 @@ declare const handleAuthProvider: ({ authPlugin, withCustomerData, }: {
39
42
  name: any;
40
43
  email: any;
41
44
  };
45
+ } | null> | Promise<{
46
+ customerId: string;
47
+ customerData: {
48
+ name: string;
49
+ email: string | null | undefined;
50
+ };
51
+ } | {
52
+ customerId: string;
53
+ customerData?: undefined;
54
+ } | {
55
+ customerId: string;
56
+ customerData: {
57
+ name: string | null;
58
+ email: string | undefined;
59
+ };
42
60
  } | null>;
43
61
 
44
62
  export { handleAuthProvider, handleBetterAuth, handleClerk, handleSupabase };
@@ -82,6 +82,12 @@ const handleClerk = async ({
82
82
  email
83
83
  }
84
84
  };
85
+ } else {
86
+ if (authData.orgId) {
87
+ return {
88
+ customerId: authData.orgId
89
+ };
90
+ }
85
91
  }
86
92
  } catch (error) {
87
93
  throw {
@@ -82,6 +82,12 @@ const handleClerk = async ({
82
82
  email
83
83
  }
84
84
  };
85
+ } else {
86
+ if (authData.orgId) {
87
+ return {
88
+ customerId: authData.orgId
89
+ };
90
+ }
85
91
  }
86
92
  } catch (error) {
87
93
  throw {
@@ -22,7 +22,7 @@ const withAuth = (fn, withCustomerData = false) => {
22
22
  withCustomerData
23
23
  });
24
24
  customerId = result?.customerId;
25
- customerData = result?.customerData;
25
+ customerData = result?.customerData || void 0;
26
26
  } else {
27
27
  let encryptedCustomerId = args.encryptedCustomerId;
28
28
  customerId = encryptedCustomerId ? decryptData(encryptedCustomerId) : null;
@@ -22,7 +22,7 @@ const withAuth = (fn, withCustomerData = false) => {
22
22
  withCustomerData
23
23
  });
24
24
  customerId = result?.customerId;
25
- customerData = result?.customerData;
25
+ customerData = result?.customerData || void 0;
26
26
  } else {
27
27
  let encryptedCustomerId = args.encryptedCustomerId;
28
28
  customerId = encryptedCustomerId ? decryptData(encryptedCustomerId) : null;
@@ -60,6 +60,17 @@ interface EntitledResult {
60
60
  allowed: boolean;
61
61
  balances: EntitledBalance[];
62
62
  }
63
+ interface UsageParams {
64
+ customer_id: string;
65
+ feature_id: string;
66
+ value: number;
67
+ customer_data?: CustomerData;
68
+ }
69
+ interface UsageResult {
70
+ code: string;
71
+ customer_id: string;
72
+ feature_id: string;
73
+ }
63
74
 
64
75
  declare class Autumn {
65
76
  private readonly secretKey;
@@ -180,6 +191,10 @@ declare class Autumn {
180
191
  data: AttachResult | null;
181
192
  error: AutumnError | null;
182
193
  }>;
194
+ static usage: (params: UsageParams) => Promise<{
195
+ data: UsageResult | null;
196
+ error: AutumnError | null;
197
+ }>;
183
198
  attach(params: AttachParams): Promise<{
184
199
  data: AttachResult | null;
185
200
  error: AutumnError | null;
@@ -192,6 +207,10 @@ declare class Autumn {
192
207
  data: EventResult | null;
193
208
  error: AutumnError | null;
194
209
  }>;
210
+ usage(params: UsageParams): Promise<{
211
+ data: UsageResult | null;
212
+ error: AutumnError | null;
213
+ }>;
195
214
  }
196
215
 
197
216
  interface ProductItem {
@@ -60,6 +60,17 @@ interface EntitledResult {
60
60
  allowed: boolean;
61
61
  balances: EntitledBalance[];
62
62
  }
63
+ interface UsageParams {
64
+ customer_id: string;
65
+ feature_id: string;
66
+ value: number;
67
+ customer_data?: CustomerData;
68
+ }
69
+ interface UsageResult {
70
+ code: string;
71
+ customer_id: string;
72
+ feature_id: string;
73
+ }
63
74
 
64
75
  declare class Autumn {
65
76
  private readonly secretKey;
@@ -180,6 +191,10 @@ declare class Autumn {
180
191
  data: AttachResult | null;
181
192
  error: AutumnError | null;
182
193
  }>;
194
+ static usage: (params: UsageParams) => Promise<{
195
+ data: UsageResult | null;
196
+ error: AutumnError | null;
197
+ }>;
183
198
  attach(params: AttachParams): Promise<{
184
199
  data: AttachResult | null;
185
200
  error: AutumnError | null;
@@ -192,6 +207,10 @@ declare class Autumn {
192
207
  data: EventResult | null;
193
208
  error: AutumnError | null;
194
209
  }>;
210
+ usage(params: UsageParams): Promise<{
211
+ data: UsageResult | null;
212
+ error: AutumnError | null;
213
+ }>;
195
214
  }
196
215
 
197
216
  interface ProductItem {
@@ -60,6 +60,12 @@ interface UsageParams {
60
60
  customer_id: string;
61
61
  feature_id: string;
62
62
  value: number;
63
+ customer_data?: CustomerData;
64
+ }
65
+ interface UsageResult {
66
+ code: string;
67
+ customer_id: string;
68
+ feature_id: string;
63
69
  }
64
70
 
65
- export type { AttachFeatureOptions, AttachParams, AttachResult, EntitledBalance, EntitledParams, EntitledResult, EventParams, EventResult, UsageParams };
71
+ export type { AttachFeatureOptions, AttachParams, AttachResult, EntitledBalance, EntitledParams, EntitledResult, EventParams, EventResult, UsageParams, UsageResult };
@@ -60,6 +60,12 @@ interface UsageParams {
60
60
  customer_id: string;
61
61
  feature_id: string;
62
62
  value: number;
63
+ customer_data?: CustomerData;
64
+ }
65
+ interface UsageResult {
66
+ code: string;
67
+ customer_id: string;
68
+ feature_id: string;
63
69
  }
64
70
 
65
- export type { AttachFeatureOptions, AttachParams, AttachResult, EntitledBalance, EntitledParams, EntitledResult, EventParams, EventResult, UsageParams };
71
+ export type { AttachFeatureOptions, AttachParams, AttachResult, EntitledBalance, EntitledParams, EntitledResult, EventParams, EventResult, UsageParams, UsageResult };
@@ -1,4 +1,4 @@
1
- import { EntitledParams, EntitledResult, EventParams, EventResult, AttachParams, AttachResult } from './general.mjs';
1
+ import { EntitledParams, EntitledResult, EventParams, EventResult, AttachParams, AttachResult, UsageParams, UsageResult } from './general.mjs';
2
2
  import { C as Customer, a as CreateCustomerParams, U as UpdateCustomerParams, B as BillingPortalParams, b as BillingPortalResponse } from './cusTypes-DEdFHlrl.mjs';
3
3
  export { e as CustomerData, c as CustomerFeature, d as CustomerProduct, P as ProductStatus } from './cusTypes-DEdFHlrl.mjs';
4
4
  import { Product, CreateProductParams } from './products.mjs';
@@ -129,6 +129,10 @@ declare class Autumn {
129
129
  data: AttachResult | null;
130
130
  error: AutumnError | null;
131
131
  }>;
132
+ static usage: (params: UsageParams) => Promise<{
133
+ data: UsageResult | null;
134
+ error: AutumnError | null;
135
+ }>;
132
136
  attach(params: AttachParams): Promise<{
133
137
  data: AttachResult | null;
134
138
  error: AutumnError | null;
@@ -141,6 +145,10 @@ declare class Autumn {
141
145
  data: EventResult | null;
142
146
  error: AutumnError | null;
143
147
  }>;
148
+ usage(params: UsageParams): Promise<{
149
+ data: UsageResult | null;
150
+ error: AutumnError | null;
151
+ }>;
144
152
  }
145
153
 
146
154
  export { Autumn, type AutumnError, BillingPortalParams, BillingPortalResponse, CreateCustomerParams, CreateProductParams, Customer, Product, UpdateCustomerParams };
@@ -1,4 +1,4 @@
1
- import { EntitledParams, EntitledResult, EventParams, EventResult, AttachParams, AttachResult } from './general.js';
1
+ import { EntitledParams, EntitledResult, EventParams, EventResult, AttachParams, AttachResult, UsageParams, UsageResult } from './general.js';
2
2
  import { C as Customer, a as CreateCustomerParams, U as UpdateCustomerParams, B as BillingPortalParams, b as BillingPortalResponse } from './cusTypes-B9fUPd5R.js';
3
3
  export { e as CustomerData, c as CustomerFeature, d as CustomerProduct, P as ProductStatus } from './cusTypes-B9fUPd5R.js';
4
4
  import { Product, CreateProductParams } from './products.js';
@@ -129,6 +129,10 @@ declare class Autumn {
129
129
  data: AttachResult | null;
130
130
  error: AutumnError | null;
131
131
  }>;
132
+ static usage: (params: UsageParams) => Promise<{
133
+ data: UsageResult | null;
134
+ error: AutumnError | null;
135
+ }>;
132
136
  attach(params: AttachParams): Promise<{
133
137
  data: AttachResult | null;
134
138
  error: AutumnError | null;
@@ -141,6 +145,10 @@ declare class Autumn {
141
145
  data: EventResult | null;
142
146
  error: AutumnError | null;
143
147
  }>;
148
+ usage(params: UsageParams): Promise<{
149
+ data: UsageResult | null;
150
+ error: AutumnError | null;
151
+ }>;
144
152
  }
145
153
 
146
154
  export { Autumn, type AutumnError, BillingPortalParams, BillingPortalResponse, CreateCustomerParams, CreateProductParams, Customer, Product, UpdateCustomerParams };
package/dist/sdk/index.js CHANGED
@@ -69,8 +69,7 @@ var billingPortal = async ({
69
69
  id,
70
70
  params
71
71
  }) => {
72
- const queryParams = params?.return_url ? `?return_url=${encodeURIComponent(params.return_url)}` : "";
73
- return instance.get(`/customers/${id}/billing_portal${queryParams}`);
72
+ return instance.post(`/customers/${id}/billing_portal`, params);
74
73
  };
75
74
 
76
75
  // src/sdk/general/genMethods.ts
@@ -92,6 +91,12 @@ var handleEvent = async ({
92
91
  }) => {
93
92
  return instance.post("/events", params);
94
93
  };
94
+ var handleUsage = async ({
95
+ instance,
96
+ params
97
+ }) => {
98
+ return instance.post("/usage", params);
99
+ };
95
100
 
96
101
  // src/sdk/products/prodMethods.ts
97
102
  var productMethods = (instance) => {
@@ -217,12 +222,19 @@ var Autumn = class {
217
222
  params
218
223
  });
219
224
  }
225
+ async usage(params) {
226
+ return handleUsage({
227
+ instance: this,
228
+ params
229
+ });
230
+ }
220
231
  };
221
232
  __publicField(Autumn, "customers", customerMethods());
222
233
  __publicField(Autumn, "products", productMethods());
223
234
  __publicField(Autumn, "entitled", (params) => staticWrapper(handleEntitled, void 0, { params }));
224
235
  __publicField(Autumn, "event", (params) => staticWrapper(handleEvent, void 0, { params }));
225
236
  __publicField(Autumn, "attach", (params) => staticWrapper(handleAttach, void 0, { params }));
237
+ __publicField(Autumn, "usage", (params) => staticWrapper(handleUsage, void 0, { params }));
226
238
 
227
239
  // src/sdk/general/genEnums.ts
228
240
  var AppEnv = /* @__PURE__ */ ((AppEnv2) => {
@@ -67,8 +67,7 @@ var billingPortal = async ({
67
67
  id,
68
68
  params
69
69
  }) => {
70
- const queryParams = params?.return_url ? `?return_url=${encodeURIComponent(params.return_url)}` : "";
71
- return instance.get(`/customers/${id}/billing_portal${queryParams}`);
70
+ return instance.post(`/customers/${id}/billing_portal`, params);
72
71
  };
73
72
 
74
73
  // src/sdk/general/genMethods.ts
@@ -90,6 +89,12 @@ var handleEvent = async ({
90
89
  }) => {
91
90
  return instance.post("/events", params);
92
91
  };
92
+ var handleUsage = async ({
93
+ instance,
94
+ params
95
+ }) => {
96
+ return instance.post("/usage", params);
97
+ };
93
98
 
94
99
  // src/sdk/products/prodMethods.ts
95
100
  var productMethods = (instance) => {
@@ -215,12 +220,19 @@ var Autumn = class {
215
220
  params
216
221
  });
217
222
  }
223
+ async usage(params) {
224
+ return handleUsage({
225
+ instance: this,
226
+ params
227
+ });
228
+ }
218
229
  };
219
230
  __publicField(Autumn, "customers", customerMethods());
220
231
  __publicField(Autumn, "products", productMethods());
221
232
  __publicField(Autumn, "entitled", (params) => staticWrapper(handleEntitled, void 0, { params }));
222
233
  __publicField(Autumn, "event", (params) => staticWrapper(handleEvent, void 0, { params }));
223
234
  __publicField(Autumn, "attach", (params) => staticWrapper(handleAttach, void 0, { params }));
235
+ __publicField(Autumn, "usage", (params) => staticWrapper(handleUsage, void 0, { params }));
224
236
 
225
237
  // src/sdk/general/genEnums.ts
226
238
  var AppEnv = /* @__PURE__ */ ((AppEnv2) => {
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.9",
4
+ "version": "0.0.11",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -31,16 +31,27 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.14.1",
34
- "@types/react": "^18.2.0",
35
- "@types/react-dom": "^18.2.0",
34
+ "@types/react": "^18.2.0 || ^19.0.0",
35
+ "@types/react-dom": "^18.2.0 || ^19.0.0",
36
36
  "tsup": "^8.4.0",
37
37
  "typescript": "^5.8.3"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@clerk/nextjs": "^6.16.0",
41
41
  "better-auth": "^1.2.7",
42
- "react": "^18.2.0",
43
- "react-dom": "^18.2.0",
42
+ "react": "^18.2.0 || ^19.0.0",
43
+ "react-dom": "^18.2.0 || ^19.0.0",
44
44
  "@supabase/ssr": "^0.6.1"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@clerk/nextjs": {
48
+ "optional": true
49
+ },
50
+ "better-auth": {
51
+ "optional": true
52
+ },
53
+ "@supabase/ssr": {
54
+ "optional": true
55
+ }
45
56
  }
46
57
  }