ogi-addon 1.5.1 → 1.6.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/SearchEngine.ts"],"sourcesContent":["export type SearchResult = {\n name: string;\n downloadType: 'torrent' | 'direct' | 'magnet' | 'request';\n filename?: string;\n downloadURL?: string;\n files?: {\n name: string;\n downloadURL: string;\n headers?: Record<string, string>;\n }[];\n manifest?: Record<string, any>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/SearchEngine.ts"],"sourcesContent":["export type SearchResult = {\n name: string;\n downloadType: 'torrent' | 'direct' | 'magnet' | 'request' | 'task';\n filename?: string;\n downloadURL?: string;\n files?: {\n name: string;\n downloadURL: string;\n headers?: Record<string, string>;\n }[];\n manifest?: Record<string, any>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,6 +1,6 @@
1
1
  type SearchResult = {
2
2
  name: string;
3
- downloadType: 'torrent' | 'direct' | 'magnet' | 'request';
3
+ downloadType: 'torrent' | 'direct' | 'magnet' | 'request' | 'task';
4
4
  filename?: string;
5
5
  downloadURL?: string;
6
6
  files?: {
@@ -1,6 +1,6 @@
1
1
  type SearchResult = {
2
2
  name: string;
3
- downloadType: 'torrent' | 'direct' | 'magnet' | 'request';
3
+ downloadType: 'torrent' | 'direct' | 'magnet' | 'request' | 'task';
4
4
  filename?: string;
5
5
  downloadURL?: string;
6
6
  files?: {
package/build/main.cjs CHANGED
@@ -418,7 +418,7 @@ var package_default = {
418
418
  module: "./build/main.js",
419
419
  type: "module",
420
420
  main: "./build/main.cjs",
421
- version: "1.5.1",
421
+ version: "1.6.0",
422
422
  exports: {
423
423
  ".": {
424
424
  import: {
@@ -675,12 +675,16 @@ var OGIAddonWSListener = class {
675
675
  case "config-update":
676
676
  const result = this.addon.config.updateConfig(message.args);
677
677
  if (!result[0]) {
678
- this.respondToMessage(message.id, {
679
- success: false,
680
- error: result[1]
681
- });
678
+ this.respondToMessage(
679
+ message.id,
680
+ {
681
+ success: false,
682
+ error: result[1]
683
+ },
684
+ void 0
685
+ );
682
686
  } else {
683
- this.respondToMessage(message.id, { success: true });
687
+ this.respondToMessage(message.id, { success: true }, void 0);
684
688
  }
685
689
  break;
686
690
  case "search":
@@ -689,25 +693,17 @@ var OGIAddonWSListener = class {
689
693
  );
690
694
  this.eventEmitter.emit("search", message.args, searchResultEvent);
691
695
  const searchResult = await this.waitForEventToRespond(searchResultEvent);
692
- this.respondToMessage(message.id, searchResult.data);
696
+ this.respondToMessage(
697
+ message.id,
698
+ searchResult.data,
699
+ searchResultEvent
700
+ );
693
701
  break;
694
- case "setup":
702
+ case "setup": {
695
703
  let setupEvent = new EventResponse(
696
704
  (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
697
705
  );
698
- this.eventEmitter.emit(
699
- "setup",
700
- {
701
- path: message.args.path,
702
- appID: message.args.appID,
703
- storefront: message.args.storefront,
704
- type: message.args.type,
705
- name: message.args.name,
706
- usedRealDebrid: message.args.usedRealDebrid,
707
- multiPartFiles: message.args.multiPartFiles
708
- },
709
- setupEvent
710
- );
706
+ this.eventEmitter.emit("setup", message.args, setupEvent);
711
707
  const interval = setInterval(() => {
712
708
  if (setupEvent.resolved) {
713
709
  clearInterval(interval);
@@ -721,14 +717,15 @@ var OGIAddonWSListener = class {
721
717
  });
722
718
  }, 100);
723
719
  const setupResult = await this.waitForEventToRespond(setupEvent);
724
- this.respondToMessage(message.id, setupResult.data);
720
+ this.respondToMessage(message.id, setupResult.data, setupEvent);
725
721
  break;
722
+ }
726
723
  case "library-search":
727
724
  let librarySearchEvent = new EventResponse(
728
725
  (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
729
726
  );
730
727
  if (this.eventEmitter.listenerCount("game-details") === 0) {
731
- this.respondToMessage(message.id, []);
728
+ this.respondToMessage(message.id, [], librarySearchEvent);
732
729
  break;
733
730
  }
734
731
  this.eventEmitter.emit(
@@ -737,16 +734,24 @@ var OGIAddonWSListener = class {
737
734
  librarySearchEvent
738
735
  );
739
736
  const librarySearchResult = await this.waitForEventToRespond(librarySearchEvent);
740
- this.respondToMessage(message.id, librarySearchResult.data);
737
+ this.respondToMessage(
738
+ message.id,
739
+ librarySearchResult.data,
740
+ librarySearchEvent
741
+ );
741
742
  break;
742
743
  case "game-details":
743
744
  let gameDetailsEvent = new EventResponse(
744
745
  (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
745
746
  );
746
747
  if (this.eventEmitter.listenerCount("game-details") === 0) {
747
- this.respondToMessage(message.id, {
748
- error: "No event listener for game-details"
749
- });
748
+ this.respondToMessage(
749
+ message.id,
750
+ {
751
+ error: "No event listener for game-details"
752
+ },
753
+ gameDetailsEvent
754
+ );
750
755
  break;
751
756
  }
752
757
  this.eventEmitter.emit(
@@ -755,16 +760,24 @@ var OGIAddonWSListener = class {
755
760
  gameDetailsEvent
756
761
  );
757
762
  const gameDetailsResult = await this.waitForEventToRespond(gameDetailsEvent);
758
- this.respondToMessage(message.id, gameDetailsResult.data);
763
+ this.respondToMessage(
764
+ message.id,
765
+ gameDetailsResult.data,
766
+ gameDetailsEvent
767
+ );
759
768
  break;
760
769
  case "request-dl":
761
770
  let requestDLEvent = new EventResponse(
762
771
  (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
763
772
  );
764
773
  if (this.eventEmitter.listenerCount("request-dl") === 0) {
765
- this.respondToMessage(message.id, {
766
- error: "No event listener for request-dl"
767
- });
774
+ this.respondToMessage(
775
+ message.id,
776
+ {
777
+ error: "No event listener for request-dl"
778
+ },
779
+ requestDLEvent
780
+ );
768
781
  break;
769
782
  }
770
783
  this.eventEmitter.emit(
@@ -775,9 +788,7 @@ var OGIAddonWSListener = class {
775
788
  );
776
789
  const requestDLResult = await this.waitForEventToRespond(requestDLEvent);
777
790
  if (requestDLEvent.failed) {
778
- this.respondToMessage(message.id, {
779
- statusError: requestDLEvent.failed
780
- });
791
+ this.respondToMessage(message.id, void 0, requestDLEvent);
781
792
  break;
782
793
  }
783
794
  if (requestDLEvent.data === void 0 || requestDLEvent.data?.downloadType === "request") {
@@ -785,14 +796,39 @@ var OGIAddonWSListener = class {
785
796
  "Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type."
786
797
  );
787
798
  }
788
- this.respondToMessage(message.id, requestDLResult.data);
799
+ this.respondToMessage(
800
+ message.id,
801
+ requestDLResult.data,
802
+ requestDLEvent
803
+ );
789
804
  break;
790
805
  case "catalog":
791
806
  let catalogEvent = new EventResponse();
792
807
  this.eventEmitter.emit("catalog", catalogEvent);
793
808
  const catalogResult = await this.waitForEventToRespond(catalogEvent);
794
- this.respondToMessage(message.id, catalogResult.data);
809
+ this.respondToMessage(message.id, catalogResult.data, catalogEvent);
810
+ break;
811
+ case "task-run": {
812
+ let taskRunEvent = new EventResponse(
813
+ (screen, name, description) => this.userInputAsked(screen, name, description, this.socket)
814
+ );
815
+ this.eventEmitter.emit("task-run", message.args, taskRunEvent);
816
+ const interval = setInterval(() => {
817
+ if (taskRunEvent.resolved) {
818
+ clearInterval(interval);
819
+ return;
820
+ }
821
+ this.send("defer-update", {
822
+ logs: taskRunEvent.logs,
823
+ deferID: message.args.deferID,
824
+ progress: taskRunEvent.progress,
825
+ failed: taskRunEvent.failed
826
+ });
827
+ }, 100);
828
+ const taskRunResult = await this.waitForEventToRespond(taskRunEvent);
829
+ this.respondToMessage(message.id, taskRunResult.data, taskRunEvent);
795
830
  break;
831
+ }
796
832
  }
797
833
  });
798
834
  }
@@ -819,12 +855,13 @@ var OGIAddonWSListener = class {
819
855
  }, 5e3);
820
856
  });
821
857
  }
822
- respondToMessage(messageID, response) {
858
+ respondToMessage(messageID, response, originalEvent) {
823
859
  this.socket.send(
824
860
  JSON.stringify({
825
861
  event: "response",
826
862
  id: messageID,
827
- args: response
863
+ args: response,
864
+ statusError: originalEvent ? originalEvent.failed : void 0
828
865
  })
829
866
  );
830
867
  console.log("dispatched response to " + messageID);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main.ts","../src/config/ConfigurationBuilder.ts","../src/config/Configuration.ts","../src/EventResponse.ts","../package.json"],"sourcesContent":["import ws, { WebSocket } from 'ws';\nimport events from 'node:events';\nimport {\n ConfigurationBuilder,\n ConfigurationFile,\n} from './config/ConfigurationBuilder';\nimport { Configuration } from './config/Configuration';\nimport EventResponse from './EventResponse';\nimport { SearchResult } from './SearchEngine';\nimport Fuse, { IFuseOptions } from 'fuse.js';\n\nexport type OGIAddonEvent =\n | 'connect'\n | 'disconnect'\n | 'configure'\n | 'authenticate'\n | 'search'\n | 'setup'\n | 'library-search'\n | 'game-details'\n | 'exit'\n | 'request-dl'\n | 'catalog';\n\nexport type OGIAddonClientSentEvent =\n | 'response'\n | 'authenticate'\n | 'configure'\n | 'defer-update'\n | 'notification'\n | 'input-asked'\n | 'get-app-details'\n | 'flag'\n | 'task-update';\n\nexport type OGIAddonServerSentEvent =\n | 'authenticate'\n | 'configure'\n | 'config-update'\n | 'search'\n | 'setup'\n | 'response'\n | 'library-search'\n | 'game-details'\n | 'request-dl'\n | 'catalog';\nexport { ConfigurationBuilder, Configuration, EventResponse, SearchResult };\nconst defaultPort = 7654;\nimport pjson from '../package.json';\nexport const VERSION = pjson.version;\n\nexport interface ClientSentEventTypes {\n response: any;\n authenticate: {\n name: string;\n id: string;\n description: string;\n version: string;\n author: string;\n };\n configure: ConfigurationFile;\n 'defer-update': {\n logs: string[];\n progress: number;\n };\n notification: Notification;\n 'input-asked': ConfigurationBuilder;\n 'task-update': {\n id: string;\n progress: number;\n logs: string[];\n finished: boolean;\n failed: string | undefined;\n };\n 'get-app-details': {\n appID: number;\n storefront: string;\n };\n flag: {\n flag: string;\n value: string | string[];\n };\n}\n\nexport type BasicLibraryInfo = {\n name: string;\n capsuleImage: string;\n appID: number;\n storefront: string;\n};\n\nexport interface EventListenerTypes {\n /**\n * This event is emitted when the addon connects to the OGI Addon Server. Addon does not need to resolve anything.\n * @param socket\n * @returns\n */\n connect: (socket: ws) => void;\n\n /**\n * This event is emitted when the client requests for the addon to disconnect. Addon does not need to resolve this event, but we recommend `process.exit(0)` so the addon can exit gracefully instead of by force by the addon server.\n * @param reason\n * @returns\n */\n disconnect: (reason: string) => void;\n /**\n * This event is emitted when the client requests for the addon to configure itself. Addon should resolve the event with the internal configuration. (See ConfigurationBuilder)\n * @param config\n * @returns\n */\n configure: (config: ConfigurationBuilder) => ConfigurationBuilder;\n /**\n * This event is called when the client provides a response to any event. This should be treated as middleware.\n * @param response\n * @returns\n */\n response: (response: any) => void;\n\n /**\n * This event is called when the client requests for the addon to authenticate itself. You don't need to provide any info.\n * @param config\n * @returns\n */\n authenticate: (config: any) => void;\n /**\n * This event is emitted when the client requests for a torrent/direct download search to be performed. Addon is given the gameID (could be a steam appID or custom store appID), along with the storefront type. Addon should resolve the event with the search results. (See SearchResult)\n * @param query\n * @param event\n * @returns\n */\n search: (\n query: { storefront: string; appID: number },\n event: EventResponse<SearchResult[]>\n ) => void;\n /**\n * This event is emitted when the client requests for app setup to be performed. Addon should resolve the event with the metadata for the library entry. (See LibraryInfo)\n * @param data\n * @param event\n * @returns\n */\n setup: (\n data: {\n path: string;\n type: 'direct' | 'torrent' | 'magnet';\n name: string;\n usedRealDebrid: boolean;\n multiPartFiles?: {\n name: string;\n downloadURL: string;\n }[];\n appID: number;\n storefront: string;\n },\n event: EventResponse<\n Omit<\n LibraryInfo,\n | 'capsuleImage'\n | 'coverImage'\n | 'name'\n | 'appID'\n | 'storefront'\n | 'addonsource'\n | 'titleImage'\n >\n >\n ) => void;\n\n /**\n * This event is emitted when the client requires for a search to be performed. Input is the search query.\n * @param query\n * @param event\n * @returns\n */\n 'library-search': (\n query: string,\n event: EventResponse<BasicLibraryInfo[]>\n ) => void;\n\n /**\n * This event is emitted when the client requests for a game details to be fetched. Addon should resolve the event with the game details. This is used to generate a store page for the game.\n * @param appID\n * @param event\n * @returns\n */\n 'game-details': (\n details: { appID: number; storefront: string },\n event: EventResponse<StoreData | undefined>\n ) => void;\n\n /**\n * This event is emitted when the client requests for the addon to exit. Use this to perform any cleanup tasks, ending with a `process.exit(0)`.\n * @returns\n */\n exit: () => void;\n\n /**\n * This event is emitted when the client requests for a download to be performed with the 'request' type. Addon should resolve the event with a SearchResult containing the actual download info.\n * @param appID\n * @param info\n * @param event\n * @returns\n */\n 'request-dl': (\n appID: number,\n info: SearchResult,\n event: EventResponse<SearchResult>\n ) => void;\n\n /**\n * This event is emitted when the client requests for a catalog to be fetched. Addon should resolve the event with the catalog.\n * @param event\n * @returns\n */\n catalog: (\n event: Omit<\n EventResponse<{\n [key: string]: {\n name: string;\n description: string;\n listings: BasicLibraryInfo[];\n };\n }>,\n 'askForInput'\n >\n ) => void;\n}\n\nexport interface StoreData {\n name: string;\n publishers: string[];\n developers: string[];\n appID: number;\n releaseDate: string;\n capsuleImage: string;\n coverImage: string;\n basicDescription: string;\n description: string;\n headerImage: string;\n}\nexport interface WebsocketMessageClient {\n event: OGIAddonClientSentEvent;\n id?: string;\n args: any;\n}\nexport interface WebsocketMessageServer {\n event: OGIAddonServerSentEvent;\n id?: string;\n args: any;\n}\n\n/**\n * The configuration for the addon. This is used to identify the addon and provide information about it.\n * Storefronts is an array of names of stores that the addon supports.\n */\nexport interface OGIAddonConfiguration {\n name: string;\n id: string;\n description: string;\n version: string;\n\n author: string;\n repository: string;\n storefronts: string[];\n}\n\n/**\n * The main class for the OGI Addon. This class is used to interact with the OGI Addon Server. The OGI Addon Server provides a `--addonSecret` to the addon so it can securely connect.\n * @example\n * ```typescript\n * const addon = new OGIAddon({\n * name: 'Test Addon',\n * id: 'test-addon',\n * description: 'A test addon',\n * version: '1.0.0',\n * author: 'OGI Developers',\n * repository: ''\n * });\n * ```\n *\n */\nexport default class OGIAddon {\n public eventEmitter = new events.EventEmitter();\n public addonWSListener: OGIAddonWSListener;\n public addonInfo: OGIAddonConfiguration;\n public config: Configuration = new Configuration({});\n private eventsAvailable: OGIAddonEvent[] = [];\n private registeredConnectEvent: boolean = false;\n\n constructor(addonInfo: OGIAddonConfiguration) {\n this.addonInfo = addonInfo;\n this.addonWSListener = new OGIAddonWSListener(this, this.eventEmitter);\n }\n\n /**\n * Register an event listener for the addon. (See EventListenerTypes)\n * @param event {OGIAddonEvent}\n * @param listener {EventListenerTypes[OGIAddonEvent]}\n */\n public on<T extends OGIAddonEvent>(\n event: T,\n listener: EventListenerTypes[T]\n ) {\n this.eventEmitter.on(event, listener);\n this.eventsAvailable.push(event);\n // wait for the addon to be connected\n if (!this.registeredConnectEvent) {\n this.addonWSListener.eventEmitter.once('connect', () => {\n this.addonWSListener.send('flag', {\n flag: 'events-available',\n value: this.eventsAvailable,\n });\n });\n this.registeredConnectEvent = true;\n }\n }\n\n public emit<T extends OGIAddonEvent>(\n event: T,\n ...args: Parameters<EventListenerTypes[T]>\n ) {\n this.eventEmitter.emit(event, ...args);\n }\n\n /**\n * Notify the client using a notification. Provide the type of notification, the message, and an ID.\n * @param notification {Notification}\n */\n public notify(notification: Notification) {\n this.addonWSListener.send('notification', [notification]);\n }\n\n /**\n * Get the app details for a given appID and storefront.\n * @param appID {number}\n * @param storefront {string}\n * @returns {Promise<StoreData>}\n */\n public async getAppDetails(appID: number, storefront: string) {\n const id = this.addonWSListener.send('get-app-details', {\n appID,\n storefront,\n });\n return await this.addonWSListener.waitForResponseFromServer<\n StoreData | undefined\n >(id);\n }\n\n /**\n * Notify the OGI Addon Server that you are performing a background task. This can be used to help users understand what is happening in the background.\n * @param id {string}\n * @param progress {number}\n * @param logs {string[]}\n */\n public async task() {\n const id = Math.random().toString(36).substring(7);\n const progress = 0;\n const logs: string[] = [];\n const task = new CustomTask(this.addonWSListener, id, progress, logs);\n this.addonWSListener.send('task-update', {\n id,\n progress,\n logs,\n finished: false,\n failed: undefined,\n });\n return task;\n }\n}\n\nexport class CustomTask {\n public readonly id: string;\n public progress: number;\n public logs: string[];\n public finished: boolean = false;\n public ws: OGIAddonWSListener;\n public failed: string | undefined = undefined;\n constructor(\n ws: OGIAddonWSListener,\n id: string,\n progress: number,\n logs: string[]\n ) {\n this.id = id;\n this.progress = progress;\n this.logs = logs;\n this.ws = ws;\n }\n public log(log: string) {\n this.logs.push(log);\n this.update();\n }\n public finish() {\n this.finished = true;\n this.update();\n }\n public fail(message: string) {\n this.failed = message;\n this.update();\n }\n public setProgress(progress: number) {\n this.progress = progress;\n this.update();\n }\n public update() {\n this.ws.send('task-update', {\n id: this.id,\n progress: this.progress,\n logs: this.logs,\n finished: this.finished,\n failed: this.failed,\n });\n }\n}\n/**\n * A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.\n * @example\n * ```typescript\n * const searchTool = new SearchTool<LibraryInfo>([{ name: 'test', appID: 123 }, { name: 'test2', appID: 124 }], ['name']);\n * const results = searchTool.search('test', 10);\n * ```\n */\nexport class SearchTool<T> {\n private fuse: Fuse<T>;\n constructor(\n items: T[],\n keys: string[],\n options: Omit<IFuseOptions<T>, 'keys'> = {\n threshold: 0.3,\n includeScore: true,\n }\n ) {\n this.fuse = new Fuse(items, {\n keys,\n ...options,\n });\n }\n public search(query: string, limit: number = 10): T[] {\n return this.fuse\n .search(query)\n .slice(0, limit)\n .map((result) => result.item);\n }\n public addItems(items: T[]) {\n items.map((item) => this.fuse.add(item));\n }\n}\n/**\n * Library Info is the metadata for a library entry after setting up a game.\n */\nexport interface LibraryInfo {\n name: string;\n version: string;\n cwd: string;\n appID: number;\n launchExecutable: string;\n launchArguments?: string;\n capsuleImage: string;\n storefront: string;\n addonsource: string;\n coverImage: string;\n titleImage?: string;\n}\ninterface Notification {\n type: 'warning' | 'error' | 'info' | 'success';\n message: string;\n id: string;\n}\nclass OGIAddonWSListener {\n private socket: WebSocket;\n public eventEmitter: events.EventEmitter;\n public addon: OGIAddon;\n\n constructor(ogiAddon: OGIAddon, eventEmitter: events.EventEmitter) {\n if (\n process.argv[process.argv.length - 1].split('=')[0] !== '--addonSecret'\n ) {\n throw new Error(\n 'No secret provided. This usually happens because the addon was not started by the OGI Addon Server.'\n );\n }\n this.addon = ogiAddon;\n this.eventEmitter = eventEmitter;\n this.socket = new ws('ws://localhost:' + defaultPort);\n this.socket.on('open', () => {\n console.log('Connected to OGI Addon Server');\n console.log('OGI Addon Server Version:', VERSION);\n\n // Authenticate with OGI Addon Server\n this.send('authenticate', {\n ...this.addon.addonInfo,\n secret: process.argv[process.argv.length - 1].split('=')[1],\n ogiVersion: VERSION,\n });\n\n this.eventEmitter.emit('connect');\n\n // send a configuration request\n let configBuilder = new ConfigurationBuilder();\n this.eventEmitter.emit('configure', configBuilder);\n this.send('configure', configBuilder.build(false));\n this.addon.config = new Configuration(configBuilder.build(true));\n });\n\n this.socket.on('error', (error) => {\n if (error.message.includes('Failed to connect')) {\n throw new Error(\n 'OGI Addon Server is not running/is unreachable. Please start the server and try again.'\n );\n }\n console.error('An error occurred:', error);\n });\n\n this.socket.on('close', (code, reason) => {\n if (code === 1008) {\n console.error('Authentication failed:', reason);\n return;\n }\n this.eventEmitter.emit('disconnect', reason);\n console.log('Disconnected from OGI Addon Server');\n console.error(reason.toString());\n this.eventEmitter.emit('exit');\n this.socket.close();\n });\n\n this.registerMessageReceiver();\n }\n\n private async userInputAsked(\n configBuilt: ConfigurationBuilder,\n name: string,\n description: string,\n socket: WebSocket\n ): Promise<{ [key: string]: number | boolean | string }> {\n const config = configBuilt.build(false);\n const id = Math.random().toString(36).substring(7);\n if (!socket) {\n return {};\n }\n socket.send(\n JSON.stringify({\n event: 'input-asked',\n args: {\n config,\n name,\n description,\n },\n id: id,\n })\n );\n return await this.waitForResponseFromServer(id);\n }\n\n private registerMessageReceiver() {\n this.socket.on('message', async (data: string) => {\n const message: WebsocketMessageServer = JSON.parse(data);\n switch (message.event) {\n case 'config-update':\n const result = this.addon.config.updateConfig(message.args);\n if (!result[0]) {\n this.respondToMessage(message.id!!, {\n success: false,\n error: result[1],\n });\n } else {\n this.respondToMessage(message.id!!, { success: true });\n }\n break;\n case 'search':\n let searchResultEvent = new EventResponse<SearchResult[]>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n this.eventEmitter.emit('search', message.args, searchResultEvent);\n const searchResult =\n await this.waitForEventToRespond(searchResultEvent);\n this.respondToMessage(message.id!!, searchResult.data);\n break;\n case 'setup':\n let setupEvent = new EventResponse<LibraryInfo>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n this.eventEmitter.emit(\n 'setup',\n {\n path: message.args.path,\n appID: message.args.appID,\n storefront: message.args.storefront,\n type: message.args.type,\n name: message.args.name,\n usedRealDebrid: message.args.usedRealDebrid,\n multiPartFiles: message.args.multiPartFiles,\n },\n setupEvent\n );\n const interval = setInterval(() => {\n if (setupEvent.resolved) {\n clearInterval(interval);\n return;\n }\n this.send('defer-update', {\n logs: setupEvent.logs,\n deferID: message.args.deferID,\n progress: setupEvent.progress,\n failed: setupEvent.failed,\n } as ClientSentEventTypes['defer-update']);\n }, 100);\n const setupResult = await this.waitForEventToRespond(setupEvent);\n this.respondToMessage(message.id!!, setupResult.data);\n break;\n case 'library-search':\n let librarySearchEvent = new EventResponse<BasicLibraryInfo[]>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('game-details') === 0) {\n this.respondToMessage(message.id!!, []);\n break;\n }\n this.eventEmitter.emit(\n 'library-search',\n message.args,\n librarySearchEvent\n );\n const librarySearchResult =\n await this.waitForEventToRespond(librarySearchEvent);\n this.respondToMessage(message.id!!, librarySearchResult.data);\n break;\n case 'game-details':\n let gameDetailsEvent = new EventResponse<StoreData | undefined>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('game-details') === 0) {\n this.respondToMessage(message.id!!, {\n error: 'No event listener for game-details',\n });\n break;\n }\n this.eventEmitter.emit(\n 'game-details',\n message.args,\n gameDetailsEvent\n );\n const gameDetailsResult =\n await this.waitForEventToRespond(gameDetailsEvent);\n this.respondToMessage(message.id!!, gameDetailsResult.data);\n break;\n case 'request-dl':\n let requestDLEvent = new EventResponse<SearchResult>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('request-dl') === 0) {\n this.respondToMessage(message.id!!, {\n error: 'No event listener for request-dl',\n });\n break;\n }\n this.eventEmitter.emit(\n 'request-dl',\n message.args.appID,\n message.args.info,\n requestDLEvent\n );\n const requestDLResult =\n await this.waitForEventToRespond(requestDLEvent);\n if (requestDLEvent.failed) {\n this.respondToMessage(message.id!!, {\n statusError: requestDLEvent.failed,\n });\n break;\n }\n if (\n requestDLEvent.data === undefined ||\n requestDLEvent.data?.downloadType === 'request'\n ) {\n throw new Error(\n 'Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type.'\n );\n }\n this.respondToMessage(message.id!!, requestDLResult.data);\n break;\n case 'catalog':\n let catalogEvent = new EventResponse<{\n [key: string]: {\n name: string;\n description: string;\n listings: BasicLibraryInfo[];\n };\n }>();\n this.eventEmitter.emit('catalog', catalogEvent);\n const catalogResult = await this.waitForEventToRespond(catalogEvent);\n this.respondToMessage(message.id!!, catalogResult.data);\n break;\n }\n });\n }\n\n private waitForEventToRespond<T>(\n event: EventResponse<T>\n ): Promise<EventResponse<T>> {\n // check the handlers to see if there even is any\n return new Promise((resolve, reject) => {\n const dataGet = setInterval(() => {\n if (event.resolved) {\n resolve(event);\n clearTimeout(timeout);\n }\n }, 5);\n\n const timeout = setTimeout(() => {\n if (event.deffered) {\n clearInterval(dataGet);\n const interval = setInterval(() => {\n if (event.resolved) {\n clearInterval(interval);\n resolve(event);\n }\n }, 100);\n } else {\n reject('Event did not respond in time');\n }\n }, 5000);\n });\n }\n\n public respondToMessage(messageID: string, response: any) {\n this.socket.send(\n JSON.stringify({\n event: 'response',\n id: messageID,\n args: response,\n })\n );\n console.log('dispatched response to ' + messageID);\n }\n\n public waitForResponseFromServer<T>(messageID: string): Promise<T> {\n return new Promise((resolve) => {\n const waiter = (data: string) => {\n const message: WebsocketMessageClient = JSON.parse(data);\n if (message.event !== 'response') {\n this.socket.once('message', waiter);\n return;\n }\n console.log('received response from ' + messageID);\n\n if (message.id === messageID) {\n resolve(message.args);\n } else {\n this.socket.once('message', waiter);\n }\n };\n this.socket.once('message', waiter);\n });\n }\n\n public send(\n event: OGIAddonClientSentEvent,\n args: ClientSentEventTypes[OGIAddonClientSentEvent]\n ): string {\n // generate a random id\n const id = Math.random().toString(36).substring(7);\n this.socket.send(\n JSON.stringify({\n event,\n args,\n id,\n })\n );\n return id;\n }\n\n public close() {\n this.socket.close();\n }\n}\n","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","import {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n} from './ConfigurationBuilder';\n\ninterface DefiniteConfig {\n [key: string]: string | number | boolean;\n}\nexport class Configuration {\n readonly storedConfigTemplate: ConfigurationFile;\n definiteConfig: DefiniteConfig = {};\n constructor(configTemplate: ConfigurationFile) {\n this.storedConfigTemplate = configTemplate;\n }\n\n updateConfig(\n config: DefiniteConfig,\n validate: boolean = true\n ): [boolean, { [key: string]: string }] {\n this.definiteConfig = config;\n if (validate) {\n const result = this.validateConfig();\n return result;\n }\n return [true, {}];\n }\n // provides falsey or truthy value, and an error message if falsey\n private validateConfig(): [boolean, { [key: string]: string }] {\n const erroredKeys = new Map<string, string>();\n for (const key in this.storedConfigTemplate) {\n if (\n this.definiteConfig[key] === null ||\n this.definiteConfig[key] === undefined\n ) {\n console.warn(\n 'Option ' +\n key +\n ' is not defined. Using default value Value: ' +\n this.definiteConfig[key]\n );\n this.definiteConfig[key] = this.storedConfigTemplate[key]\n .defaultValue as string | number | boolean;\n }\n if (\n this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]\n ) {\n throw new Error('Option ' + key + ' is not of the correct type');\n }\n\n const result = this.storedConfigTemplate[key].validate(\n this.definiteConfig[key]\n );\n if (!result[0]) {\n erroredKeys.set(key, result[1]);\n }\n }\n\n for (const key in this.definiteConfig) {\n if (!this.storedConfigTemplate[key]) {\n throw new Error(\n 'Option ' + key + ' is not defined in the configuration template'\n );\n }\n }\n\n if (erroredKeys.size > 0) {\n return [false, Object.fromEntries(erroredKeys)];\n }\n\n return [true, Object.fromEntries(erroredKeys)];\n }\n\n getStringValue(optionName: string): string {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'string') {\n throw new Error('Option ' + optionName + ' is not a string');\n }\n return this.definiteConfig[optionName];\n }\n\n getNumberValue(optionName: string): number {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'number') {\n throw new Error('Option ' + optionName + ' is not a number');\n }\n return this.definiteConfig[optionName];\n }\n\n getBooleanValue(optionName: string): boolean {\n if (this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\n throw new Error('Option ' + optionName + ' is not a boolean');\n }\n return this.definiteConfig[optionName];\n }\n}\n\nexport {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n};\n","import { ConfigurationBuilder } from './main';\n\nexport default class EventResponse<T> {\n data: T | undefined = undefined;\n deffered: boolean = false;\n resolved: boolean = false;\n progress: number = 0;\n logs: string[] = [];\n failed: string | undefined = undefined;\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>;\n\n constructor(\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>\n ) {\n this.onInputAsked = onInputAsked;\n }\n\n public defer(promise?: () => Promise<void>) {\n this.deffered = true;\n // include this to make it easier to use the defer method with async functions\n if (promise) {\n promise();\n }\n }\n\n /**\n * 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.**\n * @param data {T}\n */\n public resolve(data: T) {\n this.resolved = true;\n this.data = data;\n }\n\n /**\n * 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.**\n */\n public complete() {\n this.resolved = true;\n }\n\n public fail(message: string) {\n this.resolved = true;\n this.failed = message;\n }\n\n /**\n * Logs a message to the event. This is useful for debugging and logging information to the user.\n * @param message {string}\n */\n public log(message: string) {\n this.logs.push(message);\n }\n\n /**\n * 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.\n * @async\n * @param name {string}\n * @param description {string}\n * @param screen {ConfigurationBuilder}\n * @returns {Promise<{ [key: string]: boolean | string | number }>}\n */\n public async askForInput(\n name: string,\n description: string,\n screen: ConfigurationBuilder\n ): Promise<{ [key: string]: boolean | string | number }> {\n if (!this.onInputAsked) {\n throw new Error('No input asked callback');\n }\n return await this.onInputAsked(screen, name, description);\n }\n}\n","{\n \"name\": \"ogi-addon\",\n \"module\": \"./build/main.js\",\n \"type\": \"module\",\n \"main\": \"./build/main.cjs\",\n \"version\": \"1.5.1\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"default\": \"./build/main.js\",\n \"types\": \"./build/main.d.ts\"\n },\n \"require\": {\n \"default\": \"./build/main.cjs\",\n \"types\": \"./build/main.d.cts\"\n }\n },\n \"./config\": {\n \"import\": {\n \"default\": \"./build/config/Configuration.js\",\n \"types\": \"./build/config/Configuration.d.ts\"\n },\n \"require\": {\n \"default\": \"./build/config/Configuration.cjs\",\n \"types\": \"./build/config/Configuration.d.cts\"\n }\n }\n },\n \"typings\": \"./build/main.d.ts\",\n \"author\": {\n \"name\": \"Nat3z\",\n \"email\": \"me@nat3z.com\",\n \"url\": \"https://nat3z.com/\"\n },\n \"dependencies\": {\n \"fuse.js\": \"^7.1.0\",\n \"ws\": \"^8.4.0\",\n \"zod\": \"^3.23.8\"\n },\n \"scripts\": {\n \"auto-build\": \"tsc -w\",\n \"build\": \"tsup --config tsup.config.js\",\n \"release\": \"bun run build && npm publish\",\n \"release-beta\": \"bun run build && npm publish --tag future\"\n },\n \"devDependencies\": {\n \"@types/minimatch\": \"^6.0.0\",\n \"@types/node\": \"^20.14.12\",\n \"@types/ws\": \"^8.4.0\",\n \"prettier\": \"^3.6.0\",\n \"tsup\": \"^8.2.3\",\n \"typescript\": \"^5.0.0\"\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA8B;AAC9B,yBAAmB;;;ACDnB,iBAA4B;AAM5B,IAAM,mBAAmB,WAAAA,QAAE,OAAO;AAAA,EAChC,MAAM,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAoBM,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAA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AAK,WAAW,MAAM;AAClC;AAAA,QACF;AACA,gBAAQ,IAAI,4BAA4B,SAAS;AAEjD,YAAI,QAAQ,OAAO,WAAW;AAC5B,kBAAQ,QAAQ,IAAI;AAAA,QACtB,OAAO;AACL,eAAK,OAAO,KAAK,WAAW,MAAM;AAAA,QACpC;AAAA,MACF;AACA,WAAK,OAAO,KAAK,WAAW,MAAM;AAAA,IACpC,CAAC;AAAA,EACH;AAAA,EAEO,KACL,OACA,MACQ;AAER,UAAM,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC;AACjD,SAAK,OAAO;AAAA,MACV,KAAK,UAAU;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAAA,EAEO,QAAQ;AACb,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;","names":["z","events","ws","Fuse"]}
1
+ {"version":3,"sources":["../src/main.ts","../src/config/ConfigurationBuilder.ts","../src/config/Configuration.ts","../src/EventResponse.ts","../package.json"],"sourcesContent":["import ws, { WebSocket } from 'ws';\nimport events from 'node:events';\nimport {\n ConfigurationBuilder,\n ConfigurationFile,\n} from './config/ConfigurationBuilder';\nimport { Configuration } from './config/Configuration';\nimport EventResponse from './EventResponse';\nimport { SearchResult } from './SearchEngine';\nimport Fuse, { IFuseOptions } from 'fuse.js';\n\nexport type OGIAddonEvent =\n | 'connect'\n | 'disconnect'\n | 'configure'\n | 'authenticate'\n | 'search'\n | 'setup'\n | 'library-search'\n | 'game-details'\n | 'exit'\n | 'task-run'\n | 'request-dl'\n | 'catalog';\n\nexport type OGIAddonClientSentEvent =\n | 'response'\n | 'authenticate'\n | 'configure'\n | 'defer-update'\n | 'notification'\n | 'input-asked'\n | 'get-app-details'\n | 'flag'\n | 'task-update';\n\nexport type OGIAddonServerSentEvent =\n | 'authenticate'\n | 'configure'\n | 'config-update'\n | 'search'\n | 'setup'\n | 'response'\n | 'library-search'\n | 'task-run'\n | 'game-details'\n | 'request-dl'\n | 'catalog';\nexport { ConfigurationBuilder, Configuration, EventResponse, SearchResult };\nconst defaultPort = 7654;\nimport pjson from '../package.json';\nexport const VERSION = pjson.version;\n\nexport interface ClientSentEventTypes {\n response: any;\n authenticate: {\n name: string;\n id: string;\n description: string;\n version: string;\n author: string;\n };\n configure: ConfigurationFile;\n 'defer-update': {\n logs: string[];\n progress: number;\n };\n notification: Notification;\n 'input-asked': ConfigurationBuilder;\n 'task-update': {\n id: string;\n progress: number;\n logs: string[];\n finished: boolean;\n failed: string | undefined;\n };\n 'get-app-details': {\n appID: number;\n storefront: string;\n };\n flag: {\n flag: string;\n value: string | string[];\n };\n}\n\nexport type BasicLibraryInfo = {\n name: string;\n capsuleImage: string;\n appID: number;\n storefront: string;\n};\n\nexport type SetupEventResponse = Omit<\n LibraryInfo,\n | 'capsuleImage'\n | 'coverImage'\n | 'name'\n | 'appID'\n | 'storefront'\n | 'addonsource'\n | 'titleImage'\n> & {\n redistributables?: {\n name: string;\n path: string;\n }[];\n};\nexport interface EventListenerTypes {\n /**\n * This event is emitted when the addon connects to the OGI Addon Server. Addon does not need to resolve anything.\n * @param socket\n * @returns\n */\n connect: (socket: ws) => void;\n\n /**\n * This event is emitted when the client requests for the addon to disconnect. Addon does not need to resolve this event, but we recommend `process.exit(0)` so the addon can exit gracefully instead of by force by the addon server.\n * @param reason\n * @returns\n */\n disconnect: (reason: string) => void;\n /**\n * This event is emitted when the client requests for the addon to configure itself. Addon should resolve the event with the internal configuration. (See ConfigurationBuilder)\n * @param config\n * @returns\n */\n configure: (config: ConfigurationBuilder) => ConfigurationBuilder;\n /**\n * This event is called when the client provides a response to any event. This should be treated as middleware.\n * @param response\n * @returns\n */\n response: (response: any) => void;\n\n /**\n * This event is called when the client requests for the addon to authenticate itself. You don't need to provide any info.\n * @param config\n * @returns\n */\n authenticate: (config: any) => void;\n /**\n * This event is emitted when the client requests for a torrent/direct download search to be performed. Addon is given the gameID (could be a steam appID or custom store appID), along with the storefront type. Addon should resolve the event with the search results. (See SearchResult)\n * @param query\n * @param event\n * @returns\n */\n search: (\n query: { storefront: string; appID: number },\n event: EventResponse<SearchResult[]>\n ) => void;\n /**\n * This event is emitted when the client requests for app setup to be performed. Addon should resolve the event with the metadata for the library entry. (See LibraryInfo)\n * @param data\n * @param event\n * @returns\n */\n setup: (\n data: {\n path: string;\n type: 'direct' | 'torrent' | 'magnet';\n name: string;\n usedRealDebrid: boolean;\n multiPartFiles?: {\n name: string;\n downloadURL: string;\n }[];\n appID: number;\n storefront: string;\n manifest?: Record<string, unknown>;\n },\n event: EventResponse<SetupEventResponse>\n ) => void;\n\n /**\n * This event is emitted when the client requires for a search to be performed. Input is the search query.\n * @param query\n * @param event\n * @returns\n */\n 'library-search': (\n query: string,\n event: EventResponse<BasicLibraryInfo[]>\n ) => void;\n\n /**\n * This event is emitted when the client requests for a task to be run. Addon should resolve the event with the task.\n * @param task\n * @param event\n * @returns\n */\n 'task-run': (\n task: {\n manifest: Record<string, unknown>;\n downloadPath: string;\n name: string;\n },\n event: EventResponse<void>\n ) => void;\n\n /**\n * This event is emitted when the client requests for a game details to be fetched. Addon should resolve the event with the game details. This is used to generate a store page for the game.\n * @param appID\n * @param event\n * @returns\n */\n 'game-details': (\n details: { appID: number; storefront: string },\n event: EventResponse<StoreData | undefined>\n ) => void;\n\n /**\n * This event is emitted when the client requests for the addon to exit. Use this to perform any cleanup tasks, ending with a `process.exit(0)`.\n * @returns\n */\n exit: () => void;\n\n /**\n * This event is emitted when the client requests for a download to be performed with the 'request' type. Addon should resolve the event with a SearchResult containing the actual download info.\n * @param appID\n * @param info\n * @param event\n * @returns\n */\n 'request-dl': (\n appID: number,\n info: SearchResult,\n event: EventResponse<SearchResult>\n ) => void;\n\n /**\n * This event is emitted when the client requests for a catalog to be fetched. Addon should resolve the event with the catalog.\n * @param event\n * @returns\n */\n catalog: (\n event: Omit<\n EventResponse<{\n [key: string]: {\n name: string;\n description: string;\n listings: BasicLibraryInfo[];\n };\n }>,\n 'askForInput'\n >\n ) => void;\n}\n\nexport interface StoreData {\n name: string;\n publishers: string[];\n developers: string[];\n appID: number;\n releaseDate: string;\n capsuleImage: string;\n coverImage: string;\n basicDescription: string;\n description: string;\n headerImage: string;\n}\nexport interface WebsocketMessageClient {\n event: OGIAddonClientSentEvent;\n id?: string;\n args: any;\n statusError?: string;\n}\nexport interface WebsocketMessageServer {\n event: OGIAddonServerSentEvent;\n id?: string;\n args: any;\n statusError?: string;\n}\n\n/**\n * The configuration for the addon. This is used to identify the addon and provide information about it.\n * Storefronts is an array of names of stores that the addon supports.\n */\nexport interface OGIAddonConfiguration {\n name: string;\n id: string;\n description: string;\n version: string;\n\n author: string;\n repository: string;\n storefronts: string[];\n}\n\n/**\n * The main class for the OGI Addon. This class is used to interact with the OGI Addon Server. The OGI Addon Server provides a `--addonSecret` to the addon so it can securely connect.\n * @example\n * ```typescript\n * const addon = new OGIAddon({\n * name: 'Test Addon',\n * id: 'test-addon',\n * description: 'A test addon',\n * version: '1.0.0',\n * author: 'OGI Developers',\n * repository: ''\n * });\n * ```\n *\n */\nexport default class OGIAddon {\n public eventEmitter = new events.EventEmitter();\n public addonWSListener: OGIAddonWSListener;\n public addonInfo: OGIAddonConfiguration;\n public config: Configuration = new Configuration({});\n private eventsAvailable: OGIAddonEvent[] = [];\n private registeredConnectEvent: boolean = false;\n\n constructor(addonInfo: OGIAddonConfiguration) {\n this.addonInfo = addonInfo;\n this.addonWSListener = new OGIAddonWSListener(this, this.eventEmitter);\n }\n\n /**\n * Register an event listener for the addon. (See EventListenerTypes)\n * @param event {OGIAddonEvent}\n * @param listener {EventListenerTypes[OGIAddonEvent]}\n */\n public on<T extends OGIAddonEvent>(\n event: T,\n listener: EventListenerTypes[T]\n ) {\n this.eventEmitter.on(event, listener);\n this.eventsAvailable.push(event);\n // wait for the addon to be connected\n if (!this.registeredConnectEvent) {\n this.addonWSListener.eventEmitter.once('connect', () => {\n this.addonWSListener.send('flag', {\n flag: 'events-available',\n value: this.eventsAvailable,\n });\n });\n this.registeredConnectEvent = true;\n }\n }\n\n public emit<T extends OGIAddonEvent>(\n event: T,\n ...args: Parameters<EventListenerTypes[T]>\n ) {\n this.eventEmitter.emit(event, ...args);\n }\n\n /**\n * Notify the client using a notification. Provide the type of notification, the message, and an ID.\n * @param notification {Notification}\n */\n public notify(notification: Notification) {\n this.addonWSListener.send('notification', [notification]);\n }\n\n /**\n * Get the app details for a given appID and storefront.\n * @param appID {number}\n * @param storefront {string}\n * @returns {Promise<StoreData>}\n */\n public async getAppDetails(appID: number, storefront: string) {\n const id = this.addonWSListener.send('get-app-details', {\n appID,\n storefront,\n });\n return await this.addonWSListener.waitForResponseFromServer<\n StoreData | undefined\n >(id);\n }\n\n /**\n * Notify the OGI Addon Server that you are performing a background task. This can be used to help users understand what is happening in the background.\n * @param id {string}\n * @param progress {number}\n * @param logs {string[]}\n */\n public async task() {\n const id = Math.random().toString(36).substring(7);\n const progress = 0;\n const logs: string[] = [];\n const task = new CustomTask(this.addonWSListener, id, progress, logs);\n this.addonWSListener.send('task-update', {\n id,\n progress,\n logs,\n finished: false,\n failed: undefined,\n });\n return task;\n }\n}\n\nexport class CustomTask {\n public readonly id: string;\n public progress: number;\n public logs: string[];\n public finished: boolean = false;\n public ws: OGIAddonWSListener;\n public failed: string | undefined = undefined;\n constructor(\n ws: OGIAddonWSListener,\n id: string,\n progress: number,\n logs: string[]\n ) {\n this.id = id;\n this.progress = progress;\n this.logs = logs;\n this.ws = ws;\n }\n public log(log: string) {\n this.logs.push(log);\n this.update();\n }\n public finish() {\n this.finished = true;\n this.update();\n }\n public fail(message: string) {\n this.failed = message;\n this.update();\n }\n public setProgress(progress: number) {\n this.progress = progress;\n this.update();\n }\n public update() {\n this.ws.send('task-update', {\n id: this.id,\n progress: this.progress,\n logs: this.logs,\n finished: this.finished,\n failed: this.failed,\n });\n }\n}\n/**\n * A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.\n * @example\n * ```typescript\n * const searchTool = new SearchTool<LibraryInfo>([{ name: 'test', appID: 123 }, { name: 'test2', appID: 124 }], ['name']);\n * const results = searchTool.search('test', 10);\n * ```\n */\nexport class SearchTool<T> {\n private fuse: Fuse<T>;\n constructor(\n items: T[],\n keys: string[],\n options: Omit<IFuseOptions<T>, 'keys'> = {\n threshold: 0.3,\n includeScore: true,\n }\n ) {\n this.fuse = new Fuse(items, {\n keys,\n ...options,\n });\n }\n public search(query: string, limit: number = 10): T[] {\n return this.fuse\n .search(query)\n .slice(0, limit)\n .map((result) => result.item);\n }\n public addItems(items: T[]) {\n items.map((item) => this.fuse.add(item));\n }\n}\n/**\n * Library Info is the metadata for a library entry after setting up a game.\n */\nexport interface LibraryInfo {\n name: string;\n version: string;\n cwd: string;\n appID: number;\n launchExecutable: string;\n launchArguments?: string;\n capsuleImage: string;\n storefront: string;\n addonsource: string;\n coverImage: string;\n titleImage?: string;\n}\ninterface Notification {\n type: 'warning' | 'error' | 'info' | 'success';\n message: string;\n id: string;\n}\nclass OGIAddonWSListener {\n private socket: WebSocket;\n public eventEmitter: events.EventEmitter;\n public addon: OGIAddon;\n\n constructor(ogiAddon: OGIAddon, eventEmitter: events.EventEmitter) {\n if (\n process.argv[process.argv.length - 1].split('=')[0] !== '--addonSecret'\n ) {\n throw new Error(\n 'No secret provided. This usually happens because the addon was not started by the OGI Addon Server.'\n );\n }\n this.addon = ogiAddon;\n this.eventEmitter = eventEmitter;\n this.socket = new ws('ws://localhost:' + defaultPort);\n this.socket.on('open', () => {\n console.log('Connected to OGI Addon Server');\n console.log('OGI Addon Server Version:', VERSION);\n\n // Authenticate with OGI Addon Server\n this.send('authenticate', {\n ...this.addon.addonInfo,\n secret: process.argv[process.argv.length - 1].split('=')[1],\n ogiVersion: VERSION,\n });\n\n this.eventEmitter.emit('connect');\n\n // send a configuration request\n let configBuilder = new ConfigurationBuilder();\n this.eventEmitter.emit('configure', configBuilder);\n this.send('configure', configBuilder.build(false));\n this.addon.config = new Configuration(configBuilder.build(true));\n });\n\n this.socket.on('error', (error) => {\n if (error.message.includes('Failed to connect')) {\n throw new Error(\n 'OGI Addon Server is not running/is unreachable. Please start the server and try again.'\n );\n }\n console.error('An error occurred:', error);\n });\n\n this.socket.on('close', (code, reason) => {\n if (code === 1008) {\n console.error('Authentication failed:', reason);\n return;\n }\n this.eventEmitter.emit('disconnect', reason);\n console.log('Disconnected from OGI Addon Server');\n console.error(reason.toString());\n this.eventEmitter.emit('exit');\n this.socket.close();\n });\n\n this.registerMessageReceiver();\n }\n\n private async userInputAsked(\n configBuilt: ConfigurationBuilder,\n name: string,\n description: string,\n socket: WebSocket\n ): Promise<{ [key: string]: number | boolean | string }> {\n const config = configBuilt.build(false);\n const id = Math.random().toString(36).substring(7);\n if (!socket) {\n return {};\n }\n socket.send(\n JSON.stringify({\n event: 'input-asked',\n args: {\n config,\n name,\n description,\n },\n id: id,\n })\n );\n return await this.waitForResponseFromServer(id);\n }\n\n private registerMessageReceiver() {\n this.socket.on('message', async (data: string) => {\n const message: WebsocketMessageServer = JSON.parse(data);\n switch (message.event) {\n case 'config-update':\n const result = this.addon.config.updateConfig(message.args);\n if (!result[0]) {\n this.respondToMessage(\n message.id!!,\n {\n success: false,\n error: result[1],\n },\n undefined\n );\n } else {\n this.respondToMessage(message.id!!, { success: true }, undefined);\n }\n break;\n case 'search':\n let searchResultEvent = new EventResponse<SearchResult[]>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n this.eventEmitter.emit('search', message.args, searchResultEvent);\n const searchResult =\n await this.waitForEventToRespond(searchResultEvent);\n this.respondToMessage(\n message.id!!,\n searchResult.data,\n searchResultEvent\n );\n break;\n case 'setup': {\n let setupEvent = new EventResponse<SetupEventResponse>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n this.eventEmitter.emit('setup', message.args, setupEvent);\n const interval = setInterval(() => {\n if (setupEvent.resolved) {\n clearInterval(interval);\n return;\n }\n this.send('defer-update', {\n logs: setupEvent.logs,\n deferID: message.args.deferID,\n progress: setupEvent.progress,\n failed: setupEvent.failed,\n } as ClientSentEventTypes['defer-update']);\n }, 100);\n const setupResult = await this.waitForEventToRespond(setupEvent);\n this.respondToMessage(message.id!!, setupResult.data, setupEvent);\n break;\n }\n case 'library-search':\n let librarySearchEvent = new EventResponse<BasicLibraryInfo[]>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('game-details') === 0) {\n this.respondToMessage(message.id!!, [], librarySearchEvent);\n break;\n }\n this.eventEmitter.emit(\n 'library-search',\n message.args,\n librarySearchEvent\n );\n const librarySearchResult =\n await this.waitForEventToRespond(librarySearchEvent);\n this.respondToMessage(\n message.id!!,\n librarySearchResult.data,\n librarySearchEvent\n );\n break;\n case 'game-details':\n let gameDetailsEvent = new EventResponse<StoreData | undefined>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('game-details') === 0) {\n this.respondToMessage(\n message.id!!,\n {\n error: 'No event listener for game-details',\n },\n gameDetailsEvent\n );\n break;\n }\n this.eventEmitter.emit(\n 'game-details',\n message.args,\n gameDetailsEvent\n );\n const gameDetailsResult =\n await this.waitForEventToRespond(gameDetailsEvent);\n this.respondToMessage(\n message.id!!,\n gameDetailsResult.data,\n gameDetailsEvent\n );\n break;\n case 'request-dl':\n let requestDLEvent = new EventResponse<SearchResult>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n if (this.eventEmitter.listenerCount('request-dl') === 0) {\n this.respondToMessage(\n message.id!!,\n {\n error: 'No event listener for request-dl',\n },\n requestDLEvent\n );\n break;\n }\n this.eventEmitter.emit(\n 'request-dl',\n message.args.appID,\n message.args.info,\n requestDLEvent\n );\n const requestDLResult =\n await this.waitForEventToRespond(requestDLEvent);\n if (requestDLEvent.failed) {\n this.respondToMessage(message.id!!, undefined, requestDLEvent);\n break;\n }\n if (\n requestDLEvent.data === undefined ||\n requestDLEvent.data?.downloadType === 'request'\n ) {\n throw new Error(\n 'Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type.'\n );\n }\n this.respondToMessage(\n message.id!!,\n requestDLResult.data,\n requestDLEvent\n );\n break;\n case 'catalog':\n let catalogEvent = new EventResponse<{\n [key: string]: {\n name: string;\n description: string;\n listings: BasicLibraryInfo[];\n };\n }>();\n this.eventEmitter.emit('catalog', catalogEvent);\n const catalogResult = await this.waitForEventToRespond(catalogEvent);\n this.respondToMessage(message.id!!, catalogResult.data, catalogEvent);\n break;\n case 'task-run': {\n let taskRunEvent = new EventResponse<void>(\n (screen, name, description) =>\n this.userInputAsked(screen, name, description, this.socket)\n );\n this.eventEmitter.emit('task-run', message.args, taskRunEvent);\n const interval = setInterval(() => {\n if (taskRunEvent.resolved) {\n clearInterval(interval);\n return;\n }\n this.send('defer-update', {\n logs: taskRunEvent.logs,\n deferID: message.args.deferID,\n progress: taskRunEvent.progress,\n failed: taskRunEvent.failed,\n } as ClientSentEventTypes['defer-update']);\n }, 100);\n const taskRunResult = await this.waitForEventToRespond(taskRunEvent);\n this.respondToMessage(message.id!!, taskRunResult.data, taskRunEvent);\n break;\n }\n }\n });\n }\n\n private waitForEventToRespond<T>(\n event: EventResponse<T>\n ): Promise<EventResponse<T>> {\n // check the handlers to see if there even is any\n return new Promise((resolve, reject) => {\n const dataGet = setInterval(() => {\n if (event.resolved) {\n resolve(event);\n clearTimeout(timeout);\n }\n }, 5);\n\n const timeout = setTimeout(() => {\n if (event.deffered) {\n clearInterval(dataGet);\n const interval = setInterval(() => {\n if (event.resolved) {\n clearInterval(interval);\n resolve(event);\n }\n }, 100);\n } else {\n reject('Event did not respond in time');\n }\n }, 5000);\n });\n }\n\n public respondToMessage(\n messageID: string,\n response: any,\n originalEvent: EventResponse<any> | undefined\n ) {\n this.socket.send(\n JSON.stringify({\n event: 'response',\n id: messageID,\n args: response,\n statusError: originalEvent ? originalEvent.failed : undefined,\n })\n );\n console.log('dispatched response to ' + messageID);\n }\n\n public waitForResponseFromServer<T>(messageID: string): Promise<T> {\n return new Promise((resolve) => {\n const waiter = (data: string) => {\n const message: WebsocketMessageClient = JSON.parse(data);\n if (message.event !== 'response') {\n this.socket.once('message', waiter);\n return;\n }\n console.log('received response from ' + messageID);\n\n if (message.id === messageID) {\n resolve(message.args);\n } else {\n this.socket.once('message', waiter);\n }\n };\n this.socket.once('message', waiter);\n });\n }\n\n public send(\n event: OGIAddonClientSentEvent,\n args: ClientSentEventTypes[OGIAddonClientSentEvent]\n ): string {\n // generate a random id\n const id = Math.random().toString(36).substring(7);\n this.socket.send(\n JSON.stringify({\n event,\n args,\n id,\n })\n );\n return id;\n }\n\n public close() {\n this.socket.close();\n }\n}\n","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","import {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n} from './ConfigurationBuilder';\n\ninterface DefiniteConfig {\n [key: string]: string | number | boolean;\n}\nexport class Configuration {\n readonly storedConfigTemplate: ConfigurationFile;\n definiteConfig: DefiniteConfig = {};\n constructor(configTemplate: ConfigurationFile) {\n this.storedConfigTemplate = configTemplate;\n }\n\n updateConfig(\n config: DefiniteConfig,\n validate: boolean = true\n ): [boolean, { [key: string]: string }] {\n this.definiteConfig = config;\n if (validate) {\n const result = this.validateConfig();\n return result;\n }\n return [true, {}];\n }\n // provides falsey or truthy value, and an error message if falsey\n private validateConfig(): [boolean, { [key: string]: string }] {\n const erroredKeys = new Map<string, string>();\n for (const key in this.storedConfigTemplate) {\n if (\n this.definiteConfig[key] === null ||\n this.definiteConfig[key] === undefined\n ) {\n console.warn(\n 'Option ' +\n key +\n ' is not defined. Using default value Value: ' +\n this.definiteConfig[key]\n );\n this.definiteConfig[key] = this.storedConfigTemplate[key]\n .defaultValue as string | number | boolean;\n }\n if (\n this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]\n ) {\n throw new Error('Option ' + key + ' is not of the correct type');\n }\n\n const result = this.storedConfigTemplate[key].validate(\n this.definiteConfig[key]\n );\n if (!result[0]) {\n erroredKeys.set(key, result[1]);\n }\n }\n\n for (const key in this.definiteConfig) {\n if (!this.storedConfigTemplate[key]) {\n throw new Error(\n 'Option ' + key + ' is not defined in the configuration template'\n );\n }\n }\n\n if (erroredKeys.size > 0) {\n return [false, Object.fromEntries(erroredKeys)];\n }\n\n return [true, Object.fromEntries(erroredKeys)];\n }\n\n getStringValue(optionName: string): string {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'string') {\n throw new Error('Option ' + optionName + ' is not a string');\n }\n return this.definiteConfig[optionName];\n }\n\n getNumberValue(optionName: string): number {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'number') {\n throw new Error('Option ' + optionName + ' is not a number');\n }\n return this.definiteConfig[optionName];\n }\n\n getBooleanValue(optionName: string): boolean {\n if (this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\n throw new Error('Option ' + optionName + ' is not a boolean');\n }\n return this.definiteConfig[optionName];\n }\n}\n\nexport {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n};\n","import { ConfigurationBuilder } from './main';\n\nexport default class EventResponse<T> {\n data: T | undefined = undefined;\n deffered: boolean = false;\n resolved: boolean = false;\n progress: number = 0;\n logs: string[] = [];\n failed: string | undefined = undefined;\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>;\n\n constructor(\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>\n ) {\n this.onInputAsked = onInputAsked;\n }\n\n public defer(promise?: () => Promise<void>) {\n this.deffered = true;\n // include this to make it easier to use the defer method with async functions\n if (promise) {\n promise();\n }\n }\n\n /**\n * 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.**\n * @param data {T}\n */\n public resolve(data: T) {\n this.resolved = true;\n this.data = data;\n }\n\n /**\n * 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.**\n */\n public complete() {\n this.resolved = true;\n }\n\n public fail(message: string) {\n this.resolved = true;\n this.failed = message;\n }\n\n /**\n * Logs a message to the event. This is useful for debugging and logging information to the user.\n * @param message {string}\n */\n public log(message: string) {\n this.logs.push(message);\n }\n\n /**\n * 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.\n * @async\n * @param name {string}\n * @param description {string}\n * @param screen {ConfigurationBuilder}\n * @returns {Promise<{ [key: string]: boolean | string | number }>}\n */\n public async askForInput(\n name: string,\n description: string,\n screen: ConfigurationBuilder\n ): Promise<{ [key: string]: boolean | string | number }> {\n if (!this.onInputAsked) {\n throw new Error('No input asked callback');\n }\n return await this.onInputAsked(screen, name, description);\n }\n}\n","{\n \"name\": \"ogi-addon\",\n \"module\": \"./build/main.js\",\n \"type\": \"module\",\n \"main\": \"./build/main.cjs\",\n \"version\": \"1.6.0\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"default\": \"./build/main.js\",\n \"types\": \"./build/main.d.ts\"\n },\n \"require\": {\n \"default\": \"./build/main.cjs\",\n \"types\": \"./build/main.d.cts\"\n }\n },\n \"./config\": {\n \"import\": {\n \"default\": \"./build/config/Configuration.js\",\n \"types\": \"./build/config/Configuration.d.ts\"\n },\n \"require\": {\n \"default\": \"./build/config/Configuration.cjs\",\n \"types\": \"./build/config/Configuration.d.cts\"\n }\n }\n },\n \"typings\": \"./build/main.d.ts\",\n \"author\": {\n \"name\": \"Nat3z\",\n \"email\": \"me@nat3z.com\",\n \"url\": \"https://nat3z.com/\"\n },\n \"dependencies\": {\n \"fuse.js\": \"^7.1.0\",\n \"ws\": \"^8.4.0\",\n \"zod\": \"^3.23.8\"\n },\n \"scripts\": {\n \"auto-build\": \"tsc -w\",\n \"build\": \"tsup --config tsup.config.js\",\n \"release\": \"bun run build && npm publish\",\n \"release-beta\": \"bun run build && npm publish --tag future\"\n },\n \"devDependencies\": {\n \"@types/minimatch\": \"^6.0.0\",\n \"@types/node\": \"^20.14.12\",\n \"@types/ws\": \"^8.4.0\",\n \"prettier\": \"^3.6.0\",\n \"tsup\": \"^8.2.3\",\n \"typescript\": \"^5.0.0\"\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA8B;AAC9B,yBAAmB;;;ACDnB,iBAA4B;AAM5B,IAAM,mBAAmB,WAAAA,QAAE,OAAO;AAAA,EAChC,MAAM,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAoBM,IAAM,uBAA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tB,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF,GAAG,GAAG;AAAA,QACR,OAAO;AACL,iBAAO,+BAA+B;AAAA,QACxC;AAAA,MACF,GAAG,GAAI;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EAEO,iBACL,WACA,UACA,eACA;AACA,SAAK,OAAO;AAAA,MACV,KAAK,UAAU;AAAA,QACb,OAAO;AAAA,QACP,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,aAAa,gBAAgB,cAAc,SAAS;AAAA,MACtD,CAAC;AAAA,IACH;AACA,YAAQ,IAAI,4BAA4B,SAAS;AAAA,EACnD;AAAA,EAEO,0BAA6B,WAA+B;AACjE,WAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,YAAM,SAAS,CAAC,SAAiB;AAC/B,cAAM,UAAkC,KAAK,MAAM,IAAI;AACvD,YAAI,QAAQ,UAAU,YAAY;AAChC,eAAK,OAAO,KAAK,WAAW,MAAM;AAClC;AAAA,QACF;AACA,gBAAQ,IAAI,4BAA4B,SAAS;AAEjD,YAAI,QAAQ,OAAO,WAAW;AAC5B,kBAAQ,QAAQ,IAAI;AAAA,QACtB,OAAO;AACL,eAAK,OAAO,KAAK,WAAW,MAAM;AAAA,QACpC;AAAA,MACF;AACA,WAAK,OAAO,KAAK,WAAW,MAAM;AAAA,IACpC,CAAC;AAAA,EACH;AAAA,EAEO,KACL,OACA,MACQ;AAER,UAAM,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC;AACjD,SAAK,OAAO;AAAA,MACV,KAAK,UAAU;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAAA,EAEO,QAAQ;AACb,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;","names":["z","events","ws","Fuse"]}
package/build/main.d.cts CHANGED
@@ -6,9 +6,9 @@ import EventResponse from './EventResponse.cjs';
6
6
  import { SearchResult } from './SearchEngine.cjs';
7
7
  import { IFuseOptions } from 'fuse.js';
8
8
 
9
- type OGIAddonEvent = 'connect' | 'disconnect' | 'configure' | 'authenticate' | 'search' | 'setup' | 'library-search' | 'game-details' | 'exit' | 'request-dl' | 'catalog';
9
+ type OGIAddonEvent = 'connect' | 'disconnect' | 'configure' | 'authenticate' | 'search' | 'setup' | 'library-search' | 'game-details' | 'exit' | 'task-run' | 'request-dl' | 'catalog';
10
10
  type OGIAddonClientSentEvent = 'response' | 'authenticate' | 'configure' | 'defer-update' | 'notification' | 'input-asked' | 'get-app-details' | 'flag' | 'task-update';
11
- type OGIAddonServerSentEvent = 'authenticate' | 'configure' | 'config-update' | 'search' | 'setup' | 'response' | 'library-search' | 'game-details' | 'request-dl' | 'catalog';
11
+ type OGIAddonServerSentEvent = 'authenticate' | 'configure' | 'config-update' | 'search' | 'setup' | 'response' | 'library-search' | 'task-run' | 'game-details' | 'request-dl' | 'catalog';
12
12
 
13
13
  declare const VERSION: string;
14
14
  interface ClientSentEventTypes {
@@ -49,6 +49,12 @@ type BasicLibraryInfo = {
49
49
  appID: number;
50
50
  storefront: string;
51
51
  };
52
+ type SetupEventResponse = Omit<LibraryInfo, 'capsuleImage' | 'coverImage' | 'name' | 'appID' | 'storefront' | 'addonsource' | 'titleImage'> & {
53
+ redistributables?: {
54
+ name: string;
55
+ path: string;
56
+ }[];
57
+ };
52
58
  interface EventListenerTypes {
53
59
  /**
54
60
  * This event is emitted when the addon connects to the OGI Addon Server. Addon does not need to resolve anything.
@@ -107,7 +113,8 @@ interface EventListenerTypes {
107
113
  }[];
108
114
  appID: number;
109
115
  storefront: string;
110
- }, event: EventResponse<Omit<LibraryInfo, 'capsuleImage' | 'coverImage' | 'name' | 'appID' | 'storefront' | 'addonsource' | 'titleImage'>>) => void;
116
+ manifest?: Record<string, unknown>;
117
+ }, event: EventResponse<SetupEventResponse>) => void;
111
118
  /**
112
119
  * This event is emitted when the client requires for a search to be performed. Input is the search query.
113
120
  * @param query
@@ -115,6 +122,17 @@ interface EventListenerTypes {
115
122
  * @returns
116
123
  */
117
124
  'library-search': (query: string, event: EventResponse<BasicLibraryInfo[]>) => void;
125
+ /**
126
+ * This event is emitted when the client requests for a task to be run. Addon should resolve the event with the task.
127
+ * @param task
128
+ * @param event
129
+ * @returns
130
+ */
131
+ 'task-run': (task: {
132
+ manifest: Record<string, unknown>;
133
+ downloadPath: string;
134
+ name: string;
135
+ }, event: EventResponse<void>) => void;
118
136
  /**
119
137
  * This event is emitted when the client requests for a game details to be fetched. Addon should resolve the event with the game details. This is used to generate a store page for the game.
120
138
  * @param appID
@@ -167,11 +185,13 @@ interface WebsocketMessageClient {
167
185
  event: OGIAddonClientSentEvent;
168
186
  id?: string;
169
187
  args: any;
188
+ statusError?: string;
170
189
  }
171
190
  interface WebsocketMessageServer {
172
191
  event: OGIAddonServerSentEvent;
173
192
  id?: string;
174
193
  args: any;
194
+ statusError?: string;
175
195
  }
176
196
  /**
177
197
  * The configuration for the addon. This is used to identify the addon and provide information about it.
@@ -293,10 +313,10 @@ declare class OGIAddonWSListener {
293
313
  private userInputAsked;
294
314
  private registerMessageReceiver;
295
315
  private waitForEventToRespond;
296
- respondToMessage(messageID: string, response: any): void;
316
+ respondToMessage(messageID: string, response: any, originalEvent: EventResponse<any> | undefined): void;
297
317
  waitForResponseFromServer<T>(messageID: string): Promise<T>;
298
318
  send(event: OGIAddonClientSentEvent, args: ClientSentEventTypes[OGIAddonClientSentEvent]): string;
299
319
  close(): void;
300
320
  }
301
321
 
302
- export { type BasicLibraryInfo, type ClientSentEventTypes, Configuration, ConfigurationBuilder, CustomTask, type EventListenerTypes, EventResponse, type LibraryInfo, type OGIAddonClientSentEvent, type OGIAddonConfiguration, type OGIAddonEvent, type OGIAddonServerSentEvent, SearchResult, SearchTool, type StoreData, VERSION, type WebsocketMessageClient, type WebsocketMessageServer, OGIAddon as default };
322
+ export { type BasicLibraryInfo, type ClientSentEventTypes, Configuration, ConfigurationBuilder, CustomTask, type EventListenerTypes, EventResponse, type LibraryInfo, type OGIAddonClientSentEvent, type OGIAddonConfiguration, type OGIAddonEvent, type OGIAddonServerSentEvent, SearchResult, SearchTool, type SetupEventResponse, type StoreData, VERSION, type WebsocketMessageClient, type WebsocketMessageServer, OGIAddon as default };