@newrelic/browser-agent 1.302.0-rc.10 → 1.302.0-rc.11

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.
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.302.0-rc.10";
20
+ const VERSION = exports.VERSION = "1.302.0-rc.11";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.302.0-rc.10";
20
+ const VERSION = exports.VERSION = "1.302.0-rc.11";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -24,6 +24,8 @@ function hasValidValue(val) {
24
24
 
25
25
  /**
26
26
  * When given a valid target, returns an object with the MFE payload attributes. Returns an empty object otherwise.
27
+ * @note Field names may change as the schema is finalized
28
+ *
27
29
  * @param {Object} [target] the registered target
28
30
  * @param {AggregateInstance} [aggregateInstance] the aggregate instance calling the method
29
31
  * @returns {{'mfe.id': *, 'mfe.name': String}|{}} returns an empty object if args are not supplied or the aggregate instance is not supporting version 2
@@ -39,11 +41,8 @@ function getVersion2Attributes(target, aggregateInstance) {
39
41
  }
40
42
  return {
41
43
  'mfe.id': target.id,
42
- // these field names may change as the schema is finalized
43
44
  'mfe.name': target.name,
44
- // these field names may change as the schema is finalized
45
- eventSource: 'MicroFrontendBrowserAgent',
46
- // these field names may change as the schema is finalized
47
- 'parent.id': containerAgentEntityGuid
45
+ eventSource: target.eventSource,
46
+ 'parent.id': target.parent?.id || containerAgentEntityGuid
48
47
  };
49
48
  }
@@ -13,8 +13,9 @@ exports.default = void 0;
13
13
  * @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
14
14
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
15
15
  * @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
16
+ * @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
16
17
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
17
- * @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.
18
+ * @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.
18
19
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
19
20
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
20
21
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -24,13 +25,15 @@ exports.default = void 0;
24
25
  * @typedef {Object} RegisterAPIConstructor
25
26
  * @property {string|number} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
26
27
  * @property {string} name - The readable name for the registered entity. This will be assigned to any synthesized entities.
28
+ * @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
27
29
  */
28
30
  /**
29
31
  * @typedef {Object} RegisterAPIMetadata
30
32
  * @property {Object} customAttributes - The custom attributes for the registered entity.
31
33
  * @property {Object} target - The options for the registered entity.
32
- * @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.
34
+ * @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.
33
35
  * @property {string} target.id - The ID for the registered entity.
34
36
  * @property {string} target.name - The name returned for the registered entity.
37
+ * @property {string} [target.parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
35
38
  */
36
39
  var _default = exports.default = {};
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildRegisterApi = buildRegisterApi;
7
6
  exports.setupRegisterAPI = setupRegisterAPI;
8
7
  var _handle = require("../../common/event-emitter/handle");
9
8
  var _console = require("../../common/util/console");
@@ -35,7 +34,7 @@ var _recordCustomEvent = require("./recordCustomEvent");
35
34
  */
36
35
  function setupRegisterAPI(agent) {
37
36
  (0, _sharedHandlers.setupAPI)(_constants2.REGISTER, function (target) {
38
- return buildRegisterApi(agent, target);
37
+ return register(agent, target);
39
38
  }, agent);
40
39
  }
41
40
 
@@ -43,19 +42,18 @@ function setupRegisterAPI(agent) {
43
42
  * Builds the api object that will be returned from the register api method.
44
43
  * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
45
44
  * @param {Object} agentRef the reference to the base agent instance
46
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
47
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
48
- * @param {string} [target.licenseKey] the license key of the target to report data to
49
- * @param {string} target.id the entity ID of the target to report data to
50
- * @param {string} target.name the entity name of the target to report data to
45
+ * @param {import('./register-api-types').RegisterAPIConstructor} target
46
+ * @param {import('./register-api-types').RegisterAPIConstructor} [parent]
51
47
  * @returns {RegisterAPI} the api object to be returned from the register api method
52
48
  */
53
- function buildRegisterApi(agentRef, target) {
49
+ function register(agentRef, target, parent) {
54
50
  const attrs = {};
55
51
  (0, _console.warn)(54, 'newrelic.register');
56
52
  target ||= {};
53
+ target.eventSource = 'MicroFrontendBrowserAgent';
57
54
  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.
58
55
  target.blocked = false;
56
+ target.parent = parent || {};
59
57
 
60
58
  /** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
61
59
  let invalidApiResponse = () => {};
@@ -116,6 +114,7 @@ function buildRegisterApi(agentRef, target) {
116
114
  ...attrs,
117
115
  ...attributes
118
116
  }, agentRef], target),
117
+ register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
119
118
  recordCustomEvent: (eventType, attributes = {}) => report(_recordCustomEvent.recordCustomEvent, [eventType, {
120
119
  ...attrs,
121
120
  ...attributes
@@ -167,8 +166,8 @@ function buildRegisterApi(agentRef, target) {
167
166
  const timestamp = (0, _now.now)();
168
167
  (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ["API/register/".concat(methodToCall.name, "/called")], undefined, _features.FEATURE_NAMES.metrics, agentRef.ee);
169
168
  try {
170
- const shouldDuplicate = agentRef.init.api.duplicate_registered_data;
171
- if (shouldDuplicate === true || Array.isArray(shouldDuplicate)) {
169
+ const shouldDuplicate = agentRef.init.api.duplicate_registered_data && methodToCall.name !== 'register';
170
+ if (shouldDuplicate) {
172
171
  // also report to container by providing undefined target
173
172
  methodToCall(...args, undefined, timestamp);
174
173
  }
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.302.0-rc.10";
14
+ export const VERSION = "1.302.0-rc.11";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.302.0-rc.10";
14
+ export const VERSION = "1.302.0-rc.11";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -16,6 +16,8 @@ export function hasValidValue(val) {
16
16
 
17
17
  /**
18
18
  * When given a valid target, returns an object with the MFE payload attributes. Returns an empty object otherwise.
19
+ * @note Field names may change as the schema is finalized
20
+ *
19
21
  * @param {Object} [target] the registered target
20
22
  * @param {AggregateInstance} [aggregateInstance] the aggregate instance calling the method
21
23
  * @returns {{'mfe.id': *, 'mfe.name': String}|{}} returns an empty object if args are not supplied or the aggregate instance is not supporting version 2
@@ -31,11 +33,8 @@ export function getVersion2Attributes(target, aggregateInstance) {
31
33
  }
32
34
  return {
33
35
  'mfe.id': target.id,
34
- // these field names may change as the schema is finalized
35
36
  'mfe.name': target.name,
36
- // these field names may change as the schema is finalized
37
- eventSource: 'MicroFrontendBrowserAgent',
38
- // these field names may change as the schema is finalized
39
- 'parent.id': containerAgentEntityGuid
37
+ eventSource: target.eventSource,
38
+ 'parent.id': target.parent?.id || containerAgentEntityGuid
40
39
  };
41
40
  }
@@ -8,8 +8,9 @@
8
8
  * @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
9
9
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
10
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.
11
12
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
12
- * @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.
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.
13
14
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
14
15
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
15
16
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -20,15 +21,17 @@
20
21
  * @typedef {Object} RegisterAPIConstructor
21
22
  * @property {string|number} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
22
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.
23
25
  */
24
26
 
25
27
  /**
26
28
  * @typedef {Object} RegisterAPIMetadata
27
29
  * @property {Object} customAttributes - The custom attributes for the registered entity.
28
30
  * @property {Object} target - The options for the registered entity.
29
- * @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.
30
32
  * @property {string} target.id - The ID for the registered entity.
31
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.
32
35
  */
33
36
 
34
37
  export default {};
@@ -28,7 +28,7 @@ import { recordCustomEvent } from './recordCustomEvent';
28
28
  */
29
29
  export function setupRegisterAPI(agent) {
30
30
  setupAPI(REGISTER, function (target) {
31
- return buildRegisterApi(agent, target);
31
+ return register(agent, target);
32
32
  }, agent);
33
33
  }
34
34
 
@@ -36,19 +36,18 @@ export function setupRegisterAPI(agent) {
36
36
  * Builds the api object that will be returned from the register api method.
37
37
  * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
38
38
  * @param {Object} agentRef the reference to the base agent instance
39
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
40
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
41
- * @param {string} [target.licenseKey] the license key of the target to report data to
42
- * @param {string} target.id the entity ID of the target to report data to
43
- * @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]
44
41
  * @returns {RegisterAPI} the api object to be returned from the register api method
45
42
  */
46
- export function buildRegisterApi(agentRef, target) {
43
+ function register(agentRef, target, parent) {
47
44
  const attrs = {};
48
45
  warn(54, 'newrelic.register');
49
46
  target ||= {};
47
+ target.eventSource = 'MicroFrontendBrowserAgent';
50
48
  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.
51
49
  target.blocked = false;
50
+ target.parent = parent || {};
52
51
 
53
52
  /** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
54
53
  let invalidApiResponse = () => {};
@@ -109,6 +108,7 @@ export function buildRegisterApi(agentRef, target) {
109
108
  ...attrs,
110
109
  ...attributes
111
110
  }, agentRef], target),
111
+ register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
112
112
  recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, {
113
113
  ...attrs,
114
114
  ...attributes
@@ -160,8 +160,8 @@ export function buildRegisterApi(agentRef, target) {
160
160
  const timestamp = now();
161
161
  handle(SUPPORTABILITY_METRIC_CHANNEL, ["API/register/".concat(methodToCall.name, "/called")], undefined, FEATURE_NAMES.metrics, agentRef.ee);
162
162
  try {
163
- const shouldDuplicate = agentRef.init.api.duplicate_registered_data;
164
- if (shouldDuplicate === true || Array.isArray(shouldDuplicate)) {
163
+ const shouldDuplicate = agentRef.init.api.duplicate_registered_data && methodToCall.name !== 'register';
164
+ if (shouldDuplicate) {
165
165
  // also report to container by providing undefined target
166
166
  methodToCall(...args, undefined, timestamp);
167
167
  }
@@ -10,6 +10,8 @@ export function isValidMFETarget(target?: Object): boolean;
10
10
  export function hasValidValue(val: any): boolean;
11
11
  /**
12
12
  * When given a valid target, returns an object with the MFE payload attributes. Returns an empty object otherwise.
13
+ * @note Field names may change as the schema is finalized
14
+ *
13
15
  * @param {Object} [target] the registered target
14
16
  * @param {AggregateInstance} [aggregateInstance] the aggregate instance calling the method
15
17
  * @returns {{'mfe.id': *, 'mfe.name': String}|{}} returns an empty object if args are not supplied or the aggregate instance is not supporting version 2
@@ -1 +1 @@
1
- {"version":3,"file":"mfe.d.ts","sourceRoot":"","sources":["../../../../src/common/util/mfe.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,0CAHW,MAAM,GACJ,OAAO,CAInB;AAED,iDAEC;AAED;;;;;GAKG;AACH,+CAJW,MAAM,sBACN,iBAAiB,GACf;IAAC,QAAQ,EAAE,GAAC,CAAC;IAAC,UAAU,SAAQ;CAAC,GAAC,EAAE,CAiBhD"}
1
+ {"version":3,"file":"mfe.d.ts","sourceRoot":"","sources":["../../../../src/common/util/mfe.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,0CAHW,MAAM,GACJ,OAAO,CAInB;AAED,iDAEC;AAED;;;;;;;GAOG;AACH,+CAJW,MAAM,sBACN,iBAAiB,GACf;IAAC,QAAQ,EAAE,GAAC,CAAC;IAAC,UAAU,SAAQ;CAAC,GAAC,EAAE,CAiBhD"}
@@ -16,19 +16,28 @@ export type RegisterAPI = {
16
16
  * - Notice an error for the registered entity.
17
17
  */
18
18
  noticeError: (error: Error | string, customAttributes?: object) => void;
19
+ /**
20
+ * - Record a custom event for the registered entity.
21
+ */
22
+ register: (target: RegisterAPIConstructor) => RegisterAPI;
19
23
  /**
20
24
  * - Record a custom event for the registered entity.
21
25
  */
22
26
  recordCustomEvent: (eventType: string, attributes?: Object) => void;
23
27
  /**
24
- * {start: number, end: number, duration: number, customAttributes: object}}} measure - Measures a task that is recorded as a BrowserPerformance event.
28
+ * - Measures a task that is recorded as a BrowserPerformance event.
25
29
  */
26
- "": (eventType: string, options?: {
30
+ measure: (eventType: string, options?: {
27
31
  start: number;
28
32
  end: number;
29
33
  duration: number;
30
34
  customAttributes: object;
31
- }) => {};
35
+ }) => ({
36
+ start: number;
37
+ end: number;
38
+ duration: number;
39
+ customAttributes: object;
40
+ });
32
41
  /**
33
42
  * - Add an application.version attribute to all outgoing data for the registered entity.
34
43
  */
@@ -55,6 +64,10 @@ export type RegisterAPIConstructor = {
55
64
  * - The readable name for the registered entity. This will be assigned to any synthesized entities.
56
65
  */
57
66
  name: string;
67
+ /**
68
+ * - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
69
+ */
70
+ parentId?: string | undefined;
58
71
  };
59
72
  export type RegisterAPIMetadata = {
60
73
  /**
@@ -65,9 +78,10 @@ export type RegisterAPIMetadata = {
65
78
  * - The options for the registered entity.
66
79
  */
67
80
  target: {
68
- licenseKey: string;
81
+ licenseKey?: string | undefined;
69
82
  id: string;
70
83
  name: string;
84
+ parentId?: string | undefined;
71
85
  };
72
86
  };
73
87
  //# sourceMappingURL=register-api-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-api-types.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api-types.js"],"names":[],"mappings":";;;;;;mBAOc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;SAC3C,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;KAAC,KAAK,IAAI;;;;iBACxH,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,KAAK,IAAI;;;;uBAC1D,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;QAChD,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,KAAK,EAAC;;;;2BAC5G,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;wBAC9B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI;;;;eAClF,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;cAC9B,mBAAmB;;;;;;QAKnB,MAAM,GAAC,MAAM;;;;UACb,MAAM;;;;;;sBAKN,MAAM;;;;YAEjB;QAA0B,UAAU,EAAzB,MAAM;QACS,EAAE,EAAjB,MAAM;QACS,IAAI,EAAnB,MAAM;KACnB"}
1
+ {"version":3,"file":"register-api-types.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api-types.js"],"names":[],"mappings":";;;;;;mBAOc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;SAC3C,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;KAAC,KAAK,IAAI;;;;iBACxH,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,KAAK,IAAI;;;;cAC1D,CAAC,MAAM,EAAE,sBAAsB,KAAK,WAAW;;;;uBAC/C,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;aAChD,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,CAAC;;;;2BACrL,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;wBAC9B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI;;;;eAClF,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;cAC9B,mBAAmB;;;;;;QAKnB,MAAM,GAAC,MAAM;;;;UACb,MAAM;;;;;;;;;;sBAMN,MAAM;;;;YAEjB;QAA2B,UAAU;QACX,EAAE,EAAjB,MAAM;QACS,IAAI,EAAnB,MAAM;QACU,QAAQ;KACrC"}
@@ -7,21 +7,5 @@
7
7
  * It is not recommended for use in production environments and will not receive support for issues.
8
8
  */
9
9
  export function setupRegisterAPI(agent: any): void;
10
- /**
11
- * Builds the api object that will be returned from the register api method.
12
- * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
13
- * @param {Object} agentRef the reference to the base agent instance
14
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
15
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
16
- * @param {string} [target.licenseKey] the license key of the target to report data to
17
- * @param {string} target.id the entity ID of the target to report data to
18
- * @param {string} target.name the entity name of the target to report data to
19
- * @returns {RegisterAPI} the api object to be returned from the register api method
20
- */
21
- export function buildRegisterApi(agentRef: Object, target: {
22
- licenseKey?: string | undefined;
23
- id: string;
24
- name: string;
25
- }): RegisterAPI;
26
10
  export type RegisterAPI = import("./register-api-types").RegisterAPI;
27
11
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAmBA;;GAEG;AAEH;;;;GAIG;AACH,mDAIC;AAED;;;;;;;;;;GAUG;AACH,2CARW,MAAM,UAGd;IAAwB,UAAU;IACX,EAAE,EAAjB,MAAM;IACS,IAAI,EAAnB,MAAM;CACd,GAAU,WAAW,CAwGvB;0BA/HY,OAAO,sBAAsB,EAAE,WAAW"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAmBA;;GAEG;AAEH;;;;GAIG;AACH,mDAIC;0BAZY,OAAO,sBAAsB,EAAE,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.302.0-rc.10",
3
+ "version": "1.302.0-rc.11",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -17,6 +17,8 @@ export function hasValidValue (val) {
17
17
 
18
18
  /**
19
19
  * When given a valid target, returns an object with the MFE payload attributes. Returns an empty object otherwise.
20
+ * @note Field names may change as the schema is finalized
21
+ *
20
22
  * @param {Object} [target] the registered target
21
23
  * @param {AggregateInstance} [aggregateInstance] the aggregate instance calling the method
22
24
  * @returns {{'mfe.id': *, 'mfe.name': String}|{}} returns an empty object if args are not supplied or the aggregate instance is not supporting version 2
@@ -31,9 +33,9 @@ export function getVersion2Attributes (target, aggregateInstance) {
31
33
  }
32
34
  }
33
35
  return {
34
- 'mfe.id': target.id, // these field names may change as the schema is finalized
35
- 'mfe.name': target.name, // these field names may change as the schema is finalized
36
- eventSource: 'MicroFrontendBrowserAgent', // these field names may change as the schema is finalized
37
- 'parent.id': containerAgentEntityGuid
36
+ 'mfe.id': target.id,
37
+ 'mfe.name': target.name,
38
+ eventSource: target.eventSource,
39
+ 'parent.id': target.parent?.id || containerAgentEntityGuid
38
40
  }
39
41
  }
@@ -8,8 +8,9 @@
8
8
  * @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
9
9
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
10
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.
11
12
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
12
- * @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.
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.
13
14
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
14
15
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
15
16
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -20,15 +21,17 @@
20
21
  * @typedef {Object} RegisterAPIConstructor
21
22
  * @property {string|number} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
22
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.
23
25
  */
24
26
 
25
27
  /**
26
28
  * @typedef {Object} RegisterAPIMetadata
27
29
  * @property {Object} customAttributes - The custom attributes for the registered entity.
28
30
  * @property {Object} target - The options for the registered entity.
29
- * @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.
30
32
  * @property {string} target.id - The ID for the registered entity.
31
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.
32
35
  */
33
36
 
34
37
  export default {}
@@ -28,7 +28,7 @@ import { recordCustomEvent } from './recordCustomEvent'
28
28
  */
29
29
  export function setupRegisterAPI (agent) {
30
30
  setupAPI(REGISTER, function (target) {
31
- return buildRegisterApi(agent, target)
31
+ return register(agent, target)
32
32
  }, agent)
33
33
  }
34
34
 
@@ -36,20 +36,19 @@ export function setupRegisterAPI (agent) {
36
36
  * Builds the api object that will be returned from the register api method.
37
37
  * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
38
38
  * @param {Object} agentRef the reference to the base agent instance
39
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
40
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
41
- * @param {string} [target.licenseKey] the license key of the target to report data to
42
- * @param {string} target.id the entity ID of the target to report data to
43
- * @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]
44
41
  * @returns {RegisterAPI} the api object to be returned from the register api method
45
42
  */
46
- export function buildRegisterApi (agentRef, target) {
43
+ function register (agentRef, target, parent) {
47
44
  const attrs = {}
48
45
  warn(54, 'newrelic.register')
49
46
 
50
47
  target ||= {}
48
+ target.eventSource = 'MicroFrontendBrowserAgent'
51
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.
52
50
  target.blocked = false
51
+ target.parent = parent || {}
53
52
 
54
53
  /** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
55
54
  let invalidApiResponse = () => {}
@@ -85,6 +84,7 @@ export function buildRegisterApi (agentRef, target) {
85
84
  log: (message, options = {}) => report(log, [message, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
86
85
  measure: (name, options = {}) => report(measure, [name, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
87
86
  noticeError: (error, attributes = {}) => report(noticeError, [error, { ...attrs, ...attributes }, agentRef], target),
87
+ register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
88
88
  recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, { ...attrs, ...attributes }, agentRef], target),
89
89
  setApplicationVersion: (value) => setLocalValue('application.version', value),
90
90
  setCustomAttribute: (key, value) => setLocalValue(key, value),
@@ -133,8 +133,8 @@ export function buildRegisterApi (agentRef, target) {
133
133
  const timestamp = now()
134
134
  handle(SUPPORTABILITY_METRIC_CHANNEL, [`API/register/${methodToCall.name}/called`], undefined, FEATURE_NAMES.metrics, agentRef.ee)
135
135
  try {
136
- const shouldDuplicate = agentRef.init.api.duplicate_registered_data
137
- if (shouldDuplicate === true || Array.isArray(shouldDuplicate)) {
136
+ const shouldDuplicate = agentRef.init.api.duplicate_registered_data && methodToCall.name !== 'register'
137
+ if (shouldDuplicate) {
138
138
  // also report to container by providing undefined target
139
139
  methodToCall(...args, undefined, timestamp)
140
140
  }