@lerna/otplease
Advanced tools
Comparing version 3.18.5 to 4.0.0
@@ -6,2 +6,29 @@ # Change Log | ||
# [4.0.0](https://github.com/lerna/lerna/compare/v3.22.1...v4.0.0) (2021-02-10) | ||
### Features | ||
* Consume named exports of sibling modules ([63499e3](https://github.com/lerna/lerna/commit/63499e33652bc78fe23751875d74017e2f16a689)) | ||
* Drop support for Node v6.x & v8.x ([ff4bb4d](https://github.com/lerna/lerna/commit/ff4bb4da215555e3bb136f5af09b5cbc631e57bb)) | ||
* Expose named export ([c1303f1](https://github.com/lerna/lerna/commit/c1303f13adc4cf15f96ff25889b52149f8224c0e)) | ||
* Remove default export ([e2f1ec3](https://github.com/lerna/lerna/commit/e2f1ec3dd049d2a89880029908a2aa7c66f15082)) | ||
* **otplease:** Remove figgy-pudding ([45ee52e](https://github.com/lerna/lerna/commit/45ee52e010cfd98fdcddf43f6bfc9cd11b4a3aa0)) | ||
### BREAKING CHANGES | ||
* The default export has been removed, please use a named export instead. | ||
* Node v6.x & v8.x are no longer supported. Please upgrade to the latest LTS release. | ||
Here's the gnarly one-liner I used to make these changes: | ||
``` | ||
npx lerna exec --concurrency 1 --stream -- 'json -I -f package.json -e '"'"'this.engines=this.engines||{};this.engines.node=">= 10.18.0"'"'" | ||
``` | ||
(requires `npm i -g json` beforehand) | ||
## [3.18.5](https://github.com/lerna/lerna/compare/v3.18.4...v3.18.5) (2019-11-20) | ||
@@ -8,0 +35,0 @@ |
"use strict"; | ||
const figgyPudding = require("figgy-pudding"); | ||
const prompt = require("@lerna/prompt"); | ||
const { promptTextInput } = require("@lerna/prompt"); | ||
const OtpPleaseConfig = figgyPudding({ | ||
otp: {}, | ||
}); | ||
/** | ||
* @typedef {object} OneTimePasswordCache - Passed between concurrent executions | ||
* @property {string} [otp] The one-time password, passed as an option or received via prompt | ||
*/ | ||
@@ -13,6 +13,6 @@ // basic single-entry semaphore | ||
wait() { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
if (!this._promise) { | ||
// not waiting, block other callers until 'release' is called. | ||
this._promise = new Promise(release => { | ||
this._promise = new Promise((release) => { | ||
this._resolve = release; | ||
@@ -39,16 +39,23 @@ }); | ||
module.exports = otplease; | ||
module.exports.otplease = otplease; | ||
module.exports.getOneTimePassword = getOneTimePassword; | ||
/** | ||
* Attempt to execute Promise callback, prompting for OTP if necessary. | ||
* @template {Record<string, unknown>} T | ||
* @param {(opts: T) => Promise<unknown>} fn | ||
* @param {T} _opts The options to be passed to `fn` | ||
* @param {OneTimePasswordCache} otpCache | ||
*/ | ||
function otplease(fn, _opts, otpCache) { | ||
// NOTE: do not use 'otpCache' as a figgy-pudding provider directly as the | ||
// otp value could change between async wait points. | ||
const opts = OtpPleaseConfig(Object.assign({}, otpCache), _opts); | ||
// always prefer explicit config (if present) to cache | ||
const opts = { ...otpCache, ..._opts }; | ||
return attempt(fn, opts, otpCache); | ||
} | ||
/** @returns {Promise<unknown>} */ | ||
function attempt(fn, opts, otpCache) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
resolve(fn(opts)); | ||
}).catch(err => { | ||
}).catch((err) => { | ||
if (err.code !== "EOTP" && !(err.code === "E401" && /one-time pass/.test(err.body))) { | ||
@@ -61,3 +68,3 @@ throw err; | ||
if (otpCache != null && otpCache.otp != null && otpCache.otp !== opts.otp) { | ||
return attempt(fn, opts.concat(otpCache), otpCache); | ||
return attempt(fn, { ...opts, ...otpCache }, otpCache); | ||
} | ||
@@ -70,7 +77,7 @@ // only allow one getOneTimePassword attempt at a time to reuse the value | ||
semaphore.release(); | ||
return attempt(fn, opts.concat({ otp: otpCache.otp }), otpCache); | ||
return attempt(fn, { ...opts, ...otpCache }, otpCache); | ||
} | ||
return getOneTimePassword() | ||
.then( | ||
otp => { | ||
(otp) => { | ||
// update the otp and release the lock so that waiting | ||
@@ -85,3 +92,3 @@ // callers can see the updated otp. | ||
}, | ||
promptError => { | ||
(promptError) => { | ||
// release the lock and reject the promise. | ||
@@ -92,4 +99,4 @@ semaphore.release(); | ||
) | ||
.then(otp => { | ||
return fn(opts.concat({ otp })); | ||
.then((otp) => { | ||
return fn({ ...opts, otp }); | ||
}); | ||
@@ -101,7 +108,11 @@ }); | ||
/** | ||
* Prompt user for one-time password. | ||
* @returns {Promise<string>} | ||
*/ | ||
function getOneTimePassword(message = "This operation requires a one-time password:") { | ||
// Logic taken from npm internals: https://git.io/fNoMe | ||
return prompt.input(message, { | ||
filter: otp => otp.replace(/\s+/g, ""), | ||
validate: otp => | ||
return promptTextInput(message, { | ||
filter: (otp) => otp.replace(/\s+/g, ""), | ||
validate: (otp) => | ||
(otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) || | ||
@@ -108,0 +119,0 @@ "Must be a valid one-time-password. " + |
{ | ||
"name": "@lerna/otplease", | ||
"version": "3.18.5", | ||
"version": "4.0.0", | ||
"description": "Prompt for OTP when wrapped Promise fails", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 6.9.0" | ||
"node": ">= 10.18.0" | ||
}, | ||
@@ -35,6 +35,5 @@ "publishConfig": { | ||
"dependencies": { | ||
"@lerna/prompt": "3.18.5", | ||
"figgy-pudding": "^3.5.1" | ||
"@lerna/prompt": "4.0.0" | ||
}, | ||
"gitHead": "2612f51e7eecec58eacf0571724e6989e4b8e42d" | ||
"gitHead": "4582c476e07dddddd6b2e3ab6e7f52c1f9eed59a" | ||
} |
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
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
7863
1
108
+ Added@lerna/prompt@4.0.0(transitive)
+ Addedansi-escapes@4.3.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcli-cursor@3.1.0(transitive)
+ Addedcli-width@3.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfigures@3.2.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedinquirer@7.3.3(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addedmute-stream@0.0.8(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedrestore-cursor@3.1.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtype-fest@0.21.3(transitive)
- Removedfiggy-pudding@^3.5.1
- Removed@lerna/prompt@3.18.5(transitive)
- Removedansi-escapes@3.2.0(transitive)
- Removedansi-regex@3.0.14.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcli-cursor@2.1.0(transitive)
- Removedcli-width@2.2.1(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedfiggy-pudding@3.5.2(transitive)
- Removedfigures@2.0.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedinquirer@6.5.2(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedmute-stream@0.0.7(transitive)
- Removedonetime@2.0.1(transitive)
- Removedrestore-cursor@2.0.0(transitive)
- Removedstring-width@2.1.1(transitive)
- Removedstrip-ansi@4.0.05.2.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updated@lerna/prompt@4.0.0