@uniformdev/redirect
Advanced tools
Comparing version 19.11.0 to 19.12.0
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __export = (target, all) => { | ||
@@ -18,10 +23,169 @@ for (var name in all) | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json | ||
var require_package = __commonJS({ | ||
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) { | ||
module2.exports = { | ||
name: "dotenv", | ||
version: "16.0.3", | ||
description: "Loads environment variables from .env file", | ||
main: "lib/main.js", | ||
types: "lib/main.d.ts", | ||
exports: { | ||
".": { | ||
require: "./lib/main.js", | ||
types: "./lib/main.d.ts", | ||
default: "./lib/main.js" | ||
}, | ||
"./config": "./config.js", | ||
"./config.js": "./config.js", | ||
"./lib/env-options": "./lib/env-options.js", | ||
"./lib/env-options.js": "./lib/env-options.js", | ||
"./lib/cli-options": "./lib/cli-options.js", | ||
"./lib/cli-options.js": "./lib/cli-options.js", | ||
"./package.json": "./package.json" | ||
}, | ||
scripts: { | ||
"dts-check": "tsc --project tests/types/tsconfig.json", | ||
lint: "standard", | ||
"lint-readme": "standard-markdown", | ||
pretest: "npm run lint && npm run dts-check", | ||
test: "tap tests/*.js --100 -Rspec", | ||
prerelease: "npm test", | ||
release: "standard-version" | ||
}, | ||
repository: { | ||
type: "git", | ||
url: "git://github.com/motdotla/dotenv.git" | ||
}, | ||
keywords: [ | ||
"dotenv", | ||
"env", | ||
".env", | ||
"environment", | ||
"variables", | ||
"config", | ||
"settings" | ||
], | ||
readmeFilename: "README.md", | ||
license: "BSD-2-Clause", | ||
devDependencies: { | ||
"@types/node": "^17.0.9", | ||
decache: "^4.6.1", | ||
dtslint: "^3.7.0", | ||
sinon: "^12.0.1", | ||
standard: "^16.0.4", | ||
"standard-markdown": "^7.1.0", | ||
"standard-version": "^9.3.2", | ||
tap: "^15.1.6", | ||
tar: "^6.1.11", | ||
typescript: "^4.5.4" | ||
}, | ||
engines: { | ||
node: ">=12" | ||
} | ||
}; | ||
} | ||
}); | ||
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js | ||
var require_main = __commonJS({ | ||
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) { | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var os = require("os"); | ||
var packageJson = require_package(); | ||
var version = packageJson.version; | ||
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg; | ||
function parse(src) { | ||
const obj = {}; | ||
let lines = src.toString(); | ||
lines = lines.replace(/\r\n?/mg, "\n"); | ||
let match; | ||
while ((match = LINE.exec(lines)) != null) { | ||
const key = match[1]; | ||
let value = match[2] || ""; | ||
value = value.trim(); | ||
const maybeQuote = value[0]; | ||
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"); | ||
if (maybeQuote === '"') { | ||
value = value.replace(/\\n/g, "\n"); | ||
value = value.replace(/\\r/g, "\r"); | ||
} | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _log(message) { | ||
console.log(`[dotenv@${version}][DEBUG] ${message}`); | ||
} | ||
function _resolveHome(envPath) { | ||
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath; | ||
} | ||
function config(options) { | ||
let dotenvPath = path.resolve(process.cwd(), ".env"); | ||
let encoding = "utf8"; | ||
const debug = Boolean(options && options.debug); | ||
const override = Boolean(options && options.override); | ||
if (options) { | ||
if (options.path != null) { | ||
dotenvPath = _resolveHome(options.path); | ||
} | ||
if (options.encoding != null) { | ||
encoding = options.encoding; | ||
} | ||
} | ||
try { | ||
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding })); | ||
Object.keys(parsed).forEach(function(key) { | ||
if (!Object.prototype.hasOwnProperty.call(process.env, key)) { | ||
process.env[key] = parsed[key]; | ||
} else { | ||
if (override === true) { | ||
process.env[key] = parsed[key]; | ||
} | ||
if (debug) { | ||
if (override === true) { | ||
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`); | ||
} else { | ||
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`); | ||
} | ||
} | ||
} | ||
}); | ||
return { parsed }; | ||
} catch (e) { | ||
if (debug) { | ||
_log(`Failed to load ${dotenvPath} ${e.message}`); | ||
} | ||
return { error: e }; | ||
} | ||
} | ||
var DotenvModule = { | ||
config, | ||
parse | ||
}; | ||
module2.exports.config = DotenvModule.config; | ||
module2.exports.parse = DotenvModule.parse; | ||
module2.exports = DotenvModule; | ||
} | ||
}); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ExtractWildcards: () => ExtractWildcards, | ||
PathTrie: () => PathTrie, | ||
PathTrieData: () => PathTrieData, | ||
RedirectClient: () => RedirectClient, | ||
RedirectFileConverter: () => RedirectFileConverter, | ||
UncachedRedirectClient: () => UncachedRedirectClient, | ||
@@ -149,2 +313,3 @@ WithMemoryCache: () => WithMemoryCache | ||
const ret = []; | ||
const splats = []; | ||
const processed = /* @__PURE__ */ new Set(); | ||
@@ -181,2 +346,10 @@ const getVariables = () => { | ||
const segment = segments[i]; | ||
if (Object.hasOwn(cur, "*")) { | ||
cur["*"][dataProp].forEach((splat) => { | ||
splats.push({ | ||
data: splat, | ||
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }] | ||
}); | ||
}); | ||
} | ||
getPropsStartingWithColon(cur).forEach((wildcard) => { | ||
@@ -203,3 +376,3 @@ if (!processed.has(wildcard)) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
@@ -214,9 +387,9 @@ if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
} | ||
if (ret.length > 0 && bestMatch) | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
@@ -514,9 +687,84 @@ }; | ||
}; | ||
// src/util/RedirectFileConverter.ts | ||
var getDefaultClient = async () => { | ||
const dotenv = await Promise.resolve().then(() => __toESM(require_main())); | ||
dotenv.config(); | ||
return new RedirectClient({ | ||
apiKey: process.env.UNIFORM_API_KEY, | ||
apiHost: process.env.UNIFORM_BASE_URL, | ||
projectId: process.env.UNIFORM_PROJECT_ID | ||
}); | ||
}; | ||
function ExtractWildcards(url) { | ||
let last = ""; | ||
let wildcardStart = -1; | ||
const terminators = ["/", "?", "&", "#"]; | ||
const ret = []; | ||
for (let i = 0; i < url.length; i++) { | ||
const cur = url.charAt(i); | ||
if (terminators.includes(last) && cur === ":") { | ||
wildcardStart = i; | ||
} | ||
if (terminators.includes(cur) && wildcardStart !== -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) }); | ||
wildcardStart = -1; | ||
} | ||
last = cur; | ||
} | ||
if (wildcardStart > -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) }); | ||
} | ||
if (last === "*") { | ||
ret.push({ index: url.length, pathSegment: "*" }); | ||
} | ||
return ret; | ||
} | ||
async function RedirectFileConverter({ | ||
client, | ||
redirectEntryObject, | ||
wildcardConverter = (s) => s, | ||
writeFile | ||
}) { | ||
if (!client) { | ||
client = await getDefaultClient(); | ||
} | ||
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects; | ||
let count = 0; | ||
const ret = []; | ||
while (redirects.length) { | ||
const redirect = redirects.pop(); | ||
if (redirect == null ? void 0 : redirect.redirect) { | ||
const st = wildcardConverter({ | ||
...redirect.redirect, | ||
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl), | ||
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl) | ||
}); | ||
ret.push( | ||
redirectEntryObject({ | ||
metadata: redirect.metadata, | ||
redirect: { | ||
...redirect.redirect, | ||
sourceUrl: st.sourceUrl, | ||
targetUrl: st.targetUrl | ||
} | ||
}) | ||
); | ||
} | ||
if (!redirects.length) { | ||
count++; | ||
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects; | ||
} | ||
} | ||
writeFile(ret); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ExtractWildcards, | ||
PathTrie, | ||
PathTrieData, | ||
RedirectClient, | ||
RedirectFileConverter, | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
}); |
@@ -345,2 +345,5 @@ import { ClientOptions, ApiClient } from '@uniformdev/context/api'; | ||
type RedirectDefinition = RedirectGetResponse['redirects'][0]; | ||
type RedirectDefinitions = { | ||
redirects: RedirectDefinition['redirect'][]; | ||
}; | ||
type RedirectResult = { | ||
@@ -370,2 +373,23 @@ url: string; | ||
export { PathTrie, PathTrieData, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDeleteRequest, RedirectDeleteResponse, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, UncachedRedirectClient, WithMemoryCache, pathTrieReturn }; | ||
type Wildcard = { | ||
pathSegment: string; | ||
index: number; | ||
}; | ||
type SourceAndTarget = { | ||
sourceUrl: string; | ||
targetUrl: string; | ||
}; | ||
type SourceTargetAndWildcards = SourceAndTarget & { | ||
sourceWildcards: Wildcard[]; | ||
targetWildcards: Wildcard[]; | ||
}; | ||
type RedirectFileConverterParams<T> = { | ||
client?: RedirectClient; | ||
redirectEntryObject: (redirect: RedirectDefinition) => T; | ||
wildcardConverter?: (sourceTarget: SourceTargetAndWildcards) => SourceAndTarget; | ||
writeFile: (redirects: T[]) => void; | ||
}; | ||
declare function ExtractWildcards(url: string): Wildcard[]; | ||
declare function RedirectFileConverter<T>({ client, redirectEntryObject, wildcardConverter, writeFile, }: RedirectFileConverterParams<T>): Promise<void>; | ||
export { ExtractWildcards, PathTrie, PathTrieData, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn }; |
@@ -0,1 +1,3 @@ | ||
import "./chunk-FFYIGW52.mjs"; | ||
// src/cache/redirectClientCache.ts | ||
@@ -118,2 +120,3 @@ var RedirectClientCache = class { | ||
const ret = []; | ||
const splats = []; | ||
const processed = /* @__PURE__ */ new Set(); | ||
@@ -150,2 +153,10 @@ const getVariables = () => { | ||
const segment = segments[i]; | ||
if (Object.hasOwn(cur, "*")) { | ||
cur["*"][dataProp].forEach((splat) => { | ||
splats.push({ | ||
data: splat, | ||
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }] | ||
}); | ||
}); | ||
} | ||
getPropsStartingWithColon(cur).forEach((wildcard) => { | ||
@@ -172,3 +183,3 @@ if (!processed.has(wildcard)) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
@@ -183,9 +194,9 @@ if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
} | ||
if (ret.length > 0 && bestMatch) | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
@@ -483,8 +494,83 @@ }; | ||
}; | ||
// src/util/RedirectFileConverter.ts | ||
var getDefaultClient = async () => { | ||
const dotenv = await import("./main-NHOL4NFR.mjs"); | ||
dotenv.config(); | ||
return new RedirectClient({ | ||
apiKey: process.env.UNIFORM_API_KEY, | ||
apiHost: process.env.UNIFORM_BASE_URL, | ||
projectId: process.env.UNIFORM_PROJECT_ID | ||
}); | ||
}; | ||
function ExtractWildcards(url) { | ||
let last = ""; | ||
let wildcardStart = -1; | ||
const terminators = ["/", "?", "&", "#"]; | ||
const ret = []; | ||
for (let i = 0; i < url.length; i++) { | ||
const cur = url.charAt(i); | ||
if (terminators.includes(last) && cur === ":") { | ||
wildcardStart = i; | ||
} | ||
if (terminators.includes(cur) && wildcardStart !== -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) }); | ||
wildcardStart = -1; | ||
} | ||
last = cur; | ||
} | ||
if (wildcardStart > -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) }); | ||
} | ||
if (last === "*") { | ||
ret.push({ index: url.length, pathSegment: "*" }); | ||
} | ||
return ret; | ||
} | ||
async function RedirectFileConverter({ | ||
client, | ||
redirectEntryObject, | ||
wildcardConverter = (s) => s, | ||
writeFile | ||
}) { | ||
if (!client) { | ||
client = await getDefaultClient(); | ||
} | ||
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects; | ||
let count = 0; | ||
const ret = []; | ||
while (redirects.length) { | ||
const redirect = redirects.pop(); | ||
if (redirect == null ? void 0 : redirect.redirect) { | ||
const st = wildcardConverter({ | ||
...redirect.redirect, | ||
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl), | ||
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl) | ||
}); | ||
ret.push( | ||
redirectEntryObject({ | ||
metadata: redirect.metadata, | ||
redirect: { | ||
...redirect.redirect, | ||
sourceUrl: st.sourceUrl, | ||
targetUrl: st.targetUrl | ||
} | ||
}) | ||
); | ||
} | ||
if (!redirects.length) { | ||
count++; | ||
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects; | ||
} | ||
} | ||
writeFile(ret); | ||
} | ||
export { | ||
ExtractWildcards, | ||
PathTrie, | ||
PathTrieData, | ||
RedirectClient, | ||
RedirectFileConverter, | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
}; |
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __export = (target, all) => { | ||
@@ -18,10 +23,169 @@ for (var name in all) | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json | ||
var require_package = __commonJS({ | ||
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) { | ||
module2.exports = { | ||
name: "dotenv", | ||
version: "16.0.3", | ||
description: "Loads environment variables from .env file", | ||
main: "lib/main.js", | ||
types: "lib/main.d.ts", | ||
exports: { | ||
".": { | ||
require: "./lib/main.js", | ||
types: "./lib/main.d.ts", | ||
default: "./lib/main.js" | ||
}, | ||
"./config": "./config.js", | ||
"./config.js": "./config.js", | ||
"./lib/env-options": "./lib/env-options.js", | ||
"./lib/env-options.js": "./lib/env-options.js", | ||
"./lib/cli-options": "./lib/cli-options.js", | ||
"./lib/cli-options.js": "./lib/cli-options.js", | ||
"./package.json": "./package.json" | ||
}, | ||
scripts: { | ||
"dts-check": "tsc --project tests/types/tsconfig.json", | ||
lint: "standard", | ||
"lint-readme": "standard-markdown", | ||
pretest: "npm run lint && npm run dts-check", | ||
test: "tap tests/*.js --100 -Rspec", | ||
prerelease: "npm test", | ||
release: "standard-version" | ||
}, | ||
repository: { | ||
type: "git", | ||
url: "git://github.com/motdotla/dotenv.git" | ||
}, | ||
keywords: [ | ||
"dotenv", | ||
"env", | ||
".env", | ||
"environment", | ||
"variables", | ||
"config", | ||
"settings" | ||
], | ||
readmeFilename: "README.md", | ||
license: "BSD-2-Clause", | ||
devDependencies: { | ||
"@types/node": "^17.0.9", | ||
decache: "^4.6.1", | ||
dtslint: "^3.7.0", | ||
sinon: "^12.0.1", | ||
standard: "^16.0.4", | ||
"standard-markdown": "^7.1.0", | ||
"standard-version": "^9.3.2", | ||
tap: "^15.1.6", | ||
tar: "^6.1.11", | ||
typescript: "^4.5.4" | ||
}, | ||
engines: { | ||
node: ">=12" | ||
} | ||
}; | ||
} | ||
}); | ||
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js | ||
var require_main = __commonJS({ | ||
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) { | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var os = require("os"); | ||
var packageJson = require_package(); | ||
var version = packageJson.version; | ||
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg; | ||
function parse(src) { | ||
const obj = {}; | ||
let lines = src.toString(); | ||
lines = lines.replace(/\r\n?/mg, "\n"); | ||
let match; | ||
while ((match = LINE.exec(lines)) != null) { | ||
const key = match[1]; | ||
let value = match[2] || ""; | ||
value = value.trim(); | ||
const maybeQuote = value[0]; | ||
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"); | ||
if (maybeQuote === '"') { | ||
value = value.replace(/\\n/g, "\n"); | ||
value = value.replace(/\\r/g, "\r"); | ||
} | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _log(message) { | ||
console.log(`[dotenv@${version}][DEBUG] ${message}`); | ||
} | ||
function _resolveHome(envPath) { | ||
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath; | ||
} | ||
function config(options) { | ||
let dotenvPath = path.resolve(process.cwd(), ".env"); | ||
let encoding = "utf8"; | ||
const debug = Boolean(options && options.debug); | ||
const override = Boolean(options && options.override); | ||
if (options) { | ||
if (options.path != null) { | ||
dotenvPath = _resolveHome(options.path); | ||
} | ||
if (options.encoding != null) { | ||
encoding = options.encoding; | ||
} | ||
} | ||
try { | ||
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding })); | ||
Object.keys(parsed).forEach(function(key) { | ||
if (!Object.prototype.hasOwnProperty.call(process.env, key)) { | ||
process.env[key] = parsed[key]; | ||
} else { | ||
if (override === true) { | ||
process.env[key] = parsed[key]; | ||
} | ||
if (debug) { | ||
if (override === true) { | ||
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`); | ||
} else { | ||
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`); | ||
} | ||
} | ||
} | ||
}); | ||
return { parsed }; | ||
} catch (e) { | ||
if (debug) { | ||
_log(`Failed to load ${dotenvPath} ${e.message}`); | ||
} | ||
return { error: e }; | ||
} | ||
} | ||
var DotenvModule = { | ||
config, | ||
parse | ||
}; | ||
module2.exports.config = DotenvModule.config; | ||
module2.exports.parse = DotenvModule.parse; | ||
module2.exports = DotenvModule; | ||
} | ||
}); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ExtractWildcards: () => ExtractWildcards, | ||
PathTrie: () => PathTrie, | ||
PathTrieData: () => PathTrieData, | ||
RedirectClient: () => RedirectClient, | ||
RedirectFileConverter: () => RedirectFileConverter, | ||
UncachedRedirectClient: () => UncachedRedirectClient, | ||
@@ -149,2 +313,3 @@ WithMemoryCache: () => WithMemoryCache | ||
const ret = []; | ||
const splats = []; | ||
const processed = /* @__PURE__ */ new Set(); | ||
@@ -181,2 +346,10 @@ const getVariables = () => { | ||
const segment = segments[i]; | ||
if (Object.hasOwn(cur, "*")) { | ||
cur["*"][dataProp].forEach((splat) => { | ||
splats.push({ | ||
data: splat, | ||
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }] | ||
}); | ||
}); | ||
} | ||
getPropsStartingWithColon(cur).forEach((wildcard) => { | ||
@@ -203,3 +376,3 @@ if (!processed.has(wildcard)) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
@@ -214,9 +387,9 @@ if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) { | ||
if (typeof more === "undefined") | ||
return ret; | ||
return [...ret, ...splats]; | ||
i = more; | ||
} | ||
if (ret.length > 0 && bestMatch) | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
return ret; | ||
return [...ret, ...splats]; | ||
} | ||
@@ -514,9 +687,84 @@ }; | ||
}; | ||
// src/util/RedirectFileConverter.ts | ||
var getDefaultClient = async () => { | ||
const dotenv = await Promise.resolve().then(() => __toESM(require_main())); | ||
dotenv.config(); | ||
return new RedirectClient({ | ||
apiKey: process.env.UNIFORM_API_KEY, | ||
apiHost: process.env.UNIFORM_BASE_URL, | ||
projectId: process.env.UNIFORM_PROJECT_ID | ||
}); | ||
}; | ||
function ExtractWildcards(url) { | ||
let last = ""; | ||
let wildcardStart = -1; | ||
const terminators = ["/", "?", "&", "#"]; | ||
const ret = []; | ||
for (let i = 0; i < url.length; i++) { | ||
const cur = url.charAt(i); | ||
if (terminators.includes(last) && cur === ":") { | ||
wildcardStart = i; | ||
} | ||
if (terminators.includes(cur) && wildcardStart !== -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) }); | ||
wildcardStart = -1; | ||
} | ||
last = cur; | ||
} | ||
if (wildcardStart > -1) { | ||
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) }); | ||
} | ||
if (last === "*") { | ||
ret.push({ index: url.length, pathSegment: "*" }); | ||
} | ||
return ret; | ||
} | ||
async function RedirectFileConverter({ | ||
client, | ||
redirectEntryObject, | ||
wildcardConverter = (s) => s, | ||
writeFile | ||
}) { | ||
if (!client) { | ||
client = await getDefaultClient(); | ||
} | ||
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects; | ||
let count = 0; | ||
const ret = []; | ||
while (redirects.length) { | ||
const redirect = redirects.pop(); | ||
if (redirect == null ? void 0 : redirect.redirect) { | ||
const st = wildcardConverter({ | ||
...redirect.redirect, | ||
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl), | ||
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl) | ||
}); | ||
ret.push( | ||
redirectEntryObject({ | ||
metadata: redirect.metadata, | ||
redirect: { | ||
...redirect.redirect, | ||
sourceUrl: st.sourceUrl, | ||
targetUrl: st.targetUrl | ||
} | ||
}) | ||
); | ||
} | ||
if (!redirects.length) { | ||
count++; | ||
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects; | ||
} | ||
} | ||
writeFile(ret); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ExtractWildcards, | ||
PathTrie, | ||
PathTrieData, | ||
RedirectClient, | ||
RedirectFileConverter, | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
}); |
{ | ||
"name": "@uniformdev/redirect", | ||
"version": "19.11.0", | ||
"version": "19.12.0", | ||
"description": "Uniform redirect client", | ||
@@ -35,3 +35,3 @@ "license": "SEE LICENSE IN LICENSE.txt", | ||
"dependencies": { | ||
"@uniformdev/context": "19.11.0", | ||
"@uniformdev/context": "19.12.0", | ||
"p-limit": "^3.1.0" | ||
@@ -42,3 +42,3 @@ }, | ||
}, | ||
"gitHead": "25d492fe923f313b517cbc70d3ff13fdcf97fa34" | ||
"gitHead": "ca508c44f1b274e3e47d90717a98036256ae8379" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121473
10
3205
27
+ Added@uniformdev/context@19.12.0(transitive)
- Removed@uniformdev/context@19.11.0(transitive)
Updated@uniformdev/context@19.12.0