auth-mn 0.2.0 → 1.0.1
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/README.md +206 -1
- package/dist/auth.d.ts +55 -1
- package/dist/auth.js +142 -85
- package/dist/index.d.ts +94 -349
- package/dist/index.js +82 -47
- package/dist/notification.d.ts +16 -116
- package/dist/notification.js +16 -258
- package/dist/request.d.ts +19 -0
- package/dist/request.js +81 -0
- package/dist/socket.d.ts +21 -98
- package/dist/socket.js +25 -198
- package/dist/types.d.ts +235 -0
- package/dist/types.js +7 -0
- package/dist/user.d.ts +78 -0
- package/dist/user.js +93 -0
- package/package.json +8 -9
- package/dist/find.d.ts +0 -208
- package/dist/find.js +0 -256
package/dist/notification.d.ts
CHANGED
|
@@ -1,119 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
url: string;
|
|
12
|
-
} | null;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
type MailT = {
|
|
16
|
-
type: "notification" | "otp" | "custom";
|
|
17
|
-
form?: {
|
|
18
|
-
name?: string;
|
|
19
|
-
email?: string;
|
|
20
|
-
};
|
|
21
|
-
to: string[];
|
|
22
|
-
subject: string;
|
|
23
|
-
body: {
|
|
24
|
-
name: string;
|
|
25
|
-
title?: string;
|
|
26
|
-
desc?: string;
|
|
27
|
-
otp?: string | number;
|
|
28
|
-
button?: {
|
|
29
|
-
text: string;
|
|
30
|
-
url: string | null;
|
|
31
|
-
};
|
|
32
|
-
footer_text?: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export declare const SinglePushNoti: (body: SinglePushNotiT) => Promise<{
|
|
36
|
-
success: boolean;
|
|
37
|
-
data: null;
|
|
38
|
-
message: string;
|
|
39
|
-
}>;
|
|
40
|
-
export declare const SMS: (body: {
|
|
41
|
-
text: string;
|
|
42
|
-
to: string;
|
|
43
|
-
from: string;
|
|
44
|
-
}) => Promise<{
|
|
45
|
-
success: boolean;
|
|
46
|
-
data: null;
|
|
47
|
-
message: string;
|
|
48
|
-
}>;
|
|
49
|
-
export declare const MAIL: (body: MailT) => Promise<{
|
|
50
|
-
success: boolean;
|
|
51
|
-
data: null;
|
|
52
|
-
message: string;
|
|
53
|
-
}>;
|
|
54
|
-
export declare const _3RD_TOKI_NOTI: (body: {
|
|
55
|
-
accountId: string;
|
|
56
|
-
title: string;
|
|
57
|
-
body: string;
|
|
58
|
-
url: string;
|
|
59
|
-
buttonName: string;
|
|
60
|
-
imageURL?: string;
|
|
61
|
-
icon: string;
|
|
62
|
-
}) => Promise<{
|
|
63
|
-
success: boolean;
|
|
64
|
-
data: null;
|
|
65
|
-
message: string;
|
|
66
|
-
}>;
|
|
67
|
-
export declare const _3RD_TOKI_HIPAY: (body: {
|
|
68
|
-
customerId: string;
|
|
69
|
-
message: string;
|
|
70
|
-
}) => Promise<{
|
|
71
|
-
success: boolean;
|
|
72
|
-
data: null;
|
|
73
|
-
message: string;
|
|
74
|
-
}>;
|
|
1
|
+
import { MailT, PushNotiT, Result, SmsT } from "./types";
|
|
2
|
+
/** Push мэдэгдэл — permission: notification.push */
|
|
3
|
+
export declare const push: (body: PushNotiT) => Promise<Result<null>>;
|
|
4
|
+
/** SMS — permission: notification.sms */
|
|
5
|
+
export declare const sms: (body: SmsT) => Promise<Result<null>>;
|
|
6
|
+
/** Имэйл — permission: notification.mail */
|
|
7
|
+
export declare const mail: (body: MailT) => Promise<Result<null>>;
|
|
8
|
+
export declare const SinglePushNoti: (body: PushNotiT) => Promise<Result<null>>;
|
|
9
|
+
export declare const SMS: (body: SmsT) => Promise<Result<null>>;
|
|
10
|
+
export declare const MAIL: (body: MailT) => Promise<Result<null>>;
|
|
75
11
|
declare const _default: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
text: string;
|
|
83
|
-
to: string;
|
|
84
|
-
from: string;
|
|
85
|
-
}) => Promise<{
|
|
86
|
-
success: boolean;
|
|
87
|
-
data: null;
|
|
88
|
-
message: string;
|
|
89
|
-
}>;
|
|
90
|
-
MAIL: (body: MailT) => Promise<{
|
|
91
|
-
success: boolean;
|
|
92
|
-
data: null;
|
|
93
|
-
message: string;
|
|
94
|
-
}>;
|
|
95
|
-
_3RD: {
|
|
96
|
-
TOKI: (body: {
|
|
97
|
-
accountId: string;
|
|
98
|
-
title: string;
|
|
99
|
-
body: string;
|
|
100
|
-
url: string;
|
|
101
|
-
buttonName: string;
|
|
102
|
-
imageURL?: string;
|
|
103
|
-
icon: string;
|
|
104
|
-
}) => Promise<{
|
|
105
|
-
success: boolean;
|
|
106
|
-
data: null;
|
|
107
|
-
message: string;
|
|
108
|
-
}>;
|
|
109
|
-
HIPAY: (body: {
|
|
110
|
-
customerId: string;
|
|
111
|
-
message: string;
|
|
112
|
-
}) => Promise<{
|
|
113
|
-
success: boolean;
|
|
114
|
-
data: null;
|
|
115
|
-
message: string;
|
|
116
|
-
}>;
|
|
117
|
-
};
|
|
12
|
+
push: (body: PushNotiT) => Promise<Result<null>>;
|
|
13
|
+
sms: (body: SmsT) => Promise<Result<null>>;
|
|
14
|
+
mail: (body: MailT) => Promise<Result<null>>;
|
|
15
|
+
SinglePushNoti: (body: PushNotiT) => Promise<Result<null>>;
|
|
16
|
+
SMS: (body: SmsT) => Promise<Result<null>>;
|
|
17
|
+
MAIL: (body: MailT) => Promise<Result<null>>;
|
|
118
18
|
};
|
|
119
19
|
export default _default;
|
package/dist/notification.js
CHANGED
|
@@ -1,260 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
data: body
|
|
20
|
-
}, {
|
|
21
|
-
name: "notification single-push",
|
|
22
|
-
timeout: 20000,
|
|
23
|
-
retryFunction: auth_1.getToken,
|
|
24
|
-
shouldRetry: true,
|
|
25
|
-
shouldRetryStatus: [401, 400],
|
|
26
|
-
logger(data) {
|
|
27
|
-
if (_1.config.logger) {
|
|
28
|
-
console.log({
|
|
29
|
-
time: data.json.time,
|
|
30
|
-
request: data.json.request,
|
|
31
|
-
response: `${data.json.response}`,
|
|
32
|
-
responseBody: data.json.responseBody,
|
|
33
|
-
statusCode: data.json.statusCode
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return { success: true, data: result.data, message: result.message };
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
const axiosError = error;
|
|
42
|
-
if (axiosError.data) {
|
|
43
|
-
console.log(axiosError.data);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
console.error("Request Failed:", axiosError);
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
data: null,
|
|
51
|
-
message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || ""
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.SinglePushNoti = SinglePushNoti;
|
|
56
|
-
const SMS = async (body) => {
|
|
57
|
-
var _a;
|
|
58
|
-
try {
|
|
59
|
-
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
60
|
-
method: "POST",
|
|
61
|
-
maxBodyLength: Infinity,
|
|
62
|
-
url: `${_1.config.hosts.MAIN}/main/v1/notification/sms`,
|
|
63
|
-
headers: {
|
|
64
|
-
Accept: "application/json",
|
|
65
|
-
"Content-Type": "application/json",
|
|
66
|
-
Authorization: `Bearer ${_1.config.token}`
|
|
67
|
-
},
|
|
68
|
-
data: body
|
|
69
|
-
}, {
|
|
70
|
-
name: "notification sms",
|
|
71
|
-
timeout: 20000,
|
|
72
|
-
retryFunction: auth_1.getToken,
|
|
73
|
-
shouldRetry: true,
|
|
74
|
-
shouldRetryStatus: [401, 400],
|
|
75
|
-
logger(data) {
|
|
76
|
-
if (_1.config.logger) {
|
|
77
|
-
console.log({
|
|
78
|
-
time: data.json.time,
|
|
79
|
-
request: data.json.request,
|
|
80
|
-
response: `${data.json.response}`,
|
|
81
|
-
responseBody: data.json.responseBody,
|
|
82
|
-
statusCode: data.json.statusCode
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return { success: true, data: result.data, message: result.message };
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
const axiosError = error;
|
|
91
|
-
if (axiosError.data) {
|
|
92
|
-
console.log(axiosError.data);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.error("Request Failed:", axiosError);
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
data: null,
|
|
100
|
-
message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || ""
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
exports.SMS = SMS;
|
|
105
|
-
const MAIL = async (body) => {
|
|
106
|
-
var _a;
|
|
107
|
-
try {
|
|
108
|
-
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
109
|
-
method: "POST",
|
|
110
|
-
maxBodyLength: Infinity,
|
|
111
|
-
url: `${_1.config.hosts.MAIN}/main/v1/notification/mail`,
|
|
112
|
-
headers: {
|
|
113
|
-
Accept: "application/json",
|
|
114
|
-
"Content-Type": "application/json",
|
|
115
|
-
Authorization: `Bearer ${_1.config.token}`
|
|
116
|
-
},
|
|
117
|
-
data: body
|
|
118
|
-
}, {
|
|
119
|
-
name: "notification mail",
|
|
120
|
-
timeout: 20000,
|
|
121
|
-
retryFunction: auth_1.getToken,
|
|
122
|
-
shouldRetry: true,
|
|
123
|
-
shouldRetryStatus: [401, 400],
|
|
124
|
-
logger(data) {
|
|
125
|
-
if (_1.config.logger) {
|
|
126
|
-
console.log({
|
|
127
|
-
time: data.json.time,
|
|
128
|
-
request: data.json.request,
|
|
129
|
-
response: `${data.json.response}`,
|
|
130
|
-
responseBody: data.json.responseBody,
|
|
131
|
-
statusCode: data.json.statusCode
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return { success: true, data: result.data, message: result.message };
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
const axiosError = error;
|
|
140
|
-
if (axiosError.data) {
|
|
141
|
-
console.log(axiosError.data);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
console.error("Request Failed:", axiosError);
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
success: false,
|
|
148
|
-
data: null,
|
|
149
|
-
message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || ""
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
exports.MAIL = MAIL;
|
|
154
|
-
const _3RD_TOKI_NOTI = async (body) => {
|
|
155
|
-
var _a;
|
|
156
|
-
try {
|
|
157
|
-
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
158
|
-
method: "POST",
|
|
159
|
-
maxBodyLength: Infinity,
|
|
160
|
-
url: `${_1.config.hosts.MAIN}/main/v1/notification/3rd/toki-app`,
|
|
161
|
-
headers: {
|
|
162
|
-
Accept: "application/json",
|
|
163
|
-
"Content-Type": "application/json",
|
|
164
|
-
Authorization: `Bearer ${_1.config.token}`
|
|
165
|
-
},
|
|
166
|
-
data: body
|
|
167
|
-
}, {
|
|
168
|
-
name: "notification 3rd toki",
|
|
169
|
-
timeout: 20000,
|
|
170
|
-
retryFunction: auth_1.getToken,
|
|
171
|
-
shouldRetry: true,
|
|
172
|
-
shouldRetryStatus: [401, 400],
|
|
173
|
-
logger(data) {
|
|
174
|
-
if (_1.config.logger) {
|
|
175
|
-
console.log({
|
|
176
|
-
time: data.json.time,
|
|
177
|
-
request: data.json.request,
|
|
178
|
-
response: `${data.json.response}`,
|
|
179
|
-
responseBody: data.json.responseBody,
|
|
180
|
-
statusCode: data.json.statusCode
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
return { success: true, data: result.data, message: result.message };
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
const axiosError = error;
|
|
189
|
-
if (axiosError.data) {
|
|
190
|
-
console.log(axiosError.data);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
console.error("Request Failed:", axiosError);
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
success: false,
|
|
197
|
-
data: null,
|
|
198
|
-
message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || ""
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
exports._3RD_TOKI_NOTI = _3RD_TOKI_NOTI;
|
|
203
|
-
const _3RD_TOKI_HIPAY = async (body) => {
|
|
204
|
-
var _a;
|
|
205
|
-
try {
|
|
206
|
-
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
207
|
-
method: "POST",
|
|
208
|
-
maxBodyLength: Infinity,
|
|
209
|
-
url: `${_1.config.hosts.MAIN}/main/v1/notification/3rd/hipay-app`,
|
|
210
|
-
headers: {
|
|
211
|
-
Accept: "application/json",
|
|
212
|
-
"Content-Type": "application/json",
|
|
213
|
-
Authorization: `Bearer ${_1.config.token}`
|
|
214
|
-
},
|
|
215
|
-
data: body
|
|
216
|
-
}, {
|
|
217
|
-
name: "notification 3rd hipay",
|
|
218
|
-
timeout: 20000,
|
|
219
|
-
retryFunction: auth_1.getToken,
|
|
220
|
-
shouldRetry: true,
|
|
221
|
-
shouldRetryStatus: [401, 400],
|
|
222
|
-
logger(data) {
|
|
223
|
-
if (_1.config.logger) {
|
|
224
|
-
console.log({
|
|
225
|
-
time: data.json.time,
|
|
226
|
-
request: data.json.request,
|
|
227
|
-
response: `${data.json.response}`,
|
|
228
|
-
responseBody: data.json.responseBody,
|
|
229
|
-
statusCode: data.json.statusCode
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
return { success: true, data: result.data, message: result.message };
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
const axiosError = error;
|
|
238
|
-
if (axiosError.data) {
|
|
239
|
-
console.log(axiosError.data);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
console.error("Request Failed:", axiosError);
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
success: false,
|
|
246
|
-
data: null,
|
|
247
|
-
message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || ""
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
exports._3RD_TOKI_HIPAY = _3RD_TOKI_HIPAY;
|
|
252
|
-
exports.default = {
|
|
253
|
-
SinglePushNoti: exports.SinglePushNoti,
|
|
254
|
-
SMS: exports.SMS,
|
|
255
|
-
MAIL: exports.MAIL,
|
|
256
|
-
_3RD: {
|
|
257
|
-
TOKI: exports._3RD_TOKI_NOTI,
|
|
258
|
-
HIPAY: exports._3RD_TOKI_HIPAY
|
|
259
|
-
}
|
|
260
|
-
};
|
|
3
|
+
exports.MAIL = exports.SMS = exports.SinglePushNoti = exports.mail = exports.sms = exports.push = void 0;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
/** Push мэдэгдэл — permission: notification.push */
|
|
6
|
+
const push = (body) => (0, request_1.request)({ method: "POST", path: "/main/v1/notification/single-push", name: "notification push", data: body });
|
|
7
|
+
exports.push = push;
|
|
8
|
+
/** SMS — permission: notification.sms */
|
|
9
|
+
const sms = (body) => (0, request_1.request)({ method: "POST", path: "/main/v1/notification/sms", name: "notification sms", data: body });
|
|
10
|
+
exports.sms = sms;
|
|
11
|
+
/** Имэйл — permission: notification.mail */
|
|
12
|
+
const mail = (body) => (0, request_1.request)({ method: "POST", path: "/main/v1/notification/mail", name: "notification mail", data: body });
|
|
13
|
+
exports.mail = mail;
|
|
14
|
+
// Хуучин нэрүүд (0.x) — хэвээр ажиллана
|
|
15
|
+
exports.SinglePushNoti = exports.push;
|
|
16
|
+
exports.SMS = exports.sms;
|
|
17
|
+
exports.MAIL = exports.mail;
|
|
18
|
+
exports.default = { push: exports.push, sms: exports.sms, mail: exports.mail, SinglePushNoti: exports.SinglePushNoti, SMS: exports.SMS, MAIL: exports.MAIL };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Method } from "axios";
|
|
2
|
+
import { Result } from "./types";
|
|
3
|
+
export type RequestOpts = {
|
|
4
|
+
method: Method;
|
|
5
|
+
path: string;
|
|
6
|
+
data?: any;
|
|
7
|
+
params?: Record<string, any>;
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Bearer token автоматаар нэмэх эсэх (default true) */
|
|
10
|
+
auth?: boolean;
|
|
11
|
+
host?: "MAIN" | "WALLET";
|
|
12
|
+
};
|
|
13
|
+
/** Нэг удаагийн HTTP хүсэлт — Result<T> буцна, throw хийхгүй */
|
|
14
|
+
export declare const rawRequest: <T>(opts: RequestOpts, token?: string) => Promise<Result<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Token-той хүсэлт: хүчинтэй access token авч (шаардлагатай бол refresh)
|
|
17
|
+
* илгээнэ; 401 ирвэл token-оо шинэчилж нэг удаа дахин оролдоно.
|
|
18
|
+
*/
|
|
19
|
+
export declare const request: <T>(opts: RequestOpts) => Promise<Result<T>>;
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.request = exports.rawRequest = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
const log = (name, info) => {
|
|
7
|
+
if (index_1.config.logger)
|
|
8
|
+
console.log(`[auth-mn] ${name}`, info);
|
|
9
|
+
};
|
|
10
|
+
/** Нэг удаагийн HTTP хүсэлт — Result<T> буцна, throw хийхгүй */
|
|
11
|
+
const rawRequest = async (opts, token) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const url = `${index_1.config.hosts[opts.host || "MAIN"]}${opts.path}`;
|
|
14
|
+
const req = {
|
|
15
|
+
method: opts.method,
|
|
16
|
+
url,
|
|
17
|
+
data: opts.data,
|
|
18
|
+
params: opts.params,
|
|
19
|
+
timeout: index_1.config.timeout,
|
|
20
|
+
maxBodyLength: Infinity,
|
|
21
|
+
headers: {
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
...(token ? { Authorization: `Bearer ${token}` } : {})
|
|
25
|
+
},
|
|
26
|
+
// 4xx-ийг throw хийлгэхгүй, өөрсдөө боловсруулна
|
|
27
|
+
validateStatus: () => true
|
|
28
|
+
};
|
|
29
|
+
const started = Date.now();
|
|
30
|
+
try {
|
|
31
|
+
const res = await axios_1.default.request(req);
|
|
32
|
+
const body = res.data || {};
|
|
33
|
+
log(opts.name || opts.path, {
|
|
34
|
+
status: res.status,
|
|
35
|
+
ms: Date.now() - started,
|
|
36
|
+
success: body.success,
|
|
37
|
+
message: body.message
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
success: body.success === true,
|
|
41
|
+
message: body.message || (res.status >= 400 ? `HTTP ${res.status}` : ""),
|
|
42
|
+
data: (_a = body.data) !== null && _a !== void 0 ? _a : null,
|
|
43
|
+
status: res.status
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const e = error;
|
|
48
|
+
log(opts.name || opts.path, { error: e.message, ms: Date.now() - started });
|
|
49
|
+
return { success: false, message: e.message || "Network error", data: null, status: 0 };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.rawRequest = rawRequest;
|
|
53
|
+
/**
|
|
54
|
+
* Token-той хүсэлт: хүчинтэй access token авч (шаардлагатай бол refresh)
|
|
55
|
+
* илгээнэ; 401 ирвэл token-оо шинэчилж нэг удаа дахин оролдоно.
|
|
56
|
+
*/
|
|
57
|
+
const request = async (opts) => {
|
|
58
|
+
// circular import-оос зайлсхийж энд дуудна
|
|
59
|
+
const { getToken, authState } = await Promise.resolve().then(() => require("./auth"));
|
|
60
|
+
if (opts.auth === false)
|
|
61
|
+
return (0, exports.rawRequest)(opts);
|
|
62
|
+
let token = await getToken();
|
|
63
|
+
if (!token) {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
message: authState.lastError ||
|
|
67
|
+
"Auth.mn token авч чадсангүй. setAuth({ client_id, client_secret }) тохируулсан эсэхээ шалгана уу.",
|
|
68
|
+
data: null,
|
|
69
|
+
status: 401
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
let res = await (0, exports.rawRequest)(opts, token);
|
|
73
|
+
if (res.status === 401) {
|
|
74
|
+
authState.clear();
|
|
75
|
+
token = await getToken();
|
|
76
|
+
if (token)
|
|
77
|
+
res = await (0, exports.rawRequest)(opts, token);
|
|
78
|
+
}
|
|
79
|
+
return res;
|
|
80
|
+
};
|
|
81
|
+
exports.request = request;
|
package/dist/socket.d.ts
CHANGED
|
@@ -1,101 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
title?: string;
|
|
15
|
-
amount?: number | string;
|
|
16
|
-
desc?: string;
|
|
17
|
-
footer?: {
|
|
18
|
-
text: string;
|
|
19
|
-
buttons: {
|
|
20
|
-
text: string;
|
|
21
|
-
fun: "href" | "close" | "exit";
|
|
22
|
-
href?: string | null;
|
|
23
|
-
}[];
|
|
24
|
-
};
|
|
25
|
-
show?: boolean;
|
|
26
|
-
expired_date?: Date;
|
|
27
|
-
start_date?: Date;
|
|
28
|
-
}) => Promise<{
|
|
29
|
-
success: boolean;
|
|
30
|
-
data: null;
|
|
31
|
-
message: string;
|
|
32
|
-
}>;
|
|
33
|
-
export declare const ShowOrderStatus: (body: {
|
|
34
|
-
user_id: number;
|
|
35
|
-
order_id: string;
|
|
36
|
-
}) => Promise<{
|
|
37
|
-
success: boolean;
|
|
38
|
-
data: null;
|
|
39
|
-
message: string;
|
|
40
|
-
}>;
|
|
41
|
-
export declare const EMIT: (body: {
|
|
42
|
-
user_id: number;
|
|
43
|
-
emit_name: string;
|
|
44
|
-
data: any;
|
|
45
|
-
}[]) => Promise<{
|
|
46
|
-
success: boolean;
|
|
47
|
-
data: null;
|
|
48
|
-
message: string;
|
|
49
|
-
}>;
|
|
1
|
+
import { EmitT, OrderStatusT, Result, StatusT, ToastT } from "./types";
|
|
2
|
+
/** Хэрэглэгчийн нээлттэй апп дээр toast — permission: socket.toast */
|
|
3
|
+
export declare const toast: (body: ToastT) => Promise<Result<null>>;
|
|
4
|
+
/** Төлөвийн карт (Loading / Success / Failure) — permission: socket.status */
|
|
5
|
+
export declare const status: (body: StatusT) => Promise<Result<null>>;
|
|
6
|
+
/** Захиалгын төлөв шинэчлэгдсэн event — permission: socket.status */
|
|
7
|
+
export declare const orderStatus: (body: OrderStatusT) => Promise<Result<null>>;
|
|
8
|
+
/** Дурын event олон хэрэглэгч рүү — permission: socket.emit */
|
|
9
|
+
export declare const emit: (body: EmitT[]) => Promise<Result<null>>;
|
|
10
|
+
export declare const ShowToast: (body: ToastT) => Promise<Result<null>>;
|
|
11
|
+
export declare const ShowStatus: (body: StatusT) => Promise<Result<null>>;
|
|
12
|
+
export declare const ShowOrderStatus: (body: OrderStatusT) => Promise<Result<null>>;
|
|
13
|
+
export declare const EMIT: (body: EmitT[]) => Promise<Result<null>>;
|
|
50
14
|
declare const _default: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}>;
|
|
60
|
-
ShowStatus: (body: {
|
|
61
|
-
user_id: number;
|
|
62
|
-
id: string;
|
|
63
|
-
type?: "Loading" | "Success" | "Failure";
|
|
64
|
-
title?: string;
|
|
65
|
-
amount?: number | string;
|
|
66
|
-
desc?: string;
|
|
67
|
-
footer?: {
|
|
68
|
-
text: string;
|
|
69
|
-
buttons: {
|
|
70
|
-
text: string;
|
|
71
|
-
fun: "href" | "close" | "exit";
|
|
72
|
-
href?: string | null;
|
|
73
|
-
}[];
|
|
74
|
-
};
|
|
75
|
-
show?: boolean;
|
|
76
|
-
expired_date?: Date;
|
|
77
|
-
start_date?: Date;
|
|
78
|
-
}) => Promise<{
|
|
79
|
-
success: boolean;
|
|
80
|
-
data: null;
|
|
81
|
-
message: string;
|
|
82
|
-
}>;
|
|
83
|
-
ShowOrderStatus: (body: {
|
|
84
|
-
user_id: number;
|
|
85
|
-
order_id: string;
|
|
86
|
-
}) => Promise<{
|
|
87
|
-
success: boolean;
|
|
88
|
-
data: null;
|
|
89
|
-
message: string;
|
|
90
|
-
}>;
|
|
91
|
-
EMIT: (body: {
|
|
92
|
-
user_id: number;
|
|
93
|
-
emit_name: string;
|
|
94
|
-
data: any;
|
|
95
|
-
}[]) => Promise<{
|
|
96
|
-
success: boolean;
|
|
97
|
-
data: null;
|
|
98
|
-
message: string;
|
|
99
|
-
}>;
|
|
15
|
+
toast: (body: ToastT) => Promise<Result<null>>;
|
|
16
|
+
status: (body: StatusT) => Promise<Result<null>>;
|
|
17
|
+
orderStatus: (body: OrderStatusT) => Promise<Result<null>>;
|
|
18
|
+
emit: (body: EmitT[]) => Promise<Result<null>>;
|
|
19
|
+
ShowToast: (body: ToastT) => Promise<Result<null>>;
|
|
20
|
+
ShowStatus: (body: StatusT) => Promise<Result<null>>;
|
|
21
|
+
ShowOrderStatus: (body: OrderStatusT) => Promise<Result<null>>;
|
|
22
|
+
EMIT: (body: EmitT[]) => Promise<Result<null>>;
|
|
100
23
|
};
|
|
101
24
|
export default _default;
|