diff --git a/package-lock.json b/package-lock.json index f93ec5c1..59241b62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19867,7 +19867,7 @@ }, "packages/spacecat-shared-data-access": { "name": "@adobe/spacecat-shared-data-access", - "version": "1.61.16", + "version": "1.61.18", "license": "Apache-2.0", "dependencies": { "@adobe/spacecat-shared-dynamo": "1.5.1", @@ -25571,7 +25571,7 @@ }, "packages/spacecat-shared-rum-api-client": { "name": "@adobe/spacecat-shared-rum-api-client", - "version": "2.17.2", + "version": "2.18.0", "license": "Apache-2.0", "dependencies": { "@adobe/fetch": "4.1.11", @@ -25664,7 +25664,8 @@ "@aws-sdk/client-secrets-manager": "3.721.0", "@aws-sdk/client-sqs": "3.721.0", "@json2csv/plainjs": "7.0.6", - "aws-xray-sdk": "3.10.2" + "aws-xray-sdk": "3.10.2", + "uuid": "11.0.4" }, "devDependencies": { "@adobe/helix-shared-wrap": "2.0.2", @@ -25704,6 +25705,20 @@ "npm": ">=10.0.0 <12.0.0" } }, + "packages/spacecat-shared-utils/node_modules/@adobe/spacecat-shared-data-access/node_modules/uuid": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.3.tgz", + "integrity": "sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } + }, "packages/spacecat-shared-utils/node_modules/@adobe/spacecat-shared-dynamo": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-dynamo/-/spacecat-shared-dynamo-1.5.0.tgz", @@ -27405,6 +27420,19 @@ "engines": { "node": ">=16.0.0" } + }, + "packages/spacecat-shared-utils/node_modules/uuid": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.4.tgz", + "integrity": "sha512-IzL6VtTTYcAhA/oghbFJ1Dkmqev+FpQWnCBaKq/gUluLxliWvO8DPFWfIviRmYbtaavtSQe4WBL++rFjdcGWEg==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } } } } diff --git a/packages/spacecat-shared-utils/package.json b/packages/spacecat-shared-utils/package.json index 51a4682d..a11830a3 100644 --- a/packages/spacecat-shared-utils/package.json +++ b/packages/spacecat-shared-utils/package.json @@ -49,6 +49,7 @@ "@aws-sdk/client-secrets-manager": "3.721.0", "@aws-sdk/client-sqs": "3.721.0", "@json2csv/plainjs": "7.0.6", - "aws-xray-sdk": "3.10.2" + "aws-xray-sdk": "3.10.2", + "uuid": "11.0.4" } } diff --git a/packages/spacecat-shared-utils/src/functions.js b/packages/spacecat-shared-utils/src/functions.js index 913524ed..b5d00a06 100644 --- a/packages/spacecat-shared-utils/src/functions.js +++ b/packages/spacecat-shared-utils/src/functions.js @@ -10,6 +10,8 @@ * governing permissions and limitations under the License. */ +import { validate as uuidValidate } from 'uuid'; + // Precompile regular expressions const REGEX_ISO_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/; const REGEX_TIME_OFFSET_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}(Z|[+-]\d{2}:\d{2})/; @@ -194,6 +196,15 @@ function isValidUrl(urlString) { } } +/** + * Validates whether the given string is a valid UUID. + * @param {string} uuid - The string to validate. + * @return {boolean} True if the given string is a valid UUID. + */ +function isValidUUID(uuid) { + return uuidValidate(uuid); +} + /** * Converts a given value to a boolean. Throws an error if the value is not a boolean. * @@ -257,5 +268,6 @@ export { isString, isValidDate, isValidUrl, + isValidUUID, toBoolean, }; diff --git a/packages/spacecat-shared-utils/src/index.d.ts b/packages/spacecat-shared-utils/src/index.d.ts index 90f5f74b..be7368b1 100644 --- a/packages/spacecat-shared-utils/src/index.d.ts +++ b/packages/spacecat-shared-utils/src/index.d.ts @@ -43,6 +43,8 @@ export function toBoolean(value: unknown): boolean; export function isValidUrl(urlString: string): boolean; +export function isValidUUID(uuid: string): boolean; + export function dateAfterDays(days: number, dateString: string): Date; export function deepEqual(a: unknown, b: unknown): boolean; diff --git a/packages/spacecat-shared-utils/src/index.js b/packages/spacecat-shared-utils/src/index.js index 17c6b8b9..1757439c 100644 --- a/packages/spacecat-shared-utils/src/index.js +++ b/packages/spacecat-shared-utils/src/index.js @@ -27,6 +27,7 @@ export { isString, isValidDate, isValidUrl, + isValidUUID, toBoolean, } from './functions.js'; diff --git a/packages/spacecat-shared-utils/test/functions.test.js b/packages/spacecat-shared-utils/test/functions.test.js index 8772afd8..5fee7c81 100644 --- a/packages/spacecat-shared-utils/test/functions.test.js +++ b/packages/spacecat-shared-utils/test/functions.test.js @@ -33,6 +33,7 @@ import { isString, isValidDate, isValidUrl, + isValidUUID, toBoolean, } from '../src/index.js'; @@ -320,6 +321,25 @@ describe('Shared functions', () => { }); }); + describe('isValidUUID', () => { + it('returns false for invalid UUID', async () => { + const invalidUUIDs = [ + null, + undefined, + 1234, + true, + 'invalid uuid', + '123e4567-e89b-12d3-a456-42661417', + ]; + + invalidUUIDs.forEach((uuid) => expect(isValidUUID(uuid)).to.be.false); + }); + + it('returns true for valid UUID', async () => { + expect(isValidUUID('123e4567-e89b-12d3-a456-426614174000')).to.be.true; + }); + }); + describe('dateAfterDays', () => { const sandbox = sinon.createSandbox(); diff --git a/packages/spacecat-shared-utils/test/index.test.js b/packages/spacecat-shared-utils/test/index.test.js index 237ec09b..7f20576a 100644 --- a/packages/spacecat-shared-utils/test/index.test.js +++ b/packages/spacecat-shared-utils/test/index.test.js @@ -39,6 +39,7 @@ describe('Index Exports', () => { 'isString', 'isValidDate', 'isValidUrl', + 'isValidUUID', 'logWrapper', 'prependSchema', 'resolveCustomerSecretsName',