@mertdogar/better-auth-do-sqlite
Advanced tools
+23
-10
| 'use strict'; | ||
| var cloudflare_workers = require('cloudflare:workers'); | ||
| var zod = require('zod'); | ||
| var kysely = require('kysely'); | ||
@@ -11,7 +12,4 @@ var betterAuth = require('better-auth'); | ||
| var cors = require('hono/cors'); | ||
| var zod = require('zod'); | ||
| // lib/auth-do.ts | ||
| // lib/logger.ts | ||
| var LogLevelSeverity = { | ||
@@ -24,2 +22,15 @@ debug: 0, | ||
| }; | ||
| var jsonLogSchema = zod.z.object({ | ||
| timestamp: zod.z.number(), | ||
| time: zod.z.string(), | ||
| name: zod.z.string(), | ||
| level: zod.z.string(), | ||
| message: zod.z.string(), | ||
| data: zod.z.record(zod.z.string(), zod.z.unknown()).optional(), | ||
| error: zod.z.object({ | ||
| message: zod.z.string(), | ||
| stack: zod.z.string().optional(), | ||
| name: zod.z.string().optional() | ||
| }).optional() | ||
| }); | ||
| var colors = { | ||
@@ -66,5 +77,2 @@ reset: "\x1B[0m", | ||
| } | ||
| formatTimestamp() { | ||
| return (/* @__PURE__ */ new Date()).toISOString(); | ||
| } | ||
| formatError(error) { | ||
@@ -82,5 +90,7 @@ if (error instanceof Error) { | ||
| if (!this.shouldLog(level)) return; | ||
| const now = /* @__PURE__ */ new Date(); | ||
| if (this.format === "json") { | ||
| const log = { | ||
| timestamp: this.formatTimestamp(), | ||
| timestamp: now.getTime(), | ||
| time: now.toISOString(), | ||
| name: this.name, | ||
@@ -95,3 +105,3 @@ level, | ||
| const emoji = levelEmojis[level]; | ||
| const timestamp = colors.gray + this.formatTimestamp() + colors.reset; | ||
| const timestamp = colors.gray + now.toISOString() + colors.reset; | ||
| const nameStr = colors.cyan + `[${this.name}]` + colors.reset; | ||
@@ -102,3 +112,3 @@ const levelStr = color + colors.bright + level.toUpperCase() + colors.reset; | ||
| } else { | ||
| const timestamp = this.formatTimestamp(); | ||
| const timestamp = now.toISOString(); | ||
| const dataStr = data ? ` ${JSON.stringify(data)}` : ""; | ||
@@ -122,6 +132,8 @@ console.log(`[${timestamp}] [${this.name}] ${level.toUpperCase()}: ${message}${dataStr}`); | ||
| const logData = { ...data }; | ||
| const now = /* @__PURE__ */ new Date(); | ||
| if (error) { | ||
| if (this.format === "json") { | ||
| const errorLog = { | ||
| timestamp: this.formatTimestamp(), | ||
| timestamp: now.getTime(), | ||
| time: now.toISOString(), | ||
| name: this.name, | ||
@@ -1182,3 +1194,4 @@ level: "error", | ||
| exports.getDO = getDO; | ||
| exports.jsonLogSchema = jsonLogSchema; | ||
| exports.requireAuth = requireAuth; | ||
| exports.sqlServerRouter = sqlServerRouter; |
+23
-11
| import { DurableObject } from 'cloudflare:workers'; | ||
| import { z } from 'zod'; | ||
| import { Kysely, SqliteAdapter, SqliteQueryCompiler, SqliteIntrospector } from 'kysely'; | ||
@@ -9,7 +10,4 @@ import { betterAuth } from 'better-auth'; | ||
| import { cors } from 'hono/cors'; | ||
| import { z } from 'zod'; | ||
| // lib/auth-do.ts | ||
| // lib/logger.ts | ||
| var LogLevelSeverity = { | ||
@@ -22,2 +20,15 @@ debug: 0, | ||
| }; | ||
| var jsonLogSchema = z.object({ | ||
| timestamp: z.number(), | ||
| time: z.string(), | ||
| name: z.string(), | ||
| level: z.string(), | ||
| message: z.string(), | ||
| data: z.record(z.string(), z.unknown()).optional(), | ||
| error: z.object({ | ||
| message: z.string(), | ||
| stack: z.string().optional(), | ||
| name: z.string().optional() | ||
| }).optional() | ||
| }); | ||
| var colors = { | ||
@@ -64,5 +75,2 @@ reset: "\x1B[0m", | ||
| } | ||
| formatTimestamp() { | ||
| return (/* @__PURE__ */ new Date()).toISOString(); | ||
| } | ||
| formatError(error) { | ||
@@ -80,5 +88,7 @@ if (error instanceof Error) { | ||
| if (!this.shouldLog(level)) return; | ||
| const now = /* @__PURE__ */ new Date(); | ||
| if (this.format === "json") { | ||
| const log = { | ||
| timestamp: this.formatTimestamp(), | ||
| timestamp: now.getTime(), | ||
| time: now.toISOString(), | ||
| name: this.name, | ||
@@ -93,3 +103,3 @@ level, | ||
| const emoji = levelEmojis[level]; | ||
| const timestamp = colors.gray + this.formatTimestamp() + colors.reset; | ||
| const timestamp = colors.gray + now.toISOString() + colors.reset; | ||
| const nameStr = colors.cyan + `[${this.name}]` + colors.reset; | ||
@@ -100,3 +110,3 @@ const levelStr = color + colors.bright + level.toUpperCase() + colors.reset; | ||
| } else { | ||
| const timestamp = this.formatTimestamp(); | ||
| const timestamp = now.toISOString(); | ||
| const dataStr = data ? ` ${JSON.stringify(data)}` : ""; | ||
@@ -120,6 +130,8 @@ console.log(`[${timestamp}] [${this.name}] ${level.toUpperCase()}: ${message}${dataStr}`); | ||
| const logData = { ...data }; | ||
| const now = /* @__PURE__ */ new Date(); | ||
| if (error) { | ||
| if (this.format === "json") { | ||
| const errorLog = { | ||
| timestamp: this.formatTimestamp(), | ||
| timestamp: now.getTime(), | ||
| time: now.toISOString(), | ||
| name: this.name, | ||
@@ -1172,2 +1184,2 @@ level: "error", | ||
| export { AuthDO, LibSQLHttpServer, Logger, authMiddleware, betterAuthRouter, createLogger, getBearerToken, getDO, requireAuth, sqlServerRouter }; | ||
| export { AuthDO, LibSQLHttpServer, Logger, authMiddleware, betterAuthRouter, createLogger, getBearerToken, getDO, jsonLogSchema, requireAuth, sqlServerRouter }; |
+1
-1
| { | ||
| "name": "@mertdogar/better-auth-do-sqlite", | ||
| "libName": "better-auth-do-sqlite", | ||
| "version": "0.0.22", | ||
| "version": "0.0.23", | ||
| "description": "Complete authentication and database solution for Cloudflare Durable Objects with Better Auth and libSQL HTTP protocol support", | ||
@@ -6,0 +6,0 @@ "main": "./dist/index.cjs", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
426769
0.81%5807
1.29%