auth-mn 1.0.1 → 1.1.0
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 +31 -1
- package/dist/exp.d.ts +27 -0
- package/dist/exp.js +51 -0
- package/dist/index.d.ts +22 -3
- package/dist/index.js +23 -4
- package/dist/types.d.ts +17 -0
- package/package.json +47 -47
package/README.md
CHANGED
|
@@ -176,7 +176,37 @@ await authMn.socket.orderStatus({ user_id, order_id: "order-123" });
|
|
|
176
176
|
await authMn.socket.emit([{ user_id, emit_name: "my-event", data: { any: 1 } }]); // socket.emit
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
## 6.
|
|
179
|
+
## 6. EXP нэмэх (Seller Panda г.м.)
|
|
180
|
+
|
|
181
|
+
Хэрэглэгчид exp олгох. client_id/secret-ээс **тусдаа EXP түлхүүр** хэрэгтэй — Admin panel →
|
|
182
|
+
**EXP түлхүүр** дээр нэр (ж: `Seller Panda`) + нэг дуудлагад олгох exp-ийг admin тохируулж
|
|
183
|
+
үүсгэнэ (`exp_…`, нэг удаа харагдана). Хэдэн exp нэмэгдэх нь түлхүүр дээр тогтсон — дуудагч
|
|
184
|
+
тал өөрчилж чадахгүй.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import authMn, { setExpKey } from "auth-mn";
|
|
188
|
+
|
|
189
|
+
setExpKey(process.env.AUTH_MN_EXP_KEY); // exp_…
|
|
190
|
+
|
|
191
|
+
// user_id-ээр
|
|
192
|
+
const r = await authMn.exp.add({
|
|
193
|
+
user_id: 8636569,
|
|
194
|
+
desc: "Худалдан авалт #1234",
|
|
195
|
+
ref: "order-1234" // optional — ижил ref-ээр дахин дуудахад давхар нэмэхгүй
|
|
196
|
+
});
|
|
197
|
+
// r.data → { user_id, exp: 10, exp_total: 1250, desc, ref, duplicate: false, ... }
|
|
198
|
+
|
|
199
|
+
// эсвэл frontend-ээс ирсэн хэрэглэгчийн token-оор
|
|
200
|
+
await authMn.exp.add({ token: userToken, desc: "Өдөр тутмын нэвтрэлт" });
|
|
201
|
+
|
|
202
|
+
// тухайн түлхүүрээр нэмсэн лог
|
|
203
|
+
const logs = await authMn.exp.logs({ user_id: 8636569, page: 1, limit: 20 });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Шууд HTTP: `POST https://api.auth.mn/main/v1/auth/exp/add` — `Authorization: Bearer exp_…`
|
|
207
|
+
(эсвэл `x-exp-key: exp_…`), body `{ user_id | token, desc, ref? }`.
|
|
208
|
+
|
|
209
|
+
## 7. Client өөрийн мэдээлэл
|
|
180
210
|
|
|
181
211
|
```ts
|
|
182
212
|
import { config } from "auth-mn";
|
package/dist/exp.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ExpAddResult, ExpLog, PageResult, Result } from "./types";
|
|
2
|
+
export declare const add: (input: {
|
|
3
|
+
user_id?: number | string;
|
|
4
|
+
token?: string;
|
|
5
|
+
desc: string;
|
|
6
|
+
ref?: string;
|
|
7
|
+
}, key?: string) => Promise<Result<ExpAddResult>>;
|
|
8
|
+
/** Тухайн түлхүүрээр нэмсэн exp-ийн лог (user_id-ээр шүүж болно) */
|
|
9
|
+
export declare const logs: (filter?: {
|
|
10
|
+
user_id?: number | string;
|
|
11
|
+
page?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}, key?: string) => Promise<Result<PageResult<ExpLog>>>;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
add: (input: {
|
|
16
|
+
user_id?: number | string;
|
|
17
|
+
token?: string;
|
|
18
|
+
desc: string;
|
|
19
|
+
ref?: string;
|
|
20
|
+
}, key?: string) => Promise<Result<ExpAddResult>>;
|
|
21
|
+
logs: (filter?: {
|
|
22
|
+
user_id?: number | string;
|
|
23
|
+
page?: number;
|
|
24
|
+
limit?: number;
|
|
25
|
+
}, key?: string) => Promise<Result<PageResult<ExpLog>>>;
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
package/dist/exp.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logs = exports.add = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const request_1 = require("./request");
|
|
6
|
+
/**
|
|
7
|
+
* EXP — хэрэглэгчид exp нэмэх.
|
|
8
|
+
*
|
|
9
|
+
* Admin panel → "EXP түлхүүр" дээр нэр (ж: Seller Panda) + нэг дуудлагад олгох exp-тэй
|
|
10
|
+
* түлхүүр үүсгэнэ. Энэ түлхүүр client_id/secret-ээс тусдаа: setExpKey("exp_…")-ээр
|
|
11
|
+
* тохируулна (эсвэл дуудлага бүрт key өгнө).
|
|
12
|
+
*
|
|
13
|
+
* import authMn, { setExpKey } from "auth-mn";
|
|
14
|
+
* setExpKey(process.env.AUTH_MN_EXP_KEY);
|
|
15
|
+
* await authMn.exp.add({ user_id: 8636569, desc: "Худалдан авалт #1234", ref: "order-1234" });
|
|
16
|
+
* // эсвэл frontend-ээс ирсэн хэрэглэгчийн token-оор:
|
|
17
|
+
* await authMn.exp.add({ token: userToken, desc: "Худалдан авалт" });
|
|
18
|
+
*
|
|
19
|
+
* Хэдэн exp нэмэгдэх нь түлхүүр дээр admin-ийн тохируулсан хэмжээ — дуудагч тал өөрчилж чадахгүй.
|
|
20
|
+
* `ref` өгвөл ижил ref-ээр дахин дуудахад давхар нэмэхгүй (data.duplicate = true).
|
|
21
|
+
*/
|
|
22
|
+
const keyOf = (key) => {
|
|
23
|
+
const k = (key || index_1.config.expKey || "").trim();
|
|
24
|
+
if (!k)
|
|
25
|
+
throw new Error("[auth-mn] EXP түлхүүр тохируулаагүй байна: setExpKey(\"exp_…\")");
|
|
26
|
+
return k;
|
|
27
|
+
};
|
|
28
|
+
const add = (input, key) => {
|
|
29
|
+
let k;
|
|
30
|
+
try {
|
|
31
|
+
k = keyOf(key);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return Promise.resolve({ success: false, message: e.message, data: null, status: 0 });
|
|
35
|
+
}
|
|
36
|
+
return (0, request_1.rawRequest)({ method: "POST", path: "/main/v1/auth/exp/add", name: "exp add", data: input, auth: false }, k);
|
|
37
|
+
};
|
|
38
|
+
exports.add = add;
|
|
39
|
+
/** Тухайн түлхүүрээр нэмсэн exp-ийн лог (user_id-ээр шүүж болно) */
|
|
40
|
+
const logs = (filter = {}, key) => {
|
|
41
|
+
let k;
|
|
42
|
+
try {
|
|
43
|
+
k = keyOf(key);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return Promise.resolve({ success: false, message: e.message, data: null, status: 0 });
|
|
47
|
+
}
|
|
48
|
+
return (0, request_1.rawRequest)({ method: "GET", path: "/main/v1/auth/exp/logs", name: "exp logs", params: filter, auth: false }, k);
|
|
49
|
+
};
|
|
50
|
+
exports.logs = logs;
|
|
51
|
+
exports.default = { add: exports.add, logs: exports.logs };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
* Client-д олгосон permission-ээс гадуур API дуудвал 403 + message буцна.
|
|
11
11
|
*
|
|
12
12
|
* Хамрах хүрээ: хэрэглэгч (verify / find), мэдэгдэл (push / sms / mail),
|
|
13
|
-
* socket (toast / status / orderStatus / emit)
|
|
14
|
-
* бүртгэлүүд энэ санд байхгүй.
|
|
13
|
+
* socket (toast / status / orderStatus / emit), exp (хэрэглэгчид exp нэмэх —
|
|
14
|
+
* тусдаа EXP түлхүүр, setExpKey). Merchant/admin зэрэг дотоод бүртгэлүүд энэ санд байхгүй.
|
|
15
15
|
*/
|
|
16
16
|
import auth from "./auth";
|
|
17
17
|
import user from "./user";
|
|
18
18
|
import notification from "./notification";
|
|
19
19
|
import socket from "./socket";
|
|
20
|
+
import exp from "./exp";
|
|
20
21
|
export type Env = "prod" | "staging";
|
|
21
22
|
export type Config = {
|
|
22
23
|
/** Одоогийн client access token (сан автоматаар шинэчилнэ; гараар Authorization header үүсгэхэд ашиглаж болно) */
|
|
@@ -30,6 +31,8 @@ export type Config = {
|
|
|
30
31
|
client_id: string;
|
|
31
32
|
client_secret: string;
|
|
32
33
|
};
|
|
34
|
+
/** EXP түлхүүр (exp_…) — Admin panel → EXP түлхүүр. authMn.exp.* дуудлагад ашиглана */
|
|
35
|
+
expKey: string;
|
|
33
36
|
logger: boolean;
|
|
34
37
|
/** Хүсэлтийн timeout (ms), default 20000 */
|
|
35
38
|
timeout: number;
|
|
@@ -45,11 +48,13 @@ export declare const setAuth: (auth: {
|
|
|
45
48
|
client_id: string;
|
|
46
49
|
client_secret: string;
|
|
47
50
|
}) => void;
|
|
51
|
+
/** EXP түлхүүр (Admin panel → EXP түлхүүр дээрээс авна). authMn.exp.add-д ашиглана */
|
|
52
|
+
export declare const setExpKey: (key: string | undefined | null) => void;
|
|
48
53
|
export declare const setLogger: (status: boolean) => void;
|
|
49
54
|
export declare const jsonToQueryString: (params: Record<string, any>) => string;
|
|
50
55
|
export declare const ObjectId: () => string;
|
|
51
56
|
import { authState } from "./auth";
|
|
52
|
-
export { auth, user, notification, socket, authState };
|
|
57
|
+
export { auth, user, notification, socket, exp, authState };
|
|
53
58
|
export * from "./types";
|
|
54
59
|
declare const _default: {
|
|
55
60
|
auth: {
|
|
@@ -105,6 +110,19 @@ declare const _default: {
|
|
|
105
110
|
ShowOrderStatus: (body: import("./types").OrderStatusT) => Promise<import("./types").Result<null>>;
|
|
106
111
|
EMIT: (body: import("./types").EmitT[]) => Promise<import("./types").Result<null>>;
|
|
107
112
|
};
|
|
113
|
+
exp: {
|
|
114
|
+
add: (input: {
|
|
115
|
+
user_id?: number | string;
|
|
116
|
+
token?: string;
|
|
117
|
+
desc: string;
|
|
118
|
+
ref?: string;
|
|
119
|
+
}, key?: string) => Promise<import("./types").Result<import("./types").ExpAddResult>>;
|
|
120
|
+
logs: (filter?: {
|
|
121
|
+
user_id?: number | string;
|
|
122
|
+
page?: number;
|
|
123
|
+
limit?: number;
|
|
124
|
+
}, key?: string) => Promise<import("./types").Result<import("./types").PageResult<import("./types").ExpLog>>>;
|
|
125
|
+
};
|
|
108
126
|
setAuth: (auth: {
|
|
109
127
|
client_id: string;
|
|
110
128
|
client_secret: string;
|
|
@@ -113,6 +131,7 @@ declare const _default: {
|
|
|
113
131
|
MAIN: string;
|
|
114
132
|
WALLET?: string;
|
|
115
133
|
}, env?: Env) => void;
|
|
134
|
+
setExpKey: (key: string | undefined | null) => void;
|
|
116
135
|
setLogger: (status: boolean) => void;
|
|
117
136
|
ObjectId: () => string;
|
|
118
137
|
};
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.authState = exports.socket = exports.notification = exports.user = exports.auth = exports.ObjectId = exports.jsonToQueryString = exports.setLogger = exports.setAuth = exports.setHost = exports.config = void 0;
|
|
17
|
+
exports.authState = exports.exp = exports.socket = exports.notification = exports.user = exports.auth = exports.ObjectId = exports.jsonToQueryString = exports.setLogger = exports.setExpKey = exports.setAuth = exports.setHost = exports.config = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* auth-mn — Auth.mn API client (Node.js)
|
|
20
20
|
*
|
|
@@ -27,8 +27,8 @@ exports.authState = exports.socket = exports.notification = exports.user = expor
|
|
|
27
27
|
* Client-д олгосон permission-ээс гадуур API дуудвал 403 + message буцна.
|
|
28
28
|
*
|
|
29
29
|
* Хамрах хүрээ: хэрэглэгч (verify / find), мэдэгдэл (push / sms / mail),
|
|
30
|
-
* socket (toast / status / orderStatus / emit)
|
|
31
|
-
* бүртгэлүүд энэ санд байхгүй.
|
|
30
|
+
* socket (toast / status / orderStatus / emit), exp (хэрэглэгчид exp нэмэх —
|
|
31
|
+
* тусдаа EXP түлхүүр, setExpKey). Merchant/admin зэрэг дотоод бүртгэлүүд энэ санд байхгүй.
|
|
32
32
|
*/
|
|
33
33
|
const auth_1 = require("./auth");
|
|
34
34
|
exports.auth = auth_1.default;
|
|
@@ -38,6 +38,8 @@ const notification_1 = require("./notification");
|
|
|
38
38
|
exports.notification = notification_1.default;
|
|
39
39
|
const socket_1 = require("./socket");
|
|
40
40
|
exports.socket = socket_1.default;
|
|
41
|
+
const exp_1 = require("./exp");
|
|
42
|
+
exports.exp = exp_1.default;
|
|
41
43
|
const HOSTS = {
|
|
42
44
|
prod: { MAIN: "https://api.auth.mn", WALLET: "https://api.auth.mn" },
|
|
43
45
|
staging: { MAIN: "https://staging-api.auth.mn", WALLET: "https://staging-api.auth.mn" }
|
|
@@ -47,6 +49,7 @@ exports.config = {
|
|
|
47
49
|
env: "prod",
|
|
48
50
|
hosts: { ...HOSTS.prod },
|
|
49
51
|
auth: { client_id: "", client_secret: "" },
|
|
52
|
+
expKey: "",
|
|
50
53
|
logger: false,
|
|
51
54
|
timeout: 20000
|
|
52
55
|
};
|
|
@@ -74,6 +77,11 @@ const setAuth = (auth) => {
|
|
|
74
77
|
auth_2.authState.clear();
|
|
75
78
|
};
|
|
76
79
|
exports.setAuth = setAuth;
|
|
80
|
+
/** EXP түлхүүр (Admin panel → EXP түлхүүр дээрээс авна). authMn.exp.add-д ашиглана */
|
|
81
|
+
const setExpKey = (key) => {
|
|
82
|
+
exports.config.expKey = (key || "").trim();
|
|
83
|
+
};
|
|
84
|
+
exports.setExpKey = setExpKey;
|
|
77
85
|
const setLogger = (status) => {
|
|
78
86
|
exports.config.logger = status;
|
|
79
87
|
};
|
|
@@ -95,4 +103,15 @@ exports.ObjectId = ObjectId;
|
|
|
95
103
|
const auth_2 = require("./auth");
|
|
96
104
|
Object.defineProperty(exports, "authState", { enumerable: true, get: function () { return auth_2.authState; } });
|
|
97
105
|
__exportStar(require("./types"), exports);
|
|
98
|
-
exports.default = {
|
|
106
|
+
exports.default = {
|
|
107
|
+
auth: auth_1.default,
|
|
108
|
+
user: user_1.default,
|
|
109
|
+
notification: notification_1.default,
|
|
110
|
+
socket: socket_1.default,
|
|
111
|
+
exp: exp_1.default,
|
|
112
|
+
setAuth: exports.setAuth,
|
|
113
|
+
setHost: exports.setHost,
|
|
114
|
+
setExpKey: exports.setExpKey,
|
|
115
|
+
setLogger: exports.setLogger,
|
|
116
|
+
ObjectId: exports.ObjectId
|
|
117
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -159,6 +159,23 @@ export type PageResult<T> = {
|
|
|
159
159
|
page: number;
|
|
160
160
|
limit: number;
|
|
161
161
|
};
|
|
162
|
+
export type ExpLog = {
|
|
163
|
+
_id: string;
|
|
164
|
+
user_id: number;
|
|
165
|
+
key_id: string;
|
|
166
|
+
key_name: string;
|
|
167
|
+
/** Нэмсэн exp */
|
|
168
|
+
exp: number;
|
|
169
|
+
/** Нэмсний дараах хэрэглэгчийн нийт exp */
|
|
170
|
+
exp_total: number;
|
|
171
|
+
desc: string;
|
|
172
|
+
ref?: string;
|
|
173
|
+
createdAt?: string;
|
|
174
|
+
};
|
|
175
|
+
export type ExpAddResult = ExpLog & {
|
|
176
|
+
/** true бол ижил ref-ээр өмнө нь нэмэгдсэн — давхар нэмээгүй */
|
|
177
|
+
duplicate: boolean;
|
|
178
|
+
};
|
|
162
179
|
export type PushNotiT = {
|
|
163
180
|
user_id: number;
|
|
164
181
|
target_app: string;
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "auth-mn",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Auth.mn API client for Node.js — client_id/secret token, user, notification, socket",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist/"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"build-ts": "rm -rf ./dist && npx tsc",
|
|
13
|
-
"build": "npx tsc",
|
|
14
|
-
"debug": "npm run build && npm run watch-debug",
|
|
15
|
-
"lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
|
|
16
|
-
"typecheck": "tsc --noEmit"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/togtokh-dev/auth-mn.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"auth.mn",
|
|
24
|
-
"axios",
|
|
25
|
-
"togtokh.dev"
|
|
26
|
-
],
|
|
27
|
-
"author": "TOGTOKH.DEV",
|
|
28
|
-
"license": "ISC",
|
|
29
|
-
"bugs": {
|
|
30
|
-
"url": "https://github.com/togtokh-dev/auth-mn/issues"
|
|
31
|
-
},
|
|
32
|
-
"homepage": "https://github.com/togtokh-dev/auth-mn/#readme",
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"axios": "^1.6.2"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/node": "^18.15.11",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
39
|
-
"@typescript-eslint/parser": "^6.4.0",
|
|
40
|
-
"eslint": "^8.47.0",
|
|
41
|
-
"ts-node": "^10.9.2",
|
|
42
|
-
"typescript": "^5.0.4"
|
|
43
|
-
},
|
|
44
|
-
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "auth-mn",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Auth.mn API client for Node.js — client_id/secret token, user, notification, socket",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build-ts": "rm -rf ./dist && npx tsc",
|
|
13
|
+
"build": "npx tsc",
|
|
14
|
+
"debug": "npm run build && npm run watch-debug",
|
|
15
|
+
"lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/togtokh-dev/auth-mn.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"auth.mn",
|
|
24
|
+
"axios",
|
|
25
|
+
"togtokh.dev"
|
|
26
|
+
],
|
|
27
|
+
"author": "TOGTOKH.DEV",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/togtokh-dev/auth-mn/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/togtokh-dev/auth-mn/#readme",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"axios": "^1.6.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^18.15.11",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
39
|
+
"@typescript-eslint/parser": "^6.4.0",
|
|
40
|
+
"eslint": "^8.47.0",
|
|
41
|
+
"ts-node": "^10.9.2",
|
|
42
|
+
"typescript": "^5.0.4"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
47
|
+
}
|