UNPKG

@kwiz/common

Version:

KWIZ common utilities and helpers for M365 platform

65 lines 2.83 kB
import { objectValues } from "./objects"; import { isNullOrUndefined } from "./typecheckers"; // eslint-disable-next-line no-shadow export var CommonHttpHeaderNames; (function (CommonHttpHeaderNames) { CommonHttpHeaderNames["Accept"] = "Accept"; CommonHttpHeaderNames["Authorization"] = "Authorization"; CommonHttpHeaderNames["ContentType"] = "content-type"; CommonHttpHeaderNames["XHTTPMethod"] = "X-HTTP-Method"; CommonHttpHeaderNames["XRapidApiHost"] = "x-rapidapi-host"; CommonHttpHeaderNames["XRapidApiKey"] = "x-rapidapi-key"; })(CommonHttpHeaderNames || (CommonHttpHeaderNames = {})); // eslint-disable-next-line no-shadow var AcceptOrContentTypeHeaderValues; (function (AcceptOrContentTypeHeaderValues) { AcceptOrContentTypeHeaderValues["JsonVerbose"] = "application/json; odata=verbose"; AcceptOrContentTypeHeaderValues["JsonMinimal"] = "application/json; odata=minimal"; AcceptOrContentTypeHeaderValues["JsonNometadata"] = "application/json; odata=nometadata"; })(AcceptOrContentTypeHeaderValues || (AcceptOrContentTypeHeaderValues = {})); // eslint-disable-next-line no-shadow var AuthorizationHeaderValues; (function (AuthorizationHeaderValues) { AuthorizationHeaderValues["Bearer"] = "Bearer [token]"; AuthorizationHeaderValues["Basic"] = "Basic [user]:[password]"; })(AuthorizationHeaderValues || (AuthorizationHeaderValues = {})); // eslint-disable-next-line no-shadow var XHttpMethodHeaderValues; (function (XHttpMethodHeaderValues) { XHttpMethodHeaderValues["MERGE"] = "MERGE"; XHttpMethodHeaderValues["DELETE"] = "DELETE"; XHttpMethodHeaderValues["PUT"] = "PUT"; })(XHttpMethodHeaderValues || (XHttpMethodHeaderValues = {})); export function GetCommonHeaderNames() { return objectValues(CommonHttpHeaderNames); } export function GetCommonHeaderValueSuggestions(headerName) { if (isNullOrUndefined(headerName)) { return []; } let parsedHeaderName = _getValueByKeyForStringEnum(headerName); if (isNullOrUndefined(parsedHeaderName)) { return []; } switch (parsedHeaderName) { case CommonHttpHeaderNames.Accept: case CommonHttpHeaderNames.ContentType: return objectValues(AcceptOrContentTypeHeaderValues); case CommonHttpHeaderNames.Authorization: return objectValues(AuthorizationHeaderValues); case CommonHttpHeaderNames.XHTTPMethod: return objectValues(XHttpMethodHeaderValues); default: return []; } } function _getValueByKeyForStringEnum(keyOrValue) { let found = objectValues(CommonHttpHeaderNames).filter((value) => { return value === keyOrValue; })[0]; if (isNullOrUndefined(found)) { found = CommonHttpHeaderNames[keyOrValue]; } return found; } //# sourceMappingURL=http.js.map