1
1
////@ts -check
2
2
//connectionConfig
3
3
const typedef = require ( './typedef' )
4
+ const { encodeURISegment} = require ( "./utils" )
4
5
5
6
/**
6
7
* @file Terminus DB connection configuration
@@ -83,7 +84,9 @@ ConnectionConfig.prototype.update = function(params) {
83
84
//if (typeof params.credential !== 'undefined')this.setTokenParameter(params.credential)
84
85
if ( typeof params . db !== 'undefined' ) this . setDB ( params . db )
85
86
//this to set the author and the jwt in creation
86
- if ( typeof params . jwt !== 'undefined' ) this . setLocalBasicAuth ( params . jwt , params . user , 'jwt' )
87
+ if ( typeof params . token !== 'undefined' ) this . setLocalBasicAuth ( params . token , params . user , 'apikey' )
88
+ //this is for jwt
89
+ else if ( typeof params . jwt !== 'undefined' ) this . setLocalBasicAuth ( params . jwt , params . user , 'jwt' )
87
90
//this is basic authO
88
91
else if ( typeof params . key !== 'undefined' ) this . setLocalBasicAuth ( params . key , params . user )
89
92
//If I set only the user I have to set the
@@ -225,7 +228,8 @@ ConnectionConfig.prototype.parseServerURL = function(str) {
225
228
ConnectionConfig . prototype . serverUrlEncoding = function ( str ) {
226
229
const orgArr = str . split ( "/" )
227
230
if ( orgArr . length > 3 ) {
228
- const org = encodeURIComponent ( orgArr [ 3 ] )
231
+ //const org = encodeURI(orgArr[3])
232
+ const org = encodeURISegment ( orgArr [ 3 ] )
229
233
return str . replace ( orgArr [ 3 ] , org )
230
234
}
231
235
return str
@@ -309,7 +313,7 @@ ConnectionConfig.prototype.setRemoteBasicAuth = function(remoteKey, remoteUserID
309
313
* set the local database connection credential
310
314
* @param {string } [userKey] - basic auth api key
311
315
* @param {string } [userId] - user id
312
- * @param {string } [type] - basic|jwt
316
+ * @param {string } [type] - basic|jwt|apikey
313
317
*/
314
318
//to be review this is ok for the basic Auth
315
319
ConnectionConfig . prototype . setLocalBasicAuth = function ( userKey , userId = 'admin' , type = 'basic' ) {
@@ -358,7 +362,7 @@ ConnectionConfig.prototype.dbURL = function() {
358
362
359
363
ConnectionConfig . prototype . userURL = function ( user ) {
360
364
let url = `${ this . apiURL ( ) } user`
361
- if ( user ) url += `/${ encodeURIComponent ( user ) } `
365
+ if ( user ) url += `/${ encodeURISegment ( user ) } `
362
366
return url
363
367
}
364
368
@@ -368,11 +372,11 @@ ConnectionConfig.prototype.userURL = function(user) {
368
372
* @param {string } [action] - the organization id
369
373
* @returns {string }
370
374
*/
371
-
375
+ //encodeURIComponent
372
376
ConnectionConfig . prototype . organizationURL = function ( orgId , action ) {
373
377
let url = `${ this . apiURL ( ) } organization`
374
- if ( orgId ) url += `/${ encodeURIComponent ( orgId ) } `
375
- if ( action ) url += `/${ encodeURIComponent ( action ) } `
378
+ if ( orgId ) url += `/${ encodeURISegment ( orgId ) } `
379
+ if ( action ) url += `/${ encodeURISegment ( action ) } `
376
380
return url
377
381
}
378
382
@@ -561,7 +565,7 @@ ConnectionConfig.prototype.commitDescriptorUrl = function(commitId) {
561
565
/**
562
566
* Generate URL for optimizing db branch
563
567
*/
564
-
568
+ //encodeURI() will not encode: ~!@#$&*()=:/,;?+'
565
569
ConnectionConfig . prototype . optimizeBranchUrl = function ( branchId ) {
566
570
//let o = this.optimizeBase()
567
571
const dbBase = this . dbBase ( 'optimize' )
@@ -628,9 +632,10 @@ ConnectionConfig.prototype.branchBase = function(action) {
628
632
* (unless dbid = system dbname in which case there is no organization)
629
633
* @returns {string|boolean }
630
634
*/
635
+ //encodeURIComponent
631
636
ConnectionConfig . prototype . dbURLFragment = function ( ) {
632
637
if ( this . db ( ) === this . system_db ) return this . db ( )
633
- return encodeURIComponent ( this . organization ( ) ) + '/' + encodeURIComponent ( this . db ( ) )
638
+ return encodeURISegment ( this . organization ( ) ) + '/' + encodeURISegment ( this . db ( ) )
634
639
}
635
640
636
641
/**
@@ -650,12 +655,13 @@ ConnectionConfig.prototype.documentURL = function(params){
650
655
ConnectionConfig . prototype . queryParameter = function ( params ) {
651
656
if ( ! params || typeof params !== 'object' ) return ''
652
657
let queryString = Object . keys ( params ) . map ( ( key ) => {
653
- return key + '=' + encodeURIComponent ( params [ key ] )
658
+ return key + '=' + encodeURISegment ( params [ key ] )
654
659
} ) . join ( '&' ) ;
655
660
656
661
return `?${ queryString } ` ;
657
662
}
658
663
664
+
659
665
ConnectionConfig . prototype . jsonSchemaURL = function ( params ) {
660
666
const paramsStr = this . queryParameter ( params )
661
667
return this . branchBase ( 'schema' ) + paramsStr
0 commit comments