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

+86
View File
@@ -0,0 +1,86 @@
import { z } from "zod";
export const ComponentTextSize = z.enum(["S", "M", "L"]);
export type ComponentTextSize = z.infer<typeof ComponentTextSize>;
export const ComponentTextColor = z.enum(["NORMAL", "MUTED", "SUCCESS", "WARNING", "ERROR"]);
export type ComponentTextColor = z.infer<typeof ComponentTextColor>;
export const ComponentSpacerSize = z.enum(["XS", "S", "M", "L", "XL"]);
export type ComponentSpacerSize = z.infer<typeof ComponentSpacerSize>;
export const ComponentDividerSpacingSize = z.enum(["XS", "S", "M", "L", "XL"]);
export type ComponentDividerSpacingSize = z.infer<typeof ComponentDividerSpacingSize>;
export const ComponentBadgeColor = z.enum(["GREY", "GREEN", "YELLOW", "RED", "BLUE"]);
export type ComponentBadgeColor = z.infer<typeof ComponentBadgeColor>;
const Text = z.object({
textSize: ComponentTextSize.nullish(),
textColor: ComponentTextColor.nullish(),
text: z.string().min(1).max(5000),
});
const Divider = z.object({
dividerSpacingSize: ComponentDividerSpacingSize.nullish(),
});
const LinkButton = z.object({
linkButtonUrl: z.string().url(),
linkButtonLabel: z.string().max(500),
});
const Spacer = z.object({
spacerSize: ComponentSpacerSize,
});
const Badge = z.object({
badgeLabel: z.string().max(500),
badgeColor: ComponentBadgeColor.nullish(),
});
const CopyButton = z.object({
copyButtonValue: z.string().max(1000),
copyButtonTooltipLabel: z.string().max(500).nullish(),
});
const RowContentUnionInput = z.object({
componentText: Text.optional(),
componentDivider: Divider.optional(),
componentLinkButton: LinkButton.optional(),
componentSpacer: Spacer.optional(),
componentBadge: Badge.optional(),
componentCopyButton: CopyButton.optional(),
});
const Row = z.object({
rowMainContent: z.array(RowContentUnionInput),
rowAsideContent: z.array(RowContentUnionInput),
});
const ContainerContentUnionInput = z.object({
componentText: Text.optional(),
componentDivider: Divider.optional(),
componentLinkButton: LinkButton.optional(),
componentSpacer: Spacer.optional(),
componentBadge: Badge.optional(),
componentCopyButton: CopyButton.optional(),
componentRow: Row.optional(),
});
const Container = z.object({
containerContent: z.array(ContainerContentUnionInput).min(1),
});
export const Component = z.object({
componentText: Text.optional(),
componentDivider: Divider.optional(),
componentLinkButton: LinkButton.optional(),
componentSpacer: Spacer.optional(),
componentBadge: Badge.optional(),
componentCopyButton: CopyButton.optional(),
componentRow: Row.optional(),
componentContainer: Container.optional(),
});
export type Component = z.infer<typeof Component>;
@@ -0,0 +1,164 @@
/* eslint-disable import/no-anonymous-default-export */
import type { Card } from "@pages/api/plain";
export default (
email: string,
id: string,
username: string,
timeZone: string,
emailVerified: Date | null,
twoFactorEnabled: boolean | null
): Card => {
return {
key: "customer-card",
timeToLiveSeconds: null,
components: [
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "Email",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentText: {
text: email || "Unknown",
},
},
],
},
},
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "Email Verified?",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentBadge: {
badgeLabel: emailVerified === null ? "Unknown" : emailVerified ? "Yes" : "No",
badgeColor: emailVerified === null ? "YELLOW" : emailVerified ? "GREEN" : "RED",
},
},
],
},
},
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "Username",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentText: {
text: username || "Unknown",
},
},
],
},
},
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "User ID",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentText: {
text: id || "Unknown",
},
},
],
},
},
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "Time Zone",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentText: {
text: timeZone || "Unknown",
},
},
],
},
},
{
componentSpacer: {
spacerSize: "M",
},
},
{
componentRow: {
rowMainContent: [
{
componentText: {
text: "Two Factor Enabled?",
textColor: "MUTED",
},
},
],
rowAsideContent: [
{
componentBadge: {
badgeLabel: twoFactorEnabled === null ? "Unknown" : twoFactorEnabled ? "Yes" : "No",
badgeColor: twoFactorEnabled === null ? "YELLOW" : twoFactorEnabled ? "GREEN" : "RED",
},
},
],
},
},
],
};
};
@@ -0,0 +1,11 @@
import type { Card } from "@pages/api/plain";
import customerCardDisplay from "@pages/api/plain/customer-card-display";
export const cardExamples: ((
email: string,
id: string,
username: string,
timeZone: string,
emailVerified: Date | null,
twoFactorEnabled: boolean | null
) => Card)[] = [customerCardDisplay];
+15
View File
@@ -0,0 +1,15 @@
import { z } from "zod";
import { Component } from "./components";
export const Card = z.object({
key: z.string(),
timeToLiveSeconds: z.number().int().min(0).nullish().default(null),
components: z.array(Component).nullable(),
});
export type Card = z.infer<typeof Card>;
export const ResponseBody = z.object({
cards: z.array(Card),
});
export type ResponseBody = z.infer<typeof ResponseBody>;