UNPKG

@hubspot/api-client

Version:

NodeJS v3 [HubSpot API](https://developers.hubspot.com/docs/api/overview) SDK(Client) files

347 lines 15.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectSerializer = void 0; __exportStar(require("../models/ActionConfirmationBody"), exports); __exportStar(require("../models/ActionHookActionBody"), exports); __exportStar(require("../models/CardActions"), exports); __exportStar(require("../models/CardAuditResponse"), exports); __exportStar(require("../models/CardCreateRequest"), exports); __exportStar(require("../models/CardDisplayBody"), exports); __exportStar(require("../models/CardDisplayProperty"), exports); __exportStar(require("../models/CardFetchBody"), exports); __exportStar(require("../models/CardFetchBodyPatch"), exports); __exportStar(require("../models/CardObjectTypeBody"), exports); __exportStar(require("../models/CardPatchRequest"), exports); __exportStar(require("../models/DisplayOption"), exports); __exportStar(require("../models/ErrorDetail"), exports); __exportStar(require("../models/IFrameActionBody"), exports); __exportStar(require("../models/IntegratorCardPayloadResponse"), exports); __exportStar(require("../models/IntegratorObjectResult"), exports); __exportStar(require("../models/IntegratorObjectResultActionsInner"), exports); __exportStar(require("../models/ModelError"), exports); __exportStar(require("../models/ObjectToken"), exports); __exportStar(require("../models/PublicCardFetchBody"), exports); __exportStar(require("../models/PublicCardListResponse"), exports); __exportStar(require("../models/PublicCardResponse"), exports); __exportStar(require("../models/TopLevelActions"), exports); const ActionConfirmationBody_1 = require("../models/ActionConfirmationBody"); const ActionHookActionBody_1 = require("../models/ActionHookActionBody"); const CardActions_1 = require("../models/CardActions"); const CardAuditResponse_1 = require("../models/CardAuditResponse"); const CardCreateRequest_1 = require("../models/CardCreateRequest"); const CardDisplayBody_1 = require("../models/CardDisplayBody"); const CardDisplayProperty_1 = require("../models/CardDisplayProperty"); const CardFetchBody_1 = require("../models/CardFetchBody"); const CardFetchBodyPatch_1 = require("../models/CardFetchBodyPatch"); const CardObjectTypeBody_1 = require("../models/CardObjectTypeBody"); const CardPatchRequest_1 = require("../models/CardPatchRequest"); const DisplayOption_1 = require("../models/DisplayOption"); const ErrorDetail_1 = require("../models/ErrorDetail"); const IFrameActionBody_1 = require("../models/IFrameActionBody"); const IntegratorCardPayloadResponse_1 = require("../models/IntegratorCardPayloadResponse"); const IntegratorObjectResult_1 = require("../models/IntegratorObjectResult"); const IntegratorObjectResultActionsInner_1 = require("../models/IntegratorObjectResultActionsInner"); const ModelError_1 = require("../models/ModelError"); const ObjectToken_1 = require("../models/ObjectToken"); const PublicCardFetchBody_1 = require("../models/PublicCardFetchBody"); const PublicCardListResponse_1 = require("../models/PublicCardListResponse"); const PublicCardResponse_1 = require("../models/PublicCardResponse"); const TopLevelActions_1 = require("../models/TopLevelActions"); let primitives = [ "string", "boolean", "double", "integer", "long", "float", "number", "any" ]; let enumsMap = new Set([ "ActionHookActionBodyTypeEnum", "ActionHookActionBodyHttpMethodEnum", "CardAuditResponseActionTypeEnum", "CardAuditResponseAuthSourceEnum", "CardDisplayPropertyDataTypeEnum", "CardFetchBodyCardTypeEnum", "CardFetchBodyPatchCardTypeEnum", "CardObjectTypeBodyNameEnum", "DisplayOptionTypeEnum", "IFrameActionBodyTypeEnum", "IntegratorCardPayloadResponseResponseVersionEnum", "IntegratorObjectResultActionsInnerTypeEnum", "IntegratorObjectResultActionsInnerHttpMethodEnum", "ObjectTokenDataTypeEnum", ]); let typeMap = { "ActionConfirmationBody": ActionConfirmationBody_1.ActionConfirmationBody, "ActionHookActionBody": ActionHookActionBody_1.ActionHookActionBody, "CardActions": CardActions_1.CardActions, "CardAuditResponse": CardAuditResponse_1.CardAuditResponse, "CardCreateRequest": CardCreateRequest_1.CardCreateRequest, "CardDisplayBody": CardDisplayBody_1.CardDisplayBody, "CardDisplayProperty": CardDisplayProperty_1.CardDisplayProperty, "CardFetchBody": CardFetchBody_1.CardFetchBody, "CardFetchBodyPatch": CardFetchBodyPatch_1.CardFetchBodyPatch, "CardObjectTypeBody": CardObjectTypeBody_1.CardObjectTypeBody, "CardPatchRequest": CardPatchRequest_1.CardPatchRequest, "DisplayOption": DisplayOption_1.DisplayOption, "ErrorDetail": ErrorDetail_1.ErrorDetail, "IFrameActionBody": IFrameActionBody_1.IFrameActionBody, "IntegratorCardPayloadResponse": IntegratorCardPayloadResponse_1.IntegratorCardPayloadResponse, "IntegratorObjectResult": IntegratorObjectResult_1.IntegratorObjectResult, "IntegratorObjectResultActionsInner": IntegratorObjectResultActionsInner_1.IntegratorObjectResultActionsInnerClass, "ModelError": ModelError_1.ModelError, "ObjectToken": ObjectToken_1.ObjectToken, "PublicCardFetchBody": PublicCardFetchBody_1.PublicCardFetchBody, "PublicCardListResponse": PublicCardListResponse_1.PublicCardListResponse, "PublicCardResponse": PublicCardResponse_1.PublicCardResponse, "TopLevelActions": TopLevelActions_1.TopLevelActions, }; const parseMimeType = (mimeType) => { const [type = '', subtype = ''] = mimeType.split('/'); return { type, subtype, subtypeTokens: subtype.split('+'), }; }; const mimeTypePredicateFactory = (predicate) => (mimeType) => predicate(parseMimeType(mimeType)); const mimeTypeSimplePredicateFactory = (type, subtype) => mimeTypePredicateFactory((descriptor) => { if (descriptor.type !== type) return false; if (subtype != null && descriptor.subtype !== subtype) return false; return true; }); const isTextLikeMimeType = mimeTypeSimplePredicateFactory('text'); const isJsonMimeType = mimeTypeSimplePredicateFactory('application', 'json'); const isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === 'application' && descriptor.subtypeTokens.some((item) => item === 'json')); const isOctetStreamMimeType = mimeTypeSimplePredicateFactory('application', 'octet-stream'); const isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory('application', 'x-www-form-urlencoded'); const supportedMimeTypePredicatesWithPriority = [ isJsonMimeType, isJsonLikeMimeType, isTextLikeMimeType, isOctetStreamMimeType, isFormUrlencodedMimeType, ]; const nullableSuffix = " | null"; const optionalSuffix = " | undefined"; const arrayPrefix = "Array<"; const arraySuffix = ">"; const mapPrefix = "{ [key: string]: "; const mapSuffix = "; }"; class ObjectSerializer { static findCorrectType(data, expectedType) { if (data == undefined) { return expectedType; } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { return expectedType; } else if (expectedType === "Date") { return expectedType; } else { if (enumsMap.has(expectedType)) { return expectedType; } if (!typeMap[expectedType]) { return expectedType; } let discriminatorProperty = typeMap[expectedType].discriminator; if (discriminatorProperty == null) { return expectedType; } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; let mapping = typeMap[expectedType].mapping; if (mapping != undefined && mapping[discriminatorType]) { return mapping[discriminatorType]; } else if (typeMap[discriminatorType]) { return discriminatorType; } else { return expectedType; } } else { return expectedType; } } } } static serialize(data, type, format) { if (data == undefined) { return data; } else if (primitives.indexOf(type.toLowerCase()) !== -1) { return data; } else if (type.endsWith(nullableSuffix)) { let subType = type.slice(0, -nullableSuffix.length); return ObjectSerializer.serialize(data, subType, format); } else if (type.endsWith(optionalSuffix)) { let subType = type.slice(0, -optionalSuffix.length); return ObjectSerializer.serialize(data, subType, format); } else if (type.startsWith(arrayPrefix)) { let subType = type.slice(arrayPrefix.length, -arraySuffix.length); let transformedData = []; for (let date of data) { transformedData.push(ObjectSerializer.serialize(date, subType, format)); } return transformedData; } else if (type.startsWith(mapPrefix)) { let subType = type.slice(mapPrefix.length, -mapSuffix.length); let transformedData = {}; for (let key in data) { transformedData[key] = ObjectSerializer.serialize(data[key], subType, format); } return transformedData; } else if (type === "Date") { if (format == "date") { let month = data.getMonth() + 1; month = month < 10 ? "0" + month.toString() : month.toString(); let day = data.getDate(); day = day < 10 ? "0" + day.toString() : day.toString(); return data.getFullYear() + "-" + month + "-" + day; } else { return data.toISOString(); } } else { if (enumsMap.has(type)) { return data; } if (!typeMap[type]) { return data; } type = this.findCorrectType(data, type); let attributeTypes = typeMap[type].getAttributeTypeMap(); let instance = {}; for (let attributeType of attributeTypes) { instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format); } return instance; } } static deserialize(data, type, format) { type = ObjectSerializer.findCorrectType(data, type); if (data == undefined) { return data; } else if (primitives.indexOf(type.toLowerCase()) !== -1) { return data; } else if (type.endsWith(nullableSuffix)) { let subType = type.slice(0, -nullableSuffix.length); return ObjectSerializer.deserialize(data, subType, format); } else if (type.endsWith(optionalSuffix)) { let subType = type.slice(0, -optionalSuffix.length); return ObjectSerializer.deserialize(data, subType, format); } else if (type.startsWith(arrayPrefix)) { let subType = type.slice(arrayPrefix.length, -arraySuffix.length); let transformedData = []; for (let date of data) { transformedData.push(ObjectSerializer.deserialize(date, subType, format)); } return transformedData; } else if (type.startsWith(mapPrefix)) { let subType = type.slice(mapPrefix.length, -mapSuffix.length); let transformedData = {}; for (let key in data) { transformedData[key] = ObjectSerializer.deserialize(data[key], subType, format); } return transformedData; } else if (type === "Date") { return new Date(data); } else { if (enumsMap.has(type)) { return data; } if (!typeMap[type]) { return data; } let instance = new typeMap[type](); let attributeTypes = typeMap[type].getAttributeTypeMap(); for (let attributeType of attributeTypes) { let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format); if (value !== undefined) { instance[attributeType.name] = value; } } return instance; } } static normalizeMediaType(mediaType) { var _a; if (mediaType === undefined) { return undefined; } return ((_a = mediaType.split(";")[0]) !== null && _a !== void 0 ? _a : '').trim().toLowerCase(); } static getPreferredMediaType(mediaTypes) { if (mediaTypes.length === 0) { return "application/json"; } const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { if (mediaType != null && predicate(mediaType)) { return mediaType; } } } throw new Error("None of the given media types are supported: " + mediaTypes.join(", ")); } static stringify(data, mediaType) { if (isTextLikeMimeType(mediaType)) { return String(data); } if (isJsonLikeMimeType(mediaType)) { return JSON.stringify(data); } throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify."); } static parse(rawData, mediaType) { if (mediaType === undefined) { throw new Error("Cannot parse content. No Content-Type defined."); } if (isTextLikeMimeType(mediaType)) { return rawData; } if (isJsonLikeMimeType(mediaType)) { return JSON.parse(rawData); } throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse."); } } exports.ObjectSerializer = ObjectSerializer; //# sourceMappingURL=ObjectSerializer.js.map