bkper-js 2.23.1 → 2.25.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/CHANGELOG.md +3 -0
- package/README.md +49 -8
- package/lib/index.d.ts +13 -9
- package/lib/model/App.js +0 -11
- package/lib/model/Bkper.js +13 -0
- package/lib/service/app-service.js +6 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,8 +12,10 @@ See what's new and what has changed in bkper-js
|
|
|
12
12
|
- Added `Config.agentIdProvider`
|
|
13
13
|
- Added `Billing`
|
|
14
14
|
- Added `Billing.getAdminEmail`
|
|
15
|
+
- Added `Billing.getCounts`
|
|
15
16
|
- Added `Billing.getDaysLeftInTrial`
|
|
16
17
|
- Added `Billing.getPlan`
|
|
18
|
+
- Added `Billing.getPortalUrl`
|
|
17
19
|
- Added `Billing.getTotalTransactionsThisMonth`
|
|
18
20
|
- Added `Billing.getTotalTransactionsThisYear`
|
|
19
21
|
- Added `Billing.hasStartedTrial`
|
|
@@ -23,6 +25,7 @@ See what's new and what has changed in bkper-js
|
|
|
23
25
|
- Added `User.getUsername`
|
|
24
26
|
- Removed `App.setUserEmails` from `App`. Use `App.setUsers` instead
|
|
25
27
|
- Removed `App.setDeveloperEmail` from `App`. Use `App.setDevelopers` instead
|
|
28
|
+
- Removed `Bkper.getBillingPortalUrl` from `Bkper`. Use `Billing.getPortalUrl` instead
|
|
26
29
|
- Removed `User.getDaysLeftInTrial` from `User`. Use `Billing.getDaysLeftInTrial` instead
|
|
27
30
|
- Removed `User.getPlan` from `User`. Use `Billing.getPlan` instead
|
|
28
31
|
- Removed `User.hasBillingEnabled` from `User`. Use `Billing.isEnabled` instead
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[Bkper REST API]: https://bkper.com/docs/#rest-
|
|
1
|
+
[Bkper REST API]: https://bkper.com/docs/#rest-api
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/bkper-js)
|
|
4
4
|
|
|
@@ -29,16 +29,20 @@ bun add bkper-js
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
+
### Node.js / CLI Scripts
|
|
33
|
+
|
|
34
|
+
For local scripts and CLI tools, use the [bkper](https://www.npmjs.com/package/bkper) CLI package for authentication:
|
|
35
|
+
|
|
32
36
|
```typescript
|
|
33
37
|
import { Bkper } from 'bkper-js';
|
|
38
|
+
import { getOAuthToken } from 'bkper';
|
|
34
39
|
|
|
35
|
-
//
|
|
40
|
+
// Configure with CLI authentication
|
|
36
41
|
Bkper.setConfig({
|
|
37
|
-
|
|
38
|
-
oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
42
|
+
oauthTokenProvider: async () => getOAuthToken()
|
|
39
43
|
});
|
|
40
44
|
|
|
41
|
-
// Create Bkper instance
|
|
45
|
+
// Create Bkper instance
|
|
42
46
|
const bkper = new Bkper();
|
|
43
47
|
|
|
44
48
|
// Get a book and work with it
|
|
@@ -48,10 +52,47 @@ console.log(`Book: ${book.getName()}`);
|
|
|
48
52
|
// List all books
|
|
49
53
|
const books = await bkper.getBooks();
|
|
50
54
|
console.log(`You have ${books.length} books`);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
First, login via CLI: `bkper login`
|
|
58
|
+
|
|
59
|
+
### Web Applications
|
|
60
|
+
|
|
61
|
+
For browser-based apps, use the [@bkper/web-auth](https://www.npmjs.com/package/@bkper/web-auth) SDK:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { Bkper } from 'bkper-js';
|
|
65
|
+
import { BkperAuth } from '@bkper/web-auth';
|
|
66
|
+
|
|
67
|
+
// Initialize authentication
|
|
68
|
+
const auth = new BkperAuth({
|
|
69
|
+
onLoginSuccess: () => initializeApp(),
|
|
70
|
+
onLoginRequired: () => showLoginButton()
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Restore session on app load
|
|
74
|
+
await auth.init();
|
|
51
75
|
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
// Configure Bkper with web auth
|
|
77
|
+
Bkper.setConfig({
|
|
78
|
+
oauthTokenProvider: async () => auth.getAccessToken()
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Create Bkper instance and use it
|
|
82
|
+
const bkper = new Bkper();
|
|
83
|
+
const books = await bkper.getBooks();
|
|
55
84
|
```
|
|
56
85
|
|
|
86
|
+
See the [@bkper/web-auth documentation](https://bkper.com/docs/auth-sdk) for more details.
|
|
87
|
+
|
|
88
|
+
### API Key (Optional)
|
|
89
|
+
|
|
90
|
+
API keys are optional and only needed for dedicated quota limits. If not provided, requests use a shared managed quota via the Bkper API proxy.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
Bkper.setConfig({
|
|
94
|
+
oauthTokenProvider: async () => getOAuthToken(),
|
|
95
|
+
apiKeyProvider: async () => process.env.BKPER_API_KEY // Optional - for dedicated quota
|
|
96
|
+
});
|
|
97
|
+
```
|
|
57
98
|
|
package/lib/index.d.ts
CHANGED
|
@@ -595,12 +595,6 @@ export declare class App extends Resource<bkper.App> {
|
|
|
595
595
|
* @returns This App after creation
|
|
596
596
|
*/
|
|
597
597
|
create(): Promise<App>;
|
|
598
|
-
/**
|
|
599
|
-
* Partially updates an App, applying pending changes.
|
|
600
|
-
*
|
|
601
|
-
* @returns This App after the partial update
|
|
602
|
-
*/
|
|
603
|
-
patch(): Promise<App>;
|
|
604
598
|
/**
|
|
605
599
|
* Performs a full update of the App, applying pending changes.
|
|
606
600
|
*
|
|
@@ -1329,6 +1323,14 @@ export declare class Bkper {
|
|
|
1329
1323
|
* @returns The retrieved list of Apps
|
|
1330
1324
|
*/
|
|
1331
1325
|
getApps(): Promise<App[]>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Gets the [[App]] with the specified id.
|
|
1328
|
+
*
|
|
1329
|
+
* @param id - The App id (agentId)
|
|
1330
|
+
*
|
|
1331
|
+
* @returns The retrieved App
|
|
1332
|
+
*/
|
|
1333
|
+
getApp(id: string): Promise<App>;
|
|
1332
1334
|
/**
|
|
1333
1335
|
* Gets all [[Templates]] available for the user.
|
|
1334
1336
|
*
|
|
@@ -2202,11 +2204,13 @@ export declare class Collection extends Resource<bkper.Collection> {
|
|
|
2202
2204
|
*/
|
|
2203
2205
|
export declare interface Config {
|
|
2204
2206
|
/**
|
|
2205
|
-
*
|
|
2207
|
+
* Optional API key for dedicated quota limits.
|
|
2206
2208
|
*
|
|
2207
|
-
*
|
|
2209
|
+
* If not provided, requests use a shared managed quota via the Bkper API proxy.
|
|
2210
|
+
* Use your own API key for dedicated quota limits and project-level usage tracking.
|
|
2208
2211
|
*
|
|
2209
|
-
*
|
|
2212
|
+
* API keys are for project identification only, not for authentication or agent attribution.
|
|
2213
|
+
* Agent attribution is handled separately via the `agentIdProvider`.
|
|
2210
2214
|
*/
|
|
2211
2215
|
apiKeyProvider?: () => Promise<string>;
|
|
2212
2216
|
/**
|
package/lib/model/App.js
CHANGED
|
@@ -287,17 +287,6 @@ export class App extends Resource {
|
|
|
287
287
|
return this;
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Partially updates an App, applying pending changes.
|
|
292
|
-
*
|
|
293
|
-
* @returns This App after the partial update
|
|
294
|
-
*/
|
|
295
|
-
patch() {
|
|
296
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
yield AppService.patchApp(this.payload, this.getConfig());
|
|
298
|
-
return this;
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
290
|
/**
|
|
302
291
|
* Performs a full update of the App, applying pending changes.
|
|
303
292
|
*
|
package/lib/model/Bkper.js
CHANGED
|
@@ -130,6 +130,19 @@ export class Bkper {
|
|
|
130
130
|
return apps.map((app) => new App(app, this.config));
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Gets the [[App]] with the specified id.
|
|
135
|
+
*
|
|
136
|
+
* @param id - The App id (agentId)
|
|
137
|
+
*
|
|
138
|
+
* @returns The retrieved App
|
|
139
|
+
*/
|
|
140
|
+
getApp(id) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
let app = yield AppService.getApp(id, this.config);
|
|
143
|
+
return new App(app, this.config);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
133
146
|
/**
|
|
134
147
|
* Gets all [[Templates]] available for the user.
|
|
135
148
|
*
|
|
@@ -22,21 +22,21 @@ export function getApps(config) {
|
|
|
22
22
|
return appsJson;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
export function
|
|
25
|
+
export function getApp(id, config) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
|
|
27
|
+
let response = yield new HttpApiRequest(`v5/apps/${id}`, config).setMethod('GET').fetch();
|
|
28
28
|
return response.data;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
export function
|
|
31
|
+
export function createApp(app, config) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('
|
|
33
|
+
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('POST').setPayload(app).fetch();
|
|
34
34
|
return response.data;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
export function
|
|
37
|
+
export function updateApp(app, config) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('
|
|
39
|
+
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('PUT').setPayload(app).fetch();
|
|
40
40
|
return response.data;
|
|
41
41
|
});
|
|
42
42
|
}
|