@tma.js/init-data-node 1.2.4 → 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({
@@ -56,7 +56,7 @@ function N({
56
56
  })
57
57
  );
58
58
  }
59
- function W(t, e, n) {
59
+ function B(t, e, n) {
60
60
  const r = N({
61
61
  ...t,
62
62
  authDate: n
@@ -64,7 +64,7 @@ function W(t, e, n) {
64
64
  return r.append("hash", E(o.join(`
65
65
  `), e)), r.toString();
66
66
  }
67
- function B(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,11 +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");
217
+ throw d();
218
+ }, "string"), I = h((t) => q(a().parse(t)), "rgb");
219
219
  p({
220
220
  req_id: a(),
221
221
  data: (t) => t === null ? t : a().optional().parse(t)
@@ -226,7 +226,7 @@ p({
226
226
  }), p({ slug: a(), status: a() }), p({ status: a() }), p({ data: a().optional() }), p({
227
227
  theme_params: (t) => {
228
228
  const e = I().optional();
229
- 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), {});
230
230
  }
231
231
  }), p({
232
232
  height: f(),
@@ -234,11 +234,11 @@ p({
234
234
  is_state_stable: c(),
235
235
  is_expanded: c()
236
236
  }), p({ status: a() });
237
- const O = d((t) => t instanceof Date ? t : new Date(f().parse(t) * 1e3), "Date");
237
+ const O = h((t) => t instanceof Date ? t : new Date(f().parse(t) * 1e3), "Date");
238
238
  function A(t, e) {
239
239
  return new w((n) => {
240
240
  if (typeof n != "string" && !(n instanceof URLSearchParams))
241
- throw h();
241
+ throw d();
242
242
  const r = typeof n == "string" ? new URLSearchParams(n) : n;
243
243
  return D(t, (o) => {
244
244
  const i = r.get(o);
@@ -246,7 +246,7 @@ function A(t, e) {
246
246
  });
247
247
  }, !1, e);
248
248
  }
249
- const j = p({
249
+ const C = p({
250
250
  id: f(),
251
251
  type: a(),
252
252
  title: a(),
@@ -291,7 +291,7 @@ const j = p({
291
291
  },
292
292
  username: a().optional()
293
293
  }, "User").optional();
294
- function C() {
294
+ function L() {
295
295
  return A({
296
296
  authDate: {
297
297
  type: O(),
@@ -301,7 +301,7 @@ function C() {
301
301
  type: f().optional(),
302
302
  from: "can_send_after"
303
303
  },
304
- chat: j,
304
+ chat: C,
305
305
  chatInstance: {
306
306
  type: a().optional(),
307
307
  from: "chat_instance"
@@ -324,12 +324,12 @@ function C() {
324
324
  }, "InitData");
325
325
  }
326
326
  function M(t) {
327
- return C().parse(t);
327
+ return L().parse(t);
328
328
  }
329
329
  export {
330
330
  M as parse,
331
- W as sign,
331
+ B as sign,
332
332
  E as signData,
333
- B as validate
333
+ J as validate
334
334
  };
335
335
  //# sourceMappingURL=index.js.map