intercom-client
Version:
Official Node bindings to the Intercom API
822 lines • 52 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.Companies = 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 Companies
*/
class Companies {
constructor(_options = {}) {
this._options = _options;
}
/**
* You can fetch a single company by passing in `company_id` or `name`.
*
* `https://api.intercom.io/companies?name={name}`
*
* `https://api.intercom.io/companies?company_id={company_id}`
*
* You can fetch all companies and filter by `segment_id` or `tag_id` as a query parameter.
*
* `https://api.intercom.io/companies?tag_id={tag_id}`
*
* `https://api.intercom.io/companies?segment_id={segment_id}`
*
* @param {Intercom.RetrieveCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.retrieve({
* name: "my company",
* company_id: "12345",
* tag_id: "678910",
* segment_id: "98765"
* })
*/
retrieve() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
var _a, _b, _c, _d, _e, _f;
const { name, company_id: companyId, tag_id: tagId, segment_id: segmentId, page, per_page: perPage } = request;
const _queryParams = {};
if (name != null) {
_queryParams["name"] = name;
}
if (companyId != null) {
_queryParams["company_id"] = companyId;
}
if (tagId != null) {
_queryParams["tag_id"] = tagId;
}
if (segmentId != null) {
_queryParams["segment_id"] = segmentId;
}
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, "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 /companies.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can create or update a company.
*
* Companies will be only visible in Intercom when there is at least one associated user.
*
* Companies are looked up via `company_id` in a `POST` request, if not found via `company_id`, the new company will be created, if found, that company will be updated.
*
* {% admonition type="warning" name="Using `company_id`" %}
* You can set a unique `company_id` value when creating a company. However, it is not possible to update `company_id`. Be sure to set a unique value once upon creation of the company.
* {% /admonition %}
*
* @param {Intercom.CreateOrUpdateCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.BadRequestError}
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.companies.createOrUpdate({
* name: "my company",
* company_id: "company_remote_id",
* remote_created_at: 1374138000
* })
*
* @example
* await client.companies.createOrUpdate()
*/
createOrUpdate() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
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, "companies"),
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 400:
throw new Intercom.BadRequestError(_response.error.body);
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 /companies.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch a single company.
*
* @param {Intercom.FindCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.find({
* company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632"
* })
*/
find(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { company_id: companyId } = 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, `companies/${encodeURIComponent(companyId)}`),
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 /companies/{company_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can update a single company using the Intercom provisioned `id`.
*
* {% admonition type="warning" name="Using `company_id`" %}
* When updating a company it is not possible to update `company_id`. This can only be set once upon creation of the company.
* {% /admonition %}
*
* @param {Intercom.UpdateCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.update({
* company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632"
* })
*/
update(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { company_id: companyId } = 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, `companies/${encodeURIComponent(companyId)}`),
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",
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 PUT /companies/{company_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can delete a single company.
*
* @param {Intercom.DeleteCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.delete({
* company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632"
* })
*/
delete(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { company_id: companyId } = 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, `companies/${encodeURIComponent(companyId)}`),
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 /companies/{company_id}.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch a list of all contacts that belong to a company.
*
* @param {Intercom.ListAttachedContactsRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.listAttachedContacts({
* company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632"
* })
*/
listAttachedContacts(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { company_id: companyId, 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, `companies/${encodeURIComponent(companyId)}/contacts`),
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 /companies/{company_id}/contacts.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can fetch a list of all segments that belong to a company.
*
* @param {Intercom.ListSegmentsAttachedToCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.listAttachedSegments({
* company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632"
* })
*/
listAttachedSegments(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { company_id: companyId } = 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, `companies/${encodeURIComponent(companyId)}/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 /companies/{company_id}/segments.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can list companies. The company list is sorted by the `last_request_at` field and by default is ordered descending, most recently requested first.
*
* Note that the API does not include companies who have no associated users in list responses.
*
* When using the Companies endpoint and the pages object to iterate through the returned companies, there is a limit of 10,000 Companies that can be returned. If you need to list or iterate on more than 10,000 Companies, please use the [Scroll API](https://developers.intercom.com/reference#iterating-over-all-companies).
* {% admonition type="warning" name="Pagination" %}
* You can use pagination to limit the number of results returned. The default is `20` results per page.
* See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param.
* {% /admonition %}
*
* @param {Intercom.ListCompaniesRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.companies.list({
* order: "desc"
* })
*/
list() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
const list = (request) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { page, per_page: perPage, order } = request;
const _queryParams = {};
if (page != null) {
_queryParams["page"] = page.toString();
}
if (perPage != null) {
_queryParams["per_page"] = perPage.toString();
}
if (order != null) {
_queryParams["order"] = order;
}
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, "companies/list"),
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",
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);
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 /companies/list.");
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.data) !== null && _a !== void 0 ? _a : []).length > 0; },
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : []; },
loadPage: (_response) => {
_offset += 1;
return list(core.setObjectProperty(request, "page", _offset));
},
});
});
}
/**
* The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply. The Scroll API provides an efficient mechanism for iterating over all companies in a dataset.
*
* - Each app can only have 1 scroll open at a time. You'll get an error message if you try to have more than one open per app.
* - If the scroll isn't used for 1 minute, it expires and calls with that scroll param will fail
* - If the end of the scroll is reached, "companies" will be empty and the scroll parameter will expire
*
* {% admonition type="info" name="Scroll Parameter" %}
* You can get the first page of companies by simply sending a GET request to the scroll endpoint.
* For subsequent requests you will need to use the scroll parameter from the response.
* {% /admonition %}
* {% admonition type="danger" name="Scroll network timeouts" %}
* Since scroll is often used on large datasets network errors such as timeouts can be encountered. When this occurs you will see a HTTP 500 error with the following message:
* "Request failed due to an internal network error. Please restart the scroll operation."
* If this happens, you will need to restart your scroll query: It is not possible to continue from a specific point when using scroll.
* {% /admonition %}
*
* @param {Intercom.ScrollCompaniesRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
*
* @example
* await client.companies.scroll()
*/
scroll() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
const list = (request) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { scroll_param: scrollParam } = request;
const _queryParams = {};
if (scrollParam != null) {
_queryParams["scroll_param"] = scrollParam;
}
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, "companies/scroll"),
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);
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 /companies/scroll.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
return new core.Pageable({
response: yield list(request),
hasNextPage: (response) => (response === null || response === void 0 ? void 0 : response.scroll_param) != null,
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : []; },
loadPage: (response) => {
return list(core.setObjectProperty(request, "scroll_param", response === null || response === void 0 ? void 0 : response.scroll_param));
},
});
});
}
/**
* You can attach a company to a single contact.
*
* @param {Intercom.AttachContactToCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.BadRequestError}
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.attachContact({
* contact_id: "contact_id",
* id: "667d608d8a68186f43bafd70"
* })
*
* @example
* await client.companies.attachContact({
* contact_id: "contact_id",
* id: "58a430d35458202d41b1e65b"
* })
*
* @example
* await client.companies.attachContact({
* contact_id: "contact_id",
* id: "123"
* })
*/
attachContact(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)}/companies`),
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 400:
throw new Intercom.BadRequestError(_response.error.body);
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}/companies.");
case "unknown":
throw new errors.IntercomError({
message: _response.error.errorMessage,
});
}
});
}
/**
* You can detach a company from a single contact.
*
* @param {Intercom.DetachContactFromCompanyRequest} request
* @param {Companies.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Intercom.UnauthorizedError}
* @throws {@link Intercom.NotFoundError}
*
* @example
* await client.companies.detachContact({
* contact_id: "58a430d35458202d41b1e65b",
* company_id: "58a430d35458202d41b1e65b"
* })
*/
detachContact(request, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const { contact_id: contactId, company_id: companyId } = 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)}/companies/${encodeURIComponent(companyId)}`),
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) {
r