Compare commits

...
This repository has been archived on 2019-08-30. You can view files and clone it, but cannot push or open issues or pull requests.

21 Commits

Author SHA1 Message Date
Fabian 933ecc050a Version bump 2019-07-05 14:26:18 +02:00
Fabian 38b2cd8fa4 Fixing some bugs and updating dependencies 2019-07-05 14:25:50 +02:00
Fabian 4b7c9ec6cd Updating to new utils version 2019-03-23 18:31:39 -04:00
Fabian Stamm 92dba5274e improving browser detection 2019-03-08 21:48:21 -05:00
Fabian Stamm c63ff06453 Using native fetch on supported browsers 2019-03-08 21:19:28 -05:00
Fabian Stamm 8e0b859408 Switched to @hibas123/utils package for observable and lock 2019-03-07 19:52:16 -05:00
Fabian Stamm a8d5382ac3 Changing fetch package for better web support 2019-01-20 22:54:01 +01:00
Fabian Stamm b76808022f Adding support for uploading old versions 2019-01-19 16:03:50 +01:00
Fabian Stamm 8dbc2bcb7f adding custom date support and fixing api 2019-01-19 13:15:48 +01:00
Fabian Stamm 2c4a0203d5 Version bump 2019-01-18 19:11:56 +01:00
Fabian Stamm 500bb33689 Adding post id support 2019-01-18 19:11:34 +01:00
Fabian Stamm 9b57728892 Disable jwt request collecting 2019-01-18 15:58:47 +01:00
Unknown 8de05e6b7f Merge remote-tracking branch 'origin/master' 2019-01-18 15:55:27 +01:00
Fabian Stamm baa1f106e6 Making some fields private 2019-01-18 15:52:55 +01:00
Fabian Stamm 7a8cc08d4a Version bump 2018-12-23 23:13:38 +00:00
Fabian Stamm 7f403f4163 'package.json' ändern 2018-12-23 23:11:26 +00:00
Fabian Stamm f24645a6eb Version bump 2018-12-23 23:06:04 +00:00
Fabian Stamm f46f4982e9 Adding compiled output to repository, till it will be published as npm package 2018-12-24 00:05:15 +01:00
Fabian Stamm a1241afd28 '.vscode/settings.json' löschen 2018-12-23 22:57:10 +00:00
Fabian Stamm f11334f814 'package.json' ändern 2018-12-23 22:55:38 +00:00
Fabian Stamm ebde530f76 '.npmignore' ändern 2018-12-23 22:53:58 +00:00
10 changed files with 1569 additions and 808 deletions

8
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules/ node_modules/
yarn.lock yarn.lock
private.pem private.pem
lib/ lib/

View File

@ -1,3 +1,3 @@
tsconfig.json tsconfig.json
src/ node_modules/
node_modules/ .vscode/

View File

@ -1,3 +0,0 @@
{
"cSpell.enabled": false
}

1425
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,29 @@
{ {
"name": "secure-file-wrapper", "name": "@hibas123/secure-file-wrapper",
"version": "2.0.0", "version": "2.5.1",
"main": "lib/index.js", "main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT", "license": "MIT",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"watch": "tsc --watch", "watch": "tsc --watch",
"prepublish": "tsc", "prepublishOnly": "tsc",
"test": "mocha lib/test.js" "test": "mocha lib/test.js"
}, },
"dependencies": { "dependencies": {
"isomorphic-fetch": "^2.2.1" "@hibas123/utils": "^2.1.0",
}, "cross-fetch": "^3.0.4",
"devDependencies": { "uuid": "^3.3.2"
"@types/chai": "^4.1.4", },
"@types/isomorphic-fetch": "^0.0.34", "devDependencies": {
"@types/mocha": "^5.2.2", "@types/chai": "^4.1.4",
"@types/node": "^10.12.18", "@types/mocha": "^5.2.7",
"@types/node-fetch": "^2.1.4", "@types/node": "^12.0.12",
"chai": "^4.1.2", "@types/node-fetch": "^2.3.7",
"mocha": "^5.2.0", "@types/uuid": "^3.4.5",
"typescript": "^3.2.2" "chai": "^4.1.2",
} "mocha": "^6.1.4",
"typescript": "^3.5.2"
}
} }

View File

@ -1,223 +1,250 @@
import Observable from "./observable"; import { Observable, Lock } from "@hibas123/utils";
import Lock from "./lock"; //this references global on node and window in browser
const fetch = typeof window !== "undefined" && typeof window.fetch !== undefined ? window.fetch : require("cross-fetch").default;
export interface IFileVersion {
version: string; export interface IFileVersion {
time: Date; version: string;
preview: string; time: Date;
deleted: boolean; preview: string;
} deleted: boolean;
}
export interface IFile {
_id: string; export interface IFile {
type: string; _id: string;
name: string; type: string;
folder: string; name: string;
deleted: boolean; folder: string;
active: IFileVersion; deleted: boolean;
versions: IFileVersion[]; active: IFileVersion;
user: string; versions: IFileVersion[];
application: string; user: string;
} application: string;
}
export interface IHistory {
file: IFile; export interface IHistory {
history: IFileVersion[]; file: IFile;
} history: IFileVersion[];
}
export class NoConnection extends Error {
type: string; export class NoConnection extends Error {
constructor() { type: string;
super("No connection"); constructor() {
this.type = "noconnection" super("No connection");
} this.type = "noconnection"
} }
}
export class Unauthorized extends Error {
type: string; export class Unauthorized extends Error {
constructor() { type: string;
super("Not authorized"); constructor() {
this.type = "unauthorized" super("Not authorized");
} this.type = "unauthorized"
} }
}
export class NoPermission extends Error {
type: string; export class NoPermission extends Error {
constructor() { type: string;
super("No permission"); constructor() {
this.type = "nopermission" super("No permission");
} this.type = "nopermission"
} }
}
export class NotFound extends Error {
type: string; export class NotFound extends Error {
constructor() { type: string;
super("Not found"); constructor() {
this.type = "notfound" super("Not found");
} this.type = "notfound"
} }
}
export class BadRequest extends Error {
type: string; export class BadRequest extends Error {
constructor() { type: string;
super("Bad request"); constructor() {
this.type = "badrequest" super("Bad request");
} this.type = "badrequest"
} }
}
import * as fetch from "isomorphic-fetch";
function statusParser(res: Response) {
function statusParser(res: Response) { if (res.status !== 200) {
if (res.status !== 200) { switch (res.status) {
switch (res.status) { case 400:
case 400: throw new BadRequest();
throw new BadRequest(); case 404:
case 404: throw new NotFound();
throw new NotFound(); case 403:
case 403: throw new NoPermission();
throw new NoPermission(); case 401:
case 401: throw new Unauthorized();
throw new Unauthorized(); default:
default: throw new Error(res.statusText);
throw new Error(res.statusText); }
} }
} }
}
export type JWTCallback = (err: Error | null | string, jwt: string) => void;
export default class SecureFileWrapper {
private _jwtObservableServer: Observable<(jwt: string) => void> = new Observable(); export default class SecureFileWrapper {
jwtObservable = this._jwtObservableServer.getPublicApi(); private _jwtObservableServer: Observable<JWTCallback> = new Observable();
jwtObservable = this._jwtObservableServer.getPublicApi();
jwt: string;
private jwt: string;
auth_lock = new Lock();
private auth_lock = new Lock();
constructor(private server: string) {
if (this.server.endsWith("/")) { constructor(private server: string) {
this.server += "api/v1"; if (this.server.endsWith("/")) {
} else { this.server += "api/v1";
this.server += "/api/v1"; } else {
} this.server += "/api/v1";
} }
}
public async getJWT() {
if (!this.auth_lock.locked) { public async getJWT() {
let lock = await this.auth_lock.getLock(); if (!this.auth_lock.locked) {
this._jwtObservableServer.send((jwt: string) => { let lock = await this.auth_lock.getLock();
this.jwt = jwt; await new Promise((yes, no) => {
lock.release(); this._jwtObservableServer.send((err: Error | null | string, jwt: string) => {
}); if (err) {
} this.jwt = undefined;
no(err);
await this.auth_lock.getLock().then(lock => lock.release()) }
} else {
this.jwt = jwt;
public async makeRequest(endpoint: string, method: "POST" | "GET" | "PUT" | "DELETE", query: any, body?: ArrayBuffer | ArrayBufferView, second = false) { yes();
if (!this.jwt || this.jwt === undefined) { }
await this.getJWT(); });
} }).finally(() => lock.release())
}
query.jwt = this.jwt;
let query_str = "?"; await this.auth_lock.getLock().then(lock => lock.release())
let first = true; }
for (let key in query) {
if (!first) query_str += "&"; public async makeRequest(endpoint: string, method: "POST" | "GET" | "PUT" | "DELETE", query: any, body?: ArrayBuffer | ArrayBufferView, second = false) {
query_str += encodeURIComponent(key) + "=" + encodeURIComponent(query[key]); if (!this.jwt || this.jwt === undefined) {
first = false; await this.getJWT();
} }
var headers = {
"pragme": "no-cache", query.jwt = this.jwt;
"cache-control": "no-cache" let query_str = "?";
}; let first = true;
for (let key in query) {
let body_n; if (!first) query_str += "&";
if (body) { query_str += encodeURIComponent(key) + "=" + encodeURIComponent(query[key]);
headers["Content-Type"] = "application/octet-stream" first = false;
body_n = Buffer ? Buffer.from(body instanceof ArrayBuffer ? body : body.buffer) : body; }
} var headers = {
try { "pragme": "no-cache",
let res = await fetch(this.server + endpoint + query_str, { method, body: body_n, headers }); "cache-control": "no-cache"
if (res.status === 401 && !second) { };
await this.getJWT();
return this.makeRequest(endpoint, method, query, body, true); if (body) {
} else { headers["Content-Type"] = "application/octet-stream"
statusParser(res); }
return res; try {
} let res = await fetch(this.server + endpoint + query_str, { method, body, headers });
} catch (err) { if (res.status === 401 && !second) {
if (err instanceof TypeError || err.errno === "ECONNREFUSED") await this.getJWT();
throw new NoConnection(); return this.makeRequest(endpoint, method, query, body, true);
throw err; } else {
} statusParser(res);
} return res;
}
// async test(jwt): Promise<{ user: string, test: true }> { } catch (err) {
// let res = await this.makeRequest("/test", "GET", {}, undefined, this.jwt_enabled); if (err instanceof TypeError || err.errno === "ECONNREFUSED")
// statusParser(res); throw new NoConnection();
// return await res.json(); throw err;
// } }
}
async list(folder?: string): Promise<IFile[]> {
let query: any = {} private fixIFileVersion(version: IFileVersion): IFileVersion {
if (folder) query.folder = folder; version.time = new Date(version.time)
let res = await this.makeRequest("/files", "GET", query); return version;
let d = await res.json(); }
return d.files;
} private fixIFile(file: IFile): IFile {
file.active.time = new Date(file.active.time)
async create(name: string, data: ArrayBuffer | ArrayBufferView, type: "text" | "binary", folder?: string, preview?: string): Promise<IFile> { if (file.versions) {
let params: any = { type: type, name: name }; file.versions = file.versions.map(e => this.fixIFileVersion(e))
if (preview) { }
params.preview = preview; return file;
} }
if (folder) {
params.folder = folder; // async test(jwt): Promise<{ user: string, test: true }> {
} // let res = await this.makeRequest("/test", "GET", {}, undefined, this.jwt_enabled);
// statusParser(res);
let res = await this.makeRequest("/files", "POST", params, data); // return await res.json();
return (await res.json()).file; // }
}
async list(folder?: string): Promise<IFile[]> {
async get(id: string, version?: string): Promise<ArrayBuffer> { let query: any = {}
let res: Response; if (folder) query.folder = folder;
if (typeof version === "string") { let res = await this.makeRequest("/files", "GET", query);
res = await this.makeRequest(`/files/${id}/history/${version}`, "GET", {}); let d: { files: IFile[] } = await res.json();
} else { return d.files.map(e => this.fixIFile(e));
res = await this.makeRequest("/files/" + id, "GET", {}); }
}
async create(name: string, data: ArrayBuffer | ArrayBufferView, type: "text" | "binary", folder?: string, preview?: string, id?: string, date?: Date): Promise<IFile> {
if (res.arrayBuffer) { let params: any = { type: type, name: name };
return res.arrayBuffer() if (preview)
} else { params.preview = preview;
let blob: Buffer = await (<any>res).buffer()
// console.log(blob.length); if (folder)
return Uint8Array.from(blob).buffer; params.folder = folder;
}
} if (id)
params.id = id
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string): Promise<IFile> {
let put: any = {}; if (date)
if (preview) put.preview = preview; params.date = date.toJSON()
let res = await this.makeRequest("/files/" + id, "PUT", put, data);
let json = await res.json() let res = await this.makeRequest("/files", "POST", params, data);
return json.file; return this.fixIFile((await res.json()).file);
} }
async delete(id: string): Promise<boolean> { async get(id: string, version?: string): Promise<ArrayBuffer> {
let res = await this.makeRequest("/files/" + id, "DELETE", {}); let res: Response;
if (typeof version === "string") {
return res.json(); res = await this.makeRequest(`/files/${id}/history/${version}`, "GET", {});
} } else {
res = await this.makeRequest("/files/" + id, "GET", {});
async history(id: string): Promise<IHistory> { }
let res = await this.makeRequest(`/files/${id}/history`, "GET", {});
statusParser(res); return res.arrayBuffer()
return res.json(); }
}
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date, old = false): Promise<IFile> {
async restore(id: string, version: string) { let params: any = { old };
await this.makeRequest(`/files/${id}/history/${version}/restore`, "PUT", {}); if (preview) params.preview = preview;
} if (date)
params.date = date.toJSON()
let res = await this.makeRequest("/files/" + id, "PUT", params, data);
let json = await res.json()
return this.fixIFile(json.file);
}
async delete(id: string): Promise<void> {
let res = await this.makeRequest("/files/" + id, "DELETE", {});
}
async history(id: string): Promise<IHistory> {
let res = await this.makeRequest(`/files/${id}/history`, "GET", {});
let data: IHistory = await res.json();
data.file = this.fixIFile(data.file)
data.history = data.history.map(v => this.fixIFileVersion(v));
return data;
}
async restore(id: string, version: string) {
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);
}
} }

View File

@ -1,36 +0,0 @@
export type Release = { release: () => void };
export default class Lock {
private _locked: boolean = false;
get locked() {
return this._locked;
}
private toCome: (() => void)[] = [];
constructor() {
this.release = this.release.bind(this);
}
async getLock(): Promise<Release> {
if (!this._locked) return { release: this.lock() };
else {
return new Promise<Release>((resolve) => {
this.toCome.push(() => {
resolve({ release: this.lock() });
})
})
}
}
private lock() {
this._locked = true;
return this.release;
}
private async release() {
if (this.toCome.length > 0) {
this.toCome.shift()();
} else {
this._locked = false;
}
}
}

View File

@ -1,38 +0,0 @@
export type ObserverCallback<T> = (data: T) => void;
export default class Observable<T = any> {
private subscriber: ObserverCallback<T[]>[] = [];
private events: T[] = [];
private timeout = undefined;
constructor(private collect: boolean = true, private collect_intervall: number = 100) { }
getPublicApi() {
return {
subscribe: (callback: ObserverCallback<T[]>) => {
if (this.subscriber.indexOf(callback) < 0)
this.subscriber.push(callback)
},
unsubscribe: (callback: ObserverCallback<T[]>) => {
let idx = this.subscriber.indexOf(callback);
if (idx >= 0) {
this.subscriber.splice(idx, 1);
}
}
}
}
send(data: T) {
if (!this.collect)
this.subscriber.forEach(e => e([data]));
else {
this.events.push(data);
if (!this.timeout) {
this.timeout = setTimeout(() => {
this.subscriber.forEach(e => e(this.events));
this.timeout = 0;
}, this.collect_intervall);
}
}
}
}

View File

@ -1,130 +1,173 @@
import SecureFile, { NotFound } from "./index"; import SecureFile, { NotFound } from "./index";
import * as v4 from "uuid/v4"
import { TextEncoder, TextDecoder } from "util"; import { TextEncoder, TextDecoder } from "util";
const testname = "ouiavgbsop687463743" const testname = "ouiavgbsop687463743"
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const decoder = new TextDecoder(); const decoder = new TextDecoder();
const testdata = encoder.encode("Ich bin ein Test"); const testdata = encoder.encode("Ich bin ein Test");
const newTestData = encoder.encode("neue test daten"); const newTestData = encoder.encode("neue test daten");
const testprev = "Ich bin..."; const newTestDataOld = encoder.encode("neue test daten asd");
const testprev = "Ich bin...";
const testfolder = "iabos";
let ftestid; const testfolder = "iabos";
let ftestid;
import { expect } from "chai"
import { expect } from "chai"
function test(sf: SecureFile) {
let testid: string; function test(sf: SecureFile) {
let testver: string; let testid: string;
let testver2: string; let testver: string;
let testver2: string;
it("create", async () => {
let res = await sf.create(testname, testdata, "text", undefined, testprev) it("create", async () => {
expect(res, "Res isnnot set").to.exist; let res = await sf.create(testname, testdata, "text", undefined, testprev)
expect(res._id, "Res has no _id").to.exist; expect(res, "Res isnnot set").to.exist;
testid = res._id; expect(res._id, "Res has no _id").to.exist;
testver = res.active.version; testid = res._id;
}) testver = res.active.version;
})
it("get", async () => {
let res = await sf.get(testid); it("get", async () => {
expect(res, "No data returned").to.exist; let res = await sf.get(testid);
expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata)); expect(res, "No data returned").to.exist;
}) expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
})
it("get - fail", async () => {
const inverr = new Error("Should have failed!"); it("get - fail", async () => {
try { const inverr = new Error("Should have failed!");
await sf.get(testid + "asod"); try {
throw inverr await sf.get(testid + "asod");
} catch (err) { throw inverr
if (err !== inverr) { } catch (err) {
expect(err).to.be.instanceOf(NotFound); if (err !== inverr) {
} expect(err).to.be.instanceOf(NotFound);
} }
}) }
})
it("list", async () => {
let res = await sf.list(); it("list", async () => {
expect(Array.isArray(res), "Is not from type Array").to.be.true; let res = await sf.list();
expect(res.length, "No elements returned").to.greaterThan(0); expect(Array.isArray(res), "Is not from type Array").to.be.true;
let found = !!res.find(e => e._id === testid); expect(res.length, "No elements returned").to.greaterThan(0);
expect(found, "Element not in List").to.be.true; let found = !!res.find(e => e._id === testid);
}) expect(found, "Element not in List").to.be.true;
})
it("update", async () => {
let res = await sf.update(testid, newTestData, undefined); it("update to history", async () => {
expect(res, "No data returned").to.exist; let res = await sf.update(testid, newTestDataOld, undefined, undefined, true);
expect(res._id, "_id missing").to.exist; expect(res, "No data returned").to.exist;
expect(res.active.version, "No new version was created").to.not.equal(testver); expect(res._id, "_id missing").to.exist;
testver2 = res.active.version; expect(res.active.version, "New version was created").to.equal(testver);
let res2 = await sf.get(testid); let res2 = await sf.get(testid);
expect(decoder.decode(res2), "Fetched data not updated").to.be.equal(decoder.decode(newTestData)); expect(decoder.decode(res2), "Fetched data not updated").to.be.equal(decoder.decode(testdata));
}) })
it("history", async () => { it("update", async () => {
let his = await sf.history(testid); let res = await sf.update(testid, newTestData, undefined);
expect(his, "no data returned").to.exist; expect(res, "No data returned").to.exist;
expect(his.file, "file not set").to.exist; expect(res._id, "_id missing").to.exist;
expect(his.history, "history not set").to.exist; expect(res.active.version, "No new version was created").to.not.equal(testver);
expect(his.history.length, `Not expected history length. Expected 1 got ${his.history.length}`).to.be.equal(1); testver2 = res.active.version;
let res2 = await sf.get(testid);
expect(his.history[0].version, "Wrong version on history").to.be.equal(testver); expect(decoder.decode(res2), "Fetched data not updated").to.be.equal(decoder.decode(newTestData));
expect(his.file.active.version, "Wrong version on file").to.be.equal(testver2); })
});
it("history", async () => {
it("history get old", async () => { let his = await sf.history(testid);
let arch = await sf.get(testid, testver); expect(his, "no data returned").to.exist;
expect(decoder.decode(arch), "Old version has wrong data").to.be.equal(decoder.decode(testdata)); expect(his.file, "file not set").to.exist;
}) expect(his.history, "history not set").to.exist;
expect(his.history.length, `Not expected history length. Expected 1 got ${his.history.length}`).to.be.equal(2);
it("history restore", async () => {
await sf.restore(testid, testver); expect(his.history[1].version, "Wrong version on history").to.be.equal(testver);
expect(his.file.active.version, "Wrong version on file").to.be.equal(testver2);
let res = await sf.get(testid); });
expect(res, "No data returned").to.exist;
expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata)); it("history get old", async () => {
}) let arch = await sf.get(testid, testver);
expect(decoder.decode(arch), "Old version has wrong data").to.be.equal(decoder.decode(testdata));
it("delete", async () => { })
let res = await sf.delete(testid);
expect(res, "Res not set").to.exist; it("history restore", async () => {
}) await sf.restore(testid, testver);
describe("folder", () => { let res = await sf.get(testid);
it("create", async () => { expect(res, "No data returned").to.exist;
let res = await sf.create(testname, testdata, "text", testfolder, testprev) expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
expect(res, "Res not set").to.exist; })
expect(res._id, "No _id field").to.exist;
ftestid = res._id; it("delete", async () => {
testver = res.active.version; await sf.delete(testid);
}) })
it("list", async () => {
let res = await sf.list(testfolder); describe("fixed id", () => {
expect(Array.isArray(res), "Is from type Array").to.be.true; let id = v4();
expect(res.length, "Do elements exist?").to.be.greaterThan(0); it("create", async () => {
let found = false; let res = await sf.create(testname, testdata, "text", undefined, testprev, id)
res.forEach(e => { expect(res, "Res isnnot set").to.exist;
if (e._id === ftestid) { expect(res._id, "Res has no _id").to.exist;
found = true; expect(res._id, "Res has invalid _id").to.be.equal(id)
} })
})
expect(found, "Element is not in List").to.exist; it("get", async () => {
}) let res = await sf.get(id);
expect(res, "No data returned").to.exist;
it("delete", async () => { expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
let res = await sf.delete(ftestid); })
expect(res, "Res not set").to.exist; })
});
}) describe("predefined date", () => {
} let id = v4();
it("create", async () => {
describe("SecureFile Tests", function () { const date = new Date("2017-01-01T00:00:00.000Z")
let sf = new SecureFile("http://localhost:3004"); let res = await sf.create(testname, testdata, "text", undefined, testprev, id, date)
sf.jwtObservable.subscribe((callback) => { expect(res, "Res isnnot set").to.exist;
callback[0]("TESTJWT"); expect(res._id, "Res has no _id").to.exist;
}) expect(res._id, "Res has invalid _id").to.be.equal(id)
test(sf) expect(res.active.time.toJSON()).to.be.equal(date.toJSON())
})
it("list", async () => {
let res = await sf.get(id);
expect(res, "No data returned").to.exist;
expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
})
})
describe("folder", () => {
it("create", async () => {
let res = await sf.create(testname, testdata, "text", testfolder, testprev)
expect(res, "Res not set").to.exist;
expect(res._id, "No _id field").to.exist;
ftestid = res._id;
testver = res.active.version;
})
it("list", async () => {
let res = await sf.list(testfolder);
expect(Array.isArray(res), "Is from type Array").to.be.true;
expect(res.length, "Do elements exist?").to.be.greaterThan(0);
let found = false;
res.forEach(e => {
if (e._id === ftestid) {
found = true;
}
})
expect(found, "Element is not in List").to.exist;
})
it("delete", async () => {
await sf.delete(ftestid);
});
})
}
describe("SecureFile Tests", function () {
let sf = new SecureFile("http://localhost:3004");
sf.jwtObservable.subscribe((callback) => {
callback(null, "TESTJWT");
})
test(sf)
}) })

View File

@ -1,17 +1,20 @@
{ {
"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",
"lib": [ /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"es6", "declaration": true,
"dom" /* Generates corresponding '.d.ts' file. */
], "lib": [
"outDir": "./lib", "es6",
"sourceMap": true "dom"
}, ],
"include": [ "outDir": "./lib",
"./src" "sourceMap": true
] },
"include": [
"./src"
]
} }