ogi-addon 2.0.0 → 2.2.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.
@@ -271,15 +271,13 @@ declare class OGIAddon {
271
271
  searchGame(query: string, storefront: string): Promise<BasicLibraryInfo[]>;
272
272
  /**
273
273
  * 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.
274
- * @param id {string}
275
- * @param progress {number}
276
- * @param logs {string[]}
274
+ * @returns {Promise<Task>} A Task instance for managing the background task.
277
275
  */
278
- task(): Promise<CustomTask>;
276
+ task(): Promise<Task>;
279
277
  /**
280
278
  * Register a task handler for a specific task name. The task name should match the taskName field in SearchResult or ActionOption.
281
279
  * @param taskName {string} The name of the task (should match taskName in SearchResult or ActionOption.setTaskName()).
282
- * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string }) => Promise<void> | void} The handler function.
280
+ * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string; libraryInfo: LibraryInfo }) => Promise<void> | void} The handler function.
283
281
  * @example
284
282
  * ```typescript
285
283
  * addon.onTask('clearCache', async (task) => {
@@ -295,6 +293,7 @@ declare class OGIAddon {
295
293
  manifest: Record<string, unknown>;
296
294
  downloadPath: string;
297
295
  name: string;
296
+ libraryInfo: LibraryInfo;
298
297
  }) => Promise<void> | void): void;
299
298
  /**
300
299
  * Check if a task handler is registered for the given task name.
@@ -311,6 +310,7 @@ declare class OGIAddon {
311
310
  manifest: Record<string, unknown>;
312
311
  downloadPath: string;
313
312
  name: string;
313
+ libraryInfo?: LibraryInfo;
314
314
  }) => Promise<void> | void) | undefined;
315
315
  /**
316
316
  * Extract a file using 7-Zip on Windows, unzip on Linux/Mac.
@@ -321,27 +321,32 @@ declare class OGIAddon {
321
321
  */
322
322
  extractFile(path: string, outputPath: string, type: 'unrar' | 'unzip'): Promise<void>;
323
323
  }
324
- declare class CustomTask {
325
- readonly id: string;
326
- progress: number;
327
- logs: string[];
328
- finished: boolean;
329
- ws: OGIAddonWSListener;
330
- failed: string | undefined;
331
- constructor(ws: OGIAddonWSListener, id: string, progress: number, logs: string[]);
332
- log(log: string): void;
333
- finish(): void;
334
- fail(message: string): void;
335
- setProgress(progress: number): void;
336
- update(): void;
337
- }
338
324
  /**
339
- * A cleaner API wrapper around EventResponse for task handlers.
325
+ * A unified task API for both server-initiated tasks (via onTask handlers)
326
+ * and addon-initiated background tasks (via addon.task()).
340
327
  * Provides chainable methods for logging, progress updates, and completion.
341
328
  */
342
329
  declare class Task {
343
330
  private event;
331
+ private ws;
332
+ private readonly id;
333
+ private progress;
334
+ private logs;
335
+ private finished;
336
+ private failed;
337
+ /**
338
+ * Construct a Task from an EventResponse (for onTask handlers).
339
+ * @param event {EventResponse<void>} The event response to wrap.
340
+ */
344
341
  constructor(event: EventResponse<void>);
342
+ /**
343
+ * Construct a Task from WebSocket listener (for addon.task()).
344
+ * @param ws {OGIAddonWSListener} The WebSocket listener.
345
+ * @param id {string} The task ID.
346
+ * @param progress {number} Initial progress (0-100).
347
+ * @param logs {string[]} Initial logs array.
348
+ */
349
+ constructor(ws: OGIAddonWSListener, id: string, progress: number, logs: string[]);
345
350
  /**
346
351
  * Log a message to the task. Returns this for chaining.
347
352
  * @param message {string} The message to log.
@@ -363,13 +368,20 @@ declare class Task {
363
368
  fail(message: string): void;
364
369
  /**
365
370
  * Ask the user for input using a ConfigurationBuilder screen.
371
+ * Only available for EventResponse-based tasks (onTask handlers).
366
372
  * The return type is inferred from the ConfigurationBuilder's accumulated option types.
367
373
  * @param name {string} The name/title of the input prompt.
368
374
  * @param description {string} The description of what input is needed.
369
375
  * @param screen {ConfigurationBuilder<U>} The configuration builder for the input form.
370
376
  * @returns {Promise<U>} The user's input with types matching the configuration options.
377
+ * @throws {Error} If called on a WebSocket-based task.
371
378
  */
372
379
  askForInput<U extends Record<string, string | number | boolean>>(name: string, description: string, screen: ConfigurationBuilder<U>): Promise<U>;
380
+ /**
381
+ * Update the task state (for WebSocket-based tasks only).
382
+ * Called automatically when using log(), setProgress(), complete(), or fail().
383
+ */
384
+ private update;
373
385
  }
374
386
  /**
375
387
  * A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.
@@ -483,5 +495,5 @@ declare class EventResponse<T> {
483
495
  askForInput<U extends Record<string, string | number | boolean>>(name: string, description: string, screen: ConfigurationBuilder<U>): Promise<U>;
484
496
  }
485
497
  //#endregion
486
- export { WebsocketMessageClient as _, EventListenerTypes as a, OGIAddonClientSentEvent as c, OGIAddonServerSentEvent as d, SearchTool as f, VERSION as g, Task as h, CustomTask as i, OGIAddonConfiguration as l, StoreData as m, BasicLibraryInfo as n, LibraryInfo as o, SetupEventResponse as p, ClientSentEventTypes as r, OGIAddon as s, EventResponse as t, OGIAddonEvent as u, WebsocketMessageServer as v, ZodLibraryInfo as y };
487
- //# sourceMappingURL=EventResponse-D0TZjAVC.d.mts.map
498
+ export { WebsocketMessageServer as _, LibraryInfo as a, OGIAddonConfiguration as c, SearchTool as d, SetupEventResponse as f, WebsocketMessageClient as g, VERSION as h, EventListenerTypes as i, OGIAddonEvent as l, Task as m, BasicLibraryInfo as n, OGIAddon as o, StoreData as p, ClientSentEventTypes as r, OGIAddonClientSentEvent as s, EventResponse as t, OGIAddonServerSentEvent as u, ZodLibraryInfo as v };
499
+ //# sourceMappingURL=EventResponse-BJ8gWjdT.d.mts.map
@@ -271,15 +271,13 @@ declare class OGIAddon {
271
271
  searchGame(query: string, storefront: string): Promise<BasicLibraryInfo[]>;
272
272
  /**
273
273
  * 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.
274
- * @param id {string}
275
- * @param progress {number}
276
- * @param logs {string[]}
274
+ * @returns {Promise<Task>} A Task instance for managing the background task.
277
275
  */
278
- task(): Promise<CustomTask>;
276
+ task(): Promise<Task>;
279
277
  /**
280
278
  * Register a task handler for a specific task name. The task name should match the taskName field in SearchResult or ActionOption.
281
279
  * @param taskName {string} The name of the task (should match taskName in SearchResult or ActionOption.setTaskName()).
282
- * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string }) => Promise<void> | void} The handler function.
280
+ * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string; libraryInfo: LibraryInfo }) => Promise<void> | void} The handler function.
283
281
  * @example
284
282
  * ```typescript
285
283
  * addon.onTask('clearCache', async (task) => {
@@ -295,6 +293,7 @@ declare class OGIAddon {
295
293
  manifest: Record<string, unknown>;
296
294
  downloadPath: string;
297
295
  name: string;
296
+ libraryInfo: LibraryInfo;
298
297
  }) => Promise<void> | void): void;
299
298
  /**
300
299
  * Check if a task handler is registered for the given task name.
@@ -311,6 +310,7 @@ declare class OGIAddon {
311
310
  manifest: Record<string, unknown>;
312
311
  downloadPath: string;
313
312
  name: string;
313
+ libraryInfo?: LibraryInfo;
314
314
  }) => Promise<void> | void) | undefined;
315
315
  /**
316
316
  * Extract a file using 7-Zip on Windows, unzip on Linux/Mac.
@@ -321,27 +321,32 @@ declare class OGIAddon {
321
321
  */
322
322
  extractFile(path: string, outputPath: string, type: 'unrar' | 'unzip'): Promise<void>;
323
323
  }
324
- declare class CustomTask {
325
- readonly id: string;
326
- progress: number;
327
- logs: string[];
328
- finished: boolean;
329
- ws: OGIAddonWSListener;
330
- failed: string | undefined;
331
- constructor(ws: OGIAddonWSListener, id: string, progress: number, logs: string[]);
332
- log(log: string): void;
333
- finish(): void;
334
- fail(message: string): void;
335
- setProgress(progress: number): void;
336
- update(): void;
337
- }
338
324
  /**
339
- * A cleaner API wrapper around EventResponse for task handlers.
325
+ * A unified task API for both server-initiated tasks (via onTask handlers)
326
+ * and addon-initiated background tasks (via addon.task()).
340
327
  * Provides chainable methods for logging, progress updates, and completion.
341
328
  */
342
329
  declare class Task {
343
330
  private event;
331
+ private ws;
332
+ private readonly id;
333
+ private progress;
334
+ private logs;
335
+ private finished;
336
+ private failed;
337
+ /**
338
+ * Construct a Task from an EventResponse (for onTask handlers).
339
+ * @param event {EventResponse<void>} The event response to wrap.
340
+ */
344
341
  constructor(event: EventResponse<void>);
342
+ /**
343
+ * Construct a Task from WebSocket listener (for addon.task()).
344
+ * @param ws {OGIAddonWSListener} The WebSocket listener.
345
+ * @param id {string} The task ID.
346
+ * @param progress {number} Initial progress (0-100).
347
+ * @param logs {string[]} Initial logs array.
348
+ */
349
+ constructor(ws: OGIAddonWSListener, id: string, progress: number, logs: string[]);
345
350
  /**
346
351
  * Log a message to the task. Returns this for chaining.
347
352
  * @param message {string} The message to log.
@@ -363,13 +368,20 @@ declare class Task {
363
368
  fail(message: string): void;
364
369
  /**
365
370
  * Ask the user for input using a ConfigurationBuilder screen.
371
+ * Only available for EventResponse-based tasks (onTask handlers).
366
372
  * The return type is inferred from the ConfigurationBuilder's accumulated option types.
367
373
  * @param name {string} The name/title of the input prompt.
368
374
  * @param description {string} The description of what input is needed.
369
375
  * @param screen {ConfigurationBuilder<U>} The configuration builder for the input form.
370
376
  * @returns {Promise<U>} The user's input with types matching the configuration options.
377
+ * @throws {Error} If called on a WebSocket-based task.
371
378
  */
372
379
  askForInput<U extends Record<string, string | number | boolean>>(name: string, description: string, screen: ConfigurationBuilder<U>): Promise<U>;
380
+ /**
381
+ * Update the task state (for WebSocket-based tasks only).
382
+ * Called automatically when using log(), setProgress(), complete(), or fail().
383
+ */
384
+ private update;
373
385
  }
374
386
  /**
375
387
  * A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.
@@ -483,5 +495,5 @@ declare class EventResponse<T> {
483
495
  askForInput<U extends Record<string, string | number | boolean>>(name: string, description: string, screen: ConfigurationBuilder<U>): Promise<U>;
484
496
  }
485
497
  //#endregion
486
- export { WebsocketMessageClient as _, EventListenerTypes as a, OGIAddonClientSentEvent as c, OGIAddonServerSentEvent as d, SearchTool as f, VERSION as g, Task as h, CustomTask as i, OGIAddonConfiguration as l, StoreData as m, BasicLibraryInfo as n, LibraryInfo as o, SetupEventResponse as p, ClientSentEventTypes as r, OGIAddon as s, EventResponse as t, OGIAddonEvent as u, WebsocketMessageServer as v, ZodLibraryInfo as y };
487
- //# sourceMappingURL=EventResponse-DgSuJPu8.d.cts.map
498
+ export { WebsocketMessageServer as _, LibraryInfo as a, OGIAddonConfiguration as c, SearchTool as d, SetupEventResponse as f, WebsocketMessageClient as g, VERSION as h, EventListenerTypes as i, OGIAddonEvent as l, Task as m, BasicLibraryInfo as n, OGIAddon as o, StoreData as p, ClientSentEventTypes as r, OGIAddonClientSentEvent as s, EventResponse as t, OGIAddonServerSentEvent as u, ZodLibraryInfo as v };
499
+ //# sourceMappingURL=EventResponse-DrBsB9tW.d.cts.map
@@ -1,2 +1,2 @@
1
- import { t as EventResponse } from "./EventResponse-DgSuJPu8.cjs";
1
+ import { t as EventResponse } from "./EventResponse-DrBsB9tW.cjs";
2
2
  export = EventResponse;
@@ -1,2 +1,2 @@
1
- import { t as EventResponse } from "./EventResponse-D0TZjAVC.mjs";
1
+ import { t as EventResponse } from "./EventResponse-BJ8gWjdT.mjs";
2
2
  export { EventResponse as default };
package/build/main.cjs CHANGED
@@ -14,7 +14,7 @@ let node_fs = require("node:fs");
14
14
  node_fs = require_ConfigurationBuilder.__toESM(node_fs);
15
15
 
16
16
  //#region package.json
17
- var version = "2.0.0";
17
+ var version = "2.2.0";
18
18
 
19
19
  //#endregion
20
20
  //#region src/main.ts
@@ -97,15 +97,13 @@ var OGIAddon = class {
97
97
  }
98
98
  /**
99
99
  * 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.
100
- * @param id {string}
101
- * @param progress {number}
102
- * @param logs {string[]}
100
+ * @returns {Promise<Task>} A Task instance for managing the background task.
103
101
  */
104
102
  async task() {
105
103
  const id = Math.random().toString(36).substring(7);
106
104
  const progress = 0;
107
105
  const logs = [];
108
- const task = new CustomTask(this.addonWSListener, id, progress, logs);
106
+ const task = new Task(this.addonWSListener, id, progress, logs);
109
107
  this.addonWSListener.send("task-update", {
110
108
  id,
111
109
  progress,
@@ -118,7 +116,7 @@ var OGIAddon = class {
118
116
  /**
119
117
  * Register a task handler for a specific task name. The task name should match the taskName field in SearchResult or ActionOption.
120
118
  * @param taskName {string} The name of the task (should match taskName in SearchResult or ActionOption.setTaskName()).
121
- * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string }) => Promise<void> | void} The handler function.
119
+ * @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string; libraryInfo: LibraryInfo }) => Promise<void> | void} The handler function.
122
120
  * @example
123
121
  * ```typescript
124
122
  * addon.onTask('clearCache', async (task) => {
@@ -232,61 +230,40 @@ var OGIAddon = class {
232
230
  });
233
231
  }
234
232
  };
235
- var CustomTask = class {
236
- id;
237
- progress;
238
- logs;
239
- finished = false;
240
- ws;
241
- failed = void 0;
242
- constructor(ws$2, id, progress, logs) {
243
- this.id = id;
244
- this.progress = progress;
245
- this.logs = logs;
246
- this.ws = ws$2;
247
- }
248
- log(log) {
249
- this.logs.push(log);
250
- this.update();
251
- }
252
- finish() {
253
- this.finished = true;
254
- this.update();
255
- }
256
- fail(message) {
257
- this.failed = message;
258
- this.update();
259
- }
260
- setProgress(progress) {
261
- this.progress = progress;
262
- this.update();
263
- }
264
- update() {
265
- this.ws.send("task-update", {
266
- id: this.id,
267
- progress: this.progress,
268
- logs: this.logs,
269
- finished: this.finished,
270
- failed: this.failed
271
- });
272
- }
273
- };
274
233
  /**
275
- * A cleaner API wrapper around EventResponse for task handlers.
234
+ * A unified task API for both server-initiated tasks (via onTask handlers)
235
+ * and addon-initiated background tasks (via addon.task()).
276
236
  * Provides chainable methods for logging, progress updates, and completion.
277
237
  */
278
238
  var Task = class {
279
239
  event;
280
- constructor(event) {
281
- this.event = event;
282
- this.event.defer();
240
+ ws;
241
+ id;
242
+ progress = 0;
243
+ logs = [];
244
+ finished = false;
245
+ failed = void 0;
246
+ constructor(eventOrWs, id, progress, logs) {
247
+ if (eventOrWs instanceof require_EventResponse) {
248
+ this.event = eventOrWs;
249
+ this.event.defer();
250
+ } else {
251
+ this.ws = eventOrWs;
252
+ this.id = id;
253
+ this.progress = progress ?? 0;
254
+ this.logs = logs ?? [];
255
+ }
283
256
  }
284
257
  /**
285
258
  * Log a message to the task. Returns this for chaining.
286
259
  * @param message {string} The message to log.
287
260
  */
288
261
  log(message) {
289
- this.event.log(message);
262
+ if (this.event) this.event.log(message);
263
+ else {
264
+ this.logs.push(message);
265
+ this.update();
266
+ }
290
267
  return this;
291
268
  }
292
269
  /**
@@ -294,33 +271,61 @@ var Task = class {
294
271
  * @param progress {number} The progress value (0-100).
295
272
  */
296
273
  setProgress(progress) {
297
- this.event.progress = progress;
274
+ if (this.event) this.event.progress = progress;
275
+ else {
276
+ this.progress = progress;
277
+ this.update();
278
+ }
298
279
  return this;
299
280
  }
300
281
  /**
301
282
  * Complete the task successfully.
302
283
  */
303
284
  complete() {
304
- this.event.complete();
285
+ if (this.event) this.event.complete();
286
+ else {
287
+ this.finished = true;
288
+ this.update();
289
+ }
305
290
  }
306
291
  /**
307
292
  * Fail the task with an error message.
308
293
  * @param message {string} The error message.
309
294
  */
310
295
  fail(message) {
311
- this.event.fail(message);
296
+ if (this.event) this.event.fail(message);
297
+ else {
298
+ this.failed = message;
299
+ this.update();
300
+ }
312
301
  }
313
302
  /**
314
303
  * Ask the user for input using a ConfigurationBuilder screen.
304
+ * Only available for EventResponse-based tasks (onTask handlers).
315
305
  * The return type is inferred from the ConfigurationBuilder's accumulated option types.
316
306
  * @param name {string} The name/title of the input prompt.
317
307
  * @param description {string} The description of what input is needed.
318
308
  * @param screen {ConfigurationBuilder<U>} The configuration builder for the input form.
319
309
  * @returns {Promise<U>} The user's input with types matching the configuration options.
310
+ * @throws {Error} If called on a WebSocket-based task.
320
311
  */
321
312
  async askForInput(name, description, screen) {
313
+ if (!this.event) throw new Error("askForInput() is only available for EventResponse-based tasks (onTask handlers)");
322
314
  return this.event.askForInput(name, description, screen);
323
315
  }
316
+ /**
317
+ * Update the task state (for WebSocket-based tasks only).
318
+ * Called automatically when using log(), setProgress(), complete(), or fail().
319
+ */
320
+ update() {
321
+ if (this.ws && this.id !== void 0) this.ws.send("task-update", {
322
+ id: this.id,
323
+ progress: this.progress,
324
+ logs: this.logs,
325
+ finished: this.finished,
326
+ failed: this.failed
327
+ });
328
+ }
324
329
  };
325
330
  /**
326
331
  * A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.
@@ -537,7 +542,8 @@ var OGIAddonWSListener = class {
537
542
  const result$1 = handler(task, {
538
543
  manifest: message.args.manifest || {},
539
544
  downloadPath: message.args.downloadPath || "",
540
- name: message.args.name || ""
545
+ name: message.args.name || "",
546
+ libraryInfo: message.args.libraryInfo
541
547
  });
542
548
  if (result$1 instanceof Promise) await result$1;
543
549
  clearInterval(interval);
@@ -614,7 +620,6 @@ var OGIAddonWSListener = class {
614
620
  //#endregion
615
621
  exports.Configuration = require_config_Configuration.Configuration;
616
622
  exports.ConfigurationBuilder = require_ConfigurationBuilder.ConfigurationBuilder;
617
- exports.CustomTask = CustomTask;
618
623
  exports.EventResponse = require_EventResponse;
619
624
  exports.SearchTool = SearchTool;
620
625
  exports.Task = Task;