Skip to content

Commit

Permalink
chore: refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna2020 committed Nov 21, 2024
1 parent 84d478b commit 82ffd9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
12 changes: 11 additions & 1 deletion src/v0/destinations/airship/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ const {
extractCustomFields,
isEmptyObject,
simpleProcessRouterDest,
transformSessionId,
convertToUuid,
} = require('../../util');
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(

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L34 was not covered by tests
'Invalid session ID: must be a non-empty string after conversion to string.',
);
}
return convertToUuid(sessionId); // Return the validated and converted session ID
};

const identifyResponseBuilder = (message, { Config }) => {
const tagPayload = constructPayload(message, identifyMapping);
const { apiKey, dataCenter } = Config;
Expand Down
24 changes: 6 additions & 18 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2332,25 +2332,13 @@ const isEventSentByVDMV1Flow = (event) => event?.message?.context?.mappedToDesti
const isEventSentByVDMV2Flow = (event) =>
event?.connection?.config?.destination?.schemaVersion === VDM_V2_SCHEMA_VERSION;

const validateSessionId = (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.',
);
}
return sessionId; // Return the validated and converted session ID
};

const transformSessionId = (rawSessionId) => {
const convertToUuid = (input) => {
const NAMESPACE = v5.DNS;
try {
const sessionId = validateSessionId(rawSessionId);

const NAMESPACE = v5.DNS;
const uuidV5 = v5(sessionId, NAMESPACE);
return uuidV5;
return v5(input, NAMESPACE);
} catch (error) {
throw new InstrumentationError(`Failed to transform session ID: ${error.message}`);
const errorMessage = `Failed to transform input to uuid: ${error.message}`;
throw new InstrumentationError(errorMessage);

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

View check run for this annotation

Codecov / codecov/patch

src/v0/util/index.js#L2340-L2341

Added lines #L2340 - L2341 were not covered by tests
}
};
// ========================================================================
Expand Down Expand Up @@ -2479,5 +2467,5 @@ module.exports = {
getRelativePathFromURL,
removeEmptyKey,
isAxiosError,
transformSessionId,
convertToUuid,
};

0 comments on commit 82ffd9b

Please sign in to comment.