From b0e8a1fd87b69f88d1e62ca8120f772473c6e28b Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Tue, 22 Aug 2023 19:47:57 +0530 Subject: [PATCH 1/3] feat: worked on the supabase integration and included the API authentication Signed-off-by: @nishad.shirsat --- apps/api-gateway/src/authz/authz.module.ts | 6 +- apps/api-gateway/src/authz/jwt.strategy.ts | 31 +-- apps/api-gateway/src/user/user.service.ts | 5 +- apps/user/interfaces/user.interface.ts | 2 +- apps/user/repositories/user.repository.ts | 20 +- apps/user/src/fido/fido.module.ts | 4 +- apps/user/src/user.controller.ts | 11 +- apps/user/src/user.module.ts | 4 +- apps/user/src/user.service.ts | 79 +++++-- .../src/dtos/create-user.dto.ts | 2 +- .../migration.sql | 18 -- .../migration.sql | 2 - .../20230809131410_org_status/migration.sql | 2 - .../20230809131741_org_slug/migration.sql | 13 -- .../migration.sql | 5 - .../migration.sql | 11 - .../migration.sql | 37 +++- libs/prisma-service/prisma/schema.prisma | 2 +- libs/supabase/src/index.ts | 2 + libs/supabase/src/supabase.module.ts | 8 + libs/supabase/src/supabase.service.ts | 48 ++++ libs/supabase/tsconfig.lib.json | 9 + nest-cli.json | 9 + package.json | 5 +- pnpm-lock.yaml | 208 +++++++++++++++++- tsconfig.json | 6 + 26 files changed, 422 insertions(+), 127 deletions(-) delete mode 100644 libs/prisma-service/prisma/migrations/20230809130946_user_activity/migration.sql delete mode 100644 libs/prisma-service/prisma/migrations/20230809131143_user_activity_org/migration.sql delete mode 100644 libs/prisma-service/prisma/migrations/20230809131410_org_status/migration.sql delete mode 100644 libs/prisma-service/prisma/migrations/20230809131741_org_slug/migration.sql delete mode 100644 libs/prisma-service/prisma/migrations/20230811125950_add_public_profile_flag_org_user/migration.sql delete mode 100644 libs/prisma-service/prisma/migrations/20230816113258_ledger_id_org_agents/migration.sql rename libs/prisma-service/prisma/migrations/{0_init => 20230822073057_init}/migration.sql (90%) create mode 100644 libs/supabase/src/index.ts create mode 100644 libs/supabase/src/supabase.module.ts create mode 100644 libs/supabase/src/supabase.service.ts create mode 100644 libs/supabase/tsconfig.lib.json diff --git a/apps/api-gateway/src/authz/authz.module.ts b/apps/api-gateway/src/authz/authz.module.ts index b8e84d2ee..1e6b80cd2 100644 --- a/apps/api-gateway/src/authz/authz.module.ts +++ b/apps/api-gateway/src/authz/authz.module.ts @@ -11,10 +11,11 @@ import { JwtStrategy } from './jwt.strategy'; import { MobileJwtStrategy } from './mobile-jwt.strategy'; import { Module } from '@nestjs/common'; import { PassportModule } from '@nestjs/passport'; -import { VerificationService } from '../verification/verification.service'; import { SocketGateway } from './socket.gateway'; +import { SupabaseService } from '@credebl/supabase'; import { UserModule } from '../user/user.module'; import { UserService } from '../user/user.service'; +import { VerificationService } from '../verification/verification.service'; //import { WebhookService } from "../../../platform-service/src/webhook/webhook.service"; @@ -46,7 +47,8 @@ import { UserService } from '../user/user.service'; ConnectionService, AgentService, CommonService, - UserService + UserService, + SupabaseService ], exports: [ PassportModule, diff --git a/apps/api-gateway/src/authz/jwt.strategy.ts b/apps/api-gateway/src/authz/jwt.strategy.ts index a53a78e07..c435799d2 100644 --- a/apps/api-gateway/src/authz/jwt.strategy.ts +++ b/apps/api-gateway/src/authz/jwt.strategy.ts @@ -1,17 +1,12 @@ -// src/authz/jwt.strategy.ts - import * as dotenv from 'dotenv'; -import * as jwt from 'jsonwebtoken'; import { ExtractJwt, Strategy } from 'passport-jwt'; import { Injectable, Logger } from '@nestjs/common'; -import { CommonConstants } from '@credebl/common/common.constant'; import { JwtPayload } from './jwt-payload.interface'; import { NotFoundException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { UserService } from '../user/user.service'; -import { passportJwtSecret } from 'jwks-rsa'; dotenv.config(); @@ -23,33 +18,17 @@ export class JwtStrategy extends PassportStrategy(Strategy) { private readonly usersService: UserService ) { super({ - - secretOrKeyProvider: (request, jwtToken, done) => { - const decodedToken = jwt.decode(jwtToken) as jwt.JwtPayload; - const audiance = decodedToken.iss.toString(); - const jwtOptions = { - cache: true, - rateLimit: true, - jwksRequestsPerMinute: 5, - jwksUri: `${audiance}${CommonConstants.URL_KEYCLOAK_JWKS}` - }; - const secretprovider = passportJwtSecret(jwtOptions); - let certkey; - secretprovider(request, jwtToken, async (err, data) => { - certkey = data; - done(null, certkey); - }); - }, jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), - algorithms: ['RS256'] + secretOrKey: process.env.SUPABASE_JWT_SECRET, + ignoreExpiration: false }); } async validate(payload: JwtPayload): Promise { - - const userDetails = await this.usersService.findUserByKeycloakId(payload?.sub); + + const userDetails = await this.usersService.findUserinSupabase(payload.sub); if (!userDetails.response) { - throw new NotFoundException('Keycloak user not found'); + throw new NotFoundException('User not found'); } return { diff --git a/apps/api-gateway/src/user/user.service.ts b/apps/api-gateway/src/user/user.service.ts index 3d74c6ac0..fbc39fd23 100644 --- a/apps/api-gateway/src/user/user.service.ts +++ b/apps/api-gateway/src/user/user.service.ts @@ -69,16 +69,17 @@ export class UserService extends BaseService { } } - async findUserByKeycloakId(id: string): Promise<{ response: object }> { + async findUserinSupabase(id: string): Promise<{ response: object }> { const payload = { id }; try { - return this.sendNats(this.serviceProxy, 'get-user-by-keycloak-id', payload); + return this.sendNats(this.serviceProxy, 'get-user-by-supabase', payload); } catch (error) { this.logger.error(`Error in get user:${JSON.stringify(error)}`); } } + async invitations(id: number, status: string, getAllInvitationsDto: GetAllInvitationsDto): Promise<{ response: object }> { const {pageNumber, pageSize, search} = getAllInvitationsDto; const payload = { id, status, pageNumber, pageSize, search }; diff --git a/apps/user/interfaces/user.interface.ts b/apps/user/interfaces/user.interface.ts index 4d19887b1..c7fcabf23 100644 --- a/apps/user/interfaces/user.interface.ts +++ b/apps/user/interfaces/user.interface.ts @@ -9,7 +9,7 @@ export interface UserI { isEmailVerified?: boolean, clientId?: string, clientSecret?: string, - keycloakUserId?: string, + supabaseUserId?: string, userOrgRoles?: object } diff --git a/apps/user/repositories/user.repository.ts b/apps/user/repositories/user.repository.ts index 7fad04539..bf5a5c7ee 100644 --- a/apps/user/repositories/user.repository.ts +++ b/apps/user/repositories/user.repository.ts @@ -1,10 +1,12 @@ /* eslint-disable prefer-destructuring */ import * as bcrypt from 'bcrypt'; + import { Injectable, Logger, NotFoundException } from '@nestjs/common'; +import { UpdateUserProfile, UserEmailVerificationDto, UserI, userInfo } from '../interfaces/user.interface'; + import { InternalServerErrorException } from '@nestjs/common'; import { PrismaService } from '@credebl/prisma-service'; -import { UpdateUserProfile, UserEmailVerificationDto, UserI, userInfo } from '../interfaces/user.interface'; // eslint-disable-next-line camelcase import { user } from '@prisma/client'; import { v4 as uuidv4 } from 'uuid'; @@ -136,11 +138,11 @@ export class UserRepository { * @param id * @returns User data */ - async getUserByKeycloakId(id: string): Promise { + async getUserBySupabaseId(id: string): Promise { try { return this.prisma.user.findFirst({ where: { - keycloakUserId: id + supabaseUserId: id }, select: { id: true, @@ -152,7 +154,7 @@ export class UserRepository { isEmailVerified: true, clientId: true, clientSecret: true, - keycloakUserId: true, + supabaseUserId: true, userOrgRoles: { include: { orgRole: true, @@ -202,7 +204,7 @@ export class UserRepository { isEmailVerified: true, clientId: true, clientSecret: true, - keycloakUserId: true, + supabaseUserId: true, userOrgRoles: { include: { orgRole: true, @@ -272,7 +274,7 @@ export class UserRepository { * @returns Updates organization details */ // eslint-disable-next-line camelcase - async updateUserDetails(id: number, keycloakUserId: string): Promise { + async updateUserDetails(id: number, supabaseUserId: string): Promise { try { const updateUserDetails = await this.prisma.user.update({ where: { @@ -280,7 +282,7 @@ export class UserRepository { }, data: { isEmailVerified: true, - keycloakUserId + supabaseUserId } }); return updateUserDetails; @@ -338,7 +340,7 @@ export class UserRepository { isEmailVerified: true, clientId: true, clientSecret: true, - keycloakUserId: true, + supabaseUserId: true, userOrgRoles: { where: { ...filterOptions @@ -404,7 +406,7 @@ export class UserRepository { isEmailVerified: true, clientId: false, clientSecret: false, - keycloakUserId: false + supabaseUserId: false }, take: pageSize, skip: (pageNumber - 1) * pageSize, diff --git a/apps/user/src/fido/fido.module.ts b/apps/user/src/fido/fido.module.ts index ee3b6b78e..a5106d814 100644 --- a/apps/user/src/fido/fido.module.ts +++ b/apps/user/src/fido/fido.module.ts @@ -11,6 +11,7 @@ import { KeycloakUrlService } from '@credebl/keycloak-url'; import { OrgRolesRepository } from 'libs/org-roles/repositories'; import { OrgRolesService } from '@credebl/org-roles'; import { PrismaService } from '@credebl/prisma-service'; +import { SupabaseService } from '@credebl/supabase'; import { UserActivityRepository } from 'libs/user-activity/repositories'; import { UserActivityService } from '@credebl/user-activity'; import { UserDevicesRepository } from '../../repositories/user-device.repository'; @@ -32,7 +33,7 @@ import { UserService } from '../user.service'; ]), HttpModule, CommonModule - ], +], controllers: [FidoController], providers: [ UserService, @@ -41,6 +42,7 @@ import { UserService } from '../user.service'; UserRepository, UserDevicesRepository, ClientRegistrationService, + SupabaseService, Logger, KeycloakUrlService, FidoUserRepository, diff --git a/apps/user/src/user.controller.ts b/apps/user/src/user.controller.ts index 6077d1e2c..94c55e6c1 100644 --- a/apps/user/src/user.controller.ts +++ b/apps/user/src/user.controller.ts @@ -50,14 +50,15 @@ export class UserController { return this.userService.updateUserProfile(payload.updateUserProfileDto); } - @MessagePattern({ cmd: 'get-user-by-keycloak-id' }) - async findByKeycloakId(payload: { id }): Promise { - return this.userService.findByKeycloakId(payload); + @MessagePattern({ cmd: 'get-user-by-supabase' }) + async findSupabaseUser(payload: { id }): Promise { + return this.userService.findSupabaseUser(payload); } + @MessagePattern({ cmd: 'get-user-by-mail' }) async findUserByEmail(payload: { email }): Promise { - return this.userService.findUserByEmail(payload); + return this.userService.findUserByEmail(payload); } @MessagePattern({ cmd: 'get-org-invitations' }) @@ -105,7 +106,7 @@ export class UserController { } @MessagePattern({ cmd: 'add-user' }) async addUserDetailsInKeyCloak(payload: { userEmail: string, userInfo: userInfo }): Promise { - return this.userService.createUserInKeyCloak(payload.userEmail, payload.userInfo); + return this.userService.createUserForToken(payload.userEmail, payload.userInfo); } // Fetch Users recent activities diff --git a/apps/user/src/user.module.ts b/apps/user/src/user.module.ts index 603a20e6b..42362c279 100644 --- a/apps/user/src/user.module.ts +++ b/apps/user/src/user.module.ts @@ -8,6 +8,7 @@ import { FidoModule } from './fido/fido.module'; import { KeycloakUrlService } from '@credebl/keycloak-url'; import { OrgRolesRepository } from 'libs/org-roles/repositories'; import { PrismaService } from '@credebl/prisma-service'; +import { SupabaseService } from '@credebl/supabase'; import { UserActivityRepository } from 'libs/user-activity/repositories'; import { UserActivityService } from '@credebl/user-activity'; import { UserController } from './user.controller'; @@ -30,7 +31,7 @@ import { UserService } from './user.service'; CommonModule, FidoModule, OrgRolesModule - ], +], controllers: [UserController], providers: [ UserService, @@ -38,6 +39,7 @@ import { UserService } from './user.service'; PrismaService, Logger, ClientRegistrationService, + SupabaseService, KeycloakUrlService, OrgRolesService, UserOrgRolesService, diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index 9666b8386..8e146abb5 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -2,6 +2,7 @@ import * as bcrypt from 'bcrypt'; import { BadRequestException, + // BadRequestException, ConflictException, Injectable, Logger, @@ -31,6 +32,7 @@ import { HttpException } from '@nestjs/common'; import { InvitationsI, UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface'; import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto'; import { UserActivityService } from '@credebl/user-activity'; +import { SupabaseService } from '@credebl/supabase'; @Injectable() @@ -38,6 +40,7 @@ export class UserService { constructor( private readonly prisma: PrismaService, private readonly clientRegistrationService: ClientRegistrationService, + private readonly supabaseService: SupabaseService, private readonly commonService: CommonService, private readonly orgRoleService: OrgRolesService, private readonly userOrgRoleService: UserOrgRolesService, @@ -106,7 +109,7 @@ export class UserService { } } catch (error) { - this.logger.error(`error in create keycloak user: ${JSON.stringify(error)}`); + this.logger.error(`Error in sendEmailForVerification: ${JSON.stringify(error)}`); throw new InternalServerErrorException(error.message); } } @@ -148,13 +151,8 @@ export class UserService { } } - /** - * - * @param param email, verification code - * @returns Email verification succcess - */ - async createUserInKeyCloak(email: string, userInfo: userInfo): Promise { + async createUserForToken(email: string, userInfo: userInfo): Promise { try { if (!email) { throw new UnauthorizedException(ResponseMessages.user.error.invalidEmail); @@ -163,7 +161,7 @@ export class UserService { if (!checkUserDetails) { throw new NotFoundException(ResponseMessages.user.error.invalidEmail); } - if (checkUserDetails.keycloakUserId) { + if (checkUserDetails.supabaseUserId) { throw new ConflictException(ResponseMessages.user.error.exists); } if (false === checkUserDetails.isEmailVerified) { @@ -178,13 +176,21 @@ export class UserService { if (!userDetails) { throw new NotFoundException(ResponseMessages.user.error.adduser); } - const clientManagementToken = await this.clientRegistrationService.getManagementToken(); + const supaUser = await this.supabaseService.getClient().auth.signUp({ + email, + password: userInfo.password + }); + + if (supaUser.error) { + throw new InternalServerErrorException(supaUser.error?.message); + } - const keycloakDetails = await this.keycloakUserRegistration(userDetails, clientManagementToken); + + const supaId = supaUser.data?.user?.id; - await this.userRepository.updateUserDetails( + await this.userRepository.updateUserDetails( userDetails.id, - keycloakDetails + supaId.toString() ); const holderRoleData = await this.orgRoleService.getRole(OrgRoles.HOLDER); @@ -192,7 +198,7 @@ export class UserService { return 'User created successfully'; } catch (error) { - this.logger.error(`error in create keycloak user: ${JSON.stringify(error)}`); + this.logger.error(`Error in createUserForToken: ${JSON.stringify(error)}`); throw new RpcException(error.response); } } @@ -290,9 +296,9 @@ export class UserService { } if (true === isPasskey && userData?.username && true === userData?.isFidoVerified) { - //Get user token from keycloak - const token = await this.clientRegistrationService.getUserToken(email, userData.password); - return token; + + return this.generateToken(email, password); + } const comparePassword = await bcrypt.compare(password, userData.password); @@ -302,15 +308,35 @@ export class UserService { throw new BadRequestException(ResponseMessages.user.error.invalidCredentials); } - //Get user token from kelycloak - const token = await this.clientRegistrationService.getUserToken(email, userData.password); - return token; + return this.generateToken(email, password); } catch (error) { this.logger.error(`In Login User : ${JSON.stringify(error)}`); throw new RpcException(error.response); } } + async generateToken(email: string, password: string): Promise { + const supaInstance = await this.supabaseService.getClient(); + + this.logger.error(`supaInstance::`, supaInstance); + + const { data, error } = await supaInstance.auth.signInWithPassword({ + email, + password + }); + + this.logger.error(`Supa Login Error::`, error); + + if (error) { + throw new BadRequestException(error?.message); + } + + const token = data?.session; + + return token; + } + + async getProfile(payload: { id }): Promise { try { return this.userRepository.getUserById(payload.id); @@ -340,13 +366,22 @@ export class UserService { async findByKeycloakId(payload: { id }): Promise { try { - return this.userRepository.getUserByKeycloakId(payload.id); + return this.userRepository.getUserBySupabaseId(payload.id); } catch (error) { this.logger.error(`get user: ${JSON.stringify(error)}`); throw new RpcException(error.response); } } + async findSupabaseUser(payload: { id }): Promise { + try { + return this.userRepository.getUserBySupabaseId(payload.id); + } catch (error) { + this.logger.error(`Error in findSupabaseUser: ${JSON.stringify(error)}`); + throw new RpcException(error.response); + } + } + async findUserByEmail(payload: { email }): Promise { try { return this.userRepository.findUserByEmail(payload.email); @@ -537,7 +572,7 @@ export class UserService { if (userDetails && !userDetails.isEmailVerified) { throw new ConflictException(ResponseMessages.user.error.verificationAlreadySent); - } else if (userDetails && userDetails.keycloakUserId) { + } else if (userDetails && userDetails.supabaseUserId) { throw new ConflictException(ResponseMessages.user.error.exists); } else if (null === userDetails) { return 'New User'; @@ -545,7 +580,7 @@ export class UserService { const userVerificationDetails = { isEmailVerified: userDetails.isEmailVerified, isFidoVerified: userDetails.isFidoVerified, - isKeycloak: null !== userDetails.keycloakUserId && undefined !== userDetails.keycloakUserId + isKeycloak: null !== userDetails.supabaseUserId && undefined !== userDetails.supabaseUserId }; return userVerificationDetails; } diff --git a/libs/client-registration/src/dtos/create-user.dto.ts b/libs/client-registration/src/dtos/create-user.dto.ts index 4970d97d1..162a2dd35 100644 --- a/libs/client-registration/src/dtos/create-user.dto.ts +++ b/libs/client-registration/src/dtos/create-user.dto.ts @@ -18,6 +18,6 @@ export class CreateUserDto { createdBy?: number; clientId?: string; clientSecret?: string; - keycloakUserId?: string; + supabaseUserId?: string; } diff --git a/libs/prisma-service/prisma/migrations/20230809130946_user_activity/migration.sql b/libs/prisma-service/prisma/migrations/20230809130946_user_activity/migration.sql deleted file mode 100644 index d5f65cfcb..000000000 --- a/libs/prisma-service/prisma/migrations/20230809130946_user_activity/migration.sql +++ /dev/null @@ -1,18 +0,0 @@ --- CreateTable -CREATE TABLE "user_activity" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "orgId" INTEGER NOT NULL, - "action" TEXT NOT NULL, - "details" TEXT NOT NULL, - "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "createdBy" INTEGER NOT NULL DEFAULT 1, - "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastChangedBy" INTEGER NOT NULL DEFAULT 1, - "deletedAt" TIMESTAMP(6), - - CONSTRAINT "user_activity_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/libs/prisma-service/prisma/migrations/20230809131143_user_activity_org/migration.sql b/libs/prisma-service/prisma/migrations/20230809131143_user_activity_org/migration.sql deleted file mode 100644 index 730d7d4e9..000000000 --- a/libs/prisma-service/prisma/migrations/20230809131143_user_activity_org/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AddForeignKey -ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/libs/prisma-service/prisma/migrations/20230809131410_org_status/migration.sql b/libs/prisma-service/prisma/migrations/20230809131410_org_status/migration.sql deleted file mode 100644 index a9946b817..000000000 --- a/libs/prisma-service/prisma/migrations/20230809131410_org_status/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "organisation" ADD COLUMN "status" TEXT; diff --git a/libs/prisma-service/prisma/migrations/20230809131741_org_slug/migration.sql b/libs/prisma-service/prisma/migrations/20230809131741_org_slug/migration.sql deleted file mode 100644 index ebc5f758a..000000000 --- a/libs/prisma-service/prisma/migrations/20230809131741_org_slug/migration.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `status` on the `organisation` table. All the data in the column will be lost. - - A unique constraint covering the columns `[orgSlug]` on the table `organisation` will be added. If there are existing duplicate values, this will fail. - -*/ --- AlterTable -ALTER TABLE "organisation" DROP COLUMN "status", -ADD COLUMN "orgSlug" TEXT; - --- CreateIndex -CREATE UNIQUE INDEX "organisation_orgSlug_key" ON "organisation"("orgSlug"); diff --git a/libs/prisma-service/prisma/migrations/20230811125950_add_public_profile_flag_org_user/migration.sql b/libs/prisma-service/prisma/migrations/20230811125950_add_public_profile_flag_org_user/migration.sql deleted file mode 100644 index 733c9568c..000000000 --- a/libs/prisma-service/prisma/migrations/20230811125950_add_public_profile_flag_org_user/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterTable -ALTER TABLE "organisation" ADD COLUMN "publicProfile" BOOLEAN NOT NULL DEFAULT false; - --- AlterTable -ALTER TABLE "user" ADD COLUMN "publicProfile" BOOLEAN NOT NULL DEFAULT false; diff --git a/libs/prisma-service/prisma/migrations/20230816113258_ledger_id_org_agents/migration.sql b/libs/prisma-service/prisma/migrations/20230816113258_ledger_id_org_agents/migration.sql deleted file mode 100644 index 476189aeb..000000000 --- a/libs/prisma-service/prisma/migrations/20230816113258_ledger_id_org_agents/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - Added the required column `ledgerId` to the `org_agents` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "org_agents" ADD COLUMN "ledgerId" INTEGER NOT NULL; - --- AddForeignKey -ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_ledgerId_fkey" FOREIGN KEY ("ledgerId") REFERENCES "ledgers"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/libs/prisma-service/prisma/migrations/0_init/migration.sql b/libs/prisma-service/prisma/migrations/20230822073057_init/migration.sql similarity index 90% rename from libs/prisma-service/prisma/migrations/0_init/migration.sql rename to libs/prisma-service/prisma/migrations/20230822073057_init/migration.sql index a231b6f80..de8f7ca3e 100644 --- a/libs/prisma-service/prisma/migrations/0_init/migration.sql +++ b/libs/prisma-service/prisma/migrations/20230822073057_init/migration.sql @@ -12,16 +12,33 @@ CREATE TABLE "user" ( "password" VARCHAR(500), "verificationCode" VARCHAR(500), "isEmailVerified" BOOLEAN NOT NULL DEFAULT false, - "keycloakUserId" VARCHAR(500), + "supabaseUserId" VARCHAR(500), "clientId" VARCHAR(500), "clientSecret" VARCHAR(500), "profileImg" VARCHAR(1000), "fidoUserId" VARCHAR(1000), "isFidoVerified" BOOLEAN NOT NULL DEFAULT false, + "publicProfile" BOOLEAN NOT NULL DEFAULT false, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") ); +-- CreateTable +CREATE TABLE "user_activity" ( + "id" SERIAL NOT NULL, + "userId" INTEGER NOT NULL, + "orgId" INTEGER NOT NULL, + "action" TEXT NOT NULL, + "details" TEXT NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "deletedAt" TIMESTAMP(6), + + CONSTRAINT "user_activity_pkey" PRIMARY KEY ("id") +); + -- CreateTable CREATE TABLE "org_roles" ( "id" SERIAL NOT NULL, @@ -55,8 +72,10 @@ CREATE TABLE "organisation" ( "lastChangedBy" INTEGER NOT NULL DEFAULT 1, "name" VARCHAR(500), "description" VARCHAR(500), + "orgSlug" TEXT, "logoUrl" TEXT, "website" VARCHAR, + "publicProfile" BOOLEAN NOT NULL DEFAULT false, CONSTRAINT "organisation_pkey" PRIMARY KEY ("id") ); @@ -133,7 +152,8 @@ CREATE TABLE "org_agents" ( "apiKey" TEXT, "agentsTypeId" INTEGER NOT NULL, "orgId" INTEGER NOT NULL, - "orgAgentTypeId" INTEGER NOT NULL + "orgAgentTypeId" INTEGER NOT NULL, + "ledgerId" INTEGER NOT NULL ); -- CreateTable @@ -299,6 +319,9 @@ CREATE UNIQUE INDEX "UQ_e12875dfb3b1d92d7d7c5377e22" ON "user"("email"); -- CreateIndex CREATE UNIQUE INDEX "org_roles_name_key" ON "org_roles"("name"); +-- CreateIndex +CREATE UNIQUE INDEX "organisation_orgSlug_key" ON "organisation"("orgSlug"); + -- CreateIndex CREATE UNIQUE INDEX "UQ_7c903f5e362fe8fd3d3edba17b5" ON "user_devices"("credentialId"); @@ -326,6 +349,12 @@ CREATE UNIQUE INDEX "presentations_id_key" ON "presentations"("id"); -- CreateIndex CREATE UNIQUE INDEX "presentations_connectionId_key" ON "presentations"("connectionId"); +-- AddForeignKey +ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE "user_org_roles" ADD CONSTRAINT "user_org_roles_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE; @@ -344,6 +373,9 @@ ALTER TABLE "org_invitations" ADD CONSTRAINT "org_invitations_orgId_fkey" FOREIG -- AddForeignKey ALTER TABLE "user_devices" ADD CONSTRAINT "FK_e12ac4f8016243ac71fd2e415af" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION; +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_ledgerId_fkey" FOREIGN KEY ("ledgerId") REFERENCES "ledgers"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_agentsTypeId_fkey" FOREIGN KEY ("agentsTypeId") REFERENCES "agents_type"("id") ON DELETE RESTRICT ON UPDATE CASCADE; @@ -370,4 +402,3 @@ ALTER TABLE "credentials" ADD CONSTRAINT "credentials_orgId_fkey" FOREIGN KEY (" -- AddForeignKey ALTER TABLE "presentations" ADD CONSTRAINT "presentations_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - diff --git a/libs/prisma-service/prisma/schema.prisma b/libs/prisma-service/prisma/schema.prisma index e68468b18..ed29b96e6 100644 --- a/libs/prisma-service/prisma/schema.prisma +++ b/libs/prisma-service/prisma/schema.prisma @@ -20,7 +20,7 @@ model user { password String? @db.VarChar(500) verificationCode String? @db.VarChar(500) isEmailVerified Boolean @default(false) - keycloakUserId String? @db.VarChar(500) + supabaseUserId String? @db.VarChar(500) clientId String? @db.VarChar(500) clientSecret String? @db.VarChar(500) profileImg String? @db.VarChar(1000) diff --git a/libs/supabase/src/index.ts b/libs/supabase/src/index.ts new file mode 100644 index 000000000..1b4bbcdf4 --- /dev/null +++ b/libs/supabase/src/index.ts @@ -0,0 +1,2 @@ +export * from './supabase.module'; +export * from './supabase.service'; diff --git a/libs/supabase/src/supabase.module.ts b/libs/supabase/src/supabase.module.ts new file mode 100644 index 000000000..1cd0a3c77 --- /dev/null +++ b/libs/supabase/src/supabase.module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common'; +import { SupabaseService } from './supabase.service'; + +@Module({ + providers: [SupabaseService], + exports: [SupabaseService] +}) +export class SupabaseModule {} diff --git a/libs/supabase/src/supabase.service.ts b/libs/supabase/src/supabase.service.ts new file mode 100644 index 000000000..05ddc2964 --- /dev/null +++ b/libs/supabase/src/supabase.service.ts @@ -0,0 +1,48 @@ +import { Inject, Injectable, Logger, Scope } from '@nestjs/common'; +import { SupabaseClient, createClient } from '@supabase/supabase-js'; +import { Request } from 'express'; +import { REQUEST } from '@nestjs/core'; + +@Injectable({ scope: Scope.REQUEST }) +export class SupabaseService { + + private readonly logger = new Logger(SupabaseService.name); + private clientInstance: SupabaseClient; + constructor( + @Inject(REQUEST) private readonly request: Request + ) { } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + getClient(): SupabaseClient { + this.logger.log('getting supabase client...'); + + if (this.clientInstance) { + this.logger.log('client exists - returning for current Scope.REQUEST'); + return this.clientInstance; + } + + this.logger.log('initialising new supabase client for new Scope.REQUEST'); + + this.clientInstance = createClient( + + process.env.SUPABASE_URL, + process.env.SUPABASE_KEY + // { + // auth: { + // persistSession: false + // }, + // global: { + // headers: { + // Authorization: `Bearer ${ExtractJwt.fromAuthHeaderAsBearerToken()( + // this.request + // )}` + // } + // } + // } + ); + + this.logger.log('auth has been set!'); + + return this.clientInstance; + } +} diff --git a/libs/supabase/tsconfig.lib.json b/libs/supabase/tsconfig.lib.json new file mode 100644 index 000000000..fdd77eefc --- /dev/null +++ b/libs/supabase/tsconfig.lib.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "../../dist/libs/supabase" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/nest-cli.json b/nest-cli.json index e40641492..68dc6c90e 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -223,6 +223,15 @@ "compilerOptions": { "tsConfigPath": "libs/user-activity/tsconfig.lib.json" } + }, + "supabase": { + "type": "library", + "root": "libs/supabase", + "entryFile": "index", + "sourceRoot": "libs/supabase/src", + "compilerOptions": { + "tsConfigPath": "libs/supabase/tsconfig.lib.json" + } } } } \ No newline at end of file diff --git a/package.json b/package.json index bab2d9934..aa863013e 100755 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@nestjs/websockets": "^10.1.3", "@prisma/client": "^5.1.1", "@sendgrid/mail": "^7.7.0", + "@supabase/supabase-js": "^2.32.0", "@types/async-retry": "^1.4.5", "@types/crypto-js": "^4.1.1", "@types/pdfkit": "^0.12.6", @@ -69,6 +70,7 @@ "moment": "^2.29.3", "nanoid": "^4.0.2", "nats": "^2.15.1", + "nestjs-supabase-auth": "^1.0.9", "nestjs-typeorm-paginate": "^4.0.4", "node-qpdf2": "^2.0.0", "papaparse": "^5.4.1", @@ -164,7 +166,8 @@ "^@credebl/prisma-service(|/.*)$": "/libs/prisma-service/src/$1", "^@credebl/org-roles(|/.*)$": "/libs/org-roles/src/$1", "^@credebl/user-org-roles(|/.*)$": "/libs/user-org-roles/src/$1", - "^y/user-activity(|/.*)$": "/libs/user-activity/src/$1" + "^y/user-activity(|/.*)$": "/libs/user-activity/src/$1", + "^@app/supabase(|/.*)$": "/libs/supabase/src/$1" } } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85f431b89..67c45af41 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,12 +53,21 @@ dependencies: '@sendgrid/mail': specifier: ^7.7.0 version: 7.7.0 + '@supabase/supabase-js': + specifier: ^2.32.0 + version: 2.32.0 + '@types/async-retry': + specifier: ^1.4.5 + version: 1.4.5 '@types/crypto-js': specifier: ^4.1.1 version: 4.1.1 '@types/pdfkit': specifier: ^0.12.6 version: 0.12.6 + async-retry: + specifier: ^1.3.3 + version: 1.3.3 auth0-js: specifier: ^9.22.1 version: 9.22.1 @@ -128,6 +137,9 @@ dependencies: nats: specifier: ^2.15.1 version: 2.15.1 + nestjs-supabase-auth: + specifier: ^1.0.9 + version: 1.0.9 nestjs-typeorm-paginate: specifier: ^4.0.4 version: 4.0.4(@nestjs/common@10.1.3)(typeorm@0.3.10) @@ -1625,6 +1637,62 @@ packages: resolution: {integrity: sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==} dev: false + /@supabase/functions-js@2.1.2: + resolution: {integrity: sha512-QCR6pwJs9exCl37bmpMisUd6mf+0SUBJ6mUpiAjEkSJ/+xW8TCuO14bvkWHADd5hElJK9MxNlMQXxSA4DRz9nQ==} + dependencies: + cross-fetch: 3.1.8 + transitivePeerDependencies: + - encoding + dev: false + + /@supabase/gotrue-js@2.47.0: + resolution: {integrity: sha512-3e34/vsKH/DoSZCpB85UZpFWSJ2p4GRUUlqgAgeTPagPlx4xS+Nc5v7g7ic7vp3gK0J5PsYVCn9Qu2JQUp4vXg==} + dependencies: + cross-fetch: 3.1.8 + transitivePeerDependencies: + - encoding + dev: false + + /@supabase/postgrest-js@1.8.0: + resolution: {integrity: sha512-R6leDIC92NgjyG2/tCRJ42rWN7+fZY6ulTEE+c00tcnghn6cX4IYUlnTNMtrdfYC2JYNOTyM+rWj63Wdhr7Zig==} + dependencies: + cross-fetch: 3.1.8 + transitivePeerDependencies: + - encoding + dev: false + + /@supabase/realtime-js@2.7.3: + resolution: {integrity: sha512-c7TzL81sx2kqyxsxcDduJcHL9KJdCOoKimGP6lQSqiZKX42ATlBZpWbyy9KFGFBjAP4nyopMf5JhPi2ZH9jyNw==} + dependencies: + '@types/phoenix': 1.6.0 + '@types/websocket': 1.0.5 + websocket: 1.0.34 + transitivePeerDependencies: + - supports-color + dev: false + + /@supabase/storage-js@2.5.1: + resolution: {integrity: sha512-nkR0fQA9ScAtIKA3vNoPEqbZv1k5B5HVRYEvRWdlP6mUpFphM9TwPL2jZ/ztNGMTG5xT6SrHr+H7Ykz8qzbhjw==} + dependencies: + cross-fetch: 3.1.8 + transitivePeerDependencies: + - encoding + dev: false + + /@supabase/supabase-js@2.32.0: + resolution: {integrity: sha512-1ShFhuOI5Du7604nlCelBsRD61daXk2O0qwjumoz35bqrYThnSPPtpJqZOHw6Mg6o7mLjIInYLh/DBlh8UvzRg==} + dependencies: + '@supabase/functions-js': 2.1.2 + '@supabase/gotrue-js': 2.47.0 + '@supabase/postgrest-js': 1.8.0 + '@supabase/realtime-js': 2.7.3 + '@supabase/storage-js': 2.5.1 + cross-fetch: 3.1.8 + transitivePeerDependencies: + - encoding + - supports-color + dev: false + /@swc/helpers@0.3.17: resolution: {integrity: sha512-tb7Iu+oZ+zWJZ3HJqwx8oNwSDIU440hmVMDPhpACWQWnrZHK99Bxs70gT1L2dnr5Hg50ZRWEFkQCAnOVVV0z1Q==} dependencies: @@ -1643,6 +1711,12 @@ packages: /@tsconfig/node16@1.0.4: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} + /@types/async-retry@1.4.5: + resolution: {integrity: sha512-YrdjSD+yQv7h6d5Ip+PMxh3H6ZxKyQk0Ts+PvaNRInxneG9PFVZjFg77ILAN+N6qYf7g4giSJ1l+ZjQ1zeegvA==} + dependencies: + '@types/retry': 0.12.2 + dev: false + /@types/babel__core@7.20.1: resolution: {integrity: sha512-aACu/U/omhdk15O4Nfb+fHgH/z3QsfQzpnvRZhYhThms83ZnAOZz7zZAWO7mn2yyNQaA4xTO8GLK3uqFU4bYYw==} dependencies: @@ -1832,12 +1906,20 @@ packages: '@types/node': 20.4.6 dev: false + /@types/phoenix@1.6.0: + resolution: {integrity: sha512-qwfpsHmFuhAS/dVd4uBIraMxRd56vwBUYQGZ6GpXnFuM2XMRFJbIyruFKKlW2daQliuYZwe0qfn/UjFCDKic5g==} + dev: false + /@types/qs@6.9.7: resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==} /@types/range-parser@1.2.4: resolution: {integrity: sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==} + /@types/retry@0.12.2: + resolution: {integrity: sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==} + dev: false + /@types/semver@7.5.0: resolution: {integrity: sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==} dev: true @@ -1875,6 +1957,12 @@ packages: /@types/validator@13.9.0: resolution: {integrity: sha512-NclP0IbzHj/4tJZKFqKh8E7kZdgss+MCUYV9G+TLltFfDA4lFgE4PKPpDIyS2FlcdANIfSx273emkupvChigbw==} + /@types/websocket@1.0.5: + resolution: {integrity: sha512-NbsqiNX9CnEfC1Z0Vf4mE1SgAJ07JnRYcNex7AJ9zAVzmiGHmjKFEk7O4TJIsgv2B1sLEb6owKFZrACwdYngsQ==} + dependencies: + '@types/node': 20.4.6 + dev: false + /@types/yargs-parser@21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} dev: true @@ -2483,6 +2571,12 @@ packages: engines: {node: '>=8'} dev: true + /async-retry@1.3.3: + resolution: {integrity: sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==} + dependencies: + retry: 0.13.1 + dev: false + /asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} @@ -2814,6 +2908,14 @@ packages: engines: {node: '>=0.2.0'} dev: false + /bufferutil@4.0.7: + resolution: {integrity: sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw==} + engines: {node: '>=6.14.2'} + requiresBuild: true + dependencies: + node-gyp-build: 4.6.0 + dev: false + /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -3239,6 +3341,14 @@ packages: luxon: 3.3.0 dev: false + /cross-fetch@3.1.8: + resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==} + dependencies: + node-fetch: 2.6.12 + transitivePeerDependencies: + - encoding + dev: false + /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -3259,6 +3369,13 @@ packages: type-fest: 2.19.0 dev: false + /d@1.0.1: + resolution: {integrity: sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==} + dependencies: + es5-ext: 0.10.62 + type: 1.2.0 + dev: false + /dashdash@1.14.1: resolution: {integrity: sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==} engines: {node: '>=0.10'} @@ -3662,10 +3779,35 @@ packages: is-symbol: 1.0.4 dev: true + /es5-ext@0.10.62: + resolution: {integrity: sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==} + engines: {node: '>=0.10'} + requiresBuild: true + dependencies: + es6-iterator: 2.0.3 + es6-symbol: 3.1.3 + next-tick: 1.1.0 + dev: false + + /es6-iterator@2.0.3: + resolution: {integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==} + dependencies: + d: 1.0.1 + es5-ext: 0.10.62 + es6-symbol: 3.1.3 + dev: false + /es6-promise@4.2.8: resolution: {integrity: sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==} dev: false + /es6-symbol@3.1.3: + resolution: {integrity: sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==} + dependencies: + d: 1.0.1 + ext: 1.7.0 + dev: false + /escalade@3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -4110,6 +4252,12 @@ packages: transitivePeerDependencies: - supports-color + /ext@1.7.0: + resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==} + dependencies: + type: 2.7.2 + dev: false + /extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} requiresBuild: true @@ -5047,7 +5195,6 @@ packages: resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==} requiresBuild: true dev: false - optional: true /is-unicode-supported@0.1.0: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} @@ -6201,6 +6348,10 @@ packages: resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==} dev: true + /nestjs-supabase-auth@1.0.9: + resolution: {integrity: sha512-1Aar5K2WuGggPV8q/xzJCIeAQz5wkPcvKGLPTUXwt1he1EKLg+OdWK2C0T7LzTgO4uX2WLakNWZBsUTZEOvt4Q==} + dev: false + /nestjs-typeorm-paginate@4.0.4(@nestjs/common@10.1.3)(typeorm@0.3.10): resolution: {integrity: sha512-arinWDc78wPV/EYWMmLYyeMSE5Lae1FHWD/2QpOdTmHaOVqK4PYf19EqZBqT9gbbPugkNW9JAMz3G2WmvSgR/A==} peerDependencies: @@ -6211,6 +6362,10 @@ packages: typeorm: 0.3.10(pg@8.11.2)(ts-node@10.9.1) dev: false + /next-tick@1.1.0: + resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} + dev: false + /nkeys.js@1.0.5: resolution: {integrity: sha512-u25YnRPHiGVsNzwyHnn+PT90sgAhnS8jUJ1nxmkHMFYCJ6+Ic0lv291w7uhRBpJVJ3PH2GWbYqA151lGCRrB5g==} engines: {node: '>=10.0.0'} @@ -6249,6 +6404,11 @@ packages: dev: false optional: true + /node-gyp-build@4.6.0: + resolution: {integrity: sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==} + hasBin: true + dev: false + /node-int64@0.4.0: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} dev: true @@ -7134,6 +7294,11 @@ packages: resolution: {integrity: sha512-e0dOpjm5DseomnXx2M5lpdZ5zoHqF1+bqdMJUohoYVVQa7cBdnk7fdmeI6byNWP/kiME72EeTiSypTCVnpLiDg==} dev: false + /retry@0.13.1: + resolution: {integrity: sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==} + engines: {node: '>= 4'} + dev: false + /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -8032,6 +8197,14 @@ packages: media-typer: 0.3.0 mime-types: 2.1.35 + /type@1.2.0: + resolution: {integrity: sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==} + dev: false + + /type@2.7.2: + resolution: {integrity: sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==} + dev: false + /typed-array-buffer@1.0.0: resolution: {integrity: sha512-Y8KTSIglk9OZEr8zywiIHG/kmQ7KWyjseXs1CbSo8vC42w7hg2HgYTxSWwP0+is7bWDc1H+Fo026CpHFwm8tkw==} engines: {node: '>= 0.4'} @@ -8070,6 +8243,12 @@ packages: is-typed-array: 1.1.12 dev: true + /typedarray-to-buffer@3.1.5: + resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==} + dependencies: + is-typedarray: 1.0.0 + dev: false + /typedarray@0.0.6: resolution: {integrity: sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==} @@ -8240,6 +8419,14 @@ packages: resolution: {integrity: sha512-RtuPeMy7c1UrHwproMZN9gN6kiZ0SvJwRaEzwZY0j9MypEkFqyBaKv176jvlPtg58Zh36bOkS0NFABXMHvvGCA==} dev: false + /utf-8-validate@5.0.10: + resolution: {integrity: sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==} + engines: {node: '>=6.14.2'} + requiresBuild: true + dependencies: + node-gyp-build: 4.6.0 + dev: false + /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} @@ -8429,6 +8616,20 @@ packages: - uglify-js dev: true + /websocket@1.0.34: + resolution: {integrity: sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==} + engines: {node: '>=4.0.0'} + dependencies: + bufferutil: 4.0.7 + debug: 2.6.9 + es5-ext: 0.10.62 + typedarray-to-buffer: 3.1.5 + utf-8-validate: 5.0.10 + yaeti: 0.0.6 + transitivePeerDependencies: + - supports-color + dev: false + /whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} dependencies: @@ -8577,6 +8778,11 @@ packages: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} + /yaeti@0.0.6: + resolution: {integrity: sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==} + engines: {node: '>=0.10.32'} + dev: false + /yallist@2.1.2: resolution: {integrity: sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==} dev: false diff --git a/tsconfig.json b/tsconfig.json index 3e71568cb..afa54f6bf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -94,6 +94,12 @@ ], "@credebl/user-activity/*": [ "libs/user-activity/src/*" + ], + "@credebl/supabase": [ + "libs/supabase/src" + ], + "@credebl/supabase/*": [ + "libs/supabase/src/*" ] } }, From ec05a89c74928bb9f4041603a04a23e18d7a72e5 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Thu, 24 Aug 2023 20:12:41 +0530 Subject: [PATCH 2/3] chnages in the prisma seed Signed-off-by: @nishad.shirsat --- apps/user/src/user.service.ts | 3 +-- .../{20230822073057_init => 20230824100446_init}/migration.sql | 0 libs/prisma-service/prisma/seed.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) rename libs/prisma-service/prisma/migrations/{20230822073057_init => 20230824100446_init}/migration.sql (100%) diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index 8e146abb5..86bdc9aca 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -185,7 +185,6 @@ export class UserService { throw new InternalServerErrorException(supaUser.error?.message); } - const supaId = supaUser.data?.user?.id; await this.userRepository.updateUserDetails( @@ -325,7 +324,7 @@ export class UserService { password }); - this.logger.error(`Supa Login Error::`, error); + this.logger.error(`Supa Login Error::`, JSON.stringify(error)); if (error) { throw new BadRequestException(error?.message); diff --git a/libs/prisma-service/prisma/migrations/20230822073057_init/migration.sql b/libs/prisma-service/prisma/migrations/20230824100446_init/migration.sql similarity index 100% rename from libs/prisma-service/prisma/migrations/20230822073057_init/migration.sql rename to libs/prisma-service/prisma/migrations/20230824100446_init/migration.sql diff --git a/libs/prisma-service/prisma/seed.ts b/libs/prisma-service/prisma/seed.ts index 0d5d75a20..8b6b6fb51 100644 --- a/libs/prisma-service/prisma/seed.ts +++ b/libs/prisma-service/prisma/seed.ts @@ -103,7 +103,7 @@ const createPlatformUserOrgRoles = async (): Promise => { const createLedger = async (): Promise => { try { const { ledgerData } = JSON.parse(configData); - const createLedger = await prisma.ledgers.create({ + const createLedger = await prisma.ledgers.createMany({ data: ledgerData }); From 3aef716dcbc1e65d61259fc0b3f58a5072e9adb6 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Fri, 25 Aug 2023 15:56:22 +0530 Subject: [PATCH 3/3] removed bycrypt import from user repository Signed-off-by: @nishad.shirsat --- .../user/repositories/fido-user.repository.ts | 3 - apps/user/repositories/user.repository.ts | 10 +- apps/user/src/user.service.ts | 113 +---- .../20230825075815_init/migration.sql | 403 ++++++++++++++++++ .../prisma/migrations/migration_lock.toml | 3 + libs/prisma-service/prisma/schema.prisma | 1 - libs/supabase/src/supabase.service.ts | 17 +- 7 files changed, 426 insertions(+), 124 deletions(-) create mode 100644 libs/prisma-service/prisma/migrations/20230825075815_init/migration.sql create mode 100644 libs/prisma-service/prisma/migrations/migration_lock.toml diff --git a/apps/user/repositories/fido-user.repository.ts b/apps/user/repositories/fido-user.repository.ts index 8c82d8b6a..812b4ba73 100644 --- a/apps/user/repositories/fido-user.repository.ts +++ b/apps/user/repositories/fido-user.repository.ts @@ -1,5 +1,3 @@ -import * as bcrypt from 'bcrypt'; - import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { CreateUserDto } from '../dtos/create-user.dto'; import { InternalServerErrorException } from '@nestjs/common'; @@ -34,7 +32,6 @@ export class FidoUserRepository { email: createUserDto.email, firstName: createUserDto.firstName, lastName: createUserDto.lastName, - password: await bcrypt.hash(createUserDto.password, 10), verificationCode: verifyCode } }); diff --git a/apps/user/repositories/user.repository.ts b/apps/user/repositories/user.repository.ts index 69c63ce35..860e4a784 100644 --- a/apps/user/repositories/user.repository.ts +++ b/apps/user/repositories/user.repository.ts @@ -1,7 +1,5 @@ /* eslint-disable prefer-destructuring */ -import * as bcrypt from 'bcrypt'; - import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { UpdateUserProfile, UserEmailVerificationDto, UserI, userInfo } from '../interfaces/user.interface'; @@ -147,7 +145,6 @@ export class UserRepository { select: { id: true, username: true, - password: false, email: true, firstName: true, lastName: true, @@ -197,7 +194,6 @@ export class UserRepository { select: { id: true, username: true, - password: false, email: true, firstName: true, lastName: true, @@ -243,7 +239,6 @@ export class UserRepository { select: { id: true, username: true, - password: false, email: true, firstName: true, lastName: true, @@ -308,8 +303,7 @@ export class UserRepository { }, data: { firstName: userInfo.firstName, - lastName: userInfo.lastName, - password: await bcrypt.hash(userInfo.password, 10) + lastName: userInfo.lastName } }); return updateUserDetails; @@ -335,7 +329,6 @@ export class UserRepository { select: { id: true, username: true, - password: false, email: true, firstName: true, lastName: true, @@ -401,7 +394,6 @@ export class UserRepository { select: { id: true, username: true, - password: false, email: true, firstName: true, lastName: true, diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index 6b34a5b25..b9e42fcd4 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -1,8 +1,6 @@ -import * as bcrypt from 'bcrypt'; import { BadRequestException, - // BadRequestException, ConflictException, Injectable, Logger, @@ -176,18 +174,18 @@ export class UserService { if (!userDetails) { throw new NotFoundException(ResponseMessages.user.error.adduser); } - const supaUser = await this.supabaseService.getClient().auth.signUp({ - email, - password: userInfo.password - }); + const supaUser = await this.supabaseService.getClient().auth.signUp({ + email, + password: userInfo.password + }); - if (supaUser.error) { - throw new InternalServerErrorException(supaUser.error?.message); - } + if (supaUser.error) { + throw new InternalServerErrorException(supaUser.error?.message); + } - const supaId = supaUser.data?.user?.id; + const supaId = supaUser.data?.user?.id; - await this.userRepository.updateUserDetails( + await this.userRepository.updateUserDetails( userDetails.id, supaId.toString() ); @@ -202,74 +200,6 @@ export class UserService { } } - /** - * - * @param userName - * @param clientToken - * @returns Keycloak client details - */ - async keycloakClienGenerate(userName: string, clientToken: string): Promise<{ clientId; clientSecret }> { - try { - const userClient = await this.clientRegistrationService.createClient(userName, clientToken); - - return userClient; - } catch (error) { - this.logger.error(`error in keycloakClienGenerate: ${JSON.stringify(error)}`); - throw error; - } - } - - /** - * - * @param keycloakUserRegestrationDto - * @returns Email verification succcess - */ - - async keycloakUserRegistration(userDetails: user, clientToken: string): Promise { - const keycloakRegistrationPayload = { - email: userDetails.email, - firstName: userDetails.firstName, - lastName: userDetails.lastName, - username: userDetails.username, - enabled: true, - totp: true, - emailVerified: true, - notBefore: 0, - credentials: [ - { - type: 'password', - value: `${userDetails.password}`, - temporary: false - } - ], - access: { - manageGroupMembership: true, - view: true, - mapRoles: true, - impersonate: true, - manage: true - }, - realmRoles: ['user', 'offline_access'], - attributes: { - uid: [], - homedir: [], - shell: [] - } - }; - - try { - const createUserResponse = await this.clientRegistrationService.registerKeycloakUser( - keycloakRegistrationPayload, - process.env.KEYCLOAK_CREDEBL_REALM, - clientToken - ); - - return createUserResponse?.keycloakUserId; - } catch (error) { - this.logger.error(`error in keycloakUserRegistration: ${JSON.stringify(error)}`); - throw error; - } - } /** * @@ -300,13 +230,6 @@ export class UserService { } - const comparePassword = await bcrypt.compare(password, userData.password); - - if (!comparePassword) { - this.logger.error(`Password Is wrong`); - throw new BadRequestException(ResponseMessages.user.error.invalidCredentials); - } - return this.generateToken(email, password); } catch (error) { this.logger.error(`In Login User : ${JSON.stringify(error)}`); @@ -348,7 +271,7 @@ export class UserService { async getPublicProfile(payload: { id }): Promise { try { const userProfile = await this.userRepository.getUserPublicProfile(payload.id); - + if (!userProfile) { throw new NotFoundException(ResponseMessages.user.error.profileNotFound); } @@ -549,12 +472,12 @@ export class UserService { } } - /** - * - * @param orgId - * @returns users list - */ - async get(pageNumber: number, pageSize: number, search: string): Promise { + /** + * + * @param orgId + * @returns users list + */ + async get(pageNumber: number, pageSize: number, search: string): Promise { try { const query = { OR: [ @@ -585,7 +508,7 @@ export class UserService { const userVerificationDetails = { isEmailVerified: userDetails.isEmailVerified, isFidoVerified: userDetails.isFidoVerified, - isKeycloak: null !== userDetails.supabaseUserId && undefined !== userDetails.supabaseUserId + isSupabase: null !== userDetails.supabaseUserId && undefined !== userDetails.supabaseUserId }; return userVerificationDetails; } @@ -600,7 +523,7 @@ export class UserService { async getUserActivity(userId: number, limit: number): Promise { try { - return this.userActivityService.getUserActivity(userId, limit); + return this.userActivityService.getUserActivity(userId, limit); } catch (error) { this.logger.error(`In getUserActivity : ${JSON.stringify(error)}`); diff --git a/libs/prisma-service/prisma/migrations/20230825075815_init/migration.sql b/libs/prisma-service/prisma/migrations/20230825075815_init/migration.sql new file mode 100644 index 000000000..d27203ae5 --- /dev/null +++ b/libs/prisma-service/prisma/migrations/20230825075815_init/migration.sql @@ -0,0 +1,403 @@ +-- CreateTable +CREATE TABLE "user" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "firstName" VARCHAR(500), + "lastName" VARCHAR(500), + "email" VARCHAR(500), + "username" VARCHAR(500), + "verificationCode" VARCHAR(500), + "isEmailVerified" BOOLEAN NOT NULL DEFAULT false, + "supabaseUserId" VARCHAR(500), + "clientId" VARCHAR(500), + "clientSecret" VARCHAR(500), + "profileImg" TEXT, + "fidoUserId" VARCHAR(1000), + "isFidoVerified" BOOLEAN NOT NULL DEFAULT false, + "publicProfile" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "user_activity" ( + "id" SERIAL NOT NULL, + "userId" INTEGER NOT NULL, + "orgId" INTEGER NOT NULL, + "action" TEXT NOT NULL, + "details" TEXT NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "deletedAt" TIMESTAMP(6), + + CONSTRAINT "user_activity_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "org_roles" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "deletedAt" TIMESTAMP(6), + + CONSTRAINT "org_roles_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "user_org_roles" ( + "id" SERIAL NOT NULL, + "userId" INTEGER NOT NULL, + "orgRoleId" INTEGER NOT NULL, + "orgId" INTEGER, + + CONSTRAINT "user_org_roles_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "organisation" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "name" VARCHAR(500), + "description" VARCHAR(500), + "orgSlug" TEXT, + "logoUrl" TEXT, + "website" VARCHAR, + "publicProfile" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "organisation_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "org_invitations" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "deletedAt" TIMESTAMP(6), + "userId" INTEGER NOT NULL, + "orgId" INTEGER NOT NULL, + "status" TEXT NOT NULL, + "orgRoles" INTEGER[], + "email" TEXT, + + CONSTRAINT "org_invitations_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "user_devices" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "devices" JSONB DEFAULT '[]', + "credentialId" VARCHAR, + "deviceFriendlyName" VARCHAR, + "userId" INTEGER, + "deletedAt" TIMESTAMP(6), + "authCounter" INTEGER NOT NULL DEFAULT 0, + + CONSTRAINT "PK_c9e7e648903a9e537347aba4371" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "platform_config" ( + "id" SERIAL NOT NULL, + "externalIp" VARCHAR NOT NULL, + "lastInternalId" VARCHAR NOT NULL, + "username" VARCHAR NOT NULL, + "sgApiKey" VARCHAR NOT NULL, + "emailFrom" VARCHAR NOT NULL, + "apiEndpoint" VARCHAR NOT NULL, + "tailsFileServer" VARCHAR NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "deletedAt" TIMESTAMP(6), + + CONSTRAINT "platform_config_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "org_agents" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "orgDid" VARCHAR NOT NULL, + "verkey" VARCHAR NOT NULL, + "agentEndPoint" VARCHAR NOT NULL, + "agentId" INTEGER, + "isDidPublic" BOOLEAN NOT NULL, + "agentSpinUpStatus" INTEGER NOT NULL, + "agentOptions" BYTEA, + "walletName" VARCHAR, + "tenantId" TEXT, + "apiKey" TEXT, + "agentsTypeId" INTEGER NOT NULL, + "orgId" INTEGER NOT NULL, + "orgAgentTypeId" INTEGER NOT NULL, + "ledgerId" INTEGER +); + +-- CreateTable +CREATE TABLE "org_agents_type" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "agent" VARCHAR(500) NOT NULL, + + CONSTRAINT "org_agents_type_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "agents_type" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "agent" VARCHAR(500) NOT NULL, + + CONSTRAINT "agents_type_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "ledgers" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "name" VARCHAR NOT NULL, + "networkType" VARCHAR NOT NULL, + "poolConfig" VARCHAR NOT NULL, + "isActive" BOOLEAN NOT NULL, + "networkString" VARCHAR NOT NULL, + "registerDIDEndpoint" VARCHAR NOT NULL, + "registerDIDPayload" JSONB +); + +-- CreateTable +CREATE TABLE "agents" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "name" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "schema" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "name" VARCHAR NOT NULL, + "version" VARCHAR NOT NULL, + "attributes" TEXT NOT NULL, + "schemaLedgerId" VARCHAR NOT NULL, + "publisherDid" VARCHAR NOT NULL, + "ledgerId" INTEGER NOT NULL DEFAULT 1, + "issuerId" VARCHAR NOT NULL, + "orgId" INTEGER NOT NULL, + + CONSTRAINT "PK_c9e7e648903a9e537347aba4372" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "credential_definition" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "credentialDefinitionId" VARCHAR NOT NULL, + "tag" VARCHAR NOT NULL, + "schemaLedgerId" VARCHAR NOT NULL, + "schemaId" INTEGER NOT NULL DEFAULT 1, + "orgId" INTEGER NOT NULL DEFAULT 1, + "revocable" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "PK_c9e7e648903a9e537347aba4373" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "shortening_url" ( + "id" SERIAL NOT NULL, + "referenceId" VARCHAR(50), + "url" TEXT, + "type" TEXT, + + CONSTRAINT "shortening_url_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "agent_invitations" ( + "id" SERIAL NOT NULL, + "orgId" INTEGER NOT NULL DEFAULT 1, + "agentId" INTEGER NOT NULL DEFAULT 1, + "connectionInvitation" TEXT NOT NULL, + "multiUse" BOOLEAN NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1 +); + +-- CreateTable +CREATE TABLE "connections" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "connectionId" TEXT NOT NULL, + "state" TEXT NOT NULL, + "orgDid" TEXT NOT NULL, + "theirLabel" TEXT NOT NULL, + "autoAcceptConnection" BOOLEAN NOT NULL, + "outOfBandId" TEXT NOT NULL, + "orgId" INTEGER NOT NULL, + + CONSTRAINT "connections_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "credentials" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "connectionId" TEXT NOT NULL, + "threadId" TEXT NOT NULL, + "protocolVersion" TEXT NOT NULL, + "credentialAttributes" JSONB[], + "orgId" INTEGER NOT NULL, + + CONSTRAINT "credentials_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "presentations" ( + "id" SERIAL NOT NULL, + "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdBy" INTEGER NOT NULL DEFAULT 1, + "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastChangedBy" INTEGER NOT NULL DEFAULT 1, + "connectionId" TEXT NOT NULL, + "state" TEXT, + "threadId" TEXT, + "isVerified" BOOLEAN, + "orgId" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "UQ_e12875dfb3b1d92d7d7c5377e22" ON "user"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "org_roles_name_key" ON "org_roles"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "organisation_orgSlug_key" ON "organisation"("orgSlug"); + +-- CreateIndex +CREATE UNIQUE INDEX "UQ_7c903f5e362fe8fd3d3edba17b5" ON "user_devices"("credentialId"); + +-- CreateIndex +CREATE UNIQUE INDEX "org_agents_id_key" ON "org_agents"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "ledgers_id_key" ON "ledgers"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "agents_id_key" ON "agents"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "agent_invitations_id_key" ON "agent_invitations"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "connections_connectionId_key" ON "connections"("connectionId"); + +-- CreateIndex +CREATE UNIQUE INDEX "credentials_connectionId_key" ON "credentials"("connectionId"); + +-- CreateIndex +CREATE UNIQUE INDEX "presentations_id_key" ON "presentations"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "presentations_connectionId_key" ON "presentations"("connectionId"); + +-- AddForeignKey +ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_activity" ADD CONSTRAINT "user_activity_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_org_roles" ADD CONSTRAINT "user_org_roles_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_org_roles" ADD CONSTRAINT "user_org_roles_orgRoleId_fkey" FOREIGN KEY ("orgRoleId") REFERENCES "org_roles"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_org_roles" ADD CONSTRAINT "user_org_roles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_invitations" ADD CONSTRAINT "org_invitations_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_invitations" ADD CONSTRAINT "org_invitations_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "user_devices" ADD CONSTRAINT "FK_e12ac4f8016243ac71fd2e415af" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_ledgerId_fkey" FOREIGN KEY ("ledgerId") REFERENCES "ledgers"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_agentsTypeId_fkey" FOREIGN KEY ("agentsTypeId") REFERENCES "agents_type"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_orgAgentTypeId_fkey" FOREIGN KEY ("orgAgentTypeId") REFERENCES "org_agents_type"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "org_agents" ADD CONSTRAINT "org_agents_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "agents"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "schema" ADD CONSTRAINT "schema_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "agent_invitations" ADD CONSTRAINT "agent_invitations_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "org_agents"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "connections" ADD CONSTRAINT "connections_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "credentials" ADD CONSTRAINT "credentials_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "presentations" ADD CONSTRAINT "presentations_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/libs/prisma-service/prisma/migrations/migration_lock.toml b/libs/prisma-service/prisma/migrations/migration_lock.toml new file mode 100644 index 000000000..fbffa92c2 --- /dev/null +++ b/libs/prisma-service/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/libs/prisma-service/prisma/schema.prisma b/libs/prisma-service/prisma/schema.prisma index 372fd8d26..23fb8d161 100644 --- a/libs/prisma-service/prisma/schema.prisma +++ b/libs/prisma-service/prisma/schema.prisma @@ -17,7 +17,6 @@ model user { lastName String? @db.VarChar(500) email String? @unique(map: "UQ_e12875dfb3b1d92d7d7c5377e22") @db.VarChar(500) username String? @db.VarChar(500) - password String? @db.VarChar(500) verificationCode String? @db.VarChar(500) isEmailVerified Boolean @default(false) supabaseUserId String? @db.VarChar(500) diff --git a/libs/supabase/src/supabase.service.ts b/libs/supabase/src/supabase.service.ts index 05ddc2964..83acf5d6f 100644 --- a/libs/supabase/src/supabase.service.ts +++ b/libs/supabase/src/supabase.service.ts @@ -1,7 +1,5 @@ -import { Inject, Injectable, Logger, Scope } from '@nestjs/common'; +import { Injectable, Logger, Scope } from '@nestjs/common'; import { SupabaseClient, createClient } from '@supabase/supabase-js'; -import { Request } from 'express'; -import { REQUEST } from '@nestjs/core'; @Injectable({ scope: Scope.REQUEST }) export class SupabaseService { @@ -9,7 +7,6 @@ export class SupabaseService { private readonly logger = new Logger(SupabaseService.name); private clientInstance: SupabaseClient; constructor( - @Inject(REQUEST) private readonly request: Request ) { } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -27,18 +24,6 @@ export class SupabaseService { process.env.SUPABASE_URL, process.env.SUPABASE_KEY - // { - // auth: { - // persistSession: false - // }, - // global: { - // headers: { - // Authorization: `Bearer ${ExtractJwt.fromAuthHeaderAsBearerToken()( - // this.request - // )}` - // } - // } - // } ); this.logger.log('auth has been set!');