UNPKG

@planet-a/affinity-node

Version:
237 lines (236 loc) 15.4 kB
// TODO: better import syntax? import { BaseAPIRequestFactory, RequiredError } from './baseapi.js'; import { HttpMethod, HttpInfo } from '../http/http.js'; import { ObjectSerializer } from '../models/ObjectSerializer.js'; import { ApiException } from './exception.js'; import { isCodeInRange } from '../util.js'; /** * no description */ export class OpportunitiesApiRequestFactory extends BaseAPIRequestFactory { /** * Paginate through Opportunities in Affinity. Returns basic information but **not** field data on each Opportunity. To access field data on Opportunities, use the `/lists/{list_id}/list-entries` or the `/v2/lists/{list_id}/saved-views/{view_id}/list-entries` GET endpoint. Requires the \"Export data from Lists\" [permission](#section/Getting-Started/Permissions). * Get all Opportunities * @param cursor Cursor for the next or previous page * @param limit Number of items to include in the page * @param ids Opportunity IDs */ async v2OpportunitiesGET(cursor, limit, ids, _options) { let _config = _options || this.configuration; // Path Params const localVarPath = '/v2/opportunities'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8"); // Query Params if (cursor !== undefined) { requestContext.setQueryParam("cursor", ObjectSerializer.serialize(cursor, "string", "")); } // Query Params if (limit !== undefined) { requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", "int32")); } // Query Params if (ids !== undefined) { const serializedParams = ObjectSerializer.serialize(ids, "Array<number>", "int64"); for (const serializedParam of serializedParams) { requestContext.appendQueryParam("ids", serializedParam); } } let authMethod; // Apply auth methods authMethod = _config.authMethods["bearerAuth"]; if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth = _config?.authMethods?.default; if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Returns basic information but **not** field data on the requested Opportunity. To access field data on Opportunities, use the `/lists/{list_id}/list-entries` or the `/v2/lists/{list_id}/saved-views/{view_id}/list-entries` GET endpoint. Requires the \"Export data from Lists\" [permission](#section/Getting-Started/Permissions). * Get a single Opportunity * @param opportunityId Opportunity ID */ async v2OpportunitiesOpportunityIdGET(opportunityId, _options) { let _config = _options || this.configuration; // verify required parameter 'opportunityId' is not null or undefined if (opportunityId === null || opportunityId === undefined) { throw new RequiredError("OpportunitiesApi", "v2OpportunitiesOpportunityIdGET", "opportunityId"); } // Path Params const localVarPath = '/v2/opportunities/{opportunityId}' .replace('{' + 'opportunityId' + '}', encodeURIComponent(String(opportunityId))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8"); let authMethod; // Apply auth methods authMethod = _config.authMethods["bearerAuth"]; if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth = _config?.authMethods?.default; if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * | ⚠️ This endpoint is currently in BETA | |--| Returns Notes for a given Opportunity which includes directly attached notes and those attached to persons on this Opportunity. You can filter notes using the `filter` query parameter. The filter parameter is a string that you can specify conditions based on the following properties. | **Property Name** | **Description** | **Type** | **Allowed Operators** | **Examples** | |-----------------------------|-----------------------------------------------------------------|------------|--------------------------------------|---------------------------------| | `creator.id` | Filter notes by the creator of the note | `int32` | `=` | `creator.id=1` | | `createdAt` | Filter notes by when it was created | `datetime` | `>`, `<`, `>=`, `<=` | `createdAt<2025-02-04T10:48:24Z` | | `updatedAt` | Filter notes by when it was updated | `datetime` | `>`, `<`, `>=`, `<=` | `updatedAt>=2025-02-03T10:48:24Z`| * Get Notes for an Opportunity * @param opportunityId Opportunity ID * @param filter Filter options * @param cursor Cursor for the next or previous page * @param limit Number of items to include in the page * @param totalCount Include total count of the collection in the pagination response */ async v2OpportunitiesOpportunityIdNotesGET(opportunityId, filter, cursor, limit, totalCount, _options) { let _config = _options || this.configuration; // verify required parameter 'opportunityId' is not null or undefined if (opportunityId === null || opportunityId === undefined) { throw new RequiredError("OpportunitiesApi", "v2OpportunitiesOpportunityIdNotesGET", "opportunityId"); } // Path Params const localVarPath = '/v2/opportunities/{opportunityId}/notes' .replace('{' + 'opportunityId' + '}', encodeURIComponent(String(opportunityId))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8"); // Query Params if (filter !== undefined) { requestContext.setQueryParam("filter", ObjectSerializer.serialize(filter, "string", "")); } // Query Params if (cursor !== undefined) { requestContext.setQueryParam("cursor", ObjectSerializer.serialize(cursor, "string", "")); } // Query Params if (limit !== undefined) { requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", "int32")); } // Query Params if (totalCount !== undefined) { requestContext.setQueryParam("totalCount", ObjectSerializer.serialize(totalCount, "boolean", "")); } let authMethod; // Apply auth methods authMethod = _config.authMethods["bearerAuth"]; if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth = _config?.authMethods?.default; if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class OpportunitiesApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to v2OpportunitiesGET * @throws ApiException if the response code was not in [200, 299] */ async v2OpportunitiesGETWithHttpInfo(response) { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "OpportunityPaged", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Responses400", ""); throw new ApiException(response.httpStatusCode, "Bad Request", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "AuthorizationErrors", ""); throw new ApiException(response.httpStatusCode, "Forbidden", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotFoundErrors", ""); throw new ApiException(response.httpStatusCode, "Not Found", body, response.headers); } if (isCodeInRange("0", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Errors", ""); throw new ApiException(response.httpStatusCode, "Errors", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "OpportunityPaged", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to v2OpportunitiesOpportunityIdGET * @throws ApiException if the response code was not in [200, 299] */ async v2OpportunitiesOpportunityIdGETWithHttpInfo(response) { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Opportunity", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Responses400", ""); throw new ApiException(response.httpStatusCode, "Bad Request", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "AuthorizationErrors", ""); throw new ApiException(response.httpStatusCode, "Forbidden", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotFoundErrors", ""); throw new ApiException(response.httpStatusCode, "Not Found", body, response.headers); } if (isCodeInRange("0", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Errors", ""); throw new ApiException(response.httpStatusCode, "Errors", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Opportunity", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to v2OpportunitiesOpportunityIdNotesGET * @throws ApiException if the response code was not in [200, 299] */ async v2OpportunitiesOpportunityIdNotesGETWithHttpInfo(response) { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotesNotesPaged", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Responses400", ""); throw new ApiException(response.httpStatusCode, "Bad Request", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotFoundErrors", ""); throw new ApiException(response.httpStatusCode, "Not Found", body, response.headers); } if (isCodeInRange("0", response.httpStatusCode)) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Errors", ""); throw new ApiException(response.httpStatusCode, "Errors", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotesNotesPaged", ""); return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }