refactor: circular deps between app store and lib [2] (#23734)
* mv getDefaultLocations * fix * 2 more utils * update imports * fix * move getConnectedApps * move handlePaymentSuccess * update imports * fix import * publish platform libraries
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
"@axiomhq/winston": "^1.2.0",
|
||||
"@calcom/platform-constants": "*",
|
||||
"@calcom/platform-enums": "*",
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.350",
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.351",
|
||||
"@calcom/platform-types": "*",
|
||||
"@calcom/platform-utils": "*",
|
||||
"@calcom/prisma": "*",
|
||||
|
||||
+4
-11
@@ -1,10 +1,9 @@
|
||||
import type { LocationObject } from "@calcom/app-store/locations";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import type { LocationObject } from "../locations";
|
||||
import { getAppFromSlug } from "../utils";
|
||||
|
||||
export const bulkUpdateEventsToDefaultLocation = async ({
|
||||
eventTypeIds,
|
||||
@@ -18,19 +17,13 @@ export const bulkUpdateEventsToDefaultLocation = async ({
|
||||
const defaultApp = userMetadataSchema.parse(user.metadata)?.defaultConferencingApp;
|
||||
|
||||
if (!defaultApp) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Default conferencing app not set",
|
||||
});
|
||||
throw new Error("Default conferencing app not set");
|
||||
}
|
||||
|
||||
const foundApp = getAppFromSlug(defaultApp.appSlug);
|
||||
const appType = foundApp?.appData?.location?.type;
|
||||
if (!appType) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `Default conferencing app '${defaultApp.appSlug}' doesnt exist.`,
|
||||
});
|
||||
throw new Error(`Default conferencing app '${defaultApp.appSlug}' doesnt exist.`);
|
||||
}
|
||||
|
||||
const credential = await prisma.credential.findFirst({
|
||||
+6
-12
@@ -1,9 +1,8 @@
|
||||
import type { LocationObject } from "@calcom/app-store/locations";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import type { LocationObject } from "../locations";
|
||||
import { getAppFromSlug } from "../utils";
|
||||
|
||||
export const bulkUpdateTeamEventsToDefaultLocation = async ({
|
||||
eventTypeIds,
|
||||
@@ -18,22 +17,17 @@ export const bulkUpdateTeamEventsToDefaultLocation = async ({
|
||||
where: { id: teamId },
|
||||
select: { metadata: true },
|
||||
});
|
||||
const defaultApp = teamMetadataSchema.parse(team?.metadata)?.defaultConferencingApp;
|
||||
const metadataResult = teamMetadataSchema.safeParse(team?.metadata);
|
||||
const defaultApp = metadataResult.success ? metadataResult.data?.defaultConferencingApp : null;
|
||||
|
||||
if (!defaultApp) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Default conferencing app not set",
|
||||
});
|
||||
throw new Error("Default conferencing app not set");
|
||||
}
|
||||
|
||||
const foundApp = getAppFromSlug(defaultApp.appSlug);
|
||||
const appType = foundApp?.appData?.location?.type;
|
||||
if (!appType) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `Default conferencing app '${defaultApp.appSlug}' doesnt exist.`,
|
||||
});
|
||||
throw new Error(`Default conferencing app '${defaultApp.appSlug}' doesnt exist.`);
|
||||
}
|
||||
|
||||
const credential = await prisma.credential.findFirst({
|
||||
@@ -1,19 +1,19 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import type { TDependencyData } from "@calcom/app-store/_appRegistry";
|
||||
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
|
||||
import type { CredentialOwner } from "@calcom/app-store/types";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials";
|
||||
import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
|
||||
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
import type { AppCategories } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import { buildNonDelegationCredentials } from "./delegationCredential/clientAndServer";
|
||||
import type { TDependencyData } from "../_appRegistry";
|
||||
import { PaymentServiceMap } from "../payment.services.generated";
|
||||
import type { CredentialOwner } from "../types";
|
||||
import { getAppFromSlug } from "../utils";
|
||||
|
||||
export type ConnectedApps = Awaited<ReturnType<typeof getConnectedApps>>;
|
||||
type InputSchema = {
|
||||
+4
-3
@@ -4,13 +4,12 @@ import { getGoogleMeetCredential, TestData } from "@calcom/web/test/utils/bookin
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { DailyLocationType, MeetLocationType } from "@calcom/app-store/locations";
|
||||
|
||||
import { DailyLocationType, MeetLocationType } from "../locations";
|
||||
import { getDefaultLocations } from "./getDefaultLocations";
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
email?: string;
|
||||
email: string;
|
||||
name?: string;
|
||||
metadata: {
|
||||
defaultConferencingApp?: {
|
||||
@@ -34,6 +33,7 @@ describe("getDefaultLocation ", async () => {
|
||||
it("should return location based on user default conferencing app", async () => {
|
||||
const user: User = {
|
||||
id: 101,
|
||||
email: "test@example.com",
|
||||
metadata: {
|
||||
defaultConferencingApp: {
|
||||
appSlug: "google-meet",
|
||||
@@ -53,6 +53,7 @@ describe("getDefaultLocation ", async () => {
|
||||
it("should return calvideo when default conferencing app is not set", async () => {
|
||||
const user: User = {
|
||||
id: 101,
|
||||
email: "test@example.com",
|
||||
metadata: {},
|
||||
};
|
||||
await mockUser(user);
|
||||
+8
-8
@@ -1,16 +1,16 @@
|
||||
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
||||
import { DailyLocationType } from "@calcom/app-store/constants";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeLocation } from "@calcom/prisma/zod/custom/eventtype";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
type SessionUser = NonNullable<TrpcSessionUser>;
|
||||
import { DailyLocationType } from "../constants";
|
||||
import getApps from "../utils";
|
||||
import getAppKeysFromSlug from "./getAppKeysFromSlug";
|
||||
|
||||
type User = {
|
||||
id: SessionUser["id"];
|
||||
email: SessionUser["email"];
|
||||
metadata: SessionUser["metadata"];
|
||||
id: number;
|
||||
email: string;
|
||||
metadata: Prisma.JsonValue;
|
||||
};
|
||||
|
||||
export async function getDefaultLocations(user: User): Promise<EventTypeLocation[]> {
|
||||
+1
-2
@@ -9,14 +9,13 @@ import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-pl
|
||||
import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getBooking } from "@calcom/lib/payment/getBooking";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import { eventTypeAppMetadataOptionalSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import logger from "../logger";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[handlePaymentSuccess]"] });
|
||||
export async function handlePaymentSuccess(paymentId: number, bookingId: number) {
|
||||
log.debug(`handling payment success for bookingId ${bookingId}`);
|
||||
@@ -2,12 +2,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import getRawBody from "raw-body";
|
||||
import { z } from "zod";
|
||||
|
||||
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
|
||||
import { albyCredentialKeysSchema } from "@calcom/app-store/alby/lib";
|
||||
import parseInvoice from "@calcom/app-store/alby/lib/parseInvoice";
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const config = {
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import getRawBody from "raw-body";
|
||||
import { z } from "zod";
|
||||
|
||||
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
|
||||
import { PrismaBookingPaymentRepository as BookingPaymentRepository } from "@calcom/lib/server/repository/PrismaBookingPaymentRepository";
|
||||
|
||||
import appConfig from "../config.json";
|
||||
|
||||
@@ -2,10 +2,10 @@ import { createHmac } from "crypto";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type z from "zod";
|
||||
|
||||
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { hitpayCredentialKeysSchema } from "../lib/hitpayCredentialKeysSchema";
|
||||
|
||||
@@ -2,12 +2,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import getRawBody from "raw-body";
|
||||
import { z } from "zod";
|
||||
|
||||
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
|
||||
import { paypalCredentialKeysSchema } from "@calcom/app-store/paypal/lib";
|
||||
import Paypal from "@calcom/app-store/paypal/lib/Paypal";
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const config = {
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
import type { ConnectedApps } from "_utils/getConnectedApps";
|
||||
import type React from "react";
|
||||
import type { z } from "zod";
|
||||
|
||||
import type { ConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
import type { EventTypeFormMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { ButtonProps } from "@calcom/ui/components/button";
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { buffer } from "micro";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type Stripe from "stripe";
|
||||
|
||||
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
|
||||
import { sendAttendeeRequestEmailAndSMS, sendOrganizerRequestEmail } from "@calcom/emails";
|
||||
import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/doesBookingRequireConfirmation";
|
||||
import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials";
|
||||
@@ -16,7 +17,6 @@ import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getBooking } from "@calcom/lib/payment/getBooking";
|
||||
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "../delegationCredential/server";
|
||||
|
||||
type SessionUser = NonNullable<TrpcSessionUser>;
|
||||
type User = { id: SessionUser["id"]; email: SessionUser["email"] };
|
||||
type User = { id: number; email: string };
|
||||
|
||||
/**
|
||||
* It includes in-memory DelegationCredential credentials as well.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import type { ConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ConnectedApps } from "@calcom/platform-libraries/app-store";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import { useAtomsContext } from "../../../hooks/useAtomsContext";
|
||||
|
||||
@@ -20,11 +20,11 @@ export type { App } from "@calcom/types/App";
|
||||
|
||||
export { getEnabledAppsFromCredentials };
|
||||
|
||||
export { getConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
export { getConnectedApps } from "@calcom/app-store/_utils/getConnectedApps";
|
||||
|
||||
export type { TServiceAccountKeySchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export type { ConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
export type { ConnectedApps } from "@calcom/app-store/_utils/getConnectedApps";
|
||||
|
||||
export type { AppsStatus } from "@calcom/types/Calendar";
|
||||
|
||||
|
||||
@@ -27,5 +27,5 @@ export type { EventTypesByViewer } from "@calcom/lib/event-types/getEventTypesBy
|
||||
export type { UpdateEventTypeReturn } from "@calcom/trpc/server/routers/viewer/eventTypes/heavy/update.handler";
|
||||
export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries/teams";
|
||||
|
||||
export { bulkUpdateEventsToDefaultLocation } from "@calcom/lib/bulkUpdateEventsToDefaultLocation";
|
||||
export { bulkUpdateTeamEventsToDefaultLocation } from "@calcom/lib/bulkUpdateTeamEventsToDefaultLocation";
|
||||
export { bulkUpdateEventsToDefaultLocation } from "@calcom/app-store/_utils/bulkUpdateEventsToDefaultLocation";
|
||||
export { bulkUpdateTeamEventsToDefaultLocation } from "@calcom/app-store/_utils/bulkUpdateTeamEventsToDefaultLocation";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
import { getConnectedApps } from "@calcom/app-store/_utils/getConnectedApps";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
|
||||
+18
-6
@@ -1,6 +1,8 @@
|
||||
import { bulkUpdateEventsToDefaultLocation } from "@calcom/lib/bulkUpdateEventsToDefaultLocation";
|
||||
import { bulkUpdateEventsToDefaultLocation } from "@calcom/app-store/_utils/bulkUpdateEventsToDefaultLocation";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../types";
|
||||
import type { TBulkUpdateToDefaultLocationInputSchema } from "./bulkUpdateToDefaultLocation.schema";
|
||||
|
||||
@@ -13,9 +15,19 @@ type BulkUpdateToDefaultLocationOptions = {
|
||||
|
||||
export const bulkUpdateToDefaultLocationHandler = ({ ctx, input }: BulkUpdateToDefaultLocationOptions) => {
|
||||
const { eventTypeIds } = input;
|
||||
return bulkUpdateEventsToDefaultLocation({
|
||||
eventTypeIds,
|
||||
user: ctx.user,
|
||||
prisma,
|
||||
});
|
||||
try {
|
||||
return bulkUpdateEventsToDefaultLocation({
|
||||
eventTypeIds,
|
||||
user: ctx.user,
|
||||
prisma,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import { getDefaultLocations } from "@calcom/app-store/_utils/getDefaultLocations";
|
||||
import { DailyLocationType } from "@calcom/app-store/constants";
|
||||
import { getDefaultLocations } from "@calcom/lib/server/getDefaultLocations";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
|
||||
@@ -2715,7 +2715,7 @@ __metadata:
|
||||
"@axiomhq/winston": ^1.2.0
|
||||
"@calcom/platform-constants": "*"
|
||||
"@calcom/platform-enums": "*"
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.350"
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.351"
|
||||
"@calcom/platform-types": "*"
|
||||
"@calcom/platform-utils": "*"
|
||||
"@calcom/prisma": "*"
|
||||
@@ -3774,13 +3774,13 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.350":
|
||||
version: 0.0.350
|
||||
resolution: "@calcom/platform-libraries@npm:0.0.350"
|
||||
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.351":
|
||||
version: 0.0.351
|
||||
resolution: "@calcom/platform-libraries@npm:0.0.351"
|
||||
dependencies:
|
||||
"@calcom/features": "*"
|
||||
"@calcom/lib": "*"
|
||||
checksum: 11c9cc5e33da21574a7b960dc488bfa989e807f020c5817c9dce0ec04ea6f74df05247ab321da99a8fd22cc82dceb5104ab4eea8fc25d70d982d6ddbff7bd848
|
||||
checksum: a0cab66796357a6fe006f3aeb782ad4dfe256a187312aa9e50287e0e8c0637c87ab289a57a660da7953bd6a6db7cec4616b981c90fbe350a4b0c1c14d2e0ef2d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user