phonic
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node) [ • 2.32 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";
const TOKEN_PARAM = "apiKey";
const ENV_TOKEN = "PHONIC_API_KEY";
export class BearerAuthProvider {
constructor(options) {
this.options = options;
}
static canCreate(options) {
var _a;
return (options === null || options === void 0 ? void 0 : options[TOKEN_PARAM]) != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a[ENV_TOKEN]) != null;
}
getAuthRequest() {
return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
var _a, _b;
const apiKey = (_a = (yield core.Supplier.get(this.options[TOKEN_PARAM]))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b[ENV_TOKEN];
if (apiKey == null) {
throw new errors.PhonicError({
message: BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE,
});
}
return {
headers: { Authorization: `Bearer ${apiKey}` },
};
});
}
}
(function (BearerAuthProvider) {
BearerAuthProvider.AUTH_SCHEME = "bearerAuth";
BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE = `Please provide '${TOKEN_PARAM}' when initializing the client, or set the '${ENV_TOKEN}' environment variable`;
function createInstance(options) {
return new BearerAuthProvider(options);
}
BearerAuthProvider.createInstance = createInstance;
})(BearerAuthProvider || (BearerAuthProvider = {}));