Skip to content

Commit

Permalink
Feat: bugs (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmullapudi authored Jul 9, 2023
1 parent c2468a3 commit 973127a
Show file tree
Hide file tree
Showing 64 changed files with 3,871 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ JWT_ACCESS_SECRET=nestjsPrismaAccessSecret
JWT_REFRESH_SECRET=nestjsPrismaRefreshSecret

FRONTEND_HOST=http://localhost:8000
PUBLIC_FRONTEND_HOST=https://app.poozle.dev
BACKEND_HOST=http://localhost:3000

BACKEND_URL=http://server:3000

SUPERTOKEN_CONNECTION_URI=http://supertokens:3567
3 changes: 3 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- ENGINE_VERSION=${ENGINE_VERSION}
- DATABASE_URL=${DATABASE_URL}
- FRONTEND_HOST=${FRONTEND_HOST}
- PUBLIC_FRONTEND_HOST=${PUBLIC_FRONTEND_HOST}
- BACKEND_HOST=${BACKEND_HOST}
- JWT_ACCESS_SECRET=${JWT_ACCESS_SECRET}
- JWT_REFRESH_SECRET=${JWT_REFRESH_SECRET}
Expand All @@ -54,6 +55,8 @@ services:
- db
environment:
POSTGRESQL_CONNECTION_URI: ${SUPERTOKEN_DATABASE_URL}
ports:
- 3567:3567
networks:
- poozle
restart: unless-stopped
Expand Down
6 changes: 4 additions & 2 deletions engine-idk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poozle/engine-idk",
"version": "0.1.8",
"version": "0.1.9",
"description": "Used to develop integrations for Poozle",
"license": "MIT",
"author": "Poozle <support@poozle.in>",
Expand All @@ -16,7 +16,8 @@
"node": ">=10"
},
"dependencies": {
"axios": "^1.3.2"
"axios": "^1.3.2",
"qs": "^6.11.2"
},
"devDependencies": {
"@babel/core": "^7.18.2",
Expand All @@ -27,6 +28,7 @@
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "5.48.2",
"@typescript-eslint/parser": "5.48.2",
"eslint": "^8.31.0",
Expand Down
8 changes: 7 additions & 1 deletion engine-idk/src/utils/oAuthUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

import axios from 'axios';
import qs from 'qs';

/**
* A helper function to interpolate a string.
Expand All @@ -18,10 +19,15 @@ export function interpolateString(str: string, replacers: Record<string, any>) {
}

export async function getAccessToken(url: string, data: Record<string, string>) {
const parsedData = qs.stringify({ ...data, grant_type: 'refresh_token' });

const response = await axios({
method: 'POST',
url,
data: { ...data, grant_type: 'refresh_token' },
data: parsedData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});

return response.data.access_token;
Expand Down
12 changes: 12 additions & 0 deletions engine-idk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,11 @@
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
integrity sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==

"@types/qs@^6.9.7":
version "6.9.7"
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb"
integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==

"@types/resolve@1.20.2":
version "1.20.2"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
Expand Down Expand Up @@ -2969,6 +2974,13 @@ punycode@^2.1.0:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f"
integrity sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==

qs@^6.11.2:
version "6.11.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9"
integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==
dependencies:
side-channel "^1.0.4"

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
Expand Down
6 changes: 3 additions & 3 deletions engine-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@nestjs/swagger": "^6.3.0",
"@paciolan/remote-module-loader": "^3.0.2",
"@poozle/engine-edk": "^0.2.0",
"@poozle/engine-idk": "^0.1.3",
"@poozle/engine-idk": "^0.1.8",
"@prisma/client": "^4.9.0",
"@segment/analytics-node": "^1.0.0-beta.24",
"@vegardit/prisma-generator-nestjs-dto": "^1.5.1",
Expand All @@ -72,7 +72,7 @@
"nestjs-prisma": "0.20.0",
"passport": "0.6.0",
"passport-jwt": "4.0.1",
"prompt-sync": "^4.2.0",
"readline-sync": "^1.4.10",
"reflect-metadata": "0.1.13",
"rimraf": "4.1.1",
"rxjs": "7.8.0",
Expand All @@ -91,7 +91,7 @@
"@types/jest": "28.1.6",
"@types/node": "^18.11.18",
"@types/passport-jwt": "^3.0.8",
"@types/prompt-sync": "^4.2.0",
"@types/readline-sync": "^1.4.4",
"@types/simple-oauth2": "^5.0.4",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "5.48.2",
Expand Down
15 changes: 8 additions & 7 deletions engine-server/prisma/seeds/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

import { PrismaClient } from '@prisma/client';
import axios from 'axios';
import * as promptSync from 'prompt-sync';
import * as readline from 'readline-sync';

const prisma = new PrismaClient();
// Uncomment this when you are testing in local
// import * as promptSync from 'prompt-sync';

const prompt = promptSync();
const prisma = new PrismaClient();

// eslint-disable-next-line prefer-const
let retryTimes = 0;
Expand Down Expand Up @@ -41,10 +42,10 @@ async function main() {
return;
}

const email = prompt('Enter email: ');
const password = prompt('Enter password: ');
const firstName = prompt('Enter firstname: ');
const lastName = prompt('Enter lastname: ');
const email = readline.question('Enter email: ');
const password = readline.question('Enter password: ');
const firstName = readline.question('Enter firstname: ');
const lastName = readline.question('Enter lastname: ');

const users = await prisma.user.findMany({
where: {
Expand Down
11 changes: 10 additions & 1 deletion engine-server/src/common/decorators/integration_account.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import {
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform,
} from '@nestjs/common';
import { IntegrationType } from '@prisma/client';

import { IntegrationAccount } from '@@generated/integrationAccount/entities';
Expand All @@ -20,6 +25,10 @@ export class ParseIntegrationAccountPipe implements PipeTransform {
async transform(value: Value, metadata: ArgumentMetadata) {
const integrationType = metadata.data;

if (!value.workspaceId) {
throw new BadRequestException('workspaceId header is must');
}

const integrationAccount =
(await this.integrationAccountService.getIntegrationAccountWithIntegrationType(
{
Expand Down
8 changes: 6 additions & 2 deletions engine-server/src/common/interfaces/query.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import { PaginationParams } from './pagination.interface';
export class QueryParams extends PaginationParams {
@IsBoolean()
@IsOptional()
@Transform(({ value }) => value === 'true' || value === 'True')
@Transform(({ value }) => {
return value === 'true' || value === 'True' || value === true;
})
raw?: boolean;
}

export class JustRawParams {
@IsBoolean()
@IsOptional()
@Transform(({ value }) => value === 'true' || value === 'True')
@Transform(({ value }) => {
return value === 'true' || value === 'True' || value === true;
})
raw?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion engine-server/src/modules/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AuthModule } from 'modules/auth/auth.module';
import { MailModule } from 'modules/categories/mail/mail.module';
import { TicketingModule } from 'modules/categories/ticketing/ticketing.module';
import { IntegrationAccountModule } from 'modules/integration_account/integration_account.module';
import { IntegrationDefinitionModule } from 'modules/integration_definition /integration_definition.module';
import { IntegrationDefinitionModule } from 'modules/integration_definition/integration_definition.module';
import { IntegrationOAuthModule } from 'modules/integration_oauth/integration_oauth.module';
import { LinkModule } from 'modules/link/link.module';
import { OAuthCallbackModule } from 'modules/oauth_callback/oauth_callback.module';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

import {
All,
BadRequestException,
Body,
Controller,
Get,
Param,
Post,
Query,
Req,
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
Expand All @@ -26,7 +28,6 @@ import {
IntegrationAccountWithLinkRequestIdBody,
IntegrationAccountsRequestBody,
IntegrationCheckBody,
ProxyBody,
UpdateIntegrationAccountBody,
} from './integration_account.interface';
import { IntegrationAccountService } from './integration_account.service';
Expand Down Expand Up @@ -132,17 +133,20 @@ export class IntegrationAccountController {
);
}

@Post(':integrationAccountId/proxy')
@All(':integrationAccountId/proxy/*')
@UseGuards(new AuthGuard())
async proxyPost(
@Body()
proxyBody: ProxyBody,
body: any,
@Req() request: Request,
@Param()
integrationAccountIdRequestIdBody: IntegrationAccountRequestIdBody,
integrationAccountIdRequestIdBody: any,
): Promise<any> {
return this.integrationAccountService.runProxyCommand(
return await this.integrationAccountService.runProxyCommand(
integrationAccountIdRequestIdBody.integrationAccountId,
proxyBody,
body,
request.method,
integrationAccountIdRequestIdBody['0'],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,3 @@ export class UpdateIntegrationAccountBody {
@IsObject()
config: Config;
}

export class ProxyBody {
@IsString()
method: string;

@IsString()
path: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
postBody?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { PrismaModule, PrismaService } from 'nestjs-prisma';

import { IntegrationDefinitionModule } from 'modules/integration_definition /integration_definition.module';
import { IntegrationDefinitionModule } from 'modules/integration_definition/integration_definition.module';
import { LinkModule } from 'modules/link/link.module';

import { IntegrationAccountController } from './integration_account.controller';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import {
runProxyIntegrationCommand,
} from 'shared/integration_run_utils';

import { IntegrationDefinitionService } from 'modules/integration_definition /integration_definition.service';
import { IntegrationDefinitionService } from 'modules/integration_definition/integration_definition.service';

import {
IntegrationAccountRequestBody,
IntegrationAccountRequestBodyWithIntegrationType,
IntegrationAccountRequestIdBody,
ProxyBody,
UpdateIntegrationAccountBody,
} from './integration_account.interface';

Expand Down Expand Up @@ -57,6 +56,7 @@ export class IntegrationAccountService {
integrationAccountName: string,
authType: string,
workspaceId: string,
linkId?: string,
) {
const { status } = await this.checkForIntegrationCredentails(
integrationDefinitionId,
Expand All @@ -73,6 +73,7 @@ export class IntegrationAccountService {
workspaceId,
integrationConfiguration: config,
authType,
linkId,
},
});
}
Expand Down Expand Up @@ -203,7 +204,11 @@ export class IntegrationAccountService {
updateIntegrationAccountBody: UpdateIntegrationAccountBody,
) {
return await this.prismaService.integrationAccount.update({
data: updateIntegrationAccountBody,
data: {
integrationAccountName:
updateIntegrationAccountBody.integrationAccountName,
integrationConfiguration: updateIntegrationAccountBody.config,
},
where: {
integrationAccountId,
},
Expand All @@ -228,7 +233,13 @@ export class IntegrationAccountService {
return false;
}

async runProxyCommand(integrationAccountId: string, body: ProxyBody) {
async runProxyCommand(
integrationAccountId: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: any,
method: string,
path: string,
) {
const integrationAccount =
await this.prismaService.integrationAccount.findUnique({
where: {
Expand All @@ -241,8 +252,8 @@ export class IntegrationAccountService {

return await runProxyIntegrationCommand(
integrationAccount.integrationDefinition.sourceUrl,
body.path,
body.method,
path,
method,
integrationAccount.integrationConfiguration as Config,
integrationAccount.authType,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class IntegrationDefinitionController {
async getSpecForIntegrationDefinition(
@Param()
integrationDefinitionRequestIdBody: IntegrationDefinitionRequestIdBody,
@Body()
@Query()
integrationDefinitionRequestWorkspaceIdBody: IntegrationDefinitionRequestWorkspaceIdBody,
): Promise<Specification> {
return await this.integrationDefinitionService.getSpecForIntegrationDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,16 @@ export class IntegrationDefinitionService {
}

const latestDetails = {
isLatest:
integrationDefinition.version ===
integrationDefinitions[integrationDefinition.key].version,
latestVersion: integrationDefinitions[integrationDefinition.key].version,
latestVersionSource:
integrationDefinitions[integrationDefinition.key].sourceUrl,
isLatest: integrationDefinitions[integrationDefinition.key]
? integrationDefinition.version ===
integrationDefinitions[integrationDefinition.key].version
: true,
latestVersion: integrationDefinitions[integrationDefinition.key]
? integrationDefinitions[integrationDefinition.key].version
: integrationDefinition.version,
latestVersionSource: integrationDefinitions[integrationDefinition.key]
? integrationDefinitions[integrationDefinition.key].sourceUrl
: integrationDefinition.sourceUrl,
};

return {
Expand Down
Loading

0 comments on commit 973127a

Please sign in to comment.