@ozura/elements 1.3.1-next.75 → 1.3.1-next.77

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.
@@ -1282,6 +1282,10 @@ class OzVault {
1282
1282
  return false;
1283
1283
  return els.every(el => this.completionState.get(el.frameId) === true);
1284
1284
  }
1285
+ /** The state a field reports before its first change event (and after reset/reload). */
1286
+ makeDefaultFieldState() {
1287
+ return { empty: true, complete: false, valid: false };
1288
+ }
1285
1289
  /**
1286
1290
  * Snapshot of every created field's latest state, keyed by element type.
1287
1291
  * Card and bank fields are combined (their type keys never collide). Useful for
@@ -1293,10 +1297,10 @@ class OzVault {
1293
1297
  var _a, _b;
1294
1298
  const snapshot = {};
1295
1299
  for (const [type, el] of this.elementsByType) {
1296
- snapshot[type] = Object.assign({}, ((_a = this.fieldStates.get(el.frameId)) !== null && _a !== void 0 ? _a : { empty: true, complete: false, valid: false }));
1300
+ snapshot[type] = Object.assign({}, ((_a = this.fieldStates.get(el.frameId)) !== null && _a !== void 0 ? _a : this.makeDefaultFieldState()));
1297
1301
  }
1298
1302
  for (const [type, el] of this.bankElementsByType) {
1299
- snapshot[type] = Object.assign({}, ((_b = this.fieldStates.get(el.frameId)) !== null && _b !== void 0 ? _b : { empty: true, complete: false, valid: false }));
1303
+ snapshot[type] = Object.assign({}, ((_b = this.fieldStates.get(el.frameId)) !== null && _b !== void 0 ? _b : this.makeDefaultFieldState()));
1300
1304
  }
1301
1305
  return snapshot;
1302
1306
  }
@@ -1364,7 +1368,7 @@ class OzVault {
1364
1368
  }, this._debug);
1365
1369
  this.elements.set(el.frameId, el);
1366
1370
  typeMap.set(type, el);
1367
- this.fieldStates.set(el.frameId, { empty: true, complete: false, valid: false });
1371
+ this.fieldStates.set(el.frameId, this.makeDefaultFieldState());
1368
1372
  return el;
1369
1373
  }
1370
1374
  /**
@@ -1666,7 +1670,7 @@ class OzVault {
1666
1670
  }
1667
1671
  // Mirror for field states: every created field returns to its default.
1668
1672
  for (const frameId of this.fieldStates.keys()) {
1669
- this.fieldStates.set(frameId, { empty: true, complete: false, valid: false });
1673
+ this.fieldStates.set(frameId, this.makeDefaultFieldState());
1670
1674
  }
1671
1675
  // NOTE: _tokenizeSuccessCount is intentionally NOT reset.
1672
1676
  // It reflects real server-side wax key budget consumption. Zeroing it
@@ -1877,6 +1881,10 @@ class OzVault {
1877
1881
  // the previous session and justCompleted never fires, breaking auto-advance.
1878
1882
  if (msg.type === 'OZ_FRAME_READY') {
1879
1883
  this.completionState.set(frameId, false);
1884
+ // Mirror the completion reset: a reloaded iframe starts empty, so the
1885
+ // field state must return to default rather than serving pre-reload data
1886
+ // (e.g. a stale card brand) until the next OZ_CHANGE arrives.
1887
+ this.fieldStates.set(frameId, this.makeDefaultFieldState());
1880
1888
  if (msg.__ozVersion !== PROTOCOL_VERSION) {
1881
1889
  console.warn(`[OzVault] Protocol version mismatch on element frame "${frameId}" — ` +
1882
1890
  `SDK expects v${PROTOCOL_VERSION}, frame reported v${typeof msg.__ozVersion === 'number' ? msg.__ozVersion : '(none)'}. ` +
@@ -1918,9 +1926,13 @@ class OzVault {
1918
1926
  var _a, _b, _c;
1919
1927
  const complete = msg.complete;
1920
1928
  const valid = msg.valid;
1929
+ // Narrow rather than blind-cast: a malformed/legacy frame that omits `empty`
1930
+ // must not write `undefined` into the public FieldState contract.
1931
+ const empty = typeof msg.empty === 'boolean' ? msg.empty : true;
1921
1932
  const wasComplete = (_a = this.completionState.get(el.frameId)) !== null && _a !== void 0 ? _a : false;
1922
1933
  this.completionState.set(el.frameId, complete && valid);
1923
- this.fieldStates.set(el.frameId, Object.assign(Object.assign({ empty: msg.empty, complete,
1934
+ this.fieldStates.set(el.frameId, Object.assign(Object.assign({ empty,
1935
+ complete,
1924
1936
  valid }, (typeof msg.error === 'string' ? { error: msg.error } : {})), (typeof msg.cardBrand === 'string' ? { cardBrand: msg.cardBrand } : {})));
1925
1937
  // Require valid too — avoids advancing at 13 digits for unknown-brand cards
1926
1938
  // where isComplete() fires before the user has finished typing.