-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add revoke/create connections * add connected endpoint * delete * ignore * Add redirect back after auth * fix css * Improve css * Link to package * Improve fallback * Improve prompt * Add auth query headers * Add proxy rewriting
- Loading branch information
Showing
34 changed files
with
725 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ yarn-error.log* | |
next-env.d.ts | ||
|
||
.vscode | ||
TODO.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
import {useRouter} from 'next/navigation' | ||
|
||
import {jsonFetch} from '@/lib/json-fetch' | ||
import {UserConnection} from '@/server/db/user-connections/types' | ||
|
||
export function ConnectionItem({connection}: {connection: UserConnection}) { | ||
const router = useRouter() | ||
|
||
const onRevoke = async () => { | ||
if ( | ||
!confirm( | ||
`Are you sure you want to revoke this connection to ${connection.package_id}?`, | ||
) | ||
) { | ||
return | ||
} | ||
|
||
const {error} = await jsonFetch(`/api/connections/${connection.id}`, { | ||
method: 'DELETE', | ||
}) | ||
|
||
if (error) { | ||
alert(error.message) | ||
throw new Error(error.message ?? 'Unknown error') | ||
} | ||
|
||
router.refresh() | ||
} | ||
|
||
return ( | ||
<li className="grid max-w-sm grid-cols-3"> | ||
<Link | ||
prefetch={false} | ||
href={`/apis/${connection.package_id}`} | ||
className="text-sm font-medium text-blue-500" | ||
> | ||
{connection.package_id} | ||
</Link> | ||
|
||
<span className="col-span-2"> | ||
<button | ||
type="button" | ||
onClick={onRevoke} | ||
className="text-xs font-medium text-red-500" | ||
> | ||
Revoke | ||
</button> | ||
</span> | ||
</li> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use server' | ||
|
||
import {getConnectionsForUser} from '@/server/db/user-connections/getters' | ||
|
||
import {ConnectionItem} from './connection-item' | ||
|
||
export async function Connections({userId}: {userId: string}) { | ||
const connections = await getConnectionsForUser(userId) | ||
|
||
return ( | ||
<div> | ||
<ul> | ||
{connections.map((conn) => ( | ||
<ConnectionItem key={conn.id} connection={conn} /> | ||
))} | ||
</ul> | ||
|
||
{connections.length === 0 && ( | ||
<p className="text-sm text-slate-500">You don't have any connections yet.</p> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {ReactNode, Suspense} from 'react' | ||
|
||
export function Section({title, children}: {title: string; children: ReactNode}) { | ||
return ( | ||
<section className="space-y-3" id={dasherize(title)}> | ||
<h2 className="font-medium">{title}</h2> | ||
|
||
<Suspense fallback={<Fallback />}>{children}</Suspense> | ||
</section> | ||
) | ||
} | ||
|
||
function Fallback() { | ||
return ( | ||
<div className="grid max-w-sm grid-rows-3 gap-3 rounded-md bg-slate-50 p-3 dark:bg-white/5"> | ||
<div className="h-3 animate-pulse rounded-md bg-slate-200 dark:bg-slate-800"></div> | ||
<div className="h-3 animate-pulse rounded-md bg-slate-200 dark:bg-slate-800"></div> | ||
<div className="h-3 animate-pulse rounded-md bg-slate-200 dark:bg-slate-800"></div> | ||
</div> | ||
) | ||
} | ||
|
||
function dasherize(str: string) { | ||
return str.replace(/\s+/g, '-').toLowerCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {NextResponse} from 'next/server' | ||
|
||
import {assertString} from '@/lib/assert' | ||
import {deleteUserConnection} from '@/server/db/user-connections/setters' | ||
import {withAuth} from '@/server/helpers/auth' | ||
|
||
export const DELETE = withAuth( | ||
async ( | ||
req: Request, | ||
{userId, params}: {userId: string; params: {connectionId: string}}, | ||
) => { | ||
const {connectionId} = params | ||
|
||
assertString(userId, 'Invalid user') | ||
assertString(connectionId, 'Invalid connection id') | ||
|
||
await deleteUserConnection({userId, connectionId}) | ||
|
||
return NextResponse.json({success: true}) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {NextResponse} from 'next/server' | ||
import {z} from 'zod' | ||
|
||
import {parseJsonSpec} from '@/helpers/openapi' | ||
import {getPackageById} from '@/server/db/packages/getters' | ||
import {createUserConnection} from '@/server/db/user-connections/setters' | ||
import {withApiBuilder} from '@/server/helpers/api-builder' | ||
import {withAuth} from '@/server/helpers/auth' | ||
import {error} from '@/server/helpers/error' | ||
|
||
const ApiSchema = z.object({ | ||
package_id: z.string(), | ||
api_key: z.string().nullable(), | ||
}) | ||
|
||
type ApiRequestParams = z.infer<typeof ApiSchema> | ||
|
||
// Connects a user to a package | ||
|
||
export const POST = withAuth( | ||
withApiBuilder<ApiRequestParams, {userId: string}>( | ||
ApiSchema, | ||
async (req: Request, {userId, data}) => { | ||
const packageRow = await getPackageById(data.package_id) | ||
|
||
if (!packageRow) { | ||
return error('Package does not exist') | ||
} | ||
|
||
const _doc = await parseJsonSpec(packageRow.openapi) | ||
|
||
// Todo - validate the spec against | ||
// the auth provided | ||
|
||
const connection = await createUserConnection({ | ||
packageId: data.package_id, | ||
userId: userId, | ||
apiKey: data.api_key, | ||
}) | ||
|
||
return NextResponse.json({ | ||
id: connection.id, | ||
}) | ||
}, | ||
), | ||
) |
Oops, something went wrong.
2d467db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
openpm – ./
openpm-openpm.vercel.app
openpm-git-master-openpm.vercel.app
www.openpm.ai
openpm.vercel.app
openpm.ai
openpm.dev