@xpert-ai/plugin-sdk 3.6.2 → 3.6.3

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.
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-sdk",
3
- "version": "3.6.2",
3
+ "version": "3.6.3",
4
4
  "license": "AGPL-3.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/xpert-ai/xpert.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/xpert-ai/xpert/issues"
11
+ },
5
12
  "dependencies": {},
6
13
  "main": "./index.cjs.js",
7
14
  "module": "./index.esm.js",
@@ -16,9 +23,11 @@
16
23
  "lodash-es": "*",
17
24
  "i18next-fs-backend": "*",
18
25
  "i18next": "*",
19
- "zod": "*",
26
+ "jsonwebtoken": "*",
20
27
  "fs": "*",
28
+ "path": "*",
29
+ "passport-jwt": "*",
21
30
  "stream": "*",
22
- "path": "*"
31
+ "zod": "*"
23
32
  }
24
33
  }
@@ -0,0 +1,2 @@
1
+ export * from './request-context';
2
+ export * from './request-context.middleware';
@@ -0,0 +1,46 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { IUser, LanguagesEnum, PermissionsEnum, RolesEnum } from '@metad/contracts';
4
+ import type { IncomingMessage, ServerResponse } from 'http';
5
+ import { AsyncLocalStorage } from 'node:async_hooks';
6
+ export declare class RequestContext {
7
+ readonly request: IncomingMessage;
8
+ readonly response: ServerResponse;
9
+ readonly reqId: string;
10
+ readonly userId?: string;
11
+ readonly extras: Record<string, any>;
12
+ constructor(request: IncomingMessage, response: ServerResponse, reqId: string, userId?: string, extras?: Record<string, any>);
13
+ static currentRequestContext(): RequestContext;
14
+ static currentRequest(): IncomingMessage;
15
+ static currentTenantId(): string;
16
+ static currentUserId(): string;
17
+ static currentRoleId(): string;
18
+ static currentUser(throwError?: boolean): IUser;
19
+ static hasPermission(permission: PermissionsEnum | string, throwError?: boolean): boolean;
20
+ /**
21
+ * Retrieves the language code from the headers of the current request.
22
+ * @returns The language code (LanguagesEnum) extracted from the headers, or the default language (ENGLISH) if not found.
23
+ */
24
+ static getLanguageCode(): LanguagesEnum;
25
+ static getOrganizationId(): string;
26
+ static hasPermissions(findPermissions: Array<PermissionsEnum | string>, throwError?: boolean): boolean;
27
+ static hasAnyPermission(findPermissions: PermissionsEnum[], throwError?: boolean): boolean;
28
+ static currentToken(throwError?: boolean): any;
29
+ /**
30
+ * Checks if the current user has a specific role.
31
+ * @param {RolesEnum} role - The role to check.
32
+ * @param {boolean} throwError - Flag indicating whether to throw an error if the role is not granted.
33
+ * @returns {boolean} - True if the user has the role, otherwise false.
34
+ */
35
+ static hasRole(role: RolesEnum, throwError?: boolean): boolean;
36
+ /**
37
+ * Checks if the current request context has any of the specified roles.
38
+ *
39
+ * @param roles - An array of roles to check.
40
+ * @param throwError - Whether to throw an error if no roles are found.
41
+ * @returns True if any of the required roles are found, otherwise false.
42
+ */
43
+ static hasRoles(roles: RolesEnum[], throwError?: boolean): boolean;
44
+ }
45
+ export declare const als: AsyncLocalStorage<RequestContext>;
46
+ export declare function getRequestContext(): RequestContext;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { NestMiddleware } from '@nestjs/common';
3
+ import { IncomingMessage, ServerResponse } from 'node:http';
4
+ export declare class RequestContextMiddleware implements NestMiddleware {
5
+ use(req: IncomingMessage, _res: ServerResponse, next: () => void): void;
6
+ }
7
+ export declare function runWithRequestContext(req: IncomingMessage, res: ServerResponse, next: () => void): void;
@@ -3,3 +3,4 @@ export * from './permissions';
3
3
  export * from './schema';
4
4
  export * from './i18n';
5
5
  export * from './utils';
6
+ export * from './context/index';
@@ -27,5 +27,5 @@ export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstanding
27
27
  /**
28
28
  * Understand image files (e.g., OCR, VLM, Chart Parsing)
29
29
  */
30
- understandImages(doc: IKnowledgeDocument<ChunkMetadata>, config: TConfig): Promise<TImageUnderstandingResult>;
30
+ understandImages(doc: IKnowledgeDocument, config: TConfig): Promise<TImageUnderstandingResult>;
31
31
  }