Compare commits
3 Commits
refactor/t
...
fix/duplic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
596ea7e364 | ||
|
|
2c7f5f6173 | ||
|
|
f19dc700ef |
@@ -31,7 +31,6 @@ MICROSOFT_CLIENT_ID="************************************************"
|
|||||||
MICROSOFT_CLIENT_SECRET="************************************************"
|
MICROSOFT_CLIENT_SECRET="************************************************"
|
||||||
MICROSOFT_CALLBACK_URL="http://localhost:3170/v1/auth/microsoft/callback"
|
MICROSOFT_CALLBACK_URL="http://localhost:3170/v1/auth/microsoft/callback"
|
||||||
MICROSOFT_SCOPE="user.read"
|
MICROSOFT_SCOPE="user.read"
|
||||||
MICROSOFT_TENANT="common"
|
|
||||||
|
|
||||||
# Mailer config
|
# Mailer config
|
||||||
MAILER_SMTP_URL="smtps://user@domain.com:pass@smtp.domain.com"
|
MAILER_SMTP_URL="smtps://user@domain.com:pass@smtp.domain.com"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hoppscotch-backend",
|
"name": "hoppscotch-backend",
|
||||||
"version": "2023.4.7",
|
"version": "2023.4.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export class AdminService {
|
|||||||
* @returns an array team invitations
|
* @returns an array team invitations
|
||||||
*/
|
*/
|
||||||
async pendingInvitationCountInTeam(teamID: string) {
|
async pendingInvitationCountInTeam(teamID: string) {
|
||||||
const invitations = await this.teamInvitationService.getTeamInvitations(
|
const invitations = await this.teamInvitationService.getAllTeamInvitations(
|
||||||
teamID,
|
teamID,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ export class AdminService {
|
|||||||
if (E.isRight(userInvitation)) {
|
if (E.isRight(userInvitation)) {
|
||||||
await this.teamInvitationService.revokeInvitation(
|
await this.teamInvitationService.revokeInvitation(
|
||||||
userInvitation.right.id,
|
userInvitation.right.id,
|
||||||
);
|
)();
|
||||||
}
|
}
|
||||||
|
|
||||||
return E.right(addedUser.right);
|
return E.right(addedUser.right);
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ export class AuthService {
|
|||||||
url = process.env.VITE_BASE_URL;
|
url = process.env.VITE_BASE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.mailerService.sendEmail(email, {
|
await this.mailerService.sendAuthEmail(email, {
|
||||||
template: 'code-your-own',
|
template: 'code-your-own',
|
||||||
variables: {
|
variables: {
|
||||||
inviteeEmail: email,
|
inviteeEmail: email,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
|
|||||||
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
||||||
callbackURL: process.env.MICROSOFT_CALLBACK_URL,
|
callbackURL: process.env.MICROSOFT_CALLBACK_URL,
|
||||||
scope: [process.env.MICROSOFT_SCOPE],
|
scope: [process.env.MICROSOFT_SCOPE],
|
||||||
tenant: process.env.MICROSOFT_TENANT,
|
passReqToCallback: true,
|
||||||
store: true,
|
store: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,13 +312,6 @@ export const SHORTCODE_ALREADY_EXISTS = 'shortcode/already_exists' as const;
|
|||||||
*/
|
*/
|
||||||
export const TEAM_ENVIRONMENT_NOT_FOUND = 'team_environment/not_found' as const;
|
export const TEAM_ENVIRONMENT_NOT_FOUND = 'team_environment/not_found' as const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalid TEAM ENVIRONMENT name
|
|
||||||
* (TeamEnvironmentsService)
|
|
||||||
*/
|
|
||||||
export const TEAM_ENVIRONMENT_SHORT_NAME =
|
|
||||||
'team_environment/short_name' as const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user is not a member of the team of the given environment
|
* The user is not a member of the team of the given environment
|
||||||
* (GqlTeamEnvTeamGuard)
|
* (GqlTeamEnvTeamGuard)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
UserMagicLinkMailDescription,
|
UserMagicLinkMailDescription,
|
||||||
} from './MailDescriptions';
|
} from './MailDescriptions';
|
||||||
import { throwErr } from 'src/utils';
|
import { throwErr } from 'src/utils';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import { EMAIL_FAILED } from 'src/errors';
|
import { EMAIL_FAILED } from 'src/errors';
|
||||||
import { MailerService as NestMailerService } from '@nestjs-modules/mailer';
|
import { MailerService as NestMailerService } from '@nestjs-modules/mailer';
|
||||||
|
|
||||||
@@ -34,14 +35,33 @@ export class MailerService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an email to the given email address given a mail description
|
* Sends an email to the given email address given a mail description
|
||||||
* @param to Receiver's email id
|
* @param to The email address to be sent to (NOTE: this is not validated)
|
||||||
* @param mailDesc Definition of what email to be sent
|
* @param mailDesc Definition of what email to be sent
|
||||||
* @returns Response if email was send successfully or not
|
|
||||||
*/
|
*/
|
||||||
async sendEmail(
|
sendMail(
|
||||||
to: string,
|
to: string,
|
||||||
mailDesc: MailDescription | UserMagicLinkMailDescription,
|
mailDesc: MailDescription | UserMagicLinkMailDescription,
|
||||||
) {
|
) {
|
||||||
|
return TE.tryCatch(
|
||||||
|
async () => {
|
||||||
|
await this.nestMailerService.sendMail({
|
||||||
|
to,
|
||||||
|
template: mailDesc.template,
|
||||||
|
subject: this.resolveSubjectForMailDesc(mailDesc),
|
||||||
|
context: mailDesc.variables,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => EMAIL_FAILED,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param to Receiver's email id
|
||||||
|
* @param mailDesc Details of email to be sent for Magic-Link auth
|
||||||
|
* @returns Response if email was send successfully or not
|
||||||
|
*/
|
||||||
|
async sendAuthEmail(to: string, mailDesc: UserMagicLinkMailDescription) {
|
||||||
try {
|
try {
|
||||||
await this.nestMailerService.sendMail({
|
await this.nestMailerService.sendMail({
|
||||||
to,
|
to,
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
|
import * as O from 'fp-ts/Option';
|
||||||
|
import * as S from 'fp-ts/string';
|
||||||
|
import { pipe } from 'fp-ts/function';
|
||||||
|
import {
|
||||||
|
getAnnotatedRequiredRoles,
|
||||||
|
getGqlArg,
|
||||||
|
getUserFromGQLContext,
|
||||||
|
throwErr,
|
||||||
|
} from 'src/utils';
|
||||||
import { TeamEnvironmentsService } from './team-environments.service';
|
import { TeamEnvironmentsService } from './team-environments.service';
|
||||||
import {
|
import {
|
||||||
BUG_AUTH_NO_USER_CTX,
|
BUG_AUTH_NO_USER_CTX,
|
||||||
@@ -9,10 +19,6 @@ import {
|
|||||||
TEAM_ENVIRONMENT_NOT_FOUND,
|
TEAM_ENVIRONMENT_NOT_FOUND,
|
||||||
} from 'src/errors';
|
} from 'src/errors';
|
||||||
import { TeamService } from 'src/team/team.service';
|
import { TeamService } from 'src/team/team.service';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
||||||
import * as E from 'fp-ts/Either';
|
|
||||||
import { TeamMemberRole } from '@prisma/client';
|
|
||||||
import { throwErr } from 'src/utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A guard which checks whether the caller of a GQL Operation
|
* A guard which checks whether the caller of a GQL Operation
|
||||||
@@ -27,31 +33,50 @@ export class GqlTeamEnvTeamGuard implements CanActivate {
|
|||||||
private readonly teamService: TeamService,
|
private readonly teamService: TeamService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
const requireRoles = this.reflector.get<TeamMemberRole[]>(
|
return pipe(
|
||||||
'requiresTeamRole',
|
TE.Do,
|
||||||
context.getHandler(),
|
|
||||||
);
|
|
||||||
if (!requireRoles) throw new Error(BUG_TEAM_ENV_GUARD_NO_REQUIRE_ROLES);
|
|
||||||
|
|
||||||
const gqlExecCtx = GqlExecutionContext.create(context);
|
TE.bindW('requiredRoles', () =>
|
||||||
|
pipe(
|
||||||
|
getAnnotatedRequiredRoles(this.reflector, context),
|
||||||
|
TE.fromOption(() => BUG_TEAM_ENV_GUARD_NO_REQUIRE_ROLES),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const { user } = gqlExecCtx.getContext().req;
|
TE.bindW('user', () =>
|
||||||
if (user == undefined) throw new Error(BUG_AUTH_NO_USER_CTX);
|
pipe(
|
||||||
|
getUserFromGQLContext(context),
|
||||||
|
TE.fromOption(() => BUG_AUTH_NO_USER_CTX),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const { id } = gqlExecCtx.getArgs<{ id: string }>();
|
TE.bindW('envID', () =>
|
||||||
if (!id) throwErr(BUG_TEAM_ENV_GUARD_NO_ENV_ID);
|
pipe(
|
||||||
|
getGqlArg('id', context),
|
||||||
|
O.fromPredicate(S.isString),
|
||||||
|
TE.fromOption(() => BUG_TEAM_ENV_GUARD_NO_ENV_ID),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const teamEnvironment =
|
TE.bindW('membership', ({ envID, user }) =>
|
||||||
await this.teamEnvironmentService.getTeamEnvironment(id);
|
pipe(
|
||||||
if (E.isLeft(teamEnvironment)) throwErr(TEAM_ENVIRONMENT_NOT_FOUND);
|
this.teamEnvironmentService.getTeamEnvironment(envID),
|
||||||
|
TE.fromTaskOption(() => TEAM_ENVIRONMENT_NOT_FOUND),
|
||||||
|
TE.chainW((env) =>
|
||||||
|
pipe(
|
||||||
|
this.teamService.getTeamMemberTE(env.teamID, user.uid),
|
||||||
|
TE.mapLeft(() => TEAM_ENVIRONMENT_NOT_TEAM_MEMBER),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const member = await this.teamService.getTeamMember(
|
TE.map(({ membership, requiredRoles }) =>
|
||||||
teamEnvironment.right.teamID,
|
requiredRoles.includes(membership.role),
|
||||||
user.uid,
|
),
|
||||||
);
|
|
||||||
if (!member) throwErr(TEAM_ENVIRONMENT_NOT_TEAM_MEMBER);
|
|
||||||
|
|
||||||
return requireRoles.includes(member.role);
|
TE.getOrElse(throwErr),
|
||||||
|
)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import { ArgsType, Field, ID } from '@nestjs/graphql';
|
|
||||||
|
|
||||||
@ArgsType()
|
|
||||||
export class CreateTeamEnvironmentArgs {
|
|
||||||
@Field({
|
|
||||||
name: 'name',
|
|
||||||
description: 'Name of the Team Environment',
|
|
||||||
})
|
|
||||||
name: string;
|
|
||||||
|
|
||||||
@Field(() => ID, {
|
|
||||||
name: 'teamID',
|
|
||||||
description: 'ID of the Team',
|
|
||||||
})
|
|
||||||
teamID: string;
|
|
||||||
|
|
||||||
@Field({
|
|
||||||
name: 'variables',
|
|
||||||
description: 'JSON string of the variables object',
|
|
||||||
})
|
|
||||||
variables: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ArgsType()
|
|
||||||
export class UpdateTeamEnvironmentArgs {
|
|
||||||
@Field(() => ID, {
|
|
||||||
name: 'id',
|
|
||||||
description: 'ID of the Team Environment',
|
|
||||||
})
|
|
||||||
id: string;
|
|
||||||
@Field({
|
|
||||||
name: 'name',
|
|
||||||
description: 'Name of the Team Environment',
|
|
||||||
})
|
|
||||||
name: string;
|
|
||||||
@Field({
|
|
||||||
name: 'variables',
|
|
||||||
description: 'JSON string of the variables object',
|
|
||||||
})
|
|
||||||
variables: string;
|
|
||||||
}
|
|
||||||
@@ -13,11 +13,6 @@ import { throwErr } from 'src/utils';
|
|||||||
import { GqlTeamEnvTeamGuard } from './gql-team-env-team.guard';
|
import { GqlTeamEnvTeamGuard } from './gql-team-env-team.guard';
|
||||||
import { TeamEnvironment } from './team-environments.model';
|
import { TeamEnvironment } from './team-environments.model';
|
||||||
import { TeamEnvironmentsService } from './team-environments.service';
|
import { TeamEnvironmentsService } from './team-environments.service';
|
||||||
import * as E from 'fp-ts/Either';
|
|
||||||
import {
|
|
||||||
CreateTeamEnvironmentArgs,
|
|
||||||
UpdateTeamEnvironmentArgs,
|
|
||||||
} from './input-type.args';
|
|
||||||
|
|
||||||
@UseGuards(GqlThrottlerGuard)
|
@UseGuards(GqlThrottlerGuard)
|
||||||
@Resolver(() => 'TeamEnvironment')
|
@Resolver(() => 'TeamEnvironment')
|
||||||
@@ -34,18 +29,29 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
||||||
async createTeamEnvironment(
|
createTeamEnvironment(
|
||||||
@Args() args: CreateTeamEnvironmentArgs,
|
@Args({
|
||||||
|
name: 'name',
|
||||||
|
description: 'Name of the Team Environment',
|
||||||
|
})
|
||||||
|
name: string,
|
||||||
|
@Args({
|
||||||
|
name: 'teamID',
|
||||||
|
description: 'ID of the Team',
|
||||||
|
type: () => ID,
|
||||||
|
})
|
||||||
|
teamID: string,
|
||||||
|
@Args({
|
||||||
|
name: 'variables',
|
||||||
|
description: 'JSON string of the variables object',
|
||||||
|
})
|
||||||
|
variables: string,
|
||||||
): Promise<TeamEnvironment> {
|
): Promise<TeamEnvironment> {
|
||||||
const teamEnvironment =
|
return this.teamEnvironmentsService.createTeamEnvironment(
|
||||||
await this.teamEnvironmentsService.createTeamEnvironment(
|
name,
|
||||||
args.name,
|
teamID,
|
||||||
args.teamID,
|
variables,
|
||||||
args.variables,
|
)();
|
||||||
);
|
|
||||||
|
|
||||||
if (E.isLeft(teamEnvironment)) throwErr(teamEnvironment.left);
|
|
||||||
return teamEnvironment.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => Boolean, {
|
@Mutation(() => Boolean, {
|
||||||
@@ -53,7 +59,7 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
||||||
async deleteTeamEnvironment(
|
deleteTeamEnvironment(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
description: 'ID of the Team Environment',
|
description: 'ID of the Team Environment',
|
||||||
@@ -61,12 +67,10 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
id: string,
|
id: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const isDeleted = await this.teamEnvironmentsService.deleteTeamEnvironment(
|
return pipe(
|
||||||
id,
|
this.teamEnvironmentsService.deleteTeamEnvironment(id),
|
||||||
);
|
TE.getOrElse(throwErr),
|
||||||
|
)();
|
||||||
if (E.isLeft(isDeleted)) throwErr(isDeleted.left);
|
|
||||||
return isDeleted.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TeamEnvironment, {
|
@Mutation(() => TeamEnvironment, {
|
||||||
@@ -75,19 +79,28 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
||||||
async updateTeamEnvironment(
|
updateTeamEnvironment(
|
||||||
@Args()
|
@Args({
|
||||||
args: UpdateTeamEnvironmentArgs,
|
name: 'id',
|
||||||
|
description: 'ID of the Team Environment',
|
||||||
|
type: () => ID,
|
||||||
|
})
|
||||||
|
id: string,
|
||||||
|
@Args({
|
||||||
|
name: 'name',
|
||||||
|
description: 'Name of the Team Environment',
|
||||||
|
})
|
||||||
|
name: string,
|
||||||
|
@Args({
|
||||||
|
name: 'variables',
|
||||||
|
description: 'JSON string of the variables object',
|
||||||
|
})
|
||||||
|
variables: string,
|
||||||
): Promise<TeamEnvironment> {
|
): Promise<TeamEnvironment> {
|
||||||
const updatedTeamEnvironment =
|
return pipe(
|
||||||
await this.teamEnvironmentsService.updateTeamEnvironment(
|
this.teamEnvironmentsService.updateTeamEnvironment(id, name, variables),
|
||||||
args.id,
|
TE.getOrElse(throwErr),
|
||||||
args.name,
|
)();
|
||||||
args.variables,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (E.isLeft(updatedTeamEnvironment)) throwErr(updatedTeamEnvironment.left);
|
|
||||||
return updatedTeamEnvironment.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TeamEnvironment, {
|
@Mutation(() => TeamEnvironment, {
|
||||||
@@ -95,7 +108,7 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
||||||
async deleteAllVariablesFromTeamEnvironment(
|
deleteAllVariablesFromTeamEnvironment(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
description: 'ID of the Team Environment',
|
description: 'ID of the Team Environment',
|
||||||
@@ -103,13 +116,10 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
id: string,
|
id: string,
|
||||||
): Promise<TeamEnvironment> {
|
): Promise<TeamEnvironment> {
|
||||||
const teamEnvironment =
|
return pipe(
|
||||||
await this.teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
this.teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(id),
|
||||||
id,
|
TE.getOrElse(throwErr),
|
||||||
);
|
)();
|
||||||
|
|
||||||
if (E.isLeft(teamEnvironment)) throwErr(teamEnvironment.left);
|
|
||||||
return teamEnvironment.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TeamEnvironment, {
|
@Mutation(() => TeamEnvironment, {
|
||||||
@@ -117,7 +127,7 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamEnvTeamGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
@RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
||||||
async createDuplicateEnvironment(
|
createDuplicateEnvironment(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
description: 'ID of the Team Environment',
|
description: 'ID of the Team Environment',
|
||||||
@@ -125,12 +135,10 @@ export class TeamEnvironmentsResolver {
|
|||||||
})
|
})
|
||||||
id: string,
|
id: string,
|
||||||
): Promise<TeamEnvironment> {
|
): Promise<TeamEnvironment> {
|
||||||
const res = await this.teamEnvironmentsService.createDuplicateEnvironment(
|
return pipe(
|
||||||
id,
|
this.teamEnvironmentsService.createDuplicateEnvironment(id),
|
||||||
);
|
TE.getOrElse(throwErr),
|
||||||
|
)();
|
||||||
if (E.isLeft(res)) throwErr(res.left);
|
|
||||||
return res.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Subscriptions */
|
/* Subscriptions */
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import { mockDeep, mockReset } from 'jest-mock-extended';
|
|||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import { TeamEnvironment } from './team-environments.model';
|
import { TeamEnvironment } from './team-environments.model';
|
||||||
import { TeamEnvironmentsService } from './team-environments.service';
|
import { TeamEnvironmentsService } from './team-environments.service';
|
||||||
import {
|
import { TEAM_ENVIRONMENT_NOT_FOUND } from 'src/errors';
|
||||||
JSON_INVALID,
|
|
||||||
TEAM_ENVIRONMENT_NOT_FOUND,
|
|
||||||
TEAM_ENVIRONMENT_SHORT_NAME,
|
|
||||||
} from 'src/errors';
|
|
||||||
|
|
||||||
const mockPrisma = mockDeep<PrismaService>();
|
const mockPrisma = mockDeep<PrismaService>();
|
||||||
|
|
||||||
@@ -35,81 +31,125 @@ beforeEach(() => {
|
|||||||
|
|
||||||
describe('TeamEnvironmentsService', () => {
|
describe('TeamEnvironmentsService', () => {
|
||||||
describe('getTeamEnvironment', () => {
|
describe('getTeamEnvironment', () => {
|
||||||
test('should successfully return a TeamEnvironment with valid ID', async () => {
|
test('queries the db with the id', async () => {
|
||||||
mockPrisma.teamEnvironment.findFirstOrThrow.mockResolvedValueOnce(
|
mockPrisma.teamEnvironment.findFirst.mockResolvedValue(teamEnvironment);
|
||||||
teamEnvironment,
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.getTeamEnvironment(
|
await teamEnvironmentsService.getTeamEnvironment('123')();
|
||||||
teamEnvironment.id,
|
|
||||||
|
expect(mockPrisma.teamEnvironment.findFirst).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
where: {
|
||||||
|
id: '123',
|
||||||
|
},
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
expect(result).toEqualRight(teamEnvironment);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMENT_NOT_FOUND with invalid ID', async () => {
|
test('requests prisma to reject the query promise if not found', async () => {
|
||||||
mockPrisma.teamEnvironment.findFirstOrThrow.mockRejectedValueOnce(
|
mockPrisma.teamEnvironment.findFirst.mockResolvedValue(teamEnvironment);
|
||||||
'RejectOnNotFound',
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.getTeamEnvironment(
|
await teamEnvironmentsService.getTeamEnvironment('123')();
|
||||||
teamEnvironment.id,
|
|
||||||
|
expect(mockPrisma.teamEnvironment.findFirst).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
rejectOnNotFound: true,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return a Some of the correct environment if exists', async () => {
|
||||||
|
mockPrisma.teamEnvironment.findFirst.mockResolvedValue(teamEnvironment);
|
||||||
|
|
||||||
|
const result = await teamEnvironmentsService.getTeamEnvironment('123')();
|
||||||
|
|
||||||
|
expect(result).toEqualSome(teamEnvironment);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return a None if the environment does not exist', async () => {
|
||||||
|
mockPrisma.teamEnvironment.findFirst.mockRejectedValue('NotFoundError');
|
||||||
|
|
||||||
|
const result = await teamEnvironmentsService.getTeamEnvironment('123')();
|
||||||
|
|
||||||
|
expect(result).toBeNone();
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('createTeamEnvironment', () => {
|
describe('createTeamEnvironment', () => {
|
||||||
test('should successfully create and return a new team environment given valid inputs', async () => {
|
test('should create and return a new team environment given a valid name,variable and team ID', async () => {
|
||||||
mockPrisma.teamEnvironment.create.mockResolvedValue(teamEnvironment);
|
mockPrisma.teamEnvironment.create.mockResolvedValue(teamEnvironment);
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.createTeamEnvironment(
|
const result = await teamEnvironmentsService.createTeamEnvironment(
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
teamEnvironment.teamID,
|
teamEnvironment.teamID,
|
||||||
JSON.stringify(teamEnvironment.variables),
|
JSON.stringify(teamEnvironment.variables),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight({
|
expect(result).toEqual(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
id: teamEnvironment.id,
|
||||||
|
name: teamEnvironment.name,
|
||||||
|
teamID: teamEnvironment.teamID,
|
||||||
variables: JSON.stringify(teamEnvironment.variables),
|
variables: JSON.stringify(teamEnvironment.variables),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
|
test('should reject if given team ID is invalid', async () => {
|
||||||
const result = await teamEnvironmentsService.createTeamEnvironment(
|
mockPrisma.teamEnvironment.create.mockRejectedValue(null as any);
|
||||||
'12',
|
|
||||||
|
await expect(
|
||||||
|
teamEnvironmentsService.createTeamEnvironment(
|
||||||
|
teamEnvironment.name,
|
||||||
|
'invalidteamid',
|
||||||
|
JSON.stringify(teamEnvironment.variables),
|
||||||
|
),
|
||||||
|
).rejects.toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should reject if provided team environment name is not a string', async () => {
|
||||||
|
mockPrisma.teamEnvironment.create.mockRejectedValue(null as any);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
teamEnvironmentsService.createTeamEnvironment(
|
||||||
|
null as any,
|
||||||
teamEnvironment.teamID,
|
teamEnvironment.teamID,
|
||||||
JSON.stringify(teamEnvironment.variables),
|
JSON.stringify(teamEnvironment.variables),
|
||||||
);
|
),
|
||||||
|
).rejects.toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_SHORT_NAME);
|
test('should reject if provided variable is not a string', async () => {
|
||||||
|
mockPrisma.teamEnvironment.create.mockRejectedValue(null as any);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
teamEnvironmentsService.createTeamEnvironment(
|
||||||
|
teamEnvironment.name,
|
||||||
|
teamEnvironment.teamID,
|
||||||
|
null as any,
|
||||||
|
),
|
||||||
|
).rejects.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should send pubsub message to "team_environment/<teamID>/created" if team environment is created successfully', async () => {
|
test('should send pubsub message to "team_environment/<teamID>/created" if team environment is created successfully', async () => {
|
||||||
mockPrisma.teamEnvironment.create.mockResolvedValue(teamEnvironment);
|
mockPrisma.teamEnvironment.create.mockResolvedValueOnce(teamEnvironment);
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.createTeamEnvironment(
|
const result = await teamEnvironmentsService.createTeamEnvironment(
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
teamEnvironment.teamID,
|
teamEnvironment.teamID,
|
||||||
JSON.stringify(teamEnvironment.variables),
|
JSON.stringify(teamEnvironment.variables),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
||||||
`team_environment/${teamEnvironment.teamID}/created`,
|
`team_environment/${teamEnvironment.teamID}/created`,
|
||||||
{
|
result,
|
||||||
...teamEnvironment,
|
|
||||||
variables: JSON.stringify(teamEnvironment.variables),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteTeamEnvironment', () => {
|
describe('deleteTeamEnvironment', () => {
|
||||||
test('should successfully delete a TeamEnvironment with a valid ID', async () => {
|
test('should resolve to true given a valid team environment ID', async () => {
|
||||||
mockPrisma.teamEnvironment.delete.mockResolvedValueOnce(teamEnvironment);
|
mockPrisma.teamEnvironment.delete.mockResolvedValueOnce(teamEnvironment);
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(true);
|
expect(result).toEqualRight(true);
|
||||||
});
|
});
|
||||||
@@ -119,7 +159,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
|
|
||||||
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
||||||
'invalidid',
|
'invalidid',
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
||||||
});
|
});
|
||||||
@@ -129,7 +169,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
|
|
||||||
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
const result = await teamEnvironmentsService.deleteTeamEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
||||||
`team_environment/${teamEnvironment.teamID}/deleted`,
|
`team_environment/${teamEnvironment.teamID}/deleted`,
|
||||||
@@ -142,7 +182,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('updateVariablesInTeamEnvironment', () => {
|
describe('updateVariablesInTeamEnvironment', () => {
|
||||||
test('should successfully add new variable to a team environment', async () => {
|
test('should add new variable to a team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
variables: [{ key: 'value' }],
|
variables: [{ key: 'value' }],
|
||||||
@@ -152,7 +192,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify([{ key: 'value' }]),
|
JSON.stringify([{ key: 'value' }]),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
@@ -160,7 +200,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should successfully add new variable to already existing list of variables in a team environment', async () => {
|
test('should add new variable to already existing list of variables in a team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
variables: [{ key: 'value' }, { key_2: 'value_2' }],
|
variables: [{ key: 'value' }, { key_2: 'value_2' }],
|
||||||
@@ -170,7 +210,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify([{ key: 'value' }, { key_2: 'value_2' }]),
|
JSON.stringify([{ key: 'value' }, { key_2: 'value_2' }]),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
@@ -178,7 +218,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should successfully edit existing variables in a team environment', async () => {
|
test('should edit existing variables in a team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
variables: [{ key: '1234' }],
|
variables: [{ key: '1234' }],
|
||||||
@@ -188,7 +228,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify([{ key: '1234' }]),
|
JSON.stringify([{ key: '1234' }]),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
@@ -196,7 +236,22 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should successfully edit name of an existing team environment', async () => {
|
test('should delete existing variable in a team environment', async () => {
|
||||||
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce(teamEnvironment);
|
||||||
|
|
||||||
|
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
||||||
|
teamEnvironment.id,
|
||||||
|
teamEnvironment.name,
|
||||||
|
JSON.stringify([{}]),
|
||||||
|
)();
|
||||||
|
|
||||||
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
|
...teamEnvironment,
|
||||||
|
variables: JSON.stringify([{}]),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should edit name of an existing team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce({
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
variables: [{ key: '123' }],
|
variables: [{ key: '123' }],
|
||||||
@@ -206,7 +261,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify([{ key: '123' }]),
|
JSON.stringify([{ key: '123' }]),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
@@ -214,24 +269,14 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMENT_SHORT_NAME if input TeamEnvironment name is invalid', async () => {
|
test('should reject to TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
||||||
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
|
||||||
teamEnvironment.id,
|
|
||||||
'12',
|
|
||||||
JSON.stringify([{ key: 'value' }]),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_SHORT_NAME);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
|
||||||
mockPrisma.teamEnvironment.update.mockRejectedValue('RecordNotFound');
|
mockPrisma.teamEnvironment.update.mockRejectedValue('RecordNotFound');
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
const result = await teamEnvironmentsService.updateTeamEnvironment(
|
||||||
'invalidid',
|
'invalidid',
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify(teamEnvironment.variables),
|
JSON.stringify(teamEnvironment.variables),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
||||||
});
|
});
|
||||||
@@ -243,7 +288,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
teamEnvironment.name,
|
teamEnvironment.name,
|
||||||
JSON.stringify([{ key: 'value' }]),
|
JSON.stringify([{ key: 'value' }]),
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
||||||
`team_environment/${teamEnvironment.teamID}/updated`,
|
`team_environment/${teamEnvironment.teamID}/updated`,
|
||||||
@@ -256,13 +301,13 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteAllVariablesFromTeamEnvironment', () => {
|
describe('deleteAllVariablesFromTeamEnvironment', () => {
|
||||||
test('should successfully delete all variables in a team environment', async () => {
|
test('should delete all variables in a team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockResolvedValueOnce(teamEnvironment);
|
mockPrisma.teamEnvironment.update.mockResolvedValueOnce(teamEnvironment);
|
||||||
|
|
||||||
const result =
|
const result =
|
||||||
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
@@ -270,13 +315,13 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
test('should reject to TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
||||||
mockPrisma.teamEnvironment.update.mockRejectedValue('RecordNotFound');
|
mockPrisma.teamEnvironment.update.mockRejectedValue('RecordNotFound');
|
||||||
|
|
||||||
const result =
|
const result =
|
||||||
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
||||||
'invalidid',
|
'invalidid',
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
||||||
});
|
});
|
||||||
@@ -287,7 +332,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
const result =
|
const result =
|
||||||
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
await teamEnvironmentsService.deleteAllVariablesFromTeamEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
||||||
`team_environment/${teamEnvironment.teamID}/updated`,
|
`team_environment/${teamEnvironment.teamID}/updated`,
|
||||||
@@ -300,7 +345,7 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('createDuplicateEnvironment', () => {
|
describe('createDuplicateEnvironment', () => {
|
||||||
test('should successfully duplicate an existing team environment', async () => {
|
test('should duplicate an existing team environment', async () => {
|
||||||
mockPrisma.teamEnvironment.findFirst.mockResolvedValueOnce(
|
mockPrisma.teamEnvironment.findFirst.mockResolvedValueOnce(
|
||||||
teamEnvironment,
|
teamEnvironment,
|
||||||
);
|
);
|
||||||
@@ -312,21 +357,21 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
|
|
||||||
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualRight(<TeamEnvironment>{
|
expect(result).toEqualRight(<TeamEnvironment>{
|
||||||
id: 'newid',
|
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
|
id: 'newid',
|
||||||
variables: JSON.stringify(teamEnvironment.variables),
|
variables: JSON.stringify(teamEnvironment.variables),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
test('should reject to TEAM_ENVIRONMMENT_NOT_FOUND if provided id is invalid', async () => {
|
||||||
mockPrisma.teamEnvironment.findFirst.mockRejectedValue('NotFoundError');
|
mockPrisma.teamEnvironment.findFirst.mockRejectedValue('NotFoundError');
|
||||||
|
|
||||||
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
expect(result).toEqualLeft(TEAM_ENVIRONMENT_NOT_FOUND);
|
||||||
});
|
});
|
||||||
@@ -343,13 +388,13 @@ describe('TeamEnvironmentsService', () => {
|
|||||||
|
|
||||||
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
const result = await teamEnvironmentsService.createDuplicateEnvironment(
|
||||||
teamEnvironment.id,
|
teamEnvironment.id,
|
||||||
);
|
)();
|
||||||
|
|
||||||
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
expect(mockPubSub.publish).toHaveBeenCalledWith(
|
||||||
`team_environment/${teamEnvironment.teamID}/created`,
|
`team_environment/${teamEnvironment.teamID}/created`,
|
||||||
{
|
{
|
||||||
id: 'newid',
|
|
||||||
...teamEnvironment,
|
...teamEnvironment,
|
||||||
|
id: 'newid',
|
||||||
variables: JSON.stringify([{}]),
|
variables: JSON.stringify([{}]),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TeamEnvironment as DBTeamEnvironment, Prisma } from '@prisma/client';
|
import { pipe } from 'fp-ts/function';
|
||||||
|
import * as T from 'fp-ts/Task';
|
||||||
|
import * as TO from 'fp-ts/TaskOption';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
|
import * as A from 'fp-ts/Array';
|
||||||
|
import { Prisma } from '@prisma/client';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import { PubSubService } from 'src/pubsub/pubsub.service';
|
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||||
import { TeamEnvironment } from './team-environments.model';
|
import { TeamEnvironment } from './team-environments.model';
|
||||||
import {
|
import { TEAM_ENVIRONMENT_NOT_FOUND } from 'src/errors';
|
||||||
TEAM_ENVIRONMENT_NOT_FOUND,
|
|
||||||
TEAM_ENVIRONMENT_SHORT_NAME,
|
|
||||||
} from 'src/errors';
|
|
||||||
import * as E from 'fp-ts/Either';
|
|
||||||
import { isValidLength } from 'src/utils';
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TeamEnvironmentsService {
|
export class TeamEnvironmentsService {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -16,218 +17,219 @@ export class TeamEnvironmentsService {
|
|||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
TITLE_LENGTH = 3;
|
getTeamEnvironment(id: string) {
|
||||||
|
return TO.tryCatch(() =>
|
||||||
/**
|
this.prisma.teamEnvironment.findFirst({
|
||||||
* TeamEnvironments are saved in the DB in the following way
|
|
||||||
* [{ key: value }, { key: value },....]
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Typecast a database TeamEnvironment to a TeamEnvironment model
|
|
||||||
* @param teamEnvironment database TeamEnvironment
|
|
||||||
* @returns TeamEnvironment model
|
|
||||||
*/
|
|
||||||
private cast(teamEnvironment: DBTeamEnvironment): TeamEnvironment {
|
|
||||||
return {
|
|
||||||
id: teamEnvironment.id,
|
|
||||||
name: teamEnvironment.name,
|
|
||||||
teamID: teamEnvironment.teamID,
|
|
||||||
variables: JSON.stringify(teamEnvironment.variables),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get details of a TeamEnvironment.
|
|
||||||
*
|
|
||||||
* @param id TeamEnvironment ID
|
|
||||||
* @returns Either of a TeamEnvironment or error message
|
|
||||||
*/
|
|
||||||
async getTeamEnvironment(id: string) {
|
|
||||||
try {
|
|
||||||
const teamEnvironment =
|
|
||||||
await this.prisma.teamEnvironment.findFirstOrThrow({
|
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
rejectOnNotFound: true,
|
||||||
return E.right(teamEnvironment);
|
}),
|
||||||
} catch (error) {
|
);
|
||||||
return E.left(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
createTeamEnvironment(name: string, teamID: string, variables: string) {
|
||||||
* Create a new TeamEnvironment.
|
return pipe(
|
||||||
*
|
() =>
|
||||||
* @param name name of new TeamEnvironment
|
this.prisma.teamEnvironment.create({
|
||||||
* @param teamID teamID of new TeamEnvironment
|
|
||||||
* @param variables JSONified string of contents of new TeamEnvironment
|
|
||||||
* @returns Either of a TeamEnvironment or error message
|
|
||||||
*/
|
|
||||||
async createTeamEnvironment(name: string, teamID: string, variables: string) {
|
|
||||||
const isTitleValid = isValidLength(name, this.TITLE_LENGTH);
|
|
||||||
if (!isTitleValid) return E.left(TEAM_ENVIRONMENT_SHORT_NAME);
|
|
||||||
|
|
||||||
const result = await this.prisma.teamEnvironment.create({
|
|
||||||
data: {
|
data: {
|
||||||
name: name,
|
name: name,
|
||||||
teamID: teamID,
|
teamID: teamID,
|
||||||
variables: JSON.parse(variables),
|
variables: JSON.parse(variables),
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
T.chainFirst(
|
||||||
const createdTeamEnvironment = this.cast(result);
|
(environment) => () =>
|
||||||
|
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team_environment/${createdTeamEnvironment.teamID}/created`,
|
`team_environment/${environment.teamID}/created`,
|
||||||
createdTeamEnvironment,
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
T.map((data) => {
|
||||||
|
return <TeamEnvironment>{
|
||||||
|
id: data.id,
|
||||||
|
name: data.name,
|
||||||
|
teamID: data.teamID,
|
||||||
|
variables: JSON.stringify(data.variables),
|
||||||
|
};
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return E.right(createdTeamEnvironment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
deleteTeamEnvironment(id: string) {
|
||||||
* Delete a TeamEnvironment.
|
return pipe(
|
||||||
*
|
TE.tryCatch(
|
||||||
* @param id TeamEnvironment ID
|
() =>
|
||||||
* @returns Either of boolean or error message
|
this.prisma.teamEnvironment.delete({
|
||||||
*/
|
|
||||||
async deleteTeamEnvironment(id: string) {
|
|
||||||
try {
|
|
||||||
const result = await this.prisma.teamEnvironment.delete({
|
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
() => TEAM_ENVIRONMENT_NOT_FOUND,
|
||||||
const deletedTeamEnvironment = this.cast(result);
|
),
|
||||||
|
TE.chainFirst((environment) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team_environment/${deletedTeamEnvironment.teamID}/deleted`,
|
`team_environment/${environment.teamID}/deleted`,
|
||||||
deletedTeamEnvironment,
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.map((data) => true),
|
||||||
);
|
);
|
||||||
|
|
||||||
return E.right(true);
|
|
||||||
} catch (error) {
|
|
||||||
return E.left(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
updateTeamEnvironment(id: string, name: string, variables: string) {
|
||||||
* Update a TeamEnvironment.
|
return pipe(
|
||||||
*
|
TE.tryCatch(
|
||||||
* @param id TeamEnvironment ID
|
() =>
|
||||||
* @param name TeamEnvironment name
|
this.prisma.teamEnvironment.update({
|
||||||
* @param variables JSONified string of contents of new TeamEnvironment
|
|
||||||
* @returns Either of a TeamEnvironment or error message
|
|
||||||
*/
|
|
||||||
async updateTeamEnvironment(id: string, name: string, variables: string) {
|
|
||||||
try {
|
|
||||||
const isTitleValid = isValidLength(name, this.TITLE_LENGTH);
|
|
||||||
if (!isTitleValid) return E.left(TEAM_ENVIRONMENT_SHORT_NAME);
|
|
||||||
|
|
||||||
const result = await this.prisma.teamEnvironment.update({
|
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
variables: JSON.parse(variables),
|
variables: JSON.parse(variables),
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
() => TEAM_ENVIRONMENT_NOT_FOUND,
|
||||||
const updatedTeamEnvironment = this.cast(result);
|
),
|
||||||
|
TE.chainFirst((environment) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team_environment/${updatedTeamEnvironment.teamID}/updated`,
|
`team_environment/${environment.teamID}/updated`,
|
||||||
updatedTeamEnvironment,
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.map(
|
||||||
|
(environment) =>
|
||||||
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return E.right(updatedTeamEnvironment);
|
|
||||||
} catch (error) {
|
|
||||||
return E.left(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
deleteAllVariablesFromTeamEnvironment(id: string) {
|
||||||
* Clear contents of a TeamEnvironment.
|
return pipe(
|
||||||
*
|
TE.tryCatch(
|
||||||
* @param id TeamEnvironment ID
|
() =>
|
||||||
* @returns Either of a TeamEnvironment or error message
|
this.prisma.teamEnvironment.update({
|
||||||
*/
|
|
||||||
async deleteAllVariablesFromTeamEnvironment(id: string) {
|
|
||||||
try {
|
|
||||||
const result = await this.prisma.teamEnvironment.update({
|
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
data: {
|
data: {
|
||||||
variables: [],
|
variables: [],
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
() => TEAM_ENVIRONMENT_NOT_FOUND,
|
||||||
const teamEnvironment = this.cast(result);
|
),
|
||||||
|
TE.chainFirst((environment) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team_environment/${teamEnvironment.teamID}/updated`,
|
`team_environment/${environment.teamID}/updated`,
|
||||||
teamEnvironment,
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.map(
|
||||||
|
(environment) =>
|
||||||
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return E.right(teamEnvironment);
|
|
||||||
} catch (error) {
|
|
||||||
return E.left(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
createDuplicateEnvironment(id: string) {
|
||||||
* Create a duplicate of a existing TeamEnvironment.
|
return pipe(
|
||||||
*
|
TE.tryCatch(
|
||||||
* @param id TeamEnvironment ID
|
() =>
|
||||||
* @returns Either of a TeamEnvironment or error message
|
this.prisma.teamEnvironment.findFirst({
|
||||||
*/
|
|
||||||
async createDuplicateEnvironment(id: string) {
|
|
||||||
try {
|
|
||||||
const environment = await this.prisma.teamEnvironment.findFirst({
|
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
rejectOnNotFound: true,
|
rejectOnNotFound: true,
|
||||||
});
|
}),
|
||||||
|
() => TEAM_ENVIRONMENT_NOT_FOUND,
|
||||||
const result = await this.prisma.teamEnvironment.create({
|
),
|
||||||
|
TE.chain((environment) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
|
this.prisma.teamEnvironment.create({
|
||||||
data: {
|
data: {
|
||||||
name: environment.name,
|
name: environment.name,
|
||||||
teamID: environment.teamID,
|
teamID: environment.teamID,
|
||||||
variables: environment.variables as Prisma.JsonArray,
|
variables: environment.variables as Prisma.JsonArray,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
),
|
||||||
const duplicatedTeamEnvironment = this.cast(result);
|
),
|
||||||
|
TE.chainFirst((environment) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team_environment/${duplicatedTeamEnvironment.teamID}/created`,
|
`team_environment/${environment.teamID}/created`,
|
||||||
duplicatedTeamEnvironment,
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.map(
|
||||||
|
(environment) =>
|
||||||
|
<TeamEnvironment>{
|
||||||
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return E.right(duplicatedTeamEnvironment);
|
|
||||||
} catch (error) {
|
|
||||||
return E.left(TEAM_ENVIRONMENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fetchAllTeamEnvironments(teamID: string) {
|
||||||
* Fetch all TeamEnvironments of a team.
|
return pipe(
|
||||||
*
|
() =>
|
||||||
* @param teamID teamID of new TeamEnvironment
|
this.prisma.teamEnvironment.findMany({
|
||||||
* @returns List of TeamEnvironments
|
|
||||||
*/
|
|
||||||
async fetchAllTeamEnvironments(teamID: string) {
|
|
||||||
const result = await this.prisma.teamEnvironment.findMany({
|
|
||||||
where: {
|
where: {
|
||||||
teamID: teamID,
|
teamID: teamID,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
const teamEnvironments = result.map((item) => {
|
T.map(
|
||||||
return this.cast(item);
|
A.map(
|
||||||
});
|
(environment) =>
|
||||||
|
<TeamEnvironment>{
|
||||||
return teamEnvironments;
|
id: environment.id,
|
||||||
|
name: environment.name,
|
||||||
|
teamID: environment.teamID,
|
||||||
|
variables: JSON.stringify(environment.variables),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ export class TeamEnvsTeamResolver {
|
|||||||
description: 'Returns all Team Environments for the given Team',
|
description: 'Returns all Team Environments for the given Team',
|
||||||
})
|
})
|
||||||
teamEnvironments(@Parent() team: Team): Promise<TeamEnvironment[]> {
|
teamEnvironments(@Parent() team: Team): Promise<TeamEnvironment[]> {
|
||||||
return this.teamEnvironmentService.fetchAllTeamEnvironments(team.id);
|
return this.teamEnvironmentService.fetchAllTeamEnvironments(team.id)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import { ArgsType, Field, ID } from '@nestjs/graphql';
|
|
||||||
import { TeamMemberRole } from 'src/team/team.model';
|
|
||||||
|
|
||||||
@ArgsType()
|
|
||||||
export class CreateTeamInvitationArgs {
|
|
||||||
@Field(() => ID, {
|
|
||||||
name: 'teamID',
|
|
||||||
description: 'ID of the Team ID to invite from',
|
|
||||||
})
|
|
||||||
teamID: string;
|
|
||||||
|
|
||||||
@Field({ name: 'inviteeEmail', description: 'Email of the user to invite' })
|
|
||||||
inviteeEmail: string;
|
|
||||||
|
|
||||||
@Field(() => TeamMemberRole, {
|
|
||||||
name: 'inviteeRole',
|
|
||||||
description: 'Role to be given to the user',
|
|
||||||
})
|
|
||||||
inviteeRole: TeamMemberRole;
|
|
||||||
}
|
|
||||||
@@ -12,10 +12,15 @@ import { TeamInvitation } from './team-invitation.model';
|
|||||||
import { TeamInvitationService } from './team-invitation.service';
|
import { TeamInvitationService } from './team-invitation.service';
|
||||||
import { pipe } from 'fp-ts/function';
|
import { pipe } from 'fp-ts/function';
|
||||||
import * as TE from 'fp-ts/TaskEither';
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import * as E from 'fp-ts/Either';
|
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import { Team, TeamMember, TeamMemberRole } from 'src/team/team.model';
|
import { Team, TeamMember, TeamMemberRole } from 'src/team/team.model';
|
||||||
import { TEAM_INVITE_NO_INVITE_FOUND, USER_NOT_FOUND } from 'src/errors';
|
import { EmailCodec } from 'src/types/Email';
|
||||||
|
import {
|
||||||
|
INVALID_EMAIL,
|
||||||
|
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
|
TEAM_INVITE_NO_INVITE_FOUND,
|
||||||
|
USER_NOT_FOUND,
|
||||||
|
} from 'src/errors';
|
||||||
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
||||||
import { User } from 'src/user/user.model';
|
import { User } from 'src/user/user.model';
|
||||||
import { UseGuards } from '@nestjs/common';
|
import { UseGuards } from '@nestjs/common';
|
||||||
@@ -31,8 +36,6 @@ import { UserService } from 'src/user/user.service';
|
|||||||
import { PubSubService } from 'src/pubsub/pubsub.service';
|
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||||
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
|
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
|
||||||
import { SkipThrottle } from '@nestjs/throttler';
|
import { SkipThrottle } from '@nestjs/throttler';
|
||||||
import { AuthUser } from 'src/types/AuthUser';
|
|
||||||
import { CreateTeamInvitationArgs } from './input-type.args';
|
|
||||||
|
|
||||||
@UseGuards(GqlThrottlerGuard)
|
@UseGuards(GqlThrottlerGuard)
|
||||||
@Resolver(() => TeamInvitation)
|
@Resolver(() => TeamInvitation)
|
||||||
@@ -76,8 +79,8 @@ export class TeamInvitationResolver {
|
|||||||
'Gets the Team Invitation with the given ID, or null if not exists',
|
'Gets the Team Invitation with the given ID, or null if not exists',
|
||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, TeamInviteViewerGuard)
|
@UseGuards(GqlAuthGuard, TeamInviteViewerGuard)
|
||||||
async teamInvitation(
|
teamInvitation(
|
||||||
@GqlUser() user: AuthUser,
|
@GqlUser() user: User,
|
||||||
@Args({
|
@Args({
|
||||||
name: 'inviteID',
|
name: 'inviteID',
|
||||||
description: 'ID of the Team Invitation to lookup',
|
description: 'ID of the Team Invitation to lookup',
|
||||||
@@ -85,11 +88,17 @@ export class TeamInvitationResolver {
|
|||||||
})
|
})
|
||||||
inviteID: string,
|
inviteID: string,
|
||||||
): Promise<TeamInvitation> {
|
): Promise<TeamInvitation> {
|
||||||
const teamInvitation = await this.teamInvitationService.getInvitation(
|
return pipe(
|
||||||
inviteID,
|
this.teamInvitationService.getInvitation(inviteID),
|
||||||
);
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
if (O.isNone(teamInvitation)) throwErr(TEAM_INVITE_NO_INVITE_FOUND);
|
TE.chainW(
|
||||||
return teamInvitation.value;
|
TE.fromPredicate(
|
||||||
|
(a) => a.inviteeEmail.toLowerCase() === user.email?.toLowerCase(),
|
||||||
|
() => TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.getOrElse(throwErr),
|
||||||
|
)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TeamInvitation, {
|
@Mutation(() => TeamInvitation, {
|
||||||
@@ -97,19 +106,56 @@ export class TeamInvitationResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
|
@UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER)
|
@RequiresTeamRole(TeamMemberRole.OWNER)
|
||||||
async createTeamInvitation(
|
createTeamInvitation(
|
||||||
@GqlUser() user: AuthUser,
|
@GqlUser()
|
||||||
@Args() args: CreateTeamInvitationArgs,
|
user: User,
|
||||||
): Promise<TeamInvitation> {
|
|
||||||
const teamInvitation = await this.teamInvitationService.createInvitation(
|
|
||||||
user,
|
|
||||||
args.teamID,
|
|
||||||
args.inviteeEmail,
|
|
||||||
args.inviteeRole,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (E.isLeft(teamInvitation)) throwErr(teamInvitation.left);
|
@Args({
|
||||||
return teamInvitation.right;
|
name: 'teamID',
|
||||||
|
description: 'ID of the Team ID to invite from',
|
||||||
|
type: () => ID,
|
||||||
|
})
|
||||||
|
teamID: string,
|
||||||
|
@Args({
|
||||||
|
name: 'inviteeEmail',
|
||||||
|
description: 'Email of the user to invite',
|
||||||
|
})
|
||||||
|
inviteeEmail: string,
|
||||||
|
@Args({
|
||||||
|
name: 'inviteeRole',
|
||||||
|
type: () => TeamMemberRole,
|
||||||
|
description: 'Role to be given to the user',
|
||||||
|
})
|
||||||
|
inviteeRole: TeamMemberRole,
|
||||||
|
): Promise<TeamInvitation> {
|
||||||
|
return pipe(
|
||||||
|
TE.Do,
|
||||||
|
|
||||||
|
// Validate email
|
||||||
|
TE.bindW('email', () =>
|
||||||
|
pipe(
|
||||||
|
EmailCodec.decode(inviteeEmail),
|
||||||
|
TE.fromEither,
|
||||||
|
TE.mapLeft(() => INVALID_EMAIL),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Validate and get Team
|
||||||
|
TE.bindW('team', () => this.teamService.getTeamWithIDTE(teamID)),
|
||||||
|
|
||||||
|
// Create team
|
||||||
|
TE.chainW(({ email, team }) =>
|
||||||
|
this.teamInvitationService.createInvitation(
|
||||||
|
user,
|
||||||
|
team,
|
||||||
|
email,
|
||||||
|
inviteeRole,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// If failed, throw err (so the message is passed) else return value
|
||||||
|
TE.getOrElse(throwErr),
|
||||||
|
)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => Boolean, {
|
@Mutation(() => Boolean, {
|
||||||
@@ -117,7 +163,7 @@ export class TeamInvitationResolver {
|
|||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, TeamInviteTeamOwnerGuard)
|
@UseGuards(GqlAuthGuard, TeamInviteTeamOwnerGuard)
|
||||||
@RequiresTeamRole(TeamMemberRole.OWNER)
|
@RequiresTeamRole(TeamMemberRole.OWNER)
|
||||||
async revokeTeamInvitation(
|
revokeTeamInvitation(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'inviteID',
|
name: 'inviteID',
|
||||||
type: () => ID,
|
type: () => ID,
|
||||||
@@ -125,19 +171,19 @@ export class TeamInvitationResolver {
|
|||||||
})
|
})
|
||||||
inviteID: string,
|
inviteID: string,
|
||||||
): Promise<true> {
|
): Promise<true> {
|
||||||
const isRevoked = await this.teamInvitationService.revokeInvitation(
|
return pipe(
|
||||||
inviteID,
|
this.teamInvitationService.revokeInvitation(inviteID),
|
||||||
);
|
TE.map(() => true as const),
|
||||||
if (E.isLeft(isRevoked)) throwErr(isRevoked.left);
|
TE.getOrElse(throwErr),
|
||||||
return true;
|
)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TeamMember, {
|
@Mutation(() => TeamMember, {
|
||||||
description: 'Accept an Invitation',
|
description: 'Accept an Invitation',
|
||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, TeamInviteeGuard)
|
@UseGuards(GqlAuthGuard, TeamInviteeGuard)
|
||||||
async acceptTeamInvitation(
|
acceptTeamInvitation(
|
||||||
@GqlUser() user: AuthUser,
|
@GqlUser() user: User,
|
||||||
@Args({
|
@Args({
|
||||||
name: 'inviteID',
|
name: 'inviteID',
|
||||||
type: () => ID,
|
type: () => ID,
|
||||||
@@ -145,12 +191,10 @@ export class TeamInvitationResolver {
|
|||||||
})
|
})
|
||||||
inviteID: string,
|
inviteID: string,
|
||||||
): Promise<TeamMember> {
|
): Promise<TeamMember> {
|
||||||
const teamMember = await this.teamInvitationService.acceptInvitation(
|
return pipe(
|
||||||
inviteID,
|
this.teamInvitationService.acceptInvitation(inviteID, user),
|
||||||
user,
|
TE.getOrElse(throwErr),
|
||||||
);
|
)();
|
||||||
if (E.isLeft(teamMember)) throwErr(teamMember.left);
|
|
||||||
return teamMember.right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscriptions
|
// Subscriptions
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import * as T from 'fp-ts/Task';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
|
import * as TO from 'fp-ts/TaskOption';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import * as E from 'fp-ts/Either';
|
import * as E from 'fp-ts/Either';
|
||||||
|
import { pipe, flow, constVoid } from 'fp-ts/function';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import { TeamInvitation as DBTeamInvitation } from '@prisma/client';
|
import { Team, TeamMemberRole } from 'src/team/team.model';
|
||||||
import { TeamMember, TeamMemberRole } from 'src/team/team.model';
|
import { Email } from 'src/types/Email';
|
||||||
|
import { User } from 'src/user/user.model';
|
||||||
import { TeamService } from 'src/team/team.service';
|
import { TeamService } from 'src/team/team.service';
|
||||||
import {
|
import {
|
||||||
INVALID_EMAIL,
|
INVALID_EMAIL,
|
||||||
TEAM_INVALID_ID,
|
|
||||||
TEAM_INVITE_ALREADY_MEMBER,
|
TEAM_INVITE_ALREADY_MEMBER,
|
||||||
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
TEAM_INVITE_MEMBER_HAS_INVITE,
|
TEAM_INVITE_MEMBER_HAS_INVITE,
|
||||||
TEAM_INVITE_NO_INVITE_FOUND,
|
TEAM_INVITE_NO_INVITE_FOUND,
|
||||||
TEAM_MEMBER_NOT_FOUND,
|
|
||||||
} from 'src/errors';
|
} from 'src/errors';
|
||||||
import { TeamInvitation } from './team-invitation.model';
|
import { TeamInvitation } from './team-invitation.model';
|
||||||
import { MailerService } from 'src/mailer/mailer.service';
|
import { MailerService } from 'src/mailer/mailer.service';
|
||||||
import { UserService } from 'src/user/user.service';
|
import { UserService } from 'src/user/user.service';
|
||||||
import { PubSubService } from 'src/pubsub/pubsub.service';
|
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||||
import { validateEmail } from '../utils';
|
import { validateEmail } from '../utils';
|
||||||
import { AuthUser } from 'src/types/AuthUser';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TeamInvitationService {
|
export class TeamInvitationService {
|
||||||
@@ -30,37 +32,38 @@ export class TeamInvitationService {
|
|||||||
private readonly mailerService: MailerService,
|
private readonly mailerService: MailerService,
|
||||||
|
|
||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {
|
||||||
|
this.getInvitation = this.getInvitation.bind(this);
|
||||||
/**
|
|
||||||
* Cast a DBTeamInvitation to a TeamInvitation
|
|
||||||
* @param dbTeamInvitation database TeamInvitation
|
|
||||||
* @returns TeamInvitation model
|
|
||||||
*/
|
|
||||||
cast(dbTeamInvitation: DBTeamInvitation): TeamInvitation {
|
|
||||||
return {
|
|
||||||
...dbTeamInvitation,
|
|
||||||
inviteeRole: TeamMemberRole[dbTeamInvitation.inviteeRole],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
getInvitation(inviteID: string): TO.TaskOption<TeamInvitation> {
|
||||||
* Get the team invite
|
return pipe(
|
||||||
* @param inviteID invite id
|
() =>
|
||||||
* @returns an Option of team invitation or none
|
this.prisma.teamInvitation.findUnique({
|
||||||
*/
|
|
||||||
async getInvitation(inviteID: string) {
|
|
||||||
try {
|
|
||||||
const dbInvitation = await this.prisma.teamInvitation.findUniqueOrThrow({
|
|
||||||
where: {
|
where: {
|
||||||
id: inviteID,
|
id: inviteID,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
TO.fromTask,
|
||||||
return O.some(this.cast(dbInvitation));
|
TO.chain(flow(O.fromNullable, TO.fromOption)),
|
||||||
} catch (e) {
|
TO.map((x) => x as TeamInvitation),
|
||||||
return O.none;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInvitationWithEmail(email: Email, team: Team) {
|
||||||
|
return pipe(
|
||||||
|
() =>
|
||||||
|
this.prisma.teamInvitation.findUnique({
|
||||||
|
where: {
|
||||||
|
teamID_inviteeEmail: {
|
||||||
|
inviteeEmail: email,
|
||||||
|
teamID: team.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
TO.fromTask,
|
||||||
|
TO.chain(flow(O.fromNullable, TO.fromOption)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,162 +92,211 @@ export class TeamInvitationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
createInvitation(
|
||||||
* Create a team invitation
|
creator: User,
|
||||||
* @param creator creator of the invitation
|
team: Team,
|
||||||
* @param teamID team id
|
inviteeEmail: Email,
|
||||||
* @param inviteeEmail invitee email
|
|
||||||
* @param inviteeRole invitee role
|
|
||||||
* @returns an Either of team invitation or error message
|
|
||||||
*/
|
|
||||||
async createInvitation(
|
|
||||||
creator: AuthUser,
|
|
||||||
teamID: string,
|
|
||||||
inviteeEmail: string,
|
|
||||||
inviteeRole: TeamMemberRole,
|
inviteeRole: TeamMemberRole,
|
||||||
) {
|
) {
|
||||||
// validate email
|
return pipe(
|
||||||
const isEmailValid = validateEmail(inviteeEmail);
|
// Perform all validation checks
|
||||||
if (!isEmailValid) return E.left(INVALID_EMAIL);
|
TE.sequenceArray([
|
||||||
|
// creator should be a TeamMember
|
||||||
|
pipe(
|
||||||
|
this.teamService.getTeamMemberTE(team.id, creator.uid),
|
||||||
|
TE.map(constVoid),
|
||||||
|
),
|
||||||
|
|
||||||
// team ID should valid
|
// Invitee should not be a team member
|
||||||
const team = await this.teamService.getTeamWithID(teamID);
|
pipe(
|
||||||
if (!team) return E.left(TEAM_INVALID_ID);
|
async () => await this.userService.findUserByEmail(inviteeEmail),
|
||||||
|
TO.foldW(
|
||||||
|
() => TE.right(undefined), // If no user, short circuit to completion
|
||||||
|
(user) =>
|
||||||
|
pipe(
|
||||||
|
// If user is found, check if team member
|
||||||
|
this.teamService.getTeamMemberTE(team.id, user.uid),
|
||||||
|
TE.foldW(
|
||||||
|
() => TE.right(undefined), // Not team-member, this is good
|
||||||
|
() => TE.left(TEAM_INVITE_ALREADY_MEMBER), // Is team member, not good
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TE.map(constVoid),
|
||||||
|
),
|
||||||
|
|
||||||
// invitation creator should be a TeamMember
|
// Should not have an existing invite
|
||||||
const isTeamMember = await this.teamService.getTeamMember(
|
pipe(
|
||||||
team.id,
|
this.getInvitationWithEmail(inviteeEmail, team),
|
||||||
creator.uid,
|
TE.fromTaskOption(() => null),
|
||||||
);
|
TE.swap,
|
||||||
if (!isTeamMember) return E.left(TEAM_MEMBER_NOT_FOUND);
|
TE.map(constVoid),
|
||||||
|
TE.mapLeft(() => TEAM_INVITE_MEMBER_HAS_INVITE),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
|
||||||
// Checking to see if the invitee is already part of the team or not
|
// Create the invitation
|
||||||
const inviteeUser = await this.userService.findUserByEmail(inviteeEmail);
|
TE.chainTaskK(
|
||||||
if (O.isSome(inviteeUser)) {
|
() => () =>
|
||||||
// invitee should not already a member
|
this.prisma.teamInvitation.create({
|
||||||
const isTeamMember = await this.teamService.getTeamMember(
|
|
||||||
team.id,
|
|
||||||
inviteeUser.value.uid,
|
|
||||||
);
|
|
||||||
if (isTeamMember) return E.left(TEAM_INVITE_ALREADY_MEMBER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check invitee already invited earlier or not
|
|
||||||
const teamInvitation = await this.getTeamInviteByEmailAndTeamID(
|
|
||||||
inviteeEmail,
|
|
||||||
team.id,
|
|
||||||
);
|
|
||||||
if (E.isRight(teamInvitation)) return E.left(TEAM_INVITE_MEMBER_HAS_INVITE);
|
|
||||||
|
|
||||||
// create the invitation
|
|
||||||
const dbInvitation = await this.prisma.teamInvitation.create({
|
|
||||||
data: {
|
data: {
|
||||||
teamID: team.id,
|
teamID: team.id,
|
||||||
inviteeEmail,
|
inviteeEmail,
|
||||||
inviteeRole,
|
inviteeRole,
|
||||||
creatorUid: creator.uid,
|
creatorUid: creator.uid,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
await this.mailerService.sendEmail(inviteeEmail, {
|
// Send email, this is a side effect
|
||||||
|
TE.chainFirstTaskK((invitation) =>
|
||||||
|
pipe(
|
||||||
|
this.mailerService.sendMail(inviteeEmail, {
|
||||||
template: 'team-invitation',
|
template: 'team-invitation',
|
||||||
variables: {
|
variables: {
|
||||||
invitee: creator.displayName ?? 'A Hoppscotch User',
|
invitee: creator.displayName ?? 'A Hoppscotch User',
|
||||||
action_url: `${process.env.VITE_BASE_URL}/join-team?id=${dbInvitation.id}`,
|
action_url: `${process.env.VITE_BASE_URL}/join-team?id=${invitation.id}`,
|
||||||
invite_team_name: team.name,
|
invite_team_name: team.name,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
|
||||||
const invitation = this.cast(dbInvitation);
|
TE.getOrElseW(() => T.of(undefined)), // This value doesn't matter as we don't mind the return value (chainFirst) as long as the task completes
|
||||||
this.pubsub.publish(`team/${invitation.teamID}/invite_added`, invitation);
|
),
|
||||||
|
),
|
||||||
|
|
||||||
return E.right(invitation);
|
// Send PubSub topic
|
||||||
|
TE.chainFirstTaskK((invitation) =>
|
||||||
|
TE.fromTask(async () => {
|
||||||
|
const inv: TeamInvitation = {
|
||||||
|
id: invitation.id,
|
||||||
|
teamID: invitation.teamID,
|
||||||
|
creatorUid: invitation.creatorUid,
|
||||||
|
inviteeEmail: invitation.inviteeEmail,
|
||||||
|
inviteeRole: TeamMemberRole[invitation.inviteeRole],
|
||||||
|
};
|
||||||
|
|
||||||
|
this.pubsub.publish(`team/${inv.teamID}/invite_added`, inv);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Map to model type
|
||||||
|
TE.map((x) => x as TeamInvitation),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
revokeInvitation(inviteID: string) {
|
||||||
* Revoke a team invitation
|
return pipe(
|
||||||
* @param inviteID invite id
|
// Make sure invite exists
|
||||||
* @returns an Either of true or error message
|
this.getInvitation(inviteID),
|
||||||
*/
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
async revokeInvitation(inviteID: string) {
|
|
||||||
// check if the invite exists
|
|
||||||
const invitation = await this.getInvitation(inviteID);
|
|
||||||
if (O.isNone(invitation)) return E.left(TEAM_INVITE_NO_INVITE_FOUND);
|
|
||||||
|
|
||||||
// delete the invite
|
// Delete team invitation
|
||||||
await this.prisma.teamInvitation.delete({
|
TE.chainTaskK(
|
||||||
|
() => () =>
|
||||||
|
this.prisma.teamInvitation.delete({
|
||||||
where: {
|
where: {
|
||||||
id: inviteID,
|
id: inviteID,
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Emit Pubsub Event
|
||||||
|
TE.chainFirst((invitation) =>
|
||||||
|
TE.fromTask(() =>
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`team/${invitation.value.teamID}/invite_removed`,
|
`team/${invitation.teamID}/invite_removed`,
|
||||||
invitation.value.id,
|
invitation.id,
|
||||||
);
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
return E.right(true);
|
// We are not returning anything
|
||||||
|
TE.map(constVoid),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllInvitationsInTeam(team: Team) {
|
||||||
|
return pipe(
|
||||||
|
() =>
|
||||||
|
this.prisma.teamInvitation.findMany({
|
||||||
|
where: {
|
||||||
|
teamID: team.id,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
T.map((x) => x as TeamInvitation[]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
acceptInvitation(inviteID: string, acceptedBy: User) {
|
||||||
|
return pipe(
|
||||||
|
TE.Do,
|
||||||
|
|
||||||
|
// First get the invitation
|
||||||
|
TE.bindW('invitation', () =>
|
||||||
|
pipe(
|
||||||
|
this.getInvitation(inviteID),
|
||||||
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Validation checks
|
||||||
|
TE.chainFirstW(({ invitation }) =>
|
||||||
|
TE.sequenceArray([
|
||||||
|
// Make sure the invited user is not part of the team
|
||||||
|
pipe(
|
||||||
|
this.teamService.getTeamMemberTE(invitation.teamID, acceptedBy.uid),
|
||||||
|
TE.swap,
|
||||||
|
TE.bimap(
|
||||||
|
() => TEAM_INVITE_ALREADY_MEMBER,
|
||||||
|
constVoid, // The return type is ignored
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Make sure the invited user and accepting user has the same email
|
||||||
|
pipe(
|
||||||
|
undefined,
|
||||||
|
TE.fromPredicate(
|
||||||
|
(a) => acceptedBy.email === invitation.inviteeEmail,
|
||||||
|
() => TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Add the team member
|
||||||
|
// TODO: Somehow bring subscriptions to this ?
|
||||||
|
TE.bindW('teamMember', ({ invitation }) =>
|
||||||
|
pipe(
|
||||||
|
TE.tryCatch(
|
||||||
|
() =>
|
||||||
|
this.teamService.addMemberToTeam(
|
||||||
|
invitation.teamID,
|
||||||
|
acceptedBy.uid,
|
||||||
|
invitation.inviteeRole,
|
||||||
|
),
|
||||||
|
() => TEAM_INVITE_ALREADY_MEMBER, // Can only fail if Team Member already exists, which we checked, but due to async lets assert that here too
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
TE.chainFirstW(({ invitation }) => this.revokeInvitation(invitation.id)),
|
||||||
|
|
||||||
|
TE.map(({ teamMember }) => teamMember),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept a team invitation
|
* Fetch the count invitations for a given team.
|
||||||
* @param inviteID invite id
|
|
||||||
* @param acceptedBy user who accepted the invitation
|
|
||||||
* @returns an Either of team member or error message
|
|
||||||
*/
|
|
||||||
async acceptInvitation(inviteID: string, acceptedBy: AuthUser) {
|
|
||||||
// check if the invite exists
|
|
||||||
const invitation = await this.getInvitation(inviteID);
|
|
||||||
if (O.isNone(invitation)) return E.left(TEAM_INVITE_NO_INVITE_FOUND);
|
|
||||||
|
|
||||||
// make sure the user is not already a member of the team
|
|
||||||
const teamMemberInvitee = await this.teamService.getTeamMember(
|
|
||||||
invitation.value.teamID,
|
|
||||||
acceptedBy.uid,
|
|
||||||
);
|
|
||||||
if (teamMemberInvitee) return E.left(TEAM_INVITE_ALREADY_MEMBER);
|
|
||||||
|
|
||||||
// make sure the user is the same as the invitee
|
|
||||||
if (
|
|
||||||
acceptedBy.email.toLowerCase() !==
|
|
||||||
invitation.value.inviteeEmail.toLowerCase()
|
|
||||||
)
|
|
||||||
return E.left(TEAM_INVITE_EMAIL_DO_NOT_MATCH);
|
|
||||||
|
|
||||||
// add the user to the team
|
|
||||||
let teamMember: TeamMember;
|
|
||||||
try {
|
|
||||||
teamMember = await this.teamService.addMemberToTeam(
|
|
||||||
invitation.value.teamID,
|
|
||||||
acceptedBy.uid,
|
|
||||||
invitation.value.inviteeRole,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
return E.left(TEAM_INVITE_ALREADY_MEMBER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete the invite
|
|
||||||
await this.revokeInvitation(inviteID);
|
|
||||||
|
|
||||||
return E.right(teamMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all team invitations for a given team.
|
|
||||||
* @param teamID team id
|
* @param teamID team id
|
||||||
* @returns array of team invitations for a team
|
* @returns a count team invitations for a team
|
||||||
*/
|
*/
|
||||||
async getTeamInvitations(teamID: string) {
|
async getAllTeamInvitations(teamID: string) {
|
||||||
const dbInvitations = await this.prisma.teamInvitation.findMany({
|
const invitations = await this.prisma.teamInvitation.findMany({
|
||||||
where: {
|
where: {
|
||||||
teamID: teamID,
|
teamID: teamID,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const invitations: TeamInvitation[] = dbInvitations.map((dbInvitation) =>
|
|
||||||
this.cast(dbInvitation),
|
|
||||||
);
|
|
||||||
|
|
||||||
return invitations;
|
return invitations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
|
import { pipe } from 'fp-ts/function';
|
||||||
import { TeamService } from 'src/team/team.service';
|
import { TeamService } from 'src/team/team.service';
|
||||||
import { TeamInvitationService } from './team-invitation.service';
|
import { TeamInvitationService } from './team-invitation.service';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
|
import * as T from 'fp-ts/Task';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||||
import {
|
import {
|
||||||
BUG_AUTH_NO_USER_CTX,
|
BUG_AUTH_NO_USER_CTX,
|
||||||
BUG_TEAM_INVITE_NO_INVITE_ID,
|
BUG_TEAM_INVITE_NO_INVITE_ID,
|
||||||
TEAM_INVITE_NO_INVITE_FOUND,
|
TEAM_INVITE_NO_INVITE_FOUND,
|
||||||
TEAM_MEMBER_NOT_FOUND,
|
|
||||||
TEAM_NOT_REQUIRED_ROLE,
|
TEAM_NOT_REQUIRED_ROLE,
|
||||||
} from 'src/errors';
|
} from 'src/errors';
|
||||||
|
import { User } from 'src/user/user.model';
|
||||||
import { throwErr } from 'src/utils';
|
import { throwErr } from 'src/utils';
|
||||||
import { TeamMemberRole } from 'src/team/team.model';
|
import { TeamMemberRole } from 'src/team/team.model';
|
||||||
|
|
||||||
/**
|
|
||||||
* This guard only allows team owner to execute the resolver
|
|
||||||
*/
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TeamInviteTeamOwnerGuard implements CanActivate {
|
export class TeamInviteTeamOwnerGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -24,30 +24,48 @@ export class TeamInviteTeamOwnerGuard implements CanActivate {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
// Get GQL context
|
return pipe(
|
||||||
const gqlExecCtx = GqlExecutionContext.create(context);
|
TE.Do,
|
||||||
|
|
||||||
// Get user
|
TE.bindW('gqlCtx', () => TE.of(GqlExecutionContext.create(context))),
|
||||||
const { user } = gqlExecCtx.getContext().req;
|
|
||||||
if (!user) throwErr(BUG_AUTH_NO_USER_CTX);
|
|
||||||
|
|
||||||
// Get the invite
|
// Get the invite
|
||||||
const { inviteID } = gqlExecCtx.getArgs<{ inviteID: string }>();
|
TE.bindW('invite', ({ gqlCtx }) =>
|
||||||
if (!inviteID) throwErr(BUG_TEAM_INVITE_NO_INVITE_ID);
|
pipe(
|
||||||
|
O.fromNullable(gqlCtx.getArgs<{ inviteID?: string }>().inviteID),
|
||||||
|
TE.fromOption(() => BUG_TEAM_INVITE_NO_INVITE_ID),
|
||||||
|
TE.chainW((inviteID) =>
|
||||||
|
pipe(
|
||||||
|
this.teamInviteService.getInvitation(inviteID),
|
||||||
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const invitation = await this.teamInviteService.getInvitation(inviteID);
|
TE.bindW('user', ({ gqlCtx }) =>
|
||||||
if (O.isNone(invitation)) throwErr(TEAM_INVITE_NO_INVITE_FOUND);
|
pipe(
|
||||||
|
gqlCtx.getContext().req.user,
|
||||||
|
O.fromNullable,
|
||||||
|
TE.fromOption(() => BUG_AUTH_NO_USER_CTX),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// Fetch team member details of this user
|
TE.bindW('userMember', ({ invite, user }) =>
|
||||||
const teamMember = await this.teamService.getTeamMember(
|
this.teamService.getTeamMemberTE(invite.teamID, user.uid),
|
||||||
invitation.value.teamID,
|
),
|
||||||
user.uid,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!teamMember) throwErr(TEAM_MEMBER_NOT_FOUND);
|
TE.chainW(
|
||||||
if (teamMember.role !== TeamMemberRole.OWNER)
|
TE.fromPredicate(
|
||||||
throwErr(TEAM_NOT_REQUIRED_ROLE);
|
({ userMember }) => userMember.role === TeamMemberRole.OWNER,
|
||||||
|
() => TEAM_NOT_REQUIRED_ROLE,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
return true;
|
TE.fold(
|
||||||
|
(err) => throwErr(err),
|
||||||
|
() => T.of(true),
|
||||||
|
),
|
||||||
|
)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,20 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { TeamInvitationService } from './team-invitation.service';
|
import { TeamInvitationService } from './team-invitation.service';
|
||||||
|
import { pipe, flow } from 'fp-ts/function';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
|
import * as T from 'fp-ts/Task';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||||
import {
|
import {
|
||||||
BUG_AUTH_NO_USER_CTX,
|
BUG_AUTH_NO_USER_CTX,
|
||||||
BUG_TEAM_INVITE_NO_INVITE_ID,
|
BUG_TEAM_INVITE_NO_INVITE_ID,
|
||||||
|
TEAM_INVITE_NOT_VALID_VIEWER,
|
||||||
TEAM_INVITE_NO_INVITE_FOUND,
|
TEAM_INVITE_NO_INVITE_FOUND,
|
||||||
TEAM_MEMBER_NOT_FOUND,
|
|
||||||
} from 'src/errors';
|
} from 'src/errors';
|
||||||
|
import { User } from 'src/user/user.model';
|
||||||
import { throwErr } from 'src/utils';
|
import { throwErr } from 'src/utils';
|
||||||
import { TeamService } from 'src/team/team.service';
|
import { TeamService } from 'src/team/team.service';
|
||||||
|
|
||||||
/**
|
|
||||||
* This guard only allows user to execute the resolver
|
|
||||||
* 1. If user is invitee, allow
|
|
||||||
* 2. Or else, if user is team member, allow
|
|
||||||
*
|
|
||||||
* TLDR: Allow if user is invitee or team member
|
|
||||||
*/
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TeamInviteViewerGuard implements CanActivate {
|
export class TeamInviteViewerGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -26,32 +23,50 @@ export class TeamInviteViewerGuard implements CanActivate {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
// Get GQL context
|
return pipe(
|
||||||
const gqlExecCtx = GqlExecutionContext.create(context);
|
TE.Do,
|
||||||
|
|
||||||
|
// Get GQL Context
|
||||||
|
TE.bindW('gqlCtx', () => TE.of(GqlExecutionContext.create(context))),
|
||||||
|
|
||||||
// Get user
|
// Get user
|
||||||
const { user } = gqlExecCtx.getContext().req;
|
TE.bindW('user', ({ gqlCtx }) =>
|
||||||
if (!user) throwErr(BUG_AUTH_NO_USER_CTX);
|
pipe(
|
||||||
|
O.fromNullable(gqlCtx.getContext().req.user),
|
||||||
|
TE.fromOption(() => BUG_AUTH_NO_USER_CTX),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// Get the invite
|
// Get the invite
|
||||||
const { inviteID } = gqlExecCtx.getArgs<{ inviteID: string }>();
|
TE.bindW('invite', ({ gqlCtx }) =>
|
||||||
if (!inviteID) throwErr(BUG_TEAM_INVITE_NO_INVITE_ID);
|
pipe(
|
||||||
|
O.fromNullable(gqlCtx.getArgs<{ inviteID?: string }>().inviteID),
|
||||||
|
TE.fromOption(() => BUG_TEAM_INVITE_NO_INVITE_ID),
|
||||||
|
TE.chainW(
|
||||||
|
flow(
|
||||||
|
this.teamInviteService.getInvitation,
|
||||||
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const invitation = await this.teamInviteService.getInvitation(inviteID);
|
// Check if the user and the invite email match, else if we can resolver the user as a team member
|
||||||
if (O.isNone(invitation)) throwErr(TEAM_INVITE_NO_INVITE_FOUND);
|
// any better solution ?
|
||||||
|
TE.chainW(({ user, invite }) =>
|
||||||
|
user.email?.toLowerCase() === invite.inviteeEmail.toLowerCase()
|
||||||
|
? TE.of(true)
|
||||||
|
: pipe(
|
||||||
|
this.teamService.getTeamMemberTE(invite.teamID, user.uid),
|
||||||
|
TE.map(() => true),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// Check if the user and the invite email match, else if user is a team member
|
TE.mapLeft((e) =>
|
||||||
if (
|
e === 'team/member_not_found' ? TEAM_INVITE_NOT_VALID_VIEWER : e,
|
||||||
user.email?.toLowerCase() !== invitation.value.inviteeEmail.toLowerCase()
|
),
|
||||||
) {
|
|
||||||
const teamMember = await this.teamService.getTeamMember(
|
|
||||||
invitation.value.teamID,
|
|
||||||
user.uid,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!teamMember) throwErr(TEAM_MEMBER_NOT_FOUND);
|
TE.fold(throwErr, () => T.of(true)),
|
||||||
}
|
)();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { TeamInvitationService } from './team-invitation.service';
|
import { TeamInvitationService } from './team-invitation.service';
|
||||||
|
import { pipe, flow } from 'fp-ts/function';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
|
import * as T from 'fp-ts/Task';
|
||||||
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||||
|
import { User } from 'src/user/user.model';
|
||||||
import {
|
import {
|
||||||
BUG_AUTH_NO_USER_CTX,
|
BUG_AUTH_NO_USER_CTX,
|
||||||
BUG_TEAM_INVITE_NO_INVITE_ID,
|
BUG_TEAM_INVITE_NO_INVITE_ID,
|
||||||
@@ -20,26 +24,44 @@ export class TeamInviteeGuard implements CanActivate {
|
|||||||
constructor(private readonly teamInviteService: TeamInvitationService) {}
|
constructor(private readonly teamInviteService: TeamInvitationService) {}
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
// Get GQL Context
|
return pipe(
|
||||||
const gqlExecCtx = GqlExecutionContext.create(context);
|
TE.Do,
|
||||||
|
|
||||||
|
// Get execution context
|
||||||
|
TE.bindW('gqlCtx', () => TE.of(GqlExecutionContext.create(context))),
|
||||||
|
|
||||||
// Get user
|
// Get user
|
||||||
const { user } = gqlExecCtx.getContext().req;
|
TE.bindW('user', ({ gqlCtx }) =>
|
||||||
if (!user) throwErr(BUG_AUTH_NO_USER_CTX);
|
pipe(
|
||||||
|
O.fromNullable(gqlCtx.getContext().req.user),
|
||||||
|
TE.fromOption(() => BUG_AUTH_NO_USER_CTX),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// Get the invite
|
// Get invite
|
||||||
const { inviteID } = gqlExecCtx.getArgs<{ inviteID: string }>();
|
TE.bindW('invite', ({ gqlCtx }) =>
|
||||||
if (!inviteID) throwErr(BUG_TEAM_INVITE_NO_INVITE_ID);
|
pipe(
|
||||||
|
O.fromNullable(gqlCtx.getArgs<{ inviteID?: string }>().inviteID),
|
||||||
|
TE.fromOption(() => BUG_TEAM_INVITE_NO_INVITE_ID),
|
||||||
|
TE.chainW(
|
||||||
|
flow(
|
||||||
|
this.teamInviteService.getInvitation,
|
||||||
|
TE.fromTaskOption(() => TEAM_INVITE_NO_INVITE_FOUND),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const invitation = await this.teamInviteService.getInvitation(inviteID);
|
// Check if the emails match
|
||||||
if (O.isNone(invitation)) throwErr(TEAM_INVITE_NO_INVITE_FOUND);
|
TE.chainW(
|
||||||
|
TE.fromPredicate(
|
||||||
|
({ user, invite }) => user.email === invite.inviteeEmail,
|
||||||
|
() => TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
if (
|
// Fold it to a promise
|
||||||
user.email.toLowerCase() !== invitation.value.inviteeEmail.toLowerCase()
|
TE.fold(throwErr, () => T.of(true)),
|
||||||
) {
|
)();
|
||||||
throwErr(TEAM_INVITE_EMAIL_DO_NOT_MATCH);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ export class TeamTeamInviteExtResolver {
|
|||||||
complexity: 10,
|
complexity: 10,
|
||||||
})
|
})
|
||||||
teamInvitations(@Parent() team: Team): Promise<TeamInvitation[]> {
|
teamInvitations(@Parent() team: Team): Promise<TeamInvitation[]> {
|
||||||
return this.teamInviteService.getTeamInvitations(team.id);
|
return this.teamInviteService.getAllInvitationsInTeam(team)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-star"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 337 B |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hoppscotch/common",
|
"name": "@hoppscotch/common",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2023.4.7",
|
"version": "2023.4.6",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "pnpm exec npm-run-all -p -l dev:*",
|
"dev": "pnpm exec npm-run-all -p -l dev:*",
|
||||||
"dev:vite": "vite",
|
"dev:vite": "vite",
|
||||||
|
|||||||
@@ -44,9 +44,8 @@
|
|||||||
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
|
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
|
||||||
>
|
>
|
||||||
<icon-lucide-search class="pb-2 opacity-75 svg-icons" />
|
<icon-lucide-search class="pb-2 opacity-75 svg-icons" />
|
||||||
<span class="my-2 text-center flex flex-col">
|
<span class="my-2 text-center">
|
||||||
{{ t("state.nothing_found") }}
|
{{ t("state.nothing_found") }} "{{ filterText }}"
|
||||||
<span class="break-all">"{{ filterText }}"</span>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -284,14 +284,6 @@ const importerAction = async (stepResults: StepReturnValue[]) => {
|
|||||||
emit("import-to-teams", result)
|
emit("import-to-teams", result)
|
||||||
} else {
|
} else {
|
||||||
appendRESTCollections(result)
|
appendRESTCollections(result)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_IMPORT_COLLECTION",
|
|
||||||
importer: importerModule.value!.name,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
fileImported()
|
fileImported()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1 bg-primaryContrast">
|
||||||
<div
|
<div
|
||||||
class="sticky z-10 flex justify-between flex-1 border-b bg-primary border-dividerLight"
|
class="sticky z-10 flex justify-between flex-1 border-b bg-primary border-dividerLight"
|
||||||
:style="
|
:style="
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ import {
|
|||||||
import { GQLError } from "~/helpers/backend/GQLClient"
|
import { GQLError } from "~/helpers/backend/GQLClient"
|
||||||
import { computedWithControl } from "@vueuse/core"
|
import { computedWithControl } from "@vueuse/core"
|
||||||
import { currentActiveTab } from "~/helpers/rest/tab"
|
import { currentActiveTab } from "~/helpers/rest/tab"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -224,13 +223,6 @@ const saveRequestAs = async () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "my-folder") {
|
} else if (picked.value.pickedType === "my-folder") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(requestUpdated))
|
||||||
@@ -251,13 +243,6 @@ const saveRequestAs = async () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "my-request") {
|
} else if (picked.value.pickedType === "my-request") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(requestUpdated))
|
||||||
@@ -279,38 +264,17 @@ const saveRequestAs = async () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: false,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "teams-collection") {
|
} else if (picked.value.pickedType === "teams-collection") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(requestUpdated))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
updateTeamCollectionOrFolder(picked.value.collectionID, requestUpdated)
|
updateTeamCollectionOrFolder(picked.value.collectionID, requestUpdated)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
} else if (picked.value.pickedType === "teams-folder") {
|
} else if (picked.value.pickedType === "teams-folder") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(requestUpdated))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
updateTeamCollectionOrFolder(picked.value.folderID, requestUpdated)
|
updateTeamCollectionOrFolder(picked.value.folderID, requestUpdated)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
} else if (picked.value.pickedType === "teams-request") {
|
} else if (picked.value.pickedType === "teams-request") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(requestUpdated))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
@@ -328,13 +292,6 @@ const saveRequestAs = async () => {
|
|||||||
title: requestUpdated.name,
|
title: requestUpdated.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: false,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
updateTeamRequest(picked.value.requestID, data),
|
updateTeamRequest(picked.value.requestID, data),
|
||||||
TE.match(
|
TE.match(
|
||||||
@@ -356,13 +313,6 @@ const saveRequestAs = async () => {
|
|||||||
requestUpdated as HoppGQLRequest
|
requestUpdated as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: false,
|
|
||||||
platform: "gql",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "gql-my-folder") {
|
} else if (picked.value.pickedType === "gql-my-folder") {
|
||||||
// TODO: Check for GQL request ?
|
// TODO: Check for GQL request ?
|
||||||
@@ -371,13 +321,6 @@ const saveRequestAs = async () => {
|
|||||||
requestUpdated as HoppGQLRequest
|
requestUpdated as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "gql",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "gql-my-collection") {
|
} else if (picked.value.pickedType === "gql-my-collection") {
|
||||||
// TODO: Check for GQL request ?
|
// TODO: Check for GQL request ?
|
||||||
@@ -386,13 +329,6 @@ const saveRequestAs = async () => {
|
|||||||
requestUpdated as HoppGQLRequest
|
requestUpdated as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "gql",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1 bg-primaryContrast">
|
||||||
<div
|
<div
|
||||||
class="sticky z-10 flex justify-between flex-1 border-b bg-primary border-dividerLight"
|
class="sticky z-10 flex justify-between flex-1 border-b bg-primary border-dividerLight"
|
||||||
:style="
|
:style="
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import { useToast } from "@composables/toast"
|
|||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { HoppGQLRequest, makeCollection } from "@hoppscotch/data"
|
import { HoppGQLRequest, makeCollection } from "@hoppscotch/data"
|
||||||
import { addGraphqlCollection } from "~/newstore/collections"
|
import { addGraphqlCollection } from "~/newstore/collections"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
@@ -80,13 +79,6 @@ export default defineComponent({
|
|||||||
)
|
)
|
||||||
|
|
||||||
this.hideModal()
|
this.hideModal()
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
isRootCollection: true,
|
|
||||||
platform: "gql",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
hideModal() {
|
hideModal() {
|
||||||
this.name = null
|
this.name = null
|
||||||
|
|||||||
@@ -244,14 +244,6 @@ const importFromJSON = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
appendGraphqlCollections(collections)
|
appendGraphqlCollections(collections)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_IMPORT_COLLECTION",
|
|
||||||
importer: "json",
|
|
||||||
workspaceType: "personal",
|
|
||||||
platform: "gql",
|
|
||||||
})
|
|
||||||
|
|
||||||
fileImported()
|
fileImported()
|
||||||
}
|
}
|
||||||
reader.readAsText(inputChooseFileToImportFrom.value.files[0])
|
reader.readAsText(inputChooseFileToImportFrom.value.files[0])
|
||||||
@@ -265,12 +257,6 @@ const exportJSON = () => {
|
|||||||
const url = URL.createObjectURL(file)
|
const url = URL.createObjectURL(file)
|
||||||
a.href = url
|
a.href = url
|
||||||
|
|
||||||
platform?.analytics?.logEvent({
|
|
||||||
type: "HOPP_EXPORT_COLLECTION",
|
|
||||||
exporter: "json",
|
|
||||||
platform: "gql",
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO: get uri from meta
|
// TODO: get uri from meta
|
||||||
a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}.json`
|
a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}.json`
|
||||||
document.body.appendChild(a)
|
document.body.appendChild(a)
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ import IconArchive from "~icons/lucide/archive"
|
|||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useReadonlyStream } from "@composables/stream"
|
import { useReadonlyStream } from "@composables/stream"
|
||||||
import { useColorMode } from "@composables/theming"
|
import { useColorMode } from "@composables/theming"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
@@ -286,13 +285,6 @@ export default defineComponent({
|
|||||||
response: "",
|
response: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
platform: "gql",
|
|
||||||
createdNow: true,
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
this.displayModalAddRequest(false)
|
this.displayModalAddRequest(false)
|
||||||
},
|
},
|
||||||
addRequest(payload) {
|
addRequest(payload) {
|
||||||
@@ -302,14 +294,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
onAddFolder({ name, path }) {
|
onAddFolder({ name, path }) {
|
||||||
addGraphqlFolder(name, path)
|
addGraphqlFolder(name, path)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
isRootCollection: false,
|
|
||||||
platform: "gql",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
this.displayModalAddFolder(false)
|
this.displayModalAddFolder(false)
|
||||||
},
|
},
|
||||||
addFolder(payload) {
|
addFolder(payload) {
|
||||||
|
|||||||
@@ -599,25 +599,11 @@ const addNewRootCollection = (name: string) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
isRootCollection: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
displayModalAdd(false)
|
displayModalAdd(false)
|
||||||
} else if (hasTeamWriteAccess.value) {
|
} else if (hasTeamWriteAccess.value) {
|
||||||
if (!collectionsType.value.selectedTeam) return
|
if (!collectionsType.value.selectedTeam) return
|
||||||
modalLoadingState.value = true
|
modalLoadingState.value = true
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "team",
|
|
||||||
isRootCollection: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
createNewRootCollection(name, collectionsType.value.selectedTeam.id),
|
createNewRootCollection(name, collectionsType.value.selectedTeam.id),
|
||||||
TE.match(
|
TE.match(
|
||||||
@@ -666,13 +652,6 @@ const onAddRequest = (requestName: string) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
workspaceType: "personal",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
displayModalAddRequest(false)
|
displayModalAddRequest(false)
|
||||||
} else if (hasTeamWriteAccess.value) {
|
} else if (hasTeamWriteAccess.value) {
|
||||||
const folder = editingFolder.value
|
const folder = editingFolder.value
|
||||||
@@ -688,13 +667,6 @@ const onAddRequest = (requestName: string) => {
|
|||||||
title: requestName,
|
title: requestName,
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
workspaceType: "team",
|
|
||||||
platform: "rest",
|
|
||||||
createdNow: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
createRequestInCollection(folder.id, data),
|
createRequestInCollection(folder.id, data),
|
||||||
TE.match(
|
TE.match(
|
||||||
@@ -740,14 +712,6 @@ const onAddFolder = (folderName: string) => {
|
|||||||
if (collectionsType.value.type === "my-collections") {
|
if (collectionsType.value.type === "my-collections") {
|
||||||
if (!path) return
|
if (!path) return
|
||||||
addRESTFolder(folderName, path)
|
addRESTFolder(folderName, path)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
workspaceType: "personal",
|
|
||||||
isRootCollection: false,
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
displayModalAddFolder(false)
|
displayModalAddFolder(false)
|
||||||
} else if (hasTeamWriteAccess.value) {
|
} else if (hasTeamWriteAccess.value) {
|
||||||
const folder = editingFolder.value
|
const folder = editingFolder.value
|
||||||
@@ -755,13 +719,6 @@ const onAddFolder = (folderName: string) => {
|
|||||||
|
|
||||||
modalLoadingState.value = true
|
modalLoadingState.value = true
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
|
||||||
workspaceType: "personal",
|
|
||||||
isRootCollection: false,
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
createChildCollection(folderName, folder.id),
|
createChildCollection(folderName, folder.id),
|
||||||
TE.match(
|
TE.match(
|
||||||
@@ -1927,12 +1884,6 @@ const exportData = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportJSONCollection = async () => {
|
const exportJSONCollection = async () => {
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_EXPORT_COLLECTION",
|
|
||||||
exporter: "json",
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
await getJSONCollection()
|
await getJSONCollection()
|
||||||
|
|
||||||
initializeDownloadCollection(collectionJSON.value, null)
|
initializeDownloadCollection(collectionJSON.value, null)
|
||||||
@@ -1944,12 +1895,6 @@ const createCollectionGist = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_EXPORT_COLLECTION",
|
|
||||||
exporter: "gist",
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
creatingGistCollection.value = true
|
creatingGistCollection.value = true
|
||||||
await getJSONCollection()
|
await getJSONCollection()
|
||||||
|
|
||||||
@@ -1980,12 +1925,6 @@ const importToTeams = async (collection: HoppCollection<HoppRESTRequest>[]) => {
|
|||||||
|
|
||||||
importingMyCollections.value = true
|
importingMyCollections.value = true
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_EXPORT_COLLECTION",
|
|
||||||
exporter: "import-to-teams",
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
importJSONToTeam(
|
importJSONToTeam(
|
||||||
JSON.stringify(collection),
|
JSON.stringify(collection),
|
||||||
|
|||||||
@@ -190,12 +190,6 @@ const createEnvironmentGist = async () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
toast.success(t("export.gist_created").toString())
|
toast.success(t("export.gist_created").toString())
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_EXPORT_ENVIRONMENT",
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
window.open(res.data.html_url)
|
window.open(res.data.html_url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(t("error.something_went_wrong").toString())
|
toast.error(t("error.something_went_wrong").toString())
|
||||||
@@ -255,13 +249,6 @@ const openDialogChooseFileToImportFrom = () => {
|
|||||||
|
|
||||||
const importToTeams = async (content: Environment[]) => {
|
const importToTeams = async (content: Environment[]) => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_IMPORT_ENVIRONMENT",
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const [i, env] of content.entries()) {
|
for (const [i, env] of content.entries()) {
|
||||||
if (i === content.length - 1) {
|
if (i === content.length - 1) {
|
||||||
await pipe(
|
await pipe(
|
||||||
@@ -314,12 +301,6 @@ const importFromJSON = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_IMPORT_ENVIRONMENT",
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
|
|
||||||
reader.onload = ({ target }) => {
|
reader.onload = ({ target }) => {
|
||||||
@@ -371,7 +352,6 @@ const importFromPostman = ({
|
|||||||
const environment: Environment = { name, variables: [] }
|
const environment: Environment = { name, variables: [] }
|
||||||
values.forEach(({ key, value }) => environment.variables.push({ key, value }))
|
values.forEach(({ key, value }) => environment.variables.push({ key, value }))
|
||||||
const environments = [environment]
|
const environments = [environment]
|
||||||
|
|
||||||
importFromHoppscotch(environments)
|
importFromHoppscotch(environments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ import { useToast } from "@composables/toast"
|
|||||||
import { useReadonlyStream } from "@composables/stream"
|
import { useReadonlyStream } from "@composables/stream"
|
||||||
import { useColorMode } from "@composables/theming"
|
import { useColorMode } from "@composables/theming"
|
||||||
import { environmentsStore } from "~/newstore/environments"
|
import { environmentsStore } from "~/newstore/environments"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
type EnvironmentVariable = {
|
type EnvironmentVariable = {
|
||||||
id: number
|
id: number
|
||||||
@@ -312,11 +311,6 @@ const saveEnvironment = () => {
|
|||||||
index: envList.value.length - 1,
|
index: envList.value.length - 1,
|
||||||
})
|
})
|
||||||
toast.success(`${t("environment.created")}`)
|
toast.success(`${t("environment.created")}`)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_ENVIRONMENT",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
} else if (props.editingEnvironmentIndex === "Global") {
|
} else if (props.editingEnvironmentIndex === "Global") {
|
||||||
// Editing the Global environment
|
// Editing the Global environment
|
||||||
setGlobalEnvVariables(environmentUpdated.variables)
|
setGlobalEnvVariables(environmentUpdated.variables)
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ import IconTrash from "~icons/lucide/trash"
|
|||||||
import IconTrash2 from "~icons/lucide/trash-2"
|
import IconTrash2 from "~icons/lucide/trash-2"
|
||||||
import IconDone from "~icons/lucide/check"
|
import IconDone from "~icons/lucide/check"
|
||||||
import IconPlus from "~icons/lucide/plus"
|
import IconPlus from "~icons/lucide/plus"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
type EnvironmentVariable = {
|
type EnvironmentVariable = {
|
||||||
id: number
|
id: number
|
||||||
@@ -295,11 +294,6 @@ const saveEnvironment = async () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (props.action === "new") {
|
if (props.action === "new") {
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_ENVIRONMENT",
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
createTeamEnvironment(
|
createTeamEnvironment(
|
||||||
JSON.stringify(filterdVariables),
|
JSON.stringify(filterdVariables),
|
||||||
|
|||||||
@@ -142,15 +142,15 @@
|
|||||||
<div v-if="authType === 'basic'">
|
<div v-if="authType === 'basic'">
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="basicUsername"
|
v-model="basicUsername"
|
||||||
:environment-highlights="false"
|
|
||||||
:placeholder="t('authorization.username')"
|
:placeholder="t('authorization.username')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="basicPassword"
|
v-model="basicPassword"
|
||||||
:environment-highlights="false"
|
|
||||||
:placeholder="t('authorization.password')"
|
:placeholder="t('authorization.password')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -158,8 +158,8 @@
|
|||||||
<div v-if="authType === 'bearer'">
|
<div v-if="authType === 'bearer'">
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="bearerToken"
|
v-model="bearerToken"
|
||||||
:environment-highlights="false"
|
|
||||||
placeholder="Token"
|
placeholder="Token"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -167,8 +167,8 @@
|
|||||||
<div v-if="authType === 'oauth-2'">
|
<div v-if="authType === 'oauth-2'">
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="oauth2Token"
|
v-model="oauth2Token"
|
||||||
:environment-highlights="false"
|
|
||||||
placeholder="Token"
|
placeholder="Token"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -177,15 +177,15 @@
|
|||||||
<div v-if="authType === 'api-key'">
|
<div v-if="authType === 'api-key'">
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="apiKey"
|
v-model="apiKey"
|
||||||
:environment-highlights="false"
|
|
||||||
placeholder="Key"
|
placeholder="Key"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-1 border-b border-dividerLight">
|
<div class="flex flex-1 border-b border-dividerLight">
|
||||||
<SmartEnvInput
|
<SmartEnvInput
|
||||||
|
:environmentHighlights="false"
|
||||||
v-model="apiValue"
|
v-model="apiValue"
|
||||||
:environment-highlights="false"
|
|
||||||
placeholder="Value"
|
placeholder="Value"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ const onConnectClick = () => {
|
|||||||
if (!connected.value) {
|
if (!connected.value) {
|
||||||
props.conn.connect(url.value, headers.value as any, auth.value)
|
props.conn.connect(url.value, headers.value as any, auth.value)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "graphql-schema",
|
platform: "graphql-schema",
|
||||||
strategy: getCurrentStrategyID(),
|
strategy: getCurrentStrategyID(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -748,8 +748,7 @@ const runQuery = async () => {
|
|||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "graphql-query",
|
platform: "graphql-query",
|
||||||
strategy: getCurrentStrategyID(),
|
strategy: getCurrentStrategyID(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ import { GQLHistoryEntry } from "~/newstore/history"
|
|||||||
import { shortDateTime } from "~/helpers/utils/date"
|
import { shortDateTime } from "~/helpers/utils/date"
|
||||||
|
|
||||||
import IconStar from "~icons/lucide/star"
|
import IconStar from "~icons/lucide/star"
|
||||||
import IconStarOff from "~icons/hopp/star-off"
|
import IconStarOff from "~icons/lucide/star-off"
|
||||||
import IconTrash from "~icons/lucide/trash"
|
import IconTrash from "~icons/lucide/trash"
|
||||||
import IconMinimize2 from "~icons/lucide/minimize-2"
|
import IconMinimize2 from "~icons/lucide/minimize-2"
|
||||||
import IconMaximize2 from "~icons/lucide/maximize-2"
|
import IconMaximize2 from "~icons/lucide/maximize-2"
|
||||||
|
|||||||
@@ -72,11 +72,9 @@
|
|||||||
class="flex items-center justify-between flex-1 min-w-0 transition cursor-pointer focus:outline-none text-secondaryLight text-tiny group"
|
class="flex items-center justify-between flex-1 min-w-0 transition cursor-pointer focus:outline-none text-secondaryLight text-tiny group"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="inline-flex items-center justify-center px-4 py-2 transition group-hover:text-secondary truncate"
|
class="inline-flex items-center justify-center px-4 py-2 transition group-hover:text-secondary"
|
||||||
>
|
>
|
||||||
<icon-lucide-chevron-right
|
<icon-lucide-chevron-right class="mr-2 indicator" />
|
||||||
class="mr-2 indicator flex flex-shrink-0"
|
|
||||||
/>
|
|
||||||
<span
|
<span
|
||||||
:class="[
|
:class="[
|
||||||
{ 'capitalize-first': groupSelection === 'TIME' },
|
{ 'capitalize-first': groupSelection === 'TIME' },
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ import { RESTHistoryEntry } from "~/newstore/history"
|
|||||||
import { shortDateTime } from "~/helpers/utils/date"
|
import { shortDateTime } from "~/helpers/utils/date"
|
||||||
|
|
||||||
import IconStar from "~icons/lucide/star"
|
import IconStar from "~icons/lucide/star"
|
||||||
import IconStarOff from "~icons/hopp/star-off"
|
import IconStarOff from "~icons/lucide/star-off"
|
||||||
import IconTrash from "~icons/lucide/trash"
|
import IconTrash from "~icons/lucide/trash"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|||||||
@@ -165,7 +165,6 @@ import IconCheck from "~icons/lucide/check"
|
|||||||
import IconWrapText from "~icons/lucide/wrap-text"
|
import IconWrapText from "~icons/lucide/wrap-text"
|
||||||
import { currentActiveTab } from "~/helpers/rest/tab"
|
import { currentActiveTab } from "~/helpers/rest/tab"
|
||||||
import cloneDeep from "lodash-es/cloneDeep"
|
import cloneDeep from "lodash-es/cloneDeep"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
|
||||||
@@ -249,10 +248,6 @@ watch(
|
|||||||
(goingToShow) => {
|
(goingToShow) => {
|
||||||
if (goingToShow) {
|
if (goingToShow) {
|
||||||
request.value = cloneDeep(currentActiveTab.value.document.request)
|
request.value = cloneDeep(currentActiveTab.value.document.request)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_REST_CODEGEN_OPENED",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ watch(workingHeaders, (headersList) => {
|
|||||||
|
|
||||||
// Sync logic between headers and working/bulk headers
|
// Sync logic between headers and working/bulk headers
|
||||||
watch(
|
watch(
|
||||||
() => request.value.headers,
|
request.value.headers,
|
||||||
(newHeadersList) => {
|
(newHeadersList) => {
|
||||||
// Sync should overwrite working headers
|
// Sync should overwrite working headers
|
||||||
const filteredWorkingHeaders = pipe(
|
const filteredWorkingHeaders = pipe(
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ import IconClipboard from "~icons/lucide/clipboard"
|
|||||||
import IconCheck from "~icons/lucide/check"
|
import IconCheck from "~icons/lucide/check"
|
||||||
import IconTrash2 from "~icons/lucide/trash-2"
|
import IconTrash2 from "~icons/lucide/trash-2"
|
||||||
import { currentActiveTab } from "~/helpers/rest/tab"
|
import { currentActiveTab } from "~/helpers/rest/tab"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
|
||||||
@@ -145,10 +144,6 @@ const handleImport = () => {
|
|||||||
try {
|
try {
|
||||||
const req = parseCurlToHoppRESTReq(text)
|
const req = parseCurlToHoppRESTReq(text)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_REST_IMPORT_CURL",
|
|
||||||
})
|
|
||||||
|
|
||||||
currentActiveTab.value.document.request = req
|
currentActiveTab.value.document.request = req
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
@@ -324,8 +324,7 @@ const newSendRequest = async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
// Log the request run into analytics
|
// Log the request run into analytics
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "rest",
|
platform: "rest",
|
||||||
strategy: getCurrentStrategyID(),
|
strategy: getCurrentStrategyID(),
|
||||||
})
|
})
|
||||||
@@ -447,11 +446,6 @@ const copyRequest = async () => {
|
|||||||
shareLink.value = ""
|
shareLink.value = ""
|
||||||
fetchingShareLink.value = true
|
fetchingShareLink.value = true
|
||||||
const shortcodeResult = await createShortcode(tab.value.document.request)()
|
const shortcodeResult = await createShortcode(tab.value.document.request)()
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SHORTCODE_CREATED",
|
|
||||||
})
|
|
||||||
|
|
||||||
if (E.isLeft(shortcodeResult)) {
|
if (E.isLeft(shortcodeResult)) {
|
||||||
toast.error(`${shortcodeResult.left.error}`)
|
toast.error(`${shortcodeResult.left.error}`)
|
||||||
shareLink.value = `${t("error.something_went_wrong")}`
|
shareLink.value = `${t("error.something_went_wrong")}`
|
||||||
@@ -522,14 +516,6 @@ const saveRequest = () => {
|
|||||||
editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, req)
|
editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, req)
|
||||||
|
|
||||||
tab.value.document.isDirty = false
|
tab.value.document.isDirty = false
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
platform: "rest",
|
|
||||||
createdNow: false,
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
toast.success(`${t("request.saved")}`)
|
toast.success(`${t("request.saved")}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tab.value.document.saveContext = undefined
|
tab.value.document.saveContext = undefined
|
||||||
@@ -540,13 +526,6 @@ const saveRequest = () => {
|
|||||||
|
|
||||||
// TODO: handle error case (NOTE: overwriteRequestTeams is async)
|
// TODO: handle error case (NOTE: overwriteRequestTeams is async)
|
||||||
try {
|
try {
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
platform: "rest",
|
|
||||||
createdNow: false,
|
|
||||||
workspaceType: "team",
|
|
||||||
})
|
|
||||||
|
|
||||||
runMutation(UpdateRequestDocument, {
|
runMutation(UpdateRequestDocument, {
|
||||||
requestID: saveCtx.requestID,
|
requestID: saveCtx.requestID,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -54,8 +54,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { useVModel } from "@vueuse/core"
|
import { computed, ref, watch } from "vue"
|
||||||
import { computed, ref } from "vue"
|
|
||||||
|
|
||||||
export type RequestOptionTabs =
|
export type RequestOptionTabs =
|
||||||
| "params"
|
| "params"
|
||||||
@@ -71,7 +70,15 @@ const emit = defineEmits<{
|
|||||||
(e: "update:modelValue", value: HoppRESTRequest): void
|
(e: "update:modelValue", value: HoppRESTRequest): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const request = useVModel(props, "modelValue", emit)
|
const request = ref(props.modelValue)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => request.value,
|
||||||
|
(newVal) => {
|
||||||
|
emit("update:modelValue", newVal)
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
const selectedRealtimeTab = ref<RequestOptionTabs>("params")
|
const selectedRealtimeTab = ref<RequestOptionTabs>("params")
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,9 @@
|
|||||||
class="flex items-center justify-between flex-1 min-w-0 transition cursor-pointer focus:outline-none text-secondaryLight text-tiny group"
|
class="flex items-center justify-between flex-1 min-w-0 transition cursor-pointer focus:outline-none text-secondaryLight text-tiny group"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="inline-flex items-center justify-center px-4 py-2 transition group-hover:text-secondary truncate"
|
class="inline-flex items-center justify-center px-4 py-2 transition group-hover:text-secondary"
|
||||||
>
|
>
|
||||||
<icon-lucide-chevron-right
|
<icon-lucide-chevron-right class="mr-2 indicator" />
|
||||||
class="mr-2 indicator flex flex-shrink-0"
|
|
||||||
/>
|
|
||||||
<span class="truncate capitalize-first">
|
<span class="truncate capitalize-first">
|
||||||
{{ t("environment.title") }}
|
{{ t("environment.title") }}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import { createTeam } from "~/helpers/backend/mutations/Team"
|
|||||||
import { TeamNameCodec } from "~/helpers/backend/types/TeamName"
|
import { TeamNameCodec } from "~/helpers/backend/types/TeamName"
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
|
||||||
@@ -69,12 +68,6 @@ const addNewTeam = async () => {
|
|||||||
TE.fromEither,
|
TE.fromEither,
|
||||||
TE.mapLeft(() => "invalid_name" as const),
|
TE.mapLeft(() => "invalid_name" as const),
|
||||||
TE.chainW(createTeam),
|
TE.chainW(createTeam),
|
||||||
TE.chainFirstIOK(
|
|
||||||
() => () =>
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_CREATE_TEAM",
|
|
||||||
})
|
|
||||||
),
|
|
||||||
TE.match(
|
TE.match(
|
||||||
(err) => {
|
(err) => {
|
||||||
// err is of type "invalid_name" | GQLError<Err>
|
// err is of type "invalid_name" | GQLError<Err>
|
||||||
|
|||||||
@@ -71,11 +71,9 @@ const parseURL = (urlText: string | number) =>
|
|||||||
* @returns URL object
|
* @returns URL object
|
||||||
*/
|
*/
|
||||||
export function getURLObject(parsedArguments: parser.Arguments) {
|
export function getURLObject(parsedArguments: parser.Arguments) {
|
||||||
const location = parsedArguments.location ?? undefined
|
|
||||||
|
|
||||||
return pipe(
|
return pipe(
|
||||||
// contains raw url strings
|
// contains raw url strings
|
||||||
[...parsedArguments._.slice(1), location],
|
parsedArguments._.slice(1),
|
||||||
A.findFirstMap(parseURL),
|
A.findFirstMap(parseURL),
|
||||||
// no url found
|
// no url found
|
||||||
O.getOrElse(() => new URL(defaultRESTReq.endpoint))
|
O.getOrElse(() => new URL(defaultRESTReq.endpoint))
|
||||||
|
|||||||
@@ -105,8 +105,7 @@ export class MQTTConnection {
|
|||||||
this.handleError(e)
|
this.handleError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "mqtt",
|
platform: "mqtt",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,7 @@ export class SIOConnection {
|
|||||||
this.handleError(error, "CONNECTION")
|
this.handleError(error, "CONNECTION")
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "socketio",
|
platform: "socketio",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ export class SSEConnection {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "sse",
|
platform: "sse",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ export class WSConnection {
|
|||||||
this.handleError(error as SyntaxError)
|
this.handleError(error as SyntaxError)
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logHoppRequestRunToAnalytics({
|
||||||
type: "HOPP_REQUEST_RUN",
|
|
||||||
platform: "wss",
|
platform: "wss",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { refWithControl } from "@vueuse/core"
|
|||||||
import { HoppRESTResponse } from "../types/HoppRESTResponse"
|
import { HoppRESTResponse } from "../types/HoppRESTResponse"
|
||||||
import { getDefaultRESTRequest } from "./default"
|
import { getDefaultRESTRequest } from "./default"
|
||||||
import { HoppTestResult } from "../types/HoppTestResult"
|
import { HoppTestResult } from "../types/HoppTestResult"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
export type HoppRESTTab = {
|
export type HoppRESTTab = {
|
||||||
id: string
|
id: string
|
||||||
@@ -148,10 +147,6 @@ export function createNewTab(document: HoppRESTDocument, switchToIt = true) {
|
|||||||
currentTabID.value = id
|
currentTabID.value = id
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_REST_NEW_TAB_OPENED",
|
|
||||||
})
|
|
||||||
|
|
||||||
return tab
|
return tab
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ import IconHome from "~icons/lucide/home"
|
|||||||
import IconRefreshCW from "~icons/lucide/refresh-cw"
|
import IconRefreshCW from "~icons/lucide/refresh-cw"
|
||||||
import { createNewTab } from "~/helpers/rest/tab"
|
import { createNewTab } from "~/helpers/rest/tab"
|
||||||
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -121,10 +120,6 @@ const addRequestToTab = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SHORTCODE_RESOLVED",
|
|
||||||
})
|
|
||||||
|
|
||||||
const request: unknown = JSON.parse(data.right.shortcode?.request as string)
|
const request: unknown = JSON.parse(data.right.shortcode?.request as string)
|
||||||
|
|
||||||
createNewTab({
|
createNewTab({
|
||||||
|
|||||||
@@ -5,50 +5,8 @@ export type HoppRequestEvent =
|
|||||||
}
|
}
|
||||||
| { platform: "wss" | "sse" | "socketio" | "mqtt" }
|
| { platform: "wss" | "sse" | "socketio" | "mqtt" }
|
||||||
|
|
||||||
export type AnalyticsEvent =
|
|
||||||
| ({ type: "HOPP_REQUEST_RUN" } & HoppRequestEvent)
|
|
||||||
| {
|
|
||||||
type: "HOPP_CREATE_ENVIRONMENT"
|
|
||||||
workspaceType: "personal" | "team"
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "HOPP_CREATE_COLLECTION"
|
|
||||||
platform: "rest" | "gql"
|
|
||||||
isRootCollection: boolean
|
|
||||||
workspaceType: "personal" | "team"
|
|
||||||
}
|
|
||||||
| { type: "HOPP_CREATE_TEAM" }
|
|
||||||
| {
|
|
||||||
type: "HOPP_SAVE_REQUEST"
|
|
||||||
createdNow: boolean
|
|
||||||
workspaceType: "personal" | "team"
|
|
||||||
platform: "rest" | "gql"
|
|
||||||
}
|
|
||||||
| { type: "HOPP_SHORTCODE_CREATED" }
|
|
||||||
| { type: "HOPP_SHORTCODE_RESOLVED" }
|
|
||||||
| { type: "HOPP_REST_NEW_TAB_OPENED" }
|
|
||||||
| {
|
|
||||||
type: "HOPP_IMPORT_COLLECTION"
|
|
||||||
importer: string
|
|
||||||
workspaceType: "personal" | "team"
|
|
||||||
platform: "rest" | "gql"
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "HOPP_IMPORT_ENVIRONMENT"
|
|
||||||
workspaceType: "personal" | "team"
|
|
||||||
platform: "rest" | "gql"
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "HOPP_EXPORT_COLLECTION"
|
|
||||||
exporter: string
|
|
||||||
platform: "rest" | "gql"
|
|
||||||
}
|
|
||||||
| { type: "HOPP_EXPORT_ENVIRONMENT"; platform: "rest" | "gql" }
|
|
||||||
| { type: "HOPP_REST_CODEGEN_OPENED" }
|
|
||||||
| { type: "HOPP_REST_IMPORT_CURL" }
|
|
||||||
|
|
||||||
export type AnalyticsPlatformDef = {
|
export type AnalyticsPlatformDef = {
|
||||||
initAnalytics: () => void
|
initAnalytics: () => void
|
||||||
logEvent: (ev: AnalyticsEvent) => void
|
logHoppRequestRunToAnalytics: (ev: HoppRequestEvent) => void
|
||||||
logPageView: (pagePath: string) => void
|
logPageView: (pagePath: string) => void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hoppscotch/selfhost-web",
|
"name": "@hoppscotch/selfhost-web",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2023.4.7",
|
"version": "2023.4.6",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev:vite": "vite",
|
"dev:vite": "vite",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "hoppscotch-sh-admin",
|
"name": "hoppscotch-sh-admin",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2023.4.7",
|
"version": "2023.4.6",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "pnpm exec npm-run-all -p -l dev:*",
|
"dev": "pnpm exec npm-run-all -p -l dev:*",
|
||||||
|
|||||||
Reference in New Issue
Block a user