feat: Plain integration (#18130)

* revert: "fix: Request permissions to allow events to be created on shared Office365/Outlook calendars (#17760)"

This reverts commit 1680cba5a5.

* plain.com card

* detiled error handling for get customer

* working email and id

* hmac

* Revert "fix: correct line-breaks in calendar event description (#18077)"

This reverts commit 06494a6999.

* pr changes requet

* remove pan for now

* add-new-implementation-for-early-review

* Pushing fix for createHmac stringify

* added validation and user repository for email check

* add apiRouteMiddleware which handles the error handling

* HMAC_SECRET_KEY -> PLAIN_HMAC_SECRET_KEY

* Use the right error

* Convey right error to consumer

* Fixup apiRouteMiddleware to handle handler

* Don't export handler, only export POST

* changed to app directory

* working unkown user card

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Omar López <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-12-17 20:24:07 -05:00
1 parent 6b3ccbc61a
commit 63013d402e
10 files changed
+7455 -69

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { captureException } from "@sentry/nextjs";
import { ApiError } from "next/dist/server/api-utils";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getServerErrorFromUnknown } from "./getServerErrorFromUnknown";
export const apiRouteMiddleware =
(handler: (req: Request, res?: Response) => Promise<Response>) =>
async (req: NextRequest, res: NextResponse) => {
try {
return await handler(req, res);
} catch (error) {
if (error instanceof ApiError) {
return NextResponse.json({ message: error.message }, { status: error.statusCode });
} else {
const serverError = getServerErrorFromUnknown(error);
// we don't want to report Bad Request errors to Sentry / console
if (!(serverError.statusCode >= 400 && serverError.statusCode < 500)) {
console.error(error);
captureException(error);
}
return NextResponse.json(
{
message: serverError.message,
url: serverError.url,
method: serverError.method,
},
{
status: serverError.statusCode,
}
);
}
}
};
+10
View File
@@ -199,6 +199,16 @@ export class UserRepository {
return { where, profiles };
}
static async findByEmail({ email }: { email: string }) {
const user = await prisma.user.findUnique({
where: {
email: email.toLowerCase(),
},
select: userSelect,
});
return user;
}
static async findByEmailAndIncludeProfilesAndPassword({ email }: { email: string }) {
const user = await prisma.user.findUnique({
where: {