UNPKG

outers

Version:

outers - a all in one package for your day to day use

144 lines 9.93 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _APiCall_Domain, _APiCall_ContentType; Object.defineProperty(exports, "__esModule", { value: true }); exports.APiCall = void 0; /* eslint-disable @typescript-eslint/no-explicit-any */ // Import API from internal module const Fetch_1 = require("./functions/Fetch"); // Import Fetch Module const node_os_1 = require("node:os"); // Import OS Module // Import Variables const Middleware_Constant_1 = require("../Config/Constant/Middleware.Constant"); // Import Middleware Constant Module // Create A Class for API /* The `APiCall` class is a TypeScript class that provides a method for making GET requests to a specified API endpoint and returning the response as JSON. */ class APiCall { constructor(Domain, ContentType = { "Content-Type": "application/json", "X-Powered-By": `${(0, Middleware_Constant_1.XPoweredBy)()}`, Accept: "application/json", Server: `${(0, Middleware_Constant_1.ServerName)()}`, "Access-Control-Allow-Origin": "*", "User-Agent": `${(0, node_os_1.platform)()} ${(0, node_os_1.arch)()} server`, }) { _APiCall_Domain.set(this, void 0); // The #Domain property is a private property that can only be accessed within the class. _APiCall_ContentType.set(this, void 0); // The #ContentType property is a private property that can only be accessed within the class. __classPrivateFieldSet(this, _APiCall_Domain, Domain, "f"); // Set Domain to the Domain passed in the constructor __classPrivateFieldSet(this, _APiCall_ContentType, ContentType, "f"); // Set ContentType to the ContentType passed in the constructor } // Function for GET requests /** * The Get function is an asynchronous function that makes a GET request to a specified path and * returns the response as JSON. * @param {string} path - The `path` parameter is a string that represents the endpoint or URL path * that you want to make a GET request to. It is typically used to specify the specific resource or * data you want to retrieve from the server. * @param [Responsejson=true] - The "Responsejson" parameter is a boolean flag that determines * whether the response from the API should be parsed as JSON or not. If set to true, the response * will be parsed as JSON. If set to false, the response will be returned as is without any parsing. * @param {any} headers - The `headers` parameter is an optional parameter that allows you to * specify custom headers for the HTTP request. In the code snippet you provided, the default value * for the `headers` parameter is set to `{'Content-Type': 'application/json'}`. This means that if * no custom headers are provided * @returns the result of the `GetFetch` function, which is being awaited. */ Get(path, Responsejson = true, headers = __classPrivateFieldGet(this, _APiCall_ContentType, "f")) { return __awaiter(this, void 0, void 0, function* () { return yield (0, Fetch_1.GetFetch)(`${__classPrivateFieldGet(this, _APiCall_Domain, "f")}${path}`, Responsejson, headers); }); } // Function for POST requests /** * The function is used for making POST requests with optional parameters for the path, data, * response format, and headers. * @param {string} path - The `path` parameter is a string that represents the endpoint or URL path * where the POST request will be sent to. It specifies the location on the server where the * request should be handled. * @param {any} Data - The "Data" parameter is used to pass the data that you want to send in the * request body. It can be of any type, but in this case, it is expected to be of type "any", which * means it can be any valid JavaScript object. * @param [Responsejson=true] - The `Responsejson` parameter is a boolean flag that determines * whether the response from the server should be parsed as JSON or not. If `Responsejson` is set * to `true`, the response will be parsed as JSON. If it is set to `false`, the response will be * returned as is * @param {any} headers - The `headers` parameter is an optional parameter that allows you to * specify additional headers for the POST request. By default, it is set to `{'Content-Type': * 'application/json'}` which sets the content type of the request to JSON. * @returns the result of the `PostFetch` function, which is awaited. */ Post(path, Data, Responsejson = true, headers = __classPrivateFieldGet(this, _APiCall_ContentType, "f")) { return __awaiter(this, void 0, void 0, function* () { // Function for POST requests return yield (0, Fetch_1.PostFetch)(`${__classPrivateFieldGet(this, _APiCall_Domain, "f")}${path}`, Data, Responsejson, headers); }); } // Function for DELETE requests /** * The function is used for making DELETE requests with optional parameters for response format and * headers. * @param {string} path - The path parameter is a string that represents the endpoint or resource * that you want to delete. It is appended to the domain to form the complete URL for the DELETE * request. * @param [Responsejson=true] - The Responsejson parameter is a boolean value that determines * whether the response from the DELETE request should be parsed as JSON. If set to true, the * response will be parsed as JSON. If set to false, the response will be returned as is without any * parsing. * @param {any} headers - The `headers` parameter is an optional parameter that allows you to * specify additional headers to include in the DELETE request. By default, it is set to * `{'Content-Type': 'application/json'}` which sets the content type of the request to JSON. * However, you can override this default value by * @returns the result of the `DeleteFetch` function, which is being awaited. */ Delete(path, Responsejson = true, headers = __classPrivateFieldGet(this, _APiCall_ContentType, "f")) { return __awaiter(this, void 0, void 0, function* () { // Function for DELETE requests return yield (0, Fetch_1.DeleteFetch)(`${__classPrivateFieldGet(this, _APiCall_Domain, "f")}${path}`, Responsejson, headers); }); } // Function for PUT requests /** * The function is used for making PUT requests with optional parameters for data, response format, and * headers. * @param {string} path - The path parameter is a string that represents the endpoint or URL path where * the PUT request will be sent to. It specifies the location of the resource that needs to be updated * or modified. * @param {any} Data - The `Data` parameter is the payload or data that you want to send in the request * body. It can be of any type, but in this case, it is of type `any`, which means it can be any * JavaScript object. * @param [Responsejson=true] - The `Responsejson` parameter is a boolean flag that determines whether * the response from the server should be parsed as JSON or not. If `Responsejson` is set to `true`, * the response will be parsed as JSON. If it is set to `false`, the response will be returned as is * @param {any} headers - The `headers` parameter is an optional parameter that allows you to specify * additional headers for the PUT request. By default, it is set to `{'Content-Type': * 'application/json'}` which sets the content type of the request to JSON. * @returns the result of the `PutFetch` function. */ Put(path, Data, Responsejson = true, headers = __classPrivateFieldGet(this, _APiCall_ContentType, "f")) { return __awaiter(this, void 0, void 0, function* () { // Function for PUT requests return yield (0, Fetch_1.PutFetch)(`${__classPrivateFieldGet(this, _APiCall_Domain, "f")}${path}`, Data, Responsejson, headers); }); } } exports.APiCall = APiCall; _APiCall_Domain = new WeakMap(), _APiCall_ContentType = new WeakMap(); //# sourceMappingURL=Dispatcher.js.map