bkper-js 1.9.3 → 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 +86 -0
- package/lib/model/Bkper.js +26 -0
- package/lib/model/Collection.js +65 -0
- package/lib/model/Integration.js +65 -0
- package/lib/service/collection-service.js +30 -0
- package/lib/service/integration-service.js +1 -3
- package/lib/service/user-service.js +6 -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
|
*
|
|
@@ -436,6 +442,14 @@ export declare class Bkper {
|
|
|
436
442
|
* @returns The retrieved User, for chaining
|
|
437
443
|
*/
|
|
438
444
|
static getUser(): Promise<User>;
|
|
445
|
+
/**
|
|
446
|
+
* Gets the URL to redirect the User to the billing portal.
|
|
447
|
+
*
|
|
448
|
+
* @param returnUrl - The URL to return to after the User has been redirected to the billing portal
|
|
449
|
+
*
|
|
450
|
+
* @returns The URL to redirect the User to the billing portal
|
|
451
|
+
*/
|
|
452
|
+
static getBillingPortalUrl(returnUrl: string): Promise<string | undefined>;
|
|
439
453
|
/**
|
|
440
454
|
* Sets the API [[Config]] object.
|
|
441
455
|
*
|
|
@@ -813,10 +827,46 @@ export declare class Collection {
|
|
|
813
827
|
* @returns The name of this Collection
|
|
814
828
|
*/
|
|
815
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;
|
|
816
848
|
/**
|
|
817
849
|
* @returns All Books of this collection.
|
|
818
850
|
*/
|
|
819
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>;
|
|
820
870
|
}
|
|
821
871
|
|
|
822
872
|
/**
|
|
@@ -1261,6 +1311,36 @@ export declare class Integration {
|
|
|
1261
1311
|
* @returns The Integration's name
|
|
1262
1312
|
*/
|
|
1263
1313
|
getName(): string | undefined;
|
|
1314
|
+
/**
|
|
1315
|
+
* Gets the name of the user who added the Integration.
|
|
1316
|
+
*
|
|
1317
|
+
* @returns The user name of who added the Integration
|
|
1318
|
+
*/
|
|
1319
|
+
getAddedBy(): string | undefined;
|
|
1320
|
+
/**
|
|
1321
|
+
* Gets the agent id of the Integration.
|
|
1322
|
+
*
|
|
1323
|
+
* @returns The Integration's agent id
|
|
1324
|
+
*/
|
|
1325
|
+
getAgentId(): string | undefined;
|
|
1326
|
+
/**
|
|
1327
|
+
* Gets the logo of the Integration.
|
|
1328
|
+
*
|
|
1329
|
+
* @returns The Integration's logo
|
|
1330
|
+
*/
|
|
1331
|
+
getLogo(): string | undefined;
|
|
1332
|
+
/**
|
|
1333
|
+
* Gets the date when the Integration was added.
|
|
1334
|
+
*
|
|
1335
|
+
* @returns The Integration add date in milliseconds
|
|
1336
|
+
*/
|
|
1337
|
+
getDateAddedMs(): string | undefined;
|
|
1338
|
+
/**
|
|
1339
|
+
* Gets the date when the Integration was last updated.
|
|
1340
|
+
*
|
|
1341
|
+
* @returns The Integration last update date in milliseconds
|
|
1342
|
+
*/
|
|
1343
|
+
getLastUpdateMs(): string | undefined;
|
|
1264
1344
|
/**
|
|
1265
1345
|
* Gets the custom properties stored in the Integration.
|
|
1266
1346
|
*
|
|
@@ -1304,6 +1384,12 @@ export declare class Integration {
|
|
|
1304
1384
|
* @returns The Integration, for chainning
|
|
1305
1385
|
*/
|
|
1306
1386
|
deleteProperty(key: string): Integration;
|
|
1387
|
+
/**
|
|
1388
|
+
* Performs remove Integration.
|
|
1389
|
+
*
|
|
1390
|
+
* @returns The removed Integration object
|
|
1391
|
+
*/
|
|
1392
|
+
remove(): Promise<Integration>;
|
|
1307
1393
|
}
|
|
1308
1394
|
|
|
1309
1395
|
/**
|
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
|
*
|
|
@@ -108,6 +121,19 @@ export class Bkper {
|
|
|
108
121
|
return new User(user);
|
|
109
122
|
});
|
|
110
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets the URL to redirect the User to the billing portal.
|
|
126
|
+
*
|
|
127
|
+
* @param returnUrl - The URL to return to after the User has been redirected to the billing portal
|
|
128
|
+
*
|
|
129
|
+
* @returns The URL to redirect the User to the billing portal
|
|
130
|
+
*/
|
|
131
|
+
static getBillingPortalUrl(returnUrl) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
let url = yield UserService.getBillingPortalUrl(returnUrl);
|
|
134
|
+
return url.url;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
111
137
|
/**
|
|
112
138
|
* Sets the API [[Config]] object.
|
|
113
139
|
*
|
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
|
package/lib/model/Integration.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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 * as IntegrationService from '../service/integration-service.js';
|
|
1
11
|
/**
|
|
2
12
|
* This class defines a Integration from an [[User]] to an external service.
|
|
3
13
|
*
|
|
@@ -37,6 +47,46 @@ export class Integration {
|
|
|
37
47
|
getName() {
|
|
38
48
|
return this.payload.name;
|
|
39
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the name of the user who added the Integration.
|
|
52
|
+
*
|
|
53
|
+
* @returns The user name of who added the Integration
|
|
54
|
+
*/
|
|
55
|
+
getAddedBy() {
|
|
56
|
+
return this.payload.addedBy;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the agent id of the Integration.
|
|
60
|
+
*
|
|
61
|
+
* @returns The Integration's agent id
|
|
62
|
+
*/
|
|
63
|
+
getAgentId() {
|
|
64
|
+
return this.payload.agentId;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the logo of the Integration.
|
|
68
|
+
*
|
|
69
|
+
* @returns The Integration's logo
|
|
70
|
+
*/
|
|
71
|
+
getLogo() {
|
|
72
|
+
return this.payload.logo;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets the date when the Integration was added.
|
|
76
|
+
*
|
|
77
|
+
* @returns The Integration add date in milliseconds
|
|
78
|
+
*/
|
|
79
|
+
getDateAddedMs() {
|
|
80
|
+
return this.payload.dateAddedMs;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets the date when the Integration was last updated.
|
|
84
|
+
*
|
|
85
|
+
* @returns The Integration last update date in milliseconds
|
|
86
|
+
*/
|
|
87
|
+
getLastUpdateMs() {
|
|
88
|
+
return this.payload.lastUpdateMs;
|
|
89
|
+
}
|
|
40
90
|
/**
|
|
41
91
|
* Gets the custom properties stored in the Integration.
|
|
42
92
|
*
|
|
@@ -105,5 +155,20 @@ export class Integration {
|
|
|
105
155
|
this.setProperty(key, null);
|
|
106
156
|
return this;
|
|
107
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Performs remove Integration.
|
|
160
|
+
*
|
|
161
|
+
* @returns The removed Integration object
|
|
162
|
+
*/
|
|
163
|
+
remove() {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const bookId = this.getBookId();
|
|
166
|
+
const integrationId = this.getId();
|
|
167
|
+
if (bookId && integrationId) {
|
|
168
|
+
this.payload = yield IntegrationService.deleteIntegration(bookId, integrationId);
|
|
169
|
+
}
|
|
170
|
+
return this;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
108
173
|
}
|
|
109
174
|
//# sourceMappingURL=Integration.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
|
|
@@ -37,9 +37,7 @@ export function updateIntegration(bookId, integration) {
|
|
|
37
37
|
}
|
|
38
38
|
export function deleteIntegration(bookId, id) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations/${id}`)
|
|
41
|
-
.setMethod('DELETE')
|
|
42
|
-
.fetch();
|
|
40
|
+
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations/${id}`).setMethod('DELETE').fetch();
|
|
43
41
|
return res.data;
|
|
44
42
|
});
|
|
45
43
|
}
|
|
@@ -14,4 +14,10 @@ export function getUser() {
|
|
|
14
14
|
return res.data;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
export function getBillingPortalUrl(returnUrl) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const res = yield new HttpApiV5Request(`user/billing/portal`).addParam('returnUrl', returnUrl).fetch();
|
|
20
|
+
return res.data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
17
23
|
//# sourceMappingURL=user-service.js.map
|