Skip to content

Commit 2b523b2

Browse files
authored
Add custom message type support (#418)
feat(message-type): add custom message type support Add custom message type support for the following APIs: publish, signal, share file, subscribe and history.
1 parent 66520c2 commit 2b523b2

27 files changed

+372
-84
lines changed

Diff for: .pubnub.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2024-11-14
4+
version: v8.3.0
5+
changes:
6+
- type: feature
7+
text: "Add custom message type support for the following APIs: publish, signal, share file, subscribe and history."
38
- date: 2024-10-31
49
version: v8.2.10
510
changes:
@@ -1062,7 +1067,7 @@ supported-platforms:
10621067
- 'Ubuntu 14.04 and up'
10631068
- 'Windows 7 and up'
10641069
version: 'Pubnub Javascript for Node'
1065-
version: '8.2.10'
1070+
version: '8.3.0'
10661071
sdks:
10671072
- full-name: PubNub Javascript SDK
10681073
short-name: Javascript
@@ -1078,7 +1083,7 @@ sdks:
10781083
- distribution-type: source
10791084
distribution-repository: GitHub release
10801085
package-name: pubnub.js
1081-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.10.zip
1086+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.0.zip
10821087
requires:
10831088
- name: 'agentkeepalive'
10841089
min-version: '3.5.2'
@@ -1749,7 +1754,7 @@ sdks:
17491754
- distribution-type: library
17501755
distribution-repository: GitHub release
17511756
package-name: pubnub.js
1752-
location: https://github.com/pubnub/javascript/releases/download/v8.2.10/pubnub.8.2.10.js
1757+
location: https://github.com/pubnub/javascript/releases/download/v8.3.0/pubnub.8.3.0.js
17531758
requires:
17541759
- name: 'agentkeepalive'
17551760
min-version: '3.5.2'

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v8.3.0
2+
November 14 2024
3+
4+
#### Added
5+
- Add custom message type support for the following APIs: publish, signal, share file, subscribe and history.
6+
17
## v8.2.10
28
October 31 2024
39

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2828
npm install pubnub
2929
```
3030
* or download one of our builds from our CDN:
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.min.js
3333
3434
2. Configure your keys:
3535

Diff for: dist/web/pubnub.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@
39483948
return base.PubNubFile;
39493949
},
39503950
get version() {
3951-
return '8.2.10';
3951+
return '8.3.0';
39523952
},
39533953
getVersion() {
39543954
return this.version;
@@ -6230,6 +6230,8 @@
62306230
};
62316231
if (envelope.u)
62326232
event.userMetadata = envelope.u;
6233+
if (envelope.cmt)
6234+
event.customMessageType = envelope.cmt;
62336235
if (decryptionError)
62346236
event.error = decryptionError;
62356237
return event;
@@ -6245,6 +6247,8 @@
62456247
};
62466248
if (envelope.u)
62476249
event.userMetadata = envelope.u;
6250+
if (envelope.cmt)
6251+
event.customMessageType = envelope.cmt;
62486252
return event;
62496253
}
62506254
messageActionFromEnvelope(envelope) {
@@ -6296,6 +6300,8 @@
62966300
};
62976301
}
62986302
}
6303+
if (envelope.cmt)
6304+
event.customMessageType = envelope.cmt;
62996305
if (errorMessage)
63006306
event.error = errorMessage;
63016307
return event;
@@ -8303,8 +8309,10 @@
83038309
return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${encodeString(channel)}/0${!this.parameters.sendByPost ? `/${encodeString(stringifiedPayload)}` : ''}`;
83048310
}
83058311
get queryParameters() {
8306-
const { meta, replicate, storeInHistory, ttl } = this.parameters;
8312+
const { customMessageType, meta, replicate, storeInHistory, ttl } = this.parameters;
83078313
const query = {};
8314+
if (customMessageType)
8315+
query.custom_message_type = customMessageType;
83088316
if (storeInHistory !== undefined)
83098317
query.store = storeInHistory ? '1' : '0';
83108318
if (ttl !== undefined)
@@ -8380,6 +8388,13 @@
83808388
const stringifiedPayload = JSON.stringify(message);
83818389
return `/signal/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(stringifiedPayload)}`;
83828390
}
8391+
get queryParameters() {
8392+
const { customMessageType } = this.parameters;
8393+
const query = {};
8394+
if (customMessageType)
8395+
query.custom_message_type = customMessageType;
8396+
return query;
8397+
}
83838398
}
83848399

83858400
/**
@@ -9151,13 +9166,7 @@
91519166
if (payload.message_type === null)
91529167
payload.message_type = PubNubMessageType.Message;
91539168
const processedPayload = this.processPayload(channel, payload);
9154-
const item = {
9155-
channel,
9156-
timetoken: payload.timetoken,
9157-
message: processedPayload.payload,
9158-
messageType: payload.message_type,
9159-
uuid: payload.uuid,
9160-
};
9169+
const item = Object.assign(Object.assign({ channel, timetoken: payload.timetoken, message: processedPayload.payload, messageType: payload.message_type }, (payload.custom_message_type ? { customMessageType: payload.custom_message_type } : {})), { uuid: payload.uuid });
91619170
if (payload.actions) {
91629171
const itemWithActions = item;
91639172
itemWithActions.actions = payload.actions;
@@ -9183,8 +9192,10 @@
91839192
return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${encodeNames(channels)}`;
91849193
}
91859194
get queryParameters() {
9186-
const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters;
9187-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {}));
9195+
const { start, end, count, includeCustomMessageType, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken, } = this.parameters;
9196+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeCustomMessageType !== undefined && includeCustomMessageType !== null
9197+
? { include_custom_message_type: includeCustomMessageType ? 'true' : 'false' }
9198+
: {})), (includeMessageType ? { include_message_type: 'true' } : {}));
91889199
}
91899200
/**
91909201
* Parse single channel data entry.
@@ -9461,8 +9472,8 @@
94619472
return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(this.prepareMessagePayload(fileMessage))}`;
94629473
}
94639474
get queryParameters() {
9464-
const { storeInHistory, ttl, meta } = this.parameters;
9465-
return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {}));
9475+
const { customMessageType, storeInHistory, ttl, meta } = this.parameters;
9476+
return Object.assign(Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (customMessageType ? { custom_message_type: customMessageType } : {})), (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {}));
94669477
}
94679478
/**
94689479
* Pre-process provided data.

Diff for: dist/web/pubnub.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/core/components/configuration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
112112
return base.PubNubFile;
113113
},
114114
get version() {
115-
return '8.2.10';
115+
return '8.3.0';
116116
},
117117
getVersion() {
118118
return this.version;

Diff for: lib/core/endpoints/fetch_messages.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ class FetchMessagesRequest extends request_1.AbstractRequest {
135135
if (payload.message_type === null)
136136
payload.message_type = History.PubNubMessageType.Message;
137137
const processedPayload = this.processPayload(channel, payload);
138-
const item = {
139-
channel,
140-
timetoken: payload.timetoken,
141-
message: processedPayload.payload,
142-
messageType: payload.message_type,
143-
uuid: payload.uuid,
144-
};
138+
const item = Object.assign(Object.assign({ channel, timetoken: payload.timetoken, message: processedPayload.payload, messageType: payload.message_type }, (payload.custom_message_type ? { customMessageType: payload.custom_message_type } : {})), { uuid: payload.uuid });
145139
if (payload.actions) {
146140
const itemWithActions = item;
147141
itemWithActions.actions = payload.actions;
@@ -167,8 +161,10 @@ class FetchMessagesRequest extends request_1.AbstractRequest {
167161
return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels)}`;
168162
}
169163
get queryParameters() {
170-
const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters;
171-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {}));
164+
const { start, end, count, includeCustomMessageType, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken, } = this.parameters;
165+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeCustomMessageType !== undefined && includeCustomMessageType !== null
166+
? { include_custom_message_type: includeCustomMessageType ? 'true' : 'false' }
167+
: {})), (includeMessageType ? { include_message_type: 'true' } : {}));
172168
}
173169
/**
174170
* Parse single channel data entry.

Diff for: lib/core/endpoints/file_upload/publish_file.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class PublishFileMessageRequest extends request_1.AbstractRequest {
7575
return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(this.prepareMessagePayload(fileMessage))}`;
7676
}
7777
get queryParameters() {
78-
const { storeInHistory, ttl, meta } = this.parameters;
79-
return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {}));
78+
const { customMessageType, storeInHistory, ttl, meta } = this.parameters;
79+
return Object.assign(Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (customMessageType ? { custom_message_type: customMessageType } : {})), (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {}));
8080
}
8181
/**
8282
* Pre-process provided data.

Diff for: lib/core/endpoints/publish.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class PublishRequest extends request_1.AbstractRequest {
7979
return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0${!this.parameters.sendByPost ? `/${(0, utils_1.encodeString)(stringifiedPayload)}` : ''}`;
8080
}
8181
get queryParameters() {
82-
const { meta, replicate, storeInHistory, ttl } = this.parameters;
82+
const { customMessageType, meta, replicate, storeInHistory, ttl } = this.parameters;
8383
const query = {};
84+
if (customMessageType)
85+
query.custom_message_type = customMessageType;
8486
if (storeInHistory !== undefined)
8587
query.store = storeInHistory ? '1' : '0';
8688
if (ttl !== undefined)

Diff for: lib/core/endpoints/signal.js

+7
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,12 @@ class SignalRequest extends request_1.AbstractRequest {
5656
const stringifiedPayload = JSON.stringify(message);
5757
return `/signal/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(stringifiedPayload)}`;
5858
}
59+
get queryParameters() {
60+
const { customMessageType } = this.parameters;
61+
const query = {};
62+
if (customMessageType)
63+
query.custom_message_type = customMessageType;
64+
return query;
65+
}
5966
}
6067
exports.SignalRequest = SignalRequest;

Diff for: lib/core/endpoints/subscribe.js

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest {
216216
};
217217
if (envelope.u)
218218
event.userMetadata = envelope.u;
219+
if (envelope.cmt)
220+
event.customMessageType = envelope.cmt;
219221
if (decryptionError)
220222
event.error = decryptionError;
221223
return event;
@@ -231,6 +233,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest {
231233
};
232234
if (envelope.u)
233235
event.userMetadata = envelope.u;
236+
if (envelope.cmt)
237+
event.customMessageType = envelope.cmt;
234238
return event;
235239
}
236240
messageActionFromEnvelope(envelope) {
@@ -282,6 +286,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest {
282286
};
283287
}
284288
}
289+
if (envelope.cmt)
290+
event.customMessageType = envelope.cmt;
285291
if (errorMessage)
286292
event.error = errorMessage;
287293
return event;

Diff for: lib/types/index.d.ts

+39
Original file line numberDiff line numberDiff line change
@@ -4764,6 +4764,10 @@ declare namespace PubNub {
47644764
userMetadata?: {
47654765
[p: string]: Payload;
47664766
};
4767+
/**
4768+
* User-provided message type.
4769+
*/
4770+
customMessageType?: string;
47674771
/**
47684772
* Sent data.
47694773
*/
@@ -6086,6 +6090,13 @@ declare namespace PubNub {
60866090
* The message may be any valid JSON type including objects, arrays, strings, and numbers.
60876091
*/
60886092
message: Payload;
6093+
/**
6094+
* User-specified message type.
6095+
*
6096+
* **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only
6097+
* `-` and `_` special characters allowed.
6098+
*/
6099+
customMessageType?: string;
60896100
/**
60906101
* Whether published data should be available with `Storage API` later or not.
60916102
*
@@ -6150,6 +6161,13 @@ declare namespace PubNub {
61506161
* The message may be any valid JSON type including objects, arrays, strings, and numbers.
61516162
*/
61526163
message: Payload;
6164+
/**
6165+
* User-specified message type.
6166+
*
6167+
* **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only
6168+
* `-` and `_` special characters allowed.
6169+
*/
6170+
customMessageType?: string;
61536171
};
61546172

61556173
/**
@@ -6566,6 +6584,10 @@ declare namespace PubNub {
65666584
* PubNub-defined message type.
65676585
*/
65686586
messageType?: PubNubMessageType.Message;
6587+
/**
6588+
* User-provided message type.
6589+
*/
6590+
customMessageType?: string;
65696591
};
65706592

65716593
/**
@@ -6610,6 +6632,10 @@ declare namespace PubNub {
66106632
* PubNub-defined message type.
66116633
*/
66126634
messageType?: PubNubMessageType.Files;
6635+
/**
6636+
* User-provided message type.
6637+
*/
6638+
customMessageType?: string;
66136639
};
66146640

66156641
/**
@@ -6652,6 +6678,12 @@ declare namespace PubNub {
66526678
* @default `100` or `25`
66536679
*/
66546680
count?: number;
6681+
/**
6682+
* Include messages' custom type flag.
6683+
*
6684+
* Message / signal and file messages may contain user-provided type.
6685+
*/
6686+
includeCustomMessageType?: boolean;
66556687
/**
66566688
* Whether message type should be returned with each history message or not.
66576689
*
@@ -7194,6 +7226,13 @@ declare namespace PubNub {
71947226
* File annotation message.
71957227
*/
71967228
message?: Payload;
7229+
/**
7230+
* User-specified message type.
7231+
*
7232+
* **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only
7233+
* `-` and `_` special characters allowed.
7234+
*/
7235+
customMessageType?: string;
71977236
/**
71987237
* Custom file and message encryption key.
71997238
*

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "8.2.10",
3+
"version": "8.3.0",
44
"author": "PubNub <[email protected]>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"scripts": {

Diff for: src/core/components/configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const makeConfiguration = (
171171
return base.PubNubFile;
172172
},
173173
get version(): string {
174-
return '8.2.10';
174+
return '8.3.0';
175175
},
176176
getVersion(): string {
177177
return this.version;

0 commit comments

Comments
 (0)