mixi2-js 1.2.1 → 1.3.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.
@@ -1,186 +0,0 @@
1
- import "../chunk-4NKIICB5.js";
2
-
3
- // src/helpers/address.ts
4
- var tokenUrl = "https://application-auth.mixi.social/oauth2/token";
5
- var apiAddress = "application-api.mixi.social";
6
- var streamAddress = "application-stream.mixi.social";
7
-
8
- // src/helpers/event-router.ts
9
- var EventRouter = class {
10
- listeners = /* @__PURE__ */ new Map();
11
- /**
12
- * 指定したイベントタイプのハンドラを登録する。
13
- * 同じイベントタイプに複数のハンドラを登録可能(登録順に実行)。
14
- */
15
- on(eventType, listener) {
16
- const existing = this.listeners.get(eventType);
17
- if (existing) {
18
- existing.push(listener);
19
- } else {
20
- this.listeners.set(eventType, [listener]);
21
- }
22
- return this;
23
- }
24
- /**
25
- * 指定したイベントタイプのハンドラを削除する。
26
- * listener を省略した場合、そのイベントタイプのすべてのハンドラを削除する。
27
- */
28
- off(eventType, listener) {
29
- if (!listener) {
30
- this.listeners.delete(eventType);
31
- return this;
32
- }
33
- const existing = this.listeners.get(eventType);
34
- if (existing) {
35
- const filtered = existing.filter((l) => l !== listener);
36
- if (filtered.length > 0) {
37
- this.listeners.set(eventType, filtered);
38
- } else {
39
- this.listeners.delete(eventType);
40
- }
41
- }
42
- return this;
43
- }
44
- /**
45
- * EventHandler.handle() の実装。
46
- * 登録されたリスナーに対してイベントをルーティングする。
47
- */
48
- async handle(event) {
49
- const listeners = this.listeners.get(event.eventType);
50
- if (!listeners) return;
51
- for (const listener of listeners) {
52
- await listener(event);
53
- }
54
- }
55
- };
56
-
57
- // src/helpers/media-uploader.ts
58
- var MediaUploader = class {
59
- client;
60
- pollInterval;
61
- timeout;
62
- constructor(client, options) {
63
- this.client = client;
64
- this.pollInterval = options?.pollInterval ?? 1e3;
65
- this.timeout = options?.timeout ?? 6e4;
66
- }
67
- /**
68
- * メディアアップロードを開始し、uploadUrl と mediaId を返す。
69
- */
70
- async initiate(request) {
71
- const response = await this.client.initiatePostMediaUpload(request);
72
- return {
73
- mediaId: response.mediaId,
74
- uploadUrl: response.uploadUrl
75
- };
76
- }
77
- /**
78
- * メディアの処理が完了するまでポーリングして待機する。
79
- * 完了時に mediaId を返す。失敗時はエラーをスローする。
80
- */
81
- async waitForReady(mediaId) {
82
- const startTime = Date.now();
83
- while (Date.now() - startTime < this.timeout) {
84
- const status = await this.client.getPostMediaStatus(mediaId);
85
- if (status.status === 3 /* COMPLETED */) {
86
- return mediaId;
87
- }
88
- if (status.status === 4 /* FAILED */) {
89
- throw new Error(`Media upload failed: ${mediaId}`);
90
- }
91
- await new Promise((resolve) => setTimeout(resolve, this.pollInterval));
92
- }
93
- throw new Error(
94
- `Media upload timed out after ${this.timeout}ms: ${mediaId}`
95
- );
96
- }
97
- };
98
-
99
- // src/helpers/post-builder.ts
100
- var PostBuilder = class {
101
- request;
102
- constructor(text) {
103
- this.request = { text };
104
- }
105
- /** 返信先ポスト ID を設定する。 */
106
- reply(postId) {
107
- this.request.inReplyToPostId = postId;
108
- this.request.quotedPostId = void 0;
109
- return this;
110
- }
111
- /** 引用対象ポスト ID を設定する。 */
112
- quote(postId) {
113
- this.request.quotedPostId = postId;
114
- this.request.inReplyToPostId = void 0;
115
- return this;
116
- }
117
- /** 添付メディア ID を設定する(最大 4 件)。 */
118
- media(mediaIdList) {
119
- this.request.mediaIdList = mediaIdList;
120
- return this;
121
- }
122
- /** センシティブマスクを設定する。 */
123
- sensitive(caption = "") {
124
- this.request.postMask = {
125
- maskType: 1 /* SENSITIVE */,
126
- caption
127
- };
128
- return this;
129
- }
130
- /** ネタバレマスクを設定する。 */
131
- spoiler(caption = "") {
132
- this.request.postMask = {
133
- maskType: 2 /* SPOILER */,
134
- caption
135
- };
136
- return this;
137
- }
138
- /** カスタムマスクを設定する。 */
139
- mask(postMask) {
140
- this.request.postMask = postMask;
141
- return this;
142
- }
143
- /** 配信設定を設定する。 */
144
- publishing(type) {
145
- this.request.publishingType = type;
146
- return this;
147
- }
148
- /** CreatePostRequest オブジェクトを構築する。 */
149
- build() {
150
- return { ...this.request };
151
- }
152
- };
153
-
154
- // src/helpers/reason-filter.ts
155
- var ReasonFilter = class {
156
- inner;
157
- allowedReasons;
158
- constructor(handler, reasons) {
159
- this.inner = handler;
160
- this.allowedReasons = new Set(reasons);
161
- }
162
- async handle(event) {
163
- const reasons = this.getReasons(event);
164
- if (reasons.length === 0 || reasons.some((r) => this.allowedReasons.has(r))) {
165
- await this.inner.handle(event);
166
- }
167
- }
168
- getReasons(event) {
169
- if (event.postCreatedEvent) {
170
- return event.postCreatedEvent.eventReasonList || [];
171
- }
172
- if (event.chatMessageReceivedEvent) {
173
- return event.chatMessageReceivedEvent.eventReasonList || [];
174
- }
175
- return [];
176
- }
177
- };
178
- export {
179
- EventRouter,
180
- MediaUploader,
181
- PostBuilder,
182
- ReasonFilter,
183
- apiAddress,
184
- streamAddress,
185
- tokenUrl
186
- };
package/dist/index.d.ts DELETED
@@ -1,46 +0,0 @@
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
- import http from 'http';
4
-
5
- interface WebhookServerOptions {
6
- port?: number;
7
- publicKey: Buffer;
8
- handler: EventHandler;
9
- syncHandling?: boolean;
10
- }
11
- declare class WebhookServer {
12
- private readonly server;
13
- private readonly port;
14
- private readonly publicKey;
15
- private readonly handler;
16
- private readonly syncHandling;
17
- constructor(options: WebhookServerOptions);
18
- private requestListener;
19
- private handleEvent;
20
- start(): Promise<void>;
21
- shutdown(): Promise<void>;
22
- get address(): string;
23
- get httpServer(): http.Server;
24
- get eventHandlerFunc(): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
25
- }
26
-
27
- interface StreamWatcherOptions {
28
- streamAddress: string;
29
- authenticator: Authenticator;
30
- authKey?: string;
31
- }
32
- declare class StreamWatcher {
33
- private readonly authenticator;
34
- private readonly authKey?;
35
- private readonly streamClient;
36
- private aborted;
37
- constructor(options: StreamWatcherOptions);
38
- private getMetadata;
39
- private connect;
40
- private reconnect;
41
- watch(handler: EventHandler): Promise<void>;
42
- private handleEvent;
43
- stop(): void;
44
- }
45
-
46
- export { Authenticator, EventHandler, StreamWatcher, type StreamWatcherOptions, WebhookServer, type WebhookServerOptions };