@lblod/mu-auth-sudo 1.0.0-beta.5 → 1.0.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/dist/auth-sudo.d.ts +1 -1
- package/dist/auth-sudo.js +13 -32
- package/package.json +4 -5
package/dist/auth-sudo.d.ts
CHANGED
package/dist/auth-sudo.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
@@ -29,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
6
|
exports.updateSudo = exports.querySudo = exports.HTTPResponseError = void 0;
|
|
30
7
|
const express_http_context_1 = __importDefault(require("express-http-context"));
|
|
31
8
|
const env_var_1 = __importDefault(require("env-var"));
|
|
32
|
-
const node_fetch_1 = __importStar(require("node-fetch"));
|
|
33
9
|
const digest_fetch_1 = __importDefault(require("digest-fetch"));
|
|
34
10
|
const SPARQL_ENDPOINT = env_var_1.default.get('MU_SPARQL_ENDPOINT').required().asString();
|
|
35
11
|
const LOG_SPARQL_ALL = env_var_1.default.get('LOG_SPARQL_ALL').required().asString();
|
|
@@ -43,6 +19,8 @@ const RETRY_FOR_HTTP_STATUS_CODES = env_var_1.default.get('SUDO_QUERY_RETRY_FOR_
|
|
|
43
19
|
const RETRY_FOR_CONNECTION_ERRORS = env_var_1.default.get('SUDO_QUERY_RETRY_FOR_CONNECTION_ERRORS').default('ECONNRESET,ETIMEDOUT,EAI_AGAIN').asArray();
|
|
44
20
|
const RETRY_TIMEOUT_INCREMENT_FACTOR = env_var_1.default.get('SUDO_QUERY_RETRY_TIMEOUT_INCREMENT_FACTOR').default('0.3').asFloat();
|
|
45
21
|
class HTTPResponseError extends Error {
|
|
22
|
+
httpStatus;
|
|
23
|
+
httpStatusText;
|
|
46
24
|
constructor(response) {
|
|
47
25
|
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
48
26
|
this.httpStatus = response.status;
|
|
@@ -51,7 +29,7 @@ class HTTPResponseError extends Error {
|
|
|
51
29
|
}
|
|
52
30
|
exports.HTTPResponseError = HTTPResponseError;
|
|
53
31
|
function defaultHeaders() {
|
|
54
|
-
const headers = new
|
|
32
|
+
const headers = new Headers();
|
|
55
33
|
headers.set('content-type', 'application/x-www-form-urlencoded');
|
|
56
34
|
headers.set('mu-auth-sudo', 'true');
|
|
57
35
|
headers.set('Accept', 'application/sparql-results+json');
|
|
@@ -82,6 +60,9 @@ async function executeRawQuery(queryString, extraHeaders = {}, connectionOptions
|
|
|
82
60
|
let response;
|
|
83
61
|
if (connectionOptions.authUser && connectionOptions.authPassword) {
|
|
84
62
|
const client = new digest_fetch_1.default(connectionOptions.authUser, connectionOptions.authPassword, { basic: connectionOptions.authType === 'basic' });
|
|
63
|
+
// the cast fixes a weird inconsistency between digest-fetch's declared return type
|
|
64
|
+
// it declares it either returns the browser's version of Response or node-fetch's, and
|
|
65
|
+
// I think those are slightly different from the real Response type in node
|
|
85
66
|
response = await client.fetch(sparqlEndpoint, {
|
|
86
67
|
method: 'POST',
|
|
87
68
|
body: formData.toString(),
|
|
@@ -89,7 +70,7 @@ async function executeRawQuery(queryString, extraHeaders = {}, connectionOptions
|
|
|
89
70
|
});
|
|
90
71
|
}
|
|
91
72
|
else {
|
|
92
|
-
response = await (
|
|
73
|
+
response = await fetch(sparqlEndpoint, {
|
|
93
74
|
method: 'POST',
|
|
94
75
|
body: formData.toString(),
|
|
95
76
|
headers
|
|
@@ -141,20 +122,20 @@ function updateSudo(queryString, extraHeaders = {}, connectionOptions = {}) {
|
|
|
141
122
|
exports.updateSudo = updateSudo;
|
|
142
123
|
function mayRetry(error, attempt, connectionOptions = {}) {
|
|
143
124
|
console.log(`Checking retry allowed for error: ${error} and attempt: ${attempt}`);
|
|
144
|
-
let
|
|
125
|
+
let shouldRetry = false;
|
|
145
126
|
if (!(RETRY || connectionOptions.mayRetry)) {
|
|
146
|
-
|
|
127
|
+
shouldRetry = false;
|
|
147
128
|
}
|
|
148
129
|
else if (attempt < RETRY_MAX_ATTEMPTS) {
|
|
149
130
|
if (error.code && RETRY_FOR_CONNECTION_ERRORS.includes(error.code)) {
|
|
150
|
-
|
|
131
|
+
shouldRetry = true;
|
|
151
132
|
}
|
|
152
133
|
else if (error.httpStatus && RETRY_FOR_HTTP_STATUS_CODES.includes(`${error.httpStatus}`)) {
|
|
153
|
-
|
|
134
|
+
shouldRetry = true;
|
|
154
135
|
}
|
|
155
136
|
}
|
|
156
|
-
console.log(`Retry allowed? ${
|
|
157
|
-
return
|
|
137
|
+
console.log(`Retry allowed? ${shouldRetry}`);
|
|
138
|
+
return shouldRetry;
|
|
158
139
|
}
|
|
159
140
|
function nextAttemptTimeout(attempt) {
|
|
160
141
|
// expected to be milliseconds
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lblod/mu-auth-sudo",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.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
|
"types": "dist/auth-sudo.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/lblod/mu-auth-sudo#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node
|
|
30
|
+
"@types/node": "^25.0.9",
|
|
31
31
|
"express-http-context": "^1.2.4",
|
|
32
32
|
"prettier": "^2.7.1",
|
|
33
33
|
"release-it": "^15.5.0",
|
|
@@ -36,9 +36,8 @@
|
|
|
36
36
|
"typescript": "^4.8.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"digest-fetch": "^1.
|
|
40
|
-
"env-var": "^7.0.1"
|
|
41
|
-
"node-fetch": "^2.6.7"
|
|
39
|
+
"digest-fetch": "^3.1.1",
|
|
40
|
+
"env-var": "^7.0.1"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
44
43
|
"express-http-context": "~1.2.4"
|