ogi-addon 1.2.2 → 1.3.1
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.
- package/README.md +15 -7
- package/build/EventResponse.cjs +3 -3
- package/build/EventResponse.cjs.map +1 -1
- package/build/EventResponse.js +3 -3
- package/build/EventResponse.js.map +1 -1
- package/build/SearchEngine.cjs.map +1 -1
- package/build/SearchEngine.d.cts +1 -0
- package/build/SearchEngine.d.ts +1 -0
- package/build/config/Configuration.cjs +37 -22
- package/build/config/Configuration.cjs.map +1 -1
- package/build/config/Configuration.js +37 -22
- package/build/config/Configuration.js.map +1 -1
- package/build/config/ConfigurationBuilder.cjs +28 -19
- package/build/config/ConfigurationBuilder.cjs.map +1 -1
- package/build/config/ConfigurationBuilder.d.cts +2 -2
- package/build/config/ConfigurationBuilder.d.ts +2 -2
- package/build/config/ConfigurationBuilder.js +28 -19
- package/build/config/ConfigurationBuilder.js.map +1 -1
- package/build/main.cjs +181 -72
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +59 -17
- package/build/main.d.ts +59 -17
- package/build/main.js +181 -72
- package/build/main.js.map +1 -1
- package/package.json +3 -2
- package/schema.json +4 -1
- package/src/EventResponse.ts +22 -11
- package/src/SearchEngine.ts +2 -2
- package/src/config/Configuration.ts +53 -13
- package/src/config/ConfigurationBuilder.ts +79 -56
- package/src/main.ts +382 -139
- package/tsconfig.json +4 -10
- package/tsup.config.js +2 -2
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import z, { ZodError } from
|
|
1
|
+
import z, { ZodError } from 'zod';
|
|
2
2
|
|
|
3
3
|
export interface ConfigurationFile {
|
|
4
|
-
[key: string]: ConfigurationOption
|
|
4
|
+
[key: string]: ConfigurationOption;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
const configValidation = z.object({
|
|
8
8
|
name: z.string().min(1),
|
|
9
9
|
displayName: z.string().min(1),
|
|
10
10
|
description: z.string().min(1),
|
|
11
|
-
})
|
|
11
|
+
});
|
|
12
12
|
|
|
13
|
-
export function isStringOption(
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export function isStringOption(
|
|
14
|
+
option: ConfigurationOption
|
|
15
|
+
): option is StringOption {
|
|
16
|
+
return option.type === 'string';
|
|
17
|
+
}
|
|
16
18
|
|
|
17
|
-
export function isNumberOption(
|
|
19
|
+
export function isNumberOption(
|
|
20
|
+
option: ConfigurationOption
|
|
21
|
+
): option is NumberOption {
|
|
18
22
|
return option.type === 'number';
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
export function isBooleanOption(
|
|
25
|
+
export function isBooleanOption(
|
|
26
|
+
option: ConfigurationOption
|
|
27
|
+
): option is BooleanOption {
|
|
22
28
|
return option.type === 'boolean';
|
|
23
29
|
}
|
|
24
30
|
|
|
@@ -28,9 +34,11 @@ export class ConfigurationBuilder {
|
|
|
28
34
|
/**
|
|
29
35
|
* Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
30
36
|
* @param option { (option: NumberOption) => NumberOption }
|
|
31
|
-
* @returns
|
|
37
|
+
* @returns
|
|
32
38
|
*/
|
|
33
|
-
public addNumberOption(
|
|
39
|
+
public addNumberOption(
|
|
40
|
+
option: (option: NumberOption) => NumberOption
|
|
41
|
+
): ConfigurationBuilder {
|
|
34
42
|
let newOption = new NumberOption();
|
|
35
43
|
newOption = option(newOption);
|
|
36
44
|
this.options.push(newOption);
|
|
@@ -40,7 +48,7 @@ export class ConfigurationBuilder {
|
|
|
40
48
|
/**
|
|
41
49
|
* Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
42
50
|
* @param option { (option: StringOption) => StringOption }
|
|
43
|
-
|
|
51
|
+
*/
|
|
44
52
|
public addStringOption(option: (option: StringOption) => StringOption) {
|
|
45
53
|
let newOption = new StringOption();
|
|
46
54
|
newOption = option(newOption);
|
|
@@ -51,7 +59,7 @@ export class ConfigurationBuilder {
|
|
|
51
59
|
/**
|
|
52
60
|
* Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
53
61
|
* @param option { (option: BooleanOption) => BooleanOption }
|
|
54
|
-
|
|
62
|
+
*/
|
|
55
63
|
public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {
|
|
56
64
|
let newOption = new BooleanOption();
|
|
57
65
|
newOption = option(newOption);
|
|
@@ -61,18 +69,17 @@ export class ConfigurationBuilder {
|
|
|
61
69
|
|
|
62
70
|
public build(includeFunctions: boolean): ConfigurationFile {
|
|
63
71
|
let config: ConfigurationFile = {};
|
|
64
|
-
this.options.forEach(option => {
|
|
72
|
+
this.options.forEach((option) => {
|
|
65
73
|
// remove all functions from the option object
|
|
66
74
|
if (!includeFunctions) {
|
|
67
75
|
option = JSON.parse(JSON.stringify(option));
|
|
68
|
-
const optionData = configValidation.safeParse(option)
|
|
76
|
+
const optionData = configValidation.safeParse(option);
|
|
69
77
|
if (!optionData.success) {
|
|
70
|
-
throw new ZodError(optionData.error.errors)
|
|
78
|
+
throw new ZodError(optionData.error.errors);
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
config[option.name] = option;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
82
|
+
} else {
|
|
76
83
|
config[option.name] = option;
|
|
77
84
|
}
|
|
78
85
|
});
|
|
@@ -80,14 +87,14 @@ export class ConfigurationBuilder {
|
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
|
|
83
|
-
export type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'
|
|
90
|
+
export type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset';
|
|
84
91
|
export class ConfigurationOption {
|
|
85
92
|
public name: string = '';
|
|
86
93
|
public defaultValue: unknown = '';
|
|
87
94
|
public displayName: string = '';
|
|
88
95
|
public description: string = '';
|
|
89
|
-
public type: ConfigurationOptionType = 'unset'
|
|
90
|
-
|
|
96
|
+
public type: ConfigurationOptionType = 'unset';
|
|
97
|
+
|
|
91
98
|
/**
|
|
92
99
|
* Set the name of the option. **REQUIRED**
|
|
93
100
|
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
@@ -98,9 +105,9 @@ export class ConfigurationOption {
|
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
/**
|
|
101
|
-
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
102
|
-
* @param displayName {string} The display name of the option.
|
|
103
|
-
* @returns
|
|
108
|
+
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
109
|
+
* @param displayName {string} The display name of the option.
|
|
110
|
+
* @returns
|
|
104
111
|
*/
|
|
105
112
|
setDisplayName(displayName: string) {
|
|
106
113
|
this.displayName = displayName;
|
|
@@ -109,8 +116,8 @@ export class ConfigurationOption {
|
|
|
109
116
|
|
|
110
117
|
/**
|
|
111
118
|
* Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
|
|
112
|
-
* @param description {string} The description of the option.
|
|
113
|
-
* @returns
|
|
119
|
+
* @param description {string} The description of the option.
|
|
120
|
+
* @returns
|
|
114
121
|
*/
|
|
115
122
|
setDescription(description: string) {
|
|
116
123
|
this.description = description;
|
|
@@ -121,9 +128,9 @@ export class ConfigurationOption {
|
|
|
121
128
|
* Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.
|
|
122
129
|
* @param input {unknown} The input to validate
|
|
123
130
|
*/
|
|
124
|
-
validate(input: unknown): [
|
|
125
|
-
throw new Error('Validation code not implemented. Value: ' + input)
|
|
126
|
-
}
|
|
131
|
+
validate(input: unknown): [boolean, string] {
|
|
132
|
+
throw new Error('Validation code not implemented. Value: ' + input);
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
export class StringOption extends ConfigurationOption {
|
|
@@ -132,10 +139,10 @@ export class StringOption extends ConfigurationOption {
|
|
|
132
139
|
public maxTextLength: number = Number.MAX_SAFE_INTEGER;
|
|
133
140
|
public defaultValue: string = '';
|
|
134
141
|
public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';
|
|
135
|
-
public type: ConfigurationOptionType = 'string'
|
|
142
|
+
public type: ConfigurationOptionType = 'string';
|
|
136
143
|
|
|
137
144
|
/**
|
|
138
|
-
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
145
|
+
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
139
146
|
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
140
147
|
*/
|
|
141
148
|
setAllowedValues(allowedValues: string[]): this {
|
|
@@ -153,8 +160,8 @@ export class StringOption extends ConfigurationOption {
|
|
|
153
160
|
}
|
|
154
161
|
|
|
155
162
|
/**
|
|
156
|
-
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
157
|
-
* @param minTextLength {number} The minimum text length for the string.
|
|
163
|
+
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
164
|
+
* @param minTextLength {number} The minimum text length for the string.
|
|
158
165
|
*/
|
|
159
166
|
setMinTextLength(minTextLength: number): this {
|
|
160
167
|
this.minTextLength = minTextLength;
|
|
@@ -162,7 +169,7 @@ export class StringOption extends ConfigurationOption {
|
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
/**
|
|
165
|
-
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
172
|
+
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
166
173
|
* @param maxTextLength {number} The maximum text length for the string.
|
|
167
174
|
*/
|
|
168
175
|
setMaxTextLength(maxTextLength: number): this {
|
|
@@ -171,25 +178,40 @@ export class StringOption extends ConfigurationOption {
|
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
/**
|
|
174
|
-
* Set the input type for the string. This will change how the client renders the input.
|
|
175
|
-
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
181
|
+
* Set the input type for the string. This will change how the client renders the input.
|
|
182
|
+
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
176
183
|
*/
|
|
177
184
|
setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {
|
|
178
185
|
this.inputType = inputType;
|
|
179
186
|
return this;
|
|
180
187
|
}
|
|
181
188
|
|
|
182
|
-
override validate(input: unknown): [
|
|
189
|
+
override validate(input: unknown): [boolean, string] {
|
|
183
190
|
if (typeof input !== 'string') {
|
|
184
|
-
return [
|
|
191
|
+
return [false, 'Input is not a string'];
|
|
185
192
|
}
|
|
186
193
|
if (this.allowedValues.length === 0 && input.length !== 0)
|
|
187
|
-
return [
|
|
188
|
-
if (
|
|
189
|
-
|
|
194
|
+
return [true, ''];
|
|
195
|
+
if (
|
|
196
|
+
input.length < this.minTextLength ||
|
|
197
|
+
input.length > this.maxTextLength
|
|
198
|
+
) {
|
|
199
|
+
return [
|
|
200
|
+
false,
|
|
201
|
+
'Input is not within the text length ' +
|
|
202
|
+
this.minTextLength +
|
|
203
|
+
' and ' +
|
|
204
|
+
this.maxTextLength +
|
|
205
|
+
' characters (currently ' +
|
|
206
|
+
input.length +
|
|
207
|
+
' characters)',
|
|
208
|
+
];
|
|
190
209
|
}
|
|
191
210
|
|
|
192
|
-
return [
|
|
211
|
+
return [
|
|
212
|
+
this.allowedValues.includes(input),
|
|
213
|
+
'Input is not an allowed value',
|
|
214
|
+
];
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
217
|
|
|
@@ -197,7 +219,7 @@ export class NumberOption extends ConfigurationOption {
|
|
|
197
219
|
public min: number = 0;
|
|
198
220
|
public max: number = Number.MAX_SAFE_INTEGER;
|
|
199
221
|
public defaultValue: number = 0;
|
|
200
|
-
public type: ConfigurationOptionType = 'number'
|
|
222
|
+
public type: ConfigurationOptionType = 'number';
|
|
201
223
|
public inputType: 'range' | 'number' = 'number';
|
|
202
224
|
|
|
203
225
|
/**
|
|
@@ -210,8 +232,8 @@ export class NumberOption extends ConfigurationOption {
|
|
|
210
232
|
}
|
|
211
233
|
|
|
212
234
|
/**
|
|
213
|
-
* Set the input type for the number. This will change how the client renders the input.
|
|
214
|
-
* @param type {'range' | 'number'} The input type for the number.
|
|
235
|
+
* Set the input type for the number. This will change how the client renders the input.
|
|
236
|
+
* @param type {'range' | 'number'} The input type for the number.
|
|
215
237
|
*/
|
|
216
238
|
setInputType(type: 'range' | 'number'): this {
|
|
217
239
|
this.inputType = type;
|
|
@@ -224,7 +246,7 @@ export class NumberOption extends ConfigurationOption {
|
|
|
224
246
|
*/
|
|
225
247
|
setMax(max: number): this {
|
|
226
248
|
this.max = max;
|
|
227
|
-
return this
|
|
249
|
+
return this;
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
/**
|
|
@@ -236,20 +258,22 @@ export class NumberOption extends ConfigurationOption {
|
|
|
236
258
|
return this;
|
|
237
259
|
}
|
|
238
260
|
|
|
239
|
-
override validate(input: unknown): [
|
|
261
|
+
override validate(input: unknown): [boolean, string] {
|
|
240
262
|
if (isNaN(Number(input))) {
|
|
241
|
-
return [
|
|
263
|
+
return [false, 'Input is not a number'];
|
|
242
264
|
}
|
|
243
265
|
if (Number(input) < this.min || Number(input) > this.max) {
|
|
244
|
-
return [
|
|
266
|
+
return [
|
|
267
|
+
false,
|
|
268
|
+
'Input is not within the range of ' + this.min + ' and ' + this.max,
|
|
269
|
+
];
|
|
245
270
|
}
|
|
246
|
-
return [
|
|
271
|
+
return [true, ''];
|
|
247
272
|
}
|
|
248
|
-
|
|
249
273
|
}
|
|
250
274
|
|
|
251
275
|
export class BooleanOption extends ConfigurationOption {
|
|
252
|
-
public type: ConfigurationOptionType = 'boolean'
|
|
276
|
+
public type: ConfigurationOptionType = 'boolean';
|
|
253
277
|
public defaultValue: boolean = false;
|
|
254
278
|
|
|
255
279
|
/**
|
|
@@ -261,11 +285,10 @@ export class BooleanOption extends ConfigurationOption {
|
|
|
261
285
|
return this;
|
|
262
286
|
}
|
|
263
287
|
|
|
264
|
-
override validate(input: unknown): [
|
|
288
|
+
override validate(input: unknown): [boolean, string] {
|
|
265
289
|
if (typeof input !== 'boolean') {
|
|
266
|
-
return [
|
|
290
|
+
return [false, 'Input is not a boolean'];
|
|
267
291
|
}
|
|
268
|
-
return [
|
|
292
|
+
return [true, ''];
|
|
269
293
|
}
|
|
270
|
-
|
|
271
|
-
}
|
|
294
|
+
}
|