diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1dea290 --- /dev/null +++ b/.gitignore @@ -0,0 +1,132 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +.tmp diff --git a/actions/imanage/.app-functions b/actions/imanage/.app-functions new file mode 100644 index 0000000..e69de29 diff --git a/actions/imanage/functions/imanage-login/1.0/function.json b/actions/imanage/functions/imanage-login/1.0/function.json new file mode 100644 index 0000000..768ff4a --- /dev/null +++ b/actions/imanage/functions/imanage-login/1.0/function.json @@ -0,0 +1,63 @@ +{ + "description": "Description", + "label": "Imanage Login", + "category": "Misc", + "icon": "CreateIcon", + "options": [ + { + "meta": { + "type": "Text" + }, + "name": "email", + "label": "Email", + "info": "email", + "configuration": { + "placeholder": "admin@example.com" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "password", + "label": "Password", + "info": "Password", + "configuration": { + "placeholder": "supersecret" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "client_id", + "label": "Client Id", + "info": "Client Id", + "configuration": { + "placeholder": "supersecret" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "client_secret", + "label": "Client Secret", + "info": "Client Secret", + "configuration": { + "placeholder": "supersecret" + } + }, + { + "name": "token", + "label": "Token", + "meta": { + "type": "Output", + "output": { + "type": "Text" + } + } + } + ], + "yields": "NONE" +} diff --git a/actions/imanage/functions/imanage-login/1.0/index.js b/actions/imanage/functions/imanage-login/1.0/index.js new file mode 100644 index 0000000..89f2246 --- /dev/null +++ b/actions/imanage/functions/imanage-login/1.0/index.js @@ -0,0 +1,33 @@ +import urlSearchParams from "../../utils/url-search-params" + +const AUTHURL = "https://cloudimanage.com/auth/oauth2/token" + +const imanageLogin = async ({email, password, client_id, client_secret}) => { + const loginData = new urlSearchParams({ + username: email, + password, + client_id, + client_secret, + grant_type: "password" + }) + + return await fetch(AUTHURL, { + method: "post", + body: loginData.toString(), + headers: { "Content-Type": "application/x-www-form-urlencoded"} + }) + .then(response => { + if (response.status === 200 && response.ok === true) { + const tokens = response.json() + return { + token: tokens.access_token + } + } + throw Error(`${JSON.stringify(response)}`) + }) + .catch(error => { + throw Error(`${JSON.stringify(error)}`) + }) +} + +export default imanageLogin; \ No newline at end of file diff --git a/actions/imanage/functions/imanage-upload-document/1.0/function.json b/actions/imanage/functions/imanage-upload-document/1.0/function.json new file mode 100644 index 0000000..0fcb777 --- /dev/null +++ b/actions/imanage/functions/imanage-upload-document/1.0/function.json @@ -0,0 +1,79 @@ +{ + "description": "Description", + "label": "Imanage Upload Document", + "category": "Misc", + "icon": "CreateIcon", + "options": [ + { + "meta": { + "type": "Text" + }, + "name": "documentName", + "label": "Document Name", + "info": "The document name", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "customerId", + "label": "Customer ID", + "info": "The customer id in the format Dev!01", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "documentId", + "label": "Document ID", + "info": "The document id in the format Dev!01", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "authToken", + "label": "authToken", + "info": "authToken", + "advanced": true, + "configuration": { + "placeholder": "token" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "file", + "label": "File", + "info": "", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "name": "result", + "label": "Result", + "meta": { + "type": "Output", + "output": { + "type": "Text" + } + } + } + ], + "yields": "NONE" +} diff --git a/actions/imanage/functions/imanage-upload-document/1.0/index.js b/actions/imanage/functions/imanage-upload-document/1.0/index.js new file mode 100644 index 0000000..fbe79e3 --- /dev/null +++ b/actions/imanage/functions/imanage-upload-document/1.0/index.js @@ -0,0 +1,42 @@ +import FormData from "../../utils/url-search-params" + +const imanageUploadDocument = async ({documentName, customerId, documentId, authToken, fileURL}) => { + +const resourceURL = `https://cloudimanage.com/work/api/v2/customers/${customerId}/libraries/Dev/folders/${documentId}/documents` + +let response = await fetch(fileURL) + +let blob = await response.blob() + +let buffer = await blob.arrayBuffer() + +let file = Buffer.from(buffer) + +let fileProfile = { + "warnings_for_required_and_disabled_fields": true, + "doc_profile": { + "name": documentName, + "extension": "pdf" + }, + "user_trustees": [], + "group_trustees": [] +} + +let fileProfileJson = JSON.stringify(fileProfile) + +let formData = new FormData({ + "profile": fileProfileJson, + "file": file +}) + +let request = { + method: "POST", + headers: {'X-Auth-Token': authToken}, + body: formData.toString() +} + +let imanageResponse = await fetch(resourceURL, request) +return imanageResponse.json() +} + +export default imanageUploadDocument; \ No newline at end of file diff --git a/actions/imanage/functions/imanage/1.0/function.json b/actions/imanage/functions/imanage/1.0/function.json new file mode 100644 index 0000000..48f2fb0 --- /dev/null +++ b/actions/imanage/functions/imanage/1.0/function.json @@ -0,0 +1,112 @@ +{ + "description": "Description", + "label": "Imanage", + "category": "Misc", + "icon": "CreateIcon", + "options": [ + { + "meta": { + "type": "Text" + }, + "name": "name", + "label": "Name", + "info": "name", + "advanced": true, + "configuration": { + "placeholder": "model" + } + }, + { + "meta": { + "type": "Object" + }, + "name": "params", + "label": "Params", + "info": "params", + "advanced": true + }, + { + "meta": { + "type": "Text" + }, + "name": "customerId", + "label": "Customer Id", + "info": "Customer Id", + "advanced": true, + "configuration": { + "placeholder": "1234" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "libraryName", + "label": "Library Name", + "info": "Library Name", + "advanced": true, + "configuration": { + "placeholder": "Dev" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "workspaceId", + "label": "Workspace ID", + "info": "The workspace id in the format Dev!01", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "folderId", + "label": "Folder ID", + "info": "The folder id in the format Dev!01", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "documentId", + "label": "Document ID", + "info": "The document id in the format Dev!01", + "advanced": true, + "configuration": { + "placeholder": "Dev!01" + } + }, + { + "meta": { + "type": "Text" + }, + "name": "authToken", + "label": "authToken", + "info": "authToken", + "advanced": true, + "configuration": { + "placeholder": "token" + } + }, + { + "name": "result", + "label": "Result", + "meta": { + "type": "Output", + "output": { + "type": "Text" + } + } + } + ], + "yields": "NONE" +} diff --git a/actions/imanage/functions/imanage/1.0/index.js b/actions/imanage/functions/imanage/1.0/index.js new file mode 100644 index 0000000..82c2e77 --- /dev/null +++ b/actions/imanage/functions/imanage/1.0/index.js @@ -0,0 +1,231 @@ +import lodash from "lodash"; + +const BASEURL = "https://cloudimanage.com/work/api/v2/customers" + +const responseResultFormatterNestedResult = { + processResponse: (respose) => { + return respose.data.results + }, + returnFormat: (results) => { + return { + results: results, + totalCount: results.length, + } + } +} + +const responseResultFormatterNoNestedResult = { + processResponse: (respose) => { + return respose.data + }, + returnFormat: (results) => { + return { + results: results, + totalCount: results.length, + } + } +} + +const responseResultFormatter = { + processResponse: (respose) => { + return [respose.data] + }, + returnFormat: (results) => { + return results + } +} + +const MODEL_LOOKUP = { + allDocuments: { + url: `${BASEURL}/{customerId}/documents`, + method: "GET", + ...responseResultFormatterNestedResult + }, + allWorkspaces: { + url: `${BASEURL}/{customerId}/workspaces`, + method: "GET", + ...responseResultFormatterNestedResult + }, + allDocumentNVP: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}/name-value-pairs`, + method: "GET", + + }, + allFolders: { + url: `${BASEURL}/{customerId}/folders`, + method: "GET", + ...responseResultFormatterNoNestedResult + }, + allFolderChildren: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/folders/{folderId}/children`, + method: "GET", + ...responseResultFormatterNoNestedResult + }, + allDocumentHistory: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}/history`, + method: "GET", + ...responseResultFormatterNoNestedResult + }, + allDocumentUserHistory: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}/history/users`, + method: "GET", + ...responseResultFormatterNoNestedResult + }, + allLibraryCheckedOutDocuments: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/checkout`, + method: "GET", + ...responseResultFormatterNoNestedResult + }, + oneDocuments: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}`, + method: "GET", + ...responseResultFormatter + }, + oneWorkspaces: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/workspaces/{workspaceId}`, + method: "GET", + ...responseResultFormatter + }, + oneFolders: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/folders/{folderId}`, + method: "GET", + ...responseResultFormatter + }, + updateDocuments: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}`, + method: "PATCH", + ...responseResultFormatter + }, + updateWorkspaces: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/workspace/{workspaceId}`, + method: "PATCH", + ...responseResultFormatter + }, + updateFolders: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/folder/{folderId}`, + method: "PATCH", + ...responseResultFormatter + }, + createFolders: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/workspaces/{workspaceId}/folders`, + method: "POST", + ...responseResultFormatter + }, + createSubFolders: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/folders/{folderId}/subfolders`, + method: "POST", + ...responseResultFormatter + }, + createWorkspaces: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/workspaces`, + method: "POST", + ...responseResultFormatter + }, + deleteDocuments: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/documents/{documentId}`, + method: "DELETE", + ...responseResultFormatter + }, + deleteFolders: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/folders/{folderId}`, + method: "DELETE", + ...responseResultFormatter + }, + deleteWorkspaces: { + url: `${BASEURL}/{customerId}/libraries/{libraryName}/workspaces/{workspaceId}`, + method: "DELETE", + ...responseResultFormatter + } + +} + +const mapKeys = (key) => { + if (["size", "class", "type"].includes(key)) { + return `document_${key}`; + } else { + return key; + } + }; + + const pruneId = (value, libraryName) => { + let combinedId = lodash.trimStart(value.replace(libraryName, ""), "!"); + let [id] = combinedId.split(".") + return parseInt(id) + } + + const mapResults = (data, requestedFields, libraryName) => { + return data.map((map) => { + let newMap = {}; + + for (let [key, value] of Object.entries(map)) { + let convertedKey = lodash.camelCase(mapKeys(key)); + if (requestedFields.includes(convertedKey) || requestedFields.includes("all")) { + if (convertedKey == "id") { + newMap[convertedKey] = pruneId(value, libraryName); + } else { + newMap[convertedKey] = value; + } + } else { + newMap; + } + }; + + return newMap; + }); + }; + + const fetchData = async (url, method, authToken, body) => { + let request = { + method: method, + headers: { "Content-Type": "application/json", "X-Auth-Token": authToken } + } + + if (method != 'GET') { + request['body'] = body + } + + let response = await fetch(url, request); + + return response.json(); + } + +const imanage = async ({name, params, customerId, libraryName, workspaceId, folderId, documentId, authToken}) => { + const requestedFields = typeof(params) == "undefined" ? ["all"] : params.select || ["all"]; + const requestData = typeof(params) == "undefined" ? {} : JSON.stringify(params.input) || {}; + const MODEL_RESOURCE = MODEL_LOOKUP[name] + + if (MODEL_RESOURCE == undefined) { + let not_implement = `${name} is not implemented` + console.error(not_implement) + throw Error(not_implement) + } + + const url = MODEL_RESOURCE.url + .replace("{customerId}", customerId) + .replace("{libraryName}", libraryName) + .replace("{documentId}", documentId) + .replace("{folderId}", folderId) + .replace("{workspaceId}", workspaceId) + + let response = await fetchData(url, MODEL_RESOURCE.method, authToken, requestData); + + if (response.data) { + let data = MODEL_RESOURCE.processResponse(response) + let results = mapResults(data, requestedFields, libraryName) + + return { + result: MODEL_RESOURCE.returnFormat(results) + } + } + + if (response.error) { + console.error(response.error) + throw Error(`${JSON.stringify(response.error)}`); + } + + return { + result: {} + } +} + +export default imanage; \ No newline at end of file diff --git a/actions/imanage/functions/utils/url-search-params.js b/actions/imanage/functions/utils/url-search-params.js new file mode 100644 index 0000000..8bda26e --- /dev/null +++ b/actions/imanage/functions/utils/url-search-params.js @@ -0,0 +1,376 @@ +/*! (c) Andrea Giammarchi - ISC */ +var self = {}; +try { + (function (URLSearchParams, plus) { + if ( + new URLSearchParams('q=%2B').get('q') !== plus || + new URLSearchParams({q: plus}).get('q') !== plus || + new URLSearchParams([['q', plus]]).get('q') !== plus || + new URLSearchParams('q=\n').toString() !== 'q=%0A' || + new URLSearchParams({q: ' &'}).toString() !== 'q=+%26' || + new URLSearchParams({q: '%zx'}).toString() !== 'q=%25zx' + ) + throw URLSearchParams; + self.URLSearchParams = URLSearchParams; + }(URLSearchParams, '+')); +} catch(URLSearchParams) { + (function (Object, String, isArray) {'use strict'; + var create = Object.create; + var defineProperty = Object.defineProperty; + var find = /[!'\(\)~]|%20|%00/g; + var findPercentSign = /%(?![0-9a-fA-F]{2})/g; + var plus = /\+/g; + var replace = { + '!': '%21', + "'": '%27', + '(': '%28', + ')': '%29', + '~': '%7E', + '%20': '+', + '%00': '\x00' + }; + var proto = { + append: function (key, value) { + appendTo(this._ungap, key, value); + }, + delete: function (key) { + delete this._ungap[key]; + }, + get: function (key) { + return this.has(key) ? this._ungap[key][0] : null; + }, + getAll: function (key) { + return this.has(key) ? this._ungap[key].slice(0) : []; + }, + has: function (key) { + return key in this._ungap; + }, + set: function (key, value) { + this._ungap[key] = [String(value)]; + }, + forEach: function (callback, thisArg) { + var self = this; + for (var key in self._ungap) + self._ungap[key].forEach(invoke, key); + function invoke(value) { + callback.call(thisArg, value, String(key), self); + } + }, + toJSON: function () { + return {}; + }, + toString: function () { + var query = []; + for (var key in this._ungap) { + var encoded = encode(key); + for (var + i = 0, + value = this._ungap[key]; + i < value.length; i++ + ) { + query.push(encoded + '=' + encode(value[i])); + } + } + return query.join('&'); + } + }; + for (var key in proto) + defineProperty(URLSearchParams.prototype, key, { + configurable: true, + writable: true, + value: proto[key] + }); + self.URLSearchParams = URLSearchParams; + function URLSearchParams(query) { + var dict = create(null); + defineProperty(this, '_ungap', {value: dict}); + switch (true) { + case !query: + break; + case typeof query === 'string': + if (query.charAt(0) === '?') { + query = query.slice(1); + } + for (var + pairs = query.split('&'), + i = 0, + length = pairs.length; i < length; i++ + ) { + var value = pairs[i]; + var index = value.indexOf('='); + if (-1 < index) { + appendTo( + dict, + decode(value.slice(0, index)), + decode(value.slice(index + 1)) + ); + } else if (value.length){ + appendTo( + dict, + decode(value), + '' + ); + } + } + break; + case isArray(query): + for (var + i = 0, + length = query.length; i < length; i++ + ) { + var value = query[i]; + appendTo(dict, value[0], value[1]); + } + break; + case 'forEach' in query: + query.forEach(addEach, dict); + break; + default: + for (var key in query) + appendTo(dict, key, query[key]); + } + } + + function addEach(value, key) { + appendTo(this, key, value); + } + + function appendTo(dict, key, value) { + var res = isArray(value) ? value.join(',') : value; + if (key in dict) + dict[key].push(res); + else + dict[key] = [res]; + } + + function decode(str) { + return decodeURIComponent(str.replace(findPercentSign, '%25').replace(plus, ' ')); + } + + function encode(str) { + return encodeURIComponent(str).replace(find, replacer); + } + + function replacer(match) { + return replace[match]; + } + + }(Object, String, Array.isArray)); +} + +(function (URLSearchParamsProto) { + + var iterable = false; + try { iterable = !!Symbol.iterator; } catch (o_O) {} + + /* istanbul ignore else */ + if (!('forEach' in URLSearchParamsProto)) { + URLSearchParamsProto.forEach = function forEach(callback, thisArg) { + var self = this; + var names = Object.create(null); + this.toString() + .replace(/=[\s\S]*?(?:&|$)/g, '=') + .split('=') + .forEach(function (name) { + if (!name.length || name in names) + return; + (names[name] = self.getAll(name)).forEach(function(value) { + callback.call(thisArg, value, name, self); + }); + }); + }; + } + + /* istanbul ignore else */ + if (!('keys' in URLSearchParamsProto)) { + URLSearchParamsProto.keys = function keys() { + return iterator(this, function(value, key) { this.push(key); }); + }; + } + + /* istanbul ignore else */ + if (!('values' in URLSearchParamsProto)) { + URLSearchParamsProto.values = function values() { + return iterator(this, function(value, key) { this.push(value); }); + }; + } + + /* istanbul ignore else */ + if (!('entries' in URLSearchParamsProto)) { + URLSearchParamsProto.entries = function entries() { + return iterator(this, function(value, key) { this.push([key, value]); }); + }; + } + + /* istanbul ignore else */ + if (iterable && !(Symbol.iterator in URLSearchParamsProto)) { + URLSearchParamsProto[Symbol.iterator] = URLSearchParamsProto.entries; + } + + /* istanbul ignore else */ + if (!('sort' in URLSearchParamsProto)) { + URLSearchParamsProto.sort = function sort() { + var + entries = this.entries(), + entry = entries.next(), + done = entry.done, + keys = [], + values = Object.create(null), + i, key, value + ; + while (!done) { + value = entry.value; + key = value[0]; + keys.push(key); + if (!(key in values)) { + values[key] = []; + } + values[key].push(value[1]); + entry = entries.next(); + done = entry.done; + } + // not the champion in efficiency + // but these two bits just do the job + keys.sort(); + for (i = 0; i < keys.length; i++) { + this.delete(keys[i]); + } + for (i = 0; i < keys.length; i++) { + key = keys[i]; + this.append(key, values[key].shift()); + } + }; + } + + function iterator(self, callback) { + var items = []; + self.forEach(callback, items); + /* istanbul ignore next */ + return iterable ? + items[Symbol.iterator]() : + { + next: function() { + var value = items.shift(); + return {done: value === void 0, value: value}; + } + }; + } + + /* istanbul ignore next */ + (function (Object) { + var + dP = Object.defineProperty, + gOPD = Object.getOwnPropertyDescriptor, + createSearchParamsPollute = function (search) { + function append(name, value) { + URLSearchParamsProto.append.call(this, name, value); + name = this.toString(); + search.set.call(this._usp, name ? ('?' + name) : ''); + } + function del(name) { + URLSearchParamsProto.delete.call(this, name); + name = this.toString(); + search.set.call(this._usp, name ? ('?' + name) : ''); + } + function set(name, value) { + URLSearchParamsProto.set.call(this, name, value); + name = this.toString(); + search.set.call(this._usp, name ? ('?' + name) : ''); + } + return function (sp, value) { + sp.append = append; + sp.delete = del; + sp.set = set; + return dP(sp, '_usp', { + configurable: true, + writable: true, + value: value + }); + }; + }, + createSearchParamsCreate = function (polluteSearchParams) { + return function (obj, sp) { + dP( + obj, '_searchParams', { + configurable: true, + writable: true, + value: polluteSearchParams(sp, obj) + } + ); + return sp; + }; + }, + updateSearchParams = function (sp) { + var append = sp.append; + sp.append = URLSearchParamsProto.append; + URLSearchParams.call(sp, sp._usp.search.slice(1)); + sp.append = append; + }, + verifySearchParams = function (obj, Class) { + if (!(obj instanceof Class)) throw new TypeError( + "'searchParams' accessed on an object that " + + "does not implement interface " + Class.name + ); + }, + upgradeClass = function (Class) { + var + ClassProto = Class.prototype, + searchParams = gOPD(ClassProto, 'searchParams'), + href = gOPD(ClassProto, 'href'), + search = gOPD(ClassProto, 'search'), + createSearchParams + ; + if (!searchParams && search && search.set) { + createSearchParams = createSearchParamsCreate( + createSearchParamsPollute(search) + ); + Object.defineProperties( + ClassProto, + { + href: { + get: function () { + return href.get.call(this); + }, + set: function (value) { + var sp = this._searchParams; + href.set.call(this, value); + if (sp) updateSearchParams(sp); + } + }, + search: { + get: function () { + return search.get.call(this); + }, + set: function (value) { + var sp = this._searchParams; + search.set.call(this, value); + if (sp) updateSearchParams(sp); + } + }, + searchParams: { + get: function () { + verifySearchParams(this, Class); + return this._searchParams || createSearchParams( + this, + new URLSearchParams(this.search.slice(1)) + ); + }, + set: function (sp) { + verifySearchParams(this, Class); + createSearchParams(this, sp); + } + } + } + ); + } + } + ; + try { + upgradeClass(HTMLAnchorElement); + if (/^function|object$/.test(typeof URL) && URL.prototype) + upgradeClass(URL); + } catch (meh) {} + }(Object)); + +}(self.URLSearchParams.prototype, Object)); +export default self.URLSearchParams; \ No newline at end of file diff --git a/actions/imanage/package-lock.json b/actions/imanage/package-lock.json new file mode 100644 index 0000000..eb6dd1d --- /dev/null +++ b/actions/imanage/package-lock.json @@ -0,0 +1,125 @@ +{ + "name": "app-functions", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "app-functions", + "version": "1.0.0", + "dependencies": { + "form-data": "^4.0.0", + "lodash": "^4.17.15" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + } + }, + "dependencies": { + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + } + } +} diff --git a/actions/imanage/package.json b/actions/imanage/package.json new file mode 100644 index 0000000..2f9da36 --- /dev/null +++ b/actions/imanage/package.json @@ -0,0 +1,9 @@ +{ + "name": "app-functions", + "version": "1.0.0", + "dependencies": { + "form-data": "^4.0.0", + "lodash": "^4.17.15" + }, + "private": "true" +} diff --git a/actions/imanage/test/helpers.js b/actions/imanage/test/helpers.js new file mode 100644 index 0000000..02c7b70 --- /dev/null +++ b/actions/imanage/test/helpers.js @@ -0,0 +1,232 @@ +const gql = async (query) => { + return [{ id: 1, name: 'Bruce Wayne' }]; +}; + +const fetch = async (url, options) => { + if (url === "https://cloudimanage.com/auth/oauth2/token") { + return { + ok: true, + status: 200, + json: () => { + return { + "access_token": "access_token_12345", + "refresh_token": "refresh_token", + "token_type": "Bearer", + "expires_in": 1800 + } + } + } + } + + if (url === "https://cloudimanage.com/work/api/v2/customers/0000/documents") { + return { + ok: true, + status: 200, + json: () => { + return { + "data": { + "results": [ + { + "author_description": "testtest", + "author": "test", + "checksum": "SHA256:7FCEFF211111111111111111111111111111111111111111111C", + "class": "DOC", + "class_description": "Document", + "content_type": "D", + "create_date": "2022-10-12T16:13:28.579Z", + "create_profile_date": "2022-10-12T16:13:28.579Z", + "database": "DEV", + "default_security": "public", + "document_number": 74, + "edit_date": "2022-10-12T16:13:28.579Z", + "edit_profile_date": "2022-10-12T16:13:28.579Z", + "file_create_date": "2022-10-12T16:13:28.579Z", + "file_edit_date": "2022-10-12T16:13:28.579Z", + "id": "Dev!74.1", + "is_checked_out": false, + "is_declared": false, + "is_external": false, + "is_external_as_normal": false, + "is_hipaa": false, + "is_in_use": false, + "is_restorable": true, + "iwl": "iwl:dms=cloudimanage.com&&lib=Dev&&num=74&&ver=1", + "last_user": "test", + "last_user_description": "testtest", + "name": "Assesment Result", + "operator_description": "testtest", + "operator": "test", + "retain_days": 10, + "size": 59760, + "subclass_description": "", + "extension": "PDF", + "type": "ACROBAT", + "type_description": "Adobe Acrobat Reader", + "version": 1, + "wopi_file_size_warning": false, + "workspace_id": "Dev!11", + "workspace_name": "test test Assesments", + "wstype": "document" + } + ] + } + } + } + } + } + + if (url === "https://cloudimanage.com/work/api/v2/customers/0000/libraries/Dev/documents/Dev!11.1" && options.method === 'GET') { + return { + ok: true, + status: 200, + json: () => { + return { + "data": { + "author_description": "testtest", + "author": "test", + "checksum": "SHA256:7FCEFF211111111111111111111111111111111111111111111C", + "class": "DOC", + "class_description": "Document", + "content_type": "D", + "create_date": "2022-10-12T16:13:28.579Z", + "create_profile_date": "2022-10-12T16:13:28.579Z", + "database": "DEV", + "default_security": "public", + "document_number": 11, + "edit_date": "2022-10-12T16:13:28.579Z", + "edit_profile_date": "2022-10-12T16:13:28.579Z", + "file_create_date": "2022-10-12T16:13:28.579Z", + "file_edit_date": "2022-10-12T16:13:28.579Z", + "id": "Dev!11.1", + "is_checked_out": false, + "is_declared": false, + "is_external": false, + "is_external_as_normal": false, + "is_hipaa": false, + "is_in_use": false, + "is_restorable": true, + "iwl": "iwl:dms=cloudimanage.com&&lib=Dev&&num=74&&ver=1", + "last_user": "test", + "last_user_description": "testtest", + "name": "Assesment Result", + "operator_description": "testtest", + "operator": "test", + "retain_days": 10, + "size": 59760, + "subclass_description": "", + "extension": "PDF", + "type": "ACROBAT", + "type_description": "Adobe Acrobat Reader", + "version": 1, + "wopi_file_size_warning": false, + "workspace_id": "Dev!11", + "workspace_name": "test test Assesments", + "wstype": "document" + } + } + } + } + } + + if (url === "https://cloudimanage.com/work/api/v2/customers/0000/libraries/Dev/documents/Dev!12.1" && options.method === 'PATCH') { + return { + ok: true, + status: 200, + json: () => { + return { + "data": { + "author_description": "testtest", + "author": "test", + "checksum": "SHA256:7FCEFF211111111111111111111111111111111111111111111C", + "class": "DOC", + "class_description": "Document", + "content_type": "D", + "create_date": "2022-10-12T16:13:28.579Z", + "create_profile_date": "2022-10-12T16:13:28.579Z", + "database": "DEV", + "default_security": "public", + "document_number": 12, + "edit_date": "2022-10-12T16:13:28.579Z", + "edit_profile_date": "2022-10-12T16:13:28.579Z", + "file_create_date": "2022-10-12T16:13:28.579Z", + "file_edit_date": "2022-10-12T16:13:28.579Z", + "id": "Dev!12.1", + "is_checked_out": false, + "is_declared": false, + "is_external": false, + "is_external_as_normal": false, + "is_hipaa": false, + "is_in_use": false, + "is_restorable": true, + "iwl": "iwl:dms=cloudimanage.com&&lib=Dev&&num=74&&ver=1", + "last_user": "test", + "last_user_description": "testtest", + "name": "test-updated", + "operator_description": "testtest", + "operator": "test", + "retain_days": 10, + "size": 59760, + "subclass_description": "", + "extension": "PDF", + "type": "ACROBAT", + "type_description": "Adobe Acrobat Reader", + "version": 1, + "wopi_file_size_warning": false, + "workspace_id": "Dev!11", + "workspace_name": "test test Assesments", + "wstype": "document" + } + } + } + } + } + + if (url === "https://cloudimanage.com/work/api/v2/customers/0000/libraries/Dev/workspaces/test/folders" && options.method === 'POST') { + return { + ok: true, + status: 201, + json: () => { + return { + "data": { + "database": "Dev", + "default_security": "inherit", + "edit_date": "2022-10-19T13:05:09.604Z", + "effective_security": "full_access", + "folder_type": "regular", + "has_subfolders": false, + "id": "Dev!13", + "is_container_saved_search": false, + "is_content_saved_search": false, + "is_external_as_normal": false, + "name": "Created Folder", + "owner": "test test", + "owner_description": "test", + "parent_id": "Dev!09", + "view_type": "document", + "workspace_id": "Dev!85", + "workspace_name": "Action Setup Workspace", + "wstype": "folder" + } + } + } + } + } + + if (url === "https://cloudimanage.com/work/api/v2/customers/0000/libraries/Dev/documents/Dev!14.1" && options.method === 'DELETE') { + return { + ok: true, + status: 200, + json: () => { + return {} + } + } + } + + return { + ok: true, + status: 200, + json: () => { + return {} + } + } +} diff --git a/actions/imanage/test/imanage-createFolder.test.js b/actions/imanage/test/imanage-createFolder.test.js new file mode 100644 index 0000000..47e90ac --- /dev/null +++ b/actions/imanage/test/imanage-createFolder.test.js @@ -0,0 +1,27 @@ +test("imanage createFolder", async () => { + const output = await $app["imanage 1.0"]({ + name: "createFolders", + params: {select: ["id"], input: { + "name": "Demo Folder", + "description" : "Folder Created For Demo Purposes", + "location" : "Demoville", + "default_security": "public", + "is_external" : false, + "is_external_as_normal" : false, + "is_container_saved_search" : false, + "is_content_saved_search" : false + }}, + customerId: "0000", + libraryName: "Dev", + workspaceId: "test", + authToken: "tokentoken" + }) + + assert(output, { + "result": [ + { + "id": 13, + } + ] + }) +}) \ No newline at end of file diff --git a/actions/imanage/test/imanage-deleteDocument.test.js b/actions/imanage/test/imanage-deleteDocument.test.js new file mode 100644 index 0000000..49119aa --- /dev/null +++ b/actions/imanage/test/imanage-deleteDocument.test.js @@ -0,0 +1,14 @@ +test("imanage deleteDocument", async () => { + const output = await $app["imanage 1.0"]({ + name: "deleteDocuments", + params: {}, + customerId: "0000", + libraryName: "Dev", + documentId: "Dev!14.1", + authToken: "tokentoken" + }) + + assert(output, { + "result": {} + }) +}) \ No newline at end of file diff --git a/actions/imanage/test/imanage-getAllDocuments.test.js b/actions/imanage/test/imanage-getAllDocuments.test.js new file mode 100644 index 0000000..3507a80 --- /dev/null +++ b/actions/imanage/test/imanage-getAllDocuments.test.js @@ -0,0 +1,80 @@ +test("imanage getAllDocuments", async () => { + const output = await $app["imanage 1.0"]({ + name: "allDocuments", + params: {}, + customerId: "0000", + libraryName: "Dev", + authToken: "tokentoken" + }) + + assert(output, { + "result": { + "results": [ + { + "authorDescription":"testtest", + "author":"test", + "checksum":"SHA256:7FCEFF211111111111111111111111111111111111111111111C", + "documentClass":"DOC", + "classDescription":"Document", + "contentType":"D", + "createDate":"2022-10-12T16:13:28.579Z", + "createProfileDate":"2022-10-12T16:13:28.579Z", + "database":"DEV", + "defaultSecurity":"public", + "documentNumber":74, + "editDate":"2022-10-12T16:13:28.579Z", + "editProfileDate":"2022-10-12T16:13:28.579Z", + "fileCreateDate":"2022-10-12T16:13:28.579Z", + "fileEditDate":"2022-10-12T16:13:28.579Z", + "id":74, + "isCheckedOut":false, + "isDeclared":false, + "isExternal":false, + "isExternalAsNormal":false, + "isHipaa":false, + "isInUse":false, + "isRestorable":true, + "iwl":"iwl:dms=cloudimanage.com&&lib=Dev&&num=74&&ver=1", + "lastUser":"test", + "lastUserDescription":"testtest", + "name":"Assesment Result", + "operatorDescription":"testtest", + "operator":"test", + "retainDays":10, + "documentSize":59760, + "subclassDescription":"", + "extension":"PDF", + "documentType":"ACROBAT", + "typeDescription":"Adobe Acrobat Reader", + "version":1, + "wopiFileSizeWarning":false, + "workspaceId":"Dev!11", + "workspaceName":"test test Assesments", + "wstype":"document" + } + ], + "totalCount": 1 + } + }) +}); + +test("imanage getAllDocuments only return id", async () => { + const output = await $app["imanage 1.0"]({ + name: "allDocuments", + params: {select: ["id"]}, + customerId: "0000", + libraryName: "Dev", + authToken: "tokentoken" + }) + + assert(output, { + "result": { + "results": [ + { + "id":74, + } + ], + "totalCount": 1 + } + }) +}) \ No newline at end of file diff --git a/actions/imanage/test/imanage-getDocument.test.js b/actions/imanage/test/imanage-getDocument.test.js new file mode 100644 index 0000000..abb8517 --- /dev/null +++ b/actions/imanage/test/imanage-getDocument.test.js @@ -0,0 +1,18 @@ +test("imanage getDocuments only return id", async () => { + const output = await $app["imanage 1.0"]({ + name: "oneDocuments", + params: {select: ["id"]}, + customerId: "0000", + libraryName: "Dev", + documentId: "Dev!11.1", + authToken: "tokentoken" + }) + + assert(output, { + "result": [ + { + "id": 11, + } + ] + }) +}) \ No newline at end of file diff --git a/actions/imanage/test/imanage-login.test.js b/actions/imanage/test/imanage-login.test.js new file mode 100644 index 0000000..565f7f0 --- /dev/null +++ b/actions/imanage/test/imanage-login.test.js @@ -0,0 +1,10 @@ +test("imanage login", async () => { + const output = await $app["imanageLogin 1.0"]({ + email: "test@test.com", + password: "test", + client_id: "testtesttesttest", + client_secret: "testsecrettesttest", + grant_type: "password" + }) + assert(output.token, "access_token_12345") +}) \ No newline at end of file diff --git a/actions/imanage/test/imanage-updateDocument.test.js b/actions/imanage/test/imanage-updateDocument.test.js new file mode 100644 index 0000000..d7c9097 --- /dev/null +++ b/actions/imanage/test/imanage-updateDocument.test.js @@ -0,0 +1,19 @@ +test("imanage updateDocuments", async () => { + const output = await $app["imanage 1.0"]({ + name: "updateDocuments", + params: {select: ["id", "name"], input: {"name": "test-updated"}}, + customerId: "0000", + libraryName: "Dev", + documentId: "Dev!12.1", + authToken: "tokentoken" + }) + + assert(output, { + "result": [ + { + "id": 12, + "name": "test-updated" + } + ] + }) +}) \ No newline at end of file diff --git a/highq.json b/datasources/highq.json similarity index 100% rename from highq.json rename to datasources/highq.json diff --git a/imanage-v2-swagger.json b/datasources/imanage-v2-swagger.json similarity index 100% rename from imanage-v2-swagger.json rename to datasources/imanage-v2-swagger.json diff --git a/imanage-v2-swagger.yaml b/datasources/imanage-v2-swagger.yaml similarity index 100% rename from imanage-v2-swagger.yaml rename to datasources/imanage-v2-swagger.yaml