@konemono/nostr-login 1.7.22 → 1.7.23

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.
@@ -23,29 +23,9 @@ class ProcessManager extends EventEmitter {
23
23
 
24
24
  public async wait<T>(cb: () => Promise<T>): Promise<T> {
25
25
  // FIXME only allow 1 parallel req
26
- console.log('ProcessManager.wait called, callTimer exists:', !!this.callTimer, 'callCount:', this.callCount);
27
-
28
- let timeoutReject: ((reason?: any) => void) | undefined;
29
- let isTimedOut = false;
30
- let localTimer: NodeJS.Timeout | undefined;
31
-
32
- const timeoutPromise = new Promise<T>((_, reject) => {
33
- timeoutReject = reject;
34
- });
35
26
 
36
27
  if (!this.callTimer) {
37
- console.log('Setting up timeout timer for', CALL_TIMEOUT, 'ms');
38
- localTimer = setTimeout(() => {
39
- console.log('ProcessManager: timeout reached, emitting onCallTimeout');
40
- isTimedOut = true;
41
- this.emit('onCallTimeout');
42
- if (timeoutReject) {
43
- timeoutReject(new Error('[ProcessManager] Request timed out'));
44
- }
45
- }, CALL_TIMEOUT);
46
- this.callTimer = localTimer;
47
- } else {
48
- console.log('Timer already exists, not setting up new one');
28
+ this.callTimer = setTimeout(() => this.emit('onCallTimeout'), CALL_TIMEOUT);
49
29
  }
50
30
 
51
31
  if (!this.callCount) {
@@ -56,45 +36,23 @@ class ProcessManager extends EventEmitter {
56
36
 
57
37
  let error;
58
38
  let result;
59
- let raceFinished = false;
60
39
 
61
40
  try {
62
- result = await Promise.race([
63
- cb().then(r => {
64
- if (!raceFinished) {
65
- raceFinished = true;
66
- return r;
67
- }
68
- // Race already finished (timed out), ignore this result
69
- console.log('ProcessManager: ignoring late result after timeout');
70
- throw new Error('Already timed out');
71
- }),
72
- timeoutPromise.then(
73
- () => {
74
- raceFinished = true;
75
- throw new Error('Should not resolve');
76
- },
77
- (err) => {
78
- raceFinished = true;
79
- throw err;
80
- }
81
- )
82
- ]);
41
+ result = await cb();
83
42
  } catch (e) {
84
43
  error = e;
85
44
  }
86
45
 
87
46
  this.callCount--;
88
47
 
89
- // Always emit onCallEnd for cleanup
90
48
  this.emit('onCallEnd');
91
49
 
92
- // Clear the timer if it's the one we created
93
- if (this.callTimer === localTimer) {
50
+ if (this.callTimer) {
94
51
  clearTimeout(this.callTimer);
95
- this.callTimer = undefined;
96
52
  }
97
53
 
54
+ this.callTimer = undefined;
55
+
98
56
  if (error) {
99
57
  throw error;
100
58
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Info, AuthMethod, ConnectionString, RecentType, BannerNotify } from 'nostr-login-components';
1
+ import { Info, AuthMethod, ConnectionString, RecentType, BannerNotify } from 'nostr-login-components/dist/types/types';
2
2
 
3
3
  export interface NostrLoginAuthOptions {
4
4
  localNsec?: string;
@@ -10,7 +10,6 @@ export interface NostrLoginAuthOptions {
10
10
  name?: string;
11
11
  }
12
12
 
13
- // NOTE: must be a subset of CURRENT_MODULE enum
14
13
  export type StartScreens =
15
14
  | 'welcome'
16
15
  | 'welcome-login'
@@ -27,56 +26,27 @@ export type StartScreens =
27
26
  | 'import';
28
27
 
29
28
  export interface NostrLoginOptions {
30
- // optional
31
29
  theme?: string;
32
30
  startScreen?: StartScreens;
33
31
  bunkers?: string;
34
32
  onAuth?: (npub: string, options: NostrLoginAuthOptions) => void;
35
33
  perms?: string;
36
34
  darkMode?: boolean;
37
-
38
- // do not show the banner, modals must be `launch`-ed
39
35
  noBanner?: boolean;
40
-
41
- // forward reqs to this bunker origin for testing
42
36
  devOverrideBunkerOrigin?: string;
43
-
44
- // deprecated, use methods=['local']
45
- // use local signup instead of nostr connect
46
37
  localSignup?: boolean;
47
-
48
- // allowed auth methods
49
38
  methods?: AuthMethod[];
50
-
51
- // otp endpoints
52
39
  otpRequestUrl?: string;
53
40
  otpReplyUrl?: string;
54
-
55
- // welcome screen's title/desc
56
41
  title?: string;
57
42
  description?: string;
58
-
59
- // comma-separated list of relays added
60
- // to relay list of new profiles created with local signup
61
43
  signupRelays?: string;
62
-
63
- // relay list to override hardcoded `OUTBOX_RELAYS` constant
64
44
  outboxRelays?: string[];
65
-
66
- // dev mode
67
45
  dev?: boolean;
68
-
69
- // use start.njump.me instead of local signup
70
46
  signupNstart?: boolean;
71
-
72
- // list of npubs to auto/suggest-follow on signup
73
47
  followNpubs?: string;
74
-
75
- // when method call auth needed, instead of showing
76
- // the modal, we start waiting for incoming nip46
77
- // connection and send the nostrconnect string using
78
- // nlNeedAuth event
79
48
  customNostrConnect?: boolean;
49
+ connectRelays?: string[];
80
50
  }
81
51
 
82
52
  export interface IBanner {
@@ -115,36 +115,22 @@ export const getBunkerUrl = async (value: string, optionsModal: NostrLoginOption
115
115
  const origin = optionsModal.devOverrideBunkerOrigin || `https://${domain}`;
116
116
  const bunkerUrl = `${origin}/.well-known/nostr.json?name=_`;
117
117
  const userUrl = `${origin}/.well-known/nostr.json?name=${name}`;
118
-
119
- // 10 sec timeout for fetch
120
- const controller = new AbortController();
121
- const timeoutId = setTimeout(() => controller.abort(), 10000);
122
-
123
- try {
124
- const bunker = await fetch(bunkerUrl, { signal: controller.signal });
125
- const bunkerData = await bunker.json();
126
- const bunkerPubkey = bunkerData.names['_'];
127
- const bunkerRelays = bunkerData.nip46[bunkerPubkey];
128
- const user = await fetch(userUrl, { signal: controller.signal });
129
- const userData = await user.json();
130
- const userPubkey = userData.names[name];
131
- // console.log({
132
- // bunkerData, userData, bunkerPubkey, bunkerRelays, userPubkey,
133
- // name, domain, origin
134
- // })
135
- if (!bunkerRelays.length) {
136
- throw new Error('Bunker relay not provided');
137
- }
138
-
139
- return `bunker://${userPubkey}?relay=${bunkerRelays[0]}`;
140
- } catch (e: any) {
141
- if (e.name === 'AbortError') {
142
- throw new Error('[getBunkerUrl] Request timed out');
143
- }
144
- throw e;
145
- } finally {
146
- clearTimeout(timeoutId);
118
+ const bunker = await fetch(bunkerUrl);
119
+ const bunkerData = await bunker.json();
120
+ const bunkerPubkey = bunkerData.names['_'];
121
+ const bunkerRelays = bunkerData.nip46[bunkerPubkey];
122
+ const user = await fetch(userUrl);
123
+ const userData = await user.json();
124
+ const userPubkey = userData.names[name];
125
+ // console.log({
126
+ // bunkerData, userData, bunkerPubkey, bunkerRelays, userPubkey,
127
+ // name, domain, origin
128
+ // })
129
+ if (!bunkerRelays.length) {
130
+ throw new Error('Bunker relay not provided');
147
131
  }
132
+
133
+ return `bunker://${userPubkey}?relay=${bunkerRelays[0]}`;
148
134
  }
149
135
 
150
136
  throw new Error('Invalid user name or bunker url');