UNPKG

@azure/cosmos

Version:
62 lines (61 loc) 2.65 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 platform_exports = {}; __export(platform_exports, { addFeatureFlagsToUserAgent: () => addFeatureFlagsToUserAgent, getUserAgent: () => getUserAgent }); module.exports = __toCommonJS(platform_exports); var import_constants = require("./constants.js"); function getUserAgent(optionsOrConnectionString, hostFramework) { let ua = `${userAgentDetails()} ${import_constants.Constants.SDKName}/${import_constants.Constants.SDKVersion}`; if (hostFramework) { ua = ua + " " + hostFramework; } if (optionsOrConnectionString && optionsOrConnectionString.userAgentSuffix) { ua = ua + " " + optionsOrConnectionString.userAgentSuffix; } return ua; } function userAgentDetails() { let userAgentDetail = "<environment undetectable>"; if (globalThis.navigator && globalThis.navigator.userAgent) { userAgentDetail = globalThis.navigator.userAgent; } if (globalThis.process && globalThis.process.version) { userAgentDetail = `Node.js/${process.version.slice(1)} (${process.platform}; ${process.arch})`; } return userAgentDetail; } function addFeatureFlagsToUserAgent(optionsOrConnectionString) { let featureFlag = 0; if (optionsOrConnectionString.connectionPolicy) { if (optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover) { featureFlag += import_constants.UserAgentFeatureFlags.PerPartitionAutomaticFailover; } if (optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover || optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker) { featureFlag += import_constants.UserAgentFeatureFlags.PerPartitionCircuitBreaker; } } return featureFlag === 0 ? "" : ` F${featureFlag.toString(16).toUpperCase()}`; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { addFeatureFlagsToUserAgent, getUserAgent });