odsl-javascript-sdk 1.0.1 → 1.0.2
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 +11 -12
- package/package.json +3 -3
- package/src/sdk.js +45 -24
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The Javascript SDK for the [OpenDataDSL](https://opendatadsl.com) data managemen
|
|
|
4
4
|
## Installation
|
|
5
5
|
You can install the ODSL Javascript SDK from [npm](https://www.npmjs.com/package/odsl-javascript-sdk):
|
|
6
6
|
|
|
7
|
-
npm i odsl-
|
|
7
|
+
npm i odsl-javascript-sdk
|
|
8
8
|
|
|
9
9
|
## About
|
|
10
10
|
This javascript SDK for OpenDataDSL has the following features:
|
|
@@ -40,36 +40,35 @@ ODSL.loginWithSecret(config).then(function(odsl) {
|
|
|
40
40
|
### Finding master data
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
|
-
objects = ODSL.list('object', 'public',
|
|
44
|
-
|
|
45
|
-
print(objects.body[0])
|
|
43
|
+
objects = ODSL.list('object', 'public', {"source":"ECB"})
|
|
44
|
+
print(objects[0])
|
|
46
45
|
```
|
|
47
46
|
|
|
48
47
|
### Getting master data
|
|
49
48
|
|
|
50
49
|
```js
|
|
51
50
|
obj = ODSL.get('object', 'public', '#ECB')
|
|
52
|
-
print(obj
|
|
51
|
+
print(obj['description'])
|
|
53
52
|
```
|
|
54
53
|
|
|
55
54
|
### Getting a timeseries
|
|
56
55
|
```js
|
|
57
56
|
ts = ODSL.get('data', 'public', '#ABN_FX.EURUSD:SPOT')
|
|
58
|
-
print(ts
|
|
57
|
+
print(ts)
|
|
59
58
|
```
|
|
60
59
|
|
|
61
60
|
### Updating some private master data
|
|
62
61
|
```js
|
|
63
|
-
var = {
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
var body = {
|
|
63
|
+
"_id":"AAA.JS",
|
|
64
|
+
"name": "Javascript Update Object"
|
|
66
65
|
}
|
|
67
|
-
ODSL.update('object', 'private',
|
|
66
|
+
ODSL.update('object', 'private', body)
|
|
68
67
|
```
|
|
69
68
|
|
|
70
69
|
### Reading and updating some private master data
|
|
71
70
|
```js
|
|
72
71
|
po = ODSL.get('object', 'private', 'AAA.TEST')
|
|
73
|
-
po
|
|
74
|
-
ODSL.update('object', 'private', po
|
|
72
|
+
po['description'] = 'Updated from Javascript'
|
|
73
|
+
ODSL.update('object', 'private', po)
|
|
75
74
|
```
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odsl-javascript-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Javascript SDK for OpenDataDSL",
|
|
6
6
|
"main": "src/sdk.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha test/test.js",
|
|
9
|
+
"testUpdate": "mocha test/testUpdate.js",
|
|
9
10
|
"npm:publish": "npm publish"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
@@ -25,12 +26,11 @@
|
|
|
25
26
|
},
|
|
26
27
|
"homepage": "https://github.com/OpenDataDSL/odsl-javascript-sdk#readme",
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@azure/msal-browser": "^3.11.1",
|
|
29
29
|
"@azure/msal-node": "^2.6.6",
|
|
30
|
-
"mocha": "^10.4.0",
|
|
31
30
|
"xmlhttprequest": "^1.8.0"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
33
|
+
"mocha": "^10.4.0",
|
|
34
34
|
"dotenv": "^16.4.5"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/sdk.js
CHANGED
|
@@ -45,23 +45,16 @@ export default class ODSL {
|
|
|
45
45
|
get(service, source, id) {
|
|
46
46
|
try {
|
|
47
47
|
var xhttp = new XMLHttpRequest();
|
|
48
|
-
|
|
48
|
+
id = encodeURIComponent(id);
|
|
49
|
+
var url = new URL(this.host + service + "/v1/" + source + "/" + id);
|
|
49
50
|
xhttp.open("GET", url, false);
|
|
50
51
|
xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
|
|
51
52
|
xhttp.responseType = "json";
|
|
52
53
|
xhttp.send();
|
|
53
|
-
if (xhttp.status
|
|
54
|
-
|
|
55
|
-
status: xhttp.status,
|
|
56
|
-
statusText: xhttp.getResponseHeader("x-odsl-error"),
|
|
57
|
-
body: undefined
|
|
58
|
-
};
|
|
54
|
+
if (xhttp.status < 200 || xhttp.status >= 300) {
|
|
55
|
+
throw xhttp.getResponseHeader("x-odsl-error");
|
|
59
56
|
}
|
|
60
|
-
return
|
|
61
|
-
status: xhttp.status,
|
|
62
|
-
statusText: xhttp.statusText,
|
|
63
|
-
body: JSON.parse(xhttp.responseText)
|
|
64
|
-
};
|
|
57
|
+
return JSON.parse(xhttp.responseText);
|
|
65
58
|
} catch (err) {
|
|
66
59
|
console.log("GET request Failed: " + err);
|
|
67
60
|
}
|
|
@@ -69,28 +62,56 @@ export default class ODSL {
|
|
|
69
62
|
getAsync(service, source, id, callback) {
|
|
70
63
|
try {
|
|
71
64
|
var xhttp = new XMLHttpRequest();
|
|
72
|
-
|
|
65
|
+
id = encodeURIComponent(id);
|
|
66
|
+
var url = new URL(this.host + service + "/v1/" + source + "/" + id);
|
|
73
67
|
xhttp.open("GET", url);
|
|
74
68
|
xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
|
|
75
69
|
xhttp.responseType = "json";
|
|
76
70
|
xhttp.send();
|
|
77
71
|
xhttp.onload = function() {
|
|
78
|
-
if (xhttp.status
|
|
79
|
-
|
|
80
|
-
status: xhttp.status,
|
|
81
|
-
statusText: xhttp.getResponseHeader("x-odsl-error"),
|
|
82
|
-
body: undefined
|
|
83
|
-
});
|
|
72
|
+
if (xhttp.status < 200 || xhttp.status >= 300) {
|
|
73
|
+
throw xhttp.getResponseHeader("x-odsl-error");
|
|
84
74
|
} else {
|
|
85
|
-
callback(
|
|
86
|
-
status: xhttp.status,
|
|
87
|
-
statusText: xhttp.statusText,
|
|
88
|
-
body: JSON.parse(xhttp.responseText)
|
|
89
|
-
});
|
|
75
|
+
callback(JSON.parse(xhttp.responseText));
|
|
90
76
|
}
|
|
91
77
|
}
|
|
92
78
|
} catch (err) {
|
|
93
79
|
console.log("GET request Failed: " + err);
|
|
94
80
|
}
|
|
95
81
|
}
|
|
82
|
+
list(service, source, filter) {
|
|
83
|
+
try {
|
|
84
|
+
var xhttp = new XMLHttpRequest();
|
|
85
|
+
var url = new URL(this.host + service + "/v1/" + source);
|
|
86
|
+
if (filter != undefined) {
|
|
87
|
+
url.searchParams.set("_filter", JSON.stringify(filter));
|
|
88
|
+
}
|
|
89
|
+
xhttp.open("GET", url, false);
|
|
90
|
+
xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
|
|
91
|
+
xhttp.responseType = "json";
|
|
92
|
+
xhttp.send();
|
|
93
|
+
if (xhttp.status < 200 || xhttp.status >= 300) {
|
|
94
|
+
throw xhttp.getResponseHeader("x-odsl-error");
|
|
95
|
+
}
|
|
96
|
+
return JSON.parse(xhttp.responseText);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.log("GET request Failed: " + err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
update(service, source, body) {
|
|
102
|
+
try {
|
|
103
|
+
var xhttp = new XMLHttpRequest();
|
|
104
|
+
var url = new URL(this.host + service + "/v1/" + source);
|
|
105
|
+
xhttp.open("POST", url, false);
|
|
106
|
+
xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
|
|
107
|
+
xhttp.responseType = "json";
|
|
108
|
+
xhttp.send(JSON.stringify(body));
|
|
109
|
+
if (xhttp.status < 200 || xhttp.status >= 300) {
|
|
110
|
+
throw xhttp.getResponseHeader("x-odsl-error");
|
|
111
|
+
}
|
|
112
|
+
return JSON.parse(xhttp.responseText);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
console.log("GET request Failed: " + err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
96
117
|
}
|