From 6c554e91577a3ccec92d65da06742e599812eb33 Mon Sep 17 00:00:00 2001 From: Mayank Thakur Date: Thu, 26 Oct 2023 17:03:35 +0530 Subject: [PATCH] feat: added debug flag in the SuperTokenConfig in the init() for logging --- lib/build/framework/fastify/index.d.ts | 11 +++++++---- lib/build/framework/utils.d.ts | 2 +- lib/build/logger.js | 15 +++++++-------- lib/build/supertokens.js | 4 ++++ lib/build/types.d.ts | 1 + lib/ts/logger.ts | 11 +++++------ lib/ts/supertokens.ts | 4 ++++ lib/ts/types.ts | 1 + 8 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/build/framework/fastify/index.d.ts b/lib/build/framework/fastify/index.d.ts index 3cca3a1a2..fb2d3fe21 100644 --- a/lib/build/framework/fastify/index.d.ts +++ b/lib/build/framework/fastify/index.d.ts @@ -1,18 +1,21 @@ // @ts-nocheck /// export type { SessionRequest } from "./framework"; -export declare const plugin: import("fastify").FastifyPluginCallback, import("http").Server>; +export declare const plugin: import("fastify").FastifyPluginCallback< + Record, + import("fastify").RawServerDefault +>; export declare const errorHandler: () => ( err: any, req: import("fastify").FastifyRequest< import("fastify/types/route").RouteGenericInterface, - import("http").Server, + import("fastify").RawServerDefault, import("http").IncomingMessage >, res: import("fastify").FastifyReply< - import("http").Server, + import("fastify").RawServerDefault, import("http").IncomingMessage, - import("http").ServerResponse, + import("http").ServerResponse, import("fastify/types/route").RouteGenericInterface, unknown > diff --git a/lib/build/framework/utils.d.ts b/lib/build/framework/utils.d.ts index 636a97724..123ddf23c 100644 --- a/lib/build/framework/utils.d.ts +++ b/lib/build/framework/utils.d.ts @@ -45,7 +45,7 @@ export declare function setCookieForServerResponse( expires: number, path: string, sameSite: "strict" | "lax" | "none" -): ServerResponse; +): ServerResponse; export declare function getCookieValueToSetInHeader( prev: string | string[] | undefined, val: string | string[], diff --git a/lib/build/logger.js b/lib/build/logger.js index 520e67fc5..f95ac8e17 100644 --- a/lib/build/logger.js +++ b/lib/build/logger.js @@ -22,20 +22,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.logDebugMessage = void 0; const debug_1 = __importDefault(require("debug")); const version_1 = require("./version"); +// import SuperTokens from "./supertokens"; const SUPERTOKENS_DEBUG_NAMESPACE = "com.supertokens"; /* The debug logger below can be used to log debug messages in the following format com.supertokens {t: "2022-03-18T11:15:24.608Z", message: Your message, file: "/home/supertokens-node/lib/build/supertokens.js:231:18" sdkVer: "9.2.0"} +0m */ function logDebugMessage(message) { - if (debug_1.default.enabled(SUPERTOKENS_DEBUG_NAMESPACE)) { - debug_1.default(SUPERTOKENS_DEBUG_NAMESPACE)( - `{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${ - version_1.version - }"}` - ); - console.log(); - } + debug_1.default(SUPERTOKENS_DEBUG_NAMESPACE)( + `{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${ + version_1.version + }"}` + ); + console.log(); } exports.logDebugMessage = logDebugMessage; let getFileLocation = () => { diff --git a/lib/build/supertokens.js b/lib/build/supertokens.js index 61c14e77d..f30b1ce66 100644 --- a/lib/build/supertokens.js +++ b/lib/build/supertokens.js @@ -28,6 +28,7 @@ const error_1 = __importDefault(require("./error")); const logger_1 = require("./logger"); const postSuperTokensInitCallbacks_1 = require("./postSuperTokensInitCallbacks"); const constants_2 = require("./recipe/multitenancy/constants"); +const debug_1 = __importDefault(require("debug")); class SuperTokens { constructor(config) { var _a, _b; @@ -262,6 +263,9 @@ class SuperTokens { } return userContext._default.request; }; + if (config.debug) { + debug_1.default.enable("com.supertokens"); + } logger_1.logDebugMessage("Started SuperTokens with debug logging (supertokens.init called)"); const originToPrint = config.appInfo.origin === undefined diff --git a/lib/build/types.d.ts b/lib/build/types.d.ts index 6a924d65d..b57c40ce9 100644 --- a/lib/build/types.d.ts +++ b/lib/build/types.d.ts @@ -35,6 +35,7 @@ export declare type TypeInput = { recipeList: RecipeListFunction[]; telemetry?: boolean; isInServerlessEnv?: boolean; + debug?: boolean; }; export declare type RecipeListFunction = (appInfo: NormalisedAppinfo, isInServerlessEnv: boolean) => RecipeModule; export declare type APIHandled = { diff --git a/lib/ts/logger.ts b/lib/ts/logger.ts index 42fa1be9b..1acc6037e 100644 --- a/lib/ts/logger.ts +++ b/lib/ts/logger.ts @@ -15,6 +15,7 @@ import debug from "debug"; import { version } from "./version"; +// import SuperTokens from "./supertokens"; const SUPERTOKENS_DEBUG_NAMESPACE = "com.supertokens"; /* @@ -23,12 +24,10 @@ const SUPERTOKENS_DEBUG_NAMESPACE = "com.supertokens"; */ function logDebugMessage(message: string) { - if (debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE)) { - debug(SUPERTOKENS_DEBUG_NAMESPACE)( - `{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${version}"}` - ); - console.log(); - } + debug(SUPERTOKENS_DEBUG_NAMESPACE)( + `{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${version}"}` + ); + console.log(); } let getFileLocation = () => { diff --git a/lib/ts/supertokens.ts b/lib/ts/supertokens.ts index 4308d3115..31e4ebe2e 100644 --- a/lib/ts/supertokens.ts +++ b/lib/ts/supertokens.ts @@ -32,6 +32,7 @@ import STError from "./error"; import { logDebugMessage } from "./logger"; import { PostSuperTokensInitCallbacks } from "./postSuperTokensInitCallbacks"; import { DEFAULT_TENANT_ID } from "./recipe/multitenancy/constants"; +import debug from "debug"; export default class SuperTokens { private static instance: SuperTokens | undefined; @@ -49,6 +50,9 @@ export default class SuperTokens { telemetryEnabled: boolean; constructor(config: TypeInput) { + if (config.debug) { + debug.enable("com.supertokens"); + } logDebugMessage("Started SuperTokens with debug logging (supertokens.init called)"); const originToPrint = config.appInfo.origin === undefined diff --git a/lib/ts/types.ts b/lib/ts/types.ts index 6699e29c0..a72063d4e 100644 --- a/lib/ts/types.ts +++ b/lib/ts/types.ts @@ -53,6 +53,7 @@ export type TypeInput = { recipeList: RecipeListFunction[]; telemetry?: boolean; isInServerlessEnv?: boolean; + debug?: boolean; }; export type RecipeListFunction = (appInfo: NormalisedAppinfo, isInServerlessEnv: boolean) => RecipeModule;