Merge pull request #938 from podemos-info/shortid
Reemplace shortid with nanoid (v2)
This commit is contained in:
commit
ef66108cf7
16 changed files with 49 additions and 26 deletions
|
@ -55,6 +55,10 @@ enabledLanguages:
|
|||
# Inject custom scripts in subscription/layout.mjml.hbs
|
||||
# customSubscriptionScripts: [/custom/hello-world.js]
|
||||
|
||||
# Customize the random string generation for cid
|
||||
cid:
|
||||
alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
length: 10
|
||||
|
||||
# Enable to use Redis session cache or disable if Redis is not installed
|
||||
redis:
|
||||
|
|
|
@ -24,7 +24,7 @@ const blacklist = require('../models/blacklist');
|
|||
const libmime = require('libmime');
|
||||
const { enforce, hashEmail } = require('./helpers');
|
||||
const senders = require('./senders');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('./shortid');
|
||||
|
||||
const MessageType = {
|
||||
REGULAR: 0,
|
||||
|
|
27
server/lib/shortid.js
Normal file
27
server/lib/shortid.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
// Modules
|
||||
const nanoid = require('nanoid');
|
||||
const config = require('./config');
|
||||
|
||||
// Default hardcoded values
|
||||
let alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let customlength = 10;
|
||||
|
||||
// Gets from config if defined
|
||||
if (config.cid && config.cid.alphabet) alphabet=config.cid.alphabet;
|
||||
if (config.cid && config.cid.length) customlength=config.cid.length;
|
||||
|
||||
// Create custom nanoid
|
||||
const customnanoid = nanoid.customAlphabet(alphabet, customlength);
|
||||
|
||||
const re = new RegExp('['+alphabet+']{'+customlength+'}');
|
||||
|
||||
// Implements the public methods of shortid module with nanoid and export them
|
||||
module.exports.generate = function() {
|
||||
return customnanoid();
|
||||
}
|
||||
|
||||
module.exports.isValid = function(id) {
|
||||
return re.test(id);
|
||||
}
|
|
@ -4,7 +4,7 @@ const knex = require('../lib/knex');
|
|||
const hasher = require('node-object-hash')();
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const { enforce, filterObject } = require('../lib/helpers');
|
||||
const shares = require('./shares');
|
||||
const namespaceHelpers = require('../lib/namespace-helpers');
|
||||
|
|
|
@ -4,7 +4,7 @@ const knex = require('../lib/knex');
|
|||
const hasher = require('node-object-hash')();
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const { enforce, filterObject } = require('../lib/helpers');
|
||||
const shares = require('./shares');
|
||||
const namespaceHelpers = require('../lib/namespace-helpers');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const knex = require('../lib/knex');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
|
||||
async function addConfirmation(listId, action, ip, data) {
|
||||
const cid = shortid.generate();
|
||||
|
|
|
@ -7,7 +7,7 @@ const dtHelpers = require('../lib/dt-helpers');
|
|||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shares = require('./shares');
|
||||
const validators = require('../../shared/validators');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const slugify = require('slugify');
|
||||
const segments = require('./segments');
|
||||
const { formatDate, formatBirthday, parseDate, parseBirthday } = require('../../shared/date');
|
||||
|
|
|
@ -10,7 +10,7 @@ const uaParser = require('device');
|
|||
const he = require('he');
|
||||
const { getPublicUrl } = require('../lib/urls');
|
||||
const tools = require('../lib/tools');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const {enforce} = require('../lib/helpers');
|
||||
|
||||
const LinkId = {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const knex = require('../lib/knex');
|
||||
const hasher = require('node-object-hash')();
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const { enforce, filterObject } = require('../lib/helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shares = require('./shares');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const knex = require('../lib/knex');
|
||||
const hasher = require('node-object-hash')();
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const { enforce, filterObject } = require('../lib/helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shares = require('./shares');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const config = require('../lib/config');
|
||||
const knex = require('../lib/knex');
|
||||
const hasher = require('node-object-hash')();
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const shares = require('./shares');
|
||||
|
|
14
server/package-lock.json
generated
14
server/package-lock.json
generated
|
@ -5038,9 +5038,9 @@
|
|||
"optional": true
|
||||
},
|
||||
"nanoid": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.7.tgz",
|
||||
"integrity": "sha512-fmS3qwDldm4bE01HCIRqNk+f255CNjnAoeV3Zzzv0KemObHKqYgirVaZA9DtKcjogicWjYcHkJs4D5A8CjnuVQ=="
|
||||
"version": "3.1.12",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.12.tgz",
|
||||
"integrity": "sha512-1qstj9z5+x491jfiC4Nelk+f8XBad7LN20PmyWINJEMRSf3wcAjAWysw1qaA8z6NSKe2sjq1hRSDpBH5paCb6A=="
|
||||
},
|
||||
"nanomatch": {
|
||||
"version": "1.2.13",
|
||||
|
@ -12744,14 +12744,6 @@
|
|||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
|
||||
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
|
||||
},
|
||||
"shortid": {
|
||||
"version": "2.2.15",
|
||||
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.15.tgz",
|
||||
"integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==",
|
||||
"requires": {
|
||||
"nanoid": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"sigmund": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
"morgan": "^1.9.1",
|
||||
"multer": "^1.4.2",
|
||||
"mysql": "^2.17.1",
|
||||
"nanoid": "^3.1.12",
|
||||
"node-ipc": "^9.1.1",
|
||||
"node-mocks-http": "^1.8.1",
|
||||
"node-object-hash": "^1.4.1",
|
||||
|
@ -105,7 +106,6 @@
|
|||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.5",
|
||||
"serve-favicon": "^2.5.0",
|
||||
"shortid": "^2.2.15",
|
||||
"slugify": "^1.3.6",
|
||||
"smtp-server": "^3.4.7",
|
||||
"tmp-promise": "^1.1.0",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const config = require('../config');
|
||||
const knex = require('../../../lib/knex');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../../../lib/shortid');
|
||||
const slugify = require('slugify');
|
||||
|
||||
async function run() {
|
||||
|
|
|
@ -11,7 +11,7 @@ const { EntityVals: TriggerEntityVals, EventVals: TriggerEventVals } = require('
|
|||
const { SubscriptionSource } = require('../../../../shared/lists');
|
||||
const {DOMParser, XMLSerializer} = require('xmldom');
|
||||
const log = require('../../../lib/log');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../../../lib/shortid');
|
||||
const slugify = require('slugify');
|
||||
|
||||
const entityTypesAddNamespace = ['list', 'custom_form', 'template', 'campaign', 'report', 'report_template', 'user'];
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
const config = require('../lib/config');
|
||||
const { useCase, step, precondition, driver } = require('../lib/mocha-e2e');
|
||||
const shortid = require('shortid');
|
||||
const shortid = require('../lib/shortid');
|
||||
const expect = require('chai').expect;
|
||||
const createPage = require('../page-objects/subscription');
|
||||
const faker = require('faker');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue