@endo/where
Advanced tools
Comparing version 0.2.11 to 0.3.0
131
index.js
// @ts-check | ||
/* Infers the rendezvous path for the endo.sock file and apps from the platform | ||
* and environment. | ||
*/ | ||
const { raw } = String; | ||
/** | ||
* @param {{[name: string]: string}} env | ||
* Returns a path for local Endo application user data on Windows. | ||
* | ||
* @param {{[name: string]: string | undefined}} env | ||
* @param {import('./types.js').Info} info | ||
*/ | ||
const whereEndoStateWindows = env => { | ||
const whereHomeWindows = (env, info) => { | ||
// Favoring local app data over roaming app data since I don't expect to be | ||
// able to listen on one host and connect on another. | ||
// TODO support roaming data for shared content addressable state and | ||
// find a suitable mechanism for merging state that may change independently | ||
// on separate roaming hosts. | ||
if (env.LOCALAPPDATA !== undefined) { | ||
return `${env.LOCALAPPDATA}\\Endo`; | ||
return `${env.LOCALAPPDATA}`; | ||
} | ||
if (env.APPDATA !== undefined) { | ||
return `${env.APPDATA}\\Endo`; | ||
return `${env.APPDATA}\\Local`; | ||
} | ||
if (env.USERPROFILE !== undefined) { | ||
return `${env.USERPROFILE}\\AppData\\Endo`; | ||
return `${env.USERPROFILE}\\AppData\\Local`; | ||
} | ||
if (env.HOMEDRIVE !== undefined && env.HOMEPATH !== undefined) { | ||
return `${env.HOMEDRIVE}${env.HOMEPATH}\\AppData\\Endo`; | ||
return `${env.HOMEDRIVE}${env.HOMEPATH}\\AppData\\Local`; | ||
} | ||
return '.'; | ||
return `${info.home}\\AppData\\Local`; | ||
}; | ||
/** | ||
* Returns the most suitable path for Endo state with this platform and | ||
* environment. | ||
* Endo uses the state directory for saved files including applications, | ||
* durable capabilities, and the user's pet names for them. | ||
* Endo also logs here, per XDG's preference to persist logs even when caches | ||
* are purged. | ||
* | ||
* @type {typeof import('./types.js').whereEndoState} | ||
*/ | ||
export const whereEndoState = (platform, env) => { | ||
if (platform === 'win32') { | ||
return whereEndoStateWindows(env); | ||
} else if (platform === 'darwin') { | ||
if (env.HOME !== undefined) { | ||
return `${env.HOME}/Library/Application Support/Endo`; | ||
export const whereEndoState = (platform, env, info) => { | ||
if (env.XDG_STATE_HOME !== undefined) { | ||
return `${env.XDG_STATE_HOME}/endo`; | ||
} else if (platform === 'win32') { | ||
return `${whereHomeWindows(env, info)}\\Endo`; | ||
} | ||
const home = env.HOME !== undefined ? env.HOME : info.home; | ||
if (platform === 'darwin') { | ||
if (home !== undefined) { | ||
return `${home}/Library/Application Support/Endo`; | ||
} | ||
} else { | ||
if (env.XDG_CONFIG_DIR !== undefined) { | ||
return `${env.XDG_CONFIG_DIR}/endo`; | ||
} | ||
if (env.HOME !== undefined) { | ||
return `${env.HOME}/.config/endo`; | ||
} | ||
} | ||
return 'endo'; | ||
return `${home}/.local/state/endo`; | ||
}; | ||
/** | ||
* Returns the most suitable location for storing state that ideally does not | ||
* persist between restarts or reboots, specifically PID files. | ||
* | ||
* @type {typeof import('./types.js').whereEndoEphemeralState} | ||
*/ | ||
export const whereEndoEphemeralState = (platform, env, info) => { | ||
if (env.XDG_RUNTIME_DIR !== undefined) { | ||
return `${env.XDG_RUNTIME_DIR}/endo`; | ||
} else if (platform === 'win32') { | ||
return `${whereHomeWindows(env, info)}\\Temp\\Endo`; | ||
} | ||
const temp = env.TMPDIR !== undefined ? env.TMPDIR : info.temp; | ||
const user = env.USER !== undefined ? env.USER : info.user; | ||
return `${temp}/endo-${user}`; | ||
}; | ||
/** | ||
* Returns the most suitable path for the Endo UNIX domain socket or Windows | ||
* named pipe. | ||
* | ||
* @type {typeof import('./types.js').whereEndoSock} | ||
*/ | ||
export const whereEndoSock = (platform, env) => { | ||
if (platform === 'win32') { | ||
export const whereEndoSock = (platform, env, info, protocol = 'captp0') => { | ||
// It must be possible to override the socket or named pipe location, but we | ||
// cannot use XDG_RUNTIME_DIR for Windows named pipes, so for this case, we | ||
// invent our own environment variable. | ||
if (env.ENDO_SOCK !== undefined) { | ||
return env.ENDO_SOCK; | ||
} else if (platform === 'win32') { | ||
// Named pipes have a special place in Windows (and in our ashen hearts). | ||
if (env.USERNAME !== undefined) { | ||
return `\\\\?\\pipe\\${env.USERNAME}-Endo\\endo.pipe`; | ||
} else { | ||
return raw`\\?\pipe\Endo\endo.pipe`; | ||
} | ||
const user = env.USERNAME !== undefined ? env.USERNAME : info.user; | ||
return `\\\\?\\pipe\\${user}-Endo\\${protocol}.pipe`; | ||
} else if (env.XDG_RUNTIME_DIR !== undefined) { | ||
return `${env.XDG_RUNTIME_DIR}/endo/${protocol}.sock`; | ||
} else if (platform === 'darwin') { | ||
if (env.HOME !== undefined) { | ||
return `${env.HOME}/Library/Application Support/Endo/endo.sock`; | ||
} | ||
} else if (env.XDG_RUNTIME_DIR !== undefined) { | ||
return `${env.XDG_RUNTIME_DIR}/endo/endo.sock`; | ||
} else if (env.USER !== undefined) { | ||
return `/tmp/endo-${env.USER}/endo.sock`; | ||
const home = env.HOME !== undefined ? env.HOME : info.home; | ||
return `${home}/Library/Application Support/Endo/${protocol}.sock`; | ||
} | ||
return 'endo.sock'; | ||
const user = env.USER !== undefined ? env.USER : info.user; | ||
const temp = env.TMPDIR !== undefined ? env.TMPDIR : info.temp; | ||
return `${temp}/endo-${user}/${protocol}.sock`; | ||
}; | ||
/** | ||
* Returns the most suitable path for Endo caches. | ||
* | ||
* @type {typeof import('./types.js').whereEndoCache} | ||
*/ | ||
export const whereEndoCache = (platform, env) => { | ||
if (platform === 'win32') { | ||
return `${whereEndoStateWindows(env)}`; | ||
export const whereEndoCache = (platform, env, info) => { | ||
if (env.XDG_CACHE_HOME !== undefined) { | ||
return `${env.XDG_CACHE_HOME}/endo`; | ||
} else if (platform === 'win32') { | ||
return `${whereHomeWindows(env, info)}\\Endo`; | ||
} else if (platform === 'darwin') { | ||
if (env.HOME !== undefined) { | ||
return `${env.HOME}/Library/Caches/Endo`; | ||
} | ||
} else if (env.XDG_CACHE_HOME !== undefined) { | ||
return `${env.XDG_CACHE_HOME}/endo`; | ||
} else if (env.HOME !== undefined) { | ||
return `${env.HOME}/.cache/endo`; | ||
const home = env.HOME !== undefined ? env.HOME : info.home; | ||
return `${home}/Library/Caches/Endo`; | ||
} | ||
return ''; | ||
const home = env.HOME !== undefined ? env.HOME : info.home; | ||
return `${home}/.cache/endo`; | ||
}; |
{ | ||
"name": "@endo/where", | ||
"version": "0.2.11", | ||
"version": "0.3.0", | ||
"private": null, | ||
@@ -9,3 +9,3 @@ "description": "Description forthcoming.", | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/endojs/endo/tree/master/packages/where#readme", | ||
"homepage": "https://github.com/endojs/endo/blob/master/packages/where/README.md", | ||
"repository": { | ||
@@ -23,3 +23,3 @@ "type": "git", | ||
"unpkg": null, | ||
"types": "./index.d.ts", | ||
"types": "./types.d.ts", | ||
"exports": { | ||
@@ -39,4 +39,4 @@ ".": "./index.js", | ||
"devDependencies": { | ||
"@endo/eslint-config": "^0.5.2", | ||
"ava": "^5.1.0", | ||
"@endo/eslint-config": "^0.5.3", | ||
"ava": "^5.2.0", | ||
"babel-eslint": "^10.0.3", | ||
@@ -48,6 +48,6 @@ "c8": "^7.7.3", | ||
"eslint-plugin-eslint-comments": "^3.1.2", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^3.4.1", | ||
"prettier": "^2.8.0", | ||
"typescript": "~4.8.4" | ||
"typescript": "~4.9.5" | ||
}, | ||
@@ -80,3 +80,3 @@ "files": [ | ||
}, | ||
"gitHead": "ab8d64ae6fc9c628a2d1c02d16bf9ef249f5c8dc" | ||
"gitHead": "0053227a37ee76ee8a3dce6059dd55140ed0ce6d" | ||
} |
@@ -7,1 +7,10 @@ # Where is Endo? | ||
including logs and other application storage. | ||
Endo attempts to use or infer [Cross-desktop XDG conventions][XDG] paths in | ||
every meaningful way. | ||
Windows named pipes do not appear to fit this model. | ||
Otherwise falls back to the native conventions on Windows and Mac/Darwin. | ||
On Windows, Endo does not use separate state and cache directories and does not | ||
yet sync state between home directories. | ||
[XDG]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html |
@@ -13,3 +13,3 @@ # Security Policy | ||
* Reporting the issue to the [Agoric HackerOne vulnerability rewards program](hackerone.com/agoric). | ||
* Reporting the issue to the [Agoric HackerOne vulnerability rewards program](https://hackerone.com/agoric). | ||
@@ -16,0 +16,0 @@ * Sending an email to security at (@) agoric.com., encrypted or unencrypted. To encrypt, please use @Warner’s personal GPG key [A476E2E6 11880C98 5B3C3A39 0386E81B 11CAA07A](http://www.lothar.com/warner-gpg.html) . |
@@ -0,12 +1,27 @@ | ||
export type Info = { | ||
home: string; | ||
user: string; | ||
temp: string; | ||
}; | ||
export function whereEndoState( | ||
platform: string, | ||
env: { [name: string]: string }, | ||
env: { [name: string]: string | undefined }, | ||
info: Info, | ||
): string; | ||
export function whereEndoEphemeralState( | ||
platform: string, | ||
env: { [name: string]: string | undefined }, | ||
info: Info, | ||
): string; | ||
export function whereEndoSock( | ||
platform: string, | ||
env: { [name: string]: string }, | ||
env: { [name: string]: string | undefined }, | ||
info: Info, | ||
protocol?: string, | ||
): string; | ||
export function whereEndoCache( | ||
platform: string, | ||
env: { [name: string]: string }, | ||
env: { [name: string]: string | undefined }, | ||
info: Info, | ||
): string; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
22320
136
16
6
1