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

Feat: Added Credential Schema Service #219

Merged
merged 76 commits into from
Jul 11, 2023
Merged
Changes from 13 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
87ecce0
Feat: Added Credential Schema Service
KDwevedi Apr 19, 2023
0d39a7a
Feat: Added Credential Schema Service
KDwevedi Apr 19, 2023
ac7d507
Update: removed build files
KDwevedi Apr 25, 2023
ea9416b
Feat: Better function naming
KDwevedi Apr 25, 2023
30ee8ca
Fix: better variable names
KDwevedi Apr 25, 2023
64e4363
Fix: Better variable names
KDwevedi Apr 25, 2023
1806ab6
Fix: better function name
KDwevedi Apr 25, 2023
085af23
Fix: better function name
KDwevedi Apr 25, 2023
7db65b8
feat: Add tests
tushar5526 Jun 20, 2023
2e4ce2a
Merge pull request #1 from tushar5526/cred-schema-test
techsavvyash Jun 21, 2023
8401fed
fix
techsavvyash Jun 21, 2023
0e7b123
fix: variable and fn naming
techsavvyash Jun 22, 2023
0db4b6c
fix: openAPI spec compliance
techsavvyash Jun 28, 2023
38b2401
feat: Added dockerized tests
tushar5526 Jun 28, 2023
c5d5613
fix: wait for DB
tushar5526 Jun 28, 2023
44dd235
Merge pull request #3 from tushar5526/cred-schema-docker-test
techsavvyash Jun 28, 2023
9f90f19
fix: Sign schema after creating
tushar5526 Jun 28, 2023
d0f2620
fix: Break createSchema into create and sign schema
tushar5526 Jun 29, 2023
db80f82
feat: Fix tests and add basic test for schema service
tushar5526 Jun 29, 2023
b69e3ea
fix: use mock util service to mimick identity service.
tushar5526 Jul 3, 2023
ba748a1
feat: show test coverage results as well
tushar5526 Jul 3, 2023
f5a39b7
fix: Use fixtures for test payloads
tushar5526 Jul 3, 2023
2f0843f
fix: add semantic versioning check
tushar5526 Jul 3, 2023
e333a18
fix: create uuid as id and then store in DB. Update tests
tushar5526 Jul 3, 2023
7f4c942
Merge pull request #5 from tushar5526/tests
tushar5526 Jul 4, 2023
1f4be43
Merge branch 'main' of https://github.com/Sunbird-RC/sunbird-rc-core
tushar5526 Jul 4, 2023
514e1e1
feat: Add logging
tushar5526 Jul 4, 2023
08a3667
Merge pull request #7 from KDwevedi/logger
tushar5526 Jul 4, 2023
7b46af7
feat: Add health check for prisma
tushar5526 Jul 4, 2023
4f1fef2
Merge pull request #8 from KDwevedi/health-check
tushar5526 Jul 4, 2023
28499e5
feat: add health checks, remove prisma service and fix docker compose
tushar5526 Jul 4, 2023
846ceb4
fix: Use prisma client
tushar5526 Jul 4, 2023
26246a8
fix: use prisma client
tushar5526 Jul 4, 2023
024c3ca
fix: update dependencies in test
tushar5526 Jul 4, 2023
712457f
feat: Add swagger for render-template controller
tushar5526 Jul 4, 2023
4e70af2
fix: controller path and start work on createSchema logic
tushar5526 Jul 5, 2023
61e411e
fix: schema validator tests
tushar5526 Jul 5, 2023
1a43c5d
fix: make strict tuples to be false in ajv
tushar5526 Jul 5, 2023
71d36e8
fix: change to schema
tushar5526 Jul 5, 2023
9c04590
Merge pull request #9 from KDwevedi/create-schema
tushar5526 Jul 5, 2023
08cf3c4
Merge branch 'release-2.0.0' into main
tushar5526 Jul 5, 2023
1fcb58c
fix: don't hard validate
tushar5526 Jul 5, 2023
5b77157
fix: Improve logs and error handling
tushar5526 Jul 5, 2023
629a901
fix: PR review comments + code cleanup
techsavvyash Jul 5, 2023
9a3e5b6
Merge pull request #10 from KDwevedi/refactor-schema
tushar5526 Jul 5, 2023
3be2fe2
fix: Fix sign and generate DIDs
tushar5526 Jul 5, 2023
7560cf9
fix
techsavvyash Jul 5, 2023
b3cd410
Merge pull request #11 from KDwevedi/refactor-schema
techsavvyash Jul 5, 2023
4b677c8
fix: add mock generatDID
tushar5526 Jul 5, 2023
6297e21
fix
techsavvyash Jul 5, 2023
46952fd
fix: Fix indentation in makefile
tushar5526 Jul 6, 2023
a6a5206
fix: Change default port
tushar5526 Jul 6, 2023
068d9e2
fix: Refactor tests to run dependents services first
tushar5526 Jul 7, 2023
9380ba7
fix: Refactor tests to not use mock services
tushar5526 Jul 7, 2023
20a52e3
fix: Stop identity service when done testing
tushar5526 Jul 7, 2023
6c8bff0
Merge pull request #12 from KDwevedi/tests-refactor
tushar5526 Jul 7, 2023
3e2c0ac
Change service name
tushar5526 Jul 7, 2023
a1599a0
fix: generate did in tests
tushar5526 Jul 7, 2023
41a777a
Merge pull request #13 from KDwevedi/tests
tushar5526 Jul 7, 2023
076596b
Merge branch 'main' of https://github.com/KDwevedi/sunbird-rc-core in…
techsavvyash Jul 7, 2023
03cf010
feat: add schema updation flow to APIs
techsavvyash Jul 7, 2023
38858eb
Merge pull request #14 from KDwevedi/refactor-schema
techsavvyash Jul 7, 2023
576e14d
fix: Add identity service to healthcheck fo cred-schema
tushar5526 Jul 10, 2023
104dbbd
fix: Add tests, fix sample schema, update identiy to use rcw in vault
tushar5526 Jul 10, 2023
f160e08
feat: push e2e test
tushar5526 Jul 10, 2023
b18009a
fix: updation logic
techsavvyash Jul 10, 2023
9112cba
Merge branch 'main' of https://github.com/KDwevedi/sunbird-rc-core in…
techsavvyash Jul 10, 2023
5217378
Merge pull request #15 from KDwevedi/refactor-schema
tushar5526 Jul 10, 2023
60c5677
fix: add error on invalid status type
techsavvyash Jul 10, 2023
7f9a5f9
Merge pull request #16 from KDwevedi/refactor-schema
tushar5526 Jul 10, 2023
1abf690
fix
techsavvyash Jul 10, 2023
34aa1fd
Merge pull request #17 from KDwevedi/refactor-schema
tushar5526 Jul 10, 2023
3ac8a29
feat: added tests
tushar5526 Jul 10, 2023
33056c3
feat: add more tests in schema
tushar5526 Jul 11, 2023
379d198
feat: add tests for rendering templates
tushar5526 Jul 11, 2023
098606a
feat: add tests for template
tushar5526 Jul 11, 2023
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ build: java/registry/target/registry.jar
make -C services/public-key-service docker
make -C services/context-proxy-service docker
docker build -t dockerhub/sunbird-rc-nginx .
make -C services/credential-schema/ docker

java/registry/target/registry.jar: $(SOURCES)
echo $(SOURCES)
@@ -62,6 +63,7 @@ test:
make -C services/certificate-signer test
make -C services/public-key-service test
make -C services/context-proxy-service test
make -c services/credential-schema test

clean:
@rm -rf target || true
@@ -94,6 +96,7 @@ release: test
docker push dockerhub/sunbird-rc-context-proxy-service:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-nginx:latest
docker push dockerhub/sunbird-rc-nginx:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-credential-schema:$(RELEASE_VERSION)
@cd tools/cli/ && npm publish


25 changes: 25 additions & 0 deletions services/credential-schema/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
38 changes: 38 additions & 0 deletions services/credential-schema/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

#Environment files
.env
5 changes: 5 additions & 0 deletions services/credential-schema/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2
}
6 changes: 6 additions & 0 deletions services/credential-schema/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:16 as dependencies
WORKDIR /app
COPY . ./
RUN yarn
EXPOSE 3000
CMD ["yarn", "start"]
86 changes: 86 additions & 0 deletions services/credential-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Credential Schema Microservice

## Description

[Nest](https://github.com/nestjs/nest) based CRUD APIs for handling the schemas of different verifiable credentials used for implementing the [Unified Learner's Passbook](https://github.com/Unified-Learners-Passbook) in the state of Uttar Pradesh, India.

## Installation

```bash

$ npm install

```
OR
```bash

$ npx yarn

```
## Running the app

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

OR

```bash
# development
$ npx yarn run start

# watch mode
$ npx yarn run start:dev

# production mode
$ npx yarn run start:prod
```

## Test

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

OR

```bash
# unit tests
$ npx yarn run test

# e2e tests
$ npx yarn run test:e2e

# test coverage
$ npx yarn run test:cov
```

## Stay in touch

- Authors - [Yash Mittal](https://github.com/techsavvyash) and [Chakshu Gautam](https://github.com/ChakshuGautam)
- Website - [https://nestjs.com](https://nestjs.com/)

## License

Nest is [MIT licensed](LICENSE).

## Reference Links

- [W3C Credential Schema (Currently being used)](https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json)
- [W3C Credential Schema (initially used)](https://w3c-ccg.github.io/vc-json-schemas/schema/1.0/schema.json)
- [W3C JSON Schemas Website](https://w3c-ccg.github.io/vc-json-schemas/)
- [API Documentation](https://github.com/Sunbird-RC/sunbird-rc-core/tree/main/api-documentation)
5 changes: 5 additions & 0 deletions services/credential-schema/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
89 changes: 89 additions & 0 deletions services/credential-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "cred-schema-ms",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@fastify/static": "^6.6.0",
"@handlebars/parser": "^2.1.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/platform-fastify": "^9.2.1",
"@nestjs/swagger": "^6.1.4",
"@prisma/client": "4.7.1",
"ajv": "^8.11.2",
"cache-manager": "^5.1.4",
"fastify-swagger": "^5.2.0",
"flat": "^5.0.2",
"handlebars": "4.7.7",
"json-schema-to-typescript": "^11.0.2",
"jwks-rsa": "^3.0.0",
"passport": "^0.6.0",
"passport-http": "^0.3.0",
"passport-jwt": "^4.0.1",
"prisma": "4.7.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "28.1.8",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- CreateTable
CREATE TABLE "VerifiableCredentialSchema" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"version" TEXT NOT NULL,
"type" TEXT NOT NULL,
"schema" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"tags" TEXT[],

CONSTRAINT "VerifiableCredentialSchema_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VerifiablePresentationSchema" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"version" TEXT NOT NULL,
"type" TEXT NOT NULL,
"schema" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"tags" TEXT[],

CONSTRAINT "VerifiablePresentationSchema_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "VerifiableCredentialSchema_type_idx" ON "VerifiableCredentialSchema" USING HASH ("type");

-- CreateIndex
CREATE INDEX "VerifiableCredentialSchema_name_idx" ON "VerifiableCredentialSchema" USING HASH ("name");

-- CreateIndex
CREATE INDEX "VerifiablePresentationSchema_type_idx" ON "VerifiablePresentationSchema" USING HASH ("type");

-- CreateIndex
CREATE INDEX "VerifiablePresentationSchema_name_idx" ON "VerifiablePresentationSchema" USING HASH ("name");
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- Changed the type of `version` on the `VerifiableCredentialSchema` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `version` on the `VerifiablePresentationSchema` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
*/
-- AlterTable
ALTER TABLE "VerifiableCredentialSchema" DROP COLUMN "version",
ADD COLUMN "version" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "VerifiablePresentationSchema" DROP COLUMN "version",
ADD COLUMN "version" INTEGER NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Warnings:
- You are about to drop the column `description` on the `VerifiableCredentialSchema` table. All the data in the column will be lost.
- You are about to drop the column `description` on the `VerifiablePresentationSchema` table. All the data in the column will be lost.
- Added the required column `author` to the `VerifiableCredentialSchema` table without a default value. This is not possible if the table is not empty.
- Added the required column `authored` to the `VerifiableCredentialSchema` table without a default value. This is not possible if the table is not empty.
- Added the required column `proof` to the `VerifiableCredentialSchema` table without a default value. This is not possible if the table is not empty.
- Added the required column `author` to the `VerifiablePresentationSchema` table without a default value. This is not possible if the table is not empty.
- Added the required column `authored` to the `VerifiablePresentationSchema` table without a default value. This is not possible if the table is not empty.
- Added the required column `proof` to the `VerifiablePresentationSchema` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "VerifiableCredentialSchema" DROP COLUMN "description",
ADD COLUMN "author" TEXT NOT NULL,
ADD COLUMN "authored" TIMESTAMP(3) NOT NULL,
ADD COLUMN "proof" JSONB NOT NULL;

-- AlterTable
ALTER TABLE "VerifiablePresentationSchema" DROP COLUMN "description",
ADD COLUMN "author" TEXT NOT NULL,
ADD COLUMN "authored" TIMESTAMP(3) NOT NULL,
ADD COLUMN "proof" JSONB NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "VerifiableCredentialSchema" ALTER COLUMN "version" SET DATA TYPE TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "Template" (
"id" TEXT NOT NULL,
"schema" TEXT NOT NULL,
"template" TEXT NOT NULL,
"type" TEXT NOT NULL,

CONSTRAINT "Template_pkey" PRIMARY KEY ("id")
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- You are about to drop the column `schema` on the `Template` table. All the data in the column will be lost.
- Added the required column `schemaId` to the `Template` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Template" DROP COLUMN "schema",
ADD COLUMN "createdBy" TEXT,
ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "schemaId" TEXT NOT NULL,
ADD COLUMN "updatedBy" TEXT,
ADD COLUMN "updated_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP;
Loading