@mocanetwork/airkit 1.2.1 → 1.3.0-beta.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.
@@ -118,14 +118,14 @@ const AirAuthMessageTypes = {
118
118
  SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
119
119
  CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
120
120
  CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
121
- PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
122
- PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
121
+ GET_PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_get_partner_access_token_request",
122
+ GET_PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_get_partner_access_token_response",
123
123
  LOGOUT_REQUEST: "air_auth_logout_request",
124
124
  LOGOUT_RESPONSE: "air_auth_logout_response",
125
125
  RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
126
126
  };
127
127
 
128
- const AirWalletMessageTypes = {
128
+ const AirMessageTypes = {
129
129
  SERVICE_STARTED: "air_service_started",
130
130
  INITIALIZATION_REQUEST: "air_initialization_request",
131
131
  INITIALIZATION_RESPONSE: "air_initialization_response",
@@ -133,8 +133,8 @@ const AirWalletMessageTypes = {
133
133
  WALLET_INITIALIZED: "air_wallet_initialized",
134
134
  WALLET_LOGIN_REQUEST: "air_wallet_login_request",
135
135
  WALLET_LOGIN_RESPONSE: "air_wallet_login_response",
136
- SETUP_OR_UPDATE_MFA_REQUEST: "air_setup_mfa_request",
137
- SETUP_OR_UPDATE_MFA_RESPONSE: "air_setup_mfa_response",
136
+ SETUP_MFA_REQUEST: "air_setup_mfa_request",
137
+ SETUP_MFA_RESPONSE: "air_setup_mfa_response",
138
138
  CLAIM_ID_REQUEST: "air_claim_id_request",
139
139
  CLAIM_ID_RESPONSE: "air_claim_id_response",
140
140
  DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
@@ -150,8 +150,6 @@ const AirWalletMessageTypes = {
150
150
  WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
151
151
  OPEN_WINDOW_REQUEST: "air_open_window_request",
152
152
  OPEN_WINDOW_RESPONSE: "air_open_window_response",
153
- OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
154
- OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
155
153
  WINDOW_CLOSED: "air_window_closed",
156
154
  IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
157
155
  IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
@@ -191,50 +189,6 @@ function ensureError(value) {
191
189
  return new Error(`This value was not thrown as type Error: ${stringified}`);
192
190
  }
193
191
 
194
- const BUILD_ENV = {
195
- PRODUCTION: "production",
196
- UAT: "uat",
197
- STAGING: "staging",
198
- DEVELOPMENT: "development",
199
- };
200
-
201
- const AIR_URLS = {
202
- [BUILD_ENV.DEVELOPMENT]: {
203
- authUrl: "http://localhost:8100",
204
- walletUrl: "http://localhost:8200",
205
- },
206
- [BUILD_ENV.UAT]: {
207
- authUrl: "https://auth.uat.air3.com",
208
- walletUrl: "https://account.uat.air3.com",
209
- },
210
- [BUILD_ENV.STAGING]: {
211
- authUrl: "https://auth.staging.air3.com",
212
- walletUrl: "https://account.staging.air3.com",
213
- },
214
- [BUILD_ENV.PRODUCTION]: {
215
- authUrl: "https://auth.air3.com",
216
- walletUrl: "https://account.air3.com",
217
- },
218
- };
219
- const isElement = (element) => element instanceof Element || element instanceof Document;
220
- const randomId = () => Math.random().toString(36).slice(2);
221
- const extractErrorHash = (message) => {
222
- if (!message)
223
- return "";
224
- // Format: "reason: 0x..."
225
- if (message.includes("reason:")) {
226
- return message.split("reason:")[1].trim();
227
- }
228
- // Format: "UserOperation reverted during simulation with reason: 0x..."
229
- if (message.includes("with reason:")) {
230
- const match = message.match(/with reason: (0x[a-fA-F0-9]+)/);
231
- return match ? match[1].trim() : "";
232
- }
233
- // Look for any 0x pattern that could be a hash
234
- const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
235
- return hexMatch ? hexMatch[1].trim() : "";
236
- };
237
-
238
192
  class AirServiceError extends BaseError {
239
193
  static from(error) {
240
194
  if (error instanceof AirServiceError) {
@@ -252,7 +206,6 @@ class AirServiceError extends BaseError {
252
206
  class ProviderRpcError extends Error {
253
207
  constructor(message) {
254
208
  super(message);
255
- this.metaMessages = [];
256
209
  }
257
210
  }
258
211
  class UserRejectedRequestError extends ProviderRpcError {
@@ -297,17 +250,6 @@ class SwitchChainError extends ProviderRpcError {
297
250
  this.name = "SwitchChainError";
298
251
  }
299
252
  }
300
- class TransactionRejectedRpcError extends ProviderRpcError {
301
- constructor(message) {
302
- // Remove the "Version: viem@x.x.x" suffix if present
303
- const cleanMessage = message.replace(/\nVersion:.*$/, '');
304
- super(cleanMessage);
305
- this.code = -32003;
306
- this.name = "TransactionRejectedRpcError";
307
- // Parse the error hash from the message
308
- this.metaMessages.push(extractErrorHash(cleanMessage));
309
- }
310
- }
311
253
  class InvalidRequestRpcError extends ProviderRpcError {
312
254
  constructor() {
313
255
  super(...arguments);
@@ -358,8 +300,6 @@ function ensureProviderRpcError(value) {
358
300
  return new ChainDisconnectedError(value.errorMessage);
359
301
  case 4902:
360
302
  return new SwitchChainError(value.errorMessage);
361
- case -32003:
362
- return new TransactionRejectedRpcError(value.errorMessage);
363
303
  }
364
304
  }
365
305
  }
@@ -373,461 +313,130 @@ function ensureProviderRpcError(value) {
373
313
  return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
374
314
  }
375
315
 
376
- function getDefaultExportFromCjs (x) {
377
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
316
+ function isFunction(value) {
317
+ return typeof value === 'function';
378
318
  }
379
319
 
380
- var loglevel$1 = {exports: {}};
381
-
382
- /*
383
- * loglevel - https://github.com/pimterry/loglevel
384
- *
385
- * Copyright (c) 2013 Tim Perry
386
- * Licensed under the MIT license.
387
- */
388
- var loglevel = loglevel$1.exports;
389
- var hasRequiredLoglevel;
390
- function requireLoglevel() {
391
- if (hasRequiredLoglevel) return loglevel$1.exports;
392
- hasRequiredLoglevel = 1;
393
- (function (module) {
394
- (function (root, definition) {
320
+ function createErrorClass(createImpl) {
321
+ var _super = function (instance) {
322
+ Error.call(instance);
323
+ instance.stack = new Error().stack;
324
+ };
325
+ var ctorFunc = createImpl(_super);
326
+ ctorFunc.prototype = Object.create(Error.prototype);
327
+ ctorFunc.prototype.constructor = ctorFunc;
328
+ return ctorFunc;
329
+ }
395
330
 
396
- if (module.exports) {
397
- module.exports = definition();
398
- } else {
399
- root.log = definition();
400
- }
401
- })(loglevel, function () {
331
+ var UnsubscriptionError = createErrorClass(function (_super) {
332
+ return function UnsubscriptionErrorImpl(errors) {
333
+ _super(this);
334
+ this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
335
+ return i + 1 + ") " + err.toString();
336
+ }).join('\n ') : '';
337
+ this.name = 'UnsubscriptionError';
338
+ this.errors = errors;
339
+ };
340
+ });
402
341
 
403
- // Slightly dubious tricks to cut down minimized file size
404
- var noop = function () {};
405
- var undefinedType = "undefined";
406
- var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
407
- var logMethods = ["trace", "debug", "info", "warn", "error"];
408
- var _loggersByName = {};
409
- var defaultLogger = null;
342
+ function arrRemove(arr, item) {
343
+ if (arr) {
344
+ var index = arr.indexOf(item);
345
+ 0 <= index && arr.splice(index, 1);
346
+ }
347
+ }
410
348
 
411
- // Cross-browser bind equivalent that works at least back to IE6
412
- function bindMethod(obj, methodName) {
413
- var method = obj[methodName];
414
- if (typeof method.bind === 'function') {
415
- return method.bind(obj);
416
- } else {
349
+ var Subscription = function () {
350
+ function Subscription(initialTeardown) {
351
+ this.initialTeardown = initialTeardown;
352
+ this.closed = false;
353
+ this._parentage = null;
354
+ this._finalizers = null;
355
+ }
356
+ Subscription.prototype.unsubscribe = function () {
357
+ var e_1, _a, e_2, _b;
358
+ var errors;
359
+ if (!this.closed) {
360
+ this.closed = true;
361
+ var _parentage = this._parentage;
362
+ if (_parentage) {
363
+ this._parentage = null;
364
+ if (Array.isArray(_parentage)) {
417
365
  try {
418
- return Function.prototype.bind.call(method, obj);
419
- } catch (e) {
420
- // Missing bind shim or IE8 + Modernizr, fallback to wrapping
421
- return function () {
422
- return Function.prototype.apply.apply(method, [obj, arguments]);
366
+ for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
367
+ var parent_1 = _parentage_1_1.value;
368
+ parent_1.remove(this);
369
+ }
370
+ } catch (e_1_1) {
371
+ e_1 = {
372
+ error: e_1_1
423
373
  };
374
+ } finally {
375
+ try {
376
+ if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
377
+ } finally {
378
+ if (e_1) throw e_1.error;
379
+ }
424
380
  }
381
+ } else {
382
+ _parentage.remove(this);
425
383
  }
426
384
  }
427
-
428
- // Trace() doesn't print the message in IE, so for that case we need to wrap it
429
- function traceForIE() {
430
- if (console.log) {
431
- if (console.log.apply) {
432
- console.log.apply(console, arguments);
433
- } else {
434
- // In old IE, native console methods themselves don't have apply().
435
- Function.prototype.apply.apply(console.log, [console, arguments]);
436
- }
385
+ var initialFinalizer = this.initialTeardown;
386
+ if (isFunction(initialFinalizer)) {
387
+ try {
388
+ initialFinalizer();
389
+ } catch (e) {
390
+ errors = e instanceof UnsubscriptionError ? e.errors : [e];
437
391
  }
438
- if (console.trace) console.trace();
439
392
  }
440
-
441
- // Build the best logging method possible for this env
442
- // Wherever possible we want to bind, not wrap, to preserve stack traces
443
- function realMethod(methodName) {
444
- if (methodName === 'debug') {
445
- methodName = 'log';
446
- }
447
- if (typeof console === undefinedType) {
448
- return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
449
- } else if (methodName === 'trace' && isIE) {
450
- return traceForIE;
451
- } else if (console[methodName] !== undefined) {
452
- return bindMethod(console, methodName);
453
- } else if (console.log !== undefined) {
454
- return bindMethod(console, 'log');
455
- } else {
456
- return noop;
393
+ var _finalizers = this._finalizers;
394
+ if (_finalizers) {
395
+ this._finalizers = null;
396
+ try {
397
+ for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
398
+ var finalizer = _finalizers_1_1.value;
399
+ try {
400
+ execFinalizer(finalizer);
401
+ } catch (err) {
402
+ errors = errors !== null && errors !== void 0 ? errors : [];
403
+ if (err instanceof UnsubscriptionError) {
404
+ errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
405
+ } else {
406
+ errors.push(err);
407
+ }
408
+ }
409
+ }
410
+ } catch (e_2_1) {
411
+ e_2 = {
412
+ error: e_2_1
413
+ };
414
+ } finally {
415
+ try {
416
+ if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
417
+ } finally {
418
+ if (e_2) throw e_2.error;
419
+ }
457
420
  }
458
421
  }
459
-
460
- // These private functions always need `this` to be set properly
461
-
462
- function replaceLoggingMethods() {
463
- /*jshint validthis:true */
464
- var level = this.getLevel();
465
-
466
- // Replace the actual methods.
467
- for (var i = 0; i < logMethods.length; i++) {
468
- var methodName = logMethods[i];
469
- this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
470
- }
471
-
472
- // Define log.log as an alias for log.debug
473
- this.log = this.debug;
474
-
475
- // Return any important warnings.
476
- if (typeof console === undefinedType && level < this.levels.SILENT) {
477
- return "No console available for logging";
478
- }
422
+ if (errors) {
423
+ throw new UnsubscriptionError(errors);
479
424
  }
480
-
481
- // In old IE versions, the console isn't present until you first open it.
482
- // We build realMethod() replacements here that regenerate logging methods
483
- function enableLoggingWhenConsoleArrives(methodName) {
484
- return function () {
485
- if (typeof console !== undefinedType) {
486
- replaceLoggingMethods.call(this);
487
- this[methodName].apply(this, arguments);
425
+ }
426
+ };
427
+ Subscription.prototype.add = function (teardown) {
428
+ var _a;
429
+ if (teardown && teardown !== this) {
430
+ if (this.closed) {
431
+ execFinalizer(teardown);
432
+ } else {
433
+ if (teardown instanceof Subscription) {
434
+ if (teardown.closed || teardown._hasParent(this)) {
435
+ return;
488
436
  }
489
- };
490
- }
491
-
492
- // By default, we use closely bound real methods wherever possible, and
493
- // otherwise we wait for a console to appear, and then try again.
494
- function defaultMethodFactory(methodName, _level, _loggerName) {
495
- /*jshint validthis:true */
496
- return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
497
- }
498
- function Logger(name, factory) {
499
- // Private instance variables.
500
- var self = this;
501
- /**
502
- * The level inherited from a parent logger (or a global default). We
503
- * cache this here rather than delegating to the parent so that it stays
504
- * in sync with the actual logging methods that we have installed (the
505
- * parent could change levels but we might not have rebuilt the loggers
506
- * in this child yet).
507
- * @type {number}
508
- */
509
- var inheritedLevel;
510
- /**
511
- * The default level for this logger, if any. If set, this overrides
512
- * `inheritedLevel`.
513
- * @type {number|null}
514
- */
515
- var defaultLevel;
516
- /**
517
- * A user-specific level for this logger. If set, this overrides
518
- * `defaultLevel`.
519
- * @type {number|null}
520
- */
521
- var userLevel;
522
- var storageKey = "loglevel";
523
- if (typeof name === "string") {
524
- storageKey += ":" + name;
525
- } else if (typeof name === "symbol") {
526
- storageKey = undefined;
527
- }
528
- function persistLevelIfPossible(levelNum) {
529
- var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
530
- if (typeof window === undefinedType || !storageKey) return;
531
-
532
- // Use localStorage if available
533
- try {
534
- window.localStorage[storageKey] = levelName;
535
- return;
536
- } catch (ignore) {}
537
-
538
- // Use session cookie as fallback
539
- try {
540
- window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
541
- } catch (ignore) {}
542
- }
543
- function getPersistedLevel() {
544
- var storedLevel;
545
- if (typeof window === undefinedType || !storageKey) return;
546
- try {
547
- storedLevel = window.localStorage[storageKey];
548
- } catch (ignore) {}
549
-
550
- // Fallback to cookies if local storage gives us nothing
551
- if (typeof storedLevel === undefinedType) {
552
- try {
553
- var cookie = window.document.cookie;
554
- var cookieName = encodeURIComponent(storageKey);
555
- var location = cookie.indexOf(cookieName + "=");
556
- if (location !== -1) {
557
- storedLevel = /^([^;]+)/.exec(cookie.slice(location + cookieName.length + 1))[1];
558
- }
559
- } catch (ignore) {}
560
- }
561
-
562
- // If the stored level is not valid, treat it as if nothing was stored.
563
- if (self.levels[storedLevel] === undefined) {
564
- storedLevel = undefined;
565
- }
566
- return storedLevel;
567
- }
568
- function clearPersistedLevel() {
569
- if (typeof window === undefinedType || !storageKey) return;
570
-
571
- // Use localStorage if available
572
- try {
573
- window.localStorage.removeItem(storageKey);
574
- } catch (ignore) {}
575
-
576
- // Use session cookie as fallback
577
- try {
578
- window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
579
- } catch (ignore) {}
580
- }
581
- function normalizeLevel(input) {
582
- var level = input;
583
- if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
584
- level = self.levels[level.toUpperCase()];
585
- }
586
- if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
587
- return level;
588
- } else {
589
- throw new TypeError("log.setLevel() called with invalid level: " + input);
590
- }
591
- }
592
-
593
- /*
594
- *
595
- * Public logger API - see https://github.com/pimterry/loglevel for details
596
- *
597
- */
598
-
599
- self.name = name;
600
- self.levels = {
601
- "TRACE": 0,
602
- "DEBUG": 1,
603
- "INFO": 2,
604
- "WARN": 3,
605
- "ERROR": 4,
606
- "SILENT": 5
607
- };
608
- self.methodFactory = factory || defaultMethodFactory;
609
- self.getLevel = function () {
610
- if (userLevel != null) {
611
- return userLevel;
612
- } else if (defaultLevel != null) {
613
- return defaultLevel;
614
- } else {
615
- return inheritedLevel;
616
- }
617
- };
618
- self.setLevel = function (level, persist) {
619
- userLevel = normalizeLevel(level);
620
- if (persist !== false) {
621
- // defaults to true
622
- persistLevelIfPossible(userLevel);
623
- }
624
-
625
- // NOTE: in v2, this should call rebuild(), which updates children.
626
- return replaceLoggingMethods.call(self);
627
- };
628
- self.setDefaultLevel = function (level) {
629
- defaultLevel = normalizeLevel(level);
630
- if (!getPersistedLevel()) {
631
- self.setLevel(level, false);
632
- }
633
- };
634
- self.resetLevel = function () {
635
- userLevel = null;
636
- clearPersistedLevel();
637
- replaceLoggingMethods.call(self);
638
- };
639
- self.enableAll = function (persist) {
640
- self.setLevel(self.levels.TRACE, persist);
641
- };
642
- self.disableAll = function (persist) {
643
- self.setLevel(self.levels.SILENT, persist);
644
- };
645
- self.rebuild = function () {
646
- if (defaultLogger !== self) {
647
- inheritedLevel = normalizeLevel(defaultLogger.getLevel());
648
- }
649
- replaceLoggingMethods.call(self);
650
- if (defaultLogger === self) {
651
- for (var childName in _loggersByName) {
652
- _loggersByName[childName].rebuild();
653
- }
654
- }
655
- };
656
-
657
- // Initialize all the internal levels.
658
- inheritedLevel = normalizeLevel(defaultLogger ? defaultLogger.getLevel() : "WARN");
659
- var initialLevel = getPersistedLevel();
660
- if (initialLevel != null) {
661
- userLevel = normalizeLevel(initialLevel);
662
- }
663
- replaceLoggingMethods.call(self);
664
- }
665
-
666
- /*
667
- *
668
- * Top-level API
669
- *
670
- */
671
-
672
- defaultLogger = new Logger();
673
- defaultLogger.getLogger = function getLogger(name) {
674
- if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
675
- throw new TypeError("You must supply a name when creating a logger.");
676
- }
677
- var logger = _loggersByName[name];
678
- if (!logger) {
679
- logger = _loggersByName[name] = new Logger(name, defaultLogger.methodFactory);
680
- }
681
- return logger;
682
- };
683
-
684
- // Grab the current global log variable in case of overwrite
685
- var _log = typeof window !== undefinedType ? window.log : undefined;
686
- defaultLogger.noConflict = function () {
687
- if (typeof window !== undefinedType && window.log === defaultLogger) {
688
- window.log = _log;
689
- }
690
- return defaultLogger;
691
- };
692
- defaultLogger.getLoggers = function getLoggers() {
693
- return _loggersByName;
694
- };
695
-
696
- // ES6 default export, for compatibility
697
- defaultLogger['default'] = defaultLogger;
698
- return defaultLogger;
699
- });
700
- })(loglevel$1);
701
- return loglevel$1.exports;
702
- }
703
-
704
- var loglevelExports = requireLoglevel();
705
- var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
706
-
707
- function isFunction(value) {
708
- return typeof value === 'function';
709
- }
710
-
711
- function createErrorClass(createImpl) {
712
- var _super = function (instance) {
713
- Error.call(instance);
714
- instance.stack = new Error().stack;
715
- };
716
- var ctorFunc = createImpl(_super);
717
- ctorFunc.prototype = Object.create(Error.prototype);
718
- ctorFunc.prototype.constructor = ctorFunc;
719
- return ctorFunc;
720
- }
721
-
722
- var UnsubscriptionError = createErrorClass(function (_super) {
723
- return function UnsubscriptionErrorImpl(errors) {
724
- _super(this);
725
- this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
726
- return i + 1 + ") " + err.toString();
727
- }).join('\n ') : '';
728
- this.name = 'UnsubscriptionError';
729
- this.errors = errors;
730
- };
731
- });
732
-
733
- function arrRemove(arr, item) {
734
- if (arr) {
735
- var index = arr.indexOf(item);
736
- 0 <= index && arr.splice(index, 1);
737
- }
738
- }
739
-
740
- var Subscription = function () {
741
- function Subscription(initialTeardown) {
742
- this.initialTeardown = initialTeardown;
743
- this.closed = false;
744
- this._parentage = null;
745
- this._finalizers = null;
746
- }
747
- Subscription.prototype.unsubscribe = function () {
748
- var e_1, _a, e_2, _b;
749
- var errors;
750
- if (!this.closed) {
751
- this.closed = true;
752
- var _parentage = this._parentage;
753
- if (_parentage) {
754
- this._parentage = null;
755
- if (Array.isArray(_parentage)) {
756
- try {
757
- for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
758
- var parent_1 = _parentage_1_1.value;
759
- parent_1.remove(this);
760
- }
761
- } catch (e_1_1) {
762
- e_1 = {
763
- error: e_1_1
764
- };
765
- } finally {
766
- try {
767
- if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
768
- } finally {
769
- if (e_1) throw e_1.error;
770
- }
771
- }
772
- } else {
773
- _parentage.remove(this);
774
- }
775
- }
776
- var initialFinalizer = this.initialTeardown;
777
- if (isFunction(initialFinalizer)) {
778
- try {
779
- initialFinalizer();
780
- } catch (e) {
781
- errors = e instanceof UnsubscriptionError ? e.errors : [e];
782
- }
783
- }
784
- var _finalizers = this._finalizers;
785
- if (_finalizers) {
786
- this._finalizers = null;
787
- try {
788
- for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
789
- var finalizer = _finalizers_1_1.value;
790
- try {
791
- execFinalizer(finalizer);
792
- } catch (err) {
793
- errors = errors !== null && errors !== void 0 ? errors : [];
794
- if (err instanceof UnsubscriptionError) {
795
- errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
796
- } else {
797
- errors.push(err);
798
- }
799
- }
800
- }
801
- } catch (e_2_1) {
802
- e_2 = {
803
- error: e_2_1
804
- };
805
- } finally {
806
- try {
807
- if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
808
- } finally {
809
- if (e_2) throw e_2.error;
810
- }
811
- }
812
- }
813
- if (errors) {
814
- throw new UnsubscriptionError(errors);
815
- }
816
- }
817
- };
818
- Subscription.prototype.add = function (teardown) {
819
- var _a;
820
- if (teardown && teardown !== this) {
821
- if (this.closed) {
822
- execFinalizer(teardown);
823
- } else {
824
- if (teardown instanceof Subscription) {
825
- if (teardown.closed || teardown._hasParent(this)) {
826
- return;
827
- }
828
- teardown._addParent(this);
829
- }
830
- (this._finalizers = (_a = this._finalizers) !== null && _a !== undefined ? _a : []).push(teardown);
437
+ teardown._addParent(this);
438
+ }
439
+ (this._finalizers = (_a = this._finalizers) !== null && _a !== undefined ? _a : []).push(teardown);
831
440
  }
832
441
  }
833
442
  };
@@ -1145,533 +754,625 @@ var Observable = function () {
1145
754
  });
1146
755
  });
1147
756
  };
1148
- Observable.create = function (subscribe) {
1149
- return new Observable(subscribe);
757
+ Observable.create = function (subscribe) {
758
+ return new Observable(subscribe);
759
+ };
760
+ return Observable;
761
+ }();
762
+ function getPromiseCtor(promiseCtor) {
763
+ var _a;
764
+ return (_a = promiseCtor !== null && promiseCtor !== undefined ? promiseCtor : config.Promise) !== null && _a !== undefined ? _a : Promise;
765
+ }
766
+ function isObserver(value) {
767
+ return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
768
+ }
769
+ function isSubscriber(value) {
770
+ return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
771
+ }
772
+
773
+ function hasLift(source) {
774
+ return isFunction(source === null || source === undefined ? undefined : source.lift);
775
+ }
776
+ function operate(init) {
777
+ return function (source) {
778
+ if (hasLift(source)) {
779
+ return source.lift(function (liftedSource) {
780
+ try {
781
+ return init(liftedSource, this);
782
+ } catch (err) {
783
+ this.error(err);
784
+ }
785
+ });
786
+ }
787
+ throw new TypeError('Unable to lift unknown Observable type');
788
+ };
789
+ }
790
+
791
+ function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
792
+ return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
793
+ }
794
+ var OperatorSubscriber = function (_super) {
795
+ __extends(OperatorSubscriber, _super);
796
+ function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
797
+ var _this = _super.call(this, destination) || this;
798
+ _this.onFinalize = onFinalize;
799
+ _this.shouldUnsubscribe = shouldUnsubscribe;
800
+ _this._next = onNext ? function (value) {
801
+ try {
802
+ onNext(value);
803
+ } catch (err) {
804
+ destination.error(err);
805
+ }
806
+ } : _super.prototype._next;
807
+ _this._error = onError ? function (err) {
808
+ try {
809
+ onError(err);
810
+ } catch (err) {
811
+ destination.error(err);
812
+ } finally {
813
+ this.unsubscribe();
814
+ }
815
+ } : _super.prototype._error;
816
+ _this._complete = onComplete ? function () {
817
+ try {
818
+ onComplete();
819
+ } catch (err) {
820
+ destination.error(err);
821
+ } finally {
822
+ this.unsubscribe();
823
+ }
824
+ } : _super.prototype._complete;
825
+ return _this;
826
+ }
827
+ OperatorSubscriber.prototype.unsubscribe = function () {
828
+ var _a;
829
+ if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
830
+ var closed_1 = this.closed;
831
+ _super.prototype.unsubscribe.call(this);
832
+ !closed_1 && ((_a = this.onFinalize) === null || _a === undefined ? undefined : _a.call(this));
833
+ }
834
+ };
835
+ return OperatorSubscriber;
836
+ }(Subscriber);
837
+
838
+ var ObjectUnsubscribedError = createErrorClass(function (_super) {
839
+ return function ObjectUnsubscribedErrorImpl() {
840
+ _super(this);
841
+ this.name = 'ObjectUnsubscribedError';
842
+ this.message = 'object unsubscribed';
843
+ };
844
+ });
845
+
846
+ var Subject = function (_super) {
847
+ __extends(Subject, _super);
848
+ function Subject() {
849
+ var _this = _super.call(this) || this;
850
+ _this.closed = false;
851
+ _this.currentObservers = null;
852
+ _this.observers = [];
853
+ _this.isStopped = false;
854
+ _this.hasError = false;
855
+ _this.thrownError = null;
856
+ return _this;
857
+ }
858
+ Subject.prototype.lift = function (operator) {
859
+ var subject = new AnonymousSubject(this, this);
860
+ subject.operator = operator;
861
+ return subject;
862
+ };
863
+ Subject.prototype._throwIfClosed = function () {
864
+ if (this.closed) {
865
+ throw new ObjectUnsubscribedError();
866
+ }
867
+ };
868
+ Subject.prototype.next = function (value) {
869
+ var _this = this;
870
+ errorContext(function () {
871
+ var e_1, _a;
872
+ _this._throwIfClosed();
873
+ if (!_this.isStopped) {
874
+ if (!_this.currentObservers) {
875
+ _this.currentObservers = Array.from(_this.observers);
876
+ }
877
+ try {
878
+ for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
879
+ var observer = _c.value;
880
+ observer.next(value);
881
+ }
882
+ } catch (e_1_1) {
883
+ e_1 = {
884
+ error: e_1_1
885
+ };
886
+ } finally {
887
+ try {
888
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
889
+ } finally {
890
+ if (e_1) throw e_1.error;
891
+ }
892
+ }
893
+ }
894
+ });
895
+ };
896
+ Subject.prototype.error = function (err) {
897
+ var _this = this;
898
+ errorContext(function () {
899
+ _this._throwIfClosed();
900
+ if (!_this.isStopped) {
901
+ _this.hasError = _this.isStopped = true;
902
+ _this.thrownError = err;
903
+ var observers = _this.observers;
904
+ while (observers.length) {
905
+ observers.shift().error(err);
906
+ }
907
+ }
908
+ });
909
+ };
910
+ Subject.prototype.complete = function () {
911
+ var _this = this;
912
+ errorContext(function () {
913
+ _this._throwIfClosed();
914
+ if (!_this.isStopped) {
915
+ _this.isStopped = true;
916
+ var observers = _this.observers;
917
+ while (observers.length) {
918
+ observers.shift().complete();
919
+ }
920
+ }
921
+ });
922
+ };
923
+ Subject.prototype.unsubscribe = function () {
924
+ this.isStopped = this.closed = true;
925
+ this.observers = this.currentObservers = null;
926
+ };
927
+ Object.defineProperty(Subject.prototype, "observed", {
928
+ get: function () {
929
+ var _a;
930
+ return ((_a = this.observers) === null || _a === undefined ? undefined : _a.length) > 0;
931
+ },
932
+ enumerable: false,
933
+ configurable: true
934
+ });
935
+ Subject.prototype._trySubscribe = function (subscriber) {
936
+ this._throwIfClosed();
937
+ return _super.prototype._trySubscribe.call(this, subscriber);
938
+ };
939
+ Subject.prototype._subscribe = function (subscriber) {
940
+ this._throwIfClosed();
941
+ this._checkFinalizedStatuses(subscriber);
942
+ return this._innerSubscribe(subscriber);
943
+ };
944
+ Subject.prototype._innerSubscribe = function (subscriber) {
945
+ var _this = this;
946
+ var _a = this,
947
+ hasError = _a.hasError,
948
+ isStopped = _a.isStopped,
949
+ observers = _a.observers;
950
+ if (hasError || isStopped) {
951
+ return EMPTY_SUBSCRIPTION;
952
+ }
953
+ this.currentObservers = null;
954
+ observers.push(subscriber);
955
+ return new Subscription(function () {
956
+ _this.currentObservers = null;
957
+ arrRemove(observers, subscriber);
958
+ });
959
+ };
960
+ Subject.prototype._checkFinalizedStatuses = function (subscriber) {
961
+ var _a = this,
962
+ hasError = _a.hasError,
963
+ thrownError = _a.thrownError,
964
+ isStopped = _a.isStopped;
965
+ if (hasError) {
966
+ subscriber.error(thrownError);
967
+ } else if (isStopped) {
968
+ subscriber.complete();
969
+ }
970
+ };
971
+ Subject.prototype.asObservable = function () {
972
+ var observable = new Observable();
973
+ observable.source = this;
974
+ return observable;
975
+ };
976
+ Subject.create = function (destination, source) {
977
+ return new AnonymousSubject(destination, source);
978
+ };
979
+ return Subject;
980
+ }(Observable);
981
+ var AnonymousSubject = function (_super) {
982
+ __extends(AnonymousSubject, _super);
983
+ function AnonymousSubject(destination, source) {
984
+ var _this = _super.call(this) || this;
985
+ _this.destination = destination;
986
+ _this.source = source;
987
+ return _this;
988
+ }
989
+ AnonymousSubject.prototype.next = function (value) {
990
+ var _a, _b;
991
+ (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.next) === null || _b === undefined ? undefined : _b.call(_a, value);
992
+ };
993
+ AnonymousSubject.prototype.error = function (err) {
994
+ var _a, _b;
995
+ (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.error) === null || _b === undefined ? undefined : _b.call(_a, err);
996
+ };
997
+ AnonymousSubject.prototype.complete = function () {
998
+ var _a, _b;
999
+ (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.complete) === null || _b === undefined ? undefined : _b.call(_a);
1000
+ };
1001
+ AnonymousSubject.prototype._subscribe = function (subscriber) {
1002
+ var _a, _b;
1003
+ return (_b = (_a = this.source) === null || _a === undefined ? undefined : _a.subscribe(subscriber)) !== null && _b !== undefined ? _b : EMPTY_SUBSCRIPTION;
1150
1004
  };
1151
- return Observable;
1152
- }();
1153
- function getPromiseCtor(promiseCtor) {
1154
- var _a;
1155
- return (_a = promiseCtor !== null && promiseCtor !== undefined ? promiseCtor : config.Promise) !== null && _a !== undefined ? _a : Promise;
1156
- }
1157
- function isObserver(value) {
1158
- return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
1005
+ return AnonymousSubject;
1006
+ }(Subject);
1007
+
1008
+ var EmptyError = createErrorClass(function (_super) {
1009
+ return function EmptyErrorImpl() {
1010
+ _super(this);
1011
+ this.name = 'EmptyError';
1012
+ this.message = 'no elements in sequence';
1013
+ };
1014
+ });
1015
+
1016
+ function firstValueFrom(source, config) {
1017
+ return new Promise(function (resolve, reject) {
1018
+ var subscriber = new SafeSubscriber({
1019
+ next: function (value) {
1020
+ resolve(value);
1021
+ subscriber.unsubscribe();
1022
+ },
1023
+ error: reject,
1024
+ complete: function () {
1025
+ {
1026
+ reject(new EmptyError());
1027
+ }
1028
+ }
1029
+ });
1030
+ source.subscribe(subscriber);
1031
+ });
1159
1032
  }
1160
- function isSubscriber(value) {
1161
- return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
1033
+
1034
+ function filter(predicate, thisArg) {
1035
+ return operate(function (source, subscriber) {
1036
+ var index = 0;
1037
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) {
1038
+ return predicate.call(thisArg, value, index++) && subscriber.next(value);
1039
+ }));
1040
+ });
1162
1041
  }
1163
1042
 
1164
- function hasLift(source) {
1165
- return isFunction(source === null || source === undefined ? undefined : source.lift);
1043
+ function getDefaultExportFromCjs (x) {
1044
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1166
1045
  }
1167
- function operate(init) {
1168
- return function (source) {
1169
- if (hasLift(source)) {
1170
- return source.lift(function (liftedSource) {
1171
- try {
1172
- return init(liftedSource, this);
1173
- } catch (err) {
1174
- this.error(err);
1046
+
1047
+ var loglevel$1 = {exports: {}};
1048
+
1049
+ /*
1050
+ * loglevel - https://github.com/pimterry/loglevel
1051
+ *
1052
+ * Copyright (c) 2013 Tim Perry
1053
+ * Licensed under the MIT license.
1054
+ */
1055
+ var loglevel = loglevel$1.exports;
1056
+ var hasRequiredLoglevel;
1057
+ function requireLoglevel() {
1058
+ if (hasRequiredLoglevel) return loglevel$1.exports;
1059
+ hasRequiredLoglevel = 1;
1060
+ (function (module) {
1061
+ (function (root, definition) {
1062
+
1063
+ if (module.exports) {
1064
+ module.exports = definition();
1065
+ } else {
1066
+ root.log = definition();
1067
+ }
1068
+ })(loglevel, function () {
1069
+
1070
+ // Slightly dubious tricks to cut down minimized file size
1071
+ var noop = function () {};
1072
+ var undefinedType = "undefined";
1073
+ var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
1074
+ var logMethods = ["trace", "debug", "info", "warn", "error"];
1075
+ var _loggersByName = {};
1076
+ var defaultLogger = null;
1077
+
1078
+ // Cross-browser bind equivalent that works at least back to IE6
1079
+ function bindMethod(obj, methodName) {
1080
+ var method = obj[methodName];
1081
+ if (typeof method.bind === 'function') {
1082
+ return method.bind(obj);
1083
+ } else {
1084
+ try {
1085
+ return Function.prototype.bind.call(method, obj);
1086
+ } catch (e) {
1087
+ // Missing bind shim or IE8 + Modernizr, fallback to wrapping
1088
+ return function () {
1089
+ return Function.prototype.apply.apply(method, [obj, arguments]);
1090
+ };
1091
+ }
1175
1092
  }
1176
- });
1177
- }
1178
- throw new TypeError('Unable to lift unknown Observable type');
1179
- };
1180
- }
1093
+ }
1181
1094
 
1182
- function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
1183
- return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
1184
- }
1185
- var OperatorSubscriber = function (_super) {
1186
- __extends(OperatorSubscriber, _super);
1187
- function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
1188
- var _this = _super.call(this, destination) || this;
1189
- _this.onFinalize = onFinalize;
1190
- _this.shouldUnsubscribe = shouldUnsubscribe;
1191
- _this._next = onNext ? function (value) {
1192
- try {
1193
- onNext(value);
1194
- } catch (err) {
1195
- destination.error(err);
1095
+ // Trace() doesn't print the message in IE, so for that case we need to wrap it
1096
+ function traceForIE() {
1097
+ if (console.log) {
1098
+ if (console.log.apply) {
1099
+ console.log.apply(console, arguments);
1100
+ } else {
1101
+ // In old IE, native console methods themselves don't have apply().
1102
+ Function.prototype.apply.apply(console.log, [console, arguments]);
1103
+ }
1104
+ }
1105
+ if (console.trace) console.trace();
1196
1106
  }
1197
- } : _super.prototype._next;
1198
- _this._error = onError ? function (err) {
1199
- try {
1200
- onError(err);
1201
- } catch (err) {
1202
- destination.error(err);
1203
- } finally {
1204
- this.unsubscribe();
1107
+
1108
+ // Build the best logging method possible for this env
1109
+ // Wherever possible we want to bind, not wrap, to preserve stack traces
1110
+ function realMethod(methodName) {
1111
+ if (methodName === 'debug') {
1112
+ methodName = 'log';
1113
+ }
1114
+ if (typeof console === undefinedType) {
1115
+ return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
1116
+ } else if (methodName === 'trace' && isIE) {
1117
+ return traceForIE;
1118
+ } else if (console[methodName] !== undefined) {
1119
+ return bindMethod(console, methodName);
1120
+ } else if (console.log !== undefined) {
1121
+ return bindMethod(console, 'log');
1122
+ } else {
1123
+ return noop;
1124
+ }
1205
1125
  }
1206
- } : _super.prototype._error;
1207
- _this._complete = onComplete ? function () {
1208
- try {
1209
- onComplete();
1210
- } catch (err) {
1211
- destination.error(err);
1212
- } finally {
1213
- this.unsubscribe();
1126
+
1127
+ // These private functions always need `this` to be set properly
1128
+
1129
+ function replaceLoggingMethods() {
1130
+ /*jshint validthis:true */
1131
+ var level = this.getLevel();
1132
+
1133
+ // Replace the actual methods.
1134
+ for (var i = 0; i < logMethods.length; i++) {
1135
+ var methodName = logMethods[i];
1136
+ this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
1137
+ }
1138
+
1139
+ // Define log.log as an alias for log.debug
1140
+ this.log = this.debug;
1141
+
1142
+ // Return any important warnings.
1143
+ if (typeof console === undefinedType && level < this.levels.SILENT) {
1144
+ return "No console available for logging";
1145
+ }
1214
1146
  }
1215
- } : _super.prototype._complete;
1216
- return _this;
1217
- }
1218
- OperatorSubscriber.prototype.unsubscribe = function () {
1219
- var _a;
1220
- if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
1221
- var closed_1 = this.closed;
1222
- _super.prototype.unsubscribe.call(this);
1223
- !closed_1 && ((_a = this.onFinalize) === null || _a === undefined ? undefined : _a.call(this));
1224
- }
1225
- };
1226
- return OperatorSubscriber;
1227
- }(Subscriber);
1228
1147
 
1229
- var ObjectUnsubscribedError = createErrorClass(function (_super) {
1230
- return function ObjectUnsubscribedErrorImpl() {
1231
- _super(this);
1232
- this.name = 'ObjectUnsubscribedError';
1233
- this.message = 'object unsubscribed';
1234
- };
1235
- });
1148
+ // In old IE versions, the console isn't present until you first open it.
1149
+ // We build realMethod() replacements here that regenerate logging methods
1150
+ function enableLoggingWhenConsoleArrives(methodName) {
1151
+ return function () {
1152
+ if (typeof console !== undefinedType) {
1153
+ replaceLoggingMethods.call(this);
1154
+ this[methodName].apply(this, arguments);
1155
+ }
1156
+ };
1157
+ }
1158
+
1159
+ // By default, we use closely bound real methods wherever possible, and
1160
+ // otherwise we wait for a console to appear, and then try again.
1161
+ function defaultMethodFactory(methodName, _level, _loggerName) {
1162
+ /*jshint validthis:true */
1163
+ return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
1164
+ }
1165
+ function Logger(name, factory) {
1166
+ // Private instance variables.
1167
+ var self = this;
1168
+ /**
1169
+ * The level inherited from a parent logger (or a global default). We
1170
+ * cache this here rather than delegating to the parent so that it stays
1171
+ * in sync with the actual logging methods that we have installed (the
1172
+ * parent could change levels but we might not have rebuilt the loggers
1173
+ * in this child yet).
1174
+ * @type {number}
1175
+ */
1176
+ var inheritedLevel;
1177
+ /**
1178
+ * The default level for this logger, if any. If set, this overrides
1179
+ * `inheritedLevel`.
1180
+ * @type {number|null}
1181
+ */
1182
+ var defaultLevel;
1183
+ /**
1184
+ * A user-specific level for this logger. If set, this overrides
1185
+ * `defaultLevel`.
1186
+ * @type {number|null}
1187
+ */
1188
+ var userLevel;
1189
+ var storageKey = "loglevel";
1190
+ if (typeof name === "string") {
1191
+ storageKey += ":" + name;
1192
+ } else if (typeof name === "symbol") {
1193
+ storageKey = undefined;
1194
+ }
1195
+ function persistLevelIfPossible(levelNum) {
1196
+ var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
1197
+ if (typeof window === undefinedType || !storageKey) return;
1198
+
1199
+ // Use localStorage if available
1200
+ try {
1201
+ window.localStorage[storageKey] = levelName;
1202
+ return;
1203
+ } catch (ignore) {}
1236
1204
 
1237
- var Subject = function (_super) {
1238
- __extends(Subject, _super);
1239
- function Subject() {
1240
- var _this = _super.call(this) || this;
1241
- _this.closed = false;
1242
- _this.currentObservers = null;
1243
- _this.observers = [];
1244
- _this.isStopped = false;
1245
- _this.hasError = false;
1246
- _this.thrownError = null;
1247
- return _this;
1248
- }
1249
- Subject.prototype.lift = function (operator) {
1250
- var subject = new AnonymousSubject(this, this);
1251
- subject.operator = operator;
1252
- return subject;
1253
- };
1254
- Subject.prototype._throwIfClosed = function () {
1255
- if (this.closed) {
1256
- throw new ObjectUnsubscribedError();
1257
- }
1258
- };
1259
- Subject.prototype.next = function (value) {
1260
- var _this = this;
1261
- errorContext(function () {
1262
- var e_1, _a;
1263
- _this._throwIfClosed();
1264
- if (!_this.isStopped) {
1265
- if (!_this.currentObservers) {
1266
- _this.currentObservers = Array.from(_this.observers);
1205
+ // Use session cookie as fallback
1206
+ try {
1207
+ window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
1208
+ } catch (ignore) {}
1267
1209
  }
1268
- try {
1269
- for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
1270
- var observer = _c.value;
1271
- observer.next(value);
1272
- }
1273
- } catch (e_1_1) {
1274
- e_1 = {
1275
- error: e_1_1
1276
- };
1277
- } finally {
1210
+ function getPersistedLevel() {
1211
+ var storedLevel;
1212
+ if (typeof window === undefinedType || !storageKey) return;
1278
1213
  try {
1279
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1280
- } finally {
1281
- if (e_1) throw e_1.error;
1214
+ storedLevel = window.localStorage[storageKey];
1215
+ } catch (ignore) {}
1216
+
1217
+ // Fallback to cookies if local storage gives us nothing
1218
+ if (typeof storedLevel === undefinedType) {
1219
+ try {
1220
+ var cookie = window.document.cookie;
1221
+ var cookieName = encodeURIComponent(storageKey);
1222
+ var location = cookie.indexOf(cookieName + "=");
1223
+ if (location !== -1) {
1224
+ storedLevel = /^([^;]+)/.exec(cookie.slice(location + cookieName.length + 1))[1];
1225
+ }
1226
+ } catch (ignore) {}
1227
+ }
1228
+
1229
+ // If the stored level is not valid, treat it as if nothing was stored.
1230
+ if (self.levels[storedLevel] === undefined) {
1231
+ storedLevel = undefined;
1282
1232
  }
1233
+ return storedLevel;
1283
1234
  }
1284
- }
1285
- });
1286
- };
1287
- Subject.prototype.error = function (err) {
1288
- var _this = this;
1289
- errorContext(function () {
1290
- _this._throwIfClosed();
1291
- if (!_this.isStopped) {
1292
- _this.hasError = _this.isStopped = true;
1293
- _this.thrownError = err;
1294
- var observers = _this.observers;
1295
- while (observers.length) {
1296
- observers.shift().error(err);
1235
+ function clearPersistedLevel() {
1236
+ if (typeof window === undefinedType || !storageKey) return;
1237
+
1238
+ // Use localStorage if available
1239
+ try {
1240
+ window.localStorage.removeItem(storageKey);
1241
+ } catch (ignore) {}
1242
+
1243
+ // Use session cookie as fallback
1244
+ try {
1245
+ window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
1246
+ } catch (ignore) {}
1297
1247
  }
1298
- }
1299
- });
1300
- };
1301
- Subject.prototype.complete = function () {
1302
- var _this = this;
1303
- errorContext(function () {
1304
- _this._throwIfClosed();
1305
- if (!_this.isStopped) {
1306
- _this.isStopped = true;
1307
- var observers = _this.observers;
1308
- while (observers.length) {
1309
- observers.shift().complete();
1248
+ function normalizeLevel(input) {
1249
+ var level = input;
1250
+ if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
1251
+ level = self.levels[level.toUpperCase()];
1252
+ }
1253
+ if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
1254
+ return level;
1255
+ } else {
1256
+ throw new TypeError("log.setLevel() called with invalid level: " + input);
1257
+ }
1310
1258
  }
1311
- }
1312
- });
1313
- };
1314
- Subject.prototype.unsubscribe = function () {
1315
- this.isStopped = this.closed = true;
1316
- this.observers = this.currentObservers = null;
1317
- };
1318
- Object.defineProperty(Subject.prototype, "observed", {
1319
- get: function () {
1320
- var _a;
1321
- return ((_a = this.observers) === null || _a === undefined ? undefined : _a.length) > 0;
1322
- },
1323
- enumerable: false,
1324
- configurable: true
1325
- });
1326
- Subject.prototype._trySubscribe = function (subscriber) {
1327
- this._throwIfClosed();
1328
- return _super.prototype._trySubscribe.call(this, subscriber);
1329
- };
1330
- Subject.prototype._subscribe = function (subscriber) {
1331
- this._throwIfClosed();
1332
- this._checkFinalizedStatuses(subscriber);
1333
- return this._innerSubscribe(subscriber);
1334
- };
1335
- Subject.prototype._innerSubscribe = function (subscriber) {
1336
- var _this = this;
1337
- var _a = this,
1338
- hasError = _a.hasError,
1339
- isStopped = _a.isStopped,
1340
- observers = _a.observers;
1341
- if (hasError || isStopped) {
1342
- return EMPTY_SUBSCRIPTION;
1343
- }
1344
- this.currentObservers = null;
1345
- observers.push(subscriber);
1346
- return new Subscription(function () {
1347
- _this.currentObservers = null;
1348
- arrRemove(observers, subscriber);
1349
- });
1350
- };
1351
- Subject.prototype._checkFinalizedStatuses = function (subscriber) {
1352
- var _a = this,
1353
- hasError = _a.hasError,
1354
- thrownError = _a.thrownError,
1355
- isStopped = _a.isStopped;
1356
- if (hasError) {
1357
- subscriber.error(thrownError);
1358
- } else if (isStopped) {
1359
- subscriber.complete();
1360
- }
1361
- };
1362
- Subject.prototype.asObservable = function () {
1363
- var observable = new Observable();
1364
- observable.source = this;
1365
- return observable;
1366
- };
1367
- Subject.create = function (destination, source) {
1368
- return new AnonymousSubject(destination, source);
1369
- };
1370
- return Subject;
1371
- }(Observable);
1372
- var AnonymousSubject = function (_super) {
1373
- __extends(AnonymousSubject, _super);
1374
- function AnonymousSubject(destination, source) {
1375
- var _this = _super.call(this) || this;
1376
- _this.destination = destination;
1377
- _this.source = source;
1378
- return _this;
1379
- }
1380
- AnonymousSubject.prototype.next = function (value) {
1381
- var _a, _b;
1382
- (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.next) === null || _b === undefined ? undefined : _b.call(_a, value);
1383
- };
1384
- AnonymousSubject.prototype.error = function (err) {
1385
- var _a, _b;
1386
- (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.error) === null || _b === undefined ? undefined : _b.call(_a, err);
1387
- };
1388
- AnonymousSubject.prototype.complete = function () {
1389
- var _a, _b;
1390
- (_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.complete) === null || _b === undefined ? undefined : _b.call(_a);
1391
- };
1392
- AnonymousSubject.prototype._subscribe = function (subscriber) {
1393
- var _a, _b;
1394
- return (_b = (_a = this.source) === null || _a === undefined ? undefined : _a.subscribe(subscriber)) !== null && _b !== undefined ? _b : EMPTY_SUBSCRIPTION;
1395
- };
1396
- return AnonymousSubject;
1397
- }(Subject);
1398
1259
 
1399
- var EmptyError = createErrorClass(function (_super) {
1400
- return function EmptyErrorImpl() {
1401
- _super(this);
1402
- this.name = 'EmptyError';
1403
- this.message = 'no elements in sequence';
1404
- };
1405
- });
1260
+ /*
1261
+ *
1262
+ * Public logger API - see https://github.com/pimterry/loglevel for details
1263
+ *
1264
+ */
1265
+
1266
+ self.name = name;
1267
+ self.levels = {
1268
+ "TRACE": 0,
1269
+ "DEBUG": 1,
1270
+ "INFO": 2,
1271
+ "WARN": 3,
1272
+ "ERROR": 4,
1273
+ "SILENT": 5
1274
+ };
1275
+ self.methodFactory = factory || defaultMethodFactory;
1276
+ self.getLevel = function () {
1277
+ if (userLevel != null) {
1278
+ return userLevel;
1279
+ } else if (defaultLevel != null) {
1280
+ return defaultLevel;
1281
+ } else {
1282
+ return inheritedLevel;
1283
+ }
1284
+ };
1285
+ self.setLevel = function (level, persist) {
1286
+ userLevel = normalizeLevel(level);
1287
+ if (persist !== false) {
1288
+ // defaults to true
1289
+ persistLevelIfPossible(userLevel);
1290
+ }
1406
1291
 
1407
- function firstValueFrom(source, config) {
1408
- return new Promise(function (resolve, reject) {
1409
- var subscriber = new SafeSubscriber({
1410
- next: function (value) {
1411
- resolve(value);
1412
- subscriber.unsubscribe();
1413
- },
1414
- error: reject,
1415
- complete: function () {
1416
- {
1417
- reject(new EmptyError());
1292
+ // NOTE: in v2, this should call rebuild(), which updates children.
1293
+ return replaceLoggingMethods.call(self);
1294
+ };
1295
+ self.setDefaultLevel = function (level) {
1296
+ defaultLevel = normalizeLevel(level);
1297
+ if (!getPersistedLevel()) {
1298
+ self.setLevel(level, false);
1299
+ }
1300
+ };
1301
+ self.resetLevel = function () {
1302
+ userLevel = null;
1303
+ clearPersistedLevel();
1304
+ replaceLoggingMethods.call(self);
1305
+ };
1306
+ self.enableAll = function (persist) {
1307
+ self.setLevel(self.levels.TRACE, persist);
1308
+ };
1309
+ self.disableAll = function (persist) {
1310
+ self.setLevel(self.levels.SILENT, persist);
1311
+ };
1312
+ self.rebuild = function () {
1313
+ if (defaultLogger !== self) {
1314
+ inheritedLevel = normalizeLevel(defaultLogger.getLevel());
1315
+ }
1316
+ replaceLoggingMethods.call(self);
1317
+ if (defaultLogger === self) {
1318
+ for (var childName in _loggersByName) {
1319
+ _loggersByName[childName].rebuild();
1320
+ }
1321
+ }
1322
+ };
1323
+
1324
+ // Initialize all the internal levels.
1325
+ inheritedLevel = normalizeLevel(defaultLogger ? defaultLogger.getLevel() : "WARN");
1326
+ var initialLevel = getPersistedLevel();
1327
+ if (initialLevel != null) {
1328
+ userLevel = normalizeLevel(initialLevel);
1418
1329
  }
1330
+ replaceLoggingMethods.call(self);
1419
1331
  }
1420
- });
1421
- source.subscribe(subscriber);
1422
- });
1423
- }
1424
-
1425
- function map(project, thisArg) {
1426
- return operate(function (source, subscriber) {
1427
- var index = 0;
1428
- source.subscribe(createOperatorSubscriber(subscriber, function (value) {
1429
- subscriber.next(project.call(thisArg, value, index++));
1430
- }));
1431
- });
1432
- }
1433
-
1434
- function filter(predicate, thisArg) {
1435
- return operate(function (source, subscriber) {
1436
- var index = 0;
1437
- source.subscribe(createOperatorSubscriber(subscriber, function (value) {
1438
- return predicate.call(thisArg, value, index++) && subscriber.next(value);
1439
- }));
1440
- });
1441
- }
1442
-
1443
- // refer to realm-network-api/src/common/enums/error-codes.enum.ts
1444
- /*** Authentication Errors ***/
1445
- var AuthErrorName;
1446
- (function (AuthErrorName) {
1447
- AuthErrorName["UNAUTHORIZED"] = "UNAUTHORIZED";
1448
- AuthErrorName["INVALID_TOKEN"] = "INVALID_TOKEN";
1449
- AuthErrorName["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
1450
- AuthErrorName["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
1451
- })(AuthErrorName || (AuthErrorName = {}));
1452
- /*** Partner Access Token Errors ***/
1453
- var PartnerAccessTokenErrorName;
1454
- (function (PartnerAccessTokenErrorName) {
1455
- PartnerAccessTokenErrorName["PARTNER_ACCESS_TOKEN_INVALID"] = "PARTNER_ACCESS_TOKEN_INVALID";
1456
- PartnerAccessTokenErrorName["USER_MISMATCH"] = "USER_MISMATCH";
1457
- })(PartnerAccessTokenErrorName || (PartnerAccessTokenErrorName = {}));
1458
- /*** Realm ID Errors ***/
1459
- var RealmIDErrorName;
1460
- (function (RealmIDErrorName) {
1461
- RealmIDErrorName["REALM_ID_NOT_FOUND"] = "REALM_ID_NOT_FOUND";
1462
- RealmIDErrorName["REALM_ID_INVALID_NAME"] = "REALM_ID_INVALID_NAME";
1463
- RealmIDErrorName["REALM_ID_ALREADY_EXISTS"] = "REALM_ID_ALREADY_EXISTS";
1464
- RealmIDErrorName["REALM_ID_DUPLICATE_PARTNER_USER"] = "REALM_ID_DUPLICATE_PARTNER_USER";
1465
- })(RealmIDErrorName || (RealmIDErrorName = {}));
1466
- /*** Parameter Errors ***/
1467
- var ParameterErrorName;
1468
- (function (ParameterErrorName) {
1469
- ParameterErrorName["INVALID_PARAMETER"] = "INVALID_PARAMETER";
1470
- })(ParameterErrorName || (ParameterErrorName = {}));
1471
- /*** Server Errors ***/
1472
- var ServerErrorName;
1473
- (function (ServerErrorName) {
1474
- ServerErrorName["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
1475
- })(ServerErrorName || (ServerErrorName = {}));
1476
- /*** Passkey Errors ***/
1477
- var PasskeyErrorName;
1478
- (function (PasskeyErrorName) {
1479
- PasskeyErrorName["PASSKEY_REGISTRATION_FAILED"] = "PASSKEY_REGISTRATION_FAILED";
1480
- PasskeyErrorName["PASSKEY_AUTHENTICATION_FAILED"] = "PASSKEY_AUTHENTICATION_FAILED";
1481
- PasskeyErrorName["PASSKEY_LIMIT_EXCEEDED"] = "PASSKEY_LIMIT_EXCEEDED";
1482
- PasskeyErrorName["PASSKEY_NOT_FOUND"] = "PASSKEY_NOT_FOUND";
1483
- PasskeyErrorName["PASSKEY_UNAUTHORIZED"] = "PASSKEY_UNAUTHORIZED";
1484
- PasskeyErrorName["PASSKEY_CHALLENGE_INVALID"] = "PASSKEY_CHALLENGE_INVALID";
1485
- })(PasskeyErrorName || (PasskeyErrorName = {}));
1486
- /*** Passwordless Authentication Errors ***/
1487
- var PasswordlessErrorName;
1488
- (function (PasswordlessErrorName) {
1489
- PasswordlessErrorName["PASSWORDLESS_CODE_EXPIRED"] = "PASSWORDLESS_CODE_EXPIRED";
1490
- PasswordlessErrorName["PASSWORDLESS_INVALID_CODE"] = "PASSWORDLESS_INVALID_CODE";
1491
- PasswordlessErrorName["PASSWORDLESS_MAX_ATTEMPTS"] = "PASSWORDLESS_MAX_ATTEMPTS";
1492
- PasswordlessErrorName["PASSWORDLESS_HOURLY_LIMIT"] = "PASSWORDLESS_HOURLY_LIMIT";
1493
- PasswordlessErrorName["PASSWORDLESS_LOCK_EXCEEDED"] = "PASSWORDLESS_LOCK_EXCEEDED";
1494
- PasswordlessErrorName["CAPTCHA_TOKEN_VERIFICATION_FAILED"] = "CAPTCHA_TOKEN_VERIFICATION_FAILED";
1495
- PasswordlessErrorName["CAPTCHA_TOKEN_INVALID"] = "CAPTCHA_TOKEN_INVALID";
1496
- PasswordlessErrorName["CAPTCHA_SECRET_MISSING"] = "CAPTCHA_SECRET_MISSING";
1497
- PasswordlessErrorName["CAPTCHA_TOKEN_MISSING"] = "CAPTCHA_TOKEN_MISSING";
1498
- })(PasswordlessErrorName || (PasswordlessErrorName = {}));
1499
- /*** Authentication Wallet Errors ***/
1500
- var AuthWalletErrorName;
1501
- (function (AuthWalletErrorName) {
1502
- AuthWalletErrorName["AUTH_WALLET_LOCK_EXCEEDED"] = "AUTH_WALLET_LOCK_EXCEEDED";
1503
- AuthWalletErrorName["AUTH_WALLET_NONCE_EXPIRED_OR_INVALID"] = "AUTH_WALLET_NONCE_EXPIRED_OR_INVALID";
1504
- AuthWalletErrorName["AUTH_WALLET_ADDRESS_MISMATCH"] = "AUTH_WALLET_ADDRESS_MISMATCH";
1505
- AuthWalletErrorName["AUTH_WALLET_SIGNATURE_VERIFICATION_FAILED"] = "AUTH_WALLET_SIGNATURE_VERIFICATION_FAILED";
1506
- })(AuthWalletErrorName || (AuthWalletErrorName = {}));
1507
- /*** Wallet Linking Errors ***/
1508
- var WalletLinkErrorName;
1509
- (function (WalletLinkErrorName) {
1510
- WalletLinkErrorName["LINK_WALLET_ALREADY_LINKED"] = "LINK_WALLET_ALREADY_LINKED";
1511
- WalletLinkErrorName["LINK_WALLET_LINKED_OTHER_ACCOUNT"] = "LINK_WALLET_LINKED_OTHER_ACCOUNT";
1512
- WalletLinkErrorName["LINK_EMAIL_LINKED_OTHER_ACCOUNT"] = "LINK_EMAIL_LINKED_OTHER_ACCOUNT";
1513
- })(WalletLinkErrorName || (WalletLinkErrorName = {}));
1514
- /*** Intent Errors ***/
1515
- var IntentErrorName;
1516
- (function (IntentErrorName) {
1517
- IntentErrorName["INTENT_INVALID"] = "INTENT_INVALID";
1518
- IntentErrorName["INTENT_LOCK_EXCEEDED"] = "INTENT_LOCK_EXCEEDED";
1519
- IntentErrorName["INTENT_REQUIRED"] = "INTENT_REQUIRED";
1520
- IntentErrorName["INTENT_UNSUPPORTED_TYPE"] = "INTENT_UNSUPPORTED_TYPE";
1521
- })(IntentErrorName || (IntentErrorName = {}));
1522
- /*** Privy Errors ***/
1523
- var PrivyErrorName;
1524
- (function (PrivyErrorName) {
1525
- PrivyErrorName["WALLET_PROVIDER_ERROR"] = "WALLET_PROVIDER_ERROR";
1526
- })(PrivyErrorName || (PrivyErrorName = {}));
1527
- /*** Air ID Errors ***/
1528
- var AirIDErrorName;
1529
- (function (AirIDErrorName) {
1530
- AirIDErrorName["AIR_ID_MINT_TRANSACTION_NOT_FOUND"] = "AIR_ID_MINT_TRANSACTION_NOT_FOUND";
1531
- AirIDErrorName["AIR_ID_ON_CHAIN_TRANSACTION_NOT_FOUND"] = "AIR_ID_ON_CHAIN_TRANSACTION_NOT_FOUND";
1532
- AirIDErrorName["AIR_ID_NOT_FOUND"] = "AIR_ID_NOT_FOUND";
1533
- AirIDErrorName["AIR_ID_INVALID_OR_DISABLED_CONFIGURATION"] = "AIR_ID_INVALID_OR_DISABLED_CONFIGURATION";
1534
- AirIDErrorName["AIR_ID_RPC_URL_NOT_CONFIGURED"] = "AIR_ID_RPC_URL_NOT_CONFIGURED";
1535
- AirIDErrorName["AIR_ID_INVALID_STATUS"] = "AIR_ID_INVALID_STATUS";
1536
- AirIDErrorName["AIR_ID_PARTNER_ELIGIBILITY_CHECK_FAILED"] = "AIR_ID_PARTNER_ELIGIBILITY_CHECK_FAILED";
1537
- AirIDErrorName["AIR_ID_PARTNER_ELIGIBILITY_CHECK_TIMEOUT"] = "AIR_ID_PARTNER_ELIGIBILITY_CHECK_TIMEOUT";
1538
- AirIDErrorName["AIR_ID_MULTIPLE_AIR_IDS_FOUND"] = "AIR_ID_MULTIPLE_AIR_IDS_FOUND";
1539
- AirIDErrorName["AIR_ID_NAME_RESERVED"] = "AIR_ID_NAME_RESERVED";
1540
- AirIDErrorName["AIR_ID_NAME_PROFANITY"] = "AIR_ID_NAME_PROFANITY";
1541
- AirIDErrorName["AIR_ID_USER_ALREADY_HAS_AIR_ID"] = "AIR_ID_USER_ALREADY_HAS_AIR_ID";
1542
- AirIDErrorName["AIR_ID_NAME_ALREADY_EXISTS"] = "AIR_ID_NAME_ALREADY_EXISTS";
1543
- AirIDErrorName["AIR_ID_INVALID_MINT_NAME"] = "AIR_ID_INVALID_MINT_NAME";
1544
- AirIDErrorName["AIR_ID_MINT_TRANSACTION_HASH_MISMATCH"] = "AIR_ID_MINT_TRANSACTION_HASH_MISMATCH";
1545
- })(AirIDErrorName || (AirIDErrorName = {}));
1546
- /*** Window Errors ***/
1547
- var WindowErrorName;
1548
- (function (WindowErrorName) {
1549
- WindowErrorName["WINDOW_BLOCKED"] = "WINDOW_BLOCKED";
1550
- WindowErrorName["WINDOW_CLOSED"] = "WINDOW_CLOSED";
1551
- })(WindowErrorName || (WindowErrorName = {}));
1552
- const Codes = {
1553
- ...AuthErrorName,
1554
- ...PartnerAccessTokenErrorName,
1555
- ...RealmIDErrorName,
1556
- ...ParameterErrorName,
1557
- ...ServerErrorName,
1558
- ...PasskeyErrorName,
1559
- ...PasswordlessErrorName,
1560
- ...AuthWalletErrorName,
1561
- ...WalletLinkErrorName,
1562
- ...IntentErrorName,
1563
- ...PrivyErrorName,
1564
- ...AirIDErrorName,
1565
- ...WindowErrorName
1566
- };
1567
1332
 
1568
- const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED"];
1333
+ /*
1334
+ *
1335
+ * Top-level API
1336
+ *
1337
+ */
1569
1338
 
1570
- class AirError extends BaseError {}
1571
- new Set(AirClientUserErrors);
1572
- new Set(Object.values(Codes));
1339
+ defaultLogger = new Logger();
1340
+ defaultLogger.getLogger = function getLogger(name) {
1341
+ if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
1342
+ throw new TypeError("You must supply a name when creating a logger.");
1343
+ }
1344
+ var logger = _loggersByName[name];
1345
+ if (!logger) {
1346
+ logger = _loggersByName[name] = new Logger(name, defaultLogger.methodFactory);
1347
+ }
1348
+ return logger;
1349
+ };
1573
1350
 
1574
- class MessageServiceBase {
1575
- get events$() {
1576
- return this._events$;
1577
- }
1578
- get messages$() {
1579
- return this._messages$;
1580
- }
1581
- get isOpen() {
1582
- return !!this.closeListener;
1583
- }
1584
- constructor(name, allowedMessageTypes) {
1585
- this.name = name;
1586
- this.allowedMessageTypes = allowedMessageTypes;
1587
- this.closeListener = null;
1588
- }
1589
- async _open(target) {
1590
- await this.close();
1591
- this.eventSubject = new Subject();
1592
- this._events$ = this.eventSubject.asObservable();
1593
- this._messages$ = this.eventSubject.pipe(map(ev => ev.data));
1594
- this._events$.subscribe(event => {
1595
- const sentOrReceived = event.origin === window.origin ? "sent" : "received";
1596
- log.debug(`[${this.name}] Message ${sentOrReceived}:`, event.data);
1597
- });
1598
- const handleMessage = async ev => {
1599
- if (this.targetOrigin && ev.origin !== this.targetOrigin || !ev.data || !(ev.data instanceof Object)) return;
1600
- if (this.isMessageAllowed(ev.data)) {
1601
- await this.onBeforeEvent(ev);
1602
- this.eventSubject.next(ev);
1603
- }
1604
- };
1605
- if (target instanceof MessagePort) {
1606
- this.messagePort = target;
1607
- target.onmessage = handleMessage;
1608
- this.closeListener = async () => {
1609
- target.close();
1351
+ // Grab the current global log variable in case of overwrite
1352
+ var _log = typeof window !== undefinedType ? window.log : undefined;
1353
+ defaultLogger.noConflict = function () {
1354
+ if (typeof window !== undefinedType && window.log === defaultLogger) {
1355
+ window.log = _log;
1356
+ }
1357
+ return defaultLogger;
1610
1358
  };
1611
- } else {
1612
- this.targetWindow = target.window;
1613
- this.targetOrigin = target.origin;
1614
- window.addEventListener("message", handleMessage);
1615
- this.closeListener = async () => {
1616
- window.removeEventListener("message", handleMessage);
1359
+ defaultLogger.getLoggers = function getLoggers() {
1360
+ return _loggersByName;
1617
1361
  };
1618
- }
1619
- }
1620
- isMessageAllowed(message) {
1621
- return this.allowedMessageTypes.includes(message.type);
1622
- }
1623
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1624
- async onBeforeEvent(_event) {
1625
- // by default not used
1626
- }
1627
- async close() {
1628
- if (this.closeListener) {
1629
- await this.closeListener();
1630
- this.closeListener = null;
1631
- }
1632
- if (this.eventSubject && !this.eventSubject.closed) {
1633
- this.eventSubject.complete();
1634
- }
1635
- }
1636
- createErrorResponseMessage(type, error) {
1637
- return {
1638
- type,
1639
- payload: {
1640
- success: false,
1641
- errorName: error instanceof AirError ? error.name : "UNKNOWN_ERROR",
1642
- errorMessage: error.message
1643
- }
1644
- };
1645
- }
1646
- async sendMessage(message, transfer) {
1647
- // To prevent any non-cloneable objects causing errors in postMessage
1648
- const clonedMessage = this.deepClone(message);
1649
- if (this.messagePort) {
1650
- this.messagePort.postMessage(clonedMessage);
1651
- this.eventSubject.next(new MessageEvent("message", {
1652
- data: clonedMessage,
1653
- origin: window.origin
1654
- }));
1655
- } else if (this.targetWindow && this.targetOrigin) {
1656
- this.targetWindow.postMessage(clonedMessage, this.targetOrigin, transfer);
1657
- this.eventSubject.next(new MessageEvent("message", {
1658
- data: clonedMessage,
1659
- origin: window.origin
1660
- }));
1661
- } else {
1662
- log.debug(`[${this.name}] Not opened yet`);
1663
- }
1664
- }
1665
- deepClone(message) {
1666
- try {
1667
- return JSON.parse(JSON.stringify(message));
1668
- } catch (e) {
1669
- log.warn("Error generating cloneable message", e);
1670
- return message;
1671
- }
1672
- }
1362
+
1363
+ // ES6 default export, for compatibility
1364
+ defaultLogger['default'] = defaultLogger;
1365
+ return defaultLogger;
1366
+ });
1367
+ })(loglevel$1);
1368
+ return loglevel$1.exports;
1673
1369
  }
1674
1370
 
1371
+ var loglevelExports = requireLoglevel();
1372
+ var log$1 = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
1373
+
1374
+ var log = log$1.getLogger("airkit");
1375
+
1675
1376
  var AirWalletProviderMessageTypes;
1676
1377
  (function (AirWalletProviderMessageTypes) {
1677
1378
  AirWalletProviderMessageTypes["REQUEST"] = "JRPC_REQUEST";
@@ -1679,54 +1380,418 @@ var AirWalletProviderMessageTypes;
1679
1380
  AirWalletProviderMessageTypes["EVENT"] = "JRPC_EVENT";
1680
1381
  })(AirWalletProviderMessageTypes || (AirWalletProviderMessageTypes = {}));
1681
1382
 
1682
- var _a$2, _ProviderMessageService_instance;
1683
- const ALLOWED_PROVIDER_MESSAGES = [
1684
- AirWalletProviderMessageTypes.RESPONSE,
1685
- AirWalletProviderMessageTypes.EVENT,
1383
+ const ACCOUNT_MESSAGES = [
1384
+ AirMessageTypes.INITIALIZATION_RESPONSE,
1385
+ AirMessageTypes.WALLET_INITIALIZED,
1386
+ AirMessageTypes.WALLET_LOGIN_RESPONSE,
1387
+ AirMessageTypes.SETUP_MFA_RESPONSE,
1388
+ AirMessageTypes.CLAIM_ID_RESPONSE,
1389
+ AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
1390
+ AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
1391
+ AirMessageTypes.EXECUTE_ACTION_RESPONSE,
1392
+ AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE,
1393
+ AirMessageTypes.GRANT_PERMISSIONS_RESPONSE,
1394
+ AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE,
1395
+ AirMessageTypes.WALLET_INITIALIZED,
1396
+ AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
1397
+ AirMessageTypes.LOGOUT_RESPONSE,
1398
+ AirMessageTypes.OPEN_WINDOW_REQUEST,
1399
+ ];
1400
+ const AUTH_MESSAGES = [
1401
+ AirAuthMessageTypes.INITIALIZATION_RESPONSE,
1402
+ AirAuthMessageTypes.LOGIN_RESPONSE,
1403
+ AirAuthMessageTypes.REFRESH_TOKEN_RESPONSE,
1404
+ AirAuthMessageTypes.SETUP_WALLET_REQUEST,
1405
+ AirAuthMessageTypes.LOGOUT_RESPONSE,
1406
+ AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
1407
+ AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
1408
+ AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_RESPONSE,
1409
+ AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
1686
1410
  ];
1687
- class ProviderMessageService extends MessageServiceBase {
1688
- static create() {
1689
- if (__classPrivateFieldGet(this, _a$2, "f", _ProviderMessageService_instance))
1690
- throw new Error("ProviderMessageService already created");
1691
- __classPrivateFieldSet(this, _a$2, new _a$2("Embed Service: Provider Channel", ALLOWED_PROVIDER_MESSAGES), "f", _ProviderMessageService_instance);
1692
- return __classPrivateFieldGet(this, _a$2, "f", _ProviderMessageService_instance);
1693
- }
1694
- async open(walletIframe) {
1695
- const origin = new URL(walletIframe.src).origin;
1696
- const window = walletIframe.contentWindow;
1697
- await super._open({ window, origin });
1698
- }
1699
- async sendWalletProviderRequest(payload) {
1700
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletProviderMessageTypes.RESPONSE), filter((msg) => msg.payload.method === payload.method)));
1701
- await this.sendMessage({
1411
+ class AirMessageService {
1412
+ constructor() {
1413
+ this.closeAuthMessageListeners = null;
1414
+ this.closeRealmMessageListeners = null;
1415
+ this.closeWalletMessageListeners = null;
1416
+ }
1417
+ static get instance() {
1418
+ if (!AirMessageService._instance) {
1419
+ AirMessageService._instance = new AirMessageService();
1420
+ }
1421
+ return AirMessageService._instance;
1422
+ }
1423
+ get messages$() {
1424
+ return this.airMessages$.asObservable();
1425
+ }
1426
+ get authMessage$() {
1427
+ return this._authMessage$.asObservable();
1428
+ }
1429
+ get providerMessage$() {
1430
+ return this._providerMessage$.asObservable();
1431
+ }
1432
+ get providerEvent$() {
1433
+ return this._providerEvent$.asObservable();
1434
+ }
1435
+ async openAuthObservables({ authIframeOrigin }) {
1436
+ this.closeAuthObservables();
1437
+ this.setupAuthObservables();
1438
+ const handleAuthMessage = async (ev) => {
1439
+ if (ev.origin !== authIframeOrigin || !ev.data || !(ev.data instanceof Object))
1440
+ return;
1441
+ log.debug("Embed auth message received from auth", ev.data);
1442
+ if (AUTH_MESSAGES.includes(ev.data.type)) {
1443
+ this._authMessage$.next(ev.data);
1444
+ }
1445
+ };
1446
+ window.addEventListener("message", handleAuthMessage);
1447
+ this.closeAuthMessageListeners = () => {
1448
+ window.removeEventListener("message", handleAuthMessage);
1449
+ };
1450
+ }
1451
+ async openWalletObservables({ walletIframeOrigin }) {
1452
+ this.closeAirObservables();
1453
+ this.setupAirObservables();
1454
+ const handleMessage = async (ev) => {
1455
+ if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object))
1456
+ return;
1457
+ log.debug("Account messages received from wallet frontend", ev.data);
1458
+ if (ACCOUNT_MESSAGES.includes(ev.data.type)) {
1459
+ this.airMessages$.next(ev.data);
1460
+ }
1461
+ };
1462
+ window.addEventListener("message", handleMessage);
1463
+ this.closeRealmMessageListeners = () => {
1464
+ window.removeEventListener("message", handleMessage);
1465
+ };
1466
+ this.closeWalletObservables();
1467
+ this.setupWalletObservables();
1468
+ const handleWalletMessage = async (ev) => {
1469
+ if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object))
1470
+ return;
1471
+ log.debug("Wallet provider messages received from wallet frontend", ev.data);
1472
+ if (ev.data.type === AirWalletProviderMessageTypes.RESPONSE) {
1473
+ this._providerMessage$.next(ev.data);
1474
+ }
1475
+ if (ev.data.type === AirWalletProviderMessageTypes.EVENT) {
1476
+ this._providerEvent$.next(ev.data);
1477
+ }
1478
+ };
1479
+ window.addEventListener("message", handleWalletMessage);
1480
+ this.closeWalletMessageListeners = () => {
1481
+ window.removeEventListener("message", handleWalletMessage);
1482
+ };
1483
+ }
1484
+ setupIframeCommunication(authIframe, walletIframe, skipWalletLogin) {
1485
+ const channel = new MessageChannel();
1486
+ const authOrigin = new URL(authIframe.src).origin;
1487
+ authIframe.contentWindow.postMessage({
1488
+ type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION,
1489
+ }, authOrigin, [channel.port1]);
1490
+ const walletOrigin = new URL(walletIframe.src).origin;
1491
+ walletIframe.contentWindow.postMessage({
1492
+ type: AirMessageTypes.INIT_AUTH_COMMUNICATION,
1493
+ payload: {
1494
+ skipWalletLogin,
1495
+ },
1496
+ }, walletOrigin, [channel.port2]);
1497
+ }
1498
+ async sendGrantPermissionRequest(walletIframe, policies) {
1499
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
1500
+ const { origin } = new URL(walletIframe.src);
1501
+ walletIframe.contentWindow.postMessage({
1502
+ type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
1503
+ payload: {
1504
+ policies,
1505
+ },
1506
+ }, origin);
1507
+ const result = await response;
1508
+ if (result.payload.success === false) {
1509
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
1510
+ }
1511
+ return result.payload.sessionData;
1512
+ }
1513
+ async sendExecuteActionRequest(walletIframe, params) {
1514
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
1515
+ const { origin } = new URL(walletIframe.src);
1516
+ walletIframe.contentWindow.postMessage({
1517
+ type: AirMessageTypes.EXECUTE_ACTION_REQUEST,
1518
+ payload: {
1519
+ sessionData: params.sessionData,
1520
+ call: {
1521
+ to: params.call.to,
1522
+ value: params.call.value,
1523
+ data: params.call.data,
1524
+ },
1525
+ sessionOwnerPrivateKey: params.sessionOwnerPrivateKey,
1526
+ },
1527
+ }, origin);
1528
+ const result = await response;
1529
+ if (result.payload.success === false) {
1530
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
1531
+ }
1532
+ return result.payload.txHash;
1533
+ }
1534
+ async sendRevokePermissionsRequest(walletIframe, permissionId) {
1535
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
1536
+ const { origin } = new URL(walletIframe.src);
1537
+ walletIframe.contentWindow.postMessage({
1538
+ type: AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
1539
+ payload: {
1540
+ permissionId,
1541
+ },
1542
+ }, origin);
1543
+ const result = await response;
1544
+ if (result.payload.success === false) {
1545
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
1546
+ }
1547
+ return result.payload.txHash;
1548
+ }
1549
+ sendDeploySmartAccountRequest(walletIframe) {
1550
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
1551
+ const { origin } = new URL(walletIframe.src);
1552
+ walletIframe.contentWindow.postMessage({
1553
+ type: AirMessageTypes.DEPLOY_SMART_ACCOUNT_REQUEST,
1554
+ }, origin);
1555
+ return response;
1556
+ }
1557
+ async sendIsSmartAccountDeployedRequest(walletIframe) {
1558
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE)));
1559
+ const { origin } = new URL(walletIframe.src);
1560
+ walletIframe.contentWindow.postMessage({
1561
+ type: AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_REQUEST,
1562
+ }, origin);
1563
+ return response;
1564
+ }
1565
+ async sendPartnerUserInfoRequest(authIframe) {
1566
+ const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
1567
+ const { origin } = new URL(authIframe.src);
1568
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.PARTNER_USER_INFO_REQUEST }, origin);
1569
+ return response;
1570
+ }
1571
+ async sendAuthLoginRequest(authIframe, payload) {
1572
+ const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
1573
+ const { origin } = new URL(authIframe.src);
1574
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.LOGIN_REQUEST, payload }, origin);
1575
+ return response;
1576
+ }
1577
+ async logoutAuth(authIframe) {
1578
+ const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGOUT_RESPONSE)));
1579
+ const { origin } = new URL(authIframe.src);
1580
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.LOGOUT_REQUEST }, origin);
1581
+ return response;
1582
+ }
1583
+ async logoutWallet(walletIframe) {
1584
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.LOGOUT_RESPONSE)));
1585
+ const { origin } = new URL(walletIframe.src);
1586
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.LOGOUT_REQUEST }, origin);
1587
+ return response;
1588
+ }
1589
+ sendResetAuthServiceWalletCommunication(authIframe) {
1590
+ const { origin: authOrigin } = new URL(authIframe.src);
1591
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.RESET_WALLET_COMMUNICATION }, authOrigin);
1592
+ }
1593
+ async sendAuthInitializationRequest(authIframe, payload) {
1594
+ const response = firstValueFrom(this._authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
1595
+ const { origin } = new URL(authIframe.src);
1596
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.INITIALIZATION_REQUEST, payload }, origin);
1597
+ return response;
1598
+ }
1599
+ async sendWalletInitializationRequest(walletIframe, payload) {
1600
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.INITIALIZATION_RESPONSE)));
1601
+ const { origin } = new URL(walletIframe.src);
1602
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.INITIALIZATION_REQUEST, payload }, origin);
1603
+ return response;
1604
+ }
1605
+ async sendCrossPartnerTokenRequest(authIframe, targetPartnerUrl) {
1606
+ const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE)));
1607
+ const { origin } = new URL(authIframe.src);
1608
+ authIframe.contentWindow.postMessage({
1609
+ type: AirAuthMessageTypes.CROSS_PARTNER_TOKEN_REQUEST,
1610
+ payload: {
1611
+ targetPartnerUrl,
1612
+ },
1613
+ }, origin);
1614
+ return response;
1615
+ }
1616
+ async sendGrantPermissionsRequest(walletIframe, payload) {
1617
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
1618
+ const { origin } = new URL(walletIframe.src);
1619
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST, payload }, origin);
1620
+ return response;
1621
+ }
1622
+ async sendListAllSessionKeyScopesRequest(walletIframe) {
1623
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE)));
1624
+ const { origin } = new URL(walletIframe.src);
1625
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_REQUEST }, origin);
1626
+ return response;
1627
+ }
1628
+ onWalletInitialized() {
1629
+ return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.WALLET_INITIALIZED)));
1630
+ }
1631
+ sendWalletLoginRequest(walletIframe) {
1632
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.WALLET_LOGIN_RESPONSE)));
1633
+ const { origin } = new URL(walletIframe.src);
1634
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.WALLET_LOGIN_REQUEST }, origin);
1635
+ return response;
1636
+ }
1637
+ async sendSetupMfaRequest(walletIframe) {
1638
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.SETUP_MFA_RESPONSE)));
1639
+ const { origin } = new URL(walletIframe.src);
1640
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.SETUP_MFA_REQUEST }, origin);
1641
+ return response;
1642
+ }
1643
+ sendOpenWindowSuccessResponse(walletIframe, windowId, port) {
1644
+ const { origin: walletOrigin } = new URL(walletIframe.src);
1645
+ walletIframe.contentWindow.postMessage({
1646
+ type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
1647
+ payload: {
1648
+ success: true,
1649
+ windowId,
1650
+ },
1651
+ }, walletOrigin, [port]);
1652
+ }
1653
+ sendOpenWindowErrorResponse(walletIframe, windowId, error) {
1654
+ const { origin: walletOrigin } = new URL(walletIframe.src);
1655
+ walletIframe.contentWindow.postMessage({
1656
+ type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
1657
+ payload: {
1658
+ success: false,
1659
+ windowId,
1660
+ errorName: "UNKNOWN_ERROR",
1661
+ errorMessage: error.message,
1662
+ },
1663
+ }, walletOrigin);
1664
+ }
1665
+ sendWindowClosed(walletIframe, windowId) {
1666
+ const { origin: walletOrigin } = new URL(walletIframe.src);
1667
+ walletIframe.contentWindow.postMessage({
1668
+ type: AirMessageTypes.WINDOW_CLOSED,
1669
+ payload: {
1670
+ windowId,
1671
+ },
1672
+ }, walletOrigin);
1673
+ }
1674
+ async sendClaimIdRequest(walletIframe, payload) {
1675
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.CLAIM_ID_RESPONSE)));
1676
+ const { origin } = new URL(walletIframe.src);
1677
+ walletIframe.contentWindow.postMessage({ type: AirMessageTypes.CLAIM_ID_REQUEST, payload }, origin);
1678
+ return response;
1679
+ }
1680
+ async sendWalletProviderRequest(walletIframe, payload) {
1681
+ const response = firstValueFrom(this.providerMessage$.pipe(filter((msg) => msg.type === AirWalletProviderMessageTypes.RESPONSE &&
1682
+ msg.payload.requestId === payload.requestId)));
1683
+ const { origin } = new URL(walletIframe.src);
1684
+ walletIframe.contentWindow.postMessage({
1702
1685
  type: AirWalletProviderMessageTypes.REQUEST,
1703
1686
  payload,
1704
- });
1687
+ }, origin);
1688
+ return response;
1689
+ }
1690
+ closeAuthObservables() {
1691
+ if (this._authMessage$ && !this._authMessage$.closed)
1692
+ this._authMessage$.complete();
1693
+ if (this.closeAuthMessageListeners)
1694
+ this.closeAuthMessageListeners();
1695
+ }
1696
+ closeAirObservables() {
1697
+ if (this.airMessages$ && !this.airMessages$.closed)
1698
+ this.airMessages$.complete();
1699
+ if (this.closeRealmMessageListeners)
1700
+ this.closeRealmMessageListeners();
1701
+ }
1702
+ closeWalletObservables() {
1703
+ if (this._providerMessage$ && !this._providerMessage$.closed)
1704
+ this._providerMessage$.complete();
1705
+ if (this._providerEvent$ && !this._providerEvent$.closed)
1706
+ this._providerEvent$.complete();
1707
+ if (this.closeWalletMessageListeners)
1708
+ this.closeWalletMessageListeners();
1709
+ }
1710
+ setupAuthObservables() {
1711
+ this._authMessage$ = new Subject();
1712
+ }
1713
+ setupAirObservables() {
1714
+ this.airMessages$ = new Subject();
1715
+ }
1716
+ setupWalletObservables() {
1717
+ this._providerMessage$ = new Subject();
1718
+ this._providerEvent$ = new Subject();
1719
+ }
1720
+ async sendGetPartnerAccessTokenRequest(authIframe) {
1721
+ const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_RESPONSE)));
1722
+ const { origin } = new URL(authIframe.src);
1723
+ authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_REQUEST }, origin);
1705
1724
  return response;
1706
1725
  }
1707
1726
  }
1708
- _a$2 = ProviderMessageService;
1709
- _ProviderMessageService_instance = { value: undefined };
1727
+ var AirMessageService$1 = AirMessageService.instance;
1728
+
1729
+ const BUILD_ENV = {
1730
+ PRODUCTION: "production",
1731
+ UAT: "uat",
1732
+ STAGING: "staging",
1733
+ DEVELOPMENT: "development",
1734
+ };
1735
+
1736
+ const AIR_URLS = {
1737
+ [BUILD_ENV.DEVELOPMENT]: {
1738
+ authUrl: "http://localhost:8100",
1739
+ walletUrl: "http://localhost:8200",
1740
+ logLevel: "debug",
1741
+ },
1742
+ [BUILD_ENV.UAT]: {
1743
+ authUrl: "https://auth.uat.air3.com",
1744
+ walletUrl: "https://account.uat.air3.com",
1745
+ logLevel: "info",
1746
+ },
1747
+ [BUILD_ENV.STAGING]: {
1748
+ authUrl: "https://auth.staging.air3.com",
1749
+ walletUrl: "https://account.staging.air3.com",
1750
+ logLevel: "info",
1751
+ },
1752
+ [BUILD_ENV.PRODUCTION]: {
1753
+ authUrl: "https://auth.air3.com",
1754
+ walletUrl: "https://account.air3.com",
1755
+ logLevel: "error",
1756
+ },
1757
+ };
1758
+ const isElement = (element) => element instanceof Element || element instanceof Document;
1759
+ const randomId = () => Math.random().toString(36).slice(2);
1760
+ const getWindowFeatures = (width, height) => {
1761
+ const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
1762
+ const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
1763
+ const w = window.innerWidth
1764
+ ? window.innerWidth
1765
+ : document.documentElement.clientWidth
1766
+ ? document.documentElement.clientWidth
1767
+ : window.screen.width;
1768
+ const h = window.innerHeight
1769
+ ? window.innerHeight
1770
+ : document.documentElement.clientHeight
1771
+ ? document.documentElement.clientHeight
1772
+ : window.screen.height;
1773
+ const systemZoom = 1; // No reliable estimate
1774
+ const left = Math.abs((w - width) / 2 / systemZoom + dualScreenLeft);
1775
+ const top = Math.abs((h - height) / 2 / systemZoom + dualScreenTop);
1776
+ return `titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=${height / systemZoom},width=${width / systemZoom},top=${top},left=${left}`;
1777
+ };
1710
1778
 
1711
- var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService, _AirWalletProvider_isLoggedIn, _AirWalletProvider_ensureWallet, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
1779
+ var _AirWalletProvider_instances, _AirWalletProvider_isLoggedIn, _AirWalletProvider_ensureWallet, _AirWalletProvider_getWalletIframeController, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
1712
1780
  class AirWalletProvider {
1713
- constructor({ isLoggedIn, ensureWallet, }) {
1781
+ constructor({ isLoggedIn, ensureWallet, getWalletIframeController, }) {
1714
1782
  _AirWalletProvider_instances.add(this);
1715
- _AirWalletProvider_providerMessageService.set(this, undefined);
1716
1783
  _AirWalletProvider_isLoggedIn.set(this, undefined);
1717
1784
  _AirWalletProvider_ensureWallet.set(this, undefined);
1785
+ _AirWalletProvider_getWalletIframeController.set(this, undefined);
1718
1786
  _AirWalletProvider_eventListeners.set(this, undefined);
1719
- this.startEventMessageListening = async (walletIframe) => {
1720
- await __classPrivateFieldGet(this, _AirWalletProvider_providerMessageService, "f").open(walletIframe);
1721
- __classPrivateFieldGet(this, _AirWalletProvider_providerMessageService, "f").messages$
1722
- .pipe(filter((msg) => msg.type === AirWalletProviderMessageTypes.EVENT))
1723
- .subscribe((message) => {
1787
+ this.startEventMessageListening = () => {
1788
+ AirMessageService$1.providerEvent$.subscribe((message) => {
1724
1789
  __classPrivateFieldGet(this, _AirWalletProvider_instances, "m", _AirWalletProvider_emit).call(this, message.payload.event, ...[message.payload.data]);
1725
1790
  });
1726
1791
  };
1727
- __classPrivateFieldSet(this, _AirWalletProvider_providerMessageService, ProviderMessageService.create(), "f");
1728
1792
  __classPrivateFieldSet(this, _AirWalletProvider_isLoggedIn, isLoggedIn, "f");
1729
1793
  __classPrivateFieldSet(this, _AirWalletProvider_ensureWallet, ensureWallet, "f");
1794
+ __classPrivateFieldSet(this, _AirWalletProvider_getWalletIframeController, getWalletIframeController, "f");
1730
1795
  __classPrivateFieldSet(this, _AirWalletProvider_eventListeners, {
1731
1796
  connect: [],
1732
1797
  disconnect: [],
@@ -1762,7 +1827,7 @@ class AirWalletProvider {
1762
1827
  throw ensureProviderRpcError(error);
1763
1828
  }
1764
1829
  const requestId = randomId();
1765
- const response = await __classPrivateFieldGet(this, _AirWalletProvider_providerMessageService, "f").sendWalletProviderRequest({
1830
+ const response = await AirMessageService$1.sendWalletProviderRequest(__classPrivateFieldGet(this, _AirWalletProvider_getWalletIframeController, "f").call(this).iframeElement, {
1766
1831
  requestId,
1767
1832
  ...request,
1768
1833
  });
@@ -1792,13 +1857,13 @@ class AirWalletProvider {
1792
1857
  }, "f");
1793
1858
  }
1794
1859
  }
1795
- _AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_isLoggedIn = new WeakMap(), _AirWalletProvider_ensureWallet = new WeakMap(), _AirWalletProvider_eventListeners = new WeakMap(), _AirWalletProvider_instances = new WeakSet(), _AirWalletProvider_emit = function _AirWalletProvider_emit(eventName, ...args) {
1860
+ _AirWalletProvider_isLoggedIn = new WeakMap(), _AirWalletProvider_ensureWallet = new WeakMap(), _AirWalletProvider_getWalletIframeController = new WeakMap(), _AirWalletProvider_eventListeners = new WeakMap(), _AirWalletProvider_instances = new WeakSet(), _AirWalletProvider_emit = function _AirWalletProvider_emit(eventName, ...args) {
1796
1861
  (__classPrivateFieldGet(this, _AirWalletProvider_eventListeners, "f")[eventName] || []).forEach((listener) => {
1797
1862
  try {
1798
1863
  return listener(...args);
1799
1864
  }
1800
1865
  catch (error) {
1801
- log.warn(error);
1866
+ log$1.error(error);
1802
1867
  }
1803
1868
  });
1804
1869
  };
@@ -1829,7 +1894,6 @@ class IframeController {
1829
1894
  iframe.style.margin = "0";
1830
1895
  iframe.style.padding = "0";
1831
1896
  iframe.style.display = "none";
1832
- iframe.style.colorScheme = "auto";
1833
1897
  document.body.appendChild(iframe);
1834
1898
  this._iframeElement = iframe;
1835
1899
  return iframe;
@@ -1867,137 +1931,85 @@ IframeController.defaultState = {
1867
1931
  isVisible: false,
1868
1932
  };
1869
1933
 
1870
- /**
1871
- * Creates a window features string for `window.open`, based on the current screen size.
1872
- * It tries to center the window and limits the size to the given max width and height.
1873
- * Slightly reduces the size to avoid browser auto-resizing.
1874
- */
1875
- const getWindowFeatures = (maxWidth, maxHeight) => {
1876
- const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
1877
- const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
1878
- const w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : window.screen.width;
1879
- const h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : window.screen.height;
1880
- // 95% adjustment for mobile devices, some browser might resize the window
1881
- const finalWidth = Math.min(w, maxWidth) * 0.95;
1882
- const finalHeight = Math.min(h, maxHeight) * 0.95;
1883
- const systemZoom = 1; // No reliable estimate
1884
- const left = Math.abs((w - finalWidth) / 2 / systemZoom + dualScreenLeft);
1885
- const top = Math.abs((h - finalHeight) / 2 / systemZoom + dualScreenTop);
1886
- return `titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=${finalHeight / systemZoom},width=${finalWidth / systemZoom},top=${top},left=${left}`;
1887
- };
1888
-
1889
1934
  class WindowController {
1890
- get messages$() {
1891
- return this._messages$.asObservable();
1892
- }
1893
- constructor(windowId, windowUrl) {
1894
- this._windowInstance = null;
1895
- this._messageHandler = null;
1896
- this._messages$ = new Subject();
1897
- this.windowId = windowId;
1898
- this.windowUrl = windowUrl;
1899
- this.windowOrigin = new URL(windowUrl).origin;
1900
- this._messageHandler = ev => {
1901
- if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
1902
- return;
1903
- }
1904
- this._messages$.next(ev);
1905
- };
1906
- window.addEventListener("message", this._messageHandler);
1907
- }
1908
- get windowInstance() {
1909
- return this._windowInstance;
1910
- }
1911
- async openWindow(onRetry) {
1912
- let windowInstance = this.tryOpenWindow();
1913
- if (!windowInstance) {
1914
- await onRetry();
1915
- windowInstance = this.tryOpenWindow();
1916
- if (!windowInstance) {
1917
- throw new AirError(WindowErrorName.WINDOW_BLOCKED);
1918
- }
1919
- }
1920
- const pendingWindowOpenCheck = new Promise((resolve, reject) => {
1921
- setTimeout(() => {
1922
- if (this.isWindowOpen(windowInstance)) {
1923
- // only now are we scheduling the close event check since we're sure the window is open
1924
- this.scheduleWindowClosedChecks(windowInstance);
1925
- resolve("opened");
1926
- } else {
1927
- onRetry().then(() => {
1928
- windowInstance = this.tryOpenWindow();
1929
- if (windowInstance) {
1930
- this._windowInstance = windowInstance;
1931
- windowInstance.focus();
1932
- this.scheduleWindowClosedChecks(windowInstance);
1933
- resolve("retry");
1934
- } else {
1935
- reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
1935
+ get messages$() {
1936
+ return this._messages$.asObservable();
1937
+ }
1938
+ constructor(windowUrl, windowId) {
1939
+ this._windowInstance = null;
1940
+ this._messageHandler = null;
1941
+ this._messages$ = new Subject();
1942
+ this.windowUrl = windowUrl;
1943
+ this.windowOrigin = new URL(windowUrl).origin;
1944
+ this.windowId = windowId;
1945
+ }
1946
+ get windowInstance() {
1947
+ return this._windowInstance;
1948
+ }
1949
+ openWindow() {
1950
+ if (this._windowInstance && !this._windowInstance.closed) {
1951
+ this._windowInstance.focus();
1952
+ return this._windowInstance;
1953
+ }
1954
+ const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(400, 600));
1955
+ if (!windowInstance) {
1956
+ throw new Error("Failed to open window. Popup might be blocked by the browser.");
1957
+ }
1958
+ this._windowInstance = windowInstance;
1959
+ this._messageHandler = (ev) => {
1960
+ if (ev.source !== windowInstance ||
1961
+ ev.origin !== this.windowOrigin ||
1962
+ !ev.data ||
1963
+ !(ev.data instanceof Object)) {
1964
+ return;
1936
1965
  }
1937
- }).catch(reject);
1938
- }
1939
- }, 1000);
1940
- });
1941
- this._windowInstance = windowInstance;
1942
- windowInstance.focus();
1943
- return {
1944
- pendingWindowOpenCheck
1945
- };
1946
- }
1947
- postMessage(message, transfer) {
1948
- if (!this._windowInstance) return;
1949
- this._windowInstance.postMessage(message, this.windowOrigin, transfer);
1950
- }
1951
- onMessage(callback) {
1952
- const listener = ev => {
1953
- if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
1954
- callback(ev);
1955
- };
1956
- window.addEventListener("message", listener);
1957
- const close = () => window.removeEventListener("message", listener);
1958
- this.onClose(close);
1959
- return {
1960
- close
1961
- };
1962
- }
1963
- cleanup() {
1964
- if (this._windowInstance && !this._windowInstance.closed) {
1965
- this._windowInstance.close();
1966
- }
1967
- this._windowInstance = null;
1968
- if (this._messageHandler) {
1969
- window.removeEventListener("message", this._messageHandler);
1970
- this._messageHandler = null;
1966
+ this._messages$.next(ev);
1967
+ };
1968
+ window.addEventListener("message", this._messageHandler);
1969
+ const checkWindow = setInterval(() => {
1970
+ if (!this._windowInstance || this._windowInstance?.closed) {
1971
+ this.cleanup();
1972
+ clearInterval(checkWindow);
1973
+ }
1974
+ }, 500);
1975
+ return windowInstance;
1971
1976
  }
1972
- if (this._messages$ && !this._messages$.closed) {
1973
- this._messages$.complete();
1977
+ postMessage(message, transfer) {
1978
+ if (!this._windowInstance)
1979
+ return;
1980
+ this._windowInstance.postMessage(message, this.windowOrigin, transfer);
1974
1981
  }
1975
- }
1976
- onClose(callback) {
1977
- return this._messages$.subscribe({
1978
- complete: callback
1979
- });
1980
- }
1981
- isWindowOpen(windowInstance) {
1982
- return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
1983
- }
1984
- tryOpenWindow() {
1985
- const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
1986
- if (this.isWindowOpen(windowInstance)) {
1987
- return windowInstance;
1982
+ onMessage(callback) {
1983
+ const listener = (ev) => {
1984
+ if (ev.source !== this._windowInstance)
1985
+ return;
1986
+ callback(ev);
1987
+ };
1988
+ window.addEventListener("message", listener);
1989
+ const close = () => window.removeEventListener("message", listener);
1990
+ this.onClose(close);
1991
+ return {
1992
+ close,
1993
+ };
1988
1994
  }
1989
- return null;
1990
- }
1991
- scheduleWindowClosedChecks(windowInstance) {
1992
- const checkWindow = setInterval(() => {
1993
- if (!windowInstance || windowInstance.closed) {
1994
- clearInterval(checkWindow);
1995
- if (windowInstance === this._windowInstance) {
1996
- this.cleanup();
1995
+ cleanup() {
1996
+ if (this._windowInstance && !this._windowInstance.closed) {
1997
+ this._windowInstance.close();
1997
1998
  }
1998
- }
1999
- }, 500);
2000
- }
1999
+ if (this._messageHandler) {
2000
+ window.removeEventListener("message", this._messageHandler);
2001
+ this._messageHandler = null;
2002
+ }
2003
+ if (this._messages$ && !this._messages$.closed) {
2004
+ this._messages$.complete();
2005
+ }
2006
+ this._windowInstance = null;
2007
+ }
2008
+ onClose(callback) {
2009
+ return this._messages$.subscribe({
2010
+ complete: callback,
2011
+ });
2012
+ }
2001
2013
  }
2002
2014
 
2003
2015
  class WindowService {
@@ -2016,59 +2028,37 @@ class WindowService {
2016
2028
  if (!windowInstance) {
2017
2029
  throw new Error("Window instance not found");
2018
2030
  }
2019
- const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type ===
2020
- AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
2021
- windowController.postMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload }, [
2022
- port,
2023
- ]);
2031
+ const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type === AirMessageTypes.INITIALIZATION_RESPONSE)));
2032
+ windowController.postMessage({ type: AirMessageTypes.INITIALIZATION_REQUEST, payload }, [port]);
2024
2033
  return (await response).data;
2025
2034
  }
2026
- async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, onRetry, sdkVersion, }) {
2035
+ async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, port, }) {
2027
2036
  if (this.windowControllers.has(windowId)) {
2028
2037
  throw new Error("Window controller already exists");
2029
2038
  }
2030
- const windowController = new WindowController(windowId, url);
2031
- const { pendingWindowOpenCheck } = await windowController.openWindow(onRetry);
2039
+ const windowController = new WindowController(url, windowId);
2040
+ this.windowControllers.set(windowId, windowController);
2041
+ windowController.openWindow();
2032
2042
  windowController.onClose(() => {
2033
2043
  this.removeWindowController(windowId);
2034
2044
  });
2035
- this.windowControllers.set(windowId, windowController);
2036
- let channel = null;
2037
- const initializeWindow = () => {
2038
- return new Promise((resolve, reject) => {
2039
- windowController.onMessage(async (ev) => {
2040
- if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
2041
- try {
2042
- channel = new MessageChannel();
2043
- const { payload } = await this.sendWindowInitializationRequest(windowId, {
2044
- partnerId,
2045
- enableLogging,
2046
- sdkVersion,
2047
- }, channel.port1);
2048
- if (payload.success === false) {
2049
- reject(new AirServiceError(payload.errorName, payload.errorMessage));
2050
- }
2051
- else {
2052
- resolve();
2053
- }
2054
- }
2055
- catch (e) {
2056
- reject(e);
2057
- }
2045
+ await new Promise((resolve, reject) => {
2046
+ windowController.onMessage(async (ev) => {
2047
+ if (ev.data === AirMessageTypes.SERVICE_STARTED) {
2048
+ const { payload } = await this.sendWindowInitializationRequest(windowId, {
2049
+ partnerId,
2050
+ enableLogging,
2051
+ }, port);
2052
+ if (payload.success === false) {
2053
+ reject(new AirServiceError(payload.errorName, payload.errorMessage));
2054
+ }
2055
+ else {
2056
+ resolve();
2058
2057
  }
2059
- });
2058
+ }
2060
2059
  });
2061
- };
2062
- const initializeWindowPromise = initializeWindow();
2063
- const result = await pendingWindowOpenCheck;
2064
- if (result === "retry") {
2065
- // we can ignore previous initialization attempt since a new window was opened
2066
- await initializeWindow();
2067
- }
2068
- else {
2069
- await initializeWindowPromise;
2070
- }
2071
- return { windowController, port: channel.port2 };
2060
+ });
2061
+ return windowController;
2072
2062
  }
2073
2063
  getWindowController(windowId) {
2074
2064
  return this.windowControllers.get(windowId);
@@ -2079,381 +2069,7 @@ class WindowService {
2079
2069
  }
2080
2070
  var WindowService$1 = WindowService.instance;
2081
2071
 
2082
- var _a$1, _AuthMessageService_instance;
2083
- const ALLOWED_AUTH_MESSAGES = [
2084
- AirAuthMessageTypes.INITIALIZATION_RESPONSE,
2085
- AirAuthMessageTypes.LOGIN_RESPONSE,
2086
- AirAuthMessageTypes.SETUP_WALLET_REQUEST,
2087
- AirAuthMessageTypes.LOGOUT_RESPONSE,
2088
- AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
2089
- AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
2090
- AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
2091
- AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
2092
- ];
2093
- class AuthMessageService extends MessageServiceBase {
2094
- static create() {
2095
- if (__classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance))
2096
- throw new Error("AuthMessageService already created");
2097
- __classPrivateFieldSet(this, _a$1, new _a$1("Embed Service: Auth Channel", ALLOWED_AUTH_MESSAGES), "f", _AuthMessageService_instance);
2098
- return __classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance);
2099
- }
2100
- async open(authIframe) {
2101
- const origin = new URL(authIframe.src).origin;
2102
- const window = authIframe.contentWindow;
2103
- await super._open({ window, origin });
2104
- }
2105
- async initWalletCommunication(port) {
2106
- await this.sendMessage({
2107
- type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION,
2108
- }, [port]);
2109
- }
2110
- async sendPartnerUserInfoRequest() {
2111
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
2112
- await this.sendMessage({
2113
- type: AirAuthMessageTypes.PARTNER_USER_INFO_REQUEST,
2114
- payload: { allowCache: false },
2115
- });
2116
- return response;
2117
- }
2118
- async sendLoginRequest(payload) {
2119
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
2120
- await this.sendMessage({ type: AirAuthMessageTypes.LOGIN_REQUEST, payload });
2121
- return response;
2122
- }
2123
- async logout() {
2124
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGOUT_RESPONSE)));
2125
- await this.sendMessage({ type: AirAuthMessageTypes.LOGOUT_REQUEST });
2126
- return response;
2127
- }
2128
- async resetWalletCommunication() {
2129
- await this.sendMessage({ type: AirAuthMessageTypes.RESET_WALLET_COMMUNICATION });
2130
- }
2131
- async sendInitializationRequest(payload) {
2132
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
2133
- await this.sendMessage({ type: AirAuthMessageTypes.INITIALIZATION_REQUEST, payload });
2134
- return response;
2135
- }
2136
- async sendSetupWalletSuccessResponse() {
2137
- await this.sendMessage({
2138
- type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
2139
- payload: {
2140
- success: true,
2141
- },
2142
- });
2143
- }
2144
- async sendSetupWalletErrorResponse(error) {
2145
- await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
2146
- }
2147
- async sendCrossPartnerTokenRequest(targetPartnerUrl) {
2148
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE)));
2149
- await this.sendMessage({
2150
- type: AirAuthMessageTypes.CROSS_PARTNER_TOKEN_REQUEST,
2151
- payload: {
2152
- targetPartnerUrl,
2153
- },
2154
- });
2155
- return response;
2156
- }
2157
- async sendPartnerAccessTokenRequest() {
2158
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE)));
2159
- await this.sendMessage({ type: AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_REQUEST });
2160
- return response;
2161
- }
2162
- }
2163
- _a$1 = AuthMessageService;
2164
- _AuthMessageService_instance = { value: undefined };
2165
-
2166
- var _a, _WalletMessageService_instance;
2167
- const ALLOWED_WALLET_MESSAGES = [
2168
- AirWalletMessageTypes.INITIALIZATION_RESPONSE,
2169
- AirWalletMessageTypes.WALLET_INITIALIZED,
2170
- AirWalletMessageTypes.WALLET_LOGIN_RESPONSE,
2171
- AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE,
2172
- AirWalletMessageTypes.CLAIM_ID_RESPONSE,
2173
- AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
2174
- AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
2175
- AirWalletMessageTypes.EXECUTE_ACTION_RESPONSE,
2176
- AirWalletMessageTypes.REVOKE_PERMISSIONS_RESPONSE,
2177
- AirWalletMessageTypes.GRANT_PERMISSIONS_RESPONSE,
2178
- AirWalletMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE,
2179
- AirWalletMessageTypes.WALLET_INITIALIZED,
2180
- AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
2181
- AirWalletMessageTypes.LOGOUT_RESPONSE,
2182
- AirWalletMessageTypes.OPEN_WINDOW_REQUEST,
2183
- AirWalletMessageTypes.OPEN_WINDOW_RETRY_RESPONSE,
2184
- ];
2185
- class WalletMessageService extends MessageServiceBase {
2186
- static create() {
2187
- if (__classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance))
2188
- throw new Error("WalletMessageService already created");
2189
- __classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
2190
- return __classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance);
2191
- }
2192
- async open(walletIframe) {
2193
- const origin = new URL(walletIframe.src).origin;
2194
- const window = walletIframe.contentWindow;
2195
- await super._open({ window, origin });
2196
- }
2197
- async initAuthCommunication(skipWalletLogin, port) {
2198
- await this.sendMessage({
2199
- type: AirWalletMessageTypes.INIT_AUTH_COMMUNICATION,
2200
- payload: {
2201
- skipWalletLogin,
2202
- },
2203
- }, [port]);
2204
- }
2205
- async sendGrantPermissionRequest(policies) {
2206
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
2207
- await this.sendMessage({
2208
- type: AirWalletMessageTypes.GRANT_PERMISSIONS_REQUEST,
2209
- payload: {
2210
- policies,
2211
- },
2212
- });
2213
- const result = await response;
2214
- if (result.payload.success === false) {
2215
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2216
- }
2217
- return result.payload.sessionData;
2218
- }
2219
- async sendExecuteActionRequest(params) {
2220
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.EXECUTE_ACTION_RESPONSE)));
2221
- await this.sendMessage({
2222
- type: AirWalletMessageTypes.EXECUTE_ACTION_REQUEST,
2223
- payload: {
2224
- sessionData: params.sessionData,
2225
- call: {
2226
- to: params.call.to,
2227
- value: params.call.value,
2228
- data: params.call.data,
2229
- },
2230
- sessionOwnerPrivateKey: params.sessionOwnerPrivateKey,
2231
- },
2232
- });
2233
- const result = await response;
2234
- if (result.payload.success === false) {
2235
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2236
- }
2237
- return result.payload.txHash;
2238
- }
2239
- async sendRevokePermissionsRequest(permissionId) {
2240
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
2241
- await this.sendMessage({
2242
- type: AirWalletMessageTypes.REVOKE_PERMISSIONS_REQUEST,
2243
- payload: {
2244
- permissionId,
2245
- },
2246
- });
2247
- const result = await response;
2248
- if (result.payload.success === false) {
2249
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2250
- }
2251
- return result.payload.txHash;
2252
- }
2253
- async sendDeploySmartAccountRequest() {
2254
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
2255
- await this.sendMessage({
2256
- type: AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_REQUEST,
2257
- });
2258
- return response;
2259
- }
2260
- async sendIsSmartAccountDeployedRequest() {
2261
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE)));
2262
- await this.sendMessage({
2263
- type: AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_REQUEST,
2264
- });
2265
- return response;
2266
- }
2267
- async logout() {
2268
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.LOGOUT_RESPONSE)));
2269
- await this.sendMessage({ type: AirWalletMessageTypes.LOGOUT_REQUEST });
2270
- return response;
2271
- }
2272
- async sendInitializationRequest(payload) {
2273
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
2274
- await this.sendMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload });
2275
- return response;
2276
- }
2277
- async sendGrantPermissionsRequest(payload) {
2278
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
2279
- await this.sendMessage({ type: AirWalletMessageTypes.GRANT_PERMISSIONS_REQUEST, payload });
2280
- return response;
2281
- }
2282
- async sendListAllSessionKeyScopesRequest() {
2283
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE)));
2284
- await this.sendMessage({ type: AirWalletMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_REQUEST });
2285
- return response;
2286
- }
2287
- onInitialized() {
2288
- return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_INITIALIZED)));
2289
- }
2290
- async sendLoginRequest() {
2291
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_LOGIN_RESPONSE)));
2292
- await this.sendMessage({
2293
- type: AirWalletMessageTypes.WALLET_LOGIN_REQUEST,
2294
- });
2295
- return response;
2296
- }
2297
- async sendSetupMfaRequest() {
2298
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE)));
2299
- await this.sendMessage({
2300
- type: AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_REQUEST,
2301
- });
2302
- return response;
2303
- }
2304
- async sendOpenWindowSuccessResponse(windowId, port) {
2305
- await this.sendMessage({
2306
- type: AirWalletMessageTypes.OPEN_WINDOW_RESPONSE,
2307
- payload: {
2308
- success: true,
2309
- windowId,
2310
- },
2311
- }, [port]);
2312
- }
2313
- async sendOpenWindowErrorResponse(windowId, error) {
2314
- const errorResponse = this.createErrorResponseMessage(AirWalletMessageTypes.OPEN_WINDOW_RESPONSE, error);
2315
- await this.sendMessage({
2316
- ...errorResponse,
2317
- payload: { ...errorResponse.payload, windowId },
2318
- });
2319
- }
2320
- async sendOpenWindowRetryRequest(windowId) {
2321
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.OPEN_WINDOW_RETRY_RESPONSE), filter((msg) => msg.payload.windowId === windowId)));
2322
- await this.sendMessage({
2323
- type: AirWalletMessageTypes.OPEN_WINDOW_RETRY_REQUEST,
2324
- payload: { windowId },
2325
- });
2326
- return response;
2327
- }
2328
- async sendWindowClosed(windowId) {
2329
- await this.sendMessage({
2330
- type: AirWalletMessageTypes.WINDOW_CLOSED,
2331
- payload: {
2332
- windowId,
2333
- },
2334
- });
2335
- }
2336
- async sendClaimIdRequest(payload) {
2337
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.CLAIM_ID_RESPONSE)));
2338
- await this.sendMessage({ type: AirWalletMessageTypes.CLAIM_ID_REQUEST, payload });
2339
- return response;
2340
- }
2341
- }
2342
- _a = WalletMessageService;
2343
- _WalletMessageService_instance = { value: undefined };
2344
-
2345
- const getLevelName = levelNum => {
2346
- const levelNames = Object.keys(log.levels);
2347
- if (levelNum >= 0 && levelNum < levelNames.length) {
2348
- return levelNames[levelNum];
2349
- }
2350
- return "UNKNOWN";
2351
- };
2352
- const configureLogLevel = (environment, enableLogging) => {
2353
- let level = log.levels.ERROR;
2354
- if (environment === "development") {
2355
- level = enableLogging ? log.levels.TRACE : log.levels.INFO;
2356
- } else if (environment === "staging") {
2357
- level = enableLogging ? log.levels.DEBUG : log.levels.INFO;
2358
- } else if (environment === "uat") {
2359
- level = enableLogging ? log.levels.INFO : log.levels.WARN;
2360
- } else if (environment === "production") {
2361
- // Be cautious with enabling more than WARN in prod
2362
- level = enableLogging ? log.levels.WARN : log.levels.ERROR;
2363
- }
2364
- log.setLevel(level);
2365
- log.info(`[${window?.location?.origin}] LogLevel: ${getLevelName(log.getLevel())}`);
2366
- };
2367
-
2368
- var name = "@mocanetwork/airkit";
2369
- var version = "1.2.1";
2370
- var description = "Air kit to interact with the Moca Network";
2371
- var main = "dist/airkit.cjs.js";
2372
- var module = "dist/airkit.esm.js";
2373
- var unpkg = "dist/airkit.umd.min.js";
2374
- var jsdelivr = "dist/airkit.umd.min.js";
2375
- var types = "dist/types/index.d.ts";
2376
- var files = [
2377
- "dist"
2378
- ];
2379
- var scripts = {
2380
- build: "rollup --config",
2381
- prepack: "npm run build && npm run postbuild",
2382
- lint: "eslint --fix 'src/**/*.ts'",
2383
- format: "prettier --write 'src/**/*.ts'",
2384
- postbuild: "node scripts/copyAndAdjustDtsFiles.js '../common/src' 'common'"
2385
- };
2386
- var dependencies = {
2387
- "@mocanetwork/airkit-connector": "^1.2.0",
2388
- "fast-deep-equal": "^3.1.3",
2389
- loglevel: "^1.9.2",
2390
- pump: "^3.0.0",
2391
- "readable-stream": "^4.5.2",
2392
- rxjs: "^7.8.1"
2393
- };
2394
- var devDependencies = {
2395
- "@babel/runtime": "^7.25.6",
2396
- "@rushstack/eslint-patch": "^1.10.2",
2397
- "@types/pump": "^1.1.3",
2398
- "@types/readable-stream": "^4.0.15",
2399
- "fs-extra": "^11.2.0",
2400
- glob: "^11.0.0",
2401
- process: "^0.11.10",
2402
- "typescript-eslint": "^8.21.0"
2403
- };
2404
- var mocha = {
2405
- timeout: 0
2406
- };
2407
- var keywords = [
2408
- "airkit",
2409
- "mocaverse",
2410
- "wallet",
2411
- "embed",
2412
- "login",
2413
- "OAuth",
2414
- "crypto"
2415
- ];
2416
- var author = "Mocaverse";
2417
- var license = "ISC";
2418
- var engines = {
2419
- node: ">=18.x",
2420
- npm: ">=9.x"
2421
- };
2422
- var publishConfig = {
2423
- access: "restricted"
2424
- };
2425
- var airkitPackage = {
2426
- name: name,
2427
- version: version,
2428
- description: description,
2429
- main: main,
2430
- module: module,
2431
- unpkg: unpkg,
2432
- jsdelivr: jsdelivr,
2433
- types: types,
2434
- files: files,
2435
- scripts: scripts,
2436
- dependencies: dependencies,
2437
- devDependencies: devDependencies,
2438
- mocha: mocha,
2439
- keywords: keywords,
2440
- author: author,
2441
- license: license,
2442
- "lint-staged": {
2443
- "!(*d).{js,ts}": [
2444
- "eslint --cache --fix",
2445
- "prettier --write"
2446
- ],
2447
- "*.{json, md}": [
2448
- "prettier --write"
2449
- ]
2450
- },
2451
- engines: engines,
2452
- publishConfig: publishConfig
2453
- };
2454
-
2455
- var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
2456
- const airKitVersion = airkitPackage.version;
2072
+ var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
2457
2073
  class AirService {
2458
2074
  constructor({ partnerId }) {
2459
2075
  _AirService_instances.add(this);
@@ -2462,21 +2078,18 @@ class AirService {
2462
2078
  _AirService_enableLogging.set(this, false);
2463
2079
  _AirService_partnerId.set(this, undefined);
2464
2080
  //#modalZIndex: number; TODO implement z index overwrite
2465
- _AirService_authMessagingService.set(this, undefined);
2466
2081
  _AirService_authIframeController.set(this, undefined);
2467
2082
  _AirService_isAuthInitialized.set(this, false);
2468
2083
  _AirService_airAuthListener.set(this, []);
2469
- _AirService_walletMessagingService.set(this, undefined);
2470
2084
  _AirService_walletIframeController.set(this, undefined);
2471
2085
  _AirService_walletInitialization.set(this, undefined);
2472
2086
  _AirService_walletLoggedInResult.set(this, undefined);
2473
2087
  _AirService_airWalletProvider.set(this, undefined);
2474
2088
  __classPrivateFieldSet(this, _AirService_partnerId, partnerId, "f");
2475
- __classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create(), "f");
2476
- __classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create(), "f");
2477
2089
  __classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
2478
2090
  isLoggedIn: () => this.isLoggedIn,
2479
2091
  ensureWallet: __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
2092
+ getWalletIframeController: () => __classPrivateFieldGet(this, _AirService_walletIframeController, "f"),
2480
2093
  }), "f");
2481
2094
  // this.#modalZIndex = modalZIndex ?? 99999;
2482
2095
  }
@@ -2507,46 +2120,61 @@ class AirService {
2507
2120
  return;
2508
2121
  __classPrivateFieldSet(this, _AirService_buildEnv, buildEnv, "f");
2509
2122
  __classPrivateFieldSet(this, _AirService_enableLogging, enableLogging, "f");
2510
- const { authUrl } = AIR_URLS[buildEnv];
2511
- configureLogLevel(buildEnv, enableLogging);
2123
+ const { authUrl, logLevel } = AIR_URLS[buildEnv];
2124
+ log.setDefaultLevel(logLevel);
2125
+ if (__classPrivateFieldGet(this, _AirService_enableLogging, "f"))
2126
+ log.enableAll();
2127
+ else
2128
+ log.disableAll();
2512
2129
  const authIframeOrigin = new URL(authUrl).origin;
2130
+ await AirMessageService$1.openAuthObservables({ authIframeOrigin });
2513
2131
  __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController(authUrl, `air-auth-${randomId()}`), "f");
2514
- try {
2515
- __classPrivateFieldGet(this, _AirService_authIframeController, "f").createIframe();
2516
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
2517
- __classPrivateFieldGet(this, _AirService_authMessagingService, "f").messages$.subscribe(async (msg) => {
2518
- switch (msg.type) {
2519
- case AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST: {
2520
- const authIframeController = __classPrivateFieldGet(this, _AirService_authIframeController, "f");
2521
- authIframeController.setIframeVisibility(msg.payload.visible);
2522
- authIframeController.updateIframeState();
2523
- break;
2132
+ AirMessageService$1.authMessage$.subscribe(async (msg) => {
2133
+ switch (msg.type) {
2134
+ case AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST: {
2135
+ const authIframeController = __classPrivateFieldGet(this, _AirService_authIframeController, "f");
2136
+ authIframeController.setIframeVisibility(msg.payload.visible);
2137
+ authIframeController.updateIframeState();
2138
+ break;
2139
+ }
2140
+ case AirAuthMessageTypes.SETUP_WALLET_REQUEST: {
2141
+ try {
2142
+ await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this, { skipWalletLogin: true });
2143
+ __classPrivateFieldGet(this, _AirService_authIframeController, "f").postMessage({
2144
+ type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
2145
+ payload: {
2146
+ success: true,
2147
+ },
2148
+ });
2524
2149
  }
2525
- case AirAuthMessageTypes.SETUP_WALLET_REQUEST: {
2526
- try {
2527
- await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this, { skipWalletLogin: true });
2528
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendSetupWalletSuccessResponse();
2529
- }
2530
- catch (err) {
2531
- const error = ensureError(err);
2532
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendSetupWalletErrorResponse(error);
2533
- }
2534
- break;
2150
+ catch (err) {
2151
+ log.error("Error initializing wallet", err);
2152
+ const error = AirServiceError.from(err);
2153
+ __classPrivateFieldGet(this, _AirService_authIframeController, "f").postMessage({
2154
+ type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
2155
+ payload: {
2156
+ success: false,
2157
+ errorName: error.name ?? "UNKNOWN_ERROR",
2158
+ errorMessage: error.message ?? "Unknown error occurred",
2159
+ },
2160
+ });
2535
2161
  }
2162
+ break;
2536
2163
  }
2537
- });
2164
+ }
2165
+ });
2166
+ try {
2167
+ __classPrivateFieldGet(this, _AirService_authIframeController, "f").createIframe();
2538
2168
  const result = await new Promise((resolve, reject) => {
2539
2169
  const handleAuthMessage = async (ev) => {
2540
2170
  if (ev.origin !== authIframeOrigin)
2541
2171
  return;
2542
2172
  if (ev.data === AirAuthMessageTypes.AUTH_SETUP_COMPLETED) {
2543
2173
  window.removeEventListener("message", handleAuthMessage);
2544
- const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendInitializationRequest({
2174
+ const { payload } = await AirMessageService$1.sendAuthInitializationRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement, {
2545
2175
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
2546
2176
  skipRehydration,
2547
2177
  partnerDAppUrl: window.location.href,
2548
- sdkVersion: airKitVersion,
2549
- enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
2550
2178
  });
2551
2179
  if (payload.success === true) {
2552
2180
  resolve(payload);
@@ -2579,7 +2207,8 @@ class AirService {
2579
2207
  throw new Error("Service is not initialized");
2580
2208
  if (__classPrivateFieldGet(this, _AirService_loginResult, "f"))
2581
2209
  return __classPrivateFieldGet(this, _AirService_loginResult, "f");
2582
- const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLoginRequest({
2210
+ const iframeController = __classPrivateFieldGet(this, _AirService_authIframeController, "f");
2211
+ const { payload } = await AirMessageService$1.sendAuthLoginRequest(iframeController.iframeElement, {
2583
2212
  partnerLoginToken: options?.authToken,
2584
2213
  });
2585
2214
  if (payload.success === true) {
@@ -2587,7 +2216,7 @@ class AirService {
2587
2216
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedIn).call(this);
2588
2217
  return __classPrivateFieldGet(this, _AirService_loginResult, "f");
2589
2218
  }
2590
- throw new AirServiceError(payload.errorName, payload.errorMessage);
2219
+ throw new AirServiceError("UNKNOWN_ERROR", "Unknown error occurred");
2591
2220
  }
2592
2221
  /**
2593
2222
  * @experimental This method is experimental and will change in the future.
@@ -2598,7 +2227,7 @@ class AirService {
2598
2227
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2599
2228
  try {
2600
2229
  log.info("deploySmartAccount");
2601
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendDeploySmartAccountRequest();
2230
+ const { payload } = await AirMessageService$1.sendDeploySmartAccountRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2602
2231
  if (payload.success === false) {
2603
2232
  throw new AirServiceError(payload.errorName, payload.errorMessage);
2604
2233
  }
@@ -2617,9 +2246,7 @@ class AirService {
2617
2246
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2618
2247
  try {
2619
2248
  log.info("grantPermission", policies);
2620
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendGrantPermissionsRequest({
2621
- policies,
2622
- });
2249
+ const { payload } = await AirMessageService$1.sendGrantPermissionsRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, { policies });
2623
2250
  if (payload.success === false) {
2624
2251
  throw new AirServiceError(payload.errorName, payload.errorMessage);
2625
2252
  }
@@ -2637,7 +2264,7 @@ class AirService {
2637
2264
  throw new Error("Service is not initialized");
2638
2265
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2639
2266
  try {
2640
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendListAllSessionKeyScopesRequest();
2267
+ const { payload } = await AirMessageService$1.sendListAllSessionKeyScopesRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2641
2268
  if (payload.success === false) {
2642
2269
  throw new AirServiceError(payload.errorName, payload.errorMessage);
2643
2270
  }
@@ -2656,7 +2283,7 @@ class AirService {
2656
2283
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2657
2284
  try {
2658
2285
  log.info("executeAction", params);
2659
- const txHash = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendExecuteActionRequest(params);
2286
+ const txHash = await AirMessageService$1.sendExecuteActionRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, params);
2660
2287
  return txHash;
2661
2288
  }
2662
2289
  catch (error) {
@@ -2672,7 +2299,7 @@ class AirService {
2672
2299
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2673
2300
  try {
2674
2301
  log.info("revokePermission", permissionId);
2675
- const txHash = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendRevokePermissionsRequest(permissionId);
2302
+ const txHash = await AirMessageService$1.sendRevokePermissionsRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, permissionId);
2676
2303
  return txHash;
2677
2304
  }
2678
2305
  catch (error) {
@@ -2687,7 +2314,7 @@ class AirService {
2687
2314
  throw new Error("Service is not initialized");
2688
2315
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2689
2316
  try {
2690
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendIsSmartAccountDeployedRequest();
2317
+ const { payload } = await AirMessageService$1.sendIsSmartAccountDeployedRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2691
2318
  if (payload.success === false) {
2692
2319
  throw new AirServiceError(payload.errorName, payload.errorMessage);
2693
2320
  }
@@ -2705,18 +2332,14 @@ class AirService {
2705
2332
  }
2706
2333
  async setupOrUpdateMfa() {
2707
2334
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this, { skipWalletLogin: true });
2708
- const result = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendSetupMfaRequest();
2335
+ const result = await AirMessageService$1.sendSetupMfaRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2709
2336
  if (result.payload.success === false) {
2710
2337
  throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2711
2338
  }
2712
- __classPrivateFieldSet(this, _AirService_loginResult, {
2713
- ...__classPrivateFieldGet(this, _AirService_loginResult, "f"),
2714
- isMFASetup: true,
2715
- }, "f");
2716
2339
  }
2717
2340
  async claimAirId(options) {
2718
2341
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2719
- const result = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendClaimIdRequest(options ?? {});
2342
+ const result = await AirMessageService$1.sendClaimIdRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, options ?? {});
2720
2343
  if (result.payload.success === true) {
2721
2344
  return { airId: result.payload.airId };
2722
2345
  }
@@ -2725,7 +2348,7 @@ class AirService {
2725
2348
  async getUserInfo() {
2726
2349
  if (!this.isLoggedIn)
2727
2350
  throw new Error("User not logged in");
2728
- const info = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerUserInfoRequest();
2351
+ const info = await AirMessageService$1.sendPartnerUserInfoRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
2729
2352
  if (info.payload.success === false) {
2730
2353
  throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
2731
2354
  }
@@ -2746,7 +2369,7 @@ class AirService {
2746
2369
  throw new Error("Service is not initialized");
2747
2370
  if (!this.isLoggedIn)
2748
2371
  throw new Error("No active session to generate token");
2749
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCrossPartnerTokenRequest(partnerUrl);
2372
+ const result = await AirMessageService$1.sendCrossPartnerTokenRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement, partnerUrl);
2750
2373
  if (result.payload.success === false) {
2751
2374
  throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2752
2375
  }
@@ -2754,20 +2377,6 @@ class AirService {
2754
2377
  urlWithToken: result.payload.urlWithToken,
2755
2378
  };
2756
2379
  }
2757
- async getAccessToken() {
2758
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2759
- throw new Error("Service is not initialized");
2760
- if (!this.isLoggedIn)
2761
- throw new Error("No active session to get partner access token");
2762
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerAccessTokenRequest();
2763
- if (result.payload.success !== true) {
2764
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2765
- }
2766
- if (!result.payload.partnerAccessToken) {
2767
- throw new Error("Partner access token not found in response");
2768
- }
2769
- return { token: result.payload.partnerAccessToken };
2770
- }
2771
2380
  async logout() {
2772
2381
  if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2773
2382
  throw new Error("Service is not initialized");
@@ -2775,7 +2384,7 @@ class AirService {
2775
2384
  throw new Error("No active session to logout");
2776
2385
  // Clear up wallet
2777
2386
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2778
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").logout();
2387
+ await AirMessageService$1.logoutAuth(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
2779
2388
  __classPrivateFieldSet(this, _AirService_loginResult, undefined, "f");
2780
2389
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
2781
2390
  }
@@ -2795,8 +2404,22 @@ class AirService {
2795
2404
  clearEventListeners() {
2796
2405
  __classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
2797
2406
  }
2407
+ async getPartnerAccessToken() {
2408
+ if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2409
+ throw new Error("Service is not initialized");
2410
+ if (!this.isLoggedIn)
2411
+ throw new Error("No active session to get partner access token");
2412
+ const result = await AirMessageService$1.sendGetPartnerAccessTokenRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
2413
+ if (result.payload.success === false) {
2414
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2415
+ }
2416
+ if (!result.payload.partnerAccessToken) {
2417
+ throw new Error("Partner access token not found in response");
2418
+ }
2419
+ return result.payload.partnerAccessToken;
2420
+ }
2798
2421
  }
2799
- _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletMessagingService = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
2422
+ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
2800
2423
  if (!this.isInitialized)
2801
2424
  throw new Error("Service not initialized");
2802
2425
  if (!this.isLoggedIn && !option?.skipWalletLogin)
@@ -2818,7 +2441,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2818
2441
  }
2819
2442
  if (__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"))
2820
2443
  return __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f");
2821
- const walletLoginResult = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendLoginRequest();
2444
+ const walletLoginResult = await AirMessageService$1.sendWalletLoginRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2822
2445
  if (walletLoginResult.payload.success !== true) {
2823
2446
  throw new AirServiceError(walletLoginResult.payload.errorName, walletLoginResult.payload.errorMessage);
2824
2447
  }
@@ -2829,17 +2452,20 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2829
2452
  const { walletUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
2830
2453
  log.info(walletUrl, "url loaded");
2831
2454
  const walletIframeOrigin = new URL(walletUrl).origin;
2455
+ await AirMessageService$1.openWalletObservables({ walletIframeOrigin });
2832
2456
  try {
2833
- const walletInitRequestPromise = new Promise((resolve, reject) => {
2834
- const handleWalletMessage = async (ev) => {
2457
+ __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
2458
+ __classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
2459
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToWalletEvents).call(this);
2460
+ await new Promise((resolve, reject) => {
2461
+ const handleAuthMessage = async (ev) => {
2835
2462
  if (ev.origin !== walletIframeOrigin)
2836
2463
  return;
2837
- if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
2838
- window.removeEventListener("message", handleWalletMessage);
2839
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendInitializationRequest({
2464
+ if (ev.data === AirMessageTypes.SERVICE_STARTED) {
2465
+ window.removeEventListener("message", handleAuthMessage);
2466
+ const { payload } = await AirMessageService$1.sendWalletInitializationRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, {
2840
2467
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
2841
2468
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
2842
- sdkVersion: airKitVersion,
2843
2469
  });
2844
2470
  if (payload.success === true) {
2845
2471
  resolve();
@@ -2849,18 +2475,11 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2849
2475
  }
2850
2476
  }
2851
2477
  };
2852
- window.addEventListener("message", handleWalletMessage);
2478
+ window.addEventListener("message", handleAuthMessage);
2853
2479
  });
2854
- __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
2855
- __classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
2856
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2857
- __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToWalletEvents).call(this);
2858
- await __classPrivateFieldGet(this, _AirService_airWalletProvider, "f").startEventMessageListening(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
2859
- const walletInitPromise = __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").onInitialized();
2860
- await walletInitRequestPromise;
2861
- const channel = new MessageChannel();
2862
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initWalletCommunication(channel.port1);
2863
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").initAuthCommunication(option?.skipWalletLogin ?? false, channel.port2);
2480
+ __classPrivateFieldGet(this, _AirService_airWalletProvider, "f").startEventMessageListening();
2481
+ const walletInitPromise = AirMessageService$1.onWalletInitialized();
2482
+ AirMessageService$1.setupIframeCommunication(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement, __classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, option?.skipWalletLogin ?? false);
2864
2483
  const walletInitResult = await walletInitPromise;
2865
2484
  if (walletInitResult.payload.success !== true) {
2866
2485
  throw new AirServiceError(walletInitResult.payload.errorName, walletInitResult.payload.errorMessage);
@@ -2877,43 +2496,37 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2877
2496
  throw error;
2878
2497
  }
2879
2498
  }, _AirService_subscribeToWalletEvents = function _AirService_subscribeToWalletEvents() {
2880
- __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").messages$.subscribe(async (msg) => {
2499
+ AirMessageService$1.messages$.subscribe(async (msg) => {
2881
2500
  switch (msg.type) {
2882
- case AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
2501
+ case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
2883
2502
  const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
2884
2503
  walletIframeController.setIframeVisibility(msg.payload.visible);
2885
2504
  walletIframeController.updateIframeState();
2886
2505
  break;
2887
2506
  }
2888
- case AirWalletMessageTypes.WALLET_LOGIN_RESPONSE: {
2507
+ case AirMessageTypes.WALLET_LOGIN_RESPONSE: {
2889
2508
  if (msg.payload.success === true && !__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f")) {
2890
2509
  __classPrivateFieldSet(this, _AirService_walletLoggedInResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, msg.payload), "f");
2891
2510
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"));
2892
2511
  }
2893
2512
  break;
2894
2513
  }
2895
- case AirWalletMessageTypes.OPEN_WINDOW_REQUEST: {
2514
+ case AirMessageTypes.OPEN_WINDOW_REQUEST: {
2896
2515
  try {
2897
- const onRetry = async () => {
2898
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendOpenWindowRetryRequest(msg.payload.windowId);
2899
- if (payload.success === false) {
2900
- throw new AirServiceError(payload.errorName, payload.errorMessage);
2901
- }
2902
- };
2903
- const { windowController, port } = await WindowService$1.openAndInitializeWalletServiceWindow({
2516
+ const channel = new MessageChannel();
2517
+ const windowController = await WindowService$1.openAndInitializeWalletServiceWindow({
2904
2518
  url: msg.payload.url,
2905
2519
  windowId: msg.payload.windowId,
2906
2520
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
2907
2521
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
2908
- sdkVersion: airKitVersion,
2909
- onRetry,
2522
+ port: channel.port1,
2910
2523
  });
2911
- windowController.onClose(async () => await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendWindowClosed(msg.payload.windowId));
2912
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendOpenWindowSuccessResponse(msg.payload.windowId, port);
2524
+ windowController.onClose(() => AirMessageService$1.sendWindowClosed(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId));
2525
+ AirMessageService$1.sendOpenWindowSuccessResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, channel.port2);
2913
2526
  }
2914
2527
  catch (err) {
2915
2528
  const error = ensureError(err);
2916
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendOpenWindowErrorResponse(msg.payload.windowId, error);
2529
+ AirMessageService$1.sendOpenWindowErrorResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, error);
2917
2530
  }
2918
2531
  break;
2919
2532
  }
@@ -2958,7 +2571,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2958
2571
  };
2959
2572
  }, _AirService_cleanUpAuth = async function _AirService_cleanUpAuth() {
2960
2573
  // Logout auth session
2961
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").logout();
2574
+ await AirMessageService$1.logoutAuth(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
2962
2575
  // Destroy the auth iframe
2963
2576
  const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
2964
2577
  if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
@@ -2966,7 +2579,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2966
2579
  __classPrivateFieldSet(this, _AirService_authIframeController, undefined, "f");
2967
2580
  }
2968
2581
  // Close the message service
2969
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").close();
2582
+ AirMessageService$1.closeAuthObservables();
2970
2583
  __classPrivateFieldSet(this, _AirService_isAuthInitialized, false, "f");
2971
2584
  }, _AirService_cleanUpWallet = async function _AirService_cleanUpWallet() {
2972
2585
  if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
@@ -2974,18 +2587,18 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2974
2587
  // Logout wallet and destroy the wallet iframe
2975
2588
  const walletIframeElement = __classPrivateFieldGet(this, _AirService_walletIframeController, "f")?.iframeElement;
2976
2589
  if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
2977
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").logout();
2590
+ await AirMessageService$1.logoutWallet(walletIframeElement);
2978
2591
  __classPrivateFieldGet(this, _AirService_walletIframeController, "f").destroy();
2979
2592
  __classPrivateFieldSet(this, _AirService_walletIframeController, undefined, "f");
2980
2593
  }
2981
2594
  const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
2982
2595
  if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
2983
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetWalletCommunication();
2596
+ AirMessageService$1.sendResetAuthServiceWalletCommunication(authIframeElement);
2984
2597
  }
2985
2598
  // Close the message service
2986
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").close();
2599
+ AirMessageService$1.closeAirObservables();
2987
2600
  __classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined, "f");
2988
2601
  __classPrivateFieldSet(this, _AirService_walletInitialization, undefined, "f");
2989
2602
  };
2990
2603
 
2991
- export { AirService, AirServiceError, BUILD_ENV, ChainDisconnectedError, InternalRpcError, InvalidParamsRpcError, InvalidRequestRpcError, MethodNotFoundRpcError, ProviderDisconnectedError, ProviderRpcError, SwitchChainError, TransactionRejectedRpcError, UnauthorizedProviderError, UnsupportedProviderMethodError, UserRejectedRequestError, ensureProviderRpcError };
2604
+ export { AirService, AirServiceError, BUILD_ENV, ChainDisconnectedError, InternalRpcError, InvalidParamsRpcError, InvalidRequestRpcError, MethodNotFoundRpcError, ProviderDisconnectedError, SwitchChainError, UnauthorizedProviderError, UnsupportedProviderMethodError, UserRejectedRequestError, ensureProviderRpcError };