-
Notifications
You must be signed in to change notification settings - Fork 12k
chore: disable apps with missing required keys #27012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+215
−3
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
00fae93
ci(companion): add separate typecheck workflow to catch type errors
devin-ai-integration[bot] f6f3c8f
add lint checks
anikdhabal 52b8c2d
test
anikdhabal bd6f376
remove
anikdhabal 947173a
update typecheck
anikdhabal f23fb98
Merge branch 'main' into devin/1768666328-add-companion-typecheck
anikdhabal 31f394b
address review
anikdhabal 0943377
chore:- hide apps with missing required keys from app store
anikdhabal 9c2e58e
update
anikdhabal fca2ef1
Merge branch 'main' into hide-apps-from-appstore
anikdhabal fda90b0
Delete packages/app-store/_utils/hasRequiredAppKeys.test.ts
anikdhabal fcf2aa1
Update validateAppKeys.ts
anikdhabal 2814ae1
Update validateAppKeys.ts
anikdhabal 1935b2e
Update validateAppKeys.test.ts
anikdhabal 740c987
Merge branch 'main' into hide-apps-from-appstore
anikdhabal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { shouldEnableApp } from "./validateAppKeys"; | ||
|
|
||
| describe("shouldEnableApp", () => { | ||
| describe("Apps without key schemas", () => { | ||
| it("should return true for apps that don't require keys", () => { | ||
| // Use a dirName that doesn't have a schema (e.g., a non-existent app) | ||
| const result = shouldEnableApp("non-existent-app", null); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true even if keys are null for apps without schemas", () => { | ||
| const result = shouldEnableApp("non-existent-app", null); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true even if keys are empty object for apps without schemas", () => { | ||
| const result = shouldEnableApp("non-existent-app", {}); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Apps with key schemas", () => { | ||
| it("should return false when keys are null", () => { | ||
| // dailyvideo requires api_key and has scale_plan with default | ||
| const result = shouldEnableApp("dailyvideo", null); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when keys are undefined", () => { | ||
| const result = shouldEnableApp("dailyvideo", undefined); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when keys is an empty object", () => { | ||
| // Empty object doesn't have required api_key field | ||
| const result = shouldEnableApp("dailyvideo", {}); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when keys is an array", () => { | ||
| const result = shouldEnableApp("dailyvideo", [] as any); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when keys is a string", () => { | ||
| const result = shouldEnableApp("dailyvideo", "invalid" as any); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when keys is a number", () => { | ||
| const result = shouldEnableApp("dailyvideo", 123 as any); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when required keys are missing", () => { | ||
| // Missing required api_key field | ||
| const result = shouldEnableApp("dailyvideo", { | ||
| scale_plan: "true", | ||
| }); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when required keys are empty strings", () => { | ||
| // api_key is empty string, which violates .min(1) | ||
| const result = shouldEnableApp("dailyvideo", { | ||
| api_key: "", | ||
| scale_plan: "false", | ||
| }); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return true when all required keys are present and valid", () => { | ||
| const result = shouldEnableApp("dailyvideo", { | ||
| api_key: "valid-api-key", | ||
| scale_plan: "false", | ||
| }); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true when required keys are present and optional fields use defaults", () => { | ||
| // scale_plan has a default, so we can omit it | ||
| const result = shouldEnableApp("dailyvideo", { | ||
| api_key: "valid-api-key", | ||
| }); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return false when keys have wrong types", () => { | ||
| // api_key should be string, not number | ||
| const result = shouldEnableApp("dailyvideo", { | ||
| api_key: 123 as any, | ||
| scale_plan: "false", | ||
| }); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Apps with multiple required fields", () => { | ||
| it("should return false when any required field is missing", () => { | ||
| // vital requires mode, region, api_key, and webhook_secret | ||
| const result = shouldEnableApp("vital", { | ||
| mode: "sandbox", | ||
| region: "us", | ||
| api_key: "test-key", | ||
| // Missing webhook_secret | ||
| }); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return true when all required fields are present", () => { | ||
| const result = shouldEnableApp("vital", { | ||
| mode: "sandbox", | ||
| region: "us", | ||
| api_key: "test-key", | ||
| webhook_secret: "test-secret", | ||
| }); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return false when any required field is empty", () => { | ||
| const result = shouldEnableApp("vital", { | ||
| mode: "", | ||
| region: "us", | ||
| api_key: "test-key", | ||
| webhook_secret: "test-secret", | ||
| }); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Apps with empty key schemas (user-configured apps like PayPal, GTM)", () => { | ||
| // These apps have `appKeysSchema = z.object({})` - they don't need server-side keys | ||
| // Users configure them after installation, so they should always be enabled | ||
|
|
||
| it("should return true for PayPal when keys are null", () => { | ||
| const result = shouldEnableApp("paypal", null); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true for PayPal when keys are undefined", () => { | ||
| const result = shouldEnableApp("paypal", undefined); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true for PayPal when keys are empty object", () => { | ||
| const result = shouldEnableApp("paypal", {}); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true for GTM when keys are null", () => { | ||
| const result = shouldEnableApp("gtm", null); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true for GTM when keys are undefined", () => { | ||
| const result = shouldEnableApp("gtm", undefined); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return true for GA4 when keys are null", () => { | ||
| const result = shouldEnableApp("ga4", null); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { appKeysSchemas } from "@calcom/app-store/apps.keys-schemas.generated"; | ||
| import type { Prisma } from "@calcom/prisma/client"; | ||
| /** | ||
| * Determines if an app should be enabled based on whether it has valid keys. | ||
| * This is used by app registration scripts to prevent enabling apps without proper configuration. | ||
| * | ||
| * @param dirName - The directory name of the app | ||
| * @param keys - The keys object (can be undefined/null) | ||
| */ | ||
| export function shouldEnableApp(dirName: string, keys?: Prisma.JsonValue | null): boolean { | ||
| const keySchema = appKeysSchemas[dirName as keyof typeof appKeysSchemas]; | ||
|
|
||
| // If no schema, the app doesn't require keys - can be enabled | ||
| if (!keySchema) { | ||
| return true; | ||
| } | ||
|
|
||
| // If keys is null/undefined, check if the schema accepts an empty object. | ||
| if (keys === null || keys === undefined) { | ||
| const emptyObjectResult = keySchema.safeParse({}); | ||
| return emptyObjectResult.success; | ||
| } | ||
|
|
||
|
|
||
| // Validate keys against schema | ||
| const result = keySchema.safeParse(keys); | ||
| return result.success; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.