From ce10c3e86110810e5e0079851ad58191b6973846 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Thu, 10 Jun 2021 23:28:24 -0600 Subject: [PATCH] Optimization for image thumbnails --- .gitignore | 1 + api/images.js | 53 +- components/card/style.module.css | 2 + import/.gitignore | 3 - import/index.js | 45 -- import/mongo/cart.js | 24 - import/mongo/coupon.js | 20 - import/mongo/index.js | 31 - import/mongo/media.js | 18 - import/mongo/sock.js | 20 - import/mongo/user.js | 19 - import/package-lock.json | 1003 ------------------------------ import/package.json | 8 - import/tariffData.json | 8 - import/tasks/createItems.js | 80 --- import/tasks/createUsers.js | 35 -- import/tasks/uploadImages.js | 18 - import/tasks/writeExcelSheet.js | 173 ------ 18 files changed, 54 insertions(+), 1507 deletions(-) delete mode 100644 import/.gitignore delete mode 100644 import/index.js delete mode 100644 import/mongo/cart.js delete mode 100644 import/mongo/coupon.js delete mode 100644 import/mongo/index.js delete mode 100644 import/mongo/media.js delete mode 100644 import/mongo/sock.js delete mode 100644 import/mongo/user.js delete mode 100644 import/package-lock.json delete mode 100644 import/package.json delete mode 100644 import/tariffData.json delete mode 100644 import/tasks/createItems.js delete mode 100644 import/tasks/createUsers.js delete mode 100644 import/tasks/uploadImages.js delete mode 100644 import/tasks/writeExcelSheet.js diff --git a/.gitignore b/.gitignore index ddf2bf0..14300a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .next/ node_modules/ .env +cache/ \ No newline at end of file diff --git a/api/images.js b/api/images.js index 303dbb7..bb48132 100644 --- a/api/images.js +++ b/api/images.js @@ -1,14 +1,63 @@ const router = require('express-promise-router')() const db = require('../db') const ensureAdmin = require('./middleware/ensureAdmin') +const fs = require('fs'); +const path = require('path'); + +const cacheRoot = path.join(__dirname, '../cache/images') + +fs.promises.mkdir(cacheRoot, {recursive: true}) + .catch(() => console.error("Could not create image cache dir: " + cacheRoot)); + +const memCache = {}; + +async function writeImageFile(uuid, size, data) { + if(size !== 'thumb' && size !== 'large') + throw new Error(`Unknown image size ${size}`); + + await fs.promises.writeFile(path.join(cacheRoot, `${uuid}-${size}`), data); +} + +async function getImage(uuid, size) { + // If we've already stored a mime type, that means we've written the file to disk + if(memCache[`${uuid}-${size}`]?.mime_type) { + return { + file: fs.createReadStream(path.join(cacheRoot, `${uuid}-${size}`)), + mime_type: memCache[`${uuid}-${size}`].mime_type + } + } + + // If we've stored a promise, that means we're currently retrieving it from the db + if(memCache[`${uuid}-${size}`]?.dbPromise) { + return await memCache[`${uuid}-${size}`]?.dbPromise; + } + + // Otherwise, retrieve it from the DB, and then write it to disk + const record = memCache[`${uuid}-${size}`] = {}; + record.dbPromise = db.item.getImage(uuid, size); + + const image = await record.dbPromise; + await writeImageFile(uuid, size, image.file); + + record.mime_type = image.mime_type; + delete record.dbPromise; + + return image; +} router.get('/:uuid/:size', async (req, res) => { - const image = await db.item.getImage(req.params.uuid, req.params.size) + const image = await getImage(req.params.uuid, req.params.size) const cacheSeconds = 60 * 60 * 24; res.set('Cache-Control', cacheSeconds); res.set('Content-Type', image.mime_type) - res.end(image.file) + + if(Buffer.isBuffer(image.file)) + res.end(image.file) + else if (typeof image.file.pipe === 'function') + image.file.pipe(res) + else + throw new Error("Unable to send file to user"); }) router.post('/:uuid/featured', ensureAdmin, async (req, res) => { diff --git a/components/card/style.module.css b/components/card/style.module.css index aafec8f..668c0b3 100644 --- a/components/card/style.module.css +++ b/components/card/style.module.css @@ -74,6 +74,8 @@ .card img{ width:80%; + aspect-ratio: 4 / 3; + object-fit: cover; padding:10px; background: #d4d4fb; border: solid 1px #dec8e2; diff --git a/import/.gitignore b/import/.gitignore deleted file mode 100644 index 8b79a53..0000000 --- a/import/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -users.json -node_modules/ -datafile.xlsx \ No newline at end of file diff --git a/import/index.js b/import/index.js deleted file mode 100644 index 0e14c51..0000000 --- a/import/index.js +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env node -const path = require('path') -require('dotenv').config({path: path.join(__dirname, '../.env')}) - -const pg = require('../db/pg') -const newDB = require('../db') -const oldDB = require('./mongo')('mongodb://localhost/sos') - -const createItems = require('./tasks/createItems') -const createUsers = require('./tasks/createUsers') -const uploadImages = require('./tasks/uploadImages') -const saveExcelDataFile = require('./tasks/writeExcelSheet') - -async function doMigration() { - const items = await oldDB.sock.find().lean().exec() - const allUsers = await oldDB.user.find().populate('purchases').lean().exec() - const carts = allUsers.map(u => u.purchases).flat() - const coupons = await oldDB.coupon.find().lean().exec() - - const registeredUsers = allUsers.filter(user => user.email) - - console.log(`Loaded ${carts.length} purchases and ${registeredUsers.length} users`) - - console.log(`Inserting ${registeredUsers.length} users into the database`) - const importAdmin = await createUsers(newDB, registeredUsers); - console.log(` Found user account ${importAdmin.uuid} (${importAdmin.email}) to attribute file uploads to`) - - console.log(`\nInserting ${items.length} items into database`) - const itemImages = await createItems(newDB, items); - - const numImages = itemImages.map(({images}) => images.length).reduce((a,b) => b+a, 0) - console.log(`\nImporting ${numImages} images into database`) - await uploadImages(newDB, itemImages, importAdmin.uuid) - - console.log('\nWriting Excel data file') - await saveExcelDataFile(allUsers, coupons, items, path.join(__dirname, './datafile.xlsx')) -} - -doMigration() - .catch(console.error) - .finally(() => { - pg.end() - oldDB._connection.close() - }) - diff --git a/import/mongo/cart.js b/import/mongo/cart.js deleted file mode 100644 index 2076726..0000000 --- a/import/mongo/cart.js +++ /dev/null @@ -1,24 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -module.exports.schema = new Schema({ - user: {type: Schema.Types.ObjectId, ref: 'User'}, - items: [{type: Schema.Types.ObjectId, required: true, ref: 'Sock'}], - purchased: {type: Schema.Types.Mixed, enum: [true, false, 'refunded'], default: false, required: true}, - purchaseTime: {type: Number}, - shipped: {type: Boolean, required: true, default: false}, - shippedOn: {type: Number}, - address: {type: String}, // Easypost id - shipment: {type: String}, // Easypost id - shipmentMeasured: {type: Boolean, default: false}, - sockPrice: {type: Number}, - totalPrice: {type: Number}, - shippingEstimate: {type: Number}, - coupon: {type: Schema.Types.ObjectId, required: false, ref: 'Coupon'}, - trackingCode: {type: String}, - needsCustoms: {type: Boolean, default: false} -}, { - usePushEach: true -}); - -module.exports.model = mongoose.model('Cart', module.exports.schema); diff --git a/import/mongo/coupon.js b/import/mongo/coupon.js deleted file mode 100644 index 8395483..0000000 --- a/import/mongo/coupon.js +++ /dev/null @@ -1,20 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -module.exports.schema = new Schema({ - code: {type: String, required: true, unique: true, index: true}, - - numAllowedUses: {type: Number, required: true, default: 1}, - uses: [{type: Schema.Types.ObjectId, required: true, ref: 'Cart'}], - expires: {type: Number, required: true, default: 0}, - - flatDiscount: {type: Number, required: true, default: 0}, - percentDiscount: {type: Number, required: true, default:0}, - socksFree: {type: Number, required: true, default: 0}, - perSockDiscount: {type: Number, required: false, default: 0}, - freeShipping: {type: Boolean, required: true, default: false} -}, { - usePushEach: true -}); - -module.exports.model = mongoose.model('Coupon', module.exports.schema); diff --git a/import/mongo/index.js b/import/mongo/index.js deleted file mode 100644 index 9c9804e..0000000 --- a/import/mongo/index.js +++ /dev/null @@ -1,31 +0,0 @@ -const mongoose = require('mongoose') -mongoose.Promise = Promise - -const models = { - Sock: require('./sock.js').schema, - Media: require('./media.js').schema, - User: require('./user.js').schema, - Cart: require('./cart.js').schema, - Coupon: require('./coupon.js').schema, -} - -module.exports = function connect(url) { - const connection = mongoose.createConnection(url) - - connection.on('error', console.error.bind(console, 'connection error:')); - - var sock = connection.model('Sock',models.Sock, 'socks'); - var media = connection.model('Media',models.Media, 'medias'); - var user = connection.model('User',models.User, 'users'); - var cart = connection.model('Cart',models.Cart, 'carts'); - var coupon = connection.model('Coupon',models.Coupon, 'coupons'); - - return { - sock, - media, - user, - cart, - coupon, - _connection: connection - } -} diff --git a/import/mongo/media.js b/import/mongo/media.js deleted file mode 100644 index 471ccf8..0000000 --- a/import/mongo/media.js +++ /dev/null @@ -1,18 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -var MediaSchema = new Schema({ - name: {type: String, required: true}, - urlslug: {type: String, required: true, unique: true}, - uploaded: {type: Number, required: true}, - filename: {type: String, required: true, unique: true}, - thumbnail: {type: String}, - mimetype: {type: String, required: true}, - width: {type:Number,required:true}, - height: {type:Number,required:true} -}); - -var Media = mongoose.model('Media', MediaSchema); - -module.exports.model = Media; -module.exports.schema = MediaSchema diff --git a/import/mongo/sock.js b/import/mongo/sock.js deleted file mode 100644 index 7a48023..0000000 --- a/import/mongo/sock.js +++ /dev/null @@ -1,20 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -module.exports.schema = new Schema({ - name: {type: String, required: true}, - urlslug: {type: String, required: true, lowercase: true, unique: true}, - productImage: {type: String, required: true}, - description: {type: String, required: true}, - numberInStock: {type: Number}, - price: {type: Number}, - images: [String], //Does not include productImage - tags: [String], - publishTime:{type: Number, required: true}, - expireTime:{type: Number, required: true}, - preorderDate: {type: Number, default: null} -}); - -module.exports.schema.index({name: 'text', description: 'text'}); - -module.exports.model = mongoose.model('Sock', module.exports.schema); diff --git a/import/mongo/user.js b/import/mongo/user.js deleted file mode 100644 index 272a9a5..0000000 --- a/import/mongo/user.js +++ /dev/null @@ -1,19 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -module.exports.schema = new Schema({ - email: {type: String}, - emailConfirmed: {type: Boolean, default: false}, - emailPin: {type: String}, - password: {type: String}, - isAdmin: {type: Boolean, default: false}, - cart: {type: Schema.Types.ObjectId, ref: 'Cart'}, - purchases: [{type: Schema.Types.ObjectId, ref: 'Cart'}], - credit: {type: Number, default: 0},//Credit in cents because non-integers are confusing? - savedAddress: {type: String}, - lastLogin: {type: Number, required: true} -}, { - usePushEach: true -}); - -module.exports.model = mongoose.model('User', module.exports.schema); diff --git a/import/package-lock.json b/import/package-lock.json deleted file mode 100644 index a43bea6..0000000 --- a/import/package-lock.json +++ /dev/null @@ -1,1003 +0,0 @@ -{ - "name": "sos-import", - "version": "0.0.1", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@fast-csv/format": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/@fast-csv/format/-/format-4.3.5.tgz", - "integrity": "sha512-8iRn6QF3I8Ak78lNAa+Gdl5MJJBM5vRHivFtMRUWINdevNo00K7OXxS2PshawLKTejVwieIlPmK5YlLu6w4u8A==", - "requires": { - "@types/node": "^14.0.1", - "lodash.escaperegexp": "^4.1.2", - "lodash.isboolean": "^3.0.3", - "lodash.isequal": "^4.5.0", - "lodash.isfunction": "^3.0.9", - "lodash.isnil": "^4.0.0" - } - }, - "@fast-csv/parse": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/@fast-csv/parse/-/parse-4.3.6.tgz", - "integrity": "sha512-uRsLYksqpbDmWaSmzvJcuApSEe38+6NQZBUsuAyMZKqHxH0g1wcJgsKUvN3WC8tewaqFjBMMGrkHmC+T7k8LvA==", - "requires": { - "@types/node": "^14.0.1", - "lodash.escaperegexp": "^4.1.2", - "lodash.groupby": "^4.6.0", - "lodash.isfunction": "^3.0.9", - "lodash.isnil": "^4.0.0", - "lodash.isundefined": "^3.0.1", - "lodash.uniq": "^4.5.0" - } - }, - "@types/node": { - "version": "14.17.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.2.tgz", - "integrity": "sha512-sld7b/xmFum66AAKuz/rp/CUO8+98fMpyQ3SBfzzBNGMd/1iHBTAg9oyAvcYlAj46bpc74r91jSw2iFdnx29nw==" - }, - "archiver": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/archiver/-/archiver-5.3.0.tgz", - "integrity": "sha512-iUw+oDwK0fgNpvveEsdQ0Ase6IIKztBJU2U0E9MzszMfmVVUyv1QJhS2ITW9ZCqx8dktAxVAjWWkKehuZE8OPg==", - "requires": { - "archiver-utils": "^2.1.0", - "async": "^3.2.0", - "buffer-crc32": "^0.2.1", - "readable-stream": "^3.6.0", - "readdir-glob": "^1.0.0", - "tar-stream": "^2.2.0", - "zip-stream": "^4.1.0" - }, - "dependencies": { - "async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" - }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "archiver-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-2.1.0.tgz", - "integrity": "sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==", - "requires": { - "glob": "^7.1.4", - "graceful-fs": "^4.2.0", - "lazystream": "^1.0.0", - "lodash.defaults": "^4.2.0", - "lodash.difference": "^4.5.0", - "lodash.flatten": "^4.4.0", - "lodash.isplainobject": "^4.0.6", - "lodash.union": "^4.6.0", - "normalize-path": "^3.0.0", - "readable-stream": "^2.0.0" - } - }, - "async": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.0.tgz", - "integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==", - "requires": { - "lodash": "^4.14.0" - } - }, - "balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" - }, - "base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" - }, - "big-integer": { - "version": "1.6.48", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", - "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" - }, - "binary": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz", - "integrity": "sha1-n2BVO8XOjDOG87VTz/R0Yq3sqnk=", - "requires": { - "buffers": "~0.1.1", - "chainsaw": "~0.1.0" - } - }, - "bl": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "requires": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "bluebird": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", - "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "bson": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.9.tgz", - "integrity": "sha512-IQX9/h7WdMBIW/q/++tGd+emQr0XMdeZ6icnT/74Xk9fnabWn+gZgpE+9V+gujL3hhJOoNrnDVY7tWdzc7NUTg==" - }, - "buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, - "buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" - }, - "buffer-indexof-polyfill": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/buffer-indexof-polyfill/-/buffer-indexof-polyfill-1.0.2.tgz", - "integrity": "sha512-I7wzHwA3t1/lwXQh+A5PbNvJxgfo5r3xulgpYDB5zckTu/Z9oUK9biouBKQUjEqzaz3HnAT6TYoovmE+GqSf7A==" - }, - "buffer-shims": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", - "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=" - }, - "buffers": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz", - "integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s=" - }, - "chainsaw": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", - "integrity": "sha1-XqtQsor+WAdNDVgpE4iCi15fvJg=", - "requires": { - "traverse": ">=0.3.0 <0.4" - } - }, - "compress-commons": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz", - "integrity": "sha512-QLdDLCKNV2dtoTorqgxngQCMA+gWXkM/Nwu7FpeBhk/RdkzimqC3jueb/FDmaZeXh+uby1jkBqE3xArsLBE5wQ==", - "requires": { - "buffer-crc32": "^0.2.13", - "crc32-stream": "^4.0.2", - "normalize-path": "^3.0.0", - "readable-stream": "^3.6.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "crc-32": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.0.tgz", - "integrity": "sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==", - "requires": { - "exit-on-epipe": "~1.0.1", - "printj": "~1.1.0" - } - }, - "crc32-stream": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-4.0.2.tgz", - "integrity": "sha512-DxFZ/Hk473b/muq1VJ///PMNLj0ZMnzye9thBpmjpJKCc5eMgB95aK8zCGrGfQ90cWo561Te6HK9D+j4KPdM6w==", - "requires": { - "crc-32": "^1.2.0", - "readable-stream": "^3.4.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "dayjs": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.5.tgz", - "integrity": "sha512-BUFis41ikLz+65iH6LHQCDm4YPMj5r1YFLdupPIyM4SGcXMmtiLQ7U37i+hGS8urIuqe7I/ou3IS1jVc4nbN4g==" - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "duplexer2": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", - "integrity": "sha1-ixLauHjA1p4+eJEFFmKjL8a93ME=", - "requires": { - "readable-stream": "^2.0.2" - } - }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "requires": { - "once": "^1.4.0" - } - }, - "es6-promise": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz", - "integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q=" - }, - "exceljs": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/exceljs/-/exceljs-4.2.1.tgz", - "integrity": "sha512-EogoTdXH1X1PxqD9sV8caYd1RIfXN3PVlCV+mA/87CgdO2h4X5xAEbr7CaiP8tffz7L4aBFwsdMbjfMXi29NjA==", - "requires": { - "archiver": "^5.0.0", - "dayjs": "^1.8.34", - "fast-csv": "^4.3.1", - "jszip": "^3.5.0", - "readable-stream": "^3.6.0", - "saxes": "^5.0.1", - "tmp": "^0.2.0", - "unzipper": "^0.10.11", - "uuid": "^8.3.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "exit-on-epipe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz", - "integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==" - }, - "fast-csv": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/fast-csv/-/fast-csv-4.3.6.tgz", - "integrity": "sha512-2RNSpuwwsJGP0frGsOmTb9oUF+VkFSM4SyLTDgwf2ciHWTarN0lQTC+F2f/t5J9QjW+c65VFIAAu85GsvMIusw==", - "requires": { - "@fast-csv/format": "4.3.5", - "@fast-csv/parse": "4.3.6" - } - }, - "fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "fstream": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", - "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", - "requires": { - "graceful-fs": "^4.1.2", - "inherits": "~2.0.0", - "mkdirp": ">=0.5 0", - "rimraf": "2" - }, - "dependencies": { - "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "requires": { - "glob": "^7.1.3" - } - } - } - }, - "glob": { - "version": "7.1.7", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", - "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "graceful-fs": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" - }, - "hooks-fixed": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/hooks-fixed/-/hooks-fixed-2.0.2.tgz", - "integrity": "sha512-YurCM4gQSetcrhwEtpQHhQ4M7Zo7poNGqY4kQGeBS6eZtOcT3tnNs01ThFa0jYBByAiYt1MjMjP/YApG0EnAvQ==" - }, - "ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" - }, - "immediate": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, - "jszip": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.6.0.tgz", - "integrity": "sha512-jgnQoG9LKnWO3mnVNBnfhkh0QknICd1FGSrXcgrl67zioyJ4wgx25o9ZqwNtrROSflGBCGYnJfjrIyRIby1OoQ==", - "requires": { - "lie": "~3.3.0", - "pako": "~1.0.2", - "readable-stream": "~2.3.6", - "set-immediate-shim": "~1.0.1" - }, - "dependencies": { - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - } - } - }, - "kareem": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-1.5.0.tgz", - "integrity": "sha1-4+QQHZ3P3imXadr0tNtk2JXRdEg=" - }, - "lazystream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.0.tgz", - "integrity": "sha1-9plf4PggOS9hOWvolGJAe7dxaOQ=", - "requires": { - "readable-stream": "^2.0.5" - } - }, - "lie": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", - "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "requires": { - "immediate": "~3.0.5" - } - }, - "listenercount": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/listenercount/-/listenercount-1.0.1.tgz", - "integrity": "sha1-hMinKrWcRyUyFIDJdeZQg0LnCTc=" - }, - "lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, - "lodash.defaults": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", - "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" - }, - "lodash.difference": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", - "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=" - }, - "lodash.escaperegexp": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", - "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=" - }, - "lodash.flatten": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", - "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=" - }, - "lodash.get": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" - }, - "lodash.groupby": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.groupby/-/lodash.groupby-4.6.0.tgz", - "integrity": "sha1-Cwih3PaDl8OXhVwyOXg4Mt90A9E=" - }, - "lodash.isboolean": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", - "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" - }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, - "lodash.isfunction": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz", - "integrity": "sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==" - }, - "lodash.isnil": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/lodash.isnil/-/lodash.isnil-4.0.0.tgz", - "integrity": "sha1-SeKM1VkBNFjIFMVHnTxmOiG/qmw=" - }, - "lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" - }, - "lodash.isundefined": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash.isundefined/-/lodash.isundefined-3.0.1.tgz", - "integrity": "sha1-I+89lTVWUgOmbO/VuDD4SJEa+0g=" - }, - "lodash.union": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.union/-/lodash.union-4.6.0.tgz", - "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=" - }, - "lodash.uniq": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", - "integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" - }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "requires": { - "minimist": "^1.2.5" - } - }, - "mongodb": { - "version": "2.2.34", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.34.tgz", - "integrity": "sha1-o09Zu+thdUrsQy3nLD/iFSakTBo=", - "requires": { - "es6-promise": "3.2.1", - "mongodb-core": "2.1.18", - "readable-stream": "2.2.7" - } - }, - "mongodb-core": { - "version": "2.1.18", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.18.tgz", - "integrity": "sha1-TEYTm986HwMt7ZHbSfOO7AFlkFA=", - "requires": { - "bson": "~1.0.4", - "require_optional": "~1.0.0" - } - }, - "mongoose": { - "version": "4.13.21", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.21.tgz", - "integrity": "sha512-0VZtQu1rSUPwUtbb7zh6CymI0nNkVInOIDbtWNlna070qnUO14On8PpSVSwlx3gwmkKL2OkP4ioCj5YHC6trMg==", - "requires": { - "async": "2.6.0", - "bson": "~1.0.4", - "hooks-fixed": "2.0.2", - "kareem": "1.5.0", - "lodash.get": "4.4.2", - "mongodb": "2.2.34", - "mpath": "0.5.1", - "mpromise": "0.5.5", - "mquery": "2.3.3", - "ms": "2.0.0", - "muri": "1.3.0", - "regexp-clone": "0.0.1", - "sliced": "1.0.1" - } - }, - "mpath": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.5.1.tgz", - "integrity": "sha512-H8OVQ+QEz82sch4wbODFOz+3YQ61FYz/z3eJ5pIdbMEaUzDqA268Wd+Vt4Paw9TJfvDgVKaayC0gBzMIw2jhsg==" - }, - "mpromise": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mpromise/-/mpromise-0.5.5.tgz", - "integrity": "sha1-9bJCWddjrMIlewoMjG2Gb9UXMuY=" - }, - "mquery": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/mquery/-/mquery-2.3.3.tgz", - "integrity": "sha512-NC8L14kn+qxJbbJ1gbcEMDxF0sC3sv+1cbRReXXwVvowcwY1y9KoVZFq0ebwARibsadu8lx8nWGvm3V0Pf0ZWQ==", - "requires": { - "bluebird": "3.5.0", - "debug": "2.6.9", - "regexp-clone": "0.0.1", - "sliced": "0.0.5" - }, - "dependencies": { - "sliced": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", - "integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8=" - } - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "muri": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/muri/-/muri-1.3.0.tgz", - "integrity": "sha512-FiaFwKl864onHFFUV/a2szAl7X0fxVlSKNdhTf+BM8i8goEgYut8u5P9MqQqIYwvaMxjzVESsoEm/2kfkFH1rg==" - }, - "normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1" - } - }, - "pako": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "printj": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz", - "integrity": "sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==" - }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" - }, - "readable-stream": { - "version": "2.2.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz", - "integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=", - "requires": { - "buffer-shims": "~1.0.0", - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "~1.0.0", - "process-nextick-args": "~1.0.6", - "string_decoder": "~1.0.0", - "util-deprecate": "~1.0.1" - } - }, - "readdir-glob": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/readdir-glob/-/readdir-glob-1.1.1.tgz", - "integrity": "sha512-91/k1EzZwDx6HbERR+zucygRFfiPl2zkIYZtv3Jjr6Mn7SkKcVct8aVO+sSRiGMc6fLf72du3d92/uY63YPdEA==", - "requires": { - "minimatch": "^3.0.4" - } - }, - "regexp-clone": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz", - "integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk=" - }, - "require_optional": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", - "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", - "requires": { - "resolve-from": "^2.0.0", - "semver": "^5.1.0" - } - }, - "resolve-from": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", - "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" - }, - "rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "requires": { - "glob": "^7.1.3" - } - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "saxes": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz", - "integrity": "sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==", - "requires": { - "xmlchars": "^2.2.0" - } - }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" - }, - "set-immediate-shim": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", - "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=" - }, - "setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" - }, - "sliced": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", - "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E=" - }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "tar-stream": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", - "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "requires": { - "bl": "^4.0.3", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - }, - "tmp": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", - "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", - "requires": { - "rimraf": "^3.0.0" - } - }, - "traverse": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", - "integrity": "sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk=" - }, - "unzipper": { - "version": "0.10.11", - "resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.10.11.tgz", - "integrity": "sha512-+BrAq2oFqWod5IESRjL3S8baohbevGcVA+teAIOYWM3pDVdseogqbzhhvvmiyQrUNKFUnDMtELW3X8ykbyDCJw==", - "requires": { - "big-integer": "^1.6.17", - "binary": "~0.3.0", - "bluebird": "~3.4.1", - "buffer-indexof-polyfill": "~1.0.0", - "duplexer2": "~0.1.4", - "fstream": "^1.0.12", - "graceful-fs": "^4.2.2", - "listenercount": "~1.0.1", - "readable-stream": "~2.3.6", - "setimmediate": "~1.0.4" - }, - "dependencies": { - "bluebird": { - "version": "3.4.7", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", - "integrity": "sha1-9y12C+Cbf3bQjtj66Ysomo0F+rM=" - }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - } - } - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, - "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - }, - "xmlchars": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", - "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" - }, - "zip-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-4.1.0.tgz", - "integrity": "sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==", - "requires": { - "archiver-utils": "^2.1.0", - "compress-commons": "^4.1.0", - "readable-stream": "^3.6.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - } - } - } - } -} diff --git a/import/package.json b/import/package.json deleted file mode 100644 index 232c4d7..0000000 --- a/import/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "sos-import", - "version": "0.0.1", - "dependencies": { - "exceljs": "^4.2.1", - "mongoose": "^4.4.16" - } -} diff --git a/import/tariffData.json b/import/tariffData.json deleted file mode 100644 index 7e65bfa..0000000 --- a/import/tariffData.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "sock": { - "hs_tariff_number": "611595", - "customs_description": "A pair of socks", - "origin_country": "CN", - "weight": 2 - } -} \ No newline at end of file diff --git a/import/tasks/createItems.js b/import/tasks/createItems.js deleted file mode 100644 index dc90c13..0000000 --- a/import/tasks/createItems.js +++ /dev/null @@ -1,80 +0,0 @@ -const tariffTemplates = require('../tariffData.json') - -module.exports = async function(pg, items) { - await checkForPreviousItems(pg); - - const {itemCounts, itemImages} = await createItems(pg, items); - - await createShipment(pg, itemCounts); - - return itemImages.map(({uuid, name, images}) => ({ - uuid, - name, - images: images.map(image => image.replace(/^thumb\//, '')) - })) -} - -async function checkForPreviousItems(pg) { - const items = await pg.item.findAll(); - - if(items.length) - throw new Error(`Cannot migrate items - ${items.length} items already exist!`) -} - -async function createItems(pg, items) { - const itemCounts = []; - const itemImages = []; - - for (const item of items) { - let tariffData = null; - - if(item.tags.includes('fauxpaws')) - tariffData = tariffTemplates.sock; - - if(item.tags.includes('tinyequine')) - tariffData = tariffTemplates.sock; - - if(!tariffData) { - console.warn(` Skipping item ${item.name} because of missing tariff data`) - continue; - } - - const newItem = await pg.item.create( - item.name, - item.urlslug, - item.description - .replace(/<(\/|)p>/g, '') - .replace(' ', ' ') - .trim(), - item.price * 100, - true, - tariffData.hs_tariff_number, - tariffData.customs_description, - tariffData.origin_country, - tariffData.weight - ) - - itemCounts.push({ - uuid: newItem.uuid, - count: item.numberInStock - }) - - itemImages.push({ - uuid: newItem.uuid, - name: newItem.name, - images: [ - item.productImage, - ...item.images - ] - }) - } - - return {itemCounts, itemImages}; -} - -async function createShipment(pg, itemCounts) { - return await pg.shipment.createShipment( - "Initial stock from db import", - itemCounts.filter(({count}) => count > 0) - ); -} \ No newline at end of file diff --git a/import/tasks/createUsers.js b/import/tasks/createUsers.js deleted file mode 100644 index eadb179..0000000 --- a/import/tasks/createUsers.js +++ /dev/null @@ -1,35 +0,0 @@ -module.exports = async function(pg, users) { - let adminUser - - for (const user of users) { - const existing = await pg.user.findByEmail(user.email) - - if(existing) { - console.warn(" Warning: duplicate user with email " + user.email) - continue; - } - - const newUser = await pg.user.import(user.email, user.password); - - if (user.emailConfirmed) { - await pg.user.markEmailVerified(newUser.uuid) - } - - if (user.isAdmin) { - await pg.user.makeAdmin(newUser.uuid) - } - - if (user.isAdmin && !adminUser) { - adminUser = newUser; - } - - const creationDate = new Date(parseInt(user._id.toString().slice(0,8), 16)*1000) - await pg.user.updateRegistrationDate(newUser.uuid, creationDate, user.emailConfirmed) - } - - if (!adminUser) { - throw new Error("Unable to find importing admin") - } - - return adminUser -} \ No newline at end of file diff --git a/import/tasks/uploadImages.js b/import/tasks/uploadImages.js deleted file mode 100644 index 09dbba3..0000000 --- a/import/tasks/uploadImages.js +++ /dev/null @@ -1,18 +0,0 @@ -const axios = require('axios'); -const db = require('../../db'); - -module.exports = async function(db, itemImages, adminUUID) { - for (const item of itemImages) { - const {uuid, name, images} = item; - - console.log(` Downloading images for item: ${name}`) - - for (const imageName of images) { - const url = `https://societyofsocks.us/media/${imageName}` - console.log(' Downloading ' + url) - const response = await axios.get(url, { responseType: 'arraybuffer' }) - - await db.item.addImage(uuid, response.data, adminUUID); - } - } -} \ No newline at end of file diff --git a/import/tasks/writeExcelSheet.js b/import/tasks/writeExcelSheet.js deleted file mode 100644 index 29e07df..0000000 --- a/import/tasks/writeExcelSheet.js +++ /dev/null @@ -1,173 +0,0 @@ -const ExcelJS = require('exceljs'); -const easypost = new (require('@easypost/api'))(process.env.EASYPOST_API_KEY); - -module.exports = async function(users, coupons, items, filename) { - const workbook = new ExcelJS.Workbook(); - workbook.creator = 'Ashe Erickson' - workbook.lastModifiedBy = 'Ashe Erickson' - workbook.created = new Date() - workbook.modified = new Date() - - const usersSheet = workbook.addWorksheet('Users', {views:[{state: 'frozen', xSplit: 0, ySplit:1}]}) - const ordersSheet = workbook.addWorksheet('Orders', {views:[{state: 'frozen', xSplit: 0, ySplit:1}]}) - const couponsSheet = workbook.addWorksheet('Coupons', {views:[{state: 'frozen', xSplit: 0, ySplit:1}]}) - - const couponCache = {}; - - - // Write coupons - couponsSheet.columns = [ - {header: 'Coupon Code', width: 20}, - {header: 'Expires', width: 14}, - {header: 'Flat discount', key: 'flat', width: 12}, - {header: '% discount', key: 'percent', width: 10}, - {header: '# Socks free', width: 12}, - {header: 'Per sock discount', key: 'perSock', width: 18}, - {header: 'Free Shipping', width: 15}, - {header: '# Allowed Uses', width: 18}, - {header: '# Times Used', width: 18}, - ] - - for (const coupon of coupons) { - const row = couponsSheet.addRow([ - coupon.code, - new Date(coupon.expires * 1000), - formatMoney(coupon.flatDiscount), - coupon.percentDiscount ? coupon.percentDiscount / 100 : '', - coupon.socksFree || '', - formatMoney(coupon.perSockDiscount), - coupon.freeShipping ? 'Yes' : 'No', - coupon.numAllowedUses, - coupon.uses.length - ]) - - row.eachCell(cell => {cell.alignment = {horizontal: 'left' }}) - - couponCache[coupon._id.toString()] = { - code: coupon.code, - row: row.number - } - } - - // Write users + orders - usersSheet.columns = [ - {header: 'Email', width: 40}, - {header: 'Email Confirmed', width: 10}, - {header: 'Registered', width: 20}, - {header: 'Last Login', width: 20}, - {header: 'Purchases', width: 20}, - {header: 'Admin', width: 20}, - ] - - ordersSheet.columns = [ - {header: 'User', width: 40}, - {header: 'Purchase Date', width: 14}, - {header: 'Shipment Date', width: 14}, - {header: 'Items', width: 60}, - {header: 'Item Subtotal', key: 'itemCost', width: 20}, - {header: 'Shipping Estimate', key: 'shippingEst', width: 20}, - {header: 'Shipping Actual', key: 'shippingCost', width: 20}, - {header: 'Total Paid', key: 'totalCost', width: 20}, - {header: 'Coupon', key: 'coupon', width: 20}, - {header: 'Tracking Code', width: 20}, - {header: 'Address', width: 20}, - ] - - const usersWithPurchases = users.filter(user => user.purchases?.length); - usersWithPurchases.sort((a,b) => (a.email || 'zzzz').localeCompare(b.email || 'zzzz')) - - let userNum = 0; - for(const user of usersWithPurchases) { - if (user.purchases?.length < 1) continue; - userNum++ - - const creationDate = new Date(parseInt(user._id.toString().slice(0,8), 16)*1000) - const userID = user.email || user._id.toString(); - const firstOrderRow = ordersSheet.rowCount + 1; - const userRow = usersSheet.rowCount + 1; - - - console.log(` (${userNum}/${usersWithPurchases.length}) Retrieving shipment + address info for orders by user ${userID}`) - - for(const purchase of user.purchases) { - const shipmentPromise = easypost.Shipment.retrieve(purchase.shipment); - const addressPromise = easypost.Address.retrieve(purchase.address); - - try { - purchase.shipment = await shipmentPromise; - purchase.address = await addressPromise; - } catch { - console.warn(` Unable to retrieve info for order ${purchase._id}`) - } - - if (purchase.shipment?.tracker?.id) { - easypost.Tracker.retrieve(purchase.shipment.tracker.id).then(tracker => { - purchase.shipment.tracker = tracker - }).catch(() => {}) - } - - const coupon = couponCache[purchase.coupon] - const trackingCode = purchase.shipment?.tracking_code || purchase.trackingCode - const trackingLink = purchase.shipment?.tracker?.public_url || `https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=${trackingCode}` - - const row = ordersSheet.addRow([ - user.email ? {formula: `=HYPERLINK("#'Users'!A${userRow}", "${userID}")`} : userID, - purchase.purchaseTime ? new Date(purchase.purchaseTime) : '', - purchase.shippedOn ? new Date(purchase.shippedOn) : '', - purchase.items.map(id => items.find(item => item._id.toString() === id.toString()).urlslug).join(', '), - formatMoney(purchase.sockPrice), - formatMoney(purchase.shippingEstimate), - formatMoney(purchase.shipment?.selected_rate?.rate), - formatMoney(purchase.totalPrice), - coupon ? {formula: `=HYPERLINK("#'Coupons'!A${coupon.row}","${coupon.code}")`} : '', - trackingCode ? {formula: `=HYPERLINK("${trackingLink}", "${trackingCode}")`} : "", - formatAddress(purchase.address) - ]) - - row.eachCell(cell => {cell.alignment = {horizontal: 'left' }}) - } - - if (!user.email) continue; - - const row = usersSheet.addRow([ - userID, - user.emailConfirmed ? 'Yes' : 'No', - creationDate, - user.lastLogin ? new Date(user.lastLogin) : '', - {formula: `=HYPERLINK("#'Orders'!A${firstOrderRow}", "${user.purchases.length} purchase${user.purchases.length > 1 ? "s" : ""}")`}, - user.isAdmin ? 'Yes' : 'No' - ]) - - row.eachCell(cell => {cell.alignment = {horizontal: 'left' }}) - } - - ordersSheet.getColumn('itemCost').eachCell(cell => {cell.numFmt = '$0.00'}) - ordersSheet.getColumn('shippingEst').eachCell(cell => {cell.numFmt = '$0.00'}) - ordersSheet.getColumn('shippingCost').eachCell(cell => {cell.numFmt = '$0.00'}) - ordersSheet.getColumn('totalCost').eachCell(cell => {cell.numFmt = '$0.00'}) - - couponsSheet.getColumn('flat').eachCell(cell => {cell.numFmt = '$0.00'}) - couponsSheet.getColumn('percent').eachCell(cell => {cell.numFmt = '0%'}) - couponsSheet.getColumn('perSock').eachCell(cell => {cell.numFmt = '$0.00'}) - - await workbook.xlsx.writeFile(filename); -} - -function formatMoney(value) { - if(value === undefined) return '' - if(value === '') return '' - if(value === 0) return '' - - if(typeof value === 'string') - return parseFloat(value); - - - return value -} - -function formatAddress(address) { - if(typeof address !== 'object') - return address - - return `${address.name || ""} | ${address.company ? address.company + "| " : ""}${address.street1} | ${address.street2 ? address.street2 + "| " : ""}${address.city} | ${address.state} | ${address.country} | ${address.zip}` -} \ No newline at end of file