better-inbox 0.0.1 → 0.1.0

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.
@@ -0,0 +1,291 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { InferOptionSchema } from 'better-auth';
3
+ import * as better_call from 'better-call';
4
+ import * as zod_v4_core from 'zod/v4/core';
5
+ import * as zod from 'zod';
6
+
7
+ declare const schema: {
8
+ notification: {
9
+ fields: {
10
+ userId: {
11
+ type: "string";
12
+ required: true;
13
+ references: {
14
+ model: string;
15
+ field: string;
16
+ };
17
+ };
18
+ organizationId: {
19
+ type: "string";
20
+ required: false;
21
+ };
22
+ type: {
23
+ type: "string";
24
+ required: true;
25
+ };
26
+ title: {
27
+ type: "string";
28
+ required: true;
29
+ };
30
+ body: {
31
+ type: "string";
32
+ required: false;
33
+ };
34
+ href: {
35
+ type: "string";
36
+ required: false;
37
+ };
38
+ data: {
39
+ type: "json";
40
+ required: false;
41
+ };
42
+ read: {
43
+ type: "boolean";
44
+ required: true;
45
+ defaultValue: false;
46
+ };
47
+ createdAt: {
48
+ type: "date";
49
+ required: true;
50
+ };
51
+ };
52
+ };
53
+ };
54
+ type Notification = {
55
+ id: string;
56
+ userId: string;
57
+ organizationId?: string | null;
58
+ type: string;
59
+ title: string;
60
+ body?: string | null;
61
+ href?: string | null;
62
+ data?: Record<string, unknown> | null;
63
+ read: boolean;
64
+ createdAt: Date;
65
+ };
66
+
67
+ declare const INBOX_ERROR_CODES: {
68
+ NOTIFICATION_NOT_FOUND: better_auth.RawError<"NOTIFICATION_NOT_FOUND">;
69
+ USER_OR_ORGANIZATION_REQUIRED: better_auth.RawError<"USER_OR_ORGANIZATION_REQUIRED">;
70
+ ORGANIZATION_PLUGIN_REQUIRED: better_auth.RawError<"ORGANIZATION_PLUGIN_REQUIRED">;
71
+ ORGANIZATION_HAS_NO_MEMBERS: better_auth.RawError<"ORGANIZATION_HAS_NO_MEMBERS">;
72
+ FAN_OUT_LIMIT_EXCEEDED: better_auth.RawError<"FAN_OUT_LIMIT_EXCEEDED">;
73
+ };
74
+
75
+ type InboxOptions = {
76
+ /**
77
+ * Maximum number of members an organization notify may fan out to.
78
+ * @default 1000
79
+ */
80
+ maxFanout?: number;
81
+ schema?: InferOptionSchema<typeof schema>;
82
+ };
83
+ declare const inbox: (options?: InboxOptions) => {
84
+ id: "inbox";
85
+ schema: {
86
+ notification: {
87
+ fields: {
88
+ userId: {
89
+ type: "string";
90
+ required: true;
91
+ references: {
92
+ model: string;
93
+ field: string;
94
+ };
95
+ };
96
+ organizationId: {
97
+ type: "string";
98
+ required: false;
99
+ };
100
+ type: {
101
+ type: "string";
102
+ required: true;
103
+ };
104
+ title: {
105
+ type: "string";
106
+ required: true;
107
+ };
108
+ body: {
109
+ type: "string";
110
+ required: false;
111
+ };
112
+ href: {
113
+ type: "string";
114
+ required: false;
115
+ };
116
+ data: {
117
+ type: "json";
118
+ required: false;
119
+ };
120
+ read: {
121
+ type: "boolean";
122
+ required: true;
123
+ defaultValue: false;
124
+ };
125
+ createdAt: {
126
+ type: "date";
127
+ required: true;
128
+ };
129
+ };
130
+ };
131
+ };
132
+ endpoints: {
133
+ notify: better_call.StrictEndpoint<string, {
134
+ method: "POST";
135
+ body: zod.ZodObject<{
136
+ userId: zod.ZodOptional<zod.ZodString>;
137
+ organizationId: zod.ZodOptional<zod.ZodString>;
138
+ roles: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
139
+ type: zod.ZodString;
140
+ title: zod.ZodString;
141
+ body: zod.ZodOptional<zod.ZodString>;
142
+ href: zod.ZodOptional<zod.ZodString>;
143
+ data: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
144
+ }, zod_v4_core.$strip>;
145
+ }, {
146
+ count: number;
147
+ notifications: Notification[];
148
+ }>;
149
+ listNotifications: better_call.StrictEndpoint<"/inbox/list", {
150
+ method: "GET";
151
+ query: zod.ZodOptional<zod.ZodObject<{
152
+ filter: zod.ZodOptional<zod.ZodEnum<{
153
+ unread: "unread";
154
+ all: "all";
155
+ }>>;
156
+ limit: zod.ZodOptional<zod.ZodCoercedNumber<unknown>>;
157
+ offset: zod.ZodOptional<zod.ZodCoercedNumber<unknown>>;
158
+ organizationId: zod.ZodOptional<zod.ZodString>;
159
+ }, zod_v4_core.$strip>>;
160
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
161
+ session: {
162
+ session: Record<string, any> & {
163
+ id: string;
164
+ createdAt: Date;
165
+ updatedAt: Date;
166
+ userId: string;
167
+ expiresAt: Date;
168
+ token: string;
169
+ ipAddress?: string | null | undefined;
170
+ userAgent?: string | null | undefined;
171
+ };
172
+ user: Record<string, any> & {
173
+ id: string;
174
+ createdAt: Date;
175
+ updatedAt: Date;
176
+ email: string;
177
+ emailVerified: boolean;
178
+ name: string;
179
+ image?: string | null | undefined;
180
+ };
181
+ };
182
+ }>)[];
183
+ }, {
184
+ notifications: Notification[];
185
+ hasMore: boolean;
186
+ }>;
187
+ markRead: better_call.StrictEndpoint<"/inbox/mark-read", {
188
+ method: "POST";
189
+ body: zod.ZodObject<{
190
+ id: zod.ZodString;
191
+ }, zod_v4_core.$strip>;
192
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
193
+ session: {
194
+ session: Record<string, any> & {
195
+ id: string;
196
+ createdAt: Date;
197
+ updatedAt: Date;
198
+ userId: string;
199
+ expiresAt: Date;
200
+ token: string;
201
+ ipAddress?: string | null | undefined;
202
+ userAgent?: string | null | undefined;
203
+ };
204
+ user: Record<string, any> & {
205
+ id: string;
206
+ createdAt: Date;
207
+ updatedAt: Date;
208
+ email: string;
209
+ emailVerified: boolean;
210
+ name: string;
211
+ image?: string | null | undefined;
212
+ };
213
+ };
214
+ }>)[];
215
+ }, {
216
+ notification: Notification;
217
+ }>;
218
+ markAllRead: better_call.StrictEndpoint<"/inbox/mark-all-read", {
219
+ method: "POST";
220
+ body: zod.ZodObject<{
221
+ organizationId: zod.ZodOptional<zod.ZodString>;
222
+ }, zod_v4_core.$strip>;
223
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
224
+ session: {
225
+ session: Record<string, any> & {
226
+ id: string;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+ userId: string;
230
+ expiresAt: Date;
231
+ token: string;
232
+ ipAddress?: string | null | undefined;
233
+ userAgent?: string | null | undefined;
234
+ };
235
+ user: Record<string, any> & {
236
+ id: string;
237
+ createdAt: Date;
238
+ updatedAt: Date;
239
+ email: string;
240
+ emailVerified: boolean;
241
+ name: string;
242
+ image?: string | null | undefined;
243
+ };
244
+ };
245
+ }>)[];
246
+ }, {
247
+ count: number;
248
+ }>;
249
+ unreadCount: better_call.StrictEndpoint<"/inbox/unread-count", {
250
+ method: "GET";
251
+ query: zod.ZodOptional<zod.ZodObject<{
252
+ organizationId: zod.ZodOptional<zod.ZodString>;
253
+ }, zod_v4_core.$strip>>;
254
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
255
+ session: {
256
+ session: Record<string, any> & {
257
+ id: string;
258
+ createdAt: Date;
259
+ updatedAt: Date;
260
+ userId: string;
261
+ expiresAt: Date;
262
+ token: string;
263
+ ipAddress?: string | null | undefined;
264
+ userAgent?: string | null | undefined;
265
+ };
266
+ user: Record<string, any> & {
267
+ id: string;
268
+ createdAt: Date;
269
+ updatedAt: Date;
270
+ email: string;
271
+ emailVerified: boolean;
272
+ name: string;
273
+ image?: string | null | undefined;
274
+ };
275
+ };
276
+ }>)[];
277
+ }, {
278
+ count: number;
279
+ }>;
280
+ };
281
+ $ERROR_CODES: {
282
+ NOTIFICATION_NOT_FOUND: better_auth.RawError<"NOTIFICATION_NOT_FOUND">;
283
+ USER_OR_ORGANIZATION_REQUIRED: better_auth.RawError<"USER_OR_ORGANIZATION_REQUIRED">;
284
+ ORGANIZATION_PLUGIN_REQUIRED: better_auth.RawError<"ORGANIZATION_PLUGIN_REQUIRED">;
285
+ ORGANIZATION_HAS_NO_MEMBERS: better_auth.RawError<"ORGANIZATION_HAS_NO_MEMBERS">;
286
+ FAN_OUT_LIMIT_EXCEEDED: better_auth.RawError<"FAN_OUT_LIMIT_EXCEEDED">;
287
+ };
288
+ options: InboxOptions;
289
+ };
290
+
291
+ export { INBOX_ERROR_CODES, type InboxOptions, type Notification, inbox };
@@ -0,0 +1,291 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { InferOptionSchema } from 'better-auth';
3
+ import * as better_call from 'better-call';
4
+ import * as zod_v4_core from 'zod/v4/core';
5
+ import * as zod from 'zod';
6
+
7
+ declare const schema: {
8
+ notification: {
9
+ fields: {
10
+ userId: {
11
+ type: "string";
12
+ required: true;
13
+ references: {
14
+ model: string;
15
+ field: string;
16
+ };
17
+ };
18
+ organizationId: {
19
+ type: "string";
20
+ required: false;
21
+ };
22
+ type: {
23
+ type: "string";
24
+ required: true;
25
+ };
26
+ title: {
27
+ type: "string";
28
+ required: true;
29
+ };
30
+ body: {
31
+ type: "string";
32
+ required: false;
33
+ };
34
+ href: {
35
+ type: "string";
36
+ required: false;
37
+ };
38
+ data: {
39
+ type: "json";
40
+ required: false;
41
+ };
42
+ read: {
43
+ type: "boolean";
44
+ required: true;
45
+ defaultValue: false;
46
+ };
47
+ createdAt: {
48
+ type: "date";
49
+ required: true;
50
+ };
51
+ };
52
+ };
53
+ };
54
+ type Notification = {
55
+ id: string;
56
+ userId: string;
57
+ organizationId?: string | null;
58
+ type: string;
59
+ title: string;
60
+ body?: string | null;
61
+ href?: string | null;
62
+ data?: Record<string, unknown> | null;
63
+ read: boolean;
64
+ createdAt: Date;
65
+ };
66
+
67
+ declare const INBOX_ERROR_CODES: {
68
+ NOTIFICATION_NOT_FOUND: better_auth.RawError<"NOTIFICATION_NOT_FOUND">;
69
+ USER_OR_ORGANIZATION_REQUIRED: better_auth.RawError<"USER_OR_ORGANIZATION_REQUIRED">;
70
+ ORGANIZATION_PLUGIN_REQUIRED: better_auth.RawError<"ORGANIZATION_PLUGIN_REQUIRED">;
71
+ ORGANIZATION_HAS_NO_MEMBERS: better_auth.RawError<"ORGANIZATION_HAS_NO_MEMBERS">;
72
+ FAN_OUT_LIMIT_EXCEEDED: better_auth.RawError<"FAN_OUT_LIMIT_EXCEEDED">;
73
+ };
74
+
75
+ type InboxOptions = {
76
+ /**
77
+ * Maximum number of members an organization notify may fan out to.
78
+ * @default 1000
79
+ */
80
+ maxFanout?: number;
81
+ schema?: InferOptionSchema<typeof schema>;
82
+ };
83
+ declare const inbox: (options?: InboxOptions) => {
84
+ id: "inbox";
85
+ schema: {
86
+ notification: {
87
+ fields: {
88
+ userId: {
89
+ type: "string";
90
+ required: true;
91
+ references: {
92
+ model: string;
93
+ field: string;
94
+ };
95
+ };
96
+ organizationId: {
97
+ type: "string";
98
+ required: false;
99
+ };
100
+ type: {
101
+ type: "string";
102
+ required: true;
103
+ };
104
+ title: {
105
+ type: "string";
106
+ required: true;
107
+ };
108
+ body: {
109
+ type: "string";
110
+ required: false;
111
+ };
112
+ href: {
113
+ type: "string";
114
+ required: false;
115
+ };
116
+ data: {
117
+ type: "json";
118
+ required: false;
119
+ };
120
+ read: {
121
+ type: "boolean";
122
+ required: true;
123
+ defaultValue: false;
124
+ };
125
+ createdAt: {
126
+ type: "date";
127
+ required: true;
128
+ };
129
+ };
130
+ };
131
+ };
132
+ endpoints: {
133
+ notify: better_call.StrictEndpoint<string, {
134
+ method: "POST";
135
+ body: zod.ZodObject<{
136
+ userId: zod.ZodOptional<zod.ZodString>;
137
+ organizationId: zod.ZodOptional<zod.ZodString>;
138
+ roles: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
139
+ type: zod.ZodString;
140
+ title: zod.ZodString;
141
+ body: zod.ZodOptional<zod.ZodString>;
142
+ href: zod.ZodOptional<zod.ZodString>;
143
+ data: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
144
+ }, zod_v4_core.$strip>;
145
+ }, {
146
+ count: number;
147
+ notifications: Notification[];
148
+ }>;
149
+ listNotifications: better_call.StrictEndpoint<"/inbox/list", {
150
+ method: "GET";
151
+ query: zod.ZodOptional<zod.ZodObject<{
152
+ filter: zod.ZodOptional<zod.ZodEnum<{
153
+ unread: "unread";
154
+ all: "all";
155
+ }>>;
156
+ limit: zod.ZodOptional<zod.ZodCoercedNumber<unknown>>;
157
+ offset: zod.ZodOptional<zod.ZodCoercedNumber<unknown>>;
158
+ organizationId: zod.ZodOptional<zod.ZodString>;
159
+ }, zod_v4_core.$strip>>;
160
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
161
+ session: {
162
+ session: Record<string, any> & {
163
+ id: string;
164
+ createdAt: Date;
165
+ updatedAt: Date;
166
+ userId: string;
167
+ expiresAt: Date;
168
+ token: string;
169
+ ipAddress?: string | null | undefined;
170
+ userAgent?: string | null | undefined;
171
+ };
172
+ user: Record<string, any> & {
173
+ id: string;
174
+ createdAt: Date;
175
+ updatedAt: Date;
176
+ email: string;
177
+ emailVerified: boolean;
178
+ name: string;
179
+ image?: string | null | undefined;
180
+ };
181
+ };
182
+ }>)[];
183
+ }, {
184
+ notifications: Notification[];
185
+ hasMore: boolean;
186
+ }>;
187
+ markRead: better_call.StrictEndpoint<"/inbox/mark-read", {
188
+ method: "POST";
189
+ body: zod.ZodObject<{
190
+ id: zod.ZodString;
191
+ }, zod_v4_core.$strip>;
192
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
193
+ session: {
194
+ session: Record<string, any> & {
195
+ id: string;
196
+ createdAt: Date;
197
+ updatedAt: Date;
198
+ userId: string;
199
+ expiresAt: Date;
200
+ token: string;
201
+ ipAddress?: string | null | undefined;
202
+ userAgent?: string | null | undefined;
203
+ };
204
+ user: Record<string, any> & {
205
+ id: string;
206
+ createdAt: Date;
207
+ updatedAt: Date;
208
+ email: string;
209
+ emailVerified: boolean;
210
+ name: string;
211
+ image?: string | null | undefined;
212
+ };
213
+ };
214
+ }>)[];
215
+ }, {
216
+ notification: Notification;
217
+ }>;
218
+ markAllRead: better_call.StrictEndpoint<"/inbox/mark-all-read", {
219
+ method: "POST";
220
+ body: zod.ZodObject<{
221
+ organizationId: zod.ZodOptional<zod.ZodString>;
222
+ }, zod_v4_core.$strip>;
223
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
224
+ session: {
225
+ session: Record<string, any> & {
226
+ id: string;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+ userId: string;
230
+ expiresAt: Date;
231
+ token: string;
232
+ ipAddress?: string | null | undefined;
233
+ userAgent?: string | null | undefined;
234
+ };
235
+ user: Record<string, any> & {
236
+ id: string;
237
+ createdAt: Date;
238
+ updatedAt: Date;
239
+ email: string;
240
+ emailVerified: boolean;
241
+ name: string;
242
+ image?: string | null | undefined;
243
+ };
244
+ };
245
+ }>)[];
246
+ }, {
247
+ count: number;
248
+ }>;
249
+ unreadCount: better_call.StrictEndpoint<"/inbox/unread-count", {
250
+ method: "GET";
251
+ query: zod.ZodOptional<zod.ZodObject<{
252
+ organizationId: zod.ZodOptional<zod.ZodString>;
253
+ }, zod_v4_core.$strip>>;
254
+ use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
255
+ session: {
256
+ session: Record<string, any> & {
257
+ id: string;
258
+ createdAt: Date;
259
+ updatedAt: Date;
260
+ userId: string;
261
+ expiresAt: Date;
262
+ token: string;
263
+ ipAddress?: string | null | undefined;
264
+ userAgent?: string | null | undefined;
265
+ };
266
+ user: Record<string, any> & {
267
+ id: string;
268
+ createdAt: Date;
269
+ updatedAt: Date;
270
+ email: string;
271
+ emailVerified: boolean;
272
+ name: string;
273
+ image?: string | null | undefined;
274
+ };
275
+ };
276
+ }>)[];
277
+ }, {
278
+ count: number;
279
+ }>;
280
+ };
281
+ $ERROR_CODES: {
282
+ NOTIFICATION_NOT_FOUND: better_auth.RawError<"NOTIFICATION_NOT_FOUND">;
283
+ USER_OR_ORGANIZATION_REQUIRED: better_auth.RawError<"USER_OR_ORGANIZATION_REQUIRED">;
284
+ ORGANIZATION_PLUGIN_REQUIRED: better_auth.RawError<"ORGANIZATION_PLUGIN_REQUIRED">;
285
+ ORGANIZATION_HAS_NO_MEMBERS: better_auth.RawError<"ORGANIZATION_HAS_NO_MEMBERS">;
286
+ FAN_OUT_LIMIT_EXCEEDED: better_auth.RawError<"FAN_OUT_LIMIT_EXCEEDED">;
287
+ };
288
+ options: InboxOptions;
289
+ };
290
+
291
+ export { INBOX_ERROR_CODES, type InboxOptions, type Notification, inbox };