@tma.js/init-data-node 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ function E(t, e) {
|
|
|
6
6
|
b("sha256", "WebAppData").update(e).digest()
|
|
7
7
|
).update(t).digest().toString("hex");
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function U(t) {
|
|
10
10
|
const e = {};
|
|
11
11
|
for (const n in t) {
|
|
12
12
|
const r = t[n];
|
|
@@ -14,7 +14,7 @@ function $(t) {
|
|
|
14
14
|
}
|
|
15
15
|
return e;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function S(t) {
|
|
18
18
|
return t ? JSON.stringify({
|
|
19
19
|
added_to_attachment_menu: t.addedToAttachmentMenu,
|
|
20
20
|
allows_write_to_pm: t.allowsWriteToPm,
|
|
@@ -36,7 +36,7 @@ function N({
|
|
|
36
36
|
}) {
|
|
37
37
|
var o;
|
|
38
38
|
return new m(
|
|
39
|
-
|
|
39
|
+
U({
|
|
40
40
|
auth_date: r.authDate ? (+r.authDate / 1e3 | 0).toString() : void 0,
|
|
41
41
|
can_send_after: (o = r.canSendAfter) == null ? void 0 : o.toString(),
|
|
42
42
|
chat: t ? JSON.stringify({
|
|
@@ -50,13 +50,13 @@ function N({
|
|
|
50
50
|
chat_type: r.chatType || void 0,
|
|
51
51
|
hash: r.hash,
|
|
52
52
|
query_id: r.queryId,
|
|
53
|
-
receiver:
|
|
53
|
+
receiver: S(e),
|
|
54
54
|
start_param: r.startParam || void 0,
|
|
55
|
-
user:
|
|
55
|
+
user: S(n)
|
|
56
56
|
})
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function W(t, e, n) {
|
|
60
60
|
const r = N({
|
|
61
61
|
...t,
|
|
62
62
|
authDate: n
|
|
@@ -64,7 +64,7 @@ function B(t, e, n) {
|
|
|
64
64
|
return r.append("hash", E(o.join(`
|
|
65
65
|
`), e)), r.toString();
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function B(t, e, n = {}) {
|
|
68
68
|
let r, o;
|
|
69
69
|
const i = [];
|
|
70
70
|
if (new m(
|
|
@@ -100,9 +100,9 @@ class _ extends Error {
|
|
|
100
100
|
function y(t, e, n) {
|
|
101
101
|
return new _(t, e, n);
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
const R = "ERR_UNEXPECTED_TYPE", P = "ERR_PARSE";
|
|
104
104
|
function h() {
|
|
105
|
-
return y(
|
|
105
|
+
return y(R, "Value has unexpected type");
|
|
106
106
|
}
|
|
107
107
|
class w {
|
|
108
108
|
constructor(e, n, r) {
|
|
@@ -165,7 +165,7 @@ function D(t, e) {
|
|
|
165
165
|
}
|
|
166
166
|
return n;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function $(t) {
|
|
169
169
|
let e = t;
|
|
170
170
|
if (typeof e == "string" && (e = JSON.parse(e)), typeof e != "object" || e === null || Array.isArray(e))
|
|
171
171
|
throw h();
|
|
@@ -173,7 +173,7 @@ function U(t) {
|
|
|
173
173
|
}
|
|
174
174
|
function p(t, e) {
|
|
175
175
|
return new w((n) => {
|
|
176
|
-
const r =
|
|
176
|
+
const r = $(n);
|
|
177
177
|
return D(t, (o) => r[o]);
|
|
178
178
|
}, !1, e);
|
|
179
179
|
}
|
|
@@ -187,17 +187,17 @@ const f = d((t) => {
|
|
|
187
187
|
}
|
|
188
188
|
throw h();
|
|
189
189
|
}, "number");
|
|
190
|
-
function
|
|
190
|
+
function T(t) {
|
|
191
191
|
return /^#[\da-f]{6}$/i.test(t);
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function q(t) {
|
|
194
194
|
return /^#[\da-f]{3}$/i.test(t);
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function x(t) {
|
|
197
197
|
const e = t.replace(/\s/g, "").toLowerCase();
|
|
198
|
-
if (
|
|
198
|
+
if (T(e))
|
|
199
199
|
return e;
|
|
200
|
-
if (
|
|
200
|
+
if (q(e)) {
|
|
201
201
|
let r = "#";
|
|
202
202
|
for (let o = 0; o < 3; o += 1)
|
|
203
203
|
r += e[1 + o].repeat(2);
|
|
@@ -215,9 +215,7 @@ const a = d((t) => {
|
|
|
215
215
|
if (typeof t == "string" || typeof t == "number")
|
|
216
216
|
return t.toString();
|
|
217
217
|
throw h();
|
|
218
|
-
}, "string"), I = d((t) =>
|
|
219
|
-
button_id: (t) => t == null ? void 0 : a().parse(t)
|
|
220
|
-
});
|
|
218
|
+
}, "string"), I = d((t) => x(a().parse(t)), "rgb");
|
|
221
219
|
p({
|
|
222
220
|
req_id: a(),
|
|
223
221
|
data: (t) => t === null ? t : a().optional().parse(t)
|
|
@@ -225,28 +223,19 @@ p({
|
|
|
225
223
|
req_id: a(),
|
|
226
224
|
result: (t) => t,
|
|
227
225
|
error: a().optional()
|
|
228
|
-
}), p({
|
|
229
|
-
slug: a(),
|
|
230
|
-
status: a()
|
|
231
|
-
}), p({
|
|
232
|
-
status: a()
|
|
233
|
-
}), p({
|
|
234
|
-
data: a().optional()
|
|
235
|
-
}), p({
|
|
226
|
+
}), p({ slug: a(), status: a() }), p({ status: a() }), p({ data: a().optional() }), p({
|
|
236
227
|
theme_params: (t) => {
|
|
237
228
|
const e = I().optional();
|
|
238
|
-
return Object.entries(
|
|
229
|
+
return Object.entries($(t)).reduce((n, [r, o]) => (n[r] = e.parse(o), n), {});
|
|
239
230
|
}
|
|
240
231
|
}), p({
|
|
241
232
|
height: f(),
|
|
242
233
|
width: (t) => t == null ? window.innerWidth : f().parse(t),
|
|
243
234
|
is_state_stable: c(),
|
|
244
235
|
is_expanded: c()
|
|
245
|
-
}), p({
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const A = d((t) => t instanceof Date ? t : new Date(f().parse(t) * 1e3), "Date");
|
|
249
|
-
function C(t, e) {
|
|
236
|
+
}), p({ status: a() });
|
|
237
|
+
const O = d((t) => t instanceof Date ? t : new Date(f().parse(t) * 1e3), "Date");
|
|
238
|
+
function A(t, e) {
|
|
250
239
|
return new w((n) => {
|
|
251
240
|
if (typeof n != "string" && !(n instanceof URLSearchParams))
|
|
252
241
|
throw h();
|
|
@@ -257,7 +246,7 @@ function C(t, e) {
|
|
|
257
246
|
});
|
|
258
247
|
}, !1, e);
|
|
259
248
|
}
|
|
260
|
-
const
|
|
249
|
+
const j = p({
|
|
261
250
|
id: f(),
|
|
262
251
|
type: a(),
|
|
263
252
|
title: a(),
|
|
@@ -266,7 +255,7 @@ const J = p({
|
|
|
266
255
|
from: "photo_url"
|
|
267
256
|
},
|
|
268
257
|
username: a().optional()
|
|
269
|
-
}, "Chat").optional(),
|
|
258
|
+
}, "Chat").optional(), v = p({
|
|
270
259
|
addedToAttachmentMenu: {
|
|
271
260
|
type: c().optional(),
|
|
272
261
|
from: "added_to_attachment_menu"
|
|
@@ -302,17 +291,17 @@ const J = p({
|
|
|
302
291
|
},
|
|
303
292
|
username: a().optional()
|
|
304
293
|
}, "User").optional();
|
|
305
|
-
function
|
|
306
|
-
return
|
|
294
|
+
function C() {
|
|
295
|
+
return A({
|
|
307
296
|
authDate: {
|
|
308
|
-
type:
|
|
297
|
+
type: O(),
|
|
309
298
|
from: "auth_date"
|
|
310
299
|
},
|
|
311
300
|
canSendAfter: {
|
|
312
301
|
type: f().optional(),
|
|
313
302
|
from: "can_send_after"
|
|
314
303
|
},
|
|
315
|
-
chat:
|
|
304
|
+
chat: j,
|
|
316
305
|
chatInstance: {
|
|
317
306
|
type: a().optional(),
|
|
318
307
|
from: "chat_instance"
|
|
@@ -326,21 +315,21 @@ function L() {
|
|
|
326
315
|
type: a().optional(),
|
|
327
316
|
from: "query_id"
|
|
328
317
|
},
|
|
329
|
-
receiver:
|
|
318
|
+
receiver: v,
|
|
330
319
|
startParam: {
|
|
331
320
|
type: a().optional(),
|
|
332
321
|
from: "start_param"
|
|
333
322
|
},
|
|
334
|
-
user:
|
|
323
|
+
user: v
|
|
335
324
|
}, "InitData");
|
|
336
325
|
}
|
|
337
|
-
function
|
|
338
|
-
return
|
|
326
|
+
function M(t) {
|
|
327
|
+
return C().parse(t);
|
|
339
328
|
}
|
|
340
329
|
export {
|
|
341
|
-
|
|
342
|
-
|
|
330
|
+
M as parse,
|
|
331
|
+
W as sign,
|
|
343
332
|
E as signData,
|
|
344
|
-
|
|
333
|
+
B as validate
|
|
345
334
|
};
|
|
346
335
|
//# sourceMappingURL=index.js.map
|