@mst-mkt/mixi2-application-sdk-ts 0.1.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.
Files changed (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +131 -0
  3. package/dist/auth/authenticator.d.ts +8 -0
  4. package/dist/auth/authenticator.d.ts.map +1 -0
  5. package/dist/auth/authenticator.js +44 -0
  6. package/dist/auth/authenticator.js.map +1 -0
  7. package/dist/auth/index.d.ts +4 -0
  8. package/dist/auth/index.js +3 -0
  9. package/dist/auth/interceptor.d.ts +8 -0
  10. package/dist/auth/interceptor.d.ts.map +1 -0
  11. package/dist/auth/interceptor.js +13 -0
  12. package/dist/auth/interceptor.js.map +1 -0
  13. package/dist/auth/types.d.ts +15 -0
  14. package/dist/auth/types.d.ts.map +1 -0
  15. package/dist/client/index.d.ts +13 -0
  16. package/dist/client/index.d.ts.map +1 -0
  17. package/dist/client/index.js +11 -0
  18. package/dist/client/index.js.map +1 -0
  19. package/dist/event/index.d.ts +2 -0
  20. package/dist/event/index.js +0 -0
  21. package/dist/event/stream/backoff.js +12 -0
  22. package/dist/event/stream/backoff.js.map +1 -0
  23. package/dist/event/stream/index.d.ts +2 -0
  24. package/dist/event/stream/index.js +2 -0
  25. package/dist/event/stream/watcher.d.ts +17 -0
  26. package/dist/event/stream/watcher.d.ts.map +1 -0
  27. package/dist/event/stream/watcher.js +40 -0
  28. package/dist/event/stream/watcher.js.map +1 -0
  29. package/dist/event/types.d.ts +14 -0
  30. package/dist/event/types.d.ts.map +1 -0
  31. package/dist/event/types.js +13 -0
  32. package/dist/event/types.js.map +1 -0
  33. package/dist/event/webhook/handler.d.ts +13 -0
  34. package/dist/event/webhook/handler.d.ts.map +1 -0
  35. package/dist/event/webhook/handler.js +35 -0
  36. package/dist/event/webhook/handler.js.map +1 -0
  37. package/dist/event/webhook/index.d.ts +2 -0
  38. package/dist/event/webhook/index.js +2 -0
  39. package/dist/event/webhook/verify.js +30 -0
  40. package/dist/event/webhook/verify.js.map +1 -0
  41. package/dist/gen/social/mixi/application/const/v1/event_type_pb.d.ts +78 -0
  42. package/dist/gen/social/mixi/application/const/v1/event_type_pb.d.ts.map +1 -0
  43. package/dist/gen/social/mixi/application/const/v1/event_type_pb.js +42 -0
  44. package/dist/gen/social/mixi/application/const/v1/event_type_pb.js.map +1 -0
  45. package/dist/gen/social/mixi/application/const/v1/language_code_pb.d.ts +29 -0
  46. package/dist/gen/social/mixi/application/const/v1/language_code_pb.d.ts.map +1 -0
  47. package/dist/gen/social/mixi/application/const/v1/language_code_pb.js +10 -0
  48. package/dist/gen/social/mixi/application/const/v1/language_code_pb.js.map +1 -0
  49. package/dist/gen/social/mixi/application/const/v1/media_type_pb.d.ts +29 -0
  50. package/dist/gen/social/mixi/application/const/v1/media_type_pb.d.ts.map +1 -0
  51. package/dist/gen/social/mixi/application/const/v1/media_type_pb.js +10 -0
  52. package/dist/gen/social/mixi/application/const/v1/media_type_pb.js.map +1 -0
  53. package/dist/gen/social/mixi/application/const/v1/post_access_level_pb.d.ts +29 -0
  54. package/dist/gen/social/mixi/application/const/v1/post_access_level_pb.d.ts.map +1 -0
  55. package/dist/gen/social/mixi/application/const/v1/post_access_level_pb.js +10 -0
  56. package/dist/gen/social/mixi/application/const/v1/post_access_level_pb.js.map +1 -0
  57. package/dist/gen/social/mixi/application/const/v1/post_mask_type_pb.d.ts +29 -0
  58. package/dist/gen/social/mixi/application/const/v1/post_mask_type_pb.d.ts.map +1 -0
  59. package/dist/gen/social/mixi/application/const/v1/post_mask_type_pb.js +10 -0
  60. package/dist/gen/social/mixi/application/const/v1/post_mask_type_pb.js.map +1 -0
  61. package/dist/gen/social/mixi/application/const/v1/post_media_type_pb.d.ts +29 -0
  62. package/dist/gen/social/mixi/application/const/v1/post_media_type_pb.d.ts.map +1 -0
  63. package/dist/gen/social/mixi/application/const/v1/post_media_type_pb.js +10 -0
  64. package/dist/gen/social/mixi/application/const/v1/post_media_type_pb.js.map +1 -0
  65. package/dist/gen/social/mixi/application/const/v1/post_publishing_type_pb.d.ts +23 -0
  66. package/dist/gen/social/mixi/application/const/v1/post_publishing_type_pb.d.ts.map +1 -0
  67. package/dist/gen/social/mixi/application/const/v1/post_publishing_type_pb.js +10 -0
  68. package/dist/gen/social/mixi/application/const/v1/post_publishing_type_pb.js.map +1 -0
  69. package/dist/gen/social/mixi/application/const/v1/post_visibility_pb.d.ts +29 -0
  70. package/dist/gen/social/mixi/application/const/v1/post_visibility_pb.d.ts.map +1 -0
  71. package/dist/gen/social/mixi/application/const/v1/post_visibility_pb.js +10 -0
  72. package/dist/gen/social/mixi/application/const/v1/post_visibility_pb.js.map +1 -0
  73. package/dist/gen/social/mixi/application/const/v1/stamp_set_type_pb.d.ts +29 -0
  74. package/dist/gen/social/mixi/application/const/v1/stamp_set_type_pb.d.ts.map +1 -0
  75. package/dist/gen/social/mixi/application/const/v1/stamp_set_type_pb.js +10 -0
  76. package/dist/gen/social/mixi/application/const/v1/stamp_set_type_pb.js.map +1 -0
  77. package/dist/gen/social/mixi/application/const/v1/user_access_level_pb.d.ts +29 -0
  78. package/dist/gen/social/mixi/application/const/v1/user_access_level_pb.d.ts.map +1 -0
  79. package/dist/gen/social/mixi/application/const/v1/user_access_level_pb.js +10 -0
  80. package/dist/gen/social/mixi/application/const/v1/user_access_level_pb.js.map +1 -0
  81. package/dist/gen/social/mixi/application/const/v1/user_visibility_pb.d.ts +29 -0
  82. package/dist/gen/social/mixi/application/const/v1/user_visibility_pb.d.ts.map +1 -0
  83. package/dist/gen/social/mixi/application/const/v1/user_visibility_pb.js +10 -0
  84. package/dist/gen/social/mixi/application/const/v1/user_visibility_pb.js.map +1 -0
  85. package/dist/gen/social/mixi/application/model/v1/event_pb.d.ts +119 -0
  86. package/dist/gen/social/mixi/application/model/v1/event_pb.d.ts.map +1 -0
  87. package/dist/gen/social/mixi/application/model/v1/event_pb.js +19 -0
  88. package/dist/gen/social/mixi/application/model/v1/event_pb.js.map +1 -0
  89. package/dist/gen/social/mixi/application/model/v1/media_pb.d.ts +193 -0
  90. package/dist/gen/social/mixi/application/model/v1/media_pb.d.ts.map +1 -0
  91. package/dist/gen/social/mixi/application/model/v1/media_pb.js +11 -0
  92. package/dist/gen/social/mixi/application/model/v1/media_pb.js.map +1 -0
  93. package/dist/gen/social/mixi/application/model/v1/message_pb.d.ts +58 -0
  94. package/dist/gen/social/mixi/application/model/v1/message_pb.d.ts.map +1 -0
  95. package/dist/gen/social/mixi/application/model/v1/message_pb.js +12 -0
  96. package/dist/gen/social/mixi/application/model/v1/message_pb.js.map +1 -0
  97. package/dist/gen/social/mixi/application/model/v1/post_pb.d.ts +284 -0
  98. package/dist/gen/social/mixi/application/model/v1/post_pb.d.ts.map +1 -0
  99. package/dist/gen/social/mixi/application/model/v1/post_pb.js +23 -0
  100. package/dist/gen/social/mixi/application/model/v1/post_pb.js.map +1 -0
  101. package/dist/gen/social/mixi/application/model/v1/stamp_pb.d.ts +89 -0
  102. package/dist/gen/social/mixi/application/model/v1/stamp_pb.d.ts.map +1 -0
  103. package/dist/gen/social/mixi/application/model/v1/stamp_pb.js +12 -0
  104. package/dist/gen/social/mixi/application/model/v1/stamp_pb.js.map +1 -0
  105. package/dist/gen/social/mixi/application/model/v1/user_pb.d.ts +119 -0
  106. package/dist/gen/social/mixi/application/model/v1/user_pb.d.ts.map +1 -0
  107. package/dist/gen/social/mixi/application/model/v1/user_pb.js +12 -0
  108. package/dist/gen/social/mixi/application/model/v1/user_pb.js.map +1 -0
  109. package/dist/gen/social/mixi/application/service/application_api/v1/service_pb.d.ts +525 -0
  110. package/dist/gen/social/mixi/application/service/application_api/v1/service_pb.d.ts.map +1 -0
  111. package/dist/gen/social/mixi/application/service/application_api/v1/service_pb.js +24 -0
  112. package/dist/gen/social/mixi/application/service/application_api/v1/service_pb.js.map +1 -0
  113. package/dist/gen/social/mixi/application/service/application_stream/v1/service_pb.js +12 -0
  114. package/dist/gen/social/mixi/application/service/application_stream/v1/service_pb.js.map +1 -0
  115. package/dist/gen/social/mixi/application/service/client_endpoint/v1/service_pb.js +11 -0
  116. package/dist/gen/social/mixi/application/service/client_endpoint/v1/service_pb.js.map +1 -0
  117. package/dist/index.d.ts +6 -0
  118. package/dist/index.js +4 -0
  119. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 mst-mkt
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # mixi2 Application SDK for TypeScript
2
+
3
+ mixi2 の Application API を利用するための TypeScript SDK です。
4
+
5
+ > [!NOTE]
6
+ > これは非公式の SDK です。公式の Go SDK は [mixigroup/mixi2-application-sdk-go](https://github.com/mixigroup/mixi2-application-sdk-go) を参照してください。
7
+
8
+ ## インストール
9
+
10
+ TODO: npm, jsr へ publish
11
+
12
+ ## 機能
13
+
14
+ | モジュール | 機能 |
15
+ | ---------------------------------------- | ------------------------------------------------------------------------------ |
16
+ | `mixi2-application-sdk-ts/auth` | OAuth2 Client Credentials 認証(アクセストークンの取得・キャッシュ・自動更新) |
17
+ | `mixi2-application-sdk-ts/client` | mixi2 Application API クライアント |
18
+ | `mixi2-application-sdk-ts/event` | イベントハンドリングのインターフェース定義 |
19
+ | `mixi2-application-sdk-ts/event/webhook` | HTTP Webhook によるイベント受信 |
20
+ | `mixi2-application-sdk-ts/event/stream` | gRPC ストリーミングによるイベント受信 |
21
+
22
+ ## クイックスタート
23
+
24
+ ### 認証
25
+
26
+ ```typescript
27
+ import { createAuthenticator } from 'mixi2-application-sdk-ts/auth'
28
+
29
+ const authenticator = createAuthenticator({
30
+ clientId: CLIENT_ID,
31
+ clientSecret: CLIENT_SECRET,
32
+ tokenUrl: TOKEN_URL,
33
+ })
34
+
35
+ // アクセストークンを取得
36
+ const token = await authenticator.getAccessToken()
37
+ ```
38
+
39
+ ### Webhook サーバー
40
+
41
+ [Example](./example/webhook)
42
+
43
+ ```typescript
44
+ import { createGrpcTransport } from '@connectrpc/connect-node'
45
+ import { createAuthenticator } from 'mixi2-application-sdk-ts/auth'
46
+ import { createMixi2Client } from 'mixi2-application-sdk-ts/client'
47
+ import type { EventHandler } from 'mixi2-application-sdk-ts/event'
48
+ import { createWebhookHandler } from 'mixi2-application-sdk-ts/event/webhook'
49
+
50
+ const authenticator = createAuthenticator({
51
+ clientId: CLIENT_ID,
52
+ clientSecret: CLIENT_SECRET,
53
+ tokenUrl: TOKEN_URL,
54
+ })
55
+
56
+ const client = createMixi2Client({
57
+ transport: createGrpcTransport({
58
+ baseUrl: API_ADDRESS,
59
+ interceptors: [authenticator.createInterceptor()],
60
+ }),
61
+ })
62
+
63
+ const eventHandler: EventHandler = {
64
+ handle: async (event) => {
65
+ console.log('Received event:', event)
66
+ },
67
+ }
68
+
69
+ const webhookHandler = createWebhookHandler(
70
+ { signaturePublicKey: SIGNATURE_PUBLIC_KEY },
71
+ eventHandler,
72
+ )
73
+
74
+ export const POST = (request: Request) => webhookHandler(request)
75
+ ```
76
+
77
+ ### gRPC ストリーミング
78
+
79
+ TODO: gRPC の Example を作成
80
+
81
+ ```typescript
82
+ import { createGrpcTransport } from '@connectrpc/connect-node'
83
+ import { createAuthenticator } from 'mixi2-application-sdk-ts/auth'
84
+ import type { EventHandler } from 'mixi2-application-sdk-ts/event'
85
+ import { createStreamWatcher } from 'mixi2-application-sdk-ts/event/stream'
86
+
87
+ const authenticator = createAuthenticator({
88
+ clientId: CLIENT_ID,
89
+ clientSecret: CLIENT_SECRET,
90
+ tokenUrl: TOKEN_URL,
91
+ })
92
+
93
+ const transport = createGrpcTransport({
94
+ baseUrl: API_ADDRESS,
95
+ interceptors: [authenticator.createInterceptor()],
96
+ })
97
+
98
+ const eventHandler: EventHandler = {
99
+ handle: async (event) => {
100
+ console.log('Received event:', event)
101
+ },
102
+ }
103
+
104
+ const watcher = createStreamWatcher({ transport }, eventHandler)
105
+
106
+ const controller = new AbortController()
107
+ await watcher.watch(controller.signal)
108
+ ```
109
+
110
+ ## 開発
111
+
112
+ ### 必要なツール
113
+
114
+ - [mise](https://mise.jdx.dev): 以下のツールを管理
115
+ - Node.js
116
+ - pnpm
117
+
118
+ ### スクリプト
119
+
120
+ - `pnpm generate` (proto から TypeScript コードを生成)
121
+ - `pnpm build`
122
+ - `pnpm test`
123
+ - `pnpm check:lint`
124
+ - `pnpm check:fmt`
125
+ - `pnpm check:types`
126
+ - `pnpm fix:lint`
127
+ - `pnpm fix:fmt`
128
+
129
+ ## ライセンス
130
+
131
+ [Apache License 2.0](LICENSE)
@@ -0,0 +1,8 @@
1
+ import { AuthConfig, Authenticator } from "./types.js";
2
+
3
+ //#region src/auth/authenticator.d.ts
4
+ /** createAuthenticator creates an Authenticator that manages OAuth2 Client Credentials tokens. */
5
+ declare const createAuthenticator: (config: AuthConfig) => Authenticator;
6
+ //#endregion
7
+ export { createAuthenticator };
8
+ //# sourceMappingURL=authenticator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticator.d.ts","names":[],"sources":["../../src/auth/authenticator.ts"],"mappings":";;;;cAMa,mBAAA,GAAuB,MAAA,EAAQ,UAAA,KAAa,aAAA"}
@@ -0,0 +1,44 @@
1
+ import { createAuthInterceptor } from "./interceptor.js";
2
+ //#region src/auth/authenticator.ts
3
+ const TOKEN_EXPIRY_BUFFER_MS = 6e4;
4
+ /** createAuthenticator creates an Authenticator that manages OAuth2 Client Credentials tokens. */
5
+ const createAuthenticator = (config) => {
6
+ let cached;
7
+ const fetchToken = async () => {
8
+ const body = new URLSearchParams({
9
+ grant_type: "client_credentials",
10
+ client_id: config.clientId,
11
+ client_secret: config.clientSecret
12
+ });
13
+ const response = await fetch(config.tokenUrl, {
14
+ method: "POST",
15
+ headers: { "content-type": "application/x-www-form-urlencoded" },
16
+ body: body.toString()
17
+ });
18
+ if (!response.ok) throw new Error(`Failed to fetch access token: ${response.status} ${response.statusText}`);
19
+ const data = await response.json();
20
+ if (typeof data !== "object" || data === null) throw new Error("Invalid token response: expected an object");
21
+ const { access_token, expires_in } = data;
22
+ if (typeof access_token !== "string") throw new Error("Invalid token response: access_token must be a string");
23
+ if (typeof expires_in !== "number") throw new Error("Invalid token response: expires_in must be a number");
24
+ return {
25
+ accessToken: access_token,
26
+ expiresAt: Date.now() + expires_in * 1e3
27
+ };
28
+ };
29
+ const isExpired = (token) => {
30
+ return Date.now() >= token.expiresAt - TOKEN_EXPIRY_BUFFER_MS;
31
+ };
32
+ const getAccessToken = async () => {
33
+ if (cached === void 0 || isExpired(cached)) cached = await fetchToken();
34
+ return cached.accessToken;
35
+ };
36
+ return {
37
+ getAccessToken,
38
+ createInterceptor: () => createAuthInterceptor(getAccessToken)
39
+ };
40
+ };
41
+ //#endregion
42
+ export { createAuthenticator };
43
+
44
+ //# sourceMappingURL=authenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticator.js","names":[],"sources":["../../src/auth/authenticator.ts"],"sourcesContent":["import { createAuthInterceptor } from './interceptor'\nimport type { AuthConfig, Authenticator, TokenResponse } from './types'\n\nconst TOKEN_EXPIRY_BUFFER_MS = 60_000\n\n/** createAuthenticator creates an Authenticator that manages OAuth2 Client Credentials tokens. */\nexport const createAuthenticator = (config: AuthConfig): Authenticator => {\n let cached: TokenResponse | undefined\n\n const fetchToken = async (): Promise<TokenResponse> => {\n const body = new URLSearchParams({\n grant_type: 'client_credentials',\n client_id: config.clientId,\n client_secret: config.clientSecret,\n })\n\n const response = await fetch(config.tokenUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: body.toString(),\n })\n\n if (!response.ok) {\n throw new Error(`Failed to fetch access token: ${response.status} ${response.statusText}`)\n }\n\n const data = await response.json()\n\n if (typeof data !== 'object' || data === null) {\n throw new Error('Invalid token response: expected an object')\n }\n\n const { access_token, expires_in } = data\n\n if (typeof access_token !== 'string') {\n throw new Error('Invalid token response: access_token must be a string')\n }\n\n if (typeof expires_in !== 'number') {\n throw new Error('Invalid token response: expires_in must be a number')\n }\n\n return {\n accessToken: access_token,\n expiresAt: Date.now() + expires_in * 1000,\n }\n }\n\n const isExpired = (token: TokenResponse): boolean => {\n return Date.now() >= token.expiresAt - TOKEN_EXPIRY_BUFFER_MS\n }\n\n const getAccessToken = async (): Promise<string> => {\n if (cached === undefined || isExpired(cached)) {\n cached = await fetchToken()\n }\n return cached.accessToken\n }\n\n return {\n getAccessToken,\n createInterceptor: () => createAuthInterceptor(getAccessToken),\n }\n}\n"],"mappings":";;AAGA,MAAM,yBAAyB;;AAG/B,MAAa,uBAAuB,WAAsC;CACxE,IAAI;CAEJ,MAAM,aAAa,YAAoC;EACrD,MAAM,OAAO,IAAI,gBAAgB;GAC/B,YAAY;GACZ,WAAW,OAAO;GAClB,eAAe,OAAO;GACvB,CAAC;EAEF,MAAM,WAAW,MAAM,MAAM,OAAO,UAAU;GAC5C,QAAQ;GACR,SAAS,EAAE,gBAAgB,qCAAqC;GAChE,MAAM,KAAK,UAAU;GACtB,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,iCAAiC,SAAS,OAAO,GAAG,SAAS,aAAa;EAG5F,MAAM,OAAO,MAAM,SAAS,MAAM;AAElC,MAAI,OAAO,SAAS,YAAY,SAAS,KACvC,OAAM,IAAI,MAAM,6CAA6C;EAG/D,MAAM,EAAE,cAAc,eAAe;AAErC,MAAI,OAAO,iBAAiB,SAC1B,OAAM,IAAI,MAAM,wDAAwD;AAG1E,MAAI,OAAO,eAAe,SACxB,OAAM,IAAI,MAAM,sDAAsD;AAGxE,SAAO;GACL,aAAa;GACb,WAAW,KAAK,KAAK,GAAG,aAAa;GACtC;;CAGH,MAAM,aAAa,UAAkC;AACnD,SAAO,KAAK,KAAK,IAAI,MAAM,YAAY;;CAGzC,MAAM,iBAAiB,YAA6B;AAClD,MAAI,WAAW,KAAA,KAAa,UAAU,OAAO,CAC3C,UAAS,MAAM,YAAY;AAE7B,SAAO,OAAO;;AAGhB,QAAO;EACL;EACA,yBAAyB,sBAAsB,eAAe;EAC/D"}
@@ -0,0 +1,4 @@
1
+ import { AuthConfig, Authenticator } from "./types.js";
2
+ import { createAuthenticator } from "./authenticator.js";
3
+ import { createAuthInterceptor } from "./interceptor.js";
4
+ export { type AuthConfig, type Authenticator, createAuthInterceptor, createAuthenticator };
@@ -0,0 +1,3 @@
1
+ import { createAuthInterceptor } from "./interceptor.js";
2
+ import { createAuthenticator } from "./authenticator.js";
3
+ export { createAuthInterceptor, createAuthenticator };
@@ -0,0 +1,8 @@
1
+ import { Interceptor } from "@connectrpc/connect";
2
+
3
+ //#region src/auth/interceptor.d.ts
4
+ /** createAuthInterceptor creates an Interceptor that sets the Authorization header. */
5
+ declare const createAuthInterceptor: (getToken: () => Promise<string>) => Interceptor;
6
+ //#endregion
7
+ export { createAuthInterceptor };
8
+ //# sourceMappingURL=interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptor.d.ts","names":[],"sources":["../../src/auth/interceptor.ts"],"mappings":";;;;cAGa,qBAAA,GAAyB,QAAA,QAAgB,OAAA,aAAkB,WAAA"}
@@ -0,0 +1,13 @@
1
+ //#region src/auth/interceptor.ts
2
+ /** createAuthInterceptor creates an Interceptor that sets the Authorization header. */
3
+ const createAuthInterceptor = (getToken) => {
4
+ return (next) => async (req) => {
5
+ const token = await getToken();
6
+ req.header.set("authorization", `Bearer ${token}`);
7
+ return next(req);
8
+ };
9
+ };
10
+ //#endregion
11
+ export { createAuthInterceptor };
12
+
13
+ //# sourceMappingURL=interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptor.js","names":[],"sources":["../../src/auth/interceptor.ts"],"sourcesContent":["import type { Interceptor } from '@connectrpc/connect'\n\n/** createAuthInterceptor creates an Interceptor that sets the Authorization header. */\nexport const createAuthInterceptor = (getToken: () => Promise<string>): Interceptor => {\n return (next) => async (req) => {\n const token = await getToken()\n req.header.set('authorization', `Bearer ${token}`)\n return next(req)\n }\n}\n"],"mappings":";;AAGA,MAAa,yBAAyB,aAAiD;AACrF,SAAQ,SAAS,OAAO,QAAQ;EAC9B,MAAM,QAAQ,MAAM,UAAU;AAC9B,MAAI,OAAO,IAAI,iBAAiB,UAAU,QAAQ;AAClD,SAAO,KAAK,IAAI"}
@@ -0,0 +1,15 @@
1
+ import { Interceptor } from "@connectrpc/connect";
2
+
3
+ //#region src/auth/types.d.ts
4
+ type AuthConfig = {
5
+ readonly clientId: string;
6
+ readonly clientSecret: string;
7
+ readonly tokenUrl: string;
8
+ };
9
+ type Authenticator = {
10
+ readonly getAccessToken: () => Promise<string>;
11
+ readonly createInterceptor: () => Interceptor;
12
+ };
13
+ //#endregion
14
+ export { AuthConfig, Authenticator };
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/auth/types.ts"],"mappings":";;;KAEY,UAAA;EAAA,SACD,QAAA;EAAA,SACA,YAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAQC,aAAA;EAAA,SACD,cAAA,QAAsB,OAAA;EAAA,SACtB,iBAAA,QAAyB,WAAA;AAAA"}
@@ -0,0 +1,13 @@
1
+ import { ApplicationService } from "../gen/social/mixi/application/service/application_api/v1/service_pb.js";
2
+ import { Client, Transport } from "@connectrpc/connect";
3
+
4
+ //#region src/client/index.d.ts
5
+ type ClientConfig = {
6
+ readonly transport: Transport;
7
+ };
8
+ type Mixi2Client = Client<typeof ApplicationService>;
9
+ /** createMixi2Client creates a typed client for the mixi2 Application API. */
10
+ declare const createMixi2Client: (config: ClientConfig) => Mixi2Client;
11
+ //#endregion
12
+ export { ClientConfig, Mixi2Client, createMixi2Client };
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/index.ts"],"mappings":";;;;KAKY,YAAA;EAAA,SACD,SAAA,EAAW,SAAA;AAAA;AAAA,KAGV,WAAA,GAAc,MAAA,QAAc,kBAAA;;cAG3B,iBAAA,GAAqB,MAAA,EAAQ,YAAA,KAAe,WAAA"}
@@ -0,0 +1,11 @@
1
+ import { ApplicationService } from "../gen/social/mixi/application/service/application_api/v1/service_pb.js";
2
+ import { createClient } from "@connectrpc/connect";
3
+ //#region src/client/index.ts
4
+ /** createMixi2Client creates a typed client for the mixi2 Application API. */
5
+ const createMixi2Client = (config) => {
6
+ return createClient(ApplicationService, config.transport);
7
+ };
8
+ //#endregion
9
+ export { createMixi2Client };
10
+
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/client/index.ts"],"sourcesContent":["import type { Client, Transport } from '@connectrpc/connect'\nimport { createClient } from '@connectrpc/connect'\n\nimport { ApplicationService } from '../gen/social/mixi/application/service/application_api/v1/service_pb'\n\nexport type ClientConfig = {\n readonly transport: Transport\n}\n\nexport type Mixi2Client = Client<typeof ApplicationService>\n\n/** createMixi2Client creates a typed client for the mixi2 Application API. */\nexport const createMixi2Client = (config: ClientConfig): Mixi2Client => {\n return createClient(ApplicationService, config.transport)\n}\n"],"mappings":";;;;AAYA,MAAa,qBAAqB,WAAsC;AACtE,QAAO,aAAa,oBAAoB,OAAO,UAAU"}
@@ -0,0 +1,2 @@
1
+ import { EventHandler, OnErrorHandler } from "./types.js";
2
+ export { type EventHandler, type OnErrorHandler };
File without changes
@@ -0,0 +1,12 @@
1
+ //#region src/event/stream/backoff.ts
2
+ const calculateBackoff = (attempt, baseMs = 1e3, maxMs = 3e4) => {
3
+ const delay = baseMs * 2 ** attempt;
4
+ return Math.min(delay, maxMs);
5
+ };
6
+ const sleep = (ms) => {
7
+ return new Promise((resolve) => setTimeout(resolve, ms));
8
+ };
9
+ //#endregion
10
+ export { calculateBackoff, sleep };
11
+
12
+ //# sourceMappingURL=backoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.js","names":[],"sources":["../../../src/event/stream/backoff.ts"],"sourcesContent":["export const calculateBackoff = (attempt: number, baseMs = 1000, maxMs = 30_000): number => {\n const delay = baseMs * 2 ** attempt\n return Math.min(delay, maxMs)\n}\n\nexport const sleep = (ms: number): Promise<void> => {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n"],"mappings":";AAAA,MAAa,oBAAoB,SAAiB,SAAS,KAAM,QAAQ,QAAmB;CAC1F,MAAM,QAAQ,SAAS,KAAK;AAC5B,QAAO,KAAK,IAAI,OAAO,MAAM;;AAG/B,MAAa,SAAS,OAA8B;AAClD,QAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { StreamWatcher, StreamWatcherConfig, createStreamWatcher } from "./watcher.js";
2
+ export { type StreamWatcher, type StreamWatcherConfig, createStreamWatcher };
@@ -0,0 +1,2 @@
1
+ import { createStreamWatcher } from "./watcher.js";
2
+ export { createStreamWatcher };
@@ -0,0 +1,17 @@
1
+ import { EventHandler, OnErrorHandler } from "../types.js";
2
+ import { Transport } from "@connectrpc/connect";
3
+
4
+ //#region src/event/stream/watcher.d.ts
5
+ type StreamWatcherConfig = {
6
+ readonly transport: Transport;
7
+ readonly maxRetries?: number;
8
+ readonly onError?: OnErrorHandler;
9
+ };
10
+ type StreamWatcher = {
11
+ readonly watch: (signal?: AbortSignal) => Promise<void>;
12
+ };
13
+ /** createStreamWatcher creates a streaming event watcher with auto-reconnect. */
14
+ declare const createStreamWatcher: (config: StreamWatcherConfig, handler: EventHandler) => StreamWatcher;
15
+ //#endregion
16
+ export { StreamWatcher, StreamWatcherConfig, createStreamWatcher };
17
+ //# sourceMappingURL=watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.d.ts","names":[],"sources":["../../../src/event/stream/watcher.ts"],"mappings":";;;;KAWY,mBAAA;EAAA,SACD,SAAA,EAAW,SAAA;EAAA,SACX,UAAA;EAAA,SACA,OAAA,GAAU,cAAA;AAAA;AAAA,KAGT,aAAA;EAAA,SACD,KAAA,GAAQ,MAAA,GAAS,WAAA,KAAgB,OAAA;AAAA;;cAkC/B,mBAAA,GACX,MAAA,EAAQ,mBAAA,EACR,OAAA,EAAS,YAAA,KACR,aAAA"}
@@ -0,0 +1,40 @@
1
+ import { isPingEvent, resolveOnError } from "../types.js";
2
+ import { ApplicationService } from "../../gen/social/mixi/application/service/application_stream/v1/service_pb.js";
3
+ import { calculateBackoff, sleep } from "./backoff.js";
4
+ import { createClient } from "@connectrpc/connect";
5
+ //#region src/event/stream/watcher.ts
6
+ const DEFAULT_MAX_RETRIES = 3;
7
+ const handleEvents = async (events, handler, onError) => {
8
+ for (const event of events) {
9
+ if (isPingEvent(event)) continue;
10
+ try {
11
+ await handler.handle(event);
12
+ } catch (error) {
13
+ onError(error);
14
+ }
15
+ }
16
+ };
17
+ const consumeStream = async (transport, handler, onError, signal) => {
18
+ const stream = createClient(ApplicationService, transport).subscribeEvents({}, signal ? { signal } : {});
19
+ for await (const response of stream) await handleEvents(response.events, handler, onError);
20
+ };
21
+ /** createStreamWatcher creates a streaming event watcher with auto-reconnect. */
22
+ const createStreamWatcher = (config, handler) => {
23
+ const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
24
+ const onError = resolveOnError(config.onError);
25
+ const watch = async (signal) => {
26
+ for (let retries = 0; !signal?.aborted; retries++) try {
27
+ await consumeStream(config.transport, handler, onError, signal);
28
+ return;
29
+ } catch (error) {
30
+ if (signal?.aborted) return;
31
+ if (retries >= maxRetries) throw error;
32
+ await sleep(calculateBackoff(retries));
33
+ }
34
+ };
35
+ return { watch };
36
+ };
37
+ //#endregion
38
+ export { createStreamWatcher };
39
+
40
+ //# sourceMappingURL=watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.js","names":[],"sources":["../../../src/event/stream/watcher.ts"],"sourcesContent":["import type { Transport } from '@connectrpc/connect'\nimport { createClient } from '@connectrpc/connect'\n\nimport type { Event } from '../../gen/social/mixi/application/model/v1/event_pb'\nimport { ApplicationService } from '../../gen/social/mixi/application/service/application_stream/v1/service_pb'\nimport { isPingEvent, resolveOnError } from '../types'\nimport type { EventHandler, OnErrorHandler } from '../types'\nimport { calculateBackoff, sleep } from './backoff'\n\nconst DEFAULT_MAX_RETRIES = 3\n\nexport type StreamWatcherConfig = {\n readonly transport: Transport\n readonly maxRetries?: number\n readonly onError?: OnErrorHandler\n}\n\nexport type StreamWatcher = {\n readonly watch: (signal?: AbortSignal) => Promise<void>\n}\n\nconst handleEvents = async (\n events: readonly Event[],\n handler: EventHandler,\n onError: OnErrorHandler,\n): Promise<void> => {\n for (const event of events) {\n if (isPingEvent(event)) continue\n\n try {\n await handler.handle(event)\n } catch (error) {\n onError(error)\n }\n }\n}\n\nconst consumeStream = async (\n transport: Transport,\n handler: EventHandler,\n onError: OnErrorHandler,\n signal?: AbortSignal,\n): Promise<void> => {\n const client = createClient(ApplicationService, transport)\n const stream = client.subscribeEvents({}, signal ? { signal } : {})\n\n for await (const response of stream) {\n await handleEvents(response.events, handler, onError)\n }\n}\n\n/** createStreamWatcher creates a streaming event watcher with auto-reconnect. */\nexport const createStreamWatcher = (\n config: StreamWatcherConfig,\n handler: EventHandler,\n): StreamWatcher => {\n const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES\n const onError = resolveOnError(config.onError)\n\n const watch = async (signal?: AbortSignal): Promise<void> => {\n for (let retries = 0; !signal?.aborted; retries++) {\n try {\n await consumeStream(config.transport, handler, onError, signal)\n return\n } catch (error) {\n if (signal?.aborted) return\n if (retries >= maxRetries) throw error\n await sleep(calculateBackoff(retries))\n }\n }\n }\n\n return { watch }\n}\n"],"mappings":";;;;;AASA,MAAM,sBAAsB;AAY5B,MAAM,eAAe,OACnB,QACA,SACA,YACkB;AAClB,MAAK,MAAM,SAAS,QAAQ;AAC1B,MAAI,YAAY,MAAM,CAAE;AAExB,MAAI;AACF,SAAM,QAAQ,OAAO,MAAM;WACpB,OAAO;AACd,WAAQ,MAAM;;;;AAKpB,MAAM,gBAAgB,OACpB,WACA,SACA,SACA,WACkB;CAElB,MAAM,SADS,aAAa,oBAAoB,UAAU,CACpC,gBAAgB,EAAE,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,CAAC;AAEnE,YAAW,MAAM,YAAY,OAC3B,OAAM,aAAa,SAAS,QAAQ,SAAS,QAAQ;;;AAKzD,MAAa,uBACX,QACA,YACkB;CAClB,MAAM,aAAa,OAAO,cAAc;CACxC,MAAM,UAAU,eAAe,OAAO,QAAQ;CAE9C,MAAM,QAAQ,OAAO,WAAwC;AAC3D,OAAK,IAAI,UAAU,GAAG,CAAC,QAAQ,SAAS,UACtC,KAAI;AACF,SAAM,cAAc,OAAO,WAAW,SAAS,SAAS,OAAO;AAC/D;WACO,OAAO;AACd,OAAI,QAAQ,QAAS;AACrB,OAAI,WAAW,WAAY,OAAM;AACjC,SAAM,MAAM,iBAAiB,QAAQ,CAAC;;;AAK5C,QAAO,EAAE,OAAO"}
@@ -0,0 +1,14 @@
1
+ import { Event } from "../gen/social/mixi/application/model/v1/event_pb.js";
2
+
3
+ //#region src/event/types.d.ts
4
+ /**
5
+ * EventHandler processes events from mixi2.
6
+ * Ping events are handled internally by the SDK and not passed to handle.
7
+ */
8
+ type EventHandler = {
9
+ readonly handle: (event: Event) => Promise<void>;
10
+ };
11
+ type OnErrorHandler = (error: unknown) => void;
12
+ //#endregion
13
+ export { EventHandler, OnErrorHandler };
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/event/types.ts"],"mappings":";;;;;AAOA;;KAAY,YAAA;EAAA,SACD,MAAA,GAAS,KAAA,EAAO,KAAA,KAAU,OAAA;AAAA;AAAA,KAGzB,cAAA,IAAkB,KAAA"}
@@ -0,0 +1,13 @@
1
+ import { EventType } from "../gen/social/mixi/application/const/v1/event_type_pb.js";
2
+ //#region src/event/types.ts
3
+ const defaultOnError = (error) => {
4
+ console.error("[mixi2-sdk] event handler error:", error);
5
+ };
6
+ const resolveOnError = (onError) => onError ?? defaultOnError;
7
+ const isPingEvent = (event) => {
8
+ return event.eventType === EventType.PING;
9
+ };
10
+ //#endregion
11
+ export { isPingEvent, resolveOnError };
12
+
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/event/types.ts"],"sourcesContent":["import { EventType } from '../gen/social/mixi/application/const/v1/event_type_pb'\nimport type { Event } from '../gen/social/mixi/application/model/v1/event_pb'\n\n/**\n * EventHandler processes events from mixi2.\n * Ping events are handled internally by the SDK and not passed to handle.\n */\nexport type EventHandler = {\n readonly handle: (event: Event) => Promise<void>\n}\n\nexport type OnErrorHandler = (error: unknown) => void\n\nconst defaultOnError: OnErrorHandler = (error) => {\n console.error('[mixi2-sdk] event handler error:', error)\n}\n\nexport const resolveOnError = (onError: OnErrorHandler | undefined): OnErrorHandler =>\n onError ?? defaultOnError\n\nexport const isPingEvent = (event: Event): boolean => {\n return event.eventType === EventType.PING\n}\n"],"mappings":";;AAaA,MAAM,kBAAkC,UAAU;AAChD,SAAQ,MAAM,oCAAoC,MAAM;;AAG1D,MAAa,kBAAkB,YAC7B,WAAW;AAEb,MAAa,eAAe,UAA0B;AACpD,QAAO,MAAM,cAAc,UAAU"}