Skip to content

Commit 44fd594

Browse files
committed
Provide better hinting around event type
1 parent bda7aa8 commit 44fd594

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

packages/core/src/EventBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ExceptionlessClient } from "./ExceptionlessClient.js";
2-
import { Event, KnownEventDataKeys } from "./models/Event.js";
2+
import { Event, EventType, KnownEventDataKeys } from "./models/Event.js";
33
import { ManualStackingInfo } from "./models/data/ManualStackingInfo.js";
44
import { UserInfo } from "./models/data/UserInfo.js";
55
import { EventContext } from "./models/EventContext.js";
@@ -19,7 +19,7 @@ export class EventBuilder {
1919
this.context = context || new EventContext();
2020
}
2121

22-
public setType(type: string): EventBuilder {
22+
public setType(type: EventType): EventBuilder {
2323
if (type) {
2424
this.target.type = type;
2525
}

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type { ILog } from "./logging/ILog.js";
88
export { ConsoleLog } from "./logging/ConsoleLog.js";
99
export { NullLog } from "./logging/NullLog.js";
1010

11-
export type { Event, IEventData } from "./models/Event.js";
11+
export type { Event, EventType, IEventData } from "./models/Event.js";
1212
export { KnownEventDataKeys } from "./models/Event.js";
1313
export type { EnvironmentInfo } from "./models/data/EnvironmentInfo.js";
1414
export type { ManualStackingInfo } from "./models/data/ManualStackingInfo.js";

packages/core/src/models/Event.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { UserInfo } from "./data/UserInfo.js";
55
import { UserDescription } from "./data/UserDescription.js";
66
import { ManualStackingInfo } from "./data/ManualStackingInfo.js";
77

8+
export type EventType = "error" | "usage" | "log" | "404" | "session" | string;
9+
810
export interface Event {
911
/** The event type (ie. error, log message, feature usage). */
10-
type?: string;
12+
type?: EventType;
1113
/** The event source (ie. machine name, log name, feature name). */
1214
source?: string;
1315
/** The date that the event occurred on. */

packages/core/test/plugins/default/EventExclusionPlugin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, test } from "@jest/globals";
22
import { expect } from "expect";
33

44
import { ExceptionlessClient } from "../../../src/ExceptionlessClient.js";
5-
import { Event, KnownEventDataKeys } from "../../../src/models/Event.js";
5+
import { Event, EventType, KnownEventDataKeys } from "../../../src/models/Event.js";
66
import { InnerErrorInfo } from "../../../src/models/data/ErrorInfo.js";
77
import { EventExclusionPlugin } from "../../../src/plugins/default/EventExclusionPlugin.js";
88
import { EventPluginContext } from "../../../src/plugins/EventPluginContext.js";
@@ -142,7 +142,7 @@ describe("EventExclusionPlugin", () => {
142142
});
143143

144144
describe("should exclude source type", () => {
145-
const run = async (type: string | null | undefined, source: string | undefined, settingKey: string | null | undefined, settingValue: string | null | undefined): Promise<boolean> => {
145+
const run = async (type: EventType | null | undefined, source: string | undefined, settingKey: string | null | undefined, settingValue: string | null | undefined): Promise<boolean> => {
146146
const client = new ExceptionlessClient();
147147

148148
if (typeof settingKey === "string") {

packages/core/test/submission/TestSubmissionClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("TestSubmissionClient", () => {
2020
const apiFetchMock = jest.fn<(url: string, options: FetchOptions) => Promise<Response<undefined>>>()
2121
.mockReturnValueOnce(Promise.resolve(new Response(202, "", NaN, NaN, undefined)));
2222

23-
const events = [{ type: "log", message: "From js client", reference_id: "123454321" }];
23+
const events: Event[] = [{ type: "log", message: "From js client", reference_id: "123454321" }];
2424
const client = new TestSubmissionClient(config, apiFetchMock);
2525
await client.submitEvents(events);
2626
expect(apiFetchMock).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)