Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url shortening #580

Merged
merged 51 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
eb690e8
Added Additional object storing endpoint in utility
GHkrishna Feb 21, 2024
d88ab76
Added some changes
GHkrishna Feb 22, 2024
0fd750a
resolved:Merge branch 'develop' of https://github.com/credebl/platfor…
GHkrishna Feb 22, 2024
dc27806
Utilility endpoint for storing endpoint and returning URL
GHkrishna Feb 25, 2024
bda2dba
Added support for shortening URL while creating connection
GHkrishna Feb 26, 2024
f5f3152
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Feb 27, 2024
dc0ca1b
Update: shortening URL
GHkrishna Feb 27, 2024
e8de841
Added Shorten URL for Issuance
GHkrishna Feb 27, 2024
246adf8
Added flag name
GHkrishna Feb 28, 2024
655cf1b
Remove console log
GHkrishna Feb 28, 2024
037fe30
Remove console log
GHkrishna Feb 28, 2024
1c5034d
Add uuid in aws
GHkrishna Feb 28, 2024
8719985
Removed logs
GHkrishna Feb 28, 2024
c488b73
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Feb 28, 2024
07f006b
Added sortenUrl to connection
GHkrishna Feb 28, 2024
a4dd14a
fix: shorten url changes
shitrerohit Feb 28, 2024
3c1ba10
fix: reset ports in start_agent script
GHkrishna Feb 29, 2024
62d76ea
fix: uncommented helmet
GHkrishna Feb 29, 2024
aa01c00
Removed comments from connection service
GHkrishna Feb 29, 2024
cc56c0c
fix: datatype for invitation variable in connection service
GHkrishna Feb 29, 2024
2d81937
fix: remove comments from interface
GHkrishna Feb 29, 2024
f1e3ec5
fix: minute fixes in connection service
GHkrishna Feb 29, 2024
0da8a39
fix: remove unused Interface
GHkrishna Feb 29, 2024
0ce9da5
fix: logging error correctly using contructor object
GHkrishna Feb 29, 2024
3c14fca
fix: logging error correctly using contructor object
GHkrishna Feb 29, 2024
245b0fb
fix: updated object storing in verification
GHkrishna Feb 29, 2024
724e85d
fix: remove unnecessary interfaces
GHkrishna Feb 29, 2024
a31523c
fix: remove unnecessary interfaces
GHkrishna Feb 29, 2024
202dd75
fix: minor fixes in verification service
GHkrishna Feb 29, 2024
d8ee72f
Update: success message after storing object
GHkrishna Feb 29, 2024
4737b19
Update: Dto update
GHkrishna Feb 29, 2024
9d8d4cb
Update: function name for sonar linting issue
GHkrishna Feb 29, 2024
92dcd3a
fix: dto comments
GHkrishna Feb 29, 2024
6f29f91
Merge branch 'develop' of https://github.com/credebl/platform into fe…
shitrerohit Feb 29, 2024
7dce1a4
Merge branch 'feat/url-shortening' of https://github.com/credebl/plat…
shitrerohit Feb 29, 2024
e246cb5
fix: shorten url changes for issue cred OOB on send email- WIP
shitrerohit Feb 29, 2024
04b7943
Merge branch 'develop' of https://github.com/credebl/platform into fe…
shitrerohit Feb 29, 2024
10e8385
fix:resolved isRequired issue
shitrerohit Mar 1, 2024
9422d15
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Mar 6, 2024
661b3fd
Minor changes to issuance and verification for shortening url
GHkrishna Mar 7, 2024
a293e7c
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Mar 7, 2024
7f0f0e0
Change default version for w3c credential to v2
GHkrishna Mar 7, 2024
7f3458c
fix: protocol versionining
GHkrishna Mar 7, 2024
28e6b62
fix: linting issues
GHkrishna Mar 7, 2024
0a366e9
fix: sonar lint issue of code repeatibility
GHkrishna Mar 7, 2024
dd074f1
fix: sonar lint issue of code repeatibility in Issuance
GHkrishna Mar 7, 2024
878cb50
fix: remove comments & unused code
GHkrishna Mar 7, 2024
ea17250
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Mar 7, 2024
b4378a0
Merge branch 'develop' of https://github.com/credebl/platform into fe…
GHkrishna Mar 8, 2024
e865efe
fix: spelling mistake
GHkrishna Mar 8, 2024
e36d3c7
fix: error handling
GHkrishna Mar 8, 2024
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
21 changes: 15 additions & 6 deletions apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable @typescript-eslint/array-type */

import { IsArray, IsNotEmpty, IsOptional, IsString, IsEmail, ArrayMaxSize, ValidateNested, ArrayMinSize, IsBoolean, IsDefined, MaxLength, IsEnum, IsObject} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ArrayMaxSize, ArrayMinSize, IsArray, IsBoolean, IsDefined, IsEmail, IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator';
import { IsCredentialJsonLdContext, SingleOrArray } from '../utils/helper';
import { IssueCredentialType, JsonLdCredentialDetailCredentialStatusOptions, JsonLdCredentialDetailOptionsOptions, JsonObject } from '../interfaces';
import { Transform, Type } from 'class-transformer';
import { trim } from '@credebl/common/cast.helper';
import { SortValue } from '../../enum';
import { SortFields } from 'apps/connection/src/enum/connection.enum';

import { AutoAccept } from '@credebl/enum/enum';
import { IssueCredentialType, JsonLdCredentialDetailCredentialStatusOptions, JsonLdCredentialDetailOptionsOptions, JsonObject } from '../interfaces';
import { IsCredentialJsonLdContext, SingleOrArray } from '../utils/helper';
import { SortFields } from 'apps/connection/src/enum/connection.enum';
import { SortValue } from '../../enum';
import { trim } from '@credebl/common/cast.helper';

class Issuer {
@ApiProperty()
Expand Down Expand Up @@ -209,6 +210,14 @@ export class OOBIssueCredentialDto extends CredentialsIssuanceDto {
@IsNotEmpty({ message: 'Please provide valid attributes' })
@Type(() => Attribute)
attributes?: Attribute[];

@ApiProperty({
example: false
})
@IsOptional()
@IsNotEmpty()
@IsBoolean({message: 'isShortenUrl must be boolean'})
isShortenUrl?: boolean;


@ApiProperty()
Expand Down
12 changes: 6 additions & 6 deletions apps/api-gateway/src/issuance/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export class IssuanceService extends BaseService {
}> {
let payload;
if (IssueCredentialType.INDY === issueCredentialDto.credentialType) {
payload = { attributes: issueCredentialDto.attributes, comment: issueCredentialDto.comment, credentialDefinitionId: issueCredentialDto.credentialDefinitionId, orgId: issueCredentialDto.orgId, protocolVersion: issueCredentialDto.protocolVersion, goalCode: issueCredentialDto.goalCode, parentThreadId: issueCredentialDto.parentThreadId, willConfirm: issueCredentialDto.willConfirm, label: issueCredentialDto.label, autoAcceptCredential: issueCredentialDto.autoAcceptCredential, credentialType: issueCredentialDto.credentialType };
}
if (IssueCredentialType.JSONLD === issueCredentialDto.credentialType) {
payload = { credential: issueCredentialDto.credential, options:issueCredentialDto.options, comment: issueCredentialDto.comment, orgId: issueCredentialDto.orgId, protocolVersion: issueCredentialDto.protocolVersion, goalCode: issueCredentialDto.goalCode, parentThreadId: issueCredentialDto.parentThreadId, willConfirm: issueCredentialDto.willConfirm, label: issueCredentialDto.label, autoAcceptCredential: issueCredentialDto.autoAcceptCredential, credentialType: issueCredentialDto.credentialType };
}
payload = { attributes: issueCredentialDto.attributes, comment: issueCredentialDto.comment, credentialDefinitionId: issueCredentialDto.credentialDefinitionId, orgId: issueCredentialDto.orgId, protocolVersion: issueCredentialDto.protocolVersion, goalCode: issueCredentialDto.goalCode, parentThreadId: issueCredentialDto.parentThreadId, willConfirm: issueCredentialDto.willConfirm, label: issueCredentialDto.label, autoAcceptCredential: issueCredentialDto.autoAcceptCredential, credentialType: issueCredentialDto.credentialType, isShortenUrl: issueCredentialDto.isShortenUrl };
}
if (IssueCredentialType.JSONLD === issueCredentialDto.credentialType) {
payload = { credential: issueCredentialDto.credential, options: issueCredentialDto.options, comment: issueCredentialDto.comment, orgId: issueCredentialDto.orgId, protocolVersion: issueCredentialDto.protocolVersion, goalCode: issueCredentialDto.goalCode, parentThreadId: issueCredentialDto.parentThreadId, willConfirm: issueCredentialDto.willConfirm, label: issueCredentialDto.label, autoAcceptCredential: issueCredentialDto.autoAcceptCredential, credentialType: issueCredentialDto.credentialType, isShortenUrl: issueCredentialDto.isShortenUrl };
}

return this.sendNats(this.issuanceProxy, 'send-credential-create-offer-oob', payload);
}

Expand Down
6 changes: 6 additions & 0 deletions apps/api-gateway/src/utilities/dtos/shortening-url.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ interface Attribute {
name: string;
value: string;
}

export class GenericDto {
@ApiProperty()
@IsNotEmpty()
data: string | object;
}
19 changes: 16 additions & 3 deletions apps/api-gateway/src/utilities/utilities.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApiForbiddenResponse, ApiOperation, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { Controller, UseFilters, Post, Body, Res, HttpStatus } from '@nestjs/common';
import { Controller, UseFilters, Post, Body, Res, HttpStatus, Param } from '@nestjs/common';
import IResponse from '@credebl/common/interfaces/response.interface';
import { Response } from 'express';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto';
import { ResponseMessages } from '@credebl/common/response-messages';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { UtilitiesDto } from './dtos/shortening-url.dto';
import { GenericDto, UtilitiesDto } from './dtos/shortening-url.dto';
import { UtilitiesService } from './utilities.service';

@UseFilters(CustomExceptionFilter)
Expand All @@ -20,7 +20,7 @@ export class UtilitiesController {
constructor(
private readonly utilitiesService: UtilitiesService
) { }


@Post('/')
@ApiOperation({ summary: 'Create a shorteningurl', description: 'Create a shortening url' })
Expand All @@ -35,5 +35,18 @@ export class UtilitiesController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Post('/store-object/:persist')
@ApiOperation({ summary: 'Store an object and return a short url to it', description: 'Create a short url representing the object' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
async storeObject(@Body() storeObjectDto: GenericDto, @Param('persist') persist: boolean, @Res() res: Response): Promise<Response> {
const shorteningUrl = await this.utilitiesService.storeObject(persist.valueOf(), storeObjectDto);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.storeObject.success.storeObject,
data: shorteningUrl
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

}

5 changes: 5 additions & 0 deletions apps/api-gateway/src/utilities/utilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ export class UtilitiesService extends BaseService {
async createShorteningUrl(shorteningUrlDto: UtilitiesDto): Promise<string> {
return this.sendNatsMessage(this.serviceProxy, 'create-shortening-url', shorteningUrlDto);
}

async storeObject(persistent: boolean, storeObj: unknown): Promise<string> {
const payload = {persistent, storeObj};
return this.sendNatsMessage(this.serviceProxy, 'store-object-return-url', payload);
}
}
22 changes: 14 additions & 8 deletions apps/api-gateway/src/verification/dto/request-proof.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ArrayNotEmpty, IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString, ValidateIf, ValidateNested, IsUUID } from 'class-validator';
import { toLowerCase, trim } from '@credebl/common/cast.helper';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ArrayNotEmpty, IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString, IsUUID, ValidateIf, ValidateNested } from 'class-validator';
import { Transform, Type } from 'class-transformer';
import { toLowerCase, trim } from '@credebl/common/cast.helper';

import { AutoAccept } from '@credebl/enum/enum';
import { IProofFormats } from '../interfaces/verification.interface';


export class ProofRequestAttribute {

@ValidateIf((obj) => obj.attributeNames === undefined)
Expand All @@ -16,7 +16,7 @@ export class ProofRequestAttribute {
@ValidateIf((obj) => obj.attributeName === undefined)
@IsArray({ message: 'attributeNames must be an array.' })
@ArrayNotEmpty({ message: 'array can not be empty' })
@IsString({ each: true})
@IsString({ each: true })
@IsNotEmpty({ each: true, message: 'each element cannot be empty' })
attributeNames?: string[];

Expand Down Expand Up @@ -127,7 +127,7 @@ export class OutOfBandRequestProof extends ProofPayload {
type: () => [ProofRequestAttribute]
})
@IsArray({ message: 'attributes must be in array' })
@ValidateNested({each: true})
@ValidateNested({ each: true })
@IsObject({ each: true })
@IsNotEmpty({ message: 'please provide valid attributes' })
@Type(() => ProofRequestAttribute)
Expand Down Expand Up @@ -254,11 +254,11 @@ export class SendProofRequestPayload {
requested_attributes: {
verifynameAddress: {
names: ['name', 'address'],
restrictions: [{'schema_id': 'KU583UbI4yAKfaBTSz1rqG:2:National ID:1.0.0'}]
restrictions: [{ 'schema_id': 'KU583UbI4yAKfaBTSz1rqG:2:National ID:1.0.0' }]
},
verifyBirthPlace: {
name: 'Place',
restrictions: [{'schema_id': 'KU583UbI4yAKfaBTSz1rqG:2:Birth Certificate:1.0.0'}]
restrictions: [{ 'schema_id': 'KU583UbI4yAKfaBTSz1rqG:2:Birth Certificate:1.0.0' }]
}
},
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -325,6 +325,12 @@ export class SendProofRequestPayload {
@IsOptional()
@IsUUID()
@IsNotEmpty({ message: 'please provide valid parentThreadId' })
parentThreadId: string;
parentThreadId: string;

@ApiProperty({ example: true })
@IsBoolean()
@IsOptional()
@IsNotEmpty({message:'Please provide the flag for shorten url.'})
isShortenUrl?: boolean;
}

56 changes: 47 additions & 9 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class ConnectionService {

this.logger.log(`logoUrl:::, ${organisation.logoUrl}`);
const connectionPayload = {
multiUseInvitation: multiUseInvitation || true,
autoAcceptConnection: autoAcceptConnection || true,
multiUseInvitation: multiUseInvitation ?? true,
autoAcceptConnection: autoAcceptConnection ?? true,
alias: alias || undefined,
imageUrl: organisation.logoUrl || imageUrl || undefined,
label: organisation.name,
Expand All @@ -83,13 +83,11 @@ export class ConnectionService {
apiKey = await this._getOrgAgentApiKey(orgId);
}
const createConnectionInvitation = await this._createConnectionInvitation(connectionPayload, url, apiKey);
const invitationObject = createConnectionInvitation?.message?.invitation['@id'];
let shortenedUrl;
if (agentDetails?.tenantId) {
shortenedUrl = `${agentEndPoint}/multi-tenancy/url/${agentDetails?.tenantId}/${invitationObject}`;
} else {
shortenedUrl = `${agentEndPoint}/url/${invitationObject}`;
}
const connectionInvitaionUrl: string = createConnectionInvitation?.message?.invitationUrl;
GHkrishna marked this conversation as resolved.
Show resolved Hide resolved
const shortenedUrl: string = await this.storeConnectionObjectAndReturnUrl(
connectionInvitaionUrl,
connectionPayload.multiUseInvitation
);

const saveConnectionDetails = await this.connectionRepository.saveAgentConnectionInvitations(
shortenedUrl,
Expand Down Expand Up @@ -457,6 +455,7 @@ export class ConnectionService {
});
}


/**
* Description: Fetch agent url
* @param referenceId
Expand Down Expand Up @@ -752,4 +751,43 @@ export class ConnectionService {
}
}
}

async storeConnectionObjectAndReturnUrl(connectionInvitationUrl: string, persistent: boolean): Promise<string> {
const storeObj = connectionInvitationUrl;
//nats call in agent-service to create an invitation url
const pattern = { cmd: 'store-object-return-url' };
const payload = { persistent, storeObj };

try {
const message = await this.connectionServiceProxy
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.send<any>(pattern, payload)
.toPromise()
.catch((error) => {
this.logger.error(
`[storeConnectionObjectAndReturnUrl] [NATS call]- error in storing object and returning url : ${JSON.stringify(
error
)}`
);
throw new HttpException(
{
status: error.statusCode,
error: error.error?.message?.error ? error.error?.message?.error : error.error,
message: error.message
},
error.error
);
});
return message;
} catch (error) {
this.logger.error(`catch: ${JSON.stringify(error)}`);
throw new HttpException(
{
status: error.status,
error: error.message
},
error.status
);
}
}
}
3 changes: 2 additions & 1 deletion apps/connection/src/interfaces/connection.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ export interface IConnectionInvitation {
}
interface IInvitation {
invitation: string;

invitationUrl: string;
}

export interface OrgAgent {
organisation: organisation;
id: string;
Expand Down
Loading