@contentgrowth/content-auth 0.1.0 → 0.2.1

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.
@@ -1027,6 +1027,23 @@ declare const invitations: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
1027
1027
  }, {}, {
1028
1028
  length: number | undefined;
1029
1029
  }>;
1030
+ createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
1031
+ name: "createdAt";
1032
+ tableName: "invitations";
1033
+ dataType: "date";
1034
+ columnType: "SQLiteTimestamp";
1035
+ data: Date;
1036
+ driverParam: number;
1037
+ notNull: true;
1038
+ hasDefault: false;
1039
+ isPrimaryKey: false;
1040
+ isAutoincrement: false;
1041
+ hasRuntimeDefault: false;
1042
+ enumValues: undefined;
1043
+ baseColumn: never;
1044
+ identity: undefined;
1045
+ generated: undefined;
1046
+ }, {}, {}>;
1030
1047
  };
1031
1048
  dialect: "sqlite";
1032
1049
  }>;
@@ -1042,6 +1059,22 @@ declare namespace schema {
1042
1059
  export { schema_accounts as accounts, schema_invitations as invitations, schema_members as members, schema_organizations as organizations, schema_sessions as sessions, schema_users as users, schema_verifications as verifications };
1043
1060
  }
1044
1061
 
1062
+ /**
1063
+ * Generates a formatted invitation link from the Better-Auth invitation data.
1064
+ *
1065
+ * Handles:
1066
+ * 1. Default Better-Auth fields (link, url)
1067
+ * 2. Fallback construction using baseUrl and invitation ID
1068
+ * 3. Markdown formatting for email clients causing auto-link issues
1069
+ *
1070
+ * @param data The data object received in the sendInvitationEmail hook
1071
+ * @param baseUrl The base URL of the application (e.g., https://app.example.com)
1072
+ * @returns An object containing the raw link and the markdown formatted link
1073
+ */
1074
+ declare function getInvitationLink(data: any, baseUrl: string): {
1075
+ link: any;
1076
+ };
1077
+
1045
1078
  interface AuthConfig {
1046
1079
  /**
1047
1080
  * The database instance or D1 binding.
@@ -1071,4 +1104,4 @@ declare const createAuthApp: (config: AuthConfig) => {
1071
1104
  auth: better_auth.Auth<any>;
1072
1105
  };
1073
1106
 
1074
- export { type AuthConfig, authMiddleware, createAuth, createAuthApp, schema };
1107
+ export { type AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, schema };
@@ -3,13 +3,15 @@ import {
3
3
  authMiddleware,
4
4
  createAuth,
5
5
  createAuthApp,
6
+ getInvitationLink,
6
7
  schema_exports
7
- } from "../chunk-HPPCUGKY.js";
8
+ } from "../chunk-FYU2PONS.js";
8
9
  import "../chunk-R5U7XKVJ.js";
9
10
  export {
10
11
  Hono,
11
12
  authMiddleware,
12
13
  createAuth,
13
14
  createAuthApp,
15
+ getInvitationLink,
14
16
  schema_exports as schema
15
17
  };
@@ -86,7 +86,8 @@ var invitations = sqliteTable("invitations", {
86
86
  role: text("role"),
87
87
  status: text("status").notNull(),
88
88
  expiresAt: integer("expiresAt", { mode: "timestamp" }).notNull(),
89
- inviterId: text("inviterId").notNull().references(() => users.id, { onDelete: "cascade" })
89
+ inviterId: text("inviterId").notNull().references(() => users.id, { onDelete: "cascade" }),
90
+ createdAt: integer("createdAt", { mode: "timestamp" }).notNull()
90
91
  });
91
92
 
92
93
  // src/backend/native-hashing.ts
@@ -163,6 +164,18 @@ async function verifyPassword(passwordOrData, storedHash) {
163
164
  return result === 0;
164
165
  }
165
166
 
167
+ // src/backend/utils.ts
168
+ function getInvitationLink(data, baseUrl) {
169
+ let rawLink = data.link || data.url;
170
+ if (!rawLink) {
171
+ const cleanBaseUrl = baseUrl.replace(/\/$/, "");
172
+ rawLink = `${cleanBaseUrl}/accept-invitation/${data.id}`;
173
+ }
174
+ return {
175
+ link: rawLink
176
+ };
177
+ }
178
+
166
179
  // src/backend/index.ts
167
180
  var createAuth = (config) => {
168
181
  let db;
@@ -221,6 +234,7 @@ var createAuthApp = (config) => {
221
234
 
222
235
  export {
223
236
  schema_exports,
237
+ getInvitationLink,
224
238
  Hono,
225
239
  createAuth,
226
240
  authMiddleware,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthConfig, authMiddleware, createAuth, createAuthApp, schema } from './backend/index.js';
1
+ export { AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, schema } from './backend/index.js';
2
2
  export { AuthForm, CreateOrganizationForm, InviteMemberForm, OrganizationSwitcher } from './frontend/index.js';
3
3
  export { authClient, createClient } from './frontend/client.js';
4
4
  export * from 'better-auth';
package/dist/index.js CHANGED
@@ -3,8 +3,9 @@ import {
3
3
  authMiddleware,
4
4
  createAuth,
5
5
  createAuthApp,
6
+ getInvitationLink,
6
7
  schema_exports
7
- } from "./chunk-HPPCUGKY.js";
8
+ } from "./chunk-FYU2PONS.js";
8
9
  import {
9
10
  AuthForm,
10
11
  CreateOrganizationForm,
@@ -27,5 +28,6 @@ export {
27
28
  createAuth,
28
29
  createAuthApp,
29
30
  createClient,
31
+ getInvitationLink,
30
32
  schema_exports as schema
31
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-auth",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Better Auth wrapper with UI components for Cloudflare Workers & Pages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/schema/auth.sql CHANGED
@@ -19,7 +19,7 @@
19
19
  -- ==========================================
20
20
 
21
21
  -- Users
22
- CREATE TABLE IF NOT EXISTS user (
22
+ CREATE TABLE IF NOT EXISTS users (
23
23
  id TEXT PRIMARY KEY,
24
24
  name TEXT NOT NULL,
25
25
  email TEXT NOT NULL UNIQUE,
@@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS user (
30
30
  );
31
31
 
32
32
  -- Sessions
33
- CREATE TABLE IF NOT EXISTS session (
33
+ CREATE TABLE IF NOT EXISTS sessions (
34
34
  id TEXT PRIMARY KEY,
35
35
  expiresAt TIMESTAMP NOT NULL,
36
36
  token TEXT NOT NULL UNIQUE,
@@ -38,15 +38,16 @@ CREATE TABLE IF NOT EXISTS session (
38
38
  updatedAt TIMESTAMP NOT NULL,
39
39
  ipAddress TEXT,
40
40
  userAgent TEXT,
41
- userId TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE
41
+ userId TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
42
+ activeOrganizationId TEXT
42
43
  );
43
44
 
44
45
  -- OAuth/Credential Accounts
45
- CREATE TABLE IF NOT EXISTS account (
46
+ CREATE TABLE IF NOT EXISTS accounts (
46
47
  id TEXT PRIMARY KEY,
47
48
  accountId TEXT NOT NULL,
48
49
  providerId TEXT NOT NULL,
49
- userId TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE,
50
+ userId TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
50
51
  accessToken TEXT,
51
52
  refreshToken TEXT,
52
53
  idToken TEXT,
@@ -59,7 +60,7 @@ CREATE TABLE IF NOT EXISTS account (
59
60
  );
60
61
 
61
62
  -- Email/Token Verification
62
- CREATE TABLE IF NOT EXISTS verification (
63
+ CREATE TABLE IF NOT EXISTS verifications (
63
64
  id TEXT PRIMARY KEY,
64
65
  identifier TEXT NOT NULL,
65
66
  value TEXT NOT NULL,
@@ -73,7 +74,7 @@ CREATE TABLE IF NOT EXISTS verification (
73
74
  -- ==========================================
74
75
 
75
76
  -- Organizations
76
- CREATE TABLE IF NOT EXISTS organization (
77
+ CREATE TABLE IF NOT EXISTS organizations (
77
78
  id TEXT PRIMARY KEY,
78
79
  name TEXT NOT NULL,
79
80
  slug TEXT UNIQUE,
@@ -83,23 +84,24 @@ CREATE TABLE IF NOT EXISTS organization (
83
84
  );
84
85
 
85
86
  -- Organization Members
86
- CREATE TABLE IF NOT EXISTS member (
87
+ CREATE TABLE IF NOT EXISTS members (
87
88
  id TEXT PRIMARY KEY,
88
- organizationId TEXT NOT NULL REFERENCES organization(id) ON DELETE CASCADE,
89
- userId TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE,
89
+ organizationId TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
90
+ userId TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
90
91
  role TEXT NOT NULL, -- 'owner', 'admin', 'member'
91
92
  createdAt TIMESTAMP NOT NULL
92
93
  );
93
94
 
94
95
  -- Organization Invitations
95
- CREATE TABLE IF NOT EXISTS invitation (
96
+ CREATE TABLE IF NOT EXISTS invitations (
96
97
  id TEXT PRIMARY KEY,
97
- organizationId TEXT NOT NULL REFERENCES organization(id) ON DELETE CASCADE,
98
+ organizationId TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
98
99
  email TEXT NOT NULL,
99
100
  role TEXT,
100
101
  status TEXT NOT NULL, -- 'pending', 'accepted', 'rejected', 'expired'
101
102
  expiresAt TIMESTAMP NOT NULL,
102
- inviterId TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE
103
+ inviterId TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
104
+ createdAt TIMESTAMP NOT NULL
103
105
  );
104
106
 
105
107
  -- ==========================================
@@ -109,7 +111,7 @@ CREATE TABLE IF NOT EXISTS invitation (
109
111
  --
110
112
  -- CREATE TABLE IF NOT EXISTS my_entity (
111
113
  -- id TEXT PRIMARY KEY,
112
- -- org_id TEXT NOT NULL, -- References organization.id
114
+ -- org_id TEXT NOT NULL, -- References organizations.id
113
115
  -- name TEXT NOT NULL,
114
116
  -- created_at INTEGER
115
117
  -- );