@ts-core/oauth 3.1.10 → 3.1.12
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/cjs/tg/TgAuth.d.ts +6 -0
- package/cjs/tg/TgAuth.js +59 -0
- package/esm/tg/TgAuth.d.ts +6 -0
- package/esm/tg/TgAuth.js +59 -0
- package/package.json +1 -1
package/cjs/tg/TgAuth.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { ExtendedError, ILogger, LoggerWrapper, PromiseHandler } from "@ts-core/
|
|
|
2
2
|
import { TgUser } from "./TgUser";
|
|
3
3
|
import { ITgApiLoader } from "./TgApiLoader";
|
|
4
4
|
export declare class TgAuth extends LoggerWrapper {
|
|
5
|
+
static getUser(locationHash: string): TgUser;
|
|
6
|
+
static getInitData(locationHash: string): string;
|
|
7
|
+
static getInitDataUnsafe(locationHash: string): Record<string, any>;
|
|
8
|
+
private static urlParseHashParams;
|
|
9
|
+
private static urlParseQueryString;
|
|
10
|
+
private static urlSafeDecode;
|
|
5
11
|
protected promise: PromiseHandler<TgUser, ExtendedError>;
|
|
6
12
|
protected settings: ITgAuthSettings;
|
|
7
13
|
constructor(logger: ILogger, settings: ITgAuthSettings);
|
package/cjs/tg/TgAuth.js
CHANGED
|
@@ -15,6 +15,65 @@ const TgUser_1 = require("./TgUser");
|
|
|
15
15
|
const PopUpBase_1 = require("../PopUpBase");
|
|
16
16
|
const _ = require("lodash");
|
|
17
17
|
class TgAuth extends common_1.LoggerWrapper {
|
|
18
|
+
static getUser(locationHash) {
|
|
19
|
+
let item = new TgUser_1.TgUser();
|
|
20
|
+
item.parse(TgAuth.getInitDataUnsafe(locationHash));
|
|
21
|
+
item.raw = TgAuth.getInitData(locationHash);
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
static getInitData(locationHash) {
|
|
25
|
+
let item = TgAuth.urlParseHashParams(locationHash);
|
|
26
|
+
return item.tgWebAppData;
|
|
27
|
+
}
|
|
28
|
+
static getInitDataUnsafe(locationHash) {
|
|
29
|
+
return TgAuth.urlParseQueryString(TgAuth.getInitData(locationHash));
|
|
30
|
+
}
|
|
31
|
+
static urlParseHashParams(locationHash) {
|
|
32
|
+
locationHash = locationHash.replace(/^#/, '');
|
|
33
|
+
let params = {};
|
|
34
|
+
if (_.isEmpty(locationHash)) {
|
|
35
|
+
return params;
|
|
36
|
+
}
|
|
37
|
+
if (locationHash.indexOf('=') < 0 && locationHash.indexOf('?') < 0) {
|
|
38
|
+
params._path = TgAuth.urlSafeDecode(locationHash);
|
|
39
|
+
return params;
|
|
40
|
+
}
|
|
41
|
+
let qIndex = locationHash.indexOf('?');
|
|
42
|
+
if (qIndex >= 0) {
|
|
43
|
+
var pathParam = locationHash.substr(0, qIndex);
|
|
44
|
+
params._path = TgAuth.urlSafeDecode(pathParam);
|
|
45
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
46
|
+
}
|
|
47
|
+
let query_params = TgAuth.urlParseQueryString(locationHash);
|
|
48
|
+
for (var k in query_params) {
|
|
49
|
+
params[k] = query_params[k];
|
|
50
|
+
}
|
|
51
|
+
return params;
|
|
52
|
+
}
|
|
53
|
+
static urlParseQueryString(queryString) {
|
|
54
|
+
var params = {};
|
|
55
|
+
if (!queryString.length) {
|
|
56
|
+
return params;
|
|
57
|
+
}
|
|
58
|
+
let queryStringParams = queryString.split('&');
|
|
59
|
+
let i, param, paramName, paramValue;
|
|
60
|
+
for (i = 0; i < queryStringParams.length; i++) {
|
|
61
|
+
param = queryStringParams[i].split(/=(.+)/);
|
|
62
|
+
paramName = TgAuth.urlSafeDecode(param[0]);
|
|
63
|
+
paramValue = param[1] == null ? null : TgAuth.urlSafeDecode(param[1]);
|
|
64
|
+
params[paramName] = paramValue;
|
|
65
|
+
}
|
|
66
|
+
return params;
|
|
67
|
+
}
|
|
68
|
+
static urlSafeDecode(item) {
|
|
69
|
+
try {
|
|
70
|
+
item = item.replace(/\+/g, '%20');
|
|
71
|
+
return decodeURIComponent(item);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return item;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
18
77
|
constructor(logger, settings) {
|
|
19
78
|
super(logger);
|
|
20
79
|
this.settings = settings;
|
package/esm/tg/TgAuth.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { ExtendedError, ILogger, LoggerWrapper, PromiseHandler } from "@ts-core/
|
|
|
2
2
|
import { TgUser } from "./TgUser";
|
|
3
3
|
import { ITgApiLoader } from "./TgApiLoader";
|
|
4
4
|
export declare class TgAuth extends LoggerWrapper {
|
|
5
|
+
static getUser(locationHash: string): TgUser;
|
|
6
|
+
static getInitData(locationHash: string): string;
|
|
7
|
+
static getInitDataUnsafe(locationHash: string): Record<string, any>;
|
|
8
|
+
private static urlParseHashParams;
|
|
9
|
+
private static urlParseQueryString;
|
|
10
|
+
private static urlSafeDecode;
|
|
5
11
|
protected promise: PromiseHandler<TgUser, ExtendedError>;
|
|
6
12
|
protected settings: ITgAuthSettings;
|
|
7
13
|
constructor(logger: ILogger, settings: ITgAuthSettings);
|
package/esm/tg/TgAuth.js
CHANGED
|
@@ -12,6 +12,65 @@ import { TgUser } from "./TgUser";
|
|
|
12
12
|
import { PopUpBase } from "../PopUpBase";
|
|
13
13
|
import * as _ from 'lodash';
|
|
14
14
|
export class TgAuth extends LoggerWrapper {
|
|
15
|
+
static getUser(locationHash) {
|
|
16
|
+
let item = new TgUser();
|
|
17
|
+
item.parse(TgAuth.getInitDataUnsafe(locationHash));
|
|
18
|
+
item.raw = TgAuth.getInitData(locationHash);
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
static getInitData(locationHash) {
|
|
22
|
+
let item = TgAuth.urlParseHashParams(locationHash);
|
|
23
|
+
return item.tgWebAppData;
|
|
24
|
+
}
|
|
25
|
+
static getInitDataUnsafe(locationHash) {
|
|
26
|
+
return TgAuth.urlParseQueryString(TgAuth.getInitData(locationHash));
|
|
27
|
+
}
|
|
28
|
+
static urlParseHashParams(locationHash) {
|
|
29
|
+
locationHash = locationHash.replace(/^#/, '');
|
|
30
|
+
let params = {};
|
|
31
|
+
if (_.isEmpty(locationHash)) {
|
|
32
|
+
return params;
|
|
33
|
+
}
|
|
34
|
+
if (locationHash.indexOf('=') < 0 && locationHash.indexOf('?') < 0) {
|
|
35
|
+
params._path = TgAuth.urlSafeDecode(locationHash);
|
|
36
|
+
return params;
|
|
37
|
+
}
|
|
38
|
+
let qIndex = locationHash.indexOf('?');
|
|
39
|
+
if (qIndex >= 0) {
|
|
40
|
+
var pathParam = locationHash.substr(0, qIndex);
|
|
41
|
+
params._path = TgAuth.urlSafeDecode(pathParam);
|
|
42
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
43
|
+
}
|
|
44
|
+
let query_params = TgAuth.urlParseQueryString(locationHash);
|
|
45
|
+
for (var k in query_params) {
|
|
46
|
+
params[k] = query_params[k];
|
|
47
|
+
}
|
|
48
|
+
return params;
|
|
49
|
+
}
|
|
50
|
+
static urlParseQueryString(queryString) {
|
|
51
|
+
var params = {};
|
|
52
|
+
if (!queryString.length) {
|
|
53
|
+
return params;
|
|
54
|
+
}
|
|
55
|
+
let queryStringParams = queryString.split('&');
|
|
56
|
+
let i, param, paramName, paramValue;
|
|
57
|
+
for (i = 0; i < queryStringParams.length; i++) {
|
|
58
|
+
param = queryStringParams[i].split(/=(.+)/);
|
|
59
|
+
paramName = TgAuth.urlSafeDecode(param[0]);
|
|
60
|
+
paramValue = param[1] == null ? null : TgAuth.urlSafeDecode(param[1]);
|
|
61
|
+
params[paramName] = paramValue;
|
|
62
|
+
}
|
|
63
|
+
return params;
|
|
64
|
+
}
|
|
65
|
+
static urlSafeDecode(item) {
|
|
66
|
+
try {
|
|
67
|
+
item = item.replace(/\+/g, '%20');
|
|
68
|
+
return decodeURIComponent(item);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
15
74
|
constructor(logger, settings) {
|
|
16
75
|
super(logger);
|
|
17
76
|
this.settings = settings;
|