diff --git a/packages/core/package.json b/packages/core/package.json index 53ce95e16..21c86d02f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -93,7 +93,7 @@ "zod": "^3.22.4" }, "devDependencies": { - "@logto/cloud": "0.2.5-c6ed487", + "@logto/cloud": "0.2.5-faca9a9", "@silverhand/eslint-config": "5.0.0", "@silverhand/ts-config": "5.0.0", "@types/debug": "^4.1.7", diff --git a/packages/core/src/libraries/quota.ts b/packages/core/src/libraries/quota.ts index b353b4f00..45603bf4e 100644 --- a/packages/core/src/libraries/quota.ts +++ b/packages/core/src/libraries/quota.ts @@ -23,7 +23,7 @@ export const createQuotaLibrary = ( connectorLibrary: ConnectorLibrary ) => { const { - applications: { countAllApplications, countM2mApplications }, + applications: { countThirdPartyApplications, countAllApplications, countM2mApplications }, resources: { findTotalNumberOfResources }, hooks: { getTotalNumberOfHooks }, roles: { countRoles }, @@ -38,6 +38,7 @@ export const createQuotaLibrary = ( (queryKey?: string) => Promise<{ count: number }> > = { applicationsLimit: countAllApplications, + thirdPartyApplicationsLimit: countThirdPartyApplications, hooksLimit: getTotalNumberOfHooks, machineToMachineLimit: countM2mApplications, resourcesLimit: async () => { diff --git a/packages/core/src/queries/application.ts b/packages/core/src/queries/application.ts index 80dd295a1..37280a222 100644 --- a/packages/core/src/queries/application.ts +++ b/packages/core/src/queries/application.ts @@ -161,6 +161,16 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => { return { count: Number(count) }; }; + const countThirdPartyApplications = async () => { + const { count } = await pool.one<{ count: string }>(sql` + select count(*) + from ${table} + where ${fields.isThirdParty} = true + `); + + return { count: Number(count) }; + }; + const countM2mApplicationsByIds = async (search: Search, applicationIds: string[]) => { if (applicationIds.length === 0) { return { count: 0 }; @@ -228,6 +238,7 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => { return { countApplications, + countThirdPartyApplications, findApplications, findTotalNumberOfApplications, findApplicationById, diff --git a/packages/core/src/routes/applications/application.ts b/packages/core/src/routes/applications/application.ts index a80dddbee..674d677fe 100644 --- a/packages/core/src/routes/applications/application.ts +++ b/packages/core/src/routes/applications/application.ts @@ -151,6 +151,12 @@ export default function applicationRoutes( if (rest.type === ApplicationType.MachineToMachine) { await quota.guardKey('machineToMachineLimit'); } + + // Guard third party application limit + if (rest.isThirdParty) { + await quota.guardKey('thirdPartyApplicationsLimit'); + } + await quota.guardKey('applicationsLimit'); assertThat( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8bf061d39..aef265121 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3327,8 +3327,8 @@ importers: version: 3.22.4 devDependencies: '@logto/cloud': - specifier: 0.2.5-c6ed487 - version: 0.2.5-c6ed487(zod@3.22.4) + specifier: 0.2.5-faca9a9 + version: 0.2.5-faca9a9(zod@3.22.4) '@silverhand/eslint-config': specifier: 5.0.0 version: 5.0.0(eslint@8.44.0)(prettier@3.0.0)(typescript@5.3.3)