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.
- package/README.md +16 -13
- package/dist/client-C90Zd_yq.d.cts +303 -0
- package/dist/client-DPeVTCYr.d.mts +303 -0
- package/dist/helpers/index.cjs +305 -207
- package/dist/helpers/index.d.cts +150 -65
- package/dist/helpers/index.d.mts +207 -0
- package/dist/helpers/index.mjs +304 -0
- package/dist/index.cjs +542 -750
- package/dist/index.d.cts +41 -37
- package/dist/index.d.mts +50 -0
- package/dist/index.mjs +559 -0
- package/dist/types-BrJ83qtL.mjs +92 -0
- package/dist/types-D9t_NdQ0.cjs +175 -0
- package/package.json +43 -51
- package/dist/chunk-4NKIICB5.js +0 -107
- package/dist/client-iXbbRxc-.d.cts +0 -296
- package/dist/client-iXbbRxc-.d.ts +0 -296
- package/dist/helpers/index.d.ts +0 -122
- package/dist/helpers/index.js +0 -186
- package/dist/index.d.ts +0 -46
- package/dist/index.js +0 -680
package/dist/index.cjs
CHANGED
|
@@ -1,812 +1,604 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
MediaUploadStatus: () => MediaUploadStatus,
|
|
39
|
-
MediaUploadType: () => MediaUploadType,
|
|
40
|
-
OAuth2Authenticator: () => OAuth2Authenticator,
|
|
41
|
-
PostAccessLevel: () => PostAccessLevel,
|
|
42
|
-
PostMaskType: () => PostMaskType,
|
|
43
|
-
PostMediaType: () => PostMediaType,
|
|
44
|
-
PostPublishingType: () => PostPublishingType,
|
|
45
|
-
PostVisibility: () => PostVisibility,
|
|
46
|
-
StampSetType: () => StampSetType,
|
|
47
|
-
StreamWatcher: () => StreamWatcher,
|
|
48
|
-
UserAccessLevel: () => UserAccessLevel,
|
|
49
|
-
UserVisibility: () => UserVisibility,
|
|
50
|
-
WebhookServer: () => WebhookServer
|
|
51
|
-
});
|
|
52
|
-
module.exports = __toCommonJS(index_exports);
|
|
53
|
-
|
|
54
|
-
// node_modules/tsup/assets/cjs_shims.js
|
|
55
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
56
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
57
|
-
|
|
58
|
-
// src/auth.ts
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
const require_types = require("./types-D9t_NdQ0.cjs");
|
|
25
|
+
let _grpc_grpc_js = require("@grpc/grpc-js");
|
|
26
|
+
_grpc_grpc_js = __toESM(_grpc_grpc_js);
|
|
27
|
+
let path = require("path");
|
|
28
|
+
path = __toESM(path);
|
|
29
|
+
let url = require("url");
|
|
30
|
+
let _grpc_proto_loader = require("@grpc/proto-loader");
|
|
31
|
+
_grpc_proto_loader = __toESM(_grpc_proto_loader);
|
|
32
|
+
let http = require("http");
|
|
33
|
+
http = __toESM(http);
|
|
34
|
+
let crypto = require("crypto");
|
|
35
|
+
crypto = __toESM(crypto);
|
|
36
|
+
//#region src/auth.ts
|
|
59
37
|
var OAuth2Authenticator = class {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`Failed to acquire access token: ${response.status} ${response.statusText}`
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
const data = await response.json();
|
|
101
|
-
this.accessToken = data.access_token;
|
|
102
|
-
this.expiresAt = Date.now() + (data.expires_in - 60) * 1e3;
|
|
103
|
-
}
|
|
38
|
+
clientId;
|
|
39
|
+
clientSecret;
|
|
40
|
+
tokenUrl;
|
|
41
|
+
accessToken = null;
|
|
42
|
+
expiresAt = null;
|
|
43
|
+
refreshPromise = null;
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.clientId = options.clientId;
|
|
46
|
+
this.clientSecret = options.clientSecret;
|
|
47
|
+
this.tokenUrl = options.tokenUrl;
|
|
48
|
+
}
|
|
49
|
+
async getAccessToken() {
|
|
50
|
+
if (this.accessToken && this.expiresAt && Date.now() < this.expiresAt) return this.accessToken;
|
|
51
|
+
if (!this.refreshPromise) this.refreshPromise = this.refreshToken().finally(() => {
|
|
52
|
+
this.refreshPromise = null;
|
|
53
|
+
});
|
|
54
|
+
await this.refreshPromise;
|
|
55
|
+
return this.accessToken;
|
|
56
|
+
}
|
|
57
|
+
async refreshToken() {
|
|
58
|
+
const credentials = Buffer.from(`${encodeURIComponent(this.clientId)}:${encodeURIComponent(this.clientSecret)}`).toString("base64");
|
|
59
|
+
const response = await fetch(this.tokenUrl, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
63
|
+
Authorization: `Basic ${credentials}`
|
|
64
|
+
},
|
|
65
|
+
body: "grant_type=client_credentials"
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) throw new Error(`Failed to acquire access token: ${response.status} ${response.statusText}`);
|
|
68
|
+
const data = await response.json();
|
|
69
|
+
this.accessToken = data.access_token;
|
|
70
|
+
this.expiresAt = Date.now() + (data.expires_in - 60) * 1e3;
|
|
71
|
+
}
|
|
104
72
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
EventReason2[EventReason2["PING"] = 1] = "PING";
|
|
117
|
-
EventReason2[EventReason2["POST_REPLY"] = 2] = "POST_REPLY";
|
|
118
|
-
EventReason2[EventReason2["POST_MENTIONED"] = 3] = "POST_MENTIONED";
|
|
119
|
-
EventReason2[EventReason2["POST_QUOTED"] = 4] = "POST_QUOTED";
|
|
120
|
-
EventReason2[EventReason2["DIRECT_MESSAGE_RECEIVED"] = 8] = "DIRECT_MESSAGE_RECEIVED";
|
|
121
|
-
return EventReason2;
|
|
122
|
-
})(EventReason || {});
|
|
123
|
-
var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
124
|
-
MediaType2[MediaType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
125
|
-
MediaType2[MediaType2["IMAGE"] = 1] = "IMAGE";
|
|
126
|
-
MediaType2[MediaType2["VIDEO"] = 2] = "VIDEO";
|
|
127
|
-
return MediaType2;
|
|
128
|
-
})(MediaType || {});
|
|
129
|
-
var PostMediaType = /* @__PURE__ */ ((PostMediaType2) => {
|
|
130
|
-
PostMediaType2[PostMediaType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
131
|
-
PostMediaType2[PostMediaType2["IMAGE"] = 1] = "IMAGE";
|
|
132
|
-
PostMediaType2[PostMediaType2["VIDEO"] = 2] = "VIDEO";
|
|
133
|
-
return PostMediaType2;
|
|
134
|
-
})(PostMediaType || {});
|
|
135
|
-
var PostVisibility = /* @__PURE__ */ ((PostVisibility2) => {
|
|
136
|
-
PostVisibility2[PostVisibility2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
137
|
-
PostVisibility2[PostVisibility2["VISIBLE"] = 1] = "VISIBLE";
|
|
138
|
-
PostVisibility2[PostVisibility2["INVISIBLE"] = 2] = "INVISIBLE";
|
|
139
|
-
return PostVisibility2;
|
|
140
|
-
})(PostVisibility || {});
|
|
141
|
-
var PostAccessLevel = /* @__PURE__ */ ((PostAccessLevel2) => {
|
|
142
|
-
PostAccessLevel2[PostAccessLevel2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
143
|
-
PostAccessLevel2[PostAccessLevel2["PUBLIC"] = 1] = "PUBLIC";
|
|
144
|
-
PostAccessLevel2[PostAccessLevel2["PRIVATE"] = 2] = "PRIVATE";
|
|
145
|
-
return PostAccessLevel2;
|
|
146
|
-
})(PostAccessLevel || {});
|
|
147
|
-
var PostMaskType = /* @__PURE__ */ ((PostMaskType2) => {
|
|
148
|
-
PostMaskType2[PostMaskType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
149
|
-
PostMaskType2[PostMaskType2["SENSITIVE"] = 1] = "SENSITIVE";
|
|
150
|
-
PostMaskType2[PostMaskType2["SPOILER"] = 2] = "SPOILER";
|
|
151
|
-
return PostMaskType2;
|
|
152
|
-
})(PostMaskType || {});
|
|
153
|
-
var PostPublishingType = /* @__PURE__ */ ((PostPublishingType2) => {
|
|
154
|
-
PostPublishingType2[PostPublishingType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
155
|
-
PostPublishingType2[PostPublishingType2["NOT_PUBLISHING"] = 1] = "NOT_PUBLISHING";
|
|
156
|
-
return PostPublishingType2;
|
|
157
|
-
})(PostPublishingType || {});
|
|
158
|
-
var UserVisibility = /* @__PURE__ */ ((UserVisibility2) => {
|
|
159
|
-
UserVisibility2[UserVisibility2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
160
|
-
UserVisibility2[UserVisibility2["VISIBLE"] = 1] = "VISIBLE";
|
|
161
|
-
UserVisibility2[UserVisibility2["INVISIBLE"] = 2] = "INVISIBLE";
|
|
162
|
-
return UserVisibility2;
|
|
163
|
-
})(UserVisibility || {});
|
|
164
|
-
var UserAccessLevel = /* @__PURE__ */ ((UserAccessLevel2) => {
|
|
165
|
-
UserAccessLevel2[UserAccessLevel2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
166
|
-
UserAccessLevel2[UserAccessLevel2["PUBLIC"] = 1] = "PUBLIC";
|
|
167
|
-
UserAccessLevel2[UserAccessLevel2["PRIVATE"] = 2] = "PRIVATE";
|
|
168
|
-
return UserAccessLevel2;
|
|
169
|
-
})(UserAccessLevel || {});
|
|
170
|
-
var LanguageCode = /* @__PURE__ */ ((LanguageCode2) => {
|
|
171
|
-
LanguageCode2[LanguageCode2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
172
|
-
LanguageCode2[LanguageCode2["JP"] = 1] = "JP";
|
|
173
|
-
LanguageCode2[LanguageCode2["EN"] = 2] = "EN";
|
|
174
|
-
return LanguageCode2;
|
|
175
|
-
})(LanguageCode || {});
|
|
176
|
-
var StampSetType = /* @__PURE__ */ ((StampSetType2) => {
|
|
177
|
-
StampSetType2[StampSetType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
178
|
-
StampSetType2[StampSetType2["DEFAULT"] = 1] = "DEFAULT";
|
|
179
|
-
StampSetType2[StampSetType2["SEASONAL"] = 2] = "SEASONAL";
|
|
180
|
-
return StampSetType2;
|
|
181
|
-
})(StampSetType || {});
|
|
182
|
-
var MediaUploadType = /* @__PURE__ */ ((MediaUploadType2) => {
|
|
183
|
-
MediaUploadType2[MediaUploadType2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
184
|
-
MediaUploadType2[MediaUploadType2["IMAGE"] = 1] = "IMAGE";
|
|
185
|
-
MediaUploadType2[MediaUploadType2["VIDEO"] = 2] = "VIDEO";
|
|
186
|
-
return MediaUploadType2;
|
|
187
|
-
})(MediaUploadType || {});
|
|
188
|
-
var MediaUploadStatus = /* @__PURE__ */ ((MediaUploadStatus2) => {
|
|
189
|
-
MediaUploadStatus2[MediaUploadStatus2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
190
|
-
MediaUploadStatus2[MediaUploadStatus2["UPLOAD_PENDING"] = 1] = "UPLOAD_PENDING";
|
|
191
|
-
MediaUploadStatus2[MediaUploadStatus2["PROCESSING"] = 2] = "PROCESSING";
|
|
192
|
-
MediaUploadStatus2[MediaUploadStatus2["COMPLETED"] = 3] = "COMPLETED";
|
|
193
|
-
MediaUploadStatus2[MediaUploadStatus2["FAILED"] = 4] = "FAILED";
|
|
194
|
-
return MediaUploadStatus2;
|
|
195
|
-
})(MediaUploadStatus || {});
|
|
196
|
-
|
|
197
|
-
// src/client.ts
|
|
198
|
-
var grpc2 = __toESM(require("@grpc/grpc-js"), 1);
|
|
199
|
-
|
|
200
|
-
// src/proto.ts
|
|
201
|
-
var import_path = __toESM(require("path"), 1);
|
|
202
|
-
var import_url = require("url");
|
|
203
|
-
var grpc = __toESM(require("@grpc/grpc-js"), 1);
|
|
204
|
-
var protoLoader = __toESM(require("@grpc/proto-loader"), 1);
|
|
205
|
-
var __filename2 = (0, import_url.fileURLToPath)(importMetaUrl);
|
|
206
|
-
var __dirname = import_path.default.dirname(__filename2);
|
|
207
|
-
var PROTO_DIR = import_path.default.resolve(__dirname, "..", "proto");
|
|
208
|
-
var PROTO_LOADER_OPTIONS = {
|
|
209
|
-
keepCase: false,
|
|
210
|
-
longs: Number,
|
|
211
|
-
enums: Number,
|
|
212
|
-
defaults: true,
|
|
213
|
-
oneofs: true
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/proto.ts
|
|
75
|
+
const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
76
|
+
const __dirname$1 = path.default.dirname(__filename$1);
|
|
77
|
+
const PROTO_DIR = path.default.resolve(__dirname$1, "..", "proto");
|
|
78
|
+
const PROTO_LOADER_OPTIONS = {
|
|
79
|
+
keepCase: false,
|
|
80
|
+
longs: Number,
|
|
81
|
+
enums: Number,
|
|
82
|
+
defaults: true,
|
|
83
|
+
oneofs: true
|
|
214
84
|
};
|
|
215
|
-
|
|
216
|
-
|
|
85
|
+
let _packageDefinition = null;
|
|
86
|
+
let _grpcObject = null;
|
|
217
87
|
function getPackageDefinition() {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
return _packageDefinition;
|
|
88
|
+
if (!_packageDefinition) _packageDefinition = _grpc_proto_loader.loadSync([
|
|
89
|
+
"social/mixi/application/service/application_api/v1/service.proto",
|
|
90
|
+
"social/mixi/application/service/application_stream/v1/service.proto",
|
|
91
|
+
"social/mixi/application/service/client_endpoint/v1/service.proto"
|
|
92
|
+
], {
|
|
93
|
+
...PROTO_LOADER_OPTIONS,
|
|
94
|
+
includeDirs: [PROTO_DIR]
|
|
95
|
+
});
|
|
96
|
+
return _packageDefinition;
|
|
229
97
|
}
|
|
230
98
|
function getGrpcObject() {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
return _grpcObject;
|
|
99
|
+
if (!_grpcObject) _grpcObject = _grpc_grpc_js.loadPackageDefinition(getPackageDefinition());
|
|
100
|
+
return _grpcObject;
|
|
235
101
|
}
|
|
236
|
-
function resolveNested(obj,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
return current;
|
|
102
|
+
function resolveNested(obj, path$2) {
|
|
103
|
+
const parts = path$2.split(".");
|
|
104
|
+
let current = obj;
|
|
105
|
+
for (const part of parts) {
|
|
106
|
+
current = current[part];
|
|
107
|
+
if (current === void 0) throw new Error(`Could not resolve gRPC path: ${path$2}`);
|
|
108
|
+
}
|
|
109
|
+
return current;
|
|
246
110
|
}
|
|
247
111
|
function getApiServiceClient() {
|
|
248
|
-
|
|
249
|
-
return resolveNested(
|
|
250
|
-
grpcObj,
|
|
251
|
-
"social.mixi.application.service.application_api.v1.ApplicationService"
|
|
252
|
-
);
|
|
112
|
+
return resolveNested(getGrpcObject(), "social.mixi.application.service.application_api.v1.ApplicationService");
|
|
253
113
|
}
|
|
254
114
|
function getStreamServiceClient() {
|
|
255
|
-
|
|
256
|
-
return resolveNested(
|
|
257
|
-
grpcObj,
|
|
258
|
-
"social.mixi.application.service.application_stream.v1.ApplicationService"
|
|
259
|
-
);
|
|
115
|
+
return resolveNested(getGrpcObject(), "social.mixi.application.service.application_stream.v1.ApplicationService");
|
|
260
116
|
}
|
|
261
117
|
function getSendEventRequestType() {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
throw new Error("SendEventRequest message type not found in proto");
|
|
266
|
-
}
|
|
267
|
-
const pbType = msgDef.type;
|
|
268
|
-
return pbType;
|
|
118
|
+
const msgDef = getPackageDefinition()["social.mixi.application.service.client_endpoint.v1.SendEventRequest"];
|
|
119
|
+
if (!msgDef || !("type" in msgDef)) throw new Error("SendEventRequest message type not found in proto");
|
|
120
|
+
return msgDef.type;
|
|
269
121
|
}
|
|
270
|
-
|
|
271
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/convert.ts
|
|
272
124
|
function toDate(ts) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
125
|
+
if (!ts) return null;
|
|
126
|
+
if (ts instanceof Date) return ts;
|
|
127
|
+
const obj = ts;
|
|
128
|
+
if (obj.seconds !== void 0) {
|
|
129
|
+
const ms = Number(obj.seconds) * 1e3 + Math.floor((obj.nanos || 0) / 1e6);
|
|
130
|
+
return new Date(ms);
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
281
133
|
}
|
|
282
134
|
function convertUserAvatar(raw) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
135
|
+
if (!raw) return null;
|
|
136
|
+
const r = raw;
|
|
137
|
+
return {
|
|
138
|
+
largeImageUrl: r.largeImageUrl || "",
|
|
139
|
+
largeImageMimeType: r.largeImageMimeType || "",
|
|
140
|
+
largeImageHeight: r.largeImageHeight || 0,
|
|
141
|
+
largeImageWidth: r.largeImageWidth || 0,
|
|
142
|
+
smallImageUrl: r.smallImageUrl || "",
|
|
143
|
+
smallImageMimeType: r.smallImageMimeType || "",
|
|
144
|
+
smallImageHeight: r.smallImageHeight || 0,
|
|
145
|
+
smallImageWidth: r.smallImageWidth || 0
|
|
146
|
+
};
|
|
295
147
|
}
|
|
296
148
|
function convertUser(raw) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
149
|
+
const r = raw;
|
|
150
|
+
return {
|
|
151
|
+
userId: r.userId || "",
|
|
152
|
+
isDisabled: r.isDisabled || false,
|
|
153
|
+
name: r.name || "",
|
|
154
|
+
displayName: r.displayName || "",
|
|
155
|
+
profile: r.profile || "",
|
|
156
|
+
userAvatar: convertUserAvatar(r.userAvatar),
|
|
157
|
+
visibility: r.visibility || 0,
|
|
158
|
+
accessLevel: r.accessLevel || 0
|
|
159
|
+
};
|
|
308
160
|
}
|
|
309
161
|
function convertMediaImage(raw) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
162
|
+
if (!raw) return void 0;
|
|
163
|
+
const r = raw;
|
|
164
|
+
return {
|
|
165
|
+
largeImageUrl: r.largeImageUrl || "",
|
|
166
|
+
largeImageMimeType: r.largeImageMimeType || "",
|
|
167
|
+
largeImageHeight: r.largeImageHeight || 0,
|
|
168
|
+
largeImageWidth: r.largeImageWidth || 0,
|
|
169
|
+
smallImageUrl: r.smallImageUrl || "",
|
|
170
|
+
smallImageMimeType: r.smallImageMimeType || "",
|
|
171
|
+
smallImageHeight: r.smallImageHeight || 0,
|
|
172
|
+
smallImageWidth: r.smallImageWidth || 0
|
|
173
|
+
};
|
|
322
174
|
}
|
|
323
175
|
function convertMediaVideo(raw) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
176
|
+
if (!raw) return void 0;
|
|
177
|
+
const r = raw;
|
|
178
|
+
return {
|
|
179
|
+
videoUrl: r.videoUrl || "",
|
|
180
|
+
videoMimeType: r.videoMimeType || "",
|
|
181
|
+
videoHeight: r.videoHeight || 0,
|
|
182
|
+
videoWidth: r.videoWidth || 0,
|
|
183
|
+
previewImageUrl: r.previewImageUrl || "",
|
|
184
|
+
previewImageMimeType: r.previewImageMimeType || "",
|
|
185
|
+
previewImageHeight: r.previewImageHeight || 0,
|
|
186
|
+
previewImageWidth: r.previewImageWidth || 0,
|
|
187
|
+
duration: r.duration || 0
|
|
188
|
+
};
|
|
337
189
|
}
|
|
338
190
|
function convertMedia(raw) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
191
|
+
const r = raw;
|
|
192
|
+
return {
|
|
193
|
+
mediaType: r.mediaType || 0,
|
|
194
|
+
image: convertMediaImage(r.image),
|
|
195
|
+
video: convertMediaVideo(r.video)
|
|
196
|
+
};
|
|
345
197
|
}
|
|
346
198
|
function convertMediaStamp(raw) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
199
|
+
if (!raw) return null;
|
|
200
|
+
const r = raw;
|
|
201
|
+
return {
|
|
202
|
+
url: r.url || "",
|
|
203
|
+
mimeType: r.mimeType || "",
|
|
204
|
+
height: r.height || 0,
|
|
205
|
+
width: r.width || 0
|
|
206
|
+
};
|
|
355
207
|
}
|
|
356
208
|
function convertPostMedia(raw) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
209
|
+
const r = raw;
|
|
210
|
+
return {
|
|
211
|
+
mediaType: r.mediaType || 0,
|
|
212
|
+
image: r.image ? convertMediaImage(r.image) : void 0,
|
|
213
|
+
video: r.video ? convertMediaVideo(r.video) : void 0
|
|
214
|
+
};
|
|
363
215
|
}
|
|
364
216
|
function convertPostMask(raw) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
217
|
+
if (!raw) return void 0;
|
|
218
|
+
const r = raw;
|
|
219
|
+
return {
|
|
220
|
+
maskType: r.maskType || 0,
|
|
221
|
+
caption: r.caption || ""
|
|
222
|
+
};
|
|
371
223
|
}
|
|
372
224
|
function convertPostStamp(raw) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
225
|
+
const r = raw;
|
|
226
|
+
return {
|
|
227
|
+
stamp: convertMediaStamp(r.stamp),
|
|
228
|
+
count: Number(r.count) || 0
|
|
229
|
+
};
|
|
378
230
|
}
|
|
379
231
|
function convertPost(raw) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
232
|
+
const r = raw;
|
|
233
|
+
return {
|
|
234
|
+
postId: r.postId || "",
|
|
235
|
+
isDeleted: r.isDeleted || false,
|
|
236
|
+
creatorId: r.creatorId || "",
|
|
237
|
+
text: r.text || "",
|
|
238
|
+
createdAt: toDate(r.createdAt),
|
|
239
|
+
postMediaList: (r.postMediaList || []).map(convertPostMedia),
|
|
240
|
+
inReplyToPostId: r.inReplyToPostId || void 0,
|
|
241
|
+
postMask: convertPostMask(r.postMask),
|
|
242
|
+
visibility: r.visibility || 0,
|
|
243
|
+
accessLevel: r.accessLevel || 0,
|
|
244
|
+
stamps: (r.stamps || []).map(convertPostStamp),
|
|
245
|
+
readerStampId: r.readerStampId || void 0
|
|
246
|
+
};
|
|
395
247
|
}
|
|
396
248
|
function convertChatMessage(raw) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
249
|
+
const r = raw;
|
|
250
|
+
return {
|
|
251
|
+
roomId: r.roomId || "",
|
|
252
|
+
messageId: r.messageId || "",
|
|
253
|
+
creatorId: r.creatorId || "",
|
|
254
|
+
text: r.text || "",
|
|
255
|
+
createdAt: toDate(r.createdAt),
|
|
256
|
+
mediaList: (r.mediaList || []).map(convertMedia),
|
|
257
|
+
postId: r.postId || void 0
|
|
258
|
+
};
|
|
407
259
|
}
|
|
408
260
|
function convertOfficialStamp(raw) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
261
|
+
const r = raw;
|
|
262
|
+
return {
|
|
263
|
+
stampId: r.stampId || "",
|
|
264
|
+
index: r.index || 0,
|
|
265
|
+
searchTags: r.searchTags || [],
|
|
266
|
+
url: r.url || ""
|
|
267
|
+
};
|
|
416
268
|
}
|
|
417
269
|
function convertOfficialStampSet(raw) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
270
|
+
const r = raw;
|
|
271
|
+
return {
|
|
272
|
+
name: r.name || "",
|
|
273
|
+
spriteUrl: r.spriteUrl || "",
|
|
274
|
+
stamps: (r.stamps || []).map(convertOfficialStamp),
|
|
275
|
+
stampSetId: r.stampSetId || "",
|
|
276
|
+
startAt: toDate(r.startAt) ?? void 0,
|
|
277
|
+
endAt: toDate(r.endAt) ?? void 0,
|
|
278
|
+
stampSetType: r.stampSetType || 0
|
|
279
|
+
};
|
|
428
280
|
}
|
|
429
281
|
function convertPostCreatedEvent(raw) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
282
|
+
const r = raw;
|
|
283
|
+
return {
|
|
284
|
+
eventReasonList: r.eventReasonList || [],
|
|
285
|
+
post: r.post ? convertPost(r.post) : null,
|
|
286
|
+
issuer: r.issuer ? convertUser(r.issuer) : null
|
|
287
|
+
};
|
|
436
288
|
}
|
|
437
289
|
function convertChatMessageReceivedEvent(raw) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
290
|
+
const r = raw;
|
|
291
|
+
return {
|
|
292
|
+
eventReasonList: r.eventReasonList || [],
|
|
293
|
+
message: r.message ? convertChatMessage(r.message) : null,
|
|
294
|
+
issuer: r.issuer ? convertUser(r.issuer) : null
|
|
295
|
+
};
|
|
444
296
|
}
|
|
445
297
|
function convertEvent(raw) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
298
|
+
const r = raw;
|
|
299
|
+
return {
|
|
300
|
+
eventId: r.eventId || "",
|
|
301
|
+
eventType: r.eventType || 0,
|
|
302
|
+
pingEvent: r.pingEvent || void 0,
|
|
303
|
+
postCreatedEvent: r.postCreatedEvent ? convertPostCreatedEvent(r.postCreatedEvent) : void 0,
|
|
304
|
+
chatMessageReceivedEvent: r.chatMessageReceivedEvent ? convertChatMessageReceivedEvent(r.chatMessageReceivedEvent) : void 0
|
|
305
|
+
};
|
|
454
306
|
}
|
|
455
|
-
|
|
456
|
-
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/client.ts
|
|
457
309
|
var Client = class {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
return this.call(
|
|
519
|
-
"getPostMediaStatus",
|
|
520
|
-
{ mediaId }
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
async sendChatMessage(request) {
|
|
524
|
-
const response = await this.call("sendChatMessage", request);
|
|
525
|
-
return convertChatMessage(response.message);
|
|
526
|
-
}
|
|
527
|
-
async getStamps(request) {
|
|
528
|
-
const response = await this.call("getStamps", request || {});
|
|
529
|
-
return (response.officialStampSets || []).map(convertOfficialStampSet);
|
|
530
|
-
}
|
|
531
|
-
async addStampToPost(postId, stampId) {
|
|
532
|
-
const response = await this.call("addStampToPost", { postId, stampId });
|
|
533
|
-
return convertPost(response.post);
|
|
534
|
-
}
|
|
535
|
-
close() {
|
|
536
|
-
this.grpcClient.close();
|
|
537
|
-
}
|
|
310
|
+
grpcClient;
|
|
311
|
+
authenticator;
|
|
312
|
+
authKey;
|
|
313
|
+
constructor(options) {
|
|
314
|
+
this.grpcClient = new (getApiServiceClient())(options.apiAddress, _grpc_grpc_js.credentials.createSsl());
|
|
315
|
+
this.authenticator = options.authenticator;
|
|
316
|
+
this.authKey = options.authKey;
|
|
317
|
+
}
|
|
318
|
+
async getMetadata() {
|
|
319
|
+
const token = await this.authenticator.getAccessToken();
|
|
320
|
+
const metadata = new _grpc_grpc_js.Metadata();
|
|
321
|
+
metadata.add("authorization", `Bearer ${token}`);
|
|
322
|
+
if (this.authKey) metadata.add("x-auth-key", this.authKey);
|
|
323
|
+
return metadata;
|
|
324
|
+
}
|
|
325
|
+
call(method, request) {
|
|
326
|
+
return this.getMetadata().then((metadata) => {
|
|
327
|
+
return new Promise((resolve, reject) => {
|
|
328
|
+
const fn = this.grpcClient[method];
|
|
329
|
+
if (!fn) {
|
|
330
|
+
reject(/* @__PURE__ */ new Error(`Method "${method}" not found on gRPC client`));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
fn.call(this.grpcClient, request, metadata, (err, response) => {
|
|
334
|
+
if (err) reject(err);
|
|
335
|
+
else resolve(response);
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async getUsers(userIdList) {
|
|
341
|
+
return ((await this.call("getUsers", { userIdList })).users || []).map(convertUser);
|
|
342
|
+
}
|
|
343
|
+
async getPosts(postIdList) {
|
|
344
|
+
return ((await this.call("getPosts", { postIdList })).posts || []).map(convertPost);
|
|
345
|
+
}
|
|
346
|
+
async createPost(request) {
|
|
347
|
+
return convertPost((await this.call("createPost", request)).post);
|
|
348
|
+
}
|
|
349
|
+
async initiatePostMediaUpload(request) {
|
|
350
|
+
return this.call("initiatePostMediaUpload", request);
|
|
351
|
+
}
|
|
352
|
+
async getPostMediaStatus(mediaId) {
|
|
353
|
+
return this.call("getPostMediaStatus", { mediaId });
|
|
354
|
+
}
|
|
355
|
+
async sendChatMessage(request) {
|
|
356
|
+
return convertChatMessage((await this.call("sendChatMessage", request)).message);
|
|
357
|
+
}
|
|
358
|
+
async getStamps(request) {
|
|
359
|
+
return ((await this.call("getStamps", request || {})).officialStampSets || []).map(convertOfficialStampSet);
|
|
360
|
+
}
|
|
361
|
+
async addStampToPost(postId, stampId) {
|
|
362
|
+
return convertPost((await this.call("addStampToPost", {
|
|
363
|
+
postId,
|
|
364
|
+
stampId
|
|
365
|
+
})).post);
|
|
366
|
+
}
|
|
367
|
+
close() {
|
|
368
|
+
this.grpcClient.close();
|
|
369
|
+
}
|
|
538
370
|
};
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
var import_crypto = __toESM(require("crypto"), 1);
|
|
543
|
-
var TIMESTAMP_TOLERANCE = 300;
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/webhook.ts
|
|
373
|
+
const TIMESTAMP_TOLERANCE = 300;
|
|
544
374
|
var WebhookServer = class {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
else resolve();
|
|
671
|
-
});
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
get address() {
|
|
675
|
-
return `:${this.port}`;
|
|
676
|
-
}
|
|
677
|
-
get httpServer() {
|
|
678
|
-
return this.server;
|
|
679
|
-
}
|
|
680
|
-
get eventHandlerFunc() {
|
|
681
|
-
return this.handleEvent.bind(this);
|
|
682
|
-
}
|
|
375
|
+
server;
|
|
376
|
+
port;
|
|
377
|
+
publicKey;
|
|
378
|
+
handler;
|
|
379
|
+
syncHandling;
|
|
380
|
+
constructor(options) {
|
|
381
|
+
this.port = options.port || 8080;
|
|
382
|
+
this.handler = options.handler;
|
|
383
|
+
this.syncHandling = options.syncHandling || false;
|
|
384
|
+
const derPrefix = Buffer.from("302a300506032b6570032100", "hex");
|
|
385
|
+
const derKey = Buffer.concat([derPrefix, options.publicKey]);
|
|
386
|
+
this.publicKey = crypto.default.createPublicKey({
|
|
387
|
+
key: derKey,
|
|
388
|
+
format: "der",
|
|
389
|
+
type: "spki"
|
|
390
|
+
});
|
|
391
|
+
this.server = http.default.createServer(this.requestListener.bind(this));
|
|
392
|
+
}
|
|
393
|
+
async requestListener(req, res) {
|
|
394
|
+
if (req.method === "GET" && req.url === "/healthz") {
|
|
395
|
+
res.writeHead(200);
|
|
396
|
+
res.end("OK");
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (req.method === "POST" && req.url === "/events") {
|
|
400
|
+
await this.handleEvent(req, res);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
res.writeHead(404);
|
|
404
|
+
res.end("Not Found");
|
|
405
|
+
}
|
|
406
|
+
async handleEvent(req, res) {
|
|
407
|
+
const signatureBase64 = req.headers["x-mixi2-application-event-signature"];
|
|
408
|
+
if (!signatureBase64) {
|
|
409
|
+
res.writeHead(401);
|
|
410
|
+
res.end("missing x-mixi2-application-event-signature");
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const signature = Buffer.from(signatureBase64, "base64");
|
|
414
|
+
if (signature.length === 0) {
|
|
415
|
+
res.writeHead(401);
|
|
416
|
+
res.end("x-mixi2-application-event-signature is invalid");
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const timestamp = req.headers["x-mixi2-application-event-timestamp"];
|
|
420
|
+
if (!timestamp) {
|
|
421
|
+
res.writeHead(401);
|
|
422
|
+
res.end("missing x-mixi2-application-event-timestamp");
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const unixTime = parseInt(timestamp, 10);
|
|
426
|
+
if (isNaN(unixTime)) {
|
|
427
|
+
res.writeHead(401);
|
|
428
|
+
res.end("x-mixi2-application-event-timestamp is invalid");
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const diff = Math.floor(Date.now() / 1e3) - unixTime;
|
|
432
|
+
if (diff > TIMESTAMP_TOLERANCE) {
|
|
433
|
+
res.writeHead(401);
|
|
434
|
+
res.end("x-mixi2-application-event-timestamp is too old");
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (diff < -TIMESTAMP_TOLERANCE) {
|
|
438
|
+
res.writeHead(401);
|
|
439
|
+
res.end("x-mixi2-application-event-timestamp is in the future");
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const body = await new Promise((resolve, reject) => {
|
|
443
|
+
const chunks = [];
|
|
444
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
445
|
+
req.on("end", () => resolve(Buffer.concat(chunks)));
|
|
446
|
+
req.on("error", reject);
|
|
447
|
+
});
|
|
448
|
+
const dataToVerify = Buffer.concat([body, Buffer.from(timestamp)]);
|
|
449
|
+
if (!crypto.default.verify(null, dataToVerify, this.publicKey, signature)) {
|
|
450
|
+
res.writeHead(401);
|
|
451
|
+
res.end("Signature is invalid");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
let events;
|
|
455
|
+
try {
|
|
456
|
+
events = (getSendEventRequestType().decode(new Uint8Array(body)).events || []).map(convertEvent);
|
|
457
|
+
} catch {
|
|
458
|
+
res.writeHead(400);
|
|
459
|
+
res.end("Failed to parse request body");
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
res.writeHead(204);
|
|
463
|
+
res.end();
|
|
464
|
+
for (const event of events) {
|
|
465
|
+
if (event.eventType === require_types.EventType.PING) continue;
|
|
466
|
+
if (this.syncHandling) try {
|
|
467
|
+
await this.handler.handle(event);
|
|
468
|
+
} catch (err) {
|
|
469
|
+
console.error(`Failed to handle event ${event.eventId}:`, err);
|
|
470
|
+
}
|
|
471
|
+
else Promise.resolve(this.handler.handle(event)).catch((err) => {
|
|
472
|
+
console.error(`Failed to handle event ${event.eventId}:`, err);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
start() {
|
|
477
|
+
return new Promise((resolve) => {
|
|
478
|
+
this.server.listen(this.port, () => {
|
|
479
|
+
resolve();
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
shutdown() {
|
|
484
|
+
return new Promise((resolve, reject) => {
|
|
485
|
+
this.server.close((err) => {
|
|
486
|
+
if (err) reject(err);
|
|
487
|
+
else resolve();
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
get address() {
|
|
492
|
+
return `:${this.port}`;
|
|
493
|
+
}
|
|
494
|
+
get httpServer() {
|
|
495
|
+
return this.server;
|
|
496
|
+
}
|
|
497
|
+
get eventHandlerFunc() {
|
|
498
|
+
return this.handleEvent.bind(this);
|
|
499
|
+
}
|
|
683
500
|
};
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
var grpc3 = __toESM(require("@grpc/grpc-js"), 1);
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/stream.ts
|
|
687
503
|
var StreamWatcher = class {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
try {
|
|
770
|
-
stream = await this.reconnect();
|
|
771
|
-
setupStream(stream);
|
|
772
|
-
} catch (reconnectErr) {
|
|
773
|
-
reject(reconnectErr);
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
s.on("error", handleDisconnect);
|
|
777
|
-
s.on("end", handleDisconnect);
|
|
778
|
-
};
|
|
779
|
-
setupStream(stream);
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
handleEvent(handler, event) {
|
|
783
|
-
Promise.resolve(handler.handle(event)).catch((err) => {
|
|
784
|
-
console.error(`Failed to handle event ${event.eventId}:`, err);
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
stop() {
|
|
788
|
-
this.aborted = true;
|
|
789
|
-
this.streamClient.close();
|
|
790
|
-
}
|
|
504
|
+
authenticator;
|
|
505
|
+
authKey;
|
|
506
|
+
streamClient;
|
|
507
|
+
maxRetries;
|
|
508
|
+
aborted = false;
|
|
509
|
+
constructor(options) {
|
|
510
|
+
this.streamClient = new (getStreamServiceClient())(options.streamAddress, _grpc_grpc_js.credentials.createSsl());
|
|
511
|
+
this.authenticator = options.authenticator;
|
|
512
|
+
this.authKey = options.authKey;
|
|
513
|
+
this.maxRetries = options.maxRetries ?? 3;
|
|
514
|
+
}
|
|
515
|
+
async getMetadata() {
|
|
516
|
+
const token = await this.authenticator.getAccessToken();
|
|
517
|
+
const metadata = new _grpc_grpc_js.Metadata();
|
|
518
|
+
metadata.add("authorization", `Bearer ${token}`);
|
|
519
|
+
if (this.authKey) metadata.add("x-auth-key", this.authKey);
|
|
520
|
+
return metadata;
|
|
521
|
+
}
|
|
522
|
+
async connect() {
|
|
523
|
+
const metadata = await this.getMetadata();
|
|
524
|
+
const fn = this.streamClient["subscribeEvents"];
|
|
525
|
+
if (!fn) throw new Error("subscribeEvents method not found on stream client");
|
|
526
|
+
return fn.call(this.streamClient, {}, metadata);
|
|
527
|
+
}
|
|
528
|
+
async reconnect() {
|
|
529
|
+
const maxRetries = this.maxRetries;
|
|
530
|
+
let lastError;
|
|
531
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
532
|
+
if (this.aborted) throw new Error("Watcher aborted");
|
|
533
|
+
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1e3));
|
|
534
|
+
try {
|
|
535
|
+
return await this.connect();
|
|
536
|
+
} catch (err) {
|
|
537
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
538
|
+
console.warn(`Reconnect attempt ${i + 1}/${maxRetries} failed:`, lastError.message);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
throw lastError || /* @__PURE__ */ new Error("Failed to reconnect");
|
|
542
|
+
}
|
|
543
|
+
async watch(handler) {
|
|
544
|
+
this.aborted = false;
|
|
545
|
+
let stream = await this.connect();
|
|
546
|
+
return new Promise((resolve, reject) => {
|
|
547
|
+
const setupStream = (s) => {
|
|
548
|
+
s.on("data", (response) => {
|
|
549
|
+
const events = (response.events || []).map(convertEvent);
|
|
550
|
+
for (const event of events) {
|
|
551
|
+
if (event.eventType === require_types.EventType.PING) continue;
|
|
552
|
+
this.handleEvent(handler, event);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
let disconnected = false;
|
|
556
|
+
const handleDisconnect = async () => {
|
|
557
|
+
if (disconnected) return;
|
|
558
|
+
disconnected = true;
|
|
559
|
+
if (this.aborted) {
|
|
560
|
+
resolve();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
stream = await this.reconnect();
|
|
565
|
+
setupStream(stream);
|
|
566
|
+
} catch (reconnectErr) {
|
|
567
|
+
reject(reconnectErr);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
s.on("error", handleDisconnect);
|
|
571
|
+
s.on("end", handleDisconnect);
|
|
572
|
+
};
|
|
573
|
+
setupStream(stream);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
handleEvent(handler, event) {
|
|
577
|
+
Promise.resolve(handler.handle(event)).catch((err) => {
|
|
578
|
+
console.error(`Failed to handle event ${event.eventId}:`, err);
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
stop() {
|
|
582
|
+
this.aborted = true;
|
|
583
|
+
this.streamClient.close();
|
|
584
|
+
}
|
|
791
585
|
};
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
WebhookServer
|
|
812
|
-
});
|
|
586
|
+
//#endregion
|
|
587
|
+
exports.Client = Client;
|
|
588
|
+
exports.EventReason = require_types.EventReason;
|
|
589
|
+
exports.EventType = require_types.EventType;
|
|
590
|
+
exports.LanguageCode = require_types.LanguageCode;
|
|
591
|
+
exports.MediaType = require_types.MediaType;
|
|
592
|
+
exports.MediaUploadStatus = require_types.MediaUploadStatus;
|
|
593
|
+
exports.MediaUploadType = require_types.MediaUploadType;
|
|
594
|
+
exports.OAuth2Authenticator = OAuth2Authenticator;
|
|
595
|
+
exports.PostAccessLevel = require_types.PostAccessLevel;
|
|
596
|
+
exports.PostMaskType = require_types.PostMaskType;
|
|
597
|
+
exports.PostMediaType = require_types.PostMediaType;
|
|
598
|
+
exports.PostPublishingType = require_types.PostPublishingType;
|
|
599
|
+
exports.PostVisibility = require_types.PostVisibility;
|
|
600
|
+
exports.StampSetType = require_types.StampSetType;
|
|
601
|
+
exports.StreamWatcher = StreamWatcher;
|
|
602
|
+
exports.UserAccessLevel = require_types.UserAccessLevel;
|
|
603
|
+
exports.UserVisibility = require_types.UserVisibility;
|
|
604
|
+
exports.WebhookServer = WebhookServer;
|