mybase 1.0.32 → 1.0.35

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.
Files changed (2) hide show
  1. package/mybase.js +46 -3
  2. package/package.json +1 -1
package/mybase.js CHANGED
@@ -26,6 +26,7 @@ function validEmail(email) {
26
26
  // taken from https://www.w3resource.com/javascript/form/email-validation.php
27
27
  // strange looking emails might be indeed valid
28
28
  // check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
29
+ if (typeof email==='string') email=email.toLowerCase().trim()
29
30
  return (/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/).test(email)
30
31
  }
31
32
 
@@ -124,10 +125,12 @@ function vaultRead(vault, key) {
124
125
  })
125
126
  }
126
127
 
127
- function vaultFill(vault, obj, ignoreError = false) {
128
+ function vaultFill(vault, obj, ignoreError = false, keepCache=true) {
128
129
  // v2.1
129
130
  // fills all strings with ^vault@/secret/... with proper vault values
130
131
  // if you call it again, it does reload the configuration
132
+ // v2.2
133
+ // supports keepCache - if vault fails, we will keep previous values instead of filling with false
131
134
  return new Promise(async function(resolve, reject) {
132
135
  function findVaultKeyMappings(config, keys = []) {
133
136
 
@@ -158,6 +161,11 @@ function vaultFill(vault, obj, ignoreError = false) {
158
161
  if (config[i] !== null) {
159
162
 
160
163
  if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
164
+ if (keepCache) {
165
+ if (vaultResults[config[i]['__vaultkey']]) config[i] = vaultResults[config[i]['__vaultkey']]
166
+ }
167
+
168
+ else
161
169
  config[i] = vaultResults[config[i]['__vaultkey']]
162
170
  continue
163
171
  }
@@ -198,7 +206,6 @@ function vaultFill(vault, obj, ignoreError = false) {
198
206
 
199
207
  resolve(true)
200
208
  })
201
-
202
209
  }
203
210
 
204
211
 
@@ -326,7 +333,42 @@ function softexit(message = false, seconds = 60, exitcode = 1) {
326
333
  setTimeout(() => { process.exit(exitcode) }, seconds * 1000)
327
334
  }
328
335
 
329
- function validHostname(domainName) {
336
+ function validHostname(value) {
337
+ // credit: https://github.com/miguelmota/is-valid-hostname/blob/master/index.js
338
+ if (typeof value !== 'string') return false
339
+
340
+ const validHostnameChars = /^[a-zA-Z0-9-.]{1,253}\.?$/g
341
+ if (!validHostnameChars.test(value)) {
342
+ return false
343
+ }
344
+
345
+ if (value.endsWith('.')) {
346
+ value = value.slice(0, value.length - 1)
347
+ }
348
+
349
+ if (value.length > 253) {
350
+ return false
351
+ }
352
+
353
+ const labels = value.split('.')
354
+
355
+ const isValid = labels.every(function (label) {
356
+ const validLabelChars = /^([a-zA-Z0-9-]+)$/g
357
+
358
+ const validLabel = (
359
+ validLabelChars.test(label) &&
360
+ label.length < 64 &&
361
+ !label.startsWith('-') &&
362
+ !label.endsWith('-')
363
+ )
364
+
365
+ return validLabel
366
+ })
367
+
368
+ return isValid
369
+ }
370
+
371
+ function validHostname2(domainName) {
330
372
  var domainNameRegex = /^(?:[a-z0-9](?:[a-z0-9_\-]{0,61}[a-z0-9])?\.){0,126}(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9]))\.?$/i
331
373
  if (!domainName || typeof domainName!=='string') return false
332
374
  // is an ip host
@@ -465,6 +507,7 @@ module.exports = {
465
507
  validHPassword,
466
508
  validEmail,
467
509
  validHostname,
510
+ validHostname2,
468
511
  validIp,validIpNative,
469
512
  validUUID4,
470
513
  getTemp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.0.32",
3
+ "version": "1.0.35",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {