Skip to content

Commit 5dc7ec7

Browse files
fix: Subscription entity's subscribe() signature to accept timetoken (#385)
* fix: subscribe() signature to accept timetoken in subscribe() method * fix lint errors * added test for custom timetoken with subscription * format * sync package-lock * PubNub SDK v8.2.4 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 4e18e9d commit 5dc7ec7

File tree

15 files changed

+109
-44
lines changed

15 files changed

+109
-44
lines changed

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2024-06-17
4+
version: v8.2.4
5+
changes:
6+
- type: bug
7+
text: "Subscription/SubscriptionSet's `subscribe()` method accepts `timetoken` parameter. Instead as in subscriptionOption."
38
- date: 2024-06-06
49
version: v8.2.3
510
changes:
@@ -1003,7 +1008,7 @@ supported-platforms:
10031008
- 'Ubuntu 14.04 and up'
10041009
- 'Windows 7 and up'
10051010
version: 'Pubnub Javascript for Node'
1006-
version: '8.2.3'
1011+
version: '8.2.4'
10071012
sdks:
10081013
- full-name: PubNub Javascript SDK
10091014
short-name: Javascript
@@ -1019,7 +1024,7 @@ sdks:
10191024
- distribution-type: source
10201025
distribution-repository: GitHub release
10211026
package-name: pubnub.js
1022-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.3.zip
1027+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.4.zip
10231028
requires:
10241029
- name: 'agentkeepalive'
10251030
min-version: '3.5.2'
@@ -1690,7 +1695,7 @@ sdks:
16901695
- distribution-type: library
16911696
distribution-repository: GitHub release
16921697
package-name: pubnub.js
1693-
location: https://github.com/pubnub/javascript/releases/download/v8.2.3/pubnub.8.2.3.js
1698+
location: https://github.com/pubnub/javascript/releases/download/v8.2.4/pubnub.8.2.4.js
16941699
requires:
16951700
- name: 'agentkeepalive'
16961701
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v8.2.4
2+
June 17 2024
3+
4+
#### Fixed
5+
- Subscription/SubscriptionSet's `subscribe()` method accepts `timetoken` parameter. Instead as in subscriptionOption.
6+
17
## v8.2.3
28
June 06 2024
39

README.md

Lines changed: 2 additions & 2 deletions
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.3.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.3.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,7 +3813,7 @@
38133813
return base.PubNubFile;
38143814
},
38153815
get version() {
3816-
return '8.2.3';
3816+
return '8.2.4';
38173817
},
38183818
getVersion() {
38193819
return this.version;
@@ -8963,9 +8963,9 @@
89638963
}
89648964

89658965
class SubscribeCapable {
8966-
subscribe() {
8967-
var _a, _b;
8968-
this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken })));
8966+
subscribe(subscribeParameters) {
8967+
const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken;
8968+
this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken })));
89698969
}
89708970
unsubscribe() {
89718971
this.pubnub.unsubscribe({

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/configuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
110110
return base.PubNubFile;
111111
},
112112
get version() {
113-
return '8.2.3';
113+
return '8.2.4';
114114
},
115115
getVersion() {
116116
return this.version;

lib/entities/SubscribeCapable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.SubscribeCapable = void 0;
44
class SubscribeCapable {
5-
subscribe() {
6-
var _a, _b;
7-
this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken })));
5+
subscribe(subscribeParameters) {
6+
const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken;
7+
this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken })));
88
}
99
unsubscribe() {
1010
this.pubnub.unsubscribe({

lib/types/entities/SubscribeCapable.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export declare abstract class SubscribeCapable {
1010
protected abstract eventEmitter: EventEmitter;
1111
protected abstract pubnub: PubNub<unknown, unknown>;
1212
protected abstract options?: SubscriptionOptions;
13-
subscribe(): void;
13+
subscribe(subscribeParameters?: {
14+
timetoken?: string;
15+
}): void;
1416
unsubscribe(): void;
1517
set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void);
1618
set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void);

lib/types/entities/commonTypes.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
export type SubscriptionOptions = {
2-
cursor?: {
3-
timetoken?: string;
4-
region?: number;
5-
};
62
receivePresenceEvents?: boolean;
73
};

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

src/core/components/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const makeConfiguration = (
169169
return base.PubNubFile;
170170
},
171171
get version(): string {
172-
return '8.2.3';
172+
return '8.2.4';
173173
},
174174
getVersion(): string {
175175
return this.version;

src/entities/SubscribeCapable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export abstract class SubscribeCapable {
1212
protected abstract pubnub: PubNub<unknown, unknown>;
1313
protected abstract options?: SubscriptionOptions;
1414

15-
subscribe() {
15+
subscribe(subscribeParameters?: { timetoken?: string }) {
16+
const timetoken = subscribeParameters?.timetoken;
1617
this.pubnub.subscribe({
1718
channels: this.channelNames,
1819
channelGroups: this.groupNames,
19-
...(this.options?.cursor?.timetoken && { timetoken: this.options.cursor.timetoken }),
20+
...(timetoken !== null && timetoken !== '' && { timetoken: timetoken }),
2021
});
2122
}
2223
unsubscribe() {

src/entities/commonTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export type SubscriptionOptions = {
2-
cursor?: { timetoken?: string; region?: number };
32
receivePresenceEvents?: boolean;
43
};

test/integration/endpoints/subscribe.test.ts

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import utils from '../../utils';
1010
describe('subscribe endpoints', () => {
1111
let pubnubWithFiltering: PubNub;
1212
let pubnub: PubNub;
13+
let pubnubWithEE: PubNub;
1314

1415
before(() => {
1516
nock.disableNetConnect();
@@ -38,6 +39,14 @@ describe('subscribe endpoints', () => {
3839
filterExpression: 'hello!',
3940
autoNetworkDetection: false,
4041
});
42+
pubnubWithEE = new PubNub({
43+
subscribeKey: 'mySubKey',
44+
publishKey: 'myPublishKey',
45+
uuid: 'myUUID',
46+
// @ts-expect-error Force override default value.
47+
useRequestId: false,
48+
enableEventEngine: true,
49+
});
4150
});
4251

4352
afterEach(() => {
@@ -65,9 +74,9 @@ describe('subscribe endpoints', () => {
6574
if (status.category === 'PNConnectedCategory') {
6675
try {
6776
assert.equal(scope.isDone(), true);
68-
assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]);
77+
assert.deepEqual(pubnub.getSubscribedChannels(), ['coolChannel', 'coolChannel2']);
6978
assert.deepEqual(pubnub.getSubscribedChannelGroups(), []);
70-
assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]);
79+
assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']);
7180
assert.deepEqual(status.affectedChannelGroups, []);
7281
done();
7382
} catch (error) {
@@ -99,12 +108,12 @@ describe('subscribe endpoints', () => {
99108
pubnub.addListener({
100109
status(status) {
101110
if (status.category === 'PNConnectedCategory') {
102-
try {
111+
try {
103112
assert.equal(scope.isDone(), true);
104-
assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]);
105-
assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]);
106-
assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]);
107-
assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]);
113+
assert.deepEqual(pubnub.getSubscribedChannels(), ['coolChannel', 'coolChannel2']);
114+
assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']);
115+
assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']);
116+
assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']);
108117
done();
109118
} catch (error) {
110119
done(error);
@@ -141,9 +150,9 @@ describe('subscribe endpoints', () => {
141150
try {
142151
assert.equal(scope.isDone(), true);
143152
assert.deepEqual(pubnub.getSubscribedChannels(), []);
144-
assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]);
153+
assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']);
145154
assert.deepEqual(status.affectedChannels, []);
146-
assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]);
155+
assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']);
147156
done();
148157
} catch (error) {
149158
done(error);
@@ -176,9 +185,9 @@ describe('subscribe endpoints', () => {
176185
if (status.category === 'PNConnectedCategory') {
177186
try {
178187
assert.equal(scope.isDone(), true);
179-
assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), ["coolChannel", "coolChannel2"]);
188+
assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), ['coolChannel', 'coolChannel2']);
180189
assert.deepEqual(pubnubWithFiltering.getSubscribedChannelGroups(), []);
181-
assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]);
190+
assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']);
182191
assert.deepEqual(status.affectedChannelGroups, []);
183192
done();
184193
} catch (error) {
@@ -192,4 +201,51 @@ describe('subscribe endpoints', () => {
192201
channels: ['coolChannel', 'coolChannel2'],
193202
});
194203
});
204+
205+
it('supports timetoken', (done) => {
206+
const scope0 = utils
207+
.createNock()
208+
.get('/v2/subscribe/mySubKey/c1/0')
209+
.query({
210+
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
211+
uuid: 'myUUID',
212+
ee: '',
213+
tt: 0,
214+
})
215+
.reply(
216+
200,
217+
'{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}',
218+
{ 'content-type': 'text/javascript' },
219+
);
220+
const scope = utils
221+
.createNock()
222+
.get('/v2/subscribe/mySubKey/c1/0')
223+
.query({
224+
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
225+
uuid: 'myUUID',
226+
ee: '',
227+
tt: '1234567890',
228+
tr: 1,
229+
})
230+
.reply(
231+
200,
232+
'{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}',
233+
{ 'content-type': 'text/javascript' },
234+
);
235+
236+
pubnubWithEE.addListener({
237+
message(message) {
238+
try {
239+
assert.deepEqual(message.message, { text: 'customttresponse' });
240+
assert.equal(scope.isDone(), true);
241+
done();
242+
} catch (error) {
243+
done(error);
244+
}
245+
},
246+
});
247+
const channel = pubnubWithEE.channel('c1');
248+
const subscription = channel.subscription();
249+
subscription.subscribe({ timetoken: '1234567890' });
250+
});
195251
});

0 commit comments

Comments
 (0)