odsl-javascript-sdk 1.0.6 → 1.1.1

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "odsl-javascript-sdk",
3
3
  "type": "commonjs",
4
- "version": "1.0.6",
4
+ "version": "1.1.1",
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
@@ -2,6 +2,7 @@
2
2
  const { ConfidentialClientApplication } = require("@azure/msal-node");
3
3
  const { PublicClientApplication } = require("@azure/msal-browser");
4
4
  const { XMLHttpRequest } = require("xmlhttprequest");
5
+ const PROCESS = require("./process.js");
5
6
 
6
7
  const msalConfig = {
7
8
  "auth": {
@@ -19,7 +20,7 @@ module.exports = class ODSL_SDK {
19
20
  }
20
21
  static async login() {
21
22
  try {
22
- let msalInstance = new pcbrowser(msalConfig);
23
+ let msalInstance = new PublicClientApplication(msalConfig);
23
24
  console.log("Initialising");
24
25
  await msalInstance.initialize();
25
26
  console.log("Logging In");
@@ -45,6 +46,9 @@ module.exports = class ODSL_SDK {
45
46
  static loginWithToken(token) {
46
47
  return new ODSL_SDK({accessToken:token});
47
48
  }
49
+ static process(p, t) {
50
+ return new PROCESS(p, t);
51
+ }
48
52
  get(service, source, id) {
49
53
  try {
50
54
  var xhttp = new XMLHttpRequest();
package/src/process.js CHANGED
@@ -1,4 +1,4 @@
1
- const { ServiceBusClient, ServiceBusMessage } = require("@azure/service-bus");
1
+ const { ServiceBusClient } = require("@azure/service-bus");
2
2
 
3
3
  module.exports = class PROCESS {
4
4
  constructor(p, task) {
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
- }