@tma.js/init-data 0.2.14 → 0.2.16
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/dts/parsing.d.ts +11 -0
- package/dist/{types → dts}/types.d.ts +15 -2
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +16 -20
- package/src/parsing.ts +46 -23
- package/src/types.ts +24 -2
- package/dist/lib/browser.js +0 -2
- package/dist/lib/browser.js.map +0 -1
- package/dist/lib/index.cjs +0 -2
- package/dist/lib/index.cjs.map +0 -1
- package/dist/lib/index.mjs +0 -2
- package/dist/lib/index.mjs.map +0 -1
- package/dist/types/parsing.d.ts +0 -5
- /package/dist/{types → dts}/index.d.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InitData } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parser used to parse init data, presented as search params.
|
|
4
|
+
* @deprecated Use `parse` method instead.
|
|
5
|
+
*/
|
|
6
|
+
export declare const initData: import("@tma.js/parsing").ValueParser<InitData, false>;
|
|
7
|
+
/**
|
|
8
|
+
* Parses incoming value as init data.
|
|
9
|
+
* @param value - value to parse.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parse(value: string | URLSearchParams): InitData;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known type of chat.
|
|
3
|
+
*/
|
|
4
|
+
export type ChatType = 'sender' | 'private' | 'group' | 'supergroup' | 'channel' | string;
|
|
1
5
|
/**
|
|
2
6
|
* Describes user information.
|
|
3
7
|
* @see https://docs.telegram-mini-apps.com/docs/launch-params/init-data#user
|
|
@@ -77,16 +81,25 @@ export interface InitData {
|
|
|
77
81
|
*/
|
|
78
82
|
authDate: Date;
|
|
79
83
|
/**
|
|
80
|
-
*
|
|
84
|
+
* The number of seconds after which a message can be sent via the method answerWebAppQuery.
|
|
81
85
|
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
82
86
|
*/
|
|
83
|
-
canSendAfter?:
|
|
87
|
+
canSendAfter?: number;
|
|
84
88
|
/**
|
|
85
89
|
* An object containing data about the chat where the bot was launched via
|
|
86
90
|
* the attachment menu. Returned for supergroups, channels and group
|
|
87
91
|
* chats – only for Web Apps launched via the attachment menu.
|
|
88
92
|
*/
|
|
89
93
|
chat?: Chat;
|
|
94
|
+
/**
|
|
95
|
+
* The type of chat from which Mini App was opened.
|
|
96
|
+
*/
|
|
97
|
+
chatType?: ChatType;
|
|
98
|
+
/**
|
|
99
|
+
* A global identifier indicating the chat from which Mini App was
|
|
100
|
+
* opened. Returned only for applications opened by direct link.
|
|
101
|
+
*/
|
|
102
|
+
chatInstance?: string;
|
|
90
103
|
/**
|
|
91
104
|
* A hash of all passed parameters, which the bot server can use to
|
|
92
105
|
* check their validity.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { string as i, number as s, boolean as l, searchParams as m, date as h, json as u } from "@tma.js/parsing";
|
|
2
|
+
function t(e, p) {
|
|
3
|
+
return {
|
|
4
|
+
from: p,
|
|
5
|
+
type: e
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
const n = i(), a = i().optional(), c = s(), _ = s().optional(), o = l().optional();
|
|
9
|
+
function r() {
|
|
10
|
+
return u({
|
|
11
|
+
firstName: t(n, "first_name"),
|
|
12
|
+
id: c,
|
|
13
|
+
isBot: t(o, "is_bot"),
|
|
14
|
+
isPremium: t(o, "is_premium"),
|
|
15
|
+
lastName: t(a, "last_name"),
|
|
16
|
+
languageCode: t(a, "language_code"),
|
|
17
|
+
photoUrl: t(a, "photo_url"),
|
|
18
|
+
username: a
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function d() {
|
|
22
|
+
return u({
|
|
23
|
+
id: c,
|
|
24
|
+
type: n,
|
|
25
|
+
title: n,
|
|
26
|
+
photoUrl: t(a, "photo_url"),
|
|
27
|
+
username: a
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const f = m({
|
|
31
|
+
authDate: t(h(), "auth_date"),
|
|
32
|
+
hash: n,
|
|
33
|
+
user: r().optional(),
|
|
34
|
+
receiver: r().optional(),
|
|
35
|
+
chat: d().optional(),
|
|
36
|
+
chatType: t(a, "chat_type"),
|
|
37
|
+
chatInstance: t(a, "chat_instance"),
|
|
38
|
+
canSendAfter: t(_, "can_send_after"),
|
|
39
|
+
queryId: t(a, "query_id"),
|
|
40
|
+
startParam: t(a, "start_param")
|
|
41
|
+
});
|
|
42
|
+
function g(e) {
|
|
43
|
+
return f.parse(e);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
f as initData,
|
|
47
|
+
g as parse
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/parsing.ts"],"sourcesContent":["import {\n searchParams,\n json,\n string,\n number,\n boolean,\n date,\n type AnyParser,\n} from '@tma.js/parsing';\n\nimport type { InitData, User } from './types.js';\n\nfunction field<P extends AnyParser<any>>(parser: P, from?: string) {\n return {\n from,\n type: parser,\n };\n}\n\nconst str = string();\nconst strOptional = string().optional();\nconst num = number();\nconst numOptional = number().optional();\nconst boolOptional = boolean().optional();\n\nfunction user() {\n return json<User>({\n firstName: field(str, 'first_name'),\n id: num,\n isBot: field(boolOptional, 'is_bot'),\n isPremium: field(boolOptional, 'is_premium'),\n lastName: field(strOptional, 'last_name'),\n languageCode: field(strOptional, 'language_code'),\n photoUrl: field(strOptional, 'photo_url'),\n username: strOptional,\n });\n}\n\nfunction chat() {\n return json({\n id: num,\n type: str,\n title: str,\n photoUrl: field(strOptional, 'photo_url'),\n username: strOptional,\n });\n}\n\n/**\n * Parser used to parse init data, presented as search params.\n * @deprecated Use `parse` method instead.\n */\nexport const initData = searchParams<InitData>({\n authDate: field(date(), 'auth_date'),\n hash: str,\n user: user().optional(),\n receiver: user().optional(),\n chat: chat().optional(),\n chatType: field(strOptional, 'chat_type'),\n chatInstance: field(strOptional, 'chat_instance'),\n canSendAfter: field(numOptional, 'can_send_after'),\n queryId: field(strOptional, 'query_id'),\n startParam: field(strOptional, 'start_param'),\n});\n\n/**\n * Parses incoming value as init data.\n * @param value - value to parse.\n */\nexport function parse(value: string | URLSearchParams): InitData {\n return initData.parse(value);\n}\n"],"names":["field","parser","from","str","string","strOptional","num","number","numOptional","boolOptional","boolean","user","json","chat","initData","searchParams","date","parse","value"],"mappings":";AAYA,SAASA,EAAgCC,GAAWC,GAAe;AAC1D,SAAA;AAAA,IACL,MAAAA;AAAA,IACA,MAAMD;AAAA,EAAA;AAEV;AAEA,MAAME,IAAMC,EAAO,GACbC,IAAcD,IAAS,YACvBE,IAAMC,EAAO,GACbC,IAAcD,IAAS,YACvBE,IAAeC,IAAU;AAE/B,SAASC,IAAO;AACd,SAAOC,EAAW;AAAA,IAChB,WAAWZ,EAAMG,GAAK,YAAY;AAAA,IAClC,IAAIG;AAAA,IACJ,OAAON,EAAMS,GAAc,QAAQ;AAAA,IACnC,WAAWT,EAAMS,GAAc,YAAY;AAAA,IAC3C,UAAUT,EAAMK,GAAa,WAAW;AAAA,IACxC,cAAcL,EAAMK,GAAa,eAAe;AAAA,IAChD,UAAUL,EAAMK,GAAa,WAAW;AAAA,IACxC,UAAUA;AAAA,EAAA,CACX;AACH;AAEA,SAASQ,IAAO;AACd,SAAOD,EAAK;AAAA,IACV,IAAIN;AAAA,IACJ,MAAMH;AAAA,IACN,OAAOA;AAAA,IACP,UAAUH,EAAMK,GAAa,WAAW;AAAA,IACxC,UAAUA;AAAA,EAAA,CACX;AACH;AAMO,MAAMS,IAAWC,EAAuB;AAAA,EAC7C,UAAUf,EAAMgB,EAAK,GAAG,WAAW;AAAA,EACnC,MAAMb;AAAA,EACN,MAAMQ,EAAK,EAAE,SAAS;AAAA,EACtB,UAAUA,EAAK,EAAE,SAAS;AAAA,EAC1B,MAAME,EAAK,EAAE,SAAS;AAAA,EACtB,UAAUb,EAAMK,GAAa,WAAW;AAAA,EACxC,cAAcL,EAAMK,GAAa,eAAe;AAAA,EAChD,cAAcL,EAAMQ,GAAa,gBAAgB;AAAA,EACjD,SAASR,EAAMK,GAAa,UAAU;AAAA,EACtC,YAAYL,EAAMK,GAAa,aAAa;AAC9C,CAAC;AAMM,SAASY,EAAMC,GAA2C;AACxD,SAAAJ,EAAS,MAAMI,CAAK;AAC7B;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@tma.js/parsing")):typeof define=="function"&&define.amd?define(["exports","@tma.js/parsing"],t):(n=typeof globalThis<"u"?globalThis:n||self,t((n["@tma"]=n["@tma"]||{},n["@tma"]["js/init-data"]={}),n["@tma"]["js/parsing"]))})(this,function(n,t){"use strict";function e(i,f){return{from:f,type:i}}const o=t.string(),a=t.string().optional(),r=t.number(),m=t.number().optional(),s=t.boolean().optional();function u(){return t.json({firstName:e(o,"first_name"),id:r,isBot:e(s,"is_bot"),isPremium:e(s,"is_premium"),lastName:e(a,"last_name"),languageCode:e(a,"language_code"),photoUrl:e(a,"photo_url"),username:a})}function d(){return t.json({id:r,type:o,title:o,photoUrl:e(a,"photo_url"),username:a})}const c=t.searchParams({authDate:e(t.date(),"auth_date"),hash:o,user:u().optional(),receiver:u().optional(),chat:d().optional(),chatType:e(a,"chat_type"),chatInstance:e(a,"chat_instance"),canSendAfter:e(m,"can_send_after"),queryId:e(a,"query_id"),startParam:e(a,"start_param")});function p(i){return c.parse(i)}n.initData=c,n.parse=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
//# sourceMappingURL=index.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.cjs","sources":["../src/parsing.ts"],"sourcesContent":["import {\n searchParams,\n json,\n string,\n number,\n boolean,\n date,\n type AnyParser,\n} from '@tma.js/parsing';\n\nimport type { InitData, User } from './types.js';\n\nfunction field<P extends AnyParser<any>>(parser: P, from?: string) {\n return {\n from,\n type: parser,\n };\n}\n\nconst str = string();\nconst strOptional = string().optional();\nconst num = number();\nconst numOptional = number().optional();\nconst boolOptional = boolean().optional();\n\nfunction user() {\n return json<User>({\n firstName: field(str, 'first_name'),\n id: num,\n isBot: field(boolOptional, 'is_bot'),\n isPremium: field(boolOptional, 'is_premium'),\n lastName: field(strOptional, 'last_name'),\n languageCode: field(strOptional, 'language_code'),\n photoUrl: field(strOptional, 'photo_url'),\n username: strOptional,\n });\n}\n\nfunction chat() {\n return json({\n id: num,\n type: str,\n title: str,\n photoUrl: field(strOptional, 'photo_url'),\n username: strOptional,\n });\n}\n\n/**\n * Parser used to parse init data, presented as search params.\n * @deprecated Use `parse` method instead.\n */\nexport const initData = searchParams<InitData>({\n authDate: field(date(), 'auth_date'),\n hash: str,\n user: user().optional(),\n receiver: user().optional(),\n chat: chat().optional(),\n chatType: field(strOptional, 'chat_type'),\n chatInstance: field(strOptional, 'chat_instance'),\n canSendAfter: field(numOptional, 'can_send_after'),\n queryId: field(strOptional, 'query_id'),\n startParam: field(strOptional, 'start_param'),\n});\n\n/**\n * Parses incoming value as init data.\n * @param value - value to parse.\n */\nexport function parse(value: string | URLSearchParams): InitData {\n return initData.parse(value);\n}\n"],"names":["field","parser","from","str","string","strOptional","num","number","numOptional","boolOptional","boolean","user","json","chat","initData","searchParams","date","parse","value"],"mappings":"gVAYA,SAASA,EAAgCC,EAAWC,EAAe,CAC1D,MAAA,CACL,KAAAA,EACA,KAAMD,CAAA,CAEV,CAEA,MAAME,EAAMC,EAAO,OAAA,EACbC,EAAcD,EAAAA,SAAS,WACvBE,EAAMC,EAAO,OAAA,EACbC,EAAcD,EAAAA,SAAS,WACvBE,EAAeC,EAAAA,UAAU,WAE/B,SAASC,GAAO,CACd,OAAOC,OAAW,CAChB,UAAWZ,EAAMG,EAAK,YAAY,EAClC,GAAIG,EACJ,MAAON,EAAMS,EAAc,QAAQ,EACnC,UAAWT,EAAMS,EAAc,YAAY,EAC3C,SAAUT,EAAMK,EAAa,WAAW,EACxC,aAAcL,EAAMK,EAAa,eAAe,EAChD,SAAUL,EAAMK,EAAa,WAAW,EACxC,SAAUA,CAAA,CACX,CACH,CAEA,SAASQ,GAAO,CACd,OAAOD,OAAK,CACV,GAAIN,EACJ,KAAMH,EACN,MAAOA,EACP,SAAUH,EAAMK,EAAa,WAAW,EACxC,SAAUA,CAAA,CACX,CACH,CAMa,MAAAS,EAAWC,EAAAA,aAAuB,CAC7C,SAAUf,EAAMgB,OAAK,EAAG,WAAW,EACnC,KAAMb,EACN,KAAMQ,EAAK,EAAE,SAAS,EACtB,SAAUA,EAAK,EAAE,SAAS,EAC1B,KAAME,EAAK,EAAE,SAAS,EACtB,SAAUb,EAAMK,EAAa,WAAW,EACxC,aAAcL,EAAMK,EAAa,eAAe,EAChD,aAAcL,EAAMQ,EAAa,gBAAgB,EACjD,QAASR,EAAMK,EAAa,UAAU,EACtC,WAAYL,EAAMK,EAAa,aAAa,CAC9C,CAAC,EAMM,SAASY,EAAMC,EAA2C,CACxD,OAAAJ,EAAS,MAAMI,CAAK,CAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tma.js/init-data",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "Frontend TypeScript library to make work with Web Apps init data easier.",
|
|
5
5
|
"author": "Vladislav Kibenko <wolfram.deus@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Telegram-Mini-Apps/tma.js#readme",
|
|
@@ -24,38 +24,34 @@
|
|
|
24
24
|
"dist",
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
|
-
"main": "dist/
|
|
28
|
-
"browser": "dist/
|
|
29
|
-
"module": "dist/
|
|
30
|
-
"types": "dist/
|
|
27
|
+
"main": "./dist/index.umd.cjs",
|
|
28
|
+
"browser": "./dist/index.umd.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/dts/index.d.ts",
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
36
|
-
"default": "./dist/
|
|
37
|
-
},
|
|
38
|
-
"./*": {
|
|
39
|
-
"types": "./dist/types/*.d.ts",
|
|
40
|
-
"import": "./dist/lib/*.mjs",
|
|
41
|
-
"require": "./dist/lib/*.cjs",
|
|
42
|
-
"default": "./dist/lib/*.cjs"
|
|
33
|
+
"types": "./dist/dts/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.umd.cjs",
|
|
36
|
+
"default": "./dist/index.umd.cjs"
|
|
43
37
|
}
|
|
44
38
|
},
|
|
45
39
|
"dependencies": {
|
|
46
|
-
"@tma.js/parsing": "0.0
|
|
40
|
+
"@tma.js/parsing": "0.1.0"
|
|
47
41
|
},
|
|
48
42
|
"devDependencies": {
|
|
49
43
|
"tsconfig": "0.0.2",
|
|
50
44
|
"eslint-config-custom": "0.1.0",
|
|
51
|
-
"
|
|
45
|
+
"build-utils": "0.0.0"
|
|
52
46
|
},
|
|
53
47
|
"publishConfig": {
|
|
54
48
|
"access": "public"
|
|
55
49
|
},
|
|
56
50
|
"scripts": {
|
|
57
|
-
"test": "
|
|
58
|
-
"lint": "eslint -c .eslintrc.cjs src/**/*
|
|
59
|
-
"
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"lint": "eslint -c .eslintrc.cjs src/**/* tests/**/*",
|
|
53
|
+
"typecheck": "tsc --noEmit -p tsconfig.build.json",
|
|
54
|
+
"build": "vite build",
|
|
55
|
+
"rollup": "pnpm run typecheck && pnpm run build"
|
|
60
56
|
}
|
|
61
57
|
}
|
package/src/parsing.ts
CHANGED
|
@@ -17,33 +17,56 @@ function field<P extends AnyParser<any>>(parser: P, from?: string) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
const str = string();
|
|
21
|
+
const strOptional = string().optional();
|
|
22
|
+
const num = number();
|
|
23
|
+
const numOptional = number().optional();
|
|
24
|
+
const boolOptional = boolean().optional();
|
|
25
|
+
|
|
26
|
+
function user() {
|
|
27
|
+
return json<User>({
|
|
28
|
+
firstName: field(str, 'first_name'),
|
|
29
|
+
id: num,
|
|
30
|
+
isBot: field(boolOptional, 'is_bot'),
|
|
31
|
+
isPremium: field(boolOptional, 'is_premium'),
|
|
32
|
+
lastName: field(strOptional, 'last_name'),
|
|
33
|
+
languageCode: field(strOptional, 'language_code'),
|
|
34
|
+
photoUrl: field(strOptional, 'photo_url'),
|
|
35
|
+
username: strOptional,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function chat() {
|
|
40
|
+
return json({
|
|
41
|
+
id: num,
|
|
42
|
+
type: str,
|
|
43
|
+
title: str,
|
|
44
|
+
photoUrl: field(strOptional, 'photo_url'),
|
|
45
|
+
username: strOptional,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
30
48
|
|
|
31
49
|
/**
|
|
32
50
|
* Parser used to parse init data, presented as search params.
|
|
51
|
+
* @deprecated Use `parse` method instead.
|
|
33
52
|
*/
|
|
34
53
|
export const initData = searchParams<InitData>({
|
|
35
54
|
authDate: field(date(), 'auth_date'),
|
|
36
|
-
hash:
|
|
37
|
-
user: user.optional(),
|
|
38
|
-
receiver: user.optional(),
|
|
39
|
-
chat:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}).optional(),
|
|
46
|
-
canSendAfter: field(date().optional(), 'can_send_after'),
|
|
47
|
-
queryId: field(string().optional(), 'query_id'),
|
|
48
|
-
startParam: field(string().optional(), 'start_param'),
|
|
55
|
+
hash: str,
|
|
56
|
+
user: user().optional(),
|
|
57
|
+
receiver: user().optional(),
|
|
58
|
+
chat: chat().optional(),
|
|
59
|
+
chatType: field(strOptional, 'chat_type'),
|
|
60
|
+
chatInstance: field(strOptional, 'chat_instance'),
|
|
61
|
+
canSendAfter: field(numOptional, 'can_send_after'),
|
|
62
|
+
queryId: field(strOptional, 'query_id'),
|
|
63
|
+
startParam: field(strOptional, 'start_param'),
|
|
49
64
|
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parses incoming value as init data.
|
|
68
|
+
* @param value - value to parse.
|
|
69
|
+
*/
|
|
70
|
+
export function parse(value: string | URLSearchParams): InitData {
|
|
71
|
+
return initData.parse(value);
|
|
72
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known type of chat.
|
|
3
|
+
*/
|
|
4
|
+
export type ChatType =
|
|
5
|
+
| 'sender'
|
|
6
|
+
| 'private'
|
|
7
|
+
| 'group'
|
|
8
|
+
| 'supergroup'
|
|
9
|
+
| 'channel'
|
|
10
|
+
| string;
|
|
11
|
+
|
|
1
12
|
/**
|
|
2
13
|
* Describes user information.
|
|
3
14
|
* @see https://docs.telegram-mini-apps.com/docs/launch-params/init-data#user
|
|
@@ -91,10 +102,10 @@ export interface InitData {
|
|
|
91
102
|
authDate: Date;
|
|
92
103
|
|
|
93
104
|
/**
|
|
94
|
-
*
|
|
105
|
+
* The number of seconds after which a message can be sent via the method answerWebAppQuery.
|
|
95
106
|
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
96
107
|
*/
|
|
97
|
-
canSendAfter?:
|
|
108
|
+
canSendAfter?: number;
|
|
98
109
|
|
|
99
110
|
/**
|
|
100
111
|
* An object containing data about the chat where the bot was launched via
|
|
@@ -103,6 +114,17 @@ export interface InitData {
|
|
|
103
114
|
*/
|
|
104
115
|
chat?: Chat;
|
|
105
116
|
|
|
117
|
+
/**
|
|
118
|
+
* The type of chat from which Mini App was opened.
|
|
119
|
+
*/
|
|
120
|
+
chatType?: ChatType;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A global identifier indicating the chat from which Mini App was
|
|
124
|
+
* opened. Returned only for applications opened by direct link.
|
|
125
|
+
*/
|
|
126
|
+
chatInstance?: string;
|
|
127
|
+
|
|
106
128
|
/**
|
|
107
129
|
* A hash of all passed parameters, which the bot server can use to
|
|
108
130
|
* check their validity.
|
package/dist/lib/browser.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
this["@tma"]=this["@tma"]||{},this["@tma"]["js/init-data"]=function(t){"use strict";class e{parser;isOptional;getDefault;isEmpty;static create(t){return new e(t,!1,void 0)}constructor(t,e,r,n=(t=>void 0===t)){this.parser=t,this.isOptional=e,this.getDefault=r,this.isEmpty=n}parse(t){return this.isOptional&&this.isEmpty(t)?this.getDefault?this.getDefault():void 0:this.parser(t)}optional(t){return this.isOptional=!0,t&&(this.isEmpty=t),this}default(t){return this.getDefault=t,this}}function r(t){return()=>e.create(t)}function n(t){return r((e=>{if(typeof e!==t)throw new TypeError(`Unable to parse value ${JSON.stringify(e)} as ${t}.`);return e}))}function o(t,e){const r={};for(const n in t){const o=t[n];if(!o)continue;let i,a,s,p;if("type"in o){const{from:t=n,type:e}=o;i=t,a="function"==typeof e?e:e.parse.bind(e),s="required"in o&&o.required}else i=n,s=!1,a="function"==typeof o?o:o.parse.bind(o);try{p=a(e(i))}catch(t){throw new Error(`Unable to parse field "${i}"`,{cause:t})}(void 0!==p||s)&&(r[n]=p)}return r}const i=n("string"),a=n("number"),s=n("boolean"),p=r((t=>{const e=i().parse(t);if(e){const t=Number(e),r=new Date(t.toString()===e?1e3*t:e);if("Invalid Date"!==r.toString())return r}throw new TypeError(`Unable to parse value "${t}" as Date.`)}));function u(t){return e.create((e=>{let r=e;if("string"==typeof r)try{r=JSON.parse(r)}catch(t){throw new TypeError("Value is not JSON object converted to string.")}if("object"!=typeof r||null===r||Array.isArray(r))throw new TypeError("Value is not JSON object.");return o(t,(t=>r[t]))}))}function l(t,e){return{from:e,type:t}}const c=u({firstName:l(i(),"first_name"),id:a(),isBot:l(s().optional(),"is_bot"),isPremium:l(s().optional(),"is_premium"),lastName:l(i().optional(),"last_name"),languageCode:l(i().optional(),"language_code"),photoUrl:l(i().optional(),"photo_url"),username:i().optional()}),f=(h={authDate:l(p(),"auth_date"),hash:i(),user:c.optional(),receiver:c.optional(),chat:u({id:a(),type:i(),title:i(),photoUrl:l(i().optional(),"photo_url"),username:i().optional()}).optional(),canSendAfter:l(p().optional(),"can_send_after"),queryId:l(i().optional(),"query_id"),startParam:l(i().optional(),"start_param")},e.create((t=>{if("string"!=typeof t&&!(t instanceof URLSearchParams))throw new TypeError("Value has not processable type.");const e="string"==typeof t?new URLSearchParams(t):t;return o(h,(t=>{const r=e.get(t);return null===r?void 0:r}))})));var h;return t.initData=f,t}({});
|
|
2
|
-
//# sourceMappingURL=browser.js.map
|
package/dist/lib/browser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sources":["../../../parsing/dist/lib/index.mjs","../../src/parsing.ts"],"sourcesContent":["import{toRGB as t}from\"@tma.js/colors\";class r{parser;isOptional;getDefault;isEmpty;static create(t){return new r(t,!1,void 0)}constructor(t,r,e,n=(t=>void 0===t)){this.parser=t,this.isOptional=r,this.getDefault=e,this.isEmpty=n}parse(t){return this.isOptional&&this.isEmpty(t)?this.getDefault?this.getDefault():void 0:this.parser(t)}optional(t){return this.isOptional=!0,t&&(this.isEmpty=t),this}default(t){return this.getDefault=t,this}}function e(t){const r=\"function\"==typeof t?t:t.parse.bind(t);return t=>function(t){if(Array.isArray(t))return t;if(\"string\"==typeof t)try{const r=JSON.parse(t);if(Array.isArray(r))return r}catch(t){}throw new Error(`Passed value does not satisfy any of known formats: ${JSON.stringify(t)}`)}(t).map(r)}class n extends r{constructor(t,r,n,o=(t=>void 0===t)){super(e(t),r,n,o)}of(t){return this.parser=e(t),this}}function o(t){return()=>r.create(t)}function s(t){return o((r=>{if(typeof r!==t)throw new TypeError(`Unable to parse value ${JSON.stringify(r)} as ${t}.`);return r}))}function i(t,r){const e={};for(const n in t){const o=t[n];if(!o)continue;let s,i,a,u;if(\"type\"in o){const{from:t=n,type:r}=o;s=t,i=\"function\"==typeof r?r:r.parse.bind(r),a=\"required\"in o&&o.required}else s=n,a=!1,i=\"function\"==typeof o?o:o.parse.bind(o);try{u=i(r(s))}catch(t){throw new Error(`Unable to parse field \"${s}\"`,{cause:t})}(void 0!==u||a)&&(e[n]=u)}return e}const a=s(\"string\"),u=s(\"number\"),c=s(\"boolean\"),f=o((t=>{const r=a().parse(t);if(r){const t=Number(r),e=new Date(t.toString()===r?1e3*t:r);if(\"Invalid Date\"!==e.toString())return e}throw new TypeError(`Unable to parse value \"${t}\" as Date.`)})),p=o((r=>{const e=a().parse(r);try{return t(e)}catch(t){throw new TypeError(`Unable to parse value \"${e}\" as RGB.`,{cause:t})}}));function l(t){return r.create((r=>{let e=r;if(\"string\"==typeof e)try{e=JSON.parse(e)}catch(t){throw new TypeError(\"Value is not JSON object converted to string.\")}if(\"object\"!=typeof e||null===e||Array.isArray(e))throw new TypeError(\"Value is not JSON object.\");return i(t,(t=>e[t]))}))}function y(t){return r.create((r=>{if(\"string\"!=typeof r&&!(r instanceof URLSearchParams))throw new TypeError(\"Value has not processable type.\");const e=\"string\"==typeof r?new URLSearchParams(r):r;return i(t,(t=>{const r=e.get(t);return null===r?void 0:r}))}))}function h(){return new n((t=>t),!1,void 0)}export{n as ArrayValueParser,r as ValueParser,h as array,c as boolean,o as createParserGenerator,f as date,l as json,u as number,p as rgb,y as searchParams,a as string};\n//# sourceMappingURL=index.mjs.map\n","import {\n searchParams,\n json,\n string,\n number,\n boolean,\n date,\n type AnyParser,\n} from '@tma.js/parsing';\n\nimport type { InitData, User } from './types.js';\n\nfunction field<P extends AnyParser<any>>(parser: P, from?: string) {\n return {\n from,\n type: parser,\n };\n}\n\nconst user = json<User>({\n firstName: field(string(), 'first_name'),\n id: number(),\n isBot: field(boolean().optional(), 'is_bot'),\n isPremium: field(boolean().optional(), 'is_premium'),\n lastName: field(string().optional(), 'last_name'),\n languageCode: field(string().optional(), 'language_code'),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n});\n\n/**\n * Parser used to parse init data, presented as search params.\n */\nexport const initData = searchParams<InitData>({\n authDate: field(date(), 'auth_date'),\n hash: string(),\n user: user.optional(),\n receiver: user.optional(),\n chat: json<InitData['chat']>({\n id: number(),\n type: string(),\n title: string(),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n }).optional(),\n canSendAfter: field(date().optional(), 'can_send_after'),\n queryId: field(string().optional(), 'query_id'),\n startParam: field(string().optional(), 'start_param'),\n});\n"],"names":["r","parser","isOptional","getDefault","isEmpty","static","t","constructor","e","n","this","parse","optional","default","o","create","s","TypeError","JSON","stringify","i","a","u","from","type","bind","required","Error","cause","c","f","Number","Date","toString","l","Array","isArray","field","user","json","firstName","string","id","number","isBot","boolean","isPremium","lastName","languageCode","photoUrl","username","initData","authDate","date","hash","receiver","chat","title","canSendAfter","queryId","startParam","URLSearchParams","get"],"mappings":"oFAAuC,MAAMA,EAAEC,OAAOC,WAAWC,WAAWC,QAAQC,cAAcC,GAAG,OAAO,IAAIN,EAAEM,GAAE,OAAG,EAAO,CAACC,YAAYD,EAAEN,EAAEQ,EAAEC,EAAG,CAAAH,QAAG,IAASA,IAAII,KAAKT,OAAOK,EAAEI,KAAKR,WAAWF,EAAEU,KAAKP,WAAWK,EAAEE,KAAKN,QAAQK,CAAC,CAACE,MAAML,GAAG,OAAOI,KAAKR,YAAYQ,KAAKN,QAAQE,GAAGI,KAAKP,WAAWO,KAAKP,kBAAa,EAAOO,KAAKT,OAAOK,EAAE,CAACM,SAASN,GAAG,OAAOI,KAAKR,YAAW,EAA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AgB7D,GAAGA,EAAE,OAAOoB,EAAEd,GAAGA,IAAI,MAAMN,EAAEQ,EAAEsD,IAAIxD,GAAG,OAAO,OAAON,OAAE,EAAOA,CAAE,GAAG,KAAlQ,IAAWM"}
|
package/dist/lib/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var t=require("@tma.js/parsing");function a(t,a){return{from:a,type:t}}const o=t.json({firstName:a(t.string(),"first_name"),id:t.number(),isBot:a(t.boolean().optional(),"is_bot"),isPremium:a(t.boolean().optional(),"is_premium"),lastName:a(t.string().optional(),"last_name"),languageCode:a(t.string().optional(),"language_code"),photoUrl:a(t.string().optional(),"photo_url"),username:t.string().optional()}),n=t.searchParams({authDate:a(t.date(),"auth_date"),hash:t.string(),user:o.optional(),receiver:o.optional(),chat:t.json({id:t.number(),type:t.string(),title:t.string(),photoUrl:a(t.string().optional(),"photo_url"),username:t.string().optional()}).optional(),canSendAfter:a(t.date().optional(),"can_send_after"),queryId:a(t.string().optional(),"query_id"),startParam:a(t.string().optional(),"start_param")});exports.initData=n;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/lib/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/parsing.ts"],"sourcesContent":["import {\n searchParams,\n json,\n string,\n number,\n boolean,\n date,\n type AnyParser,\n} from '@tma.js/parsing';\n\nimport type { InitData, User } from './types.js';\n\nfunction field<P extends AnyParser<any>>(parser: P, from?: string) {\n return {\n from,\n type: parser,\n };\n}\n\nconst user = json<User>({\n firstName: field(string(), 'first_name'),\n id: number(),\n isBot: field(boolean().optional(), 'is_bot'),\n isPremium: field(boolean().optional(), 'is_premium'),\n lastName: field(string().optional(), 'last_name'),\n languageCode: field(string().optional(), 'language_code'),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n});\n\n/**\n * Parser used to parse init data, presented as search params.\n */\nexport const initData = searchParams<InitData>({\n authDate: field(date(), 'auth_date'),\n hash: string(),\n user: user.optional(),\n receiver: user.optional(),\n chat: json<InitData['chat']>({\n id: number(),\n type: string(),\n title: string(),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n }).optional(),\n canSendAfter: field(date().optional(), 'can_send_after'),\n queryId: field(string().optional(), 'query_id'),\n startParam: field(string().optional(), 'start_param'),\n});\n"],"names":["field","parser","from","type","user","json","firstName","string","id","number","isBot","boolean","optional","isPremium","lastName","languageCode","photoUrl","username","initData","searchParams","authDate","date","hash","receiver","chat","title","canSendAfter","queryId","startParam"],"mappings":"8CAYA,SAASA,EAAgCC,EAAWC,GAClD,MAAO,CACLA,OACAC,KAAMF,EAEV,CAEA,MAAMG,EAAOC,EAAAA,KAAW,CACtBC,UAAWN,EAAMO,WAAU,cAC3BC,GAAIC,EAAAA,SACJC,MAAOV,EAAMW,EAAAA,UAAUC,WAAY,UACnCC,UAAWb,EAAMW,EAAAA,UAAUC,WAAY,cACvCE,SAAUd,EAAMO,EAAAA,SAASK,WAAY,aACrCG,aAAcf,EAAMO,EAAAA,SAASK,WAAY,iBACzCI,SAAUhB,EAAMO,EAAAA,SAASK,WAAY,aACrCK,SAAUV,EAAAA,SAASK,aAMRM,EAAWC,EAAAA,aAAuB,CAC7CC,SAAUpB,EAAMqB,SAAQ,aACxBC,KAAMf,EAAAA,SACNH,KAAMA,EAAKQ,WACXW,SAAUnB,EAAKQ,WACfY,KAAMnB,EAAAA,KAAuB,CAC3BG,GAAIC,EAAAA,SACJN,KAAMI,EAAAA,SACNkB,MAAOlB,EAAAA,SACPS,SAAUhB,EAAMO,EAAAA,SAASK,WAAY,aACrCK,SAAUV,EAAAA,SAASK,aAClBA,WACHc,aAAc1B,EAAMqB,EAAAA,OAAOT,WAAY,kBACvCe,QAAS3B,EAAMO,EAAAA,SAASK,WAAY,YACpCgB,WAAY5B,EAAMO,EAAAA,SAASK,WAAY"}
|
package/dist/lib/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{json as o,string as t,number as a,boolean as e,searchParams as i,date as n}from"@tma.js/parsing";function r(o,t){return{from:t,type:o}}const p=o({firstName:r(t(),"first_name"),id:a(),isBot:r(e().optional(),"is_bot"),isPremium:r(e().optional(),"is_premium"),lastName:r(t().optional(),"last_name"),languageCode:r(t().optional(),"language_code"),photoUrl:r(t().optional(),"photo_url"),username:t().optional()}),l=i({authDate:r(n(),"auth_date"),hash:t(),user:p.optional(),receiver:p.optional(),chat:o({id:a(),type:t(),title:t(),photoUrl:r(t().optional(),"photo_url"),username:t().optional()}).optional(),canSendAfter:r(n().optional(),"can_send_after"),queryId:r(t().optional(),"query_id"),startParam:r(t().optional(),"start_param")});export{l as initData};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/parsing.ts"],"sourcesContent":["import {\n searchParams,\n json,\n string,\n number,\n boolean,\n date,\n type AnyParser,\n} from '@tma.js/parsing';\n\nimport type { InitData, User } from './types.js';\n\nfunction field<P extends AnyParser<any>>(parser: P, from?: string) {\n return {\n from,\n type: parser,\n };\n}\n\nconst user = json<User>({\n firstName: field(string(), 'first_name'),\n id: number(),\n isBot: field(boolean().optional(), 'is_bot'),\n isPremium: field(boolean().optional(), 'is_premium'),\n lastName: field(string().optional(), 'last_name'),\n languageCode: field(string().optional(), 'language_code'),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n});\n\n/**\n * Parser used to parse init data, presented as search params.\n */\nexport const initData = searchParams<InitData>({\n authDate: field(date(), 'auth_date'),\n hash: string(),\n user: user.optional(),\n receiver: user.optional(),\n chat: json<InitData['chat']>({\n id: number(),\n type: string(),\n title: string(),\n photoUrl: field(string().optional(), 'photo_url'),\n username: string().optional(),\n }).optional(),\n canSendAfter: field(date().optional(), 'can_send_after'),\n queryId: field(string().optional(), 'query_id'),\n startParam: field(string().optional(), 'start_param'),\n});\n"],"names":["field","parser","from","type","user","json","firstName","string","id","number","isBot","boolean","optional","isPremium","lastName","languageCode","photoUrl","username","initData","searchParams","authDate","date","hash","receiver","chat","title","canSendAfter","queryId","startParam"],"mappings":"wGAYA,SAASA,EAAgCC,EAAWC,GAClD,MAAO,CACLA,OACAC,KAAMF,EAEV,CAEA,MAAMG,EAAOC,EAAW,CACtBC,UAAWN,EAAMO,IAAU,cAC3BC,GAAIC,IACJC,MAAOV,EAAMW,IAAUC,WAAY,UACnCC,UAAWb,EAAMW,IAAUC,WAAY,cACvCE,SAAUd,EAAMO,IAASK,WAAY,aACrCG,aAAcf,EAAMO,IAASK,WAAY,iBACzCI,SAAUhB,EAAMO,IAASK,WAAY,aACrCK,SAAUV,IAASK,aAMRM,EAAWC,EAAuB,CAC7CC,SAAUpB,EAAMqB,IAAQ,aACxBC,KAAMf,IACNH,KAAMA,EAAKQ,WACXW,SAAUnB,EAAKQ,WACfY,KAAMnB,EAAuB,CAC3BG,GAAIC,IACJN,KAAMI,IACNkB,MAAOlB,IACPS,SAAUhB,EAAMO,IAASK,WAAY,aACrCK,SAAUV,IAASK,aAClBA,WACHc,aAAc1B,EAAMqB,IAAOT,WAAY,kBACvCe,QAAS3B,EAAMO,IAASK,WAAY,YACpCgB,WAAY5B,EAAMO,IAASK,WAAY"}
|
package/dist/types/parsing.d.ts
DELETED
|
File without changes
|