Fixing some bugs and updating dependencies
This commit is contained in:
parent
4b7c9ec6cd
commit
38b2cd8fa4
1433
package-lock.json
generated
1433
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/secure-file-wrapper",
|
"name": "@hibas123/secure-file-wrapper",
|
||||||
"version": "2.4.0",
|
"version": "2.5.0",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -12,18 +12,18 @@
|
|||||||
"test": "mocha lib/test.js"
|
"test": "mocha lib/test.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hibas123/utils": "^2.0.0",
|
"@hibas123/utils": "^2.1.0",
|
||||||
"cross-fetch": "^3.0.1",
|
"cross-fetch": "^3.0.4",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.1.4",
|
"@types/chai": "^4.1.4",
|
||||||
"@types/mocha": "^5.2.6",
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "^11.11.6",
|
"@types/node": "^12.0.12",
|
||||||
"@types/node-fetch": "^2.1.7",
|
"@types/node-fetch": "^2.3.7",
|
||||||
"@types/uuid": "^3.4.4",
|
"@types/uuid": "^3.4.5",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
"mocha": "^6.0.2",
|
"mocha": "^6.1.4",
|
||||||
"typescript": "^3.3.4000"
|
"typescript": "^3.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/index.ts
25
src/index.ts
@ -84,8 +84,10 @@ function statusParser(res: Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type JWTCallback = (err: Error | null | string, jwt: string) => void;
|
||||||
|
|
||||||
export default class SecureFileWrapper {
|
export default class SecureFileWrapper {
|
||||||
private _jwtObservableServer: Observable<(jwt: string) => void> = new Observable();
|
private _jwtObservableServer: Observable<JWTCallback> = new Observable();
|
||||||
jwtObservable = this._jwtObservableServer.getPublicApi();
|
jwtObservable = this._jwtObservableServer.getPublicApi();
|
||||||
|
|
||||||
private jwt: string;
|
private jwt: string;
|
||||||
@ -103,10 +105,18 @@ export default class SecureFileWrapper {
|
|||||||
public async getJWT() {
|
public async getJWT() {
|
||||||
if (!this.auth_lock.locked) {
|
if (!this.auth_lock.locked) {
|
||||||
let lock = await this.auth_lock.getLock();
|
let lock = await this.auth_lock.getLock();
|
||||||
this._jwtObservableServer.send((jwt: string) => {
|
await new Promise((yes, no) => {
|
||||||
this.jwt = jwt;
|
this._jwtObservableServer.send((err: Error | null | string, jwt: string) => {
|
||||||
lock.release();
|
if (err) {
|
||||||
});
|
this.jwt = undefined;
|
||||||
|
no(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jwt = jwt;
|
||||||
|
yes();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).finally(() => lock.release())
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.auth_lock.getLock().then(lock => lock.release())
|
await this.auth_lock.getLock().then(lock => lock.release())
|
||||||
@ -232,4 +242,9 @@ export default class SecureFileWrapper {
|
|||||||
async restore(id: string, version: string) {
|
async restore(id: string, version: string) {
|
||||||
await this.makeRequest(`/files/${id}/history/${version}/restore`, "PUT", {});
|
await this.makeRequest(`/files/${id}/history/${version}/restore`, "PUT", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async clean(id: string, val: number | Date): Promise<void> {
|
||||||
|
let query = typeof val === "number" ? { count: val } : { date: val.toISOString() };
|
||||||
|
return this.makeRequest(`/files/${id}/history/clean`, "PUT", query);
|
||||||
|
}
|
||||||
}
|
}
|
@ -167,7 +167,7 @@ function test(sf: SecureFile) {
|
|||||||
describe("SecureFile Tests", function () {
|
describe("SecureFile Tests", function () {
|
||||||
let sf = new SecureFile("http://localhost:3004");
|
let sf = new SecureFile("http://localhost:3004");
|
||||||
sf.jwtObservable.subscribe((callback) => {
|
sf.jwtObservable.subscribe((callback) => {
|
||||||
callback("TESTJWT");
|
callback(null, "TESTJWT");
|
||||||
})
|
})
|
||||||
test(sf)
|
test(sf)
|
||||||
})
|
})
|
@ -1,9 +1,12 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
"target": "es6",
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
"module": "commonjs",
|
||||||
|
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
|
"declaration": true,
|
||||||
|
/* Generates corresponding '.d.ts' file. */
|
||||||
"lib": [
|
"lib": [
|
||||||
"es6",
|
"es6",
|
||||||
"dom"
|
"dom"
|
||||||
|
Reference in New Issue
Block a user