odsl-javascript-sdk 1.0.5 → 1.1.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.
Files changed (3) hide show
  1. package/package.json +2 -2
  2. package/src/odsl.js +5 -5
  3. package/src/sdk.js +0 -120
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "odsl-javascript-sdk",
3
3
  "type": "commonjs",
4
- "version": "1.0.5",
4
+ "version": "1.1.0",
5
5
  "description": "Javascript SDK for OpenDataDSL",
6
- "main": "src/sdk.js",
6
+ "main": "src/odsl.js",
7
7
  "scripts": {
8
8
  "test": "mocha test/test.js",
9
9
  "testUpdate": "mocha test/testUpdate.js",
package/src/odsl.js CHANGED
@@ -10,7 +10,7 @@ const msalConfig = {
10
10
  }
11
11
  };
12
12
 
13
- module.exports = class ODSL {
13
+ module.exports = class ODSL_SDK {
14
14
  token = null;
15
15
  // host = "https://odsl-dev.azurewebsites.net/api/";
16
16
  host = "http://localhost:7071/api/";
@@ -19,12 +19,12 @@ module.exports = class ODSL {
19
19
  }
20
20
  static async login() {
21
21
  try {
22
- let msalInstance = new pcbrowser(msalConfig);
22
+ let msalInstance = new PublicClientApplication(msalConfig);
23
23
  console.log("Initialising");
24
24
  await msalInstance.initialize();
25
25
  console.log("Logging In");
26
26
  const loginResponse = await msalInstance.loginPopup(loginRequest);
27
- return new ODSL(loginResponse);
27
+ return new ODSL_SDK(loginResponse);
28
28
  } catch (err) {
29
29
  console.log("Token Acquisition Failed: " + err);
30
30
  }
@@ -37,13 +37,13 @@ module.exports = class ODSL {
37
37
  let msalInstance = new ConfidentialClientApplication(config);
38
38
  console.log("Logging In");
39
39
  const loginResponse = await msalInstance.acquireTokenByClientCredential(loginRequest);
40
- return new ODSL(loginResponse);
40
+ return new ODSL_SDK(loginResponse);
41
41
  } catch (err) {
42
42
  console.log("Token Acquisition Failed: " + err);
43
43
  }
44
44
  }
45
45
  static loginWithToken(token) {
46
- return new ODSL({accessToken:token});
46
+ return new ODSL_SDK({accessToken:token});
47
47
  }
48
48
  get(service, source, id) {
49
49
  try {
package/src/sdk.js DELETED
@@ -1,120 +0,0 @@
1
- 'use strict';
2
- import { PublicClientApplication as pcnode, ConfidentialClientApplication as ccnode } from "@azure/msal-node";
3
- import { PublicClientApplication as pcbrowser } from "@azure/msal-browser";
4
- import { XMLHttpRequest } from "xmlhttprequest";
5
-
6
- const msalConfig = {
7
- "auth": {
8
- "clientId": "d3742f5f-3d4d-4565-a80a-ebdefaab8d08",
9
- "authority": "https://login.microsoft.com/common"
10
- }
11
- };
12
-
13
- export default class ODSL {
14
- token = null;
15
- // host = "https://odsl-dev.azurewebsites.net/api/";
16
- host = "http://localhost:7071/api/";
17
- constructor(loginResponse) {
18
- this.token = loginResponse.accessToken;
19
- }
20
- static async login() {
21
- try {
22
- let msalInstance = new pcbrowser(msalConfig);
23
- console.log("Initialising");
24
- await msalInstance.initialize();
25
- console.log("Logging In");
26
- const loginResponse = await msalInstance.loginPopup(loginRequest);
27
- return new ODSL(loginResponse);
28
- } catch (err) {
29
- console.log("Token Acquisition Failed: " + err);
30
- }
31
- }
32
- static async loginWithSecret(config) {
33
- try {
34
- let loginRequest = {
35
- scopes: ["api://opendatadsl/.default"]
36
- }
37
- let msalInstance = new ccnode(config);
38
- console.log("Logging In");
39
- const loginResponse = await msalInstance.acquireTokenByClientCredential(loginRequest);
40
- return new ODSL(loginResponse);
41
- } catch (err) {
42
- console.log("Token Acquisition Failed: " + err);
43
- }
44
- }
45
- static loginWithToken(token) {
46
- return new ODSL({accessToken:token});
47
- }
48
- get(service, source, id) {
49
- try {
50
- var xhttp = new XMLHttpRequest();
51
- id = encodeURIComponent(id);
52
- var url = new URL(this.host + service + "/v1/" + source + "/" + id);
53
- xhttp.open("GET", url, false);
54
- xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
55
- xhttp.responseType = "json";
56
- xhttp.send();
57
- if (xhttp.status < 200 || xhttp.status >= 300) {
58
- throw xhttp.getResponseHeader("x-odsl-error");
59
- }
60
- return JSON.parse(xhttp.responseText);
61
- } catch (err) {
62
- console.log("GET request Failed: " + err);
63
- }
64
- }
65
- getAsync(service, source, id, callback) {
66
- try {
67
- var xhttp = new XMLHttpRequest();
68
- id = encodeURIComponent(id);
69
- var url = new URL(this.host + service + "/v1/" + source + "/" + id);
70
- xhttp.open("GET", url);
71
- xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
72
- xhttp.responseType = "json";
73
- xhttp.send();
74
- xhttp.onload = function() {
75
- if (xhttp.status < 200 || xhttp.status >= 300) {
76
- throw xhttp.getResponseHeader("x-odsl-error");
77
- } else {
78
- callback(JSON.parse(xhttp.responseText));
79
- }
80
- }
81
- } catch (err) {
82
- console.log("GET request Failed: " + err);
83
- }
84
- }
85
- list(service, source, filter) {
86
- try {
87
- var xhttp = new XMLHttpRequest();
88
- var url = new URL(this.host + service + "/v1/" + source);
89
- if (filter != undefined) {
90
- url.searchParams.set("_filter", JSON.stringify(filter));
91
- }
92
- xhttp.open("GET", url, false);
93
- xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
94
- xhttp.responseType = "json";
95
- xhttp.send();
96
- if (xhttp.status < 200 || xhttp.status >= 300) {
97
- throw xhttp.getResponseHeader("x-odsl-error");
98
- }
99
- return JSON.parse(xhttp.responseText);
100
- } catch (err) {
101
- console.log("GET request Failed: " + err);
102
- }
103
- }
104
- update(service, source, body) {
105
- try {
106
- var xhttp = new XMLHttpRequest();
107
- var url = new URL(this.host + service + "/v1/" + source);
108
- xhttp.open("POST", url, false);
109
- xhttp.setRequestHeader("Authorization", "Bearer " + this.token);
110
- xhttp.responseType = "json";
111
- xhttp.send(JSON.stringify(body));
112
- if (xhttp.status < 200 || xhttp.status >= 300) {
113
- throw xhttp.getResponseHeader("x-odsl-error");
114
- }
115
- return JSON.parse(xhttp.responseText);
116
- } catch (err) {
117
- console.log("GET request Failed: " + err);
118
- }
119
- }
120
- }