Skip to content

Commit 33fd221

Browse files
committed
make types more strict
1 parent 5a9947d commit 33fd221

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

packages/node/src/client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,20 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
164164
const options = this.getOptions();
165165
const { release, environment, tunnel } = options;
166166

167-
const id = checkIn.checkInId || uuid4();
167+
const id = checkIn.status === 'in_progress' ? uuid4() : checkIn.checkInId;
168168

169169
const serializedCheckIn: SerializedCheckIn = {
170170
check_in_id: id,
171171
monitor_slug: checkIn.monitorSlug,
172172
status: checkIn.status,
173-
duration: checkIn.duration,
174173
release,
175174
environment,
176175
};
177176

177+
if (checkIn.status !== 'in_progress') {
178+
serializedCheckIn.duration = checkIn.duration;
179+
}
180+
178181
if (monitorConfig) {
179182
serializedCheckIn.monitor_config = {
180183
schedule: monitorConfig.schedule,

packages/node/test/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ describe('NodeClient', () => {
361361
// @ts-ignore accessing private method
362362
const sendEnvelopeSpy = jest.spyOn(client, '_sendEnvelope');
363363

364-
client.captureCheckIn({ monitorSlug: 'foo', status: 'ok', duration: 1222 });
364+
client.captureCheckIn({ monitorSlug: 'foo', status: 'in_progress' });
365365

366366
expect(sendEnvelopeSpy).toHaveBeenCalledTimes(0);
367367
});

packages/types/src/checkin.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,25 @@ export interface SerializedCheckIn {
3838
};
3939
}
4040

41-
export type CheckIn = {
41+
interface InProgressCheckIn {
42+
// The distinct slug of the monitor.
43+
monitorSlug: SerializedCheckIn['monitor_slug'];
44+
// The status of the check-in.
45+
status: 'in_progress';
46+
}
47+
48+
interface FinishedCheckIn {
4249
// The distinct slug of the monitor.
4350
monitorSlug: SerializedCheckIn['monitor_slug'];
4451
// Check-In ID (unique and client generated).
45-
checkInId?: SerializedCheckIn['check_in_id'];
52+
checkInId: SerializedCheckIn['check_in_id'];
4653
// The status of the check-in.
47-
status: SerializedCheckIn['status'];
54+
status: 'ok' | 'error';
4855
// The duration of the check-in in seconds. Will only take effect if the status is ok or error.
4956
duration?: SerializedCheckIn['duration'];
50-
};
57+
}
58+
59+
export type CheckIn = InProgressCheckIn | FinishedCheckIn;
5160

5261
type SerializedMonitorConfig = NonNullable<SerializedCheckIn['monitor_config']>;
5362

0 commit comments

Comments
 (0)