tering-serieuze-cli 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
  });
@@ -19,6 +19,7 @@ async function initCompletion(api2) {
19
19
  ["clearcache" /* clearcache */]: ["auth", "jingle", "all"],
20
20
  ["login" /* login */]: [],
21
21
  ["play" /* play */]: playCompletion,
22
+ ["recent" /* recent */]: [],
22
23
  ["jingles" /* jingles */]: [],
23
24
  ["p" /* playShort */]: [],
24
25
  ["version" /* version */]: []
@@ -29,24 +30,30 @@ async function initCompletion(api2) {
29
30
  }
30
31
 
31
32
  // package.json
32
- var version = "1.0.0";
33
+ var version = "1.2.0";
33
34
 
34
35
  // src/index.ts
35
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
36
36
  var Commands = /* @__PURE__ */ ((Commands2) => {
37
37
  Commands2["autocomplete"] = "autocomplete";
38
38
  Commands2["clearcache"] = "clearcache";
39
39
  Commands2["login"] = "login";
40
40
  Commands2["play"] = "play";
41
+ Commands2["recent"] = "recent";
41
42
  Commands2["jingles"] = "jingles";
42
43
  Commands2["playShort"] = "p";
43
44
  Commands2["version"] = "version";
44
45
  return Commands2;
45
46
  })(Commands || {});
46
- var api = new TssApi({
47
- jingle: new FilesystemCache("jingle"),
48
- auth: new OnePasswordCache("TSS-TOKEN")
49
- });
47
+ var playWhichJingleString = "Which jingle do you want to play?";
48
+ var api = new TssApi(
49
+ {
50
+ API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081"
51
+ },
52
+ {
53
+ jingle: new FilesystemCache("jingle"),
54
+ auth: new OnePasswordCache("TSS-TOKEN")
55
+ }
56
+ );
50
57
  var program = new Command();
51
58
  var completion = await initCompletion(api);
52
59
  if (process.argv.length <= 2 || process.argv[2] === "help") {
@@ -96,24 +103,61 @@ program.command("clearcache" /* clearcache */).description("Clear the cache").ar
96
103
  await api.auth.removeToken();
97
104
  await api.jingle.getCache().clear();
98
105
  console.log("Cleared all caches");
106
+ } else {
107
+ console.error("Invalid cache type");
99
108
  }
100
109
  });
101
110
  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
- });
111
+ try {
112
+ const jingles = await api.jingle.getAll();
113
+ jingles.forEach((jingle) => {
114
+ console.log(jingle.folder + "/" + jingle.file);
115
+ });
116
+ } catch (e) {
117
+ console.error(e.status + ": " + e.message);
118
+ }
106
119
  });
107
120
  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);
121
+ try {
122
+ await api.jingle.play({ folder, file });
123
+ } catch (e) {
124
+ console.error(`ERROR ${e.status}: ${e.message}`);
125
+ }
126
+ });
127
+ program.command("recent" /* recent */).description("Show recently added jingles, select a jingle to play").action(async () => {
128
+ try {
129
+ const jingles = await api.jingle.getAll();
130
+ jingles.sort((a, b) => b.mtime - a.mtime);
131
+ const answers = await inquirer.prompt([
132
+ {
133
+ type: "list",
134
+ name: "jingle",
135
+ message: playWhichJingleString,
136
+ choices: jingles.slice(0, 30).map((jingle2) => jingle2.folder + "/" + jingle2.file)
137
+ }
138
+ ]);
139
+ const [folder, file] = answers.jingle.split("/");
140
+ const jingle = { folder, file };
141
+ await api.jingle.play(jingle);
142
+ } catch (e) {
143
+ console.error(e.status + ": " + e.message);
144
+ }
109
145
  });
110
146
  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)));
147
+ let jingles;
148
+ try {
149
+ jingles = await api.jingle.getAll();
150
+ } catch (e) {
151
+ console.error(e.status + ": " + e.message);
152
+ return;
153
+ }
154
+ const matches = jingles.filter((jingle2) => query.every((q) => (jingle2.folder + "/" + jingle2.file).includes(q)));
155
+ let jingle;
113
156
  if (matches.length === 0) {
114
157
  console.log("No matches found");
158
+ return;
115
159
  } else if (matches.length === 1) {
116
- api.jingle.play(matches[0].folder, matches[0].file);
160
+ jingle = { folder: matches[0].folder, file: matches[0].file };
117
161
  } else {
118
162
  const sortedMatches = matches.sort((a, b) => {
119
163
  const aScore = a.keywords.filter((k) => query.includes(k)).length;
@@ -124,17 +168,30 @@ program.command("p" /* playShort */).description("Play a jingle by typing (some)
124
168
  {
125
169
  type: "list",
126
170
  name: "jingle",
127
- message: "Which jingle do you want to play?",
128
- choices: sortedMatches.map((jingle) => jingle.folder + "/" + jingle.file)
171
+ message: playWhichJingleString,
172
+ choices: sortedMatches.map((jingle2) => jingle2.folder + "/" + jingle2.file)
129
173
  }
130
174
  ]);
131
175
  const [folder, file] = answers.jingle.split("/");
132
- api.jingle.play(folder, file);
176
+ jingle = { folder, file };
177
+ }
178
+ try {
179
+ await api.jingle.play(jingle);
180
+ } catch (e) {
181
+ console.error(`ERROR ${e.status}: ${e.message}`);
133
182
  }
134
183
  });
135
184
  program.command("version" /* version */).description("Show the TSS-CLI version").action(() => {
136
185
  console.log(version);
137
186
  });
187
+ program.command("users").action(async () => {
188
+ try {
189
+ const users = await api.user.getAll();
190
+ console.log(users);
191
+ } catch (e) {
192
+ console.error(e.status + ": " + e.message);
193
+ }
194
+ });
138
195
  program.parse();
139
196
  export {
140
197
  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.3.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": "^3.0.0",
31
+ "tering-serieuze-types": "^1.14.1"
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
  });
@@ -14,6 +15,7 @@ export async function initCompletion(api: TssApi) {
14
15
  [Commands.clearcache]: ["auth", "jingle", "all"],
15
16
  [Commands.login]: [],
16
17
  [Commands.play]: playCompletion,
18
+ [Commands.recent]: [],
17
19
  [Commands.jingles]: [],
18
20
  [Commands.playShort]: [],
19
21
  [Commands.version]: [],
package/src/index.ts CHANGED
@@ -8,22 +8,28 @@ 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",
16
14
  login = "login",
17
15
  play = "play",
16
+ recent = "recent",
18
17
  jingles = "jingles",
19
18
  playShort = "p",
20
19
  version = "version",
21
20
  }
22
21
 
23
- const api = new TssApi({
24
- jingle: new FilesystemCache("jingle"),
25
- auth: new OnePasswordCache("TSS-TOKEN"),
26
- });
22
+ const playWhichJingleString = "Which jingle do you want to play?";
23
+
24
+ const api = new TssApi(
25
+ {
26
+ API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081",
27
+ },
28
+ {
29
+ jingle: new FilesystemCache("jingle"),
30
+ auth: new OnePasswordCache("TSS-TOKEN"),
31
+ }
32
+ );
27
33
 
28
34
  const program = new Command();
29
35
  const completion = await initCompletion(api);
@@ -94,6 +100,8 @@ program
94
100
  await api.auth.removeToken();
95
101
  await api.jingle.getCache().clear();
96
102
  console.log("Cleared all caches");
103
+ } else {
104
+ console.error("Invalid cache type");
97
105
  }
98
106
  });
99
107
 
@@ -101,10 +109,14 @@ program
101
109
  .command(Commands.jingles)
102
110
  .description("Show all jingles")
103
111
  .action(async () => {
104
- const jingles = await api.jingle.getAll();
105
- jingles.forEach((jingle) => {
106
- console.log(jingle.folder + "/" + jingle.file);
107
- });
112
+ try {
113
+ const jingles = await api.jingle.getAll();
114
+ jingles.forEach((jingle) => {
115
+ console.log(jingle.folder + "/" + jingle.file);
116
+ });
117
+ } catch (e: any) {
118
+ console.error(e.status + ": " + e.message);
119
+ }
108
120
  });
109
121
 
110
122
  program
@@ -113,7 +125,36 @@ program
113
125
  .argument("<folder>", "The folder of the jingle")
114
126
  .argument("<file>", "The jingle to play")
115
127
  .action(async (folder, file) => {
116
- api.jingle.play(folder, file);
128
+ try {
129
+ await api.jingle.play({ folder, file });
130
+ } catch (e: any) {
131
+ console.error(`ERROR ${e.status}: ${e.message}`);
132
+ }
133
+ });
134
+
135
+ program
136
+ .command(Commands.recent)
137
+ .description("Show recently added jingles, select a jingle to play")
138
+ .action(async () => {
139
+ try {
140
+ const jingles = await api.jingle.getAll();
141
+ jingles.sort((a, b) => b.mtime - a.mtime);
142
+
143
+ const answers = await inquirer.prompt([
144
+ {
145
+ type: "list",
146
+ name: "jingle",
147
+ message: playWhichJingleString,
148
+ choices: jingles.slice(0, 30).map((jingle) => jingle.folder + "/" + jingle.file),
149
+ },
150
+ ]);
151
+
152
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
153
+ const jingle = { folder, file };
154
+ await api.jingle.play(jingle);
155
+ } catch (e: any) {
156
+ console.error(e.status + ": " + e.message);
157
+ }
117
158
  });
118
159
 
119
160
  program
@@ -121,13 +162,22 @@ program
121
162
  .description("Play a jingle by typing (some) parts of the name")
122
163
  .argument("<query...>", "The query to search for")
123
164
  .action(async (query: string[]) => {
124
- const jingles = await api.jingle.getAll();
165
+ let jingles;
166
+ try {
167
+ jingles = await api.jingle.getAll();
168
+ } catch (e: any) {
169
+ console.error(e.status + ": " + e.message);
170
+ return;
171
+ }
172
+
125
173
  const matches = jingles.filter((jingle) => query.every((q) => (jingle.folder + "/" + jingle.file).includes(q)));
126
174
 
175
+ let jingle;
127
176
  if (matches.length === 0) {
128
177
  console.log("No matches found");
178
+ return;
129
179
  } else if (matches.length === 1) {
130
- api.jingle.play(matches[0].folder, matches[0].file);
180
+ jingle = { folder: matches[0].folder, file: matches[0].file };
131
181
  } else {
132
182
  const sortedMatches = matches.sort((a, b) => {
133
183
  const aScore = a.keywords.filter((k) => query.includes(k)).length;
@@ -140,13 +190,19 @@ program
140
190
  {
141
191
  type: "list",
142
192
  name: "jingle",
143
- message: "Which jingle do you want to play?",
193
+ message: playWhichJingleString,
144
194
  choices: sortedMatches.map((jingle) => jingle.folder + "/" + jingle.file),
145
195
  },
146
196
  ]);
147
197
 
148
- const [folder, file] = answers.jingle.split("/");
149
- api.jingle.play(folder, file);
198
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
199
+ jingle = { folder, file };
200
+ }
201
+
202
+ try {
203
+ await api.jingle.play(jingle);
204
+ } catch (e: any) {
205
+ console.error(`ERROR ${e.status}: ${e.message}`);
150
206
  }
151
207
  });
152
208
 
@@ -157,4 +213,13 @@ program
157
213
  console.log(version);
158
214
  });
159
215
 
216
+ program.command("users").action(async () => {
217
+ try {
218
+ const users = await api.user.getAll();
219
+ console.log(users);
220
+ } catch (e: any) {
221
+ console.error(e.status + ": " + e.message);
222
+ }
223
+ });
224
+
160
225
  program.parse();