@nimee/api-clients 0.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/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "singleQuote": false,
3
+ "trailingComma": "es5",
4
+ "printWidth": 130,
5
+ "semi": true
6
+ }
@@ -0,0 +1,2 @@
1
+ import userClient from "./user";
2
+ export default userClient;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const user_1 = __importDefault(require("./user"));
7
+ exports.default = user_1.default;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,kDAAgC;AAChC,kBAAe,cAAU,CAAC"}
@@ -0,0 +1,12 @@
1
+ export default class userClient {
2
+ verifyToken(token: string): Promise<import("axios").AxiosResponse<any, any>>;
3
+ checkAccountRole(params: {
4
+ jwt: string;
5
+ requestRoute: string;
6
+ accountId: string;
7
+ }): Promise<import("axios").AxiosResponse<any, any>>;
8
+ getAccountById(params: {
9
+ jwt: string;
10
+ accountId: string;
11
+ }): Promise<any>;
12
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ const userPort = 3002;
17
+ const userUrl = `http://localhost:${userPort}/user`;
18
+ const accountUrl = `http://localhost:${userPort}/user/account`;
19
+ class userClient {
20
+ verifyToken(token) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return yield axios_1.default.get(`${userUrl}/verifyToken`, { headers: { authorization: `Bearer ${token}` } });
23
+ });
24
+ }
25
+ checkAccountRole(params) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const { requestRoute, accountId, jwt } = params;
28
+ if (!requestRoute || !accountId || !jwt) {
29
+ throw new Error("userId, requestRoute, accountId and jwt are required");
30
+ }
31
+ return yield axios_1.default.post(`${accountUrl}/checkRole/${accountId}`, params, { headers: { authorization: jwt } });
32
+ });
33
+ }
34
+ getAccountById(params) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const { accountId, jwt } = params;
37
+ if (!jwt || !accountId) {
38
+ throw new Error("jwt, accountId and jwt are required");
39
+ }
40
+ const response = yield axios_1.default.get(`${accountUrl}/${accountId}`, { headers: { authorization: jwt } });
41
+ return response === null || response === void 0 ? void 0 : response.data;
42
+ });
43
+ }
44
+ }
45
+ exports.default = userClient;
46
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/user.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,OAAO,GAAG,oBAAoB,QAAQ,OAAO,CAAC;AACpD,MAAM,UAAU,GAAG,oBAAoB,QAAQ,eAAe,CAAC;AAE/D,MAAqB,UAAU;IACvB,WAAW,CAAC,KAAa;;YAC7B,OAAO,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,OAAO,cAAc,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACtG,CAAC;KAAA;IACK,gBAAgB,CAAC,MAAgE;;YACrF,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;YAChD,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE;gBACvC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;aACzE;YACD,OAAO,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,UAAU,cAAc,SAAS,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/G,CAAC;KAAA;IACK,cAAc,CAAC,MAA0C;;YAC7D,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;YAClC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;aACxD;YACD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,UAAU,IAAI,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YACpG,OAAO,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC;QACxB,CAAC;KAAA;CACF;AAnBD,6BAmBC"}
package/nodemon.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src"],
3
+ "ext": "ts,json",
4
+ "ignore": ["src/**/*.spec.ts"],
5
+ "exec": "npm run build"
6
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@nimee/api-clients",
3
+ "version": "0.0.1",
4
+ "description": "communication http for each ms",
5
+ "main": "dist/src/index.js",
6
+ "author": "dan goldberg",
7
+ "license": "ISC",
8
+ "scripts": {
9
+ "build-ts": "tsc",
10
+ "watch-ts": "tsc -w",
11
+ "build": "npm run build-ts",
12
+ "lint": "eslint -c ../../.eslintrc.js --ext .ts src/**",
13
+ "watch": "nodemon",
14
+ "prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write"
15
+ },
16
+ "devDependencies": {
17
+ "@typescript-eslint/eslint-plugin": "^5.18.0",
18
+ "@typescript-eslint/eslint-plugin-tslint": "^5.18.0",
19
+ "@typescript-eslint/parser": "^5.18.0",
20
+ "eslint": "8.22.0",
21
+ "eslint-plugin-jsdoc": "^38.1.6",
22
+ "eslint-plugin-no-null": "^1.0.2",
23
+ "nodemon": "^1.19.1",
24
+ "typescript": "4.6.3"
25
+ },
26
+ "types": "dist/src/index.d.ts",
27
+ "dependencies": {
28
+ }
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ import userClient from "./user";
2
+ export default userClient;
package/src/user.ts ADDED
@@ -0,0 +1,26 @@
1
+ import axios from "axios";
2
+ import logger from "@minta/logger";
3
+ const userPort = 3002;
4
+ const userUrl = `http://localhost:${userPort}/user`;
5
+ const accountUrl = `http://localhost:${userPort}/user/account`;
6
+
7
+ export default class userClient {
8
+ async verifyToken(token: string) {
9
+ return await axios.get(`${userUrl}/verifyToken`, { headers: { authorization: `Bearer ${token}` } });
10
+ }
11
+ async checkAccountRole(params: { jwt: string; requestRoute: string; accountId: string }) {
12
+ const { requestRoute, accountId, jwt } = params;
13
+ if (!requestRoute || !accountId || !jwt) {
14
+ throw new Error("userId, requestRoute, accountId and jwt are required");
15
+ }
16
+ return await axios.post(`${accountUrl}/checkRole/${accountId}`, params, { headers: { authorization: jwt } });
17
+ }
18
+ async getAccountById(params: { jwt: string; accountId: string }) {
19
+ const { accountId, jwt } = params;
20
+ if (!jwt || !accountId) {
21
+ throw new Error("jwt, accountId and jwt are required");
22
+ }
23
+ const response = await axios.get(`${accountUrl}/${accountId}`, { headers: { authorization: jwt } });
24
+ return response?.data;
25
+ }
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compileOnSave": true,
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "esModuleInterop": true,
6
+ "declaration": true,
7
+ "target": "es6",
8
+ "noImplicitAny": true,
9
+ "skipLibCheck": true,
10
+ "moduleResolution": "node",
11
+ "sourceMap": true,
12
+ "outDir": "./dist",
13
+ "baseUrl": "./",
14
+ "rootDir": "./",
15
+ }
16
+ }