Skip to content

Commit

Permalink
feat: reserved elements list updated (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoumitaM authored Mar 1, 2024
1 parent d81adde commit 20417fa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,25 @@ describe('Event Manager - Utilities', () => {

it('should log a warn message if the object contains reserved elements', () => {
const obj = {
anonymousId: sampleAnonId,
originalTimestamp: sampleOriginalTimestamp,
anonymous_id: sampleAnonId,
original_timestamp: sampleOriginalTimestamp,
nonReservedKey: 123,
messageId: 'myMsgId',
id: 'myMsgId',
} as ApiObject;

checkForReservedElementsInObject(obj, defaultParentKeyPath, mockLogger);

expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
1,
`EventManager:: The "anonymousId" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "anonymous_id" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
2,
`EventManager:: The "originalTimestamp" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "original_timestamp" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
3,
`EventManager:: The "messageId" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "id" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
});

Expand Down Expand Up @@ -407,18 +407,18 @@ describe('Event Manager - Utilities', () => {
const obj = {
EVENT: 'test event',
nonReservedKey: 123,
originalTimestamp: sampleOriginalTimestamp,
original_timestamp: sampleOriginalTimestamp,
} as ApiObject;

checkForReservedElementsInObject(obj, defaultParentKeyPath, mockLogger);

expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
1,
`EventManager:: The "EVENT" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "EVENT" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
2,
`EventManager:: The "originalTimestamp" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "original_timestamp" property defined under "${defaultParentKeyPath}" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
});
});
Expand All @@ -429,43 +429,43 @@ describe('Event Manager - Utilities', () => {
const rudderEvent = {
type: defaultEventType,
properties: {
anonymousId: sampleAnonId,
originalTimestamp: sampleOriginalTimestamp,
anonymous_id: sampleAnonId,
original_timestamp: sampleOriginalTimestamp,
},
traits: {
originalTimestamp: sampleOriginalTimestamp,
original_timestamp: sampleOriginalTimestamp,
event: 'test event',
},
// @ts-ignore
context: {
traits: {
anonymousId: sampleAnonId,
anonymous_id: sampleAnonId,
},
locale: 'en-US',
} as RudderContext,
} as RudderEvent;

checkForReservedElements(rudderEvent, mockLogger);

expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
1,
`EventManager:: The "anonymousId" property defined under "properties" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "anonymous_id" property defined under "properties" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
2,
`EventManager:: The "originalTimestamp" property defined under "properties" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "original_timestamp" property defined under "properties" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
3,
`EventManager:: The "originalTimestamp" property defined under "traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "original_timestamp" property defined under "traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
4,
`EventManager:: The "event" property defined under "traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "event" property defined under "traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
expect(mockLogger.warn).nthCalledWith(
expect(mockLogger.warn).toHaveBeenNthCalledWith(
5,
`EventManager:: The "anonymousId" property defined under "context.traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (anonymousId,sentAt,receivedAt,timestamp,originalTimestamp,event,messageId,channel).`,
`EventManager:: The "anonymous_id" property defined under "context.traits" is a reserved keyword. Please choose a different property name to avoid conflicts with reserved keywords (id,anonymous_id,user_id,sent_at,timestamp,received_at,original_timestamp,event,event_text,channel,context_ip,context_request_ip,context_passed_ip,group_id,previous_id).`,
);
});
});
Expand Down
17 changes: 12 additions & 5 deletions packages/analytics-js/src/components/eventManager/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ const CONTEXT_RESERVED_ELEMENTS = ['library', 'consentManagement', 'userAgent',

// Reserved elements in the standard RudderStack event spec
const RESERVED_ELEMENTS = [
'anonymousId',
'sentAt',
'receivedAt',
'id',
'anonymous_id',
'user_id',
'sent_at',
'timestamp',
'originalTimestamp',
'received_at',
'original_timestamp',
'event',
'messageId',
'event_text',
'channel',
'context_ip',
'context_request_ip',
'context_passed_ip',
'group_id',
'previous_id',
];

export { CHANNEL, TOP_LEVEL_ELEMENTS, CONTEXT_RESERVED_ELEMENTS, RESERVED_ELEMENTS };

0 comments on commit 20417fa

Please sign in to comment.