Skip to content

Commit ffdb745

Browse files
aremohitpubnubclient-engineering-bot
authored
fix: wrong error interface in RN (pubnub#305)
* fix: wrong error interface in RN * merge CLEN-913 changes. * PubNub SDK v7.2.2 release. Co-authored-by: Mohit Tejani <[email protected]> Co-authored-by: Client Engineering Bot <[email protected]>
1 parent 0f15940 commit ffdb745

File tree

13 files changed

+95
-51
lines changed

13 files changed

+95
-51
lines changed

.pubnub.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22
changelog:
3+
- date: 2022-12-12
4+
version: v7.2.2
5+
changes:
6+
- type: bug
7+
text: "Fixes a case in React Native with using an error interface in superagent."
8+
- type: bug
9+
text: "Fixes issue of getFileUrl not setting auth value as token string when token is set."
310
- date: 2022-11-10
411
version: v7.2.1
512
changes:
@@ -879,7 +886,7 @@ sdks:
879886
- distribution-type: source
880887
distribution-repository: GitHub release
881888
package-name: pubnub.js
882-
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.1.zip
889+
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.2.zip
883890
requires:
884891
- name: 'agentkeepalive'
885892
min-version: '3.5.2'
@@ -1550,7 +1557,7 @@ sdks:
15501557
- distribution-type: library
15511558
distribution-repository: GitHub release
15521559
package-name: pubnub.js
1553-
location: https://github.com/pubnub/javascript/releases/download/v7.2.1/pubnub.7.2.1.js
1560+
location: https://github.com/pubnub/javascript/releases/download/v7.2.2/pubnub.7.2.2.js
15541561
requires:
15551562
- name: 'agentkeepalive'
15561563
min-version: '3.5.2'

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v7.2.2
2+
December 12 2022
3+
4+
#### Fixed
5+
- Fixes a case in React Native with using an error interface in superagent.
6+
- Fixes issue of getFileUrl not setting auth value as token string when token is set. Fixed the following issues reported by [@abdalla-nayer](https://github.com/abdalla-nayer): [#302](https://github.com/pubnub/javascript/issues/302).
7+
18
## v7.2.1
29
November 10 2022
310

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2222
npm install pubnub
2323
```
2424
* or download one of our builds from our CDN:
25-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.min.js
25+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.2.js
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.2.min.js
2727
2828
2. Configure your keys:
2929

dist/web/pubnub.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@
768768
return this;
769769
};
770770
default_1.prototype.getVersion = function () {
771-
return '7.2.1';
771+
return '7.2.2';
772772
};
773773
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
774774
this._PNSDKSuffix[name] = suffix;
@@ -4706,7 +4706,7 @@
47064706
}
47074707
_s.label = 4;
47084708
case 4:
4709-
_s.trys.push([4, 18, , 20]);
4709+
_s.trys.push([4, 18, , 22]);
47104710
if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 7];
47114711
_f = (_e = networking).POSTFILE;
47124712
_g = [url, formFieldsWithMimeType];
@@ -4743,24 +4743,27 @@
47434743
result = _s.sent();
47444744
return [3 /*break*/, 17];
47454745
case 16: throw new Error('Unsupported environment');
4746-
case 17: return [3 /*break*/, 20];
4746+
case 17: return [3 /*break*/, 22];
47474747
case 18:
47484748
e_1 = _s.sent();
4749+
if (!e_1.response) return [3 /*break*/, 20];
47494750
return [4 /*yield*/, getErrorFromResponse(e_1.response)];
47504751
case 19:
47514752
errorBody = _s.sent();
47524753
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
47534754
throw new PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1);
4754-
case 20:
4755+
case 20: throw new PubNubError('Upload to bucket failed.', e_1);
4756+
case 21: return [3 /*break*/, 22];
4757+
case 22:
47554758
if (result.status !== 204) {
47564759
throw new PubNubError('Upload to bucket was unsuccessful', result);
47574760
}
47584761
retries = config.fileUploadPublishRetryLimit;
47594762
wasSuccessful = false;
47604763
publishResult = { timetoken: '0' };
4761-
_s.label = 21;
4762-
case 21:
4763-
_s.trys.push([21, 23, , 24]);
4764+
_s.label = 23;
4765+
case 23:
4766+
_s.trys.push([23, 25, , 26]);
47644767
return [4 /*yield*/, publishFile({
47654768
channel: channel,
47664769
message: message,
@@ -4770,19 +4773,19 @@
47704773
storeInHistory: storeInHistory,
47714774
ttl: ttl,
47724775
})];
4773-
case 22:
4776+
case 24:
47744777
/* eslint-disable-next-line no-await-in-loop */
47754778
publishResult = _s.sent();
47764779
wasSuccessful = true;
4777-
return [3 /*break*/, 24];
4778-
case 23:
4780+
return [3 /*break*/, 26];
4781+
case 25:
47794782
_s.sent();
47804783
retries -= 1;
4781-
return [3 /*break*/, 24];
4782-
case 24:
4783-
if (!wasSuccessful && retries > 0) return [3 /*break*/, 21];
4784-
_s.label = 25;
4785-
case 25:
4784+
return [3 /*break*/, 26];
4785+
case 26:
4786+
if (!wasSuccessful && retries > 0) return [3 /*break*/, 23];
4787+
_s.label = 27;
4788+
case 27:
47864789
if (!wasSuccessful) {
47874790
throw new PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', {
47884791
channel: channel,
@@ -4817,7 +4820,7 @@
48174820
/** */
48184821
var getFileUrlFunction = (function (modules, _a) {
48194822
var channel = _a.channel, id = _a.id, name = _a.name;
4820-
var config = modules.config, networking = modules.networking;
4823+
var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager;
48214824
if (!channel) {
48224825
throw new PubNubError('Validation failed, check status for details', createValidationError("channel can't be empty"));
48234826
}
@@ -4831,8 +4834,9 @@
48314834
var params = {};
48324835
params.uuid = config.getUUID();
48334836
params.pnsdk = generatePNSDK(config);
4834-
if (config.getAuthKey()) {
4835-
params.auth = config.getAuthKey();
4837+
var tokenOrKey = tokenManager.getToken() || config.getAuthKey();
4838+
if (tokenOrKey) {
4839+
params.auth = tokenOrKey;
48364840
}
48374841
if (config.secretKey) {
48384842
signRequest(modules, url, params, {}, {

dist/web/pubnub.min.js

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

lib/core/components/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ var default_1 = /** @class */ (function () {
169169
return this;
170170
};
171171
default_1.prototype.getVersion = function () {
172-
return '7.2.1';
172+
return '7.2.2';
173173
};
174174
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
175175
this._PNSDKSuffix[name] = suffix;

lib/core/endpoints/file_upload/get_file_url.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var endpoint_1 = require("../../components/endpoint");
88
var utils_1 = __importDefault(require("../../utils"));
99
exports.default = (function (modules, _a) {
1010
var channel = _a.channel, id = _a.id, name = _a.name;
11-
var config = modules.config, networking = modules.networking;
11+
var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager;
1212
if (!channel) {
1313
throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("channel can't be empty"));
1414
}
@@ -22,8 +22,9 @@ exports.default = (function (modules, _a) {
2222
var params = {};
2323
params.uuid = config.getUUID();
2424
params.pnsdk = (0, endpoint_1.generatePNSDK)(config);
25-
if (config.getAuthKey()) {
26-
params.auth = config.getAuthKey();
25+
var tokenOrKey = tokenManager.getToken() || config.getAuthKey();
26+
if (tokenOrKey) {
27+
params.auth = tokenOrKey;
2728
}
2829
if (config.secretKey) {
2930
(0, endpoint_1.signRequest)(modules, url, params, {}, {

lib/core/endpoints/file_upload/send_file.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ var sendFile = function (_a) {
8484
}
8585
_s.label = 4;
8686
case 4:
87-
_s.trys.push([4, 18, , 20]);
87+
_s.trys.push([4, 18, , 22]);
8888
if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 7];
8989
_f = (_e = networking).POSTFILE;
9090
_g = [url, formFieldsWithMimeType];
@@ -121,24 +121,27 @@ var sendFile = function (_a) {
121121
result = _s.sent();
122122
return [3 /*break*/, 17];
123123
case 16: throw new Error('Unsupported environment');
124-
case 17: return [3 /*break*/, 20];
124+
case 17: return [3 /*break*/, 22];
125125
case 18:
126126
e_1 = _s.sent();
127+
if (!e_1.response) return [3 /*break*/, 20];
127128
return [4 /*yield*/, getErrorFromResponse(e_1.response)];
128129
case 19:
129130
errorBody = _s.sent();
130131
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
131132
throw new endpoint_1.PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1);
132-
case 20:
133+
case 20: throw new endpoint_1.PubNubError('Upload to bucket failed.', e_1);
134+
case 21: return [3 /*break*/, 22];
135+
case 22:
133136
if (result.status !== 204) {
134137
throw new endpoint_1.PubNubError('Upload to bucket was unsuccessful', result);
135138
}
136139
retries = config.fileUploadPublishRetryLimit;
137140
wasSuccessful = false;
138141
publishResult = { timetoken: '0' };
139-
_s.label = 21;
140-
case 21:
141-
_s.trys.push([21, 23, , 24]);
142+
_s.label = 23;
143+
case 23:
144+
_s.trys.push([23, 25, , 26]);
142145
return [4 /*yield*/, publishFile({
143146
channel: channel,
144147
message: message,
@@ -148,19 +151,19 @@ var sendFile = function (_a) {
148151
storeInHistory: storeInHistory,
149152
ttl: ttl,
150153
})];
151-
case 22:
154+
case 24:
152155
/* eslint-disable-next-line no-await-in-loop */
153156
publishResult = _s.sent();
154157
wasSuccessful = true;
155-
return [3 /*break*/, 24];
156-
case 23:
158+
return [3 /*break*/, 26];
159+
case 25:
157160
e_2 = _s.sent();
158161
retries -= 1;
159-
return [3 /*break*/, 24];
160-
case 24:
161-
if (!wasSuccessful && retries > 0) return [3 /*break*/, 21];
162-
_s.label = 25;
163-
case 25:
162+
return [3 /*break*/, 26];
163+
case 26:
164+
if (!wasSuccessful && retries > 0) return [3 /*break*/, 23];
165+
_s.label = 27;
166+
case 27:
164167
if (!wasSuccessful) {
165168
throw new endpoint_1.PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', {
166169
channel: channel,

package.json

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

src/core/components/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export default class {
339339
}
340340

341341
getVersion() {
342-
return '7.2.1';
342+
return '7.2.2';
343343
}
344344

345345
_addPnsdkSuffix(name, suffix) {

src/core/endpoints/file_upload/get_file_url.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PubNubError, createValidationError, signRequest, generatePNSDK } from '
55
import utils from '../../utils';
66

77
export default (modules, { channel, id, name }) => {
8-
const { config, networking } = modules;
8+
const { config, networking, tokenManager } = modules;
99

1010
if (!channel) {
1111
throw new PubNubError(
@@ -34,8 +34,9 @@ export default (modules, { channel, id, name }) => {
3434
params.uuid = config.getUUID();
3535
params.pnsdk = generatePNSDK(config);
3636

37-
if (config.getAuthKey()) {
38-
params.auth = config.getAuthKey();
37+
const tokenOrKey = tokenManager.getToken() || config.getAuthKey();
38+
if (tokenOrKey) {
39+
params.auth = tokenOrKey;
3940
}
4041

4142
if (config.secretKey) {

src/core/endpoints/file_upload/send_file.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ const sendFile = function ({
6868
throw new Error('Unsupported environment');
6969
}
7070
} catch (e) {
71-
const errorBody = await getErrorFromResponse(e.response);
71+
if (e.response) {
72+
const errorBody = await getErrorFromResponse(e.response);
7273

73-
const reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
74+
const reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
7475

75-
throw new PubNubError(reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.', e);
76+
throw new PubNubError(reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.', e);
77+
} else {
78+
throw new PubNubError('Upload to bucket failed.', e);
79+
}
7680
}
7781

7882
if (result.status !== 204) {

test/integration/endpoints/get_file_url.test.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/* eslint no-console: 0 */
33

44
import assert from 'assert';
5-
import nock from 'nock';
6-
import utils from '../../utils';
75
import PubNub from '../../../src/node/index';
86

97
describe('getFileUrl', () => {
@@ -35,4 +33,23 @@ describe('getFileUrl', () => {
3533
assert(url === `https://test1.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`
3634
|| url === `https://test2.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`);
3735
});
36+
37+
it('constructs proper url when token is set', () => {
38+
const pubnub = new PubNub({
39+
subscribeKey: 'demo',
40+
publishKey: 'demo',
41+
uuid: 'myUUID',
42+
origin: 'example.com',
43+
});
44+
45+
pubnub.setToken('tokenString');
46+
47+
const url = pubnub.getFileUrl({ channel: 'channel', id: 'id', name: 'name' });
48+
const pnsdk = `PubNub-JS-${pubnub._config.sdkFamily}%2F${pubnub._config.getVersion()}`;
49+
50+
assert.equal(
51+
url,
52+
`https://example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}&auth=tokenString`,
53+
);
54+
});
3855
});

0 commit comments

Comments
 (0)