@newrelic/browser-agent 1.301.0 → 1.302.0-alpha.0

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 (142) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/common/config/init-types.js +1 -1
  3. package/dist/cjs/common/config/init.js +7 -1
  4. package/dist/cjs/common/config/runtime.js +1 -1
  5. package/dist/cjs/common/constants/agent-constants.js +11 -2
  6. package/dist/cjs/common/constants/env.cdn.js +1 -1
  7. package/dist/cjs/common/constants/env.npm.js +1 -1
  8. package/dist/cjs/common/drain/drain.js +1 -1
  9. package/dist/cjs/common/harvest/harvester.js +30 -39
  10. package/dist/cjs/common/util/mfe.js +45 -0
  11. package/dist/cjs/features/ajax/aggregate/index.js +5 -1
  12. package/dist/cjs/features/generic_events/aggregate/index.js +9 -8
  13. package/dist/cjs/features/generic_events/constants.js +3 -1
  14. package/dist/cjs/features/generic_events/instrument/index.js +38 -32
  15. package/dist/cjs/features/jserrors/aggregate/index.js +18 -17
  16. package/dist/cjs/features/logging/aggregate/index.js +19 -15
  17. package/dist/cjs/features/logging/shared/utils.js +3 -3
  18. package/dist/cjs/features/page_view_event/aggregate/index.js +3 -33
  19. package/dist/cjs/features/session_replay/aggregate/index.js +13 -13
  20. package/dist/cjs/features/session_replay/shared/recorder.js +3 -2
  21. package/dist/cjs/features/session_trace/aggregate/index.js +0 -2
  22. package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -2
  23. package/dist/cjs/features/utils/aggregate-base.js +45 -47
  24. package/dist/cjs/loaders/api/addPageAction.js +2 -2
  25. package/dist/cjs/loaders/api/log.js +2 -2
  26. package/dist/cjs/loaders/api/noticeError.js +2 -2
  27. package/dist/cjs/loaders/api/register-api-types.js +5 -5
  28. package/dist/cjs/loaders/api/register.js +80 -97
  29. package/dist/esm/common/config/init-types.js +1 -1
  30. package/dist/esm/common/config/init.js +7 -1
  31. package/dist/esm/common/config/runtime.js +1 -1
  32. package/dist/esm/common/constants/agent-constants.js +9 -1
  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/drain/drain.js +1 -1
  36. package/dist/esm/common/harvest/harvester.js +30 -39
  37. package/dist/esm/common/util/mfe.js +38 -0
  38. package/dist/esm/features/ajax/aggregate/index.js +5 -1
  39. package/dist/esm/features/generic_events/aggregate/index.js +9 -8
  40. package/dist/esm/features/generic_events/constants.js +3 -1
  41. package/dist/esm/features/generic_events/instrument/index.js +38 -32
  42. package/dist/esm/features/jserrors/aggregate/index.js +18 -17
  43. package/dist/esm/features/logging/aggregate/index.js +19 -15
  44. package/dist/esm/features/logging/shared/utils.js +3 -3
  45. package/dist/esm/features/page_view_event/aggregate/index.js +3 -33
  46. package/dist/esm/features/session_replay/aggregate/index.js +13 -13
  47. package/dist/esm/features/session_replay/shared/recorder.js +3 -2
  48. package/dist/esm/features/session_trace/aggregate/index.js +0 -2
  49. package/dist/esm/features/soft_navigations/aggregate/index.js +1 -2
  50. package/dist/esm/features/utils/aggregate-base.js +46 -48
  51. package/dist/esm/loaders/api/addPageAction.js +2 -2
  52. package/dist/esm/loaders/api/log.js +2 -2
  53. package/dist/esm/loaders/api/noticeError.js +2 -2
  54. package/dist/esm/loaders/api/register-api-types.js +5 -5
  55. package/dist/esm/loaders/api/register.js +80 -97
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/dist/types/common/config/init-types.d.ts +4 -1
  58. package/dist/types/common/config/init-types.d.ts.map +1 -1
  59. package/dist/types/common/config/init.d.ts.map +1 -1
  60. package/dist/types/common/constants/agent-constants.d.ts +7 -4
  61. package/dist/types/common/constants/agent-constants.d.ts.map +1 -1
  62. package/dist/types/common/harvest/harvester.d.ts +2 -2
  63. package/dist/types/common/harvest/harvester.d.ts.map +1 -1
  64. package/dist/types/common/util/mfe.d.ts +20 -0
  65. package/dist/types/common/util/mfe.d.ts.map +1 -0
  66. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  67. package/dist/types/features/generic_events/aggregate/index.d.ts +2 -2
  68. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  69. package/dist/types/features/generic_events/constants.d.ts +1 -0
  70. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  71. package/dist/types/features/jserrors/aggregate/index.d.ts +3 -3
  72. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  73. package/dist/types/features/logging/aggregate/index.d.ts +3 -3
  74. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  75. package/dist/types/features/logging/shared/utils.d.ts +2 -2
  76. package/dist/types/features/logging/shared/utils.d.ts.map +1 -1
  77. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -4
  78. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  79. package/dist/types/features/session_replay/aggregate/index.d.ts +13 -4
  80. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  81. package/dist/types/features/session_replay/shared/recorder.d.ts +1 -0
  82. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  83. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  84. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  85. package/dist/types/features/utils/aggregate-base.d.ts +13 -5
  86. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  87. package/dist/types/loaders/api/addPageAction.d.ts +1 -1
  88. package/dist/types/loaders/api/addPageAction.d.ts.map +1 -1
  89. package/dist/types/loaders/api/log.d.ts +1 -1
  90. package/dist/types/loaders/api/log.d.ts.map +1 -1
  91. package/dist/types/loaders/api/noticeError.d.ts +1 -1
  92. package/dist/types/loaders/api/noticeError.d.ts.map +1 -1
  93. package/dist/types/loaders/api/register-api-types.d.ts +4 -4
  94. package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
  95. package/dist/types/loaders/api/register.d.ts +8 -1
  96. package/dist/types/loaders/api/register.d.ts.map +1 -1
  97. package/package.json +3 -3
  98. package/src/common/config/init-types.js +1 -1
  99. package/src/common/config/init.js +3 -1
  100. package/src/common/config/runtime.js +1 -1
  101. package/src/common/constants/agent-constants.js +10 -0
  102. package/src/common/drain/drain.js +1 -1
  103. package/src/common/harvest/harvester.js +27 -32
  104. package/src/common/util/mfe.js +35 -0
  105. package/src/features/ajax/aggregate/index.js +7 -1
  106. package/src/features/generic_events/aggregate/index.js +9 -8
  107. package/src/features/generic_events/constants.js +3 -1
  108. package/src/features/generic_events/instrument/index.js +44 -35
  109. package/src/features/jserrors/aggregate/index.js +17 -17
  110. package/src/features/logging/aggregate/index.js +20 -13
  111. package/src/features/logging/shared/utils.js +3 -3
  112. package/src/features/page_view_event/aggregate/index.js +3 -28
  113. package/src/features/session_replay/aggregate/index.js +12 -10
  114. package/src/features/session_replay/shared/recorder.js +3 -2
  115. package/src/features/session_trace/aggregate/index.js +0 -2
  116. package/src/features/soft_navigations/aggregate/index.js +1 -2
  117. package/src/features/utils/aggregate-base.js +47 -42
  118. package/src/loaders/api/addPageAction.js +2 -2
  119. package/src/loaders/api/log.js +2 -2
  120. package/src/loaders/api/noticeError.js +2 -2
  121. package/src/loaders/api/register-api-types.js +5 -5
  122. package/src/loaders/api/register.js +62 -89
  123. package/dist/cjs/common/util/target.js +0 -34
  124. package/dist/cjs/features/utils/entity-manager.js +0 -46
  125. package/dist/cjs/features/utils/event-store-manager.js +0 -174
  126. package/dist/cjs/loaders/api/register-api.js +0 -165
  127. package/dist/esm/common/util/target.js +0 -27
  128. package/dist/esm/features/utils/entity-manager.js +0 -39
  129. package/dist/esm/features/utils/event-store-manager.js +0 -166
  130. package/dist/esm/loaders/api/register-api.js +0 -159
  131. package/dist/types/common/util/target.d.ts +0 -18
  132. package/dist/types/common/util/target.d.ts.map +0 -1
  133. package/dist/types/features/utils/entity-manager.d.ts +0 -11
  134. package/dist/types/features/utils/entity-manager.d.ts.map +0 -1
  135. package/dist/types/features/utils/event-store-manager.d.ts +0 -85
  136. package/dist/types/features/utils/event-store-manager.d.ts.map +0 -1
  137. package/dist/types/loaders/api/register-api.d.ts +0 -14
  138. package/dist/types/loaders/api/register-api.d.ts.map +0 -1
  139. package/src/common/util/target.js +0 -27
  140. package/src/features/utils/entity-manager.js +0 -45
  141. package/src/features/utils/event-store-manager.js +0 -165
  142. package/src/loaders/api/register-api.js +0 -152
@@ -1,159 +0,0 @@
1
- /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { handle } from '../../common/event-emitter/handle';
6
- import { warn } from '../../common/util/console';
7
- import { isContainerAgentTarget, isValidTarget } from '../../common/util/target';
8
- import { FEATURE_NAMES } from '../features/features';
9
- import { now } from '../../common/timing/now';
10
- import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants';
11
-
12
- /**
13
- * @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
14
- */
15
-
16
- /**
17
- * Builds the api object that will be returned from the register api method.
18
- * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
19
- * @param {Object} agentRef the reference to the base agent instance
20
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
21
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
22
- * @returns {RegisterAPI} the api object to be returned from the register api method
23
- */
24
- export function buildRegisterApi(agentRef, handlers, target) {
25
- const attrs = {};
26
- warn(54, 'newrelic.register');
27
-
28
- /** @type {Function|undefined} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
29
- let invalidApiResponse;
30
-
31
- /**
32
- * A promise that indicates when all needed connections for the registered child to be ready to report data
33
- * 1. The main agent to be ready (made a RUM call and got its entity guid)
34
- * 2. The child to be registered with the main agent (made its own RUM call and got its entity guid)
35
- * @type {Promise<RegisterAPI>}
36
- */
37
- let _connected;
38
- if (!agentRef.init.api.allow_registered_children) invalidApiResponse = () => warn(55);
39
- if (!target || !isValidTarget(target)) invalidApiResponse = () => warn(48, target);
40
-
41
- /** @type {RegisterAPI} */
42
- const api = {
43
- addPageAction: (name, attributes = {}) => {
44
- report(handlers.addPageAction, [name, {
45
- ...attrs,
46
- ...attributes
47
- }], target);
48
- },
49
- log: (message, options = {}) => {
50
- report(handlers.log, [message, {
51
- ...options,
52
- customAttributes: {
53
- ...attrs,
54
- ...(options.customAttributes || {})
55
- }
56
- }], target);
57
- },
58
- noticeError: (error, attributes = {}) => {
59
- report(handlers.noticeError, [error, {
60
- ...attrs,
61
- ...attributes
62
- }], target);
63
- },
64
- setApplicationVersion: value => {
65
- attrs['application.version'] = value;
66
- },
67
- setCustomAttribute: (key, value) => {
68
- attrs[key] = value;
69
- },
70
- setUserId: value => {
71
- attrs['enduser.id'] = value;
72
- },
73
- /** metadata */
74
- metadata: {
75
- customAttributes: attrs,
76
- target,
77
- /** set in a getter so that later access of the Promise is not polluted before customer is allowed to set a catch block */
78
- get connected() {
79
- return _connected || Promise.reject(new Error('Failed to connect'));
80
- }
81
- }
82
- };
83
- if (invalidApiResponse) {
84
- invalidApiResponse();
85
- } else {
86
- _connected = new Promise((resolve, reject) => {
87
- try {
88
- const entityManager = agentRef.runtime?.entityManager;
89
- /** check if main agent already has main agent entity guid */
90
- let mainAgentReady = !!entityManager?.get().entityGuid;
91
- /** check if registered target already has entity guid */
92
- let registeredEntityGuid = entityManager?.getEntityGuidFor(target.licenseKey, target.applicationID);
93
- let registrationReady = !!registeredEntityGuid;
94
-
95
- /** check if we can just resolve immediately without making another connect call */
96
- if (mainAgentReady && registrationReady) {
97
- target.entityGuid = registeredEntityGuid;
98
- resolve(api);
99
- } else {
100
- /** we need to make a new connection call since we dont already have a registered entity for this call */
101
-
102
- /** if the connect callback doesnt resolve in 15 seconds... reject */
103
- const timeout = setTimeout(() => reject(new Error('Failed to connect - Timeout')), 15000);
104
-
105
- // tell the main agent to send a rum call for this target
106
- // when the rum call resolves, it will emit an "entity-added" event, see below
107
- agentRef.ee.emit('api-send-rum', [attrs, target]);
108
-
109
- // wait for entity events to emit to see when main agent and/or API registration is ready
110
- agentRef.ee.on('entity-added', entityEventHandler);
111
- function entityEventHandler(entity) {
112
- if (isContainerAgentTarget(entity, agentRef)) mainAgentReady ||= true;else {
113
- if (target.licenseKey === entity.licenseKey && target.applicationID === entity.applicationID) {
114
- registrationReady = true;
115
- target.entityGuid = entity.entityGuid;
116
- }
117
- }
118
- if (mainAgentReady && registrationReady) {
119
- clearTimeout(timeout);
120
- // unsubscribe from the event emitter
121
- agentRef.ee.removeEventListener('entity-added', entityEventHandler);
122
- resolve(api);
123
- }
124
- }
125
- }
126
- } catch (err) {
127
- reject(err);
128
- }
129
- });
130
- }
131
-
132
- /**
133
- * The reporter method that will be used to report the data to the container agent's API method. If invalid, will log a warning and not execute.
134
- * If the api.duplicate_registered_data configuration value is set to true, the data will be reported to BOTH the container and the external target
135
- * @param {*} methodToCall the container agent's API method to call
136
- * @param {*} args the arguments to supply to the container agent's API method
137
- * @param {string} targetEntityGuid the target entity guid, which looks up the target to report the data to from the entity manager. If undefined, will report to the container agent's target.
138
- * @returns
139
- */
140
- const report = async (methodToCall, args, target) => {
141
- if (invalidApiResponse) return invalidApiResponse();
142
- /** set the timestamp before the async part of waiting for the rum response for better accuracy */
143
- const timestamp = now();
144
- handle(SUPPORTABILITY_METRIC_CHANNEL, ["API/register/".concat(methodToCall.name, "/called")], undefined, FEATURE_NAMES.metrics, agentRef.ee);
145
- try {
146
- await _connected;
147
- // target should be decorated with entityGuid by the rum resp at this point
148
- const shouldDuplicate = agentRef.init.api.duplicate_registered_data;
149
- if (shouldDuplicate === true || Array.isArray(shouldDuplicate) && shouldDuplicate.includes(target.entityGuid)) {
150
- // also report to container by providing undefined target
151
- methodToCall(...args, undefined, timestamp);
152
- }
153
- methodToCall(...args, target.entityGuid, timestamp); // always report to target
154
- } catch (err) {
155
- warn(50, err);
156
- }
157
- };
158
- return api;
159
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- /**
6
- * @param {Object} [target] - the target to be validated
7
- * @param {boolean} [allowUndefined=true]
8
- * @returns {boolean}
9
- */
10
- export function isValidTarget(target?: Object): boolean;
11
- /**
12
- * Checks if the target matches the container agent target
13
- * @param {*} target the target to be validated
14
- * @param {*} agentRef the agent reference to be validated
15
- * @returns {boolean}
16
- */
17
- export function isContainerAgentTarget(target: any, agentRef: any): boolean;
18
- //# sourceMappingURL=target.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../src/common/util/target.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,uCAJW,MAAM,GAEJ,OAAO,CAOnB;AAED;;;;;GAKG;AACH,+CAJW,GAAC,YACD,GAAC,GACC,OAAO,CAKnB"}
@@ -1,11 +0,0 @@
1
- export class EntityManager {
2
- constructor(agentRef: any);
3
- agentRef: any;
4
- get(entityGuid?: string): any;
5
- getEntityGuidFor(licenseKey: any, applicationID: any): any;
6
- set(entityGuid: any, entity: any): void;
7
- clear(): void;
8
- setDefaultEntity(entity: any): void;
9
- #private;
10
- }
11
- //# sourceMappingURL=entity-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-manager.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/entity-manager.js"],"names":[],"mappings":"AAOA;IAIE,2BAGC;IAFC,cAAwB;IAI1B,8BAEC;IAED,2DAGC;IAED,wCAUC;IAED,cAEC;IAED,oCAEC;;CACF"}
@@ -1,85 +0,0 @@
1
- /**
2
- * This layer allows multiple browser entity apps, or "target", to each have their own segregated storage instance.
3
- * The purpose is so the harvester can send data to different apps within the same agent. Each feature should have a manager if it needs this capability.
4
- */
5
- export class EventStoreManager {
6
- /**
7
- * @param {object} agentRef - reference to base agent class
8
- * @param {EventBuffer|EventAggregator} storageClass - the type of storage to use in this manager; 'EventBuffer' (1), 'EventAggregator' (2)
9
- * @param {string} [defaultEntityGuid] - the entity guid to use as the default storage instance; if not provided, a new one is created
10
- * @param {Object} featureAgg - the feature aggregate instance that initialized this manager
11
- */
12
- constructor(agentRef: object, storageClass: EventBuffer | EventAggregator, defaultEntityGuid?: string, featureAgg: Object);
13
- agentRef: object;
14
- entityManager: any;
15
- StorageClass: any;
16
- appStorageMap: Map<string, any>;
17
- featureAgg: Object;
18
- setEventStore(targetEntityGuid: any): void;
19
- /** IMPORTANT
20
- * This class must contain an union of all methods from all supported storage classes and conceptualize away the target app argument.
21
- */
22
- get length(): any;
23
- /**
24
- * Calls the merge method on the underlying storage class.
25
- * @param {*} matcher
26
- * @param {*} data
27
- * @param {*} targetEntityGuid
28
- * @returns {boolean} True if the merge was successful
29
- */
30
- merge(matcher: any, data: any, targetEntityGuid: any): boolean;
31
- /**
32
- * Calls the isEmpty method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
33
- * @param {object} optsIfPresent - exists if called during harvest interval, @see AggregateBase.makeHarvestPayload
34
- * @param {object} target - specific app's storage to check; if not provided, this method takes into account all apps recorded by this manager
35
- * @returns {boolean} True if the target's storage is empty, or target does not exist in map (defaults to all storages)
36
- */
37
- isEmpty(optsIfPresent: object, targetEntityGuid: any): boolean;
38
- /**
39
- * Calls the add method on the underlying storage class.
40
- * @param {string} event - the event element to store
41
- * @param {object} targetEntityGuid - the entity guid lookup to store event under; if not provided, this method adds to the default
42
- * @returns {boolean} True if the event was successfully added
43
- */
44
- add(event: string, targetEntityGuid: object): boolean;
45
- /** This is only used by the Metrics feature which has no need to add metric under a different app atm. */
46
- addMetric(type: any, name: any, params: any, value: any): any;
47
- /**
48
- * Calls the get method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
49
- * @param {object=} opts - exists if called during harvest interval, @see AggregateBase.makeHarvestPayload
50
- * @param {object=} target - specific app to fetch; if not provided, this method fetches from all apps
51
- * @returns {Array} Objects of `data` labeled with their respective `target` app to be sent to
52
- */
53
- get(opts?: object | undefined, targetEntityGuid: any): any[];
54
- /**
55
- * Calls the byteSize method on the underlying storage class
56
- * @param {*} targetEntityGuid
57
- * @returns
58
- */
59
- byteSize(targetEntityGuid: any): any;
60
- /**
61
- * Calls the wouldExceedMaxSize method on the underlying storage class
62
- * @param {*} incomingSize
63
- * @param {*} targetEntityGuid
64
- * @returns
65
- */
66
- wouldExceedMaxSize(incomingSize: any, targetEntityGuid: any): any;
67
- /**
68
- * Calls the save method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
69
- * @param {*} optsIfPresent
70
- * @param {*} targetEntityGuid
71
- * @returns
72
- */
73
- save(optsIfPresent: any, targetEntityGuid: any): any;
74
- /**
75
- * Calls the clear method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
76
- * @param {*} optsIfPresent
77
- * @param {*} targetEntityGuid
78
- * @returns
79
- */
80
- clear(optsIfPresent: any, targetEntityGuid: any): any;
81
- reloadSave(optsIfPresent: any, targetEntityGuid: any): any;
82
- clearSave(optsIfPresent: any, targetEntityGuid: any): any;
83
- #private;
84
- }
85
- //# sourceMappingURL=event-store-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-store-manager.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/event-store-manager.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,sBALW,MAAM,gBACN,WAAW,GAAC,eAAe,sBAC3B,MAAM,cACN,MAAM,EAShB;IANC,iBAAwB;IACxB,mBAAmD;IACnD,kBAAgC;IAChC,gCAAkG;IAClG,mBAA4B;IAc9B,2CAQC;IAED;;OAEG;IAEH,kBAEC;IAED;;;;;;OAMG;IACH,eALW,GAAC,QACD,GAAC,oBACD,GAAC,GACC,OAAO,CAInB;IAED;;;;;OAKG;IACH,uBAJW,MAAM,0BAEJ,OAAO,CASnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,oBACN,MAAM,GACJ,OAAO,CAInB;IAED,0GAA0G;IAC1G,8DAEC;IAED;;;;;OAKG;IACH,WAJW,MAAM,YAAC,gCAgBjB;IAED;;;;OAIG;IACH,2BAHW,GAAC,OAKX;IAED;;;;;OAKG;IACH,iCAJW,GAAC,oBACD,GAAC,OAKX;IAED;;;;;OAKG;IACH,oBAJW,GAAC,oBACD,GAAC,OAMX;IAED;;;;;OAKG;IACH,qBAJW,GAAC,oBACD,GAAC,OAMX;IAGD,2DAEC;IAED,0DAEC;;CACF"}
@@ -1,14 +0,0 @@
1
- /**
2
- * @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
3
- */
4
- /**
5
- * Builds the api object that will be returned from the register api method.
6
- * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
7
- * @param {Object} agentRef the reference to the base agent instance
8
- * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
9
- * @param {Object} target the target information to be used by the external target's API to send data to the correct location
10
- * @returns {RegisterAPI} the api object to be returned from the register api method
11
- */
12
- export function buildRegisterApi(agentRef: Object, handlers: Object, target: Object): RegisterAPI;
13
- export type RegisterAPI = import("./register-api-types").RegisterAPI;
14
- //# sourceMappingURL=register-api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"register-api.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api.js"],"names":[],"mappings":"AAWA;;GAEG;AAEH;;;;;;;GAOG;AACH,2CALW,MAAM,YACN,MAAM,UACN,MAAM,GACJ,WAAW,CAkIvB;0BA3IY,OAAO,sBAAsB,EAAE,WAAW"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- /**
7
- * @param {Object} [target] - the target to be validated
8
- * @param {boolean} [allowUndefined=true]
9
- * @returns {boolean}
10
- */
11
- export function isValidTarget (target) {
12
- /** target can be undefined to support legacy/default behaviors - main agent does not supply a target */
13
- if (!target) return true
14
- /** if not undefined, we require specific values */
15
- return !!(target.licenseKey && target.applicationID)
16
- }
17
-
18
- /**
19
- * Checks if the target matches the container agent target
20
- * @param {*} target the target to be validated
21
- * @param {*} agentRef the agent reference to be validated
22
- * @returns {boolean}
23
- */
24
- export function isContainerAgentTarget (target, agentRef) {
25
- if (!target) return true
26
- return (target.licenseKey === agentRef.info.licenseKey && target.applicationID === agentRef.info.applicationID)
27
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- import { DEFAULT_KEY } from '../../common/constants/agent-constants'
7
-
8
- export class EntityManager {
9
- #entities = new Map()
10
- #entityGuidLookup = {}
11
-
12
- constructor (agentRef) {
13
- this.agentRef = agentRef
14
- this.#entities.set(DEFAULT_KEY, { licenseKey: agentRef.info.licenseKey, applicationID: agentRef.info.applicationID })
15
- }
16
-
17
- get (entityGuid = DEFAULT_KEY) {
18
- return this.#entities.get(entityGuid)
19
- }
20
-
21
- getEntityGuidFor (licenseKey, applicationID) {
22
- if (!this.#entityGuidLookup[licenseKey] || !this.#entityGuidLookup[applicationID]) return
23
- return this.#entityGuidLookup[licenseKey].filter(x => this.#entityGuidLookup[applicationID].includes(x))[0]
24
- }
25
-
26
- set (entityGuid, entity) {
27
- if (this.#entities.has(entityGuid)) return
28
- this.#entities.set(entityGuid, entity)
29
-
30
- this.#entityGuidLookup[entity.licenseKey] ??= []
31
- this.#entityGuidLookup[entity.licenseKey].push(entityGuid)
32
- this.#entityGuidLookup[entity.applicationID] ??= []
33
- this.#entityGuidLookup[entity.applicationID].push(entityGuid)
34
-
35
- this.agentRef.ee.emit('entity-added', [entity])
36
- }
37
-
38
- clear () {
39
- this.#entities.clear()
40
- }
41
-
42
- setDefaultEntity (entity) {
43
- this.#entities.set(DEFAULT_KEY, entity)
44
- }
45
- }
@@ -1,165 +0,0 @@
1
- /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { DEFAULT_KEY, MAX_PAYLOAD_SIZE } from '../../common/constants/agent-constants'
6
- import { isContainerAgentTarget } from '../../common/util/target'
7
- /**
8
- * This layer allows multiple browser entity apps, or "target", to each have their own segregated storage instance.
9
- * The purpose is so the harvester can send data to different apps within the same agent. Each feature should have a manager if it needs this capability.
10
- */
11
- export class EventStoreManager {
12
- /**
13
- * @param {object} agentRef - reference to base agent class
14
- * @param {EventBuffer|EventAggregator} storageClass - the type of storage to use in this manager; 'EventBuffer' (1), 'EventAggregator' (2)
15
- * @param {string} [defaultEntityGuid] - the entity guid to use as the default storage instance; if not provided, a new one is created
16
- * @param {Object} featureAgg - the feature aggregate instance that initialized this manager
17
- */
18
- constructor (agentRef, storageClass, defaultEntityGuid, featureAgg) {
19
- this.agentRef = agentRef
20
- this.entityManager = agentRef.runtime.entityManager
21
- this.StorageClass = storageClass
22
- this.appStorageMap = new Map([[DEFAULT_KEY, new this.StorageClass(MAX_PAYLOAD_SIZE, featureAgg)]])
23
- this.featureAgg = featureAgg
24
- this.setEventStore(defaultEntityGuid)
25
- }
26
-
27
- /**
28
- * Always returns a storage instance. Creates one if one does not exist. If a lookup is not provided, uses the DEFAULT namespace
29
- * @param {string=} targetEntityGuid the lookup
30
- * @returns {*} ALWAYS returns a storage instance
31
- */
32
- #getEventStore (targetEntityGuid = DEFAULT_KEY) {
33
- if (!this.appStorageMap.has(targetEntityGuid)) this.setEventStore(targetEntityGuid)
34
- return this.appStorageMap.get(targetEntityGuid)
35
- }
36
-
37
- setEventStore (targetEntityGuid) {
38
- /** we should already have an event store for the default */
39
- if (!targetEntityGuid) return
40
- /** if the target is the container agent, SHARE the default storage -- otherwise create a new event store */
41
- const eventStorage = (isContainerAgentTarget(this.entityManager.get(targetEntityGuid), this.agentRef))
42
- ? this.appStorageMap.get(DEFAULT_KEY)
43
- : new this.StorageClass(MAX_PAYLOAD_SIZE, this.featureAgg)
44
- this.appStorageMap.set(targetEntityGuid, eventStorage)
45
- }
46
-
47
- /** IMPORTANT
48
- * This class must contain an union of all methods from all supported storage classes and conceptualize away the target app argument.
49
- */
50
-
51
- get length () {
52
- return this.#getEventStore().length
53
- }
54
-
55
- /**
56
- * Calls the merge method on the underlying storage class.
57
- * @param {*} matcher
58
- * @param {*} data
59
- * @param {*} targetEntityGuid
60
- * @returns {boolean} True if the merge was successful
61
- */
62
- merge (matcher, data, targetEntityGuid) {
63
- return this.#getEventStore(targetEntityGuid).merge(matcher, data)
64
- }
65
-
66
- /**
67
- * Calls the isEmpty method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
68
- * @param {object} optsIfPresent - exists if called during harvest interval, @see AggregateBase.makeHarvestPayload
69
- * @param {object} target - specific app's storage to check; if not provided, this method takes into account all apps recorded by this manager
70
- * @returns {boolean} True if the target's storage is empty, or target does not exist in map (defaults to all storages)
71
- */
72
- isEmpty (optsIfPresent, targetEntityGuid) {
73
- if (targetEntityGuid) return this.#getEventStore(targetEntityGuid).isEmpty(optsIfPresent)
74
-
75
- for (const eventStore of this.appStorageMap.values()) {
76
- if (!eventStore.isEmpty(optsIfPresent)) return false
77
- }
78
- return true
79
- }
80
-
81
- /**
82
- * Calls the add method on the underlying storage class.
83
- * @param {string} event - the event element to store
84
- * @param {object} targetEntityGuid - the entity guid lookup to store event under; if not provided, this method adds to the default
85
- * @returns {boolean} True if the event was successfully added
86
- */
87
- add (event, targetEntityGuid) {
88
- return this.#getEventStore(targetEntityGuid).add(event)
89
- }
90
-
91
- /** This is only used by the Metrics feature which has no need to add metric under a different app atm. */
92
- addMetric (type, name, params, value) {
93
- return this.#getEventStore().addMetric(type, name, params, value)
94
- }
95
-
96
- /**
97
- * Calls the get method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
98
- * @param {object=} opts - exists if called during harvest interval, @see AggregateBase.makeHarvestPayload
99
- * @param {object=} target - specific app to fetch; if not provided, this method fetches from all apps
100
- * @returns {Array} Objects of `data` labeled with their respective `target` app to be sent to
101
- */
102
- get (opts, targetEntityGuid) {
103
- if (targetEntityGuid) return [{ targetApp: this.entityManager.get(targetEntityGuid), data: this.#getEventStore(targetEntityGuid).get(opts) }]
104
- const allPayloads = []
105
- this.appStorageMap.forEach((eventStore, targetEntityGuid) => {
106
- // We shouldnt harvest unless we have a valid entity guid. It was ONLY stored under the default key temporarily
107
- // until a real key was returned in the RUM call. The real key SHARES the event store with the default key, and
108
- // should be the key that is honored to get the event store to ensure a valid connection was made.
109
- if (targetEntityGuid === DEFAULT_KEY) return
110
- const targetApp = this.entityManager.get(targetEntityGuid)
111
- if (targetApp) allPayloads.push({ targetApp, data: eventStore.get(opts) })
112
- })
113
- return allPayloads
114
- }
115
-
116
- /**
117
- * Calls the byteSize method on the underlying storage class
118
- * @param {*} targetEntityGuid
119
- * @returns
120
- */
121
- byteSize (targetEntityGuid) {
122
- return this.#getEventStore(targetEntityGuid).byteSize()
123
- }
124
-
125
- /**
126
- * Calls the wouldExceedMaxSize method on the underlying storage class
127
- * @param {*} incomingSize
128
- * @param {*} targetEntityGuid
129
- * @returns
130
- */
131
- wouldExceedMaxSize (incomingSize, targetEntityGuid) {
132
- return this.#getEventStore(targetEntityGuid).wouldExceedMaxSize(incomingSize)
133
- }
134
-
135
- /**
136
- * Calls the save method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
137
- * @param {*} optsIfPresent
138
- * @param {*} targetEntityGuid
139
- * @returns
140
- */
141
- save (optsIfPresent, targetEntityGuid) {
142
- if (targetEntityGuid) return this.#getEventStore(targetEntityGuid).save(optsIfPresent)
143
- this.appStorageMap.forEach((eventStore) => eventStore.save(optsIfPresent))
144
- }
145
-
146
- /**
147
- * Calls the clear method on the underlying storage class. If target is provided, runs just for the target, otherwise runs for all apps.
148
- * @param {*} optsIfPresent
149
- * @param {*} targetEntityGuid
150
- * @returns
151
- */
152
- clear (optsIfPresent, targetEntityGuid) {
153
- if (targetEntityGuid) return this.#getEventStore(targetEntityGuid).clear(optsIfPresent)
154
- this.appStorageMap.forEach((eventStore) => eventStore.clear(optsIfPresent))
155
- }
156
-
157
- // Unlike the methods above, the following will have a target as they are called by AggregateBase.postHarvestCleanup callback on harvest finish after getting & sending the data.
158
- reloadSave (optsIfPresent, targetEntityGuid) {
159
- return this.#getEventStore(targetEntityGuid).reloadSave(optsIfPresent)
160
- }
161
-
162
- clearSave (optsIfPresent, targetEntityGuid) {
163
- return this.#getEventStore(targetEntityGuid).clearSave(optsIfPresent)
164
- }
165
- }