@somewhatintelligent/guestlist 0.0.1-beta.1783705886.297c5be

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/src/schema.ts ADDED
@@ -0,0 +1,538 @@
1
+ /**
2
+ * Query-layer table definitions for the packaged ops and the drizzle
3
+ * adapter mapping. NOT the source of DDL truth: migrations are
4
+ * consumer-owned, generated from the consumer's configured plugin set via
5
+ * better-auth's CLI (see ./codegen.ts). The pinned better-auth version
6
+ * range keeps these shapes aligned with what the CLI generates for the
7
+ * tables this package queries.
8
+ */
9
+ import { relations, sql } from "drizzle-orm";
10
+ import { sqliteTable, text, integer, index, uniqueIndex } from "drizzle-orm/sqlite-core";
11
+
12
+ export const user = sqliteTable("user", {
13
+ id: text("id").primaryKey(),
14
+ name: text("name").notNull(),
15
+ email: text("email").notNull().unique(),
16
+ emailVerified: integer("email_verified", { mode: "boolean" }).default(false).notNull(),
17
+ image: text("image"),
18
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
19
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
20
+ .notNull(),
21
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
22
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
23
+ .$onUpdate(() => /* @__PURE__ */ new Date())
24
+ .notNull(),
25
+ username: text("username").unique(),
26
+ displayUsername: text("display_username"),
27
+ role: text("role"),
28
+ banned: integer("banned", { mode: "boolean" }).default(false),
29
+ banReason: text("ban_reason"),
30
+ banExpires: integer("ban_expires", { mode: "timestamp_ms" }),
31
+ twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default(false),
32
+ // better-auth `stripe` plugin field (packages/auth/src/server.ts). Shipped
33
+ // now even though the plugin is dormant everywhere today — see
34
+ // Note: flipping
35
+ // STRIPE_SECRET_KEY on later must not require a schema migration.
36
+ stripeCustomerId: text("stripe_customer_id"),
37
+ });
38
+
39
+ export const session = sqliteTable(
40
+ "session",
41
+ {
42
+ id: text("id").primaryKey(),
43
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
44
+ token: text("token").notNull().unique(),
45
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
46
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
47
+ .notNull(),
48
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
49
+ .$onUpdate(() => /* @__PURE__ */ new Date())
50
+ .notNull(),
51
+ ipAddress: text("ip_address"),
52
+ userAgent: text("user_agent"),
53
+ userId: text("user_id")
54
+ .notNull()
55
+ .references(() => user.id, { onDelete: "cascade" }),
56
+ impersonatedBy: text("impersonated_by"),
57
+ activeOrganizationId: text("active_organization_id"),
58
+ },
59
+ (table) => [index("session_userId_idx").on(table.userId)],
60
+ );
61
+
62
+ export const account = sqliteTable(
63
+ "account",
64
+ {
65
+ id: text("id").primaryKey(),
66
+ accountId: text("account_id").notNull(),
67
+ providerId: text("provider_id").notNull(),
68
+ userId: text("user_id")
69
+ .notNull()
70
+ .references(() => user.id, { onDelete: "cascade" }),
71
+ accessToken: text("access_token"),
72
+ refreshToken: text("refresh_token"),
73
+ idToken: text("id_token"),
74
+ accessTokenExpiresAt: integer("access_token_expires_at", {
75
+ mode: "timestamp_ms",
76
+ }),
77
+ refreshTokenExpiresAt: integer("refresh_token_expires_at", {
78
+ mode: "timestamp_ms",
79
+ }),
80
+ scope: text("scope"),
81
+ password: text("password"),
82
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
83
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
84
+ .notNull(),
85
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
86
+ .$onUpdate(() => /* @__PURE__ */ new Date())
87
+ .notNull(),
88
+ },
89
+ (table) => [index("account_userId_idx").on(table.userId)],
90
+ );
91
+
92
+ export const verification = sqliteTable(
93
+ "verification",
94
+ {
95
+ id: text("id").primaryKey(),
96
+ identifier: text("identifier").notNull(),
97
+ value: text("value").notNull(),
98
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
99
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
100
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
101
+ .notNull(),
102
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
103
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
104
+ .$onUpdate(() => /* @__PURE__ */ new Date())
105
+ .notNull(),
106
+ },
107
+ (table) => [index("verification_identifier_idx").on(table.identifier)],
108
+ );
109
+
110
+ export const jwks = sqliteTable("jwks", {
111
+ id: text("id").primaryKey(),
112
+ publicKey: text("public_key").notNull(),
113
+ privateKey: text("private_key").notNull(),
114
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
115
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }),
116
+ });
117
+
118
+ export const twoFactor = sqliteTable(
119
+ "two_factor",
120
+ {
121
+ id: text("id").primaryKey(),
122
+ secret: text("secret").notNull(),
123
+ backupCodes: text("backup_codes").notNull(),
124
+ userId: text("user_id")
125
+ .notNull()
126
+ .references(() => user.id, { onDelete: "cascade" }),
127
+ verified: integer("verified", { mode: "boolean" }).default(true),
128
+ },
129
+ (table) => [
130
+ index("twoFactor_secret_idx").on(table.secret),
131
+ index("twoFactor_userId_idx").on(table.userId),
132
+ ],
133
+ );
134
+
135
+ export const passkey = sqliteTable(
136
+ "passkey",
137
+ {
138
+ id: text("id").primaryKey(),
139
+ name: text("name"),
140
+ publicKey: text("public_key").notNull(),
141
+ userId: text("user_id")
142
+ .notNull()
143
+ .references(() => user.id, { onDelete: "cascade" }),
144
+ credentialID: text("credential_id").notNull(),
145
+ counter: integer("counter").notNull(),
146
+ deviceType: text("device_type").notNull(),
147
+ backedUp: integer("backed_up", { mode: "boolean" }).notNull(),
148
+ transports: text("transports"),
149
+ createdAt: integer("created_at", { mode: "timestamp_ms" }),
150
+ aaguid: text("aaguid"),
151
+ },
152
+ (table) => [
153
+ index("passkey_userId_idx").on(table.userId),
154
+ index("passkey_credentialID_idx").on(table.credentialID),
155
+ ],
156
+ );
157
+
158
+ export const deviceCode = sqliteTable("device_code", {
159
+ id: text("id").primaryKey(),
160
+ deviceCode: text("device_code").notNull(),
161
+ userCode: text("user_code").notNull(),
162
+ userId: text("user_id"),
163
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
164
+ status: text("status").notNull(),
165
+ lastPolledAt: integer("last_polled_at", { mode: "timestamp_ms" }),
166
+ pollingInterval: integer("polling_interval"),
167
+ clientId: text("client_id"),
168
+ scope: text("scope"),
169
+ });
170
+
171
+ export const apikey = sqliteTable(
172
+ "apikey",
173
+ {
174
+ id: text("id").primaryKey(),
175
+ configId: text("config_id").default("default").notNull(),
176
+ name: text("name"),
177
+ start: text("start"),
178
+ referenceId: text("reference_id").notNull(),
179
+ prefix: text("prefix"),
180
+ key: text("key").notNull(),
181
+ refillInterval: integer("refill_interval"),
182
+ refillAmount: integer("refill_amount"),
183
+ lastRefillAt: integer("last_refill_at", { mode: "timestamp_ms" }),
184
+ enabled: integer("enabled", { mode: "boolean" }).default(true),
185
+ rateLimitEnabled: integer("rate_limit_enabled", {
186
+ mode: "boolean",
187
+ }).default(true),
188
+ rateLimitTimeWindow: integer("rate_limit_time_window").default(86400000),
189
+ rateLimitMax: integer("rate_limit_max").default(10),
190
+ requestCount: integer("request_count").default(0),
191
+ remaining: integer("remaining"),
192
+ lastRequest: integer("last_request", { mode: "timestamp_ms" }),
193
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }),
194
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
195
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull(),
196
+ permissions: text("permissions"),
197
+ metadata: text("metadata"),
198
+ },
199
+ (table) => [
200
+ index("apikey_configId_idx").on(table.configId),
201
+ index("apikey_referenceId_idx").on(table.referenceId),
202
+ index("apikey_key_idx").on(table.key),
203
+ ],
204
+ );
205
+
206
+ export const oauthClient = sqliteTable(
207
+ "oauth_client",
208
+ {
209
+ id: text("id").primaryKey(),
210
+ clientId: text("client_id").notNull().unique(),
211
+ clientSecret: text("client_secret"),
212
+ disabled: integer("disabled", { mode: "boolean" }).default(false),
213
+ skipConsent: integer("skip_consent", { mode: "boolean" }),
214
+ enableEndSession: integer("enable_end_session", { mode: "boolean" }),
215
+ subjectType: text("subject_type"),
216
+ scopes: text("scopes", { mode: "json" }),
217
+ userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
218
+ createdAt: integer("created_at", { mode: "timestamp_ms" }),
219
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" }),
220
+ name: text("name"),
221
+ uri: text("uri"),
222
+ icon: text("icon"),
223
+ contacts: text("contacts", { mode: "json" }),
224
+ tos: text("tos"),
225
+ policy: text("policy"),
226
+ softwareId: text("software_id"),
227
+ softwareVersion: text("software_version"),
228
+ softwareStatement: text("software_statement"),
229
+ redirectUris: text("redirect_uris", { mode: "json" }).notNull(),
230
+ postLogoutRedirectUris: text("post_logout_redirect_uris", { mode: "json" }),
231
+ tokenEndpointAuthMethod: text("token_endpoint_auth_method"),
232
+ grantTypes: text("grant_types", { mode: "json" }),
233
+ responseTypes: text("response_types", { mode: "json" }),
234
+ public: integer("public", { mode: "boolean" }),
235
+ type: text("type"),
236
+ requirePKCE: integer("require_pkce", { mode: "boolean" }),
237
+ referenceId: text("reference_id"),
238
+ metadata: text("metadata", { mode: "json" }),
239
+ },
240
+ (table) => [index("oauthClient_userId_idx").on(table.userId)],
241
+ );
242
+
243
+ export const oauthRefreshToken = sqliteTable(
244
+ "oauth_refresh_token",
245
+ {
246
+ id: text("id").primaryKey(),
247
+ token: text("token").notNull().unique(),
248
+ clientId: text("client_id")
249
+ .notNull()
250
+ .references(() => oauthClient.clientId, { onDelete: "cascade" }),
251
+ sessionId: text("session_id").references(() => session.id, {
252
+ onDelete: "set null",
253
+ }),
254
+ userId: text("user_id")
255
+ .notNull()
256
+ .references(() => user.id, { onDelete: "cascade" }),
257
+ referenceId: text("reference_id"),
258
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
259
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
260
+ revoked: integer("revoked", { mode: "timestamp_ms" }),
261
+ authTime: integer("auth_time", { mode: "timestamp_ms" }),
262
+ scopes: text("scopes", { mode: "json" }).notNull(),
263
+ },
264
+ (table) => [
265
+ index("oauthRefreshToken_clientId_idx").on(table.clientId),
266
+ index("oauthRefreshToken_sessionId_idx").on(table.sessionId),
267
+ index("oauthRefreshToken_userId_idx").on(table.userId),
268
+ ],
269
+ );
270
+
271
+ export const oauthAccessToken = sqliteTable(
272
+ "oauth_access_token",
273
+ {
274
+ id: text("id").primaryKey(),
275
+ token: text("token").notNull().unique(),
276
+ clientId: text("client_id")
277
+ .notNull()
278
+ .references(() => oauthClient.clientId, { onDelete: "cascade" }),
279
+ sessionId: text("session_id").references(() => session.id, {
280
+ onDelete: "set null",
281
+ }),
282
+ userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
283
+ referenceId: text("reference_id"),
284
+ refreshId: text("refresh_id").references(() => oauthRefreshToken.id, {
285
+ onDelete: "cascade",
286
+ }),
287
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
288
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
289
+ scopes: text("scopes", { mode: "json" }).notNull(),
290
+ },
291
+ (table) => [
292
+ index("oauthAccessToken_clientId_idx").on(table.clientId),
293
+ index("oauthAccessToken_sessionId_idx").on(table.sessionId),
294
+ index("oauthAccessToken_userId_idx").on(table.userId),
295
+ index("oauthAccessToken_refreshId_idx").on(table.refreshId),
296
+ ],
297
+ );
298
+
299
+ export const oauthConsent = sqliteTable(
300
+ "oauth_consent",
301
+ {
302
+ id: text("id").primaryKey(),
303
+ clientId: text("client_id")
304
+ .notNull()
305
+ .references(() => oauthClient.clientId, { onDelete: "cascade" }),
306
+ userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
307
+ referenceId: text("reference_id"),
308
+ scopes: text("scopes", { mode: "json" }).notNull(),
309
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
310
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull(),
311
+ },
312
+ (table) => [
313
+ index("oauthConsent_clientId_idx").on(table.clientId),
314
+ index("oauthConsent_userId_idx").on(table.userId),
315
+ ],
316
+ );
317
+
318
+ export const organization = sqliteTable(
319
+ "organization",
320
+ {
321
+ id: text("id").primaryKey(),
322
+ name: text("name").notNull(),
323
+ slug: text("slug").notNull().unique(),
324
+ logo: text("logo"),
325
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
326
+ metadata: text("metadata"),
327
+ // better-auth `stripe` plugin field, organization-billing surface. See
328
+ // the `user.stripeCustomerId` comment above — shipped ahead of the
329
+ // plugin turning on.
330
+ stripeCustomerId: text("stripe_customer_id"),
331
+ },
332
+ (table) => [uniqueIndex("organization_slug_uidx").on(table.slug)],
333
+ );
334
+
335
+ export const member = sqliteTable(
336
+ "member",
337
+ {
338
+ id: text("id").primaryKey(),
339
+ organizationId: text("organization_id")
340
+ .notNull()
341
+ .references(() => organization.id, { onDelete: "cascade" }),
342
+ userId: text("user_id")
343
+ .notNull()
344
+ .references(() => user.id, { onDelete: "cascade" }),
345
+ role: text("role").default("member").notNull(),
346
+ createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
347
+ },
348
+ (table) => [
349
+ index("member_organizationId_idx").on(table.organizationId),
350
+ index("member_userId_idx").on(table.userId),
351
+ ],
352
+ );
353
+
354
+ export const invitation = sqliteTable(
355
+ "invitation",
356
+ {
357
+ id: text("id").primaryKey(),
358
+ organizationId: text("organization_id")
359
+ .notNull()
360
+ .references(() => organization.id, { onDelete: "cascade" }),
361
+ email: text("email").notNull(),
362
+ role: text("role"),
363
+ status: text("status").default("pending").notNull(),
364
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
365
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
366
+ .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
367
+ .notNull(),
368
+ inviterId: text("inviter_id")
369
+ .notNull()
370
+ .references(() => user.id, { onDelete: "cascade" }),
371
+ },
372
+ (table) => [
373
+ index("invitation_organizationId_idx").on(table.organizationId),
374
+ index("invitation_email_idx").on(table.email),
375
+ ],
376
+ );
377
+
378
+ // better-auth `stripe` plugin's subscription table (packages/auth/src/
379
+ // server.ts, `@better-auth/stripe`'s `subscriptions` schema fragment).
380
+ // Shipped now, ahead of the plugin turning on, so onboarding a real Stripe
381
+ // key later is a config flip, not a migration — see
382
+ // Reserved for the commerce track.
383
+ export const subscription = sqliteTable(
384
+ "subscription",
385
+ {
386
+ id: text("id").primaryKey(),
387
+ plan: text("plan").notNull(),
388
+ referenceId: text("reference_id").notNull(),
389
+ stripeCustomerId: text("stripe_customer_id"),
390
+ stripeSubscriptionId: text("stripe_subscription_id"),
391
+ status: text("status").default("incomplete").notNull(),
392
+ periodStart: integer("period_start", { mode: "timestamp_ms" }),
393
+ periodEnd: integer("period_end", { mode: "timestamp_ms" }),
394
+ trialStart: integer("trial_start", { mode: "timestamp_ms" }),
395
+ trialEnd: integer("trial_end", { mode: "timestamp_ms" }),
396
+ cancelAtPeriodEnd: integer("cancel_at_period_end", { mode: "boolean" }).default(false),
397
+ cancelAt: integer("cancel_at", { mode: "timestamp_ms" }),
398
+ canceledAt: integer("canceled_at", { mode: "timestamp_ms" }),
399
+ endedAt: integer("ended_at", { mode: "timestamp_ms" }),
400
+ seats: integer("seats"),
401
+ billingInterval: text("billing_interval"),
402
+ stripeScheduleId: text("stripe_schedule_id"),
403
+ },
404
+ (table) => [index("subscription_referenceId_idx").on(table.referenceId)],
405
+ );
406
+
407
+ export const rateLimit = sqliteTable("rate_limit", {
408
+ id: text("id").primaryKey(),
409
+ key: text("key").notNull().unique(),
410
+ count: integer("count").notNull(),
411
+ lastRequest: integer("last_request").notNull(),
412
+ });
413
+
414
+ export const userRelations = relations(user, ({ many }) => ({
415
+ sessions: many(session),
416
+ accounts: many(account),
417
+ twoFactors: many(twoFactor),
418
+ passkeys: many(passkey),
419
+ oauthClients: many(oauthClient),
420
+ oauthRefreshTokens: many(oauthRefreshToken),
421
+ oauthAccessTokens: many(oauthAccessToken),
422
+ oauthConsents: many(oauthConsent),
423
+ members: many(member),
424
+ invitations: many(invitation),
425
+ }));
426
+
427
+ export const sessionRelations = relations(session, ({ one, many }) => ({
428
+ user: one(user, {
429
+ fields: [session.userId],
430
+ references: [user.id],
431
+ }),
432
+ oauthRefreshTokens: many(oauthRefreshToken),
433
+ oauthAccessTokens: many(oauthAccessToken),
434
+ }));
435
+
436
+ export const accountRelations = relations(account, ({ one }) => ({
437
+ user: one(user, {
438
+ fields: [account.userId],
439
+ references: [user.id],
440
+ }),
441
+ }));
442
+
443
+ export const twoFactorRelations = relations(twoFactor, ({ one }) => ({
444
+ user: one(user, {
445
+ fields: [twoFactor.userId],
446
+ references: [user.id],
447
+ }),
448
+ }));
449
+
450
+ export const passkeyRelations = relations(passkey, ({ one }) => ({
451
+ user: one(user, {
452
+ fields: [passkey.userId],
453
+ references: [user.id],
454
+ }),
455
+ }));
456
+
457
+ export const oauthClientRelations = relations(oauthClient, ({ one, many }) => ({
458
+ user: one(user, {
459
+ fields: [oauthClient.userId],
460
+ references: [user.id],
461
+ }),
462
+ oauthRefreshTokens: many(oauthRefreshToken),
463
+ oauthAccessTokens: many(oauthAccessToken),
464
+ oauthConsents: many(oauthConsent),
465
+ }));
466
+
467
+ export const oauthRefreshTokenRelations = relations(oauthRefreshToken, ({ one, many }) => ({
468
+ oauthClient: one(oauthClient, {
469
+ fields: [oauthRefreshToken.clientId],
470
+ references: [oauthClient.clientId],
471
+ }),
472
+ session: one(session, {
473
+ fields: [oauthRefreshToken.sessionId],
474
+ references: [session.id],
475
+ }),
476
+ user: one(user, {
477
+ fields: [oauthRefreshToken.userId],
478
+ references: [user.id],
479
+ }),
480
+ oauthAccessTokens: many(oauthAccessToken),
481
+ }));
482
+
483
+ export const oauthAccessTokenRelations = relations(oauthAccessToken, ({ one }) => ({
484
+ oauthClient: one(oauthClient, {
485
+ fields: [oauthAccessToken.clientId],
486
+ references: [oauthClient.clientId],
487
+ }),
488
+ session: one(session, {
489
+ fields: [oauthAccessToken.sessionId],
490
+ references: [session.id],
491
+ }),
492
+ user: one(user, {
493
+ fields: [oauthAccessToken.userId],
494
+ references: [user.id],
495
+ }),
496
+ oauthRefreshToken: one(oauthRefreshToken, {
497
+ fields: [oauthAccessToken.refreshId],
498
+ references: [oauthRefreshToken.id],
499
+ }),
500
+ }));
501
+
502
+ export const oauthConsentRelations = relations(oauthConsent, ({ one }) => ({
503
+ oauthClient: one(oauthClient, {
504
+ fields: [oauthConsent.clientId],
505
+ references: [oauthClient.clientId],
506
+ }),
507
+ user: one(user, {
508
+ fields: [oauthConsent.userId],
509
+ references: [user.id],
510
+ }),
511
+ }));
512
+
513
+ export const organizationRelations = relations(organization, ({ many }) => ({
514
+ members: many(member),
515
+ invitations: many(invitation),
516
+ }));
517
+
518
+ export const memberRelations = relations(member, ({ one }) => ({
519
+ organization: one(organization, {
520
+ fields: [member.organizationId],
521
+ references: [organization.id],
522
+ }),
523
+ user: one(user, {
524
+ fields: [member.userId],
525
+ references: [user.id],
526
+ }),
527
+ }));
528
+
529
+ export const invitationRelations = relations(invitation, ({ one }) => ({
530
+ organization: one(organization, {
531
+ fields: [invitation.organizationId],
532
+ references: [organization.id],
533
+ }),
534
+ user: one(user, {
535
+ fields: [invitation.inviterId],
536
+ references: [user.id],
537
+ }),
538
+ }));
@@ -0,0 +1,7 @@
1
+ // AUTO-STAMPED by scripts/stamp-versions.ts at release — the checked-in
2
+ // values are dev placeholders, identical to the runtime fallbacks.
3
+ export const PKG = {
4
+ name: "@somewhatintelligent/guestlist",
5
+ version: "0.0.1-beta.1783705886.297c5be",
6
+ commit: "297c5be7d3af822a7f5da906acf27a076332609c",
7
+ } as const;