Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google FS API New #234

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
workflow_dispatch:

permissions:
pull-requests: write
contents: write

jobs:
Expand Down Expand Up @@ -147,3 +148,11 @@ jobs:
git fetch origin main
git checkout main
git push origin main:production -f
- name: Wait for 5 minutes for any remaining Vercel Main Branch Deployment that's in flight
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our deployment is not guaranteed to take 5 mins. Could be longer sometimes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

run: sleep 300
- name: Stably Runner Action
id: stably-runner
uses: stablyhq/stably-runner-action@v3
with:
api-key: ${{ secrets.STABLY_API_KEY }}
test-group-id: cm5g8i6nc0005l103urkixuxz
25 changes: 0 additions & 25 deletions .github/workflows/stably-workflow.yml

This file was deleted.

119 changes: 2 additions & 117 deletions apps/web/app/connect/page.tsx
Original file line number Diff line number Diff line change
@@ -1,123 +1,8 @@
// import {clerkClient} from '@clerk/nextjs/server'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this related?

// import Image from 'next/image'
import {defConnectors} from '@openint/app-config/connectors/connectors.def'
import {kAccessToken} from '@openint/app-config/constants'
import {envRequired} from '@openint/app-config/env'
import type {ConnectorDef} from '@openint/cdk'
import {
extractConnectorName,
getViewerId,
makeId,
NangoConnect,
} from '@openint/cdk'
import {zConnectPageParams} from '@openint/engine-backend/router/customerRouter'
import {makeUlid} from '@openint/util'
import {createServerComponentHelpers} from '@/lib-server/server-component-helpers'
import {SetCookieAndRedirect} from './(oauth)/redirect/SetCookieAndRedirect'
import {kConnectSession, type ConnectSession} from './shared'

export const metadata = {
title: 'OpenInt Connect',
title: 'OpenInt Connect (Deprecated)',
}

/**
* Workaround for searchParams being empty on production. Will ahve to check
* @see https://github.com/vercel/next.js/issues/43077#issuecomment-1383742153
*/
export const dynamic = 'force-dynamic'

// Should we allow page to optionally load without token for performance then add token async
// Perhaps it would even be an advantage to have the page simply be static?
// Though that would result in waterfall loading of integrations

/** https://beta.nextjs.org/docs/api-reference/file-conventions/page#searchparams-optional */
export default async function ConnectPageContainer({
searchParams,
}: {
// Only accessible in PageComponent rather than layout component
// @see https://github.com/vercel/next.js/issues/43704
searchParams: Record<string, string | string[] | undefined>
}) {
const {token, ...params} = zConnectPageParams.parse(searchParams)
const {ssg, viewer} = await createServerComponentHelpers({
searchParams: {[kAccessToken]: token},
})
if (viewer.role !== 'customer') {
return (
<div>Authenticated user only. Your role is {getViewerId(viewer)}</div>
)
}

// Implement shorthand for specifying only connectorConfigId by connectorName
let connectorConfigId = params.connectorConfigId
if (!connectorConfigId && params.connectorNames) {
let ints = await ssg.listConnectorConfigInfos.fetch({
connectorName: params.connectorNames,
})
if (params.connectorConfigDisplayName) {
ints = ints.filter(
(int) => int.displayName === params.connectorConfigDisplayName,
)
}
if (ints.length === 1 && ints[0]?.id) {
connectorConfigId = ints[0]?.id
} else if (ints.length < 1) {
return (
<div>No connector config for {params.connectorNames} configured</div>
)
} else if (ints.length > 1) {
console.warn(
`${ints.length} connector configs found for ${params.connectorNames}`,
)
}
}

// Special case when we are handling a single oauth connector config
if (connectorConfigId) {
const connectorName = extractConnectorName(connectorConfigId)
const intDef = defConnectors[
connectorName as keyof typeof defConnectors
] as ConnectorDef

if (intDef.metadata?.nangoProvider) {
const connectionId = makeId('conn', connectorName, makeUlid())
const url = await NangoConnect.getOauthConnectUrl({
public_key: envRequired.NEXT_PUBLIC_NANGO_PUBLIC_KEY,
connection_id: connectionId,
provider_config_key: connectorConfigId,
// Consider using hookdeck so we can work with any number of urls
// redirect_uri: joinPath(getServerUrl(null), '/connect/callback'),
})
return (
<SetCookieAndRedirect
cookies={[
{
key: kConnectSession,
value: JSON.stringify({
connectionId,
token,
} satisfies ConnectSession),
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7%7Cthe
// Need sameSite to be lax in order for this to work
options: {maxAge: 3600, sameSite: 'lax'},
},
]}
redirectUrl={url}
/>
)
}
}

await Promise.all([
// clerkClient.organizations.getOrganization({organizationId: viewer.orgId}),
// Switch to using react suspense / server fetch for this instead of prefetch
ssg.listConnectorConfigInfos.prefetch({
id: connectorConfigId,
connectorName: params.connectorNames,
}),
params.showExisting ? ssg.listConnections.prefetch({}) : Promise.resolve(),
])

export default async function ConnectPageContainer() {
return (
<div className="h-screen w-screen p-6">
/connect is deprecated. Please use /connect/portal instead
Expand Down
3 changes: 2 additions & 1 deletion connectors/connector-google/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dependencies": {
"@openint/cdk": "workspace:*",
"@openint/util": "workspace:*",
"@opensdks/runtime": "^0.0.19"
"@opensdks/runtime": "^0.0.19",
"@opensdks/sdk-google": "*"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm we should probably version this at least with ^...

},
"devDependencies": {}
}
53 changes: 30 additions & 23 deletions connectors/connector-google/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {extractId, initNangoSDK, type ConnectorServer} from '@openint/cdk'
import {initGoogleSDK} from '@opensdks/sdk-google'
import {
extractId,
initNangoSDK,
nangoProxyLink,
type ConnectorServer,
} from '@openint/cdk'
import type {googleSchemas} from './def'

function mergeScopes(
Expand Down Expand Up @@ -64,28 +70,29 @@ const integrations = [
]

export const googleServer = {
// newInstance: ({settings, fetchLinks}) => {
// const sdk = initHubspotSDK({
// // We rely on nango to refresh the access token...
// headers: {
// authorization: `Bearer ${settings.oauth.credentials.access_token}`,
// },
// links: (defaultLinks) => [
// (req, next) => {
// if (sdk.clientOptions.baseUrl) {
// req.headers.set(
// nangoProxyLink.kBaseUrlOverride,
// sdk.clientOptions.baseUrl,
// )
// }
// return next(req)
// },
// ...fetchLinks,
// ...defaultLinks,
// ],
// })
// return sdk
// },
newInstance: ({settings, fetchLinks}) => {
const sdk = initGoogleSDK({
// We rely on nango to refresh the access token...
headers: {
authorization: `Bearer ${settings.oauth.credentials.access_token}`,
},
links: (defaultLinks) => [
(req, next) => {
// TODO: make this dynamic to different base URLs than just drive_v2
if (sdk.drive_v2.clientOptions.baseUrl) {
req.headers.set(
nangoProxyLink.kBaseUrlOverride,
sdk.drive_v2.clientOptions.baseUrl,
)
}
return next(req)
},
...fetchLinks,
...defaultLinks,
],
})
return sdk
},
// passthrough: (instance, input) =>
// instance.request(input.method, input.path, {
// headers: input.headers as Record<string, string>,
Expand Down
32 changes: 12 additions & 20 deletions kits/sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@
"add-deeplink"
],
"description": "Magic Link tab view"
},
"connectorConfigDisplayName": {
"type": ["string", "null"],
"description": "Filter connector config by displayName "
},
"connectorConfigId": {
"type": "string",
"description": "Must start with 'ccfg_'"
},
"showExisting": {
"type": "boolean",
"default": true
}
}
}
Expand Down Expand Up @@ -7564,7 +7552,7 @@
},
{
"in": "query",
"name": "driveGroupId",
"name": "drive_group_id",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -7659,14 +7647,14 @@
},
{
"in": "query",
"name": "driveId",
"name": "drive_id",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "folderId",
"name": "folder_id",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -7942,7 +7930,7 @@
},
{
"in": "query",
"name": "driveId",
"name": "drive_id",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -10024,7 +10012,8 @@
},
"created_at": {
"type": ["string", "null"]
}
},
"raw_data": {}
},
"required": ["id", "name"],
"description": "A unified representation of a drive group"
Expand All @@ -10046,7 +10035,8 @@
},
"created_at": {
"type": ["string", "null"]
}
},
"raw_data": {}
},
"required": ["id", "name"],
"description": "A unified representation of a storage drive"
Expand Down Expand Up @@ -10102,7 +10092,8 @@
},
"created_at": {
"type": ["string", "null"]
}
},
"raw_data": {}
},
"required": ["id", "type", "downloadable", "permissions", "exportable"],
"description": "A unified representation of a file"
Expand All @@ -10127,7 +10118,8 @@
},
"created_at": {
"type": ["string", "null"]
}
},
"raw_data": {}
},
"required": ["id", "name", "path"],
"description": "A unified representation of a folder"
Expand Down
Loading