yaveon.ecm.d3dwebhooks 0.7.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.
- package/js/Yaveon.ECM.d3d.Client.d.ts +62 -0
- package/js/Yaveon.ECM.d3d.Client.js +171 -0
- package/js/Yaveon.ECM.d3d.Webhook.Client.d.ts +55 -0
- package/js/Yaveon.ECM.d3d.Webhook.Client.js +149 -0
- package/js/Yaveon.ECM.d3d.Webhook.Constants.d.ts +20 -0
- package/js/Yaveon.ECM.d3d.Webhook.Constants.js +40 -0
- package/js/Yaveon.ECM.d3d.Webhook.Interfaces.d.ts +37 -0
- package/js/Yaveon.ECM.d3d.Webhook.Interfaces.js +3 -0
- package/js/Yaveon.ECM.d3d.Webhook.SetNumberId.Test.d.ts +1 -0
- package/js/Yaveon.ECM.d3d.Webhook.SetNumberId.Test.js +50 -0
- package/package.json +14 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare class D3dClient {
|
|
2
|
+
private baseUrl;
|
|
3
|
+
protected repositoryId: string;
|
|
4
|
+
private defaultHeaders;
|
|
5
|
+
constructor(baseUrl: string, repositoryId: string, accessToken: string);
|
|
6
|
+
/**
|
|
7
|
+
* creates a copy of the default header and sets content-type to 'octet-stream'
|
|
8
|
+
*
|
|
9
|
+
* @returns a copy of the default header and with content-type set to 'octet-stream'
|
|
10
|
+
*/
|
|
11
|
+
private getUploadHeader;
|
|
12
|
+
/**
|
|
13
|
+
* uploads a binary chunk of data to d3 documents
|
|
14
|
+
*
|
|
15
|
+
* @param binaryData - this parameter takes in the upload body as byte array
|
|
16
|
+
* @returns The response object of the webservice call
|
|
17
|
+
*/
|
|
18
|
+
uploadChunk(binaryData: Uint8Array): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* updates a document with properties in the updateBody
|
|
21
|
+
*
|
|
22
|
+
* @param d3dObjectId - string id of the documents object
|
|
23
|
+
* @param updateBody - contains the properties which are supposed to be updated
|
|
24
|
+
* @returns The response object of the webservice call
|
|
25
|
+
*/
|
|
26
|
+
updateDocumentProperties(d3dObjectId: string, updateBody: Object): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* returns the content of a d3 documents file
|
|
29
|
+
*
|
|
30
|
+
* @param d3dDocumentId - string id of the documents object
|
|
31
|
+
* @returns the retrieved documents file content
|
|
32
|
+
*/
|
|
33
|
+
getDocumentContent(d3dDocumentId: string): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param d3dObjectId - string id of the documents object
|
|
37
|
+
* @param ownerUpn - upn of the desired owner
|
|
38
|
+
* @param stateValue - string representation of a DmsObjectState
|
|
39
|
+
* @param alterationText - optional: value that contains the alteration reason for documents system
|
|
40
|
+
* @returns the d3dObject update response object
|
|
41
|
+
*/
|
|
42
|
+
setObjectState(d3dObjectId: string, ownerUpn: string, stateValue: string, alterationText?: string): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* returns a valid eTag value
|
|
45
|
+
*
|
|
46
|
+
* @param d3dObjectId - string id of the documents object
|
|
47
|
+
* @returns a valid eTag value string
|
|
48
|
+
*/
|
|
49
|
+
getETag(d3dObjectId: string): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* retrieves an object that represents the current user
|
|
52
|
+
* @returns the current user object
|
|
53
|
+
*/
|
|
54
|
+
getCurrentUserObject(): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* retrieves search results for the given search url
|
|
57
|
+
*
|
|
58
|
+
* @param searchUrlPart - contains the search query
|
|
59
|
+
* @returns the search result object
|
|
60
|
+
*/
|
|
61
|
+
getSearchResults(searchUrlPart: string): Promise<any>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.D3dClient = void 0;
|
|
30
|
+
const Constants = __importStar(require("./Yaveon.ECM.d3d.Webhook.Constants"));
|
|
31
|
+
const axios_1 = __importDefault(require("axios"));
|
|
32
|
+
//const axios = require('axios');
|
|
33
|
+
class D3dClient {
|
|
34
|
+
constructor(baseUrl, repositoryId, accessToken) {
|
|
35
|
+
this.baseUrl = baseUrl;
|
|
36
|
+
this.repositoryId = repositoryId;
|
|
37
|
+
this.defaultHeaders = Constants.defaultHeaders;
|
|
38
|
+
this.defaultHeaders.Authorization = accessToken;
|
|
39
|
+
this.defaultHeaders.Origin = baseUrl;
|
|
40
|
+
axios_1.default.defaults.headers.common = this.defaultHeaders;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* creates a copy of the default header and sets content-type to 'octet-stream'
|
|
44
|
+
*
|
|
45
|
+
* @returns a copy of the default header and with content-type set to 'octet-stream'
|
|
46
|
+
*/
|
|
47
|
+
getUploadHeader() {
|
|
48
|
+
let headerCopy = JSON.parse(JSON.stringify(this.defaultHeaders));
|
|
49
|
+
headerCopy['Content-Type'] = "application/octet-stream";
|
|
50
|
+
return headerCopy;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* uploads a binary chunk of data to d3 documents
|
|
54
|
+
*
|
|
55
|
+
* @param binaryData - this parameter takes in the upload body as byte array
|
|
56
|
+
* @returns The response object of the webservice call
|
|
57
|
+
*/
|
|
58
|
+
async uploadChunk(binaryData) {
|
|
59
|
+
let uploadHeader = this.getUploadHeader();
|
|
60
|
+
let uploadUrl = this.baseUrl + "/dms/r/" + this.repositoryId + "/blob/chunk/";
|
|
61
|
+
let uploadResponse = await axios_1.default.post(uploadUrl, binaryData, { headers: uploadHeader });
|
|
62
|
+
return uploadResponse;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* updates a document with properties in the updateBody
|
|
66
|
+
*
|
|
67
|
+
* @param d3dObjectId - string id of the documents object
|
|
68
|
+
* @param updateBody - contains the properties which are supposed to be updated
|
|
69
|
+
* @returns The response object of the webservice call
|
|
70
|
+
*/
|
|
71
|
+
async updateDocumentProperties(d3dObjectId, updateBody) {
|
|
72
|
+
const updateUrl = this.baseUrl + '/dms/r/' + this.repositoryId + '/o2/' + d3dObjectId;
|
|
73
|
+
let updateResponse = await axios_1.default.put(updateUrl, updateBody);
|
|
74
|
+
return updateResponse;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* returns the content of a d3 documents file
|
|
78
|
+
*
|
|
79
|
+
* @param d3dDocumentId - string id of the documents object
|
|
80
|
+
* @returns the retrieved documents file content
|
|
81
|
+
*/
|
|
82
|
+
async getDocumentContent(d3dDocumentId) {
|
|
83
|
+
const fileUrl = this.baseUrl + '/dms/r/' + this.repositoryId + '/o2m/' + d3dDocumentId;
|
|
84
|
+
const getFileResponse = await axios_1.default.get(fileUrl);
|
|
85
|
+
const fileContentUrl = this.baseUrl + getFileResponse.data._links.mainblobcontent.href;
|
|
86
|
+
const getFileContentResponse = await axios_1.default.get(fileContentUrl);
|
|
87
|
+
return getFileContentResponse.data;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param d3dObjectId - string id of the documents object
|
|
92
|
+
* @param ownerUpn - upn of the desired owner
|
|
93
|
+
* @param stateValue - string representation of a DmsObjectState
|
|
94
|
+
* @param alterationText - optional: value that contains the alteration reason for documents system
|
|
95
|
+
* @returns the d3dObject update response object
|
|
96
|
+
*/
|
|
97
|
+
async setObjectState(d3dObjectId, ownerUpn, stateValue, alterationText = '') {
|
|
98
|
+
if (!Constants.DmsObjectStates.isValid(stateValue)) {
|
|
99
|
+
throw stateValue + " is not a valid document state. Valid states are " + Object.values(Constants.DmsObjectStates.States).join(", ");
|
|
100
|
+
}
|
|
101
|
+
if (stateValue === Constants.DmsObjectStates.States.Released) {
|
|
102
|
+
stateValue = Constants.FILE_STATUS_RELEASED;
|
|
103
|
+
}
|
|
104
|
+
const updateUrl = this.baseUrl + '/dms/r/' + this.repositoryId + '/o2/' + d3dObjectId + '/v/current';
|
|
105
|
+
/* let updateBody: Map <string,string> = new Map <string,string>([
|
|
106
|
+
['eTag', await this.getETag(d3dObjectId)],
|
|
107
|
+
['state', stateValue],
|
|
108
|
+
['destionationUserOrGroup', ownerUpn]
|
|
109
|
+
]); */
|
|
110
|
+
let updateBody = {
|
|
111
|
+
"eTag": await this.getETag(d3dObjectId),
|
|
112
|
+
"state": stateValue,
|
|
113
|
+
"destinationUserOrGroup": ownerUpn,
|
|
114
|
+
"alterationText": alterationText
|
|
115
|
+
};
|
|
116
|
+
let updateResponse = null;
|
|
117
|
+
try {
|
|
118
|
+
updateResponse = await axios_1.default.put(updateUrl, updateBody);
|
|
119
|
+
}
|
|
120
|
+
catch (ex) {
|
|
121
|
+
debugger;
|
|
122
|
+
}
|
|
123
|
+
return updateResponse;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* returns a valid eTag value
|
|
127
|
+
*
|
|
128
|
+
* @param d3dObjectId - string id of the documents object
|
|
129
|
+
* @returns a valid eTag value string
|
|
130
|
+
*/
|
|
131
|
+
async getETag(d3dObjectId) {
|
|
132
|
+
const eTagRequestUrl = this.baseUrl + '/dms/r/' + this.repositoryId + '/o2/' + d3dObjectId;
|
|
133
|
+
try {
|
|
134
|
+
const eTagResponse = await axios_1.default.get(eTagRequestUrl);
|
|
135
|
+
return eTagResponse.data.eTag;
|
|
136
|
+
}
|
|
137
|
+
catch (ex) {
|
|
138
|
+
throw ex.Message;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* retrieves an object that represents the current user
|
|
143
|
+
* @returns the current user object
|
|
144
|
+
*/
|
|
145
|
+
async getCurrentUserObject() {
|
|
146
|
+
let requestUrl = this.baseUrl + "/identityprovider/validate";
|
|
147
|
+
let response;
|
|
148
|
+
try {
|
|
149
|
+
response = await axios_1.default.get(requestUrl);
|
|
150
|
+
}
|
|
151
|
+
catch (ex) {
|
|
152
|
+
throw ex.Message;
|
|
153
|
+
}
|
|
154
|
+
return response.data;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* retrieves search results for the given search url
|
|
158
|
+
*
|
|
159
|
+
* @param searchUrlPart - contains the search query
|
|
160
|
+
* @returns the search result object
|
|
161
|
+
*/
|
|
162
|
+
async getSearchResults(searchUrlPart) {
|
|
163
|
+
let resultItems;
|
|
164
|
+
let searchUrl = this.baseUrl + '/dms/r/' + this.repositoryId + '/sr' + searchUrlPart;
|
|
165
|
+
let searchResponse = await axios_1.default.get(searchUrl);
|
|
166
|
+
resultItems = searchResponse.data.items;
|
|
167
|
+
return resultItems;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.D3dClient = D3dClient;
|
|
171
|
+
//# sourceMappingURL=Yaveon.ECM.d3d.Client.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { INumberRangePropertyObject } from "./Yaveon.ECM.d3d.Webhook.Interfaces";
|
|
2
|
+
import { D3dClient } from "./Yaveon.ECM.d3d.Client";
|
|
3
|
+
export declare class D3dWebhookClient extends D3dClient {
|
|
4
|
+
private configFileId;
|
|
5
|
+
private currentUserName;
|
|
6
|
+
constructor(baseUrl: string, repositoryId: string, accessToken: string);
|
|
7
|
+
/**
|
|
8
|
+
* updates the config file in d3 documents with the given config object
|
|
9
|
+
*
|
|
10
|
+
* @param configObject - config object that shall be written to d3d documents
|
|
11
|
+
* @param updateBody - contains the necessary metadata
|
|
12
|
+
* @returns {string} contentLocationUri
|
|
13
|
+
*/
|
|
14
|
+
updateConfiguration(configObject: Object, alterationText: string): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* ensures that configuration file id is present. Throws if file can't be found.
|
|
17
|
+
*
|
|
18
|
+
* @returns void
|
|
19
|
+
*/
|
|
20
|
+
private ensureConfigurationFileId;
|
|
21
|
+
/**
|
|
22
|
+
* retrieves the webhook configuration from d3 documents
|
|
23
|
+
*
|
|
24
|
+
* @returns webhook configuration object
|
|
25
|
+
*/
|
|
26
|
+
getConfiguration(): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* sets the config file to state 'processing'
|
|
29
|
+
*
|
|
30
|
+
* @param configFileId - string id of the config file document
|
|
31
|
+
* @returns void
|
|
32
|
+
*/
|
|
33
|
+
blockConfiguration(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* sets the config file to state 'released'
|
|
36
|
+
*
|
|
37
|
+
* @param configFileId - string id of the config file document
|
|
38
|
+
* @returns void
|
|
39
|
+
*/
|
|
40
|
+
releaseConfiguration(alterationText?: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* retrieves the current user name
|
|
43
|
+
*
|
|
44
|
+
* @returns the current user name as string
|
|
45
|
+
*/
|
|
46
|
+
getCurrentUserName(): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* returns the document categroy specific number range information from config
|
|
49
|
+
*
|
|
50
|
+
* @param doc - the current document object
|
|
51
|
+
* @param config - the current config object
|
|
52
|
+
* @returns the document categroy's' number range information from config
|
|
53
|
+
*/
|
|
54
|
+
getNumberRangeInformation(doc: any, config: any): INumberRangePropertyObject[];
|
|
55
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.D3dWebhookClient = void 0;
|
|
27
|
+
const Constants = __importStar(require("./Yaveon.ECM.d3d.Webhook.Constants"));
|
|
28
|
+
const Yaveon_ECM_d3d_Client_1 = require("./Yaveon.ECM.d3d.Client");
|
|
29
|
+
class D3dWebhookClient extends Yaveon_ECM_d3d_Client_1.D3dClient {
|
|
30
|
+
constructor(baseUrl, repositoryId, accessToken) {
|
|
31
|
+
super(baseUrl, repositoryId, accessToken);
|
|
32
|
+
this.configFileId = '';
|
|
33
|
+
this.currentUserName = '';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* updates the config file in d3 documents with the given config object
|
|
37
|
+
*
|
|
38
|
+
* @param configObject - config object that shall be written to d3d documents
|
|
39
|
+
* @param updateBody - contains the necessary metadata
|
|
40
|
+
* @returns {string} contentLocationUri
|
|
41
|
+
*/
|
|
42
|
+
async updateConfiguration(configObject, alterationText) {
|
|
43
|
+
await this.ensureConfigurationFileId();
|
|
44
|
+
let uploadResponse = await this.uploadChunk((new TextEncoder).encode(JSON.stringify(configObject)));
|
|
45
|
+
let updateBody = {
|
|
46
|
+
"displayValue": Constants.ConfigFileDisplayName,
|
|
47
|
+
"alterationText": alterationText,
|
|
48
|
+
"filename": Constants.ConfigFileName + '.' + Constants.ConfigFileExtension,
|
|
49
|
+
"sourceId": '/dms/r/' + this.repositoryId + '/source',
|
|
50
|
+
"contentLocationUri": uploadResponse.headers.location
|
|
51
|
+
};
|
|
52
|
+
let updateResponse = await this.updateDocumentProperties(this.configFileId, updateBody);
|
|
53
|
+
return updateResponse;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* ensures that configuration file id is present. Throws if file can't be found.
|
|
57
|
+
*
|
|
58
|
+
* @returns void
|
|
59
|
+
*/
|
|
60
|
+
async ensureConfigurationFileId() {
|
|
61
|
+
if (this.configFileId) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let searchResults = await this.getSearchResults('?properties={"property_filename":["' + Constants.ConfigFileName + '"],"property_filetype":["' + Constants.ConfigFileExtension + '"]}');
|
|
65
|
+
if (searchResults.count === 0) {
|
|
66
|
+
throw "Configuration file with filname '" + Constants.ConfigFileName + "' and filetype '" + Constants.ConfigFileExtension + "' could not be found.";
|
|
67
|
+
}
|
|
68
|
+
this.configFileId = searchResults[0].id;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* retrieves the webhook configuration from d3 documents
|
|
72
|
+
*
|
|
73
|
+
* @returns webhook configuration object
|
|
74
|
+
*/
|
|
75
|
+
async getConfiguration() {
|
|
76
|
+
let searchResults = await this.getSearchResults('?properties={"property_filename":["' + Constants.ConfigFileName + '"],"property_filetype":["' + Constants.ConfigFileExtension + '"]}');
|
|
77
|
+
let configFileState = searchResults[0].displayProperties.find((p) => p.id === Constants.FILE_STATUS_PROPERTY_NAME).value.toLowerCase();
|
|
78
|
+
this.configFileId = searchResults[0].id;
|
|
79
|
+
// make sure to not use a configuration that is about to get changed
|
|
80
|
+
let counter = 0;
|
|
81
|
+
while (configFileState !== Constants.DmsObjectStates.States.Released) {
|
|
82
|
+
// go to sleep
|
|
83
|
+
await new Promise(resolve => setTimeout(resolve, Constants.ConfigFileLockedTimeout));
|
|
84
|
+
if (counter >= 2) {
|
|
85
|
+
await this.releaseConfiguration(this.configFileId);
|
|
86
|
+
}
|
|
87
|
+
searchResults = await this.getSearchResults('?properties={"property_filename":["' + Constants.ConfigFileName + '"],"property_filetype":["' + Constants.ConfigFileExtension + '"]}');
|
|
88
|
+
configFileState = searchResults[0].displayProperties.find((p) => p.id === Constants.FILE_STATUS_PROPERTY_NAME).value.toLowerCase();
|
|
89
|
+
++counter;
|
|
90
|
+
}
|
|
91
|
+
return await this.getDocumentContent(this.configFileId);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* sets the config file to state 'processing'
|
|
95
|
+
*
|
|
96
|
+
* @param configFileId - string id of the config file document
|
|
97
|
+
* @returns void
|
|
98
|
+
*/
|
|
99
|
+
async blockConfiguration() {
|
|
100
|
+
await this.ensureConfigurationFileId();
|
|
101
|
+
await this.setObjectState(this.configFileId, (await this.getCurrentUserName()), Constants.DmsObjectStates.States.Processing);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* sets the config file to state 'released'
|
|
105
|
+
*
|
|
106
|
+
* @param configFileId - string id of the config file document
|
|
107
|
+
* @returns void
|
|
108
|
+
*/
|
|
109
|
+
async releaseConfiguration(alterationText = '') {
|
|
110
|
+
await this.ensureConfigurationFileId();
|
|
111
|
+
await this.setObjectState(this.configFileId, (await this.getCurrentUserName()), Constants.DmsObjectStates.States.Released, alterationText);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* retrieves the current user name
|
|
115
|
+
*
|
|
116
|
+
* @returns the current user name as string
|
|
117
|
+
*/
|
|
118
|
+
async getCurrentUserName() {
|
|
119
|
+
if (this.currentUserName == null) {
|
|
120
|
+
this.currentUserName = (await this.getCurrentUserObject()).userName;
|
|
121
|
+
}
|
|
122
|
+
return this.currentUserName;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* returns the document categroy specific number range information from config
|
|
126
|
+
*
|
|
127
|
+
* @param doc - the current document object
|
|
128
|
+
* @param config - the current config object
|
|
129
|
+
* @returns the document categroy's' number range information from config
|
|
130
|
+
*/
|
|
131
|
+
getNumberRangeInformation(doc, config) {
|
|
132
|
+
let tenantInfo = config.numberRanges.tenants.find((cp) => {
|
|
133
|
+
let tenantProperty = doc.properties.find((p) => p.id.toLowerCase() === cp.tenantPropertyGuid.toLowerCase());
|
|
134
|
+
if (typeof (tenantProperty.values) !== 'undefined') {
|
|
135
|
+
if (tenantProperty.isMultiValue) {
|
|
136
|
+
return tenantProperty.values.some(v => v.value === cp.tenantPropertyValue);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return tenantProperty.value === cp.tenantPropertyValue;
|
|
140
|
+
});
|
|
141
|
+
let numberRangeInformation = [];
|
|
142
|
+
if (tenantInfo !== null) {
|
|
143
|
+
numberRangeInformation = tenantInfo.properties.filter(p => p.enabledCategories.some(ec => ec.id === doc.categoryId));
|
|
144
|
+
}
|
|
145
|
+
return numberRangeInformation;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.D3dWebhookClient = D3dWebhookClient;
|
|
149
|
+
//# sourceMappingURL=Yaveon.ECM.d3d.Webhook.Client.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDefaultHeaders } from './Yaveon.ECM.d3d.Webhook.Interfaces';
|
|
2
|
+
declare enum _dmsObjectStates {
|
|
3
|
+
Processing = "processing",
|
|
4
|
+
Verifiction = "verification",
|
|
5
|
+
Released = "released",
|
|
6
|
+
Archive = "archive",
|
|
7
|
+
Block = "Block"
|
|
8
|
+
}
|
|
9
|
+
export declare class DmsObjectStates {
|
|
10
|
+
static States: typeof _dmsObjectStates;
|
|
11
|
+
static isValid(stateValue: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const ConfigFileName: string;
|
|
14
|
+
export declare const ConfigFileExtension: string;
|
|
15
|
+
export declare const ConfigFileDisplayName: string;
|
|
16
|
+
export declare const FILE_STATUS_PROPERTY_NAME: string;
|
|
17
|
+
export declare const FILE_STATUS_RELEASED: string;
|
|
18
|
+
export declare const ConfigFileLockedTimeout: number;
|
|
19
|
+
export declare const defaultHeaders: IDefaultHeaders;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultHeaders = exports.ConfigFileLockedTimeout = exports.FILE_STATUS_RELEASED = exports.FILE_STATUS_PROPERTY_NAME = exports.ConfigFileDisplayName = exports.ConfigFileExtension = exports.ConfigFileName = exports.DmsObjectStates = void 0;
|
|
4
|
+
var _dmsObjectStates;
|
|
5
|
+
(function (_dmsObjectStates) {
|
|
6
|
+
_dmsObjectStates["Processing"] = "processing";
|
|
7
|
+
_dmsObjectStates["Verifiction"] = "verification";
|
|
8
|
+
_dmsObjectStates["Released"] = "released";
|
|
9
|
+
_dmsObjectStates["Archive"] = "archive";
|
|
10
|
+
_dmsObjectStates["Block"] = "Block";
|
|
11
|
+
})(_dmsObjectStates || (_dmsObjectStates = {}));
|
|
12
|
+
;
|
|
13
|
+
class DmsObjectStates {
|
|
14
|
+
static isValid(stateValue) {
|
|
15
|
+
return Object.values(_dmsObjectStates).includes(stateValue);
|
|
16
|
+
// return true;
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
}
|
|
20
|
+
DmsObjectStates.States = _dmsObjectStates;
|
|
21
|
+
exports.DmsObjectStates = DmsObjectStates;
|
|
22
|
+
exports.ConfigFileName = 'webhookConfiguration';
|
|
23
|
+
exports.ConfigFileExtension = 'json';
|
|
24
|
+
exports.ConfigFileDisplayName = 'Webhook Konfiguration';
|
|
25
|
+
exports.FILE_STATUS_PROPERTY_NAME = 'property_state';
|
|
26
|
+
exports.FILE_STATUS_RELEASED = 'release';
|
|
27
|
+
exports.ConfigFileLockedTimeout = 3000;
|
|
28
|
+
// export const defaultHeaders: Map <string,string> = new Map <string,string> ([
|
|
29
|
+
// ['Accept', 'application/json+hal'],
|
|
30
|
+
// ['Authorization', ''],
|
|
31
|
+
// ['Content-Type', 'application/json;charset=utf-8'],
|
|
32
|
+
// ['Origin', '']
|
|
33
|
+
// ]);
|
|
34
|
+
exports.defaultHeaders = {
|
|
35
|
+
Accept: 'application/json+hal',
|
|
36
|
+
Authorization: '',
|
|
37
|
+
Origin: '',
|
|
38
|
+
'Content-Type': 'application/json;charset=utf-8'
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=Yaveon.ECM.d3d.Webhook.Constants.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { RawAxiosRequestHeaders } from 'axios';
|
|
2
|
+
export interface IDefaultHeaders extends RawAxiosRequestHeaders {
|
|
3
|
+
Accept: string;
|
|
4
|
+
Authorization: string;
|
|
5
|
+
Origin: string;
|
|
6
|
+
'Content-Type': string;
|
|
7
|
+
}
|
|
8
|
+
export interface ITenantInformation {
|
|
9
|
+
tenantPropertyGuid: string;
|
|
10
|
+
tenantPropertyId: string;
|
|
11
|
+
tenantPropertyName: string;
|
|
12
|
+
tenantPropertyValue: string;
|
|
13
|
+
properties: INumberRangePropertyObject[];
|
|
14
|
+
}
|
|
15
|
+
export interface INumberRangePropertyObject {
|
|
16
|
+
enabledCategories: IEnabledCategory[];
|
|
17
|
+
numberRangePropertyGuid: string;
|
|
18
|
+
numberRangePropertyId: number;
|
|
19
|
+
numberRangePropertyName: string;
|
|
20
|
+
nextValue: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IEnabledCategory {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
export interface IDocPropertyObject {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
dataType: string;
|
|
30
|
+
isMultiValue: boolean;
|
|
31
|
+
value?: string;
|
|
32
|
+
values?: IDocPropertyCollectionValue[];
|
|
33
|
+
}
|
|
34
|
+
export interface IDocPropertyCollectionValue {
|
|
35
|
+
row: number;
|
|
36
|
+
value: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Yaveon_ECM_d3d_Webhook_Client_1 = require("./Yaveon.ECM.d3d.Webhook.Client");
|
|
4
|
+
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '1';
|
|
5
|
+
module.exports = async (req, res) => {
|
|
6
|
+
let reqBody = req.json();
|
|
7
|
+
let doc = reqBody.doc;
|
|
8
|
+
let resultMsg = '';
|
|
9
|
+
let resultState = 200;
|
|
10
|
+
let whClient = new Yaveon_ECM_d3d_Webhook_Client_1.D3dWebhookClient(req.get('x-dv-baseuri'), req.get('x-dv-repository-id'), 'Bearer ' + req.get('Authorization').replace('Bearer ', ''));
|
|
11
|
+
// obtain configuration file
|
|
12
|
+
let config = await whClient.getConfiguration();
|
|
13
|
+
// block configuration to prevent concurrent updates
|
|
14
|
+
await whClient.blockConfiguration();
|
|
15
|
+
let alterationText = "";
|
|
16
|
+
try {
|
|
17
|
+
let configNeedsUpdate = false;
|
|
18
|
+
let numberRangeInformation = whClient.getNumberRangeInformation(doc, config);
|
|
19
|
+
for (const numberRangeInfo of numberRangeInformation) {
|
|
20
|
+
let property = doc.properties.find((p) => p.id === numberRangeInfo.numberRangePropertyGuid);
|
|
21
|
+
if (property.value === null || property.value === "") {
|
|
22
|
+
property.value = numberRangeInfo.nextValue.toString();
|
|
23
|
+
numberRangeInfo.nextValue += 1;
|
|
24
|
+
configNeedsUpdate = true;
|
|
25
|
+
alterationText += "incremented number range for " + numberRangeInfo.numberRangePropertyName + ": " + numberRangeInfo.nextValue + ". ";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (configNeedsUpdate) {
|
|
29
|
+
let updateResponse = await whClient.updateConfiguration(config, alterationText);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (ex) {
|
|
33
|
+
alterationText = '';
|
|
34
|
+
resultState = 400;
|
|
35
|
+
if (ex.response.data) {
|
|
36
|
+
resultMsg = ex.response.data;
|
|
37
|
+
}
|
|
38
|
+
else if (ex.Message) {
|
|
39
|
+
resultMsg = ex.Message;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
resultMsg = ex;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
await whClient.releaseConfiguration(alterationText.trim());
|
|
47
|
+
}
|
|
48
|
+
res.status(resultState).set(req.get()).send((resultState === 200 ? Buffer.from(JSON.stringify(reqBody)) : resultMsg));
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=Yaveon.ECM.d3d.Webhook.SetNumberId.Test.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "yaveon.ecm.d3dwebhooks",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Utility files for triggered d3d webhooks",
|
|
5
|
+
"main": "",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "YAVEON GmbH",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"axios": "^1.3.6"
|
|
13
|
+
}
|
|
14
|
+
}
|