auth-mn 0.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 ADDED
@@ -0,0 +1 @@
1
+ # AUTH.MN
package/dist/auth.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export declare const getToken: () => Promise<string>;
2
+ declare const _default: {
3
+ TOKEN: (auth: {
4
+ username: string;
5
+ password: string;
6
+ }) => Promise<string>;
7
+ };
8
+ export default _default;
package/dist/auth.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToken = void 0;
4
+ const _1 = require("./");
5
+ const axios_master_1 = require("axios-master");
6
+ const TOKEN = async (auth) => {
7
+ try {
8
+ const response = await (0, axios_master_1.axiosMasterMain)({
9
+ method: "GET",
10
+ url: `${_1.config.hosts.MAIN}/main/v1/auth//client/create`,
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ },
14
+ data: {
15
+ email: auth.username,
16
+ password: auth.password,
17
+ },
18
+ }, {
19
+ name: "Token",
20
+ timeout: 20000,
21
+ logger: (data) => {
22
+ if (_1.config.logger)
23
+ console.log(data);
24
+ },
25
+ });
26
+ if (response === null || response === void 0 ? void 0 : response.token) {
27
+ _1.config.token = response === null || response === void 0 ? void 0 : response.token;
28
+ return response === null || response === void 0 ? void 0 : response.token;
29
+ }
30
+ return "";
31
+ }
32
+ catch (error) {
33
+ const axiosError = error;
34
+ if (axiosError.data) {
35
+ console.log(axiosError.data);
36
+ }
37
+ else {
38
+ console.error("Token Request Failed:", axiosError);
39
+ }
40
+ return "";
41
+ }
42
+ };
43
+ const getToken = async () => {
44
+ try {
45
+ const response = await (0, axios_master_1.axiosMasterMain)({
46
+ method: "GET",
47
+ url: `${_1.config.hosts.MAIN}/main/v1/auth//client/create`,
48
+ headers: {
49
+ "Content-Type": "application/json",
50
+ },
51
+ data: {
52
+ email: _1.config.auth.username,
53
+ password: _1.config.auth.password,
54
+ },
55
+ }, {
56
+ name: "Token",
57
+ timeout: 20000,
58
+ logger: (data) => {
59
+ if (_1.config.logger)
60
+ console.log(data);
61
+ },
62
+ });
63
+ if (response === null || response === void 0 ? void 0 : response.token) {
64
+ _1.config.token = response === null || response === void 0 ? void 0 : response.token;
65
+ return response === null || response === void 0 ? void 0 : response.token;
66
+ }
67
+ return "";
68
+ }
69
+ catch (error) {
70
+ const axiosError = error;
71
+ if (axiosError.data) {
72
+ console.log(axiosError.data);
73
+ }
74
+ else {
75
+ console.error("Token Request Failed:", axiosError);
76
+ }
77
+ return "";
78
+ }
79
+ };
80
+ exports.getToken = getToken;
81
+ exports.default = { TOKEN };
@@ -0,0 +1,52 @@
1
+ export declare const jsonToQueryString: (params: Record<string, any>) => string;
2
+ export declare const ObjectId: () => string;
3
+ export type Config = {
4
+ token: string;
5
+ env: "prod" | "staging";
6
+ hosts: {
7
+ MAIN: string;
8
+ WALLET: string;
9
+ };
10
+ auth: {
11
+ username: string;
12
+ password: string;
13
+ };
14
+ logger: boolean;
15
+ };
16
+ export declare const config: Config;
17
+ export declare const setHost: ({ MAIN, WALLET }: {
18
+ MAIN: string;
19
+ WALLET: string;
20
+ }, ENV: "staging" | "prod") => void;
21
+ export declare const setLogger: (status: boolean) => void;
22
+ declare const _default: {
23
+ auth: {
24
+ TOKEN: (auth: {
25
+ username: string;
26
+ password: string;
27
+ }) => Promise<string>;
28
+ };
29
+ ObjectId: () => string;
30
+ notification: {
31
+ SinglePushNoti: (body: {
32
+ user_id: number;
33
+ target_app: "AVDAR-STORE" | "AUTH-APP";
34
+ body: {
35
+ title: string;
36
+ body: string;
37
+ icon: string;
38
+ image?: string;
39
+ button?: {
40
+ title: string;
41
+ url: string;
42
+ } | null;
43
+ };
44
+ }) => Promise<{
45
+ success: boolean;
46
+ data: null;
47
+ message: string;
48
+ }>;
49
+ };
50
+ };
51
+ export default _default;
52
+ export { default as notification } from "./notification";
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notification = exports.setLogger = exports.setHost = exports.config = exports.ObjectId = exports.jsonToQueryString = void 0;
4
+ const auth_1 = require("./auth");
5
+ const notification_1 = require("./notification");
6
+ const jsonToQueryString = (params) => {
7
+ const query = Object.entries(params)
8
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
9
+ .join("&");
10
+ return query ? `?${query}` : "";
11
+ };
12
+ exports.jsonToQueryString = jsonToQueryString;
13
+ const ObjectId = () => {
14
+ const timestamp = ((Date.now() / 1000) | 0).toString(16);
15
+ return (timestamp +
16
+ "xxxxxxxxxxxxxxxx"
17
+ .replace(/[x]/g, () => ((Math.random() * 16) | 0).toString(16))
18
+ .toLowerCase());
19
+ };
20
+ exports.ObjectId = ObjectId;
21
+ exports.config = {
22
+ token: "",
23
+ env: "staging",
24
+ hosts: {
25
+ MAIN: "https://staging-api.auth.mn",
26
+ WALLET: "https://staging-api.auth.mn",
27
+ },
28
+ auth: {
29
+ username: "",
30
+ password: "",
31
+ },
32
+ logger: false,
33
+ };
34
+ // Function to set the host URLs for API requests
35
+ const setHost = ({ MAIN, WALLET }, ENV) => {
36
+ exports.config.hosts.MAIN = MAIN;
37
+ exports.config.hosts.WALLET = WALLET;
38
+ exports.config.env = ENV;
39
+ console.log("Hosts set to:", exports.config.hosts);
40
+ console.log("Environment set to:", ENV);
41
+ };
42
+ exports.setHost = setHost;
43
+ // Function to enable or disable logging
44
+ const setLogger = (status) => {
45
+ exports.config.logger = status;
46
+ console.log("Logger status set to:", status);
47
+ };
48
+ exports.setLogger = setLogger;
49
+ exports.default = {
50
+ auth: auth_1.default,
51
+ ObjectId: exports.ObjectId,
52
+ notification: notification_1.default,
53
+ };
54
+ var notification_2 = require("./notification");
55
+ Object.defineProperty(exports, "notification", { enumerable: true, get: function () { return notification_2.default; } });
@@ -0,0 +1,27 @@
1
+ type SinglePushNotiT = {
2
+ user_id: number;
3
+ target_app: "AVDAR-STORE" | "AUTH-APP";
4
+ body: {
5
+ title: string;
6
+ body: string;
7
+ icon: string;
8
+ image?: string;
9
+ button?: {
10
+ title: string;
11
+ url: string;
12
+ } | null;
13
+ };
14
+ };
15
+ export declare const SinglePushNoti: (body: SinglePushNotiT) => Promise<{
16
+ success: boolean;
17
+ data: null;
18
+ message: string;
19
+ }>;
20
+ declare const _default: {
21
+ SinglePushNoti: (body: SinglePushNotiT) => Promise<{
22
+ success: boolean;
23
+ data: null;
24
+ message: string;
25
+ }>;
26
+ };
27
+ export default _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SinglePushNoti = void 0;
4
+ const _1 = require(".");
5
+ const auth_1 = require("./auth");
6
+ const axios_master_1 = require("axios-master");
7
+ const SinglePushNoti = async (body) => {
8
+ var _a;
9
+ try {
10
+ const result = await (0, axios_master_1.axiosMasterMain)({
11
+ method: "POST",
12
+ maxBodyLength: Infinity,
13
+ url: `${_1.config.hosts.MAIN}/main/v1/notification/single-push`,
14
+ headers: {
15
+ Accept: "application/json",
16
+ "Content-Type": "application/json",
17
+ Authorization: `Bearer ${_1.config.token}`,
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(data.json);
29
+ }
30
+ },
31
+ });
32
+ return { success: true, data: result.data, message: result.message };
33
+ }
34
+ catch (error) {
35
+ const axiosError = error;
36
+ if (axiosError.data) {
37
+ console.log(axiosError.data);
38
+ }
39
+ else {
40
+ console.error("Request Failed:", axiosError);
41
+ }
42
+ return {
43
+ success: false,
44
+ data: null,
45
+ message: ((_a = axiosError.data) === null || _a === void 0 ? void 0 : _a.message) || "",
46
+ };
47
+ }
48
+ };
49
+ exports.SinglePushNoti = SinglePushNoti;
50
+ exports.default = { SinglePushNoti: exports.SinglePushNoti };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "auth-mn",
3
+ "version": "0.1.0",
4
+ "description": "Auth.mn API",
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
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/togtokh-dev/auth-mn.git"
20
+ },
21
+ "keywords": [
22
+ "auth.mn",
23
+ "axios",
24
+ "togtokh.dev"
25
+ ],
26
+ "author": "TOGTOKH.DEV",
27
+ "license": "ISC",
28
+ "bugs": {
29
+ "url": "https://github.com/togtokh-dev/auth-mn/issues"
30
+ },
31
+ "homepage": "https://github.com/togtokh-dev/auth-mn/#readme",
32
+ "dependencies": {
33
+ "axios": "^1.6.2",
34
+ "axios-master": "^1.1.6",
35
+ "https": "^1.0.0",
36
+ "ts-node": "^10.9.2",
37
+ "typescript": "^5.0.4"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^18.15.11",
41
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
42
+ "@typescript-eslint/parser": "^6.4.0",
43
+ "eslint": "^8.47.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }