Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(auth): publish the allowedChats bound in the API schema
Yudhi Armyndharis2b272cd93804
diff --git a/openapi.json b/openapi.jsonindex c8ef1f718..b30053b51 100644--- a/openapi.json+++ b/openapi.json@@ -18196,6 +18196,7 @@],+ "maxItems": 2000,"type": "array","items": {"type": "string"@@ -18382,6 +18383,7 @@}},"allowedChats": {+ "maxItems": 2000,"type": "array","items": {"type": "string"diff --git a/src/modules/auth/dto/api-key.dto.spec.ts b/src/modules/auth/dto/api-key.dto.spec.tsindex 6c6189668..3f32058b2 100644--- a/src/modules/auth/dto/api-key.dto.spec.ts+++ b/src/modules/auth/dto/api-key.dto.spec.ts@@ -13,6 +13,7 @@ const property = (dto: object, name: string) =>nullable?: boolean;minLength?: number;maxLength?: number;+ maxItems?: number;};describe('API key DTO contract', () => {@@ -39,6 +40,11 @@ describe('API key DTO contract', () => {expect(property(dto.prototype, 'name')).toEqual(expect.objectContaining({ minLength: 3, maxLength: 100 }));});+ // @ArrayMaxSize is runtime-only: a client generated from the schema learns the bound from maxItems or not at all.+ it.each([CreateApiKeyDto, UpdateApiKeyDto])('publishes the allowedChats bound of %p', dto => {+ expect(property(dto.prototype, 'allowedChats').maxItems).toBe(ALLOWED_CHATS_MAX);+ });+it.each([CreateApiKeyDto, UpdateApiKeyDto])('bounds the allowedChats list of %p', async dto => {// Search binds one SQL parameter per expanded id and a socket holds at most 4096 rooms, two address// forms per phone, so an unbounded list made search answer 500 and every subscribe refuse.diff --git a/src/modules/auth/dto/api-key.dto.ts b/src/modules/auth/dto/api-key.dto.tsindex 8d1d736d6..bcd516643 100644--- a/src/modules/auth/dto/api-key.dto.ts+++ b/src/modules/auth/dto/api-key.dto.ts@@ -75,6 +75,9 @@ export class CreateApiKeyDto {'A contact entry also matches its resolved `@lid` form (and vice versa) through the lid mapping ' +'table. Omit or leave empty to let the key reach every chat.',example: ['[email protected]', '[email protected]'],+ // @ArrayMaxSize is runtime-only; without this the schema, and every client generated from it,+ // advertises an unbounded list and learns the limit from a 400.+ maxItems: ALLOWED_CHATS_MAX,})@IsOptional()@IsArray()@@ -190,7 +193,7 @@ export class UpdateApiKeyDto {@Validate(IsSessionIdConstraint, { each: true })allowedSessions?: string[];- @ApiPropertyOptional()+ @ApiPropertyOptional({ maxItems: ALLOWED_CHATS_MAX })@IsOptional()@IsArray()@ArrayMaxSize(ALLOWED_CHATS_MAX)