itrm-tools 1.0.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,2 @@
1
+ # itrm-tools
2
+ Library developed by Intelligent Trading Machines for building robust APIs
@@ -0,0 +1,3 @@
1
+ export interface APIChecker {
2
+ initialize(): PromiseLike<any>;
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=APIChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"APIChecker.js","sourceRoot":"","sources":["../../src/api/APIChecker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import { Express, Request, Response } from 'express';
2
+ export declare enum RequestMethod {
3
+ GET = "GET",
4
+ POST = "POST",
5
+ PUT = "PUT",
6
+ DELETE = "DELETE"
7
+ }
8
+ export declare enum RequestContext {
9
+ BODY = "body",
10
+ PARAMS = "params",
11
+ QUERY = "query"
12
+ }
13
+ export interface GroupedParameters {
14
+ context: RequestContext;
15
+ properties: string[];
16
+ }
17
+ export interface APIRequestConfig {
18
+ path: string;
19
+ params: GroupedParameters[];
20
+ }
21
+ export declare abstract class APIRequest {
22
+ method: RequestMethod;
23
+ path: string;
24
+ private params;
25
+ constructor(method: RequestMethod, config: APIRequestConfig);
26
+ abstract init(app: Express): Promise<void>;
27
+ process(req: Request, res: Response): Promise<any>;
28
+ private checkParameters;
29
+ private buildMissingParametersMessage;
30
+ private findMissingParameters;
31
+ abstract apply(req: Request, res: Response): Promise<any>;
32
+ }
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.APIRequest = exports.RequestContext = exports.RequestMethod = void 0;
13
+ const APIService_1 = require("./APIService");
14
+ var RequestMethod;
15
+ (function (RequestMethod) {
16
+ RequestMethod["GET"] = "GET";
17
+ RequestMethod["POST"] = "POST";
18
+ RequestMethod["PUT"] = "PUT";
19
+ RequestMethod["DELETE"] = "DELETE";
20
+ })(RequestMethod = exports.RequestMethod || (exports.RequestMethod = {}));
21
+ var RequestContext;
22
+ (function (RequestContext) {
23
+ RequestContext["BODY"] = "body";
24
+ RequestContext["PARAMS"] = "params";
25
+ RequestContext["QUERY"] = "query";
26
+ })(RequestContext = exports.RequestContext || (exports.RequestContext = {}));
27
+ class APIRequest {
28
+ constructor(method, config) {
29
+ this.method = method;
30
+ this.path = config.path;
31
+ this.params = config.params;
32
+ }
33
+ process(req, res) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ let request = APIService_1.ITRMAPIServiceGlobal.requests[req.method + "_" + req.route.path];
36
+ let check = request.checkParameters(req, request);
37
+ for (let key of Object.keys(check))
38
+ if (check[key].status !== 'OK')
39
+ return yield res.status(400).json(check[key]);
40
+ return yield request.apply(req, res);
41
+ });
42
+ }
43
+ checkParameters(req, request) {
44
+ let result = {};
45
+ for (let group of request.params) {
46
+ let missing = request.findMissingParameters(req[group.context], group.properties);
47
+ if (missing.length > 0)
48
+ result[group.context] = result[group.context] ? result[group.context] : { status: 'Error', message: request.buildMissingParametersMessage(group.context, missing) };
49
+ else
50
+ result[group.context] = { status: 'OK' };
51
+ }
52
+ return result;
53
+ }
54
+ buildMissingParametersMessage(context, missing) {
55
+ let message = "Parameters";
56
+ for (let i = 0; i < missing.length; i++)
57
+ message += (i > 0 ? ", " : " ") + "'" + missing[i] + "'";
58
+ message += " where not found in " + context;
59
+ return message;
60
+ }
61
+ findMissingParameters(context, properties) {
62
+ let missing = [];
63
+ for (let property of properties)
64
+ if (!context.hasOwnProperty(property))
65
+ missing.push(property);
66
+ return missing;
67
+ }
68
+ }
69
+ exports.APIRequest = APIRequest;
70
+ //# sourceMappingURL=APIRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"APIRequest.js","sourceRoot":"","sources":["../../src/api/APIRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAAoD;AAEpD,IAAY,aAKX;AALD,WAAY,aAAa;IACrB,4BAAW,CAAA;IACX,8BAAa,CAAA;IACb,4BAAW,CAAA;IACX,kCAAiB,CAAA;AACrB,CAAC,EALW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAKxB;AAED,IAAY,cAIX;AAJD,WAAY,cAAc;IACtB,+BAAa,CAAA;IACb,mCAAiB,CAAA;IACjB,iCAAe,CAAA;AACnB,CAAC,EAJW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAIzB;AAYD,MAAsB,UAAU;IAK5B,YAAY,MAAqB,EAAE,MAAwB;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,CAAC;IAIY,OAAO,CAAC,GAAY,EAAE,GAAa;;YAC5C,IAAI,OAAO,GAAe,iCAAoB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3F,IAAI,KAAK,GAAQ,OAAO,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACvD,KAAK,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC9B,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,MAA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,CAAC;QAC7D,OAAO,IAAI,sBAAsB,GAAG,OAAO,CAAC;QAC5C,OAAO,OAAO,CAAC;IACnB,CAAC;IAEO,qBAAqB,CAAC,OAAY,EAAE,UAAoB;QAC5D,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,KAAK,IAAI,QAAQ,IAAI,UAAU;YAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC;gBACjC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC;IACnB,CAAC;CAGJ;AAnDD,gCAmDC"}
@@ -0,0 +1,26 @@
1
+ import { Express } from 'express';
2
+ import { APIRequest } from './APIRequest';
3
+ export declare namespace ITRMAPIServiceGlobal {
4
+ var memory: any;
5
+ var service: APIService | undefined;
6
+ var requests: any;
7
+ }
8
+ export interface APIServiceConfig {
9
+ name: string;
10
+ port: string | number;
11
+ }
12
+ export interface APIServiceResponse {
13
+ status: string;
14
+ message: string;
15
+ error?: any;
16
+ }
17
+ export declare class APIService {
18
+ protected config: APIServiceConfig;
19
+ protected server: any;
20
+ protected app: Express;
21
+ constructor(config: APIServiceConfig);
22
+ init(): void;
23
+ addRequest(request: APIRequest): Promise<void>;
24
+ run(init: Function): Promise<APIServiceResponse>;
25
+ close(finish: Function): Promise<APIServiceResponse>;
26
+ }
@@ -0,0 +1,91 @@
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
+ exports.APIService = exports.ITRMAPIServiceGlobal = void 0;
16
+ const express_1 = __importDefault(require("express"));
17
+ var ITRMAPIServiceGlobal;
18
+ (function (ITRMAPIServiceGlobal) {
19
+ ITRMAPIServiceGlobal.memory = {};
20
+ ITRMAPIServiceGlobal.service = undefined;
21
+ ITRMAPIServiceGlobal.requests = {};
22
+ })(ITRMAPIServiceGlobal = exports.ITRMAPIServiceGlobal || (exports.ITRMAPIServiceGlobal = {}));
23
+ class APIService {
24
+ constructor(config) {
25
+ this.server = undefined;
26
+ this.app = (0, express_1.default)();
27
+ this.config = config;
28
+ this.init();
29
+ }
30
+ init() {
31
+ ITRMAPIServiceGlobal.service = this;
32
+ this.app.use(express_1.default.json());
33
+ this.app.get('/', (req, res) => {
34
+ return res.send('Server working!');
35
+ });
36
+ }
37
+ addRequest(request) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ ITRMAPIServiceGlobal.requests[request.method + "_" + request.path] = request;
40
+ yield request.init(this.app);
41
+ });
42
+ }
43
+ run(init) {
44
+ return new Promise((resolve, reject) => {
45
+ this.server = this.app.listen(this.config.port, () => __awaiter(this, void 0, void 0, function* () {
46
+ console.log(`⚡️[server]: Server is running at http://localhost:${this.config.port}`);
47
+ try {
48
+ yield init();
49
+ resolve({ status: 'Ok', message: 'Server has been Initialized' });
50
+ }
51
+ catch (err) {
52
+ reject({
53
+ status: 'Error',
54
+ message: 'An error has ocurred in the initialization function',
55
+ error: err
56
+ });
57
+ }
58
+ }));
59
+ });
60
+ }
61
+ close(finish) {
62
+ return new Promise((resolve, reject) => {
63
+ this.server.close((err) => __awaiter(this, void 0, void 0, function* () {
64
+ console.log("> closing server");
65
+ if (err)
66
+ reject({
67
+ status: 'Error',
68
+ message: 'An error has ocurred when closing Server',
69
+ error: err
70
+ });
71
+ try {
72
+ yield finish();
73
+ resolve({
74
+ status: 'Ok',
75
+ message: 'Server has been closed'
76
+ });
77
+ }
78
+ catch (err) {
79
+ reject({
80
+ status: 'Error',
81
+ message: 'An error has ocurred in the closing function',
82
+ error: err
83
+ });
84
+ }
85
+ console.log("> Server closed");
86
+ }));
87
+ });
88
+ }
89
+ }
90
+ exports.APIService = APIService;
91
+ //# sourceMappingURL=APIService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"APIService.js","sourceRoot":"","sources":["../../src/api/APIService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8D;AAG9D,IAAiB,oBAAoB,CAIpC;AAJD,WAAiB,oBAAoB;IACtB,2BAAM,GAAQ,EAAE,CAAC;IACjB,4BAAO,GAA2B,SAAS,CAAC;IAC5C,6BAAQ,GAAQ,EAAE,CAAC;AAClC,CAAC,EAJgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAIpC;AAaD,MAAa,UAAU;IAKnB,YAAY,MAAwB;QAH1B,WAAM,GAAQ,SAAS,CAAC;QACxB,QAAG,GAAY,IAAA,iBAAO,GAAE,CAAC;QAG/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAEM,IAAI;QACP,oBAAoB,CAAC,OAAO,GAAG,IAAI,CAAC;QACpC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;YAC9C,OAAO,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACP,CAAC;IAEY,UAAU,CAAC,OAAmB;;YACvC,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;Y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BACd,MAAM,CAAC;wBACH,MAAM,EAAE,OAAO;wBACf,OAAO,EAAE,8CAA8C;wBACvD,KAAK,EAAE,GAAG;qBACb,CAAC,CAAC;iBACN;gBACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACnC,CAAC,CAAA,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AApED,gCAoEC"}
@@ -0,0 +1,6 @@
1
+ import { Express } from "express";
2
+ import { APIRequest, APIRequestConfig } from "../APIRequest";
3
+ export declare abstract class DeleteRequest extends APIRequest {
4
+ constructor(config: APIRequestConfig);
5
+ init(app: Express): Promise<void>;
6
+ }
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeleteRequest = void 0;
13
+ const APIRequest_1 = require("../APIRequest");
14
+ class DeleteRequest extends APIRequest_1.APIRequest {
15
+ constructor(config) {
16
+ super(APIRequest_1.RequestMethod.DELETE, config);
17
+ }
18
+ init(app) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ app.delete(this.path, this.process);
21
+ });
22
+ }
23
+ }
24
+ exports.DeleteRequest = DeleteRequest;
25
+ //# sourceMappingURL=DeleteRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeleteRequest.js","sourceRoot":"","sources":["../../../src/api/request/DeleteRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAA4E;AAE5E,MAAsB,aAAc,SAAQ,uBAAU;IAClD,YAAY,MAAwB;QAChC,KAAK,CAAC,0BAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAEY,IAAI,CAAC,GAAY;;YAC1B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;KAAA;CACJ;AARD,sCAQC"}
@@ -0,0 +1,6 @@
1
+ import { Express } from "express";
2
+ import { APIRequest, APIRequestConfig } from "../APIRequest";
3
+ export declare abstract class GetRequest extends APIRequest {
4
+ constructor(config: APIRequestConfig);
5
+ init(app: Express): Promise<void>;
6
+ }
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GetRequest = void 0;
13
+ const APIRequest_1 = require("../APIRequest");
14
+ class GetRequest extends APIRequest_1.APIRequest {
15
+ constructor(config) {
16
+ super(APIRequest_1.RequestMethod.GET, config);
17
+ }
18
+ init(app) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ app.get(this.path, this.process);
21
+ });
22
+ }
23
+ }
24
+ exports.GetRequest = GetRequest;
25
+ //# sourceMappingURL=GetRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GetRequest.js","sourceRoot":"","sources":["../../../src/api/request/GetRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAA4E;AAE5E,MAAsB,UAAW,SAAQ,uBAAU;IAC/C,YAAY,MAAwB;QAChC,KAAK,CAAC,0BAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAEY,IAAI,CAAC,GAAY;;YAC1B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;KAAA;CACJ;AARD,gCAQC"}
@@ -0,0 +1,6 @@
1
+ import { Express } from "express";
2
+ import { APIRequest, APIRequestConfig } from "../APIRequest";
3
+ export declare abstract class PostRequest extends APIRequest {
4
+ constructor(config: APIRequestConfig);
5
+ init(app: Express): Promise<void>;
6
+ }
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PostRequest = void 0;
13
+ const APIRequest_1 = require("../APIRequest");
14
+ class PostRequest extends APIRequest_1.APIRequest {
15
+ constructor(config) {
16
+ super(APIRequest_1.RequestMethod.POST, config);
17
+ }
18
+ init(app) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ app.post(this.path, this.process);
21
+ });
22
+ }
23
+ }
24
+ exports.PostRequest = PostRequest;
25
+ //# sourceMappingURL=PostRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostRequest.js","sourceRoot":"","sources":["../../../src/api/request/PostRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAA4E;AAE5E,MAAsB,WAAY,SAAQ,uBAAU;IAChD,YAAY,MAAwB;QAChC,KAAK,CAAC,0BAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAEY,IAAI,CAAC,GAAY;;YAC1B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;KAAA;CACJ;AARD,kCAQC"}
@@ -0,0 +1,6 @@
1
+ import { Express } from "express";
2
+ import { APIRequest, APIRequestConfig } from "../APIRequest";
3
+ export declare abstract class PutRequest extends APIRequest {
4
+ constructor(config: APIRequestConfig);
5
+ init(app: Express): Promise<void>;
6
+ }
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PutRequest = void 0;
13
+ const APIRequest_1 = require("../APIRequest");
14
+ class PutRequest extends APIRequest_1.APIRequest {
15
+ constructor(config) {
16
+ super(APIRequest_1.RequestMethod.PUT, config);
17
+ }
18
+ init(app) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ app.put(this.path, this.process);
21
+ });
22
+ }
23
+ }
24
+ exports.PutRequest = PutRequest;
25
+ //# sourceMappingURL=PutRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PutRequest.js","sourceRoot":"","sources":["../../../src/api/request/PutRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAA4E;AAE5E,MAAsB,UAAW,SAAQ,uBAAU;IAC/C,YAAY,MAAwB;QAChC,KAAK,CAAC,0BAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAEY,IAAI,CAAC,GAAY;;YAC1B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;KAAA;CACJ;AARD,gCAQC"}
@@ -0,0 +1,7 @@
1
+ export { APIChecker as APIChecker } from './api/APIChecker';
2
+ export { APIRequest as APIRequest, RequestMethod as RequestMethod, RequestContext as RequestContext, GroupedParameters as GroupedParameters, APIRequestConfig as APIRequestConfig } from './api/APIRequest';
3
+ export { APIServiceConfig as APIServiceConfig, APIService as APIService, APIServiceResponse as APIServiceResponse } from './api/APIService';
4
+ export { GetRequest as GetRequest } from './api/request/GetRequest';
5
+ export { PostRequest as PostRequest } from './api/request/PostRequest';
6
+ export { PutRequest as PutRequest } from './api/request/PutRequest';
7
+ export { DeleteRequest as DeleteRequest } from './api/request/DeleteRequest';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeleteRequest = exports.PutRequest = exports.PostRequest = exports.GetRequest = exports.APIService = exports.RequestContext = exports.RequestMethod = exports.APIRequest = void 0;
4
+ var APIRequest_1 = require("./api/APIRequest");
5
+ Object.defineProperty(exports, "APIRequest", { enumerable: true, get: function () { return APIRequest_1.APIRequest; } });
6
+ Object.defineProperty(exports, "RequestMethod", { enumerable: true, get: function () { return APIRequest_1.RequestMethod; } });
7
+ Object.defineProperty(exports, "RequestContext", { enumerable: true, get: function () { return APIRequest_1.RequestContext; } });
8
+ var APIService_1 = require("./api/APIService");
9
+ Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
10
+ var GetRequest_1 = require("./api/request/GetRequest");
11
+ Object.defineProperty(exports, "GetRequest", { enumerable: true, get: function () { return GetRequest_1.GetRequest; } });
12
+ var PostRequest_1 = require("./api/request/PostRequest");
13
+ Object.defineProperty(exports, "PostRequest", { enumerable: true, get: function () { return PostRequest_1.PostRequest; } });
14
+ var PutRequest_1 = require("./api/request/PutRequest");
15
+ Object.defineProperty(exports, "PutRequest", { enumerable: true, get: function () { return PutRequest_1.PutRequest; } });
16
+ var DeleteRequest_1 = require("./api/request/DeleteRequest");
17
+ Object.defineProperty(exports, "DeleteRequest", { enumerable: true, get: function () { return DeleteRequest_1.DeleteRequest; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,+CAA4M;AAAnM,wGAAA,UAAU,OAAc;AAAE,2GAAA,aAAa,OAAiB;AAAE,4GAAA,cAAc,OAAkB;AACnG,+CAA4I;AAA7F,wGAAA,UAAU,OAAc;AACvE,uDAAoE;AAA3D,wGAAA,UAAU,OAAc;AACjC,yDAAuE;AAA9D,0GAAA,WAAW,OAAe;AACnC,uDAAoE;AAA3D,wGAAA,UAAU,OAAc;AACjC,6DAA6E;AAApE,8GAAA,aAAa,OAAiB"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "itrm-tools",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "rimraf ./dist && tsc --skipLibCheck",
12
+ "publish-lib": "npm run build && npm publish",
13
+ "publish-beta": "npm run build && npm publish --tag beta",
14
+ "publish-dryrun": "npm run build && npm publish --dry-run",
15
+ "link": "npm run build && npm link",
16
+ "test": "npm run build && jest"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/itrm-team/itrm-tools.git"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "bugs": {
26
+ "url": "https://github.com/itrm-team/itrm-tools/issues"
27
+ },
28
+ "homepage": "https://github.com/itrm-team/itrm-tools#readme",
29
+ "devDependencies": {
30
+ "@types/jest": "^29.2.5",
31
+ "jest": "^29.3.1",
32
+ "ts-jest": "^29.0.3"
33
+ },
34
+ "dependencies": {
35
+ "@types/express": "^4.17.15",
36
+ "@types/node": "^18.11.18",
37
+ "axios": "^1.2.2",
38
+ "cors": "^2.8.5",
39
+ "express": "^4.18.2",
40
+ "rimraf": "^3.0.2",
41
+ "typescript": "^4.9.4"
42
+ }
43
+ }