Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lerna/otplease

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lerna/otplease - npm Package Compare versions

Comparing version 3.18.5 to 4.0.0

27

CHANGELOG.md

@@ -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 @@

55

otplease.js
"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. " +

9

package.json
{
"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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc