tering-serieuze-sdk 3.11.0 → 3.13.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/biome.json +104 -0
- package/dist/index.mjs +138 -131
- package/dist/index.mjs.map +3 -3
- package/index.d.ts +3 -3
- package/package.json +5 -3
- package/src/api/auth.ts +14 -21
- package/src/api/base.ts +4 -1
- package/src/api/jingle.ts +10 -10
- package/src/api/k8s.ts +6 -1
- package/src/api/user.ts +4 -4
- package/src/cache/cookieCache.ts +5 -4
- package/src/cache/filesystemCache.ts +39 -23
- package/src/cache/nullCache.ts +12 -6
- package/src/cache/onePasswordCache.ts +7 -7
- package/src/index.ts +20 -19
- package/test/api/base.test.ts +1 -1
- package/test/api/jingle.test.ts +2 -2
- package/test/cache/filesystemCache.test.ts +5 -5
- package/test/cache/nullCache.test.ts +1 -1
- package/tsconfig.json +16 -16
- package/types/environment.d.ts +1 -0
- package/.prettierrc +0 -6
package/biome.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
|
|
3
|
+
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
|
|
4
|
+
"files": {
|
|
5
|
+
"includes": ["**/*.ts", "**/*.js", "**/*.mts", "**/*.json", "**/*.md", "!package*.json"]
|
|
6
|
+
},
|
|
7
|
+
"formatter": {
|
|
8
|
+
"enabled": true,
|
|
9
|
+
"indentStyle": "space",
|
|
10
|
+
"indentWidth": 4,
|
|
11
|
+
"lineWidth": 120
|
|
12
|
+
},
|
|
13
|
+
"linter": {
|
|
14
|
+
"enabled": true,
|
|
15
|
+
"rules": {
|
|
16
|
+
"recommended": true,
|
|
17
|
+
"complexity": {
|
|
18
|
+
"noExcessiveCognitiveComplexity": "error",
|
|
19
|
+
"noExcessiveNestedTestSuites": "error",
|
|
20
|
+
"noUselessStringConcat": "error"
|
|
21
|
+
},
|
|
22
|
+
"correctness": {
|
|
23
|
+
"noUndeclaredVariables": "error"
|
|
24
|
+
},
|
|
25
|
+
"nursery": {
|
|
26
|
+
"noAwaitInLoop": "error",
|
|
27
|
+
"noUnassignedVariables": "error",
|
|
28
|
+
"useNumericSeparators": "error",
|
|
29
|
+
"useObjectSpread": "error",
|
|
30
|
+
"useParseIntRadix": "error",
|
|
31
|
+
"useReadonlyClassProperties": "error"
|
|
32
|
+
},
|
|
33
|
+
"performance": {
|
|
34
|
+
"noBarrelFile": "off",
|
|
35
|
+
"noDelete": "error",
|
|
36
|
+
"noNamespaceImport": "error",
|
|
37
|
+
"noReExportAll": "off"
|
|
38
|
+
},
|
|
39
|
+
"style": {
|
|
40
|
+
"noCommonJs": "error",
|
|
41
|
+
"noInferrableTypes": "error",
|
|
42
|
+
"noNamespace": "error",
|
|
43
|
+
"noNestedTernary": "error",
|
|
44
|
+
"noNonNullAssertion": "error",
|
|
45
|
+
"noParameterAssign": "error",
|
|
46
|
+
"noSubstr": "error",
|
|
47
|
+
"noUnusedTemplateLiteral": "error",
|
|
48
|
+
"noUselessElse": "error",
|
|
49
|
+
"noYodaExpression": "error",
|
|
50
|
+
"useArrayLiterals": "error",
|
|
51
|
+
"useAsConstAssertion": "error",
|
|
52
|
+
"useBlockStatements": "error",
|
|
53
|
+
"useCollapsedIf": "error",
|
|
54
|
+
"useConsistentArrayType": "error",
|
|
55
|
+
"useConsistentBuiltinInstantiation": "error",
|
|
56
|
+
"useConst": "error",
|
|
57
|
+
"useDefaultParameterLast": "error",
|
|
58
|
+
"useDefaultSwitchClause": "error",
|
|
59
|
+
"useExplicitLengthCheck": "error",
|
|
60
|
+
"useForOf": "error",
|
|
61
|
+
"useImportType": "off",
|
|
62
|
+
"useLiteralEnumMembers": "error",
|
|
63
|
+
"useNodejsImportProtocol": "error",
|
|
64
|
+
"useNumberNamespace": "error",
|
|
65
|
+
"useShorthandAssign": "error",
|
|
66
|
+
"useShorthandFunctionType": "error",
|
|
67
|
+
"useThrowNewError": "error",
|
|
68
|
+
"useThrowOnlyError": "error",
|
|
69
|
+
"useTrimStartEnd": "error"
|
|
70
|
+
},
|
|
71
|
+
"suspicious": {
|
|
72
|
+
"noDuplicateTestHooks": "error",
|
|
73
|
+
"noEmptyBlockStatements": "error",
|
|
74
|
+
"noEvolvingTypes": "error",
|
|
75
|
+
"noExportsInTest": "error",
|
|
76
|
+
"noFocusedTests": "error",
|
|
77
|
+
"noMisplacedAssertion": "error",
|
|
78
|
+
"noSkippedTests": "error",
|
|
79
|
+
"noVar": "error",
|
|
80
|
+
"useAwait": "error",
|
|
81
|
+
"useErrorMessage": "error",
|
|
82
|
+
"useNumberToFixedDigitsArgument": "error"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"domains": {
|
|
86
|
+
"test": "all"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"javascript": {
|
|
90
|
+
"parser": {
|
|
91
|
+
"unsafeParameterDecoratorsEnabled": true
|
|
92
|
+
},
|
|
93
|
+
"formatter": {
|
|
94
|
+
"quoteStyle": "single"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"assist": {
|
|
98
|
+
"actions": {
|
|
99
|
+
"source": {
|
|
100
|
+
"organizeImports": "on"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,79 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
// src/api/base.ts
|
|
9
|
+
var BaseModule = class {
|
|
10
|
+
constructor(api, cache) {
|
|
11
|
+
this.api = api;
|
|
12
|
+
this.cache = cache;
|
|
13
|
+
}
|
|
14
|
+
getCache() {
|
|
15
|
+
return this.cache;
|
|
16
|
+
}
|
|
17
|
+
setCache(cache) {
|
|
18
|
+
this.cache = cache;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/api/auth.ts
|
|
23
|
+
function parseJwt(token) {
|
|
24
|
+
let jsonPayload = "";
|
|
25
|
+
if (typeof Buffer !== "undefined") {
|
|
26
|
+
jsonPayload = Buffer.from(token.split(".")[1], "base64").toString();
|
|
27
|
+
} else {
|
|
28
|
+
const base64Url = token.split(".")[1];
|
|
29
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
30
|
+
jsonPayload = decodeURIComponent(
|
|
31
|
+
window.atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return JSON.parse(jsonPayload);
|
|
35
|
+
}
|
|
36
|
+
var _AuthModule = class extends BaseModule {
|
|
37
|
+
getToken() {
|
|
38
|
+
return process.env.TSS_TOKEN ? Promise.resolve(process.env.TSS_TOKEN) : this.cache.get(_AuthModule.cacheKey);
|
|
39
|
+
}
|
|
40
|
+
setToken(token, lifetime) {
|
|
41
|
+
return this.cache.set(_AuthModule.cacheKey, token, lifetime);
|
|
42
|
+
}
|
|
43
|
+
removeToken() {
|
|
44
|
+
return this.cache.remove(_AuthModule.cacheKey);
|
|
45
|
+
}
|
|
46
|
+
async getSessionId() {
|
|
47
|
+
const token = await this.getToken();
|
|
48
|
+
const { sessionId } = parseJwt(token ?? "");
|
|
49
|
+
return sessionId;
|
|
50
|
+
}
|
|
51
|
+
async removeSession(sessionId) {
|
|
52
|
+
const session = sessionId ?? await this.getSessionId();
|
|
53
|
+
await this.api.delete(`session/${session}`, { credentials: "include" });
|
|
54
|
+
}
|
|
55
|
+
async logout() {
|
|
56
|
+
await this.removeSession();
|
|
57
|
+
this.removeToken();
|
|
58
|
+
}
|
|
59
|
+
getRegistrationOptions(registrationToken) {
|
|
60
|
+
return this.api.get(`auth/registration-options/${registrationToken}`);
|
|
61
|
+
}
|
|
62
|
+
getAuthenticationOptions() {
|
|
63
|
+
return this.api.get("auth/authentication-options");
|
|
64
|
+
}
|
|
65
|
+
verifyRegistration(registrationToken, registrationResponse) {
|
|
66
|
+
return this.api.post(
|
|
67
|
+
`auth/verify-registration/${registrationToken}`,
|
|
68
|
+
registrationResponse,
|
|
69
|
+
{ credentials: "include" }
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
verifyAuthentication(token, response) {
|
|
73
|
+
return this.api.post(`auth/verify-authentication/${token}`, response, {
|
|
74
|
+
credentials: "include"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var AuthModule = _AuthModule;
|
|
79
|
+
__publicField(AuthModule, "cacheKey", "TSS-TOKEN");
|
|
80
|
+
|
|
8
81
|
// node_modules/stack-trace/index.js
|
|
9
82
|
function get(belowFn) {
|
|
10
83
|
const oldLimit = Error.stackTraceLimit;
|
|
@@ -81,14 +154,14 @@ var AbstractCache = class {
|
|
|
81
154
|
|
|
82
155
|
// src/cache/cookieCache.ts
|
|
83
156
|
var CookieCache = class extends AbstractCache {
|
|
84
|
-
cacheOrGet(
|
|
157
|
+
cacheOrGet() {
|
|
85
158
|
throw new Error("Not implemented, use get() and set()");
|
|
86
159
|
}
|
|
87
|
-
|
|
160
|
+
get(key) {
|
|
88
161
|
if (document.cookie.includes(`${key}=`)) {
|
|
89
|
-
return document.cookie.split(`${key}=`)[1]?.split(";")[0];
|
|
162
|
+
return Promise.resolve(document.cookie.split(`${key}=`)[1]?.split(";")[0]);
|
|
90
163
|
}
|
|
91
|
-
return void 0;
|
|
164
|
+
return Promise.resolve(void 0);
|
|
92
165
|
}
|
|
93
166
|
set(key, value, lifetime) {
|
|
94
167
|
const expires = lifetime ? new Date(Date.now() + lifetime).toUTCString() : "";
|
|
@@ -103,31 +176,34 @@ var CookieCache = class extends AbstractCache {
|
|
|
103
176
|
};
|
|
104
177
|
|
|
105
178
|
// src/cache/filesystemCache.ts
|
|
106
|
-
import fs from "fs";
|
|
107
|
-
import
|
|
108
|
-
import
|
|
179
|
+
import fs from "node:fs";
|
|
180
|
+
import os from "node:os";
|
|
181
|
+
import path from "node:path";
|
|
109
182
|
var FilesystemCache = class extends AbstractCache {
|
|
110
183
|
initialized = false;
|
|
111
|
-
state =
|
|
184
|
+
state = /* @__PURE__ */ new Map();
|
|
112
185
|
async cacheOrGet(callbackWhenEmpty, key, lifetime) {
|
|
113
|
-
|
|
114
|
-
const cachedValue = await this.get(
|
|
186
|
+
const usedKey = key ?? this.getCacheKey();
|
|
187
|
+
const cachedValue = await this.get(usedKey);
|
|
115
188
|
if (cachedValue) {
|
|
116
189
|
return cachedValue;
|
|
117
190
|
}
|
|
118
191
|
const result = await callbackWhenEmpty();
|
|
119
|
-
this.set(
|
|
192
|
+
this.set(usedKey, result, lifetime);
|
|
120
193
|
return result;
|
|
121
194
|
}
|
|
122
|
-
|
|
195
|
+
get(key) {
|
|
123
196
|
if (!this.initialized) {
|
|
124
|
-
|
|
197
|
+
this._initialize();
|
|
125
198
|
}
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
|
|
199
|
+
const item = this.state.get(key);
|
|
200
|
+
if (item) {
|
|
201
|
+
const expires = item.expiresAt;
|
|
202
|
+
if (expires === void 0 || expires > Date.now()) {
|
|
203
|
+
return Promise.resolve(item.value);
|
|
204
|
+
}
|
|
129
205
|
}
|
|
130
|
-
return void 0;
|
|
206
|
+
return Promise.resolve(void 0);
|
|
131
207
|
}
|
|
132
208
|
set(key, value, lifetime) {
|
|
133
209
|
const expiresAt = lifetime ? Date.now() + lifetime : void 0;
|
|
@@ -135,15 +211,15 @@ var FilesystemCache = class extends AbstractCache {
|
|
|
135
211
|
if (expiresAt) {
|
|
136
212
|
content.expiresAt = expiresAt;
|
|
137
213
|
}
|
|
138
|
-
this.state
|
|
214
|
+
this.state.set(key, content);
|
|
139
215
|
this.writeState();
|
|
140
216
|
}
|
|
141
217
|
remove(key) {
|
|
142
|
-
|
|
218
|
+
this.state.delete(key);
|
|
143
219
|
this.writeState();
|
|
144
220
|
}
|
|
145
221
|
clear() {
|
|
146
|
-
this.state
|
|
222
|
+
this.state.clear();
|
|
147
223
|
if (fs.existsSync(this.getFilePath())) {
|
|
148
224
|
fs.unlinkSync(this.getFilePath());
|
|
149
225
|
}
|
|
@@ -154,39 +230,46 @@ var FilesystemCache = class extends AbstractCache {
|
|
|
154
230
|
_initialize() {
|
|
155
231
|
this.initialized = true;
|
|
156
232
|
if (fs.existsSync(this.getFilePath())) {
|
|
157
|
-
|
|
233
|
+
try {
|
|
234
|
+
const fileContent = fs.readFileSync(this.getFilePath(), "utf8");
|
|
235
|
+
const parsed = JSON.parse(fileContent);
|
|
236
|
+
this.state = new Map(Object.entries(parsed));
|
|
237
|
+
} catch (_e) {
|
|
238
|
+
this.state = /* @__PURE__ */ new Map();
|
|
239
|
+
}
|
|
158
240
|
}
|
|
159
241
|
}
|
|
160
242
|
writeState() {
|
|
161
243
|
if (!fs.existsSync(path.dirname(this.getFilePath()))) {
|
|
162
|
-
fs.mkdirSync(path.dirname(this.getFilePath()));
|
|
244
|
+
fs.mkdirSync(path.dirname(this.getFilePath()), { recursive: true });
|
|
163
245
|
}
|
|
164
|
-
|
|
246
|
+
const plainObject = Object.fromEntries(this.state);
|
|
247
|
+
fs.writeFileSync(this.getFilePath(), JSON.stringify(plainObject));
|
|
165
248
|
}
|
|
166
249
|
};
|
|
167
250
|
|
|
168
251
|
// src/cache/nullCache.ts
|
|
169
252
|
var NullCache = class extends AbstractCache {
|
|
170
|
-
cacheOrGet(callbackWhenEmpty
|
|
253
|
+
cacheOrGet(callbackWhenEmpty) {
|
|
171
254
|
return callbackWhenEmpty();
|
|
172
255
|
}
|
|
173
|
-
|
|
174
|
-
return void 0;
|
|
256
|
+
get() {
|
|
257
|
+
return Promise.resolve(void 0);
|
|
175
258
|
}
|
|
176
|
-
set(
|
|
259
|
+
set() {
|
|
177
260
|
}
|
|
178
|
-
remove(
|
|
261
|
+
remove() {
|
|
179
262
|
}
|
|
180
263
|
clear() {
|
|
181
264
|
}
|
|
182
265
|
};
|
|
183
266
|
|
|
184
267
|
// src/cache/onePasswordCache.ts
|
|
185
|
-
import
|
|
186
|
-
import
|
|
268
|
+
import child_process from "node:child_process";
|
|
269
|
+
import util from "node:util";
|
|
187
270
|
var OnePasswordCache = class extends AbstractCache {
|
|
188
271
|
asyncExec = util.promisify(child_process.exec);
|
|
189
|
-
cacheOrGet(
|
|
272
|
+
cacheOrGet() {
|
|
190
273
|
throw new Error("Not implemented, use get() and set()");
|
|
191
274
|
}
|
|
192
275
|
async get(key) {
|
|
@@ -197,14 +280,14 @@ var OnePasswordCache = class extends AbstractCache {
|
|
|
197
280
|
}
|
|
198
281
|
return JSON.parse(stdout).value;
|
|
199
282
|
}
|
|
200
|
-
async set(key, value
|
|
283
|
+
async set(key, value) {
|
|
201
284
|
let action = `op item edit '${key}' 'credential=${value}'`;
|
|
202
285
|
try {
|
|
203
|
-
|
|
204
|
-
} catch (
|
|
286
|
+
await this.get(key);
|
|
287
|
+
} catch (_e) {
|
|
205
288
|
action = `op item create --category="API Credential" --title ${key} 'credential=${value}'`;
|
|
206
289
|
}
|
|
207
|
-
const {
|
|
290
|
+
const { stderr } = await this.asyncExec(action);
|
|
208
291
|
if (stderr) {
|
|
209
292
|
console.log(stderr);
|
|
210
293
|
throw new Error("ERROR");
|
|
@@ -217,88 +300,9 @@ var OnePasswordCache = class extends AbstractCache {
|
|
|
217
300
|
}
|
|
218
301
|
};
|
|
219
302
|
|
|
220
|
-
// src/api/base.ts
|
|
221
|
-
var BaseModule = class {
|
|
222
|
-
constructor(api, cache) {
|
|
223
|
-
this.api = api;
|
|
224
|
-
this.cache = cache;
|
|
225
|
-
}
|
|
226
|
-
getCache() {
|
|
227
|
-
return this.cache;
|
|
228
|
-
}
|
|
229
|
-
setCache(cache) {
|
|
230
|
-
this.cache = cache;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// src/api/auth.ts
|
|
235
|
-
function parseJwt(token) {
|
|
236
|
-
let jsonPayload;
|
|
237
|
-
if (typeof Buffer !== "undefined") {
|
|
238
|
-
jsonPayload = Buffer.from(token.split(".")[1], "base64").toString();
|
|
239
|
-
} else {
|
|
240
|
-
const base64Url = token.split(".")[1];
|
|
241
|
-
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
242
|
-
jsonPayload = decodeURIComponent(
|
|
243
|
-
window.atob(base64).split("").map(function(c) {
|
|
244
|
-
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
245
|
-
}).join("")
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
return JSON.parse(jsonPayload);
|
|
249
|
-
}
|
|
250
|
-
var _AuthModule = class extends BaseModule {
|
|
251
|
-
async getToken() {
|
|
252
|
-
return process.env.TSS_TOKEN ?? this.cache.get(_AuthModule.cacheKey);
|
|
253
|
-
}
|
|
254
|
-
async setToken(token, lifetime) {
|
|
255
|
-
return this.cache.set(_AuthModule.cacheKey, token, lifetime);
|
|
256
|
-
}
|
|
257
|
-
async setCode(code) {
|
|
258
|
-
const { accessToken } = await this.api.post(`auth/setCode?code=${code}`, {}, { credentials: "include" });
|
|
259
|
-
return accessToken;
|
|
260
|
-
}
|
|
261
|
-
async removeToken() {
|
|
262
|
-
return this.cache.remove(_AuthModule.cacheKey);
|
|
263
|
-
}
|
|
264
|
-
async getSessionId() {
|
|
265
|
-
const token = await this.getToken();
|
|
266
|
-
const { sessionId } = parseJwt(token ?? "");
|
|
267
|
-
return sessionId;
|
|
268
|
-
}
|
|
269
|
-
async removeSession(sessionId) {
|
|
270
|
-
const session = sessionId ?? await this.getSessionId();
|
|
271
|
-
await this.api.delete(`session/${session}`, { credentials: "include" });
|
|
272
|
-
}
|
|
273
|
-
async logout() {
|
|
274
|
-
await this.removeSession();
|
|
275
|
-
await this.removeToken();
|
|
276
|
-
}
|
|
277
|
-
async getRegistrationOptions(registrationToken) {
|
|
278
|
-
return this.api.get(`auth/registration-options/${registrationToken}`);
|
|
279
|
-
}
|
|
280
|
-
async getAuthenticationOptions() {
|
|
281
|
-
return this.api.get("auth/authentication-options");
|
|
282
|
-
}
|
|
283
|
-
async verifyRegistration(registrationToken, registrationResponse) {
|
|
284
|
-
return this.api.post(
|
|
285
|
-
`auth/verify-registration/${registrationToken}`,
|
|
286
|
-
registrationResponse,
|
|
287
|
-
{ credentials: "include" }
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
async verifyAuthentication(token, response) {
|
|
291
|
-
return this.api.post(`auth/verify-authentication/${token}`, response, {
|
|
292
|
-
credentials: "include"
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
var AuthModule = _AuthModule;
|
|
297
|
-
__publicField(AuthModule, "cacheKey", "TSS-TOKEN");
|
|
298
|
-
|
|
299
303
|
// src/api/jingle.ts
|
|
300
304
|
var JingleModule = class extends BaseModule {
|
|
301
|
-
|
|
305
|
+
getGrouped() {
|
|
302
306
|
return this.cache.cacheOrGet(
|
|
303
307
|
() => {
|
|
304
308
|
return this.api.get("jingle/grouped");
|
|
@@ -307,7 +311,7 @@ var JingleModule = class extends BaseModule {
|
|
|
307
311
|
864e5 /* Day */
|
|
308
312
|
);
|
|
309
313
|
}
|
|
310
|
-
|
|
314
|
+
getAll() {
|
|
311
315
|
return this.cache.cacheOrGet(
|
|
312
316
|
() => {
|
|
313
317
|
return this.api.get("jingle");
|
|
@@ -320,18 +324,18 @@ var JingleModule = class extends BaseModule {
|
|
|
320
324
|
const jingles = await this.getAll();
|
|
321
325
|
return jingles.sort((a, b) => b.mtime - a.mtime).slice(0, 30);
|
|
322
326
|
}
|
|
323
|
-
|
|
327
|
+
play(playJingleDto) {
|
|
324
328
|
console.log(`Playing jingle ${playJingleDto.folder}/${playJingleDto.file}`);
|
|
325
329
|
return this.api.post("jingle/play", playJingleDto);
|
|
326
330
|
}
|
|
327
|
-
|
|
331
|
+
getBigBrotherData() {
|
|
328
332
|
return this.api.get("jingle/bigbrother");
|
|
329
333
|
}
|
|
330
334
|
async find(query, jingles = []) {
|
|
331
|
-
|
|
335
|
+
const items = jingles.length > 0 ? jingles : await this.getAll();
|
|
332
336
|
const queryParts = query.split(" ");
|
|
333
|
-
const matches =
|
|
334
|
-
(jingle) => queryParts.every((queryPart) =>
|
|
337
|
+
const matches = items.filter(
|
|
338
|
+
(jingle) => queryParts.every((queryPart) => `${jingle.folder}/${jingle.file}`.includes(queryPart))
|
|
335
339
|
);
|
|
336
340
|
return matches.sort((a, b) => {
|
|
337
341
|
const aScore = a.keywords.filter((keyword) => query.includes(keyword)).length;
|
|
@@ -343,26 +347,29 @@ var JingleModule = class extends BaseModule {
|
|
|
343
347
|
|
|
344
348
|
// src/api/k8s.ts
|
|
345
349
|
var K8sModule = class extends BaseModule {
|
|
350
|
+
getPods() {
|
|
351
|
+
return this.api.get("k8s");
|
|
352
|
+
}
|
|
346
353
|
async deletePod(podName) {
|
|
347
|
-
return this.api.delete(`k8s/${podName}`);
|
|
354
|
+
return await this.api.delete(`k8s/${podName}`);
|
|
348
355
|
}
|
|
349
356
|
};
|
|
350
357
|
|
|
351
358
|
// src/api/user.ts
|
|
352
359
|
var UserModule = class extends BaseModule {
|
|
353
360
|
async get(userId) {
|
|
354
|
-
return this.cache.cacheOrGet(() => {
|
|
361
|
+
return await this.cache.cacheOrGet(() => {
|
|
355
362
|
const userIdParam = userId ? `/${userId}` : "";
|
|
356
363
|
return this.api.get(`user${userIdParam}`);
|
|
357
364
|
});
|
|
358
365
|
}
|
|
359
366
|
async getAll() {
|
|
360
|
-
return this.cache.cacheOrGet(() => {
|
|
367
|
+
return await this.cache.cacheOrGet(() => {
|
|
361
368
|
return this.api.get("user/all");
|
|
362
369
|
});
|
|
363
370
|
}
|
|
364
371
|
async setWindowState(setWindowStateDto) {
|
|
365
|
-
return this.api.putPossibleEmptyResponse("user/windowState", setWindowStateDto);
|
|
372
|
+
return await this.api.putPossibleEmptyResponse("user/windowState", setWindowStateDto);
|
|
366
373
|
}
|
|
367
374
|
};
|
|
368
375
|
|
|
@@ -411,7 +418,7 @@ var TssApi = class {
|
|
|
411
418
|
let response;
|
|
412
419
|
try {
|
|
413
420
|
response = await fetch(fullUrl, config);
|
|
414
|
-
} catch (
|
|
421
|
+
} catch (_e) {
|
|
415
422
|
throw new ErrorResponse(503, "API erg dood");
|
|
416
423
|
}
|
|
417
424
|
if (response.status >= 400) {
|
|
@@ -420,7 +427,7 @@ var TssApi = class {
|
|
|
420
427
|
}
|
|
421
428
|
return response;
|
|
422
429
|
}
|
|
423
|
-
|
|
430
|
+
fetchPossibleEmptyResponse(method, url, dto, config = {}) {
|
|
424
431
|
return this.fetch(url, {
|
|
425
432
|
method,
|
|
426
433
|
...config,
|
|
@@ -429,7 +436,7 @@ var TssApi = class {
|
|
|
429
436
|
}
|
|
430
437
|
async get(url) {
|
|
431
438
|
const response = await this.fetch(url);
|
|
432
|
-
return response.json();
|
|
439
|
+
return await response.json();
|
|
433
440
|
}
|
|
434
441
|
async post(url, dto, config = {}) {
|
|
435
442
|
const response = await this.fetchPossibleEmptyResponse("POST", url, dto, config);
|
|
@@ -438,7 +445,7 @@ var TssApi = class {
|
|
|
438
445
|
}
|
|
439
446
|
return await response.json();
|
|
440
447
|
}
|
|
441
|
-
|
|
448
|
+
postPossibleEmptyResponse(url, dto) {
|
|
442
449
|
return this.fetchPossibleEmptyResponse("POST", url, dto);
|
|
443
450
|
}
|
|
444
451
|
async put(url, dto) {
|
|
@@ -448,10 +455,10 @@ var TssApi = class {
|
|
|
448
455
|
}
|
|
449
456
|
return await response.json();
|
|
450
457
|
}
|
|
451
|
-
|
|
458
|
+
putPossibleEmptyResponse(url, dto) {
|
|
452
459
|
return this.fetchPossibleEmptyResponse("PUT", url, dto);
|
|
453
460
|
}
|
|
454
|
-
|
|
461
|
+
delete(url, config = {}) {
|
|
455
462
|
return this.fetch(url, {
|
|
456
463
|
method: "DELETE",
|
|
457
464
|
...config
|