intercom-client
Version:
Official Node bindings to the Intercom API
789 lines • 72 kB
JavaScript
"use strict";
/**
* This file was auto-generated by Fern from our API Definition.
*/
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Contacts = void 0;
const environments = __importStar(require("../../../../environments"));
const core = __importStar(require("../../../../core"));
const Intercom = __importStar(require("../../../index"));
const url_join_1 = __importDefault(require("url-join"));
const errors = __importStar(require("../../../../errors/index"));
/**
* Everything about your contacts
*/
class Contacts {
constructor(_options = {}) {
this._options = _options;
}
/**
* You can fetch a list of companies that are associated to a contact.
*
* @param {Intercom.ListAttachedCompaniesRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.listAttachedCompanies({
* contact_id: "63a07ddf05a32042dffac965"
* })
*/
listAttachedCompanies(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
const list = (request) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId, page, per_page: perPage } = request;
const _queryParams = {};
if (page != null) {
_queryParams["page"] = page.toString();
}
if (perPage != null) {
_queryParams["per_page"] = perPage.toString();
}
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/companies`),
method: "GET",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling GET /contacts/{contact_id}/companies.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
let _offset = (request === null || request === void 0 ? void 0 : request.page) != null ? request === null || request === void 0 ? void 0 : request.page : 1;
return new core.Pageable({
response: yield list(request),
hasNextPage: (response) => { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.companies) !== null && _a !== void 0 ? _a : []).length > 0; },
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.companies) !== null && _a !== void 0 ? _a : []; },
loadPage: (_response) => {
_offset += 1;
return list(core.setObjectProperty(request, "page", _offset));
},
});
});
}
/**
* You can fetch a list of segments that are associated to a contact.
*
* @param {Intercom.ListSegmentsAttachedToContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.listAttachedSegments({
* contact_id: "63a07ddf05a32042dffac965"
* })
*/
listAttachedSegments(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/segments`),
method: "GET",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling GET /contacts/{contact_id}/segments.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch a list of subscription types that are attached to a contact. These can be subscriptions that a user has 'opted-in' to or has 'opted-out' from, depending on the subscription type.
* This will return a list of Subscription Type objects that the contact is associated with.
*
* The data property will show a combined list of:
*
* 1.Opt-out subscription types that the user has opted-out from.
* 2.Opt-in subscription types that the user has opted-in to receiving.
*
* @param {Intercom.ListAttachedSubscriptionsRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.listAttachedSubscriptions({
* contact_id: "63a07ddf05a32042dffac965"
* })
*/
listAttachedSubscriptions(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/subscriptions`),
method: "GET",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling GET /contacts/{contact_id}/subscriptions.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can add a specific subscription to a contact. In Intercom, we have two different subscription types based on user consent - opt-out and opt-in:
*
* 1.Attaching a contact to an opt-out subscription type will opt that user out from receiving messages related to that subscription type.
*
* 2.Attaching a contact to an opt-in subscription type will opt that user in to receiving messages related to that subscription type.
*
* This will return a subscription type model for the subscription type that was added to the contact.
*
* @param {Intercom.AttachSubscriptionToContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.attachSubscription({
* contact_id: "63a07ddf05a32042dffac965",
* id: "37846",
* consent_type: "opt_in"
* })
*
* @example
* await client.contacts.attachSubscription({
* contact_id: "63a07ddf05a32042dffac965",
* id: "invalid_id",
* consent_type: "opt_in"
* })
*/
attachSubscription(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request, _body = __rest(request, ["contact_id"]);
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/subscriptions`),
method: "POST",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
body: _body,
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling POST /contacts/{contact_id}/subscriptions.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can remove a specific subscription from a contact. This will return a subscription type model for the subscription type that was removed from the contact.
*
* @param {Intercom.DetachSubscriptionFromContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.detachSubscription({
* contact_id: "63a07ddf05a32042dffac965",
* subscription_id: "37846"
* })
*/
detachSubscription(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId, subscription_id: subscriptionId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/subscriptions/${encodeURIComponent(subscriptionId)}`),
method: "DELETE",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling DELETE /contacts/{contact_id}/subscriptions/{subscription_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch a list of all tags that are attached to a specific contact.
*
* @param {Intercom.ListTagsAttachedToContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.contacts.listAttachedTags({
* contact_id: "63a07ddf05a32042dffac965"
* })
*/
listAttachedTags(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}/tags`),
method: "GET",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
case 404:
throw new Intercom.NotFoundError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling GET /contacts/{contact_id}/tags.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch the details of a single contact.
*
* @param {Intercom.FindContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.contacts.find({
* contact_id: "63a07ddf05a32042dffac965"
* })
*/
find(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}`),
method: "GET",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling GET /contacts/{contact_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can update an existing contact (ie. user or lead).
*
* @param {Intercom.UpdateContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.contacts.update({
* contact_id: "63a07ddf05a32042dffac965",
* email: "joebloggs@intercom.io",
* name: "joe bloggs"
* })
*/
update(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request, _body = __rest(request, ["contact_id"]);
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}`),
method: "PUT",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
body: _body,
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling PUT /contacts/{contact_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can delete a single contact.
*
* @param {Intercom.DeleteContactRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.contacts.delete({
* contact_id: "contact_id"
* })
*/
delete(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId } = request;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, `contacts/${encodeURIComponent(contactId)}`),
method: "DELETE",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling DELETE /contacts/{contact_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`.
*
* @param {Intercom.MergeContactsRequest} request
* @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.contacts.mergeLeadInUser({
* from: "667d60ac8a68186f43bafdbb",
* into: "667d60ac8a68186f43bafdbc"
* })
*/
mergeLeadInUser(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.IntercomEnvironment.UsProduction, "contacts/merge"),
method: "POST",
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "intercom-client", "X-Fern-SDK-Version": "6.3.0", "User-Agent": "intercom-client/6.3.0", "Intercom-Version": (_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : "2.11", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 20000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Intercom.UnauthorizedError(_response.error.body);
default:
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.IntercomError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.IntercomTimeoutError("Timeout exceeded when calling POST /contacts/merge.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want.
*
* To search for contacts, you need to send a `POST` request to `https://api.intercom.io/contacts/search`.
*
* This will accept a query object in the body which will define your filters in order to search for contacts.
*
* {% admonition type="warning" name="Optimizing search queries" %}
* Search queries can be complex, so optimizing them can help the performance of your search.
* Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize
* pagination to limit the number of results returned. The default is `50` results per page.
* See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param.
* {% /admonition %}
* ### Contact Creation Delay
*
* If a contact has recently been created, there is a possibility that it will not yet be available when searching. This means that it may not appear in the response. This delay can take a few minutes. If you need to be instantly notified it is recommended to use webhooks and iterate to see if they match your search filters.
*
* ### Nesting & Limitations
*
* You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4).
* There are some limitations to the amount of multiple's there can be:
* * There's a limit of max 2 nested filters
* * There's a limit of max 15 filters for each AND or OR group
*
* ### Searching for Timestamp Fields
*
* All timestamp fields (created_at, updated_at etc.) are indexed as Dates for Contact Search queries; Datetime queries are not currently supported. This means you can only query for timestamp fields by day - not hour, minute or second.
* For example, if you search for all Contacts with a created_at value greater (>) than 1577869200 (the UNIX timestamp for January 1st, 2020 9:00 AM), that will be interpreted as 1577836800 (January 1st, 2020 12:00 AM). The search results will then include Contacts created from January 2nd, 2020 12:00 AM onwards.
* If you'd like to get contacts created on January 1st, 2020 you should search with a created_at value equal (=) to 1577836800 (January 1st, 2020 12:00 AM).
* This behaviour applies only to timestamps used in search queries. The search results will still contain the full UNIX timestamp and be sorted accordingly.
*
* ### Accepted Fields
*
* Most key listed as part of the Contacts Model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`).
*
* | Field | Type |
* | ---------------------------------- | ------------------------------ |
* | id | String |
* | role | String<br>Accepts user or lead |
* | name | String |
* | avatar | String |
* | owner_id | Integer |
* | email | String |
* | email_domain | String |
* | phone | String |
* | external_id | String |
* | created_at | Date (UNIX Timestamp) |
* | signed_up_at | Date (UNIX Timestamp) |
* | updated_at | Date (UNIX Timestamp) |
* | last_seen_at | Date (UNIX Timestamp) |
* | last_contacted_at | Date (UNIX Timestamp) |
* | last_replied_at | Date (UNIX Timestamp) |
* | last_email_opened_at | Date (UNIX Timestamp) |
* | last_email_clicked_at | Date (UNIX Timestamp) |
* | language_override | String |
* | browser | String |
* | browser_language | String |
* | os | String |
* | location.country | String |
* | location.region | String |
* | location.city | String |
* | unsubscribed_from_emails | Boolean |
* | marked_email_as_spam | Boolean |
* | has_hard_bounced | Boolean |
* | ios_last_seen_at | Date (UNIX Timestamp) |
* | ios_app_version | String |
* | ios_device | String |
* | ios_app_device | String |
* | ios_os_version | String |
* | ios_app_name | String |
* | ios_sdk_version | String |
* | android_last_seen_at | Date (UNIX Timestamp) |
* | android_app_version | String |
* | android_device | String |
* | android_app_name | String |
* | andoid_sdk_version | String |
* | segment_id | String |
* | tag_id | String |
* | custom_attributes.{attribute_name} | String |
*
* ### Accepted Operators
*
* {% admonition type="warning" name="Searching based on `created_at`" %}
* You cannot use the `<=` or `>=` operators to search by `created_at`.
* {% /admonition %}
*
* The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates).
*
* | Operator | Valid Types | Description |
* | :------- | :------------------------------- | :-------------------------------------------------