@lyxa.ai/core 1.1.46 → 1.1.47

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.
@@ -5,7 +5,7 @@ import { AuthEntityType, TokenType } from '../auth';
5
5
  import jwt from 'jsonwebtoken';
6
6
  import type { IncomingMessage, ServerResponse } from 'http';
7
7
  import { Types } from 'mongoose';
8
- import { UserRef } from '../../utilities/enum';
8
+ import { AdminRole, ShopRole, UserRef, VendorRole } from '../../utilities/enum';
9
9
  export interface EntityContext extends jwt.JwtPayload {
10
10
  id: string;
11
11
  type: AuthEntityType;
@@ -31,6 +31,7 @@ export declare const createLyxaWsContext: (opts: CreateWSSContextFnOptions) => P
31
31
  export type UserInfo = {
32
32
  user: Types.ObjectId;
33
33
  userType: UserRef;
34
+ userRole: AdminRole | VendorRole | ShopRole;
34
35
  };
35
- export declare function withUserContext<T extends object>(input: T, ctx: LyxaContext): T & LyxaContext;
36
+ export declare function withUserContext<T extends object>(input: T, ctx: LyxaContext): T & UserInfo;
36
37
  export type LyxaContext = Awaited<ReturnType<typeof createLyxaContext>>;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLyxaWsContext = exports.createLyxaContext = void 0;
4
4
  exports.withUserContext = withUserContext;
5
+ const mongoose_1 = require("mongoose");
6
+ const auth_ref_mapper_1 = require("../../utilities/auth-ref.mapper");
5
7
  const createLyxaContext = async (opts) => {
6
8
  return {
7
9
  entity: undefined,
@@ -32,7 +34,9 @@ function withUserContext(input, ctx) {
32
34
  throw new Error('No entity in context');
33
35
  return {
34
36
  ...input,
35
- ...ctx,
37
+ user: new mongoose_1.Types.ObjectId(entity.id),
38
+ userType: auth_ref_mapper_1.AuthEntityToUserRefMap[entity.type],
39
+ userRole: entity.parameters?.role,
36
40
  };
37
41
  }
38
42
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"/","sources":["libraries/trpc/context.ts"],"names":[],"mappings":";;;AAyEA,0CAQC;AAhDM,MAAM,iBAAiB,GAAG,KAAK,EACrC,IAAgG,EACrE,EAAE;IAC7B,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,iBAAiB,qBAY5B;AAEK,MAAM,mBAAmB,GAAG,KAAK,EAAE,IAA+B,EAA0B,EAAE;IACpG,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B;AAgBF,SAAgB,eAAe,CAAmB,KAAQ,EAAE,GAAgB;IAC3E,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAErD,OAAO;QACN,GAAG,KAAK;QACR,GAAG,GAAG;KACN,CAAC;AACH,CAAC","sourcesContent":["import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';\nimport type { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';\nimport type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws';\nimport { AuthEntityType, TokenType } from '../auth';\nimport jwt from 'jsonwebtoken';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport { Types } from 'mongoose';\nimport { UserRef } from '../../utilities/enum';\n\nexport interface EntityContext extends jwt.JwtPayload {\n\tid: string;\n\ttype: AuthEntityType;\n\tparameters: Record<string, unknown>;\n}\n\nexport interface LyxaContextParams {\n\tentity?: EntityContext;\n\trequestId?: string;\n\ttokenType?: TokenType;\n\tusedRefreshToken?: boolean;\n\ttokenRenewed?: boolean;\n}\n\nexport interface LyxaHTTPContext extends LyxaContextParams {\n\treq: IncomingMessage;\n\tres: ServerResponse;\n}\n\nexport interface LyxaWSContext extends LyxaContextParams {\n\treq: any;\n\tres: any;\n}\n\nexport const createLyxaContext = async (\n\topts: CreateHTTPContextOptions | NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>\n): Promise<LyxaHTTPContext> => {\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport const createLyxaWsContext = async (opts: CreateWSSContextFnOptions): Promise<LyxaWSContext> => {\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport type UserInfo = {\n\tuser: Types.ObjectId;\n\tuserType: UserRef;\n};\n\n/**\n *\n * Enriches the input object with user context information from the LyxaContext.\n *\n * @param input\n * @param ctx\n *\n * @example const inp: SendMessageDTO = withUserContext(input, ctx);\n */\nexport function withUserContext<T extends object>(input: T, ctx: LyxaContext): T & LyxaContext {\n\tconst entity = ctx.entity;\n\tif (!entity) throw new Error('No entity in context');\n\n\treturn {\n\t\t...input,\n\t\t...ctx,\n\t};\n}\n\nexport type LyxaContext = Awaited<ReturnType<typeof createLyxaContext>>;\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"/","sources":["libraries/trpc/context.ts"],"names":[],"mappings":";;;AA2EA,0CAUC;AA/ED,uCAAiC;AACjC,qEAAyE;AA2BlE,MAAM,iBAAiB,GAAG,KAAK,EACrC,IAAgG,EACrE,EAAE;IAC7B,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,iBAAiB,qBAY5B;AAEK,MAAM,mBAAmB,GAAG,KAAK,EAAE,IAA+B,EAA0B,EAAE;IACpG,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B;AAiBF,SAAgB,eAAe,CAAmB,KAAQ,EAAE,GAAgB;IAC3E,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAErD,OAAO;QACN,GAAG,KAAK;QACR,IAAI,EAAE,IAAI,gBAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,QAAQ,EAAE,wCAAsB,CAAC,MAAM,CAAC,IAAI,CAAC;QAC7C,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,IAAyC;KACtE,CAAC;AACH,CAAC","sourcesContent":["import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';\nimport type { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';\nimport type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws';\nimport { AuthEntityType, TokenType } from '../auth';\nimport jwt from 'jsonwebtoken';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport { Types } from 'mongoose';\nimport { AuthEntityToUserRefMap } from '../../utilities/auth-ref.mapper';\nimport { AdminRole, ShopRole, UserRef, VendorRole } from '../../utilities/enum';\n\nexport interface EntityContext extends jwt.JwtPayload {\n\tid: string;\n\ttype: AuthEntityType;\n\tparameters: Record<string, unknown>;\n}\n\nexport interface LyxaContextParams {\n\tentity?: EntityContext;\n\trequestId?: string;\n\ttokenType?: TokenType;\n\tusedRefreshToken?: boolean;\n\ttokenRenewed?: boolean;\n}\n\nexport interface LyxaHTTPContext extends LyxaContextParams {\n\treq: IncomingMessage;\n\tres: ServerResponse;\n}\n\nexport interface LyxaWSContext extends LyxaContextParams {\n\treq: any;\n\tres: any;\n}\n\nexport const createLyxaContext = async (\n\topts: CreateHTTPContextOptions | NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>\n): Promise<LyxaHTTPContext> => {\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport const createLyxaWsContext = async (opts: CreateWSSContextFnOptions): Promise<LyxaWSContext> => {\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport type UserInfo = {\n\tuser: Types.ObjectId;\n\tuserType: UserRef;\n\tuserRole: AdminRole | VendorRole | ShopRole;\n};\n\n/**\n *\n * Enriches the input object with user context information from the LyxaContext.\n *\n * @param input\n * @param ctx\n *\n * @example const inp: SendMessageDTO = withUserContext(input, ctx);\n */\nexport function withUserContext<T extends object>(input: T, ctx: LyxaContext): T & UserInfo {\n\tconst entity = ctx.entity;\n\tif (!entity) throw new Error('No entity in context');\n\n\treturn {\n\t\t...input,\n\t\tuser: new Types.ObjectId(entity.id),\n\t\tuserType: AuthEntityToUserRefMap[entity.type],\n\t\tuserRole: entity.parameters?.role as AdminRole | VendorRole | ShopRole,\n\t};\n}\n\nexport type LyxaContext = Awaited<ReturnType<typeof createLyxaContext>>;\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.1.46
25
+ Version: 1.1.47
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.1.46",
3
+ "version": "1.1.47",
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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.1.46",
3
+ "version": "1.1.47",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",