tering-serieuze-sdk 2.0.0 → 2.0.1
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 +10 -10
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/cache/filesystemCache.ts +7 -7
- package/src/cache/onePasswordCache.ts +3 -3
package/dist/index.mjs
CHANGED
|
@@ -54,7 +54,7 @@ var CookieCache = class extends AbstractCache {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
// src/cache/filesystemCache.ts
|
|
57
|
-
import
|
|
57
|
+
import fs from "fs";
|
|
58
58
|
import path from "path";
|
|
59
59
|
import os from "os";
|
|
60
60
|
var FilesystemCache = class extends AbstractCache {
|
|
@@ -95,22 +95,22 @@ var FilesystemCache = class extends AbstractCache {
|
|
|
95
95
|
}
|
|
96
96
|
clear() {
|
|
97
97
|
this.state = {};
|
|
98
|
-
unlinkSync(this.getFilePath());
|
|
98
|
+
fs.unlinkSync(this.getFilePath());
|
|
99
99
|
}
|
|
100
100
|
getFilePath() {
|
|
101
101
|
return path.join(os.homedir(), ".tss", `${this.cacheName}.json`);
|
|
102
102
|
}
|
|
103
103
|
_initialize() {
|
|
104
104
|
this.initialized = true;
|
|
105
|
-
if (existsSync(this.getFilePath())) {
|
|
106
|
-
this.state = JSON.parse(readFileSync(this.getFilePath(), "utf8"));
|
|
105
|
+
if (fs.existsSync(this.getFilePath())) {
|
|
106
|
+
this.state = JSON.parse(fs.readFileSync(this.getFilePath(), "utf8"));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
writeState() {
|
|
110
|
-
if (!existsSync(path.dirname(this.getFilePath()))) {
|
|
111
|
-
mkdirSync(path.dirname(this.getFilePath()));
|
|
110
|
+
if (!fs.existsSync(path.dirname(this.getFilePath()))) {
|
|
111
|
+
fs.mkdirSync(path.dirname(this.getFilePath()));
|
|
112
112
|
}
|
|
113
|
-
writeFileSync(this.getFilePath(), JSON.stringify(this.state));
|
|
113
|
+
fs.writeFileSync(this.getFilePath(), JSON.stringify(this.state));
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
@@ -131,10 +131,10 @@ var NullCache = class extends AbstractCache {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// src/cache/onePasswordCache.ts
|
|
134
|
-
import
|
|
135
|
-
import
|
|
134
|
+
import util from "util";
|
|
135
|
+
import child_process from "child_process";
|
|
136
136
|
var OnePasswordCache = class extends AbstractCache {
|
|
137
|
-
asyncExec = promisify(exec);
|
|
137
|
+
asyncExec = util.promisify(child_process.exec);
|
|
138
138
|
cacheOrGet(callbackWhenEmpty, key, lifetime) {
|
|
139
139
|
throw new Error("Not implemented, use get() and set()");
|
|
140
140
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/cache/abstractCache.ts", "../src/cache/cookieCache.ts", "../src/cache/filesystemCache.ts", "../src/cache/nullCache.ts", "../src/cache/onePasswordCache.ts", "../src/api/base.ts", "../src/api/auth.ts", "../src/api/jingle.ts", "../src/api/user.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { get } from \"stack-trace\";\n\nexport enum CacheLifetime {\n Day = 60 * 60 * 24,\n Week = 60 * 60 * 24 * 7,\n}\n\nexport abstract class AbstractCache {\n constructor(protected cacheName: string) {}\n\n public abstract cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T>;\n\n public abstract get<T>(key: string): Promise<T | undefined>;\n\n public abstract set<T>(key: string, value: T, lifetime?: number): void;\n\n public abstract remove(key: string): void;\n\n public abstract clear(): void;\n\n public getCacheKey(): string {\n const errorMessage = \"Could not determine cache key. Please provide a key manually.\";\n const trace = get();\n if (trace.length < 3) {\n throw new Error(errorMessage);\n }\n\n const functionName = get()[2].getFunctionName();\n if (!functionName) {\n throw new Error(errorMessage);\n }\n\n return functionName;\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\n\nexport class CookieCache extends AbstractCache {\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n throw new Error(\"Not implemented, use get() and set()\");\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n if (document.cookie.includes(`${key}=`)) {\n return document.cookie.split(`${key}=`)[1]?.split(\";\")[0] as T;\n }\n\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {\n const expires = lifetime ? new Date(Date.now() + lifetime).toUTCString() : \"\";\n document.cookie = `${key}=${value}; expires=${expires}; path=/; samesite=strict; secure`;\n }\n\n public remove(key: string): void {\n document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;\n }\n\n public clear(): void {\n throw new Error(\"Not implemented, use remove()\");\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\nimport { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from \"fs\";\nimport path from \"path\";\nimport os from \"os\";\n\ntype CacheItem = {\n value: any;\n expiresAt?: number;\n};\n\nexport class FilesystemCache extends AbstractCache {\n protected initialized = false;\n\n protected state: { [key: string]: CacheItem } = {};\n\n public async cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n key = key ?? this.getCacheKey();\n\n const cachedValue = await this.get<T>(key);\n if (cachedValue) {\n return cachedValue;\n }\n\n const result = await callbackWhenEmpty();\n this.set(key, result, lifetime);\n return result;\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n // TODO iets met # (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)\n if (!this.initialized) {\n await this._initialize();\n }\n\n const expires = this.state[key]?.expiresAt;\n if (Object.keys(this.state).includes(key) && (expires === undefined || expires > Date.now())) {\n return this.state[key].value;\n }\n\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {\n const expiresAt = lifetime ? Date.now() + lifetime : undefined;\n const content: CacheItem = { value };\n if (expiresAt) {\n content.expiresAt = expiresAt;\n }\n this.state[key] = content;\n this.writeState();\n }\n\n public remove(key: string): void {\n delete this.state[key];\n this.writeState();\n }\n\n public clear(): void {\n this.state = {};\n unlinkSync(this.getFilePath());\n }\n\n public getFilePath() {\n return path.join(os.homedir(), \".tss\", `${this.cacheName}.json`);\n }\n\n protected _initialize() {\n this.initialized = true;\n if (existsSync(this.getFilePath())) {\n this.state = JSON.parse(readFileSync(this.getFilePath(), \"utf8\"));\n }\n }\n\n protected writeState() {\n if (!existsSync(path.dirname(this.getFilePath()))) {\n mkdirSync(path.dirname(this.getFilePath()));\n }\n\n writeFileSync(this.getFilePath(), JSON.stringify(this.state));\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\n\nexport class NullCache extends AbstractCache {\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n return callbackWhenEmpty();\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {}\n\n public remove(key: string): void {}\n\n public clear(): void {}\n}\n", "import { AbstractCache } from \"./abstractCache\";\nimport { promisify } from \"util\";\nimport { exec } from \"child_process\";\n\n// TODO error handling en lifetime\nexport class OnePasswordCache extends AbstractCache {\n protected asyncExec = promisify(exec);\n\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n throw new Error(\"Not implemented, use get() and set()\");\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n const { stdout, stderr } = await this.asyncExec(`op item get \"${key}\" --fields label=credential --format json`);\n\n if (stderr) {\n console.log(stderr);\n throw new Error(\"ERROR\");\n }\n\n return JSON.parse(stdout).value;\n }\n\n public async set<T>(key: string, value: T, lifetime?: number): Promise<void> {\n let action = `op item edit '${key}' 'credential=${value}'`;\n\n try {\n const t = await this.get(key);\n } catch (e) {\n action = `op item create --category=\"API Credential\" --title ${key} 'credential=${value}'`;\n }\n\n const { stdout, stderr } = await this.asyncExec(action);\n\n if (stderr) {\n console.log(stderr);\n throw new Error(\"ERROR\");\n }\n }\n\n public async remove(key: string): Promise<void> {\n await this.asyncExec(`op item delete '${key}'`);\n }\n\n public clear(): void {\n // Loopje maken en heel 1password leeg maken?\n }\n}\n", "import { AbstractCache } from \"../cache\";\nimport { TssApi } from \"../index\";\n\nexport class BaseModule {\n constructor(protected api: TssApi, protected cache: AbstractCache) {}\n\n public getCache() {\n return this.cache;\n }\n\n public setCache(cache: AbstractCache) {\n this.cache = cache;\n }\n}\n", "import { BaseModule } from \"./base\";\n\nexport class AuthModule extends BaseModule {\n public static cacheKey = \"TSS-TOKEN\";\n\n async getToken(): Promise<string | undefined> {\n return this.cache.get(AuthModule.cacheKey);\n }\n\n async setToken(token: string, lifetime?: number) {\n return this.cache.set(AuthModule.cacheKey, token, lifetime);\n }\n\n async setCode(code: string) {\n // TODO any ?!\n const { accessToken } = await this.api.post<any>(`auth/setCode?code=${code}`, {});\n return accessToken;\n }\n\n async removeToken() {\n return this.cache.remove(AuthModule.cacheKey);\n }\n}\n", "import { JingleFolder, Jingle, PlayJingleDto } from \"tering-serieuze-types\";\nimport { BaseModule } from \"./base\";\nimport { CacheLifetime } from \"../cache\";\n\nexport class JingleModule extends BaseModule {\n async getGrouped() {\n return this.cache.cacheOrGet(\n () => {\n return this.api.get<JingleFolder[]>(\"jingle/grouped\");\n },\n \"getGrouped\",\n CacheLifetime.Week\n );\n }\n\n async getAll() {\n return this.cache.cacheOrGet(\n () => {\n return this.api.get<Jingle[]>(\"jingle\");\n },\n \"getAll\",\n CacheLifetime.Week\n );\n }\n\n async play(playJingleDto: PlayJingleDto) {\n console.log(`Playing jingle ${playJingleDto.folder}/${playJingleDto.file}`);\n return this.api.post(\"jingle/play\", playJingleDto);\n }\n}\n", "import { BaseModule } from \"./base\";\nimport { SetWindowStateDto, User } from \"tering-serieuze-types\";\n\nexport class UserModule extends BaseModule {\n async get(userId?: string) {\n return this.cache.cacheOrGet(() => {\n const userIdParam = userId ? `/${userId}` : \"\";\n return this.api.get<User>(`user${userIdParam}`);\n });\n }\n\n async getAll() {\n return this.cache.cacheOrGet(() => {\n return this.api.get<User[]>(\"user/all\");\n });\n }\n\n async setWindowState(setWindowStateDto: SetWindowStateDto) {\n return this.api.put(\"user/windowState\", setWindowStateDto);\n }\n}\n", "import { AbstractCache, NullCache } from \"./cache\";\nimport { AuthModule, JingleModule, UserModule } from \"./api\";\nimport {\n BadRequestException,\n ForbiddenException,\n NotFoundException,\n UnauthorizedException,\n UnprocessableEntityException,\n InternalServerErrorException,\n GatewayTimeoutException,\n BadGatewayException,\n ConflictException,\n GoneException,\n HttpVersionNotSupportedException,\n ImATeapotException,\n MethodNotAllowedException,\n MisdirectedException,\n NotAcceptableException,\n NotImplementedException,\n PayloadTooLargeException,\n PreconditionFailedException,\n RequestTimeoutException,\n ServiceUnavailableException,\n UnsupportedMediaTypeException,\n} from \"@nestjs/common\";\nimport { Dto } from \"tering-serieuze-types\";\n\nexport * from \"./api\";\nexport * from \"./cache\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\nexport interface SDKRequestInit extends RequestInit {\n method?: HttpMethod;\n}\n\nexport enum CacheType {\n jingle = \"jingle\",\n auth = \"auth\",\n user = \"user\",\n}\n\nexport type ApiConfiguration = {\n API_URL: string;\n};\n\nexport type CacheConfiguration = {\n [key in keyof typeof CacheType]?: AbstractCache;\n};\n\nexport class TssApi {\n auth: AuthModule;\n\n jingle: JingleModule;\n\n user: UserModule;\n\n constructor(protected readonly apiConfiguration: ApiConfiguration, cacheConfiguration?: CacheConfiguration) {\n this.jingle = new JingleModule(this, cacheConfiguration?.jingle ?? new NullCache(\"jingle\"));\n this.auth = new AuthModule(this, cacheConfiguration?.auth ?? new NullCache(\"auth\"));\n this.user = new UserModule(this, cacheConfiguration?.user ?? new NullCache(\"user\"));\n }\n\n async fetch(url: string, config: SDKRequestInit = {}) {\n config.method = config.method ?? \"GET\";\n config.headers = {\n ...config.headers,\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${await this.auth.getToken()}`,\n };\n\n const apiPrefix = this.apiConfiguration.API_URL;\n\n if (apiPrefix.match(/^https?:\\/\\/localhost/) !== null && typeof process !== \"undefined\" && process.env) {\n process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;\n }\n\n const fullUrl = `${apiPrefix}/api/${url}`;\n console.log(\"Fetching url\", fullUrl);\n\n let response;\n try {\n response = await fetch(fullUrl, config);\n } catch (e) {\n throw new GatewayTimeoutException(\"API erg dood\");\n }\n\n if (response.status >= 400) {\n const error = await response.json();\n switch (response.status) {\n case 400:\n throw new BadRequestException(error);\n case 401:\n throw new UnauthorizedException(error);\n case 403:\n throw new ForbiddenException(error);\n case 404:\n throw new NotFoundException(error);\n case 405:\n throw new MethodNotAllowedException(error);\n case 406:\n throw new NotAcceptableException(error);\n case 408:\n throw new RequestTimeoutException(error);\n case 409:\n throw new ConflictException(error);\n case 410:\n throw new GoneException(error);\n case 412:\n throw new PreconditionFailedException(error);\n case 413:\n throw new PayloadTooLargeException(error);\n case 415:\n throw new UnsupportedMediaTypeException(error);\n case 418:\n throw new ImATeapotException(error);\n case 421:\n throw new MisdirectedException(error);\n case 422:\n throw new UnprocessableEntityException(error);\n case 500:\n throw new InternalServerErrorException(error);\n case 501:\n throw new NotImplementedException(error);\n case 502:\n throw new BadGatewayException(error);\n case 503:\n throw new ServiceUnavailableException(error);\n case 504:\n throw new GatewayTimeoutException(error);\n case 505:\n throw new HttpVersionNotSupportedException(error);\n }\n }\n\n return response;\n }\n\n protected async fetchPossibleEmptyResponse<T>(method: HttpMethod, url: string, dto: Dto) {\n const response = await this.fetch(url, {\n method,\n body: JSON.stringify(dto),\n });\n\n if (response.status === 204) {\n return;\n }\n\n return response.json() as Promise<T>;\n }\n\n async get<T>(url: string) {\n const response = await this.fetch(url);\n return response.json() as Promise<T>;\n }\n\n async post<T>(url: string, dto: Dto) {\n return this.fetchPossibleEmptyResponse<T>(\"POST\", url, dto);\n }\n\n async put<T>(url: string, dto: Dto) {\n return this.fetchPossibleEmptyResponse<T>(\"PUT\", url, dto);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAAA,SAAS,WAAW;AAEb,IAAK,gBAAL,kBAAKA,mBAAL;AACH,EAAAA,8BAAA,SAAM,SAAN;AACA,EAAAA,8BAAA,UAAO,UAAP;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAe,gBAAf,MAA6B;AAAA,EAChC,YAAsB,WAAmB;AAAnB;AAAA,EAAoB;AAAA,EAYnC,cAAsB;AACzB,UAAM,eAAe;AACrB,UAAM,QAAQ,IAAI;AAClB,QAAI,MAAM,SAAS,GAAG;AAClB,YAAM,IAAI,MAAM,YAAY;AAAA,IAChC;AAEA,UAAM,eAAe,IAAI,EAAE,CAAC,EAAE,gBAAgB;AAC9C,QAAI,CAAC,cAAc;AACf,YAAM,IAAI,MAAM,YAAY;AAAA,IAChC;AAEA,WAAO;AAAA,EACX;AACJ;;;AChCO,IAAM,cAAN,cAA0B,cAAc;AAAA,EACpC,WAAc,mBAAqC,KAAc,UAA+B;AACnG,UAAM,IAAI,MAAM,sCAAsC;AAAA,EAC1D;AAAA,EAEA,MAAa,IAAO,KAAqC;AACrD,QAAI,SAAS,OAAO,SAAS,GAAG,MAAM,GAAG;AACrC,aAAO,SAAS,OAAO,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,CAAC;AAAA,IAC5D;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,IAAO,KAAa,OAAU,UAAyB;AAC1D,UAAM,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,IAAI,QAAQ,EAAE,YAAY,IAAI;AAC3E,aAAS,SAAS,GAAG,OAAO,kBAAkB;AAAA,EAClD;AAAA,EAEO,OAAO,KAAmB;AAC7B,aAAS,SAAS,GAAG;AAAA,EACzB;AAAA,EAEO,QAAc;AACjB,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACnD;AACJ;;;AC1BA,
|
|
4
|
+
"sourcesContent": ["import { get } from \"stack-trace\";\n\nexport enum CacheLifetime {\n Day = 60 * 60 * 24,\n Week = 60 * 60 * 24 * 7,\n}\n\nexport abstract class AbstractCache {\n constructor(protected cacheName: string) {}\n\n public abstract cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T>;\n\n public abstract get<T>(key: string): Promise<T | undefined>;\n\n public abstract set<T>(key: string, value: T, lifetime?: number): void;\n\n public abstract remove(key: string): void;\n\n public abstract clear(): void;\n\n public getCacheKey(): string {\n const errorMessage = \"Could not determine cache key. Please provide a key manually.\";\n const trace = get();\n if (trace.length < 3) {\n throw new Error(errorMessage);\n }\n\n const functionName = get()[2].getFunctionName();\n if (!functionName) {\n throw new Error(errorMessage);\n }\n\n return functionName;\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\n\nexport class CookieCache extends AbstractCache {\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n throw new Error(\"Not implemented, use get() and set()\");\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n if (document.cookie.includes(`${key}=`)) {\n return document.cookie.split(`${key}=`)[1]?.split(\";\")[0] as T;\n }\n\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {\n const expires = lifetime ? new Date(Date.now() + lifetime).toUTCString() : \"\";\n document.cookie = `${key}=${value}; expires=${expires}; path=/; samesite=strict; secure`;\n }\n\n public remove(key: string): void {\n document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;\n }\n\n public clear(): void {\n throw new Error(\"Not implemented, use remove()\");\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport os from \"os\";\n\ntype CacheItem = {\n value: any;\n expiresAt?: number;\n};\n\nexport class FilesystemCache extends AbstractCache {\n protected initialized = false;\n\n protected state: { [key: string]: CacheItem } = {};\n\n public async cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n key = key ?? this.getCacheKey();\n\n const cachedValue = await this.get<T>(key);\n if (cachedValue) {\n return cachedValue;\n }\n\n const result = await callbackWhenEmpty();\n this.set(key, result, lifetime);\n return result;\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n if (!this.initialized) {\n await this._initialize();\n }\n\n const expires = this.state[key]?.expiresAt;\n if (Object.keys(this.state).includes(key) && (expires === undefined || expires > Date.now())) {\n return this.state[key].value;\n }\n\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {\n const expiresAt = lifetime ? Date.now() + lifetime : undefined;\n const content: CacheItem = { value };\n if (expiresAt) {\n content.expiresAt = expiresAt;\n }\n this.state[key] = content;\n this.writeState();\n }\n\n public remove(key: string): void {\n delete this.state[key];\n this.writeState();\n }\n\n public clear(): void {\n this.state = {};\n fs.unlinkSync(this.getFilePath());\n }\n\n public getFilePath() {\n return path.join(os.homedir(), \".tss\", `${this.cacheName}.json`);\n }\n\n protected _initialize() {\n this.initialized = true;\n if (fs.existsSync(this.getFilePath())) {\n this.state = JSON.parse(fs.readFileSync(this.getFilePath(), \"utf8\"));\n }\n }\n\n protected writeState() {\n if (!fs.existsSync(path.dirname(this.getFilePath()))) {\n fs.mkdirSync(path.dirname(this.getFilePath()));\n }\n\n fs.writeFileSync(this.getFilePath(), JSON.stringify(this.state));\n }\n}\n", "import { AbstractCache } from \"./abstractCache\";\n\nexport class NullCache extends AbstractCache {\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n return callbackWhenEmpty();\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n return undefined;\n }\n\n public set<T>(key: string, value: T, lifetime?: number): void {}\n\n public remove(key: string): void {}\n\n public clear(): void {}\n}\n", "import { AbstractCache } from \"./abstractCache\";\nimport util from \"util\";\nimport child_process from \"child_process\";\n\n// TODO error handling en lifetime\nexport class OnePasswordCache extends AbstractCache {\n protected asyncExec = util.promisify(child_process.exec);\n\n public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {\n throw new Error(\"Not implemented, use get() and set()\");\n }\n\n public async get<T>(key: string): Promise<T | undefined> {\n const { stdout, stderr } = await this.asyncExec(`op item get \"${key}\" --fields label=credential --format json`);\n\n if (stderr) {\n console.log(stderr);\n throw new Error(\"ERROR\");\n }\n\n return JSON.parse(stdout).value;\n }\n\n public async set<T>(key: string, value: T, lifetime?: number): Promise<void> {\n let action = `op item edit '${key}' 'credential=${value}'`;\n\n try {\n const t = await this.get(key);\n } catch (e) {\n action = `op item create --category=\"API Credential\" --title ${key} 'credential=${value}'`;\n }\n\n const { stdout, stderr } = await this.asyncExec(action);\n\n if (stderr) {\n console.log(stderr);\n throw new Error(\"ERROR\");\n }\n }\n\n public async remove(key: string): Promise<void> {\n await this.asyncExec(`op item delete '${key}'`);\n }\n\n public clear(): void {\n // Loopje maken en heel 1password leeg maken?\n }\n}\n", "import { AbstractCache } from \"../cache\";\nimport { TssApi } from \"../index\";\n\nexport class BaseModule {\n constructor(protected api: TssApi, protected cache: AbstractCache) {}\n\n public getCache() {\n return this.cache;\n }\n\n public setCache(cache: AbstractCache) {\n this.cache = cache;\n }\n}\n", "import { BaseModule } from \"./base\";\n\nexport class AuthModule extends BaseModule {\n public static cacheKey = \"TSS-TOKEN\";\n\n async getToken(): Promise<string | undefined> {\n return this.cache.get(AuthModule.cacheKey);\n }\n\n async setToken(token: string, lifetime?: number) {\n return this.cache.set(AuthModule.cacheKey, token, lifetime);\n }\n\n async setCode(code: string) {\n // TODO any ?!\n const { accessToken } = await this.api.post<any>(`auth/setCode?code=${code}`, {});\n return accessToken;\n }\n\n async removeToken() {\n return this.cache.remove(AuthModule.cacheKey);\n }\n}\n", "import { JingleFolder, Jingle, PlayJingleDto } from \"tering-serieuze-types\";\nimport { BaseModule } from \"./base\";\nimport { CacheLifetime } from \"../cache\";\n\nexport class JingleModule extends BaseModule {\n async getGrouped() {\n return this.cache.cacheOrGet(\n () => {\n return this.api.get<JingleFolder[]>(\"jingle/grouped\");\n },\n \"getGrouped\",\n CacheLifetime.Week\n );\n }\n\n async getAll() {\n return this.cache.cacheOrGet(\n () => {\n return this.api.get<Jingle[]>(\"jingle\");\n },\n \"getAll\",\n CacheLifetime.Week\n );\n }\n\n async play(playJingleDto: PlayJingleDto) {\n console.log(`Playing jingle ${playJingleDto.folder}/${playJingleDto.file}`);\n return this.api.post(\"jingle/play\", playJingleDto);\n }\n}\n", "import { BaseModule } from \"./base\";\nimport { SetWindowStateDto, User } from \"tering-serieuze-types\";\n\nexport class UserModule extends BaseModule {\n async get(userId?: string) {\n return this.cache.cacheOrGet(() => {\n const userIdParam = userId ? `/${userId}` : \"\";\n return this.api.get<User>(`user${userIdParam}`);\n });\n }\n\n async getAll() {\n return this.cache.cacheOrGet(() => {\n return this.api.get<User[]>(\"user/all\");\n });\n }\n\n async setWindowState(setWindowStateDto: SetWindowStateDto) {\n return this.api.put(\"user/windowState\", setWindowStateDto);\n }\n}\n", "import { AbstractCache, NullCache } from \"./cache\";\nimport { AuthModule, JingleModule, UserModule } from \"./api\";\nimport {\n BadRequestException,\n ForbiddenException,\n NotFoundException,\n UnauthorizedException,\n UnprocessableEntityException,\n InternalServerErrorException,\n GatewayTimeoutException,\n BadGatewayException,\n ConflictException,\n GoneException,\n HttpVersionNotSupportedException,\n ImATeapotException,\n MethodNotAllowedException,\n MisdirectedException,\n NotAcceptableException,\n NotImplementedException,\n PayloadTooLargeException,\n PreconditionFailedException,\n RequestTimeoutException,\n ServiceUnavailableException,\n UnsupportedMediaTypeException,\n} from \"@nestjs/common\";\nimport { Dto } from \"tering-serieuze-types\";\n\nexport * from \"./api\";\nexport * from \"./cache\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\nexport interface SDKRequestInit extends RequestInit {\n method?: HttpMethod;\n}\n\nexport enum CacheType {\n jingle = \"jingle\",\n auth = \"auth\",\n user = \"user\",\n}\n\nexport type ApiConfiguration = {\n API_URL: string;\n};\n\nexport type CacheConfiguration = {\n [key in keyof typeof CacheType]?: AbstractCache;\n};\n\nexport class TssApi {\n auth: AuthModule;\n\n jingle: JingleModule;\n\n user: UserModule;\n\n constructor(protected readonly apiConfiguration: ApiConfiguration, cacheConfiguration?: CacheConfiguration) {\n this.jingle = new JingleModule(this, cacheConfiguration?.jingle ?? new NullCache(\"jingle\"));\n this.auth = new AuthModule(this, cacheConfiguration?.auth ?? new NullCache(\"auth\"));\n this.user = new UserModule(this, cacheConfiguration?.user ?? new NullCache(\"user\"));\n }\n\n async fetch(url: string, config: SDKRequestInit = {}) {\n config.method = config.method ?? \"GET\";\n config.headers = {\n ...config.headers,\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${await this.auth.getToken()}`,\n };\n\n const apiPrefix = this.apiConfiguration.API_URL;\n\n if (apiPrefix.match(/^https?:\\/\\/localhost/) !== null && typeof process !== \"undefined\" && process.env) {\n process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;\n }\n\n const fullUrl = `${apiPrefix}/api/${url}`;\n console.log(\"Fetching url\", fullUrl);\n\n let response;\n try {\n response = await fetch(fullUrl, config);\n } catch (e) {\n throw new GatewayTimeoutException(\"API erg dood\");\n }\n\n if (response.status >= 400) {\n const error = await response.json();\n switch (response.status) {\n case 400:\n throw new BadRequestException(error);\n case 401:\n throw new UnauthorizedException(error);\n case 403:\n throw new ForbiddenException(error);\n case 404:\n throw new NotFoundException(error);\n case 405:\n throw new MethodNotAllowedException(error);\n case 406:\n throw new NotAcceptableException(error);\n case 408:\n throw new RequestTimeoutException(error);\n case 409:\n throw new ConflictException(error);\n case 410:\n throw new GoneException(error);\n case 412:\n throw new PreconditionFailedException(error);\n case 413:\n throw new PayloadTooLargeException(error);\n case 415:\n throw new UnsupportedMediaTypeException(error);\n case 418:\n throw new ImATeapotException(error);\n case 421:\n throw new MisdirectedException(error);\n case 422:\n throw new UnprocessableEntityException(error);\n case 500:\n throw new InternalServerErrorException(error);\n case 501:\n throw new NotImplementedException(error);\n case 502:\n throw new BadGatewayException(error);\n case 503:\n throw new ServiceUnavailableException(error);\n case 504:\n throw new GatewayTimeoutException(error);\n case 505:\n throw new HttpVersionNotSupportedException(error);\n }\n }\n\n return response;\n }\n\n protected async fetchPossibleEmptyResponse<T>(method: HttpMethod, url: string, dto: Dto) {\n const response = await this.fetch(url, {\n method,\n body: JSON.stringify(dto),\n });\n\n if (response.status === 204) {\n return;\n }\n\n return response.json() as Promise<T>;\n }\n\n async get<T>(url: string) {\n const response = await this.fetch(url);\n return response.json() as Promise<T>;\n }\n\n async post<T>(url: string, dto: Dto) {\n return this.fetchPossibleEmptyResponse<T>(\"POST\", url, dto);\n }\n\n async put<T>(url: string, dto: Dto) {\n return this.fetchPossibleEmptyResponse<T>(\"PUT\", url, dto);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,SAAS,WAAW;AAEb,IAAK,gBAAL,kBAAKA,mBAAL;AACH,EAAAA,8BAAA,SAAM,SAAN;AACA,EAAAA,8BAAA,UAAO,UAAP;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAe,gBAAf,MAA6B;AAAA,EAChC,YAAsB,WAAmB;AAAnB;AAAA,EAAoB;AAAA,EAYnC,cAAsB;AACzB,UAAM,eAAe;AACrB,UAAM,QAAQ,IAAI;AAClB,QAAI,MAAM,SAAS,GAAG;AAClB,YAAM,IAAI,MAAM,YAAY;AAAA,IAChC;AAEA,UAAM,eAAe,IAAI,EAAE,CAAC,EAAE,gBAAgB;AAC9C,QAAI,CAAC,cAAc;AACf,YAAM,IAAI,MAAM,YAAY;AAAA,IAChC;AAEA,WAAO;AAAA,EACX;AACJ;;;AChCO,IAAM,cAAN,cAA0B,cAAc;AAAA,EACpC,WAAc,mBAAq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AA,QAC3C,KAAK;AACD,gBAAM,IAAI,iCAAiC,KAAK;AAAA,MACxD;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AAAA,EAEA,MAAgB,2BAA8B,QAAoB,KAAa,KAAU;AACrF,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK;AAAA,MACnC;AAAA,MACA,MAAM,KAAK,UAAU,GAAG;AAAA,IAC5B,CAAC;AAED,QAAI,SAAS,WAAW,KAAK;AACzB;AAAA,IACJ;AAEA,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA,EAEA,MAAM,IAAO,KAAa;AACtB,UAAM,WAAW,MAAM,KAAK,MAAM,GAAG;AACrC,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA,EAEA,MAAM,KAAQ,KAAa,KAAU;AACjC,WAAO,KAAK,2BAA8B,QAAQ,KAAK,GAAG;AAAA,EAC9D;AAAA,EAEA,MAAM,IAAO,KAAa,KAAU;AAChC,WAAO,KAAK,2BAA8B,OAAO,KAAK,GAAG;AAAA,EAC7D;AACJ;",
|
|
6
6
|
"names": ["CacheLifetime", "CacheType"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractCache } from "./abstractCache";
|
|
2
|
-
import
|
|
2
|
+
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import os from "os";
|
|
5
5
|
|
|
@@ -56,7 +56,7 @@ export class FilesystemCache extends AbstractCache {
|
|
|
56
56
|
|
|
57
57
|
public clear(): void {
|
|
58
58
|
this.state = {};
|
|
59
|
-
unlinkSync(this.getFilePath());
|
|
59
|
+
fs.unlinkSync(this.getFilePath());
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
public getFilePath() {
|
|
@@ -65,16 +65,16 @@ export class FilesystemCache extends AbstractCache {
|
|
|
65
65
|
|
|
66
66
|
protected _initialize() {
|
|
67
67
|
this.initialized = true;
|
|
68
|
-
if (existsSync(this.getFilePath())) {
|
|
69
|
-
this.state = JSON.parse(readFileSync(this.getFilePath(), "utf8"));
|
|
68
|
+
if (fs.existsSync(this.getFilePath())) {
|
|
69
|
+
this.state = JSON.parse(fs.readFileSync(this.getFilePath(), "utf8"));
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
protected writeState() {
|
|
74
|
-
if (!existsSync(path.dirname(this.getFilePath()))) {
|
|
75
|
-
mkdirSync(path.dirname(this.getFilePath()));
|
|
74
|
+
if (!fs.existsSync(path.dirname(this.getFilePath()))) {
|
|
75
|
+
fs.mkdirSync(path.dirname(this.getFilePath()));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
writeFileSync(this.getFilePath(), JSON.stringify(this.state));
|
|
78
|
+
fs.writeFileSync(this.getFilePath(), JSON.stringify(this.state));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AbstractCache } from "./abstractCache";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import util from "util";
|
|
3
|
+
import child_process from "child_process";
|
|
4
4
|
|
|
5
5
|
// TODO error handling en lifetime
|
|
6
6
|
export class OnePasswordCache extends AbstractCache {
|
|
7
|
-
protected asyncExec = promisify(exec);
|
|
7
|
+
protected asyncExec = util.promisify(child_process.exec);
|
|
8
8
|
|
|
9
9
|
public cacheOrGet<T>(callbackWhenEmpty: () => Promise<T>, key?: string, lifetime?: number): Promise<T> {
|
|
10
10
|
throw new Error("Not implemented, use get() and set()");
|