ogi-addon 1.0.0 → 1.1.0

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.
@@ -16,18 +16,31 @@ function isBooleanOption(option) {
16
16
  }
17
17
  var ConfigurationBuilder = class {
18
18
  options = [];
19
+ /**
20
+ * 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.
21
+ * @param option { (option: NumberOption) => NumberOption }
22
+ * @returns
23
+ */
19
24
  addNumberOption(option) {
20
25
  let newOption = new NumberOption();
21
26
  newOption = option(newOption);
22
27
  this.options.push(newOption);
23
28
  return this;
24
29
  }
30
+ /**
31
+ * 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.
32
+ * @param option { (option: StringOption) => StringOption }
33
+ */
25
34
  addStringOption(option) {
26
35
  let newOption = new StringOption();
27
36
  newOption = option(newOption);
28
37
  this.options.push(newOption);
29
38
  return this;
30
39
  }
40
+ /**
41
+ * 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.
42
+ * @param option { (option: BooleanOption) => BooleanOption }
43
+ */
31
44
  addBooleanOption(option) {
32
45
  let newOption = new BooleanOption();
33
46
  newOption = option(newOption);
@@ -57,18 +70,36 @@ var ConfigurationOption = class {
57
70
  displayName = "";
58
71
  description = "";
59
72
  type = "unset";
73
+ /**
74
+ * Set the name of the option. **REQUIRED**
75
+ * @param name {string} The name of the option. This is used to reference the option in the configuration file.
76
+ */
60
77
  setName(name) {
61
78
  this.name = name;
62
79
  return this;
63
80
  }
81
+ /**
82
+ * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
83
+ * @param displayName {string} The display name of the option.
84
+ * @returns
85
+ */
64
86
  setDisplayName(displayName) {
65
87
  this.displayName = displayName;
66
88
  return this;
67
89
  }
90
+ /**
91
+ * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
92
+ * @param description {string} The description of the option.
93
+ * @returns
94
+ */
68
95
  setDescription(description) {
69
96
  this.description = description;
70
97
  return this;
71
98
  }
99
+ /**
100
+ * 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.
101
+ * @param input {unknown} The input to validate
102
+ */
72
103
  validate(input) {
73
104
  throw new Error("Validation code not implemented. Value: " + input);
74
105
  }
@@ -80,22 +111,42 @@ var StringOption = class extends ConfigurationOption {
80
111
  defaultValue = "";
81
112
  inputType = "text";
82
113
  type = "string";
114
+ /**
115
+ * 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.
116
+ * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
117
+ */
83
118
  setAllowedValues(allowedValues) {
84
119
  this.allowedValues = allowedValues;
85
120
  return this;
86
121
  }
122
+ /**
123
+ * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
124
+ * @param defaultValue {string} The default value for the string.
125
+ */
87
126
  setDefaultValue(defaultValue) {
88
127
  this.defaultValue = defaultValue;
89
128
  return this;
90
129
  }
130
+ /**
131
+ * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
132
+ * @param minTextLength {number} The minimum text length for the string.
133
+ */
91
134
  setMinTextLength(minTextLength) {
92
135
  this.minTextLength = minTextLength;
93
136
  return this;
94
137
  }
138
+ /**
139
+ * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
140
+ * @param maxTextLength {number} The maximum text length for the string.
141
+ */
95
142
  setMaxTextLength(maxTextLength) {
96
143
  this.maxTextLength = maxTextLength;
97
144
  return this;
98
145
  }
146
+ /**
147
+ * Set the input type for the string. This will change how the client renders the input.
148
+ * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
149
+ */
99
150
  setInputType(inputType) {
100
151
  this.inputType = inputType;
101
152
  return this;
@@ -118,18 +169,34 @@ var NumberOption = class extends ConfigurationOption {
118
169
  defaultValue = 0;
119
170
  type = "number";
120
171
  inputType = "number";
172
+ /**
173
+ * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
174
+ * @param min {number} The minimum value for the number.
175
+ */
121
176
  setMin(min) {
122
177
  this.min = min;
123
178
  return this;
124
179
  }
180
+ /**
181
+ * Set the input type for the number. This will change how the client renders the input.
182
+ * @param type {'range' | 'number'} The input type for the number.
183
+ */
125
184
  setInputType(type) {
126
185
  this.inputType = type;
127
186
  return this;
128
187
  }
188
+ /**
189
+ * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
190
+ * @param max {number} The maximum value for the number.
191
+ */
129
192
  setMax(max) {
130
193
  this.max = max;
131
194
  return this;
132
195
  }
196
+ /**
197
+ * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
198
+ * @param defaultValue {number} The default value for the number.
199
+ */
133
200
  setDefaultValue(defaultValue) {
134
201
  this.defaultValue = defaultValue;
135
202
  return this;
@@ -147,6 +214,10 @@ var NumberOption = class extends ConfigurationOption {
147
214
  var BooleanOption = class extends ConfigurationOption {
148
215
  type = "boolean";
149
216
  defaultValue = false;
217
+ /**
218
+ * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
219
+ * @param defaultValue {boolean} The default value for the boolean.
220
+ */
150
221
  setDefaultValue(defaultValue) {
151
222
  this.defaultValue = defaultValue;
152
223
  return this;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\r\n\r\nexport interface ConfigurationFile {\r\n [key: string]: ConfigurationOption\r\n}\r\n\r\nconst configValidation = z.object({\r\n name: z.string().min(1),\r\n displayName: z.string().min(1),\r\n description: z.string().min(1),\r\n})\r\n\r\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\r\n return option.type === 'string';\r\n }\r\n\r\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\r\n return option.type === 'number';\r\n}\r\n\r\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\r\n return option.type === 'boolean';\r\n}\r\n\r\nexport class ConfigurationBuilder {\r\n private options: ConfigurationOption[] = [];\r\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\r\n let newOption = new NumberOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addStringOption(option: (option: StringOption) => StringOption) {\r\n let newOption = new StringOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\r\n let newOption = new BooleanOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public build(includeFunctions: boolean): ConfigurationFile {\r\n let config: ConfigurationFile = {};\r\n this.options.forEach(option => {\r\n // remove all functions from the option object\r\n if (!includeFunctions) {\r\n option = JSON.parse(JSON.stringify(option));\r\n const optionData = configValidation.safeParse(option)\r\n if (!optionData.success) {\r\n throw new ZodError(optionData.error.errors)\r\n }\r\n\r\n config[option.name] = option;\r\n }\r\n else {\r\n config[option.name] = option;\r\n }\r\n });\r\n return config;\r\n }\r\n}\r\n\r\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\r\nexport class ConfigurationOption {\r\n public name: string = '';\r\n public defaultValue: unknown = '';\r\n public displayName: string = '';\r\n public description: string = '';\r\n public type: ConfigurationOptionType = 'unset'\r\n \r\n setName(name: string) {\r\n this.name = name;\r\n return this;\r\n }\r\n\r\n setDisplayName(displayName: string) {\r\n this.displayName = displayName;\r\n return this;\r\n }\r\n\r\n setDescription(description: string) {\r\n this.description = description;\r\n return this;\r\n }\r\n\r\n\r\n validate(input: unknown): [ boolean, string ] {\r\n throw new Error('Validation code not implemented. Value: ' + input)\r\n };\r\n}\r\n\r\nexport class StringOption extends ConfigurationOption {\r\n public allowedValues: string[] = [];\r\n public minTextLength: number = 0;\r\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: string = '';\r\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\r\n public type: ConfigurationOptionType = 'string'\r\n\r\n setAllowedValues(allowedValues: string[]): this {\r\n this.allowedValues = allowedValues;\r\n return this;\r\n }\r\n\r\n setDefaultValue(defaultValue: string): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n setMinTextLength(minTextLength: number): this {\r\n this.minTextLength = minTextLength;\r\n return this;\r\n }\r\n\r\n setMaxTextLength(maxTextLength: number): this {\r\n this.maxTextLength = maxTextLength;\r\n return this;\r\n }\r\n\r\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\r\n this.inputType = inputType;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'string') {\r\n return [ false, 'Input is not a string' ];\r\n }\r\n if (this.allowedValues.length === 0 && input.length !== 0)\r\n return [ true, '' ];\r\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\r\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\r\n }\r\n\r\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\r\n }\r\n}\r\n\r\nexport class NumberOption extends ConfigurationOption {\r\n public min: number = 0;\r\n public max: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: number = 0;\r\n public type: ConfigurationOptionType = 'number'\r\n public inputType: 'range' | 'number' = 'number';\r\n setMin(min: number): this {\r\n this.min = min;\r\n return this;\r\n }\r\n\r\n setInputType(type: 'range' | 'number'): this {\r\n this.inputType = type;\r\n return this;\r\n }\r\n\r\n setMax(max: number): this {\r\n this.max = max;\r\n return this\r\n }\r\n\r\n setDefaultValue(defaultValue: number): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (isNaN(Number(input))) {\r\n return [ false, 'Input is not a number' ];\r\n }\r\n if (Number(input) < this.min || Number(input) > this.max) {\r\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}\r\n\r\nexport class BooleanOption extends ConfigurationOption {\r\n public type: ConfigurationOptionType = 'boolean'\r\n public defaultValue: boolean = false;\r\n\r\n setDefaultValue(defaultValue: boolean): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'boolean') {\r\n return [ false, 'Input is not a boolean' ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}"],"mappings":";AAAA,OAAO,KAAK,gBAAgB;AAM5B,IAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAEM,SAAS,eAAe,QAAqD;AAChF,SAAO,OAAO,SAAS;AACzB;AAEK,SAAS,eAAe,QAAqD;AAClF,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,gBAAgB,QAAsD;AACpF,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAAA,EACnC,gBAAgB,QAAsE;AAC3F,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,gBAAgB,QAAgD;AACrE,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,iBAAiB,QAAkD;AACxE,QAAI,YAAY,IAAI,cAAc;AAClC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,MAAM,kBAA8C;AACzD,QAAI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oB;AAAA,EAC9C,OAAgC;AAAA,EAChC,eAAwB;AAAA,EAE/B,gBAAgB,cAA6B;AAC3C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,OAAO,UAAU,WAAW;AAC9B,aAAO,CAAE,OAAO,wBAAyB;AAAA,IAC3C;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;","names":[]}
1
+ {"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\r\n\r\nexport interface ConfigurationFile {\r\n [key: string]: ConfigurationOption\r\n}\r\n\r\nconst configValidation = z.object({\r\n name: z.string().min(1),\r\n displayName: z.string().min(1),\r\n description: z.string().min(1),\r\n})\r\n\r\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\r\n return option.type === 'string';\r\n }\r\n\r\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\r\n return option.type === 'number';\r\n}\r\n\r\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\r\n return option.type === 'boolean';\r\n}\r\n\r\nexport class ConfigurationBuilder {\r\n private options: ConfigurationOption[] = [];\r\n\r\n /**\r\n * 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.\r\n * @param option { (option: NumberOption) => NumberOption }\r\n * @returns \r\n */\r\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\r\n let newOption = new NumberOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n /**\r\n * 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.\r\n * @param option { (option: StringOption) => StringOption }\r\n */\r\n public addStringOption(option: (option: StringOption) => StringOption) {\r\n let newOption = new StringOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n /**\r\n * 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.\r\n * @param option { (option: BooleanOption) => BooleanOption }\r\n */\r\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\r\n let newOption = new BooleanOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public build(includeFunctions: boolean): ConfigurationFile {\r\n let config: ConfigurationFile = {};\r\n this.options.forEach(option => {\r\n // remove all functions from the option object\r\n if (!includeFunctions) {\r\n option = JSON.parse(JSON.stringify(option));\r\n const optionData = configValidation.safeParse(option)\r\n if (!optionData.success) {\r\n throw new ZodError(optionData.error.errors)\r\n }\r\n\r\n config[option.name] = option;\r\n }\r\n else {\r\n config[option.name] = option;\r\n }\r\n });\r\n return config;\r\n }\r\n}\r\n\r\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\r\nexport class ConfigurationOption {\r\n public name: string = '';\r\n public defaultValue: unknown = '';\r\n public displayName: string = '';\r\n public description: string = '';\r\n public type: ConfigurationOptionType = 'unset'\r\n \r\n /**\r\n * Set the name of the option. **REQUIRED**\r\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\r\n */\r\n setName(name: string) {\r\n this.name = name;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED** \r\n * @param displayName {string} The display name of the option. \r\n * @returns \r\n */\r\n setDisplayName(displayName: string) {\r\n this.displayName = displayName;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\r\n * @param description {string} The description of the option. \r\n * @returns \r\n */\r\n setDescription(description: string) {\r\n this.description = description;\r\n return this;\r\n }\r\n\r\n /**\r\n * 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.\r\n * @param input {unknown} The input to validate\r\n */\r\n validate(input: unknown): [ boolean, string ] {\r\n throw new Error('Validation code not implemented. Value: ' + input)\r\n };\r\n}\r\n\r\nexport class StringOption extends ConfigurationOption {\r\n public allowedValues: string[] = [];\r\n public minTextLength: number = 0;\r\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: string = '';\r\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\r\n public type: ConfigurationOptionType = 'string'\r\n\r\n /**\r\n * 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. \r\n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\r\n */\r\n setAllowedValues(allowedValues: string[]): this {\r\n this.allowedValues = allowedValues;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {string} The default value for the string.\r\n */\r\n setDefaultValue(defaultValue: string): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail. \r\n * @param minTextLength {number} The minimum text length for the string. \r\n */\r\n setMinTextLength(minTextLength: number): this {\r\n this.minTextLength = minTextLength;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail. \r\n * @param maxTextLength {number} The maximum text length for the string.\r\n */\r\n setMaxTextLength(maxTextLength: number): this {\r\n this.maxTextLength = maxTextLength;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the input type for the string. This will change how the client renders the input. \r\n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string. \r\n */\r\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\r\n this.inputType = inputType;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'string') {\r\n return [ false, 'Input is not a string' ];\r\n }\r\n if (this.allowedValues.length === 0 && input.length !== 0)\r\n return [ true, '' ];\r\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\r\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\r\n }\r\n\r\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\r\n }\r\n}\r\n\r\nexport class NumberOption extends ConfigurationOption {\r\n public min: number = 0;\r\n public max: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: number = 0;\r\n public type: ConfigurationOptionType = 'number'\r\n public inputType: 'range' | 'number' = 'number';\r\n\r\n /**\r\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\r\n * @param min {number} The minimum value for the number.\r\n */\r\n setMin(min: number): this {\r\n this.min = min;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the input type for the number. This will change how the client renders the input. \r\n * @param type {'range' | 'number'} The input type for the number. \r\n */\r\n setInputType(type: 'range' | 'number'): this {\r\n this.inputType = type;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\r\n * @param max {number} The maximum value for the number.\r\n */\r\n setMax(max: number): this {\r\n this.max = max;\r\n return this\r\n }\r\n\r\n /**\r\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {number} The default value for the number.\r\n */\r\n setDefaultValue(defaultValue: number): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (isNaN(Number(input))) {\r\n return [ false, 'Input is not a number' ];\r\n }\r\n if (Number(input) < this.min || Number(input) > this.max) {\r\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}\r\n\r\nexport class BooleanOption extends ConfigurationOption {\r\n public type: ConfigurationOptionType = 'boolean'\r\n public defaultValue: boolean = false;\r\n\r\n /**\r\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {boolean} The default value for the boolean.\r\n */\r\n setDefaultValue(defaultValue: boolean): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'boolean') {\r\n return [ false, 'Input is not a boolean' ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}"],"mappings":";AAAA,OAAO,KAAK,gBAAgB;AAM5B,IAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAEM,SAAS,eAAe,QAAqD;AAChF,SAAO,OAAO,SAAS;AACzB;AAEK,SAAS,eAAe,QAAqD;AAClF,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,gBAAgB,QAAsD;AACpF,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,gBAAgB,QAAsE;AAC3F,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,gBAAgB,QAAgD;AACrE,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,iBAAiB,QAAkD;AACxE,QAAI,YAAY,IAAI,cAAc;AAClC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,MAAM,kBAA8C;AACzD,QAAI,SAA4B,CAAC;AACjC,SAAK,QAAQ,QAAQ,YAAU;AAE7B,UAAI,CAAC,kBAAkB;AACrB,iBAAS,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC;AAC1C,cA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AK,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK;AACxD,aAAO,CAAE,OAAO,sCAAsC,KAAK,MAAM,UAAU,KAAK,GAAI;AAAA,IACtF;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;AAEO,IAAM,gBAAN,cAA4B,oBAAoB;AAAA,EAC9C,OAAgC;AAAA,EAChC,eAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/B,gBAAgB,cAA6B;AAC3C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,OAAO,UAAU,WAAW;AAC9B,aAAO,CAAE,OAAO,wBAAyB;AAAA,IAC3C;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;","names":[]}
package/build/main.cjs CHANGED
@@ -33,7 +33,8 @@ __export(main_exports, {
33
33
  Configuration: () => Configuration,
34
34
  ConfigurationBuilder: () => ConfigurationBuilder,
35
35
  EventResponse: () => EventResponse,
36
- default: () => OGIAddon
36
+ default: () => OGIAddon,
37
+ version: () => version
37
38
  });
38
39
  module.exports = __toCommonJS(main_exports);
39
40
  var import_ws = __toESM(require("ws"), 1);
@@ -48,18 +49,31 @@ var configValidation = import_zod.default.object({
48
49
  });
49
50
  var ConfigurationBuilder = class {
50
51
  options = [];
52
+ /**
53
+ * 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.
54
+ * @param option { (option: NumberOption) => NumberOption }
55
+ * @returns
56
+ */
51
57
  addNumberOption(option) {
52
58
  let newOption = new NumberOption();
53
59
  newOption = option(newOption);
54
60
  this.options.push(newOption);
55
61
  return this;
56
62
  }
63
+ /**
64
+ * 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.
65
+ * @param option { (option: StringOption) => StringOption }
66
+ */
57
67
  addStringOption(option) {
58
68
  let newOption = new StringOption();
59
69
  newOption = option(newOption);
60
70
  this.options.push(newOption);
61
71
  return this;
62
72
  }
73
+ /**
74
+ * 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.
75
+ * @param option { (option: BooleanOption) => BooleanOption }
76
+ */
63
77
  addBooleanOption(option) {
64
78
  let newOption = new BooleanOption();
65
79
  newOption = option(newOption);
@@ -89,18 +103,36 @@ var ConfigurationOption = class {
89
103
  displayName = "";
90
104
  description = "";
91
105
  type = "unset";
106
+ /**
107
+ * Set the name of the option. **REQUIRED**
108
+ * @param name {string} The name of the option. This is used to reference the option in the configuration file.
109
+ */
92
110
  setName(name) {
93
111
  this.name = name;
94
112
  return this;
95
113
  }
114
+ /**
115
+ * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
116
+ * @param displayName {string} The display name of the option.
117
+ * @returns
118
+ */
96
119
  setDisplayName(displayName) {
97
120
  this.displayName = displayName;
98
121
  return this;
99
122
  }
123
+ /**
124
+ * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
125
+ * @param description {string} The description of the option.
126
+ * @returns
127
+ */
100
128
  setDescription(description) {
101
129
  this.description = description;
102
130
  return this;
103
131
  }
132
+ /**
133
+ * 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.
134
+ * @param input {unknown} The input to validate
135
+ */
104
136
  validate(input) {
105
137
  throw new Error("Validation code not implemented. Value: " + input);
106
138
  }
@@ -112,22 +144,42 @@ var StringOption = class extends ConfigurationOption {
112
144
  defaultValue = "";
113
145
  inputType = "text";
114
146
  type = "string";
147
+ /**
148
+ * 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.
149
+ * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
150
+ */
115
151
  setAllowedValues(allowedValues) {
116
152
  this.allowedValues = allowedValues;
117
153
  return this;
118
154
  }
155
+ /**
156
+ * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
157
+ * @param defaultValue {string} The default value for the string.
158
+ */
119
159
  setDefaultValue(defaultValue) {
120
160
  this.defaultValue = defaultValue;
121
161
  return this;
122
162
  }
163
+ /**
164
+ * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
165
+ * @param minTextLength {number} The minimum text length for the string.
166
+ */
123
167
  setMinTextLength(minTextLength) {
124
168
  this.minTextLength = minTextLength;
125
169
  return this;
126
170
  }
171
+ /**
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.
173
+ * @param maxTextLength {number} The maximum text length for the string.
174
+ */
127
175
  setMaxTextLength(maxTextLength) {
128
176
  this.maxTextLength = maxTextLength;
129
177
  return this;
130
178
  }
179
+ /**
180
+ * Set the input type for the string. This will change how the client renders the input.
181
+ * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
182
+ */
131
183
  setInputType(inputType) {
132
184
  this.inputType = inputType;
133
185
  return this;
@@ -150,18 +202,34 @@ var NumberOption = class extends ConfigurationOption {
150
202
  defaultValue = 0;
151
203
  type = "number";
152
204
  inputType = "number";
205
+ /**
206
+ * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
207
+ * @param min {number} The minimum value for the number.
208
+ */
153
209
  setMin(min) {
154
210
  this.min = min;
155
211
  return this;
156
212
  }
213
+ /**
214
+ * Set the input type for the number. This will change how the client renders the input.
215
+ * @param type {'range' | 'number'} The input type for the number.
216
+ */
157
217
  setInputType(type) {
158
218
  this.inputType = type;
159
219
  return this;
160
220
  }
221
+ /**
222
+ * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
223
+ * @param max {number} The maximum value for the number.
224
+ */
161
225
  setMax(max) {
162
226
  this.max = max;
163
227
  return this;
164
228
  }
229
+ /**
230
+ * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
231
+ * @param defaultValue {number} The default value for the number.
232
+ */
165
233
  setDefaultValue(defaultValue) {
166
234
  this.defaultValue = defaultValue;
167
235
  return this;
@@ -179,6 +247,10 @@ var NumberOption = class extends ConfigurationOption {
179
247
  var BooleanOption = class extends ConfigurationOption {
180
248
  type = "boolean";
181
249
  defaultValue = false;
250
+ /**
251
+ * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
252
+ * @param defaultValue {boolean} The default value for the boolean.
253
+ */
182
254
  setDefaultValue(defaultValue) {
183
255
  this.defaultValue = defaultValue;
184
256
  return this;
@@ -275,16 +347,35 @@ var EventResponse = class {
275
347
  defer() {
276
348
  this.deffered = true;
277
349
  }
350
+ /**
351
+ * Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.**
352
+ * @param data {T}
353
+ */
278
354
  resolve(data) {
279
355
  this.resolved = true;
280
356
  this.data = data;
281
357
  }
358
+ /**
359
+ * Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.**
360
+ */
282
361
  complete() {
283
362
  this.resolved = true;
284
363
  }
364
+ /**
365
+ * Logs a message to the event. This is useful for debugging and logging information to the user.
366
+ * @param message {string}
367
+ */
285
368
  log(message) {
286
369
  this.logs.push(message);
287
370
  }
371
+ /**
372
+ * Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.
373
+ * @async
374
+ * @param name {string}
375
+ * @param description {string}
376
+ * @param screen {ConfigurationBuilder}
377
+ * @returns {Promise<{ [key: string]: boolean | string | number }>}
378
+ */
288
379
  async askForInput(name, description, screen) {
289
380
  if (!this.onInputAsked) {
290
381
  throw new Error("No input asked callback");
@@ -299,6 +390,7 @@ var package_default = {
299
390
  module: "./build/main.js",
300
391
  type: "module",
301
392
  main: "./build/main.cjs",
393
+ version: "1.1.0",
302
394
  exports: {
303
395
  ".": {
304
396
  import: {
@@ -327,7 +419,6 @@ var package_default = {
327
419
  email: "me@nat3z.com",
328
420
  url: "https://nat3z.com/"
329
421
  },
330
- version: "1.0.0",
331
422
  dependencies: {
332
423
  ws: "^8.4.0",
333
424
  zod: "^3.23.8"
@@ -357,12 +448,21 @@ var OGIAddon = class {
357
448
  this.addonInfo = addonInfo;
358
449
  this.addonWSListener = new OGIAddonWSListener(this, this.eventEmitter);
359
450
  }
451
+ /**
452
+ * Register an event listener for the addon. (See EventListenerTypes)
453
+ * @param event {OGIAddonEvent}
454
+ * @param listener {EventListenerTypes[OGIAddonEvent]}
455
+ */
360
456
  on(event, listener) {
361
457
  this.eventEmitter.on(event, listener);
362
458
  }
363
459
  emit(event, ...args) {
364
460
  this.eventEmitter.emit(event, ...args);
365
461
  }
462
+ /**
463
+ * Notify the client using a notification. Provide the type of notification, the message, and an ID.
464
+ * @param notification {Notification}
465
+ */
366
466
  notify(notification) {
367
467
  this.addonWSListener.send("notification", [notification]);
368
468
  }
@@ -489,6 +589,19 @@ var OGIAddonWSListener = class {
489
589
  const gameDetailsResult = await this.waitForEventToRespond(gameDetailsEvent);
490
590
  this.respondToMessage(message.id, gameDetailsResult.data);
491
591
  break;
592
+ case "request-dl":
593
+ let requestDLEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
594
+ if (this.eventEmitter.listenerCount("request-dl") === 0) {
595
+ this.respondToMessage(message.id, { error: "No event listener for request-dl" });
596
+ break;
597
+ }
598
+ this.eventEmitter.emit("request-dl", message.args.appID, message.args.info, requestDLEvent);
599
+ const requestDLResult = await this.waitForEventToRespond(requestDLEvent);
600
+ if (requestDLEvent.data === null || requestDLEvent.data?.downloadType === "request") {
601
+ throw new Error("Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type.");
602
+ }
603
+ this.respondToMessage(message.id, requestDLResult.data);
604
+ break;
492
605
  }
493
606
  });
494
607
  }
@@ -555,6 +668,7 @@ var OGIAddonWSListener = class {
555
668
  0 && (module.exports = {
556
669
  Configuration,
557
670
  ConfigurationBuilder,
558
- EventResponse
671
+ EventResponse,
672
+ version
559
673
  });
560
674
  //# sourceMappingURL=main.cjs.map