Skip to content

Commit 28bf0c7

Browse files
authored
Allow null value metadata (#1274)
## Description We say in our [docs](https://workos.com/docs/user-management/metadata/add-and-update-metadata) that to remove a metadata field, you should set the value to null: > To delete a metadata attribute, set the key to null in the metadata object of the request body. This works via Postman. However, in our workos-node SDK, we have the TS interface set to only accept string values for the metadata object ([here](https://github.com/workos/workos-node/blob/16a31c8605bc91c66616e7e54dd15c0ec2b7da66/src/user-management/interfaces/update-user-options.interface.ts#L12)). This PR adds `null` to the`UpdateUserOptions` and `SerializedUpdateUserOptions` interfaces and adds one test. ## Documentation No docs changes needed ## Review I would love eyes on my test - I am pretty sure it is correctly testing that the key is removed from the metadata since the [user fixture](https://github.com/workos/workos-node/blob/16a31c8605bc91c66616e7e54dd15c0ec2b7da66/src/user-management/fixtures/user.json) starts with a value there, but I'd love confirmation!
1 parent 16a31c8 commit 28bf0c7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/user-management/interfaces/update-user-options.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface UpdateUserOptions {
99
passwordHash?: string;
1010
passwordHashType?: PasswordHashType;
1111
externalId?: string;
12-
metadata?: Record<string, string>;
12+
metadata?: Record<string, string | null>;
1313
}
1414

1515
export interface SerializedUpdateUserOptions {
@@ -20,5 +20,5 @@ export interface SerializedUpdateUserOptions {
2020
password_hash?: string;
2121
password_hash_type?: PasswordHashType;
2222
external_id?: string;
23-
metadata?: Record<string, string>;
23+
metadata?: Record<string, string | null>;
2424
}

src/user-management/user-management.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,19 @@ describe('UserManagement', () => {
13221322
metadata: { key: 'value' },
13231323
});
13241324
});
1325+
1326+
it('removes metadata from the request', async () => {
1327+
fetchOnce(userFixture);
1328+
1329+
await workos.userManagement.updateUser({
1330+
userId,
1331+
metadata: { key: null },
1332+
});
1333+
1334+
expect(fetchBody()).toMatchObject({
1335+
metadata: {},
1336+
});
1337+
});
13251338
});
13261339

13271340
describe('enrollAuthFactor', () => {

0 commit comments

Comments
 (0)