diff --git a/package-lock.json b/package-lock.json index 83c7b18..5b46628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "backend-manager", - "version": "2.5.59", + "version": "2.5.62", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "backend-manager", - "version": "2.5.59", + "version": "2.5.62", "license": "ISC", "dependencies": { "@firebase/rules-unit-testing": "^2.0.7", "@google-cloud/storage": "^5.20.5", "@sendgrid/mail": "^7.7.0", "@sentry/node": "^6.19.7", - "backend-assistant": "^1.0.0", + "backend-assistant": "^1.0.1", "busboy": "^1.6.0", "chalk": "^4.1.2", "cors": "^2.8.5", @@ -1492,15 +1492,15 @@ } }, "node_modules/backend-assistant": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/backend-assistant/-/backend-assistant-1.0.0.tgz", - "integrity": "sha512-k/DxzdKSLTOTsskVcJZqkxNKennMrYvyZem6qqNyNbt46K5IMm+x6zIilLBJTO7SAqR/wgO6ive+g5+vVomMPA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/backend-assistant/-/backend-assistant-1.0.1.tgz", + "integrity": "sha512-QjJqhE2QTk4qIik9tTbx0P846gXsKQkzVTx2BGXjrsSBbNpnkUg1+oofhW8XSyGUTiIIfKb2zcmOYNAMCM1Ajg==", "dependencies": { "busboy": "^1.6.0", "fs-jetpack": "^4.3.1", - "json5": "^2.2.1", + "json5": "^2.2.3", "lodash": "^4.17.21", - "resolve-account": "^0.0.5", + "resolve-account": "^0.0.8", "uuid": "^8.3.2" } }, @@ -3989,9 +3989,9 @@ } }, "node_modules/resolve-account": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/resolve-account/-/resolve-account-0.0.5.tgz", - "integrity": "sha512-DAccfGAGOoU0uGRPk7vX0OtphOAqsbtpNg5XrWbe5lh3v7lBFT5Qg54BOFt/GXW5dYBSQVuSEZwWAM/3fhrNVQ==", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/resolve-account/-/resolve-account-0.0.8.tgz", + "integrity": "sha512-wKaa6sdSc9b5bQcbNrOCwE4+i5Y4g9GgYUKAC7/js6AdmDf2eay3kyaxjQaelhuKZG/uwlQ7qdSeGR5hk3DCqA==", "engines": { "node": ">=6.0.0" } @@ -6117,15 +6117,15 @@ } }, "backend-assistant": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/backend-assistant/-/backend-assistant-1.0.0.tgz", - "integrity": "sha512-k/DxzdKSLTOTsskVcJZqkxNKennMrYvyZem6qqNyNbt46K5IMm+x6zIilLBJTO7SAqR/wgO6ive+g5+vVomMPA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/backend-assistant/-/backend-assistant-1.0.1.tgz", + "integrity": "sha512-QjJqhE2QTk4qIik9tTbx0P846gXsKQkzVTx2BGXjrsSBbNpnkUg1+oofhW8XSyGUTiIIfKb2zcmOYNAMCM1Ajg==", "requires": { "busboy": "^1.6.0", "fs-jetpack": "^4.3.1", - "json5": "^2.2.1", + "json5": "^2.2.3", "lodash": "^4.17.21", - "resolve-account": "^0.0.5", + "resolve-account": "^0.0.8", "uuid": "^8.3.2" } }, @@ -8079,9 +8079,9 @@ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==" }, "resolve-account": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/resolve-account/-/resolve-account-0.0.5.tgz", - "integrity": "sha512-DAccfGAGOoU0uGRPk7vX0OtphOAqsbtpNg5XrWbe5lh3v7lBFT5Qg54BOFt/GXW5dYBSQVuSEZwWAM/3fhrNVQ==" + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/resolve-account/-/resolve-account-0.0.8.tgz", + "integrity": "sha512-wKaa6sdSc9b5bQcbNrOCwE4+i5Y4g9GgYUKAC7/js6AdmDf2eay3kyaxjQaelhuKZG/uwlQ7qdSeGR5hk3DCqA==" }, "restore-cursor": { "version": "3.1.0", diff --git a/package.json b/package.json index 1c73dfd..a6400db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backend-manager", - "version": "2.5.62", + "version": "2.5.63", "description": "Quick tools for developing Firebase functions", "main": "src/manager/index.js", "bin": { @@ -31,7 +31,7 @@ "@google-cloud/storage": "^5.20.5", "@sendgrid/mail": "^7.7.0", "@sentry/node": "^6.19.7", - "backend-assistant": "^1.0.0", + "backend-assistant": "^1.0.1", "busboy": "^1.6.0", "chalk": "^4.1.2", "cors": "^2.8.5", diff --git a/src/manager/functions/core/actions/api/user/get-subscription-info.js b/src/manager/functions/core/actions/api/user/get-subscription-info.js index 65bc221..582f230 100644 --- a/src/manager/functions/core/actions/api/user/get-subscription-info.js +++ b/src/manager/functions/core/actions/api/user/get-subscription-info.js @@ -1,4 +1,5 @@ const _ = require('lodash') +const powertools = require('node-powertools') function Module() { @@ -12,11 +13,25 @@ Module.prototype.main = function () { const payload = self.payload; return new Promise(async function(resolve, reject) { + const oldDate = powertools.timestamp(new Date(0), {output: 'string'}) + const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'}); + self.Api.resolveUser({adminRequired: false}) .then(async (user) => { const result = { plan: { id: _.get(user, 'plan.id', 'unknown'), + expires: { + timestamp: _.get(user, 'plan.expires.timestamp', oldDate), + timestampUNIX: _.get(user, 'plan.expires.timestampUNIX', oldDateUNIX), + }, + trial: { + activated: _.get(user, 'plan.trial.activated', false), + date: { + timestamp: _.get(user, 'plan.trial.date.timestamp', oldDate), + timestampUNIX: _.get(user, 'plan.trial.date.timestampUNIX', oldDateUNIX), + } + }, payment: { active: _.get(user, 'plan.payment.active', false), }, diff --git a/src/manager/helpers/user.js b/src/manager/helpers/user.js index 143f5fb..4e48ef0 100644 --- a/src/manager/helpers/user.js +++ b/src/manager/helpers/user.js @@ -6,13 +6,15 @@ const UIDGenerator = require('uid-generator'); const uidgen = new UIDGenerator(256); function User(settings, options) { - let self = this; + const self = this; + settings = settings || {}; options = options || {}; - let now = powertools.timestamp(new Date(), {output: 'string'}); - let nowUNIX = powertools.timestamp(now, {output: 'unix'}); - let oldDate = powertools.timestamp(new Date(0), {output: 'string'}) - let oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'}); + + const now = powertools.timestamp(new Date(), {output: 'string'}); + const nowUNIX = powertools.timestamp(now, {output: 'unix'}); + const oldDate = powertools.timestamp(new Date(0), {output: 'string'}) + const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'}); const useDefaults = typeof options.defaults === 'undefined' ? true : options.defaults; @@ -33,6 +35,13 @@ function User(settings, options) { timestamp: _.get(settings, 'plan.expires.timestamp', useDefaults ? oldDate : null), timestampUNIX: _.get(settings, 'plan.expires.timestampUNIX', useDefaults ? oldDateUNIX : null), }, + trial: { + activated: _.get(settings, 'plan.trial.activated', useDefaults ? false : null), + date: { + timestamp: _.get(settings, 'plan.trial.date.timestamp', useDefaults ? oldDate : null), + timestampUNIX: _.get(settings, 'plan.trial.date.timestampUNIX', useDefaults ? oldDateUNIX : null), + } + }, limits: { // devices: _.get(settings, 'plan.limits.devices', null), }, @@ -77,6 +86,25 @@ function User(settings, options) { clientId: _.get(settings, 'api.clientId', useDefaults ? `${uuid4()}` : null), privateKey: _.get(settings, 'api.privateKey', useDefaults ? `${uidgen.generateSync()}` : null), }, + personal: { + birthday: { + timestamp: _.get(settings, 'personal.birthday.timestamp', useDefaults ? oldDate : null), + timestampUNIX: _.get(settings, 'personal.birthday.timestampUNIX', useDefaults ? oldDateUNIX : null), + }, + gender: _.get(settings, 'personal.gender', useDefaults ? 'undisclosed' : null), + location: { + city: _.get(settings, 'personal.location.city', useDefaults ? 'undisclosed' : null), + country: _.get(settings, 'personal.location.country', useDefaults ? 'ZZ' : null), + }, + name: { + first: _.get(settings, 'personal.name.first', useDefaults ? 'undisclosed' : null), + last: _.get(settings, 'personal.name.last', useDefaults ? 'undisclosed' : null), + }, + telephone: { + countryCode: _.get(settings, 'personal.telephone.countryCode', useDefaults ? 0 : null), + national: _.get(settings, 'personal.telephone.national', useDefaults ? 0 : null), + }, + }, } if (options.prune) {