From 6c4e580cf1878e78b038e69435f06e65cc2cbef7 Mon Sep 17 00:00:00 2001 From: Chia Automation Date: Thu, 5 Oct 2023 18:08:24 +0000 Subject: [PATCH 1/8] chore: Updating npm dev dependencies --- package-lock.json | 71 +++++++++++++++++++++++------------------------ package.json | 2 +- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c93f184..70284f98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cadt", - "version": "1.6.12", + "version": "1.6.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cadt", - "version": "1.6.12", + "version": "1.6.14", "dependencies": { "@babel/eslint-parser": "^7.22.9", "body-parser": "^1.20.2", @@ -54,7 +54,7 @@ "husky": "^8.0.3", "mocha": "^10.2.0", "semver": "^7.5.4", - "sinon": "^16.0.0", + "sinon": "^16.1.0", "socket.io-client": "^4.7.2", "standard-version": "^9.5.0", "supertest": "^6.3.3" @@ -2344,9 +2344,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.0.tgz", - "integrity": "sha512-zJmuCWj2VLBt4c25CfBIbMZLGLyhkvs7LznyVX5HfpzeocThgIj5XQK4L+g3U36mMcx8bPMhGyPpwCATamC4jQ==", + "version": "4.9.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.1.tgz", + "integrity": "sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA==", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } @@ -2389,9 +2389,9 @@ } }, "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "13.22.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.22.0.tgz", - "integrity": "sha512-H1Ddc/PbZHTDVJSnj8kWptIRSD6AM3pK+mKytuIVF4uoBV7rshFlhhvA58ceJ5wp3Er58w6zj7bykMpYXt3ETw==", + "version": "13.23.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", + "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", "dependencies": { "type-fest": "^0.20.2" }, @@ -3442,9 +3442,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001541", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001541.tgz", - "integrity": "sha512-bLOsqxDgTqUBkzxbNlSBt8annkDpQB9NdzdTbO2ooJ+eC/IQcvDspDc058g84ejCelF7vHUx57KIOjEecOHXaw==", + "version": "1.0.30001546", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001546.tgz", + "integrity": "sha512-zvtSJwuQFpewSyRrI3AsftF6rM0X80mZkChIt1spBGEvRglCrjTniXvinc8JKRoqTwXAgvqTImaN9igfSMtUBw==", "funding": [ { "type": "opencollective", @@ -4328,12 +4328,12 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" }, "node_modules/core-js-compat": { - "version": "3.32.2", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.32.2.tgz", - "integrity": "sha512-+GjlguTDINOijtVRUxrQOv3kfu9rl+qPNdX2LTbJ/ZyVTuxK+ksVSAGX1nHstu4hrv1En/uPTtWgq2gI5wt4AQ==", + "version": "3.33.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.33.0.tgz", + "integrity": "sha512-0w4LcLXsVEuNkIqwjjf9rjCoPhK8uqA4tMRh4Ge26vfLtUutshn+aRJU21I9LCJlh2QQHfisNToLjw1XEJLTWw==", "dev": true, "dependencies": { - "browserslist": "^4.21.10" + "browserslist": "^4.22.1" }, "funding": { "type": "opencollective", @@ -4728,9 +4728,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.536", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.536.tgz", - "integrity": "sha512-L4VgC/76m6y8WVCgnw5kJy/xs7hXrViCFdNKVG8Y7B2isfwrFryFyJzumh3ugxhd/oB1uEaEEvRdmeLrnd7OFA==" + "version": "1.4.543", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.543.tgz", + "integrity": "sha512-t2ZP4AcGE0iKCCQCBx/K2426crYdxD3YU6l0uK2EO3FZH0pbC4pFz/sZm2ruZsND6hQBTcDWWlo/MLpiOdif5g==" }, "node_modules/emoji-regex": { "version": "8.0.0", @@ -5132,9 +5132,9 @@ } }, "node_modules/eslint/node_modules/globals": { - "version": "13.22.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.22.0.tgz", - "integrity": "sha512-H1Ddc/PbZHTDVJSnj8kWptIRSD6AM3pK+mKytuIVF4uoBV7rshFlhhvA58ceJ5wp3Er58w6zj7bykMpYXt3ETw==", + "version": "13.23.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", + "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", "dependencies": { "type-fest": "^0.20.2" }, @@ -6029,12 +6029,9 @@ } }, "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dependencies": { - "function-bind": "^1.1.1" - }, + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz", + "integrity": "sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==", "engines": { "node": ">= 0.4.0" } @@ -6504,9 +6501,9 @@ } }, "node_modules/joi": { - "version": "17.10.2", - "resolved": "https://registry.npmjs.org/joi/-/joi-17.10.2.tgz", - "integrity": "sha512-hcVhjBxRNW/is3nNLdGLIjkgXetkeGc2wyhydhz8KumG23Aerk4HPjU5zaPAMRqXQFc0xNqXTC7+zQjxr0GlKA==", + "version": "17.11.0", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.11.0.tgz", + "integrity": "sha512-NgB+lZLNoqISVy1rZocE9PZI36bL/77ie924Ri43yEvi9GUUMPeyVIr8KdFTMUlby1p0PBYMk9spIxEUQYqrJQ==", "dependencies": { "@hapi/hoek": "^9.0.0", "@hapi/topo": "^5.0.0", @@ -9128,9 +9125,9 @@ "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" }, "node_modules/sinon": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-16.0.0.tgz", - "integrity": "sha512-B8AaZZm9CT5pqe4l4uWJztfD/mOTa7dL8Qo0W4+s+t74xECOgSZDDQCBjNgIK3+n4kyxQrSTv2V5ul8K25qkiQ==", + "version": "16.1.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-16.1.0.tgz", + "integrity": "sha512-ZSgzF0vwmoa8pq0GEynqfdnpEDyP1PkYmEChnkjW0Vyh8IDlyFEJ+fkMhCP0il6d5cJjPl2PUsnUSAuP5sttOQ==", "dev": true, "dependencies": { "@sinonjs/commons": "^3.0.0", @@ -9366,9 +9363,9 @@ } }, "node_modules/spdx-license-ids": { - "version": "3.0.15", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.15.tgz", - "integrity": "sha512-lpT8hSQp9jAKp9mhtBU4Xjon8LPGBvLIuBiSVhMEtmLecTh2mO0tlqrAMp47tBXzMr13NJMQ2lf7RpQGLJ3HsQ==", + "version": "3.0.16", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.16.tgz", + "integrity": "sha512-eWN+LnM3GR6gPu35WxNgbGl8rmY1AEmoMDvL/QD6zYmPWgywxWqJWNdLGT+ke8dKNWrcYgYjPpG5gbTfghP8rw==", "dev": true }, "node_modules/split": { diff --git a/package.json b/package.json index 2ba866a2..cfedbb80 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "mocha": "^10.2.0", "semver": "^7.5.4", - "sinon": "^16.0.0", + "sinon": "^16.1.0", "socket.io-client": "^4.7.2", "standard-version": "^9.5.0", "supertest": "^6.3.3" From fdf25cf826d363ec5eae0831199e81d473d4fa96 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 11 Oct 2023 09:08:25 -0400 Subject: [PATCH 2/8] fix: change default organization sync interval --- src/tasks/sync-organization-meta.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tasks/sync-organization-meta.js b/src/tasks/sync-organization-meta.js index fb4202dc..fbe03827 100644 --- a/src/tasks/sync-organization-meta.js +++ b/src/tasks/sync-organization-meta.js @@ -25,7 +25,7 @@ const task = new Task('sync-organization-meta', async () => { } catch (error) { logger.error( `Retrying in ${ - CONFIG?.APP?.TASKS?.ORGANIZATION_META_SYNC_TASK_INTERVAL || 86400 + CONFIG?.APP?.TASKS?.ORGANIZATION_META_SYNC_TASK_INTERVAL || 300 } seconds`, error, ); @@ -35,7 +35,7 @@ const task = new Task('sync-organization-meta', async () => { const job = new SimpleIntervalJob( { // DEFAULT 1 - seconds: CONFIG?.APP?.TASKS?.ORGANIZATION_META_SYNC_TASK_INTERVAL || 86400, + seconds: CONFIG?.APP?.TASKS?.ORGANIZATION_META_SYNC_TASK_INTERVAL || 300, runImmediately: true, }, task, From 7855be95a7236d55565134e05483710b17e1e022 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 11 Oct 2023 09:22:10 -0400 Subject: [PATCH 3/8] feat: remove meta_ prefix from metadata keys --- src/controllers/organization.controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index 7ec3823f..a2cd5dad 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -385,7 +385,15 @@ export const getMetaData = async (req, res) => { where: { orgUid: req.query.orgUid }, }); - return res.json(JSON.parse(organization.metadata)); + const rawMetadata = JSON.parse(organization.metadata); + const cleanedMetadata = {}; + + for (const [key, value] of Object.entries(rawMetadata)) { + const newKey = key.startsWith('meta_') ? key.substring(5) : key; + cleanedMetadata[newKey] = value; + } + + return res.json(cleanedMetadata); } catch (error) { res.status(400).json({ message: 'Error getting metadata for organization', From 5ae708bee2762e10df5b38dfd0c0d06555763861 Mon Sep 17 00:00:00 2001 From: Michael Taylor <5665004+MichaelTaylor3D@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:00:49 -0400 Subject: [PATCH 4/8] Revert "feat: remove meta_ prefix from metadata keys" --- src/controllers/organization.controller.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index a2cd5dad..7ec3823f 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -385,15 +385,7 @@ export const getMetaData = async (req, res) => { where: { orgUid: req.query.orgUid }, }); - const rawMetadata = JSON.parse(organization.metadata); - const cleanedMetadata = {}; - - for (const [key, value] of Object.entries(rawMetadata)) { - const newKey = key.startsWith('meta_') ? key.substring(5) : key; - cleanedMetadata[newKey] = value; - } - - return res.json(cleanedMetadata); + return res.json(JSON.parse(organization.metadata)); } catch (error) { res.status(400).json({ message: 'Error getting metadata for organization', From 78338463d5ad433fc88439137c94f935cfd1cbd6 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 17 Oct 2023 17:15:23 -0400 Subject: [PATCH 5/8] feat: add some error handling --- src/datalayer/syncService.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/datalayer/syncService.js b/src/datalayer/syncService.js index 4a06a08c..42081bcd 100644 --- a/src/datalayer/syncService.js +++ b/src/datalayer/syncService.js @@ -288,16 +288,21 @@ const getRootDiff = (storeId, root1, root2) => { }; const getStoreData = async (storeId, callback, onFail, retry = 0) => { - logger.info(`Getting store data, retry: ${retry}`); - if (retry <= 10) { - const encodedData = await dataLayer.getStoreData(storeId); - if (_.isEmpty(encodedData?.keys_values)) { - await new Promise((resolve) => setTimeout(() => resolve(), 120000)); - return getStoreData(storeId, callback, onFail, retry + 1); + try { + logger.info(`Getting store data, retry: ${retry}`); + if (retry <= 10) { + const encodedData = await dataLayer.getStoreData(storeId); + if (_.isEmpty(encodedData?.keys_values)) { + await new Promise((resolve) => setTimeout(() => resolve(), 120000)); + return getStoreData(storeId, callback, onFail, retry + 1); + } else { + callback(decodeDataLayerResponse(encodedData)); + } } else { - callback(decodeDataLayerResponse(encodedData)); + onFail(); } - } else { + } catch (error) { + logger.error(error.message); onFail(); } }; From ca66c9cee79a64a143aeeea00dfb6c9b7bd8d495 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 20 Oct 2023 12:03:54 -0400 Subject: [PATCH 6/8] fix: improved organization sync --- .jshintrc | 3 + src/datalayer/persistance.js | 18 +-- src/datalayer/syncService.js | 78 ++++++++---- .../organizations/organizations.model.js | 118 ++++++++++-------- 4 files changed, 129 insertions(+), 88 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..711f4c4f --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esversion": 11 +} diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index 5e25fcab..99272bb9 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -302,12 +302,17 @@ const getStoreData = async (storeId, rootHash) => { } return data; } + + logger.error( + `FAILED GETTING STORE DATA FOR ${storeId}: ${JSON.stringify(data)}`, + ); } catch (error) { logger.info( `Unable to find store data for ${storeId} at root ${ rootHash || 'latest' }`, ); + logger.error(error.message); return false; } } @@ -330,20 +335,15 @@ const getRoot = async (storeId, ignoreEmptyStore = false) => { .timeout(timeout) .send({ id: storeId }); - const data = response.body; + const { confirmed, hash } = response.body; - if ( - (data.confirmed && !ignoreEmptyStore) || - (data.confirmed && - ignoreEmptyStore && - !data.hash.includes('0x00000000000')) - ) { - return data; + if (confirmed && (!ignoreEmptyStore || !hash.includes('0x00000000000'))) { + return response.body; } return false; } catch (error) { - logger.error(error); + logger.error(error.message); return false; } }; diff --git a/src/datalayer/syncService.js b/src/datalayer/syncService.js index 42081bcd..9c9f49dc 100644 --- a/src/datalayer/syncService.js +++ b/src/datalayer/syncService.js @@ -287,23 +287,39 @@ const getRootDiff = (storeId, root1, root2) => { } }; -const getStoreData = async (storeId, callback, onFail, retry = 0) => { +/** + * Fetches store data and invokes either a callback or an error handler. + * + * @param {string} storeId - The ID of the store to fetch data for. + * @param {Function} callback - Function to call on successful data retrieval. + * @param {Function} onFail - Function to call when data retrieval fails. + * @param {number} retry - Number of retry attempts. + */ +const getStoreData = async (storeId, callback, onFail, rootHash, retry = 0) => { + const MAX_RETRIES = 50; + const RETRY_DELAY = 120000; + try { logger.info(`Getting store data, retry: ${retry}`); - if (retry <= 10) { - const encodedData = await dataLayer.getStoreData(storeId); - if (_.isEmpty(encodedData?.keys_values)) { - await new Promise((resolve) => setTimeout(() => resolve(), 120000)); - return getStoreData(storeId, callback, onFail, retry + 1); - } else { - callback(decodeDataLayerResponse(encodedData)); - } - } else { - onFail(); + + if (retry > MAX_RETRIES) { + return onFail(`Max retries exceeded for store ${storeId}`); } + + const encodedData = await dataLayer.getStoreData(storeId, rootHash); + + if (!encodedData || _.isEmpty(encodedData?.keys_values)) { + logger.debug(`No data found for store ${storeId}, retrying...`); + await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY)); + return getStoreData(storeId, callback, onFail, rootHash, retry + 1); + } + + const decodedData = decodeDataLayerResponse(encodedData); + + callback(decodedData); } catch (error) { logger.error(error.message); - onFail(); + onFail(error.message); } }; @@ -320,18 +336,32 @@ const getCurrentStoreData = async (storeId) => { } }; -const getStoreIfUpdated = async ( - storeId, - lastRootHash, - onUpdate, - callback, - onFail, -) => { - const rootResponse = await dataLayer.getRoot(storeId); - if (rootResponse.confirmed && rootResponse.hash !== lastRootHash) { - logger.debug(`Updating orgUid ${storeId} with hash ${rootResponse.hash}`); - onUpdate(rootResponse.hash); - await getStoreData(storeId, callback, onFail); +/** + * Checks if the store data has been updated and triggers the appropriate callbacks. + * + * @param {string} storeId - The ID of the store to check. + * @param {string} lastRootHash - The last known root hash for comparison. + * @param {function} callback - Callback to invoke to process the store data. + * @param {function} onFail - Callback to invoke if an operation fails. + */ +const getStoreIfUpdated = async (storeId, lastRootHash, callback, onFail) => { + try { + const rootResponse = await dataLayer.getRoot(storeId); + + if (rootResponse.confirmed && rootResponse.hash !== lastRootHash) { + const curriedCallback = (data) => callback(rootResponse.hash, data); + + await getStoreData( + storeId, + curriedCallback, + onFail, + rootResponse.hash, + 0, + ); + } + } catch (error) { + logger.error(error.message); + onFail(error.message); } }; diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index 79b0a3f7..88d7f02e 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -256,8 +256,7 @@ class Organization extends Model { }); } - // eslint-disable-next-line - static importOrganization = async (orgUid) => { + static async importOrganization(orgUid) { try { console.log('Importing organization ' + orgUid); const orgData = await datalayer.getSubscribedStoreData(orgUid); @@ -310,10 +309,9 @@ class Organization extends Model { } catch (error) { logger.info(error.message); } - }; + } - // eslint-disable-next-line - static subscribeToOrganization = async (orgUid) => { + static async subscribeToOrganization(orgUid) { const exists = await Organization.findOne({ where: { orgUid } }); if (exists) { await Organization.update({ subscribed: true }, { where: { orgUid } }); @@ -322,65 +320,75 @@ class Organization extends Model { 'Can not subscribe, please import this organization first', ); } - }; + } - // eslint-disable-next-line - static unsubscribeToOrganization = async (orgUid) => { + static async unsubscribeToOrganization(orgUid) { await Organization.update({ subscribed: false }, { orgUid }); - }; + } - static syncOrganizationMeta = async () => { + /** + * Synchronizes metadata for all subscribed organizations. + */ + static async syncOrganizationMeta() { try { const allSubscribedOrganizations = await Organization.findAll({ subscribed: true, }); await Promise.all( - allSubscribedOrganizations.map((organization) => { - const onResult = (data) => { - const updateData = data - .filter((pair) => !pair.key.includes('meta_')) - .reduce((update, current) => { - update[current.key] = current.value; - return update; - }, {}); - - // will return metadata fields. i.e.: { meta_key1: 'value1', meta_key2: 'value2' } - const metadata = data - .filter((pair) => pair.key.includes('meta_')) - .reduce((update, current) => { - update[current.key] = current.value; - return update; - }, {}); - - Organization.update( - { - ..._.omit(updateData, ['registryId']), - metadata: JSON.stringify(metadata), - }, - { - where: { orgUid: organization.orgUid }, - }, - ); - }; - - const onUpdate = (updateHash) => { + allSubscribedOrganizations.map(async (organization) => { + const processData = (data, keyFilter) => + data + .filter(({ key }) => keyFilter(key)) + .reduce( + (update, { key, value }) => ({ ...update, [key]: value }), + {}, + ); + + const onFail = (message) => { + logger.info(`Unable to sync metadata from ${organization.orgUid}`); + logger.error(`ORGANIZATION DATA SYNC ERROR: ${message}`); Organization.update( - { orgHash: updateHash }, - { - where: { orgUid: organization.orgUid }, - }, + { orgHash: '0' }, + { where: { orgUid: organization.orgUid } }, ); }; - const onFail = () => { - logger.info(`Unable to sync metadata from ${organization.orgUid}`); + const onResult = async (updateHash, data) => { + try { + const updateData = processData( + data, + (key) => !key.includes('meta_'), + ); + const metadata = processData(data, (key) => + key.includes('meta_'), + ); + + await Organization.update( + { + ..._.omit(updateData, ['registryId']), + prefix: updateData.prefix || '0', + metadata: JSON.stringify(metadata), + }, + { where: { orgUid: organization.orgUid } }, + ); + + logger.debug( + `Updating orgUid ${organization.orgUid} with hash ${updateHash}`, + ); + await Organization.update( + { orgHash: updateHash }, + { where: { orgUid: organization.orgUid } }, + ); + } catch (error) { + logger.info(error.message); + onFail(error.message); + } }; datalayer.getStoreIfUpdated( organization.orgUid, organization.orgHash, - onUpdate, onResult, onFail, ); @@ -389,9 +397,9 @@ class Organization extends Model { } catch (error) { logger.info(error.message); } - }; + } - static subscribeToDefaultOrganizations = async () => { + static async subscribeToDefaultOrganizations() { try { const defaultOrgs = await getDefaultOrganizationList(); if (!Array.isArray(defaultOrgs)) { @@ -414,9 +422,9 @@ class Organization extends Model { } catch (error) { logger.info(error); } - }; + } - static editOrgMeta = async ({ name, icon }) => { + static async editOrgMeta({ name, icon }) { const myOrganization = await Organization.getHomeOrg(); const payload = {}; @@ -430,20 +438,20 @@ class Organization extends Model { } await datalayer.upsertDataLayer(myOrganization.orgUid, payload); - }; + } - static addMetadata = async (payload) => { + static async addMetadata(payload) { const myOrganization = await Organization.getHomeOrg(); // Prefix keys with "meta_" const metadata = _.mapKeys(payload, (_value, key) => `meta_${key}`); await datalayer.upsertDataLayer(myOrganization.orgUid, metadata); - }; + } - static removeMirror = async (storeId, coinId) => { + static async removeMirror(storeId, coinId) { datalayer.removeMirror(storeId, coinId); - }; + } } Organization.init(ModelTypes, { From 7e9c9cea65ad20d398162db3bb299ad4650d9f42 Mon Sep 17 00:00:00 2001 From: Michael Taylor <5665004+MichaelTaylor3D@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:45:22 -0400 Subject: [PATCH 7/8] Revert "Revert "feat: remove meta_ prefix from metadata keys"" --- src/controllers/organization.controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index 7ec3823f..a2cd5dad 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -385,7 +385,15 @@ export const getMetaData = async (req, res) => { where: { orgUid: req.query.orgUid }, }); - return res.json(JSON.parse(organization.metadata)); + const rawMetadata = JSON.parse(organization.metadata); + const cleanedMetadata = {}; + + for (const [key, value] of Object.entries(rawMetadata)) { + const newKey = key.startsWith('meta_') ? key.substring(5) : key; + cleanedMetadata[newKey] = value; + } + + return res.json(cleanedMetadata); } catch (error) { res.status(400).json({ message: 'Error getting metadata for organization', From 1bfc3b159420adfeef914a923b142ef4e11581da Mon Sep 17 00:00:00 2001 From: Zachary Brown Date: Fri, 20 Oct 2023 13:45:07 -0700 Subject: [PATCH 8/8] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cfedbb80..4b9ef371 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cadt", - "version": "1.6.14", + "version": "1.6.15", "_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2", "private": true, "bin": "build/server.js",