@lyxa.ai/core 1.3.181 → 1.3.182

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.
@@ -33,7 +33,8 @@ export declare const t: import("@trpc/server").TRPCRootObject<import("./context"
33
33
  };
34
34
  transformer: false;
35
35
  }>;
36
- export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<import("./context").LyxaHTTPContext, object, object, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
36
+ export declare const slowApiMiddleware: import("@trpc/server").TRPCMiddlewareBuilder<import("./context").LyxaHTTPContext, object, object, unknown>;
37
+ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<import("./context").LyxaHTTPContext, object, {}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
37
38
  export declare const createTRPCRouter: import("@trpc/server").TRPCRouterBuilder<{
38
39
  ctx: import("./context").LyxaHTTPContext;
39
40
  meta: object;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TRPCError = exports.observable = exports.createHTTPHandler = exports.createCallerFactory = exports.createTRPCRouter = exports.publicProcedure = exports.t = void 0;
3
+ exports.TRPCError = exports.observable = exports.createHTTPHandler = exports.createCallerFactory = exports.createTRPCRouter = exports.publicProcedure = exports.slowApiMiddleware = exports.t = void 0;
4
4
  const server_1 = require("@trpc/server");
5
5
  const zod_1 = require("zod");
6
+ const index_1 = require("../../index");
7
+ const enum_1 = require("../../utilities/enum");
6
8
  exports.t = server_1.initTRPC.context().create({
7
9
  errorFormatter({ shape, error }) {
8
10
  let zodErrors = null;
@@ -25,7 +27,26 @@ exports.t = server_1.initTRPC.context().create({
25
27
  };
26
28
  },
27
29
  });
28
- exports.publicProcedure = exports.t.procedure;
30
+ const SLOW_API_THRESHOLD_MS = 10000;
31
+ exports.slowApiMiddleware = exports.t.middleware(async ({ path, ctx, next }) => {
32
+ const logger = (0, index_1.getLibraries)().getLoggerKit();
33
+ const startTime = Date.now();
34
+ const result = await next();
35
+ const duration = Date.now() - startTime;
36
+ if (duration > SLOW_API_THRESHOLD_MS) {
37
+ const logEntry = {
38
+ timestamp: new Date().toISOString(),
39
+ path,
40
+ duration,
41
+ userId: ctx.entity?.id,
42
+ userType: ctx.entity?.type,
43
+ message: `Slow API call detected: ${path} took ${duration}ms`,
44
+ };
45
+ logger.warn(logEntry.message, { tag: enum_1.LogTag.HTTP_REQUEST, data: logEntry });
46
+ }
47
+ return result;
48
+ });
49
+ exports.publicProcedure = exports.t.procedure.use(exports.slowApiMiddleware);
29
50
  exports.createTRPCRouter = exports.t.router;
30
51
  exports.createCallerFactory = exports.t.createCallerFactory;
31
52
  var standalone_1 = require("@trpc/server/adapters/standalone");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/trpc/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AACxC,6BAA+B;AAGlB,QAAA,CAAC,GAAG,iBAAQ,CAAC,OAAO,EAAe,CAAC,MAAM,CAAC;IACvD,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE;QAC9B,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,KAAK,YAAY,cAAQ,EAAE,CAAC;YACrE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACxC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC;QACnC,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAE5D,OAAO;YACN,GAAG,KAAK;YACR,OAAO,EACN,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;gBACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO;gBACnD,CAAC,CAAC,KAAK,CAAC,OAAO;YACjB,IAAI,EAAE;gBACL,GAAG,KAAK,CAAC,IAAI;gBAEb,KAAK,EAAE,SAAS;gBAChB,IAAI,EAAE,SAAS;aACf;YAED,KAAK,EAAE,SAAS;SAChB,CAAC;IACH,CAAC;CACD,CAAC,CAAC;AAEU,QAAA,eAAe,GAAG,SAAC,CAAC,SAAS,CAAC;AAC9B,QAAA,gBAAgB,GAAG,SAAC,CAAC,MAAM,CAAC;AAC5B,QAAA,mBAAmB,GAAG,SAAC,CAAC,mBAAmB,CAAC;AAIzD,+DAAqE;AAA5D,+GAAA,iBAAiB,OAAA;AAC1B,sDAAqD;AAA5C,wGAAA,UAAU,OAAA;AACnB,uCAAyC;AAAhC,mGAAA,SAAS,OAAA","sourcesContent":["import { initTRPC } from '@trpc/server';\nimport { ZodError } from 'zod';\nimport { LyxaContext } from './context';\n\nexport const t = initTRPC.context<LyxaContext>().create({\n\terrorFormatter({ shape, error }) {\n\t\tlet zodErrors = null;\n\n\t\tif (error.code === 'BAD_REQUEST' && error.cause instanceof ZodError) {\n\t\t\tconst flattened = error.cause.flatten();\n\t\t\tzodErrors = flattened.fieldErrors;\n\t\t}\n\n\t\tconsole.log('Error:', error, shape, 'error log', zodErrors);\n\n\t\treturn {\n\t\t\t...shape,\n\t\t\tmessage:\n\t\t\t\tzodErrors && typeof zodErrors === 'object'\n\t\t\t\t\t? Object.values(zodErrors)[0]?.[0] || shape.message\n\t\t\t\t\t: shape.message,\n\t\t\tdata: {\n\t\t\t\t...shape.data,\n\n\t\t\t\tstack: undefined,\n\t\t\t\tpath: undefined,\n\t\t\t},\n\t\t\t// Prevent stack trace from being returned in the response\n\t\t\tstack: undefined,\n\t\t};\n\t},\n});\n\nexport const publicProcedure = t.procedure;\nexport const createTRPCRouter = t.router;\nexport const createCallerFactory = t.createCallerFactory;\n\nexport type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';\nexport type { AnyTRPCRouter } from '@trpc/server';\nexport { createHTTPHandler } from '@trpc/server/adapters/standalone';\nexport { observable } from '@trpc/server/observable';\nexport { TRPCError } from '@trpc/server';\n\nexport type LyxaRouter = ReturnType<typeof createTRPCRouter>;"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/trpc/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AACxC,6BAA+B;AAE/B,uCAA2C;AAC3C,+CAA8C;AAEjC,QAAA,CAAC,GAAG,iBAAQ,CAAC,OAAO,EAAe,CAAC,MAAM,CAAC;IACvD,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE;QAC9B,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,KAAK,YAAY,cAAQ,EAAE,CAAC;YACrE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACxC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC;QACnC,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAE5D,OAAO;YACN,GAAG,KAAK;YACR,OAAO,EACN,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;gBACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO;gBACnD,CAAC,CAAC,KAAK,CAAC,OAAO;YACjB,IAAI,EAAE;gBACL,GAAG,KAAK,CAAC,IAAI;gBAEb,KAAK,EAAE,SAAS;gBAChB,IAAI,EAAE,SAAS;aACf;YAED,KAA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AACnB,uCAAyC;AAAhC,mGAAA,SAAS,OAAA","sourcesContent":["import { initTRPC } from '@trpc/server';\nimport { ZodError } from 'zod';\nimport { LyxaContext } from './context';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nexport const t = initTRPC.context<LyxaContext>().create({\n\terrorFormatter({ shape, error }) {\n\t\tlet zodErrors = null;\n\n\t\tif (error.code === 'BAD_REQUEST' && error.cause instanceof ZodError) {\n\t\t\tconst flattened = error.cause.flatten();\n\t\t\tzodErrors = flattened.fieldErrors;\n\t\t}\n\n\t\tconsole.log('Error:', error, shape, 'error log', zodErrors);\n\n\t\treturn {\n\t\t\t...shape,\n\t\t\tmessage:\n\t\t\t\tzodErrors && typeof zodErrors === 'object'\n\t\t\t\t\t? Object.values(zodErrors)[0]?.[0] || shape.message\n\t\t\t\t\t: shape.message,\n\t\t\tdata: {\n\t\t\t\t...shape.data,\n\n\t\t\t\tstack: undefined,\n\t\t\t\tpath: undefined,\n\t\t\t},\n\t\t\t// Prevent stack trace from being returned in the response\n\t\t\tstack: undefined,\n\t\t};\n\t},\n});\n\ninterface SlowApiLogEntry {\n\ttimestamp: string;\n\tpath: string;\n\tduration: number;\n\tinput?: any;\n\tuserId?: string;\n\tuserType?: string;\n}\n\nconst SLOW_API_THRESHOLD_MS = 10000; // 10 second\n\nexport const slowApiMiddleware = t.middleware(async ({ path, ctx, next }) => {\n\tconst logger = getLibraries().getLoggerKit();\n\tconst startTime = Date.now();\n\n\tconst result = await next();\n\n\tconst duration = Date.now() - startTime;\n\n\tif (duration > SLOW_API_THRESHOLD_MS) {\n\t\tconst logEntry: SlowApiLogEntry & { message: string } = {\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpath,\n\t\t\tduration,\n\t\t\tuserId: ctx.entity?.id,\n\t\t\tuserType: ctx.entity?.type,\n\t\t\tmessage: `Slow API call detected: ${path} took ${duration}ms`,\n\t\t};\n\n\t\t// Pass `message` so Mongoose validation passes\n\t\tlogger.warn(logEntry.message, { tag: LogTag.HTTP_REQUEST, data: logEntry });\n\t}\n\n\treturn result;\n});\n\nexport const publicProcedure = t.procedure.use(slowApiMiddleware);\nexport const createTRPCRouter = t.router;\nexport const createCallerFactory = t.createCallerFactory;\n\nexport type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';\nexport type { AnyTRPCRouter } from '@trpc/server';\nexport { createHTTPHandler } from '@trpc/server/adapters/standalone';\nexport { observable } from '@trpc/server/observable';\nexport { TRPCError } from '@trpc/server';\n\nexport type LyxaRouter = ReturnType<typeof createTRPCRouter>;"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.3.181
25
+ Version: 1.3.182
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.181",
3
+ "version": "1.3.182",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- populate?: any;
30
29
  select?: Record<string, 0 | 1> | undefined;
30
+ populate?: any;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- populate?: any;
40
39
  select?: Record<string, 0 | 1> | undefined;
40
+ populate?: any;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -733,12 +733,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
733
733
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
734
734
  }, "strip", z.ZodTypeAny, {
735
735
  _id: import("mongoose").Types.ObjectId;
736
- populate?: any;
737
736
  select?: Record<string, 0 | 1> | undefined;
737
+ populate?: any;
738
738
  }, {
739
739
  _id: string | import("mongoose").Types.ObjectId;
740
- populate?: any;
741
740
  select?: Record<string, 0 | 1> | undefined;
741
+ populate?: any;
742
742
  }>;
743
743
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
744
744
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -751,12 +751,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
751
751
  _id: import("mongoose").Types.ObjectId;
752
752
  withAttributeHiddenItems: boolean;
753
753
  withAddonsHiddenItems: boolean;
754
- populate?: any;
755
754
  select?: Record<string, 0 | 1> | undefined;
755
+ populate?: any;
756
756
  }, {
757
757
  _id: string | import("mongoose").Types.ObjectId;
758
- populate?: any;
759
758
  select?: Record<string, 0 | 1> | undefined;
759
+ populate?: any;
760
760
  withAttributeHiddenItems?: boolean | undefined;
761
761
  withAddonsHiddenItems?: boolean | undefined;
762
762
  }>;
@@ -768,13 +768,13 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
768
768
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
769
769
  }, "strip", z.ZodTypeAny, {
770
770
  _id: import("mongoose").Types.ObjectId;
771
- populate?: any;
772
771
  select?: Record<string, 0 | 1> | undefined;
772
+ populate?: any;
773
773
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
774
774
  }, {
775
775
  _id: string | import("mongoose").Types.ObjectId;
776
- populate?: any;
777
776
  select?: Record<string, 0 | 1> | undefined;
777
+ populate?: any;
778
778
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
779
779
  }>;
780
780
  export type GetOrderByIdInputDTO = DTO<typeof GetOrderByIdInputSchema>;
@@ -782,11 +782,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
782
782
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
783
783
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
784
784
  }, "strip", z.ZodTypeAny, {
785
- populate?: any;
786
785
  select?: Record<string, 0 | 1> | undefined;
787
- }, {
788
786
  populate?: any;
787
+ }, {
789
788
  select?: Record<string, 0 | 1> | undefined;
789
+ populate?: any;
790
790
  }>>;
791
791
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
792
792
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -794,12 +794,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
794
794
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
795
795
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
796
796
  }, "strip", z.ZodTypeAny, {
797
- populate?: any;
798
797
  select?: Record<string, 0 | 1> | undefined;
798
+ populate?: any;
799
799
  query?: Record<string, any> | undefined;
800
800
  }, {
801
- populate?: any;
802
801
  select?: Record<string, 0 | 1> | undefined;
802
+ populate?: any;
803
803
  query?: Record<string, any> | undefined;
804
804
  }>;
805
805
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.3.181",
3
+ "version": "1.3.182",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",