1- /*! 4.29.8 / Consumer */
1+ /*! 4.29.9 / Consumer */
22exports [ "PubNub" ] =
33/******/ ( function ( modules ) { // webpackBootstrap
44/******/ // The module cache
@@ -566,7 +566,7 @@ var _default = function () {
566566 } , {
567567 key : "getVersion" ,
568568 value : function getVersion ( ) {
569- return '4.29.8 ' ;
569+ return '4.29.9 ' ;
570570 }
571571 } , {
572572 key : "_addPnsdkSuffix" ,
@@ -756,6 +756,8 @@ Object.defineProperty(exports, "__esModule", {
756756 value : true
757757} ) ;
758758exports . createValidationError = createValidationError ;
759+ exports . generatePNSDK = generatePNSDK ;
760+ exports . signRequest = signRequest ;
759761exports [ "default" ] = _default ;
760762exports . PubNubError = void 0 ;
761763
@@ -892,6 +894,10 @@ function signRequest(modules, url, outgoingParams, incomingParams, endpoint) {
892894 httpMethod = 'GET' ;
893895 }
894896
897+ if ( httpMethod === 'GETFILE' ) {
898+ httpMethod = 'GET' ;
899+ }
900+
895901 var signInput = "" . concat ( httpMethod , "\n" ) . concat ( config . publishKey , "\n" ) . concat ( url , "\n" ) . concat ( _utils [ "default" ] . signPamFromParams ( outgoingParams ) , "\n" ) ;
896902
897903 if ( httpMethod === 'POST' ) {
@@ -7686,6 +7692,18 @@ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(22));
76867692
76877693var _endpoint = __webpack_require__ ( 16 ) ;
76887694
7695+ var getErrorFromResponse = function getErrorFromResponse ( response ) {
7696+ return new Promise ( function ( resolve ) {
7697+ var result = '' ;
7698+ response . on ( 'data' , function ( data ) {
7699+ result += data . toString ( 'utf8' ) ;
7700+ } ) ;
7701+ response . on ( 'end' , function ( ) {
7702+ resolve ( result ) ;
7703+ } ) ;
7704+ } ) ;
7705+ } ;
7706+
76897707var sendFile = function sendFile ( _ref ) {
76907708 var generateUploadUrl = _ref . generateUploadUrl ,
76917709 publishFile = _ref . publishFile ,
@@ -7696,7 +7714,7 @@ var sendFile = function sendFile(_ref) {
76967714 networking = _ref$modules . networking ;
76977715 return function ( ) {
76987716 var _ref3 = ( 0 , _asyncToGenerator2 [ "default" ] ) ( _regenerator [ "default" ] . mark ( function _callee ( _ref2 ) {
7699- var channel , input , message , cipherKey , meta , ttl , storeInHistory , file , _yield$generateUpload , _yield$generateUpload2 , url , formFields , _yield$generateUpload3 , id , name , formFieldsWithMimeType , result , retries , wasSuccessful ;
7717+ var channel , input , message , cipherKey , meta , ttl , storeInHistory , file , _yield$generateUpload , _yield$generateUpload2 , url , formFields , _yield$generateUpload3 , id , name , formFieldsWithMimeType , result , errorBody , reason , retries , wasSuccessful , publishResult ;
77007718
77017719 return _regenerator [ "default" ] . wrap ( function _callee$ ( _context ) {
77027720 while ( 1 ) {
@@ -7852,34 +7870,43 @@ var sendFile = function sendFile(_ref) {
78527870 throw new Error ( 'Unsupported environment' ) ;
78537871
78547872 case 71 :
7855- _context . next = 76 ;
7873+ _context . next = 80 ;
78567874 break ;
78577875
78587876 case 73 :
78597877 _context . prev = 73 ;
78607878 _context . t16 = _context [ "catch" ] ( 21 ) ;
7861- throw new _endpoint . PubNubError ( 'Upload to bucket failed' , _context . t16 ) ;
7879+ _context . next = 77 ;
7880+ return getErrorFromResponse ( _context . t16 . response ) ;
78627881
7863- case 76 :
7882+ case 77 :
7883+ errorBody = _context . sent ;
7884+ reason = / < M e s s a g e > ( .* ) < \/ M e s s a g e > / gi. exec ( errorBody ) ;
7885+ throw new _endpoint . PubNubError ( reason ? "Upload to bucket failed: " . concat ( reason [ 1 ] ) : 'Upload to bucket failed.' , _context . t16 ) ;
7886+
7887+ case 80 :
78647888 if ( ! ( result . status !== 204 ) ) {
7865- _context . next = 78 ;
7889+ _context . next = 82 ;
78667890 break ;
78677891 }
78687892
78697893 throw new _endpoint . PubNubError ( 'Upload to bucket was unsuccessful' , result ) ;
78707894
7871- case 78 :
7895+ case 82 :
78727896 retries = 5 ;
78737897 wasSuccessful = false ;
7898+ publishResult = {
7899+ timetoken : '0'
7900+ } ;
78747901
7875- case 80 :
7902+ case 85 :
78767903 if ( ! ( ! wasSuccessful && retries > 0 ) ) {
7877- _context . next = 92 ;
7904+ _context . next = 98 ;
78787905 break ;
78797906 }
78807907
7881- _context . prev = 81 ;
7882- _context . next = 84 ;
7908+ _context . prev = 86 ;
7909+ _context . next = 89 ;
78837910 return publishFile ( {
78847911 channel : channel ,
78857912 message : message ,
@@ -7890,23 +7917,24 @@ var sendFile = function sendFile(_ref) {
78907917 ttl : ttl
78917918 } ) ;
78927919
7893- case 84 :
7920+ case 89 :
7921+ publishResult = _context . sent ;
78947922 wasSuccessful = true ;
7895- _context . next = 90 ;
7923+ _context . next = 96 ;
78967924 break ;
78977925
7898- case 87 :
7899- _context . prev = 87 ;
7900- _context . t17 = _context [ "catch" ] ( 81 ) ;
7926+ case 93 :
7927+ _context . prev = 93 ;
7928+ _context . t17 = _context [ "catch" ] ( 86 ) ;
79017929 retries -= 1 ;
79027930
7903- case 90 :
7904- _context . next = 80 ;
7931+ case 96 :
7932+ _context . next = 85 ;
79057933 break ;
79067934
7907- case 92 :
7935+ case 98 :
79087936 if ( wasSuccessful ) {
7909- _context . next = 96 ;
7937+ _context . next = 102 ;
79107938 break ;
79117939 }
79127940
@@ -7916,18 +7944,19 @@ var sendFile = function sendFile(_ref) {
79167944 name : name
79177945 } ) ;
79187946
7919- case 96 :
7947+ case 102 :
79207948 return _context . abrupt ( "return" , {
7949+ timetoken : publishResult . timetoken ,
79217950 id : id ,
79227951 name : name
79237952 } ) ;
79247953
7925- case 97 :
7954+ case 103 :
79267955 case "end" :
79277956 return _context . stop ( ) ;
79287957 }
79297958 }
7930- } , _callee , null , [ [ 21 , 73 ] , [ 81 , 87 ] ] ) ;
7959+ } , _callee , null , [ [ 21 , 73 ] , [ 86 , 93 ] ] ) ;
79317960 } ) ) ;
79327961
79337962 return function ( _x ) {
@@ -8725,11 +8754,11 @@ exports["default"] = void 0;
87258754
87268755var _endpoint = __webpack_require__ ( 16 ) ;
87278756
8728- var _default = function _default ( _ref , _ref2 ) {
8729- var config = _ref . config ;
8730- var channel = _ref2 . channel ,
8731- id = _ref2 . id ,
8732- name = _ref2 . name ;
8757+ var _default = function _default ( modules , _ref ) {
8758+ var channel = _ref . channel ,
8759+ id = _ref . id ,
8760+ name = _ref . name ;
8761+ var config = modules . config ;
87338762
87348763 if ( ! channel ) {
87358764 throw new _endpoint . PubNubError ( 'Validation failed, check status for details' , ( 0 , _endpoint . createValidationError ) ( "channel can't be empty" ) ) ;
@@ -8743,7 +8772,32 @@ var _default = function _default(_ref, _ref2) {
87438772 throw new _endpoint . PubNubError ( 'Validation failed, check status for details' , ( 0 , _endpoint . createValidationError ) ( "file name can't be empty" ) ) ;
87448773 }
87458774
8746- return "https://" . concat ( config . origin , "/v1/files/" ) . concat ( config . subscribeKey , "/channels/" ) . concat ( channel , "/files/" ) . concat ( id , "/" ) . concat ( name ) ;
8775+ var url = "/v1/files/" . concat ( config . subscribeKey , "/channels/" ) . concat ( channel , "/files/" ) . concat ( id , "/" ) . concat ( name ) ;
8776+ var params = { } ;
8777+ params . uuid = config . getUUID ( ) ;
8778+ params . pnsdk = ( 0 , _endpoint . generatePNSDK ) ( config ) ;
8779+
8780+ if ( config . getAuthKey ( ) ) {
8781+ params . auth = config . getAuthKey ( ) ;
8782+ }
8783+
8784+ if ( config . secretKey ) {
8785+ ( 0 , _endpoint . signRequest ) ( modules , url , params , { } , {
8786+ getOperation : function getOperation ( ) {
8787+ return 'PubNubGetFileUrlOperation' ;
8788+ }
8789+ } ) ;
8790+ }
8791+
8792+ var queryParams = Object . keys ( params ) . map ( function ( key ) {
8793+ return "" . concat ( encodeURIComponent ( key ) , "=" ) . concat ( encodeURIComponent ( params [ key ] ) ) ;
8794+ } ) . join ( '&' ) ;
8795+
8796+ if ( queryParams !== '' ) {
8797+ return "https://" . concat ( config . origin ) . concat ( url , "?" ) . concat ( queryParams ) ;
8798+ }
8799+
8800+ return "https://" . concat ( config . origin ) . concat ( url ) ;
87478801} ;
87488802
87498803exports [ "default" ] = _default ;
@@ -8806,15 +8860,11 @@ var endpoint = {
88068860 forceBuffered : function forceBuffered ( ) {
88078861 return true ;
88088862 } ,
8809- getAuthToken : function getAuthToken ( _ref3 ) {
8810- var tokenManager = _ref3 . tokenManager ;
8811- return tokenManager . getToken ( 'fileUpload' ) ;
8812- } ,
88138863 prepareParams : function prepareParams ( ) {
88148864 return { } ;
88158865 } ,
88168866 handleResponse : function ( ) {
8817- var _handleResponse = ( 0 , _asyncToGenerator2 [ "default" ] ) ( _regenerator [ "default" ] . mark ( function _callee ( _ref4 , res , params ) {
8867+ var _handleResponse = ( 0 , _asyncToGenerator2 [ "default" ] ) ( _regenerator [ "default" ] . mark ( function _callee ( _ref3 , res , params ) {
88188868 var _res$response$name ;
88198869
88208870 var PubNubFile , config , cryptography , body , _params$cipherKey ;
@@ -8823,7 +8873,7 @@ var endpoint = {
88238873 while ( 1 ) {
88248874 switch ( _context . prev = _context . next ) {
88258875 case 0 :
8826- PubNubFile = _ref4 . PubNubFile , config = _ref4 . config , cryptography = _ref4 . cryptography ;
8876+ PubNubFile = _ref3 . PubNubFile , config = _ref3 . config , cryptography = _ref3 . cryptography ;
88278877 body = res . response . body ;
88288878
88298879 if ( ! ( PubNubFile . supportsEncryptFile && config . cipherKey ) ) {
0 commit comments