Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Mar 28, 2024
1 parent ccfdb00 commit 70c2bfe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions packages/rum-core/src/browser/cookieObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions packages/rum-core/src/browser/cookieObservable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Configuration } from '@datadog/browser-core'
import type { Configuration, CookieStore } from '@datadog/browser-core'
import {
setInterval,
clearInterval,
Expand All @@ -7,16 +7,17 @@ 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
}

export type CookieObservable = ReturnType<typeof createCookieObservable>

export type CookieChange = { name: string; value: string | undefined }

export function createCookieObservable(configuration: Configuration, cookieName: string) {
return new Observable<CookieChangeItem>(
return new Observable<CookieChange>(
(observable) =>
listenToCookieStoreChange(configuration, cookieName, (event) => observable.notify(event)) ??
watchCookieFallback(cookieName, (event) => observable.notify(event))
Expand All @@ -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
Expand Down

0 comments on commit 70c2bfe

Please sign in to comment.