@dotbots-boutique/auth-sdk 1.0.9 → 1.0.10

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/README.md CHANGED
@@ -115,7 +115,7 @@ App (frontend) → Local proxy (per server) → api.dotbots.ai
115
115
 
116
116
  During `initialize()`, the SDK fetches the proxy config from `GET {apiUrl}/api/proxy/config`. After that, all `auth.fetch()` calls are routed through the proxy automatically. If the proxy config cannot be fetched, the SDK falls back to direct communication with `apiUrl`.
117
117
 
118
- Auth endpoints (`/auth/*`) and the proxy config endpoint always go directly to `apiUrl` never through the proxy.
118
+ Only `GET /api/proxy/config` always goes directly to `apiUrl`. All other calls — auth token exchange, refresh, revoke, user info, payments, and `auth.fetch()` — go to `proxyUrl` when available, falling back to `apiUrl` when proxy is unavailable.
119
119
 
120
120
  ---
121
121
 
@@ -150,7 +150,7 @@ const response = await auth.fetch('/api/customers', {
150
150
  });
151
151
  ```
152
152
 
153
- This is the **only** method that routes via `proxyUrl`. All auth calls and the proxy config call always go directly to `apiUrl`.
153
+ All SDK calls route via `proxyUrl` when available. Only `GET /api/proxy/config` always goes to `apiUrl`.
154
154
 
155
155
  ---
156
156
 
@@ -210,6 +210,7 @@ auth.on('sessionExpired', () => {
210
210
  });
211
211
  auth.on('loggedOut', () => { });
212
212
  auth.on('userLoaded', () => { });
213
+ auth.on('charged', () => { });
213
214
  ```
214
215
 
215
216
  | Event | Description |
@@ -218,6 +219,7 @@ auth.on('userLoaded', () => { });
218
219
  | `loggedOut` | User logged out |
219
220
  | `sessionExpired` | Refresh token expired, user must re-authenticate |
220
221
  | `userLoaded` | User data was fetched |
222
+ | `charged` | Successful charge — also sent as `DOTBOTS_CHARGE` postMessage to parent |
221
223
 
222
224
  ---
223
225
 
@@ -283,19 +285,17 @@ interface DotBotsConfig {
283
285
  ```typescript
284
286
  interface DotBotsUser {
285
287
  id: string;
286
- name: string | null; // null if 'profile' scope not granted
287
- email: string | null; // null if 'email' scope not granted
288
+ name: string;
289
+ email: string;
288
290
  orgId: string;
289
- orgName: string | null; // null if 'org' scope not granted
291
+ orgName: string;
290
292
  teams: { teamId: string; teamName: string }[];
291
293
  roles: string[];
292
294
  permissions: string[];
293
- avatarUrl: string | null; // null if 'avatar' scope not granted
295
+ avatarUrl?: string;
294
296
  }
295
297
  ```
296
298
 
297
- Fields marked as `null` are not provided by the platform because the user has not granted the corresponding scope.
298
-
299
299
  ---
300
300
 
301
301
  ## API Reference
@@ -340,7 +340,7 @@ Authenticated fetch wrapper. Routes through the proxy when available, falls back
340
340
 
341
341
  #### `charge(featureCode: string, paidBy: 'org' | 'app', quantity?: number): Promise<{ transactionId: string }>`
342
342
 
343
- Charges a feature usage. Calls `POST {proxyUrl}/payments/charge`. Throws `PAYMENT_FAILED` on 402 with a message indicating the reason (`INSUFFICIENT_BALANCE`, `BUDGET_EXCEEDED`, `FEATURE_NOT_FOUND`, `PAYMENT_REJECTED`).
343
+ Charges a feature usage. Calls `POST {proxyUrl}/payments/charge`. On success, sends a `DOTBOTS_CHARGE` postMessage to the parent window (iframe only) and emits the `charged` event. Throws `PAYMENT_FAILED` on 402 with a message indicating the reason (`INSUFFICIENT_BALANCE`, `BUDGET_EXCEEDED`, `FEATURE_NOT_FOUND`, `PAYMENT_REJECTED`).
344
344
 
345
345
  #### `logout(): Promise<void>`
346
346
 
package/dist/cjs/index.js CHANGED
@@ -193,6 +193,14 @@ class PostMessageHandler {
193
193
  window.parent.postMessage({ type: 'DOTBOTS_LOGOUT' }, this.marketplaceOrigin);
194
194
  }
195
195
  }
196
+ /**
197
+ * Notify the parent of a successful charge (for real-time payment indicator).
198
+ */
199
+ sendCharge(appId, featureCode, amount, transactionId) {
200
+ if (this.isInIframe()) {
201
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
202
+ }
203
+ }
196
204
  }
197
205
 
198
206
  class ProxyConfigManager {
@@ -340,7 +348,10 @@ class DotBotsAuth {
340
348
  if (!response.ok) {
341
349
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
342
350
  }
343
- return response.json();
351
+ const result = await response.json();
352
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, result.amount, result.transactionId);
353
+ this.emit('charged');
354
+ return result;
344
355
  }
345
356
  async logout() {
346
357
  this.assertInitialized();
@@ -352,7 +363,7 @@ class DotBotsAuth {
352
363
  }
353
364
  else {
354
365
  const redirectUri = encodeURIComponent(window.location.origin);
355
- window.location.href = `${this.config.apiUrl}/auth/logout?redirectUri=${redirectUri}`;
366
+ window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
356
367
  }
357
368
  }
358
369
  on(event, handler) {
@@ -400,7 +411,7 @@ class DotBotsAuth {
400
411
  else if (!this.tokenManager.isAuthenticated()) {
401
412
  // Redirect to auth
402
413
  const redirectUri = encodeURIComponent(window.location.href);
403
- window.location.href = `${this.config.apiUrl}/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
414
+ window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
404
415
  }
405
416
  }
406
417
  async buildRequest(url, options) {
@@ -432,7 +443,7 @@ class DotBotsAuth {
432
443
  }
433
444
  }
434
445
  }
435
- DotBotsAuth.SDK_VERSION = '1.0.9';
446
+ DotBotsAuth.SDK_VERSION = '1.0.10';
436
447
 
437
448
  exports.DotBotsAuth = DotBotsAuth;
438
449
  exports.DotBotsAuthError = DotBotsAuthError;
package/dist/esm/index.js CHANGED
@@ -191,6 +191,14 @@ class PostMessageHandler {
191
191
  window.parent.postMessage({ type: 'DOTBOTS_LOGOUT' }, this.marketplaceOrigin);
192
192
  }
193
193
  }
194
+ /**
195
+ * Notify the parent of a successful charge (for real-time payment indicator).
196
+ */
197
+ sendCharge(appId, featureCode, amount, transactionId) {
198
+ if (this.isInIframe()) {
199
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
200
+ }
201
+ }
194
202
  }
195
203
 
196
204
  class ProxyConfigManager {
@@ -338,7 +346,10 @@ class DotBotsAuth {
338
346
  if (!response.ok) {
339
347
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
340
348
  }
341
- return response.json();
349
+ const result = await response.json();
350
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, result.amount, result.transactionId);
351
+ this.emit('charged');
352
+ return result;
342
353
  }
343
354
  async logout() {
344
355
  this.assertInitialized();
@@ -350,7 +361,7 @@ class DotBotsAuth {
350
361
  }
351
362
  else {
352
363
  const redirectUri = encodeURIComponent(window.location.origin);
353
- window.location.href = `${this.config.apiUrl}/auth/logout?redirectUri=${redirectUri}`;
364
+ window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
354
365
  }
355
366
  }
356
367
  on(event, handler) {
@@ -398,7 +409,7 @@ class DotBotsAuth {
398
409
  else if (!this.tokenManager.isAuthenticated()) {
399
410
  // Redirect to auth
400
411
  const redirectUri = encodeURIComponent(window.location.href);
401
- window.location.href = `${this.config.apiUrl}/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
412
+ window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
402
413
  }
403
414
  }
404
415
  async buildRequest(url, options) {
@@ -430,6 +441,6 @@ class DotBotsAuth {
430
441
  }
431
442
  }
432
443
  }
433
- DotBotsAuth.SDK_VERSION = '1.0.9';
444
+ DotBotsAuth.SDK_VERSION = '1.0.10';
434
445
 
435
446
  export { DotBotsAuth, DotBotsAuthError };
@@ -8,7 +8,7 @@ export declare class DotBotsAuth {
8
8
  private readonly listeners;
9
9
  private cachedUser;
10
10
  private initialized;
11
- static readonly SDK_VERSION = "1.0.9";
11
+ static readonly SDK_VERSION = "1.0.10";
12
12
  constructor(config: DotBotsConfig);
13
13
  initialize(): Promise<void>;
14
14
  getUser(): Promise<DotBotsUser>;
@@ -15,4 +15,8 @@ export declare class PostMessageHandler {
15
15
  * Notify the parent that the user has logged out.
16
16
  */
17
17
  sendLogout(): void;
18
+ /**
19
+ * Notify the parent of a successful charge (for real-time payment indicator).
20
+ */
21
+ sendCharge(appId: string, featureCode: string, amount: number, transactionId: string): void;
18
22
  }
@@ -191,6 +191,14 @@ class PostMessageHandler {
191
191
  window.parent.postMessage({ type: 'DOTBOTS_LOGOUT' }, this.marketplaceOrigin);
192
192
  }
193
193
  }
194
+ /**
195
+ * Notify the parent of a successful charge (for real-time payment indicator).
196
+ */
197
+ sendCharge(appId, featureCode, amount, transactionId) {
198
+ if (this.isInIframe()) {
199
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
200
+ }
201
+ }
194
202
  }
195
203
 
196
204
  class ProxyConfigManager {
@@ -338,7 +346,10 @@ class DotBotsAuth {
338
346
  if (!response.ok) {
339
347
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
340
348
  }
341
- return response.json();
349
+ const result = await response.json();
350
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, result.amount, result.transactionId);
351
+ this.emit('charged');
352
+ return result;
342
353
  }
343
354
  async logout() {
344
355
  this.assertInitialized();
@@ -350,7 +361,7 @@ class DotBotsAuth {
350
361
  }
351
362
  else {
352
363
  const redirectUri = encodeURIComponent(window.location.origin);
353
- window.location.href = `${this.config.apiUrl}/auth/logout?redirectUri=${redirectUri}`;
364
+ window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
354
365
  }
355
366
  }
356
367
  on(event, handler) {
@@ -398,7 +409,7 @@ class DotBotsAuth {
398
409
  else if (!this.tokenManager.isAuthenticated()) {
399
410
  // Redirect to auth
400
411
  const redirectUri = encodeURIComponent(window.location.href);
401
- window.location.href = `${this.config.apiUrl}/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
412
+ window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
402
413
  }
403
414
  }
404
415
  async buildRequest(url, options) {
@@ -430,6 +441,6 @@ class DotBotsAuth {
430
441
  }
431
442
  }
432
443
  }
433
- DotBotsAuth.SDK_VERSION = '1.0.9';
444
+ DotBotsAuth.SDK_VERSION = '1.0.10';
434
445
 
435
446
  export { DotBotsAuth, DotBotsAuthError };
@@ -19,17 +19,17 @@ export interface DotBotsConfig {
19
19
  }
20
20
  export interface DotBotsUser {
21
21
  id: string;
22
- name: string | null;
23
- email: string | null;
22
+ name: string;
23
+ email: string;
24
24
  orgId: string;
25
- orgName: string | null;
25
+ orgName: string;
26
26
  teams: {
27
27
  teamId: string;
28
28
  teamName: string;
29
29
  }[];
30
30
  roles: string[];
31
31
  permissions: string[];
32
- avatarUrl: string | null;
32
+ avatarUrl?: string;
33
33
  }
34
34
  export interface DotBotsProxyConfig {
35
35
  /** URL of the local proxy, e.g. 'https://proxy.test-apps.dotbots.boutique' */
@@ -40,7 +40,7 @@ export interface DotBotsProxyConfig {
40
40
  cacheTtl: number;
41
41
  }
42
42
  export type ProxyFeature = 'cache' | 'localdb' | 'webhooks' | 'ratelimit';
43
- export type DotBotsAuthEvent = 'tokenRefreshed' | 'loggedOut' | 'sessionExpired' | 'userLoaded';
43
+ export type DotBotsAuthEvent = 'tokenRefreshed' | 'loggedOut' | 'sessionExpired' | 'userLoaded' | 'charged';
44
44
  export type DotBotsAuthErrorCode = 'IFRAME_TIMEOUT' | 'CODE_EXPIRED' | 'UNAUTHORIZED' | 'REFRESH_FAILED' | 'NETWORK_ERROR' | 'NOT_INITIALIZED' | 'PROXY_UNAVAILABLE' | 'PAYMENT_FAILED';
45
45
  export interface TokenPair {
46
46
  accessToken: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotbots-boutique/auth-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Authentication SDK for DotBots marketplace apps",
5
5
  "license": "MIT",
6
6
  "type": "module",