@replohq/canopy-sdk 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,139 +1,5 @@
1
- import { Symbol_default, isArray_default, isObjectLike_default, baseGetTag_default } from '../../../chunk-FNTGY7I5.mjs';
2
-
3
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayMap.js
4
- function arrayMap(array, iteratee) {
5
- var index = -1, length = array == null ? 0 : array.length, result = Array(length);
6
- while (++index < length) {
7
- result[index] = iteratee(array[index], index, array);
8
- }
9
- return result;
10
- }
11
- var arrayMap_default = arrayMap;
12
-
13
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isSymbol.js
14
- var symbolTag = "[object Symbol]";
15
- function isSymbol(value) {
16
- return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
17
- }
18
- var isSymbol_default = isSymbol;
19
- var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
20
- var symbolToString = symbolProto ? symbolProto.toString : void 0;
21
- function baseToString(value) {
22
- if (typeof value == "string") {
23
- return value;
24
- }
25
- if (isArray_default(value)) {
26
- return arrayMap_default(value, baseToString) + "";
27
- }
28
- if (isSymbol_default(value)) {
29
- return symbolToString ? symbolToString.call(value) : "";
30
- }
31
- var result = value + "";
32
- return result == "0" && 1 / value == -Infinity ? "-0" : result;
33
- }
34
- var baseToString_default = baseToString;
35
-
36
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toString.js
37
- function toString(value) {
38
- return value == null ? "" : baseToString_default(value);
39
- }
40
- var toString_default = toString;
41
-
42
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseSlice.js
43
- function baseSlice(array, start, end) {
44
- var index = -1, length = array.length;
45
- if (start < 0) {
46
- start = -start > length ? 0 : length + start;
47
- }
48
- end = end > length ? length : end;
49
- if (end < 0) {
50
- end += length;
51
- }
52
- length = start > end ? 0 : end - start >>> 0;
53
- start >>>= 0;
54
- var result = Array(length);
55
- while (++index < length) {
56
- result[index] = array[index + start];
57
- }
58
- return result;
59
- }
60
- var baseSlice_default = baseSlice;
61
-
62
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_castSlice.js
63
- function castSlice(array, start, end) {
64
- var length = array.length;
65
- end = end === void 0 ? length : end;
66
- return !start && end >= length ? array : baseSlice_default(array, start, end);
67
- }
68
- var castSlice_default = castSlice;
69
-
70
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_hasUnicode.js
71
- var rsAstralRange = "\\ud800-\\udfff";
72
- var rsComboMarksRange = "\\u0300-\\u036f";
73
- var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
74
- var rsComboSymbolsRange = "\\u20d0-\\u20ff";
75
- var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
76
- var rsVarRange = "\\ufe0e\\ufe0f";
77
- var rsZWJ = "\\u200d";
78
- var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + "]");
79
- function hasUnicode(string) {
80
- return reHasUnicode.test(string);
81
- }
82
- var hasUnicode_default = hasUnicode;
83
-
84
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_asciiToArray.js
85
- function asciiToArray(string) {
86
- return string.split("");
87
- }
88
- var asciiToArray_default = asciiToArray;
89
-
90
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_unicodeToArray.js
91
- var rsAstralRange2 = "\\ud800-\\udfff";
92
- var rsComboMarksRange2 = "\\u0300-\\u036f";
93
- var reComboHalfMarksRange2 = "\\ufe20-\\ufe2f";
94
- var rsComboSymbolsRange2 = "\\u20d0-\\u20ff";
95
- var rsComboRange2 = rsComboMarksRange2 + reComboHalfMarksRange2 + rsComboSymbolsRange2;
96
- var rsVarRange2 = "\\ufe0e\\ufe0f";
97
- var rsAstral = "[" + rsAstralRange2 + "]";
98
- var rsCombo = "[" + rsComboRange2 + "]";
99
- var rsFitz = "\\ud83c[\\udffb-\\udfff]";
100
- var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
101
- var rsNonAstral = "[^" + rsAstralRange2 + "]";
102
- var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
103
- var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
104
- var rsZWJ2 = "\\u200d";
105
- var reOptMod = rsModifier + "?";
106
- var rsOptVar = "[" + rsVarRange2 + "]?";
107
- var rsOptJoin = "(?:" + rsZWJ2 + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
108
- var rsSeq = rsOptVar + reOptMod + rsOptJoin;
109
- var rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
110
- var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
111
- function unicodeToArray(string) {
112
- return string.match(reUnicode) || [];
113
- }
114
- var unicodeToArray_default = unicodeToArray;
115
-
116
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_stringToArray.js
117
- function stringToArray(string) {
118
- return hasUnicode_default(string) ? unicodeToArray_default(string) : asciiToArray_default(string);
119
- }
120
- var stringToArray_default = stringToArray;
121
-
122
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createCaseFirst.js
123
- function createCaseFirst(methodName) {
124
- return function(string) {
125
- string = toString_default(string);
126
- var strSymbols = hasUnicode_default(string) ? stringToArray_default(string) : void 0;
127
- var chr = strSymbols ? strSymbols[0] : string.charAt(0);
128
- var trailing = strSymbols ? castSlice_default(strSymbols, 1).join("") : string.slice(1);
129
- return chr[methodName]() + trailing;
130
- };
131
- }
132
- var createCaseFirst_default = createCaseFirst;
133
-
134
- // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/upperFirst.js
135
- var upperFirst = createCaseFirst_default("toUpperCase");
136
- var upperFirst_default = upperFirst;
1
+ import { upperFirst_default, toString_default } from '../../../chunk-AKZNN7F2.mjs';
2
+ import '../../../chunk-FNTGY7I5.mjs';
137
3
 
138
4
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/capitalize.js
139
5
  function capitalize(string) {
@@ -0,0 +1,43 @@
1
+ export declare const getValidFilename: (value: string) => string;
2
+ export declare function slugify(text: string): string;
3
+ export declare function metafieldContainsHtml(metafieldValue: string): boolean;
4
+ export declare function capitalizeFirstLetter(inputString: string): string;
5
+ /**
6
+ * Get url without query params.
7
+ *
8
+ * @author Kurt 2024-10-14
9
+ */
10
+ export declare const getUrlWithoutQueryParams: (url: string) => string | undefined;
11
+ /**
12
+ * Converts PascalCase strings to readable format with spaces.
13
+ * E.g., "LandingPage1" -> "Landing Page 1"
14
+ *
15
+ * @param pascalCaseString - The PascalCase string to convert
16
+ * @returns A readable string with spaces between words and numbers
17
+ */
18
+ export declare const convertPascalCaseToReadable: (pascalCaseString: string) => string;
19
+ export declare function formatWithCatN({ content, startLineNumber, }: {
20
+ content: string;
21
+ startLineNumber?: number;
22
+ }): string;
23
+ /**
24
+ * Escapes special regex characters in a string for use in RegExp constructor
25
+ */
26
+ export declare function escapeRegExp(string: string): string;
27
+ /**
28
+ * Skill names are authored as kebab-case slugs in SKILL.md frontmatter
29
+ * ("site-management", "founder-review"). Anywhere we render the name to the
30
+ * user — skills app cards, the chat tool feed, the provisioning overlay — we
31
+ * run it through this so they see "Site Management", "Founder Review", etc.
32
+ * instead of the raw slug.
33
+ *
34
+ * Names that already look human-authored (any whitespace or any uppercase
35
+ * letter) are returned untouched, so a skill can opt out by writing
36
+ * `name: My Custom Skill` in frontmatter.
37
+ */
38
+ export declare function prettifySkillName(name: string): string;
39
+ /**
40
+ * Safely decodes a URI component, returning the original value if decoding fails.
41
+ * Returns null if the input is null or undefined, preserving empty strings.
42
+ */
43
+ export declare function decodeURIComponentSafe(value: string | null | undefined): string | null;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Builds a URLSearchParams from a record, omitting undefined values. Array
3
+ * values are appended as repeated keys; scalars are stringified.
4
+ */
5
+ export declare function buildUrlSearchParams(values: Record<string, string | number | boolean | string[] | undefined>): URLSearchParams;
6
+ export declare function isValidHttpUrl(url: string, options?: {
7
+ allowBlockedHostnames?: boolean;
8
+ allowedHostnames?: string[];
9
+ }): boolean;
10
+ /**
11
+ * Tries to parse and validate the given string as a URL, including protocol-relative
12
+ * URLs. Returns a URL if parsing is possible, otherwise null.
13
+ *
14
+ * Note: Javascript URLs don't recognize protocol-relative URLs (e.g. //google.com)
15
+ * as valid, so we need special casing here. If protocol-relative, the returned
16
+ * url will have an https protocol. This default is arbitrary but backed up by best
17
+ * practice: https://webhint.io/docs/user-guide/hints/hint-no-protocol-relative-urls/
18
+ */
19
+ export declare function normalizeUrlIncludingProtocolRelative(url: string): URL | null;
20
+ export declare function normalizeCustomDomain(input: string): string;
21
+ /**
22
+ * Returns true if `origin` is a valid Replo Vercel preview deployment origin.
23
+ * Matches `https://<slug>.preview.replointernal.com`, e.g.
24
+ *
25
+ * Use this when you have a full origin string (e.g. from `request.headers.origin`).
26
+ */
27
+ export declare function isPreviewOrigin(origin: string): boolean;
28
+ /**
29
+ * Returns true if `hostname` belongs to a Replo Vercel preview deployment.
30
+ * Matches `<slug>.preview.replointernal.com`, e.g.
31
+ *
32
+ * Use this when you've already parsed the URL and have a bare hostname.
33
+ */
34
+ export declare function isPreviewInternalHostname(hostname: string): boolean;
35
+ export declare function normalizeUrlScheme(url: string): string;
36
+ /**
37
+ * Truncates a domain name by shortening the subdomain portion while preserving
38
+ * the main domain suffix. Useful for displaying long domain names in UI.
39
+ *
40
+ * @param domain - The domain to truncate (e.g., "very-long-subdomain.example.com")
41
+ * @param maxLength - Maximum length of the truncated domain (default: 40)
42
+ * @returns Truncated domain with ellipsis (e.g., "very-long-sub...example.com")
43
+ */
44
+ export declare function truncateDomain(domain: string, maxLength?: number): string;
45
+ /**
46
+ * Validates that a route path is properly formatted and URL-safe.
47
+ * Routes must start with / and contain only valid slug segments.
48
+ *
49
+ * @param path - The route path to validate
50
+ * @returns true if the path is a valid route, false otherwise
51
+ */
52
+ export declare const isValidRoutePath: (path: string) => boolean;
53
+ /**
54
+ * Parses a URL, returning null instead of throwing. Pass `base` to resolve a
55
+ * relative value such as a site path.
56
+ */
57
+ export declare function parseUrl(value: string, base?: string): URL | null;
@@ -0,0 +1,3 @@
1
+ export { buildUrlSearchParams, isPreviewInternalHostname, isPreviewOrigin, isValidHttpUrl, isValidRoutePath, normalizeCustomDomain, normalizeUrlIncludingProtocolRelative, normalizeUrlScheme, parseUrl, truncateDomain } from '../../../chunk-2GKD6VTQ.mjs';
2
+ import '../../../chunk-AKZNN7F2.mjs';
3
+ import '../../../chunk-FNTGY7I5.mjs';
@@ -3,6 +3,8 @@ var DATA_LOADER_KEYS = {
3
3
  SHOPIFY_PRODUCT: "shopify_storefront.product",
4
4
  SHOPIFY_COLLECTION: "shopify_storefront.collection",
5
5
  SHOPIFY_COLLECTION_PRODUCTS: "shopify_storefront.collection_products",
6
+ SHOPIFY_METAOBJECT: "shopify_storefront.metaobject",
7
+ SHOPIFY_METAOBJECTS: "shopify_storefront.metaobjects",
6
8
  REPLO_PRODUCT: "replo_products.product",
7
9
  OKENDO_PRODUCT_REVIEWS: "okendo.product_reviews",
8
10
  OKENDO_PRODUCT_REVIEW_AGGREGATE: "okendo.product_review_aggregate",
@@ -0,0 +1,38 @@
1
+ /** Captured segment values, keyed by param name. */
2
+ type RouteParams = Record<string, string>;
3
+ /**
4
+ * The params captured from `pathname`, or null when the source does not match.
5
+ * An empty object means the source matched with nothing to capture.
6
+ */
7
+ export declare function matchSource({ source, pathname, }: {
8
+ source: string;
9
+ pathname: string;
10
+ }): RouteParams | null;
11
+ /**
12
+ * Whether a destination carries any `:param`, anywhere — including inside a
13
+ * query, which splitting on `/` would miss.
14
+ */
15
+ export declare function hasRouteParam(value: string): boolean;
16
+ /**
17
+ * Every `:param` in the string, in order, each written back with its modifier.
18
+ * The modifier is part of the identity: a source's `:page?` may capture
19
+ * nothing, so a destination's `:page` is not the same param.
20
+ */
21
+ export declare function getRouteParams(value: string): string[];
22
+ /**
23
+ * Substitutes captured params into a destination in one pass, so a substituted
24
+ * value is never rescanned as though it were itself a param. A param the
25
+ * request never captured collapses to nothing when it was optional, and is
26
+ * otherwise left in place for the caller to notice.
27
+ */
28
+ export declare function applyParams({ value, params, }: {
29
+ value: string;
30
+ params: RouteParams;
31
+ }): string;
32
+ export interface ParamSegment {
33
+ name: string;
34
+ modifier: "*" | "+" | "?" | null;
35
+ }
36
+ /** Reads `:name`, `:name*`, `:name+`, or `:name?`; null for a literal segment. */
37
+ export declare function getParamSegment(segment: string): ParamSegment | null;
38
+ export {};
@@ -0,0 +1 @@
1
+ export { applyParams, getParamSegment, getRouteParams, hasRouteParam, matchSource } from '../../../chunk-VPEVERWE.mjs';
@@ -0,0 +1,30 @@
1
+ import { ReploError } from "../errors";
2
+ import { z } from "zod";
3
+ export declare class RedirectRuleValidationError extends ReploError {
4
+ }
5
+ export declare const redirectStatusSchema: z.ZodUnion<readonly [z.ZodLiteral<301>, z.ZodLiteral<302>, z.ZodLiteral<307>, z.ZodLiteral<308>]>;
6
+ export declare const redirectRuleSchema: z.ZodObject<{
7
+ source: z.ZodString;
8
+ destination: z.ZodString;
9
+ status: z.ZodUnion<readonly [z.ZodLiteral<301>, z.ZodLiteral<302>, z.ZodLiteral<307>, z.ZodLiteral<308>]>;
10
+ }, z.core.$strict>;
11
+ export type RedirectStatus = z.infer<typeof redirectStatusSchema>;
12
+ export type RedirectRule = z.infer<typeof redirectRuleSchema>;
13
+ /**
14
+ * Validates a redirect rule, returning it unchanged. Throws
15
+ * `RedirectRuleValidationError` carrying the first failing check's message.
16
+ */
17
+ export declare function reploRedirect(input: RedirectRule): RedirectRule;
18
+ export interface RedirectConflict {
19
+ blockingIndex: number;
20
+ blockedIndex: number;
21
+ }
22
+ /**
23
+ * Rules evaluate first-match-wins, so an earlier rule that already matches a
24
+ * later rule's own source makes the later rule dead. Compared with the later
25
+ * source's route params replaced, since that is a concrete path the earlier rule
26
+ * would see at request time.
27
+ */
28
+ export declare function findRedirectConflicts(rules: readonly {
29
+ source: string;
30
+ }[]): RedirectConflict[];
@@ -0,0 +1,92 @@
1
+ import { getParamSegment, getRouteParams, hasRouteParam, matchSource } from '../../../chunk-VPEVERWE.mjs';
2
+ import { parseUrl } from '../../../chunk-2GKD6VTQ.mjs';
3
+ import '../../../chunk-AKZNN7F2.mjs';
4
+ import { ReploError } from '../../../chunk-OFU2QEDR.mjs';
5
+ import '../../../chunk-H36NDYLG.mjs';
6
+ import '../../../chunk-ILGEM42C.mjs';
7
+ import '../../../chunk-FNTGY7I5.mjs';
8
+ import { z } from 'zod';
9
+
10
+ var RedirectRuleValidationError = class extends ReploError {
11
+ };
12
+ var SITE_PATH_ORIGIN = "https://site.invalid";
13
+ var redirectStatusSchema = z.union([
14
+ z.literal(301),
15
+ z.literal(302),
16
+ z.literal(307),
17
+ z.literal(308)
18
+ ]);
19
+ var sourceSchema = z.string().min(1).refine((source) => source.startsWith("/"), {
20
+ message: "must start with /"
21
+ }).refine((source) => source.split("/").every(hasValidWildcardUsage), {
22
+ message: '"*" is only meaningful on a param segment \u2014 write "/blog/:rest*", not "/blog/*"'
23
+ });
24
+ function hasValidWildcardUsage(segment) {
25
+ if (!segment.includes("*")) {
26
+ return true;
27
+ }
28
+ return getParamSegment(segment)?.modifier === "*";
29
+ }
30
+ var destinationSchema = z.string().min(1).refine(
31
+ (destination) => {
32
+ const concrete = replaceRouteParamsWithSentinel(destination);
33
+ if (concrete.startsWith("/")) {
34
+ return parseUrl(concrete, SITE_PATH_ORIGIN)?.origin === SITE_PATH_ORIGIN;
35
+ }
36
+ const protocol = parseUrl(concrete)?.protocol;
37
+ return protocol === "http:" || protocol === "https:";
38
+ },
39
+ {
40
+ message: "must be a path on this site or an absolute HTTP(S) URL; a destination starting with / must stay on this site"
41
+ }
42
+ );
43
+ var redirectRuleSchema = z.object({
44
+ source: sourceSchema,
45
+ destination: destinationSchema,
46
+ status: redirectStatusSchema
47
+ }).strict().superRefine(({ source, destination }, context) => {
48
+ const captured = new Set(getRouteParams(source));
49
+ for (const routeParam of getRouteParams(destination)) {
50
+ if (!captured.has(routeParam)) {
51
+ context.addIssue({
52
+ code: "custom",
53
+ path: ["destination"],
54
+ message: `":${routeParam}" is not captured by this rule's source, so it would be redirected to literally`
55
+ });
56
+ }
57
+ }
58
+ const concrete = replaceRouteParamsWithSentinel(destination);
59
+ if (hasRouteParam(destination) && concrete.startsWith("/") && matchSource({ source, pathname: concrete }) !== null) {
60
+ context.addIssue({
61
+ code: "custom",
62
+ path: ["destination"],
63
+ message: "destination is matched by this rule's own source, so the redirect would loop forever"
64
+ });
65
+ }
66
+ });
67
+ function reploRedirect(input) {
68
+ const parsed = redirectRuleSchema.safeParse(input);
69
+ if (parsed.success) {
70
+ return parsed.data;
71
+ }
72
+ const message = parsed.error.issues[0]?.message ?? "invalid redirect rule";
73
+ throw new RedirectRuleValidationError({ message });
74
+ }
75
+ function findRedirectConflicts(rules) {
76
+ const conflicts = [];
77
+ rules.forEach((blocked, blockedIndex) => {
78
+ const pathname = replaceRouteParamsWithSentinel(blocked.source);
79
+ const blockingIndex = rules.findIndex((blocking, index) => {
80
+ return index < blockedIndex && matchSource({ source: blocking.source, pathname }) !== null;
81
+ });
82
+ if (blockingIndex >= 0) {
83
+ conflicts.push({ blockingIndex, blockedIndex });
84
+ }
85
+ });
86
+ return conflicts;
87
+ }
88
+ function replaceRouteParamsWithSentinel(value) {
89
+ return value.split("/").map((segment) => getParamSegment(segment) ? "x" : segment).join("/");
90
+ }
91
+
92
+ export { RedirectRuleValidationError, findRedirectConflicts, redirectRuleSchema, redirectStatusSchema, reploRedirect };
@@ -0,0 +1,150 @@
1
+ // ../replo-utils/lib/string.ts
2
+ function slugify(text) {
3
+ return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
4
+ }
5
+
6
+ // ../replo-utils/lib/url.ts
7
+ function buildUrlSearchParams(values) {
8
+ const urlSearchParams = new URLSearchParams();
9
+ for (const [key, value] of Object.entries(values)) {
10
+ if (Array.isArray(value)) {
11
+ for (const item of value) {
12
+ urlSearchParams.append(key, item);
13
+ }
14
+ } else if (value !== void 0) {
15
+ urlSearchParams.set(key, String(value));
16
+ }
17
+ }
18
+ return urlSearchParams;
19
+ }
20
+ function isValidHttpUrl(url, options = {}) {
21
+ const validUrl = normalizeUrlIncludingProtocolRelative(url);
22
+ if (!validUrl) {
23
+ return false;
24
+ }
25
+ if (validUrl.protocol !== "http:" && validUrl.protocol !== "https:") {
26
+ return false;
27
+ }
28
+ if (options.allowBlockedHostnames === false && isBlockedHostname(validUrl.hostname)) {
29
+ return false;
30
+ }
31
+ if (options.allowedHostnames && !matchesAllowedHostname({
32
+ hostname: validUrl.hostname,
33
+ allowedHostnames: options.allowedHostnames
34
+ })) {
35
+ return false;
36
+ }
37
+ return true;
38
+ }
39
+ function matchesAllowedHostname({
40
+ hostname,
41
+ allowedHostnames
42
+ }) {
43
+ const normalized = hostname.toLowerCase();
44
+ return allowedHostnames.some((allowedHostname) => {
45
+ const normalizedAllowed = allowedHostname.toLowerCase();
46
+ return normalized === normalizedAllowed || normalized.endsWith(`.${normalizedAllowed}`);
47
+ });
48
+ }
49
+ function isBlockedHostname(hostname) {
50
+ const normalized = hostname.toLowerCase();
51
+ if (normalized === "localhost" || normalized.endsWith(".localhost")) {
52
+ return true;
53
+ }
54
+ if (/^(::1|fc[\da-f]{0,2}:|fd[\da-f]{0,2}:|fe80:)/.test(normalized) || normalized.startsWith("::ffff:")) {
55
+ return true;
56
+ }
57
+ const ipv4Match = /^(\d{1,3})\.(\d{1,3})/.exec(normalized);
58
+ if (ipv4Match) {
59
+ const first = Number(ipv4Match[1]);
60
+ const second = Number(ipv4Match[2]);
61
+ if (Number.isNaN(first) || Number.isNaN(second)) {
62
+ return true;
63
+ }
64
+ return first === 0 || first === 127 || first === 10 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 168 || first === 169 && second === 254;
65
+ }
66
+ return false;
67
+ }
68
+ function normalizeUrlIncludingProtocolRelative(url) {
69
+ let validUrl;
70
+ try {
71
+ validUrl = new URL(url);
72
+ } catch {
73
+ if (url.startsWith("//")) {
74
+ try {
75
+ validUrl = new URL(`https:${url}`);
76
+ } catch {
77
+ return null;
78
+ }
79
+ } else {
80
+ return null;
81
+ }
82
+ }
83
+ return validUrl;
84
+ }
85
+ function normalizeCustomDomain(input) {
86
+ return input.trim().replace(/^https?:\/\//i, "").replace(/\/.*$/, "").replace(/\.$/, "").toLowerCase();
87
+ }
88
+ var PREVIEW_INTERNAL_ORIGIN_RE = /^https:\/\/[\da-z-]+\.preview\.replointernal\.com$/;
89
+ var PREVIEW_INTERNAL_HOSTNAME_RE = /^[\da-z-]+\.preview\.replointernal\.com$/;
90
+ function isPreviewOrigin(origin) {
91
+ return PREVIEW_INTERNAL_ORIGIN_RE.test(origin);
92
+ }
93
+ function isPreviewInternalHostname(hostname) {
94
+ return PREVIEW_INTERNAL_HOSTNAME_RE.test(hostname);
95
+ }
96
+ function normalizeUrlScheme(url) {
97
+ return url.startsWith("//") ? `https:${url}` : url;
98
+ }
99
+ function truncateDomain(domain, maxLength = 60) {
100
+ if (domain.length <= maxLength) {
101
+ return domain;
102
+ }
103
+ const parts = domain.split(".");
104
+ if (parts.length < 2) {
105
+ return domain.length <= maxLength ? domain : `${domain.slice(0, maxLength - 3)}...`;
106
+ }
107
+ const mainDomainParts = parts.slice(-2);
108
+ const subdomainParts = parts.slice(0, -2);
109
+ const mainDomain = mainDomainParts.join(".");
110
+ if (mainDomain.length >= maxLength - 3) {
111
+ return `${mainDomain.slice(0, maxLength - 3)}...`;
112
+ }
113
+ const availableSpace = maxLength - mainDomain.length - 4;
114
+ if (subdomainParts.length === 0) {
115
+ return domain;
116
+ }
117
+ const subdomainString = subdomainParts.join(".");
118
+ if (subdomainString.length <= availableSpace) {
119
+ return domain;
120
+ }
121
+ const truncatedSubdomain = subdomainString.slice(
122
+ 0,
123
+ Math.max(1, availableSpace)
124
+ );
125
+ return `${truncatedSubdomain}...${mainDomain}`;
126
+ }
127
+ var isValidRoutePath = (path) => {
128
+ if (!path.startsWith("/")) {
129
+ return false;
130
+ }
131
+ const segments = path.slice(1).split("/");
132
+ if (segments.length === 1 && segments[0] === "") {
133
+ return true;
134
+ }
135
+ return segments.every((segment) => {
136
+ if (segment === "") {
137
+ return false;
138
+ }
139
+ return segment === slugify(segment) && segment.length > 0;
140
+ });
141
+ };
142
+ function parseUrl(value, base) {
143
+ try {
144
+ return new URL(value, base);
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+
150
+ export { buildUrlSearchParams, isPreviewInternalHostname, isPreviewOrigin, isValidHttpUrl, isValidRoutePath, normalizeCustomDomain, normalizeUrlIncludingProtocolRelative, normalizeUrlScheme, parseUrl, truncateDomain };