@tma.js/init-data-node 1.2.3 → 1.2.5

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.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 U(t) {
9
+ function $(t) {
10
10
  const e = {};
11
11
  for (const n in t) {
12
12
  const r = t[n];
@@ -36,7 +36,7 @@ function N({
36
36
  }) {
37
37
  var o;
38
38
  return new m(
39
- U({
39
+ $({
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({
@@ -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 G(t, e, n = {}) {
67
+ function J(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 R = "ERR_UNEXPECTED_TYPE", P = "ERR_PARSE";
104
- function h() {
105
- return y(R, "Value has unexpected type");
103
+ const x = "ERR_UNEXPECTED_TYPE", P = "ERR_PARSE";
104
+ function d() {
105
+ return y(x, "Value has unexpected type");
106
106
  }
107
107
  class w {
108
108
  constructor(e, n, r) {
@@ -130,10 +130,10 @@ class w {
130
130
  return this.isOptional = !0, this;
131
131
  }
132
132
  }
133
- function d(t, e) {
133
+ function h(t, e) {
134
134
  return () => new w(t, !1, e);
135
135
  }
136
- const c = d((t) => {
136
+ const c = h((t) => {
137
137
  if (typeof t == "boolean")
138
138
  return t;
139
139
  const e = String(t);
@@ -141,7 +141,7 @@ const c = d((t) => {
141
141
  return !0;
142
142
  if (e === "0" || e === "false")
143
143
  return !1;
144
- throw h();
144
+ throw d();
145
145
  }, "boolean");
146
146
  function D(t, e) {
147
147
  const n = {};
@@ -165,19 +165,19 @@ function D(t, e) {
165
165
  }
166
166
  return n;
167
167
  }
168
- function $(t) {
168
+ function U(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
- throw h();
171
+ throw d();
172
172
  return e;
173
173
  }
174
174
  function p(t, e) {
175
175
  return new w((n) => {
176
- const r = $(n);
176
+ const r = U(n);
177
177
  return D(t, (o) => r[o]);
178
178
  }, !1, e);
179
179
  }
180
- const f = d((t) => {
180
+ const f = h((t) => {
181
181
  if (typeof t == "number")
182
182
  return t;
183
183
  if (typeof t == "string") {
@@ -185,19 +185,19 @@ const f = d((t) => {
185
185
  if (!Number.isNaN(e))
186
186
  return e;
187
187
  }
188
- throw h();
188
+ throw d();
189
189
  }, "number");
190
- function T(t) {
190
+ function R(t) {
191
191
  return /^#[\da-f]{6}$/i.test(t);
192
192
  }
193
- function q(t) {
193
+ function T(t) {
194
194
  return /^#[\da-f]{3}$/i.test(t);
195
195
  }
196
- function x(t) {
196
+ function q(t) {
197
197
  const e = t.replace(/\s/g, "").toLowerCase();
198
- if (T(e))
198
+ if (R(e))
199
199
  return e;
200
- if (q(e)) {
200
+ if (T(e)) {
201
201
  let r = "#";
202
202
  for (let o = 0; o < 3; o += 1)
203
203
  r += e[1 + o].repeat(2);
@@ -211,13 +211,11 @@ function x(t) {
211
211
  return r + (i.length === 1 ? "0" : "") + i;
212
212
  }, "#");
213
213
  }
214
- const a = d((t) => {
214
+ const a = h((t) => {
215
215
  if (typeof t == "string" || typeof t == "number")
216
216
  return t.toString();
217
- throw h();
218
- }, "string"), I = d((t) => x(a().parse(t)), "rgb"), O = p({
219
- button_id: (t) => t == null ? void 0 : a().parse(t)
220
- });
217
+ throw d();
218
+ }, "string"), I = h((t) => q(a().parse(t)), "rgb");
221
219
  p({
222
220
  req_id: a(),
223
221
  data: (t) => t === null ? t : a().optional().parse(t)
@@ -225,31 +223,22 @@ 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($(t)).reduce((n, [r, o]) => (n[r] = e.parse(o), n), {});
229
+ return Object.entries(U(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
- status: a()
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 = h((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
- throw h();
241
+ throw d();
253
242
  const r = typeof n == "string" ? new URLSearchParams(n) : n;
254
243
  return D(t, (o) => {
255
244
  const i = r.get(o);
@@ -257,7 +246,7 @@ function C(t, e) {
257
246
  });
258
247
  }, !1, e);
259
248
  }
260
- const J = p({
249
+ const C = p({
261
250
  id: f(),
262
251
  type: a(),
263
252
  title: a(),
@@ -303,16 +292,16 @@ const J = p({
303
292
  username: a().optional()
304
293
  }, "User").optional();
305
294
  function L() {
306
- return C({
295
+ return A({
307
296
  authDate: {
308
- type: A(),
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: J,
304
+ chat: C,
316
305
  chatInstance: {
317
306
  type: a().optional(),
318
307
  from: "chat_instance"
@@ -341,6 +330,6 @@ export {
341
330
  M as parse,
342
331
  B as sign,
343
332
  E as signData,
344
- G as validate
333
+ J as validate
345
334
  };
346
335
  //# sourceMappingURL=index.js.map