@tma.js/init-data-node 1.1.7 → 1.1.8
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 +2 -2
- package/dist/index.mjs +4 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("node:crypto"),O=require("node:url");var
|
|
2
|
-
`)).digest().toString("hex")!==s)throw new Error("Signature is invalid")}exports.parse=x;exports.validate=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("node:crypto"),O=require("node:url");var T=Object.defineProperty,E=(e,t,r)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,I=(e,t,r)=>(E(e,typeof t!="symbol"?t+"":t,r),r);function c(){return new TypeError("Value has unexpected type")}class m extends Error{constructor(t,{cause:r,type:o}={}){super(`Unable to parse value${o?` as ${o}`:""}`,{cause:r}),I(this,"type"),this.value=t,Object.setPrototypeOf(this,m.prototype),this.type=o}}class w{constructor(t,r,o){this.parser=t,this.isOptional=r,this.type=o}parse(t){if(!(this.isOptional&&t===void 0))try{return this.parser(t)}catch(r){throw new m(t,{type:this.type,cause:r})}}optional(){return this.isOptional=!0,this}}function y(e,t){return()=>new w(e,!1,t)}class l extends Error{constructor(t,{cause:r,type:o}={}){super(`Unable to parse field "${t}"${o?` as ${o}`:""}`,{cause:r}),Object.setPrototypeOf(this,l.prototype)}}function v(e,t){const r={};for(const o in e){const a=e[o];if(!a)continue;let s,p;if(typeof a=="function"||"parse"in a)s=o,p=typeof a=="function"?a:a.parse.bind(a);else{const{type:i}=a;s=a.from||o,p=typeof i=="function"?i:i.parse.bind(i)}let u;const b=t(s);try{u=p(b)}catch(i){throw i instanceof m?new l(s,{type:i.type,cause:i}):new l(s,{cause:i})}u!==void 0&&(r[o]=u)}return r}const h=y(e=>{if(typeof e=="boolean")return e;const t=String(e);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;throw c()},"boolean"),f=y(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw c()},"number"),P=y(e=>e instanceof Date?e:new Date(f().parse(e)*1e3),"Date");function U(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw c();return t}function _(e,t){return new w(r=>{const o=U(r);return v(e,a=>o[a])},!1,t)}const n=y(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw c()},"string");function S(e,t){return new w(r=>{if(typeof r!="string"&&!(r instanceof URLSearchParams))throw c();const o=typeof r=="string"?new URLSearchParams(r):r;return v(e,a=>{const s=o.get(a);return s===null?void 0:s})},!1,t)}function $(){return _({id:f(),type:n(),title:n(),photoUrl:{type:n().optional(),from:"photo_url"},username:n().optional()},"Chat")}function D(){return _({addedToAttachmentMenu:{type:h().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:h().optional(),from:"allows_write_to_pm"},firstName:{type:n(),from:"first_name"},id:f(),isBot:{type:h().optional(),from:"is_bot"},isPremium:{type:h().optional(),from:"is_premium"},languageCode:{type:n().optional(),from:"language_code"},lastName:{type:n().optional(),from:"last_name"},photoUrl:{type:n().optional(),from:"photo_url"},username:n().optional()},"User")}function j(){return S({authDate:{type:P(),from:"auth_date"},canSendAfter:{type:f().optional(),from:"can_send_after"},chat:$().optional(),chatInstance:{type:n().optional(),from:"chat_instance"},chatType:{type:n().optional(),from:"chat_type"},hash:n(),queryId:{type:n().optional(),from:"query_id"},receiver:D().optional(),startParam:{type:n().optional(),from:"start_param"},user:D().optional()},"InitData")}function x(e){return j().parse(e)}S({contact:_({userId:{type:f(),from:"user_id"},phoneNumber:{type:n(),from:"phone_number"},firstName:{type:n(),from:"first_name"},lastName:{type:n().optional(),from:"last_name"}}),authDate:{type:P(),from:"auth_date"},hash:n()});function A(e,t,r={}){const o=typeof e=="string"?new O.URLSearchParams(e):e;let a=new Date(0),s="";const p=[];if(o.forEach((i,d)=>{if(d==="hash"){s=i;return}if(d==="auth_date"){const g=parseInt(i,10);if(Number.isNaN(g))throw new TypeError('"auth_date" should present integer');a=new Date(g*1e3)}p.push(`${d}=${i}`)}),s.length===0)throw new Error('"hash" is empty or not found');if(a.getTime()===0)throw new Error('"auth_date" is empty or not found');const{expiresIn:u=86400}=r;if(u>0&&a.getTime()+u*1e3<new Date().getTime())throw new Error("Init data expired");if(p.sort(),N.createHmac("sha256",N.createHmac("sha256","WebAppData").update(t).digest()).update(p.join(`
|
|
2
|
+
`)).digest().toString("hex")!==s)throw new Error("Signature is invalid")}exports.parse=x;exports.validate=A;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createHmac as N } from "node:crypto";
|
|
2
2
|
import { URLSearchParams as E } from "node:url";
|
|
3
|
-
var O = Object.defineProperty,
|
|
3
|
+
var O = Object.defineProperty, T = (e, t, r) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, U = (e, t, r) => (T(e, typeof t != "symbol" ? t + "" : t, r), r);
|
|
4
4
|
function f() {
|
|
5
5
|
return new TypeError("Value has unexpected type");
|
|
6
6
|
}
|
|
7
7
|
class l extends Error {
|
|
8
8
|
constructor(t, { cause: r, type: o } = {}) {
|
|
9
|
-
super(`Unable to parse value${o ? ` as ${o}` : ""}`, { cause: r }),
|
|
9
|
+
super(`Unable to parse value${o ? ` as ${o}` : ""}`, { cause: r }), U(this, "type"), this.value = t, Object.setPrototypeOf(this, l.prototype), this.type = o;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
class w {
|
|
@@ -107,7 +107,7 @@ function S(e, t) {
|
|
|
107
107
|
});
|
|
108
108
|
}, !1, t);
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function $() {
|
|
111
111
|
return _({
|
|
112
112
|
id: c(),
|
|
113
113
|
type: n(),
|
|
@@ -167,7 +167,7 @@ function x() {
|
|
|
167
167
|
type: c().optional(),
|
|
168
168
|
from: "can_send_after"
|
|
169
169
|
},
|
|
170
|
-
chat:
|
|
170
|
+
chat: $().optional(),
|
|
171
171
|
chatInstance: {
|
|
172
172
|
type: n().optional(),
|
|
173
173
|
from: "chat_instance"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tma.js/init-data-node",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "TypeScript Node library to operate with Telegram init data.",
|
|
5
5
|
"author": "Vladislav Kibenko <wolfram.deus@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Telegram-Mini-Apps/tma.js#readme",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@tma.js/sdk": "^1.4.
|
|
49
|
+
"@tma.js/sdk": "^1.4.7"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"test": "vitest --run",
|