From 70c2bfe8973fbeb0fcff8f0e1a68ab251c957f36 Mon Sep 17 00:00:00 2001 From: Aymeric Mortemousque Date: Thu, 28 Mar 2024 12:17:20 +0100 Subject: [PATCH] Fix types --- packages/core/src/index.ts | 1 + packages/rum-core/src/browser/cookieObservable.spec.ts | 5 ++--- packages/rum-core/src/browser/cookieObservable.ts | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7ad222a458..cbd049e324 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -96,6 +96,7 @@ export { deleteCookie, resetInitCookies, } from './browser/cookie' +export { CookieStore } from './browser/types' export { initXhrObservable, XhrCompleteContext, XhrStartContext } from './browser/xhrObservable' export { initFetchObservable, FetchResolveContext, FetchStartContext, FetchContext } from './browser/fetchObservable' export { createPageExitObservable, PageExitEvent, PageExitReason, isPageExitReason } from './browser/pageExitObservable' diff --git a/packages/rum-core/src/browser/cookieObservable.spec.ts b/packages/rum-core/src/browser/cookieObservable.spec.ts index a86c213cb8..3abd9ff516 100644 --- a/packages/rum-core/src/browser/cookieObservable.spec.ts +++ b/packages/rum-core/src/browser/cookieObservable.spec.ts @@ -2,10 +2,9 @@ import type { Subscription } from '@datadog/browser-core' import { ONE_MINUTE, STORAGE_POLL_DELAY, deleteCookie, setCookie } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' import { mockClock } from '@datadog/browser-core/test' -import type { CookieChangeItem } from 'packages/core/src/browser/types' import type { RumConfiguration } from '../domain/configuration' import { createCookieObservable } from './cookieObservable' -import type { CookieObservable } from './cookieObservable' +import type { CookieChange, CookieObservable } from './cookieObservable' const COOKIE_NAME = 'cookie_name' const COOKIE_DURATION = ONE_MINUTE @@ -44,7 +43,7 @@ describe('cookieObservable', () => { it('should notify observers on cookie change when cookieStore is not supported', () => { Object.defineProperty(window, 'cookieStore', { get: () => undefined }) - let cookieChange: CookieChangeItem | undefined + let cookieChange: CookieChange | undefined observable.subscribe((change) => (cookieChange = change)) setCookie(COOKIE_NAME, 'foo', COOKIE_DURATION) diff --git a/packages/rum-core/src/browser/cookieObservable.ts b/packages/rum-core/src/browser/cookieObservable.ts index e54e1dcef0..6630f0a421 100644 --- a/packages/rum-core/src/browser/cookieObservable.ts +++ b/packages/rum-core/src/browser/cookieObservable.ts @@ -1,4 +1,4 @@ -import type { Configuration } from '@datadog/browser-core' +import type { Configuration, CookieStore } from '@datadog/browser-core' import { setInterval, clearInterval, @@ -7,7 +7,6 @@ import { ONE_SECOND, findCommaSeparatedValue, } from '@datadog/browser-core' -import type { CookieChangeItem, CookieStore } from 'packages/core/src/browser/types' export interface CookieStoreWindow extends Window { cookieStore: CookieStore @@ -15,8 +14,10 @@ export interface CookieStoreWindow extends Window { export type CookieObservable = ReturnType +export type CookieChange = { name: string; value: string | undefined } + export function createCookieObservable(configuration: Configuration, cookieName: string) { - return new Observable( + return new Observable( (observable) => listenToCookieStoreChange(configuration, cookieName, (event) => observable.notify(event)) ?? watchCookieFallback(cookieName, (event) => observable.notify(event)) @@ -26,7 +27,7 @@ export function createCookieObservable(configuration: Configuration, cookieName: function listenToCookieStoreChange( configuration: Configuration, cookieName: string, - callback: (event: CookieChangeItem) => void + callback: (event: CookieChange) => void ) { if (!('cookieStore' in window)) { return