ogi-addon 1.2.0 → 1.3.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n})\n\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\n return option.type === 'string';\n }\n\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\n return option.type === 'boolean';\n}\n\nexport class ConfigurationBuilder {\n private options: ConfigurationOption[] = [];\n\n /**\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.\n * @param option { (option: NumberOption) => NumberOption }\n * @returns \n */\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\n let newOption = new NumberOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\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.\n * @param option { (option: StringOption) => StringOption }\n */\n public addStringOption(option: (option: StringOption) => StringOption) {\n let newOption = new StringOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\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.\n * @param option { (option: BooleanOption) => BooleanOption }\n */\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\n let newOption = new BooleanOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach(option => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option)\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors)\n }\n\n config[option.name] = option;\n }\n else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\nexport class ConfigurationOption {\n public name: string = '';\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset'\n \n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName(name: string) {\n this.name = name;\n return this;\n }\n\n /**\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** \n * @param displayName {string} The display name of the option. \n * @returns \n */\n setDisplayName(displayName: string) {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option. \n * @returns \n */\n setDescription(description: string) {\n this.description = description;\n return this;\n }\n\n /**\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.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [ boolean, string ] {\n throw new Error('Validation code not implemented. Value: ' + input)\n };\n}\n\nexport class StringOption extends ConfigurationOption {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string'\n\n /**\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. \n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\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. \n * @param minTextLength {number} The minimum text length for the string. \n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\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. \n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input. \n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string. \n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (typeof input !== 'string') {\n return [ false, 'Input is not a string' ];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [ true, '' ];\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\n }\n\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\n }\n}\n\nexport class NumberOption extends ConfigurationOption {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number'\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input. \n * @param type {'range' | 'number'} The input type for the number. \n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (isNaN(Number(input))) {\n return [ false, 'Input is not a number' ];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\n }\n return [ true, '' ];\n }\n\n}\n\nexport class BooleanOption extends ConfigurationOption {\n public type: ConfigurationOptionType = 'boolean'\n public defaultValue: boolean = false;\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (typeof input !== 'boolean') {\n return [ false, 'Input is not a boolean' ];\n }\n return [ true, '' ];\n }\n\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,Y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AAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa,MAAgC;AAC3C,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,KAAmB;AACxB,SAAK,MAAM;AACX,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgB,cAA4B;AAC1C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,MAAM,OAAO,KAAK,CAAC,GAAG;AACxB,aAAO,CAAE,OAAO,uBAAwB;AAAA,IAC1C;AACA,QAAI,OAAO,KAAK,IAAI,KAAK,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":[]}
1
+ {"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from 'zod';\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption;\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n});\n\nexport function isStringOption(\n option: ConfigurationOption\n): option is StringOption {\n return option.type === 'string';\n}\n\nexport function isNumberOption(\n option: ConfigurationOption\n): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(\n option: ConfigurationOption\n): option is BooleanOption {\n return option.type === 'boolean';\n}\n\nexport class ConfigurationBuilder {\n private options: ConfigurationOption[] = [];\n\n /**\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.\n * @param option { (option: NumberOption) => NumberOption }\n * @returns\n */\n public addNumberOption(\n option: (option: NumberOption) => NumberOption\n ): ConfigurationBuilder {\n let newOption = new NumberOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\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.\n * @param option { (option: StringOption) => StringOption }\n */\n public addStringOption(option: (option: StringOption) => StringOption) {\n let newOption = new StringOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\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.\n * @param option { (option: BooleanOption) => BooleanOption }\n */\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\n let newOption = new BooleanOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach((option) => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option);\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors);\n }\n\n config[option.name] = option;\n } else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset';\nexport class ConfigurationOption {\n public name: string = '';\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName(name: string) {\n this.name = name;\n return this;\n }\n\n /**\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**\n * @param displayName {string} The display name of the option.\n * @returns\n */\n setDisplayName(displayName: string) {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option.\n * @returns\n */\n setDescription(description: string) {\n this.description = description;\n return this;\n }\n\n /**\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.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [boolean, string] {\n throw new Error('Validation code not implemented. Value: ' + input);\n }\n}\n\nexport class StringOption extends ConfigurationOption {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string';\n\n /**\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.\n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\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.\n * @param minTextLength {number} The minimum text length for the string.\n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\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.\n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input.\n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.\n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'string') {\n return [false, 'Input is not a string'];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [true, ''];\n if (\n input.length < this.minTextLength ||\n input.length > this.maxTextLength\n ) {\n return [\n false,\n 'Input is not within the text length ' +\n this.minTextLength +\n ' and ' +\n this.maxTextLength +\n ' characters (currently ' +\n input.length +\n ' characters)',\n ];\n }\n\n return [\n this.allowedValues.includes(input),\n 'Input is not an allowed value',\n ];\n }\n}\n\nexport class NumberOption extends ConfigurationOption {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number';\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input.\n * @param type {'range' | 'number'} The input type for the number.\n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this;\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (isNaN(Number(input))) {\n return [false, 'Input is not a number'];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [\n false,\n 'Input is not within the range of ' + this.min + ' and ' + this.max,\n ];\n }\n return [true, ''];\n }\n}\n\nexport class BooleanOption extends ConfigurationOption {\n public type: ConfigurationOptionType = 'boolean';\n public defaultValue: boolean = false;\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'boolean') {\n return [false, 'Input is not a boolean'];\n }\n return [true, ''];\n }\n}\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,eACd,QACwB;AACxB,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,eACd,QACwB;AACxB,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,gBACd,QACyB;AACzB,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,gBACL,QACsB;AACtB,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,CAAC,WAAW;AAE/B,UAAI,CAAC,kBAAkB;AACrB,iBAAS,KAAK,MAAM,KAA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IACxC;AACA,QAAI,OAAO,KAAK,IAAI,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK;AACxD,aAAO;AAAA,QACL;AAAA,QACA,sCAAsC,KAAK,MAAM,UAAU,KAAK;AAAA,MAClE;AAAA,IACF;AACA,WAAO,CAAC,MAAM,EAAE;AAAA,EAClB;AACF;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,OAAmC;AACnD,QAAI,OAAO,UAAU,WAAW;AAC9B,aAAO,CAAC,OAAO,wBAAwB;AAAA,IACzC;AACA,WAAO,CAAC,MAAM,EAAE;AAAA,EAClB;AACF;","names":[]}
package/build/main.cjs CHANGED
@@ -54,7 +54,7 @@ var ConfigurationBuilder = class {
54
54
  /**
55
55
  * 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.
56
56
  * @param option { (option: NumberOption) => NumberOption }
57
- * @returns
57
+ * @returns
58
58
  */
59
59
  addNumberOption(option) {
60
60
  let newOption = new NumberOption();
@@ -65,7 +65,7 @@ var ConfigurationBuilder = class {
65
65
  /**
66
66
  * 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.
67
67
  * @param option { (option: StringOption) => StringOption }
68
- */
68
+ */
69
69
  addStringOption(option) {
70
70
  let newOption = new StringOption();
71
71
  newOption = option(newOption);
@@ -75,7 +75,7 @@ var ConfigurationBuilder = class {
75
75
  /**
76
76
  * 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.
77
77
  * @param option { (option: BooleanOption) => BooleanOption }
78
- */
78
+ */
79
79
  addBooleanOption(option) {
80
80
  let newOption = new BooleanOption();
81
81
  newOption = option(newOption);
@@ -114,9 +114,9 @@ var ConfigurationOption = class {
114
114
  return this;
115
115
  }
116
116
  /**
117
- * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
118
- * @param displayName {string} The display name of the option.
119
- * @returns
117
+ * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
118
+ * @param displayName {string} The display name of the option.
119
+ * @returns
120
120
  */
121
121
  setDisplayName(displayName) {
122
122
  this.displayName = displayName;
@@ -124,8 +124,8 @@ var ConfigurationOption = class {
124
124
  }
125
125
  /**
126
126
  * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
127
- * @param description {string} The description of the option.
128
- * @returns
127
+ * @param description {string} The description of the option.
128
+ * @returns
129
129
  */
130
130
  setDescription(description) {
131
131
  this.description = description;
@@ -147,7 +147,7 @@ var StringOption = class extends ConfigurationOption {
147
147
  inputType = "text";
148
148
  type = "string";
149
149
  /**
150
- * 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.
150
+ * 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.
151
151
  * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
152
152
  */
153
153
  setAllowedValues(allowedValues) {
@@ -163,15 +163,15 @@ var StringOption = class extends ConfigurationOption {
163
163
  return this;
164
164
  }
165
165
  /**
166
- * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
167
- * @param minTextLength {number} The minimum text length for the string.
166
+ * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
167
+ * @param minTextLength {number} The minimum text length for the string.
168
168
  */
169
169
  setMinTextLength(minTextLength) {
170
170
  this.minTextLength = minTextLength;
171
171
  return this;
172
172
  }
173
173
  /**
174
- * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
174
+ * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
175
175
  * @param maxTextLength {number} The maximum text length for the string.
176
176
  */
177
177
  setMaxTextLength(maxTextLength) {
@@ -179,8 +179,8 @@ var StringOption = class extends ConfigurationOption {
179
179
  return this;
180
180
  }
181
181
  /**
182
- * Set the input type for the string. This will change how the client renders the input.
183
- * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
182
+ * Set the input type for the string. This will change how the client renders the input.
183
+ * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
184
184
  */
185
185
  setInputType(inputType) {
186
186
  this.inputType = inputType;
@@ -193,9 +193,15 @@ var StringOption = class extends ConfigurationOption {
193
193
  if (this.allowedValues.length === 0 && input.length !== 0)
194
194
  return [true, ""];
195
195
  if (input.length < this.minTextLength || input.length > this.maxTextLength) {
196
- return [false, "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"];
196
+ return [
197
+ false,
198
+ "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"
199
+ ];
197
200
  }
198
- return [this.allowedValues.includes(input), "Input is not an allowed value"];
201
+ return [
202
+ this.allowedValues.includes(input),
203
+ "Input is not an allowed value"
204
+ ];
199
205
  }
200
206
  };
201
207
  var NumberOption = class extends ConfigurationOption {
@@ -213,8 +219,8 @@ var NumberOption = class extends ConfigurationOption {
213
219
  return this;
214
220
  }
215
221
  /**
216
- * Set the input type for the number. This will change how the client renders the input.
217
- * @param type {'range' | 'number'} The input type for the number.
222
+ * Set the input type for the number. This will change how the client renders the input.
223
+ * @param type {'range' | 'number'} The input type for the number.
218
224
  */
219
225
  setInputType(type) {
220
226
  this.inputType = type;
@@ -241,7 +247,10 @@ var NumberOption = class extends ConfigurationOption {
241
247
  return [false, "Input is not a number"];
242
248
  }
243
249
  if (Number(input) < this.min || Number(input) > this.max) {
244
- return [false, "Input is not within the range of " + this.min + " and " + this.max];
250
+ return [
251
+ false,
252
+ "Input is not within the range of " + this.min + " and " + this.max
253
+ ];
245
254
  }
246
255
  return [true, ""];
247
256
  }
@@ -285,20 +294,26 @@ var Configuration = class {
285
294
  const erroredKeys = /* @__PURE__ */ new Map();
286
295
  for (const key in this.storedConfigTemplate) {
287
296
  if (this.definiteConfig[key] === null || this.definiteConfig[key] === void 0) {
288
- console.warn("Option " + key + " is not defined. Using default value Value: " + this.definiteConfig[key]);
297
+ console.warn(
298
+ "Option " + key + " is not defined. Using default value Value: " + this.definiteConfig[key]
299
+ );
289
300
  this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue;
290
301
  }
291
302
  if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
292
303
  throw new Error("Option " + key + " is not of the correct type");
293
304
  }
294
- const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);
305
+ const result = this.storedConfigTemplate[key].validate(
306
+ this.definiteConfig[key]
307
+ );
295
308
  if (!result[0]) {
296
309
  erroredKeys.set(key, result[1]);
297
310
  }
298
311
  }
299
312
  for (const key in this.definiteConfig) {
300
313
  if (!this.storedConfigTemplate[key]) {
301
- throw new Error("Option " + key + " is not defined in the configuration template");
314
+ throw new Error(
315
+ "Option " + key + " is not defined in the configuration template"
316
+ );
302
317
  }
303
318
  }
304
319
  if (erroredKeys.size > 0) {
@@ -342,15 +357,19 @@ var EventResponse = class {
342
357
  resolved = false;
343
358
  progress = 0;
344
359
  logs = [];
360
+ failed = void 0;
345
361
  onInputAsked;
346
362
  constructor(onInputAsked) {
347
363
  this.onInputAsked = onInputAsked;
348
364
  }
349
- defer() {
365
+ defer(promise) {
350
366
  this.deffered = true;
367
+ if (promise) {
368
+ promise();
369
+ }
351
370
  }
352
371
  /**
353
- * 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.**
372
+ * 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.**
354
373
  * @param data {T}
355
374
  */
356
375
  resolve(data) {
@@ -358,13 +377,17 @@ var EventResponse = class {
358
377
  this.data = data;
359
378
  }
360
379
  /**
361
- * 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.**
380
+ * 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.**
362
381
  */
363
382
  complete() {
364
383
  this.resolved = true;
365
384
  }
385
+ fail(message) {
386
+ this.resolved = true;
387
+ this.failed = message;
388
+ }
366
389
  /**
367
- * Logs a message to the event. This is useful for debugging and logging information to the user.
390
+ * Logs a message to the event. This is useful for debugging and logging information to the user.
368
391
  * @param message {string}
369
392
  */
370
393
  log(message) {
@@ -395,7 +418,7 @@ var package_default = {
395
418
  module: "./build/main.js",
396
419
  type: "module",
397
420
  main: "./build/main.cjs",
398
- version: "1.2.0",
421
+ version: "1.3.0",
399
422
  exports: {
400
423
  ".": {
401
424
  import: {
@@ -438,6 +461,7 @@ var package_default = {
438
461
  devDependencies: {
439
462
  "@types/node": "^20.14.12",
440
463
  "@types/ws": "^8.4.0",
464
+ prettier: "^3.6.0",
441
465
  tsup: "^8.2.3",
442
466
  typescript: "^5.0.0"
443
467
  }
@@ -452,34 +476,45 @@ var OGIAddon = class {
452
476
  addonInfo;
453
477
  config = new Configuration({});
454
478
  constructor(addonInfo) {
455
- this.addonInfo = addonInfo;
479
+ this.addonInfo = { storeFrontServerCapable: false, ...addonInfo };
456
480
  this.addonWSListener = new OGIAddonWSListener(this, this.eventEmitter);
457
481
  }
458
482
  /**
459
- * Register an event listener for the addon. (See EventListenerTypes)
483
+ * Register an event listener for the addon. (See EventListenerTypes)
460
484
  * @param event {OGIAddonEvent}
461
- * @param listener {EventListenerTypes[OGIAddonEvent]}
485
+ * @param listener {EventListenerTypes[OGIAddonEvent]}
462
486
  */
463
487
  on(event, listener) {
464
488
  this.eventEmitter.on(event, listener);
489
+ if (event === "game-details") {
490
+ this.addonInfo.storeFrontServerCapable = true;
491
+ this.addonWSListener.send("flag", {
492
+ flag: "storeFrontServerCapable",
493
+ value: this.addonInfo.storeFrontServerCapable
494
+ });
495
+ }
465
496
  }
466
497
  emit(event, ...args) {
467
498
  this.eventEmitter.emit(event, ...args);
468
499
  }
469
500
  /**
470
- * Notify the client using a notification. Provide the type of notification, the message, and an ID.
501
+ * Notify the client using a notification. Provide the type of notification, the message, and an ID.
471
502
  * @param notification {Notification}
472
503
  */
473
504
  notify(notification) {
474
505
  this.addonWSListener.send("notification", [notification]);
475
506
  }
476
507
  /**
477
- * Search for items in the OGI Steam-Synced Library. Query can either be a Steam AppID or a Steam Game Name.
478
- * @param query {string}
479
- * @param event {EventResponse<BasicLibraryInfo[]>}
508
+ * Get the app details for a given appID and storefront.
509
+ * @param appID {number}
510
+ * @param storefront {string}
511
+ * @returns {Promise<StoreData>}
480
512
  */
481
- async steamSearch(query, strict = false) {
482
- const id = this.addonWSListener.send("steam-search", { query, strict });
513
+ async getAppDetails(appID, storefront) {
514
+ const id = this.addonWSListener.send("get-app-details", {
515
+ appID,
516
+ storefront
517
+ });
483
518
  return await this.addonWSListener.waitForResponseFromServer(id);
484
519
  }
485
520
  /**
@@ -493,7 +528,13 @@ var OGIAddon = class {
493
528
  const progress = 0;
494
529
  const logs = [];
495
530
  const task = new CustomTask(this.addonWSListener, id, progress, logs);
496
- this.addonWSListener.send("task-update", { id, progress, logs, finished: false });
531
+ this.addonWSListener.send("task-update", {
532
+ id,
533
+ progress,
534
+ logs,
535
+ finished: false,
536
+ failed: void 0
537
+ });
497
538
  return task;
498
539
  }
499
540
  };
@@ -503,6 +544,7 @@ var CustomTask = class {
503
544
  logs;
504
545
  finished = false;
505
546
  ws;
547
+ failed = void 0;
506
548
  constructor(ws2, id, progress, logs) {
507
549
  this.id = id;
508
550
  this.progress = progress;
@@ -517,17 +559,30 @@ var CustomTask = class {
517
559
  this.finished = true;
518
560
  this.update();
519
561
  }
562
+ fail(message) {
563
+ this.failed = message;
564
+ this.update();
565
+ }
520
566
  setProgress(progress) {
521
567
  this.progress = progress;
522
568
  this.update();
523
569
  }
524
570
  update() {
525
- this.ws.send("task-update", { id: this.id, progress: this.progress, logs: this.logs, finished: this.finished });
571
+ this.ws.send("task-update", {
572
+ id: this.id,
573
+ progress: this.progress,
574
+ logs: this.logs,
575
+ finished: this.finished,
576
+ failed: this.failed
577
+ });
526
578
  }
527
579
  };
528
580
  var SearchTool = class {
529
581
  fuse;
530
- constructor(items, keys, options = { threshold: 0.3, includeScore: true }) {
582
+ constructor(items, keys, options = {
583
+ threshold: 0.3,
584
+ includeScore: true
585
+ }) {
531
586
  this.fuse = new import_fuse.default(items, {
532
587
  keys,
533
588
  ...options
@@ -546,7 +601,9 @@ var OGIAddonWSListener = class {
546
601
  addon;
547
602
  constructor(ogiAddon, eventEmitter) {
548
603
  if (process.argv[process.argv.length - 1].split("=")[0] !== "--addonSecret") {
549
- throw new Error("No secret provided. This usually happens because the addon was not started by the OGI Addon Server.");
604
+ throw new Error(
605
+ "No secret provided. This usually happens because the addon was not started by the OGI Addon Server."
606
+ );
550
607
  }
551
608
  this.addon = ogiAddon;
552
609
  this.eventEmitter = eventEmitter;
@@ -567,7 +624,9 @@ var OGIAddonWSListener = class {
567
624
  });
568
625
  this.socket.on("error", (error) => {
569
626
  if (error.message.includes("Failed to connect")) {
570
- throw new Error("OGI Addon Server is not running/is unreachable. Please start the server and try again.");
627
+ throw new Error(
628
+ "OGI Addon Server is not running/is unreachable. Please start the server and try again."
629
+ );
571
630
  }
572
631
  console.error("An error occurred:", error);
573
632
  });
@@ -590,15 +649,17 @@ var OGIAddonWSListener = class {
590
649
  if (!socket) {
591
650
  return {};
592
651
  }
593
- socket.send(JSON.stringify({
594
- event: "input-asked",
595
- args: {
596
- config,
597
- name,
598
- description
599
- },
600
- id
601
- }));
652
+ socket.send(
653
+ JSON.stringify({
654
+ event: "input-asked",
655
+ args: {
656
+ config,
657
+ name,
658
+ description
659
+ },
660
+ id
661
+ })
662
+ );
602
663
  return await this.waitForResponseFromServer(id);
603
664
  }
604
665
  registerMessageReceiver() {
@@ -608,20 +669,39 @@ var OGIAddonWSListener = class {
608
669
  case "config-update":
609
670
  const result = this.addon.config.updateConfig(message.args);
610
671
  if (!result[0]) {
611
- this.respondToMessage(message.id, { success: false, error: result[1] });
672
+ this.respondToMessage(message.id, {
673
+ success: false,
674
+ error: result[1]
675
+ });
612
676
  } else {
613
677
  this.respondToMessage(message.id, { success: true });
614
678
  }
615
679
  break;
616
680
  case "search":
617
- let searchResultEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
681
+ let searchResultEvent = new EventResponse(
682
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
683
+ );
618
684
  this.eventEmitter.emit("search", message.args, searchResultEvent);
619
685
  const searchResult = await this.waitForEventToRespond(searchResultEvent);
620
686
  this.respondToMessage(message.id, searchResult.data);
621
687
  break;
622
688
  case "setup":
623
- let setupEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
624
- this.eventEmitter.emit("setup", { path: message.args.path, appID: message.args.appID, storefront: message.args.storefront, type: message.args.type, name: message.args.name, usedRealDebrid: message.args.usedRealDebrid, multiPartFiles: message.args.multiPartFiles }, setupEvent);
689
+ let setupEvent = new EventResponse(
690
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
691
+ );
692
+ this.eventEmitter.emit(
693
+ "setup",
694
+ {
695
+ path: message.args.path,
696
+ appID: message.args.appID,
697
+ storefront: message.args.storefront,
698
+ type: message.args.type,
699
+ name: message.args.name,
700
+ usedRealDebrid: message.args.usedRealDebrid,
701
+ multiPartFiles: message.args.multiPartFiles
702
+ },
703
+ setupEvent
704
+ );
625
705
  const interval = setInterval(() => {
626
706
  if (setupEvent.resolved) {
627
707
  clearInterval(interval);
@@ -630,45 +710,83 @@ var OGIAddonWSListener = class {
630
710
  this.send("defer-update", {
631
711
  logs: setupEvent.logs,
632
712
  deferID: message.args.deferID,
633
- progress: setupEvent.progress
713
+ progress: setupEvent.progress,
714
+ failed: setupEvent.failed
634
715
  });
635
716
  }, 100);
636
717
  const setupResult = await this.waitForEventToRespond(setupEvent);
637
718
  this.respondToMessage(message.id, setupResult.data);
638
719
  break;
639
720
  case "library-search":
640
- let librarySearchEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
721
+ let librarySearchEvent = new EventResponse(
722
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
723
+ );
641
724
  if (this.eventEmitter.listenerCount("game-details") === 0) {
642
725
  this.respondToMessage(message.id, []);
643
726
  break;
644
727
  }
645
- this.eventEmitter.emit("library-search", message.args, librarySearchEvent);
728
+ this.eventEmitter.emit(
729
+ "library-search",
730
+ message.args,
731
+ librarySearchEvent
732
+ );
646
733
  const librarySearchResult = await this.waitForEventToRespond(librarySearchEvent);
647
734
  this.respondToMessage(message.id, librarySearchResult.data);
648
735
  break;
649
736
  case "game-details":
650
- let gameDetailsEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
737
+ let gameDetailsEvent = new EventResponse(
738
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
739
+ );
651
740
  if (this.eventEmitter.listenerCount("game-details") === 0) {
652
- this.respondToMessage(message.id, { error: "No event listener for game-details" });
741
+ this.respondToMessage(message.id, {
742
+ error: "No event listener for game-details"
743
+ });
653
744
  break;
654
745
  }
655
- this.eventEmitter.emit("game-details", message.args, gameDetailsEvent);
746
+ this.eventEmitter.emit(
747
+ "game-details",
748
+ message.args,
749
+ gameDetailsEvent
750
+ );
656
751
  const gameDetailsResult = await this.waitForEventToRespond(gameDetailsEvent);
657
752
  this.respondToMessage(message.id, gameDetailsResult.data);
658
753
  break;
659
754
  case "request-dl":
660
- let requestDLEvent = new EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
755
+ let requestDLEvent = new EventResponse(
756
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
757
+ );
661
758
  if (this.eventEmitter.listenerCount("request-dl") === 0) {
662
- this.respondToMessage(message.id, { error: "No event listener for request-dl" });
759
+ this.respondToMessage(message.id, {
760
+ error: "No event listener for request-dl"
761
+ });
663
762
  break;
664
763
  }
665
- this.eventEmitter.emit("request-dl", message.args.appID, message.args.info, requestDLEvent);
764
+ this.eventEmitter.emit(
765
+ "request-dl",
766
+ message.args.appID,
767
+ message.args.info,
768
+ requestDLEvent
769
+ );
666
770
  const requestDLResult = await this.waitForEventToRespond(requestDLEvent);
667
- if (requestDLEvent.data === null || requestDLEvent.data?.downloadType === "request") {
668
- 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.");
771
+ if (requestDLEvent.failed) {
772
+ this.respondToMessage(message.id, {
773
+ statusError: requestDLEvent.failed
774
+ });
775
+ break;
776
+ }
777
+ if (requestDLEvent.data === void 0 || requestDLEvent.data?.downloadType === "request") {
778
+ throw new Error(
779
+ "Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type."
780
+ );
669
781
  }
670
782
  this.respondToMessage(message.id, requestDLResult.data);
671
783
  break;
784
+ case "catalog":
785
+ let catalogEvent = new EventResponse();
786
+ this.eventEmitter.emit("catalog", catalogEvent);
787
+ const catalogResult = await this.waitForEventToRespond(catalogEvent);
788
+ this.respondToMessage(message.id, catalogResult.data);
789
+ break;
672
790
  }
673
791
  });
674
792
  }
@@ -696,11 +814,13 @@ var OGIAddonWSListener = class {
696
814
  });
697
815
  }
698
816
  respondToMessage(messageID, response) {
699
- this.socket.send(JSON.stringify({
700
- event: "response",
701
- id: messageID,
702
- args: response
703
- }));
817
+ this.socket.send(
818
+ JSON.stringify({
819
+ event: "response",
820
+ id: messageID,
821
+ args: response
822
+ })
823
+ );
704
824
  console.log("dispatched response to " + messageID);
705
825
  }
706
826
  waitForResponseFromServer(messageID) {
@@ -723,11 +843,13 @@ var OGIAddonWSListener = class {
723
843
  }
724
844
  send(event, args) {
725
845
  const id = Math.random().toString(36).substring(7);
726
- this.socket.send(JSON.stringify({
727
- event,
728
- args,
729
- id
730
- }));
846
+ this.socket.send(
847
+ JSON.stringify({
848
+ event,
849
+ args,
850
+ id
851
+ })
852
+ );
731
853
  return id;
732
854
  }
733
855
  close() {