UNPKG

@azure/communication-common

Version:
55 lines (54 loc) 2.37 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var clientArguments_exports = {}; __export(clientArguments_exports, { isKeyCredential: () => isKeyCredential, parseClientArguments: () => parseClientArguments }); module.exports = __toCommonJS(clientArguments_exports); var import_core_auth = require("@azure/core-auth"); var import_connectionString = require("./connectionString.js"); const isValidEndpoint = (host) => { const url = new URL(host); return !!url.protocol?.match(/^http[s]?/) && url.host !== void 0 && url.host !== "" && (url.pathname === void 0 || url.pathname === "" || url.pathname === "/"); }; const assertValidEndpoint = (host) => { if (!isValidEndpoint(host)) { throw new Error(`Invalid endpoint url ${host}`); } }; const isKeyCredential = (credential) => { const castCredential = credential; return castCredential && typeof castCredential.key === "string" && castCredential.getToken === void 0; }; const parseClientArguments = (connectionStringOrUrl, credentialOrOptions) => { if (isKeyCredential(credentialOrOptions) || (0, import_core_auth.isTokenCredential)(credentialOrOptions)) { assertValidEndpoint(connectionStringOrUrl); return { url: connectionStringOrUrl, credential: credentialOrOptions }; } else { const { endpoint: host, credential } = (0, import_connectionString.parseConnectionString)(connectionStringOrUrl); assertValidEndpoint(host); return { url: host, credential }; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { isKeyCredential, parseClientArguments }); //# sourceMappingURL=clientArguments.js.map