Skip to content

Commit c5d3f6e

Browse files
committed
to be fix test
2 parents 818cc3f + 5c2ef87 commit c5d3f6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+15273
-2612
lines changed

dist/terminus-client.min.js

Lines changed: 83 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
'use strict';
21
module.exports = {
32
WOQLClient:require('./lib/woqlClient'),
4-
ConnectionCapabilities:require('./lib/connectionCapabilities'),
5-
ConnectionConfig:require('./lib/connectionConfig'),
6-
IDParser:require('./lib/terminusIDParser'),
7-
ErrorMessage:require('./lib/errorMessage'),
8-
FrameHelper:require('./lib/frameHelper'),
9-
ObjectFrame:require('./lib/objectFrame'),
10-
WOQLResult:require('./lib/woqlResult'),
11-
WOQL:require('./lib/woql')};
3+
ConnectionCapabilities:require('./lib/connectionCapabilities'),
4+
ConnectionConfig:require('./lib/connectionConfig'),
5+
IDParser:require('./lib/terminusIDParser'),
6+
ErrorMessage:require('./lib/errorMessage'),
7+
UTILS:require('./lib/utils'),
8+
WOQLResult:require('./lib/woqlResult'),
9+
WOQLRule:require('./lib/woqlRule'),
10+
FrameRule:require('./lib/frameRule'),
11+
View:require('./lib/woqlView'),
12+
DocumentFrame:require('./lib/viewer/documentFrame'),
13+
WOQLGraph:require('./lib/viewer/woqlGraph'),
14+
WOQLTable:require('./lib/viewer/woqlTable'),
15+
WOQLChooser:require('./lib/viewer/woqlChooser'),
16+
WOQLChart:require('./lib/viewer/woqlChart'),
17+
WOQLStream:require('./lib/viewer/woqlStream'),
18+
WOQL:require('./lib/woql')};

lib/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

lib/connectionCapabilities.js

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
const UTILS = require('./utils.js');
2-
const CONST = require('./const.js');
3-
const ErrorMessage = require('./errorMessage');
4-
/*
1+
/**
2+
* @file Connection Capabilities
3+
* @license Apache Version 2
4+
* @summary Object which helps manage the capabilities available for a given TerminusDB connection
55
* Creates an entry in the connection registry for the server
66
* and all the databases that the client has access to
77
* maps the input authorties to a per-db array for internal storage and easy
88
* access control checks
9-
* {doc:dbid => {terminus:authority =>
10-
* [terminus:woql_select, terminus:create_document, auth3, ...]}}
11-
*
129
*/
10+
const CONST = require('./const.js');
11+
const ErrorMessage = require('./errorMessage');
1312

13+
/**
14+
* @constructor
15+
* @param {connectionConfig} connectionConfig connectionConfig object containing the connection parameters
16+
* @param {String} key API key
17+
*/
1418
function ConnectionCapabilities(connectionConfig, key) {
1519
this.connection = {};
1620
this.connectionConfig = connectionConfig;
@@ -19,6 +23,10 @@ function ConnectionCapabilities(connectionConfig, key) {
1923
}
2024
}
2125

26+
/**
27+
* @summary Retrieves the API key for the given TerminusDB Server
28+
* @param {String} serverURL optional - URL of TerminusDB - if ommited the current server URL is used
29+
*/
2230
ConnectionCapabilities.prototype.getClientKey = function (serverURL) {
2331
if (!serverURL) serverURL = this.connectionConfig.serverURL();
2432
if (serverURL && this.connection[serverURL]) return this.connection[serverURL].key;
@@ -29,6 +37,12 @@ ConnectionCapabilities.prototype.getClientKey = function (serverURL) {
2937
/*
3038
* Utility functions for changing the state of connections with Terminus servers
3139
*/
40+
41+
/**
42+
* @summary sets the api key for the given url
43+
* @param {String} curl a valid terminusDB server URL
44+
* @param {String} key an optional API key
45+
*/
3246
ConnectionCapabilities.prototype.setClientKey = function (curl, key) {
3347
if (typeof key === 'string' && key.trim()) {
3448
if (typeof this.connection[curl] === 'undefined') {
@@ -40,8 +54,8 @@ ConnectionCapabilities.prototype.setClientKey = function (curl, key) {
4054

4155

4256
/**
43-
* @params {string} curl a valid terminusDB server URL
44-
* @params {object} capabilities it is the connect call response
57+
* @param {string} curl a valid terminusDB server URL
58+
* @param {object} capabilities the JSON object returned by the connect API call
4559
*/
4660
ConnectionCapabilities.prototype.addConnection = function (curl, capabilities) {
4761
if (typeof this.connection[curl] === 'undefined') {
@@ -59,9 +73,8 @@ ConnectionCapabilities.prototype.addConnection = function (curl, capabilities) {
5973
let scope = auths[i]['terminus:authority_scope'];
6074
const actions = auths[i]['terminus:action'];
6175

62-
if (Array.isArray(scope) === false) scope = [scope];
63-
const actionsArr = UTILS.authorityActionsToArr(actions);
64-
76+
if (Array.isArray(scope) === false) scope = [scope];
77+
const actionsArr = ((Array.isArray(actions)) ? actions.map(item => item['@id']) : [] );
6578
for (let j = 0; j < scope.length; j += 1) {
6679
const nrec = scope[j];
6780
if (typeof this.connection[curl][nrec['@id']] === 'undefined') {
@@ -76,34 +89,20 @@ ConnectionCapabilities.prototype.addConnection = function (curl, capabilities) {
7689
}
7790
};
7891

92+
/**
93+
* @summary returns true if the client is currently connected to a server
94+
* @returns {Boolean}
95+
*/
7996
ConnectionCapabilities.prototype.serverConnected = function () {
8097
return typeof this.connection[this.connectionConfig.server] !== 'undefined';
8198
};
8299

83-
ConnectionCapabilities.prototype.capabilitiesPermit = function (action, dbid, server) {
84-
if (!this.connectionConfig.connectionMode()
85-
|| this.connectionConfig.client_checks_capabilities !== true
86-
|| action === CONST.CONNECT) { return true; }
87-
88-
server = server || this.connectionConfig.server;
89-
dbid = dbid || this.connectionConfig.dbid;
90-
91-
let rec;
92-
93-
if (action === CONST.CREATE_DATABASE) {
94-
rec = this.getServerRecord(server);
95-
} else if (dbid) rec = this.getDBRecord(dbid);
96-
else console.log('no dbid', server, dbid);
97-
if (rec) {
98-
const auths = rec['terminus:authority'];
99-
if (auths && auths.indexOf(`terminus:${action}`) !== -1) return true;
100-
} else {
101-
console.log('problem with ', this.connection, action, server, dbid);
102-
}
103-
this.error = ErrorMessage.accessDenied(action, dbid, server);
104-
return false;
105-
};
106100

101+
/**
102+
* @summary retrieves the meta-data record returned by connect for a particular server
103+
* @param {String} [srvr] optional server URL - if omitted current connection config will be used
104+
* @returns {terminus:Server} JSON server record as returned by WOQLClient.connect
105+
*/
107106
ConnectionCapabilities.prototype.getServerRecord = function (srvr) {
108107
const url = (srvr || this.connectionConfig.server);
109108
const connectionObj = this.connection[url] || {};
@@ -117,6 +116,12 @@ ConnectionCapabilities.prototype.getServerRecord = function (srvr) {
117116
return false;
118117
};
119118

119+
/**
120+
* @summary retrieves the meta-data record returned by connect for a particular database
121+
* @param {String} [dbid] optional database id - if omitted current connection config db will be used
122+
* @param {String} [srvr] optional server URL - if omitted current connection config server will be used
123+
* @returns {terminus:Database} terminus:Database JSON document as returned by WOQLClient.connect
124+
*/
120125
ConnectionCapabilities.prototype.getDBRecord = function (dbid, srvr) {
121126
const url = (srvr || this.connectionConfig.server);
122127
dbid = (dbid || this.connectionConfig.dbid);
@@ -132,6 +137,11 @@ ConnectionCapabilities.prototype.getDBRecord = function (dbid, srvr) {
132137
return undefined;
133138
};
134139

140+
/**
141+
* @summary retrieves all the db meta-data records returned by connect for a particular server
142+
* @param {String} [srvr] optional server URL - if omitted current connection config server will be used
143+
* @returns {[terminus:Database]} array of terminus:Database JSON documents as returned by WOQLClient.connect
144+
*/
135145
ConnectionCapabilities.prototype.getServerDBRecords = function (srvr) {
136146
const url = (srvr || this.connectionConfig.server);
137147
const dbrecs = {};
@@ -145,8 +155,11 @@ ConnectionCapabilities.prototype.getServerDBRecords = function (srvr) {
145155
return dbrecs;
146156
};
147157

148-
/*
149-
* removes a database record from the connection registry (after deletion, for example)
158+
/**
159+
* @summary removes a database record from the connection registry (after deletion, for example)
160+
* @param {String} [dbid] optional DB ID - if omitted current connection config db will be used
161+
* @param {String} [srvr] optional server URL - if omitted current connection config server will be used
162+
* @returns {[terminus:Database]} array of terminus:Database JSON documents as returned by WOQLClient.connect
150163
*/
151164
ConnectionCapabilities.prototype.removeDB = function (dbid, srvr) {
152165
dbid = dbid || this.connectionConfig.dbid;
@@ -162,24 +175,41 @@ ConnectionCapabilities.prototype.removeDB = function (dbid, srvr) {
162175
}
163176
};
164177

165-
178+
/**
179+
* @param {String} dbid local id of database
180+
* @returns {String} the id of the terminus:Document describing the DB
181+
* @summary Generates the ID of the terminus:Database document from the database ID
182+
*/
166183
ConnectionCapabilities.prototype.dbCapabilityID = function (dbid) {
167184
return `doc:${dbid}`;
168185
};
169186

170-
ConnectionCapabilities.prototype.getDBRecord = function (dbid, srvr) {
171-
const url = srvr || this.connectionConfig.server;
187+
/**
188+
* @param {String} action - the action that will be carried out
189+
* @param {String} [dbid] optional DB ID - if omitted current connection config db will be used
190+
* @param {String} [srvr] optional server URL - if omitted current connection config server will be used
191+
* @returns {Boolean} true if the client's capabilities allow the action on the given server / db
192+
* @summary supports client side access control checks (in addition to server side)
193+
*/
194+
ConnectionCapabilities.prototype.capabilitiesPermit = function (action, dbid, server) {
195+
server = server || this.connectionConfig.server;
172196
dbid = dbid || this.connectionConfig.dbid;
173-
if (typeof this.connection[url] !== 'object') {
174-
return false;
175-
}
176-
if (typeof this.connection[url][dbid] !== 'undefined') { return this.connection[url][dbid]; }
177-
178-
dbid = this.dbCapabilityID(dbid);
179197

180-
if (typeof this.connection[url][dbid] !== 'undefined') { return this.connection[url][dbid]; }
198+
let rec;
181199

182-
return undefined;
200+
if (action === CONST.CREATE_DATABASE) {
201+
rec = this.getServerRecord(server);
202+
} else if (dbid) rec = this.getDBRecord(dbid);
203+
else console.log('no dbid provided in capabilities check ', server, dbid);
204+
if (rec) {
205+
const auths = rec['terminus:authority'];
206+
if (auths && auths.indexOf(`terminus:${action}`) !== -1) return true;
207+
} else {
208+
console.log('No record found for connection: ', this.connection, action, server, dbid);
209+
}
210+
this.error = ErrorMessage.accessDenied(action, dbid, server);
211+
return false;
183212
};
184213

214+
185215
module.exports = ConnectionCapabilities;

0 commit comments

Comments
 (0)