From 5263a7d2e30b2e6d034cfa443325075cc68f88d4 Mon Sep 17 00:00:00 2001 From: gustrb Date: Tue, 22 Oct 2024 14:28:24 -0300 Subject: [PATCH] chore: using object as parameter --- apps/meteor/app/apps/server/bridges/cloud.ts | 2 +- .../cloud/server/functions/getWorkspaceAccessToken.ts | 2 +- .../functions/getWorkspaceAccessTokenWithScope.ts | 10 +++++++++- apps/meteor/ee/server/apps/communication/rest.ts | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/cloud.ts b/apps/meteor/app/apps/server/bridges/cloud.ts index 30ca897240f8..0f908ccfe0a3 100644 --- a/apps/meteor/app/apps/server/bridges/cloud.ts +++ b/apps/meteor/app/apps/server/bridges/cloud.ts @@ -12,7 +12,7 @@ export class AppCloudBridge extends CloudWorkspaceBridge { public async getWorkspaceToken(scope: string, appId: string): Promise { this.orch.debugLog(`App ${appId} is getting the workspace's token`); - const token = await getWorkspaceAccessTokenWithScope(scope); + const token = await getWorkspaceAccessTokenWithScope({ scope }); return token; } diff --git a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts index d281121a7de9..6595c8e90fc4 100644 --- a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts +++ b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts @@ -42,7 +42,7 @@ export async function getWorkspaceAccessToken(forceNew = false, scope = '', save SystemLogger.debug(`Workspace credentials cache miss using scope: ${scope}, fetching new access token from cloud services.`); - const accessToken = await getWorkspaceAccessTokenWithScope(scope, throwOnError); + const accessToken = await getWorkspaceAccessTokenWithScope({ scope, throwOnError }); if (save) { await WorkspaceCredentials.updateCredentialByScope({ diff --git a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts index ec05937a8270..1137b899967a 100644 --- a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts +++ b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts @@ -14,7 +14,15 @@ type WorkspaceAccessTokenWithScope = { scope: string; }; -export async function getWorkspaceAccessTokenWithScope(scope = '', throwOnError = false): Promise { +type GetWorkspaceAccessTokenWithScopeParams = { + scope?: string; + throwOnError?: boolean; +}; + +export async function getWorkspaceAccessTokenWithScope({ + scope = '', + throwOnError = false, +}: GetWorkspaceAccessTokenWithScopeParams): Promise { const { workspaceRegistered } = await retrieveRegistrationStatus(); const tokenResponse = { token: '', expiresAt: new Date(), scope: '' }; diff --git a/apps/meteor/ee/server/apps/communication/rest.ts b/apps/meteor/ee/server/apps/communication/rest.ts index fc597d00857c..0283f2eef783 100644 --- a/apps/meteor/ee/server/apps/communication/rest.ts +++ b/apps/meteor/ee/server/apps/communication/rest.ts @@ -189,7 +189,7 @@ export class AppsRestApi { return API.v1.failure({ error: 'Invalid purchase type' }); } - const response = await getWorkspaceAccessTokenWithScope('marketplace:purchase'); + const response = await getWorkspaceAccessTokenWithScope({ scope: 'marketplace:purchase' }); if (!response.token) { return API.v1.failure({ error: 'Unauthorized' }); } @@ -289,7 +289,7 @@ export class AppsRestApi { return API.v1.failure({ error: 'Invalid purchase type' }); } - const token = await getWorkspaceAccessTokenWithScope('marketplace:purchase'); + const token = await getWorkspaceAccessTokenWithScope({ scope: 'marketplace:purchase' }); if (!token) { return API.v1.failure({ error: 'Unauthorized' }); }