ogi-addon 1.0.0 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,50 +1,51 @@
1
- {
2
- "name": "ogi-addon",
3
- "module": "./build/main.js",
4
- "type": "module",
5
- "main": "./build/main.cjs",
6
- "exports": {
7
- ".": {
8
- "import": {
9
- "default": "./build/main.js",
10
- "types": "./build/main.d.ts"
11
- },
12
- "require": {
13
- "default": "./build/main.cjs",
14
- "types": "./build/main.d.cts"
15
- }
16
- },
17
- "./config": {
18
- "import": {
19
- "default": "./build/config/Configuration.js",
20
- "types": "./build/config/Configuration.d.ts"
21
- },
22
- "require": {
23
- "default": "./build/config/Configuration.cjs",
24
- "types": "./build/config/Configuration.d.cts"
25
- }
26
- }
27
- },
28
- "typings": "./build/main.d.ts",
29
- "author": {
30
- "name": "Nat3z",
31
- "email": "me@nat3z.com",
32
- "url": "https://nat3z.com/"
33
- },
34
- "version": "1.0.0",
35
- "dependencies": {
36
- "ws": "^8.4.0",
37
- "zod": "^3.23.8"
38
- },
39
- "scripts": {
40
- "auto-build": "tsc -w",
41
- "build": "tsup --config tsup.config.js",
42
- "release": "bun run build && npm publish"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^20.14.12",
46
- "@types/ws": "^8.4.0",
47
- "tsup": "^8.2.3",
48
- "typescript": "^5.0.0"
49
- }
1
+ {
2
+ "name": "ogi-addon",
3
+ "module": "./build/main.js",
4
+ "type": "module",
5
+ "main": "./build/main.cjs",
6
+ "version": "1.1.5",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "default": "./build/main.js",
11
+ "types": "./build/main.d.ts"
12
+ },
13
+ "require": {
14
+ "default": "./build/main.cjs",
15
+ "types": "./build/main.d.cts"
16
+ }
17
+ },
18
+ "./config": {
19
+ "import": {
20
+ "default": "./build/config/Configuration.js",
21
+ "types": "./build/config/Configuration.d.ts"
22
+ },
23
+ "require": {
24
+ "default": "./build/config/Configuration.cjs",
25
+ "types": "./build/config/Configuration.d.cts"
26
+ }
27
+ }
28
+ },
29
+ "typings": "./build/main.d.ts",
30
+ "author": {
31
+ "name": "Nat3z",
32
+ "email": "me@nat3z.com",
33
+ "url": "https://nat3z.com/"
34
+ },
35
+ "dependencies": {
36
+ "fuse.js": "^7.1.0",
37
+ "ws": "^8.4.0",
38
+ "zod": "^3.23.8"
39
+ },
40
+ "scripts": {
41
+ "auto-build": "tsc -w",
42
+ "build": "tsup --config tsup.config.js",
43
+ "release": "bun run build && npm publish"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.14.12",
47
+ "@types/ws": "^8.4.0",
48
+ "tsup": "^8.2.3",
49
+ "typescript": "^5.0.0"
50
+ }
50
51
  }
package/schema.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "AddonFileConfigurationSchema",
4
- "type": "object",
5
- "properties": {
6
- "author": {
7
- "type": "string"
8
- },
9
- "scripts": {
10
- "type": "object",
11
- "properties": {
12
- "setup": {
13
- "type": "string"
14
- },
15
- "run": {
16
- "type": "string"
17
- },
18
- "preSetup": {
19
- "type": "string"
20
- },
21
- "postSetup": {
22
- "type": "string"
23
- }
24
- },
25
- "required": ["run"],
26
- "additionalProperties": false
27
- }
28
- },
29
- "required": ["author", "scripts"],
30
- "additionalProperties": false
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "AddonFileConfigurationSchema",
4
+ "type": "object",
5
+ "properties": {
6
+ "author": {
7
+ "type": "string"
8
+ },
9
+ "scripts": {
10
+ "type": "object",
11
+ "properties": {
12
+ "setup": {
13
+ "type": "string"
14
+ },
15
+ "run": {
16
+ "type": "string"
17
+ },
18
+ "preSetup": {
19
+ "type": "string"
20
+ },
21
+ "postSetup": {
22
+ "type": "string"
23
+ }
24
+ },
25
+ "required": ["run"],
26
+ "additionalProperties": false
27
+ }
28
+ },
29
+ "required": ["author", "scripts"],
30
+ "additionalProperties": false
31
31
  }
@@ -1,41 +1,60 @@
1
- import { ConfigurationBuilder } from "./main";
2
-
3
- export default class EventResponse<T> {
4
- data: T | undefined = undefined;
5
- deffered: boolean = false;
6
- resolved: boolean = false;
7
- progress: number = 0;
8
- logs: string[] = [];
9
- onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;
10
-
11
- constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {
12
- this.onInputAsked = onInputAsked;
13
- }
14
-
15
-
16
- public defer() {
17
- this.deffered = true;
18
- }
19
-
20
- public resolve(data: T) {
21
- this.resolved = true;
22
- this.data = data;
23
- }
24
-
25
- public complete() {
26
- this.resolved = true;
27
- }
28
-
29
- public log(message: string) {
30
- this.logs.push(message);
31
- }
32
-
33
- public async askForInput(name: string, description: string, screen: ConfigurationBuilder) {
34
- if (!this.onInputAsked) {
35
- throw new Error('No input asked callback');
36
- }
37
- return await this.onInputAsked(screen, name, description);
38
- }
39
-
40
-
1
+ import { ConfigurationBuilder } from "./main";
2
+
3
+ export default class EventResponse<T> {
4
+ data: T | undefined = undefined;
5
+ deffered: boolean = false;
6
+ resolved: boolean = false;
7
+ progress: number = 0;
8
+ logs: string[] = [];
9
+ onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;
10
+
11
+ constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {
12
+ this.onInputAsked = onInputAsked;
13
+ }
14
+
15
+
16
+ public defer() {
17
+ this.deffered = true;
18
+ }
19
+
20
+ /**
21
+ * 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.**
22
+ * @param data {T}
23
+ */
24
+ public resolve(data: T) {
25
+ this.resolved = true;
26
+ this.data = data;
27
+ }
28
+
29
+ /**
30
+ * 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.**
31
+ */
32
+ public complete() {
33
+ this.resolved = true;
34
+ }
35
+
36
+ /**
37
+ * Logs a message to the event. This is useful for debugging and logging information to the user.
38
+ * @param message {string}
39
+ */
40
+ public log(message: string) {
41
+ this.logs.push(message);
42
+ }
43
+
44
+ /**
45
+ * 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.
46
+ * @async
47
+ * @param name {string}
48
+ * @param description {string}
49
+ * @param screen {ConfigurationBuilder}
50
+ * @returns {Promise<{ [key: string]: boolean | string | number }>}
51
+ */
52
+ public async askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{ [key: string]: boolean | string | number; }> {
53
+ if (!this.onInputAsked) {
54
+ throw new Error('No input asked callback');
55
+ }
56
+ return await this.onInputAsked(screen, name, description);
57
+ }
58
+
59
+
41
60
  }
@@ -1,16 +1,16 @@
1
- export type SearchResult = {
2
- name: string;
3
- description: string;
4
- coverURL: string;
5
- downloadType: 'torrent' | 'direct' | 'magnet';
6
- downloadSize: number;
7
- appID: number;
8
- storefront: 'steam' | 'internal';
9
- filename?: string;
10
- downloadURL?: string;
11
- files?: {
12
- name: string;
13
- downloadURL: string;
14
- }[];
15
- }
16
-
1
+ export type SearchResult = {
2
+ name: string;
3
+ description: string;
4
+ coverURL: string;
5
+ downloadType: 'torrent' | 'direct' | 'magnet' | 'request';
6
+ downloadSize: number;
7
+ appID: number;
8
+ storefront: 'steam' | 'internal';
9
+ filename?: string;
10
+ downloadURL?: string;
11
+ files?: {
12
+ name: string;
13
+ downloadURL: string;
14
+ }[];
15
+ }
16
+
@@ -1,83 +1,83 @@
1
- import { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption } from "./ConfigurationBuilder";
2
-
3
- interface DefiniteConfig {
4
- [key: string]: string | number | boolean;
5
- }
6
- export class Configuration {
7
- readonly storedConfigTemplate: ConfigurationFile;
8
- definiteConfig: DefiniteConfig = {};
9
- constructor(configTemplate: ConfigurationFile) {
10
- this.storedConfigTemplate = configTemplate;
11
- }
12
-
13
- updateConfig(config: DefiniteConfig, validate: boolean = true): [ boolean, { [key: string]: string } ] {
14
- this.definiteConfig = config;
15
- if (validate) {
16
- const result = this.validateConfig();
17
- return result;
18
- }
19
- return [ true, {} ];
20
- }
21
- // provides falsey or truthy value, and an error message if falsey
22
- private validateConfig(): [ boolean, { [key: string]: string } ] {
23
- const erroredKeys = new Map<string, string>();
24
- for (const key in this.storedConfigTemplate) {
25
- if (this.definiteConfig[key] === null || this.definiteConfig[key] === undefined) {
26
- console.warn('Option ' + key + ' is not defined. Using default value Value: ' + this.definiteConfig[key]);
27
- this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue as string | number | boolean;
28
- }
29
- if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
30
- throw new Error('Option ' + key + ' is not of the correct type');
31
- }
32
-
33
- const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);
34
- if (!result[0]) {
35
- erroredKeys.set(key, result[1]);
36
- }
37
- }
38
-
39
- for (const key in this.definiteConfig) {
40
- if (!this.storedConfigTemplate[key]) {
41
- throw new Error('Option ' + key + ' is not defined in the configuration template');
42
- }
43
- }
44
-
45
- if (erroredKeys.size > 0) {
46
- return [ false, Object.fromEntries(erroredKeys) ];
47
- }
48
-
49
- return [ true, Object.fromEntries(erroredKeys) ];
50
- }
51
-
52
- getStringValue(optionName: string): string {
53
- if (!this.definiteConfig[optionName] === null) {
54
- throw new Error('Option ' + optionName + ' is not defined');
55
- }
56
- if (typeof this.definiteConfig[optionName] !== 'string') {
57
- throw new Error('Option ' + optionName + ' is not a string');
58
- }
59
- return this.definiteConfig[optionName];
60
- }
61
-
62
- getNumberValue(optionName: string): number {
63
- if (!this.definiteConfig[optionName] === null) {
64
- throw new Error('Option ' + optionName + ' is not defined');
65
- }
66
- if (typeof this.definiteConfig[optionName] !== 'number') {
67
- throw new Error('Option ' + optionName + ' is not a number');
68
- }
69
- return this.definiteConfig[optionName];
70
- }
71
-
72
- getBooleanValue(optionName: string): boolean {
73
- if (this.definiteConfig[optionName] === null) {
74
- throw new Error('Option ' + optionName + ' is not defined');
75
- }
76
- if (typeof this.definiteConfig[optionName] !== 'boolean') {
77
- throw new Error('Option ' + optionName + ' is not a boolean');
78
- }
79
- return this.definiteConfig[optionName];
80
- }
81
- }
82
-
1
+ import { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption } from "./ConfigurationBuilder";
2
+
3
+ interface DefiniteConfig {
4
+ [key: string]: string | number | boolean;
5
+ }
6
+ export class Configuration {
7
+ readonly storedConfigTemplate: ConfigurationFile;
8
+ definiteConfig: DefiniteConfig = {};
9
+ constructor(configTemplate: ConfigurationFile) {
10
+ this.storedConfigTemplate = configTemplate;
11
+ }
12
+
13
+ updateConfig(config: DefiniteConfig, validate: boolean = true): [ boolean, { [key: string]: string } ] {
14
+ this.definiteConfig = config;
15
+ if (validate) {
16
+ const result = this.validateConfig();
17
+ return result;
18
+ }
19
+ return [ true, {} ];
20
+ }
21
+ // provides falsey or truthy value, and an error message if falsey
22
+ private validateConfig(): [ boolean, { [key: string]: string } ] {
23
+ const erroredKeys = new Map<string, string>();
24
+ for (const key in this.storedConfigTemplate) {
25
+ if (this.definiteConfig[key] === null || this.definiteConfig[key] === undefined) {
26
+ console.warn('Option ' + key + ' is not defined. Using default value Value: ' + this.definiteConfig[key]);
27
+ this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue as string | number | boolean;
28
+ }
29
+ if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
30
+ throw new Error('Option ' + key + ' is not of the correct type');
31
+ }
32
+
33
+ const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);
34
+ if (!result[0]) {
35
+ erroredKeys.set(key, result[1]);
36
+ }
37
+ }
38
+
39
+ for (const key in this.definiteConfig) {
40
+ if (!this.storedConfigTemplate[key]) {
41
+ throw new Error('Option ' + key + ' is not defined in the configuration template');
42
+ }
43
+ }
44
+
45
+ if (erroredKeys.size > 0) {
46
+ return [ false, Object.fromEntries(erroredKeys) ];
47
+ }
48
+
49
+ return [ true, Object.fromEntries(erroredKeys) ];
50
+ }
51
+
52
+ getStringValue(optionName: string): string {
53
+ if (!this.definiteConfig[optionName] === null) {
54
+ throw new Error('Option ' + optionName + ' is not defined');
55
+ }
56
+ if (typeof this.definiteConfig[optionName] !== 'string') {
57
+ throw new Error('Option ' + optionName + ' is not a string');
58
+ }
59
+ return this.definiteConfig[optionName];
60
+ }
61
+
62
+ getNumberValue(optionName: string): number {
63
+ if (!this.definiteConfig[optionName] === null) {
64
+ throw new Error('Option ' + optionName + ' is not defined');
65
+ }
66
+ if (typeof this.definiteConfig[optionName] !== 'number') {
67
+ throw new Error('Option ' + optionName + ' is not a number');
68
+ }
69
+ return this.definiteConfig[optionName];
70
+ }
71
+
72
+ getBooleanValue(optionName: string): boolean {
73
+ if (this.definiteConfig[optionName] === null) {
74
+ throw new Error('Option ' + optionName + ' is not defined');
75
+ }
76
+ if (typeof this.definiteConfig[optionName] !== 'boolean') {
77
+ throw new Error('Option ' + optionName + ' is not a boolean');
78
+ }
79
+ return this.definiteConfig[optionName];
80
+ }
81
+ }
82
+
83
83
  export { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };