@lblod/mu-auth-sudo 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/auth-sudo.js +16 -18
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,6 +9,24 @@ npm install @lblod/mu-auth-sudo
|
|
|
9
9
|
Include the following in your code
|
|
10
10
|
```
|
|
11
11
|
import { querySudo as query, updateSudo as update } from '@lblod/mu-auth-sudo';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
//Examples
|
|
15
|
+
|
|
16
|
+
// To run a normal query
|
|
17
|
+
|
|
18
|
+
const queryString = `SELECT * FROM { GRAPH ?g { ?s ?p ?o. } } LIMIT 1`;
|
|
19
|
+
await query(queryString);
|
|
20
|
+
|
|
21
|
+
// To pass extra headers
|
|
22
|
+
|
|
23
|
+
const updateString = `INSERT DATA { GRAPH <http://foo> { <http://bar> <http://baz> <http://boom>. } }`;
|
|
24
|
+
const extraHeaders = { 'mu-call-scope-id': 'http://foo/bar', 'other-info'; 'hello' };
|
|
25
|
+
await update(updateString, extraHeaders);
|
|
26
|
+
|
|
27
|
+
// With custom sparqlEndpoint (this should be exceptional, make sure you know what you're doing)
|
|
28
|
+
|
|
29
|
+
await update(updateString, extraHeaders, 'http://the.sparql.endpoint/sparql');
|
|
12
30
|
```
|
|
13
31
|
|
|
14
32
|
## Logging
|
package/dist/auth-sudo.js
CHANGED
|
@@ -72,31 +72,23 @@ function sudoSparqlClient() {
|
|
|
72
72
|
return new _sparqlClient.SparqlClient(sparqlEndpoint, options);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function executeRawQuery(queryString) {
|
|
75
|
+
async function executeRawQuery(queryString) {
|
|
76
76
|
var extraHeaders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
77
77
|
var sparqlEndpoint = arguments[2];
|
|
78
78
|
|
|
79
|
-
return sudoSparqlClient(extraHeaders, sparqlEndpoint).query(queryString).executeRaw().then(function (response) {
|
|
80
|
-
function maybeParseJSON(body) {
|
|
81
|
-
// Catch invalid JSON
|
|
82
|
-
try {
|
|
83
|
-
return JSON.parse(body);
|
|
84
|
-
} catch (ex) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
79
|
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
if (LOG_SPARQL_QUERIES) {
|
|
81
|
+
console.log(queryString);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var response = await sudoSparqlClient(extraHeaders, sparqlEndpoint).query(queryString).executeRaw();
|
|
85
|
+
return maybeParseJSON(response.body);
|
|
91
86
|
}
|
|
92
87
|
|
|
93
88
|
function querySudo(queryString) {
|
|
94
89
|
var extraHeaders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
95
90
|
var sparqlEndpoint = arguments[2];
|
|
96
91
|
|
|
97
|
-
if (LOG_SPARQL_QUERIES) {
|
|
98
|
-
console.log(queryString);
|
|
99
|
-
}
|
|
100
92
|
return executeRawQuery(queryString, extraHeaders, sparqlEndpoint);
|
|
101
93
|
}
|
|
102
94
|
|
|
@@ -104,12 +96,18 @@ function updateSudo(queryString) {
|
|
|
104
96
|
var extraHeaders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
105
97
|
var sparqlEndpoint = arguments[2];
|
|
106
98
|
|
|
107
|
-
if (LOG_SPARQL_UPDATES) {
|
|
108
|
-
console.log(queryString);
|
|
109
|
-
}
|
|
110
99
|
return executeRawQuery(queryString, extraHeaders, sparqlEndpoint);
|
|
111
100
|
}
|
|
112
101
|
|
|
102
|
+
function maybeParseJSON(body) {
|
|
103
|
+
// Catch invalid JSON
|
|
104
|
+
try {
|
|
105
|
+
return JSON.parse(body);
|
|
106
|
+
} catch (ex) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
113
111
|
var _exports = {
|
|
114
112
|
querySudo: querySudo,
|
|
115
113
|
updateSudo: updateSudo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lblod/mu-auth-sudo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "this package provides an alternative sparql client for the mu-javascript-template that has sudo rights.",
|
|
5
5
|
"main": "dist/auth-sudo.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"homepage": "https://github.com/lblod/mu-auth-sudo#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"babel-cli": "^6.26.0",
|
|
36
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
36
37
|
"babel-preset-env": "^1.7.0",
|
|
37
|
-
"babel-plugin-add-module-exports": "^1.0.0",
|
|
38
38
|
"babel-preset-es2015": "^6.24.1",
|
|
39
39
|
"babel-register": "^6.26.0"
|
|
40
40
|
},
|