mixi2-js 1.2.0 → 1.2.1
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/dist/{client-BmF_2lFq.d.cts → client-iXbbRxc-.d.cts} +1 -0
- package/dist/{client-BmF_2lFq.d.ts → client-iXbbRxc-.d.ts} +1 -0
- package/dist/helpers/index.d.cts +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/index.cjs +16 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -10
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ declare class OAuth2Authenticator implements Authenticator {
|
|
|
12
12
|
private readonly tokenUrl;
|
|
13
13
|
private accessToken;
|
|
14
14
|
private expiresAt;
|
|
15
|
+
private refreshPromise;
|
|
15
16
|
constructor(options: AuthenticatorOptions);
|
|
16
17
|
getAccessToken(): Promise<string>;
|
|
17
18
|
private refreshToken;
|
|
@@ -12,6 +12,7 @@ declare class OAuth2Authenticator implements Authenticator {
|
|
|
12
12
|
private readonly tokenUrl;
|
|
13
13
|
private accessToken;
|
|
14
14
|
private expiresAt;
|
|
15
|
+
private refreshPromise;
|
|
15
16
|
constructor(options: AuthenticatorOptions);
|
|
16
17
|
getAccessToken(): Promise<string>;
|
|
17
18
|
private refreshToken;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EventHandler, h as EventType, f as Event, c as Client, I as InitiatePostMediaUploadRequest, v as PostMask, D as PostPublishingType, e as CreatePostRequest, g as EventReason } from '../client-
|
|
1
|
+
import { E as EventHandler, h as EventType, f as Event, c as Client, I as InitiatePostMediaUploadRequest, v as PostMask, D as PostPublishingType, e as CreatePostRequest, g as EventReason } from '../client-iXbbRxc-.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* アクセストークン取得用のエンドポイント URL です。
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EventHandler, h as EventType, f as Event, c as Client, I as InitiatePostMediaUploadRequest, v as PostMask, D as PostPublishingType, e as CreatePostRequest, g as EventReason } from '../client-
|
|
1
|
+
import { E as EventHandler, h as EventType, f as Event, c as Client, I as InitiatePostMediaUploadRequest, v as PostMask, D as PostPublishingType, e as CreatePostRequest, g as EventReason } from '../client-iXbbRxc-.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* アクセストークン取得用のエンドポイント URL です。
|
package/dist/index.cjs
CHANGED
|
@@ -62,6 +62,7 @@ var OAuth2Authenticator = class {
|
|
|
62
62
|
tokenUrl;
|
|
63
63
|
accessToken = null;
|
|
64
64
|
expiresAt = null;
|
|
65
|
+
refreshPromise = null;
|
|
65
66
|
constructor(options) {
|
|
66
67
|
this.clientId = options.clientId;
|
|
67
68
|
this.clientSecret = options.clientSecret;
|
|
@@ -71,7 +72,12 @@ var OAuth2Authenticator = class {
|
|
|
71
72
|
if (this.accessToken && this.expiresAt && Date.now() < this.expiresAt) {
|
|
72
73
|
return this.accessToken;
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
if (!this.refreshPromise) {
|
|
76
|
+
this.refreshPromise = this.refreshToken().finally(() => {
|
|
77
|
+
this.refreshPromise = null;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
await this.refreshPromise;
|
|
75
81
|
return this.accessToken;
|
|
76
82
|
}
|
|
77
83
|
async refreshToken() {
|
|
@@ -574,10 +580,8 @@ var WebhookServer = class {
|
|
|
574
580
|
res.end("missing x-mixi2-application-event-signature");
|
|
575
581
|
return;
|
|
576
582
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
signature = Buffer.from(signatureBase64, "base64");
|
|
580
|
-
} catch {
|
|
583
|
+
const signature = Buffer.from(signatureBase64, "base64");
|
|
584
|
+
if (signature.length === 0) {
|
|
581
585
|
res.writeHead(401);
|
|
582
586
|
res.end("x-mixi2-application-event-signature is invalid");
|
|
583
587
|
return;
|
|
@@ -754,7 +758,10 @@ var StreamWatcher = class {
|
|
|
754
758
|
this.handleEvent(handler, event);
|
|
755
759
|
}
|
|
756
760
|
});
|
|
757
|
-
|
|
761
|
+
let disconnected = false;
|
|
762
|
+
const handleDisconnect = async () => {
|
|
763
|
+
if (disconnected) return;
|
|
764
|
+
disconnected = true;
|
|
758
765
|
if (this.aborted) {
|
|
759
766
|
resolve();
|
|
760
767
|
return;
|
|
@@ -765,10 +772,9 @@ var StreamWatcher = class {
|
|
|
765
772
|
} catch (reconnectErr) {
|
|
766
773
|
reject(reconnectErr);
|
|
767
774
|
}
|
|
768
|
-
}
|
|
769
|
-
s.on("
|
|
770
|
-
|
|
771
|
-
});
|
|
775
|
+
};
|
|
776
|
+
s.on("error", handleDisconnect);
|
|
777
|
+
s.on("end", handleDisconnect);
|
|
772
778
|
};
|
|
773
779
|
setupStream(stream);
|
|
774
780
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EventHandler, A as Authenticator } from './client-
|
|
2
|
-
export { a as AuthenticatorOptions, C as ChatMessage, b as ChatMessageReceivedEvent, c as Client, d as ClientOptions, e as CreatePostRequest, f as Event, g as EventReason, h as EventType, G as GetPostMediaStatusResponse, i as GetStampsRequest, I as InitiatePostMediaUploadRequest, j as InitiatePostMediaUploadResponse, L as LanguageCode, M as Media, k as MediaImage, l as MediaStamp, m as MediaType, n as MediaUploadStatus, o as MediaUploadType, p as MediaVideo, O as OAuth2Authenticator, q as OfficialStamp, r as OfficialStampSet, P as PingEvent, s as Post, t as PostAccessLevel, u as PostCreatedEvent, v as PostMask, w as PostMaskType, x as PostMedia, y as PostMediaImage, z as PostMediaType, B as PostMediaVideo, D as PostPublishingType, F as PostStamp, H as PostVisibility, S as SendChatMessageRequest, J as StampSetType, U as User, K as UserAccessLevel, N as UserAvatar, Q as UserVisibility } from './client-
|
|
1
|
+
import { E as EventHandler, A as Authenticator } from './client-iXbbRxc-.cjs';
|
|
2
|
+
export { a as AuthenticatorOptions, C as ChatMessage, b as ChatMessageReceivedEvent, c as Client, d as ClientOptions, e as CreatePostRequest, f as Event, g as EventReason, h as EventType, G as GetPostMediaStatusResponse, i as GetStampsRequest, I as InitiatePostMediaUploadRequest, j as InitiatePostMediaUploadResponse, L as LanguageCode, M as Media, k as MediaImage, l as MediaStamp, m as MediaType, n as MediaUploadStatus, o as MediaUploadType, p as MediaVideo, O as OAuth2Authenticator, q as OfficialStamp, r as OfficialStampSet, P as PingEvent, s as Post, t as PostAccessLevel, u as PostCreatedEvent, v as PostMask, w as PostMaskType, x as PostMedia, y as PostMediaImage, z as PostMediaType, B as PostMediaVideo, D as PostPublishingType, F as PostStamp, H as PostVisibility, S as SendChatMessageRequest, J as StampSetType, U as User, K as UserAccessLevel, N as UserAvatar, Q as UserVisibility } from './client-iXbbRxc-.cjs';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
|
|
5
5
|
interface WebhookServerOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EventHandler, A as Authenticator } from './client-
|
|
2
|
-
export { a as AuthenticatorOptions, C as ChatMessage, b as ChatMessageReceivedEvent, c as Client, d as ClientOptions, e as CreatePostRequest, f as Event, g as EventReason, h as EventType, G as GetPostMediaStatusResponse, i as GetStampsRequest, I as InitiatePostMediaUploadRequest, j as InitiatePostMediaUploadResponse, L as LanguageCode, M as Media, k as MediaImage, l as MediaStamp, m as MediaType, n as MediaUploadStatus, o as MediaUploadType, p as MediaVideo, O as OAuth2Authenticator, q as OfficialStamp, r as OfficialStampSet, P as PingEvent, s as Post, t as PostAccessLevel, u as PostCreatedEvent, v as PostMask, w as PostMaskType, x as PostMedia, y as PostMediaImage, z as PostMediaType, B as PostMediaVideo, D as PostPublishingType, F as PostStamp, H as PostVisibility, S as SendChatMessageRequest, J as StampSetType, U as User, K as UserAccessLevel, N as UserAvatar, Q as UserVisibility } from './client-
|
|
1
|
+
import { E as EventHandler, A as Authenticator } from './client-iXbbRxc-.js';
|
|
2
|
+
export { a as AuthenticatorOptions, C as ChatMessage, b as ChatMessageReceivedEvent, c as Client, d as ClientOptions, e as CreatePostRequest, f as Event, g as EventReason, h as EventType, G as GetPostMediaStatusResponse, i as GetStampsRequest, I as InitiatePostMediaUploadRequest, j as InitiatePostMediaUploadResponse, L as LanguageCode, M as Media, k as MediaImage, l as MediaStamp, m as MediaType, n as MediaUploadStatus, o as MediaUploadType, p as MediaVideo, O as OAuth2Authenticator, q as OfficialStamp, r as OfficialStampSet, P as PingEvent, s as Post, t as PostAccessLevel, u as PostCreatedEvent, v as PostMask, w as PostMaskType, x as PostMedia, y as PostMediaImage, z as PostMediaType, B as PostMediaVideo, D as PostPublishingType, F as PostStamp, H as PostVisibility, S as SendChatMessageRequest, J as StampSetType, U as User, K as UserAccessLevel, N as UserAvatar, Q as UserVisibility } from './client-iXbbRxc-.js';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
|
|
5
5
|
interface WebhookServerOptions {
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var OAuth2Authenticator = class {
|
|
|
22
22
|
tokenUrl;
|
|
23
23
|
accessToken = null;
|
|
24
24
|
expiresAt = null;
|
|
25
|
+
refreshPromise = null;
|
|
25
26
|
constructor(options) {
|
|
26
27
|
this.clientId = options.clientId;
|
|
27
28
|
this.clientSecret = options.clientSecret;
|
|
@@ -31,7 +32,12 @@ var OAuth2Authenticator = class {
|
|
|
31
32
|
if (this.accessToken && this.expiresAt && Date.now() < this.expiresAt) {
|
|
32
33
|
return this.accessToken;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
if (!this.refreshPromise) {
|
|
36
|
+
this.refreshPromise = this.refreshToken().finally(() => {
|
|
37
|
+
this.refreshPromise = null;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
await this.refreshPromise;
|
|
35
41
|
return this.accessToken;
|
|
36
42
|
}
|
|
37
43
|
async refreshToken() {
|
|
@@ -443,10 +449,8 @@ var WebhookServer = class {
|
|
|
443
449
|
res.end("missing x-mixi2-application-event-signature");
|
|
444
450
|
return;
|
|
445
451
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
signature = Buffer.from(signatureBase64, "base64");
|
|
449
|
-
} catch {
|
|
452
|
+
const signature = Buffer.from(signatureBase64, "base64");
|
|
453
|
+
if (signature.length === 0) {
|
|
450
454
|
res.writeHead(401);
|
|
451
455
|
res.end("x-mixi2-application-event-signature is invalid");
|
|
452
456
|
return;
|
|
@@ -623,7 +627,10 @@ var StreamWatcher = class {
|
|
|
623
627
|
this.handleEvent(handler, event);
|
|
624
628
|
}
|
|
625
629
|
});
|
|
626
|
-
|
|
630
|
+
let disconnected = false;
|
|
631
|
+
const handleDisconnect = async () => {
|
|
632
|
+
if (disconnected) return;
|
|
633
|
+
disconnected = true;
|
|
627
634
|
if (this.aborted) {
|
|
628
635
|
resolve();
|
|
629
636
|
return;
|
|
@@ -634,10 +641,9 @@ var StreamWatcher = class {
|
|
|
634
641
|
} catch (reconnectErr) {
|
|
635
642
|
reject(reconnectErr);
|
|
636
643
|
}
|
|
637
|
-
}
|
|
638
|
-
s.on("
|
|
639
|
-
|
|
640
|
-
});
|
|
644
|
+
};
|
|
645
|
+
s.on("error", handleDisconnect);
|
|
646
|
+
s.on("end", handleDisconnect);
|
|
641
647
|
};
|
|
642
648
|
setupStream(stream);
|
|
643
649
|
});
|