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/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AbstractCache, NullCache } from './cache';
|
|
2
|
-
import { AuthModule, JingleModule, K8sModule, UserModule } from './api';
|
|
3
1
|
import type { Dto } from 'tering-serieuze-types';
|
|
2
|
+
import { AuthModule, JingleModule, K8sModule, UserModule } from './api';
|
|
3
|
+
import { AbstractCache, NullCache } from './cache';
|
|
4
4
|
|
|
5
5
|
export * from './api';
|
|
6
6
|
export * from './cache';
|
|
@@ -27,7 +27,10 @@ export type CacheConfiguration = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export class ErrorResponse extends Error {
|
|
30
|
-
constructor(
|
|
30
|
+
constructor(
|
|
31
|
+
public readonly status: number,
|
|
32
|
+
public readonly message: string,
|
|
33
|
+
) {
|
|
31
34
|
super();
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -38,7 +41,10 @@ export class TssApi {
|
|
|
38
41
|
k8s: K8sModule;
|
|
39
42
|
user: UserModule;
|
|
40
43
|
|
|
41
|
-
constructor(
|
|
44
|
+
constructor(
|
|
45
|
+
protected readonly apiConfiguration: ApiConfiguration,
|
|
46
|
+
cacheConfiguration?: CacheConfiguration,
|
|
47
|
+
) {
|
|
42
48
|
this.jingle = new JingleModule(this, cacheConfiguration?.jingle ?? new NullCache('jingle'));
|
|
43
49
|
this.auth = new AuthModule(this, cacheConfiguration?.auth ?? new NullCache('auth'));
|
|
44
50
|
this.k8s = new K8sModule(this, cacheConfiguration?.k8s ?? new NullCache('k8s'));
|
|
@@ -67,10 +73,10 @@ export class TssApi {
|
|
|
67
73
|
const fullUrl = `${apiPrefix}/api/${url}`;
|
|
68
74
|
console.log('Fetching url', fullUrl);
|
|
69
75
|
|
|
70
|
-
let response;
|
|
76
|
+
let response: Response;
|
|
71
77
|
try {
|
|
72
78
|
response = await fetch(fullUrl, config);
|
|
73
|
-
} catch (
|
|
79
|
+
} catch (_e) {
|
|
74
80
|
throw new ErrorResponse(503, 'API erg dood');
|
|
75
81
|
}
|
|
76
82
|
|
|
@@ -82,12 +88,7 @@ export class TssApi {
|
|
|
82
88
|
return response;
|
|
83
89
|
}
|
|
84
90
|
|
|
85
|
-
protected
|
|
86
|
-
method: HttpMethod,
|
|
87
|
-
url: string,
|
|
88
|
-
dto: Dto,
|
|
89
|
-
config: SDKRequestInit = {},
|
|
90
|
-
) {
|
|
91
|
+
protected fetchPossibleEmptyResponse(method: HttpMethod, url: string, dto: Dto, config: SDKRequestInit = {}) {
|
|
91
92
|
return this.fetch(url, {
|
|
92
93
|
method,
|
|
93
94
|
...config,
|
|
@@ -95,36 +96,36 @@ export class TssApi {
|
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
async get<T>(url: string) {
|
|
99
|
+
async get<T>(url: string): Promise<T> {
|
|
99
100
|
const response = await this.fetch(url);
|
|
100
|
-
return response.json() as Promise<T>;
|
|
101
|
+
return (await response.json()) as Promise<T>;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
async post<T>(url: string, dto: Dto, config: SDKRequestInit = {}) {
|
|
104
|
-
const response = await this.fetchPossibleEmptyResponse
|
|
105
|
+
const response = await this.fetchPossibleEmptyResponse('POST', url, dto, config);
|
|
105
106
|
if (response === undefined) {
|
|
106
107
|
throw new Error('Response was undefined');
|
|
107
108
|
}
|
|
108
109
|
return (await response.json()) as Promise<T>;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
postPossibleEmptyResponse(url: string, dto: Dto) {
|
|
112
113
|
return this.fetchPossibleEmptyResponse('POST', url, dto);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
async put<T>(url: string, dto: Dto) {
|
|
116
|
-
const response = await this.fetchPossibleEmptyResponse
|
|
117
|
+
const response = await this.fetchPossibleEmptyResponse('PUT', url, dto);
|
|
117
118
|
if (response === undefined) {
|
|
118
119
|
throw new Error('Response was undefined');
|
|
119
120
|
}
|
|
120
121
|
return (await response.json()) as Promise<T>;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
putPossibleEmptyResponse(url: string, dto: Dto) {
|
|
124
125
|
return this.fetchPossibleEmptyResponse('PUT', url, dto);
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
delete(url: string, config: SDKRequestInit = {}) {
|
|
128
129
|
return this.fetch(url, {
|
|
129
130
|
method: 'DELETE',
|
|
130
131
|
...config,
|
package/test/api/base.test.ts
CHANGED
package/test/api/jingle.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { NullCache, OnePasswordCache, TssApi } from '../../src';
|
|
3
3
|
|
|
4
4
|
describe('Jingle API', () => {
|
|
5
5
|
const api = new TssApi(
|
|
@@ -28,7 +28,7 @@ describe('Jingle API', () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it('Plays a jingle', async () => {
|
|
31
|
-
const result
|
|
31
|
+
const result = await api.jingle.play({ folder: 'keeskankerkachel', file: 'aan.mp3' });
|
|
32
32
|
expect(result.success).toBe(true);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { FilesystemCache } from '../../src
|
|
3
|
-
import { existsSync, unlinkSync, writeFileSync } from 'fs';
|
|
4
|
-
import path from 'path';
|
|
4
|
+
import { FilesystemCache } from '../../src';
|
|
5
5
|
|
|
6
6
|
describe('filesystemCache', () => {
|
|
7
7
|
let cache: FilesystemCache;
|
|
@@ -59,7 +59,7 @@ describe('filesystemCache', () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('Should use the function name as key, when no key is passed', async () => {
|
|
62
|
-
let expected
|
|
62
|
+
let expected = 0;
|
|
63
63
|
await (async function doeHet() {
|
|
64
64
|
expected = await cache.cacheOrGet(() => Promise.resolve(50));
|
|
65
65
|
})();
|
|
@@ -95,7 +95,7 @@ describe('filesystemCache', () => {
|
|
|
95
95
|
expect(cachedValue).toBe(otherCorrectValue);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
it('Should be able to clear the cache',
|
|
98
|
+
it('Should be able to clear the cache', () => {
|
|
99
99
|
expect(existsSync(cache.getFilePath())).toBe(false);
|
|
100
100
|
cache.set('test', 1);
|
|
101
101
|
expect(existsSync(cache.getFilePath())).toBe(true);
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "src",
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"strict": true,
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"module": "ES2022",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"noImplicitAny": true,
|
|
13
|
+
"experimentalDecorators": true,
|
|
14
|
+
"strictPropertyInitialization": false,
|
|
15
|
+
"verbatimModuleSyntax": true
|
|
16
|
+
}
|
|
17
|
+
}
|
package/types/environment.d.ts
CHANGED