Skip to content

Commit

Permalink
Merge pull request #558 from credebl/develop
Browse files Browse the repository at this point in the history
Develop to qa
  • Loading branch information
KulkarniShashank authored Feb 29, 2024
2 parents 8bdf391 + 7e36041 commit 97cbddf
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 104 deletions.
41 changes: 41 additions & 0 deletions Dockerfiles/Dockerfile.notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Stage 1: Build the application
FROM node:18-alpine as build
RUN npm install -g pnpm --ignore-scripts
# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json ./
#COPY package-lock.json ./

# Install dependencies
RUN pnpm i --ignore-scripts

# Copy the rest of the application code
COPY . .
RUN cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate

# Build the notification service
RUN npm run build notification


# Stage 2: Create the final image
FROM node:18-alpine
RUN npm install -g pnpm --ignore-scripts
# Set the working directory
WORKDIR /app

# Copy the compiled code from the build stage
COPY --from=build /app/dist/apps/notification/ ./dist/apps/notification/

# Copy the libs folder from the build stage
COPY --from=build /app/libs/ ./libs/
#COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate && cd ../.. && node dist/apps/notification/main.js"]

# docker build -t notification -f Dockerfiles/Dockerfile.notification .
# docker run -d --env-file .env --name notification docker.io/library/notification
# docker logs -f notification
193 changes: 187 additions & 6 deletions apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,109 @@
/* eslint-disable @typescript-eslint/array-type */

import { IsArray, IsNotEmpty, IsOptional, IsString, IsEmail, ArrayMaxSize, ValidateNested, ArrayMinSize, IsBoolean, IsDefined, MaxLength, IsEnum } from 'class-validator';
import { IsArray, IsNotEmpty, IsOptional, IsString, IsEmail, ArrayMaxSize, ValidateNested, ArrayMinSize, IsBoolean, IsDefined, MaxLength, IsEnum, IsObject} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
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';

class Issuer {
@ApiProperty()
@IsNotEmpty({ message: 'id is required' })
@Type(() => String)
id:string | { id?: string };
}
class Credential {
@ApiProperty()
@IsNotEmpty({ message: 'context is required' })
@IsCredentialJsonLdContext()
'@context': Array<string | JsonObject>;

@ApiProperty()
@IsNotEmpty({ message: 'type is required' })
type: string[];

@ApiProperty()
@IsString({ message: 'id should be string' })
@IsNotEmpty({ message: 'id is required' })
@Type(() => String)
@IsOptional()
id?:string;


@ApiProperty()
@ValidateNested({ each: true })
@Type(() => Issuer)
issuer:Issuer;

@ApiProperty()
@IsString({ message: 'issuance date should be string' })
@IsNotEmpty({ message: 'issuance date is required' })
@Type(() => String)
issuanceDate:string;

@ApiProperty()
@IsString({ message: 'expiration date should be string' })
@IsNotEmpty({ message: 'expiration date is required' })
@Type(() => String)
@IsOptional()
expirationDate?:string;

@ApiProperty()
@IsNotEmpty({ message: ' credential subject required' })
credentialSubject: SingleOrArray<JsonObject>;
[key: string]: unknown

}

export class JsonLdCredentialDetailCredentialStatus {
public constructor(options: JsonLdCredentialDetailCredentialStatusOptions) {
if (options) {
this.type = options.type;
}
}
@IsString()
public type!: string;
}
export class JsonLdCredentialDetailOptions {
public constructor(options: JsonLdCredentialDetailOptionsOptions) {
if (options) {
this.proofPurpose = options.proofPurpose;
this.created = options.created;
this.domain = options.domain;
this.challenge = options.challenge;
this.credentialStatus = options.credentialStatus;
this.proofType = options.proofType;
}
}

@IsString()
@IsNotEmpty({ message: 'proof purpose is required' })
public proofPurpose!: string;

@IsString()
@IsOptional()
public created?: string;

@IsString()
@IsOptional()
public domain?: string;

@IsString()
@IsOptional()
public challenge?: string;

@IsString()
@IsNotEmpty({ message: 'proof type is required' })
public proofType!: string;

@IsOptional()
@IsObject()
public credentialStatus?: JsonLdCredentialDetailCredentialStatus;
}
class Attribute {
@ApiProperty()
@IsString({ message: 'Attribute name should be string' })
Expand All @@ -33,7 +130,8 @@ class CredentialsIssuanceDto {
@IsNotEmpty({ message: 'Please provide valid credential definition id' })
@IsString({ message: 'credential definition id should be string' })
@Transform(({ value }) => value.trim())
credentialDefinitionId: string;
@IsOptional()
credentialDefinitionId?: string;

@ApiProperty({ example: 'string' })
@IsNotEmpty({ message: 'Please provide valid comment' })
Expand Down Expand Up @@ -86,6 +184,12 @@ class CredentialsIssuanceDto {
})
autoAcceptCredential?: string;

@ApiProperty({ example: 'jsonld' })
@IsNotEmpty({ message: 'Please provide credential type ' })
@Transform(({ value }) => trim(value).toLocaleLowerCase())
@IsOptional()
credentialType:IssueCredentialType;

orgId: string;
}

Expand All @@ -101,8 +205,29 @@ export class OOBIssueCredentialDto extends CredentialsIssuanceDto {
@IsArray()
@ValidateNested({ each: true })
@ArrayMinSize(1)
@IsOptional()
@IsNotEmpty({ message: 'Please provide valid attributes' })
@Type(() => Attribute)
attributes: Attribute[];
attributes?: Attribute[];


@ApiProperty()
@IsNotEmpty({ message: 'Please provide valid credential' })
@IsObject({ message: 'credential should be an object' })
@Type(() => Credential)
@IsOptional()
@ValidateNested({ each: true })
credential?:Credential;


@ApiProperty()
@IsOptional()
@IsNotEmpty({ message: 'Please provide valid options' })
@IsObject({ message: 'options should be an object' })
@ValidateNested({ each: true })
@Type(() => JsonLdCredentialDetailOptions)
options?:JsonLdCredentialDetailOptions;

}

class CredentialOffer {
Expand All @@ -111,7 +236,8 @@ class CredentialOffer {
@IsArray({ message: 'Attributes should be an array' })
@ValidateNested({ each: true })
@Type(() => Attribute)
attributes: Attribute[];
@IsOptional()
attributes?: Attribute[];

@ApiProperty({ example: '[email protected]' })
@IsEmail({}, { message: 'Please provide a valid email' })
Expand All @@ -121,6 +247,22 @@ class CredentialOffer {
@Transform(({ value }) => trim(value))
@Type(() => String)
emailId: string;

@IsNotEmpty({ message: 'Please provide valid credential' })
@IsObject({ message: 'credential should be an object' })
@Type(() => Credential)
@IsOptional()
@ValidateNested({ each: true })
credential?:Credential;

@ApiProperty()
@IsOptional()
@IsNotEmpty({ message: 'Please provide valid options' })
@IsObject({ message: 'options should be an object' })
@ValidateNested({ each: true })
@Type(() => JsonLdCredentialDetailOptions)
options?:JsonLdCredentialDetailOptions;

}

export class IssueCredentialDto extends OOBIssueCredentialDto {
Expand Down Expand Up @@ -218,7 +360,39 @@ export class CredentialAttributes {
}

export class OOBCredentialDtoWithEmail {
@ApiProperty({ example: [{ 'emailId': '[email protected]', 'attributes': [{ 'value': 'string', 'name': 'string' }] }] })
@ApiProperty({ example: [
{
'emailId': '[email protected]',
'credential': {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1'
],
'type': [
'VerifiableCredential',
'UniversityDegreeCredential'
],
'issuer': {
'id': 'did:key:z6Mkn72LVp3mq1fWSefkSMh5V7qrmGfCV4KH3K6SoTM21ouM'
},
'issuanceDate': '2019-10-12T07:20:50.52Z',
'credentialSubject': {
'id': 'did:key:z6Mkn72LVp3mq1fWSefkSMh5V7qrmGfCV4KH3K6SoTM21ouM',
'degree': {
'type': 'BachelorDegree',
'name': 'Bachelor of Science and Arts'
}
}
},
'options': {
'proofType': 'Ed25519Signature2018',
'proofPurpose': 'assertionMethod'
}
}
]


})
@IsNotEmpty({ message: 'Please provide valid attributes' })
@IsArray({ message: 'attributes should be array' })
@ArrayMaxSize(Number(process.env.OOB_BATCH_SIZE), { message: `Limit reached (${process.env.OOB_BATCH_SIZE} credentials max). Easily handle larger batches via seamless CSV file uploads` })
Expand All @@ -229,8 +403,9 @@ export class OOBCredentialDtoWithEmail {
@ApiProperty({ example: 'string' })
@IsNotEmpty({ message: 'Please provide valid credential definition id' })
@IsString({ message: 'credential definition id should be string' })
@IsOptional()
@Transform(({ value }) => value.trim())
credentialDefinitionId: string;
credentialDefinitionId?: string;

@ApiProperty({ example: 'string' })
@IsOptional()
Expand All @@ -244,6 +419,12 @@ export class OOBCredentialDtoWithEmail {
@IsString({ message: 'protocol version should be string' })
protocolVersion?: string;

@ApiProperty({ example: 'jsonld' })
@IsNotEmpty({ message: 'Please provide credential type ' })
@Transform(({ value }) => trim(value).toLocaleLowerCase())
@IsOptional()
credentialType:IssueCredentialType;

imageUrl?: string;

orgId: string;
Expand Down
24 changes: 24 additions & 0 deletions apps/api-gateway/src/issuance/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { JsonLdCredentialDetailCredentialStatus } from '../dtos/issuance.dto';
import { JsonValue } from '../utils/helper';

export interface IUserRequestInterface {
userId: string;
email: string;
Expand Down Expand Up @@ -75,3 +78,24 @@ export interface IIssuedCredentialSearchParams {
searchByText: string;
}

export enum IssueCredentialType {
JSONLD = 'jsonld',
INDY = 'indy'
}

export interface JsonObject {
[property: string]: JsonValue
}

export interface JsonLdCredentialDetailCredentialStatusOptions {
type: string
}

export interface JsonLdCredentialDetailOptionsOptions {
proofPurpose: string
created?: string
domain?: string
challenge?: string
credentialStatus?: JsonLdCredentialDetailCredentialStatus
proofType: string
}
Loading

0 comments on commit 97cbddf

Please sign in to comment.