Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export class AgentServiceService {
/**
* Organization storage data
*/
const storeOrgAgentData = await this._buildStoreOrgAgentData(payload, `${orgAgentTypeId}`);
const storeOrgAgentData = this._buildStoreOrgAgentData(payload, `${orgAgentTypeId}`);
/**
* Store org agent details
*/
Expand Down
10 changes: 1 addition & 9 deletions apps/api-gateway/src/authz/guards/session.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@ import { UserRepository } from 'apps/user/repositories/user.repository';

@Injectable()
export class SessionGuard implements CanActivate {
constructor(private userRepository: UserRepository) {}
constructor(private readonly userRepository: UserRepository) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>();
const sessionId = request.cookies['session_id'];

// if (!sessionId) {
// throw new UnauthorizedException('Missing session cookie');
// }
if (sessionId) {
const user = await this.userRepository.validateSession(sessionId);
request.user = user;
}

// if (!user) {
// throw new UnauthorizedException('Invalid session');
// }
return true;
}
}
20 changes: 9 additions & 11 deletions apps/api-gateway/src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
// @ts-nocheck TODO: Facing issues with types, need to fix later
// tracer.ts
import * as dotenv from 'dotenv';
dotenv.config();

import { NodeSDK } from '@opentelemetry/sdk-node';
import * as process from 'process';

import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { BatchLogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';
import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';

import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import type { Logger } from '@opentelemetry/api-logs';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';

import { resourceFromAttributes } from '@opentelemetry/resources';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { resourceFromAttributes } from '@opentelemetry/resources';

import { LoggerProvider, BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';
import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';
import type { Logger } from '@opentelemetry/api-logs';
dotenv.config();

let otelSDK: NodeSDK | null = null;
let otelLogger: Logger | null = null;
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/user/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getCredentialsByAlias(alias: string): Promise<IClientDetai
return defaultClient;
}

const clientDetails = await getClientDetails(alias);
const clientDetails = getClientDetails(alias);

if (!clientDetails.clientId || !clientDetails.clientSecret || !clientDetails.domain) {
throw new Error(`Missing configuration for SSO client: ${alias}`);
Expand Down
3 changes: 2 additions & 1 deletion apps/cloud-wallet/src/cloud-wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export class CloudWalletService {

const [baseWalletDetails, decryptedApiKey] = await this._commonCloudWalletInfo(userId);
const { agentEndpoint } = baseWalletDetails;
const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_GET_PROOF_REQUEST}/${threadId ? `?threadId=${threadId}` : ''}`;
const threadParam = threadId ? `?threadId=${threadId}` : '';
const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_GET_PROOF_REQUEST}/${threadParam}}`;
const getProofById = await this.commonService.httpGet(url, { headers: { authorization: decryptedApiKey } });
return getProofById;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ export class IssuanceService {

if (isEmailSent) {
const w3cSchemaId = outOfBandIssuancePayload?.credentialFormats?.jsonld?.credential?.['@context'] as string[];
if (w3cSchemaId && w3cSchemaId.includes(CommonConstants.W3C_SCHEMA_URL)) {
if (w3cSchemaId?.includes(CommonConstants.W3C_SCHEMA_URL)) {
const filterData = w3cSchemaId.filter((item) => CommonConstants.W3C_SCHEMA_URL !== item);
const [schemaId] = filterData;
if (credentialCreateOfferDetails.response.credentialRequestThId) {
Expand Down
38 changes: 23 additions & 15 deletions apps/organization/src/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@ export class OrganizationService {
}
}

private async ensureOrganizationExists(orgId: string): Promise<void> {
const organizationExist = await this.organizationRepository.getOrgProfile(orgId);
if (!organizationExist) {
throw new NotFoundException(ResponseMessages.organisation.error.notFound);
}
}
private async ensureNotExistingPrimaryDid(orgId: string, did: string): Promise<void> {
const orgAgentDetails = await this.organizationRepository.getAgentEndPoint(orgId);
if (orgAgentDetails.orgDid === did) {
throw new ConflictException(ResponseMessages.organisation.error.primaryDid);
}
}
private async ensureDidBelongsToOrg(orgId: string, did: string): Promise<void> {
const organizationDidList = await this.organizationRepository.getAllOrganizationDid(orgId);
const isDidMatch = organizationDidList.some((item) => item.did === did);
if (!isDidMatch) {
throw new NotFoundException(ResponseMessages.organisation.error.didNotFound);
}
}
/**
*
* @param registerOrgDto
Expand All @@ -203,22 +222,11 @@ export class OrganizationService {
// eslint-disable-next-line camelcase
async setPrimaryDid(orgId: string, did: string, id: string): Promise<string> {
try {
const organizationExist = await this.organizationRepository.getOrgProfile(orgId);
if (!organizationExist) {
throw new NotFoundException(ResponseMessages.organisation.error.notFound);
}
const orgAgentDetails = await this.organizationRepository.getAgentEndPoint(orgId);
if (orgAgentDetails.orgDid === did) {
throw new ConflictException(ResponseMessages.organisation.error.primaryDid);
}
await this.ensureOrganizationExists(orgId);
await this.ensureNotExistingPrimaryDid(orgId, did);

//check user DID exist in the organization's did list
const organizationDidList = await this.organizationRepository.getAllOrganizationDid(orgId);
const isDidMatch = organizationDidList.some((item) => item.did === did);

if (!isDidMatch) {
throw new NotFoundException(ResponseMessages.organisation.error.didNotFound);
}
await this.ensureDidBelongsToOrg(orgId, did);
const didDetails = await this.organizationRepository.getDidDetailsByDid(did);

if (!didDetails) {
Expand Down Expand Up @@ -1735,7 +1743,7 @@ export class OrganizationService {
emailData.emailTo = email;
emailData.emailSubject = `Removal of participation of “${orgName}”`;

emailData.emailHtml = await urlEmailTemplate.sendDeleteOrgMemberEmailTemplate(email, orgName, orgRole);
emailData.emailHtml = urlEmailTemplate.sendDeleteOrgMemberEmailTemplate(email, orgName, orgRole);

//Email is sent to user for the verification through emailData
const isEmailSent = await sendEmail(emailData);
Expand Down
1 change: 0 additions & 1 deletion apps/user/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class UserRepository {
where: { id: sessionId },
include: { user: true }
});
// if (!session || new Date() > session.expires) return null;
return session;
}

Expand Down
33 changes: 12 additions & 21 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import {
IVerifyUserEmail,
IUserInvitations,
IResetPasswordResponse,
ISignUpUserResponse
ISignUpUserResponse,
IVerificationEmail
} from '@credebl/common/interfaces/user.interface';
import { AddPasskeyDetailsDto } from 'apps/api-gateway/src/user/dto/add-user.dto';
import { URLUserResetPasswordTemplate } from '../templates/reset-password-template';
Expand Down Expand Up @@ -149,16 +150,16 @@ export class UserService {
throw new NotFoundException(ResponseMessages.user.error.redirectUrlNotFound);
}

sendVerificationMail = await this.sendEmailForVerification(
sendVerificationMail = await this.sendEmailForVerification({
email,
verifyCode,
verificationCode: verifyCode,
redirectUrl,
clientDetails.clientId,
clientId: clientDetails.clientId,
brandLogoUrl,
platformName,
clientDetails.domain,
redirectTo: clientDetails.domain,
clientAlias
);
});
} catch (error) {
throw new InternalServerErrorException(ResponseMessages.user.error.emailSend);
}
Expand Down Expand Up @@ -207,32 +208,22 @@ export class UserService {
* @returns
*/

async sendEmailForVerification(
email: string,
verificationCode: string,
redirectUrl: string,
clientId: string,
brandLogoUrl: string,
platformName: string,
redirectTo?: string,
clientAlias?: string
): Promise<boolean> {
async sendEmailForVerification(verificationEmailParameter: IVerificationEmail): Promise<boolean> {
try {
const { email, verificationCode, brandLogoUrl, platformName, redirectTo, clientAlias } =
verificationEmailParameter;
const platformConfigData = await this.prisma.platform_config.findMany();

const decryptedClientId = await this.commonService.decryptPassword(clientId);
const urlEmailTemplate = new URLUserEmailTemplate();
const emailData = new EmailDto();
emailData.emailFrom = platformConfigData[0].emailFrom;
emailData.emailTo = email;
const platform = platformName || process.env.PLATFORM_NAME;
emailData.emailSubject = `[${platform}] Verify your email to activate your account`;

emailData.emailHtml = await urlEmailTemplate.getUserURLTemplate(
emailData.emailHtml = urlEmailTemplate.getUserURLTemplate(
email,
verificationCode,
redirectUrl,
decryptedClientId,
brandLogoUrl,
platformName,
redirectTo,
Expand Down Expand Up @@ -662,7 +653,7 @@ export class UserService {
const platform = platformName || process.env.PLATFORM_NAME;
emailData.emailSubject = `[${platform}] Important: Password Reset Request`;

emailData.emailHtml = await urlEmailTemplate.getUserResetPasswordTemplate(
emailData.emailHtml = urlEmailTemplate.getUserResetPasswordTemplate(
email,
platform,
brandLogoUrl,
Expand Down
2 changes: 0 additions & 2 deletions apps/user/templates/user-email-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ export class URLUserEmailTemplate {
public getUserURLTemplate(
email: string,
verificationCode: string,
redirectUrl: string,
clientId: string,
brandLogoUrl: string,
platformName: string,
redirectTo?: string,
Expand Down
11 changes: 11 additions & 0 deletions libs/common/src/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,14 @@ export interface IClientAliases {
clientAlias: string;
clientUrl: string;
}

export interface IVerificationEmail {
email: string;
verificationCode: string;
redirectUrl: string;
clientId: string;
brandLogoUrl: string;
platformName: string;
redirectTo?: string;
clientAlias?: string;
}
29 changes: 17 additions & 12 deletions libs/logger/src/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,23 @@ export default class LoggerService implements Logger {
};

if (data?.error) {
attributes.error =
'string' === typeof data.error
? data.error
: data.error instanceof Error
? {
name: data.error.name,
message: data.error.message,
stack: data.error.stack
}
: 'object' === typeof data.error
? JSON.parse(JSON.stringify(data.error))
: String(data.error);
let errorValue;

if ('string' === typeof data.error) {
errorValue = data.error;
} else if (data.error instanceof Error) {
errorValue = {
name: data.error.name,
message: data.error.message,
stack: data.error.stack
};
} else if ('object' === typeof data.error) {
errorValue = JSON.parse(JSON.stringify(data.error));
} else {
errorValue = String(data.error);
}

attributes.error = errorValue;
}

otelLogger.emit({
Expand Down