diff --git a/src/core/headers.ts b/src/core/headers.ts index 63596c31..75511584 100644 --- a/src/core/headers.ts +++ b/src/core/headers.ts @@ -11,7 +11,5 @@ * server-side validation. When reading the headers treat them like user * input. * - * The key prefix `ably-chat` is reserved and cannot be used. Ably may add - * headers prefixed with `ably-chat` in the future. */ export type Headers = Record; diff --git a/src/core/messages.ts b/src/core/messages.ts index 1a5d8748..442ab663 100644 --- a/src/core/messages.ts +++ b/src/core/messages.ts @@ -87,8 +87,6 @@ export interface SendMessageParams { * Do not use metadata for authoritative information. There is no server-side * validation. When reading the metadata treat it like user input. * - * The key `ably-chat` is reserved and cannot be used. Ably may populate - * this with different values in the future. */ metadata?: MessageMetadata; @@ -105,8 +103,6 @@ export interface SendMessageParams { * server-side validation. When reading the headers treat them like user * input. * - * The key prefix `ably-chat` is reserved and cannot be used. Ably may add - * headers prefixed with `ably-chat` in the future. */ headers?: MessageHeaders; } @@ -445,22 +441,6 @@ export class DefaultMessages const { text, metadata, headers } = params; - if (metadata && metadata['ably-chat'] !== undefined) { - throw new Ably.ErrorInfo("unable to send message; metadata cannot use reserved key 'ably-chat'", 40001, 400); - } - - if (headers) { - for (const key of Object.keys(headers)) { - if (key.startsWith('ably-chat')) { - throw new Ably.ErrorInfo( - "unable to send message; headers cannot have any key starting with reserved prefix 'ably-chat'", - 40001, - 400, - ); - } - } - } - const response = await this._chatApi.sendMessage(this._roomId, { text, headers, metadata }); return new DefaultMessage( diff --git a/src/core/metadata.ts b/src/core/metadata.ts index 976d239a..75e11f2a 100644 --- a/src/core/metadata.ts +++ b/src/core/metadata.ts @@ -8,7 +8,5 @@ * Do not use metadata for authoritative information. There is no server-side * validation. When reading the metadata treat it like user input. * - * The key `ably-chat` is reserved and cannot be used. Ably may populate - * this with different values in the future. */ export type Metadata = Record; diff --git a/src/core/room-reactions.ts b/src/core/room-reactions.ts index 63905a78..10e132ae 100644 --- a/src/core/room-reactions.ts +++ b/src/core/room-reactions.ts @@ -40,8 +40,6 @@ export interface SendReactionParams { * Do not use metadata for authoritative information. There is no server-side * validation. When reading the metadata treat it like user input. * - * The key `ably-chat` is reserved and cannot be used. Ably may populate this - * with different values in the future. */ metadata?: ReactionMetadata; @@ -58,8 +56,6 @@ export interface SendReactionParams { * server-side validation. When reading the headers treat them like user * input. * - * The key prefix `ably-chat` is reserved and cannot be used. Ably may add - * headers prefixed with `ably-chat` in the future. */ headers?: ReactionHeaders; } @@ -190,26 +186,6 @@ export class DefaultRoomReactions return Promise.reject(new Ably.ErrorInfo('unable to send reaction; type not set and it is required', 40001, 400)); } - if (metadata && metadata['ably-chat'] !== undefined) { - return Promise.reject( - new Ably.ErrorInfo("unable to send reaction; metadata cannot use reserved key 'ably-chat'", 40001, 400), - ); - } - - if (headers) { - for (const key of Object.keys(headers)) { - if (key.startsWith('ably-chat')) { - return Promise.reject( - new Ably.ErrorInfo( - "unable to send reaction; headers cannot have any key starting with reserved prefix 'ably-chat'", - 40001, - 400, - ), - ); - } - } - } - const payload: ReactionPayload = { type: type, metadata: metadata ?? {}, diff --git a/test/core/messages.test.ts b/test/core/messages.test.ts index abf1b303..c2cdf883 100644 --- a/test/core/messages.test.ts +++ b/test/core/messages.test.ts @@ -115,60 +115,6 @@ describe('Messages', () => { }), ); }); - - it('should be not be able to set reserved header prefix', (context) => { - return new Promise((accept, reject) => { - const { chatApi, realtime } = context; - const timestamp = Date.now(); - vi.spyOn(chatApi, 'sendMessage').mockResolvedValue({ - timeserial: 'abcdefghij@1672531200000-123', - createdAt: timestamp, - }); - - const room = makeRandomRoom({ chatApi, realtime }); - const messagePromise = room.messages.send({ - text: 'hello there', - headers: { 'ably-chat.you': 'shall not pass' }, - }); - - messagePromise - .then(() => { - reject(new Error('message should have not been sent successfully')); - }) - .catch((error: unknown) => { - expect(error).toBeTruthy(); - expect((error as Error).message).toMatch(/reserved prefix/); - accept(); - }); - }); - }); - - it('should be not be able to set reserved metadata key', (context) => { - return new Promise((accept, reject) => { - const { chatApi, realtime } = context; - const timestamp = Date.now(); - vi.spyOn(chatApi, 'sendMessage').mockResolvedValue({ - timeserial: 'abcdefghij@1672531200000-123', - createdAt: timestamp, - }); - - const room = makeRandomRoom({ chatApi, realtime }); - const messagePromise = room.messages.send({ - text: 'hello there', - metadata: { 'ably-chat': 'shall not pass' }, - }); - - messagePromise - .then(() => { - reject(new Error('message should have not been sent successfully')); - }) - .catch((error: unknown) => { - expect(error).toBeTruthy(); - expect((error as Error).message).toMatch(/reserved key/); - accept(); - }); - }); - }); }); describe('subscribing to updates', () => { diff --git a/test/core/room-reactions.test.ts b/test/core/room-reactions.test.ts index d0c92439..af3e1fde 100644 --- a/test/core/room-reactions.test.ts +++ b/test/core/room-reactions.test.ts @@ -299,58 +299,6 @@ describe('Reactions', () => { headers: { action: 'strike back', number: 1980 }, }); })); - - it('should not be able to use reserved prefix in reaction headers', (context) => - new Promise((done, reject) => { - const { room } = context; - - room.reactions.subscribe(() => { - reject(new Error("should not receive reaction, sending must've failed")); - }); - - const sendPromise = room.reactions.send({ - type: 'love', - headers: { 'ably-chat-hello': true }, // "ably-chat" prefix is the reserved - }); - - sendPromise - .then(() => { - reject(new Error('send should not succeed')); - }) - .catch((error: unknown) => { - const errInfo = error as Ably.ErrorInfo; - expect(errInfo).toBeTruthy(); - expect(errInfo.message).toMatch(/reserved prefix/); - expect(errInfo.code).toEqual(40001); - done(); - }); - })); - - it('should not be able to use reserved key in reaction metadata', (context) => - new Promise((done, reject) => { - const { room } = context; - - room.reactions.subscribe(() => { - reject(new Error("should not receive reaction, sending must've failed")); - }); - - const sendPromise = room.reactions.send({ - type: 'love', - metadata: { 'ably-chat': { value: 1 } }, // "ably-chat" is reserved - }); - - sendPromise - .then(() => { - reject(new Error('send should not succeed')); - }) - .catch((error: unknown) => { - const errInfo = error as Ably.ErrorInfo; - expect(errInfo).toBeTruthy(); - expect(errInfo.message).toMatch(/reserved key/); - expect(errInfo.code).toEqual(40001); - done(); - }); - })); }); it('has an attachment error code', (context) => {