@konemono/nostr-login 1.15.2 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.15.2",
3
+ "version": "1.15.3",
4
4
  "description": "Extended fork of nostr-login with multi-relay support, QR scanner, and improved stability",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "tseep": "^1.2.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@konemono/nostr-login-components": "^1.4.2",
30
+ "@konemono/nostr-login-components": "^1.4.3",
31
31
  "@rollup/plugin-commonjs": "^25.0.7",
32
32
  "@rollup/plugin-node-resolve": "^15.2.3",
33
33
  "@rollup/plugin-terser": "^0.4.4",
package/src/index.ts CHANGED
@@ -305,6 +305,10 @@ export class NostrLoginInitializer {
305
305
  this.modalManager.onDarkMode(dark);
306
306
  };
307
307
 
308
+ public setBannerVisible = (visible: boolean) => {
309
+ this.bannerManager.setBannerVisible(visible);
310
+ };
311
+
308
312
  public setAuth = async (o: NostrLoginAuthOptions) => {
309
313
  if (!o.type) throw new Error('Invalid auth event');
310
314
  if (o.type !== 'login' && o.type !== 'logout' && o.type !== 'signup') throw new Error('Invalid auth event');
@@ -335,7 +339,7 @@ export class NostrLoginInitializer {
335
339
 
336
340
  const initializer = new NostrLoginInitializer();
337
341
 
338
- export const { init, launch, logout, setDarkMode, setAuth, cancelNeedAuth } = initializer;
342
+ export const { init, launch, logout, setDarkMode, setBannerVisible, setAuth, cancelNeedAuth } = initializer;
339
343
 
340
344
  document.addEventListener('nlLogout', logout);
341
345
  document.addEventListener('nlLaunch', (event: any) => {
@@ -81,6 +81,18 @@ class BannerManager extends EventEmitter {
81
81
  if (this.banner) this.banner.darkMode = dark;
82
82
  }
83
83
 
84
+ public setBannerVisible(visible: boolean) {
85
+ if (this.banner) {
86
+ if (visible) {
87
+ this.banner.removeAttribute('hidden-mode');
88
+ (this.banner as any).hiddenMode = false;
89
+ } else {
90
+ this.banner.setAttribute('hidden-mode', 'true');
91
+ (this.banner as any).hiddenMode = true;
92
+ }
93
+ }
94
+ }
95
+
84
96
  public launchAuthBanner(opt: NostrLoginOptions) {
85
97
  this.banner = document.createElement('nl-banner');
86
98
 
@@ -88,6 +100,7 @@ class BannerManager extends EventEmitter {
88
100
 
89
101
  if (opt.theme) this.banner.setAttribute('theme', opt.theme);
90
102
  if (opt.noBanner) this.banner.setAttribute('hidden-mode', 'true');
103
+ if (opt.bannerPosition) this.banner.setAttribute('banner-position', opt.bannerPosition);
91
104
 
92
105
  this.banner.addEventListener('nlLoginBanner', (event: any) => {
93
106
  this.emit('launch', event.detail);
@@ -37,7 +37,7 @@ export class RelayHealthManager {
37
37
  }
38
38
  }
39
39
 
40
- await this.ctx.pool.waitForConnection(8000);
40
+ await this.ctx.pool.waitForConnection(5000);
41
41
  this.ensureSubscription();
42
42
  }
43
43
 
@@ -62,7 +62,7 @@ export class RelayHealthManager {
62
62
  }
63
63
  }
64
64
 
65
- await this.ctx.pool.waitForConnection(8000);
65
+ await this.ctx.pool.waitForConnection(5000);
66
66
  this.ensureSubscription();
67
67
  } else if (!isSubActive) {
68
68
  console.log('ensureRelayConnection: relay connected but subscription dead, resubscribing...');
@@ -28,8 +28,8 @@ export class RelayPool {
28
28
  verifier,
29
29
  connectionStrategy: 'lazy-keep',
30
30
  retry: { strategy: 'exponential', maxCount: 5, initialDelay: 1000 },
31
- eoseTimeout: 10000,
32
- okTimeout: 10000,
31
+ eoseTimeout: 5000,
32
+ okTimeout: 5000,
33
33
  skipFetchNip11: true,
34
34
  });
35
35
  this._owned = true;
@@ -77,7 +77,7 @@ export class RelayPool {
77
77
  * 互換のため明示的に接続状態を待機する。
78
78
  * createConnectionStateObservable() でリアクティブに接続完了を検知する。
79
79
  */
80
- async connect(timeoutMs = 10000): Promise<void> {
80
+ async connect(timeoutMs = 5000): Promise<void> {
81
81
  this._syncRelays();
82
82
  if (this.isAnyConnected()) return;
83
83
 
@@ -2,6 +2,14 @@
2
2
 
3
3
  export type Nip46ErrorCode = 'TIMEOUT' | 'RELAY_DISCONNECTED' | 'SIGNER_REJECTED' | 'CANCELLED' | 'UNKNOWN';
4
4
 
5
+ const USER_MESSAGES: Record<Nip46ErrorCode, string> = {
6
+ TIMEOUT: 'No response from signer. Please check your key storage app.',
7
+ RELAY_DISCONNECTED: 'Cannot connect to relay. Please check your relay settings.',
8
+ SIGNER_REJECTED: 'The request was rejected by the signer.',
9
+ CANCELLED: 'The operation was cancelled.',
10
+ UNKNOWN: 'An unknown error occurred.',
11
+ };
12
+
5
13
  export class Nip46Error extends Error {
6
14
  public code: Nip46ErrorCode;
7
15
  constructor(message: string, code: Nip46ErrorCode) {
@@ -12,4 +20,10 @@ export class Nip46Error extends Error {
12
20
  get retryable() {
13
21
  return this.code === 'TIMEOUT' || this.code === 'RELAY_DISCONNECTED';
14
22
  }
23
+ get userMessage(): string {
24
+ return USER_MESSAGES[this.code] || USER_MESSAGES.UNKNOWN;
25
+ }
26
+ toString(): string {
27
+ return this.userMessage;
28
+ }
15
29
  }
package/src/types.ts CHANGED
@@ -40,6 +40,9 @@ export interface NostrLoginOptions {
40
40
  // do not show the banner, modals must be `launch`-ed
41
41
  noBanner?: boolean;
42
42
 
43
+ // banner vertical position: 'top', 'center', 'bottom' (default: 'center')
44
+ bannerPosition?: 'top' | 'center' | 'bottom';
45
+
43
46
  // forward reqs to this bunker origin for testing
44
47
  devOverrideBunkerOrigin?: string;
45
48