@solidxai/core 0.1.11 → 0.1.12-beta.1
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/dist/constants/error-messages.d.ts +1 -0
- package/dist/constants/error-messages.d.ts.map +1 -1
- package/dist/constants/error-messages.js +1 -0
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/controllers/authentication.controller.d.ts +1 -1
- package/dist/controllers/chatter-message.controller.d.ts +0 -2
- package/dist/controllers/chatter-message.controller.d.ts.map +1 -1
- package/dist/controllers/chatter-message.controller.js +0 -16
- package/dist/controllers/chatter-message.controller.js.map +1 -1
- package/dist/guards/access-token.guard.d.ts +5 -1
- package/dist/guards/access-token.guard.d.ts.map +1 -1
- package/dist/guards/access-token.guard.js +31 -3
- package/dist/guards/access-token.guard.js.map +1 -1
- package/dist/guards/authentication.guard.d.ts +1 -0
- package/dist/guards/authentication.guard.d.ts.map +1 -1
- package/dist/guards/authentication.guard.js +16 -1
- package/dist/guards/authentication.guard.js.map +1 -1
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
- package/dist/helpers/bootstrap.helper.js +3 -1
- package/dist/helpers/bootstrap.helper.js.map +1 -1
- package/dist/helpers/solid-core-error-codes-provider.service.d.ts.map +1 -1
- package/dist/helpers/solid-core-error-codes-provider.service.js +28 -0
- package/dist/helpers/solid-core-error-codes-provider.service.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/active-user-data.interface.d.ts +1 -0
- package/dist/interfaces/active-user-data.interface.d.ts.map +1 -1
- package/dist/interfaces/active-user-data.interface.js.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +18 -1
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +0 -1
- package/dist/services/active-session-storage.service.d.ts +10 -0
- package/dist/services/active-session-storage.service.d.ts.map +1 -0
- package/dist/services/active-session-storage.service.js +41 -0
- package/dist/services/active-session-storage.service.js.map +1 -0
- package/dist/services/authentication.service.d.ts +6 -3
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +29 -5
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/chatter-message.service.d.ts +2 -0
- package/dist/services/chatter-message.service.d.ts.map +1 -1
- package/dist/services/chatter-message.service.js +25 -2
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/crud.service.d.ts.map +1 -1
- package/dist/services/crud.service.js +1 -0
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/refresh-token-ids-storage.service.d.ts +6 -1
- package/dist/services/refresh-token-ids-storage.service.d.ts.map +1 -1
- package/dist/services/refresh-token-ids-storage.service.js +0 -2
- package/dist/services/refresh-token-ids-storage.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +18 -0
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +10 -0
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +2 -0
- package/dist/solid-core.module.js.map +1 -1
- package/package.json +1 -1
- package/src/constants/error-messages.ts +1 -0
- package/src/controllers/chatter-message.controller.ts +7 -7
- package/src/guards/access-token.guard.ts +43 -3
- package/src/guards/authentication.guard.ts +22 -1
- package/src/helpers/bootstrap.helper.ts +9 -3
- package/src/helpers/solid-core-error-codes-provider.service.ts +29 -1
- package/src/index.ts +1 -0
- package/src/interfaces/active-user-data.interface.ts +6 -0
- package/src/seeders/module-metadata-seeder.service.ts +23 -2
- package/src/seeders/seed-data/solid-core-metadata.json +0 -1
- package/src/services/active-session-storage.service.ts +24 -0
- package/src/services/authentication.service.ts +30 -3
- package/src/services/chatter-message.service.ts +32 -2
- package/src/services/crud.service.ts +1 -0
- package/src/services/refresh-token-ids-storage.service.ts +9 -8
- package/src/services/settings/default-settings-provider.service.ts +10 -1
- package/src/solid-core.module.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-messages.d.ts","sourceRoot":"","sources":["../../src/constants/error-messages.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyCE,MAAM,EAAE;2CACM,MAAM;+BAClB,MAAM;uCACE,MAAM
|
|
1
|
+
{"version":3,"file":"error-messages.d.ts","sourceRoot":"","sources":["../../src/constants/error-messages.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyCE,MAAM,EAAE;2CACM,MAAM;+BAClB,MAAM;uCACE,MAAM;;;;;;;;;;;;;;;;;6BAiChB,MAAM;;;;0BAOT,MAAM,GAAG,MAAM;mCACN,MAAM;;;;;;mCASN,MAAM,GAAG,MAAM;qCACb,MAAM;yDACc,MAAM;qCAC1B,MAAM;;mCAIR,MAAM;8BACX,MAAM,GAAG,MAAM;gCAGb,MAAM,GAAG,MAAM;;;kCAKb,MAAM,GAAG,MAAM;qCACZ,MAAM;8CAGG,MAAM,GAAG,MAAM;;yCAIpB,MAAM;;;;;yBAYtC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAElD,CAAC"}
|
|
@@ -47,6 +47,7 @@ exports.ERROR_MESSAGES = {
|
|
|
47
47
|
GROUP_BY_LIMIT: 'buildFilterQuery: Only 1 Group by field is supported currently.',
|
|
48
48
|
INVALID_GROUP_BY_COUNT: 'Exactly one groupBy field is required to count grouped records.',
|
|
49
49
|
FORBIDDEN: 'Forbidden',
|
|
50
|
+
RESOURCE_NOT_FOUND: 'The requested resource was not found.',
|
|
50
51
|
DUPLICATE_ENTRY: 'Duplicate entry. A record with similar unique fields already exists.',
|
|
51
52
|
ID_REQUIRED_FOR_UPDATE: 'Id is required for update.',
|
|
52
53
|
ID_REQUIRED_FOR_DELETE: 'Id is required for deletion.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-messages.js","sourceRoot":"","sources":["../../src/constants/error-messages.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAG;IAE1B,cAAc,EAAE,sBAAsB;IACtC,eAAe,EAAE,gCAAgC;IACjD,aAAa,EAAE,mBAAmB;IAClC,eAAe,EAAE,sEAAsE;IACvF,kBAAkB,EAAE,0BAA0B;IAC9C,4BAA4B,EAAE,oCAAoC;IAClE,2BAA2B,EAAE,yCAAyC;IACtE,kCAAkC,EAAE,2CAA2C;IAC/E,6BAA6B,EAAE,iEAAiE;IAChG,6BAA6B,EAAE,gDAAgD;IAC/E,8BAA8B,EAAE,kDAAkD;IAClF,mBAAmB,EAAE,sCAAsC;IAC3D,0BAA0B,EAAE,6CAA6C;IACzE,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,kBAAkB;IAC/B,yBAAyB,EAAE,+CAA+C;IAC1E,kBAAkB,EAAE,8DAA8D;IAClF,gBAAgB,EAAE,yBAAyB;IAC3C,iBAAiB,EAAE,+BAA+B;IAClD,0BAA0B,EAAE,uCAAuC;IACnE,eAAe,EAAE,0BAA0B;IAC3C,0BAA0B,EAAE,4BAA4B;IACxD,qBAAqB,EAAE,uBAAuB;IAC9C,aAAa,EAAE,eAAe;IAC9B,oBAAoB,EAAE,sBAAsB;IAC5C,iCAAiC,EAAE,wDAAwD;IAC3F,qDAAqD,EAAE,4EAA4E;IACnI,aAAa,EAAE,2CAA2C;IAE1D,mBAAmB,EAAE,qBAAqB;IAC1C,YAAY,EAAE,cAAc;IAC5B,sBAAsB,EAAE,+CAA+C;IACvE,oBAAoB,EAAE,uBAAuB;IAC7C,sBAAsB,EAAE,iCAAiC;IAGzD,uBAAuB,EAAE,yCAAyC;IAClE,mBAAmB,EAAE,2CAA2C;IAChE,e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,WAAW;KACtB;CAElD,CAAC","sourcesContent":["// backend/common/constants/error-messages.ts\n\nexport const ERROR_MESSAGES = {\n //authentication errors\n USER_NOT_FOUND: 'User does not exist.',\n USER_NOT_ACTIVE: 'User profile is not activated.',\n USER_INACTIVE: 'User is inactive.',\n ACCOUNT_BLOCKED: 'Your account has been blocked due to multiple failed login attempts.',\n PASSWORD_INCORRECT: 'Password does not match.',\n PUBLIC_REGISTRATION_DISABLED: 'Public registrations are disabled.',\n UNIQUE_CONSTRAINT_VIOLATION: 'A unique constraint violation occurred.',\n PASSWORDLESS_REGISTRATION_DISABLED: 'Passwordless registration is not enabled.',\n REGISTRATION_REQUIRES_CONTACT: 'Either mobile or email is required for initiating registration.',\n EMAIL_REQUIRED_FOR_VALIDATION: 'Email is required for email validation source.',\n MOBILE_REQUIRED_FOR_VALIDATION: 'Mobile is required for mobile validation source.',\n USER_ALREADY_EXISTS: 'User already exists. Please sign in.',\n VALIDATION_SOURCE_REQUIRED: 'At least one validation source is required.',\n INVALID_OTP: 'Invalid OTP.',\n OTP_EXPIRED: 'OTP has expired.',\n INVALID_VERIFICATION_TYPE: 'Invalid type. Must be either email or mobile.',\n NON_LOCAL_PROVIDER: 'User seems to have used a passwordless mode to authenticate.',\n USER_ID_MISMATCH: \"User ID's do not match.\",\n USERNAME_MISMATCH: \"User username's do not match.\",\n INCORRECT_CURRENT_PASSWORD: 'Incorrect current password specified.',\n PASSWORD_REUSED: 'Try a different password',\n INVALID_VERIFICATION_TOKEN: 'Invalid verification token',\n INVALID_REFRESH_TOKEN: 'Invalid refresh token',\n ACCESS_DENIED: 'Access denied',\n INVALID_USER_PROFILE: 'Invalid user profile',\n GOOGLE_OAUTH_PROFILE_FETCH_FAILED: 'Failed to fetch user profile from Google OAuth service',\n MICROSOFT_ACTIVE_DIRECTORY_OAUTH_PROFILE_FETCH_FAILED: 'Failed to fetch user profile from Microsoft Active Directory OAuth service',\n LOGOUT_FAILED: 'Logout failed due to an unexpected error.',\n\n INVALID_CREDENTIALS: 'Invalid credentials',\n LOGIN_FAILED: 'Login Failed',\n OLD_PASSWORD_INCORRECT: 'You have specified an incorrect old password.',\n INVALID_NEW_PASSWORD: 'Invalid new password.',\n PASSWORDS_DO_NOT_MATCH: 'New passwords are not matching.',\n\n // user management errors\n DELETE_SELF_NOT_ALLOWED: 'Deleting logged-in user is not allowed.',\n DELETE_IDS_REQUIRED: 'At least one ID is required for deletion.',\n USER_MISSING_ID: 'User must exist before initializing roles.',\n ROLES_NOT_FOUND: (roles: string[]) => `The following roles were not found: ${roles.join(', ')}`,\n USER_NOT_FOUND_BY_USERNAME: (username: string) => `User with username '${username}' not found.`,\n ROLE_NOT_FOUND: (roleName: string) => `Role '${roleName}' not found.`,\n PERMISSION_NOT_EXIST: (permission: string) => `Permission '${permission}' does not exist.`,\n\n // session errors\n SESSION_INVALID: 'Your session is no longer valid. Please log in again.',\n SESSION_EXPIRED: 'Your session has expired. Please log in again.',\n\n // filter errors\n GROUP_BY_LIMIT: 'buildFilterQuery: Only 1 Group by field is supported currently.',\n INVALID_GROUP_BY_COUNT: 'Exactly one groupBy field is required to count grouped records.',\n\n // general errors\n FORBIDDEN: 'Forbidden',\n\n\n // database errors\n DUPLICATE_ENTRY: 'Duplicate entry. A record with similar unique fields already exists.',\n\n // validation errors\n ID_REQUIRED_FOR_UPDATE: 'Id is required for update.',\n ID_REQUIRED_FOR_DELETE: 'Id is required for deletion.',\n\n // CRUD service errors\n RELATION_TYPE_NOT_SUPPORTED: 'Relation type not supported in CRUD service.',\n NO_SOFT_DELETED_RECORD_FOUND: 'No soft-deleted record found with the given ID.',\n CONFLICTING_RECORD_ON_UNARCHIVE: 'Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record so as to avoid this conflict.',\n NO_SOFT_DELETED_RECORDS_FOUND: 'No matching soft-deleted records found.',\n EMPTY_PATH_PARTS: 'Path parts cannot be empty',\n\n\n // CSV/Excel service errors\n MISSING_HEADERS_OR_FUNCTION: 'Either headers or data records function must be provided.',\n INVALID_CHUNK_SIZE: 'Chunk size must be greater than 0 when data records function is provided.',\n INVALID_FORMAT: (format: string) => `Invalid ${format} format`,\n\n\n //field errors\n INVALID_INVERSE_FIELD_TYPE: 'Only relation fields can have inverse fields.',\n MODEL_AND_MODULE_REQUIRED_TO_UPDATE_INVERSE_FIELD: 'Model and module are required to update inverse field.',\n MODEL_NAME_AND_MODULE_NAME_REQUIRED_TO_CREATE_INVERSE_FIELD: 'Model name and module name are required to create inverse field.',\n FIELD_NOT_FOUND: (id: number | string) => `No field with id #${id} exists`,\n PROVIDER_NOT_FOUND: (provider: string) => `Field incorrectly configured. No provider with name ${provider} registered in backend.`,\n FILE_WRITE_FAILED: 'File creation failed, rolling back transaction',\n FILE_DELETE_FAILED: 'File deletion failed, rolling back transaction',\n // file service errors\n FILE_NOT_FOUND: 'File not found',\n FILE_COPY_ERROR: 'Error copying file',\n S3_CLIENT_NOT_INITIALIZED: 'S3 Client not initialized. Please check the S3 configuration.',\n\n // model errors\n MODEL_METADATA_NOT_FOUND: (id: string | number) => `Model metadata with ID ${id} not found.`,\n MODEL_SERVICE_NOT_FOUND: (model: string) => `Model service for ${model} not found.`,\n RELATION_CO_MODEL_NOT_DEFINED_FOR_FIELD: (fieldName: string) => `Relation coModelSingularName is not defined for relation field ${fieldName}`,\n MODEL_NOT_FOUND: (singularName?: string) => `Model${singularName ? ` with singular name \"${singularName}\"` : ''} not found.`,\n MODEL_REQUIRED_FOR_CODE_GENERATION: 'Model ID or Model Name is required for generating code.',\n\n //module errors\n MODULE_NOT_FOUND: (moduleName: string) => `Module with name ${moduleName} not found.`,\n MODULE_ID_NOT_FOUND: (id: string | number) => `Module with ID ${id} not found.`,\n\n //entity errors\n ENTITY_NOT_FOUND: (entity?: string | number) => `Entity${entity ? ' ' + entity : ''} not found.`,\n ENTITY_NAME_REQUIRED: 'Entity name is required to find the entity.',\n ENTITY_ID_REQUIRED: 'Entity ID is required to find the entity.',\n\n // import errors\n NO_ERROR_LOG_FOR_IMPORT: (id: string | number) => `No error log entries found for import transaction ID ${id}.`,\n FILE_READ_FAILED_FROM_URL: (url: string) => `Failed to read file from URL: ${url}`,\n\n // media storage provider errors\n MEDIA_STORAGE_PROVIDER_ID_NOT_FOUND: (id: number | string) => `Media Storage Provider with #${id} not found.`,\n MEDIA_STORAGE_PROVIDER_NOT_FOUND: 'Media Storage Provider not found',\n\n // SQL errors\n UNSUPPORTED_SQL_OPERATOR: (operator: string) => `Unsupported SQL operator: ${operator}`,\n\n // AI interaction errors\n PYTHON_EXECUTABLE_NOT_CONFIGURED: 'SolidX AI MCP python executable or client path not configured.',\n UNABLE_TO_RESOLVE_SOLID_COMMAND: 'Unable to resolve a solid_ command that was used to come up with this response.',\n UNABLE_TO_RESOLVE_MCP_HANDLER: 'Unable to resolve a mcp tool handler.',\n\n DEFAULT_REGEX_PATTERN_NOT_MATCHING_ERROR_MSG: 'Invalid regex pattern.',\n\n PERMISSION_MESSAGES: {\n insertMany: (model?: string) =>\n `You do not have permission to import ${model ?? 'these'} records.`,\n } as Record<string, (model?: string) => string>,\n\n};\n"]}
|
|
1
|
+
{"version":3,"file":"error-messages.js","sourceRoot":"","sources":["../../src/constants/error-messages.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAG;IAE1B,cAAc,EAAE,sBAAsB;IACtC,eAAe,EAAE,gCAAgC;IACjD,aAAa,EAAE,mBAAmB;IAClC,eAAe,EAAE,sEAAsE;IACvF,kBAAkB,EAAE,0BAA0B;IAC9C,4BAA4B,EAAE,oCAAoC;IAClE,2BAA2B,EAAE,yCAAyC;IACtE,kCAAkC,EAAE,2CAA2C;IAC/E,6BAA6B,EAAE,iEAAiE;IAChG,6BAA6B,EAAE,gDAAgD;IAC/E,8BAA8B,EAAE,kDAAkD;IAClF,mBAAmB,EAAE,sCAAsC;IAC3D,0BAA0B,EAAE,6CAA6C;IACzE,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,kBAAkB;IAC/B,yBAAyB,EAAE,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AChG,oBAAoB,EAAE,6CAA6C;IACnE,kBAAkB,EAAE,2CAA2C;IAG/D,uBAAuB,EAAE,CAAC,EAAmB,EAAE,EAAE,CAAC,wDAAwD,EAAE,GAAG;IAC/G,yBAAyB,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,iCAAiC,GAAG,EAAE;IAGlF,mCAAmC,EAAE,CAAC,EAAmB,EAAE,EAAE,CAAC,gCAAgC,EAAE,aAAa;IAC7G,gCAAgC,EAAE,kCAAkC;IAGpE,wBAAwB,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,6BAA6B,QAAQ,EAAE;IAGvF,gCAAgC,EAAE,gEAAgE;IAClG,+BAA+B,EAAE,iFAAiF;IAClH,6BAA6B,EAAE,uCAAuC;IAEtE,4CAA4C,EAAE,wBAAwB;IAEtE,mBAAmB,EAAE;QACrB,UAAU,EAAE,CAAC,KAAc,EAAE,EAAE,CAC7B,wCAAwC,KAAK,IAAI,OAAO,WAAW;KACtB;CAElD,CAAC","sourcesContent":["// backend/common/constants/error-messages.ts\n\nexport const ERROR_MESSAGES = {\n //authentication errors\n USER_NOT_FOUND: 'User does not exist.',\n USER_NOT_ACTIVE: 'User profile is not activated.',\n USER_INACTIVE: 'User is inactive.',\n ACCOUNT_BLOCKED: 'Your account has been blocked due to multiple failed login attempts.',\n PASSWORD_INCORRECT: 'Password does not match.',\n PUBLIC_REGISTRATION_DISABLED: 'Public registrations are disabled.',\n UNIQUE_CONSTRAINT_VIOLATION: 'A unique constraint violation occurred.',\n PASSWORDLESS_REGISTRATION_DISABLED: 'Passwordless registration is not enabled.',\n REGISTRATION_REQUIRES_CONTACT: 'Either mobile or email is required for initiating registration.',\n EMAIL_REQUIRED_FOR_VALIDATION: 'Email is required for email validation source.',\n MOBILE_REQUIRED_FOR_VALIDATION: 'Mobile is required for mobile validation source.',\n USER_ALREADY_EXISTS: 'User already exists. Please sign in.',\n VALIDATION_SOURCE_REQUIRED: 'At least one validation source is required.',\n INVALID_OTP: 'Invalid OTP.',\n OTP_EXPIRED: 'OTP has expired.',\n INVALID_VERIFICATION_TYPE: 'Invalid type. Must be either email or mobile.',\n NON_LOCAL_PROVIDER: 'User seems to have used a passwordless mode to authenticate.',\n USER_ID_MISMATCH: \"User ID's do not match.\",\n USERNAME_MISMATCH: \"User username's do not match.\",\n INCORRECT_CURRENT_PASSWORD: 'Incorrect current password specified.',\n PASSWORD_REUSED: 'Try a different password',\n INVALID_VERIFICATION_TOKEN: 'Invalid verification token',\n INVALID_REFRESH_TOKEN: 'Invalid refresh token',\n ACCESS_DENIED: 'Access denied',\n INVALID_USER_PROFILE: 'Invalid user profile',\n GOOGLE_OAUTH_PROFILE_FETCH_FAILED: 'Failed to fetch user profile from Google OAuth service',\n MICROSOFT_ACTIVE_DIRECTORY_OAUTH_PROFILE_FETCH_FAILED: 'Failed to fetch user profile from Microsoft Active Directory OAuth service',\n LOGOUT_FAILED: 'Logout failed due to an unexpected error.',\n\n INVALID_CREDENTIALS: 'Invalid credentials',\n LOGIN_FAILED: 'Login Failed',\n OLD_PASSWORD_INCORRECT: 'You have specified an incorrect old password.',\n INVALID_NEW_PASSWORD: 'Invalid new password.',\n PASSWORDS_DO_NOT_MATCH: 'New passwords are not matching.',\n\n // user management errors\n DELETE_SELF_NOT_ALLOWED: 'Deleting logged-in user is not allowed.',\n DELETE_IDS_REQUIRED: 'At least one ID is required for deletion.',\n USER_MISSING_ID: 'User must exist before initializing roles.',\n ROLES_NOT_FOUND: (roles: string[]) => `The following roles were not found: ${roles.join(', ')}`,\n USER_NOT_FOUND_BY_USERNAME: (username: string) => `User with username '${username}' not found.`,\n ROLE_NOT_FOUND: (roleName: string) => `Role '${roleName}' not found.`,\n PERMISSION_NOT_EXIST: (permission: string) => `Permission '${permission}' does not exist.`,\n\n // session errors\n SESSION_INVALID: 'Your session is no longer valid. Please log in again.',\n SESSION_EXPIRED: 'Your session has expired. Please log in again.',\n\n // filter errors\n GROUP_BY_LIMIT: 'buildFilterQuery: Only 1 Group by field is supported currently.',\n INVALID_GROUP_BY_COUNT: 'Exactly one groupBy field is required to count grouped records.',\n\n // general errors\n FORBIDDEN: 'Forbidden',\n RESOURCE_NOT_FOUND: 'The requested resource was not found.',\n\n\n // database errors\n DUPLICATE_ENTRY: 'Duplicate entry. A record with similar unique fields already exists.',\n\n // validation errors\n ID_REQUIRED_FOR_UPDATE: 'Id is required for update.',\n ID_REQUIRED_FOR_DELETE: 'Id is required for deletion.',\n\n // CRUD service errors\n RELATION_TYPE_NOT_SUPPORTED: 'Relation type not supported in CRUD service.',\n NO_SOFT_DELETED_RECORD_FOUND: 'No soft-deleted record found with the given ID.',\n CONFLICTING_RECORD_ON_UNARCHIVE: 'Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record so as to avoid this conflict.',\n NO_SOFT_DELETED_RECORDS_FOUND: 'No matching soft-deleted records found.',\n EMPTY_PATH_PARTS: 'Path parts cannot be empty',\n\n\n // CSV/Excel service errors\n MISSING_HEADERS_OR_FUNCTION: 'Either headers or data records function must be provided.',\n INVALID_CHUNK_SIZE: 'Chunk size must be greater than 0 when data records function is provided.',\n INVALID_FORMAT: (format: string) => `Invalid ${format} format`,\n\n\n //field errors\n INVALID_INVERSE_FIELD_TYPE: 'Only relation fields can have inverse fields.',\n MODEL_AND_MODULE_REQUIRED_TO_UPDATE_INVERSE_FIELD: 'Model and module are required to update inverse field.',\n MODEL_NAME_AND_MODULE_NAME_REQUIRED_TO_CREATE_INVERSE_FIELD: 'Model name and module name are required to create inverse field.',\n FIELD_NOT_FOUND: (id: number | string) => `No field with id #${id} exists`,\n PROVIDER_NOT_FOUND: (provider: string) => `Field incorrectly configured. No provider with name ${provider} registered in backend.`,\n FILE_WRITE_FAILED: 'File creation failed, rolling back transaction',\n FILE_DELETE_FAILED: 'File deletion failed, rolling back transaction',\n // file service errors\n FILE_NOT_FOUND: 'File not found',\n FILE_COPY_ERROR: 'Error copying file',\n S3_CLIENT_NOT_INITIALIZED: 'S3 Client not initialized. Please check the S3 configuration.',\n\n // model errors\n MODEL_METADATA_NOT_FOUND: (id: string | number) => `Model metadata with ID ${id} not found.`,\n MODEL_SERVICE_NOT_FOUND: (model: string) => `Model service for ${model} not found.`,\n RELATION_CO_MODEL_NOT_DEFINED_FOR_FIELD: (fieldName: string) => `Relation coModelSingularName is not defined for relation field ${fieldName}`,\n MODEL_NOT_FOUND: (singularName?: string) => `Model${singularName ? ` with singular name \"${singularName}\"` : ''} not found.`,\n MODEL_REQUIRED_FOR_CODE_GENERATION: 'Model ID or Model Name is required for generating code.',\n\n //module errors\n MODULE_NOT_FOUND: (moduleName: string) => `Module with name ${moduleName} not found.`,\n MODULE_ID_NOT_FOUND: (id: string | number) => `Module with ID ${id} not found.`,\n\n //entity errors\n ENTITY_NOT_FOUND: (entity?: string | number) => `Entity${entity ? ' ' + entity : ''} not found.`,\n ENTITY_NAME_REQUIRED: 'Entity name is required to find the entity.',\n ENTITY_ID_REQUIRED: 'Entity ID is required to find the entity.',\n\n // import errors\n NO_ERROR_LOG_FOR_IMPORT: (id: string | number) => `No error log entries found for import transaction ID ${id}.`,\n FILE_READ_FAILED_FROM_URL: (url: string) => `Failed to read file from URL: ${url}`,\n\n // media storage provider errors\n MEDIA_STORAGE_PROVIDER_ID_NOT_FOUND: (id: number | string) => `Media Storage Provider with #${id} not found.`,\n MEDIA_STORAGE_PROVIDER_NOT_FOUND: 'Media Storage Provider not found',\n\n // SQL errors\n UNSUPPORTED_SQL_OPERATOR: (operator: string) => `Unsupported SQL operator: ${operator}`,\n\n // AI interaction errors\n PYTHON_EXECUTABLE_NOT_CONFIGURED: 'SolidX AI MCP python executable or client path not configured.',\n UNABLE_TO_RESOLVE_SOLID_COMMAND: 'Unable to resolve a solid_ command that was used to come up with this response.',\n UNABLE_TO_RESOLVE_MCP_HANDLER: 'Unable to resolve a mcp tool handler.',\n\n DEFAULT_REGEX_PATTERN_NOT_MATCHING_ERROR_MSG: 'Invalid regex pattern.',\n\n PERMISSION_MESSAGES: {\n insertMany: (model?: string) =>\n `You do not have permission to import ${model ?? 'these'} records.`,\n } as Record<string, (model?: string) => string>,\n\n};\n"]}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { ChatterMessageService } from '../services/chatter-message.service';
|
|
2
|
-
import { CreateChatterMessageDto } from '../dtos/create-chatter-message.dto';
|
|
3
2
|
import { PostChatterMessageDto } from '../dtos/post-chatter-message.dto';
|
|
4
3
|
import { UpdateChatterNoteMessageDto } from '../dtos/update-chatter-note-message.dto';
|
|
5
4
|
export declare class ChatterMessageController {
|
|
6
5
|
private readonly service;
|
|
7
6
|
constructor(service: ChatterMessageService);
|
|
8
|
-
create(createDto: CreateChatterMessageDto, files: Array<Express.Multer.File>): Promise<import("..").ChatterMessage>;
|
|
9
7
|
getChatterMessages(entityId: number, entityName: string, query: any): Promise<{
|
|
10
8
|
meta: {
|
|
11
9
|
totalRecords: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/chatter-message.controller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"chatter-message.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/chatter-message.controller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAUtF,qBAEa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,qBAAqB;IAsDrD,kBAAkB,CACH,QAAQ,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAC9B,KAAK,EAAE,GAAG;;;;;;;;;;;IAgBf,QAAQ,CAAU,KAAK,EAAE,GAAG;IAM5B,OAAO,CAAc,EAAE,EAAE,MAAM,EAAW,KAAK,EAAE,GAAG;IAmBpD,WAAW,CACP,OAAO,EAAE,qBAAqB,EACrB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IAO9C,aAAa,CAAc,EAAE,EAAE,MAAM;IAOrC,uBAAuB,CACd,EAAE,EAAE,MAAM,EACf,SAAS,EAAE,2BAA2B,EAC7B,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;CAIrD"}
|
|
@@ -18,10 +18,8 @@ const common_1 = require("@nestjs/common");
|
|
|
18
18
|
const platform_express_1 = require("@nestjs/platform-express");
|
|
19
19
|
const swagger_1 = require("@nestjs/swagger");
|
|
20
20
|
const chatter_message_service_1 = require("../services/chatter-message.service");
|
|
21
|
-
const create_chatter_message_dto_1 = require("../dtos/create-chatter-message.dto");
|
|
22
21
|
const post_chatter_message_dto_1 = require("../dtos/post-chatter-message.dto");
|
|
23
22
|
const update_chatter_note_message_dto_1 = require("../dtos/update-chatter-note-message.dto");
|
|
24
|
-
const public_decorator_1 = require("../decorators/public.decorator");
|
|
25
23
|
var ShowSoftDeleted;
|
|
26
24
|
(function (ShowSoftDeleted) {
|
|
27
25
|
ShowSoftDeleted["INCLUSIVE"] = "inclusive";
|
|
@@ -31,9 +29,6 @@ let ChatterMessageController = class ChatterMessageController {
|
|
|
31
29
|
constructor(service) {
|
|
32
30
|
this.service = service;
|
|
33
31
|
}
|
|
34
|
-
create(createDto, files) {
|
|
35
|
-
return this.service.create(createDto, files);
|
|
36
|
-
}
|
|
37
32
|
async getChatterMessages(entityId, entityName, query) {
|
|
38
33
|
return this.service.getChatterMessages(entityId, entityName, query);
|
|
39
34
|
}
|
|
@@ -56,17 +51,6 @@ let ChatterMessageController = class ChatterMessageController {
|
|
|
56
51
|
exports.ChatterMessageController = ChatterMessageController;
|
|
57
52
|
__decorate([
|
|
58
53
|
(0, swagger_1.ApiBearerAuth)("jwt"),
|
|
59
|
-
(0, common_1.Post)(),
|
|
60
|
-
(0, common_1.UseInterceptors)((0, platform_express_1.AnyFilesInterceptor)()),
|
|
61
|
-
openapi.ApiResponse({ status: 201, type: require("../entities/chatter-message.entity").ChatterMessage }),
|
|
62
|
-
__param(0, (0, common_1.Body)()),
|
|
63
|
-
__param(1, (0, common_1.UploadedFiles)()),
|
|
64
|
-
__metadata("design:type", Function),
|
|
65
|
-
__metadata("design:paramtypes", [create_chatter_message_dto_1.CreateChatterMessageDto, Array]),
|
|
66
|
-
__metadata("design:returntype", void 0)
|
|
67
|
-
], ChatterMessageController.prototype, "create", null);
|
|
68
|
-
__decorate([
|
|
69
|
-
(0, public_decorator_1.Public)(),
|
|
70
54
|
(0, common_1.Get)('/getChatterMessages/:entityId/:entityName'),
|
|
71
55
|
(0, swagger_1.ApiQuery)({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted }),
|
|
72
56
|
(0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message.controller.js","sourceRoot":"","sources":["../../src/controllers/chatter-message.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA+H;AAC/H,+DAA+D;AAC/D,6CAAmE;AACnE,iFAA4E;
|
|
1
|
+
{"version":3,"file":"chatter-message.controller.js","sourceRoot":"","sources":["../../src/controllers/chatter-message.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA+H;AAC/H,+DAA+D;AAC/D,6CAAmE;AACnE,iFAA4E;AAG5E,+EAAyE;AACzE,6FAAsF;AAKtF,IAAK,eAGJ;AAHD,WAAK,eAAe;IAClB,0CAAuB,CAAA;IACvB,0CAAuB,CAAA;AACzB,CAAC,EAHI,eAAe,KAAf,eAAe,QAGnB;AAIM,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAA6B,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;IAAG,CAAC;IAsDzD,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C,gDAAqB;QACd,KAAK;;2DAG9B;AAIK;IAFL,IAAA,uBAAa,EAAC,KAAK,CAAC;IACpB,IAAA,cAAK,EAAC,cAAc,CAAC;;IACD,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;6DAE/B;AAKK;IAHL,IAAA,uBAAa,EAAC,KAAK,CAAC;IACpB,IAAA,cAAK,EAAC,UAAU,CAAC;IACjB,IAAA,wBAAe,EAAC,IAAA,sCAAmB,GAAE,CAAC;;IAEpC,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,sBAAa,GAAE,CAAA;;6CADG,6DAA2B;QACtB,KAAK;;uEAG9B;mCAzHU,wBAAwB;IAFpC,IAAA,iBAAO,EAAC,YAAY,CAAC;IACrB,IAAA,mBAAU,EAAC,iBAAiB,CAAC;qCAEU,+CAAqB;GADhD,wBAAwB,CA0HpC","sourcesContent":["import { Controller, Post, Body, Param, UploadedFiles, UseInterceptors, Put, Get, Query, Delete, Patch } from '@nestjs/common';\nimport { AnyFilesInterceptor } from \"@nestjs/platform-express\";\nimport { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';\nimport { ChatterMessageService } from '../services/chatter-message.service';\nimport { CreateChatterMessageDto } from '../dtos/create-chatter-message.dto';\nimport { UpdateChatterMessageDto } from '../dtos/update-chatter-message.dto';\nimport { PostChatterMessageDto } from '../dtos/post-chatter-message.dto';\nimport { UpdateChatterNoteMessageDto } from '../dtos/update-chatter-note-message.dto';\nimport { SolidRequestContextDecorator } from 'src/decorators/solid-request-context.decorator';\nimport { SolidRequestContextDto } from 'src/dtos/solid-request-context.dto';\nimport { Public } from 'src/decorators/public.decorator';\n\nenum ShowSoftDeleted {\n INCLUSIVE = \"inclusive\",\n EXCLUSIVE = \"exclusive\",\n}\n\n@ApiTags('Solid Core')\n@Controller('chatter-message')\nexport class ChatterMessageController {\n constructor(private readonly service: ChatterMessageService) {}\n\n // @ApiBearerAuth(\"jwt\")\n // @Post()\n // @UseInterceptors(AnyFilesInterceptor())\n // create(@Body() createDto: CreateChatterMessageDto, @UploadedFiles() files: Array<Express.Multer.File>) {\n // return this.service.create(createDto, files);\n // }\n\n // @ApiBearerAuth(\"jwt\")\n // @Post('/bulk')\n // @UseInterceptors(AnyFilesInterceptor())\n // insertMany(@Body() createDtos: CreateChatterMessageDto[], @UploadedFiles() filesArray: Express.Multer.File[][] = []) {\n // return this.service.insertMany(createDtos, filesArray);\n // }\n\n\n // @ApiBearerAuth(\"jwt\")\n // @Put(':id')\n // @UseInterceptors(AnyFilesInterceptor())\n // update(@Param('id') id: number, @Body() updateDto: UpdateChatterMessageDto, @UploadedFiles() files: Array<Express.Multer.File>) {\n // return this.service.update(id, updateDto, files);\n // }\n\n // @ApiBearerAuth(\"jwt\")\n // @Patch(':id')\n // @UseInterceptors(AnyFilesInterceptor())\n // partialUpdate(@Param('id') id: number, @Body() updateDto: UpdateChatterMessageDto, @UploadedFiles() files: Array<Express.Multer.File>) {\n // return this.service.update(id, updateDto, files, true);\n // }\n\n // @ApiBearerAuth(\"jwt\")\n // @Post('/bulk-recover')\n // async recoverMany(@Body() ids: number[]) {\n // return this.service.recoverMany(ids);\n // }\n\n // @ApiBearerAuth(\"jwt\")\n // @Get('/recover/:id')\n // async recover(@Param('id') id: number) {\n // return this.service.recover(id);\n // }\n\n @ApiBearerAuth(\"jwt\")\n @Get('/getChatterMessages/:entityId/:entityName')\n @ApiQuery({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted })\n @ApiQuery({ name: 'limit', required: false, type: Number })\n @ApiQuery({ name: 'offset', required: false, type: Number })\n @ApiQuery({ name: 'fields', required: false, type: Array })\n @ApiQuery({ name: 'sort', required: false, type: Array })\n @ApiQuery({ name: 'groupBy', required: false, type: Array })\n @ApiQuery({ name: 'populate', required: false, type: Array })\n @ApiQuery({ name: 'populateMedia', required: false, type: Array })\n @ApiQuery({ name: 'filters', required: false, type: Array })\n async getChatterMessages(\n @Param('entityId') entityId: number,\n @Param('entityName') entityName: string,\n @Query() query: any\n ) {\n return this.service.getChatterMessages(entityId, entityName, query);\n }\n\n @ApiBearerAuth(\"jwt\")\n @ApiQuery({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted })\n @ApiQuery({ name: 'limit', required: false, type: Number })\n @ApiQuery({ name: 'offset', required: false, type: Number })\n @ApiQuery({ name: 'fields', required: false, type: Array })\n @ApiQuery({ name: 'sort', required: false, type: Array }) \n @ApiQuery({ name: 'groupBy', required: false, type: Array })\n @ApiQuery({ name: 'populate', required: false, type: Array })\n @ApiQuery({ name: 'populateMedia', required: false, type: Array })\n @ApiQuery({ name: 'filters', required: false, type: Array })\n @Get()\n async findMany(@Query() query: any) { \n return this.service.find(query); \n }\n\n @ApiBearerAuth(\"jwt\")\n @Get(':id')\n async findOne(@Param('id') id: string, @Query() query: any) {\n return this.service.findOne(+id, query);\n }\n\n // @ApiBearerAuth(\"jwt\")\n // @Delete('/bulk')\n // async deleteMany(@Body() ids: number[]) {\n // return this.service.deleteMany(ids);\n // }\n\n // @ApiBearerAuth(\"jwt\")\n // @Delete(':id')\n // async delete(@Param('id') id: number) {\n // return this.service.delete(id);\n // }\n\n @ApiBearerAuth(\"jwt\")\n @Post('post')\n @UseInterceptors(AnyFilesInterceptor())\n async postMessage(\n @Body() postDto: PostChatterMessageDto,\n @UploadedFiles() files: Array<Express.Multer.File>,\n ) {\n return this.service.postMessage(postDto, files);\n }\n\n @ApiBearerAuth(\"jwt\")\n @Patch(':id/complete')\n async markCompleted(@Param('id') id: string) {\n return this.service.markCompleted(+id);\n }\n\n @ApiBearerAuth(\"jwt\")\n @Patch(':id/note')\n @UseInterceptors(AnyFilesInterceptor())\n async updateCustomNoteMessage(\n @Param('id') id: string,\n @Body() updateDto: UpdateChatterNoteMessageDto,\n @UploadedFiles() files: Array<Express.Multer.File>,\n ) {\n return this.service.updateCustomNoteMessage(+id, updateDto, files);\n }\n}\n"]}
|
|
@@ -2,14 +2,18 @@ import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
|
2
2
|
import { JwtService } from '@nestjs/jwt';
|
|
3
3
|
import { PermissionMetadataService } from '../services/permission-metadata.service';
|
|
4
4
|
import { ClsService } from 'nestjs-cls';
|
|
5
|
+
import { ActiveSessionStorageService } from "../services/active-session-storage.service";
|
|
5
6
|
import { SettingService } from '../services/setting.service';
|
|
6
7
|
export declare class AccessTokenGuard implements CanActivate {
|
|
7
8
|
private readonly jwtService;
|
|
8
9
|
private readonly permissionsService;
|
|
10
|
+
private readonly activeSessionStorage;
|
|
9
11
|
private readonly settingService;
|
|
10
12
|
private readonly cls;
|
|
11
|
-
constructor(jwtService: JwtService, permissionsService: PermissionMetadataService, settingService: SettingService, cls: ClsService);
|
|
13
|
+
constructor(jwtService: JwtService, permissionsService: PermissionMetadataService, activeSessionStorage: ActiveSessionStorageService, settingService: SettingService, cls: ClsService);
|
|
12
14
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
15
|
private extractTokenFromHeader;
|
|
16
|
+
private resolveSessionId;
|
|
17
|
+
private validateConcurrentLoginSession;
|
|
14
18
|
}
|
|
15
19
|
//# sourceMappingURL=access-token.guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.guard.d.ts","sourceRoot":"","sources":["../../src/guards/access-token.guard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,
|
|
1
|
+
{"version":3,"file":"access-token.guard.d.ts","sourceRoot":"","sources":["../../src/guards/access-token.guard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,qBACa,gBAAiB,YAAW,WAAW;IAEhD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAJH,UAAU,EAAE,UAAU,EACtB,kBAAkB,EAAE,yBAAyB,EAC7C,oBAAoB,EAAE,2BAA2B,EACjD,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,UAAU;IAG5B,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAwC9D,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,gBAAgB;YAUV,8BAA8B;CAqB7C"}
|
|
@@ -12,14 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AccessTokenGuard = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const jwt_1 = require("@nestjs/jwt");
|
|
15
|
+
const error_messages_1 = require("../constants/error-messages");
|
|
15
16
|
const constants_1 = require("../constants");
|
|
16
17
|
const permission_metadata_service_1 = require("../services/permission-metadata.service");
|
|
17
18
|
const nestjs_cls_1 = require("nestjs-cls");
|
|
19
|
+
const active_session_storage_service_1 = require("../services/active-session-storage.service");
|
|
18
20
|
const setting_service_1 = require("../services/setting.service");
|
|
21
|
+
const crypto_1 = require("crypto");
|
|
19
22
|
let AccessTokenGuard = class AccessTokenGuard {
|
|
20
|
-
constructor(jwtService, permissionsService, settingService, cls) {
|
|
23
|
+
constructor(jwtService, permissionsService, activeSessionStorage, settingService, cls) {
|
|
21
24
|
this.jwtService = jwtService;
|
|
22
25
|
this.permissionsService = permissionsService;
|
|
26
|
+
this.activeSessionStorage = activeSessionStorage;
|
|
23
27
|
this.settingService = settingService;
|
|
24
28
|
this.cls = cls;
|
|
25
29
|
}
|
|
@@ -38,13 +42,16 @@ let AccessTokenGuard = class AccessTokenGuard {
|
|
|
38
42
|
refreshTokenTtl: this.settingService.getConfigValue("refreshTokenTtl")
|
|
39
43
|
};
|
|
40
44
|
const payload = await this.jwtService.verifyAsync(token, jwtConfiguration);
|
|
45
|
+
await this.validateConcurrentLoginSession(payload, token);
|
|
41
46
|
const permissions = await this.permissionsService.findAllUsingRoles(payload.roles);
|
|
42
47
|
payload.permissions = permissions.map((permission) => permission.name);
|
|
43
48
|
request[constants_1.REQUEST_USER_KEY] = payload;
|
|
44
49
|
this.cls.set(constants_1.REQUEST_USER_KEY, payload);
|
|
45
50
|
}
|
|
46
|
-
catch {
|
|
47
|
-
throw
|
|
51
|
+
catch (err) {
|
|
52
|
+
throw err instanceof common_1.UnauthorizedException
|
|
53
|
+
? err
|
|
54
|
+
: new common_1.UnauthorizedException();
|
|
48
55
|
}
|
|
49
56
|
return true;
|
|
50
57
|
}
|
|
@@ -52,12 +59,33 @@ let AccessTokenGuard = class AccessTokenGuard {
|
|
|
52
59
|
const [_, token] = request.headers.authorization?.split(' ') ?? [];
|
|
53
60
|
return token;
|
|
54
61
|
}
|
|
62
|
+
resolveSessionId(payload, token) {
|
|
63
|
+
if (payload.sessionId) {
|
|
64
|
+
return payload.sessionId;
|
|
65
|
+
}
|
|
66
|
+
return (0, crypto_1.createHash)('sha256').update(token).digest('hex');
|
|
67
|
+
}
|
|
68
|
+
async validateConcurrentLoginSession(payload, token) {
|
|
69
|
+
if (!this.settingService.getConfigValue("preventConcurrentLogins")) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const activeSessionId = await this.activeSessionStorage.getActiveSession(payload.sub);
|
|
73
|
+
const currentSessionId = this.resolveSessionId(payload, token);
|
|
74
|
+
if (!activeSessionId) {
|
|
75
|
+
await this.activeSessionStorage.setActiveSession(payload.sub, currentSessionId);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (currentSessionId !== activeSessionId) {
|
|
79
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.SESSION_INVALID);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
55
82
|
};
|
|
56
83
|
exports.AccessTokenGuard = AccessTokenGuard;
|
|
57
84
|
exports.AccessTokenGuard = AccessTokenGuard = __decorate([
|
|
58
85
|
(0, common_1.Injectable)(),
|
|
59
86
|
__metadata("design:paramtypes", [jwt_1.JwtService,
|
|
60
87
|
permission_metadata_service_1.PermissionMetadataService,
|
|
88
|
+
active_session_storage_service_1.ActiveSessionStorageService,
|
|
61
89
|
setting_service_1.SettingService,
|
|
62
90
|
nestjs_cls_1.ClsService])
|
|
63
91
|
], AccessTokenGuard);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.guard.js","sourceRoot":"","sources":["../../src/guards/access-token.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"access-token.guard.js","sourceRoot":"","sources":["../../src/guards/access-token.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAKwB;AACxB,qCAAyC;AAEzC,gEAA8D;AAE9D,4CAAgD;AAChD,yFAAoF;AACpF,2CAAwC;AACxC,+FAAyF;AACzF,iEAA6D;AAC7D,mCAAoC;AAG7B,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,UAAsB,EACtB,kBAA6C,EAC7C,oBAAiD,EACjD,cAA8B,EAC9B,GAAe;QAJf,eAAU,GAAV,UAAU,CAAY;QACtB,uBAAkB,GAAlB,kBAAkB,CAA2B;QAC7C,yBAAoB,GAApB,oBAAoB,CAA6B;QACjD,mBAAc,GAAd,cAAc,CAAgB;QAC9B,QAAG,GAAH,GAAG,CAAY;IAC9B,CAAC;IAEL,KAAK,CAAC,WAAW,CAAC,OAAyB;QAEzC,MAAM,OAAO,GAAG,O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AU;QACF,uDAAyB;QACvB,4DAA2B;QACjC,gCAAc;QACzB,uBAAU;GANvB,gBAAgB,CAuF5B","sourcesContent":["import type { SolidCoreSetting } from \"src/services/settings/default-settings-provider.service\";\nimport {\n CanActivate,\n ExecutionContext,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { Request } from 'express';\nimport { ERROR_MESSAGES } from \"src/constants/error-messages\";\nimport { ActiveUserData } from '../interfaces/active-user-data.interface';\nimport { REQUEST_USER_KEY } from \"../constants\";\nimport { PermissionMetadataService } from '../services/permission-metadata.service';\nimport { ClsService } from 'nestjs-cls';\nimport { ActiveSessionStorageService } from \"../services/active-session-storage.service\";\nimport { SettingService } from '../services/setting.service';\nimport { createHash } from \"crypto\";\n\n@Injectable()\nexport class AccessTokenGuard implements CanActivate {\n constructor(\n private readonly jwtService: JwtService,\n private readonly permissionsService: PermissionMetadataService,\n private readonly activeSessionStorage: ActiveSessionStorageService,\n private readonly settingService: SettingService,\n private readonly cls: ClsService\n ) { }\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n // 💡 NOTE: For GraphQL applications, you'd have to use the wrapper GqlExecutionContext here instead.\n const request = context.switchToHttp().getRequest();\n const token = this.extractTokenFromHeader(request);\n if (!token) {\n throw new UnauthorizedException();\n }\n try {\n\n const jwtConfiguration = {\n secret: this.settingService.getConfigValue<SolidCoreSetting>(\"secret\"),\n audience: this.settingService.getConfigValue<SolidCoreSetting>(\"audience\"),\n issuer: this.settingService.getConfigValue<SolidCoreSetting>(\"issuer\"),\n accessTokenTtl: this.settingService.getConfigValue<SolidCoreSetting>(\"accessTokenTtl\"),\n refreshTokenTtl: this.settingService.getConfigValue<SolidCoreSetting>(\"refreshTokenTtl\")\n }\n const payload: ActiveUserData = await this.jwtService.verifyAsync(\n token,\n jwtConfiguration\n );\n\n // Prevent Concurrent Login Feature\n await this.validateConcurrentLoginSession(payload, token);\n\n // Load permissions given the user. \n const permissions = await this.permissionsService.findAllUsingRoles(payload.roles);\n payload.permissions = permissions.map((permission) => permission.name);\n\n request[REQUEST_USER_KEY] = payload;\n this.cls.set(REQUEST_USER_KEY, payload);\n // console.log(`About to set payload in the request user key:`);\n // console.log(payload);\n } catch (err) {\n throw err instanceof UnauthorizedException\n ? err\n : new UnauthorizedException();\n }\n return true;\n }\n\n private extractTokenFromHeader(request: Request): string | undefined {\n // Since token is included in the Authorization header something like \n // Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImVtYWlsIjoidXNlcjFAbmVzdGpzLmNvbSIsImlhdCI6MTcwMDk5NTk1MywiZXhwIjoxNzAwOTk5NTUzLCJhdWQiOiJsb2NhbGhvc3Q6MzAwMCIsImlzcyI6ImxvY2FsaG9zdDozMDAwIn0.303Y04SZjKqoPjJRq4hXHcarHeZYS878gPGWmw2SoUc\n const [_, token] = request.headers.authorization?.split(' ') ?? [];\n return token;\n }\n\n private resolveSessionId(payload: ActiveUserData, token: string): string {\n if (payload.sessionId) {\n return payload.sessionId;\n }\n\n // Legacy tokens (issued before preventConcurrentLogins was enabled)\n // have no sessionId claim, so derive a stable fallback from the token.\n return createHash('sha256').update(token).digest('hex');\n }\n\n private async validateConcurrentLoginSession(payload: ActiveUserData, token: string,): Promise<void> {\n if (!this.settingService.getConfigValue<SolidCoreSetting>(\"preventConcurrentLogins\",)) {\n return;\n }\n\n const activeSessionId = await this.activeSessionStorage.getActiveSession(payload.sub);\n const currentSessionId = this.resolveSessionId(payload, token);\n\n if (!activeSessionId) {\n // No active session recorded yet for this user — this is the first\n // request we've seen since the feature was enabled (or storage was\n // cleared). Adopt this request's session as the active one so this\n // browser stays logged in going forward.\n await this.activeSessionStorage.setActiveSession(payload.sub, currentSessionId,);\n return;\n }\n\n if (currentSessionId !== activeSessionId) {\n throw new UnauthorizedException(ERROR_MESSAGES.SESSION_INVALID);\n }\n }\n}\n"]}
|
|
@@ -13,6 +13,7 @@ export declare class AuthenticationGuard implements CanActivate {
|
|
|
13
13
|
private static readonly defaultAuthTypes;
|
|
14
14
|
private readonly authTypeGuardMap;
|
|
15
15
|
constructor(reflector: Reflector, accessTokenGuard: AccessTokenGuard, apiKeyGuard: ApiKeyGuard, permissionService: PermissionMetadataService, cls: ClsService);
|
|
16
|
+
private isGenericUnauthorizedError;
|
|
16
17
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=authentication.guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.guard.d.ts","sourceRoot":"","sources":["../../src/guards/authentication.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,qBACa,mBAAoB,YAAW,WAAW;IAWnD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAdtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAsC;IAC9E,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAM7B;gBAGe,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,yBAAyB,EAC5C,GAAG,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"authentication.guard.d.ts","sourceRoot":"","sources":["../../src/guards/authentication.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,qBACa,mBAAoB,YAAW,WAAW;IAWnD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAdtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAsC;IAC9E,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAM7B;gBAGe,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,yBAAyB,EAC5C,GAAG,EAAE,UAAU;IAGlC,OAAO,CAAC,0BAA0B;IAgB5B,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAsD/D"}
|
|
@@ -33,6 +33,18 @@ let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
|
33
33
|
[auth_type_enum_1.AuthType.None]: { canActivate: () => true },
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
+
isGenericUnauthorizedError(error) {
|
|
37
|
+
if (!(error instanceof common_1.UnauthorizedException)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const response = error.getResponse();
|
|
41
|
+
const message = typeof response === 'string'
|
|
42
|
+
? response
|
|
43
|
+
: Array.isArray(response?.message)
|
|
44
|
+
? response.message[0]
|
|
45
|
+
: response?.message;
|
|
46
|
+
return !message || message === 'Unauthorized';
|
|
47
|
+
}
|
|
36
48
|
async canActivate(context) {
|
|
37
49
|
const contextLog = context.getHandler();
|
|
38
50
|
const request = context.switchToHttp().getRequest();
|
|
@@ -58,7 +70,10 @@ let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
|
58
70
|
let error = new common_1.UnauthorizedException();
|
|
59
71
|
for (const instance of guards) {
|
|
60
72
|
const canActivate = await Promise.resolve(instance.canActivate(context)).catch((err) => {
|
|
61
|
-
error
|
|
73
|
+
if (this.isGenericUnauthorizedError(error) ||
|
|
74
|
+
!this.isGenericUnauthorizedError(err)) {
|
|
75
|
+
error = err;
|
|
76
|
+
}
|
|
62
77
|
});
|
|
63
78
|
if (canActivate) {
|
|
64
79
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.guard.js","sourceRoot":"","sources":["../../src/guards/authentication.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,iEAA6D;AAC7D,4DAAmD;AACnD,6DAAwD;AACxD,mDAA8C;AAC9C,qEAA+D;AAC/D,yFAAoF;AACpF,2CAAwC;AAGjC,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAU9B,YACmB,SAAoB,EACpB,gBAAkC,EAClC,WAAwB,EACxB,iBAA4C,EAC5C,GAAe;QAJf,cAAS,GAAT,SAAS,CAAW;QACpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,gBAAW,GAAX,WAAW,CAAa;QACxB,sBAAiB,GAAjB,iBAAiB,CAA2B;QAC5C,QAAG,GAAH,GAAG,CAAY;QAbjB,qBAAgB,GAEA;YAC7B,CAAC,yBAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,gBA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KAAK,CAAC;IACd,CAAC;;AAvFU,kDAAmB;AACN,oCAAgB,GAAG,CAAC,yBAAQ,CAAC,MAAM,EAAE,yBAAQ,CAAC,MAAM,CAAC,AAArC,CAAsC;8BADnE,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAYmB,gBAAS;QACF,qCAAgB;QACrB,2BAAW;QACL,uDAAyB;QACvC,uBAAU;GAfvB,mBAAmB,CAwF/B","sourcesContent":["import {\n CanActivate,\n ExecutionContext,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common';\nimport { Reflector } from '@nestjs/core';\nimport { AUTH_TYPE_KEY } from '../decorators/auth.decorator';\nimport { AuthType } from '../enums/auth-type.enum';\nimport { AccessTokenGuard } from './access-token.guard';\nimport { ApiKeyGuard } from './api-key.guard';\nimport { IS_PUBLIC_KEY } from '../decorators/public.decorator';\nimport { PermissionMetadataService } from '../services/permission-metadata.service';\nimport { ClsService } from 'nestjs-cls';\n\n@Injectable()\nexport class AuthenticationGuard implements CanActivate {\n private static readonly defaultAuthTypes = [AuthType.Bearer, AuthType.ApiKey];\n private readonly authTypeGuardMap: Record<\n AuthType,\n CanActivate | CanActivate[]> = {\n [AuthType.Bearer]: this.accessTokenGuard,\n [AuthType.ApiKey]: this.apiKeyGuard,\n [AuthType.None]: { canActivate: () => true },\n };\n\n constructor(\n private readonly reflector: Reflector,\n private readonly accessTokenGuard: AccessTokenGuard,\n private readonly apiKeyGuard: ApiKeyGuard,\n private readonly permissionService: PermissionMetadataService,\n private readonly cls: ClsService,\n ) { }\n\n private isGenericUnauthorizedError(error: unknown): boolean {\n if (!(error instanceof UnauthorizedException)) {\n return false;\n }\n\n const response = error.getResponse();\n const message =\n typeof response === 'string'\n ? response\n : Array.isArray((response as any)?.message)\n ? (response as any).message[0]\n : (response as any)?.message;\n\n return !message || message === 'Unauthorized';\n }\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n // If method marked as public, then we return with true, else go ahead and apply the access token guard. \n const contextLog = context.getHandler();\n const request = context.switchToHttp().getRequest();\n request['isListedInPublicRole'] = false;\n\n // Set IP and User-Agent into CLS context\n const rawIp = request.headers['x-forwarded-for'] || request.socket?.remoteAddress || request.ip;\n const ip = Array.isArray(rawIp) ? rawIp[0] :\n typeof rawIp === 'string' ? rawIp.split(',')[0].trim() : '';\n const userAgent = request.headers['user-agent'] || '';\n\n this.cls.set('ipAddress', ip);\n this.cls.set('userAgent', userAgent);\n\n const isPublic = this.reflector.get(IS_PUBLIC_KEY, context.getHandler());\n if (isPublic) {\n return true;\n }\n\n // TODO: Check if this permission viz. contextPermission is listed in the Public role.\n const contextPermission = `${context.getClass().name}.${context.getHandler().name}`;\n\n const permissionExistsInRole = await this.permissionService.permissionExistsInRole('Public', contextPermission)\n if (permissionExistsInRole.length > 0) {\n request['isListedInPublicRole'] = true;\n return true\n }\n\n const authTypes = this.reflector.getAllAndOverride<AuthType[]>(\n AUTH_TYPE_KEY,\n [context.getHandler(), context.getClass()],\n ) ?? AuthenticationGuard.defaultAuthTypes;\n const guards = authTypes.map((type) => this.authTypeGuardMap[type]).flat();\n let error = new UnauthorizedException();\n\n for (const instance of guards) {\n const canActivate = await Promise.resolve(\n instance.canActivate(context),\n ).catch((err) => {\n if (\n this.isGenericUnauthorizedError(error) ||\n !this.isGenericUnauthorizedError(err)\n ) {\n error = err;\n }\n });\n\n if (canActivate) {\n return true;\n }\n }\n throw error;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAcA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE9D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAcA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE9D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CA8Hf;AAgBD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -105,7 +105,9 @@ async function bootstrapSolidApp(appModuleFactory, options = {}) {
|
|
|
105
105
|
const document = swagger_1.SwaggerModule.createDocument(app, swaggerConfig);
|
|
106
106
|
swagger_1.SwaggerModule.setup('/docs', app, document);
|
|
107
107
|
}
|
|
108
|
-
app.useGlobalInterceptors(new
|
|
108
|
+
app.useGlobalInterceptors(new common_1.ClassSerializerInterceptor(app.get(core_1.Reflector), {
|
|
109
|
+
enableImplicitConversion: true,
|
|
110
|
+
}), new wrap_response_interceptor_1.WrapResponseInterceptor());
|
|
109
111
|
app.enableCors((0, cors_helper_1.buildDefaultCorsOptions)());
|
|
110
112
|
const types = require('pg').types;
|
|
111
113
|
types.setTypeParser(types.builtins.INT8, (val) => parseInt(val));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":";;;;;AAoEA,8CA2HC;AAgBD,8CA0CC;AAzPD,2CAAgD;AAChD,uCAA2C;AAC3C,qDAAgD;AAChD,6CAAiE;AAEjE,oDAA4B;AAC5B,4CAAoB;AACpB,2BAAgC;AAChC,+BAA+B;AAC/B,+CAA2E;AAC3E,mDAAgD;AAChD,sDAA8D;AAC9D,yFAAoF;AACpF,+CAAwD;AACxD,uDAA6H;AAC7H,6DAAuD;AAIvD,SAAS,6BAA6B;IACpC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAGH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;QAChC,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAA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IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnF,KAAK,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC;IAGvC,MAAM,GAAG,GAAG,MAAM,+BAAc,CAAC,oBAAoB,CAAC,SAAS,EAAE;QAC/D,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;KACjF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,+BAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { WsAdapter } from '@nestjs/platform-ws';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { createWinstonLoggerConfig } from '../winston.logger';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n /** Show full NestJS init logs during bootstrap (route mapping, module deps, pollers). Defaults to false. */\n verboseBootstrap?: boolean;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {}, verboseBootstrap = false } = options;\n\n const startTime = Date.now();\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule, {\n logger: WinstonModule.createLogger({ ...createWinstonLoggerConfig(), level: verboseBootstrap ? 'debug' : 'error' }),\n });\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n app.useWebSocketAdapter(new WsAdapter(app));\n\n await app.listen(port);\n\n // Wire up Winston as the runtime logger only AFTER listen — this suppresses all\n // framework init noise (route mapping, module deps, onModuleInit) during boot.\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);\n process.stdout.write(`\\x1b[32mServer started on port ${port} in ${elapsed}s\\x1b[0m\\n`);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":";;;;;AAoEA,8CAiIC;AAgBD,8CA0CC;AA/PD,2CAA4E;AAC5E,uCAAsD;AACtD,qDAAgD;AAChD,6CAAiE;AAEjE,oDAA4B;AAC5B,4CAAoB;AACpB,2BAAgC;AAChC,+BAA+B;AAC/B,+CAA2E;AAC3E,mDAAgD;AAChD,sDAA8D;AAC9D,yFAAoF;AACpF,+CAAwD;AACxD,uDAA6H;AAC7H,6DAAuD;AAIvD,SAAS,6BAA6B;IACpC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAGH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE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assSerializerInterceptor, ValidationPipe } from '@nestjs/common';\nimport { NestFactory, Reflector } from '@nestjs/core';\nimport { WsAdapter } from '@nestjs/platform-ws';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { createWinstonLoggerConfig } from '../winston.logger';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n /** Show full NestJS init logs during bootstrap (route mapping, module deps, pollers). Defaults to false. */\n verboseBootstrap?: boolean;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {}, verboseBootstrap = false } = options;\n\n const startTime = Date.now();\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule, {\n logger: WinstonModule.createLogger({ ...createWinstonLoggerConfig(), level: verboseBootstrap ? 'debug' : 'error' }),\n });\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(\n new ClassSerializerInterceptor(app.get(Reflector), {\n enableImplicitConversion: true, // optional but handy\n // groups: ['client'], // if you use groups\n }),\n new WrapResponseInterceptor()\n );\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n app.useWebSocketAdapter(new WsAdapter(app));\n\n await app.listen(port);\n\n // Wire up Winston as the runtime logger only AFTER listen — this suppresses all\n // framework init noise (route mapping, module deps, onModuleInit) during boot.\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);\n process.stdout.write(`\\x1b[32mServer started on port ${port} in ${elapsed}s\\x1b[0m\\n`);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-core-error-codes-provider.service.d.ts","sourceRoot":"","sources":["../../src/helpers/solid-core-error-codes-provider.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"solid-core-error-codes-provider.service.d.ts","sourceRoot":"","sources":["../../src/helpers/solid-core-error-codes-provider.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAG1E,qBAEa,2BAA4B,YAAW,kBAAkB;IAClE,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,aAAa,CAAC,SAAS,CAAC;IAwEjC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;CAI/C"}
|
|
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.SolidCoreErrorCodesProvider = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
+
const error_messages_1 = require("../constants/error-messages");
|
|
11
12
|
const error_codes_provider_decorator_1 = require("../decorators/error-codes-provider.decorator");
|
|
12
13
|
let SolidCoreErrorCodesProvider = class SolidCoreErrorCodesProvider {
|
|
13
14
|
name() {
|
|
@@ -15,6 +16,24 @@ let SolidCoreErrorCodesProvider = class SolidCoreErrorCodesProvider {
|
|
|
15
16
|
}
|
|
16
17
|
rules() {
|
|
17
18
|
return [
|
|
19
|
+
{
|
|
20
|
+
code: 'solidx-session-invalid',
|
|
21
|
+
priority: 110,
|
|
22
|
+
match: (txt) => txt.includes(error_messages_1.ERROR_MESSAGES.SESSION_INVALID.toLowerCase()),
|
|
23
|
+
meta: {
|
|
24
|
+
message: error_messages_1.ERROR_MESSAGES.SESSION_INVALID,
|
|
25
|
+
httpStatus: 401,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: 'solidx-session-expired',
|
|
30
|
+
priority: 110,
|
|
31
|
+
match: (txt) => txt.includes(error_messages_1.ERROR_MESSAGES.SESSION_EXPIRED.toLowerCase()),
|
|
32
|
+
meta: {
|
|
33
|
+
message: error_messages_1.ERROR_MESSAGES.SESSION_EXPIRED,
|
|
34
|
+
httpStatus: 401,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
18
37
|
{
|
|
19
38
|
code: 'solidx-mcp-server-unavailable',
|
|
20
39
|
priority: 100,
|
|
@@ -25,6 +44,15 @@ let SolidCoreErrorCodesProvider = class SolidCoreErrorCodesProvider {
|
|
|
25
44
|
httpStatus: 503,
|
|
26
45
|
},
|
|
27
46
|
},
|
|
47
|
+
{
|
|
48
|
+
code: 'solidx-resource-not-found',
|
|
49
|
+
priority: 95,
|
|
50
|
+
match: (txt) => txt.includes('enoent') && txt.includes('no such file or directory'),
|
|
51
|
+
meta: {
|
|
52
|
+
message: error_messages_1.ERROR_MESSAGES.RESOURCE_NOT_FOUND,
|
|
53
|
+
httpStatus: 404,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
28
56
|
{
|
|
29
57
|
code: 'solidx-db-duplicate-key',
|
|
30
58
|
priority: 90,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-core-error-codes-provider.service.js","sourceRoot":"","sources":["../../src/helpers/solid-core-error-codes-provider.service.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAA4C;AAC5C,iGAAkF;AAM3E,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IACpC,IAAI;QACA,OAAO,4BAA4B,CAAC;IACxC,CAAC;IAED,KAAK;QACD,OAAO;YACH;gBACI,IAAI,EAAE,+BAA+B;gBACrC,QAAQ,EAAE,GAAG;gBACb,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CACX,GAAG,CAAC,QAAQ,CAAC,gCAAgC,CAAC;oBAC9C,GAAG,CAAC,QAAQ,CAAC,mDAAmD,CAAC;gBACrE,IAAI,EAAE;oBACF,OAAO,EAAE,mEAAmE;oBAC5E,UAAU,EAAE,GAAG;iBAClB;aACJ;YACD;gBACI,IAAI,EAAE,yBAAyB;gBAC/B,QAAQ,EAAE,EAAE;gBACZ,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC;gBAClF,IAAI,EAAE;oBACF,OAAO,EAAE,qEAAqE;oBAC9E,UAAU,EAAE,GAAG;iBAClB;aACJ;YACD;gBACI,IAAI,EAAE,6BAA6B;gBACnC,QAAQ,EAAE,EAAE;gBACZ,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpD,IAAI,EAAE;oBACF,OAAO,EACH,wEAAwE;oBAC5E,UAAU,EAAE,GAAG;iBAClB;aACJ;YACD;gBACI,IAAI,EAAE,sBAAsB;gBAC5B,QAAQ,EAAE,CAAC,CAAC;gBACZ,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;gBACrB,IAAI,EAAE;oBACF,OAAO,EAAE,+BAA+B;oBACxC,UAAU,EAAE,GAAG;iBAClB;aACJ;SACJ,CAAC;IACN,CAAC;IAGD,OAAO,CAAC,IAAY;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,EAAE,IAAI,CAAC;IACtB,CAAC;CACJ,CAAA;
|
|
1
|
+
{"version":3,"file":"solid-core-error-codes-provider.service.js","sourceRoot":"","sources":["../../src/helpers/solid-core-error-codes-provider.service.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAA4C;AAC5C,gEAA8D;AAC9D,iGAAkF;AAM3E,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IACpC,IAAI;QACA,OAAO,4BAA4B,CAAC;IACxC,CAAC;IAED,KAAK;QACD,OAAO;YACH;gBACI,IAAI,EAAE,wBAAwB;gBAC9B,QAAQ,EAAE,GAAG;gBACb,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,+BAAc,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;gBAC1E,IAAI,EAAE;oBACF,OAAO,EAAE,+BAAc,CAAC,eAAe;oBACvC,UAAU,EAAE,GAAG;iBAClB;aACJ;YACD;gBACI,IAAI,EAAE,wBAAwB;gBAC9B,QAAQ,EAAE,GAAG;gBAC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EACH,wEAAwE;oBAC5E,UAAU,EAAE,GAAG;iBAClB;aACJ;YACD;gBACI,IAAI,EAAE,sBAAsB;gBAC5B,QAAQ,EAAE,CAAC,CAAC;gBACZ,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;gBACrB,IAAI,EAAE;oBACF,OAAO,EAAE,+BAA+B;oBACxC,UAAU,EAAE,GAAG;iBAClB;aACJ;SACJ,CAAC;IACN,CAAC;IAGD,OAAO,CAAC,IAAY;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,EAAE,IAAI,CAAC;IACtB,CAAC;CACJ,CAAA;AAjFY,kEAA2B;sCAA3B,2BAA2B;IAFvC,IAAA,kDAAiB,GAAE;IACnB,IAAA,mBAAU,GAAE;GACA,2BAA2B,CAiFvC","sourcesContent":["// src/common/errors/providers/solidcore-error-code.provider.ts\nimport { Injectable } from '@nestjs/common';\nimport { ERROR_MESSAGES } from 'src/constants/error-messages';\nimport { ErrorCodeProvider } from 'src/decorators/error-codes-provider.decorator';\nimport { ErrorMeta, ErrorRule, IErrorCodeProvider } from 'src/interfaces';\n\n\n@ErrorCodeProvider()\n@Injectable()\nexport class SolidCoreErrorCodesProvider implements IErrorCodeProvider {\n name(): string {\n return 'SolidCoreErrorCodeProvider';\n }\n\n rules(): ReadonlyArray<ErrorRule> {\n return [\n {\n code: 'solidx-session-invalid',\n priority: 110,\n match: (txt) => txt.includes(ERROR_MESSAGES.SESSION_INVALID.toLowerCase()),\n meta: {\n message: ERROR_MESSAGES.SESSION_INVALID,\n httpStatus: 401,\n },\n },\n {\n code: 'solidx-session-expired',\n priority: 110,\n match: (txt) => txt.includes(ERROR_MESSAGES.SESSION_EXPIRED.toLowerCase()),\n meta: {\n message: ERROR_MESSAGES.SESSION_EXPIRED,\n httpStatus: 401,\n },\n },\n {\n code: 'solidx-mcp-server-unavailable',\n priority: 100,\n match: (txt) =>\n txt.includes('all connection attempts failed') &&\n txt.includes('unhandled errors in a taskgroup (1 sub-exception)'),\n meta: {\n message: 'SolidX MCP server is unreachable. Please verify the MCP endpoint.',\n httpStatus: 503,\n },\n },\n {\n code: 'solidx-resource-not-found',\n priority: 95,\n match: (txt) => txt.includes('enoent') && txt.includes('no such file or directory'),\n meta: {\n message: ERROR_MESSAGES.RESOURCE_NOT_FOUND,\n httpStatus: 404,\n },\n },\n {\n code: 'solidx-db-duplicate-key',\n priority: 90,\n match: (txt) => txt.includes('unique constraint') || txt.includes('duplicate key'),\n meta: {\n message: 'Duplicate key violation. A record with these values already exists.',\n httpStatus: 409,\n },\n },\n {\n code: 'solidx-db-foreign-key-error',\n priority: 90,\n match: (txt) => txt.includes('violates foreign key'),\n meta: {\n message:\n 'Foreign key constraint prevents this operation due to related records.',\n httpStatus: 409,\n },\n },\n {\n code: 'solidx-unknown-error',\n priority: -1, // last resort\n match: (_txt) => true, // fallback catch-all\n meta: {\n message: 'An unexpected error occurred.',\n httpStatus: 500,\n },\n },\n ];\n }\n\n // Optional explicit meta resolution (if you want)\n resolve(code: string): ErrorMeta | undefined {\n const rule = this.rules().find((r) => r.code === code);\n return rule?.meta;\n }\n}\n"]}
|