tering-serieuze-cli 1.0.0 → 1.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.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import { TssApi, FilesystemCache, OnePasswordCache } from "tering-serieuze-sdk";
10
10
  import omelette from "omelette";
11
11
  async function initCompletion(api2) {
12
12
  const playCompletion = {};
13
- const jingleFolders = await api2.jingle.getGrouped();
13
+ const jingleFolders = await api2.jingle.getCache().get("getGrouped") ?? [];
14
14
  jingleFolders.forEach((jingleFolder) => {
15
15
  playCompletion[jingleFolder.folder] = jingleFolder.jingles.map((jingle) => jingle.file);
16
16
  });
@@ -29,10 +29,9 @@ async function initCompletion(api2) {
29
29
  }
30
30
 
31
31
  // package.json
32
- var version = "1.0.0";
32
+ var version = "1.1.1";
33
33
 
34
34
  // src/index.ts
35
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
36
35
  var Commands = /* @__PURE__ */ ((Commands2) => {
37
36
  Commands2["autocomplete"] = "autocomplete";
38
37
  Commands2["clearcache"] = "clearcache";
@@ -43,10 +42,15 @@ var Commands = /* @__PURE__ */ ((Commands2) => {
43
42
  Commands2["version"] = "version";
44
43
  return Commands2;
45
44
  })(Commands || {});
46
- var api = new TssApi({
47
- jingle: new FilesystemCache("jingle"),
48
- auth: new OnePasswordCache("TSS-TOKEN")
49
- });
45
+ var api = new TssApi(
46
+ {
47
+ API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081"
48
+ },
49
+ {
50
+ jingle: new FilesystemCache("jingle"),
51
+ auth: new OnePasswordCache("TSS-TOKEN")
52
+ }
53
+ );
50
54
  var program = new Command();
51
55
  var completion = await initCompletion(api);
52
56
  if (process.argv.length <= 2 || process.argv[2] === "help") {
@@ -99,21 +103,37 @@ program.command("clearcache" /* clearcache */).description("Clear the cache").ar
99
103
  }
100
104
  });
101
105
  program.command("jingles" /* jingles */).description("Show all jingles").action(async () => {
102
- const jingles = await api.jingle.getAll();
103
- jingles.forEach((jingle) => {
104
- console.log(jingle.folder + "/" + jingle.file);
105
- });
106
+ try {
107
+ const jingles = await api.jingle.getAll();
108
+ jingles.forEach((jingle) => {
109
+ console.log(jingle.folder + "/" + jingle.file);
110
+ });
111
+ } catch (e) {
112
+ console.error(e.status + ": " + e.message);
113
+ }
106
114
  });
107
115
  program.command("play" /* play */).description("Play a jingle").argument("<folder>", "The folder of the jingle").argument("<file>", "The jingle to play").action(async (folder, file) => {
108
- api.jingle.play(folder, file);
116
+ try {
117
+ await api.jingle.play({ folder, file });
118
+ } catch (e) {
119
+ console.error(`ERROR ${e.status}: ${e.message}`);
120
+ }
109
121
  });
110
122
  program.command("p" /* playShort */).description("Play a jingle by typing (some) parts of the name").argument("<query...>", "The query to search for").action(async (query) => {
111
- const jingles = await api.jingle.getAll();
112
- const matches = jingles.filter((jingle) => query.every((q) => (jingle.folder + "/" + jingle.file).includes(q)));
123
+ let jingles;
124
+ try {
125
+ jingles = await api.jingle.getAll();
126
+ } catch (e) {
127
+ console.error(e.status + ": " + e.message);
128
+ return;
129
+ }
130
+ const matches = jingles.filter((jingle2) => query.every((q) => (jingle2.folder + "/" + jingle2.file).includes(q)));
131
+ let jingle;
113
132
  if (matches.length === 0) {
114
133
  console.log("No matches found");
134
+ return;
115
135
  } else if (matches.length === 1) {
116
- api.jingle.play(matches[0].folder, matches[0].file);
136
+ jingle = { folder: matches[0].folder, file: matches[0].file };
117
137
  } else {
118
138
  const sortedMatches = matches.sort((a, b) => {
119
139
  const aScore = a.keywords.filter((k) => query.includes(k)).length;
@@ -125,16 +145,29 @@ program.command("p" /* playShort */).description("Play a jingle by typing (some)
125
145
  type: "list",
126
146
  name: "jingle",
127
147
  message: "Which jingle do you want to play?",
128
- choices: sortedMatches.map((jingle) => jingle.folder + "/" + jingle.file)
148
+ choices: sortedMatches.map((jingle2) => jingle2.folder + "/" + jingle2.file)
129
149
  }
130
150
  ]);
131
151
  const [folder, file] = answers.jingle.split("/");
132
- api.jingle.play(folder, file);
152
+ jingle = { folder, file };
153
+ }
154
+ try {
155
+ await api.jingle.play(jingle);
156
+ } catch (e) {
157
+ console.error(`ERROR ${e.status}: ${e.message}`);
133
158
  }
134
159
  });
135
160
  program.command("version" /* version */).description("Show the TSS-CLI version").action(() => {
136
161
  console.log(version);
137
162
  });
163
+ program.command("users").action(async () => {
164
+ try {
165
+ const users = await api.user.getAll();
166
+ console.log(users);
167
+ } catch (e) {
168
+ console.error(e.status + ": " + e.message);
169
+ }
170
+ });
138
171
  program.parse();
139
172
  export {
140
173
  Commands
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tering-serieuze-cli",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Teringserieuze CLI",
5
5
  "author": "Frank",
6
6
  "main": "dist/index.mjs",
@@ -22,20 +22,20 @@
22
22
  },
23
23
  "homepage": "https://gitlab.com/tering-serieuze-shit/tering-serieuze-cli#readme",
24
24
  "dependencies": {
25
- "@types/node": "^18.11.18",
26
25
  "commander": "^9.4.1",
27
26
  "completion": "^1.0.3",
28
27
  "figlet": "^1.5.2",
29
28
  "inquirer": "^9.1.4",
30
29
  "omelette": "^0.4.17",
31
- "tering-serieuze-sdk": "^1.0.1",
32
- "tering-serieuze-types": "^1.8.4"
30
+ "tering-serieuze-sdk": "^2.0.0",
31
+ "tering-serieuze-types": "^1.9.0"
33
32
  },
34
33
  "devDependencies": {
35
34
  "@types/figlet": "^1.5.5",
36
35
  "@types/inquirer": "^9.0.3",
36
+ "@types/node": "^18.15.3",
37
37
  "@types/omelette": "^0.4.2",
38
- "esbuild": "^0.16.12",
38
+ "esbuild": "^0.17.12",
39
39
  "prettier": "^2.8.1"
40
40
  }
41
41
  }
package/src/completion.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import omelette from "omelette";
2
2
  import { Commands } from "./index";
3
3
  import { TssApi } from "tering-serieuze-sdk";
4
+ import { JingleFolder } from "tering-serieuze-types";
4
5
 
5
6
  export async function initCompletion(api: TssApi) {
6
7
  const playCompletion: { [key: string]: string[] } = {};
7
- const jingleFolders = await api.jingle.getGrouped();
8
+ const jingleFolders = (await api.jingle.getCache().get<JingleFolder[]>("getGrouped")) ?? [];
8
9
  jingleFolders.forEach((jingleFolder) => {
9
10
  playCompletion[jingleFolder.folder] = jingleFolder.jingles.map((jingle) => jingle.file);
10
11
  });
package/src/index.ts CHANGED
@@ -8,8 +8,6 @@ import { initCompletion } from "./completion";
8
8
  // @ts-ignore
9
9
  import { version } from "../package.json";
10
10
 
11
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
12
-
13
11
  export enum Commands {
14
12
  autocomplete = "autocomplete",
15
13
  clearcache = "clearcache",
@@ -20,10 +18,15 @@ export enum Commands {
20
18
  version = "version",
21
19
  }
22
20
 
23
- const api = new TssApi({
24
- jingle: new FilesystemCache("jingle"),
25
- auth: new OnePasswordCache("TSS-TOKEN"),
26
- });
21
+ const api = new TssApi(
22
+ {
23
+ API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081",
24
+ },
25
+ {
26
+ jingle: new FilesystemCache("jingle"),
27
+ auth: new OnePasswordCache("TSS-TOKEN"),
28
+ }
29
+ );
27
30
 
28
31
  const program = new Command();
29
32
  const completion = await initCompletion(api);
@@ -101,10 +104,14 @@ program
101
104
  .command(Commands.jingles)
102
105
  .description("Show all jingles")
103
106
  .action(async () => {
104
- const jingles = await api.jingle.getAll();
105
- jingles.forEach((jingle) => {
106
- console.log(jingle.folder + "/" + jingle.file);
107
- });
107
+ try {
108
+ const jingles = await api.jingle.getAll();
109
+ jingles.forEach((jingle) => {
110
+ console.log(jingle.folder + "/" + jingle.file);
111
+ });
112
+ } catch (e: any) {
113
+ console.error(e.status + ": " + e.message);
114
+ }
108
115
  });
109
116
 
110
117
  program
@@ -113,7 +120,11 @@ program
113
120
  .argument("<folder>", "The folder of the jingle")
114
121
  .argument("<file>", "The jingle to play")
115
122
  .action(async (folder, file) => {
116
- api.jingle.play(folder, file);
123
+ try {
124
+ await api.jingle.play({ folder, file });
125
+ } catch (e: any) {
126
+ console.error(`ERROR ${e.status}: ${e.message}`);
127
+ }
117
128
  });
118
129
 
119
130
  program
@@ -121,13 +132,22 @@ program
121
132
  .description("Play a jingle by typing (some) parts of the name")
122
133
  .argument("<query...>", "The query to search for")
123
134
  .action(async (query: string[]) => {
124
- const jingles = await api.jingle.getAll();
135
+ let jingles;
136
+ try {
137
+ jingles = await api.jingle.getAll();
138
+ } catch (e: any) {
139
+ console.error(e.status + ": " + e.message);
140
+ return;
141
+ }
142
+
125
143
  const matches = jingles.filter((jingle) => query.every((q) => (jingle.folder + "/" + jingle.file).includes(q)));
126
144
 
145
+ let jingle;
127
146
  if (matches.length === 0) {
128
147
  console.log("No matches found");
148
+ return;
129
149
  } else if (matches.length === 1) {
130
- api.jingle.play(matches[0].folder, matches[0].file);
150
+ jingle = { folder: matches[0].folder, file: matches[0].file };
131
151
  } else {
132
152
  const sortedMatches = matches.sort((a, b) => {
133
153
  const aScore = a.keywords.filter((k) => query.includes(k)).length;
@@ -146,7 +166,13 @@ program
146
166
  ]);
147
167
 
148
168
  const [folder, file] = answers.jingle.split("/");
149
- api.jingle.play(folder, file);
169
+ jingle = { folder, file };
170
+ }
171
+
172
+ try {
173
+ await api.jingle.play(jingle);
174
+ } catch (e: any) {
175
+ console.error(`ERROR ${e.status}: ${e.message}`);
150
176
  }
151
177
  });
152
178
 
@@ -157,4 +183,13 @@ program
157
183
  console.log(version);
158
184
  });
159
185
 
186
+ program.command("users").action(async () => {
187
+ try {
188
+ const users = await api.user.getAll();
189
+ console.log(users);
190
+ } catch (e: any) {
191
+ console.error(e.status + ": " + e.message);
192
+ }
193
+ });
194
+
160
195
  program.parse();