bison-web-components 1.6.0 → 2.0.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/api.js CHANGED
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @class BisonJibPayAPI
9
9
  * @author @kfajardo
10
- * @version 1.0.0
10
+ * @version 1.6.0
11
11
  *
12
12
  * @example
13
13
  * // Initialize the API
@@ -25,7 +25,7 @@
25
25
  * onUnlinkError(error) – called when unlinking bank account(s) fails
26
26
  *
27
27
  * @author @kfajardo
28
- * @version 1.1.0
28
+ * @version 2.0.0
29
29
  */
30
30
 
31
31
  const BOP_BISON_LOGO =
@@ -95,7 +95,7 @@ class BisonJibPayAPI {
95
95
  if (!embeddableKey || typeof embeddableKey !== 'string' || !embeddableKey.trim()) {
96
96
  throw new Error("Missing required 'x-embeddable-key' for BisonJibPayAPI");
97
97
  }
98
- this.baseURL = baseURL || "https://bison-jib-development.azurewebsites.net";
98
+ this.baseURL = baseURL || "https://bison-backend-development-hhgrdbhcbwhahdfk.southeastasia-01.azurewebsites.net";
99
99
  this.embeddableKey = embeddableKey;
100
100
  }
101
101
 
@@ -742,6 +742,7 @@ class BisonOperatorPayments extends HTMLElement {
742
742
  this._linkedAccount = null;
743
743
  this._isFetchingAccounts = false;
744
744
  this._pendingLinkedAccount = null;
745
+ this._isOpen = false;
745
746
 
746
747
  // Unlink state
747
748
  this._unlinkTarget = null;
@@ -772,24 +773,108 @@ class BisonOperatorPayments extends HTMLElement {
772
773
  this._isOperatorLookupPending = false;
773
774
  this._componentDisabled = true;
774
775
 
775
- // Consumer callbacks
776
- this.onOpen = null;
777
- this.onClose = null;
778
- this.onLookupSuccess = null;
779
- this.onLookupError = null;
780
- this.onBankFetchSuccess = null;
781
- this.onBankFetchError = null;
782
- this.onLinkSuccess = null;
783
- this.onLinkError = null;
784
- this.onUnlinkSuccess = null;
785
- this.onUnlinkError = null;
776
+ // Consumer callbacks — intentionally NOT set to null here.
777
+ // Setting them in the constructor would clobber values the consumer
778
+ // assigned before the element upgraded. They are rescued via
779
+ // _upgradeProperty() in connectedCallback instead.
786
780
  }
787
781
 
788
782
  static get observedAttributes() {
789
- return ["org-number", "op-org-id", "x-embeddable-key", "api-base-url"];
783
+ return [
784
+ "org-number",
785
+ "op-org-id",
786
+ "x-embeddable-key",
787
+ "api-base-url",
788
+ // Callback attributes — resolved from window globals by name
789
+ "on-open",
790
+ "on-close",
791
+ "on-lookup-success",
792
+ "on-lookup-error",
793
+ "on-bank-fetch-success",
794
+ "on-bank-fetch-error",
795
+ "on-link-success",
796
+ "on-link-error",
797
+ "on-unlink-success",
798
+ "on-unlink-error",
799
+ ];
800
+ }
801
+
802
+ /** Attribute name → JS property name mapping for consumer callbacks */
803
+ static get _callbackAttrMap() {
804
+ return {
805
+ "on-open": "onOpen",
806
+ "on-close": "onClose",
807
+ "on-lookup-success": "onLookupSuccess",
808
+ "on-lookup-error": "onLookupError",
809
+ "on-bank-fetch-success": "onBankFetchSuccess",
810
+ "on-bank-fetch-error": "onBankFetchError",
811
+ "on-link-success": "onLinkSuccess",
812
+ "on-link-error": "onLinkError",
813
+ "on-unlink-success": "onUnlinkSuccess",
814
+ "on-unlink-error": "onUnlinkError",
815
+ };
816
+ }
817
+
818
+ /**
819
+ * Resolves a callback attribute value to a window-global function and assigns
820
+ * it to the corresponding JS property.
821
+ *
822
+ * @param {string} attrName - e.g. "on-lookup-success"
823
+ * @param {string|null} fnName - e.g. "handleLookup"
824
+ */
825
+ _resolveCallbackAttr(attrName, fnName) {
826
+ const propName = BisonOperatorPayments._callbackAttrMap[attrName];
827
+ if (!propName) return;
828
+ if (!fnName) {
829
+ this[propName] = null;
830
+ return;
831
+ }
832
+ const fn = typeof window !== "undefined" ? window[fnName] : undefined;
833
+ if (typeof fn === "function") {
834
+ this[propName] = fn;
835
+ this._log(`Callback attribute "${attrName}" → window.${fnName}`);
836
+ } else {
837
+ this._log(`Warning: "${fnName}" not found on window for attribute "${attrName}"`);
838
+ }
839
+ }
840
+
841
+ /** Seeds all callback attributes declared in HTML at connect time. */
842
+ _seedCallbackAttributes() {
843
+ for (const attrName of Object.keys(BisonOperatorPayments._callbackAttrMap)) {
844
+ const val = this.getAttribute(attrName);
845
+ if (val) this._resolveCallbackAttr(attrName, val.trim());
846
+ }
847
+ }
848
+
849
+ /**
850
+ * Rescues a property that was set on the element before it was upgraded
851
+ * by customElements.define. Without this, the constructor's field
852
+ * initializations would silently overwrite the consumer's pre-set values.
853
+ *
854
+ * @param {string} prop - Property name, e.g. 'onLookupSuccess'
855
+ */
856
+ _upgradeProperty(prop) {
857
+ if (Object.prototype.hasOwnProperty.call(this, prop)) {
858
+ const value = this[prop];
859
+ delete this[prop];
860
+ this[prop] = value;
861
+ }
790
862
  }
791
863
 
792
864
  connectedCallback() {
865
+ // Rescue any callback properties set on the element before upgrade.
866
+ // Must run first — before anything else could overwrite them.
867
+ this._upgradeProperty("onOpen");
868
+ this._upgradeProperty("onClose");
869
+ this._upgradeProperty("onLookupSuccess");
870
+ this._upgradeProperty("onLookupError");
871
+ this._upgradeProperty("onBankFetchSuccess");
872
+ this._upgradeProperty("onBankFetchError");
873
+ this._upgradeProperty("onLinkSuccess");
874
+ this._upgradeProperty("onLinkError");
875
+ this._upgradeProperty("onUnlinkSuccess");
876
+ this._upgradeProperty("onUnlinkError");
877
+
793
878
  // Seed embeddable key from initial attribute
794
879
  const initialKey = (this.getAttribute("x-embeddable-key") || "").trim();
795
880
  if (initialKey) {
@@ -797,6 +882,10 @@ class BisonOperatorPayments extends HTMLElement {
797
882
  this._disabledReason = null;
798
883
  }
799
884
 
885
+ // Seed any callback attributes declared directly in HTML.
886
+ // Attribute values take lower priority — only apply if JS property not already set.
887
+ this._seedCallbackAttributes();
888
+
800
889
  this._injectStyles();
801
890
  this._renderTrigger();
802
891
  // Evaluate initial attribute state on connect
@@ -827,11 +916,28 @@ class BisonOperatorPayments extends HTMLElement {
827
916
  this._log(`Attribute changed: ${name} → "${newVal}" (was "${oldVal}")`);
828
917
  this._evaluateOperatorAttributes();
829
918
  }
919
+ return;
920
+ }
921
+ // Callback attributes: resolve the named window function and wire it up
922
+ if (name in BisonOperatorPayments._callbackAttrMap) {
923
+ this._resolveCallbackAttr(name, (newVal || "").trim() || null);
830
924
  }
831
925
  }
832
926
 
927
+ open() {
928
+ this._isOpen = true;
929
+ this._isClosing = false;
930
+ this._render();
931
+ if (typeof this.onOpen === "function") this.onOpen();
932
+ }
933
+
934
+ /** Programmatic close */
935
+ close() {
936
+ this._handleClose();
937
+ }
938
+
833
939
  get isOpen() {
834
- return this.hasAttribute("open");
940
+ return this._isOpen;
835
941
  }
836
942
 
837
943
  /** Resolves the API instance and syncs the current embeddable key. */
@@ -957,7 +1063,7 @@ class BisonOperatorPayments extends HTMLElement {
957
1063
  this._componentDisabled = false;
958
1064
  this._dispatchLookupEvent({ status: "success", data: result });
959
1065
  if (typeof this.onLookupSuccess === "function")
960
- this.onLookupSuccess(result);
1066
+ this.onLookupSuccess(result.data);
961
1067
 
962
1068
  // Fetch operator bank accounts
963
1069
  if (this._operatorId) {
@@ -1059,7 +1165,7 @@ class BisonOperatorPayments extends HTMLElement {
1059
1165
 
1060
1166
  this._log("Fetched bank accounts successfully", this._accounts);
1061
1167
  if (typeof this.onBankFetchSuccess === "function")
1062
- this.onBankFetchSuccess(this._accounts);
1168
+ this.onBankFetchSuccess(response.data);
1063
1169
  } catch (err) {
1064
1170
  const errData = err?.data || err;
1065
1171
  this._log("Error fetching bank accounts", errData);
@@ -1198,7 +1304,7 @@ class BisonOperatorPayments extends HTMLElement {
1198
1304
  "animationend",
1199
1305
  () => {
1200
1306
  this._isClosing = false;
1201
- this.removeAttribute("open");
1307
+ this._isOpen = false;
1202
1308
  setTimeout(() => this._resetState(), 50);
1203
1309
  this._render();
1204
1310
  this.dispatchEvent(
@@ -1210,7 +1316,7 @@ class BisonOperatorPayments extends HTMLElement {
1210
1316
  );
1211
1317
  } else {
1212
1318
  this._isClosing = false;
1213
- this.removeAttribute("open");
1319
+ this._isOpen = false;
1214
1320
  this._resetState();
1215
1321
  this._render();
1216
1322
  this.dispatchEvent(
@@ -1611,7 +1717,7 @@ class BisonOperatorPayments extends HTMLElement {
1611
1717
  this._linkModalResult = "success";
1612
1718
  this._renderLinkModal();
1613
1719
  if (typeof this.onLinkSuccess === "function")
1614
- this.onLinkSuccess(this._pendingLinkedAccount);
1720
+ this.onLinkSuccess(response.data);
1615
1721
  } catch (err) {
1616
1722
  this._log("Error linking account:", err);
1617
1723
  const errData = err?.data || err;
@@ -2136,10 +2242,7 @@ class BisonOperatorPayments extends HTMLElement {
2136
2242
  if (this._componentDisabled) btn.setAttribute("aria-disabled", "true");
2137
2243
  btn.addEventListener("click", () => {
2138
2244
  if (this._componentDisabled) return;
2139
- this.setAttribute("open", "");
2140
- this._isClosing = false;
2141
- this._render();
2142
- if (typeof this.onOpen === "function") this.onOpen();
2245
+ this.open();
2143
2246
  });
2144
2247
 
2145
2248
  const tooltip = document.createElement("span");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bison-web-components",
3
- "version": "1.6.0",
3
+ "version": "2.0.0",
4
4
  "description": "Bison JIB's suite of web components",
5
5
  "main": "component.js",
6
6
  "type": "module",
package/wio-payment.js CHANGED
@@ -81,7 +81,6 @@ class WioPayment extends HTMLElement {
81
81
  "redirect-url",
82
82
  "on-success",
83
83
  "on-error",
84
- "open",
85
84
  "api-base-url",
86
85
  "embeddable-key",
87
86
  ];
@@ -268,10 +267,6 @@ class WioPayment extends HTMLElement {
268
267
  }
269
268
  break;
270
269
 
271
- case "open":
272
- this.open = newValue !== null;
273
- break;
274
-
275
270
  case "api-base-url":
276
271
  this.apiBaseURL = newValue;
277
272
  this.api = new BisonJibPayAPI(this.apiBaseURL, this.embeddableKey);