Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@itarius-ug/docuware-api-client

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itarius-ug/docuware-api-client - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

dist/docuware.d.ts

34

dist/index.d.ts

@@ -1,32 +0,2 @@

/// <reference types="node" resolution-mode="require"/>
import type { DialogExpression, DocuWareConfiguration, Document, FileCabinet, Data } from "./contracts.js";
export declare class DocuWare {
#private;
constructor(configuration: DocuWareConfiguration);
getIdentityServiceUrl(): Promise<string>;
getOpenIdConfiguration(): Promise<any>;
authenticate(): Promise<void>;
revoke(): Promise<void>;
getFileCabinetById(fileCabinetId: string): Promise<FileCabinet>;
getFileCabinetByName(name: string): Promise<FileCabinet>;
getDocumentById(fileCabinetId: string, documentId: number): Promise<Document>;
searchDocumentInFileCabinet(fileCabinetId: string, input: DialogExpression, dialogId?: string): Promise<Document | undefined>;
createDocument(fileCabinetId: string, data: Data, options?: {
mapping?: {
fields?: Record<string, string>;
tableFields?: Record<string, string>;
};
}): Promise<number>;
updateDocument(fileCabinetId: string, documentId: number, data: Data, options?: {
mapping?: {
fields?: Record<string, string>;
tableFields?: Record<string, string>;
};
replace?: boolean;
}): Promise<void>;
appendFilesToDocument(fileCabinetId: string, documentId: number, files: string | string[]): Promise<void>;
appendBufferToDocument(fileCabinetId: string, documentId: number, buffer: {
name: string;
content: Buffer;
}): Promise<void>;
}
export * from "./docuware.js";
export * from "./contracts.js";

@@ -1,236 +0,2 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _DocuWare_instances, _DocuWare_username, _DocuWare_password, _DocuWare_impersonateName, _DocuWare_baseUrl, _DocuWare_token, _DocuWare_send, _DocuWare_get, _DocuWare_post, _DocuWare_put;
import got from "got";
import { basename } from "path";
import { readFile } from "fs/promises";
import { transformData } from "./utils.js";
export class DocuWare {
constructor(configuration) {
_DocuWare_instances.add(this);
_DocuWare_username.set(this, void 0);
_DocuWare_password.set(this, void 0);
_DocuWare_impersonateName.set(this, void 0);
_DocuWare_baseUrl.set(this, void 0);
_DocuWare_token.set(this, void 0);
__classPrivateFieldSet(this, _DocuWare_baseUrl, `${configuration.baseUrl}/DocuWare/Platform`, "f");
__classPrivateFieldSet(this, _DocuWare_username, configuration.username, "f");
__classPrivateFieldSet(this, _DocuWare_password, configuration.password, "f");
__classPrivateFieldSet(this, _DocuWare_impersonateName, configuration.impersonateName, "f");
__classPrivateFieldSet(this, _DocuWare_token, null, "f");
}
getIdentityServiceUrl() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_get).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/Home/IdentityServiceInfo`, {}, false);
const identityServiceUrl = response.IdentityServiceUrl;
if (!identityServiceUrl) {
throw new Error("IdentityServiceUrl not found in the response.");
}
return identityServiceUrl;
});
}
getOpenIdConfiguration() {
return __awaiter(this, void 0, void 0, function* () {
const identityServiceUrl = yield this.getIdentityServiceUrl();
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_get).call(this, `${identityServiceUrl}/.well-known/openid-configuration`, {}, false);
});
}
authenticate() {
return __awaiter(this, void 0, void 0, function* () {
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"),
},
};
try {
const response = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.token_endpoint, options, false);
__classPrivateFieldSet(this, _DocuWare_token, response.access_token, "f");
}
catch (error) {
throw new Error(`Authentication failed: ${error.message}`);
}
});
}
revoke() {
return __awaiter(this, void 0, void 0, function* () {
const configuration = yield this.getOpenIdConfiguration();
const options = {
form: {
token: __classPrivateFieldGet(this, _DocuWare_token, "f"),
token_type_hint: "access_token",
},
};
try {
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, configuration.revocation_endpoint, options);
__classPrivateFieldSet(this, _DocuWare_token, null, "f");
}
catch (error) {
throw new Error(`Revocation failed: ${error.message}`);
}
});
}
getFileCabinetById(fileCabinetId) {
return __awaiter(this, void 0, void 0, function* () {
try {
const fileCabinet = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_get).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}`);
return fileCabinet;
}
catch (error) {
throw new Error(`File cabinet with ID '${fileCabinetId}' not found.`);
}
});
}
getFileCabinetByName(name) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_get).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets`);
const fileCabinet = response.FileCabinet.find((cabinet) => cabinet.Name === name);
if (!fileCabinet) {
throw new Error(`File cabinet with name '${name}' not found.`);
}
return fileCabinet;
});
}
getDocumentById(fileCabinetId, documentId) {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_get).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/documents/${documentId}`);
});
}
searchDocumentInFileCabinet(fileCabinetId, input, dialogId) {
return __awaiter(this, void 0, void 0, function* () {
const searchParams = {
count: 1,
dialogId: dialogId !== null && dialogId !== void 0 ? dialogId : "00000000-0000-0000-0000-000000000000",
};
const result = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/query/DialogExpression`, {
json: input,
searchParams,
});
return result.Items[0];
});
}
createDocument(fileCabinetId, data, options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const fileCabinet = yield this.getFileCabinetById(fileCabinetId);
const fields = [];
for (const [key, value] of Object.entries(data)) {
const field = (_a = fileCabinet.Fields) === null || _a === void 0 ? void 0 : _a.find((field) => { var _a, _b, _c; return field.DBFieldName === ((_c = ((_b = (_a = options === null || options === void 0 ? void 0 : options.mapping) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : {})[key]) !== null && _c !== void 0 ? _c : key); });
if (field) {
fields.push({
FieldName: field.DBFieldName,
Item: transformData(field, field.TableFieldColumns, value, options),
});
}
}
const result = yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/documents`, {
json: {
Fields: fields,
},
});
return result.Id;
});
}
updateDocument(fileCabinetId, documentId, data, options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const document = yield this.getDocumentById(fileCabinetId, documentId);
const fileCabinet = yield this.getFileCabinetById(fileCabinetId);
const updatedFields = [];
for (const [key, value] of Object.entries(data)) {
const field = (_a = document.Fields) === null || _a === void 0 ? void 0 : _a.find((field) => { var _a, _b, _c; return field.FieldName === ((_c = ((_b = (_a = options === null || options === void 0 ? void 0 : options.mapping) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : {})[key]) !== null && _c !== void 0 ? _c : key); });
const fileCabinetField = (_b = fileCabinet.Fields) === null || _b === void 0 ? void 0 : _b.find((field) => { var _a, _b, _c; return field.DBFieldName === ((_c = ((_b = (_a = options === null || options === void 0 ? void 0 : options.mapping) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : {})[key]) !== null && _c !== void 0 ? _c : key); });
if (field) {
updatedFields.push({
FieldName: field.FieldName,
Item: transformData(field, fileCabinetField.TableFieldColumns, value, options),
});
}
}
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_put).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/documents/${documentId}/Fields`, {
json: { Field: updatedFields },
});
});
}
appendFilesToDocument(fileCabinetId, documentId, files) {
return __awaiter(this, void 0, void 0, function* () {
if (!Array.isArray(files)) {
files = [files];
}
for (const file of files) {
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/Sections?DocId=${documentId}`, {
headers: {
"Content-Disposition": `file; filename="${basename(file)}"`,
"X-File-ModifiedDate": new Date().toISOString(),
},
body: yield readFile(file),
});
}
});
}
appendBufferToDocument(fileCabinetId, documentId, buffer) {
return __awaiter(this, void 0, void 0, function* () {
yield __classPrivateFieldGet(this, _DocuWare_instances, "m", _DocuWare_post).call(this, `${__classPrivateFieldGet(this, _DocuWare_baseUrl, "f")}/filecabinets/${fileCabinetId}/Sections?DocId=${documentId}`, {
headers: {
"Content-Disposition": `file; filename="${buffer.name}"`,
"X-File-ModifiedDate": new Date().toISOString(),
},
body: buffer.content,
});
});
}
}
_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;
return __awaiter(this, void 0, void 0, function* () {
if (requireAuthentication && !__classPrivateFieldGet(this, _DocuWare_token, "f")) {
throw new Error("Not authenticated. Call authenticate() first.");
}
const headers = Object.assign({ Accept: "application/json" }, options.headers);
if (requireAuthentication) {
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 : {});
}
catch (error) {
throw new Error(`Request Failed: ${error.message}`);
}
});
}, _DocuWare_get = function _DocuWare_get(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: "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);
});
}, _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);
});
};
export * from "./docuware.js";
export * from "./contracts.js";
{
"name": "@itarius-ug/docuware-api-client",
"version": "2.1.0",
"version": "2.1.1",
"description": "A TypeScript wrapper for the DocuWare REST API",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc