From c5af7f28d133a43183bc502e654cb94b84842ea3 Mon Sep 17 00:00:00 2001 From: Jena Date: Thu, 2 Jul 2026 13:58:31 -0500 Subject: [PATCH 1/2] [SDK-563] Make preferUserId caller-configurable, default to true Previously the SDK hardcoded preferUserId: true on users/update, commerce updateCart, and trackPurchase requests, overriding any value the caller passed. Now it uses `payload.preferUserId ?? true` (and `payload.user?.preferUserId ?? true` for the nested commerce user), so callers can opt out while the default stays true. --- src/commerce/commerce.ts | 6 ++++-- src/unknownUserTracking/unknownUserEventManager.ts | 9 ++++++--- src/users/users.ts | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commerce/commerce.ts b/src/commerce/commerce.ts index f09c2524..31a2ab34 100644 --- a/src/commerce/commerce.ts +++ b/src/commerce/commerce.ts @@ -26,7 +26,8 @@ export const updateCart = (payload: UpdateCartRequestParams) => { ...payload, user: { ...payload.user, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.user?.preferUserId ?? true } }, validation: { @@ -54,7 +55,8 @@ export const trackPurchase = (payload: TrackPurchaseRequestParams) => { ...payload, user: { ...payload.user, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.user?.preferUserId ?? true } }, validation: { diff --git a/src/unknownUserTracking/unknownUserEventManager.ts b/src/unknownUserTracking/unknownUserEventManager.ts index 85c4f97b..af7dbb1e 100644 --- a/src/unknownUserTracking/unknownUserEventManager.ts +++ b/src/unknownUserTracking/unknownUserEventManager.ts @@ -504,7 +504,8 @@ export class UnknownUserEventManager { ...payload, user: { ...payload.user, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.user?.preferUserId ?? true } }, validation: { @@ -520,7 +521,8 @@ export class UnknownUserEventManager { ...payload, user: { ...payload.user, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.user?.preferUserId ?? true } }, validation: { @@ -535,7 +537,8 @@ export class UnknownUserEventManager { url: ENDPOINTS.users_update.route, data: { ...payload, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.preferUserId ?? true }, validation: { data: updateUserSchema diff --git a/src/users/users.ts b/src/users/users.ts index 46c11620..c5a30209 100644 --- a/src/users/users.ts +++ b/src/users/users.ts @@ -38,7 +38,8 @@ export const updateUser = (payloadParam: UpdateUserParams = {}) => { url: ENDPOINTS.users_update.route, data: { ...payload, - preferUserId: true + /* default to true, but allow the caller to override */ + preferUserId: payload.preferUserId ?? true }, validation: { data: updateUserSchema From 2349bc4efb601c59560a4fd86680c372848151ba Mon Sep 17 00:00:00 2001 From: Jena Date: Mon, 13 Jul 2026 15:30:31 -0500 Subject: [PATCH 2/2] fixed type gap with updateUser --- src/commerce/commerce.test.ts | 40 +++++++++++++++++++++++++++++++++++ src/users/types.ts | 1 + src/users/users.test.ts | 21 ++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/src/commerce/commerce.test.ts b/src/commerce/commerce.test.ts index e580814e..fb6e1822 100644 --- a/src/commerce/commerce.test.ts +++ b/src/commerce/commerce.test.ts @@ -48,6 +48,29 @@ describe('Users Requests', () => { expect(response.data.msg).toBe('hello'); }); + it('should respect a caller-provided preferUserId of false for updateCart', async () => { + mockRequest.onPost('/commerce/updateCart').reply(200, { + msg: 'hello' + }); + + const response = await updateCart({ + user: { + preferUserId: false + }, + items: [ + { + id: 'fdsafds', + name: 'banana', + quantity: 2, + price: 12 + } + ] + }); + + expect(JSON.parse(response.config.data).user.preferUserId).toBe(false); + expect(response.data.msg).toBe('hello'); + }); + it('should reject updateCart on bad params', async () => { try { await updateCart({ @@ -93,6 +116,23 @@ describe('Users Requests', () => { expect(response.data.msg).toBe('hello'); }); + it('should respect a caller-provided preferUserId of false for trackPurchase', async () => { + mockRequest.onPost('/commerce/trackPurchase').reply(200, { + msg: 'hello' + }); + + const response = await trackPurchase({ + user: { + preferUserId: false + }, + items: [], + total: 100 + }); + + expect(JSON.parse(response.config.data).user.preferUserId).toBe(false); + expect(response.data.msg).toBe('hello'); + }); + it('should not allow a passed userId or email for API methods', async () => { mockRequest.onPost('/commerce/trackPurchase').reply(200, { msg: 'hello' diff --git a/src/users/types.ts b/src/users/types.ts index 79c43e2a..6dd5a0c3 100644 --- a/src/users/types.ts +++ b/src/users/types.ts @@ -12,6 +12,7 @@ export interface GetUserResponse { export interface UpdateUserParams { dataFields?: Record; + preferUserId?: boolean; mergeNestedObjects?: boolean; } diff --git a/src/users/users.test.ts b/src/users/users.test.ts index 2fb189b3..01728b4a 100644 --- a/src/users/users.test.ts +++ b/src/users/users.test.ts @@ -36,6 +36,22 @@ describe('Users Requests', () => { expect(response && response.data.msg).toBe('hello'); }); + it('should respect a caller-provided preferUserId of false for updateUser', async () => { + mockRequest.onPost('/users/update').reply(200, { + msg: 'hello' + }); + + const response = await updateUser({ + dataFields: {}, + preferUserId: false + }); + + expect(JSON.parse(response && response.config.data).preferUserId).toBe( + false + ); + expect(response && response.data.msg).toBe('hello'); + }); + it('should reject updateUser on bad params', async () => { try { await updateUser({ @@ -52,6 +68,11 @@ describe('Users Requests', () => { ' If "null" is intended as an empty value be sure to mark the schema as `.nullable()`', field: 'dataFields' }, + { + error: + 'preferUserId must be a `boolean` type, but the final value was: `"string"`.', + field: 'preferUserId' + }, { error: 'mergeNestedObjects must be a `boolean` type, but the final value was: `"string"`.',