From a1ef78a37a9ea02dea8393ac6d9437a121d8f950 Mon Sep 17 00:00:00 2001 From: "kentaro.amenomori" Date: Thu, 17 Jul 2025 14:46:51 +0900 Subject: [PATCH 1/2] feat: Implement pagination for database enabled clients update in connections --- src/tools/auth0/handlers/connections.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tools/auth0/handlers/connections.ts b/src/tools/auth0/handlers/connections.ts index 5caf6785..0290c29f 100644 --- a/src/tools/auth0/handlers/connections.ts +++ b/src/tools/auth0/handlers/connections.ts @@ -158,18 +158,24 @@ export const updateConnectionEnabledClients = async ( ): Promise => { if (!connectionId || !Array.isArray(enabledClientIds) || !enabledClientIds.length) return false; - const enabledClientUpdatePayload: Array = enabledClientIds.map( + const enabledClientUpdatePayloads: Array = enabledClientIds.map( (clientId) => ({ client_id: clientId, status: true, }) ); + const payloadChunks = _.chunk(enabledClientUpdatePayloads, 50); + try { - await auth0Client.connections.updateEnabledClients( - { - id: connectionId, - }, - enabledClientUpdatePayload + await Promise.all( + payloadChunks.map((payload) => + auth0Client.connections.updateEnabledClients( + { + id: connectionId, + }, + payload + ) + ) ); log.debug(`Updated enabled clients for ${typeName}: ${connectionId}`); return true; From e8bfa1bf4f12080b3f057b9a95d46cf422aa9048 Mon Sep 17 00:00:00 2001 From: "kentaro.amenomori" Date: Thu, 17 Jul 2025 19:04:19 +0900 Subject: [PATCH 2/2] test: Add test for updating enabled clients with more than 50 clients --- .../tools/auth0/handlers/connections.tests.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/tools/auth0/handlers/connections.tests.js b/test/tools/auth0/handlers/connections.tests.js index 432549c9..7ade638e 100644 --- a/test/tools/auth0/handlers/connections.tests.js +++ b/test/tools/auth0/handlers/connections.tests.js @@ -742,6 +742,36 @@ describe('#connections enabled clients functionality', () => { ] ); }); + + it('should update enabled clients with more than 50 clients', async () => { + const connectionId = 'con_123'; + const enabledClientIds = Array.from({ length: 60 }, (_, i) => `client_${i + 1}`); + const typeName = 'connection'; + + mockAuth0Client.connections.updateEnabledClients.resolves(); + + const result = await updateConnectionEnabledClients( + mockAuth0Client, + typeName, + connectionId, + enabledClientIds + ); + + expect(result).to.equal(true); + sinon.assert.calledTwice(mockAuth0Client.connections.updateEnabledClients); + + const firstCall = mockAuth0Client.connections.updateEnabledClients.getCall(0); + expect(firstCall.args[0]).to.deep.equal({ id: connectionId }); + expect(firstCall.args[1]).to.have.length(50); + expect(firstCall.args[1][0]).to.deep.equal({ client_id: 'client_1', status: true }); + expect(firstCall.args[1][49]).to.deep.equal({ client_id: 'client_50', status: true }); + + const secondCall = mockAuth0Client.connections.updateEnabledClients.getCall(1); + expect(secondCall.args[0]).to.deep.equal({ id: connectionId }); + expect(secondCall.args[1]).to.have.length(10); + expect(secondCall.args[1][0]).to.deep.equal({ client_id: 'client_51', status: true }); + expect(secondCall.args[1][9]).to.deep.equal({ client_id: 'client_60', status: true }); + }); }); describe('#processConnectionEnabledClients', () => {