Skip to content

Commit

Permalink
fix: wrong error interface in RN (#305)
Browse files Browse the repository at this point in the history
* fix: wrong error interface in RN

* merge CLEN-913 changes.

* PubNub SDK v7.2.2 release.

Co-authored-by: Mohit Tejani <mohit.tejani@pubnub.com>
Co-authored-by: Client Engineering Bot <60980775+client-engineering-bot@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 13, 2022
1 parent 0f15940 commit ffdb745
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 51 deletions.
11 changes: 9 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
changelog:
- date: 2022-12-12
version: v7.2.2
changes:
- type: bug
text: "Fixes a case in React Native with using an error interface in superagent."
- type: bug
text: "Fixes issue of getFileUrl not setting auth value as token string when token is set."
- date: 2022-11-10
version: v7.2.1
changes:
Expand Down Expand Up @@ -879,7 +886,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.1.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.2.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1550,7 +1557,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v7.2.1/pubnub.7.2.1.js
location: https://github.com/pubnub/javascript/releases/download/v7.2.2/pubnub.7.2.2.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v7.2.2
December 12 2022

#### Fixed
- Fixes a case in React Native with using an error interface in superagent.
- 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).

## v7.2.1
November 10 2022

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ You will need the publish and subscribe keys to authenticate your app. Get your
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.2.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.2.min.js
2. Configure your keys:
Expand Down
40 changes: 22 additions & 18 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
return this;
};
default_1.prototype.getVersion = function () {
return '7.2.1';
return '7.2.2';
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
Expand Down Expand Up @@ -4706,7 +4706,7 @@
}
_s.label = 4;
case 4:
_s.trys.push([4, 18, , 20]);
_s.trys.push([4, 18, , 22]);
if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 7];
_f = (_e = networking).POSTFILE;
_g = [url, formFieldsWithMimeType];
Expand Down Expand Up @@ -4743,24 +4743,27 @@
result = _s.sent();
return [3 /*break*/, 17];
case 16: throw new Error('Unsupported environment');
case 17: return [3 /*break*/, 20];
case 17: return [3 /*break*/, 22];
case 18:
e_1 = _s.sent();
if (!e_1.response) return [3 /*break*/, 20];
return [4 /*yield*/, getErrorFromResponse(e_1.response)];
case 19:
errorBody = _s.sent();
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
throw new PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1);
case 20:
case 20: throw new PubNubError('Upload to bucket failed.', e_1);
case 21: return [3 /*break*/, 22];
case 22:
if (result.status !== 204) {
throw new PubNubError('Upload to bucket was unsuccessful', result);
}
retries = config.fileUploadPublishRetryLimit;
wasSuccessful = false;
publishResult = { timetoken: '0' };
_s.label = 21;
case 21:
_s.trys.push([21, 23, , 24]);
_s.label = 23;
case 23:
_s.trys.push([23, 25, , 26]);
return [4 /*yield*/, publishFile({
channel: channel,
message: message,
Expand All @@ -4770,19 +4773,19 @@
storeInHistory: storeInHistory,
ttl: ttl,
})];
case 22:
case 24:
/* eslint-disable-next-line no-await-in-loop */
publishResult = _s.sent();
wasSuccessful = true;
return [3 /*break*/, 24];
case 23:
return [3 /*break*/, 26];
case 25:
_s.sent();
retries -= 1;
return [3 /*break*/, 24];
case 24:
if (!wasSuccessful && retries > 0) return [3 /*break*/, 21];
_s.label = 25;
case 25:
return [3 /*break*/, 26];
case 26:
if (!wasSuccessful && retries > 0) return [3 /*break*/, 23];
_s.label = 27;
case 27:
if (!wasSuccessful) {
throw new PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', {
channel: channel,
Expand Down Expand Up @@ -4817,7 +4820,7 @@
/** */
var getFileUrlFunction = (function (modules, _a) {
var channel = _a.channel, id = _a.id, name = _a.name;
var config = modules.config, networking = modules.networking;
var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager;
if (!channel) {
throw new PubNubError('Validation failed, check status for details', createValidationError("channel can't be empty"));
}
Expand All @@ -4831,8 +4834,9 @@
var params = {};
params.uuid = config.getUUID();
params.pnsdk = generatePNSDK(config);
if (config.getAuthKey()) {
params.auth = config.getAuthKey();
var tokenOrKey = tokenManager.getToken() || config.getAuthKey();
if (tokenOrKey) {
params.auth = tokenOrKey;
}
if (config.secretKey) {
signRequest(modules, url, params, {}, {
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ var default_1 = /** @class */ (function () {
return this;
};
default_1.prototype.getVersion = function () {
return '7.2.1';
return '7.2.2';
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
Expand Down
7 changes: 4 additions & 3 deletions lib/core/endpoints/file_upload/get_file_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var endpoint_1 = require("../../components/endpoint");
var utils_1 = __importDefault(require("../../utils"));
exports.default = (function (modules, _a) {
var channel = _a.channel, id = _a.id, name = _a.name;
var config = modules.config, networking = modules.networking;
var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager;
if (!channel) {
throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("channel can't be empty"));
}
Expand All @@ -22,8 +22,9 @@ exports.default = (function (modules, _a) {
var params = {};
params.uuid = config.getUUID();
params.pnsdk = (0, endpoint_1.generatePNSDK)(config);
if (config.getAuthKey()) {
params.auth = config.getAuthKey();
var tokenOrKey = tokenManager.getToken() || config.getAuthKey();
if (tokenOrKey) {
params.auth = tokenOrKey;
}
if (config.secretKey) {
(0, endpoint_1.signRequest)(modules, url, params, {}, {
Expand Down
31 changes: 17 additions & 14 deletions lib/core/endpoints/file_upload/send_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var sendFile = function (_a) {
}
_s.label = 4;
case 4:
_s.trys.push([4, 18, , 20]);
_s.trys.push([4, 18, , 22]);
if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 7];
_f = (_e = networking).POSTFILE;
_g = [url, formFieldsWithMimeType];
Expand Down Expand Up @@ -121,24 +121,27 @@ var sendFile = function (_a) {
result = _s.sent();
return [3 /*break*/, 17];
case 16: throw new Error('Unsupported environment');
case 17: return [3 /*break*/, 20];
case 17: return [3 /*break*/, 22];
case 18:
e_1 = _s.sent();
if (!e_1.response) return [3 /*break*/, 20];
return [4 /*yield*/, getErrorFromResponse(e_1.response)];
case 19:
errorBody = _s.sent();
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
throw new endpoint_1.PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1);
case 20:
case 20: throw new endpoint_1.PubNubError('Upload to bucket failed.', e_1);
case 21: return [3 /*break*/, 22];
case 22:
if (result.status !== 204) {
throw new endpoint_1.PubNubError('Upload to bucket was unsuccessful', result);
}
retries = config.fileUploadPublishRetryLimit;
wasSuccessful = false;
publishResult = { timetoken: '0' };
_s.label = 21;
case 21:
_s.trys.push([21, 23, , 24]);
_s.label = 23;
case 23:
_s.trys.push([23, 25, , 26]);
return [4 /*yield*/, publishFile({
channel: channel,
message: message,
Expand All @@ -148,19 +151,19 @@ var sendFile = function (_a) {
storeInHistory: storeInHistory,
ttl: ttl,
})];
case 22:
case 24:
/* eslint-disable-next-line no-await-in-loop */
publishResult = _s.sent();
wasSuccessful = true;
return [3 /*break*/, 24];
case 23:
return [3 /*break*/, 26];
case 25:
e_2 = _s.sent();
retries -= 1;
return [3 /*break*/, 24];
case 24:
if (!wasSuccessful && retries > 0) return [3 /*break*/, 21];
_s.label = 25;
case 25:
return [3 /*break*/, 26];
case 26:
if (!wasSuccessful && retries > 0) return [3 /*break*/, 23];
_s.label = 27;
case 27:
if (!wasSuccessful) {
throw new endpoint_1.PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', {
channel: channel,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "7.2.1",
"version": "7.2.2",
"author": "PubNub <support@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export default class {
}

getVersion() {
return '7.2.1';
return '7.2.2';
}

_addPnsdkSuffix(name, suffix) {
Expand Down
7 changes: 4 additions & 3 deletions src/core/endpoints/file_upload/get_file_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PubNubError, createValidationError, signRequest, generatePNSDK } from '
import utils from '../../utils';

export default (modules, { channel, id, name }) => {
const { config, networking } = modules;
const { config, networking, tokenManager } = modules;

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

if (config.getAuthKey()) {
params.auth = config.getAuthKey();
const tokenOrKey = tokenManager.getToken() || config.getAuthKey();
if (tokenOrKey) {
params.auth = tokenOrKey;
}

if (config.secretKey) {
Expand Down
10 changes: 7 additions & 3 deletions src/core/endpoints/file_upload/send_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ const sendFile = function ({
throw new Error('Unsupported environment');
}
} catch (e) {
const errorBody = await getErrorFromResponse(e.response);
if (e.response) {
const errorBody = await getErrorFromResponse(e.response);

const reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
const reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);

throw new PubNubError(reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.', e);
throw new PubNubError(reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.', e);
} else {
throw new PubNubError('Upload to bucket failed.', e);
}
}

if (result.status !== 204) {
Expand Down
21 changes: 19 additions & 2 deletions test/integration/endpoints/get_file_url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/* eslint no-console: 0 */

import assert from 'assert';
import nock from 'nock';
import utils from '../../utils';
import PubNub from '../../../src/node/index';

describe('getFileUrl', () => {
Expand Down Expand Up @@ -35,4 +33,23 @@ describe('getFileUrl', () => {
assert(url === `https://test1.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`
|| url === `https://test2.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`);
});

it('constructs proper url when token is set', () => {
const pubnub = new PubNub({
subscribeKey: 'demo',
publishKey: 'demo',
uuid: 'myUUID',
origin: 'example.com',
});

pubnub.setToken('tokenString');

const url = pubnub.getFileUrl({ channel: 'channel', id: 'id', name: 'name' });
const pnsdk = `PubNub-JS-${pubnub._config.sdkFamily}%2F${pubnub._config.getVersion()}`;

assert.equal(
url,
`https://example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}&auth=tokenString`,
);
});
});

0 comments on commit ffdb745

Please sign in to comment.