Skip to content

Commit

Permalink
Feat: add link feature (#124)
Browse files Browse the repository at this point in the history
* Feat: poozle link

* Feat: added link feature

* Publish: New poozle version
  • Loading branch information
harshithmullapudi committed Jul 6, 2023
1 parent 7c9523a commit 96abb8a
Show file tree
Hide file tree
Showing 123 changed files with 2,386 additions and 656 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENGINE_VERSION=0.1.2-alpha
ENGINE_VERSION=0.1.3-alpha

# POSTGRES
POSTGRES_USER=docker
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- 5432:5432
networks:
- poozle
restart: unless-stopped
Expand Down
2 changes: 1 addition & 1 deletion 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.4",
"version": "0.1.6",
"description": "Used to develop integrations for Poozle",
"license": "MIT",
"author": "Poozle <support@poozle.in>",
Expand Down
19 changes: 9 additions & 10 deletions engine-idk/src/bases/base_integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ export class BaseIntegration implements BaseIntegrationInterface {
This function will be used when the integration is getting configured. We will use this to test with the
credentials are valid.
*/
async check(_config: Config): CheckResponse {
try {
return { status: false, error: '' };
} catch (err) {
return {
status: false,
error: err.message as string,
};
async check(config: Config): CheckResponse {
const headers = await this.authHeaders(config);

if (Object.keys(headers).length === 0) {
return { status: false, error: 'Check failed' };
}

return { status: true, error: '' };
}

async authHeaders(config: Config): AuthHeaderResponse {
Expand All @@ -54,11 +53,11 @@ export class BaseIntegration implements BaseIntegrationInterface {
const specification = spec.authSpecification['OAuth2'] as AuthSpecificationOAuth;
headers = specification.headers ?? {};
token = await getAccessToken(
interpolateString(specification.tokenUrl as string, config),
interpolateString(specification.token_url as string, config),
config,
);
headers = {
Authorization: 'Bearer ${token}',
Authorization: `Bearer ${token}`,
};
} else {
const type = config.authType;
Expand Down
12 changes: 7 additions & 5 deletions engine-idk/src/types/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export interface AuthSpecificationGeneric {
}

export interface AuthSpecificationOAuth {
tokenUrl?: string;
authMode?: string;
authorizationUrl?: string;
authorizationParams?: Record<string, string>;
tokenParams?: Record<string, string>;
// Params that are directly supported by simple-oauth2
token_url?: string;
auth_mode?: string;
authorization_url?: string;
authorization_params?: Record<string, string>;
token_params?: Record<string, string>;
headers?: Record<string, string>;
// Needed to store
inputSpecification?: {
type: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
14 changes: 0 additions & 14 deletions engine-server/config/o_auth_provider.ts

This file was deleted.

3 changes: 2 additions & 1 deletion engine-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "engine-server",
"version": "0.1.2-alpha",
"version": "0.1.3-alpha",
"description": "Poozle engine",
"author": "Poozle",
"license": "MIT",
Expand Down Expand Up @@ -68,6 +68,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"date-fns": "^2.30.0",
"nestjs-prisma": "0.20.0",
"passport": "0.6.0",
"passport-jwt": "4.0.1",
Expand Down
22 changes: 12 additions & 10 deletions engine-server/prisma/dbml/schema.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Table Workspace {
IntegrationAccount IntegrationAccount [not null]
IntegrationOAuthApp IntegrationOAuthApp [not null]
deleted DateTime
IntegrationConnectLink IntegrationConnectLink [not null]
Link Link [not null]
}

Table IntegrationDefinition {
Expand Down Expand Up @@ -56,14 +56,15 @@ Table IntegrationOAuthApp {
clientId String [not null]
clientSecret String [not null]
scopes String [not null]
workspace Workspace
workspaceId String
workspace Workspace [not null]
workspaceId String [not null]
deleted DateTime
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [not null]

indexes {
(integrationOAuthAppName, workspaceId) [unique]
(integrationDefinitionId, workspaceId) [unique]
}
}

Expand All @@ -79,17 +80,18 @@ Table IntegrationAccount {
deleted DateTime
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [not null]
fromLinks IntegrationConnectLink
integrationConnectLinkIntegrationConnectionLinkId String
fromLinks Link
linkId String

indexes {
(integrationAccountName, workspaceId) [unique]
}
}

Table IntegrationConnectLink {
integrationConnectionLinkId String [pk]
expiresIn Int [not null, default: 60]
Table Link {
linkId String [pk]
linkName String [not null]
expiresIn Int [not null, default: 3600]
category IntegrationType[] [not null]
workspace Workspace [not null]
workspaceId String [not null]
Expand Down Expand Up @@ -125,6 +127,6 @@ Ref: IntegrationAccount.integrationDefinitionId > IntegrationDefinition.integrat

Ref: IntegrationAccount.workspaceId > Workspace.workspaceId

Ref: IntegrationAccount.integrationConnectLinkIntegrationConnectionLinkId > IntegrationConnectLink.integrationConnectionLinkId
Ref: IntegrationAccount.linkId > Link.linkId

Ref: IntegrationConnectLink.workspaceId > Workspace.workspaceId
Ref: Link.workspaceId > Workspace.workspaceId
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Warnings:
- You are about to drop the column `integrationConnectLinkIntegrationConnectionLinkId` on the `IntegrationAccount` table. All the data in the column will be lost.
- You are about to drop the `IntegrationConnectLink` table. If the table is not empty, all the data it contains will be lost.
- Made the column `workspaceId` on table `IntegrationOAuthApp` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "IntegrationAccount" DROP CONSTRAINT "IntegrationAccount_integrationConnectLinkIntegrationConnec_fkey";

-- DropForeignKey
ALTER TABLE "IntegrationConnectLink" DROP CONSTRAINT "IntegrationConnectLink_workspaceId_fkey";

-- DropForeignKey
ALTER TABLE "IntegrationOAuthApp" DROP CONSTRAINT "IntegrationOAuthApp_workspaceId_fkey";

-- AlterTable
ALTER TABLE "IntegrationAccount" DROP COLUMN "integrationConnectLinkIntegrationConnectionLinkId",
ADD COLUMN "linkId" TEXT;

-- AlterTable
ALTER TABLE "IntegrationOAuthApp" ALTER COLUMN "workspaceId" SET NOT NULL;

-- DropTable
DROP TABLE "IntegrationConnectLink";

-- CreateTable
CREATE TABLE "Link" (
"linkId" TEXT NOT NULL,
"linkName" TEXT NOT NULL,
"expiresIn" INTEGER NOT NULL DEFAULT 3600,
"category" "IntegrationType"[],
"workspaceId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Link_pkey" PRIMARY KEY ("linkId")
);

-- AddForeignKey
ALTER TABLE "IntegrationOAuthApp" ADD CONSTRAINT "IntegrationOAuthApp_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "Workspace"("workspaceId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "IntegrationAccount" ADD CONSTRAINT "IntegrationAccount_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("linkId") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Link" ADD CONSTRAINT "Link_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "Workspace"("workspaceId") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[integrationDefinitionId,workspaceId]` on the table `IntegrationOAuthApp` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "IntegrationOAuthApp_integrationDefinitionId_workspaceId_key" ON "IntegrationOAuthApp"("integrationDefinitionId", "workspaceId");
60 changes: 31 additions & 29 deletions engine-server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ model User {
}

model Workspace {
workspaceId String @id @default(uuid())
slug String @unique
user User @relation(references: [userId], fields: [userId])
workspaceId String @id @default(uuid())
slug String @unique
user User @relation(references: [userId], fields: [userId])
userId String
initialSetupComplete Boolean @default(false)
anonymousDataCollection Boolean @default(false)
initialSetupComplete Boolean @default(false)
anonymousDataCollection Boolean @default(false)
IntegrationDefinition IntegrationDefinition[]
IntegrationAccount IntegrationAccount[]
IntegrationOAuthApp IntegrationOAuthApp[]
deleted DateTime?
IntegrationConnectLink IntegrationConnectLink[]
Link Link[]
}

model IntegrationDefinition {
Expand Down Expand Up @@ -78,39 +78,41 @@ model IntegrationOAuthApp {
clientSecret String
scopes String
workspace Workspace? @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String?
workspace Workspace @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String
deleted DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([integrationOAuthAppName, workspaceId])
@@unique([integrationDefinitionId, workspaceId])
}

model IntegrationAccount {
integrationAccountId String @id @default(uuid())
integrationDefinition IntegrationDefinition @relation(references: [integrationDefinitionId], fields: [integrationDefinitionId])
integrationDefinitionId String
integrationConfiguration Json?
authType String
workspace Workspace @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String
integrationAccountName String
deleted DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
fromLinks IntegrationConnectLink? @relation(fields: [integrationConnectLinkIntegrationConnectionLinkId], references: [integrationConnectionLinkId])
integrationConnectLinkIntegrationConnectionLinkId String?
integrationAccountId String @id @default(uuid())
integrationDefinition IntegrationDefinition @relation(references: [integrationDefinitionId], fields: [integrationDefinitionId])
integrationDefinitionId String
integrationConfiguration Json?
authType String
workspace Workspace @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String
integrationAccountName String
deleted DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
fromLinks Link? @relation(fields: [linkId], references: [linkId])
linkId String?
@@unique([integrationAccountName, workspaceId])
}

model IntegrationConnectLink {
integrationConnectionLinkId String @id @default(uuid())
expiresIn Int @default(60)
category IntegrationType[]
workspace Workspace @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String
model Link {
linkId String @id @default(uuid())
linkName String
expiresIn Int @default(3600)
category IntegrationType[]
workspace Workspace @relation(references: [workspaceId], fields: [workspaceId])
workspaceId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
6 changes: 6 additions & 0 deletions engine-server/prisma/seeds/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ async function main() {

const accessToken = response.headers['st-access-token'];

if (!accessToken) {
console.log(response.data);
console.log('User not created');
return;
}

await axios.post(
`${process.env.BACKEND_HOST}/v1/user`,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { Prisma } from '@prisma/client';
import { IntegrationDefinition } from '../../integrationDefinition/entities/integrationDefinition.entity';
import { Workspace } from '../../workspace/entities/workspace.entity';
import { IntegrationConnectLink } from '../../integrationConnectLink/entities/integrationConnectLink.entity';
import { ApiHideProperty } from '@nestjs/swagger';

export class IntegrationAccount {
integrationAccountId: string;
integrationDefinition?: IntegrationDefinition;
integrationDefinitionId: string;
integrationConfiguration: Prisma.JsonValue | null;
authType: string;

@ApiHideProperty()
workspace?: Workspace;
import {Prisma} from '@prisma/client'
import {IntegrationDefinition} from '../../integrationDefinition/entities/integrationDefinition.entity'
import {Workspace} from '../../workspace/entities/workspace.entity'
import {Link} from '../../link/entities/link.entity'

workspaceId: string;
integrationAccountName: string;
deleted: Date | null;
createdAt: Date;
updatedAt: Date;

@ApiHideProperty()
fromLinks?: IntegrationConnectLink | null;

integrationConnectLinkIntegrationConnectionLinkId: string | null;
export class IntegrationAccount {
integrationAccountId: string ;
integrationDefinition?: IntegrationDefinition ;
integrationDefinitionId: string ;
integrationConfiguration: Prisma.JsonValue | null;
authType: string ;
workspace?: Workspace ;
workspaceId: string ;
integrationAccountName: string ;
deleted: Date | null;
createdAt: Date ;
updatedAt: Date ;
fromLinks?: Link | null;
linkId: string | null;
}
Loading

0 comments on commit 96abb8a

Please sign in to comment.