refactor(logs): move to core package (#4586)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import superjson from "superjson";
|
||||
|
||||
import { decryptSecret, encryptSecret } from "@homarr/common/server";
|
||||
import { logger } from "@homarr/log";
|
||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
||||
import { createGetSetChannel } from "@homarr/redis";
|
||||
|
||||
const localLogger = logger.child({ module: "SessionStore" });
|
||||
const logger = createLogger({ module: "sessionStore" });
|
||||
|
||||
export const createSessionStore = <TValue>(integration: { id: string }) => {
|
||||
const channelName = `session-store:${integration.id}`;
|
||||
@@ -12,26 +13,26 @@ export const createSessionStore = <TValue>(integration: { id: string }) => {
|
||||
|
||||
return {
|
||||
async getAsync() {
|
||||
localLogger.debug("Getting session from store", { store: channelName });
|
||||
logger.debug("Getting session from store", { store: channelName });
|
||||
const value = await channel.getAsync();
|
||||
if (!value) return null;
|
||||
try {
|
||||
return superjson.parse<TValue>(decryptSecret(value));
|
||||
} catch (error) {
|
||||
localLogger.warn("Failed to load session", { store: channelName, error });
|
||||
logger.warn("Failed to load session", { store: channelName, error });
|
||||
return null;
|
||||
}
|
||||
},
|
||||
async setAsync(value: TValue) {
|
||||
localLogger.debug("Updating session in store", { store: channelName });
|
||||
logger.debug("Updating session in store", { store: channelName });
|
||||
try {
|
||||
await channel.setAsync(encryptSecret(superjson.stringify(value)));
|
||||
} catch (error) {
|
||||
localLogger.error("Failed to save session", { store: channelName, error });
|
||||
logger.error(new ErrorWithMetadata("Failed to save session", { store: channelName }, { cause: error }));
|
||||
}
|
||||
},
|
||||
async clearAsync() {
|
||||
localLogger.debug("Cleared session in store", { store: channelName });
|
||||
logger.debug("Cleared session in store", { store: channelName });
|
||||
await channel.removeAsync();
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user