From 0eb5131f4631f969182311babcb6169a1cb0865e Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 15:25:22 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`feat/si?= =?UTF-8?q?ngle-sign-on-feature`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @GHkrishna. * https://github.com/credebl/platform/pull/1183#issuecomment-3009464681 The following files were modified: * `apps/api-gateway/src/main.ts` * `apps/api-gateway/src/user/utils/index.ts` * `libs/common/src/cast.helper.ts` * `libs/prisma-service/prisma/seed.ts` --- apps/api-gateway/src/main.ts | 5 +++++ apps/api-gateway/src/user/utils/index.ts | 18 +++++++++++++++++- libs/common/src/cast.helper.ts | 16 ++++++++++++++++ libs/prisma-service/prisma/seed.ts | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/api-gateway/src/main.ts b/apps/api-gateway/src/main.ts index 576bf81b9..2dba05c7e 100644 --- a/apps/api-gateway/src/main.ts +++ b/apps/api-gateway/src/main.ts @@ -18,6 +18,11 @@ import helmet from 'helmet'; dotenv.config(); +/** + * Initializes and starts the API Gateway application with OpenTelemetry, microservices, Swagger documentation, security, middleware, and static file serving. + * + * Configures the NestJS application with custom logging, NATS microservice connection, request validation, global exception handling, CORS, API versioning, and global interceptors. Serves static files from multiple directories and sets up Swagger documentation at the `/api` endpoint. Starts the application on the host and port specified by environment variables. + */ async function bootstrap(): Promise { try { if (otelSDK) { diff --git a/apps/api-gateway/src/user/utils/index.ts b/apps/api-gateway/src/user/utils/index.ts index 68193f49d..f24c76344 100644 --- a/apps/api-gateway/src/user/utils/index.ts +++ b/apps/api-gateway/src/user/utils/index.ts @@ -8,7 +8,14 @@ export const getDefaultClient = async (): Promise => ({ clientSecret: await encryptClientCredential(process.env.KEYCLOAK_MANAGEMENT_CLIENT_SECRET) }); -// Now getting from env, but can get from DB +/** + * Retrieves SSO client details for a given alias from environment variables. + * + * Constructs environment variable keys using the provided alias to obtain the client ID, client secret, domain, and alias name. If the alias name is not set in the environment, it defaults to the input alias. + * + * @param alias - The identifier used to construct environment variable keys for client credentials + * @returns An object containing the client ID, client secret, domain, and alias name + */ function getClientDetails(alias: string): IClientDetailsSSO { const clientIdKey = `${alias}_KEYCLOAK_MANAGEMENT_CLIENT_ID`; const clientSecretKey = `${alias}_KEYCLOAK_MANAGEMENT_CLIENT_SECRET`; @@ -30,6 +37,15 @@ function getClientDetails(alias: string): IClientDetailsSSO { return clientDetails; } +/** + * Retrieves SSO client credentials for the specified alias. + * + * If the alias matches the default client alias (case-insensitive), returns the default client details. Otherwise, fetches client details for the given alias from environment variables. Throws an error if required configuration is missing. + * + * @param alias - The client alias to retrieve credentials for + * @returns The SSO client details associated with the alias + * @throws Error if client ID, client secret, or domain are missing for the specified alias + */ export async function getCredentialsByAlias(alias: string): Promise { const defaultClient = await getDefaultClient(); if (alias.toUpperCase() === defaultClient.alias) { diff --git a/libs/common/src/cast.helper.ts b/libs/common/src/cast.helper.ts index f4f8ba20b..153ead2ff 100644 --- a/libs/common/src/cast.helper.ts +++ b/libs/common/src/cast.helper.ts @@ -421,6 +421,12 @@ export function checkDidLedgerAndNetwork(schemaType: string, did: string): boole return false; } +/** + * Updates the issuance date of each credential in the array to the current date if it differs from today. + * + * @param data - Array of credential data objects to check and update + * @returns The updated array of credential data objects + */ export function validateAndUpdateIssuanceDates(data: ICredentialData[]): ICredentialData[] { // Get current date in 'YYYY-MM-DD' format // eslint-disable-next-line prefer-destructuring @@ -456,6 +462,16 @@ export const encryptClientCredential = async (clientCredential: string): Promise } }; +/** + * Decorator that validates the structure of nested schema fields based on the `schemaDataType` property. + * + * Ensures that: + * - For `object` types, only `properties` is defined and `items` is not. + * - For `array` types, only `items` is defined and `properties` is not. + * - For other types, neither `properties` nor `items` are present. + * + * Provides detailed error messages when the structure does not match the expected format for the given `schemaDataType`. + */ export function ValidateNestedStructureFields(validationOptions?: ValidationOptions) { return function (object: object, propertyName: string): void { registerDecorator({ diff --git a/libs/prisma-service/prisma/seed.ts b/libs/prisma-service/prisma/seed.ts index 95cbd88e3..73b6ec0ba 100644 --- a/libs/prisma-service/prisma/seed.ts +++ b/libs/prisma-service/prisma/seed.ts @@ -449,6 +449,11 @@ const updateClientCredential = async (): Promise => { } }; +/** + * Executes the full database seeding and initialization process. + * + * Runs all seeding and setup functions in sequence to populate configuration, master data, and perform required migrations and updates. + */ async function main(): Promise { await createPlatformConfig(); await createOrgRoles();