bison-web-components 1.1.0 → 1.3.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.
@@ -202,13 +202,38 @@ class BisonOperatorPayments extends HTMLElement {
202
202
  }
203
203
 
204
204
  /** Resolves the API instance and syncs the current embeddable key. */
205
- _getApi() {
206
- const api =
207
- this._api || (typeof window !== "undefined" && window.__bisonApi);
208
- if (api) {
209
- api.embeddableKey = this._embeddableKey;
205
+ async _getApi() {
206
+ if (this._api) {
207
+ this._api.embeddableKey = this._embeddableKey;
208
+ return this._api;
209
+ }
210
+ if (typeof window !== "undefined" && window.__bisonApi) {
211
+ window.__bisonApi.embeddableKey = this._embeddableKey;
212
+ return window.__bisonApi;
213
+ }
214
+
215
+ try {
216
+ if (typeof window !== "undefined" && window.BisonJibPayAPI) {
217
+ this._api = new window.BisonJibPayAPI("", this._embeddableKey);
218
+ return this._api;
219
+ }
220
+
221
+ // Dynamically import the API class
222
+ // Works for both local dev and CDN (api.js deployed alongside)
223
+ const { BisonJibPayAPI } = await import("./api.js");
224
+ this._api = new BisonJibPayAPI("", this._embeddableKey);
225
+
226
+ // Attach to window to prevent redundant instantiations across components
227
+ if (typeof window !== "undefined") {
228
+ window.BisonJibPayAPI = BisonJibPayAPI;
229
+ window.__bisonApi = this._api;
230
+ }
231
+
232
+ return this._api;
233
+ } catch (err) {
234
+ this._log("Failed to initialize BisonJibPayAPI dynamically:", err);
235
+ return null;
210
236
  }
211
- return api;
212
237
  }
213
238
 
214
239
  // ==================== OPERATOR LOOKUP (Enverus) ====================
@@ -260,7 +285,7 @@ class BisonOperatorPayments extends HTMLElement {
260
285
  async _performOperatorLookup(opOrgId, orgNumber) {
261
286
  // Resolve API instance — consumers can set this._api externally,
262
287
  // or the component falls back to a global instance on window.
263
- const api = this._getApi();
288
+ const api = await this._getApi();
264
289
  if (!api || typeof api.findOperatorFromEnverus !== "function") {
265
290
  const msg =
266
291
  "No API instance available — set component._api or window.__bisonApi";
@@ -420,7 +445,6 @@ class BisonOperatorPayments extends HTMLElement {
420
445
  this._searchQuery = "";
421
446
  this._selectedBank = BOP_BRAND_BANK;
422
447
  this._isLoading = false;
423
- this._accounts = [];
424
448
  this._selectedAccounts = new Set();
425
449
  this._linkedAccount = null;
426
450
  this._unlinkTarget = null;
@@ -653,7 +677,7 @@ class BisonOperatorPayments extends HTMLElement {
653
677
  this._isLoading = true;
654
678
  this._renderContent();
655
679
 
656
- const api = this._getApi();
680
+ const api = await this._getApi();
657
681
  if (!api || !this._operatorId) {
658
682
  this._log("Error: Missing API instance or operator ID for unlinking.");
659
683
  this._isLoading = false;
@@ -893,7 +917,7 @@ class BisonOperatorPayments extends HTMLElement {
893
917
  this._renderLinkModal();
894
918
 
895
919
  try {
896
- const api = this._getApi();
920
+ const api = await this._getApi();
897
921
  if (!api || !this._operatorId) {
898
922
  throw new Error("Missing API instance or operator ID");
899
923
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bison-web-components",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Bison JIB's suite of web components",
5
5
  "main": "component.js",
6
6
  "type": "module",