bkper-js 2.7.1 → 2.8.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/index.d.ts +142 -144
  3. package/lib/model/Account.js +18 -24
  4. package/lib/model/App.js +70 -24
  5. package/lib/model/Bkper.js +42 -30
  6. package/lib/model/Book.js +107 -102
  7. package/lib/model/BotResponse.js +2 -2
  8. package/lib/model/Collaborator.js +10 -14
  9. package/lib/model/Collection.js +22 -22
  10. package/lib/model/Connection.js +26 -21
  11. package/lib/model/Conversation.js +18 -16
  12. package/lib/model/File.js +17 -20
  13. package/lib/model/Group.js +27 -24
  14. package/lib/model/Integration.js +15 -16
  15. package/lib/model/Message.js +18 -19
  16. package/lib/model/Query.js +10 -14
  17. package/lib/model/Resource.js +23 -0
  18. package/lib/model/Template.js +8 -10
  19. package/lib/model/Transaction.js +59 -46
  20. package/lib/model/User.js +12 -15
  21. package/lib/service/account-service.js +12 -12
  22. package/lib/service/app-service.js +8 -8
  23. package/lib/service/balances-service.js +2 -2
  24. package/lib/service/book-service.js +14 -14
  25. package/lib/service/collaborator-service.js +6 -6
  26. package/lib/service/collection-service.js +12 -12
  27. package/lib/service/connection-service.js +12 -15
  28. package/lib/service/conversation-service.js +10 -10
  29. package/lib/service/event-service.js +8 -8
  30. package/lib/service/file-service.js +4 -4
  31. package/lib/service/group-service.js +16 -16
  32. package/lib/service/http-api-request.js +54 -45
  33. package/lib/service/integration-service.js +8 -8
  34. package/lib/service/query-service.js +8 -8
  35. package/lib/service/template-service.js +2 -2
  36. package/lib/service/transaction-service.js +32 -32
  37. package/lib/service/user-service.js +4 -4
  38. 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 '../service/app-service.js';
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,13 @@ import * as AppService from '../service/app-service.js';
15
17
  *
16
18
  * @public
17
19
  */
18
- export class App {
19
- constructor(payload) {
20
- this.payload = payload || {};
20
+ export class App extends Resource {
21
+ constructor(payload, config) {
22
+ super(payload);
23
+ this.config = config;
21
24
  }
22
- /**
23
- * Gets the wrapped plain JSON object.
24
- *
25
- * @returns The wrapped plain json object
26
- */
27
- json() {
28
- return Object.assign({}, this.payload);
25
+ getConfig() {
26
+ return this.config || Bkper.globalConfig;
29
27
  }
30
28
  /**
31
29
  * Sets the webhook url for development.
@@ -90,6 +88,14 @@ export class App {
90
88
  isPublished() {
91
89
  return this.payload.published || false;
92
90
  }
91
+ /**
92
+ * Tells if this App is installable.
93
+ *
94
+ * @returns True if this App is installable
95
+ */
96
+ isInstallable() {
97
+ return this.payload.installable || false;
98
+ }
93
99
  /**
94
100
  * Checks if this App is conversational.
95
101
  *
@@ -133,14 +139,6 @@ export class App {
133
139
  this.payload.userEmails = emails;
134
140
  return this;
135
141
  }
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
142
  /**
145
143
  * Gets the menu url of this App.
146
144
  *
@@ -181,6 +179,14 @@ export class App {
181
179
  getMenuPopupHeight() {
182
180
  return this.payload.menuPopupHeight;
183
181
  }
182
+ /**
183
+ * Gets the name of the owner of this App.
184
+ *
185
+ * @returns The name of the owner of this App
186
+ */
187
+ getOwnerName() {
188
+ return this.payload.ownerName;
189
+ }
184
190
  /**
185
191
  * Gets the logo url of the owner of this App.
186
192
  *
@@ -189,6 +195,14 @@ export class App {
189
195
  getOwnerLogoUrl() {
190
196
  return this.payload.ownerLogoUrl;
191
197
  }
198
+ /**
199
+ * Gets the website url of the owner of this App.
200
+ *
201
+ * @returns The website url of the owner of this App
202
+ */
203
+ getOwnerWebsiteUrl() {
204
+ return this.payload.ownerWebsite;
205
+ }
192
206
  /**
193
207
  * Gets the file patterns the App handles.
194
208
  *
@@ -220,11 +234,43 @@ export class App {
220
234
  return this;
221
235
  }
222
236
  /**
223
- * Sets the readme text.
237
+ * Gets the website url of this App.
238
+ *
239
+ * @returns The website url of this App
240
+ */
241
+ getWebsiteUrl() {
242
+ return this.payload.website;
243
+ }
244
+ /**
245
+ * Tells if the repository is private.
246
+ *
247
+ * @returns True if the repository is private
248
+ */
249
+ isRepositoryPrivate() {
250
+ return this.payload.repoPrivate;
251
+ }
252
+ /**
253
+ * Gets the repository url of this App.
254
+ *
255
+ * @returns The repository url of this App
256
+ */
257
+ getRepositoryUrl() {
258
+ return this.payload.repoUrl;
259
+ }
260
+ /**
261
+ * Gets the readme.md file as text.
262
+ *
263
+ * @returns The readme text
264
+ */
265
+ getReadme() {
266
+ return this.payload.readme;
267
+ }
268
+ /**
269
+ * Sets the readme.md file as text.
224
270
  *
225
271
  * @param readme - The readme text to set
226
272
  *
227
- * @returns This App for chaining
273
+ * @returns This App, for chaining
228
274
  */
229
275
  setReadme(readme) {
230
276
  this.payload.readme = readme;
@@ -239,7 +285,7 @@ export class App {
239
285
  */
240
286
  create() {
241
287
  return __awaiter(this, void 0, void 0, function* () {
242
- yield AppService.createApp(this.payload);
288
+ yield AppService.createApp(this.payload, this.getConfig());
243
289
  return this;
244
290
  });
245
291
  }
@@ -250,7 +296,7 @@ export class App {
250
296
  */
251
297
  patch() {
252
298
  return __awaiter(this, void 0, void 0, function* () {
253
- yield AppService.patchApp(this.payload);
299
+ yield AppService.patchApp(this.payload, this.getConfig());
254
300
  return this;
255
301
  });
256
302
  }
@@ -261,7 +307,7 @@ export class App {
261
307
  */
262
308
  update() {
263
309
  return __awaiter(this, void 0, void 0, function* () {
264
- yield AppService.updateApp(this.payload);
310
+ yield AppService.updateApp(this.payload, this.getConfig());
265
311
  return this;
266
312
  });
267
313
  }
@@ -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 '../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';
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 start by setting the API [[Config]] object using the static setConfig method.
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
- * Once the config is set, you can create instances and start using the library.
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
- HttpApiRequest.config = config;
60
+ Bkper.globalConfig = config;
53
61
  }
54
62
  /**
55
- * Creates a new Bkper instance using the global configuration set via setConfig().
56
- * Make sure to call Bkper.setConfig() before creating instances.
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
- // Uses global configuration set via setConfig()
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