Skip to content

Commit 3875708

Browse files
authored
chore: reduce size of partial types (#484)
1 parent 776915e commit 3875708

13 files changed

+112
-169
lines changed

src/orchestration/Orchestration.ts

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -52,57 +52,6 @@ export type Telemetry = string | (string | object)[];
5252

5353
export type PageIdFormat = 'PATH' | 'HASH' | 'PATH_AND_HASH';
5454

55-
export type PartialCookieAttributes = {
56-
unique?: boolean;
57-
domain?: string;
58-
path?: string;
59-
sameSite?: string;
60-
secure?: boolean;
61-
};
62-
63-
export type PartialConfig = {
64-
allowCookies?: boolean;
65-
batchLimit?: number;
66-
client?: string;
67-
clientBuilder?: ClientBuilder;
68-
cookieAttributes?: PartialCookieAttributes;
69-
disableAutoPageView?: boolean;
70-
dispatchInterval?: number;
71-
enableRumClient?: boolean;
72-
enableXRay?: boolean;
73-
endpoint?: string;
74-
eventCacheSize?: number;
75-
eventPluginsToLoad?: Plugin[];
76-
guestRoleArn?: string;
77-
identityPoolId?: string;
78-
pageIdFormat?: PageIdFormat;
79-
pagesToExclude?: RegExp[];
80-
pagesToInclude?: RegExp[];
81-
signing?: boolean;
82-
recordResourceUrl?: boolean;
83-
routeChangeComplete?: number;
84-
routeChangeTimeout?: number;
85-
sessionAttributes?: { [k: string]: string | number | boolean };
86-
sessionEventLimit?: number;
87-
sessionLengthSeconds?: number;
88-
sessionSampleRate?: number;
89-
/**
90-
* Application owners think about data collection in terms of the categories
91-
* of data being collected. For example, JavaScript errors, page load
92-
* performance, user journeys and user interactions are data collection
93-
* categories. However, there is not a 1-1 mapping between data collection
94-
* categories and plugins.
95-
*
96-
* This configuration option allows application owners to define the data
97-
* categories they want to collect without needing to understand and
98-
* instantiate each plugin themselves. The toolkit will instantiate the
99-
* plugins which map to the selected categories.
100-
*/
101-
telemetries?: Telemetry[];
102-
useBeacon?: boolean;
103-
userIdRetentionDays?: number;
104-
};
105-
10655
export const defaultCookieAttributes = (): CookieAttributes => {
10756
return {
10857
unique: false,
@@ -153,7 +102,9 @@ export type CookieAttributes = {
153102
secure: boolean;
154103
};
155104

156-
export type Config = {
105+
export type PartialCookieAttributes = Partial<CookieAttributes>;
106+
107+
export interface Config {
157108
allowCookies: boolean;
158109
batchLimit: number;
159110
client: string;
@@ -190,10 +141,27 @@ export type Config = {
190141
sessionEventLimit: number;
191142
sessionLengthSeconds: number;
192143
sessionSampleRate: number;
144+
/**
145+
* Application owners think about data collection in terms of the categories
146+
* of data being collected. For example, JavaScript errors, page load
147+
* performance, user journeys and user interactions are data collection
148+
* categories. However, there is not a 1-1 mapping between data collection
149+
* categories and plugins.
150+
*
151+
* This configuration option allows application owners to define the data
152+
* categories they want to collect without needing to understand and
153+
* instantiate each plugin themselves. The toolkit will instantiate the
154+
* plugins which map to the selected categories.
155+
*/
193156
telemetries: Telemetry[];
194157
useBeacon: boolean;
195158
userIdRetentionDays: number;
196-
};
159+
}
160+
161+
export interface PartialConfig
162+
extends Omit<Partial<Config>, 'cookieAttributes'> {
163+
cookieAttributes?: PartialCookieAttributes;
164+
}
197165

198166
/**
199167
* An orchestrator which (1) initializes cwr components and (2) provides the API for the application to interact

src/plugins/event-plugins/DomEventPlugin.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ export type TargetDomEvent = {
2626
element?: HTMLElement;
2727
};
2828

29-
export type PartialDomEventPluginConfig = {
30-
interactionId?: (event: Event) => string;
31-
enableMutationObserver?: boolean;
32-
events?: TargetDomEvent[];
33-
};
34-
3529
export type DomEventPluginConfig = {
3630
interactionId: (event: Event) => string;
3731
enableMutationObserver?: boolean;
@@ -62,7 +56,7 @@ export class DomEventPlugin<
6256
private config: DomEventPluginConfig;
6357
private observer: MutationObserver | undefined;
6458

65-
constructor(config?: PartialDomEventPluginConfig) {
59+
constructor(config?: Partial<DomEventPluginConfig>) {
6660
super(DOM_EVENT_PLUGIN_ID);
6761
this.eventListenerMap = new Map<
6862
TargetDomEvent,

src/plugins/event-plugins/FetchPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from '../../events/xray-trace-event';
66
import { MonkeyPatched } from '../MonkeyPatched';
77
import {
8-
PartialHttpPluginConfig,
98
defaultConfig,
109
epochTime,
1110
createXRayTraceEvent,
@@ -55,7 +54,7 @@ export const FETCH_PLUGIN_ID = 'fetch';
5554
export class FetchPlugin extends MonkeyPatched<Window, 'fetch'> {
5655
private readonly config: HttpPluginConfig;
5756

58-
constructor(config?: PartialHttpPluginConfig) {
57+
constructor(config?: Partial<HttpPluginConfig>) {
5958
super(FETCH_PLUGIN_ID);
6059
this.config = { ...defaultConfig, ...config };
6160
}

src/plugins/event-plugins/NavigationPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { InternalPlugin } from '../InternalPlugin';
22
import { NavigationEvent } from '../../events/navigation-event';
33
import { PERFORMANCE_NAVIGATION_EVENT_TYPE } from '../utils/constant';
44
import {
5-
PartialPerformancePluginConfig,
65
PerformancePluginConfig,
76
defaultPerformancePluginConfig
87
} from '../utils/performance-utils';
@@ -19,7 +18,7 @@ const LOAD = 'load';
1918
*/
2019
export class NavigationPlugin extends InternalPlugin {
2120
private config: PerformancePluginConfig;
22-
constructor(config?: PartialPerformancePluginConfig) {
21+
constructor(config?: Partial<PerformancePluginConfig>) {
2322
super(NAVIGATION_EVENT_PLUGIN_ID);
2423
this.config = { ...defaultPerformancePluginConfig, ...config };
2524
}

src/plugins/event-plugins/ResourcePlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ResourceEvent } from '../../events/resource-event';
44
import { PERFORMANCE_RESOURCE_EVENT_TYPE } from '../utils/constant';
55
import {
66
defaultPerformancePluginConfig,
7-
PartialPerformancePluginConfig,
87
PerformancePluginConfig
98
} from '../utils/performance-utils';
109

@@ -20,7 +19,7 @@ export class ResourcePlugin extends InternalPlugin {
2019
private resourceObserver: PerformanceObserver;
2120
private eventCount: number;
2221

23-
constructor(config?: PartialPerformancePluginConfig) {
22+
constructor(config?: Partial<PerformancePluginConfig>) {
2423
super(RESOURCE_EVENT_PLUGIN_ID);
2524
this.config = { ...defaultPerformancePluginConfig, ...config };
2625
this.eventCount = 0;

src/plugins/event-plugins/XhrPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { XRayTraceEvent } from '../../events/xray-trace-event';
22
import { HttpEvent } from '../../events/http-event';
33
import { MonkeyPatch, MonkeyPatched } from '../MonkeyPatched';
44
import {
5-
PartialHttpPluginConfig,
65
defaultConfig,
76
epochTime,
87
createXRayTraceEvent,
@@ -99,7 +98,7 @@ export class XhrPlugin extends MonkeyPatched<XMLHttpRequest, 'send' | 'open'> {
9998
private xhrMap: Map<XMLHttpRequest, XhrDetails>;
10099
private isSyntheticsUA: boolean;
101100

102-
constructor(config?: PartialHttpPluginConfig) {
101+
constructor(config?: Partial<HttpPluginConfig>) {
103102
super(XHR_PLUGIN_ID);
104103
this.config = { ...defaultConfig, ...config };
105104
this.xhrMap = new Map<XMLHttpRequest, XhrDetails>();

src/plugins/event-plugins/__tests__/FetchPlugin.integ.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Orchestration } from '../../../orchestration/Orchestration';
22
import { createAwsCredentials } from '../../../test-utils/test-utils';
3-
import { PartialHttpPluginConfig } from '../../utils/http-utils';
3+
import { HttpPluginConfig } from '../../utils/http-utils';
44
import { FetchPlugin } from '../FetchPlugin';
55

66
const mockFetch = jest.fn(
@@ -27,7 +27,7 @@ describe('FetchPlugin integ tests', () => {
2727

2828
test('dispatch requests are not recorded by the http plugin', async () => {
2929
// Init
30-
const config: PartialHttpPluginConfig = {
30+
const config: Partial<HttpPluginConfig> = {
3131
recordAllRequests: true
3232
};
3333

0 commit comments

Comments
 (0)