Skip to content

Commit

Permalink
merging upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Oct 31, 2024
1 parent e8d9665 commit d1d3f16
Show file tree
Hide file tree
Showing 31 changed files with 473 additions and 319 deletions.
2 changes: 0 additions & 2 deletions apps/app-config/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## Deploy

## Environment variables

| Name | Description |
Expand Down
8 changes: 7 additions & 1 deletion apps/web/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default function AdminLayout(props: {children: React.ReactNode}) {
// createBrowserSupabaseClient which only uses cookie and does not use header etc.

return (
<ClerkProvider>
<ClerkProvider
appearance={{
elements: {
footer: 'hidden',
},
}}
>
<ClientRootWithClerk>{props.children}</ClientRootWithClerk>
</ClerkProvider>
)
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
--button-hover: #a082e9;
--button-stroke: #6947bb;
--button-secondary: #ffffff;
--button-secondary-foreground: #000000;
--button-secondary-stroke: #e6e6e6;
--button-secondary-hover: #efefef;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/tailwind.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/web/pages/api/trpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {NextApiRequest, NextApiResponse} from 'next'
import {renderTrpcPanel} from 'trpc-panel'
import {appRouter} from '@openint/api'

export const maxDuration = 60;

export default function handler(req: NextApiRequest, res: NextApiResponse) {
// req.url is normally `/api/trpc` already which is the right place
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
28 changes: 28 additions & 0 deletions apps/web/public/_assets/logo-google-calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions apps/web/public/_assets/logo-google-drive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions apps/web/public/_assets/logo-google-gmail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions apps/web/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export default {
foreground: 'var(--button-foreground)',
hover: 'var(--button-hover)',
stroke: 'var(--button-stroke)',
secondary: {
DEFAULT: 'var(--button-secondary)',
foreground: 'var(--button-secondary-foreground)',
stroke: 'var(--button-secondary-stroke)',
hover: 'var(--button-secondary-hover)',
},
},
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
Expand Down
2 changes: 1 addition & 1 deletion kits/cdk/entity-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function cachingTransformLink(

/**
* Used to workaround beancount limitation https://groups.google.com/g/beancount/c/PmkPVgLNKgg
* Not ideal that we have to use Venice link to workaround
* Not ideal that we have to use Openint link to workaround
* beancount quirk. Maybe this should actually be a beancount plugin in python?
* @see https://share.cleanshot.com/8AVFxc
* We have two options instead
Expand Down
9 changes: 2 additions & 7 deletions packages/engine-backend/router/connectorRouter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {zodToOas31Schema} from '@opensdks/util-zod'
import {
extractId,
metaForConnector,
zId,
zVerticalKey,
} from '@openint/cdk'
import {extractId, metaForConnector, zId, zVerticalKey} from '@openint/cdk'
import type {RouterMeta} from '@openint/trpc'
import {TRPCError} from '@openint/trpc'
import {R, z} from '@openint/util'
Expand Down Expand Up @@ -156,7 +151,7 @@ const _connectorRouter = trpc.router({
...res,
items: res.items.map((item) => ({
...item,
id: `${name}_${item.id}`,
id: `int_${name}_${item.id}`,
connector_name: name,
})),
}))
Expand Down
106 changes: 59 additions & 47 deletions packages/engine-backend/router/resourceRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,21 @@ export {type inferProcedureInput} from '@openint/trpc'

const tags = ['Core']

async function performResourceCheck(
ctx: any,
resoId: string,
opts: any,
) {
async function performResourceCheck(ctx: any, resoId: string, opts: any) {
const remoteCtx = await getRemoteContext({
...ctx,
remoteResourceId: resoId,
})
const {connectorConfig: int, ...reso} =
await ctx.asOrgIfNeeded.getResourceExpandedOrFail(resoId)

const resoUpdate = await int.connector.checkResource?.({
let resoUpdate = await int.connector.checkResource?.({
settings: remoteCtx.remote.settings,
config: int.config,
options: opts ?? {},
instance: remoteCtx.remote.instance,
context: {
webhookBaseUrl: joinPath(
ctx.apiUrl,
parseWebhookRequest.pathOf(int.id),
),
webhookBaseUrl: joinPath(ctx.apiUrl, parseWebhookRequest.pathOf(int.id)),
},
})
if (resoUpdate || opts?.import !== false) {
Expand All @@ -55,15 +48,18 @@ async function performResourceCheck(
...resoUpdate,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
settings: {
...(opts?.import && remoteCtx.remote.settings),
// ...(opts?.import && remoteCtx.remote.settings),
// unconditionally import resource settings
...remoteCtx.remote.settings,
...resoUpdate?.settings,
},
resourceExternalId:
resoUpdate?.resourceExternalId ?? extractId(reso.id)[2],
})
resoUpdate = await ctx.services.getResourceOrFail(reso.id)
}
if (!int.connector.checkResource) {
return resoUpdate;
return resoUpdate
}
return resoUpdate
}
Expand Down Expand Up @@ -241,40 +237,51 @@ export const resourceRouter = trpc.router({
)
.output(z.array(zRaw.resource))
.query(async ({input = {}, ctx}) => {
let resources =
await ctx.services.metaService.tables.resource.list(input)
let resources = await ctx.services.metaService.tables.resource.list(input)

// Handle forceRefresh for each resource

console.log('[listResources] Refreshing tokens for all resources');
const updatedResources = await Promise.all(resources.map(async (reso) => {
// @ts-expect-error
const expiresAt = reso?.settings?.['oauth']?.credentials?.raw?.expires_at

if (expiresAt && (input.forceRefresh || new Date(expiresAt).getTime() <= Date.now())) {
console.log(`[listResources] Refreshing token for resource ${reso.connectorName}`);
const resoCheck = await performResourceCheck(ctx, reso.id, {});
if(!resoCheck) {
console.warn(`[listResources] resourceCheck not implemented for ${reso.connectorName} which requires a refresh. Returning the stale resource.`);
console.log('[listResources] Refreshing tokens for all resources')
const updatedResources = await Promise.all(
resources.map(async (reso) => {
const expiresAt =
// @ts-expect-error
reso?.settings?.['oauth']?.credentials?.raw?.expires_at

if (
expiresAt &&
(input.forceRefresh || new Date(expiresAt).getTime() <= Date.now())
) {
console.log(
`[listResources] Refreshing token for resource ${reso.connectorName}`,
)
const resoCheck = await performResourceCheck(ctx, reso.id, {})
if (!resoCheck) {
console.warn(
`[listResources] resourceCheck not implemented for ${reso.connectorName} which requires a refresh. Returning the stale resource.`,
)
}
return resoCheck || reso
}
return resoCheck || reso;
}
return reso;
}));
return reso
}),
)

resources = updatedResources

resources = updatedResources;

return resources as Array<ZRaw['resource']>
}),
getResource: protectedProcedure
.meta({
description: 'Not automatically called, used for debugging for now',
openapi: {method: 'GET', path: '/core/resource/{id}', tags},
})
.input(z.object({
id: zId('reso'),
forceRefresh: z.boolean().optional()
}))
.input(
z.object({
id: zId('reso'),
forceRefresh: z.boolean().optional(),
}),
)
.output(
// TODO: Should we expand this?
zRaw.resource.extend({
Expand All @@ -289,20 +296,25 @@ export const resourceRouter = trpc.router({
// do not expand for now otherwise permission issues..
let reso = await ctx.services.getResourceOrFail(input.id)
const ccfg = await ctx.services.getConnectorConfigOrFail(
reso.connectorConfigId
reso.connectorConfigId,
)

// Handle forceRefresh
// @ts-expect-error
const expiresAt = reso?.settings?.['oauth']?.credentials?.raw?.expires_at

if (expiresAt && (input.forceRefresh ||new Date(expiresAt).getTime() <= Date.now())) {
console.log('[getResource] Refreshing token');
const resoCheck = await performResourceCheck(ctx, reso.id, {});
if(!resoCheck) {
console.warn(`[getResource] resourceCheck not implemented for ${reso.connectorName} which requires a refresh. Returning the stale resource.`);

if (
expiresAt &&
(input.forceRefresh || new Date(expiresAt).getTime() <= Date.now())
) {
console.log('[getResource] Refreshing token')
const resoCheck = await performResourceCheck(ctx, reso.id, {})
if (!resoCheck) {
console.warn(
`[getResource] resourceCheck not implemented for ${reso.connectorName} which requires a refresh. Returning the stale resource.`,
)
}
reso = resoCheck || reso;
reso = resoCheck || reso
}

return {
Expand All @@ -321,11 +333,11 @@ export const resourceRouter = trpc.router({
if (ctx.viewer.role === 'end_user') {
await ctx.services.getResourceOrFail(resoId)
}
const resourceCheck = await performResourceCheck(ctx, resoId, opts);
if(!resourceCheck) {
return `Resource check not implemented for ${resoId}`;
const resourceCheck = await performResourceCheck(ctx, resoId, opts)
if (!resourceCheck) {
return `Resource check not implemented for ${resoId}`
}
return resourceCheck;
return resourceCheck
}),

// MARK: - Sync
Expand Down Expand Up @@ -387,4 +399,4 @@ export const resourceRouter = trpc.router({
triggerDefaultSync: true,
})
}),
})
})
6 changes: 3 additions & 3 deletions packages/engine-frontend/DeprecatedOpenIntConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {SchemaFormElement, UIProps, UIPropsNoChildren} from '@openint/ui'
import {
Button,
ConnectorConfigCard,
DeprecatedIntegrationCard,
Dialog,
DialogContent,
DialogDescription,
Expand All @@ -36,7 +37,6 @@ import {
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
IntegrationCard,
ResourceCard,
SchemaForm,
useToast,
Expand Down Expand Up @@ -364,7 +364,7 @@ export function _OpenIntConnect({
))}
{!debugConnectorConfigs &&
configuredIntegrations.map((int) => (
<IntegrationCard
<DeprecatedIntegrationCard
{...uiProps}
key={int.id}
integration={{
Expand All @@ -382,7 +382,7 @@ export function _OpenIntConnect({
onEvent?.({type: e.type, ccfgId: int.connector_config_id})
}}
/>
</IntegrationCard>
</DeprecatedIntegrationCard>
))}
</div>
)
Expand Down
1 change: 0 additions & 1 deletion packages/engine-frontend/components/ConnectionPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export function ConnectionPortal({className}: ConnectionPortalProps) {
),
}))
const connectionCount = connections.length
console.log({connectionCount})

const tabConfig = [
{
Expand Down
11 changes: 7 additions & 4 deletions packages/engine-frontend/components/ConnectionsTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function ConnectionsTabContent({
if (event.type === 'close') {
refetch() // Trigger refetch
}
}}></ConnectDialog>
}}
/>
</div>
) : (
<div className="p-4">
Expand All @@ -72,10 +73,12 @@ export function ConnectionsTabContent({
<div className="flex h-full flex-col justify-center">
<div className="flex flex-row items-center gap-2">
<h4 className="font-bold">
{conn.connectorName.charAt(0).toUpperCase() +
conn.connectorName.slice(1)}
{conn.connectorConfig.connector.displayName
.charAt(0)
.toUpperCase() +
conn.connectorConfig.connector.displayName.slice(1)}
</h4>
<Badge variant="secondary">{category.name}</Badge>
<Badge variant="outline">{category.name}</Badge>
</div>
{conn.pipelineIds.length > 0 && (
<div className="mt-2">
Expand Down
Loading

0 comments on commit d1d3f16

Please sign in to comment.