Skip to content

Commit

Permalink
fix: Add zod schemas for app metadata living in config.json
Browse files Browse the repository at this point in the history
Fixes calcom#14808

Add zod schemas for app metadata in `config.json`.

* Import `appDataSchemas` and `appKeysSchemas` from `apps.schemas.generated` in `packages/app-store/appStoreMetaData.ts`.
* Use `appDataSchemas` and `appKeysSchemas` to parse the metadata in `packages/app-store/appStoreMetaData.ts`.
* Update the `appStoreMetadata` object to use the parsed metadata in `packages/app-store/appStoreMetaData.ts`.
* Import `appDataSchemas` and `appKeysSchemas` from `apps.schemas.generated` in `packages/app-store/getNormalizedAppMetadata.ts`.
* Use `appDataSchemas` and `appKeysSchemas` to parse the metadata in `packages/app-store/getNormalizedAppMetadata.ts`.
* Update the `getNormalizedAppMetadata` function to use the parsed metadata in `packages/app-store/getNormalizedAppMetadata.ts`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/calcom/cal.com/issues/14808?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
AritraDey-Dev committed Jan 6, 2025
1 parent f9dc788 commit b8f8cbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/app-store/appStoreMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AppMeta } from "@calcom/types/App";

import { appStoreMetadata as rawAppStoreMetadata } from "./apps.metadata.generated";
import { getNormalizedAppMetadata } from "./getNormalizedAppMetadata";
import { appDataSchemas, appKeysSchemas } from "./apps.schemas.generated";

type RawAppStoreMetaData = typeof rawAppStoreMetadata;
type AppStoreMetaData = {
Expand All @@ -10,5 +11,12 @@ type AppStoreMetaData = {

export const appStoreMetadata = {} as AppStoreMetaData;
for (const [key, value] of Object.entries(rawAppStoreMetadata)) {
appStoreMetadata[key as keyof typeof appStoreMetadata] = getNormalizedAppMetadata(value);
const appDataSchema = appDataSchemas[key as keyof typeof appDataSchemas];
const appKeysSchema = appKeysSchemas[key as keyof typeof appKeysSchemas];
const parsedMetadata = {
...value,
appData: appDataSchema.parse(value.appData),
key: appKeysSchema.parse(value.key),
};
appStoreMetadata[key as keyof typeof appStoreMetadata] = getNormalizedAppMetadata(parsedMetadata);
}
7 changes: 7 additions & 0 deletions packages/app-store/getNormalizedAppMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppMeta } from "@calcom/types/App";
import { appDataSchemas, appKeysSchemas } from "./apps.schemas.generated";

// We have to import all the booker-apps config/metadata in here as without that we couldn't
import type { appStoreMetadata as rawAppStoreMetadata } from "./apps.metadata.generated";
Expand All @@ -24,5 +25,11 @@ export const getNormalizedAppMetadata = (appMeta: RawAppStoreMetaData[keyof RawA
dirName,
isTemplate: metadata.isTemplate,
});

const appDataSchema = appDataSchemas[dirName as keyof typeof appDataSchemas];
const appKeysSchema = appKeysSchemas[dirName as keyof typeof appKeysSchemas];
metadata.appData = appDataSchema.parse(metadata.appData);
metadata.key = appKeysSchema.parse(metadata.key);

return metadata;
};

0 comments on commit b8f8cbc

Please sign in to comment.