Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
feat: allow listConnections to work with Supaglue sdk not just sdk-nango
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Feb 19, 2024
1 parent 684964a commit 5d34ccc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
44 changes: 39 additions & 5 deletions main/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import {featureFlags} from '@supaglue/vdk'
import {initNangoSDK} from '@opensdks/sdk-nango'
import {initSupaglueSDK} from '@opensdks/sdk-supaglue'
import {env} from '@/env'
import {NewConnection} from './NewConnection'

async function listConnections() {
if (env.SUPAGLUE_API_KEY && featureFlags.mode === 'supaglue') {
const supaglue = initSupaglueSDK({
headers: {'x-api-key': env.SUPAGLUE_API_KEY},
})
const cusRes = await supaglue.mgmt.GET('/customers')
const connections = await Promise.all(
cusRes.data.map((c) =>
supaglue.mgmt.GET('/customers/{customer_id}/connections', {
params: {path: {customer_id: c.customer_id}},
}),
),
).then((resArray) => resArray.flatMap((res) => res.data))
return connections.map((c) => ({
id: c.id,
connection_id: `customerId: ${c.customer_id}\n connectionId: ${c.id}`,
provider: c.provider_name,
// customer_id: c.customer_id,
}))
}
if (env.NANGO_SECRET_KEY && featureFlags.mode === 'nango') {
const nango = initNangoSDK({
headers: {authorization: `Bearer ${env.NANGO_SECRET_KEY}`},
})
const res = await nango.GET('/connection')
return res.data.connections.map((c) => ({
id: c.id,
provider: c.provider,
connection_id: c.connection_id,
// CustomerId does not exist in nango...
}))
}
throw new Error('Neither Supaglue nor nango is initialized')
}

export default async function Home() {
const nango = initNangoSDK({
headers: {authorization: `Bearer ${env.NANGO_SECRET_KEY}`},
})
const res = await nango.GET('/connection')
const connections = await listConnections()

return (
<main className="flex min-h-screen flex-col items-center p-24">
Expand All @@ -19,7 +53,7 @@ export default async function Home() {
</tr>
</thead>
<tbody>
{res.data.connections.map((connection) => (
{connections.map((connection) => (
<tr key={connection.id}>
<td>{connection.provider}</td>
<td>{connection.connection_id}</td>
Expand Down
2 changes: 2 additions & 0 deletions main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"dependencies": {
"@nangohq/frontend": "0.36.89",
"@opensdks/sdk-nango": "0.0.2",
"@opensdks/sdk-supaglue": "0.0.2",
"@supaglue/api": "workspace:*",
"@supaglue/sdk": "workspace:*",
"@supaglue/vdk": "workspace:*",
"@supaglue/worker": "workspace:*",
"@t3-oss/env-nextjs": "0.7.3",
"next": "14.0.3",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d34ccc

Please sign in to comment.