@newrelic/browser-agent 1.302.0 → 1.303.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/common/config/init-types.js +2 -0
  3. package/dist/cjs/common/config/init.js +3 -0
  4. package/dist/cjs/common/config/runtime.js +9 -0
  5. package/dist/cjs/common/constants/env.cdn.js +1 -1
  6. package/dist/cjs/common/constants/env.npm.js +1 -1
  7. package/dist/cjs/common/harvest/harvester.js +13 -9
  8. package/dist/cjs/common/harvest/types.js +0 -1
  9. package/dist/cjs/common/session/session-entity.js +4 -2
  10. package/dist/cjs/common/util/mfe.js +8 -5
  11. package/dist/cjs/common/wrap/wrap-promise.js +10 -5
  12. package/dist/cjs/features/generic_events/aggregate/index.js +4 -4
  13. package/dist/cjs/features/logging/aggregate/index.js +1 -2
  14. package/dist/cjs/features/page_view_event/aggregate/index.js +84 -22
  15. package/dist/cjs/features/page_view_event/instrument/index.js +0 -4
  16. package/dist/cjs/features/session_replay/aggregate/index.js +3 -2
  17. package/dist/cjs/features/session_replay/constants.js +2 -6
  18. package/dist/cjs/features/session_replay/instrument/index.js +3 -2
  19. package/dist/cjs/features/utils/agent-session.js +5 -0
  20. package/dist/cjs/features/utils/instrument-base.js +7 -8
  21. package/dist/cjs/interfaces/registered-entity.js +21 -0
  22. package/dist/cjs/loaders/agent.js +2 -0
  23. package/dist/cjs/loaders/api/consent.js +37 -0
  24. package/dist/cjs/loaders/api/constants.js +3 -2
  25. package/dist/cjs/loaders/api/measure.js +36 -35
  26. package/dist/cjs/loaders/api/recordCustomEvent.js +5 -3
  27. package/dist/cjs/loaders/api/register-api-types.js +14 -10
  28. package/dist/cjs/loaders/api/register.js +25 -10
  29. package/dist/cjs/loaders/api-base.js +14 -7
  30. package/dist/esm/common/config/init-types.js +2 -0
  31. package/dist/esm/common/config/init.js +3 -0
  32. package/dist/esm/common/config/runtime.js +9 -0
  33. package/dist/esm/common/constants/env.cdn.js +1 -1
  34. package/dist/esm/common/constants/env.npm.js +1 -1
  35. package/dist/esm/common/harvest/harvester.js +13 -9
  36. package/dist/esm/common/harvest/types.js +0 -1
  37. package/dist/esm/common/session/session-entity.js +4 -2
  38. package/dist/esm/common/util/mfe.js +7 -5
  39. package/dist/esm/common/wrap/wrap-promise.js +10 -5
  40. package/dist/esm/features/generic_events/aggregate/index.js +4 -4
  41. package/dist/esm/features/logging/aggregate/index.js +1 -2
  42. package/dist/esm/features/page_view_event/aggregate/index.js +84 -22
  43. package/dist/esm/features/page_view_event/instrument/index.js +0 -4
  44. package/dist/esm/features/session_replay/aggregate/index.js +4 -3
  45. package/dist/esm/features/session_replay/constants.js +1 -5
  46. package/dist/esm/features/session_replay/instrument/index.js +4 -3
  47. package/dist/esm/features/utils/agent-session.js +5 -0
  48. package/dist/esm/features/utils/instrument-base.js +7 -8
  49. package/dist/esm/interfaces/registered-entity.js +21 -0
  50. package/dist/esm/loaders/agent.js +2 -0
  51. package/dist/esm/loaders/api/consent.js +30 -0
  52. package/dist/esm/loaders/api/constants.js +2 -1
  53. package/dist/esm/loaders/api/measure.js +35 -35
  54. package/dist/esm/loaders/api/recordCustomEvent.js +4 -3
  55. package/dist/esm/loaders/api/register-api-types.js +14 -10
  56. package/dist/esm/loaders/api/register.js +26 -10
  57. package/dist/esm/loaders/api-base.js +15 -8
  58. package/dist/tsconfig.tsbuildinfo +1 -1
  59. package/dist/types/common/config/init-types.d.ts +6 -0
  60. package/dist/types/common/config/init.d.ts.map +1 -1
  61. package/dist/types/common/config/runtime.d.ts.map +1 -1
  62. package/dist/types/common/harvest/harvester.d.ts.map +1 -1
  63. package/dist/types/common/harvest/types.d.ts +0 -2
  64. package/dist/types/common/harvest/types.d.ts.map +1 -1
  65. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  66. package/dist/types/common/util/mfe.d.ts +3 -0
  67. package/dist/types/common/util/mfe.d.ts.map +1 -1
  68. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  69. package/dist/types/features/page_view_event/aggregate/index.d.ts +22 -3
  70. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  71. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  72. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  73. package/dist/types/features/session_replay/constants.d.ts +1 -5
  74. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  75. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  76. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  77. package/dist/types/features/utils/instrument-base.d.ts +1 -0
  78. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  79. package/dist/types/interfaces/registered-entity.d.ts +25 -0
  80. package/dist/types/interfaces/registered-entity.d.ts.map +1 -1
  81. package/dist/types/loaders/agent.d.ts.map +1 -1
  82. package/dist/types/loaders/api/consent.d.ts +2 -0
  83. package/dist/types/loaders/api/consent.d.ts.map +1 -0
  84. package/dist/types/loaders/api/constants.d.ts +1 -0
  85. package/dist/types/loaders/api/constants.d.ts.map +1 -1
  86. package/dist/types/loaders/api/measure.d.ts +3 -0
  87. package/dist/types/loaders/api/measure.d.ts.map +1 -1
  88. package/dist/types/loaders/api/recordCustomEvent.d.ts +1 -0
  89. package/dist/types/loaders/api/recordCustomEvent.d.ts.map +1 -1
  90. package/dist/types/loaders/api/register-api-types.d.ts +43 -12
  91. package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
  92. package/dist/types/loaders/api/register.d.ts +0 -16
  93. package/dist/types/loaders/api/register.d.ts.map +1 -1
  94. package/dist/types/loaders/api-base.d.ts +20 -15
  95. package/dist/types/loaders/api-base.d.ts.map +1 -1
  96. package/package.json +4 -4
  97. package/src/common/config/init-types.js +2 -0
  98. package/src/common/config/init.js +1 -0
  99. package/src/common/config/runtime.js +10 -0
  100. package/src/common/harvest/harvester.js +11 -8
  101. package/src/common/harvest/types.js +0 -1
  102. package/src/common/session/session-entity.js +6 -2
  103. package/src/common/util/mfe.js +10 -4
  104. package/src/common/wrap/wrap-promise.js +16 -6
  105. package/src/features/generic_events/aggregate/index.js +4 -4
  106. package/src/features/logging/aggregate/index.js +1 -1
  107. package/src/features/page_view_event/aggregate/index.js +79 -15
  108. package/src/features/page_view_event/instrument/index.js +0 -4
  109. package/src/features/session_replay/aggregate/index.js +4 -3
  110. package/src/features/session_replay/constants.js +1 -5
  111. package/src/features/session_replay/instrument/index.js +4 -3
  112. package/src/features/utils/agent-session.js +4 -0
  113. package/src/features/utils/instrument-base.js +7 -9
  114. package/src/interfaces/registered-entity.js +21 -0
  115. package/src/loaders/agent.js +2 -0
  116. package/src/loaders/api/consent.js +31 -0
  117. package/src/loaders/api/constants.js +1 -0
  118. package/src/loaders/api/measure.js +34 -33
  119. package/src/loaders/api/recordCustomEvent.js +5 -3
  120. package/src/loaders/api/register-api-types.js +14 -10
  121. package/src/loaders/api/register.js +17 -10
  122. package/src/loaders/api-base.js +15 -8
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { prefix, CONSENT } from './constants'
6
+ import { setupAPI } from './sharedHandlers'
7
+ import { handle } from '../../common/event-emitter/handle'
8
+ import { warn } from '../../common/util/console'
9
+
10
+ export function setupConsentAPI (agent) {
11
+ setupAPI(CONSENT, function (accept = true) {
12
+ if (typeof accept !== 'boolean') {
13
+ warn(65, typeof accept)
14
+ return
15
+ }
16
+ /** harvester, by way of "consented" getter, checks session state first, and falls back on runtime state if not available. Set both here */
17
+ handle(prefix + CONSENT, [accept], undefined, 'session', agent.ee) // sets session state (if available)
18
+ agent.runtime.consented = accept // sets runtime state
19
+
20
+ /** if consent is granted, attempt to make a PageView event harvest if one has not already been made */
21
+ if (accept) {
22
+ const pveInst = agent.features.page_view_event
23
+ pveInst.onAggregateImported.then((loaded) => {
24
+ const pveAgg = pveInst.featAggregate
25
+ if (loaded && !pveAgg.sentRum) {
26
+ pveAgg.sendRum()
27
+ }
28
+ })
29
+ }
30
+ }, agent)
31
+ }
@@ -25,3 +25,4 @@ export const SET_USER_ID = 'setUserId'
25
25
  export const START = 'start'
26
26
  export const WRAP_LOGGER = 'wrapLogger'
27
27
  export const MEASURE = 'measure'
28
+ export const CONSENT = 'consent'
@@ -10,44 +10,45 @@ import { prefix, MEASURE } from './constants'
10
10
  import { setupAPI } from './sharedHandlers'
11
11
 
12
12
  export function setupMeasureAPI (agent) {
13
- setupAPI(MEASURE, function (name, options) {
14
- const n = now()
15
- const { start, end, customAttributes } = options || {}
16
- const returnObj = { customAttributes: customAttributes || {} }
13
+ setupAPI(MEASURE, (name, options) => measure(name, options, agent), agent)
14
+ }
15
+
16
+ export function measure (name, options, agentRef, target, timestamp = now()) {
17
+ const { start, end, customAttributes } = options || {}
18
+ const returnObj = { customAttributes: customAttributes || {} }
17
19
 
18
- if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
19
- warn(57)
20
- return
21
- }
20
+ if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
21
+ warn(57)
22
+ return
23
+ }
22
24
 
23
- /**
25
+ /**
24
26
  * getValueFromTiming - Helper function to extract a numeric value from a supplied option.
25
27
  * @param {Number|PerformanceMark} [timing] The timing value
26
28
  * @param {Number} [d] The default value to return if timing is invalid
27
29
  * @returns {Number} The timing value or the default value
28
30
  */
29
- const getValueFromTiming = (timing, d) => {
30
- if (timing == null) return d
31
- if (typeof timing === 'number') return timing
32
- if (timing instanceof PerformanceMark) return timing.startTime
33
- return Number.NaN
34
- }
35
-
36
- returnObj.start = getValueFromTiming(start, 0)
37
- returnObj.end = getValueFromTiming(end, n)
38
- if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
39
- warn(57)
40
- return
41
- }
42
-
43
- returnObj.duration = returnObj.end - returnObj.start
44
- if (returnObj.duration < 0) {
45
- warn(58)
46
- return
47
- }
48
-
49
- handle(prefix + MEASURE, [returnObj, name], undefined, FEATURE_NAMES.genericEvents, agent.ee)
50
-
51
- return returnObj
52
- }, agent)
31
+ const getValueFromTiming = (timing, d) => {
32
+ if (timing == null) return d
33
+ if (typeof timing === 'number') return timing
34
+ if (timing instanceof PerformanceMark) return timing.startTime
35
+ return Number.NaN
36
+ }
37
+
38
+ returnObj.start = getValueFromTiming(start, 0)
39
+ returnObj.end = getValueFromTiming(end, timestamp)
40
+ if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
41
+ warn(57)
42
+ return
43
+ }
44
+
45
+ returnObj.duration = returnObj.end - returnObj.start
46
+ if (returnObj.duration < 0) {
47
+ warn(58)
48
+ return
49
+ }
50
+
51
+ handle(prefix + MEASURE, [returnObj, name, target], undefined, FEATURE_NAMES.genericEvents, agentRef.ee)
52
+
53
+ return returnObj
53
54
  }
@@ -9,7 +9,9 @@ import { prefix, RECORD_CUSTOM_EVENT } from './constants'
9
9
  import { setupAPI } from './sharedHandlers'
10
10
 
11
11
  export function setupRecordCustomEventAPI (agent) {
12
- setupAPI(RECORD_CUSTOM_EVENT, function () {
13
- handle(prefix + RECORD_CUSTOM_EVENT, [now(), ...arguments], undefined, FEATURE_NAMES.genericEvents, agent.ee)
14
- }, agent)
12
+ setupAPI(RECORD_CUSTOM_EVENT, (eventType, attributes) => recordCustomEvent(eventType, attributes, agent), agent)
13
+ }
14
+
15
+ export function recordCustomEvent (eventType, attributes = {}, agentRef, target, timestamp = now()) {
16
+ handle(prefix + RECORD_CUSTOM_EVENT, [timestamp, eventType, attributes, target], undefined, FEATURE_NAMES.genericEvents, agentRef.ee)
15
17
  }
@@ -5,29 +5,33 @@
5
5
 
6
6
  /**
7
7
  * @typedef {Object} RegisterAPI
8
- * @property {Function} addPageAction - Add a page action for the registered entity.
9
- * @property {Function} log - Capture a log for the registered entity.
10
- * @property {Function} noticeError - Notice an error for the registered entity.
11
- * @property {Function} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
12
- * @property {Function} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
13
- * @property {Function} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
8
+ * @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
9
+ * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
10
+ * @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
11
+ * @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
12
+ * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
13
+ * @property {(eventType: string, options?: {start: number, end: number, duration: number, customAttributes: object}) => ({start: number, end: number, duration: number, customAttributes: object})} measure - Measures a task that is recorded as a BrowserPerformance event.
14
+ * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
15
+ * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
16
+ * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
14
17
  * @property {RegisterAPIMetadata} metadata - The metadata object containing the custom attributes and target information for the registered entity.
15
18
  */
16
19
 
17
20
  /**
18
21
  * @typedef {Object} RegisterAPIConstructor
19
- * @property {Object} opts - The options for the registered entity.
20
- * @property {string} opts.id - The unique id for the registered entity. This will be assigned to any synthesized entities.
21
- * @property {string} opts.name - The readable name for the registered entity. This will be assigned to any synthesized entities.
22
+ * @property {string|number} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
23
+ * @property {string} name - The readable name for the registered entity. This will be assigned to any synthesized entities.
24
+ * @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
22
25
  */
23
26
 
24
27
  /**
25
28
  * @typedef {Object} RegisterAPIMetadata
26
29
  * @property {Object} customAttributes - The custom attributes for the registered entity.
27
30
  * @property {Object} target - The options for the registered entity.
28
- * @property {string} target.licenseKey - The license key for the registered entity. If none was supplied, it will assume the license key from the main agent.
31
+ * @property {string} [target.licenseKey] - The license key for the registered entity. If none was supplied, it will assume the license key from the main agent.
29
32
  * @property {string} target.id - The ID for the registered entity.
30
33
  * @property {string} target.name - The name returned for the registered entity.
34
+ * @property {string} [target.parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
31
35
  */
32
36
 
33
37
  export default {}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { handle } from '../../common/event-emitter/handle'
6
6
  import { warn } from '../../common/util/console'
7
- import { isValidMFETarget } from '../../common/util/mfe'
7
+ import { hasValidValue, isValidMFETarget } from '../../common/util/mfe'
8
8
  import { FEATURE_NAMES } from '../features/features'
9
9
  import { now } from '../../common/timing/now'
10
10
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
@@ -14,6 +14,8 @@ import { log } from './log'
14
14
  import { addPageAction } from './addPageAction'
15
15
  import { noticeError } from './noticeError'
16
16
  import { single } from '../../common/util/invoke'
17
+ import { measure } from './measure'
18
+ import { recordCustomEvent } from './recordCustomEvent'
17
19
 
18
20
  /**
19
21
  * @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
@@ -26,7 +28,7 @@ import { single } from '../../common/util/invoke'
26
28
  */
27
29
  export function setupRegisterAPI (agent) {
28
30
  setupAPI(REGISTER, function (target) {
29
- return buildRegisterApi(agent, target)
31
+ return register(agent, target)
30
32
  }, agent)
31
33
  }
32
34
 
@@ -34,20 +36,19 @@ export function setupRegisterAPI (agent) {
34
36
  * Builds the api object that will be returned from the register api method.
35
37
  * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
36
38
  * @param {Object} agentRef the reference to the base agent instance
37
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
38
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
39
- * @param {string} [target.licenseKey] the license key of the target to report data to
40
- * @param {string} target.id the entity ID of the target to report data to
41
- * @param {string} target.name the entity name of the target to report data to
39
+ * @param {import('./register-api-types').RegisterAPIConstructor} target
40
+ * @param {import('./register-api-types').RegisterAPIConstructor} [parent]
42
41
  * @returns {RegisterAPI} the api object to be returned from the register api method
43
42
  */
44
- export function buildRegisterApi (agentRef, target) {
43
+ function register (agentRef, target, parent) {
45
44
  const attrs = {}
46
45
  warn(54, 'newrelic.register')
47
46
 
48
47
  target ||= {}
48
+ target.eventSource = 'MicroFrontendBrowserAgent'
49
49
  target.licenseKey ||= agentRef.info.licenseKey // will inherit the license key from the container agent if not provided for brevity. A future state may dictate that we need different license keys to do different things.
50
50
  target.blocked = false
51
+ target.parent = parent || {}
51
52
 
52
53
  /** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
53
54
  let invalidApiResponse = () => {}
@@ -73,12 +74,18 @@ export function buildRegisterApi (agentRef, target) {
73
74
  /** primary cases that can block the register API from working at init time */
74
75
  if (!agentRef.init.api.allow_registered_children) block(single(() => warn(55)))
75
76
  if (!isValidMFETarget(target)) block(single(() => warn(48, target)))
77
+ if (!hasValidValue(target.id) || !hasValidValue(target.name)) {
78
+ block(single(() => warn(48, target)))
79
+ }
76
80
 
77
81
  /** @type {RegisterAPI} */
78
82
  const api = {
79
83
  addPageAction: (name, attributes = {}) => report(addPageAction, [name, { ...attrs, ...attributes }, agentRef], target),
80
84
  log: (message, options = {}) => report(log, [message, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
85
+ measure: (name, options = {}) => report(measure, [name, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
81
86
  noticeError: (error, attributes = {}) => report(noticeError, [error, { ...attrs, ...attributes }, agentRef], target),
87
+ register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
88
+ recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, { ...attrs, ...attributes }, agentRef], target),
82
89
  setApplicationVersion: (value) => setLocalValue('application.version', value),
83
90
  setCustomAttribute: (key, value) => setLocalValue(key, value),
84
91
  setUserId: (value) => setLocalValue('enduser.id', value),
@@ -126,8 +133,8 @@ export function buildRegisterApi (agentRef, target) {
126
133
  const timestamp = now()
127
134
  handle(SUPPORTABILITY_METRIC_CHANNEL, [`API/register/${methodToCall.name}/called`], undefined, FEATURE_NAMES.metrics, agentRef.ee)
128
135
  try {
129
- const shouldDuplicate = agentRef.init.api.duplicate_registered_data
130
- if (shouldDuplicate === true || Array.isArray(shouldDuplicate)) {
136
+ const shouldDuplicate = agentRef.init.api.duplicate_registered_data && methodToCall.name !== 'register'
137
+ if (shouldDuplicate) {
131
138
  // also report to container by providing undefined target
132
139
  methodToCall(...args, undefined, timestamp)
133
140
  }
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { warn } from '../common/util/console'
6
- import { ADD_PAGE_ACTION, ADD_RELEASE, ADD_TO_TRACE, FINISHED, INTERACTION, LOG, NOTICE_ERROR, PAUSE_REPLAY, RECORD_CUSTOM_EVENT, RECORD_REPLAY, REGISTER, SET_APPLICATION_VERSION, SET_CURRENT_ROUTE_NAME, SET_CUSTOM_ATTRIBUTE, SET_ERROR_HANDLER, SET_PAGE_VIEW_NAME, SET_USER_ID, START, WRAP_LOGGER, MEASURE } from './api/constants'
6
+ import { ADD_PAGE_ACTION, ADD_RELEASE, ADD_TO_TRACE, CONSENT, FINISHED, INTERACTION, LOG, NOTICE_ERROR, PAUSE_REPLAY, RECORD_CUSTOM_EVENT, RECORD_REPLAY, REGISTER, SET_APPLICATION_VERSION, SET_CURRENT_ROUTE_NAME, SET_CUSTOM_ATTRIBUTE, SET_ERROR_HANDLER, SET_PAGE_VIEW_NAME, SET_USER_ID, START, WRAP_LOGGER, MEASURE } from './api/constants'
7
7
 
8
8
  /**
9
9
  * @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
@@ -32,11 +32,8 @@ export class ApiBase {
32
32
  * It is not recommended for use in production environments and will not receive support for issues.
33
33
  *
34
34
  * Registers an external caller to report through the base agent to a different target than the base agent.
35
- * @param {object} target the target object to report data to
36
- * @param {string} target.licenseKey The licenseKey to report data to
37
- * @param {string} target.applicationID The applicationID to report data to
38
- * @param {string=} target.entityGuid The entityGuid to report data to
39
- * @returns {object} Returns an object that contains the available API methods and configurations to use with the external caller. See loaders/api/api.js for more information.
35
+ * @param {import('./api/register-api-types').RegisterAPIConstructor} target the target object to report data to
36
+ @returns {import('./api/register-api-types').RegisterAPI} Returns an object that contains the available API methods and configurations to use with the external caller. See loaders/api/api.js for more information.
40
37
  */
41
38
  register (target) {
42
39
  return this.#callMethod(REGISTER, target)
@@ -46,7 +43,7 @@ export class ApiBase {
46
43
  * Records a custom event with a specified eventType and attributes.
47
44
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordCustomEvent/}
48
45
  * @param {string} eventType The eventType to store the event as.
49
- * @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}.
46
+ * @param {Object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}.
50
47
  */
51
48
  recordCustomEvent (eventType, attributes) {
52
49
  return this.#callMethod(RECORD_CUSTOM_EVENT, eventType, attributes)
@@ -222,10 +219,20 @@ export class ApiBase {
222
219
  * Measures a task that is recorded as a BrowserPerformance event.
223
220
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
224
221
  * @param {string} name The name of the task
225
- * @param {object?} options An object used to control the way the measure API operates
222
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
226
223
  * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
227
224
  */
228
225
  measure (name, options) {
229
226
  return this.#callMethod(MEASURE, name, options)
230
227
  }
228
+
229
+ /**
230
+ * Accepts or rejects consent when the agent is configured to require consent before harvesting.
231
+ * The consent state is stored in session storage inside the NRBA_SESSION object.
232
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/consent/}
233
+ * @param {boolean?} accept Whether to accept or reject consent. Defaults to true (accept) if left undefined.
234
+ */
235
+ consent (accept) {
236
+ return this.#callMethod(CONSENT, accept)
237
+ }
231
238
  }