Skip to content

Commit bd5bd83

Browse files
phairowRai PhairowClient Engineering Bot
authored
fix for react native token parsing (#280)
* fix for react native token parsing * rebase * use base64 fix from clen-535 * build * fix module issue with web build * PubNub SDK v7.1.2 release. Co-authored-by: Rai Phairow <[email protected]> Co-authored-by: Client Engineering Bot <60980775+Client Engineering [email protected]>
1 parent dbfbf3d commit bd5bd83

File tree

16 files changed

+219
-159
lines changed

16 files changed

+219
-159
lines changed

.pubnub.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
22
changelog:
3+
- date: 2022-06-22
4+
version: v7.1.2
5+
changes:
6+
37
- date: 2022-06-14
48
version: v7.1.1
59
changes:
@@ -1124,7 +1128,7 @@ supported-platforms:
11241128
- "Ubuntu 14.04 and up"
11251129
- "Windows 7 and up"
11261130
version: "Pubnub Javascript for Node"
1127-
version: "7.1.1"
1131+
version: "7.1.2"
11281132
sdks:
11291133
-
11301134
full-name: PubNub Javascript SDK
@@ -1143,7 +1147,7 @@ sdks:
11431147
distribution-type: source
11441148
distribution-repository: GitHub release
11451149
package-name: pubnub.js
1146-
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.1.1.zip
1150+
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.1.2.zip
11471151
requires:
11481152
-
11491153
name: "agentkeepalive"
@@ -1907,7 +1911,7 @@ sdks:
19071911
distribution-type: library
19081912
distribution-repository: GitHub release
19091913
package-name: pubnub.js
1910-
location: https://github.com/pubnub/javascript/releases/download/v7.1.1/pubnub.7.1.1.js
1914+
location: https://github.com/pubnub/javascript/releases/download/v7.1.2/pubnub.7.1.2.js
19111915
requires:
19121916
-
19131917
name: "agentkeepalive"

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v7.1.2
2+
June 22 2022
3+
14
## v7.1.1
25
June 14 2022
36

README.md

Lines changed: 2 additions & 2 deletions
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.1.1.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.1.1.min.js
25+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.1.2.js
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.1.2.min.js
2727
2828
2. Configure your keys:
2929

dist/web/pubnub.js

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@
747747
return this;
748748
};
749749
default_1.prototype.getVersion = function () {
750-
return '7.1.1';
750+
return '7.1.2';
751751
};
752752
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
753753
this._PNSDKSuffix[name] = suffix;
@@ -7672,6 +7672,80 @@
76727672
return default_1;
76737673
}());
76747674

7675+
var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
7676+
/**
7677+
* Decode a Base64 encoded string.
7678+
*
7679+
* @param paddedInput Base64 string with padding
7680+
* @returns ArrayBuffer with decoded data
7681+
*/
7682+
function decode$1(paddedInput) {
7683+
// Remove up to last two equal signs.
7684+
var input = paddedInput.replace(/==?$/, '');
7685+
var outputLength = Math.floor((input.length / 4) * 3);
7686+
// Prepare output buffer.
7687+
var data = new ArrayBuffer(outputLength);
7688+
var view = new Uint8Array(data);
7689+
var cursor = 0;
7690+
/**
7691+
* Returns the next integer representation of a sixtet of bytes from the input
7692+
* @returns sixtet of bytes
7693+
*/
7694+
function nextSixtet() {
7695+
var char = input.charAt(cursor++);
7696+
var index = BASE64_CHARMAP.indexOf(char);
7697+
if (index === -1) {
7698+
throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1)));
7699+
}
7700+
return index;
7701+
}
7702+
for (var i = 0; i < outputLength; i += 3) {
7703+
// Obtain four sixtets
7704+
var sx1 = nextSixtet();
7705+
var sx2 = nextSixtet();
7706+
var sx3 = nextSixtet();
7707+
var sx4 = nextSixtet();
7708+
// Encode them as three octets
7709+
var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4);
7710+
var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2);
7711+
var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0);
7712+
view[i] = oc1;
7713+
// Skip padding bytes.
7714+
if (sx3 != 64)
7715+
view[i + 1] = oc2;
7716+
if (sx4 != 64)
7717+
view[i + 2] = oc3;
7718+
}
7719+
return data;
7720+
}
7721+
7722+
function stringifyBufferKeys(obj) {
7723+
var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; };
7724+
var isString = function (value) { return typeof value === 'string' || value instanceof String; };
7725+
var isNumber = function (value) { return typeof value === 'number' && isFinite(value); };
7726+
if (!isObject(obj)) {
7727+
return obj;
7728+
}
7729+
var normalizedObject = {};
7730+
Object.keys(obj).forEach(function (key) {
7731+
var keyIsString = isString(key);
7732+
var stringifiedKey = key;
7733+
var value = obj[key];
7734+
if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) {
7735+
var bytes = keyIsString ? key.split(',') : key;
7736+
stringifiedKey = bytes.reduce(function (string, byte) {
7737+
string += String.fromCharCode(byte);
7738+
return string;
7739+
}, '');
7740+
}
7741+
else if (isNumber(key) || (keyIsString && !isNaN(key))) {
7742+
stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10);
7743+
}
7744+
normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value;
7745+
});
7746+
return normalizedObject;
7747+
}
7748+
76757749
var default_1$1 = /** @class */ (function () {
76767750
function default_1(decode, base64ToBinary) {
76777751
this._base64ToBinary = base64ToBinary;
@@ -11499,60 +11573,6 @@
1149911573
return false;
1150011574
}
1150111575
}
11502-
function base64ToBinary(base64String) {
11503-
var parsedWordArray = hmacSha256.enc.Base64.parse(base64String).words;
11504-
var arrayBuffer = new ArrayBuffer(parsedWordArray.length * 4);
11505-
var view = new Uint8Array(arrayBuffer);
11506-
var filledArrayBuffer = null;
11507-
var zeroBytesCount = 0;
11508-
var byteOffset = 0;
11509-
for (var wordIdx = 0; wordIdx < parsedWordArray.length; wordIdx += 1) {
11510-
var word = parsedWordArray[wordIdx];
11511-
byteOffset = wordIdx * 4;
11512-
view[byteOffset] = (word & 0xff000000) >> 24;
11513-
view[byteOffset + 1] = (word & 0x00ff0000) >> 16;
11514-
view[byteOffset + 2] = (word & 0x0000ff00) >> 8;
11515-
view[byteOffset + 3] = word & 0x000000ff;
11516-
}
11517-
for (var byteIdx = byteOffset + 3; byteIdx >= byteOffset; byteIdx -= 1) {
11518-
if (view[byteIdx] === 0 && zeroBytesCount < 3) {
11519-
zeroBytesCount += 1;
11520-
}
11521-
}
11522-
if (zeroBytesCount > 0) {
11523-
filledArrayBuffer = view.buffer.slice(0, view.byteLength - zeroBytesCount);
11524-
}
11525-
else {
11526-
filledArrayBuffer = view.buffer;
11527-
}
11528-
return filledArrayBuffer;
11529-
}
11530-
function stringifyBufferKeys(obj) {
11531-
var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; };
11532-
var isString = function (value) { return typeof value === 'string' || value instanceof String; };
11533-
var isNumber = function (value) { return typeof value === 'number' && isFinite(value); };
11534-
if (!isObject(obj)) {
11535-
return obj;
11536-
}
11537-
var normalizedObject = {};
11538-
Object.keys(obj).forEach(function (key) {
11539-
var keyIsString = isString(key);
11540-
var stringifiedKey = key;
11541-
var value = obj[key];
11542-
if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) {
11543-
var bytes = keyIsString ? key.split(',') : key;
11544-
stringifiedKey = bytes.reduce(function (string, byte) {
11545-
string += String.fromCharCode(byte);
11546-
return string;
11547-
}, '');
11548-
}
11549-
else if (isNumber(key) || (keyIsString && !isNaN(key))) {
11550-
stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10);
11551-
}
11552-
normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value;
11553-
});
11554-
return normalizedObject;
11555-
}
1155611576
var default_1 = /** @class */ (function (_super) {
1155711577
__extends(default_1, _super);
1155811578
function default_1(setup) {
@@ -11569,7 +11589,7 @@
1156911589
getfile: getfile,
1157011590
postfile: postfile,
1157111591
});
11572-
setup.cbor = new default_1$1(function (arrayBuffer) { return stringifyBufferKeys(CborReader.decode(arrayBuffer)); }, base64ToBinary);
11592+
setup.cbor = new default_1$1(function (arrayBuffer) { return stringifyBufferKeys(CborReader.decode(arrayBuffer)); }, decode$1);
1157311593
setup.PubNubFile = PubNubFile;
1157411594
setup.cryptography = new WebCryptography();
1157511595
_this = _super.call(this, setup) || this;

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/base64_codec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.decode = void 0;
4+
var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
5+
/**
6+
* Decode a Base64 encoded string.
7+
*
8+
* @param paddedInput Base64 string with padding
9+
* @returns ArrayBuffer with decoded data
10+
*/
11+
function decode(paddedInput) {
12+
// Remove up to last two equal signs.
13+
var input = paddedInput.replace(/==?$/, '');
14+
var outputLength = Math.floor((input.length / 4) * 3);
15+
// Prepare output buffer.
16+
var data = new ArrayBuffer(outputLength);
17+
var view = new Uint8Array(data);
18+
var cursor = 0;
19+
/**
20+
* Returns the next integer representation of a sixtet of bytes from the input
21+
* @returns sixtet of bytes
22+
*/
23+
function nextSixtet() {
24+
var char = input.charAt(cursor++);
25+
var index = BASE64_CHARMAP.indexOf(char);
26+
if (index === -1) {
27+
throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1)));
28+
}
29+
return index;
30+
}
31+
for (var i = 0; i < outputLength; i += 3) {
32+
// Obtain four sixtets
33+
var sx1 = nextSixtet();
34+
var sx2 = nextSixtet();
35+
var sx3 = nextSixtet();
36+
var sx4 = nextSixtet();
37+
// Encode them as three octets
38+
var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4);
39+
var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2);
40+
var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0);
41+
view[i] = oc1;
42+
// Skip padding bytes.
43+
if (sx3 != 64)
44+
view[i + 1] = oc2;
45+
if (sx4 != 64)
46+
view[i + 2] = oc3;
47+
}
48+
return data;
49+
}
50+
exports.decode = decode;

lib/core/components/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ var default_1 = /** @class */ (function () {
148148
return this;
149149
};
150150
default_1.prototype.getVersion = function () {
151-
return '7.1.1';
151+
return '7.1.2';
152152
};
153153
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
154154
this._PNSDKSuffix[name] = suffix;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.stringifyBufferKeys = void 0;
4+
function stringifyBufferKeys(obj) {
5+
var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; };
6+
var isString = function (value) { return typeof value === 'string' || value instanceof String; };
7+
var isNumber = function (value) { return typeof value === 'number' && isFinite(value); };
8+
if (!isObject(obj)) {
9+
return obj;
10+
}
11+
var normalizedObject = {};
12+
Object.keys(obj).forEach(function (key) {
13+
var keyIsString = isString(key);
14+
var stringifiedKey = key;
15+
var value = obj[key];
16+
if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) {
17+
var bytes = keyIsString ? key.split(',') : key;
18+
stringifiedKey = bytes.reduce(function (string, byte) {
19+
string += String.fromCharCode(byte);
20+
return string;
21+
}, '');
22+
}
23+
else if (isNumber(key) || (keyIsString && !isNaN(key))) {
24+
stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10);
25+
}
26+
normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value;
27+
});
28+
return normalizedObject;
29+
}
30+
exports.stringifyBufferKeys = stringifyBufferKeys;

lib/node/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var cbor_sync_1 = __importDefault(require("cbor-sync"));
2121
var pubnub_common_1 = __importDefault(require("../core/pubnub-common"));
2222
var networking_1 = __importDefault(require("../networking"));
2323
var common_1 = __importDefault(require("../cbor/common"));
24+
var base64_codec_1 = require("../core/components/base64_codec");
2425
var web_node_1 = require("../networking/modules/web-node");
2526
var node_1 = require("../networking/modules/node");
2627
var node_2 = __importDefault(require("../crypto/modules/node"));
@@ -29,7 +30,7 @@ module.exports = /** @class */ (function (_super) {
2930
__extends(class_1, _super);
3031
function class_1(setup) {
3132
var _this = this;
32-
setup.cbor = new common_1.default(cbor_sync_1.default.decode, function (base64String) { return Buffer.from(base64String, 'base64'); });
33+
setup.cbor = new common_1.default(function (buffer) { return cbor_sync_1.default.decode(Buffer.from(buffer)); }, base64_codec_1.decode);
3334
setup.networking = new networking_1.default({
3435
keepAlive: node_1.keepAlive,
3536
del: web_node_1.del,

lib/react_native/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1818
return (mod && mod.__esModule) ? mod : { "default": mod };
1919
};
2020
Object.defineProperty(exports, "__esModule", { value: true });
21-
var cbor_sync_1 = __importDefault(require("cbor-sync"));
21+
var cbor_js_1 = __importDefault(require("cbor-js"));
2222
var buffer_1 = require("buffer");
2323
var pubnub_common_1 = __importDefault(require("../core/pubnub-common"));
2424
var networking_1 = __importDefault(require("../networking"));
25+
var base64_codec_1 = require("../core/components/base64_codec");
26+
var stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys");
2527
var common_1 = __importDefault(require("../cbor/common"));
2628
var web_node_1 = require("../networking/modules/web-node");
2729
var react_native_1 = require("../networking/modules/react_native");
@@ -31,7 +33,7 @@ var default_1 = /** @class */ (function (_super) {
3133
__extends(default_1, _super);
3234
function default_1(setup) {
3335
var _this = this;
34-
setup.cbor = new common_1.default(cbor_sync_1.default.decode, function (base64String) { return buffer_1.Buffer.from(base64String, 'base64'); });
36+
setup.cbor = new common_1.default(function (arrayBuffer) { return (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)); }, base64_codec_1.decode);
3537
setup.PubNubFile = react_native_2.default;
3638
setup.networking = new networking_1.default({
3739
del: web_node_1.del,

0 commit comments

Comments
 (0)