UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

98 lines (94 loc) 3.14 kB
"use strict"; 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); // src/proxy.ts var proxy_exports = {}; __export(proxy_exports, { getRequestUrl: () => getRequestUrl, isHttpOrHttps: () => isHttpOrHttps, isProxyUrlRelative: () => isProxyUrlRelative, isValidProxyUrl: () => isValidProxyUrl, proxyUrlToAbsoluteURL: () => proxyUrlToAbsoluteURL }); module.exports = __toCommonJS(proxy_exports); // src/utils/runtimeEnvironment.ts var isTestEnvironment = () => { try { return process.env.NODE_ENV === "test"; } catch (err) { } return false; }; var isProductionEnvironment = () => { try { return process.env.NODE_ENV === "production"; } catch (err) { } return false; }; // src/deprecated.ts var displayedWarnings = /* @__PURE__ */ new Set(); var deprecated = (fnName, warning, key) => { const hideWarning = isTestEnvironment() || isProductionEnvironment(); const messageId = key ?? fnName; if (displayedWarnings.has(messageId) || hideWarning) { return; } displayedWarnings.add(messageId); console.warn( `Clerk - DEPRECATION WARNING: "${fnName}" is deprecated and will be removed in the next major release. ${warning}` ); }; // src/proxy.ts function isValidProxyUrl(key) { if (!key) { return true; } return isHttpOrHttps(key) || isProxyUrlRelative(key); } function isHttpOrHttps(key) { return /^http(s)?:\/\//.test(key || ""); } function isProxyUrlRelative(key) { return key.startsWith("/"); } function proxyUrlToAbsoluteURL(url) { if (!url) { return ""; } return isProxyUrlRelative(url) ? new URL(url, window.location.origin).toString() : url; } function getRequestUrl({ request, relativePath }) { deprecated("getRequestUrl", "Use `buildRequestUrl` from @clerk/backend instead."); const { headers, url: initialUrl } = request; const url = new URL(initialUrl); const host = headers.get("X-Forwarded-Host") ?? headers.get("host") ?? headers["host"] ?? url.host; let protocol = (headers.get("X-Forwarded-Proto") ?? headers["X-Forwarded-Proto"])?.split(",")[0] ?? url.protocol; protocol = protocol.replace(/[:/]/, ""); return new URL(relativePath || url.pathname, `${protocol}://${host}`); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getRequestUrl, isHttpOrHttps, isProxyUrlRelative, isValidProxyUrl, proxyUrlToAbsoluteURL }); //# sourceMappingURL=proxy.js.map