bkper-js 2.7.1 → 2.8.1
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/CHANGELOG.md +26 -0
- package/lib/index.d.ts +172 -99
- package/lib/model/Account.js +20 -21
- package/lib/model/App.js +72 -21
- package/lib/model/Bkper.js +42 -30
- package/lib/model/Book.js +109 -99
- package/lib/model/BotResponse.js +2 -2
- package/lib/model/Collaborator.js +12 -11
- package/lib/model/Collection.js +24 -19
- package/lib/model/Connection.js +28 -18
- package/lib/model/Conversation.js +20 -13
- package/lib/model/File.js +19 -17
- package/lib/model/Group.js +29 -21
- package/lib/model/Integration.js +17 -13
- package/lib/model/Message.js +20 -16
- package/lib/model/Query.js +12 -11
- package/lib/model/Resource.js +23 -0
- package/lib/model/Template.js +10 -7
- package/lib/model/Transaction.js +61 -43
- package/lib/model/User.js +14 -12
- package/lib/service/account-service.js +12 -12
- package/lib/service/app-service.js +8 -8
- package/lib/service/balances-service.js +2 -2
- package/lib/service/book-service.js +14 -14
- package/lib/service/collaborator-service.js +6 -6
- package/lib/service/collection-service.js +12 -12
- package/lib/service/connection-service.js +12 -15
- package/lib/service/conversation-service.js +10 -10
- package/lib/service/event-service.js +8 -8
- package/lib/service/file-service.js +4 -4
- package/lib/service/group-service.js +16 -16
- package/lib/service/http-api-request.js +54 -45
- package/lib/service/integration-service.js +8 -8
- package/lib/service/query-service.js +8 -8
- package/lib/service/template-service.js +2 -2
- package/lib/service/transaction-service.js +32 -32
- package/lib/service/user-service.js +4 -4
- package/package.json +1 -1
package/lib/model/App.js
CHANGED
|
@@ -7,7 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import * as AppService from
|
|
10
|
+
import * as AppService from "../service/app-service.js";
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
12
|
+
import { Bkper } from "./Bkper.js";
|
|
11
13
|
/**
|
|
12
14
|
* Defines an App on Bkper.
|
|
13
15
|
*
|
|
@@ -15,17 +17,18 @@ import * as AppService from '../service/app-service.js';
|
|
|
15
17
|
*
|
|
16
18
|
* @public
|
|
17
19
|
*/
|
|
18
|
-
export class App {
|
|
19
|
-
constructor(payload) {
|
|
20
|
-
|
|
20
|
+
export class App extends Resource {
|
|
21
|
+
constructor(payload, config) {
|
|
22
|
+
super(payload);
|
|
23
|
+
this.config = config;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
|
-
* Gets the
|
|
26
|
+
* Gets the configuration object for this App.
|
|
24
27
|
*
|
|
25
|
-
* @returns The
|
|
28
|
+
* @returns The Config object for this App or the global config
|
|
26
29
|
*/
|
|
27
|
-
|
|
28
|
-
return
|
|
30
|
+
getConfig() {
|
|
31
|
+
return this.config || Bkper.globalConfig;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* Sets the webhook url for development.
|
|
@@ -90,6 +93,14 @@ export class App {
|
|
|
90
93
|
isPublished() {
|
|
91
94
|
return this.payload.published || false;
|
|
92
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Tells if this App is installable.
|
|
98
|
+
*
|
|
99
|
+
* @returns True if this App is installable
|
|
100
|
+
*/
|
|
101
|
+
isInstallable() {
|
|
102
|
+
return this.payload.installable || false;
|
|
103
|
+
}
|
|
93
104
|
/**
|
|
94
105
|
* Checks if this App is conversational.
|
|
95
106
|
*
|
|
@@ -133,14 +144,6 @@ export class App {
|
|
|
133
144
|
this.payload.userEmails = emails;
|
|
134
145
|
return this;
|
|
135
146
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Gets the name of the owner of this App.
|
|
138
|
-
*
|
|
139
|
-
* @returns The name of the owner of this App
|
|
140
|
-
*/
|
|
141
|
-
getOwnerName() {
|
|
142
|
-
return this.payload.ownerName;
|
|
143
|
-
}
|
|
144
147
|
/**
|
|
145
148
|
* Gets the menu url of this App.
|
|
146
149
|
*
|
|
@@ -181,6 +184,14 @@ export class App {
|
|
|
181
184
|
getMenuPopupHeight() {
|
|
182
185
|
return this.payload.menuPopupHeight;
|
|
183
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Gets the name of the owner of this App.
|
|
189
|
+
*
|
|
190
|
+
* @returns The name of the owner of this App
|
|
191
|
+
*/
|
|
192
|
+
getOwnerName() {
|
|
193
|
+
return this.payload.ownerName;
|
|
194
|
+
}
|
|
184
195
|
/**
|
|
185
196
|
* Gets the logo url of the owner of this App.
|
|
186
197
|
*
|
|
@@ -189,6 +200,14 @@ export class App {
|
|
|
189
200
|
getOwnerLogoUrl() {
|
|
190
201
|
return this.payload.ownerLogoUrl;
|
|
191
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Gets the website url of the owner of this App.
|
|
205
|
+
*
|
|
206
|
+
* @returns The website url of the owner of this App
|
|
207
|
+
*/
|
|
208
|
+
getOwnerWebsiteUrl() {
|
|
209
|
+
return this.payload.ownerWebsite;
|
|
210
|
+
}
|
|
192
211
|
/**
|
|
193
212
|
* Gets the file patterns the App handles.
|
|
194
213
|
*
|
|
@@ -220,11 +239,43 @@ export class App {
|
|
|
220
239
|
return this;
|
|
221
240
|
}
|
|
222
241
|
/**
|
|
223
|
-
*
|
|
242
|
+
* Gets the website url of this App.
|
|
243
|
+
*
|
|
244
|
+
* @returns The website url of this App
|
|
245
|
+
*/
|
|
246
|
+
getWebsiteUrl() {
|
|
247
|
+
return this.payload.website;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Tells if the repository is private.
|
|
251
|
+
*
|
|
252
|
+
* @returns True if the repository is private
|
|
253
|
+
*/
|
|
254
|
+
isRepositoryPrivate() {
|
|
255
|
+
return this.payload.repoPrivate;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Gets the repository url of this App.
|
|
259
|
+
*
|
|
260
|
+
* @returns The repository url of this App
|
|
261
|
+
*/
|
|
262
|
+
getRepositoryUrl() {
|
|
263
|
+
return this.payload.repoUrl;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Gets the readme.md file as text.
|
|
267
|
+
*
|
|
268
|
+
* @returns The readme text
|
|
269
|
+
*/
|
|
270
|
+
getReadme() {
|
|
271
|
+
return this.payload.readme;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Sets the readme.md file as text.
|
|
224
275
|
*
|
|
225
276
|
* @param readme - The readme text to set
|
|
226
277
|
*
|
|
227
|
-
* @returns This App for chaining
|
|
278
|
+
* @returns This App, for chaining
|
|
228
279
|
*/
|
|
229
280
|
setReadme(readme) {
|
|
230
281
|
this.payload.readme = readme;
|
|
@@ -239,7 +290,7 @@ export class App {
|
|
|
239
290
|
*/
|
|
240
291
|
create() {
|
|
241
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
yield AppService.createApp(this.payload);
|
|
293
|
+
yield AppService.createApp(this.payload, this.getConfig());
|
|
243
294
|
return this;
|
|
244
295
|
});
|
|
245
296
|
}
|
|
@@ -250,7 +301,7 @@ export class App {
|
|
|
250
301
|
*/
|
|
251
302
|
patch() {
|
|
252
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
yield AppService.patchApp(this.payload);
|
|
304
|
+
yield AppService.patchApp(this.payload, this.getConfig());
|
|
254
305
|
return this;
|
|
255
306
|
});
|
|
256
307
|
}
|
|
@@ -261,7 +312,7 @@ export class App {
|
|
|
261
312
|
*/
|
|
262
313
|
update() {
|
|
263
314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
-
yield AppService.updateApp(this.payload);
|
|
315
|
+
yield AppService.updateApp(this.payload, this.getConfig());
|
|
265
316
|
return this;
|
|
266
317
|
});
|
|
267
318
|
}
|
package/lib/model/Bkper.js
CHANGED
|
@@ -9,13 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { Book } from "./Book.js";
|
|
11
11
|
import { App } from "./App.js";
|
|
12
|
-
import * as AppService from
|
|
13
|
-
import * as ConversationService from
|
|
14
|
-
import * as BookService from
|
|
15
|
-
import * as CollectionService from
|
|
16
|
-
import * as UserService from
|
|
17
|
-
import * as TemplateService from
|
|
18
|
-
import { HttpApiRequest } from '../service/http-api-request.js';
|
|
12
|
+
import * as AppService from "../service/app-service.js";
|
|
13
|
+
import * as ConversationService from "../service/conversation-service.js";
|
|
14
|
+
import * as BookService from "../service/book-service.js";
|
|
15
|
+
import * as CollectionService from "../service/collection-service.js";
|
|
16
|
+
import * as UserService from "../service/user-service.js";
|
|
17
|
+
import * as TemplateService from "../service/template-service.js";
|
|
19
18
|
import { User } from "./User.js";
|
|
20
19
|
import { Template } from "./Template.js";
|
|
21
20
|
import { Collection } from "./Collection.js";
|
|
@@ -24,10 +23,9 @@ import { Agent } from "./Agent.js";
|
|
|
24
23
|
/**
|
|
25
24
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
26
25
|
*
|
|
27
|
-
* You
|
|
28
|
-
*
|
|
29
|
-
* Example:
|
|
26
|
+
* You can configure the library in two ways:
|
|
30
27
|
*
|
|
28
|
+
* 1. Using static configuration (traditional approach):
|
|
31
29
|
* ```javascript
|
|
32
30
|
* Bkper.setConfig({
|
|
33
31
|
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
@@ -38,7 +36,15 @@ import { Agent } from "./Agent.js";
|
|
|
38
36
|
* const book = await bkper.getBook('bookId');
|
|
39
37
|
* ```
|
|
40
38
|
*
|
|
41
|
-
*
|
|
39
|
+
* 2. Using per-instance configuration (recommended for Cloudflare Workers):
|
|
40
|
+
* ```javascript
|
|
41
|
+
* const bkper = new Bkper({
|
|
42
|
+
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
43
|
+
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* const book = await bkper.getBook('bookId');
|
|
47
|
+
* ```
|
|
42
48
|
*
|
|
43
49
|
* @public
|
|
44
50
|
*/
|
|
@@ -46,17 +52,21 @@ export class Bkper {
|
|
|
46
52
|
/**
|
|
47
53
|
* Sets the global API configuration for all Bkper operations.
|
|
48
54
|
*
|
|
55
|
+
* WARNING: This configuration will be shared and should NOT be used on shared environments.
|
|
56
|
+
*
|
|
49
57
|
* @param config - The Config object containing API key and OAuth token providers
|
|
50
58
|
*/
|
|
51
59
|
static setConfig(config) {
|
|
52
|
-
|
|
60
|
+
Bkper.globalConfig = config;
|
|
53
61
|
}
|
|
54
62
|
/**
|
|
55
|
-
* Creates a new Bkper instance
|
|
56
|
-
*
|
|
63
|
+
* Creates a new Bkper instance with the provided configuration.
|
|
64
|
+
*
|
|
65
|
+
* @param config - The Config object containing API key and OAuth token providers.
|
|
66
|
+
* If not provided, uses the global configuration set via setConfig().
|
|
57
67
|
*/
|
|
58
|
-
constructor() {
|
|
59
|
-
|
|
68
|
+
constructor(config) {
|
|
69
|
+
this.config = config || Bkper.globalConfig;
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
72
|
* Gets the [[Book]] with the specified bookId from url param.
|
|
@@ -75,8 +85,8 @@ export class Bkper {
|
|
|
75
85
|
*/
|
|
76
86
|
getBook(id, includeAccounts, includeGroups) {
|
|
77
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
let book = yield BookService.loadBook(id, includeAccounts, includeGroups);
|
|
79
|
-
return new Book(book);
|
|
88
|
+
let book = yield BookService.loadBook(id, includeAccounts, includeGroups, this.config);
|
|
89
|
+
return new Book(book, this.config);
|
|
80
90
|
});
|
|
81
91
|
}
|
|
82
92
|
/**
|
|
@@ -87,8 +97,8 @@ export class Bkper {
|
|
|
87
97
|
*/
|
|
88
98
|
getBooks(query) {
|
|
89
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
let books = yield BookService.loadBooks(query);
|
|
91
|
-
return books.map(book => new Book(book));
|
|
100
|
+
let books = yield BookService.loadBooks(query, this.config);
|
|
101
|
+
return books.map((book) => new Book(book, this.config));
|
|
92
102
|
});
|
|
93
103
|
}
|
|
94
104
|
/**
|
|
@@ -98,8 +108,8 @@ export class Bkper {
|
|
|
98
108
|
*/
|
|
99
109
|
getCollections() {
|
|
100
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
let collections = yield CollectionService.loadCollections();
|
|
102
|
-
return collections.map(collection => new Collection(collection));
|
|
111
|
+
let collections = yield CollectionService.loadCollections(this.config);
|
|
112
|
+
return collections.map((collection) => new Collection(collection, this.config));
|
|
103
113
|
});
|
|
104
114
|
}
|
|
105
115
|
/**
|
|
@@ -109,8 +119,8 @@ export class Bkper {
|
|
|
109
119
|
*/
|
|
110
120
|
getApps() {
|
|
111
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
let apps = yield AppService.getApps();
|
|
113
|
-
return apps.map(app => new App(app));
|
|
122
|
+
let apps = yield AppService.getApps(this.config);
|
|
123
|
+
return apps.map((app) => new App(app));
|
|
114
124
|
});
|
|
115
125
|
}
|
|
116
126
|
/**
|
|
@@ -120,7 +130,7 @@ export class Bkper {
|
|
|
120
130
|
*/
|
|
121
131
|
getConversations() {
|
|
122
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
const conversationPayloads = yield ConversationService.getConversations();
|
|
133
|
+
const conversationPayloads = yield ConversationService.getConversations(this.config);
|
|
124
134
|
let conversations = [];
|
|
125
135
|
for (const payload of conversationPayloads) {
|
|
126
136
|
const agent = new Agent(payload.agent);
|
|
@@ -137,8 +147,8 @@ export class Bkper {
|
|
|
137
147
|
*/
|
|
138
148
|
getTemplates() {
|
|
139
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
let templates = yield TemplateService.getTemplates();
|
|
141
|
-
return templates.map(template => new Template(template));
|
|
150
|
+
let templates = yield TemplateService.getTemplates(this.config);
|
|
151
|
+
return templates.map((template) => new Template(template));
|
|
142
152
|
});
|
|
143
153
|
}
|
|
144
154
|
/**
|
|
@@ -148,8 +158,8 @@ export class Bkper {
|
|
|
148
158
|
*/
|
|
149
159
|
getUser() {
|
|
150
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
let user = yield UserService.getUser();
|
|
152
|
-
return new User(user);
|
|
161
|
+
let user = yield UserService.getUser(this.config);
|
|
162
|
+
return new User(user, this.config);
|
|
153
163
|
});
|
|
154
164
|
}
|
|
155
165
|
/**
|
|
@@ -161,9 +171,11 @@ export class Bkper {
|
|
|
161
171
|
*/
|
|
162
172
|
getBillingPortalUrl(returnUrl) {
|
|
163
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
let url = yield UserService.getBillingPortalUrl(returnUrl);
|
|
174
|
+
let url = yield UserService.getBillingPortalUrl(returnUrl, this.config);
|
|
165
175
|
return url.url;
|
|
166
176
|
});
|
|
167
177
|
}
|
|
168
178
|
}
|
|
179
|
+
/** @internal */
|
|
180
|
+
Bkper.globalConfig = {};
|
|
169
181
|
//# sourceMappingURL=Bkper.js.map
|