Files
outline/plugins/gitlab/server/api/schema.ts
T
Tom Moor f50bb00b29 Refactor of OAuth account linking flows (#12246)
* Refactor of OAuth account linking flows

* PR feedback
2026-05-02 18:54:38 -04:00

42 lines
1.1 KiB
TypeScript

import isEmpty from "lodash/isEmpty";
import { z } from "zod";
import { BaseSchema } from "@server/routes/api/schema";
export const GitLabCallbackSchema = BaseSchema.extend({
query: z
.object({
code: z.string().nullish(),
state: z.string(),
error: z.string().nullish(),
})
.refine((req) => !(isEmpty(req.code) && isEmpty(req.error)), {
message: "one of code or error is required",
}),
});
export type GitLabCallbackReq = z.infer<typeof GitLabCallbackSchema>;
export const GitLabConnectSchema = BaseSchema.extend({
body: z
.object({
url: z.url().startsWith("https://").optional(),
clientId: z.string().optional(),
clientSecret: z.string().optional(),
})
.refine(
(data) => {
const { url, clientId, clientSecret } = data;
const allOrNone =
(url && clientId && clientSecret) ||
(!url && !clientId && !clientSecret);
return allOrNone;
},
{
message:
"Either all of url, clientId, and clientSecret must be provided, or none of them.",
}
),
});
export type GitLabConnectReq = z.infer<typeof GitLabConnectSchema>;