@kuckit/auth 1.0.3 → 2.0.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.
@@ -0,0 +1,42 @@
1
+ //#region src/config.d.ts
2
+ /**
3
+ * Pure config exports for @kuckit/auth
4
+ *
5
+ * This entrypoint is GUARANTEED to be side-effect-free:
6
+ * - No better-auth instantiation
7
+ * - No database connections
8
+ * - No process.env reads at module scope
9
+ *
10
+ * Safe for CLI tools, build scripts, and config files.
11
+ */
12
+ /**
13
+ * Auth configuration options
14
+ */
15
+ interface AuthConfig {
16
+ /** List of trusted origins for CORS */
17
+ trustedOrigins?: string[];
18
+ /** Base URL for auth endpoints (e.g., http://localhost:3000) */
19
+ baseUrl?: string;
20
+ /** Cookie name prefix (default: better-auth) */
21
+ cookiePrefix?: string;
22
+ /** Session max age in seconds (default: 7 days) */
23
+ sessionMaxAge?: number;
24
+ }
25
+ /**
26
+ * Define auth configuration with type safety
27
+ */
28
+ declare function defineAuthConfig(config: AuthConfig): AuthConfig;
29
+ /**
30
+ * Get cookie attributes for auth cookies
31
+ *
32
+ * @param secure - Whether to use secure cookies (true in production)
33
+ */
34
+ declare function getCookieAttributes(secure: boolean): {
35
+ secure: boolean;
36
+ sameSite: "lax";
37
+ path: string;
38
+ httpOnly: boolean;
39
+ };
40
+ //#endregion
41
+ export { defineAuthConfig as n, getCookieAttributes as r, AuthConfig as t };
42
+ //# sourceMappingURL=config-BViah4xX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-BViah4xX.d.ts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":";;AAcA;AAcA;AASA;;;;;;;;;;UAvBiB,UAAA;;;;;;;;;;;;;iBAcD,gBAAA,SAAyB,aAAa;;;;;;iBAStC,mBAAA"}
@@ -0,0 +1,24 @@
1
+ //#region src/config.ts
2
+ /**
3
+ * Define auth configuration with type safety
4
+ */
5
+ function defineAuthConfig(config) {
6
+ return config;
7
+ }
8
+ /**
9
+ * Get cookie attributes for auth cookies
10
+ *
11
+ * @param secure - Whether to use secure cookies (true in production)
12
+ */
13
+ function getCookieAttributes(secure) {
14
+ return {
15
+ secure,
16
+ sameSite: "lax",
17
+ path: "/",
18
+ httpOnly: true
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ export { getCookieAttributes as n, defineAuthConfig as t };
24
+ //# sourceMappingURL=config-BZZEHPCg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-BZZEHPCg.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["/**\n * Pure config exports for @kuckit/auth\n *\n * This entrypoint is GUARANTEED to be side-effect-free:\n * - No better-auth instantiation\n * - No database connections\n * - No process.env reads at module scope\n *\n * Safe for CLI tools, build scripts, and config files.\n */\n\n/**\n * Auth configuration options\n */\nexport interface AuthConfig {\n\t/** List of trusted origins for CORS */\n\ttrustedOrigins?: string[]\n\t/** Base URL for auth endpoints (e.g., http://localhost:3000) */\n\tbaseUrl?: string\n\t/** Cookie name prefix (default: better-auth) */\n\tcookiePrefix?: string\n\t/** Session max age in seconds (default: 7 days) */\n\tsessionMaxAge?: number\n}\n\n/**\n * Define auth configuration with type safety\n */\nexport function defineAuthConfig(config: AuthConfig): AuthConfig {\n\treturn config\n}\n\n/**\n * Get cookie attributes for auth cookies\n *\n * @param secure - Whether to use secure cookies (true in production)\n */\nexport function getCookieAttributes(secure: boolean) {\n\treturn {\n\t\tsecure,\n\t\tsameSite: 'lax' as const,\n\t\tpath: '/',\n\t\thttpOnly: true,\n\t}\n}\n"],"mappings":";;;;AA4BA,SAAgB,iBAAiB,QAAgC;AAChE,QAAO;;;;;;;AAQR,SAAgB,oBAAoB,QAAiB;AACpD,QAAO;EACN;EACA,UAAU;EACV,MAAM;EACN,UAAU;EACV"}
@@ -0,0 +1,2 @@
1
+ import { n as defineAuthConfig, r as getCookieAttributes, t as AuthConfig } from "./config-BViah4xX.js";
2
+ export { AuthConfig, defineAuthConfig, getCookieAttributes };
package/dist/config.js ADDED
@@ -0,0 +1,3 @@
1
+ import { n as getCookieAttributes, t as defineAuthConfig } from "./config-BZZEHPCg.js";
2
+
3
+ export { defineAuthConfig, getCookieAttributes };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,47 @@
1
- import * as better_auth0 from "better-auth";
2
- import { BetterAuthOptions } from "better-auth";
1
+ import { n as defineAuthConfig, r as getCookieAttributes, t as AuthConfig } from "./config-BViah4xX.js";
2
+ import { betterAuth } from "better-auth";
3
+ import { drizzleAdapter } from "better-auth/adapters/drizzle";
3
4
 
4
5
  //#region src/index.d.ts
5
- declare const auth: better_auth0.Auth<BetterAuthOptions>;
6
+
7
+ /**
8
+ * Auth instance type (inferred from betterAuth)
9
+ */
10
+ type Auth = ReturnType<typeof betterAuth>;
11
+ /**
12
+ * Database type accepted by createAuth
13
+ * This matches the Drizzle database type from @kuckit/db
14
+ */
15
+ type AuthDbClient = Parameters<typeof drizzleAdapter>[0];
16
+ interface CreateAuthOptions {
17
+ /** Drizzle database instance */
18
+ db: AuthDbClient;
19
+ /** Auth configuration */
20
+ config?: AuthConfig;
21
+ }
22
+ /**
23
+ * Create a Better-Auth instance
24
+ *
25
+ * This is a factory function that creates the auth instance at runtime,
26
+ * avoiding module-level side effects.
27
+ *
28
+ * @param options - Database and configuration options
29
+ * @returns Better-Auth instance
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const auth = createAuth({
34
+ * db,
35
+ * config: {
36
+ * trustedOrigins: ['http://localhost:5173'],
37
+ * },
38
+ * })
39
+ * ```
40
+ */
41
+ declare function createAuth({
42
+ db,
43
+ config
44
+ }: CreateAuthOptions): Auth;
6
45
  //#endregion
7
- export { auth };
46
+ export { Auth, type AuthConfig, AuthDbClient, CreateAuthOptions, createAuth, defineAuthConfig, getCookieAttributes };
8
47
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;cAKa,MAAI,YAAA,CAAA,KAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAQA;AAMY,KANA,IAAA,GAAO,UAMK,CAAqB,OANR,UAMV,CAAA;AAE3B;AA0BA;;;AAAgD,KA5BpC,YAAA,GAAe,UA4BqB,CAAA,OA5BH,cA4BG,CAAA,CAAA,CAAA,CAAA;AAAoB,UA1BnD,iBAAA,CA0BmD;EAAI;MAxBnE;;WAEK;;;;;;;;;;;;;;;;;;;;;iBAsBM,UAAA;;;GAAgC,oBAAoB"}
package/dist/index.js CHANGED
@@ -1,23 +1,45 @@
1
+ import { n as getCookieAttributes, t as defineAuthConfig } from "./config-BZZEHPCg.js";
1
2
  import { betterAuth } from "better-auth";
2
3
  import { drizzleAdapter } from "better-auth/adapters/drizzle";
3
- import { db } from "@kuckit/db";
4
4
  import * as schema from "@kuckit/db/schema/auth";
5
5
 
6
6
  //#region src/index.ts
7
- const auth = betterAuth({
8
- database: drizzleAdapter(db, {
9
- provider: "pg",
10
- schema
11
- }),
12
- trustedOrigins: [process.env.CORS_ORIGIN || ""],
13
- emailAndPassword: { enabled: true },
14
- advanced: { defaultCookieAttributes: {
15
- sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
16
- secure: process.env.NODE_ENV === "production",
17
- httpOnly: true
18
- } }
19
- });
7
+ /**
8
+ * Create a Better-Auth instance
9
+ *
10
+ * This is a factory function that creates the auth instance at runtime,
11
+ * avoiding module-level side effects.
12
+ *
13
+ * @param options - Database and configuration options
14
+ * @returns Better-Auth instance
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const auth = createAuth({
19
+ * db,
20
+ * config: {
21
+ * trustedOrigins: ['http://localhost:5173'],
22
+ * },
23
+ * })
24
+ * ```
25
+ */
26
+ function createAuth({ db, config = {} }) {
27
+ const isProduction = process.env.NODE_ENV === "production";
28
+ return betterAuth({
29
+ database: drizzleAdapter(db, {
30
+ provider: "pg",
31
+ schema
32
+ }),
33
+ trustedOrigins: config.trustedOrigins ?? [process.env.CORS_ORIGIN || ""],
34
+ emailAndPassword: { enabled: true },
35
+ advanced: { defaultCookieAttributes: {
36
+ sameSite: isProduction ? "none" : "lax",
37
+ secure: isProduction,
38
+ httpOnly: true
39
+ } }
40
+ });
41
+ }
20
42
 
21
43
  //#endregion
22
- export { auth };
44
+ export { createAuth, defineAuthConfig, getCookieAttributes };
23
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { betterAuth, type BetterAuthOptions } from 'better-auth'\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle'\nimport { db } from '@kuckit/db'\nimport * as schema from '@kuckit/db/schema/auth'\n\nexport const auth = betterAuth<BetterAuthOptions>({\n\tdatabase: drizzleAdapter(db, {\n\t\tprovider: 'pg',\n\n\t\tschema: schema,\n\t}),\n\ttrustedOrigins: [process.env.CORS_ORIGIN || ''],\n\temailAndPassword: {\n\t\tenabled: true,\n\t},\n\tadvanced: {\n\t\tdefaultCookieAttributes: {\n\t\t\tsameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',\n\t\t\tsecure: process.env.NODE_ENV === 'production',\n\t\t\thttpOnly: true,\n\t\t},\n\t},\n})\n"],"mappings":";;;;;;AAKA,MAAa,OAAO,WAA8B;CACjD,UAAU,eAAe,IAAI;EAC5B,UAAU;EAEF;EACR,CAAC;CACF,gBAAgB,CAAC,QAAQ,IAAI,eAAe,GAAG;CAC/C,kBAAkB,EACjB,SAAS,MACT;CACD,UAAU,EACT,yBAAyB;EACxB,UAAU,QAAQ,IAAI,aAAa,eAAe,SAAS;EAC3D,QAAQ,QAAQ,IAAI,aAAa;EACjC,UAAU;EACV,EACD;CACD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { betterAuth, type BetterAuthOptions } from 'better-auth'\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle'\nimport * as schema from '@kuckit/db/schema/auth'\nimport type { AuthConfig } from './config'\n\n/**\n * Auth instance type (inferred from betterAuth)\n */\nexport type Auth = ReturnType<typeof betterAuth>\n\n/**\n * Database type accepted by createAuth\n * This matches the Drizzle database type from @kuckit/db\n */\nexport type AuthDbClient = Parameters<typeof drizzleAdapter>[0]\n\nexport interface CreateAuthOptions {\n\t/** Drizzle database instance */\n\tdb: AuthDbClient\n\t/** Auth configuration */\n\tconfig?: AuthConfig\n}\n\n/**\n * Create a Better-Auth instance\n *\n * This is a factory function that creates the auth instance at runtime,\n * avoiding module-level side effects.\n *\n * @param options - Database and configuration options\n * @returns Better-Auth instance\n *\n * @example\n * ```ts\n * const auth = createAuth({\n * db,\n * config: {\n * trustedOrigins: ['http://localhost:5173'],\n * },\n * })\n * ```\n */\nexport function createAuth({ db, config = {} }: CreateAuthOptions): Auth {\n\tconst isProduction = process.env.NODE_ENV === 'production'\n\n\treturn betterAuth<BetterAuthOptions>({\n\t\tdatabase: drizzleAdapter(db, {\n\t\t\tprovider: 'pg',\n\t\t\tschema: schema,\n\t\t}),\n\t\ttrustedOrigins: config.trustedOrigins ?? [process.env.CORS_ORIGIN || ''],\n\t\temailAndPassword: {\n\t\t\tenabled: true,\n\t\t},\n\t\tadvanced: {\n\t\t\tdefaultCookieAttributes: {\n\t\t\t\tsameSite: isProduction ? 'none' : 'lax',\n\t\t\t\tsecure: isProduction,\n\t\t\t\thttpOnly: true,\n\t\t\t},\n\t\t},\n\t})\n}\n\n// Re-export config types\nexport type { AuthConfig } from './config'\nexport { defineAuthConfig, getCookieAttributes } from './config'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,WAAW,EAAE,IAAI,SAAS,EAAE,IAA6B;CACxE,MAAM,eAAe,QAAQ,IAAI,aAAa;AAE9C,QAAO,WAA8B;EACpC,UAAU,eAAe,IAAI;GAC5B,UAAU;GACF;GACR,CAAC;EACF,gBAAgB,OAAO,kBAAkB,CAAC,QAAQ,IAAI,eAAe,GAAG;EACxE,kBAAkB,EACjB,SAAS,MACT;EACD,UAAU,EACT,yBAAyB;GACxB,UAAU,eAAe,SAAS;GAClC,QAAQ;GACR,UAAU;GACV,EACD;EACD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuckit/auth",
3
- "version": "1.0.3",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,10 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "default": "./dist/index.js"
14
14
  },
15
+ "./config": {
16
+ "types": "./dist/config.d.ts",
17
+ "default": "./dist/config.js"
18
+ },
15
19
  "./*": {
16
20
  "types": "./dist/*.d.ts",
17
21
  "default": "./dist/*.js"
@@ -31,6 +35,6 @@
31
35
  "better-auth": "^1.3.28",
32
36
  "dotenv": "^17.2.2",
33
37
  "zod": "^4.1.11",
34
- "@kuckit/db": "^1.0.3"
38
+ "@kuckit/db": "^2.0.1"
35
39
  }
36
40
  }