intercom-client
Version:
Official Node bindings to the Intercom API
36 lines (35 loc) • 1.8 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());
});
};
import * as core from "../core/index.mjs";
import * as errors from "../errors/index.mjs";
export class BearerAuthProvider {
constructor(options) {
this.token = options.token;
}
static canCreate(options) {
var _a;
return options.token != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.INTERCOM_API_KEY) != null;
}
getAuthRequest(_arg) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const token = (_a = (yield core.Supplier.get(this.token))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.INTERCOM_API_KEY;
if (token == null) {
throw new errors.IntercomError({
message: "Please specify a token by either passing it in to the constructor or initializing a INTERCOM_API_KEY environment variable",
});
}
return {
headers: { Authorization: `Bearer ${token}` },
};
});
}
}