Skip to content

Commit

Permalink
feat: revert new client (#599)
Browse files Browse the repository at this point in the history
* Initial Commit

* chore: bump yarn lock files

* feat: useSWR to revalidate the requests on stale or onfocus

* feat: badge with recentApiCalls

* fix: badge to not show boolean value on ui

* feat(ui): skeleton for loading state

* fix: revalidation on change in environment

* fix: map iteration key id in client components

* fix: map iteration key id in client components

* fix: spacing in recent api calls component

* feat(api): keep track of total number of api requests

* feat(ui): graph skeleton on loading

* feat(ui): recent api calls skeleton

* fix: store 8 recent call apis in redis queue

* feat(api): summary of api calls of last 7 days

* feat(ui): total api request graph

* fix(ui): recent api calls card

* fix: skeleton loading to use conditional one of useSWR only

* feat(analytics): make api response typesafe with zod

* fix: account types to add zod schema

* fix: file imports to have aliases

* feat(ui): Modal for create app

* feat(ui): application cards with border gradients

* feat(ui): Tabs and Separator Component

* feat(ui): app settings view

* feat: delete integration container

* feat(ui): api reference template page

* feat: typesafe fetchAccounts

* feat: settings and apireference navigation with interactivity

* chore: remove temp routes which was made for making components

* feat: create Application server action

* feat(ui): save preference to use particular credentials

* fix(wip): scopes component

* feat: delete revert app

* feat: store recent api calls for particular app

* feat(api): get recent api call for tenantId

* fix(api): recent api calls to have appId as params instead of tenantId in headers

* feat(ui): recent api calls dashboard for each apps

* fix(ui): handle recent api calls if no connection is made.

* fix(api): update credentials of app to clear extra param when needed

* feat(ui): have extra params config for discord and ms_dynamics_365_sales

* fix(ui): add integrations logos

* fix: environment change under settings should redirect to /dashboard/integrations

* fix: svg param names

* feat(ui): scope multi select component version 1

* feat(api): get available_scope under accounts

* fix(ui): to not remove scope for more

* fix(ui): to see the updated scope

* feat(ui): change scopes for the app

* fix(ui): change commandItem color on hover

* fix(ui): Add Integration button to take full length

* fix(ui): to have skeleton for apiReference view

* chore: include loader svg

* fix(ui): missing keys in map function and popover styles

* fix(ui): Show no integration configured container when no apps created

* fix(ui): focus outlines ring

* fix(ui): tab list to have logs as tab and fix creation integration modal styles

* fix(ui): don't close modal when disable button is clicked

* fix(ui): buttons to be client component and clickable on focus

* fix(ui): remove shadow from modal border

* fix(ui): modal to not have shadow

* fix(ui): sidenav component returning as promise

* fix: errors generated from conflicts

* fix: workspace name

* feat(ui): Sidenav workspacename and revert logo

* fix: let next use env api url instead, fixed .nvmrc version removes package-lock.json

* fix: config and resolve build errors

* feat(wip): onboarding screens

* fix(wip): integrate frontend sdk

* fix: header height

* fix: integrate frontend sdk to have flexible frontend sdk

* fix: copy to clipboard button top margin

* fix: overflow-scroll for integrations and onboarding

* fix(ui): to hide scrollbar from several containers

* fix: AppSettings of tabs to pass onboarding prop

* fix: padding top for sdk content

* fix(ui): styles in 13inch laptop

* fix(graph): text color to have gray

* feat: onboarding redirects

* fix: onboarding completion
  • Loading branch information
Nabhag8848 authored Aug 13, 2024
1 parent 6552893 commit 6a00423
Show file tree
Hide file tree
Showing 406 changed files with 12,810 additions and 7,777 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.19.1
18.20.4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/fsevents-patch-3340e2eb10-8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/glob-npm-8.1.0-65f64af8b1-92fbea3221.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/has-npm-1.0.3-b7f00631c1-b9ad53d53b.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ip-npm-1.1.8-abea558b72-a2ade53eb3.zip
Binary file not shown.
Binary file removed .yarn/cache/ip-npm-2.0.0-204facb3cc-cfcfac6b87.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nan-npm-2.17.0-bf36a21d6f-ec609aeaf7.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nopt-npm-6.0.0-5ea8050815-82149371f8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/resolve-patch-46f9469d0d-5656f4d0be.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/tar-npm-6.1.13-3234e72781-8a278bed12.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/url-npm-0.11.0-32ce15acfb-50d100d3dd.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions fern/definition/common/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ types:
skipWaitlist: boolean
users: optional<list<RevertUser>>
apps: optional<list<App>>
isOnboardingCompleted: optional<Environment>

Environment:
properties:
development: boolean
production: boolean

App:
properties:
id: string
tp_id: TPID
scope: optional<list<string>>
available_scope: list<string>
app_client_id: optional<string>
app_client_secret: optional<string>
owner_account_public_token: string
Expand Down Expand Up @@ -83,13 +90,20 @@ types:
method: string
path: string
status: integer

SummaryApiCalls:
properties:
date: string
numberOfCalls: integer

Analytics:
properties:
totalConnections: integer
connectedApps: optional<list<ConnectedApps>>
recentConnections: optional<list<RecentConnections>>
recentApiCalls: optional<list<RecentApiCalls>>
totalApiCalls: optional<integer>
summaryApiCalls: optional<list<SummaryApiCalls>>
TicketStatus:
enum:
- open
Expand Down
35 changes: 35 additions & 0 deletions fern/definition/internal/account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ types:
properties:
key: string
environment: string
DeleteRevertAppResponse:
properties:
appId: string
delete: boolean
setOnboardingResponse:
properties:
result: boolean

service:
base-path: /internal/account
Expand Down Expand Up @@ -117,3 +124,31 @@ service:
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
deleteRevertAppforAccount:
docs: delete Revert App for Account
method: DELETE
path: /apps
request:
name: DeleteRevertAppForAccount
body:
properties:
appId: string
response: DeleteRevertAppResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError
setOnboardingCompleted:
docs: Set Onboarding Completed
method: POST
path: '/onboarding'
request:
name: SetOnboardingCompletedRequest
body:
properties:
userId: string
environment: string
response: setOnboardingResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
34 changes: 34 additions & 0 deletions fern/definition/internal/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
imports:
errors: ../common/errors.yml

types:
RecentApiCalls:
properties:
method: string
path: string
status: integer
RecentAppApiCallsResponse:
properties:
result: optional<list<RecentApiCalls>>

service:
base-path: /internal/request
auth: false
headers:
x-revert-api-token: string
audiences:
- internal
endpoints:
getRecentApiCallsForApp:
docs: Recent api calls for App
method: GET
path: /app/{appId}
path-parameters:
appId: string
request:
name: RecentApiCallsForApp
response: RecentAppApiCallsResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError
46 changes: 43 additions & 3 deletions packages/backend/helpers/endPointLoggerMiddleWare.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Request, Response, NextFunction } from 'express';
import redis from '../redis/client';
import { logError } from './logger';
import prisma from '../prisma/client';
import { getDateWithShortMonth } from './timeZoneHelper';
// @FIXME Add logic for error
const endpointLogger = () => async (req: Request, res: Response, next: NextFunction) => {
try {
const path = req.path;
const { 'x-revert-api-token': token } = req.headers;
const { 'x-revert-api-token': token, 'x-revert-t-id': tenantId } = req.headers;
const toAllow =
path.includes('/crm') ||
path.includes('/chat') ||
Expand All @@ -14,7 +16,6 @@ const endpointLogger = () => async (req: Request, res: Response, next: NextFunct
path.includes('/accounting');

if (!toAllow) return next();

const logEntry: any = {
method: req.method,
path: path,
Expand All @@ -23,7 +24,46 @@ const endpointLogger = () => async (req: Request, res: Response, next: NextFunct

if (res.headersSent) logEntry.status = res.statusCode;
const queueLength = await redis.lPush(`recent_routes_${token}`, JSON.stringify(logEntry));
if (queueLength && queueLength > 5) await redis.rPop(`recent_routes_${token}`);
if (queueLength && queueLength > 8) await redis.rPop(`recent_routes_${token}`);

const environment = await prisma.environments.findFirst({
where: {
private_token: String(token),
},
});

if (!environment) {
throw new Error("Account doesn't exist");
}
await redis.INCR(`request_count_${environment.id}`);

// Summary of Api Calls by date for last 7 days + 1 buffer day
const key = `summary_api_calls_${environment.id}`;
await redis.hIncrBy(key, getDateWithShortMonth(), 1);
const isExpiryExist = await redis.ttl(key); // -1 means expiry doesn't exist, -2 means key doesn't exist

if (isExpiryExist === -1) {
const isExpirySet = await redis.expire(key, 60 * 60 * 24 * 8);
if (!isExpirySet) {
console.error(isExpirySet);
}
}

// Recent Api Calls for Particular App

const connections = await prisma.connections.findFirst({
where: {
t_id: tenantId as string,
},
});

if (connections?.appId) {
const recentAppCalls = await redis.lPush(
`recent_routes_app_${connections.appId}`,
JSON.stringify(logEntry)
);
if (recentAppCalls && recentAppCalls > 8) await redis.rPop(`recent_routes_app_${connections.appId}`);
}

next();
} catch (error: any) {
Expand Down
31 changes: 30 additions & 1 deletion packages/backend/helpers/timeZoneHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,33 @@ const convertToHHMMInUTC = (dateTimeString: string) => {
return formattedTimeUTC;
};

export { convertToHHMMInUTC, getDuration, getFormattedDate };
const getCurrentLocale = () => {
const dateTimeFormat = new Intl.DateTimeFormat();
const options = dateTimeFormat.resolvedOptions();
return options.locale;
};

const getDateWithShortMonth = () => {
const today = new Date();
const formattedDate = today.toLocaleDateString(getCurrentLocale(), { day: 'numeric', month: 'short' });
return formattedDate;
};

function getLastSevenDays() {
const daysArray = [];
const today = new Date();

for (let i = 6; i > -1; --i) {
const currentDate = new Date();
currentDate.setDate(today.getDate() - i);

// Formatting the date in form: "22 Jan"
const formattedDate = currentDate.toLocaleDateString(getCurrentLocale(), { day: 'numeric', month: 'short' });

daysArray.push(formattedDate);
}

return daysArray;
}

export { convertToHHMMInUTC, getDuration, getFormattedDate, getDateWithShortMonth, getLastSevenDays };
2 changes: 1 addition & 1 deletion packages/backend/helpers/webhooks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default async function sendConnectionAddedEvent(
tenantId: string,
tp_id: string,
tp_access_token: string,
tp_customer_id: string
tp_customer_id: string,
) {
try {
const isSvixAppExist = await getSvixAccount(svixAppId);
Expand Down
Loading

0 comments on commit 6a00423

Please sign in to comment.