From 6aeb7f02016a715c5bcac9b701f86620cb5351af Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 19 Jul 2024 13:31:47 -0300 Subject: [PATCH] feat: load limits from server --- src/core/index.ts | 19 +++---------------- src/services/api/index.test.ts | 20 +++++++++++--------- src/services/api/index.ts | 18 +++++++----------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/core/index.ts b/src/core/index.ts index 100def89..a5a55b92 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -107,9 +107,10 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise { throw new Error('Failed to load configuration from server'); }); @@ -129,21 +130,7 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise { return { @@ -209,7 +209,7 @@ describe('ApiService', () => { const baseUrl = 'https://dev.nodeapi.superviz.com'; const response = await ApiService.fetchLimits(baseUrl, VALID_API_KEY); - expect(response).toEqual(CHECK_LIMITS_MOCK.usage); + expect(response).toEqual(CHECK_LIMITS_MOCK.limits); }); }); @@ -217,7 +217,9 @@ describe('ApiService', () => { test('should return the participants', async () => { const response = await ApiService.fetchParticipantsByGroup('any_group_id'); - expect(response).toEqual([{"avatar": null, "id": "any_user_id", "name": "any_name", "email": "any_email"}]); + expect(response).toEqual([ + { avatar: null, id: 'any_user_id', name: 'any_name', email: 'any_email' }, + ]); }); }); @@ -225,10 +227,10 @@ describe('ApiService', () => { test('should create a mention', async () => { const response = await ApiService.createMentions({ commentsId: 'any_comment_id', - participants: [] + participants: [], }); expect(response).toEqual({}); }); - }) + }); }); diff --git a/src/services/api/index.ts b/src/services/api/index.ts index f549bf3e..83a84f55 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -2,14 +2,14 @@ import { SuperVizSdkOptions } from '../../common/types/sdk-options.types'; import { doRequest } from '../../common/utils'; import { Annotation } from '../../components/comments/types'; import config from '../config'; - +import { ComponentLimits } from '../limits/types'; import { AnnotationParams, CommentParams, CreateOrUpdateParticipantParams, FetchAnnotationsParams, - MentionParams + MentionParams, } from './types'; export default class ApiService { @@ -32,11 +32,11 @@ export default class ApiService { return doRequest(url, 'POST', { apiKey }); } - static async fetchLimits(baseUrl: string, apikey: string) { - const path: string = '/user/check_limits'; + static async fetchLimits(baseUrl: string, apikey: string): Promise { + const path: string = '/user/check_limits_v2'; const url: string = this.createUrl(baseUrl, path); const result = await doRequest(url, 'GET', '', { apikey }); - return result.usage; + return result.limits; } static async fetchWaterMark(baseUrl: string, apiKey: string) { @@ -130,18 +130,14 @@ export default class ApiService { return doRequest(url, 'POST', body, { apikey }); } - static async fetchParticipantsByGroup( - groupId: string, - ) { + static async fetchParticipantsByGroup(groupId: string) { const path = `/groups/participants/${groupId}`; const baseUrl = config.get('apiUrl'); const url = this.createUrl(baseUrl, path, { take: 10000 }); return doRequest(url, 'GET', undefined, { apikey: config.get('apiKey') }); } - static async createMentions( - mentionParams: MentionParams - ) { + static async createMentions(mentionParams: MentionParams) { const path = '/mentions'; const baseUrl = config.get('apiUrl'); const url = this.createUrl(baseUrl, path);