Skip to content

Commit

Permalink
chore: handled stringifcation in convertToUuid
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna2020 committed Nov 21, 2024
1 parent 82ffd9b commit 5360d14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/v0/destinations/airship/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ const { JSON_MIME_TYPE } = require('../../util/constant');
const DEFAULT_ACCEPT_HEADER = 'application/vnd.urbanairship+json; version=3';

const transformSessionId = (rawSessionId) => {
const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace
if (!sessionId) {
throw new InstrumentationError(
'Invalid session ID: must be a non-empty string after conversion to string.',
);
try {
return convertToUuid(rawSessionId);
} catch (error) {
throw new InstrumentationError(`Failed to transform session ID: ${error.message}`);

Check warning on line 35 in src/v0/destinations/airship/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/airship/transform.js#L35

Added line #L35 was not covered by tests
}
return convertToUuid(sessionId); // Return the validated and converted session ID
};

const identifyResponseBuilder = (message, { Config }) => {
Expand Down
10 changes: 9 additions & 1 deletion src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,15 @@ const isEventSentByVDMV2Flow = (event) =>
const convertToUuid = (input) => {
const NAMESPACE = v5.DNS;
try {
return v5(input, NAMESPACE);
// Stringify and trim the input
const trimmedInput = String(input).trim();

// Check for empty input after trimming
if (!trimmedInput) {
throw new InstrumentationError('Input is empty or invalid.');

Check warning on line 2343 in src/v0/util/index.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/index.js#L2343

Added line #L2343 was not covered by tests
}
// Generate and return UUID
return v5(trimmedInput, NAMESPACE);
} catch (error) {
const errorMessage = `Failed to transform input to uuid: ${error.message}`;
throw new InstrumentationError(errorMessage);

Check warning on line 2349 in src/v0/util/index.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/index.js#L2348-L2349

Added lines #L2348 - L2349 were not covered by tests
Expand Down

0 comments on commit 5360d14

Please sign in to comment.