0

Creates a new screen

by
Published Oct 17, 2025

Creates a new screen

Script mezmo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Creates a new screen
4
 * Creates a new screen
5
 */
6
export async function main(auth: RT.Mezmo, body: Body) {
7
	const url = new URL(`https://api.mezmo.com/v1/config/screen`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Token ' + auth.apiKey
14
		},
15
		body: JSON.stringify(body)
16
	})
17
	if (!response.ok) {
18
		const text = await response.text()
19
		throw new Error(`${response.status} ${text}`)
20
	}
21
	return await response.json()
22
}
23

24
/* eslint-disable */
25
/**
26
 * This file was automatically generated by json-schema-to-typescript.
27
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
28
 * and run json-schema-to-typescript to regenerate this file.
29
 */
30

31
export interface Body {
32
	/**
33
	 * The identifier of this screen.
34
	 */
35
	id: string
36
	/**
37
	 * The account this screen belongs to.
38
	 */
39
	account?: string
40
	/**
41
	 * The title of this screen.
42
	 */
43
	title: string
44
	/**
45
	 * The width to height aspect ratio of this screen.
46
	 */
47
	ratio: '3:2' | '4:3' | '5:4' | '16:9' | '16:10' | '21:9'
48
	/**
49
	 * Whether the screen is rotated 90 degrees. Setting to true effectively swaps the width to height ratio.
50
	 */
51
	rotate90Degrees: boolean
52
	/**
53
	 * The background color to use when viewing the screen.
54
	 */
55
	background: 'dark' | 'light'
56
	/**
57
	 * A list of string categories the screen belongs to.
58
	 */
59
	categories?: string[]
60
	widgets?: {
61
		/**
62
		 * The id of this widget.
63
		 */
64
		id: string
65
		/**
66
		 * The type for this widget.
67
		 */
68
		type: 'count' | 'gauge' | 'table' | 'time-shifted-graph'
69
		/**
70
		 * The type of operation to perform on the field indicated in the “field” option. If the "field" option is set to all lines, only "count" can be used and other values may not display any results.
71
		 */
72
		operation:
73
			| 'count'
74
			| 'min'
75
			| 'max'
76
			| 'avg'
77
			| 'cum'
78
			| 'diff'
79
			| 'percentile-75'
80
			| 'percentile-85'
81
			| 'percentile-95'
82
			| 'percentile-99'
83
		/**
84
		 * How far into the past to graph this widget. Time shifted graph widgets must use time shifted durations e.g. "iso-weekly-compare". All other widgets must use regular durations e.g. "hourly".
85
		 */
86
		duration: (
87
			| ('hourly-compare' | 'daily-compare' | 'weekly-compare' | 'iso-weekly-compare')
88
			| (
89
					| 'hourly'
90
					| 'daily'
91
					| 'weekly'
92
					| 'iso-weekly'
93
					| '1m'
94
					| '30m'
95
					| '1h'
96
					| '2h'
97
					| '4h'
98
					| '8h'
99
					| '12h'
100
					| '1d'
101
					| '2d'
102
					| '4d'
103
					| '1w'
104
					| '2w'
105
			  )
106
		) &
107
			string
108
		/**
109
		 * Which field is being operated on and displayed in this widget. Use the special field “__ALL__LINES__” to perform the operation on all lines.
110
		 */
111
		field: string
112
		/**
113
		 * A special matching operation done on each value of the field. If the field is a string type then this value is used for equivalence matching. For number types, the supported operators are ["*", ">N", "<N", "=N", ">=N", "<=N"]. If the field is set the special type "__ALL_LINES__", this option is disabled.
114
		 */
115
		match?: string
116
		/**
117
		 * An extra query filter to run to match lines. Must be specified as a Mezmo line query e.g. “statusCode:>=400”.
118
		 */
119
		filter?: string
120
		/**
121
		 * A label that is displayed on the widget.
122
		 */
123
		label?: string
124
		/**
125
		 * The positional coordinates of a widget. Screens coordinates start at at the top left at [1, 1] and increase down and to the right of a screen.
126
		 */
127
		position: {
128
			/**
129
			 * The top left corner of the widget as an [x, y] coordinate.
130
			 */
131
			start: unknown[]
132
			/**
133
			 * The bottom right corner of the widget as an [x, y] coordinate.
134
			 */
135
			end: unknown[]
136
		}
137
		/**
138
		 * The order in which the rows of a table are sorted. This option is specific to the "table" widget.
139
		 */
140
		sort?: ('asc' | 'desc') & string
141
		/**
142
		 * How many rows to include for the table. This option is specific to the "table" widget.
143
		 */
144
		rows?: number & (3 | 5 | 10 | 15 | 20 | 25)
145
		/**
146
		 * Label to display on the left side of a table. This option is specific to the "table" widget.
147
		 */
148
		leftLabel?: unknown & string
149
		/**
150
		 * Label to display on the right side of a table. This option is specific to the "table" widget.
151
		 */
152
		rightLabel?: unknown & string
153
		/**
154
		 * Whether the rows of a table should also be displayed as a bar chart. This option is specific to the "table" widget.
155
		 */
156
		showBarChart?: boolean & {
157
			[k: string]: unknown
158
		}
159
		/**
160
		 * An additional field with which to group results. This option is specific to the "table" widget.
161
		 */
162
		groupBy?: {
163
			[k: string]: unknown
164
		} & string
165
		/**
166
		 * The minimum bounds of the gauge. This option is specific to the "gauge" widget.
167
		 */
168
		min?: number & {
169
			[k: string]: unknown
170
		}
171
		/**
172
		 * The maximum bounds of the gauge. This option is specific to the "gauge" widget.
173
		 */
174
		max?: number & {
175
			[k: string]: unknown
176
		}
177
		/**
178
		 * A label for the units of this widget. This option is specific to the "count" and "gauge" widgets.
179
		 */
180
		units?: unknown & string
181
		/**
182
		 * How to format the results of this widget. This option is specific to the "count", "gauge", and "table" widgets.
183
		 */
184
		format?: (
185
			| 'number-integer'
186
			| 'number-tenths'
187
			| 'number-ten-thousandths'
188
			| 'number-unformatted'
189
			| 'currency-prefix'
190
			| 'currency-postfix'
191
			| 'bytes-si'
192
			| 'percent-integer'
193
			| 'percent-thousandths'
194
			| 'time-HH:mm:ss'
195
		) &
196
			string
197
	}[]
198
}
199