bkper-js 1.10.0 → 1.11.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/lib/index.d.ts +42 -0
- package/lib/model/Bkper.js +13 -0
- package/lib/model/Collection.js +65 -0
- package/lib/service/collection-service.js +30 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -418,6 +418,12 @@ export declare class Bkper {
|
|
|
418
418
|
* @returns The retrieved list of Books
|
|
419
419
|
*/
|
|
420
420
|
static getBooks(): Promise<Book[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Gets all [[Collections]] the user has access to.
|
|
423
|
+
*
|
|
424
|
+
* @returns The retrieved list of Collections
|
|
425
|
+
*/
|
|
426
|
+
static getCollections(): Promise<Collection[]>;
|
|
421
427
|
/**
|
|
422
428
|
* Gets all [[Apps]] available for the user.
|
|
423
429
|
*
|
|
@@ -821,10 +827,46 @@ export declare class Collection {
|
|
|
821
827
|
* @returns The name of this Collection
|
|
822
828
|
*/
|
|
823
829
|
getName(): string | undefined;
|
|
830
|
+
/**
|
|
831
|
+
* Sets the name of the Collection.
|
|
832
|
+
*
|
|
833
|
+
* @returns This Collection, for chainning.
|
|
834
|
+
*/
|
|
835
|
+
setName(name: string): Collection;
|
|
836
|
+
/**
|
|
837
|
+
* Gets the username of the owner of this Collection
|
|
838
|
+
*
|
|
839
|
+
* @returns The Collection's owner username
|
|
840
|
+
*/
|
|
841
|
+
getOwnerUsername(): string | undefined;
|
|
842
|
+
/**
|
|
843
|
+
* Gets the user permission for this Collection
|
|
844
|
+
*
|
|
845
|
+
* @returns The permission for the current user
|
|
846
|
+
*/
|
|
847
|
+
getPermission(): Permission | undefined;
|
|
824
848
|
/**
|
|
825
849
|
* @returns All Books of this collection.
|
|
826
850
|
*/
|
|
827
851
|
getBooks(): Book[];
|
|
852
|
+
/**
|
|
853
|
+
* Gets the last update date of this Collection
|
|
854
|
+
*
|
|
855
|
+
* @returns The Collection's last update timestamp, in milliseconds
|
|
856
|
+
*/
|
|
857
|
+
getUpdatedAt(): string | undefined;
|
|
858
|
+
/**
|
|
859
|
+
* Performs create new Collection.
|
|
860
|
+
*
|
|
861
|
+
* @returns The created Collection object
|
|
862
|
+
*/
|
|
863
|
+
create(): Promise<Collection>;
|
|
864
|
+
/**
|
|
865
|
+
* Performs update Collection, applying pending changes.
|
|
866
|
+
*
|
|
867
|
+
* @returns The updated Collection object
|
|
868
|
+
*/
|
|
869
|
+
update(): Promise<Collection>;
|
|
828
870
|
}
|
|
829
871
|
|
|
830
872
|
/**
|
package/lib/model/Bkper.js
CHANGED
|
@@ -11,11 +11,13 @@ import { Book } from "./Book.js";
|
|
|
11
11
|
import { App } from "./App.js";
|
|
12
12
|
import * as AppService from '../service/app-service.js';
|
|
13
13
|
import * as BookService from '../service/book-service.js';
|
|
14
|
+
import * as CollectionService from '../service/collection-service.js';
|
|
14
15
|
import * as UserService from '../service/user-service.js';
|
|
15
16
|
import * as TemplateService from '../service/template-service.js';
|
|
16
17
|
import { HttpApiRequest } from '../service/http-api-request.js';
|
|
17
18
|
import { User } from "./User.js";
|
|
18
19
|
import { Template } from "./Template.js";
|
|
20
|
+
import { Collection } from "./Collection.js";
|
|
19
21
|
/**
|
|
20
22
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
21
23
|
*
|
|
@@ -75,6 +77,17 @@ export class Bkper {
|
|
|
75
77
|
return books.map(book => new Book(book));
|
|
76
78
|
});
|
|
77
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets all [[Collections]] the user has access to.
|
|
82
|
+
*
|
|
83
|
+
* @returns The retrieved list of Collections
|
|
84
|
+
*/
|
|
85
|
+
static getCollections() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
let collections = yield CollectionService.loadCollections();
|
|
88
|
+
return collections.map(collection => new Collection(collection));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
78
91
|
/**
|
|
79
92
|
* Gets all [[Apps]] available for the user.
|
|
80
93
|
*
|
package/lib/model/Collection.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { Book } from "./Book.js";
|
|
11
|
+
import * as CollectionService from '../service/collection-service.js';
|
|
2
12
|
/**
|
|
3
13
|
* This class defines a Collection of [[Books]].
|
|
4
14
|
*
|
|
@@ -26,6 +36,31 @@ export class Collection {
|
|
|
26
36
|
getName() {
|
|
27
37
|
return this.payload.name;
|
|
28
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the name of the Collection.
|
|
41
|
+
*
|
|
42
|
+
* @returns This Collection, for chainning.
|
|
43
|
+
*/
|
|
44
|
+
setName(name) {
|
|
45
|
+
this.payload.name = name;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the username of the owner of this Collection
|
|
50
|
+
*
|
|
51
|
+
* @returns The Collection's owner username
|
|
52
|
+
*/
|
|
53
|
+
getOwnerUsername() {
|
|
54
|
+
return this.payload.ownerUsername;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets the user permission for this Collection
|
|
58
|
+
*
|
|
59
|
+
* @returns The permission for the current user
|
|
60
|
+
*/
|
|
61
|
+
getPermission() {
|
|
62
|
+
return this.payload.permission ? this.payload.permission : undefined;
|
|
63
|
+
}
|
|
29
64
|
/**
|
|
30
65
|
* @returns All Books of this collection.
|
|
31
66
|
*/
|
|
@@ -40,5 +75,35 @@ export class Collection {
|
|
|
40
75
|
}
|
|
41
76
|
return books;
|
|
42
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the last update date of this Collection
|
|
80
|
+
*
|
|
81
|
+
* @returns The Collection's last update timestamp, in milliseconds
|
|
82
|
+
*/
|
|
83
|
+
getUpdatedAt() {
|
|
84
|
+
return this.payload.updatedAt;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Performs create new Collection.
|
|
88
|
+
*
|
|
89
|
+
* @returns The created Collection object
|
|
90
|
+
*/
|
|
91
|
+
create() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
this.payload = yield CollectionService.createCollection(this.payload);
|
|
94
|
+
return this;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Performs update Collection, applying pending changes.
|
|
99
|
+
*
|
|
100
|
+
* @returns The updated Collection object
|
|
101
|
+
*/
|
|
102
|
+
update() {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
this.payload = yield CollectionService.updateCollection(this.payload);
|
|
105
|
+
return this;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
43
108
|
}
|
|
44
109
|
//# sourceMappingURL=Collection.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { HttpApiV5Request } from "./http-api-request.js";
|
|
11
|
+
export function loadCollections() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a;
|
|
14
|
+
let response = yield new HttpApiV5Request('collections').fetch();
|
|
15
|
+
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function createCollection(payload) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
let response = yield new HttpApiV5Request('collections').setMethod('POST').setPayload(payload).fetch();
|
|
21
|
+
return response.data;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function updateCollection(payload) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let response = yield new HttpApiV5Request('collections').setMethod('PUT').setPayload(payload).fetch();
|
|
27
|
+
return response.data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=collection-service.js.map
|