bison-web-components 2.0.0 → 4.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.
@@ -150,7 +150,8 @@
150
150
  <h1>Operator Bank Account Mgt.</h1>
151
151
  <p>
152
152
  Set the operator attributes below, then click the button to open the
153
- Bank Management modal. Both fields empty = component disabled.
153
+ Bank Management modal. Link Account uses the latest Plaid Link flow.
154
+ Both lookup fields empty = component disabled.
154
155
  </p>
155
156
 
156
157
  <!-- Attribute controls -->
@@ -191,84 +192,110 @@
191
192
  </div>
192
193
 
193
194
  <!-- ── Scripts ──────────────────────────────────── -->
194
- <script src="https://cdn.jsdelivr.net/npm/bison-web-components@1.0.0/bison-operator-payments.js"></script>
195
+ <script type="module" src="./bison-operator-payments.js"></script>
195
196
  <script type="module">
196
- import { BisonJibPayAPI } from "https://cdn.jsdelivr.net/npm/bison-web-components@1.0.0/api.js";
197
-
198
- // ── API Bootstrap ─────────────────────────────
199
- const API_BASE =
200
- "https://bison-backend-development-hhgrdbhcbwhahdfk.southeastasia-01.azurewebsites.net";
201
- const API_KEY = "BwVEfJ2u5y2JPsX8qGxtXlIhHyhu3qU2VW2y6Nf9Qc6KTsETvr";
202
-
203
- const api = new BisonJibPayAPI(API_BASE, API_KEY);
204
- window.__bisonApi = api;
205
-
206
- // ── DOM References ────────────────────────────
207
- const comp = document.querySelector("bison-operator-payments");
197
+ const paymentsEl = document.querySelector("bison-operator-payments");
208
198
  const logEl = document.getElementById("log");
209
- const inputEmbeddableKey = document.getElementById("input-embeddableKey");
210
- const inputOpOrgId = document.getElementById("input-opOrgId");
211
- const inputOrgNumber = document.getElementById("input-orgNumber");
199
+ const embeddableKeyInput = document.getElementById("input-embeddableKey");
200
+ const opOrgIdInput = document.getElementById("input-opOrgId");
201
+ const orgNumberInput = document.getElementById("input-orgNumber");
212
202
 
213
- // ── Helpers ────────────────────────────────────
214
- function addLog(text, cls = "") {
215
- const entry = document.createElement("div");
216
- entry.className = `entry ${cls}`;
217
- entry.textContent = `[${new Date().toLocaleTimeString()}] ${text}`;
218
- logEl.appendChild(entry);
203
+ function log(message, type = "") {
204
+ const row = document.createElement("div");
205
+ row.className = `entry ${type}`.trim();
206
+ const timestamp = new Date().toLocaleTimeString();
207
+ row.textContent = `[${timestamp}] ${message}`;
208
+ logEl.appendChild(row);
219
209
  logEl.scrollTop = logEl.scrollHeight;
220
210
  }
221
211
 
222
- // ── Attribute Binding ─────────────────────────
223
- function bindAttributeInput(inputEl, attrName) {
224
- inputEl.addEventListener("input", (e) => {
225
- const val = e.target.value.trim();
226
- if (val) {
227
- comp.setAttribute(attrName, val);
228
- addLog(`SET ${attrName}="${val}"`, "lookup");
229
- } else {
230
- comp.removeAttribute(attrName);
231
- addLog(`REMOVED ${attrName}`, "disabled");
232
- }
233
- });
212
+ function setOrRemoveAttr(el, attr, value) {
213
+ const cleaned = (value || "").trim();
214
+ if (cleaned) {
215
+ el.setAttribute(attr, cleaned);
216
+ } else {
217
+ el.removeAttribute(attr);
218
+ }
234
219
  }
235
220
 
236
- bindAttributeInput(inputEmbeddableKey, "x-embeddable-key");
237
- bindAttributeInput(inputOpOrgId, "op-org-id");
238
- bindAttributeInput(inputOrgNumber, "org-number");
239
-
240
- // ── Component Events ──────────────────────────
241
- comp.addEventListener("bop-close", () => {
242
- addLog("bop-close fired", "close");
243
- });
221
+ function applyComponentAttributes() {
222
+ setOrRemoveAttr(paymentsEl, "x-embeddable-key", embeddableKeyInput.value);
223
+ setOrRemoveAttr(paymentsEl, "op-org-id", opOrgIdInput.value);
224
+ setOrRemoveAttr(paymentsEl, "org-number", orgNumberInput.value);
225
+ }
244
226
 
245
- comp.addEventListener("bop-success", (e) => {
246
- const { bankName, accountType, lastFour } = e.detail;
247
- addLog(
248
- `bop-success ${bankName} · ${accountType} · ••••${lastFour}`,
249
- "success"
227
+ // Property callbacks
228
+ paymentsEl.onOpen = () => log("Modal opened");
229
+ paymentsEl.onClose = () => log("Modal closed", "close");
230
+ paymentsEl.onLookupSuccess = (data) => {
231
+ const operatorId = data?.operatorId || data?.data?.operatorId || "n/a";
232
+ log(`Lookup success (operatorId=${operatorId})`, "lookup");
233
+ };
234
+ paymentsEl.onLookupError = (error) => {
235
+ const msg = error?.message || "Lookup failed";
236
+ log(`Lookup error: ${msg}`, "error");
237
+ };
238
+ paymentsEl.onBankFetchSuccess = (accounts) => {
239
+ const count = Array.isArray(accounts) ? accounts.length : 0;
240
+ log(`Fetched ${count} bank account(s)`, "success");
241
+ };
242
+ paymentsEl.onBankFetchError = (error) => {
243
+ const msg = error?.message || "Bank account fetch failed";
244
+ log(`Bank fetch error: ${msg}`, "error");
245
+ };
246
+ paymentsEl.onLinkSuccess = (payload) => {
247
+ const succeeded = payload?.allSucceeded;
248
+ log(
249
+ `Link success${typeof succeeded === "boolean" ? ` (allSucceeded=${succeeded})` : ""}`,
250
+ "success",
250
251
  );
252
+ };
253
+ paymentsEl.onLinkError = (error) => {
254
+ const msg = error?.message || "Link account failed";
255
+ log(`Link error: ${msg}`, "error");
256
+ };
257
+ paymentsEl.onUnlinkSuccess = (accounts) => {
258
+ const count = Array.isArray(accounts) ? accounts.length : 0;
259
+ log(`Unlinked ${count} account(s)`, "success");
260
+ };
261
+ paymentsEl.onUnlinkError = (errors) => {
262
+ const count = Array.isArray(errors) ? errors.length : 0;
263
+ log(`Unlink error for ${count} account(s)`, "error");
264
+ };
265
+
266
+ // Custom events
267
+ paymentsEl.addEventListener("bop-operator-lookup", (event) => {
268
+ const status = event?.detail?.status || "unknown";
269
+ const cssClass =
270
+ status === "success"
271
+ ? "lookup"
272
+ : status === "disabled"
273
+ ? "disabled"
274
+ : status === "error"
275
+ ? "error"
276
+ : "";
277
+ log(`Lookup event status: ${status}`, cssClass);
251
278
  });
252
279
 
253
- comp.addEventListener("bop-operator-lookup", (e) => {
254
- const { status, data, error, reason } = e.detail;
280
+ paymentsEl.addEventListener("bop-success", (event) => {
281
+ const detail = event.detail || {};
282
+ const bankName = detail.bankName || "Unknown bank";
283
+ const lastFour = detail.lastFour || "----";
284
+ log(`bop-success: ${bankName} ••••${lastFour}`, "success");
285
+ });
255
286
 
256
- switch (status) {
257
- case "success":
258
- addLog("bop-operator-lookup → SUCCESS", "success");
259
- addLog(` Data: ${JSON.stringify(data)}`, "success");
260
- break;
261
- case "error":
262
- addLog("bop-operator-lookup → ERROR", "error");
263
- addLog(` ${JSON.stringify(error)}`, "error");
264
- break;
265
- case "disabled":
266
- addLog(`bop-operator-lookup → DISABLED: ${reason}`, "disabled");
267
- break;
268
- }
287
+ paymentsEl.addEventListener("bop-close", () => {
288
+ log("bop-close emitted", "close");
269
289
  });
270
290
 
271
- addLog("Component ready. Set x-embeddable-key first, then op-org-id or org-number.");
291
+ // Attribute controls
292
+ embeddableKeyInput.addEventListener("input", applyComponentAttributes);
293
+ opOrgIdInput.addEventListener("input", applyComponentAttributes);
294
+ orgNumberInput.addEventListener("input", applyComponentAttributes);
295
+
296
+ applyComponentAttributes();
297
+ log("Demo ready. Set embeddable key and operator lookup fields.");
298
+ log("Link Account now uses Plaid Link + registerPlaidBankAccount.");
272
299
  </script>
273
300
  </body>
274
301
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bison-web-components",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Bison JIB's suite of web components",
5
5
  "main": "component.js",
6
6
  "type": "module",