diff --git a/src/schemas/v1/page-hit-processed.ts b/src/schemas/v1/page-hit-processed.ts index be60711e..22535cfd 100644 --- a/src/schemas/v1/page-hit-processed.ts +++ b/src/schemas/v1/page-hit-processed.ts @@ -21,6 +21,8 @@ export const PageHitProcessedSchema = Type.Object({ member_status: Type.Union([Type.String({minLength: 1}), Type.Literal('undefined')]), post_uuid: Type.Union([Type.String({format: 'uuid'}), Type.Literal('undefined')]), post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]), + // Gift-link token, present only on gift reads; absent/null otherwise. + gift: Type.Optional(Type.Union([Type.String(), Type.Null()])), locale: Type.String({minLength: 1}), location: Type.Union([Type.String({minLength: 1}), Type.Null()]), pathname: Type.String({minLength: 1}), @@ -161,6 +163,7 @@ export async function transformPageHitRawToProcessed( member_status: pageHitRaw.payload.member_status, post_uuid: pageHitRaw.payload.post_uuid, post_type: pageHitRaw.payload.post_type, + gift: pageHitRaw.payload.gift, locale: pageHitRaw.payload.locale, location: pageHitRaw.payload.location, pathname: pageHitRaw.payload.pathname, diff --git a/src/schemas/v1/page-hit-raw.ts b/src/schemas/v1/page-hit-raw.ts index ad1b3038..e7248658 100644 --- a/src/schemas/v1/page-hit-raw.ts +++ b/src/schemas/v1/page-hit-raw.ts @@ -28,6 +28,8 @@ const PayloadSchema = Type.Object({ member_status: Type.Union([NonEmptyStringSchema, Type.Literal('undefined')]), post_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]), post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]), + // Gift-link token, present only on gift reads; absent/null otherwise. + gift: Type.Optional(Type.Union([StringSchema, Type.Null()])), locale: NonEmptyStringSchema, location: Type.Union([NonEmptyStringSchema, Type.Null()]), referrer: Type.Optional(Type.Union([StringSchema, Type.Null()])), diff --git a/src/schemas/v1/page-hit-request.ts b/src/schemas/v1/page-hit-request.ts index ed80f58a..15295f5f 100644 --- a/src/schemas/v1/page-hit-request.ts +++ b/src/schemas/v1/page-hit-request.ts @@ -79,6 +79,8 @@ export const PageHitRequestPayloadSchema = Type.Object({ site_uuid: UUIDSchema, post_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]), post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]), + // Gift-link token, present only on gift reads; absent/null otherwise. + gift: Type.Optional(Type.Union([StringSchema, Type.Null()])), member_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]), member_status: Type.Union([NonEmptyStringSchema, Type.Literal('undefined')]), utm_source: Type.Optional(Type.Union([StringSchema, Type.Null()])), @@ -140,6 +142,7 @@ export const PageHitRequestPayloadDefaults = { site_uuid: '', post_uuid: 'undefined', post_type: 'null', + gift: null, member_uuid: 'undefined', member_status: 'undefined', utm_source: null, diff --git a/src/transformations/page-hit-transformations.ts b/src/transformations/page-hit-transformations.ts index 27e8a17e..4fa5aabb 100644 --- a/src/transformations/page-hit-transformations.ts +++ b/src/transformations/page-hit-transformations.ts @@ -25,6 +25,7 @@ export const pageHitRawPayloadFromRequest = (request: PageHitRequestType): PageH member_status: request.body.payload.member_status, post_uuid: request.body.payload.post_uuid, post_type: request.body.payload.post_type, + gift: request.body.payload.gift ?? null, locale: request.body.payload.locale, location: request.body.payload.location, referrer: request.body.payload.referrer ?? null, diff --git a/test/unit/transformations/page-hit-transformations.test.ts b/test/unit/transformations/page-hit-transformations.test.ts index 7b3b3845..a3ce6b8f 100644 --- a/test/unit/transformations/page-hit-transformations.test.ts +++ b/test/unit/transformations/page-hit-transformations.test.ts @@ -22,6 +22,7 @@ describe('pageHitRawPayloadFromRequest', () => { member_status: 'free', post_uuid: 'post-uuid-456', post_type: 'post', + gift: 'gift-token-789', locale: 'en-US', location: 'homepage', referrer: 'https://google.com', @@ -52,6 +53,7 @@ describe('pageHitRawPayloadFromRequest', () => { member_status: 'free', post_uuid: 'post-uuid-456', post_type: 'post', + gift: 'gift-token-789', locale: 'en-US', location: 'homepage', referrer: 'https://google.com', @@ -77,6 +79,15 @@ describe('pageHitRawPayloadFromRequest', () => { }); }); + it('defaults gift to null when absent (non-gift hit)', () => { + const request = createPageHitRequest(); + delete request.body.payload.gift; + + const result = pageHitRawPayloadFromRequest(request); + + expect(result.payload.gift).toBeNull(); + }); + describe('Event ID', () => { const uuidMatcher = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;