bison-web-components 1.2.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.
- package/bison-operator-payments.js +34 -9
- package/package.json +1 -1
|
@@ -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
|
-
|
|
207
|
-
this._api
|
|
208
|
-
|
|
209
|
-
|
|
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";
|
|
@@ -652,7 +677,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
652
677
|
this._isLoading = true;
|
|
653
678
|
this._renderContent();
|
|
654
679
|
|
|
655
|
-
const api = this._getApi();
|
|
680
|
+
const api = await this._getApi();
|
|
656
681
|
if (!api || !this._operatorId) {
|
|
657
682
|
this._log("Error: Missing API instance or operator ID for unlinking.");
|
|
658
683
|
this._isLoading = false;
|
|
@@ -892,7 +917,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
892
917
|
this._renderLinkModal();
|
|
893
918
|
|
|
894
919
|
try {
|
|
895
|
-
const api = this._getApi();
|
|
920
|
+
const api = await this._getApi();
|
|
896
921
|
if (!api || !this._operatorId) {
|
|
897
922
|
throw new Error("Missing API instance or operator ID");
|
|
898
923
|
}
|