diff --git a/libs/velo-external-db-core/src/converters/data_utils.ts b/libs/velo-external-db-core/src/converters/data_utils.ts index 0281f38c0..ed839fe9b 100644 --- a/libs/velo-external-db-core/src/converters/data_utils.ts +++ b/libs/velo-external-db-core/src/converters/data_utils.ts @@ -11,12 +11,19 @@ export const asWixDataItem = (item: Item) => { return { item: asWixData(item) } } +const replaceNonAlphanumeric = (str: string) => { + // Replace non-alphanumeric characters with dashes + return str.replace(/[^a-zA-Z0-9]/g, '-') +} + export const generateIdsIfNeeded = (item: Item): ItemWithId => { if ('_id' in item) return item as ItemWithId const sha = crypto.createHash('sha1') const fieldsConcat = Object.values(item).join('') - return { ...item, _id: sha.update(fieldsConcat).digest('base64') } + const base64Digest = sha.update(fieldsConcat).digest('base64') + const validId = replaceNonAlphanumeric(base64Digest) + return { ...item, _id: validId } } const packDates = (item: Item) => Object.entries(item)