@itarius-ug/docuware-api-client
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -103,2 +103,8 @@ export interface Link { | ||
} | ||
export interface TokenResponse { | ||
access_token: string; | ||
expires_in: number; | ||
token_type: string; | ||
scope: string; | ||
} | ||
export interface QueryResponse extends HasLinks { | ||
@@ -105,0 +111,0 @@ Count: { |
@@ -5,3 +5,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
#private; | ||
constructor(configuration: DocuWareConfiguration); | ||
constructor(configuration: DocuWareConfiguration, userAgent?: string); | ||
getIdentityServiceUrl(): Promise<string>; | ||
@@ -8,0 +8,0 @@ getOpenIdConfiguration(): Promise<any>; |
@@ -21,9 +21,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
var _DocuWare_instances, _DocuWare_username, _DocuWare_password, _DocuWare_impersonateName, _DocuWare_baseUrl, _DocuWare_token, _DocuWare_send, _DocuWare_get, _DocuWare_post, _DocuWare_put; | ||
var _DocuWare_instances, _DocuWare_username, _DocuWare_password, _DocuWare_impersonateName, _DocuWare_baseUrl, _DocuWare_token, _DocuWare_expiration, _DocuWare_userAgent, _DocuWare_send, _DocuWare_get, _DocuWare_post, _DocuWare_put, _DocuWare_isExpired; | ||
import { readFile } from "fs/promises"; | ||
import got from "got"; | ||
import ky from "ky"; | ||
import { basename } from "path"; | ||
import { transformData } from "./utils.js"; | ||
export class DocuWare { | ||
constructor(configuration) { | ||
constructor(configuration, userAgent) { | ||
_DocuWare_instances.add(this); | ||
@@ -34,3 +34,5 @@ _DocuWare_username.set(this, void 0); | ||
_DocuWare_baseUrl.set(this, void 0); | ||
_DocuWare_token.set(this, void 0); | ||
_DocuWare_token.set(this, null); | ||
_DocuWare_expiration.set(this, null); | ||
_DocuWare_userAgent.set(this, "itarius/docuware-api-client"); | ||
__classPrivateFieldSet(this, _DocuWare_baseUrl, `${configuration.baseUrl}/DocuWare/Platform`, "f"); | ||
@@ -40,3 +42,5 @@ __classPrivateFieldSet(this, _DocuWare_username, configuration.username, "f"); | ||
__classPrivateFieldSet(this, _DocuWare_impersonateName, configuration.impersonateName, "f"); | ||
__classPrivateFieldSet(this, _DocuWare_token, null, "f"); | ||
if (userAgent) { | ||
__classPrivateFieldSet(this, _DocuWare_userAgent, `itarius/docuware-api-client - ${userAgent}`, "f"); | ||
} | ||
} | ||
@@ -62,15 +66,15 @@ getIdentityServiceUrl() { | ||
const configuration = yield this.getOpenIdConfiguration(); | ||
const options = { | ||
form: { | ||
grant_type: "trusted", | ||
scope: "docuware.platform", | ||
client_id: "docuware.platform.net.client", | ||
username: __classPrivateFieldGet(this, _DocuWare_username, "f"), | ||
password: __classPrivateFieldGet(this, _DocuWare_password, "f"), | ||
impersonateName: __classPrivateFieldGet(this, _DocuWare_impersonateName, "f"), | ||
}, | ||
}; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set("grant_type", "trusted"); | ||
searchParams.set("scope", "docuware.platform"); | ||
searchParams.set("client_id", "docuware.platform.net.client"); | ||
searchParams.set("username", __classPrivateFieldGet(this, _DocuWare_username, "f")); | ||
searchParams.set("password", __classPrivateFieldGet(this, _DocuWare_password, "f")); | ||
if (__classPrivateFieldGet(this, _DocuWare_impersonateName, "f")) { | ||
searchParams.set("impersonateName", __classPrivateFieldGet(this, _DocuWare_impersonateName, "f")); | ||
} | ||
try { | ||
const response = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.token_endpoint, options, false); | ||
const response = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.token_endpoint, { body: searchParams }, false); | ||
__classPrivateFieldSet(this, _DocuWare_token, response.access_token, "f"); | ||
__classPrivateFieldSet(this, _DocuWare_expiration, Math.floor(Date.now() / 1000) + response.expires_in, "f"); | ||
} | ||
@@ -85,11 +89,9 @@ catch (error) { | ||
const configuration = yield this.getOpenIdConfiguration(); | ||
const options = { | ||
form: { | ||
token: __classPrivateFieldGet(this, _DocuWare_token, "f"), | ||
token_type_hint: "access_token", | ||
}, | ||
}; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set("token", __classPrivateFieldGet(this, _DocuWare_token, "f")); | ||
searchParams.set("token_type_hint", "access_token"); | ||
try { | ||
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.revocation_endpoint, options); | ||
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.revocation_endpoint, { body: searchParams }); | ||
__classPrivateFieldSet(this, _DocuWare_token, null, "f"); | ||
__classPrivateFieldSet(this, _DocuWare_expiration, null, "f"); | ||
} | ||
@@ -211,4 +213,3 @@ catch (error) { | ||
} | ||
_DocuWare_username = new WeakMap(), _DocuWare_password = new WeakMap(), _DocuWare_impersonateName = new WeakMap(), _DocuWare_baseUrl = new WeakMap(), _DocuWare_token = new WeakMap(), _DocuWare_instances = new WeakSet(), _DocuWare_send = function _DocuWare_send(options, requireAuthentication = true) { | ||
var _a; | ||
_DocuWare_username = new WeakMap(), _DocuWare_password = new WeakMap(), _DocuWare_impersonateName = new WeakMap(), _DocuWare_baseUrl = new WeakMap(), _DocuWare_token = new WeakMap(), _DocuWare_expiration = new WeakMap(), _DocuWare_userAgent = new WeakMap(), _DocuWare_instances = new WeakSet(), _DocuWare_send = function _DocuWare_send(url, options, requireAuthentication = true) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -218,9 +219,12 @@ if (requireAuthentication && !__classPrivateFieldGet(this, _DocuWare_token, "f")) { | ||
} | ||
const headers = Object.assign({ Accept: "application/json" }, options.headers); | ||
const headers = Object.assign({ "User-Agent": __classPrivateFieldGet(this, _DocuWare_userAgent, "f"), Accept: "application/json" }, options.headers); | ||
if (requireAuthentication) { | ||
if (__classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_isExpired).call(this)) { | ||
yield this.authenticate(); | ||
} | ||
headers.Authorization = `Bearer ${__classPrivateFieldGet(this, _DocuWare_token, "f")}`; | ||
} | ||
try { | ||
const response = yield got(Object.assign(Object.assign({}, options), { headers })); | ||
return JSON.parse((_a = response.body) !== null && _a !== void 0 ? _a : {}); | ||
const response = yield ky(url, Object.assign(Object.assign({}, options), { headers })).json(); | ||
return response; | ||
} | ||
@@ -233,12 +237,14 @@ catch (error) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, Object.assign(Object.assign({}, options), { url, method: "GET" }), requireAuthentication); | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, url, Object.assign(Object.assign({}, options), { method: "GET" }), requireAuthentication); | ||
}); | ||
}, _DocuWare_post = function _DocuWare_post(url, options = {}, requireAuthentication = true) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, Object.assign(Object.assign({}, options), { url, method: "POST" }), requireAuthentication); | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, url, Object.assign(Object.assign({}, options), { method: "POST" }), requireAuthentication); | ||
}); | ||
}, _DocuWare_put = function _DocuWare_put(url, options = {}, requireAuthentication = true) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, Object.assign(Object.assign({}, options), { url, method: "PUT" }), requireAuthentication); | ||
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_send).call(this, url, Object.assign(Object.assign({}, options), { method: "PUT" }), requireAuthentication); | ||
}); | ||
}, _DocuWare_isExpired = function _DocuWare_isExpired() { | ||
return !__classPrivateFieldGet(this, _DocuWare_expiration, "f") || __classPrivateFieldGet(this, _DocuWare_expiration, "f") < Date.now() / 1000; | ||
}; |
{ | ||
"name": "@itarius-ug/docuware-api-client", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "A TypeScript wrapper for the DocuWare REST API", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"got": "^14.2.1" | ||
"ky": "^1.2.4" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
49708
457
0
+ Addedky@^1.2.4
+ Addedky@1.7.2(transitive)
- Removedgot@^14.2.1
- Removed@sec-ant/readable-stream@0.4.1(transitive)
- Removed@sindresorhus/is@7.0.1(transitive)
- Removed@szmarczak/http-timer@5.0.1(transitive)
- Removed@types/http-cache-semantics@4.0.4(transitive)
- Removedcacheable-lookup@7.0.0(transitive)
- Removedcacheable-request@12.0.1(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removeddefer-to-connect@2.0.1(transitive)
- Removedform-data-encoder@4.0.2(transitive)
- Removedget-stream@9.0.1(transitive)
- Removedgot@14.4.5(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp2-wrapper@2.2.1(transitive)
- Removedis-stream@4.0.1(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlowercase-keys@3.0.0(transitive)
- Removedmimic-response@3.1.04.0.0(transitive)
- Removednormalize-url@8.0.1(transitive)
- Removedp-cancelable@4.0.1(transitive)
- Removedquick-lru@5.1.1(transitive)
- Removedresolve-alpn@1.2.1(transitive)
- Removedresponselike@3.0.0(transitive)
- Removedtype-fest@4.29.0(transitive)