autumn-js 1.2.12 → 1.2.13

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 (159) hide show
  1. package/dist/backend/adapters/express.js +91 -4
  2. package/dist/backend/adapters/express.mjs +6 -6
  3. package/dist/backend/adapters/fetch.js +91 -4
  4. package/dist/backend/adapters/fetch.mjs +6 -6
  5. package/dist/backend/adapters/hono.js +91 -4
  6. package/dist/backend/adapters/hono.mjs +6 -6
  7. package/dist/backend/adapters/index.js +91 -4
  8. package/dist/backend/adapters/index.mjs +9 -9
  9. package/dist/backend/adapters/next.js +91 -4
  10. package/dist/backend/adapters/next.mjs +6 -6
  11. package/dist/backend/{chunk-JQX5WYYY.mjs → chunk-7BVATYGA.mjs} +1 -1
  12. package/dist/backend/{chunk-7Q77N2K2.mjs → chunk-DNNJOZAT.mjs} +1 -1
  13. package/dist/backend/{chunk-N53PKNZ6.mjs → chunk-EJGHP7KT.mjs} +2 -2
  14. package/dist/backend/{chunk-X4LPDDOP.mjs → chunk-MANTLPDT.mjs} +4 -0
  15. package/dist/backend/{chunk-4Q54RXI2.mjs → chunk-OUDB34Y7.mjs} +1 -1
  16. package/dist/backend/{chunk-SE5CK5NY.mjs → chunk-RPH5L44S.mjs} +1 -1
  17. package/dist/backend/{chunk-UEYDU64U.mjs → chunk-T42RZEUZ.mjs} +87 -4
  18. package/dist/backend/{chunk-ITXMMCSD.mjs → chunk-YSQQKZBU.mjs} +2 -2
  19. package/dist/backend/core/handlers/coreHandler.d.mts +1 -1
  20. package/dist/backend/core/handlers/coreHandler.d.ts +1 -1
  21. package/dist/backend/core/handlers/coreHandler.js +91 -4
  22. package/dist/backend/core/handlers/coreHandler.mjs +4 -4
  23. package/dist/backend/core/handlers/executeRoute.d.mts +1 -1
  24. package/dist/backend/core/handlers/executeRoute.d.ts +1 -1
  25. package/dist/backend/core/handlers/executeRoute.mjs +1 -1
  26. package/dist/backend/core/handlers/handleRouteByName.js +91 -4
  27. package/dist/backend/core/handlers/handleRouteByName.mjs +4 -4
  28. package/dist/backend/core/handlers/index.d.mts +1 -1
  29. package/dist/backend/core/handlers/index.d.ts +1 -1
  30. package/dist/backend/core/handlers/index.js +91 -4
  31. package/dist/backend/core/handlers/index.mjs +5 -5
  32. package/dist/backend/core/index.d.mts +1 -1
  33. package/dist/backend/core/index.d.ts +1 -1
  34. package/dist/backend/core/index.js +91 -4
  35. package/dist/backend/core/index.mjs +7 -7
  36. package/dist/backend/core/routes/index.d.mts +1 -1
  37. package/dist/backend/core/routes/index.d.ts +1 -1
  38. package/dist/backend/core/routes/index.js +4 -0
  39. package/dist/backend/core/routes/index.mjs +2 -2
  40. package/dist/backend/core/routes/routeBuilder.d.mts +1 -1
  41. package/dist/backend/core/routes/routeBuilder.d.ts +1 -1
  42. package/dist/backend/core/routes/routeConfigs.d.mts +1 -1
  43. package/dist/backend/core/routes/routeConfigs.d.ts +1 -1
  44. package/dist/backend/core/routes/routeConfigs.js +4 -0
  45. package/dist/backend/core/routes/routeConfigs.mjs +2 -2
  46. package/dist/backend/core/types/handlerTypes.d.mts +1 -1
  47. package/dist/backend/core/types/handlerTypes.d.ts +1 -1
  48. package/dist/backend/core/types/index.d.mts +1 -1
  49. package/dist/backend/core/types/index.d.ts +1 -1
  50. package/dist/backend/core/types/routeTypes.d.mts +1 -1
  51. package/dist/backend/core/types/routeTypes.d.ts +1 -1
  52. package/dist/backend/core/utils/index.mjs +3 -3
  53. package/dist/backend/index.d.mts +2 -2
  54. package/dist/backend/index.d.ts +2 -2
  55. package/dist/backend/index.js +91 -4
  56. package/dist/backend/index.mjs +7 -7
  57. package/dist/backend/{routeTypes-D0ag5-Tb.d.ts → routeTypes-B94_Mq2J.d.ts} +93 -0
  58. package/dist/backend/{routeTypes-Cu-XQy7A.d.mts → routeTypes-DVwngaBn.d.mts} +93 -0
  59. package/dist/better-auth/{chunk-TEP6CVHR.mjs → chunk-4OWECHZC.mjs} +1 -1
  60. package/dist/better-auth/{chunk-GKUK5UGW.mjs → chunk-JIFD4TSN.mjs} +4 -0
  61. package/dist/better-auth/{chunk-XFATOIZD.mjs → chunk-ZZGFPTHO.mjs} +88 -5
  62. package/dist/better-auth/client.d.mts +3 -7
  63. package/dist/better-auth/client.d.ts +3 -7
  64. package/dist/better-auth/createAutumnEndpoint-CvXRCg-M.d.mts +43 -0
  65. package/dist/better-auth/createAutumnEndpoint-CvXRCg-M.d.ts +43 -0
  66. package/dist/better-auth/index.d.mts +3 -7
  67. package/dist/better-auth/index.d.ts +3 -7
  68. package/dist/better-auth/index.js +91 -4
  69. package/dist/better-auth/index.mjs +3 -3
  70. package/dist/better-auth/utils/createAutumnEndpoint.d.mts +3 -7
  71. package/dist/better-auth/utils/createAutumnEndpoint.d.ts +3 -7
  72. package/dist/better-auth/utils/createAutumnEndpoint.js +4 -0
  73. package/dist/better-auth/utils/createAutumnEndpoint.mjs +2 -2
  74. package/dist/better-auth/utils/handleBetterAuthRoute.d.mts +3 -7
  75. package/dist/better-auth/utils/handleBetterAuthRoute.d.ts +3 -7
  76. package/dist/better-auth/utils/handleBetterAuthRoute.js +91 -4
  77. package/dist/better-auth/utils/handleBetterAuthRoute.mjs +2 -2
  78. package/dist/better-auth/utils/index.d.mts +3 -8
  79. package/dist/better-auth/utils/index.d.ts +3 -8
  80. package/dist/better-auth/utils/index.js +91 -4
  81. package/dist/better-auth/utils/index.mjs +3 -3
  82. package/dist/react/AutumnContext.d.mts +3 -3
  83. package/dist/react/AutumnContext.d.ts +3 -3
  84. package/dist/react/AutumnProvider.js +15 -15
  85. package/dist/react/AutumnProvider.mjs +2 -2
  86. package/dist/react/{chunk-26CKSAPZ.mjs → chunk-7IDH4OMG.mjs} +1 -1
  87. package/dist/react/{chunk-HSQUB3BZ.mjs → chunk-BDG6JHEW.mjs} +1 -1
  88. package/dist/react/{chunk-KB72KQKN.mjs → chunk-DEZBJQEG.mjs} +1 -1
  89. package/dist/react/{chunk-XJZH5NMZ.mjs → chunk-E5ZHOMZ4.mjs} +23 -23
  90. package/dist/react/{chunk-OXQG65ZT.mjs → chunk-FWWIAOPU.mjs} +1 -1
  91. package/dist/react/{chunk-ZGPE4R6H.mjs → chunk-HVBDZARN.mjs} +2 -2
  92. package/dist/react/{chunk-MC2YYATT.mjs → chunk-J6SLKTKE.mjs} +1 -1
  93. package/dist/react/{chunk-CHU7CIWP.mjs → chunk-NSFHAUTD.mjs} +1 -1
  94. package/dist/react/{chunk-G7FTQLT7.mjs → chunk-YQFYWH7J.mjs} +1 -1
  95. package/dist/react/client/AutumnClient.d.mts +3 -3
  96. package/dist/react/client/AutumnClient.d.ts +3 -3
  97. package/dist/react/client/IAutumnClient.d.mts +16 -3
  98. package/dist/react/client/IAutumnClient.d.ts +16 -3
  99. package/dist/react/client/index.d.mts +3 -3
  100. package/dist/react/client/index.d.ts +3 -3
  101. package/dist/react/{customer-CbcVyRCQ.d.ts → customer-CaGJEN5J.d.ts} +1 -1
  102. package/dist/react/{customer-BYYt9N1h.d.mts → customer-DB8vL_m7.d.mts} +1 -1
  103. package/dist/react/hooks/index.d.mts +3 -3
  104. package/dist/react/hooks/index.d.ts +3 -3
  105. package/dist/react/hooks/index.js +16 -16
  106. package/dist/react/hooks/index.mjs +8 -8
  107. package/dist/react/hooks/internal/check/balanceToAllowed.d.mts +2 -2
  108. package/dist/react/hooks/internal/check/balanceToAllowed.d.ts +2 -2
  109. package/dist/react/hooks/internal/check/customerToFeatures.d.mts +2 -2
  110. package/dist/react/hooks/internal/check/customerToFeatures.d.ts +2 -2
  111. package/dist/react/hooks/internal/check/findCreditSystemsByFeature.d.mts +2 -2
  112. package/dist/react/hooks/internal/check/findCreditSystemsByFeature.d.ts +2 -2
  113. package/dist/react/hooks/internal/check/getCreditCost.d.mts +2 -2
  114. package/dist/react/hooks/internal/check/getCreditCost.d.ts +2 -2
  115. package/dist/react/hooks/internal/getLocalCheckResponse.d.mts +3 -3
  116. package/dist/react/hooks/internal/getLocalCheckResponse.d.ts +3 -3
  117. package/dist/react/hooks/internal/useCustomerActions.d.mts +3 -3
  118. package/dist/react/hooks/internal/useCustomerActions.d.ts +3 -3
  119. package/dist/react/hooks/internal/useCustomerActions.js +1 -1
  120. package/dist/react/hooks/internal/useCustomerActions.mjs +2 -2
  121. package/dist/react/hooks/useAggregateEvents.d.mts +2 -2
  122. package/dist/react/hooks/useAggregateEvents.d.ts +2 -2
  123. package/dist/react/hooks/useAggregateEvents.js +16 -16
  124. package/dist/react/hooks/useAggregateEvents.mjs +2 -2
  125. package/dist/react/hooks/useCustomer.d.mts +3 -3
  126. package/dist/react/hooks/useCustomer.d.ts +3 -3
  127. package/dist/react/hooks/useCustomer.js +16 -16
  128. package/dist/react/hooks/useCustomer.mjs +3 -3
  129. package/dist/react/hooks/useEntity.d.mts +2 -2
  130. package/dist/react/hooks/useEntity.d.ts +2 -2
  131. package/dist/react/hooks/useEntity.js +16 -16
  132. package/dist/react/hooks/useEntity.mjs +2 -2
  133. package/dist/react/hooks/useListEvents.d.mts +2 -2
  134. package/dist/react/hooks/useListEvents.d.ts +2 -2
  135. package/dist/react/hooks/useListEvents.js +16 -16
  136. package/dist/react/hooks/useListEvents.mjs +2 -2
  137. package/dist/react/hooks/useListPlans.d.mts +2 -2
  138. package/dist/react/hooks/useListPlans.d.ts +2 -2
  139. package/dist/react/hooks/useListPlans.js +16 -16
  140. package/dist/react/hooks/useListPlans.mjs +2 -2
  141. package/dist/react/hooks/useReferrals.d.mts +2 -2
  142. package/dist/react/hooks/useReferrals.d.ts +2 -2
  143. package/dist/react/hooks/useReferrals.js +16 -16
  144. package/dist/react/hooks/useReferrals.mjs +2 -2
  145. package/dist/react/index.d.mts +3 -3
  146. package/dist/react/index.d.ts +3 -3
  147. package/dist/react/index.js +22 -22
  148. package/dist/react/index.mjs +9 -9
  149. package/dist/react/{params-By0MIRsJ.d.ts → params-B5l9vHfZ.d.ts} +1 -1
  150. package/dist/react/{params-CUb0ZlUG.d.mts → params-BVglT8vT.d.mts} +1 -1
  151. package/dist/react/{plan-CqxFGNk2.d.mts → plan-DSTBzzTY.d.mts} +13 -0
  152. package/dist/react/{plan-CqxFGNk2.d.ts → plan-DSTBzzTY.d.ts} +13 -0
  153. package/dist/sdk/index.d.mts +125 -1
  154. package/dist/sdk/index.d.ts +125 -1
  155. package/dist/sdk/index.js +146 -4
  156. package/dist/sdk/index.mjs +133 -5
  157. package/package.json +1 -1
  158. package/dist/better-auth/createAutumnEndpoint-D9Plymvy.d.mts +0 -309
  159. package/dist/better-auth/createAutumnEndpoint-D9Plymvy.d.ts +0 -309
@@ -1,309 +0,0 @@
1
- import { StandardSchemaV1 } from './standard-schema.mjs';
2
- import { APIError } from './error.mjs';
3
- import { InputContext } from './context.mjs';
4
- import { Middleware } from './middleware.mjs';
5
- import { OpenAPIParameter, OpenAPISchemaType } from './openapi.mjs';
6
- import * as zod from 'zod';
7
- import * as z from 'zod/v4/core';
8
-
9
- /** All supported route names as const for type safety */
10
- declare const ROUTE_NAMES: {
11
- readonly getOrCreateCustomer: "getOrCreateCustomer";
12
- readonly getEntity: "getEntity";
13
- readonly attach: "attach";
14
- readonly previewAttach: "previewAttach";
15
- readonly updateSubscription: "updateSubscription";
16
- readonly previewUpdateSubscription: "previewUpdateSubscription";
17
- readonly openCustomerPortal: "openCustomerPortal";
18
- readonly createReferralCode: "createReferralCode";
19
- readonly redeemReferralCode: "redeemReferralCode";
20
- readonly listPlans: "listPlans";
21
- readonly listEvents: "listEvents";
22
- readonly aggregateEvents: "aggregateEvents";
23
- readonly multiAttach: "multiAttach";
24
- readonly previewMultiAttach: "previewMultiAttach";
25
- readonly setupPayment: "setupPayment";
26
- };
27
- /** Union of all route names */
28
- type RouteName = keyof typeof ROUTE_NAMES;
29
-
30
- //#region src/endpoint.d.ts
31
- interface EndpointBaseOptions {
32
- /**
33
- * Query Schema
34
- */
35
- query?: StandardSchemaV1;
36
- /**
37
- * Error Schema
38
- */
39
- error?: StandardSchemaV1;
40
- /**
41
- * If true headers will be required to be passed in the context
42
- */
43
- requireHeaders?: boolean;
44
- /**
45
- * If true request object will be required
46
- */
47
- requireRequest?: boolean;
48
- /**
49
- * Clone the request object from the router
50
- */
51
- cloneRequest?: boolean;
52
- /**
53
- * If true the body will be undefined
54
- */
55
- disableBody?: boolean;
56
- /**
57
- * Endpoint metadata
58
- */
59
- metadata?: {
60
- /**
61
- * Open API definition
62
- */
63
- openapi?: {
64
- summary?: string;
65
- description?: string;
66
- tags?: string[];
67
- operationId?: string;
68
- parameters?: OpenAPIParameter[];
69
- requestBody?: {
70
- content: {
71
- "application/json": {
72
- schema: {
73
- type?: OpenAPISchemaType;
74
- properties?: Record<string, any>;
75
- required?: string[];
76
- $ref?: string;
77
- };
78
- };
79
- };
80
- };
81
- responses?: {
82
- [status: string]: {
83
- description: string;
84
- content?: {
85
- "application/json"?: {
86
- schema: {
87
- type?: OpenAPISchemaType;
88
- properties?: Record<string, any>;
89
- required?: string[];
90
- $ref?: string;
91
- };
92
- };
93
- "text/plain"?: {
94
- schema?: {
95
- type?: OpenAPISchemaType;
96
- properties?: Record<string, any>;
97
- required?: string[];
98
- $ref?: string;
99
- };
100
- };
101
- "text/html"?: {
102
- schema?: {
103
- type?: OpenAPISchemaType;
104
- properties?: Record<string, any>;
105
- required?: string[];
106
- $ref?: string;
107
- };
108
- };
109
- };
110
- };
111
- };
112
- };
113
- /**
114
- * Infer body and query type from ts interface
115
- *
116
- * useful for generic and dynamic types
117
- *
118
- * @example
119
- * ```ts
120
- * const endpoint = createEndpoint("/path", {
121
- * method: "POST",
122
- * body: z.record(z.string()),
123
- * $Infer: {
124
- * body: {} as {
125
- * type: InferTypeFromOptions<Option> // custom type inference
126
- * }
127
- * }
128
- * }, async(ctx)=>{
129
- * const body = ctx.body
130
- * })
131
- * ```
132
- */
133
- $Infer?: {
134
- /**
135
- * Body
136
- */
137
- body?: any;
138
- /**
139
- * Query
140
- */
141
- query?: Record<string, any>;
142
- };
143
- /**
144
- * If enabled, endpoint won't be exposed over a router
145
- * @deprecated Use path-less endpoints instead
146
- */
147
- SERVER_ONLY?: boolean;
148
- /**
149
- * If enabled, endpoint won't be exposed as an action to the client
150
- * @deprecated Use path-less endpoints instead
151
- */
152
- isAction?: boolean;
153
- /**
154
- * Defines the places where the endpoint will be available
155
- *
156
- * Possible options:
157
- * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
158
- * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
159
- * - `http` - the endpoint is only exposed to the router
160
- * @default "rpc"
161
- */
162
- scope?: "rpc" | "server" | "http";
163
- /**
164
- * List of allowed media types (MIME types) for the endpoint
165
- *
166
- * if provided, only the media types in the list will be allowed to be passed in the body
167
- *
168
- * @example
169
- * ```ts
170
- * const endpoint = createEndpoint("/path", {
171
- * method: "POST",
172
- * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
173
- * }, async(ctx)=>{
174
- * const body = ctx.body
175
- * })
176
- * ```
177
- */
178
- allowedMediaTypes?: string[];
179
- /**
180
- * Extra metadata
181
- */
182
- [key: string]: any;
183
- };
184
- /**
185
- * List of middlewares to use
186
- */
187
- use?: Middleware[];
188
- /**
189
- * A callback to run before any API error is throw or returned
190
- *
191
- * @param e - The API error
192
- * @returns - The response to return
193
- */
194
- onAPIError?: (e: APIError) => void | Promise<void>;
195
- /**
196
- * A callback to run before a validation error is thrown
197
- * You can customize the validation error message by throwing your own APIError
198
- */
199
- onValidationError?: ({
200
- issues,
201
- message
202
- }: {
203
- message: string;
204
- issues: readonly StandardSchemaV1.Issue[];
205
- }) => void | Promise<void>;
206
- }
207
- type EndpointBodyMethodOptions = {
208
- /**
209
- * Request Method
210
- */
211
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
212
- /**
213
- * Body Schema
214
- */
215
- body?: StandardSchemaV1;
216
- } | {
217
- /**
218
- * Request Method
219
- */
220
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
221
- /**
222
- * Body Schema
223
- */
224
- body?: never;
225
- } | {
226
- /**
227
- * Request Method
228
- */
229
- method: "*";
230
- /**
231
- * Body Schema
232
- */
233
- body?: StandardSchemaV1;
234
- } | {
235
- /**
236
- * Request Method
237
- */
238
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
239
- /**
240
- * Body Schema
241
- */
242
- body?: StandardSchemaV1;
243
- };
244
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
245
- type StrictEndpoint<Path extends string, Options extends EndpointOptions, R = any> = {
246
- (context: InputContext<Path, Options> & {
247
- asResponse: true;
248
- }): Promise<Response>;
249
- (context: InputContext<Path, Options> & {
250
- returnHeaders: true;
251
- returnStatus: true;
252
- }): Promise<{
253
- headers: Headers;
254
- status: number;
255
- response: Awaited<R>;
256
- }>;
257
- (context: InputContext<Path, Options> & {
258
- returnHeaders: true;
259
- returnStatus: false;
260
- }): Promise<{
261
- headers: Headers;
262
- response: Awaited<R>;
263
- }>;
264
- (context: InputContext<Path, Options> & {
265
- returnHeaders: false;
266
- returnStatus: true;
267
- }): Promise<{
268
- status: number;
269
- response: Awaited<R>;
270
- }>;
271
- (context: InputContext<Path, Options> & {
272
- returnHeaders: false;
273
- returnStatus: false;
274
- }): Promise<R>;
275
- (context: InputContext<Path, Options> & {
276
- returnHeaders: true;
277
- }): Promise<{
278
- headers: Headers;
279
- response: Awaited<R>;
280
- }>;
281
- (context: InputContext<Path, Options> & {
282
- returnStatus: true;
283
- }): Promise<{
284
- status: number;
285
- response: Awaited<R>;
286
- }>;
287
- (context?: InputContext<Path, Options>): Promise<R>;
288
- options: Options;
289
- path: Path;
290
- };//# sourceMappingURL=endpoint.d.mts.map
291
-
292
- /** Type for the handleRoute function used by better-auth endpoints */
293
- type HandleBetterAuthRouteFn = (args: {
294
- ctx: unknown;
295
- routeName: RouteName;
296
- }) => Promise<{
297
- status: number;
298
- body: unknown;
299
- }>;
300
- /**
301
- * Creates a better-auth endpoint for a given route name.
302
- * Each route needs its own call to preserve TypeScript literal types for the path.
303
- */
304
- declare const createAutumnEndpoint: <T extends RouteName>(routeName: T, handleRoute: HandleBetterAuthRouteFn) => StrictEndpoint<`/autumn/${T}`, {
305
- method: "POST";
306
- body: zod.ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>> | undefined;
307
- }, Record<string, unknown> | null>;
308
-
309
- export { type HandleBetterAuthRouteFn as H, type RouteName as R, createAutumnEndpoint as c };
@@ -1,309 +0,0 @@
1
- import { StandardSchemaV1 } from './standard-schema.mjs';
2
- import { APIError } from './error.mjs';
3
- import { InputContext } from './context.mjs';
4
- import { Middleware } from './middleware.mjs';
5
- import { OpenAPIParameter, OpenAPISchemaType } from './openapi.mjs';
6
- import * as zod from 'zod';
7
- import * as z from 'zod/v4/core';
8
-
9
- /** All supported route names as const for type safety */
10
- declare const ROUTE_NAMES: {
11
- readonly getOrCreateCustomer: "getOrCreateCustomer";
12
- readonly getEntity: "getEntity";
13
- readonly attach: "attach";
14
- readonly previewAttach: "previewAttach";
15
- readonly updateSubscription: "updateSubscription";
16
- readonly previewUpdateSubscription: "previewUpdateSubscription";
17
- readonly openCustomerPortal: "openCustomerPortal";
18
- readonly createReferralCode: "createReferralCode";
19
- readonly redeemReferralCode: "redeemReferralCode";
20
- readonly listPlans: "listPlans";
21
- readonly listEvents: "listEvents";
22
- readonly aggregateEvents: "aggregateEvents";
23
- readonly multiAttach: "multiAttach";
24
- readonly previewMultiAttach: "previewMultiAttach";
25
- readonly setupPayment: "setupPayment";
26
- };
27
- /** Union of all route names */
28
- type RouteName = keyof typeof ROUTE_NAMES;
29
-
30
- //#region src/endpoint.d.ts
31
- interface EndpointBaseOptions {
32
- /**
33
- * Query Schema
34
- */
35
- query?: StandardSchemaV1;
36
- /**
37
- * Error Schema
38
- */
39
- error?: StandardSchemaV1;
40
- /**
41
- * If true headers will be required to be passed in the context
42
- */
43
- requireHeaders?: boolean;
44
- /**
45
- * If true request object will be required
46
- */
47
- requireRequest?: boolean;
48
- /**
49
- * Clone the request object from the router
50
- */
51
- cloneRequest?: boolean;
52
- /**
53
- * If true the body will be undefined
54
- */
55
- disableBody?: boolean;
56
- /**
57
- * Endpoint metadata
58
- */
59
- metadata?: {
60
- /**
61
- * Open API definition
62
- */
63
- openapi?: {
64
- summary?: string;
65
- description?: string;
66
- tags?: string[];
67
- operationId?: string;
68
- parameters?: OpenAPIParameter[];
69
- requestBody?: {
70
- content: {
71
- "application/json": {
72
- schema: {
73
- type?: OpenAPISchemaType;
74
- properties?: Record<string, any>;
75
- required?: string[];
76
- $ref?: string;
77
- };
78
- };
79
- };
80
- };
81
- responses?: {
82
- [status: string]: {
83
- description: string;
84
- content?: {
85
- "application/json"?: {
86
- schema: {
87
- type?: OpenAPISchemaType;
88
- properties?: Record<string, any>;
89
- required?: string[];
90
- $ref?: string;
91
- };
92
- };
93
- "text/plain"?: {
94
- schema?: {
95
- type?: OpenAPISchemaType;
96
- properties?: Record<string, any>;
97
- required?: string[];
98
- $ref?: string;
99
- };
100
- };
101
- "text/html"?: {
102
- schema?: {
103
- type?: OpenAPISchemaType;
104
- properties?: Record<string, any>;
105
- required?: string[];
106
- $ref?: string;
107
- };
108
- };
109
- };
110
- };
111
- };
112
- };
113
- /**
114
- * Infer body and query type from ts interface
115
- *
116
- * useful for generic and dynamic types
117
- *
118
- * @example
119
- * ```ts
120
- * const endpoint = createEndpoint("/path", {
121
- * method: "POST",
122
- * body: z.record(z.string()),
123
- * $Infer: {
124
- * body: {} as {
125
- * type: InferTypeFromOptions<Option> // custom type inference
126
- * }
127
- * }
128
- * }, async(ctx)=>{
129
- * const body = ctx.body
130
- * })
131
- * ```
132
- */
133
- $Infer?: {
134
- /**
135
- * Body
136
- */
137
- body?: any;
138
- /**
139
- * Query
140
- */
141
- query?: Record<string, any>;
142
- };
143
- /**
144
- * If enabled, endpoint won't be exposed over a router
145
- * @deprecated Use path-less endpoints instead
146
- */
147
- SERVER_ONLY?: boolean;
148
- /**
149
- * If enabled, endpoint won't be exposed as an action to the client
150
- * @deprecated Use path-less endpoints instead
151
- */
152
- isAction?: boolean;
153
- /**
154
- * Defines the places where the endpoint will be available
155
- *
156
- * Possible options:
157
- * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
158
- * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
159
- * - `http` - the endpoint is only exposed to the router
160
- * @default "rpc"
161
- */
162
- scope?: "rpc" | "server" | "http";
163
- /**
164
- * List of allowed media types (MIME types) for the endpoint
165
- *
166
- * if provided, only the media types in the list will be allowed to be passed in the body
167
- *
168
- * @example
169
- * ```ts
170
- * const endpoint = createEndpoint("/path", {
171
- * method: "POST",
172
- * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
173
- * }, async(ctx)=>{
174
- * const body = ctx.body
175
- * })
176
- * ```
177
- */
178
- allowedMediaTypes?: string[];
179
- /**
180
- * Extra metadata
181
- */
182
- [key: string]: any;
183
- };
184
- /**
185
- * List of middlewares to use
186
- */
187
- use?: Middleware[];
188
- /**
189
- * A callback to run before any API error is throw or returned
190
- *
191
- * @param e - The API error
192
- * @returns - The response to return
193
- */
194
- onAPIError?: (e: APIError) => void | Promise<void>;
195
- /**
196
- * A callback to run before a validation error is thrown
197
- * You can customize the validation error message by throwing your own APIError
198
- */
199
- onValidationError?: ({
200
- issues,
201
- message
202
- }: {
203
- message: string;
204
- issues: readonly StandardSchemaV1.Issue[];
205
- }) => void | Promise<void>;
206
- }
207
- type EndpointBodyMethodOptions = {
208
- /**
209
- * Request Method
210
- */
211
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
212
- /**
213
- * Body Schema
214
- */
215
- body?: StandardSchemaV1;
216
- } | {
217
- /**
218
- * Request Method
219
- */
220
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
221
- /**
222
- * Body Schema
223
- */
224
- body?: never;
225
- } | {
226
- /**
227
- * Request Method
228
- */
229
- method: "*";
230
- /**
231
- * Body Schema
232
- */
233
- body?: StandardSchemaV1;
234
- } | {
235
- /**
236
- * Request Method
237
- */
238
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
239
- /**
240
- * Body Schema
241
- */
242
- body?: StandardSchemaV1;
243
- };
244
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
245
- type StrictEndpoint<Path extends string, Options extends EndpointOptions, R = any> = {
246
- (context: InputContext<Path, Options> & {
247
- asResponse: true;
248
- }): Promise<Response>;
249
- (context: InputContext<Path, Options> & {
250
- returnHeaders: true;
251
- returnStatus: true;
252
- }): Promise<{
253
- headers: Headers;
254
- status: number;
255
- response: Awaited<R>;
256
- }>;
257
- (context: InputContext<Path, Options> & {
258
- returnHeaders: true;
259
- returnStatus: false;
260
- }): Promise<{
261
- headers: Headers;
262
- response: Awaited<R>;
263
- }>;
264
- (context: InputContext<Path, Options> & {
265
- returnHeaders: false;
266
- returnStatus: true;
267
- }): Promise<{
268
- status: number;
269
- response: Awaited<R>;
270
- }>;
271
- (context: InputContext<Path, Options> & {
272
- returnHeaders: false;
273
- returnStatus: false;
274
- }): Promise<R>;
275
- (context: InputContext<Path, Options> & {
276
- returnHeaders: true;
277
- }): Promise<{
278
- headers: Headers;
279
- response: Awaited<R>;
280
- }>;
281
- (context: InputContext<Path, Options> & {
282
- returnStatus: true;
283
- }): Promise<{
284
- status: number;
285
- response: Awaited<R>;
286
- }>;
287
- (context?: InputContext<Path, Options>): Promise<R>;
288
- options: Options;
289
- path: Path;
290
- };//# sourceMappingURL=endpoint.d.mts.map
291
-
292
- /** Type for the handleRoute function used by better-auth endpoints */
293
- type HandleBetterAuthRouteFn = (args: {
294
- ctx: unknown;
295
- routeName: RouteName;
296
- }) => Promise<{
297
- status: number;
298
- body: unknown;
299
- }>;
300
- /**
301
- * Creates a better-auth endpoint for a given route name.
302
- * Each route needs its own call to preserve TypeScript literal types for the path.
303
- */
304
- declare const createAutumnEndpoint: <T extends RouteName>(routeName: T, handleRoute: HandleBetterAuthRouteFn) => StrictEndpoint<`/autumn/${T}`, {
305
- method: "POST";
306
- body: zod.ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>> | undefined;
307
- }, Record<string, unknown> | null>;
308
-
309
- export { type HandleBetterAuthRouteFn as H, type RouteName as R, createAutumnEndpoint as c };