Skip to content

Commit 9156848

Browse files
authored
refactor: circular deps between app store and lib [2] (calcom#23734)
* mv getDefaultLocations * fix * 2 more utils * update imports * fix * move getConnectedApps * move handlePaymentSuccess * update imports * fix import * publish platform libraries
1 parent 2e6ad8b commit 9156848

21 files changed

Lines changed: 66 additions & 69 deletions

File tree

apps/api/v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@axiomhq/winston": "^1.2.0",
3939
"@calcom/platform-constants": "*",
4040
"@calcom/platform-enums": "*",
41-
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.350",
41+
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.351",
4242
"@calcom/platform-types": "*",
4343
"@calcom/platform-utils": "*",
4444
"@calcom/prisma": "*",

packages/lib/bulkUpdateEventsToDefaultLocation.ts renamed to packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { LocationObject } from "@calcom/app-store/locations";
2-
import { getAppFromSlug } from "@calcom/app-store/utils";
31
import type { PrismaClient } from "@calcom/prisma";
42
import type { User } from "@calcom/prisma/client";
53
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
64

7-
import { TRPCError } from "@trpc/server";
5+
import type { LocationObject } from "../locations";
6+
import { getAppFromSlug } from "../utils";
87

98
export const bulkUpdateEventsToDefaultLocation = async ({
109
eventTypeIds,
@@ -18,19 +17,13 @@ export const bulkUpdateEventsToDefaultLocation = async ({
1817
const defaultApp = userMetadataSchema.parse(user.metadata)?.defaultConferencingApp;
1918

2019
if (!defaultApp) {
21-
throw new TRPCError({
22-
code: "BAD_REQUEST",
23-
message: "Default conferencing app not set",
24-
});
20+
throw new Error("Default conferencing app not set");
2521
}
2622

2723
const foundApp = getAppFromSlug(defaultApp.appSlug);
2824
const appType = foundApp?.appData?.location?.type;
2925
if (!appType) {
30-
throw new TRPCError({
31-
code: "BAD_REQUEST",
32-
message: `Default conferencing app '${defaultApp.appSlug}' doesnt exist.`,
33-
});
26+
throw new Error(`Default conferencing app '${defaultApp.appSlug}' doesnt exist.`);
3427
}
3528

3629
const credential = await prisma.credential.findFirst({

packages/lib/bulkUpdateTeamEventsToDefaultLocation.ts renamed to packages/app-store/_utils/bulkUpdateTeamEventsToDefaultLocation.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { LocationObject } from "@calcom/app-store/locations";
2-
import { getAppFromSlug } from "@calcom/app-store/utils";
31
import type { PrismaClient } from "@calcom/prisma";
42
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
53

6-
import { TRPCError } from "@trpc/server";
4+
import type { LocationObject } from "../locations";
5+
import { getAppFromSlug } from "../utils";
76

87
export const bulkUpdateTeamEventsToDefaultLocation = async ({
98
eventTypeIds,
@@ -18,22 +17,17 @@ export const bulkUpdateTeamEventsToDefaultLocation = async ({
1817
where: { id: teamId },
1918
select: { metadata: true },
2019
});
21-
const defaultApp = teamMetadataSchema.parse(team?.metadata)?.defaultConferencingApp;
20+
const metadataResult = teamMetadataSchema.safeParse(team?.metadata);
21+
const defaultApp = metadataResult.success ? metadataResult.data?.defaultConferencingApp : null;
2222

2323
if (!defaultApp) {
24-
throw new TRPCError({
25-
code: "BAD_REQUEST",
26-
message: "Default conferencing app not set",
27-
});
24+
throw new Error("Default conferencing app not set");
2825
}
2926

3027
const foundApp = getAppFromSlug(defaultApp.appSlug);
3128
const appType = foundApp?.appData?.location?.type;
3229
if (!appType) {
33-
throw new TRPCError({
34-
code: "BAD_REQUEST",
35-
message: `Default conferencing app '${defaultApp.appSlug}' doesnt exist.`,
36-
});
30+
throw new Error(`Default conferencing app '${defaultApp.appSlug}' doesnt exist.`);
3731
}
3832

3933
const credential = await prisma.credential.findFirst({

packages/lib/getConnectedApps.ts renamed to packages/app-store/_utils/getConnectedApps.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import type { Prisma } from "@prisma/client";
22

3-
import type { TDependencyData } from "@calcom/app-store/_appRegistry";
4-
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
5-
import type { CredentialOwner } from "@calcom/app-store/types";
6-
import { getAppFromSlug } from "@calcom/app-store/utils";
73
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
84
import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials";
95
import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
6+
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
107
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
118
import type { PrismaClient } from "@calcom/prisma";
129
import type { User } from "@calcom/prisma/client";
1310
import type { AppCategories } from "@calcom/prisma/enums";
1411
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
1512

16-
import { buildNonDelegationCredentials } from "./delegationCredential/clientAndServer";
13+
import type { TDependencyData } from "../_appRegistry";
14+
import { PaymentServiceMap } from "../payment.services.generated";
15+
import type { CredentialOwner } from "../types";
16+
import { getAppFromSlug } from "../utils";
1717

1818
export type ConnectedApps = Awaited<ReturnType<typeof getConnectedApps>>;
1919
type InputSchema = {

packages/lib/server/getDefaultLocations.test.ts renamed to packages/app-store/_utils/getDefaultLocations.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { getGoogleMeetCredential, TestData } from "@calcom/web/test/utils/bookin
44

55
import { describe, expect, it } from "vitest";
66

7-
import { DailyLocationType, MeetLocationType } from "@calcom/app-store/locations";
8-
7+
import { DailyLocationType, MeetLocationType } from "../locations";
98
import { getDefaultLocations } from "./getDefaultLocations";
109

1110
type User = {
1211
id: number;
13-
email?: string;
12+
email: string;
1413
name?: string;
1514
metadata: {
1615
defaultConferencingApp?: {
@@ -34,6 +33,7 @@ describe("getDefaultLocation ", async () => {
3433
it("should return location based on user default conferencing app", async () => {
3534
const user: User = {
3635
id: 101,
36+
email: "test@example.com",
3737
metadata: {
3838
defaultConferencingApp: {
3939
appSlug: "google-meet",
@@ -53,6 +53,7 @@ describe("getDefaultLocation ", async () => {
5353
it("should return calvideo when default conferencing app is not set", async () => {
5454
const user: User = {
5555
id: 101,
56+
email: "test@example.com",
5657
metadata: {},
5758
};
5859
await mockUser(user);

packages/lib/server/getDefaultLocations.ts renamed to packages/app-store/_utils/getDefaultLocations.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
2-
import { DailyLocationType } from "@calcom/app-store/constants";
3-
import getApps from "@calcom/app-store/utils";
41
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
2+
import type { Prisma } from "@calcom/prisma/client";
53
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
64
import type { EventTypeLocation } from "@calcom/prisma/zod/custom/eventtype";
7-
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
85

9-
type SessionUser = NonNullable<TrpcSessionUser>;
6+
import { DailyLocationType } from "../constants";
7+
import getApps from "../utils";
8+
import getAppKeysFromSlug from "./getAppKeysFromSlug";
9+
1010
type User = {
11-
id: SessionUser["id"];
12-
email: SessionUser["email"];
13-
metadata: SessionUser["metadata"];
11+
id: number;
12+
email: string;
13+
metadata: Prisma.JsonValue;
1414
};
1515

1616
export async function getDefaultLocations(user: User): Promise<EventTypeLocation[]> {

packages/lib/payment/handlePaymentSuccess.ts renamed to packages/app-store/_utils/payments/handlePaymentSuccess.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-pl
99
import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository";
1010
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
1111
import { HttpError as HttpCode } from "@calcom/lib/http-error";
12+
import logger from "@calcom/lib/logger";
1213
import { getBooking } from "@calcom/lib/payment/getBooking";
1314
import prisma from "@calcom/prisma";
1415
import { BookingStatus } from "@calcom/prisma/enums";
1516
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
1617
import { eventTypeAppMetadataOptionalSchema } from "@calcom/prisma/zod-utils";
1718

18-
import logger from "../logger";
19-
2019
const log = logger.getSubLogger({ prefix: ["[handlePaymentSuccess]"] });
2120
export async function handlePaymentSuccess(paymentId: number, bookingId: number) {
2221
log.debug(`handling payment success for bookingId ${bookingId}`);

packages/app-store/alby/api/webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
22
import getRawBody from "raw-body";
33
import { z } from "zod";
44

5+
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
56
import { albyCredentialKeysSchema } from "@calcom/app-store/alby/lib";
67
import parseInvoice from "@calcom/app-store/alby/lib/parseInvoice";
78
import { IS_PRODUCTION } from "@calcom/lib/constants";
89
import { getErrorFromUnknown } from "@calcom/lib/errors";
910
import { HttpError as HttpCode } from "@calcom/lib/http-error";
10-
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
1111
import prisma from "@calcom/prisma";
1212

1313
export const config = {

packages/app-store/btcpayserver/api/webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { NextApiRequest, NextApiResponse } from "next";
33
import getRawBody from "raw-body";
44
import { z } from "zod";
55

6+
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
67
import { IS_PRODUCTION } from "@calcom/lib/constants";
78
import { getErrorFromUnknown } from "@calcom/lib/errors";
89
import { HttpError as HttpCode } from "@calcom/lib/http-error";
9-
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
1010
import { PrismaBookingPaymentRepository as BookingPaymentRepository } from "@calcom/lib/server/repository/PrismaBookingPaymentRepository";
1111

1212
import appConfig from "../config.json";

packages/app-store/hitpay/api/webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { createHmac } from "crypto";
22
import type { NextApiRequest, NextApiResponse } from "next";
33
import type z from "zod";
44

5+
import { handlePaymentSuccess } from "@calcom/app-store/_utils/payments/handlePaymentSuccess";
56
import { IS_PRODUCTION } from "@calcom/lib/constants";
67
import { getErrorFromUnknown } from "@calcom/lib/errors";
78
import { HttpError as HttpCode } from "@calcom/lib/http-error";
8-
import { handlePaymentSuccess } from "@calcom/lib/payment/handlePaymentSuccess";
99
import prisma from "@calcom/prisma";
1010

1111
import type { hitpayCredentialKeysSchema } from "../lib/hitpayCredentialKeysSchema";

0 commit comments

Comments
 (0)