@dotbots-boutique/auth-sdk 1.0.12 → 1.0.14

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/dist/cjs/index.js CHANGED
@@ -196,10 +196,10 @@ class PostMessageHandler {
196
196
  /**
197
197
  * Notify the parent of a successful charge (for real-time payment indicator).
198
198
  */
199
- sendCharge(appId, featureCode, quantity, transactionId) {
199
+ sendCharge(appId, featureCode, amount, transactionId) {
200
200
  if (this.isInIframe()) {
201
- console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, quantity: ${quantity}, transactionId: ${transactionId}`);
202
- window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, quantity, transactionId }, this.marketplaceOrigin);
201
+ console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, amount: ${amount}, transactionId: ${transactionId}`);
202
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
203
203
  }
204
204
  }
205
205
  }
@@ -257,6 +257,7 @@ class DotBotsAuth {
257
257
  this.listeners = new Map();
258
258
  this.cachedUser = null;
259
259
  this.initialized = false;
260
+ this.initializePromise = null;
260
261
  this.config = config;
261
262
  this.environment = this.detectEnvironment();
262
263
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
@@ -266,6 +267,13 @@ class DotBotsAuth {
266
267
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
267
268
  }
268
269
  async initialize() {
270
+ // Idempotency guard — safe to call multiple times (React StrictMode)
271
+ if (this.initializePromise)
272
+ return this.initializePromise;
273
+ this.initializePromise = this._doInitialize();
274
+ return this.initializePromise;
275
+ }
276
+ async _doInitialize() {
269
277
  // Step 1 — Fetch proxy config
270
278
  await this.proxyConfigManager.fetchConfig();
271
279
  // Step 2 — Authenticate
@@ -352,12 +360,11 @@ class DotBotsAuth {
352
360
  console.error(`[DotBotsAuth] charge() failed — HTTP ${response.status}`);
353
361
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
354
362
  }
355
- const result = await response.json();
356
- const qty = quantity ?? 1;
357
- console.warn(`[DotBotsAuth] charge() success — transactionId: ${result.transactionId}, quantity: ${qty}`);
358
- this.postMessageHandler.sendCharge(this.config.appId, featureCode, qty, result.transactionId);
363
+ const data = await response.json();
364
+ console.warn(`[DotBotsAuth] charge() success transactionId: ${data.transactionId}, amount: ${data.amount}`);
365
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, data.amount, data.transactionId);
359
366
  this.emit('charged');
360
- return result;
367
+ return data;
361
368
  }
362
369
  async logout() {
363
370
  this.assertInitialized();
@@ -449,7 +456,7 @@ class DotBotsAuth {
449
456
  }
450
457
  }
451
458
  }
452
- DotBotsAuth.SDK_VERSION = '1.0.12';
459
+ DotBotsAuth.SDK_VERSION = '1.0.14';
453
460
 
454
461
  exports.DotBotsAuth = DotBotsAuth;
455
462
  exports.DotBotsAuthError = DotBotsAuthError;
package/dist/esm/index.js CHANGED
@@ -194,10 +194,10 @@ class PostMessageHandler {
194
194
  /**
195
195
  * Notify the parent of a successful charge (for real-time payment indicator).
196
196
  */
197
- sendCharge(appId, featureCode, quantity, transactionId) {
197
+ sendCharge(appId, featureCode, amount, transactionId) {
198
198
  if (this.isInIframe()) {
199
- console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, quantity: ${quantity}, transactionId: ${transactionId}`);
200
- window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, quantity, transactionId }, this.marketplaceOrigin);
199
+ console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, amount: ${amount}, transactionId: ${transactionId}`);
200
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
201
201
  }
202
202
  }
203
203
  }
@@ -255,6 +255,7 @@ class DotBotsAuth {
255
255
  this.listeners = new Map();
256
256
  this.cachedUser = null;
257
257
  this.initialized = false;
258
+ this.initializePromise = null;
258
259
  this.config = config;
259
260
  this.environment = this.detectEnvironment();
260
261
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
@@ -264,6 +265,13 @@ class DotBotsAuth {
264
265
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
265
266
  }
266
267
  async initialize() {
268
+ // Idempotency guard — safe to call multiple times (React StrictMode)
269
+ if (this.initializePromise)
270
+ return this.initializePromise;
271
+ this.initializePromise = this._doInitialize();
272
+ return this.initializePromise;
273
+ }
274
+ async _doInitialize() {
267
275
  // Step 1 — Fetch proxy config
268
276
  await this.proxyConfigManager.fetchConfig();
269
277
  // Step 2 — Authenticate
@@ -350,12 +358,11 @@ class DotBotsAuth {
350
358
  console.error(`[DotBotsAuth] charge() failed — HTTP ${response.status}`);
351
359
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
352
360
  }
353
- const result = await response.json();
354
- const qty = quantity ?? 1;
355
- console.warn(`[DotBotsAuth] charge() success — transactionId: ${result.transactionId}, quantity: ${qty}`);
356
- this.postMessageHandler.sendCharge(this.config.appId, featureCode, qty, result.transactionId);
361
+ const data = await response.json();
362
+ console.warn(`[DotBotsAuth] charge() success transactionId: ${data.transactionId}, amount: ${data.amount}`);
363
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, data.amount, data.transactionId);
357
364
  this.emit('charged');
358
- return result;
365
+ return data;
359
366
  }
360
367
  async logout() {
361
368
  this.assertInitialized();
@@ -447,6 +454,6 @@ class DotBotsAuth {
447
454
  }
448
455
  }
449
456
  }
450
- DotBotsAuth.SDK_VERSION = '1.0.12';
457
+ DotBotsAuth.SDK_VERSION = '1.0.14';
451
458
 
452
459
  export { DotBotsAuth, DotBotsAuthError };
@@ -8,9 +8,11 @@ export declare class DotBotsAuth {
8
8
  private readonly listeners;
9
9
  private cachedUser;
10
10
  private initialized;
11
- static readonly SDK_VERSION = "1.0.12";
11
+ private initializePromise;
12
+ static readonly SDK_VERSION = "1.0.14";
12
13
  constructor(config: DotBotsConfig);
13
14
  initialize(): Promise<void>;
15
+ private _doInitialize;
14
16
  getUser(): Promise<DotBotsUser>;
15
17
  can(permission: string): boolean;
16
18
  canAll(permissions: string[]): boolean;
@@ -18,5 +18,5 @@ export declare class PostMessageHandler {
18
18
  /**
19
19
  * Notify the parent of a successful charge (for real-time payment indicator).
20
20
  */
21
- sendCharge(appId: string, featureCode: string, quantity: number, transactionId: string): void;
21
+ sendCharge(appId: string, featureCode: string, amount: number, transactionId: string): void;
22
22
  }
@@ -194,10 +194,10 @@ class PostMessageHandler {
194
194
  /**
195
195
  * Notify the parent of a successful charge (for real-time payment indicator).
196
196
  */
197
- sendCharge(appId, featureCode, quantity, transactionId) {
197
+ sendCharge(appId, featureCode, amount, transactionId) {
198
198
  if (this.isInIframe()) {
199
- console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, quantity: ${quantity}, transactionId: ${transactionId}`);
200
- window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, quantity, transactionId }, this.marketplaceOrigin);
199
+ console.warn(`[DotBotsAuth] Sending DOTBOTS_CHARGE postMessage — featureCode: ${featureCode}, amount: ${amount}, transactionId: ${transactionId}`);
200
+ window.parent.postMessage({ type: 'DOTBOTS_CHARGE', appId, featureCode, amount, transactionId }, this.marketplaceOrigin);
201
201
  }
202
202
  }
203
203
  }
@@ -255,6 +255,7 @@ class DotBotsAuth {
255
255
  this.listeners = new Map();
256
256
  this.cachedUser = null;
257
257
  this.initialized = false;
258
+ this.initializePromise = null;
258
259
  this.config = config;
259
260
  this.environment = this.detectEnvironment();
260
261
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
@@ -264,6 +265,13 @@ class DotBotsAuth {
264
265
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
265
266
  }
266
267
  async initialize() {
268
+ // Idempotency guard — safe to call multiple times (React StrictMode)
269
+ if (this.initializePromise)
270
+ return this.initializePromise;
271
+ this.initializePromise = this._doInitialize();
272
+ return this.initializePromise;
273
+ }
274
+ async _doInitialize() {
267
275
  // Step 1 — Fetch proxy config
268
276
  await this.proxyConfigManager.fetchConfig();
269
277
  // Step 2 — Authenticate
@@ -350,12 +358,11 @@ class DotBotsAuth {
350
358
  console.error(`[DotBotsAuth] charge() failed — HTTP ${response.status}`);
351
359
  throw new DotBotsAuthError('NETWORK_ERROR', 'Payment request failed');
352
360
  }
353
- const result = await response.json();
354
- const qty = quantity ?? 1;
355
- console.warn(`[DotBotsAuth] charge() success — transactionId: ${result.transactionId}, quantity: ${qty}`);
356
- this.postMessageHandler.sendCharge(this.config.appId, featureCode, qty, result.transactionId);
361
+ const data = await response.json();
362
+ console.warn(`[DotBotsAuth] charge() success transactionId: ${data.transactionId}, amount: ${data.amount}`);
363
+ this.postMessageHandler.sendCharge(this.config.appId, featureCode, data.amount, data.transactionId);
357
364
  this.emit('charged');
358
- return result;
365
+ return data;
359
366
  }
360
367
  async logout() {
361
368
  this.assertInitialized();
@@ -447,6 +454,6 @@ class DotBotsAuth {
447
454
  }
448
455
  }
449
456
  }
450
- DotBotsAuth.SDK_VERSION = '1.0.12';
457
+ DotBotsAuth.SDK_VERSION = '1.0.14';
451
458
 
452
459
  export { DotBotsAuth, DotBotsAuthError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotbots-boutique/auth-sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Authentication SDK for DotBots marketplace apps",
5
5
  "license": "MIT",
6
6
  "type": "module",