intercom-client
Version:
Official Node bindings to the Intercom API
337 lines (336 loc) • 23.3 kB
JavaScript
// This file was auto-generated by Fern from our API Definition.
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 __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
import * as core from "../../../../core/index.mjs";
import * as environments from "../../../../environments.mjs";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
import * as errors from "../../../../errors/index.mjs";
import * as Intercom from "../../../index.mjs";
/**
* Everything about your Custom Object instances.
* {% admonition type="warning" name="Permission Requirements" %}
* From now on, to access this endpoint, you need additional permissions. Please head over to the [Developer Hub](https://app.intercom.com/a/apps/_/developer-hub) app package authentication settings to configure the required permissions.
* {% /admonition %}
*/
export class CustomObjectInstancesClient {
constructor(options = {}) {
this._options = normalizeClientOptionsWithAuth(options);
}
/**
* Fetch a Custom Object Instance by external_id.
*
* @param {Intercom.GetCustomObjectInstancesByExternalIdRequest} request
* @param {CustomObjectInstancesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.customObjectInstances.getCustomObjectInstancesByExternalId({
* custom_object_type_identifier: "Order",
* external_id: "external_id"
* })
*/
getCustomObjectInstancesByExternalId(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__getCustomObjectInstancesByExternalId(request, requestOptions));
}
__getCustomObjectInstancesByExternalId(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { custom_object_type_identifier: customObjectTypeIdentifier, external_id: externalId } = request;
const _queryParams = {};
_queryParams.external_id = externalId;
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, `custom_object_instances/${core.url.encodePathParam(customObjectTypeIdentifier)}`),
method: "GET",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/custom_object_instances/{custom_object_type_identifier}");
});
}
/**
* Create or update a custom object instance
*
* @param {Intercom.CreateOrUpdateCustomObjectInstanceRequest} request
* @param {CustomObjectInstancesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.customObjectInstances.createCustomObjectInstances({
* custom_object_type_identifier: "Order",
* external_id: "123",
* external_created_at: 1392036272,
* external_updated_at: 1392036272,
* custom_attributes: {
* "order_number": "ORDER-12345",
* "total_amount": "custom_attributes"
* }
* })
*/
createCustomObjectInstances(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__createCustomObjectInstances(request, requestOptions));
}
__createCustomObjectInstances(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { custom_object_type_identifier: customObjectTypeIdentifier } = request, _body = __rest(request, ["custom_object_type_identifier"]);
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, `custom_object_instances/${core.url.encodePathParam(customObjectTypeIdentifier)}`),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
requestType: "json",
body: _body,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/custom_object_instances/{custom_object_type_identifier}");
});
}
/**
* Delete a single Custom Object instance by external_id.
*
* @param {Intercom.DeleteCustomObjectInstancesByIdRequest} request
* @param {CustomObjectInstancesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.customObjectInstances.deleteCustomObjectInstancesById({
* custom_object_type_identifier: "Order",
* external_id: "external_id"
* })
*/
deleteCustomObjectInstancesById(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__deleteCustomObjectInstancesById(request, requestOptions));
}
__deleteCustomObjectInstancesById(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { custom_object_type_identifier: customObjectTypeIdentifier, external_id: externalId } = request;
const _queryParams = {};
_queryParams.external_id = externalId;
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, `custom_object_instances/${core.url.encodePathParam(customObjectTypeIdentifier)}`),
method: "DELETE",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/custom_object_instances/{custom_object_type_identifier}");
});
}
/**
* Fetch a Custom Object Instance by id.
*
* @param {Intercom.GetCustomObjectInstancesByIdRequest} request
* @param {CustomObjectInstancesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.customObjectInstances.getCustomObjectInstancesById({
* custom_object_type_identifier: "Order",
* custom_object_instance_id: "custom_object_instance_id"
* })
*/
getCustomObjectInstancesById(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__getCustomObjectInstancesById(request, requestOptions));
}
__getCustomObjectInstancesById(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { custom_object_type_identifier: customObjectTypeIdentifier, custom_object_instance_id: customObjectInstanceId, } = request;
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, `custom_object_instances/${core.url.encodePathParam(customObjectTypeIdentifier)}/${core.url.encodePathParam(customObjectInstanceId)}`),
method: "GET",
headers: _headers,
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/custom_object_instances/{custom_object_type_identifier}/{custom_object_instance_id}");
});
}
/**
* Delete a single Custom Object instance using the Intercom defined id.
*
* @param {Intercom.DeleteCustomObjectInstancesByExternalIdRequest} request
* @param {CustomObjectInstancesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.customObjectInstances.deleteCustomObjectInstancesByExternalId({
* custom_object_type_identifier: "Order",
* custom_object_instance_id: "custom_object_instance_id"
* })
*/
deleteCustomObjectInstancesByExternalId(request, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__deleteCustomObjectInstancesByExternalId(request, requestOptions));
}
__deleteCustomObjectInstancesByExternalId(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const { custom_object_type_identifier: customObjectTypeIdentifier, custom_object_instance_id: customObjectInstanceId, } = request;
const _authRequest = yield this._options.authProvider.getAuthRequest();
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, `custom_object_instances/${core.url.encodePathParam(customObjectTypeIdentifier)}/${core.url.encodePathParam(customObjectInstanceId)}`),
method: "DELETE",
headers: _headers,
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse);
case 404:
throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/custom_object_instances/{custom_object_type_identifier}/{custom_object_instance_id}");
});
}
}