From 491f00806955d22d73d10e0ab2d5cee1f6beff55 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Thu, 13 Mar 2025 14:45:54 +0530 Subject: [PATCH 01/10] feat:error handling and region support Signed-off-by: Amitkanswal --- src/types.ts | 3 ++ src/types/api.type.ts | 22 ++++++++++-- src/uiLocation.ts | 12 +++++-- src/utils/adapter.ts | 80 +++++++++++++++++++++++++++---------------- src/utils/utils.ts | 38 ++++++++++++++++---- 5 files changed, 113 insertions(+), 42 deletions(-) diff --git a/src/types.ts b/src/types.ts index 25110f9..ac5b923 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,7 @@ import { GenericObjectType } from "./types/common.types"; import { Entry } from "./types/entry.types"; import { Asset, ContentType, Schema, StackDetail } from "./types/stack.types"; import { OrganizationDetails } from "./types/organization.types"; +import { ServiceURLsMap } from './types/api.type'; import { User } from "./types/user.types"; import Window from "./window"; @@ -102,6 +103,7 @@ declare interface ICommonInitData { type: LocationType; user: User; manifest?: Manifest; + serviceDomainUrls?: ServiceURLsMap; } export declare interface IOrgFullPageLocationInitData extends ICommonInitData { @@ -254,4 +256,5 @@ export enum Region { AZURE_NA = "AZURE_NA", AZURE_EU = "AZURE_EU", GCP_NA = "GCP_NA", + GCP_EU = "GCP_EU", } diff --git a/src/types/api.type.ts b/src/types/api.type.ts index 4a6c773..5309681 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -1,3 +1,19 @@ -import { AxiosRequestConfig, AxiosResponse, } from 'axios' -export type RequestConfig = AxiosRequestConfig -export type ProxyResponse = AxiosResponse \ No newline at end of file +import { AxiosRequestConfig, AxiosResponse } from "axios"; +export type RequestConfig = AxiosRequestConfig; +export type ProxyResponse = AxiosResponse; + +export type ServiceURLsMap = { + CMA: string; +}; + +enum SupportedServices { + CMA = "CMA", +} + +export type RequestInitConfig = RequestInit & { + service?: keyof typeof SupportedServices; +}; + +export type RequestConfigWithBaseUrl = RequestInitConfig & { + baseURL: string; +}; diff --git a/src/uiLocation.ts b/src/uiLocation.ts index 6ef9f94..f70f5d9 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -1,3 +1,4 @@ +import { AxiosRequestConfig, AxiosResponse } from 'axios'; import postRobot from "post-robot"; import EventEmitter from "wolfy87-eventemitter"; @@ -34,7 +35,7 @@ import { User } from "./types/user.types"; import { formatAppRegion, onData, onError } from "./utils/utils"; import Window from "./window"; import { dispatchApiRequest, dispatchAdapter } from './utils/adapter'; -import { AxiosRequestConfig, AxiosResponse } from 'axios'; +import { RequestInitConfig, ServiceURLsMap } from "./types/api.type"; const emitter = new EventEmitter(); @@ -69,6 +70,9 @@ class UiLocation { */ private config: GenericObjectType; + + readonly hostedEndpoints: ServiceURLsMap + /** * This holds the instance of Cross-domain communication library for posting messages between windows. */ @@ -154,7 +158,7 @@ class UiLocation { }); this.metadata = new Metadata(postRobot); - + this.config = initializationData.config ?? {}; this.ids = { @@ -186,6 +190,8 @@ class UiLocation { this.region = formatAppRegion(initializationData.region); + this.hostedEndpoints = initializationData.serviceDomainUrls ?? { CMA: '' }; + const stack = new Stack(initializationData.stack, postRobot, { currentBranch: initializationData.currentBranch, }); @@ -476,7 +482,7 @@ class UiLocation { * Method used to make an API request to the Contentstack's CMA APIs. */ - api = (url: string, option?: RequestInit): Promise => dispatchApiRequest(url, option) as Promise; + api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url,this.hostedEndpoints, option) as Promise; /** * Method used to create an adapter for management sdk. diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 62b334f..1124695 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -1,47 +1,69 @@ -import PostRobot from 'post-robot'; -import { AxiosRequestConfig, AxiosResponse } from 'axios'; -import { onError, fetchToAxiosConfig } from './utils'; +import PostRobot from "post-robot"; +import { AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; + +import { onError, fetchToAxiosConfig, serializeAxiosResponse } from "./utils"; +import { RequestInitConfig, ServiceURLsMap } from "../types/api.type"; + +export const resolveBaseUrl = (hostingRegion:ServiceURLsMap, option?:RequestInitConfig)=>{ +return option?.service? hostingRegion[option.service]: hostingRegion.CMA +} + /** * Dispatches a request using PostRobot. * @param postRobot - The PostRobot instance. * @returns A function that takes AxiosRequestConfig and returns a promise. */ -export const dispatchAdapter = (postRobot: typeof PostRobot) => (config: AxiosRequestConfig)=> { +export const dispatchAdapter = (postRobot: typeof PostRobot) => (config: AxiosRequestConfig): Promise => { return postRobot - .sendToParent("apiAdapter", config ) - .then(({ data }) => ({ ...data, config })) + .sendToParent("apiAdapter", config) + .then((event:unknown) => { + const { data } = event as { data: AxiosResponse }; + if (data.status >= 400) { + throw serializeAxiosResponse(data, config); + } + return serializeAxiosResponse(data, config); + }) .catch(onError); }; - /** * Dispatches an API request using axios and PostRobot. * @param url - The URL of the API endpoint. * @param options - Optional request options. * @returns A promise that resolves to a partial Response object. */ -export const dispatchApiRequest = async (url: string, options?: RequestInit): Promise => { - try { - const config = fetchToAxiosConfig(url, options); - const responseData = await dispatchAdapter(PostRobot)(config) as AxiosResponse; - return new Response(responseData.data,{ - status: responseData.status, - statusText: responseData.statusText, - headers: new Headers(responseData.config.headers || {}), - }); +export const dispatchApiRequest = async ( + url: string, + hostedUrl:ServiceURLsMap, + options?: RequestInitConfig, +): Promise => { + try { + const updatedOptions = {...options, baseURL: resolveBaseUrl(hostedUrl, options)}; + const config = fetchToAxiosConfig(url, updatedOptions); + const responseData = (await dispatchAdapter(PostRobot)( + config + )) as AxiosResponse; + + if (isAxiosError(responseData)) { + throw responseData; + } + const response = new Response(responseData?.data, { + status: responseData.status, + statusText: responseData.statusText, + headers: new Headers(responseData.config.headers || {}), + }); + return response + + } catch (error: any) { + const data = error.response?.data || error.data; + const status = error.response?.status || error.status || 500; + const statusText = error.response?.statusText || error.statusText || "Internal Server Error"; + const headers = new Headers(error.response?.headers || error.headers); - } catch (error: any) { - if (error.response) { - const fetchResponse = new Response(error.response.data, { - status: error.response.status, - statusText: error.response.statusText, - headers: new Headers(error.response.headers) + throw new Response(data, { + status, + statusText, + headers, }); - return Promise.reject(fetchResponse); - } else if (error.request) { - return Promise.reject(new Response(null, { status: 0, statusText: 'Network Error' })); - } else { - return Promise.reject(new Response(null, { status: 0, statusText: error.message })); - } } -}; \ No newline at end of file +}; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index f9cffbe..40ed0d5 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,5 +1,6 @@ import { Region } from "../types"; -import { AxiosHeaders, AxiosRequestConfig } from "axios"; +import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from "axios"; +import { RequestConfigWithBaseUrl } from '../types/api.type'; export function onData>(data: { data: Data }) { if (typeof data.data === "string") { @@ -50,6 +51,14 @@ export function getPreferredBodyElement(nodeCollection: HTMLCollection) { return rootElement || nodeCollection[0]; } +function isAbsoluteURL(url) { + try { + new URL(url); + return true; + } catch (e) { + return false; + } +} export const convertHeaders = (headers: HeadersInit): AxiosHeaders => { const axiosHeaders = new AxiosHeaders(); @@ -69,17 +78,32 @@ export const convertHeaders = (headers: HeadersInit): AxiosHeaders => { return axiosHeaders; }; - export const fetchToAxiosConfig = (url: string, options: RequestInit = {}): AxiosRequestConfig => { + export const fetchToAxiosConfig = (url: string ,options?: RequestConfigWithBaseUrl): AxiosRequestConfig => { + const axiosConfig: AxiosRequestConfig = { url, - method: options.method || 'GET', - headers: options.headers ? convertHeaders({...options.headers}) : {}, - data: options.body, + method: options?.method || 'GET', + headers: options?.headers ? convertHeaders({...options?.headers}) : {}, + data: options?.body, }; - - if (options.credentials === 'include') { + + if (!isAbsoluteURL(url)) { + axiosConfig.baseURL = options?.baseURL; + } + + if (options?.credentials === 'include') { axiosConfig.withCredentials = true; } return axiosConfig; + } + + export const serializeAxiosResponse = (responseData: AxiosResponse, config) => { + return { + data: responseData.data, + status: responseData.status, + statusText: responseData.statusText, + headers: responseData.headers as AxiosHeaders, + config, + } } \ No newline at end of file From 32c27fa895d91e9d51dedc52456d4a0cd878e80c Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Thu, 13 Mar 2025 15:29:31 +0530 Subject: [PATCH 02/10] fix:snyk fix --- package-lock.json | 335 ++++++++++++---------------------------------- yarn.lock | 157 +++++++--------------- 2 files changed, 130 insertions(+), 362 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0a71ee7..9d7088e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,12 +53,13 @@ "dev": true }, "node_modules/@babel/code-frame": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", - "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.7", + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", "picocolors": "^1.0.0" }, "engines": { @@ -384,18 +385,18 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", - "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", - "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", "dev": true, "engines": { "node": ">=6.9.0" @@ -426,41 +427,25 @@ } }, "node_modules/@babel/helpers": { - "version": "7.15.4", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.15.4.tgz", - "integrity": "sha512-V45u6dqEJ3w2rlryYYXf6i9rQ5YMNu4FLS6ngs8ikblhu2VdR1AqAd6aJjBzmf2Qzh6KOLqKHxEN9+TFbAkAVQ==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.10.tgz", + "integrity": "sha512-UPYc3SauzZ3JGgj87GgZ89JVdC5dj0AoetR5Bw6wj4niittNyFh6+eOGonYvJ1ao6B8lEa3Q3klS7ADZ53bc5g==", "dev": true, "dependencies": { - "@babel/template": "^7.15.4", - "@babel/traverse": "^7.15.4", - "@babel/types": "^7.15.4" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/highlight": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", - "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", - "dev": true, - "dependencies": { - "@babel/helper-validator-identifier": "^7.24.7", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "@babel/template": "^7.26.9", + "@babel/types": "^7.26.10" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/parser": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz", - "integrity": "sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.10.tgz", + "integrity": "sha512-6aQR2zGE/QFi8JpDLjUZEPYOs7+mhKXm86VaKFiLP35JQwQb6bwUE+XbvkH0EptsYhbNBSUGaUBLKqxH1xSgsA==", "dev": true, "dependencies": { - "@babel/types": "^7.25.6" + "@babel/types": "^7.26.10" }, "bin": { "parser": "bin/babel-parser.js" @@ -1558,26 +1543,26 @@ } }, "node_modules/@babel/runtime": { - "version": "7.20.1", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.1.tgz", - "integrity": "sha512-mrzLkl6U9YLF8qpqI7TB82PESyEGjm/0Ly91jG575eVxMMlb8fYfOXFZIJ8XfLrJZQbm7dlKry2bJmXBUEkdFg==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.10.tgz", + "integrity": "sha512-2WJMeRQPHKSPemqk/awGrAiuFfzBmOIPXKizAsVhWH9YJqLZ0H+HS4c8loHGgW6utJ3E/ejXQUsiGaQy2NZ9Fw==", "dev": true, "dependencies": { - "regenerator-runtime": "^0.13.10" + "regenerator-runtime": "^0.14.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/template": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", - "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", + "version": "7.26.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.26.9.tgz", + "integrity": "sha512-qyRplbeIpNZhmzOysF/wFMuP9sctmh2cFzRAZOn1YapxBsE1i9bJIY586R/WBLfLcmcBlM8ROBiQURnnNy+zfA==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/parser": "^7.25.0", - "@babel/types": "^7.25.0" + "@babel/code-frame": "^7.26.2", + "@babel/parser": "^7.26.9", + "@babel/types": "^7.26.9" }, "engines": { "node": ">=6.9.0" @@ -1602,14 +1587,13 @@ } }, "node_modules/@babel/types": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz", - "integrity": "sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.10.tgz", + "integrity": "sha512-emqcG3vHrpxUKTrxcblR36dcrcoRDvKmnL/dCL6ZsHaShW80qxCAcNhzQZrpeM765VzEos+xOi4s+r4IXzTwdQ==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.8", - "@babel/helper-validator-identifier": "^7.24.7", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -3703,18 +3687,6 @@ "node": ">=8" } }, - "node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/anymatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", @@ -3800,9 +3772,9 @@ } }, "node_modules/axios": { - "version": "1.7.9", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", - "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.3.tgz", + "integrity": "sha512-iP4DebzoNlP/YN2dpwCgb8zoCmhtkajzS48JvwmkSkXvPI3DHc7m+XYL5tGnSlJtR6nImXZmdCuN5aP8dh1d8A==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -4322,20 +4294,6 @@ "node": ">=4" } }, - "node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/char-regex": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", @@ -4554,21 +4512,6 @@ "integrity": "sha512-iBPtljfCNcTKNAto0KEtDfZ3qzjJvqE3aTGZsbhjSBlorqpXJlaWWtPO35D+ZImoC3KWejX64o+yPGxhWSTzfg==", "dev": true }, - "node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, "node_modules/colorette": { "version": "2.0.19", "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz", @@ -5353,15 +5296,6 @@ "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", "dev": true }, - "node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/escodegen": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.0.0.tgz", @@ -6444,15 +6378,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -10682,9 +10607,9 @@ } }, "node_modules/regenerator-runtime": { - "version": "0.13.10", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.10.tgz", - "integrity": "sha512-KepLsg4dU12hryUO7bp/axHAKvwGOCV0sGloQtpagJ12ai+ojVDqkeGSiRX1zlq+kjIMZ1t7gpze+26QqtdGqw==", + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", "dev": true }, "node_modules/regenerator-transform": { @@ -11600,18 +11525,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/supports-hyperlinks": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz", @@ -11797,15 +11710,6 @@ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -13060,12 +12964,13 @@ "dev": true }, "@babel/code-frame": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", - "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, "requires": { - "@babel/highlight": "^7.24.7", + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", "picocolors": "^1.0.0" } }, @@ -13309,15 +13214,15 @@ } }, "@babel/helper-string-parser": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", - "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", "dev": true }, "@babel/helper-validator-identifier": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", - "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", "dev": true }, "@babel/helper-validator-option": { @@ -13339,35 +13244,22 @@ } }, "@babel/helpers": { - "version": "7.15.4", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.15.4.tgz", - "integrity": "sha512-V45u6dqEJ3w2rlryYYXf6i9rQ5YMNu4FLS6ngs8ikblhu2VdR1AqAd6aJjBzmf2Qzh6KOLqKHxEN9+TFbAkAVQ==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.10.tgz", + "integrity": "sha512-UPYc3SauzZ3JGgj87GgZ89JVdC5dj0AoetR5Bw6wj4niittNyFh6+eOGonYvJ1ao6B8lEa3Q3klS7ADZ53bc5g==", "dev": true, "requires": { - "@babel/template": "^7.15.4", - "@babel/traverse": "^7.15.4", - "@babel/types": "^7.15.4" - } - }, - "@babel/highlight": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", - "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", - "dev": true, - "requires": { - "@babel/helper-validator-identifier": "^7.24.7", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "@babel/template": "^7.26.9", + "@babel/types": "^7.26.10" } }, "@babel/parser": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz", - "integrity": "sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.10.tgz", + "integrity": "sha512-6aQR2zGE/QFi8JpDLjUZEPYOs7+mhKXm86VaKFiLP35JQwQb6bwUE+XbvkH0EptsYhbNBSUGaUBLKqxH1xSgsA==", "dev": true, "requires": { - "@babel/types": "^7.25.6" + "@babel/types": "^7.26.10" } }, "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": { @@ -14099,23 +13991,23 @@ } }, "@babel/runtime": { - "version": "7.20.1", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.1.tgz", - "integrity": "sha512-mrzLkl6U9YLF8qpqI7TB82PESyEGjm/0Ly91jG575eVxMMlb8fYfOXFZIJ8XfLrJZQbm7dlKry2bJmXBUEkdFg==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.10.tgz", + "integrity": "sha512-2WJMeRQPHKSPemqk/awGrAiuFfzBmOIPXKizAsVhWH9YJqLZ0H+HS4c8loHGgW6utJ3E/ejXQUsiGaQy2NZ9Fw==", "dev": true, "requires": { - "regenerator-runtime": "^0.13.10" + "regenerator-runtime": "^0.14.0" } }, "@babel/template": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", - "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", + "version": "7.26.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.26.9.tgz", + "integrity": "sha512-qyRplbeIpNZhmzOysF/wFMuP9sctmh2cFzRAZOn1YapxBsE1i9bJIY586R/WBLfLcmcBlM8ROBiQURnnNy+zfA==", "dev": true, "requires": { - "@babel/code-frame": "^7.24.7", - "@babel/parser": "^7.25.0", - "@babel/types": "^7.25.0" + "@babel/code-frame": "^7.26.2", + "@babel/parser": "^7.26.9", + "@babel/types": "^7.26.9" } }, "@babel/traverse": { @@ -14134,14 +14026,13 @@ } }, "@babel/types": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz", - "integrity": "sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.10.tgz", + "integrity": "sha512-emqcG3vHrpxUKTrxcblR36dcrcoRDvKmnL/dCL6ZsHaShW80qxCAcNhzQZrpeM765VzEos+xOi4s+r4IXzTwdQ==", "dev": true, "requires": { - "@babel/helper-string-parser": "^7.24.8", - "@babel/helper-validator-identifier": "^7.24.7", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9" } }, "@bcoe/v8-coverage": { @@ -15784,15 +15675,6 @@ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, "anymatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", @@ -15860,9 +15742,9 @@ "dev": true }, "axios": { - "version": "1.7.9", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", - "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.3.tgz", + "integrity": "sha512-iP4DebzoNlP/YN2dpwCgb8zoCmhtkajzS48JvwmkSkXvPI3DHc7m+XYL5tGnSlJtR6nImXZmdCuN5aP8dh1d8A==", "requires": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -16253,17 +16135,6 @@ "type-detect": "^4.0.5" } }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, "char-regex": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", @@ -16425,21 +16296,6 @@ "integrity": "sha512-iBPtljfCNcTKNAto0KEtDfZ3qzjJvqE3aTGZsbhjSBlorqpXJlaWWtPO35D+ZImoC3KWejX64o+yPGxhWSTzfg==", "dev": true }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, "colorette": { "version": "2.0.19", "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz", @@ -17046,12 +16902,6 @@ "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", "dev": true }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true - }, "escodegen": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.0.0.tgz", @@ -17849,12 +17699,6 @@ "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", "dev": true }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true - }, "has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -20919,9 +20763,9 @@ } }, "regenerator-runtime": { - "version": "0.13.10", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.10.tgz", - "integrity": "sha512-KepLsg4dU12hryUO7bp/axHAKvwGOCV0sGloQtpagJ12ai+ojVDqkeGSiRX1zlq+kjIMZ1t7gpze+26QqtdGqw==", + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", "dev": true }, "regenerator-transform": { @@ -21649,15 +21493,6 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, "supports-hyperlinks": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz", @@ -21792,12 +21627,6 @@ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, - "to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", - "dev": true - }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/yarn.lock b/yarn.lock index 04987d5..78d0ed5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,12 +7,13 @@ resolved "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz" integrity sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ== -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.15.8", "@babel/code-frame@^7.24.7": - version "7.24.7" - resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz" - integrity sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA== +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.15.8", "@babel/code-frame@^7.24.7", "@babel/code-frame@^7.26.2": + version "7.26.2" + resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz" + integrity sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ== dependencies: - "@babel/highlight" "^7.24.7" + "@babel/helper-validator-identifier" "^7.25.9" + js-tokens "^4.0.0" picocolors "^1.0.0" "@babel/compat-data@^7.13.11", "@babel/compat-data@^7.15.0": @@ -212,15 +213,15 @@ dependencies: "@babel/types" "^7.24.7" -"@babel/helper-string-parser@^7.24.8": - version "7.24.8" - resolved "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz" - integrity sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ== +"@babel/helper-string-parser@^7.25.9": + version "7.25.9" + resolved "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz" + integrity sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA== -"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.15.7", "@babel/helper-validator-identifier@^7.24.7": - version "7.24.7" - resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz" - integrity sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w== +"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.15.7", "@babel/helper-validator-identifier@^7.25.9": + version "7.25.9" + resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz" + integrity sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ== "@babel/helper-validator-option@^7.14.5": version "7.14.5" @@ -238,30 +239,19 @@ "@babel/types" "^7.15.4" "@babel/helpers@^7.15.4": - version "7.15.4" - resolved "https://registry.npmjs.org/@babel/helpers/-/helpers-7.15.4.tgz" - integrity sha512-V45u6dqEJ3w2rlryYYXf6i9rQ5YMNu4FLS6ngs8ikblhu2VdR1AqAd6aJjBzmf2Qzh6KOLqKHxEN9+TFbAkAVQ== + version "7.26.10" + resolved "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.10.tgz" + integrity sha512-UPYc3SauzZ3JGgj87GgZ89JVdC5dj0AoetR5Bw6wj4niittNyFh6+eOGonYvJ1ao6B8lEa3Q3klS7ADZ53bc5g== dependencies: - "@babel/template" "^7.15.4" - "@babel/traverse" "^7.15.4" - "@babel/types" "^7.15.4" + "@babel/template" "^7.26.9" + "@babel/types" "^7.26.10" -"@babel/highlight@^7.24.7": - version "7.24.7" - resolved "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz" - integrity sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.15.8", "@babel/parser@^7.25.6", "@babel/parser@^7.26.9": + version "7.26.10" + resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.26.10.tgz" + integrity sha512-6aQR2zGE/QFi8JpDLjUZEPYOs7+mhKXm86VaKFiLP35JQwQb6bwUE+XbvkH0EptsYhbNBSUGaUBLKqxH1xSgsA== dependencies: - "@babel/helper-validator-identifier" "^7.24.7" - chalk "^2.4.2" - js-tokens "^4.0.0" - picocolors "^1.0.0" - -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.15.8", "@babel/parser@^7.25.0", "@babel/parser@^7.25.6": - version "7.25.6" - resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz" - integrity sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q== - dependencies: - "@babel/types" "^7.25.6" + "@babel/types" "^7.26.10" "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@^7.15.4": version "7.15.4" @@ -858,20 +848,20 @@ esutils "^2.0.2" "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2": - version "7.20.1" - resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.1.tgz" - integrity sha512-mrzLkl6U9YLF8qpqI7TB82PESyEGjm/0Ly91jG575eVxMMlb8fYfOXFZIJ8XfLrJZQbm7dlKry2bJmXBUEkdFg== + version "7.26.10" + resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.10.tgz" + integrity sha512-2WJMeRQPHKSPemqk/awGrAiuFfzBmOIPXKizAsVhWH9YJqLZ0H+HS4c8loHGgW6utJ3E/ejXQUsiGaQy2NZ9Fw== dependencies: - regenerator-runtime "^0.13.10" + regenerator-runtime "^0.14.0" -"@babel/template@^7.15.4", "@babel/template@^7.24.7", "@babel/template@^7.25.0", "@babel/template@^7.3.3": - version "7.25.0" - resolved "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz" - integrity sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q== +"@babel/template@^7.15.4", "@babel/template@^7.24.7", "@babel/template@^7.25.0", "@babel/template@^7.26.9", "@babel/template@^7.3.3": + version "7.26.9" + resolved "https://registry.npmjs.org/@babel/template/-/template-7.26.9.tgz" + integrity sha512-qyRplbeIpNZhmzOysF/wFMuP9sctmh2cFzRAZOn1YapxBsE1i9bJIY586R/WBLfLcmcBlM8ROBiQURnnNy+zfA== dependencies: - "@babel/code-frame" "^7.24.7" - "@babel/parser" "^7.25.0" - "@babel/types" "^7.25.0" + "@babel/code-frame" "^7.26.2" + "@babel/parser" "^7.26.9" + "@babel/types" "^7.26.9" "@babel/traverse@^7.13.0", "@babel/traverse@^7.15.4", "@babel/traverse@^7.7.2": version "7.25.6" @@ -886,14 +876,13 @@ debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.15.4", "@babel/types@^7.15.6", "@babel/types@^7.24.7", "@babel/types@^7.25.0", "@babel/types@^7.25.6", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4": - version "7.25.6" - resolved "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz" - integrity sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw== +"@babel/types@^7.0.0", "@babel/types@^7.15.4", "@babel/types@^7.15.6", "@babel/types@^7.24.7", "@babel/types@^7.25.6", "@babel/types@^7.26.10", "@babel/types@^7.26.9", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4": + version "7.26.10" + resolved "https://registry.npmjs.org/@babel/types/-/types-7.26.10.tgz" + integrity sha512-emqcG3vHrpxUKTrxcblR36dcrcoRDvKmnL/dCL6ZsHaShW80qxCAcNhzQZrpeM765VzEos+xOi4s+r4IXzTwdQ== dependencies: - "@babel/helper-string-parser" "^7.24.8" - "@babel/helper-validator-identifier" "^7.24.7" - to-fast-properties "^2.0.0" + "@babel/helper-string-parser" "^7.25.9" + "@babel/helper-validator-identifier" "^7.25.9" "@bcoe/v8-coverage@^0.2.3": version "0.2.3" @@ -1872,13 +1861,6 @@ ansi-regex@^6.0.1: resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz" integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA== -ansi-styles@^3.2.1: - version "3.2.1" - resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz" - integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== - dependencies: - color-convert "^1.9.0" - ansi-styles@^4.0.0: version "4.3.0" resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz" @@ -1971,9 +1953,9 @@ available-typed-arrays@^1.0.5: integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== axios@^1.7.9: - version "1.7.9" - resolved "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz" - integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw== + version "1.8.3" + resolved "https://registry.npmjs.org/axios/-/axios-1.8.3.tgz" + integrity sha512-iP4DebzoNlP/YN2dpwCgb8zoCmhtkajzS48JvwmkSkXvPI3DHc7m+XYL5tGnSlJtR6nImXZmdCuN5aP8dh1d8A== dependencies: follow-redirects "^1.15.6" form-data "^4.0.0" @@ -2244,15 +2226,6 @@ chai@^4.3.4: pathval "^1.1.1" type-detect "^4.0.5" -chalk@^2.4.2: - version "2.4.2" - resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz" - integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== - dependencies: - ansi-styles "^3.2.1" - escape-string-regexp "^1.0.5" - supports-color "^5.3.0" - chalk@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz" @@ -2378,13 +2351,6 @@ collect-v8-coverage@^1.0.0: resolved "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz" integrity sha512-iBPtljfCNcTKNAto0KEtDfZ3qzjJvqE3aTGZsbhjSBlorqpXJlaWWtPO35D+ZImoC3KWejX64o+yPGxhWSTzfg== -color-convert@^1.9.0: - version "1.9.3" - resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz" - integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== - dependencies: - color-name "1.1.3" - color-convert@^2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz" @@ -2397,11 +2363,6 @@ color-name@~1.1.4: resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -color-name@1.1.3: - version "1.1.3" - resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz" - integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw== - colorette@^2.0.10, colorette@^2.0.14, colorette@^2.0.19: version "2.0.19" resolved "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz" @@ -2904,11 +2865,6 @@ escape-html@~1.0.3: resolved "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz" integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= -escape-string-regexp@^1.0.5: - version "1.0.5" - resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" - integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== - escape-string-regexp@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz" @@ -3497,11 +3453,6 @@ has-bigints@^1.0.1: resolved "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz" integrity sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ== -has-flag@^3.0.0: - version "3.0.0" - resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz" - integrity sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw== - has-flag@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz" @@ -5344,10 +5295,10 @@ regenerate@^1.4.2: resolved "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz" integrity sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A== -regenerator-runtime@^0.13.10: - version "0.13.10" - resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.10.tgz" - integrity sha512-KepLsg4dU12hryUO7bp/axHAKvwGOCV0sGloQtpagJ12ai+ojVDqkeGSiRX1zlq+kjIMZ1t7gpze+26QqtdGqw== +regenerator-runtime@^0.14.0: + version "0.14.1" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz" + integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw== regenerator-transform@^0.14.2: version "0.14.5" @@ -5936,13 +5887,6 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -supports-color@^5.3.0: - version "5.5.0" - resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz" - integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== - dependencies: - has-flag "^3.0.0" - supports-color@^7.0.0: version "7.2.0" resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz" @@ -6050,11 +5994,6 @@ tmpl@1.0.5: resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz" integrity sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw== -to-fast-properties@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz" - integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= - to-regex-range@^5.0.1: version "5.0.1" resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz" From 081343720b220a6ffb5bf438f024a20b3b1255f5 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Tue, 18 Mar 2025 00:40:32 +0530 Subject: [PATCH 03/10] fix:updated naming for hosting url Signed-off-by: Amitkanswal --- src/types.ts | 2 +- src/uiLocation.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/types.ts b/src/types.ts index ac5b923..a590df5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -103,7 +103,7 @@ declare interface ICommonInitData { type: LocationType; user: User; manifest?: Manifest; - serviceDomainUrls?: ServiceURLsMap; + serviceEndpoints?: ServiceURLsMap; } export declare interface IOrgFullPageLocationInitData extends ICommonInitData { diff --git a/src/uiLocation.ts b/src/uiLocation.ts index f70f5d9..38c4e23 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -71,7 +71,7 @@ class UiLocation { private config: GenericObjectType; - readonly hostedEndpoints: ServiceURLsMap + readonly endpoints: ServiceURLsMap /** * This holds the instance of Cross-domain communication library for posting messages between windows. @@ -188,9 +188,8 @@ class UiLocation { this.modal = new Modal(); - this.region = formatAppRegion(initializationData.region); - - this.hostedEndpoints = initializationData.serviceDomainUrls ?? { CMA: '' }; + this.region = formatAppRegion(initializationData.region); + this.endpoints = initializationData.serviceEndpoints ?? { CMA: '' }; const stack = new Stack(initializationData.stack, postRobot, { currentBranch: initializationData.currentBranch, @@ -482,7 +481,7 @@ class UiLocation { * Method used to make an API request to the Contentstack's CMA APIs. */ - api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url,this.hostedEndpoints, option) as Promise; + api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url,this.endpoints, option) as Promise; /** * Method used to create an adapter for management sdk. From 3daf6998079ea3247c1800206f6f28abbc68a14b Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Tue, 18 Mar 2025 12:51:10 +0530 Subject: [PATCH 04/10] fix:removed service option from .api Signed-off-by: Amitkanswal --- src/types/api.type.ts | 9 +-------- src/uiLocation.ts | 2 +- src/utils/adapter.ts | 11 ++--------- src/utils/utils.ts | 4 ++-- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/types/api.type.ts b/src/types/api.type.ts index 5309681..f0b2a57 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -6,14 +6,7 @@ export type ServiceURLsMap = { CMA: string; }; -enum SupportedServices { - CMA = "CMA", -} export type RequestInitConfig = RequestInit & { - service?: keyof typeof SupportedServices; -}; - -export type RequestConfigWithBaseUrl = RequestInitConfig & { - baseURL: string; + baseURL?: string; }; diff --git a/src/uiLocation.ts b/src/uiLocation.ts index 38c4e23..ae44c15 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -481,7 +481,7 @@ class UiLocation { * Method used to make an API request to the Contentstack's CMA APIs. */ - api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url,this.endpoints, option) as Promise; + api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url, option) as Promise; /** * Method used to create an adapter for management sdk. diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 1124695..e44212e 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -2,12 +2,7 @@ import PostRobot from "post-robot"; import { AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; import { onError, fetchToAxiosConfig, serializeAxiosResponse } from "./utils"; -import { RequestInitConfig, ServiceURLsMap } from "../types/api.type"; - -export const resolveBaseUrl = (hostingRegion:ServiceURLsMap, option?:RequestInitConfig)=>{ -return option?.service? hostingRegion[option.service]: hostingRegion.CMA -} - +import { RequestInitConfig } from "../types/api.type"; /** * Dispatches a request using PostRobot. @@ -34,12 +29,10 @@ export const dispatchAdapter = (postRobot: typeof PostRobot) => (config: AxiosRe */ export const dispatchApiRequest = async ( url: string, - hostedUrl:ServiceURLsMap, options?: RequestInitConfig, ): Promise => { try { - const updatedOptions = {...options, baseURL: resolveBaseUrl(hostedUrl, options)}; - const config = fetchToAxiosConfig(url, updatedOptions); + const config = fetchToAxiosConfig(url, options); const responseData = (await dispatchAdapter(PostRobot)( config )) as AxiosResponse; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 40ed0d5..3973c0c 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,6 +1,6 @@ import { Region } from "../types"; import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from "axios"; -import { RequestConfigWithBaseUrl } from '../types/api.type'; +import { RequestInitConfig } from '../types/api.type'; export function onData>(data: { data: Data }) { if (typeof data.data === "string") { @@ -78,7 +78,7 @@ export const convertHeaders = (headers: HeadersInit): AxiosHeaders => { return axiosHeaders; }; - export const fetchToAxiosConfig = (url: string ,options?: RequestConfigWithBaseUrl): AxiosRequestConfig => { + export const fetchToAxiosConfig = (url: string ,options?: RequestInitConfig): AxiosRequestConfig => { const axiosConfig: AxiosRequestConfig = { url, From 3231a366d1ce8b6cb0a2882ba5f2b27a52ae3038 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Tue, 18 Mar 2025 12:57:37 +0530 Subject: [PATCH 05/10] fix:added access via function Signed-off-by: Amitkanswal --- src/uiLocation.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uiLocation.ts b/src/uiLocation.ts index ae44c15..5a6fb67 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -477,6 +477,10 @@ class UiLocation { return this.region; }; + getCurrentEndpoints = (): ServiceURLsMap => { + return this.endpoints; + }; + /** * Method used to make an API request to the Contentstack's CMA APIs. */ From f6a76ee1d12e778474f934d9e90de735149a7d0a Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Tue, 18 Mar 2025 15:32:51 +0530 Subject: [PATCH 06/10] fix:updated naming for type Signed-off-by: Amitkanswal --- src/types.ts | 4 ++-- src/types/api.type.ts | 3 ++- src/uiLocation.ts | 9 ++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/types.ts b/src/types.ts index a590df5..f001119 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,7 +7,7 @@ import { GenericObjectType } from "./types/common.types"; import { Entry } from "./types/entry.types"; import { Asset, ContentType, Schema, StackDetail } from "./types/stack.types"; import { OrganizationDetails } from "./types/organization.types"; -import { ServiceURLsMap } from './types/api.type'; +import { ContentstackEndpoints } from './types/api.type'; import { User } from "./types/user.types"; import Window from "./window"; @@ -103,7 +103,7 @@ declare interface ICommonInitData { type: LocationType; user: User; manifest?: Manifest; - serviceEndpoints?: ServiceURLsMap; + serviceEndpoints?: ContentstackEndpoints; } export declare interface IOrgFullPageLocationInitData extends ICommonInitData { diff --git a/src/types/api.type.ts b/src/types/api.type.ts index f0b2a57..36de599 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -2,8 +2,9 @@ import { AxiosRequestConfig, AxiosResponse } from "axios"; export type RequestConfig = AxiosRequestConfig; export type ProxyResponse = AxiosResponse; -export type ServiceURLsMap = { +export type ContentstackEndpoints = { CMA: string; + [key:string]:string; }; diff --git a/src/uiLocation.ts b/src/uiLocation.ts index 5a6fb67..9915c15 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -35,7 +35,7 @@ import { User } from "./types/user.types"; import { formatAppRegion, onData, onError } from "./utils/utils"; import Window from "./window"; import { dispatchApiRequest, dispatchAdapter } from './utils/adapter'; -import { RequestInitConfig, ServiceURLsMap } from "./types/api.type"; +import { RequestInitConfig, ContentstackEndpoints } from "./types/api.type"; const emitter = new EventEmitter(); @@ -71,7 +71,7 @@ class UiLocation { private config: GenericObjectType; - readonly endpoints: ServiceURLsMap + readonly endpoints: ContentstackEndpoints /** * This holds the instance of Cross-domain communication library for posting messages between windows. @@ -477,10 +477,9 @@ class UiLocation { return this.region; }; - getCurrentEndpoints = (): ServiceURLsMap => { + getCurrentEndpoints = ():ContentstackEndpoints => { return this.endpoints; - }; - + } /** * Method used to make an API request to the Contentstack's CMA APIs. */ From 1b29bba16603a2b993acc2cebee4c15ddb96ef82 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Thu, 20 Mar 2025 11:16:57 +0530 Subject: [PATCH 07/10] fix:refactored the code with reviewed changes Signed-off-by: Amitkanswal --- __test__/assetSidebarWidget.test.ts | 1 + __test__/fieldModifierLocation/entry.test.ts | 1 + __test__/organizationFullPage.test.ts | 1 + __test__/uiLocation.test.ts | 1 + __test__/utils.test.ts | 2 +- src/types.ts | 4 +- src/types/api.type.ts | 6 +- src/uiLocation.ts | 12 +-- src/utils/adapter.ts | 3 +- src/utils/utils.ts | 84 +++++++++----------- 10 files changed, 52 insertions(+), 63 deletions(-) diff --git a/__test__/assetSidebarWidget.test.ts b/__test__/assetSidebarWidget.test.ts index 5fc9c11..ee1f74f 100644 --- a/__test__/assetSidebarWidget.test.ts +++ b/__test__/assetSidebarWidget.test.ts @@ -25,6 +25,7 @@ describe("AssetSidebarWidget", () => { user: {} as any, currentBranch: "mock_branch", region: "region", + endpoints: { CMA: "", APP: "" }, }; let connection: { sendToParent: (...props: any[]) => any }; diff --git a/__test__/fieldModifierLocation/entry.test.ts b/__test__/fieldModifierLocation/entry.test.ts index 65ce54c..28ccbc7 100644 --- a/__test__/fieldModifierLocation/entry.test.ts +++ b/__test__/fieldModifierLocation/entry.test.ts @@ -47,6 +47,7 @@ describe("FieldModifierLocationEntry", () => { extension_uid: "extension_uid", installation_uid: "installation_uid", region: "NA", + endpoints: { CMA: "", APP: "" }, stack: { api_key: "api_key", created_at: "created_at", diff --git a/__test__/organizationFullPage.test.ts b/__test__/organizationFullPage.test.ts index 8913160..1d5794d 100644 --- a/__test__/organizationFullPage.test.ts +++ b/__test__/organizationFullPage.test.ts @@ -7,6 +7,7 @@ const mockData: IOrgFullPageLocationInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", + endpoints:{CMA:"",APP:""}, stack: {} as any, user: {} as any, currentBranch: "currentBranch", diff --git a/__test__/uiLocation.test.ts b/__test__/uiLocation.test.ts index 39f4e4c..41c02d0 100644 --- a/__test__/uiLocation.test.ts +++ b/__test__/uiLocation.test.ts @@ -60,6 +60,7 @@ const initData: IAppConfigInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", + endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app" }, stack: mockStackData, user: {} as any, currentBranch: "currentBranch", diff --git a/__test__/utils.test.ts b/__test__/utils.test.ts index 7530174..7afdbf8 100644 --- a/__test__/utils.test.ts +++ b/__test__/utils.test.ts @@ -23,6 +23,6 @@ describe("formatAppRegion", () => { }); it("should return unknown for any invalid region", () => { - expect(formatAppRegion("invalid")).toBe(Region.UNKNOWN); + expect(formatAppRegion("invalid")).toBe("invalid"); }); }); diff --git a/src/types.ts b/src/types.ts index f001119..c71b513 100644 --- a/src/types.ts +++ b/src/types.ts @@ -103,7 +103,7 @@ declare interface ICommonInitData { type: LocationType; user: User; manifest?: Manifest; - serviceEndpoints?: ContentstackEndpoints; + endpoints: ContentstackEndpoints; } export declare interface IOrgFullPageLocationInitData extends ICommonInitData { @@ -258,3 +258,5 @@ export enum Region { GCP_NA = "GCP_NA", GCP_EU = "GCP_EU", } + +export type RegionType = "UNKNOWN" | "NA" | "EU" | "AZURE_NA" | "AZURE_EU" | "GCP_NA" | string; \ No newline at end of file diff --git a/src/types/api.type.ts b/src/types/api.type.ts index 36de599..43bc7af 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -3,11 +3,7 @@ export type RequestConfig = AxiosRequestConfig; export type ProxyResponse = AxiosResponse; export type ContentstackEndpoints = { + APP: string; CMA: string; [key:string]:string; }; - - -export type RequestInitConfig = RequestInit & { - baseURL?: string; -}; diff --git a/src/uiLocation.ts b/src/uiLocation.ts index 9915c15..768525b 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -27,15 +27,15 @@ import { InitializationData, LocationType, Manifest, - Region, IOrgFullPageLocation, + RegionType, } from "./types"; import { GenericObjectType } from "./types/common.types"; import { User } from "./types/user.types"; import { formatAppRegion, onData, onError } from "./utils/utils"; import Window from "./window"; import { dispatchApiRequest, dispatchAdapter } from './utils/adapter'; -import { RequestInitConfig, ContentstackEndpoints } from "./types/api.type"; +import { ContentstackEndpoints } from "./types/api.type"; const emitter = new EventEmitter(); @@ -107,7 +107,7 @@ class UiLocation { /** * The Contentstack Region on which the app is running. */ - readonly region: Region; + readonly region: RegionType; version: number | null; ids: { @@ -189,7 +189,7 @@ class UiLocation { this.modal = new Modal(); this.region = formatAppRegion(initializationData.region); - this.endpoints = initializationData.serviceEndpoints ?? { CMA: '' }; + this.endpoints = initializationData.endpoints; const stack = new Stack(initializationData.stack, postRobot, { currentBranch: initializationData.currentBranch, @@ -473,7 +473,7 @@ class UiLocation { /** * Method used to get the Contentstack Region on which the app is running. */ - getCurrentRegion = (): Region => { + getCurrentRegion = (): RegionType => { return this.region; }; @@ -484,7 +484,7 @@ class UiLocation { * Method used to make an API request to the Contentstack's CMA APIs. */ - api = (url: string, option?: RequestInitConfig): Promise => dispatchApiRequest(url, option) as Promise; + api = (url: string, option?: RequestInit): Promise => dispatchApiRequest(url, option) as Promise; /** * Method used to create an adapter for management sdk. diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index e44212e..d857143 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -2,7 +2,6 @@ import PostRobot from "post-robot"; import { AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; import { onError, fetchToAxiosConfig, serializeAxiosResponse } from "./utils"; -import { RequestInitConfig } from "../types/api.type"; /** * Dispatches a request using PostRobot. @@ -29,7 +28,7 @@ export const dispatchAdapter = (postRobot: typeof PostRobot) => (config: AxiosRe */ export const dispatchApiRequest = async ( url: string, - options?: RequestInitConfig, + options?: RequestInit, ): Promise => { try { const config = fetchToAxiosConfig(url, options); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 3973c0c..4dc31bb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,6 +1,6 @@ -import { Region } from "../types"; import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from "axios"; -import { RequestInitConfig } from '../types/api.type'; + +import { Region, RegionType } from "../types"; export function onData>(data: { data: Data }) { if (typeof data.data === "string") { @@ -13,11 +13,8 @@ export function onError(error: Error) { return Promise.reject(error); } -export function formatAppRegion(region: string): Region { - if (region && Object.values(Region).includes(region as Region)) { - return region as Region; - } - return Region.UNKNOWN; +export function formatAppRegion(region: string): RegionType { + return region ?? Region.UNKNOWN; } export function getPreferredBodyElement(nodeCollection: HTMLCollection) { @@ -51,59 +48,50 @@ export function getPreferredBodyElement(nodeCollection: HTMLCollection) { return rootElement || nodeCollection[0]; } -function isAbsoluteURL(url) { - try { - new URL(url); - return true; - } catch (e) { - return false; - } -} - export const convertHeaders = (headers: HeadersInit): AxiosHeaders => { const axiosHeaders = new AxiosHeaders(); if (headers instanceof Headers) { - headers.forEach((value, key) => { - axiosHeaders.set(key, value); - }); + headers.forEach((value, key) => { + axiosHeaders.set(key, value); + }); } else if (Array.isArray(headers)) { - headers.forEach(([key, value]) => { - axiosHeaders.set(key, value); - }); + headers.forEach(([key, value]) => { + axiosHeaders.set(key, value); + }); } else { - Object.entries(headers).forEach(([key, value]) => { - axiosHeaders.set(key, value); - }); + Object.entries(headers).forEach(([key, value]) => { + axiosHeaders.set(key, value); + }); } return axiosHeaders; - }; - - export const fetchToAxiosConfig = (url: string ,options?: RequestInitConfig): AxiosRequestConfig => { +}; +export const fetchToAxiosConfig = ( + url: string, + options?: RequestInit +): AxiosRequestConfig => { const axiosConfig: AxiosRequestConfig = { - url, - method: options?.method || 'GET', - headers: options?.headers ? convertHeaders({...options?.headers}) : {}, - data: options?.body, + url, + method: options?.method || "GET", + headers: options?.headers + ? convertHeaders({ ...options?.headers }) + : {}, + data: options?.body, }; - - if (!isAbsoluteURL(url)) { - axiosConfig.baseURL = options?.baseURL; - } - if (options?.credentials === 'include') { - axiosConfig.withCredentials = true; + if (options?.credentials === "include") { + axiosConfig.withCredentials = true; } - + return axiosConfig; - } +}; - export const serializeAxiosResponse = (responseData: AxiosResponse, config) => { +export const serializeAxiosResponse = (responseData: AxiosResponse, config) => { return { - data: responseData.data, - status: responseData.status, - statusText: responseData.statusText, - headers: responseData.headers as AxiosHeaders, - config, - } - } \ No newline at end of file + data: responseData.data, + status: responseData.status, + statusText: responseData.statusText, + headers: responseData.headers as AxiosHeaders, + config, + }; +}; From 89f4ec48b05d273e92a2eefc7c84f25296377e36 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Thu, 20 Mar 2025 12:58:34 +0530 Subject: [PATCH 08/10] fix:added default developerhub endpoint Signed-off-by: Amitkanswal --- __test__/assetSidebarWidget.test.ts | 2 +- __test__/fieldModifierLocation/entry.test.ts | 2 +- __test__/organizationFullPage.test.ts | 2 +- __test__/uiLocation.test.ts | 2 +- src/types/api.type.ts | 1 + src/uiLocation.ts | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/__test__/assetSidebarWidget.test.ts b/__test__/assetSidebarWidget.test.ts index ee1f74f..3a5d02e 100644 --- a/__test__/assetSidebarWidget.test.ts +++ b/__test__/assetSidebarWidget.test.ts @@ -25,7 +25,7 @@ describe("AssetSidebarWidget", () => { user: {} as any, currentBranch: "mock_branch", region: "region", - endpoints: { CMA: "", APP: "" }, + endpoints: { CMA: "", APP: "",DEVELOPERHUB:"" }, }; let connection: { sendToParent: (...props: any[]) => any }; diff --git a/__test__/fieldModifierLocation/entry.test.ts b/__test__/fieldModifierLocation/entry.test.ts index 28ccbc7..fa8666b 100644 --- a/__test__/fieldModifierLocation/entry.test.ts +++ b/__test__/fieldModifierLocation/entry.test.ts @@ -47,7 +47,7 @@ describe("FieldModifierLocationEntry", () => { extension_uid: "extension_uid", installation_uid: "installation_uid", region: "NA", - endpoints: { CMA: "", APP: "" }, + endpoints: { CMA: "", APP: "",DEVELOPERHUB:"" }, stack: { api_key: "api_key", created_at: "created_at", diff --git a/__test__/organizationFullPage.test.ts b/__test__/organizationFullPage.test.ts index 1d5794d..7aad37f 100644 --- a/__test__/organizationFullPage.test.ts +++ b/__test__/organizationFullPage.test.ts @@ -7,7 +7,7 @@ const mockData: IOrgFullPageLocationInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", - endpoints:{CMA:"",APP:""}, + endpoints:{CMA:"",APP:"",DEVELOPERHUB:""}, stack: {} as any, user: {} as any, currentBranch: "currentBranch", diff --git a/__test__/uiLocation.test.ts b/__test__/uiLocation.test.ts index 41c02d0..403ecf6 100644 --- a/__test__/uiLocation.test.ts +++ b/__test__/uiLocation.test.ts @@ -60,7 +60,7 @@ const initData: IAppConfigInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", - endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app" }, + endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app",DEVELOPERHUB:"" }, stack: mockStackData, user: {} as any, currentBranch: "currentBranch", diff --git a/src/types/api.type.ts b/src/types/api.type.ts index 43bc7af..ae7fb3f 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -5,5 +5,6 @@ export type ProxyResponse = AxiosResponse; export type ContentstackEndpoints = { APP: string; CMA: string; + DEVELOPERHUB: string; [key:string]:string; }; diff --git a/src/uiLocation.ts b/src/uiLocation.ts index 768525b..ad6a8c4 100755 --- a/src/uiLocation.ts +++ b/src/uiLocation.ts @@ -491,7 +491,7 @@ class UiLocation { */ createAdapter = (): (config: AxiosRequestConfig) => Promise => { return (config: AxiosRequestConfig): Promise => { - return dispatchAdapter(postRobot)(config) as Promise; + return dispatchAdapter(postRobot)(config) }; }; From f1d287ee893037e8d07b065506643b6feab4ad82 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Fri, 21 Mar 2025 11:15:50 +0530 Subject: [PATCH 09/10] fix:refactored error response Signed-off-by: Amitkanswal --- __test__/assetSidebarWidget.test.ts | 2 +- __test__/fieldModifierLocation/entry.test.ts | 2 +- __test__/organizationFullPage.test.ts | 2 +- __test__/uiLocation.test.ts | 2 +- src/types/api.type.ts | 2 +- src/utils/adapter.ts | 17 +++------ src/utils/utils.ts | 39 +++++++++++++++++++- 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/__test__/assetSidebarWidget.test.ts b/__test__/assetSidebarWidget.test.ts index 3a5d02e..fbad1b3 100644 --- a/__test__/assetSidebarWidget.test.ts +++ b/__test__/assetSidebarWidget.test.ts @@ -25,7 +25,7 @@ describe("AssetSidebarWidget", () => { user: {} as any, currentBranch: "mock_branch", region: "region", - endpoints: { CMA: "", APP: "",DEVELOPERHUB:"" }, + endpoints: { CMA: "", APP: "",DEVELOPER_HUB:"" }, }; let connection: { sendToParent: (...props: any[]) => any }; diff --git a/__test__/fieldModifierLocation/entry.test.ts b/__test__/fieldModifierLocation/entry.test.ts index fa8666b..b0f4db1 100644 --- a/__test__/fieldModifierLocation/entry.test.ts +++ b/__test__/fieldModifierLocation/entry.test.ts @@ -47,7 +47,7 @@ describe("FieldModifierLocationEntry", () => { extension_uid: "extension_uid", installation_uid: "installation_uid", region: "NA", - endpoints: { CMA: "", APP: "",DEVELOPERHUB:"" }, + endpoints: { CMA: "", APP: "",DEVELOPER_HUB:"" }, stack: { api_key: "api_key", created_at: "created_at", diff --git a/__test__/organizationFullPage.test.ts b/__test__/organizationFullPage.test.ts index 7aad37f..75b6350 100644 --- a/__test__/organizationFullPage.test.ts +++ b/__test__/organizationFullPage.test.ts @@ -7,7 +7,7 @@ const mockData: IOrgFullPageLocationInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", - endpoints:{CMA:"",APP:"",DEVELOPERHUB:""}, + endpoints:{CMA:"",APP:"",DEVELOPER_HUB:""}, stack: {} as any, user: {} as any, currentBranch: "currentBranch", diff --git a/__test__/uiLocation.test.ts b/__test__/uiLocation.test.ts index 403ecf6..ebdacb1 100644 --- a/__test__/uiLocation.test.ts +++ b/__test__/uiLocation.test.ts @@ -60,7 +60,7 @@ const initData: IAppConfigInitData = { installation_uid: "installation_uid", extension_uid: "extension_uid", region: "NA", - endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app",DEVELOPERHUB:"" }, + endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app",DEVELOPER_HUB:"" }, stack: mockStackData, user: {} as any, currentBranch: "currentBranch", diff --git a/src/types/api.type.ts b/src/types/api.type.ts index ae7fb3f..9ab74ec 100644 --- a/src/types/api.type.ts +++ b/src/types/api.type.ts @@ -5,6 +5,6 @@ export type ProxyResponse = AxiosResponse; export type ContentstackEndpoints = { APP: string; CMA: string; - DEVELOPERHUB: string; + DEVELOPER_HUB: string; [key:string]:string; }; diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index d857143..97ba952 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -1,7 +1,7 @@ import PostRobot from "post-robot"; -import { AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; +import { AxiosError, AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; -import { onError, fetchToAxiosConfig, serializeAxiosResponse } from "./utils"; +import { onError, fetchToAxiosConfig, serializeAxiosResponse, createErrorResponse, axiosError } from "./utils"; /** * Dispatches a request using PostRobot. @@ -47,15 +47,8 @@ export const dispatchApiRequest = async ( return response } catch (error: any) { - const data = error.response?.data || error.data; - const status = error.response?.status || error.status || 500; - const statusText = error.response?.statusText || error.statusText || "Internal Server Error"; - const headers = new Headers(error.response?.headers || error.headers); - - throw new Response(data, { - status, - statusText, - headers, - }); + throw isAxiosError(error) + ? createErrorResponse(axiosError(error)) + : createErrorResponse(error); } }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 4dc31bb..dd837e8 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,4 +1,9 @@ -import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from "axios"; +import { + AxiosError, + AxiosHeaders, + AxiosRequestConfig, + AxiosResponse, +} from "axios"; import { Region, RegionType } from "../types"; @@ -13,6 +18,38 @@ export function onError(error: Error) { return Promise.reject(error); } +export function axiosError(error: AxiosError) { + const { response, message } = error || {}; + return { + data: response?.data || message, + status: response?.status || 500, + statusText: response?.statusText || "Internal Server Error", + headers: new Headers( + response?.headers ? Object.entries(response.headers) : undefined + ), + }; +} + +export const createErrorResponse = (errorData: any): Response => { + const data = errorData.data || errorData.message || errorData; + const status = errorData.status || 500; + const statusText = errorData.statusText || 'Internal Server Error'; + const headers = errorData.headers instanceof Headers + ? errorData.headers + : new Headers(errorData.headers || {}); + + // Handle various data types appropriately + const responseBody = typeof data === 'string' + ? data + : JSON.stringify(data); + + return new Response(responseBody, { + status, + statusText, + headers + }); +}; + export function formatAppRegion(region: string): RegionType { return region ?? Region.UNKNOWN; } From d6daa7967dd680ecf35a864cdefb857ae6622ea6 Mon Sep 17 00:00:00 2001 From: Amitkanswal Date: Fri, 21 Mar 2025 13:24:50 +0530 Subject: [PATCH 10/10] refactor: updated error handling Signed-off-by: Amitkanswal --- src/utils/adapter.ts | 10 ++++------ src/utils/utils.ts | 40 +++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 97ba952..883220f 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -1,7 +1,7 @@ import PostRobot from "post-robot"; -import { AxiosError, AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; +import { AxiosRequestConfig, AxiosResponse, isAxiosError } from "axios"; -import { onError, fetchToAxiosConfig, serializeAxiosResponse, createErrorResponse, axiosError } from "./utils"; +import { onError, fetchToAxiosConfig, serializeAxiosResponse, handleApiError } from "./utils"; /** * Dispatches a request using PostRobot. @@ -46,9 +46,7 @@ export const dispatchApiRequest = async ( }); return response - } catch (error: any) { - throw isAxiosError(error) - ? createErrorResponse(axiosError(error)) - : createErrorResponse(error); + } catch (error) { + throw handleApiError(error); } }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index dd837e8..6e5acdd 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -3,6 +3,7 @@ import { AxiosHeaders, AxiosRequestConfig, AxiosResponse, + isAxiosError, } from "axios"; import { Region, RegionType } from "../types"; @@ -30,24 +31,29 @@ export function axiosError(error: AxiosError) { }; } +export const handleApiError = (error: any): Response => { + return isAxiosError(error) + ? createErrorResponse(axiosError(error)) + : createErrorResponse(error); +}; + export const createErrorResponse = (errorData: any): Response => { - const data = errorData.data || errorData.message || errorData; - const status = errorData.status || 500; - const statusText = errorData.statusText || 'Internal Server Error'; - const headers = errorData.headers instanceof Headers - ? errorData.headers - : new Headers(errorData.headers || {}); - - // Handle various data types appropriately - const responseBody = typeof data === 'string' - ? data - : JSON.stringify(data); - - return new Response(responseBody, { - status, - statusText, - headers - }); + const data = errorData.data || errorData.message || errorData; + const status = errorData.status || 500; + const statusText = errorData.statusText || 'Internal Server Error'; + const headers = errorData.headers instanceof Headers + ? errorData.headers + : new Headers(errorData.headers || {}); + + const responseBody = typeof data === 'string' + ? data + : JSON.stringify(data); + + return new Response(responseBody, { + status, + statusText, + headers + }); }; export function formatAppRegion(region: string): RegionType {