bkper-js 2.22.0 → 2.23.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 CHANGED
@@ -10,13 +10,24 @@ See what's new and what has changed in bkper-js
10
10
  - Added `App.setDevelopers`
11
11
  - Added `App.getDevelopers`
12
12
  - Added `Config.agentIdProvider`
13
- - Added `User.getBillingAdminEmail`
14
- - Added `User.getTotalTransactionsThisMonth`
15
- - Added `User.getTotalTransactionsThisYear`
13
+ - Added `Billing`
14
+ - Added `Billing.getAdminEmail`
15
+ - Added `Billing.getDaysLeftInTrial`
16
+ - Added `Billing.getPlan`
17
+ - Added `Billing.getTotalTransactionsThisMonth`
18
+ - Added `Billing.getTotalTransactionsThisYear`
19
+ - Added `Billing.hasStartedTrial`
20
+ - Added `Billing.isEnabled`
21
+ - Added `Billing.isPlanOverdue`
22
+ - Added `User.getBilling`
16
23
  - Added `User.getUsername`
17
- - Added `User.isPlanOverdue`
18
24
  - Removed `App.setUserEmails` from `App`. Use `App.setUsers` instead
19
25
  - Removed `App.setDeveloperEmail` from `App`. Use `App.setDevelopers` instead
26
+ - Removed `User.getDaysLeftInTrial` from `User`. Use `Billing.getDaysLeftInTrial` instead
27
+ - Removed `User.getPlan` from `User`. Use `Billing.getPlan` instead
28
+ - Removed `User.hasBillingEnabled` from `User`. Use `Billing.isEnabled` instead
29
+ - Removed `User.hasStartedTrial` from `User`. Use `Billing.hasStartedTrial` instead
30
+ - Removed `User.isFree` from `User`. Use `Billing.getPlan` instead
20
31
 
21
32
  ## 2025
22
33
 
package/lib/index.d.ts CHANGED
@@ -1224,6 +1224,20 @@ export declare class Billing extends Resource<bkper.Billing> {
1224
1224
  * @returns The number of total transactions this year
1225
1225
  */
1226
1226
  getTotalTransactionsThisYear(): number | undefined;
1227
+ /**
1228
+ * Gets the transaction counts associated to the User's billing account.
1229
+ *
1230
+ * @returns The transaction counts associated to the User's billing account
1231
+ */
1232
+ getCounts(): Promise<bkper.Counts>;
1233
+ /**
1234
+ * Gets the URL to redirect the User to the billing portal.
1235
+ *
1236
+ * @param returnUrl - The URL to return to after the User has been redirected to the billing portal
1237
+ *
1238
+ * @returns The URL to redirect the User to the billing portal
1239
+ */
1240
+ getPortalUrl(returnUrl: string): Promise<string | undefined>;
1227
1241
  }
1228
1242
 
1229
1243
  /**
@@ -1327,14 +1341,6 @@ export declare class Bkper {
1327
1341
  * @returns The retrieved User
1328
1342
  */
1329
1343
  getUser(): Promise<User>;
1330
- /**
1331
- * Gets the URL to redirect the User to the billing portal.
1332
- *
1333
- * @param returnUrl - The URL to return to after the User has been redirected to the billing portal
1334
- *
1335
- * @returns The URL to redirect the User to the billing portal
1336
- */
1337
- getBillingPortalUrl(returnUrl: string): Promise<string | undefined>;
1338
1344
  }
1339
1345
 
1340
1346
  /**
@@ -2237,10 +2243,7 @@ export declare interface Config {
2237
2243
  * @param attempt - The number of retry attempts made so far.
2238
2244
  */
2239
2245
  requestRetryHandler?: (status?: number, error?: any, attempt?: number) => Promise<void>;
2240
- /**
2241
- * Sets the base api url. Default to https://app.bkper.com/_ah/api/bkper
2242
- */
2243
- apiBaseUrl?: string;
2246
+
2244
2247
  }
2245
2248
 
2246
2249
  /**
@@ -1,5 +1,15 @@
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 { Resource } from "./Resource.js";
2
11
  import { Bkper } from "./Bkper.js";
12
+ import * as UserService from "../service/user-service.js";
3
13
  /**
4
14
  * This class defines the Billing information for a [[User]].
5
15
  *
@@ -80,5 +90,29 @@ export class Billing extends Resource {
80
90
  getTotalTransactionsThisYear() {
81
91
  return this.payload.totalTransactionsThisYear;
82
92
  }
93
+ /**
94
+ * Gets the transaction counts associated to the User's billing account.
95
+ *
96
+ * @returns The transaction counts associated to the User's billing account
97
+ */
98
+ getCounts() {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const countsPayload = yield UserService.getBillingCounts(this.getConfig());
101
+ return countsPayload;
102
+ });
103
+ }
104
+ /**
105
+ * Gets the URL to redirect the User to the billing portal.
106
+ *
107
+ * @param returnUrl - The URL to return to after the User has been redirected to the billing portal
108
+ *
109
+ * @returns The URL to redirect the User to the billing portal
110
+ */
111
+ getPortalUrl(returnUrl) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const urlPayload = yield UserService.getBillingPortalUrl(returnUrl, this.getConfig());
114
+ return urlPayload.url;
115
+ });
116
+ }
83
117
  }
84
118
  //# sourceMappingURL=Billing.js.map
@@ -152,19 +152,6 @@ export class Bkper {
152
152
  return new User(user, this.config);
153
153
  });
154
154
  }
155
- /**
156
- * Gets the URL to redirect the User to the billing portal.
157
- *
158
- * @param returnUrl - The URL to return to after the User has been redirected to the billing portal
159
- *
160
- * @returns The URL to redirect the User to the billing portal
161
- */
162
- getBillingPortalUrl(returnUrl) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- let url = yield UserService.getBillingPortalUrl(returnUrl, this.config);
165
- return url.url;
166
- });
167
- }
168
155
  }
169
156
  /** @internal */
170
157
  Bkper.globalConfig = {};
@@ -9,30 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { HttpRequest } from "./http-request.js";
11
11
  /**
12
- * Proxy URL for clients without their own API key.
13
- * The proxy injects a managed API key server-side.
12
+ * The official Bkper API base URL.
14
13
  */
15
- export const PROXY_BASE_URL = "https://api.bkper.app";
16
- /**
17
- * Direct API URL for clients with their own API key.
18
- */
19
- export const DIRECT_BASE_URL = "https://app.bkper.com/_ah/api/bkper";
14
+ export const API_BASE_URL = "https://api.bkper.app";
20
15
  /**
21
16
  * Resolves the base URL based on config.
22
- *
23
- * Priority:
24
- * 1. If apiBaseUrl is set, use it (power user / dev mode)
25
- * 2. If apiKeyProvider is set, use direct URL (power user with own key)
26
- * 3. Otherwise, use proxy URL (default for most users)
27
17
  */
28
18
  export function resolveBaseUrl(config) {
29
19
  if (config.apiBaseUrl) {
30
20
  return config.apiBaseUrl;
31
21
  }
32
- if (config.apiKeyProvider) {
33
- return DIRECT_BASE_URL;
34
- }
35
- return PROXY_BASE_URL;
22
+ return API_BASE_URL;
36
23
  }
37
24
  export class HttpApiRequest extends HttpRequest {
38
25
  constructor(path, config) {
@@ -49,7 +36,7 @@ export class HttpApiRequest extends HttpRequest {
49
36
  this.addCustomHeaders();
50
37
  yield this.addAgentIdHeader();
51
38
  this.setHeader("Authorization", `Bearer ${yield this.getAccessToken()}`);
52
- this.addParam("key", yield this.getApiKey());
39
+ yield this.addApiKeyHeader();
53
40
  try {
54
41
  let resp = yield _super.execute.call(this);
55
42
  if (resp.status >= 200 && resp.status < 300) {
@@ -146,13 +133,15 @@ export class HttpApiRequest extends HttpRequest {
146
133
  }
147
134
  });
148
135
  }
149
- getApiKey() {
136
+ addApiKeyHeader() {
150
137
  return __awaiter(this, void 0, void 0, function* () {
151
138
  const effectiveConfig = this.config;
152
139
  if (effectiveConfig.apiKeyProvider) {
153
- return yield effectiveConfig.apiKeyProvider();
140
+ const apiKey = yield effectiveConfig.apiKeyProvider();
141
+ if (apiKey) {
142
+ this.setHeader("bkper-api-key", apiKey);
143
+ }
154
144
  }
155
- return null;
156
145
  });
157
146
  }
158
147
  getAccessToken() {
@@ -20,6 +20,12 @@ export function getBilling(config) {
20
20
  return res.data;
21
21
  });
22
22
  }
23
+ export function getBillingCounts(config) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const res = yield new HttpApiV5Request(`user/billing/counts`, config).setMethod('GET').fetch();
26
+ return res.data;
27
+ });
28
+ }
23
29
  export function getBillingPortalUrl(returnUrl, config) {
24
30
  return __awaiter(this, void 0, void 0, function* () {
25
31
  const res = yield new HttpApiV5Request(`user/billing/portal`, config).addParam('returnUrl', returnUrl).fetch();
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.53.1"
8
+ "packageVersion": "7.55.2"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.22.0",
3
+ "version": "2.23.1",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -34,10 +34,8 @@
34
34
  "preversion": "bun run build",
35
35
  "postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
36
36
  },
37
- "peerDependencies": {
38
- "@bkper/bkper-api-types": "^5.34.0"
39
- },
40
37
  "dependencies": {
38
+ "@bkper/bkper-api-types": "^5.34.0",
41
39
  "big.js": "^6.0.3",
42
40
  "dayjs": "^1.10.3",
43
41
  "luxon": "^1.25.0",