Skip to content

Commit 5396f3a

Browse files
committed
undeprecate stuff
1 parent a19d1c1 commit 5396f3a

File tree

9 files changed

+229
-93
lines changed

9 files changed

+229
-93
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "keypal",
3-
"version": "0.0.213",
3+
"version": "0.0.214",
44
"description": "A TypeScript library for secure API key management with cryptographic hashing, expiration, scopes, and pluggable storage",
55
"type": "module",
66
"main": "./dist/index.mjs",
@@ -81,7 +81,7 @@
8181
"db:generate": "bunx drizzle-kit generate",
8282
"db:migrate": "bunx drizzle-kit migrate",
8383
"db:push": "bunx drizzle-kit push",
84-
"prepare": "husky",
84+
"prepare": "bunx husky || true",
8585
"prepublishOnly": "bun run build",
8686
"version:patch": "npm version patch --no-git-tag-version",
8787
"version:minor": "npm version minor --no-git-tag-version",

src/storage/adapter-factory/index.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ApiKeyRecord, ApiKeyMetadata } from "../../types/api-key-types";
22
import type { AuditLog, AuditLogQuery, AuditLogStats, AuditAction } from "../../types/audit-log-types";
33
import type { Storage } from "../../types/storage-types";
44
import { generateKey } from "../../core/generate";
5+
import { logger } from "../../utils/logger";
56
import type {
67
AdapterFactoryConfig,
78
AdapterFactoryOptions,
@@ -12,23 +13,19 @@ import type {
1213
} from "./types";
1314

1415
export * from "./types";
15-
16-
/** Default query limit for paginated results */
17-
export const DEFAULT_QUERY_LIMIT = 100;
16+
export { DEFAULT_QUERY_LIMIT, calculateLogStats } from "../utils";
1817

1918
/**
2019
* Creates a storage adapter with automatic transformations and field mapping
2120
*/
2221
export const createAdapterFactory = (
23-
options: AdapterFactoryOptions
22+
options: AdapterFactoryOptions
2423
): Storage => {
2524
const config: AdapterFactoryConfig = {
2625
supportsDates: true,
2726
supportsBooleans: true,
2827
usePlural: false,
2928
disableIdGeneration: false,
30-
disableTransformInput: false,
31-
disableTransformOutput: false,
3229
debugLogs: false,
3330
...options.config,
3431
};
@@ -40,19 +37,17 @@ export const createAdapterFactory = (
4037
...options.schema,
4138
};
4239

43-
// Debug logging helper
4440
const debugLog = (...args: unknown[]) => {
4541
if (!config.debugLogs) return;
4642

4743
if (typeof config.debugLogs === "boolean") {
48-
console.log(`[${config.adapterName}]`, ...args);
44+
logger.info(`[${config.adapterName}]`, ...args);
4945
return;
5046
}
5147

52-
// Check if the specific method is enabled
5348
const method = typeof args[0] === "string" ? args[0] : null;
5449
if (method && config.debugLogs[method as keyof typeof config.debugLogs]) {
55-
console.log(`[${config.adapterName}]`, ...args);
50+
logger.info(`[${config.adapterName}]`, ...args);
5651
}
5752
};
5853

@@ -283,11 +278,6 @@ export const createAdapterFactory = (
283278
record.id = config.customIdGenerator ? config.customIdGenerator() : generateKey();
284279
}
285280

286-
if (!config.disableTransformInput) {
287-
const transformed = transformApiKeyInput(record);
288-
debugLog("save", "Transformed:", transformed);
289-
}
290-
291281
await baseAdapter.save(record);
292282
debugLog("save", "Saved successfully");
293283
},

src/storage/adapter-factory/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ export type AdapterFactoryConfig = {
3030
/** Custom ID generator function */
3131
customIdGenerator?: () => string;
3232

33-
/** Whether to disable input transformations (for performance) */
34-
disableTransformInput?: boolean;
35-
36-
/** Whether to disable output transformations (for performance) */
37-
disableTransformOutput?: boolean;
38-
3933
/** Enable debug logging */
4034
debugLogs?: boolean | {
4135
save?: boolean;

src/storage/drizzle.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import type {
66
AuditLogStats,
77
} from "../types/audit-log-types";
88
import type { Storage } from "../types/storage-types";
9+
import { logger } from "../utils/logger";
910
import {
1011
createAdapterFactory,
1112
type SchemaConfig,
1213
} from "./adapter-factory";
13-
14-
const DEFAULT_QUERY_LIMIT = 100;
14+
import { DEFAULT_QUERY_LIMIT, calculateLogStats } from "./utils";
1515

1616
/**
1717
* Generic database interface for Drizzle
@@ -86,7 +86,7 @@ function detectProvider(db: DrizzleDB): DatabaseProvider {
8686
return "sqlite";
8787
}
8888

89-
console.warn(
89+
logger.warn(
9090
"[Drizzle Store] Could not detect database provider, defaulting to PostgreSQL"
9191
);
9292
return "pg";
@@ -152,7 +152,7 @@ export function createDrizzleStore(options: DrizzleAdapterConfig): Storage {
152152
const provider = options.provider ?? detectProvider(db);
153153

154154
if (provider === "mysql" && auditLogTable) {
155-
console.warn(
155+
logger.warn(
156156
"[Drizzle Store] MySQL detected: RETURNING clause not supported, using fallback queries"
157157
);
158158
}
@@ -457,21 +457,7 @@ export function createDrizzleStore(options: DrizzleAdapterConfig): Storage {
457457
context.transformAuditLogOutput?.(row)!
458458
);
459459

460-
const byAction: Partial<Record<string, number>> = {};
461-
let lastActivity: string | null = null;
462-
463-
for (const log of logs) {
464-
byAction[log.action] = (byAction[log.action] || 0) + 1;
465-
if (!lastActivity || log.timestamp > lastActivity) {
466-
lastActivity = log.timestamp;
467-
}
468-
}
469-
470-
return {
471-
total: logs.length,
472-
byAction,
473-
lastActivity,
474-
};
460+
return calculateLogStats(logs);
475461
},
476462
}),
477463
};

src/storage/kysely.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import type {
66
AuditLogStats,
77
} from "../types/audit-log-types";
88
import type { Storage } from "../types/storage-types";
9+
import { logger } from "../utils/logger";
910
import {
1011
createAdapterFactory,
1112
type SchemaConfig,
1213
} from "./adapter-factory";
13-
14-
const DEFAULT_QUERY_LIMIT = 100;
14+
import { DEFAULT_QUERY_LIMIT, calculateLogStats } from "./utils";
1515

1616
/**
1717
* Generic Kysely database interface
@@ -82,7 +82,7 @@ function detectProvider(db: Kysely<KyselyDB>): DatabaseProvider {
8282
return "mssql";
8383
}
8484

85-
console.warn(
85+
logger.warn(
8686
"[Kysely Store] Could not detect database provider, defaulting to PostgreSQL"
8787
);
8888
return "pg";
@@ -151,7 +151,7 @@ export function createKyselyStore(options: KyselyAdapterConfig): Storage {
151151
const provider = options.provider ?? detectProvider(db);
152152

153153
if (provider === "sqlite") {
154-
console.warn(
154+
logger.warn(
155155
"[Kysely Store] SQLite detected: JSON queries use TEXT storage, not native JSON"
156156
);
157157
}
@@ -465,21 +465,7 @@ export function createKyselyStore(options: KyselyAdapterConfig): Storage {
465465
context.transformAuditLogOutput?.(row)!
466466
);
467467

468-
const byAction: Partial<Record<string, number>> = {};
469-
let lastActivity: string | null = null;
470-
471-
for (const log of logs) {
472-
byAction[log.action] = (byAction[log.action] || 0) + 1;
473-
if (!lastActivity || log.timestamp > lastActivity) {
474-
lastActivity = log.timestamp;
475-
}
476-
}
477-
478-
return {
479-
total: logs.length,
480-
byAction,
481-
lastActivity,
482-
};
468+
return calculateLogStats(logs);
483469
},
484470
}),
485471
};
@@ -516,4 +502,4 @@ export class KyselyStore implements Storage {
516502
countLogs = (query: AuditLogQuery) => this.storage.countLogs?.(query) ?? Promise.resolve(0);
517503
deleteLogs = (query: AuditLogQuery) => this.storage.deleteLogs?.(query) ?? Promise.resolve(0);
518504
getLogStats = (ownerId: string) => this.storage.getLogStats?.(ownerId) ?? Promise.resolve({ total: 0, byAction: {}, lastActivity: null });
519-
}
505+
}

src/storage/memory.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import type {
55
AuditLogStats,
66
} from "../types/audit-log-types";
77
import type { Storage } from "../types/storage-types";
8-
9-
const DEFAULT_QUERY_LIMIT = 100;
8+
import { DEFAULT_QUERY_LIMIT, calculateLogStats } from "./utils";
109

1110
export class MemoryStore implements Storage {
1211
private readonly keys = new Map<string, ApiKeyRecord>();
@@ -154,18 +153,7 @@ export class MemoryStore implements Storage {
154153
const logs = Array.from(this.logs.values()).filter(
155154
(log) => log.ownerId === ownerId
156155
);
157-
158-
const byAction: Partial<Record<string, number>> = {};
159-
let lastActivity: string | null = null;
160-
161-
for (const log of logs) {
162-
byAction[log.action] = (byAction[log.action] || 0) + 1;
163-
if (!lastActivity || log.timestamp > lastActivity) {
164-
lastActivity = log.timestamp;
165-
}
166-
}
167-
168-
return { total: logs.length, byAction, lastActivity };
156+
return calculateLogStats(logs);
169157
}
170158

171159
private filterLogs(query: AuditLogQuery): AuditLog[] {

src/storage/prisma.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
createAdapterFactory,
1010
type SchemaConfig,
1111
} from "./adapter-factory";
12-
13-
const DEFAULT_QUERY_LIMIT = 100;
12+
import { DEFAULT_QUERY_LIMIT, calculateLogStats } from "./utils";
1413

1514
/**
1615
* Generic Prisma Client interface
@@ -420,21 +419,7 @@ export function createPrismaStore(options: PrismaAdapterConfig): Storage {
420419
context.transformAuditLogOutput?.(row)!
421420
);
422421

423-
const byAction: Partial<Record<string, number>> = {};
424-
let lastActivity: string | null = null;
425-
426-
for (const log of logs) {
427-
byAction[log.action] = (byAction[log.action] || 0) + 1;
428-
if (!lastActivity || log.timestamp > lastActivity) {
429-
lastActivity = log.timestamp;
430-
}
431-
}
432-
433-
return {
434-
total: logs.length,
435-
byAction,
436-
lastActivity,
437-
};
422+
return calculateLogStats(logs);
438423
},
439424
}),
440425
};

0 commit comments

Comments
 (0)