bkper-js 1.37.0 → 1.39.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 CHANGED
@@ -724,6 +724,7 @@ export declare class Book {
724
724
 
725
725
 
726
726
 
727
+
727
728
  constructor(payload?: bkper.Book);
728
729
  /**
729
730
  * @returns An immutable copy of the json payload
@@ -1113,6 +1114,10 @@ export declare class Book {
1113
1114
  * ```
1114
1115
  */
1115
1116
  getBalancesReport(query: string): Promise<BalancesReport>;
1117
+ /**
1118
+ * @return The saved queries from this book
1119
+ */
1120
+ getSavedQueries(): Promise<Query[]>;
1116
1121
  }
1117
1122
 
1118
1123
  /**
@@ -2251,6 +2256,39 @@ export declare enum Permission {
2251
2256
  OWNER = "OWNER"
2252
2257
  }
2253
2258
 
2259
+ /**
2260
+ * Defines a saved Query in a [[Book]].
2261
+ *
2262
+ * Queries can be saved on Books by users.
2263
+ *
2264
+ * @public
2265
+ */
2266
+ export declare class Query {
2267
+ payload: bkper.Query;
2268
+
2269
+ constructor(book: Book, payload?: bkper.Query);
2270
+ /**
2271
+ * @returns The wrapped plain json object
2272
+ */
2273
+ json(): bkper.Query;
2274
+ /**
2275
+ * @returns The Query universal identifier
2276
+ */
2277
+ getId(): string | undefined;
2278
+ /**
2279
+ * @return The title of this saved Query
2280
+ */
2281
+ getTitle(): string | undefined;
2282
+ /**
2283
+ * @return This Query string to be executed
2284
+ */
2285
+ getQuery(): string | undefined;
2286
+ /**
2287
+ * Perform delete group.
2288
+ */
2289
+ remove(): Promise<Query>;
2290
+ }
2291
+
2254
2292
  /**
2255
2293
  * This class defines a Template.
2256
2294
  *
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ export { File } from './model/File.js';
19
19
  export { Group } from './model/Group.js';
20
20
  export { Integration } from './model/Integration.js';
21
21
  export { Message } from './model/Message.js';
22
+ export { Query } from './model/Query.js';
22
23
  export { Template } from './model/Template.js';
23
24
  export { Transaction } from './model/Transaction.js';
24
25
  export { TransactionList } from './model/TransactionList.js';
package/lib/model/Book.js CHANGED
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import * as AccountService from '../service/account-service.js';
11
11
  import * as BookService from '../service/book-service.js';
12
+ import * as QueryService from '../service/query-service.js';
12
13
  import * as BalancesService from '../service/balances-service.js';
13
14
  import * as FileService from '../service/file-service.js';
14
15
  import * as GroupService from '../service/group-service.js';
@@ -27,6 +28,7 @@ import { Transaction } from './Transaction.js';
27
28
  import { TransactionList } from './TransactionList.js';
28
29
  import { BalancesReport } from './BalancesReport.js';
29
30
  import { App } from './App.js';
31
+ import { Query } from './Query.js';
30
32
  /**
31
33
  *
32
34
  * A Book represents [General Ledger](https://en.wikipedia.org/wiki/General_ledger) for a company or business, but can also represent a [Ledger](https://en.wikipedia.org/wiki/Ledger) for a project or department
@@ -859,5 +861,17 @@ export class Book {
859
861
  return new BalancesReport(this, balances);
860
862
  });
861
863
  }
864
+ /**
865
+ * @return The saved queries from this book
866
+ */
867
+ getSavedQueries() {
868
+ return __awaiter(this, void 0, void 0, function* () {
869
+ if (this.queries == null) {
870
+ const queryPayloads = yield QueryService.getSavedQueries(this.getId());
871
+ this.queries = queryPayloads.map(payload => new Query(this, payload));
872
+ }
873
+ return this.queries;
874
+ });
875
+ }
862
876
  }
863
877
  //# sourceMappingURL=Book.js.map
@@ -0,0 +1,61 @@
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 QueryService from '../service/query-service.js';
11
+ /**
12
+ * Defines a saved Query in a [[Book]].
13
+ *
14
+ * Queries can be saved on Books by users.
15
+ *
16
+ * @public
17
+ */
18
+ export class Query {
19
+ constructor(book, payload) {
20
+ this.book = book;
21
+ this.payload = payload || {};
22
+ }
23
+ /**
24
+ * @returns The wrapped plain json object
25
+ */
26
+ json() {
27
+ return Object.assign({}, this.payload);
28
+ }
29
+ /**
30
+ * @returns The Query universal identifier
31
+ */
32
+ getId() {
33
+ return this.payload.id;
34
+ }
35
+ /**
36
+ * @return The title of this saved Query
37
+ */
38
+ getTitle() {
39
+ return this.payload.title;
40
+ }
41
+ /**
42
+ * @return This Query string to be executed
43
+ */
44
+ getQuery() {
45
+ return this.payload.query;
46
+ }
47
+ /**
48
+ * Perform delete group.
49
+ */
50
+ remove() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const queryId = this.getId();
53
+ if (!queryId) {
54
+ throw new Error("Query id null!");
55
+ }
56
+ this.payload = yield QueryService.deleteSavedQuery(this.book.getId(), queryId);
57
+ return this;
58
+ });
59
+ }
60
+ }
61
+ //# sourceMappingURL=Query.js.map
@@ -0,0 +1,24 @@
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 { HttpBooksApiV5Request } from "./http-api-request.js";
11
+ export function getSavedQueries(bookId) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ var _a;
14
+ let response = yield new HttpBooksApiV5Request(`${bookId}/queries`).setMethod('GET').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 deleteSavedQuery(bookId, queryId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ let response = yield new HttpBooksApiV5Request(`${bookId}/queries/${queryId}`).setMethod('DELETE').fetch();
21
+ return response.data;
22
+ });
23
+ }
24
+ //# sourceMappingURL=query-service.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.37.0",
3
+ "version": "1.39.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",